diff --git a/.clang-format b/.clang-format index eeb5240f8da..aa3843e1c0d 100644 --- a/.clang-format +++ b/.clang-format @@ -8,7 +8,8 @@ # src/tools/pgindent for the canonical formatter (we don't reformat # PG-original files -- only pgrac-original cluster code). # -# Compatible with clang-format >= 14 (Linux apt) and >= 22 (homebrew). +# Frozen output: clang-format 18.1.3 (Ubuntu 24.04 CI). +# Other versions may parse this file but produce different macro formatting. --- Language: Cpp diff --git a/.github/workflows/fast.yml b/.github/workflows/fast.yml index b213871ac08..c8bd3457c13 100644 --- a/.github/workflows/fast.yml +++ b/.github/workflows/fast.yml @@ -3,8 +3,8 @@ # linkdb fast-gate CI (Tier 1 of 3-tier CI model). # # Implements CLAUDE.md rule 20.A revised — every push / PR runs the -# fast gate (target 5-8 min wallclock). Heavier full coverage runs -# in nightly.yml + perf.yml. +# fast gate. Current MVP release checks also run in nightly.yml; +# historical extended checks remain in legacy-extended.yml. # # Author: SqlRush # @@ -19,7 +19,7 @@ # comment headers / commit msg # 2. linux-enable (~5-7 min): build + install + cluster_unit + # cluster_regress + smoke TAP -# subset (010 / 030 / 050 / 200 / 226) +# current MVP smoke subset # 3. linux-disable (~3-4 min): build + PG 219 + binary symbol # audit (--disable-cluster contract) # 4. macos-build-only (~3-4 min): build only — cross-platform @@ -29,10 +29,9 @@ # (cluster sources only) # # Tag (v*) push intentionally re-runs the same fast gate. Per CLAUDE.md -# rule 20.A revised, ship-time verification additionally requires the -# most recent nightly.yml run on the same commit (or its ancestor) to -# have completed green;tag push without nightly green coverage is a -# rule violation. +# current MVP policy, ship-time verification additionally requires every +# nightly.yml job on the exact commit to pass. Historical failures remain +# visible but do not certify or block the narrower MVP release scope. # ---------------------------------------------------------------------- name: linkdb fast-gate CI @@ -46,6 +45,7 @@ on: tags: ['v*'] pull_request: branches: [main] + workflow_dispatch: concurrency: group: ${{ github.workflow }}-${{ github.ref }} @@ -77,9 +77,9 @@ jobs: run: | set -euo pipefail - if [[ "${{ github.ref }}" == refs/tags/* ]]; then + if [[ "${{ github.ref }}" == refs/tags/* || "${{ github.event_name }}" == workflow_dispatch ]]; then echo "code_changed=true" >> "$GITHUB_OUTPUT" - echo "Tag push: run the full fast gate." + echo "Release qualification: run the full fast gate." exit 0 fi @@ -153,6 +153,13 @@ jobs: - name: Check release-notes principle-0 (spec-5.21 D7) run: ./scripts/ci/check-release-notes-principle0.sh + - name: Check static-analyzer execution contract + if: steps.changes.outputs.code_changed == 'true' + run: python3 scripts/ci/test_scan_build.py + + - name: Check MVP release evidence contract + run: python3 scripts/ci/test_mvp_ci.py + - name: Lint commit message if: github.event_name == 'pull_request' run: | @@ -190,12 +197,15 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 + with: + # Unit evidence manifests verify immutable predecessor commits. + fetch-depth: 0 - name: Install Linux dependencies run: | sudo apt-get update -y sudo apt-get install -y --no-install-recommends \ - build-essential ccache \ + build-essential ccache clang \ libreadline-dev zlib1g-dev libicu-dev \ liblz4-dev libzstd-dev libssl-dev libxml2-dev \ libipc-run-perl pkg-config @@ -230,35 +240,20 @@ jobs: - name: Install run: make install - - name: Run cluster_unit (35 binaries, link-level only) - run: make -C src/test/cluster_unit check + - name: Run cluster_unit (full registered suite) + run: make -j$(getconf _NPROCESSORS_ONLN) -C src/test/cluster_unit check - - name: Run cluster_regress (7 SQL smoke tests) + - name: Run cluster_regress (13 SQL smoke tests) run: make -C src/test/cluster_regress check - - name: Run smoke TAP subset (010 + 030 + 050 + 200 + 226) + - name: Run current MVP smoke TAP subset run: | - # Tier 1 fast gate: TAP files covering basic catalog views, - # acceptance lifecycle, smgr opt-in workflow + spec-2.40 Stage 2 - # acceptance capability smoke (t/200) + - # spec-3.17 Stage 3 MVCC capability cross-cutting smoke (t/226, - # single-node, ~5s). - # spec-4.14 Stage 4 recovery capability cross-cutting smoke (t/273, - # single-node, ~3s; multi-node hard-gate t/274 + matrix t/275 run in - # nightly stage4-wal shard + make check). - # t/202 perf smoke runs in nightly Stage 2 acceptance medium. - # t/201 fault matrix NOT here (avoid fast-gate inject flake). - # t/227 Stage 3 workload perf smoke runs pgbench (>30s) -> nightly. - # spec-5.20 Hang Manager capability smoke on fast-gate = the D8 - # cluster_unit static contract (test_cluster_hang_acceptance, runs in - # the unit step above, deterministic ms). The chaos TAP matrix - # (t/340-343: 70-conn hang storm / ABA / 2PC / 3+4-node reconfig) is - # kept OFF the fast-gate blocking path (L91 minimal scope + storm - # flake risk) and runs in the nightly stage5-hang-acceptance shard. - # Full cluster_tap suite + 2-node ClusterPair + heartbeat round- - # trip + Stage 2/3 medium perf matrix tests run in nightly.yml. + # Scope is explicit, shared with macOS, and validated before use. + # Former mixed 2PC/recovery/raw-device deployment cases still run + # unchanged in legacy-extended.yml; no failure is converted to PASS. + SMOKE="$(python3 scripts/ci/mvp_ci.py --smoke)" make -C src/test/cluster_tap check \ - PROVE_TESTS="t/010_views.pl t/030_acceptance.pl t/050_shared_storage_initdb.pl t/200_stage2_acceptance_capability.pl t/226_stage3_mvcc_acceptance_capability.pl t/273_stage4_recovery_acceptance_capability.pl t/332_block_device_backend.pl t/333_block_device_multinode.pl" + PROVE_TESTS="$SMOKE" - name: Upload regression diffs on failure if: failure() @@ -356,6 +351,8 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 + with: + fetch-depth: 0 - name: Install macOS dependencies run: | @@ -396,7 +393,7 @@ jobs: - name: Install + cluster_unit (link-level smoke) run: | make install - make -C src/test/cluster_unit check + make -j$(sysctl -n hw.ncpu) -C src/test/cluster_unit check # ==================================================================== diff --git a/.github/workflows/legacy-extended.yml b/.github/workflows/legacy-extended.yml new file mode 100644 index 00000000000..acd61dcebfa --- /dev/null +++ b/.github/workflows/legacy-extended.yml @@ -0,0 +1,564 @@ +# Historical extended CI — retained, non-blocking for the current MVP. +# Tests, failure exits and artifact retention remain unchanged; a red run is +# still a real failure and is not a current-MVP capability certificate. +# Author: SqlRush +# Portions Copyright (c) 2026, pgrac contributors + +name: PGRAC historical extended CI (non-blocking for MVP) + +env: + CCACHE_DIR: ${{ github.workspace }}/.ccache + +on: + schedule: + - cron: '0 8 * * *' + workflow_dispatch: + push: + tags: ['v*'] + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: false + +jobs: + + # ==================================================================== + # Tier 2.1a — Linux PG 219 three-mode regression (own job) + # -------------------------------------------------------------------- + # Kept off the cluster_tap shard critical path: PG 219 (~5 min) on any + # TAP shard would dominate it. Build + install + make check only. + # ==================================================================== + linux-pg-regress: + name: Linux PG 219 regression + runs-on: ubuntu-latest + timeout-minutes: 30 + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Install Linux dependencies + run: | + sudo apt-get update -y + sudo apt-get install -y --no-install-recommends \ + build-essential ccache clang \ + libreadline-dev zlib1g-dev libicu-dev \ + liblz4-dev libzstd-dev libssl-dev libxml2-dev \ + libipc-run-perl pkg-config + + - name: Restore ccache + uses: actions/cache@v4 + with: + path: .ccache + key: ${{ runner.os }}-${{ github.job }}-ccache-${{ github.ref_name }} + restore-keys: | + ${{ runner.os }}-${{ github.job }}-ccache- + ${{ runner.os }}-ccache- + + - name: Configure ccache + run: | + ccache --max-size=700M + ccache --zero-stats + + - name: Configure (--enable-cluster) + run: | + CC="ccache gcc" ./configure \ + --prefix=$HOME/pgrac-install \ + --enable-cassert --enable-debug \ + --with-openssl --with-icu --with-lz4 --with-zstd \ + --enable-cluster --enable-tap-tests + + - name: Build and install + run: | + make -j$(getconf _NPROCESSORS_ONLN) + ccache --show-stats + make install + + - name: Run PG regression tests (219 tests) + run: make check + + - name: Upload regression diffs on failure + if: failure() + uses: actions/upload-artifact@v4 + with: + name: nightly-pg-regress-diffs + path: | + src/test/regress/regression.diffs + src/test/regress/regression.out + src/test/regress/log/ + if-no-files-found: ignore + retention-days: 14 + + # ==================================================================== + # Tier 2.1b — Linux cluster_tap (9 parallel shards) + # -------------------------------------------------------------------- + # Shards by leading test-file number. Stage acceptance files are not + # duplicated here: + # - 200-202 are owned by stage2-acceptance-medium below. + # - 226-227 are owned by stage3-acceptance-medium below. + # + # cluster_unit + cluster_regress run only in foundation-core; the other + # shards run their TAP slice only. This saves repeated unit/regress work + # and keeps the longest Linux TAP shard below the macOS smoke bound. + # ==================================================================== + linux-cluster-tap: + name: Linux cluster_tap (${{ matrix.shard.name }}) + runs-on: ubuntu-latest + timeout-minutes: 45 + strategy: + fail-fast: false + matrix: + shard: + - { name: foundation-core, ranges: "001-031", unit: true, regress: true } + - { name: foundation-stage1, ranges: "050-071", unit: false, regress: false } + - { name: stage2-ic-cssd, ranges: "072-099", unit: false, regress: false } + - { name: stage2-gcs, ranges: "100-118", unit: false, regress: false } + - { name: stage3-core, ranges: "203-225", unit: false, regress: false } + - { name: stage3-recent, ranges: "228-237", unit: false, regress: false } + # 255 = spec-5.22b D2-7 undo-block GCS shared-storage data-plane TAP + # (2-node ClusterPair + shared cluster_fs; owner-as-master physical + # migration). Registered here (undo/recovery bucket) so the new file + # runs in nightly per the "every new t/ file lands in a shard the same + # commit" rule. NOTE: t/249-254 + t/256-272 remain an un-sharded + # pre-existing gap (tracked separately), not opened by this commit. + - { name: stage4-wal, ranges: "242-248 255 273 275", unit: false, regress: false } + - { name: stage4-hardgate, ranges: "274-274", unit: false, regress: false } + - { name: stage5-ges-locking, ranges: "276-326", unit: false, regress: false } + # spec-5.19 D9: Stage 5 integrated acceptance (heavy 4-node ClusterQuad + # + pgbench + crash-recovery) gets its own shard so the multi-node + # legs run in parallel and do not extend the ges-locking shard + # wallclock. t/327 HW workload / t/328 MG-B write perf / t/329 MG-D + # heap-ITL WAL measure / t/330 production-bench-subset / t/331 4-node + # reconfig fault matrix / t/334 spec-5.59 xnode-profile buckets. + - { name: stage5-integrated-acceptance, ranges: "327-331 334", unit: false, regress: false } + # spec-6.0a production shared-storage backend matrix. The first + # shard covers the CI-portable block_device raw-image e2e; hardware + # O_DIRECT / SCSI-3 PR legs remain external/manual. (334 is the + # spec-5.59 profiling TAP and lives in the stage5 shard above.) + - { name: stage6-storage, ranges: "332-333 335-339", unit: false, regress: false } + # spec-5.20 D9: Hang Manager chaos acceptance (detection matrix / + # remediation chaos / diagnostic completeness single-node + reconfig + # non-interference 3-node ClusterTriple + 4-node ClusterQuad). Own + # shard so the multi-node reconfig leg (t/343) runs in parallel and + # does not extend the ges-locking shard wallclock. + - { name: stage5-hang-acceptance, ranges: "340-343", unit: false, regress: false } + # spec-5.21 D8: Stage 5 beta close-out. t/344 = release-level sustained + # 4-node chaos soak (kill/leave under continuous load, HG#2); t/345 = + # integrated beta acceptance (evidence-completeness + 7 RAC core smoke, + # HG#1/HG#3). Own shard so the multi-node soak runs in parallel. The + # 4-node ClusterQuad soak leg is HG#2a-CI (PASS-or-environment-SKIP); + # the release-cut 4-node evidence is HG#2a-CI or HG#2a-EXT (external). + - { name: stage5-beta-chaos-soak, ranges: "344-345", unit: false, regress: false } + # spec-6.12/6.15 cross-node perf + correctness family (t/346-350: + # aged-seed verdict / ledger / 3-node nudge / PI rebuild + crash), + # the renumbered t/351-356 family, t/357 multi-xmax alias floor, and + # t/361 XID authority native-era adoption. + # Closes the 346+ shard hole (every new t/ file must land in a shard + # the same commit; see docs/code-review-checklist.md). + - { name: stage6-crossnode-a, ranges: "346-350", unit: false, regress: false } + - { name: stage6-crossnode-b, ranges: "351-357 361", unit: false, regress: false } + # t/358 spec-7.2 data-plane flip e2e + t/360 data-plane fault legs + # (conn-reset injection / KNOWN-BLOCKED docs). Closes the review + # P1-3 shard hole: both files predate this shard and were in NO CI + # matrix. Own shard: the t/360 value gate + reconnect deadline + # need the wall clock. (t/359 gapwalk runs in stage7-multixact.) + - { name: stage7-data-plane, ranges: "358 360", unit: false, regress: false } + # t/362 spec-4.6a 4-node shared_catalog kill self-heal (L464 + # occupancy verified against origin branches 2026-07-08). Own + # shard: 4-node formation + kill + convergence needs the wall + # clock. + - { name: stage7-reconfig-liveness, ranges: "362-362", unit: false, regress: false } + # t/363 spec-2.29a marker-async LMON liveness. + - { name: stage7-marker-async, ranges: "363-363", unit: false, regress: false } + # t/364 + t/367 spec-7.3 LMS worker-pool family (single-node pool + # smoke + 2-node topology / multi-tag routing / recycle / N=1 + # sentinel). Every new t/ file lands in a shard the same commit + # (L342). + - { name: stage7-lms-pool, ranges: "364 367", unit: false, regress: false } + # t/365 spec-7.1a cross-instance write-write MVCC coordination. + - { name: stage7-write-write, ranges: "365-365", unit: false, regress: false } + # t/366 spec-7.2a GCS block dedup capacity + eager reclaim, plus + # t/371 GCS_DONE mixed-version compat (suppressed pre-protocol + # binary at the default cap). Own shard: 2-node shared_catalog + # bring-up + cross-node distinct-read dedup pressure + injected + # retransmit-dedup correctness needs the wall clock. + - { name: stage7-gcs-dedup-capacity, ranges: "366 371", unit: false, regress: false } + # t/359 mxid-stripe gapwalk + t/368 multixact member-serve refuse + # (spec-7.1 family; 368 renamed from the double-occupied t/360 per + # the hub number ledger -- the lms data-plane faults file keeps 360). + - { name: stage7-multixact, ranges: "359 368", unit: false, regress: false } + # t/369 spec-5.22d dead-owner authority serve + t/370 spec-5.22e + # cluster-wide undo retention brake (both 2-node shared-root) + + # t/386 spec-2.2 caps-reply directed matrix / rolling-upgrade + # compat / generation legs (3-node triple). Own shard: the brake + # legs pin/stall/self-heal on real cleaner cadence and need the + # wall clock. + - { name: stage5-undo-retention, ranges: "369-370 386 389", unit: false, regress: false } + # t/390 GCS block-ship race convergence (3-node triple): PENDING_X + # dedup re-evaluation (no reply-timeout burn), invalidate-slot + # bounded claim wait, duplicate-reply first-reply-wins. Own shard: + # triple bring-up + injection legs need the wall clock (L342: every + # new t/ file lands in a shard the same commit). + - { name: stage7-gcs-block-race, ranges: "390-390", unit: false, regress: false } + # t/392-397 GCS-race round-2 + ownership-generation wave (2-node + # pairs): raw-xid visibility collision, copy->drop lost-write + # window, W1 cached-cover / W2 restore-ABA / W3 grant-finalize + # window REDs, and the no-injection ownership convergence gate. + # Own shard: six ClusterPair bring-ups need the wall clock + # (L342: every new t/ file lands in a shard the same commit). + - { name: stage7-gcs-ownership-gen, ranges: "392-397", unit: false, regress: false } + # t/401 GCS master-direct STALE-ship storage rescue (PR#55) + + # t/402 undo cleaner stall-retry cadence (PR#56) + t/403 TT-lane + # idle-peer floor pin under write load (all 2-node pairs from the + # S3 wave). t/401/402 predate this shard and were in NO CI + # matrix -- closes that hole (L342: every new t/ file lands in a + # shard the same commit). Own shard: three ClusterPair bring-ups + # + the t/403 sustained write phase need the wall clock. + - { name: stage7-s3-wave, ranges: "401-403", unit: false, regress: false } + # t/400 PCM-X convert-queue 4-node liveness (ClusterQuad bring-up) + # + t/404 crash-rejoin stale-read/write fence (2-node with a full + # crash/restart cycle). Both were in NO CI matrix (L342: every new + # t/ file lands in a shard the same commit). Own shard: the quad + # formation and the rejoin crash cycle dominate the wall clock. + - { name: stage7-queue-liveness-rejoin, ranges: "400 404", unit: false, regress: false } + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + # Unit evidence manifests verify immutable predecessor commits. + fetch-depth: 0 + + # spec-5.21 D2 Part A (evidence-completeness) checks each Stage 5 sub-spec + # ship tag is an ancestor of HEAD. A default shallow checkout (depth 1) + # both omits the tags AND makes `git merge-base --is-ancestor` return + # rc=1 (ancestry cannot be established through a truncated history), so + # the shard must UNSHALLOW here. Only the beta shard needs it. Errors + # are NOT swallowed: if this fails the shard goes red rather than silently + # skipping the evidence-completeness gate (rule 8.B). + - name: Unshallow + fetch tags (beta evidence-completeness) + if: matrix.shard.name == 'stage5-beta-chaos-soak' + run: | + git fetch --unshallow --tags --force origin 2>/dev/null \ + || git fetch --tags --force origin + + - name: Install Linux dependencies + run: | + sudo apt-get update -y + sudo apt-get install -y --no-install-recommends \ + build-essential ccache clang \ + libreadline-dev zlib1g-dev libicu-dev \ + liblz4-dev libzstd-dev libssl-dev libxml2-dev \ + libipc-run-perl pkg-config + + - name: Restore ccache + uses: actions/cache@v4 + with: + path: .ccache + key: ${{ runner.os }}-${{ github.job }}-${{ matrix.shard.name }}-ccache-${{ github.ref_name }} + restore-keys: | + ${{ runner.os }}-${{ github.job }}-${{ matrix.shard.name }}-ccache- + ${{ runner.os }}-${{ github.job }}-ccache- + ${{ runner.os }}-ccache- + + - name: Configure ccache + run: | + ccache --max-size=700M + ccache --zero-stats + + - name: Configure (--enable-cluster) + run: | + CC="ccache gcc" ./configure \ + --prefix=$HOME/pgrac-install \ + --enable-cassert --enable-debug \ + --with-openssl --with-icu --with-lz4 --with-zstd \ + --enable-cluster --enable-tap-tests + + - name: Build and install + run: | + make -j$(getconf _NPROCESSORS_ONLN) + ccache --show-stats + make install + + - name: Run cluster_unit + if: matrix.shard.unit + run: make -C src/test/cluster_unit check + + - name: Run cluster_regress (foundation-core shard only) + if: matrix.shard.regress + run: make -C src/test/cluster_regress check + + - name: Run cluster_tap shard ${{ matrix.shard.name }} + env: + # Harmless to set everywhere. The medium Stage 2 acceptance job + # owns t/202; keep the env here so manual shard experiments behave + # the same if t/202 is temporarily included in a range. + STAGE2_PERF_HARD_GATE: '1' + run: | + SEL=$(cd src/test/cluster_tap && ranges="${{ matrix.shard.ranges }}"; for f in t/*.pl; do \ + n=$(basename "$f" .pl | cut -d_ -f1); \ + d=$((10#$n)); \ + include=0; \ + for r in $ranges; do \ + lo=${r%-*}; hi=${r#*-}; \ + lo_d=$((10#$lo)); hi_d=$((10#$hi)); \ + if [ "$d" -ge "$lo_d" ] && [ "$d" -le "$hi_d" ]; then \ + include=1; break; \ + fi; \ + done; \ + if [ "$include" -eq 1 ]; then \ + printf '%s ' "$f"; \ + fi; \ + done) + echo "shard ${{ matrix.shard.name }} files: $SEL" + test -n "$SEL" || { echo "ERROR: empty shard selection"; exit 1; } + make -C src/test/cluster_tap check PROVE_TESTS="$SEL" + + - name: Upload cluster_tap diffs on failure + if: failure() + uses: actions/upload-artifact@v4 + with: + name: nightly-cluster-tap-diffs-${{ matrix.shard.name }} + path: | + src/test/cluster_regress/regression.diffs + src/test/cluster_regress/regression.out + src/test/cluster_regress/log/ + src/test/cluster_tap/tmp_check/log/ + if-no-files-found: ignore + retention-days: 14 + + # ==================================================================== + # Tier 2.1c — macOS Build+Test (smoke) + # -------------------------------------------------------------------- + # macOS keeps build + PG 219 + cluster_unit + cluster_regress + a curated + # cluster_tap SMOKE subset only (the full cluster_tap on macOS was the + # ~22min nightly bottleneck; Linux runs the full suite, sharded, above). + # The smoke deliberately INCLUDES the concurrency-sensitive spec-3.19 + # 234/235 (macOS shmem/IPC behaviour is exactly where those matter most). + # ==================================================================== + build-test-macos: + name: macOS Build+Test (smoke) + runs-on: macos-latest + timeout-minutes: 45 + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Install macOS dependencies + run: | + brew install readline icu4c lz4 zstd openssl@3 libxml2 cpanminus pkg-config ccache || true + cpanm --local-lib=$HOME/perl5 --notest IPC::Run IO::Tty + { + echo "PERL5LIB=$HOME/perl5/lib/perl5" + echo "PKG_CONFIG_PATH=$(brew --prefix icu4c)/lib/pkgconfig:$(brew --prefix openssl@3)/lib/pkgconfig:$(brew --prefix lz4)/lib/pkgconfig:$(brew --prefix zstd)/lib/pkgconfig" + echo "LDFLAGS=-L$(brew --prefix readline)/lib -L$(brew --prefix zstd)/lib -L$(brew --prefix lz4)/lib -L$(brew --prefix openssl@3)/lib -L$(brew --prefix icu4c)/lib" + echo "CPPFLAGS=-I$(brew --prefix readline)/include -I$(brew --prefix zstd)/include -I$(brew --prefix lz4)/include -I$(brew --prefix openssl@3)/include -I$(brew --prefix icu4c)/include" + } >> $GITHUB_ENV + + - name: Restore ccache + uses: actions/cache@v4 + with: + path: .ccache + key: ${{ runner.os }}-${{ github.job }}-ccache-${{ github.ref_name }} + restore-keys: | + ${{ runner.os }}-${{ github.job }}-ccache- + ${{ runner.os }}-ccache- + + - name: Configure ccache + run: | + ccache --max-size=700M + ccache --zero-stats + + - name: Configure (--enable-cluster) + run: | + CC="ccache clang" ./configure \ + --prefix=$HOME/pgrac-install \ + --enable-cassert --enable-debug \ + --with-openssl --with-icu --with-lz4 --with-zstd \ + --enable-cluster --enable-tap-tests + + - name: Build and install + run: | + make -j$(sysctl -n hw.ncpu) + ccache --show-stats + make install + + - name: Run PG regression tests (219 tests) + run: make check + + - name: Run cluster smoke (unit + regress + curated TAP) + run: | + make -C src/test/cluster_unit check + make -C src/test/cluster_regress check + SMOKE="t/001_single_node_smoke.pl t/005_wait_events_catalog.pl t/020_shmem_registry.pl t/068_wal_xl_scn.pl t/215_cluster_3_9_cr_construction.pl t/219_cluster_3_11_durable_tt_slot.pl t/226_stage3_mvcc_acceptance_capability.pl t/234_cluster_3_19_dml_boundary.pl t/235_cluster_3_19_snapshot_isolation.pl" + make -C src/test/cluster_tap check PROVE_TESTS="$SMOKE" + + - name: Upload regression diffs on failure + if: failure() + uses: actions/upload-artifact@v4 + with: + name: nightly-regression-diffs-macos + path: | + src/test/cluster_regress/regression.diffs + src/test/cluster_regress/regression.out + src/test/cluster_regress/log/ + src/test/regress/regression.diffs + src/test/regress/regression.out + src/test/regress/log/ + src/test/cluster_tap/tmp_check/log/ + if-no-files-found: ignore + retention-days: 14 + + # ==================================================================== + # Tier 2.2 — Stage 2 acceptance medium representative job + # -------------------------------------------------------------------- + # Self-contained Ubuntu job. It intentionally rebuilds/install locally + # instead of assuming workspace or install artifacts from other jobs. + # Runs the Stage 2 acceptance TAPs with longer knobs than fast-gate and + # uploads the generated JSON reports. + # ==================================================================== + stage2-acceptance-medium: + name: Stage 2 acceptance medium (Ubuntu) + runs-on: ubuntu-latest + timeout-minutes: 90 + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Install Linux dependencies + run: | + sudo apt-get update -y + sudo apt-get install -y --no-install-recommends \ + build-essential ccache clang \ + libreadline-dev zlib1g-dev libicu-dev \ + liblz4-dev libzstd-dev libssl-dev libxml2-dev \ + libipc-run-perl pkg-config + + - name: Restore ccache + uses: actions/cache@v4 + with: + path: .ccache + key: ${{ runner.os }}-${{ github.job }}-ccache-${{ github.ref_name }} + restore-keys: | + ${{ runner.os }}-${{ github.job }}-ccache- + ${{ runner.os }}-ccache- + + - name: Configure ccache + run: | + ccache --max-size=700M + ccache --zero-stats + + - name: Configure (--enable-cluster) + run: | + CC="ccache gcc" ./configure \ + --prefix=$HOME/pgrac-install \ + --enable-cassert --enable-debug \ + --with-openssl --with-icu --with-lz4 --with-zstd \ + --enable-cluster --enable-tap-tests + + - name: Build and install + run: | + make -j$(getconf _NPROCESSORS_ONLN) + ccache --show-stats + make install + + - name: Run Stage 2 acceptance TAP matrix + env: + STAGE2_TAG: ${{ github.ref_name }} + STAGE2_PGBENCH_SECONDS: "20" + STAGE2_WORKLOAD_SECONDS: "1" + STAGE2_WORKLOAD_ITERATIONS: "20" + run: | + make -C src/test/cluster_tap check \ + PROVE_TESTS="t/200_stage2_acceptance_capability.pl t/201_stage2_acceptance_fault_matrix.pl t/202_stage2_acceptance_perf_smoke.pl" + + - name: Upload Stage 2 acceptance reports + if: always() + uses: actions/upload-artifact@v4 + with: + name: stage2-acceptance-medium-${{ github.run_id }} + path: | + src/test/cluster_tap/tmp/stage2-acceptance-*.json + src/test/cluster_tap/tmp_check/log/ + if-no-files-found: ignore + retention-days: 30 + + # ==================================================================== + # Tier 2.3 — Stage 3 MVCC acceptance medium representative job + # -------------------------------------------------------------------- + # Self-contained Ubuntu job (rebuilds/install locally). Runs the + # spec-3.17 Stage 3 acceptance TAPs — capability cross-cutting (t/226) + # and the workload perf smoke (t/227, pgbench) — with longer knobs than + # fast-gate, plus the static contract unit binary, and uploads the + # generated JSON reports. All perf numbers are report-only (the Stage 3 + # performance bar is owned by spec-3.18); this job gates only on the + # functional/correctness assertions. + # ==================================================================== + stage3-acceptance-medium: + name: Stage 3 acceptance medium (Ubuntu) + runs-on: ubuntu-latest + timeout-minutes: 90 + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Install Linux dependencies + run: | + sudo apt-get update -y + sudo apt-get install -y --no-install-recommends \ + build-essential ccache clang \ + libreadline-dev zlib1g-dev libicu-dev \ + liblz4-dev libzstd-dev libssl-dev libxml2-dev \ + libipc-run-perl pkg-config + + - name: Restore ccache + uses: actions/cache@v4 + with: + path: .ccache + key: ${{ runner.os }}-${{ github.job }}-ccache-${{ github.ref_name }} + restore-keys: | + ${{ runner.os }}-${{ github.job }}-ccache- + ${{ runner.os }}-ccache- + + - name: Configure ccache + run: | + ccache --max-size=700M + ccache --zero-stats + + - name: Configure (--enable-cluster) + run: | + CC="ccache gcc" ./configure \ + --prefix=$HOME/pgrac-install \ + --enable-cassert --enable-debug \ + --with-openssl --with-icu --with-lz4 --with-zstd \ + --enable-cluster --enable-tap-tests + + - name: Build and install + run: | + make -j$(getconf _NPROCESSORS_ONLN) + ccache --show-stats + make install + + - name: Run Stage 3 static contract unit binary + run: make -C src/test/cluster_unit check + + - name: Run Stage 3 acceptance TAP matrix + env: + PGRAC_TAG: ${{ github.ref_name }} + STAGE3_PGBENCH_SECONDS: "20" + run: | + make -C src/test/cluster_tap check \ + PROVE_TESTS="t/226_stage3_mvcc_acceptance_capability.pl t/227_stage3_mvcc_workload_smoke.pl" + + - name: Upload Stage 3 acceptance reports + if: always() + uses: actions/upload-artifact@v4 + with: + name: stage3-acceptance-medium-${{ github.run_id }} + path: | + src/test/cluster_tap/tmp/stage3-acceptance-*.json + src/test/cluster_tap/tmp_check/log/ + if-no-files-found: ignore + retention-days: 30 diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index 4f2b426e037..b513eba38fa 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -1,43 +1,10 @@ -# ---------------------------------------------------------------------- -# .github/workflows/nightly.yml -# linkdb full coverage CI (Tier 2 of 3-tier CI model). -# -# Runs the heavy parts that fast.yml intentionally skips, sharded for -# wallclock: -# - linux-pg-regress: PG 219 three-mode (own job, off the TAP path) -# - linux-cluster-tap: cluster_tap files split into 9 parallel shards -# (foundation-core / foundation-stage1 / stage2-ic-cssd / stage2-gcs / -# stage3-core / stage3-recent / stage4-wal / stage4-hardgate / -# stage5-ges-locking), with Stage 2/3 acceptance files kept in their -# dedicated medium jobs. cluster_unit + cluster_regress run once on the -# foundation-core shard. -# - build-test-macos: PG 219 + cluster_unit + cluster_regress + a curated -# cluster_tap SMOKE subset (the full cluster_tap on macOS was the -# wallclock bottleneck; Linux is the primary target) -# -# Per CLAUDE.md rule 20.A revised, ship-time tag verification requires -# both fast.yml green (push gate) AND nightly.yml green (this workflow) -# on the same commit (or its main-branch ancestor). -# +# Current MVP release CI. Historical extended tests live in legacy-extended.yml. +# Together with every required fast.yml job, this workflow must pass on the +# exact release commit. Docs-only skips and older-commit results do not qualify. # Author: SqlRush -# # Portions Copyright (c) 2026, pgrac contributors -# -# Triggers: -# - schedule cron 08:00 UTC daily (off-peak for both US/EU/AP) -# - workflow_dispatch (manual trigger by maintainer) -# - push to tags v* (mandatory ship-time verification) -# -# Total wallclock target: ≤ 7 min (Linux TAP shards + pg-regress + macOS -# smoke all run in parallel; the slowest shard is the bound). Was ~26 min -# (single macOS full cluster_tap job) before sharding + macOS smoke, then -# ~8-9 min with 3 broad Linux TAP shards. -# Trade-off: more runner-minutes (each shard self-builds) for less wallclock, -# per the maintainer's "GitHub job sharding is more stable than prove -j" -# guidance (TAP has port/tmp/IPC/cluster-node resource contention). -# ---------------------------------------------------------------------- -name: linkdb nightly full CI +name: PGRAC MVP release CI env: CCACHE_DIR: ${{ github.workspace }}/.ccache @@ -55,12 +22,6 @@ concurrency: jobs: - # ==================================================================== - # Tier 2.1a — Linux PG 219 three-mode regression (own job) - # -------------------------------------------------------------------- - # Kept off the cluster_tap shard critical path: PG 219 (~5 min) on any - # TAP shard would dominate it. Build + install + make check only. - # ==================================================================== linux-pg-regress: name: Linux PG 219 regression runs-on: ubuntu-latest @@ -73,7 +34,7 @@ jobs: run: | sudo apt-get update -y sudo apt-get install -y --no-install-recommends \ - build-essential ccache \ + build-essential ccache clang \ libreadline-dev zlib1g-dev libicu-dev \ liblz4-dev libzstd-dev libssl-dev libxml2-dev \ libipc-run-perl pkg-config @@ -121,249 +82,6 @@ jobs: if-no-files-found: ignore retention-days: 14 - # ==================================================================== - # Tier 2.1b — Linux cluster_tap (9 parallel shards) - # -------------------------------------------------------------------- - # Shards by leading test-file number. Stage acceptance files are not - # duplicated here: - # - 200-202 are owned by stage2-acceptance-medium below. - # - 226-227 are owned by stage3-acceptance-medium below. - # - # cluster_unit + cluster_regress run only in foundation-core; the other - # shards run their TAP slice only. This saves repeated unit/regress work - # and keeps the longest Linux TAP shard below the macOS smoke bound. - # ==================================================================== - linux-cluster-tap: - name: Linux cluster_tap (${{ matrix.shard.name }}) - runs-on: ubuntu-latest - timeout-minutes: 45 - strategy: - fail-fast: false - matrix: - shard: - - { name: foundation-core, ranges: "001-030", unit: true, regress: true } - - { name: foundation-stage1, ranges: "050-071", unit: false, regress: false } - - { name: stage2-ic-cssd, ranges: "072-099", unit: false, regress: false } - - { name: stage2-gcs, ranges: "100-118", unit: false, regress: false } - - { name: stage3-core, ranges: "203-225", unit: false, regress: false } - - { name: stage3-recent, ranges: "228-237", unit: false, regress: false } - # 255 = spec-5.22b D2-7 undo-block GCS shared-storage data-plane TAP - # (2-node ClusterPair + shared cluster_fs; owner-as-master physical - # migration). Registered here (undo/recovery bucket) so the new file - # runs in nightly per the "every new t/ file lands in a shard the same - # commit" rule. NOTE: t/249-254 + t/256-272 remain an un-sharded - # pre-existing gap (tracked separately), not opened by this commit. - - { name: stage4-wal, ranges: "242-248 255 273 275", unit: false, regress: false } - - { name: stage4-hardgate, ranges: "274-274", unit: false, regress: false } - - { name: stage5-ges-locking, ranges: "276-326", unit: false, regress: false } - # spec-5.19 D9: Stage 5 integrated acceptance (heavy 4-node ClusterQuad - # + pgbench + crash-recovery) gets its own shard so the multi-node - # legs run in parallel and do not extend the ges-locking shard - # wallclock. t/327 HW workload / t/328 MG-B write perf / t/329 MG-D - # heap-ITL WAL measure / t/330 production-bench-subset / t/331 4-node - # reconfig fault matrix / t/334 spec-5.59 xnode-profile buckets. - - { name: stage5-integrated-acceptance, ranges: "327-331 334", unit: false, regress: false } - # spec-6.0a production shared-storage backend matrix. The first - # shard covers the CI-portable block_device raw-image e2e; hardware - # O_DIRECT / SCSI-3 PR legs remain external/manual. (334 is the - # spec-5.59 profiling TAP and lives in the stage5 shard above.) - - { name: stage6-storage, ranges: "332-333 335-339", unit: false, regress: false } - # spec-5.20 D9: Hang Manager chaos acceptance (detection matrix / - # remediation chaos / diagnostic completeness single-node + reconfig - # non-interference 3-node ClusterTriple + 4-node ClusterQuad). Own - # shard so the multi-node reconfig leg (t/343) runs in parallel and - # does not extend the ges-locking shard wallclock. - - { name: stage5-hang-acceptance, ranges: "340-343", unit: false, regress: false } - # spec-5.21 D8: Stage 5 beta close-out. t/344 = release-level sustained - # 4-node chaos soak (kill/leave under continuous load, HG#2); t/345 = - # integrated beta acceptance (evidence-completeness + 7 RAC core smoke, - # HG#1/HG#3). Own shard so the multi-node soak runs in parallel. The - # 4-node ClusterQuad soak leg is HG#2a-CI (PASS-or-environment-SKIP); - # the release-cut 4-node evidence is HG#2a-CI or HG#2a-EXT (external). - - { name: stage5-beta-chaos-soak, ranges: "344-345", unit: false, regress: false } - # spec-6.12/6.15 cross-node perf + correctness family (t/346-350: - # aged-seed verdict / ledger / 3-node nudge / PI rebuild + crash), - # the renumbered t/351-356 family, t/357 multi-xmax alias floor, and - # t/361 XID authority native-era adoption. - # Closes the 346+ shard hole (every new t/ file must land in a shard - # the same commit; see docs/code-review-checklist.md). - - { name: stage6-crossnode-a, ranges: "346-350", unit: false, regress: false } - - { name: stage6-crossnode-b, ranges: "351-357 361", unit: false, regress: false } - # t/358 spec-7.2 data-plane flip e2e + t/360 data-plane fault legs - # (conn-reset injection / KNOWN-BLOCKED docs). Closes the review - # P1-3 shard hole: both files predate this shard and were in NO CI - # matrix. Own shard: the t/360 value gate + reconnect deadline - # need the wall clock. (t/359 gapwalk runs in stage7-multixact.) - - { name: stage7-data-plane, ranges: "358 360", unit: false, regress: false } - # t/362 spec-4.6a 4-node shared_catalog kill self-heal (L464 - # occupancy verified against origin branches 2026-07-08). Own - # shard: 4-node formation + kill + convergence needs the wall - # clock. - - { name: stage7-reconfig-liveness, ranges: "362-362", unit: false, regress: false } - # t/363 spec-2.29a marker-async LMON liveness. - - { name: stage7-marker-async, ranges: "363-363", unit: false, regress: false } - # t/364 + t/367 spec-7.3 LMS worker-pool family (single-node pool - # smoke + 2-node topology / multi-tag routing / recycle / N=1 - # sentinel). Every new t/ file lands in a shard the same commit - # (L342). - - { name: stage7-lms-pool, ranges: "364 367", unit: false, regress: false } - # t/365 spec-7.1a cross-instance write-write MVCC coordination. - - { name: stage7-write-write, ranges: "365-365", unit: false, regress: false } - # t/366 spec-7.2a GCS block dedup capacity + eager reclaim, plus - # t/371 GCS_DONE mixed-version compat (suppressed pre-protocol - # binary at the default cap). Own shard: 2-node shared_catalog - # bring-up + cross-node distinct-read dedup pressure + injected - # retransmit-dedup correctness needs the wall clock. - - { name: stage7-gcs-dedup-capacity, ranges: "366 371", unit: false, regress: false } - # t/359 mxid-stripe gapwalk + t/368 multixact member-serve refuse - # (spec-7.1 family; 368 renamed from the double-occupied t/360 per - # the hub number ledger -- the lms data-plane faults file keeps 360). - - { name: stage7-multixact, ranges: "359 368", unit: false, regress: false } - # t/369 spec-5.22d dead-owner authority serve + t/370 spec-5.22e - # cluster-wide undo retention brake (both 2-node shared-root) + - # t/386 spec-2.2 caps-reply directed matrix / rolling-upgrade - # compat / generation legs (3-node triple). Own shard: the brake - # legs pin/stall/self-heal on real cleaner cadence and need the - # wall clock. - - { name: stage5-undo-retention, ranges: "369-370 386 389", unit: false, regress: false } - # t/390 GCS block-ship race convergence (3-node triple): PENDING_X - # dedup re-evaluation (no reply-timeout burn), invalidate-slot - # bounded claim wait, duplicate-reply first-reply-wins. Own shard: - # triple bring-up + injection legs need the wall clock (L342: every - # new t/ file lands in a shard the same commit). - - { name: stage7-gcs-block-race, ranges: "390-390", unit: false, regress: false } - # t/392-397 GCS-race round-2 + ownership-generation wave (2-node - # pairs): raw-xid visibility collision, copy->drop lost-write - # window, W1 cached-cover / W2 restore-ABA / W3 grant-finalize - # window REDs, and the no-injection ownership convergence gate. - # Own shard: six ClusterPair bring-ups need the wall clock - # (L342: every new t/ file lands in a shard the same commit). - - { name: stage7-gcs-ownership-gen, ranges: "392-397", unit: false, regress: false } - # t/401 GCS master-direct STALE-ship storage rescue (PR#55) + - # t/402 undo cleaner stall-retry cadence (PR#56) + t/403 TT-lane - # idle-peer floor pin under write load (all 2-node pairs from the - # S3 wave). t/401/402 predate this shard and were in NO CI - # matrix -- closes that hole (L342: every new t/ file lands in a - # shard the same commit). Own shard: three ClusterPair bring-ups - # + the t/403 sustained write phase need the wall clock. - - { name: stage7-s3-wave, ranges: "401-403", unit: false, regress: false } - # t/400 PCM-X convert-queue 4-node liveness (ClusterQuad bring-up) - # + t/404 crash-rejoin stale-read/write fence (2-node with a full - # crash/restart cycle). Both were in NO CI matrix (L342: every new - # t/ file lands in a shard the same commit). Own shard: the quad - # formation and the rejoin crash cycle dominate the wall clock. - - { name: stage7-queue-liveness-rejoin, ranges: "400 404", unit: false, regress: false } - steps: - - name: Checkout - uses: actions/checkout@v4 - - # spec-5.21 D2 Part A (evidence-completeness) checks each Stage 5 sub-spec - # ship tag is an ancestor of HEAD. A default shallow checkout (depth 1) - # both omits the tags AND makes `git merge-base --is-ancestor` return - # rc=1 (ancestry cannot be established through a truncated history), so - # the shard must UNSHALLOW here. Only the beta shard needs it. Errors - # are NOT swallowed: if this fails the shard goes red rather than silently - # skipping the evidence-completeness gate (rule 8.B). - - name: Unshallow + fetch tags (beta evidence-completeness) - if: matrix.shard.name == 'stage5-beta-chaos-soak' - run: | - git fetch --unshallow --tags --force origin 2>/dev/null \ - || git fetch --tags --force origin - - - name: Install Linux dependencies - run: | - sudo apt-get update -y - sudo apt-get install -y --no-install-recommends \ - build-essential ccache \ - libreadline-dev zlib1g-dev libicu-dev \ - liblz4-dev libzstd-dev libssl-dev libxml2-dev \ - libipc-run-perl pkg-config - - - name: Restore ccache - uses: actions/cache@v4 - with: - path: .ccache - key: ${{ runner.os }}-${{ github.job }}-${{ matrix.shard.name }}-ccache-${{ github.ref_name }} - restore-keys: | - ${{ runner.os }}-${{ github.job }}-${{ matrix.shard.name }}-ccache- - ${{ runner.os }}-${{ github.job }}-ccache- - ${{ runner.os }}-ccache- - - - name: Configure ccache - run: | - ccache --max-size=700M - ccache --zero-stats - - - name: Configure (--enable-cluster) - run: | - CC="ccache gcc" ./configure \ - --prefix=$HOME/pgrac-install \ - --enable-cassert --enable-debug \ - --with-openssl --with-icu --with-lz4 --with-zstd \ - --enable-cluster --enable-tap-tests - - - name: Build and install - run: | - make -j$(getconf _NPROCESSORS_ONLN) - ccache --show-stats - make install - - - name: Run cluster_unit - if: matrix.shard.unit - run: make -C src/test/cluster_unit check - - - name: Run cluster_regress (foundation-core shard only) - if: matrix.shard.regress - run: make -C src/test/cluster_regress check - - - name: Run cluster_tap shard ${{ matrix.shard.name }} - env: - # Harmless to set everywhere. The medium Stage 2 acceptance job - # owns t/202; keep the env here so manual shard experiments behave - # the same if t/202 is temporarily included in a range. - STAGE2_PERF_HARD_GATE: '1' - run: | - SEL=$(cd src/test/cluster_tap && ranges="${{ matrix.shard.ranges }}"; for f in t/*.pl; do \ - n=$(basename "$f" .pl | cut -d_ -f1); \ - d=$((10#$n)); \ - include=0; \ - for r in $ranges; do \ - lo=${r%-*}; hi=${r#*-}; \ - lo_d=$((10#$lo)); hi_d=$((10#$hi)); \ - if [ "$d" -ge "$lo_d" ] && [ "$d" -le "$hi_d" ]; then \ - include=1; break; \ - fi; \ - done; \ - if [ "$include" -eq 1 ]; then \ - printf '%s ' "$f"; \ - fi; \ - done) - echo "shard ${{ matrix.shard.name }} files: $SEL" - test -n "$SEL" || { echo "ERROR: empty shard selection"; exit 1; } - make -C src/test/cluster_tap check PROVE_TESTS="$SEL" - - - name: Upload cluster_tap diffs on failure - if: failure() - uses: actions/upload-artifact@v4 - with: - name: nightly-cluster-tap-diffs-${{ matrix.shard.name }} - path: | - src/test/cluster_regress/regression.diffs - src/test/cluster_regress/regression.out - src/test/cluster_regress/log/ - src/test/cluster_tap/tmp_check/log/ - if-no-files-found: ignore - retention-days: 14 - - # ==================================================================== - # Tier 2.1c — macOS Build+Test (smoke) - # -------------------------------------------------------------------- - # macOS keeps build + PG 219 + cluster_unit + cluster_regress + a curated - # cluster_tap SMOKE subset only (the full cluster_tap on macOS was the - # ~22min nightly bottleneck; Linux runs the full suite, sharded, above). - # The smoke deliberately INCLUDES the concurrency-sensitive spec-3.19 - # 234/235 (macOS shmem/IPC behaviour is exactly where those matter most). - # ==================================================================== build-test-macos: name: macOS Build+Test (smoke) runs-on: macos-latest @@ -371,6 +89,8 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 + with: + fetch-depth: 0 - name: Install macOS dependencies run: | @@ -416,9 +136,9 @@ jobs: - name: Run cluster smoke (unit + regress + curated TAP) run: | - make -C src/test/cluster_unit check + make -j$(sysctl -n hw.ncpu) -C src/test/cluster_unit check make -C src/test/cluster_regress check - SMOKE="t/001_single_node_smoke.pl t/005_wait_events_catalog.pl t/020_shmem_registry.pl t/068_wal_xl_scn.pl t/215_cluster_3_9_cr_construction.pl t/219_cluster_3_11_durable_tt_slot.pl t/226_stage3_mvcc_acceptance_capability.pl t/234_cluster_3_19_dml_boundary.pl t/235_cluster_3_19_snapshot_isolation.pl" + SMOKE="$(python3 scripts/ci/mvp_ci.py --smoke)" make -C src/test/cluster_tap check PROVE_TESTS="$SMOKE" - name: Upload regression diffs on failure @@ -436,155 +156,3 @@ jobs: src/test/cluster_tap/tmp_check/log/ if-no-files-found: ignore retention-days: 14 - - # ==================================================================== - # Tier 2.2 — Stage 2 acceptance medium representative job - # -------------------------------------------------------------------- - # Self-contained Ubuntu job. It intentionally rebuilds/install locally - # instead of assuming workspace or install artifacts from other jobs. - # Runs the Stage 2 acceptance TAPs with longer knobs than fast-gate and - # uploads the generated JSON reports. - # ==================================================================== - stage2-acceptance-medium: - name: Stage 2 acceptance medium (Ubuntu) - runs-on: ubuntu-latest - timeout-minutes: 90 - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Install Linux dependencies - run: | - sudo apt-get update -y - sudo apt-get install -y --no-install-recommends \ - build-essential ccache \ - libreadline-dev zlib1g-dev libicu-dev \ - liblz4-dev libzstd-dev libssl-dev libxml2-dev \ - libipc-run-perl pkg-config - - - name: Restore ccache - uses: actions/cache@v4 - with: - path: .ccache - key: ${{ runner.os }}-${{ github.job }}-ccache-${{ github.ref_name }} - restore-keys: | - ${{ runner.os }}-${{ github.job }}-ccache- - ${{ runner.os }}-ccache- - - - name: Configure ccache - run: | - ccache --max-size=700M - ccache --zero-stats - - - name: Configure (--enable-cluster) - run: | - CC="ccache gcc" ./configure \ - --prefix=$HOME/pgrac-install \ - --enable-cassert --enable-debug \ - --with-openssl --with-icu --with-lz4 --with-zstd \ - --enable-cluster --enable-tap-tests - - - name: Build and install - run: | - make -j$(getconf _NPROCESSORS_ONLN) - ccache --show-stats - make install - - - name: Run Stage 2 acceptance TAP matrix - env: - STAGE2_TAG: ${{ github.ref_name }} - STAGE2_PGBENCH_SECONDS: "20" - STAGE2_WORKLOAD_SECONDS: "1" - STAGE2_WORKLOAD_ITERATIONS: "20" - run: | - make -C src/test/cluster_tap check \ - PROVE_TESTS="t/200_stage2_acceptance_capability.pl t/201_stage2_acceptance_fault_matrix.pl t/202_stage2_acceptance_perf_smoke.pl" - - - name: Upload Stage 2 acceptance reports - if: always() - uses: actions/upload-artifact@v4 - with: - name: stage2-acceptance-medium-${{ github.run_id }} - path: | - src/test/cluster_tap/tmp/stage2-acceptance-*.json - src/test/cluster_tap/tmp_check/log/ - if-no-files-found: ignore - retention-days: 30 - - # ==================================================================== - # Tier 2.3 — Stage 3 MVCC acceptance medium representative job - # -------------------------------------------------------------------- - # Self-contained Ubuntu job (rebuilds/install locally). Runs the - # spec-3.17 Stage 3 acceptance TAPs — capability cross-cutting (t/226) - # and the workload perf smoke (t/227, pgbench) — with longer knobs than - # fast-gate, plus the static contract unit binary, and uploads the - # generated JSON reports. All perf numbers are report-only (the Stage 3 - # performance bar is owned by spec-3.18); this job gates only on the - # functional/correctness assertions. - # ==================================================================== - stage3-acceptance-medium: - name: Stage 3 acceptance medium (Ubuntu) - runs-on: ubuntu-latest - timeout-minutes: 90 - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Install Linux dependencies - run: | - sudo apt-get update -y - sudo apt-get install -y --no-install-recommends \ - build-essential ccache \ - libreadline-dev zlib1g-dev libicu-dev \ - liblz4-dev libzstd-dev libssl-dev libxml2-dev \ - libipc-run-perl pkg-config - - - name: Restore ccache - uses: actions/cache@v4 - with: - path: .ccache - key: ${{ runner.os }}-${{ github.job }}-ccache-${{ github.ref_name }} - restore-keys: | - ${{ runner.os }}-${{ github.job }}-ccache- - ${{ runner.os }}-ccache- - - - name: Configure ccache - run: | - ccache --max-size=700M - ccache --zero-stats - - - name: Configure (--enable-cluster) - run: | - CC="ccache gcc" ./configure \ - --prefix=$HOME/pgrac-install \ - --enable-cassert --enable-debug \ - --with-openssl --with-icu --with-lz4 --with-zstd \ - --enable-cluster --enable-tap-tests - - - name: Build and install - run: | - make -j$(getconf _NPROCESSORS_ONLN) - ccache --show-stats - make install - - - name: Run Stage 3 static contract unit binary - run: make -C src/test/cluster_unit check - - - name: Run Stage 3 acceptance TAP matrix - env: - PGRAC_TAG: ${{ github.ref_name }} - STAGE3_PGBENCH_SECONDS: "20" - run: | - make -C src/test/cluster_tap check \ - PROVE_TESTS="t/226_stage3_mvcc_acceptance_capability.pl t/227_stage3_mvcc_workload_smoke.pl" - - - name: Upload Stage 3 acceptance reports - if: always() - uses: actions/upload-artifact@v4 - with: - name: stage3-acceptance-medium-${{ github.run_id }} - path: | - src/test/cluster_tap/tmp/stage3-acceptance-*.json - src/test/cluster_tap/tmp_check/log/ - if-no-files-found: ignore - retention-days: 30 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 45bc4319c79..21862b61feb 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -45,8 +45,32 @@ concurrency: permissions: contents: read + actions: read jobs: + mvp-ci: + name: Verify exact-commit MVP CI + needs: principle-0 + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Verify all required jobs actually passed + env: + GH_TOKEN: ${{ github.token }} + RELEASE_REPOSITORY: ${{ github.repository }} + RELEASE_SHA: ${{ github.sha }} + run: | + python3 scripts/ci/mvp_ci.py --verify-release \ + --repository "$RELEASE_REPOSITORY" --sha "$RELEASE_SHA" \ + > mvp-ci-evidence.json + - name: Preserve release CI evidence + uses: actions/upload-artifact@v4 + with: + name: mvp-ci-evidence-${{ github.sha }} + path: mvp-ci-evidence.json + retention-days: 30 + # ------------------------------------------------------------------------- # Principle-0 compliance: the public release artifacts must carry no private # design reasoning. A leak into a public release is permanent, so this is a @@ -73,7 +97,7 @@ jobs: # ------------------------------------------------------------------------- package: name: Package (${{ matrix.os }}) - needs: principle-0 + needs: [principle-0, mvp-ci] strategy: fail-fast: false matrix: diff --git a/docs/ci/historical-results-2026-09-17.json b/docs/ci/historical-results-2026-09-17.json new file mode 100644 index 00000000000..01d3e83c5fc --- /dev/null +++ b/docs/ci/historical-results-2026-09-17.json @@ -0,0 +1,169 @@ +{ + "conclusion": "failure", + "created_at": "2026-09-17T03:46:33Z", + "jobs": [ + { + "conclusion": "success", + "name": "Linux PG 219 regression", + "url": "https://github.com/sqlrush/pgrac/actions/runs/35179423876/job/105068171988" + }, + { + "conclusion": "failure", + "name": "macOS Build+Test (smoke)", + "url": "https://github.com/sqlrush/pgrac/actions/runs/35179423876/job/105068172097" + }, + { + "conclusion": "failure", + "name": "Stage 3 acceptance medium (Ubuntu)", + "url": "https://github.com/sqlrush/pgrac/actions/runs/35179423876/job/105068172149" + }, + { + "conclusion": "failure", + "name": "Stage 2 acceptance medium (Ubuntu)", + "url": "https://github.com/sqlrush/pgrac/actions/runs/35179423876/job/105068172166" + }, + { + "conclusion": "failure", + "name": "Linux cluster_tap (foundation-stage1)", + "url": "https://github.com/sqlrush/pgrac/actions/runs/35179423876/job/105068172219" + }, + { + "conclusion": "failure", + "name": "Linux cluster_tap (stage3-core)", + "url": "https://github.com/sqlrush/pgrac/actions/runs/35179423876/job/105068172240" + }, + { + "conclusion": "failure", + "name": "Linux cluster_tap (stage2-ic-cssd)", + "url": "https://github.com/sqlrush/pgrac/actions/runs/35179423876/job/105068172241" + }, + { + "conclusion": "failure", + "name": "Linux cluster_tap (stage7-gcs-block-race)", + "url": "https://github.com/sqlrush/pgrac/actions/runs/35179423876/job/105068172250" + }, + { + "conclusion": "failure", + "name": "Linux cluster_tap (stage7-data-plane)", + "url": "https://github.com/sqlrush/pgrac/actions/runs/35179423876/job/105068172251" + }, + { + "conclusion": "failure", + "name": "Linux cluster_tap (stage2-gcs)", + "url": "https://github.com/sqlrush/pgrac/actions/runs/35179423876/job/105068172260" + }, + { + "conclusion": "failure", + "name": "Linux cluster_tap (stage5-integrated-acceptance)", + "url": "https://github.com/sqlrush/pgrac/actions/runs/35179423876/job/105068172261" + }, + { + "conclusion": "failure", + "name": "Linux cluster_tap (stage7-lms-pool)", + "url": "https://github.com/sqlrush/pgrac/actions/runs/35179423876/job/105068172265" + }, + { + "conclusion": "success", + "name": "Linux cluster_tap (stage5-hang-acceptance)", + "url": "https://github.com/sqlrush/pgrac/actions/runs/35179423876/job/105068172279" + }, + { + "conclusion": "failure", + "name": "Linux cluster_tap (stage7-s3-wave)", + "url": "https://github.com/sqlrush/pgrac/actions/runs/35179423876/job/105068172283" + }, + { + "conclusion": "failure", + "name": "Linux cluster_tap (stage5-ges-locking)", + "url": "https://github.com/sqlrush/pgrac/actions/runs/35179423876/job/105068172288" + }, + { + "conclusion": "failure", + "name": "Linux cluster_tap (stage7-queue-liveness-rejoin)", + "url": "https://github.com/sqlrush/pgrac/actions/runs/35179423876/job/105068172291" + }, + { + "conclusion": "failure", + "name": "Linux cluster_tap (stage4-wal)", + "url": "https://github.com/sqlrush/pgrac/actions/runs/35179423876/job/105068172292" + }, + { + "conclusion": "failure", + "name": "Linux cluster_tap (foundation-core)", + "url": "https://github.com/sqlrush/pgrac/actions/runs/35179423876/job/105068172296" + }, + { + "conclusion": "failure", + "name": "Linux cluster_tap (stage7-gcs-ownership-gen)", + "url": "https://github.com/sqlrush/pgrac/actions/runs/35179423876/job/105068172308" + }, + { + "conclusion": "failure", + "name": "Linux cluster_tap (stage3-recent)", + "url": "https://github.com/sqlrush/pgrac/actions/runs/35179423876/job/105068172311" + }, + { + "conclusion": "failure", + "name": "Linux cluster_tap (stage7-write-write)", + "url": "https://github.com/sqlrush/pgrac/actions/runs/35179423876/job/105068172333" + }, + { + "conclusion": "failure", + "name": "Linux cluster_tap (stage7-marker-async)", + "url": "https://github.com/sqlrush/pgrac/actions/runs/35179423876/job/105068172345" + }, + { + "conclusion": "failure", + "name": "Linux cluster_tap (stage6-storage)", + "url": "https://github.com/sqlrush/pgrac/actions/runs/35179423876/job/105068172351" + }, + { + "conclusion": "failure", + "name": "Linux cluster_tap (stage6-crossnode-b)", + "url": "https://github.com/sqlrush/pgrac/actions/runs/35179423876/job/105068172360" + }, + { + "conclusion": "failure", + "name": "Linux cluster_tap (stage7-gcs-dedup-capacity)", + "url": "https://github.com/sqlrush/pgrac/actions/runs/35179423876/job/105068172361" + }, + { + "conclusion": "failure", + "name": "Linux cluster_tap (stage4-hardgate)", + "url": "https://github.com/sqlrush/pgrac/actions/runs/35179423876/job/105068172380" + }, + { + "conclusion": "success", + "name": "Linux cluster_tap (stage5-beta-chaos-soak)", + "url": "https://github.com/sqlrush/pgrac/actions/runs/35179423876/job/105068172381" + }, + { + "conclusion": "failure", + "name": "Linux cluster_tap (stage5-undo-retention)", + "url": "https://github.com/sqlrush/pgrac/actions/runs/35179423876/job/105068172397" + }, + { + "conclusion": "failure", + "name": "Linux cluster_tap (stage6-crossnode-a)", + "url": "https://github.com/sqlrush/pgrac/actions/runs/35179423876/job/105068172399" + }, + { + "conclusion": "failure", + "name": "Linux cluster_tap (stage7-reconfig-liveness)", + "url": "https://github.com/sqlrush/pgrac/actions/runs/35179423876/job/105068172434" + }, + { + "conclusion": "failure", + "name": "Linux cluster_tap (stage7-multixact)", + "url": "https://github.com/sqlrush/pgrac/actions/runs/35179423876/job/105068172498" + } + ], + "run_id": 35179423876, + "source_commit": "1fad868aeff51de2b7946c766871cf0d427a7286", + "url": "https://github.com/sqlrush/pgrac/actions/runs/35179423876", + "scope": "Historical extended CI; non-blocking for the current MVP by maintainer decision on 2026-09-17. Failures remain failures; no capability PASS is implied.", + "summary": { + "success": 3, + "failure": 28 + } +} diff --git a/scripts/ci/README.md b/scripts/ci/README.md index 74dc114f167..5f445f936ba 100644 --- a/scripts/ci/README.md +++ b/scripts/ci/README.md @@ -2,8 +2,79 @@ > Author: SqlRush \ -CI/CD helper scripts invoked by `.github/workflows/ci.yml`. Designed -to be runnable locally for layer-2 gate (commit-time) checks. +CI/CD helpers for the current MVP gates in `fast.yml` and `nightly.yml`. +Historical extended qualification remains in `legacy-extended.yml`. + +## Current MVP release gate + +The release policy is [mvp-policy.json](mvp-policy.json). Both workflows must +pass on the **exact release commit**, with every required job actually run: + +| Workflow | Required coverage | +|---|---| +| `fast.yml` | Validate; strict cppcheck and completed Clang analysis; enabled Linux build, all registered C units, 13 cluster SQL tests and MVP TAP smoke; disabled Linux build and 219 native PG tests; macOS build and all registered C units | +| `nightly.yml` | Enabled Linux 219 native PG tests; macOS 219 native PG tests, all registered C units, 13 cluster SQL tests and the same MVP TAP smoke | + +The six smoke files are `010`, `030`, `031`, `050`, `200`, and `332`. +They cover views, acceptance observability, safe undo-publication refusal, +shared-storage initialization, basic cluster capability and single-node raw +backend checks. This gate does not claim four-host shared-LUN deployment, +positive crash recovery, prepared transactions, or performance certification. +It does not replace the separately recorded C8/soak/micro/D7/PRE results. + +All registered unit tests remain mandatory, including safety and negative tests. +Compilation may run in parallel; the unit runner still executes every binary +and propagates failures. No product timeout is changed. `cppcheck` remains +strict with a zero-report baseline and narrowly documented suppressions. +Clang findings retain the existing warn-only policy and published reports; +a failed compiler, analyzer command or cleanup is a CI failure. + +### Historical extended checks + +The maintainer approved this MVP scope on 2026-09-17. The previous full nightly +workflow is preserved as `legacy-extended.yml`, with the same test commands, +failure exits, schedule and log uploads. It can fail independently; it is not +converted into a successful or skipped MVP check. + +Former fast files `226` and `273` include legacy positive 2PC/recovery +qualification; `333` uses an old multi-node raw-device deployment fixture. +They remain in the historical workflow. Other historical shards cover old +setup/protocol expectations, recovery, faults, deployment and performance. +Non-blocking does not mean every failure is obsolete or safe to ignore: +supported-path defects still require triage and repair. + +The [31-job historical result record](../../docs/ci/historical-results-2026-09-17.json) +preserves the source commit, 3 PASS / 28 FAIL outcomes and original job links. +Original artifacts remain subject to GitHub retention. No historical test +source was removed by the scope change. + +### Before packaging + +Run the MVP nightly on the candidate, wait for both workflows, then verify the +full immutable commit (requires authenticated `gh`): + +```bash +gh workflow run fast.yml --ref +gh workflow run nightly.yml --ref +python3 scripts/ci/mvp_ci.py --verify-release \ + --repository sqlrush/pgrac --sha <40-character-commit-sha> +``` + +The checker rejects missing/incomplete runs, skipped required jobs, an older +commit, a different workflow, and fallback to an earlier green after a newer +failure. Documentation-only fast runs do not qualify a release. Historical +results are not counted as MVP passes. PR runs test a synthetic merge, so they +do not certify the head commit for release; use the full manual runs above, +or completed push/scheduled runs that check out the exact commit. +Packaging in `release.yml` depends on +this checker and preserves its JSON evidence; it does not publish a Release. +If a tag-triggered package starts before CI finishes, it fails closed and must +be rerun after the required checks finish. + +```bash +python3 scripts/ci/test_mvp_ci.py +python3 scripts/ci/test_scan_build.py +``` ## Scripts diff --git a/scripts/ci/check-format.sh b/scripts/ci/check-format.sh index 065d3bd007e..8a1ec33a35d 100755 --- a/scripts/ci/check-format.sh +++ b/scripts/ci/check-format.sh @@ -28,9 +28,9 @@ set -e set -o pipefail -# Locate clang-format. Prefer clang-format 18 because GitHub Actions -# ubuntu-24.04 installs 18.1.x, and later releases differ on comment -# alignment in several long-lived cluster files. +# Locate clang-format. GitHub Actions ubuntu-24.04 uses 18.1.3. +# Even 18.1.8 differs on braced macro initializers; use CLANG_FORMAT to +# select 18.1.3 when the locally installed patch release differs. if [ -z "${CLANG_FORMAT:-}" ]; then for candidate in \ clang-format-18 \ diff --git a/scripts/ci/mvp-policy.json b/scripts/ci/mvp-policy.json new file mode 100644 index 00000000000..cddac22e007 --- /dev/null +++ b/scripts/ci/mvp-policy.json @@ -0,0 +1,30 @@ +{ + "schema_version": 1, + "required_workflows": { + "fast.yml": [ + "Validate (comment headers + format + tidy + commit msg)", + "Security (cppcheck + scan-build)", + "Linux --disable-cluster regression", + "macOS build-only (compile guard)", + "Linux enable-cluster (unit + regress + smoke TAP)" + ], + "nightly.yml": [ + "Linux PG 219 regression", + "macOS Build+Test (smoke)" + ] + }, + "smoke_tests": [ + "t/010_views.pl", + "t/030_acceptance.pl", + "t/031_undo_publication_refusal.pl", + "t/050_shared_storage_initdb.pl", + "t/200_stage2_acceptance_capability.pl", + "t/332_block_device_backend.pl" + ], + "historical_workflow": "legacy-extended.yml", + "historical_fast_tests": { + "t/226_stage3_mvcc_acceptance_capability.pl": "Mixed legacy capability fixture including positive prepared transactions and immediate-stop recovery.", + "t/273_stage4_recovery_acceptance_capability.pl": "Legacy positive recovery qualification, outside the current MVP release scope.", + "t/333_block_device_multinode.pl": "Legacy raw-device multi-node deployment fixture, not the qualified MVP single-host shared-filesystem topology." + } +} diff --git a/scripts/ci/mvp_ci.py b/scripts/ci/mvp_ci.py new file mode 100644 index 00000000000..1b4a38b4296 --- /dev/null +++ b/scripts/ci/mvp_ci.py @@ -0,0 +1,123 @@ +#!/usr/bin/env python3 +"""Select MVP smoke tests or verify exact-commit release CI evidence. + +Author: SqlRush +Copyright (c) 2026, pgrac contributors +""" + +import argparse +import json +from pathlib import Path +import re +import subprocess +import sys + + +ROOT = Path(__file__).resolve().parents[2] +EXACT_CHECKOUT_EVENTS = {"push", "workflow_dispatch", "schedule"} + + +def load_policy(): + policy = json.loads((ROOT / "scripts/ci/mvp-policy.json").read_text()) + if policy.get("schema_version") != 1: + raise ValueError("unsupported MVP CI policy version") + for workflow, names in policy["required_workflows"].items(): + if not (ROOT / ".github/workflows" / workflow).is_file(): + raise ValueError(f"missing required workflow: {workflow}") + if not names or len(names) != len(set(names)): + raise ValueError(f"empty or duplicate required jobs: {workflow}") + smoke = policy["smoke_tests"] + if not smoke or len(smoke) != len(set(smoke)): + raise ValueError("empty or duplicate MVP smoke selection") + if set(smoke) & set(policy["historical_fast_tests"]): + raise ValueError("a smoke test cannot also be historical") + for name in [*smoke, *policy["historical_fast_tests"]]: + if not re.fullmatch(r"t/[0-9]{3}_[A-Za-z0-9_]+\.pl", name): + raise ValueError(f"invalid TAP path: {name}") + if not (ROOT / "src/test/cluster_tap" / name).is_file(): + raise ValueError(f"missing retained TAP test: {name}") + if not (ROOT / ".github/workflows" / policy["historical_workflow"]).is_file(): + raise ValueError("missing historical workflow") + return policy + + +def latest_run(runs, sha): + # PR head_sha identifies the branch, but checkout normally tests a merge. + exact = [run for run in runs if run.get("head_sha") == sha + and run.get("event") in EXACT_CHECKOUT_EVENTS] + if not exact: + raise ValueError(f"no CI run for exact commit {sha}") + return max(exact, key=lambda run: run["id"]) + + +def validate_run(workflow, sha, run, jobs, required): + if run.get("event") not in EXACT_CHECKOUT_EVENTS: + raise ValueError(f"{workflow}: event does not prove exact-commit checkout") + if run.get("head_sha") != sha or run.get("path") != f".github/workflows/{workflow}": + raise ValueError(f"{workflow}: evidence identity mismatch") + if run.get("status") != "completed" or run.get("conclusion") != "success": + raise ValueError(f"{workflow}: latest exact-commit run is not successful") + for name in required: + matches = [job for job in jobs if job.get("name") == name] + if len(matches) != 1: + raise ValueError(f"{workflow}: expected exactly one executed job: {name}") + job = matches[0] + if job.get("status") != "completed" or job.get("conclusion") != "success": + raise ValueError(f"{workflow}: required job did not pass: {name}") + + +def gh_json(endpoint, paginate=False): + args = ["gh", "api", endpoint] + if paginate: + args += ["--paginate", "--slurp"] + return json.loads(subprocess.run(args, check=True, capture_output=True, text=True).stdout) + + +def verify_release(repository, sha, policy): + if not re.fullmatch(r"[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+", repository or ""): + raise ValueError("--repository must be owner/repository") + if not re.fullmatch(r"[0-9a-f]{40}", sha or ""): + raise ValueError("--sha must be the full lowercase commit SHA") + evidence = {"repository": repository, "sha": sha, "workflows": []} + for workflow, required in policy["required_workflows"].items(): + runs = gh_json( + f"repos/{repository}/actions/workflows/{workflow}/runs?head_sha={sha}&per_page=100" + )["workflow_runs"] + run = latest_run(runs, sha) + pages = gh_json( + f"repos/{repository}/actions/runs/{run['id']}/jobs?filter=latest&per_page=100", + paginate=True, + ) + jobs = [job for page in pages for job in page["jobs"]] + validate_run(workflow, sha, run, jobs, required) + evidence["workflows"].append({ + "workflow": workflow, "run_id": run["id"], + "event": run["event"], + "run_attempt": run["run_attempt"], "url": run["html_url"], + "required_jobs": required, + }) + return evidence + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + mode = parser.add_mutually_exclusive_group(required=True) + mode.add_argument("--smoke", action="store_true") + mode.add_argument("--verify-release", action="store_true") + parser.add_argument("--repository") + parser.add_argument("--sha") + args = parser.parse_args() + try: + policy = load_policy() + if args.smoke: + print(" ".join(policy["smoke_tests"])) + else: + print(json.dumps(verify_release(args.repository, args.sha, policy), indent=2)) + except (OSError, ValueError, KeyError, subprocess.CalledProcessError) as exc: + print(f"MVP CI evidence refused: {exc}", file=sys.stderr) + return 1 + return 0 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/scripts/ci/run-cppcheck.sh b/scripts/ci/run-cppcheck.sh index e20c5128b3e..6e2b2382c79 100755 --- a/scripts/ci/run-cppcheck.sh +++ b/scripts/ci/run-cppcheck.sh @@ -8,9 +8,9 @@ # Design: pgrac/docs/ci-static-analysis.md # # Scans: -# - src/backend/cluster/ (~10 .c files, ~3000 LOC) -# - src/include/cluster/ (~10 .h files) -# - src/test/cluster_unit/ (~14 .c files) +# - src/backend/cluster/ +# - src/include/cluster/ +# - src/test/cluster_unit/ # # Excludes PG-upstream code by design (PG has its own cppcheck # buildfarm + Coverity scan; pgrac is only responsible for cluster @@ -25,8 +25,8 @@ # # NOTES # Exit codes: -# 0 - always (warn-only at stage 0.27.5 - 0.30; the SARIF -# artifact carries the actual findings, not the exit code) +# 0 - scan completed with no findings beyond the frozen baseline +# 1 - new findings (strict baseline comparison) # 2 - cppcheck binary not found # # Configuration: @@ -36,7 +36,7 @@ # 'missingInclude' because cppcheck cannot resolve PG's # hand-rolled include layout reliably) # --inline-suppr enable inline /* cppcheck-suppress xxx */ -# --suppressions-list scripts/ci/cppcheck-suppressions.txt +# --suppress=... narrowly documented CLI suppressions below # --xml --xml-version=2 machine-readable for artifact upload # -DUSE_PGRAC_CLUSTER=1 match enable-cluster build mode # @@ -98,6 +98,21 @@ PG_HEADER_SUPP=( # are out of pgrac scope per spec-0.27.5 §1.2. --suppress=constParameterPointer:src/include/port/atomics/generic.h --suppress=integerOverflowCond:src/include/port/atomics/generic.h + # The initdb fixture includes PG's complete initdb.c and file_utils.c. + # These exact sites are unchanged upstream bodies, not PGRAC sections. + --suppress=knownConditionTrueFalse:src/common/file_utils.c:432 + --suppress=knownConditionTrueFalse:src/bin/initdb/initdb.c:1519 + --suppress=variableScope:src/bin/initdb/initdb.c:888 + --suppress=variableScope:src/bin/initdb/initdb.c:980 + --suppress=variableScope:src/bin/initdb/initdb.c:1176 + --suppress=shadowVariable:src/bin/initdb/initdb.c:857 + --suppress=shadowVariable:src/bin/initdb/initdb.c:1087 + --suppress=constVariablePointer:src/bin/initdb/initdb.c:515 + --suppress=constVariablePointer:src/bin/initdb/initdb.c:2167 + --suppress=constVariablePointer:src/bin/initdb/initdb.c:2168 + --suppress=constVariablePointer:src/bin/initdb/initdb.c:2169 + --suppress=constVariablePointer:src/bin/initdb/initdb.c:2225 + --suppress=constVariablePointer:src/bin/initdb/initdb.c:2625 ) # Reason: PG's Assert() is non-trapping by spec to cppcheck (it has no @@ -226,8 +241,8 @@ UNIT_STUB_SUPP=( echo "## cppcheck $(cppcheck --version)" echo "Scanning: ${CLUSTER_DIRS[*]}" -# --error-exitcode=0 keeps the exit non-fatal (warn-only). Findings -# go to cppcheck.xml; a human-readable summary is built downstream. +# The scanner writes all findings first; the strict baseline comparison +# below determines the final exit status without losing the XML artifact. cppcheck \ --enable=warning,style,performance,portability \ "${GLOBAL_SUPP[@]}" \ @@ -242,6 +257,36 @@ cppcheck \ -DUSE_PGRAC_CLUSTER=1 \ '-DHEAPAM_SOURCE_PATH="src/backend/access/heap/heapam.c"' \ '-DTT_LOCAL_SOURCE_PATH="src/backend/cluster/cluster_tt_local.c"' \ + "-DCLUSTER_CR_SOURCE_PATH=\"$REPO_ROOT/src/backend/cluster/cluster_cr.c\"" \ + '-DCR_SERVER_HEADER_PATH="src/include/cluster/cluster_cr_server.h"' \ + '-DCR_SERVER_SOURCE_PATH="src/backend/cluster/cluster_cr_server.c"' \ + '-DCR_SOURCE_PATH="src/backend/cluster/cluster_cr.c"' \ + '-DGCS_HEADER_PATH="src/include/cluster/cluster_gcs_block.h"' \ + '-DGCS_SOURCE_PATH="src/backend/cluster/cluster_gcs_block.c"' \ + '-DPCM_HEADER_PATH="src/include/cluster/cluster_pcm_lock.h"' \ + '-DPCM_SOURCE_PATH="src/backend/cluster/cluster_pcm_lock.c"' \ + '-DBUFMGR_SOURCE_PATH="src/backend/storage/buffer/bufmgr.c"' \ + '-DIC_HEADER_PATH="src/include/cluster/cluster_ic.h"' \ + '-DITL_HEADER_PATH="src/include/cluster/cluster_itl.h"' \ + '-DHEAP_VIS_SOURCE_PATH="src/backend/access/heap/heapam_visibility.c"' \ + '-DVIS_RESOLVE_SOURCE_PATH="src/backend/cluster/cluster_visibility_resolve.c"' \ + '-DTT_STATUS_HEADER_PATH="src/include/cluster/cluster_tt_status.h"' \ + '-DTT_STATUS_SOURCE_PATH="src/backend/cluster/cluster_tt_status.c"' \ + '-DTT_HINT_HEADER_PATH="src/include/cluster/cluster_tt_status_hint.h"' \ + '-DTT_HINT_SOURCE_PATH="src/backend/cluster/cluster_tt_status_hint.c"' \ + '-DMULTIXACT_HEADER_PATH="src/include/cluster/cluster_multixact.h"' \ + '-DMULTIXACT_SOURCE_PATH="src/backend/cluster/cluster_multixact.c"' \ + '-DTX_RESOLVE_HEADER_PATH="src/include/cluster/cluster_tx_resolve.h"' \ + '-DTX_RESOLVE_SOURCE_PATH="src/backend/cluster/cluster_tx_resolve.c"' \ + '-DSEMANTIC_HEADER_PATH="src/include/cluster/cluster_semantic_activation.h"' \ + '-DSEMANTIC_SOURCE_PATH="src/backend/cluster/cluster_semantic_activation.c"' \ + '-DQVOTEC_SOURCE_PATH="src/backend/cluster/cluster_qvotec.c"' \ + '-DTT_2PC_SOURCE_PATH="src/backend/cluster/cluster_tt_2pc.c"' \ + '-DTWOPHASE_SOURCE_PATH="src/backend/access/transam/twophase.c"' \ + '-DHEAPAM_VISIBILITY_SOURCE_PATH="src/backend/access/heap/heapam_visibility.c"' \ + '-DXACT_SOURCE_PATH="src/backend/access/transam/xact.c"' \ + '-DHEAPAM_HANDLER_SOURCE_PATH="src/backend/access/heap/heapam_handler.c"' \ + '-DNBTINSERT_SOURCE_PATH="src/backend/access/nbtree/nbtinsert.c"' \ --quiet \ "${CLUSTER_DIRS[@]}" \ 2> cppcheck.xml diff --git a/scripts/ci/run-scan-build.sh b/scripts/ci/run-scan-build.sh index 1f21ac41cd8..a741dc930f1 100755 --- a/scripts/ci/run-scan-build.sh +++ b/scripts/ci/run-scan-build.sh @@ -22,9 +22,9 @@ # # NOTES # Exit codes: -# 0 - always (warn-only at stage 0.27.5 - 0.30; HTML reports in -# scan-build-report/ carry the actual findings) +# 0 - analysis completed (findings retain the existing warn-only policy) # 2 - scan-build binary not found +# other - preparation, compiler or analyzer execution failed # # Enabled checkers: # security use-after-free / buffer overrun / integer overflow @@ -37,7 +37,7 @@ # #------------------------------------------------------------------------- -set -uo pipefail +set -euo pipefail if ! command -v scan-build >/dev/null 2>&1; then echo "ERROR: scan-build not installed" >&2 @@ -47,6 +47,12 @@ fi REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)" cd "$REPO_ROOT" || exit 2 +CI_ANALYZE_JOBS="${CI_ANALYZE_JOBS:-$(getconf _NPROCESSORS_ONLN)}" +if ! [[ "$CI_ANALYZE_JOBS" =~ ^[1-9][0-9]*$ ]]; then + echo "ERROR: CI_ANALYZE_JOBS must be a positive integer" >&2 + exit 2 +fi + OUT_DIR=scan-build-report rm -rf "$OUT_DIR" mkdir -p "$OUT_DIR" @@ -74,14 +80,13 @@ scan-build \ -disable-checker deadcode.DeadStores \ -disable-checker security.insecureAPI \ --keep-empty \ - make -C src/backend/cluster \ - 2>&1 | tee "$OUT_DIR/scan-build.log" \ - || true + make -j"$CI_ANALYZE_JOBS" -C src/backend/cluster \ + 2>&1 | tee "$OUT_DIR/scan-build.log" REPORT_COUNT=$(find "$OUT_DIR" -name 'report-*.html' 2>/dev/null | wc -l | tr -d ' ') echo "## scan-build summary" echo "scan-build issued $REPORT_COUNT bug reports" echo "Open: $OUT_DIR/index.html (or any report-*.html)" -# Always succeed; CI artifact carries the findings. +# Only successful execution reaches here; artifacts carry analyzer findings. exit 0 diff --git a/scripts/ci/test_mvp_ci.py b/scripts/ci/test_mvp_ci.py new file mode 100644 index 00000000000..2a7884bf6fa --- /dev/null +++ b/scripts/ci/test_mvp_ci.py @@ -0,0 +1,96 @@ +#!/usr/bin/env python3 +"""MVP CI evidence must be complete and tied to the exact release commit. + +Author: SqlRush +Copyright (c) 2026, pgrac contributors +""" + +import copy +import unittest + +import mvp_ci + + +class EvidenceTests(unittest.TestCase): + def setUp(self): + self.sha = "a" * 40 + self.run = { + "id": 7, + "head_sha": self.sha, + "path": ".github/workflows/fast.yml", + "event": "push", + "status": "completed", + "conclusion": "success", + } + self.jobs = [ + {"name": "build", "status": "completed", "conclusion": "success"}, + {"name": "test", "status": "completed", "conclusion": "success"}, + ] + + def validate(self, run=None, jobs=None): + mvp_ci.validate_run( + "fast.yml", self.sha, run or self.run, + self.jobs if jobs is None else jobs, ["build", "test"] + ) + + def test_complete_exact_commit_passes(self): + self.validate() + + def test_wrong_commit_or_workflow_fails(self): + for field, value in [("head_sha", "b" * 40), ("path", "legacy.yml")]: + run = dict(self.run, **{field: value}) + with self.subTest(field=field), self.assertRaises(ValueError): + self.validate(run=run) + + def test_incomplete_or_failed_run_fails(self): + for field, value in [("status", "in_progress"), ("conclusion", "failure")]: + with self.subTest(field=field), self.assertRaises(ValueError): + self.validate(run=dict(self.run, **{field: value})) + + def test_pr_head_sha_does_not_prove_tested_checkout_sha(self): + for event in ["pull_request", "pull_request_target", "workflow_run"]: + run = dict(self.run, event=event) + with self.subTest(event=event), self.assertRaises(ValueError): + self.validate(run=run) + with self.subTest(event=event), self.assertRaises(ValueError): + mvp_ci.latest_run([run], self.sha) + + def test_missing_or_duplicate_job_fails(self): + for jobs in [[], self.jobs[:1], self.jobs + self.jobs[:1]]: + with self.subTest(jobs=jobs), self.assertRaises(ValueError): + self.validate(jobs=jobs) + + def test_docs_only_skips_cannot_qualify_release(self): + for conclusion in ["skipped", "failure", "cancelled", "timed_out", None]: + jobs = copy.deepcopy(self.jobs) + jobs[1]["conclusion"] = conclusion + with self.subTest(conclusion=conclusion), self.assertRaises(ValueError): + self.validate(jobs=jobs) + + def test_latest_failure_cannot_fall_back_to_old_green(self): + later = dict(self.run, id=8, conclusion="failure") + selected = mvp_ci.latest_run([self.run, later], self.sha) + self.assertEqual(selected["id"], 8) + with self.assertRaises(ValueError): + self.validate(run=selected) + + def test_no_exact_candidate_run_fails(self): + with self.assertRaises(ValueError): + mvp_ci.latest_run([self.run], "b" * 40) + + def test_policy_preserves_strict_gates_and_defers_only_old_fast_cases(self): + policy = mvp_ci.load_policy() + self.assertEqual(set(policy["required_workflows"]), {"fast.yml", "nightly.yml"}) + self.assertEqual(len(policy["required_workflows"]["fast.yml"]), 5) + self.assertEqual(len(policy["required_workflows"]["nightly.yml"]), 2) + self.assertEqual(len(policy["smoke_tests"]), 6) + self.assertIn("t/031_undo_publication_refusal.pl", policy["smoke_tests"]) + self.assertEqual( + {name.split("_")[0] for name in policy["historical_fast_tests"]}, + {"t/226", "t/273", "t/333"}, + ) + self.assertEqual(policy["historical_workflow"], "legacy-extended.yml") + + +if __name__ == "__main__": + unittest.main() diff --git a/scripts/ci/test_scan_build.py b/scripts/ci/test_scan_build.py new file mode 100644 index 00000000000..360adfd6bbc --- /dev/null +++ b/scripts/ci/test_scan_build.py @@ -0,0 +1,57 @@ +#!/usr/bin/env python3 +"""CI analyzer execution contract. Author: SqlRush .""" + +import os +from pathlib import Path +import shutil +import subprocess +import tempfile +import unittest + + +class ScanBuildExecution(unittest.TestCase): + def run_helper(self, *, clean_rc=0, analysis_rc=0): + with tempfile.TemporaryDirectory(prefix="pgrac-scan-build-test-") as root: + root = Path(root) + ci = root / "scripts" / "ci" + ci.mkdir(parents=True) + shutil.copyfile(Path(__file__).with_name("run-scan-build.sh"), ci / "run-scan-build.sh") + (root / "src" / "backend" / "cluster").mkdir(parents=True) + commands = root / "commands" + commands.mkdir() + for name, body in { + "make": f"exit {clean_rc}\n", + "scan-build": ( + 'if [ "$1" = --help ]; then echo "fixture scan-build"; exit 0; fi\n' + 'printf "%s\\n" "$@" > "$CAPTURE_ARGS"\n' + f"exit {analysis_rc}\n" + ), + }.items(): + command = commands / name + command.write_text("#!/bin/sh\n" + body) + command.chmod(0o755) + capture = root / "arguments" + env = dict(os.environ, PATH=f"{commands}:{os.environ['PATH']}", + CAPTURE_ARGS=str(capture), CI_ANALYZE_JOBS="2") + result = subprocess.run(["bash", str(ci / "run-scan-build.sh")], + env=env, text=True, capture_output=True, check=False) + return result.returncode, capture.read_text() if capture.exists() else "" + + def test_analysis_build_failure_is_not_success(self): + rc, _ = self.run_helper(analysis_rc=7) + self.assertEqual(rc, 7) + + def test_clean_failure_prevents_analysis(self): + rc, arguments = self.run_helper(clean_rc=9) + self.assertEqual(rc, 9) + self.assertEqual(arguments, "") + + def test_success_uses_parallel_build_without_changing_bug_policy(self): + rc, arguments = self.run_helper() + self.assertEqual(rc, 0) + self.assertIn("-j2\n", arguments) + self.assertNotIn("--status-bugs", arguments) + + +if __name__ == "__main__": + unittest.main() diff --git a/src/backend/access/heap/heapam.c b/src/backend/access/heap/heapam.c index 2e93eb38723..b049653ab5c 100644 --- a/src/backend/access/heap/heapam.c +++ b/src/backend/access/heap/heapam.c @@ -33,6 +33,7 @@ * PGRAC MODIFICATIONS * Modified by: SqlRush * Record bounded metadata for shared MVCC selection misses. + * Keep cluster-only VM acquisition plans out of non-cluster builds. */ #include "postgres.h" @@ -1579,7 +1580,7 @@ cluster_heap_itl_capacity_diagnostic(const ClusterHeapItlTerminalCensus *census, } } -/* Called only after UPDATE's ordinary allocation and terminal census failed. +/* Called after ordinary allocation and terminal census failed. * Recapture under the current page bracket: the preceding census may have * unlocked/relocked it. This capture is never stamped or recycled. All * page ownership and the borrowed new-page pin are released before resolving @@ -1588,6 +1589,7 @@ cluster_heap_itl_capacity_diagnostic(const ClusterHeapItlTerminalCensus *census, static ClusterTxwResult cluster_heap_itl_wait_capacity_after_census(Buffer old_buffer, Buffer new_buffer, Buffer full_buffer, TransactionId xid, + bool lock_only, uint64 *deadline_us, const char **diagnostic_reason) { ClusterHeapItlTerminalCensus census; @@ -1615,7 +1617,7 @@ cluster_heap_itl_wait_capacity_after_census(Buffer old_buffer, Buffer new_buffer * fresh one. Reuse the allocator's exact protection predicate while * content authority is still held; this check never allocates or stamps. */ if (capture_result == CLUSTER_HEAP_ITL_CENSUS_CAPTURED) - fresh_capacity = cluster_itl_has_allocatable_slot(full_buffer, xid, false); + fresh_capacity = cluster_itl_has_allocatable_slot(full_buffer, xid, lock_only); /* No recycle guard is armed by this path; its capture requires flags=0. * The earlier terminal-census owner has already finished/cancelled. */ if (new_buffer != old_buffer) @@ -1688,6 +1690,10 @@ cluster_heap_itl_wait_capacity_after_census(Buffer old_buffer, Buffer new_buffer if ((census.terminal_mask & CLUSTER_HEAP_ITL_SLOT_BIT(i)) != 0) terminal = true; else if (census.outcomes[i] == CLUSTER_TX_IN_PROGRESS) { + /* A lock-only caller may already own a data slot, but that + * does not supply its distinct lock slot. Never wait on self. */ + if (resolution->locator_echo.xid == xid) + continue; if (!active) blocker = resolution->locator_echo; active = true; /* lowest slot index wins, never a raw-xid key */ @@ -1760,7 +1766,15 @@ cluster_heap_test_itl_wait_capacity(Buffer old_buffer, Buffer new_buffer, Buffer const char **diagnostic_reason) { return cluster_heap_itl_wait_capacity_after_census(old_buffer, new_buffer, full_buffer, xid, - deadline_us, diagnostic_reason); + false, deadline_us, diagnostic_reason); +} + +ClusterTxwResult +cluster_heap_test_itl_wait_lock_capacity(Buffer buffer, TransactionId xid, + uint64 *deadline_us, const char **diagnostic_reason) +{ + return cluster_heap_itl_wait_capacity_after_census(buffer, buffer, buffer, xid, + true, deadline_us, diagnostic_reason); } #endif @@ -1847,20 +1861,52 @@ static ClusterHeapPreparedUndoResult cluster_heap_itl_prepare_prepared_undo(Relation relation, Buffer buffer, HeapTuple tuple, TransactionId xid, bool lock_only, ClusterUndoRecordPrepareReceipt *receipt, uint16 payload_len, - bool *targets_invalidated) + bool *targets_invalidated, const char **refusal_reason, + uint64 *capacity_wait_deadline_us, bool *content_unlocked) { ClusterHeapItlCapacityResult capacity_result; ClusterHeapDmlAuthorityGuard dml_guard; ClusterCtrcTargetV1 pending_target; + const char *reason; Assert(receipt != NULL); + if (content_unlocked != NULL) + *content_unlocked = false; + if (refusal_reason != NULL) + *refusal_reason = NULL; capacity_result = cluster_heap_itl_ensure_capacity_with_terminal_census( buffer, xid, lock_only); *targets_invalidated = false; if (capacity_result == CLUSTER_HEAP_ITL_CAPACITY_RETRY_REQUALIFY) return CLUSTER_HEAP_PREPARED_UNDO_RETRY_REQUIRED; - if (capacity_result != CLUSTER_HEAP_ITL_CAPACITY_READY) - return CLUSTER_HEAP_PREPARED_UNDO_REFUSED; + if (capacity_result != CLUSTER_HEAP_ITL_CAPACITY_READY) { + if (lock_only && receipt->ctrc_applied_mask == 0 + && capacity_wait_deadline_us != NULL && content_unlocked != NULL) { + ClusterTxwResult wait_result; + const char *wait_reason; + + /* The existing wait owner releases content before exact blocker + * resolution. Its wake cannot validate this DML's old target. */ + wait_result = cluster_heap_itl_wait_capacity_after_census( + buffer, buffer, buffer, xid, true, capacity_wait_deadline_us, &wait_reason); + *content_unlocked = true; + *targets_invalidated = true; + if (wait_result == CLUSTER_TXW_RESOLVED || wait_result == CLUSTER_TXW_RETRY) + return CLUSTER_HEAP_PREPARED_UNDO_RETRY_REQUIRED; + ereport(ERROR, + (errcode(wait_result == CLUSTER_TXW_TIMEOUT ? ERRCODE_CLUSTER_GES_TIMEOUT + : wait_result == CLUSTER_TXW_DEADLOCK ? ERRCODE_T_R_DEADLOCK_DETECTED + : ERRCODE_PROGRAM_LIMIT_EXCEEDED), + errmsg("ITL slot OVERFLOW before heap tuple lock (INITRANS=%d full)", + CLUSTER_ITL_INITRANS_DEFAULT), + errdetail("PGRAC_FAMILY=ITL_CAPACITY PGRAC_REASON=%s PGRAC_NODE=%d " + "PGRAC_ATTEMPT=0 wait_result=%d deadline_us=" UINT64_FORMAT, + wait_reason, cluster_node_id, (int)wait_result, + *capacity_wait_deadline_us))); + } + reason = "ITL_CAPACITY_REFUSED"; + goto refused; + } /* Terminal census may stamp independently-authorized cleanout bytes. * Capture the DML attempt only after that preparatory work is complete, * after any tuple-header change has returned RETRY_REQUALIFY above. @@ -1868,22 +1914,30 @@ cluster_heap_itl_prepare_prepared_undo(Relation relation, Buffer buffer, HeapTup if (!cluster_heap_dml_authority_guard_capture( buffer, tuple, &dml_guard)) return CLUSTER_HEAP_PREPARED_UNDO_RETRY_REQUIRED; - if (!cluster_undo_record_prepared_recheck(receipt, payload_len)) - return receipt->ctrc_applied_mask == 0 ? CLUSTER_HEAP_PREPARED_UNDO_RETRY_REQUIRED - : CLUSTER_HEAP_PREPARED_UNDO_REFUSED; + if (!cluster_undo_record_prepared_recheck(receipt, payload_len)) { + if (receipt->ctrc_applied_mask == 0) + return CLUSTER_HEAP_PREPARED_UNDO_RETRY_REQUIRED; + reason = "POST_APPLY_PREPARED_RECHECK"; + goto refused; + } if (!cluster_heap_ctrc_pending_itl_target(relation, buffer, &dml_guard, - receipt->record_type, &pending_target)) - return CLUSTER_HEAP_PREPARED_UNDO_REFUSED; + receipt->record_type, &pending_target)) { + reason = "PENDING_TARGET_INVALID"; + goto refused; + } if ((receipt->ctrc_pending_mask & UINT8_C(1)) == 0) { if (!cluster_undo_record_ctrc_stage_pending( - receipt, 0, &pending_target)) - return CLUSTER_HEAP_PREPARED_UNDO_REFUSED; + receipt, 0, &pending_target)) { + reason = "PENDING_STAGE_REFUSED"; + goto refused; + } } else if (!cluster_undo_record_ctrc_pending_recheck(receipt, 0, &pending_target)) { *targets_invalidated = true; - return receipt->ctrc_applied_mask == 0 - ? CLUSTER_HEAP_PREPARED_UNDO_RETRY_REQUIRED - : CLUSTER_HEAP_PREPARED_UNDO_REFUSED; + if (receipt->ctrc_applied_mask == 0) + return CLUSTER_HEAP_PREPARED_UNDO_RETRY_REQUIRED; + reason = "POST_APPLY_PENDING_RECHECK"; + goto refused; } if ((receipt->ctrc_prepared_mask & UINT8_C(1)) == 0) { @@ -1895,11 +1949,17 @@ cluster_heap_itl_prepare_prepared_undo(Relation relation, Buffer buffer, HeapTup } if (!cluster_undo_record_ctrc_pending_matches(receipt, 0, &pending_target)) { *targets_invalidated = true; - return receipt->ctrc_applied_mask == 0 - ? CLUSTER_HEAP_PREPARED_UNDO_RETRY_REQUIRED - : CLUSTER_HEAP_PREPARED_UNDO_REFUSED; + if (receipt->ctrc_applied_mask == 0) + return CLUSTER_HEAP_PREPARED_UNDO_RETRY_REQUIRED; + reason = "POST_APPLY_PENDING_MISMATCH"; + goto refused; } return CLUSTER_HEAP_PREPARED_UNDO_READY; + +refused: + if (refusal_reason != NULL) + *refusal_reason = reason; + return CLUSTER_HEAP_PREPARED_UNDO_REFUSED; } @@ -5817,7 +5877,7 @@ heap_insert(Relation relation, HeapTuple tup, CommandId cid, undo_result = cluster_heap_itl_prepare_prepared_undo( relation, buffer, NULL, canonical_xid, false, &undo_receipt, - sizeof(UndoInsertPayload), &targets_invalidated); + sizeof(UndoInsertPayload), &targets_invalidated, NULL, NULL, NULL); if (undo_result == CLUSTER_HEAP_PREPARED_UNDO_RETRY_REQUIRED) { @@ -10319,6 +10379,7 @@ cluster_xwait_has_remote_evidence(Page page, HeapTupleHeader tuple, TransactionI * caller's re-attempt is normally served by the cached-cover fast path * without consulting the guard again. */ +#ifdef USE_PGRAC_CLUSTER static void cluster_heap_vm_barrier_warm(Buffer *vmbuf, Buffer *alias, ResourceXAuxiliaryAcquireContext *context) @@ -10327,6 +10388,7 @@ cluster_heap_vm_barrier_warm(Buffer *vmbuf, Buffer *alias, && ClusterLockBufferExclusiveAuxiliaryAliasAware(vmbuf, alias, NULL, context)) LockBuffer(*vmbuf, BUFFER_LOCK_UNLOCK); } +#endif /* * Acquire heap content X without carrying a visibility-map pin across the @@ -10387,7 +10449,6 @@ heap_delete(Relation relation, ItemPointer tid, Buffer buffer; Buffer vmbuffer = InvalidBuffer; bool vm_locked; /* PGRAC: pre-crit VM content lock held */ - ResourceXAuxiliaryAcquireContext cluster_vm_context = { 0 }; CommandId pgrac_entry_cid = cid; /* PGRAC: restored on barrier requalify */ TransactionId new_xmax; uint16 new_infomask, @@ -10399,6 +10460,7 @@ heap_delete(Relation relation, ItemPointer tid, HeapTuple old_key_tuple = NULL; /* replica identity of the tuple */ bool old_key_copied = false; #ifdef USE_PGRAC_CLUSTER + ResourceXAuxiliaryAcquireContext cluster_vm_context = { 0 }; /* PGRAC (spec-3.4a D5 / spec-3.4b D5): hoisted ITL state for delete path. */ uint8 cluster_itl_slot = CLUSTER_ITL_SLOT_UNALLOCATED; bool cluster_itl_active = false; @@ -10857,7 +10919,7 @@ heap_delete(Relation relation, ItemPointer tid, undo_payload_len = sizeof(UndoDeletePayload) + (uint16) tp.t_len; undo_result = cluster_heap_itl_prepare_prepared_undo( relation, buffer, &tp, canonical_xid, false, &undo_receipt, undo_payload_len, - &targets_invalidated); + &targets_invalidated, NULL, NULL, NULL); if (undo_result == CLUSTER_HEAP_PREPARED_UNDO_RETRY_REQUIRED) @@ -10958,6 +11020,7 @@ heap_delete(Relation relation, ItemPointer tid, /* PGRAC: pre-crit VM content lock — see heap_insert. */ vm_locked = false; if (PageIsAllVisible(page) && BufferIsValid(vmbuffer)) { +#ifdef USE_PGRAC_CLUSTER { bool vm_acquired; bool vm_pin_replaced = false; @@ -11034,6 +11097,9 @@ heap_delete(Relation relation, ItemPointer tid, goto l1; } } +#else + LockBuffer(vmbuffer, BUFFER_LOCK_EXCLUSIVE); +#endif vm_locked = true; } @@ -11524,8 +11590,10 @@ heap_update(Relation relation, ItemPointer otid, HeapTuple newtup, bool vm_locked; /* PGRAC: pre-crit VM content lock held */ bool vm_locked_new; bool old_tuple_temp_locked = false; /* PGRAC: t/400 L3 item 3 */ +#ifdef USE_PGRAC_CLUSTER ResourceXAuxiliaryAcquireContext cluster_vm_context = { 0 }; ResourceXAuxiliaryAcquireContext cluster_vm_new_context = { 0 }; +#endif CommandId pgrac_entry_cid = cid; /* PGRAC: restored on barrier requalify */ bool need_toast; Size newtupsize, @@ -12437,6 +12505,7 @@ heap_update(Relation relation, ItemPointer otid, HeapTuple newtup, vm_locked = false; if (PageIsAllVisible(page) && BufferIsValid(vmbuffer)) { +#ifdef USE_PGRAC_CLUSTER bool vm_acquired; bool vm_pin_replaced = false; RelFileLocator refused_rlocator; @@ -12501,6 +12570,9 @@ heap_update(Relation relation, ItemPointer otid, HeapTuple newtup, CLUSTER_BUFFER_BARRIER_PROOF_REENTRY); goto l2; } +#else + LockBuffer(vmbuffer, BUFFER_LOCK_EXCLUSIVE); +#endif vm_locked = true; } @@ -13487,6 +13559,7 @@ heap_update(Relation relation, ItemPointer otid, HeapTuple newtup, && BufferIsValid(vmbuffer); bool need_new = newbuf != buffer && PageIsAllVisible(BufferGetPage(newbuf)) && BufferIsValid(vmbuffer_new); +#ifdef USE_PGRAC_CLUSTER Buffer refused_vm = InvalidBuffer; ClusterBufferBarrierSiteId refused_site = (ClusterBufferBarrierSiteId) 0; bool refused_pin_replaced = false; @@ -13507,6 +13580,7 @@ heap_update(Relation relation, ItemPointer otid, HeapTuple newtup, if (need_new) BufferGetTag(vmbuffer_new, &new_vm_rlocator, &new_vm_forknum, &new_vm_blocknum); +#endif if (need_old && need_new && vmbuffer_new == vmbuffer) need_new = false; /* same map page: one lock covers both */ @@ -13518,6 +13592,7 @@ heap_update(Relation relation, ItemPointer otid, HeapTuple newtup, bool new_first = need_old && need_new && vmbuffer_new < vmbuffer; bool is_new = new_first ? vm_leg == 0 : vm_leg == 1; Buffer *target = is_new ? &vmbuffer_new : &vmbuffer; +#ifdef USE_PGRAC_CLUSTER Buffer *alias = is_new ? &vmbuffer : &vmbuffer_new; ResourceXAuxiliaryAcquireContext *context = is_new ? &cluster_vm_new_context : &cluster_vm_context; @@ -13527,9 +13602,11 @@ heap_update(Relation relation, ItemPointer otid, HeapTuple newtup, : (new_first ? CLUSTER_BUFFER_BARRIER_SITE_HEAP_UPDATE_PAIR_OLD_SECOND : CLUSTER_BUFFER_BARRIER_SITE_HEAP_UPDATE_OLD); Buffer requested; +#endif if (is_new ? !need_new : !need_old) continue; +#ifdef USE_PGRAC_CLUSTER requested = *target; if (!cluster_current_mx_stamp_lock_buffer( requested, true, site, &refused_pin_replaced, &cluster_current_mx_old_plan, @@ -13544,12 +13621,16 @@ heap_update(Relation relation, ItemPointer otid, HeapTuple newtup, *target = InvalidBuffer; break; } +#else + LockBuffer(*target, BUFFER_LOCK_EXCLUSIVE); +#endif if (is_new) vm_locked_new = true; else vm_locked = true; } +#ifdef USE_PGRAC_CLUSTER if (refused_vm != InvalidBuffer) { /* @@ -13666,6 +13747,7 @@ heap_update(Relation relation, ItemPointer otid, HeapTuple newtup, CLUSTER_BUFFER_BARRIER_PROOF_REENTRY); goto l_pgrac_reacquire; } +#endif } #ifdef USE_PGRAC_CLUSTER @@ -14367,7 +14449,7 @@ l_pgrac_itl_capacity_wait: { ClusterTxwResult wait_result; wait_result = cluster_heap_itl_wait_capacity_after_census( - buffer, newbuf, itl_capacity_wait_buffer, canonical_xid, &itl_capacity_absolute_deadline_us, + buffer, newbuf, itl_capacity_wait_buffer, canonical_xid, false, &itl_capacity_absolute_deadline_us, &wait_reason); if (wait_result != CLUSTER_TXW_RESOLVED && wait_result != CLUSTER_TXW_RETRY) ereport(ERROR, @@ -14876,6 +14958,7 @@ heap_lock_tuple_internal(Relation relation, HeapTuple tuple, ClusterUndoRecordPrepareReceipt undo_receipt = {0}; ClusterCtrcReceiptHandle cluster_lock_ctrc_handle = {0}; uint64 undo_prepare_deadline_us = 0; + uint64 itl_capacity_absolute_deadline_us = 0; TransactionId canonical_xid = InvalidTransactionId; #endif @@ -15950,10 +16033,14 @@ heap_lock_tuple_internal(Relation relation, HeapTuple tuple, { ClusterHeapPreparedUndoResult undo_result; bool targets_invalidated; + const char *refusal_reason = NULL; + bool content_unlocked = false; undo_result = cluster_heap_itl_prepare_prepared_undo( relation, *buffer, tuple, canonical_xid, true, &undo_receipt, - sizeof(UndoItlPayload), &targets_invalidated); + sizeof(UndoItlPayload), &targets_invalidated, &refusal_reason, + wait_policy == LockWaitBlock ? &itl_capacity_absolute_deadline_us : NULL, + &content_unlocked); if (undo_result == CLUSTER_HEAP_PREPARED_UNDO_RETRY_REQUIRED) { @@ -15961,7 +16048,8 @@ heap_lock_tuple_internal(Relation relation, HeapTuple tuple, = (undo_receipt.ctrc_pending_mask & UINT8_C(1)) != 0 && (undo_receipt.ctrc_prepared_mask & UINT8_C(1)) == 0; - LockBuffer(*buffer, BUFFER_LOCK_UNLOCK); + if (!content_unlocked) + LockBuffer(*buffer, BUFFER_LOCK_UNLOCK); if (ctrc_prepare_only && !targets_invalidated) { if (!cluster_undo_record_ctrc_prepare_pending( &undo_receipt, 0)) @@ -15998,14 +16086,39 @@ heap_lock_tuple_internal(Relation relation, HeapTuple tuple, tuple->t_len = ItemIdGetLength(lp); goto l3; } - if (undo_result != CLUSTER_HEAP_PREPARED_UNDO_READY) + if (undo_result != CLUSTER_HEAP_PREPARED_UNDO_READY) { + StringInfoData detail; + Page current_page = BufferGetPage(*buffer); + int i; + + /* Read-only evidence under the existing content lock. No + * reason here changes whether publication is admitted. */ + initStringInfo(&detail); + appendStringInfo(&detail, + "PGRAC_FAMILY=UNDO_RECEIPT PGRAC_REASON=%s PGRAC_NODE=%d " + "PGRAC_ATTEMPT=0 block=%u offset=%u xid=%u " + "pending=%u prepared=%u applied=%u", + refusal_reason != NULL ? refusal_reason : "CALLER_CAUSE_UNPROVEN", + cluster_node_id, BufferGetBlockNumber(*buffer), + ItemPointerGetOffsetNumber(tid), canonical_xid, + (unsigned)undo_receipt.ctrc_pending_mask, + (unsigned)undo_receipt.ctrc_prepared_mask, + (unsigned)undo_receipt.ctrc_applied_mask); + if (PageHasItl(current_page) + && ((PageHeader)current_page)->pd_special <= BLCKSZ + && PageGetSpecialSize(current_page) >= CLUSTER_ITL_ARRAY_SIZE) { + const ClusterItlSlotData *slots = ClusterPageGetItlSlots(current_page); + + for (i = 0; i < CLUSTER_ITL_INITRANS_DEFAULT; i++) + appendStringInfo(&detail, " itl%d=%u/%u/%u", i, + slots[i].xid, (unsigned)slots[i].flags, (unsigned)slots[i].wrap); + } ereport( ERROR, (errcode(ERRCODE_CLUSTER_UNDO_RECORD_INVALID_UBA), errmsg("cluster undo receipt preparation failed for heap_lock_tuple"), - errdetail("PGRAC_FAMILY=UNDO_RECEIPT PGRAC_REASON=CALLER_CAUSE_UNPROVEN " - "PGRAC_NODE=%d PGRAC_ATTEMPT=0 ", - cluster_node_id))); + errdetail("%s", detail.data))); + } cluster_lock_undo_ready = true; } } @@ -16042,6 +16155,7 @@ heap_lock_tuple_internal(Relation relation, HeapTuple tuple, vm_locked = false; if (PageIsAllVisible(page) && BufferIsValid(vmbuffer)) { +#ifdef USE_PGRAC_CLUSTER bool vm_pin_replaced = false; if (!cluster_current_mx_stamp_lock_buffer(vmbuffer, false, (ClusterBufferBarrierSiteId)0, @@ -16068,6 +16182,9 @@ heap_lock_tuple_internal(Relation relation, HeapTuple tuple, tuple->t_len = ItemIdGetLength(lp); goto l3; } +#else + LockBuffer(vmbuffer, BUFFER_LOCK_EXCLUSIVE); +#endif vm_locked = true; } @@ -16970,6 +17087,7 @@ heap_lock_updated_tuple_rec(Relation rel, TransactionId priorXmax, bool cluster_chain_needs_itl = false; bool cluster_chain_receipt_owned = false; uint64 cluster_chain_prepare_deadline_us = 0; + uint64 cluster_chain_capacity_deadline_us = 0; bool cluster_chain_vm_locked = false; uint8 cluster_chain_slot_idx = CLUSTER_ITL_SLOT_UNALLOCATED; UBA cluster_chain_uba = InvalidUba_init; @@ -17338,6 +17456,7 @@ heap_lock_updated_tuple_rec(Relation rel, TransactionId priorXmax, { ClusterHeapPreparedUndoResult undo_result; bool targets_invalidated; + bool content_unlocked = false; if (new_infomask & HEAP_XMAX_IS_MULTI) { @@ -17387,14 +17506,16 @@ heap_lock_updated_tuple_rec(Relation rel, TransactionId priorXmax, undo_result = cluster_heap_itl_prepare_prepared_undo( rel, buf, &mytup, canonical_xid, true, &cluster_chain_receipt, - sizeof(UndoItlPayload), &targets_invalidated); + sizeof(UndoItlPayload), &targets_invalidated, NULL, + &cluster_chain_capacity_deadline_us, &content_unlocked); if (undo_result == CLUSTER_HEAP_PREPARED_UNDO_RETRY_REQUIRED) { bool prepare_only = (cluster_chain_receipt.ctrc_pending_mask & UINT8_C(1)) != 0 && (cluster_chain_receipt.ctrc_prepared_mask & UINT8_C(1)) == 0; - LockBuffer(buf, BUFFER_LOCK_UNLOCK); + if (!content_unlocked) + LockBuffer(buf, BUFFER_LOCK_UNLOCK); if (prepare_only && !targets_invalidated) { if (!cluster_undo_record_ctrc_prepare_pending( &cluster_chain_receipt, 0)) diff --git a/src/backend/access/heap/heapam_r4_private.h b/src/backend/access/heap/heapam_r4_private.h index 84d46d6a6d5..891ac9d5c07 100644 --- a/src/backend/access/heap/heapam_r4_private.h +++ b/src/backend/access/heap/heapam_r4_private.h @@ -234,6 +234,7 @@ typedef struct ClusterHeapNoRetryTestReport bool retry_edge; } ClusterHeapNoRetryTestReport; +#ifdef USE_PGRAC_CLUSTER typedef struct ClusterHeapPrepareRetryTestReport { uint8 prepare_calls; @@ -241,6 +242,7 @@ typedef struct ClusterHeapPrepareRetryTestReport uint64 observed_deadline_us; ClusterUndoRecordPrepareResult terminal_result; } ClusterHeapPrepareRetryTestReport; +#endif typedef enum ClusterHeapMultiInsertRoute { @@ -305,6 +307,8 @@ extern ClusterTxwResult cluster_heap_test_itl_wait_capacity(Buffer old_buffer, B Buffer full_buffer, TransactionId xid, uint64 *deadline_us, const char **diagnostic_reason); +extern ClusterTxwResult cluster_heap_test_itl_wait_lock_capacity(Buffer buffer, TransactionId xid, + uint64 *deadline_us, const char **diagnostic_reason); extern bool cluster_heap_test_itl_resolve_pair_terminal_census( Buffer old_buffer, Buffer new_buffer, Buffer full_buffer); extern bool cluster_heap_test_itl_update_same_page_failure_cleanup(void); diff --git a/src/backend/access/heap/heapam_visibility.c b/src/backend/access/heap/heapam_visibility.c index 8faa3bf9e76..743d229170d 100644 --- a/src/backend/access/heap/heapam_visibility.c +++ b/src/backend/access/heap/heapam_visibility.c @@ -64,6 +64,7 @@ * PGRAC MODIFICATIONS * Modified by: SqlRush * Preserve request-owned scratch verdict metadata for selection-miss logs. + * Compile cluster-only scratch proof helpers only in cluster builds. * * Cluster MVCC visibility fork: tuples carrying cluster ITL evidence are * resolved through the cluster TT/undo authority instead of native @@ -1993,6 +1994,7 @@ cluster_remote_live_xmax_keeps_visible(Buffer buffer, HeapTupleHeader tuple, Sna } #endif +#ifdef USE_PGRAC_CLUSTER /* * Fail closed when a FULL R4 page does not carry a complete, authoritative * visibility proof. This evaluator deliberately has no Buffer argument: @@ -2034,7 +2036,6 @@ cluster_r4_scratch_creator_slot(Page page, uint8 writer_index, TransactionId xmi return writer_index; } -#ifdef USE_PGRAC_CLUSTER /* Observe already validated private bytes; no authority or page mutation. */ static ClusterR4ScratchObservation * cluster_r4_scratch_observe(const ClusterR4HotScratchTestContext *context, HeapTuple tuple) diff --git a/src/backend/access/heap/rewriteheap.c b/src/backend/access/heap/rewriteheap.c index 542e88c6775..6851208cbdc 100644 --- a/src/backend/access/heap/rewriteheap.c +++ b/src/backend/access/heap/rewriteheap.c @@ -100,6 +100,12 @@ * *------------------------------------------------------------------------- */ +/* + * PGRAC MODIFICATIONS + * Modified by: SqlRush + * Require terminal-reference closure for cluster rewrites, not native + * backends with no assigned cluster identity. + */ #include "postgres.h" #include @@ -249,7 +255,7 @@ begin_heap_rewrite(Relation old_heap, Relation new_heap, TransactionId oldest_xm /* A rewrite changes every physical TID. Under the caller's * AccessExclusiveLock, require the bounded CTRC journal for the old * relfilenode to be fully terminal before copying any tuple bytes. */ - if (cluster_enabled + if (cluster_enabled && cluster_node_id >= 0 && old_heap->rd_rel->relpersistence != RELPERSISTENCE_TEMP && !cluster_ctrc_relation_removal_ready_shared( (uint32)old_heap->rd_locator.spcOid, diff --git a/src/backend/cluster/cluster_cf_enqueue.c b/src/backend/cluster/cluster_cf_enqueue.c index 0d61b9885b2..355b3d03c64 100644 --- a/src/backend/cluster/cluster_cf_enqueue.c +++ b/src/backend/cluster/cluster_cf_enqueue.c @@ -36,7 +36,7 @@ #include "cluster/cluster_conf.h" #include "cluster/cluster_guc.h" #include "cluster/cluster_lock_acquire.h" -#include "miscadmin.h" /* AmStartupProcess / AmCheckpointerProcess */ +#include "miscadmin.h" /* AmStartupProcess / AmCheckpointerProcess */ #include "storage/fd.h" #include "storage/lock.h" #include "utils/timestamp.h" @@ -133,10 +133,9 @@ cluster_cf_lock(LOCKMODE mode) * a backend that slips past it. */ if (cluster_clean_leave_node_refuses_writes() && !AmCheckpointerProcess()) { - ereport(LOG, - (errmsg("cluster CF acquire refused: clean-leave drain in " - "progress on this node (mode %d)", - (int) mode))); + ereport(LOG, (errmsg("cluster CF acquire refused: clean-leave drain in " + "progress on this node (mode %d)", + (int)mode))); return false; } @@ -160,10 +159,9 @@ cluster_cf_lock(LOCKMODE mode) ClusterCfReleaseResult drain = cluster_cf_unlock_confirmed(mode); if (drain == CLUSTER_CF_RELEASE_UNCONFIRMED) { - ereport(LOG, - (errmsg("cluster CF acquire refused: stale held slot could " - "not be drained (mode %d)", - (int) mode))); + ereport(LOG, (errmsg("cluster CF acquire refused: stale held slot could " + "not be drained (mode %d)", + (int)mode))); return false; } } @@ -229,9 +227,7 @@ cluster_cf_lock(LOCKMODE mode) * appropriate FATAL/ERROR (CF correctness). */ cluster_cf_counter_inc(CLUSTER_CF_FAILCLOSED); - ereport(LOG, - (errmsg("cluster CF acquire failed (mode %d, result %d)", - (int) mode, (int) r))); + ereport(LOG, (errmsg("cluster CF acquire failed (mode %d, result %d)", (int)mode, (int)r))); return false; } } @@ -316,8 +312,7 @@ cluster_cf_set_bootstrap_authority(bool on) bool cluster_cf_write_permitted(void) { - return cluster_cf_held(ExclusiveLock) || cf_bootstrap_authority - || cf_owner_eor_authority; + return cluster_cf_held(ExclusiveLock) || cf_bootstrap_authority || cf_owner_eor_authority; } /* @@ -353,8 +348,8 @@ cluster_cf_exactly_one_declared_node(void) if (loaded_count != 0) return loaded_count == 1; - path = (cluster_config_file != NULL && cluster_config_file[0] != '\0') - ? cluster_config_file : "pgrac.conf"; + path = (cluster_config_file != NULL && cluster_config_file[0] != '\0') ? cluster_config_file + : "pgrac.conf"; f = AllocateFile(path, "r"); if (f == NULL) return false; @@ -371,9 +366,8 @@ cluster_cf_exactly_one_declared_node(void) errno = 0; node_id = strtol(p + 6, &endptr, 10); - if (errno != 0 || endptr == p + 6 || *endptr != ']' - || node_id < 0 || node_id >= CLUSTER_MAX_NODES - || node_id != cluster_node_id) { + if (errno != 0 || endptr == p + 6 || *endptr != ']' || node_id < 0 + || node_id >= CLUSTER_MAX_NODES || node_id != cluster_node_id) { valid = false; break; } @@ -405,10 +399,8 @@ cluster_cf_exactly_one_declared_node(void) bool cluster_cf_owner_eor_install(void) { - if (!cluster_controlfile_shared_authority - || !cluster_cf_exactly_one_declared_node() - || cluster_cf_join_readonly() - || cf_bootstrap_authority) + if (!cluster_controlfile_shared_authority || !cluster_cf_exactly_one_declared_node() + || cluster_cf_join_readonly() || cf_bootstrap_authority) return false; if (!cluster_cf_owner_eor_phase_install()) return false; @@ -424,10 +416,8 @@ cluster_cf_owner_eor_install(void) bool cluster_cf_owner_eor_consume(bool end_of_recovery, bool identity_ok) { - if (!end_of_recovery || !identity_ok - || !cluster_controlfile_shared_authority - || !cluster_cf_exactly_one_declared_node() - || cluster_cf_join_readonly() + if (!end_of_recovery || !identity_ok || !cluster_controlfile_shared_authority + || !cluster_cf_exactly_one_declared_node() || cluster_cf_join_readonly() || cf_owner_eor_authority) return false; if (!cluster_cf_owner_eor_phase_activate()) diff --git a/src/backend/cluster/cluster_cf_phase2.c b/src/backend/cluster/cluster_cf_phase2.c index 6ba877ae49a..087d7a3a519 100644 --- a/src/backend/cluster/cluster_cf_phase2.c +++ b/src/backend/cluster/cluster_cf_phase2.c @@ -70,8 +70,7 @@ ensure_p2_dir(const char *shared_dir) static bool cf_phase2_node_valid(int node_id) { - return node_id >= 0 && node_id < CLUSTER_MAX_NODES - && cluster_conf_lookup_node(node_id) != NULL; + return node_id >= 0 && node_id < CLUSTER_MAX_NODES && cluster_conf_lookup_node(node_id) != NULL; } static bool @@ -83,41 +82,34 @@ cf_phase2_path(char path[MAXPGPATH], const char *shared_dir, const char *rel) } static bool -cf_phase2_probe_paths(char final_rel[MAXPGPATH], char tmp_rel[MAXPGPATH], - int probe_owner, uint64 nonce) +cf_phase2_probe_paths(char final_rel[MAXPGPATH], char tmp_rel[MAXPGPATH], int probe_owner, + uint64 nonce) { int final_n; int tmp_n; - final_n = snprintf(final_rel, MAXPGPATH, "%s/probe.%d", - CLUSTER_CF_PHASE2_DIR, probe_owner); - tmp_n = snprintf(tmp_rel, MAXPGPATH, - "%s/probe.%d.tmp.%016" INT64_MODIFIER "x", - CLUSTER_CF_PHASE2_DIR, probe_owner, nonce); - return final_n >= 0 && final_n < MAXPGPATH - && tmp_n >= 0 && tmp_n < MAXPGPATH; + final_n = snprintf(final_rel, MAXPGPATH, "%s/probe.%d", CLUSTER_CF_PHASE2_DIR, probe_owner); + tmp_n = snprintf(tmp_rel, MAXPGPATH, "%s/probe.%d.tmp.%016" INT64_MODIFIER "x", + CLUSTER_CF_PHASE2_DIR, probe_owner, nonce); + return final_n >= 0 && final_n < MAXPGPATH && tmp_n >= 0 && tmp_n < MAXPGPATH; } static bool -cf_phase2_ack_paths(char final_rel[MAXPGPATH], char tmp_rel[MAXPGPATH], - int probe_owner, int responder, uint64 nonce) +cf_phase2_ack_paths(char final_rel[MAXPGPATH], char tmp_rel[MAXPGPATH], int probe_owner, + int responder, uint64 nonce) { int final_n; int tmp_n; - final_n = snprintf(final_rel, MAXPGPATH, - "%s/ack.%d.%d.%016" INT64_MODIFIER "x", - CLUSTER_CF_PHASE2_DIR, probe_owner, responder, nonce); - tmp_n = snprintf(tmp_rel, MAXPGPATH, - "%s/ack.%d.%d.%016" INT64_MODIFIER "x.tmp", - CLUSTER_CF_PHASE2_DIR, probe_owner, responder, nonce); - return final_n >= 0 && final_n < MAXPGPATH - && tmp_n >= 0 && tmp_n < MAXPGPATH; + final_n = snprintf(final_rel, MAXPGPATH, "%s/ack.%d.%d.%016" INT64_MODIFIER "x", + CLUSTER_CF_PHASE2_DIR, probe_owner, responder, nonce); + tmp_n = snprintf(tmp_rel, MAXPGPATH, "%s/ack.%d.%d.%016" INT64_MODIFIER "x.tmp", + CLUSTER_CF_PHASE2_DIR, probe_owner, responder, nonce); + return final_n >= 0 && final_n < MAXPGPATH && tmp_n >= 0 && tmp_n < MAXPGPATH; } static void -cf_phase2_init_record(ClusterCfPhase2RecordV2 *rec, - ClusterCfPhase2Kind kind, int probe_owner, +cf_phase2_init_record(ClusterCfPhase2RecordV2 *rec, ClusterCfPhase2Kind kind, int probe_owner, int responder, uint64 nonce) { memset(rec, 0, sizeof(*rec)); @@ -134,11 +126,9 @@ cf_phase2_init_record(ClusterCfPhase2RecordV2 *rec, /* Read one exact V2 tuple. V1, trailing bytes and path/body drift fail shut. */ static bool -cf_phase2_read_record(const char *shared_dir, const char *rel, - ClusterCfPhase2Kind expected_kind, - int expected_owner, int expected_responder, - uint64 expected_nonce, bool exact_nonce, - ClusterCfPhase2RecordV2 *out) +cf_phase2_read_record(const char *shared_dir, const char *rel, ClusterCfPhase2Kind expected_kind, + int expected_owner, int expected_responder, uint64 expected_nonce, + bool exact_nonce, ClusterCfPhase2RecordV2 *out) { ClusterCfPhase2RecordV2 rec; char path[MAXPGPATH]; @@ -160,11 +150,9 @@ cf_phase2_read_record(const char *shared_dir, const char *rel, } CloseTransientFile(fd); if (!exact_size || rec.magic != CLUSTER_CF_PHASE2_MAGIC - || rec.version != CLUSTER_CF_PHASE2_VERSION - || rec.kind != expected_kind || rec.reserved != 0 - || rec.probe_owner_node != expected_owner - || rec.responder_node != expected_responder - || rec.probe_nonce == 0 + || rec.version != CLUSTER_CF_PHASE2_VERSION || rec.kind != expected_kind + || rec.reserved != 0 || rec.probe_owner_node != expected_owner + || rec.responder_node != expected_responder || rec.probe_nonce == 0 || (exact_nonce && rec.probe_nonce != expected_nonce) || !cf_phase2_node_valid(rec.probe_owner_node)) return false; @@ -172,8 +160,7 @@ cf_phase2_read_record(const char *shared_dir, const char *rel, if (rec.responder_node != -1) return false; } else if (rec.kind == CLUSTER_CF_P2_ACK) { - if (!cf_phase2_node_valid(rec.responder_node) - || rec.responder_node == rec.probe_owner_node) + if (!cf_phase2_node_valid(rec.responder_node) || rec.responder_node == rec.probe_owner_node) return false; } else return false; @@ -191,33 +178,30 @@ cf_phase2_read_record(const char *shared_dir, const char *rel, /* Tuple-scoped staging prevents independent responders sharing a tmp file. */ static bool -cf_phase2_write_record(const char *shared_dir, const char *final_rel, - const char *tmp_rel, ClusterCfPhase2Kind kind, - int probe_owner, int responder, uint64 nonce) +cf_phase2_write_record(const char *shared_dir, const char *final_rel, const char *tmp_rel, + ClusterCfPhase2Kind kind, int probe_owner, int responder, uint64 nonce) { ClusterCfPhase2RecordV2 rec; char final_path[MAXPGPATH]; char tmp_path[MAXPGPATH]; int fd; - if (cf_phase2_read_record(shared_dir, final_rel, kind, probe_owner, - responder, nonce, true, NULL)) + if (cf_phase2_read_record(shared_dir, final_rel, kind, probe_owner, responder, nonce, true, + NULL)) return true; if (!cf_phase2_path(final_path, shared_dir, final_rel) || !cf_phase2_path(tmp_path, shared_dir, tmp_rel)) return false; cf_phase2_init_record(&rec, kind, probe_owner, responder, nonce); - fd = OpenTransientFile(tmp_path, - O_RDWR | O_CREAT | O_EXCL | PG_BINARY); + fd = OpenTransientFile(tmp_path, O_RDWR | O_CREAT | O_EXCL | PG_BINARY); if (fd < 0) { if (errno != EEXIST - || !cf_phase2_read_record(shared_dir, tmp_rel, kind, - probe_owner, responder, nonce, true, NULL)) + || !cf_phase2_read_record(shared_dir, tmp_rel, kind, probe_owner, responder, nonce, + true, NULL)) return false; } else { - if (write(fd, &rec, sizeof(rec)) != (ssize_t)sizeof(rec) - || pg_fsync(fd) != 0) { + if (write(fd, &rec, sizeof(rec)) != (ssize_t)sizeof(rec) || pg_fsync(fd) != 0) { CloseTransientFile(fd); unlink(tmp_path); return false; @@ -229,15 +213,14 @@ cf_phase2_write_record(const char *shared_dir, const char *final_rel, } if (durable_rename(tmp_path, final_path, LOG) != 0) - return cf_phase2_read_record(shared_dir, final_rel, kind, - probe_owner, responder, nonce, true, NULL); - return cf_phase2_read_record(shared_dir, final_rel, kind, - probe_owner, responder, nonce, true, NULL); + return cf_phase2_read_record(shared_dir, final_rel, kind, probe_owner, responder, nonce, + true, NULL); + return cf_phase2_read_record(shared_dir, final_rel, kind, probe_owner, responder, nonce, true, + NULL); } static bool -cf_phase2_parse_ack_name(const char *name, int probe_owner, int responder, - uint64 *nonce) +cf_phase2_parse_ack_name(const char *name, int probe_owner, int responder, uint64 *nonce) { char prefix[64]; const char *p; @@ -245,8 +228,8 @@ cf_phase2_parse_ack_name(const char *name, int probe_owner, int responder, uint64 value = 0; int i; - if (snprintf(prefix, sizeof(prefix), "ack.%d.%d.", - probe_owner, responder) >= (int)sizeof(prefix)) + if (snprintf(prefix, sizeof(prefix), "ack.%d.%d.", probe_owner, responder) + >= (int)sizeof(prefix)) return false; if (strncmp(name, prefix, strlen(prefix)) != 0) return false; @@ -290,9 +273,8 @@ typedef struct ClusterCfPhase2GcSnapshot { * writer therefore cannot discover a later writer's current-nonce final. */ static void -cf_phase2_capture_ack_pair(const char *shared_dir, int probe_owner, - int responder, uint64 incoming_nonce, - ClusterCfPhase2GcSnapshot *snapshot) +cf_phase2_capture_ack_pair(const char *shared_dir, int probe_owner, int responder, + uint64 incoming_nonce, ClusterCfPhase2GcSnapshot *snapshot) { char dirpath[MAXPGPATH]; DIR *dir; @@ -311,19 +293,17 @@ cf_phase2_capture_ack_pair(const char *shared_dir, int probe_owner, struct stat st; uint64 nonce; - if (!cf_phase2_parse_ack_name(de->d_name, probe_owner, responder, - &nonce) || nonce == incoming_nonce - || snapshot->count >= CLUSTER_CF_PHASE2_GC_MAX + if (!cf_phase2_parse_ack_name(de->d_name, probe_owner, responder, &nonce) + || nonce == incoming_nonce || snapshot->count >= CLUSTER_CF_PHASE2_GC_MAX || strlen(de->d_name) >= CLUSTER_CF_PHASE2_GC_NAME_MAX) continue; - if (snprintf(rel, sizeof(rel), "%s/%s", CLUSTER_CF_PHASE2_DIR, - de->d_name) >= (int)sizeof(rel)) + if (snprintf(rel, sizeof(rel), "%s/%s", CLUSTER_CF_PHASE2_DIR, de->d_name) + >= (int)sizeof(rel)) continue; - if (!cf_phase2_read_record(shared_dir, rel, CLUSTER_CF_P2_ACK, - probe_owner, responder, nonce, true, NULL)) + if (!cf_phase2_read_record(shared_dir, rel, CLUSTER_CF_P2_ACK, probe_owner, responder, + nonce, true, NULL)) continue; - if (!cf_phase2_path(path, shared_dir, rel) || lstat(path, &st) != 0 - || !S_ISREG(st.st_mode)) + if (!cf_phase2_path(path, shared_dir, rel) || lstat(path, &st) != 0 || !S_ISREG(st.st_mode)) continue; entry = &snapshot->entries[snapshot->count++]; strlcpy(entry->name, de->d_name, sizeof(entry->name)); @@ -335,9 +315,8 @@ cf_phase2_capture_ack_pair(const char *shared_dir, int probe_owner, /* Delete only the pre-publication snapshot, never a later directory entry. */ static void -cf_phase2_cleanup_ack_snapshot(const char *shared_dir, int probe_owner, - int responder, uint64 current_nonce, - const ClusterCfPhase2GcSnapshot *snapshot) +cf_phase2_cleanup_ack_snapshot(const char *shared_dir, int probe_owner, int responder, + uint64 current_nonce, const ClusterCfPhase2GcSnapshot *snapshot) { int i; @@ -352,24 +331,22 @@ cf_phase2_cleanup_ack_snapshot(const char *shared_dir, int probe_owner, if (!cluster_cf_phase2_read_probe(shared_dir, probe_owner, &probe) || probe.probe_nonce != current_nonce) return; - if (!cf_phase2_parse_ack_name(entry->name, probe_owner, responder, - &nonce) || nonce == current_nonce) + if (!cf_phase2_parse_ack_name(entry->name, probe_owner, responder, &nonce) + || nonce == current_nonce) continue; - if (snprintf(rel, sizeof(rel), "%s/%s", CLUSTER_CF_PHASE2_DIR, - entry->name) >= (int)sizeof(rel) - || !cf_phase2_read_record(shared_dir, rel, CLUSTER_CF_P2_ACK, - probe_owner, responder, nonce, true, NULL) - || !cf_phase2_path(path, shared_dir, rel) - || lstat(path, &st) != 0 || st.st_dev != entry->device - || st.st_ino != entry->inode) + if (snprintf(rel, sizeof(rel), "%s/%s", CLUSTER_CF_PHASE2_DIR, entry->name) + >= (int)sizeof(rel) + || !cf_phase2_read_record(shared_dir, rel, CLUSTER_CF_P2_ACK, probe_owner, responder, + nonce, true, NULL) + || !cf_phase2_path(path, shared_dir, rel) || lstat(path, &st) != 0 + || st.st_dev != entry->device || st.st_ino != entry->inode) continue; (void)unlink(path); } } bool -cluster_cf_phase2_write_probe(const char *shared_dir, int probe_owner, - uint64 probe_nonce) +cluster_cf_phase2_write_probe(const char *shared_dir, int probe_owner, uint64 probe_nonce) { char final_rel[MAXPGPATH]; char tmp_rel[MAXPGPATH]; @@ -380,13 +357,12 @@ cluster_cf_phase2_write_probe(const char *shared_dir, int probe_owner, ensure_p2_dir(shared_dir); if (!cf_phase2_probe_paths(final_rel, tmp_rel, probe_owner, probe_nonce)) return false; - return cf_phase2_write_record(shared_dir, final_rel, tmp_rel, - CLUSTER_CF_P2_PROBE, probe_owner, -1, probe_nonce); + return cf_phase2_write_record(shared_dir, final_rel, tmp_rel, CLUSTER_CF_P2_PROBE, probe_owner, + -1, probe_nonce); } bool -cluster_cf_phase2_read_probe(const char *shared_dir, int probe_owner, - ClusterCfPhase2RecordV2 *out) +cluster_cf_phase2_read_probe(const char *shared_dir, int probe_owner, ClusterCfPhase2RecordV2 *out) { char final_rel[MAXPGPATH]; char tmp_rel[MAXPGPATH]; @@ -394,63 +370,58 @@ cluster_cf_phase2_read_probe(const char *shared_dir, int probe_owner, if (shared_dir == NULL || out == NULL || !cf_phase2_node_valid(probe_owner) || !cf_phase2_probe_paths(final_rel, tmp_rel, probe_owner, 1)) return false; - return cf_phase2_read_record(shared_dir, final_rel, CLUSTER_CF_P2_PROBE, - probe_owner, -1, 0, false, out); + return cf_phase2_read_record(shared_dir, final_rel, CLUSTER_CF_P2_PROBE, probe_owner, -1, 0, + false, out); } bool -cluster_cf_phase2_write_ack(const char *shared_dir, int probe_owner, - int responder, uint64 probe_nonce) +cluster_cf_phase2_write_ack(const char *shared_dir, int probe_owner, int responder, + uint64 probe_nonce) { ClusterCfPhase2GcSnapshot gc_snapshot; ClusterCfPhase2RecordV2 probe; char final_rel[MAXPGPATH]; char tmp_rel[MAXPGPATH]; - char final_path[MAXPGPATH]; if (shared_dir == NULL || shared_dir[0] == '\0' || probe_nonce == 0 - || !cf_phase2_node_valid(probe_owner) - || !cf_phase2_node_valid(responder) || responder == probe_owner + || !cf_phase2_node_valid(probe_owner) || !cf_phase2_node_valid(responder) + || responder == probe_owner || !cluster_cf_phase2_read_probe(shared_dir, probe_owner, &probe) || probe.probe_nonce != probe_nonce - || !cf_phase2_ack_paths(final_rel, tmp_rel, probe_owner, responder, - probe_nonce)) + || !cf_phase2_ack_paths(final_rel, tmp_rel, probe_owner, responder, probe_nonce)) return false; - cf_phase2_capture_ack_pair(shared_dir, probe_owner, responder, - probe_nonce, &gc_snapshot); - if (!cf_phase2_write_record(shared_dir, final_rel, tmp_rel, - CLUSTER_CF_P2_ACK, probe_owner, responder, probe_nonce)) + cf_phase2_capture_ack_pair(shared_dir, probe_owner, responder, probe_nonce, &gc_snapshot); + if (!cf_phase2_write_record(shared_dir, final_rel, tmp_rel, CLUSTER_CF_P2_ACK, probe_owner, + responder, probe_nonce)) return false; /* A delayed old-nonce writer cannot leave a positive ACK after drift. */ if (!cluster_cf_phase2_read_probe(shared_dir, probe_owner, &probe) || probe.probe_nonce != probe_nonce) { + char final_path[MAXPGPATH]; + if (cf_phase2_path(final_path, shared_dir, final_rel)) (void)unlink(final_path); return false; } - cf_phase2_cleanup_ack_snapshot(shared_dir, probe_owner, responder, - probe_nonce, &gc_snapshot); + cf_phase2_cleanup_ack_snapshot(shared_dir, probe_owner, responder, probe_nonce, &gc_snapshot); return true; } bool -cluster_cf_phase2_read_exact_ack(const char *shared_dir, int probe_owner, - int expected_responder, - uint64 expected_nonce) +cluster_cf_phase2_read_exact_ack(const char *shared_dir, int probe_owner, int expected_responder, + uint64 expected_nonce) { char final_rel[MAXPGPATH]; char tmp_rel[MAXPGPATH]; - if (shared_dir == NULL || expected_nonce == 0 - || !cf_phase2_node_valid(probe_owner) - || !cf_phase2_node_valid(expected_responder) - || expected_responder == probe_owner - || !cf_phase2_ack_paths(final_rel, tmp_rel, probe_owner, - expected_responder, expected_nonce)) + if (shared_dir == NULL || expected_nonce == 0 || !cf_phase2_node_valid(probe_owner) + || !cf_phase2_node_valid(expected_responder) || expected_responder == probe_owner + || !cf_phase2_ack_paths(final_rel, tmp_rel, probe_owner, expected_responder, + expected_nonce)) return false; - return cf_phase2_read_record(shared_dir, final_rel, CLUSTER_CF_P2_ACK, - probe_owner, expected_responder, expected_nonce, true, NULL); + return cf_phase2_read_record(shared_dir, final_rel, CLUSTER_CF_P2_ACK, probe_owner, + expected_responder, expected_nonce, true, NULL); } /* @@ -462,10 +433,8 @@ cluster_cf_phase2_rendezvous(const char *shared_dir, int self_id, int peer_id, u { TimestampTz deadline; - if (shared_dir == NULL || shared_dir[0] == '\0' - || !cf_phase2_node_valid(self_id) - || !cf_phase2_node_valid(peer_id) || self_id == peer_id - || nonce == 0) + if (shared_dir == NULL || shared_dir[0] == '\0' || !cf_phase2_node_valid(self_id) + || !cf_phase2_node_valid(peer_id) || self_id == peer_id || nonce == 0) return false; ensure_p2_dir(shared_dir); @@ -486,13 +455,11 @@ cluster_cf_phase2_rendezvous(const char *shared_dir, int self_id, int peer_id, u if (id == self_id || !cf_phase2_node_valid(id)) continue; if (cluster_cf_phase2_read_probe(shared_dir, id, &peer_probe)) - (void)cluster_cf_phase2_write_ack(shared_dir, id, self_id, - peer_probe.probe_nonce); + (void)cluster_cf_phase2_write_ack(shared_dir, id, self_id, peer_probe.probe_nonce); } /* Only the selected peer can complete this exact round trip. */ - if (cluster_cf_phase2_read_exact_ack(shared_dir, self_id, peer_id, - nonce)) + if (cluster_cf_phase2_read_exact_ack(shared_dir, self_id, peer_id, nonce)) return true; if (GetCurrentTimestamp() >= deadline) @@ -546,8 +513,7 @@ cluster_cf_phase2_verify_or_fail(const char *pgdata) uint64 nonce; uint8 raw[8]; - if (!cluster_controlfile_shared_authority) - { + if (!cluster_controlfile_shared_authority) { return; } if (!cluster_enabled || cluster_conf_node_count() <= 1) @@ -562,8 +528,7 @@ cluster_cf_phase2_verify_or_fail(const char *pgdata) * survivor should perform). */ peer_id = find_peer_node(); - if (peer_id < 0) - { + if (peer_id < 0) { return; /* no peer configured -> gate fails closed */ } @@ -637,13 +602,11 @@ cluster_cf_phase2_respond_tick(void) { ClusterCfPhase2RecordV2 probe; - if (!cluster_cf_phase2_read_probe(cluster_shared_data_dir, id, - &probe)) + if (!cluster_cf_phase2_read_probe(cluster_shared_data_dir, id, &probe)) continue; nonce = probe.probe_nonce; } - if (!cluster_cf_phase2_write_ack(cluster_shared_data_dir, id, - cluster_node_id, nonce)) + if (!cluster_cf_phase2_write_ack(cluster_shared_data_dir, id, cluster_node_id, nonce)) continue; } } diff --git a/src/backend/cluster/cluster_cf_stats.c b/src/backend/cluster/cluster_cf_stats.c index 7f1463a5aa1..d8f9b9531d4 100644 --- a/src/backend/cluster/cluster_cf_stats.c +++ b/src/backend/cluster/cluster_cf_stats.c @@ -107,8 +107,7 @@ cluster_cf_stats_shmem_init(void) for (i = 0; i < CLUSTER_CF_COUNTER_COUNT; i++) pg_atomic_init_u64(&cluster_cf_stats_state->counters[i], 0); pg_atomic_init_u32(&cluster_cf_stats_state->join_readonly, 0); - pg_atomic_init_u32(&cluster_cf_stats_state->owner_eor_phase, - CLUSTER_CF_OWNER_EOR_EMPTY); + pg_atomic_init_u32(&cluster_cf_stats_state->owner_eor_phase, CLUSTER_CF_OWNER_EOR_EMPTY); } } @@ -179,44 +178,39 @@ cluster_cf_owner_eor_phase_read(void) { if (cluster_cf_stats_state == NULL) return CLUSTER_CF_OWNER_EOR_EMPTY; - return (ClusterCfOwnerEorPhase) - pg_atomic_read_u32(&cluster_cf_stats_state->owner_eor_phase); + return (ClusterCfOwnerEorPhase)pg_atomic_read_u32(&cluster_cf_stats_state->owner_eor_phase); } static bool -owner_eor_phase_cas(ClusterCfOwnerEorPhase old_phase, - ClusterCfOwnerEorPhase new_phase) +owner_eor_phase_cas(ClusterCfOwnerEorPhase old_phase, ClusterCfOwnerEorPhase new_phase) { uint32 expected = (uint32)old_phase; if (cluster_cf_stats_state == NULL) return false; - return pg_atomic_compare_exchange_u32(&cluster_cf_stats_state->owner_eor_phase, - &expected, (uint32)new_phase); + return pg_atomic_compare_exchange_u32(&cluster_cf_stats_state->owner_eor_phase, &expected, + (uint32)new_phase); } bool cluster_cf_owner_eor_phase_install(void) { return AmStartupProcess() - && owner_eor_phase_cas(CLUSTER_CF_OWNER_EOR_EMPTY, - CLUSTER_CF_OWNER_EOR_INSTALLED); + && owner_eor_phase_cas(CLUSTER_CF_OWNER_EOR_EMPTY, CLUSTER_CF_OWNER_EOR_INSTALLED); } bool cluster_cf_owner_eor_phase_activate(void) { return AmCheckpointerProcess() - && owner_eor_phase_cas(CLUSTER_CF_OWNER_EOR_INSTALLED, - CLUSTER_CF_OWNER_EOR_ACTIVE); + && owner_eor_phase_cas(CLUSTER_CF_OWNER_EOR_INSTALLED, CLUSTER_CF_OWNER_EOR_ACTIVE); } bool cluster_cf_owner_eor_phase_done(void) { return AmCheckpointerProcess() - && owner_eor_phase_cas(CLUSTER_CF_OWNER_EOR_ACTIVE, - CLUSTER_CF_OWNER_EOR_DONE); + && owner_eor_phase_cas(CLUSTER_CF_OWNER_EOR_ACTIVE, CLUSTER_CF_OWNER_EOR_DONE); } bool @@ -228,8 +222,7 @@ cluster_cf_owner_eor_phase_clear(void) return false; phase = cluster_cf_owner_eor_phase_read(); - if (phase != CLUSTER_CF_OWNER_EOR_INSTALLED - && phase != CLUSTER_CF_OWNER_EOR_DONE) + if (phase != CLUSTER_CF_OWNER_EOR_INSTALLED && phase != CLUSTER_CF_OWNER_EOR_DONE) return false; return owner_eor_phase_cas(phase, CLUSTER_CF_OWNER_EOR_EMPTY); } diff --git a/src/backend/cluster/cluster_cf_storage.c b/src/backend/cluster/cluster_cf_storage.c index 4c52c3e7fbd..962629efceb 100644 --- a/src/backend/cluster/cluster_cf_storage.c +++ b/src/backend/cluster/cluster_cf_storage.c @@ -511,9 +511,10 @@ cluster_cf_enter_bootstrap_window_or_fail(void) multi_node = cluster_enabled && cluster_conf_node_count() > 1; if (!multi_node) { if (!cluster_cf_exactly_one_declared_node()) - ereport(FATAL, - (errcode(ERRCODE_CLUSTER_CONTROLFILE_AUTHORITY_UNAVAILABLE), - errmsg("single-node control-file authority requires exactly one declared node"))); + ereport( + FATAL, + (errcode(ERRCODE_CLUSTER_CONTROLFILE_AUTHORITY_UNAVAILABLE), + errmsg("single-node control-file authority requires exactly one declared node"))); /* Install the boot-local transport before retaining Startup permission. */ if (!cluster_cf_owner_eor_install()) diff --git a/src/backend/cluster/cluster_clean_leave_policy.c b/src/backend/cluster/cluster_clean_leave_policy.c index 42e00f4db33..89ddd8cb32e 100644 --- a/src/backend/cluster/cluster_clean_leave_policy.c +++ b/src/backend/cluster/cluster_clean_leave_policy.c @@ -370,8 +370,7 @@ cluster_clean_leave_serve_gate_allows(bool block_from_leaving, bool leave_flushe * clean-leave behavior. Once the readiness lifecycle is managed, clean leave * is an ordinary serving transition and cannot start or advance before OPEN. */ bool -cluster_clean_leave_startup_serving_allows(bool authority_managed, - bool serving_ready) +cluster_clean_leave_startup_serving_allows(bool authority_managed, bool serving_ready) { return !authority_managed || serving_ready; } @@ -475,8 +474,7 @@ cluster_clean_leave_ack_payload_valid(const ClusterLeaveAckPayload *p) return false; if (p->leaving_node_id < 0 || p->leaving_node_id >= CLUSTER_CLEAN_LEAVE_MAX_NODE_ID) return false; - if (p->phase1_round != 0 - && p->phase1_round != CLUSTER_PHASE1_FULL_STOP_WIRE_RELEASE) + if (p->phase1_round != 0 && p->phase1_round != CLUSTER_PHASE1_FULL_STOP_WIRE_RELEASE) return false; if (p->phase1_round == CLUSTER_PHASE1_FULL_STOP_WIRE_RELEASE && (p->_pad0 != 0 || p->_pad1 != 0 @@ -494,54 +492,47 @@ cluster_clean_leave_ack_payload_valid(const ClusterLeaveAckPayload *p) * ------------------------------------------------------------------ */ bool -cluster_clean_leave_phase1_full_stop_plan_valid( - const ClusterPhase1FullStopPlan *plan) +cluster_clean_leave_phase1_full_stop_plan_valid(const ClusterPhase1FullStopPlan *plan) { int i; - if (plan == NULL || !plan->valid || plan->epoch != 0 - || plan->attempt_nonce == 0 || plan->attempt_nonce == UINT64_MAX - || plan->absolute_deadline_us == 0 - || plan->absolute_deadline_us == UINT64_MAX - || plan->own_wal_started_at <= 0) + if (plan == NULL || !plan->valid || plan->epoch != 0 || plan->attempt_nonce == 0 + || plan->attempt_nonce == UINT64_MAX || plan->absolute_deadline_us == 0 + || plan->absolute_deadline_us == UINT64_MAX || plan->own_wal_started_at <= 0) return false; for (i = 0; i < CLUSTER_PHASE1_FULL_STOP_MEMBER_COUNT; i++) { - if (plan->member_incarnations[i] == 0 - || plan->member_incarnations[i] == UINT64_MAX) + if (plan->member_incarnations[i] == 0 || plan->member_incarnations[i] == UINT64_MAX) return false; } return true; } bool -cluster_clean_leave_phase1_full_stop_probe_accepts( - uint8 producer_kind, bool preflight, int32 envelope_source_node, - int32 payload_leaving_node, uint64 envelope_epoch, uint64 payload_epoch, - uint64 attempt_nonce, bool local_fast_shutdown, bool exact_phase1_eligible) +cluster_clean_leave_phase1_full_stop_probe_accepts(uint8 producer_kind, bool preflight, + int32 envelope_source_node, + int32 payload_leaving_node, + uint64 envelope_epoch, uint64 payload_epoch, + uint64 attempt_nonce, bool local_fast_shutdown, + bool exact_phase1_eligible) { - return producer_kind == CLUSTER_LEAVE_PRODUCER_SHUTDOWN - && preflight - && envelope_source_node >= 0 - && envelope_source_node < CLUSTER_PHASE1_FULL_STOP_MEMBER_COUNT - && envelope_source_node == payload_leaving_node - && envelope_epoch == payload_epoch - && payload_epoch == 0 - && attempt_nonce != 0 && attempt_nonce != UINT64_MAX - && local_fast_shutdown && exact_phase1_eligible; + return producer_kind == CLUSTER_LEAVE_PRODUCER_SHUTDOWN && preflight + && envelope_source_node >= 0 + && envelope_source_node < CLUSTER_PHASE1_FULL_STOP_MEMBER_COUNT + && envelope_source_node == payload_leaving_node && envelope_epoch == payload_epoch + && payload_epoch == 0 && attempt_nonce != 0 && attempt_nonce != UINT64_MAX + && local_fast_shutdown && exact_phase1_eligible; } bool -cluster_clean_leave_phase1_full_stop_probe_phase_accepts( - bool source_active, bool source_stopped, - bool local_active, bool local_stopped) +cluster_clean_leave_phase1_full_stop_probe_phase_accepts(bool source_active, bool source_stopped, + bool local_active, bool local_stopped) { /* The two rounds deliberately reuse one wire shape. Existing source * WAL/root evidence is therefore the phase discriminator: an ACTIVE source * is still in the first round, while STOPPED+CLOSED is the second round. * A receiver may already have closed while helping a slower first-round * peer, but it must never ACK a second-round peer before its own close. */ - if (source_active == source_stopped - || local_active == local_stopped) + if (source_active == source_stopped || local_active == local_stopped) return false; if (source_stopped) return local_stopped; @@ -550,8 +541,8 @@ cluster_clean_leave_phase1_full_stop_probe_phase_accepts( bool cluster_clean_leave_phase1_full_stop_post_stopped_receiver_ready( - bool local_stopped, bool request_in_progress, bool shutdown_driven, - bool preflight_pending, bool preflight_sent, bool release_pending) + bool local_stopped, bool request_in_progress, bool shutdown_driven, bool preflight_pending, + bool preflight_sent, bool release_pending) { /* The STOPPED after-image becomes an acknowledged local terminal only * after its publisher has confirmed the CF release and armed this process's @@ -561,89 +552,73 @@ cluster_clean_leave_phase1_full_stop_post_stopped_receiver_ready( * release/completion phase is active; accepting a slower peer's replay in * that interval prevents a one-way completion race without reopening the * round or refreshing its deadline. */ - return local_stopped && request_in_progress && shutdown_driven - && preflight_sent && (preflight_pending || release_pending); + return local_stopped && request_in_progress && shutdown_driven && preflight_sent + && (preflight_pending || release_pending); } bool cluster_clean_leave_phase1_full_stop_release_probe_accepts( - uint8 producer_kind, uint8 wire_round, int32 envelope_source_node, - int32 payload_leaving_node, uint64 envelope_epoch, uint64 payload_epoch, - uint64 nonce, bool source_stopped, bool local_stopped, - bool exact_phase1_eligible) + uint8 producer_kind, uint8 wire_round, int32 envelope_source_node, int32 payload_leaving_node, + uint64 envelope_epoch, uint64 payload_epoch, uint64 nonce, bool source_stopped, + bool local_stopped, bool exact_phase1_eligible) { return producer_kind == CLUSTER_LEAVE_PRODUCER_SHUTDOWN - && wire_round == CLUSTER_PHASE1_FULL_STOP_WIRE_RELEASE - && envelope_source_node >= 0 - && envelope_source_node < CLUSTER_PHASE1_FULL_STOP_MEMBER_COUNT - && envelope_source_node == payload_leaving_node - && envelope_epoch == payload_epoch - && payload_epoch == 0 - && nonce != 0 && nonce != UINT64_MAX - && source_stopped && local_stopped && exact_phase1_eligible; + && wire_round == CLUSTER_PHASE1_FULL_STOP_WIRE_RELEASE && envelope_source_node >= 0 + && envelope_source_node < CLUSTER_PHASE1_FULL_STOP_MEMBER_COUNT + && envelope_source_node == payload_leaving_node && envelope_epoch == payload_epoch + && payload_epoch == 0 && nonce != 0 && nonce != UINT64_MAX && source_stopped + && local_stopped && exact_phase1_eligible; } bool -cluster_clean_leave_phase1_full_stop_receipt_accepts( - uint8 producer_kind, uint8 wire_round, bool release_pending, - uint64 stored_nonce, uint64 receipt_nonce, bool request_seen) +cluster_clean_leave_phase1_full_stop_receipt_accepts(uint8 producer_kind, uint8 wire_round, + bool release_pending, uint64 stored_nonce, + uint64 receipt_nonce, bool request_seen) { /* The exact receipt is peer-consumption evidence for a reply whose local * reply_sent publication may still be catching up after dispatch. Do not * require that local bookkeeping bit here: the terminal predicate checks it * independently together with every other delivery bit and transport drain. */ return producer_kind == CLUSTER_LEAVE_PRODUCER_SHUTDOWN - && wire_round == CLUSTER_PHASE1_FULL_STOP_WIRE_RECEIPT - && release_pending - && stored_nonce != 0 && stored_nonce != UINT64_MAX - && receipt_nonce == stored_nonce - && request_seen; + && wire_round == CLUSTER_PHASE1_FULL_STOP_WIRE_RECEIPT && release_pending + && stored_nonce != 0 && stored_nonce != UINT64_MAX && receipt_nonce == stored_nonce + && request_seen; } bool cluster_clean_leave_phase1_full_stop_release_complete( - const ClusterPhase1FullStopPlan *plan, int32 self_node, - const uint8 *request_sent, const uint8 *request_seen, - const uint8 *reply_sent, const uint8 *reply_seen, - const uint8 *receipt_sent, const uint8 *receipt_seen, - int nbytes, bool transport_drained) + const ClusterPhase1FullStopPlan *plan, int32 self_node, const uint8 *request_sent, + const uint8 *request_seen, const uint8 *reply_sent, const uint8 *reply_seen, + const uint8 *receipt_sent, const uint8 *receipt_seen, int nbytes, bool transport_drained) { return transport_drained - && cluster_clean_leave_phase1_full_stop_ack_complete( - plan, self_node, request_sent, nbytes) - && cluster_clean_leave_phase1_full_stop_ack_complete( - plan, self_node, request_seen, nbytes) - && cluster_clean_leave_phase1_full_stop_ack_complete( - plan, self_node, reply_sent, nbytes) - && cluster_clean_leave_phase1_full_stop_ack_complete( - plan, self_node, reply_seen, nbytes) - && cluster_clean_leave_phase1_full_stop_ack_complete( - plan, self_node, receipt_sent, nbytes) - && cluster_clean_leave_phase1_full_stop_ack_complete( - plan, self_node, receipt_seen, nbytes); + && cluster_clean_leave_phase1_full_stop_ack_complete(plan, self_node, request_sent, + nbytes) + && cluster_clean_leave_phase1_full_stop_ack_complete(plan, self_node, request_seen, + nbytes) + && cluster_clean_leave_phase1_full_stop_ack_complete(plan, self_node, reply_sent, nbytes) + && cluster_clean_leave_phase1_full_stop_ack_complete(plan, self_node, reply_seen, nbytes) + && cluster_clean_leave_phase1_full_stop_ack_complete(plan, self_node, receipt_sent, + nbytes) + && cluster_clean_leave_phase1_full_stop_ack_complete(plan, self_node, receipt_seen, + nbytes); } bool cluster_clean_leave_phase1_full_stop_request_ahead_can_consume( - bool retained, bool retained_before_local_round, - uint64 retained_local_nonce, uint64 retained_deadline_us, - uint64 current_local_nonce, uint64 current_deadline_us, - bool exact_identity, bool request_in_progress, - bool shutdown_driven, bool post_requests_sent) -{ - if (!retained || !exact_identity || !request_in_progress - || !shutdown_driven || !post_requests_sent - || retained_local_nonce == 0 - || retained_local_nonce == UINT64_MAX - || retained_deadline_us == 0 - || retained_deadline_us == UINT64_MAX - || current_local_nonce == 0 - || current_local_nonce == UINT64_MAX + bool retained, bool retained_before_local_round, uint64 retained_local_nonce, + uint64 retained_deadline_us, uint64 current_local_nonce, uint64 current_deadline_us, + bool exact_identity, bool request_in_progress, bool shutdown_driven, bool post_requests_sent) +{ + if (!retained || !exact_identity || !request_in_progress || !shutdown_driven + || !post_requests_sent || retained_local_nonce == 0 || retained_local_nonce == UINT64_MAX + || retained_deadline_us == 0 || retained_deadline_us == UINT64_MAX + || current_local_nonce == 0 || current_local_nonce == UINT64_MAX || current_deadline_us != retained_deadline_us) return false; if (retained_before_local_round) - return cluster_clean_leave_phase1_full_stop_nonce_fresh( - retained_local_nonce, current_local_nonce); + return cluster_clean_leave_phase1_full_stop_nonce_fresh(retained_local_nonce, + current_local_nonce); return current_local_nonce == retained_local_nonce; } @@ -662,38 +637,30 @@ cluster_clean_leave_phase1_full_stop_request_ahead_uses_predecessor_nonce( } bool -cluster_clean_leave_phase1_full_stop_ack_matches( - const ClusterPhase1FullStopPlan *plan, int32 self_node, - int32 envelope_source_node, int32 survivor_node, int32 leaving_node, - uint64 payload_epoch, uint64 attempt_nonce, - uint64 current_survivor_incarnation) -{ - return cluster_clean_leave_phase1_full_stop_plan_valid(plan) - && self_node >= 0 - && self_node < CLUSTER_PHASE1_FULL_STOP_MEMBER_COUNT - && survivor_node >= 0 - && survivor_node < CLUSTER_PHASE1_FULL_STOP_MEMBER_COUNT - && survivor_node != self_node - && envelope_source_node == survivor_node - && leaving_node == self_node - && payload_epoch == plan->epoch - && attempt_nonce == plan->attempt_nonce - && current_survivor_incarnation - == plan->member_incarnations[survivor_node]; +cluster_clean_leave_phase1_full_stop_ack_matches(const ClusterPhase1FullStopPlan *plan, + int32 self_node, int32 envelope_source_node, + int32 survivor_node, int32 leaving_node, + uint64 payload_epoch, uint64 attempt_nonce, + uint64 current_survivor_incarnation) +{ + return cluster_clean_leave_phase1_full_stop_plan_valid(plan) && self_node >= 0 + && self_node < CLUSTER_PHASE1_FULL_STOP_MEMBER_COUNT && survivor_node >= 0 + && survivor_node < CLUSTER_PHASE1_FULL_STOP_MEMBER_COUNT && survivor_node != self_node + && envelope_source_node == survivor_node && leaving_node == self_node + && payload_epoch == plan->epoch && attempt_nonce == plan->attempt_nonce + && current_survivor_incarnation == plan->member_incarnations[survivor_node]; } bool -cluster_clean_leave_phase1_full_stop_ack_complete( - const ClusterPhase1FullStopPlan *plan, int32 self_node, - const uint8 *ack_bitmap, int nbytes) +cluster_clean_leave_phase1_full_stop_ack_complete(const ClusterPhase1FullStopPlan *plan, + int32 self_node, const uint8 *ack_bitmap, + int nbytes) { uint8 expected; int i; - if (!cluster_clean_leave_phase1_full_stop_plan_valid(plan) - || self_node < 0 - || self_node >= CLUSTER_PHASE1_FULL_STOP_MEMBER_COUNT - || ack_bitmap == NULL + if (!cluster_clean_leave_phase1_full_stop_plan_valid(plan) || self_node < 0 + || self_node >= CLUSTER_PHASE1_FULL_STOP_MEMBER_COUNT || ack_bitmap == NULL || nbytes != CLUSTER_CLEAN_LEAVE_ACK_BITMAP_BYTES) return false; expected = (uint8)(UINT8_C(0x0f) & ~(UINT8_C(1) << self_node)); @@ -707,20 +674,17 @@ cluster_clean_leave_phase1_full_stop_ack_complete( } bool -cluster_clean_leave_phase1_full_stop_nonce_fresh(uint64 prior_nonce, - uint64 next_nonce) +cluster_clean_leave_phase1_full_stop_nonce_fresh(uint64 prior_nonce, uint64 next_nonce) { - return prior_nonce != 0 && prior_nonce != UINT64_MAX - && next_nonce != 0 && next_nonce != UINT64_MAX - && next_nonce != prior_nonce; + return prior_nonce != 0 && prior_nonce != UINT64_MAX && next_nonce != 0 + && next_nonce != UINT64_MAX && next_nonce != prior_nonce; } ClusterPhase1FullStopProbeNonceDecision -cluster_clean_leave_phase1_full_stop_probe_nonce_decide( - uint64 active_nonce, uint64 stopped_nonce, uint64 incoming_nonce) +cluster_clean_leave_phase1_full_stop_probe_nonce_decide(uint64 active_nonce, uint64 stopped_nonce, + uint64 incoming_nonce) { - if (active_nonce == 0 || active_nonce == UINT64_MAX - || stopped_nonce == UINT64_MAX + if (active_nonce == 0 || active_nonce == UINT64_MAX || stopped_nonce == UINT64_MAX || incoming_nonce == 0 || incoming_nonce == UINT64_MAX) return CLUSTER_PHASE1_PROBE_NONCE_CONFLICT; if (incoming_nonce == active_nonce) diff --git a/src/backend/cluster/cluster_control_root.c b/src/backend/cluster/cluster_control_root.c index e14be8451c8..16a94fc6a68 100644 --- a/src/backend/cluster/cluster_control_root.c +++ b/src/backend/cluster/cluster_control_root.c @@ -85,8 +85,7 @@ read_u16_le(const uint8 *src) static uint32 read_u32_le(const uint8 *src) { - return (uint32)src[0] | ((uint32)src[1] << 8) | ((uint32)src[2] << 16) - | ((uint32)src[3] << 24); + return (uint32)src[0] | ((uint32)src[1] << 8) | ((uint32)src[2] << 16) | ((uint32)src[3] << 24); } static uint64 @@ -100,8 +99,7 @@ read_u64_le(const uint8 *src) return value; } -static void make_file_token(const ControlRootImage *image, - ClusterControlRootFileToken *token); +static void make_file_token(const ControlRootImage *image, ClusterControlRootFileToken *token); static void write_u16_le(uint8 *dst, uint16 value) @@ -181,16 +179,14 @@ bool cluster_control_root_identity_equal(const ClusterControlRootIdentity *left, const ClusterControlRootIdentity *right) { - return left != NULL && right != NULL - && left->system_identifier == right->system_identifier + return left != NULL && right != NULL && left->system_identifier == right->system_identifier && memcmp(left->storage_uuid, right->storage_uuid, 16) == 0 && memcmp(left->authority_uuid, right->authority_uuid, 16) == 0 - && left->origin_thread_id == right->origin_thread_id - && left->reserved42 == 0 && right->reserved42 == 0 - && left->origin_node_id == right->origin_node_id + && left->origin_thread_id == right->origin_thread_id && left->reserved42 == 0 + && right->reserved42 == 0 && left->origin_node_id == right->origin_node_id && left->thread_claim_created_at == right->thread_claim_created_at - && left->thread_claim_crc32c == right->thread_claim_crc32c - && left->reserved60 == 0 && right->reserved60 == 0 + && left->thread_claim_crc32c == right->thread_claim_crc32c && left->reserved60 == 0 + && right->reserved60 == 0 && left->origin_owner_incarnation == right->origin_owner_incarnation && left->root_lineage_seq == right->root_lineage_seq; } @@ -240,8 +236,7 @@ control_paths_safe(void) if (!build_control_path(primary, sizeof(primary), CLUSTER_CONTROL_ROOT_REL_PATH) || !build_control_path(bak, sizeof(bak), CLUSTER_CONTROL_ROOT_BAK_REL_PATH)) return false; - return regular_or_absent_nosymlink(primary, true) - && regular_or_absent_nosymlink(bak, true); + return regular_or_absent_nosymlink(primary, true) && regular_or_absent_nosymlink(bak, true); } static int @@ -302,9 +297,8 @@ static bool snapshot_reserved_zero(const ClusterControlRootSnapshot *snapshot) { return snapshot->identity.reserved42 == 0 && snapshot->identity.reserved60 == 0 - && snapshot->reserved96 == 0 && snapshot->reserved122 == 0 - && snapshot->reserved124 == 0 && snapshot->reserved160 == 0 - && snapshot->reserved208 == 0; + && snapshot->reserved96 == 0 && snapshot->reserved122 == 0 && snapshot->reserved124 == 0 + && snapshot->reserved160 == 0 && snapshot->reserved208 == 0; } static ClusterControlRootResult @@ -346,12 +340,10 @@ snapshot_validate(const ClusterControlRootSnapshot *snapshot, uint16 expected_th tail_valid = (flags & CLUSTER_CONTROL_ROOT_FLAG_TAIL_VALID) != 0; recovered_valid = (flags & CLUSTER_CONTROL_ROOT_FLAG_RECOVERED_VALID) != 0; tail_last_valid = (flags & CLUSTER_CONTROL_ROOT_FLAG_TAIL_LAST_RECORD_VALID) != 0; - recovered_last_valid = - (flags & CLUSTER_CONTROL_ROOT_FLAG_RECOVERED_LAST_RECORD_VALID) != 0; + recovered_last_valid = (flags & CLUSTER_CONTROL_ROOT_FLAG_RECOVERED_LAST_RECORD_VALID) != 0; bound_valid = (flags & CLUSTER_CONTROL_ROOT_FLAG_CONSERVATIVE_SCN_VALID) != 0; - if (!checkpoint_valid || snapshot->checkpoint_tli == 0 - || snapshot->checkpoint_lower_lsn == 0 + if (!checkpoint_valid || snapshot->checkpoint_tli == 0 || snapshot->checkpoint_lower_lsn == 0 || snapshot->checkpoint_record_crc32c == 0 || (snapshot->checkpoint_source_kind != CLUSTER_CONTROL_ROOT_CHECKPOINT_NATIVE_V1 && snapshot->checkpoint_source_kind @@ -359,8 +351,7 @@ snapshot_validate(const ClusterControlRootSnapshot *snapshot, uint16 expected_th return CLUSTER_CONTROL_ROOT_RANGE_INVALID; if (tail_valid) { if (snapshot->tail_tli == 0 - || snapshot->tail_validation_kind - != CLUSTER_CONTROL_ROOT_TAIL_WAL_RECORD_SCAN_V1 + || snapshot->tail_validation_kind != CLUSTER_CONTROL_ROOT_TAIL_WAL_RECORD_SCAN_V1 || snapshot->validated_tail_lsn_exclusive < snapshot->checkpoint_lower_lsn) return CLUSTER_CONTROL_ROOT_RANGE_INVALID; if (snapshot->validated_tail_lsn_exclusive == snapshot->checkpoint_lower_lsn) { @@ -369,20 +360,17 @@ snapshot_validate(const ClusterControlRootSnapshot *snapshot, uint16 expected_th return CLUSTER_CONTROL_ROOT_RANGE_INVALID; } else if (!tail_last_valid || snapshot->tail_last_record_lsn == 0 || snapshot->tail_last_record_crc32c == 0 - || snapshot->tail_last_record_lsn - >= snapshot->validated_tail_lsn_exclusive) + || snapshot->tail_last_record_lsn >= snapshot->validated_tail_lsn_exclusive) return CLUSTER_CONTROL_ROOT_RANGE_INVALID; } else if (snapshot->tail_tli != 0 || snapshot->tail_validation_kind != 0 || snapshot->validated_tail_lsn_exclusive != 0 || tail_last_valid - || snapshot->tail_last_record_lsn != 0 - || snapshot->tail_last_record_crc32c != 0) + || snapshot->tail_last_record_lsn != 0 || snapshot->tail_last_record_crc32c != 0) return CLUSTER_CONTROL_ROOT_RANGE_INVALID; if (recovered_valid) { if (!tail_valid || snapshot->recovered_tli == 0 || snapshot->recovered_through_lsn_exclusive < snapshot->checkpoint_lower_lsn - || snapshot->recovered_through_lsn_exclusive - > snapshot->validated_tail_lsn_exclusive) + || snapshot->recovered_through_lsn_exclusive > snapshot->validated_tail_lsn_exclusive) return CLUSTER_CONTROL_ROOT_RANGE_INVALID; if (snapshot->recovered_through_lsn_exclusive == snapshot->checkpoint_lower_lsn) { if (recovered_last_valid || snapshot->recovered_last_record_lsn != 0 @@ -391,19 +379,17 @@ snapshot_validate(const ClusterControlRootSnapshot *snapshot, uint16 expected_th } else if (!recovered_last_valid || snapshot->recovered_last_record_lsn == 0 || snapshot->recovered_last_record_crc32c == 0 || snapshot->recovered_last_record_lsn - >= snapshot->recovered_through_lsn_exclusive) + >= snapshot->recovered_through_lsn_exclusive) return CLUSTER_CONTROL_ROOT_RANGE_INVALID; } else if (snapshot->recovered_tli != 0 || recovered_last_valid || snapshot->recovered_last_record_lsn != 0 || snapshot->recovered_last_record_crc32c != 0 || (snapshot->recovered_through_lsn_exclusive != 0 - && snapshot->recovered_through_lsn_exclusive - != snapshot->checkpoint_lower_lsn)) + && snapshot->recovered_through_lsn_exclusive != snapshot->checkpoint_lower_lsn)) return CLUSTER_CONTROL_ROOT_RANGE_INVALID; if (bound_valid) { - if (snapshot->conservative_bound_kind - != CLUSTER_CONTROL_ROOT_BOUND_R14_M1_PARTITION_S_V1 + if (snapshot->conservative_bound_kind != CLUSTER_CONTROL_ROOT_BOUND_R14_M1_PARTITION_S_V1 || snapshot->conservative_commit_scn == 0) return CLUSTER_CONTROL_ROOT_RANGE_INVALID; } else if (snapshot->conservative_bound_kind != CLUSTER_CONTROL_ROOT_BOUND_NONE @@ -416,9 +402,8 @@ snapshot_validate(const ClusterControlRootSnapshot *snapshot, uint16 expected_th } static void -encode_record(uint8 *dst, const ClusterControlRootSnapshot *snapshot, - uint64 publisher_incarnation, uint32 publisher_node, - ClusterControlRootPublishReason reason) +encode_record(uint8 *dst, const ClusterControlRootSnapshot *snapshot, uint64 publisher_incarnation, + uint32 publisher_node, ClusterControlRootPublishReason reason) { memset(dst, 0, CLUSTER_CONTROL_ROOT_RECORD_BYTES); memcpy(dst, CONTROL_ROOT_RECORD_MAGIC, 4); @@ -555,9 +540,9 @@ encode_header(ControlRootImage *image) write_u32_le(dst + 76, image->header.activation_state); write_u64_le(dst + 80, (uint64)image->header.created_at_usec); write_u64_le(dst + 88, (uint64)image->header.published_at_usec); - image->header.body_crc32c = control_root_crc( - image->bytes + CONTROL_ROOT_BODY_OFFSET, - CLUSTER_CONTROL_ROOT_FILE_BYTES - CONTROL_ROOT_BODY_OFFSET); + image->header.body_crc32c + = control_root_crc(image->bytes + CONTROL_ROOT_BODY_OFFSET, + CLUSTER_CONTROL_ROOT_FILE_BYTES - CONTROL_ROOT_BODY_OFFSET); write_u32_le(dst + 96, image->header.body_crc32c); memcpy(dst + 100, image->header.migration_round_sha256, PG_SHA256_DIGEST_LENGTH); memcpy(dst + 132, image->header.source_wal_state_sha256, PG_SHA256_DIGEST_LENGTH); @@ -626,19 +611,18 @@ decode_image(ControlRootImage *image, const uint8 current_uuid[16], uint64 curre || !cluster_control_root_feature_bitmap_is_known(image->header.source_feature_bitmap) || !cluster_control_root_feature_bitmap_is_known(image->header.target_feature_bitmap) || (image->header.target_feature_bitmap - & PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1) == 0) + & PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1) + == 0) return CLUSTER_CONTROL_ROOT_MIXED_VERSION; if (image->header.body_crc32c != control_root_crc(src + CONTROL_ROOT_BODY_OFFSET, - CLUSTER_CONTROL_ROOT_FILE_BYTES - CONTROL_ROOT_BODY_OFFSET)) + CLUSTER_CONTROL_ROOT_FILE_BYTES - CONTROL_ROOT_BODY_OFFSET)) return CLUSTER_CONTROL_ROOT_BAD_BODY_CRC; for (i = 0; i < CLUSTER_CONTROL_ROOT_RECORD_COUNT; i++) { ClusterControlRootResult result = decode_record( - src + CLUSTER_CONTROL_ROOT_HEADER_BYTES - + (size_t)i * CLUSTER_CONTROL_ROOT_RECORD_BYTES, - (uint16)(i + 1), &image->header, &image->records[i], - &image->record_crc32c[i]); + src + CLUSTER_CONTROL_ROOT_HEADER_BYTES + (size_t)i * CLUSTER_CONTROL_ROOT_RECORD_BYTES, + (uint16)(i + 1), &image->header, &image->records[i], &image->record_crc32c[i]); if (result == CLUSTER_CONTROL_ROOT_ABSENT) continue; @@ -701,14 +685,15 @@ same_immutable_header(const ControlRootImage *left, const ControlRootImage *righ return left->header.system_identifier == right->header.system_identifier && memcmp(left->header.storage_uuid, right->header.storage_uuid, 16) == 0 && memcmp(left->header.authority_uuid, right->header.authority_uuid, 16) == 0 - && memcmp(left->header.migration_round_sha256, - right->header.migration_round_sha256, PG_SHA256_DIGEST_LENGTH) == 0 - && memcmp(left->header.source_wal_state_sha256, - right->header.source_wal_state_sha256, PG_SHA256_DIGEST_LENGTH) == 0 + && memcmp(left->header.migration_round_sha256, right->header.migration_round_sha256, + PG_SHA256_DIGEST_LENGTH) + == 0 + && memcmp(left->header.source_wal_state_sha256, right->header.source_wal_state_sha256, + PG_SHA256_DIGEST_LENGTH) + == 0 && left->header.migration_prepare_generation == right->header.migration_prepare_generation - && left->header.migration_transition_epoch - == right->header.migration_transition_epoch + && left->header.migration_transition_epoch == right->header.migration_transition_epoch && left->header.source_feature_bitmap == right->header.source_feature_bitmap && left->header.target_feature_bitmap == right->header.target_feature_bitmap; } @@ -738,8 +723,7 @@ read_canonical_pair(ControlRootImage *primary, ControlRootImage *bak) if (!same_immutable_header(primary, bak) || bak->header.file_txn_seq > primary->header.file_txn_seq || (bak->header.file_txn_seq == primary->header.file_txn_seq - && memcmp(primary->bytes, bak->bytes, - CLUSTER_CONTROL_ROOT_FILE_BYTES) != 0)) + && memcmp(primary->bytes, bak->bytes, CLUSTER_CONTROL_ROOT_FILE_BYTES) != 0)) return CLUSTER_CONTROL_ROOT_COPY_DIVERGENT; return CLUSTER_CONTROL_ROOT_OK_PRIMARY; } @@ -793,29 +777,25 @@ cluster_control_root_restore_bit22_latch_if_active(void) * — a REAL durable OPEN(P+2) record reads back nonzero, so the flag * must NOT gate the restore (a post-bit22 restart would never re-arm * the latch and the control-plane gates would stay closed). */ - qv_result = cluster_qvotec_bootstrap_read_semantic_activation( - selected, &implicit_open); - (void) implicit_open; + qv_result = cluster_qvotec_bootstrap_read_semantic_activation(selected, &implicit_open); + (void)implicit_open; if (qv_result != CLUSTER_SEMANTIC_ACTIVATION_OK - || !cluster_semantic_activation_record_decode( - selected, &open, NULL) + || !cluster_semantic_activation_record_decode(selected, &open, NULL) || open.phase != CLUSTER_SEMANTIC_PHASE_OPEN) return false; root_result = read_canonical_pair(&primary, &bak); if (root_result != CLUSTER_CONTROL_ROOT_OK_PRIMARY && root_result != CLUSTER_CONTROL_ROOT_OK_PRIMARY_DEGRADED) return false; - if (primary.header.activation_state - != CLUSTER_CONTROL_ROOT_ACTIVATION_ACTIVE + if (primary.header.activation_state != CLUSTER_CONTROL_ROOT_ACTIVATION_ACTIVE || (primary.header.target_feature_bitmap - & PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1) == 0 + & PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1) + == 0 || primary.header.migration_transition_epoch != open.transition_epoch || primary.header.migration_prepare_generation == UINT64_MAX - || primary.header.migration_prepare_generation + 2 - != open.record_generation) + || primary.header.migration_prepare_generation + 2 != open.record_generation) return false; - return cluster_r4_bit22_cutover_latch_apply( - open.transition_epoch, open.record_generation); + return cluster_r4_bit22_cutover_latch_apply(open.transition_epoch, open.record_generation); } /* @@ -829,25 +809,21 @@ cluster_control_root_restore_bit22_latch_if_active(void) */ ClusterControlRootResult cluster_control_root_bootstrap_validate_active_round( - const ClusterControlRootMigrationRoundV1 *round, - ClusterControlRootFileToken *token) + const ClusterControlRootMigrationRoundV1 *round, ClusterControlRootFileToken *token) { ControlRootImage primary; ControlRootImage bak; uint8 sha[PG_SHA256_DIGEST_LENGTH]; ClusterControlRootResult result; - if (round == NULL - || !cluster_control_root_round_sha256(round, sha)) + if (round == NULL || !cluster_control_root_round_sha256(round, sha)) return CLUSTER_CONTROL_ROOT_INVALID_ARGUMENT; result = read_canonical_pair(&primary, &bak); if (result != CLUSTER_CONTROL_ROOT_OK_PRIMARY && result != CLUSTER_CONTROL_ROOT_OK_PRIMARY_DEGRADED) return result; - if (primary.header.activation_state - != CLUSTER_CONTROL_ROOT_ACTIVATION_ACTIVE - || memcmp(primary.header.migration_round_sha256, sha, - PG_SHA256_DIGEST_LENGTH) != 0) + if (primary.header.activation_state != CLUSTER_CONTROL_ROOT_ACTIVATION_ACTIVE + || memcmp(primary.header.migration_round_sha256, sha, PG_SHA256_DIGEST_LENGTH) != 0) return CLUSTER_CONTROL_ROOT_IDENTITY_MISMATCH; if (token != NULL) make_file_token(&primary, token); @@ -869,9 +845,10 @@ cluster_control_root_bootstrap_validate_active_round( * read_canonical_pair; read-only, grants no token authority. */ ClusterControlRootResult -cluster_control_root_bootstrap_validate_active_round_fields( - uint64 transition_epoch, uint64 prepare_generation, - uint64 source_feature_bitmap, uint64 target_feature_bitmap) +cluster_control_root_bootstrap_validate_active_round_fields(uint64 transition_epoch, + uint64 prepare_generation, + uint64 source_feature_bitmap, + uint64 target_feature_bitmap) { ControlRootImage primary; ControlRootImage bak; @@ -881,8 +858,7 @@ cluster_control_root_bootstrap_validate_active_round_fields( if (result != CLUSTER_CONTROL_ROOT_OK_PRIMARY && result != CLUSTER_CONTROL_ROOT_OK_PRIMARY_DEGRADED) return result; - if (primary.header.activation_state - != CLUSTER_CONTROL_ROOT_ACTIVATION_ACTIVE + if (primary.header.activation_state != CLUSTER_CONTROL_ROOT_ACTIVATION_ACTIVE || primary.header.migration_transition_epoch != transition_epoch || primary.header.migration_prepare_generation != prepare_generation || primary.header.source_feature_bitmap != source_feature_bitmap @@ -912,8 +888,7 @@ make_read_token(const ControlRootImage *image, uint16 thread_id, uint8 source, } static bool -read_token_equal(const ClusterControlRootReadToken *left, - const ClusterControlRootReadToken *right) +read_token_equal(const ClusterControlRootReadToken *left, const ClusterControlRootReadToken *right) { return left != NULL && right != NULL && memcmp(left, right, sizeof(*left)) == 0; } @@ -940,10 +915,10 @@ release_cf(LOCKMODE mode, ClusterControlRootResult result) ClusterControlRootResult cluster_control_root_read_canonical(uint16 origin_thread_id, - const ClusterControlRootIdentity *expected_identity, - ClusterControlRootReadMode mode, - ClusterControlRootSnapshot *out_snapshot, - ClusterControlRootReadToken *out_token) + const ClusterControlRootIdentity *expected_identity, + ClusterControlRootReadMode mode, + ClusterControlRootSnapshot *out_snapshot, + ClusterControlRootReadToken *out_token) { ControlRootImage *primary; ControlRootImage *bak; @@ -981,8 +956,8 @@ cluster_control_root_read_canonical(uint16 origin_thread_id, if ((result == CLUSTER_CONTROL_ROOT_OK_PRIMARY || result == CLUSTER_CONTROL_ROOT_OK_PRIMARY_DEGRADED) && expected_identity != NULL - && !cluster_control_root_identity_equal( - expected_identity, &primary->records[origin_thread_id - 1].identity)) + && !cluster_control_root_identity_equal(expected_identity, + &primary->records[origin_thread_id - 1].identity)) result = CLUSTER_CONTROL_ROOT_IDENTITY_MISMATCH; if (result == CLUSTER_CONTROL_ROOT_OK_PRIMARY || result == CLUSTER_CONTROL_ROOT_OK_PRIMARY_DEGRADED) { @@ -994,7 +969,7 @@ cluster_control_root_read_canonical(uint16 origin_thread_id, * bound phase-4 revalidation — upgrade a bootstrapped bit22 * latch to TARGET_VERIFIED (the serving/admission gate). * Idempotent; a SOURCE latch is left untouched. */ - (void) cluster_r4_bit22_cutover_latch_verify(); + (void)cluster_r4_bit22_cutover_latch_verify(); } } pfree(bak); @@ -1025,9 +1000,9 @@ cluster_control_root_read_canonical(uint16 origin_thread_id, * decision directly. */ ClusterControlRootResult -cluster_control_root_read_canonical_discovered( - uint16 origin_thread_id, ClusterControlRootSnapshot *out_snapshot, - ClusterControlRootReadToken *out_token) +cluster_control_root_read_canonical_discovered(uint16 origin_thread_id, + ClusterControlRootSnapshot *out_snapshot, + ClusterControlRootReadToken *out_token) { ClusterControlRootSnapshot bootstrap; ClusterControlRootIdentity discovered; @@ -1041,15 +1016,13 @@ cluster_control_root_read_canonical_discovered( memset(out_token, 0, sizeof(*out_token)); memset(&bootstrap, 0, sizeof(bootstrap)); result = cluster_control_root_read_canonical( - origin_thread_id, NULL, CLUSTER_CONTROL_ROOT_READ_BOOTSTRAP_VALIDATE, - &bootstrap, NULL); + origin_thread_id, NULL, CLUSTER_CONTROL_ROOT_READ_BOOTSTRAP_VALIDATE, &bootstrap, NULL); if (result != CLUSTER_CONTROL_ROOT_OK_PRIMARY && result != CLUSTER_CONTROL_ROOT_OK_PRIMARY_DEGRADED) return result; discovered = bootstrap.identity; return cluster_control_root_read_canonical( - origin_thread_id, &discovered, CLUSTER_CONTROL_ROOT_READ_STRONG, - out_snapshot, out_token); + origin_thread_id, &discovered, CLUSTER_CONTROL_ROOT_READ_STRONG, out_snapshot, out_token); } /* @@ -1068,8 +1041,8 @@ cluster_control_root_read_canonical_discovered( * remaster -> unfreeze -> CF-shard-NORMAL deadlock. */ ClusterControlRootResult -cluster_control_root_read_canonical_dead_origin( - uint16 origin_thread_id, ClusterControlRootSnapshot *out_snapshot) +cluster_control_root_read_canonical_dead_origin(uint16 origin_thread_id, + ClusterControlRootSnapshot *out_snapshot) { ControlRootImage *primary; ControlRootImage *bak; @@ -1077,8 +1050,7 @@ cluster_control_root_read_canonical_dead_origin( if (out_snapshot != NULL) memset(out_snapshot, 0, sizeof(*out_snapshot)); - if (origin_thread_id == 0 - || origin_thread_id > CLUSTER_CONTROL_ROOT_RECORD_COUNT) + if (origin_thread_id == 0 || origin_thread_id > CLUSTER_CONTROL_ROOT_RECORD_COUNT) return CLUSTER_CONTROL_ROOT_INVALID_ARGUMENT; result = storage_contract_check(NULL, false); if (result != CLUSTER_CONTROL_ROOT_OK_PRIMARY) @@ -1103,9 +1075,9 @@ cluster_control_root_read_canonical_dead_origin( ClusterControlRootResult cluster_control_root_lookup_owner_by_node_runtime(int32 old_node_id, - ClusterControlRootIdentity *out_identity, - ClusterControlRootSnapshot *out_snapshot, - ClusterControlRootReadToken *out_token) + ClusterControlRootIdentity *out_identity, + ClusterControlRootSnapshot *out_snapshot, + ClusterControlRootReadToken *out_token) { ControlRootImage *primary; ControlRootImage *bak; @@ -1164,16 +1136,14 @@ encode_round(const ClusterControlRootMigrationRoundV1 *round, uint8 bytes[80]) if (round == NULL || memcmp(round->magic, "PCRM", 4) != 0 || round->version != 1 || round->bytes != sizeof(*round) || round->prepare_generation == 0 || round->coordinator_incarnation == 0 - || round->coordinator_node_id >= CLUSTER_CONTROL_ROOT_RECORD_COUNT - || round->reserved76 != 0 + || round->coordinator_node_id >= CLUSTER_CONTROL_ROOT_RECORD_COUNT || round->reserved76 != 0 || !cluster_control_root_feature_bitmap_is_known(round->source_feature_bitmap) || !cluster_control_root_feature_bitmap_is_known(round->target_feature_bitmap) /* STOP04 §11.7: this package has no selected/certified production * provider, so a migration image must not activate bit24. */ - || (round->target_feature_bitmap & - PGRAC_CONTROL_ROOT_FEATURE_EXTERNAL_FENCE_V1) != 0 - || (round->target_feature_bitmap - & PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1) == 0) + || (round->target_feature_bitmap & PGRAC_CONTROL_ROOT_FEATURE_EXTERNAL_FENCE_V1) != 0 + || (round->target_feature_bitmap & PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1) + == 0) return false; memset(bytes, 0, 80); memcpy(bytes, "PCRM", 4); @@ -1212,7 +1182,7 @@ migration_image_validate(const ClusterControlRootMigrationImage *image, continue; } if (snapshot_validate(snapshot, (uint16)(i + 1), image->system_identifier, - image->storage_uuid, image->authority_uuid) + image->storage_uuid, image->authority_uuid) != CLUSTER_CONTROL_ROOT_OK_PRIMARY) return false; if (snapshot->identity.root_lineage_seq != 1) @@ -1225,8 +1195,7 @@ migration_image_validate(const ClusterControlRootMigrationImage *image, } static bool -read_thread_claim_exact(uint16 thread_id, int32 node_id, - const ClusterControlRootIdentity *expected) +read_thread_claim_exact(uint16 thread_id, int32 node_id, const ClusterControlRootIdentity *expected) { ClusterWalThreadClaim claim; char dirname[MAXPGPATH]; @@ -1242,14 +1211,12 @@ read_thread_claim_exact(uint16 thread_id, int32 node_id, if (dirname[0] == '\0' || written <= 0 || (size_t)written >= sizeof(dirpath) || lstat(dirpath, &st) != 0 || !S_ISDIR(st.st_mode)) return false; - written = snprintf(path, sizeof(path), "%s/%s", dirpath, - CLUSTER_WAL_THREAD_CLAIM_FILENAME); + written = snprintf(path, sizeof(path), "%s/%s", dirpath, CLUSTER_WAL_THREAD_CLAIM_FILENAME); if (written <= 0 || (size_t)written >= sizeof(path) || !regular_or_absent_nosymlink(path, false)) return false; fd = OpenTransientFile(path, O_RDONLY | PG_BINARY); - if (fd < 0 || fstat(fd, &st) != 0 || !S_ISREG(st.st_mode) - || st.st_size != sizeof(claim)) { + if (fd < 0 || fstat(fd, &st) != 0 || !S_ISREG(st.st_mode) || st.st_size != sizeof(claim)) { if (fd >= 0) CloseTransientFile(fd); return false; @@ -1294,7 +1261,8 @@ read_source_wal_state(const ClusterControlRootSnapshot *expected_records, if (cluster_wal_threads_dir == NULL || cluster_wal_threads_dir[0] == '\0' || lstat(cluster_wal_threads_dir, &st) != 0 || !S_ISDIR(st.st_mode) || snprintf(path, sizeof(path), "%s/%s", cluster_wal_threads_dir, - CLUSTER_WAL_STATE_FILENAME) <= 0 + CLUSTER_WAL_STATE_FILENAME) + <= 0 || !regular_or_absent_nosymlink(path, false)) return CLUSTER_CONTROL_ROOT_IO_ERROR; first = palloc(CLUSTER_WAL_STATE_FILE_SIZE); @@ -1323,8 +1291,8 @@ read_source_wal_state(const ClusterControlRootSnapshot *expected_records, done += (size_t)n; } if (CloseTransientFile(fd) != 0 - || !cluster_wal_state_image_validate(dst, CLUSTER_WAL_STATE_FILE_SIZE, - &bad_thread, &reason)) { + || !cluster_wal_state_image_validate(dst, CLUSTER_WAL_STATE_FILE_SIZE, &bad_thread, + &reason)) { pfree(second); pfree(first); return CLUSTER_CONTROL_ROOT_HASH_MISMATCH; @@ -1354,16 +1322,13 @@ read_source_wal_state(const ClusterControlRootSnapshot *expected_records, } if (verdict != CLUSTER_WAL_SLOT_OK || (slot.state != CLUSTER_WAL_SLOT_STATE_STOPPED - && !(slot.state == CLUSTER_WAL_SLOT_STATE_ACTIVE - && round != NULL - && cluster_r4_bit22_source_close_current( - round->transition_epoch, - round->prepare_generation))) + && !(slot.state == CLUSTER_WAL_SLOT_STATE_ACTIVE && round != NULL + && cluster_r4_bit22_source_close_current(round->transition_epoch, + round->prepare_generation))) || slot.checkpoint_redo_lsn == 0 || slot.merge_recovered_lsn != 0 || expected->identity.system_identifier == 0 || expected->identity.origin_node_id != slot.node_id - || !read_thread_claim_exact((uint16)(i + 1), slot.node_id, - &expected->identity)) { + || !read_thread_claim_exact((uint16)(i + 1), slot.node_id, &expected->identity)) { pfree(second); pfree(first); return CLUSTER_CONTROL_ROOT_HASH_MISMATCH; @@ -1382,8 +1347,7 @@ read_source_wal_state(const ClusterControlRootSnapshot *expected_records, } pfree(second); pfree(first); - if (expected_hash != NULL - && memcmp(expected_hash, hash_out, PG_SHA256_DIGEST_LENGTH) != 0) + if (expected_hash != NULL && memcmp(expected_hash, hash_out, PG_SHA256_DIGEST_LENGTH) != 0) return CLUSTER_CONTROL_ROOT_HASH_MISMATCH; return CLUSTER_CONTROL_ROOT_OK_PRIMARY; } @@ -1428,9 +1392,9 @@ write_durable_image(const char *final_path, const uint8 *bytes) base = strrchr(final_path, '/'); if (base == NULL) return false; - if (snprintf(temp_path, sizeof(temp_path), "%.*s/%s.tmp.%d.%ld.%s", - (int)(base - final_path), final_path, base + 1, cluster_node_id, - (long)getpid(), suffix) <= 0) + if (snprintf(temp_path, sizeof(temp_path), "%.*s/%s.tmp.%d.%ld.%s", (int)(base - final_path), + final_path, base + 1, cluster_node_id, (long)getpid(), suffix) + <= 0) return false; fd = BasicOpenFilePerm(temp_path, O_WRONLY | O_CREAT | O_EXCL | PG_BINARY, 0600); if (fd < 0) @@ -1491,8 +1455,7 @@ publish_initial_image(const ControlRootImage *image) return false; if (lstat(bak, &st) == 0 || errno != ENOENT) return false; - return write_durable_image(bak, image->bytes) - && write_durable_image(primary, image->bytes); + return write_durable_image(bak, image->bytes) && write_durable_image(primary, image->bytes); } static bool @@ -1520,14 +1483,12 @@ make_file_token(const ControlRootImage *image, ClusterControlRootFileToken *toke token->format_version = CONTROL_ROOT_FORMAT_VERSION; token->record_count = CLUSTER_CONTROL_ROOT_RECORD_COUNT; token->system_identifier = image->header.system_identifier; - if (!control_root_sha256(image->bytes, CLUSTER_CONTROL_ROOT_FILE_BYTES, - token->image_sha256)) + if (!control_root_sha256(image->bytes, CLUSTER_CONTROL_ROOT_FILE_BYTES, token->image_sha256)) memset(token, 0, sizeof(*token)); } static bool -file_token_equal(const ClusterControlRootFileToken *left, - const ClusterControlRootFileToken *right) +file_token_equal(const ClusterControlRootFileToken *left, const ClusterControlRootFileToken *right) { return left != NULL && right != NULL && memcmp(left, right, sizeof(*left)) == 0; } @@ -1539,8 +1500,7 @@ file_token_equal(const ClusterControlRootFileToken *left, * write-once (spec-4.1), so this is the durable origin evidence. */ static bool -read_thread_claim_fields(uint16 thread_id, int32 node_id, - ClusterControlRootIdentity *identity) +read_thread_claim_fields(uint16 thread_id, int32 node_id, ClusterControlRootIdentity *identity) { ClusterWalThreadClaim claim; char dirname[MAXPGPATH]; @@ -1554,22 +1514,17 @@ read_thread_claim_fields(uint16 thread_id, int32 node_id, return false; cluster_wal_thread_dir_name(thread_id, dirname, sizeof(dirname)); if (dirname[0] == '\0' - || snprintf(dirpath, sizeof(dirpath), "%s/%s", - cluster_wal_threads_dir, dirname) <= 0 - || (size_t)snprintf(dirpath, sizeof(dirpath), "%s/%s", - cluster_wal_threads_dir, dirname) - >= sizeof(dirpath) + || snprintf(dirpath, sizeof(dirpath), "%s/%s", cluster_wal_threads_dir, dirname) <= 0 + || (size_t)snprintf(dirpath, sizeof(dirpath), "%s/%s", cluster_wal_threads_dir, dirname) + >= sizeof(dirpath) || lstat(dirpath, &st) != 0 || !S_ISDIR(st.st_mode)) return false; - if (snprintf(path, sizeof(path), "%s/%s", dirpath, - CLUSTER_WAL_THREAD_CLAIM_FILENAME) <= 0 - || (size_t)snprintf(path, sizeof(path), "%s/%s", dirpath, - CLUSTER_WAL_THREAD_CLAIM_FILENAME) - >= sizeof(path)) + if (snprintf(path, sizeof(path), "%s/%s", dirpath, CLUSTER_WAL_THREAD_CLAIM_FILENAME) <= 0 + || (size_t)snprintf(path, sizeof(path), "%s/%s", dirpath, CLUSTER_WAL_THREAD_CLAIM_FILENAME) + >= sizeof(path)) return false; fd = OpenTransientFile(path, O_RDONLY | PG_BINARY); - if (fd < 0 || fstat(fd, &st) != 0 || !S_ISREG(st.st_mode) - || st.st_size != sizeof(claim)) { + if (fd < 0 || fstat(fd, &st) != 0 || !S_ISREG(st.st_mode) || st.st_size != sizeof(claim)) { if (fd >= 0) CloseTransientFile(fd); return false; @@ -1601,15 +1556,13 @@ read_thread_claim_fields(uint16 thread_id, int32 node_id, */ typedef struct MigrationWalReaderPrivate { char thread_dir[MAXPGPATH]; - uint32 tli; /* stream TLI (from the wal-state slot) */ + uint32 tli; /* stream TLI (from the wal-state slot) */ } MigrationWalReaderPrivate; static void -migration_wal_segment_open(XLogReaderState *state, XLogSegNo nextSegNo, - TimeLineID *tli_p) +migration_wal_segment_open(XLogReaderState *state, XLogSegNo nextSegNo, TimeLineID *tli_p) { - MigrationWalReaderPrivate *priv = - (MigrationWalReaderPrivate *) state->private_data; + MigrationWalReaderPrivate *priv = (MigrationWalReaderPrivate *)state->private_data; char fname[MAXFNAMELEN]; char path[MAXPGPATH]; int written; @@ -1620,7 +1573,7 @@ migration_wal_segment_open(XLogReaderState *state, XLogSegNo nextSegNo, } XLogFileName(fname, *tli_p, nextSegNo, state->segcxt.ws_segsize); written = snprintf(path, sizeof(path), "%s/%s", priv->thread_dir, fname); - if (written <= 0 || (size_t) written >= sizeof(path)) { + if (written <= 0 || (size_t)written >= sizeof(path)) { state->seg.ws_file = -1; return; } @@ -1642,12 +1595,10 @@ migration_wal_segment_close(XLogReaderState *state) } static int -migration_wal_read_page(XLogReaderState *state, XLogRecPtr targetPagePtr, - int reqLen, XLogRecPtr targetRecPtr, - char *cur_page) +migration_wal_read_page(XLogReaderState *state, XLogRecPtr targetPagePtr, int reqLen, + XLogRecPtr targetRecPtr, char *cur_page) { - MigrationWalReaderPrivate *priv = - (MigrationWalReaderPrivate *) state->private_data; + MigrationWalReaderPrivate *priv = (MigrationWalReaderPrivate *)state->private_data; WALReadError errinfo; /* WALRead drives segment_open/close and pg_pread; a short read or a @@ -1655,8 +1606,7 @@ migration_wal_read_page(XLogReaderState *state, XLogRecPtr targetPagePtr, * reader treats as EOF. */ if (priv == NULL) return XLREAD_FAIL; - if (!WALRead(state, cur_page, targetPagePtr, XLOG_BLCKSZ, priv->tli, - &errinfo)) + if (!WALRead(state, cur_page, targetPagePtr, XLOG_BLCKSZ, priv->tli, &errinfo)) return XLREAD_WOULDBLOCK; return XLOG_BLCKSZ; } @@ -1669,9 +1619,8 @@ migration_wal_read_page(XLogReaderState *state, XLogRecPtr targetPagePtr, * then cannot pass migration_image_validate — the round stays un-begun). */ static bool -migration_wal_scan(uint16 thread_id, uint32 tli, XLogRecPtr checkpoint_redo, - XLogRecPtr write_pos, uint32 *out_ckpt_crc, - XLogRecPtr *out_tail_last_lsn, uint32 *out_tail_last_crc) +migration_wal_scan(uint16 thread_id, uint32 tli, XLogRecPtr checkpoint_redo, XLogRecPtr write_pos, + uint32 *out_ckpt_crc, XLogRecPtr *out_tail_last_lsn, uint32 *out_tail_last_crc) { MigrationWalReaderPrivate priv; XLogReaderState *reader; @@ -1680,10 +1629,8 @@ migration_wal_scan(uint16 thread_id, uint32 tli, XLogRecPtr checkpoint_redo, char *errormsg; bool saw_checkpoint = false; - if (out_ckpt_crc == NULL || out_tail_last_lsn == NULL - || out_tail_last_crc == NULL || tli == 0 - || XLogRecPtrIsInvalid(checkpoint_redo) - || XLogRecPtrIsInvalid(write_pos) + if (out_ckpt_crc == NULL || out_tail_last_lsn == NULL || out_tail_last_crc == NULL || tli == 0 + || XLogRecPtrIsInvalid(checkpoint_redo) || XLogRecPtrIsInvalid(write_pos) || write_pos < checkpoint_redo) return false; *out_ckpt_crc = 0; @@ -1696,11 +1643,12 @@ migration_wal_scan(uint16 thread_id, uint32 tli, XLogRecPtr checkpoint_redo, priv.tli = tli; cluster_wal_thread_dir_name(thread_id, dirname, sizeof(dirname)); if (dirname[0] == '\0' - || snprintf(priv.thread_dir, sizeof(priv.thread_dir), "%s/%s", - cluster_wal_threads_dir, dirname) <= 0 - || (size_t)snprintf(priv.thread_dir, sizeof(priv.thread_dir), - "%s/%s", cluster_wal_threads_dir, dirname) - >= sizeof(priv.thread_dir)) + || snprintf(priv.thread_dir, sizeof(priv.thread_dir), "%s/%s", cluster_wal_threads_dir, + dirname) + <= 0 + || (size_t)snprintf(priv.thread_dir, sizeof(priv.thread_dir), "%s/%s", + cluster_wal_threads_dir, dirname) + >= sizeof(priv.thread_dir)) return false; } reader = XLogReaderAllocate(wal_segment_size, NULL, @@ -1718,7 +1666,7 @@ migration_wal_scan(uint16 thread_id, uint32 tli, XLogRecPtr checkpoint_redo, for (;;) { record = XLogReadRecord(reader, &errormsg); if (record == NULL) - break; /* clean end of stream */ + break; /* clean end of stream */ if (!saw_checkpoint) { /* The first record at the redo pointer is the checkpoint record. */ *out_ckpt_crc = record->xl_crc; @@ -1750,9 +1698,8 @@ migration_wal_scan(uint16 thread_id, uint32 tli, XLogRecPtr checkpoint_redo, * refuses the round before any file is touched. */ ClusterControlRootResult -cluster_control_root_build_migration_image( - const ClusterControlRootMigrationRoundV1 *round, - ClusterControlRootMigrationImage *out) +cluster_control_root_build_migration_image(const ClusterControlRootMigrationRoundV1 *round, + ClusterControlRootMigrationImage *out) { ClusterControlRootMigrationImage image; uint8 current_uuid[16]; @@ -1777,7 +1724,8 @@ cluster_control_root_build_migration_image( if (cluster_wal_threads_dir == NULL || cluster_wal_threads_dir[0] == '\0' || lstat(cluster_wal_threads_dir, &st) != 0 || !S_ISDIR(st.st_mode) || snprintf(path, sizeof(path), "%s/%s", cluster_wal_threads_dir, - CLUSTER_WAL_STATE_FILENAME) <= 0 + CLUSTER_WAL_STATE_FILENAME) + <= 0 || !regular_or_absent_nosymlink(path, false)) return CLUSTER_CONTROL_ROOT_IO_ERROR; first = palloc(CLUSTER_WAL_STATE_FILE_SIZE); @@ -1786,19 +1734,16 @@ cluster_control_root_build_migration_image( * rejects a torn read — the same guarantee the double-read in * read_source_wal_state provides, without re-reading per slot). */ fd = OpenTransientFile(path, O_RDONLY | PG_BINARY); - if (fd < 0 || fstat(fd, &st) != 0 - || st.st_size != CLUSTER_WAL_STATE_FILE_SIZE) { + if (fd < 0 || fstat(fd, &st) != 0 || st.st_size != CLUSTER_WAL_STATE_FILE_SIZE) { if (fd >= 0) CloseTransientFile(fd); pfree(second); pfree(first); return CLUSTER_CONTROL_ROOT_BAD_SIZE; } - if (pg_pread(fd, first, CLUSTER_WAL_STATE_FILE_SIZE, 0) - != CLUSTER_WAL_STATE_FILE_SIZE + if (pg_pread(fd, first, CLUSTER_WAL_STATE_FILE_SIZE, 0) != CLUSTER_WAL_STATE_FILE_SIZE || CloseTransientFile(fd) != 0 - || !cluster_wal_state_image_validate( - first, CLUSTER_WAL_STATE_FILE_SIZE, NULL, NULL)) { + || !cluster_wal_state_image_validate(first, CLUSTER_WAL_STATE_FILE_SIZE, NULL, NULL)) { pfree(second); pfree(first); return CLUSTER_CONTROL_ROOT_HASH_MISMATCH; @@ -1823,31 +1768,24 @@ cluster_control_root_build_migration_image( * first-open create_prepared (INVALID_ARGUMENT) at the very first * bit22 round — the fixture cast path never hit this because it * carries an externally-minted v4 UUID. */ - image.authority_uuid[6] = (uint8) ((image.authority_uuid[6] & UINT8_C(0x0f)) - | UINT8_C(0x40)); - image.authority_uuid[8] = (uint8) ((image.authority_uuid[8] & UINT8_C(0x3f)) - | UINT8_C(0x80)); + image.authority_uuid[6] = (uint8)((image.authority_uuid[6] & UINT8_C(0x0f)) | UINT8_C(0x40)); + image.authority_uuid[8] = (uint8)((image.authority_uuid[8] & UINT8_C(0x3f)) | UINT8_C(0x80)); image.created_at_usec = GetCurrentTimestamp(); for (i = 0; i < CLUSTER_WAL_STATE_SLOT_COUNT; i++) { ClusterWalStateSlot slot; ClusterWalSlotVerdict verdict; ClusterControlRootSnapshot *record; - memcpy(&slot, first + CLUSTER_WAL_STATE_SLOT_OFFSET(i + 1), - sizeof(slot)); - verdict = cluster_wal_state_slot_classify(&slot, (uint16)(i + 1), - -1, NULL); + memcpy(&slot, first + CLUSTER_WAL_STATE_SLOT_OFFSET(i + 1), sizeof(slot)); + verdict = cluster_wal_state_slot_classify(&slot, (uint16)(i + 1), -1, NULL); if (verdict == CLUSTER_WAL_SLOT_EMPTY) continue; - if (verdict != CLUSTER_WAL_SLOT_OK - || slot.checkpoint_redo_lsn == 0 + if (verdict != CLUSTER_WAL_SLOT_OK || slot.checkpoint_redo_lsn == 0 || slot.merge_recovered_lsn != 0 || (slot.state != CLUSTER_WAL_SLOT_STATE_STOPPED - && !(slot.state == CLUSTER_WAL_SLOT_STATE_ACTIVE - && round != NULL - && cluster_r4_bit22_source_close_current( - round->transition_epoch, - round->prepare_generation)))) { + && !(slot.state == CLUSTER_WAL_SLOT_STATE_ACTIVE && round != NULL + && cluster_r4_bit22_source_close_current(round->transition_epoch, + round->prepare_generation)))) { pfree(second); pfree(first); return CLUSTER_CONTROL_ROOT_INVALID_ARGUMENT; @@ -1861,17 +1799,15 @@ cluster_control_root_build_migration_image( record->identity.origin_owner_incarnation = cluster_membership_get_last_admitted_incarnation(slot.node_id); if (record->identity.origin_owner_incarnation == 0 - || !read_thread_claim_fields((uint16)(i + 1), slot.node_id, - &record->identity)) { + || !read_thread_claim_fields((uint16)(i + 1), slot.node_id, &record->identity)) { pfree(second); pfree(first); return CLUSTER_CONTROL_ROOT_IO_ERROR; } record->lifecycle = CLUSTER_CONTROL_ROOT_LIFECYCLE_CLOSED; - record->root_flags = CLUSTER_CONTROL_ROOT_FLAG_CLAIM_VALID - | CLUSTER_CONTROL_ROOT_FLAG_CHECKPOINT_VALID - | CLUSTER_CONTROL_ROOT_FLAG_TAIL_VALID - | CLUSTER_CONTROL_ROOT_FLAG_RECOVERED_VALID; + record->root_flags + = CLUSTER_CONTROL_ROOT_FLAG_CLAIM_VALID | CLUSTER_CONTROL_ROOT_FLAG_CHECKPOINT_VALID + | CLUSTER_CONTROL_ROOT_FLAG_TAIL_VALID | CLUSTER_CONTROL_ROOT_FLAG_RECOVERED_VALID; /* RF-ROOT P9 verification (contract): every snapshot_validate field * must be backed — lineage/publish/kind/tli/CRC. The record * CRCs (checkpoint + tail-last) come from the WAL stream via @@ -1881,20 +1817,15 @@ cluster_control_root_build_migration_image( record->root_publish_seq = 1; record->checkpoint_lower_lsn = slot.checkpoint_redo_lsn; record->checkpoint_tli = slot.tli; - record->checkpoint_source_kind - = CLUSTER_CONTROL_ROOT_CHECKPOINT_NATIVE_V1; + record->checkpoint_source_kind = CLUSTER_CONTROL_ROOT_CHECKPOINT_NATIVE_V1; record->validated_tail_lsn_exclusive = slot.highest_lsn; record->tail_tli = slot.tli; - record->tail_validation_kind - = CLUSTER_CONTROL_ROOT_TAIL_WAL_RECORD_SCAN_V1; + record->tail_validation_kind = CLUSTER_CONTROL_ROOT_TAIL_WAL_RECORD_SCAN_V1; record->recovered_through_lsn_exclusive = slot.checkpoint_redo_lsn; record->recovered_tli = slot.tli; - if (!migration_wal_scan( - (uint16)(i + 1), slot.tli, slot.checkpoint_redo_lsn, - slot.highest_lsn, - &record->checkpoint_record_crc32c, - &record->tail_last_record_lsn, - &record->tail_last_record_crc32c)) { + if (!migration_wal_scan((uint16)(i + 1), slot.tli, slot.checkpoint_redo_lsn, + slot.highest_lsn, &record->checkpoint_record_crc32c, + &record->tail_last_record_lsn, &record->tail_last_record_crc32c)) { pfree(second); pfree(first); return CLUSTER_CONTROL_ROOT_IO_ERROR; @@ -1907,13 +1838,10 @@ cluster_control_root_build_migration_image( * both zero). Without the flag the live first-open image failed * migration_image_validate (RANGE_INVALID) and create_prepared * refused the round. */ - if (record->tail_last_record_lsn != 0 - && record->tail_last_record_crc32c != 0) - record->root_flags - |= CLUSTER_CONTROL_ROOT_FLAG_TAIL_LAST_RECORD_VALID; + if (record->tail_last_record_lsn != 0 && record->tail_last_record_crc32c != 0) + record->root_flags |= CLUSTER_CONTROL_ROOT_FLAG_TAIL_LAST_RECORD_VALID; record->published_at_usec = image.created_at_usec; - record->lifecycle_reason - = CLUSTER_CONTROL_ROOT_PUBLISH_MIGRATION_IMPORT; + record->lifecycle_reason = CLUSTER_CONTROL_ROOT_PUBLISH_MIGRATION_IMPORT; assigned++; } image.assigned_record_count = assigned; @@ -1949,8 +1877,7 @@ cluster_control_root_create_prepared(const ClusterControlRootMigrationImage *ima result = storage_contract_check(image->storage_uuid, true); if (result != CLUSTER_CONTROL_ROOT_OK_PRIMARY) return result; - if (!current_storage_uuid(current_uuid) - || memcmp(current_uuid, image->storage_uuid, 16) != 0) + if (!current_storage_uuid(current_uuid) || memcmp(current_uuid, image->storage_uuid, 16) != 0) return CLUSTER_CONTROL_ROOT_IDENTITY_MISMATCH; if (!acquire_clusterwide_cf(ExclusiveLock)) return CLUSTER_CONTROL_ROOT_LOCK_UNAVAILABLE; @@ -1968,26 +1895,23 @@ cluster_control_root_create_prepared(const ClusterControlRootMigrationImage *ima root->header.migration_transition_epoch = round->transition_epoch; root->header.source_feature_bitmap = round->source_feature_bitmap; root->header.target_feature_bitmap = round->target_feature_bitmap; - if (!control_root_sha256(round_bytes, sizeof(round_bytes), - root->header.migration_round_sha256)) + if (!control_root_sha256(round_bytes, sizeof(round_bytes), root->header.migration_round_sha256)) result = CLUSTER_CONTROL_ROOT_IO_ERROR; else - result = read_source_wal_state(image->records, NULL, - root->header.source_wal_state_sha256, - round); + result = read_source_wal_state(image->records, NULL, root->header.source_wal_state_sha256, + round); if (result == CLUSTER_CONTROL_ROOT_OK_PRIMARY) { for (i = 0; i < CLUSTER_CONTROL_ROOT_RECORD_COUNT; i++) { if (image->records[i].identity.system_identifier == 0) continue; root->records[i] = image->records[i]; root->records[i].published_at_usec = GetCurrentTimestamp(); - root->records[i].lifecycle_reason = - CLUSTER_CONTROL_ROOT_PUBLISH_MIGRATION_IMPORT; + root->records[i].lifecycle_reason = CLUSTER_CONTROL_ROOT_PUBLISH_MIGRATION_IMPORT; encode_record(root->bytes + CLUSTER_CONTROL_ROOT_HEADER_BYTES - + (size_t)i * CLUSTER_CONTROL_ROOT_RECORD_BYTES, - &root->records[i], round->coordinator_incarnation, - round->coordinator_node_id, - CLUSTER_CONTROL_ROOT_PUBLISH_MIGRATION_IMPORT); + + (size_t)i * CLUSTER_CONTROL_ROOT_RECORD_BYTES, + &root->records[i], round->coordinator_incarnation, + round->coordinator_node_id, + CLUSTER_CONTROL_ROOT_PUBLISH_MIGRATION_IMPORT); root->present[i] = true; } encode_header(root); @@ -2043,8 +1967,8 @@ cluster_control_root_activate_prepared(const ClusterControlRootFileToken *expect /* The PREPARED token and round hash establish freshness only. Activation * also requires the cutover owner's separately bound authority (the round * carries the coordinator identity + ACK-binding fields for the proof). */ - if (!cluster_control_root_activate_authority_current_v1( - expected_token, expected_round_sha256, round)) + if (!cluster_control_root_activate_authority_current_v1(expected_token, expected_round_sha256, + round)) return CLUSTER_CONTROL_ROOT_INVALID_ARGUMENT; result = storage_contract_check(NULL, true); if (result != CLUSTER_CONTROL_ROOT_OK_PRIMARY) @@ -2061,12 +1985,12 @@ cluster_control_root_activate_prepared(const ClusterControlRootFileToken *expect if (!file_token_equal(expected_token, &actual)) result = CLUSTER_CONTROL_ROOT_STALE_TOKEN; else if (memcmp(primary->header.migration_round_sha256, expected_round_sha256, - PG_SHA256_DIGEST_LENGTH) != 0) + PG_SHA256_DIGEST_LENGTH) + != 0) result = CLUSTER_CONTROL_ROOT_MIGRATION_ROUND_MISMATCH; else - result = read_source_wal_state(primary->records, - primary->header.source_wal_state_sha256, - source_hash, round); + result = read_source_wal_state( + primary->records, primary->header.source_wal_state_sha256, source_hash, round); } if (result == CLUSTER_CONTROL_ROOT_OK_PRIMARY || result == CLUSTER_CONTROL_ROOT_OK_PRIMARY_DEGRADED) { @@ -2086,14 +2010,13 @@ cluster_control_root_activate_prepared(const ClusterControlRootFileToken *expect char path[MAXPGPATH]; if (!current_storage_uuid(current_uuid) - || !build_control_path(path, sizeof(path), - CLUSTER_CONTROL_ROOT_REL_PATH)) + || !build_control_path(path, sizeof(path), CLUSTER_CONTROL_ROOT_REL_PATH)) result = CLUSTER_CONTROL_ROOT_POSTREAD_FAILED; else result = read_one_image(path, current_uuid, GetSystemIdentifier(), readback); if (result == CLUSTER_CONTROL_ROOT_OK_PRIMARY - && memcmp(readback->bytes, updated->bytes, - CLUSTER_CONTROL_ROOT_FILE_BYTES) != 0) + && memcmp(readback->bytes, updated->bytes, CLUSTER_CONTROL_ROOT_FILE_BYTES) + != 0) result = CLUSTER_CONTROL_ROOT_POSTREAD_FAILED; if (result == CLUSTER_CONTROL_ROOT_OK_PRIMARY) make_file_token(readback, &token); @@ -2141,15 +2064,13 @@ reason_mask(ClusterControlRootPublishReason reason) } static bool -patch_shape_valid(const ClusterControlRootPatch *patch, - ClusterControlRootPublishReason reason) +patch_shape_valid(const ClusterControlRootPatch *patch, ClusterControlRootPublishReason reason) { ClusterControlRootSnapshot allowed; uint64 mask = reason_mask(reason); if (patch == NULL || mask == 0 || patch->mask != mask || patch->reserved20 != 0 - || patch->reserved24 != 0 - || patch->expected_lifecycle < CLUSTER_CONTROL_ROOT_LIFECYCLE_OPEN + || patch->reserved24 != 0 || patch->expected_lifecycle < CLUSTER_CONTROL_ROOT_LIFECYCLE_OPEN || patch->expected_lifecycle > CLUSTER_CONTROL_ROOT_LIFECYCLE_RETIRED || (patch->expected_flags_mask & ~CLUSTER_CONTROL_ROOT_FLAGS_V1) != 0 || (patch->expected_flags_value & ~patch->expected_flags_mask) != 0 @@ -2157,8 +2078,7 @@ patch_shape_valid(const ClusterControlRootPatch *patch, || (patch->desired.root_flags & ~CLUSTER_CONTROL_ROOT_FLAGS_V1) != 0) return false; if (reason == CLUSTER_CONTROL_ROOT_PUBLISH_OWNER_REJOIN - && (patch->expected_lifecycle - != CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_COMPLETE + && (patch->expected_lifecycle != CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_COMPLETE || patch->desired.lifecycle != CLUSTER_CONTROL_ROOT_LIFECYCLE_OPEN || patch->desired.identity.origin_owner_incarnation == 0 || patch->desired.identity.root_lineage_seq == 0)) @@ -2174,13 +2094,11 @@ patch_shape_valid(const ClusterControlRootPatch *patch, * failure-recovery FSM instead. */ if (reason == CLUSTER_CONTROL_ROOT_PUBLISH_THREAD_CLEAN_CLOSE - && (patch->expected_lifecycle - != CLUSTER_CONTROL_ROOT_LIFECYCLE_OPEN + && (patch->expected_lifecycle != CLUSTER_CONTROL_ROOT_LIFECYCLE_OPEN || patch->desired.lifecycle != CLUSTER_CONTROL_ROOT_LIFECYCLE_CLOSED)) return false; if (reason == CLUSTER_CONTROL_ROOT_PUBLISH_THREAD_OPEN - && (patch->expected_lifecycle - != CLUSTER_CONTROL_ROOT_LIFECYCLE_CLOSED + && (patch->expected_lifecycle != CLUSTER_CONTROL_ROOT_LIFECYCLE_CLOSED || patch->desired.lifecycle != CLUSTER_CONTROL_ROOT_LIFECYCLE_OPEN || patch->desired.identity.origin_owner_incarnation == 0 || patch->desired.identity.root_lineage_seq == 0)) @@ -2189,8 +2107,8 @@ patch_shape_valid(const ClusterControlRootPatch *patch, if ((mask & CLUSTER_CONTROL_ROOT_PATCH_LIFECYCLE) != 0) allowed.lifecycle = patch->desired.lifecycle; if ((mask & CLUSTER_CONTROL_ROOT_PATCH_OWNER_LINEAGE) != 0) { - allowed.identity.origin_owner_incarnation = - patch->desired.identity.origin_owner_incarnation; + allowed.identity.origin_owner_incarnation + = patch->desired.identity.origin_owner_incarnation; allowed.identity.root_lineage_seq = patch->desired.identity.root_lineage_seq; } if ((mask & CLUSTER_CONTROL_ROOT_PATCH_CHECKPOINT) != 0) { @@ -2208,20 +2126,19 @@ patch_shape_valid(const ClusterControlRootPatch *patch, } if ((mask & CLUSTER_CONTROL_ROOT_PATCH_RECOVERY_PROGRESS) != 0) { allowed.recovered_tli = patch->desired.recovered_tli; - allowed.recovered_through_lsn_exclusive = - patch->desired.recovered_through_lsn_exclusive; + allowed.recovered_through_lsn_exclusive = patch->desired.recovered_through_lsn_exclusive; allowed.recovered_last_record_lsn = patch->desired.recovered_last_record_lsn; - allowed.recovered_last_record_crc32c = - patch->desired.recovered_last_record_crc32c; + allowed.recovered_last_record_crc32c = patch->desired.recovered_last_record_crc32c; } if ((mask & CLUSTER_CONTROL_ROOT_PATCH_CONSERVATIVE_BOUND) != 0) { allowed.conservative_bound_kind = patch->desired.conservative_bound_kind; allowed.conservative_commit_scn = patch->desired.conservative_commit_scn; } - if ((mask & (CLUSTER_CONTROL_ROOT_PATCH_CHECKPOINT | CLUSTER_CONTROL_ROOT_PATCH_TAIL - | CLUSTER_CONTROL_ROOT_PATCH_RECOVERY_PROGRESS - | CLUSTER_CONTROL_ROOT_PATCH_FPW_STICKY - | CLUSTER_CONTROL_ROOT_PATCH_CONSERVATIVE_BOUND)) != 0) + if ((mask + & (CLUSTER_CONTROL_ROOT_PATCH_CHECKPOINT | CLUSTER_CONTROL_ROOT_PATCH_TAIL + | CLUSTER_CONTROL_ROOT_PATCH_RECOVERY_PROGRESS | CLUSTER_CONTROL_ROOT_PATCH_FPW_STICKY + | CLUSTER_CONTROL_ROOT_PATCH_CONSERVATIVE_BOUND)) + != 0) allowed.root_flags = patch->desired.root_flags; return memcmp(&allowed, &patch->desired, sizeof(allowed)) == 0; } @@ -2241,8 +2158,8 @@ apply_patch(ClusterControlRootSnapshot *snapshot, const ClusterControlRootPatch if ((mask & CLUSTER_CONTROL_ROOT_PATCH_LIFECYCLE) != 0) snapshot->lifecycle = patch->desired.lifecycle; if ((mask & CLUSTER_CONTROL_ROOT_PATCH_OWNER_LINEAGE) != 0) { - snapshot->identity.origin_owner_incarnation = - patch->desired.identity.origin_owner_incarnation; + snapshot->identity.origin_owner_incarnation + = patch->desired.identity.origin_owner_incarnation; snapshot->identity.root_lineage_seq = patch->desired.identity.root_lineage_seq; } if ((mask & CLUSTER_CONTROL_ROOT_PATCH_CHECKPOINT) != 0) { @@ -2251,7 +2168,7 @@ apply_patch(ClusterControlRootSnapshot *snapshot, const ClusterControlRootPatch snapshot->checkpoint_lower_lsn = patch->desired.checkpoint_lower_lsn; snapshot->checkpoint_record_crc32c = patch->desired.checkpoint_record_crc32c; merge_flag_group(&snapshot->root_flags, patch->desired.root_flags, - CLUSTER_CONTROL_ROOT_FLAG_CHECKPOINT_VALID); + CLUSTER_CONTROL_ROOT_FLAG_CHECKPOINT_VALID); } if ((mask & CLUSTER_CONTROL_ROOT_PATCH_TAIL) != 0) { snapshot->tail_tli = patch->desired.tail_tli; @@ -2260,63 +2177,60 @@ apply_patch(ClusterControlRootSnapshot *snapshot, const ClusterControlRootPatch snapshot->tail_last_record_lsn = patch->desired.tail_last_record_lsn; snapshot->tail_last_record_crc32c = patch->desired.tail_last_record_crc32c; merge_flag_group(&snapshot->root_flags, patch->desired.root_flags, - CLUSTER_CONTROL_ROOT_FLAG_TAIL_VALID - | CLUSTER_CONTROL_ROOT_FLAG_TAIL_LAST_RECORD_VALID); + CLUSTER_CONTROL_ROOT_FLAG_TAIL_VALID + | CLUSTER_CONTROL_ROOT_FLAG_TAIL_LAST_RECORD_VALID); } if ((mask & CLUSTER_CONTROL_ROOT_PATCH_RECOVERY_PROGRESS) != 0) { snapshot->recovered_tli = patch->desired.recovered_tli; - snapshot->recovered_through_lsn_exclusive = - patch->desired.recovered_through_lsn_exclusive; + snapshot->recovered_through_lsn_exclusive = patch->desired.recovered_through_lsn_exclusive; snapshot->recovered_last_record_lsn = patch->desired.recovered_last_record_lsn; - snapshot->recovered_last_record_crc32c = - patch->desired.recovered_last_record_crc32c; + snapshot->recovered_last_record_crc32c = patch->desired.recovered_last_record_crc32c; merge_flag_group(&snapshot->root_flags, patch->desired.root_flags, - CLUSTER_CONTROL_ROOT_FLAG_RECOVERED_VALID - | CLUSTER_CONTROL_ROOT_FLAG_RECOVERED_LAST_RECORD_VALID); + CLUSTER_CONTROL_ROOT_FLAG_RECOVERED_VALID + | CLUSTER_CONTROL_ROOT_FLAG_RECOVERED_LAST_RECORD_VALID); } if ((mask & CLUSTER_CONTROL_ROOT_PATCH_FPW_STICKY) != 0) { if ((old_flags & CLUSTER_CONTROL_ROOT_FLAG_FPW_WAS_OFF) != 0 && (patch->desired.root_flags & CLUSTER_CONTROL_ROOT_FLAG_FPW_WAS_OFF) == 0) return false; merge_flag_group(&snapshot->root_flags, patch->desired.root_flags, - CLUSTER_CONTROL_ROOT_FLAG_FPW_WAS_OFF); + CLUSTER_CONTROL_ROOT_FLAG_FPW_WAS_OFF); } if ((mask & CLUSTER_CONTROL_ROOT_PATCH_CONSERVATIVE_BOUND) != 0) { snapshot->conservative_bound_kind = patch->desired.conservative_bound_kind; snapshot->conservative_commit_scn = patch->desired.conservative_commit_scn; merge_flag_group(&snapshot->root_flags, patch->desired.root_flags, - CLUSTER_CONTROL_ROOT_FLAG_CONSERVATIVE_SCN_VALID); + CLUSTER_CONTROL_ROOT_FLAG_CONSERVATIVE_SCN_VALID); } return true; } static bool -root_publish_requires_walr(ClusterControlRootPublishReason reason, - bool *require_sealed_pin) +root_publish_requires_walr(ClusterControlRootPublishReason reason, bool *require_sealed_pin) { *require_sealed_pin = false; switch (reason) { - case CLUSTER_CONTROL_ROOT_PUBLISH_THREAD_OPEN: - case CLUSTER_CONTROL_ROOT_PUBLISH_THREAD_CLEAN_CLOSE: - case CLUSTER_CONTROL_ROOT_PUBLISH_FAILURE_DUTY_OPEN: - case CLUSTER_CONTROL_ROOT_PUBLISH_FAILURE_TAIL_VALIDATED: - case CLUSTER_CONTROL_ROOT_PUBLISH_OWNER_REJOIN: - case CLUSTER_CONTROL_ROOT_PUBLISH_CHECKPOINT_ADVANCE: - return true; - case CLUSTER_CONTROL_ROOT_PUBLISH_RECOVERY_COMPLETE: - *require_sealed_pin = true; - return true; - default: - return false; + case CLUSTER_CONTROL_ROOT_PUBLISH_THREAD_OPEN: + case CLUSTER_CONTROL_ROOT_PUBLISH_THREAD_CLEAN_CLOSE: + case CLUSTER_CONTROL_ROOT_PUBLISH_FAILURE_DUTY_OPEN: + case CLUSTER_CONTROL_ROOT_PUBLISH_FAILURE_TAIL_VALIDATED: + case CLUSTER_CONTROL_ROOT_PUBLISH_OWNER_REJOIN: + case CLUSTER_CONTROL_ROOT_PUBLISH_CHECKPOINT_ADVANCE: + return true; + case CLUSTER_CONTROL_ROOT_PUBLISH_RECOVERY_COMPLETE: + *require_sealed_pin = true; + return true; + default: + return false; } } ClusterControlRootResult cluster_control_root_compare_and_publish(const ClusterControlRootReadToken *expected_token, - const ClusterControlRootPatch *patch, - ClusterControlRootPublishReason reason, - ClusterControlRootSnapshot *out_snapshot, - ClusterControlRootReadToken *out_token) + const ClusterControlRootPatch *patch, + ClusterControlRootPublishReason reason, + ClusterControlRootSnapshot *out_snapshot, + ClusterControlRootReadToken *out_token) { ControlRootImage *primary; ControlRootImage *bak; @@ -2344,8 +2258,7 @@ cluster_control_root_compare_and_publish(const ClusterControlRootReadToken *expe /* RF-ROOT P5: the byte-exact CAS token proves root freshness, not caller * authority. Consume the backend-private authority bound by the owning * publisher before CF acquisition or any file I/O. */ - if (!cluster_control_root_publish_authority_current_v1( - expected_token, patch, reason)) + if (!cluster_control_root_publish_authority_current_v1(expected_token, patch, reason)) return CLUSTER_CONTROL_ROOT_INVALID_ARGUMENT; thread_id = expected_token->origin_thread_id; if (root_publish_requires_walr(reason, &require_sealed_pin)) { @@ -2361,8 +2274,7 @@ cluster_control_root_compare_and_publish(const ClusterControlRootReadToken *expe result = storage_contract_check(NULL, true); if (result != CLUSTER_CONTROL_ROOT_OK_PRIMARY) goto release_walr; - if (!acquire_clusterwide_cf(ExclusiveLock)) - { + if (!acquire_clusterwide_cf(ExclusiveLock)) { result = CLUSTER_CONTROL_ROOT_LOCK_UNAVAILABLE; goto release_walr; } @@ -2380,26 +2292,23 @@ cluster_control_root_compare_and_publish(const ClusterControlRootReadToken *expe if (!read_token_equal(expected_token, &actual)) result = CLUSTER_CONTROL_ROOT_STALE_TOKEN; else if (primary->records[thread_id - 1].lifecycle != patch->expected_lifecycle - || (primary->records[thread_id - 1].root_flags - & patch->expected_flags_mask) != patch->expected_flags_value) + || (primary->records[thread_id - 1].root_flags & patch->expected_flags_mask) + != patch->expected_flags_value) result = CLUSTER_CONTROL_ROOT_CAS_CONFLICT; else if ((reason == CLUSTER_CONTROL_ROOT_PUBLISH_OWNER_REJOIN || reason == CLUSTER_CONTROL_ROOT_PUBLISH_THREAD_OPEN) - && (primary->records[thread_id - 1].identity.root_lineage_seq - == UINT64_MAX + && (primary->records[thread_id - 1].identity.root_lineage_seq == UINT64_MAX || patch->desired.identity.root_lineage_seq != primary->records[thread_id - 1].identity.root_lineage_seq + 1 || patch->desired.identity.origin_owner_incarnation - <= primary->records[thread_id - 1] - .identity.origin_owner_incarnation)) + <= primary->records[thread_id - 1].identity.origin_owner_incarnation)) result = CLUSTER_CONTROL_ROOT_CAS_CONFLICT; } if (result == CLUSTER_CONTROL_ROOT_OK_PRIMARY || result == CLUSTER_CONTROL_ROOT_OK_PRIMARY_DEGRADED) { memcpy(updated, primary, sizeof(*updated)); snapshot = updated->records[thread_id - 1]; - if (updated->header.file_txn_seq == UINT64_MAX - || snapshot.root_publish_seq == UINT64_MAX) + if (updated->header.file_txn_seq == UINT64_MAX || snapshot.root_publish_seq == UINT64_MAX) result = CLUSTER_CONTROL_ROOT_SEQUENCE_EXHAUSTED; else if (!apply_patch(&snapshot, patch)) result = CLUSTER_CONTROL_ROOT_INVALID_ARGUMENT; @@ -2407,17 +2316,16 @@ cluster_control_root_compare_and_publish(const ClusterControlRootReadToken *expe snapshot.root_publish_seq++; snapshot.published_at_usec = GetCurrentTimestamp(); snapshot.lifecycle_reason = reason; - result = snapshot_validate(&snapshot, thread_id, - updated->header.system_identifier, - updated->header.storage_uuid, - updated->header.authority_uuid); + result + = snapshot_validate(&snapshot, thread_id, updated->header.system_identifier, + updated->header.storage_uuid, updated->header.authority_uuid); } if (result == CLUSTER_CONTROL_ROOT_OK_PRIMARY) { updated->records[thread_id - 1] = snapshot; encode_record(updated->bytes + CLUSTER_CONTROL_ROOT_HEADER_BYTES - + (size_t)(thread_id - 1) * CLUSTER_CONTROL_ROOT_RECORD_BYTES, - &snapshot, snapshot.identity.origin_owner_incarnation, - (uint32)cluster_node_id, reason); + + (size_t)(thread_id - 1) * CLUSTER_CONTROL_ROOT_RECORD_BYTES, + &snapshot, snapshot.identity.origin_owner_incarnation, + (uint32)cluster_node_id, reason); updated->header.file_txn_seq++; updated->header.published_at_usec = snapshot.published_at_usec; encode_header(updated); @@ -2429,19 +2337,17 @@ cluster_control_root_compare_and_publish(const ClusterControlRootReadToken *expe char path[MAXPGPATH]; if (!current_storage_uuid(current_uuid) - || !build_control_path(path, sizeof(path), - CLUSTER_CONTROL_ROOT_REL_PATH)) + || !build_control_path(path, sizeof(path), CLUSTER_CONTROL_ROOT_REL_PATH)) result = CLUSTER_CONTROL_ROOT_POSTREAD_FAILED; else result = read_one_image(path, current_uuid, GetSystemIdentifier(), readback); if (result == CLUSTER_CONTROL_ROOT_OK_PRIMARY - && memcmp(readback->bytes, updated->bytes, - CLUSTER_CONTROL_ROOT_FILE_BYTES) != 0) + && memcmp(readback->bytes, updated->bytes, CLUSTER_CONTROL_ROOT_FILE_BYTES) + != 0) result = CLUSTER_CONTROL_ROOT_POSTREAD_FAILED; if (result == CLUSTER_CONTROL_ROOT_OK_PRIMARY) { snapshot = readback->records[thread_id - 1]; - make_read_token(readback, thread_id, CONTROL_ROOT_SOURCE_PRIMARY, - &token); + make_read_token(readback, thread_id, CONTROL_ROOT_SOURCE_PRIMARY, &token); } pfree(readback); } @@ -2454,8 +2360,7 @@ cluster_control_root_compare_and_publish(const ClusterControlRootReadToken *expe release_walr: if (walr_guard != NULL) { - walr_release_result = - cluster_wal_retention_root_publish_end(&walr_guard); + walr_release_result = cluster_wal_retention_root_publish_end(&walr_guard); if (walr_release_result != CLUSTER_WALR_RELEASE_CONFIRMED) result = CLUSTER_CONTROL_ROOT_RELEASE_UNCERTAIN; } @@ -2481,9 +2386,9 @@ cluster_control_root_revalidate(const ClusterControlRootReadToken *token, memset(out_snapshot, 0, sizeof(*out_snapshot)); if (token == NULL || expected_identity == NULL) return CLUSTER_CONTROL_ROOT_INVALID_ARGUMENT; - result = cluster_control_root_read_canonical(token->origin_thread_id, expected_identity, - CLUSTER_CONTROL_ROOT_READ_STRONG, &snapshot, - &fresh); + result + = cluster_control_root_read_canonical(token->origin_thread_id, expected_identity, + CLUSTER_CONTROL_ROOT_READ_STRONG, &snapshot, &fresh); if (result != CLUSTER_CONTROL_ROOT_OK_PRIMARY && result != CLUSTER_CONTROL_ROOT_OK_PRIMARY_DEGRADED) return result; @@ -2500,14 +2405,12 @@ cluster_control_root_revalidate(const ClusterControlRootReadToken *token, * migration_round_sha256). The cutover driver needs it to stage the seam. */ bool -cluster_control_root_round_sha256( - const ClusterControlRootMigrationRoundV1 *round, - uint8 out_sha[PG_SHA256_DIGEST_LENGTH]) +cluster_control_root_round_sha256(const ClusterControlRootMigrationRoundV1 *round, + uint8 out_sha[PG_SHA256_DIGEST_LENGTH]) { uint8 round_bytes[80]; - if (round == NULL || out_sha == NULL - || !encode_round(round, round_bytes)) + if (round == NULL || out_sha == NULL || !encode_round(round, round_bytes)) return false; return control_root_sha256(round_bytes, sizeof(round_bytes), out_sha); } diff --git a/src/backend/cluster/cluster_control_root_private.h b/src/backend/cluster/cluster_control_root_private.h index 909b58e7b69..d05105c0831 100644 --- a/src/backend/cluster/cluster_control_root_private.h +++ b/src/backend/cluster/cluster_control_root_private.h @@ -10,21 +10,18 @@ #include "cluster/cluster_control_root.h" -extern bool cluster_control_root_create_authority_current_v1( - const ClusterControlRootMigrationImage *image, - const ClusterControlRootMigrationRoundV1 *round); +extern bool +cluster_control_root_create_authority_current_v1(const ClusterControlRootMigrationImage *image, + const ClusterControlRootMigrationRoundV1 *round); extern bool cluster_control_root_activate_authority_current_v1( - const ClusterControlRootFileToken *expected_token, - const uint8 expected_round_sha256[32], + const ClusterControlRootFileToken *expected_token, const uint8 expected_round_sha256[32], const ClusterControlRootMigrationRoundV1 *round); -extern bool cluster_control_root_publish_authority_current_v1( - const ClusterControlRootReadToken *expected_token, - const ClusterControlRootPatch *patch, - ClusterControlRootPublishReason reason); +extern bool +cluster_control_root_publish_authority_current_v1(const ClusterControlRootReadToken *expected_token, + const ClusterControlRootPatch *patch, + ClusterControlRootPublishReason reason); extern ClusterControlRootResult cluster_control_root_recovery_complete_publish_v1( - const ClusterControlRootReadToken *expected_token, - const ClusterControlRootPatch *patch, - ClusterControlRootSnapshot *out_snapshot, - ClusterControlRootReadToken *out_token); + const ClusterControlRootReadToken *expected_token, const ClusterControlRootPatch *patch, + ClusterControlRootSnapshot *out_snapshot, ClusterControlRootReadToken *out_token); #endif /* CLUSTER_CONTROL_ROOT_PRIVATE_H */ diff --git a/src/backend/cluster/cluster_cr_server.c b/src/backend/cluster/cluster_cr_server.c index 3081e9fe70e..bd3a305d6c6 100644 --- a/src/backend/cluster/cluster_cr_server.c +++ b/src/backend/cluster/cluster_cr_server.c @@ -51,7 +51,7 @@ #ifdef USE_PGRAC_CLUSTER -#include "access/clog.h" /* C0 literal raw CLOG status */ +#include "access/clog.h" /* C0 literal raw CLOG status */ #include "access/multixact.h" /* GetMultiXactIdMembers / MultiXactMember (spec-7.1 D3-b) */ #include "access/transam.h" /* TransactionIdDidCommit/DidAbort (D-i4 CLOG cross) */ #include "access/xlog.h" /* GetFlushRecPtr (spec-6.12i live_hwm_lsn) */ @@ -68,18 +68,18 @@ #include "cluster/cluster_ic_router.h" /* cluster_ic_send_envelope */ #include "cluster/cluster_ic_tier1.h" /* PGRAC: spec-7.3 P2-1 — my DATA channel */ #include "cluster/cluster_inject.h" -#include "cluster/cluster_lmon.h" /* PGRAC: spec-7.2 D1 READY-publish wakeup */ -#include "cluster/cluster_lms.h" /* PGRAC: spec-7.3 D8 per-worker serve counters */ -#include "cluster/cluster_lms_shard.h" /* PGRAC: spec-7.3 P2-1 — tag->worker shard */ +#include "cluster/cluster_lmon.h" /* PGRAC: spec-7.2 D1 READY-publish wakeup */ +#include "cluster/cluster_lms.h" /* PGRAC: spec-7.3 D8 per-worker serve counters */ +#include "cluster/cluster_lms_shard.h" /* PGRAC: spec-7.3 P2-1 — tag->worker shard */ #include "cluster/cluster_multixact_current_wire.h" #include "cluster/cluster_mxid_stripe.h" /* cluster_mxid_is_mine (spec-7.1 D3-b) */ #include "cluster/cluster_scn.h" /* cluster_scn_current (spec-7.1a authority_scn co-sample) */ #include "cluster/cluster_semantic_activation.h" #include "cluster/cluster_shmem.h" -#include "cluster/cluster_conf.h" /* CLUSTER_MAX_NODES (D4-6 owner range) */ -#include "cluster/cluster_tt_durable.h" /* resolve_by_xid (D-i4 complete scan) */ +#include "cluster/cluster_conf.h" /* CLUSTER_MAX_NODES (D4-6 owner range) */ +#include "cluster/cluster_tt_durable.h" /* resolve_by_xid (D-i4 complete scan) */ #include "cluster/cluster_tt_status.h" -#include "cluster/cluster_tt_slot.h" /* max_recycle_horizon (D-i4 bound) */ +#include "cluster/cluster_tt_slot.h" /* max_recycle_horizon (D-i4 bound) */ #include "cluster/cluster_uba.h" #include "cluster/cluster_undo_authority.h" /* authority lookup + block0 prove (D4-6) */ #include "cluster/cluster_undo_record_api.h" /* tt_retention_rollover_count */ @@ -149,28 +149,25 @@ cr_server_r4_protocol_detail(const ClusterLmsCrSlot *slot, const char *site, int emitted == 64); } -#define CR_SERVER_R4_REQUIRED_HELLO_CAPS \ - (PGRAC_IC_HELLO_CAP_SEMANTIC_ACTIVATION_V1 | PGRAC_IC_HELLO_CAP_R4_SYNC_CR_V1 \ - | PGRAC_IC_HELLO_CAP_CANDIDATE2_CORRECTED_A1_V1 \ - | PGRAC_IC_HELLO_CAP_UNDO_ROOT_DESCRIPTOR_V1) +#define CR_SERVER_R4_REQUIRED_HELLO_CAPS \ + (PGRAC_IC_HELLO_CAP_SEMANTIC_ACTIVATION_V1 | PGRAC_IC_HELLO_CAP_R4_SYNC_CR_V1 \ + | PGRAC_IC_HELLO_CAP_CANDIDATE2_CORRECTED_A1_V1 | PGRAC_IC_HELLO_CAP_UNDO_ROOT_DESCRIPTOR_V1) /* A local R4 identity has no self HELLO record. The compiled protocol * family is fixed by this binary; its frozen uint32 carrier must be the exact * checked view of the same entered local TARGET OPEN generation. */ static bool -cr_server_r4_local_open_generation_matches( - const ClusterSemanticAdmissionToken *admission, uint32 stored_generation) +cr_server_r4_local_open_generation_matches(const ClusterSemanticAdmissionToken *admission, + uint32 stored_generation) { - const uint32 compiled_capabilities - = PGRAC_IC_HELLO_CAP_SEMANTIC_ACTIVATION_V1 - | PGRAC_IC_HELLO_CAP_R4_SYNC_CR_V1 - | PGRAC_IC_HELLO_CAP_CANDIDATE2_CORRECTED_A1_V1 - | PGRAC_IC_HELLO_CAP_UNDO_ROOT_DESCRIPTOR_V1; + const uint32 compiled_capabilities = PGRAC_IC_HELLO_CAP_SEMANTIC_ACTIVATION_V1 + | PGRAC_IC_HELLO_CAP_R4_SYNC_CR_V1 + | PGRAC_IC_HELLO_CAP_CANDIDATE2_CORRECTED_A1_V1 + | PGRAC_IC_HELLO_CAP_UNDO_ROOT_DESCRIPTOR_V1; return admission != NULL && admission->entered && admission->feature_bit == CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1 - && admission->side == CLUSTER_SEMANTIC_TARGET_SIDE - && admission->record_generation > 0 + && admission->side == CLUSTER_SEMANTIC_TARGET_SIDE && admission->record_generation > 0 && admission->record_generation <= (uint64)PG_UINT32_MAX && (compiled_capabilities & CR_SERVER_R4_REQUIRED_HELLO_CAPS) == CR_SERVER_R4_REQUIRED_HELLO_CAPS @@ -178,65 +175,62 @@ cr_server_r4_local_open_generation_matches( } static bool -cr_server_r4_identity_open_matches( - const ClusterSemanticAdmissionToken *admission, int32 identity_node, - uint32 stored_generation) +cr_server_r4_identity_open_matches(const ClusterSemanticAdmissionToken *admission, + int32 identity_node, uint32 stored_generation) { if (identity_node == cluster_node_id) - return cr_server_r4_local_open_generation_matches( - admission, stored_generation); + return cr_server_r4_local_open_generation_matches(admission, stored_generation); return cluster_semantic_activation_peer_open_matches( - admission, identity_node, CR_SERVER_R4_REQUIRED_HELLO_CAPS, - stored_generation); + admission, identity_node, CR_SERVER_R4_REQUIRED_HELLO_CAPS, stored_generation); } const char * cluster_cr_build_reason_name(ClusterCrBuildReason reason) { switch (reason) { - case CLUSTER_CR_BUILD_NONE: - return "none"; - case CLUSTER_CR_BUILD_TARGET_DISABLED: - return "target_disabled"; - case CLUSTER_CR_BUILD_RF_DEFERRED: - return "rf_deferred"; - case CLUSTER_CR_BUILD_WRONG_MASTER: - return "wrong_master"; - case CLUSTER_CR_BUILD_NO_HOLDER: - return "no_holder"; - case CLUSTER_CR_BUILD_HOLDER_AMBIGUOUS: - return "holder_ambiguous"; - case CLUSTER_CR_BUILD_HOLDER_MOVED: - return "holder_moved"; - case CLUSTER_CR_BUILD_RECOVERING: - return "recovering"; - case CLUSTER_CR_BUILD_GENERATION_MISMATCH: - return "generation_mismatch"; - case CLUSTER_CR_BUILD_CAPACITY: - return "capacity"; - case CLUSTER_CR_BUILD_BAD_LOCATOR: - return "bad_locator"; - case CLUSTER_CR_BUILD_BAD_UNDO: - return "bad_undo"; - case CLUSTER_CR_BUILD_CHAIN_LIMIT: - return "chain_limit"; - case CLUSTER_CR_BUILD_SNAPSHOT_TOO_OLD: - return "snapshot_too_old"; - case CLUSTER_CR_BUILD_EPOCH_MISMATCH: - return "epoch_mismatch"; - case CLUSTER_CR_BUILD_CANCELLED: - return "cancelled"; - case CLUSTER_CR_BUILD_IO_ERROR: - return "io_error"; - case CLUSTER_CR_BUILD_PROTOCOL: - return "protocol"; + case CLUSTER_CR_BUILD_NONE: + return "none"; + case CLUSTER_CR_BUILD_TARGET_DISABLED: + return "target_disabled"; + case CLUSTER_CR_BUILD_RF_DEFERRED: + return "rf_deferred"; + case CLUSTER_CR_BUILD_WRONG_MASTER: + return "wrong_master"; + case CLUSTER_CR_BUILD_NO_HOLDER: + return "no_holder"; + case CLUSTER_CR_BUILD_HOLDER_AMBIGUOUS: + return "holder_ambiguous"; + case CLUSTER_CR_BUILD_HOLDER_MOVED: + return "holder_moved"; + case CLUSTER_CR_BUILD_RECOVERING: + return "recovering"; + case CLUSTER_CR_BUILD_GENERATION_MISMATCH: + return "generation_mismatch"; + case CLUSTER_CR_BUILD_CAPACITY: + return "capacity"; + case CLUSTER_CR_BUILD_BAD_LOCATOR: + return "bad_locator"; + case CLUSTER_CR_BUILD_BAD_UNDO: + return "bad_undo"; + case CLUSTER_CR_BUILD_CHAIN_LIMIT: + return "chain_limit"; + case CLUSTER_CR_BUILD_SNAPSHOT_TOO_OLD: + return "snapshot_too_old"; + case CLUSTER_CR_BUILD_EPOCH_MISMATCH: + return "epoch_mismatch"; + case CLUSTER_CR_BUILD_CANCELLED: + return "cancelled"; + case CLUSTER_CR_BUILD_IO_ERROR: + return "io_error"; + case CLUSTER_CR_BUILD_PROTOCOL: + return "protocol"; } return "unknown"; } ClusterCrBuildResult cluster_cr_build_on_holder(const BufferTag *tag, SCN read_scn, char dst[BLCKSZ], - ClusterCrBuildReason *reason_out) + ClusterCrBuildReason *reason_out) { ClusterSemanticAdmissionToken admission; ClusterSemanticAdmissionResult admission_result; @@ -258,8 +252,8 @@ cluster_cr_build_on_holder(const BufferTag *tag, SCN read_scn, char dst[BLCKSZ], if (dst == NULL || reason_out == NULL) return CLUSTER_CR_BUILD_FAIL_CLOSED; - admission_result = cluster_semantic_activation_enter( - CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, CLUSTER_SEMANTIC_TARGET_SIDE, &admission); + admission_result = cluster_semantic_activation_enter(CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, + CLUSTER_SEMANTIC_TARGET_SIDE, &admission); if (admission_result != CLUSTER_SEMANTIC_ADMISSION_OK) { *reason_out = admission_result == CLUSTER_SEMANTIC_ADMISSION_TARGET_DISABLED ? CLUSTER_CR_BUILD_TARGET_DISABLED @@ -275,7 +269,7 @@ cluster_cr_build_on_holder(const BufferTag *tag, SCN read_scn, char dst[BLCKSZ], } if (!cluster_bufmgr_copy_block_for_r4_cr(*tag, InvalidScn, &page_lsn, &page_scn, - current_copy.data, &refusal)) { + current_copy.data, &refusal)) { if (refusal == CLUSTER_BUFMGR_GCS_COPY_REFUSAL_INVALID_ARGUMENT) { reason = CLUSTER_CR_BUILD_PROTOCOL; goto admitted_done; @@ -323,19 +317,17 @@ cluster_cr_build_on_holder(const BufferTag *tag, SCN read_scn, char dst[BLCKSZ], reason = CLUSTER_CR_BUILD_NONE; result = CLUSTER_CR_BUILD_FULL; -admitted_done: + admitted_done: switch (result) { case CLUSTER_CR_BUILD_FULL: - cluster_r4_observe(CLUSTER_R4_EVENT_CR_HOLDER_FULL, - CLUSTER_TX_RESOLVE_NONE, reason); + cluster_r4_observe(CLUSTER_R4_EVENT_CR_HOLDER_FULL, CLUSTER_TX_RESOLVE_NONE, reason); break; case CLUSTER_CR_BUILD_RETRYABLE: - cluster_r4_observe(CLUSTER_R4_EVENT_CR_HOLDER_RETRY, - CLUSTER_TX_RESOLVE_NONE, reason); + cluster_r4_observe(CLUSTER_R4_EVENT_CR_HOLDER_RETRY, CLUSTER_TX_RESOLVE_NONE, reason); break; case CLUSTER_CR_BUILD_FAIL_CLOSED: - cluster_r4_observe(CLUSTER_R4_EVENT_CR_HOLDER_FAIL_CLOSED, - CLUSTER_TX_RESOLVE_NONE, reason); + cluster_r4_observe(CLUSTER_R4_EVENT_CR_HOLDER_FAIL_CLOSED, CLUSTER_TX_RESOLVE_NONE, + reason); break; } } @@ -431,14 +423,14 @@ cluster_cr_server_r4_worker0_drained(void) if (memcmp(&CrServerR4Contexts[i], &zero, sizeof(zero)) != 0) return false; switch (state) { - case CLUSTER_LMS_CR_R4_READY_FULL: - case CLUSTER_LMS_CR_R4_READY_RETRY: - case CLUSTER_LMS_CR_R4_READY_FAIL: - case CLUSTER_LMS_CR_R4_CANCELLED: - case CLUSTER_LMS_CR_R4_SHIPPING: - return false; - default: - break; + case CLUSTER_LMS_CR_R4_READY_FULL: + case CLUSTER_LMS_CR_R4_READY_RETRY: + case CLUSTER_LMS_CR_R4_READY_FAIL: + case CLUSTER_LMS_CR_R4_CANCELLED: + case CLUSTER_LMS_CR_R4_SHIPPING: + return false; + default: + break; } } @@ -517,8 +509,7 @@ cr_server_reserve_legacy_slot(ClusterLmsCrSlot *slot, uint32 reserved_state) bool reserved = false; if (slot == NULL - || (reserved_state != CLUSTER_LMS_CR_PENDING - && reserved_state != CLUSTER_LMS_CR_FILLING)) + || (reserved_state != CLUSTER_LMS_CR_PENDING && reserved_state != CLUSTER_LMS_CR_FILLING)) return false; lms_state = cluster_lms_shared_state(); if (lms_state == NULL) @@ -547,8 +538,7 @@ cr_server_r4_canonicalize_unpublished(ClusterLmsCrSlot *slot, uint64 slot_genera if (slot == NULL) return; - memset((char *)slot + sizeof(slot->state), 0, - sizeof(*slot) - sizeof(slot->state)); + memset((char *)slot + sizeof(slot->state), 0, sizeof(*slot) - sizeof(slot->state)); slot->r4.slot_generation = slot_generation; } @@ -562,8 +552,7 @@ cr_server_r4_release_unpublished(ClusterLmsCrSlot *slot, uint64 slot_generation) return false; cr_server_r4_canonicalize_unpublished(slot, slot_generation); pg_write_barrier(); - return pg_atomic_compare_exchange_u32( - &slot->state, &expected, CLUSTER_LMS_CR_FREE); + return pg_atomic_compare_exchange_u32(&slot->state, &expected, CLUSTER_LMS_CR_FREE); } #ifdef USE_CLUSTER_UNIT @@ -628,8 +617,7 @@ ClusterCrBuildResult cluster_lms_cr_submit_r4(const ClusterR4CrForwardPayload *forward, const ClusterSemanticAdmissionToken *receive_admission, uint32 requester_capability_generation, - uint32 master_capability_generation, - ClusterCrBuildReason *reason_out) + uint32 master_capability_generation, ClusterCrBuildReason *reason_out) { ClusterLmsSharedState *lms_state; ClusterLmsCrSlot *slot = NULL; @@ -661,25 +649,22 @@ cluster_lms_cr_submit_r4(const ClusterR4CrForwardPayload *forward, || receive_admission->side != (uint8)CLUSTER_SEMANTIC_TARGET_SIDE || receive_admission->record_generation == 0 || receive_admission->formation_epoch != forward->base.epoch - || forward->base.request_id == 0 - || forward->base.original_requester_node < 0 + || forward->base.request_id == 0 || forward->base.original_requester_node < 0 || forward->base.original_requester_node >= RESOURCE_X_PROTOCOL_NODE_LIMIT - || forward->base.requester_backend_id <= 0 - || forward->base.master_node < 0 + || forward->base.requester_backend_id <= 0 || forward->base.master_node < 0 || forward->base.master_node >= RESOURCE_X_PROTOCOL_NODE_LIMIT || forward->base.transition_id != (uint8)PCM_TRANS_N_TO_S - || !GcsBlockForwardPayloadIsCrRequest(&forward->base) - || forward->base.reserved_0[0] != 0 || forward->base.reserved_0[1] != 0 - || forward->base.reserved_0[2] != 0 || forward->base.reserved_0[3] != 0 - || forward->base.reserved_0[4] != 1 || forward->base.reserved_0[5] != 0 - || forward->base.reserved_0[6] != 0) + || !GcsBlockForwardPayloadIsCrRequest(&forward->base) || forward->base.reserved_0[0] != 0 + || forward->base.reserved_0[1] != 0 || forward->base.reserved_0[2] != 0 + || forward->base.reserved_0[3] != 0 || forward->base.reserved_0[4] != 1 + || forward->base.reserved_0[5] != 0 || forward->base.reserved_0[6] != 0) return CLUSTER_CR_BUILD_FAIL_CLOSED; if ((forward->base.master_node == cluster_node_id - && !cr_server_r4_local_open_generation_matches( - receive_admission, master_capability_generation)) + && !cr_server_r4_local_open_generation_matches(receive_admission, + master_capability_generation)) || (forward->base.original_requester_node == cluster_node_id - && !cr_server_r4_local_open_generation_matches( - receive_admission, requester_capability_generation))) + && !cr_server_r4_local_open_generation_matches(receive_admission, + requester_capability_generation))) return CLUSTER_CR_BUILD_FAIL_CLOSED; read_scn = GcsBlockForwardPayloadGetExpectedPiWatermarkScn(&forward->base); @@ -736,12 +721,11 @@ cluster_lms_cr_submit_r4(const ClusterR4CrForwardPayload *forward, candidate->r4.owner.edge_owner_incarnation = worker_incarnation; candidate->r4.owner.edge_owner_pid = MyProcPid; candidate->r4.owner.edge_owner_worker_id = (uint8)worker_id; - candidate->r4.owner.edge_owner_role - = (uint8)(worker_id == 0 ? B_LMS : B_LMS_WORKER); + candidate->r4.owner.edge_owner_role = (uint8)(worker_id == 0 ? B_LMS : B_LMS_WORKER); pg_write_barrier(); expected = CLUSTER_LMS_CR_FREE; - if (pg_atomic_compare_exchange_u32( - &candidate->state, &expected, CLUSTER_LMS_CR_FILLING)) { + if (pg_atomic_compare_exchange_u32(&candidate->state, &expected, + CLUSTER_LMS_CR_FILLING)) { slot = candidate; break; } @@ -779,44 +763,41 @@ cluster_lms_cr_submit_r4(const ClusterR4CrForwardPayload *forward, PG_TRY(); { copy_ok = cluster_bufmgr_copy_block_for_r4_cr( - forward->base.tag, route_proof.expected_page_scn, &copied_page_lsn, - &copied_page_scn, slot->result_page, ©_refusal); + forward->base.tag, route_proof.expected_page_scn, &copied_page_lsn, &copied_page_scn, + slot->result_page, ©_refusal); if (!copy_ok) { switch (copy_refusal) { - case CLUSTER_BUFMGR_GCS_COPY_REFUSAL_NOT_RESIDENT: - case CLUSTER_BUFMGR_GCS_COPY_REFUSAL_CURRENT_INVALID: - case CLUSTER_BUFMGR_GCS_COPY_REFUSAL_CONTENT_LOCK_FIRST: - case CLUSTER_BUFMGR_GCS_COPY_REFUSAL_CONTENT_LOCK_SECOND: - case CLUSTER_BUFMGR_GCS_COPY_REFUSAL_OWNERSHIP_REVOKE_BUSY: - reason = CLUSTER_CR_BUILD_HOLDER_MOVED; - break; - case CLUSTER_BUFMGR_GCS_COPY_REFUSAL_NONE: - case CLUSTER_BUFMGR_GCS_COPY_REFUSAL_INVALID_ARGUMENT: - case CLUSTER_BUFMGR_GCS_COPY_REFUSAL_HC89_LSN_DRIFT: - case CLUSTER_BUFMGR_GCS_COPY_REFUSAL_SMART_FUSION_UNCLASSIFIED: - case CLUSTER_BUFMGR_GCS_COPY_REFUSAL_INJECTED_EVICT: - default: - reason = CLUSTER_CR_BUILD_PROTOCOL; - break; + case CLUSTER_BUFMGR_GCS_COPY_REFUSAL_NOT_RESIDENT: + case CLUSTER_BUFMGR_GCS_COPY_REFUSAL_CURRENT_INVALID: + case CLUSTER_BUFMGR_GCS_COPY_REFUSAL_CONTENT_LOCK_FIRST: + case CLUSTER_BUFMGR_GCS_COPY_REFUSAL_CONTENT_LOCK_SECOND: + case CLUSTER_BUFMGR_GCS_COPY_REFUSAL_OWNERSHIP_REVOKE_BUSY: + reason = CLUSTER_CR_BUILD_HOLDER_MOVED; + break; + case CLUSTER_BUFMGR_GCS_COPY_REFUSAL_NONE: + case CLUSTER_BUFMGR_GCS_COPY_REFUSAL_INVALID_ARGUMENT: + case CLUSTER_BUFMGR_GCS_COPY_REFUSAL_HC89_LSN_DRIFT: + case CLUSTER_BUFMGR_GCS_COPY_REFUSAL_SMART_FUSION_UNCLASSIFIED: + case CLUSTER_BUFMGR_GCS_COPY_REFUSAL_INJECTED_EVICT: + default: + reason = CLUSTER_CR_BUILD_PROTOCOL; + break; } result = cluster_cr_build_result_for_reason(reason); - } - else { + } else { slot->r4.copied_page_lsn = copied_page_lsn; slot->r4.copied_page_scn = copied_page_scn; - final_match = cluster_semantic_activation_recheck(receive_admission) - && cr_server_r4_identity_open_matches( - receive_admission, forward->base.master_node, - master_capability_generation) - && cr_server_r4_identity_open_matches( - receive_admission, - forward->base.original_requester_node, - requester_capability_generation); + final_match + = cluster_semantic_activation_recheck(receive_admission) + && cr_server_r4_identity_open_matches( + receive_admission, forward->base.master_node, master_capability_generation) + && cr_server_r4_identity_open_matches(receive_admission, + forward->base.original_requester_node, + requester_capability_generation); if (!final_match) { reason = CLUSTER_CR_BUILD_RF_DEFERRED; result = CLUSTER_CR_BUILD_RETRYABLE; - } - else { + } else { pg_write_barrier(); pg_atomic_write_u32(&slot->state, CLUSTER_LMS_CR_R4_QUEUED); cleanup_needed = false; @@ -834,8 +815,7 @@ cluster_lms_cr_submit_r4(const ClusterR4CrForwardPayload *forward, } PG_END_TRY(); - if (cleanup_needed - && !cr_server_r4_release_unpublished(slot, slot_generation)) { + if (cleanup_needed && !cr_server_r4_release_unpublished(slot, slot_generation)) { reason = CLUSTER_CR_BUILD_PROTOCOL; result = CLUSTER_CR_BUILD_FAIL_CLOSED; } @@ -859,8 +839,7 @@ cr_server_bytes_zero(const void *ptr, Size size) static bool cr_server_r4_reclaimable_slot(const ClusterLmsCrSlot *slot, uint32 state, - const ClusterLmsSharedState *lms_state, - bool live_close_proved) + const ClusterLmsSharedState *lms_state, bool live_close_proved) { const ClusterR4CrOwnerStamp *owner; uint64 current_incarnation; @@ -875,8 +854,7 @@ cr_server_r4_reclaimable_slot(const ClusterLmsCrSlot *slot, uint32 state, if (state == CLUSTER_LMS_CR_R4_RECLAIMING) return true; if (state != CLUSTER_LMS_CR_FILLING - && (state < CLUSTER_LMS_CR_R4_QUEUED - || state > CLUSTER_LMS_CR_R4_SHIPPING)) + && (state < CLUSTER_LMS_CR_R4_QUEUED || state > CLUSTER_LMS_CR_R4_SHIPPING)) return false; if (state != CLUSTER_LMS_CR_FILLING && slot->req_kind != (uint8)CLUSTER_LMS_SLOT_KIND_R4_CR_BUILD) @@ -891,22 +869,17 @@ cr_server_r4_reclaimable_slot(const ClusterLmsCrSlot *slot, uint32 state, || !cr_server_bytes_zero(owner->reserved, sizeof(owner->reserved))) return false; - current_incarnation = lms_state->r4_controls.data_worker_incarnation[ - owner->edge_owner_worker_id]; - if (state == CLUSTER_LMS_CR_FILLING - || state == CLUSTER_LMS_CR_R4_QUEUED) { + current_incarnation + = lms_state->r4_controls.data_worker_incarnation[owner->edge_owner_worker_id]; + if (state == CLUSTER_LMS_CR_FILLING || state == CLUSTER_LMS_CR_R4_QUEUED) { if (owner->builder_incarnation != 0 || owner->builder_pid != 0) return false; - return live_close_proved - || current_incarnation != owner->edge_owner_incarnation; + return live_close_proved || current_incarnation != owner->edge_owner_incarnation; } - if (owner->builder_incarnation == 0 || owner->builder_pid <= 0 - || owner->builder_worker_id != 0) + if (owner->builder_incarnation == 0 || owner->builder_pid <= 0 || owner->builder_worker_id != 0) return false; - current_incarnation - = lms_state->r4_controls.data_worker_incarnation[owner->builder_worker_id]; - return live_close_proved - || current_incarnation != owner->builder_incarnation; + current_incarnation = lms_state->r4_controls.data_worker_incarnation[owner->builder_worker_id]; + return live_close_proved || current_incarnation != owner->builder_incarnation; } /* @@ -916,8 +889,7 @@ cr_server_r4_reclaimable_slot(const ClusterLmsCrSlot *slot, uint32 state, * and require four FREE publications before reporting zero. */ bool -cluster_cr_server_r4_lmon_reclaim_closed(uint64 worker_incarnation, - uint64 generation) +cluster_cr_server_r4_lmon_reclaim_closed(uint64 worker_incarnation, uint64 generation) { ClusterLmsSharedState *lms_state; bool claimed = false; @@ -931,11 +903,9 @@ cluster_cr_server_r4_lmon_reclaim_closed(uint64 worker_incarnation, return false; LWLockAcquire(&lms_state->lwlock, LW_EXCLUSIVE); - live_close_proved - = lms_state->r4_controls.data_worker_incarnation[0] - == worker_incarnation - && lms_state->r4_controls.drain_request_generation == generation - && lms_state->r4_controls.drain_ack_generation == generation; + live_close_proved = lms_state->r4_controls.data_worker_incarnation[0] == worker_incarnation + && lms_state->r4_controls.drain_request_generation == generation + && lms_state->r4_controls.drain_ack_generation == generation; if (!live_close_proved) goto release_proof_lock; @@ -943,8 +913,7 @@ cluster_cr_server_r4_lmon_reclaim_closed(uint64 worker_incarnation, ClusterLmsCrSlot *slot = &CrServerShared->slots[i]; uint32 state = pg_atomic_read_u32(&slot->state); - if (!cr_server_r4_reclaimable_slot( - slot, state, lms_state, live_close_proved)) + if (!cr_server_r4_reclaimable_slot(slot, state, lms_state, live_close_proved)) goto release_proof_lock; } @@ -953,12 +922,10 @@ cluster_cr_server_r4_lmon_reclaim_closed(uint64 worker_incarnation, uint32 state = pg_atomic_read_u32(&slot->state); uint32 expected; - if (state == CLUSTER_LMS_CR_FREE - || state == CLUSTER_LMS_CR_R4_RECLAIMING) + if (state == CLUSTER_LMS_CR_FREE || state == CLUSTER_LMS_CR_R4_RECLAIMING) continue; expected = state; - if (!pg_atomic_compare_exchange_u32( - &slot->state, &expected, CLUSTER_LMS_CR_R4_RECLAIMING)) + if (!pg_atomic_compare_exchange_u32(&slot->state, &expected, CLUSTER_LMS_CR_R4_RECLAIMING)) goto release_proof_lock; } claimed = true; @@ -982,14 +949,12 @@ cluster_cr_server_r4_lmon_reclaim_closed(uint64 worker_incarnation, cr_server_r4_canonicalize_unpublished(slot, slot_generation); pg_write_barrier(); expected = CLUSTER_LMS_CR_R4_RECLAIMING; - if (!pg_atomic_compare_exchange_u32( - &slot->state, &expected, CLUSTER_LMS_CR_FREE)) + if (!pg_atomic_compare_exchange_u32(&slot->state, &expected, CLUSTER_LMS_CR_FREE)) return false; } for (i = 0; i < CLUSTER_LMS_CR_SLOTS; i++) { - if (pg_atomic_read_u32(&CrServerShared->slots[i].state) - != CLUSTER_LMS_CR_FREE) + if (pg_atomic_read_u32(&CrServerShared->slots[i].state) != CLUSTER_LMS_CR_FREE) return false; } return true; @@ -1005,37 +970,33 @@ cr_server_r4_queued_identity_valid(const ClusterLmsCrSlot *slot, if (slot == NULL || lms_state == NULL || slot->req_kind != (uint8)CLUSTER_LMS_SLOT_KIND_R4_CR_BUILD - || slot->r4.slot_generation == 0 - || slot->r4.slot_generation > (UINT64_MAX >> 2) + || slot->r4.slot_generation == 0 || slot->r4.slot_generation > (UINT64_MAX >> 2) || slot->request_id == 0 || !SCN_VALID(slot->read_scn) || slot->epoch != slot->r4.route_proof.formation_epoch || !BufferTagsEqual(&slot->tag, &slot->r4.route_proof.tag) || slot->read_scn != slot->r4.route_proof.read_scn || slot->r4.route_proof.activation_generation == 0 || slot->reply_master_node != slot->r4.route_proof.real_master_node - || slot->r4.route_proof.selected_holder_node != cluster_node_id - || slot->requester_node < 0 || slot->requester_node >= RESOURCE_X_PROTOCOL_NODE_LIMIT - || slot->requester_backend <= 0 - || slot->reply_master_node < 0 - || slot->reply_master_node >= RESOURCE_X_PROTOCOL_NODE_LIMIT + || slot->r4.route_proof.selected_holder_node != cluster_node_id || slot->requester_node < 0 + || slot->requester_node >= RESOURCE_X_PROTOCOL_NODE_LIMIT || slot->requester_backend <= 0 + || slot->reply_master_node < 0 || slot->reply_master_node >= RESOURCE_X_PROTOCOL_NODE_LIMIT || slot->transition_id != (uint8)PCM_TRANS_N_TO_S || slot->r4.requester_capability_generation == 0 || slot->r4.master_capability_generation == 0 - || slot->r4.terminal_reason != (uint8)CLUSTER_CR_BUILD_NONE - || slot->r4.flags != 0 + || slot->r4.terminal_reason != (uint8)CLUSTER_CR_BUILD_NONE || slot->r4.flags != 0 || !cr_server_bytes_zero(slot->r4.reserved, sizeof(slot->r4.reserved))) return false; owner = &slot->r4.owner; - if (owner->edge_owner_worker_id >= CLUSTER_LMS_MAX_WORKERS - || owner->edge_owner_incarnation == 0 || owner->builder_incarnation != 0 - || owner->builder_pid != 0 || owner->builder_worker_id != 0 + if (owner->edge_owner_worker_id >= CLUSTER_LMS_MAX_WORKERS || owner->edge_owner_incarnation == 0 + || owner->builder_incarnation != 0 || owner->builder_pid != 0 + || owner->builder_worker_id != 0 || !cr_server_bytes_zero(owner->reserved, sizeof(owner->reserved))) return false; expected_role = (uint8)(owner->edge_owner_worker_id == 0 ? B_LMS : B_LMS_WORKER); return owner->edge_owner_role == expected_role && lms_state->r4_controls.data_worker_incarnation[owner->edge_owner_worker_id] - == owner->edge_owner_incarnation; + == owner->edge_owner_incarnation; } /* @@ -1071,22 +1032,19 @@ cr_server_r4_claim_queued(uint32 slot_index) return false; memset(&admission, 0, sizeof(admission)); - admission_result = cluster_semantic_activation_enter( - CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, CLUSTER_SEMANTIC_TARGET_SIDE, - &admission); + admission_result = cluster_semantic_activation_enter(CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, + CLUSTER_SEMANTIC_TARGET_SIDE, &admission); if (admission_result != CLUSTER_SEMANTIC_ADMISSION_OK) return false; - has_local_identity = slot->reply_master_node == cluster_node_id - || slot->requester_node == cluster_node_id; + has_local_identity + = slot->reply_master_node == cluster_node_id || slot->requester_node == cluster_node_id; if (admission.record_generation != slot->r4.route_proof.activation_generation || admission.formation_epoch != slot->epoch || (has_local_identity && !cluster_semantic_activation_recheck(&admission)) - || !cr_server_r4_identity_open_matches( - &admission, slot->reply_master_node, - slot->r4.master_capability_generation) - || !cr_server_r4_identity_open_matches( - &admission, slot->requester_node, - slot->r4.requester_capability_generation)) { + || !cr_server_r4_identity_open_matches(&admission, slot->reply_master_node, + slot->r4.master_capability_generation) + || !cr_server_r4_identity_open_matches(&admission, slot->requester_node, + slot->r4.requester_capability_generation)) { cluster_semantic_activation_leave(&admission); return false; } @@ -1101,8 +1059,7 @@ cr_server_r4_claim_queued(uint32 slot_index) slot->r4.owner.edge_owner_role = (uint8)B_LMS; pg_write_barrier(); expected = CLUSTER_LMS_CR_R4_QUEUED; - if (!pg_atomic_compare_exchange_u32( - &slot->state, &expected, CLUSTER_LMS_CR_R4_BUILDING)) { + if (!pg_atomic_compare_exchange_u32(&slot->state, &expected, CLUSTER_LMS_CR_R4_BUILDING)) { cluster_semantic_activation_leave(&admission); return false; } @@ -1128,22 +1085,20 @@ cr_server_r4_claim_queued(uint32 slot_index) * here. */ static bool -cr_server_r4_terminalize_build_error( - uint32 slot_index, ClusterLmsCrSlot *slot, ClusterR4CrWorkerContext *context, - const ClusterR4CrWorkerContext *key, int sqlerrcode) +cr_server_r4_terminalize_build_error(uint32 slot_index, ClusterLmsCrSlot *slot, + ClusterR4CrWorkerContext *context, + const ClusterR4CrWorkerContext *key, int sqlerrcode) { ClusterCrBuildReason reason; uint32 terminal_state; uint32 expected = CLUSTER_LMS_CR_R4_BUILDING; - if (slot == NULL || context == NULL || key == NULL || !key->in_use - || key->builder_forgotten + if (slot == NULL || context == NULL || key == NULL || !key->in_use || key->builder_forgotten || pg_atomic_read_u32(&slot->state) != CLUSTER_LMS_CR_R4_BUILDING || memcmp(context, key, sizeof(*key)) != 0 || slot->r4.slot_generation != key->slot_generation || slot->r4.owner.builder_incarnation != key->builder_incarnation - || slot->r4.owner.builder_pid != MyProcPid - || slot->r4.owner.builder_worker_id != 0 + || slot->r4.owner.builder_pid != MyProcPid || slot->r4.owner.builder_worker_id != 0 || slot->requester_node != key->requester_node || slot->requester_backend != key->requester_backend_id || slot->request_id != key->request_id) @@ -1152,8 +1107,7 @@ cr_server_r4_terminalize_build_error( if (sqlerrcode == ERRCODE_QUERY_CANCELED) { reason = CLUSTER_CR_BUILD_CANCELLED; terminal_state = CLUSTER_LMS_CR_R4_CANCELLED; - } - else { + } else { reason = CLUSTER_CR_BUILD_IO_ERROR; terminal_state = CLUSTER_LMS_CR_R4_READY_FAIL; } @@ -1258,8 +1212,8 @@ cr_server_r4_build_step(uint32 slot_index) } PG_CATCH(); { - error_terminalized = cr_server_r4_terminalize_build_error( - slot_index, slot, context, &key, geterrcode()); + error_terminalized + = cr_server_r4_terminalize_build_error(slot_index, slot, context, &key, geterrcode()); if (!error_terminalized) PG_RE_THROW(); MemoryContextSwitchTo(saved_context); @@ -1269,39 +1223,39 @@ cr_server_r4_build_step(uint32 slot_index) if (error_terminalized) return true; switch (step_result) { - case CLUSTER_R4_CR_STEP_FULL: - if (reason == CLUSTER_CR_BUILD_NONE) - terminal_state = CLUSTER_LMS_CR_R4_READY_FULL; - else { - reason = CLUSTER_CR_BUILD_PROTOCOL; - terminal_state = CLUSTER_LMS_CR_R4_READY_FAIL; - } - break; - case CLUSTER_R4_CR_STEP_RETRY: - if (reason != CLUSTER_CR_BUILD_NONE - && cluster_cr_build_result_for_reason(reason) == CLUSTER_CR_BUILD_RETRYABLE) - terminal_state = CLUSTER_LMS_CR_R4_READY_RETRY; - else { - reason = CLUSTER_CR_BUILD_PROTOCOL; - terminal_state = CLUSTER_LMS_CR_R4_READY_FAIL; - } - break; - case CLUSTER_R4_CR_STEP_FAIL: - if (reason == CLUSTER_CR_BUILD_NONE - || cluster_cr_build_result_for_reason(reason) != CLUSTER_CR_BUILD_FAIL_CLOSED) - reason = CLUSTER_CR_BUILD_PROTOCOL; + case CLUSTER_R4_CR_STEP_FULL: + if (reason == CLUSTER_CR_BUILD_NONE) + terminal_state = CLUSTER_LMS_CR_R4_READY_FULL; + else { + reason = CLUSTER_CR_BUILD_PROTOCOL; terminal_state = CLUSTER_LMS_CR_R4_READY_FAIL; - break; - case CLUSTER_R4_CR_STEP_NEED_UNDO: - if (reason == CLUSTER_CR_BUILD_NONE) - terminal_state = CLUSTER_LMS_CR_R4_NEED_UNDO; - else { - reason = CLUSTER_CR_BUILD_PROTOCOL; - terminal_state = CLUSTER_LMS_CR_R4_READY_FAIL; - } - break; - default: - return false; + } + break; + case CLUSTER_R4_CR_STEP_RETRY: + if (reason != CLUSTER_CR_BUILD_NONE + && cluster_cr_build_result_for_reason(reason) == CLUSTER_CR_BUILD_RETRYABLE) + terminal_state = CLUSTER_LMS_CR_R4_READY_RETRY; + else { + reason = CLUSTER_CR_BUILD_PROTOCOL; + terminal_state = CLUSTER_LMS_CR_R4_READY_FAIL; + } + break; + case CLUSTER_R4_CR_STEP_FAIL: + if (reason == CLUSTER_CR_BUILD_NONE + || cluster_cr_build_result_for_reason(reason) != CLUSTER_CR_BUILD_FAIL_CLOSED) + reason = CLUSTER_CR_BUILD_PROTOCOL; + terminal_state = CLUSTER_LMS_CR_R4_READY_FAIL; + break; + case CLUSTER_R4_CR_STEP_NEED_UNDO: + if (reason == CLUSTER_CR_BUILD_NONE) + terminal_state = CLUSTER_LMS_CR_R4_NEED_UNDO; + else { + reason = CLUSTER_CR_BUILD_PROTOCOL; + terminal_state = CLUSTER_LMS_CR_R4_READY_FAIL; + } + break; + default: + return false; } if (reason == CLUSTER_CR_BUILD_PROTOCOL) @@ -1315,8 +1269,7 @@ cr_server_r4_build_step(uint32 slot_index) static bool cr_server_r4_publish_foreign_terminal(ClusterLmsCrSlot *slot, uint32 from_state, - uint32 terminal_state, - ClusterCrBuildReason reason) + uint32 terminal_state, ClusterCrBuildReason reason) { uint32 expected = from_state; @@ -1327,10 +1280,9 @@ cr_server_r4_publish_foreign_terminal(ClusterLmsCrSlot *slot, uint32 from_state, static bool cr_server_r4_foreign_request_valid(uint32 slot_index, const ClusterLmsCrSlot *slot, - const ClusterR4CrWorkerContext *context, - bool allow_unresolved_wrap, - ClusterTxLocator *locator_out, - uint32 *segment_out, uint32 *block_out) + const ClusterR4CrWorkerContext *context, + bool allow_unresolved_wrap, ClusterTxLocator *locator_out, + uint32 *segment_out, uint32 *block_out) { uint16 tt_slot_offset; uint16 row_offset; @@ -1408,18 +1360,18 @@ cr_server_r4_send_foreign_undo(uint32 slot_index) if (!cr_server_r4_foreign_request_valid(slot_index, slot, context, true, &locator, &segment_id, &block_no)) { cr_server_r4_protocol_detail(slot, "FROZEN_REQUEST", -1, -1, -1, false, 0); - return cr_server_r4_publish_foreign_terminal( - slot, CLUSTER_LMS_CR_R4_NEED_UNDO, CLUSTER_LMS_CR_R4_READY_FAIL, - CLUSTER_CR_BUILD_PROTOCOL); + return cr_server_r4_publish_foreign_terminal(slot, CLUSTER_LMS_CR_R4_NEED_UNDO, + CLUSTER_LMS_CR_R4_READY_FAIL, + CLUSTER_CR_BUILD_PROTOCOL); } /* An absent local foreign header is not missing origin authority. The * original-origin service selects and rechecks its generation under SCUR. */ if (context->foreign_physical_generation_frozen && context->expected_foreign_physical_generation == UINT32_MAX) { cr_server_r4_protocol_detail(slot, "FROZEN_GENERATION", -1, -1, -1, true, UINT32_MAX); - return cr_server_r4_publish_foreign_terminal( - slot, CLUSTER_LMS_CR_R4_NEED_UNDO, CLUSTER_LMS_CR_R4_READY_FAIL, - CLUSTER_CR_BUILD_PROTOCOL); + return cr_server_r4_publish_foreign_terminal(slot, CLUSTER_LMS_CR_R4_NEED_UNDO, + CLUSTER_LMS_CR_R4_READY_FAIL, + CLUSTER_CR_BUILD_PROTOCOL); } request_generation = context->foreign_physical_generation_frozen ? context->expected_foreign_physical_generation @@ -1433,51 +1385,47 @@ cr_server_r4_send_foreign_undo(uint32 slot_index) forward.base.requester_backend_id = CLUSTER_GCS_BLOCK_R4_INTERNAL_ENDPOINT; forward.base.master_node = cluster_node_id; forward.base.transition_id = (uint8)PCM_TRANS_N_TO_S; - GcsBlockForwardPayloadSetExpectedPiWatermarkScn( - &forward.base, slot->r4.route_proof.read_scn); + GcsBlockForwardPayloadSetExpectedPiWatermarkScn(&forward.base, slot->r4.route_proof.read_scn); forward.base.reserved_0[6] = CLUSTER_R4_FORWARD_EXTENDED; if (!ClusterR4ForwardExtensionSetLocatorGeneration( &forward.extension, CLUSTER_R4_WIRE_UNDO_DATA_FETCH, &locator, request_generation)) { cr_server_r4_protocol_detail(slot, "FORWARD_ENCODE", -1, -1, -1, context->foreign_physical_generation_frozen, request_generation); - return cr_server_r4_publish_foreign_terminal( - slot, CLUSTER_LMS_CR_R4_NEED_UNDO, CLUSTER_LMS_CR_R4_READY_FAIL, - CLUSTER_CR_BUILD_PROTOCOL); + return cr_server_r4_publish_foreign_terminal(slot, CLUSTER_LMS_CR_R4_NEED_UNDO, + CLUSTER_LMS_CR_R4_READY_FAIL, + CLUSTER_CR_BUILD_PROTOCOL); } expected = CLUSTER_LMS_CR_R4_NEED_UNDO; - if (!pg_atomic_compare_exchange_u32( - &slot->state, &expected, CLUSTER_LMS_CR_R4_UNDO_INFLIGHT)) + if (!pg_atomic_compare_exchange_u32(&slot->state, &expected, CLUSTER_LMS_CR_R4_UNDO_INFLIGHT)) return false; pg_read_barrier(); - send_result = cluster_ic_send_envelope( - PGRAC_IC_MSG_GCS_BLOCK_FORWARD, slot->r4.foreign_origin_node, &forward, - sizeof(forward)); + send_result = cluster_ic_send_envelope(PGRAC_IC_MSG_GCS_BLOCK_FORWARD, + slot->r4.foreign_origin_node, &forward, sizeof(forward)); cluster_gcs_block_note_send_outcome(GCS_BLOCK_SEND_FAMILY_FORWARD, send_result); switch (send_result) { - case CLUSTER_IC_SEND_DONE: - case CLUSTER_IC_SEND_WOULD_BLOCK: - return true; - case CLUSTER_IC_SEND_NOT_ADMITTED: - return cr_server_r4_publish_foreign_terminal( - slot, CLUSTER_LMS_CR_R4_UNDO_INFLIGHT, - CLUSTER_LMS_CR_R4_READY_RETRY, CLUSTER_CR_BUILD_CAPACITY); - case CLUSTER_IC_SEND_HARD_ERROR: - cluster_lms_data_plane_close_peer_now(slot->r4.foreign_origin_node); - cr_server_r4_protocol_detail(slot, "FORWARD_SEND", send_result, -1, -1, false, 0); - return cr_server_r4_publish_foreign_terminal( - slot, CLUSTER_LMS_CR_R4_UNDO_INFLIGHT, - CLUSTER_LMS_CR_R4_READY_FAIL, CLUSTER_CR_BUILD_PROTOCOL); + case CLUSTER_IC_SEND_DONE: + case CLUSTER_IC_SEND_WOULD_BLOCK: + return true; + case CLUSTER_IC_SEND_NOT_ADMITTED: + return cr_server_r4_publish_foreign_terminal(slot, CLUSTER_LMS_CR_R4_UNDO_INFLIGHT, + CLUSTER_LMS_CR_R4_READY_RETRY, + CLUSTER_CR_BUILD_CAPACITY); + case CLUSTER_IC_SEND_HARD_ERROR: + cluster_lms_data_plane_close_peer_now(slot->r4.foreign_origin_node); + cr_server_r4_protocol_detail(slot, "FORWARD_SEND", send_result, -1, -1, false, 0); + return cr_server_r4_publish_foreign_terminal(slot, CLUSTER_LMS_CR_R4_UNDO_INFLIGHT, + CLUSTER_LMS_CR_R4_READY_FAIL, + CLUSTER_CR_BUILD_PROTOCOL); } return false; } static bool -cr_server_r4_foreign_landing_key_valid( - uint32 slot_index, ClusterLmsCrSlot *slot, - const ClusterR4CrWorkerContext *context, - const ClusterR4CrWorkerContext *frozen_context) +cr_server_r4_foreign_landing_key_valid(uint32 slot_index, ClusterLmsCrSlot *slot, + const ClusterR4CrWorkerContext *context, + const ClusterR4CrWorkerContext *frozen_context) { ClusterLmsSharedState *lms_state = cluster_lms_shared_state(); @@ -1519,9 +1467,10 @@ cr_server_r4_foreign_landing_key_valid( } bool -cluster_cr_server_r4_land_foreign_undo( - const ClusterICEnvelope *env, const GcsBlockReplyHeader *header, - const char undo_page[BLCKSZ], const ClusterGcsUndoAuthTrailer *undo_auth) +cluster_cr_server_r4_land_foreign_undo(const ClusterICEnvelope *env, + const GcsBlockReplyHeader *header, + const char undo_page[BLCKSZ], + const ClusterGcsUndoAuthTrailer *undo_auth) { ClusterLmsCrSlot *slot; ClusterR4CrWorkerContext *context; @@ -1570,8 +1519,7 @@ cluster_cr_server_r4_land_foreign_undo( slot_index = (uint32)(header->request_id & (CLUSTER_LMS_CR_SLOTS - 1)); slot = &CrServerShared->slots[slot_index]; context = &CrServerR4Contexts[slot_index]; - if (pg_atomic_read_u32(&slot->state) - != CLUSTER_LMS_CR_R4_UNDO_INFLIGHT) + if (pg_atomic_read_u32(&slot->state) != CLUSTER_LMS_CR_R4_UNDO_INFLIGHT) return false; pg_read_barrier(); frozen_context = *context; @@ -1608,17 +1556,14 @@ cluster_cr_server_r4_land_foreign_undo( memset(&receive_admission, 0, sizeof(receive_admission)); admission_result = cluster_semantic_activation_enter( - CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, - CLUSTER_SEMANTIC_TARGET_SIDE, &receive_admission); + CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, CLUSTER_SEMANTIC_TARGET_SIDE, &receive_admission); if (admission_result != CLUSTER_SEMANTIC_ADMISSION_OK) return false; admitted = true; - if (receive_admission.record_generation - != frozen_context.admission.record_generation + if (receive_admission.record_generation != frozen_context.admission.record_generation || receive_admission.formation_epoch != header->epoch || !cluster_semantic_activation_recheck(&receive_admission) - || !cr_server_r4_foreign_landing_key_valid( - slot_index, slot, context, &frozen_context)) + || !cr_server_r4_foreign_landing_key_valid(slot_index, slot, context, &frozen_context)) goto out; if (refusal) { @@ -1643,8 +1588,7 @@ cluster_cr_server_r4_land_foreign_undo( slot->r4.origin_authority_scn = authority_scn; pg_write_barrier(); expected = CLUSTER_LMS_CR_R4_UNDO_INFLIGHT; - landed = pg_atomic_compare_exchange_u32( - &slot->state, &expected, CLUSTER_LMS_CR_R4_UNDO_READY); + landed = pg_atomic_compare_exchange_u32(&slot->state, &expected, CLUSTER_LMS_CR_R4_UNDO_READY); out: if (admitted) @@ -1702,37 +1646,32 @@ cr_server_r4_ship_terminal(uint32 slot_index) terminal_state = pg_atomic_read_u32(&slot->state); terminal_reason = (ClusterCrBuildReason)slot->r4.terminal_reason; switch (terminal_state) { - case CLUSTER_LMS_CR_R4_READY_FULL: - if (terminal_reason != CLUSTER_CR_BUILD_NONE) - return false; - reply_status = (uint8)GCS_BLOCK_REPLY_R4_CR_FULL; - break; - case CLUSTER_LMS_CR_R4_READY_RETRY: - if (terminal_reason <= CLUSTER_CR_BUILD_NONE - || terminal_reason > CLUSTER_CR_BUILD_PROTOCOL - || cluster_cr_build_result_for_reason(terminal_reason) - != CLUSTER_CR_BUILD_RETRYABLE) - return false; - reply_status = (uint8)GCS_BLOCK_REPLY_R4_RETRYABLE_HOLDER_MOVED; - break; - case CLUSTER_LMS_CR_R4_READY_FAIL: - if (terminal_reason <= CLUSTER_CR_BUILD_NONE - || terminal_reason > CLUSTER_CR_BUILD_PROTOCOL - || cluster_cr_build_result_for_reason(terminal_reason) - != CLUSTER_CR_BUILD_FAIL_CLOSED) - return false; - reply_status = (uint8)GCS_BLOCK_REPLY_R4_DENIED; - break; - case CLUSTER_LMS_CR_R4_CANCELLED: - if (terminal_reason != CLUSTER_CR_BUILD_CANCELLED) - return false; - reply_status = (uint8)GCS_BLOCK_REPLY_R4_DENIED; - break; - default: + case CLUSTER_LMS_CR_R4_READY_FULL: + if (terminal_reason != CLUSTER_CR_BUILD_NONE) + return false; + reply_status = (uint8)GCS_BLOCK_REPLY_R4_CR_FULL; + break; + case CLUSTER_LMS_CR_R4_READY_RETRY: + if (terminal_reason <= CLUSTER_CR_BUILD_NONE || terminal_reason > CLUSTER_CR_BUILD_PROTOCOL + || cluster_cr_build_result_for_reason(terminal_reason) != CLUSTER_CR_BUILD_RETRYABLE) + return false; + reply_status = (uint8)GCS_BLOCK_REPLY_R4_RETRYABLE_HOLDER_MOVED; + break; + case CLUSTER_LMS_CR_R4_READY_FAIL: + if (terminal_reason <= CLUSTER_CR_BUILD_NONE || terminal_reason > CLUSTER_CR_BUILD_PROTOCOL + || cluster_cr_build_result_for_reason(terminal_reason) != CLUSTER_CR_BUILD_FAIL_CLOSED) return false; + reply_status = (uint8)GCS_BLOCK_REPLY_R4_DENIED; + break; + case CLUSTER_LMS_CR_R4_CANCELLED: + if (terminal_reason != CLUSTER_CR_BUILD_CANCELLED) + return false; + reply_status = (uint8)GCS_BLOCK_REPLY_R4_DENIED; + break; + default: + return false; } - if (!context->in_use || !context->admission.entered - || context->slot_generation == 0 + if (!context->in_use || !context->admission.entered || context->slot_generation == 0 || context->slot_generation != slot->r4.slot_generation || context->builder_incarnation != slot->r4.owner.builder_incarnation || context->requester_node != slot->requester_node @@ -1742,8 +1681,7 @@ cr_server_r4_ship_terminal(uint32 slot_index) slot_generation = context->slot_generation; expected = terminal_state; - if (!pg_atomic_compare_exchange_u32( - &slot->state, &expected, CLUSTER_LMS_CR_R4_SHIPPING)) + if (!pg_atomic_compare_exchange_u32(&slot->state, &expected, CLUSTER_LMS_CR_R4_SHIPPING)) return false; pg_read_barrier(); @@ -1761,12 +1699,11 @@ cr_server_r4_ship_terminal(uint32 slot_index) } header->checksum = cluster_gcs_block_compute_checksum(frame + sizeof(*header)); - if (!cr_server_r4_identity_open_matches( - &context->admission, slot->requester_node, - slot->r4.requester_capability_generation) + if (!cr_server_r4_identity_open_matches(&context->admission, slot->requester_node, + slot->r4.requester_capability_generation) || !cluster_semantic_activation_recheck(&context->admission) - || (terminal_state == CLUSTER_LMS_CR_R4_READY_FULL - && cluster_write_fence_enforcing() && !cluster_write_fence_allowed())) + || (terminal_state == CLUSTER_LMS_CR_R4_READY_FULL && cluster_write_fence_enforcing() + && !cluster_write_fence_allowed())) return cr_server_r4_release_terminal(slot_index, slot_generation); if (terminal_reason != CLUSTER_CR_BUILD_NONE) @@ -1775,33 +1712,28 @@ cr_server_r4_ship_terminal(uint32 slot_index) slot->reply_master_node, slot->read_scn); if (slot->requester_node == cluster_node_id) { - if (!cluster_ic_envelope_build( - &envelope, PGRAC_IC_MSG_GCS_BLOCK_REPLY, - (uint32)cluster_node_id, (uint32)cluster_node_id, - frame, sizeof(frame))) + if (!cluster_ic_envelope_build(&envelope, PGRAC_IC_MSG_GCS_BLOCK_REPLY, + (uint32)cluster_node_id, (uint32)cluster_node_id, frame, + sizeof(frame))) send_result = CLUSTER_IC_SEND_HARD_ERROR; else - send_result = cluster_ic_dispatch_envelope( - &envelope, frame, cluster_node_id) - ? CLUSTER_IC_SEND_DONE - : CLUSTER_IC_SEND_HARD_ERROR; - } - else - send_result = cluster_ic_send_envelope( - PGRAC_IC_MSG_GCS_BLOCK_REPLY, slot->requester_node, frame, - sizeof(frame)); + send_result = cluster_ic_dispatch_envelope(&envelope, frame, cluster_node_id) + ? CLUSTER_IC_SEND_DONE + : CLUSTER_IC_SEND_HARD_ERROR; + } else + send_result = cluster_ic_send_envelope(PGRAC_IC_MSG_GCS_BLOCK_REPLY, slot->requester_node, + frame, sizeof(frame)); switch (send_result) { - case CLUSTER_IC_SEND_DONE: - case CLUSTER_IC_SEND_WOULD_BLOCK: - return cr_server_r4_release_terminal(slot_index, slot_generation); - case CLUSTER_IC_SEND_NOT_ADMITTED: - expected = CLUSTER_LMS_CR_R4_SHIPPING; - (void)pg_atomic_compare_exchange_u32( - &slot->state, &expected, terminal_state); - return false; - case CLUSTER_IC_SEND_HARD_ERROR: - cluster_lms_data_plane_close_peer_now(slot->requester_node); - return cr_server_r4_release_terminal(slot_index, slot_generation); + case CLUSTER_IC_SEND_DONE: + case CLUSTER_IC_SEND_WOULD_BLOCK: + return cr_server_r4_release_terminal(slot_index, slot_generation); + case CLUSTER_IC_SEND_NOT_ADMITTED: + expected = CLUSTER_LMS_CR_R4_SHIPPING; + (void)pg_atomic_compare_exchange_u32(&slot->state, &expected, terminal_state); + return false; + case CLUSTER_IC_SEND_HARD_ERROR: + cluster_lms_data_plane_close_peer_now(slot->requester_node); + return cr_server_r4_release_terminal(slot_index, slot_generation); } return false; } @@ -1826,8 +1758,7 @@ cluster_cr_server_test_r4_send_foreign_undo(uint32 slot_index) } bool -cluster_cr_server_test_r4_freeze_foreign_generation( - uint32 slot_index, uint32 physical_generation) +cluster_cr_server_test_r4_freeze_foreign_generation(uint32 slot_index, uint32 physical_generation) { ClusterLmsCrSlot *slot; ClusterR4CrWorkerContext *context; @@ -1864,9 +1795,9 @@ cluster_cr_server_test_r4_reset_contexts(void) } bool -cluster_cr_server_test_r4_context_matches( - uint32 slot_index, bool expect_present, uint64 slot_generation, - uint64 builder_incarnation, const ClusterSemanticAdmissionToken *admission) +cluster_cr_server_test_r4_context_matches(uint32 slot_index, bool expect_present, + uint64 slot_generation, uint64 builder_incarnation, + const ClusterSemanticAdmissionToken *admission) { ClusterR4CrWorkerContext zero; ClusterR4CrWorkerContext *context; @@ -1979,9 +1910,8 @@ cluster_lms_undo_verdict_submit(const GcsBlockForwardPayload *fwd) freshref_pair = GcsBlockForwardPayloadIsUndoFreshRefC1bPairRequest(fwd); if (freshref_pair) { if (!cluster_cr_server_freshref_c1b_pair_request_decode( - fwd, fwd->original_requester_node, cluster_node_id, - cluster_epoch_get_current(), MaxBackends, &segment_id, &pair_xid, - &block_no, &pair_scn)) + fwd, fwd->original_requester_node, cluster_node_id, cluster_epoch_get_current(), + MaxBackends, &segment_id, &pair_xid, &block_no, &pair_scn)) return false; } else if (!GcsBlockUndoFetchTagDecode(fwd->tag, &segment_id, &block_no)) return false; @@ -1999,8 +1929,7 @@ cluster_lms_undo_verdict_submit(const GcsBlockForwardPayload *fwd) if (!freshref_pair) { carrier = (uint64)GcsBlockForwardPayloadGetExpectedPiWatermarkScn(fwd); - if (carrier > (uint64)PG_UINT32_MAX - || !TransactionIdIsNormal((TransactionId)carrier)) + if (carrier > (uint64)PG_UINT32_MAX || !TransactionIdIsNormal((TransactionId)carrier)) return false; } @@ -2302,8 +2231,7 @@ lms_resolve_own_xid_freshref_c1b_pair(TransactionId xid, uint32 expected_segment volatile LmsFreshrefPairDiagnostic *diagnostic) { volatile LmsFreshrefPairDiagnostic ignored; - ClusterUndoVerdictKind pair_verdict - = CLUSTER_UNDO_VERDICT_UNKNOWN_FAIL_CLOSED; + ClusterUndoVerdictKind pair_verdict = CLUSTER_UNDO_VERDICT_UNKNOWN_FAIL_CLOSED; ClusterTTDurableResolve resolve = CLUSTER_TT_DURABLE_SCAN_UNAVAILABLE; SCN resolved_scn = InvalidScn; SCN horizon_scn = InvalidScn; @@ -2323,9 +2251,8 @@ lms_resolve_own_xid_freshref_c1b_pair(TransactionId xid, uint32 expected_segment *out_horizon_scn = InvalidScn; *out_wrap = 0; - if (!TransactionIdIsNormal(xid) || expected_segment_id == 0 - || expected_segment_id > UINT16_MAX || expected_tt_slot_id < 1 - || expected_tt_slot_id > TT_SLOTS_PER_SEGMENT + if (!TransactionIdIsNormal(xid) || expected_segment_id == 0 || expected_segment_id > UINT16_MAX + || expected_tt_slot_id < 1 || expected_tt_slot_id > TT_SLOTS_PER_SEGMENT || !SCN_VALID(proposed_scn)) return LMS_OWN_XID_REFUSE_OTHER; @@ -2346,9 +2273,9 @@ lms_resolve_own_xid_freshref_c1b_pair(TransactionId xid, uint32 expected_segment diagnostic->own_xid = xid_is_mine; if (xid_is_mine) { - resolve = cluster_tt_slot_durable_resolve_by_xid( - xid, CLUSTER_TT_WRAP_ANY, &resolved_scn, &matched_segment, - &matched_slot, &matched_wrap); + resolve = cluster_tt_slot_durable_resolve_by_xid(xid, CLUSTER_TT_WRAP_ANY, + &resolved_scn, &matched_segment, + &matched_slot, &matched_wrap); diagnostic->scan_sampled = true; diagnostic->resolve = resolve; diagnostic->matched_segment = matched_segment; @@ -2372,8 +2299,7 @@ lms_resolve_own_xid_freshref_c1b_pair(TransactionId xid, uint32 expected_segment } LWLockRelease(XactTruncationLock); - if (clog_sampled - && resolve == CLUSTER_TT_DURABLE_RECYCLED_ZERO_MATCH + if (clog_sampled && resolve == CLUSTER_TT_DURABLE_RECYCLED_ZERO_MATCH && raw_clog_status == TRANSACTION_STATUS_COMMITTED) { retention_ok = lms_own_xid_recycle_bound(&horizon_scn); /* This path already holds the no-reuse reader fence and @@ -2395,10 +2321,9 @@ lms_resolve_own_xid_freshref_c1b_pair(TransactionId xid, uint32 expected_segment if (clog_sampled) pair_verdict = cluster_cr_server_freshref_c1b_pair_verdict( - true, true, expected_segment_id, expected_tt_slot_id, - no_raw_reuse_window, raw_clog_status, resolve, - matched_segment, matched_slot, resolved_scn, proposed_scn, - retention_ok, horizon_scn); + true, true, expected_segment_id, expected_tt_slot_id, no_raw_reuse_window, + raw_clog_status, resolve, matched_segment, matched_slot, resolved_scn, + proposed_scn, retention_ok, horizon_scn); } } cluster_cr_native_prehistory_reader_unlock(); @@ -2434,9 +2359,9 @@ lms_resolve_own_xid_freshref_c1b_pair(TransactionId xid, uint32 expected_segment * the exact COMMITTED conjunction, with the retained SCN remaining the * proposed value. */ bool -cluster_cr_server_local_freshref_c1b_pair_exact( - TransactionId xid, uint32 expected_segment_id, - uint32 expected_tt_slot_id, SCN proposed_scn, uint16 *out_wrap) +cluster_cr_server_local_freshref_c1b_pair_exact(TransactionId xid, uint32 expected_segment_id, + uint32 expected_tt_slot_id, SCN proposed_scn, + uint16 *out_wrap) { uint8 verdict = 0; SCN commit_scn = InvalidScn; @@ -2622,7 +2547,7 @@ lms_resolve_own_xid_verdict_observed(TransactionId xid, uint32 expected_segment_ *out_wrap = 0; resolve = cluster_tt_slot_durable_resolve_by_xid(xid, CLUSTER_TT_WRAP_ANY, &scn, - &matched_segment, &matched_slot, &wrap); + &matched_segment, &matched_slot, &wrap); diagnostic->resolve = resolve; diagnostic->resolved_scn = scn; diagnostic->matched_segment = matched_segment; @@ -2708,8 +2633,8 @@ lms_resolve_own_xid_verdict_observed(TransactionId xid, uint32 expected_segment_ if (xid_is_in_progress || terminal_rechecked) { durable_binding_stable = cluster_tt_slot_durable_resolve_by_xid(xid, CLUSTER_TT_WRAP_ANY, - &confirm_scn, &confirm_segment, - &confirm_slot, &confirm_wrap) + &confirm_scn, &confirm_segment, + &confirm_slot, &confirm_wrap) == CLUSTER_TT_DURABLE_RESOLVED_SCN && confirm_segment == matched_segment && confirm_slot == matched_slot && confirm_wrap == wrap && confirm_scn == scn; @@ -2719,9 +2644,9 @@ lms_resolve_own_xid_verdict_observed(TransactionId xid, uint32 expected_segment_ } } } - exact_live = cluster_cr_server_live_binding_exact( - xid_is_mine, expected_segment_id, expected_tt_slot_id, matched_segment, - matched_slot, xid_is_in_progress, durable_binding_stable); + exact_live = cluster_cr_server_live_binding_exact( + xid_is_mine, expected_segment_id, expected_tt_slot_id, matched_segment, + matched_slot, xid_is_in_progress, durable_binding_stable); } switch (cluster_cr_server_resolved_scn_verdict(did_commit, did_abort, exact_live)) { @@ -2818,8 +2743,7 @@ lms_resolve_own_xid_verdict_observed(TransactionId xid, uint32 expected_segment_ */ if (allow_live && expected_segment_id > 0 && expected_segment_id <= UINT16_MAX && expected_tt_slot_id >= 1 && expected_tt_slot_id <= TT_SLOTS_PER_SEGMENT) { - volatile ClusterUndoVerdictKind c0_verdict - = CLUSTER_UNDO_VERDICT_UNKNOWN_FAIL_CLOSED; + volatile ClusterUndoVerdictKind c0_verdict = CLUSTER_UNDO_VERDICT_UNKNOWN_FAIL_CLOSED; volatile bool c0_hard_refuse = false; PG_TRY(c0_window); @@ -2861,8 +2785,7 @@ lms_resolve_own_xid_verdict_observed(TransactionId xid, uint32 expected_segment_ allow_live, xid_is_mine, expected_segment_id, expected_tt_slot_id, no_raw_reuse_window, clog_is_committed, clog_is_aborted, clog_is_in_progress, xid_is_in_progress); - if (clog_sampled - && c0_verdict == CLUSTER_UNDO_VERDICT_UNKNOWN_FAIL_CLOSED + if (clog_sampled && c0_verdict == CLUSTER_UNDO_VERDICT_UNKNOWN_FAIL_CLOSED && !clog_is_committed) c0_hard_refuse = true; } @@ -2984,16 +2907,15 @@ cluster_cr_server_test_ordinary_reason(TransactionId xid, uint32 segment_hint, /* Execute the real static resolver from the focused C0 fixture. */ ClusterUndoVerdictKind cluster_cr_server_test_own_xid_verdict(TransactionId xid, uint32 expected_segment_id, - uint32 expected_tt_slot_id, bool authoritative) + uint32 expected_tt_slot_id, bool authoritative) { uint8 verdict = 0; SCN commit_scn = InvalidScn; SCN horizon_scn = InvalidScn; uint16 wrap = 0; - (void)lms_resolve_own_xid_verdict(xid, expected_segment_id, expected_tt_slot_id, - authoritative, &verdict, &commit_scn, &horizon_scn, - &wrap); + (void)lms_resolve_own_xid_verdict(xid, expected_segment_id, expected_tt_slot_id, authoritative, + &verdict, &commit_scn, &horizon_scn, &wrap); switch (verdict) { case CLUSTER_GCS_UNDO_VERDICT_COMMITTED_EXACT: return CLUSTER_UNDO_VERDICT_COMMITTED_EXACT; @@ -3009,15 +2931,11 @@ cluster_cr_server_test_own_xid_verdict(TransactionId xid, uint32 expected_segmen } ClusterUndoVerdictResult -cluster_cr_server_test_own_xid_pair_verdict(TransactionId xid, - uint32 expected_segment_id, - uint32 expected_tt_slot_id, - SCN proposed_scn) +cluster_cr_server_test_own_xid_pair_verdict(TransactionId xid, uint32 expected_segment_id, + uint32 expected_tt_slot_id, SCN proposed_scn) { ClusterUndoVerdictResult result - = { .kind = CLUSTER_UNDO_VERDICT_UNKNOWN_FAIL_CLOSED, - .commit_scn = InvalidScn, - .wrap = 0 }; + = { .kind = CLUSTER_UNDO_VERDICT_UNKNOWN_FAIL_CLOSED, .commit_scn = InvalidScn, .wrap = 0 }; uint8 verdict = 0; SCN commit_scn = InvalidScn; SCN horizon_scn = InvalidScn; @@ -3210,8 +3128,7 @@ lms_undo_verdict_serve(ClusterLmsCrSlot *slot) if (freshref_pair && (!slot->undo_authoritative || slot->undo_owner != -1 || slot->epoch != cluster_epoch_get_current() - || !GcsBlockUndoFreshRefC1bTagDecode( - slot->tag, &pair_segment, &pair_xid, &pair_slot) + || !GcsBlockUndoFreshRefC1bTagDecode(slot->tag, &pair_segment, &pair_xid, &pair_slot) || pair_segment != slot->undo_segment_id || pair_xid != xid || pair_slot != slot->undo_block_no)) { cluster_vis53r97_note_srv_other(); @@ -3236,8 +3153,7 @@ lms_undo_verdict_serve(ClusterLmsCrSlot *slot) * while an ordinary current R4 TARGET token continuously covers the * origin proof. Non-zero rounds retain their existing epoch binding. */ if (zero_epoch_pair) { - if (!cluster_runtime_visibility_zero_epoch_pair_admission_enter( - &zero_epoch_admission)) { + if (!cluster_runtime_visibility_zero_epoch_pair_admission_enter(&zero_epoch_admission)) { cluster_vis53r97_note_srv_other(); lms_freshref_pair_log_refusal(slot, "ENTRY", "ZERO_EPOCH_ADMISSION", NULL); return false; @@ -3246,15 +3162,12 @@ lms_undo_verdict_serve(ClusterLmsCrSlot *slot) { slot->undo_auth.origin_epoch = cluster_epoch_get_current(); slot->undo_auth.live_hwm_lsn = GetFlushRecPtr(NULL); - slot->undo_auth.tt_generation - = cluster_undo_tt_retention_rollover_count(); + slot->undo_auth.tt_generation = cluster_undo_tt_retention_rollover_count(); slot->undo_auth.authority_scn = cluster_scn_current(); reason = lms_resolve_own_xid_freshref_c1b_pair( xid, slot->undo_segment_id, slot->undo_block_no, slot->read_scn, &verdict, &commit_scn, &horizon_scn, &wrap, &pair_diagnostic); - zero_epoch_current - = cluster_semantic_activation_recheck( - &zero_epoch_admission); + zero_epoch_current = cluster_semantic_activation_recheck(&zero_epoch_admission); } PG_FINALLY(); { @@ -3270,8 +3183,7 @@ lms_undo_verdict_serve(ClusterLmsCrSlot *slot) /* Co-sample the authority triple BEFORE the scan (see banner). */ slot->undo_auth.origin_epoch = cluster_epoch_get_current(); slot->undo_auth.live_hwm_lsn = GetFlushRecPtr(NULL); - slot->undo_auth.tt_generation - = cluster_undo_tt_retention_rollover_count(); + slot->undo_auth.tt_generation = cluster_undo_tt_retention_rollover_count(); /* PGRAC: spec-7.1a D3 -- co-sample the origin SCN clock with the same * pre-content-read ordering (a stamp landing after the sample only makes * the content newer than claimed; additive and safe). */ @@ -3883,8 +3795,7 @@ cluster_lms_cr_drain(void) uint32 state = pg_atomic_read_u32(&slot->state); if (state == CLUSTER_LMS_CR_R4_QUEUED) { - if (cr_server_r4_claim_queued((uint32)i) - && cr_server_r4_build_step((uint32)i)) + if (cr_server_r4_claim_queued((uint32)i) && cr_server_r4_build_step((uint32)i)) (void)cr_server_r4_ship_terminal((uint32)i); continue; } @@ -3899,10 +3810,8 @@ cluster_lms_cr_drain(void) } if (state == CLUSTER_LMS_CR_R4_UNDO_INFLIGHT) continue; - if (state == CLUSTER_LMS_CR_R4_READY_FULL - || state == CLUSTER_LMS_CR_R4_READY_RETRY - || state == CLUSTER_LMS_CR_R4_READY_FAIL - || state == CLUSTER_LMS_CR_R4_CANCELLED) { + if (state == CLUSTER_LMS_CR_R4_READY_FULL || state == CLUSTER_LMS_CR_R4_READY_RETRY + || state == CLUSTER_LMS_CR_R4_READY_FAIL || state == CLUSTER_LMS_CR_R4_CANCELLED) { (void)cr_server_r4_ship_terminal((uint32)i); } } @@ -3914,9 +3823,7 @@ cluster_lms_cr_drain(void) * keeps the four fixed slots fair without adding shared protocol state. */ for (i = 0; i < CLUSTER_LMS_CR_SLOTS; i++) { - uint32 slot_index - = (cluster_lms_cr_legacy_drain_cursor + (uint32)i) - % CLUSTER_LMS_CR_SLOTS; + uint32 slot_index = (cluster_lms_cr_legacy_drain_cursor + (uint32)i) % CLUSTER_LMS_CR_SLOTS; ClusterLmsCrSlot *slot = &CrServerShared->slots[slot_index]; uint32 expected = CLUSTER_LMS_CR_PENDING; @@ -3982,10 +3889,10 @@ cr_serve_scratch_context(void) } static ClusterMxDescribeResult -cr_current_mx_build_describe_page( - uint16 source_node_id, uint64 request_id, const ClusterCurrentMxKey *key, - const MultiXactMember *native_members, int native_count, - ClusterCurrentMxDescribeReplyPage *page) +cr_current_mx_build_describe_page(uint16 source_node_id, uint64 request_id, + const ClusterCurrentMxKey *key, + const MultiXactMember *native_members, int native_count, + ClusterCurrentMxDescribeReplyPage *page) { ClusterMxDescribeResult result = CMX_DESC_DENIED; int i; @@ -4018,20 +3925,17 @@ cr_current_mx_build_describe_page( page->members[i].xid = native_members[i].xid; page->members[i].member_status = (uint8)native_members[i].status; } - if (cluster_multixact_current_validate_descriptor( - key, source_node_id, key->cluster_epoch, page->members, - (uint16)native_count, (uint32)native_count) + if (cluster_multixact_current_validate_descriptor(key, source_node_id, key->cluster_epoch, + page->members, (uint16)native_count, + (uint32)native_count) == CMX_DESC_OK) { page->header.descriptor_hash - = cluster_multixact_current_descriptor_hash( - key, page->members, (uint16)native_count); + = cluster_multixact_current_descriptor_hash(key, page->members, (uint16)native_count); if (page->header.descriptor_hash != 0) { page->header.total_count = (uint32)native_count; page->header.entry_count = (uint16)native_count; page->header.wire_length - = sizeof(page->header) - + (uint16)native_count - * sizeof(ClusterCurrentMxMemberDesc); + = sizeof(page->header) + (uint16)native_count * sizeof(ClusterCurrentMxMemberDesc); page->header.result = (uint8)CMX_DESC_OK; result = CMX_DESC_OK; } @@ -4050,17 +3954,15 @@ ClusterMxResolveResult cluster_cr_server_current_mx_build_proof_page( uint16 source_node_id, const ClusterCurrentMxProofForwardV2 *request, ClusterMxResolveResult result, uint32 requester_capability_generation, - const ClusterCurrentMemberProof *proofs, - uint16 proof_count, const ClusterCurrentUpdaterProof *updater_proof, - ClusterCurrentMxProofReplyPage *page) + const ClusterCurrentMemberProof *proofs, uint16 proof_count, + const ClusterCurrentUpdaterProof *updater_proof, ClusterCurrentMxProofReplyPage *page) { Size wire_length; if (page == NULL) return CMX_RESOLVE_UNKNOWN; memset(page, 0, sizeof(*page)); - if (request == NULL || request->prefix.request_id == 0 - || source_node_id >= CLUSTER_MAX_NODES) + if (request == NULL || request->prefix.request_id == 0 || source_node_id >= CLUSTER_MAX_NODES) return CMX_RESOLVE_UNKNOWN; page->header.magic = CLUSTER_CURRENT_MX_WIRE_MAGIC; @@ -4071,12 +3973,10 @@ cluster_cr_server_current_mx_build_proof_page( page->header.source_node_id = source_node_id; page->header.request_id = request->prefix.request_id; page->header.mxkey = request->prefix.mxkey; - page->header.descriptor_hash - = ClusterCurrentMxProofPrefixGetDescriptorHash(&request->prefix); + page->header.descriptor_hash = ClusterCurrentMxProofPrefixGetDescriptorHash(&request->prefix); page->header.total_count = request->prefix.total_count; page->header.chunk_ordinal = request->prefix.chunk_ordinal; - page->header.chunk_count_minus_one - = request->prefix.chunk_count_minus_one; + page->header.chunk_count_minus_one = request->prefix.chunk_count_minus_one; page->header.wire_length = sizeof(page->header); if (result == CMX_RESOLVE_TIMEOUT || result > CMX_RESOLVE_RETRY) @@ -4093,8 +3993,7 @@ cluster_cr_server_current_mx_build_proof_page( switch ((ClusterCurrentMxProofBodyKind)request->prefix.body_kind) { case CLUSTER_CURRENT_MX_PROOF_BODY_MEMBER_ASKS: - if (proof_count == 0 - || proof_count > CLUSTER_CURRENT_MX_MAX_PROOF_ASKS_PER_FRAME) + if (proof_count == 0 || proof_count > CLUSTER_CURRENT_MX_MAX_PROOF_ASKS_PER_FRAME) return CMX_RESOLVE_UNKNOWN; memcpy(page->body.proofs, proofs, sizeof(*proofs) * proof_count); wire_length = sizeof(page->header) + sizeof(*proofs) * proof_count; @@ -4104,16 +4003,14 @@ cluster_cr_server_current_mx_build_proof_page( return CMX_RESOLVE_UNKNOWN; page->body.updater.member_proof = proofs[0]; page->body.updater.updater_proof = *updater_proof; - wire_length = sizeof(page->header) + sizeof(proofs[0]) - + sizeof(*updater_proof); + wire_length = sizeof(page->header) + sizeof(proofs[0]) + sizeof(*updater_proof); break; default: return CMX_RESOLVE_UNKNOWN; } page->header.entry_count = proof_count; - page->header.requester_capability_generation - = requester_capability_generation; + page->header.requester_capability_generation = requester_capability_generation; page->header.wire_length = (uint16)wire_length; page->header.result = (uint8)CMX_RESOLVE_OK; return CMX_RESOLVE_OK; @@ -4121,27 +4018,26 @@ cluster_cr_server_current_mx_build_proof_page( #ifdef USE_CLUSTER_UNIT ClusterMxDescribeResult -cluster_cr_server_test_current_mx_build_describe_page( - uint16 source_node_id, uint64 request_id, const ClusterCurrentMxKey *key, - const MultiXactMember *native_members, int native_count, - ClusterCurrentMxDescribeReplyPage *page) +cluster_cr_server_test_current_mx_build_describe_page(uint16 source_node_id, uint64 request_id, + const ClusterCurrentMxKey *key, + const MultiXactMember *native_members, + int native_count, + ClusterCurrentMxDescribeReplyPage *page) { - return cr_current_mx_build_describe_page( - source_node_id, request_id, key, native_members, native_count, page); + return cr_current_mx_build_describe_page(source_node_id, request_id, key, native_members, + native_count, page); } ClusterMxResolveResult cluster_cr_server_test_current_mx_build_proof_page( uint16 source_node_id, const ClusterCurrentMxProofForwardV2 *request, ClusterMxResolveResult result, uint32 requester_capability_generation, - const ClusterCurrentMemberProof *proofs, - uint16 proof_count, const ClusterCurrentUpdaterProof *updater_proof, - ClusterCurrentMxProofReplyPage *page) + const ClusterCurrentMemberProof *proofs, uint16 proof_count, + const ClusterCurrentUpdaterProof *updater_proof, ClusterCurrentMxProofReplyPage *page) { - return cluster_cr_server_current_mx_build_proof_page( - source_node_id, request, result, requester_capability_generation, - proofs, proof_count, - updater_proof, page); + return cluster_cr_server_current_mx_build_proof_page(source_node_id, request, result, + requester_capability_generation, proofs, + proof_count, updater_proof, page); } #endif @@ -4149,8 +4045,7 @@ cluster_cr_server_test_current_mx_build_proof_page( * returns one typed page. Every validation, fence or connection doubt is a * DENIED page or a dropped send; native pg_multixact bytes never leave. */ void -cluster_gcs_current_mx_describe_serve_inline( - const ClusterICEnvelope *env, const void *payload) +cluster_gcs_current_mx_describe_serve_inline(const ClusterICEnvelope *env, const void *payload) { ClusterCurrentMxDescribeForwardV2 request; BufferTag route_tag; @@ -4159,27 +4054,23 @@ cluster_gcs_current_mx_describe_serve_inline( int recv_worker; int expected_worker; uint32 capability_generation = 0; - uint32 reply_total - = (uint32)sizeof(GcsBlockReplyHeader) + GCS_BLOCK_DATA_SIZE; + uint32 reply_total = (uint32)sizeof(GcsBlockReplyHeader) + GCS_BLOCK_DATA_SIZE; char *reply; GcsBlockReplyHeader *outer; ClusterCurrentMxDescribeReplyPage *page; MemoryContext old_context; - if (env == NULL || payload == NULL - || env->dest_node_id != (uint32)cluster_node_id + if (env == NULL || payload == NULL || env->dest_node_id != (uint32)cluster_node_id || !cluster_gcs_block_family_on_data_plane() || !cluster_multixact_current_wire_validate_describe_forward( - payload, env->payload_length, (int32)env->source_node_id, - cluster_node_id, cluster_epoch_get_current(), &request)) + payload, env->payload_length, (int32)env->source_node_id, cluster_node_id, + cluster_epoch_get_current(), &request)) return; - route_tag = GcsBlockCurrentMxRouteTagMake( - request.prefix.request_id, request.prefix.epoch, - request.prefix.original_requester_node, - request.prefix.requester_backend_id); + route_tag = GcsBlockCurrentMxRouteTagMake(request.prefix.request_id, request.prefix.epoch, + request.prefix.original_requester_node, + request.prefix.requester_backend_id); recv_worker = cluster_ic_tier1_my_data_channel(); - expected_worker = cluster_lms_shard_for_tag( - &route_tag, cluster_lms_workers); + expected_worker = cluster_lms_shard_for_tag(&route_tag, cluster_lms_workers); Assert(expected_worker == recv_worker); if (expected_worker != recv_worker) return; @@ -4190,20 +4081,18 @@ cluster_gcs_current_mx_describe_serve_inline( reply = (char *)palloc0(reply_total); outer = (GcsBlockReplyHeader *)reply; page = (ClusterCurrentMxDescribeReplyPage *)(reply + sizeof(*outer)); - (void)cr_current_mx_build_describe_page( - (uint16)cluster_node_id, request.prefix.request_id, - &request.prefix.mxkey, NULL, -1, page); + (void)cr_current_mx_build_describe_page((uint16)cluster_node_id, request.prefix.request_id, + &request.prefix.mxkey, NULL, -1, page); if ((!cluster_write_fence_enforcing() || cluster_write_fence_allowed()) && cluster_mxid_is_mine(request.prefix.mxkey.multixact_id)) { PG_TRY(); { - native_count = GetMultiXactIdMembers( - request.prefix.mxkey.multixact_id, &native_members, - false, false); + native_count = GetMultiXactIdMembers(request.prefix.mxkey.multixact_id, &native_members, + false, false); (void)cr_current_mx_build_describe_page( - (uint16)cluster_node_id, request.prefix.request_id, - &request.prefix.mxkey, native_members, native_count, page); + (uint16)cluster_node_id, request.prefix.request_id, &request.prefix.mxkey, + native_members, native_count, page); if (native_members != NULL) { pfree(native_members); native_members = NULL; @@ -4213,9 +4102,9 @@ cluster_gcs_current_mx_describe_serve_inline( { MemoryContextSwitchTo(cr_serve_scratch_context()); FlushErrorState(); - (void)cr_current_mx_build_describe_page( - (uint16)cluster_node_id, request.prefix.request_id, - &request.prefix.mxkey, NULL, -1, page); + (void)cr_current_mx_build_describe_page((uint16)cluster_node_id, + request.prefix.request_id, + &request.prefix.mxkey, NULL, -1, page); } PG_END_TRY(); } @@ -4223,34 +4112,26 @@ cluster_gcs_current_mx_describe_serve_inline( /* Positive bytes sampled before an epoch/fence transition are not * publishable. */ if (cluster_epoch_get_current() != request.prefix.epoch - || (cluster_write_fence_enforcing() - && !cluster_write_fence_allowed())) - (void)cr_current_mx_build_describe_page( - (uint16)cluster_node_id, request.prefix.request_id, - &request.prefix.mxkey, NULL, -1, page); + || (cluster_write_fence_enforcing() && !cluster_write_fence_allowed())) + (void)cr_current_mx_build_describe_page((uint16)cluster_node_id, request.prefix.request_id, + &request.prefix.mxkey, NULL, -1, page); outer->request_id = request.prefix.request_id; outer->epoch = request.prefix.epoch; outer->sender_node = cluster_node_id; outer->requester_backend_id = request.prefix.requester_backend_id; outer->transition_id = 0; - outer->status - = (uint8)GCS_BLOCK_REPLY_CURRENT_MX_DESCRIBE_RESULT; - GcsBlockReplyHeaderSetForwardingMasterNode( - outer, GCS_BLOCK_REPLY_NO_FORWARDING_MASTER); - outer->checksum - = cluster_gcs_block_compute_checksum((const char *)page); + outer->status = (uint8)GCS_BLOCK_REPLY_CURRENT_MX_DESCRIBE_RESULT; + GcsBlockReplyHeaderSetForwardingMasterNode(outer, GCS_BLOCK_REPLY_NO_FORWARDING_MASTER); + outer->checksum = cluster_gcs_block_compute_checksum((const char *)page); if (cluster_sf_peer_multixact_current_capability_generation( - request.prefix.original_requester_node, - &capability_generation) - && cluster_sf_peer_capability_generation_matches( - request.prefix.original_requester_node, - PGRAC_IC_HELLO_CAP_MULTIXACT_CURRENT_V1, - capability_generation)) - (void)cluster_ic_send_envelope( - PGRAC_IC_MSG_GCS_BLOCK_REPLY, - request.prefix.original_requester_node, reply, reply_total); + request.prefix.original_requester_node, &capability_generation) + && cluster_sf_peer_capability_generation_matches(request.prefix.original_requester_node, + PGRAC_IC_HELLO_CAP_MULTIXACT_CURRENT_V1, + capability_generation)) + (void)cluster_ic_send_envelope(PGRAC_IC_MSG_GCS_BLOCK_REPLY, + request.prefix.original_requester_node, reply, reply_total); MemoryContextSwitchTo(old_context); MemoryContextReset(CrServeScratchCtx); } @@ -4261,8 +4142,7 @@ cluster_gcs_current_mx_describe_serve_inline( * admitted to that existing event-loop context; it never consults SOURCE or * synthesizes a positive proof. */ void -cluster_gcs_current_mx_member_proof_serve_inline( - const ClusterICEnvelope *env, const void *payload) +cluster_gcs_current_mx_member_proof_serve_inline(const ClusterICEnvelope *env, const void *payload) { ClusterCurrentMxProofForwardV2 request; ClusterMxResolveResult proof_result = CMX_RESOLVE_UNKNOWN; @@ -4270,28 +4150,24 @@ cluster_gcs_current_mx_member_proof_serve_inline( int recv_worker; int expected_worker; uint32 capability_generation = 0; - uint32 reply_total - = (uint32)sizeof(GcsBlockReplyHeader) + GCS_BLOCK_DATA_SIZE; + uint32 reply_total = (uint32)sizeof(GcsBlockReplyHeader) + GCS_BLOCK_DATA_SIZE; char *reply; GcsBlockReplyHeader *outer; ClusterCurrentMxProofReplyPage *page; MemoryContext old_context; - if (env == NULL || payload == NULL - || env->dest_node_id != (uint32)cluster_node_id + if (env == NULL || payload == NULL || env->dest_node_id != (uint32)cluster_node_id || !cluster_gcs_block_family_on_data_plane() || !cluster_multixact_current_wire_validate_proof_forward( - payload, env->payload_length, (int32)env->source_node_id, - cluster_node_id, cluster_epoch_get_current(), &request)) + payload, env->payload_length, (int32)env->source_node_id, cluster_node_id, + cluster_epoch_get_current(), &request)) return; - route_tag = GcsBlockCurrentMxRouteTagMake( - request.prefix.request_id, request.prefix.epoch, - request.prefix.original_requester_node, - request.prefix.requester_backend_id); + route_tag = GcsBlockCurrentMxRouteTagMake(request.prefix.request_id, request.prefix.epoch, + request.prefix.original_requester_node, + request.prefix.requester_backend_id); recv_worker = cluster_ic_tier1_my_data_channel(); - expected_worker = cluster_lms_shard_for_tag( - &route_tag, cluster_lms_workers); + expected_worker = cluster_lms_shard_for_tag(&route_tag, cluster_lms_workers); Assert(expected_worker == recv_worker); if (expected_worker != recv_worker) return; @@ -4302,22 +4178,18 @@ cluster_gcs_current_mx_member_proof_serve_inline( reply = (char *)palloc0(reply_total); outer = (GcsBlockReplyHeader *)reply; page = (ClusterCurrentMxProofReplyPage *)(reply + sizeof(*outer)); - if (cluster_write_fence_enforcing() - && !cluster_write_fence_allowed()) + if (cluster_write_fence_enforcing() && !cluster_write_fence_allowed()) proof_result = CMX_RESOLVE_DENIED; if (cluster_epoch_get_current() != request.prefix.epoch - || (cluster_write_fence_enforcing() - && !cluster_write_fence_allowed())) + || (cluster_write_fence_enforcing() && !cluster_write_fence_allowed())) proof_result = CMX_RESOLVE_DENIED; - if (cluster_cr_server_current_mx_build_proof_page( - (uint16)cluster_node_id, &request, proof_result, 0, NULL, - 0, NULL, page) + if (cluster_cr_server_current_mx_build_proof_page((uint16)cluster_node_id, &request, + proof_result, 0, NULL, 0, NULL, page) != proof_result) { proof_result = CMX_RESOLVE_UNKNOWN; - (void)cluster_cr_server_current_mx_build_proof_page( - (uint16)cluster_node_id, &request, proof_result, 0, NULL, 0, - NULL, page); + (void)cluster_cr_server_current_mx_build_proof_page((uint16)cluster_node_id, &request, + proof_result, 0, NULL, 0, NULL, page); } outer->request_id = request.prefix.request_id; @@ -4325,23 +4197,17 @@ cluster_gcs_current_mx_member_proof_serve_inline( outer->sender_node = cluster_node_id; outer->requester_backend_id = request.prefix.requester_backend_id; outer->transition_id = 0; - outer->status - = (uint8)GCS_BLOCK_REPLY_CURRENT_MX_MEMBER_PROOF_RESULT; - GcsBlockReplyHeaderSetForwardingMasterNode( - outer, GCS_BLOCK_REPLY_NO_FORWARDING_MASTER); - outer->checksum - = cluster_gcs_block_compute_checksum((const char *)page); + outer->status = (uint8)GCS_BLOCK_REPLY_CURRENT_MX_MEMBER_PROOF_RESULT; + GcsBlockReplyHeaderSetForwardingMasterNode(outer, GCS_BLOCK_REPLY_NO_FORWARDING_MASTER); + outer->checksum = cluster_gcs_block_compute_checksum((const char *)page); if (cluster_sf_peer_multixact_current_capability_generation( - request.prefix.original_requester_node, - &capability_generation) - && cluster_sf_peer_capability_generation_matches( - request.prefix.original_requester_node, - PGRAC_IC_HELLO_CAP_MULTIXACT_CURRENT_V1, - capability_generation)) - (void)cluster_ic_send_envelope( - PGRAC_IC_MSG_GCS_BLOCK_REPLY, - request.prefix.original_requester_node, reply, reply_total); + request.prefix.original_requester_node, &capability_generation) + && cluster_sf_peer_capability_generation_matches(request.prefix.original_requester_node, + PGRAC_IC_HELLO_CAP_MULTIXACT_CURRENT_V1, + capability_generation)) + (void)cluster_ic_send_envelope(PGRAC_IC_MSG_GCS_BLOCK_REPLY, + request.prefix.original_requester_node, reply, reply_total); MemoryContextSwitchTo(old_context); MemoryContextReset(CrServeScratchCtx); } @@ -4479,15 +4345,13 @@ cluster_gcs_block_forward_serve_inline(const GcsBlockForwardPayload *fwd, Cluste case CLUSTER_LMS_SLOT_KIND_UNDO_VERDICT: { uint64 carrier = (uint64)GcsBlockForwardPayloadGetExpectedPiWatermarkScn(fwd); - bool freshref_pair - = GcsBlockForwardPayloadIsUndoFreshRefC1bPairRequest(fwd); + bool freshref_pair = GcsBlockForwardPayloadIsUndoFreshRefC1bPairRequest(fwd); slot.read_scn = InvalidScn; if (freshref_pair) { if (cluster_cr_server_freshref_c1b_pair_request_decode( - fwd, fwd->original_requester_node, cluster_node_id, - cluster_epoch_get_current(), MaxBackends, &segment_id, - &pair_xid, &block_no, &pair_scn)) { + fwd, fwd->original_requester_node, cluster_node_id, cluster_epoch_get_current(), + MaxBackends, &segment_id, &pair_xid, &block_no, &pair_scn)) { slot.read_scn = pair_scn; slot.undo_xid = pair_xid; } else @@ -4496,11 +4360,10 @@ cluster_gcs_block_forward_serve_inline(const GcsBlockForwardPayload *fwd, Cluste (void)GcsBlockUndoFetchTagDecode(fwd->tag, &segment_id, &block_no); /* A malformed carrier (upper 32 bits set / non-normal) leaves xid * Invalid -> lms_undo_verdict_serve refuses. */ - slot.undo_xid - = (carrier <= (uint64)PG_UINT32_MAX - && TransactionIdIsNormal((TransactionId)carrier)) - ? (TransactionId)carrier - : InvalidTransactionId; + slot.undo_xid = (carrier <= (uint64)PG_UINT32_MAX + && TransactionIdIsNormal((TransactionId)carrier)) + ? (TransactionId)carrier + : InvalidTransactionId; } slot.undo_segment_id = segment_id; slot.undo_block_no = block_no; diff --git a/src/backend/cluster/cluster_cr_server_policy.c b/src/backend/cluster/cluster_cr_server_policy.c index 19cf437a0f8..5f569afac7f 100644 --- a/src/backend/cluster/cluster_cr_server_policy.c +++ b/src/backend/cluster/cluster_cr_server_policy.c @@ -107,8 +107,7 @@ cluster_cr_server_live_binding_exact(bool xid_is_mine, uint32 expected_segment_i ClusterUndoVerdictKind cluster_cr_server_c0_zero_match_verdict(bool authoritative, bool xid_is_mine, - uint32 expected_segment_id, - uint32 expected_tt_slot_id, + uint32 expected_segment_id, uint32 expected_tt_slot_id, bool no_raw_reuse_window, bool clog_is_committed, bool clog_is_aborted, bool clog_is_in_progress, bool xid_is_in_progress) @@ -121,8 +120,7 @@ cluster_cr_server_c0_zero_match_verdict(bool authoritative, bool xid_is_mine, return CLUSTER_UNDO_VERDICT_UNKNOWN_FAIL_CLOSED; raw_status_count - = (clog_is_committed ? 1 : 0) + (clog_is_aborted ? 1 : 0) - + (clog_is_in_progress ? 1 : 0); + = (clog_is_committed ? 1 : 0) + (clog_is_aborted ? 1 : 0) + (clog_is_in_progress ? 1 : 0); if (raw_status_count != 1 || clog_is_committed) return CLUSTER_UNDO_VERDICT_UNKNOWN_FAIL_CLOSED; if (clog_is_aborted) @@ -134,11 +132,12 @@ cluster_cr_server_c0_zero_match_verdict(bool authoritative, bool xid_is_mine, } ClusterUndoVerdictKind -cluster_cr_server_freshref_c1b_pair_verdict( - bool pair_request, bool xid_is_mine, uint32 expected_segment_id, - uint32 expected_tt_slot_id, bool no_raw_reuse_window, int raw_clog_status, - ClusterTTDurableResolve resolve, uint16 matched_segment, uint16 matched_slot, - SCN resolved_scn, SCN proposed_scn, bool retention_ok, SCN horizon_scn) +cluster_cr_server_freshref_c1b_pair_verdict(bool pair_request, bool xid_is_mine, + uint32 expected_segment_id, uint32 expected_tt_slot_id, + bool no_raw_reuse_window, int raw_clog_status, + ClusterTTDurableResolve resolve, uint16 matched_segment, + uint16 matched_slot, SCN resolved_scn, SCN proposed_scn, + bool retention_ok, SCN horizon_scn) { if (!pair_request || !xid_is_mine || expected_segment_id == 0 || expected_segment_id > UINT16_MAX || expected_tt_slot_id < 1 @@ -149,8 +148,8 @@ cluster_cr_server_freshref_c1b_pair_verdict( switch (resolve) { case CLUSTER_TT_DURABLE_RESOLVED_SCN: if ((uint32)matched_segment == expected_segment_id - && (uint32)matched_slot + 1 == expected_tt_slot_id - && SCN_VALID(resolved_scn) && resolved_scn == proposed_scn) + && (uint32)matched_slot + 1 == expected_tt_slot_id && SCN_VALID(resolved_scn) + && resolved_scn == proposed_scn) return CLUSTER_UNDO_VERDICT_COMMITTED_EXACT; break; case CLUSTER_TT_DURABLE_RECYCLED_ZERO_MATCH: @@ -170,11 +169,12 @@ cluster_cr_server_freshref_c1b_pair_verdict( } bool -cluster_cr_server_freshref_c1b_pair_request_decode( - const GcsBlockForwardPayload *fwd, int32 authenticated_source_node, - int32 local_node, uint64 current_epoch, int max_backends, - uint32 *segment_id, TransactionId *xid, uint32 *expected_tt_slot_id, - SCN *proposed_scn) +cluster_cr_server_freshref_c1b_pair_request_decode(const GcsBlockForwardPayload *fwd, + int32 authenticated_source_node, + int32 local_node, uint64 current_epoch, + int max_backends, uint32 *segment_id, + TransactionId *xid, uint32 *expected_tt_slot_id, + SCN *proposed_scn) { uint32 decoded_segment = 0; uint32 decoded_slot = 0; @@ -183,22 +183,18 @@ cluster_cr_server_freshref_c1b_pair_request_decode( int i; if (fwd == NULL || !GcsBlockForwardPayloadIsUndoFreshRefC1bPairRequest(fwd) - || fwd->request_id == 0 || fwd->epoch != current_epoch - || authenticated_source_node < 0 - || authenticated_source_node >= CLUSTER_MAX_NODES - || local_node < 0 || local_node >= CLUSTER_MAX_NODES - || authenticated_source_node == local_node + || fwd->request_id == 0 || fwd->epoch != current_epoch || authenticated_source_node < 0 + || authenticated_source_node >= CLUSTER_MAX_NODES || local_node < 0 + || local_node >= CLUSTER_MAX_NODES || authenticated_source_node == local_node || fwd->original_requester_node != authenticated_source_node - || fwd->master_node != authenticated_source_node - || max_backends <= 0 || fwd->requester_backend_id <= 0 - || fwd->requester_backend_id > max_backends + || fwd->master_node != authenticated_source_node || max_backends <= 0 + || fwd->requester_backend_id <= 0 || fwd->requester_backend_id > max_backends || fwd->transition_id != (uint8)PCM_TRANS_N_TO_S) return false; for (i = 0; i < 6; i++) if (fwd->reserved_0[i] != 0) return false; - if (!GcsBlockUndoFreshRefC1bTagDecode( - fwd->tag, &decoded_segment, &decoded_xid, &decoded_slot)) + if (!GcsBlockUndoFreshRefC1bTagDecode(fwd->tag, &decoded_segment, &decoded_xid, &decoded_slot)) return false; decoded_scn = GcsBlockForwardPayloadGetExpectedPiWatermarkScn(fwd); if (!SCN_VALID(decoded_scn)) diff --git a/src/backend/cluster/cluster_cssd.c b/src/backend/cluster/cluster_cssd.c index 28c47a9596e..8818cd7f6dc 100644 --- a/src/backend/cluster/cluster_cssd.c +++ b/src/backend/cluster/cluster_cssd.c @@ -987,7 +987,6 @@ CssdMain(void) WAIT_EVENT_CLUSTER_BGPROC_CSSD_MAIN_LOOP); if (rc & WL_LATCH_SET) ResetLatch(MyLatch); - } } diff --git a/src/backend/cluster/cluster_debug.c b/src/backend/cluster/cluster_debug.c index 8bc2ce142e0..4423b5fdb32 100644 --- a/src/backend/cluster/cluster_debug.c +++ b/src/backend/cluster/cluster_debug.c @@ -82,8 +82,8 @@ PG_FUNCTION_INFO_V1(cluster_dump_state); #include "cluster/cluster_scn.h" /* cluster_scn_current (spec-1.15 D6) */ #include "cluster/cluster_ges.h" /* cluster_ges_{request,reply}_defer_count (spec-2.13 D4) */ #include "cluster/cluster_ges_reply_wait.h" /* spec-2.23 D13 reply wait counters */ -#include "cluster/cluster_grd.h" /* cluster_grd_* observability accessors (spec-2.14 D6) */ -#include "cluster/cluster_hw.h" /* HW relation-extend authority counters (spec-5.7 §3.1c) */ +#include "cluster/cluster_grd.h" /* cluster_grd_* observability accessors (spec-2.14 D6) */ +#include "cluster/cluster_hw.h" /* HW relation-extend authority counters (spec-5.7 §3.1c) */ #include "cluster/cluster_hw_snapshot.h" #include "cluster/cluster_dl.h" /* DL bulk-load lease counters (spec-5.7 D4) */ #include "cluster/cluster_ir.h" /* IR instance-recovery owner counters (spec-5.7 D8) */ @@ -95,17 +95,17 @@ PG_FUNCTION_INFO_V1(cluster_dump_state); #include "cluster/cluster_lmd_probe_collector.h" /* spec-5.8 D8 — probe collector counters */ #include "cluster/cluster_lms.h" /* cluster_lms_* observability accessors (spec-2.18 D10) */ #include "cluster/cluster_tt_slot.h" /* spec-3.12 D5 retention counters */ -#include "cluster/cluster_terminal_authority.h" /* spec-6.2 authority counters */ +#include "cluster/cluster_terminal_authority.h" /* spec-6.2 authority counters */ #include "cluster/cluster_terminal_ref_census.h" /* spec-8.4D CTRC */ -#include "cluster/cluster_sf_dep.h" /* spec-6.2 Smart Fusion dep counters */ +#include "cluster/cluster_sf_dep.h" /* spec-6.2 Smart Fusion dep counters */ #include "cluster/cluster_undo_record_api.h" /* cluster_undo_* counter accessors (spec-3.7 D10) */ #include "cluster/storage/cluster_undo_buf.h" /* spec-3.18 D7: undo buffer counters */ #include "cluster/cluster_cr.h" /* cluster_cr_* counter accessors (spec-3.9 D8) */ #include "cluster/cluster_r4_observe.h" -#include "cluster/cluster_cr_pool.h" /* cluster_cr_pool_* counters (spec-5.51 D9) */ -#include "cluster/cluster_cr_admit.h" /* cluster_cr_admit_stat_* counters (spec-5.52 D9) */ -#include "cluster/cluster_cr_tuple.h" /* cluster_cr_tuple_stat_* counters (spec-5.54 D5) */ -#include "cluster/cluster_xnode_profile.h" /* xnode profiling buckets (spec-5.59 D1) */ +#include "cluster/cluster_cr_pool.h" /* cluster_cr_pool_* counters (spec-5.51 D9) */ +#include "cluster/cluster_cr_admit.h" /* cluster_cr_admit_stat_* counters (spec-5.52 D9) */ +#include "cluster/cluster_cr_tuple.h" /* cluster_cr_tuple_stat_* counters (spec-5.54 D5) */ +#include "cluster/cluster_xnode_profile.h" /* xnode profiling buckets (spec-5.59 D1) */ #include "cluster/cluster_xnode_lever.h" #include "cluster/cluster_xid_stripe_boot.h" /* spec-6.15 D6 dump */ /* xnode lever counters (spec-6.12) */ #include "cluster/cluster_multixact.h" /* mxid stripe guardrail counters (spec-7.1 D3-a) */ @@ -140,23 +140,23 @@ PG_FUNCTION_INFO_V1(cluster_dump_state); #include "cluster/cluster_xid_authority.h" /* XID authority state (spec-6.15b D7) */ #include "cluster/cluster_remote_xact.h" /* remote outcome counters (spec-4.5a D11) */ #include "cluster/cluster_ic.h" /* ClusterICOps_Active, ClusterICTier */ -#include "cluster/cluster_ic_tier1.h" /* listener metadata accessors (Hardening v1.0.1 F3) */ -#include "cluster/cluster_scn.h" /* SCN typedef (stage 1.4) */ -#include "cluster/cluster_itl_slot.h" /* CLUSTER_ITL_* constants (stage 1.5) */ -#include "cluster/cluster_buffer_desc.h" /* BufferType / PcmState enums (stage 1.6) */ -#include "cluster/cluster_pcm_lock.h" /* PCM state-machine API + grd helpers */ +#include "cluster/cluster_ic_tier1.h" /* listener metadata accessors (Hardening v1.0.1 F3) */ +#include "cluster/cluster_scn.h" /* SCN typedef (stage 1.4) */ +#include "cluster/cluster_itl_slot.h" /* CLUSTER_ITL_* constants (stage 1.5) */ +#include "cluster/cluster_buffer_desc.h" /* BufferType / PcmState enums (stage 1.6) */ +#include "cluster/cluster_pcm_lock.h" /* PCM state-machine API + grd helpers */ #include "cluster/storage/cluster_undo_block0_current.h" #include "cluster/cluster_semantic_activation.h" /* R4 writer-path snapshot */ #include "cluster/cluster_resource_x_identity.h" /* Resource-X proof readiness */ -#include "cluster/cluster_gcs.h" /* GCS request protocol surface (spec-2.32 D8) */ -#include "cluster/cluster_gcs_block.h" /* GCS block-ship data plane (spec-2.33 D10) */ +#include "cluster/cluster_gcs.h" /* GCS request protocol surface (spec-2.32 D8) */ +#include "cluster/cluster_gcs_block.h" /* GCS block-ship data plane (spec-2.33 D10) */ #include "cluster/cluster_gcs_block_dedup.h" /* per-worker dedup-shard counters (spec-7.3 D5/D9) */ #include "cluster/cluster_sinval.h" /* SI Broadcaster counter accessors (spec-2.38 D10) */ #include "cluster/cluster_tt_status.h" /* TT status overlay counter accessors (spec-3.1 D9) */ #include "cluster/cluster_tt_status_hint.h" /* TT status hint counter accessors (spec-3.2 D8) */ #include "cluster/cluster_tx_enqueue.h" /* TX enqueue wait counters (spec-5.2 D4/D6) */ #include "cluster/cluster_multixact_current_stats.h" -#include "cluster/cluster_startup_phase.h" /* phase enum + accessors (stage 1.10) */ +#include "cluster/cluster_startup_phase.h" /* phase enum + accessors (stage 1.10) */ #include "storage/bufpage.h" /* PG_PAGE_LAYOUT_VERSION, SizeOfPageHeaderData (stage 1.4) */ #include "storage/buf_internals.h" /* BufferDesc layout (stage 1.6) */ #include "cluster/cluster_pgstat.h" @@ -1970,40 +1970,27 @@ dump_pcm(ReturnSetInfo *rsinfo) [CLUSTER_UNDO_BLOCK0_WAIT_BUDGET_REPOLL] = "block0_exact_reply_budget_repoll_count", }; static const char *const reclaim_refusal_keys[PCM_RETIRE_REFUSAL_N] = { - [PCM_RETIRE_REFUSAL_GATE_NOT_OPEN] - = "pcm_grd_reclaim_refused_gate_not_open_count", - [PCM_RETIRE_REFUSAL_IDENTITY_MISMATCH] - = "pcm_grd_reclaim_refused_identity_mismatch_count", + [PCM_RETIRE_REFUSAL_GATE_NOT_OPEN] = "pcm_grd_reclaim_refused_gate_not_open_count", + [PCM_RETIRE_REFUSAL_IDENTITY_MISMATCH] = "pcm_grd_reclaim_refused_identity_mismatch_count", [PCM_RETIRE_REFUSAL_LIFECYCLE_NOT_LIVE] - = "pcm_grd_reclaim_refused_lifecycle_not_live_count", - [PCM_RETIRE_REFUSAL_PINNED] - = "pcm_grd_reclaim_refused_pinned_count", - [PCM_RETIRE_REFUSAL_WAITER_PRESENT] - = "pcm_grd_reclaim_refused_waiter_present_count", - [PCM_RETIRE_REFUSAL_TRANSPORT_PRESENT] - = "pcm_grd_reclaim_refused_transport_present_count", - [PCM_RETIRE_REFUSAL_PCM_MODE_NOT_N] - = "pcm_grd_reclaim_refused_pcm_mode_not_n_count", - [PCM_RETIRE_REFUSAL_HOLDER_PRESENT] - = "pcm_grd_reclaim_refused_holder_present_count", - [PCM_RETIRE_REFUSAL_PI_PRESENT] - = "pcm_grd_reclaim_refused_pi_present_count", - [PCM_RETIRE_REFUSAL_WATERMARK_PRESENT] - = "pcm_grd_reclaim_refused_watermark_present_count", - [PCM_RETIRE_REFUSAL_CONVERT_PENDING] - = "pcm_grd_reclaim_refused_convert_pending_count", - [PCM_RETIRE_REFUSAL_RESOURCE_X_ACTIVE] - = "pcm_grd_reclaim_refused_resource_x_active_count", + = "pcm_grd_reclaim_refused_lifecycle_not_live_count", + [PCM_RETIRE_REFUSAL_PINNED] = "pcm_grd_reclaim_refused_pinned_count", + [PCM_RETIRE_REFUSAL_WAITER_PRESENT] = "pcm_grd_reclaim_refused_waiter_present_count", + [PCM_RETIRE_REFUSAL_TRANSPORT_PRESENT] = "pcm_grd_reclaim_refused_transport_present_count", + [PCM_RETIRE_REFUSAL_PCM_MODE_NOT_N] = "pcm_grd_reclaim_refused_pcm_mode_not_n_count", + [PCM_RETIRE_REFUSAL_HOLDER_PRESENT] = "pcm_grd_reclaim_refused_holder_present_count", + [PCM_RETIRE_REFUSAL_PI_PRESENT] = "pcm_grd_reclaim_refused_pi_present_count", + [PCM_RETIRE_REFUSAL_WATERMARK_PRESENT] = "pcm_grd_reclaim_refused_watermark_present_count", + [PCM_RETIRE_REFUSAL_CONVERT_PENDING] = "pcm_grd_reclaim_refused_convert_pending_count", + [PCM_RETIRE_REFUSAL_RESOURCE_X_ACTIVE] = "pcm_grd_reclaim_refused_resource_x_active_count", [PCM_RETIRE_REFUSAL_RETAINED_PAIR_PRESENT] - = "pcm_grd_reclaim_refused_retained_pair_present_count", + = "pcm_grd_reclaim_refused_retained_pair_present_count", [PCM_RETIRE_REFUSAL_REQUESTER_NOT_TERMINAL] - = "pcm_grd_reclaim_refused_requester_not_terminal_count", + = "pcm_grd_reclaim_refused_requester_not_terminal_count", [PCM_RETIRE_REFUSAL_SIDECAR_NOT_TERMINAL] - = "pcm_grd_reclaim_refused_sidecar_not_terminal_count", - [PCM_RETIRE_REFUSAL_FORMATION_STALE] - = "pcm_grd_reclaim_refused_formation_stale_count", - [PCM_RETIRE_REFUSAL_ENTRY_LOCK_BUSY] - = "pcm_grd_reclaim_refused_entry_lock_busy_count", + = "pcm_grd_reclaim_refused_sidecar_not_terminal_count", + [PCM_RETIRE_REFUSAL_FORMATION_STALE] = "pcm_grd_reclaim_refused_formation_stale_count", + [PCM_RETIRE_REFUSAL_ENTRY_LOCK_BUSY] = "pcm_grd_reclaim_refused_entry_lock_busy_count", }; PcmGrdLifecycleStats lifecycle; PcmGrdProtocolDebtStats protocol_debt; @@ -2052,43 +2039,37 @@ dump_pcm(ReturnSetInfo *rsinfo) fmt_int64((int64)cluster_pcm_grd_shmem_size())); emit_row(rsinfo, "pcm", "pcm_grd_active_entries", fmt_int32(cluster_pcm_grd_count())); cluster_pcm_grd_lifecycle_stats_snapshot(&lifecycle); - emit_row(rsinfo, "pcm", "pcm_grd_live_entries", - fmt_uint64(lifecycle.live_entries)); - emit_row(rsinfo, "pcm", "pcm_grd_tombstone_slots", - fmt_uint64(lifecycle.tombstone_slots)); - emit_row(rsinfo, "pcm", "pcm_grd_binding_generation", - fmt_uint64(lifecycle.binding_generation)); + emit_row(rsinfo, "pcm", "pcm_grd_live_entries", fmt_uint64(lifecycle.live_entries)); + emit_row(rsinfo, "pcm", "pcm_grd_tombstone_slots", fmt_uint64(lifecycle.tombstone_slots)); + emit_row(rsinfo, "pcm", "pcm_grd_binding_generation", fmt_uint64(lifecycle.binding_generation)); emit_row(rsinfo, "pcm", "pcm_grd_reclaim_attempt_count", - fmt_uint64(lifecycle.reclaim_attempt_count)); + fmt_uint64(lifecycle.reclaim_attempt_count)); emit_row(rsinfo, "pcm", "pcm_grd_reclaim_success_count", - fmt_uint64(lifecycle.reclaim_success_count)); + fmt_uint64(lifecycle.reclaim_success_count)); emit_row(rsinfo, "pcm", "pcm_grd_reclaim_reuse_count", - fmt_uint64(lifecycle.reclaim_reuse_count)); + fmt_uint64(lifecycle.reclaim_reuse_count)); emit_row(rsinfo, "pcm", "pcm_grd_capacity_retry_count", - fmt_uint64(lifecycle.capacity_retry_count)); + fmt_uint64(lifecycle.capacity_retry_count)); emit_row(rsinfo, "pcm", "pcm_grd_capacity_fail_count", - fmt_uint64(lifecycle.capacity_fail_count)); - emit_row(rsinfo, "pcm", "pcm_grd_peak_live_entries", - fmt_uint64(lifecycle.peak_live_entries)); + fmt_uint64(lifecycle.capacity_fail_count)); + emit_row(rsinfo, "pcm", "pcm_grd_peak_live_entries", fmt_uint64(lifecycle.peak_live_entries)); cluster_pcm_grd_protocol_debt_snapshot(&protocol_debt); - emit_row(rsinfo, "pcm", "pcm_grd_wait_refcount", - fmt_uint64(protocol_debt.wait_refcount)); + emit_row(rsinfo, "pcm", "pcm_grd_wait_refcount", fmt_uint64(protocol_debt.wait_refcount)); emit_row(rsinfo, "pcm", "pcm_grd_transport_refcount", - fmt_uint64(protocol_debt.transport_refcount)); + fmt_uint64(protocol_debt.transport_refcount)); emit_row(rsinfo, "pcm", "resource_x_retained_debt_count", - fmt_uint64(protocol_debt.retained_entry_count)); + fmt_uint64(protocol_debt.retained_entry_count)); emit_row(rsinfo, "pcm", "resource_x_active_debt_count", - fmt_uint64(protocol_debt.active_resource_x_entry_count)); + fmt_uint64(protocol_debt.active_resource_x_entry_count)); emit_row(rsinfo, "pcm", "resource_x_local_owner_debt_count", - fmt_uint64(protocol_debt.local_owner_entry_count)); + fmt_uint64(protocol_debt.local_owner_entry_count)); emit_row(rsinfo, "pcm", "resource_x_evicting_debt_count", - fmt_uint64(protocol_debt.evicting_entry_count)); + fmt_uint64(protocol_debt.evicting_entry_count)); emit_row(rsinfo, "pcm", "resource_x_invalid_debt_count", - fmt_uint64(protocol_debt.invalid_entry_count)); - for (refusal = PCM_RETIRE_REFUSAL_GATE_NOT_OPEN; - refusal < PCM_RETIRE_REFUSAL_N; refusal++) + fmt_uint64(protocol_debt.invalid_entry_count)); + for (refusal = PCM_RETIRE_REFUSAL_GATE_NOT_OPEN; refusal < PCM_RETIRE_REFUSAL_N; refusal++) emit_row(rsinfo, "pcm", reclaim_refusal_keys[refusal], - fmt_uint64(lifecycle.reclaim_refused[refusal])); + fmt_uint64(lifecycle.reclaim_refused[refusal])); emit_row(rsinfo, "pcm", "pcm_lock_mode_count", "3"); if (cluster_pcm_rx_stats_snapshot(&rx)) { emit_row(rsinfo, "pcm", "rx_stats_available", "true"); @@ -2203,24 +2184,17 @@ dump_pcm(ReturnSetInfo *rsinfo) */ emit_row(rsinfo, "pcm", "pcm_api_state", (cluster_pcm_grd_max_entries == 0) ? "stub" : "active"); - emit_row(rsinfo, "pcm", "resource_x_proof_readiness", - resource_x_proof_readiness_status()); + emit_row(rsinfo, "pcm", "resource_x_proof_readiness", resource_x_proof_readiness_status()); memset(&gate_before, 0, sizeof(gate_before)); memset(&gate_after, 0, sizeof(gate_after)); + owner_snapshot_exact = cluster_pcm_lock_resource_x_gate_snapshot(&gate_before); + writer_before = cluster_resource_x_writer_path_snapshot(&writer_generation_before); owner_snapshot_exact - = cluster_pcm_lock_resource_x_gate_snapshot(&gate_before); - writer_before = cluster_resource_x_writer_path_snapshot( - &writer_generation_before); + = owner_snapshot_exact && cluster_pcm_lock_resource_x_gate_snapshot(&gate_after); + writer_after = cluster_resource_x_writer_path_snapshot(&writer_generation_after); owner_snapshot_exact - = owner_snapshot_exact - && cluster_pcm_lock_resource_x_gate_snapshot(&gate_after); - writer_after = cluster_resource_x_writer_path_snapshot( - &writer_generation_after); - owner_snapshot_exact - = owner_snapshot_exact - && memcmp(&gate_before, &gate_after, sizeof(gate_before)) == 0 - && writer_before == writer_after - && writer_generation_before == writer_generation_after; + = owner_snapshot_exact && memcmp(&gate_before, &gate_after, sizeof(gate_before)) == 0 + && writer_before == writer_after && writer_generation_before == writer_generation_after; if (!owner_snapshot_exact) { gate_phase = "unavailable"; writer_path = "closed"; @@ -2228,35 +2202,34 @@ dump_pcm(ReturnSetInfo *rsinfo) writer_generation_before = 0; } else { switch (gate_before.phase) { - case RESOURCE_X_GATE_OPEN: - gate_phase = "open"; - break; - case RESOURCE_X_GATE_FROZEN: - gate_phase = "frozen"; - break; - case RESOURCE_X_GATE_RECOVERY_BLOCKED: - gate_phase = "recovery-blocked"; - break; - default: - gate_phase = "invalid"; - break; + case RESOURCE_X_GATE_OPEN: + gate_phase = "open"; + break; + case RESOURCE_X_GATE_FROZEN: + gate_phase = "frozen"; + break; + case RESOURCE_X_GATE_RECOVERY_BLOCKED: + gate_phase = "recovery-blocked"; + break; + default: + gate_phase = "invalid"; + break; } switch (writer_before) { - case RESOURCE_X_WRITER_SOURCE: - writer_path = "source"; - break; - case RESOURCE_X_WRITER_TARGET: - writer_path = "target"; - break; - case RESOURCE_X_WRITER_CLOSED: - default: - writer_path = "closed"; - break; + case RESOURCE_X_WRITER_SOURCE: + writer_path = "source"; + break; + case RESOURCE_X_WRITER_TARGET: + writer_path = "target"; + break; + case RESOURCE_X_WRITER_CLOSED: + default: + writer_path = "closed"; + break; } } emit_row(rsinfo, "pcm", "resource_x_gate_phase", gate_phase); - emit_row(rsinfo, "pcm", "resource_x_gate_formation", - fmt_uint64(gate_before.formation)); + emit_row(rsinfo, "pcm", "resource_x_gate_formation", fmt_uint64(gate_before.formation)); emit_row(rsinfo, "pcm", "resource_x_writer_path", writer_path); emit_row(rsinfo, "pcm", "resource_x_writer_r4_generation", fmt_uint64(writer_generation_before)); @@ -2273,10 +2246,8 @@ dump_pcm(ReturnSetInfo *rsinfo) fmt_int64((int64)o1.remote_episode_excluded_missing_grant)); emit_row(rsinfo, "pcm", "remote_episode_excluded_missing_image", fmt_int64((int64)o1.remote_episode_excluded_missing_image)); - emit_row(rsinfo, "pcm", "last_remote_t_image_us", - fmt_int64((int64)o1.last_remote_t_image_us)); - emit_row(rsinfo, "pcm", "last_remote_t_grant_us", - fmt_int64((int64)o1.last_remote_t_grant_us)); + emit_row(rsinfo, "pcm", "last_remote_t_image_us", fmt_int64((int64)o1.last_remote_t_image_us)); + emit_row(rsinfo, "pcm", "last_remote_t_grant_us", fmt_int64((int64)o1.last_remote_t_grant_us)); emit_row(rsinfo, "pcm", "last_remote_t_install_us", fmt_int64((int64)o1.last_remote_t_install_us)); @@ -2354,7 +2325,6 @@ dump_pcm(ReturnSetInfo *rsinfo) * (table full): non-zero means prov_query absence is inconclusive. */ emit_row(rsinfo, "pcm", "wm_prov_insert_fail_count", fmt_int64((int64)cluster_pcm_get_wm_prov_insert_fail_count())); - } @@ -2658,8 +2628,7 @@ dump_gcs(ReturnSetInfo *rsinfo) { uint64 metadata_retire_count = cluster_gcs_get_pi_watermark_retire_count(); - emit_row(rsinfo, "gcs", "pi_watermark_retire_count", - fmt_uint64(metadata_retire_count)); + emit_row(rsinfo, "gcs", "pi_watermark_retire_count", fmt_uint64(metadata_retire_count)); emit_row(rsinfo, "gcs", "pi_master_metadata_retire_count", fmt_uint64(metadata_retire_count)); } @@ -3789,8 +3758,7 @@ dump_write_fence(ReturnSetInfo *rsinfo) fmt_uint64(cluster_write_fence_get_external_publish_gate_blocked())); emit_row(rsinfo, "write_fence", "external_last_journal_seq", fmt_uint64(cluster_write_fence_get_external_last_journal_seq())); - proof_age_valid = - cluster_write_fence_get_external_last_proof_age_ms(&proof_age_ms); + proof_age_valid = cluster_write_fence_get_external_last_proof_age_ms(&proof_age_ms); emit_row(rsinfo, "write_fence", "external_last_proof_age_ms", proof_age_valid ? fmt_uint64(proof_age_ms) : "-"); } @@ -4215,7 +4183,7 @@ dump_multixact_current(ReturnSetInfo *rsinfo) [CMX_STAT_RESTART_MAX] = "restart_max", [CMX_STAT_FOREIGN_SLRU_GUARD] = "foreign_slru_guard_count", [CMX_STAT_UPDATER_PROVENANCE_CROSS_SEGMENT_MATCH] - = "updater_provenance_cross_segment_match_count", + = "updater_provenance_cross_segment_match_count", }; int i; @@ -4233,54 +4201,38 @@ dump_ctrc(ReturnSetInfo *rsinfo) int i; for (i = 0; i < CTRC_STAT_COUNT; i++) - emit_row(rsinfo, "ctrc", - cluster_ctrc_stat_name((ClusterCtrcStatId)i), - fmt_int64((int64)cluster_ctrc_stat_get( - (ClusterCtrcStatId)i))); + emit_row(rsinfo, "ctrc", cluster_ctrc_stat_name((ClusterCtrcStatId)i), + fmt_int64((int64)cluster_ctrc_stat_get((ClusterCtrcStatId)i))); MemSet(&snapshot, 0, sizeof(snapshot)); if (!cluster_ctrc_debug_snapshot(&snapshot)) return; reason = cluster_ctrc_cleaner_reason_get(); reason_name = cluster_ctrc_cleaner_reason_name(reason); - emit_row(rsinfo, "ctrc", "cleaner_reason", - reason_name != NULL ? reason_name : "BLOCKED"); - emit_row(rsinfo, "ctrc", "test_barrier_phase", - fmt_int64((int64)snapshot.test_barrier_phase)); + emit_row(rsinfo, "ctrc", "cleaner_reason", reason_name != NULL ? reason_name : "BLOCKED"); + emit_row(rsinfo, "ctrc", "test_barrier_phase", fmt_int64((int64)snapshot.test_barrier_phase)); emit_row(rsinfo, "ctrc", "test_barrier_hit_count", - fmt_int64((int64)snapshot.test_barrier_hit_count)); - emit_row(rsinfo, "ctrc", "origin_open", - fmt_int64((int64)snapshot.origin_open)); - emit_row(rsinfo, "ctrc", "origin_sealing", - fmt_int64((int64)snapshot.origin_sealing)); + fmt_int64((int64)snapshot.test_barrier_hit_count)); + emit_row(rsinfo, "ctrc", "origin_open", fmt_int64((int64)snapshot.origin_open)); + emit_row(rsinfo, "ctrc", "origin_sealing", fmt_int64((int64)snapshot.origin_sealing)); emit_row(rsinfo, "ctrc", "origin_release_proven", - fmt_int64((int64)snapshot.origin_release_proven)); - emit_row(rsinfo, "ctrc", "origin_blocked", - fmt_int64((int64)snapshot.origin_blocked)); - emit_row(rsinfo, "ctrc", "participant_open", - fmt_int64((int64)snapshot.participant_open)); + fmt_int64((int64)snapshot.origin_release_proven)); + emit_row(rsinfo, "ctrc", "origin_blocked", fmt_int64((int64)snapshot.origin_blocked)); + emit_row(rsinfo, "ctrc", "participant_open", fmt_int64((int64)snapshot.participant_open)); emit_row(rsinfo, "ctrc", "participant_draining", - fmt_int64((int64)snapshot.participant_draining)); + fmt_int64((int64)snapshot.participant_draining)); emit_row(rsinfo, "ctrc", "participant_ack_ready", - fmt_int64((int64)snapshot.participant_ack_ready)); + fmt_int64((int64)snapshot.participant_ack_ready)); emit_row(rsinfo, "ctrc", "participant_ack_frozen", - fmt_int64((int64)snapshot.participant_ack_frozen)); - emit_row(rsinfo, "ctrc", "participant_blocked", - fmt_int64((int64)snapshot.participant_blocked)); - emit_row(rsinfo, "ctrc", "receipt_prepared", - fmt_int64((int64)snapshot.receipt_prepared)); - emit_row(rsinfo, "ctrc", "receipt_applied", - fmt_int64((int64)snapshot.receipt_applied)); - emit_row(rsinfo, "ctrc", "receipt_cleaned", - fmt_int64((int64)snapshot.receipt_cleaned)); - emit_row(rsinfo, "ctrc", "receipt_cancelled", - fmt_int64((int64)snapshot.receipt_cancelled)); - emit_row(rsinfo, "ctrc", "receipt_ack_frozen", - fmt_int64((int64)snapshot.receipt_ack_frozen)); - emit_row(rsinfo, "ctrc", "receipt_blocked", - fmt_int64((int64)snapshot.receipt_blocked)); - emit_row(rsinfo, "ctrc", "full_refusal_count", - fmt_int64((int64)snapshot.full_refusal_count)); + fmt_int64((int64)snapshot.participant_ack_frozen)); + emit_row(rsinfo, "ctrc", "participant_blocked", fmt_int64((int64)snapshot.participant_blocked)); + emit_row(rsinfo, "ctrc", "receipt_prepared", fmt_int64((int64)snapshot.receipt_prepared)); + emit_row(rsinfo, "ctrc", "receipt_applied", fmt_int64((int64)snapshot.receipt_applied)); + emit_row(rsinfo, "ctrc", "receipt_cleaned", fmt_int64((int64)snapshot.receipt_cleaned)); + emit_row(rsinfo, "ctrc", "receipt_cancelled", fmt_int64((int64)snapshot.receipt_cancelled)); + emit_row(rsinfo, "ctrc", "receipt_ack_frozen", fmt_int64((int64)snapshot.receipt_ack_frozen)); + emit_row(rsinfo, "ctrc", "receipt_blocked", fmt_int64((int64)snapshot.receipt_blocked)); + emit_row(rsinfo, "ctrc", "full_refusal_count", fmt_int64((int64)snapshot.full_refusal_count)); } #endif /* USE_PGRAC_CLUSTER */ @@ -4354,7 +4306,7 @@ cluster_dump_state(PG_FUNCTION_ARGS) dump_xid_stripe(rsinfo); /* spec-6.15 D6 */ dump_multixact_current(rsinfo); dump_ctrc(rsinfo); - dump_catalog(rsinfo); /* spec-6.14 D10 */ + dump_catalog(rsinfo); /* spec-6.14 D10 */ } #else ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), diff --git a/src/backend/cluster/cluster_epoch.c b/src/backend/cluster/cluster_epoch.c index 59dccce5a35..37a145e0f77 100644 --- a/src/backend/cluster/cluster_epoch.c +++ b/src/backend/cluster/cluster_epoch.c @@ -240,7 +240,7 @@ cluster_epoch_advance_for_reconfig_if_baseline(uint64 baseline, uint64 *new_out) cache_mutation = cluster_write_fence_authority_cache_mutation_begin(); advanced = pg_atomic_compare_exchange_u64(&cluster_epoch_state->current_epoch, &expected, - baseline + 1); + baseline + 1); cluster_write_fence_authority_cache_mutation_end(cache_mutation); if (advanced) { *new_out = baseline + 1; @@ -306,7 +306,7 @@ cluster_epoch_observe_remote(uint64 remote_epoch) mutation_started = true; } if (pg_atomic_compare_exchange_u64(&cluster_epoch_state->current_epoch, &cur_val, - remote_epoch)) { + remote_epoch)) { cluster_write_fence_authority_cache_mutation_end(cache_mutation); return true; } diff --git a/src/backend/cluster/cluster_epoch_ballot.c b/src/backend/cluster/cluster_epoch_ballot.c index d8010f9eb72..f02661e1e9d 100644 --- a/src/backend/cluster/cluster_epoch_ballot.c +++ b/src/backend/cluster/cluster_epoch_ballot.c @@ -30,16 +30,14 @@ epoch_ballot_get_le16(const uint8 *in) static uint32 epoch_ballot_get_le32(const uint8 *in) { - return (uint32)in[0] | ((uint32)in[1] << 8) - | ((uint32)in[2] << 16) | ((uint32)in[3] << 24); + return (uint32)in[0] | ((uint32)in[1] << 8) | ((uint32)in[2] << 16) | ((uint32)in[3] << 24); } static uint64 epoch_ballot_get_le64(const uint8 *in) { - return (uint64)epoch_ballot_get_le32(in) - | ((uint64)epoch_ballot_get_le32(in + 4) << 32); + return (uint64)epoch_ballot_get_le32(in) | ((uint64)epoch_ballot_get_le32(in + 4) << 32); } @@ -91,16 +89,14 @@ epoch_ballot_bytes_zero(const void *bytes, Size size) static bool -epoch_ballot_bitmap_empty( - const uint8 bitmap[CLUSTER_EPOCH_BALLOT_BITMAP_BYTES]) +epoch_ballot_bitmap_empty(const uint8 bitmap[CLUSTER_EPOCH_BALLOT_BITMAP_BYTES]) { return epoch_ballot_bytes_zero(bitmap, CLUSTER_EPOCH_BALLOT_BITMAP_BYTES); } static int -epoch_ballot_bitmap_count( - const uint8 bitmap[CLUSTER_EPOCH_BALLOT_BITMAP_BYTES]) +epoch_ballot_bitmap_count(const uint8 bitmap[CLUSTER_EPOCH_BALLOT_BITMAP_BYTES]) { int count = 0; int i; @@ -118,8 +114,7 @@ epoch_ballot_bitmap_count( static bool -epoch_ballot_bitmap_has( - const uint8 bitmap[CLUSTER_EPOCH_BALLOT_BITMAP_BYTES], int32 node_id) +epoch_ballot_bitmap_has(const uint8 bitmap[CLUSTER_EPOCH_BALLOT_BITMAP_BYTES], int32 node_id) { return epoch_ballot_node_valid(node_id) && (bitmap[node_id / 8] & (uint8)(1u << (node_id % 8))) != 0; @@ -149,10 +144,8 @@ bool cluster_epoch_ballot_id_is_valid(const ClusterEpochBallotId *ballot) { return ballot != NULL && ballot->counter != 0 - && epoch_ballot_node_valid(ballot->proposer_node_id) - && ballot->reserved == 0 - && ballot->proposer_admitted_incarnation != 0 - && ballot->nonce != 0; + && epoch_ballot_node_valid(ballot->proposer_node_id) && ballot->reserved == 0 + && ballot->proposer_admitted_incarnation != 0 && ballot->nonce != 0; } @@ -167,8 +160,7 @@ cluster_epoch_ballot_id_encode(const ClusterEpochBallotId *ballot, memset(image, 0, sizeof(image)); epoch_ballot_put_le64(image + 0, ballot->counter); epoch_ballot_put_le32(image + 8, (uint32)ballot->proposer_node_id); - epoch_ballot_put_le64(image + 16, - ballot->proposer_admitted_incarnation); + epoch_ballot_put_le64(image + 16, ballot->proposer_admitted_incarnation); epoch_ballot_put_le64(image + 24, ballot->nonce); memcpy(out, image, sizeof(image)); return true; @@ -176,8 +168,8 @@ cluster_epoch_ballot_id_encode(const ClusterEpochBallotId *ballot, bool -cluster_epoch_ballot_id_decode( - const uint8 bytes[CLUSTER_EPOCH_BALLOT_ID_BYTES], ClusterEpochBallotId *out) +cluster_epoch_ballot_id_decode(const uint8 bytes[CLUSTER_EPOCH_BALLOT_ID_BYTES], + ClusterEpochBallotId *out) { ClusterEpochBallotId decoded; @@ -197,19 +189,20 @@ cluster_epoch_ballot_id_decode( int -cluster_epoch_ballot_id_compare(const ClusterEpochBallotId *a, - const ClusterEpochBallotId *b) -{ -#define EPOCH_BALLOT_CMP_FIELD(field) \ - do { \ - if (a->field < b->field) \ - return -1; \ - if (a->field > b->field) \ - return 1; \ +cluster_epoch_ballot_id_compare(const ClusterEpochBallotId *a, const ClusterEpochBallotId *b) +{ +#define EPOCH_BALLOT_CMP_FIELD(field) \ + do { \ + if (a->field < b->field) \ + return -1; \ + if (a->field > b->field) \ + return 1; \ } while (0) Assert(a != NULL); Assert(b != NULL); + /* Assert is the caller-contract guard; cppcheck does not model its trap. */ + /* cppcheck-suppress nullPointerRedundantCheck */ EPOCH_BALLOT_CMP_FIELD(counter); EPOCH_BALLOT_CMP_FIELD(proposer_node_id); EPOCH_BALLOT_CMP_FIELD(proposer_admitted_incarnation); @@ -251,8 +244,7 @@ epoch_authority_target_matches_subject(const ClusterEpochAuthorityValue *value) int subjects = epoch_ballot_bitmap_count(value->event_subject_bitmap); if (subjects == 1) - return epoch_ballot_bitmap_has(value->event_subject_bitmap, - value->target_node_id); + return epoch_ballot_bitmap_has(value->event_subject_bitmap, value->target_node_id); if (subjects > 1) return value->target_node_id == -1; return false; @@ -272,8 +264,7 @@ epoch_authority_event_identity_valid(const ClusterEpochAuthorityValue *value) case CLUSTER_EPOCH_EVENT_NODE_REMOVE: return value->old_incarnation != 0 && value->fresh_incarnation == 0; case CLUSTER_EPOCH_EVENT_SAME_NODE_REPLACEMENT: - return value->old_incarnation != 0 - && value->fresh_incarnation > value->old_incarnation; + return value->old_incarnation != 0 && value->fresh_incarnation > value->old_incarnation; default: return false; } @@ -282,19 +273,16 @@ epoch_authority_event_identity_valid(const ClusterEpochAuthorityValue *value) bool cluster_epoch_authority_value_is_valid(const ClusterEpochAuthorityValue *value, - uint64 expected_grammar_fingerprint) + uint64 expected_grammar_fingerprint) { bool genesis; - if (value == NULL - || expected_grammar_fingerprint - != CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT + if (value == NULL || expected_grammar_fingerprint != CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT || value->value_version != CLUSTER_EPOCH_AUTHORITY_VALUE_VERSION || !epoch_authority_transition_valid(value->transition) || !epoch_authority_event_kind_valid(value->event_kind) || !epoch_ballot_node_valid(value->request_origin_node) - || (value->target_node_id != -1 - && !epoch_ballot_node_valid(value->target_node_id)) + || (value->target_node_id != -1 && !epoch_ballot_node_valid(value->target_node_id)) || value->reserved0 != 0 || value->authority_generation == 0 || epoch_ballot_bitmap_empty(value->authority_member_bitmap) || value->grammar_fingerprint != expected_grammar_fingerprint @@ -305,14 +293,12 @@ cluster_epoch_authority_value_is_valid(const ClusterEpochAuthorityValue *value, if (genesis != (value->event_kind == CLUSTER_EPOCH_EVENT_GENESIS)) return false; if (genesis) { - return value->authority_generation == 1 - && value->baseline_epoch == value->reserved_epoch - && value->target_node_id == 0 - && value->old_incarnation == 0 && value->fresh_incarnation == 0 - && value->request_nonce == 0 + return value->authority_generation == 1 && value->baseline_epoch == value->reserved_epoch + && value->target_node_id == 0 && value->old_incarnation == 0 + && value->fresh_incarnation == 0 && value->request_nonce == 0 && epoch_ballot_bitmap_empty(value->event_subject_bitmap) && epoch_ballot_bytes_zero(value->predecessor_digest, - sizeof(value->predecessor_digest)); + sizeof(value->predecessor_digest)); } if (value->request_nonce == 0 || value->baseline_epoch == UINT64_MAX @@ -340,26 +326,21 @@ epoch_authority_value_pack(const ClusterEpochAuthorityValue *value, epoch_ballot_put_le64(image + 40, value->old_incarnation); epoch_ballot_put_le64(image + 48, value->fresh_incarnation); epoch_ballot_put_le64(image + 56, value->request_nonce); - memcpy(image + 64, value->authority_member_bitmap, - CLUSTER_EPOCH_BALLOT_BITMAP_BYTES); - memcpy(image + 80, value->event_subject_bitmap, - CLUSTER_EPOCH_BALLOT_BITMAP_BYTES); + memcpy(image + 64, value->authority_member_bitmap, CLUSTER_EPOCH_BALLOT_BITMAP_BYTES); + memcpy(image + 80, value->event_subject_bitmap, CLUSTER_EPOCH_BALLOT_BITMAP_BYTES); epoch_ballot_put_le64(image + 96, value->grammar_fingerprint); - memcpy(image + 104, value->predecessor_digest, - CLUSTER_EPOCH_BALLOT_DIGEST_BYTES); + memcpy(image + 104, value->predecessor_digest, CLUSTER_EPOCH_BALLOT_DIGEST_BYTES); } bool -cluster_epoch_authority_value_encode( - const ClusterEpochAuthorityValue *value, uint64 expected_grammar_fingerprint, - uint8 out[CLUSTER_EPOCH_AUTHORITY_VALUE_BYTES]) +cluster_epoch_authority_value_encode(const ClusterEpochAuthorityValue *value, + uint64 expected_grammar_fingerprint, + uint8 out[CLUSTER_EPOCH_AUTHORITY_VALUE_BYTES]) { uint8 image[CLUSTER_EPOCH_AUTHORITY_VALUE_BYTES]; - if (out == NULL - || !cluster_epoch_authority_value_is_valid( - value, expected_grammar_fingerprint)) + if (out == NULL || !cluster_epoch_authority_value_is_valid(value, expected_grammar_fingerprint)) return false; epoch_authority_value_pack(value, image); memcpy(out, image, sizeof(image)); @@ -368,9 +349,9 @@ cluster_epoch_authority_value_encode( bool -cluster_epoch_authority_value_decode( - const uint8 bytes[CLUSTER_EPOCH_AUTHORITY_VALUE_BYTES], - uint64 expected_grammar_fingerprint, ClusterEpochAuthorityValue *out) +cluster_epoch_authority_value_decode(const uint8 bytes[CLUSTER_EPOCH_AUTHORITY_VALUE_BYTES], + uint64 expected_grammar_fingerprint, + ClusterEpochAuthorityValue *out) { ClusterEpochAuthorityValue decoded; @@ -389,16 +370,12 @@ cluster_epoch_authority_value_decode( decoded.old_incarnation = epoch_ballot_get_le64(bytes + 40); decoded.fresh_incarnation = epoch_ballot_get_le64(bytes + 48); decoded.request_nonce = epoch_ballot_get_le64(bytes + 56); - memcpy(decoded.authority_member_bitmap, bytes + 64, - CLUSTER_EPOCH_BALLOT_BITMAP_BYTES); - memcpy(decoded.event_subject_bitmap, bytes + 80, - CLUSTER_EPOCH_BALLOT_BITMAP_BYTES); + memcpy(decoded.authority_member_bitmap, bytes + 64, CLUSTER_EPOCH_BALLOT_BITMAP_BYTES); + memcpy(decoded.event_subject_bitmap, bytes + 80, CLUSTER_EPOCH_BALLOT_BITMAP_BYTES); decoded.grammar_fingerprint = epoch_ballot_get_le64(bytes + 96); - memcpy(decoded.predecessor_digest, bytes + 104, - CLUSTER_EPOCH_BALLOT_DIGEST_BYTES); + memcpy(decoded.predecessor_digest, bytes + 104, CLUSTER_EPOCH_BALLOT_DIGEST_BYTES); memcpy(decoded.reserved1, bytes + 120, sizeof(decoded.reserved1)); - if (!cluster_epoch_authority_value_is_valid( - &decoded, expected_grammar_fingerprint)) + if (!cluster_epoch_authority_value_is_valid(&decoded, expected_grammar_fingerprint)) return false; *out = decoded; return true; @@ -420,8 +397,7 @@ epoch_authority_value_zero(const ClusterEpochAuthorityValue *value) static bool -epoch_ballot_pair_valid(const ClusterEpochBallotId *ballot, - const ClusterEpochAuthorityValue *value, +epoch_ballot_pair_valid(const ClusterEpochBallotId *ballot, const ClusterEpochAuthorityValue *value, uint64 expected_grammar_fingerprint) { bool ballot_zero = epoch_ballot_id_zero(ballot); @@ -432,22 +408,19 @@ epoch_ballot_pair_valid(const ClusterEpochBallotId *ballot, if (ballot_zero) return true; return cluster_epoch_ballot_id_is_valid(ballot) - && cluster_epoch_authority_value_is_valid( - value, expected_grammar_fingerprint); + && cluster_epoch_authority_value_is_valid(value, expected_grammar_fingerprint); } static bool -epoch_ballot_same_id(const ClusterEpochBallotId *a, - const ClusterEpochBallotId *b) +epoch_ballot_same_id(const ClusterEpochBallotId *a, const ClusterEpochBallotId *b) { return memcmp(a, b, sizeof(*a)) == 0; } static bool -epoch_authority_same_value(const ClusterEpochAuthorityValue *a, - const ClusterEpochAuthorityValue *b) +epoch_authority_same_value(const ClusterEpochAuthorityValue *a, const ClusterEpochAuthorityValue *b) { return memcmp(a, b, sizeof(*a)) == 0; } @@ -464,40 +437,29 @@ epoch_ballot_lane_history_valid(const ClusterEpochBallotLane *lane, || lane->promised_ballot.proposer_node_id != lane->proposer_node_id || lane->promised_ballot.proposer_admitted_incarnation != lane->proposer_admitted_incarnation - || !epoch_ballot_pair_valid(&lane->accepted_ballot, - &lane->accepted_value, - expected_grammar_fingerprint) - || !epoch_ballot_pair_valid(&lane->settled_ballot, - &lane->settled_value, - expected_grammar_fingerprint)) + || !epoch_ballot_pair_valid(&lane->accepted_ballot, &lane->accepted_value, + expected_grammar_fingerprint) + || !epoch_ballot_pair_valid(&lane->settled_ballot, &lane->settled_value, + expected_grammar_fingerprint)) return false; - if (!accepted_zero - && lane->accepted_ballot.proposer_node_id != lane->proposer_node_id) + if (!accepted_zero && lane->accepted_ballot.proposer_node_id != lane->proposer_node_id) return false; - if (!settled_zero - && lane->settled_ballot.proposer_node_id != lane->proposer_node_id) + if (!settled_zero && lane->settled_ballot.proposer_node_id != lane->proposer_node_id) return false; if (!accepted_zero - && cluster_epoch_ballot_id_compare(&lane->promised_ballot, - &lane->accepted_ballot) < 0) + && cluster_epoch_ballot_id_compare(&lane->promised_ballot, &lane->accepted_ballot) < 0) return false; if (!accepted_zero && !settled_zero - && cluster_epoch_ballot_id_compare(&lane->accepted_ballot, - &lane->settled_ballot) < 0) + && cluster_epoch_ballot_id_compare(&lane->accepted_ballot, &lane->settled_ballot) < 0) return false; if (!accepted_zero && !settled_zero) { - if (epoch_ballot_same_id(&lane->accepted_ballot, - &lane->settled_ballot) - && !epoch_authority_same_value(&lane->accepted_value, - &lane->settled_value)) + if (epoch_ballot_same_id(&lane->accepted_ballot, &lane->settled_ballot) + && !epoch_authority_same_value(&lane->accepted_value, &lane->settled_value)) return false; - if (lane->accepted_value.authority_generation - < lane->settled_value.authority_generation) + if (lane->accepted_value.authority_generation < lane->settled_value.authority_generation) return false; - if (lane->accepted_value.authority_generation - == lane->settled_value.authority_generation - && !epoch_authority_same_value(&lane->accepted_value, - &lane->settled_value)) + if (lane->accepted_value.authority_generation == lane->settled_value.authority_generation + && !epoch_authority_same_value(&lane->accepted_value, &lane->settled_value)) return false; } @@ -506,16 +468,12 @@ epoch_ballot_lane_history_valid(const ClusterEpochBallotLane *lane, return true; case CLUSTER_EPOCH_BALLOT_PHASE_ACCEPTED: return !accepted_zero - && epoch_ballot_same_id(&lane->promised_ballot, - &lane->accepted_ballot); + && epoch_ballot_same_id(&lane->promised_ballot, &lane->accepted_ballot); case CLUSTER_EPOCH_BALLOT_PHASE_SETTLED: return !accepted_zero && !settled_zero - && epoch_ballot_same_id(&lane->promised_ballot, - &lane->accepted_ballot) - && epoch_ballot_same_id(&lane->accepted_ballot, - &lane->settled_ballot) - && epoch_authority_same_value(&lane->accepted_value, - &lane->settled_value); + && epoch_ballot_same_id(&lane->promised_ballot, &lane->accepted_ballot) + && epoch_ballot_same_id(&lane->accepted_ballot, &lane->settled_ballot) + && epoch_authority_same_value(&lane->accepted_value, &lane->settled_value); default: return false; } @@ -523,52 +481,47 @@ epoch_ballot_lane_history_valid(const ClusterEpochBallotLane *lane, bool -cluster_epoch_ballot_lane_is_valid( - const ClusterEpochBallotLane *lane, int32 expected_proposer_node_id, - uint32 expected_configured_disk_count, - uint64 expected_proposer_admitted_incarnation, - uint64 expected_system_identifier, uint64 expected_grammar_fingerprint) +cluster_epoch_ballot_lane_is_valid(const ClusterEpochBallotLane *lane, + int32 expected_proposer_node_id, + uint32 expected_configured_disk_count, + uint64 expected_proposer_admitted_incarnation, + uint64 expected_system_identifier, + uint64 expected_grammar_fingerprint) { if (lane == NULL || !epoch_ballot_node_valid(expected_proposer_node_id) || !epoch_ballot_disk_count_valid(expected_configured_disk_count) - || expected_proposer_admitted_incarnation == 0 - || expected_system_identifier == 0 - || expected_grammar_fingerprint - != CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT + || expected_proposer_admitted_incarnation == 0 || expected_system_identifier == 0 + || expected_grammar_fingerprint != CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT || lane->magic != CLUSTER_EPOCH_BALLOT_MAGIC || lane->version != CLUSTER_EPOCH_BALLOT_VERSION || lane->last_write_phase < CLUSTER_EPOCH_BALLOT_PHASE_PROMISED - || lane->last_write_phase > CLUSTER_EPOCH_BALLOT_PHASE_SETTLED - || lane->flags != 0 + || lane->last_write_phase > CLUSTER_EPOCH_BALLOT_PHASE_SETTLED || lane->flags != 0 || lane->proposer_node_id != expected_proposer_node_id || lane->configured_disk_count != expected_configured_disk_count - || lane->proposer_admitted_incarnation - != expected_proposer_admitted_incarnation - || lane->lane_generation == 0 - || lane->system_identifier != expected_system_identifier + || lane->proposer_admitted_incarnation != expected_proposer_admitted_incarnation + || lane->lane_generation == 0 || lane->system_identifier != expected_system_identifier || lane->grammar_fingerprint != expected_grammar_fingerprint || !epoch_ballot_bytes_zero(lane->reserved, sizeof(lane->reserved))) return false; - return epoch_ballot_lane_history_valid(lane, - expected_grammar_fingerprint); + return epoch_ballot_lane_history_valid(lane, expected_grammar_fingerprint); } static bool -epoch_ballot_id_pack(const ClusterEpochBallotId *ballot, - uint8 image[CLUSTER_EPOCH_BALLOT_ID_BYTES]) +epoch_ballot_id_pack(const ClusterEpochBallotId *ballot, uint8 image[CLUSTER_EPOCH_BALLOT_ID_BYTES]) { return cluster_epoch_ballot_id_encode(ballot, image); } bool -cluster_epoch_ballot_lane_encode( - const ClusterEpochBallotLane *lane, int32 expected_proposer_node_id, - uint32 expected_configured_disk_count, - uint64 expected_proposer_admitted_incarnation, - uint64 expected_system_identifier, uint64 expected_grammar_fingerprint, - uint8 out[CLUSTER_EPOCH_BALLOT_LANE_BYTES]) +cluster_epoch_ballot_lane_encode(const ClusterEpochBallotLane *lane, + int32 expected_proposer_node_id, + uint32 expected_configured_disk_count, + uint64 expected_proposer_admitted_incarnation, + uint64 expected_system_identifier, + uint64 expected_grammar_fingerprint, + uint8 out[CLUSTER_EPOCH_BALLOT_LANE_BYTES]) { uint8 image[CLUSTER_EPOCH_BALLOT_LANE_BYTES]; @@ -584,30 +537,23 @@ cluster_epoch_ballot_lane_encode( image[6] = lane->last_write_phase; epoch_ballot_put_le32(image + 8, (uint32)lane->proposer_node_id); epoch_ballot_put_le32(image + 12, lane->configured_disk_count); - epoch_ballot_put_le64(image + 16, - lane->proposer_admitted_incarnation); + epoch_ballot_put_le64(image + 16, lane->proposer_admitted_incarnation); epoch_ballot_put_le64(image + 24, lane->lane_generation); epoch_ballot_put_le64(image + 32, lane->system_identifier); epoch_ballot_put_le64(image + 40, lane->grammar_fingerprint); - if (!epoch_ballot_id_pack(&lane->promised_ballot, - image + EPOCH_BALLOT_OFF_PROMISED)) + if (!epoch_ballot_id_pack(&lane->promised_ballot, image + EPOCH_BALLOT_OFF_PROMISED)) return false; if (!epoch_ballot_id_zero(&lane->accepted_ballot)) { - if (!epoch_ballot_id_pack(&lane->accepted_ballot, - image + EPOCH_BALLOT_OFF_ACCEPTED)) + if (!epoch_ballot_id_pack(&lane->accepted_ballot, image + EPOCH_BALLOT_OFF_ACCEPTED)) return false; - epoch_authority_value_pack(&lane->accepted_value, - image + EPOCH_BALLOT_OFF_ACCEPTED_VALUE); + epoch_authority_value_pack(&lane->accepted_value, image + EPOCH_BALLOT_OFF_ACCEPTED_VALUE); } if (!epoch_ballot_id_zero(&lane->settled_ballot)) { - if (!epoch_ballot_id_pack(&lane->settled_ballot, - image + EPOCH_BALLOT_OFF_SETTLED)) + if (!epoch_ballot_id_pack(&lane->settled_ballot, image + EPOCH_BALLOT_OFF_SETTLED)) return false; - epoch_authority_value_pack(&lane->settled_value, - image + EPOCH_BALLOT_OFF_SETTLED_VALUE); + epoch_authority_value_pack(&lane->settled_value, image + EPOCH_BALLOT_OFF_SETTLED_VALUE); } - epoch_ballot_put_le32(image + EPOCH_BALLOT_OFF_CRC, - epoch_ballot_lane_crc(image)); + epoch_ballot_put_le32(image + EPOCH_BALLOT_OFF_CRC, epoch_ballot_lane_crc(image)); memcpy(out, image, sizeof(image)); return true; } @@ -626,32 +572,30 @@ epoch_ballot_id_decode_pair(const uint8 bytes[CLUSTER_EPOCH_BALLOT_ID_BYTES], static bool -epoch_authority_value_decode_pair( - const uint8 bytes[CLUSTER_EPOCH_AUTHORITY_VALUE_BYTES], - uint64 expected_grammar_fingerprint, ClusterEpochAuthorityValue *out) +epoch_authority_value_decode_pair(const uint8 bytes[CLUSTER_EPOCH_AUTHORITY_VALUE_BYTES], + uint64 expected_grammar_fingerprint, + ClusterEpochAuthorityValue *out) { if (epoch_ballot_bytes_zero(bytes, CLUSTER_EPOCH_AUTHORITY_VALUE_BYTES)) { memset(out, 0, sizeof(*out)); return true; } - return cluster_epoch_authority_value_decode( - bytes, expected_grammar_fingerprint, out); + return cluster_epoch_authority_value_decode(bytes, expected_grammar_fingerprint, out); } bool -cluster_epoch_ballot_lane_decode( - const uint8 bytes[CLUSTER_EPOCH_BALLOT_LANE_BYTES], - int32 expected_proposer_node_id, uint32 expected_configured_disk_count, - uint64 expected_proposer_admitted_incarnation, - uint64 expected_system_identifier, uint64 expected_grammar_fingerprint, - ClusterEpochBallotLane *out) +cluster_epoch_ballot_lane_decode(const uint8 bytes[CLUSTER_EPOCH_BALLOT_LANE_BYTES], + int32 expected_proposer_node_id, + uint32 expected_configured_disk_count, + uint64 expected_proposer_admitted_incarnation, + uint64 expected_system_identifier, + uint64 expected_grammar_fingerprint, ClusterEpochBallotLane *out) { ClusterEpochBallotLane decoded; if (bytes == NULL || out == NULL - || epoch_ballot_lane_crc(bytes) - != epoch_ballot_get_le32(bytes + EPOCH_BALLOT_OFF_CRC)) + || epoch_ballot_lane_crc(bytes) != epoch_ballot_get_le32(bytes + EPOCH_BALLOT_OFF_CRC)) return false; memset(&decoded, 0, sizeof(decoded)); decoded.magic = epoch_ballot_get_le32(bytes + 0); @@ -664,27 +608,20 @@ cluster_epoch_ballot_lane_decode( decoded.lane_generation = epoch_ballot_get_le64(bytes + 24); decoded.system_identifier = epoch_ballot_get_le64(bytes + 32); decoded.grammar_fingerprint = epoch_ballot_get_le64(bytes + 40); - if (!epoch_ballot_id_decode_pair(bytes + EPOCH_BALLOT_OFF_PROMISED, - &decoded.promised_ballot) - || !epoch_ballot_id_decode_pair(bytes + EPOCH_BALLOT_OFF_ACCEPTED, - &decoded.accepted_ballot) - || !epoch_authority_value_decode_pair( - bytes + EPOCH_BALLOT_OFF_ACCEPTED_VALUE, - expected_grammar_fingerprint, &decoded.accepted_value) - || !epoch_ballot_id_decode_pair(bytes + EPOCH_BALLOT_OFF_SETTLED, - &decoded.settled_ballot) - || !epoch_authority_value_decode_pair( - bytes + EPOCH_BALLOT_OFF_SETTLED_VALUE, - expected_grammar_fingerprint, &decoded.settled_value)) + if (!epoch_ballot_id_decode_pair(bytes + EPOCH_BALLOT_OFF_PROMISED, &decoded.promised_ballot) + || !epoch_ballot_id_decode_pair(bytes + EPOCH_BALLOT_OFF_ACCEPTED, &decoded.accepted_ballot) + || !epoch_authority_value_decode_pair(bytes + EPOCH_BALLOT_OFF_ACCEPTED_VALUE, + expected_grammar_fingerprint, &decoded.accepted_value) + || !epoch_ballot_id_decode_pair(bytes + EPOCH_BALLOT_OFF_SETTLED, &decoded.settled_ballot) + || !epoch_authority_value_decode_pair(bytes + EPOCH_BALLOT_OFF_SETTLED_VALUE, + expected_grammar_fingerprint, &decoded.settled_value)) return false; - memcpy(decoded.reserved, bytes + EPOCH_BALLOT_OFF_RESERVED, - sizeof(decoded.reserved)); + memcpy(decoded.reserved, bytes + EPOCH_BALLOT_OFF_RESERVED, sizeof(decoded.reserved)); decoded.crc32c = epoch_ballot_get_le32(bytes + EPOCH_BALLOT_OFF_CRC); if (!cluster_epoch_ballot_lane_is_valid( - &decoded, expected_proposer_node_id, - expected_configured_disk_count, - expected_proposer_admitted_incarnation, - expected_system_identifier, expected_grammar_fingerprint)) + &decoded, expected_proposer_node_id, expected_configured_disk_count, + expected_proposer_admitted_incarnation, expected_system_identifier, + expected_grammar_fingerprint)) return false; *out = decoded; return true; diff --git a/src/backend/cluster/cluster_external_fence.c b/src/backend/cluster/cluster_external_fence.c index e81ec7cf0a3..1e869a01b26 100644 --- a/src/backend/cluster/cluster_external_fence.c +++ b/src/backend/cluster/cluster_external_fence.c @@ -38,15 +38,14 @@ #include "common/cryptohash.h" #include "common/pgrac_external_fence_protocol.h" -static PgracExternalFenceDenyReason external_fence_last_deny = - PGRAC_EXTERNAL_FENCE_DENY_NONE; +static PgracExternalFenceDenyReason external_fence_last_deny = PGRAC_EXTERNAL_FENCE_DENY_NONE; #ifdef USE_CLUSTER_UNIT extern bool cluster_external_fence_test_runtime_active(void); extern int cluster_external_fence_test_connect_root_daemon(int timeout_ms); extern bool cluster_external_fence_test_root_peer_authenticated(int fd); -extern int cluster_external_fence_test_admission_lease_ms( - const PgracExternalFenceAdmissionV1 *admission); +extern int +cluster_external_fence_test_admission_lease_ms(const PgracExternalFenceAdmissionV1 *admission); #endif bool @@ -63,8 +62,7 @@ cluster_external_fence_runtime_active(void) } bool -cluster_external_fence_rejoin_protected_set_digest( - uint8 out[PGRAC_EXTERNAL_FENCE_DIGEST_BYTES]) +cluster_external_fence_rejoin_protected_set_digest(uint8 out[PGRAC_EXTERNAL_FENCE_DIGEST_BYTES]) { ClusterProtectedSetIdentityV1 identity; @@ -72,21 +70,20 @@ cluster_external_fence_rejoin_protected_set_digest( return false; memset(out, 0, PGRAC_EXTERNAL_FENCE_DIGEST_BYTES); memset(&identity, 0, sizeof(identity)); - if (!cluster_shared_fs_get_protected_set_identity(&identity) || - !pgrac_external_fence_protected_set_digest_v1( - identity.backend_id, identity.storage_uuid, out)) - { + if (!cluster_shared_fs_get_protected_set_identity(&identity) + || !pgrac_external_fence_protected_set_digest_v1(identity.backend_id, identity.storage_uuid, + out)) { memset(out, 0, PGRAC_EXTERNAL_FENCE_DIGEST_BYTES); return false; } return true; } -#define PGRAC_EXTERNAL_FENCE_ADMISSION_MAGIC UINT32_C(0x50464131) /* PFA1 */ -#define PGRAC_EXTERNAL_FENCE_NEED_SET_MAGIC UINT32_C(0x50464e31) /* PFN1 */ +#define PGRAC_EXTERNAL_FENCE_ADMISSION_MAGIC UINT32_C(0x50464131) /* PFA1 */ +#define PGRAC_EXTERNAL_FENCE_NEED_SET_MAGIC UINT32_C(0x50464e31) /* PFN1 */ #define PGRAC_EXTERNAL_FENCE_ADMISSION_SET_MAGIC UINT32_C(0x50465331) /* PFS1 */ -#define PGRAC_EXTERNAL_FENCE_REJOIN_OP_MAGIC UINT32_C(0x50465231) /* PFR1 */ -#define PGRAC_EXTERNAL_FENCE_REJOIN_CLEAR_MAGIC UINT32_C(0x50464331) /* PFC1 */ +#define PGRAC_EXTERNAL_FENCE_REJOIN_OP_MAGIC UINT32_C(0x50465231) /* PFR1 */ +#define PGRAC_EXTERNAL_FENCE_REJOIN_CLEAR_MAGIC UINT32_C(0x50464331) /* PFC1 */ #define PGRAC_EXTERNAL_FENCE_MAX_FRESHNESS_NS UINT64_C(5000000000) #define PGRAC_EXTERNAL_FENCE_ROOT_SOURCE_PRIMARY UINT8_C(1) @@ -94,14 +91,10 @@ cluster_external_fence_rejoin_protected_set_digest( static bool external_fence_monotonic_now(uint64 *out_now_ns); #endif -static const uint8 external_fence_rejoin_clear_domain[] = - "PGRAC-REJOIN-AUTHORITY-CLEAR-V1"; -static const uint8 external_fence_rejoin_complete_domain[] = - "PGRAC-REJOIN-COMPLETE-V1"; -static const uint8 external_fence_rejoin_gate_domain[] = - "PGRAC-REJOIN-GATE-V1"; -static const uint8 external_fence_writer_set_domain[] = - "PGRAC-PROTECTED-WRITERS-V1"; +static const uint8 external_fence_rejoin_clear_domain[] = "PGRAC-REJOIN-AUTHORITY-CLEAR-V1"; +static const uint8 external_fence_rejoin_complete_domain[] = "PGRAC-REJOIN-COMPLETE-V1"; +static const uint8 external_fence_rejoin_gate_domain[] = "PGRAC-REJOIN-GATE-V1"; +static const uint8 external_fence_writer_set_domain[] = "PGRAC-PROTECTED-WRITERS-V1"; StaticAssertDecl(sizeof(external_fence_rejoin_clear_domain) == 32, "rejoin authority-clear digest domain changed"); @@ -116,8 +109,7 @@ StaticAssertDecl(sizeof(external_fence_writer_set_domain) == 27, * instance can be created while provider id 0 is the sole registry outcome, * but keeping the complete closed representation here pins the no-wait and * lifetime boundary before later consumers are wired. */ -struct PgracExternalFenceAdmissionV1 -{ +struct PgracExternalFenceAdmissionV1 { uint32 magic; int32 owner_pid; uint32 released; @@ -132,8 +124,7 @@ struct PgracExternalFenceAdmissionV1 int32 socket_fd; }; -struct PgracExternalFenceNeedSetV1 -{ +struct PgracExternalFenceNeedSetV1 { uint32 magic; int32 owner_pid; uint32 released; @@ -147,8 +138,7 @@ struct PgracExternalFenceNeedSetV1 PgracExternalFenceNeedV1 needs[CLUSTER_MAX_NODES]; }; -struct PgracExternalFenceAdmissionSetV1 -{ +struct PgracExternalFenceAdmissionSetV1 { uint32 magic; int32 owner_pid; uint32 released; @@ -158,8 +148,7 @@ struct PgracExternalFenceAdmissionSetV1 PgracExternalFenceAdmissionV1 *admissions[CLUSTER_MAX_NODES]; }; -struct PgracExternalFenceRejoinOpV1 -{ +struct PgracExternalFenceRejoinOpV1 { uint32 magic; int32 owner_pid; uint32 status; @@ -194,8 +183,7 @@ struct PgracExternalFenceRejoinOpV1 ClusterReconfigRejoinPendingSnapshotV1 refresh_pending; }; -struct PgracExternalFenceRejoinAuthorityClearV1 -{ +struct PgracExternalFenceRejoinAuthorityClearV1 { uint32 magic; int32 owner_pid; uint64 operation_deadline_mono_ns; @@ -209,9 +197,9 @@ static int32 external_fence_owner_pid(void) { #ifndef WIN32 - return (int32) getpid(); + return (int32)getpid(); #else - return (int32) GetCurrentProcessId(); + return (int32)GetCurrentProcessId(); #endif } @@ -220,8 +208,7 @@ bytes_nonzero(const uint8 *bytes, size_t len) { size_t i; - for (i = 0; i < len; i++) - { + for (i = 0; i < len; i++) { if (bytes[i] != 0) return true; } @@ -231,17 +218,17 @@ bytes_nonzero(const uint8 *bytes, size_t len) static void external_fence_put_u16_le(uint8 *out, uint16 value) { - out[0] = (uint8) value; - out[1] = (uint8) (value >> 8); + out[0] = (uint8)value; + out[1] = (uint8)(value >> 8); } static void external_fence_put_u32_le(uint8 *out, uint32 value) { - out[0] = (uint8) value; - out[1] = (uint8) (value >> 8); - out[2] = (uint8) (value >> 16); - out[3] = (uint8) (value >> 24); + out[0] = (uint8)value; + out[1] = (uint8)(value >> 8); + out[2] = (uint8)(value >> 16); + out[3] = (uint8)(value >> 24); } static void @@ -250,12 +237,12 @@ external_fence_put_u64_le(uint8 *out, uint64 value) int i; for (i = 0; i < 8; i++) - out[i] = (uint8) (value >> (i * 8)); + out[i] = (uint8)(value >> (i * 8)); } static bool external_fence_sha256(const uint8 *bytes, size_t len, - uint8 digest[PGRAC_EXTERNAL_FENCE_DIGEST_BYTES]) + uint8 digest[PGRAC_EXTERNAL_FENCE_DIGEST_BYTES]) { pg_cryptohash_ctx *ctx; bool ok; @@ -263,12 +250,9 @@ external_fence_sha256(const uint8 *bytes, size_t len, ctx = pg_cryptohash_create(PG_SHA256); if (ctx == NULL) ok = false; - else - { - ok = pg_cryptohash_init(ctx) >= 0 && - pg_cryptohash_update(ctx, bytes, len) >= 0 && - pg_cryptohash_final(ctx, digest, - PGRAC_EXTERNAL_FENCE_DIGEST_BYTES) >= 0; + else { + ok = pg_cryptohash_init(ctx) >= 0 && pg_cryptohash_update(ctx, bytes, len) >= 0 + && pg_cryptohash_final(ctx, digest, PGRAC_EXTERNAL_FENCE_DIGEST_BYTES) >= 0; pg_cryptohash_free(ctx); } if (!ok) @@ -277,41 +261,39 @@ external_fence_sha256(const uint8 *bytes, size_t len, } static bool -external_fence_rejoin_root_completion_digest( - const ClusterControlRootIdentity *identity, - const ClusterControlRootReadToken *token, - uint8 digest[PGRAC_EXTERNAL_FENCE_DIGEST_BYTES]) +external_fence_rejoin_root_completion_digest(const ClusterControlRootIdentity *identity, + const ClusterControlRootReadToken *token, + uint8 digest[PGRAC_EXTERNAL_FENCE_DIGEST_BYTES]) { uint8 preimage[167]; size_t offset = 0; -#define ROOT_APPEND_BYTES(bytes_, len_) \ - do { \ - memcpy(preimage + offset, (bytes_), (len_)); \ - offset += (len_); \ +#define ROOT_APPEND_BYTES(bytes_, len_) \ + do { \ + memcpy(preimage + offset, (bytes_), (len_)); \ + offset += (len_); \ } while (0) -#define ROOT_APPEND_U16(value_) \ - do { \ - external_fence_put_u16_le(preimage + offset, (uint16) (value_)); \ - offset += 2; \ +#define ROOT_APPEND_U16(value_) \ + do { \ + external_fence_put_u16_le(preimage + offset, (uint16)(value_)); \ + offset += 2; \ } while (0) -#define ROOT_APPEND_U32(value_) \ - do { \ - external_fence_put_u32_le(preimage + offset, (uint32) (value_)); \ - offset += 4; \ +#define ROOT_APPEND_U32(value_) \ + do { \ + external_fence_put_u32_le(preimage + offset, (uint32)(value_)); \ + offset += 4; \ } while (0) -#define ROOT_APPEND_U64(value_) \ - do { \ - external_fence_put_u64_le(preimage + offset, (uint64) (value_)); \ - offset += 8; \ +#define ROOT_APPEND_U64(value_) \ + do { \ + external_fence_put_u64_le(preimage + offset, (uint64)(value_)); \ + offset += 8; \ } while (0) ROOT_APPEND_BYTES(external_fence_rejoin_complete_domain, sizeof(external_fence_rejoin_complete_domain)); ROOT_APPEND_U64(identity->system_identifier); ROOT_APPEND_BYTES(identity->storage_uuid, sizeof(identity->storage_uuid)); - ROOT_APPEND_BYTES(identity->authority_uuid, - sizeof(identity->authority_uuid)); + ROOT_APPEND_BYTES(identity->authority_uuid, sizeof(identity->authority_uuid)); ROOT_APPEND_U16(identity->origin_thread_id); ROOT_APPEND_U32(identity->origin_node_id); ROOT_APPEND_U64(identity->thread_claim_created_at); @@ -348,12 +330,10 @@ external_fence_rejoin_gate_digest( { uint8 preimage[85]; - memcpy(preimage, external_fence_rejoin_gate_domain, - sizeof(external_fence_rejoin_gate_domain)); - memcpy(preimage + sizeof(external_fence_rejoin_gate_domain), - root_completion_digest, PGRAC_EXTERNAL_FENCE_DIGEST_BYTES); - memcpy(preimage + sizeof(external_fence_rejoin_gate_domain) + - PGRAC_EXTERNAL_FENCE_DIGEST_BYTES, + memcpy(preimage, external_fence_rejoin_gate_domain, sizeof(external_fence_rejoin_gate_domain)); + memcpy(preimage + sizeof(external_fence_rejoin_gate_domain), root_completion_digest, + PGRAC_EXTERNAL_FENCE_DIGEST_BYTES); + memcpy(preimage + sizeof(external_fence_rejoin_gate_domain) + PGRAC_EXTERNAL_FENCE_DIGEST_BYTES, authority_clear_digest, PGRAC_EXTERNAL_FENCE_DIGEST_BYTES); return external_fence_sha256(preimage, sizeof(preimage), digest); } @@ -364,12 +344,10 @@ external_fence_bitmap_popcount(const uint8 bitmap[16]) uint32 count = 0; int i; - for (i = 0; i < 16; i++) - { + for (i = 0; i < 16; i++) { uint8 value = bitmap[i]; - while (value != 0) - { + while (value != 0) { count += value & 1U; value >>= 1; } @@ -380,46 +358,43 @@ external_fence_bitmap_popcount(const uint8 bitmap[16]) static bool external_fence_bitmap_member(const uint8 bitmap[16], int32 node_id) { - return node_id >= 0 && node_id < CLUSTER_MAX_NODES && - (bitmap[node_id / 8] & (UINT8_C(1) << (node_id % 8))) != 0; + return node_id >= 0 && node_id < CLUSTER_MAX_NODES + && (bitmap[node_id / 8] & (UINT8_C(1) << (node_id % 8))) != 0; } static bool -external_fence_rejoin_clear_digest( - const PgracExternalFenceRejoinOpV1 *op, - const ClusterReconfigRejoinFailureSnapshotV1 *failure, - const ClusterGrdRejoinClearSnapshotV1 *grd_clear, - uint8 digest[PGRAC_EXTERNAL_FENCE_DIGEST_BYTES]) +external_fence_rejoin_clear_digest(const PgracExternalFenceRejoinOpV1 *op, + const ClusterReconfigRejoinFailureSnapshotV1 *failure, + const ClusterGrdRejoinClearSnapshotV1 *grd_clear, + uint8 digest[PGRAC_EXTERNAL_FENCE_DIGEST_BYTES]) { uint8 preimage[312]; size_t offset = 0; bool ok; -#define APPEND_BYTES(bytes_, len_) \ - do { \ - memcpy(preimage + offset, (bytes_), (len_)); \ - offset += (len_); \ +#define APPEND_BYTES(bytes_, len_) \ + do { \ + memcpy(preimage + offset, (bytes_), (len_)); \ + offset += (len_); \ } while (0) -#define APPEND_U16(value_) \ - do { \ - external_fence_put_u16_le(preimage + offset, (uint16) (value_)); \ - offset += 2; \ +#define APPEND_U16(value_) \ + do { \ + external_fence_put_u16_le(preimage + offset, (uint16)(value_)); \ + offset += 2; \ } while (0) -#define APPEND_U32(value_) \ - do { \ - external_fence_put_u32_le(preimage + offset, (uint32) (value_)); \ - offset += 4; \ +#define APPEND_U32(value_) \ + do { \ + external_fence_put_u32_le(preimage + offset, (uint32)(value_)); \ + offset += 4; \ } while (0) -#define APPEND_U64(value_) \ - do { \ - external_fence_put_u64_le(preimage + offset, (uint64) (value_)); \ - offset += 8; \ +#define APPEND_U64(value_) \ + do { \ + external_fence_put_u64_le(preimage + offset, (uint64)(value_)); \ + offset += 8; \ } while (0) - APPEND_BYTES(external_fence_rejoin_clear_domain, - sizeof(external_fence_rejoin_clear_domain)); - APPEND_BYTES(op->offer_frame.operation_id, - sizeof(op->offer_frame.operation_id)); + APPEND_BYTES(external_fence_rejoin_clear_domain, sizeof(external_fence_rejoin_clear_domain)); + APPEND_BYTES(op->offer_frame.operation_id, sizeof(op->offer_frame.operation_id)); APPEND_U64(op->offer_frame.system_identifier); APPEND_U32(op->offer_frame.old_node_id); APPEND_U32(0); @@ -431,25 +406,21 @@ external_fence_rejoin_clear_digest( APPEND_U64(failure->new_epoch); APPEND_U64(failure->cssd_dead_generation); APPEND_BYTES(failure->dead_bitmap, sizeof(failure->dead_bitmap)); - APPEND_BYTES(failure->survivor_bitmap, - sizeof(failure->survivor_bitmap)); + APPEND_BYTES(failure->survivor_bitmap, sizeof(failure->survivor_bitmap)); APPEND_U64(grd_clear->episode_epoch); APPEND_U64(grd_clear->dead_bitmap_hash); - APPEND_BYTES(grd_clear->survivor_bitmap, - sizeof(grd_clear->survivor_bitmap)); + APPEND_BYTES(grd_clear->survivor_bitmap, sizeof(grd_clear->survivor_bitmap)); APPEND_U64(op->offer_frame.target_mapping_generation); APPEND_U16(op->offer_frame.provider_id); APPEND_U16(op->offer_frame.provider_abi_version); APPEND_U32(0); - APPEND_BYTES(op->offer_frame.daemon_boot_id, - sizeof(op->offer_frame.daemon_boot_id)); + APPEND_BYTES(op->offer_frame.daemon_boot_id, sizeof(op->offer_frame.daemon_boot_id)); APPEND_U64(op->offer_frame.journal_seq); APPEND_U64(op->offer_frame.proof_generation); APPEND_U64(op->offer_frame.verified_mono_ns); APPEND_U64(op->offer_frame.fresh_until_mono_ns); APPEND_U64(op->deadline_mono_ns); - APPEND_BYTES(op->offer_frame.target_state_digest, - sizeof(op->offer_frame.target_state_digest)); + APPEND_BYTES(op->offer_frame.target_state_digest, sizeof(op->offer_frame.target_state_digest)); APPEND_BYTES(op->offer_frame.protected_set_digest, sizeof(op->offer_frame.protected_set_digest)); Assert(offset == sizeof(preimage)); @@ -468,83 +439,77 @@ external_fence_rejoin_clear_digest( static bool external_fence_need_valid(const PgracExternalFenceNeedV1 *need) { - return need != NULL && need->system_identifier != 0 && - need->victim_node_id >= 0 && - need->victim_node_id < CLUSTER_MAX_NODES && need->reserved0 == 0 && - need->victim_incarnation != 0 && - bytes_nonzero(need->canonical_duty_digest.bytes, - sizeof(need->canonical_duty_digest.bytes)) && - bytes_nonzero(need->protected_set_digest, - sizeof(need->protected_set_digest)) && - need->predicate_id == PGRAC_EXTERNAL_FENCE_PREDICATE_WRITE_EXCLUDED && - need->predicate_version == PGRAC_EXTERNAL_FENCE_PREDICATE_VERSION_V1; + return need != NULL && need->system_identifier != 0 && need->victim_node_id >= 0 + && need->victim_node_id < CLUSTER_MAX_NODES && need->reserved0 == 0 + && need->victim_incarnation != 0 + && bytes_nonzero(need->canonical_duty_digest.bytes, + sizeof(need->canonical_duty_digest.bytes)) + && bytes_nonzero(need->protected_set_digest, sizeof(need->protected_set_digest)) + && need->predicate_id == PGRAC_EXTERNAL_FENCE_PREDICATE_WRITE_EXCLUDED + && need->predicate_version == PGRAC_EXTERNAL_FENCE_PREDICATE_VERSION_V1; } static void -external_fence_record_result(PgracExternalFenceVerdict verdict, - PgracExternalFenceDenyReason reason, +external_fence_record_result(PgracExternalFenceVerdict verdict, PgracExternalFenceDenyReason reason, uint64 journal_seq, uint64 verified_mono_ns) { /* Verdict counters are mutually exclusive. Reason-specific counters are * additional diagnostics, never an alternate verdict. */ - switch (verdict) - { - case PGRAC_EXTERNAL_FENCE_WRITE_EXCLUDED: - cluster_write_fence_note_external_write_excluded(journal_seq, - verified_mono_ns); - break; - case PGRAC_EXTERNAL_FENCE_REJECTED: - cluster_write_fence_note_external_rejected(); - break; - case PGRAC_EXTERNAL_FENCE_UNKNOWN: - cluster_write_fence_note_external_unknown(); - break; - case PGRAC_EXTERNAL_FENCE_UNAVAILABLE: - cluster_write_fence_note_external_unavailable(); - break; - } - - switch (reason) - { - case PGRAC_EXTERNAL_FENCE_DENY_BINDING_MISMATCH: - cluster_write_fence_note_external_identity_mismatch(); - break; - case PGRAC_EXTERNAL_FENCE_DENY_EXPIRED: - cluster_write_fence_note_external_expired(); - break; - case PGRAC_EXTERNAL_FENCE_DENY_CONNECTION_CLOSED: - cluster_write_fence_note_external_daemon_disconnect(); - break; - case PGRAC_EXTERNAL_FENCE_DENY_NONE: - case PGRAC_EXTERNAL_FENCE_DENY_BAD_ARGUMENT: - case PGRAC_EXTERNAL_FENCE_DENY_EPISODE_NOT_CURRENT: - case PGRAC_EXTERNAL_FENCE_DENY_VICTIM_NOT_AUTHORIZED: - case PGRAC_EXTERNAL_FENCE_DENY_STORAGE_IDENTITY: - case PGRAC_EXTERNAL_FENCE_DENY_SOCKET_CONFIG: - case PGRAC_EXTERNAL_FENCE_DENY_PEER_AUTH: - case PGRAC_EXTERNAL_FENCE_DENY_PROTOCOL: - case PGRAC_EXTERNAL_FENCE_DENY_PROVIDER_REJECTED: - case PGRAC_EXTERNAL_FENCE_DENY_PROVIDER_UNKNOWN: - case PGRAC_EXTERNAL_FENCE_DENY_DAEMON_UNAVAILABLE: - case PGRAC_EXTERNAL_FENCE_DENY_TIMEOUT: - case PGRAC_EXTERNAL_FENCE_DENY_JOURNAL: - case PGRAC_EXTERNAL_FENCE_DENY_DAEMON_RESTARTED: - case PGRAC_EXTERNAL_FENCE_DENY_MAPPING_CHANGED: - case PGRAC_EXTERNAL_FENCE_DENY_MIXED_VERSION: - case PGRAC_EXTERNAL_FENCE_DENY_REJOIN_INVALIDATED: - case PGRAC_EXTERNAL_FENCE_DENY_WRITER_SET_STALE: - case PGRAC_EXTERNAL_FENCE_DENY_ROOT_NOT_COMPLETE: - case PGRAC_EXTERNAL_FENCE_DENY_ROOT_STALE: - case PGRAC_EXTERNAL_FENCE_DENY_REJOIN_OFFER_MISMATCH: - case PGRAC_EXTERNAL_FENCE_DENY_JOIN_CANDIDATE_MISMATCH: - case PGRAC_EXTERNAL_FENCE_DENY_JOIN_NOT_READY: - case PGRAC_EXTERNAL_FENCE_DENY_REJOIN_CONSUMED: - case PGRAC_EXTERNAL_FENCE_DENY_AUTHORITY_CLEAR_MISSING: - case PGRAC_EXTERNAL_FENCE_DENY_AUTHORITY_CLEAR_STALE: - case PGRAC_EXTERNAL_FENCE_DENY_REJOIN_LINEAGE_MISMATCH: - case PGRAC_EXTERNAL_FENCE_DENY_IO_NOT_DRAINED: - case PGRAC_EXTERNAL_FENCE_DENY_GRD_NOT_CLEAR: - break; + switch (verdict) { + case PGRAC_EXTERNAL_FENCE_WRITE_EXCLUDED: + cluster_write_fence_note_external_write_excluded(journal_seq, verified_mono_ns); + break; + case PGRAC_EXTERNAL_FENCE_REJECTED: + cluster_write_fence_note_external_rejected(); + break; + case PGRAC_EXTERNAL_FENCE_UNKNOWN: + cluster_write_fence_note_external_unknown(); + break; + case PGRAC_EXTERNAL_FENCE_UNAVAILABLE: + cluster_write_fence_note_external_unavailable(); + break; + } + + switch (reason) { + case PGRAC_EXTERNAL_FENCE_DENY_BINDING_MISMATCH: + cluster_write_fence_note_external_identity_mismatch(); + break; + case PGRAC_EXTERNAL_FENCE_DENY_EXPIRED: + cluster_write_fence_note_external_expired(); + break; + case PGRAC_EXTERNAL_FENCE_DENY_CONNECTION_CLOSED: + cluster_write_fence_note_external_daemon_disconnect(); + break; + case PGRAC_EXTERNAL_FENCE_DENY_NONE: + case PGRAC_EXTERNAL_FENCE_DENY_BAD_ARGUMENT: + case PGRAC_EXTERNAL_FENCE_DENY_EPISODE_NOT_CURRENT: + case PGRAC_EXTERNAL_FENCE_DENY_VICTIM_NOT_AUTHORIZED: + case PGRAC_EXTERNAL_FENCE_DENY_STORAGE_IDENTITY: + case PGRAC_EXTERNAL_FENCE_DENY_SOCKET_CONFIG: + case PGRAC_EXTERNAL_FENCE_DENY_PEER_AUTH: + case PGRAC_EXTERNAL_FENCE_DENY_PROTOCOL: + case PGRAC_EXTERNAL_FENCE_DENY_PROVIDER_REJECTED: + case PGRAC_EXTERNAL_FENCE_DENY_PROVIDER_UNKNOWN: + case PGRAC_EXTERNAL_FENCE_DENY_DAEMON_UNAVAILABLE: + case PGRAC_EXTERNAL_FENCE_DENY_TIMEOUT: + case PGRAC_EXTERNAL_FENCE_DENY_JOURNAL: + case PGRAC_EXTERNAL_FENCE_DENY_DAEMON_RESTARTED: + case PGRAC_EXTERNAL_FENCE_DENY_MAPPING_CHANGED: + case PGRAC_EXTERNAL_FENCE_DENY_MIXED_VERSION: + case PGRAC_EXTERNAL_FENCE_DENY_REJOIN_INVALIDATED: + case PGRAC_EXTERNAL_FENCE_DENY_WRITER_SET_STALE: + case PGRAC_EXTERNAL_FENCE_DENY_ROOT_NOT_COMPLETE: + case PGRAC_EXTERNAL_FENCE_DENY_ROOT_STALE: + case PGRAC_EXTERNAL_FENCE_DENY_REJOIN_OFFER_MISMATCH: + case PGRAC_EXTERNAL_FENCE_DENY_JOIN_CANDIDATE_MISMATCH: + case PGRAC_EXTERNAL_FENCE_DENY_JOIN_NOT_READY: + case PGRAC_EXTERNAL_FENCE_DENY_REJOIN_CONSUMED: + case PGRAC_EXTERNAL_FENCE_DENY_AUTHORITY_CLEAR_MISSING: + case PGRAC_EXTERNAL_FENCE_DENY_AUTHORITY_CLEAR_STALE: + case PGRAC_EXTERNAL_FENCE_DENY_REJOIN_LINEAGE_MISMATCH: + case PGRAC_EXTERNAL_FENCE_DENY_IO_NOT_DRAINED: + case PGRAC_EXTERNAL_FENCE_DENY_GRD_NOT_CLEAR: + break; } } @@ -552,91 +517,79 @@ static bool external_fence_binding_matches_need(const PgracExternalFenceBindingV1 *binding, const PgracExternalFenceNeedV1 *need) { - return binding->system_identifier == need->system_identifier && - memcmp(&binding->canonical_duty_digest, - &need->canonical_duty_digest, - sizeof(binding->canonical_duty_digest)) == 0 && - binding->victim_node_id == need->victim_node_id && - binding->reserved0 == 0 && - binding->victim_incarnation == need->victim_incarnation && - memcmp(binding->protected_set_digest, need->protected_set_digest, - sizeof(binding->protected_set_digest)) == 0 && - binding->predicate_id == need->predicate_id && - binding->predicate_version == need->predicate_version; + return binding->system_identifier == need->system_identifier + && memcmp(&binding->canonical_duty_digest, &need->canonical_duty_digest, + sizeof(binding->canonical_duty_digest)) + == 0 + && binding->victim_node_id == need->victim_node_id && binding->reserved0 == 0 + && binding->victim_incarnation == need->victim_incarnation + && memcmp(binding->protected_set_digest, need->protected_set_digest, + sizeof(binding->protected_set_digest)) + == 0 + && binding->predicate_id == need->predicate_id + && binding->predicate_version == need->predicate_version; } static bool external_fence_admission_valid(const PgracExternalFenceAdmissionV1 *admission) { - return admission != NULL && - admission->magic == PGRAC_EXTERNAL_FENCE_ADMISSION_MAGIC && - admission->owner_pid == external_fence_owner_pid() && - admission->released == 0 && admission->socket_fd >= 0; + return admission != NULL && admission->magic == PGRAC_EXTERNAL_FENCE_ADMISSION_MAGIC + && admission->owner_pid == external_fence_owner_pid() && admission->released == 0 + && admission->socket_fd >= 0; } static bool external_fence_need_set_valid(const PgracExternalFenceNeedSetV1 *set) { - return set != NULL && set->magic == PGRAC_EXTERNAL_FENCE_NEED_SET_MAGIC && - set->owner_pid == external_fence_owner_pid() && set->released == 0 && - set->count >= 1 && set->count <= CLUSTER_MAX_NODES && - bytes_nonzero(set->writer_set_digest.bytes, - sizeof(set->writer_set_digest.bytes)) && - set->formation != NULL; + return set != NULL && set->magic == PGRAC_EXTERNAL_FENCE_NEED_SET_MAGIC + && set->owner_pid == external_fence_owner_pid() && set->released == 0 && set->count >= 1 + && set->count <= CLUSTER_MAX_NODES + && bytes_nonzero(set->writer_set_digest.bytes, sizeof(set->writer_set_digest.bytes)) + && set->formation != NULL; } static bool -external_fence_admission_set_valid( - const PgracExternalFenceAdmissionSetV1 *set) +external_fence_admission_set_valid(const PgracExternalFenceAdmissionSetV1 *set) { - return set != NULL && - set->magic == PGRAC_EXTERNAL_FENCE_ADMISSION_SET_MAGIC && - set->owner_pid == external_fence_owner_pid() && set->released == 0 && - set->count >= 1 && set->count <= CLUSTER_MAX_NODES && - bytes_nonzero(set->writer_set_digest.bytes, - sizeof(set->writer_set_digest.bytes)) && - set->formation != NULL; + return set != NULL && set->magic == PGRAC_EXTERNAL_FENCE_ADMISSION_SET_MAGIC + && set->owner_pid == external_fence_owner_pid() && set->released == 0 && set->count >= 1 + && set->count <= CLUSTER_MAX_NODES + && bytes_nonzero(set->writer_set_digest.bytes, sizeof(set->writer_set_digest.bytes)) + && set->formation != NULL; } static bool external_fence_writer_set_digest_v1( const ClusterRecoveryDutyDigest *duty_digest, const uint8 protected_set_digest[PGRAC_EXTERNAL_FENCE_DIGEST_BYTES], - const PgracExternalFenceNeedV1 *needs, uint32 count, - PgracExternalFenceWriterSetDigest *out) + const PgracExternalFenceNeedV1 *needs, uint32 count, PgracExternalFenceWriterSetDigest *out) { - uint8 preimage[27 + PGRAC_EXTERNAL_FENCE_DIGEST_BYTES * 2 + 4 + - CLUSTER_MAX_NODES * sizeof(PgracExternalFenceWriterV1)]; + uint8 preimage[27 + PGRAC_EXTERNAL_FENCE_DIGEST_BYTES * 2 + 4 + + CLUSTER_MAX_NODES * sizeof(PgracExternalFenceWriterV1)]; size_t offset = 0; uint32 i; - if (duty_digest == NULL || protected_set_digest == NULL || needs == NULL || - out == NULL || count < 1 || count > CLUSTER_MAX_NODES) + if (duty_digest == NULL || protected_set_digest == NULL || needs == NULL || out == NULL + || count < 1 || count > CLUSTER_MAX_NODES) return false; memcpy(preimage + offset, external_fence_writer_set_domain, - sizeof(external_fence_writer_set_domain)); + sizeof(external_fence_writer_set_domain)); offset += sizeof(external_fence_writer_set_domain); - memcpy(preimage + offset, duty_digest->bytes, - sizeof(duty_digest->bytes)); + memcpy(preimage + offset, duty_digest->bytes, sizeof(duty_digest->bytes)); offset += sizeof(duty_digest->bytes); - memcpy(preimage + offset, protected_set_digest, - PGRAC_EXTERNAL_FENCE_DIGEST_BYTES); + memcpy(preimage + offset, protected_set_digest, PGRAC_EXTERNAL_FENCE_DIGEST_BYTES); offset += PGRAC_EXTERNAL_FENCE_DIGEST_BYTES; external_fence_put_u32_le(preimage + offset, count); offset += 4; - for (i = 0; i < count; i++) - { - external_fence_put_u32_le(preimage + offset, - (uint32) needs[i].victim_node_id); + for (i = 0; i < count; i++) { + external_fence_put_u32_le(preimage + offset, (uint32)needs[i].victim_node_id); offset += 4; external_fence_put_u32_le(preimage + offset, 0); offset += 4; - external_fence_put_u64_le(preimage + offset, - needs[i].victim_incarnation); + external_fence_put_u64_le(preimage + offset, needs[i].victim_incarnation); offset += 8; } - if (!external_fence_sha256(preimage, offset, out->bytes)) - { + if (!external_fence_sha256(preimage, offset, out->bytes)) { explicit_bzero(preimage, sizeof(preimage)); return false; } @@ -645,10 +598,9 @@ external_fence_writer_set_digest_v1( } PgracExternalFenceNeedSetResult -cluster_external_fence_need_set_build( - const ClusterRecoveryDutyKey *duty, - const ClusterFormationWitnessV1 *formation, - PgracExternalFenceNeedSetV1 **out) +cluster_external_fence_need_set_build(const ClusterRecoveryDutyKey *duty, + const ClusterFormationWitnessV1 *formation, + PgracExternalFenceNeedSetV1 **out) { ClusterFenceAuthorityProof authority; ClusterFormationSnapshotV1 classification; @@ -671,58 +623,50 @@ cluster_external_fence_need_set_build( if (formation_result != CLUSTER_FORMATION_WITNESS_READY) return PGRAC_EXTERNAL_FENCE_NEED_SET_FENCE_AUTHORITY_UNAVAILABLE; - if ((cluster_ic_local_capability_word() & - PGRAC_IC_HELLO_CAP_CONTROL_ROOT_V1) == 0 || - !cluster_external_fence_runtime_active()) + if ((cluster_ic_local_capability_word() & PGRAC_IC_HELLO_CAP_CONTROL_ROOT_V1) == 0 + || !cluster_external_fence_runtime_active()) return PGRAC_EXTERNAL_FENCE_NEED_SET_CAPABILITY_UNAVAILABLE; - if (!cluster_formation_witness_copy_classification_v1(formation, - &formation_origin_thread, &authority, &classification)) + if (!cluster_formation_witness_copy_classification_v1(formation, &formation_origin_thread, + &authority, &classification)) return PGRAC_EXTERNAL_FENCE_NEED_SET_FENCE_AUTHORITY_UNAVAILABLE; if (formation_origin_thread != duty->origin_thread_id) return PGRAC_EXTERNAL_FENCE_NEED_SET_DUTY_INVALID; - if (authority.total_disk_count == 0 || - authority.agree_disk_count <= authority.total_disk_count / 2 || - !cluster_fence_marker_valid_v1(&authority.marker)) + if (authority.total_disk_count == 0 + || authority.agree_disk_count <= authority.total_disk_count / 2 + || !cluster_fence_marker_valid_v1(&authority.marker)) return PGRAC_EXTERNAL_FENCE_NEED_SET_FENCE_AUTHORITY_UNAVAILABLE; - if (memcmp(authority.marker.fenced_dead_bitmap, - classification.excluded_bitmap, - sizeof(classification.excluded_bitmap)) != 0 || - authority.marker.fence_epoch != classification.local_epoch) + if (memcmp(authority.marker.fenced_dead_bitmap, classification.excluded_bitmap, + sizeof(classification.excluded_bitmap)) + != 0 + || authority.marker.fence_epoch != classification.local_epoch) return PGRAC_EXTERNAL_FENCE_NEED_SET_MEMBERSHIP_UNSTABLE; - for (node_id = 0; node_id < CLUSTER_MAX_NODES; node_id++) - { - if (!external_fence_bitmap_member(classification.excluded_bitmap, - node_id)) + for (node_id = 0; node_id < CLUSTER_MAX_NODES; node_id++) { + if (!external_fence_bitmap_member(classification.excluded_bitmap, node_id)) continue; count++; - if (classification.membership.membership_state[node_id] != - CLUSTER_MEMBER_DEAD && - classification.membership.membership_state[node_id] != - CLUSTER_MEMBER_REMOVED) + if (classification.membership.membership_state[node_id] != CLUSTER_MEMBER_DEAD + && classification.membership.membership_state[node_id] != CLUSTER_MEMBER_REMOVED) return PGRAC_EXTERNAL_FENCE_NEED_SET_MEMBERSHIP_UNSTABLE; if (classification.membership.last_admitted_incarnation[node_id] == 0) return PGRAC_EXTERNAL_FENCE_NEED_SET_WRITER_INCAR_UNPROVEN; } if (count < 1 || count > CLUSTER_MAX_NODES) return PGRAC_EXTERNAL_FENCE_NEED_SET_WRITER_COUNT_INVALID; - if (!external_fence_bitmap_member(classification.excluded_bitmap, - duty->origin_node_id)) + if (!external_fence_bitmap_member(classification.excluded_bitmap, duty->origin_node_id)) return PGRAC_EXTERNAL_FENCE_NEED_SET_ORIGINAL_OWNER_MISSING; - if (classification.membership.last_admitted_incarnation[ - duty->origin_node_id] != duty->origin_owner_incarnation) + if (classification.membership.last_admitted_incarnation[duty->origin_node_id] + != duty->origin_owner_incarnation) return PGRAC_EXTERNAL_FENCE_NEED_SET_WRITER_INCAR_UNPROVEN; memset(&protected_identity, 0, sizeof(protected_identity)); - if (!cluster_shared_fs_get_protected_set_identity(&protected_identity) || - (protected_identity.backend_id != - CLUSTER_SHARED_FS_BACKEND_BLOCK_DEVICE && - protected_identity.backend_id != - CLUSTER_SHARED_FS_BACKEND_CLUSTER_FS) || - memcmp(protected_identity.storage_uuid, duty->storage_uuid, - sizeof(protected_identity.storage_uuid)) != 0 || - !pgrac_external_fence_protected_set_digest_v1( - protected_identity.backend_id, protected_identity.storage_uuid, - protected_set_digest)) + if (!cluster_shared_fs_get_protected_set_identity(&protected_identity) + || (protected_identity.backend_id != CLUSTER_SHARED_FS_BACKEND_BLOCK_DEVICE + && protected_identity.backend_id != CLUSTER_SHARED_FS_BACKEND_CLUSTER_FS) + || memcmp(protected_identity.storage_uuid, duty->storage_uuid, + sizeof(protected_identity.storage_uuid)) + != 0 + || !pgrac_external_fence_protected_set_digest_v1( + protected_identity.backend_id, protected_identity.storage_uuid, protected_set_digest)) return PGRAC_EXTERNAL_FENCE_NEED_SET_STORAGE_UNAVAILABLE; if (!cluster_recovery_duty_digest_v1(duty, &duty_digest)) return PGRAC_EXTERNAL_FENCE_NEED_SET_DUTY_INVALID; @@ -737,28 +681,23 @@ cluster_external_fence_need_set_build( set->classification = classification; set->formation = formation; count = 0; - for (node_id = 0; node_id < CLUSTER_MAX_NODES; node_id++) - { + for (node_id = 0; node_id < CLUSTER_MAX_NODES; node_id++) { PgracExternalFenceNeedV1 *need; - if (!external_fence_bitmap_member(classification.excluded_bitmap, - node_id)) + if (!external_fence_bitmap_member(classification.excluded_bitmap, node_id)) continue; need = &set->needs[count++]; need->system_identifier = duty->system_identifier; need->canonical_duty_digest = duty_digest; need->victim_node_id = node_id; - need->victim_incarnation = - classification.membership.last_admitted_incarnation[node_id]; + need->victim_incarnation = classification.membership.last_admitted_incarnation[node_id]; memcpy(need->protected_set_digest, protected_set_digest, - sizeof(need->protected_set_digest)); + sizeof(need->protected_set_digest)); need->predicate_id = PGRAC_EXTERNAL_FENCE_PREDICATE_WRITE_EXCLUDED; need->predicate_version = PGRAC_EXTERNAL_FENCE_PREDICATE_VERSION_V1; } - if (!external_fence_writer_set_digest_v1(&duty_digest, - protected_set_digest, set->needs, set->count, - &set->writer_set_digest)) - { + if (!external_fence_writer_set_digest_v1(&duty_digest, protected_set_digest, set->needs, + set->count, &set->writer_set_digest)) { explicit_bzero(set, sizeof(*set)); pfree(set); return PGRAC_EXTERNAL_FENCE_NEED_SET_STORAGE_UNAVAILABLE; @@ -768,31 +707,26 @@ cluster_external_fence_need_set_build( } bool -cluster_external_fence_need_set_revalidate_nowait( - const PgracExternalFenceNeedSetV1 *needs, - const ClusterFormationWitnessV1 *formation, - PgracExternalFenceDenyReason *reason) +cluster_external_fence_need_set_revalidate_nowait(const PgracExternalFenceNeedSetV1 *needs, + const ClusterFormationWitnessV1 *formation, + PgracExternalFenceDenyReason *reason) { uint32 i; if (reason == NULL) return false; - if (!external_fence_need_set_valid(needs) || formation == NULL) - { + if (!external_fence_need_set_valid(needs) || formation == NULL) { *reason = PGRAC_EXTERNAL_FENCE_DENY_BAD_ARGUMENT; return false; } - if (formation != needs->formation || - cluster_formation_witness_revalidate_nowait(formation) != - CLUSTER_FORMATION_WITNESS_READY) - { + if (formation != needs->formation + || cluster_formation_witness_revalidate_nowait(formation) + != CLUSTER_FORMATION_WITNESS_READY) { *reason = PGRAC_EXTERNAL_FENCE_DENY_WRITER_SET_STALE; return false; } - for (i = 0; i < needs->count; i++) - { - if (!external_fence_need_valid(&needs->needs[i])) - { + for (i = 0; i < needs->count; i++) { + if (!external_fence_need_valid(&needs->needs[i])) { *reason = PGRAC_EXTERNAL_FENCE_DENY_WRITER_SET_STALE; return false; } @@ -802,40 +736,30 @@ cluster_external_fence_need_set_revalidate_nowait( } static PgracExternalFenceVerdict -external_fence_admit_result(PgracExternalFenceVerdict verdict, - PgracExternalFenceDenyReason reason, uint64 journal_seq, - uint64 verified_mono_ns) +external_fence_admit_result(PgracExternalFenceVerdict verdict, PgracExternalFenceDenyReason reason, + uint64 journal_seq, uint64 verified_mono_ns) { external_fence_last_deny = reason; - external_fence_record_result(verdict, reason, journal_seq, - verified_mono_ns); + external_fence_record_result(verdict, reason, journal_seq, verified_mono_ns); return verdict; } static bool -external_fence_response_verdict_valid( - const PgracExternalFenceProtocolResponseV1 *response) -{ - switch ((PgracExternalFenceVerdict) response->verdict) - { - case PGRAC_EXTERNAL_FENCE_WRITE_EXCLUDED: - return response->deny_reason == PGRAC_EXTERNAL_FENCE_DENY_NONE; - case PGRAC_EXTERNAL_FENCE_REJECTED: - return response->deny_reason == - PGRAC_EXTERNAL_FENCE_DENY_PROVIDER_REJECTED || - response->deny_reason == - PGRAC_EXTERNAL_FENCE_DENY_IO_NOT_DRAINED; - case PGRAC_EXTERNAL_FENCE_UNKNOWN: - return response->deny_reason == - PGRAC_EXTERNAL_FENCE_DENY_PROVIDER_UNKNOWN; - case PGRAC_EXTERNAL_FENCE_UNAVAILABLE: - return response->deny_reason != PGRAC_EXTERNAL_FENCE_DENY_NONE && - response->deny_reason != - PGRAC_EXTERNAL_FENCE_DENY_PROVIDER_REJECTED && - response->deny_reason != - PGRAC_EXTERNAL_FENCE_DENY_PROVIDER_UNKNOWN && - response->deny_reason != - PGRAC_EXTERNAL_FENCE_DENY_IO_NOT_DRAINED; +external_fence_response_verdict_valid(const PgracExternalFenceProtocolResponseV1 *response) +{ + switch ((PgracExternalFenceVerdict)response->verdict) { + case PGRAC_EXTERNAL_FENCE_WRITE_EXCLUDED: + return response->deny_reason == PGRAC_EXTERNAL_FENCE_DENY_NONE; + case PGRAC_EXTERNAL_FENCE_REJECTED: + return response->deny_reason == PGRAC_EXTERNAL_FENCE_DENY_PROVIDER_REJECTED + || response->deny_reason == PGRAC_EXTERNAL_FENCE_DENY_IO_NOT_DRAINED; + case PGRAC_EXTERNAL_FENCE_UNKNOWN: + return response->deny_reason == PGRAC_EXTERNAL_FENCE_DENY_PROVIDER_UNKNOWN; + case PGRAC_EXTERNAL_FENCE_UNAVAILABLE: + return response->deny_reason != PGRAC_EXTERNAL_FENCE_DENY_NONE + && response->deny_reason != PGRAC_EXTERNAL_FENCE_DENY_PROVIDER_REJECTED + && response->deny_reason != PGRAC_EXTERNAL_FENCE_DENY_PROVIDER_UNKNOWN + && response->deny_reason != PGRAC_EXTERNAL_FENCE_DENY_IO_NOT_DRAINED; } return false; } @@ -843,46 +767,40 @@ external_fence_response_verdict_valid( #ifndef WIN32 static bool external_fence_wait_ready(int fd, short events, uint64 deadline_ns, - PgracExternalFenceDenyReason *reason) + PgracExternalFenceDenyReason *reason) { - for (;;) - { + for (;;) { struct pollfd poll_fd; uint64 now_ns; uint64 remaining_ns; uint64 remaining_ms; int poll_result; - if (!external_fence_monotonic_now(&now_ns) || now_ns >= deadline_ns) - { + if (!external_fence_monotonic_now(&now_ns) || now_ns >= deadline_ns) { *reason = PGRAC_EXTERNAL_FENCE_DENY_TIMEOUT; return false; } remaining_ns = deadline_ns - now_ns; - remaining_ms = (remaining_ns + UINT64_C(999999)) / - UINT64_C(1000000); - if (remaining_ms > (uint64) INT_MAX) - remaining_ms = (uint64) INT_MAX; + remaining_ms = (remaining_ns + UINT64_C(999999)) / UINT64_C(1000000); + if (remaining_ms > (uint64)INT_MAX) + remaining_ms = (uint64)INT_MAX; poll_fd.fd = fd; poll_fd.events = events; poll_fd.revents = 0; - poll_result = poll(&poll_fd, 1, (int) remaining_ms); - if (poll_result < 0) - { + poll_result = poll(&poll_fd, 1, (int)remaining_ms); + if (poll_result < 0) { if (errno == EINTR) continue; *reason = PGRAC_EXTERNAL_FENCE_DENY_CONNECTION_CLOSED; return false; } - if (poll_result == 0) - { + if (poll_result == 0) { *reason = PGRAC_EXTERNAL_FENCE_DENY_TIMEOUT; return false; } if ((poll_fd.revents & events) != 0) return true; - if ((poll_fd.revents & (POLLERR | POLLHUP | POLLNVAL)) != 0) - { + if ((poll_fd.revents & (POLLERR | POLLHUP | POLLNVAL)) != 0) { *reason = PGRAC_EXTERNAL_FENCE_DENY_CONNECTION_CLOSED; return false; } @@ -890,8 +808,8 @@ external_fence_wait_ready(int fd, short events, uint64 deadline_ns, } static bool -external_fence_write_exact(int fd, const uint8 *bytes, size_t len, - uint64 deadline_ns, PgracExternalFenceDenyReason *reason) +external_fence_write_exact(int fd, const uint8 *bytes, size_t len, uint64 deadline_ns, + PgracExternalFenceDenyReason *reason) { size_t sent = 0; int send_flags = MSG_DONTWAIT; @@ -899,24 +817,20 @@ external_fence_write_exact(int fd, const uint8 *bytes, size_t len, #ifdef MSG_NOSIGNAL send_flags |= MSG_NOSIGNAL; #endif - while (sent < len) - { + while (sent < len) { ssize_t count = send(fd, bytes + sent, len - sent, send_flags); - if (count > 0) - { - sent += (size_t) count; + if (count > 0) { + sent += (size_t)count; continue; } - if (count == 0) - { + if (count == 0) { *reason = PGRAC_EXTERNAL_FENCE_DENY_CONNECTION_CLOSED; return false; } if (errno == EINTR) continue; - if (errno != EAGAIN && errno != EWOULDBLOCK) - { + if (errno != EAGAIN && errno != EWOULDBLOCK) { *reason = PGRAC_EXTERNAL_FENCE_DENY_CONNECTION_CLOSED; return false; } @@ -927,30 +841,25 @@ external_fence_write_exact(int fd, const uint8 *bytes, size_t len, } static bool -external_fence_read_exact(int fd, uint8 *bytes, size_t len, - uint64 deadline_ns, PgracExternalFenceDenyReason *reason) +external_fence_read_exact(int fd, uint8 *bytes, size_t len, uint64 deadline_ns, + PgracExternalFenceDenyReason *reason) { size_t received = 0; - while (received < len) - { - ssize_t count = recv(fd, bytes + received, len - received, - MSG_DONTWAIT); + while (received < len) { + ssize_t count = recv(fd, bytes + received, len - received, MSG_DONTWAIT); - if (count > 0) - { - received += (size_t) count; + if (count > 0) { + received += (size_t)count; continue; } - if (count == 0) - { + if (count == 0) { *reason = PGRAC_EXTERNAL_FENCE_DENY_CONNECTION_CLOSED; return false; } if (errno == EINTR) continue; - if (errno != EAGAIN && errno != EWOULDBLOCK) - { + if (errno != EAGAIN && errno != EWOULDBLOCK) { *reason = PGRAC_EXTERNAL_FENCE_DENY_CONNECTION_CLOSED; return false; } @@ -962,15 +871,14 @@ external_fence_read_exact(int fd, uint8 *bytes, size_t len, static int external_fence_connect_root_daemon(int timeout_ms, uint64 deadline_ns, - PgracExternalFenceDenyReason *reason) + PgracExternalFenceDenyReason *reason) { int fd = -1; int flags; #ifdef USE_CLUSTER_UNIT fd = cluster_external_fence_test_connect_root_daemon(timeout_ms); - if (fd < 0) - { + if (fd < 0) { *reason = PGRAC_EXTERNAL_FENCE_DENY_DAEMON_UNAVAILABLE; return -1; } @@ -979,76 +887,64 @@ external_fence_connect_root_daemon(int timeout_ms, uint64 deadline_ns, struct stat socket_stat; int connect_result; - if (cluster_external_fence_socket_path == NULL || - cluster_external_fence_socket_path[0] != '/' || - strlen(cluster_external_fence_socket_path) >= sizeof(address.sun_path) || - lstat(cluster_external_fence_socket_path, &socket_stat) != 0 || - !S_ISSOCK(socket_stat.st_mode) || socket_stat.st_uid != 0 || - (socket_stat.st_mode & 0777) != 0660) - { + if (cluster_external_fence_socket_path == NULL || cluster_external_fence_socket_path[0] != '/' + || strlen(cluster_external_fence_socket_path) >= sizeof(address.sun_path) + || lstat(cluster_external_fence_socket_path, &socket_stat) != 0 + || !S_ISSOCK(socket_stat.st_mode) || socket_stat.st_uid != 0 + || (socket_stat.st_mode & 0777) != 0660) { *reason = PGRAC_EXTERNAL_FENCE_DENY_SOCKET_CONFIG; return -1; } fd = socket(AF_UNIX, SOCK_STREAM, 0); - if (fd < 0) - { + if (fd < 0) { *reason = PGRAC_EXTERNAL_FENCE_DENY_SOCKET_CONFIG; return -1; } memset(&address, 0, sizeof(address)); address.sun_family = AF_UNIX; - strlcpy(address.sun_path, cluster_external_fence_socket_path, - sizeof(address.sun_path)); + strlcpy(address.sun_path, cluster_external_fence_socket_path, sizeof(address.sun_path)); #endif flags = fcntl(fd, F_GETFL, 0); - if (flags < 0 || fcntl(fd, F_SETFL, flags | O_NONBLOCK) < 0 || - fcntl(fd, F_SETFD, FD_CLOEXEC) < 0) - { + if (flags < 0 || fcntl(fd, F_SETFL, flags | O_NONBLOCK) < 0 + || fcntl(fd, F_SETFD, FD_CLOEXEC) < 0) { *reason = PGRAC_EXTERNAL_FENCE_DENY_SOCKET_CONFIG; - (void) close(fd); + (void)close(fd); return -1; } #ifdef SO_NOSIGPIPE { int no_sigpipe = 1; - if (setsockopt(fd, SOL_SOCKET, SO_NOSIGPIPE, &no_sigpipe, - sizeof(no_sigpipe)) != 0) - { + if (setsockopt(fd, SOL_SOCKET, SO_NOSIGPIPE, &no_sigpipe, sizeof(no_sigpipe)) != 0) { *reason = PGRAC_EXTERNAL_FENCE_DENY_SOCKET_CONFIG; - (void) close(fd); + (void)close(fd); return -1; } } #endif #ifndef USE_CLUSTER_UNIT - connect_result = connect(fd, (struct sockaddr *) &address, - sizeof(address)); - if (connect_result != 0) - { + connect_result = connect(fd, (struct sockaddr *)&address, sizeof(address)); + if (connect_result != 0) { int socket_error = 0; socklen_t socket_error_len = sizeof(socket_error); - if (errno != EINPROGRESS && errno != EAGAIN && errno != EWOULDBLOCK) - { + if (errno != EINPROGRESS && errno != EAGAIN && errno != EWOULDBLOCK) { *reason = PGRAC_EXTERNAL_FENCE_DENY_DAEMON_UNAVAILABLE; - (void) close(fd); + (void)close(fd); return -1; } - if (!external_fence_wait_ready(fd, POLLOUT, deadline_ns, reason)) - { + if (!external_fence_wait_ready(fd, POLLOUT, deadline_ns, reason)) { if (*reason == PGRAC_EXTERNAL_FENCE_DENY_CONNECTION_CLOSED) *reason = PGRAC_EXTERNAL_FENCE_DENY_DAEMON_UNAVAILABLE; - (void) close(fd); + (void)close(fd); return -1; } - if (getsockopt(fd, SOL_SOCKET, SO_ERROR, &socket_error, - &socket_error_len) != 0 || socket_error != 0) - { + if (getsockopt(fd, SOL_SOCKET, SO_ERROR, &socket_error, &socket_error_len) != 0 + || socket_error != 0) { *reason = PGRAC_EXTERNAL_FENCE_DENY_DAEMON_UNAVAILABLE; - (void) close(fd); + (void)close(fd); return -1; } } @@ -1057,32 +953,27 @@ external_fence_connect_root_daemon(int timeout_ms, uint64 deadline_ns, struct ucred credential; socklen_t credential_len = sizeof(credential); - if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &credential, - &credential_len) != 0 || - credential_len != sizeof(credential) || credential.uid != 0 || - credential.pid <= 0) - { + if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &credential, &credential_len) != 0 + || credential_len != sizeof(credential) || credential.uid != 0 || credential.pid <= 0) { *reason = PGRAC_EXTERNAL_FENCE_DENY_PEER_AUTH; - (void) close(fd); + (void)close(fd); return -1; } } -#elif defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) || \ - defined(__NetBSD__) +#elif defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) { uid_t uid; gid_t gid; - if (getpeereid(fd, &uid, &gid) != 0 || uid != 0) - { + if (getpeereid(fd, &uid, &gid) != 0 || uid != 0) { *reason = PGRAC_EXTERNAL_FENCE_DENY_PEER_AUTH; - (void) close(fd); + (void)close(fd); return -1; } } #else *reason = PGRAC_EXTERNAL_FENCE_DENY_PEER_AUTH; - (void) close(fd); + (void)close(fd); return -1; #endif #endif @@ -1090,14 +981,12 @@ external_fence_connect_root_daemon(int timeout_ms, uint64 deadline_ns, } static bool -external_fence_live_connection_exact(int fd, - PgracExternalFenceDenyReason *reason) +external_fence_live_connection_exact(int fd, PgracExternalFenceDenyReason *reason) { struct pollfd poll_fd; int poll_result; - for (;;) - { + for (;;) { poll_fd.fd = fd; poll_fd.events = POLLIN | POLLHUP | POLLERR; poll_fd.revents = 0; @@ -1114,17 +1003,15 @@ external_fence_live_connection_exact(int fd, #endif PgracExternalFenceVerdict -cluster_external_fence_admit_wait( - const PgracExternalFenceNeedV1 *need, int timeout_ms, - PgracExternalFenceAdmissionV1 **out) +cluster_external_fence_admit_wait(const PgracExternalFenceNeedV1 *need, int timeout_ms, + PgracExternalFenceAdmissionV1 **out) { int32 cooperative_lease_ms_snapshot = cluster_write_fence_lease_ms; if (out != NULL) *out = NULL; - if (out == NULL || !external_fence_need_valid(need) || timeout_ms < 1 || - timeout_ms > (int) PGRAC_EXTERNAL_FENCE_TIMEOUT_MAX_MS) - { + if (out == NULL || !external_fence_need_valid(need) || timeout_ms < 1 + || timeout_ms > (int)PGRAC_EXTERNAL_FENCE_TIMEOUT_MAX_MS) { external_fence_last_deny = PGRAC_EXTERNAL_FENCE_DENY_BAD_ARGUMENT; return PGRAC_EXTERNAL_FENCE_UNAVAILABLE; } @@ -1132,197 +1019,153 @@ cluster_external_fence_admit_wait( cluster_write_fence_note_external_admit_requested(); if (!cluster_external_fence_runtime_active()) return external_fence_admit_result(PGRAC_EXTERNAL_FENCE_UNAVAILABLE, - PGRAC_EXTERNAL_FENCE_DENY_DAEMON_UNAVAILABLE, 0, 0); + PGRAC_EXTERNAL_FENCE_DENY_DAEMON_UNAVAILABLE, 0, 0); #ifdef WIN32 return external_fence_admit_result(PGRAC_EXTERNAL_FENCE_UNAVAILABLE, - PGRAC_EXTERNAL_FENCE_DENY_DAEMON_UNAVAILABLE, 0, 0); + PGRAC_EXTERNAL_FENCE_DENY_DAEMON_UNAVAILABLE, 0, 0); #else { PgracExternalFenceProtocolRequestV1 request; PgracExternalFenceProtocolResponseV1 response; PgracExternalFenceAdmissionV1 *admission; - PgracExternalFenceDenyReason reason = - PGRAC_EXTERNAL_FENCE_DENY_NONE; + PgracExternalFenceDenyReason reason = PGRAC_EXTERNAL_FENCE_DENY_NONE; uint8 request_frame[PGRAC_EXTERNAL_FENCE_REQUEST_V1_BYTES]; uint8 response_frame[PGRAC_EXTERNAL_FENCE_RESPONSE_V1_BYTES]; uint64 start_ns; uint64 deadline_ns; - uint64 timeout_ns = (uint64) timeout_ms * UINT64_C(1000000); + uint64 timeout_ns = (uint64)timeout_ms * UINT64_C(1000000); uint64 now_ns; int fd = -1; - if (!external_fence_monotonic_now(&start_ns) || - UINT64_MAX - start_ns < timeout_ns) - return external_fence_admit_result( - PGRAC_EXTERNAL_FENCE_UNAVAILABLE, - PGRAC_EXTERNAL_FENCE_DENY_TIMEOUT, 0, 0); + if (!external_fence_monotonic_now(&start_ns) || UINT64_MAX - start_ns < timeout_ns) + return external_fence_admit_result(PGRAC_EXTERNAL_FENCE_UNAVAILABLE, + PGRAC_EXTERNAL_FENCE_DENY_TIMEOUT, 0, 0); deadline_ns = start_ns + timeout_ns; memset(&request, 0, sizeof(request)); - if (!pg_strong_random(request.request_nonce, - sizeof(request.request_nonce)) || - !bytes_nonzero(request.request_nonce, - sizeof(request.request_nonce))) - return external_fence_admit_result( - PGRAC_EXTERNAL_FENCE_UNAVAILABLE, - PGRAC_EXTERNAL_FENCE_DENY_PROTOCOL, 0, 0); + if (!pg_strong_random(request.request_nonce, sizeof(request.request_nonce)) + || !bytes_nonzero(request.request_nonce, sizeof(request.request_nonce))) + return external_fence_admit_result(PGRAC_EXTERNAL_FENCE_UNAVAILABLE, + PGRAC_EXTERNAL_FENCE_DENY_PROTOCOL, 0, 0); request.need.system_identifier = need->system_identifier; - memcpy(request.need.canonical_duty_digest, - need->canonical_duty_digest.bytes, - sizeof(request.need.canonical_duty_digest)); + memcpy(request.need.canonical_duty_digest, need->canonical_duty_digest.bytes, + sizeof(request.need.canonical_duty_digest)); request.need.victim_node_id = need->victim_node_id; request.need.victim_incarnation = need->victim_incarnation; - memcpy(request.need.protected_set_digest, - need->protected_set_digest, - sizeof(request.need.protected_set_digest)); + memcpy(request.need.protected_set_digest, need->protected_set_digest, + sizeof(request.need.protected_set_digest)); request.need.predicate_id = need->predicate_id; request.need.predicate_version = need->predicate_version; - request.timeout_ms = (uint32) timeout_ms; + request.timeout_ms = (uint32)timeout_ms; if (!pgrac_external_fence_request_v1_encode(&request, request_frame)) - return external_fence_admit_result( - PGRAC_EXTERNAL_FENCE_UNAVAILABLE, - PGRAC_EXTERNAL_FENCE_DENY_PROTOCOL, 0, 0); + return external_fence_admit_result(PGRAC_EXTERNAL_FENCE_UNAVAILABLE, + PGRAC_EXTERNAL_FENCE_DENY_PROTOCOL, 0, 0); - fd = external_fence_connect_root_daemon(timeout_ms, deadline_ns, - &reason); + fd = external_fence_connect_root_daemon(timeout_ms, deadline_ns, &reason); if (fd < 0) - return external_fence_admit_result( - PGRAC_EXTERNAL_FENCE_UNAVAILABLE, reason, 0, 0); - if (!external_fence_write_exact(fd, request_frame, - sizeof(request_frame), deadline_ns, &reason) || - !external_fence_read_exact(fd, response_frame, - sizeof(response_frame), deadline_ns, &reason)) - { - (void) close(fd); - return external_fence_admit_result( - PGRAC_EXTERNAL_FENCE_UNAVAILABLE, reason, 0, 0); + return external_fence_admit_result(PGRAC_EXTERNAL_FENCE_UNAVAILABLE, reason, 0, 0); + if (!external_fence_write_exact(fd, request_frame, sizeof(request_frame), deadline_ns, + &reason) + || !external_fence_read_exact(fd, response_frame, sizeof(response_frame), deadline_ns, + &reason)) { + (void)close(fd); + return external_fence_admit_result(PGRAC_EXTERNAL_FENCE_UNAVAILABLE, reason, 0, 0); } - if (!pgrac_external_fence_response_v1_decode(response_frame, - sizeof(response_frame), &response) || - memcmp(request.request_nonce, response.request_nonce, - sizeof(request.request_nonce)) != 0 || - !external_fence_response_verdict_valid(&response)) - { - (void) close(fd); - return external_fence_admit_result( - PGRAC_EXTERNAL_FENCE_UNAVAILABLE, - PGRAC_EXTERNAL_FENCE_DENY_PROTOCOL, 0, 0); + if (!pgrac_external_fence_response_v1_decode(response_frame, sizeof(response_frame), + &response) + || memcmp(request.request_nonce, response.request_nonce, sizeof(request.request_nonce)) + != 0 + || !external_fence_response_verdict_valid(&response)) { + (void)close(fd); + return external_fence_admit_result(PGRAC_EXTERNAL_FENCE_UNAVAILABLE, + PGRAC_EXTERNAL_FENCE_DENY_PROTOCOL, 0, 0); } - if (response.verdict != PGRAC_EXTERNAL_FENCE_WRITE_EXCLUDED) - { - PgracExternalFenceVerdict verdict = - (PgracExternalFenceVerdict) response.verdict; - PgracExternalFenceDenyReason deny = - (PgracExternalFenceDenyReason) response.deny_reason; - - (void) close(fd); - return external_fence_admit_result(verdict, deny, - response.journal_seq, response.verified_mono_ns); + if (response.verdict != PGRAC_EXTERNAL_FENCE_WRITE_EXCLUDED) { + PgracExternalFenceVerdict verdict = (PgracExternalFenceVerdict)response.verdict; + PgracExternalFenceDenyReason deny = (PgracExternalFenceDenyReason)response.deny_reason; + + (void)close(fd); + return external_fence_admit_result(verdict, deny, response.journal_seq, + response.verified_mono_ns); } - if (!pgrac_external_fence_affirmative_response_matches_request_v1( - &request, &response)) - { - (void) close(fd); - return external_fence_admit_result( - PGRAC_EXTERNAL_FENCE_UNAVAILABLE, - PGRAC_EXTERNAL_FENCE_DENY_BINDING_MISMATCH, 0, 0); + if (!pgrac_external_fence_affirmative_response_matches_request_v1(&request, &response)) { + (void)close(fd); + return external_fence_admit_result(PGRAC_EXTERNAL_FENCE_UNAVAILABLE, + PGRAC_EXTERNAL_FENCE_DENY_BINDING_MISMATCH, 0, 0); } - if (!external_fence_monotonic_now(&now_ns) || now_ns >= deadline_ns) - { - (void) close(fd); - return external_fence_admit_result( - PGRAC_EXTERNAL_FENCE_UNAVAILABLE, - PGRAC_EXTERNAL_FENCE_DENY_TIMEOUT, 0, 0); + if (!external_fence_monotonic_now(&now_ns) || now_ns >= deadline_ns) { + (void)close(fd); + return external_fence_admit_result(PGRAC_EXTERNAL_FENCE_UNAVAILABLE, + PGRAC_EXTERNAL_FENCE_DENY_TIMEOUT, 0, 0); } - if (now_ns < response.verified_mono_ns || - now_ns >= response.fresh_until_mono_ns || - response.fresh_until_mono_ns <= response.verified_mono_ns || - response.fresh_until_mono_ns - response.verified_mono_ns > - PGRAC_EXTERNAL_FENCE_MAX_FRESHNESS_NS) - { - (void) close(fd); - return external_fence_admit_result( - PGRAC_EXTERNAL_FENCE_UNAVAILABLE, - PGRAC_EXTERNAL_FENCE_DENY_EXPIRED, 0, 0); + if (now_ns < response.verified_mono_ns || now_ns >= response.fresh_until_mono_ns + || response.fresh_until_mono_ns <= response.verified_mono_ns + || response.fresh_until_mono_ns - response.verified_mono_ns + > PGRAC_EXTERNAL_FENCE_MAX_FRESHNESS_NS) { + (void)close(fd); + return external_fence_admit_result(PGRAC_EXTERNAL_FENCE_UNAVAILABLE, + PGRAC_EXTERNAL_FENCE_DENY_EXPIRED, 0, 0); } - if (!external_fence_live_connection_exact(fd, &reason)) - { - (void) close(fd); - return external_fence_admit_result( - PGRAC_EXTERNAL_FENCE_UNAVAILABLE, reason, 0, 0); + if (!external_fence_live_connection_exact(fd, &reason)) { + (void)close(fd); + return external_fence_admit_result(PGRAC_EXTERNAL_FENCE_UNAVAILABLE, reason, 0, 0); } admission = palloc0(sizeof(*admission)); admission->magic = PGRAC_EXTERNAL_FENCE_ADMISSION_MAGIC; admission->owner_pid = external_fence_owner_pid(); - admission->binding.system_identifier = - response.binding.system_identifier; + admission->binding.system_identifier = response.binding.system_identifier; memcpy(admission->binding.canonical_duty_digest.bytes, - response.binding.canonical_duty_digest, - sizeof(response.binding.canonical_duty_digest)); + response.binding.canonical_duty_digest, + sizeof(response.binding.canonical_duty_digest)); admission->binding.victim_node_id = response.binding.victim_node_id; - admission->binding.victim_incarnation = - response.binding.victim_incarnation; - admission->binding.target_mapping_generation = - response.binding.target_mapping_generation; - memcpy(admission->binding.protected_set_digest, - response.binding.protected_set_digest, - sizeof(response.binding.protected_set_digest)); + admission->binding.victim_incarnation = response.binding.victim_incarnation; + admission->binding.target_mapping_generation = response.binding.target_mapping_generation; + memcpy(admission->binding.protected_set_digest, response.binding.protected_set_digest, + sizeof(response.binding.protected_set_digest)); admission->binding.predicate_id = response.binding.predicate_id; - admission->binding.predicate_version = - response.binding.predicate_version; + admission->binding.predicate_version = response.binding.predicate_version; memcpy(admission->daemon_boot_id, response.daemon_boot_id, - sizeof(admission->daemon_boot_id)); + sizeof(admission->daemon_boot_id)); admission->journal_seq = response.journal_seq; admission->proof_generation = response.proof_generation; admission->verified_mono_ns = response.verified_mono_ns; admission->fresh_until_mono_ns = response.fresh_until_mono_ns; - admission->cached_mapping_generation = - response.binding.target_mapping_generation; - admission->cooperative_lease_ms_snapshot = - cooperative_lease_ms_snapshot; + admission->cached_mapping_generation = response.binding.target_mapping_generation; + admission->cooperative_lease_ms_snapshot = cooperative_lease_ms_snapshot; admission->socket_fd = fd; *out = admission; - return external_fence_admit_result( - PGRAC_EXTERNAL_FENCE_WRITE_EXCLUDED, - PGRAC_EXTERNAL_FENCE_DENY_NONE, response.journal_seq, - response.verified_mono_ns); + return external_fence_admit_result(PGRAC_EXTERNAL_FENCE_WRITE_EXCLUDED, + PGRAC_EXTERNAL_FENCE_DENY_NONE, response.journal_seq, + response.verified_mono_ns); } #endif } bool -cluster_external_fence_revalidate_nowait( - const PgracExternalFenceAdmissionV1 *admission, - const PgracExternalFenceNeedV1 *current, - PgracExternalFenceDenyReason *reason) +cluster_external_fence_revalidate_nowait(const PgracExternalFenceAdmissionV1 *admission, + const PgracExternalFenceNeedV1 *current, + PgracExternalFenceDenyReason *reason) { uint64 now_ns; if (reason == NULL) return false; - if (!external_fence_admission_valid(admission) || - !external_fence_need_valid(current)) - { + if (!external_fence_admission_valid(admission) || !external_fence_need_valid(current)) { *reason = PGRAC_EXTERNAL_FENCE_DENY_BAD_ARGUMENT; return false; } - if (!external_fence_binding_matches_need(&admission->binding, current)) - { + if (!external_fence_binding_matches_need(&admission->binding, current)) { *reason = PGRAC_EXTERNAL_FENCE_DENY_BINDING_MISMATCH; return false; } - if (admission->binding.target_mapping_generation == 0 || - admission->cached_mapping_generation != - admission->binding.target_mapping_generation) - { + if (admission->binding.target_mapping_generation == 0 + || admission->cached_mapping_generation != admission->binding.target_mapping_generation) { *reason = PGRAC_EXTERNAL_FENCE_DENY_MAPPING_CHANGED; return false; } - if (!bytes_nonzero(admission->daemon_boot_id, - sizeof(admission->daemon_boot_id)) || - admission->journal_seq == 0 || admission->proof_generation == 0) - { + if (!bytes_nonzero(admission->daemon_boot_id, sizeof(admission->daemon_boot_id)) + || admission->journal_seq == 0 || admission->proof_generation == 0) { *reason = PGRAC_EXTERNAL_FENCE_DENY_PROTOCOL; return false; } @@ -1331,33 +1174,28 @@ cluster_external_fence_revalidate_nowait( struct timespec now; struct pollfd poll_fd; - if (clock_gettime(CLOCK_MONOTONIC, &now) != 0) - { + if (clock_gettime(CLOCK_MONOTONIC, &now) != 0) { *reason = PGRAC_EXTERNAL_FENCE_DENY_EXPIRED; return false; } - now_ns = (uint64) now.tv_sec * UINT64_C(1000000000) + - (uint64) now.tv_nsec; - if (now_ns < admission->verified_mono_ns || - now_ns >= admission->fresh_until_mono_ns || - admission->fresh_until_mono_ns <= admission->verified_mono_ns || - admission->fresh_until_mono_ns - admission->verified_mono_ns > - PGRAC_EXTERNAL_FENCE_MAX_FRESHNESS_NS) - { + now_ns = (uint64)now.tv_sec * UINT64_C(1000000000) + (uint64)now.tv_nsec; + if (now_ns < admission->verified_mono_ns || now_ns >= admission->fresh_until_mono_ns + || admission->fresh_until_mono_ns <= admission->verified_mono_ns + || admission->fresh_until_mono_ns - admission->verified_mono_ns + > PGRAC_EXTERNAL_FENCE_MAX_FRESHNESS_NS) { *reason = PGRAC_EXTERNAL_FENCE_DENY_EXPIRED; return false; } poll_fd.fd = admission->socket_fd; poll_fd.events = POLLIN | POLLHUP | POLLERR; poll_fd.revents = 0; - if (poll(&poll_fd, 1, 0) != 0) - { + if (poll(&poll_fd, 1, 0) != 0) { *reason = PGRAC_EXTERNAL_FENCE_DENY_CONNECTION_CLOSED; return false; } } #else - (void) now_ns; + (void)now_ns; *reason = PGRAC_EXTERNAL_FENCE_DENY_DAEMON_UNAVAILABLE; return false; #endif @@ -1366,10 +1204,9 @@ cluster_external_fence_revalidate_nowait( } PgracExternalFenceVerdict -cluster_external_fence_admit_set_wait( - const PgracExternalFenceNeedSetV1 *needs, - const ClusterFormationWitnessV1 *formation, int timeout_ms, - PgracExternalFenceAdmissionSetV1 **out) +cluster_external_fence_admit_set_wait(const PgracExternalFenceNeedSetV1 *needs, + const ClusterFormationWitnessV1 *formation, int timeout_ms, + PgracExternalFenceAdmissionSetV1 **out) { PgracExternalFenceAdmissionSetV1 *set; PgracExternalFenceDenyReason reason; @@ -1383,15 +1220,12 @@ cluster_external_fence_admit_set_wait( if (out != NULL) *out = NULL; - if (out == NULL || timeout_ms < 1 || timeout_ms > 600000 || - !external_fence_need_set_valid(needs) || formation == NULL) - { + if (out == NULL || timeout_ms < 1 || timeout_ms > 600000 + || !external_fence_need_set_valid(needs) || formation == NULL) { external_fence_last_deny = PGRAC_EXTERNAL_FENCE_DENY_BAD_ARGUMENT; return PGRAC_EXTERNAL_FENCE_UNAVAILABLE; } - if (!cluster_external_fence_need_set_revalidate_nowait(needs, formation, - &reason)) - { + if (!cluster_external_fence_need_set_revalidate_nowait(needs, formation, &reason)) { external_fence_last_deny = reason; return PGRAC_EXTERNAL_FENCE_UNAVAILABLE; } @@ -1400,14 +1234,12 @@ cluster_external_fence_admit_set_wait( external_fence_last_deny = PGRAC_EXTERNAL_FENCE_DENY_DAEMON_UNAVAILABLE; return PGRAC_EXTERNAL_FENCE_UNAVAILABLE; #else - if (!external_fence_monotonic_now(&now_ns)) - { + if (!external_fence_monotonic_now(&now_ns)) { external_fence_last_deny = PGRAC_EXTERNAL_FENCE_DENY_TIMEOUT; return PGRAC_EXTERNAL_FENCE_UNAVAILABLE; } - timeout_ns = (uint64) timeout_ms * UINT64_C(1000000); - if (UINT64_MAX - now_ns < timeout_ns) - { + timeout_ns = (uint64)timeout_ms * UINT64_C(1000000); + if (UINT64_MAX - now_ns < timeout_ns) { external_fence_last_deny = PGRAC_EXTERNAL_FENCE_DENY_TIMEOUT; return PGRAC_EXTERNAL_FENCE_UNAVAILABLE; } @@ -1417,44 +1249,35 @@ cluster_external_fence_admit_set_wait( set->owner_pid = external_fence_owner_pid(); set->writer_set_digest = needs->writer_set_digest; set->formation = formation; - for (i = 0; i < needs->count; i++) - { + for (i = 0; i < needs->count; i++) { PgracExternalFenceVerdict verdict; uint64 remaining_ns; uint64 remaining_ms; - if (!external_fence_monotonic_now(&now_ns) || now_ns >= deadline_ns) - { + if (!external_fence_monotonic_now(&now_ns) || now_ns >= deadline_ns) { external_fence_last_deny = PGRAC_EXTERNAL_FENCE_DENY_TIMEOUT; cluster_external_fence_admission_set_release(&set); return PGRAC_EXTERNAL_FENCE_UNAVAILABLE; } remaining_ns = deadline_ns - now_ns; - remaining_ms = (remaining_ns + UINT64_C(999999)) / - UINT64_C(1000000); + remaining_ms = (remaining_ns + UINT64_C(999999)) / UINT64_C(1000000); if (remaining_ms > PGRAC_EXTERNAL_FENCE_TIMEOUT_MAX_MS) remaining_ms = PGRAC_EXTERNAL_FENCE_TIMEOUT_MAX_MS; - verdict = cluster_external_fence_admit_wait(&needs->needs[i], - (int) remaining_ms, &set->admissions[i]); - if (verdict != PGRAC_EXTERNAL_FENCE_WRITE_EXCLUDED || - set->admissions[i] == NULL) - { + verdict = cluster_external_fence_admit_wait(&needs->needs[i], (int)remaining_ms, + &set->admissions[i]); + if (verdict != PGRAC_EXTERNAL_FENCE_WRITE_EXCLUDED || set->admissions[i] == NULL) { cluster_external_fence_admission_set_release(&set); return verdict; } - set->admissions[i]->cooperative_lease_ms_snapshot = - cooperative_lease_ms_snapshot; + set->admissions[i]->cooperative_lease_ms_snapshot = cooperative_lease_ms_snapshot; set->count++; } - if (!external_fence_monotonic_now(&now_ns) || now_ns >= deadline_ns) - { + if (!external_fence_monotonic_now(&now_ns) || now_ns >= deadline_ns) { external_fence_last_deny = PGRAC_EXTERNAL_FENCE_DENY_TIMEOUT; cluster_external_fence_admission_set_release(&set); return PGRAC_EXTERNAL_FENCE_UNAVAILABLE; } - if (!cluster_external_fence_revalidate_set_nowait(set, needs, formation, - &reason)) - { + if (!cluster_external_fence_revalidate_set_nowait(set, needs, formation, &reason)) { external_fence_last_deny = reason; cluster_external_fence_admission_set_release(&set); return PGRAC_EXTERNAL_FENCE_UNAVAILABLE; @@ -1466,37 +1289,33 @@ cluster_external_fence_admit_set_wait( } bool -cluster_external_fence_revalidate_set_nowait( - const PgracExternalFenceAdmissionSetV1 *admissions, - const PgracExternalFenceNeedSetV1 *needs, - const ClusterFormationWitnessV1 *formation, - PgracExternalFenceDenyReason *reason) +cluster_external_fence_revalidate_set_nowait(const PgracExternalFenceAdmissionSetV1 *admissions, + const PgracExternalFenceNeedSetV1 *needs, + const ClusterFormationWitnessV1 *formation, + PgracExternalFenceDenyReason *reason) { uint32 i; if (reason == NULL) return false; - if (!external_fence_admission_set_valid(admissions) || - !external_fence_need_set_valid(needs) || formation == NULL) - { + if (!external_fence_admission_set_valid(admissions) || !external_fence_need_set_valid(needs) + || formation == NULL) { *reason = PGRAC_EXTERNAL_FENCE_DENY_BAD_ARGUMENT; return false; } - if (admissions->formation != formation || needs->formation != formation || - admissions->count != needs->count || - memcmp(&admissions->writer_set_digest, &needs->writer_set_digest, - sizeof(admissions->writer_set_digest)) != 0) - { + if (admissions->formation != formation || needs->formation != formation + || admissions->count != needs->count + || memcmp(&admissions->writer_set_digest, &needs->writer_set_digest, + sizeof(admissions->writer_set_digest)) + != 0) { *reason = PGRAC_EXTERNAL_FENCE_DENY_WRITER_SET_STALE; return false; } - if (!cluster_external_fence_need_set_revalidate_nowait(needs, formation, - reason)) + if (!cluster_external_fence_need_set_revalidate_nowait(needs, formation, reason)) return false; - for (i = 0; i < admissions->count; i++) - { - if (!cluster_external_fence_revalidate_nowait( - admissions->admissions[i], &needs->needs[i], reason)) + for (i = 0; i < admissions->count; i++) { + if (!cluster_external_fence_revalidate_nowait(admissions->admissions[i], &needs->needs[i], + reason)) return false; } *reason = PGRAC_EXTERNAL_FENCE_DENY_NONE; @@ -1510,11 +1329,9 @@ cluster_external_fence_need_set_count(const PgracExternalFenceNeedSetV1 *set) } const PgracExternalFenceNeedV1 * -cluster_external_fence_need_set_at(const PgracExternalFenceNeedSetV1 *set, - uint32 index) +cluster_external_fence_need_set_at(const PgracExternalFenceNeedSetV1 *set, uint32 index) { - return external_fence_need_set_valid(set) && index < set->count - ? &set->needs[index] : NULL; + return external_fence_need_set_valid(set) && index < set->count ? &set->needs[index] : NULL; } const PgracExternalFenceWriterSetDigest * @@ -1526,11 +1343,9 @@ cluster_external_fence_need_set_digest(const PgracExternalFenceNeedSetV1 *set) void cluster_external_fence_need_set_release(PgracExternalFenceNeedSetV1 **set) { - if (set != NULL) - { - if (*set != NULL && (*set)->magic == PGRAC_EXTERNAL_FENCE_NEED_SET_MAGIC && - (*set)->owner_pid == external_fence_owner_pid()) - { + if (set != NULL) { + if (*set != NULL && (*set)->magic == PGRAC_EXTERNAL_FENCE_NEED_SET_MAGIC + && (*set)->owner_pid == external_fence_owner_pid()) { (*set)->released = 1; explicit_bzero(*set, sizeof(**set)); pfree(*set); @@ -1540,34 +1355,29 @@ cluster_external_fence_need_set_release(PgracExternalFenceNeedSetV1 **set) } const PgracExternalFenceBindingV1 * -cluster_external_fence_admission_binding( - const PgracExternalFenceAdmissionV1 *admission) +cluster_external_fence_admission_binding(const PgracExternalFenceAdmissionV1 *admission) { - return external_fence_admission_valid(admission) ? - &admission->binding : NULL; + return external_fence_admission_valid(admission) ? &admission->binding : NULL; } #ifdef USE_CLUSTER_UNIT int -cluster_external_fence_test_admission_lease_ms( - const PgracExternalFenceAdmissionV1 *admission) +cluster_external_fence_test_admission_lease_ms(const PgracExternalFenceAdmissionV1 *admission) { - return external_fence_admission_valid(admission) ? - admission->cooperative_lease_ms_snapshot : -1; + return external_fence_admission_valid(admission) ? admission->cooperative_lease_ms_snapshot + : -1; } #endif void -cluster_external_fence_admission_release( - PgracExternalFenceAdmissionV1 *admission) +cluster_external_fence_admission_release(PgracExternalFenceAdmissionV1 *admission) { - if (admission == NULL || - admission->magic != PGRAC_EXTERNAL_FENCE_ADMISSION_MAGIC || - admission->owner_pid != external_fence_owner_pid()) + if (admission == NULL || admission->magic != PGRAC_EXTERNAL_FENCE_ADMISSION_MAGIC + || admission->owner_pid != external_fence_owner_pid()) return; #ifndef WIN32 if (admission->socket_fd >= 0) - (void) close(admission->socket_fd); + (void)close(admission->socket_fd); #endif admission->released = 1; explicit_bzero(admission, sizeof(*admission)); @@ -1575,15 +1385,14 @@ cluster_external_fence_admission_release( } uint32 -cluster_external_fence_admission_set_count( - const PgracExternalFenceAdmissionSetV1 *set) +cluster_external_fence_admission_set_count(const PgracExternalFenceAdmissionSetV1 *set) { return external_fence_admission_set_valid(set) ? set->count : 0; } const PgracExternalFenceBindingV1 * -cluster_external_fence_admission_set_binding_at( - const PgracExternalFenceAdmissionSetV1 *set, uint32 index) +cluster_external_fence_admission_set_binding_at(const PgracExternalFenceAdmissionSetV1 *set, + uint32 index) { if (!external_fence_admission_set_valid(set) || index >= set->count) return NULL; @@ -1591,30 +1400,22 @@ cluster_external_fence_admission_set_binding_at( } const PgracExternalFenceWriterSetDigest * -cluster_external_fence_admission_set_digest( - const PgracExternalFenceAdmissionSetV1 *set) +cluster_external_fence_admission_set_digest(const PgracExternalFenceAdmissionSetV1 *set) { - return external_fence_admission_set_valid(set) ? - &set->writer_set_digest : NULL; + return external_fence_admission_set_valid(set) ? &set->writer_set_digest : NULL; } void -cluster_external_fence_admission_set_release( - PgracExternalFenceAdmissionSetV1 **set) +cluster_external_fence_admission_set_release(PgracExternalFenceAdmissionSetV1 **set) { - if (set != NULL) - { - if (*set != NULL && - (*set)->magic == PGRAC_EXTERNAL_FENCE_ADMISSION_SET_MAGIC && - (*set)->owner_pid == external_fence_owner_pid()) - { + if (set != NULL) { + if (*set != NULL && (*set)->magic == PGRAC_EXTERNAL_FENCE_ADMISSION_SET_MAGIC + && (*set)->owner_pid == external_fence_owner_pid()) { uint32 i = (*set)->count; - while (i > 0) - { + while (i > 0) { i--; - cluster_external_fence_admission_release( - (*set)->admissions[i]); + cluster_external_fence_admission_release((*set)->admissions[i]); (*set)->admissions[i] = NULL; } (*set)->released = 1; @@ -1626,9 +1427,8 @@ cluster_external_fence_admission_set_release( } static PgracExternalFenceRejoinStatus -external_fence_rejoin_fail(PgracExternalFenceRejoinStatus status, - PgracExternalFenceDenyReason deny, - PgracExternalFenceDenyReason *reason) +external_fence_rejoin_fail(PgracExternalFenceRejoinStatus status, PgracExternalFenceDenyReason deny, + PgracExternalFenceDenyReason *reason) { external_fence_last_deny = deny; if (reason != NULL) @@ -1642,11 +1442,10 @@ external_fence_monotonic_now(uint64 *out_now_ns) { struct timespec now; - if (out_now_ns == NULL || clock_gettime(CLOCK_MONOTONIC, &now) != 0 || - now.tv_sec < 0 || now.tv_nsec < 0) + if (out_now_ns == NULL || clock_gettime(CLOCK_MONOTONIC, &now) != 0 || now.tv_sec < 0 + || now.tv_nsec < 0) return false; - *out_now_ns = (uint64) now.tv_sec * UINT64_C(1000000000) + - (uint64) now.tv_nsec; + *out_now_ns = (uint64)now.tv_sec * UINT64_C(1000000000) + (uint64)now.tv_nsec; return true; } @@ -1659,12 +1458,9 @@ external_fence_root_peer_authenticated(int fd) struct ucred credential; socklen_t credential_len = sizeof(credential); - return getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &credential, - &credential_len) == 0 && - credential_len == sizeof(credential) && credential.uid == 0 && - credential.pid > 0; -#elif defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) || \ - defined(__NetBSD__) + return getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &credential, &credential_len) == 0 + && credential_len == sizeof(credential) && credential.uid == 0 && credential.pid > 0; +#elif defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) uid_t uid; gid_t gid; @@ -1677,165 +1473,142 @@ external_fence_root_peer_authenticated(int fd) static void external_fence_rejoin_close(PgracExternalFenceRejoinOpV1 *op) { - if (op->socket_fd >= 0) - { - (void) close(op->socket_fd); + if (op->socket_fd >= 0) { + (void)close(op->socket_fd); op->socket_fd = -1; } } static PgracExternalFenceRejoinStatus external_fence_rejoin_terminal(PgracExternalFenceRejoinOpV1 *op, - PgracExternalFenceRejoinStatus status, - PgracExternalFenceDenyReason deny, - PgracExternalFenceDenyReason *reason) + PgracExternalFenceRejoinStatus status, + PgracExternalFenceDenyReason deny, + PgracExternalFenceDenyReason *reason) { - op->status = (uint32) status; - op->deny_reason = (uint32) deny; + op->status = (uint32)status; + op->deny_reason = (uint32)deny; external_fence_rejoin_close(op); return external_fence_rejoin_fail(status, deny, reason); } static bool -external_fence_rejoin_offer_valid( - const PgracExternalFenceRejoinOpV1 *op, - const PgracExternalFenceProtocolRejoinFrameV1 *response, - uint64 now_ns) -{ - return response->opcode == PGRAC_EXTERNAL_FENCE_REJOIN_LMON_OFFER && - response->status == PGRAC_EXTERNAL_FENCE_REJOIN_OFFERED && - response->deny_reason == PGRAC_EXTERNAL_FENCE_DENY_NONE && - memcmp(response->transport_nonce, op->transport_nonce, - sizeof(op->transport_nonce)) == 0 && - bytes_nonzero(response->operation_id, - sizeof(response->operation_id)) && - !bytes_nonzero(response->rejoin_gate_digest, - sizeof(response->rejoin_gate_digest)) && - response->system_identifier != 0 && - bytes_nonzero(response->protected_set_digest, - sizeof(response->protected_set_digest)) && - response->old_node_id >= 0 && - response->old_node_id < CLUSTER_MAX_NODES && - response->old_incarnation != 0 && - response->candidate_incarnation > response->old_incarnation && - response->provider_id != 0 && - response->provider_abi_version == 1 && - response->target_mapping_generation != 0 && - bytes_nonzero(response->daemon_boot_id, - sizeof(response->daemon_boot_id)) && - response->journal_seq != 0 && - response->verified_mono_ns != 0 && - response->fresh_until_mono_ns > response->verified_mono_ns && - response->fresh_until_mono_ns - response->verified_mono_ns <= - PGRAC_EXTERNAL_FENCE_MAX_FRESHNESS_NS && - response->verified_mono_ns <= now_ns && - now_ns < response->fresh_until_mono_ns && - now_ns < op->deadline_mono_ns && - response->proof_generation != 0 && - bytes_nonzero(response->target_state_digest, - sizeof(response->target_state_digest)); +external_fence_rejoin_offer_valid(const PgracExternalFenceRejoinOpV1 *op, + const PgracExternalFenceProtocolRejoinFrameV1 *response, + uint64 now_ns) +{ + return response->opcode == PGRAC_EXTERNAL_FENCE_REJOIN_LMON_OFFER + && response->status == PGRAC_EXTERNAL_FENCE_REJOIN_OFFERED + && response->deny_reason == PGRAC_EXTERNAL_FENCE_DENY_NONE + && memcmp(response->transport_nonce, op->transport_nonce, sizeof(op->transport_nonce)) + == 0 + && bytes_nonzero(response->operation_id, sizeof(response->operation_id)) + && !bytes_nonzero(response->rejoin_gate_digest, sizeof(response->rejoin_gate_digest)) + && response->system_identifier != 0 + && bytes_nonzero(response->protected_set_digest, sizeof(response->protected_set_digest)) + && response->old_node_id >= 0 && response->old_node_id < CLUSTER_MAX_NODES + && response->old_incarnation != 0 + && response->candidate_incarnation > response->old_incarnation + && response->provider_id != 0 && response->provider_abi_version == 1 + && response->target_mapping_generation != 0 + && bytes_nonzero(response->daemon_boot_id, sizeof(response->daemon_boot_id)) + && response->journal_seq != 0 && response->verified_mono_ns != 0 + && response->fresh_until_mono_ns > response->verified_mono_ns + && response->fresh_until_mono_ns - response->verified_mono_ns + <= PGRAC_EXTERNAL_FENCE_MAX_FRESHNESS_NS + && response->verified_mono_ns <= now_ns && now_ns < response->fresh_until_mono_ns + && now_ns < op->deadline_mono_ns && response->proof_generation != 0 + && bytes_nonzero(response->target_state_digest, sizeof(response->target_state_digest)); } static bool -external_fence_rejoin_on_result_valid( - const PgracExternalFenceRejoinOpV1 *op, - const PgracExternalFenceProtocolRejoinFrameV1 *response, - uint64 now_ns) -{ - return response->opcode == - PGRAC_EXTERNAL_FENCE_REJOIN_LMON_ON_RESULT && - response->status == PGRAC_EXTERNAL_FENCE_REJOIN_WAITING_JOINER && - response->deny_reason == PGRAC_EXTERNAL_FENCE_DENY_NONE && - memcmp(response->transport_nonce, op->transport_nonce, - sizeof(op->transport_nonce)) == 0 && - memcmp(response->operation_id, op->offer_frame.operation_id, - sizeof(response->operation_id)) == 0 && - response->system_identifier == op->rejoin_need.system_identifier && - memcmp(response->rejoin_gate_digest, - op->rejoin_need.rejoin_gate_digest, - sizeof(response->rejoin_gate_digest)) == 0 && - memcmp(response->protected_set_digest, - op->rejoin_need.protected_set_digest, - sizeof(response->protected_set_digest)) == 0 && - response->old_node_id == op->rejoin_need.old_node_id && - response->old_incarnation == op->rejoin_need.old_incarnation && - response->candidate_incarnation == - op->rejoin_need.candidate_incarnation && - response->provider_id == op->offer_frame.provider_id && - response->provider_abi_version == - op->offer_frame.provider_abi_version && - response->target_mapping_generation == - op->offer_frame.target_mapping_generation && - memcmp(response->daemon_boot_id, op->offer_frame.daemon_boot_id, - sizeof(response->daemon_boot_id)) == 0 && - response->journal_seq > op->offer_frame.journal_seq && - response->proof_generation > op->offer_frame.proof_generation && - response->verified_mono_ns != 0 && - response->fresh_until_mono_ns > response->verified_mono_ns && - response->fresh_until_mono_ns - response->verified_mono_ns <= - PGRAC_EXTERNAL_FENCE_MAX_FRESHNESS_NS && - response->verified_mono_ns <= now_ns && - now_ns < response->fresh_until_mono_ns && - now_ns < op->deadline_mono_ns && - bytes_nonzero(response->target_state_digest, - sizeof(response->target_state_digest)) && - memcmp(response->target_state_digest, - op->offer_frame.target_state_digest, - sizeof(response->target_state_digest)) != 0; +external_fence_rejoin_on_result_valid(const PgracExternalFenceRejoinOpV1 *op, + const PgracExternalFenceProtocolRejoinFrameV1 *response, + uint64 now_ns) +{ + return response->opcode == PGRAC_EXTERNAL_FENCE_REJOIN_LMON_ON_RESULT + && response->status == PGRAC_EXTERNAL_FENCE_REJOIN_WAITING_JOINER + && response->deny_reason == PGRAC_EXTERNAL_FENCE_DENY_NONE + && memcmp(response->transport_nonce, op->transport_nonce, sizeof(op->transport_nonce)) + == 0 + && memcmp(response->operation_id, op->offer_frame.operation_id, + sizeof(response->operation_id)) + == 0 + && response->system_identifier == op->rejoin_need.system_identifier + && memcmp(response->rejoin_gate_digest, op->rejoin_need.rejoin_gate_digest, + sizeof(response->rejoin_gate_digest)) + == 0 + && memcmp(response->protected_set_digest, op->rejoin_need.protected_set_digest, + sizeof(response->protected_set_digest)) + == 0 + && response->old_node_id == op->rejoin_need.old_node_id + && response->old_incarnation == op->rejoin_need.old_incarnation + && response->candidate_incarnation == op->rejoin_need.candidate_incarnation + && response->provider_id == op->offer_frame.provider_id + && response->provider_abi_version == op->offer_frame.provider_abi_version + && response->target_mapping_generation == op->offer_frame.target_mapping_generation + && memcmp(response->daemon_boot_id, op->offer_frame.daemon_boot_id, + sizeof(response->daemon_boot_id)) + == 0 + && response->journal_seq > op->offer_frame.journal_seq + && response->proof_generation > op->offer_frame.proof_generation + && response->verified_mono_ns != 0 + && response->fresh_until_mono_ns > response->verified_mono_ns + && response->fresh_until_mono_ns - response->verified_mono_ns + <= PGRAC_EXTERNAL_FENCE_MAX_FRESHNESS_NS + && response->verified_mono_ns <= now_ns && now_ns < response->fresh_until_mono_ns + && now_ns < op->deadline_mono_ns + && bytes_nonzero(response->target_state_digest, sizeof(response->target_state_digest)) + && memcmp(response->target_state_digest, op->offer_frame.target_state_digest, + sizeof(response->target_state_digest)) + != 0; } static bool -external_fence_rejoin_refresh_result_valid( - const PgracExternalFenceRejoinOpV1 *op, - const PgracExternalFenceProtocolRejoinFrameV1 *response, - uint64 now_ns) -{ - return response->opcode == - PGRAC_EXTERNAL_FENCE_REJOIN_LMON_REFRESH_RESULT && - response->status == PGRAC_EXTERNAL_FENCE_REJOIN_READY && - response->deny_reason == PGRAC_EXTERNAL_FENCE_DENY_NONE && - memcmp(response->transport_nonce, op->transport_nonce, - sizeof(op->transport_nonce)) == 0 && - memcmp(response->operation_id, op->offer_frame.operation_id, - sizeof(response->operation_id)) == 0 && - response->system_identifier == op->rejoin_need.system_identifier && - memcmp(response->rejoin_gate_digest, - op->rejoin_need.rejoin_gate_digest, - sizeof(response->rejoin_gate_digest)) == 0 && - memcmp(response->protected_set_digest, - op->rejoin_need.protected_set_digest, - sizeof(response->protected_set_digest)) == 0 && - response->old_node_id == op->rejoin_need.old_node_id && - response->old_incarnation == op->rejoin_need.old_incarnation && - response->candidate_incarnation == - op->rejoin_need.candidate_incarnation && - response->provider_id == op->offer_frame.provider_id && - response->provider_abi_version == - op->offer_frame.provider_abi_version && - response->target_mapping_generation == - op->offer_frame.target_mapping_generation && - memcmp(response->daemon_boot_id, op->offer_frame.daemon_boot_id, - sizeof(response->daemon_boot_id)) == 0 && - response->journal_seq > op->on_frame.journal_seq && - response->proof_generation > op->on_frame.proof_generation && - response->verified_mono_ns != 0 && - response->fresh_until_mono_ns > response->verified_mono_ns && - response->fresh_until_mono_ns - response->verified_mono_ns <= - PGRAC_EXTERNAL_FENCE_MAX_FRESHNESS_NS && - response->verified_mono_ns <= now_ns && - now_ns < response->fresh_until_mono_ns && - now_ns < op->deadline_mono_ns && - bytes_nonzero(response->target_state_digest, - sizeof(response->target_state_digest)) && - memcmp(response->target_state_digest, - op->on_frame.target_state_digest, - sizeof(response->target_state_digest)) != 0; +external_fence_rejoin_refresh_result_valid(const PgracExternalFenceRejoinOpV1 *op, + const PgracExternalFenceProtocolRejoinFrameV1 *response, + uint64 now_ns) +{ + return response->opcode == PGRAC_EXTERNAL_FENCE_REJOIN_LMON_REFRESH_RESULT + && response->status == PGRAC_EXTERNAL_FENCE_REJOIN_READY + && response->deny_reason == PGRAC_EXTERNAL_FENCE_DENY_NONE + && memcmp(response->transport_nonce, op->transport_nonce, sizeof(op->transport_nonce)) + == 0 + && memcmp(response->operation_id, op->offer_frame.operation_id, + sizeof(response->operation_id)) + == 0 + && response->system_identifier == op->rejoin_need.system_identifier + && memcmp(response->rejoin_gate_digest, op->rejoin_need.rejoin_gate_digest, + sizeof(response->rejoin_gate_digest)) + == 0 + && memcmp(response->protected_set_digest, op->rejoin_need.protected_set_digest, + sizeof(response->protected_set_digest)) + == 0 + && response->old_node_id == op->rejoin_need.old_node_id + && response->old_incarnation == op->rejoin_need.old_incarnation + && response->candidate_incarnation == op->rejoin_need.candidate_incarnation + && response->provider_id == op->offer_frame.provider_id + && response->provider_abi_version == op->offer_frame.provider_abi_version + && response->target_mapping_generation == op->offer_frame.target_mapping_generation + && memcmp(response->daemon_boot_id, op->offer_frame.daemon_boot_id, + sizeof(response->daemon_boot_id)) + == 0 + && response->journal_seq > op->on_frame.journal_seq + && response->proof_generation > op->on_frame.proof_generation + && response->verified_mono_ns != 0 + && response->fresh_until_mono_ns > response->verified_mono_ns + && response->fresh_until_mono_ns - response->verified_mono_ns + <= PGRAC_EXTERNAL_FENCE_MAX_FRESHNESS_NS + && response->verified_mono_ns <= now_ns && now_ns < response->fresh_until_mono_ns + && now_ns < op->deadline_mono_ns + && bytes_nonzero(response->target_state_digest, sizeof(response->target_state_digest)) + && memcmp(response->target_state_digest, op->on_frame.target_state_digest, + sizeof(response->target_state_digest)) + != 0; } #endif PgracExternalFenceRejoinStatus -cluster_external_fence_rejoin_start_async( - int timeout_ms, PgracExternalFenceRejoinOpV1 **out_op) +cluster_external_fence_rejoin_start_async(int timeout_ms, PgracExternalFenceRejoinOpV1 **out_op) { PgracExternalFenceRejoinOpV1 *op; #ifndef WIN32 @@ -1853,32 +1626,26 @@ cluster_external_fence_rejoin_start_async( if (out_op != NULL) *out_op = NULL; if (out_op == NULL || timeout_ms < 1 || timeout_ms > 600000) - return external_fence_rejoin_fail( - PGRAC_EXTERNAL_FENCE_REJOIN_UNAVAILABLE, - PGRAC_EXTERNAL_FENCE_DENY_BAD_ARGUMENT, NULL); + return external_fence_rejoin_fail(PGRAC_EXTERNAL_FENCE_REJOIN_UNAVAILABLE, + PGRAC_EXTERNAL_FENCE_DENY_BAD_ARGUMENT, NULL); #ifdef WIN32 external_fence_record_result(PGRAC_EXTERNAL_FENCE_UNAVAILABLE, - PGRAC_EXTERNAL_FENCE_DENY_DAEMON_UNAVAILABLE, 0, 0); - return external_fence_rejoin_fail( - PGRAC_EXTERNAL_FENCE_REJOIN_UNAVAILABLE, - PGRAC_EXTERNAL_FENCE_DENY_DAEMON_UNAVAILABLE, NULL); + PGRAC_EXTERNAL_FENCE_DENY_DAEMON_UNAVAILABLE, 0, 0); + return external_fence_rejoin_fail(PGRAC_EXTERNAL_FENCE_REJOIN_UNAVAILABLE, + PGRAC_EXTERNAL_FENCE_DENY_DAEMON_UNAVAILABLE, NULL); #else - if (cluster_external_fence_socket_path == NULL || - cluster_external_fence_socket_path[0] != '/' || - strlen(cluster_external_fence_socket_path) >= sizeof(address.sun_path)) - return external_fence_rejoin_fail( - PGRAC_EXTERNAL_FENCE_REJOIN_UNAVAILABLE, - PGRAC_EXTERNAL_FENCE_DENY_SOCKET_CONFIG, NULL); + if (cluster_external_fence_socket_path == NULL || cluster_external_fence_socket_path[0] != '/' + || strlen(cluster_external_fence_socket_path) >= sizeof(address.sun_path)) + return external_fence_rejoin_fail(PGRAC_EXTERNAL_FENCE_REJOIN_UNAVAILABLE, + PGRAC_EXTERNAL_FENCE_DENY_SOCKET_CONFIG, NULL); if (!external_fence_monotonic_now(&now_ns)) - return external_fence_rejoin_fail( - PGRAC_EXTERNAL_FENCE_REJOIN_UNAVAILABLE, - PGRAC_EXTERNAL_FENCE_DENY_TIMEOUT, NULL); - timeout_ns = (uint64) timeout_ms * UINT64_C(1000000); + return external_fence_rejoin_fail(PGRAC_EXTERNAL_FENCE_REJOIN_UNAVAILABLE, + PGRAC_EXTERNAL_FENCE_DENY_TIMEOUT, NULL); + timeout_ns = (uint64)timeout_ms * UINT64_C(1000000); if (UINT64_MAX - now_ns < timeout_ns) - return external_fence_rejoin_fail( - PGRAC_EXTERNAL_FENCE_REJOIN_UNAVAILABLE, - PGRAC_EXTERNAL_FENCE_DENY_TIMEOUT, NULL); + return external_fence_rejoin_fail(PGRAC_EXTERNAL_FENCE_REJOIN_UNAVAILABLE, + PGRAC_EXTERNAL_FENCE_DENY_TIMEOUT, NULL); op = palloc0(sizeof(*op)); op->magic = PGRAC_EXTERNAL_FENCE_REJOIN_OP_MAGIC; @@ -1887,15 +1654,13 @@ cluster_external_fence_rejoin_start_async( op->deny_reason = PGRAC_EXTERNAL_FENCE_DENY_NONE; op->socket_fd = -1; op->deadline_mono_ns = now_ns + timeout_ns; - if (!pg_strong_random(op->transport_nonce, - sizeof(op->transport_nonce)) || - !bytes_nonzero(op->transport_nonce, sizeof(op->transport_nonce))) + if (!pg_strong_random(op->transport_nonce, sizeof(op->transport_nonce)) + || !bytes_nonzero(op->transport_nonce, sizeof(op->transport_nonce))) goto protocol_failure; memset(&claim, 0, sizeof(claim)); claim.opcode = PGRAC_EXTERNAL_FENCE_REJOIN_LMON_CLAIM_NEXT; - memcpy(claim.transport_nonce, op->transport_nonce, - sizeof(claim.transport_nonce)); + memcpy(claim.transport_nonce, op->transport_nonce, sizeof(claim.transport_nonce)); claim.status = PGRAC_EXTERNAL_FENCE_REJOIN_PENDING; claim.deny_reason = PGRAC_EXTERNAL_FENCE_DENY_NONE; if (!pgrac_external_fence_rejoin_v1_encode(&claim, op->tx_frame)) @@ -1908,18 +1673,14 @@ cluster_external_fence_rejoin_start_async( if (flags < 0 || fcntl(op->socket_fd, F_SETFL, flags | O_NONBLOCK) < 0) goto socket_failure; #ifdef SO_NOSIGPIPE - if (setsockopt(op->socket_fd, SOL_SOCKET, SO_NOSIGPIPE, - &no_sigpipe, sizeof(no_sigpipe)) != 0) + if (setsockopt(op->socket_fd, SOL_SOCKET, SO_NOSIGPIPE, &no_sigpipe, sizeof(no_sigpipe)) != 0) goto socket_failure; #endif memset(&address, 0, sizeof(address)); address.sun_family = AF_UNIX; - strlcpy(address.sun_path, cluster_external_fence_socket_path, - sizeof(address.sun_path)); - connect_result = connect(op->socket_fd, (struct sockaddr *) &address, - sizeof(address)); - if (connect_result != 0) - { + strlcpy(address.sun_path, cluster_external_fence_socket_path, sizeof(address.sun_path)); + connect_result = connect(op->socket_fd, (struct sockaddr *)&address, sizeof(address)); + if (connect_result != 0) { if (errno != EINPROGRESS && errno != EAGAIN && errno != EWOULDBLOCK) goto daemon_unavailable; op->connect_pending = true; @@ -1932,31 +1693,27 @@ cluster_external_fence_rejoin_start_async( external_fence_rejoin_close(op); explicit_bzero(op, sizeof(*op)); pfree(op); - return external_fence_rejoin_fail( - PGRAC_EXTERNAL_FENCE_REJOIN_UNAVAILABLE, - PGRAC_EXTERNAL_FENCE_DENY_SOCKET_CONFIG, NULL); + return external_fence_rejoin_fail(PGRAC_EXTERNAL_FENCE_REJOIN_UNAVAILABLE, + PGRAC_EXTERNAL_FENCE_DENY_SOCKET_CONFIG, NULL); daemon_unavailable: external_fence_rejoin_close(op); explicit_bzero(op, sizeof(*op)); pfree(op); external_fence_record_result(PGRAC_EXTERNAL_FENCE_UNAVAILABLE, - PGRAC_EXTERNAL_FENCE_DENY_DAEMON_UNAVAILABLE, 0, 0); - return external_fence_rejoin_fail( - PGRAC_EXTERNAL_FENCE_REJOIN_UNAVAILABLE, - PGRAC_EXTERNAL_FENCE_DENY_DAEMON_UNAVAILABLE, NULL); + PGRAC_EXTERNAL_FENCE_DENY_DAEMON_UNAVAILABLE, 0, 0); + return external_fence_rejoin_fail(PGRAC_EXTERNAL_FENCE_REJOIN_UNAVAILABLE, + PGRAC_EXTERNAL_FENCE_DENY_DAEMON_UNAVAILABLE, NULL); protocol_failure: explicit_bzero(op, sizeof(*op)); pfree(op); - return external_fence_rejoin_fail( - PGRAC_EXTERNAL_FENCE_REJOIN_UNAVAILABLE, - PGRAC_EXTERNAL_FENCE_DENY_PROTOCOL, NULL); + return external_fence_rejoin_fail(PGRAC_EXTERNAL_FENCE_REJOIN_UNAVAILABLE, + PGRAC_EXTERNAL_FENCE_DENY_PROTOCOL, NULL); #endif } PgracExternalFenceRejoinStatus -cluster_external_fence_rejoin_poll_nowait( - PgracExternalFenceRejoinOpV1 *op, - PgracExternalFenceDenyReason *reason) +cluster_external_fence_rejoin_poll_nowait(PgracExternalFenceRejoinOpV1 *op, + PgracExternalFenceDenyReason *reason) { PgracExternalFenceProtocolRejoinFrameV1 response; uint16 expected_opcode; @@ -1972,259 +1729,210 @@ cluster_external_fence_rejoin_poll_nowait( #endif #endif - if (reason == NULL || op == NULL || - op->magic != PGRAC_EXTERNAL_FENCE_REJOIN_OP_MAGIC || - op->owner_pid != external_fence_owner_pid() || op->socket_fd < 0) - return external_fence_rejoin_fail( - PGRAC_EXTERNAL_FENCE_REJOIN_UNAVAILABLE, - PGRAC_EXTERNAL_FENCE_DENY_BAD_ARGUMENT, reason); - if (op->status != PGRAC_EXTERNAL_FENCE_REJOIN_PENDING) - { - *reason = (PgracExternalFenceDenyReason) op->deny_reason; - return (PgracExternalFenceRejoinStatus) op->status; + if (reason == NULL || op == NULL || op->magic != PGRAC_EXTERNAL_FENCE_REJOIN_OP_MAGIC + || op->owner_pid != external_fence_owner_pid() || op->socket_fd < 0) + return external_fence_rejoin_fail(PGRAC_EXTERNAL_FENCE_REJOIN_UNAVAILABLE, + PGRAC_EXTERNAL_FENCE_DENY_BAD_ARGUMENT, reason); + if (op->status != PGRAC_EXTERNAL_FENCE_REJOIN_PENDING) { + *reason = (PgracExternalFenceDenyReason)op->deny_reason; + return (PgracExternalFenceRejoinStatus)op->status; } #ifdef WIN32 - return external_fence_rejoin_fail( - PGRAC_EXTERNAL_FENCE_REJOIN_UNAVAILABLE, - PGRAC_EXTERNAL_FENCE_DENY_DAEMON_UNAVAILABLE, reason); + return external_fence_rejoin_fail(PGRAC_EXTERNAL_FENCE_REJOIN_UNAVAILABLE, + PGRAC_EXTERNAL_FENCE_DENY_DAEMON_UNAVAILABLE, reason); #else if (!external_fence_monotonic_now(&now_ns)) - return external_fence_rejoin_terminal(op, - PGRAC_EXTERNAL_FENCE_REJOIN_UNKNOWN, - PGRAC_EXTERNAL_FENCE_DENY_TIMEOUT, reason); + return external_fence_rejoin_terminal(op, PGRAC_EXTERNAL_FENCE_REJOIN_UNKNOWN, + PGRAC_EXTERNAL_FENCE_DENY_TIMEOUT, reason); if (now_ns >= op->deadline_mono_ns) - return external_fence_rejoin_terminal(op, - PGRAC_EXTERNAL_FENCE_REJOIN_UNKNOWN, - PGRAC_EXTERNAL_FENCE_DENY_TIMEOUT, reason); + return external_fence_rejoin_terminal(op, PGRAC_EXTERNAL_FENCE_REJOIN_UNKNOWN, + PGRAC_EXTERNAL_FENCE_DENY_TIMEOUT, reason); - if (op->connect_pending) - { + if (op->connect_pending) { poll_fd.fd = op->socket_fd; poll_fd.events = POLLOUT; poll_fd.revents = 0; - if (poll(&poll_fd, 1, 0) < 0) - { - if (errno == EINTR) - { + if (poll(&poll_fd, 1, 0) < 0) { + if (errno == EINTR) { *reason = PGRAC_EXTERNAL_FENCE_DENY_NONE; return PGRAC_EXTERNAL_FENCE_REJOIN_PENDING; } - return external_fence_rejoin_terminal(op, - PGRAC_EXTERNAL_FENCE_REJOIN_UNAVAILABLE, - PGRAC_EXTERNAL_FENCE_DENY_DAEMON_UNAVAILABLE, reason); + return external_fence_rejoin_terminal(op, PGRAC_EXTERNAL_FENCE_REJOIN_UNAVAILABLE, + PGRAC_EXTERNAL_FENCE_DENY_DAEMON_UNAVAILABLE, + reason); } - if ((poll_fd.revents & POLLOUT) == 0) - { + if ((poll_fd.revents & POLLOUT) == 0) { if ((poll_fd.revents & (POLLERR | POLLHUP | POLLNVAL)) != 0) - return external_fence_rejoin_terminal(op, - PGRAC_EXTERNAL_FENCE_REJOIN_UNAVAILABLE, - PGRAC_EXTERNAL_FENCE_DENY_DAEMON_UNAVAILABLE, reason); + return external_fence_rejoin_terminal(op, PGRAC_EXTERNAL_FENCE_REJOIN_UNAVAILABLE, + PGRAC_EXTERNAL_FENCE_DENY_DAEMON_UNAVAILABLE, + reason); *reason = PGRAC_EXTERNAL_FENCE_DENY_NONE; return PGRAC_EXTERNAL_FENCE_REJOIN_PENDING; } socket_error = 0; socket_error_len = sizeof(socket_error); - if (getsockopt(op->socket_fd, SOL_SOCKET, SO_ERROR, - &socket_error, &socket_error_len) != 0 || - socket_error != 0) - return external_fence_rejoin_terminal(op, - PGRAC_EXTERNAL_FENCE_REJOIN_UNAVAILABLE, - PGRAC_EXTERNAL_FENCE_DENY_DAEMON_UNAVAILABLE, reason); + if (getsockopt(op->socket_fd, SOL_SOCKET, SO_ERROR, &socket_error, &socket_error_len) != 0 + || socket_error != 0) + return external_fence_rejoin_terminal(op, PGRAC_EXTERNAL_FENCE_REJOIN_UNAVAILABLE, + PGRAC_EXTERNAL_FENCE_DENY_DAEMON_UNAVAILABLE, + reason); op->connect_pending = false; } - if (!op->peer_authenticated) - { + if (!op->peer_authenticated) { if (!external_fence_root_peer_authenticated(op->socket_fd)) - return external_fence_rejoin_terminal(op, - PGRAC_EXTERNAL_FENCE_REJOIN_UNAVAILABLE, - PGRAC_EXTERNAL_FENCE_DENY_PEER_AUTH, reason); + return external_fence_rejoin_terminal(op, PGRAC_EXTERNAL_FENCE_REJOIN_UNAVAILABLE, + PGRAC_EXTERNAL_FENCE_DENY_PEER_AUTH, reason); op->peer_authenticated = true; } - if (op->tx_sent < sizeof(op->tx_frame)) - { + if (op->tx_sent < sizeof(op->tx_frame)) { io_count = send(op->socket_fd, op->tx_frame + op->tx_sent, sizeof(op->tx_frame) - op->tx_sent, send_flags); - if (io_count < 0) - { - if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR) - { + if (io_count < 0) { + if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR) { *reason = PGRAC_EXTERNAL_FENCE_DENY_NONE; return PGRAC_EXTERNAL_FENCE_REJOIN_PENDING; } - return external_fence_rejoin_terminal(op, - PGRAC_EXTERNAL_FENCE_REJOIN_STALE, - PGRAC_EXTERNAL_FENCE_DENY_CONNECTION_CLOSED, reason); + return external_fence_rejoin_terminal(op, PGRAC_EXTERNAL_FENCE_REJOIN_STALE, + PGRAC_EXTERNAL_FENCE_DENY_CONNECTION_CLOSED, + reason); } if (io_count == 0) - return external_fence_rejoin_terminal(op, - PGRAC_EXTERNAL_FENCE_REJOIN_STALE, - PGRAC_EXTERNAL_FENCE_DENY_CONNECTION_CLOSED, reason); - op->tx_sent += (size_t) io_count; - if (op->tx_sent < sizeof(op->tx_frame)) - { + return external_fence_rejoin_terminal(op, PGRAC_EXTERNAL_FENCE_REJOIN_STALE, + PGRAC_EXTERNAL_FENCE_DENY_CONNECTION_CLOSED, + reason); + op->tx_sent += (size_t)io_count; + if (op->tx_sent < sizeof(op->tx_frame)) { *reason = PGRAC_EXTERNAL_FENCE_DENY_NONE; return PGRAC_EXTERNAL_FENCE_REJOIN_PENDING; } } - io_count = recv(op->socket_fd, op->rx_frame + op->rx_used, - sizeof(op->rx_frame) - op->rx_used, MSG_DONTWAIT); - if (io_count < 0) - { - if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR) - { + io_count = recv(op->socket_fd, op->rx_frame + op->rx_used, sizeof(op->rx_frame) - op->rx_used, + MSG_DONTWAIT); + if (io_count < 0) { + if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR) { *reason = PGRAC_EXTERNAL_FENCE_DENY_NONE; return PGRAC_EXTERNAL_FENCE_REJOIN_PENDING; } - return external_fence_rejoin_terminal(op, - PGRAC_EXTERNAL_FENCE_REJOIN_STALE, - PGRAC_EXTERNAL_FENCE_DENY_CONNECTION_CLOSED, reason); + return external_fence_rejoin_terminal(op, PGRAC_EXTERNAL_FENCE_REJOIN_STALE, + PGRAC_EXTERNAL_FENCE_DENY_CONNECTION_CLOSED, reason); } if (io_count == 0) - return external_fence_rejoin_terminal(op, - PGRAC_EXTERNAL_FENCE_REJOIN_STALE, - PGRAC_EXTERNAL_FENCE_DENY_CONNECTION_CLOSED, reason); - op->rx_used += (size_t) io_count; - if (op->rx_used < sizeof(op->rx_frame)) - { + return external_fence_rejoin_terminal(op, PGRAC_EXTERNAL_FENCE_REJOIN_STALE, + PGRAC_EXTERNAL_FENCE_DENY_CONNECTION_CLOSED, reason); + op->rx_used += (size_t)io_count; + if (op->rx_used < sizeof(op->rx_frame)) { *reason = PGRAC_EXTERNAL_FENCE_DENY_NONE; return PGRAC_EXTERNAL_FENCE_REJOIN_PENDING; } if (op->refresh_sent) - expected_opcode = - PGRAC_EXTERNAL_FENCE_REJOIN_LMON_REFRESH_RESULT; + expected_opcode = PGRAC_EXTERNAL_FENCE_REJOIN_LMON_REFRESH_RESULT; else if (op->moved_clear != NULL) expected_opcode = PGRAC_EXTERNAL_FENCE_REJOIN_LMON_ON_RESULT; else expected_opcode = PGRAC_EXTERNAL_FENCE_REJOIN_LMON_OFFER; - if (!pgrac_external_fence_rejoin_v1_decode( - op->rx_frame, sizeof(op->rx_frame), &response) || - response.opcode != expected_opcode || - memcmp(response.transport_nonce, op->transport_nonce, - sizeof(op->transport_nonce)) != 0) - return external_fence_rejoin_terminal(op, - PGRAC_EXTERNAL_FENCE_REJOIN_UNAVAILABLE, - PGRAC_EXTERNAL_FENCE_DENY_PROTOCOL, reason); - if (response.status != PGRAC_EXTERNAL_FENCE_REJOIN_OFFERED && - response.status != PGRAC_EXTERNAL_FENCE_REJOIN_WAITING_JOINER && - response.status != PGRAC_EXTERNAL_FENCE_REJOIN_READY) - { - if (response.status < PGRAC_EXTERNAL_FENCE_REJOIN_REJECTED || - response.status > PGRAC_EXTERNAL_FENCE_REJOIN_STALE || - response.deny_reason < PGRAC_EXTERNAL_FENCE_DENY_BAD_ARGUMENT || - response.deny_reason > PGRAC_EXTERNAL_FENCE_DENY_GRD_NOT_CLEAR) - return external_fence_rejoin_terminal(op, - PGRAC_EXTERNAL_FENCE_REJOIN_UNAVAILABLE, - PGRAC_EXTERNAL_FENCE_DENY_PROTOCOL, reason); - return external_fence_rejoin_terminal(op, - (PgracExternalFenceRejoinStatus) response.status, - (PgracExternalFenceDenyReason) response.deny_reason, reason); - } - if (expected_opcode == PGRAC_EXTERNAL_FENCE_REJOIN_LMON_OFFER) - { + if (!pgrac_external_fence_rejoin_v1_decode(op->rx_frame, sizeof(op->rx_frame), &response) + || response.opcode != expected_opcode + || memcmp(response.transport_nonce, op->transport_nonce, sizeof(op->transport_nonce)) != 0) + return external_fence_rejoin_terminal(op, PGRAC_EXTERNAL_FENCE_REJOIN_UNAVAILABLE, + PGRAC_EXTERNAL_FENCE_DENY_PROTOCOL, reason); + if (response.status != PGRAC_EXTERNAL_FENCE_REJOIN_OFFERED + && response.status != PGRAC_EXTERNAL_FENCE_REJOIN_WAITING_JOINER + && response.status != PGRAC_EXTERNAL_FENCE_REJOIN_READY) { + if (response.status < PGRAC_EXTERNAL_FENCE_REJOIN_REJECTED + || response.status > PGRAC_EXTERNAL_FENCE_REJOIN_STALE + || response.deny_reason < PGRAC_EXTERNAL_FENCE_DENY_BAD_ARGUMENT + || response.deny_reason > PGRAC_EXTERNAL_FENCE_DENY_GRD_NOT_CLEAR) + return external_fence_rejoin_terminal(op, PGRAC_EXTERNAL_FENCE_REJOIN_UNAVAILABLE, + PGRAC_EXTERNAL_FENCE_DENY_PROTOCOL, reason); + return external_fence_rejoin_terminal(op, (PgracExternalFenceRejoinStatus)response.status, + (PgracExternalFenceDenyReason)response.deny_reason, + reason); + } + if (expected_opcode == PGRAC_EXTERNAL_FENCE_REJOIN_LMON_OFFER) { if (!external_fence_rejoin_offer_valid(op, &response, now_ns)) - return external_fence_rejoin_terminal(op, - PGRAC_EXTERNAL_FENCE_REJOIN_STALE, - PGRAC_EXTERNAL_FENCE_DENY_REJOIN_OFFER_MISMATCH, reason); + return external_fence_rejoin_terminal(op, PGRAC_EXTERNAL_FENCE_REJOIN_STALE, + PGRAC_EXTERNAL_FENCE_DENY_REJOIN_OFFER_MISMATCH, + reason); op->offer_frame = response; - memcpy(op->offer.operation_id, response.operation_id, - sizeof(op->offer.operation_id)); + memcpy(op->offer.operation_id, response.operation_id, sizeof(op->offer.operation_id)); op->offer.old_node_id = response.old_node_id; op->offer.old_incarnation = response.old_incarnation; op->offer.candidate_incarnation = response.candidate_incarnation; op->status = PGRAC_EXTERNAL_FENCE_REJOIN_OFFERED; - } - else if (expected_opcode == - PGRAC_EXTERNAL_FENCE_REJOIN_LMON_ON_RESULT) - { + } else if (expected_opcode == PGRAC_EXTERNAL_FENCE_REJOIN_LMON_ON_RESULT) { if (!external_fence_rejoin_on_result_valid(op, &response, now_ns)) - return external_fence_rejoin_terminal(op, - PGRAC_EXTERNAL_FENCE_REJOIN_STALE, - PGRAC_EXTERNAL_FENCE_DENY_BINDING_MISMATCH, reason); + return external_fence_rejoin_terminal(op, PGRAC_EXTERNAL_FENCE_REJOIN_STALE, + PGRAC_EXTERNAL_FENCE_DENY_BINDING_MISMATCH, + reason); op->on_frame = response; op->status = PGRAC_EXTERNAL_FENCE_REJOIN_WAITING_JOINER; - } - else - { - if (!external_fence_rejoin_refresh_result_valid(op, &response, - now_ns)) - return external_fence_rejoin_terminal(op, - PGRAC_EXTERNAL_FENCE_REJOIN_STALE, - PGRAC_EXTERNAL_FENCE_DENY_BINDING_MISMATCH, reason); + } else { + if (!external_fence_rejoin_refresh_result_valid(op, &response, now_ns)) + return external_fence_rejoin_terminal(op, PGRAC_EXTERNAL_FENCE_REJOIN_STALE, + PGRAC_EXTERNAL_FENCE_DENY_BINDING_MISMATCH, + reason); op->ready_frame = response; memset(&op->binding, 0, sizeof(op->binding)); op->binding.system_identifier = response.system_identifier; - memcpy(op->binding.rejoin_gate_digest, - response.rejoin_gate_digest, + memcpy(op->binding.rejoin_gate_digest, response.rejoin_gate_digest, sizeof(op->binding.rejoin_gate_digest)); op->binding.old_node_id = response.old_node_id; op->binding.old_incarnation = response.old_incarnation; - op->binding.candidate_incarnation = - response.candidate_incarnation; - op->binding.target_mapping_generation = - response.target_mapping_generation; - memcpy(op->binding.protected_set_digest, - response.protected_set_digest, + op->binding.candidate_incarnation = response.candidate_incarnation; + op->binding.target_mapping_generation = response.target_mapping_generation; + memcpy(op->binding.protected_set_digest, response.protected_set_digest, sizeof(op->binding.protected_set_digest)); - op->binding.predicate_id = - PGRAC_EXTERNAL_FENCE_PREDICATE_REJOIN_ON; - op->binding.predicate_version = - PGRAC_EXTERNAL_FENCE_PREDICATE_VERSION_V1; + op->binding.predicate_id = PGRAC_EXTERNAL_FENCE_PREDICATE_REJOIN_ON; + op->binding.predicate_version = PGRAC_EXTERNAL_FENCE_PREDICATE_VERSION_V1; op->root_revalidated = false; op->status = PGRAC_EXTERNAL_FENCE_REJOIN_READY; } op->deny_reason = PGRAC_EXTERNAL_FENCE_DENY_NONE; external_fence_last_deny = PGRAC_EXTERNAL_FENCE_DENY_NONE; *reason = PGRAC_EXTERNAL_FENCE_DENY_NONE; - return (PgracExternalFenceRejoinStatus) op->status; + return (PgracExternalFenceRejoinStatus)op->status; #endif } const PgracExternalFenceRejoinOfferV1 * -cluster_external_fence_rejoin_offer( - const PgracExternalFenceRejoinOpV1 *op) +cluster_external_fence_rejoin_offer(const PgracExternalFenceRejoinOpV1 *op) { - if (op == NULL || op->magic != PGRAC_EXTERNAL_FENCE_REJOIN_OP_MAGIC || - op->owner_pid != external_fence_owner_pid() || - (op->status != PGRAC_EXTERNAL_FENCE_REJOIN_OFFERED && - op->status != PGRAC_EXTERNAL_FENCE_REJOIN_WAITING_ROOT)) + if (op == NULL || op->magic != PGRAC_EXTERNAL_FENCE_REJOIN_OP_MAGIC + || op->owner_pid != external_fence_owner_pid() + || (op->status != PGRAC_EXTERNAL_FENCE_REJOIN_OFFERED + && op->status != PGRAC_EXTERNAL_FENCE_REJOIN_WAITING_ROOT)) return NULL; return &op->offer; } static bool -external_fence_rejoin_root_complete_valid( - const PgracExternalFenceRejoinOpV1 *op, - const ClusterControlRootIdentity *identity, - const ClusterControlRootSnapshot *snapshot, - const ClusterControlRootReadToken *token) -{ - return cluster_recovery_duty_key_valid_v1(identity) && - identity->system_identifier == op->offer_frame.system_identifier && - identity->origin_node_id == op->offer_frame.old_node_id && - identity->origin_thread_id == - (uint16) (op->offer_frame.old_node_id + 1) && - identity->origin_owner_incarnation == - op->offer_frame.old_incarnation && - memcmp(&snapshot->identity, identity, sizeof(*identity)) == 0 && - snapshot->lifecycle == - CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_COMPLETE && - snapshot->root_publish_seq != 0 && snapshot->reserved96 == 0 && - snapshot->reserved122 == 0 && snapshot->reserved124 == 0 && - snapshot->reserved160 == 0 && snapshot->reserved208 == 0 && - memcmp(token->authority_uuid, identity->authority_uuid, - sizeof(token->authority_uuid)) == 0 && - token->origin_thread_id == identity->origin_thread_id && - token->source == PGRAC_EXTERNAL_FENCE_ROOT_SOURCE_PRIMARY && - token->lifecycle == - CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_COMPLETE && - token->reserved20 == 0 && token->reserved32 == 0 && - token->root_lineage_seq == identity->root_lineage_seq && - token->file_txn_seq != 0 && - token->root_publish_seq == snapshot->root_publish_seq && - token->record_crc32c != 0 && token->root_flags == snapshot->root_flags; +external_fence_rejoin_root_complete_valid(const PgracExternalFenceRejoinOpV1 *op, + const ClusterControlRootIdentity *identity, + const ClusterControlRootSnapshot *snapshot, + const ClusterControlRootReadToken *token) +{ + return cluster_recovery_duty_key_valid_v1(identity) + && identity->system_identifier == op->offer_frame.system_identifier + && identity->origin_node_id == op->offer_frame.old_node_id + && identity->origin_thread_id == (uint16)(op->offer_frame.old_node_id + 1) + && identity->origin_owner_incarnation == op->offer_frame.old_incarnation + && memcmp(&snapshot->identity, identity, sizeof(*identity)) == 0 + && snapshot->lifecycle == CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_COMPLETE + && snapshot->root_publish_seq != 0 && snapshot->reserved96 == 0 + && snapshot->reserved122 == 0 && snapshot->reserved124 == 0 && snapshot->reserved160 == 0 + && snapshot->reserved208 == 0 + && memcmp(token->authority_uuid, identity->authority_uuid, sizeof(token->authority_uuid)) + == 0 + && token->origin_thread_id == identity->origin_thread_id + && token->source == PGRAC_EXTERNAL_FENCE_ROOT_SOURCE_PRIMARY + && token->lifecycle == CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_COMPLETE + && token->reserved20 == 0 && token->reserved32 == 0 + && token->root_lineage_seq == identity->root_lineage_seq && token->file_txn_seq != 0 + && token->root_publish_seq == snapshot->root_publish_seq && token->record_crc32c != 0 + && token->root_flags == snapshot->root_flags; } PgracExternalFenceRejoinStatus @@ -2232,8 +1940,7 @@ cluster_external_fence_rejoin_authority_clear_build( const PgracExternalFenceRejoinOpV1 *offered_op, const ClusterReconfigRejoinFailureSnapshotV1 *failure, const ClusterGrdRejoinClearSnapshotV1 *grd_clear, - PgracExternalFenceRejoinAuthorityClearV1 **out_clear, - PgracExternalFenceDenyReason *reason) + PgracExternalFenceRejoinAuthorityClearV1 **out_clear, PgracExternalFenceDenyReason *reason) { PgracExternalFenceRejoinAuthorityClearV1 *clear; ClusterReconfigRejoinFailureSnapshotV1 current_failure; @@ -2247,101 +1954,79 @@ cluster_external_fence_rejoin_authority_clear_build( if (out_clear != NULL) *out_clear = NULL; - if (reason == NULL || out_clear == NULL || offered_op == NULL || - failure == NULL || grd_clear == NULL) - return external_fence_rejoin_fail( - PGRAC_EXTERNAL_FENCE_REJOIN_UNAVAILABLE, - PGRAC_EXTERNAL_FENCE_DENY_BAD_ARGUMENT, reason); - if (offered_op->magic != PGRAC_EXTERNAL_FENCE_REJOIN_OP_MAGIC || - offered_op->owner_pid != external_fence_owner_pid() || - offered_op->socket_fd < 0) - return external_fence_rejoin_fail( - PGRAC_EXTERNAL_FENCE_REJOIN_UNAVAILABLE, - PGRAC_EXTERNAL_FENCE_DENY_BAD_ARGUMENT, reason); + if (reason == NULL || out_clear == NULL || offered_op == NULL || failure == NULL + || grd_clear == NULL) + return external_fence_rejoin_fail(PGRAC_EXTERNAL_FENCE_REJOIN_UNAVAILABLE, + PGRAC_EXTERNAL_FENCE_DENY_BAD_ARGUMENT, reason); + if (offered_op->magic != PGRAC_EXTERNAL_FENCE_REJOIN_OP_MAGIC + || offered_op->owner_pid != external_fence_owner_pid() || offered_op->socket_fd < 0) + return external_fence_rejoin_fail(PGRAC_EXTERNAL_FENCE_REJOIN_UNAVAILABLE, + PGRAC_EXTERNAL_FENCE_DENY_BAD_ARGUMENT, reason); if (offered_op->status != PGRAC_EXTERNAL_FENCE_REJOIN_OFFERED) - return external_fence_rejoin_fail( - PGRAC_EXTERNAL_FENCE_REJOIN_STALE, - PGRAC_EXTERNAL_FENCE_DENY_REJOIN_OFFER_MISMATCH, reason); - - if (failure->reconfig_kind != RECONFIG_KIND_FAIL_STOP || - failure->reserved0 != 0 || failure->reserved68 != 0 || - failure->event_id == 0 || failure->new_epoch == 0 || - failure->cssd_dead_generation == 0 || - failure->old_node_id < 0 || - failure->old_node_id >= CLUSTER_MAX_NODES || - failure->old_incarnation == 0 || - !external_fence_bitmap_member(failure->dead_bitmap, - failure->old_node_id) || - external_fence_bitmap_member(failure->survivor_bitmap, - failure->old_node_id)) - return external_fence_rejoin_fail( - PGRAC_EXTERNAL_FENCE_REJOIN_STALE, - PGRAC_EXTERNAL_FENCE_DENY_REJOIN_LINEAGE_MISMATCH, reason); - survivor_count = - external_fence_bitmap_popcount(failure->survivor_bitmap); - if (survivor_count < 1 || survivor_count >= CLUSTER_MAX_NODES || - grd_clear->episode_epoch != failure->new_epoch || - grd_clear->dead_bitmap_hash == 0 || - memcmp(grd_clear->survivor_bitmap, failure->survivor_bitmap, - sizeof(grd_clear->survivor_bitmap)) != 0) - return external_fence_rejoin_fail( - PGRAC_EXTERNAL_FENCE_REJOIN_PENDING, - PGRAC_EXTERNAL_FENCE_DENY_GRD_NOT_CLEAR, reason); - for (i = 0; i < 16; i++) - { + return external_fence_rejoin_fail(PGRAC_EXTERNAL_FENCE_REJOIN_STALE, + PGRAC_EXTERNAL_FENCE_DENY_REJOIN_OFFER_MISMATCH, reason); + + if (failure->reconfig_kind != RECONFIG_KIND_FAIL_STOP || failure->reserved0 != 0 + || failure->reserved68 != 0 || failure->event_id == 0 || failure->new_epoch == 0 + || failure->cssd_dead_generation == 0 || failure->old_node_id < 0 + || failure->old_node_id >= CLUSTER_MAX_NODES || failure->old_incarnation == 0 + || !external_fence_bitmap_member(failure->dead_bitmap, failure->old_node_id) + || external_fence_bitmap_member(failure->survivor_bitmap, failure->old_node_id)) + return external_fence_rejoin_fail(PGRAC_EXTERNAL_FENCE_REJOIN_STALE, + PGRAC_EXTERNAL_FENCE_DENY_REJOIN_LINEAGE_MISMATCH, + reason); + survivor_count = external_fence_bitmap_popcount(failure->survivor_bitmap); + if (survivor_count < 1 || survivor_count >= CLUSTER_MAX_NODES + || grd_clear->episode_epoch != failure->new_epoch || grd_clear->dead_bitmap_hash == 0 + || memcmp(grd_clear->survivor_bitmap, failure->survivor_bitmap, + sizeof(grd_clear->survivor_bitmap)) + != 0) + return external_fence_rejoin_fail(PGRAC_EXTERNAL_FENCE_REJOIN_PENDING, + PGRAC_EXTERNAL_FENCE_DENY_GRD_NOT_CLEAR, reason); + for (i = 0; i < 16; i++) { if ((failure->dead_bitmap[i] & failure->survivor_bitmap[i]) != 0) - return external_fence_rejoin_fail( - PGRAC_EXTERNAL_FENCE_REJOIN_STALE, - PGRAC_EXTERNAL_FENCE_DENY_REJOIN_LINEAGE_MISMATCH, - reason); - } - if (offered_op->offer_frame.old_node_id != failure->old_node_id || - offered_op->offer_frame.old_incarnation != - failure->old_incarnation || - memcmp(offered_op->offer.operation_id, - offered_op->offer_frame.operation_id, - sizeof(offered_op->offer.operation_id)) != 0 || - offered_op->offer.old_node_id != failure->old_node_id || - offered_op->offer.old_incarnation != failure->old_incarnation || - offered_op->offer.candidate_incarnation != - offered_op->offer_frame.candidate_incarnation) - return external_fence_rejoin_fail( - PGRAC_EXTERNAL_FENCE_REJOIN_STALE, - PGRAC_EXTERNAL_FENCE_DENY_REJOIN_OFFER_MISMATCH, reason); + return external_fence_rejoin_fail(PGRAC_EXTERNAL_FENCE_REJOIN_STALE, + PGRAC_EXTERNAL_FENCE_DENY_REJOIN_LINEAGE_MISMATCH, + reason); + } + if (offered_op->offer_frame.old_node_id != failure->old_node_id + || offered_op->offer_frame.old_incarnation != failure->old_incarnation + || memcmp(offered_op->offer.operation_id, offered_op->offer_frame.operation_id, + sizeof(offered_op->offer.operation_id)) + != 0 + || offered_op->offer.old_node_id != failure->old_node_id + || offered_op->offer.old_incarnation != failure->old_incarnation + || offered_op->offer.candidate_incarnation != offered_op->offer_frame.candidate_incarnation) + return external_fence_rejoin_fail(PGRAC_EXTERNAL_FENCE_REJOIN_STALE, + PGRAC_EXTERNAL_FENCE_DENY_REJOIN_OFFER_MISMATCH, reason); memset(¤t_failure, 0, sizeof(current_failure)); - if (!cluster_reconfig_rejoin_failure_snapshot( - failure->old_node_id, failure->old_incarnation, ¤t_failure) || - memcmp(¤t_failure, failure, sizeof(current_failure)) != 0) - return external_fence_rejoin_fail( - PGRAC_EXTERNAL_FENCE_REJOIN_STALE, - PGRAC_EXTERNAL_FENCE_DENY_REJOIN_LINEAGE_MISMATCH, reason); + if (!cluster_reconfig_rejoin_failure_snapshot(failure->old_node_id, failure->old_incarnation, + ¤t_failure) + || memcmp(¤t_failure, failure, sizeof(current_failure)) != 0) + return external_fence_rejoin_fail(PGRAC_EXTERNAL_FENCE_REJOIN_STALE, + PGRAC_EXTERNAL_FENCE_DENY_REJOIN_LINEAGE_MISMATCH, + reason); memset(¤t_grd_clear, 0, sizeof(current_grd_clear)); - if (!cluster_grd_rejoin_clear_snapshot(¤t_failure, - ¤t_grd_clear) || - memcmp(¤t_grd_clear, grd_clear, sizeof(current_grd_clear)) != 0) - return external_fence_rejoin_fail( - PGRAC_EXTERNAL_FENCE_REJOIN_PENDING, - PGRAC_EXTERNAL_FENCE_DENY_GRD_NOT_CLEAR, reason); + if (!cluster_grd_rejoin_clear_snapshot(¤t_failure, ¤t_grd_clear) + || memcmp(¤t_grd_clear, grd_clear, sizeof(current_grd_clear)) != 0) + return external_fence_rejoin_fail(PGRAC_EXTERNAL_FENCE_REJOIN_PENDING, + PGRAC_EXTERNAL_FENCE_DENY_GRD_NOT_CLEAR, reason); #ifdef WIN32 - return external_fence_rejoin_fail( - PGRAC_EXTERNAL_FENCE_REJOIN_UNAVAILABLE, - PGRAC_EXTERNAL_FENCE_DENY_DAEMON_UNAVAILABLE, reason); + return external_fence_rejoin_fail(PGRAC_EXTERNAL_FENCE_REJOIN_UNAVAILABLE, + PGRAC_EXTERNAL_FENCE_DENY_DAEMON_UNAVAILABLE, reason); #else - if (!external_fence_monotonic_now(&now_ns) || - !external_fence_rejoin_offer_valid(offered_op, - &offered_op->offer_frame, now_ns)) - return external_fence_rejoin_fail( - PGRAC_EXTERNAL_FENCE_REJOIN_STALE, - PGRAC_EXTERNAL_FENCE_DENY_EXPIRED, reason); + if (!external_fence_monotonic_now(&now_ns) + || !external_fence_rejoin_offer_valid(offered_op, &offered_op->offer_frame, now_ns)) + return external_fence_rejoin_fail(PGRAC_EXTERNAL_FENCE_REJOIN_STALE, + PGRAC_EXTERNAL_FENCE_DENY_EXPIRED, reason); poll_fd.fd = offered_op->socket_fd; poll_fd.events = POLLIN | POLLHUP | POLLERR; poll_fd.revents = 0; if (poll(&poll_fd, 1, 0) != 0) - return external_fence_rejoin_fail( - PGRAC_EXTERNAL_FENCE_REJOIN_STALE, - PGRAC_EXTERNAL_FENCE_DENY_CONNECTION_CLOSED, reason); + return external_fence_rejoin_fail(PGRAC_EXTERNAL_FENCE_REJOIN_STALE, + PGRAC_EXTERNAL_FENCE_DENY_CONNECTION_CLOSED, reason); clear = palloc0(sizeof(*clear)); clear->magic = PGRAC_EXTERNAL_FENCE_REJOIN_CLEAR_MAGIC; @@ -2351,20 +2036,16 @@ cluster_external_fence_rejoin_authority_clear_build( clear->grd_clear = *grd_clear; clear->offer_frame = offered_op->offer_frame; if (!external_fence_rejoin_clear_digest(offered_op, failure, grd_clear, - clear->authority_clear_digest)) - { + clear->authority_clear_digest)) { explicit_bzero(clear, sizeof(*clear)); pfree(clear); - return external_fence_rejoin_fail( - PGRAC_EXTERNAL_FENCE_REJOIN_UNAVAILABLE, - PGRAC_EXTERNAL_FENCE_DENY_PROTOCOL, reason); + return external_fence_rejoin_fail(PGRAC_EXTERNAL_FENCE_REJOIN_UNAVAILABLE, + PGRAC_EXTERNAL_FENCE_DENY_PROTOCOL, reason); } *reason = PGRAC_EXTERNAL_FENCE_DENY_NONE; external_fence_last_deny = PGRAC_EXTERNAL_FENCE_DENY_NONE; - ((PgracExternalFenceRejoinOpV1 *) offered_op)->status = - PGRAC_EXTERNAL_FENCE_REJOIN_WAITING_ROOT; - ((PgracExternalFenceRejoinOpV1 *) offered_op)->deny_reason = - PGRAC_EXTERNAL_FENCE_DENY_NONE; + ((PgracExternalFenceRejoinOpV1 *)offered_op)->status = PGRAC_EXTERNAL_FENCE_REJOIN_WAITING_ROOT; + ((PgracExternalFenceRejoinOpV1 *)offered_op)->deny_reason = PGRAC_EXTERNAL_FENCE_DENY_NONE; *out_clear = clear; return PGRAC_EXTERNAL_FENCE_REJOIN_WAITING_ROOT; #endif @@ -2372,12 +2053,10 @@ cluster_external_fence_rejoin_authority_clear_build( PgracExternalFenceRejoinStatus cluster_external_fence_rejoin_authorize_on_async( - PgracExternalFenceRejoinOpV1 *op, - PgracExternalFenceRejoinAuthorityClearV1 **authority_clear, + PgracExternalFenceRejoinOpV1 *op, PgracExternalFenceRejoinAuthorityClearV1 **authority_clear, const ClusterControlRootIdentity *old_identity, const ClusterControlRootSnapshot *complete_snapshot, - const ClusterControlRootReadToken *complete_token, - const uint8 protected_set_digest[32], + const ClusterControlRootReadToken *complete_token, const uint8 protected_set_digest[32], PgracExternalFenceDenyReason *reason) { PgracExternalFenceRejoinAuthorityClearV1 *clear; @@ -2398,143 +2077,112 @@ cluster_external_fence_rejoin_authorize_on_async( #endif #endif - if (reason == NULL || op == NULL || authority_clear == NULL || - old_identity == NULL || - complete_snapshot == NULL || complete_token == NULL || - protected_set_digest == NULL) - return external_fence_rejoin_fail( - PGRAC_EXTERNAL_FENCE_REJOIN_UNAVAILABLE, - PGRAC_EXTERNAL_FENCE_DENY_BAD_ARGUMENT, reason); - if (op->magic != PGRAC_EXTERNAL_FENCE_REJOIN_OP_MAGIC || - op->owner_pid != external_fence_owner_pid() || op->socket_fd < 0) - return external_fence_rejoin_fail( - PGRAC_EXTERNAL_FENCE_REJOIN_UNAVAILABLE, - PGRAC_EXTERNAL_FENCE_DENY_BAD_ARGUMENT, reason); + if (reason == NULL || op == NULL || authority_clear == NULL || old_identity == NULL + || complete_snapshot == NULL || complete_token == NULL || protected_set_digest == NULL) + return external_fence_rejoin_fail(PGRAC_EXTERNAL_FENCE_REJOIN_UNAVAILABLE, + PGRAC_EXTERNAL_FENCE_DENY_BAD_ARGUMENT, reason); + if (op->magic != PGRAC_EXTERNAL_FENCE_REJOIN_OP_MAGIC + || op->owner_pid != external_fence_owner_pid() || op->socket_fd < 0) + return external_fence_rejoin_fail(PGRAC_EXTERNAL_FENCE_REJOIN_UNAVAILABLE, + PGRAC_EXTERNAL_FENCE_DENY_BAD_ARGUMENT, reason); if (*authority_clear == NULL) - return external_fence_rejoin_fail( - PGRAC_EXTERNAL_FENCE_REJOIN_STALE, - PGRAC_EXTERNAL_FENCE_DENY_AUTHORITY_CLEAR_MISSING, reason); + return external_fence_rejoin_fail(PGRAC_EXTERNAL_FENCE_REJOIN_STALE, + PGRAC_EXTERNAL_FENCE_DENY_AUTHORITY_CLEAR_MISSING, + reason); clear = *authority_clear; - if (clear->magic != PGRAC_EXTERNAL_FENCE_REJOIN_CLEAR_MAGIC || - clear->owner_pid != external_fence_owner_pid() || - memcmp(&clear->offer_frame, &op->offer_frame, - sizeof(clear->offer_frame)) != 0 || - clear->operation_deadline_mono_ns != op->deadline_mono_ns) - return external_fence_rejoin_fail( - PGRAC_EXTERNAL_FENCE_REJOIN_STALE, - PGRAC_EXTERNAL_FENCE_DENY_AUTHORITY_CLEAR_MISSING, reason); - if (op->status != PGRAC_EXTERNAL_FENCE_REJOIN_WAITING_ROOT && - op->status != PGRAC_EXTERNAL_FENCE_REJOIN_OFFERED) - return external_fence_rejoin_fail( - PGRAC_EXTERNAL_FENCE_REJOIN_STALE, - PGRAC_EXTERNAL_FENCE_DENY_AUTHORITY_CLEAR_MISSING, reason); - if (complete_snapshot->lifecycle != - CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_COMPLETE) - { + if (clear->magic != PGRAC_EXTERNAL_FENCE_REJOIN_CLEAR_MAGIC + || clear->owner_pid != external_fence_owner_pid() + || memcmp(&clear->offer_frame, &op->offer_frame, sizeof(clear->offer_frame)) != 0 + || clear->operation_deadline_mono_ns != op->deadline_mono_ns) + return external_fence_rejoin_fail(PGRAC_EXTERNAL_FENCE_REJOIN_STALE, + PGRAC_EXTERNAL_FENCE_DENY_AUTHORITY_CLEAR_MISSING, + reason); + if (op->status != PGRAC_EXTERNAL_FENCE_REJOIN_WAITING_ROOT + && op->status != PGRAC_EXTERNAL_FENCE_REJOIN_OFFERED) + return external_fence_rejoin_fail(PGRAC_EXTERNAL_FENCE_REJOIN_STALE, + PGRAC_EXTERNAL_FENCE_DENY_AUTHORITY_CLEAR_MISSING, + reason); + if (complete_snapshot->lifecycle != CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_COMPLETE) { op->status = PGRAC_EXTERNAL_FENCE_REJOIN_WAITING_ROOT; op->deny_reason = PGRAC_EXTERNAL_FENCE_DENY_ROOT_NOT_COMPLETE; - return external_fence_rejoin_fail( - PGRAC_EXTERNAL_FENCE_REJOIN_WAITING_ROOT, - PGRAC_EXTERNAL_FENCE_DENY_ROOT_NOT_COMPLETE, reason); - } - if (!external_fence_rejoin_root_complete_valid(op, old_identity, - complete_snapshot, - complete_token)) - return external_fence_rejoin_fail( - PGRAC_EXTERNAL_FENCE_REJOIN_STALE, - PGRAC_EXTERNAL_FENCE_DENY_ROOT_STALE, reason); - if (!bytes_nonzero(protected_set_digest, - PGRAC_EXTERNAL_FENCE_DIGEST_BYTES) || - memcmp(protected_set_digest, op->offer_frame.protected_set_digest, - PGRAC_EXTERNAL_FENCE_DIGEST_BYTES) != 0) - return external_fence_rejoin_fail( - PGRAC_EXTERNAL_FENCE_REJOIN_STALE, - PGRAC_EXTERNAL_FENCE_DENY_REJOIN_OFFER_MISMATCH, reason); + return external_fence_rejoin_fail(PGRAC_EXTERNAL_FENCE_REJOIN_WAITING_ROOT, + PGRAC_EXTERNAL_FENCE_DENY_ROOT_NOT_COMPLETE, reason); + } + if (!external_fence_rejoin_root_complete_valid(op, old_identity, complete_snapshot, + complete_token)) + return external_fence_rejoin_fail(PGRAC_EXTERNAL_FENCE_REJOIN_STALE, + PGRAC_EXTERNAL_FENCE_DENY_ROOT_STALE, reason); + if (!bytes_nonzero(protected_set_digest, PGRAC_EXTERNAL_FENCE_DIGEST_BYTES) + || memcmp(protected_set_digest, op->offer_frame.protected_set_digest, + PGRAC_EXTERNAL_FENCE_DIGEST_BYTES) + != 0) + return external_fence_rejoin_fail(PGRAC_EXTERNAL_FENCE_REJOIN_STALE, + PGRAC_EXTERNAL_FENCE_DENY_REJOIN_OFFER_MISMATCH, reason); memset(¤t_failure, 0, sizeof(current_failure)); memset(¤t_grd_clear, 0, sizeof(current_grd_clear)); - if (!cluster_reconfig_rejoin_failure_snapshot( - clear->failure.old_node_id, clear->failure.old_incarnation, - ¤t_failure) || - memcmp(¤t_failure, &clear->failure, - sizeof(current_failure)) != 0 || - !cluster_grd_rejoin_clear_snapshot(¤t_failure, - ¤t_grd_clear) || - memcmp(¤t_grd_clear, &clear->grd_clear, - sizeof(current_grd_clear)) != 0 || - !external_fence_rejoin_clear_digest(op, &clear->failure, - &clear->grd_clear, - recalculated_clear_digest) || - memcmp(recalculated_clear_digest, clear->authority_clear_digest, - sizeof(recalculated_clear_digest)) != 0) - return external_fence_rejoin_fail( - PGRAC_EXTERNAL_FENCE_REJOIN_STALE, - PGRAC_EXTERNAL_FENCE_DENY_AUTHORITY_CLEAR_STALE, reason); + if (!cluster_reconfig_rejoin_failure_snapshot(clear->failure.old_node_id, + clear->failure.old_incarnation, ¤t_failure) + || memcmp(¤t_failure, &clear->failure, sizeof(current_failure)) != 0 + || !cluster_grd_rejoin_clear_snapshot(¤t_failure, ¤t_grd_clear) + || memcmp(¤t_grd_clear, &clear->grd_clear, sizeof(current_grd_clear)) != 0 + || !external_fence_rejoin_clear_digest(op, &clear->failure, &clear->grd_clear, + recalculated_clear_digest) + || memcmp(recalculated_clear_digest, clear->authority_clear_digest, + sizeof(recalculated_clear_digest)) + != 0) + return external_fence_rejoin_fail(PGRAC_EXTERNAL_FENCE_REJOIN_STALE, + PGRAC_EXTERNAL_FENCE_DENY_AUTHORITY_CLEAR_STALE, reason); #ifdef WIN32 - return external_fence_rejoin_fail( - PGRAC_EXTERNAL_FENCE_REJOIN_UNAVAILABLE, - PGRAC_EXTERNAL_FENCE_DENY_DAEMON_UNAVAILABLE, reason); + return external_fence_rejoin_fail(PGRAC_EXTERNAL_FENCE_REJOIN_UNAVAILABLE, + PGRAC_EXTERNAL_FENCE_DENY_DAEMON_UNAVAILABLE, reason); #else - if (!external_fence_monotonic_now(&now_ns) || - now_ns >= op->deadline_mono_ns || - now_ns < op->offer_frame.verified_mono_ns || - now_ns >= op->offer_frame.fresh_until_mono_ns) - return external_fence_rejoin_terminal(op, - PGRAC_EXTERNAL_FENCE_REJOIN_STALE, - PGRAC_EXTERNAL_FENCE_DENY_AUTHORITY_CLEAR_STALE, reason); + if (!external_fence_monotonic_now(&now_ns) || now_ns >= op->deadline_mono_ns + || now_ns < op->offer_frame.verified_mono_ns + || now_ns >= op->offer_frame.fresh_until_mono_ns) + return external_fence_rejoin_terminal(op, PGRAC_EXTERNAL_FENCE_REJOIN_STALE, + PGRAC_EXTERNAL_FENCE_DENY_AUTHORITY_CLEAR_STALE, + reason); poll_fd.fd = op->socket_fd; poll_fd.events = POLLIN | POLLHUP | POLLERR; poll_fd.revents = 0; if (poll(&poll_fd, 1, 0) != 0) - return external_fence_rejoin_terminal(op, - PGRAC_EXTERNAL_FENCE_REJOIN_STALE, - PGRAC_EXTERNAL_FENCE_DENY_CONNECTION_CLOSED, reason); - - if (!op->authorize_enqueue_pending) - { - if (!external_fence_rejoin_root_completion_digest( - old_identity, complete_token, op->root_completion_digest) || - !external_fence_rejoin_gate_digest(op->root_completion_digest, - clear->authority_clear_digest, gate_digest) || - !pg_strong_random(op->transport_nonce, - sizeof(op->transport_nonce)) || - !bytes_nonzero(op->transport_nonce, - sizeof(op->transport_nonce))) - return external_fence_rejoin_fail( - PGRAC_EXTERNAL_FENCE_REJOIN_UNAVAILABLE, - PGRAC_EXTERNAL_FENCE_DENY_PROTOCOL, reason); + return external_fence_rejoin_terminal(op, PGRAC_EXTERNAL_FENCE_REJOIN_STALE, + PGRAC_EXTERNAL_FENCE_DENY_CONNECTION_CLOSED, reason); + + if (!op->authorize_enqueue_pending) { + if (!external_fence_rejoin_root_completion_digest(old_identity, complete_token, + op->root_completion_digest) + || !external_fence_rejoin_gate_digest(op->root_completion_digest, + clear->authority_clear_digest, gate_digest) + || !pg_strong_random(op->transport_nonce, sizeof(op->transport_nonce)) + || !bytes_nonzero(op->transport_nonce, sizeof(op->transport_nonce))) + return external_fence_rejoin_fail(PGRAC_EXTERNAL_FENCE_REJOIN_UNAVAILABLE, + PGRAC_EXTERNAL_FENCE_DENY_PROTOCOL, reason); memset(&authorize, 0, sizeof(authorize)); - authorize.opcode = - PGRAC_EXTERNAL_FENCE_REJOIN_LMON_AUTHORIZE_ON; - memcpy(authorize.transport_nonce, op->transport_nonce, - sizeof(authorize.transport_nonce)); + authorize.opcode = PGRAC_EXTERNAL_FENCE_REJOIN_LMON_AUTHORIZE_ON; + memcpy(authorize.transport_nonce, op->transport_nonce, sizeof(authorize.transport_nonce)); memcpy(authorize.operation_id, op->offer_frame.operation_id, sizeof(authorize.operation_id)); authorize.system_identifier = op->offer_frame.system_identifier; - memcpy(authorize.rejoin_gate_digest, gate_digest, - sizeof(authorize.rejoin_gate_digest)); + memcpy(authorize.rejoin_gate_digest, gate_digest, sizeof(authorize.rejoin_gate_digest)); memcpy(authorize.protected_set_digest, protected_set_digest, sizeof(authorize.protected_set_digest)); authorize.old_node_id = op->offer_frame.old_node_id; authorize.old_incarnation = op->offer_frame.old_incarnation; - authorize.candidate_incarnation = - op->offer_frame.candidate_incarnation; + authorize.candidate_incarnation = op->offer_frame.candidate_incarnation; remaining_ns = op->deadline_mono_ns - now_ns; - remaining_ms = (remaining_ns + UINT64_C(999999)) / - UINT64_C(1000000); + remaining_ms = (remaining_ns + UINT64_C(999999)) / UINT64_C(1000000); if (remaining_ms < 1 || remaining_ms > 600000) - return external_fence_rejoin_terminal(op, - PGRAC_EXTERNAL_FENCE_REJOIN_STALE, - PGRAC_EXTERNAL_FENCE_DENY_AUTHORITY_CLEAR_STALE, - reason); - authorize.timeout_ms = (uint32) remaining_ms; + return external_fence_rejoin_terminal(op, PGRAC_EXTERNAL_FENCE_REJOIN_STALE, + PGRAC_EXTERNAL_FENCE_DENY_AUTHORITY_CLEAR_STALE, + reason); + authorize.timeout_ms = (uint32)remaining_ms; authorize.status = PGRAC_EXTERNAL_FENCE_REJOIN_PENDING; authorize.deny_reason = PGRAC_EXTERNAL_FENCE_DENY_NONE; - if (!pgrac_external_fence_rejoin_v1_encode(&authorize, - op->tx_frame)) - return external_fence_rejoin_fail( - PGRAC_EXTERNAL_FENCE_REJOIN_UNAVAILABLE, - PGRAC_EXTERNAL_FENCE_DENY_PROTOCOL, reason); + if (!pgrac_external_fence_rejoin_v1_encode(&authorize, op->tx_frame)) + return external_fence_rejoin_fail(PGRAC_EXTERNAL_FENCE_REJOIN_UNAVAILABLE, + PGRAC_EXTERNAL_FENCE_DENY_PROTOCOL, reason); op->tx_sent = 0; op->rx_used = 0; op->authorize_enqueue_pending = true; @@ -2544,54 +2192,41 @@ cluster_external_fence_rejoin_authorize_on_async( op->saved_root_token = *complete_token; memset(&op->rejoin_need, 0, sizeof(op->rejoin_need)); op->rejoin_need.system_identifier = authorize.system_identifier; - memcpy(op->rejoin_need.rejoin_gate_digest, - authorize.rejoin_gate_digest, + memcpy(op->rejoin_need.rejoin_gate_digest, authorize.rejoin_gate_digest, sizeof(op->rejoin_need.rejoin_gate_digest)); op->rejoin_need.old_node_id = authorize.old_node_id; op->rejoin_need.old_incarnation = authorize.old_incarnation; - op->rejoin_need.candidate_incarnation = - authorize.candidate_incarnation; - memcpy(op->rejoin_need.protected_set_digest, - authorize.protected_set_digest, + op->rejoin_need.candidate_incarnation = authorize.candidate_incarnation; + memcpy(op->rejoin_need.protected_set_digest, authorize.protected_set_digest, sizeof(op->rejoin_need.protected_set_digest)); - op->rejoin_need.predicate_id = - PGRAC_EXTERNAL_FENCE_PREDICATE_REJOIN_ON; - op->rejoin_need.predicate_version = - PGRAC_EXTERNAL_FENCE_PREDICATE_VERSION_V1; - } - else if (op->authorize_clear_borrowed != clear || - memcmp(&op->saved_root_identity, old_identity, - sizeof(*old_identity)) != 0 || - memcmp(&op->saved_root_snapshot, complete_snapshot, - sizeof(*complete_snapshot)) != 0 || - memcmp(&op->saved_root_token, complete_token, - sizeof(*complete_token)) != 0) - return external_fence_rejoin_fail( - PGRAC_EXTERNAL_FENCE_REJOIN_STALE, - PGRAC_EXTERNAL_FENCE_DENY_AUTHORITY_CLEAR_MISSING, reason); - - io_count = send(op->socket_fd, op->tx_frame + op->tx_sent, - sizeof(op->tx_frame) - op->tx_sent, send_flags); - if (io_count < 0) - { - if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR) - { + op->rejoin_need.predicate_id = PGRAC_EXTERNAL_FENCE_PREDICATE_REJOIN_ON; + op->rejoin_need.predicate_version = PGRAC_EXTERNAL_FENCE_PREDICATE_VERSION_V1; + } else if (op->authorize_clear_borrowed != clear + || memcmp(&op->saved_root_identity, old_identity, sizeof(*old_identity)) != 0 + || memcmp(&op->saved_root_snapshot, complete_snapshot, sizeof(*complete_snapshot)) + != 0 + || memcmp(&op->saved_root_token, complete_token, sizeof(*complete_token)) != 0) + return external_fence_rejoin_fail(PGRAC_EXTERNAL_FENCE_REJOIN_STALE, + PGRAC_EXTERNAL_FENCE_DENY_AUTHORITY_CLEAR_MISSING, + reason); + + io_count = send(op->socket_fd, op->tx_frame + op->tx_sent, sizeof(op->tx_frame) - op->tx_sent, + send_flags); + if (io_count < 0) { + if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR) { op->status = PGRAC_EXTERNAL_FENCE_REJOIN_WAITING_ROOT; op->deny_reason = PGRAC_EXTERNAL_FENCE_DENY_NONE; *reason = PGRAC_EXTERNAL_FENCE_DENY_NONE; return PGRAC_EXTERNAL_FENCE_REJOIN_WAITING_ROOT; } - return external_fence_rejoin_terminal(op, - PGRAC_EXTERNAL_FENCE_REJOIN_STALE, - PGRAC_EXTERNAL_FENCE_DENY_CONNECTION_CLOSED, reason); + return external_fence_rejoin_terminal(op, PGRAC_EXTERNAL_FENCE_REJOIN_STALE, + PGRAC_EXTERNAL_FENCE_DENY_CONNECTION_CLOSED, reason); } if (io_count == 0) - return external_fence_rejoin_terminal(op, - PGRAC_EXTERNAL_FENCE_REJOIN_STALE, - PGRAC_EXTERNAL_FENCE_DENY_CONNECTION_CLOSED, reason); - op->tx_sent += (size_t) io_count; - if (op->tx_sent < sizeof(op->tx_frame)) - { + return external_fence_rejoin_terminal(op, PGRAC_EXTERNAL_FENCE_REJOIN_STALE, + PGRAC_EXTERNAL_FENCE_DENY_CONNECTION_CLOSED, reason); + op->tx_sent += (size_t)io_count; + if (op->tx_sent < sizeof(op->tx_frame)) { op->status = PGRAC_EXTERNAL_FENCE_REJOIN_WAITING_ROOT; op->deny_reason = PGRAC_EXTERNAL_FENCE_DENY_NONE; *reason = PGRAC_EXTERNAL_FENCE_DENY_NONE; @@ -2611,8 +2246,7 @@ cluster_external_fence_rejoin_authorize_on_async( PgracExternalFenceRejoinStatus cluster_external_fence_rejoin_refresh_on_async( - PgracExternalFenceRejoinOpV1 *op, - const ClusterReconfigRejoinPendingSnapshotV1 *pending, + PgracExternalFenceRejoinOpV1 *op, const ClusterReconfigRejoinPendingSnapshotV1 *pending, PgracExternalFenceDenyReason *reason) { ClusterReconfigRejoinPendingSnapshotV1 current_pending; @@ -2632,160 +2266,123 @@ cluster_external_fence_rejoin_refresh_on_async( #endif if (reason == NULL || op == NULL || pending == NULL) - return external_fence_rejoin_fail( - PGRAC_EXTERNAL_FENCE_REJOIN_UNAVAILABLE, - PGRAC_EXTERNAL_FENCE_DENY_BAD_ARGUMENT, reason); - if (op->magic != PGRAC_EXTERNAL_FENCE_REJOIN_OP_MAGIC || - op->owner_pid != external_fence_owner_pid() || op->socket_fd < 0) - return external_fence_rejoin_fail( - PGRAC_EXTERNAL_FENCE_REJOIN_UNAVAILABLE, - PGRAC_EXTERNAL_FENCE_DENY_BAD_ARGUMENT, reason); - if (op->status != PGRAC_EXTERNAL_FENCE_REJOIN_WAITING_JOINER || - op->moved_clear == NULL) - return external_fence_rejoin_fail( - PGRAC_EXTERNAL_FENCE_REJOIN_STALE, - PGRAC_EXTERNAL_FENCE_DENY_REJOIN_LINEAGE_MISMATCH, reason); - if (pending->reconfig_kind != RECONFIG_KIND_JOIN_PENDING || - pending->reserved0 != 0 || pending->reserved76 != 0 || - pending->event_id == 0 || pending->old_epoch == 0 || - pending->old_epoch == UINT64_MAX || - pending->new_epoch != pending->old_epoch + 1 || - pending->cssd_dead_generation == 0 || - pending->node_id != op->offer_frame.old_node_id || - pending->candidate_incarnation != - op->offer_frame.candidate_incarnation || - pending->observed_slot_generation == 0 || - pending->old_epoch != op->moved_clear->failure.new_epoch) - return external_fence_rejoin_fail( - PGRAC_EXTERNAL_FENCE_REJOIN_STALE, - PGRAC_EXTERNAL_FENCE_DENY_JOIN_CANDIDATE_MISMATCH, reason); + return external_fence_rejoin_fail(PGRAC_EXTERNAL_FENCE_REJOIN_UNAVAILABLE, + PGRAC_EXTERNAL_FENCE_DENY_BAD_ARGUMENT, reason); + if (op->magic != PGRAC_EXTERNAL_FENCE_REJOIN_OP_MAGIC + || op->owner_pid != external_fence_owner_pid() || op->socket_fd < 0) + return external_fence_rejoin_fail(PGRAC_EXTERNAL_FENCE_REJOIN_UNAVAILABLE, + PGRAC_EXTERNAL_FENCE_DENY_BAD_ARGUMENT, reason); + if (op->status != PGRAC_EXTERNAL_FENCE_REJOIN_WAITING_JOINER || op->moved_clear == NULL) + return external_fence_rejoin_fail(PGRAC_EXTERNAL_FENCE_REJOIN_STALE, + PGRAC_EXTERNAL_FENCE_DENY_REJOIN_LINEAGE_MISMATCH, + reason); + if (pending->reconfig_kind != RECONFIG_KIND_JOIN_PENDING || pending->reserved0 != 0 + || pending->reserved76 != 0 || pending->event_id == 0 || pending->old_epoch == 0 + || pending->old_epoch == UINT64_MAX || pending->new_epoch != pending->old_epoch + 1 + || pending->cssd_dead_generation == 0 || pending->node_id != op->offer_frame.old_node_id + || pending->candidate_incarnation != op->offer_frame.candidate_incarnation + || pending->observed_slot_generation == 0 + || pending->old_epoch != op->moved_clear->failure.new_epoch) + return external_fence_rejoin_fail(PGRAC_EXTERNAL_FENCE_REJOIN_STALE, + PGRAC_EXTERNAL_FENCE_DENY_JOIN_CANDIDATE_MISMATCH, + reason); join_count = external_fence_bitmap_popcount(pending->join_bitmap); - if (join_count != 1 || - !external_fence_bitmap_member(pending->join_bitmap, - pending->node_id)) - return external_fence_rejoin_fail( - PGRAC_EXTERNAL_FENCE_REJOIN_STALE, - PGRAC_EXTERNAL_FENCE_DENY_REJOIN_LINEAGE_MISMATCH, reason); - for (i = 0; i < 16; i++) - { + if (join_count != 1 || !external_fence_bitmap_member(pending->join_bitmap, pending->node_id)) + return external_fence_rejoin_fail(PGRAC_EXTERNAL_FENCE_REJOIN_STALE, + PGRAC_EXTERNAL_FENCE_DENY_REJOIN_LINEAGE_MISMATCH, + reason); + for (i = 0; i < 16; i++) { if (pending->dead_bitmap[i] != 0) - return external_fence_rejoin_fail( - PGRAC_EXTERNAL_FENCE_REJOIN_STALE, - PGRAC_EXTERNAL_FENCE_DENY_REJOIN_LINEAGE_MISMATCH, - reason); + return external_fence_rejoin_fail(PGRAC_EXTERNAL_FENCE_REJOIN_STALE, + PGRAC_EXTERNAL_FENCE_DENY_REJOIN_LINEAGE_MISMATCH, + reason); } memset(¤t_pending, 0, sizeof(current_pending)); - if (!cluster_reconfig_rejoin_pending_snapshot( - &op->moved_clear->failure, pending->candidate_incarnation, - ¤t_pending) || - memcmp(¤t_pending, pending, sizeof(current_pending)) != 0) - return external_fence_rejoin_fail( - PGRAC_EXTERNAL_FENCE_REJOIN_STALE, - PGRAC_EXTERNAL_FENCE_DENY_JOIN_CANDIDATE_MISMATCH, reason); - if (!cluster_reconfig_rejoin_pending_ready(¤t_pending)) - { + if (!cluster_reconfig_rejoin_pending_snapshot(&op->moved_clear->failure, + pending->candidate_incarnation, ¤t_pending) + || memcmp(¤t_pending, pending, sizeof(current_pending)) != 0) + return external_fence_rejoin_fail(PGRAC_EXTERNAL_FENCE_REJOIN_STALE, + PGRAC_EXTERNAL_FENCE_DENY_JOIN_CANDIDATE_MISMATCH, + reason); + if (!cluster_reconfig_rejoin_pending_ready(¤t_pending)) { op->deny_reason = PGRAC_EXTERNAL_FENCE_DENY_JOIN_NOT_READY; - return external_fence_rejoin_fail( - PGRAC_EXTERNAL_FENCE_REJOIN_WAITING_JOINER, - PGRAC_EXTERNAL_FENCE_DENY_JOIN_NOT_READY, reason); + return external_fence_rejoin_fail(PGRAC_EXTERNAL_FENCE_REJOIN_WAITING_JOINER, + PGRAC_EXTERNAL_FENCE_DENY_JOIN_NOT_READY, reason); } memset(¤t_pending, 0, sizeof(current_pending)); - if (!cluster_reconfig_rejoin_pending_snapshot( - &op->moved_clear->failure, pending->candidate_incarnation, - ¤t_pending) || - memcmp(¤t_pending, pending, sizeof(current_pending)) != 0) - return external_fence_rejoin_fail( - PGRAC_EXTERNAL_FENCE_REJOIN_STALE, - PGRAC_EXTERNAL_FENCE_DENY_REJOIN_LINEAGE_MISMATCH, reason); + if (!cluster_reconfig_rejoin_pending_snapshot(&op->moved_clear->failure, + pending->candidate_incarnation, ¤t_pending) + || memcmp(¤t_pending, pending, sizeof(current_pending)) != 0) + return external_fence_rejoin_fail(PGRAC_EXTERNAL_FENCE_REJOIN_STALE, + PGRAC_EXTERNAL_FENCE_DENY_REJOIN_LINEAGE_MISMATCH, + reason); #ifdef WIN32 - return external_fence_rejoin_fail( - PGRAC_EXTERNAL_FENCE_REJOIN_UNAVAILABLE, - PGRAC_EXTERNAL_FENCE_DENY_DAEMON_UNAVAILABLE, reason); + return external_fence_rejoin_fail(PGRAC_EXTERNAL_FENCE_REJOIN_UNAVAILABLE, + PGRAC_EXTERNAL_FENCE_DENY_DAEMON_UNAVAILABLE, reason); #else - if (!external_fence_monotonic_now(&now_ns) || - now_ns >= op->deadline_mono_ns) - return external_fence_rejoin_terminal(op, - PGRAC_EXTERNAL_FENCE_REJOIN_UNKNOWN, - PGRAC_EXTERNAL_FENCE_DENY_TIMEOUT, reason); + if (!external_fence_monotonic_now(&now_ns) || now_ns >= op->deadline_mono_ns) + return external_fence_rejoin_terminal(op, PGRAC_EXTERNAL_FENCE_REJOIN_UNKNOWN, + PGRAC_EXTERNAL_FENCE_DENY_TIMEOUT, reason); poll_fd.fd = op->socket_fd; poll_fd.events = POLLIN | POLLHUP | POLLERR; poll_fd.revents = 0; if (poll(&poll_fd, 1, 0) != 0) - return external_fence_rejoin_terminal(op, - PGRAC_EXTERNAL_FENCE_REJOIN_STALE, - PGRAC_EXTERNAL_FENCE_DENY_CONNECTION_CLOSED, reason); + return external_fence_rejoin_terminal(op, PGRAC_EXTERNAL_FENCE_REJOIN_STALE, + PGRAC_EXTERNAL_FENCE_DENY_CONNECTION_CLOSED, reason); - if (!op->refresh_enqueue_pending) - { + if (!op->refresh_enqueue_pending) { memset(&refresh, 0, sizeof(refresh)); refresh.opcode = PGRAC_EXTERNAL_FENCE_REJOIN_LMON_REFRESH_ON; - if (!pg_strong_random(op->transport_nonce, - sizeof(op->transport_nonce)) || - !bytes_nonzero(op->transport_nonce, - sizeof(op->transport_nonce))) - return external_fence_rejoin_fail( - PGRAC_EXTERNAL_FENCE_REJOIN_UNAVAILABLE, - PGRAC_EXTERNAL_FENCE_DENY_PROTOCOL, reason); - memcpy(refresh.transport_nonce, op->transport_nonce, - sizeof(refresh.transport_nonce)); - memcpy(refresh.operation_id, op->offer_frame.operation_id, - sizeof(refresh.operation_id)); + if (!pg_strong_random(op->transport_nonce, sizeof(op->transport_nonce)) + || !bytes_nonzero(op->transport_nonce, sizeof(op->transport_nonce))) + return external_fence_rejoin_fail(PGRAC_EXTERNAL_FENCE_REJOIN_UNAVAILABLE, + PGRAC_EXTERNAL_FENCE_DENY_PROTOCOL, reason); + memcpy(refresh.transport_nonce, op->transport_nonce, sizeof(refresh.transport_nonce)); + memcpy(refresh.operation_id, op->offer_frame.operation_id, sizeof(refresh.operation_id)); refresh.system_identifier = op->rejoin_need.system_identifier; - memcpy(refresh.rejoin_gate_digest, - op->rejoin_need.rejoin_gate_digest, + memcpy(refresh.rejoin_gate_digest, op->rejoin_need.rejoin_gate_digest, sizeof(refresh.rejoin_gate_digest)); - memcpy(refresh.protected_set_digest, - op->rejoin_need.protected_set_digest, + memcpy(refresh.protected_set_digest, op->rejoin_need.protected_set_digest, sizeof(refresh.protected_set_digest)); refresh.old_node_id = op->rejoin_need.old_node_id; refresh.old_incarnation = op->rejoin_need.old_incarnation; - refresh.candidate_incarnation = - op->rejoin_need.candidate_incarnation; + refresh.candidate_incarnation = op->rejoin_need.candidate_incarnation; remaining_ns = op->deadline_mono_ns - now_ns; - remaining_ms = (remaining_ns + UINT64_C(999999)) / - UINT64_C(1000000); + remaining_ms = (remaining_ns + UINT64_C(999999)) / UINT64_C(1000000); if (remaining_ms < 1 || remaining_ms > 600000) - return external_fence_rejoin_terminal(op, - PGRAC_EXTERNAL_FENCE_REJOIN_UNKNOWN, - PGRAC_EXTERNAL_FENCE_DENY_TIMEOUT, reason); - refresh.timeout_ms = (uint32) remaining_ms; + return external_fence_rejoin_terminal(op, PGRAC_EXTERNAL_FENCE_REJOIN_UNKNOWN, + PGRAC_EXTERNAL_FENCE_DENY_TIMEOUT, reason); + refresh.timeout_ms = (uint32)remaining_ms; refresh.status = PGRAC_EXTERNAL_FENCE_REJOIN_PENDING; refresh.deny_reason = PGRAC_EXTERNAL_FENCE_DENY_NONE; if (!pgrac_external_fence_rejoin_v1_encode(&refresh, op->tx_frame)) - return external_fence_rejoin_fail( - PGRAC_EXTERNAL_FENCE_REJOIN_UNAVAILABLE, - PGRAC_EXTERNAL_FENCE_DENY_PROTOCOL, reason); + return external_fence_rejoin_fail(PGRAC_EXTERNAL_FENCE_REJOIN_UNAVAILABLE, + PGRAC_EXTERNAL_FENCE_DENY_PROTOCOL, reason); op->tx_sent = 0; op->rx_used = 0; op->refresh_pending = *pending; op->refresh_enqueue_pending = true; - } - else if (memcmp(&op->refresh_pending, pending, sizeof(*pending)) != 0) - return external_fence_rejoin_fail( - PGRAC_EXTERNAL_FENCE_REJOIN_STALE, - PGRAC_EXTERNAL_FENCE_DENY_JOIN_CANDIDATE_MISMATCH, reason); - - io_count = send(op->socket_fd, op->tx_frame + op->tx_sent, - sizeof(op->tx_frame) - op->tx_sent, send_flags); - if (io_count < 0) - { - if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR) - { + } else if (memcmp(&op->refresh_pending, pending, sizeof(*pending)) != 0) + return external_fence_rejoin_fail(PGRAC_EXTERNAL_FENCE_REJOIN_STALE, + PGRAC_EXTERNAL_FENCE_DENY_JOIN_CANDIDATE_MISMATCH, + reason); + + io_count = send(op->socket_fd, op->tx_frame + op->tx_sent, sizeof(op->tx_frame) - op->tx_sent, + send_flags); + if (io_count < 0) { + if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR) { *reason = PGRAC_EXTERNAL_FENCE_DENY_NONE; return PGRAC_EXTERNAL_FENCE_REJOIN_WAITING_JOINER; } - return external_fence_rejoin_terminal(op, - PGRAC_EXTERNAL_FENCE_REJOIN_STALE, - PGRAC_EXTERNAL_FENCE_DENY_CONNECTION_CLOSED, reason); + return external_fence_rejoin_terminal(op, PGRAC_EXTERNAL_FENCE_REJOIN_STALE, + PGRAC_EXTERNAL_FENCE_DENY_CONNECTION_CLOSED, reason); } if (io_count == 0) - return external_fence_rejoin_terminal(op, - PGRAC_EXTERNAL_FENCE_REJOIN_STALE, - PGRAC_EXTERNAL_FENCE_DENY_CONNECTION_CLOSED, reason); - op->tx_sent += (size_t) io_count; - if (op->tx_sent < sizeof(op->tx_frame)) - { + return external_fence_rejoin_terminal(op, PGRAC_EXTERNAL_FENCE_REJOIN_STALE, + PGRAC_EXTERNAL_FENCE_DENY_CONNECTION_CLOSED, reason); + op->tx_sent += (size_t)io_count; + if (op->tx_sent < sizeof(op->tx_frame)) { *reason = PGRAC_EXTERNAL_FENCE_DENY_NONE; return PGRAC_EXTERNAL_FENCE_REJOIN_WAITING_JOINER; } @@ -2800,10 +2397,9 @@ cluster_external_fence_rejoin_refresh_on_async( } bool -cluster_external_fence_rejoin_revalidate_root( - PgracExternalFenceRejoinOpV1 *op, - ClusterControlRootSnapshot *out_fresh_snapshot, - PgracExternalFenceDenyReason *reason) +cluster_external_fence_rejoin_revalidate_root(PgracExternalFenceRejoinOpV1 *op, + ClusterControlRootSnapshot *out_fresh_snapshot, + PgracExternalFenceDenyReason *reason) { ClusterControlRootSnapshot fresh_snapshot; ClusterControlRootResult result; @@ -2811,45 +2407,37 @@ cluster_external_fence_rejoin_revalidate_root( if (out_fresh_snapshot != NULL) memset(out_fresh_snapshot, 0, sizeof(*out_fresh_snapshot)); - if (reason == NULL || op == NULL || out_fresh_snapshot == NULL) - { - (void) external_fence_rejoin_fail( - PGRAC_EXTERNAL_FENCE_REJOIN_UNAVAILABLE, - PGRAC_EXTERNAL_FENCE_DENY_BAD_ARGUMENT, reason); + if (reason == NULL || op == NULL || out_fresh_snapshot == NULL) { + (void)external_fence_rejoin_fail(PGRAC_EXTERNAL_FENCE_REJOIN_UNAVAILABLE, + PGRAC_EXTERNAL_FENCE_DENY_BAD_ARGUMENT, reason); return false; } - if (op->magic != PGRAC_EXTERNAL_FENCE_REJOIN_OP_MAGIC || - op->owner_pid != external_fence_owner_pid() || - op->status != PGRAC_EXTERNAL_FENCE_REJOIN_READY || - op->moved_clear == NULL || op->consumed) - { - (void) external_fence_rejoin_fail( - PGRAC_EXTERNAL_FENCE_REJOIN_UNAVAILABLE, - PGRAC_EXTERNAL_FENCE_DENY_BAD_ARGUMENT, reason); + if (op->magic != PGRAC_EXTERNAL_FENCE_REJOIN_OP_MAGIC + || op->owner_pid != external_fence_owner_pid() + || op->status != PGRAC_EXTERNAL_FENCE_REJOIN_READY || op->moved_clear == NULL + || op->consumed) { + (void)external_fence_rejoin_fail(PGRAC_EXTERNAL_FENCE_REJOIN_UNAVAILABLE, + PGRAC_EXTERNAL_FENCE_DENY_BAD_ARGUMENT, reason); return false; } op->root_revalidated = false; memset(&fresh_snapshot, 0, sizeof(fresh_snapshot)); - result = cluster_control_root_revalidate(&op->saved_root_token, - &op->saved_root_identity, &fresh_snapshot); - if ((result != CLUSTER_CONTROL_ROOT_OK_PRIMARY && - result != CLUSTER_CONTROL_ROOT_OK_PRIMARY_DEGRADED) || - !external_fence_rejoin_root_complete_valid(op, - &op->saved_root_identity, &fresh_snapshot, - &op->saved_root_token) || - memcmp(&fresh_snapshot, &op->saved_root_snapshot, - sizeof(fresh_snapshot)) != 0 || - !external_fence_rejoin_root_completion_digest( - &op->saved_root_identity, &op->saved_root_token, - root_completion_digest) || - memcmp(root_completion_digest, op->root_completion_digest, - sizeof(root_completion_digest)) != 0) - { + result = cluster_control_root_revalidate(&op->saved_root_token, &op->saved_root_identity, + &fresh_snapshot); + if ((result != CLUSTER_CONTROL_ROOT_OK_PRIMARY + && result != CLUSTER_CONTROL_ROOT_OK_PRIMARY_DEGRADED) + || !external_fence_rejoin_root_complete_valid(op, &op->saved_root_identity, &fresh_snapshot, + &op->saved_root_token) + || memcmp(&fresh_snapshot, &op->saved_root_snapshot, sizeof(fresh_snapshot)) != 0 + || !external_fence_rejoin_root_completion_digest( + &op->saved_root_identity, &op->saved_root_token, root_completion_digest) + || memcmp(root_completion_digest, op->root_completion_digest, + sizeof(root_completion_digest)) + != 0) { op->status = PGRAC_EXTERNAL_FENCE_REJOIN_STALE; op->deny_reason = PGRAC_EXTERNAL_FENCE_DENY_ROOT_STALE; - (void) external_fence_rejoin_fail( - PGRAC_EXTERNAL_FENCE_REJOIN_STALE, - PGRAC_EXTERNAL_FENCE_DENY_ROOT_STALE, reason); + (void)external_fence_rejoin_fail(PGRAC_EXTERNAL_FENCE_REJOIN_STALE, + PGRAC_EXTERNAL_FENCE_DENY_ROOT_STALE, reason); return false; } op->root_revalidated = true; @@ -2862,137 +2450,98 @@ cluster_external_fence_rejoin_revalidate_root( bool cluster_external_fence_rejoin_consume_nowait( - PgracExternalFenceRejoinOpV1 *op, - const ClusterReconfigRejoinPendingSnapshotV1 *current_pending, - const ClusterJoinCommitMarker *committed_candidate, - PgracExternalFenceDenyReason *reason) + PgracExternalFenceRejoinOpV1 *op, const ClusterReconfigRejoinPendingSnapshotV1 *current_pending, + const ClusterJoinCommitMarker *committed_candidate, PgracExternalFenceDenyReason *reason) { uint64 now_ns; #ifndef WIN32 struct pollfd poll_fd; #endif - if (reason == NULL || op == NULL || current_pending == NULL || - committed_candidate == NULL) - { - (void) external_fence_rejoin_fail( - PGRAC_EXTERNAL_FENCE_REJOIN_UNAVAILABLE, - PGRAC_EXTERNAL_FENCE_DENY_BAD_ARGUMENT, reason); + if (reason == NULL || op == NULL || current_pending == NULL || committed_candidate == NULL) { + (void)external_fence_rejoin_fail(PGRAC_EXTERNAL_FENCE_REJOIN_UNAVAILABLE, + PGRAC_EXTERNAL_FENCE_DENY_BAD_ARGUMENT, reason); return false; } - if (op->magic != PGRAC_EXTERNAL_FENCE_REJOIN_OP_MAGIC || - op->owner_pid != external_fence_owner_pid()) - { - (void) external_fence_rejoin_fail( - PGRAC_EXTERNAL_FENCE_REJOIN_UNAVAILABLE, - PGRAC_EXTERNAL_FENCE_DENY_BAD_ARGUMENT, reason); + if (op->magic != PGRAC_EXTERNAL_FENCE_REJOIN_OP_MAGIC + || op->owner_pid != external_fence_owner_pid()) { + (void)external_fence_rejoin_fail(PGRAC_EXTERNAL_FENCE_REJOIN_UNAVAILABLE, + PGRAC_EXTERNAL_FENCE_DENY_BAD_ARGUMENT, reason); return false; } - if (op->consumed) - { - (void) external_fence_rejoin_fail( - PGRAC_EXTERNAL_FENCE_REJOIN_CONSUMED, - PGRAC_EXTERNAL_FENCE_DENY_REJOIN_CONSUMED, reason); + if (op->consumed) { + (void)external_fence_rejoin_fail(PGRAC_EXTERNAL_FENCE_REJOIN_CONSUMED, + PGRAC_EXTERNAL_FENCE_DENY_REJOIN_CONSUMED, reason); return false; } - if (op->status != PGRAC_EXTERNAL_FENCE_REJOIN_READY || - op->moved_clear == NULL || !op->root_revalidated || - op->socket_fd < 0) - { - (void) external_fence_rejoin_fail( - PGRAC_EXTERNAL_FENCE_REJOIN_STALE, - PGRAC_EXTERNAL_FENCE_DENY_REJOIN_LINEAGE_MISMATCH, reason); + if (op->status != PGRAC_EXTERNAL_FENCE_REJOIN_READY || op->moved_clear == NULL + || !op->root_revalidated || op->socket_fd < 0) { + (void)external_fence_rejoin_fail(PGRAC_EXTERNAL_FENCE_REJOIN_STALE, + PGRAC_EXTERNAL_FENCE_DENY_REJOIN_LINEAGE_MISMATCH, reason); return false; } - if (memcmp(current_pending, &op->refresh_pending, - sizeof(*current_pending)) != 0 || - current_pending->old_epoch != op->moved_clear->failure.new_epoch || - current_pending->new_epoch == UINT64_MAX || - current_pending->node_id != op->rejoin_need.old_node_id || - current_pending->candidate_incarnation != - op->rejoin_need.candidate_incarnation || - !cluster_reconfig_rejoin_pending_ready(current_pending) || - cluster_membership_get_state(current_pending->node_id) != - CLUSTER_MEMBER_JOINING || - cluster_membership_get_last_admitted_incarnation( - current_pending->node_id) >= - current_pending->candidate_incarnation || - cluster_epoch_get_current() != current_pending->new_epoch) - { - (void) external_fence_rejoin_fail( - PGRAC_EXTERNAL_FENCE_REJOIN_STALE, - PGRAC_EXTERNAL_FENCE_DENY_REJOIN_LINEAGE_MISMATCH, reason); + if (memcmp(current_pending, &op->refresh_pending, sizeof(*current_pending)) != 0 + || current_pending->old_epoch != op->moved_clear->failure.new_epoch + || current_pending->new_epoch == UINT64_MAX + || current_pending->node_id != op->rejoin_need.old_node_id + || current_pending->candidate_incarnation != op->rejoin_need.candidate_incarnation + || !cluster_reconfig_rejoin_pending_ready(current_pending) + || cluster_membership_get_state(current_pending->node_id) != CLUSTER_MEMBER_JOINING + || cluster_membership_get_last_admitted_incarnation(current_pending->node_id) + >= current_pending->candidate_incarnation + || cluster_epoch_get_current() != current_pending->new_epoch) { + (void)external_fence_rejoin_fail(PGRAC_EXTERNAL_FENCE_REJOIN_STALE, + PGRAC_EXTERNAL_FENCE_DENY_REJOIN_LINEAGE_MISMATCH, reason); return false; } - if (!cluster_join_marker_struct_valid(committed_candidate, - current_pending->node_id) || - committed_candidate->phase != CLUSTER_JCMK_PHASE_COMMITTED || - committed_candidate->_pad[0] != 0 || - committed_candidate->_pad[1] != 0 || - committed_candidate->_pad[2] != 0 || - committed_candidate->generation != - current_pending->candidate_incarnation || - committed_candidate->admitted_incarnation != - current_pending->candidate_incarnation || - committed_candidate->admitted_epoch != - current_pending->new_epoch + 1 || - committed_candidate->commit_nonce == 0) - { - (void) external_fence_rejoin_fail( - PGRAC_EXTERNAL_FENCE_REJOIN_STALE, - PGRAC_EXTERNAL_FENCE_DENY_JOIN_CANDIDATE_MISMATCH, reason); + if (!cluster_join_marker_struct_valid(committed_candidate, current_pending->node_id) + || committed_candidate->phase != CLUSTER_JCMK_PHASE_COMMITTED + || committed_candidate->_pad[0] != 0 || committed_candidate->_pad[1] != 0 + || committed_candidate->_pad[2] != 0 + || committed_candidate->generation != current_pending->candidate_incarnation + || committed_candidate->admitted_incarnation != current_pending->candidate_incarnation + || committed_candidate->admitted_epoch != current_pending->new_epoch + 1 + || committed_candidate->commit_nonce == 0) { + (void)external_fence_rejoin_fail(PGRAC_EXTERNAL_FENCE_REJOIN_STALE, + PGRAC_EXTERNAL_FENCE_DENY_JOIN_CANDIDATE_MISMATCH, reason); return false; } - if (op->binding.system_identifier != op->rejoin_need.system_identifier || - memcmp(op->binding.rejoin_gate_digest, - op->rejoin_need.rejoin_gate_digest, - sizeof(op->binding.rejoin_gate_digest)) != 0 || - op->binding.old_node_id != op->rejoin_need.old_node_id || - op->binding.reserved44 != 0 || - op->binding.old_incarnation != op->rejoin_need.old_incarnation || - op->binding.candidate_incarnation != - op->rejoin_need.candidate_incarnation || - op->binding.target_mapping_generation != - op->ready_frame.target_mapping_generation || - memcmp(op->binding.protected_set_digest, - op->rejoin_need.protected_set_digest, - sizeof(op->binding.protected_set_digest)) != 0 || - op->binding.predicate_id != - PGRAC_EXTERNAL_FENCE_PREDICATE_REJOIN_ON || - op->binding.predicate_version != - PGRAC_EXTERNAL_FENCE_PREDICATE_VERSION_V1) - { - (void) external_fence_rejoin_fail( - PGRAC_EXTERNAL_FENCE_REJOIN_STALE, - PGRAC_EXTERNAL_FENCE_DENY_BINDING_MISMATCH, reason); + if (op->binding.system_identifier != op->rejoin_need.system_identifier + || memcmp(op->binding.rejoin_gate_digest, op->rejoin_need.rejoin_gate_digest, + sizeof(op->binding.rejoin_gate_digest)) + != 0 + || op->binding.old_node_id != op->rejoin_need.old_node_id || op->binding.reserved44 != 0 + || op->binding.old_incarnation != op->rejoin_need.old_incarnation + || op->binding.candidate_incarnation != op->rejoin_need.candidate_incarnation + || op->binding.target_mapping_generation != op->ready_frame.target_mapping_generation + || memcmp(op->binding.protected_set_digest, op->rejoin_need.protected_set_digest, + sizeof(op->binding.protected_set_digest)) + != 0 + || op->binding.predicate_id != PGRAC_EXTERNAL_FENCE_PREDICATE_REJOIN_ON + || op->binding.predicate_version != PGRAC_EXTERNAL_FENCE_PREDICATE_VERSION_V1) { + (void)external_fence_rejoin_fail(PGRAC_EXTERNAL_FENCE_REJOIN_STALE, + PGRAC_EXTERNAL_FENCE_DENY_BINDING_MISMATCH, reason); return false; } #ifdef WIN32 - (void) now_ns; - (void) external_fence_rejoin_fail( - PGRAC_EXTERNAL_FENCE_REJOIN_UNAVAILABLE, - PGRAC_EXTERNAL_FENCE_DENY_DAEMON_UNAVAILABLE, reason); + (void)now_ns; + (void)external_fence_rejoin_fail(PGRAC_EXTERNAL_FENCE_REJOIN_UNAVAILABLE, + PGRAC_EXTERNAL_FENCE_DENY_DAEMON_UNAVAILABLE, reason); return false; #else - if (!external_fence_monotonic_now(&now_ns) || - now_ns >= op->deadline_mono_ns || - !external_fence_rejoin_refresh_result_valid(op, &op->ready_frame, - now_ns)) - { - (void) external_fence_rejoin_fail( - PGRAC_EXTERNAL_FENCE_REJOIN_STALE, - PGRAC_EXTERNAL_FENCE_DENY_EXPIRED, reason); + if (!external_fence_monotonic_now(&now_ns) || now_ns >= op->deadline_mono_ns + || !external_fence_rejoin_refresh_result_valid(op, &op->ready_frame, now_ns)) { + (void)external_fence_rejoin_fail(PGRAC_EXTERNAL_FENCE_REJOIN_STALE, + PGRAC_EXTERNAL_FENCE_DENY_EXPIRED, reason); return false; } poll_fd.fd = op->socket_fd; poll_fd.events = POLLIN | POLLHUP | POLLERR; poll_fd.revents = 0; - if (poll(&poll_fd, 1, 0) != 0) - { - (void) external_fence_rejoin_fail( - PGRAC_EXTERNAL_FENCE_REJOIN_STALE, - PGRAC_EXTERNAL_FENCE_DENY_CONNECTION_CLOSED, reason); + if (poll(&poll_fd, 1, 0) != 0) { + (void)external_fence_rejoin_fail(PGRAC_EXTERNAL_FENCE_REJOIN_STALE, + PGRAC_EXTERNAL_FENCE_DENY_CONNECTION_CLOSED, reason); return false; } @@ -3012,12 +2561,11 @@ cluster_external_fence_rejoin_consume_nowait( } const PgracExternalFenceRejoinBindingV1 * -cluster_external_fence_rejoin_binding( - const PgracExternalFenceRejoinOpV1 *op) +cluster_external_fence_rejoin_binding(const PgracExternalFenceRejoinOpV1 *op) { - if (op == NULL || op->magic != PGRAC_EXTERNAL_FENCE_REJOIN_OP_MAGIC || - op->owner_pid != external_fence_owner_pid() || - op->status != PGRAC_EXTERNAL_FENCE_REJOIN_READY) + if (op == NULL || op->magic != PGRAC_EXTERNAL_FENCE_REJOIN_OP_MAGIC + || op->owner_pid != external_fence_owner_pid() + || op->status != PGRAC_EXTERNAL_FENCE_REJOIN_READY) return NULL; return &op->binding; } @@ -3030,18 +2578,16 @@ cluster_external_fence_rejoin_release(PgracExternalFenceRejoinOpV1 **op) if (op == NULL || *op == NULL) return; value = *op; - if (value->magic != PGRAC_EXTERNAL_FENCE_REJOIN_OP_MAGIC || - value->owner_pid != external_fence_owner_pid()) - { + if (value->magic != PGRAC_EXTERNAL_FENCE_REJOIN_OP_MAGIC + || value->owner_pid != external_fence_owner_pid()) { *op = NULL; return; } #ifndef WIN32 if (value->socket_fd >= 0) - (void) close(value->socket_fd); + (void)close(value->socket_fd); #endif - if (value->moved_clear != NULL) - { + if (value->moved_clear != NULL) { explicit_bzero(value->moved_clear, sizeof(*value->moved_clear)); pfree(value->moved_clear); value->moved_clear = NULL; @@ -3060,9 +2606,8 @@ cluster_external_fence_rejoin_authority_clear_release( if (authority_clear == NULL || *authority_clear == NULL) return; value = *authority_clear; - if (value->magic == PGRAC_EXTERNAL_FENCE_REJOIN_CLEAR_MAGIC && - value->owner_pid == external_fence_owner_pid()) - { + if (value->magic == PGRAC_EXTERNAL_FENCE_REJOIN_CLEAR_MAGIC + && value->owner_pid == external_fence_owner_pid()) { memset(value, 0, sizeof(*value)); pfree(value); } diff --git a/src/backend/cluster/cluster_fence.c b/src/backend/cluster/cluster_fence.c index 6f34c82d296..47e47ff987a 100644 --- a/src/backend/cluster/cluster_fence.c +++ b/src/backend/cluster/cluster_fence.c @@ -69,7 +69,7 @@ #include "utils/timestamp.h" #include "funcapi.h" -#include "cluster/cluster_guc.h" /* cluster_enabled */ +#include "cluster/cluster_guc.h" /* cluster_enabled */ #include "cluster/cluster_clean_leave.h" #include "cluster/cluster_inject.h" /* CLUSTER_INJECTION_POINT (Step 4 D12) */ #include "cluster/cluster_pgstat.h" /* cluster_pgstat_lookup/_inc (Step 4 D11) */ diff --git a/src/backend/cluster/cluster_fence_authority.c b/src/backend/cluster/cluster_fence_authority.c index d8532a112e4..b2d780b55df 100644 --- a/src/backend/cluster/cluster_fence_authority.c +++ b/src/backend/cluster/cluster_fence_authority.c @@ -166,8 +166,8 @@ cluster_write_fence_read_durable_authority(ClusterFenceAuthorityProof *out) } } if (!disk_failed) - disk_states[i] = cluster_fence_disk_vote_select_v1( - slot_markers, outer_crc_valid, CLUSTER_MAX_NODES, &disk_markers[i]); + disk_states[i] = cluster_fence_disk_vote_select_v1(slot_markers, outer_crc_valid, + CLUSTER_MAX_NODES, &disk_markers[i]); } pgstat_report_wait_end(); fence_close_targets(targets, n_total); @@ -177,11 +177,9 @@ cluster_write_fence_read_durable_authority(ClusterFenceAuthorityProof *out) } ClusterRecoveryOwnerImportResult -cluster_recovery_owner_import_read_v1(int32 node_id, - const ClusterWalThreadClaim *immutable_claim, - uint64 frozen_admitted_bitmap_low, - uint64 frozen_admitted_bitmap_high, - uint64 *out_incarnation) +cluster_recovery_owner_import_read_v1(int32 node_id, const ClusterWalThreadClaim *immutable_claim, + uint64 frozen_admitted_bitmap_low, + uint64 frozen_admitted_bitmap_high, uint64 *out_incarnation) { ClusterFenceDiskTarget targets[CLUSTER_MAX_VOTING_DISKS]; ClusterRecoveryOwnerDiskSampleV1 samples[CLUSTER_MAX_VOTING_DISKS]; @@ -237,18 +235,18 @@ cluster_recovery_owner_import_read_v1(int32 node_id, if (targets[i].fd < 0 || !targets[i].stat_valid) continue; memset(&join_slot, 0, sizeof(join_slot)); - samples[i].join_io_state = cluster_voting_disk_read_join_slot( - targets[i].fd, (uint32)node_id, join_slot.bytes); + samples[i].join_io_state + = cluster_voting_disk_read_join_slot(targets[i].fd, (uint32)node_id, join_slot.bytes); if (samples[i].join_io_state == CLUSTER_VOTING_DISK_IO_OK) samples[i].join_marker = join_slot.marker; - samples[i].slot_io_state = cluster_voting_disk_read_slot( - targets[i].fd, i, (uint32)node_id, &samples[i].slot); + samples[i].slot_io_state + = cluster_voting_disk_read_slot(targets[i].fd, i, (uint32)node_id, &samples[i].slot); } pgstat_report_wait_end(); fence_close_targets(targets, n_total); return cluster_recovery_owner_import_select_v1( - node_id, immutable_claim, frozen_admitted_bitmap_low, - frozen_admitted_bitmap_high, samples, n_total, out_incarnation); + node_id, immutable_claim, frozen_admitted_bitmap_low, frozen_admitted_bitmap_high, samples, + n_total, out_incarnation); } #endif /* USE_PGRAC_CLUSTER */ diff --git a/src/backend/cluster/cluster_formation_marker.c b/src/backend/cluster/cluster_formation_marker.c index 1a36f3c8b66..e6abf5ef0ed 100644 --- a/src/backend/cluster/cluster_formation_marker.c +++ b/src/backend/cluster/cluster_formation_marker.c @@ -24,49 +24,48 @@ static void write_u16_le(uint8 *dst, uint16 value) { - dst[0] = (uint8) (value & 0xff); - dst[1] = (uint8) ((value >> 8) & 0xff); + dst[0] = (uint8)(value & 0xff); + dst[1] = (uint8)((value >> 8) & 0xff); } static void write_u32_le(uint8 *dst, uint32 value) { - int i; + int i; for (i = 0; i < 4; i++) - dst[i] = (uint8) ((value >> (8 * i)) & 0xff); + dst[i] = (uint8)((value >> (8 * i)) & 0xff); } static void write_u64_le(uint8 *dst, uint64 value) { - int i; + int i; for (i = 0; i < 8; i++) - dst[i] = (uint8) ((value >> (8 * i)) & 0xff); + dst[i] = (uint8)((value >> (8 * i)) & 0xff); } static uint16 read_u16_le(const uint8 *src) { - return (uint16) src[0] | ((uint16) src[1] << 8); + return (uint16)src[0] | ((uint16)src[1] << 8); } static uint32 read_u32_le(const uint8 *src) { - return (uint32) src[0] | ((uint32) src[1] << 8) - | ((uint32) src[2] << 16) | ((uint32) src[3] << 24); + return (uint32)src[0] | ((uint32)src[1] << 8) | ((uint32)src[2] << 16) | ((uint32)src[3] << 24); } static uint64 read_u64_le(const uint8 *src) { - uint64 v = 0; - int i; + uint64 v = 0; + int i; for (i = 0; i < 8; i++) - v |= (uint64) src[i] << (8 * i); + v |= (uint64)src[i] << (8 * i); return v; } @@ -78,7 +77,7 @@ cluster_formation_marker_compute_crc(ClusterFormationCommitMarker *marker) INIT_CRC32C(crc); COMP_CRC32C(crc, marker, offsetof(ClusterFormationCommitMarker, crc32c)); FIN_CRC32C(crc); - marker->crc32c = (uint32) crc; + marker->crc32c = (uint32)crc; } /* @@ -92,8 +91,7 @@ cluster_formation_marker_compute_crc(ClusterFormationCommitMarker *marker) * ranges. */ static uint32 -formation_marker_wire_crc(const uint8 slot_bytes[CLUSTER_VOTING_SLOT_BYTES], - int n_admitted) +formation_marker_wire_crc(const uint8 slot_bytes[CLUSTER_VOTING_SLOT_BYTES], int n_admitted) { pg_crc32c crc; @@ -103,7 +101,7 @@ formation_marker_wire_crc(const uint8 slot_bytes[CLUSTER_VOTING_SLOT_BYTES], COMP_CRC32C(crc, slot_bytes + CLUSTER_FORMATION_MARKER_HEADER_BYTES, n_admitted * CLUSTER_FORMATION_MARKER_ENTRY_BYTES); FIN_CRC32C(crc); - return (uint32) crc; + return (uint32)crc; } /* @@ -117,18 +115,16 @@ cluster_formation_marker_encode(const ClusterFormationCommitMarker *marker, const uint64 *incarnation_by_node, uint8 slot_bytes[CLUSTER_VOTING_SLOT_BYTES]) { - int member; - uint32 pop = 0; - int off; + int member; + uint32 pop = 0; + int off; if (marker == NULL || incarnation_by_node == NULL || slot_bytes == NULL || marker->magic != CLUSTER_FORMATION_MARKER_MAGIC || marker->version != CLUSTER_FORMATION_MARKER_VERSION || marker->phase != CLUSTER_FORMATION_MARKER_PHASE_COMMITTED - || marker->formation_generation == 0 - || marker->arbiter_node >= CLUSTER_MAX_NODES - || marker->arbiter_incarnation == 0 - || marker->commit_nonce == 0) + || marker->formation_generation == 0 || marker->arbiter_node >= CLUSTER_MAX_NODES + || marker->arbiter_incarnation == 0 || marker->commit_nonce == 0) return false; /* @@ -140,14 +136,12 @@ cluster_formation_marker_encode(const ClusterFormationCommitMarker *marker, * structural violation (fail-closed). */ for (member = 0; member < CLUSTER_MAX_NODES; member++) - if ((marker->admitted_nodes[member / 8] - & (uint8) (1u << (member % 8))) != 0) { + if ((marker->admitted_nodes[member / 8] & (uint8)(1u << (member % 8))) != 0) { if (member >= CLUSTER_FORMATION_MARKER_MAX_MEMBERS) return false; pop++; } - if (pop == 0 || pop != marker->n_admitted - || pop > CLUSTER_FORMATION_MARKER_MAX_MEMBERS) + if (pop == 0 || pop != marker->n_admitted || pop > CLUSTER_FORMATION_MARKER_MAX_MEMBERS) return false; memset(slot_bytes, 0, CLUSTER_VOTING_SLOT_BYTES); @@ -159,28 +153,24 @@ cluster_formation_marker_encode(const ClusterFormationCommitMarker *marker, write_u64_le(slot_bytes + 24, marker->arbiter_node); write_u64_le(slot_bytes + 32, marker->arbiter_incarnation); write_u64_le(slot_bytes + 40, marker->commit_nonce); - memcpy(slot_bytes + 48, marker->admitted_nodes, - CLUSTER_FORMATION_MARKER_BITMAP_BYTES); + memcpy(slot_bytes + 48, marker->admitted_nodes, CLUSTER_FORMATION_MARKER_BITMAP_BYTES); write_u16_le(slot_bytes + 64, marker->n_admitted); /* Compact member entries. */ off = CLUSTER_FORMATION_MARKER_HEADER_BYTES; - for (member = 0; member < CLUSTER_MAX_NODES; member++) - { - if ((marker->admitted_nodes[member / 8] - & (uint8) (1u << (member % 8))) == 0) + for (member = 0; member < CLUSTER_MAX_NODES; member++) { + if ((marker->admitted_nodes[member / 8] & (uint8)(1u << (member % 8))) == 0) continue; if (incarnation_by_node[member] == 0) return false; - slot_bytes[off++] = (uint8) member; + slot_bytes[off++] = (uint8)member; write_u64_le(slot_bytes + off, incarnation_by_node[member]); off += 8; } /* B′ P0 fix: the wire CRC covers the header + the compact table — * computed HERE, after the table is laid out, so the stored crc field * matches the exact bytes decode will hash. */ - write_u32_le(slot_bytes + 68, - formation_marker_wire_crc(slot_bytes, (int) marker->n_admitted)); + write_u32_le(slot_bytes + 68, formation_marker_wire_crc(slot_bytes, (int)marker->n_admitted)); return true; } @@ -192,14 +182,13 @@ cluster_formation_marker_encode(const ClusterFormationCommitMarker *marker, */ bool cluster_formation_marker_decode(const uint8 slot_bytes[CLUSTER_VOTING_SLOT_BYTES], - ClusterFormationCommitMarker *marker, - uint64 *incarnation_by_node) + ClusterFormationCommitMarker *marker, uint64 *incarnation_by_node) { ClusterFormationCommitMarker decoded; - uint32 expected_crc; - uint32 pop = 0; - int off; - int i; + uint32 expected_crc; + uint32 pop = 0; + int off; + int i; if (slot_bytes == NULL || marker == NULL) return false; @@ -212,18 +201,15 @@ cluster_formation_marker_decode(const uint8 slot_bytes[CLUSTER_VOTING_SLOT_BYTES decoded.arbiter_node = read_u64_le(slot_bytes + 24); decoded.arbiter_incarnation = read_u64_le(slot_bytes + 32); decoded.commit_nonce = read_u64_le(slot_bytes + 40); - memcpy(decoded.admitted_nodes, slot_bytes + 48, - CLUSTER_FORMATION_MARKER_BITMAP_BYTES); + memcpy(decoded.admitted_nodes, slot_bytes + 48, CLUSTER_FORMATION_MARKER_BITMAP_BYTES); decoded.n_admitted = read_u16_le(slot_bytes + 64); expected_crc = read_u32_le(slot_bytes + 68); if (decoded.magic != CLUSTER_FORMATION_MARKER_MAGIC || decoded.version != CLUSTER_FORMATION_MARKER_VERSION || decoded.phase != CLUSTER_FORMATION_MARKER_PHASE_COMMITTED - || decoded.formation_generation == 0 - || decoded.arbiter_node >= CLUSTER_MAX_NODES - || decoded.arbiter_incarnation == 0 - || decoded.commit_nonce == 0) + || decoded.formation_generation == 0 || decoded.arbiter_node >= CLUSTER_MAX_NODES + || decoded.arbiter_incarnation == 0 || decoded.commit_nonce == 0) return false; /* @@ -233,8 +219,7 @@ cluster_formation_marker_decode(const uint8 slot_bytes[CLUSTER_VOTING_SLOT_BYTES * Clamp BEFORE hashing — the count can never exceed the compact-table * capacity. */ - if (decoded.n_admitted == 0 - || decoded.n_admitted > CLUSTER_FORMATION_MARKER_MAX_MEMBERS) + if (decoded.n_admitted == 0 || decoded.n_admitted > CLUSTER_FORMATION_MARKER_MAX_MEMBERS) return false; /* @@ -243,13 +228,11 @@ cluster_formation_marker_decode(const uint8 slot_bytes[CLUSTER_VOTING_SLOT_BYTES * byte ranges encode hashed. A corrupt n_admitted therefore fails * the structural checks below anyway; a table tamper fails here. */ - if (formation_marker_wire_crc(slot_bytes, (int) decoded.n_admitted) - != expected_crc) + if (formation_marker_wire_crc(slot_bytes, (int)decoded.n_admitted) != expected_crc) return false; for (i = 0; i < CLUSTER_MAX_NODES; i++) - if ((decoded.admitted_nodes[i / 8] - & (uint8) (1u << (i % 8))) != 0) { + if ((decoded.admitted_nodes[i / 8] & (uint8)(1u << (i % 8))) != 0) { /* B′ P0 fix: mirror of the encode-side 48/128 capacity * clamp — a bitmap bit at or beyond MAX_MEMBERS cannot be * represented in the compact table. */ @@ -257,23 +240,19 @@ cluster_formation_marker_decode(const uint8 slot_bytes[CLUSTER_VOTING_SLOT_BYTES return false; pop++; } - if (pop == 0 || pop != decoded.n_admitted - || pop > CLUSTER_FORMATION_MARKER_MAX_MEMBERS) + if (pop == 0 || pop != decoded.n_admitted || pop > CLUSTER_FORMATION_MARKER_MAX_MEMBERS) return false; if (incarnation_by_node != NULL) - memset(incarnation_by_node, 0, - CLUSTER_MAX_NODES * sizeof(uint64)); + memset(incarnation_by_node, 0, CLUSTER_MAX_NODES * sizeof(uint64)); off = CLUSTER_FORMATION_MARKER_HEADER_BYTES; - for (i = 0; i < (int) decoded.n_admitted; i++) - { - int node_id = slot_bytes[off++]; - uint64 inc = read_u64_le(slot_bytes + off); + for (i = 0; i < (int)decoded.n_admitted; i++) { + int node_id = slot_bytes[off++]; + uint64 inc = read_u64_le(slot_bytes + off); off += 8; if (node_id < 0 || node_id >= CLUSTER_MAX_NODES - || (decoded.admitted_nodes[node_id / 8] - & (uint8) (1u << (node_id % 8))) == 0 + || (decoded.admitted_nodes[node_id / 8] & (uint8)(1u << (node_id % 8))) == 0 || inc == 0) return false; if (incarnation_by_node != NULL) @@ -284,11 +263,9 @@ cluster_formation_marker_decode(const uint8 slot_bytes[CLUSTER_VOTING_SLOT_BYTES } uint64 -cluster_formation_marker_incarnation_for(const uint64 *incarnation_by_node, - int32 node_id) +cluster_formation_marker_incarnation_for(const uint64 *incarnation_by_node, int32 node_id) { - if (incarnation_by_node == NULL || node_id < 0 - || node_id >= CLUSTER_MAX_NODES) + if (incarnation_by_node == NULL || node_id < 0 || node_id >= CLUSTER_MAX_NODES) return 0; return incarnation_by_node[node_id]; } @@ -302,6 +279,5 @@ cluster_formation_marker_validate(const uint8 slot_bytes[CLUSTER_VOTING_SLOT_BYT ClusterFormationCommitMarker *out_decoded, uint64 *out_incarnations) { - return cluster_formation_marker_decode(slot_bytes, out_decoded, - out_incarnations); + return cluster_formation_marker_decode(slot_bytes, out_decoded, out_incarnations); } diff --git a/src/backend/cluster/cluster_gcs.c b/src/backend/cluster/cluster_gcs.c index 7b478cd8a4e..0f2b0c3d572 100644 --- a/src/backend/cluster/cluster_gcs.c +++ b/src/backend/cluster/cluster_gcs.c @@ -373,15 +373,17 @@ gcs_reserve_slot(BufferTag tag, uint8 transition_id, int32 master_node, uint64 * int i; uint32 cur_outstanding; - if (cluster_node_id < 0 || cluster_node_id > (int)GCS_REQID_NODE_MASK - || backend_ord < 0 || backend_ord > (int)GCS_REQID_BACKEND_MASK) - ereport(ERROR, (errcode(ERRCODE_INTERNAL_ERROR), - errmsg("cluster_gcs: requester identity node=%d backend=%d is out of request-id domain", - cluster_node_id, backend_ord))); + if (cluster_node_id < 0 || cluster_node_id > (int)GCS_REQID_NODE_MASK || backend_ord < 0 + || backend_ord > (int)GCS_REQID_BACKEND_MASK) + ereport( + ERROR, + (errcode(ERRCODE_INTERNAL_ERROR), + errmsg( + "cluster_gcs: requester identity node=%d backend=%d is out of request-id domain", + cluster_node_id, backend_ord))); LWLockAcquire(&blk->lock.lock, LW_EXCLUSIVE); - if (blk->next_request_id == 0 - || blk->next_request_id > GCS_REQID_REQUESTER_SEQ_MASK) { + if (blk->next_request_id == 0 || blk->next_request_id > GCS_REQID_REQUESTER_SEQ_MASK) { LWLockRelease(&blk->lock.lock); ereport(ERROR, (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), errmsg("cluster_gcs: requester sequence exhausted for node=%d backend=%d", @@ -480,9 +482,9 @@ gcs_mark_slot_reply(const ClusterICEnvelope *env, const GcsReplyPayload *reply) ClusterGcsOutstandingSlot *slot = &blk->slots[i]; if (slot->in_use && !slot->reply_received - && cluster_gcs_reply_matches_outstanding( - reply, slot->request_id, slot->transition_id, slot->master_node, - env->source_node_id)) { + && cluster_gcs_reply_matches_outstanding(reply, slot->request_id, + slot->transition_id, slot->master_node, + env->source_node_id)) { slot->reply = *reply; slot->reply_received = true; ConditionVariableSignal(&slot->reply_cv); diff --git a/src/backend/cluster/cluster_gcs_block.c b/src/backend/cluster/cluster_gcs_block.c index 79eecd74a7d..1a27eb7a79f 100644 --- a/src/backend/cluster/cluster_gcs_block.c +++ b/src/backend/cluster/cluster_gcs_block.c @@ -57,12 +57,12 @@ #include "cluster/cluster_gcs_block_dedup.h" /* spec-2.34 D1 — counter forward */ #include "cluster/cluster_grd.h" /* spec-4.6 D4 — block_path_failclosed counter */ #include "cluster/cluster_grd_outbound.h" -#include "cluster/cluster_membership.h" /* spec-5.16 D3b — is_member master-side gate */ +#include "cluster/cluster_membership.h" /* spec-5.16 D3b — is_member master-side gate */ #include "cluster/cluster_multixact_current_wire.h" #include "cluster/cluster_multixact_current_stats.h" -#include "cluster/cluster_qvotec.h" /* spec-5.16 D3b — in_quorum master-side gate */ -#include "cluster/cluster_reconfig.h" /* QVOTEC-observed live peer incarnation */ -#include "cluster/cluster_recovery_merge.h" /* spec-4.7 D5 — recovered_through redo gate */ +#include "cluster/cluster_qvotec.h" /* spec-5.16 D3b — in_quorum master-side gate */ +#include "cluster/cluster_reconfig.h" /* QVOTEC-observed live peer incarnation */ +#include "cluster/cluster_recovery_merge.h" /* spec-4.7 D5 — recovered_through redo gate */ #include "cluster/cluster_r4_observe.h" #include "cluster/cluster_runtime_visibility.h" #include "cluster/cluster_scn.h" @@ -71,8 +71,8 @@ #include "cluster/cluster_startup_phase.h" #include "cluster/cluster_thread_recovery.h" /* spec-4.11 scope gate for online replay */ #include "cluster/cluster_tt_durable.h" -#include "cluster/cluster_xnode_profile.h" /* spec-5.59 D2/D3/D4 profiling buckets */ -#include "cluster/cluster_xnode_lever.h" /* spec-6.12a — downgrade counters */ +#include "cluster/cluster_xnode_profile.h" /* spec-5.59 D2/D3/D4 profiling buckets */ +#include "cluster/cluster_xnode_lever.h" /* spec-6.12a — downgrade counters */ #include "cluster/cluster_xid_stripe.h" #include "cluster/cluster_guc.h" #include "cluster/cluster_inject.h" @@ -156,11 +156,9 @@ typedef enum ClusterGcsBlockReplyDomain { * freshness/fail-closed checks. */ #define GCS_BLOCK_R4_TX_ORIGIN_CONTEXTS 128 #define GCS_BLOCK_R4_TX_ORIGIN_STEP_BUDGET 6 -#define GCS_BLOCK_R4_TX_REQUIRED_HELLO_CAPS \ - (PGRAC_IC_HELLO_CAP_SEMANTIC_ACTIVATION_V1 \ - | PGRAC_IC_HELLO_CAP_R4_SYNC_CR_V1 \ - | PGRAC_IC_HELLO_CAP_CANDIDATE2_CORRECTED_A1_V1 \ - | PGRAC_IC_HELLO_CAP_UNDO_ROOT_DESCRIPTOR_V1) +#define GCS_BLOCK_R4_TX_REQUIRED_HELLO_CAPS \ + (PGRAC_IC_HELLO_CAP_SEMANTIC_ACTIVATION_V1 | PGRAC_IC_HELLO_CAP_R4_SYNC_CR_V1 \ + | PGRAC_IC_HELLO_CAP_CANDIDATE2_CORRECTED_A1_V1 | PGRAC_IC_HELLO_CAP_UNDO_ROOT_DESCRIPTOR_V1) typedef enum GcsBlockR4TxOriginPhase { GCS_BLOCK_R4_TX_ORIGIN_ACQUIRE_BEGIN = 1, @@ -223,14 +221,10 @@ typedef struct GcsBlockR4TxOriginContext { ClusterUndoBlock0CurrentGuard guard; ClusterRuntimeVisibilityOriginPlan origin_plan; ClusterCurrentMxProofForwardV2 current_mx_request; - ClusterTTSlotPhysicalLocator current_mx_locators[ - CLUSTER_CURRENT_MX_MAX_PROOF_ASKS_PER_FRAME]; - ClusterCurrentMemberProof current_mx_proofs[ - CLUSTER_CURRENT_MX_MAX_PROOF_ASKS_PER_FRAME]; - ClusterCtrcTxnKeyV1 current_mx_ctrc_keys[ - CLUSTER_CURRENT_MX_MAX_PROOF_ASKS_PER_FRAME]; - ClusterTTStatusKey current_mx_sampled_keys[ - CLUSTER_CURRENT_MX_MAX_PROOF_ASKS_PER_FRAME]; + ClusterTTSlotPhysicalLocator current_mx_locators[CLUSTER_CURRENT_MX_MAX_PROOF_ASKS_PER_FRAME]; + ClusterCurrentMemberProof current_mx_proofs[CLUSTER_CURRENT_MX_MAX_PROOF_ASKS_PER_FRAME]; + ClusterCtrcTxnKeyV1 current_mx_ctrc_keys[CLUSTER_CURRENT_MX_MAX_PROOF_ASKS_PER_FRAME]; + ClusterTTStatusKey current_mx_sampled_keys[CLUSTER_CURRENT_MX_MAX_PROOF_ASKS_PER_FRAME]; ClusterCurrentUpdaterProof current_mx_updater_proof; ClusterMxResolveResult current_mx_result; GcsBlockCurrentMxOriginFailure current_mx_failure; @@ -248,8 +242,7 @@ typedef struct GcsBlockR4TxOriginContext { uint8 reply_frame[GCS_BLOCK_REPLY_PAYLOAD_TOTAL_SIZE + sizeof(ClusterGcsUndoAuthTrailer)]; } GcsBlockR4TxOriginContext; -static GcsBlockR4TxOriginContext - gcs_block_r4_tx_origin_contexts[GCS_BLOCK_R4_TX_ORIGIN_CONTEXTS]; +static GcsBlockR4TxOriginContext gcs_block_r4_tx_origin_contexts[GCS_BLOCK_R4_TX_ORIGIN_CONTEXTS]; static bool gcs_block_r4_tx_origin_first_denial_logged = false; static bool gcs_block_current_mx_origin_first_unknown_logged = false; @@ -276,9 +269,8 @@ typedef enum GcsBlockResourceXDiagnostic { } GcsBlockResourceXDiagnostic; static uint64 - gcs_block_resource_x_diagnostic_next_log_at - [GCS_BLOCK_RESOURCE_X_DIAGNOSTIC_COUNT] - [GCS_BLOCK_RESOURCE_X_DIAGNOSTIC_CLASS_COUNT]; + gcs_block_resource_x_diagnostic_next_log_at[GCS_BLOCK_RESOURCE_X_DIAGNOSTIC_COUNT] + [GCS_BLOCK_RESOURCE_X_DIAGNOSTIC_CLASS_COUNT]; typedef struct ClusterGcsBlockOutstandingSlot { bool in_use; @@ -349,16 +341,13 @@ typedef struct ClusterGcsBlockBackendBlock { } ClusterGcsBlockBackendBlock; static void -gcs_block_slot_clear_current_mx_expectation( - ClusterGcsBlockOutstandingSlot *slot) +gcs_block_slot_clear_current_mx_expectation(ClusterGcsBlockOutstandingSlot *slot) { slot->expected_reply_status = 0; slot->expected_current_mx_key_valid = false; - memset(&slot->expected_current_mx_key, 0, - sizeof(slot->expected_current_mx_key)); + memset(&slot->expected_current_mx_key, 0, sizeof(slot->expected_current_mx_key)); slot->expected_current_mx_proof_valid = false; - memset(&slot->expected_current_mx_proof, 0, - sizeof(slot->expected_current_mx_proof)); + memset(&slot->expected_current_mx_proof, 0, sizeof(slot->expected_current_mx_proof)); } static ClusterGcsBlockBackendBlock *gcs_block_backend_blocks = NULL; @@ -378,18 +367,14 @@ cluster_gcs_block_r4_requester_count(void) return UINT64_MAX; for (backend_id = 0; backend_id < MaxBackends; backend_id++) { - ClusterGcsBlockBackendBlock *blk - = &gcs_block_backend_blocks[backend_id]; + ClusterGcsBlockBackendBlock *blk = &gcs_block_backend_blocks[backend_id]; int slot_id; LWLockAcquire(&blk->lock.lock, LW_SHARED); - for (slot_id = 0; - slot_id < MAX_OUTSTANDING_BLOCK_REQUESTS_PER_BACKEND; - slot_id++) { + for (slot_id = 0; slot_id < MAX_OUTSTANDING_BLOCK_REQUESTS_PER_BACKEND; slot_id++) { const ClusterGcsBlockOutstandingSlot *slot = &blk->slots[slot_id]; - if (slot->in_use - && slot->reply_domain == CLUSTER_GCS_BLOCK_REPLY_DOMAIN_R4_CR) + if (slot->in_use && slot->reply_domain == CLUSTER_GCS_BLOCK_REPLY_DOMAIN_R4_CR) count++; } LWLockRelease(&blk->lock.lock); @@ -541,11 +526,11 @@ typedef struct ClusterGcsBlockShared { /* PGRAC: spec-4.7 D6 — GCS/PCM warm-recovery observability (dump category * 'gcs_recovery'). */ pg_atomic_uint64 recovery_block_resources_recovering; /* phase_for_tag → RECOVERING hits */ - pg_atomic_uint64 recovery_buffers_redeclared; /* survivor re-declare sent (D2) */ - pg_atomic_uint64 recovery_block_state_rebuilt; /* master rebuild applied (D2/D3) */ - pg_atomic_uint64 recovery_redo_boundary_waits; /* redo gate: not yet covered (D5) */ - pg_atomic_uint64 recovery_redo_boundary_reached; /* redo gate: covered (D5) */ - pg_atomic_uint64 recovery_stale_block_drop; /* re-declare dropped: off-epoch/bad (D2) */ + pg_atomic_uint64 recovery_buffers_redeclared; /* survivor re-declare sent (D2) */ + pg_atomic_uint64 recovery_block_state_rebuilt; /* master rebuild applied (D2/D3) */ + pg_atomic_uint64 recovery_redo_boundary_waits; /* redo gate: not yet covered (D5) */ + pg_atomic_uint64 recovery_redo_boundary_reached; /* redo gate: covered (D5) */ + pg_atomic_uint64 recovery_stale_block_drop; /* re-declare dropped: off-epoch/bad (D2) */ pg_atomic_uint64 recovery_ambiguous_owner_failclosed; /* not-double-X conflict (D3) */ pg_atomic_uint64 recovery_before_boundary_failclosed; /* served-before-redo gate fail (D5) */ /* PGRAC: spec-2.36 D3 (HC116) — master broadcast invalidate slot. @@ -671,11 +656,12 @@ static ClusterGcsBlockOutstandingSlot *cluster_gcs_block_test_requester_slot = N * ============================================================ */ static ClusterGcsBlockBackendBlock *gcs_block_my_block(void); static ClusterGcsBlockOutstandingSlot *gcs_block_reserve_slot(BufferTag tag, uint8 transition_id, - int32 master_node, - uint64 *out_request_id); -static ClusterGcsBlockOutstandingSlot *gcs_block_try_reserve_r4_slot( - BufferTag tag, uint64 request_epoch, int32 expected_master_node, - uint64 *out_request_id); + int32 master_node, + uint64 *out_request_id); +static ClusterGcsBlockOutstandingSlot *gcs_block_try_reserve_r4_slot(BufferTag tag, + uint64 request_epoch, + int32 expected_master_node, + uint64 *out_request_id); static ClusterCrBuildResult gcs_block_r4_cr_fetch_and_wait_raw( BufferTag tag, SCN read_scn, int32 real_master_node, char dst_page[GCS_BLOCK_DATA_SIZE], ClusterCrBuildReason *reason_out, const ClusterSemanticAdmissionToken *admission); @@ -683,14 +669,15 @@ static void gcs_block_release_slot(ClusterGcsBlockOutstandingSlot *slot); static void gcs_block_send_reply(int32 dest_node, const GcsBlockRequestPayload *req, GcsBlockReplyStatus status, XLogRecPtr page_lsn, const char *block_data); -static ClusterICSendResult gcs_block_send_envelope_or_loopback( - uint8 msg_type, int32 dest_node, const void *payload, uint32 payload_len); -static bool gcs_block_r4_tx_origin_try_accept( - const ClusterICEnvelope *env, const ClusterR4CrForwardPayload *forward); -static bool gcs_block_current_mx_origin_try_accept( - const ClusterICEnvelope *env, const void *payload); -static void gcs_block_r4_tx_origin_context_clear( - GcsBlockR4TxOriginContext *context, bool cancel_guard); +static ClusterICSendResult gcs_block_send_envelope_or_loopback(uint8 msg_type, int32 dest_node, + const void *payload, + uint32 payload_len); +static bool gcs_block_r4_tx_origin_try_accept(const ClusterICEnvelope *env, + const ClusterR4CrForwardPayload *forward); +static bool gcs_block_current_mx_origin_try_accept(const ClusterICEnvelope *env, + const void *payload); +static void gcs_block_r4_tx_origin_context_clear(GcsBlockR4TxOriginContext *context, + bool cancel_guard); static bool gcs_block_get_ship_image(BufferTag tag, int32 dest_node, bool allow_live_sge, XLogRecPtr *out_page_lsn, char *copy_buf, const char **out_block_payload, uint32 *out_block_lkey, @@ -794,14 +781,10 @@ cluster_gcs_block_shmem_init(void) pg_atomic_init_u64(&ClusterGcsBlock->resource_x_reconfig_actor_active, 0); pg_atomic_init_u64(&ClusterGcsBlock->resource_x_reconfig_old_formation, 0); pg_atomic_init_u64(&ClusterGcsBlock->resource_x_reconfig_completed_epoch, 0); - pg_atomic_init_u64( - &ClusterGcsBlock->resource_x_pre_mutation_backpressure_count, 0); - pg_atomic_init_u64( - &ClusterGcsBlock->resource_x_authority_drift_count, 0); - pg_atomic_init_u64( - &ClusterGcsBlock->resource_x_post_mutation_ambiguity_count, 0); - pg_atomic_init_u64( - &ClusterGcsBlock->resource_x_internal_corruption_count, 0); + pg_atomic_init_u64(&ClusterGcsBlock->resource_x_pre_mutation_backpressure_count, 0); + pg_atomic_init_u64(&ClusterGcsBlock->resource_x_authority_drift_count, 0); + pg_atomic_init_u64(&ClusterGcsBlock->resource_x_post_mutation_ambiguity_count, 0); + pg_atomic_init_u64(&ClusterGcsBlock->resource_x_internal_corruption_count, 0); pg_atomic_init_u64(&ClusterGcsBlock->stale_reply_drop_count, 0); pg_atomic_init_u64(&ClusterGcsBlock->done_sent_count, 0); pg_atomic_init_u64(&ClusterGcsBlock->done_enqueue_drop_count, 0); @@ -1066,8 +1049,8 @@ gcs_block_reserve_slot(BufferTag tag, uint8 transition_id, int32 master_node, * per-backend lock, so capacity cannot consume an id and a wrapped sequence * can never be mapped back to one by gcs_reqid_requester(). */ static ClusterGcsBlockOutstandingSlot * -gcs_block_try_reserve_r4_slot(BufferTag tag, uint64 request_epoch, - int32 expected_master_node, uint64 *out_request_id) +gcs_block_try_reserve_r4_slot(BufferTag tag, uint64 request_epoch, int32 expected_master_node, + uint64 *out_request_id) { ClusterGcsBlockBackendBlock *blk; ClusterGcsBlockOutstandingSlot *slot = NULL; @@ -1097,8 +1080,7 @@ gcs_block_try_reserve_r4_slot(BufferTag tag, uint64 request_epoch, memset(slot->reply_block_data, 0, sizeof(slot->reply_block_data)); slot->in_use = true; slot->reply_domain = CLUSTER_GCS_BLOCK_REPLY_DOMAIN_R4_CR; - slot->request_id - = gcs_reqid_requester(cluster_node_id, (int)MyBackendId - 1, sequence); + slot->request_id = gcs_reqid_requester(cluster_node_id, (int)MyBackendId - 1, sequence); slot->transition_id = (uint8)PCM_TRANS_N_TO_S; slot->tag = tag; slot->master_node = expected_master_node; @@ -1133,10 +1115,9 @@ gcs_block_try_reserve_r4_slot(BufferTag tag, uint64 request_epoch, /* Reserve one exact Current-MX describe attempt. The slot is published in * its own reply domain before the 128-byte request can reach the DATA ring. */ static ClusterGcsBlockOutstandingSlot * -gcs_block_try_reserve_current_mx_slot( - const ClusterCurrentMxKey *key, uint64 request_epoch, - int32 expected_origin_node, uint8 expected_reply_status, - uint64 *out_request_id) +gcs_block_try_reserve_current_mx_slot(const ClusterCurrentMxKey *key, uint64 request_epoch, + int32 expected_origin_node, uint8 expected_reply_status, + uint64 *out_request_id) { ClusterGcsBlockBackendBlock *blk; ClusterGcsBlockOutstandingSlot *slot = NULL; @@ -1145,14 +1126,10 @@ gcs_block_try_reserve_current_mx_slot( if (out_request_id != NULL) *out_request_id = 0; - if (key == NULL || out_request_id == NULL - || MyBackendId <= 0 || MyBackendId > MaxBackends - || expected_origin_node < 0 - || expected_origin_node >= RESOURCE_X_PROTOCOL_NODE_LIMIT - || (expected_reply_status - != (uint8)GCS_BLOCK_REPLY_CURRENT_MX_DESCRIBE_RESULT - && expected_reply_status - != (uint8)GCS_BLOCK_REPLY_CURRENT_MX_MEMBER_PROOF_RESULT)) + if (key == NULL || out_request_id == NULL || MyBackendId <= 0 || MyBackendId > MaxBackends + || expected_origin_node < 0 || expected_origin_node >= RESOURCE_X_PROTOCOL_NODE_LIMIT + || (expected_reply_status != (uint8)GCS_BLOCK_REPLY_CURRENT_MX_DESCRIBE_RESULT + && expected_reply_status != (uint8)GCS_BLOCK_REPLY_CURRENT_MX_MEMBER_PROOF_RESULT)) return NULL; blk = gcs_block_my_block(); LWLockAcquire(&blk->lock.lock, LW_EXCLUSIVE); @@ -1162,8 +1139,7 @@ gcs_block_try_reserve_current_mx_slot( break; } sequence = blk->next_request_id; - if (slot == NULL || sequence == 0 - || sequence > GCS_REQID_REQUESTER_SEQ_MASK) { + if (slot == NULL || sequence == 0 || sequence > GCS_REQID_REQUESTER_SEQ_MASK) { LWLockRelease(&blk->lock.lock); return NULL; } @@ -1173,11 +1149,10 @@ gcs_block_try_reserve_current_mx_slot( memset(slot->reply_block_data, 0, sizeof(slot->reply_block_data)); slot->in_use = true; slot->reply_domain = CLUSTER_GCS_BLOCK_REPLY_DOMAIN_CURRENT_MX; - slot->request_id - = gcs_reqid_requester(cluster_node_id, (int)MyBackendId - 1, sequence); + slot->request_id = gcs_reqid_requester(cluster_node_id, (int)MyBackendId - 1, sequence); slot->transition_id = 0; - slot->tag = GcsBlockCurrentMxRouteTagMake( - slot->request_id, request_epoch, cluster_node_id, (int32)MyBackendId); + slot->tag = GcsBlockCurrentMxRouteTagMake(slot->request_id, request_epoch, cluster_node_id, + (int32)MyBackendId); slot->master_node = expected_origin_node; slot->reply_received = false; slot->reply_sf_dep_valid = false; @@ -1789,7 +1764,7 @@ gcs_block_compute_redeclare_checksum(const GcsBlockRedeclarePayload *p) */ static void PGRAC_PCM_X_FENCE_DOMINATED(cluster_bufmgr_pcm_x_content_write_permitted) -gcs_block_install_block(BufferDesc *buf, const char *block_data, XLogRecPtr page_lsn) + gcs_block_install_block(BufferDesc *buf, const char *block_data, XLogRecPtr page_lsn) { LWLock *content_lock; Page page; @@ -1828,15 +1803,13 @@ gcs_block_install_block(BufferDesc *buf, const char *block_data, XLogRecPtr page * its own exact acquisition-generation proof. */ static bool gcs_block_pcm_x_reserved_image_write_exact(const ClusterPcmOwnSnapshot *live, - const ClusterPcmOwnSnapshot *base, - uint64 reservation_token) + const ClusterPcmOwnSnapshot *base, + uint64 reservation_token) { return cluster_pcm_x_grant_reservation_kind(live, base, reservation_token) - == CLUSTER_PCM_X_GRANT_RESERVATION_N_NEW - && live->writer_activation_token == 0 - && live->resource_x_activation_generation == 0 - && base->writer_activation_token == 0 - && base->resource_x_activation_generation == 0; + == CLUSTER_PCM_X_GRANT_RESERVATION_N_NEW + && live->writer_activation_token == 0 && live->resource_x_activation_generation == 0 + && base->writer_activation_token == 0 && base->resource_x_activation_generation == 0; } @@ -2271,25 +2244,24 @@ cluster_gcs_block_phase_for_tag(BufferTag tag) return GCS_BLOCK_NORMAL; } -#define R4_CR_REQUIRED_HELLO_CAPS \ - (PGRAC_IC_HELLO_CAP_SEMANTIC_ACTIVATION_V1 | PGRAC_IC_HELLO_CAP_R4_SYNC_CR_V1 \ - | PGRAC_IC_HELLO_CAP_CANDIDATE2_CORRECTED_A1_V1 \ - | PGRAC_IC_HELLO_CAP_UNDO_ROOT_DESCRIPTOR_V1) +#define R4_CR_REQUIRED_HELLO_CAPS \ + (PGRAC_IC_HELLO_CAP_SEMANTIC_ACTIVATION_V1 | PGRAC_IC_HELLO_CAP_R4_SYNC_CR_V1 \ + | PGRAC_IC_HELLO_CAP_CANDIDATE2_CORRECTED_A1_V1 | PGRAC_IC_HELLO_CAP_UNDO_ROOT_DESCRIPTOR_V1) /* A local R4 actor has no peer HELLO record. Its compiled protocol family is * fixed by this binary, while the entered TARGET token binds that capability * to the locally committed OPEN/formation generation. The final route * recheck remains the operation's freshness fence. */ static bool -gcs_block_r4_local_compiled_capability_matches( - const ClusterSemanticAdmissionToken *token, uint32 required_capabilities, - uint32 optional_capabilities, bool *optional_supported_out) +gcs_block_r4_local_compiled_capability_matches(const ClusterSemanticAdmissionToken *token, + uint32 required_capabilities, + uint32 optional_capabilities, + bool *optional_supported_out) { - uint32 compiled_capabilities - = PGRAC_IC_HELLO_CAP_SEMANTIC_ACTIVATION_V1 - | PGRAC_IC_HELLO_CAP_R4_SYNC_CR_V1 - | PGRAC_IC_HELLO_CAP_CANDIDATE2_CORRECTED_A1_V1 - | PGRAC_IC_HELLO_CAP_UNDO_ROOT_DESCRIPTOR_V1; + uint32 compiled_capabilities = PGRAC_IC_HELLO_CAP_SEMANTIC_ACTIVATION_V1 + | PGRAC_IC_HELLO_CAP_R4_SYNC_CR_V1 + | PGRAC_IC_HELLO_CAP_CANDIDATE2_CORRECTED_A1_V1 + | PGRAC_IC_HELLO_CAP_UNDO_ROOT_DESCRIPTOR_V1; if (!cluster_ic_suppress_gcs_done_cap) compiled_capabilities |= PGRAC_IC_HELLO_CAP_GCS_DONE_V1; @@ -2308,19 +2280,16 @@ gcs_block_r4_local_compiled_capability_matches( * HELLO generation to substitute, so admit only an exact, nonzero checked * conversion under the same entered TARGET token. */ static bool -gcs_block_r4_local_capability_generation( - const ClusterSemanticAdmissionToken *token, uint32 required_capabilities, - uint32 optional_capabilities, bool *optional_supported_out, - uint32 *generation_out) +gcs_block_r4_local_capability_generation(const ClusterSemanticAdmissionToken *token, + uint32 required_capabilities, uint32 optional_capabilities, + bool *optional_supported_out, uint32 *generation_out) { if (generation_out == NULL) return false; *generation_out = 0; if (!gcs_block_r4_local_compiled_capability_matches( - token, required_capabilities, optional_capabilities, - optional_supported_out) - || token->record_generation == 0 - || token->record_generation > (uint64)PG_UINT32_MAX) + token, required_capabilities, optional_capabilities, optional_supported_out) + || token->record_generation == 0 || token->record_generation > (uint64)PG_UINT32_MAX) return false; *generation_out = (uint32)token->record_generation; return true; @@ -2336,54 +2305,52 @@ typedef struct GcsBlockR4ReplyExpectation { uint8 reply_domain; } GcsBlockR4ReplyExpectation; -static bool gcs_block_decode_r4_reply_payload( - const ClusterICEnvelope *env, const void *payload, - const GcsBlockR4ReplyExpectation *expected) pg_attribute_unused(); +static bool gcs_block_decode_r4_reply_payload(const ClusterICEnvelope *env, const void *payload, + const GcsBlockR4ReplyExpectation *expected) + pg_attribute_unused(); /* Return true when D3 must publish an immediate refusal and false only for * the proved admitted FORWARD96 success. Invalid result/reason pairs close * as status 26; they never inherit retry polarity from one member alone. */ static bool -gcs_block_r4_refusal_status_for_build(ClusterCrBuildResult result, - ClusterCrBuildReason reason, bool admitted_forward, - GcsBlockReplyStatus *status_out) +gcs_block_r4_refusal_status_for_build(ClusterCrBuildResult result, ClusterCrBuildReason reason, + bool admitted_forward, GcsBlockReplyStatus *status_out) { if (status_out == NULL) return true; *status_out = GCS_BLOCK_REPLY_R4_DENIED; - if (result == CLUSTER_CR_BUILD_FULL && reason == CLUSTER_CR_BUILD_NONE - && admitted_forward) + if (result == CLUSTER_CR_BUILD_FULL && reason == CLUSTER_CR_BUILD_NONE && admitted_forward) return false; if (result == CLUSTER_CR_BUILD_RETRYABLE) { switch (reason) { - case CLUSTER_CR_BUILD_TARGET_DISABLED: - case CLUSTER_CR_BUILD_RF_DEFERRED: - case CLUSTER_CR_BUILD_WRONG_MASTER: - case CLUSTER_CR_BUILD_NO_HOLDER: - case CLUSTER_CR_BUILD_HOLDER_AMBIGUOUS: - case CLUSTER_CR_BUILD_HOLDER_MOVED: - case CLUSTER_CR_BUILD_RECOVERING: - case CLUSTER_CR_BUILD_GENERATION_MISMATCH: - case CLUSTER_CR_BUILD_CAPACITY: - case CLUSTER_CR_BUILD_EPOCH_MISMATCH: - *status_out = GCS_BLOCK_REPLY_R4_RETRYABLE_HOLDER_MOVED; - return true; - default: - break; + case CLUSTER_CR_BUILD_TARGET_DISABLED: + case CLUSTER_CR_BUILD_RF_DEFERRED: + case CLUSTER_CR_BUILD_WRONG_MASTER: + case CLUSTER_CR_BUILD_NO_HOLDER: + case CLUSTER_CR_BUILD_HOLDER_AMBIGUOUS: + case CLUSTER_CR_BUILD_HOLDER_MOVED: + case CLUSTER_CR_BUILD_RECOVERING: + case CLUSTER_CR_BUILD_GENERATION_MISMATCH: + case CLUSTER_CR_BUILD_CAPACITY: + case CLUSTER_CR_BUILD_EPOCH_MISMATCH: + *status_out = GCS_BLOCK_REPLY_R4_RETRYABLE_HOLDER_MOVED; + return true; + default: + break; } } if (result == CLUSTER_CR_BUILD_FAIL_CLOSED) { switch (reason) { - case CLUSTER_CR_BUILD_BAD_LOCATOR: - case CLUSTER_CR_BUILD_BAD_UNDO: - case CLUSTER_CR_BUILD_CHAIN_LIMIT: - case CLUSTER_CR_BUILD_SNAPSHOT_TOO_OLD: - case CLUSTER_CR_BUILD_CANCELLED: - case CLUSTER_CR_BUILD_IO_ERROR: - case CLUSTER_CR_BUILD_PROTOCOL: - return true; - default: - break; + case CLUSTER_CR_BUILD_BAD_LOCATOR: + case CLUSTER_CR_BUILD_BAD_UNDO: + case CLUSTER_CR_BUILD_CHAIN_LIMIT: + case CLUSTER_CR_BUILD_SNAPSHOT_TOO_OLD: + case CLUSTER_CR_BUILD_CANCELLED: + case CLUSTER_CR_BUILD_IO_ERROR: + case CLUSTER_CR_BUILD_PROTOCOL: + return true; + default: + break; } } return true; @@ -2418,18 +2385,18 @@ gcs_block_decode_r4_reply_payload(const ClusterICEnvelope *env, const void *payl block_data = ((const char *)payload) + sizeof(*header); status = (GcsBlockReplyStatus)header->status; switch (status) { - case GCS_BLOCK_REPLY_R4_CR_FULL: - case GCS_BLOCK_REPLY_R4_TX_RESOLVE_RESULT: - case GCS_BLOCK_REPLY_R4_RETRYABLE_HOLDER_MOVED: - case GCS_BLOCK_REPLY_R4_DENIED: - payload_size = GCS_BLOCK_REPLY_PAYLOAD_TOTAL_SIZE; - break; - case GCS_BLOCK_REPLY_R4_UNDO_DATA_RESULT: - payload_size = GCS_BLOCK_REPLY_PAYLOAD_TOTAL_SIZE - + (uint32)sizeof(ClusterGcsUndoAuthTrailer); - break; - default: - return false; + case GCS_BLOCK_REPLY_R4_CR_FULL: + case GCS_BLOCK_REPLY_R4_TX_RESOLVE_RESULT: + case GCS_BLOCK_REPLY_R4_RETRYABLE_HOLDER_MOVED: + case GCS_BLOCK_REPLY_R4_DENIED: + payload_size = GCS_BLOCK_REPLY_PAYLOAD_TOTAL_SIZE; + break; + case GCS_BLOCK_REPLY_R4_UNDO_DATA_RESULT: + payload_size + = GCS_BLOCK_REPLY_PAYLOAD_TOTAL_SIZE + (uint32)sizeof(ClusterGcsUndoAuthTrailer); + break; + default: + return false; } if (env->payload_length != payload_size || header->request_id != expected->request_id || header->epoch != expected->epoch @@ -2437,8 +2404,7 @@ gcs_block_decode_r4_reply_payload(const ClusterICEnvelope *env, const void *payl || header->transition_id != expected->transition_id || expected->transition_id != (uint8)PCM_TRANS_N_TO_S || header->sender_node != expected->sender_node - || GcsBlockReplyHeaderGetForwardingMasterNode(header) - != expected->forwarding_master_node + || GcsBlockReplyHeaderGetForwardingMasterNode(header) != expected->forwarding_master_node || header->checksum != gcs_block_compute_checksum(block_data)) return false; if (status == GCS_BLOCK_REPLY_R4_UNDO_DATA_RESULT) { @@ -2455,10 +2421,8 @@ gcs_block_decode_r4_reply_payload(const ClusterICEnvelope *env, const void *payl if (status == GCS_BLOCK_REPLY_R4_CR_FULL) return expected->forwarding_master_node != GCS_BLOCK_REPLY_NO_FORWARDING_MASTER; if (status == GCS_BLOCK_REPLY_R4_TX_RESOLVE_RESULT) - return expected->forwarding_master_node - == GCS_BLOCK_REPLY_NO_FORWARDING_MASTER - && expected->requester_backend_id > 0 - && header->page_lsn != 0; + return expected->forwarding_master_node == GCS_BLOCK_REPLY_NO_FORWARDING_MASTER + && expected->requester_backend_id > 0 && header->page_lsn != 0; if (status == GCS_BLOCK_REPLY_R4_UNDO_DATA_RESULT) { if (expected->requester_backend_id != CLUSTER_GCS_BLOCK_R4_INTERNAL_ENDPOINT || expected->forwarding_master_node != GCS_BLOCK_REPLY_NO_FORWARDING_MASTER @@ -2481,9 +2445,9 @@ gcs_block_decode_r4_reply_payload(const ClusterICEnvelope *env, const void *payl static bool gcs_block_r4_publish_refusal(int worker_id, const ClusterICEnvelope *env, const ClusterR4CrRequestPayload *request, - uint32 requester_capability_generation, - ClusterCrBuildResult result, ClusterCrBuildReason reason, - bool admitted_forward, int32 current_master_node) + uint32 requester_capability_generation, ClusterCrBuildResult result, + ClusterCrBuildReason reason, bool admitted_forward, + int32 current_master_node) { GcsBlockReplyHeader header; GcsBlockReplyStatus status; @@ -2506,8 +2470,7 @@ gcs_block_r4_publish_refusal(int worker_id, const ClusterICEnvelope *env, && reason == CLUSTER_CR_BUILD_WRONG_MASTER && current_master_node >= 0 && current_master_node < CLUSTER_MAX_NODES) header.page_lsn = (uint64)(uint32)(current_master_node + 1); - GcsBlockReplyHeaderSetForwardingMasterNode( - &header, GCS_BLOCK_REPLY_NO_FORWARDING_MASTER); + GcsBlockReplyHeaderSetForwardingMasterNode(&header, GCS_BLOCK_REPLY_NO_FORWARDING_MASTER); return cluster_lms_outbound_enqueue_zero_block_reply_cap_bound( worker_id, env->source_node_id, &header, R4_CR_REQUIRED_HELLO_CAPS, requester_capability_generation); @@ -2519,17 +2482,14 @@ gcs_block_r4_publish_refusal(int worker_id, const ClusterICEnvelope *env, * is intentionally distinct from the D3 master-refusal shape above. */ static bool -gcs_block_r4_publish_holder_refusal(int worker_id, - const ClusterR4CrForwardPayload *forward, - uint32 requester_capability_generation, - ClusterCrBuildResult result, - ClusterCrBuildReason reason) +gcs_block_r4_publish_holder_refusal(int worker_id, const ClusterR4CrForwardPayload *forward, + uint32 requester_capability_generation, + ClusterCrBuildResult result, ClusterCrBuildReason reason) { GcsBlockReplyHeader header; GcsBlockReplyStatus status; - if (forward == NULL - || !gcs_block_r4_refusal_status_for_build(result, reason, true, &status)) + if (forward == NULL || !gcs_block_r4_refusal_status_for_build(result, reason, true, &status)) return true; cluster_r4_observe_refusal(CLUSTER_R4_REFUSAL_HOLDER_ADMISSION, reason, &forward->base.tag, forward->base.request_id, forward->base.epoch, @@ -2550,8 +2510,8 @@ gcs_block_r4_publish_holder_refusal(int worker_id, static bool gcs_block_r4_request_base_valid(const ClusterICEnvelope *env, - const ClusterR4CrRequestPayload *request, - uint64 current_epoch, SCN *read_scn_out) + const ClusterR4CrRequestPayload *request, uint64 current_epoch, + SCN *read_scn_out) { int i; @@ -2562,8 +2522,8 @@ gcs_block_r4_request_base_valid(const ClusterICEnvelope *env, || env->payload_length != sizeof(*request) || env->source_node_id >= RESOURCE_X_PROTOCOL_NODE_LIMIT || env->dest_node_id != (uint32)cluster_node_id - || request->base.sender_node != (int32)env->source_node_id - || request->base.request_id == 0 || request->base.requester_backend_id <= 0 + || request->base.sender_node != (int32)env->source_node_id || request->base.request_id == 0 + || request->base.requester_backend_id <= 0 || request->base.requester_backend_id > MaxBackends || request->base.transition_id != (uint8)PCM_TRANS_N_TO_S || request->base.epoch != env->epoch || request->base.epoch != current_epoch @@ -2581,8 +2541,8 @@ gcs_block_r4_request_base_valid(const ClusterICEnvelope *env, * send publication and final recheck. */ ClusterCrBuildResult cluster_gcs_block_r4_route_cr(const ClusterICEnvelope *env, - const ClusterR4CrRequestPayload *request, - ClusterCrBuildReason *reason_out) + const ClusterR4CrRequestPayload *request, + ClusterCrBuildReason *reason_out) { ClusterSemanticAdmissionToken admission; ClusterSemanticAdmissionResult admission_result; @@ -2622,35 +2582,33 @@ cluster_gcs_block_r4_route_cr(const ClusterICEnvelope *env, if (!requester_is_local && !cluster_sf_peer_capability_family_sample( - (int32)env->source_node_id, R4_CR_REQUIRED_HELLO_CAPS, - PGRAC_IC_HELLO_CAP_GCS_DONE_V1, &requester_done_capable, - &requester_capability_generation)) { + (int32)env->source_node_id, R4_CR_REQUIRED_HELLO_CAPS, PGRAC_IC_HELLO_CAP_GCS_DONE_V1, + &requester_done_capable, &requester_capability_generation)) { *reason_out = CLUSTER_CR_BUILD_TARGET_DISABLED; return CLUSTER_CR_BUILD_RETRYABLE; } - admission_result = cluster_semantic_activation_enter( - CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, CLUSTER_SEMANTIC_TARGET_SIDE, &admission); + admission_result = cluster_semantic_activation_enter(CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, + CLUSTER_SEMANTIC_TARGET_SIDE, &admission); if (admission_result != CLUSTER_SEMANTIC_ADMISSION_OK) { reason = admission_result == CLUSTER_SEMANTIC_ADMISSION_TARGET_DISABLED ? CLUSTER_CR_BUILD_TARGET_DISABLED : CLUSTER_CR_BUILD_RF_DEFERRED; result = cluster_cr_build_result_for_reason(reason); - (void)gcs_block_r4_publish_refusal( - dedup_worker_id, env, request, requester_capability_generation, result, reason, - false, -1); + (void)gcs_block_r4_publish_refusal(dedup_worker_id, env, request, + requester_capability_generation, result, reason, false, + -1); *reason_out = reason; return result; } PG_TRY(); { - if (requester_is_local - ? !gcs_block_r4_local_compiled_capability_matches( - &admission, R4_CR_REQUIRED_HELLO_CAPS, - PGRAC_IC_HELLO_CAP_GCS_DONE_V1, &requester_done_capable) - : !cluster_semantic_activation_peer_open_matches( - &admission, (int32)env->source_node_id, R4_CR_REQUIRED_HELLO_CAPS, - requester_capability_generation)) { + if (requester_is_local ? !gcs_block_r4_local_compiled_capability_matches( + &admission, R4_CR_REQUIRED_HELLO_CAPS, + PGRAC_IC_HELLO_CAP_GCS_DONE_V1, &requester_done_capable) + : !cluster_semantic_activation_peer_open_matches( + &admission, (int32)env->source_node_id, + R4_CR_REQUIRED_HELLO_CAPS, requester_capability_generation)) { reason = CLUSTER_CR_BUILD_RF_DEFERRED; goto done; } @@ -2671,27 +2629,24 @@ cluster_gcs_block_r4_route_cr(const ClusterICEnvelope *env, goto done; } if (!cluster_pcm_lock_r4_route_snapshot(request->base.tag, &authority, - &master_authority_generation, - &expected_page_scn)) { + &master_authority_generation, &expected_page_scn)) { reason = CLUSTER_CR_BUILD_NO_HOLDER; goto done; } - reason = cluster_r4_route_policy_classify(&authority, current_epoch, - master_authority_generation, - ¤t_holder_node); + reason = cluster_r4_route_policy_classify( + &authority, current_epoch, master_authority_generation, ¤t_holder_node); if (reason != CLUSTER_CR_BUILD_NONE) goto done; holder_is_local = current_holder_node == cluster_node_id; - if (holder_is_local - ? !gcs_block_r4_local_compiled_capability_matches( - &admission, R4_CR_REQUIRED_HELLO_CAPS, 0, &holder_optional) - : (!cluster_sf_peer_capability_family_sample( - current_holder_node, R4_CR_REQUIRED_HELLO_CAPS, 0, &holder_optional, - &holder_capability_generation) - || !cluster_semantic_activation_peer_open_matches( - &admission, current_holder_node, R4_CR_REQUIRED_HELLO_CAPS, - holder_capability_generation))) { + if (holder_is_local ? !gcs_block_r4_local_compiled_capability_matches( + &admission, R4_CR_REQUIRED_HELLO_CAPS, 0, &holder_optional) + : (!cluster_sf_peer_capability_family_sample( + current_holder_node, R4_CR_REQUIRED_HELLO_CAPS, 0, + &holder_optional, &holder_capability_generation) + || !cluster_semantic_activation_peer_open_matches( + &admission, current_holder_node, R4_CR_REQUIRED_HELLO_CAPS, + holder_capability_generation))) { reason = CLUSTER_CR_BUILD_RF_DEFERRED; goto done; } @@ -2717,8 +2672,7 @@ cluster_gcs_block_r4_route_cr(const ClusterICEnvelope *env, fresh_proof.selected_holder_node = current_holder_node; if (dedup_worker_id < 0 || dedup_worker_id >= cluster_lms_workers - || cluster_lms_shard_for_tag(&identity.tag, cluster_lms_workers) - != dedup_worker_id) { + || cluster_lms_shard_for_tag(&identity.tag, cluster_lms_workers) != dedup_worker_id) { reason = CLUSTER_CR_BUILD_PROTOCOL; goto done; } @@ -2728,15 +2682,14 @@ cluster_gcs_block_r4_route_cr(const ClusterICEnvelope *env, &stored_record); if (arm_result != GCS_BLOCK_R4_ROUTE_ARM_NEW && arm_result != GCS_BLOCK_R4_ROUTE_ARM_REPLAY) { - reason = arm_result == GCS_BLOCK_R4_ROUTE_ARM_FULL ? CLUSTER_CR_BUILD_CAPACITY - : arm_result == GCS_BLOCK_R4_ROUTE_ARM_INVALID - ? CLUSTER_CR_BUILD_PROTOCOL - : CLUSTER_CR_BUILD_HOLDER_MOVED; + reason = arm_result == GCS_BLOCK_R4_ROUTE_ARM_FULL ? CLUSTER_CR_BUILD_CAPACITY + : arm_result == GCS_BLOCK_R4_ROUTE_ARM_INVALID ? CLUSTER_CR_BUILD_PROTOCOL + : CLUSTER_CR_BUILD_HOLDER_MOVED; goto done; } if (arm_result == GCS_BLOCK_R4_ROUTE_ARM_NEW) - cluster_r4_observe(CLUSTER_R4_EVENT_CR_ROUTE_STARTED, - CLUSTER_TX_RESOLVE_NONE, CLUSTER_CR_BUILD_NONE); + cluster_r4_observe(CLUSTER_R4_EVENT_CR_ROUTE_STARTED, CLUSTER_TX_RESOLVE_NONE, + CLUSTER_CR_BUILD_NONE); memset(&forward, 0, sizeof(forward)); forward.base.request_id = identity.legacy_key.request_id; @@ -2747,18 +2700,18 @@ cluster_gcs_block_r4_route_cr(const ClusterICEnvelope *env, forward.base.master_node = stored_record.proof.real_master_node; forward.base.transition_id = (uint8)PCM_TRANS_N_TO_S; GcsBlockForwardPayloadSetExpectedPiWatermarkScn(&forward.base, - stored_record.proof.read_scn); + stored_record.proof.read_scn); GcsBlockForwardPayloadSetCrRequest(&forward.base, true); - ClusterR4ForwardExtensionSetCrProof( - &forward.extension, stored_record.proof.master_authority_generation, - stored_record.proof.master_resource_transition_count, - stored_record.proof.expected_page_scn); + ClusterR4ForwardExtensionSetCrProof(&forward.extension, + stored_record.proof.master_authority_generation, + stored_record.proof.master_resource_transition_count, + stored_record.proof.expected_page_scn); if (holder_is_local) { ClusterICSendResult local_send_result; local_send_result = gcs_block_send_envelope_or_loopback( - PGRAC_IC_MSG_GCS_BLOCK_FORWARD, - stored_record.proof.selected_holder_node, &forward, sizeof(forward)); + PGRAC_IC_MSG_GCS_BLOCK_FORWARD, stored_record.proof.selected_holder_node, &forward, + sizeof(forward)); outbound_admitted = local_send_result == CLUSTER_IC_SEND_DONE; } else outbound_admitted = cluster_lms_outbound_enqueue_cap_bound( @@ -2769,24 +2722,22 @@ cluster_gcs_block_r4_route_cr(const ClusterICEnvelope *env, dedup_worker_id, &identity, (uint8)PCM_TRANS_N_TO_S, &stored_record.proof, outbound_admitted); if (!outbound_admitted || send_result != GCS_BLOCK_R4_ROUTE_SEND_FORWARDED) { - reason = send_result == GCS_BLOCK_R4_ROUTE_SEND_INVALID - ? CLUSTER_CR_BUILD_PROTOCOL - : CLUSTER_CR_BUILD_HOLDER_MOVED; + reason = send_result == GCS_BLOCK_R4_ROUTE_SEND_INVALID ? CLUSTER_CR_BUILD_PROTOCOL + : CLUSTER_CR_BUILD_HOLDER_MOVED; goto done; } reason = CLUSTER_CR_BUILD_NONE; -done: + done: final_recheck_ok = cluster_semantic_activation_recheck(&admission); if (!final_recheck_ok && reason == CLUSTER_CR_BUILD_NONE) reason = CLUSTER_CR_BUILD_RF_DEFERRED; result = cluster_cr_build_result_for_reason(reason); - admitted_forward = final_recheck_ok && reason == CLUSTER_CR_BUILD_NONE - && outbound_admitted + admitted_forward = final_recheck_ok && reason == CLUSTER_CR_BUILD_NONE && outbound_admitted && send_result == GCS_BLOCK_R4_ROUTE_SEND_FORWARDED; - (void)gcs_block_r4_publish_refusal( - dedup_worker_id, env, request, requester_capability_generation, result, reason, - admitted_forward, real_master_node); + (void)gcs_block_r4_publish_refusal(dedup_worker_id, env, request, + requester_capability_generation, result, reason, + admitted_forward, real_master_node); } PG_FINALLY(); { @@ -2806,8 +2757,7 @@ gcs_block_try_r4_request80(const ClusterICEnvelope *env, const void *payload) if (env == NULL || payload == NULL || env->msg_type != PGRAC_IC_MSG_GCS_BLOCK_REQUEST || env->payload_length != sizeof(ClusterR4CrRequestPayload)) return false; - (void)cluster_gcs_block_r4_route_cr( - env, (const ClusterR4CrRequestPayload *)payload, &reason); + (void)cluster_gcs_block_r4_route_cr(env, (const ClusterR4CrRequestPayload *)payload, &reason); return true; } @@ -2841,43 +2791,37 @@ gcs_block_try_r4_forward96(const ClusterICEnvelope *env, const void *payload) || forward->extension.r4_kind == (uint8)CLUSTER_R4_WIRE_UNDO_DATA_FETCH)) return gcs_block_r4_tx_origin_try_accept(env, forward); memset(&admission, 0, sizeof(admission)); - admission_result = cluster_semantic_activation_enter( - CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, CLUSTER_SEMANTIC_TARGET_SIDE, &admission); + admission_result = cluster_semantic_activation_enter(CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, + CLUSTER_SEMANTIC_TARGET_SIDE, &admission); if (admission_result != CLUSTER_SEMANTIC_ADMISSION_OK) return true; PG_TRY(); { master_is_local = (int32)env->source_node_id == cluster_node_id; - requester_is_local - = forward->base.original_requester_node == cluster_node_id; - if (master_is_local - ? !gcs_block_r4_local_capability_generation( - &admission, R4_CR_REQUIRED_HELLO_CAPS, 0, - &master_optional_supported, &master_capability_generation) - : !cluster_sf_peer_capability_family_sample( - (int32)env->source_node_id, R4_CR_REQUIRED_HELLO_CAPS, 0, - &master_optional_supported, &master_capability_generation)) + requester_is_local = forward->base.original_requester_node == cluster_node_id; + if (master_is_local ? !gcs_block_r4_local_capability_generation( + &admission, R4_CR_REQUIRED_HELLO_CAPS, 0, + &master_optional_supported, &master_capability_generation) + : !cluster_sf_peer_capability_family_sample( + (int32)env->source_node_id, R4_CR_REQUIRED_HELLO_CAPS, 0, + &master_optional_supported, &master_capability_generation)) goto done; if (requester_is_local - ? !gcs_block_r4_local_capability_generation( - &admission, R4_CR_REQUIRED_HELLO_CAPS, 0, - &requester_optional_supported, - &requester_capability_generation) + ? !gcs_block_r4_local_capability_generation(&admission, R4_CR_REQUIRED_HELLO_CAPS, + 0, &requester_optional_supported, + &requester_capability_generation) : (!cluster_sf_peer_capability_family_sample( - forward->base.original_requester_node, - R4_CR_REQUIRED_HELLO_CAPS, 0, - &requester_optional_supported, - &requester_capability_generation))) + forward->base.original_requester_node, R4_CR_REQUIRED_HELLO_CAPS, 0, + &requester_optional_supported, &requester_capability_generation))) goto done; if ((!master_is_local && !cluster_semantic_activation_peer_open_matches( - &admission, (int32)env->source_node_id, - R4_CR_REQUIRED_HELLO_CAPS, master_capability_generation)) + &admission, (int32)env->source_node_id, R4_CR_REQUIRED_HELLO_CAPS, + master_capability_generation)) || (!requester_is_local && !cluster_semantic_activation_peer_open_matches( - &admission, forward->base.original_requester_node, - R4_CR_REQUIRED_HELLO_CAPS, + &admission, forward->base.original_requester_node, R4_CR_REQUIRED_HELLO_CAPS, requester_capability_generation))) goto done; if (env->source_node_id >= RESOURCE_X_PROTOCOL_NODE_LIMIT @@ -2885,8 +2829,7 @@ gcs_block_try_r4_forward96(const ClusterICEnvelope *env, const void *payload) || forward->base.original_requester_node < 0 || forward->base.original_requester_node >= RESOURCE_X_PROTOCOL_NODE_LIMIT || forward->base.requester_backend_id <= 0 - || forward->base.requester_backend_id > MaxBackends - || forward->base.request_id == 0 + || forward->base.requester_backend_id > MaxBackends || forward->base.request_id == 0 || forward->base.transition_id != (uint8)PCM_TRANS_N_TO_S || forward->base.epoch != env->epoch || forward->base.epoch != cluster_epoch_get_current() @@ -2902,18 +2845,16 @@ gcs_block_try_r4_forward96(const ClusterICEnvelope *env, const void *payload) &master_resource_transition_count, &expected_page_scn)) goto done; - submit_result = cluster_lms_cr_submit_r4( - forward, &admission, requester_capability_generation, - master_capability_generation, &submit_reason); + submit_result + = cluster_lms_cr_submit_r4(forward, &admission, requester_capability_generation, + master_capability_generation, &submit_reason); if (!cluster_semantic_activation_recheck(&admission)) goto done; worker_id = cluster_ic_tier1_my_data_channel(); (void)gcs_block_r4_publish_holder_refusal( - worker_id, forward, requester_capability_generation, submit_result, - submit_reason); + worker_id, forward, requester_capability_generation, submit_result, submit_reason); -done: - ; + done:; } PG_FINALLY(); { @@ -2955,19 +2896,19 @@ cluster_gcs_block_test_r4_tx_origin_drain(void) } bool -cluster_gcs_block_test_r4_refusal_status(ClusterCrBuildResult result, - ClusterCrBuildReason reason, bool admitted_forward, - GcsBlockReplyStatus *status_out) +cluster_gcs_block_test_r4_refusal_status(ClusterCrBuildResult result, ClusterCrBuildReason reason, + bool admitted_forward, GcsBlockReplyStatus *status_out) { return gcs_block_r4_refusal_status_for_build(result, reason, admitted_forward, status_out); } bool -cluster_gcs_block_test_decode_r4_reply( - const ClusterICEnvelope *env, const void *payload, uint64 expected_request_id, - uint64 expected_epoch, int32 expected_requester_backend_id, uint8 expected_transition_id, - int32 expected_sender_node, int32 expected_forwarding_master_node, - uint8 expected_reply_domain) +cluster_gcs_block_test_decode_r4_reply(const ClusterICEnvelope *env, const void *payload, + uint64 expected_request_id, uint64 expected_epoch, + int32 expected_requester_backend_id, + uint8 expected_transition_id, int32 expected_sender_node, + int32 expected_forwarding_master_node, + uint8 expected_reply_domain) { GcsBlockR4ReplyExpectation expected; @@ -2991,10 +2932,8 @@ static ClusterGcsBlockBackendBlock cluster_gcs_block_test_reply_backend; static void gcs_block_test_reset_r4_reply_table(uint64 next_sequence) { - memset(&cluster_gcs_block_test_reply_shared, 0, - sizeof(cluster_gcs_block_test_reply_shared)); - memset(&cluster_gcs_block_test_reply_backend, 0, - sizeof(cluster_gcs_block_test_reply_backend)); + memset(&cluster_gcs_block_test_reply_shared, 0, sizeof(cluster_gcs_block_test_reply_shared)); + memset(&cluster_gcs_block_test_reply_backend, 0, sizeof(cluster_gcs_block_test_reply_backend)); pg_atomic_init_u64(&cluster_gcs_block_test_reply_shared.stale_reply_drop_count, 0); cluster_gcs_block_test_reply_backend.next_request_id = next_sequence; ClusterGcsBlock = &cluster_gcs_block_test_reply_shared; @@ -3004,8 +2943,7 @@ gcs_block_test_reset_r4_reply_table(uint64 next_sequence) bool cluster_gcs_block_test_arm_r4_reply_slot(uint64 request_id, uint64 request_epoch, - int32 requester_backend_id, - uint8 transition_id, + int32 requester_backend_id, uint8 transition_id, int32 expected_master_node) { ClusterGcsBlockOutstandingSlot *slot; @@ -3026,11 +2964,9 @@ cluster_gcs_block_test_arm_r4_reply_slot(uint64 request_id, uint64 request_epoch } bool -cluster_gcs_block_test_arm_legacy_reply_slot(uint64 request_id, - uint64 request_epoch, - int32 requester_backend_id, - uint8 transition_id, - int32 expected_master_node) +cluster_gcs_block_test_arm_legacy_reply_slot(uint64 request_id, uint64 request_epoch, + int32 requester_backend_id, uint8 transition_id, + int32 expected_master_node) { ClusterGcsBlockOutstandingSlot *slot; @@ -3051,28 +2987,29 @@ cluster_gcs_block_test_arm_legacy_reply_slot(uint64 request_id, bool cluster_gcs_block_test_r4_requester_arm(BufferTag tag, uint64 request_epoch, - int32 expected_master_node, - uint64 next_sequence, uint64 *request_id_out) + int32 expected_master_node, uint64 next_sequence, + uint64 *request_id_out) { gcs_block_test_reset_r4_reply_table(next_sequence); - cluster_gcs_block_test_requester_slot = gcs_block_try_reserve_r4_slot( - tag, request_epoch, expected_master_node, request_id_out); + cluster_gcs_block_test_requester_slot + = gcs_block_try_reserve_r4_slot(tag, request_epoch, expected_master_node, request_id_out); return cluster_gcs_block_test_requester_slot != NULL; } bool -cluster_gcs_block_test_snapshot_r4_requester_slot( - bool *in_use_out, uint8 *reply_domain_out, uint64 *request_id_out, - uint8 *transition_id_out, BufferTag *tag_out, uint64 *request_epoch_out, - int32 *expected_master_node_out, ClusterGcsBlockDirectState *direct_state_out, - bool *direct_target_prepared_out) +cluster_gcs_block_test_snapshot_r4_requester_slot(bool *in_use_out, uint8 *reply_domain_out, + uint64 *request_id_out, uint8 *transition_id_out, + BufferTag *tag_out, uint64 *request_epoch_out, + int32 *expected_master_node_out, + ClusterGcsBlockDirectState *direct_state_out, + bool *direct_target_prepared_out) { ClusterGcsBlockOutstandingSlot *slot = cluster_gcs_block_test_requester_slot; - if (slot == NULL || in_use_out == NULL || reply_domain_out == NULL - || request_id_out == NULL || transition_id_out == NULL || tag_out == NULL - || request_epoch_out == NULL || expected_master_node_out == NULL - || direct_state_out == NULL || direct_target_prepared_out == NULL) + if (slot == NULL || in_use_out == NULL || reply_domain_out == NULL || request_id_out == NULL + || transition_id_out == NULL || tag_out == NULL || request_epoch_out == NULL + || expected_master_node_out == NULL || direct_state_out == NULL + || direct_target_prepared_out == NULL) return false; *in_use_out = slot->in_use; *reply_domain_out = slot->reply_domain; @@ -3096,8 +3033,7 @@ cluster_gcs_block_test_release_r4_requester_slot(void) } bool -cluster_gcs_block_test_r4_fetch_and_wait(BufferTag tag, SCN read_scn, - int32 real_master_node, +cluster_gcs_block_test_r4_fetch_and_wait(BufferTag tag, SCN read_scn, int32 real_master_node, char dst_page[GCS_BLOCK_DATA_SIZE]) { ClusterCrBuildReason reason; @@ -3110,15 +3046,14 @@ cluster_gcs_block_test_r4_fetch_and_wait(BufferTag tag, SCN read_scn, bool cluster_gcs_block_test_snapshot_r4_reply_slot(GcsBlockReplyHeader *header_out, - char block_out[GCS_BLOCK_DATA_SIZE], - bool *reply_received_out, - uint64 *stale_drop_count_out) + char block_out[GCS_BLOCK_DATA_SIZE], + bool *reply_received_out, + uint64 *stale_drop_count_out) { - ClusterGcsBlockOutstandingSlot *slot - = &cluster_gcs_block_test_reply_backend.slots[0]; + ClusterGcsBlockOutstandingSlot *slot = &cluster_gcs_block_test_reply_backend.slots[0]; - if (!slot->in_use || header_out == NULL || block_out == NULL - || reply_received_out == NULL || stale_drop_count_out == NULL) + if (!slot->in_use || header_out == NULL || block_out == NULL || reply_received_out == NULL + || stale_drop_count_out == NULL) return false; *header_out = slot->reply_header; memcpy(block_out, slot->reply_block_data, GCS_BLOCK_DATA_SIZE); @@ -3224,13 +3159,11 @@ cluster_gcs_send_block_request_and_wait(BufferDesc *buf, PcmLockTransition trans errdetail("PGRAC_FAMILY=RESOURCE_X PGRAC_REASON=CALLER_CAUSE_UNPROVEN " "PGRAC_NODE=%d PGRAC_ATTEMPT=0 ", cluster_node_id))); - if (cluster_authority_readiness_managed() - && !cluster_serving_ready_is_current()) { - ereport(ERROR, - (errcode(ERRCODE_CLUSTER_LMS_UNAVAILABLE), - errmsg("GCS block service is not serving-ready"), - errhint("Complete StartupXLOG and publish SERVING_READY before " - "requesting cache-fusion data."))); + if (cluster_authority_readiness_managed() && !cluster_serving_ready_is_current()) { + ereport(ERROR, (errcode(ERRCODE_CLUSTER_LMS_UNAVAILABLE), + errmsg("GCS block service is not serving-ready"), + errhint("Complete StartupXLOG and publish SERVING_READY before " + "requesting cache-fusion data."))); return false; } @@ -3733,17 +3666,14 @@ cluster_gcs_send_block_request_and_wait(BufferDesc *buf, PcmLockTransition trans if (final_status != GCS_BLOCK_REPLY_DENIED_MASTER_NOT_HOLDER) awaiting_holder_refusal_master_cleanup = false; if (final_status == GCS_BLOCK_REPLY_DENIED_MASTER_NOT_HOLDER) - ereport(LOG, - (errmsg_internal("GCS holder refusal classification diagnostic"), - errdetail("requester=%d request_id=%llu retry=%d/%d " - "master=%d forwarding_master=%d direct_denial=%u " - "transition=%u", - cluster_node_id, - (unsigned long long)request_id, - retry_attempt, max_retries, current_master, - final_forwarding_master, - direct_authoritative_denial ? 1U : 0U, - (unsigned)transition_id))); + ereport(LOG, (errmsg_internal("GCS holder refusal classification diagnostic"), + errdetail( + "requester=%d request_id=%llu retry=%d/%d " + "master=%d forwarding_master=%d direct_denial=%u " + "transition=%u", + cluster_node_id, (unsigned long long)request_id, retry_attempt, + max_retries, current_master, final_forwarding_master, + direct_authoritative_denial ? 1U : 0U, (unsigned)transition_id))); /* A direct master FULL precedes registration and any grant. Only * this ordinary read can return to bufmgr's exact-abort/yield/rearm * owner. It has no dedup entry to complete and publishes no bytes. */ @@ -3804,8 +3734,7 @@ cluster_gcs_send_block_request_and_wait(BufferDesc *buf, PcmLockTransition trans * close this request identity and let bufmgr exact-abort/rearm its * GRANT_PENDING reservation before issuing a fresh request. */ if (gcs_block_forwarded_s_refusal_requires_fresh_retry( - (GcsBlockReplyStatus)final_status, transition_id, - final_forwarding_master)) { + (GcsBlockReplyStatus)final_status, transition_id, final_forwarding_master)) { awaiting_holder_refusal_master_cleanup = false; retry_denied = true; break; @@ -3815,10 +3744,9 @@ cluster_gcs_send_block_request_and_wait(BufferDesc *buf, PcmLockTransition trans * marker. Its one direct cleanup response is part of the same exact * retry round; a second direct response remains terminal. */ if (final_status == GCS_BLOCK_REPLY_DENIED_MASTER_NOT_HOLDER - && gcs_block_holder_refusal_retry_exact( - final_forwarding_master, - &awaiting_holder_refusal_master_cleanup, - retry_attempt, max_retries)) { + && gcs_block_holder_refusal_retry_exact(final_forwarding_master, + &awaiting_holder_refusal_master_cleanup, + retry_attempt, max_retries)) { current_master = cluster_gcs_lookup_master(tag); continue; } @@ -4170,8 +4098,7 @@ cluster_gcs_send_block_request_and_wait(BufferDesc *buf, PcmLockTransition trans bool cluster_gcs_local_master_read_image_and_wait(BufferDesc *buf, const PcmAuthoritySnapshot *expected, - bool force_one_shot, - bool *out_retry_denied) + bool force_one_shot, bool *out_retry_denied) { ClusterGcsBlockOutstandingSlot *slot; uint64 request_id = 0; @@ -4215,8 +4142,7 @@ cluster_gcs_local_master_read_image_and_wait(BufferDesc *buf, const PcmAuthority *out_retry_denied = true; return false; } - image_only = force_one_shot - || cluster_gcs_block_resource_x_local_s_barrier_active(tag); + image_only = force_one_shot || cluster_gcs_block_resource_x_local_s_barrier_active(tag); cluster_gcs_block_dedup_register_backend_exit_hook(); /* expected_master == self: the holder's reply carries forwarding_master = * self, which the HC108 authorized chain validates against this slot. */ @@ -4365,8 +4291,8 @@ cluster_gcs_local_master_read_image_and_wait(BufferDesc *buf, const PcmAuthority if (slot->reply_header.status == (uint8)GCS_BLOCK_REPLY_S_GRANTED_XHOLDER_DOWNGRADE) { if (!image_only - && cluster_pcm_lock_apply_gcs_transition( - tag, PCM_TRANS_N_TO_S, cluster_node_id)) + && cluster_pcm_lock_apply_gcs_transition(tag, PCM_TRANS_N_TO_S, + cluster_node_id)) durable_s = true; else cluster_lever_a_note_remote_ack_degraded(); @@ -4383,8 +4309,7 @@ cluster_gcs_local_master_read_image_and_wait(BufferDesc *buf, const PcmAuthority * GRANT_PENDING identity: return the denial to bufmgr, whose outer * boundary exact-aborts the reservation and rearms a fresh token and * request identity under the original deadline. */ - if (got_reply - && slot->reply_header.status == (uint8)GCS_BLOCK_REPLY_DENIED_PENDING_X) { + if (got_reply && slot->reply_header.status == (uint8)GCS_BLOCK_REPLY_DENIED_PENDING_X) { *out_retry_denied = true; break; } @@ -4455,10 +4380,10 @@ cluster_gcs_local_master_read_image_and_wait(BufferDesc *buf, const PcmAuthority * closes that attempt before a bounded fresh-id retry; status 26 closes the * operation without retry or caller-page mutation. */ ClusterMxDescribeResult -cluster_gcs_current_mx_describe_fetch_and_wait( - int32 origin_node, const ClusterCurrentMxKey *key, - ClusterCurrentMxMemberDesc *members, uint16 members_cap, - uint16 *members_count, uint32 *reported_total_members) +cluster_gcs_current_mx_describe_fetch_and_wait(int32 origin_node, const ClusterCurrentMxKey *key, + ClusterCurrentMxMemberDesc *members, + uint16 members_cap, uint16 *members_count, + uint32 *reported_total_members) { ClusterGcsBlockOutstandingSlot *slot; ClusterCurrentMxDescribeForwardV2 request; @@ -4480,22 +4405,19 @@ cluster_gcs_current_mx_describe_fetch_and_wait( if (reported_total_members != NULL) *reported_total_members = 0; request_epoch = cluster_epoch_get_current(); - if (key == NULL || members == NULL || members_count == NULL - || reported_total_members == NULL || origin_node < 0 - || origin_node == cluster_node_id || origin_node >= CLUSTER_MAX_NODES - || key->origin_node_id != (uint16)origin_node - || key->cluster_epoch != request_epoch - || !MultiXactIdIsValid(key->multixact_id) - || !cluster_gcs_block_family_on_data_plane()) + if (key == NULL || members == NULL || members_count == NULL || reported_total_members == NULL + || origin_node < 0 || origin_node == cluster_node_id || origin_node >= CLUSTER_MAX_NODES + || key->origin_node_id != (uint16)origin_node || key->cluster_epoch != request_epoch + || !MultiXactIdIsValid(key->multixact_id) || !cluster_gcs_block_family_on_data_plane()) return CMX_DESC_UNKNOWN; - if (!cluster_sf_peer_multixact_current_capability_generation( - origin_node, &capability_generation)) + if (!cluster_sf_peer_multixact_current_capability_generation(origin_node, + &capability_generation)) return CMX_DESC_UNKNOWN; cluster_gcs_block_dedup_register_backend_exit_hook(); - slot = gcs_block_try_reserve_current_mx_slot( - key, request_epoch, origin_node, - (uint8)GCS_BLOCK_REPLY_CURRENT_MX_DESCRIBE_RESULT, &request_id); + slot = gcs_block_try_reserve_current_mx_slot(key, request_epoch, origin_node, + (uint8)GCS_BLOCK_REPLY_CURRENT_MX_DESCRIBE_RESULT, + &request_id); if (slot == NULL) return CMX_DESC_UNKNOWN; @@ -4515,20 +4437,17 @@ cluster_gcs_current_mx_describe_fetch_and_wait( request.trailer.version = CLUSTER_CURRENT_MX_WIRE_VERSION; request.trailer.flags = CLUSTER_CURRENT_MX_WIRE_FLAGS_NONE; - route_tag = GcsBlockCurrentMxRouteTagMake( - request_id, request_epoch, cluster_node_id, (int32)MyBackendId); + route_tag = GcsBlockCurrentMxRouteTagMake(request_id, request_epoch, cluster_node_id, + (int32)MyBackendId); worker_id = cluster_lms_shard_for_tag(&route_tag, cluster_lms_workers); if (worker_id < 0 || !cluster_lms_outbound_enqueue_cap_bound( - worker_id, PGRAC_IC_MSG_GCS_BLOCK_FORWARD, - (uint32)origin_node, &request, sizeof(request), - PGRAC_IC_HELLO_CAP_MULTIXACT_CURRENT_V1, - capability_generation)) + worker_id, PGRAC_IC_MSG_GCS_BLOCK_FORWARD, (uint32)origin_node, &request, + sizeof(request), PGRAC_IC_HELLO_CAP_MULTIXACT_CURRENT_V1, capability_generation)) goto describe_done; deadline = GetCurrentTimestamp() - + ((TimestampTz)cluster_gcs_reply_timeout_ms) - * (TimestampTz)1000; + + ((TimestampTz)cluster_gcs_reply_timeout_ms) * (TimestampTz)1000; ConditionVariablePrepareToSleep(&slot->reply_cv); for (;;) { TimestampTz now; @@ -4551,9 +4470,8 @@ cluster_gcs_current_mx_describe_fetch_and_wait( timeout_ms = (long)((deadline - now) / 1000); if (timeout_ms <= 0) timeout_ms = 1; - (void)ConditionVariableTimedSleep( - &slot->reply_cv, timeout_ms, - WAIT_EVENT_GCS_BLOCK_SHIP_WAIT); + (void)ConditionVariableTimedSleep(&slot->reply_cv, timeout_ms, + WAIT_EVENT_GCS_BLOCK_SHIP_WAIT); } ConditionVariableCancelSleep(); @@ -4564,33 +4482,27 @@ cluster_gcs_current_mx_describe_fetch_and_wait( reply_header = slot->reply_header; memcpy(&reply_page, slot->reply_block_data, sizeof(reply_page)); - if (reply_header.status - != (uint8)GCS_BLOCK_REPLY_CURRENT_MX_DESCRIBE_RESULT - || reply_header.sender_node != origin_node - || reply_header.request_id != request_id + if (reply_header.status != (uint8)GCS_BLOCK_REPLY_CURRENT_MX_DESCRIBE_RESULT + || reply_header.sender_node != origin_node || reply_header.request_id != request_id || reply_header.epoch != request_epoch || reply_header.requester_backend_id != (int32)MyBackendId || reply_header.transition_id != 0 || reply_header.page_lsn != 0 || GcsBlockReplyHeaderGetForwardingMasterNode(&reply_header) != GCS_BLOCK_REPLY_NO_FORWARDING_MASTER || reply_header.checksum - != cluster_gcs_block_compute_checksum( - (const char *)&reply_page) + != cluster_gcs_block_compute_checksum((const char *)&reply_page) || cluster_epoch_get_current() != request_epoch) { result = CMX_DESC_UNKNOWN; goto describe_done; } result = cluster_multixact_current_wire_validate_describe_reply( - &reply_page, sizeof(reply_page), origin_node, request_epoch, - request_id, key, members, members_cap, members_count, - reported_total_members); + &reply_page, sizeof(reply_page), origin_node, request_epoch, request_id, key, members, + members_cap, members_count, reported_total_members); if (result == CMX_DESC_OK) - gcs_block_stamp_touched( - origin_node, GCS_BLOCK_REPLY_NO_FORWARDING_MASTER); + gcs_block_stamp_touched(origin_node, GCS_BLOCK_REPLY_NO_FORWARDING_MASTER); -describe_done: - ; + describe_done:; } PG_CATCH(); { @@ -4605,9 +4517,8 @@ cluster_gcs_current_mx_describe_fetch_and_wait( ClusterMxResolveResult cluster_gcs_current_mx_member_proof_fetch_and_wait( - int32 origin_node, ClusterCurrentMxProofForwardV2 *request, - ClusterCurrentMemberProof *proofs, uint16 proofs_cap, - uint16 *proof_count, ClusterCurrentUpdaterProof *updater_proof, + int32 origin_node, ClusterCurrentMxProofForwardV2 *request, ClusterCurrentMemberProof *proofs, + uint16 proofs_cap, uint16 *proof_count, ClusterCurrentUpdaterProof *updater_proof, uint32 *requester_capability_generation_out, TimestampTz deadline) { ClusterGcsBlockOutstandingSlot *slot; @@ -4638,8 +4549,7 @@ cluster_gcs_current_mx_member_proof_fetch_and_wait( if (requester_capability_generation_out != NULL) *requester_capability_generation_out = 0; request_epoch = cluster_epoch_get_current(); - if (request == NULL || proofs == NULL || proof_count == NULL - || updater_proof == NULL + if (request == NULL || proofs == NULL || proof_count == NULL || updater_proof == NULL || requester_capability_generation_out == NULL || origin_node < 0 || origin_node == cluster_node_id || origin_node >= CLUSTER_MAX_NODES || !cluster_gcs_block_family_on_data_plane()) @@ -4650,17 +4560,15 @@ cluster_gcs_current_mx_member_proof_fetch_and_wait( request->prefix.original_requester_node = cluster_node_id; request->prefix.requester_backend_id = (int32)MyBackendId; if (!cluster_multixact_current_wire_validate_proof_forward( - request, sizeof(*request), cluster_node_id, origin_node, - request_epoch, &decoded) - || !cluster_sf_peer_multixact_current_capability_generation( - origin_node, &capability_generation)) + request, sizeof(*request), cluster_node_id, origin_node, request_epoch, &decoded) + || !cluster_sf_peer_multixact_current_capability_generation(origin_node, + &capability_generation)) return CMX_RESOLVE_UNKNOWN; cluster_gcs_block_dedup_register_backend_exit_hook(); slot = gcs_block_try_reserve_current_mx_slot( &request->prefix.mxkey, request_epoch, origin_node, - (uint8)GCS_BLOCK_REPLY_CURRENT_MX_MEMBER_PROOF_RESULT, - &request_id); + (uint8)GCS_BLOCK_REPLY_CURRENT_MX_MEMBER_PROOF_RESULT, &request_id); if (slot == NULL) return CMX_RESOLVE_UNKNOWN; @@ -4670,8 +4578,7 @@ cluster_gcs_current_mx_member_proof_fetch_and_wait( request->prefix.request_id = request_id; if (!cluster_multixact_current_wire_validate_proof_forward( - request, sizeof(*request), cluster_node_id, origin_node, - request_epoch, &decoded)) + request, sizeof(*request), cluster_node_id, origin_node, request_epoch, &decoded)) goto proof_done; LWLockAcquire(&blk->lock.lock, LW_EXCLUSIVE); if (!slot->in_use || slot->request_id != request_id) { @@ -4682,15 +4589,13 @@ cluster_gcs_current_mx_member_proof_fetch_and_wait( slot->expected_current_mx_proof = *request; LWLockRelease(&blk->lock.lock); - route_tag = GcsBlockCurrentMxRouteTagMake( - request_id, request_epoch, cluster_node_id, (int32)MyBackendId); + route_tag = GcsBlockCurrentMxRouteTagMake(request_id, request_epoch, cluster_node_id, + (int32)MyBackendId); worker_id = cluster_lms_shard_for_tag(&route_tag, cluster_lms_workers); if (worker_id < 0 || !cluster_lms_outbound_enqueue_cap_bound( - worker_id, PGRAC_IC_MSG_GCS_BLOCK_FORWARD, - (uint32)origin_node, request, sizeof(*request), - PGRAC_IC_HELLO_CAP_MULTIXACT_CURRENT_V1, - capability_generation)) + worker_id, PGRAC_IC_MSG_GCS_BLOCK_FORWARD, (uint32)origin_node, request, + sizeof(*request), PGRAC_IC_HELLO_CAP_MULTIXACT_CURRENT_V1, capability_generation)) goto proof_done; ConditionVariablePrepareToSleep(&slot->reply_cv); @@ -4712,12 +4617,10 @@ cluster_gcs_current_mx_member_proof_fetch_and_wait( now = GetCurrentTimestamp(); if (deadline != 0 && now >= deadline) break; - timeout_ms = deadline == 0 - ? 1000L : (long)((deadline - now) / 1000); + timeout_ms = deadline == 0 ? 1000L : (long)((deadline - now) / 1000); timeout_ms = Max(timeout_ms, 1L); - (void)ConditionVariableTimedSleep( - &slot->reply_cv, timeout_ms, - WAIT_EVENT_GCS_BLOCK_SHIP_WAIT); + (void)ConditionVariableTimedSleep(&slot->reply_cv, timeout_ms, + WAIT_EVENT_GCS_BLOCK_SHIP_WAIT); } ConditionVariableCancelSleep(); if (!got_reply) { @@ -4727,31 +4630,26 @@ cluster_gcs_current_mx_member_proof_fetch_and_wait( reply_header = slot->reply_header; memcpy(&reply_page, slot->reply_block_data, sizeof(reply_page)); - if (reply_header.status - != (uint8)GCS_BLOCK_REPLY_CURRENT_MX_MEMBER_PROOF_RESULT - || reply_header.sender_node != origin_node - || reply_header.request_id != request_id + if (reply_header.status != (uint8)GCS_BLOCK_REPLY_CURRENT_MX_MEMBER_PROOF_RESULT + || reply_header.sender_node != origin_node || reply_header.request_id != request_id || reply_header.epoch != request_epoch || reply_header.requester_backend_id != (int32)MyBackendId || reply_header.transition_id != 0 || reply_header.page_lsn != 0 || GcsBlockReplyHeaderGetForwardingMasterNode(&reply_header) != GCS_BLOCK_REPLY_NO_FORWARDING_MASTER || reply_header.checksum - != cluster_gcs_block_compute_checksum( - (const char *)&reply_page) + != cluster_gcs_block_compute_checksum((const char *)&reply_page) || cluster_epoch_get_current() != request_epoch) goto proof_done; if (!cluster_multixact_current_wire_validate_proof_reply_frame( - &reply_page, sizeof(reply_page), origin_node, request_epoch, - request, &result, proofs, proofs_cap, proof_count, - updater_proof, requester_capability_generation_out)) + &reply_page, sizeof(reply_page), origin_node, request_epoch, request, &result, + proofs, proofs_cap, proof_count, updater_proof, + requester_capability_generation_out)) result = CMX_RESOLVE_UNKNOWN; if (result == CMX_RESOLVE_OK) - gcs_block_stamp_touched( - origin_node, GCS_BLOCK_REPLY_NO_FORWARDING_MASTER); + gcs_block_stamp_touched(origin_node, GCS_BLOCK_REPLY_NO_FORWARDING_MASTER); -proof_done: - ; + proof_done:; } PG_CATCH(); { @@ -4861,8 +4759,7 @@ gcs_block_r4_cr_fetch_and_wait_raw(BufferTag tag, SCN read_scn, int32 real_maste if (reason_out != NULL) *reason_out = CLUSTER_CR_BUILD_PROTOCOL; - if (dst_page == NULL || reason_out == NULL || !SCN_VALID(read_scn) - || real_master_node < 0 + if (dst_page == NULL || reason_out == NULL || !SCN_VALID(read_scn) || real_master_node < 0 || real_master_node >= RESOURCE_X_PROTOCOL_NODE_LIMIT) return CLUSTER_CR_BUILD_FAIL_CLOSED; INSTR_TIME_SET_CURRENT(diagnostic.started); @@ -4889,8 +4786,7 @@ gcs_block_r4_cr_fetch_and_wait_raw(BufferTag tag, SCN read_scn, int32 real_maste } if (diagnostic.attempts < UINT64_MAX) diagnostic.attempts++; - slot = gcs_block_try_reserve_r4_slot(tag, request_epoch, real_master_node, - &request_id); + slot = gcs_block_try_reserve_r4_slot(tag, request_epoch, real_master_node, &request_id); if (slot == NULL) { *reason_out = CLUSTER_CR_BUILD_CAPACITY; return CLUSTER_CR_BUILD_RETRYABLE; @@ -4909,10 +4805,9 @@ gcs_block_r4_cr_fetch_and_wait_raw(BufferTag tag, SCN read_scn, int32 real_maste request.base.transition_id = (uint8)PCM_TRANS_N_TO_S; GcsBlockRequestPayloadSetLifetimeHintMs( &request.base, - cluster_gcs_block_dedup_lifetime_ms( - cluster_gcs_block_retransmit_initial_backoff_ms, - cluster_gcs_block_retransmit_max_retries, - cluster_gcs_reply_timeout_ms)); + cluster_gcs_block_dedup_lifetime_ms(cluster_gcs_block_retransmit_initial_backoff_ms, + cluster_gcs_block_retransmit_max_retries, + cluster_gcs_reply_timeout_ms)); if (!ClusterR4RequestExtensionSetCr(&request.extension, read_scn)) { invalidated = true; *reason_out = CLUSTER_CR_BUILD_PROTOCOL; @@ -5036,8 +4931,7 @@ gcs_block_r4_cr_fetch_and_wait_raw(BufferTag tag, SCN read_scn, int32 real_maste *reason_out = CLUSTER_CR_BUILD_NONE; return CLUSTER_CR_BUILD_FULL; } - if (got_reply - && reply_status == (uint8)GCS_BLOCK_REPLY_R4_RETRYABLE_HOLDER_MOVED) { + if (got_reply && reply_status == (uint8)GCS_BLOCK_REPLY_R4_RETRYABLE_HOLDER_MOVED) { gcs_block_r4_wait_note(&diagnostic, &tag, request_id, request_epoch, real_master_node, 0); gcs_block_r4_retry_backoff(); @@ -5053,10 +4947,10 @@ gcs_block_r4_cr_fetch_and_wait_raw(BufferTag tag, SCN read_scn, int32 real_maste } ClusterTxOutcome -cluster_gcs_block_r4_tx_resolve_fetch_and_wait( - int32 origin_node, const ClusterTxLocator *locator, - uint32 expected_physical_generation, uint64 formation_epoch, - ClusterTxResolution *out, ClusterTxResolveReason *reason_out) +cluster_gcs_block_r4_tx_resolve_fetch_and_wait(int32 origin_node, const ClusterTxLocator *locator, + uint32 expected_physical_generation, + uint64 formation_epoch, ClusterTxResolution *out, + ClusterTxResolveReason *reason_out) { ClusterGcsBlockOutstandingSlot *slot = NULL; ClusterR4CrForwardPayload forward; @@ -5083,8 +4977,7 @@ cluster_gcs_block_r4_tx_resolve_fetch_and_wait( || block_no == 0 || uba_origin_node_id(locator->uba) != (NodeId)origin_node) return CLUSTER_TX_UNKNOWN; tag = GcsBlockUndoFetchTagMake(segment_id, block_no); - slot = gcs_block_try_reserve_r4_slot( - tag, formation_epoch, origin_node, &request_id); + slot = gcs_block_try_reserve_r4_slot(tag, formation_epoch, origin_node, &request_id); if (slot == NULL) return CLUSTER_TX_UNKNOWN; @@ -5098,12 +4991,11 @@ cluster_gcs_block_r4_tx_resolve_fetch_and_wait( forward.base.requester_backend_id = (int32)MyBackendId; forward.base.master_node = origin_node; forward.base.transition_id = (uint8)PCM_TRANS_N_TO_S; - if (ClusterR4ForwardExtensionSetLocatorGeneration( - &forward.extension, CLUSTER_R4_WIRE_TX_RESOLVE, - locator, expected_physical_generation)) + if (ClusterR4ForwardExtensionSetLocatorGeneration(&forward.extension, + CLUSTER_R4_WIRE_TX_RESOLVE, locator, + expected_physical_generation)) sent = cluster_grd_outbound_enqueue_backend_msg( - PGRAC_IC_MSG_GCS_BLOCK_FORWARD, (uint32)origin_node, - &forward, sizeof(forward)); + PGRAC_IC_MSG_GCS_BLOCK_FORWARD, (uint32)origin_node, &forward, sizeof(forward)); if (sent) { ClusterGcsBlockBackendBlock *blk = gcs_block_my_block(); instr_time started; @@ -5131,14 +5023,13 @@ cluster_gcs_block_r4_tx_resolve_fetch_and_wait( INSTR_TIME_SET_CURRENT(now); elapsed = now; INSTR_TIME_SUBTRACT(elapsed, started); - remaining_ms = (double)cluster_gcs_reply_timeout_ms - - INSTR_TIME_GET_MILLISEC(elapsed); + remaining_ms + = (double)cluster_gcs_reply_timeout_ms - INSTR_TIME_GET_MILLISEC(elapsed); if (remaining_ms <= 0) break; timeout_ms = remaining_ms < 1.0 ? 1L : (long)remaining_ms; - (void)ConditionVariableTimedSleep( - &slot->reply_cv, timeout_ms, - WAIT_EVENT_GCS_BLOCK_SHIP_WAIT); + (void)ConditionVariableTimedSleep(&slot->reply_cv, timeout_ms, + WAIT_EVENT_GCS_BLOCK_SHIP_WAIT); } ConditionVariableCancelSleep(); } @@ -5147,22 +5038,18 @@ cluster_gcs_block_r4_tx_resolve_fetch_and_wait( reason = CLUSTER_TX_RESOLVE_IO_ERROR; goto tx_done; } - if (slot->reply_header.status - != (uint8)GCS_BLOCK_REPLY_R4_TX_RESOLVE_RESULT) { + if (slot->reply_header.status != (uint8)GCS_BLOCK_REPLY_R4_TX_RESOLVE_RESULT) { reason = CLUSTER_TX_RESOLVE_AUTHORITY_UNAVAILABLE; goto tx_done; } - if (!ClusterR4TxVerdictPageDecode( - (const uint8 *)slot->reply_block_data, locator, &decoded) - || decoded.authority.origin_epoch != formation_epoch - || slot->reply_header.page_lsn == 0 + if (!ClusterR4TxVerdictPageDecode((const uint8 *)slot->reply_block_data, locator, &decoded) + || decoded.authority.origin_epoch != formation_epoch || slot->reply_header.page_lsn == 0 || !SCN_VALID(decoded.authority.authority_scn) || cluster_epoch_get_current() != formation_epoch) { reason = CLUSTER_TX_RESOLVE_AUTHORITY_STALE; goto tx_done; } - decoded.authority.live_hwm_lsn - = (XLogRecPtr)slot->reply_header.page_lsn; + decoded.authority.live_hwm_lsn = (XLogRecPtr)slot->reply_header.page_lsn; cluster_scn_observe(decoded.commit_scn); cluster_scn_observe(decoded.horizon_scn); cluster_scn_observe(decoded.authority.authority_scn); @@ -5170,8 +5057,7 @@ cluster_gcs_block_r4_tx_resolve_fetch_and_wait( outcome = decoded.outcome; reason = CLUSTER_TX_RESOLVE_NONE; -tx_done: - ; + tx_done:; } PG_CATCH(); { @@ -5191,8 +5077,7 @@ cluster_gcs_block_r4_tx_resolve_fetch_and_wait( * routing; the raw transport writes only private aligned scratch. A caller * page is published only after the same token's positive final recheck. */ ClusterCrBuildResult -cluster_gcs_block_cr_fetch_and_wait(BufferTag tag, SCN read_scn, - char dst_page[BLCKSZ], +cluster_gcs_block_cr_fetch_and_wait(BufferTag tag, SCN read_scn, char dst_page[BLCKSZ], ClusterCrBuildReason *reason_out) { ClusterSemanticAdmissionToken admission; @@ -5206,9 +5091,8 @@ cluster_gcs_block_cr_fetch_and_wait(BufferTag tag, SCN read_scn, if (reason_out != NULL) *reason_out = CLUSTER_CR_BUILD_PROTOCOL; memset(&admission, 0, sizeof(admission)); - admission_result = cluster_semantic_activation_enter( - CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, - CLUSTER_SEMANTIC_TARGET_SIDE, &admission); + admission_result = cluster_semantic_activation_enter(CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, + CLUSTER_SEMANTIC_TARGET_SIDE, &admission); if (admission_result != CLUSTER_SEMANTIC_ADMISSION_OK) { reason = admission_result == CLUSTER_SEMANTIC_ADMISSION_TARGET_DISABLED ? CLUSTER_CR_BUILD_TARGET_DISABLED @@ -5224,8 +5108,7 @@ cluster_gcs_block_cr_fetch_and_wait(BufferTag tag, SCN read_scn, if (dst_page == NULL || reason_out == NULL || !SCN_VALID(read_scn)) goto done; real_master_node = cluster_gcs_lookup_master(tag); - if (real_master_node < 0 - || real_master_node >= RESOURCE_X_PROTOCOL_NODE_LIMIT) { + if (real_master_node < 0 || real_master_node >= RESOURCE_X_PROTOCOL_NODE_LIMIT) { reason = CLUSTER_CR_BUILD_WRONG_MASTER; result = CLUSTER_CR_BUILD_RETRYABLE; goto done; @@ -5245,8 +5128,7 @@ cluster_gcs_block_cr_fetch_and_wait(BufferTag tag, SCN read_scn, reason = CLUSTER_CR_BUILD_NONE; result = CLUSTER_CR_BUILD_FULL; -done: - ; + done:; } PG_FINALLY(); { @@ -5652,9 +5534,8 @@ gcs_freshref_pair_log_refusal(const char *phase, int32 origin, BufferTag tag, Tr static bool gcs_block_undo_verdict_wire_exchange(int32 dest_node, BufferTag tag, uint64 stamped_epoch, - TransactionId xid, SCN freshref_pair_scn, - bool authoritative, bool authority_kind, - GcsBlockReplyHeader *hdr_out, + TransactionId xid, SCN freshref_pair_scn, bool authoritative, + bool authority_kind, GcsBlockReplyHeader *hdr_out, ClusterGcsUndoVerdictPage *page_out, uint64 *tt_generation_out, uint64 *authority_scn_out) { @@ -5709,8 +5590,8 @@ gcs_block_undo_verdict_wire_exchange(int32 dest_node, BufferTag tag, uint64 stam GcsBlockForwardPayloadSetUndoVerdictRequest(&fwd, authoritative); /* Kinds 2/4/5 carry the widened xid here. Kind 10 binds xid in the * synthetic tag and carries the exact retained page SCN instead. */ - GcsBlockForwardPayloadSetExpectedPiWatermarkScn( - &fwd, freshref_pair ? freshref_pair_scn : (SCN)(uint64)xid); + GcsBlockForwardPayloadSetExpectedPiWatermarkScn(&fwd, freshref_pair ? freshref_pair_scn + : (SCN)(uint64)xid); if (!cluster_grd_outbound_enqueue_backend_msg(PGRAC_IC_MSG_GCS_BLOCK_FORWARD, (uint32)dest_node, &fwd, sizeof(fwd))) { @@ -5836,8 +5717,8 @@ gcs_block_undo_verdict_wire_exchange(int32 dest_node, BufferTag tag, uint64 stam */ bool cluster_gcs_block_undo_verdict_fetch_and_wait(int32 origin_node, uint32 segment_id, - uint32 expected_tt_slot_id, - TransactionId xid, bool authoritative, + uint32 expected_tt_slot_id, TransactionId xid, + bool authoritative, ClusterGcsUndoVerdictPage *verdict_out, ClusterLiveAuthority *auth_out) { @@ -5862,10 +5743,9 @@ cluster_gcs_block_undo_verdict_fetch_and_wait(int32 origin_node, uint32 segment_ */ tag = GcsBlockUndoFetchTagMake(segment_id, expected_tt_slot_id); - if (!gcs_block_undo_verdict_wire_exchange(origin_node, tag, cluster_epoch_get_current(), xid, - InvalidScn, authoritative, - false /* owner-served kind */, &hdr, - &page, &tt_generation, &authority_scn)) + if (!gcs_block_undo_verdict_wire_exchange( + origin_node, tag, cluster_epoch_get_current(), xid, InvalidScn, authoritative, + false /* owner-served kind */, &hdr, &page, &tt_generation, &authority_scn)) return false; if (!cluster_vis_undo_verdict_page_usable(&page, xid)) { @@ -5888,10 +5768,11 @@ cluster_gcs_block_undo_verdict_fetch_and_wait(int32 origin_node, uint32 segment_ } static bool -gcs_block_undo_freshref_c1b_pair_exchange_current( - int32 origin_node, uint32 segment_id, uint32 expected_tt_slot_id, - TransactionId xid, uint64 stamped_epoch, SCN proposed_scn, - ClusterGcsUndoVerdictPage *verdict_out, ClusterLiveAuthority *auth_out) +gcs_block_undo_freshref_c1b_pair_exchange_current(int32 origin_node, uint32 segment_id, + uint32 expected_tt_slot_id, TransactionId xid, + uint64 stamped_epoch, SCN proposed_scn, + ClusterGcsUndoVerdictPage *verdict_out, + ClusterLiveAuthority *auth_out) { GcsBlockReplyHeader hdr; ClusterGcsUndoVerdictPage page; @@ -5899,13 +5780,12 @@ gcs_block_undo_freshref_c1b_pair_exchange_current( uint64 authority_scn = 0; BufferTag tag; - tag = GcsBlockUndoFreshRefC1bTagMake( - segment_id, xid, expected_tt_slot_id); + tag = GcsBlockUndoFreshRefC1bTagMake(segment_id, xid, expected_tt_slot_id); - if (!gcs_block_undo_verdict_wire_exchange( - origin_node, tag, stamped_epoch, xid, proposed_scn, - true /* physical fresh-ref authority */, false /* live owner */, &hdr, - &page, &tt_generation, &authority_scn)) + if (!gcs_block_undo_verdict_wire_exchange(origin_node, tag, stamped_epoch, xid, proposed_scn, + true /* physical fresh-ref authority */, + false /* live owner */, &hdr, &page, &tt_generation, + &authority_scn)) return false; if (hdr.sender_node != origin_node || hdr.epoch != stamped_epoch || cluster_epoch_get_current() != stamped_epoch @@ -5932,20 +5812,21 @@ gcs_block_undo_freshref_c1b_pair_exchange_current( * epoch zero, a current R4 TARGET admission is held across the whole exchange; * syntactic epoch equality alone is never authority. */ bool -cluster_gcs_block_undo_freshref_c1b_pair_fetch_and_wait( - int32 origin_node, uint32 segment_id, uint32 expected_tt_slot_id, - TransactionId xid, uint32 ref_epoch, SCN proposed_scn, - ClusterGcsUndoVerdictPage *verdict_out, ClusterLiveAuthority *auth_out) +cluster_gcs_block_undo_freshref_c1b_pair_fetch_and_wait(int32 origin_node, uint32 segment_id, + uint32 expected_tt_slot_id, + TransactionId xid, uint32 ref_epoch, + SCN proposed_scn, + ClusterGcsUndoVerdictPage *verdict_out, + ClusterLiveAuthority *auth_out) { ClusterSemanticAdmissionToken zero_epoch_admission; uint64 stamped_epoch; bool result = false; - if (verdict_out == NULL || auth_out == NULL || origin_node < 0 - || origin_node == cluster_node_id || segment_id == 0 - || segment_id > UINT16_MAX || expected_tt_slot_id < 1 - || expected_tt_slot_id > TT_SLOTS_PER_SEGMENT - || !TransactionIdIsNormal(xid) || !SCN_VALID(proposed_scn)) + if (verdict_out == NULL || auth_out == NULL || origin_node < 0 || origin_node == cluster_node_id + || segment_id == 0 || segment_id > UINT16_MAX || expected_tt_slot_id < 1 + || expected_tt_slot_id > TT_SLOTS_PER_SEGMENT || !TransactionIdIsNormal(xid) + || !SCN_VALID(proposed_scn)) return false; memset(verdict_out, 0, sizeof(*verdict_out)); memset(auth_out, 0, sizeof(*auth_out)); @@ -5961,8 +5842,8 @@ cluster_gcs_block_undo_freshref_c1b_pair_fetch_and_wait( } if (stamped_epoch != 0) return gcs_block_undo_freshref_c1b_pair_exchange_current( - origin_node, segment_id, expected_tt_slot_id, xid, stamped_epoch, - proposed_scn, verdict_out, auth_out); + origin_node, segment_id, expected_tt_slot_id, xid, stamped_epoch, proposed_scn, + verdict_out, auth_out); if (!cluster_runtime_visibility_zero_epoch_pair_admission_enter(&zero_epoch_admission)) { gcs_freshref_pair_log_refusal( "ZERO_EPOCH_ADMISSION", origin_node, @@ -5973,10 +5854,9 @@ cluster_gcs_block_undo_freshref_c1b_pair_fetch_and_wait( PG_TRY(); { result = gcs_block_undo_freshref_c1b_pair_exchange_current( - origin_node, segment_id, expected_tt_slot_id, xid, stamped_epoch, - proposed_scn, verdict_out, auth_out); - if (result - && !cluster_semantic_activation_recheck(&zero_epoch_admission)) { + origin_node, segment_id, expected_tt_slot_id, xid, stamped_epoch, proposed_scn, + verdict_out, auth_out); + if (result && !cluster_semantic_activation_recheck(&zero_epoch_admission)) { gcs_freshref_pair_log_refusal( "RETURN_ADMISSION_DRIFT", origin_node, GcsBlockUndoFreshRefC1bTagMake(segment_id, xid, expected_tt_slot_id), xid, @@ -6837,16 +6717,14 @@ gcs_block_r4_tx_origin_locator_kind_valid(const ClusterTxLocator *locator, bool || (locator->tt_wrap != TT_WRAP_INVALID && (!undo_data_fetch || locator->tt_wrap > TT_WRAP_MAX))) return false; - data_kind = locator->itl_kind == ITL_FLAG_ACTIVE - || locator->itl_kind == ITL_FLAG_COMMITTED + data_kind = locator->itl_kind == ITL_FLAG_ACTIVE || locator->itl_kind == ITL_FLAG_COMMITTED || locator->itl_kind == ITL_FLAG_ABORTED || locator->itl_kind == ITL_FLAG_NEEDS_CLEANOUT; return data_kind || ITL_FLAG_IS_LOCK_ONLY(locator->itl_kind); } static void -gcs_block_r4_tx_origin_context_clear(GcsBlockR4TxOriginContext *context, - bool cancel_guard) +gcs_block_r4_tx_origin_context_clear(GcsBlockR4TxOriginContext *context, bool cancel_guard) { if (context == NULL || !context->in_use) return; @@ -6859,24 +6737,21 @@ gcs_block_r4_tx_origin_context_clear(GcsBlockR4TxOriginContext *context, } static bool -gcs_block_r4_tx_origin_admission_current( - const GcsBlockR4TxOriginContext *context) +gcs_block_r4_tx_origin_admission_current(const GcsBlockR4TxOriginContext *context) { if (context == NULL) return false; if (context->resolve_mode == CLUSTER_TX_RESOLVE_VISIBILITY) return cluster_semantic_activation_recheck(&context->admission); if (context->resolve_mode == CLUSTER_TX_RESOLVE_TERMINAL_CENSUS) - return cluster_semantic_activation_recheck_r4_terminal_census( - &context->admission); + return cluster_semantic_activation_recheck_r4_terminal_census(&context->admission); return false; } static bool -gcs_block_r4_tx_origin_resolve_root_current( - const GcsBlockR4TxOriginContext *context, - const ClusterUndoBlock0LogicalKey *logical, - ClusterUndoBlock0ResolvedRoot *root) +gcs_block_r4_tx_origin_resolve_root_current(const GcsBlockR4TxOriginContext *context, + const ClusterUndoBlock0LogicalKey *logical, + ClusterUndoBlock0ResolvedRoot *root) { bool resolved = false; @@ -6885,19 +6760,17 @@ gcs_block_r4_tx_origin_resolve_root_current( memset(root, 0, sizeof(*root)); if (context->resolve_mode == CLUSTER_TX_RESOLVE_VISIBILITY) resolved = cluster_semantic_activation_resolve_shared_undo_root( - &context->admission, CLUSTER_UNDO_PATH_RUNTIME_SHARED, - logical->owner_instance, logical->segment_id, root); + &context->admission, CLUSTER_UNDO_PATH_RUNTIME_SHARED, logical->owner_instance, + logical->segment_id, root); else if (context->resolve_mode == CLUSTER_TX_RESOLVE_TERMINAL_CENSUS) - resolved - = cluster_semantic_activation_resolve_shared_undo_root_r4_terminal_census( - &context->admission, CLUSTER_UNDO_PATH_RUNTIME_SHARED, - logical->owner_instance, logical->segment_id, root); + resolved = cluster_semantic_activation_resolve_shared_undo_root_r4_terminal_census( + &context->admission, CLUSTER_UNDO_PATH_RUNTIME_SHARED, logical->owner_instance, + logical->segment_id, root); return resolved && gcs_block_r4_tx_origin_admission_current(context); } static int -gcs_block_r4_tx_origin_remaining_timeout_ms( - const GcsBlockR4TxOriginContext *context) +gcs_block_r4_tx_origin_remaining_timeout_ms(const GcsBlockR4TxOriginContext *context) { TimestampTz now; TimestampTz remaining_us; @@ -6916,11 +6789,9 @@ gcs_block_r4_tx_origin_remaining_timeout_ms( } static bool -gcs_block_r4_tx_origin_deadline_expired( - const GcsBlockR4TxOriginContext *context) +gcs_block_r4_tx_origin_deadline_expired(const GcsBlockR4TxOriginContext *context) { - return context != NULL && context->deadline != 0 - && GetCurrentTimestamp() >= context->deadline; + return context != NULL && context->deadline != 0 && GetCurrentTimestamp() >= context->deadline; } static void @@ -7003,10 +6874,9 @@ gcs_block_r4_tx_origin_try_accept(const ClusterICEnvelope *env, expected_tag = GcsBlockUndoFetchTagMake(segment_id, block_no); if (memcmp(&forward->base.tag, &expected_tag, sizeof(expected_tag)) != 0) return true; - if (!cluster_sf_peer_capability_family_sample( - forward->base.original_requester_node, - GCS_BLOCK_R4_TX_REQUIRED_HELLO_CAPS, 0, &optional_supported, - &capability_generation) + if (!cluster_sf_peer_capability_family_sample(forward->base.original_requester_node, + GCS_BLOCK_R4_TX_REQUIRED_HELLO_CAPS, 0, + &optional_supported, &capability_generation) || capability_generation == 0) return true; @@ -7014,18 +6884,15 @@ gcs_block_r4_tx_origin_try_accept(const ClusterICEnvelope *env, * conflicting reuse of the same authenticated request identity is * consumed without a second action or reply. */ for (i = 0; i < GCS_BLOCK_R4_TX_ORIGIN_CONTEXTS; i++) { - GcsBlockR4TxOriginContext *context - = &gcs_block_r4_tx_origin_contexts[i]; + GcsBlockR4TxOriginContext *context = &gcs_block_r4_tx_origin_contexts[i]; if (!context->in_use) { if (free_context == NULL) free_context = context; continue; } - if (context->forward.base.original_requester_node - == forward->base.original_requester_node - && context->forward.base.requester_backend_id - == forward->base.requester_backend_id + if (context->forward.base.original_requester_node == forward->base.original_requester_node + && context->forward.base.requester_backend_id == forward->base.requester_backend_id && context->forward.base.request_id == forward->base.request_id && context->forward.base.epoch == forward->base.epoch) return true; @@ -7038,9 +6905,8 @@ gcs_block_r4_tx_origin_try_accept(const ClusterICEnvelope *env, return true; logical.owner_instance = (uint8)((uint32)cluster_node_id + 1); logical.segment_id = segment_id; - admission_result = cluster_semantic_activation_enter( - CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, - CLUSTER_SEMANTIC_TARGET_SIDE, &admission); + admission_result = cluster_semantic_activation_enter(CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, + CLUSTER_SEMANTIC_TARGET_SIDE, &admission); if (admission_result == CLUSTER_SEMANTIC_ADMISSION_OK) { resolve_mode = CLUSTER_TX_RESOLVE_VISIBILITY; if ((undo_data_fetch @@ -7058,12 +6924,12 @@ gcs_block_r4_tx_origin_try_accept(const ClusterICEnvelope *env, if (undo_data_fetch || admission_result != CLUSTER_SEMANTIC_ADMISSION_TARGET_DISABLED) return true; if (cluster_semantic_activation_enter_r4_terminal_census(&admission) - != CLUSTER_SEMANTIC_ADMISSION_OK) + != CLUSTER_SEMANTIC_ADMISSION_OK) return true; resolve_mode = CLUSTER_TX_RESOLVE_TERMINAL_CENSUS; if (!cluster_semantic_activation_resolve_shared_undo_root_r4_terminal_census( - &admission, CLUSTER_UNDO_PATH_RUNTIME_SHARED, - logical.owner_instance, logical.segment_id, &root) + &admission, CLUSTER_UNDO_PATH_RUNTIME_SHARED, logical.owner_instance, + logical.segment_id, &root) || !cluster_semantic_activation_recheck_r4_terminal_census(&admission)) { cluster_semantic_activation_leave(&admission); return true; @@ -7076,10 +6942,10 @@ gcs_block_r4_tx_origin_try_accept(const ClusterICEnvelope *env, free_context->domain = GCS_BLOCK_R4_TX_ORIGIN_DOMAIN_TX_RESOLVE; free_context->phase = GCS_BLOCK_R4_TX_ORIGIN_ACQUIRE_BEGIN; free_context->resolve_mode = resolve_mode; - free_context->deadline = cluster_gcs_reply_timeout_ms > 0 - ? TimestampTzPlusMilliseconds( - GetCurrentTimestamp(), cluster_gcs_reply_timeout_ms) - : 0; + free_context->deadline + = cluster_gcs_reply_timeout_ms > 0 + ? TimestampTzPlusMilliseconds(GetCurrentTimestamp(), cluster_gcs_reply_timeout_ms) + : 0; free_context->requester_capability_generation = capability_generation; free_context->forward = *forward; free_context->locator = locator; @@ -7096,14 +6962,13 @@ gcs_block_r4_tx_origin_try_accept(const ClusterICEnvelope *env, } static bool -gcs_block_current_mx_origin_locate_physical( - TransactionId xid, ClusterTTSlotPhysicalLocator *locator, - bool *current_owner_found_out, - ClusterTTDurableLocate *durable_locate_result_out) +gcs_block_current_mx_origin_locate_physical(TransactionId xid, + ClusterTTSlotPhysicalLocator *locator, + bool *current_owner_found_out, + ClusterTTDurableLocate *durable_locate_result_out) { ClusterTTSlotCurrentOwner current_owner; - ClusterTTDurableLocate durable_locate_result - = CLUSTER_TT_DURABLE_LOCATE_SCAN_UNAVAILABLE; + ClusterTTDurableLocate durable_locate_result = CLUSTER_TT_DURABLE_LOCATE_SCAN_UNAVAILABLE; uint16 segment_id = 0; uint16 slot_offset = 0; uint16 wrap = TT_WRAP_INVALID; @@ -7111,16 +6976,13 @@ gcs_block_current_mx_origin_locate_physical( if (current_owner_found_out != NULL) *current_owner_found_out = false; if (durable_locate_result_out != NULL) - *durable_locate_result_out - = CLUSTER_TT_DURABLE_LOCATE_SCAN_UNAVAILABLE; - if (locator == NULL || current_owner_found_out == NULL - || durable_locate_result_out == NULL || cluster_node_id < 0 - || cluster_xid_origin_slot(xid) != cluster_node_id) + *durable_locate_result_out = CLUSTER_TT_DURABLE_LOCATE_SCAN_UNAVAILABLE; + if (locator == NULL || current_owner_found_out == NULL || durable_locate_result_out == NULL + || cluster_node_id < 0 || cluster_xid_origin_slot(xid) != cluster_node_id) return false; memset(locator, 0, sizeof(*locator)); memset(¤t_owner, 0, sizeof(current_owner)); - if (cluster_tt_slot_current_owner_by_xid( - cluster_node_id, xid, ¤t_owner)) { + if (cluster_tt_slot_current_owner_by_xid(cluster_node_id, xid, ¤t_owner)) { *current_owner_found_out = true; locator->segment_id = current_owner.segment_id; locator->xid = xid; @@ -7142,41 +7004,35 @@ gcs_block_current_mx_origin_locate_physical( locator->xid = xid; locator->slot_offset = slot_offset; locator->wrap = wrap; - return locator->segment_id != 0 - && locator->slot_offset < TT_SLOTS_PER_SEGMENT - && locator->wrap != TT_WRAP_INVALID; + return locator->segment_id != 0 && locator->slot_offset < TT_SLOTS_PER_SEGMENT + && locator->wrap != TT_WRAP_INVALID; } static bool -gcs_block_current_mx_requester_identity_capture( - int32 requester_node, uint32 capability_generation, - const ClusterSemanticAdmissionToken *admission, - ClusterCtrcParticipantIdentity *identity) +gcs_block_current_mx_requester_identity_capture(int32 requester_node, uint32 capability_generation, + const ClusterSemanticAdmissionToken *admission, + ClusterCtrcParticipantIdentity *identity) { uint64 observed_incarnation = 0; uint64 observed_generation = 0; uint32 required_capabilities - = PGRAC_IC_HELLO_CAP_MULTIXACT_CURRENT_V1 - | PGRAC_IC_HELLO_CAP_MULTIXACT_CTRC_V1; + = PGRAC_IC_HELLO_CAP_MULTIXACT_CURRENT_V1 | PGRAC_IC_HELLO_CAP_MULTIXACT_CTRC_V1; if (identity == NULL) return false; memset(identity, 0, sizeof(*identity)); - if (requester_node < 0 - || requester_node >= CLUSTER_CTRC_MAX_PARTICIPANTS - || capability_generation == 0 || admission == NULL - || !admission->entered || admission->record_generation == 0 + if (requester_node < 0 || requester_node >= CLUSTER_CTRC_MAX_PARTICIPANTS + || capability_generation == 0 || admission == NULL || !admission->entered + || admission->record_generation == 0 || admission->formation_epoch != cluster_epoch_get_current() || !cluster_membership_is_member(requester_node) - || !cluster_reconfig_get_observed_slot( - requester_node, &observed_incarnation, &observed_generation) + || !cluster_reconfig_get_observed_slot(requester_node, &observed_incarnation, + &observed_generation) || observed_incarnation == 0 || observed_generation == 0 - || cluster_reconfig_get_observed_epoch(requester_node) - != admission->formation_epoch - || cluster_membership_get_last_admitted_incarnation(requester_node) - != observed_incarnation - || !cluster_sf_peer_capability_generation_matches( - requester_node, required_capabilities, capability_generation)) + || cluster_reconfig_get_observed_epoch(requester_node) != admission->formation_epoch + || cluster_membership_get_last_admitted_incarnation(requester_node) != observed_incarnation + || !cluster_sf_peer_capability_generation_matches(requester_node, required_capabilities, + capability_generation)) return false; identity->node_id = (uint16)requester_node; @@ -7188,27 +7044,22 @@ gcs_block_current_mx_requester_identity_capture( } static bool -gcs_block_current_mx_requester_identity_current( - const GcsBlockR4TxOriginContext *context) +gcs_block_current_mx_requester_identity_current(const GcsBlockR4TxOriginContext *context) { ClusterCtrcParticipantIdentity current; - if (context == NULL - || context->domain != GCS_BLOCK_R4_TX_ORIGIN_DOMAIN_CURRENT_MX + if (context == NULL || context->domain != GCS_BLOCK_R4_TX_ORIGIN_DOMAIN_CURRENT_MX || !gcs_block_current_mx_requester_identity_capture( context->current_mx_request.prefix.original_requester_node, - context->requester_capability_generation, - &context->admission, ¤t)) + context->requester_capability_generation, &context->admission, ¤t)) return false; - return memcmp(¤t, &context->current_mx_requester_identity, - sizeof(current)) == 0; + return memcmp(¤t, &context->current_mx_requester_identity, sizeof(current)) == 0; } static bool -gcs_block_current_mx_ctrc_key( - const GcsBlockR4TxOriginContext *context, uint16 index, - const ClusterUndoBlock0Generation *generation, - ClusterCtrcTxnKeyV1 *key) +gcs_block_current_mx_ctrc_key(const GcsBlockR4TxOriginContext *context, uint16 index, + const ClusterUndoBlock0Generation *generation, + ClusterCtrcTxnKeyV1 *key) { const ClusterTTSlotPhysicalLocator *locator; uint64 epoch; @@ -7216,19 +7067,18 @@ gcs_block_current_mx_ctrc_key( uint64 system_identifier; if (context == NULL || generation == NULL || key == NULL - || index >= context->current_mx_locator_count - || !generation->known || generation->value == UINT32_MAX + || index >= context->current_mx_locator_count || !generation->known + || generation->value == UINT32_MAX || context->tt_root.intent != CLUSTER_UNDO_PATH_RUNTIME_SHARED - || context->tt_root.root_id == 0 - || context->tt_root.root_generation == 0 + || context->tt_root.root_id == 0 || context->tt_root.root_generation == 0 || context->admission.record_generation == 0) return false; locator = &context->current_mx_locators[index]; epoch = cluster_epoch_get_current(); boot_incarnation = cluster_qvotec_get_self_incarnation(); system_identifier = GetSystemIdentifier(); - if (epoch > UINT32_MAX || epoch != context->admission.formation_epoch - || boot_incarnation == 0 || system_identifier == 0) + if (epoch > UINT32_MAX || epoch != context->admission.formation_epoch || boot_incarnation == 0 + || system_identifier == 0) return false; memset(key, 0, sizeof(*key)); @@ -7252,8 +7102,7 @@ gcs_block_current_mx_ctrc_key( } static bool -gcs_block_current_mx_origin_try_accept( - const ClusterICEnvelope *env, const void *payload) +gcs_block_current_mx_origin_try_accept(const ClusterICEnvelope *env, const void *payload) { ClusterCurrentMxProofForwardV2 request; ClusterSemanticAdmissionToken admission; @@ -7276,17 +7125,15 @@ gcs_block_current_mx_origin_try_accept( memset(&admission, 0, sizeof(admission)); memset(&logical, 0, sizeof(logical)); memset(&root, 0, sizeof(root)); - if (env == NULL || payload == NULL - || env->dest_node_id != (uint32)cluster_node_id + if (env == NULL || payload == NULL || env->dest_node_id != (uint32)cluster_node_id || !cluster_gcs_block_family_on_data_plane() || !cluster_multixact_current_wire_validate_proof_forward( - payload, env->payload_length, (int32)env->source_node_id, - cluster_node_id, cluster_epoch_get_current(), &request)) + payload, env->payload_length, (int32)env->source_node_id, cluster_node_id, + cluster_epoch_get_current(), &request)) return false; - route_tag = GcsBlockCurrentMxRouteTagMake( - request.prefix.request_id, request.prefix.epoch, - request.prefix.original_requester_node, - request.prefix.requester_backend_id); + route_tag = GcsBlockCurrentMxRouteTagMake(request.prefix.request_id, request.prefix.epoch, + request.prefix.original_requester_node, + request.prefix.requester_backend_id); recv_worker = cluster_ic_tier1_my_data_channel(); expected_worker = cluster_lms_shard_for_tag(&route_tag, cluster_lms_workers); Assert(expected_worker == recv_worker); @@ -7297,14 +7144,12 @@ gcs_block_current_mx_origin_try_accept( || capability_generation == 0 || !cluster_sf_peer_capability_generation_matches( request.prefix.original_requester_node, - PGRAC_IC_HELLO_CAP_MULTIXACT_CURRENT_V1 - | PGRAC_IC_HELLO_CAP_MULTIXACT_CTRC_V1, + PGRAC_IC_HELLO_CAP_MULTIXACT_CURRENT_V1 | PGRAC_IC_HELLO_CAP_MULTIXACT_CTRC_V1, capability_generation)) return false; for (i = 0; i < GCS_BLOCK_R4_TX_ORIGIN_CONTEXTS; i++) { - GcsBlockR4TxOriginContext *context - = &gcs_block_r4_tx_origin_contexts[i]; + GcsBlockR4TxOriginContext *context = &gcs_block_r4_tx_origin_contexts[i]; if (!context->in_use) { if (free_context == NULL) @@ -7316,25 +7161,21 @@ gcs_block_current_mx_origin_try_accept( == request.prefix.original_requester_node && context->current_mx_request.prefix.requester_backend_id == request.prefix.requester_backend_id - && context->current_mx_request.prefix.request_id - == request.prefix.request_id - && context->current_mx_request.prefix.epoch - == request.prefix.epoch) + && context->current_mx_request.prefix.request_id == request.prefix.request_id + && context->current_mx_request.prefix.epoch == request.prefix.epoch) return true; } if (free_context == NULL) { if (!gcs_block_current_mx_origin_first_unknown_logged) { gcs_block_current_mx_origin_first_unknown_logged = true; ereport(LOG, - (errmsg_internal( - "PGRAC current-MultiXact origin first unknown: " - "requester=%d backend=%d request=" UINT64_FORMAT - " failure=%d xid=0 index=0 contexts=%d", - request.prefix.original_requester_node, - request.prefix.requester_backend_id, - request.prefix.request_id, - (int)GCS_BLOCK_CURRENT_MX_ORIGIN_FAILURE_CONTEXT_FULL, - GCS_BLOCK_R4_TX_ORIGIN_CONTEXTS))); + (errmsg_internal("PGRAC current-MultiXact origin first unknown: " + "requester=%d backend=%d request=" UINT64_FORMAT + " failure=%d xid=0 index=0 contexts=%d", + request.prefix.original_requester_node, + request.prefix.requester_backend_id, request.prefix.request_id, + (int)GCS_BLOCK_CURRENT_MX_ORIGIN_FAILURE_CONTEXT_FULL, + GCS_BLOCK_R4_TX_ORIGIN_CONTEXTS))); } return true; } @@ -7342,22 +7183,19 @@ gcs_block_current_mx_origin_try_accept( * fallback and allocate another context after the original refusal. */ if (!cluster_normal_stop_service_new_work(false)) return true; - admission_result = cluster_semantic_activation_enter( - CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, - CLUSTER_SEMANTIC_TARGET_SIDE, &admission); + admission_result = cluster_semantic_activation_enter(CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, + CLUSTER_SEMANTIC_TARGET_SIDE, &admission); if (admission_result != CLUSTER_SEMANTIC_ADMISSION_OK) { if (!gcs_block_current_mx_origin_first_unknown_logged) { gcs_block_current_mx_origin_first_unknown_logged = true; ereport(LOG, - (errmsg_internal( - "PGRAC current-MultiXact origin first unknown: " - "requester=%d backend=%d request=" UINT64_FORMAT - " failure=%d admission=%d xid=0 index=0", - request.prefix.original_requester_node, - request.prefix.requester_backend_id, - request.prefix.request_id, - (int)GCS_BLOCK_CURRENT_MX_ORIGIN_FAILURE_ADMISSION, - (int)admission_result))); + (errmsg_internal("PGRAC current-MultiXact origin first unknown: " + "requester=%d backend=%d request=" UINT64_FORMAT + " failure=%d admission=%d xid=0 index=0", + request.prefix.original_requester_node, + request.prefix.requester_backend_id, request.prefix.request_id, + (int)GCS_BLOCK_CURRENT_MX_ORIGIN_FAILURE_ADMISSION, + (int)admission_result))); } return false; } @@ -7367,42 +7205,36 @@ gcs_block_current_mx_origin_try_accept( free_context->domain = GCS_BLOCK_R4_TX_ORIGIN_DOMAIN_CURRENT_MX; free_context->phase = GCS_BLOCK_R4_TX_ORIGIN_SEND; free_context->resolve_mode = CLUSTER_TX_RESOLVE_VISIBILITY; - free_context->deadline = cluster_gcs_reply_timeout_ms > 0 - ? TimestampTzPlusMilliseconds( - GetCurrentTimestamp(), cluster_gcs_reply_timeout_ms) - : 0; + free_context->deadline + = cluster_gcs_reply_timeout_ms > 0 + ? TimestampTzPlusMilliseconds(GetCurrentTimestamp(), cluster_gcs_reply_timeout_ms) + : 0; free_context->requester_capability_generation = capability_generation; free_context->current_mx_request = request; free_context->current_mx_result = CMX_RESOLVE_UNKNOWN; - free_context->current_mx_failure - = GCS_BLOCK_CURRENT_MX_ORIGIN_FAILURE_NONE; + free_context->current_mx_failure = GCS_BLOCK_CURRENT_MX_ORIGIN_FAILURE_NONE; free_context->current_mx_updater_proof.verdict = CUCP_UNKNOWN; free_context->admission = admission; if (!gcs_block_current_mx_requester_identity_capture( - request.prefix.original_requester_node, capability_generation, - &admission, &free_context->current_mx_requester_identity)) { + request.prefix.original_requester_node, capability_generation, &admission, + &free_context->current_mx_requester_identity)) { gcs_block_r4_tx_origin_context_clear(free_context, false); return false; } free_context->outcome = CLUSTER_TX_UNKNOWN; free_context->reason = CLUSTER_TX_RESOLVE_AUTHORITY_UNAVAILABLE; - if (request.prefix.body_kind - == CLUSTER_CURRENT_MX_PROOF_BODY_UPDATER_CHALLENGE) { + if (request.prefix.body_kind == CLUSTER_CURRENT_MX_PROOF_BODY_UPDATER_CHALLENGE) { const ClusterCurrentMxUpdaterChallengeWire *challenge = &request.trailer.body.updater.challenge; if (!cluster_multixact_current_successor_provenance_well_formed( - &challenge->candidate_next_xmin_alias, - &challenge->candidate_next_xmin_locator, - challenge->updater_xid, (uint16)cluster_node_id, - request.prefix.mxkey.cluster_epoch) - || !uba_decode(challenge->candidate_next_xmin_locator.uba, - &data_segment, &data_block, &data_tt_slot, - &data_row) + &challenge->candidate_next_xmin_alias, &challenge->candidate_next_xmin_locator, + challenge->updater_xid, (uint16)cluster_node_id, request.prefix.mxkey.cluster_epoch) + || !uba_decode(challenge->candidate_next_xmin_locator.uba, &data_segment, &data_block, + &data_tt_slot, &data_row) || data_block == 0) { - free_context->current_mx_failure - = GCS_BLOCK_CURRENT_MX_ORIGIN_FAILURE_LOCATOR; + free_context->current_mx_failure = GCS_BLOCK_CURRENT_MX_ORIGIN_FAILURE_LOCATOR; free_context->current_mx_failure_xid = challenge->updater_xid; return true; } @@ -7410,13 +7242,10 @@ gcs_block_current_mx_origin_try_accept( logical.owner_instance = (uint8)((uint32)cluster_node_id + 1); logical.segment_id = data_segment; if (!cluster_semantic_activation_resolve_shared_undo_root( - &free_context->admission, - CLUSTER_UNDO_PATH_RUNTIME_SHARED, logical.owner_instance, + &free_context->admission, CLUSTER_UNDO_PATH_RUNTIME_SHARED, logical.owner_instance, logical.segment_id, &root) - || !cluster_semantic_activation_recheck( - &free_context->admission)) { - free_context->current_mx_failure - = GCS_BLOCK_CURRENT_MX_ORIGIN_FAILURE_ROOT; + || !cluster_semantic_activation_recheck(&free_context->admission)) { + free_context->current_mx_failure = GCS_BLOCK_CURRENT_MX_ORIGIN_FAILURE_ROOT; free_context->current_mx_failure_xid = challenge->updater_xid; return true; } @@ -7426,31 +7255,24 @@ gcs_block_current_mx_origin_try_accept( return true; } - owner_count = request.prefix.body_kind - == CLUSTER_CURRENT_MX_PROOF_BODY_MEMBER_ASKS - ? request.prefix.entry_count : 1; + owner_count = request.prefix.body_kind == CLUSTER_CURRENT_MX_PROOF_BODY_MEMBER_ASKS + ? request.prefix.entry_count + : 1; for (i = 0; i < owner_count; i++) { - TransactionId xid = request.prefix.body_kind - == CLUSTER_CURRENT_MX_PROOF_BODY_MEMBER_ASKS - ? request.trailer.body.asks[i].xid - : request.trailer.body.updater.challenge.updater_xid; - ClusterTTSlotPhysicalLocator *locator - = &free_context->current_mx_locators[i]; + TransactionId xid = request.prefix.body_kind == CLUSTER_CURRENT_MX_PROOF_BODY_MEMBER_ASKS + ? request.trailer.body.asks[i].xid + : request.trailer.body.updater.challenge.updater_xid; + ClusterTTSlotPhysicalLocator *locator = &free_context->current_mx_locators[i]; bool current_owner_found = false; - ClusterTTDurableLocate durable_locate_result - = CLUSTER_TT_DURABLE_LOCATE_SCAN_UNAVAILABLE; - - if (!gcs_block_current_mx_origin_locate_physical( - xid, locator, ¤t_owner_found, - &durable_locate_result)) { - free_context->current_mx_failure - = GCS_BLOCK_CURRENT_MX_ORIGIN_FAILURE_LOCATOR; + ClusterTTDurableLocate durable_locate_result = CLUSTER_TT_DURABLE_LOCATE_SCAN_UNAVAILABLE; + + if (!gcs_block_current_mx_origin_locate_physical(xid, locator, ¤t_owner_found, + &durable_locate_result)) { + free_context->current_mx_failure = GCS_BLOCK_CURRENT_MX_ORIGIN_FAILURE_LOCATOR; free_context->current_mx_failure_xid = xid; free_context->current_mx_failure_index = i; - free_context->current_mx_current_owner_found - = current_owner_found; - free_context->current_mx_durable_locate_result - = durable_locate_result; + free_context->current_mx_current_owner_found = current_owner_found; + free_context->current_mx_durable_locate_result = durable_locate_result; return true; } } @@ -7458,13 +7280,11 @@ gcs_block_current_mx_origin_try_accept( logical.owner_instance = (uint8)((uint32)cluster_node_id + 1); logical.segment_id = free_context->current_mx_locators[0].segment_id; if (!cluster_semantic_activation_resolve_shared_undo_root( - &free_context->admission, CLUSTER_UNDO_PATH_RUNTIME_SHARED, - logical.owner_instance, logical.segment_id, &root) + &free_context->admission, CLUSTER_UNDO_PATH_RUNTIME_SHARED, logical.owner_instance, + logical.segment_id, &root) || !cluster_semantic_activation_recheck(&free_context->admission)) { - free_context->current_mx_failure - = GCS_BLOCK_CURRENT_MX_ORIGIN_FAILURE_ROOT; - free_context->current_mx_failure_xid - = free_context->current_mx_locators[0].xid; + free_context->current_mx_failure = GCS_BLOCK_CURRENT_MX_ORIGIN_FAILURE_ROOT; + free_context->current_mx_failure_xid = free_context->current_mx_locators[0].xid; free_context->current_mx_failure_index = 0; return true; } @@ -7475,8 +7295,7 @@ gcs_block_current_mx_origin_try_accept( } static bool -gcs_block_r4_tx_origin_resolution_valid( - const GcsBlockR4TxOriginContext *context) +gcs_block_r4_tx_origin_resolution_valid(const GcsBlockR4TxOriginContext *context) { const ClusterTxResolution *resolution; @@ -7484,18 +7303,13 @@ gcs_block_r4_tx_origin_resolution_valid( return false; resolution = &context->resolution; if (context->outcome == CLUSTER_TX_PREPARED - || (context->outcome != CLUSTER_TX_COMMITTED - && context->outcome != CLUSTER_TX_ABORTED + || (context->outcome != CLUSTER_TX_COMMITTED && context->outcome != CLUSTER_TX_ABORTED && context->outcome != CLUSTER_TX_IN_PROGRESS) - || context->outcome != resolution->outcome - || context->reason != CLUSTER_TX_RESOLVE_NONE - || !cluster_tx_locator_reply_matches(&context->locator, - &resolution->locator_echo) + || context->outcome != resolution->outcome || context->reason != CLUSTER_TX_RESOLVE_NONE + || !cluster_tx_locator_reply_matches(&context->locator, &resolution->locator_echo) || !TransactionIdIsNormal(resolution->top_xid) - || !cluster_tx_outcome_proof_is_valid(resolution->outcome, - resolution->proof_kind) - || resolution->authority.origin_epoch - != context->admission.formation_epoch + || !cluster_tx_outcome_proof_is_valid(resolution->outcome, resolution->proof_kind) + || resolution->authority.origin_epoch != context->admission.formation_epoch || XLogRecPtrIsInvalid(resolution->authority.live_hwm_lsn) || !SCN_VALID(resolution->authority.authority_scn)) return false; @@ -7505,9 +7319,8 @@ gcs_block_r4_tx_origin_resolution_valid( } static bool -gcs_block_r4_tx_origin_failure_transition( - GcsBlockR4TxOriginPhase phase_before, - const GcsBlockR4TxOriginContext *context) +gcs_block_r4_tx_origin_failure_transition(GcsBlockR4TxOriginPhase phase_before, + const GcsBlockR4TxOriginContext *context) { if (context == NULL || context->reason == CLUSTER_TX_RESOLVE_NONE || context->outcome != CLUSTER_TX_UNKNOWN) @@ -7515,8 +7328,7 @@ gcs_block_r4_tx_origin_failure_transition( switch (phase_before) { case GCS_BLOCK_R4_TX_ORIGIN_DATA_FREEZE: case GCS_BLOCK_R4_TX_ORIGIN_DATA_RECHECK: - return context->phase - == GCS_BLOCK_R4_TX_ORIGIN_FINAL_RELEASE_BEGIN; + return context->phase == GCS_BLOCK_R4_TX_ORIGIN_FINAL_RELEASE_BEGIN; case GCS_BLOCK_R4_TX_ORIGIN_TT_SAMPLE: return context->phase == GCS_BLOCK_R4_TX_ORIGIN_TT_RELEASE_BEGIN && !context->canonical_sampled; @@ -7540,8 +7352,7 @@ gcs_block_r4_tx_origin_failure_transition( } static void -gcs_block_r4_tx_origin_log_first_denied( - const GcsBlockR4TxOriginContext *context) +gcs_block_r4_tx_origin_log_first_denied(const GcsBlockR4TxOriginContext *context) { ClusterRuntimeVisibilityCanonicalDiagnostic diagnostic; bool diagnostic_valid; @@ -7551,9 +7362,8 @@ gcs_block_r4_tx_origin_log_first_denied( gcs_block_r4_tx_origin_first_denial_logged = true; memset(&diagnostic, 0, sizeof(diagnostic)); diagnostic.resident_copy_result = -1; - diagnostic_valid - = cluster_runtime_visibility_origin_plan_canonical_diagnostic( - &context->origin_plan, &diagnostic); + diagnostic_valid = cluster_runtime_visibility_origin_plan_canonical_diagnostic( + &context->origin_plan, &diagnostic); ereport( LOG, (errmsg_internal( @@ -7604,18 +7414,14 @@ gcs_block_r4_tx_origin_prepare_reply(GcsBlockR4TxOriginContext *context) header->request_id = context->forward.base.request_id; header->epoch = context->forward.base.epoch; header->sender_node = cluster_node_id; - header->requester_backend_id - = context->forward.base.requester_backend_id; + header->requester_backend_id = context->forward.base.requester_backend_id; header->transition_id = context->forward.base.transition_id; - GcsBlockReplyHeaderSetForwardingMasterNode( - header, GCS_BLOCK_REPLY_NO_FORWARDING_MASTER); + GcsBlockReplyHeaderSetForwardingMasterNode(header, GCS_BLOCK_REPLY_NO_FORWARDING_MASTER); publish_result = gcs_block_r4_tx_origin_resolution_valid(context) - && ClusterR4TxVerdictPageEncode( - page, &context->resolution); + && ClusterR4TxVerdictPageEncode(page, &context->resolution); if (publish_result) { header->status = (uint8)GCS_BLOCK_REPLY_R4_TX_RESOLVE_RESULT; - header->page_lsn - = (uint64)context->resolution.authority.live_hwm_lsn; + header->page_lsn = (uint64)context->resolution.authority.live_hwm_lsn; } else { gcs_block_r4_tx_origin_log_first_denied(context); header->status = (uint8)GCS_BLOCK_REPLY_R4_DENIED; @@ -7682,54 +7488,41 @@ gcs_block_r4_undo_origin_prepare_reply(GcsBlockR4TxOriginContext *context) } static void -gcs_block_current_mx_origin_log_first_unknown( - const GcsBlockR4TxOriginContext *context) +gcs_block_current_mx_origin_log_first_unknown(const GcsBlockR4TxOriginContext *context) { const ClusterTTSlotPhysicalLocator *locator = NULL; if (context == NULL || gcs_block_current_mx_origin_first_unknown_logged) return; - if (context->current_mx_failure_index - < CLUSTER_CURRENT_MX_MAX_PROOF_ASKS_PER_FRAME) - locator = &context->current_mx_locators[ - context->current_mx_failure_index]; + if (context->current_mx_failure_index < CLUSTER_CURRENT_MX_MAX_PROOF_ASKS_PER_FRAME) + locator = &context->current_mx_locators[context->current_mx_failure_index]; gcs_block_current_mx_origin_first_unknown_logged = true; - ereport(LOG, - (errmsg_internal( - "PGRAC current-MultiXact origin first unknown: requester=%d " - "backend=%d request=" UINT64_FORMAT " epoch=" UINT64_FORMAT - " kind=%u entries=%u failure=%d xid=%u index=%u phase=%d " - "current_owner_found=%d durable_locate=%d " - "locator_count=%u sampled=0x%02x locator_segment=%u " - "locator_slot=%u locator_wrap=%u tt_segment=%u root=" - UINT64_FORMAT "/" UINT64_FORMAT " admission_formation=" - UINT64_FORMAT " admission_generation=" UINT64_FORMAT, - context->current_mx_request.prefix.original_requester_node, - context->current_mx_request.prefix.requester_backend_id, - context->current_mx_request.prefix.request_id, - context->current_mx_request.prefix.epoch, - context->current_mx_request.prefix.body_kind, - context->current_mx_request.prefix.entry_count, - (int)context->current_mx_failure, - context->current_mx_failure_xid, - context->current_mx_failure_index, (int)context->phase, - context->current_mx_current_owner_found, - (int)context->current_mx_durable_locate_result, - context->current_mx_locator_count, - context->current_mx_sampled_bitmap, - locator != NULL ? locator->segment_id : 0, - locator != NULL ? locator->slot_offset : 0, - locator != NULL ? locator->wrap : 0, - context->tt_logical.segment_id, - context->tt_root.root_id, - context->tt_root.root_generation, - context->admission.formation_epoch, - context->admission.record_generation))); + ereport( + LOG, + (errmsg_internal( + "PGRAC current-MultiXact origin first unknown: requester=%d " + "backend=%d request=" UINT64_FORMAT " epoch=" UINT64_FORMAT + " kind=%u entries=%u failure=%d xid=%u index=%u phase=%d " + "current_owner_found=%d durable_locate=%d " + "locator_count=%u sampled=0x%02x locator_segment=%u " + "locator_slot=%u locator_wrap=%u tt_segment=%u root=" UINT64_FORMAT "/" UINT64_FORMAT + " admission_formation=" UINT64_FORMAT " admission_generation=" UINT64_FORMAT, + context->current_mx_request.prefix.original_requester_node, + context->current_mx_request.prefix.requester_backend_id, + context->current_mx_request.prefix.request_id, context->current_mx_request.prefix.epoch, + context->current_mx_request.prefix.body_kind, + context->current_mx_request.prefix.entry_count, (int)context->current_mx_failure, + context->current_mx_failure_xid, context->current_mx_failure_index, (int)context->phase, + context->current_mx_current_owner_found, (int)context->current_mx_durable_locate_result, + context->current_mx_locator_count, context->current_mx_sampled_bitmap, + locator != NULL ? locator->segment_id : 0, locator != NULL ? locator->slot_offset : 0, + locator != NULL ? locator->wrap : 0, context->tt_logical.segment_id, + context->tt_root.root_id, context->tt_root.root_generation, + context->admission.formation_epoch, context->admission.record_generation))); } static void -gcs_block_current_mx_origin_prepare_reply( - GcsBlockR4TxOriginContext *context) +gcs_block_current_mx_origin_prepare_reply(GcsBlockR4TxOriginContext *context) { GcsBlockReplyHeader *header; ClusterCurrentMxProofReplyPage *page; @@ -7738,81 +7531,67 @@ gcs_block_current_mx_origin_prepare_reply( uint16 i; if (context->current_mx_result == CMX_RESOLVE_OK - && !gcs_block_current_mx_requester_identity_current(context)) - { + && !gcs_block_current_mx_requester_identity_current(context)) { context->current_mx_result = CMX_RESOLVE_RETRY; context->current_mx_proof_count = 0; - context->current_mx_failure - = GCS_BLOCK_CURRENT_MX_ORIGIN_FAILURE_SEND_FRESHNESS; + context->current_mx_failure = GCS_BLOCK_CURRENT_MX_ORIGIN_FAILURE_SEND_FRESHNESS; } /* The proof was sampled before releasing block-0 SCUR. Revalidate every * positive CTRC grant immediately before encoding the reply so an origin * that entered SEALING while the send was delayed cannot leak an old * ACTIVE/SELF grant. */ - for (i = 0; context->current_mx_result == CMX_RESOLVE_OK - && i < context->current_mx_proof_count; i++) - { - const ClusterCurrentMemberProof *proof - = &context->current_mx_proofs[i]; + for (i = 0; context->current_mx_result == CMX_RESOLVE_OK && i < context->current_mx_proof_count; + i++) { + const ClusterCurrentMemberProof *proof = &context->current_mx_proofs[i]; uint32 grant = ClusterCurrentMemberProofGetCtrcGrant(proof); if ((proof->state == CCM_ACTIVE || proof->state == CCM_SELF) - && !cluster_ctrc_origin_grant_publishable( - &context->current_mx_ctrc_keys[i], - &context->current_mx_requester_identity, grant)) - { + && !cluster_ctrc_origin_grant_publishable(&context->current_mx_ctrc_keys[i], + &context->current_mx_requester_identity, + grant)) { cluster_ctrc_stat_bump(CTRC_STAT_GRANT_REFUSED); context->current_mx_result = CMX_RESOLVE_RETRY; context->current_mx_proof_count = 0; - context->current_mx_failure - = GCS_BLOCK_CURRENT_MX_ORIGIN_FAILURE_SEND_FRESHNESS; + context->current_mx_failure = GCS_BLOCK_CURRENT_MX_ORIGIN_FAILURE_SEND_FRESHNESS; } } memset(context->reply_frame, 0, sizeof(context->reply_frame)); header = (GcsBlockReplyHeader *)context->reply_frame; - page = (ClusterCurrentMxProofReplyPage *)( - context->reply_frame + sizeof(*header)); + page = (ClusterCurrentMxProofReplyPage *)(context->reply_frame + sizeof(*header)); if (context->current_mx_result == CMX_RESOLVE_UNKNOWN) gcs_block_current_mx_origin_log_first_unknown(context); if (context->current_mx_result == CMX_RESOLVE_OK) requester_capability_generation = context->current_mx_requester_identity.capability_record_generation; built = cluster_cr_server_current_mx_build_proof_page( - (uint16)cluster_node_id, &context->current_mx_request, - context->current_mx_result, requester_capability_generation, - context->current_mx_proofs, - context->current_mx_proof_count, - &context->current_mx_updater_proof, page); + (uint16)cluster_node_id, &context->current_mx_request, context->current_mx_result, + requester_capability_generation, context->current_mx_proofs, + context->current_mx_proof_count, &context->current_mx_updater_proof, page); if (built != context->current_mx_result) { context->current_mx_result = CMX_RESOLVE_UNKNOWN; context->current_mx_proof_count = 0; (void)cluster_cr_server_current_mx_build_proof_page( - (uint16)cluster_node_id, &context->current_mx_request, - CMX_RESOLVE_UNKNOWN, 0, NULL, 0, NULL, page); + (uint16)cluster_node_id, &context->current_mx_request, CMX_RESOLVE_UNKNOWN, 0, NULL, 0, + NULL, page); } header->request_id = context->current_mx_request.prefix.request_id; header->epoch = context->current_mx_request.prefix.epoch; header->sender_node = cluster_node_id; - header->requester_backend_id - = context->current_mx_request.prefix.requester_backend_id; + header->requester_backend_id = context->current_mx_request.prefix.requester_backend_id; header->transition_id = 0; - header->status - = (uint8)GCS_BLOCK_REPLY_CURRENT_MX_MEMBER_PROOF_RESULT; - GcsBlockReplyHeaderSetForwardingMasterNode( - header, GCS_BLOCK_REPLY_NO_FORWARDING_MASTER); + header->status = (uint8)GCS_BLOCK_REPLY_CURRENT_MX_MEMBER_PROOF_RESULT; + GcsBlockReplyHeaderSetForwardingMasterNode(header, GCS_BLOCK_REPLY_NO_FORWARDING_MASTER); header->checksum = gcs_block_compute_checksum((const char *)page); } static bool -gcs_block_current_mx_origin_sample_held( - GcsBlockR4TxOriginContext *context) +gcs_block_current_mx_origin_sample_held(GcsBlockR4TxOriginContext *context) { const ClusterCurrentMxProofForwardV2 *request; uint16 count; uint16 i; - if (context == NULL - || context->domain != GCS_BLOCK_R4_TX_ORIGIN_DOMAIN_CURRENT_MX) + if (context == NULL || context->domain != GCS_BLOCK_R4_TX_ORIGIN_DOMAIN_CURRENT_MX) return false; request = &context->current_mx_request; count = context->current_mx_locator_count; @@ -7834,82 +7613,66 @@ gcs_block_current_mx_origin_sample_held( memset(&ctrc_key, 0, sizeof(ctrc_key)); if ((context->current_mx_sampled_bitmap & (uint8)(1U << i)) != 0 - || context->current_mx_locators[i].segment_id - != context->tt_logical.segment_id) + || context->current_mx_locators[i].segment_id != context->tt_logical.segment_id) continue; - if (request->prefix.body_kind - == CLUSTER_CURRENT_MX_PROOF_BODY_MEMBER_ASKS) + if (request->prefix.body_kind == CLUSTER_CURRENT_MX_PROOF_BODY_MEMBER_ASKS) ask = &request->trailer.body.asks[i]; else { memset(&updater_ask, 0, sizeof(updater_ask)); - updater_ask.xid - = request->trailer.body.updater.challenge.updater_xid; - updater_ask.member_ordinal - = request->trailer.body.updater.challenge.member_ordinal; - updater_ask.member_status - = request->trailer.body.updater.challenge.member_status; + updater_ask.xid = request->trailer.body.updater.challenge.updater_xid; + updater_ask.member_ordinal = request->trailer.body.updater.challenge.member_ordinal; + updater_ask.member_status = request->trailer.body.updater.challenge.member_status; ask = &updater_ask; } memset(&key, 0, sizeof(key)); memset(&result, 0, sizeof(result)); if (!cluster_runtime_visibility_physical_locator_sample_held( - &context->current_mx_locators[i], - &context->admission, &context->guard, &context->tt_root, - &key, &result, &ctrc_physical_active)) + &context->current_mx_locators[i], &context->admission, &context->guard, + &context->tt_root, &key, &result, &ctrc_physical_active)) return false; context->current_mx_sampled_keys[i] = key; if (!cluster_multixact_current_resolve_origin_member_proof( - ask->xid, ask->member_status, ask->member_ordinal, - (uint16)cluster_node_id, - request->prefix.mxkey.cluster_epoch, false, &key, &result, - NULL, NULL, &context->current_mx_proofs[i])) + ask->xid, ask->member_status, ask->member_ordinal, (uint16)cluster_node_id, + request->prefix.mxkey.cluster_epoch, false, &key, &result, NULL, NULL, + &context->current_mx_proofs[i])) return false; if (context->current_mx_proofs[i].state == CCM_ACTIVE - || context->current_mx_proofs[i].state == CCM_SELF) - { + || context->current_mx_proofs[i].state == CCM_SELF) { if (!ctrc_physical_active) return false; - if (cluster_undo_block0_current_sample_generation( - &context->guard, &context->tt_root, &generation) - != CLUSTER_UNDO_BLOCK0_OK - || !gcs_block_current_mx_ctrc_key( - context, i, &generation, &ctrc_key)) + if (cluster_undo_block0_current_sample_generation(&context->guard, &context->tt_root, + &generation) + != CLUSTER_UNDO_BLOCK0_OK + || !gcs_block_current_mx_ctrc_key(context, i, &generation, &ctrc_key)) return false; touch_result = cluster_ctrc_origin_touch_exact( &ctrc_key, &context->current_mx_requester_identity, - context->current_mx_proofs[i].state == CCM_SELF - ? CTRC_PROOF_SELF : CTRC_PROOF_ACTIVE, + context->current_mx_proofs[i].state == CCM_SELF ? CTRC_PROOF_SELF + : CTRC_PROOF_ACTIVE, &ctrc_grant); if ((touch_result != CLUSTER_CTRC_TOUCH_RECORDED && touch_result != CLUSTER_CTRC_TOUCH_DUPLICATE) || ctrc_grant == 0 - || cluster_undo_block0_current_sample_generation( - &context->guard, &context->tt_root, &final_generation) - != CLUSTER_UNDO_BLOCK0_OK - || !final_generation.known - || final_generation.value != generation.value - || !gcs_block_r4_tx_origin_resolve_root_current( - context, &context->tt_logical, &final_root) - || !cluster_undo_block0_root_matches( - &context->tt_root, &final_root) + || cluster_undo_block0_current_sample_generation(&context->guard, &context->tt_root, + &final_generation) + != CLUSTER_UNDO_BLOCK0_OK + || !final_generation.known || final_generation.value != generation.value + || !gcs_block_r4_tx_origin_resolve_root_current(context, &context->tt_logical, + &final_root) + || !cluster_undo_block0_root_matches(&context->tt_root, &final_root) || !gcs_block_r4_tx_origin_admission_current(context) - || cluster_qvotec_get_self_incarnation() - != ctrc_key.origin_boot_incarnation) + || cluster_qvotec_get_self_incarnation() != ctrc_key.origin_boot_incarnation) return false; - ClusterCurrentMemberProofSetCtrcGrant( - &context->current_mx_proofs[i], ctrc_grant); - if (!cluster_multixact_current_member_proof_bind_ctrc( - &context->current_mx_proofs[i], &ctrc_key)) + ClusterCurrentMemberProofSetCtrcGrant(&context->current_mx_proofs[i], ctrc_grant); + if (!cluster_multixact_current_member_proof_bind_ctrc(&context->current_mx_proofs[i], + &ctrc_key)) return false; context->current_mx_ctrc_keys[i] = ctrc_key; - } - else - ClusterCurrentMemberProofSetCtrcGrant( - &context->current_mx_proofs[i], 0); + } else + ClusterCurrentMemberProofSetCtrcGrant(&context->current_mx_proofs[i], 0); context->current_mx_sampled_bitmap |= (uint8)(1U << i); } - if (request->prefix.body_kind - == CLUSTER_CURRENT_MX_PROOF_BODY_UPDATER_CHALLENGE) { + if (request->prefix.body_kind == CLUSTER_CURRENT_MX_PROOF_BODY_UPDATER_CHALLENGE) { const ClusterCurrentMxUpdaterChallengeWire *challenge = &request->trailer.body.updater.challenge; @@ -7918,10 +7681,8 @@ gcs_block_current_mx_origin_sample_held( = challenge->candidate_next_xmin_alias; context->current_mx_updater_proof.candidate_next_xmin_locator = challenge->candidate_next_xmin_locator; - context->current_mx_updater_proof.updater_xid - = challenge->updater_xid; - context->current_mx_updater_proof.member_ordinal - = challenge->member_ordinal; + context->current_mx_updater_proof.updater_xid = challenge->updater_xid; + context->current_mx_updater_proof.member_ordinal = challenge->member_ordinal; /* DATA requalification, not the canonical TT sample alone, promotes * this exact echo to MATCH. */ context->current_mx_updater_proof.verdict = CUCP_UNKNOWN; @@ -7936,40 +7697,34 @@ typedef enum GcsBlockCurrentMxAdvance { } GcsBlockCurrentMxAdvance; static GcsBlockCurrentMxAdvance -gcs_block_current_mx_origin_updater_provenance_advance( - GcsBlockR4TxOriginContext *context) +gcs_block_current_mx_origin_updater_provenance_advance(GcsBlockR4TxOriginContext *context) { ClusterRuntimeVisibilityOriginStep origin_step; ClusterTxOutcome outcome; bool same_segment = false; - if (context == NULL - || context->domain != GCS_BLOCK_R4_TX_ORIGIN_DOMAIN_CURRENT_MX + if (context == NULL || context->domain != GCS_BLOCK_R4_TX_ORIGIN_DOMAIN_CURRENT_MX || context->current_mx_request.prefix.body_kind - != CLUSTER_CURRENT_MX_PROOF_BODY_UPDATER_CHALLENGE + != CLUSTER_CURRENT_MX_PROOF_BODY_UPDATER_CHALLENGE || gcs_block_r4_tx_origin_remaining_timeout_ms(context) == 0) return GCS_BLOCK_CURRENT_MX_ADVANCE_FAILED; switch (context->phase) { case GCS_BLOCK_R4_TX_ORIGIN_DATA_FREEZE: - origin_step - = cluster_runtime_visibility_origin_plan_freeze_data_held( - &context->locator, context->resolve_mode, - &context->admission, NULL, &context->guard, - &context->root, &context->origin_plan, - &context->resolution, &context->reason); + origin_step = cluster_runtime_visibility_origin_plan_freeze_data_held( + &context->locator, context->resolve_mode, &context->admission, NULL, &context->guard, + &context->root, &context->origin_plan, &context->resolution, &context->reason); if (origin_step == CLUSTER_RUNTIME_VISIBILITY_ORIGIN_FAILED || !cluster_runtime_visibility_origin_plan_canonical_physical( - &context->origin_plan, &context->current_mx_locators[0], - &same_segment)) + &context->origin_plan, &context->current_mx_locators[0], &same_segment)) return GCS_BLOCK_CURRENT_MX_ADVANCE_FAILED; context->current_mx_locator_count = 1; if (origin_step == CLUSTER_RUNTIME_VISIBILITY_ORIGIN_NEEDS_CANONICAL) { if (same_segment - || !cluster_runtime_visibility_origin_plan_canonical_logical( - &context->origin_plan, &context->tt_logical) - || !gcs_block_r4_tx_origin_resolve_root_current( - context, &context->tt_logical, &context->tt_root)) + || !cluster_runtime_visibility_origin_plan_canonical_logical(&context->origin_plan, + &context->tt_logical) + || !gcs_block_r4_tx_origin_resolve_root_current(context, &context->tt_logical, + &context->tt_root)) return GCS_BLOCK_CURRENT_MX_ADVANCE_FAILED; return GCS_BLOCK_CURRENT_MX_ADVANCE_NEXT; } @@ -7981,9 +7736,8 @@ gcs_block_current_mx_origin_updater_provenance_advance( return GCS_BLOCK_CURRENT_MX_ADVANCE_FAILED; context->canonical_sampled = true; outcome = cluster_runtime_visibility_origin_plan_recheck_data_held( - &context->origin_plan, context->resolve_mode, - &context->admission, &context->guard, &context->root, - &context->resolution, &context->reason); + &context->origin_plan, context->resolve_mode, &context->admission, &context->guard, + &context->root, &context->resolution, &context->reason); if (outcome == CLUSTER_TX_UNKNOWN) return GCS_BLOCK_CURRENT_MX_ADVANCE_FAILED; context->outcome = outcome; @@ -7994,9 +7748,8 @@ gcs_block_current_mx_origin_updater_provenance_advance( case GCS_BLOCK_R4_TX_ORIGIN_TT_SAMPLE: if (!cluster_runtime_visibility_origin_plan_sample_canonical_held( - &context->origin_plan, context->resolve_mode, - &context->admission, &context->guard, &context->tt_root, - &context->reason) + &context->origin_plan, context->resolve_mode, &context->admission, &context->guard, + &context->tt_root, &context->reason) || !gcs_block_current_mx_origin_sample_held(context)) return GCS_BLOCK_CURRENT_MX_ADVANCE_FAILED; context->canonical_sampled = true; @@ -8004,9 +7757,8 @@ gcs_block_current_mx_origin_updater_provenance_advance( case GCS_BLOCK_R4_TX_ORIGIN_DATA_RECHECK: outcome = cluster_runtime_visibility_origin_plan_recheck_data_held( - &context->origin_plan, context->resolve_mode, - &context->admission, &context->guard, &context->recheck_root, - &context->resolution, &context->reason); + &context->origin_plan, context->resolve_mode, &context->admission, &context->guard, + &context->recheck_root, &context->resolution, &context->reason); if (outcome == CLUSTER_TX_UNKNOWN) return GCS_BLOCK_CURRENT_MX_ADVANCE_FAILED; context->outcome = outcome; @@ -8021,8 +7773,7 @@ gcs_block_current_mx_origin_updater_provenance_advance( } static GcsBlockCurrentMxAdvance -gcs_block_current_mx_origin_advance( - GcsBlockR4TxOriginContext *context) +gcs_block_current_mx_origin_advance(GcsBlockR4TxOriginContext *context) { uint16 i; @@ -8031,36 +7782,29 @@ gcs_block_current_mx_origin_advance( for (i = 0; i < context->current_mx_locator_count; i++) { if ((context->current_mx_sampled_bitmap & (uint8)(1U << i)) != 0) continue; - context->tt_logical.owner_instance - = (uint8)((uint32)cluster_node_id + 1); - context->tt_logical.segment_id - = context->current_mx_locators[i].segment_id; - if (!gcs_block_r4_tx_origin_resolve_root_current( - context, &context->tt_logical, &context->tt_root)) { + context->tt_logical.owner_instance = (uint8)((uint32)cluster_node_id + 1); + context->tt_logical.segment_id = context->current_mx_locators[i].segment_id; + if (!gcs_block_r4_tx_origin_resolve_root_current(context, &context->tt_logical, + &context->tt_root)) { context->current_mx_result = CMX_RESOLVE_UNKNOWN; - context->current_mx_failure - = GCS_BLOCK_CURRENT_MX_ORIGIN_FAILURE_ROOT; - context->current_mx_failure_xid - = context->current_mx_locators[i].xid; + context->current_mx_failure = GCS_BLOCK_CURRENT_MX_ORIGIN_FAILURE_ROOT; + context->current_mx_failure_xid = context->current_mx_locators[i].xid; context->current_mx_failure_index = i; return GCS_BLOCK_CURRENT_MX_ADVANCE_FAILED; } return GCS_BLOCK_CURRENT_MX_ADVANCE_NEXT; } - if (!gcs_block_current_mx_requester_identity_current(context)) - { + if (!gcs_block_current_mx_requester_identity_current(context)) { context->current_mx_result = CMX_RESOLVE_RETRY; context->current_mx_proof_count = 0; - context->current_mx_failure - = GCS_BLOCK_CURRENT_MX_ORIGIN_FAILURE_SEND_FRESHNESS; + context->current_mx_failure = GCS_BLOCK_CURRENT_MX_ORIGIN_FAILURE_SEND_FRESHNESS; return GCS_BLOCK_CURRENT_MX_ADVANCE_FAILED; } if (context->current_mx_request.prefix.body_kind == CLUSTER_CURRENT_MX_PROOF_BODY_UPDATER_CHALLENGE && context->current_mx_updater_proof.verdict != CUCP_MATCH) { context->current_mx_result = CMX_RESOLVE_UNKNOWN; - context->current_mx_failure - = GCS_BLOCK_CURRENT_MX_ORIGIN_FAILURE_SAMPLE; + context->current_mx_failure = GCS_BLOCK_CURRENT_MX_ORIGIN_FAILURE_SAMPLE; return GCS_BLOCK_CURRENT_MX_ADVANCE_FAILED; } context->current_mx_proof_count = context->current_mx_locator_count; @@ -8068,17 +7812,15 @@ gcs_block_current_mx_origin_advance( context->reason = CLUSTER_TX_RESOLVE_NONE; if (context->current_mx_request.prefix.body_kind == CLUSTER_CURRENT_MX_PROOF_BODY_UPDATER_CHALLENGE - && context->current_mx_request.trailer.body.updater.challenge - .candidate_next_xmin_alias.undo_record_segment_id + && context->current_mx_request.trailer.body.updater.challenge.candidate_next_xmin_alias + .undo_record_segment_id != context->current_mx_locators[0].segment_id) - cluster_multixact_current_stats_bump( - CMX_STAT_UPDATER_PROVENANCE_CROSS_SEGMENT_MATCH); + cluster_multixact_current_stats_bump(CMX_STAT_UPDATER_PROVENANCE_CROSS_SEGMENT_MATCH); return GCS_BLOCK_CURRENT_MX_ADVANCE_COMPLETE; } static GcsBlockR4TxOriginPhase -gcs_block_current_mx_origin_after_release( - GcsBlockR4TxOriginContext *context) +gcs_block_current_mx_origin_after_release(GcsBlockR4TxOriginContext *context) { GcsBlockCurrentMxAdvance advance; @@ -8086,11 +7828,9 @@ gcs_block_current_mx_origin_after_release( return GCS_BLOCK_R4_TX_ORIGIN_SEND; advance = gcs_block_current_mx_origin_advance(context); if (advance == GCS_BLOCK_CURRENT_MX_ADVANCE_COMPLETE) - cluster_ctrc_test_barrier_wait( - CTRC_TEST_BARRIER_ACTIVE_PROOF_READY); - return advance == GCS_BLOCK_CURRENT_MX_ADVANCE_NEXT - ? GCS_BLOCK_R4_TX_ORIGIN_TT_ACQUIRE_BEGIN - : GCS_BLOCK_R4_TX_ORIGIN_SEND; + cluster_ctrc_test_barrier_wait(CTRC_TEST_BARRIER_ACTIVE_PROOF_READY); + return advance == GCS_BLOCK_CURRENT_MX_ADVANCE_NEXT ? GCS_BLOCK_R4_TX_ORIGIN_TT_ACQUIRE_BEGIN + : GCS_BLOCK_R4_TX_ORIGIN_SEND; } /* The status-22 DATA worker is the one bounded resolver for all contexts in @@ -8098,14 +7838,12 @@ gcs_block_current_mx_origin_after_release( * burst must yield in the existing event loop until the current holder has * released it. Each waiting context retains its original deadline. */ static bool -gcs_block_r4_tx_origin_scur_available( - const GcsBlockR4TxOriginContext *context) +gcs_block_r4_tx_origin_scur_available(const GcsBlockR4TxOriginContext *context) { int i; for (i = 0; i < GCS_BLOCK_R4_TX_ORIGIN_CONTEXTS; i++) { - const GcsBlockR4TxOriginContext *other - = &gcs_block_r4_tx_origin_contexts[i]; + const GcsBlockR4TxOriginContext *other = &gcs_block_r4_tx_origin_contexts[i]; if (other != context && other->in_use && other->guard_active) return false; @@ -8116,8 +7854,7 @@ gcs_block_r4_tx_origin_scur_available( /* Status-22 contexts are owned by worker 0. Current-MX proof contexts are * owned by the DATA shard that accepted their exact request identity. */ static bool -gcs_block_r4_tx_origin_worker_current( - const GcsBlockR4TxOriginContext *context) +gcs_block_r4_tx_origin_worker_current(const GcsBlockR4TxOriginContext *context) { int current_worker; @@ -8126,13 +7863,11 @@ gcs_block_r4_tx_origin_worker_current( current_worker = cluster_ic_tier1_my_data_channel(); if (context->domain == GCS_BLOCK_R4_TX_ORIGIN_DOMAIN_CURRENT_MX) { BufferTag route_tag = GcsBlockCurrentMxRouteTagMake( - context->current_mx_request.prefix.request_id, - context->current_mx_request.prefix.epoch, + context->current_mx_request.prefix.request_id, context->current_mx_request.prefix.epoch, context->current_mx_request.prefix.original_requester_node, context->current_mx_request.prefix.requester_backend_id); - return current_worker - == cluster_lms_shard_for_tag(&route_tag, cluster_lms_workers); + return current_worker == cluster_lms_shard_for_tag(&route_tag, cluster_lms_workers); } return current_worker == 0; } @@ -8147,489 +7882,409 @@ gcs_block_r4_tx_origin_step(GcsBlockR4TxOriginContext *context) int remaining_timeout_ms; switch (context->phase) { - case GCS_BLOCK_R4_TX_ORIGIN_ACQUIRE_BEGIN: - if (!gcs_block_r4_tx_origin_scur_available(context)) { - if (gcs_block_r4_tx_origin_deadline_expired(context)) - gcs_block_r4_tx_origin_timeout(context); - break; - } - remaining_timeout_ms - = gcs_block_r4_tx_origin_remaining_timeout_ms(context); - if (context->deadline != 0 && remaining_timeout_ms == 0) { - context->reason = CLUSTER_TX_RESOLVE_TIMEOUT; - context->phase = GCS_BLOCK_R4_TX_ORIGIN_SEND; - break; - } - step = cluster_undo_block0_current_acquire_begin_admitted( - &context->logical, CLUSTER_UNDO_BLOCK0_SCUR, - remaining_timeout_ms, &context->admission, - &context->guard, &failure); - if (step == CLUSTER_UNDO_BLOCK0_CURRENT_HELD) { - context->guard_active = true; - context->phase = GCS_BLOCK_R4_TX_ORIGIN_DATA_FREEZE; - } else if (step == CLUSTER_UNDO_BLOCK0_CURRENT_PENDING) { - context->guard_active = true; - context->phase = GCS_BLOCK_R4_TX_ORIGIN_ACQUIRE_POLL; - } else - context->phase = GCS_BLOCK_R4_TX_ORIGIN_SEND; - break; - case GCS_BLOCK_R4_TX_ORIGIN_ACQUIRE_POLL: - if (gcs_block_r4_tx_origin_deadline_expired(context)) { + case GCS_BLOCK_R4_TX_ORIGIN_ACQUIRE_BEGIN: + if (!gcs_block_r4_tx_origin_scur_available(context)) { + if (gcs_block_r4_tx_origin_deadline_expired(context)) gcs_block_r4_tx_origin_timeout(context); - break; - } - step = cluster_undo_block0_current_acquire_poll( - &context->guard, &failure); - if (step == CLUSTER_UNDO_BLOCK0_CURRENT_HELD) - context->phase = GCS_BLOCK_R4_TX_ORIGIN_DATA_FREEZE; - else if (step == CLUSTER_UNDO_BLOCK0_CURRENT_FAILED) { - context->guard_active = false; - context->phase = GCS_BLOCK_R4_TX_ORIGIN_SEND; - } break; - case GCS_BLOCK_R4_TX_ORIGIN_DATA_FREEZE: - if (context->domain - == GCS_BLOCK_R4_TX_ORIGIN_DOMAIN_CURRENT_MX) { - current_mx_advance - = gcs_block_current_mx_origin_updater_provenance_advance( - context); - if (current_mx_advance - == GCS_BLOCK_CURRENT_MX_ADVANCE_COMPLETE) - context->phase - = GCS_BLOCK_R4_TX_ORIGIN_FINAL_RELEASE_BEGIN; - else if (current_mx_advance - == GCS_BLOCK_CURRENT_MX_ADVANCE_NEXT) - context->phase - = GCS_BLOCK_R4_TX_ORIGIN_DATA_RELEASE_BEGIN; - else { - context->current_mx_failure - = GCS_BLOCK_CURRENT_MX_ORIGIN_FAILURE_SAMPLE; - context->phase - = GCS_BLOCK_R4_TX_ORIGIN_FINAL_RELEASE_BEGIN; - } - break; - } - /* Neither remote consumer must cache this origin's header. Select - * only before freezing DATA, under the existing own-origin guard; - * the unchanged plan then binds and rechecks this exact generation. */ - if (!context->expected_generation.known) { - ClusterUndoBlock0Generation sampled = { false, 0 }; - - if (cluster_undo_block0_current_sample_generation(&context->guard, &context->root, - &sampled) - != CLUSTER_UNDO_BLOCK0_OK - || !sampled.known || sampled.value == UINT32_MAX) { - context->reason = CLUSTER_TX_RESOLVE_AUTHORITY_UNAVAILABLE; - context->phase = GCS_BLOCK_R4_TX_ORIGIN_FINAL_RELEASE_BEGIN; - break; - } - context->expected_generation = sampled; - } - origin_step - = cluster_runtime_visibility_origin_plan_freeze_data_held( - &context->locator, context->resolve_mode, - &context->admission, &context->expected_generation, - &context->guard, &context->root, - &context->origin_plan, &context->resolution, - &context->reason); - if (origin_step == CLUSTER_RUNTIME_VISIBILITY_ORIGIN_COMPLETE) { - context->outcome = context->resolution.outcome; - if (context->undo_data_fetch) - gcs_block_r4_undo_origin_copy_held(context, &context->root); - context->phase - = GCS_BLOCK_R4_TX_ORIGIN_FINAL_RELEASE_BEGIN; - } else if (origin_step - == CLUSTER_RUNTIME_VISIBILITY_ORIGIN_NEEDS_CANONICAL) - context->phase - = GCS_BLOCK_R4_TX_ORIGIN_DATA_RELEASE_BEGIN; - else - context->phase - = GCS_BLOCK_R4_TX_ORIGIN_FINAL_RELEASE_BEGIN; + } + remaining_timeout_ms = gcs_block_r4_tx_origin_remaining_timeout_ms(context); + if (context->deadline != 0 && remaining_timeout_ms == 0) { + context->reason = CLUSTER_TX_RESOLVE_TIMEOUT; + context->phase = GCS_BLOCK_R4_TX_ORIGIN_SEND; + break; + } + step = cluster_undo_block0_current_acquire_begin_admitted( + &context->logical, CLUSTER_UNDO_BLOCK0_SCUR, remaining_timeout_ms, &context->admission, + &context->guard, &failure); + if (step == CLUSTER_UNDO_BLOCK0_CURRENT_HELD) { + context->guard_active = true; + context->phase = GCS_BLOCK_R4_TX_ORIGIN_DATA_FREEZE; + } else if (step == CLUSTER_UNDO_BLOCK0_CURRENT_PENDING) { + context->guard_active = true; + context->phase = GCS_BLOCK_R4_TX_ORIGIN_ACQUIRE_POLL; + } else + context->phase = GCS_BLOCK_R4_TX_ORIGIN_SEND; + break; + case GCS_BLOCK_R4_TX_ORIGIN_ACQUIRE_POLL: + if (gcs_block_r4_tx_origin_deadline_expired(context)) { + gcs_block_r4_tx_origin_timeout(context); break; - case GCS_BLOCK_R4_TX_ORIGIN_DATA_RELEASE_BEGIN: - step = cluster_undo_block0_current_release_begin( - &context->guard, &failure); - if (step == CLUSTER_UNDO_BLOCK0_CURRENT_RELEASED) { - context->guard_active = false; - memset(&context->guard, 0, sizeof(context->guard)); - context->phase = GCS_BLOCK_R4_TX_ORIGIN_TT_ACQUIRE_BEGIN; - } else if (step == CLUSTER_UNDO_BLOCK0_CURRENT_PENDING) - context->phase = GCS_BLOCK_R4_TX_ORIGIN_DATA_RELEASE_POLL; + } + step = cluster_undo_block0_current_acquire_poll(&context->guard, &failure); + if (step == CLUSTER_UNDO_BLOCK0_CURRENT_HELD) + context->phase = GCS_BLOCK_R4_TX_ORIGIN_DATA_FREEZE; + else if (step == CLUSTER_UNDO_BLOCK0_CURRENT_FAILED) { + context->guard_active = false; + context->phase = GCS_BLOCK_R4_TX_ORIGIN_SEND; + } + break; + case GCS_BLOCK_R4_TX_ORIGIN_DATA_FREEZE: + if (context->domain == GCS_BLOCK_R4_TX_ORIGIN_DOMAIN_CURRENT_MX) { + current_mx_advance = gcs_block_current_mx_origin_updater_provenance_advance(context); + if (current_mx_advance == GCS_BLOCK_CURRENT_MX_ADVANCE_COMPLETE) + context->phase = GCS_BLOCK_R4_TX_ORIGIN_FINAL_RELEASE_BEGIN; + else if (current_mx_advance == GCS_BLOCK_CURRENT_MX_ADVANCE_NEXT) + context->phase = GCS_BLOCK_R4_TX_ORIGIN_DATA_RELEASE_BEGIN; else { - context->guard_active = false; - context->outcome = CLUSTER_TX_UNKNOWN; - context->reason = CLUSTER_TX_RESOLVE_AUTHORITY_UNAVAILABLE; - memset(&context->resolution, 0, - sizeof(context->resolution)); - context->phase = GCS_BLOCK_R4_TX_ORIGIN_SEND; + context->current_mx_failure = GCS_BLOCK_CURRENT_MX_ORIGIN_FAILURE_SAMPLE; + context->phase = GCS_BLOCK_R4_TX_ORIGIN_FINAL_RELEASE_BEGIN; } break; - case GCS_BLOCK_R4_TX_ORIGIN_DATA_RELEASE_POLL: - if (gcs_block_r4_tx_origin_deadline_expired(context)) { - gcs_block_r4_tx_origin_timeout(context); - break; - } - step = cluster_undo_block0_current_release_poll( - &context->guard, &failure); - if (step == CLUSTER_UNDO_BLOCK0_CURRENT_RELEASED) { - context->guard_active = false; - memset(&context->guard, 0, sizeof(context->guard)); - context->phase = GCS_BLOCK_R4_TX_ORIGIN_TT_ACQUIRE_BEGIN; - } else if (step == CLUSTER_UNDO_BLOCK0_CURRENT_FAILED) { - context->guard_active = false; - context->outcome = CLUSTER_TX_UNKNOWN; + } + /* Neither remote consumer must cache this origin's header. Select + * only before freezing DATA, under the existing own-origin guard; + * the unchanged plan then binds and rechecks this exact generation. */ + if (!context->expected_generation.known) { + ClusterUndoBlock0Generation sampled = { false, 0 }; + + if (cluster_undo_block0_current_sample_generation(&context->guard, &context->root, + &sampled) + != CLUSTER_UNDO_BLOCK0_OK + || !sampled.known || sampled.value == UINT32_MAX) { context->reason = CLUSTER_TX_RESOLVE_AUTHORITY_UNAVAILABLE; - memset(&context->resolution, 0, - sizeof(context->resolution)); - context->phase = GCS_BLOCK_R4_TX_ORIGIN_SEND; - } - break; - case GCS_BLOCK_R4_TX_ORIGIN_TT_ACQUIRE_BEGIN: - if (!gcs_block_r4_tx_origin_scur_available(context)) { - if (gcs_block_r4_tx_origin_deadline_expired(context)) - gcs_block_r4_tx_origin_timeout(context); + context->phase = GCS_BLOCK_R4_TX_ORIGIN_FINAL_RELEASE_BEGIN; break; } - if ((context->domain - == GCS_BLOCK_R4_TX_ORIGIN_DOMAIN_CURRENT_MX - && (!gcs_block_r4_tx_origin_admission_current(context) - || context->tt_logical.segment_id == 0)) - || (context->domain - == GCS_BLOCK_R4_TX_ORIGIN_DOMAIN_TX_RESOLVE - && (!cluster_runtime_visibility_origin_plan_canonical_logical( - &context->origin_plan, &context->tt_logical) - || !gcs_block_r4_tx_origin_resolve_root_current( - context, &context->tt_logical, - &context->tt_root)))) { - context->outcome = CLUSTER_TX_UNKNOWN; - context->reason = CLUSTER_TX_RESOLVE_AUTHORITY_STALE; - if (context->domain - == GCS_BLOCK_R4_TX_ORIGIN_DOMAIN_CURRENT_MX) { - context->current_mx_failure - = GCS_BLOCK_CURRENT_MX_ORIGIN_FAILURE_ROOT; - if (context->current_mx_locator_count != 0) - context->current_mx_failure_xid - = context->current_mx_locators[0].xid; - } - context->phase = GCS_BLOCK_R4_TX_ORIGIN_SEND; - break; - } - remaining_timeout_ms - = gcs_block_r4_tx_origin_remaining_timeout_ms(context); - if (context->deadline != 0 && remaining_timeout_ms == 0) { - context->reason = CLUSTER_TX_RESOLVE_TIMEOUT; - context->phase = GCS_BLOCK_R4_TX_ORIGIN_SEND; - break; - } - step = cluster_undo_block0_current_acquire_begin_admitted( - &context->tt_logical, CLUSTER_UNDO_BLOCK0_SCUR, - remaining_timeout_ms, &context->admission, - &context->guard, &failure); - if (step == CLUSTER_UNDO_BLOCK0_CURRENT_HELD) { - context->guard_active = true; - context->phase = GCS_BLOCK_R4_TX_ORIGIN_TT_SAMPLE; - } else if (step == CLUSTER_UNDO_BLOCK0_CURRENT_PENDING) { - context->guard_active = true; - context->phase = GCS_BLOCK_R4_TX_ORIGIN_TT_ACQUIRE_POLL; - } else { - if (context->domain - == GCS_BLOCK_R4_TX_ORIGIN_DOMAIN_CURRENT_MX) - context->current_mx_failure - = GCS_BLOCK_CURRENT_MX_ORIGIN_FAILURE_SCUR_ACQUIRE; - context->phase = GCS_BLOCK_R4_TX_ORIGIN_SEND; - } + context->expected_generation = sampled; + } + origin_step = cluster_runtime_visibility_origin_plan_freeze_data_held( + &context->locator, context->resolve_mode, &context->admission, + &context->expected_generation, &context->guard, &context->root, &context->origin_plan, + &context->resolution, &context->reason); + if (origin_step == CLUSTER_RUNTIME_VISIBILITY_ORIGIN_COMPLETE) { + context->outcome = context->resolution.outcome; + if (context->undo_data_fetch) + gcs_block_r4_undo_origin_copy_held(context, &context->root); + context->phase = GCS_BLOCK_R4_TX_ORIGIN_FINAL_RELEASE_BEGIN; + } else if (origin_step == CLUSTER_RUNTIME_VISIBILITY_ORIGIN_NEEDS_CANONICAL) + context->phase = GCS_BLOCK_R4_TX_ORIGIN_DATA_RELEASE_BEGIN; + else + context->phase = GCS_BLOCK_R4_TX_ORIGIN_FINAL_RELEASE_BEGIN; + break; + case GCS_BLOCK_R4_TX_ORIGIN_DATA_RELEASE_BEGIN: + step = cluster_undo_block0_current_release_begin(&context->guard, &failure); + if (step == CLUSTER_UNDO_BLOCK0_CURRENT_RELEASED) { + context->guard_active = false; + memset(&context->guard, 0, sizeof(context->guard)); + context->phase = GCS_BLOCK_R4_TX_ORIGIN_TT_ACQUIRE_BEGIN; + } else if (step == CLUSTER_UNDO_BLOCK0_CURRENT_PENDING) + context->phase = GCS_BLOCK_R4_TX_ORIGIN_DATA_RELEASE_POLL; + else { + context->guard_active = false; + context->outcome = CLUSTER_TX_UNKNOWN; + context->reason = CLUSTER_TX_RESOLVE_AUTHORITY_UNAVAILABLE; + memset(&context->resolution, 0, sizeof(context->resolution)); + context->phase = GCS_BLOCK_R4_TX_ORIGIN_SEND; + } + break; + case GCS_BLOCK_R4_TX_ORIGIN_DATA_RELEASE_POLL: + if (gcs_block_r4_tx_origin_deadline_expired(context)) { + gcs_block_r4_tx_origin_timeout(context); break; - case GCS_BLOCK_R4_TX_ORIGIN_TT_ACQUIRE_POLL: - if (gcs_block_r4_tx_origin_deadline_expired(context)) { + } + step = cluster_undo_block0_current_release_poll(&context->guard, &failure); + if (step == CLUSTER_UNDO_BLOCK0_CURRENT_RELEASED) { + context->guard_active = false; + memset(&context->guard, 0, sizeof(context->guard)); + context->phase = GCS_BLOCK_R4_TX_ORIGIN_TT_ACQUIRE_BEGIN; + } else if (step == CLUSTER_UNDO_BLOCK0_CURRENT_FAILED) { + context->guard_active = false; + context->outcome = CLUSTER_TX_UNKNOWN; + context->reason = CLUSTER_TX_RESOLVE_AUTHORITY_UNAVAILABLE; + memset(&context->resolution, 0, sizeof(context->resolution)); + context->phase = GCS_BLOCK_R4_TX_ORIGIN_SEND; + } + break; + case GCS_BLOCK_R4_TX_ORIGIN_TT_ACQUIRE_BEGIN: + if (!gcs_block_r4_tx_origin_scur_available(context)) { + if (gcs_block_r4_tx_origin_deadline_expired(context)) gcs_block_r4_tx_origin_timeout(context); - break; - } - step = cluster_undo_block0_current_acquire_poll( - &context->guard, &failure); - if (step == CLUSTER_UNDO_BLOCK0_CURRENT_HELD) - context->phase = GCS_BLOCK_R4_TX_ORIGIN_TT_SAMPLE; - else if (step == CLUSTER_UNDO_BLOCK0_CURRENT_FAILED) { - context->guard_active = false; - if (context->domain - == GCS_BLOCK_R4_TX_ORIGIN_DOMAIN_CURRENT_MX) - context->current_mx_failure - = GCS_BLOCK_CURRENT_MX_ORIGIN_FAILURE_SCUR_ACQUIRE; - context->phase = GCS_BLOCK_R4_TX_ORIGIN_SEND; + break; + } + if ((context->domain == GCS_BLOCK_R4_TX_ORIGIN_DOMAIN_CURRENT_MX + && (!gcs_block_r4_tx_origin_admission_current(context) + || context->tt_logical.segment_id == 0)) + || (context->domain == GCS_BLOCK_R4_TX_ORIGIN_DOMAIN_TX_RESOLVE + && (!cluster_runtime_visibility_origin_plan_canonical_logical(&context->origin_plan, + &context->tt_logical) + || !gcs_block_r4_tx_origin_resolve_root_current(context, &context->tt_logical, + &context->tt_root)))) { + context->outcome = CLUSTER_TX_UNKNOWN; + context->reason = CLUSTER_TX_RESOLVE_AUTHORITY_STALE; + if (context->domain == GCS_BLOCK_R4_TX_ORIGIN_DOMAIN_CURRENT_MX) { + context->current_mx_failure = GCS_BLOCK_CURRENT_MX_ORIGIN_FAILURE_ROOT; + if (context->current_mx_locator_count != 0) + context->current_mx_failure_xid = context->current_mx_locators[0].xid; } + context->phase = GCS_BLOCK_R4_TX_ORIGIN_SEND; + break; + } + remaining_timeout_ms = gcs_block_r4_tx_origin_remaining_timeout_ms(context); + if (context->deadline != 0 && remaining_timeout_ms == 0) { + context->reason = CLUSTER_TX_RESOLVE_TIMEOUT; + context->phase = GCS_BLOCK_R4_TX_ORIGIN_SEND; break; - case GCS_BLOCK_R4_TX_ORIGIN_TT_SAMPLE: - if (context->domain - == GCS_BLOCK_R4_TX_ORIGIN_DOMAIN_CURRENT_MX + } + step = cluster_undo_block0_current_acquire_begin_admitted( + &context->tt_logical, CLUSTER_UNDO_BLOCK0_SCUR, remaining_timeout_ms, + &context->admission, &context->guard, &failure); + if (step == CLUSTER_UNDO_BLOCK0_CURRENT_HELD) { + context->guard_active = true; + context->phase = GCS_BLOCK_R4_TX_ORIGIN_TT_SAMPLE; + } else if (step == CLUSTER_UNDO_BLOCK0_CURRENT_PENDING) { + context->guard_active = true; + context->phase = GCS_BLOCK_R4_TX_ORIGIN_TT_ACQUIRE_POLL; + } else { + if (context->domain == GCS_BLOCK_R4_TX_ORIGIN_DOMAIN_CURRENT_MX) + context->current_mx_failure = GCS_BLOCK_CURRENT_MX_ORIGIN_FAILURE_SCUR_ACQUIRE; + context->phase = GCS_BLOCK_R4_TX_ORIGIN_SEND; + } + break; + case GCS_BLOCK_R4_TX_ORIGIN_TT_ACQUIRE_POLL: + if (gcs_block_r4_tx_origin_deadline_expired(context)) { + gcs_block_r4_tx_origin_timeout(context); + break; + } + step = cluster_undo_block0_current_acquire_poll(&context->guard, &failure); + if (step == CLUSTER_UNDO_BLOCK0_CURRENT_HELD) + context->phase = GCS_BLOCK_R4_TX_ORIGIN_TT_SAMPLE; + else if (step == CLUSTER_UNDO_BLOCK0_CURRENT_FAILED) { + context->guard_active = false; + if (context->domain == GCS_BLOCK_R4_TX_ORIGIN_DOMAIN_CURRENT_MX) + context->current_mx_failure = GCS_BLOCK_CURRENT_MX_ORIGIN_FAILURE_SCUR_ACQUIRE; + context->phase = GCS_BLOCK_R4_TX_ORIGIN_SEND; + } + break; + case GCS_BLOCK_R4_TX_ORIGIN_TT_SAMPLE: + if (context->domain == GCS_BLOCK_R4_TX_ORIGIN_DOMAIN_CURRENT_MX + && context->current_mx_request.prefix.body_kind + == CLUSTER_CURRENT_MX_PROOF_BODY_UPDATER_CHALLENGE) + context->canonical_sampled + = gcs_block_current_mx_origin_updater_provenance_advance(context) + == GCS_BLOCK_CURRENT_MX_ADVANCE_NEXT; + else + context->canonical_sampled + = context->domain == GCS_BLOCK_R4_TX_ORIGIN_DOMAIN_CURRENT_MX + ? gcs_block_current_mx_origin_sample_held(context) + : cluster_runtime_visibility_origin_plan_sample_canonical_held( + &context->origin_plan, context->resolve_mode, &context->admission, + &context->guard, &context->tt_root, &context->reason); + if (context->domain == GCS_BLOCK_R4_TX_ORIGIN_DOMAIN_CURRENT_MX + && !context->canonical_sampled) + context->current_mx_failure = GCS_BLOCK_CURRENT_MX_ORIGIN_FAILURE_SAMPLE; + context->phase = GCS_BLOCK_R4_TX_ORIGIN_TT_RELEASE_BEGIN; + break; + case GCS_BLOCK_R4_TX_ORIGIN_TT_RELEASE_BEGIN: + step = cluster_undo_block0_current_release_begin(&context->guard, &failure); + if (step == CLUSTER_UNDO_BLOCK0_CURRENT_RELEASED) { + context->guard_active = false; + memset(&context->guard, 0, sizeof(context->guard)); + if (context->domain == GCS_BLOCK_R4_TX_ORIGIN_DOMAIN_CURRENT_MX && context->current_mx_request.prefix.body_kind - == CLUSTER_CURRENT_MX_PROOF_BODY_UPDATER_CHALLENGE) - context->canonical_sampled - = gcs_block_current_mx_origin_updater_provenance_advance( - context) == GCS_BLOCK_CURRENT_MX_ADVANCE_NEXT; + == CLUSTER_CURRENT_MX_PROOF_BODY_UPDATER_CHALLENGE) + context->phase = context->canonical_sampled + ? GCS_BLOCK_R4_TX_ORIGIN_DATA_RECHECK_ACQUIRE_BEGIN + : GCS_BLOCK_R4_TX_ORIGIN_SEND; else - context->canonical_sampled = context->domain - == GCS_BLOCK_R4_TX_ORIGIN_DOMAIN_CURRENT_MX - ? gcs_block_current_mx_origin_sample_held(context) - : cluster_runtime_visibility_origin_plan_sample_canonical_held( - &context->origin_plan, context->resolve_mode, - &context->admission, &context->guard, - &context->tt_root, &context->reason); - if (context->domain - == GCS_BLOCK_R4_TX_ORIGIN_DOMAIN_CURRENT_MX - && !context->canonical_sampled) - context->current_mx_failure - = GCS_BLOCK_CURRENT_MX_ORIGIN_FAILURE_SAMPLE; - context->phase = GCS_BLOCK_R4_TX_ORIGIN_TT_RELEASE_BEGIN; - break; - case GCS_BLOCK_R4_TX_ORIGIN_TT_RELEASE_BEGIN: - step = cluster_undo_block0_current_release_begin( - &context->guard, &failure); - if (step == CLUSTER_UNDO_BLOCK0_CURRENT_RELEASED) { - context->guard_active = false; - memset(&context->guard, 0, sizeof(context->guard)); - if (context->domain - == GCS_BLOCK_R4_TX_ORIGIN_DOMAIN_CURRENT_MX - && context->current_mx_request.prefix.body_kind - == CLUSTER_CURRENT_MX_PROOF_BODY_UPDATER_CHALLENGE) - context->phase = context->canonical_sampled - ? GCS_BLOCK_R4_TX_ORIGIN_DATA_RECHECK_ACQUIRE_BEGIN - : GCS_BLOCK_R4_TX_ORIGIN_SEND; - else - context->phase = context->domain - == GCS_BLOCK_R4_TX_ORIGIN_DOMAIN_CURRENT_MX - ? gcs_block_current_mx_origin_after_release(context) - : (context->canonical_sampled - ? GCS_BLOCK_R4_TX_ORIGIN_DATA_RECHECK_ACQUIRE_BEGIN - : GCS_BLOCK_R4_TX_ORIGIN_SEND); - } else if (step == CLUSTER_UNDO_BLOCK0_CURRENT_PENDING) - context->phase = GCS_BLOCK_R4_TX_ORIGIN_TT_RELEASE_POLL; - else { - context->guard_active = false; - context->outcome = CLUSTER_TX_UNKNOWN; - context->reason = CLUSTER_TX_RESOLVE_AUTHORITY_UNAVAILABLE; - if (context->domain - == GCS_BLOCK_R4_TX_ORIGIN_DOMAIN_CURRENT_MX) - context->current_mx_failure - = GCS_BLOCK_CURRENT_MX_ORIGIN_FAILURE_SCUR_RELEASE; - context->phase = GCS_BLOCK_R4_TX_ORIGIN_SEND; - } + context->phase = context->domain == GCS_BLOCK_R4_TX_ORIGIN_DOMAIN_CURRENT_MX + ? gcs_block_current_mx_origin_after_release(context) + : (context->canonical_sampled + ? GCS_BLOCK_R4_TX_ORIGIN_DATA_RECHECK_ACQUIRE_BEGIN + : GCS_BLOCK_R4_TX_ORIGIN_SEND); + } else if (step == CLUSTER_UNDO_BLOCK0_CURRENT_PENDING) + context->phase = GCS_BLOCK_R4_TX_ORIGIN_TT_RELEASE_POLL; + else { + context->guard_active = false; + context->outcome = CLUSTER_TX_UNKNOWN; + context->reason = CLUSTER_TX_RESOLVE_AUTHORITY_UNAVAILABLE; + if (context->domain == GCS_BLOCK_R4_TX_ORIGIN_DOMAIN_CURRENT_MX) + context->current_mx_failure = GCS_BLOCK_CURRENT_MX_ORIGIN_FAILURE_SCUR_RELEASE; + context->phase = GCS_BLOCK_R4_TX_ORIGIN_SEND; + } + break; + case GCS_BLOCK_R4_TX_ORIGIN_TT_RELEASE_POLL: + if (gcs_block_r4_tx_origin_deadline_expired(context)) { + gcs_block_r4_tx_origin_timeout(context); break; - case GCS_BLOCK_R4_TX_ORIGIN_TT_RELEASE_POLL: - if (gcs_block_r4_tx_origin_deadline_expired(context)) { + } + step = cluster_undo_block0_current_release_poll(&context->guard, &failure); + if (step == CLUSTER_UNDO_BLOCK0_CURRENT_RELEASED) { + context->guard_active = false; + memset(&context->guard, 0, sizeof(context->guard)); + if (context->domain == GCS_BLOCK_R4_TX_ORIGIN_DOMAIN_CURRENT_MX + && context->current_mx_request.prefix.body_kind + == CLUSTER_CURRENT_MX_PROOF_BODY_UPDATER_CHALLENGE) + context->phase = context->canonical_sampled + ? GCS_BLOCK_R4_TX_ORIGIN_DATA_RECHECK_ACQUIRE_BEGIN + : GCS_BLOCK_R4_TX_ORIGIN_SEND; + else + context->phase = context->domain == GCS_BLOCK_R4_TX_ORIGIN_DOMAIN_CURRENT_MX + ? gcs_block_current_mx_origin_after_release(context) + : (context->canonical_sampled + ? GCS_BLOCK_R4_TX_ORIGIN_DATA_RECHECK_ACQUIRE_BEGIN + : GCS_BLOCK_R4_TX_ORIGIN_SEND); + } else if (step == CLUSTER_UNDO_BLOCK0_CURRENT_FAILED) { + context->guard_active = false; + context->outcome = CLUSTER_TX_UNKNOWN; + context->reason = CLUSTER_TX_RESOLVE_AUTHORITY_UNAVAILABLE; + if (context->domain == GCS_BLOCK_R4_TX_ORIGIN_DOMAIN_CURRENT_MX) + context->current_mx_failure = GCS_BLOCK_CURRENT_MX_ORIGIN_FAILURE_SCUR_RELEASE; + context->phase = GCS_BLOCK_R4_TX_ORIGIN_SEND; + } + break; + case GCS_BLOCK_R4_TX_ORIGIN_DATA_RECHECK_ACQUIRE_BEGIN: + if (!gcs_block_r4_tx_origin_scur_available(context)) { + if (gcs_block_r4_tx_origin_deadline_expired(context)) gcs_block_r4_tx_origin_timeout(context); - break; - } - step = cluster_undo_block0_current_release_poll( - &context->guard, &failure); - if (step == CLUSTER_UNDO_BLOCK0_CURRENT_RELEASED) { - context->guard_active = false; - memset(&context->guard, 0, sizeof(context->guard)); - if (context->domain - == GCS_BLOCK_R4_TX_ORIGIN_DOMAIN_CURRENT_MX - && context->current_mx_request.prefix.body_kind - == CLUSTER_CURRENT_MX_PROOF_BODY_UPDATER_CHALLENGE) - context->phase = context->canonical_sampled - ? GCS_BLOCK_R4_TX_ORIGIN_DATA_RECHECK_ACQUIRE_BEGIN - : GCS_BLOCK_R4_TX_ORIGIN_SEND; - else - context->phase = context->domain - == GCS_BLOCK_R4_TX_ORIGIN_DOMAIN_CURRENT_MX - ? gcs_block_current_mx_origin_after_release(context) - : (context->canonical_sampled - ? GCS_BLOCK_R4_TX_ORIGIN_DATA_RECHECK_ACQUIRE_BEGIN - : GCS_BLOCK_R4_TX_ORIGIN_SEND); - } else if (step == CLUSTER_UNDO_BLOCK0_CURRENT_FAILED) { - context->guard_active = false; - context->outcome = CLUSTER_TX_UNKNOWN; - context->reason = CLUSTER_TX_RESOLVE_AUTHORITY_UNAVAILABLE; - if (context->domain - == GCS_BLOCK_R4_TX_ORIGIN_DOMAIN_CURRENT_MX) - context->current_mx_failure - = GCS_BLOCK_CURRENT_MX_ORIGIN_FAILURE_SCUR_RELEASE; - context->phase = GCS_BLOCK_R4_TX_ORIGIN_SEND; - } break; - case GCS_BLOCK_R4_TX_ORIGIN_DATA_RECHECK_ACQUIRE_BEGIN: - if (!gcs_block_r4_tx_origin_scur_available(context)) { - if (gcs_block_r4_tx_origin_deadline_expired(context)) - gcs_block_r4_tx_origin_timeout(context); - break; - } - if (!gcs_block_r4_tx_origin_resolve_root_current( - context, &context->logical, &context->recheck_root) - || context->recheck_root.intent != context->root.intent - || context->recheck_root.root_id != context->root.root_id - || context->recheck_root.root_generation - != context->root.root_generation) { - context->outcome = CLUSTER_TX_UNKNOWN; - context->reason = CLUSTER_TX_RESOLVE_AUTHORITY_STALE; - context->phase = GCS_BLOCK_R4_TX_ORIGIN_SEND; - break; - } - remaining_timeout_ms - = gcs_block_r4_tx_origin_remaining_timeout_ms(context); - if (context->deadline != 0 && remaining_timeout_ms == 0) { - context->reason = CLUSTER_TX_RESOLVE_TIMEOUT; - context->phase = GCS_BLOCK_R4_TX_ORIGIN_SEND; - break; - } - step = cluster_undo_block0_current_acquire_begin_admitted( - &context->logical, CLUSTER_UNDO_BLOCK0_SCUR, - remaining_timeout_ms, &context->admission, - &context->guard, &failure); - if (step == CLUSTER_UNDO_BLOCK0_CURRENT_HELD) { - context->guard_active = true; - context->phase = GCS_BLOCK_R4_TX_ORIGIN_DATA_RECHECK; - } else if (step == CLUSTER_UNDO_BLOCK0_CURRENT_PENDING) { - context->guard_active = true; - context->phase - = GCS_BLOCK_R4_TX_ORIGIN_DATA_RECHECK_ACQUIRE_POLL; - } else - context->phase = GCS_BLOCK_R4_TX_ORIGIN_SEND; - break; - case GCS_BLOCK_R4_TX_ORIGIN_DATA_RECHECK_ACQUIRE_POLL: - if (gcs_block_r4_tx_origin_deadline_expired(context)) { - gcs_block_r4_tx_origin_timeout(context); - break; - } - step = cluster_undo_block0_current_acquire_poll( - &context->guard, &failure); - if (step == CLUSTER_UNDO_BLOCK0_CURRENT_HELD) - context->phase = GCS_BLOCK_R4_TX_ORIGIN_DATA_RECHECK; - else if (step == CLUSTER_UNDO_BLOCK0_CURRENT_FAILED) { - context->guard_active = false; - context->phase = GCS_BLOCK_R4_TX_ORIGIN_SEND; - } + } + if (!gcs_block_r4_tx_origin_resolve_root_current(context, &context->logical, + &context->recheck_root) + || context->recheck_root.intent != context->root.intent + || context->recheck_root.root_id != context->root.root_id + || context->recheck_root.root_generation != context->root.root_generation) { + context->outcome = CLUSTER_TX_UNKNOWN; + context->reason = CLUSTER_TX_RESOLVE_AUTHORITY_STALE; + context->phase = GCS_BLOCK_R4_TX_ORIGIN_SEND; break; - case GCS_BLOCK_R4_TX_ORIGIN_DATA_RECHECK: - if (context->domain - == GCS_BLOCK_R4_TX_ORIGIN_DOMAIN_CURRENT_MX) - (void)gcs_block_current_mx_origin_updater_provenance_advance( - context); - else if (context->undo_data_fetch) - gcs_block_r4_undo_origin_copy_held(context, &context->recheck_root); - else - context->outcome - = cluster_runtime_visibility_origin_plan_recheck_data_held( - &context->origin_plan, context->resolve_mode, - &context->admission, &context->guard, - &context->recheck_root, &context->resolution, - &context->reason); - context->phase = GCS_BLOCK_R4_TX_ORIGIN_FINAL_RELEASE_BEGIN; + } + remaining_timeout_ms = gcs_block_r4_tx_origin_remaining_timeout_ms(context); + if (context->deadline != 0 && remaining_timeout_ms == 0) { + context->reason = CLUSTER_TX_RESOLVE_TIMEOUT; + context->phase = GCS_BLOCK_R4_TX_ORIGIN_SEND; break; - case GCS_BLOCK_R4_TX_ORIGIN_FINAL_RELEASE_BEGIN: - step = cluster_undo_block0_current_release_begin( - &context->guard, &failure); - if (step == CLUSTER_UNDO_BLOCK0_CURRENT_RELEASED) { - context->guard_active = false; - context->phase = context->domain - == GCS_BLOCK_R4_TX_ORIGIN_DOMAIN_CURRENT_MX - ? gcs_block_current_mx_origin_after_release(context) - : GCS_BLOCK_R4_TX_ORIGIN_SEND; - } else if (step == CLUSTER_UNDO_BLOCK0_CURRENT_PENDING) - context->phase = GCS_BLOCK_R4_TX_ORIGIN_FINAL_RELEASE_POLL; - else { - context->guard_active = false; - context->outcome = CLUSTER_TX_UNKNOWN; - context->reason = CLUSTER_TX_RESOLVE_AUTHORITY_UNAVAILABLE; - memset(&context->resolution, 0, - sizeof(context->resolution)); - context->phase = GCS_BLOCK_R4_TX_ORIGIN_SEND; - } + } + step = cluster_undo_block0_current_acquire_begin_admitted( + &context->logical, CLUSTER_UNDO_BLOCK0_SCUR, remaining_timeout_ms, &context->admission, + &context->guard, &failure); + if (step == CLUSTER_UNDO_BLOCK0_CURRENT_HELD) { + context->guard_active = true; + context->phase = GCS_BLOCK_R4_TX_ORIGIN_DATA_RECHECK; + } else if (step == CLUSTER_UNDO_BLOCK0_CURRENT_PENDING) { + context->guard_active = true; + context->phase = GCS_BLOCK_R4_TX_ORIGIN_DATA_RECHECK_ACQUIRE_POLL; + } else + context->phase = GCS_BLOCK_R4_TX_ORIGIN_SEND; + break; + case GCS_BLOCK_R4_TX_ORIGIN_DATA_RECHECK_ACQUIRE_POLL: + if (gcs_block_r4_tx_origin_deadline_expired(context)) { + gcs_block_r4_tx_origin_timeout(context); break; - case GCS_BLOCK_R4_TX_ORIGIN_FINAL_RELEASE_POLL: - if (gcs_block_r4_tx_origin_deadline_expired(context)) { - gcs_block_r4_tx_origin_timeout(context); - break; - } - step = cluster_undo_block0_current_release_poll( - &context->guard, &failure); - if (step == CLUSTER_UNDO_BLOCK0_CURRENT_RELEASED) { - context->guard_active = false; - context->phase = context->domain - == GCS_BLOCK_R4_TX_ORIGIN_DOMAIN_CURRENT_MX - ? gcs_block_current_mx_origin_after_release(context) - : GCS_BLOCK_R4_TX_ORIGIN_SEND; - } else if (step == CLUSTER_UNDO_BLOCK0_CURRENT_FAILED) { - context->guard_active = false; - context->outcome = CLUSTER_TX_UNKNOWN; - context->reason = CLUSTER_TX_RESOLVE_AUTHORITY_UNAVAILABLE; - memset(&context->resolution, 0, - sizeof(context->resolution)); - context->phase = GCS_BLOCK_R4_TX_ORIGIN_SEND; - } + } + step = cluster_undo_block0_current_acquire_poll(&context->guard, &failure); + if (step == CLUSTER_UNDO_BLOCK0_CURRENT_HELD) + context->phase = GCS_BLOCK_R4_TX_ORIGIN_DATA_RECHECK; + else if (step == CLUSTER_UNDO_BLOCK0_CURRENT_FAILED) { + context->guard_active = false; + context->phase = GCS_BLOCK_R4_TX_ORIGIN_SEND; + } + break; + case GCS_BLOCK_R4_TX_ORIGIN_DATA_RECHECK: + if (context->domain == GCS_BLOCK_R4_TX_ORIGIN_DOMAIN_CURRENT_MX) + (void)gcs_block_current_mx_origin_updater_provenance_advance(context); + else if (context->undo_data_fetch) + gcs_block_r4_undo_origin_copy_held(context, &context->recheck_root); + else + context->outcome = cluster_runtime_visibility_origin_plan_recheck_data_held( + &context->origin_plan, context->resolve_mode, &context->admission, &context->guard, + &context->recheck_root, &context->resolution, &context->reason); + context->phase = GCS_BLOCK_R4_TX_ORIGIN_FINAL_RELEASE_BEGIN; + break; + case GCS_BLOCK_R4_TX_ORIGIN_FINAL_RELEASE_BEGIN: + step = cluster_undo_block0_current_release_begin(&context->guard, &failure); + if (step == CLUSTER_UNDO_BLOCK0_CURRENT_RELEASED) { + context->guard_active = false; + context->phase = context->domain == GCS_BLOCK_R4_TX_ORIGIN_DOMAIN_CURRENT_MX + ? gcs_block_current_mx_origin_after_release(context) + : GCS_BLOCK_R4_TX_ORIGIN_SEND; + } else if (step == CLUSTER_UNDO_BLOCK0_CURRENT_PENDING) + context->phase = GCS_BLOCK_R4_TX_ORIGIN_FINAL_RELEASE_POLL; + else { + context->guard_active = false; + context->outcome = CLUSTER_TX_UNKNOWN; + context->reason = CLUSTER_TX_RESOLVE_AUTHORITY_UNAVAILABLE; + memset(&context->resolution, 0, sizeof(context->resolution)); + context->phase = GCS_BLOCK_R4_TX_ORIGIN_SEND; + } + break; + case GCS_BLOCK_R4_TX_ORIGIN_FINAL_RELEASE_POLL: + if (gcs_block_r4_tx_origin_deadline_expired(context)) { + gcs_block_r4_tx_origin_timeout(context); break; - case GCS_BLOCK_R4_TX_ORIGIN_SEND: - { - ClusterICSendResult send_result; - uint32 capability_generation = 0; - bool optional_supported = false; - int32 requester_node; - uint64 request_epoch; - bool capability_current; - uint32 reply_size = GCS_BLOCK_REPLY_PAYLOAD_TOTAL_SIZE; - - if (context->domain - == GCS_BLOCK_R4_TX_ORIGIN_DOMAIN_CURRENT_MX) { - requester_node - = context->current_mx_request.prefix.original_requester_node; - request_epoch = context->current_mx_request.prefix.epoch; - capability_current - = cluster_sf_peer_multixact_current_capability_generation( - requester_node, &capability_generation) - && cluster_sf_peer_capability_generation_matches( - requester_node, - PGRAC_IC_HELLO_CAP_MULTIXACT_CURRENT_V1, - capability_generation); - } else { - requester_node - = context->forward.base.original_requester_node; - request_epoch = context->forward.base.epoch; - capability_current = cluster_sf_peer_capability_family_sample( - requester_node, GCS_BLOCK_R4_TX_REQUIRED_HELLO_CAPS, 0, - &optional_supported, &capability_generation); - } + } + step = cluster_undo_block0_current_release_poll(&context->guard, &failure); + if (step == CLUSTER_UNDO_BLOCK0_CURRENT_RELEASED) { + context->guard_active = false; + context->phase = context->domain == GCS_BLOCK_R4_TX_ORIGIN_DOMAIN_CURRENT_MX + ? gcs_block_current_mx_origin_after_release(context) + : GCS_BLOCK_R4_TX_ORIGIN_SEND; + } else if (step == CLUSTER_UNDO_BLOCK0_CURRENT_FAILED) { + context->guard_active = false; + context->outcome = CLUSTER_TX_UNKNOWN; + context->reason = CLUSTER_TX_RESOLVE_AUTHORITY_UNAVAILABLE; + memset(&context->resolution, 0, sizeof(context->resolution)); + context->phase = GCS_BLOCK_R4_TX_ORIGIN_SEND; + } + break; + case GCS_BLOCK_R4_TX_ORIGIN_SEND: { + ClusterICSendResult send_result; + uint32 capability_generation = 0; + bool optional_supported = false; + int32 requester_node; + uint64 request_epoch; + bool capability_current; + uint32 reply_size = GCS_BLOCK_REPLY_PAYLOAD_TOTAL_SIZE; + + if (context->domain == GCS_BLOCK_R4_TX_ORIGIN_DOMAIN_CURRENT_MX) { + requester_node = context->current_mx_request.prefix.original_requester_node; + request_epoch = context->current_mx_request.prefix.epoch; + capability_current = cluster_sf_peer_multixact_current_capability_generation( + requester_node, &capability_generation) + && cluster_sf_peer_capability_generation_matches( + requester_node, PGRAC_IC_HELLO_CAP_MULTIXACT_CURRENT_V1, + capability_generation); + } else { + requester_node = context->forward.base.original_requester_node; + request_epoch = context->forward.base.epoch; + capability_current = cluster_sf_peer_capability_family_sample( + requester_node, GCS_BLOCK_R4_TX_REQUIRED_HELLO_CAPS, 0, &optional_supported, + &capability_generation); + } - if (!gcs_block_r4_tx_origin_worker_current(context) - || cluster_epoch_get_current() != request_epoch - || !capability_current - || capability_generation - != context->requester_capability_generation - || !gcs_block_r4_tx_origin_admission_current(context)) { - if (context->domain - == GCS_BLOCK_R4_TX_ORIGIN_DOMAIN_CURRENT_MX) { - context->current_mx_failure - = GCS_BLOCK_CURRENT_MX_ORIGIN_FAILURE_SEND_FRESHNESS; - gcs_block_current_mx_origin_log_first_unknown(context); - } - gcs_block_r4_tx_origin_context_clear(context, true); - break; + if (!gcs_block_r4_tx_origin_worker_current(context) + || cluster_epoch_get_current() != request_epoch || !capability_current + || capability_generation != context->requester_capability_generation + || !gcs_block_r4_tx_origin_admission_current(context)) { + if (context->domain == GCS_BLOCK_R4_TX_ORIGIN_DOMAIN_CURRENT_MX) { + context->current_mx_failure = GCS_BLOCK_CURRENT_MX_ORIGIN_FAILURE_SEND_FRESHNESS; + gcs_block_current_mx_origin_log_first_unknown(context); } - if (context->domain - == GCS_BLOCK_R4_TX_ORIGIN_DOMAIN_CURRENT_MX) - gcs_block_current_mx_origin_prepare_reply(context); - else if (context->undo_data_fetch) - reply_size = gcs_block_r4_undo_origin_prepare_reply(context); - else - gcs_block_r4_tx_origin_prepare_reply(context); - send_result = gcs_block_send_envelope_or_loopback( - PGRAC_IC_MSG_GCS_BLOCK_REPLY, requester_node, context->reply_frame, reply_size); - cluster_gcs_block_note_send_outcome( - GCS_BLOCK_SEND_FAMILY_REPLY, send_result); - if (context->domain == GCS_BLOCK_R4_TX_ORIGIN_DOMAIN_TX_RESOLVE - && send_result == CLUSTER_IC_SEND_NOT_ADMITTED) - break; - if (send_result == CLUSTER_IC_SEND_HARD_ERROR) - cluster_lms_data_plane_close_peer_now( - context->forward.base.original_requester_node); - else if (ClusterGcsBlock != NULL) - pg_atomic_fetch_add_u64( - &ClusterGcsBlock->block_reply_count, 1); gcs_block_r4_tx_origin_context_clear(context, true); break; } - default: - gcs_block_r4_tx_origin_context_clear(context, true); + if (context->domain == GCS_BLOCK_R4_TX_ORIGIN_DOMAIN_CURRENT_MX) + gcs_block_current_mx_origin_prepare_reply(context); + else if (context->undo_data_fetch) + reply_size = gcs_block_r4_undo_origin_prepare_reply(context); + else + gcs_block_r4_tx_origin_prepare_reply(context); + send_result = gcs_block_send_envelope_or_loopback( + PGRAC_IC_MSG_GCS_BLOCK_REPLY, requester_node, context->reply_frame, reply_size); + cluster_gcs_block_note_send_outcome(GCS_BLOCK_SEND_FAMILY_REPLY, send_result); + if (context->domain == GCS_BLOCK_R4_TX_ORIGIN_DOMAIN_TX_RESOLVE + && send_result == CLUSTER_IC_SEND_NOT_ADMITTED) break; + if (send_result == CLUSTER_IC_SEND_HARD_ERROR) + cluster_lms_data_plane_close_peer_now(context->forward.base.original_requester_node); + else if (ClusterGcsBlock != NULL) + pg_atomic_fetch_add_u64(&ClusterGcsBlock->block_reply_count, 1); + gcs_block_r4_tx_origin_context_clear(context, true); + break; + } + default: + gcs_block_r4_tx_origin_context_clear(context, true); + break; } if (context->in_use && failure != CLUSTER_UNDO_BLOCK0_OK && context->current_failure == CLUSTER_UNDO_BLOCK0_OK) @@ -8642,15 +8297,12 @@ cluster_gcs_block_r4_tx_resolve_drain(void) int i; for (i = 0; i < GCS_BLOCK_R4_TX_ORIGIN_CONTEXTS; i++) { - GcsBlockR4TxOriginContext *context - = &gcs_block_r4_tx_origin_contexts[i]; + GcsBlockR4TxOriginContext *context = &gcs_block_r4_tx_origin_contexts[i]; int step_budget; if (!context->in_use) continue; - for (step_budget = 0; - step_budget < GCS_BLOCK_R4_TX_ORIGIN_STEP_BUDGET; - step_budget++) { + for (step_budget = 0; step_budget < GCS_BLOCK_R4_TX_ORIGIN_STEP_BUDGET; step_budget++) { GcsBlockR4TxOriginPhase phase_before = context->phase; MemoryContext saved_context = CurrentMemoryContext; @@ -8677,8 +8329,7 @@ cluster_gcs_block_r4_tx_resolve_drain(void) } PG_END_TRY(); if (context->in_use && context->failure_phase == 0 - && gcs_block_r4_tx_origin_failure_transition( - phase_before, context)) + && gcs_block_r4_tx_origin_failure_transition(phase_before, context)) context->failure_phase = phase_before; if (!context->in_use || context->phase == phase_before) break; @@ -8747,8 +8398,7 @@ cluster_gcs_block_r4_tx_resolve_wait_timeout(long idle_timeout_ms) for (i = 0; i < GCS_BLOCK_R4_TX_ORIGIN_CONTEXTS; i++) if (gcs_block_r4_tx_origin_contexts[i].in_use) active_contexts++; - return cluster_gcs_block_r4_tx_resolve_wait_timeout_for_count( - idle_timeout_ms, active_contexts); + return cluster_gcs_block_r4_tx_resolve_wait_timeout_for_count(idle_timeout_ms, active_contexts); } static void @@ -8980,8 +8630,7 @@ gcs_block_produce_reply(const GcsBlockRequestPayload *req, char *block_buf, bool if (out_sf_dep_valid != NULL) *out_sf_dep_valid = false; if (preprepared_image - && (*out_block_payload != block_buf - || PageGetLSN((Page)block_buf) != *out_page_lsn)) { + && (*out_block_payload != block_buf || PageGetLSN((Page)block_buf) != *out_page_lsn)) { /* The X->S helper already committed the local downgrade, so never * recopy or invent a carrier here. A PostgreSQL page LSN of zero is * valid (for example, a hint-only page); only disagreement between the @@ -9151,8 +8800,7 @@ bool cluster_gcs_block_resource_x_local_s_barrier_active(BufferTag tag) { if (!cluster_pcm_lock_resource_x_s_barrier_active(&tag) - && !cluster_pcm_lock_resource_x_requester_s_barrier_active_exact( - &tag)) + && !cluster_pcm_lock_resource_x_requester_s_barrier_active_exact(&tag)) return false; if (ClusterGcsBlock != NULL) pg_atomic_fetch_add_u64(&ClusterGcsBlock->starvation_denied_pending_x_count, 1); @@ -9175,28 +8823,25 @@ gcs_block_pcm_x_saturating_add_us(uint64 base, uint64 delta) } static bool -gcs_block_resource_x_diagnostic_should_log( - GcsBlockResourceXDiagnostic diagnostic, int discriminator) +gcs_block_resource_x_diagnostic_should_log(GcsBlockResourceXDiagnostic diagnostic, + int discriminator) { uint32 diagnostic_class; uint64 now_us; uint64 *next_log_at; - if (diagnostic < 0 - || diagnostic >= GCS_BLOCK_RESOURCE_X_DIAGNOSTIC_COUNT) + if (diagnostic < 0 || diagnostic >= GCS_BLOCK_RESOURCE_X_DIAGNOSTIC_COUNT) return false; - diagnostic_class = discriminator >= 0 - && discriminator < GCS_BLOCK_RESOURCE_X_DIAGNOSTIC_CLASS_COUNT - 1 - ? (uint32)discriminator - : GCS_BLOCK_RESOURCE_X_DIAGNOSTIC_CLASS_COUNT - 1; - next_log_at - = &gcs_block_resource_x_diagnostic_next_log_at[diagnostic] - [diagnostic_class]; + diagnostic_class + = discriminator >= 0 && discriminator < GCS_BLOCK_RESOURCE_X_DIAGNOSTIC_CLASS_COUNT - 1 + ? (uint32)discriminator + : GCS_BLOCK_RESOURCE_X_DIAGNOSTIC_CLASS_COUNT - 1; + next_log_at = &gcs_block_resource_x_diagnostic_next_log_at[diagnostic][diagnostic_class]; now_us = gcs_block_pcm_x_monotonic_us(); if (now_us < *next_log_at) return false; - *next_log_at = gcs_block_pcm_x_saturating_add_us( - now_us, GCS_BLOCK_RESOURCE_X_DIAGNOSTIC_INTERVAL_US); + *next_log_at + = gcs_block_pcm_x_saturating_add_us(now_us, GCS_BLOCK_RESOURCE_X_DIAGNOSTIC_INTERVAL_US); return true; } @@ -9224,9 +8869,7 @@ gcs_block_pcm_x_retry_timeout_us(void) { uint64 timeout_ms = (uint64)Max(cluster_gcs_reply_timeout_ms, 1); - return timeout_ms > UINT64_MAX / UINT64_C(1000) - ? UINT64_MAX - : timeout_ms * UINT64_C(1000); + return timeout_ms > UINT64_MAX / UINT64_C(1000) ? UINT64_MAX : timeout_ms * UINT64_C(1000); } static bool @@ -9234,20 +8877,20 @@ gcs_block_resource_x_payload_candidate(uint8 msg_type, uint32 payload_length) { if (msg_type == RESOURCE_X_MSG_ASSERT_X) return payload_length == RESOURCE_X_CONTROL_V1_BYTES - || payload_length == RESOURCE_X_SHORT_V1_BYTES; + || payload_length == RESOURCE_X_SHORT_V1_BYTES; if (msg_type == RESOURCE_X_MSG_IMAGE_OR_GRANT) return payload_length == RESOURCE_X_CONTROL_V1_BYTES - || payload_length == RESOURCE_X_PROOF_V1_BYTES - || payload_length == RESOURCE_X_IMAGE_V1_BYTES; + || payload_length == RESOURCE_X_PROOF_V1_BYTES + || payload_length == RESOURCE_X_IMAGE_V1_BYTES; if (msg_type == RESOURCE_X_MSG_BLOCK_TO_N) return payload_length == RESOURCE_X_CONTROL_V1_BYTES - || payload_length == RESOURCE_X_PROOF_V1_BYTES; + || payload_length == RESOURCE_X_PROOF_V1_BYTES; if (msg_type == RESOURCE_X_MSG_BLOCKED_TO_N) return payload_length == RESOURCE_X_CONTROL_V1_BYTES - || payload_length == RESOURCE_X_PROOF_V1_BYTES; + || payload_length == RESOURCE_X_PROOF_V1_BYTES; if (msg_type == RESOURCE_X_MSG_SETTLEMENT_OR_RELEASE) return payload_length == RESOURCE_X_CONTROL_V1_BYTES - || payload_length == RESOURCE_X_SHORT_V1_BYTES; + || payload_length == RESOURCE_X_SHORT_V1_BYTES; return false; } @@ -9255,8 +8898,7 @@ gcs_block_resource_x_payload_candidate(uint8 msg_type, uint32 payload_length) * connection (or the local endpoint) advertises the complete Resource-X * consumer. A missing/reconnected peer stays on the legacy queue path. */ static bool -gcs_block_pcm_x_resource_x_peer_ready_exact(int32 peer_node, - uint32 *connection_generation_out) +gcs_block_pcm_x_resource_x_peer_ready_exact(int32 peer_node, uint32 *connection_generation_out) { uint32 capability_word = 0; uint32 connection_generation = 0; @@ -9266,8 +8908,8 @@ gcs_block_pcm_x_resource_x_peer_ready_exact(int32 peer_node, if (peer_node < 0 || peer_node >= RESOURCE_X_PROTOCOL_NODE_LIMIT) return false; if (peer_node == cluster_node_id) { - if ((cluster_ic_local_capability_word() - & PGRAC_IC_HELLO_CAP_GCS_RESOURCE_X_CONVERT_V1) == 0) + if ((cluster_ic_local_capability_word() & PGRAC_IC_HELLO_CAP_GCS_RESOURCE_X_CONVERT_V1) + == 0) return false; /* Same-node loopback has no peer HELLO record. Match the existing * local DATA projection: capability-current generation 1 is sampled @@ -9276,9 +8918,9 @@ gcs_block_pcm_x_resource_x_peer_ready_exact(int32 peer_node, *connection_generation_out = 1; return true; } - if (!cluster_sf_peer_capability_word_sample( - peer_node, PGRAC_IC_HELLO_CAP_GCS_RESOURCE_X_CONVERT_V1, - &capability_word, &connection_generation) + if (!cluster_sf_peer_capability_word_sample(peer_node, + PGRAC_IC_HELLO_CAP_GCS_RESOURCE_X_CONVERT_V1, + &capability_word, &connection_generation) || connection_generation == 0) return false; if (connection_generation_out != NULL) @@ -9328,9 +8970,10 @@ gcs_block_resource_x_stage_ready_tag(const BufferTag *tag) } static PcmXSessionAuthResult -gcs_block_resource_x_gate_session_snapshot_result( - const BufferTag *tag, ResourceXGateSnapshot *gate_out, - int32 *master_node_out, uint64 *master_session_out) +gcs_block_resource_x_gate_session_snapshot_result(const BufferTag *tag, + ResourceXGateSnapshot *gate_out, + int32 *master_node_out, + uint64 *master_session_out) { ResourceXGateSnapshot gate; PcmXSessionAuthResult session_result; @@ -9365,16 +9008,14 @@ gcs_block_resource_x_gate_session_snapshot_result( } static bool -gcs_block_resource_x_gate_session_snapshot( - const BufferTag *tag, ResourceXGateSnapshot *gate_out, - int32 *master_node_out, uint64 *master_session_out) +gcs_block_resource_x_gate_session_snapshot(const BufferTag *tag, ResourceXGateSnapshot *gate_out, + int32 *master_node_out, uint64 *master_session_out) { ResourceXGateSnapshot gate; uint64 master_session = 0; int32 master_node = -1; - if (gcs_block_resource_x_gate_session_snapshot_result( - tag, &gate, &master_node, &master_session) + if (gcs_block_resource_x_gate_session_snapshot_result(tag, &gate, &master_node, &master_session) != PCM_X_SESSION_AUTH_OK) return false; if (gate_out != NULL) @@ -9447,14 +9088,12 @@ gcs_block_resource_x_fail_closed_current(void) ResourceXGateSnapshot gate; ResourceXApplyResult result; - if (!cluster_pcm_lock_resource_x_gate_snapshot(&gate) - || gate.phase != RESOURCE_X_GATE_OPEN) + if (!cluster_pcm_lock_resource_x_gate_snapshot(&gate) || gate.phase != RESOURCE_X_GATE_OPEN) return; result = cluster_pcm_lock_resource_x_gate_fail_closed_exact(&gate); if (result == RESOURCE_X_APPLY_APPLIED) - ereport(LOG, - (errmsg_internal("cluster PCM-X runtime fail-closed (recovery blocked): " - "Resource-X gate fenced"))); + ereport(LOG, (errmsg_internal("cluster PCM-X runtime fail-closed (recovery blocked): " + "Resource-X gate fenced"))); } static void @@ -9476,8 +9115,7 @@ gcs_block_resource_x_put_u64(uint8 *out, uint64 value) } static uint32 -gcs_block_pcm_x_resource_x_dependency_crc( - const uint64 dependencies[RESOURCE_X_DEPENDENCY_MAX]) +gcs_block_pcm_x_resource_x_dependency_crc(const uint64 dependencies[RESOURCE_X_DEPENDENCY_MAX]) { uint8 canonical[RESOURCE_X_DEPENDENCY_VECTOR_BYTES]; pg_crc32c crc; @@ -9485,8 +9123,7 @@ gcs_block_pcm_x_resource_x_dependency_crc( memset(canonical, 0, sizeof(canonical)); for (i = 0; i < RESOURCE_X_DEPENDENCY_MAX; i++) - gcs_block_resource_x_put_u64(canonical + i * 8, - dependencies[i]); + gcs_block_resource_x_put_u64(canonical + i * 8, dependencies[i]); INIT_CRC32C(crc); COMP_CRC32C(crc, canonical, sizeof(canonical)); FIN_CRC32C(crc); @@ -9497,50 +9134,33 @@ gcs_block_pcm_x_resource_x_dependency_crc( * reads. The fixed big-endian record is process-local evidence, not a new * wire ABI; AuthorityGrant carries only its exact CRC and bound fields. */ static uint32 -gcs_block_pcm_x_resource_x_durable_proof_crc( - const ResourceXDurableProof *proof) +gcs_block_pcm_x_resource_x_durable_proof_crc(const ResourceXDurableProof *proof) { uint8 canonical[96]; pg_crc32c crc; - if (proof == NULL - || !resource_x_assertion_valid(&proof->assertion) - || proof->base_authority_generation == 0 - || proof->resource_formation == 0 - || proof->master_session_incarnation == 0 - || proof->assertion_sequence == 0 + if (proof == NULL || !resource_x_assertion_valid(&proof->assertion) + || proof->base_authority_generation == 0 || proof->resource_formation == 0 + || proof->master_session_incarnation == 0 || proof->assertion_sequence == 0 || proof->requester_target_generation == 0) return 0; memset(canonical, 0, sizeof(canonical)); gcs_block_resource_x_put_u32(canonical, UINT32_C(0x52584450)); /* RXDP */ canonical[5] = 1; canonical[7] = (uint8)sizeof(canonical); - gcs_block_resource_x_put_u32(canonical + 8, - proof->assertion.resource.spcOid); - gcs_block_resource_x_put_u32(canonical + 12, - proof->assertion.resource.dbOid); - gcs_block_resource_x_put_u32(canonical + 16, - proof->assertion.resource.relNumber); - gcs_block_resource_x_put_u32(canonical + 20, - (uint32)proof->assertion.resource.forkNum); - gcs_block_resource_x_put_u32(canonical + 24, - proof->assertion.resource.blockNum); - gcs_block_resource_x_put_u32(canonical + 28, - (uint32)proof->assertion.requester_node); - gcs_block_resource_x_put_u64(canonical + 32, - proof->base_authority_generation); - gcs_block_resource_x_put_u64(canonical + 40, - proof->resource_formation); - gcs_block_resource_x_put_u64(canonical + 48, - proof->master_session_incarnation); - gcs_block_resource_x_put_u64(canonical + 56, - proof->assertion_sequence); - gcs_block_resource_x_put_u64(canonical + 64, - proof->requester_target_generation); - gcs_block_resource_x_put_u64(canonical + 72, - proof->page_scn_lsn); - gcs_block_resource_x_put_u32(canonical + 80, - proof->page_checksum); + gcs_block_resource_x_put_u32(canonical + 8, proof->assertion.resource.spcOid); + gcs_block_resource_x_put_u32(canonical + 12, proof->assertion.resource.dbOid); + gcs_block_resource_x_put_u32(canonical + 16, proof->assertion.resource.relNumber); + gcs_block_resource_x_put_u32(canonical + 20, (uint32)proof->assertion.resource.forkNum); + gcs_block_resource_x_put_u32(canonical + 24, proof->assertion.resource.blockNum); + gcs_block_resource_x_put_u32(canonical + 28, (uint32)proof->assertion.requester_node); + gcs_block_resource_x_put_u64(canonical + 32, proof->base_authority_generation); + gcs_block_resource_x_put_u64(canonical + 40, proof->resource_formation); + gcs_block_resource_x_put_u64(canonical + 48, proof->master_session_incarnation); + gcs_block_resource_x_put_u64(canonical + 56, proof->assertion_sequence); + gcs_block_resource_x_put_u64(canonical + 64, proof->requester_target_generation); + gcs_block_resource_x_put_u64(canonical + 72, proof->page_scn_lsn); + gcs_block_resource_x_put_u32(canonical + 80, proof->page_checksum); canonical[86] = RESOURCE_X_PROOF_DURABLE_STORAGE; canonical[87] = RESOURCE_X_DISPOSITION_DURABLE_STORAGE; INIT_CRC32C(crc); @@ -9553,9 +9173,8 @@ gcs_block_pcm_x_resource_x_durable_proof_crc( * share one DATA FIFO when LOCAL_PROOF exists. A clean N requester sends * ASSERT_X only and leaves proof selection to the exact no-holder master. */ static ResourceXApplyResult -gcs_block_resource_x_assert_stage_exact( - int32 master_node, const ResourceXDecodedFrame *assertion, - const ResourceXDecodedFrame *local_proof) +gcs_block_resource_x_assert_stage_exact(int32 master_node, const ResourceXDecodedFrame *assertion, + const ResourceXDecodedFrame *local_proof) { uint8 assertion_payload[RESOURCE_X_CONTROL_V1_BYTES]; uint8 proof_payload[RESOURCE_X_SHORT_V1_BYTES]; @@ -9563,29 +9182,25 @@ gcs_block_resource_x_assert_stage_exact( uint16 assertion_bytes = 0; uint16 proof_bytes = 0; - if (master_node < 0 || master_node >= RESOURCE_X_PROTOCOL_NODE_LIMIT - || assertion == NULL - || !cluster_resource_x_wire_encode( - RESOURCE_X_MSG_ASSERT_X, assertion, assertion_payload, - sizeof(assertion_payload), &assertion_bytes, &reject) + if (master_node < 0 || master_node >= RESOURCE_X_PROTOCOL_NODE_LIMIT || assertion == NULL + || !cluster_resource_x_wire_encode(RESOURCE_X_MSG_ASSERT_X, assertion, assertion_payload, + sizeof(assertion_payload), &assertion_bytes, &reject) || assertion_bytes != RESOURCE_X_CONTROL_V1_BYTES) return RESOURCE_X_APPLY_INVALID; if (local_proof != NULL - && (!cluster_resource_x_wire_encode( - RESOURCE_X_MSG_ASSERT_X, local_proof, proof_payload, - sizeof(proof_payload), &proof_bytes, &reject) + && (!cluster_resource_x_wire_encode(RESOURCE_X_MSG_ASSERT_X, local_proof, proof_payload, + sizeof(proof_payload), &proof_bytes, &reject) || proof_bytes != RESOURCE_X_SHORT_V1_BYTES)) return RESOURCE_X_APPLY_INVALID; - if (!cluster_grd_outbound_enqueue_backend_msg( - RESOURCE_X_MSG_ASSERT_X, master_node, assertion_payload, - assertion_bytes)) + if (!cluster_grd_outbound_enqueue_backend_msg(RESOURCE_X_MSG_ASSERT_X, master_node, + assertion_payload, assertion_bytes)) return RESOURCE_X_APPLY_BAD_STATE; if (local_proof == NULL) return RESOURCE_X_APPLY_APPLIED; - return cluster_grd_outbound_enqueue_backend_msg( - RESOURCE_X_MSG_ASSERT_X, master_node, proof_payload, - proof_bytes) - ? RESOURCE_X_APPLY_APPLIED : RESOURCE_X_APPLY_BAD_STATE; + return cluster_grd_outbound_enqueue_backend_msg(RESOURCE_X_MSG_ASSERT_X, master_node, + proof_payload, proof_bytes) + ? RESOURCE_X_APPLY_APPLIED + : RESOURCE_X_APPLY_BAD_STATE; } /* The kind-9 ASSERT keeps its wire-neutral observed mode, but an exact local @@ -9707,15 +9322,14 @@ gcs_block_resource_x_delivery_arm_exact(int32 master_node, const ResourceXDecode } static ResourceXApplyResult -gcs_block_resource_x_native_assert_stage_exact( - int32 master_node, const ResourceXDecodedFrame *assertion) +gcs_block_resource_x_native_assert_stage_exact(int32 master_node, + const ResourceXDecodedFrame *assertion) { PGAlignedBlock aligned_page; ClusterPcmOwnSnapshot before; ClusterPcmOwnSnapshot after; ClusterPcmOwnResult own_result; - ClusterBufmgrGcsCopyRefusal copy_refusal - = CLUSTER_BUFMGR_GCS_COPY_REFUSAL_NONE; + ClusterBufmgrGcsCopyRefusal copy_refusal = CLUSTER_BUFMGR_GCS_COPY_REFUSAL_NONE; ResourceXAcquisitionRef ref; ResourceXDecodedFrame local_proof; uint64 zero_dependencies[RESOURCE_X_DEPENDENCY_MAX] = { 0 }; @@ -9728,8 +9342,7 @@ gcs_block_resource_x_native_assert_stage_exact( int after_buffer_id = -1; ResourceXApplyResult delivery_result; - if (assertion == NULL - || assertion->kind != RESOURCE_X_WIRE_ASSERT_X + if (assertion == NULL || assertion->kind != RESOURCE_X_WIRE_ASSERT_X || assertion->common.observed_mode != (uint8)PCM_STATE_N || assertion->common.target_mode != (uint8)PCM_STATE_X) return RESOURCE_X_APPLY_INVALID; @@ -9742,75 +9355,54 @@ gcs_block_resource_x_native_assert_stage_exact( ref.acquisition_generation = assertion->common.assertion_sequence; if (cluster_pcm_lock_resource_x_bootstrap_round_direct_init_snapshot_exact( &ref, &direct_generation, &direct_token)) { - own_result - = cluster_bufmgr_pcm_own_direct_init_snapshot_by_tag_exact( - &ref.assertion.resource, direct_generation, direct_token, - &before_buffer_id, &before); + own_result = cluster_bufmgr_pcm_own_direct_init_snapshot_by_tag_exact( + &ref.assertion.resource, direct_generation, direct_token, &before_buffer_id, &before); if (own_result != CLUSTER_PCM_OWN_OK || before_buffer_id < 0) - return own_result == CLUSTER_PCM_OWN_BUSY - ? RESOURCE_X_APPLY_BAD_STATE - : own_result == CLUSTER_PCM_OWN_STALE - ? RESOURCE_X_APPLY_STALE - : RESOURCE_X_APPLY_RECOVERY_BLOCKED; + return own_result == CLUSTER_PCM_OWN_BUSY ? RESOURCE_X_APPLY_BAD_STATE + : own_result == CLUSTER_PCM_OWN_STALE ? RESOURCE_X_APPLY_STALE + : RESOURCE_X_APPLY_RECOVERY_BLOCKED; own_result = cluster_bufmgr_pcm_own_n_direct_init_candidate_exact( GetBufferDescriptor(before_buffer_id), &before); if (own_result != CLUSTER_PCM_OWN_OK) - return own_result == CLUSTER_PCM_OWN_BUSY - ? RESOURCE_X_APPLY_BAD_STATE - : own_result == CLUSTER_PCM_OWN_STALE - ? RESOURCE_X_APPLY_STALE - : RESOURCE_X_APPLY_RECOVERY_BLOCKED; - return gcs_block_resource_x_assert_stage_exact( - master_node, assertion, NULL); + return own_result == CLUSTER_PCM_OWN_BUSY ? RESOURCE_X_APPLY_BAD_STATE + : own_result == CLUSTER_PCM_OWN_STALE ? RESOURCE_X_APPLY_STALE + : RESOURCE_X_APPLY_RECOVERY_BLOCKED; + return gcs_block_resource_x_assert_stage_exact(master_node, assertion, NULL); } own_result = cluster_bufmgr_pcm_own_snapshot_by_tag( - &assertion->common.logical_assertion.resource, - &before_buffer_id, &before); + &assertion->common.logical_assertion.resource, &before_buffer_id, &before); if (own_result != CLUSTER_PCM_OWN_OK || before_buffer_id < 0) - return own_result == CLUSTER_PCM_OWN_BUSY - ? RESOURCE_X_APPLY_BAD_STATE - : own_result == CLUSTER_PCM_OWN_STALE - ? RESOURCE_X_APPLY_STALE - : RESOURCE_X_APPLY_RECOVERY_BLOCKED; - if (!BufferTagsEqual(&before.tag, - &assertion->common.logical_assertion.resource) - || before.flags != 0 - || before.writer_activation_token != 0 - || before.resource_x_activation_generation != 0 - || before.generation == UINT64_MAX) + return own_result == CLUSTER_PCM_OWN_BUSY ? RESOURCE_X_APPLY_BAD_STATE + : own_result == CLUSTER_PCM_OWN_STALE ? RESOURCE_X_APPLY_STALE + : RESOURCE_X_APPLY_RECOVERY_BLOCKED; + if (!BufferTagsEqual(&before.tag, &assertion->common.logical_assertion.resource) + || before.flags != 0 || before.writer_activation_token != 0 + || before.resource_x_activation_generation != 0 || before.generation == UINT64_MAX) return RESOURCE_X_APPLY_STALE; if (before.pcm_state == (uint8)PCM_STATE_N) { own_result = cluster_bufmgr_pcm_own_n_assertion_candidate_exact( GetBufferDescriptor(before_buffer_id), &before, NULL); if (own_result != CLUSTER_PCM_OWN_OK) - return own_result == CLUSTER_PCM_OWN_BUSY - ? RESOURCE_X_APPLY_BAD_STATE - : own_result == CLUSTER_PCM_OWN_STALE - ? RESOURCE_X_APPLY_STALE - : RESOURCE_X_APPLY_RECOVERY_BLOCKED; - return gcs_block_resource_x_assert_stage_exact( - master_node, assertion, NULL); + return own_result == CLUSTER_PCM_OWN_BUSY ? RESOURCE_X_APPLY_BAD_STATE + : own_result == CLUSTER_PCM_OWN_STALE ? RESOURCE_X_APPLY_STALE + : RESOURCE_X_APPLY_RECOVERY_BLOCKED; + return gcs_block_resource_x_assert_stage_exact(master_node, assertion, NULL); } if (before.generation == 0 - || (before.pcm_state != (uint8)PCM_STATE_S - && before.pcm_state != (uint8)PCM_STATE_X)) + || (before.pcm_state != (uint8)PCM_STATE_S && before.pcm_state != (uint8)PCM_STATE_X)) return RESOURCE_X_APPLY_STALE; - if (!cluster_bufmgr_copy_block_for_r4_cr( - before.tag, InvalidScn, &page_lsn, &page_scn, - aligned_page.data, ©_refusal)) + if (!cluster_bufmgr_copy_block_for_r4_cr(before.tag, InvalidScn, &page_lsn, &page_scn, + aligned_page.data, ©_refusal)) return RESOURCE_X_APPLY_BAD_STATE; own_result = cluster_bufmgr_pcm_own_snapshot_by_tag( - &assertion->common.logical_assertion.resource, - &after_buffer_id, &after); - if (own_result != CLUSTER_PCM_OWN_OK - || before_buffer_id != after_buffer_id + &assertion->common.logical_assertion.resource, &after_buffer_id, &after); + if (own_result != CLUSTER_PCM_OWN_OK || before_buffer_id != after_buffer_id || memcmp(&before, &after, sizeof(before)) != 0 || PageGetLSN((Page)aligned_page.data) != page_lsn || ((PageHeader)aligned_page.data)->pd_block_scn != page_scn) - return own_result == CLUSTER_PCM_OWN_CORRUPT - ? RESOURCE_X_APPLY_RECOVERY_BLOCKED - : RESOURCE_X_APPLY_BAD_STATE; + return own_result == CLUSTER_PCM_OWN_CORRUPT ? RESOURCE_X_APPLY_RECOVERY_BLOCKED + : RESOURCE_X_APPLY_BAD_STATE; page_checksum = cluster_gcs_block_compute_checksum(aligned_page.data); memset(&local_proof, 0, sizeof(local_proof)); local_proof.kind = RESOURCE_X_WIRE_LOCAL_PROOF_DECLARATION; @@ -9818,10 +9410,8 @@ gcs_block_resource_x_native_assert_stage_exact( local_proof.common = assertion->common; local_proof.common.observed_mode = before.pcm_state; local_proof.common.outcome = RESOURCE_X_OUTCOME_OK; - local_proof.body.local_proof.local_holder_authority_generation - = before.generation; - local_proof.body.local_proof.requester_target_generation - = assertion->common.assertion_sequence; + local_proof.body.local_proof.local_holder_authority_generation = before.generation; + local_proof.body.local_proof.requester_target_generation = assertion->common.assertion_sequence; local_proof.body.local_proof.page_scn_lsn = (uint64)page_scn; local_proof.body.local_proof.dependency_count = 0; local_proof.body.local_proof.dependency_vector_crc32c @@ -9831,16 +9421,15 @@ gcs_block_resource_x_native_assert_stage_exact( local_proof.body.local_proof.requester_connection_generation = assertion->common.sender_connection_generation; local_proof.body.local_proof.local_proof_generation = before.generation; - return gcs_block_resource_x_assert_stage_exact( - master_node, assertion, &local_proof); + return gcs_block_resource_x_assert_stage_exact(master_node, assertion, &local_proof); } /* PGRAC adaptation: requester round extraction has already released the * resource entry lock. Encode and stage the type-14 bootstrap request only * from that frozen copy. */ static bool -gcs_block_resource_x_bootstrap_request_stage_exact( - int32 master_node, const ResourceXDecodedFrame *request) +gcs_block_resource_x_bootstrap_request_stage_exact(int32 master_node, + const ResourceXDecodedFrame *request) { uint8 payload[RESOURCE_X_CONTROL_V1_BYTES]; ResourceXWireReject reject = RESOURCE_X_WIRE_REJECT_NONE; @@ -9852,33 +9441,28 @@ gcs_block_resource_x_bootstrap_request_stage_exact( sizeof(payload), &payload_bytes, &reject) || payload_bytes != RESOURCE_X_CONTROL_V1_BYTES) return false; - return cluster_grd_outbound_enqueue_backend_msg( - RESOURCE_X_MSG_ASSERT_X, (uint32)master_node, payload, - payload_bytes); + return cluster_grd_outbound_enqueue_backend_msg(RESOURCE_X_MSG_ASSERT_X, (uint32)master_node, + payload, payload_bytes); } /* PGRAC adaptation: the master receipt API has already copied the exact ACK * semantic snapshot and released the resource entry lock. Only then may the * DATA-plane producer encode and enqueue the existing type-15 frame. */ static bool -gcs_block_resource_x_bootstrap_ack_stage_exact( - int32 requester_node, const ResourceXDecodedFrame *ack) +gcs_block_resource_x_bootstrap_ack_stage_exact(int32 requester_node, + const ResourceXDecodedFrame *ack) { uint8 payload[RESOURCE_X_CONTROL_V1_BYTES]; ResourceXWireReject reject = RESOURCE_X_WIRE_REJECT_NONE; uint16 payload_bytes = 0; - if (requester_node < 0 - || requester_node >= RESOURCE_X_PROTOCOL_NODE_LIMIT - || ack == NULL - || !cluster_resource_x_wire_encode( - RESOURCE_X_MSG_IMAGE_OR_GRANT, ack, payload, sizeof(payload), - &payload_bytes, &reject) + if (requester_node < 0 || requester_node >= RESOURCE_X_PROTOCOL_NODE_LIMIT || ack == NULL + || !cluster_resource_x_wire_encode(RESOURCE_X_MSG_IMAGE_OR_GRANT, ack, payload, + sizeof(payload), &payload_bytes, &reject) || payload_bytes != RESOURCE_X_CONTROL_V1_BYTES) return false; - return cluster_grd_outbound_enqueue_backend_msg( - RESOURCE_X_MSG_IMAGE_OR_GRANT, (uint32)requester_node, payload, - payload_bytes); + return cluster_grd_outbound_enqueue_backend_msg(RESOURCE_X_MSG_IMAGE_OR_GRANT, + (uint32)requester_node, payload, payload_bytes); } /* A READY probe is still only pre-T1 semantic evidence. Ownership mutation @@ -9889,12 +9473,10 @@ gcs_block_resource_x_bootstrap_ack_stage_exact( * exact assertion sequence, with no ASSERT_X/BLOCK_TO_N ABI extension. */ static bool gcs_block_pcm_x_resource_x_build_source_frames( - const ResourceXDecodedFrame *block, - const ClusterPcmOwnSnapshot *revoking, const char page_bytes[BLCKSZ], - XLogRecPtr page_lsn, uint64 page_scn, uint32 requester_connection_generation, - uint64 source_boot_incarnation, uint8 source_mode, - ResourceXDecodedFrame *status, - ResourceXDecodedFrame *image) + const ResourceXDecodedFrame *block, const ClusterPcmOwnSnapshot *revoking, + const char page_bytes[BLCKSZ], XLogRecPtr page_lsn, uint64 page_scn, + uint32 requester_connection_generation, uint64 source_boot_incarnation, uint8 source_mode, + ResourceXDecodedFrame *status, ResourceXDecodedFrame *image) { ResourceXDecodedFrame canonical_image; ResourceXDecodedBlockedToN *blocked_body; @@ -9904,18 +9486,12 @@ gcs_block_pcm_x_resource_x_build_source_frames( uint16 encoded_bytes = 0; uint64 source_carrier_generation; - if (block == NULL || revoking == NULL || page_bytes == NULL - || status == NULL || image == NULL - || requester_connection_generation == 0 - || source_boot_incarnation == 0 - || revoking->generation == 0 - || revoking->generation == UINT64_MAX - || revoking->reservation_token == 0 - || revoking->flags != PCM_OWN_FLAG_REVOKING - || (source_mode != (uint8)PCM_STATE_X - && source_mode != (uint8)PCM_STATE_S) - || revoking->pcm_state != source_mode - || PageGetLSN((Page)page_bytes) != page_lsn) + if (block == NULL || revoking == NULL || page_bytes == NULL || status == NULL || image == NULL + || requester_connection_generation == 0 || source_boot_incarnation == 0 + || revoking->generation == 0 || revoking->generation == UINT64_MAX + || revoking->reservation_token == 0 || revoking->flags != PCM_OWN_FLAG_REVOKING + || (source_mode != (uint8)PCM_STATE_X && source_mode != (uint8)PCM_STATE_S) + || revoking->pcm_state != source_mode || PageGetLSN((Page)page_bytes) != page_lsn) return false; source_carrier_generation = revoking->generation + 1; memset(status, 0, sizeof(*status)); @@ -9924,14 +9500,12 @@ gcs_block_pcm_x_resource_x_build_source_frames( image->kind = RESOURCE_X_WIRE_IMAGE_ENVELOPE; image->payload_bytes = RESOURCE_X_IMAGE_V1_BYTES; image->common = block->common; - image->common.action_node - = block->common.logical_assertion.requester_node; + image->common.action_node = block->common.logical_assertion.requester_node; image->common.observed_mode = source_mode; image->common.target_mode = (uint8)PCM_STATE_X; image->common.source_candidate = 0; image->common.retain_pi_if_dirty = 0; - image->common.sender_connection_generation - = requester_connection_generation; + image->common.sender_connection_generation = requester_connection_generation; image->common.outcome = RESOURCE_X_OUTCOME_OK; image->common.flags = block->common.flags; image->common.authority_generation @@ -9939,20 +9513,14 @@ gcs_block_pcm_x_resource_x_build_source_frames( ? block->common.authority_generation : block->common.base_authority_generation + 1; image_body = &image->body.image_envelope; - gcs_block_resource_x_put_u64(image_body->request_tail, - (uint64)requester_connection_generation); - gcs_block_resource_x_put_u64(image_body->request_tail + 8, - block->common.assertion_sequence); - image_body->conversion_base_generation - = block->common.base_authority_generation; - gcs_block_resource_x_put_u32(image_body->source_fence, - (uint32)cluster_node_id); - gcs_block_resource_x_put_u64(image_body->source_fence + 4, - source_boot_incarnation); + gcs_block_resource_x_put_u64(image_body->request_tail, (uint64)requester_connection_generation); + gcs_block_resource_x_put_u64(image_body->request_tail + 8, block->common.assertion_sequence); + image_body->conversion_base_generation = block->common.base_authority_generation; + gcs_block_resource_x_put_u32(image_body->source_fence, (uint32)cluster_node_id); + gcs_block_resource_x_put_u64(image_body->source_fence + 4, source_boot_incarnation); gcs_block_resource_x_put_u64(image_body->source_fence + 12, - (uint64)requester_connection_generation); - gcs_block_resource_x_put_u64(image_body->source_fence + 20, - revoking->generation); + (uint64)requester_connection_generation); + gcs_block_resource_x_put_u64(image_body->source_fence + 20, revoking->generation); image_body->source_fence[28] = source_mode; image_body->source_fence[29] = 1; image_body->source_carrier_generation = source_carrier_generation; @@ -9960,22 +9528,17 @@ gcs_block_pcm_x_resource_x_build_source_frames( image_body->page_scn_lsn = page_scn; image_body->dependency_count = 0; image_body->dependency_vector_crc32c - = gcs_block_pcm_x_resource_x_dependency_crc( - image_body->dependencies); - image_body->page_checksum - = cluster_gcs_block_compute_checksum(page_bytes); + = gcs_block_pcm_x_resource_x_dependency_crc(image_body->dependencies); + image_body->page_checksum = cluster_gcs_block_compute_checksum(page_bytes); image_body->image_length = BLCKSZ; - image_body->source_disposition - = RESOURCE_X_DISPOSITION_REMOTE_NONWRITABLE; + image_body->source_disposition = RESOURCE_X_DISPOSITION_REMOTE_NONWRITABLE; image_body->proof_kind = RESOURCE_X_PROOF_REMOTE_CARRIER; memcpy(image_body->page_bytes, page_bytes, BLCKSZ); - if (!cluster_resource_x_wire_encode( - RESOURCE_X_MSG_IMAGE_OR_GRANT, image, encoded_image, - sizeof(encoded_image), &encoded_bytes, &reject) + if (!cluster_resource_x_wire_encode(RESOURCE_X_MSG_IMAGE_OR_GRANT, image, encoded_image, + sizeof(encoded_image), &encoded_bytes, &reject) || encoded_bytes != RESOURCE_X_IMAGE_V1_BYTES - || !cluster_resource_x_wire_decode( - RESOURCE_X_MSG_IMAGE_OR_GRANT, encoded_image, encoded_bytes, - &canonical_image, &reject) + || !cluster_resource_x_wire_decode(RESOURCE_X_MSG_IMAGE_OR_GRANT, encoded_image, + encoded_bytes, &canonical_image, &reject) || canonical_image.kind != RESOURCE_X_WIRE_IMAGE_ENVELOPE || canonical_image.common.semantic_crc32c == 0) return false; @@ -9991,40 +9554,33 @@ gcs_block_pcm_x_resource_x_build_source_frames( status->common.retain_pi_if_dirty = 0; status->common.outcome = RESOURCE_X_OUTCOME_OK; status->common.flags = RESOURCE_X_COMMON_FLAG_PI_ESTABLISHED; - status->common.authority_generation - = block->common.base_authority_generation; + status->common.authority_generation = block->common.base_authority_generation; blocked_body = &status->body.blocked_to_n; memcpy(blocked_body->source_fence, image_body->source_fence, - sizeof(blocked_body->source_fence)); - blocked_body->source_carrier_generation - = image_body->source_carrier_generation; + sizeof(blocked_body->source_fence)); + blocked_body->source_carrier_generation = image_body->source_carrier_generation; blocked_body->requester_target_generation = block->common.assertion_sequence; blocked_body->page_scn_lsn = image_body->page_scn_lsn; blocked_body->dependency_count = image_body->dependency_count; memcpy(blocked_body->dependencies, image_body->dependencies, - sizeof(blocked_body->dependencies)); + sizeof(blocked_body->dependencies)); blocked_body->source_proof_crc32c = image->common.semantic_crc32c; blocked_body->page_checksum = image_body->page_checksum; - blocked_body->source_disposition - = RESOURCE_X_DISPOSITION_REMOTE_NONWRITABLE; + blocked_body->source_disposition = RESOURCE_X_DISPOSITION_REMOTE_NONWRITABLE; blocked_body->proof_kind = RESOURCE_X_PROOF_REMOTE_CARRIER; - blocked_body->holder_connection_generation - = block->common.sender_connection_generation; + blocked_body->holder_connection_generation = block->common.sender_connection_generation; blocked_body->acting_formation = block->common.resource_formation; return true; } static bool -gcs_block_pcm_x_resource_x_abort_pre_arm( - BufferDesc *buf, const ClusterPcmOwnSnapshot *revoking) +gcs_block_pcm_x_resource_x_abort_pre_arm(BufferDesc *buf, const ClusterPcmOwnSnapshot *revoking) { ClusterPcmOwnResult abort_result; - if (revoking != NULL - && revoking->pcm_state == (uint8)PCM_STATE_S) + if (revoking != NULL && revoking->pcm_state == (uint8)PCM_STATE_S) abort_result = cluster_bufmgr_pcm_own_abort_s_revoke(buf, revoking); - else if (revoking != NULL - && revoking->pcm_state == (uint8)PCM_STATE_X) + else if (revoking != NULL && revoking->pcm_state == (uint8)PCM_STATE_X) abort_result = cluster_bufmgr_pcm_own_abort_x_revoke(buf, revoking); else abort_result = CLUSTER_PCM_OWN_CORRUPT; @@ -10036,15 +9592,13 @@ gcs_block_pcm_x_resource_x_abort_pre_arm( } static bool -gcs_block_resource_x_terminal_owner_release( - ResourceXLocalOwnerHandle *handle, bool *held) +gcs_block_resource_x_terminal_owner_release(ResourceXLocalOwnerHandle *handle, bool *held) { ResourceXApplyResult result; if (held == NULL || !*held) return true; - result = cluster_pcm_lock_resource_x_terminal_x_revoke_release_exact( - handle); + result = cluster_pcm_lock_resource_x_terminal_x_revoke_release_exact(handle); if (result != RESOURCE_X_APPLY_APPLIED) { gcs_block_resource_x_fail_closed_current(); return false; @@ -10266,9 +9820,9 @@ gcs_block_resource_x_source_finish_owned( } static ResourceXApplyResult -gcs_block_pcm_x_resource_x_source_block_to_n( - const ResourceXDecodedFrame *block, int32 authenticated_master_node, - uint64 r4_record_generation) +gcs_block_pcm_x_resource_x_source_block_to_n(const ResourceXDecodedFrame *block, + int32 authenticated_master_node, + uint64 r4_record_generation) { PGAlignedBlock aligned_page; BufferDesc *buf; @@ -10281,8 +9835,7 @@ gcs_block_pcm_x_resource_x_source_block_to_n( ResourceXLocalOwnerHandle target_revoke_owner; ResourceXTerminalXLineage lineage; ResourceXTerminalXLineage revalidated_lineage; - ClusterPcmXRevokeFinishMode target_x_finish_mode - = CLUSTER_PCM_X_REVOKE_FINISH_INVALID; + ClusterPcmXRevokeFinishMode target_x_finish_mode = CLUSTER_PCM_X_REVOKE_FINISH_INVALID; PcmXSessionAuthResult session_result; ResourceXApplyResult gate_result; ResourceXApplyResult failure_result = RESOURCE_X_APPLY_RECOVERY_BLOCKED; @@ -10329,10 +9882,8 @@ gcs_block_pcm_x_resource_x_source_block_to_n( source_mode = block->common.observed_mode; shared_s_source = source_mode == (uint8)PCM_STATE_S; if (block->kind != RESOURCE_X_WIRE_BLOCK_TO_N - || (source_mode != (uint8)PCM_STATE_X - && source_mode != (uint8)PCM_STATE_S) - || block->common.target_mode != (uint8)PCM_STATE_N - || block->common.source_candidate != 1 + || (source_mode != (uint8)PCM_STATE_X && source_mode != (uint8)PCM_STATE_S) + || block->common.target_mode != (uint8)PCM_STATE_N || block->common.source_candidate != 1 || block->common.retain_pi_if_dirty != 1 || block->common.outcome != RESOURCE_X_OUTCOME_NONE) return RESOURCE_X_APPLY_INVALID; @@ -10367,7 +9918,8 @@ gcs_block_pcm_x_resource_x_source_block_to_n( if (image_result != RESOURCE_X_APPLY_APPLIED) { failure_stage = "retained-image"; failure_result = image_result == RESOURCE_X_APPLY_NOT_FOUND - ? RESOURCE_X_APPLY_RECOVERY_BLOCKED : image_result; + ? RESOURCE_X_APPLY_RECOVERY_BLOCKED + : image_result; goto pre_retained_failure; } /* The retained pair's monotonic publication witness separates an exact @@ -10391,12 +9943,10 @@ gcs_block_pcm_x_resource_x_source_block_to_n( goto pre_retained_failure; } } else if (status_result != RESOURCE_X_APPLY_NOT_FOUND - && status_result != RESOURCE_X_APPLY_STALE) + && status_result != RESOURCE_X_APPLY_STALE) return status_result; - writer_path = cluster_resource_x_writer_path_snapshot( - &writer_r4_generation); - if (writer_path != RESOURCE_X_WRITER_TARGET - || writer_r4_generation == 0 + writer_path = cluster_resource_x_writer_path_snapshot(&writer_r4_generation); + if (writer_path != RESOURCE_X_WRITER_TARGET || writer_r4_generation == 0 || writer_r4_generation == UINT64_MAX) { failure_stage = "writer-path"; failure_result = RESOURCE_X_APPLY_RECOVERY_BLOCKED; @@ -10404,13 +9954,10 @@ gcs_block_pcm_x_resource_x_source_block_to_n( } tagless_target_x = source_mode == (uint8)PCM_STATE_X; if (tagless_target_x) { - target_x_finish_mode = - cluster_pcm_x_revoke_finish_mode( - &block->common.logical_assertion.resource, 0); - target_x_retain = target_x_finish_mode - == CLUSTER_PCM_X_REVOKE_FINISH_RETAIN; - target_x_drop = target_x_finish_mode - == CLUSTER_PCM_X_REVOKE_FINISH_DROP; + target_x_finish_mode + = cluster_pcm_x_revoke_finish_mode(&block->common.logical_assertion.resource, 0); + target_x_retain = target_x_finish_mode == CLUSTER_PCM_X_REVOKE_FINISH_RETAIN; + target_x_drop = target_x_finish_mode == CLUSTER_PCM_X_REVOKE_FINISH_DROP; if (!target_x_retain && !target_x_drop) { failure_stage = "target-x-finish-mode"; failure_result = RESOURCE_X_APPLY_RECOVERY_BLOCKED; @@ -10419,15 +9966,15 @@ gcs_block_pcm_x_resource_x_source_block_to_n( } failure_stage = "own-snapshot"; - own_result = cluster_bufmgr_pcm_own_snapshot_by_tag( - &block->common.logical_assertion.resource, &buffer_id, ¤t); + own_result = cluster_bufmgr_pcm_own_snapshot_by_tag(&block->common.logical_assertion.resource, + &buffer_id, ¤t); if (own_result != CLUSTER_PCM_OWN_OK || buffer_id < 0) { if (semantic_retained) { gcs_block_resource_x_fail_closed_current(); return RESOURCE_X_APPLY_RECOVERY_BLOCKED; } - failure_result = own_result == CLUSTER_PCM_OWN_BUSY - ? RESOURCE_X_APPLY_BAD_STATE : RESOURCE_X_APPLY_RECOVERY_BLOCKED; + failure_result = own_result == CLUSTER_PCM_OWN_BUSY ? RESOURCE_X_APPLY_BAD_STATE + : RESOURCE_X_APPLY_RECOVERY_BLOCKED; goto pre_retained_failure; } buf = GetBufferDescriptor(buffer_id); @@ -10436,22 +9983,19 @@ gcs_block_pcm_x_resource_x_source_block_to_n( if (semantic_retained) { if (image.body.image_envelope.source_carrier_generation == 0) return RESOURCE_X_APPLY_RECOVERY_BLOCKED; - terminal_holder_generation - = image.body.image_envelope.source_carrier_generation - 1; + terminal_holder_generation = image.body.image_envelope.source_carrier_generation - 1; } else terminal_holder_generation = current.generation; if (!cluster_pcm_lock_resource_x_bootstrap_round_terminal_holder_exact( - block, resource_master_node, writer_r4_generation, - terminal_holder_generation, &lineage)) { + block, resource_master_node, writer_r4_generation, terminal_holder_generation, + &lineage)) { failure_result = RESOURCE_X_APPLY_STALE; goto pre_retained_failure; } } if (semantic_retained) { - if (current.pcm_state == (uint8)PCM_STATE_N - && current.flags == PCM_OWN_FLAG_REVOKING - && current.generation - == image.body.image_envelope.source_carrier_generation) + if (current.pcm_state == (uint8)PCM_STATE_N && current.flags == PCM_OWN_FLAG_REVOKING + && current.generation == image.body.image_envelope.source_carrier_generation) finish_required = false; else if (current.generation > image.body.image_envelope.source_carrier_generation) { /* The exact old carrier has already finished and a later local @@ -10459,12 +10003,10 @@ gcs_block_pcm_x_resource_x_source_block_to_n( * the retained pair below; never apply the old revoke to current X. */ carrier_superseded = true; finish_required = false; - } - else if (current.pcm_state != source_mode - || current.flags != PCM_OWN_FLAG_REVOKING - || current.generation == UINT64_MAX - || current.generation + 1 - != image.body.image_envelope.source_carrier_generation) { + } else if (current.pcm_state != source_mode || current.flags != PCM_OWN_FLAG_REVOKING + || current.generation == UINT64_MAX + || current.generation + 1 + != image.body.image_envelope.source_carrier_generation) { gcs_block_resource_x_fail_closed_current(); return RESOURCE_X_APPLY_RECOVERY_BLOCKED; } else { @@ -10472,14 +10014,10 @@ gcs_block_pcm_x_resource_x_source_block_to_n( * or exact DEFERRED owner keeps it; only the LMS claim can transfer * its release obligation. Same-successor replay is owned wait. */ if (tagless_target_x) { - memset(&revalidated_lineage, 0, - sizeof(revalidated_lineage)); - replay_result - = cluster_pcm_lock_resource_x_terminal_x_revoke_replay_exact( - block, resource_master_node, writer_r4_generation, - terminal_holder_generation, - gcs_block_pcm_x_monotonic_us(), - &revalidated_lineage); + memset(&revalidated_lineage, 0, sizeof(revalidated_lineage)); + replay_result = cluster_pcm_lock_resource_x_terminal_x_revoke_replay_exact( + block, resource_master_node, writer_r4_generation, terminal_holder_generation, + gcs_block_pcm_x_monotonic_us(), &revalidated_lineage); if (replay_result == RESOURCE_X_APPLY_BAD_STATE) return RESOURCE_X_APPLY_BAD_STATE; if (replay_result == RESOURCE_X_APPLY_STALE) @@ -10519,23 +10057,22 @@ gcs_block_pcm_x_resource_x_source_block_to_n( return RESOURCE_X_APPLY_RECOVERY_BLOCKED; } revoking = current; - page_lsn = PageGetLSN( - (Page)image.body.image_envelope.page_bytes); + page_lsn = PageGetLSN((Page)image.body.image_envelope.page_bytes); page_scn = image.body.image_envelope.page_scn_lsn; } } else { - if (current.pcm_state != source_mode || current.flags != 0 - || current.generation == 0 || current.generation == UINT64_MAX + if (current.pcm_state != source_mode || current.flags != 0 || current.generation == 0 + || current.generation == UINT64_MAX || block->common.base_authority_generation == UINT64_MAX || block->common.logical_assertion.requester_node == cluster_node_id) { failure_result = RESOURCE_X_APPLY_BAD_STATE; goto pre_retained_failure; } failure_stage = "source-peer"; - if (!cluster_sf_peer_capability_word_sample( - block->common.logical_assertion.requester_node, - PGRAC_IC_HELLO_CAP_GCS_RESOURCE_X_CONVERT_V1, - &capability_word, &requester_connection_generation)) { + if (!cluster_sf_peer_capability_word_sample(block->common.logical_assertion.requester_node, + PGRAC_IC_HELLO_CAP_GCS_RESOURCE_X_CONVERT_V1, + &capability_word, + &requester_connection_generation)) { failure_result = RESOURCE_X_APPLY_BAD_STATE; goto pre_retained_failure; } @@ -10557,63 +10094,48 @@ gcs_block_pcm_x_resource_x_source_block_to_n( failure_stage = "source-prepare"; if (shared_s_source) own_result = cluster_bufmgr_pcm_own_prepare_s_source_image( - buf, ¤t, (SCN)0, &revoking, aligned_page.data, - &page_lsn, &page_scn, &source_prepare_refusal); + buf, ¤t, (SCN)0, &revoking, aligned_page.data, &page_lsn, &page_scn, + &source_prepare_refusal); else if (tagless_target_x) { ResourceXApplyResult owner_result; failure_stage = "terminal-owner-claim"; - event_owner_identity - = cluster_gcs_resource_x_event_owner_identity( - MyProc != NULL ? (int32)MyProc->pgprocno : -1, - (int32)getpid()); + event_owner_identity = cluster_gcs_resource_x_event_owner_identity( + MyProc != NULL ? (int32)MyProc->pgprocno : -1, (int32)getpid()); if (event_owner_identity < 0) { failure_result = RESOURCE_X_APPLY_RECOVERY_BLOCKED; goto pre_retained_failure; } - memset(&revalidated_lineage, 0, - sizeof(revalidated_lineage)); - owner_result - = cluster_pcm_lock_resource_x_terminal_x_revoke_claim_exact( - block, resource_master_node, writer_r4_generation, - terminal_holder_generation, - current.reservation_token, event_owner_identity, - gcs_block_pcm_x_monotonic_us(), - &revalidated_lineage, &target_revoke_owner); + memset(&revalidated_lineage, 0, sizeof(revalidated_lineage)); + owner_result = cluster_pcm_lock_resource_x_terminal_x_revoke_claim_exact( + block, resource_master_node, writer_r4_generation, terminal_holder_generation, + current.reservation_token, event_owner_identity, gcs_block_pcm_x_monotonic_us(), + &revalidated_lineage, &target_revoke_owner); if (owner_result == RESOURCE_X_APPLY_APPLIED) target_revoke_owner_held = true; if (owner_result != RESOURCE_X_APPLY_APPLIED - || memcmp(&lineage, &revalidated_lineage, - sizeof(lineage)) != 0) { - failure_result = owner_result - == RESOURCE_X_APPLY_BAD_STATE - ? RESOURCE_X_APPLY_BAD_STATE - : RESOURCE_X_APPLY_STALE; + || memcmp(&lineage, &revalidated_lineage, sizeof(lineage)) != 0) { + failure_result = owner_result == RESOURCE_X_APPLY_BAD_STATE + ? RESOURCE_X_APPLY_BAD_STATE + : RESOURCE_X_APPLY_STALE; goto pre_retained_failure; } if (target_x_retain) { - own_result - = cluster_bufmgr_pcm_own_begin_x_revoke_held_by_tag( - &block->common.logical_assertion.resource, ¤t, - &held_x_revoke); + own_result = cluster_bufmgr_pcm_own_begin_x_revoke_held_by_tag( + &block->common.logical_assertion.resource, ¤t, &held_x_revoke); if (own_result == CLUSTER_PCM_OWN_OK) { revoking = held_x_revoke.revoking; held_x_revoke_active = true; } - } - else if (target_x_drop) - own_result = cluster_bufmgr_pcm_own_begin_x_revoke( - buf, ¤t, &revoking); + } else if (target_x_drop) + own_result = cluster_bufmgr_pcm_own_begin_x_revoke(buf, ¤t, &revoking); else own_result = CLUSTER_PCM_OWN_CORRUPT; - } - else - own_result = cluster_bufmgr_pcm_own_begin_x_revoke( - buf, ¤t, &revoking); + } else + own_result = cluster_bufmgr_pcm_own_begin_x_revoke(buf, ¤t, &revoking); if (own_result != CLUSTER_PCM_OWN_OK) { - failure_result = own_result == CLUSTER_PCM_OWN_BUSY - ? RESOURCE_X_APPLY_BAD_STATE - : RESOURCE_X_APPLY_RECOVERY_BLOCKED; + failure_result = own_result == CLUSTER_PCM_OWN_BUSY ? RESOURCE_X_APPLY_BAD_STATE + : RESOURCE_X_APPLY_RECOVERY_BLOCKED; goto pre_retained_failure; } revoke_started = true; @@ -10622,18 +10144,14 @@ gcs_block_pcm_x_resource_x_source_block_to_n( uint64 current_writer_generation = 0; failure_stage = "terminal-lineage-recheck"; - writer_path = cluster_resource_x_writer_path_snapshot( - ¤t_writer_generation); + writer_path = cluster_resource_x_writer_path_snapshot(¤t_writer_generation); memset(&revalidated_lineage, 0, sizeof(revalidated_lineage)); if (writer_path != RESOURCE_X_WRITER_TARGET - || current_writer_generation != writer_r4_generation - || !target_revoke_owner_held + || current_writer_generation != writer_r4_generation || !target_revoke_owner_held || !cluster_pcm_lock_resource_x_terminal_x_revoke_revalidate_held_exact( - block, resource_master_node, writer_r4_generation, - terminal_holder_generation, &target_revoke_owner, - &revalidated_lineage) - || memcmp(&lineage, &revalidated_lineage, - sizeof(lineage)) != 0) { + block, resource_master_node, writer_r4_generation, terminal_holder_generation, + &target_revoke_owner, &revalidated_lineage) + || memcmp(&lineage, &revalidated_lineage, sizeof(lineage)) != 0) { failure_result = RESOURCE_X_APPLY_STALE; goto pre_retained_failure; } @@ -10659,30 +10177,25 @@ gcs_block_pcm_x_resource_x_source_block_to_n( ResourceXApplyResult yield_result; failure_stage = "terminal-content-drain"; - own_result - = cluster_bufmgr_pcm_own_try_drain_held_x_revoke( - &held_x_revoke); + own_result = cluster_bufmgr_pcm_own_try_drain_held_x_revoke(&held_x_revoke); if (own_result == CLUSTER_PCM_OWN_BUSY) { /* Do not wait in LMON: the pre-existing content-S holder may be * waiting for this same event loop to deliver a visibility reply. * No bytes or retained intent have been published, so restore X * and return the exact observed priority to HANDOFF. */ - own_result = cluster_bufmgr_pcm_own_abort_held_x_revoke( - &held_x_revoke); + own_result = cluster_bufmgr_pcm_own_abort_held_x_revoke(&held_x_revoke); if (own_result != CLUSTER_PCM_OWN_OK) { gcs_block_resource_x_fail_closed_current(); (void)cluster_bufmgr_pcm_own_abandon_held_x_revoke_after_fail_closed( &held_x_revoke); - (void)gcs_block_resource_x_terminal_owner_release( - &target_revoke_owner, &target_revoke_owner_held); + (void)gcs_block_resource_x_terminal_owner_release(&target_revoke_owner, + &target_revoke_owner_held); return RESOURCE_X_APPLY_RECOVERY_BLOCKED; } held_x_revoke_active = false; revoke_started = false; - yield_result - = cluster_pcm_lock_resource_x_terminal_x_revoke_yield_exact( - &target_revoke_owner, - gcs_block_pcm_x_monotonic_us()); + yield_result = cluster_pcm_lock_resource_x_terminal_x_revoke_yield_exact( + &target_revoke_owner, gcs_block_pcm_x_monotonic_us()); if (yield_result != RESOURCE_X_APPLY_APPLIED) { gcs_block_resource_x_fail_closed_current(); if (target_revoke_owner_held) @@ -10691,15 +10204,14 @@ gcs_block_pcm_x_resource_x_source_block_to_n( target_revoke_owner_held = false; return RESOURCE_X_APPLY_RECOVERY_BLOCKED; } - memset(&target_revoke_owner, 0, - sizeof(target_revoke_owner)); + memset(&target_revoke_owner, 0, sizeof(target_revoke_owner)); target_revoke_owner_held = false; return RESOURCE_X_APPLY_BAD_STATE; } if (own_result != CLUSTER_PCM_OWN_OK) { failure_result = own_result == CLUSTER_PCM_OWN_STALE - ? RESOURCE_X_APPLY_STALE - : RESOURCE_X_APPLY_RECOVERY_BLOCKED; + ? RESOURCE_X_APPLY_STALE + : RESOURCE_X_APPLY_RECOVERY_BLOCKED; goto pre_retained_failure; } } @@ -10707,26 +10219,22 @@ gcs_block_pcm_x_resource_x_source_block_to_n( ResourceXApplyResult yield_result; failure_stage = "terminal-aux-pin-drain"; - own_result = cluster_bufmgr_pcm_own_try_drain_drop_x_revoke( - buf, &revoking); + own_result = cluster_bufmgr_pcm_own_try_drain_drop_x_revoke(buf, &revoking); if (own_result == CLUSTER_PCM_OWN_BUSY) { /* REVOKING already refuses every new passive VM/FSM first pin. * A nonzero refcount therefore names only predecessors. Do not * wait in DATA/LMON or publish the pair: restore exact X and yield * the existing terminal owner to the same HANDOFF identity. */ - own_result = cluster_bufmgr_pcm_own_abort_x_revoke( - buf, &revoking); + own_result = cluster_bufmgr_pcm_own_abort_x_revoke(buf, &revoking); if (own_result != CLUSTER_PCM_OWN_OK) { gcs_block_resource_x_fail_closed_current(); - (void)gcs_block_resource_x_terminal_owner_release( - &target_revoke_owner, &target_revoke_owner_held); + (void)gcs_block_resource_x_terminal_owner_release(&target_revoke_owner, + &target_revoke_owner_held); return RESOURCE_X_APPLY_RECOVERY_BLOCKED; } revoke_started = false; - yield_result - = cluster_pcm_lock_resource_x_terminal_x_revoke_yield_exact( - &target_revoke_owner, - gcs_block_pcm_x_monotonic_us()); + yield_result = cluster_pcm_lock_resource_x_terminal_x_revoke_yield_exact( + &target_revoke_owner, gcs_block_pcm_x_monotonic_us()); if (yield_result != RESOURCE_X_APPLY_APPLIED) { gcs_block_resource_x_fail_closed_current(); if (target_revoke_owner_held) @@ -10735,24 +10243,22 @@ gcs_block_pcm_x_resource_x_source_block_to_n( target_revoke_owner_held = false; return RESOURCE_X_APPLY_RECOVERY_BLOCKED; } - memset(&target_revoke_owner, 0, - sizeof(target_revoke_owner)); + memset(&target_revoke_owner, 0, sizeof(target_revoke_owner)); target_revoke_owner_held = false; return RESOURCE_X_APPLY_BAD_STATE; } if (own_result != CLUSTER_PCM_OWN_OK) { failure_result = own_result == CLUSTER_PCM_OWN_STALE - ? RESOURCE_X_APPLY_STALE - : RESOURCE_X_APPLY_RECOVERY_BLOCKED; + ? RESOURCE_X_APPLY_STALE + : RESOURCE_X_APPLY_RECOVERY_BLOCKED; goto pre_retained_failure; } } if (!semantic_retained) { failure_stage = "source-copy"; if (!shared_s_source - && !cluster_bufmgr_copy_block_for_gcs( - block->common.logical_assertion.resource, &page_lsn, - aligned_page.data, NULL)) { + && !cluster_bufmgr_copy_block_for_gcs(block->common.logical_assertion.resource, + &page_lsn, aligned_page.data, NULL)) { failure_result = RESOURCE_X_APPLY_BAD_STATE; goto pre_retained_failure; } @@ -10761,9 +10267,8 @@ gcs_block_pcm_x_resource_x_source_block_to_n( failure_stage = "source-frame-build"; if (!gcs_block_pcm_x_resource_x_build_source_frames( block, &revoking, aligned_page.data, page_lsn, page_scn, - requester_connection_generation, source_boot_incarnation, - source_mode, - &status, &image)) { + requester_connection_generation, source_boot_incarnation, source_mode, &status, + &image)) { failure_result = RESOURCE_X_APPLY_RECOVERY_BLOCKED; goto pre_retained_failure; } @@ -10772,34 +10277,23 @@ gcs_block_pcm_x_resource_x_source_block_to_n( if (shared_s_source && semantic_retained && !finish_required) result = RESOURCE_X_APPLY_DUPLICATE; else if (shared_s_source) - result - = cluster_pcm_lock_resource_x_block_to_n_prepared_s_source_exact( - block, authenticated_master_node, &status, &image, &revoking, - page_lsn, page_scn, - image.body.image_envelope.page_checksum); + result = cluster_pcm_lock_resource_x_block_to_n_prepared_s_source_exact( + block, authenticated_master_node, &status, &image, &revoking, page_lsn, page_scn, + image.body.image_envelope.page_checksum); else if (tagless_target_x && target_x_drop) - result - = cluster_pcm_lock_resource_x_block_to_n_drop_x_source_exact( - block, authenticated_master_node, &status, &image, &revoking, - &target_revoke_owner); + result = cluster_pcm_lock_resource_x_block_to_n_drop_x_source_exact( + block, authenticated_master_node, &status, &image, &revoking, &target_revoke_owner); else if (tagless_target_x && target_x_retain) - result - = cluster_pcm_lock_resource_x_block_to_n_prepared_x_source_exact( - block, authenticated_master_node, &status, &image, &revoking, - &target_revoke_owner); + result = cluster_pcm_lock_resource_x_block_to_n_prepared_x_source_exact( + block, authenticated_master_node, &status, &image, &revoking, &target_revoke_owner); else result = cluster_pcm_lock_resource_x_block_to_n_source_exact( block, authenticated_master_node, &status, &image); - if (result != RESOURCE_X_APPLY_APPLIED - && result != RESOURCE_X_APPLY_DUPLICATE) { - if (semantic_retained && carrier_superseded - && result == RESOURCE_X_APPLY_STALE) { - pair_result - = cluster_pcm_lock_resource_x_holder_pair_supersedes_exact( - &block->common.logical_assertion, - block->common.assertion_sequence, - authenticated_master_node, - block->common.master_session_incarnation); + if (result != RESOURCE_X_APPLY_APPLIED && result != RESOURCE_X_APPLY_DUPLICATE) { + if (semantic_retained && carrier_superseded && result == RESOURCE_X_APPLY_STALE) { + pair_result = cluster_pcm_lock_resource_x_holder_pair_supersedes_exact( + &block->common.logical_assertion, block->common.assertion_sequence, + authenticated_master_node, block->common.master_session_incarnation); if (pair_result == RESOURCE_X_APPLY_APPLIED) { return RESOURCE_X_APPLY_STALE; } @@ -10813,19 +10307,15 @@ gcs_block_pcm_x_resource_x_source_block_to_n( } semantic_retained = true; if (!finish_required) { - pair_result - = cluster_pcm_lock_resource_x_holder_pair_publish_exact( - &block->common.logical_assertion, - block->common.assertion_sequence, - authenticated_master_node, - block->common.master_session_incarnation); - if (pair_result != RESOURCE_X_APPLY_APPLIED - && pair_result != RESOURCE_X_APPLY_DUPLICATE) { + pair_result = cluster_pcm_lock_resource_x_holder_pair_publish_exact( + &block->common.logical_assertion, block->common.assertion_sequence, + authenticated_master_node, block->common.master_session_incarnation); + if (pair_result != RESOURCE_X_APPLY_APPLIED && pair_result != RESOURCE_X_APPLY_DUPLICATE) { gcs_block_resource_x_fail_closed_current(); return RESOURCE_X_APPLY_RECOVERY_BLOCKED; } - if (!gcs_block_resource_x_terminal_owner_release( - &target_revoke_owner, &target_revoke_owner_held)) { + if (!gcs_block_resource_x_terminal_owner_release(&target_revoke_owner, + &target_revoke_owner_held)) { return RESOURCE_X_APPLY_RECOVERY_BLOCKED; } return result; @@ -10839,54 +10329,48 @@ gcs_block_pcm_x_resource_x_source_block_to_n( pre_retained_failure: ereport(LOG, (errmsg_internal("Resource-X type-17 holder diagnostic"), - errdetail("stage=%s result=%d requester=%d master=%d source=%d " - "attempt=%llu base=%llu formation=%llu session=%llu " - "status=%d image=%d pair=%d " - "mode=%u buffer=%d tag=%u/%u/%u/%d/%u generation=%llu " - "flags=%u reservation=%llu tagless=%s retained=%s revoke=%s", - failure_stage, (int)failure_result, - block->common.logical_assertion.requester_node, - authenticated_master_node, cluster_node_id, - (unsigned long long)block->common.assertion_sequence, - (unsigned long long)block->common.base_authority_generation, - (unsigned long long)block->common.resource_formation, - (unsigned long long)block->common.master_session_incarnation, - (int)status_result, (int)image_result, (int)pair_result, - (unsigned)source_mode, - buffer_id, block->common.logical_assertion.resource.spcOid, - block->common.logical_assertion.resource.dbOid, - block->common.logical_assertion.resource.relNumber, - (int)block->common.logical_assertion.resource.forkNum, - block->common.logical_assertion.resource.blockNum, - (unsigned long long)current.generation, - (unsigned)current.flags, - (unsigned long long)current.reservation_token, - tagless_target_x ? "true" : "false", - semantic_retained ? "true" : "false", - revoke_started ? "true" : "false"))); + errdetail( + "stage=%s result=%d requester=%d master=%d source=%d " + "attempt=%llu base=%llu formation=%llu session=%llu " + "status=%d image=%d pair=%d " + "mode=%u buffer=%d tag=%u/%u/%u/%d/%u generation=%llu " + "flags=%u reservation=%llu tagless=%s retained=%s revoke=%s", + failure_stage, (int)failure_result, block->common.logical_assertion.requester_node, + authenticated_master_node, cluster_node_id, + (unsigned long long)block->common.assertion_sequence, + (unsigned long long)block->common.base_authority_generation, + (unsigned long long)block->common.resource_formation, + (unsigned long long)block->common.master_session_incarnation, (int)status_result, + (int)image_result, (int)pair_result, (unsigned)source_mode, buffer_id, + block->common.logical_assertion.resource.spcOid, + block->common.logical_assertion.resource.dbOid, + block->common.logical_assertion.resource.relNumber, + (int)block->common.logical_assertion.resource.forkNum, + block->common.logical_assertion.resource.blockNum, + (unsigned long long)current.generation, (unsigned)current.flags, + (unsigned long long)current.reservation_token, tagless_target_x ? "true" : "false", + semantic_retained ? "true" : "false", revoke_started ? "true" : "false"))); if (revoke_started) { if (held_x_revoke_active) { - own_result = cluster_bufmgr_pcm_own_abort_held_x_revoke( - &held_x_revoke); + own_result = cluster_bufmgr_pcm_own_abort_held_x_revoke(&held_x_revoke); if (own_result != CLUSTER_PCM_OWN_OK) { gcs_block_resource_x_fail_closed_current(); (void)cluster_bufmgr_pcm_own_abandon_held_x_revoke_after_fail_closed( &held_x_revoke); - (void)gcs_block_resource_x_terminal_owner_release( - &target_revoke_owner, &target_revoke_owner_held); + (void)gcs_block_resource_x_terminal_owner_release(&target_revoke_owner, + &target_revoke_owner_held); return RESOURCE_X_APPLY_RECOVERY_BLOCKED; } held_x_revoke_active = false; - } else if (!gcs_block_pcm_x_resource_x_abort_pre_arm( - buf, &revoking)) { - (void)gcs_block_resource_x_terminal_owner_release( - &target_revoke_owner, &target_revoke_owner_held); + } else if (!gcs_block_pcm_x_resource_x_abort_pre_arm(buf, &revoking)) { + (void)gcs_block_resource_x_terminal_owner_release(&target_revoke_owner, + &target_revoke_owner_held); return RESOURCE_X_APPLY_RECOVERY_BLOCKED; } } revoke_started = false; - if (!gcs_block_resource_x_terminal_owner_release( - &target_revoke_owner, &target_revoke_owner_held)) + if (!gcs_block_resource_x_terminal_owner_release(&target_revoke_owner, + &target_revoke_owner_held)) return RESOURCE_X_APPLY_RECOVERY_BLOCKED; return failure_result; } @@ -10898,50 +10382,48 @@ gcs_block_pcm_x_resource_x_source_block_to_n( * type-15 image is copied, and X commit remains a later linearization. */ static ClusterPcmOwnResult PGRAC_PCM_X_FENCE_DOMINATED(gcs_block_pcm_x_reserved_image_write_exact) -gcs_block_pcm_x_resource_x_install_target_image_exact( - BufferDesc *buf, const ClusterPcmOwnSnapshot *reservation_base, - uint64 reservation_token, const ResourceXCurrentImage *image) + gcs_block_pcm_x_resource_x_install_target_image_exact( + BufferDesc *buf, const ClusterPcmOwnSnapshot *reservation_base, uint64 reservation_token, + const ResourceXCurrentImage *image) { PGAlignedBlock verified; ClusterPcmOwnSnapshot live; ClusterPcmOwnResult own_result; Page page; - if (buf == NULL || reservation_base == NULL || image == NULL - || image->page_bytes == NULL || image->image_length != BLCKSZ - || reservation_token == 0 + if (buf == NULL || reservation_base == NULL || image == NULL || image->page_bytes == NULL + || image->image_length != BLCKSZ || reservation_token == 0 || !LWLockHeldByMe(BufferDescriptorGetContentLock(buf))) return CLUSTER_PCM_OWN_INVALID; memcpy(verified.data, image->page_bytes, BLCKSZ); if (PageGetLSN((Page)verified.data) != image->page_lsn || ((PageHeader)verified.data)->pd_block_scn != image->page_scn - || cluster_gcs_block_compute_checksum(verified.data) - != image->page_checksum) + || cluster_gcs_block_compute_checksum(verified.data) != image->page_checksum) return CLUSTER_PCM_OWN_CORRUPT; own_result = cluster_bufmgr_pcm_own_snapshot(buf, &live); if (own_result != CLUSTER_PCM_OWN_OK) return own_result; - if (!gcs_block_pcm_x_reserved_image_write_exact( - &live, reservation_base, reservation_token)) - return cluster_pcm_own_classify_live_flags( - live.flags, live.reservation_token) == CLUSTER_PCM_OWN_CORRUPT - ? CLUSTER_PCM_OWN_CORRUPT : CLUSTER_PCM_OWN_STALE; + if (!gcs_block_pcm_x_reserved_image_write_exact(&live, reservation_base, reservation_token)) + return cluster_pcm_own_classify_live_flags(live.flags, live.reservation_token) + == CLUSTER_PCM_OWN_CORRUPT + ? CLUSTER_PCM_OWN_CORRUPT + : CLUSTER_PCM_OWN_STALE; page = BufferGetPage(BufferDescriptorGetBuffer(buf)); memcpy(page, verified.data, BLCKSZ); gcs_block_note_install_copy(); PageSetLSNPreserveOrigin(page, image->page_lsn); ((PageHeader)page)->pd_block_scn = image->page_scn; - own_result = cluster_bufmgr_pcm_own_publish_installed_x_image( - buf, reservation_base, reservation_token); + own_result = cluster_bufmgr_pcm_own_publish_installed_x_image(buf, reservation_base, + reservation_token); if (own_result != CLUSTER_PCM_OWN_OK) { gcs_block_resource_x_fail_closed_current(); return CLUSTER_PCM_OWN_CORRUPT; } own_result = cluster_bufmgr_pcm_own_snapshot(buf, &live); if (own_result != CLUSTER_PCM_OWN_OK - || !gcs_block_pcm_x_reserved_image_write_exact( - &live, reservation_base, reservation_token)) { + || !gcs_block_pcm_x_reserved_image_write_exact(&live, reservation_base, + reservation_token)) { gcs_block_resource_x_fail_closed_current(); return CLUSTER_PCM_OWN_CORRUPT; } @@ -10983,23 +10465,19 @@ PGRAC_PCM_X_FENCE_DOMINATED(cluster_pcm_x_resource_x_t2_snapshot_exact) memset(image_out, 0, sizeof(*image_out)); if (committed_generation_out != NULL) *committed_generation_out = 0; - if (ref == NULL || expected_local_generation >= UINT64_MAX - 1 - || aligned_page == NULL || image_out == NULL - || committed_generation_out == NULL + if (ref == NULL || expected_local_generation >= UINT64_MAX - 1 || aligned_page == NULL + || image_out == NULL || committed_generation_out == NULL || (direct_init_bound && (!target_native || !GcsBlockResourceXDirectInitProofAllowedExact( - &ref->assertion.resource, require_clean_n, - precommit_image != NULL))) + &ref->assertion.resource, require_clean_n, precommit_image != NULL))) || (direct_init_bound && direct_init_reservation_token == 0) || (!direct_init_bound && direct_init_reservation_token != 0) - || (precommit_image != NULL - && (capture_local_image || require_clean_n))) + || (precommit_image != NULL && (capture_local_image || require_clean_n))) return RESOURCE_X_BUFFER_CORRUPT; - direct_init_remote_install = direct_init_bound && !require_clean_n - && precommit_image != NULL - && GcsBlockResourceXDirectInitProofAllowedExact( - &ref->assertion.resource, false, true); + direct_init_remote_install + = direct_init_bound && !require_clean_n && precommit_image != NULL + && GcsBlockResourceXDirectInitProofAllowedExact(&ref->assertion.resource, false, true); expected_committed_generation = expected_local_generation + 1; if (direct_init_bound) { if (!cluster_pcm_lock_resource_x_bootstrap_round_direct_init_snapshot_exact( @@ -11017,15 +10495,13 @@ PGRAC_PCM_X_FENCE_DOMINATED(cluster_pcm_x_resource_x_t2_snapshot_exact) &ref->assertion.resource, round_direct_generation, round_direct_token, &buffer_id, ¤t); } else - own_result = cluster_bufmgr_pcm_own_snapshot_by_tag( - &ref->assertion.resource, &buffer_id, ¤t); + own_result = cluster_bufmgr_pcm_own_snapshot_by_tag(&ref->assertion.resource, &buffer_id, + ¤t); if (own_result != CLUSTER_PCM_OWN_OK || buffer_id < 0) - return own_result == CLUSTER_PCM_OWN_BUSY - ? RESOURCE_X_BUFFER_BUSY - : own_result == CLUSTER_PCM_OWN_STALE - ? RESOURCE_X_BUFFER_STALE - : own_result == CLUSTER_PCM_OWN_NOT_READY - ? RESOURCE_X_BUFFER_ABSENT : RESOURCE_X_BUFFER_CORRUPT; + return own_result == CLUSTER_PCM_OWN_BUSY ? RESOURCE_X_BUFFER_BUSY + : own_result == CLUSTER_PCM_OWN_STALE ? RESOURCE_X_BUFFER_STALE + : own_result == CLUSTER_PCM_OWN_NOT_READY ? RESOURCE_X_BUFFER_ABSENT + : RESOURCE_X_BUFFER_CORRUPT; if (direct_init_bound && !cluster_pcm_lock_resource_x_bootstrap_round_direct_init_matches_exact( ref, expected_local_generation, direct_init_reservation_token)) @@ -11041,17 +10517,13 @@ PGRAC_PCM_X_FENCE_DOMINATED(cluster_pcm_x_resource_x_t2_snapshot_exact) PG_TRY(); { - do - { + do { own_result = cluster_bufmgr_pcm_own_snapshot(buf, ¤t); if (own_result != CLUSTER_PCM_OWN_OK) { - result = own_result == CLUSTER_PCM_OWN_BUSY - ? RESOURCE_X_BUFFER_BUSY - : own_result == CLUSTER_PCM_OWN_STALE - ? RESOURCE_X_BUFFER_STALE - : own_result == CLUSTER_PCM_OWN_NOT_READY - ? RESOURCE_X_BUFFER_ABSENT - : RESOURCE_X_BUFFER_CORRUPT; + result = own_result == CLUSTER_PCM_OWN_BUSY ? RESOURCE_X_BUFFER_BUSY + : own_result == CLUSTER_PCM_OWN_STALE ? RESOURCE_X_BUFFER_STALE + : own_result == CLUSTER_PCM_OWN_NOT_READY ? RESOURCE_X_BUFFER_ABSENT + : RESOURCE_X_BUFFER_CORRUPT; break; } if (!BufferTagsEqual(¤t.tag, &ref->assertion.resource)) { @@ -11073,12 +10545,9 @@ PGRAC_PCM_X_FENCE_DOMINATED(cluster_pcm_x_resource_x_t2_snapshot_exact) result = RESOURCE_X_BUFFER_BUSY; break; } else if (current.generation != expected_local_generation) { - result = current.flags != 0 ? RESOURCE_X_BUFFER_BUSY - : RESOURCE_X_BUFFER_STALE; + result = current.flags != 0 ? RESOURCE_X_BUFFER_BUSY : RESOURCE_X_BUFFER_STALE; break; - } else if (direct_init_bound - && current.flags - != PCM_OWN_FLAG_GRANT_PENDING) { + } else if (direct_init_bound && current.flags != PCM_OWN_FLAG_GRANT_PENDING) { result = RESOURCE_X_BUFFER_STALE; break; } else { @@ -11108,26 +10577,21 @@ PGRAC_PCM_X_FENCE_DOMINATED(cluster_pcm_x_resource_x_t2_snapshot_exact) break; } } else if (target_native) { - if (!direct_init_bound - || (!require_clean_n - && !direct_init_remote_install) + if (!direct_init_bound || (!require_clean_n && !direct_init_remote_install) || current.pcm_state != (uint8)PCM_STATE_N) own_result = CLUSTER_PCM_OWN_STALE; else - own_result - = cluster_bufmgr_pcm_own_n_direct_init_candidate_exact( - buf, ¤t); + own_result = cluster_bufmgr_pcm_own_n_direct_init_candidate_exact( + buf, ¤t); if (own_result != CLUSTER_PCM_OWN_OK) { - result = own_result == CLUSTER_PCM_OWN_BUSY - ? RESOURCE_X_BUFFER_BUSY - : own_result == CLUSTER_PCM_OWN_STALE - ? RESOURCE_X_BUFFER_STALE - : RESOURCE_X_BUFFER_CORRUPT; + result = own_result == CLUSTER_PCM_OWN_BUSY ? RESOURCE_X_BUFFER_BUSY + : own_result == CLUSTER_PCM_OWN_STALE + ? RESOURCE_X_BUFFER_STALE + : RESOURCE_X_BUFFER_CORRUPT; break; } if (!cluster_pcm_lock_resource_x_bootstrap_round_direct_init_matches_exact( - ref, current.generation, - current.reservation_token)) { + ref, current.generation, current.reservation_token)) { result = RESOURCE_X_BUFFER_STALE; break; } @@ -11149,14 +10613,12 @@ PGRAC_PCM_X_FENCE_DOMINATED(cluster_pcm_x_resource_x_t2_snapshot_exact) } else if (current.pcm_state == (uint8)PCM_STATE_N) { if (require_clean_n) { own_result - = cluster_bufmgr_pcm_own_n_storage_candidate_exact( - buf, ¤t); + = cluster_bufmgr_pcm_own_n_storage_candidate_exact(buf, ¤t); if (own_result != CLUSTER_PCM_OWN_OK) { - result = own_result == CLUSTER_PCM_OWN_BUSY - ? RESOURCE_X_BUFFER_BUSY - : own_result == CLUSTER_PCM_OWN_STALE - ? RESOURCE_X_BUFFER_STALE - : RESOURCE_X_BUFFER_CORRUPT; + result = own_result == CLUSTER_PCM_OWN_BUSY ? RESOURCE_X_BUFFER_BUSY + : own_result == CLUSTER_PCM_OWN_STALE + ? RESOURCE_X_BUFFER_STALE + : RESOURCE_X_BUFFER_CORRUPT; break; } } @@ -11167,11 +10629,9 @@ PGRAC_PCM_X_FENCE_DOMINATED(cluster_pcm_x_resource_x_t2_snapshot_exact) own_result = cluster_bufmgr_pcm_own_begin_x_reservation(buf, ¤t, &reservation_token); if (own_result != CLUSTER_PCM_OWN_OK) { - result = own_result == CLUSTER_PCM_OWN_BUSY - ? RESOURCE_X_BUFFER_BUSY - : own_result == CLUSTER_PCM_OWN_STALE - ? RESOURCE_X_BUFFER_STALE - : RESOURCE_X_BUFFER_CORRUPT; + result = own_result == CLUSTER_PCM_OWN_BUSY ? RESOURCE_X_BUFFER_BUSY + : own_result == CLUSTER_PCM_OWN_STALE ? RESOURCE_X_BUFFER_STALE + : RESOURCE_X_BUFFER_CORRUPT; break; } if (target_native) { @@ -11196,37 +10656,29 @@ PGRAC_PCM_X_FENCE_DOMINATED(cluster_pcm_x_resource_x_t2_snapshot_exact) } } } else if (current.pcm_state == (uint8)PCM_STATE_S) { - own_result = cluster_bufmgr_pcm_own_begin_s_revoke( - buf, ¤t, &revoking); + own_result = cluster_bufmgr_pcm_own_begin_s_revoke(buf, ¤t, &revoking); if (own_result == CLUSTER_PCM_OWN_OK) { base = revoking; - own_result - = cluster_bufmgr_pcm_own_handoff_s_revoke_to_x_reservation( - buf, &revoking, &reservation_token); + own_result = cluster_bufmgr_pcm_own_handoff_s_revoke_to_x_reservation( + buf, &revoking, &reservation_token); } if (own_result != CLUSTER_PCM_OWN_OK) { - result = own_result == CLUSTER_PCM_OWN_BUSY - ? RESOURCE_X_BUFFER_BUSY - : own_result == CLUSTER_PCM_OWN_STALE - ? RESOURCE_X_BUFFER_STALE - : RESOURCE_X_BUFFER_CORRUPT; + result = own_result == CLUSTER_PCM_OWN_BUSY ? RESOURCE_X_BUFFER_BUSY + : own_result == CLUSTER_PCM_OWN_STALE ? RESOURCE_X_BUFFER_STALE + : RESOURCE_X_BUFFER_CORRUPT; break; } } else if (current.pcm_state == (uint8)PCM_STATE_X) { - own_result = cluster_bufmgr_pcm_own_begin_x_revoke( - buf, ¤t, &revoking); + own_result = cluster_bufmgr_pcm_own_begin_x_revoke(buf, ¤t, &revoking); if (own_result == CLUSTER_PCM_OWN_OK) { base = revoking; - own_result - = cluster_bufmgr_pcm_own_handoff_revoke_to_x_reservation( - buf, &revoking, &reservation_token); + own_result = cluster_bufmgr_pcm_own_handoff_revoke_to_x_reservation( + buf, &revoking, &reservation_token); } if (own_result != CLUSTER_PCM_OWN_OK) { - result = own_result == CLUSTER_PCM_OWN_BUSY - ? RESOURCE_X_BUFFER_BUSY - : own_result == CLUSTER_PCM_OWN_STALE - ? RESOURCE_X_BUFFER_STALE - : RESOURCE_X_BUFFER_CORRUPT; + result = own_result == CLUSTER_PCM_OWN_BUSY ? RESOURCE_X_BUFFER_BUSY + : own_result == CLUSTER_PCM_OWN_STALE ? RESOURCE_X_BUFFER_STALE + : RESOURCE_X_BUFFER_CORRUPT; break; } } else { @@ -11239,55 +10691,42 @@ PGRAC_PCM_X_FENCE_DOMINATED(cluster_pcm_x_resource_x_t2_snapshot_exact) result = RESOURCE_X_BUFFER_CORRUPT; break; } - own_result - = gcs_block_pcm_x_resource_x_install_target_image_exact( - buf, &base, reservation_token, - precommit_image); + own_result = gcs_block_pcm_x_resource_x_install_target_image_exact( + buf, &base, reservation_token, precommit_image); if (own_result != CLUSTER_PCM_OWN_OK) { - result = own_result == CLUSTER_PCM_OWN_BUSY - ? RESOURCE_X_BUFFER_BUSY - : own_result == CLUSTER_PCM_OWN_STALE - ? RESOURCE_X_BUFFER_STALE - : RESOURCE_X_BUFFER_CORRUPT; + result = own_result == CLUSTER_PCM_OWN_BUSY ? RESOURCE_X_BUFFER_BUSY + : own_result == CLUSTER_PCM_OWN_STALE ? RESOURCE_X_BUFFER_STALE + : RESOURCE_X_BUFFER_CORRUPT; break; } } - own_result = cluster_bufmgr_pcm_own_finish_x_commit( - buf, &base, reservation_token, &committed_generation); + own_result = cluster_bufmgr_pcm_own_finish_x_commit(buf, &base, reservation_token, + &committed_generation); if (own_result != CLUSTER_PCM_OWN_OK || committed_generation != expected_committed_generation) { - result = own_result == CLUSTER_PCM_OWN_BUSY - ? RESOURCE_X_BUFFER_BUSY - : own_result == CLUSTER_PCM_OWN_STALE - ? RESOURCE_X_BUFFER_STALE - : RESOURCE_X_BUFFER_CORRUPT; + result = own_result == CLUSTER_PCM_OWN_BUSY ? RESOURCE_X_BUFFER_BUSY + : own_result == CLUSTER_PCM_OWN_STALE ? RESOURCE_X_BUFFER_STALE + : RESOURCE_X_BUFFER_CORRUPT; break; } } if (capture_local_image) { own_result = cluster_bufmgr_pcm_own_snapshot(buf, ¤t); - if (own_result != CLUSTER_PCM_OWN_OK - || current.generation != committed_generation - || !cluster_pcm_x_resource_x_t2_snapshot_exact( - ref, ¤t)) { - result = own_result == CLUSTER_PCM_OWN_BUSY - ? RESOURCE_X_BUFFER_BUSY - : own_result == CLUSTER_PCM_OWN_NOT_READY - ? RESOURCE_X_BUFFER_ABSENT - : own_result == CLUSTER_PCM_OWN_CORRUPT - ? RESOURCE_X_BUFFER_CORRUPT - : RESOURCE_X_BUFFER_STALE; + if (own_result != CLUSTER_PCM_OWN_OK || current.generation != committed_generation + || !cluster_pcm_x_resource_x_t2_snapshot_exact(ref, ¤t)) { + result = own_result == CLUSTER_PCM_OWN_BUSY ? RESOURCE_X_BUFFER_BUSY + : own_result == CLUSTER_PCM_OWN_NOT_READY ? RESOURCE_X_BUFFER_ABSENT + : own_result == CLUSTER_PCM_OWN_CORRUPT ? RESOURCE_X_BUFFER_CORRUPT + : RESOURCE_X_BUFFER_STALE; break; } page = BufferGetPage(BufferDescriptorGetBuffer(buf)); memcpy(aligned_page->data, page, BLCKSZ); image_out->page_bytes = aligned_page->data; image_out->page_lsn = PageGetLSN((Page)aligned_page->data); - image_out->page_scn - = ((PageHeader)aligned_page->data)->pd_block_scn; - image_out->page_checksum - = cluster_gcs_block_compute_checksum(aligned_page->data); + image_out->page_scn = ((PageHeader)aligned_page->data)->pd_block_scn; + image_out->page_checksum = cluster_gcs_block_compute_checksum(aligned_page->data); image_out->image_length = BLCKSZ; } *committed_generation_out = committed_generation; @@ -11357,17 +10796,15 @@ gcs_block_pcm_x_resource_x_join_terminal_try(const ResourceXAssertion *assertion *terminal_ownership_generation_out = 0; if (terminal_authority_generation_out != NULL) *terminal_authority_generation_out = 0; - if (terminal_ref_out == NULL - || terminal_ownership_generation_out == NULL + if (terminal_ref_out == NULL || terminal_ownership_generation_out == NULL || terminal_authority_generation_out == NULL) return RESOURCE_X_APPLY_INVALID; - result = cluster_pcm_lock_resource_x_requester_join_frames_exact( - assertion, &grant, &image_frame, &join); + result = cluster_pcm_lock_resource_x_requester_join_frames_exact(assertion, &grant, + &image_frame, &join); if (result != RESOURCE_X_APPLY_APPLIED) return result; - if ((join.flags & RESOURCE_X_REQUESTER_JOIN_READY) == 0 - || join.requester_target_generation == 0 + if ((join.flags & RESOURCE_X_REQUESTER_JOIN_READY) == 0 || join.requester_target_generation == 0 || join.requester_target_generation != join.assertion_sequence || join.final_authority_generation <= join.base_authority_generation || join.final_authority_generation == UINT64_MAX @@ -11382,8 +10819,7 @@ gcs_block_pcm_x_resource_x_join_terminal_try(const ResourceXAssertion *assertion && (image_frame.kind != RESOURCE_X_WIRE_IMAGE_ENVELOPE || image_frame.body.image_envelope.image_length != BLCKSZ)) || (durable_proof - && (image_frame.kind != 0 - || grant.common.flags != 0 + && (image_frame.kind != 0 || grant.common.flags != 0 || grant.body.authority_grant.source_carrier_generation != 0 || grant.body.authority_grant.dependency_count != 0))) return RESOURCE_X_APPLY_BAD_STATE; @@ -11405,8 +10841,8 @@ gcs_block_pcm_x_resource_x_join_terminal_try(const ResourceXAssertion *assertion return RESOURCE_X_APPLY_STALE; } if (direct_init_bound) { - if (!GcsBlockResourceXDirectInitProofAllowedExact( - &ref.assertion.resource, durable_proof, remote_proof)) + if (!GcsBlockResourceXDirectInitProofAllowedExact(&ref.assertion.resource, durable_proof, + remote_proof)) return RESOURCE_X_APPLY_STALE; if (remote_proof) own_result = cluster_bufmgr_pcm_own_snapshot_by_tag(&ref.assertion.resource, @@ -11416,16 +10852,14 @@ gcs_block_pcm_x_resource_x_join_terminal_try(const ResourceXAssertion *assertion &ref.assertion.resource, direct_init_generation, direct_init_token, &target_buffer_id, &target_base); } else - own_result = cluster_bufmgr_pcm_own_snapshot_by_tag( - &ref.assertion.resource, &target_buffer_id, &target_base); + own_result = cluster_bufmgr_pcm_own_snapshot_by_tag(&ref.assertion.resource, + &target_buffer_id, &target_base); if (own_result != CLUSTER_PCM_OWN_OK || target_buffer_id < 0 - || !BufferTagsEqual(&target_base.tag, &ref.assertion.resource) - || target_base.generation == UINT64_MAX) - return own_result == CLUSTER_PCM_OWN_BUSY - ? RESOURCE_X_APPLY_BAD_STATE - : own_result == CLUSTER_PCM_OWN_CORRUPT - ? RESOURCE_X_APPLY_RECOVERY_BLOCKED - : RESOURCE_X_APPLY_STALE; + || !BufferTagsEqual(&target_base.tag, &ref.assertion.resource) + || target_base.generation == UINT64_MAX) + return own_result == CLUSTER_PCM_OWN_BUSY ? RESOURCE_X_APPLY_BAD_STATE + : own_result == CLUSTER_PCM_OWN_CORRUPT ? RESOURCE_X_APPLY_RECOVERY_BLOCKED + : RESOURCE_X_APPLY_STALE; if (delivery_claim != NULL) { ClusterPcmOwnSnapshot held; @@ -11453,37 +10887,30 @@ gcs_block_pcm_x_resource_x_join_terminal_try(const ResourceXAssertion *assertion if (!GcsBlockResourceXDirectInitProofAllowedExact(&ref.assertion.resource, durable_proof, remote_proof)) return RESOURCE_X_APPLY_STALE; - own_result - = cluster_bufmgr_pcm_own_n_direct_init_candidate_exact( - GetBufferDescriptor(target_buffer_id), &target_base); + own_result = cluster_bufmgr_pcm_own_n_direct_init_candidate_exact( + GetBufferDescriptor(target_buffer_id), &target_base); if (own_result != CLUSTER_PCM_OWN_OK) - return own_result == CLUSTER_PCM_OWN_BUSY - ? RESOURCE_X_APPLY_BAD_STATE - : own_result == CLUSTER_PCM_OWN_STALE - ? RESOURCE_X_APPLY_STALE - : RESOURCE_X_APPLY_RECOVERY_BLOCKED; + return own_result == CLUSTER_PCM_OWN_BUSY ? RESOURCE_X_APPLY_BAD_STATE + : own_result == CLUSTER_PCM_OWN_STALE ? RESOURCE_X_APPLY_STALE + : RESOURCE_X_APPLY_RECOVERY_BLOCKED; direct_init_bound = direct_init_bound && cluster_pcm_lock_resource_x_bootstrap_round_direct_init_matches_exact( - &ref, target_base.generation, - target_base.reservation_token); + &ref, target_base.generation, target_base.reservation_token); if (!direct_init_bound) return RESOURCE_X_APPLY_STALE; } } else if (target_base.pcm_state == (uint8)PCM_STATE_N) { - /* Bootstrap admitted a cold generation-zero N descriptor only + /* Bootstrap admitted a cold generation-zero N descriptor only * through this exact BM_VALID/no-IO predicate. Revalidate the * same shape at the type-15 terminal before T1/T2/T3; generation * zero supplies no authority, while the joined grant and image do. */ - own_result - = cluster_bufmgr_pcm_own_n_assertion_candidate_exact( - GetBufferDescriptor(target_buffer_id), &target_base, NULL); - if (own_result != CLUSTER_PCM_OWN_OK) - return own_result == CLUSTER_PCM_OWN_BUSY - ? RESOURCE_X_APPLY_BAD_STATE - : own_result == CLUSTER_PCM_OWN_STALE - ? RESOURCE_X_APPLY_STALE - : RESOURCE_X_APPLY_RECOVERY_BLOCKED; + own_result = cluster_bufmgr_pcm_own_n_assertion_candidate_exact( + GetBufferDescriptor(target_buffer_id), &target_base, NULL); + if (own_result != CLUSTER_PCM_OWN_OK) + return own_result == CLUSTER_PCM_OWN_BUSY ? RESOURCE_X_APPLY_BAD_STATE + : own_result == CLUSTER_PCM_OWN_STALE ? RESOURCE_X_APPLY_STALE + : RESOURCE_X_APPLY_RECOVERY_BLOCKED; } else if (target_base.generation == 0) return RESOURCE_X_APPLY_STALE; /* A T1 reservation owns the installation base through I1/I2. The @@ -11491,220 +10918,198 @@ gcs_block_pcm_x_resource_x_join_terminal_try(const ResourceXAssertion *assertion expected_local_generation = claim_source == RESOURCE_X_INSTALL_CLAIM_NONE ? target_base.generation : claim_generation; memset(&executor_snapshot, 0, sizeof(executor_snapshot)); - probe_result = cluster_pcm_lock_resource_x_executor_probe_exact( - &ref, &executor_snapshot); + probe_result = cluster_pcm_lock_resource_x_executor_probe_exact(&ref, &executor_snapshot); /* A retained exact type-15 replay is one of the existing requester * scheduling ticks. It may re-drive a prior conditional content-lock * miss once, but must not erase identity/image contradictions or spin in * this LMS callback. */ - if (probe_result == RESOURCE_X_EXECUTOR_BLOCKED - && scheduled_retry + if (probe_result == RESOURCE_X_EXECUTOR_BLOCKED && scheduled_retry && executor_snapshot.no_progress_generation == ref.acquisition_generation && executor_snapshot.no_progress_reason == RESOURCE_X_NO_PROGRESS_BUFFER_BUSY) { result = cluster_pcm_lock_resource_x_executor_rearm_exact(&ref); - if (result == RESOURCE_X_APPLY_APPLIED - || result == RESOURCE_X_APPLY_DUPLICATE) { + if (result == RESOURCE_X_APPLY_APPLIED || result == RESOURCE_X_APPLY_DUPLICATE) { memset(&executor_snapshot, 0, sizeof(executor_snapshot)); - probe_result = cluster_pcm_lock_resource_x_executor_probe_exact( - &ref, &executor_snapshot); + probe_result + = cluster_pcm_lock_resource_x_executor_probe_exact(&ref, &executor_snapshot); } } if (probe_result == RESOURCE_X_EXECUTOR_COMPLETE) { - if (target_base.pcm_state != (uint8)PCM_STATE_X - || target_base.flags != 0 - || target_base.writer_activation_token != 0 - || target_base.resource_x_activation_generation != 0) - return RESOURCE_X_APPLY_STALE; - *terminal_ref_out = ref; - *terminal_ownership_generation_out = target_base.generation; - *terminal_authority_generation_out - = join.final_authority_generation; - return RESOURCE_X_APPLY_DUPLICATE; - } + if (target_base.pcm_state != (uint8)PCM_STATE_X || target_base.flags != 0 + || target_base.writer_activation_token != 0 + || target_base.resource_x_activation_generation != 0) + return RESOURCE_X_APPLY_STALE; + *terminal_ref_out = ref; + *terminal_ownership_generation_out = target_base.generation; + *terminal_authority_generation_out = join.final_authority_generation; + return RESOURCE_X_APPLY_DUPLICATE; + } if (probe_result == RESOURCE_X_EXECUTOR_BLOCKED) { - (void)cluster_pcm_lock_resource_x_executor_wait_exact(&ref, 0); - return RESOURCE_X_APPLY_BAD_STATE; - } - /* A terminal round no longer exposes the live direct-init claim; only + (void)cluster_pcm_lock_resource_x_executor_wait_exact(&ref, 0); + return RESOURCE_X_APPLY_BAD_STATE; + } + /* A terminal round no longer exposes the live direct-init claim; only * the COMPLETE branch above may consume that historical lineage. */ - if (claim_source == RESOURCE_X_INSTALL_CLAIM_DIRECT_INIT && !direct_init_bound) - return RESOURCE_X_APPLY_STALE; - if (claim_source != RESOURCE_X_INSTALL_CLAIM_NONE - && target_base.pcm_state == (uint8)PCM_STATE_X - && !cluster_pcm_x_resource_x_claim_installed_exact(&ref, &target_base, claim_generation, - claim_token)) - return RESOURCE_X_APPLY_STALE; - if (probe_result != RESOURCE_X_EXECUTOR_READY - && !(probe_result == RESOURCE_X_EXECUTOR_CHANGED - && executor_snapshot.ref.assertion.requester_node == -1 - && executor_snapshot.ref.formation == 0 - && executor_snapshot.ref.acquisition_generation == 0 - && executor_snapshot.progress_flags == 0 - && executor_snapshot.retired_acquisition_generation < ref.acquisition_generation)) - return probe_result == RESOURCE_X_EXECUTOR_CHANGED ? RESOURCE_X_APPLY_STALE - : RESOURCE_X_APPLY_RECOVERY_BLOCKED; - memset(&gate, 0, sizeof(gate)); - if (!cluster_pcm_lock_resource_x_executor_enter(&ref, &gate)) - return RESOURCE_X_APPLY_RECOVERY_BLOCKED; - entered = true; + if (claim_source == RESOURCE_X_INSTALL_CLAIM_DIRECT_INIT && !direct_init_bound) + return RESOURCE_X_APPLY_STALE; + if (claim_source != RESOURCE_X_INSTALL_CLAIM_NONE && target_base.pcm_state == (uint8)PCM_STATE_X + && !cluster_pcm_x_resource_x_claim_installed_exact(&ref, &target_base, claim_generation, + claim_token)) + return RESOURCE_X_APPLY_STALE; + if (probe_result != RESOURCE_X_EXECUTOR_READY + && !(probe_result == RESOURCE_X_EXECUTOR_CHANGED + && executor_snapshot.ref.assertion.requester_node == -1 + && executor_snapshot.ref.formation == 0 + && executor_snapshot.ref.acquisition_generation == 0 + && executor_snapshot.progress_flags == 0 + && executor_snapshot.retired_acquisition_generation < ref.acquisition_generation)) + return probe_result == RESOURCE_X_EXECUTOR_CHANGED ? RESOURCE_X_APPLY_STALE + : RESOURCE_X_APPLY_RECOVERY_BLOCKED; + memset(&gate, 0, sizeof(gate)); + if (!cluster_pcm_lock_resource_x_executor_enter(&ref, &gate)) + return RESOURCE_X_APPLY_RECOVERY_BLOCKED; + entered = true; - PG_TRY(); - { - do - { - result = cluster_pcm_lock_resource_x_t1_grant_delivery_exact(&ref, delivery_claim); - if (result != RESOURCE_X_APPLY_APPLIED && result != RESOURCE_X_APPLY_DUPLICATE) - break; + PG_TRY(); + { + do { + result = cluster_pcm_lock_resource_x_t1_grant_delivery_exact(&ref, delivery_claim); + if (result != RESOURCE_X_APPLY_APPLIED && result != RESOURCE_X_APPLY_DUPLICATE) + break; - memset(&image, 0, sizeof(image)); - memset(&durable_image, 0, sizeof(durable_image)); - memset(&joined_image, 0, sizeof(joined_image)); - if (durable_proof) { - if (!cluster_bufmgr_read_storage_image_for_resource_x( - ref.assertion.resource, aligned_image.data, &storage_lsn, - &storage_scn)) { - result = RESOURCE_X_APPLY_RECOVERY_BLOCKED; - break; - } - memset(&durable, 0, sizeof(durable)); - durable.assertion = grant.common.logical_assertion; - durable.base_authority_generation = grant.common.base_authority_generation; - durable.resource_formation = grant.common.resource_formation; - durable.master_session_incarnation = grant.common.master_session_incarnation; - durable.assertion_sequence = grant.common.assertion_sequence; - durable.requester_target_generation - = grant.body.authority_grant.requester_target_generation; - durable.page_scn_lsn = storage_scn; - durable.page_checksum = cluster_gcs_block_compute_checksum(aligned_image.data); - durable.source_proof_crc32c - = gcs_block_pcm_x_resource_x_durable_proof_crc(&durable); - if (durable.source_proof_crc32c == 0 - || grant.body.authority_grant.page_scn_lsn != durable.page_scn_lsn - || grant.body.authority_grant.page_checksum != durable.page_checksum - || grant.body.authority_grant.source_proof_crc32c - != durable.source_proof_crc32c) { - result = RESOURCE_X_APPLY_STALE; - break; - } - durable_image.page_bytes = aligned_image.data; - durable_image.page_lsn = storage_lsn; - durable_image.page_scn = (SCN)storage_scn; - durable_image.page_checksum = durable.page_checksum; - durable_image.image_length = BLCKSZ; - } else if (remote_proof) { - memcpy(aligned_image.data, image_frame.body.image_envelope.page_bytes, BLCKSZ); - joined_image.page_bytes = aligned_image.data; - joined_image.page_lsn = PageGetLSN((Page)aligned_image.data); - joined_image.page_scn = ((PageHeader)aligned_image.data)->pd_block_scn; - joined_image.page_checksum = image_frame.body.image_envelope.page_checksum; - joined_image.image_length = BLCKSZ; - if (image_frame.body.image_envelope.page_scn_lsn - != (uint64)joined_image.page_scn) { - result = RESOURCE_X_APPLY_INVALID; - break; - } + memset(&image, 0, sizeof(image)); + memset(&durable_image, 0, sizeof(durable_image)); + memset(&joined_image, 0, sizeof(joined_image)); + if (durable_proof) { + if (!cluster_bufmgr_read_storage_image_for_resource_x( + ref.assertion.resource, aligned_image.data, &storage_lsn, &storage_scn)) { + result = RESOURCE_X_APPLY_RECOVERY_BLOCKED; + break; } - - buffer_result = gcs_block_pcm_x_resource_x_prepare_target_x( - &ref, expected_local_generation, true, direct_init_bound, direct_init_token, - local_proof, durable_proof, remote_proof ? &joined_image : NULL, &aligned_image, - &image, &committed_generation, delivery_claim); - if (buffer_result != RESOURCE_X_BUFFER_T2_INSTALLED - && buffer_result != RESOURCE_X_BUFFER_ALREADY_INSTALLED) { - cluster_pcm_lock_resource_x_publish_no_progress_exact( - &ref, buffer_result == RESOURCE_X_BUFFER_BUSY - ? RESOURCE_X_NO_PROGRESS_BUFFER_BUSY - : buffer_result == RESOURCE_X_BUFFER_ABSENT - ? RESOURCE_X_NO_PROGRESS_BUFFER_ABSENT - : buffer_result == RESOURCE_X_BUFFER_STALE - ? RESOURCE_X_NO_PROGRESS_BUFFER_STALE - : RESOURCE_X_NO_PROGRESS_BUFFER_CORRUPT); - result = buffer_result == RESOURCE_X_BUFFER_STALE ? RESOURCE_X_APPLY_STALE - : buffer_result == RESOURCE_X_BUFFER_CORRUPT - ? RESOURCE_X_APPLY_RECOVERY_BLOCKED - : RESOURCE_X_APPLY_BAD_STATE; + memset(&durable, 0, sizeof(durable)); + durable.assertion = grant.common.logical_assertion; + durable.base_authority_generation = grant.common.base_authority_generation; + durable.resource_formation = grant.common.resource_formation; + durable.master_session_incarnation = grant.common.master_session_incarnation; + durable.assertion_sequence = grant.common.assertion_sequence; + durable.requester_target_generation + = grant.body.authority_grant.requester_target_generation; + durable.page_scn_lsn = storage_scn; + durable.page_checksum = cluster_gcs_block_compute_checksum(aligned_image.data); + durable.source_proof_crc32c + = gcs_block_pcm_x_resource_x_durable_proof_crc(&durable); + if (durable.source_proof_crc32c == 0 + || grant.body.authority_grant.page_scn_lsn != durable.page_scn_lsn + || grant.body.authority_grant.page_checksum != durable.page_checksum + || grant.body.authority_grant.source_proof_crc32c + != durable.source_proof_crc32c) { + result = RESOURCE_X_APPLY_STALE; break; } + durable_image.page_bytes = aligned_image.data; + durable_image.page_lsn = storage_lsn; + durable_image.page_scn = (SCN)storage_scn; + durable_image.page_checksum = durable.page_checksum; + durable_image.image_length = BLCKSZ; + } else if (remote_proof) { + memcpy(aligned_image.data, image_frame.body.image_envelope.page_bytes, BLCKSZ); + joined_image.page_bytes = aligned_image.data; + joined_image.page_lsn = PageGetLSN((Page)aligned_image.data); + joined_image.page_scn = ((PageHeader)aligned_image.data)->pd_block_scn; + joined_image.page_checksum = image_frame.body.image_envelope.page_checksum; + joined_image.image_length = BLCKSZ; + if (image_frame.body.image_envelope.page_scn_lsn != (uint64)joined_image.page_scn) { + result = RESOURCE_X_APPLY_INVALID; + break; + } + } + + buffer_result = gcs_block_pcm_x_resource_x_prepare_target_x( + &ref, expected_local_generation, true, direct_init_bound, direct_init_token, + local_proof, durable_proof, remote_proof ? &joined_image : NULL, &aligned_image, + &image, &committed_generation, delivery_claim); + if (buffer_result != RESOURCE_X_BUFFER_T2_INSTALLED + && buffer_result != RESOURCE_X_BUFFER_ALREADY_INSTALLED) { + cluster_pcm_lock_resource_x_publish_no_progress_exact( + &ref, buffer_result == RESOURCE_X_BUFFER_BUSY + ? RESOURCE_X_NO_PROGRESS_BUFFER_BUSY + : buffer_result == RESOURCE_X_BUFFER_ABSENT + ? RESOURCE_X_NO_PROGRESS_BUFFER_ABSENT + : buffer_result == RESOURCE_X_BUFFER_STALE + ? RESOURCE_X_NO_PROGRESS_BUFFER_STALE + : RESOURCE_X_NO_PROGRESS_BUFFER_CORRUPT); + result = buffer_result == RESOURCE_X_BUFFER_STALE ? RESOURCE_X_APPLY_STALE + : buffer_result == RESOURCE_X_BUFFER_CORRUPT + ? RESOURCE_X_APPLY_RECOVERY_BLOCKED + : RESOURCE_X_APPLY_BAD_STATE; + break; + } if (durable_proof) image = durable_image; else if (remote_proof) image = joined_image; else if (local_proof - && (grant.body.authority_grant.page_scn_lsn - != (uint64)image.page_scn - || grant.body.authority_grant.page_checksum - != image.page_checksum)) { + && (grant.body.authority_grant.page_scn_lsn != (uint64)image.page_scn + || grant.body.authority_grant.page_checksum != image.page_checksum)) { result = RESOURCE_X_APPLY_STALE; break; } if (direct_init_bound && !remote_proof) - buffer_result - = cluster_bufmgr_pcm_own_direct_init_bind_x_by_tag_exact( - &ref, committed_generation, direct_init_token, - &install_proof); + buffer_result = cluster_bufmgr_pcm_own_direct_init_bind_x_by_tag_exact( + &ref, committed_generation, direct_init_token, &install_proof); else - buffer_result = cluster_bufmgr_pcm_own_activate_x_by_tag( - &ref, &image, &install_proof); + buffer_result + = cluster_bufmgr_pcm_own_activate_x_by_tag(&ref, &image, &install_proof); if (buffer_result != RESOURCE_X_BUFFER_T2_INSTALLED && buffer_result != RESOURCE_X_BUFFER_ALREADY_INSTALLED) { cluster_pcm_lock_resource_x_publish_no_progress_exact( &ref, buffer_result == RESOURCE_X_BUFFER_BUSY - ? RESOURCE_X_NO_PROGRESS_BUFFER_BUSY - : buffer_result == RESOURCE_X_BUFFER_ABSENT - ? RESOURCE_X_NO_PROGRESS_BUFFER_ABSENT - : buffer_result == RESOURCE_X_BUFFER_STALE - ? RESOURCE_X_NO_PROGRESS_BUFFER_STALE - : RESOURCE_X_NO_PROGRESS_BUFFER_CORRUPT); - result = buffer_result == RESOURCE_X_BUFFER_STALE - ? RESOURCE_X_APPLY_STALE - : buffer_result == RESOURCE_X_BUFFER_CORRUPT - ? RESOURCE_X_APPLY_RECOVERY_BLOCKED - : RESOURCE_X_APPLY_BAD_STATE; + ? RESOURCE_X_NO_PROGRESS_BUFFER_BUSY + : buffer_result == RESOURCE_X_BUFFER_ABSENT + ? RESOURCE_X_NO_PROGRESS_BUFFER_ABSENT + : buffer_result == RESOURCE_X_BUFFER_STALE + ? RESOURCE_X_NO_PROGRESS_BUFFER_STALE + : RESOURCE_X_NO_PROGRESS_BUFFER_CORRUPT); + result = buffer_result == RESOURCE_X_BUFFER_STALE ? RESOURCE_X_APPLY_STALE + : buffer_result == RESOURCE_X_BUFFER_CORRUPT + ? RESOURCE_X_APPLY_RECOVERY_BLOCKED + : RESOURCE_X_APPLY_BAD_STATE; break; } result = cluster_pcm_lock_resource_x_requester_apply_delivery_exact( &ref, &install_proof, delivery_claim); - if (result != RESOURCE_X_APPLY_APPLIED - && result != RESOURCE_X_APPLY_DUPLICATE) + if (result != RESOURCE_X_APPLY_APPLIED && result != RESOURCE_X_APPLY_DUPLICATE) break; if (direct_init_bound && !remote_proof) - buffer_result - = cluster_bufmgr_pcm_own_direct_init_clear_x_by_tag_exact( - &ref, committed_generation, direct_init_token, - &activation_proof); + buffer_result = cluster_bufmgr_pcm_own_direct_init_clear_x_by_tag_exact( + &ref, committed_generation, direct_init_token, &activation_proof); else - buffer_result - = cluster_bufmgr_pcm_own_writer_activation_clear_by_tag_exact( - &ref, &activation_proof); + buffer_result = cluster_bufmgr_pcm_own_writer_activation_clear_by_tag_exact( + &ref, &activation_proof); if (buffer_result != RESOURCE_X_BUFFER_T2_INSTALLED && buffer_result != RESOURCE_X_BUFFER_ALREADY_INSTALLED) { cluster_pcm_lock_resource_x_publish_no_progress_exact( &ref, buffer_result == RESOURCE_X_BUFFER_BUSY - ? RESOURCE_X_NO_PROGRESS_BUFFER_BUSY - : buffer_result == RESOURCE_X_BUFFER_ABSENT - ? RESOURCE_X_NO_PROGRESS_BUFFER_ABSENT - : buffer_result == RESOURCE_X_BUFFER_STALE - ? RESOURCE_X_NO_PROGRESS_BUFFER_STALE - : RESOURCE_X_NO_PROGRESS_BUFFER_CORRUPT); - result = buffer_result == RESOURCE_X_BUFFER_STALE - ? RESOURCE_X_APPLY_STALE - : buffer_result == RESOURCE_X_BUFFER_CORRUPT - ? RESOURCE_X_APPLY_RECOVERY_BLOCKED - : RESOURCE_X_APPLY_BAD_STATE; + ? RESOURCE_X_NO_PROGRESS_BUFFER_BUSY + : buffer_result == RESOURCE_X_BUFFER_ABSENT + ? RESOURCE_X_NO_PROGRESS_BUFFER_ABSENT + : buffer_result == RESOURCE_X_BUFFER_STALE + ? RESOURCE_X_NO_PROGRESS_BUFFER_STALE + : RESOURCE_X_NO_PROGRESS_BUFFER_CORRUPT); + result = buffer_result == RESOURCE_X_BUFFER_STALE ? RESOURCE_X_APPLY_STALE + : buffer_result == RESOURCE_X_BUFFER_CORRUPT + ? RESOURCE_X_APPLY_RECOVERY_BLOCKED + : RESOURCE_X_APPLY_BAD_STATE; break; } result = cluster_pcm_lock_resource_x_requester_activate_delivery_exact( &ref, &activation_proof, delivery_claim); - if (result != RESOURCE_X_APPLY_APPLIED - && result != RESOURCE_X_APPLY_DUPLICATE) + if (result != RESOURCE_X_APPLY_APPLIED && result != RESOURCE_X_APPLY_DUPLICATE) break; *terminal_ref_out = ref; - *terminal_ownership_generation_out - = activation_proof.ownership_generation; - *terminal_authority_generation_out - = join.final_authority_generation; + *terminal_ownership_generation_out = activation_proof.ownership_generation; + *terminal_authority_generation_out = join.final_authority_generation; break; } while (false); } @@ -11808,10 +11213,9 @@ gcs_block_pcm_x_resource_x_join_terminal_owned_try(const ResourceXAcquisitionRef } static ResourceXApplyResult -gcs_block_pcm_x_resource_x_master_durable_try( - const ResourceXDecodedFrame *assertion, - const ResourceXMasterSnapshot *captured, - ResourceXMasterSnapshot *out) +gcs_block_pcm_x_resource_x_master_durable_try(const ResourceXDecodedFrame *assertion, + const ResourceXMasterSnapshot *captured, + ResourceXMasterSnapshot *out) { PGAlignedBlock aligned_image; ResourceXDurableProof durable; @@ -11821,47 +11225,36 @@ gcs_block_pcm_x_resource_x_master_durable_try( if (assertion == NULL || captured == NULL || out == NULL || assertion->kind != RESOURCE_X_WIRE_ASSERT_X || assertion->common.observed_mode != (uint8)PCM_STATE_N - || captured->phase != RESOURCE_X_MASTER_WAIT_PROOF - || captured->is_head != 1 + || captured->phase != RESOURCE_X_MASTER_WAIT_PROOF || captured->is_head != 1 || captured->proof_kind != 0 || captured->incompatible_holders_bitmap != captured->blocked_holders_bitmap - || !resource_x_assertion_equal(&captured->assertion, - &assertion->common.logical_assertion) - || captured->base_authority_generation - != assertion->common.base_authority_generation - || captured->resource_formation - != assertion->common.resource_formation - || captured->master_session_incarnation - != assertion->common.master_session_incarnation - || captured->assertion_sequence - != assertion->common.assertion_sequence) + || !resource_x_assertion_equal(&captured->assertion, &assertion->common.logical_assertion) + || captured->base_authority_generation != assertion->common.base_authority_generation + || captured->resource_formation != assertion->common.resource_formation + || captured->master_session_incarnation != assertion->common.master_session_incarnation + || captured->assertion_sequence != assertion->common.assertion_sequence) return RESOURCE_X_APPLY_BAD_STATE; if (!cluster_bufmgr_read_storage_image_for_resource_x( - assertion->common.logical_assertion.resource, - aligned_image.data, &page_lsn, &page_scn)) + assertion->common.logical_assertion.resource, aligned_image.data, &page_lsn, &page_scn)) return RESOURCE_X_APPLY_RECOVERY_BLOCKED; memset(&durable, 0, sizeof(durable)); durable.assertion = captured->assertion; durable.base_authority_generation = captured->base_authority_generation; durable.resource_formation = captured->resource_formation; - durable.master_session_incarnation - = captured->master_session_incarnation; + durable.master_session_incarnation = captured->master_session_incarnation; durable.assertion_sequence = captured->assertion_sequence; durable.requester_target_generation = captured->assertion_sequence; durable.page_scn_lsn = page_scn; - durable.page_checksum - = cluster_gcs_block_compute_checksum(aligned_image.data); - durable.source_proof_crc32c - = gcs_block_pcm_x_resource_x_durable_proof_crc(&durable); + durable.page_checksum = cluster_gcs_block_compute_checksum(aligned_image.data); + durable.source_proof_crc32c = gcs_block_pcm_x_resource_x_durable_proof_crc(&durable); if (durable.source_proof_crc32c == 0) return RESOURCE_X_APPLY_RECOVERY_BLOCKED; return cluster_pcm_lock_resource_x_durable_proof_exact(&durable, out); } static ResourceXApplyResult -gcs_block_pcm_x_resource_x_remote_s_own_result( - ClusterPcmOwnResult result) +gcs_block_pcm_x_resource_x_remote_s_own_result(ClusterPcmOwnResult result) { if (result == CLUSTER_PCM_OWN_OK) return RESOURCE_X_APPLY_APPLIED; @@ -11891,8 +11284,7 @@ gcs_block_resource_x_remote_s_own_result(ClusterPcmOwnResult result) } static void -gcs_block_resource_x_failure_decision_apply( - const ResourceXRemoteSFailureDecision *decision) +gcs_block_resource_x_failure_decision_apply(const ResourceXRemoteSFailureDecision *decision) { if (decision != NULL && decision->global_fail_closed) gcs_block_resource_x_fail_closed_current(); @@ -11997,8 +11389,8 @@ gcs_block_resource_x_next_diagnostic_request_sequence(void) } static bool -gcs_block_resource_x_first_failure_should_log( - const ResourceXFirstFailureEvidence *evidence, uint64 now_us) +gcs_block_resource_x_first_failure_should_log(const ResourceXFirstFailureEvidence *evidence, + uint64 now_us) { ResourceXFirstFailureLogIdentity identity; uint32 i; @@ -12009,18 +11401,17 @@ gcs_block_resource_x_first_failure_should_log( identity.tag = evidence->tag; identity.request_sequence = evidence->request_sequence; identity.admission_generation = evidence->admission_generation != 0 - ? evidence->admission_generation : evidence->r4_generation; + ? evidence->admission_generation + : evidence->r4_generation; identity.assertion_sequence = evidence->assertion_sequence; identity.formation = evidence->formation; identity.master_session = evidence->master_session; identity.requester_node = evidence->requester_node; identity.in_use = true; for (i = 0; i < RESOURCE_X_FIRST_FAILURE_LOG_SLOTS; i++) { - ResourceXFirstFailureLogIdentity *slot - = &resource_x_first_failure_log_slots[i]; + ResourceXFirstFailureLogIdentity *slot = &resource_x_first_failure_log_slots[i]; - if (slot->in_use - && BufferTagsEqual(&slot->tag, &identity.tag) + if (slot->in_use && BufferTagsEqual(&slot->tag, &identity.tag) && slot->request_sequence == identity.request_sequence && slot->admission_generation == identity.admission_generation && slot->assertion_sequence == identity.assertion_sequence @@ -12029,21 +11420,18 @@ gcs_block_resource_x_first_failure_should_log( && slot->requester_node == identity.requester_node) return false; } - resource_x_first_failure_log_slots[resource_x_first_failure_log_next_slot] - = identity; + resource_x_first_failure_log_slots[resource_x_first_failure_log_next_slot] = identity; resource_x_first_failure_log_next_slot - = (resource_x_first_failure_log_next_slot + 1) - % RESOURCE_X_FIRST_FAILURE_LOG_SLOTS; + = (resource_x_first_failure_log_next_slot + 1) % RESOURCE_X_FIRST_FAILURE_LOG_SLOTS; if (resource_x_first_failure_log_window_start_us == 0 || now_us < resource_x_first_failure_log_window_start_us || now_us - resource_x_first_failure_log_window_start_us - >= RESOURCE_X_FIRST_FAILURE_LOG_INTERVAL_US) { + >= RESOURCE_X_FIRST_FAILURE_LOG_INTERVAL_US) { resource_x_first_failure_log_window_start_us = now_us; resource_x_first_failure_log_window_count = 0; } - if (resource_x_first_failure_log_window_count - >= RESOURCE_X_FIRST_FAILURE_LOG_RATE_LIMIT) + if (resource_x_first_failure_log_window_count >= RESOURCE_X_FIRST_FAILURE_LOG_RATE_LIMIT) return false; resource_x_first_failure_log_window_count++; return true; @@ -12053,8 +11441,7 @@ gcs_block_resource_x_first_failure_should_log( * maps the result nor fences/retries the request. Callers invoke it at their * first local failure boundary after any exact rollback attempt has ended. */ static void -gcs_block_resource_x_first_failure_record( - const ResourceXFirstFailureEvidence *evidence) +gcs_block_resource_x_first_failure_record(const ResourceXFirstFailureEvidence *evidence) { PcmGrdLifecycleStats lifecycle; uint64 now_us; @@ -12069,20 +11456,17 @@ gcs_block_resource_x_first_failure_record( if (ClusterGcsBlock != NULL) { switch (evidence->failure_domain) { case RESOURCE_X_FAIL_PRE_MUTATION_BACKPRESSURE: - pg_atomic_fetch_add_u64( - &ClusterGcsBlock->resource_x_pre_mutation_backpressure_count, 1); + pg_atomic_fetch_add_u64(&ClusterGcsBlock->resource_x_pre_mutation_backpressure_count, + 1); break; case RESOURCE_X_FAIL_AUTHORITY_DRIFT: - pg_atomic_fetch_add_u64( - &ClusterGcsBlock->resource_x_authority_drift_count, 1); + pg_atomic_fetch_add_u64(&ClusterGcsBlock->resource_x_authority_drift_count, 1); break; case RESOURCE_X_FAIL_POST_MUTATION_AMBIGUITY: - pg_atomic_fetch_add_u64( - &ClusterGcsBlock->resource_x_post_mutation_ambiguity_count, 1); + pg_atomic_fetch_add_u64(&ClusterGcsBlock->resource_x_post_mutation_ambiguity_count, 1); break; case RESOURCE_X_FAIL_INTERNAL_CORRUPTION: - pg_atomic_fetch_add_u64( - &ClusterGcsBlock->resource_x_internal_corruption_count, 1); + pg_atomic_fetch_add_u64(&ClusterGcsBlock->resource_x_internal_corruption_count, 1); break; case RESOURCE_X_FAIL_NONE: break; @@ -12094,175 +11478,143 @@ gcs_block_resource_x_first_failure_record( cluster_pcm_grd_lifecycle_stats_snapshot(&lifecycle); live_entries = cluster_pcm_grd_count(); capacity_used = live_entries > 0 ? (uint32)live_entries : 0; - capacity_limit = cluster_pcm_grd_capacity() > 0 - ? (uint32)cluster_pcm_grd_capacity() : 0; - tag_hash = hash_any((const unsigned char *)&evidence->tag, - (int)sizeof(evidence->tag)); - ereport(LOG, + capacity_limit = cluster_pcm_grd_capacity() > 0 ? (uint32)cluster_pcm_grd_capacity() : 0; + tag_hash = hash_any((const unsigned char *)&evidence->tag, (int)sizeof(evidence->tag)); + ereport( + LOG, (errmsg_internal("Resource-X first-failure diagnostic"), - errdetail("tag_hash=%u binding_generation=%llu " - "request_sequence=%llu admission_generation=%llu " - "buffer_generation_before=%llu buffer_generation_after=%llu " - "buffer_token_before=%llu buffer_token_after=%llu " - "buffer_writer_token_before=%llu buffer_writer_token_after=%llu " - "buffer_resource_x_generation_before=%llu " - "buffer_resource_x_generation_after=%llu " - "buffer_flags_before=0x%08x buffer_flags_after=0x%08x " - "buffer_pcm_state_before=%u buffer_pcm_state_after=%u " - "buffer_own_result=%d " - "formation=%llu master_session=%llu r4_generation=%llu " - "base_authority_generation=%llu authority_generation=%llu " - "assertion_sequence=%llu remote_s_stage=%u " - "source_settlement_stage=%u source_settlement_own_result=%d " - "source_settlement_commit_stage=%u " - "source_settlement_commit_mismatch=0x%08x " - "source_settlement_current_formation=%llu " - "source_settlement_current_master=%d " - "source_settlement_current_session=%llu " - "source_settlement_current_terminal_authority=%llu " - "source_settlement_current_cached_generation=%llu " - "source_settlement_current_round_phase=%u " - "source_settlement_current_owner_state=%u " - "source_settlement_pair_formation=%llu " - "source_settlement_pair_session=%llu " - "source_settlement_pair_sequence=%llu " - "source_settlement_pair_source_generation=%llu " - "source_settlement_pair_observed_mode=%u " - "source_settlement_pair_destination=%u " - "source_settlement_pair_status_valid=%u " - "source_settlement_pair_image_valid=%u " - "source_settlement_status_intent=%u " - "source_settlement_image_intent=%u " - "failure_domain=%u " - "result=%d holder_mutation_started=%s revoke_reversible=%s " - "rollback_cancel_ok=%s rollback_abort_ok=%s " - "status_staged=%s status_published=%s " - "proof_staged=%s proof_published=%s " - "round_terminal=%s round_phase=%u round_progress_flags=0x%08x " - "capacity_kind=%s capacity_used=%u capacity_limit=%u " - "reclaim_attempts=%llu reclaim_successes=%llu " - "reclaim_reuses=%llu capacity_retries=%llu " - "capacity_failures=%llu refused_pcm_mode=%llu " - "refused_holder=%llu refused_pi=%llu refused_watermark=%llu " - "refused_resource_x=%llu refused_retained=%llu " - "refused_requester=%llu refused_sidecar=%llu " - "deadline=%llu", - tag_hash, - (unsigned long long)evidence->binding_generation, - (unsigned long long)evidence->request_sequence, - (unsigned long long)(evidence->admission_generation != 0 - ? evidence->admission_generation - : evidence->r4_generation), - (unsigned long long)evidence->buffer_generation_before, - (unsigned long long)evidence->buffer_generation_after, - (unsigned long long)evidence->buffer_token_before, - (unsigned long long)evidence->buffer_token_after, - (unsigned long long)evidence->buffer_writer_token_before, - (unsigned long long)evidence->buffer_writer_token_after, - (unsigned long long) - evidence->buffer_resource_x_generation_before, - (unsigned long long) - evidence->buffer_resource_x_generation_after, - evidence->buffer_flags_before, - evidence->buffer_flags_after, - (unsigned)evidence->buffer_pcm_state_before, - (unsigned)evidence->buffer_pcm_state_after, - evidence->remote_s_stage != RESOURCE_X_REMOTE_S_STAGE_NONE - ? evidence->buffer_own_result : -1, - (unsigned long long)evidence->formation, - (unsigned long long)evidence->master_session, - (unsigned long long)evidence->r4_generation, - (unsigned long long)evidence->base_authority_generation, - (unsigned long long)evidence->authority_generation, - (unsigned long long)evidence->assertion_sequence, - (unsigned)evidence->remote_s_stage, - (unsigned)evidence->source_settlement_stage, - evidence->source_settlement_stage - != RESOURCE_X_SOURCE_SETTLEMENT_STAGE_NONE - ? evidence->source_settlement_own_result : -1, - (unsigned)evidence->source_settlement_commit.commit_stage, - evidence->source_settlement_commit.mismatch_mask, - (unsigned long long)evidence->source_settlement_commit - .current_resource_formation, - evidence->source_settlement_commit.current_master_node, - (unsigned long long)evidence->source_settlement_commit - .current_master_session, - (unsigned long long)evidence->source_settlement_commit - .current_terminal_authority_generation, - (unsigned long long)evidence->source_settlement_commit - .current_cached_ownership_generation, - (unsigned)evidence->source_settlement_commit - .current_round_phase, - (unsigned)evidence->source_settlement_commit.current_owner_state, - (unsigned long long)evidence->source_settlement_commit - .current_pair_resource_formation, - (unsigned long long)evidence->source_settlement_commit - .current_pair_master_session, - (unsigned long long)evidence->source_settlement_commit - .current_pair_assertion_sequence, - (unsigned long long)evidence->source_settlement_commit - .current_pair_source_generation, - (unsigned)evidence->source_settlement_commit - .current_pair_observed_mode, - evidence->source_settlement_commit - .current_pair_destination_node, - (unsigned)evidence->source_settlement_commit - .current_holder_status_valid, - (unsigned)evidence->source_settlement_commit - .current_holder_image_valid, - (unsigned)evidence->source_settlement_commit - .current_status_intent_state, - (unsigned)evidence->source_settlement_commit - .current_image_intent_state, - (unsigned)evidence->failure_domain, - (int)evidence->result, - evidence->holder_mutation_started ? "true" : "false", - evidence->revoke_reversible ? "true" : "false", - gcs_block_resource_x_rollback_outcome( - evidence->rollback_cancel_attempted, - evidence->rollback_cancel_ok), - gcs_block_resource_x_rollback_outcome( - evidence->rollback_abort_attempted, - evidence->rollback_abort_ok), - evidence->status_staged ? "true" : "false", - evidence->status_published ? "true" : "false", - evidence->proof_staged ? "true" : "false", - evidence->proof_published ? "true" : "false", - evidence->round_terminal ? "true" : "false", - (unsigned)evidence->round_phase, - evidence->round_progress_flags, - "pcm_grd_live", - capacity_used, - capacity_limit, - (unsigned long long)lifecycle.reclaim_attempt_count, - (unsigned long long)lifecycle.reclaim_success_count, - (unsigned long long)lifecycle.reclaim_reuse_count, - (unsigned long long)lifecycle.capacity_retry_count, - (unsigned long long)lifecycle.capacity_fail_count, - (unsigned long long)lifecycle.reclaim_refused[ - PCM_RETIRE_REFUSAL_PCM_MODE_NOT_N], - (unsigned long long)lifecycle.reclaim_refused[ - PCM_RETIRE_REFUSAL_HOLDER_PRESENT], - (unsigned long long)lifecycle.reclaim_refused[ - PCM_RETIRE_REFUSAL_PI_PRESENT], - (unsigned long long)lifecycle.reclaim_refused[ - PCM_RETIRE_REFUSAL_WATERMARK_PRESENT], - (unsigned long long)lifecycle.reclaim_refused[ - PCM_RETIRE_REFUSAL_RESOURCE_X_ACTIVE], - (unsigned long long)lifecycle.reclaim_refused[ - PCM_RETIRE_REFUSAL_RETAINED_PAIR_PRESENT], - (unsigned long long)lifecycle.reclaim_refused[ - PCM_RETIRE_REFUSAL_REQUESTER_NOT_TERMINAL], - (unsigned long long)lifecycle.reclaim_refused[ - PCM_RETIRE_REFUSAL_SIDECAR_NOT_TERMINAL], - (unsigned long long)evidence->absolute_deadline_us))); + errdetail( + "tag_hash=%u binding_generation=%llu " + "request_sequence=%llu admission_generation=%llu " + "buffer_generation_before=%llu buffer_generation_after=%llu " + "buffer_token_before=%llu buffer_token_after=%llu " + "buffer_writer_token_before=%llu buffer_writer_token_after=%llu " + "buffer_resource_x_generation_before=%llu " + "buffer_resource_x_generation_after=%llu " + "buffer_flags_before=0x%08x buffer_flags_after=0x%08x " + "buffer_pcm_state_before=%u buffer_pcm_state_after=%u " + "buffer_own_result=%d " + "formation=%llu master_session=%llu r4_generation=%llu " + "base_authority_generation=%llu authority_generation=%llu " + "assertion_sequence=%llu remote_s_stage=%u " + "source_settlement_stage=%u source_settlement_own_result=%d " + "source_settlement_commit_stage=%u " + "source_settlement_commit_mismatch=0x%08x " + "source_settlement_current_formation=%llu " + "source_settlement_current_master=%d " + "source_settlement_current_session=%llu " + "source_settlement_current_terminal_authority=%llu " + "source_settlement_current_cached_generation=%llu " + "source_settlement_current_round_phase=%u " + "source_settlement_current_owner_state=%u " + "source_settlement_pair_formation=%llu " + "source_settlement_pair_session=%llu " + "source_settlement_pair_sequence=%llu " + "source_settlement_pair_source_generation=%llu " + "source_settlement_pair_observed_mode=%u " + "source_settlement_pair_destination=%u " + "source_settlement_pair_status_valid=%u " + "source_settlement_pair_image_valid=%u " + "source_settlement_status_intent=%u " + "source_settlement_image_intent=%u " + "failure_domain=%u " + "result=%d holder_mutation_started=%s revoke_reversible=%s " + "rollback_cancel_ok=%s rollback_abort_ok=%s " + "status_staged=%s status_published=%s " + "proof_staged=%s proof_published=%s " + "round_terminal=%s round_phase=%u round_progress_flags=0x%08x " + "capacity_kind=%s capacity_used=%u capacity_limit=%u " + "reclaim_attempts=%llu reclaim_successes=%llu " + "reclaim_reuses=%llu capacity_retries=%llu " + "capacity_failures=%llu refused_pcm_mode=%llu " + "refused_holder=%llu refused_pi=%llu refused_watermark=%llu " + "refused_resource_x=%llu refused_retained=%llu " + "refused_requester=%llu refused_sidecar=%llu " + "deadline=%llu", + tag_hash, (unsigned long long)evidence->binding_generation, + (unsigned long long)evidence->request_sequence, + (unsigned long long)(evidence->admission_generation != 0 + ? evidence->admission_generation + : evidence->r4_generation), + (unsigned long long)evidence->buffer_generation_before, + (unsigned long long)evidence->buffer_generation_after, + (unsigned long long)evidence->buffer_token_before, + (unsigned long long)evidence->buffer_token_after, + (unsigned long long)evidence->buffer_writer_token_before, + (unsigned long long)evidence->buffer_writer_token_after, + (unsigned long long)evidence->buffer_resource_x_generation_before, + (unsigned long long)evidence->buffer_resource_x_generation_after, + evidence->buffer_flags_before, evidence->buffer_flags_after, + (unsigned)evidence->buffer_pcm_state_before, + (unsigned)evidence->buffer_pcm_state_after, + evidence->remote_s_stage != RESOURCE_X_REMOTE_S_STAGE_NONE + ? evidence->buffer_own_result + : -1, + (unsigned long long)evidence->formation, (unsigned long long)evidence->master_session, + (unsigned long long)evidence->r4_generation, + (unsigned long long)evidence->base_authority_generation, + (unsigned long long)evidence->authority_generation, + (unsigned long long)evidence->assertion_sequence, (unsigned)evidence->remote_s_stage, + (unsigned)evidence->source_settlement_stage, + evidence->source_settlement_stage != RESOURCE_X_SOURCE_SETTLEMENT_STAGE_NONE + ? evidence->source_settlement_own_result + : -1, + (unsigned)evidence->source_settlement_commit.commit_stage, + evidence->source_settlement_commit.mismatch_mask, + (unsigned long long)evidence->source_settlement_commit.current_resource_formation, + evidence->source_settlement_commit.current_master_node, + (unsigned long long)evidence->source_settlement_commit.current_master_session, + (unsigned long long) + evidence->source_settlement_commit.current_terminal_authority_generation, + (unsigned long long) + evidence->source_settlement_commit.current_cached_ownership_generation, + (unsigned)evidence->source_settlement_commit.current_round_phase, + (unsigned)evidence->source_settlement_commit.current_owner_state, + (unsigned long long)evidence->source_settlement_commit.current_pair_resource_formation, + (unsigned long long)evidence->source_settlement_commit.current_pair_master_session, + (unsigned long long)evidence->source_settlement_commit.current_pair_assertion_sequence, + (unsigned long long)evidence->source_settlement_commit.current_pair_source_generation, + (unsigned)evidence->source_settlement_commit.current_pair_observed_mode, + evidence->source_settlement_commit.current_pair_destination_node, + (unsigned)evidence->source_settlement_commit.current_holder_status_valid, + (unsigned)evidence->source_settlement_commit.current_holder_image_valid, + (unsigned)evidence->source_settlement_commit.current_status_intent_state, + (unsigned)evidence->source_settlement_commit.current_image_intent_state, + (unsigned)evidence->failure_domain, (int)evidence->result, + evidence->holder_mutation_started ? "true" : "false", + evidence->revoke_reversible ? "true" : "false", + gcs_block_resource_x_rollback_outcome(evidence->rollback_cancel_attempted, + evidence->rollback_cancel_ok), + gcs_block_resource_x_rollback_outcome(evidence->rollback_abort_attempted, + evidence->rollback_abort_ok), + evidence->status_staged ? "true" : "false", + evidence->status_published ? "true" : "false", + evidence->proof_staged ? "true" : "false", + evidence->proof_published ? "true" : "false", + evidence->round_terminal ? "true" : "false", (unsigned)evidence->round_phase, + evidence->round_progress_flags, "pcm_grd_live", capacity_used, capacity_limit, + (unsigned long long)lifecycle.reclaim_attempt_count, + (unsigned long long)lifecycle.reclaim_success_count, + (unsigned long long)lifecycle.reclaim_reuse_count, + (unsigned long long)lifecycle.capacity_retry_count, + (unsigned long long)lifecycle.capacity_fail_count, + (unsigned long long)lifecycle.reclaim_refused[PCM_RETIRE_REFUSAL_PCM_MODE_NOT_N], + (unsigned long long)lifecycle.reclaim_refused[PCM_RETIRE_REFUSAL_HOLDER_PRESENT], + (unsigned long long)lifecycle.reclaim_refused[PCM_RETIRE_REFUSAL_PI_PRESENT], + (unsigned long long)lifecycle.reclaim_refused[PCM_RETIRE_REFUSAL_WATERMARK_PRESENT], + (unsigned long long)lifecycle.reclaim_refused[PCM_RETIRE_REFUSAL_RESOURCE_X_ACTIVE], + (unsigned long long) + lifecycle.reclaim_refused[PCM_RETIRE_REFUSAL_RETAINED_PAIR_PRESENT], + (unsigned long long) + lifecycle.reclaim_refused[PCM_RETIRE_REFUSAL_REQUESTER_NOT_TERMINAL], + (unsigned long long)lifecycle.reclaim_refused[PCM_RETIRE_REFUSAL_SIDECAR_NOT_TERMINAL], + (unsigned long long)evidence->absolute_deadline_us))); } static ResourceXFailureDomain gcs_block_resource_x_pre_mutation_domain(ClusterPcmOwnResult own_result) { - if (own_result == CLUSTER_PCM_OWN_BUSY - || own_result == CLUSTER_PCM_OWN_NOT_READY) + if (own_result == CLUSTER_PCM_OWN_BUSY || own_result == CLUSTER_PCM_OWN_NOT_READY) return RESOURCE_X_FAIL_PRE_MUTATION_BACKPRESSURE; if (own_result == CLUSTER_PCM_OWN_STALE) return RESOURCE_X_FAIL_AUTHORITY_DRIFT; @@ -12270,54 +11622,46 @@ gcs_block_resource_x_pre_mutation_domain(ClusterPcmOwnResult own_result) } static ResourceXFailureDomain -gcs_block_resource_x_target_failure_domain( - ResourceXApplyResult result, ResourceXApplyResult round_snapshot_result, - const ResourceXBootstrapRoundFailureSnapshot *round, - ClusterPcmOwnResult live_snapshot_result) +gcs_block_resource_x_target_failure_domain(ResourceXApplyResult result, + ResourceXApplyResult round_snapshot_result, + const ResourceXBootstrapRoundFailureSnapshot *round, + ClusterPcmOwnResult live_snapshot_result) { if (live_snapshot_result == CLUSTER_PCM_OWN_CORRUPT || live_snapshot_result == CLUSTER_PCM_OWN_NOT_READY || round_snapshot_result == RESOURCE_X_APPLY_RECOVERY_BLOCKED || round_snapshot_result == RESOURCE_X_APPLY_INVALID) return RESOURCE_X_FAIL_INTERNAL_CORRUPTION; - if (round_snapshot_result == RESOURCE_X_APPLY_STALE - || result == RESOURCE_X_APPLY_STALE) + if (round_snapshot_result == RESOURCE_X_APPLY_STALE || result == RESOURCE_X_APPLY_STALE) return RESOURCE_X_FAIL_AUTHORITY_DRIFT; - if (round_snapshot_result == RESOURCE_X_APPLY_APPLIED - && round != NULL) { + if (round_snapshot_result == RESOURCE_X_APPLY_APPLIED && round != NULL) { if ((round->progress_flags & RESOURCE_X_PROGRESS_T2) != 0) return RESOURCE_X_FAIL_POST_MUTATION_AMBIGUITY; - if (round->terminal != 0 - || (round->progress_flags & RESOURCE_X_PROGRESS_T1) != 0) + if (round->terminal != 0 || (round->progress_flags & RESOURCE_X_PROGRESS_T1) != 0) return RESOURCE_X_FAIL_AUTHORITY_DRIFT; } - if (result == RESOURCE_X_APPLY_BAD_STATE - || result == RESOURCE_X_APPLY_NOT_FOUND) + if (result == RESOURCE_X_APPLY_BAD_STATE || result == RESOURCE_X_APPLY_NOT_FOUND) return RESOURCE_X_FAIL_PRE_MUTATION_BACKPRESSURE; return RESOURCE_X_FAIL_INTERNAL_CORRUPTION; } static void -gcs_block_resource_x_first_failure_from_block( - ResourceXFirstFailureEvidence *evidence, - const ResourceXDecodedFrame *block, ResourceXRemoteSStage stage, - ResourceXFailureDomain domain, ResourceXApplyResult result) +gcs_block_resource_x_first_failure_from_block(ResourceXFirstFailureEvidence *evidence, + const ResourceXDecodedFrame *block, + ResourceXRemoteSStage stage, + ResourceXFailureDomain domain, + ResourceXApplyResult result) { memset(evidence, 0, sizeof(*evidence)); if (block != NULL) { evidence->tag = block->common.logical_assertion.resource; - evidence->base_authority_generation - = block->common.base_authority_generation; - evidence->authority_generation - = block->common.authority_generation; - evidence->assertion_sequence - = block->common.assertion_sequence; + evidence->base_authority_generation = block->common.base_authority_generation; + evidence->authority_generation = block->common.authority_generation; + evidence->assertion_sequence = block->common.assertion_sequence; evidence->request_sequence = block->common.assertion_sequence; - evidence->requester_node - = block->common.logical_assertion.requester_node; + evidence->requester_node = block->common.logical_assertion.requester_node; evidence->formation = block->common.resource_formation; - evidence->master_session - = block->common.master_session_incarnation; + evidence->master_session = block->common.master_session_incarnation; } evidence->remote_s_stage = stage; evidence->buffer_own_result = -1; @@ -12327,8 +11671,7 @@ gcs_block_resource_x_first_failure_from_block( } static ResourceXFailureDomain -gcs_block_resource_x_source_settlement_apply_domain( - ResourceXApplyResult result) +gcs_block_resource_x_source_settlement_apply_domain(ResourceXApplyResult result) { if (result == RESOURCE_X_APPLY_BAD_STATE) return RESOURCE_X_FAIL_PRE_MUTATION_BACKPRESSURE; @@ -12338,16 +11681,14 @@ gcs_block_resource_x_source_settlement_apply_domain( } static ResourceXFailureDomain -gcs_block_resource_x_source_settlement_own_domain( - ClusterPcmOwnResult own_result, bool release_applied) +gcs_block_resource_x_source_settlement_own_domain(ClusterPcmOwnResult own_result, + bool release_applied) { - if (own_result == CLUSTER_PCM_OWN_CORRUPT - || own_result == CLUSTER_PCM_OWN_INVALID) + if (own_result == CLUSTER_PCM_OWN_CORRUPT || own_result == CLUSTER_PCM_OWN_INVALID) return RESOURCE_X_FAIL_INTERNAL_CORRUPTION; if (release_applied) return RESOURCE_X_FAIL_POST_MUTATION_AMBIGUITY; - if (own_result == CLUSTER_PCM_OWN_BUSY - || own_result == CLUSTER_PCM_OWN_NOT_READY) + if (own_result == CLUSTER_PCM_OWN_BUSY || own_result == CLUSTER_PCM_OWN_NOT_READY) return RESOURCE_X_FAIL_PRE_MUTATION_BACKPRESSURE; if (own_result == CLUSTER_PCM_OWN_STALE) return RESOURCE_X_FAIL_AUTHORITY_DRIFT; @@ -12358,29 +11699,24 @@ static void gcs_block_resource_x_source_settlement_failure_record( const ResourceXDecodedFrame *settlement, const ResourceXSourceSettlementCommitObservation *commit_observation, - ResourceXSourceSettlementStage source_settlement_stage, - ResourceXFailureDomain failure_domain, ResourceXApplyResult result, - uint64 source_generation, int32 source_settlement_own_result, + ResourceXSourceSettlementStage source_settlement_stage, ResourceXFailureDomain failure_domain, + ResourceXApplyResult result, uint64 source_generation, int32 source_settlement_own_result, bool release_applied, bool status_staged) { ClusterSemanticR11CutoverSnapshot cutover; ResourceXFirstFailureEvidence first_failure; gcs_block_resource_x_first_failure_from_block( - &first_failure, settlement, RESOURCE_X_REMOTE_S_STAGE_NONE, - failure_domain, result); + &first_failure, settlement, RESOURCE_X_REMOTE_S_STAGE_NONE, failure_domain, result); first_failure.source_settlement_stage = source_settlement_stage; - first_failure.source_settlement_own_result - = source_settlement_own_result; + first_failure.source_settlement_own_result = source_settlement_own_result; if (commit_observation != NULL) first_failure.source_settlement_commit = *commit_observation; first_failure.binding_generation = source_generation; first_failure.holder_mutation_started = release_applied; first_failure.status_staged = status_staged; - if (settlement != NULL - && cluster_semantic_activation_r11_cutover_snapshot(&cutover) - && cutover.formation_epoch - == settlement->common.resource_formation) { + if (settlement != NULL && cluster_semantic_activation_r11_cutover_snapshot(&cutover) + && cutover.formation_epoch == settlement->common.resource_formation) { first_failure.admission_generation = cutover.record_generation; first_failure.r4_generation = cutover.record_generation; } @@ -12444,10 +11780,8 @@ gcs_block_resource_x_remote_s_authority_result_exact(const ResourceXDecodedFrame * registry exists. */ static ResourceXApplyResult gcs_block_pcm_x_resource_x_remote_s_holder_block_to_n( - const ResourceXDecodedFrame *block, - int32 authenticated_master_node, - uint32 authenticated_capability_generation, - uint64 r4_record_generation, + const ResourceXDecodedFrame *block, int32 authenticated_master_node, + uint32 authenticated_capability_generation, uint64 r4_record_generation, const ClusterSemanticAdmissionToken *admission) { BufferDesc *buf; @@ -12462,8 +11796,7 @@ gcs_block_pcm_x_resource_x_remote_s_holder_block_to_n( LWLock *content_lock; ResourceXDecodedFrame status; ResourceXFirstFailureEvidence first_failure; - ResourceXRemoteSStage remote_s_stage - = RESOURCE_X_REMOTE_S_STAGE_VALIDATE; + ResourceXRemoteSStage remote_s_stage = RESOURCE_X_REMOTE_S_STAGE_VALIDATE; ResourceXFailureDomain failure_domain = RESOURCE_X_FAIL_NONE; ResourceXRemoteSFailureDecision failure_decision; ResourceXApplyResult mapped_result; @@ -12481,33 +11814,23 @@ gcs_block_pcm_x_resource_x_remote_s_holder_block_to_n( || !resource_x_assertion_valid(&block->common.logical_assertion) || authenticated_master_node < 0 || authenticated_master_node >= RESOURCE_X_PROTOCOL_NODE_LIMIT - || authenticated_capability_generation == 0 - || r4_record_generation == 0 - || r4_record_generation == UINT64_MAX - || admission == NULL || !admission->entered - || admission->record_generation != r4_record_generation - || cluster_node_id < 0 + || authenticated_capability_generation == 0 || r4_record_generation == 0 + || r4_record_generation == UINT64_MAX || admission == NULL || !admission->entered + || admission->record_generation != r4_record_generation || cluster_node_id < 0 || cluster_node_id >= RESOURCE_X_PROTOCOL_NODE_LIMIT || block->common.logical_assertion.requester_node == cluster_node_id || block->common.action_node != cluster_node_id || block->common.base_authority_generation == 0 || block->common.base_authority_generation == UINT64_MAX - || block->common.authority_generation - != block->common.base_authority_generation - || block->common.resource_formation == 0 - || block->common.master_session_incarnation == 0 - || block->common.assertion_sequence == 0 - || block->common.sender_connection_generation == 0 + || block->common.authority_generation != block->common.base_authority_generation + || block->common.resource_formation == 0 || block->common.master_session_incarnation == 0 + || block->common.assertion_sequence == 0 || block->common.sender_connection_generation == 0 || block->common.observed_mode != (uint8)PCM_STATE_S - || block->common.target_mode != (uint8)PCM_STATE_N - || block->common.source_candidate != 0 - || block->common.retain_pi_if_dirty != 0 - || block->common.outcome != RESOURCE_X_OUTCOME_NONE - || cluster_gcs_lookup_master( - block->common.logical_assertion.resource) + || block->common.target_mode != (uint8)PCM_STATE_N || block->common.source_candidate != 0 + || block->common.retain_pi_if_dirty != 0 || block->common.outcome != RESOURCE_X_OUTCOME_NONE + || cluster_gcs_lookup_master(block->common.logical_assertion.resource) != authenticated_master_node - || !cluster_pcm_lock_resource_x_gate_open_exact( - block->common.resource_formation)) + || !cluster_pcm_lock_resource_x_gate_open_exact(block->common.resource_formation)) return RESOURCE_X_APPLY_INVALID; mapped_result = gcs_block_resource_x_remote_s_authority_result_exact( block, authenticated_master_node, authenticated_capability_generation, admission); @@ -12529,38 +11852,30 @@ gcs_block_pcm_x_resource_x_remote_s_holder_block_to_n( remote_s_stage = RESOURCE_X_REMOTE_S_STAGE_SNAPSHOT; memset(¤t, 0, sizeof(current)); - own_result = cluster_bufmgr_pcm_own_snapshot_by_tag( - &block->common.logical_assertion.resource, &buffer_id, ¤t); + own_result = cluster_bufmgr_pcm_own_snapshot_by_tag(&block->common.logical_assertion.resource, + &buffer_id, ¤t); if (own_result != CLUSTER_PCM_OWN_OK || buffer_id < 0) { if (own_result == CLUSTER_PCM_OWN_OK) own_result = CLUSTER_PCM_OWN_CORRUPT; mapped_result = gcs_block_resource_x_remote_s_own_result(own_result); failure_domain = gcs_block_resource_x_pre_mutation_domain(own_result); - failure_decision - = cluster_gcs_resource_x_remote_s_failure_decide( - remote_s_stage, failure_domain, - false, false, false, false); - gcs_block_resource_x_first_failure_from_block( - &first_failure, block, remote_s_stage, failure_decision.domain, - mapped_result); + failure_decision = cluster_gcs_resource_x_remote_s_failure_decide( + remote_s_stage, failure_domain, false, false, false, false); + gcs_block_resource_x_first_failure_from_block(&first_failure, block, remote_s_stage, + failure_decision.domain, mapped_result); first_failure.r4_generation = r4_record_generation; gcs_block_resource_x_first_failure_record(&first_failure); gcs_block_resource_x_failure_decision_apply(&failure_decision); return mapped_result; } - if (current.pcm_state == (uint8)PCM_STATE_N - && current.flags == PCM_OWN_FLAG_GRANT_PENDING) { - own_result - = cluster_pcm_x_remote_s_holder_pending_grant_result(¤t); + if (current.pcm_state == (uint8)PCM_STATE_N && current.flags == PCM_OWN_FLAG_GRANT_PENDING) { + own_result = cluster_pcm_x_remote_s_holder_pending_grant_result(¤t); mapped_result = gcs_block_resource_x_remote_s_own_result(own_result); failure_domain = gcs_block_resource_x_pre_mutation_domain(own_result); - failure_decision - = cluster_gcs_resource_x_remote_s_failure_decide( - remote_s_stage, failure_domain, - false, false, false, false); - gcs_block_resource_x_first_failure_from_block( - &first_failure, block, remote_s_stage, failure_decision.domain, - mapped_result); + failure_decision = cluster_gcs_resource_x_remote_s_failure_decide( + remote_s_stage, failure_domain, false, false, false, false); + gcs_block_resource_x_first_failure_from_block(&first_failure, block, remote_s_stage, + failure_decision.domain, mapped_result); first_failure.r4_generation = r4_record_generation; first_failure.buffer_generation_before = current.generation; first_failure.buffer_generation_after = current.generation; @@ -12575,32 +11890,24 @@ gcs_block_pcm_x_resource_x_remote_s_holder_block_to_n( * existing status shape on the current connection. This branch never * claims a BufferDesc/PCM owner or changes the local page state. */ memset(&revalidated, 0, sizeof(revalidated)); - own_result - = cluster_pcm_x_remote_s_holder_stable_n_result(¤t); + own_result = cluster_pcm_x_remote_s_holder_stable_n_result(¤t); if (own_result == CLUSTER_PCM_OWN_OK) - own_result = cluster_bufmgr_pcm_own_n_assertion_candidate_exact( - buf, ¤t, &revalidated); + own_result + = cluster_bufmgr_pcm_own_n_assertion_candidate_exact(buf, ¤t, &revalidated); if (own_result != CLUSTER_PCM_OWN_OK) { - mapped_result - = gcs_block_resource_x_remote_s_own_result(own_result); - failure_domain - = gcs_block_resource_x_pre_mutation_domain(own_result); - failure_decision - = cluster_gcs_resource_x_remote_s_failure_decide( - remote_s_stage, failure_domain, - false, false, false, false); - gcs_block_resource_x_first_failure_from_block( - &first_failure, block, remote_s_stage, - failure_decision.domain, mapped_result); + mapped_result = gcs_block_resource_x_remote_s_own_result(own_result); + failure_domain = gcs_block_resource_x_pre_mutation_domain(own_result); + failure_decision = cluster_gcs_resource_x_remote_s_failure_decide( + remote_s_stage, failure_domain, false, false, false, false); + gcs_block_resource_x_first_failure_from_block(&first_failure, block, remote_s_stage, + failure_decision.domain, mapped_result); first_failure.r4_generation = r4_record_generation; first_failure.buffer_generation_before = current.generation; first_failure.buffer_generation_after = revalidated.generation; first_failure.buffer_token_before = current.reservation_token; first_failure.buffer_token_after = revalidated.reservation_token; - first_failure.buffer_writer_token_before - = current.writer_activation_token; - first_failure.buffer_writer_token_after - = revalidated.writer_activation_token; + first_failure.buffer_writer_token_before = current.writer_activation_token; + first_failure.buffer_writer_token_after = revalidated.writer_activation_token; first_failure.buffer_resource_x_generation_before = current.resource_x_activation_generation; first_failure.buffer_resource_x_generation_after @@ -12644,21 +11951,16 @@ gcs_block_pcm_x_resource_x_remote_s_holder_block_to_n( status.common.action_node = cluster_node_id; status.common.source_candidate = 0; status.common.retain_pi_if_dirty = 0; - status.common.sender_connection_generation - = outbound_connection_generation; + status.common.sender_connection_generation = outbound_connection_generation; status.common.outcome = RESOURCE_X_OUTCOME_OK; - if (!cluster_resource_x_wire_encode( - RESOURCE_X_MSG_BLOCKED_TO_N, &status, payload, - sizeof(payload), &payload_len, &reject) + if (!cluster_resource_x_wire_encode(RESOURCE_X_MSG_BLOCKED_TO_N, &status, payload, + sizeof(payload), &payload_len, &reject) || payload_len != RESOURCE_X_CONTROL_V1_BYTES) { - failure_decision - = cluster_gcs_resource_x_remote_s_failure_decide( - remote_s_stage, RESOURCE_X_FAIL_INTERNAL_CORRUPTION, - false, false, false, false); - gcs_block_resource_x_first_failure_from_block( - &first_failure, block, remote_s_stage, - failure_decision.domain, - RESOURCE_X_APPLY_RECOVERY_BLOCKED); + failure_decision = cluster_gcs_resource_x_remote_s_failure_decide( + remote_s_stage, RESOURCE_X_FAIL_INTERNAL_CORRUPTION, false, false, false, false); + gcs_block_resource_x_first_failure_from_block(&first_failure, block, remote_s_stage, + failure_decision.domain, + RESOURCE_X_APPLY_RECOVERY_BLOCKED); first_failure.r4_generation = r4_record_generation; first_failure.buffer_generation_before = current.generation; first_failure.buffer_generation_after = revalidated.generation; @@ -12666,17 +11968,14 @@ gcs_block_pcm_x_resource_x_remote_s_holder_block_to_n( gcs_block_resource_x_failure_decision_apply(&failure_decision); return RESOURCE_X_APPLY_RECOVERY_BLOCKED; } - worker_id = cluster_lms_shard_for_tag( - &block->common.logical_assertion.resource, cluster_lms_workers); + worker_id = cluster_lms_shard_for_tag(&block->common.logical_assertion.resource, + cluster_lms_workers); if (worker_id < 0 || worker_id >= cluster_lms_workers) { - failure_decision - = cluster_gcs_resource_x_remote_s_failure_decide( - remote_s_stage, RESOURCE_X_FAIL_INTERNAL_CORRUPTION, - false, false, false, false); - gcs_block_resource_x_first_failure_from_block( - &first_failure, block, remote_s_stage, - failure_decision.domain, - RESOURCE_X_APPLY_RECOVERY_BLOCKED); + failure_decision = cluster_gcs_resource_x_remote_s_failure_decide( + remote_s_stage, RESOURCE_X_FAIL_INTERNAL_CORRUPTION, false, false, false, false); + gcs_block_resource_x_first_failure_from_block(&first_failure, block, remote_s_stage, + failure_decision.domain, + RESOURCE_X_APPLY_RECOVERY_BLOCKED); first_failure.r4_generation = r4_record_generation; first_failure.buffer_generation_before = current.generation; first_failure.buffer_generation_after = revalidated.generation; @@ -12711,18 +12010,15 @@ gcs_block_pcm_x_resource_x_remote_s_holder_block_to_n( return mapped_result; } if (!cluster_lms_outbound_enqueue_cap_bound( - worker_id, RESOURCE_X_MSG_BLOCKED_TO_N, - (uint32)authenticated_master_node, payload, payload_len, - PGRAC_IC_HELLO_CAP_GCS_RESOURCE_X_CONVERT_V1, + worker_id, RESOURCE_X_MSG_BLOCKED_TO_N, (uint32)authenticated_master_node, payload, + payload_len, PGRAC_IC_HELLO_CAP_GCS_RESOURCE_X_CONVERT_V1, outbound_connection_generation)) { - failure_decision - = cluster_gcs_resource_x_remote_s_failure_decide( - remote_s_stage, - RESOURCE_X_FAIL_PRE_MUTATION_BACKPRESSURE, - false, false, false, false); - gcs_block_resource_x_first_failure_from_block( - &first_failure, block, remote_s_stage, - failure_decision.domain, RESOURCE_X_APPLY_BAD_STATE); + failure_decision = cluster_gcs_resource_x_remote_s_failure_decide( + remote_s_stage, RESOURCE_X_FAIL_PRE_MUTATION_BACKPRESSURE, false, false, false, + false); + gcs_block_resource_x_first_failure_from_block(&first_failure, block, remote_s_stage, + failure_decision.domain, + RESOURCE_X_APPLY_BAD_STATE); first_failure.r4_generation = r4_record_generation; first_failure.buffer_generation_before = current.generation; first_failure.buffer_generation_after = revalidated.generation; @@ -12732,18 +12028,14 @@ gcs_block_pcm_x_resource_x_remote_s_holder_block_to_n( } return RESOURCE_X_APPLY_APPLIED; } - own_result = cluster_bufmgr_pcm_own_s_holder_candidate_exact( - buf, ¤t); + own_result = cluster_bufmgr_pcm_own_s_holder_candidate_exact(buf, ¤t); if (own_result != CLUSTER_PCM_OWN_OK) { mapped_result = gcs_block_resource_x_remote_s_own_result(own_result); failure_domain = gcs_block_resource_x_pre_mutation_domain(own_result); - failure_decision - = cluster_gcs_resource_x_remote_s_failure_decide( - remote_s_stage, failure_domain, - false, false, false, false); - gcs_block_resource_x_first_failure_from_block( - &first_failure, block, remote_s_stage, failure_decision.domain, - mapped_result); + failure_decision = cluster_gcs_resource_x_remote_s_failure_decide( + remote_s_stage, failure_domain, false, false, false, false); + gcs_block_resource_x_first_failure_from_block(&first_failure, block, remote_s_stage, + failure_decision.domain, mapped_result); first_failure.r4_generation = r4_record_generation; first_failure.buffer_generation_before = current.generation; first_failure.buffer_generation_after = current.generation; @@ -12760,18 +12052,14 @@ gcs_block_pcm_x_resource_x_remote_s_holder_block_to_n( status.common.source_candidate = 0; status.common.retain_pi_if_dirty = 0; status.common.outcome = RESOURCE_X_OUTCOME_OK; - if (!cluster_resource_x_wire_encode( - RESOURCE_X_MSG_BLOCKED_TO_N, &status, payload, - sizeof(payload), &payload_len, &reject) - || payload_len != RESOURCE_X_CONTROL_V1_BYTES) { - failure_decision - = cluster_gcs_resource_x_remote_s_failure_decide( - remote_s_stage, RESOURCE_X_FAIL_INTERNAL_CORRUPTION, - false, false, false, false); - gcs_block_resource_x_first_failure_from_block( - &first_failure, block, remote_s_stage, - failure_decision.domain, - RESOURCE_X_APPLY_RECOVERY_BLOCKED); + if (!cluster_resource_x_wire_encode(RESOURCE_X_MSG_BLOCKED_TO_N, &status, payload, + sizeof(payload), &payload_len, &reject) + || payload_len != RESOURCE_X_CONTROL_V1_BYTES) { + failure_decision = cluster_gcs_resource_x_remote_s_failure_decide( + remote_s_stage, RESOURCE_X_FAIL_INTERNAL_CORRUPTION, false, false, false, false); + gcs_block_resource_x_first_failure_from_block(&first_failure, block, remote_s_stage, + failure_decision.domain, + RESOURCE_X_APPLY_RECOVERY_BLOCKED); first_failure.r4_generation = r4_record_generation; first_failure.buffer_generation_before = current.generation; first_failure.buffer_generation_after = current.generation; @@ -12779,17 +12067,14 @@ gcs_block_pcm_x_resource_x_remote_s_holder_block_to_n( gcs_block_resource_x_failure_decision_apply(&failure_decision); return RESOURCE_X_APPLY_RECOVERY_BLOCKED; } - worker_id = cluster_lms_shard_for_tag( - &block->common.logical_assertion.resource, cluster_lms_workers); + worker_id + = cluster_lms_shard_for_tag(&block->common.logical_assertion.resource, cluster_lms_workers); if (worker_id < 0 || worker_id >= cluster_lms_workers) { - failure_decision - = cluster_gcs_resource_x_remote_s_failure_decide( - remote_s_stage, RESOURCE_X_FAIL_INTERNAL_CORRUPTION, - false, false, false, false); - gcs_block_resource_x_first_failure_from_block( - &first_failure, block, remote_s_stage, - failure_decision.domain, - RESOURCE_X_APPLY_RECOVERY_BLOCKED); + failure_decision = cluster_gcs_resource_x_remote_s_failure_decide( + remote_s_stage, RESOURCE_X_FAIL_INTERNAL_CORRUPTION, false, false, false, false); + gcs_block_resource_x_first_failure_from_block(&first_failure, block, remote_s_stage, + failure_decision.domain, + RESOURCE_X_APPLY_RECOVERY_BLOCKED); first_failure.r4_generation = r4_record_generation; first_failure.buffer_generation_before = current.generation; first_failure.buffer_generation_after = current.generation; @@ -12800,15 +12085,11 @@ gcs_block_pcm_x_resource_x_remote_s_holder_block_to_n( content_lock = BufferDescriptorGetContentLock(buf); if (!LWLockConditionalAcquire(content_lock, LW_EXCLUSIVE)) { - failure_decision - = cluster_gcs_resource_x_remote_s_failure_decide( - remote_s_stage, - RESOURCE_X_FAIL_PRE_MUTATION_BACKPRESSURE, - false, false, false, false); - gcs_block_resource_x_first_failure_from_block( - &first_failure, block, remote_s_stage, - failure_decision.domain, - RESOURCE_X_APPLY_BAD_STATE); + failure_decision = cluster_gcs_resource_x_remote_s_failure_decide( + remote_s_stage, RESOURCE_X_FAIL_PRE_MUTATION_BACKPRESSURE, false, false, false, false); + gcs_block_resource_x_first_failure_from_block(&first_failure, block, remote_s_stage, + failure_decision.domain, + RESOURCE_X_APPLY_BAD_STATE); first_failure.r4_generation = r4_record_generation; first_failure.buffer_generation_before = current.generation; first_failure.buffer_generation_after = current.generation; @@ -12819,26 +12100,20 @@ gcs_block_pcm_x_resource_x_remote_s_holder_block_to_n( memset(&revalidated, 0, sizeof(revalidated)); memset(&revoking, 0, sizeof(revoking)); own_result = cluster_bufmgr_pcm_own_snapshot(buf, &revalidated); - if (own_result == CLUSTER_PCM_OWN_OK - && memcmp(¤t, &revalidated, sizeof(current)) != 0) + if (own_result == CLUSTER_PCM_OWN_OK && memcmp(¤t, &revalidated, sizeof(current)) != 0) own_result = CLUSTER_PCM_OWN_STALE; if (own_result == CLUSTER_PCM_OWN_OK) - own_result = cluster_bufmgr_pcm_own_s_holder_candidate_exact( - buf, &revalidated); + own_result = cluster_bufmgr_pcm_own_s_holder_candidate_exact(buf, &revalidated); if (own_result == CLUSTER_PCM_OWN_OK) - own_result = cluster_bufmgr_pcm_own_begin_s_revoke( - buf, &revalidated, &revoking); + own_result = cluster_bufmgr_pcm_own_begin_s_revoke(buf, &revalidated, &revoking); LWLockRelease(content_lock); if (own_result != CLUSTER_PCM_OWN_OK) { mapped_result = gcs_block_resource_x_remote_s_own_result(own_result); failure_domain = gcs_block_resource_x_pre_mutation_domain(own_result); - failure_decision - = cluster_gcs_resource_x_remote_s_failure_decide( - remote_s_stage, failure_domain, - false, false, false, false); - gcs_block_resource_x_first_failure_from_block( - &first_failure, block, remote_s_stage, failure_decision.domain, - mapped_result); + failure_decision = cluster_gcs_resource_x_remote_s_failure_decide( + remote_s_stage, failure_domain, false, false, false, false); + gcs_block_resource_x_first_failure_from_block(&first_failure, block, remote_s_stage, + failure_decision.domain, mapped_result); first_failure.r4_generation = r4_record_generation; first_failure.buffer_generation_before = current.generation; first_failure.buffer_generation_after = revalidated.generation; @@ -12850,22 +12125,18 @@ gcs_block_pcm_x_resource_x_remote_s_holder_block_to_n( memset(&status_handle, 0, sizeof(status_handle)); own_result = cluster_lms_outbound_stage_resource_x_remote_s_status_exact( - worker_id, (uint32)authenticated_master_node, - payload, payload_len, &revoking, &status_handle); + worker_id, (uint32)authenticated_master_node, payload, payload_len, &revoking, + &status_handle); if (own_result != CLUSTER_PCM_OWN_OK) { abort_result = cluster_bufmgr_pcm_own_abort_s_revoke(buf, &revoking); rollback_abort_ok = abort_result == CLUSTER_PCM_OWN_OK; - mapped_result = rollback_abort_ok - ? gcs_block_resource_x_remote_s_own_result(own_result) - : RESOURCE_X_APPLY_RECOVERY_BLOCKED; + mapped_result = rollback_abort_ok ? gcs_block_resource_x_remote_s_own_result(own_result) + : RESOURCE_X_APPLY_RECOVERY_BLOCKED; failure_domain = gcs_block_resource_x_pre_mutation_domain(own_result); - failure_decision - = cluster_gcs_resource_x_remote_s_failure_decide( - remote_s_stage, failure_domain, - false, false, true, rollback_abort_ok); - gcs_block_resource_x_first_failure_from_block( - &first_failure, block, remote_s_stage, failure_decision.domain, - mapped_result); + failure_decision = cluster_gcs_resource_x_remote_s_failure_decide( + remote_s_stage, failure_domain, false, false, true, rollback_abort_ok); + gcs_block_resource_x_first_failure_from_block(&first_failure, block, remote_s_stage, + failure_decision.domain, mapped_result); first_failure.r4_generation = r4_record_generation; first_failure.buffer_generation_before = revoking.generation; first_failure.buffer_generation_after = current.generation; @@ -12887,8 +12158,7 @@ gcs_block_pcm_x_resource_x_remote_s_holder_block_to_n( block, authenticated_master_node, authenticated_capability_generation, admission); if (mapped_result != RESOURCE_X_APPLY_APPLIED) { cancel_result - = cluster_lms_outbound_cancel_resource_x_remote_s_status_exact( - &status_handle); + = cluster_lms_outbound_cancel_resource_x_remote_s_status_exact(&status_handle); abort_result = cluster_bufmgr_pcm_own_abort_s_revoke(buf, &revoking); rollback_cancel_ok = cancel_result == CLUSTER_PCM_OWN_OK; rollback_abort_ok = abort_result == CLUSTER_PCM_OWN_OK; @@ -12919,22 +12189,17 @@ gcs_block_pcm_x_resource_x_remote_s_holder_block_to_n( if (!LWLockConditionalAcquire(content_lock, LW_EXCLUSIVE)) { cancel_result - = cluster_lms_outbound_cancel_resource_x_remote_s_status_exact( - &status_handle); + = cluster_lms_outbound_cancel_resource_x_remote_s_status_exact(&status_handle); abort_result = cluster_bufmgr_pcm_own_abort_s_revoke(buf, &revoking); rollback_cancel_ok = cancel_result == CLUSTER_PCM_OWN_OK; rollback_abort_ok = abort_result == CLUSTER_PCM_OWN_OK; - failure_decision - = cluster_gcs_resource_x_remote_s_failure_decide( - remote_s_stage, - RESOURCE_X_FAIL_PRE_MUTATION_BACKPRESSURE, - true, rollback_cancel_ok, true, rollback_abort_ok); - mapped_result = rollback_cancel_ok && rollback_abort_ok - ? RESOURCE_X_APPLY_BAD_STATE - : RESOURCE_X_APPLY_RECOVERY_BLOCKED; - gcs_block_resource_x_first_failure_from_block( - &first_failure, block, remote_s_stage, failure_decision.domain, - mapped_result); + failure_decision = cluster_gcs_resource_x_remote_s_failure_decide( + remote_s_stage, RESOURCE_X_FAIL_PRE_MUTATION_BACKPRESSURE, true, rollback_cancel_ok, + true, rollback_abort_ok); + mapped_result = rollback_cancel_ok && rollback_abort_ok ? RESOURCE_X_APPLY_BAD_STATE + : RESOURCE_X_APPLY_RECOVERY_BLOCKED; + gcs_block_resource_x_first_failure_from_block(&first_failure, block, remote_s_stage, + failure_decision.domain, mapped_result); first_failure.r4_generation = r4_record_generation; first_failure.buffer_generation_before = revoking.generation; first_failure.buffer_generation_after = current.generation; @@ -12947,32 +12212,26 @@ gcs_block_pcm_x_resource_x_remote_s_holder_block_to_n( first_failure.status_staged = true; gcs_block_resource_x_first_failure_record(&first_failure); gcs_block_resource_x_failure_decision_apply(&failure_decision); - return failure_decision.rollback_complete - ? RESOURCE_X_APPLY_BAD_STATE - : RESOURCE_X_APPLY_RECOVERY_BLOCKED; + return failure_decision.rollback_complete ? RESOURCE_X_APPLY_BAD_STATE + : RESOURCE_X_APPLY_RECOVERY_BLOCKED; } memset(&released, 0, sizeof(released)); - own_result = cluster_bufmgr_pcm_own_finish_remote_s_block_to_n( - buf, &revoking, &released); + own_result = cluster_bufmgr_pcm_own_finish_remote_s_block_to_n(buf, &revoking, &released); LWLockRelease(content_lock); if (own_result != CLUSTER_PCM_OWN_OK) { cancel_result - = cluster_lms_outbound_cancel_resource_x_remote_s_status_exact( - &status_handle); + = cluster_lms_outbound_cancel_resource_x_remote_s_status_exact(&status_handle); abort_result = cluster_bufmgr_pcm_own_abort_s_revoke(buf, &revoking); rollback_cancel_ok = cancel_result == CLUSTER_PCM_OWN_OK; rollback_abort_ok = abort_result == CLUSTER_PCM_OWN_OK; mapped_result = rollback_cancel_ok && rollback_abort_ok - ? gcs_block_resource_x_remote_s_own_result(own_result) - : RESOURCE_X_APPLY_RECOVERY_BLOCKED; + ? gcs_block_resource_x_remote_s_own_result(own_result) + : RESOURCE_X_APPLY_RECOVERY_BLOCKED; failure_domain = gcs_block_resource_x_pre_mutation_domain(own_result); - failure_decision - = cluster_gcs_resource_x_remote_s_failure_decide( - remote_s_stage, failure_domain, - true, rollback_cancel_ok, true, rollback_abort_ok); - gcs_block_resource_x_first_failure_from_block( - &first_failure, block, remote_s_stage, failure_decision.domain, - mapped_result); + failure_decision = cluster_gcs_resource_x_remote_s_failure_decide( + remote_s_stage, failure_domain, true, rollback_cancel_ok, true, rollback_abort_ok); + gcs_block_resource_x_first_failure_from_block(&first_failure, block, remote_s_stage, + failure_decision.domain, mapped_result); first_failure.r4_generation = r4_record_generation; first_failure.buffer_generation_before = revoking.generation; first_failure.buffer_generation_after = current.generation; @@ -12985,23 +12244,18 @@ gcs_block_pcm_x_resource_x_remote_s_holder_block_to_n( first_failure.status_staged = true; gcs_block_resource_x_first_failure_record(&first_failure); gcs_block_resource_x_failure_decision_apply(&failure_decision); - return failure_decision.rollback_complete - ? mapped_result : RESOURCE_X_APPLY_RECOVERY_BLOCKED; + return failure_decision.rollback_complete ? mapped_result + : RESOURCE_X_APPLY_RECOVERY_BLOCKED; } remote_s_stage = RESOURCE_X_REMOTE_S_STAGE_COMMITTED_N; own_result - = cluster_lms_outbound_publish_resource_x_remote_s_status_exact( - &status_handle, &released); + = cluster_lms_outbound_publish_resource_x_remote_s_status_exact(&status_handle, &released); if (own_result != CLUSTER_PCM_OWN_OK) { - failure_decision - = cluster_gcs_resource_x_remote_s_failure_decide( - remote_s_stage, - RESOURCE_X_FAIL_POST_MUTATION_AMBIGUITY, - false, false, false, false); - gcs_block_resource_x_first_failure_from_block( - &first_failure, block, remote_s_stage, - failure_decision.domain, - RESOURCE_X_APPLY_RECOVERY_BLOCKED); + failure_decision = cluster_gcs_resource_x_remote_s_failure_decide( + remote_s_stage, RESOURCE_X_FAIL_POST_MUTATION_AMBIGUITY, false, false, false, false); + gcs_block_resource_x_first_failure_from_block(&first_failure, block, remote_s_stage, + failure_decision.domain, + RESOURCE_X_APPLY_RECOVERY_BLOCKED); first_failure.r4_generation = r4_record_generation; first_failure.buffer_generation_before = revoking.generation; first_failure.buffer_generation_after = released.generation; @@ -13023,13 +12277,10 @@ gcs_block_resource_x_target_peer_result_exact(const ClusterSemanticAdmissionToke ClusterSemanticResourceXPeerOpenResult peer_result; if (admission == NULL || !admission->entered - || admission->feature_bit - != CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1 - || admission->side != CLUSTER_SEMANTIC_TARGET_SIDE - || admission->record_generation == 0 - || admission->record_generation == UINT64_MAX - || peer_node < 0 || peer_node >= RESOURCE_X_PROTOCOL_NODE_LIMIT - || authenticated_connection_generation == 0) + || admission->feature_bit != CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1 + || admission->side != CLUSTER_SEMANTIC_TARGET_SIDE || admission->record_generation == 0 + || admission->record_generation == UINT64_MAX || peer_node < 0 + || peer_node >= RESOURCE_X_PROTOCOL_NODE_LIMIT || authenticated_connection_generation == 0) return RESOURCE_X_APPLY_INVALID; if (admission->formation_epoch != cluster_epoch_get_current() || !cluster_semantic_activation_recheck(admission)) @@ -13402,9 +12653,9 @@ gcs_block_resource_x_cleanup_frame_exact(const ResourceXDecodedFrame *frame, int * Resource-X local-owner, and outbound staging work; no branch may resnapshot * into the retired source implementation. */ static ResourceXApplyResult -gcs_block_resource_x_type17_ingress( - const ClusterICEnvelope *env, const ResourceXDecodedFrame *frame, - uint32 authenticated_connection_generation) +gcs_block_resource_x_type17_ingress(const ClusterICEnvelope *env, + const ResourceXDecodedFrame *frame, + uint32 authenticated_connection_generation) { ClusterSemanticAdmissionToken admission; ClusterSemanticAdmissionResult admission_result; @@ -13414,8 +12665,7 @@ gcs_block_resource_x_type17_ingress( ResourceXGateSnapshot diagnostic_gate; ResourceXGateSnapshot gate; ResourceXApplyResult result = RESOURCE_X_APPLY_STALE; - PcmXSessionAuthResult diagnostic_session_check - = PCM_X_SESSION_AUTH_INVALID; + PcmXSessionAuthResult diagnostic_session_check = PCM_X_SESSION_AUTH_INVALID; uint64 diagnostic_master_session = 0; uint64 master_session = 0; int32 diagnostic_lookup_master = -1; @@ -13432,14 +12682,13 @@ gcs_block_resource_x_type17_ingress( PcmXSessionAuthResult session_check = PCM_X_SESSION_AUTH_INVALID; memset(&admission, 0, sizeof(admission)); - if (env == NULL || frame == NULL - || frame->kind != RESOURCE_X_WIRE_BLOCK_TO_N + if (env == NULL || frame == NULL || frame->kind != RESOURCE_X_WIRE_BLOCK_TO_N || authenticated_connection_generation == 0) return RESOURCE_X_APPLY_INVALID; source_node = (int32)env->source_node_id; - admission_result = cluster_semantic_activation_enter( - CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1, - CLUSTER_SEMANTIC_TARGET_SIDE, &admission); + admission_result + = cluster_semantic_activation_enter(CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1, + CLUSTER_SEMANTIC_TARGET_SIDE, &admission); if (admission_result != CLUSTER_SEMANTIC_ADMISSION_OK) return RESOURCE_X_APPLY_STALE; @@ -13447,8 +12696,7 @@ gcs_block_resource_x_type17_ingress( { if (source_node != cluster_node_id) peer_check = cluster_semantic_activation_resource_x_peer_open_check( - &admission, source_node, - authenticated_connection_generation); + &admission, source_node, authenticated_connection_generation); result = gcs_block_resource_x_target_peer_result_exact(&admission, source_node, authenticated_connection_generation); peer_exact = result == RESOURCE_X_APPLY_APPLIED; @@ -13457,8 +12705,7 @@ gcs_block_resource_x_type17_ingress( &frame->common.logical_assertion.resource, &gate, &master_node, &master_session); gate_exact = peer_exact && session_check == PCM_X_SESSION_AUTH_OK; master_exact = peer_exact && master_node == source_node; - formation_exact = master_exact - && gate.formation == frame->common.resource_formation; + formation_exact = master_exact && gate.formation == frame->common.resource_formation; session_exact = gate_exact && formation_exact && master_session == frame->common.master_session_incarnation; if (peer_exact) { @@ -13472,68 +12719,50 @@ gcs_block_resource_x_type17_ingress( admission_exact = result == RESOURCE_X_APPLY_APPLIED; if (admission_exact) { if ((frame->common.observed_mode == (uint8)PCM_STATE_X - || frame->common.observed_mode == (uint8)PCM_STATE_S) - && frame->common.source_candidate == 1 - && frame->common.retain_pi_if_dirty == 1) - result = gcs_block_pcm_x_resource_x_source_block_to_n( - frame, master_node, admission.record_generation); + || frame->common.observed_mode == (uint8)PCM_STATE_S) + && frame->common.source_candidate == 1 && frame->common.retain_pi_if_dirty == 1) + result = gcs_block_pcm_x_resource_x_source_block_to_n(frame, master_node, + admission.record_generation); else if (frame->common.observed_mode == (uint8)PCM_STATE_S - && frame->common.logical_assertion.requester_node - != cluster_node_id) - result - = gcs_block_pcm_x_resource_x_remote_s_holder_block_to_n( - frame, master_node, - authenticated_connection_generation, - admission.record_generation, &admission); + && frame->common.logical_assertion.requester_node != cluster_node_id) + result = gcs_block_pcm_x_resource_x_remote_s_holder_block_to_n( + frame, master_node, authenticated_connection_generation, + admission.record_generation, &admission); else - result = cluster_pcm_lock_resource_x_block_to_n_exact( - frame, master_node); + result = cluster_pcm_lock_resource_x_block_to_n_exact(frame, master_node); } else { memset(&diagnostic_gate, 0, sizeof(diagnostic_gate)); - memset(&diagnostic_session_sample, 0, - sizeof(diagnostic_session_sample)); - diagnostic_gate_snapshot - = cluster_pcm_lock_resource_x_gate_snapshot( - &diagnostic_gate); - diagnostic_gate_open = diagnostic_gate_snapshot - && diagnostic_gate.phase == RESOURCE_X_GATE_OPEN; + memset(&diagnostic_session_sample, 0, sizeof(diagnostic_session_sample)); + diagnostic_gate_snapshot = cluster_pcm_lock_resource_x_gate_snapshot(&diagnostic_gate); + diagnostic_gate_open + = diagnostic_gate_snapshot && diagnostic_gate.phase == RESOURCE_X_GATE_OPEN; if (diagnostic_gate_open) { - diagnostic_lookup_master = cluster_gcs_lookup_master( - frame->common.logical_assertion.resource); + diagnostic_lookup_master + = cluster_gcs_lookup_master(frame->common.logical_assertion.resource); if (diagnostic_lookup_master >= 0 - && diagnostic_lookup_master - < RESOURCE_X_PROTOCOL_NODE_LIMIT) - diagnostic_session_check - = gcs_block_pcm_x_authenticated_session_result( - diagnostic_lookup_master, - cluster_epoch_get_current(), - &diagnostic_master_session, - &diagnostic_session_sample); + && diagnostic_lookup_master < RESOURCE_X_PROTOCOL_NODE_LIMIT) + diagnostic_session_check = gcs_block_pcm_x_authenticated_session_result( + diagnostic_lookup_master, cluster_epoch_get_current(), + &diagnostic_master_session, &diagnostic_session_sample); } - ereport(LOG, - (errmsg_internal("Resource-X type-17 ingress predicate diagnostic"), - errdetail("peer=%s peer_check=%d gate=%s master=%s formation=%s " - "session=%s admission=%s source=%d current_master=%d " - "wire_formation=%llu current_formation=%llu " - "wire_session=%llu current_session=%llu " - "connection_generation=%u r4_generation=%llu", - peer_exact ? "true" : "false", - (int)peer_check, - gate_exact ? "true" : "false", - master_exact ? "true" : "false", - formation_exact ? "true" : "false", - session_exact ? "true" : "false", - admission_exact ? "true" : "false", - source_node, master_node, - (unsigned long long)frame->common.resource_formation, - (unsigned long long)(gate_exact - ? gate.formation : 0), - (unsigned long long)frame->common - .master_session_incarnation, - (unsigned long long)master_session, - authenticated_connection_generation, - (unsigned long long)admission.record_generation), - errdetail_log("gate_snapshot=%s gate_phase=%u " + ereport( + LOG, + (errmsg_internal("Resource-X type-17 ingress predicate diagnostic"), + errdetail("peer=%s peer_check=%d gate=%s master=%s formation=%s " + "session=%s admission=%s source=%d current_master=%d " + "wire_formation=%llu current_formation=%llu " + "wire_session=%llu current_session=%llu " + "connection_generation=%u r4_generation=%llu", + peer_exact ? "true" : "false", (int)peer_check, + gate_exact ? "true" : "false", master_exact ? "true" : "false", + formation_exact ? "true" : "false", session_exact ? "true" : "false", + admission_exact ? "true" : "false", source_node, master_node, + (unsigned long long)frame->common.resource_formation, + (unsigned long long)(gate_exact ? gate.formation : 0), + (unsigned long long)frame->common.master_session_incarnation, + (unsigned long long)master_session, authenticated_connection_generation, + (unsigned long long)admission.record_generation), + errdetail_log("gate_snapshot=%s gate_phase=%u " "gate_formation=%llu gate_freeze=%llu " "lookup_master=%d session_check=%d " "sampled_session=%llu slot_before=%s " @@ -13541,30 +12770,20 @@ gcs_block_resource_x_type17_ingress( "epoch_after=%llu fresh_before=%s " "fresh_after=%s connection_before=%s " "connection_after=%s", - diagnostic_gate_snapshot ? "true" : "false", - diagnostic_gate.phase, + diagnostic_gate_snapshot ? "true" : "false", diagnostic_gate.phase, (unsigned long long)diagnostic_gate.formation, - (unsigned long long) - diagnostic_gate.freeze_generation, - diagnostic_lookup_master, - (int)diagnostic_session_check, + (unsigned long long)diagnostic_gate.freeze_generation, + diagnostic_lookup_master, (int)diagnostic_session_check, (unsigned long long)diagnostic_master_session, - diagnostic_session_sample.slot_before_valid - ? "true" : "false", - diagnostic_session_sample.slot_after_valid - ? "true" : "false", - (unsigned long long) - diagnostic_session_sample.observed_epoch_before, - (unsigned long long) - diagnostic_session_sample.observed_epoch_after, - diagnostic_session_sample.fresh_before - ? "true" : "false", - diagnostic_session_sample.fresh_after - ? "true" : "false", - diagnostic_session_sample.connection_before_valid - ? "true" : "false", - diagnostic_session_sample.connection_after_valid - ? "true" : "false"))); + diagnostic_session_sample.slot_before_valid ? "true" : "false", + diagnostic_session_sample.slot_after_valid ? "true" : "false", + (unsigned long long)diagnostic_session_sample.observed_epoch_before, + (unsigned long long)diagnostic_session_sample.observed_epoch_after, + diagnostic_session_sample.fresh_before ? "true" : "false", + diagnostic_session_sample.fresh_after ? "true" : "false", + diagnostic_session_sample.connection_before_valid ? "true" : "false", + diagnostic_session_sample.connection_after_valid ? "true" + : "false"))); } } PG_CATCH(); @@ -13581,9 +12800,8 @@ gcs_block_resource_x_type17_ingress( * receipt/round mutation and frozen-frame extraction complete before either * encoder/stager runs; no malformed or stale kind-9 frame reaches legacy. */ static void -gcs_block_resource_x_kind9_ingress( - const ClusterICEnvelope *env, const ResourceXDecodedFrame *frame, - uint32 authenticated_connection_generation) +gcs_block_resource_x_kind9_ingress(const ClusterICEnvelope *env, const ResourceXDecodedFrame *frame, + uint32 authenticated_connection_generation) { ClusterSemanticAdmissionToken admission; ClusterSemanticAdmissionResult admission_result; @@ -13601,59 +12819,45 @@ gcs_block_resource_x_kind9_ingress( memset(&admission, 0, sizeof(admission)); memset(&outbound, 0, sizeof(outbound)); - if (env == NULL || frame == NULL - || frame->kind != RESOURCE_X_WIRE_PREASSERT_BOOTSTRAP) + if (env == NULL || frame == NULL || frame->kind != RESOURCE_X_WIRE_PREASSERT_BOOTSTRAP) return; source_node = (int32)env->source_node_id; - admission_result = cluster_semantic_activation_enter( - CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1, - CLUSTER_SEMANTIC_TARGET_SIDE, &admission); + admission_result + = cluster_semantic_activation_enter(CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1, + CLUSTER_SEMANTIC_TARGET_SIDE, &admission); if (admission_result != CLUSTER_SEMANTIC_ADMISSION_OK) return; - if (!gcs_block_resource_x_target_peer_matches_exact( - &admission, source_node, authenticated_connection_generation)) + if (!gcs_block_resource_x_target_peer_matches_exact(&admission, source_node, + authenticated_connection_generation)) goto done; - if (!gcs_block_resource_x_gate_session_snapshot( - &frame->common.logical_assertion.resource, &gate, - &master_node, &master_session) + if (!gcs_block_resource_x_gate_session_snapshot(&frame->common.logical_assertion.resource, + &gate, &master_node, &master_session) || gate.formation != frame->common.resource_formation - || master_session - != frame->common.master_session_incarnation + || master_session != frame->common.master_session_incarnation || !cluster_semantic_activation_recheck(&admission)) goto done; if (env->msg_type == RESOURCE_X_MSG_ASSERT_X) { if (master_node != cluster_node_id - || !gcs_block_pcm_x_resource_x_peer_ready_exact( - source_node, &outbound_connection_generation)) + || !gcs_block_pcm_x_resource_x_peer_ready_exact(source_node, + &outbound_connection_generation)) goto done; apply_result = cluster_pcm_lock_resource_x_bootstrap_request_exact( - frame, source_node, authenticated_connection_generation, - admission.record_generation, - master_session, - outbound_connection_generation, &outbound); - if ((apply_result != RESOURCE_X_APPLY_APPLIED - && apply_result != RESOURCE_X_APPLY_DUPLICATE) + frame, source_node, authenticated_connection_generation, admission.record_generation, + master_session, outbound_connection_generation, &outbound); + if ((apply_result != RESOURCE_X_APPLY_APPLIED && apply_result != RESOURCE_X_APPLY_DUPLICATE) || gcs_block_resource_x_diagnostic_should_log( - GCS_BLOCK_RESOURCE_X_DIAGNOSTIC_KIND9_REQUEST, - (int)apply_result)) - ereport(LOG, - (errmsg_internal("Resource-X kind-9 request diagnostic"), - errdetail("source=%d requester=%d attempt=%llu result=%d " - "ack_base=%llu formation=%llu session=%llu", - source_node, - frame->common.logical_assertion.requester_node, - (unsigned long long) - frame->common.assertion_sequence, - (int)apply_result, - (unsigned long long) - outbound.common.base_authority_generation, - (unsigned long long) - frame->common.resource_formation, - (unsigned long long) - frame->common.master_session_incarnation))); - if (apply_result != RESOURCE_X_APPLY_APPLIED - && apply_result != RESOURCE_X_APPLY_DUPLICATE) + GCS_BLOCK_RESOURCE_X_DIAGNOSTIC_KIND9_REQUEST, (int)apply_result)) + ereport(LOG, (errmsg_internal("Resource-X kind-9 request diagnostic"), + errdetail("source=%d requester=%d attempt=%llu result=%d " + "ack_base=%llu formation=%llu session=%llu", + source_node, frame->common.logical_assertion.requester_node, + (unsigned long long)frame->common.assertion_sequence, + (int)apply_result, + (unsigned long long)outbound.common.base_authority_generation, + (unsigned long long)frame->common.resource_formation, + (unsigned long long)frame->common.master_session_incarnation))); + if (apply_result != RESOURCE_X_APPLY_APPLIED && apply_result != RESOURCE_X_APPLY_DUPLICATE) goto done; ready = true; if (outbound.kind == RESOURCE_X_WIRE_ASSERT_X @@ -13665,24 +12869,19 @@ gcs_block_resource_x_kind9_ingress( goto done; } if (!cluster_semantic_activation_recheck(&admission) - || !gcs_block_resource_x_gate_session_recheck( - &frame->common.logical_assertion.resource, &gate, - cluster_node_id, master_session) - || !gcs_block_pcm_x_resource_x_peer_ready_exact( - source_node, &rechecked_connection_generation) - || rechecked_connection_generation - != outbound_connection_generation) + || !gcs_block_resource_x_gate_session_recheck(&frame->common.logical_assertion.resource, + &gate, cluster_node_id, master_session) + || !gcs_block_pcm_x_resource_x_peer_ready_exact(source_node, + &rechecked_connection_generation) + || rechecked_connection_generation != outbound_connection_generation) goto done; - (void)gcs_block_resource_x_bootstrap_ack_stage_exact( - source_node, &outbound); + (void)gcs_block_resource_x_bootstrap_ack_stage_exact(source_node, &outbound); } else if (env->msg_type == RESOURCE_X_MSG_IMAGE_OR_GRANT) { if (master_node != source_node) goto done; - round_action - = cluster_pcm_lock_resource_x_bootstrap_round_accept_ack_exact( - frame, source_node, authenticated_connection_generation, - admission.record_generation, - gcs_block_pcm_x_monotonic_us(), &outbound); + round_action = cluster_pcm_lock_resource_x_bootstrap_round_accept_ack_exact( + frame, source_node, authenticated_connection_generation, admission.record_generation, + gcs_block_pcm_x_monotonic_us(), &outbound); if (round_action == RESOURCE_X_BOOTSTRAP_ROUND_FAIL_CLOSED && cluster_semantic_activation_recheck(&admission) && gcs_block_resource_x_cleanup_frame_exact( @@ -13691,29 +12890,22 @@ gcs_block_resource_x_kind9_ingress( &outbound) == RESOURCE_X_APPLY_APPLIED) round_action = RESOURCE_X_BOOTSTRAP_ROUND_DISPATCH_ASSERT; - if (gcs_block_resource_x_diagnostic_should_log( - GCS_BLOCK_RESOURCE_X_DIAGNOSTIC_KIND9_ACK, - (int)round_action)) - ereport(LOG, - (errmsg_internal("Resource-X kind-9 ACK diagnostic"), - errdetail("source=%d requester=%d attempt=%llu base=%llu " - "action=%d", - source_node, - frame->common.logical_assertion.requester_node, - (unsigned long long) - frame->common.assertion_sequence, - (unsigned long long) - frame->common.base_authority_generation, - (int)round_action))); + if (gcs_block_resource_x_diagnostic_should_log(GCS_BLOCK_RESOURCE_X_DIAGNOSTIC_KIND9_ACK, + (int)round_action)) + ereport(LOG, (errmsg_internal("Resource-X kind-9 ACK diagnostic"), + errdetail("source=%d requester=%d attempt=%llu base=%llu " + "action=%d", + source_node, frame->common.logical_assertion.requester_node, + (unsigned long long)frame->common.assertion_sequence, + (unsigned long long)frame->common.base_authority_generation, + (int)round_action))); if (round_action != RESOURCE_X_BOOTSTRAP_ROUND_DISPATCH_ASSERT || !cluster_semantic_activation_recheck(&admission)) goto done; - if (!gcs_block_resource_x_gate_session_recheck( - &frame->common.logical_assertion.resource, &gate, - master_node, master_session)) + if (!gcs_block_resource_x_gate_session_recheck(&frame->common.logical_assertion.resource, + &gate, master_node, master_session)) goto done; - stage_result = gcs_block_resource_x_native_assert_stage_exact( - master_node, &outbound); + stage_result = gcs_block_resource_x_native_assert_stage_exact(master_node, &outbound); (void)stage_result; } @@ -13724,10 +12916,10 @@ gcs_block_resource_x_kind9_ingress( } static ResourceXApplyResult -gcs_block_resource_x_bootstrapped_assert_ingress( - const ClusterICEnvelope *env, const ResourceXDecodedFrame *assertion, - uint32 authenticated_connection_generation, - ResourceXMasterSnapshot *snapshot) +gcs_block_resource_x_bootstrapped_assert_ingress(const ClusterICEnvelope *env, + const ResourceXDecodedFrame *assertion, + uint32 authenticated_connection_generation, + ResourceXMasterSnapshot *snapshot) { ClusterSemanticAdmissionToken admission; ClusterSemanticAdmissionResult admission_result; @@ -13741,13 +12933,12 @@ gcs_block_resource_x_bootstrapped_assert_ingress( memset(&admission, 0, sizeof(admission)); if (env == NULL || assertion == NULL || snapshot == NULL - || assertion->kind != RESOURCE_X_WIRE_ASSERT_X - || assertion->common.ordered_lane != 0) + || assertion->kind != RESOURCE_X_WIRE_ASSERT_X || assertion->common.ordered_lane != 0) return RESOURCE_X_APPLY_INVALID; source_node = (int32)env->source_node_id; - admission_result = cluster_semantic_activation_enter( - CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1, - CLUSTER_SEMANTIC_TARGET_SIDE, &admission); + admission_result + = cluster_semantic_activation_enter(CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1, + CLUSTER_SEMANTIC_TARGET_SIDE, &admission); if (admission_result != CLUSTER_SEMANTIC_ADMISSION_OK) return RESOURCE_X_APPLY_STALE; result = gcs_block_resource_x_target_peer_result_exact(&admission, source_node, @@ -13776,9 +12967,8 @@ gcs_block_resource_x_bootstrapped_assert_ingress( goto done; } result = cluster_pcm_lock_resource_x_assert_bootstrapped_exact( - assertion, source_node, authenticated_connection_generation, - admission.record_generation, master_session, - master_sender_connection_generation, snapshot); + assertion, source_node, authenticated_connection_generation, admission.record_generation, + master_session, master_sender_connection_generation, snapshot); done: cluster_semantic_activation_leave(&admission); return result; @@ -13860,9 +13050,10 @@ gcs_block_resource_x_requester_join_ingress(const ClusterICEnvelope *env, } static ResourceXApplyResult -gcs_block_resource_x_requester_terminal_try( - const ClusterICEnvelope *env, const ResourceXDecodedFrame *frame, - uint32 authenticated_connection_generation, bool scheduled_retry) +gcs_block_resource_x_requester_terminal_try(const ClusterICEnvelope *env, + const ResourceXDecodedFrame *frame, + uint32 authenticated_connection_generation, + bool scheduled_retry) { ClusterSemanticAdmissionToken admission; ClusterSemanticAdmissionResult admission_result; @@ -13878,14 +13069,13 @@ gcs_block_resource_x_requester_terminal_try( int32 master_node = -1; int32 source_node; - if (env == NULL || frame == NULL - || authenticated_connection_generation == 0) + if (env == NULL || frame == NULL || authenticated_connection_generation == 0) return RESOURCE_X_APPLY_INVALID; source_node = (int32)env->source_node_id; memset(&admission, 0, sizeof(admission)); - admission_result = cluster_semantic_activation_enter( - CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1, - CLUSTER_SEMANTIC_TARGET_SIDE, &admission); + admission_result + = cluster_semantic_activation_enter(CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1, + CLUSTER_SEMANTIC_TARGET_SIDE, &admission); if (admission_result != CLUSTER_SEMANTIC_ADMISSION_OK) return RESOURCE_X_APPLY_STALE; @@ -13925,8 +13115,7 @@ gcs_block_resource_x_requester_terminal_try( result = gcs_block_pcm_x_resource_x_join_terminal_owned_try( &delivery_ref, scheduled_retry, &terminal_ref, &terminal_ownership_generation, &terminal_authority_generation); - if (result == RESOURCE_X_APPLY_APPLIED - || result == RESOURCE_X_APPLY_DUPLICATE) { + if (result == RESOURCE_X_APPLY_APPLIED || result == RESOURCE_X_APPLY_DUPLICATE) { result = gcs_block_resource_x_gate_session_recheck_result( &frame->common.logical_assertion.resource, &gate, master_node, master_session); peer_result = gcs_block_resource_x_target_peer_result_exact( @@ -13940,11 +13129,8 @@ gcs_block_resource_x_requester_terminal_try( if (result == RESOURCE_X_APPLY_APPLIED) { publish_result = cluster_pcm_lock_resource_x_bootstrap_round_publish_terminal_exact( - &terminal_ref, - master_session, - admission.record_generation, - terminal_ownership_generation, - terminal_authority_generation, + &terminal_ref, master_session, admission.record_generation, + terminal_ownership_generation, terminal_authority_generation, gcs_block_pcm_x_monotonic_us()); if (publish_result != RESOURCE_X_APPLY_APPLIED && publish_result != RESOURCE_X_APPLY_DUPLICATE) { @@ -13970,9 +13156,9 @@ gcs_block_resource_x_requester_terminal_try( * response is an ordinary unretained typed ACK; a full outbound queue is * healed by the master's still-retained kind-10 debt replay. */ static ResourceXApplyResult -gcs_block_resource_x_source_settlement_ingress( - const ClusterICEnvelope *env, const ResourceXDecodedFrame *settlement, - uint32 sender_connection_generation) +gcs_block_resource_x_source_settlement_ingress(const ClusterICEnvelope *env, + const ResourceXDecodedFrame *settlement, + uint32 sender_connection_generation) { ResourceXDecodedFrame ack; ResourceXSourceSettlementPlan plan; @@ -13996,102 +13182,76 @@ gcs_block_resource_x_source_settlement_ingress( memset(&plan, 0, sizeof(plan)); memset(&commit_observation, 0, sizeof(commit_observation)); memset(&prepare_observation, 0, sizeof(prepare_observation)); - result - = cluster_pcm_lock_resource_x_source_settlement_prepare_observed_exact( - settlement, (int32)env->source_node_id, &plan, - &prepare_observation); + result = cluster_pcm_lock_resource_x_source_settlement_prepare_observed_exact( + settlement, (int32)env->source_node_id, &plan, &prepare_observation); if (result == RESOURCE_X_APPLY_APPLIED && !plan.valid) { gcs_block_resource_x_source_settlement_failure_record( - settlement, &prepare_observation, - RESOURCE_X_SOURCE_SETTLEMENT_STAGE_PREPARE, - RESOURCE_X_FAIL_INTERNAL_CORRUPTION, - RESOURCE_X_APPLY_RECOVERY_BLOCKED, - prepare_observation.current_pair_source_generation, - -1, false, false); + settlement, &prepare_observation, RESOURCE_X_SOURCE_SETTLEMENT_STAGE_PREPARE, + RESOURCE_X_FAIL_INTERNAL_CORRUPTION, RESOURCE_X_APPLY_RECOVERY_BLOCKED, + prepare_observation.current_pair_source_generation, -1, false, false); gcs_block_resource_x_fail_closed_current(); return RESOURCE_X_APPLY_RECOVERY_BLOCKED; } if (result == RESOURCE_X_APPLY_APPLIED && plan.valid) { - settlement_finish_mode - = cluster_pcm_x_revoke_finish_mode(&plan.assertion.resource, 0); + settlement_finish_mode = cluster_pcm_x_revoke_finish_mode(&plan.assertion.resource, 0); if (settlement_finish_mode == CLUSTER_PCM_X_REVOKE_FINISH_RETAIN) { - own_result - = cluster_bufmgr_pcm_own_release_retained_fence_preserve_pi( - &plan.assertion.resource, plan.source_generation, - &carrier_release_complete); - if (own_result == CLUSTER_PCM_OWN_BUSY - || own_result == CLUSTER_PCM_OWN_NOT_READY) { + own_result = cluster_bufmgr_pcm_own_release_retained_fence_preserve_pi( + &plan.assertion.resource, plan.source_generation, &carrier_release_complete); + if (own_result == CLUSTER_PCM_OWN_BUSY || own_result == CLUSTER_PCM_OWN_NOT_READY) { gcs_block_resource_x_source_settlement_failure_record( - settlement, NULL, - RESOURCE_X_SOURCE_SETTLEMENT_STAGE_LOCAL_RELEASE, - gcs_block_resource_x_source_settlement_own_domain( - own_result, carrier_release_complete), - RESOURCE_X_APPLY_BAD_STATE, plan.source_generation, - (int32)own_result, carrier_release_complete, false); + settlement, NULL, RESOURCE_X_SOURCE_SETTLEMENT_STAGE_LOCAL_RELEASE, + gcs_block_resource_x_source_settlement_own_domain(own_result, + carrier_release_complete), + RESOURCE_X_APPLY_BAD_STATE, plan.source_generation, (int32)own_result, + carrier_release_complete, false); return RESOURCE_X_APPLY_BAD_STATE; } if (own_result != CLUSTER_PCM_OWN_OK) { gcs_block_resource_x_source_settlement_failure_record( - settlement, NULL, - RESOURCE_X_SOURCE_SETTLEMENT_STAGE_LOCAL_RELEASE, - gcs_block_resource_x_source_settlement_own_domain( - own_result, carrier_release_complete), - RESOURCE_X_APPLY_RECOVERY_BLOCKED, - plan.source_generation, (int32)own_result, + settlement, NULL, RESOURCE_X_SOURCE_SETTLEMENT_STAGE_LOCAL_RELEASE, + gcs_block_resource_x_source_settlement_own_domain(own_result, + carrier_release_complete), + RESOURCE_X_APPLY_RECOVERY_BLOCKED, plan.source_generation, (int32)own_result, carrier_release_complete, false); gcs_block_resource_x_fail_closed_current(); return RESOURCE_X_APPLY_RECOVERY_BLOCKED; } if (!carrier_release_complete) { gcs_block_resource_x_source_settlement_failure_record( - settlement, NULL, - RESOURCE_X_SOURCE_SETTLEMENT_STAGE_LOCAL_RELEASE, - RESOURCE_X_FAIL_INTERNAL_CORRUPTION, - RESOURCE_X_APPLY_RECOVERY_BLOCKED, - plan.source_generation, (int32)own_result, - false, false); + settlement, NULL, RESOURCE_X_SOURCE_SETTLEMENT_STAGE_LOCAL_RELEASE, + RESOURCE_X_FAIL_INTERNAL_CORRUPTION, RESOURCE_X_APPLY_RECOVERY_BLOCKED, + plan.source_generation, (int32)own_result, false, false); gcs_block_resource_x_fail_closed_current(); return RESOURCE_X_APPLY_RECOVERY_BLOCKED; } - } - else if (settlement_finish_mode == CLUSTER_PCM_X_REVOKE_FINISH_DROP) { + } else if (settlement_finish_mode == CLUSTER_PCM_X_REVOKE_FINISH_DROP) { /* VM/FSM publish this exact pair only after the unpinned DROP and * terminal-cover close both succeed. No BufferDesc remains to * release; prepare already revalidated the PUBLISHED pair identity. */ carrier_release_complete = true; - } - else { + } else { gcs_block_resource_x_source_settlement_failure_record( - settlement, NULL, - RESOURCE_X_SOURCE_SETTLEMENT_STAGE_LOCAL_RELEASE, - RESOURCE_X_FAIL_INTERNAL_CORRUPTION, - RESOURCE_X_APPLY_RECOVERY_BLOCKED, - plan.source_generation, -1, - false, false); + settlement, NULL, RESOURCE_X_SOURCE_SETTLEMENT_STAGE_LOCAL_RELEASE, + RESOURCE_X_FAIL_INTERNAL_CORRUPTION, RESOURCE_X_APPLY_RECOVERY_BLOCKED, + plan.source_generation, -1, false, false); gcs_block_resource_x_fail_closed_current(); return RESOURCE_X_APPLY_RECOVERY_BLOCKED; } result = cluster_pcm_lock_resource_x_source_settlement_commit_exact( - settlement, (int32)env->source_node_id, &plan, - &commit_observation); - if (result != RESOURCE_X_APPLY_APPLIED - && result != RESOURCE_X_APPLY_DUPLICATE) { + settlement, (int32)env->source_node_id, &plan, &commit_observation); + if (result != RESOURCE_X_APPLY_APPLIED && result != RESOURCE_X_APPLY_DUPLICATE) { gcs_block_resource_x_source_settlement_failure_record( - settlement, &commit_observation, - RESOURCE_X_SOURCE_SETTLEMENT_STAGE_COMMIT, - RESOURCE_X_FAIL_POST_MUTATION_AMBIGUITY, result, - plan.source_generation, -1, carrier_release_complete, false); + settlement, &commit_observation, RESOURCE_X_SOURCE_SETTLEMENT_STAGE_COMMIT, + RESOURCE_X_FAIL_POST_MUTATION_AMBIGUITY, result, plan.source_generation, -1, + carrier_release_complete, false); gcs_block_resource_x_fail_closed_current(); return result; } - } - else if (result != RESOURCE_X_APPLY_DUPLICATE) { + } else if (result != RESOURCE_X_APPLY_DUPLICATE) { gcs_block_resource_x_source_settlement_failure_record( - settlement, &prepare_observation, - RESOURCE_X_SOURCE_SETTLEMENT_STAGE_PREPARE, - gcs_block_resource_x_source_settlement_apply_domain(result), - result, prepare_observation.current_pair_source_generation, - -1, false, false); + settlement, &prepare_observation, RESOURCE_X_SOURCE_SETTLEMENT_STAGE_PREPARE, + gcs_block_resource_x_source_settlement_apply_domain(result), result, + prepare_observation.current_pair_source_generation, -1, false, false); return result; } ack_result = cluster_pcm_lock_resource_x_source_settlement_ack_build_exact( @@ -14099,44 +13259,35 @@ gcs_block_resource_x_source_settlement_ingress( if (ack_result != RESOURCE_X_APPLY_APPLIED) { gcs_block_resource_x_source_settlement_failure_record( settlement, NULL, RESOURCE_X_SOURCE_SETTLEMENT_STAGE_ACK_BUILD, - RESOURCE_X_FAIL_INTERNAL_CORRUPTION, ack_result, - plan.source_generation, -1, carrier_release_complete, false); + RESOURCE_X_FAIL_INTERNAL_CORRUPTION, ack_result, plan.source_generation, -1, + carrier_release_complete, false); gcs_block_resource_x_fail_closed_current(); return RESOURCE_X_APPLY_RECOVERY_BLOCKED; } - if (!cluster_resource_x_wire_encode( - RESOURCE_X_MSG_BLOCKED_TO_N, &ack, payload, sizeof(payload), - &payload_bytes, &reject) + if (!cluster_resource_x_wire_encode(RESOURCE_X_MSG_BLOCKED_TO_N, &ack, payload, sizeof(payload), + &payload_bytes, &reject) || payload_bytes != RESOURCE_X_PROOF_V1_BYTES) { gcs_block_resource_x_source_settlement_failure_record( settlement, NULL, RESOURCE_X_SOURCE_SETTLEMENT_STAGE_ACK_ENCODE, - RESOURCE_X_FAIL_INTERNAL_CORRUPTION, - RESOURCE_X_APPLY_INVALID, plan.source_generation, -1, - carrier_release_complete, false); + RESOURCE_X_FAIL_INTERNAL_CORRUPTION, RESOURCE_X_APPLY_INVALID, plan.source_generation, + -1, carrier_release_complete, false); gcs_block_resource_x_fail_closed_current(); return RESOURCE_X_APPLY_RECOVERY_BLOCKED; } ack_enqueued = cluster_grd_outbound_enqueue_backend_msg( - RESOURCE_X_MSG_BLOCKED_TO_N, env->source_node_id, payload, - payload_bytes); + RESOURCE_X_MSG_BLOCKED_TO_N, env->source_node_id, payload, payload_bytes); if ((result == RESOURCE_X_APPLY_APPLIED || !ack_enqueued) - && ((result != RESOURCE_X_APPLY_APPLIED - && result != RESOURCE_X_APPLY_DUPLICATE) + && ((result != RESOURCE_X_APPLY_APPLIED && result != RESOURCE_X_APPLY_DUPLICATE) || !ack_enqueued || gcs_block_resource_x_diagnostic_should_log( - GCS_BLOCK_RESOURCE_X_DIAGNOSTIC_SOURCE_SETTLEMENT_ACK, - (int)result))) + GCS_BLOCK_RESOURCE_X_DIAGNOSTIC_SOURCE_SETTLEMENT_ACK, (int)result))) ereport(LOG, (errmsg_internal("Resource-X source settlement ACK diagnostic"), errdetail("master=%u requester=%d attempt=%llu result=%d " "source_generation=%llu enqueue=%u sender_generation=%u", - env->source_node_id, - settlement->common.logical_assertion.requester_node, - (unsigned long long) - settlement->common.assertion_sequence, - (int)result, - (unsigned long long)plan.source_generation, - ack_enqueued ? 1U : 0U, + env->source_node_id, settlement->common.logical_assertion.requester_node, + (unsigned long long)settlement->common.assertion_sequence, (int)result, + (unsigned long long)plan.source_generation, ack_enqueued ? 1U : 0U, sender_connection_generation))); return result; } @@ -14146,8 +13297,7 @@ gcs_block_resource_x_source_settlement_ingress( * connection, or unavailable consumer. Capability publication remains off * until the type-15/type-17 consumers and retained C-intent egress close. */ static bool -gcs_block_try_resource_x_frame(const ClusterICEnvelope *env, - const void *payload) +gcs_block_try_resource_x_frame(const ClusterICEnvelope *env, const void *payload) { #ifdef CLUSTER_R4_ROUTE_POLICY_UNIT /* This focused object feeds only R4 non-candidate lengths into the shared @@ -14165,31 +13315,26 @@ gcs_block_try_resource_x_frame(const ClusterICEnvelope *env, uint32 connection_generation = 0; uint32 authenticated_capability_generation = 0; - if (env == NULL - || !gcs_block_resource_x_payload_candidate(env->msg_type, - env->payload_length)) + if (env == NULL || !gcs_block_resource_x_payload_candidate(env->msg_type, env->payload_length)) return false; if (payload == NULL || env->source_node_id >= RESOURCE_X_PROTOCOL_NODE_LIMIT - || env->dest_node_id != (uint32)cluster_node_id - || env->payload_length > PG_UINT16_MAX - || !cluster_resource_x_wire_decode(env->msg_type, payload, - (uint16)env->payload_length, &frame, &reject)) { + || env->dest_node_id != (uint32)cluster_node_id || env->payload_length > PG_UINT16_MAX + || !cluster_resource_x_wire_decode(env->msg_type, payload, (uint16)env->payload_length, + &frame, &reject)) { return true; } cluster_pcm_lock_resource_x_trace_frame(RESOURCE_X_TRACE_RECEIVE, &frame, - (int32)env->source_node_id, 0); + (int32)env->source_node_id, 0); if (env->epoch != cluster_epoch_get_current()) { return true; } if ((int32)env->source_node_id == cluster_node_id) { - if (!gcs_block_pcm_x_resource_x_peer_ready_exact( - cluster_node_id, &connection_generation)) { + if (!gcs_block_pcm_x_resource_x_peer_ready_exact(cluster_node_id, &connection_generation)) { return true; } - } else if (!cluster_sf_peer_capability_word_sample( - (int32)env->source_node_id, - PGRAC_IC_HELLO_CAP_GCS_RESOURCE_X_CONVERT_V1, - &capability_word, &connection_generation)) { + } else if (!cluster_sf_peer_capability_word_sample((int32)env->source_node_id, + PGRAC_IC_HELLO_CAP_GCS_RESOURCE_X_CONVERT_V1, + &capability_word, &connection_generation)) { return true; } /* Tier1 envelope verification has already bound this frame to the @@ -14211,66 +13356,54 @@ gcs_block_try_resource_x_frame(const ClusterICEnvelope *env, switch (frame.kind) { case RESOURCE_X_WIRE_PREASSERT_BOOTSTRAP: - gcs_block_resource_x_kind9_ingress( - env, &frame, authenticated_capability_generation); + gcs_block_resource_x_kind9_ingress(env, &frame, authenticated_capability_generation); break; case RESOURCE_X_WIRE_ASSERT_X: if (frame.common.ordered_lane == 0) result = gcs_block_resource_x_bootstrapped_assert_ingress( - env, &frame, authenticated_capability_generation, - &snapshot); - if ((result == RESOURCE_X_APPLY_APPLIED - || result == RESOURCE_X_APPLY_DUPLICATE) + env, &frame, authenticated_capability_generation, &snapshot); + if ((result == RESOURCE_X_APPLY_APPLIED || result == RESOURCE_X_APPLY_DUPLICATE) && snapshot.phase == RESOURCE_X_MASTER_WAIT_PROOF && frame.common.observed_mode == (uint8)PCM_STATE_N) - result = gcs_block_pcm_x_resource_x_master_durable_try( - &frame, &snapshot, &snapshot); + result = gcs_block_pcm_x_resource_x_master_durable_try(&frame, &snapshot, &snapshot); break; case RESOURCE_X_WIRE_LOCAL_PROOF_DECLARATION: - result = cluster_pcm_lock_resource_x_local_proof_exact( - &frame, (int32)env->source_node_id, &snapshot); + result = cluster_pcm_lock_resource_x_local_proof_exact(&frame, (int32)env->source_node_id, + &snapshot); break; case RESOURCE_X_WIRE_BLOCK_TO_N: - result = gcs_block_resource_x_type17_ingress( - env, &frame, authenticated_capability_generation); + result + = gcs_block_resource_x_type17_ingress(env, &frame, authenticated_capability_generation); break; case RESOURCE_X_WIRE_SOURCE_SETTLEMENT_V2: result = gcs_block_resource_x_source_settlement_ingress( env, &frame, authenticated_capability_generation); break; case RESOURCE_X_WIRE_BLOCKED_TO_N: - result = cluster_pcm_lock_resource_x_blocked_to_n_exact( - &frame, (int32)env->source_node_id, &snapshot); + result = cluster_pcm_lock_resource_x_blocked_to_n_exact(&frame, (int32)env->source_node_id, + &snapshot); break; case RESOURCE_X_WIRE_SOURCE_SETTLEMENT_ACK_V2: result = cluster_pcm_lock_resource_x_source_settlement_ack_exact( &frame, (int32)env->source_node_id, &snapshot); - if ((result != RESOURCE_X_APPLY_APPLIED - && result != RESOURCE_X_APPLY_DUPLICATE) + if ((result != RESOURCE_X_APPLY_APPLIED && result != RESOURCE_X_APPLY_DUPLICATE) || gcs_block_resource_x_diagnostic_should_log( - GCS_BLOCK_RESOURCE_X_DIAGNOSTIC_SOURCE_SETTLEMENT_ACK_INGRESS, - (int)result)) + GCS_BLOCK_RESOURCE_X_DIAGNOSTIC_SOURCE_SETTLEMENT_ACK_INGRESS, (int)result)) ereport(LOG, - (errmsg_internal("Resource-X source settlement ACK ingress diagnostic"), - errdetail("source=%u requester=%d attempt=%llu result=%d " - "phase=%u final=%llu", - env->source_node_id, - frame.common.logical_assertion.requester_node, - (unsigned long long) - frame.common.assertion_sequence, - (int)result, (unsigned)snapshot.phase, - (unsigned long long) - snapshot.final_authority_generation))); + (errmsg_internal("Resource-X source settlement ACK ingress diagnostic"), + errdetail("source=%u requester=%d attempt=%llu result=%d " + "phase=%u final=%llu", + env->source_node_id, frame.common.logical_assertion.requester_node, + (unsigned long long)frame.common.assertion_sequence, (int)result, + (unsigned)snapshot.phase, + (unsigned long long)snapshot.final_authority_generation))); break; - case RESOURCE_X_WIRE_INSTALL_SETTLEMENT: - { + case RESOURCE_X_WIRE_INSTALL_SETTLEMENT: { result = cluster_pcm_lock_resource_x_install_settlement_exact( &frame, (int32)env->source_node_id, &snapshot); - if ((result != RESOURCE_X_APPLY_APPLIED - && result != RESOURCE_X_APPLY_DUPLICATE) + if ((result != RESOURCE_X_APPLY_APPLIED && result != RESOURCE_X_APPLY_DUPLICATE) || gcs_block_resource_x_diagnostic_should_log( - GCS_BLOCK_RESOURCE_X_DIAGNOSTIC_INSTALL_SETTLEMENT, - (int)result)) + GCS_BLOCK_RESOURCE_X_DIAGNOSTIC_INSTALL_SETTLEMENT, (int)result)) ereport(LOG, (errmsg_internal("Resource-X install settlement diagnostic"), errdetail("source=%u requester=%d attempt=%llu result=%d " @@ -14282,19 +13415,18 @@ gcs_block_try_resource_x_frame(const ClusterICEnvelope *env, break; } case RESOURCE_X_WIRE_RELEASE_X: - result = cluster_pcm_lock_resource_x_release_x_exact( - &frame, (int32)env->source_node_id, &snapshot); + result = cluster_pcm_lock_resource_x_release_x_exact(&frame, (int32)env->source_node_id, + &snapshot); break; case RESOURCE_X_WIRE_IMAGE_ENVELOPE: case RESOURCE_X_WIRE_AUTHORITY_GRANT: result = gcs_block_resource_x_requester_join_ingress( env, &frame, authenticated_capability_generation, &join_snapshot); - if ((result == RESOURCE_X_APPLY_APPLIED - || result == RESOURCE_X_APPLY_DUPLICATE) + if ((result == RESOURCE_X_APPLY_APPLIED || result == RESOURCE_X_APPLY_DUPLICATE) && (join_snapshot.flags & RESOURCE_X_REQUESTER_JOIN_READY) != 0) { - (void)gcs_block_resource_x_requester_terminal_try( - env, &frame, authenticated_capability_generation, - result == RESOURCE_X_APPLY_DUPLICATE); + (void)gcs_block_resource_x_requester_terminal_try(env, &frame, + authenticated_capability_generation, + result == RESOURCE_X_APPLY_DUPLICATE); } break; } @@ -14316,33 +13448,24 @@ gcs_block_try_resource_x_frame(const ClusterICEnvelope *env, /* Bootstrap owns its own typed action; the local sentinel is not its result. */ if (frame.kind != RESOURCE_X_WIRE_PREASSERT_BOOTSTRAP) cluster_pcm_lock_resource_x_trace_frame(RESOURCE_X_TRACE_APPLY, &frame, - (int32)env->source_node_id, (int32)result); - if (gcs_block_resource_x_frame_diagnostic(frame.kind) - != GCS_BLOCK_RESOURCE_X_DIAGNOSTIC_COUNT - && ((result != RESOURCE_X_APPLY_APPLIED - && result != RESOURCE_X_APPLY_DUPLICATE) + (int32)env->source_node_id, (int32)result); + if (gcs_block_resource_x_frame_diagnostic(frame.kind) != GCS_BLOCK_RESOURCE_X_DIAGNOSTIC_COUNT + && ((result != RESOURCE_X_APPLY_APPLIED && result != RESOURCE_X_APPLY_DUPLICATE) || gcs_block_resource_x_diagnostic_should_log( - gcs_block_resource_x_frame_diagnostic(frame.kind), - (int)result))) + gcs_block_resource_x_frame_diagnostic(frame.kind), (int)result))) ereport(LOG, (errmsg_internal("Resource-X frame ingress diagnostic"), errdetail("kind=%u msg_type=%u source=%u requester=%d " "attempt=%llu result=%d master_phase=%u head=%u " "incompatible=0x%08x blocked=0x%08x proof=%u " "join_flags=0x%08x grant_source=%d image_source=%d", - (unsigned)frame.kind, (unsigned)env->msg_type, - env->source_node_id, + (unsigned)frame.kind, (unsigned)env->msg_type, env->source_node_id, frame.common.logical_assertion.requester_node, - (unsigned long long) - frame.common.assertion_sequence, - (int)result, (unsigned)snapshot.phase, - (unsigned)snapshot.is_head, - snapshot.incompatible_holders_bitmap, - snapshot.blocked_holders_bitmap, - (unsigned)snapshot.proof_kind, - join_snapshot.flags, - join_snapshot.grant_source_node, - join_snapshot.image_source_node))); + (unsigned long long)frame.common.assertion_sequence, (int)result, + (unsigned)snapshot.phase, (unsigned)snapshot.is_head, + snapshot.incompatible_holders_bitmap, snapshot.blocked_holders_bitmap, + (unsigned)snapshot.proof_kind, join_snapshot.flags, + join_snapshot.grant_source_node, join_snapshot.image_source_node))); if (frame.kind != RESOURCE_X_WIRE_PREASSERT_BOOTSTRAP && (result == RESOURCE_X_APPLY_APPLIED || result == RESOURCE_X_APPLY_DUPLICATE)) gcs_block_resource_x_stage_ready_tag(&frame.common.logical_assertion.resource); @@ -14351,8 +13474,7 @@ gcs_block_try_resource_x_frame(const ClusterICEnvelope *env, } static ResourceXApplyResult -gcs_block_resource_x_target_install_snapshot_result( - ClusterPcmOwnResult snapshot_result) +gcs_block_resource_x_target_install_snapshot_result(ClusterPcmOwnResult snapshot_result) { if (snapshot_result == CLUSTER_PCM_OWN_OK) return RESOURCE_X_APPLY_APPLIED; @@ -14414,8 +13536,8 @@ gcs_block_resource_x_target_install_capture_coherent( *follow_state_out = RESOURCE_X_TARGET_INSTALL_INVALID; if (continuation_out != NULL) memset(continuation_out, 0, sizeof(*continuation_out)); - if (buf == NULL || assertion == NULL || before == NULL - || follow_state_out == NULL || continuation_out == NULL) + if (buf == NULL || assertion == NULL || before == NULL || follow_state_out == NULL + || continuation_out == NULL) return RESOURCE_X_APPLY_INVALID; /* A fresh B returned by a failed header check need not still describe * this resource. Coherent B-E-B equality cannot repair that lost @@ -14430,21 +13552,17 @@ gcs_block_resource_x_target_install_capture_coherent( if (observation_result != RESOURCE_X_APPLY_APPLIED) return observation_result; memset(&candidate, 0, sizeof(candidate)); - raw_state - = cluster_pcm_lock_resource_x_bootstrap_round_target_install_capture_exact( - assertion, current_master_node, resource_formation, - master_session_incarnation, r4_record_generation, - requester_sender_connection_generation, - master_ingress_connection_generation, retry_slice_us, - caller_absolute_deadline_us, before, &candidate); + raw_state = cluster_pcm_lock_resource_x_bootstrap_round_target_install_capture_exact( + assertion, current_master_node, resource_formation, master_session_incarnation, + r4_record_generation, requester_sender_connection_generation, + master_ingress_connection_generation, retry_slice_us, caller_absolute_deadline_us, before, + &candidate); memset(&after, 0, sizeof(after)); snapshot_result = cluster_bufmgr_pcm_own_snapshot(buf, &after); if (snapshot_result != CLUSTER_PCM_OWN_OK) - return gcs_block_resource_x_target_install_snapshot_result( - snapshot_result); - *follow_state_out - = cluster_pcm_x_target_install_follow_adjudicate_exact( - before, &after, raw_state, NULL, &candidate); + return gcs_block_resource_x_target_install_snapshot_result(snapshot_result); + *follow_state_out = cluster_pcm_x_target_install_follow_adjudicate_exact( + before, &after, raw_state, NULL, &candidate); *continuation_out = candidate; return RESOURCE_X_APPLY_APPLIED; } @@ -14454,10 +13572,8 @@ gcs_block_resource_x_target_install_capture_coherent( * exact whole-snapshot equality. */ static ResourceXApplyResult gcs_block_resource_x_target_install_classify_coherent( - BufferDesc *buf, - const ResourceXTargetInstallContinuation *continuation, - const ClusterPcmOwnSnapshot *before, - ResourceXTargetInstallFollowState *follow_state_out, + BufferDesc *buf, const ResourceXTargetInstallContinuation *continuation, + const ClusterPcmOwnSnapshot *before, ResourceXTargetInstallFollowState *follow_state_out, ResourceXAcquisitionRef *terminal_ref_out) { ClusterPcmOwnSnapshot after; @@ -14469,21 +13585,18 @@ gcs_block_resource_x_target_install_classify_coherent( *follow_state_out = RESOURCE_X_TARGET_INSTALL_INVALID; if (terminal_ref_out != NULL) memset(terminal_ref_out, 0, sizeof(*terminal_ref_out)); - if (buf == NULL || continuation == NULL || before == NULL - || follow_state_out == NULL || terminal_ref_out == NULL) + if (buf == NULL || continuation == NULL || before == NULL || follow_state_out == NULL + || terminal_ref_out == NULL) return RESOURCE_X_APPLY_INVALID; memset(&candidate_ref, 0, sizeof(candidate_ref)); - raw_state - = cluster_pcm_lock_resource_x_bootstrap_round_target_install_classify_exact( - continuation, before, &candidate_ref); + raw_state = cluster_pcm_lock_resource_x_bootstrap_round_target_install_classify_exact( + continuation, before, &candidate_ref); memset(&after, 0, sizeof(after)); snapshot_result = cluster_bufmgr_pcm_own_snapshot(buf, &after); if (snapshot_result != CLUSTER_PCM_OWN_OK) - return gcs_block_resource_x_target_install_snapshot_result( - snapshot_result); - *follow_state_out - = cluster_pcm_x_target_install_follow_adjudicate_exact( - before, &after, raw_state, &candidate_ref, NULL); + return gcs_block_resource_x_target_install_snapshot_result(snapshot_result); + *follow_state_out = cluster_pcm_x_target_install_follow_adjudicate_exact( + before, &after, raw_state, &candidate_ref, NULL); *terminal_ref_out = candidate_ref; return RESOURCE_X_APPLY_APPLIED; } @@ -14633,15 +13746,13 @@ gcs_block_resource_x_target_acquire_internal( ClusterSemanticAdmissionResult admission_result; ClusterSemanticResourceXPeerOpenResult peer_open_result = CLUSTER_SEMANTIC_RESOURCE_X_PEER_OPEN_NOT_CHECKED; - PcmXSessionAuthResult preflight_session_check - = PCM_X_SESSION_AUTH_INVALID; + PcmXSessionAuthResult preflight_session_check = PCM_X_SESSION_AUTH_INVALID; ResourceXGateSnapshot gate; ResourceXGateSnapshot terminal_gate; ResourceXAssertion assertion; ResourceXDecodedFrame dispatch; ResourceXAcquisitionRef terminal_ref; - ResourceXBootstrapRoundAction action - = RESOURCE_X_BOOTSTRAP_ROUND_FAIL_CLOSED; + ResourceXBootstrapRoundAction action = RESOURCE_X_BOOTSTRAP_ROUND_FAIL_CLOSED; ResourceXBootstrapRoundFailureSnapshot failure_round; ResourceXTargetInstallContinuation target_install_follow; ResourceXCallerWitness local_caller_witness; @@ -14654,17 +13765,14 @@ gcs_block_resource_x_target_acquire_internal( ResourceXFirstFailureEvidence first_failure; ResourceXApplyResult wait_result = RESOURCE_X_APPLY_INVALID; ResourceXApplyResult dispatch_gate_session_result = RESOURCE_X_APPLY_INVALID; - ResourceXApplyResult target_install_observation_result - = RESOURCE_X_APPLY_INVALID; + ResourceXApplyResult target_install_observation_result = RESOURCE_X_APPLY_INVALID; ResourceXApplyResult ownership_loss_result = RESOURCE_X_APPLY_INVALID; ResourceXApplyResult failure_snapshot_result = RESOURCE_X_APPLY_INVALID; ResourceXApplyResult discard_result = RESOURCE_X_APPLY_INVALID; ResourceXApplyResult result = RESOURCE_X_APPLY_BAD_STATE; ClusterPcmOwnResult direct_candidate_result; - PcmXSessionAuthResult dispatch_session_check - = PCM_X_SESSION_AUTH_INVALID; - PcmXSessionAuthResult terminal_session_check - = PCM_X_SESSION_AUTH_INVALID; + PcmXSessionAuthResult dispatch_session_check = PCM_X_SESSION_AUTH_INVALID; + PcmXSessionAuthResult terminal_session_check = PCM_X_SESSION_AUTH_INVALID; ResourceXGateSnapshot rebound_gate; volatile uint64 absolute_deadline_us = 0; uint64 diagnostic_caller_budget_us = gcs_block_pcm_x_retry_timeout_us(); @@ -14682,8 +13790,7 @@ gcs_block_resource_x_target_acquire_internal( uint64 master_session = 0; uint64 rebound_master_session = 0; uint64 terminal_master_session = 0; - uint64 pending_terminal_resample_mismatch - = RESOURCE_X_PENDING_TERMINAL_MISMATCH_NONE; + uint64 pending_terminal_resample_mismatch = RESOURCE_X_PENDING_TERMINAL_MISMATCH_NONE; uint64 now_us = 0; uint64 remaining_us; uint64 retry_slice_us = 0; @@ -14693,8 +13800,7 @@ gcs_block_resource_x_target_acquire_internal( uint32 master_ingress_recheck = 0; uint32 rebound_requester_connection_generation = 0; uint32 rebound_master_connection_generation = 0; - uint32 dispatch_recheck_failure_mask - = RESOURCE_X_DISPATCH_RECHECK_OK; + uint32 dispatch_recheck_failure_mask = RESOURCE_X_DISPATCH_RECHECK_OK; long timeout_ms; int32 master_node = -1; int32 rebound_master_node = -1; @@ -14740,23 +13846,18 @@ gcs_block_resource_x_target_acquire_internal( memset(&resource, 0, sizeof(resource)); direct_init = direct_init_reservation_token != 0; if (buf == NULL || ref_out == NULL - || (!join_only && (r4_record_generation == 0 - || r4_record_generation == UINT64_MAX)) + || (!join_only && (r4_record_generation == 0 || r4_record_generation == UINT64_MAX)) || (join_only && (r4_record_generation != 0 || !direct_init)) || (!direct_init && direct_init_ownership_generation != 0) || direct_init_ownership_generation == UINT64_MAX || direct_init_reservation_token == UINT64_MAX - || (absolute_deadline_us_io != NULL - && *absolute_deadline_us_io == UINT64_MAX) - || cluster_node_id < 0 - || cluster_node_id >= RESOURCE_X_PROTOCOL_NODE_LIMIT) + || (absolute_deadline_us_io != NULL && *absolute_deadline_us_io == UINT64_MAX) + || cluster_node_id < 0 || cluster_node_id >= RESOURCE_X_PROTOCOL_NODE_LIMIT) return RESOURCE_X_APPLY_INVALID; resource = expected_resource != NULL ? *expected_resource : buf->tag; if (join_only) { now_us = gcs_block_pcm_x_monotonic_us(); - if (now_us == 0 - || !resource_x_assertion_init( - &resource, cluster_node_id, &assertion)) + if (now_us == 0 || !resource_x_assertion_init(&resource, cluster_node_id, &assertion)) return RESOURCE_X_APPLY_INVALID; result = cluster_pcm_lock_resource_x_bootstrap_round_direct_init_join_budget_exact( &assertion, direct_init_ownership_generation, direct_init_reservation_token, now_us, @@ -14764,8 +13865,7 @@ gcs_block_resource_x_target_acquire_internal( if (result != RESOURCE_X_APPLY_APPLIED) return result; } - diagnostic_request_sequence - = gcs_block_resource_x_next_diagnostic_request_sequence(); + diagnostic_request_sequence = gcs_block_resource_x_next_diagnostic_request_sequence(); if (aux_context != NULL) { if (aux_context->diagnostic_request_sequence == 0) aux_context->diagnostic_request_sequence = diagnostic_request_sequence; @@ -14777,28 +13877,24 @@ gcs_block_resource_x_target_acquire_internal( wait_diagnostic.request_sequence = diagnostic_request_sequence; wait_diagnostic.budget_us = diagnostic_caller_budget_us; if (direct_init) - direct_init_committed_generation - = direct_init_ownership_generation + 1; + direct_init_committed_generation = direct_init_ownership_generation + 1; memset(&admission, 0, sizeof(admission)); - admission_result = cluster_semantic_activation_enter( - CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1, - CLUSTER_SEMANTIC_TARGET_SIDE, &admission); + admission_result + = cluster_semantic_activation_enter(CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1, + CLUSTER_SEMANTIC_TARGET_SIDE, &admission); if (admission_result != CLUSTER_SEMANTIC_ADMISSION_OK) { ereport(LOG, - (errmsg_internal("Resource-X target acquire diagnostic"), - errdetail("stage=semantic-enter result=%d admission=%d buffer=%d", - (int)RESOURCE_X_APPLY_BAD_STATE, (int)admission_result, - buf->buf_id))); + (errmsg_internal("Resource-X target acquire diagnostic"), + errdetail("stage=semantic-enter result=%d admission=%d buffer=%d", + (int)RESOURCE_X_APPLY_BAD_STATE, (int)admission_result, buf->buf_id))); return RESOURCE_X_APPLY_BAD_STATE; } if (admission.record_generation != r4_record_generation) { - ereport(LOG, - (errmsg_internal("Resource-X target acquire diagnostic"), - errdetail("stage=semantic-generation result=%d record=" UINT64_FORMAT - " expected=" UINT64_FORMAT " buffer=%d", - (int)RESOURCE_X_APPLY_STALE, - admission.record_generation, r4_record_generation, - buf->buf_id))); + ereport(LOG, (errmsg_internal("Resource-X target acquire diagnostic"), + errdetail("stage=semantic-generation result=%d record=" UINT64_FORMAT + " expected=" UINT64_FORMAT " buffer=%d", + (int)RESOURCE_X_APPLY_STALE, admission.record_generation, + r4_record_generation, buf->buf_id))); cluster_semantic_activation_leave(&admission); return RESOURCE_X_APPLY_STALE; } @@ -14807,20 +13903,16 @@ gcs_block_resource_x_target_acquire_internal( PG_TRY(); { - do - { + do { now_us = gcs_block_pcm_x_monotonic_us(); retry_slice_us - = (uint64)Max( - cluster_gcs_block_retransmit_initial_backoff_ms, 1) - * UINT64_C(1000); + = (uint64)Max(cluster_gcs_block_retransmit_initial_backoff_ms, 1) * UINT64_C(1000); if (absolute_deadline_us_io != NULL && *absolute_deadline_us_io != 0) absolute_deadline_us = *absolute_deadline_us_io; else if (absolute_deadline_us == 0) { - absolute_deadline_us = gcs_block_pcm_x_saturating_add_us( - now_us, gcs_block_pcm_x_retry_timeout_us()); - if (absolute_deadline_us_io != NULL - && absolute_deadline_us != UINT64_MAX) + absolute_deadline_us + = gcs_block_pcm_x_saturating_add_us(now_us, gcs_block_pcm_x_retry_timeout_us()); + if (absolute_deadline_us_io != NULL && absolute_deadline_us != UINT64_MAX) *absolute_deadline_us_io = absolute_deadline_us; } if (now_us == 0 || now_us == UINT64_MAX || retry_slice_us == 0 @@ -14837,8 +13929,7 @@ gcs_block_resource_x_target_acquire_internal( * current gate/transport identity, and retry only under the first R7 * absolute deadline. No round, proof, or image exists to preserve. */ diagnostic_stage = "preflight-membership"; - for (;;) - { + for (;;) { bool master_ready; bool requester_ready; @@ -14846,20 +13937,15 @@ gcs_block_resource_x_target_acquire_internal( MemSet(&assertion, 0, sizeof(assertion)); requester_sender_connection_generation = 0; master_ingress_connection_generation = 0; - preflight_session_check - = gcs_block_resource_x_gate_session_snapshot_result( - &resource, &gate, &master_node, &master_session); - if (preflight_session_check != PCM_X_SESSION_AUTH_OK) - { - if (cluster_gcs_pcm_x_auth_result_retryable( - preflight_session_check)) + preflight_session_check = gcs_block_resource_x_gate_session_snapshot_result( + &resource, &gate, &master_node, &master_session); + if (preflight_session_check != PCM_X_SESSION_AUTH_OK) { + if (cluster_gcs_pcm_x_auth_result_retryable(preflight_session_check)) goto preflight_membership_wait; result = RESOURCE_X_APPLY_BAD_STATE; break; } - if (!resource_x_assertion_init( - &resource, cluster_node_id, &assertion)) - { + if (!resource_x_assertion_init(&resource, cluster_node_id, &assertion)) { result = RESOURCE_X_APPLY_BAD_STATE; break; } @@ -14867,45 +13953,30 @@ gcs_block_resource_x_target_acquire_internal( * formation. gate.formation names this Resource-X entry's * formation and is frozen with master_session below; the two * counters are intentionally independent and must not be compared. */ - if (!cluster_semantic_activation_recheck(&admission)) - { + if (!cluster_semantic_activation_recheck(&admission)) { result = RESOURCE_X_APPLY_STALE; break; } - requester_ready - = gcs_block_pcm_x_resource_x_peer_ready_exact( - master_node, - &requester_sender_connection_generation); - master_ready - = gcs_block_pcm_x_resource_x_peer_ready_exact( - master_node, - &master_ingress_connection_generation); - if (requester_ready && master_ready) - { + requester_ready = gcs_block_pcm_x_resource_x_peer_ready_exact( + master_node, &requester_sender_connection_generation); + master_ready = gcs_block_pcm_x_resource_x_peer_ready_exact( + master_node, &master_ingress_connection_generation); + if (requester_ready && master_ready) { bool peer_matches; - if (master_node == cluster_node_id) - { - peer_matches - = gcs_block_resource_x_target_peer_matches_exact( - &admission, master_node, - master_ingress_connection_generation); - peer_open_result = peer_matches - ? CLUSTER_SEMANTIC_RESOURCE_X_PEER_OPEN_MATCH - : CLUSTER_SEMANTIC_RESOURCE_X_PEER_OPEN_INVALID_INPUT; - } - else - { + if (master_node == cluster_node_id) { + peer_matches = gcs_block_resource_x_target_peer_matches_exact( + &admission, master_node, master_ingress_connection_generation); peer_open_result - = cluster_semantic_activation_resource_x_peer_open_check( - &admission, master_node, - master_ingress_connection_generation); + = peer_matches ? CLUSTER_SEMANTIC_RESOURCE_X_PEER_OPEN_MATCH + : CLUSTER_SEMANTIC_RESOURCE_X_PEER_OPEN_INVALID_INPUT; + } else { + peer_open_result = cluster_semantic_activation_resource_x_peer_open_check( + &admission, master_node, master_ingress_connection_generation); peer_matches - = peer_open_result - == CLUSTER_SEMANTIC_RESOURCE_X_PEER_OPEN_MATCH; + = peer_open_result == CLUSTER_SEMANTIC_RESOURCE_X_PEER_OPEN_MATCH; } - if (peer_matches) - { + if (peer_matches) { preflight_current = true; break; } @@ -14921,10 +13992,9 @@ gcs_block_resource_x_target_acquire_internal( break; } remaining_us = retry_slice_us; - timeout_ms = (long) Min( - (uint64) Max( - cluster_gcs_block_retransmit_initial_backoff_ms, 1), - (remaining_us + UINT64_C(999)) / UINT64_C(1000)); + timeout_ms + = (long)Min((uint64)Max(cluster_gcs_block_retransmit_initial_backoff_ms, 1), + (remaining_us + UINT64_C(999)) / UINT64_C(1000)); if (timeout_ms <= 0) timeout_ms = 1; CHECK_FOR_INTERRUPTS(); @@ -14936,48 +14006,47 @@ gcs_block_resource_x_target_acquire_internal( diagnostic_stage = "round-loop"; - for (;;) { - CHECK_FOR_INTERRUPTS(); - diagnostic_head_expired = false; - now_us = gcs_block_pcm_x_monotonic_us(); - if (now_us == 0 || now_us == UINT64_MAX) { - result = RESOURCE_X_APPLY_INVALID; - break; - } - if (wait_diagnostic.state.started_us != 0) - gcs_block_resource_x_requester_wait_note(&wait_diagnostic, - wait_diagnostic.state.reason); - target_retained_release_inflight = false; - if (direct_init && creation_caller.joined_request.assertion_sequence == 0 - && caller_witness->joined_request.assertion_sequence != 0) - creation_caller = *caller_witness; - result = cluster_pcm_lock_resource_x_caller_observe_exact( - &assertion, gate.formation, master_session, admission.record_generation, - caller_witness); - if (result == RESOURCE_X_APPLY_DUPLICATE) { - gcs_block_resource_x_requester_wait_note(&wait_diagnostic, - caller_witness->reobserve_reason); - memset(&target_install_follow, 0, sizeof(target_install_follow)); - target_install_preuse_retry_seen = false; - continue; - } - if (result != RESOURCE_X_APPLY_APPLIED) { - diagnostic_stage = "caller-history-reject"; - break; - } - if (direct_init && creation_caller.joined_request.assertion_sequence == 0 - && caller_witness->joined_request.assertion_sequence != 0) - creation_caller = *caller_witness; - target_retained_release_post_mutation = false; - memset(&own, 0, sizeof(own)); - diagnostic_stage = "own-snapshot"; - own_result = cluster_bufmgr_pcm_own_snapshot(buf, &own); + for (;;) { + CHECK_FOR_INTERRUPTS(); + diagnostic_head_expired = false; + now_us = gcs_block_pcm_x_monotonic_us(); + if (now_us == 0 || now_us == UINT64_MAX) { + result = RESOURCE_X_APPLY_INVALID; + break; + } + if (wait_diagnostic.state.started_us != 0) + gcs_block_resource_x_requester_wait_note(&wait_diagnostic, + wait_diagnostic.state.reason); + target_retained_release_inflight = false; + if (direct_init && creation_caller.joined_request.assertion_sequence == 0 + && caller_witness->joined_request.assertion_sequence != 0) + creation_caller = *caller_witness; + result = cluster_pcm_lock_resource_x_caller_observe_exact( + &assertion, gate.formation, master_session, admission.record_generation, + caller_witness); + if (result == RESOURCE_X_APPLY_DUPLICATE) { + gcs_block_resource_x_requester_wait_note(&wait_diagnostic, + caller_witness->reobserve_reason); + memset(&target_install_follow, 0, sizeof(target_install_follow)); + target_install_preuse_retry_seen = false; + continue; + } + if (result != RESOURCE_X_APPLY_APPLIED) { + diagnostic_stage = "caller-history-reject"; + break; + } + if (direct_init && creation_caller.joined_request.assertion_sequence == 0 + && caller_witness->joined_request.assertion_sequence != 0) + creation_caller = *caller_witness; + target_retained_release_post_mutation = false; + memset(&own, 0, sizeof(own)); + diagnostic_stage = "own-snapshot"; + own_result = cluster_bufmgr_pcm_own_snapshot(buf, &own); if (own_result != CLUSTER_PCM_OWN_OK) { - result = own_result == CLUSTER_PCM_OWN_BUSY - ? RESOURCE_X_APPLY_BAD_STATE - : own_result == CLUSTER_PCM_OWN_STALE - ? RESOURCE_X_APPLY_STALE - : RESOURCE_X_APPLY_RECOVERY_BLOCKED; + result = own_result == CLUSTER_PCM_OWN_BUSY ? RESOURCE_X_APPLY_BAD_STATE + : own_result == CLUSTER_PCM_OWN_STALE + ? RESOURCE_X_APPLY_STALE + : RESOURCE_X_APPLY_RECOVERY_BLOCKED; break; } if (direct_init && !join_only && creation_reobserve_out != NULL @@ -15036,190 +14105,157 @@ gcs_block_resource_x_target_acquire_internal( (unsigned)own.buffer_type, own.flags, own.semantic_buf_state))); } - break; - } - if (target_install_follow.valid) { - diagnostic_stage = "target-install-follow-classify"; - diagnostic_follow_attempt = target_install_follow.acquisition_generation; - diagnostic_follow_generation - = target_install_follow.expected_x_ownership_generation; - diagnostic_follow_token = target_install_follow.reservation_token; - target_install_observation_result - = gcs_block_resource_x_target_install_classify_coherent( - buf, &target_install_follow, &own, - &target_install_follow_state, &terminal_ref); - if (target_install_observation_result - != RESOURCE_X_APPLY_APPLIED) { - result = target_install_observation_result; - break; - } - if (target_install_follow_state == RESOURCE_X_TARGET_INSTALL_RESAMPLE) { - gcs_block_resource_x_requester_wait_note(&wait_diagnostic, - PCM_RX_WAIT_OBSERVATION); + break; + } + if (target_install_follow.valid) { + diagnostic_stage = "target-install-follow-classify"; + diagnostic_follow_attempt = target_install_follow.acquisition_generation; + diagnostic_follow_generation + = target_install_follow.expected_x_ownership_generation; + diagnostic_follow_token = target_install_follow.reservation_token; + target_install_observation_result + = gcs_block_resource_x_target_install_classify_coherent( + buf, &target_install_follow, &own, &target_install_follow_state, + &terminal_ref); + if (target_install_observation_result != RESOURCE_X_APPLY_APPLIED) { + result = target_install_observation_result; + break; + } + if (target_install_follow_state == RESOURCE_X_TARGET_INSTALL_RESAMPLE) { + gcs_block_resource_x_requester_wait_note(&wait_diagnostic, + PCM_RX_WAIT_OBSERVATION); + memset(&target_install_follow, 0, sizeof(target_install_follow)); + target_install_preuse_retry_seen = false; + continue; + } + if (target_install_follow_state == RESOURCE_X_TARGET_INSTALL_TERMINAL) { + action = RESOURCE_X_BOOTSTRAP_ROUND_TERMINAL; + goto target_install_terminal_recheck; + } + if (target_install_follow_state == RESOURCE_X_TARGET_INSTALL_PREUSE_RETRY) { + target_install_preuse_retry_seen = true; + diagnostic_stage = "target-install-preuse-wait"; + gcs_block_resource_x_requester_wait_note(&wait_diagnostic, + PCM_RX_WAIT_PREUSE); + now_us = gcs_block_pcm_x_monotonic_us(); + remaining_us = retry_slice_us; + timeout_ms = (long)Min( + (uint64)Max(cluster_gcs_block_retransmit_initial_backoff_ms, 1), + (remaining_us + UINT64_C(999)) / UINT64_C(1000)); + if (timeout_ms <= 0) + timeout_ms = 1; + wait_result + = cluster_pcm_lock_resource_x_bootstrap_round_target_install_wait_exact( + &target_install_follow, RESOURCE_X_TARGET_INSTALL_PREUSE_RETRY, + timeout_ms); + if (wait_result == RESOURCE_X_APPLY_DUPLICATE) { memset(&target_install_follow, 0, sizeof(target_install_follow)); target_install_preuse_retry_seen = false; continue; } - if (target_install_follow_state - == RESOURCE_X_TARGET_INSTALL_TERMINAL) { - action = RESOURCE_X_BOOTSTRAP_ROUND_TERMINAL; - goto target_install_terminal_recheck; - } - if (target_install_follow_state - == RESOURCE_X_TARGET_INSTALL_PREUSE_RETRY) { - target_install_preuse_retry_seen = true; - diagnostic_stage = "target-install-preuse-wait"; - gcs_block_resource_x_requester_wait_note(&wait_diagnostic, - PCM_RX_WAIT_PREUSE); - now_us = gcs_block_pcm_x_monotonic_us(); - remaining_us = retry_slice_us; - timeout_ms = (long) Min( - (uint64) Max( - cluster_gcs_block_retransmit_initial_backoff_ms, - 1), - (remaining_us + UINT64_C(999)) - / UINT64_C(1000)); - if (timeout_ms <= 0) - timeout_ms = 1; - wait_result - = cluster_pcm_lock_resource_x_bootstrap_round_target_install_wait_exact( - &target_install_follow, - RESOURCE_X_TARGET_INSTALL_PREUSE_RETRY, - timeout_ms); - if (wait_result == RESOURCE_X_APPLY_DUPLICATE) { - memset(&target_install_follow, 0, - sizeof(target_install_follow)); - target_install_preuse_retry_seen = false; - continue; - } - if (wait_result == RESOURCE_X_APPLY_APPLIED) { - memset(&target_install_follow, 0, sizeof(target_install_follow)); - target_install_preuse_retry_seen = false; - continue; - } - if (wait_result == RESOURCE_X_APPLY_STALE - && target_install_preuse_retry_seen) { - memset(&target_install_follow, 0, - sizeof(target_install_follow)); - target_install_preuse_retry_seen = false; - continue; - } - result = wait_result; - break; - } - if (target_install_follow_state - == RESOURCE_X_TARGET_INSTALL_INFLIGHT) { - diagnostic_stage = "target-install-continuation-wait"; - gcs_block_resource_x_requester_wait_note(&wait_diagnostic, - PCM_RX_WAIT_INSTALL); - now_us = gcs_block_pcm_x_monotonic_us(); - remaining_us = retry_slice_us; - timeout_ms = (long) Min( - (uint64) Max( - cluster_gcs_block_retransmit_initial_backoff_ms, - 1), - (remaining_us + UINT64_C(999)) - / UINT64_C(1000)); - if (timeout_ms <= 0) - timeout_ms = 1; - wait_result - = cluster_pcm_lock_resource_x_bootstrap_round_target_install_wait_exact( - &target_install_follow, - RESOURCE_X_TARGET_INSTALL_INFLIGHT, - timeout_ms); - if (wait_result == RESOURCE_X_APPLY_APPLIED - || wait_result == RESOURCE_X_APPLY_DUPLICATE) { - memset(&target_install_follow, 0, sizeof(target_install_follow)); - target_install_preuse_retry_seen = false; - continue; - } - if (wait_result == RESOURCE_X_APPLY_STALE - && target_install_preuse_retry_seen) { - memset(&target_install_follow, 0, - sizeof(target_install_follow)); - target_install_preuse_retry_seen = false; - continue; - } - result = wait_result; - break; + if (wait_result == RESOURCE_X_APPLY_APPLIED) { + memset(&target_install_follow, 0, sizeof(target_install_follow)); + target_install_preuse_retry_seen = false; + continue; } - if (target_install_follow_state - == RESOURCE_X_TARGET_INSTALL_STALE + if (wait_result == RESOURCE_X_APPLY_STALE && target_install_preuse_retry_seen) { - memset(&target_install_follow, 0, - sizeof(target_install_follow)); + memset(&target_install_follow, 0, sizeof(target_install_follow)); target_install_preuse_retry_seen = false; continue; } - result = target_install_follow_state - == RESOURCE_X_TARGET_INSTALL_STALE - ? RESOURCE_X_APPLY_STALE - : target_install_follow_state - == RESOURCE_X_TARGET_INSTALL_RECOVERY_BLOCKED - ? RESOURCE_X_APPLY_RECOVERY_BLOCKED - : RESOURCE_X_APPLY_INVALID; + result = wait_result; break; } - target_install_observation_result - = gcs_block_resource_x_target_install_capture_coherent( - buf, &assertion, master_node, gate.formation, master_session, - admission.record_generation, requester_sender_connection_generation, - master_ingress_connection_generation, retry_slice_us, - absolute_deadline_us, &own, - aux_context != NULL && !direct_init && !join_only - && ClusterBufferAuxiliaryObservationUnowned( - BufferDescriptorGetBuffer(buf)), - &target_install_follow_state, &target_install_follow); - if (target_install_observation_result - != RESOURCE_X_APPLY_APPLIED) { - result = target_install_observation_result; + if (target_install_follow_state == RESOURCE_X_TARGET_INSTALL_INFLIGHT) { + diagnostic_stage = "target-install-continuation-wait"; + gcs_block_resource_x_requester_wait_note(&wait_diagnostic, + PCM_RX_WAIT_INSTALL); + now_us = gcs_block_pcm_x_monotonic_us(); + remaining_us = retry_slice_us; + timeout_ms = (long)Min( + (uint64)Max(cluster_gcs_block_retransmit_initial_backoff_ms, 1), + (remaining_us + UINT64_C(999)) / UINT64_C(1000)); + if (timeout_ms <= 0) + timeout_ms = 1; + wait_result + = cluster_pcm_lock_resource_x_bootstrap_round_target_install_wait_exact( + &target_install_follow, RESOURCE_X_TARGET_INSTALL_INFLIGHT, + timeout_ms); + if (wait_result == RESOURCE_X_APPLY_APPLIED + || wait_result == RESOURCE_X_APPLY_DUPLICATE) { + memset(&target_install_follow, 0, sizeof(target_install_follow)); + target_install_preuse_retry_seen = false; + continue; + } + if (wait_result == RESOURCE_X_APPLY_STALE + && target_install_preuse_retry_seen) { + memset(&target_install_follow, 0, sizeof(target_install_follow)); + target_install_preuse_retry_seen = false; + continue; + } + result = wait_result; break; } - if (target_install_follow_state - == RESOURCE_X_TARGET_INSTALL_RESAMPLE) - continue; - if (target_install_follow_state - == RESOURCE_X_TARGET_INSTALL_INFLIGHT - || target_install_follow_state - == RESOURCE_X_TARGET_INSTALL_TERMINAL - || target_install_follow_state - == RESOURCE_X_TARGET_INSTALL_PREUSE_RETRY) + if (target_install_follow_state == RESOURCE_X_TARGET_INSTALL_STALE + && target_install_preuse_retry_seen) { + memset(&target_install_follow, 0, sizeof(target_install_follow)); + target_install_preuse_retry_seen = false; continue; - if (direct_init) { - cached_local_x - = own.pcm_state == (uint8)PCM_STATE_X - && own.flags == 0 - && own.generation - == direct_init_committed_generation - && own.writer_activation_token == 0 - && own.resource_x_activation_generation == 0; + } + result = target_install_follow_state == RESOURCE_X_TARGET_INSTALL_STALE + ? RESOURCE_X_APPLY_STALE + : target_install_follow_state + == RESOURCE_X_TARGET_INSTALL_RECOVERY_BLOCKED + ? RESOURCE_X_APPLY_RECOVERY_BLOCKED + : RESOURCE_X_APPLY_INVALID; + break; + } + target_install_observation_result + = gcs_block_resource_x_target_install_capture_coherent( + buf, &assertion, master_node, gate.formation, master_session, + admission.record_generation, requester_sender_connection_generation, + master_ingress_connection_generation, retry_slice_us, absolute_deadline_us, + &own, + aux_context != NULL && !direct_init && !join_only + && ClusterBufferAuxiliaryObservationUnowned( + BufferDescriptorGetBuffer(buf)), + &target_install_follow_state, &target_install_follow); + if (target_install_observation_result != RESOURCE_X_APPLY_APPLIED) { + result = target_install_observation_result; + break; + } + if (target_install_follow_state == RESOURCE_X_TARGET_INSTALL_RESAMPLE) + continue; + if (target_install_follow_state == RESOURCE_X_TARGET_INSTALL_INFLIGHT + || target_install_follow_state == RESOURCE_X_TARGET_INSTALL_TERMINAL + || target_install_follow_state == RESOURCE_X_TARGET_INSTALL_PREUSE_RETRY) + continue; + if (direct_init) { + cached_local_x = own.pcm_state == (uint8)PCM_STATE_X && own.flags == 0 + && own.generation == direct_init_committed_generation + && own.writer_activation_token == 0 + && own.resource_x_activation_generation == 0; if (!cached_local_x) { direct_init_pending_n = own.pcm_state == (uint8)PCM_STATE_N - && own.flags - == PCM_OWN_FLAG_GRANT_PENDING - && own.generation - == direct_init_ownership_generation - && own.reservation_token - == direct_init_reservation_token + && own.flags == PCM_OWN_FLAG_GRANT_PENDING + && own.generation == direct_init_ownership_generation + && own.reservation_token == direct_init_reservation_token && own.writer_activation_token == 0 && own.resource_x_activation_generation == 0; - if (!direct_init_pending_n) { - result = RESOURCE_X_APPLY_STALE; - break; - } + if (!direct_init_pending_n) { + result = RESOURCE_X_APPLY_STALE; + break; + } if (direct_init_pending_n) { direct_candidate_result - = cluster_bufmgr_pcm_own_n_direct_init_candidate_exact( - buf, &own); + = cluster_bufmgr_pcm_own_n_direct_init_candidate_exact(buf, &own); if (direct_candidate_result != CLUSTER_PCM_OWN_OK) { - if (direct_candidate_result - == CLUSTER_PCM_OWN_STALE) { - memset(&failure_live, 0, - sizeof(failure_live)); + if (direct_candidate_result == CLUSTER_PCM_OWN_STALE) { + memset(&failure_live, 0, sizeof(failure_live)); own_result - = cluster_bufmgr_pcm_own_snapshot( - buf, &failure_live); + = cluster_bufmgr_pcm_own_snapshot(buf, &failure_live); if (own_result == CLUSTER_PCM_OWN_OK) { target_install_observation_result = gcs_block_resource_x_target_install_capture_coherent( @@ -15234,29 +14270,27 @@ gcs_block_resource_x_target_acquire_internal( &target_install_follow_state, &target_install_follow); if (target_install_observation_result - != RESOURCE_X_APPLY_APPLIED) { + != RESOURCE_X_APPLY_APPLIED) { result = target_install_observation_result; break; } if (target_install_follow_state - == RESOURCE_X_TARGET_INSTALL_RESAMPLE) + == RESOURCE_X_TARGET_INSTALL_RESAMPLE) continue; if (target_install_follow_state == RESOURCE_X_TARGET_INSTALL_INFLIGHT || target_install_follow_state - == RESOURCE_X_TARGET_INSTALL_TERMINAL + == RESOURCE_X_TARGET_INSTALL_TERMINAL || target_install_follow_state - == RESOURCE_X_TARGET_INSTALL_PREUSE_RETRY) - continue; + == RESOURCE_X_TARGET_INSTALL_PREUSE_RETRY) + continue; } } - result - = direct_candidate_result == CLUSTER_PCM_OWN_BUSY - ? RESOURCE_X_APPLY_BAD_STATE - : direct_candidate_result - == CLUSTER_PCM_OWN_STALE - ? RESOURCE_X_APPLY_STALE - : RESOURCE_X_APPLY_RECOVERY_BLOCKED; + result = direct_candidate_result == CLUSTER_PCM_OWN_BUSY + ? RESOURCE_X_APPLY_BAD_STATE + : direct_candidate_result == CLUSTER_PCM_OWN_STALE + ? RESOURCE_X_APPLY_STALE + : RESOURCE_X_APPLY_RECOVERY_BLOCKED; break; } } @@ -15307,12 +14341,9 @@ gcs_block_resource_x_target_acquire_internal( gcs_block_resource_x_requester_wait_note(&wait_diagnostic, PCM_RX_WAIT_RESERVATION); remaining_us = retry_slice_us; - timeout_ms = (long) Min( - (uint64) Max( - cluster_gcs_block_retransmit_initial_backoff_ms, - 1), - (remaining_us + UINT64_C(999)) - / UINT64_C(1000)); + timeout_ms = (long)Min( + (uint64)Max(cluster_gcs_block_retransmit_initial_backoff_ms, 1), + (remaining_us + UINT64_C(999)) / UINT64_C(1000)); if (timeout_ms <= 0) timeout_ms = 1; CHECK_FOR_INTERRUPTS(); @@ -15323,15 +14354,12 @@ gcs_block_resource_x_target_acquire_internal( if (own.pcm_state == (uint8)PCM_STATE_N) { ClusterPcmOwnResult n_candidate_result; - if ((own.flags == PCM_OWN_FLAG_REVOKING - || own.flags == 0) - && own.reservation_token != 0 - && own.reservation_token != UINT64_MAX + if ((own.flags == PCM_OWN_FLAG_REVOKING || own.flags == 0) + && own.reservation_token != 0 && own.reservation_token != UINT64_MAX && own.writer_activation_token == 0 && own.resource_x_activation_generation == 0) { ClusterPcmOwnSnapshot resampled; - ClusterPcmOwnResult current_candidate_result - = CLUSTER_PCM_OWN_INVALID; + ClusterPcmOwnResult current_candidate_result = CLUSTER_PCM_OWN_INVALID; bool pair_exact; bool buffer_exact = false; bool undrained_current_predecessor = false; @@ -15339,9 +14367,8 @@ gcs_block_resource_x_target_acquire_internal( diagnostic_stage = "n-predecessor-observe"; pair_exact = cluster_pcm_lock_resource_x_holder_pair_retained_fence_exact( - &assertion.resource, master_node, - master_session, gate.formation, - own.generation); + &assertion.resource, master_node, master_session, + gate.formation, own.generation); diagnostic_n_predecessor_pair = pair_exact; diagnostic_n_predecessor_result = CLUSTER_PCM_OWN_INVALID; if (pair_exact) { @@ -15358,38 +14385,30 @@ gcs_block_resource_x_target_acquire_internal( continue; } } - target_retained_release_inflight - = pair_exact && buffer_exact; + target_retained_release_inflight = pair_exact && buffer_exact; target_retained_release_post_mutation - = target_retained_release_inflight - && own.flags == 0; - if (pair_exact && !buffer_exact - && own.flags == 0) { + = target_retained_release_inflight && own.flags == 0; + if (pair_exact && !buffer_exact && own.flags == 0) { /* DROP's clean CURRENT and retained PI classification * came from one physical observation above. Neither * grants authority or consumes the predecessor. */ undrained_current_predecessor = cluster_gcs_resource_x_target_undrained_current_predecessor_exact( - pair_exact, buffer_exact, - current_candidate_result, &own); + pair_exact, buffer_exact, current_candidate_result, &own); } - if ((pair_exact && !buffer_exact - && !undrained_current_predecessor) + if ((pair_exact && !buffer_exact && !undrained_current_predecessor) || (own.flags == PCM_OWN_FLAG_REVOKING && !target_retained_release_inflight)) { memset(&resampled, 0, sizeof(resampled)); - own_result = cluster_bufmgr_pcm_own_snapshot( - buf, &resampled); + own_result = cluster_bufmgr_pcm_own_snapshot(buf, &resampled); if (own_result == CLUSTER_PCM_OWN_OK - && memcmp(&resampled, &own, - sizeof(own)) != 0) + && memcmp(&resampled, &own, sizeof(own)) != 0) continue; if (own_result == CLUSTER_PCM_OWN_OK) gcs_block_resource_x_fail_closed_current(); - result = own_result - == CLUSTER_PCM_OWN_STALE - ? RESOURCE_X_APPLY_STALE - : RESOURCE_X_APPLY_RECOVERY_BLOCKED; + result = own_result == CLUSTER_PCM_OWN_STALE + ? RESOURCE_X_APPLY_STALE + : RESOURCE_X_APPLY_RECOVERY_BLOCKED; break; } } @@ -15401,9 +14420,8 @@ gcs_block_resource_x_target_acquire_internal( * the requester installs only after the exact grant. */ memset(&failure_live, 0, sizeof(failure_live)); diagnostic_stage = "n-assertion-candidate"; - n_candidate_result - = cluster_bufmgr_pcm_own_n_assertion_candidate_exact( - buf, &own, &failure_live); + n_candidate_result = cluster_bufmgr_pcm_own_n_assertion_candidate_exact( + buf, &own, &failure_live); if (n_candidate_result != CLUSTER_PCM_OWN_OK) { if (n_candidate_result == CLUSTER_PCM_OWN_STALE) { target_install_observation_result @@ -15418,19 +14436,19 @@ gcs_block_resource_x_target_acquire_internal( BufferDescriptorGetBuffer(buf)), &target_install_follow_state, &target_install_follow); if (target_install_observation_result - != RESOURCE_X_APPLY_APPLIED) { + != RESOURCE_X_APPLY_APPLIED) { result = target_install_observation_result; break; } if (target_install_follow_state - == RESOURCE_X_TARGET_INSTALL_RESAMPLE) + == RESOURCE_X_TARGET_INSTALL_RESAMPLE) continue; if (target_install_follow_state == RESOURCE_X_TARGET_INSTALL_INFLIGHT || target_install_follow_state - == RESOURCE_X_TARGET_INSTALL_TERMINAL + == RESOURCE_X_TARGET_INSTALL_TERMINAL || target_install_follow_state - == RESOURCE_X_TARGET_INSTALL_PREUSE_RETRY) + == RESOURCE_X_TARGET_INSTALL_PREUSE_RETRY) continue; now_us = gcs_block_pcm_x_monotonic_us(); if (cluster_gcs_resource_x_target_preassert_resample_exact( @@ -15443,86 +14461,65 @@ gcs_block_resource_x_target_acquire_internal( continue; } } - result - = gcs_block_pcm_x_resource_x_remote_s_own_result( - n_candidate_result); - memset(&failure_round, 0, - sizeof(failure_round)); - failure_snapshot_result - = cluster_pcm_lock_resource_x_bootstrap_round_failure_snapshot_exact( - &assertion, master_node, gate.formation, - master_session, - admission.record_generation, - requester_sender_connection_generation, - master_ingress_connection_generation, - retry_slice_us, &failure_round); - memset(&first_failure, 0, - sizeof(first_failure)); - first_failure.tag = assertion.resource; - first_failure.request_sequence - = diagnostic_request_sequence; - first_failure.admission_generation - = admission.record_generation; - first_failure.requester_node - = assertion.requester_node; - first_failure.buffer_generation_before - = own.generation; - first_failure.buffer_generation_after - = failure_live.generation; - first_failure.buffer_token_before - = own.reservation_token; - first_failure.buffer_token_after - = failure_live.reservation_token; - first_failure.buffer_writer_token_before - = own.writer_activation_token; - first_failure.buffer_writer_token_after - = failure_live.writer_activation_token; - first_failure.buffer_resource_x_generation_before - = own.resource_x_activation_generation; - first_failure.buffer_resource_x_generation_after - = failure_live.resource_x_activation_generation; - first_failure.formation = gate.formation; - first_failure.master_session = master_session; - first_failure.r4_generation - = admission.record_generation; - first_failure.absolute_deadline_us - = absolute_deadline_us; - first_failure.remote_s_stage - = RESOURCE_X_REMOTE_S_STAGE_NONE; - first_failure.failure_domain - = gcs_block_resource_x_pre_mutation_domain( - n_candidate_result); - first_failure.result = result; - if (failure_snapshot_result - == RESOURCE_X_APPLY_APPLIED) { - first_failure.base_authority_generation - = failure_round.base_authority_generation; - first_failure.authority_generation - = failure_round.authority_generation; - first_failure.assertion_sequence - = failure_round.ref.acquisition_generation; - first_failure.round_terminal - = failure_round.terminal != 0; - first_failure.round_phase - = failure_round.round_phase; - first_failure.round_progress_flags - = failure_round.progress_flags; - } - gcs_block_resource_x_first_failure_record( - &first_failure); - first_failure_recorded = true; - break; + result = gcs_block_pcm_x_resource_x_remote_s_own_result( + n_candidate_result); + memset(&failure_round, 0, sizeof(failure_round)); + failure_snapshot_result + = cluster_pcm_lock_resource_x_bootstrap_round_failure_snapshot_exact( + &assertion, master_node, gate.formation, master_session, + admission.record_generation, + requester_sender_connection_generation, + master_ingress_connection_generation, retry_slice_us, + &failure_round); + memset(&first_failure, 0, sizeof(first_failure)); + first_failure.tag = assertion.resource; + first_failure.request_sequence = diagnostic_request_sequence; + first_failure.admission_generation = admission.record_generation; + first_failure.requester_node = assertion.requester_node; + first_failure.buffer_generation_before = own.generation; + first_failure.buffer_generation_after = failure_live.generation; + first_failure.buffer_token_before = own.reservation_token; + first_failure.buffer_token_after = failure_live.reservation_token; + first_failure.buffer_writer_token_before + = own.writer_activation_token; + first_failure.buffer_writer_token_after + = failure_live.writer_activation_token; + first_failure.buffer_resource_x_generation_before + = own.resource_x_activation_generation; + first_failure.buffer_resource_x_generation_after + = failure_live.resource_x_activation_generation; + first_failure.formation = gate.formation; + first_failure.master_session = master_session; + first_failure.r4_generation = admission.record_generation; + first_failure.absolute_deadline_us = absolute_deadline_us; + first_failure.remote_s_stage = RESOURCE_X_REMOTE_S_STAGE_NONE; + first_failure.failure_domain + = gcs_block_resource_x_pre_mutation_domain(n_candidate_result); + first_failure.result = result; + if (failure_snapshot_result == RESOURCE_X_APPLY_APPLIED) { + first_failure.base_authority_generation + = failure_round.base_authority_generation; + first_failure.authority_generation + = failure_round.authority_generation; + first_failure.assertion_sequence + = failure_round.ref.acquisition_generation; + first_failure.round_terminal = failure_round.terminal != 0; + first_failure.round_phase = failure_round.round_phase; + first_failure.round_progress_flags + = failure_round.progress_flags; + } + gcs_block_resource_x_first_failure_record(&first_failure); + first_failure_recorded = true; + break; } } } else if (own.generation == 0) { result = RESOURCE_X_APPLY_STALE; break; } - cached_local_x - = own.pcm_state == (uint8)PCM_STATE_X - && own.flags == 0 - && own.writer_activation_token == 0 - && own.resource_x_activation_generation == 0; + cached_local_x = own.pcm_state == (uint8)PCM_STATE_X && own.flags == 0 + && own.writer_activation_token == 0 + && own.resource_x_activation_generation == 0; } if (target_retained_release_inflight) { wait_result = gcs_block_resource_x_gate_session_recheck_result( @@ -15539,8 +14536,8 @@ gcs_block_resource_x_target_acquire_internal( if (target_retained_release_post_mutation) gcs_block_resource_x_fail_closed_current(); result = target_retained_release_post_mutation - ? RESOURCE_X_APPLY_RECOVERY_BLOCKED - : RESOURCE_X_APPLY_STALE; + ? RESOURCE_X_APPLY_RECOVERY_BLOCKED + : RESOURCE_X_APPLY_STALE; break; } diagnostic_stage = "retained-release-wait"; @@ -15626,72 +14623,59 @@ gcs_block_resource_x_target_acquire_internal( cluster_pcm_vm_metric_note(&resource, PCM_VM_HEAD_JOIN); diagnostic_join_recorded = true; } - if (action == RESOURCE_X_BOOTSTRAP_ROUND_TERMINAL) { - diagnostic_stage = "terminal-recheck"; - if (target_install_follow.valid) { - memset(&failure_live, 0, sizeof(failure_live)); - own_result = cluster_bufmgr_pcm_own_snapshot( - buf, &failure_live); - if (own_result != CLUSTER_PCM_OWN_OK) { - result = own_result == CLUSTER_PCM_OWN_BUSY - ? RESOURCE_X_APPLY_BAD_STATE - : own_result == CLUSTER_PCM_OWN_STALE - ? RESOURCE_X_APPLY_STALE - : RESOURCE_X_APPLY_RECOVERY_BLOCKED; - break; - } - target_install_observation_result - = gcs_block_resource_x_target_install_classify_coherent( - buf, &target_install_follow, &failure_live, - &target_install_follow_state, &terminal_ref); - if (target_install_observation_result - != RESOURCE_X_APPLY_APPLIED) { - result = target_install_observation_result; - break; - } - if (target_install_follow_state - == RESOURCE_X_TARGET_INSTALL_RESAMPLE) - continue; - if (target_install_follow_state - == RESOURCE_X_TARGET_INSTALL_PREUSE_RETRY) { - target_install_preuse_retry_seen = true; - continue; - } - if (target_install_follow_state - == RESOURCE_X_TARGET_INSTALL_STALE - && target_install_preuse_retry_seen) { - memset(&target_install_follow, 0, - sizeof(target_install_follow)); - target_install_preuse_retry_seen = false; - continue; - } - if (target_install_follow_state - != RESOURCE_X_TARGET_INSTALL_TERMINAL) { - result = target_install_follow_state - == RESOURCE_X_TARGET_INSTALL_STALE - ? RESOURCE_X_APPLY_STALE - : target_install_follow_state - == RESOURCE_X_TARGET_INSTALL_RECOVERY_BLOCKED - ? RESOURCE_X_APPLY_RECOVERY_BLOCKED - : RESOURCE_X_APPLY_INVALID; - break; - } + if (action == RESOURCE_X_BOOTSTRAP_ROUND_TERMINAL) { + diagnostic_stage = "terminal-recheck"; + if (target_install_follow.valid) { + memset(&failure_live, 0, sizeof(failure_live)); + own_result = cluster_bufmgr_pcm_own_snapshot(buf, &failure_live); + if (own_result != CLUSTER_PCM_OWN_OK) { + result = own_result == CLUSTER_PCM_OWN_BUSY ? RESOURCE_X_APPLY_BAD_STATE + : own_result == CLUSTER_PCM_OWN_STALE + ? RESOURCE_X_APPLY_STALE + : RESOURCE_X_APPLY_RECOVERY_BLOCKED; + break; + } + target_install_observation_result + = gcs_block_resource_x_target_install_classify_coherent( + buf, &target_install_follow, &failure_live, + &target_install_follow_state, &terminal_ref); + if (target_install_observation_result != RESOURCE_X_APPLY_APPLIED) { + result = target_install_observation_result; + break; + } + if (target_install_follow_state == RESOURCE_X_TARGET_INSTALL_RESAMPLE) + continue; + if (target_install_follow_state == RESOURCE_X_TARGET_INSTALL_PREUSE_RETRY) { + target_install_preuse_retry_seen = true; + continue; + } + if (target_install_follow_state == RESOURCE_X_TARGET_INSTALL_STALE + && target_install_preuse_retry_seen) { + memset(&target_install_follow, 0, sizeof(target_install_follow)); + target_install_preuse_retry_seen = false; + continue; + } + if (target_install_follow_state != RESOURCE_X_TARGET_INSTALL_TERMINAL) { + result = target_install_follow_state == RESOURCE_X_TARGET_INSTALL_STALE + ? RESOURCE_X_APPLY_STALE + : target_install_follow_state + == RESOURCE_X_TARGET_INSTALL_RECOVERY_BLOCKED + ? RESOURCE_X_APPLY_RECOVERY_BLOCKED + : RESOURCE_X_APPLY_INVALID; + break; } - terminal_admission_current - = cluster_semantic_activation_recheck(&admission); + } + terminal_admission_current = cluster_semantic_activation_recheck(&admission); if (terminal_admission_current) { memset(&terminal_gate, 0, sizeof(terminal_gate)); terminal_master_node = -1; terminal_master_session = 0; - terminal_session_check - = gcs_block_resource_x_gate_session_snapshot_result( - &resource, &terminal_gate, - &terminal_master_node, - &terminal_master_session); + terminal_session_check = gcs_block_resource_x_gate_session_snapshot_result( + &resource, &terminal_gate, &terminal_master_node, + &terminal_master_session); terminal_gate_session_current = terminal_session_check == PCM_X_SESSION_AUTH_OK - && memcmp(&terminal_gate, &gate, - sizeof(terminal_gate)) == 0 + && memcmp(&terminal_gate, &gate, sizeof(terminal_gate)) == 0 && terminal_master_node == master_node && terminal_master_session == master_session; } @@ -15707,13 +14691,11 @@ gcs_block_resource_x_target_acquire_internal( gcs_block_resource_x_observation_pause(); continue; } - if (!terminal_admission_current - || !terminal_gate_session_current) { + if (!terminal_admission_current || !terminal_gate_session_current) { result = RESOURCE_X_APPLY_STALE; break; } - memset(&target_install_follow, 0, - sizeof(target_install_follow)); + memset(&target_install_follow, 0, sizeof(target_install_follow)); target_install_preuse_retry_seen = false; *ref_out = terminal_ref; /* All success paths, including coherent install-follow and @@ -15763,39 +14745,30 @@ gcs_block_resource_x_target_acquire_internal( bool round_drift_can_resample; memset(&failure_live, 0, sizeof(failure_live)); - own_result - = cluster_bufmgr_pcm_own_snapshot(buf, &failure_live); + own_result = cluster_bufmgr_pcm_own_snapshot(buf, &failure_live); memset(&failure_round, 0, sizeof(failure_round)); failure_snapshot_result = cluster_pcm_lock_resource_x_bootstrap_round_failure_snapshot_exact( - &assertion, master_node, gate.formation, - master_session, admission.record_generation, - requester_sender_connection_generation, - master_ingress_connection_generation, - retry_slice_us, &failure_round); + &assertion, master_node, gate.formation, master_session, + admission.record_generation, requester_sender_connection_generation, + master_ingress_connection_generation, retry_slice_us, &failure_round); requester_sender_recheck = 0; master_ingress_recheck = 0; - dispatch_admission_current - = cluster_semantic_activation_recheck(&admission); + dispatch_admission_current = cluster_semantic_activation_recheck(&admission); dispatch_gate_session_result = gcs_block_resource_x_gate_session_recheck_result( &resource, &gate, master_node, master_session); dispatch_gate_session_current = dispatch_gate_session_result == RESOURCE_X_APPLY_APPLIED; - dispatch_requester_sampled - = gcs_block_pcm_x_resource_x_peer_ready_exact( - master_node, &requester_sender_recheck); - dispatch_master_sampled - = gcs_block_pcm_x_resource_x_peer_ready_exact( - master_node, &master_ingress_recheck); + dispatch_requester_sampled = gcs_block_pcm_x_resource_x_peer_ready_exact( + master_node, &requester_sender_recheck); + dispatch_master_sampled = gcs_block_pcm_x_resource_x_peer_ready_exact( + master_node, &master_ingress_recheck); dispatch_recheck_failure_mask = cluster_gcs_resource_x_dispatch_recheck_failure_mask( - dispatch_admission_current, - dispatch_gate_session_current, - dispatch_requester_sampled, - dispatch_master_sampled, + dispatch_admission_current, dispatch_gate_session_current, + dispatch_requester_sampled, dispatch_master_sampled, requester_sender_connection_generation, - master_ingress_connection_generation, - requester_sender_recheck, + master_ingress_connection_generation, requester_sender_recheck, master_ingress_recheck); round_drift_peer_result = gcs_block_resource_x_target_peer_result_exact( &admission, master_node, master_ingress_connection_generation); @@ -15824,8 +14797,8 @@ gcs_block_resource_x_target_acquire_internal( && failure_live.pcm_state == (uint8)PCM_STATE_N) { round_drift_retained_pair_exact = cluster_pcm_lock_resource_x_holder_pair_retained_fence_exact( - &assertion.resource, master_node, master_session, - gate.formation, failure_live.generation); + &assertion.resource, master_node, master_session, gate.formation, + failure_live.generation); round_drift_retained_buffer_exact = round_drift_retained_pair_exact && cluster_bufmgr_pcm_own_n_retained_release_inflight_exact( @@ -15850,8 +14823,7 @@ gcs_block_resource_x_target_acquire_internal( result = RESOURCE_X_APPLY_STALE; break; } - if (action - == RESOURCE_X_BOOTSTRAP_ROUND_PREDECESSOR_WAIT) { + if (action == RESOURCE_X_BOOTSTRAP_ROUND_PREDECESSOR_WAIT) { /* The exact predecessor pair is older than this local request. * Keep the requester round empty. Register against the existing * settlement predicate on the same entry CV under this caller's @@ -15896,27 +14868,21 @@ gcs_block_resource_x_target_acquire_internal( diagnostic_stage = "dispatch-recheck"; requester_sender_recheck = 0; master_ingress_recheck = 0; - dispatch_admission_current - = cluster_semantic_activation_recheck(&admission); + dispatch_admission_current = cluster_semantic_activation_recheck(&admission); dispatch_gate_session_result = gcs_block_resource_x_gate_session_recheck_result( &resource, &gate, master_node, master_session); dispatch_gate_session_current = dispatch_gate_session_result == RESOURCE_X_APPLY_APPLIED; - dispatch_requester_sampled - = gcs_block_pcm_x_resource_x_peer_ready_exact( - master_node, &requester_sender_recheck); - dispatch_master_sampled - = gcs_block_pcm_x_resource_x_peer_ready_exact( - master_node, &master_ingress_recheck); + dispatch_requester_sampled = gcs_block_pcm_x_resource_x_peer_ready_exact( + master_node, &requester_sender_recheck); + dispatch_master_sampled = gcs_block_pcm_x_resource_x_peer_ready_exact( + master_node, &master_ingress_recheck); dispatch_recheck_failure_mask = cluster_gcs_resource_x_dispatch_recheck_failure_mask( - dispatch_admission_current, - dispatch_gate_session_current, - dispatch_requester_sampled, - dispatch_master_sampled, + dispatch_admission_current, dispatch_gate_session_current, + dispatch_requester_sampled, dispatch_master_sampled, requester_sender_connection_generation, - master_ingress_connection_generation, - requester_sender_recheck, + master_ingress_connection_generation, requester_sender_recheck, master_ingress_recheck); /* A missing observation is not pre-ASSERT authority drift. * Keep the exact round for REQUEST, ASSERT and followers; @@ -15936,8 +14902,7 @@ gcs_block_resource_x_target_acquire_internal( gcs_block_resource_x_observation_pause(); continue; } - if (dispatch_recheck_failure_mask - != RESOURCE_X_DISPATCH_RECHECK_OK) { + if (dispatch_recheck_failure_mask != RESOURCE_X_DISPATCH_RECHECK_OK) { /* D1 AUTHORITY_DRIFT: a pre-ACK/pre-ASSERT kind-9 round * is not authority even if its request reached a master * RECEIVED receipt. A transient session observation keeps @@ -15948,9 +14913,8 @@ gcs_block_resource_x_target_acquire_internal( * authority under that same deadline. The higher attempt * replaces any unconsumed old receipt; no proof or image is * reused. */ - if (action - == RESOURCE_X_BOOTSTRAP_ROUND_DISPATCH_REQUEST - && !join_only && dispatch_admission_current) { + if (action == RESOURCE_X_BOOTSTRAP_ROUND_DISPATCH_REQUEST && !join_only + && dispatch_admission_current) { memset(&rebound_gate, 0, sizeof(rebound_gate)); rebound_master_node = -1; rebound_master_session = 0; @@ -15961,24 +14925,19 @@ gcs_block_resource_x_target_acquire_internal( rebound_peer_matches = false; dispatch_session_check = gcs_block_resource_x_gate_session_snapshot_result( - &resource, &rebound_gate, - &rebound_master_node, + &resource, &rebound_gate, &rebound_master_node, &rebound_master_session); - if (cluster_gcs_pcm_x_auth_result_retryable( - dispatch_session_check)) + if (cluster_gcs_pcm_x_auth_result_retryable(dispatch_session_check)) goto dispatch_recheck_wait; - if (dispatch_session_check - == PCM_X_SESSION_AUTH_OK) { + if (dispatch_session_check == PCM_X_SESSION_AUTH_OK) { rebound_requester_sampled = gcs_block_pcm_x_resource_x_peer_ready_exact( rebound_master_node, &rebound_requester_connection_generation); rebound_master_sampled = gcs_block_pcm_x_resource_x_peer_ready_exact( - rebound_master_node, - &rebound_master_connection_generation); - if (!rebound_requester_sampled - || !rebound_master_sampled) + rebound_master_node, &rebound_master_connection_generation); + if (!rebound_requester_sampled || !rebound_master_sampled) goto dispatch_recheck_wait; if (rebound_master_node == cluster_node_id) rebound_peer_matches @@ -15996,30 +14955,25 @@ gcs_block_resource_x_target_acquire_internal( } if (!rebound_peer_matches) goto dispatch_recheck_wait; - if (!cluster_semantic_activation_recheck( - &admission)) { + if (!cluster_semantic_activation_recheck(&admission)) { result = RESOURCE_X_APPLY_STALE; break; } - if (memcmp(&rebound_gate, &gate, - sizeof(rebound_gate)) == 0 + if (memcmp(&rebound_gate, &gate, sizeof(rebound_gate)) == 0 && rebound_master_node == master_node && rebound_master_session == master_session && rebound_requester_connection_generation - == requester_sender_connection_generation + == requester_sender_connection_generation && rebound_master_connection_generation - == master_ingress_connection_generation) + == master_ingress_connection_generation) continue; discard_result = cluster_pcm_lock_resource_x_bootstrap_round_discard_pre_assert_authority_drift_exact( - &dispatch, master_node, - admission.record_generation, - master_ingress_connection_generation, - retry_slice_us, absolute_deadline_us, - direct_init_ownership_generation, + &dispatch, master_node, admission.record_generation, + master_ingress_connection_generation, retry_slice_us, + absolute_deadline_us, direct_init_ownership_generation, direct_init_reservation_token); - if (discard_result - != RESOURCE_X_APPLY_APPLIED) { + if (discard_result != RESOURCE_X_APPLY_APPLIED) { result = discard_result; break; } @@ -16041,19 +14995,19 @@ gcs_block_resource_x_target_acquire_internal( result = RESOURCE_X_APPLY_STALE; break; - dispatch_recheck_wait: - gcs_block_resource_x_requester_wait_note(&wait_diagnostic, - PCM_RX_WAIT_DISPATCH); - now_us = gcs_block_pcm_x_monotonic_us(); - remaining_us = retry_slice_us; - timeout_ms = (long)Min( - (uint64)Max(cluster_gcs_block_retransmit_initial_backoff_ms, 1), - (remaining_us + UINT64_C(999)) / UINT64_C(1000)); - if (timeout_ms <= 0) - timeout_ms = 1; - CHECK_FOR_INTERRUPTS(); - pg_usleep(timeout_ms * 1000L); - continue; + dispatch_recheck_wait: + gcs_block_resource_x_requester_wait_note(&wait_diagnostic, + PCM_RX_WAIT_DISPATCH); + now_us = gcs_block_pcm_x_monotonic_us(); + remaining_us = retry_slice_us; + timeout_ms = (long)Min( + (uint64)Max(cluster_gcs_block_retransmit_initial_backoff_ms, 1), + (remaining_us + UINT64_C(999)) / UINT64_C(1000)); + if (timeout_ms <= 0) + timeout_ms = 1; + CHECK_FOR_INTERRUPTS(); + pg_usleep(timeout_ms * 1000L); + continue; } result = RESOURCE_X_APPLY_STALE; break; @@ -16063,14 +15017,12 @@ gcs_block_resource_x_target_acquire_internal( || action == RESOURCE_X_BOOTSTRAP_ROUND_DISPATCH_ASSERT); if (action == RESOURCE_X_BOOTSTRAP_ROUND_DISPATCH_REQUEST) { diagnostic_stage = "dispatch-bootstrap-request"; - stage_ok - = gcs_block_resource_x_bootstrap_request_stage_exact( - master_node, &dispatch); + stage_ok = gcs_block_resource_x_bootstrap_request_stage_exact(master_node, + &dispatch); } else { diagnostic_stage = "dispatch-assert"; stage_ok - = gcs_block_resource_x_native_assert_stage_exact( - master_node, &dispatch) + = gcs_block_resource_x_native_assert_stage_exact(master_node, &dispatch) == RESOURCE_X_APPLY_APPLIED; } (void)stage_ok; @@ -16086,102 +15038,102 @@ gcs_block_resource_x_target_acquire_internal( * WAIT only enrolls/rechecks; it cannot revoke its own install. */ now_us = gcs_block_pcm_x_monotonic_us(); remaining_us = retry_slice_us; - timeout_ms = (long)Min( - (uint64)Max( - cluster_gcs_block_retransmit_initial_backoff_ms, 1), - (remaining_us + UINT64_C(999)) / UINT64_C(1000)); + timeout_ms + = (long)Min((uint64)Max(cluster_gcs_block_retransmit_initial_backoff_ms, 1), + (remaining_us + UINT64_C(999)) / UINT64_C(1000)); if (timeout_ms <= 0) timeout_ms = 1; diagnostic_stage = "round-wait"; - if (direct_init) - wait_result - = cluster_pcm_lock_resource_x_bootstrap_round_wait_direct_init_exact( - &assertion, master_node, gate.formation, master_session, - admission.record_generation, requester_sender_connection_generation, - master_ingress_connection_generation, retry_slice_us, - direct_init_ownership_generation, direct_init_reservation_token, - absolute_deadline_us, timeout_ms); - else - wait_result = cluster_pcm_lock_resource_x_bootstrap_round_wait_caller_exact( + if (direct_init) + wait_result + = cluster_pcm_lock_resource_x_bootstrap_round_wait_direct_init_exact( &assertion, master_node, gate.formation, master_session, admission.record_generation, requester_sender_connection_generation, master_ingress_connection_generation, retry_slice_us, - absolute_deadline_us, timeout_ms, caller_witness); - diagnostic_wait_failure = cluster_pcm_rx_take_wait_failure(); - if (wait_result == RESOURCE_X_APPLY_DUPLICATE - && caller_witness->reobserve_attempt != 0) - gcs_block_resource_x_requester_wait_note(&wait_diagnostic, - caller_witness->reobserve_reason); - diagnostic_deadline_expired - = diagnostic_wait_failure == PCM_RX_WAIT_CALLER_DEADLINE_EXPIRED; - diagnostic_head_expired - = diagnostic_wait_failure == PCM_RX_WAIT_HEAD_NO_PROGRESS_EXPIRED; - if (wait_result != RESOURCE_X_APPLY_APPLIED - && wait_result != RESOURCE_X_APPLY_DUPLICATE) { - /* The registered wait and BufferDesc use independent lock + direct_init_ownership_generation, direct_init_reservation_token, + absolute_deadline_us, timeout_ms); + else + wait_result = cluster_pcm_lock_resource_x_bootstrap_round_wait_caller_exact( + &assertion, master_node, gate.formation, master_session, + admission.record_generation, requester_sender_connection_generation, + master_ingress_connection_generation, retry_slice_us, absolute_deadline_us, + timeout_ms, caller_witness); + diagnostic_wait_failure = cluster_pcm_rx_take_wait_failure(); + if (wait_result == RESOURCE_X_APPLY_DUPLICATE + && caller_witness->reobserve_attempt != 0) + gcs_block_resource_x_requester_wait_note(&wait_diagnostic, + caller_witness->reobserve_reason); + diagnostic_deadline_expired + = diagnostic_wait_failure == PCM_RX_WAIT_CALLER_DEADLINE_EXPIRED; + diagnostic_head_expired + = diagnostic_wait_failure == PCM_RX_WAIT_HEAD_NO_PROGRESS_EXPIRED; + if (wait_result != RESOURCE_X_APPLY_APPLIED + && wait_result != RESOURCE_X_APPLY_DUPLICATE) { + /* The registered wait and BufferDesc use independent lock * domains. A same-node T1 executor can publish terminal X * between the wait predicate and this return, making the old * wait identity STALE even though the exact requested install * completed. Admit no generic STALE retry: independently * resample both domains and require the frozen pending(T) -> * terminal-X(T+1) proof before restarting the full driver. */ - if (!direct_init && !join_only && wait_result == RESOURCE_X_APPLY_STALE - && own.pcm_state == (uint8)PCM_STATE_N - && own.flags == PCM_OWN_FLAG_GRANT_PENDING) { - diagnostic_stage = "wait-terminal-resample"; - memset(&failure_live, 0, sizeof(failure_live)); - own_result = cluster_bufmgr_pcm_own_snapshot(buf, &failure_live); - memset(&failure_round, 0, sizeof(failure_round)); - failure_snapshot_result - = cluster_pcm_lock_resource_x_bootstrap_round_failure_snapshot_exact( - &assertion, master_node, gate.formation, master_session, - admission.record_generation, - requester_sender_connection_generation, - master_ingress_connection_generation, retry_slice_us, - &failure_round); - pending_terminal_resample_mismatch - = own_result == CLUSTER_PCM_OWN_OK - ? cluster_gcs_resource_x_pending_terminal_resample_mismatch( - &own, &failure_live, failure_snapshot_result, - &failure_round) - : RESOURCE_X_PENDING_TERMINAL_MISMATCH_INPUT; - ereport(LOG, + if (!direct_init && !join_only && wait_result == RESOURCE_X_APPLY_STALE + && own.pcm_state == (uint8)PCM_STATE_N + && own.flags == PCM_OWN_FLAG_GRANT_PENDING) { + diagnostic_stage = "wait-terminal-resample"; + memset(&failure_live, 0, sizeof(failure_live)); + own_result = cluster_bufmgr_pcm_own_snapshot(buf, &failure_live); + memset(&failure_round, 0, sizeof(failure_round)); + failure_snapshot_result + = cluster_pcm_lock_resource_x_bootstrap_round_failure_snapshot_exact( + &assertion, master_node, gate.formation, master_session, + admission.record_generation, requester_sender_connection_generation, + master_ingress_connection_generation, retry_slice_us, + &failure_round); + pending_terminal_resample_mismatch + = own_result == CLUSTER_PCM_OWN_OK + ? cluster_gcs_resource_x_pending_terminal_resample_mismatch( + &own, &failure_live, failure_snapshot_result, + &failure_round) + : RESOURCE_X_PENDING_TERMINAL_MISMATCH_INPUT; + ereport( + LOG, (errmsg_internal("Resource-X pending terminal resample diagnostic"), - errdetail("mismatch=0x%016llx live_result=%d round_result=%d " - "before_state=%u before_flags=0x%x before_generation=%llu " - "before_token=%llu before_writer=%llu before_resource_x=%llu " - "live_state=%u live_flags=0x%x live_generation=%llu " - "live_token=%llu live_writer=%llu live_resource_x=%llu " - "round_terminal=%u round_phase=%u round_buffer_generation=%llu " - "round_requester=%d round_formation=%llu round_acquisition=%llu " - "round_base_authority=%llu round_authority=%llu round_r4=%llu " - "round_session=%llu round_deadline=%llu round_retired=%llu " - "round_progress=0x%x", - (unsigned long long) pending_terminal_resample_mismatch, - (int) own_result, (int) failure_snapshot_result, - (unsigned) own.pcm_state, own.flags, - (unsigned long long) own.generation, - (unsigned long long) own.reservation_token, - (unsigned long long) own.writer_activation_token, - (unsigned long long) own.resource_x_activation_generation, - (unsigned) failure_live.pcm_state, failure_live.flags, - (unsigned long long) failure_live.generation, - (unsigned long long) failure_live.reservation_token, - (unsigned long long) failure_live.writer_activation_token, - (unsigned long long) failure_live.resource_x_activation_generation, - (unsigned) failure_round.terminal, - (unsigned) failure_round.round_phase, - (unsigned long long) failure_round.buffer_ownership_generation, - failure_round.ref.assertion.requester_node, - (unsigned long long) failure_round.ref.formation, - (unsigned long long) failure_round.ref.acquisition_generation, - (unsigned long long) failure_round.base_authority_generation, - (unsigned long long) failure_round.authority_generation, - (unsigned long long) failure_round.r4_record_generation, - (unsigned long long) failure_round.master_session_incarnation, - (unsigned long long) failure_round.absolute_deadline_us, - (unsigned long long) failure_round.retired_acquisition_generation, - failure_round.progress_flags))); + errdetail( + "mismatch=0x%016llx live_result=%d round_result=%d " + "before_state=%u before_flags=0x%x before_generation=%llu " + "before_token=%llu before_writer=%llu before_resource_x=%llu " + "live_state=%u live_flags=0x%x live_generation=%llu " + "live_token=%llu live_writer=%llu live_resource_x=%llu " + "round_terminal=%u round_phase=%u round_buffer_generation=%llu " + "round_requester=%d round_formation=%llu round_acquisition=%llu " + "round_base_authority=%llu round_authority=%llu round_r4=%llu " + "round_session=%llu round_deadline=%llu round_retired=%llu " + "round_progress=0x%x", + (unsigned long long)pending_terminal_resample_mismatch, + (int)own_result, (int)failure_snapshot_result, + (unsigned)own.pcm_state, own.flags, + (unsigned long long)own.generation, + (unsigned long long)own.reservation_token, + (unsigned long long)own.writer_activation_token, + (unsigned long long)own.resource_x_activation_generation, + (unsigned)failure_live.pcm_state, failure_live.flags, + (unsigned long long)failure_live.generation, + (unsigned long long)failure_live.reservation_token, + (unsigned long long)failure_live.writer_activation_token, + (unsigned long long)failure_live.resource_x_activation_generation, + (unsigned)failure_round.terminal, + (unsigned)failure_round.round_phase, + (unsigned long long)failure_round.buffer_ownership_generation, + failure_round.ref.assertion.requester_node, + (unsigned long long)failure_round.ref.formation, + (unsigned long long)failure_round.ref.acquisition_generation, + (unsigned long long)failure_round.base_authority_generation, + (unsigned long long)failure_round.authority_generation, + (unsigned long long)failure_round.r4_record_generation, + (unsigned long long)failure_round.master_session_incarnation, + (unsigned long long)failure_round.absolute_deadline_us, + (unsigned long long)failure_round.retired_acquisition_generation, + failure_round.progress_flags))); } result = wait_result; break; @@ -16248,10 +15200,8 @@ gcs_block_resource_x_target_acquire_internal( failure_snapshot_result = cluster_pcm_lock_resource_x_bootstrap_round_failure_snapshot_exact( &assertion, master_node, gate.formation, master_session, - admission_record_generation, - requester_sender_connection_generation, - master_ingress_connection_generation, retry_slice_us, - &failure_round); + admission_record_generation, requester_sender_connection_generation, + master_ingress_connection_generation, retry_slice_us, &failure_round); memset(&failure_live, 0, sizeof(failure_live)); own_result = cluster_bufmgr_pcm_own_snapshot(buf, &failure_live); memset(&first_failure, 0, sizeof(first_failure)); @@ -16264,39 +15214,31 @@ gcs_block_resource_x_target_acquire_internal( = own_result == CLUSTER_PCM_OWN_OK ? failure_live.generation : 0; first_failure.buffer_token_before = own.reservation_token; first_failure.buffer_token_after - = own_result == CLUSTER_PCM_OWN_OK - ? failure_live.reservation_token : 0; - first_failure.buffer_writer_token_before - = own.writer_activation_token; + = own_result == CLUSTER_PCM_OWN_OK ? failure_live.reservation_token : 0; + first_failure.buffer_writer_token_before = own.writer_activation_token; first_failure.buffer_writer_token_after - = own_result == CLUSTER_PCM_OWN_OK - ? failure_live.writer_activation_token : 0; - first_failure.buffer_resource_x_generation_before - = own.resource_x_activation_generation; + = own_result == CLUSTER_PCM_OWN_OK ? failure_live.writer_activation_token : 0; + first_failure.buffer_resource_x_generation_before = own.resource_x_activation_generation; first_failure.buffer_resource_x_generation_after - = own_result == CLUSTER_PCM_OWN_OK - ? failure_live.resource_x_activation_generation : 0; + = own_result == CLUSTER_PCM_OWN_OK ? failure_live.resource_x_activation_generation : 0; first_failure.formation = gate.formation; first_failure.master_session = master_session; first_failure.r4_generation = admission_record_generation; first_failure.absolute_deadline_us = absolute_deadline_us; first_failure.remote_s_stage = RESOURCE_X_REMOTE_S_STAGE_NONE; - first_failure.failure_domain = preflight_backpressure - ? RESOURCE_X_FAIL_PRE_MUTATION_BACKPRESSURE - : gcs_block_resource_x_target_failure_domain( - result, failure_snapshot_result, &failure_round, own_result); + first_failure.failure_domain + = preflight_backpressure + ? RESOURCE_X_FAIL_PRE_MUTATION_BACKPRESSURE + : gcs_block_resource_x_target_failure_domain(result, failure_snapshot_result, + &failure_round, own_result); first_failure.result = result; if (failure_snapshot_result == RESOURCE_X_APPLY_APPLIED) { - first_failure.base_authority_generation - = failure_round.base_authority_generation; - first_failure.authority_generation - = failure_round.authority_generation; - first_failure.assertion_sequence - = failure_round.ref.acquisition_generation; + first_failure.base_authority_generation = failure_round.base_authority_generation; + first_failure.authority_generation = failure_round.authority_generation; + first_failure.assertion_sequence = failure_round.ref.acquisition_generation; first_failure.round_terminal = failure_round.terminal != 0; first_failure.round_phase = failure_round.round_phase; - first_failure.round_progress_flags - = failure_round.progress_flags; + first_failure.round_progress_flags = failure_round.progress_flags; } gcs_block_resource_x_first_failure_record(&first_failure); first_failure_recorded = true; @@ -16403,10 +15345,11 @@ gcs_block_resource_x_target_eviction_recheck_result(const BufferTag *tag, * exact X+REVOKING residency. Entry-local EVICTING is lifecycle ownership, * never authority; every failure before local commit drops it exactly. */ ResourceXApplyResult -cluster_gcs_resource_x_target_evict_prepare_exact( - const BufferTag *tag, const ClusterPcmOwnSnapshot *exact_x, - uint64 r4_record_generation, uint64 reservation_token, - ResourceXTargetEvictionPlan *plan_out) +cluster_gcs_resource_x_target_evict_prepare_exact(const BufferTag *tag, + const ClusterPcmOwnSnapshot *exact_x, + uint64 r4_record_generation, + uint64 reservation_token, + ResourceXTargetEvictionPlan *plan_out) { ClusterSemanticAdmissionToken admission; ClusterSemanticAdmissionResult admission_result; @@ -16428,26 +15371,21 @@ cluster_gcs_resource_x_target_evict_prepare_exact( if (plan_out != NULL) memset(plan_out, 0, sizeof(*plan_out)); - if (tag == NULL || exact_x == NULL || plan_out == NULL - || !BufferTagsEqual(tag, &exact_x->tag) - || exact_x->pcm_state != (uint8)PCM_STATE_X - || exact_x->flags != PCM_OWN_FLAG_REVOKING - || exact_x->generation == 0 || exact_x->generation == UINT64_MAX - || reservation_token == 0 || reservation_token == UINT64_MAX - || exact_x->reservation_token != reservation_token - || exact_x->writer_activation_token != 0 - || exact_x->resource_x_activation_generation != 0 - || r4_record_generation == 0 - || r4_record_generation == UINT64_MAX || MyProc == NULL) + if (tag == NULL || exact_x == NULL || plan_out == NULL || !BufferTagsEqual(tag, &exact_x->tag) + || exact_x->pcm_state != (uint8)PCM_STATE_X || exact_x->flags != PCM_OWN_FLAG_REVOKING + || exact_x->generation == 0 || exact_x->generation == UINT64_MAX || reservation_token == 0 + || reservation_token == UINT64_MAX || exact_x->reservation_token != reservation_token + || exact_x->writer_activation_token != 0 || exact_x->resource_x_activation_generation != 0 + || r4_record_generation == 0 || r4_record_generation == UINT64_MAX || MyProc == NULL) return RESOURCE_X_APPLY_INVALID; memset(&admission, 0, sizeof(admission)); memset(&gate, 0, sizeof(gate)); memset(&release, 0, sizeof(release)); memset(&owner, 0, sizeof(owner)); memset((void *)&cleanup_owner, 0, sizeof(cleanup_owner)); - admission_result = cluster_semantic_activation_enter( - CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1, - CLUSTER_SEMANTIC_TARGET_SIDE, &admission); + admission_result + = cluster_semantic_activation_enter(CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1, + CLUSTER_SEMANTIC_TARGET_SIDE, &admission); if (admission_result != CLUSTER_SEMANTIC_ADMISSION_OK) return RESOURCE_X_APPLY_BAD_STATE; if (admission.record_generation != r4_record_generation) { @@ -16472,21 +15410,17 @@ cluster_gcs_resource_x_target_evict_prepare_exact( result = gcs_block_resource_x_target_peer_result_exact(&admission, master_node, sender_connection_generation); if (result == RESOURCE_X_APPLY_APPLIED) - result - = cluster_pcm_lock_resource_x_target_evict_prepare_exact( - tag, master_node, gate.formation, master_session, - r4_record_generation, exact_x->generation, - reservation_token, sender_connection_generation, - (int32)MyProc->pgprocno, &release, &owner); - if (result == RESOURCE_X_APPLY_APPLIED - || result == RESOURCE_X_APPLY_DUPLICATE) { + result = cluster_pcm_lock_resource_x_target_evict_prepare_exact( + tag, master_node, gate.formation, master_session, r4_record_generation, + exact_x->generation, reservation_token, sender_connection_generation, + (int32)MyProc->pgprocno, &release, &owner); + if (result == RESOURCE_X_APPLY_APPLIED || result == RESOURCE_X_APPLY_DUPLICATE) { memcpy((void *)&cleanup_owner, &owner, sizeof(owner)); owner_claimed = true; } if (owner_claimed - && (!cluster_resource_x_wire_encode( - RESOURCE_X_MSG_SETTLEMENT_OR_RELEASE, &release, - payload, sizeof(payload), &payload_bytes, &reject) + && (!cluster_resource_x_wire_encode(RESOURCE_X_MSG_SETTLEMENT_OR_RELEASE, &release, + payload, sizeof(payload), &payload_bytes, &reject) || payload_bytes != RESOURCE_X_CONTROL_V1_BYTES || release.kind != RESOURCE_X_WIRE_RELEASE_X)) result = RESOURCE_X_APPLY_INVALID; @@ -16496,25 +15430,20 @@ cluster_gcs_resource_x_target_evict_prepare_exact( if (recheck_result != RESOURCE_X_APPLY_APPLIED) result = recheck_result; } - if (result == RESOURCE_X_APPLY_APPLIED - || result == RESOURCE_X_APPLY_DUPLICATE) { + if (result == RESOURCE_X_APPLY_APPLIED || result == RESOURCE_X_APPLY_DUPLICATE) { plan_out->release = release; plan_out->owner = owner; plan_out->gate = gate; plan_out->tag = *tag; plan_out->cached_ownership_generation = exact_x->generation; plan_out->r4_record_generation = r4_record_generation; - plan_out->sender_connection_generation - = sender_connection_generation; + plan_out->sender_connection_generation = sender_connection_generation; plan_out->master_node = master_node; plan_out->payload_bytes = payload_bytes; memcpy(plan_out->release_payload, payload, payload_bytes); plan_out->prepared = true; - } - else if (owner_claimed) { - abort_result - = cluster_pcm_lock_resource_x_target_evict_abort_exact( - &owner); + } else if (owner_claimed) { + abort_result = cluster_pcm_lock_resource_x_target_evict_abort_exact(&owner); if (abort_result != RESOURCE_X_APPLY_APPLIED) result = RESOURCE_X_APPLY_RECOVERY_BLOCKED; } @@ -16524,11 +15453,8 @@ cluster_gcs_resource_x_target_evict_prepare_exact( if (owner_claimed) { ResourceXLocalOwnerHandle catch_owner; - memcpy(&catch_owner, (const void *)&cleanup_owner, - sizeof(catch_owner)); - abort_result - = cluster_pcm_lock_resource_x_target_evict_abort_exact( - &catch_owner); + memcpy(&catch_owner, (const void *)&cleanup_owner, sizeof(catch_owner)); + abort_result = cluster_pcm_lock_resource_x_target_evict_abort_exact(&catch_owner); if (abort_result != RESOURCE_X_APPLY_APPLIED) gcs_block_resource_x_fail_closed_current(); } @@ -16569,9 +15495,9 @@ cluster_gcs_resource_x_target_evict_publish_exact(ResourceXTargetEvictionPlan *p master_session = plan->release.common.master_session_incarnation; memset(&admission, 0, sizeof(admission)); memset(&master_snapshot, 0, sizeof(master_snapshot)); - admission_result = cluster_semantic_activation_enter( - CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1, - CLUSTER_SEMANTIC_TARGET_SIDE, &admission); + admission_result + = cluster_semantic_activation_enter(CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1, + CLUSTER_SEMANTIC_TARGET_SIDE, &admission); if (admission_result != CLUSTER_SEMANTIC_ADMISSION_OK) return RESOURCE_X_APPLY_BAD_STATE; if (admission.record_generation != plan->r4_record_generation) { @@ -16592,16 +15518,14 @@ cluster_gcs_resource_x_target_evict_publish_exact(ResourceXTargetEvictionPlan *p &plan->release, cluster_node_id, &master_snapshot); else { result = cluster_grd_outbound_enqueue_backend_msg( - RESOURCE_X_MSG_SETTLEMENT_OR_RELEASE, - (uint32)plan->master_node, plan->release_payload, - plan->payload_bytes) - ? RESOURCE_X_APPLY_APPLIED - : RESOURCE_X_APPLY_BAD_STATE; + RESOURCE_X_MSG_SETTLEMENT_OR_RELEASE, (uint32)plan->master_node, + plan->release_payload, plan->payload_bytes) + ? RESOURCE_X_APPLY_APPLIED + : RESOURCE_X_APPLY_BAD_STATE; if (result == RESOURCE_X_APPLY_BAD_STATE) *retry_pending_out = true; } - if (result == RESOURCE_X_APPLY_APPLIED - || result == RESOURCE_X_APPLY_DUPLICATE) + if (result == RESOURCE_X_APPLY_APPLIED || result == RESOURCE_X_APPLY_DUPLICATE) plan->release_admitted = true; } else if (result == RESOURCE_X_APPLY_APPLIED) result = RESOURCE_X_APPLY_DUPLICATE; @@ -16615,15 +15539,12 @@ cluster_gcs_resource_x_target_evict_publish_exact(ResourceXTargetEvictionPlan *p if (recheck_result == RESOURCE_X_APPLY_BAD_STATE) *retry_pending_out = true; } - if ((result == RESOURCE_X_APPLY_APPLIED - || result == RESOURCE_X_APPLY_DUPLICATE) + if ((result == RESOURCE_X_APPLY_APPLIED || result == RESOURCE_X_APPLY_DUPLICATE) && plan->release_admitted) { result = cluster_pcm_lock_resource_x_target_evict_commit_exact( - &plan->release, plan->master_node, - plan->r4_record_generation, + &plan->release, plan->master_node, plan->r4_record_generation, plan->cached_ownership_generation, &plan->owner); - if (result == RESOURCE_X_APPLY_APPLIED - || result == RESOURCE_X_APPLY_DUPLICATE) + if (result == RESOURCE_X_APPLY_APPLIED || result == RESOURCE_X_APPLY_DUPLICATE) plan->prepared = false; } } @@ -16640,8 +15561,7 @@ cluster_gcs_resource_x_target_evict_publish_exact(ResourceXTargetEvictionPlan *p /* PREPARE is reversible only until BufferDesc has committed X->N and before * transport/apply owns the frozen release. */ ResourceXApplyResult -cluster_gcs_resource_x_target_evict_abort_exact( - ResourceXTargetEvictionPlan *plan) +cluster_gcs_resource_x_target_evict_abort_exact(ResourceXTargetEvictionPlan *plan) { ResourceXApplyResult result; @@ -16649,8 +15569,7 @@ cluster_gcs_resource_x_target_evict_abort_exact( return RESOURCE_X_APPLY_INVALID; if (plan->local_n_committed || plan->release_admitted) return RESOURCE_X_APPLY_BAD_STATE; - result = cluster_pcm_lock_resource_x_target_evict_abort_exact( - &plan->owner); + result = cluster_pcm_lock_resource_x_target_evict_abort_exact(&plan->owner); if (result == RESOURCE_X_APPLY_APPLIED) { plan->prepared = false; memset(&plan->owner, 0, sizeof(plan->owner)); @@ -16659,19 +15578,19 @@ cluster_gcs_resource_x_target_evict_abort_exact( } ResourceXApplyResult -cluster_gcs_resource_x_target_acquire_exact( - BufferDesc *buf, uint64 r4_record_generation, - ResourceXAcquisitionRef *ref_out) +cluster_gcs_resource_x_target_acquire_exact(BufferDesc *buf, uint64 r4_record_generation, + ResourceXAcquisitionRef *ref_out) { return gcs_block_resource_x_target_acquire_internal(buf, NULL, r4_record_generation, 0, 0, false, NULL, NULL, NULL, ref_out); } ResourceXApplyResult -cluster_gcs_resource_x_target_acquire_until_exact( - BufferDesc *buf, const BufferTag *expected_resource, - uint64 r4_record_generation, - uint64 *absolute_deadline_us_io, ResourceXAcquisitionRef *ref_out) +cluster_gcs_resource_x_target_acquire_until_exact(BufferDesc *buf, + const BufferTag *expected_resource, + uint64 r4_record_generation, + uint64 *absolute_deadline_us_io, + ResourceXAcquisitionRef *ref_out) { if (expected_resource == NULL || absolute_deadline_us_io == NULL) return RESOURCE_X_APPLY_INVALID; @@ -16729,11 +15648,11 @@ cluster_gcs_resource_x_target_direct_init_acquire_exact( } ResourceXApplyResult -cluster_gcs_resource_x_target_direct_init_join_exact( - BufferDesc *buf, const BufferTag *expected_resource, - uint64 direct_init_ownership_generation, - uint64 direct_init_reservation_token, - ResourceXAcquisitionRef *ref_out) +cluster_gcs_resource_x_target_direct_init_join_exact(BufferDesc *buf, + const BufferTag *expected_resource, + uint64 direct_init_ownership_generation, + uint64 direct_init_reservation_token, + ResourceXAcquisitionRef *ref_out) { if (expected_resource == NULL || direct_init_reservation_token == 0) return RESOURCE_X_APPLY_INVALID; @@ -16752,13 +15671,10 @@ cluster_gcs_resource_x_target_context_recheck_result_exact(const ResourceXWriter uint64 writer_generation = 0; int32 master_node = -1; - if (context == NULL - || context->r4_record_generation == 0 - || context->r4_record_generation == UINT64_MAX - || context->buffer_ownership_generation == 0 + if (context == NULL || context->r4_record_generation == 0 + || context->r4_record_generation == UINT64_MAX || context->buffer_ownership_generation == 0 || context->buffer_ownership_generation == UINT64_MAX - || context->writer_activation_token != 0 - || context->resource_x_activation_generation != 0) + || context->writer_activation_token != 0 || context->resource_x_activation_generation != 0) return RESOURCE_X_APPLY_INVALID; writer_path = cluster_resource_x_writer_path_snapshot(&writer_generation); if (writer_path != RESOURCE_X_WRITER_TARGET @@ -16800,19 +15716,14 @@ gcs_block_resource_x_target_recycle_inputs_result_exact(const ResourceXWriterUse uint64 writer_generation = 0; if (context == NULL || observed == NULL - || !BufferTagsEqual( - &context->ref.assertion.resource, &observed->tag) - || context->buffer_ownership_generation - != observed->generation - || observed->reservation_token == 0 - || observed->reservation_token == UINT64_MAX - || observed->pcm_state != (uint8)PCM_STATE_X - || observed->flags != 0 + || !BufferTagsEqual(&context->ref.assertion.resource, &observed->tag) + || context->buffer_ownership_generation != observed->generation + || observed->reservation_token == 0 || observed->reservation_token == UINT64_MAX + || observed->pcm_state != (uint8)PCM_STATE_X || observed->flags != 0 || observed->writer_activation_token != 0 || observed->resource_x_activation_generation != 0) return RESOURCE_X_APPLY_STALE; - writer_path = cluster_resource_x_writer_path_snapshot( - &writer_generation); + writer_path = cluster_resource_x_writer_path_snapshot(&writer_generation); if (writer_path != RESOURCE_X_WRITER_TARGET || writer_generation != context->r4_record_generation) return RESOURCE_X_APPLY_STALE; @@ -16827,10 +15738,9 @@ gcs_block_resource_x_target_recycle_inputs_result_exact(const ResourceXWriterUse } ResourceXApplyResult -cluster_gcs_resource_x_target_itl_recycle_begin_exact( - const ResourceXWriterUseContext *context, - const ClusterPcmOwnSnapshot *observed, - ResourceXLocalOwnerHandle *handle_out) +cluster_gcs_resource_x_target_itl_recycle_begin_exact(const ResourceXWriterUseContext *context, + const ClusterPcmOwnSnapshot *observed, + ResourceXLocalOwnerHandle *handle_out) { ResourceXGateSnapshot gate; ResourceXApplyResult cancel_result; @@ -16852,8 +15762,7 @@ cluster_gcs_resource_x_target_itl_recycle_begin_exact( return result; result = cluster_pcm_lock_resource_x_itl_recycle_begin_exact( &context->ref, master_session, context->r4_record_generation, - context->buffer_ownership_generation, - observed->reservation_token, (int32)MyProc->pgprocno, + context->buffer_ownership_generation, observed->reservation_token, (int32)MyProc->pgprocno, gcs_block_pcm_x_monotonic_us(), handle_out); if (result != RESOURCE_X_APPLY_APPLIED) return result; @@ -16861,17 +15770,15 @@ cluster_gcs_resource_x_target_itl_recycle_begin_exact( &gate, master_node, master_session); if (result == RESOURCE_X_APPLY_APPLIED) return RESOURCE_X_APPLY_APPLIED; - cancel_result = cluster_pcm_lock_resource_x_itl_recycle_cancel_exact( - handle_out); + cancel_result = cluster_pcm_lock_resource_x_itl_recycle_cancel_exact(handle_out); memset(handle_out, 0, sizeof(*handle_out)); return cancel_result == RESOURCE_X_APPLY_APPLIED ? result : RESOURCE_X_APPLY_RECOVERY_BLOCKED; } ResourceXApplyResult -cluster_gcs_resource_x_target_itl_recycle_finish_exact( - const ResourceXWriterUseContext *context, - const ClusterPcmOwnSnapshot *observed, - const ResourceXLocalOwnerHandle *handle) +cluster_gcs_resource_x_target_itl_recycle_finish_exact(const ResourceXWriterUseContext *context, + const ClusterPcmOwnSnapshot *observed, + const ResourceXLocalOwnerHandle *handle) { ResourceXGateSnapshot gate; ResourceXApplyResult result; @@ -16900,13 +15807,12 @@ cluster_gcs_resource_x_target_itl_recycle_finish_exact( &gate, master_node, master_session); if (result != RESOURCE_X_APPLY_APPLIED) return result; - return cluster_pcm_lock_resource_x_itl_recycle_finish_exact( - handle, gcs_block_pcm_x_monotonic_us()); + return cluster_pcm_lock_resource_x_itl_recycle_finish_exact(handle, + gcs_block_pcm_x_monotonic_us()); } ResourceXApplyResult -cluster_gcs_resource_x_target_itl_recycle_cancel_exact( - const ResourceXLocalOwnerHandle *handle) +cluster_gcs_resource_x_target_itl_recycle_cancel_exact(const ResourceXLocalOwnerHandle *handle) { return cluster_pcm_lock_resource_x_itl_recycle_cancel_exact(handle); } @@ -16970,8 +15876,7 @@ cluster_gcs_handle_block_request_envelope(const ClusterICEnvelope *env, const vo cluster_sf_dep_vec_reset(&sf_dep_vec); memset(&s_barrier_authority_before, 0, sizeof(s_barrier_authority_before)); memset(&s_barrier_authority_after, 0, sizeof(s_barrier_authority_after)); - if (cluster_authority_readiness_managed() - && !cluster_serving_ready_is_current()) + if (cluster_authority_readiness_managed() && !cluster_serving_ready_is_current()) return; if (gcs_block_try_resource_x_frame(env, payload)) return; @@ -16999,21 +15904,17 @@ cluster_gcs_handle_block_request_envelope(const ClusterICEnvelope *env, const vo master_gate_in_quorum = cluster_qvotec_in_quorum(); master_gate_member = cluster_membership_is_member(cluster_node_id); master_gate_join_active = cluster_grd_join_remaster_active_for_shard(req->tag); - master_gate_join_rebuilt - = !master_gate_join_active || cluster_grd_block_view_rebuilt(req->tag); + master_gate_join_rebuilt = !master_gate_join_active || cluster_grd_block_view_rebuilt(req->tag); if (!master_gate_in_quorum || !master_gate_member || !master_gate_join_rebuilt) { ereport(LOG, (errmsg_internal("GCS block recovering master-gate diagnostic"), errdetail_internal("node=%d sender=%d tag=%u/%u/%u/%u in_quorum=%d " - "member=%d join_active=%d join_rebuilt=%d", - cluster_node_id, req->sender_node, req->tag.spcOid, - req->tag.dbOid, - (unsigned int)BufTagGetRelNumber(&req->tag), - (unsigned int)req->tag.blockNum, - master_gate_in_quorum ? 1 : 0, - master_gate_member ? 1 : 0, - master_gate_join_active ? 1 : 0, - master_gate_join_rebuilt ? 1 : 0))); + "member=%d join_active=%d join_rebuilt=%d", + cluster_node_id, req->sender_node, req->tag.spcOid, + req->tag.dbOid, (unsigned int)BufTagGetRelNumber(&req->tag), + (unsigned int)req->tag.blockNum, master_gate_in_quorum ? 1 : 0, + master_gate_member ? 1 : 0, master_gate_join_active ? 1 : 0, + master_gate_join_rebuilt ? 1 : 0))); cluster_grd_inc_join_block_failclosed(); gcs_block_send_reply(req->sender_node, req, GCS_BLOCK_REPLY_DENIED_RESOURCE_RECOVERING, InvalidXLogRecPtr, NULL); @@ -17038,21 +15939,18 @@ cluster_gcs_handle_block_request_envelope(const ClusterICEnvelope *env, const vo if (resource_phase == GCS_BLOCK_RECOVERING) { int static_master = cluster_gcs_lookup_master_static(req->tag); int peer_state = static_master == cluster_node_id - ? (int)CLUSTER_CSSD_PEER_ALIVE - : (int)cluster_cssd_get_peer_state(static_master); + ? (int)CLUSTER_CSSD_PEER_ALIVE + : (int)cluster_cssd_get_peer_state(static_master); ereport(LOG, (errmsg_internal("GCS block recovering phase-gate diagnostic"), errdetail_internal("node=%d sender=%d tag=%u/%u/%u/%u " - "static_master=%d peer_state=%d recovery_in_progress=%d", - cluster_node_id, req->sender_node, req->tag.spcOid, - req->tag.dbOid, - (unsigned int)BufTagGetRelNumber(&req->tag), - (unsigned int)req->tag.blockNum, static_master, - peer_state, - cluster_grd_recovery_in_progress() ? 1 : 0))); - gcs_block_send_reply(req->sender_node, req, - GCS_BLOCK_REPLY_DENIED_RESOURCE_RECOVERING, + "static_master=%d peer_state=%d recovery_in_progress=%d", + cluster_node_id, req->sender_node, req->tag.spcOid, + req->tag.dbOid, (unsigned int)BufTagGetRelNumber(&req->tag), + (unsigned int)req->tag.blockNum, static_master, peer_state, + cluster_grd_recovery_in_progress() ? 1 : 0))); + gcs_block_send_reply(req->sender_node, req, GCS_BLOCK_REPLY_DENIED_RESOURCE_RECOVERING, InvalidXLogRecPtr, NULL); return; } @@ -17105,10 +16003,9 @@ cluster_gcs_handle_block_request_envelope(const ClusterICEnvelope *env, const vo memset(&cached_entry, 0, sizeof(cached_entry)); if (req->transition_id == PCM_TRANS_N_TO_S) { queue_pending_x_before = gcs_block_queue_pending_x_authoritative(req->tag); - resource_x_s_barrier_before = - cluster_gcs_block_resource_x_local_s_barrier_active(req->tag); - s_barrier_authority_before_valid = cluster_pcm_lock_authority_snapshot( - req->tag, &s_barrier_authority_before); + resource_x_s_barrier_before = cluster_gcs_block_resource_x_local_s_barrier_active(req->tag); + s_barrier_authority_before_valid + = cluster_pcm_lock_authority_snapshot(req->tag, &s_barrier_authority_before); } dr = cluster_gcs_block_dedup_lookup_or_register( @@ -17130,24 +16027,21 @@ cluster_gcs_handle_block_request_envelope(const ClusterICEnvelope *env, const vo } if (req->transition_id == PCM_TRANS_N_TO_S) { queue_pending_x_after = gcs_block_queue_pending_x_authoritative(req->tag); - resource_x_s_barrier_after = - cluster_gcs_block_resource_x_local_s_barrier_active(req->tag); - s_barrier_authority_after_valid = cluster_pcm_lock_authority_snapshot( - req->tag, &s_barrier_authority_after); + resource_x_s_barrier_after = cluster_gcs_block_resource_x_local_s_barrier_active(req->tag); + s_barrier_authority_after_valid + = cluster_pcm_lock_authority_snapshot(req->tag, &s_barrier_authority_after); s_barrier_read_action = gcs_block_s_barrier_read_action_exact( - queue_pending_x_before, queue_pending_x_after, - resource_x_s_barrier_before, resource_x_s_barrier_after, - &s_barrier_authority_before, s_barrier_authority_before_valid, - &s_barrier_authority_after, s_barrier_authority_after_valid, - req->sender_node); + queue_pending_x_before, queue_pending_x_after, resource_x_s_barrier_before, + resource_x_s_barrier_after, &s_barrier_authority_before, + s_barrier_authority_before_valid, &s_barrier_authority_after, + s_barrier_authority_after_valid, req->sender_node); /* A cached durable S grant cannot be reinterpreted as the narrow * image-only exception after a native head appears. */ if (s_barrier_read_action == GCS_BLOCK_S_BARRIER_IMAGE_ONLY && dr == GCS_BLOCK_DEDUP_CACHED_REPLY && cached_entry.status != (uint8)GCS_BLOCK_REPLY_READ_IMAGE_FROM_XHOLDER) s_barrier_read_action = GCS_BLOCK_S_BARRIER_DENY; - s_barrier_read_image_only = - s_barrier_read_action == GCS_BLOCK_S_BARRIER_IMAGE_ONLY; + s_barrier_read_image_only = s_barrier_read_action == GCS_BLOCK_S_BARRIER_IMAGE_ONLY; } /* Check both sides of registration. A legacy queue claim or exact @@ -17222,15 +16116,14 @@ cluster_gcs_handle_block_request_envelope(const ClusterICEnvelope *env, const vo return; /* malformed dedup entry; silent drop */ if (!cluster_pcm_lock_authority_snapshot(req->tag, &authority) || !gcs_block_forward_replay_authority_exact( - (GcsBlockReplyStatus)cached_entry.status, req->transition_id, - holder_node, req->sender_node, &authority) + (GcsBlockReplyStatus)cached_entry.status, req->transition_id, holder_node, + req->sender_node, &authority) || (s_barrier_read_image_only - && memcmp(&authority, &s_barrier_authority_after, - sizeof(authority)) != 0)) { + && memcmp(&authority, &s_barrier_authority_after, sizeof(authority)) != 0)) { cluster_gcs_block_dedup_remove(dedup_worker_id, &key); gcs_block_send_reply(req->sender_node, req, - GCS_BLOCK_REPLY_DENIED_MASTER_NOT_HOLDER, - InvalidXLogRecPtr, NULL); + GCS_BLOCK_REPLY_DENIED_MASTER_NOT_HOLDER, InvalidXLogRecPtr, + NULL); return; } if (gcs_block_deny_direct_armed_forward_request(req)) @@ -17267,16 +16160,14 @@ cluster_gcs_handle_block_request_envelope(const ClusterICEnvelope *env, const vo /* A reply-13 marker is image-only. In particular, replay never * upgrades an earlier one-shot route into a durable X->S request. */ if (s_barrier_read_image_only - && !cluster_pcm_lock_authority_matches( - req->tag, &s_barrier_authority_after)) { + && !cluster_pcm_lock_authority_matches(req->tag, &s_barrier_authority_after)) { cluster_gcs_block_dedup_remove(dedup_worker_id, &key); - gcs_block_send_reply(req->sender_node, req, - GCS_BLOCK_REPLY_DENIED_PENDING_X, - InvalidXLogRecPtr, NULL); + gcs_block_send_reply(req->sender_node, req, GCS_BLOCK_REPLY_DENIED_PENDING_X, + InvalidXLogRecPtr, NULL); return; } - fwd_rc = cluster_ic_send_envelope( - PGRAC_IC_MSG_GCS_BLOCK_FORWARD, holder_node, &fwd, sizeof(fwd)); + fwd_rc = cluster_ic_send_envelope(PGRAC_IC_MSG_GCS_BLOCK_FORWARD, holder_node, &fwd, + sizeof(fwd)); cluster_gcs_block_note_send_outcome(GCS_BLOCK_SEND_FAMILY_FORWARD, fwd_rc); if (fwd_rc == CLUSTER_IC_SEND_DONE || fwd_rc == CLUSTER_IC_SEND_WOULD_BLOCK) { @@ -18029,11 +16920,9 @@ cluster_gcs_handle_block_request_envelope(const ClusterICEnvelope *env, const vo local_resident = cluster_bufmgr_probe_block_for_gcs(req->tag); holder_node = cluster_pcm_master_holder_node_by_tag(req->tag); if (s_barrier_read_image_only) { - if (!cluster_pcm_lock_authority_matches( - req->tag, &s_barrier_authority_after)) { + if (!cluster_pcm_lock_authority_matches(req->tag, &s_barrier_authority_after)) { status = GCS_BLOCK_REPLY_DENIED_PENDING_X; - pg_atomic_fetch_add_u64( - &ClusterGcsBlock->starvation_denied_pending_x_count, 1); + pg_atomic_fetch_add_u64(&ClusterGcsBlock->starvation_denied_pending_x_count, 1); goto build_and_send_reply; } pre_state = (PcmLockMode)s_barrier_authority_after.state; @@ -18077,15 +16966,11 @@ cluster_gcs_handle_block_request_envelope(const ClusterICEnvelope *env, const vo * the requester's cached S copy locally. Refusal (active ITL / * state raced / flush unavailable) keeps today's one-shot ship. */ - resource_x_successor_result - = cluster_pcm_lock_resource_x_current_x_successor_exact( - &req->tag, cluster_node_id, - &resource_x_preserve_current_x); + resource_x_successor_result = cluster_pcm_lock_resource_x_current_x_successor_exact( + &req->tag, cluster_node_id, &resource_x_preserve_current_x); if (!s_barrier_read_image_only && cluster_read_scache - && (resource_x_successor_result - == RESOURCE_X_APPLY_NOT_FOUND - || (resource_x_successor_result - == RESOURCE_X_APPLY_APPLIED + && (resource_x_successor_result == RESOURCE_X_APPLY_NOT_FOUND + || (resource_x_successor_result == RESOURCE_X_APPLY_APPLIED && !resource_x_preserve_current_x))) { local_downgrade_outcome = cluster_bufmgr_downgrade_x_to_s_for_gcs_prepare_image( req->tag, &page_lsn, block_buf, NULL); @@ -18116,8 +17001,7 @@ cluster_gcs_handle_block_request_envelope(const ClusterICEnvelope *env, const vo cluster_xp_abort(&xp_ship); if (s_barrier_read_image_only) { status = GCS_BLOCK_REPLY_DENIED_PENDING_X; - pg_atomic_fetch_add_u64( - &ClusterGcsBlock->starvation_denied_pending_x_count, 1); + pg_atomic_fetch_add_u64(&ClusterGcsBlock->starvation_denied_pending_x_count, 1); goto build_and_send_reply; } /* Evict race — fall through to the fail-closed master flow. */ @@ -18159,26 +17043,20 @@ cluster_gcs_handle_block_request_envelope(const ClusterICEnvelope *env, const vo * falls back to the read-image ship on refusal; with the GUC * off this is the pre-㉕ one-shot (counted for D0 ceiling). */ resource_x_preserve_current_x = false; - resource_x_successor_result - = cluster_pcm_lock_resource_x_current_x_successor_exact( - &req->tag, holder_node, - &resource_x_preserve_current_x); + resource_x_successor_result = cluster_pcm_lock_resource_x_current_x_successor_exact( + &req->tag, holder_node, &resource_x_preserve_current_x); if (!s_barrier_read_image_only && cluster_read_scache - && (resource_x_successor_result - == RESOURCE_X_APPLY_NOT_FOUND - || (resource_x_successor_result - == RESOURCE_X_APPLY_APPLIED + && (resource_x_successor_result == RESOURCE_X_APPLY_NOT_FOUND + || (resource_x_successor_result == RESOURCE_X_APPLY_APPLIED && !resource_x_preserve_current_x))) GcsBlockForwardPayloadSetDowngradeRequest(&fwd, true); else cluster_lever_a_note_fwd_oneshot(); if (s_barrier_read_image_only - && !cluster_pcm_lock_authority_matches( - req->tag, &s_barrier_authority_after)) { + && !cluster_pcm_lock_authority_matches(req->tag, &s_barrier_authority_after)) { status = GCS_BLOCK_REPLY_DENIED_PENDING_X; - pg_atomic_fetch_add_u64( - &ClusterGcsBlock->starvation_denied_pending_x_count, 1); + pg_atomic_fetch_add_u64(&ClusterGcsBlock->starvation_denied_pending_x_count, 1); goto build_and_send_reply; } @@ -18201,8 +17079,7 @@ cluster_gcs_handle_block_request_envelope(const ClusterICEnvelope *env, const vo } if (s_barrier_read_image_only) { status = GCS_BLOCK_REPLY_DENIED_PENDING_X; - pg_atomic_fetch_add_u64( - &ClusterGcsBlock->starvation_denied_pending_x_count, 1); + pg_atomic_fetch_add_u64(&ClusterGcsBlock->starvation_denied_pending_x_count, 1); goto build_and_send_reply; } /* Forward send failed — fall through to the fail-closed flow. */ @@ -18212,8 +17089,7 @@ cluster_gcs_handle_block_request_envelope(const ClusterICEnvelope *env, const vo } if (s_barrier_read_image_only) { status = GCS_BLOCK_REPLY_DENIED_PENDING_X; - pg_atomic_fetch_add_u64( - &ClusterGcsBlock->starvation_denied_pending_x_count, 1); + pg_atomic_fetch_add_u64(&ClusterGcsBlock->starvation_denied_pending_x_count, 1); goto build_and_send_reply; } @@ -18513,28 +17389,23 @@ build_and_send_reply: { char *buf; GcsBlockReplyHeader *hdr; - if (s_barrier_read_image_only - && status == GCS_BLOCK_REPLY_READ_IMAGE_FROM_XHOLDER - && !cluster_pcm_lock_authority_matches( - req->tag, &s_barrier_authority_after)) { - gcs_block_release_ship_image(block_payload_release_cb, - block_payload_release_arg); + if (s_barrier_read_image_only && status == GCS_BLOCK_REPLY_READ_IMAGE_FROM_XHOLDER + && !cluster_pcm_lock_authority_matches(req->tag, &s_barrier_authority_after)) { + gcs_block_release_ship_image(block_payload_release_cb, block_payload_release_arg); block_payload = NULL; block_payload_lkey = 0; block_payload_release_cb = NULL; block_payload_release_arg = NULL; page_lsn = InvalidXLogRecPtr; status = GCS_BLOCK_REPLY_DENIED_PENDING_X; - pg_atomic_fetch_add_u64( - &ClusterGcsBlock->starvation_denied_pending_x_count, 1); + pg_atomic_fetch_add_u64(&ClusterGcsBlock->starvation_denied_pending_x_count, 1); } has_block_payload - = (status == GCS_BLOCK_REPLY_GRANTED - || status == GCS_BLOCK_REPLY_READ_IMAGE_FROM_XHOLDER) + = (status == GCS_BLOCK_REPLY_GRANTED || status == GCS_BLOCK_REPLY_READ_IMAGE_FROM_XHOLDER) && block_payload != NULL; send_sf_dep = sf_dep_valid && has_block_payload; - header_len = send_sf_dep ? (uint32)sizeof(GcsBlockReplyHeaderV2) - : (uint32)sizeof(GcsBlockReplyHeader); + header_len + = send_sf_dep ? (uint32)sizeof(GcsBlockReplyHeaderV2) : (uint32)sizeof(GcsBlockReplyHeader); total = header_len + GCS_BLOCK_DATA_SIZE; buf = (char *)palloc0(total); @@ -19138,20 +18009,18 @@ gcs_ctrc_dispatch_prepare(const ClusterCtrcCloseDispatch *dispatch, uint64 participant_observed_generation = 0; uint64 self_incarnation; uint32 required_capabilities - = PGRAC_IC_HELLO_CAP_MULTIXACT_CURRENT_V1 - | PGRAC_IC_HELLO_CAP_MULTIXACT_CTRC_V1; + = PGRAC_IC_HELLO_CAP_MULTIXACT_CURRENT_V1 | PGRAC_IC_HELLO_CAP_MULTIXACT_CTRC_V1; bool participant_current; MemSet(admission, 0, sizeof(*admission)); MemSet(&logical, 0, sizeof(logical)); MemSet(&root, 0, sizeof(root)); if (dispatch == NULL || dispatch->reserved32 != 0 - || memcmp(dispatch->reserved8, - (const uint8[sizeof(dispatch->reserved8)]){0}, - sizeof(dispatch->reserved8)) != 0 + || memcmp(dispatch->reserved8, (const uint8[sizeof(dispatch->reserved8)]){ 0 }, + sizeof(dispatch->reserved8)) + != 0 || (dispatch->suboperation != CTRC_SEAL_CLOSE_AND_CLEAN - && dispatch->suboperation - != CTRC_SEAL_CERTIFICATE_COMMITTED) + && dispatch->suboperation != CTRC_SEAL_CERTIFICATE_COMMITTED) || dispatch->request_id == 0 || dispatch->grant_generation == 0 || dispatch->seal_generation == 0 || cluster_node_id < 0 || dispatch->key.origin_node_id != (uint16)cluster_node_id @@ -19161,15 +18030,13 @@ gcs_ctrc_dispatch_prepare(const ClusterCtrcCloseDispatch *dispatch, || dispatch->participant.capability_record_generation == 0 || dispatch->key.cluster_epoch != cluster_epoch_get_current() || dispatch->key.system_identifier != GetSystemIdentifier() - || dispatch->key.formation_epoch - != dispatch->participant.formation_epoch + || dispatch->key.formation_epoch != dispatch->participant.formation_epoch || dispatch->key.admission_record_generation - != dispatch->participant.admission_record_generation + != dispatch->participant.admission_record_generation || !cluster_gcs_block_family_on_data_plane() || !cluster_membership_is_member(cluster_node_id) || !cluster_membership_is_member(dispatch->participant.node_id) - || (!cluster_write_fence_enforcing() - ? false : !cluster_write_fence_allowed())) + || (!cluster_write_fence_enforcing() ? false : !cluster_write_fence_allowed())) return false; self_incarnation = cluster_qvotec_get_self_incarnation(); @@ -19194,21 +18061,18 @@ gcs_ctrc_dispatch_prepare(const ClusterCtrcCloseDispatch *dispatch, == required_capabilities; else participant_current - = cluster_reconfig_get_observed_slot( - dispatch->participant.node_id, &participant_incarnation, - &participant_observed_generation) - && participant_incarnation != 0 - && participant_observed_generation != 0 - && participant_incarnation - == dispatch->participant.boot_incarnation - && cluster_membership_get_last_admitted_incarnation( - dispatch->participant.node_id) == participant_incarnation - && cluster_reconfig_get_observed_epoch( - dispatch->participant.node_id) - == dispatch->key.formation_epoch + = cluster_reconfig_get_observed_slot(dispatch->participant.node_id, + &participant_incarnation, + &participant_observed_generation) + && participant_incarnation != 0 && participant_observed_generation != 0 + && participant_incarnation == dispatch->participant.boot_incarnation + && cluster_membership_get_last_admitted_incarnation(dispatch->participant.node_id) + == participant_incarnation + && cluster_reconfig_get_observed_epoch(dispatch->participant.node_id) + == dispatch->key.formation_epoch && cluster_sf_peer_capability_generation_matches( - dispatch->participant.node_id, required_capabilities, - dispatch->participant.capability_record_generation); + dispatch->participant.node_id, required_capabilities, + dispatch->participant.capability_record_generation); if (!participant_current) return false; @@ -19239,51 +18103,39 @@ cluster_gcs_ctrc_dispatch_close(const ClusterCtrcCloseDispatch *dispatch) bool dispatched = false; if (gcs_ctrc_dispatch_prepare(dispatch, &admission, request)) { - if (dispatch->participant.node_id == (uint16)cluster_node_id) - { + if (dispatch->participant.node_id == (uint16)cluster_node_id) { ClusterCtrcLocalReleaseAckV1 ack; ClusterCtrcSealReplyResult result; uint16 first_reason = CTRC_SEAL_REASON_IDENTITY; MemSet(&ack, 0, sizeof(ack)); result = cluster_ctrc_participant_request_shared( - &dispatch->key, &dispatch->participant, - dispatch->grant_generation, dispatch->seal_generation, - (ClusterCtrcSealSuboperation)dispatch->suboperation, + &dispatch->key, &dispatch->participant, dispatch->grant_generation, + dispatch->seal_generation, (ClusterCtrcSealSuboperation)dispatch->suboperation, &first_reason, &ack); - if (cluster_semantic_activation_recheck_r4_terminal_census( - &admission)) - { - if (dispatch->suboperation - == CTRC_SEAL_CERTIFICATE_COMMITTED) - dispatched - = cluster_ctrc_origin_note_certificate_reply_shared( - dispatch->request_id, - dispatch->participant.node_id, result); + if (cluster_semantic_activation_recheck_r4_terminal_census(&admission)) { + if (dispatch->suboperation == CTRC_SEAL_CERTIFICATE_COMMITTED) + dispatched = cluster_ctrc_origin_note_certificate_reply_shared( + dispatch->request_id, dispatch->participant.node_id, result); else if (result == CTRC_SEAL_REPLY_LOCAL_RELEASE_ACK) - dispatched = cluster_ctrc_origin_ack_land_shared( - dispatch->request_id, &ack); + dispatched = cluster_ctrc_origin_ack_land_shared(dispatch->request_id, &ack); else dispatched = cluster_ctrc_origin_note_close_reply_shared( - dispatch->request_id, - dispatch->participant.node_id, result); + dispatch->request_id, dispatch->participant.node_id, result); } - } - else - { + } else { BufferTag route_tag = GcsBlockCurrentMxRouteTagMake(dispatch->request_id, dispatch->key.cluster_epoch, cluster_node_id, CLUSTER_CTRC_INTERNAL_ENDPOINT); int worker_id = cluster_lms_shard_for_tag(&route_tag, cluster_lms_workers); uint32 required_capabilities = PGRAC_IC_HELLO_CAP_MULTIXACT_CURRENT_V1 | PGRAC_IC_HELLO_CAP_MULTIXACT_CTRC_V1; - dispatched = worker_id >= 0 - && worker_id < cluster_lms_workers - && cluster_lms_outbound_enqueue_cap_bound( - worker_id, PGRAC_IC_MSG_GCS_BLOCK_FORWARD, - dispatch->participant.node_id, request, - sizeof(request), required_capabilities, - dispatch->participant.capability_record_generation); + dispatched + = worker_id >= 0 && worker_id < cluster_lms_workers + && cluster_lms_outbound_enqueue_cap_bound( + worker_id, PGRAC_IC_MSG_GCS_BLOCK_FORWARD, dispatch->participant.node_id, + request, sizeof(request), required_capabilities, + dispatch->participant.capability_record_generation); } } if (admission.entered) @@ -19345,7 +18197,8 @@ gcs_ctrc_dispatch_local_certificates(const ClusterCtrcCloseDispatch *dispatches, (accepted_count - i) * sizeof(accepted_to_input[0])); } if (accepted_count != 0 - && cluster_ctrc_participant_certificate_batch_shared(accepted, accepted_count, results)) { + && cluster_ctrc_participant_certificate_batch_shared(accepted, accepted_count, + results)) { Size reply_count = 0; for (Size i = 0; i < accepted_count; i++) @@ -19358,8 +18211,8 @@ gcs_ctrc_dispatch_local_certificates(const ClusterCtrcCloseDispatch *dispatches, /* Every surviving token stays entered through the shared census. * Unsupported input shape retains the original per-item consumer. */ if (reply_count != 0 - && !cluster_ctrc_origin_note_local_certificate_batch_shared( - accepted, results, reply_count)) + && !cluster_ctrc_origin_note_local_certificate_batch_shared(accepted, results, + reply_count)) for (Size i = 0; i < reply_count; i++) if (cluster_semantic_activation_recheck_r4_terminal_census( &admissions[accepted_to_input[i]])) @@ -19505,8 +18358,7 @@ cluster_gcs_ctrc_dispatch_batch(const ClusterCtrcCloseDispatch *dispatches, Size * Reconstruct the exact staged CLOSE or certificate-notification request and * land it in the origin registry before any generic backend-id arithmetic. */ static bool -gcs_block_try_land_ctrc_reply( - const ClusterICEnvelope *env, const void *payload) +gcs_block_try_land_ctrc_reply(const ClusterICEnvelope *env, const void *payload) { const GcsBlockReplyHeader *outer; const uint8 *page; @@ -19521,32 +18373,27 @@ gcs_block_try_land_ctrc_reply( bool reserved_zero = true; int i; - if (env == NULL || payload == NULL - || env->payload_length < (uint32)sizeof(GcsBlockReplyHeader)) + if (env == NULL || payload == NULL || env->payload_length < (uint32)sizeof(GcsBlockReplyHeader)) return false; outer = (const GcsBlockReplyHeader *)payload; - if (outer->status - != (uint8)GCS_BLOCK_REPLY_CURRENT_MX_CTRC_SEAL_RESULT) + if (outer->status != (uint8)GCS_BLOCK_REPLY_CURRENT_MX_CTRC_SEAL_RESULT) return false; if (env->msg_type != PGRAC_IC_MSG_GCS_BLOCK_REPLY || env->payload_length != GCS_BLOCK_REPLY_PAYLOAD_TOTAL_SIZE) return true; for (i = 0; i < (int)sizeof(outer->reserved_0); i++) - if (outer->reserved_0[i] != 0) - { + if (outer->reserved_0[i] != 0) { reserved_zero = false; break; } page = (const uint8 *)payload + sizeof(*outer); - if (!reserved_zero - || env->source_node_id >= CLUSTER_CTRC_MAX_PARTICIPANTS + if (!reserved_zero || env->source_node_id >= CLUSTER_CTRC_MAX_PARTICIPANTS || env->dest_node_id != (uint32)cluster_node_id || outer->sender_node != (int32)env->source_node_id || outer->requester_backend_id != CLUSTER_CTRC_INTERNAL_ENDPOINT || outer->transition_id != 0 || outer->page_lsn != 0 || outer->epoch != cluster_epoch_get_current() - || GcsBlockReplyHeaderGetForwardingMasterNode(outer) - != GCS_BLOCK_REPLY_NO_FORWARDING_MASTER + || GcsBlockReplyHeaderGetForwardingMasterNode(outer) != GCS_BLOCK_REPLY_NO_FORWARDING_MASTER || outer->checksum != gcs_block_compute_checksum((const char *)page)) return true; @@ -19554,19 +18401,16 @@ gcs_block_try_land_ctrc_reply( MemSet(&identity, 0, sizeof(identity)); MemSet(&decoded_ack, 0, sizeof(decoded_ack)); MemSet(&reply_header, 0, sizeof(reply_header)); - if (!cluster_ctrc_origin_request_snapshot_shared( - outer->request_id, (uint16)env->source_node_id, - &key, &identity, &grant_generation, &seal_generation, - &suboperation) + if (!cluster_ctrc_origin_request_snapshot_shared(outer->request_id, (uint16)env->source_node_id, + &key, &identity, &grant_generation, + &seal_generation, &suboperation) || key.origin_node_id != (uint16)cluster_node_id - || !cluster_ctrc_seal_request_encode( - &key, outer->request_id, grant_generation, seal_generation, - identity.capability_record_generation, - suboperation, request, sizeof(request)) - || !cluster_ctrc_seal_reply_decode( - page, GCS_BLOCK_DATA_SIZE, request, sizeof(request), - (int32)env->source_node_id, cluster_node_id, - &reply_header, &decoded_ack) + || !cluster_ctrc_seal_request_encode(&key, outer->request_id, grant_generation, + seal_generation, identity.capability_record_generation, + suboperation, request, sizeof(request)) + || !cluster_ctrc_seal_reply_decode(page, GCS_BLOCK_DATA_SIZE, request, sizeof(request), + (int32)env->source_node_id, cluster_node_id, + &reply_header, &decoded_ack) || reply_header.request_id != outer->request_id || reply_header.cluster_epoch != outer->epoch || reply_header.source_node != outer->sender_node @@ -19578,8 +18422,7 @@ gcs_block_try_land_ctrc_reply( outer->request_id, (uint16)env->source_node_id, (ClusterCtrcSealReplyResult)reply_header.result); else if (reply_header.result == CTRC_SEAL_REPLY_LOCAL_RELEASE_ACK) - (void)cluster_ctrc_origin_ack_land_shared( - outer->request_id, &decoded_ack); + (void)cluster_ctrc_origin_ack_land_shared(outer->request_id, &decoded_ack); else (void)cluster_ctrc_origin_note_close_reply_shared( outer->request_id, (uint16)env->source_node_id, @@ -19591,8 +18434,7 @@ gcs_block_try_land_ctrc_reply( * replies, but a disjoint slot domain and typed Spec-3.6b bodies. Consume * every current-MX candidate here so it can never alias the legacy decoder. */ static bool -gcs_block_try_land_current_mx_reply( - const ClusterICEnvelope *env, const void *payload) +gcs_block_try_land_current_mx_reply(const ClusterICEnvelope *env, const void *payload) { const GcsBlockReplyHeader *hdr; const char *block_data; @@ -19600,21 +18442,17 @@ gcs_block_try_land_current_mx_reply( ClusterGcsBlockBackendBlock *blk; int i; - if (env == NULL || payload == NULL - || env->payload_length < (uint32)sizeof(GcsBlockReplyHeader)) + if (env == NULL || payload == NULL || env->payload_length < (uint32)sizeof(GcsBlockReplyHeader)) return false; hdr = (const GcsBlockReplyHeader *)payload; - if (hdr->status - != (uint8)GCS_BLOCK_REPLY_CURRENT_MX_DESCRIBE_RESULT - && hdr->status - != (uint8)GCS_BLOCK_REPLY_CURRENT_MX_MEMBER_PROOF_RESULT) + if (hdr->status != (uint8)GCS_BLOCK_REPLY_CURRENT_MX_DESCRIBE_RESULT + && hdr->status != (uint8)GCS_BLOCK_REPLY_CURRENT_MX_MEMBER_PROOF_RESULT) return false; if (env->msg_type != PGRAC_IC_MSG_GCS_BLOCK_REPLY || env->payload_length != GCS_BLOCK_REPLY_PAYLOAD_TOTAL_SIZE) return true; backend_idx = hdr->requester_backend_id - 1; - if (backend_idx < 0 || backend_idx >= MaxBackends - || gcs_block_backend_blocks == NULL) + if (backend_idx < 0 || backend_idx >= MaxBackends || gcs_block_backend_blocks == NULL) return true; blk = &gcs_block_backend_blocks[backend_idx]; block_data = ((const char *)payload) + sizeof(*hdr); @@ -19622,10 +18460,8 @@ gcs_block_try_land_current_mx_reply( LWLockAcquire(&blk->lock.lock, LW_EXCLUSIVE); for (i = 0; i < MAX_OUTSTANDING_BLOCK_REQUESTS_PER_BACKEND; i++) { ClusterGcsBlockOutstandingSlot *slot = &blk->slots[i]; - ClusterCurrentMxMemberDesc scratch_members - [CLUSTER_CURRENT_MX_MAX_MEMBERS]; - ClusterCurrentMemberProof scratch_proofs - [CLUSTER_CURRENT_MX_MAX_PROOF_ASKS_PER_FRAME]; + ClusterCurrentMxMemberDesc scratch_members[CLUSTER_CURRENT_MX_MAX_MEMBERS]; + ClusterCurrentMemberProof scratch_proofs[CLUSTER_CURRENT_MX_MAX_PROOF_ASKS_PER_FRAME]; ClusterCurrentUpdaterProof scratch_updater; uint16 scratch_count = 0; uint32 scratch_capability_generation = 0; @@ -19639,103 +18475,82 @@ gcs_block_try_land_current_mx_reply( if (!slot->in_use || slot->request_id != hdr->request_id) continue; - for (reserved_index = 0; - reserved_index < (int)sizeof(hdr->reserved_0); - reserved_index++) + for (reserved_index = 0; reserved_index < (int)sizeof(hdr->reserved_0); reserved_index++) if (hdr->reserved_0[reserved_index] != 0) { reserved_zero = false; break; } - outer_valid - = slot->reply_domain == CLUSTER_GCS_BLOCK_REPLY_DOMAIN_CURRENT_MX - && !slot->reply_received - && slot->direct_state == GCS_BLOCK_DIRECT_UNARMED - && !slot->direct_target_prepared - && slot->expected_reply_status == hdr->status - && env->source_node_id == (uint32)hdr->sender_node - && env->dest_node_id == (uint32)cluster_node_id - && hdr->sender_node == slot->expected_master_node - && hdr->requester_backend_id == backend_idx + 1 - && hdr->epoch == slot->request_epoch - && hdr->transition_id == 0 && hdr->page_lsn == 0 - && reserved_zero - && GcsBlockReplyHeaderGetForwardingMasterNode(hdr) - == GCS_BLOCK_REPLY_NO_FORWARDING_MASTER - && hdr->checksum == gcs_block_compute_checksum(block_data); + outer_valid = slot->reply_domain == CLUSTER_GCS_BLOCK_REPLY_DOMAIN_CURRENT_MX + && !slot->reply_received && slot->direct_state == GCS_BLOCK_DIRECT_UNARMED + && !slot->direct_target_prepared && slot->expected_reply_status == hdr->status + && env->source_node_id == (uint32)hdr->sender_node + && env->dest_node_id == (uint32)cluster_node_id + && hdr->sender_node == slot->expected_master_node + && hdr->requester_backend_id == backend_idx + 1 + && hdr->epoch == slot->request_epoch && hdr->transition_id == 0 + && hdr->page_lsn == 0 && reserved_zero + && GcsBlockReplyHeaderGetForwardingMasterNode(hdr) + == GCS_BLOCK_REPLY_NO_FORWARDING_MASTER + && hdr->checksum == gcs_block_compute_checksum(block_data); if (outer_valid) { - if (hdr->status - == (uint8)GCS_BLOCK_REPLY_CURRENT_MX_DESCRIBE_RESULT + if (hdr->status == (uint8)GCS_BLOCK_REPLY_CURRENT_MX_DESCRIBE_RESULT && slot->expected_current_mx_key_valid) { - typed_result - = cluster_multixact_current_wire_validate_describe_reply( - block_data, GCS_BLOCK_DATA_SIZE, - slot->expected_master_node, slot->request_epoch, - slot->request_id, &slot->expected_current_mx_key, - scratch_members, lengthof(scratch_members), - &scratch_count, &scratch_total); - typed_valid = typed_result != CMX_DESC_UNKNOWN - && typed_result != CMX_DESC_TIMEOUT; - } else if (hdr->status - == (uint8)GCS_BLOCK_REPLY_CURRENT_MX_MEMBER_PROOF_RESULT + typed_result = cluster_multixact_current_wire_validate_describe_reply( + block_data, GCS_BLOCK_DATA_SIZE, slot->expected_master_node, + slot->request_epoch, slot->request_id, &slot->expected_current_mx_key, + scratch_members, lengthof(scratch_members), &scratch_count, &scratch_total); + typed_valid = typed_result != CMX_DESC_UNKNOWN && typed_result != CMX_DESC_TIMEOUT; + } else if (hdr->status == (uint8)GCS_BLOCK_REPLY_CURRENT_MX_MEMBER_PROOF_RESULT && slot->expected_current_mx_proof_valid) - typed_valid - = cluster_multixact_current_wire_validate_proof_reply_frame( - block_data, GCS_BLOCK_DATA_SIZE, - slot->expected_master_node, slot->request_epoch, - &slot->expected_current_mx_proof, &proof_result, - scratch_proofs, lengthof(scratch_proofs), - &scratch_count, &scratch_updater, - &scratch_capability_generation); + typed_valid = cluster_multixact_current_wire_validate_proof_reply_frame( + block_data, GCS_BLOCK_DATA_SIZE, slot->expected_master_node, + slot->request_epoch, &slot->expected_current_mx_proof, &proof_result, + scratch_proofs, lengthof(scratch_proofs), &scratch_count, &scratch_updater, + &scratch_capability_generation); } if (!typed_valid) { const ClusterCurrentMxDescribeReplyPage *describe_page = (const ClusterCurrentMxDescribeReplyPage *)block_data; - ereport(LOG, - (errmsg("cluster_gcs_block: dropped stale current-MX reply"), - errdetail("request_id=" UINT64_FORMAT - " outer_valid=%d typed_result=%d domain=%u" - " reply_received=%d direct_state=%d direct_prepared=%d" - " expected_status=%u status=%u env_source=%u env_dest=%u" - " expected_source=%d sender=%d backend=%d expected_backend=%d" - " expected_epoch=" UINT64_FORMAT " epoch=" UINT64_FORMAT - " transition=%u page_lsn=" UINT64_FORMAT - " reserved_zero=%d forwarding_master=%d checksum_match=%d" - " body_magic=%u body_version=%u body_kind=%u body_result=%u" - " body_source=%u body_request=" UINT64_FORMAT - " body_origin=%u body_mxid=%u body_epoch=%u" - " expected_origin=%u expected_mxid=%u expected_key_epoch=%u" - " body_entries=%u body_total=%u body_wire_length=%u", - slot->request_id, outer_valid, (int)typed_result, - (unsigned int)slot->reply_domain, slot->reply_received, - (int)slot->direct_state, slot->direct_target_prepared, - (unsigned int)slot->expected_reply_status, - (unsigned int)hdr->status, env->source_node_id, - env->dest_node_id, slot->expected_master_node, - hdr->sender_node, hdr->requester_backend_id, - backend_idx + 1, slot->request_epoch, hdr->epoch, - (unsigned int)hdr->transition_id, hdr->page_lsn, - reserved_zero, - GcsBlockReplyHeaderGetForwardingMasterNode(hdr), - hdr->checksum - == gcs_block_compute_checksum(block_data), - describe_page->header.magic, - (unsigned int)describe_page->header.version, - (unsigned int)describe_page->header.kind, - (unsigned int)describe_page->header.result, - describe_page->header.source_node_id, - describe_page->header.request_id, - (unsigned int)describe_page->header.mxkey.origin_node_id, - describe_page->header.mxkey.multixact_id, - describe_page->header.mxkey.cluster_epoch, - (unsigned int)slot->expected_current_mx_key.origin_node_id, - slot->expected_current_mx_key.multixact_id, - slot->expected_current_mx_key.cluster_epoch, - (unsigned int)describe_page->header.entry_count, - describe_page->header.total_count, - (unsigned int)describe_page->header.wire_length))); - pg_atomic_fetch_add_u64( - &ClusterGcsBlock->stale_reply_drop_count, 1); + ereport( + LOG, + (errmsg("cluster_gcs_block: dropped stale current-MX reply"), + errdetail("request_id=" UINT64_FORMAT " outer_valid=%d typed_result=%d domain=%u" + " reply_received=%d direct_state=%d direct_prepared=%d" + " expected_status=%u status=%u env_source=%u env_dest=%u" + " expected_source=%d sender=%d backend=%d expected_backend=%d" + " expected_epoch=" UINT64_FORMAT " epoch=" UINT64_FORMAT + " transition=%u page_lsn=" UINT64_FORMAT + " reserved_zero=%d forwarding_master=%d checksum_match=%d" + " body_magic=%u body_version=%u body_kind=%u body_result=%u" + " body_source=%u body_request=" UINT64_FORMAT + " body_origin=%u body_mxid=%u body_epoch=%u" + " expected_origin=%u expected_mxid=%u expected_key_epoch=%u" + " body_entries=%u body_total=%u body_wire_length=%u", + slot->request_id, outer_valid, (int)typed_result, + (unsigned int)slot->reply_domain, slot->reply_received, + (int)slot->direct_state, slot->direct_target_prepared, + (unsigned int)slot->expected_reply_status, (unsigned int)hdr->status, + env->source_node_id, env->dest_node_id, slot->expected_master_node, + hdr->sender_node, hdr->requester_backend_id, backend_idx + 1, + slot->request_epoch, hdr->epoch, (unsigned int)hdr->transition_id, + hdr->page_lsn, reserved_zero, + GcsBlockReplyHeaderGetForwardingMasterNode(hdr), + hdr->checksum == gcs_block_compute_checksum(block_data), + describe_page->header.magic, (unsigned int)describe_page->header.version, + (unsigned int)describe_page->header.kind, + (unsigned int)describe_page->header.result, + describe_page->header.source_node_id, describe_page->header.request_id, + (unsigned int)describe_page->header.mxkey.origin_node_id, + describe_page->header.mxkey.multixact_id, + describe_page->header.mxkey.cluster_epoch, + (unsigned int)slot->expected_current_mx_key.origin_node_id, + slot->expected_current_mx_key.multixact_id, + slot->expected_current_mx_key.cluster_epoch, + (unsigned int)describe_page->header.entry_count, + describe_page->header.total_count, + (unsigned int)describe_page->header.wire_length))); + pg_atomic_fetch_add_u64(&ClusterGcsBlock->stale_reply_drop_count, 1); LWLockRelease(&blk->lock.lock); return true; } @@ -19771,8 +18586,7 @@ gcs_block_try_land_r4_terminal_reply(const ClusterICEnvelope *env, const void *p ClusterGcsBlockBackendBlock *blk; int i; - if (env == NULL || payload == NULL - || env->payload_length < (uint32)sizeof(GcsBlockReplyHeader)) + if (env == NULL || payload == NULL || env->payload_length < (uint32)sizeof(GcsBlockReplyHeader)) return false; hdr = (const GcsBlockReplyHeader *)payload; if (hdr->status != (uint8)GCS_BLOCK_REPLY_R4_CR_FULL @@ -19791,8 +18605,7 @@ gcs_block_try_land_r4_terminal_reply(const ClusterICEnvelope *env, const void *p } backend_idx = hdr->requester_backend_id - 1; - if (backend_idx < 0 || backend_idx >= MaxBackends - || gcs_block_backend_blocks == NULL) + if (backend_idx < 0 || backend_idx >= MaxBackends || gcs_block_backend_blocks == NULL) return true; blk = &gcs_block_backend_blocks[backend_idx]; @@ -19802,8 +18615,7 @@ gcs_block_try_land_r4_terminal_reply(const ClusterICEnvelope *env, const void *p if (!slot->in_use || slot->request_id != hdr->request_id) continue; - if (slot->reply_domain != CLUSTER_GCS_BLOCK_REPLY_DOMAIN_R4_CR - || slot->reply_received + if (slot->reply_domain != CLUSTER_GCS_BLOCK_REPLY_DOMAIN_R4_CR || slot->reply_received || slot->direct_state == GCS_BLOCK_DIRECT_ARMED || slot->direct_state == GCS_BLOCK_DIRECT_LANDED || slot->direct_state == GCS_BLOCK_DIRECT_ABORTING) { @@ -19821,8 +18633,7 @@ gcs_block_try_land_r4_terminal_reply(const ClusterICEnvelope *env, const void *p && GcsBlockReplyHeaderGetForwardingMasterNode(hdr) == GCS_BLOCK_REPLY_NO_FORWARDING_MASTER) { expected.sender_node = slot->expected_master_node; - expected.forwarding_master_node - = GCS_BLOCK_REPLY_NO_FORWARDING_MASTER; + expected.forwarding_master_node = GCS_BLOCK_REPLY_NO_FORWARDING_MASTER; } else { expected.sender_node = (int32)env->source_node_id; expected.forwarding_master_node = slot->expected_master_node; @@ -19891,8 +18702,7 @@ cluster_gcs_handle_block_reply_envelope(const ClusterICEnvelope *env, const void if (hdr->status == (uint8)GCS_BLOCK_REPLY_R4_UNDO_DATA_RESULT) { if (hdr->requester_backend_id != CLUSTER_GCS_BLOCK_R4_INTERNAL_ENDPOINT) return; - (void)cluster_cr_server_r4_land_foreign_undo( - env, hdr, block_data, undo_trailer); + (void)cluster_cr_server_r4_land_foreign_undo(env, hdr, block_data, undo_trailer); return; } @@ -19911,8 +18721,8 @@ cluster_gcs_handle_block_reply_envelope(const ClusterICEnvelope *env, const void int32 fwd_master; bool authorized = false; uint8 reply_domain = GcsBlockReplyStatusIsR4((GcsBlockReplyStatus)hdr->status) - ? CLUSTER_GCS_BLOCK_REPLY_DOMAIN_R4_CR - : CLUSTER_GCS_BLOCK_REPLY_DOMAIN_LEGACY_ACQUIRE; + ? CLUSTER_GCS_BLOCK_REPLY_DOMAIN_R4_CR + : CLUSTER_GCS_BLOCK_REPLY_DOMAIN_LEGACY_ACQUIRE; /* Reply identity includes the closed slot domain. Reject before * touching reply_received or any other slot-owned result byte. */ @@ -20078,8 +18888,7 @@ gcs_block_forward_reply_immediate_deny(const GcsBlockForwardPayload *fwd) * holder logic. A positive ACK is built only while the exact target R4 * formation/root and both endpoint identities remain current. */ static bool -gcs_block_try_ctrc_forward136( - const ClusterICEnvelope *env, const void *payload) +gcs_block_try_ctrc_forward136(const ClusterICEnvelope *env, const void *payload) { ClusterCtrcSealRequestV1 request; ClusterCtrcTxnKeyV1 key; @@ -20094,13 +18903,11 @@ gcs_block_try_ctrc_forward136( uint64 self_incarnation; uint32 source_capability_generation = 0; uint32 required_capabilities - = PGRAC_IC_HELLO_CAP_MULTIXACT_CURRENT_V1 - | PGRAC_IC_HELLO_CAP_MULTIXACT_CTRC_V1; + = PGRAC_IC_HELLO_CAP_MULTIXACT_CURRENT_V1 | PGRAC_IC_HELLO_CAP_MULTIXACT_CTRC_V1; uint16 first_reason = CTRC_SEAL_REASON_IDENTITY; ClusterCtrcSealReplyResult result = CTRC_SEAL_REPLY_BLOCKED_RETAIN; int expected_worker; - uint32 reply_total - = (uint32)sizeof(GcsBlockReplyHeader) + GCS_BLOCK_DATA_SIZE; + uint32 reply_total = (uint32)sizeof(GcsBlockReplyHeader) + GCS_BLOCK_DATA_SIZE; char *reply; GcsBlockReplyHeader *outer; uint8 *page; @@ -20108,8 +18915,7 @@ gcs_block_try_ctrc_forward136( bool source_capability_current; bool bracket_current = false; - if (env == NULL || payload == NULL - || env->payload_length != CLUSTER_CTRC_SEAL_REQUEST_BYTES) + if (env == NULL || payload == NULL || env->payload_length != CLUSTER_CTRC_SEAL_REQUEST_BYTES) return false; MemSet(&request, 0, sizeof(request)); MemSet(&key, 0, sizeof(key)); @@ -20119,95 +18925,73 @@ gcs_block_try_ctrc_forward136( MemSet(&logical, 0, sizeof(logical)); MemSet(&root, 0, sizeof(root)); if (env->msg_type != PGRAC_IC_MSG_GCS_BLOCK_FORWARD - || env->dest_node_id != (uint32)cluster_node_id - || env->epoch != cluster_epoch_get_current() + || env->dest_node_id != (uint32)cluster_node_id || env->epoch != cluster_epoch_get_current() || !cluster_gcs_block_family_on_data_plane() - || !cluster_ctrc_seal_request_decode( - (const uint8 *)payload, env->payload_length, - GetSystemIdentifier(), (int32)env->source_node_id, - cluster_node_id, cluster_epoch_get_current(), &request, &key)) + || !cluster_ctrc_seal_request_decode((const uint8 *)payload, env->payload_length, + GetSystemIdentifier(), (int32)env->source_node_id, + cluster_node_id, cluster_epoch_get_current(), &request, + &key)) return true; - route_tag = GcsBlockCurrentMxRouteTagMake( - request.request_id, request.cluster_epoch, - request.original_requester_node, request.requester_backend_id); - expected_worker = cluster_lms_shard_for_tag(&route_tag, - cluster_lms_workers); + route_tag = GcsBlockCurrentMxRouteTagMake(request.request_id, request.cluster_epoch, + request.original_requester_node, + request.requester_backend_id); + expected_worker = cluster_lms_shard_for_tag(&route_tag, cluster_lms_workers); Assert(expected_worker == cluster_ic_tier1_my_data_channel()); if (expected_worker != cluster_ic_tier1_my_data_channel()) return true; self_incarnation = cluster_qvotec_get_self_incarnation(); - if ((int32)env->source_node_id == cluster_node_id) - { + if ((int32)env->source_node_id == cluster_node_id) { source_incarnation = self_incarnation; source_observed_generation = self_incarnation; source_capability_current - = (cluster_ic_local_capability_word() & required_capabilities) - == required_capabilities; - } - else - { + = (cluster_ic_local_capability_word() & required_capabilities) == required_capabilities; + } else { source_capability_current - = cluster_sf_peer_multixact_current_capability_generation( - (int32)env->source_node_id, &source_capability_generation) + = cluster_sf_peer_multixact_current_capability_generation((int32)env->source_node_id, + &source_capability_generation) && source_capability_generation != 0 && cluster_sf_peer_capability_generation_matches( - (int32)env->source_node_id, required_capabilities, - source_capability_generation); - (void)cluster_reconfig_get_observed_slot( - (int32)env->source_node_id, &source_incarnation, - &source_observed_generation); - } - if (source_capability_current && source_incarnation != 0 - && source_observed_generation != 0 && self_incarnation != 0 - && cluster_membership_is_member((int32)env->source_node_id) + (int32)env->source_node_id, required_capabilities, source_capability_generation); + (void)cluster_reconfig_get_observed_slot((int32)env->source_node_id, &source_incarnation, + &source_observed_generation); + } + if (source_capability_current && source_incarnation != 0 && source_observed_generation != 0 + && self_incarnation != 0 && cluster_membership_is_member((int32)env->source_node_id) && cluster_membership_is_member(cluster_node_id) - && cluster_membership_get_last_admitted_incarnation( - (int32)env->source_node_id) == source_incarnation - && cluster_membership_get_last_admitted_incarnation(cluster_node_id) - == self_incarnation + && cluster_membership_get_last_admitted_incarnation((int32)env->source_node_id) + == source_incarnation + && cluster_membership_get_last_admitted_incarnation(cluster_node_id) == self_incarnation && source_incarnation == key.origin_boot_incarnation - && cluster_reconfig_get_observed_epoch((int32)env->source_node_id) - == key.formation_epoch - && (!cluster_write_fence_enforcing() - || cluster_write_fence_allowed()) + && cluster_reconfig_get_observed_epoch((int32)env->source_node_id) == key.formation_epoch + && (!cluster_write_fence_enforcing() || cluster_write_fence_allowed()) && cluster_semantic_activation_enter_r4_terminal_census(&admission) - == CLUSTER_SEMANTIC_ADMISSION_OK) - { + == CLUSTER_SEMANTIC_ADMISSION_OK) { logical.owner_instance = key.owner_instance; logical.segment_id = key.segment_id; bracket_current = admission.formation_epoch == key.formation_epoch - && admission.record_generation - == key.admission_record_generation + && admission.record_generation == key.admission_record_generation && cluster_semantic_activation_resolve_shared_undo_root_r4_terminal_census( - &admission, CLUSTER_UNDO_PATH_RUNTIME_SHARED, - logical.owner_instance, logical.segment_id, &root) - && root.intent == CLUSTER_UNDO_PATH_RUNTIME_SHARED - && root.root_id == key.root_id + &admission, CLUSTER_UNDO_PATH_RUNTIME_SHARED, logical.owner_instance, + logical.segment_id, &root) + && root.intent == CLUSTER_UNDO_PATH_RUNTIME_SHARED && root.root_id == key.root_id && root.root_generation == key.root_generation && key.root_descriptor_incarnation == root.root_generation - && cluster_semantic_activation_recheck_r4_terminal_census( - &admission); - if (bracket_current) - { + && cluster_semantic_activation_recheck_r4_terminal_census(&admission); + if (bracket_current) { identity.node_id = (uint16)cluster_node_id; identity.capability_record_generation = request.participant_capability_record_generation; identity.boot_incarnation = self_incarnation; identity.formation_epoch = admission.formation_epoch; - identity.admission_record_generation - = admission.record_generation; + identity.admission_record_generation = admission.record_generation; result = cluster_ctrc_participant_request_shared( - &key, &identity, request.grant_generation, - request.seal_generation, - (ClusterCtrcSealSuboperation)request.suboperation, - &first_reason, &ack); + &key, &identity, request.grant_generation, request.seal_generation, + (ClusterCtrcSealSuboperation)request.suboperation, &first_reason, &ack); if (result == CTRC_SEAL_REPLY_LOCAL_RELEASE_ACK - && !cluster_semantic_activation_recheck_r4_terminal_census( - &admission)) - { + && !cluster_semantic_activation_recheck_r4_terminal_census(&admission)) { MemSet(&ack, 0, sizeof(ack)); first_reason = CTRC_SEAL_REASON_IDENTITY; result = CTRC_SEAL_REPLY_BLOCKED_RETAIN; @@ -20222,9 +19006,7 @@ gcs_block_try_ctrc_forward136( if (!cluster_ctrc_seal_reply_encode( (const uint8 *)payload, env->payload_length, cluster_node_id, (int32)env->source_node_id, result, first_reason, - result == CTRC_SEAL_REPLY_LOCAL_RELEASE_ACK ? &ack : NULL, - page, GCS_BLOCK_DATA_SIZE)) - { + result == CTRC_SEAL_REPLY_LOCAL_RELEASE_ACK ? &ack : NULL, page, GCS_BLOCK_DATA_SIZE)) { pfree(reply); return true; } @@ -20233,25 +19015,20 @@ gcs_block_try_ctrc_forward136( outer->sender_node = cluster_node_id; outer->requester_backend_id = CLUSTER_CTRC_INTERNAL_ENDPOINT; outer->transition_id = 0; - outer->status - = (uint8)GCS_BLOCK_REPLY_CURRENT_MX_CTRC_SEAL_RESULT; - GcsBlockReplyHeaderSetForwardingMasterNode( - outer, GCS_BLOCK_REPLY_NO_FORWARDING_MASTER); + outer->status = (uint8)GCS_BLOCK_REPLY_CURRENT_MX_CTRC_SEAL_RESULT; + GcsBlockReplyHeaderSetForwardingMasterNode(outer, GCS_BLOCK_REPLY_NO_FORWARDING_MASTER); outer->checksum = gcs_block_compute_checksum((const char *)page); if ((int32)env->source_node_id == cluster_node_id) - send_result = gcs_block_send_envelope_or_loopback( - PGRAC_IC_MSG_GCS_BLOCK_REPLY, cluster_node_id, reply, reply_total); + send_result = gcs_block_send_envelope_or_loopback(PGRAC_IC_MSG_GCS_BLOCK_REPLY, + cluster_node_id, reply, reply_total); else if (cluster_sf_peer_capability_generation_matches( - (int32)env->source_node_id, required_capabilities, - source_capability_generation)) - send_result = cluster_ic_send_envelope( - PGRAC_IC_MSG_GCS_BLOCK_REPLY, (int32)env->source_node_id, - reply, reply_total); + (int32)env->source_node_id, required_capabilities, source_capability_generation)) + send_result = cluster_ic_send_envelope(PGRAC_IC_MSG_GCS_BLOCK_REPLY, + (int32)env->source_node_id, reply, reply_total); else send_result = CLUSTER_IC_SEND_NOT_ADMITTED; - cluster_gcs_block_note_send_outcome( - GCS_BLOCK_SEND_FAMILY_REPLY, send_result); + cluster_gcs_block_note_send_outcome(GCS_BLOCK_SEND_FAMILY_REPLY, send_result); pfree(reply); return true; } @@ -20259,8 +19036,7 @@ gcs_block_try_ctrc_forward136( /* Exact 128-byte Current-MX demultiplexing precedes every legacy BufferTag * interpretation. Kind 8 remains reserved/dormant and is consumed here. */ static bool -gcs_block_try_current_mx_forward128( - const ClusterICEnvelope *env, const void *payload) +gcs_block_try_current_mx_forward128(const ClusterICEnvelope *env, const void *payload) { const GcsBlockForwardPayload *routing; @@ -20280,8 +19056,7 @@ gcs_block_try_current_mx_forward128( #ifdef USE_CLUSTER_UNIT bool -cluster_gcs_block_test_current_mx_forward128( - const ClusterICEnvelope *env, const void *payload) +cluster_gcs_block_test_current_mx_forward128(const ClusterICEnvelope *env, const void *payload) { return gcs_block_try_current_mx_forward128(env, payload); } @@ -20338,8 +19113,8 @@ cluster_gcs_handle_block_forward_envelope(const ClusterICEnvelope *env, const vo || env->source_node_id != (uint32)fwd->original_requester_node) return; if (!cluster_cr_server_freshref_c1b_pair_request_decode( - fwd, (int32)env->source_node_id, cluster_node_id, - cluster_epoch_get_current(), MaxBackends, NULL, NULL, NULL, NULL)) { + fwd, (int32)env->source_node_id, cluster_node_id, cluster_epoch_get_current(), + MaxBackends, NULL, NULL, NULL, NULL)) { gcs_block_forward_reply_immediate_deny(fwd); return; } @@ -20954,8 +19729,7 @@ gcs_block_pcm_x_authenticated_session(int32 node_id, uint64 expected_epoch, uint static void gcs_block_legacy_pcm_x_fail_closed(int32 source_node) { - if (source_node >= 0 - && source_node < RESOURCE_X_PROTOCOL_NODE_LIMIT + if (source_node >= 0 && source_node < RESOURCE_X_PROTOCOL_NODE_LIMIT && source_node != cluster_node_id) cluster_lms_data_plane_close_peer_now(source_node); } @@ -20965,8 +19739,7 @@ gcs_block_legacy_pcm_x_fail_closed(int32 source_node) * one shared disposition confirms exact TARGET admission and then drops the * frame without resource state, buffer, outbound-ring, allocation, or ACK. */ static void -gcs_block_legacy_pcm_x_stale_ingress( - const ClusterICEnvelope *env, const void *payload) +gcs_block_legacy_pcm_x_stale_ingress(const ClusterICEnvelope *env, const void *payload) { ClusterSemanticAdmissionToken admission; ClusterSemanticAdmissionResult admission_result; @@ -20982,23 +19755,20 @@ gcs_block_legacy_pcm_x_stale_ingress( return; source_node = (int32)env->source_node_id; malformed = env->msg_type < PGRAC_IC_MSG_PCM_X_ENQUEUE - || env->msg_type > PGRAC_IC_MSG_PCM_X_RETIRE_ACK - || source_node < 0 - || source_node >= RESOURCE_X_PROTOCOL_NODE_LIMIT - || env->dest_node_id != (uint32)cluster_node_id - || env->payload_length == 0 - || env->payload_length > PGRAC_IC_PAYLOAD_MAX - || payload == NULL - || env->epoch != cluster_epoch_get_current(); + || env->msg_type > PGRAC_IC_MSG_PCM_X_RETIRE_ACK || source_node < 0 + || source_node >= RESOURCE_X_PROTOCOL_NODE_LIMIT + || env->dest_node_id != (uint32)cluster_node_id || env->payload_length == 0 + || env->payload_length > PGRAC_IC_PAYLOAD_MAX || payload == NULL + || env->epoch != cluster_epoch_get_current(); if (malformed) { gcs_block_legacy_pcm_x_fail_closed(source_node); return; } memset(&admission, 0, sizeof(admission)); - admission_result = cluster_semantic_activation_enter( - CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1, - CLUSTER_SEMANTIC_TARGET_SIDE, &admission); + admission_result + = cluster_semantic_activation_enter(CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1, + CLUSTER_SEMANTIC_TARGET_SIDE, &admission); if (admission_result != CLUSTER_SEMANTIC_ADMISSION_OK) { gcs_block_legacy_pcm_x_fail_closed(source_node); return; @@ -21006,28 +19776,27 @@ gcs_block_legacy_pcm_x_stale_ingress( if (source_node == cluster_node_id) { capability_word = cluster_ic_local_capability_word(); connection_generation = 1; - } - else + } else peer_sampled = cluster_sf_peer_capability_word_sample( - source_node, PGRAC_IC_HELLO_CAP_GCS_RESOURCE_X_CONVERT_V1, - &capability_word, &connection_generation); + source_node, PGRAC_IC_HELLO_CAP_GCS_RESOURCE_X_CONVERT_V1, &capability_word, + &connection_generation); (void)capability_word; peer_exact = peer_sampled - && gcs_block_resource_x_target_peer_matches_exact( - &admission, source_node, connection_generation); + && gcs_block_resource_x_target_peer_matches_exact(&admission, source_node, + connection_generation); admission_current = cluster_semantic_activation_recheck(&admission); cluster_semantic_activation_leave(&admission); if (!peer_sampled || !peer_exact || !admission_current) gcs_block_legacy_pcm_x_fail_closed(source_node); } -#define LEGACY_PCM_X_STALE_INFO(msg, label) \ - { \ - .msg_type = (msg), .name = (label), \ - .allowed_producer_mask = CLUSTER_IC_PRODUCER_BUFFER_CLIENTS \ - | CLUSTER_IC_PRODUCER_LMON | CLUSTER_IC_PRODUCER_LMS_DATA, \ - .broadcast_ok = false, .handler = gcs_block_legacy_pcm_x_stale_ingress, \ - .plane = CLUSTER_IC_PLANE_DATA \ +#define LEGACY_PCM_X_STALE_INFO(msg, label) \ + { \ + .msg_type = (msg), .name = (label), \ + .allowed_producer_mask = CLUSTER_IC_PRODUCER_BUFFER_CLIENTS | CLUSTER_IC_PRODUCER_LMON \ + | CLUSTER_IC_PRODUCER_LMS_DATA, \ + .broadcast_ok = false, .handler = gcs_block_legacy_pcm_x_stale_ingress, \ + .plane = CLUSTER_IC_PLANE_DATA \ } static const ClusterICMsgTypeInfo legacy_pcm_x_stale_infos[] = { @@ -22163,8 +20932,8 @@ gcs_block_invalidate_execute(const GcsBlockInvalidatePayload *inv) PcmLockMode pre_state; XLogRecPtr page_lsn = InvalidXLogRecPtr; SCN page_scn = InvalidScn; /* spec-2.41 D3 — ACK SCN carrier */ - uint8 ack_status = 0; /* OK */ - bool kept_pi = false; /* spec-6.12h D-h2 — drop converted to a PI */ + uint8 ack_status = 0; /* OK */ + bool kept_pi = false; /* spec-6.12h D-h2 — drop converted to a PI */ bool woke_local = false; uint64 current_epoch = cluster_epoch_get_current(); @@ -22868,8 +21637,8 @@ cluster_gcs_handle_block_invalidate_ack_envelope(const ClusterICEnvelope *env, c */ if ((ack->ack_status == 0 || ack->ack_status == 2) && ack->epoch == cluster_epoch_get_current() && ack->sender_node >= 0 && ack->sender_node < 32) { - (void)cluster_pcm_lock_apply_gcs_transition( - ack->tag, PCM_TRANS_S_TO_N_INVALIDATE, ack->sender_node); + (void)cluster_pcm_lock_apply_gcs_transition(ack->tag, PCM_TRANS_S_TO_N_INVALIDATE, + ack->sender_node); /* PGRAC: spec-6.12h D-h2 — the holder reported its dropped copy was * kept as a Past Image (D-h1); record it on the PI holder bitmap so * the discard protocol can target it later. Runs here (before the @@ -23799,79 +22568,60 @@ cluster_gcs_block_resource_x_cutover_tick(void) if (!cluster_semantic_activation_r11_cutover_snapshot(&cutover)) return false; - if (cutover.record_generation == 0 - || cutover.record_generation == UINT64_MAX + if (cutover.record_generation == 0 || cutover.record_generation == UINT64_MAX || cutover.formation_epoch == UINT64_MAX) return false; if (cutover.phase == CLUSTER_SEMANTIC_R11_CUTOVER_TARGET_OPEN) return false; if (!cluster_pcm_lock_resource_x_gate_snapshot(&gate)) { - if (cutover.phase - != CLUSTER_SEMANTIC_R11_CUTOVER_SOURCE_CLOSED - || !cluster_pcm_lock_resource_x_cutover_gate_snapshot_exact( - &gate)) + if (cutover.phase != CLUSTER_SEMANTIC_R11_CUTOVER_SOURCE_CLOSED + || !cluster_pcm_lock_resource_x_cutover_gate_snapshot_exact(&gate)) return false; } if (gate.reserved != 0) return false; if (cutover.phase == CLUSTER_SEMANTIC_R11_CUTOVER_SOURCE_CLOSED) { - if ((gate.phase != RESOURCE_X_GATE_OPEN - && gate.phase != RESOURCE_X_GATE_FROZEN) - || !cluster_resource_x_reconfig_cutover_begin_native_exact( - &token) + if ((gate.phase != RESOURCE_X_GATE_OPEN && gate.phase != RESOURCE_X_GATE_FROZEN) + || !cluster_resource_x_reconfig_cutover_begin_native_exact(&token) || !cluster_pcm_lock_resource_x_gate_snapshot(&gate) - || gate.phase != RESOURCE_X_GATE_FROZEN - || gate.formation != token.old_formation + || gate.phase != RESOURCE_X_GATE_FROZEN || gate.formation != token.old_formation || gate.freeze_generation != token.freeze_generation) return false; if (token.new_formation == 0) { - for (calls = 0; - calls < GCS_BLOCK_RESOURCE_X_RECONFIG_CALLS_PER_CHECKPOINT; - calls++) { + for (calls = 0; calls < GCS_BLOCK_RESOURCE_X_RECONFIG_CALLS_PER_CHECKPOINT; calls++) { result = cluster_resource_x_reconfig_sweep( - &token, GCS_BLOCK_RESOURCE_X_RECONFIG_PROBE_BUDGET, - &batch); + &token, GCS_BLOCK_RESOURCE_X_RECONFIG_PROBE_BUDGET, &batch); if (result == RESOURCE_X_RECONFIG_DONE) break; - if (result != RESOURCE_X_RECONFIG_MORE - && result != RESOURCE_X_RECONFIG_RETRY) + if (result != RESOURCE_X_RECONFIG_MORE && result != RESOURCE_X_RECONFIG_RETRY) return false; } if (result != RESOURCE_X_RECONFIG_DONE) { - return result == RESOURCE_X_RECONFIG_MORE - && batch.examined_count != 0; + return result == RESOURCE_X_RECONFIG_MORE && batch.examined_count != 0; } - if (!cluster_resource_x_reconfig_cutover_bind_native_successor_exact( - &token)) + if (!cluster_resource_x_reconfig_cutover_bind_native_successor_exact(&token)) return false; /* Binding is itself progress. Resume through the event loop so * no tick traverses more than one 64-slot checkpoint. */ return true; } - for (calls = 0; - calls < GCS_BLOCK_RESOURCE_X_RECONFIG_CALLS_PER_CHECKPOINT; - calls++) { + for (calls = 0; calls < GCS_BLOCK_RESOURCE_X_RECONFIG_CALLS_PER_CHECKPOINT; calls++) { result = cluster_resource_x_reconfig_sweep( - &token, GCS_BLOCK_RESOURCE_X_RECONFIG_PROBE_BUDGET, - &batch); + &token, GCS_BLOCK_RESOURCE_X_RECONFIG_PROBE_BUDGET, &batch); if (result == RESOURCE_X_RECONFIG_DONE) break; - if (result != RESOURCE_X_RECONFIG_MORE - && result != RESOURCE_X_RECONFIG_RETRY) + if (result != RESOURCE_X_RECONFIG_MORE && result != RESOURCE_X_RECONFIG_RETRY) return false; } if (result != RESOURCE_X_RECONFIG_DONE) { - return result == RESOURCE_X_RECONFIG_MORE - && batch.examined_count != 0; + return result == RESOURCE_X_RECONFIG_MORE && batch.examined_count != 0; } - if (!cluster_resource_x_reconfig_zero_proof_exact( - &token, &zero) - || !cluster_pcm_lock_resource_x_clean_completion_prove_exact( - &token, &zero, &clean) - || !cluster_pcm_lock_resource_x_cutover_proofs_exact( - &observed_token, &observed_zero, &observed_clean) + if (!cluster_resource_x_reconfig_zero_proof_exact(&token, &zero) + || !cluster_pcm_lock_resource_x_clean_completion_prove_exact(&token, &zero, &clean) + || !cluster_pcm_lock_resource_x_cutover_proofs_exact(&observed_token, &observed_zero, + &observed_clean) || memcmp(&observed_token, &token, sizeof(token)) != 0 || memcmp(&observed_zero, &zero, sizeof(zero)) != 0 || memcmp(&observed_clean, &clean, sizeof(clean)) != 0) @@ -23879,13 +22629,11 @@ cluster_gcs_block_resource_x_cutover_tick(void) return batch.examined_count != 0; } - if (cutover.phase - != CLUSTER_SEMANTIC_R11_CUTOVER_DURABLE_OPEN_PENDING_LOCAL - || !cluster_pcm_lock_resource_x_cutover_proofs_exact( - &token, &zero, &clean) + if (cutover.phase != CLUSTER_SEMANTIC_R11_CUTOVER_DURABLE_OPEN_PENDING_LOCAL + || !cluster_pcm_lock_resource_x_cutover_proofs_exact(&token, &zero, &clean) || !cluster_resource_x_reconfig_thaw_exact(&token) - || !cluster_pcm_lock_resource_x_cutover_thawed_proofs_exact( - &observed_token, &observed_zero, &observed_clean) + || !cluster_pcm_lock_resource_x_cutover_thawed_proofs_exact(&observed_token, &observed_zero, + &observed_clean) || memcmp(&observed_token, &token, sizeof(token)) != 0 || memcmp(&observed_zero, &zero, sizeof(zero)) != 0 || memcmp(&observed_clean, &clean, sizeof(clean)) != 0) @@ -23909,8 +22657,7 @@ gcs_block_resource_x_dead_requester_bitmap( } static bool -gcs_block_resource_x_reconfig_epoch(uint64 new_epoch, - uint32 dead_requester_bitmap) +gcs_block_resource_x_reconfig_epoch(uint64 new_epoch, uint32 dead_requester_bitmap) { ResourceXGateSnapshot gate; ResourceXReconfigBatch batch; @@ -23933,15 +22680,13 @@ gcs_block_resource_x_reconfig_epoch(uint64 new_epoch, return true; if (new_epoch == 0 || new_epoch == UINT64_MAX) return false; - completed_epoch - = pg_atomic_read_u64(&ClusterGcsBlock->resource_x_reconfig_completed_epoch); + completed_epoch = pg_atomic_read_u64(&ClusterGcsBlock->resource_x_reconfig_completed_epoch); if (new_epoch <= completed_epoch) return true; expected_epoch = 0; claimed_epoch = pg_atomic_compare_exchange_u64( - &ClusterGcsBlock->resource_x_reconfig_in_progress_epoch, &expected_epoch, - new_epoch); + &ClusterGcsBlock->resource_x_reconfig_in_progress_epoch, &expected_epoch, new_epoch); if (!claimed_epoch && expected_epoch != new_epoch) return false; deadline = GetCurrentTimestamp() @@ -23953,14 +22698,12 @@ gcs_block_resource_x_reconfig_epoch(uint64 new_epoch, } for (;;) { expected_actor = 0; - if (pg_atomic_compare_exchange_u64( - &ClusterGcsBlock->resource_x_reconfig_actor_active, &expected_actor, - new_epoch)) + if (pg_atomic_compare_exchange_u64(&ClusterGcsBlock->resource_x_reconfig_actor_active, + &expected_actor, new_epoch)) break; if (expected_actor != new_epoch) return false; - completed_epoch - = pg_atomic_read_u64(&ClusterGcsBlock->resource_x_reconfig_completed_epoch); + completed_epoch = pg_atomic_read_u64(&ClusterGcsBlock->resource_x_reconfig_completed_epoch); if (completed_epoch >= new_epoch) return true; if (GetCurrentTimestamp() >= deadline) @@ -23973,21 +22716,18 @@ gcs_block_resource_x_reconfig_epoch(uint64 new_epoch, if (!cluster_pcm_lock_resource_x_gate_snapshot(&gate)) { /* No target formation has ever opened, so there is no Resource-X * authority to sweep for this epoch. */ - pg_atomic_write_u64(&ClusterGcsBlock->resource_x_reconfig_completed_epoch, - new_epoch); + pg_atomic_write_u64(&ClusterGcsBlock->resource_x_reconfig_completed_epoch, new_epoch); pg_atomic_write_u64(&ClusterGcsBlock->resource_x_reconfig_old_formation, 0); pg_atomic_write_u64(&ClusterGcsBlock->resource_x_reconfig_in_progress_epoch, 0); pg_atomic_write_u64(&ClusterGcsBlock->resource_x_reconfig_actor_active, 0); return true; } if (claimed_epoch) - pg_atomic_write_u64(&ClusterGcsBlock->resource_x_reconfig_old_formation, - gate.formation); - expected_epoch - = pg_atomic_read_u64(&ClusterGcsBlock->resource_x_reconfig_old_formation); + pg_atomic_write_u64(&ClusterGcsBlock->resource_x_reconfig_old_formation, gate.formation); + expected_epoch = pg_atomic_read_u64(&ClusterGcsBlock->resource_x_reconfig_old_formation); if (expected_epoch == 0 - || !cluster_resource_x_reconfig_freeze_pending_exact( - expected_epoch, dead_requester_bitmap, &token)) + || !cluster_resource_x_reconfig_freeze_pending_exact(expected_epoch, dead_requester_bitmap, + &token)) goto actor_failed; deadline = GetCurrentTimestamp() @@ -24007,14 +22747,12 @@ gcs_block_resource_x_reconfig_epoch(uint64 new_epoch, } for (;;) { - for (calls = 0; calls < GCS_BLOCK_RESOURCE_X_RECONFIG_CALLS_PER_CHECKPOINT; - calls++) { + for (calls = 0; calls < GCS_BLOCK_RESOURCE_X_RECONFIG_CALLS_PER_CHECKPOINT; calls++) { result = cluster_resource_x_reconfig_sweep( &token, GCS_BLOCK_RESOURCE_X_RECONFIG_PROBE_BUDGET, &batch); if (result == RESOURCE_X_RECONFIG_DONE) goto complete; - if (result != RESOURCE_X_RECONFIG_MORE - && result != RESOURCE_X_RECONFIG_RETRY) + if (result != RESOURCE_X_RECONFIG_MORE && result != RESOURCE_X_RECONFIG_RETRY) goto actor_failed; } if (GetCurrentTimestamp() >= deadline) @@ -24024,10 +22762,9 @@ gcs_block_resource_x_reconfig_epoch(uint64 new_epoch, complete: if (!cluster_resource_x_reconfig_zero_proof_exact(&token, &zero) - || !cluster_pcm_lock_resource_x_clean_completion_prove_exact( - &token, &zero, &clean) - || !cluster_pcm_lock_resource_x_cutover_proofs_exact( - &observed_token, &observed_zero, &observed_clean) + || !cluster_pcm_lock_resource_x_clean_completion_prove_exact(&token, &zero, &clean) + || !cluster_pcm_lock_resource_x_cutover_proofs_exact(&observed_token, &observed_zero, + &observed_clean) || memcmp(&observed_token, &token, sizeof(token)) != 0 || memcmp(&observed_zero, &zero, sizeof(zero)) != 0 || memcmp(&observed_clean, &clean, sizeof(clean)) != 0 @@ -24074,16 +22811,14 @@ gcs_block_resource_x_reconfig_epoch(uint64 new_epoch, * ============================================================ */ void cluster_gcs_block_on_epoch_advance_exact( - uint64 new_epoch, - const uint8 dead_bitmap[CLUSTER_RECONFIG_DEAD_BITMAP_BYTES]) + uint64 new_epoch, const uint8 dead_bitmap[CLUSTER_RECONFIG_DEAD_BITMAP_BYTES]) { ResourceXReconfigStats resource_x_stats; uint32 dead_requester_bitmap; int b; int j; - dead_requester_bitmap - = gcs_block_resource_x_dead_requester_bitmap(dead_bitmap); + dead_requester_bitmap = gcs_block_resource_x_dead_requester_bitmap(dead_bitmap); if (!gcs_block_resource_x_reconfig_epoch(new_epoch, dead_requester_bitmap)) { gcs_block_resource_x_fail_closed_current(); cluster_resource_x_reconfig_stats_snapshot(&resource_x_stats); diff --git a/src/backend/cluster/cluster_gcs_block_dedup.c b/src/backend/cluster/cluster_gcs_block_dedup.c index 7a8fce25459..5c14258b247 100644 --- a/src/backend/cluster/cluster_gcs_block_dedup.c +++ b/src/backend/cluster/cluster_gcs_block_dedup.c @@ -87,9 +87,9 @@ typedef struct ClusterGcsBlockDedupShard { pg_atomic_uint64 done_marked_count; /* identity-verified DONE stamped */ pg_atomic_uint64 done_mismatch_count; /* DONE dropped: miss / identity / in-flight */ /* GCS-race round-2 review F5 (calibration 2): registration routing. */ - pg_atomic_uint64 hint_violation_count; /* capable peer, hint 0 / over-max: denied */ - pg_atomic_uint64 legacy_pin_count; /* no-capability peer: protocol-max pin */ - pg_atomic_uint32 entry_count; /* live in-flight + completed entries */ + pg_atomic_uint64 hint_violation_count; /* capable peer, hint 0 / over-max: denied */ + pg_atomic_uint64 legacy_pin_count; /* no-capability peer: protocol-max pin */ + pg_atomic_uint32 entry_count; /* live in-flight + completed entries */ } ClusterGcsBlockDedupShard; typedef struct ClusterGcsBlockDedupCtl { @@ -474,17 +474,13 @@ dedup_note_validation_failure(ClusterGcsBlockDedupShard *shard) } static bool -dedup_r4_route_proof_equal(const ClusterR4CrRouteProof *left, - const ClusterR4CrRouteProof *right) +dedup_r4_route_proof_equal(const ClusterR4CrRouteProof *left, const ClusterR4CrRouteProof *right) { - return left != NULL && right != NULL - && memcmp(&left->tag, &right->tag, sizeof(BufferTag)) == 0 - && left->read_scn == right->read_scn - && left->formation_epoch == right->formation_epoch + return left != NULL && right != NULL && memcmp(&left->tag, &right->tag, sizeof(BufferTag)) == 0 + && left->read_scn == right->read_scn && left->formation_epoch == right->formation_epoch && left->activation_generation == right->activation_generation && left->master_authority_generation == right->master_authority_generation - && left->master_resource_transition_count - == right->master_resource_transition_count + && left->master_resource_transition_count == right->master_resource_transition_count && left->expected_page_scn == right->expected_page_scn && left->real_master_node == right->real_master_node && left->selected_holder_node == right->selected_holder_node; @@ -492,8 +488,7 @@ dedup_r4_route_proof_equal(const ClusterR4CrRouteProof *left, static bool dedup_r4_route_identity_equal(const GcsBlockDedupEntry *entry, - const GcsBlockR4RouteIdentity *identity, - uint8 transition_id) + const GcsBlockR4RouteIdentity *identity, uint8 transition_id) { const ClusterR4CrRouteProof *stored = &entry->payload_meta.r4_route.proof; @@ -508,22 +503,18 @@ static bool dedup_r4_route_input_valid(const GcsBlockR4RouteIdentity *identity, uint8 transition_id, const ClusterR4CrRouteProof *proof) { - return identity != NULL && proof != NULL - && identity->legacy_key.request_id != 0 + return identity != NULL && proof != NULL && identity->legacy_key.request_id != 0 && identity->legacy_key.requester_backend_id > 0 && identity->legacy_key.origin_node_id < RESOURCE_X_PROTOCOL_NODE_LIMIT - && identity->activation_generation != 0 - && SCN_VALID(identity->read_scn) + && identity->activation_generation != 0 && SCN_VALID(identity->read_scn) && memcmp(&identity->tag, &proof->tag, sizeof(BufferTag)) == 0 && proof->read_scn == identity->read_scn && proof->formation_epoch == identity->legacy_key.cluster_epoch && proof->activation_generation == identity->activation_generation && (uint32)proof->master_authority_generation != 0 - && (uint32)(proof->master_authority_generation >> 32) - == (uint32)proof->formation_epoch + && (uint32)(proof->master_authority_generation >> 32) == (uint32)proof->formation_epoch && proof->master_resource_transition_count != 0 - && proof->master_resource_transition_count != UINT64_MAX - && proof->real_master_node >= 0 + && proof->master_resource_transition_count != UINT64_MAX && proof->real_master_node >= 0 && proof->real_master_node < RESOURCE_X_PROTOCOL_NODE_LIMIT && proof->selected_holder_node >= 0 && proof->selected_holder_node < RESOURCE_X_PROTOCOL_NODE_LIMIT; @@ -570,8 +561,8 @@ dedup_r4_route_reclaim_safe(const GcsBlockDedupEntry *entry, const instr_time *n if (now == NULL || !dedup_r4_route_anchor_load(anchor_slot, &anchor)) return false; - deadline_us = entry->pinned_lifetime_us > 0 ? entry->pinned_lifetime_us - : fallback_out_of_window_us; + deadline_us + = entry->pinned_lifetime_us > 0 ? entry->pinned_lifetime_us : fallback_out_of_window_us; /* R4 timestamps are monotonic anchors, including terminal DONE. A * completed requester no longer retransmits this physical request, but * retain its route through the same pinned quarantine as ordinary DONE. */ @@ -584,21 +575,17 @@ dedup_r4_route_reclaim_safe(const GcsBlockDedupEntry *entry, const instr_time *n INSTR_TIME_SUBTRACT(elapsed, anchor); if (INSTR_TIME_GET_NANOSEC(elapsed) < 0) return false; - return deadline_us > 0 - && INSTR_TIME_GET_MICROSEC(elapsed) > (uint64)deadline_us; + return deadline_us > 0 && INSTR_TIME_GET_MICROSEC(elapsed) > (uint64)deadline_us; } static bool dedup_entry_reclaim_safe(const GcsBlockDedupEntry *entry, TimestampTz wall_now, - const instr_time *route_now, - int64 fallback_out_of_window_us) + const instr_time *route_now, int64 fallback_out_of_window_us) { if (entry->entry_kind == GCS_BLOCK_DEDUP_ENTRY_GENERIC) - return GcsBlockDedupEntryIsReclaimSafe(entry, wall_now, - fallback_out_of_window_us); + return GcsBlockDedupEntryIsReclaimSafe(entry, wall_now, fallback_out_of_window_us); if (entry->entry_kind == GCS_BLOCK_DEDUP_ENTRY_R4_CR_ROUTE) - return dedup_r4_route_reclaim_safe(entry, route_now, - fallback_out_of_window_us); + return dedup_r4_route_reclaim_safe(entry, route_now, fallback_out_of_window_us); return false; } @@ -784,8 +771,7 @@ cluster_gcs_block_dedup_r4_route_arm_or_match( if (record_out != NULL) memset(record_out, 0, sizeof(*record_out)); - if (record_out == NULL - || !dedup_r4_route_input_valid(identity, transition_id, fresh_proof)) + if (record_out == NULL || !dedup_r4_route_input_valid(identity, transition_id, fresh_proof)) return GCS_BLOCK_R4_ROUTE_ARM_INVALID; if (lifetime_hint_trusted && (requester_lifetime_hint_ms == 0 @@ -833,12 +819,11 @@ cluster_gcs_block_dedup_r4_route_arm_or_match( result = GCS_BLOCK_R4_ROUTE_ARM_FULL; goto out; } - entry = (GcsBlockDedupEntry *)hash_search(htab, &identity->legacy_key, HASH_ENTER_NULL, - &found); + entry = (GcsBlockDedupEntry *)hash_search(htab, &identity->legacy_key, HASH_ENTER_NULL, &found); if (entry == NULL && dedup_reclaim_reclaimable_locked(shard, htab, GetCurrentTimestamp(), 1) > 0) - entry = (GcsBlockDedupEntry *)hash_search(htab, &identity->legacy_key, - HASH_ENTER_NULL, &found); + entry = (GcsBlockDedupEntry *)hash_search(htab, &identity->legacy_key, HASH_ENTER_NULL, + &found); if (entry == NULL) { result = GCS_BLOCK_R4_ROUTE_ARM_FULL; goto out; @@ -852,7 +837,7 @@ cluster_gcs_block_dedup_r4_route_arm_or_match( entry->payload_meta.r4_route.state = GCS_BLOCK_R4_ROUTE_ROUTING; dedup_r4_route_anchor_now(&entry->registered_at_ts); pinned_lifetime_ms = lifetime_hint_trusted ? (int64)requester_lifetime_hint_ms - : GCS_BLOCK_DEDUP_MAX_PROTOCOL_LIFETIME_MS; + : GCS_BLOCK_DEDUP_MAX_PROTOCOL_LIFETIME_MS; entry->pinned_lifetime_us = pinned_lifetime_ms * 1000 * 2; entry->pinned_done_linger_us = (int64)(cluster_gcs_reply_timeout_ms > 0 ? cluster_gcs_reply_timeout_ms : 5000) * 1000 @@ -867,9 +852,10 @@ cluster_gcs_block_dedup_r4_route_arm_or_match( } GcsBlockR4RouteSendResult -cluster_gcs_block_dedup_r4_route_finish_send( - int worker_id, const GcsBlockR4RouteIdentity *identity, uint8 transition_id, - const ClusterR4CrRouteProof *armed_proof, bool outbound_admitted) +cluster_gcs_block_dedup_r4_route_finish_send(int worker_id, const GcsBlockR4RouteIdentity *identity, + uint8 transition_id, + const ClusterR4CrRouteProof *armed_proof, + bool outbound_admitted) { ClusterGcsBlockDedupShard *shard; HTAB *htab = NULL; @@ -934,8 +920,7 @@ dedup_r4_route_remove_if(bool (*predicate)(const GcsBlockDedupEntry *, uint64), LWLockAcquire(&shard->lock.lock, LW_EXCLUSIVE); hash_seq_init(&scan, htab); while ((entry = (GcsBlockDedupEntry *)hash_seq_search(&scan)) != NULL) { - if (entry->entry_kind != GCS_BLOCK_DEDUP_ENTRY_R4_CR_ROUTE - || !predicate(entry, arg)) + if (entry->entry_kind != GCS_BLOCK_DEDUP_ENTRY_R4_CR_ROUTE || !predicate(entry, arg)) continue; (void)hash_search(htab, &entry->key, HASH_REMOVE, NULL); removed++; diff --git a/src/backend/cluster/cluster_gcs_block_shard.c b/src/backend/cluster/cluster_gcs_block_shard.c index 3a6dfc62946..a849942d53f 100644 --- a/src/backend/cluster/cluster_gcs_block_shard.c +++ b/src/backend/cluster/cluster_gcs_block_shard.c @@ -68,14 +68,13 @@ StaticAssertDecl(offsetof(GcsBlockInvalidateAckPayload, tag) == 16, StaticAssertDecl(offsetof(GcsBlockDonePayload, tag) == 16, "GCS-race round-2 review F4: GcsBlockDonePayload.tag offset moved"); static bool -cluster_resource_x_payload_route_tag(uint8 msg_type, const void *payload, - uint16 payload_len, BufferTag *tag) +cluster_resource_x_payload_route_tag(uint8 msg_type, const void *payload, uint16 payload_len, + BufferTag *tag) { ResourceXDecodedFrame decoded; ResourceXWireReject reject; - if (!cluster_resource_x_wire_decode(msg_type, payload, payload_len, - &decoded, &reject)) + if (!cluster_resource_x_wire_decode(msg_type, payload, payload_len, &decoded, &reject)) return false; *tag = decoded.common.logical_assertion.resource; return true; @@ -90,15 +89,15 @@ cluster_ctrc_route_get_u16_le(const uint8 *bytes) static uint32 cluster_ctrc_route_get_u32_le(const uint8 *bytes) { - return (uint32)bytes[0] | ((uint32)bytes[1] << 8) - | ((uint32)bytes[2] << 16) | ((uint32)bytes[3] << 24); + return (uint32)bytes[0] | ((uint32)bytes[1] << 8) | ((uint32)bytes[2] << 16) + | ((uint32)bytes[3] << 24); } static uint64 cluster_ctrc_route_get_u64_le(const uint8 *bytes) { return (uint64)cluster_ctrc_route_get_u32_le(bytes) - | ((uint64)cluster_ctrc_route_get_u32_le(bytes + 4) << 32); + | ((uint64)cluster_ctrc_route_get_u32_le(bytes + 4) << 32); } /* The full authenticated selector is checked by the receiving handler. The @@ -106,8 +105,7 @@ cluster_ctrc_route_get_u64_le(const uint8 *bytes) * to derive affinity, so a 136-byte collision cannot fall through to a * BufferTag route or split one request between workers. */ static bool -cluster_ctrc_payload_route_tag(const void *payload, uint16 payload_len, - BufferTag *tag) +cluster_ctrc_payload_route_tag(const void *payload, uint16 payload_len, BufferTag *tag) { const uint8 *bytes = (const uint8 *)payload; uint64 request_id; @@ -115,18 +113,13 @@ cluster_ctrc_payload_route_tag(const void *payload, uint16 payload_len, uint32 requester_node; uint32 requester_backend; - if (payload == NULL || tag == NULL - || payload_len != CLUSTER_CTRC_SEAL_REQUEST_BYTES + if (payload == NULL || tag == NULL || payload_len != CLUSTER_CTRC_SEAL_REQUEST_BYTES || cluster_ctrc_route_get_u16_le(bytes + 60) != 0 - || bytes[62] != CLUSTER_CTRC_SELECTOR_VERSION - || bytes[63] != CLUSTER_CTRC_FORWARD_KIND + || bytes[62] != CLUSTER_CTRC_SELECTOR_VERSION || bytes[63] != CLUSTER_CTRC_FORWARD_KIND || cluster_ctrc_route_get_u32_le(bytes + 64) != CLUSTER_CTRC_WIRE_MAGIC - || cluster_ctrc_route_get_u16_le(bytes + 68) - != CLUSTER_CTRC_WIRE_VERSION - || cluster_ctrc_route_get_u16_le(bytes + 70) - != CLUSTER_CTRC_SEAL_REQUEST_BYTES - || (bytes[55] != CTRC_SEAL_CLOSE_AND_CLEAN - && bytes[55] != CTRC_SEAL_CERTIFICATE_COMMITTED) + || cluster_ctrc_route_get_u16_le(bytes + 68) != CLUSTER_CTRC_WIRE_VERSION + || cluster_ctrc_route_get_u16_le(bytes + 70) != CLUSTER_CTRC_SEAL_REQUEST_BYTES + || (bytes[55] != CTRC_SEAL_CLOSE_AND_CLEAN && bytes[55] != CTRC_SEAL_CERTIFICATE_COMMITTED) || cluster_ctrc_route_get_u32_le(bytes + 128) == 0 || cluster_ctrc_route_get_u32_le(bytes + 132) != 0) return false; @@ -135,13 +128,12 @@ cluster_ctrc_payload_route_tag(const void *payload, uint16 payload_len, epoch = cluster_ctrc_route_get_u64_le(bytes + 8); requester_node = cluster_ctrc_route_get_u32_le(bytes + 36); requester_backend = cluster_ctrc_route_get_u32_le(bytes + 40); - if (request_id == 0 || epoch == 0 - || requester_node >= CLUSTER_CTRC_MAX_PARTICIPANTS + if (request_id == 0 || epoch == 0 || requester_node >= CLUSTER_CTRC_MAX_PARTICIPANTS || requester_backend != (uint32)CLUSTER_CTRC_INTERNAL_ENDPOINT) return false; - *tag = GcsBlockCurrentMxRouteTagMake(request_id, epoch, - (int32)requester_node, (int32)requester_backend); + *tag = GcsBlockCurrentMxRouteTagMake(request_id, epoch, (int32)requester_node, + (int32)requester_backend); return true; } @@ -160,8 +152,8 @@ cluster_gcs_block_payload_shard(uint8 msg_type, const void *payload, uint16 payl case PGRAC_IC_MSG_GCS_BLOCK_REQUEST: if (payload_len == RESOURCE_X_CONTROL_V1_BYTES || payload_len == RESOURCE_X_SHORT_V1_BYTES) { - if (!cluster_resource_x_payload_route_tag(msg_type, payload, - payload_len, &resource_x_tag)) + if (!cluster_resource_x_payload_route_tag(msg_type, payload, payload_len, + &resource_x_tag)) return -1; tag = &resource_x_tag; break; @@ -172,26 +164,22 @@ cluster_gcs_block_payload_shard(uint8 msg_type, const void *payload, uint16 payl tag = &((const GcsBlockRequestPayload *)payload)->tag; break; case PGRAC_IC_MSG_GCS_BLOCK_REPLY: - if (payload_len != RESOURCE_X_CONTROL_V1_BYTES - && payload_len != RESOURCE_X_PROOF_V1_BYTES + if (payload_len != RESOURCE_X_CONTROL_V1_BYTES && payload_len != RESOURCE_X_PROOF_V1_BYTES && payload_len != RESOURCE_X_IMAGE_V1_BYTES) return -1; - if (!cluster_resource_x_payload_route_tag(msg_type, payload, payload_len, - &resource_x_tag)) + if (!cluster_resource_x_payload_route_tag(msg_type, payload, payload_len, &resource_x_tag)) return -1; tag = &resource_x_tag; break; case PGRAC_IC_MSG_GCS_BLOCK_FORWARD: if (payload_len == CLUSTER_CTRC_SEAL_REQUEST_BYTES) { - if (!cluster_ctrc_payload_route_tag(payload, payload_len, - &route_tag)) + if (!cluster_ctrc_payload_route_tag(payload, payload_len, &route_tag)) return -1; tag = &route_tag; break; } if (payload_len == CLUSTER_CURRENT_MX_DESCRIBE_FORWARD_SIZE) { - const GcsBlockForwardPayload *current_mx - = (const GcsBlockForwardPayload *)payload; + const GcsBlockForwardPayload *current_mx = (const GcsBlockForwardPayload *)payload; const ClusterCurrentMxDescribeForwardV2 *frame = (const ClusterCurrentMxDescribeForwardV2 *)payload; @@ -200,10 +188,9 @@ cluster_gcs_block_payload_shard(uint8 msg_type, const void *payload, uint16 payl || frame->trailer.version != CLUSTER_CURRENT_MX_WIRE_VERSION || frame->trailer.flags != CLUSTER_CURRENT_MX_WIRE_FLAGS_NONE) return -1; - route_tag = GcsBlockCurrentMxRouteTagMake( - current_mx->request_id, current_mx->epoch, - current_mx->original_requester_node, - current_mx->requester_backend_id); + route_tag = GcsBlockCurrentMxRouteTagMake(current_mx->request_id, current_mx->epoch, + current_mx->original_requester_node, + current_mx->requester_backend_id); tag = &route_tag; break; } @@ -216,23 +203,20 @@ cluster_gcs_block_payload_shard(uint8 msg_type, const void *payload, uint16 payl * the positive backend id of the physical R4_CR reply slot. Every * other exact FORWARD96 retains the legacy tag shard. */ if (payload_len == sizeof(ClusterR4CrForwardPayload)) { - const ClusterR4CrForwardPayload *r4 - = (const ClusterR4CrForwardPayload *)payload; + const ClusterR4CrForwardPayload *r4 = (const ClusterR4CrForwardPayload *)payload; if (r4->extension.r4_version == CLUSTER_R4_WIRE_VERSION && (r4->extension.r4_kind == CLUSTER_R4_WIRE_TX_RESOLVE - || (r4->base.requester_backend_id - == CLUSTER_GCS_BLOCK_R4_INTERNAL_ENDPOINT - && r4->extension.r4_kind - == CLUSTER_R4_WIRE_UNDO_DATA_FETCH))) + || (r4->base.requester_backend_id == CLUSTER_GCS_BLOCK_R4_INTERNAL_ENDPOINT + && r4->extension.r4_kind == CLUSTER_R4_WIRE_UNDO_DATA_FETCH))) return n_workers > 0 ? 0 : -1; } tag = &((const GcsBlockForwardPayload *)payload)->tag; break; case PGRAC_IC_MSG_GCS_BLOCK_INVALIDATE: if (payload_len == RESOURCE_X_CONTROL_V1_BYTES) { - if (!cluster_resource_x_payload_route_tag(msg_type, payload, - payload_len, &resource_x_tag)) + if (!cluster_resource_x_payload_route_tag(msg_type, payload, payload_len, + &resource_x_tag)) return -1; tag = &resource_x_tag; break; @@ -244,8 +228,8 @@ cluster_gcs_block_payload_shard(uint8 msg_type, const void *payload, uint16 payl case PGRAC_IC_MSG_GCS_BLOCK_INVALIDATE_ACK: if (payload_len == RESOURCE_X_CONTROL_V1_BYTES || payload_len == RESOURCE_X_PROOF_V1_BYTES) { - if (!cluster_resource_x_payload_route_tag(msg_type, payload, - payload_len, &resource_x_tag)) + if (!cluster_resource_x_payload_route_tag(msg_type, payload, payload_len, + &resource_x_tag)) return -1; tag = &resource_x_tag; break; @@ -262,8 +246,8 @@ cluster_gcs_block_payload_shard(uint8 msg_type, const void *payload, uint16 payl * on the worker that owns the dedup entry. */ if (payload_len == RESOURCE_X_CONTROL_V1_BYTES || payload_len == RESOURCE_X_SHORT_V1_BYTES) { - if (!cluster_resource_x_payload_route_tag(msg_type, payload, - payload_len, &resource_x_tag)) + if (!cluster_resource_x_payload_route_tag(msg_type, payload, payload_len, + &resource_x_tag)) return -1; tag = &resource_x_tag; break; diff --git a/src/backend/cluster/cluster_ges.c b/src/backend/cluster/cluster_ges.c index 88ce0b6c1c5..120a1e9b7dd 100644 --- a/src/backend/cluster/cluster_ges.c +++ b/src/backend/cluster/cluster_ges.c @@ -58,8 +58,8 @@ #include "cluster/cluster_wal_retention.h" /* RF-ROOT P6 WALR conditional convert */ #include "cluster/cluster_ic_envelope.h" #include "cluster/cluster_ic_router.h" /* spec-5.8 D8 — cluster_ic_send_envelope (REPORT send-back) */ -#include "cluster/cluster_qvotec.h" /* cluster_qvotec_in_quorum */ -#include "cluster/cluster_conf.h" /* cluster_conf_lookup_node */ +#include "cluster/cluster_qvotec.h" /* cluster_qvotec_in_quorum */ +#include "cluster/cluster_conf.h" /* cluster_conf_lookup_node */ #include "cluster/cluster_replacement_wire.h" #include "cluster/cluster_sf_dep.h" #include "cluster/cluster_startup_phase.h" diff --git a/src/backend/cluster/cluster_ges_dedup.c b/src/backend/cluster/cluster_ges_dedup.c index 537dca5c688..adaaffceda1 100644 --- a/src/backend/cluster/cluster_ges_dedup.c +++ b/src/backend/cluster/cluster_ges_dedup.c @@ -385,8 +385,7 @@ cluster_ges_dedup_remove_completed(const ClusterGesDedupKey *key) return false; LWLockAcquire(cluster_ges_dedup_lock, LW_EXCLUSIVE); - entry = (ClusterGesDedupEntry *)hash_search(cluster_ges_dedup_htab, key, - HASH_FIND, &found); + entry = (ClusterGesDedupEntry *)hash_search(cluster_ges_dedup_htab, key, HASH_FIND, &found); if (found && entry != NULL && entry->cached_reply_len > 0) { (void)hash_search(cluster_ges_dedup_htab, key, HASH_REMOVE, &found); Assert(found); diff --git a/src/backend/cluster/cluster_ges_reply_wait.c b/src/backend/cluster/cluster_ges_reply_wait.c index af4b7aa934b..6fc9609ca5a 100644 --- a/src/backend/cluster/cluster_ges_reply_wait.c +++ b/src/backend/cluster/cluster_ges_reply_wait.c @@ -428,8 +428,7 @@ cluster_ges_reply_wait_deliver(const GesReplyWaitKey *key, uint32 reply_opcode, } GesReplyWaitPollResult -cluster_ges_reply_wait_poll_consume(const GesReplyWaitKey *key, - GesReplyWaitVerdict *verdict_out) +cluster_ges_reply_wait_poll_consume(const GesReplyWaitKey *key, GesReplyWaitVerdict *verdict_out) { GesReplyWaitEntry *entry; GesReplyWaitVerdict verdict; @@ -470,14 +469,12 @@ cluster_ges_reply_wait_poll_consume(const GesReplyWaitKey *key, } bool -cluster_ges_reply_wait_sleep_exact(const GesReplyWaitKey *key, long timeout_ms, - uint32 wait_event) +cluster_ges_reply_wait_sleep_exact(const GesReplyWaitKey *key, long timeout_ms, uint32 wait_event) { GesReplyWaitEntry *entry; bool ready; - if (key == NULL || timeout_ms <= 0 || reply_wait_state == NULL - || reply_wait_htab == NULL) + if (key == NULL || timeout_ms <= 0 || reply_wait_state == NULL || reply_wait_htab == NULL) return false; /* diff --git a/src/backend/cluster/cluster_grd.c b/src/backend/cluster/cluster_grd.c index b6d4e193746..906889518e5 100644 --- a/src/backend/cluster/cluster_grd.c +++ b/src/backend/cluster/cluster_grd.c @@ -51,15 +51,15 @@ #include "cluster/cluster_gcs_block.h" /* spec-4.7 D2 — block re-declare scan + send */ #include "cluster/cluster_signal.h" #include "cluster/cluster_shmem.h" -#include "cluster/cluster_cssd.h" /* spec-2.16 D8 newly-dead bitmap diff */ -#include "cluster/cluster_ic_tier1.h" /* cluster_ic_tier1_get_peer_fd (RF-ROOT P6 diag) */ -#include "cluster/cluster_epoch.h" /* spec-4.6 D1 — accepted epoch reads */ +#include "cluster/cluster_cssd.h" /* spec-2.16 D8 newly-dead bitmap diff */ +#include "cluster/cluster_ic_tier1.h" /* cluster_ic_tier1_get_peer_fd (RF-ROOT P6 diag) */ +#include "cluster/cluster_epoch.h" /* spec-4.6 D1 — accepted epoch reads */ #include "cluster/cluster_external_fence.h" /* STOP04 rejoin cleanup cut */ -#include "cluster/cluster_clean_leave.h" /* RF-ROOT P6: leaver write-refusal gate */ -#include "cluster/cluster_reconfig.h" /* spec-4.6 D1 — reconfig event consume */ +#include "cluster/cluster_clean_leave.h" /* RF-ROOT P6: leaver write-refusal gate */ +#include "cluster/cluster_reconfig.h" /* spec-4.6 D1 — reconfig event consume */ #include "cluster/cluster_qvotec.h" #include "cluster/cluster_recovery_duty.h" -#include "cluster/cluster_startup_phase.h" /* RF-ROOT P6 diag — cluster_current_phase */ +#include "cluster/cluster_startup_phase.h" /* RF-ROOT P6 diag — cluster_current_phase */ #include "cluster/cluster_thread_recovery.h" /* spec-4.11 D3 — unfreeze gate */ #include "cluster/cluster_undo_resid.h" /* spec-5.22a D1-5 — undo-class hash-route guard */ #include "storage/procsignal.h" /* spec-4.6 D3 — redeclare broadcast */ @@ -394,8 +394,8 @@ grd_wfg_cancel_snapshot_waiters(const GrdWfgSnapshot *snap) const GrdWfgWaiterSnap *w = &snap->waiters[i]; ClusterLmdVertex waiter_v; - grd_wfg_make_vertex(w->node_id, w->procno, w->cluster_epoch, w->request_id, - w->waiter_xid, w->wait_seq, &waiter_v); + grd_wfg_make_vertex(w->node_id, w->procno, w->cluster_epoch, w->request_id, w->waiter_xid, + w->wait_seq, &waiter_v); cluster_lmd_cancel_wait_edge_real(&waiter_v); } } @@ -809,40 +809,24 @@ cluster_grd_shmem_init(void) dlist_init(&cluster_grd_state->entry_shard_lists[i]); } pg_atomic_init_u32(&cluster_grd_state->master_map_initialized, 0); - pg_atomic_init_u64( - &cluster_grd_state->recovery_authority_request_sequence, 0); - pg_atomic_init_u64( - &cluster_grd_state->recovery_authority_request_generation, 0); - pg_atomic_init_u64( - &cluster_grd_state->recovery_authority_cancel_generation, 0); - pg_atomic_init_u64( - &cluster_grd_state->recovery_authority_terminal_generation, 0); - pg_atomic_init_u32( - &cluster_grd_state->recovery_authority_terminal_result, 0); - pg_atomic_init_u64( - &cluster_grd_state->recovery_authority_request_boot_incarnation, 0); - pg_atomic_init_u64( - &cluster_grd_state->recovery_authority_request_lms_generation, 0); - pg_atomic_init_u64( - &cluster_grd_state->recovery_authority_request_master_refresh, 0); - pg_atomic_init_u64( - &cluster_grd_state->recovery_authority_boot_incarnation, 0); - pg_atomic_init_u64( - &cluster_grd_state->recovery_authority_lms_generation, 0); - pg_atomic_init_u64( - &cluster_grd_state->recovery_authority_master_refresh, 0); - pg_atomic_init_u64( - &cluster_grd_state->recovery_authority_formation_epoch, 0); - pg_atomic_init_u64( - &cluster_grd_state->recovery_authority_bitmap_hash, 0); + pg_atomic_init_u64(&cluster_grd_state->recovery_authority_request_sequence, 0); + pg_atomic_init_u64(&cluster_grd_state->recovery_authority_request_generation, 0); + pg_atomic_init_u64(&cluster_grd_state->recovery_authority_cancel_generation, 0); + pg_atomic_init_u64(&cluster_grd_state->recovery_authority_terminal_generation, 0); + pg_atomic_init_u32(&cluster_grd_state->recovery_authority_terminal_result, 0); + pg_atomic_init_u64(&cluster_grd_state->recovery_authority_request_boot_incarnation, 0); + pg_atomic_init_u64(&cluster_grd_state->recovery_authority_request_lms_generation, 0); + pg_atomic_init_u64(&cluster_grd_state->recovery_authority_request_master_refresh, 0); + pg_atomic_init_u64(&cluster_grd_state->recovery_authority_boot_incarnation, 0); + pg_atomic_init_u64(&cluster_grd_state->recovery_authority_lms_generation, 0); + pg_atomic_init_u64(&cluster_grd_state->recovery_authority_master_refresh, 0); + pg_atomic_init_u64(&cluster_grd_state->recovery_authority_formation_epoch, 0); + pg_atomic_init_u64(&cluster_grd_state->recovery_authority_bitmap_hash, 0); for (i = 0; i < 2; i++) - pg_atomic_init_u64( - &cluster_grd_state->recovery_authority_members[i], 0); + pg_atomic_init_u64(&cluster_grd_state->recovery_authority_members[i], 0); for (i = 0; i < CLUSTER_MAX_NODES; i++) { - pg_atomic_init_u64( - &cluster_grd_state->recovery_authority_done_epoch[i], 0); - pg_atomic_init_u64( - &cluster_grd_state->recovery_authority_done_hash[i], 0); + pg_atomic_init_u64(&cluster_grd_state->recovery_authority_done_epoch[i], 0); + pg_atomic_init_u64(&cluster_grd_state->recovery_authority_done_hash[i], 0); } pg_atomic_init_u64(&cluster_grd_state->resid_encode_count, 0); pg_atomic_init_u64(&cluster_grd_state->shard_lookup_count, 0); @@ -1271,8 +1255,7 @@ cluster_grd_is_local_master(uint32 shard_id) } static bool -cluster_grd_authority_member(uint64 members_lo, uint64 members_hi, - int32 node) +cluster_grd_authority_member(uint64 members_lo, uint64 members_hi, int32 node) { if (node < 0 || node >= CLUSTER_MAX_NODES) return false; @@ -1281,32 +1264,27 @@ cluster_grd_authority_member(uint64 members_lo, uint64 members_hi, } static bool -cluster_grd_authority_map_is_current(uint64 refresh, uint64 members_lo, - uint64 members_hi) +cluster_grd_authority_map_is_current(uint64 refresh, uint64 members_lo, uint64 members_hi) { uint32 shard; if (cluster_grd_state == NULL || cluster_grd_entry_htab == NULL || pg_atomic_read_u32(&cluster_grd_state->master_map_initialized) == 0 - || pg_atomic_read_u64(&cluster_grd_state->master_map_refresh_count) - != refresh) + || pg_atomic_read_u64(&cluster_grd_state->master_map_refresh_count) != refresh) return false; for (shard = 0; shard < PGRAC_GRD_SHARD_COUNT; shard++) { - int32 master - = (int32)pg_atomic_read_u32(&cluster_grd_state->master[shard]); + int32 master = (int32)pg_atomic_read_u32(&cluster_grd_state->master[shard]); if (!cluster_grd_authority_member(members_lo, members_hi, master) || pg_atomic_read_u32(&cluster_grd_state->shard_phase[shard]) != (uint32)GRD_SHARD_NORMAL) return false; } - return pg_atomic_read_u64(&cluster_grd_state->master_map_refresh_count) - == refresh; + return pg_atomic_read_u64(&cluster_grd_state->master_map_refresh_count) == refresh; } bool -cluster_grd_recovery_authority_is_current(uint64 boot_incarnation, - uint64 lms_generation) +cluster_grd_recovery_authority_is_current(uint64 boot_incarnation, uint64 lms_generation) { uint64 refresh; uint64 epoch; @@ -1315,44 +1293,29 @@ cluster_grd_recovery_authority_is_current(uint64 boot_incarnation, uint64 members_hi; int i; - if (cluster_grd_state == NULL || boot_incarnation == 0 - || lms_generation == 0 - || pg_atomic_read_u64( - &cluster_grd_state->recovery_authority_boot_incarnation) + if (cluster_grd_state == NULL || boot_incarnation == 0 || lms_generation == 0 + || pg_atomic_read_u64(&cluster_grd_state->recovery_authority_boot_incarnation) != boot_incarnation - || pg_atomic_read_u64( - &cluster_grd_state->recovery_authority_lms_generation) + || pg_atomic_read_u64(&cluster_grd_state->recovery_authority_lms_generation) != lms_generation - || !cluster_qvotec_in_quorum() - || cluster_qvotec_get_self_incarnation() != boot_incarnation + || !cluster_qvotec_in_quorum() || cluster_qvotec_get_self_incarnation() != boot_incarnation || !cluster_membership_is_member(cluster_node_id) - || cluster_membership_get_last_admitted_incarnation(cluster_node_id) - != boot_incarnation) + || cluster_membership_get_last_admitted_incarnation(cluster_node_id) != boot_incarnation) return false; - refresh = pg_atomic_read_u64( - &cluster_grd_state->recovery_authority_master_refresh); - epoch = pg_atomic_read_u64( - &cluster_grd_state->recovery_authority_formation_epoch); - bitmap_hash = pg_atomic_read_u64( - &cluster_grd_state->recovery_authority_bitmap_hash); - members_lo = pg_atomic_read_u64( - &cluster_grd_state->recovery_authority_members[0]); - members_hi = pg_atomic_read_u64( - &cluster_grd_state->recovery_authority_members[1]); - if (refresh == 0 || bitmap_hash == 0 - || cluster_epoch_get_current() != epoch - || !cluster_grd_authority_map_is_current( - refresh, members_lo, members_hi)) + refresh = pg_atomic_read_u64(&cluster_grd_state->recovery_authority_master_refresh); + epoch = pg_atomic_read_u64(&cluster_grd_state->recovery_authority_formation_epoch); + bitmap_hash = pg_atomic_read_u64(&cluster_grd_state->recovery_authority_bitmap_hash); + members_lo = pg_atomic_read_u64(&cluster_grd_state->recovery_authority_members[0]); + members_hi = pg_atomic_read_u64(&cluster_grd_state->recovery_authority_members[1]); + if (refresh == 0 || bitmap_hash == 0 || cluster_epoch_get_current() != epoch + || !cluster_grd_authority_map_is_current(refresh, members_lo, members_hi)) return false; for (i = 0; i < CLUSTER_MAX_NODES; i++) { if (!cluster_grd_authority_member(members_lo, members_hi, i)) continue; if (!cluster_membership_is_member(i) - || pg_atomic_read_u64( - &cluster_grd_state->recovery_authority_done_epoch[i]) - != epoch - || pg_atomic_read_u64( - &cluster_grd_state->recovery_authority_done_hash[i]) + || pg_atomic_read_u64(&cluster_grd_state->recovery_authority_done_epoch[i]) != epoch + || pg_atomic_read_u64(&cluster_grd_state->recovery_authority_done_hash[i]) != bitmap_hash) return false; } @@ -1364,9 +1327,8 @@ cluster_grd_recovery_authority_is_current(uint64 boot_incarnation, * to reseal the same boot/LMS serving generation. This never starts a second * redeclare episode and never changes GRD/GES ownership. */ bool -cluster_grd_serving_authority_rebind_lmon( - const ClusterFormationSnapshotV1 *formation, uint64 boot_incarnation, - uint64 lms_generation) +cluster_grd_serving_authority_rebind_lmon(const ClusterFormationSnapshotV1 *formation, + uint64 boot_incarnation, uint64 lms_generation) { uint64 bitmap_hash; uint64 epoch; @@ -1380,33 +1342,26 @@ cluster_grd_serving_authority_rebind_lmon( || cluster_grd_recovery_in_progress() || pg_atomic_read_u32(&cluster_grd_state->recovery_direction) != (uint32)GRD_REMASTER_DIR_NONE - || !cluster_qvotec_in_quorum() - || cluster_qvotec_get_self_incarnation() != boot_incarnation + || !cluster_qvotec_in_quorum() || cluster_qvotec_get_self_incarnation() != boot_incarnation || cluster_lms_get_lms_restart_generation() != lms_generation || !cluster_membership_is_member(cluster_node_id) - || cluster_membership_get_last_admitted_incarnation(cluster_node_id) - != boot_incarnation) + || cluster_membership_get_last_admitted_incarnation(cluster_node_id) != boot_incarnation) return false; epoch = formation->local_epoch; - if (formation->applied.event_id == 0 - || epoch != formation->applied.new_epoch + if (formation->applied.event_id == 0 || epoch != formation->applied.new_epoch || epoch != cluster_epoch_get_current() || pg_atomic_read_u64(&cluster_grd_state->recovery_last_event_id) != formation->applied.event_id - || pg_atomic_read_u64(&cluster_grd_state->recovery_episode_epoch) - != epoch) { + || pg_atomic_read_u64(&cluster_grd_state->recovery_episode_epoch) != epoch) { return false; } for (i = 0; i < CLUSTER_MAX_NODES; i++) { - bool formation_member - = formation->membership.membership_state[i] - == CLUSTER_MEMBER_MEMBER; + bool formation_member = formation->membership.membership_state[i] == CLUSTER_MEMBER_MEMBER; if (formation_member - && (cluster_conf_lookup_node(i) == NULL - || !cluster_membership_is_member(i))) + && (cluster_conf_lookup_node(i) == NULL || !cluster_membership_is_member(i))) return false; if (!formation_member && cluster_conf_lookup_node(i) != NULL && cluster_membership_is_member(i)) @@ -1418,19 +1373,14 @@ cluster_grd_serving_authority_rebind_lmon( else members_hi |= UINT64_C(1) << (i - 64); } - if (!cluster_grd_authority_member( - members_lo, members_hi, cluster_node_id)) + if (!cluster_grd_authority_member(members_lo, members_hi, cluster_node_id)) return false; - refresh = pg_atomic_read_u64( - &cluster_grd_state->master_map_refresh_count); - bitmap_hash = cluster_grd_dead_bitmap_hash( - formation->applied.dead_bitmap); + refresh = pg_atomic_read_u64(&cluster_grd_state->master_map_refresh_count); + bitmap_hash = cluster_grd_dead_bitmap_hash(formation->applied.dead_bitmap); if (refresh == 0 || bitmap_hash == 0 - || pg_atomic_read_u64( - &cluster_grd_state->recovery_event_bitmap_hash) != bitmap_hash - || !cluster_grd_authority_map_is_current( - refresh, members_lo, members_hi)) { + || pg_atomic_read_u64(&cluster_grd_state->recovery_event_bitmap_hash) != bitmap_hash + || !cluster_grd_authority_map_is_current(refresh, members_lo, members_hi)) { return false; } for (i = 0; i < CLUSTER_MAX_NODES; i++) { @@ -1454,11 +1404,8 @@ cluster_grd_serving_authority_rebind_lmon( /* A JOIN recipient held no pre-episode grants to re-declare; the * ordinary P6 gate deliberately excludes it. Every survivor still * needs the exact composite DONE key. */ - if ((pg_atomic_read_u64( - &cluster_grd_state->recovery_done_epoch[i]) != epoch - || pg_atomic_read_u64( - &cluster_grd_state->recovery_done_bitmap_hash[i]) - != bitmap_hash) + if ((pg_atomic_read_u64(&cluster_grd_state->recovery_done_epoch[i]) != epoch + || pg_atomic_read_u64(&cluster_grd_state->recovery_done_bitmap_hash[i]) != bitmap_hash) && !join_fence_is_recipient_for(i, epoch)) { return false; } @@ -1469,36 +1416,24 @@ cluster_grd_serving_authority_rebind_lmon( * field and synthetic authority-DONE slot is complete. */ grd_recovery_authority_clear_seal(); pg_write_barrier(); - pg_atomic_write_u64( - &cluster_grd_state->recovery_authority_formation_epoch, epoch); - pg_atomic_write_u64( - &cluster_grd_state->recovery_authority_bitmap_hash, bitmap_hash); - pg_atomic_write_u64( - &cluster_grd_state->recovery_authority_members[0], members_lo); - pg_atomic_write_u64( - &cluster_grd_state->recovery_authority_members[1], members_hi); + pg_atomic_write_u64(&cluster_grd_state->recovery_authority_formation_epoch, epoch); + pg_atomic_write_u64(&cluster_grd_state->recovery_authority_bitmap_hash, bitmap_hash); + pg_atomic_write_u64(&cluster_grd_state->recovery_authority_members[0], members_lo); + pg_atomic_write_u64(&cluster_grd_state->recovery_authority_members[1], members_hi); for (i = 0; i < CLUSTER_MAX_NODES; i++) { bool member = cluster_grd_authority_member(members_lo, members_hi, i); - pg_atomic_write_u64( - &cluster_grd_state->recovery_authority_done_epoch[i], - member ? epoch : 0); - pg_atomic_write_u64( - &cluster_grd_state->recovery_authority_done_hash[i], - member ? bitmap_hash : 0); + pg_atomic_write_u64(&cluster_grd_state->recovery_authority_done_epoch[i], + member ? epoch : 0); + pg_atomic_write_u64(&cluster_grd_state->recovery_authority_done_hash[i], + member ? bitmap_hash : 0); } - pg_atomic_write_u64( - &cluster_grd_state->recovery_authority_master_refresh, refresh); + pg_atomic_write_u64(&cluster_grd_state->recovery_authority_master_refresh, refresh); pg_write_barrier(); - pg_atomic_write_u64( - &cluster_grd_state->recovery_authority_boot_incarnation, - boot_incarnation); - pg_atomic_write_u64( - &cluster_grd_state->recovery_authority_lms_generation, - lms_generation); - - if (!cluster_grd_recovery_authority_is_current( - boot_incarnation, lms_generation)) { + pg_atomic_write_u64(&cluster_grd_state->recovery_authority_boot_incarnation, boot_incarnation); + pg_atomic_write_u64(&cluster_grd_state->recovery_authority_lms_generation, lms_generation); + + if (!cluster_grd_recovery_authority_is_current(boot_incarnation, lms_generation)) { grd_recovery_authority_clear_seal(); return false; } @@ -1524,9 +1459,8 @@ cluster_grd_serving_authority_rebind_lmon( * and a current, NORMAL-shard master map. */ bool -cluster_grd_serving_authority_rebind_leaver( - const ClusterFormationSnapshotV1 *formation, uint64 boot_incarnation, - uint64 lms_generation) +cluster_grd_serving_authority_rebind_leaver(const ClusterFormationSnapshotV1 *formation, + uint64 boot_incarnation, uint64 lms_generation) { uint64 bitmap_hash; uint64 epoch; @@ -1537,12 +1471,10 @@ cluster_grd_serving_authority_rebind_leaver( if (formation == NULL || boot_incarnation == 0 || lms_generation == 0 || cluster_grd_state == NULL || cluster_grd_entry_htab == NULL - || !cluster_qvotec_in_quorum() - || cluster_qvotec_get_self_incarnation() != boot_incarnation + || !cluster_qvotec_in_quorum() || cluster_qvotec_get_self_incarnation() != boot_incarnation || cluster_lms_get_lms_restart_generation() != lms_generation || !cluster_membership_is_member(cluster_node_id) - || cluster_membership_get_last_admitted_incarnation(cluster_node_id) - != boot_incarnation) { + || cluster_membership_get_last_admitted_incarnation(cluster_node_id) != boot_incarnation) { return false; } @@ -1556,21 +1488,17 @@ cluster_grd_serving_authority_rebind_leaver( * from REQUESTED through COMMITTED, exactly the committed shutdown * window this rebind serves. */ - if (!cluster_clean_leave_node_refuses_writes() - || formation->local_epoch == 0 + if (!cluster_clean_leave_node_refuses_writes() || formation->local_epoch == 0 || formation->local_epoch != cluster_epoch_get_current()) { return false; } epoch = formation->local_epoch; for (i = 0; i < CLUSTER_MAX_NODES; i++) { - bool formation_member - = formation->membership.membership_state[i] - == CLUSTER_MEMBER_MEMBER; + bool formation_member = formation->membership.membership_state[i] == CLUSTER_MEMBER_MEMBER; if (formation_member - && (cluster_conf_lookup_node(i) == NULL - || !cluster_membership_is_member(i))) + && (cluster_conf_lookup_node(i) == NULL || !cluster_membership_is_member(i))) return false; if (!formation_member && cluster_conf_lookup_node(i) != NULL && cluster_membership_is_member(i)) @@ -1582,17 +1510,13 @@ cluster_grd_serving_authority_rebind_leaver( else members_hi |= UINT64_C(1) << (i - 64); } - if (!cluster_grd_authority_member( - members_lo, members_hi, cluster_node_id)) + if (!cluster_grd_authority_member(members_lo, members_hi, cluster_node_id)) return false; - refresh = pg_atomic_read_u64( - &cluster_grd_state->master_map_refresh_count); - bitmap_hash = cluster_grd_dead_bitmap_hash( - formation->applied.dead_bitmap); + refresh = pg_atomic_read_u64(&cluster_grd_state->master_map_refresh_count); + bitmap_hash = cluster_grd_dead_bitmap_hash(formation->applied.dead_bitmap); if (refresh == 0 || bitmap_hash == 0 - || !cluster_grd_authority_map_is_current( - refresh, members_lo, members_hi)) { + || !cluster_grd_authority_map_is_current(refresh, members_lo, members_hi)) { return false; } @@ -1600,36 +1524,24 @@ cluster_grd_serving_authority_rebind_leaver( * survivor rebind above). */ grd_recovery_authority_clear_seal(); pg_write_barrier(); - pg_atomic_write_u64( - &cluster_grd_state->recovery_authority_formation_epoch, epoch); - pg_atomic_write_u64( - &cluster_grd_state->recovery_authority_bitmap_hash, bitmap_hash); - pg_atomic_write_u64( - &cluster_grd_state->recovery_authority_members[0], members_lo); - pg_atomic_write_u64( - &cluster_grd_state->recovery_authority_members[1], members_hi); + pg_atomic_write_u64(&cluster_grd_state->recovery_authority_formation_epoch, epoch); + pg_atomic_write_u64(&cluster_grd_state->recovery_authority_bitmap_hash, bitmap_hash); + pg_atomic_write_u64(&cluster_grd_state->recovery_authority_members[0], members_lo); + pg_atomic_write_u64(&cluster_grd_state->recovery_authority_members[1], members_hi); for (i = 0; i < CLUSTER_MAX_NODES; i++) { bool member = cluster_grd_authority_member(members_lo, members_hi, i); - pg_atomic_write_u64( - &cluster_grd_state->recovery_authority_done_epoch[i], - member ? epoch : 0); - pg_atomic_write_u64( - &cluster_grd_state->recovery_authority_done_hash[i], - member ? bitmap_hash : 0); + pg_atomic_write_u64(&cluster_grd_state->recovery_authority_done_epoch[i], + member ? epoch : 0); + pg_atomic_write_u64(&cluster_grd_state->recovery_authority_done_hash[i], + member ? bitmap_hash : 0); } - pg_atomic_write_u64( - &cluster_grd_state->recovery_authority_master_refresh, refresh); + pg_atomic_write_u64(&cluster_grd_state->recovery_authority_master_refresh, refresh); pg_write_barrier(); - pg_atomic_write_u64( - &cluster_grd_state->recovery_authority_boot_incarnation, - boot_incarnation); - pg_atomic_write_u64( - &cluster_grd_state->recovery_authority_lms_generation, - lms_generation); - - if (!cluster_grd_recovery_authority_is_current( - boot_incarnation, lms_generation)) { + pg_atomic_write_u64(&cluster_grd_state->recovery_authority_boot_incarnation, boot_incarnation); + pg_atomic_write_u64(&cluster_grd_state->recovery_authority_lms_generation, lms_generation); + + if (!cluster_grd_recovery_authority_is_current(boot_incarnation, lms_generation)) { grd_recovery_authority_clear_seal(); return false; } @@ -2345,16 +2257,16 @@ static bool grd_recovery_event_is_terminal(uint8 reconfig_kind) { switch ((ClusterReconfigKind)reconfig_kind) { - case RECONFIG_KIND_FAIL_STOP: - case RECONFIG_KIND_CLEAN_LEAVE: - case RECONFIG_KIND_JOIN_COMMITTED: - case RECONFIG_KIND_NODE_REMOVED: - case RECONFIG_KIND_REPLACEMENT_COMMITTED: - return true; - case RECONFIG_KIND_NONE: - case RECONFIG_KIND_JOIN_PENDING: - default: - return false; + case RECONFIG_KIND_FAIL_STOP: + case RECONFIG_KIND_CLEAN_LEAVE: + case RECONFIG_KIND_JOIN_COMMITTED: + case RECONFIG_KIND_NODE_REMOVED: + case RECONFIG_KIND_REPLACEMENT_COMMITTED: + return true; + case RECONFIG_KIND_NONE: + case RECONFIG_KIND_JOIN_PENDING: + default: + return false; } } @@ -2772,8 +2684,7 @@ grd_recovery_broadcast_done(uint64 epoch) * dead-bitmap hash (cross-node convergence key), riding the request-id * field pair — NOT the sender-local event_id. */ grd_recovery_broadcast_done_key( - epoch, - pg_atomic_read_u64(&cluster_grd_state->recovery_event_bitmap_hash)); + epoch, pg_atomic_read_u64(&cluster_grd_state->recovery_event_bitmap_hash)); } /* REDECLARE_DONE receiver (cluster_ges.c inbound handler). */ @@ -2852,15 +2763,12 @@ cluster_grd_recovery_mark_peer_done(int32 node, uint64 epoch, uint64 dead_bitmap * startup authority convergence in separate accounting slots, so it * cannot forge or regress the ordinary remaster FSM's done arrays. */ if (dead_bitmap_hash != 0 - && epoch == pg_atomic_read_u64( - &cluster_grd_state->recovery_authority_formation_epoch) - && dead_bitmap_hash == pg_atomic_read_u64( - &cluster_grd_state->recovery_authority_bitmap_hash)) { - pg_atomic_write_u64( - &cluster_grd_state->recovery_authority_done_epoch[node], epoch); - pg_atomic_write_u64( - &cluster_grd_state->recovery_authority_done_hash[node], - dead_bitmap_hash); + && epoch == pg_atomic_read_u64(&cluster_grd_state->recovery_authority_formation_epoch) + && dead_bitmap_hash + == pg_atomic_read_u64(&cluster_grd_state->recovery_authority_bitmap_hash)) { + pg_atomic_write_u64(&cluster_grd_state->recovery_authority_done_epoch[node], epoch); + pg_atomic_write_u64(&cluster_grd_state->recovery_authority_done_hash[node], + dead_bitmap_hash); } episode_bitmap_hash = pg_atomic_read_u64(&cluster_grd_state->recovery_event_bitmap_hash); @@ -2905,21 +2813,19 @@ cluster_grd_recovery_mark_peer_done(int32 node, uint64 epoch, uint64 dead_bitmap * existing broadcasts use. */ { - uint64 fsm_epoch = pg_atomic_read_u64( - &cluster_grd_state->recovery_done_epoch[cluster_node_id]); - uint64 fsm_hash = pg_atomic_read_u64( - &cluster_grd_state->recovery_done_bitmap_hash[cluster_node_id]); + uint64 fsm_epoch + = pg_atomic_read_u64(&cluster_grd_state->recovery_done_epoch[cluster_node_id]); + uint64 fsm_hash + = pg_atomic_read_u64(&cluster_grd_state->recovery_done_bitmap_hash[cluster_node_id]); uint64 auth_epoch = pg_atomic_read_u64( &cluster_grd_state->recovery_authority_done_epoch[cluster_node_id]); - uint64 auth_hash = pg_atomic_read_u64( - &cluster_grd_state->recovery_authority_done_hash[cluster_node_id]); + uint64 auth_hash + = pg_atomic_read_u64(&cluster_grd_state->recovery_authority_done_hash[cluster_node_id]); if ((epoch == fsm_epoch && dead_bitmap_hash == fsm_hash) - || (epoch == auth_epoch && dead_bitmap_hash == auth_hash)) - { + || (epoch == auth_epoch && dead_bitmap_hash == auth_hash)) { if (epoch != grd_recovery_done_echo_epoch[node] - || dead_bitmap_hash != grd_recovery_done_echo_hash[node]) - { + || dead_bitmap_hash != grd_recovery_done_echo_hash[node]) { grd_recovery_done_echo_epoch[node] = epoch; grd_recovery_done_echo_hash[node] = dead_bitmap_hash; grd_recovery_broadcast_done_key(epoch, dead_bitmap_hash); @@ -2949,12 +2855,9 @@ static uint64 grd_recovery_authority_lmon_redeclare_generation = 0; static void grd_recovery_authority_clear_seal(void) { - pg_atomic_write_u64( - &cluster_grd_state->recovery_authority_boot_incarnation, 0); - pg_atomic_write_u64( - &cluster_grd_state->recovery_authority_lms_generation, 0); - pg_atomic_write_u64( - &cluster_grd_state->recovery_authority_master_refresh, 0); + pg_atomic_write_u64(&cluster_grd_state->recovery_authority_boot_incarnation, 0); + pg_atomic_write_u64(&cluster_grd_state->recovery_authority_lms_generation, 0); + pg_atomic_write_u64(&cluster_grd_state->recovery_authority_master_refresh, 0); } static bool @@ -2969,26 +2872,20 @@ grd_recovery_authority_request_current(uint64 request_generation) int i; if (request_generation == 0 || cluster_grd_state == NULL - || pg_atomic_read_u64( - &cluster_grd_state->recovery_authority_request_generation) + || pg_atomic_read_u64(&cluster_grd_state->recovery_authority_request_generation) != request_generation - || pg_atomic_read_u64( - &cluster_grd_state->recovery_authority_cancel_generation) + || pg_atomic_read_u64(&cluster_grd_state->recovery_authority_cancel_generation) >= request_generation) return false; pg_read_barrier(); - boot_incarnation = pg_atomic_read_u64( - &cluster_grd_state->recovery_authority_request_boot_incarnation); - lms_generation = pg_atomic_read_u64( - &cluster_grd_state->recovery_authority_request_lms_generation); - refresh = pg_atomic_read_u64( - &cluster_grd_state->recovery_authority_request_master_refresh); - epoch = pg_atomic_read_u64( - &cluster_grd_state->recovery_authority_formation_epoch); - members_lo = pg_atomic_read_u64( - &cluster_grd_state->recovery_authority_members[0]); - members_hi = pg_atomic_read_u64( - &cluster_grd_state->recovery_authority_members[1]); + boot_incarnation + = pg_atomic_read_u64(&cluster_grd_state->recovery_authority_request_boot_incarnation); + lms_generation + = pg_atomic_read_u64(&cluster_grd_state->recovery_authority_request_lms_generation); + refresh = pg_atomic_read_u64(&cluster_grd_state->recovery_authority_request_master_refresh); + epoch = pg_atomic_read_u64(&cluster_grd_state->recovery_authority_formation_epoch); + members_lo = pg_atomic_read_u64(&cluster_grd_state->recovery_authority_members[0]); + members_hi = pg_atomic_read_u64(&cluster_grd_state->recovery_authority_members[1]); { bool boot_ok = boot_incarnation != 0; bool lmsgen_ok = lms_generation != 0; @@ -2997,27 +2894,19 @@ grd_recovery_authority_request_current(uint64 request_generation) bool progress_ok = !cluster_grd_recovery_in_progress(); bool cssd_ok = cluster_cssd_get_status() == CLUSTER_CSSD_READY; bool quorum_ok = cluster_qvotec_in_quorum(); - bool inc_ok = cluster_qvotec_get_self_incarnation() - == boot_incarnation; - bool lms_match_ok = cluster_lms_get_lms_restart_generation() - == lms_generation; + bool inc_ok = cluster_qvotec_get_self_incarnation() == boot_incarnation; + bool lms_match_ok = cluster_lms_get_lms_restart_generation() == lms_generation; bool admitted_ok - = cluster_membership_get_last_admitted_incarnation( - cluster_node_id) - == boot_incarnation; - bool selfmember_ok = cluster_grd_authority_member( - members_lo, members_hi, cluster_node_id); - bool map_ok = cluster_grd_authority_map_is_current( - refresh, members_lo, members_hi); - - if (!(boot_ok && lmsgen_ok && refresh_ok && epoch_ok && progress_ok - && cssd_ok && quorum_ok && inc_ok && lms_match_ok - && admitted_ok && selfmember_ok && map_ok)) + = cluster_membership_get_last_admitted_incarnation(cluster_node_id) == boot_incarnation; + bool selfmember_ok = cluster_grd_authority_member(members_lo, members_hi, cluster_node_id); + bool map_ok = cluster_grd_authority_map_is_current(refresh, members_lo, members_hi); + + if (!(boot_ok && lmsgen_ok && refresh_ok && epoch_ok && progress_ok && cssd_ok && quorum_ok + && inc_ok && lms_match_ok && admitted_ok && selfmember_ok && map_ok)) return false; } for (i = 0; i < CLUSTER_MAX_NODES; i++) { - bool request_member - = cluster_grd_authority_member(members_lo, members_hi, i); + bool request_member = cluster_grd_authority_member(members_lo, members_hi, i); /* * RF-ROOT P6 (crash-rejoin): the durable admission is the * membership proof for SELF. The LMON self-state byte can @@ -3031,38 +2920,30 @@ grd_recovery_authority_request_current(uint64 request_generation) * latch. The quorum-majority COMMITTED join marker + * publish-proof (self_join_admitted) closes that cycle. */ - bool current_member - = cluster_membership_is_member(i) - || (i == cluster_node_id - && cluster_reconfig_self_join_admitted()); + bool current_member = cluster_membership_is_member(i) + || (i == cluster_node_id && cluster_reconfig_self_join_admitted()); - if (request_member - && (cluster_conf_lookup_node(i) == NULL || !current_member)) + if (request_member && (cluster_conf_lookup_node(i) == NULL || !current_member)) return false; - if (!request_member && cluster_conf_lookup_node(i) != NULL - && current_member) + if (!request_member && cluster_conf_lookup_node(i) != NULL && current_member) return false; } return true; } static void -grd_recovery_authority_publish_terminal( - uint64 request_generation, ClusterGrdRecoveryAuthorityTerminal result) +grd_recovery_authority_publish_terminal(uint64 request_generation, + ClusterGrdRecoveryAuthorityTerminal result) { - if (pg_atomic_read_u64( - &cluster_grd_state->recovery_authority_request_generation) + if (pg_atomic_read_u64(&cluster_grd_state->recovery_authority_request_generation) != request_generation) return; if (result != GRD_RECOVERY_AUTHORITY_TERMINAL_SUCCESS) grd_recovery_authority_clear_seal(); - pg_atomic_write_u32( - &cluster_grd_state->recovery_authority_terminal_result, - (uint32)result); + pg_atomic_write_u32(&cluster_grd_state->recovery_authority_terminal_result, (uint32)result); pg_write_barrier(); - pg_atomic_write_u64( - &cluster_grd_state->recovery_authority_terminal_generation, - request_generation); + pg_atomic_write_u64(&cluster_grd_state->recovery_authority_terminal_generation, + request_generation); } /* A1 R1: sole blocking executor. This runs once per LMON duty; it never @@ -3084,53 +2965,41 @@ cluster_grd_recovery_authority_lmon_tick(void) if (!cluster_enabled || cluster_grd_state == NULL) return; - request_generation = pg_atomic_read_u64( - &cluster_grd_state->recovery_authority_request_generation); + request_generation + = pg_atomic_read_u64(&cluster_grd_state->recovery_authority_request_generation); if (request_generation == 0 - || pg_atomic_read_u64( - &cluster_grd_state->recovery_authority_terminal_generation) - >= request_generation) - { + || pg_atomic_read_u64(&cluster_grd_state->recovery_authority_terminal_generation) + >= request_generation) { return; } if (!grd_recovery_authority_request_current(request_generation)) { - grd_recovery_authority_publish_terminal( - request_generation, GRD_RECOVERY_AUTHORITY_TERMINAL_FAILED); + grd_recovery_authority_publish_terminal(request_generation, + GRD_RECOVERY_AUTHORITY_TERMINAL_FAILED); return; } - epoch = pg_atomic_read_u64( - &cluster_grd_state->recovery_authority_formation_epoch); - bitmap_hash = pg_atomic_read_u64( - &cluster_grd_state->recovery_authority_bitmap_hash); - members_lo = pg_atomic_read_u64( - &cluster_grd_state->recovery_authority_members[0]); - members_hi = pg_atomic_read_u64( - &cluster_grd_state->recovery_authority_members[1]); - refresh = pg_atomic_read_u64( - &cluster_grd_state->recovery_authority_request_master_refresh); - boot_incarnation = pg_atomic_read_u64( - &cluster_grd_state->recovery_authority_request_boot_incarnation); - lms_generation = pg_atomic_read_u64( - &cluster_grd_state->recovery_authority_request_lms_generation); - - if (grd_recovery_authority_lmon_request_generation - != request_generation) { + epoch = pg_atomic_read_u64(&cluster_grd_state->recovery_authority_formation_epoch); + bitmap_hash = pg_atomic_read_u64(&cluster_grd_state->recovery_authority_bitmap_hash); + members_lo = pg_atomic_read_u64(&cluster_grd_state->recovery_authority_members[0]); + members_hi = pg_atomic_read_u64(&cluster_grd_state->recovery_authority_members[1]); + refresh = pg_atomic_read_u64(&cluster_grd_state->recovery_authority_request_master_refresh); + boot_incarnation + = pg_atomic_read_u64(&cluster_grd_state->recovery_authority_request_boot_incarnation); + lms_generation + = pg_atomic_read_u64(&cluster_grd_state->recovery_authority_request_lms_generation); + + if (grd_recovery_authority_lmon_request_generation != request_generation) { grd_recovery_authority_lmon_request_generation = request_generation; grd_recovery_authority_lmon_redeclare_generation - = pg_atomic_add_fetch_u64( - &cluster_grd_state->recovery_redeclare_generation, 1); + = pg_atomic_add_fetch_u64(&cluster_grd_state->recovery_redeclare_generation, 1); (void)grd_recovery_broadcast_redeclare(); } - if (grd_recovery_barrier_complete( - grd_recovery_authority_lmon_redeclare_generation, epoch)) { - pg_atomic_write_u64( - &cluster_grd_state->recovery_authority_done_epoch[cluster_node_id], - epoch); - pg_atomic_write_u64( - &cluster_grd_state->recovery_authority_done_hash[cluster_node_id], - bitmap_hash); + if (grd_recovery_barrier_complete(grd_recovery_authority_lmon_redeclare_generation, epoch)) { + pg_atomic_write_u64(&cluster_grd_state->recovery_authority_done_epoch[cluster_node_id], + epoch); + pg_atomic_write_u64(&cluster_grd_state->recovery_authority_done_hash[cluster_node_id], + bitmap_hash); /* * RF-ROOT P6 (STOP-01 contract): 1 Hz floor on the * done-key re-announce. The LMON main loop iterates at inbound-frame @@ -3148,10 +3017,8 @@ cluster_grd_recovery_authority_lmon_tick(void) static TimestampTz last_done_broadcast_at = 0; TimestampTz now_ts = GetCurrentTimestamp(); - if (now_ts == 0 - || last_done_broadcast_at == 0 - || now_ts - last_done_broadcast_at - >= INT64CONST(1000000)) { + if (now_ts == 0 || last_done_broadcast_at == 0 + || now_ts - last_done_broadcast_at >= INT64CONST(1000000)) { grd_recovery_broadcast_done_key(epoch, bitmap_hash); last_done_broadcast_at = now_ts; } @@ -3160,11 +3027,8 @@ cluster_grd_recovery_authority_lmon_tick(void) for (i = 0; i < CLUSTER_MAX_NODES; i++) { if (!cluster_grd_authority_member(members_lo, members_hi, i)) continue; - if (pg_atomic_read_u64( - &cluster_grd_state->recovery_authority_done_epoch[i]) - != epoch - || pg_atomic_read_u64( - &cluster_grd_state->recovery_authority_done_hash[i]) + if (pg_atomic_read_u64(&cluster_grd_state->recovery_authority_done_epoch[i]) != epoch + || pg_atomic_read_u64(&cluster_grd_state->recovery_authority_done_hash[i]) != bitmap_hash) { all_done = false; break; @@ -3175,23 +3039,17 @@ cluster_grd_recovery_authority_lmon_tick(void) (void)cluster_grd_cleanup_stale_epoch_postbarrier(epoch); if (!grd_recovery_authority_request_current(request_generation)) { - grd_recovery_authority_publish_terminal( - request_generation, GRD_RECOVERY_AUTHORITY_TERMINAL_FAILED); + grd_recovery_authority_publish_terminal(request_generation, + GRD_RECOVERY_AUTHORITY_TERMINAL_FAILED); return; } - pg_atomic_write_u64( - &cluster_grd_state->recovery_authority_master_refresh, refresh); - pg_atomic_write_u64( - &cluster_grd_state->recovery_authority_boot_incarnation, - boot_incarnation); - pg_atomic_write_u64( - &cluster_grd_state->recovery_authority_lms_generation, - lms_generation); + pg_atomic_write_u64(&cluster_grd_state->recovery_authority_master_refresh, refresh); + pg_atomic_write_u64(&cluster_grd_state->recovery_authority_boot_incarnation, boot_incarnation); + pg_atomic_write_u64(&cluster_grd_state->recovery_authority_lms_generation, lms_generation); pg_write_barrier(); grd_recovery_authority_publish_terminal( request_generation, - cluster_grd_recovery_authority_is_current( - boot_incarnation, lms_generation) + cluster_grd_recovery_authority_is_current(boot_incarnation, lms_generation) ? GRD_RECOVERY_AUTHORITY_TERMINAL_SUCCESS : GRD_RECOVERY_AUTHORITY_TERMINAL_FAILED); } @@ -3199,9 +3057,9 @@ cluster_grd_recovery_authority_lmon_tick(void) /* Postmaster coordinator: validate and publish one immutable request, then * poll only atomic terminal state under the caller's existing deadline. */ bool -cluster_grd_recovery_authority_barrier_wait( - const ClusterFormationSnapshotV1 *formation, uint64 boot_incarnation, - uint64 lms_generation, int timeout_ms) +cluster_grd_recovery_authority_barrier_wait(const ClusterFormationSnapshotV1 *formation, + uint64 boot_incarnation, uint64 lms_generation, + int timeout_ms) { TimestampTz deadline; uint64 bitmap_hash; @@ -3216,15 +3074,13 @@ cluster_grd_recovery_authority_barrier_wait( uint64 prev_members_hi; int i; - if (formation == NULL || boot_incarnation == 0 || lms_generation == 0 - || timeout_ms <= 0 || cluster_grd_state == NULL - || cluster_grd_entry_htab == NULL || cluster_grd_recovery_in_progress() - || !cluster_qvotec_in_quorum() + if (formation == NULL || boot_incarnation == 0 || lms_generation == 0 || timeout_ms <= 0 + || cluster_grd_state == NULL || cluster_grd_entry_htab == NULL + || cluster_grd_recovery_in_progress() || !cluster_qvotec_in_quorum() || cluster_qvotec_get_self_incarnation() != boot_incarnation || cluster_lms_get_lms_restart_generation() != lms_generation || !cluster_membership_is_member(cluster_node_id) - || cluster_membership_get_last_admitted_incarnation(cluster_node_id) - != boot_incarnation) { + || cluster_membership_get_last_admitted_incarnation(cluster_node_id) != boot_incarnation) { return false; } @@ -3242,19 +3098,15 @@ cluster_grd_recovery_authority_barrier_wait( * until some UNRELATED reconfig lands. */ if ((epoch != formation->applied.new_epoch - && !(formation->self_join_admitted - && epoch > formation->applied.new_epoch)) + && !(formation->self_join_admitted && epoch > formation->applied.new_epoch)) || epoch != cluster_epoch_get_current()) return false; for (i = 0; i < CLUSTER_MAX_NODES; i++) { - bool formation_member - = formation->membership.membership_state[i] - == CLUSTER_MEMBER_MEMBER; + bool formation_member = formation->membership.membership_state[i] == CLUSTER_MEMBER_MEMBER; if (formation_member - && (cluster_conf_lookup_node(i) == NULL - || !cluster_membership_is_member(i))) + && (cluster_conf_lookup_node(i) == NULL || !cluster_membership_is_member(i))) return false; if (!formation_member && cluster_conf_lookup_node(i) != NULL && cluster_membership_is_member(i)) @@ -3266,26 +3118,20 @@ cluster_grd_recovery_authority_barrier_wait( else members_hi |= UINT64_C(1) << (i - 64); } - if (!cluster_grd_authority_member( - members_lo, members_hi, cluster_node_id)) + if (!cluster_grd_authority_member(members_lo, members_hi, cluster_node_id)) return false; refresh = pg_atomic_read_u64(&cluster_grd_state->master_map_refresh_count); - if (refresh == 0 - || !cluster_grd_authority_map_is_current( - refresh, members_lo, members_hi)) + if (refresh == 0 || !cluster_grd_authority_map_is_current(refresh, members_lo, members_hi)) return false; - bitmap_hash = cluster_grd_dead_bitmap_hash( - formation->applied.dead_bitmap); + bitmap_hash = cluster_grd_dead_bitmap_hash(formation->applied.dead_bitmap); if (bitmap_hash == 0) return false; - if (pg_atomic_read_u64( - &cluster_grd_state->recovery_authority_request_generation) - > pg_atomic_read_u64( - &cluster_grd_state->recovery_authority_terminal_generation)) + if (pg_atomic_read_u64(&cluster_grd_state->recovery_authority_request_generation) + > pg_atomic_read_u64(&cluster_grd_state->recovery_authority_terminal_generation)) return false; - request_generation = pg_atomic_add_fetch_u64( - &cluster_grd_state->recovery_authority_request_sequence, 1); + request_generation + = pg_atomic_add_fetch_u64(&cluster_grd_state->recovery_authority_request_sequence, 1); if (request_generation == 0) return false; /* @@ -3305,48 +3151,32 @@ cluster_grd_recovery_authority_barrier_wait( * retained; on a changed composite they cannot match the new request's * all_done comparison anyway, so zeroing there is pure hygiene. */ - prev_epoch = pg_atomic_read_u64( - &cluster_grd_state->recovery_authority_formation_epoch); - prev_hash = pg_atomic_read_u64( - &cluster_grd_state->recovery_authority_bitmap_hash); - prev_members_lo = pg_atomic_read_u64( - &cluster_grd_state->recovery_authority_members[0]); - prev_members_hi = pg_atomic_read_u64( - &cluster_grd_state->recovery_authority_members[1]); + prev_epoch = pg_atomic_read_u64(&cluster_grd_state->recovery_authority_formation_epoch); + prev_hash = pg_atomic_read_u64(&cluster_grd_state->recovery_authority_bitmap_hash); + prev_members_lo = pg_atomic_read_u64(&cluster_grd_state->recovery_authority_members[0]); + prev_members_hi = pg_atomic_read_u64(&cluster_grd_state->recovery_authority_members[1]); grd_recovery_authority_clear_seal(); - pg_atomic_write_u64( - &cluster_grd_state->recovery_authority_request_boot_incarnation, - boot_incarnation); - pg_atomic_write_u64( - &cluster_grd_state->recovery_authority_request_lms_generation, - lms_generation); - pg_atomic_write_u64( - &cluster_grd_state->recovery_authority_request_master_refresh, - refresh); - pg_atomic_write_u64( - &cluster_grd_state->recovery_authority_formation_epoch, epoch); - pg_atomic_write_u64( - &cluster_grd_state->recovery_authority_bitmap_hash, bitmap_hash); - pg_atomic_write_u64( - &cluster_grd_state->recovery_authority_members[0], members_lo); - pg_atomic_write_u64( - &cluster_grd_state->recovery_authority_members[1], members_hi); - if (epoch != prev_epoch || bitmap_hash != prev_hash - || members_lo != prev_members_lo || members_hi != prev_members_hi) { + pg_atomic_write_u64(&cluster_grd_state->recovery_authority_request_boot_incarnation, + boot_incarnation); + pg_atomic_write_u64(&cluster_grd_state->recovery_authority_request_lms_generation, + lms_generation); + pg_atomic_write_u64(&cluster_grd_state->recovery_authority_request_master_refresh, refresh); + pg_atomic_write_u64(&cluster_grd_state->recovery_authority_formation_epoch, epoch); + pg_atomic_write_u64(&cluster_grd_state->recovery_authority_bitmap_hash, bitmap_hash); + pg_atomic_write_u64(&cluster_grd_state->recovery_authority_members[0], members_lo); + pg_atomic_write_u64(&cluster_grd_state->recovery_authority_members[1], members_hi); + if (epoch != prev_epoch || bitmap_hash != prev_hash || members_lo != prev_members_lo + || members_hi != prev_members_hi) { for (i = 0; i < CLUSTER_MAX_NODES; i++) { - pg_atomic_write_u64( - &cluster_grd_state->recovery_authority_done_epoch[i], 0); - pg_atomic_write_u64( - &cluster_grd_state->recovery_authority_done_hash[i], 0); + pg_atomic_write_u64(&cluster_grd_state->recovery_authority_done_epoch[i], 0); + pg_atomic_write_u64(&cluster_grd_state->recovery_authority_done_hash[i], 0); } } - pg_atomic_write_u32( - &cluster_grd_state->recovery_authority_terminal_result, - GRD_RECOVERY_AUTHORITY_TERMINAL_NONE); + pg_atomic_write_u32(&cluster_grd_state->recovery_authority_terminal_result, + GRD_RECOVERY_AUTHORITY_TERMINAL_NONE); pg_write_barrier(); - pg_atomic_write_u64( - &cluster_grd_state->recovery_authority_request_generation, - request_generation); + pg_atomic_write_u64(&cluster_grd_state->recovery_authority_request_generation, + request_generation); cluster_lmon_wakeup(); deadline = TimestampTzPlusMilliseconds(GetCurrentTimestamp(), timeout_ms); @@ -3355,33 +3185,27 @@ cluster_grd_recovery_authority_barrier_wait( if (GetCurrentTimestamp() >= deadline) break; - terminal_generation = pg_atomic_read_u64( - &cluster_grd_state->recovery_authority_terminal_generation); + terminal_generation + = pg_atomic_read_u64(&cluster_grd_state->recovery_authority_terminal_generation); if (terminal_generation == request_generation) { uint32 tresult; pg_read_barrier(); - tresult = pg_atomic_read_u32( - &cluster_grd_state->recovery_authority_terminal_result); + tresult = pg_atomic_read_u32(&cluster_grd_state->recovery_authority_terminal_result); return tresult == GRD_RECOVERY_AUTHORITY_TERMINAL_SUCCESS - && cluster_grd_recovery_authority_is_current( - boot_incarnation, lms_generation); + && cluster_grd_recovery_authority_is_current(boot_incarnation, lms_generation); } - if (pg_atomic_read_u64( - &cluster_grd_state->recovery_authority_request_generation) + if (pg_atomic_read_u64(&cluster_grd_state->recovery_authority_request_generation) != request_generation - || cluster_epoch_get_current() != epoch - || !cluster_qvotec_in_quorum() + || cluster_epoch_get_current() != epoch || !cluster_qvotec_in_quorum() || cluster_qvotec_get_self_incarnation() != boot_incarnation - || cluster_lms_get_lms_restart_generation() != lms_generation) - { + || cluster_lms_get_lms_restart_generation() != lms_generation) { break; } pg_usleep(1000L); } - pg_atomic_write_u64( - &cluster_grd_state->recovery_authority_cancel_generation, - request_generation); + pg_atomic_write_u64(&cluster_grd_state->recovery_authority_cancel_generation, + request_generation); pg_write_barrier(); cluster_lmon_wakeup(); return false; @@ -6136,9 +5960,8 @@ grd_find_holder_slot(ClusterGrdEntry *entry, int32 node_id, uint32 procno, LOCKM } static ClusterGrdConvertResult -cluster_grd_entry_request_convert_internal(ClusterGrdEntry *entry, - const ClusterGrdConvert *req, - bool *out_drain_hint, bool dontwait) +cluster_grd_entry_request_convert_internal(ClusterGrdEntry *entry, const ClusterGrdConvert *req, + bool *out_drain_hint, bool dontwait) { int hslot; ClusterGesConvertClass klass; @@ -6234,21 +6057,17 @@ cluster_grd_entry_request_convert_internal(ClusterGrdEntry *entry, } ClusterGrdConvertResult -cluster_grd_entry_request_convert(ClusterGrdEntry *entry, - const ClusterGrdConvert *req, +cluster_grd_entry_request_convert(ClusterGrdEntry *entry, const ClusterGrdConvert *req, bool *out_drain_hint) { - return cluster_grd_entry_request_convert_internal(entry, req, - out_drain_hint, false); + return cluster_grd_entry_request_convert_internal(entry, req, out_drain_hint, false); } ClusterGrdConvertResult -cluster_grd_entry_request_convert_nowait(ClusterGrdEntry *entry, - const ClusterGrdConvert *req, - bool *out_drain_hint) +cluster_grd_entry_request_convert_nowait(ClusterGrdEntry *entry, const ClusterGrdConvert *req, + bool *out_drain_hint) { - return cluster_grd_entry_request_convert_internal(entry, req, - out_drain_hint, true); + return cluster_grd_entry_request_convert_internal(entry, req, out_drain_hint, true); } /* Remove convert slot c (swap-with-last compaction). */ @@ -6698,10 +6517,9 @@ cluster_grd_convert_or_enqueue_meta(const ClusterResId *resid, int32 node_id, ui * target is created. */ ClusterGrdConvertResult cluster_grd_convert_nowait(const ClusterResId *resid, int32 node_id, uint32 procno, - uint64 cluster_epoch, LOCKMODE current_mode, - LOCKMODE requested_mode, uint64 convert_request_id, - uint64 old_request_id, int32 source_node_id, - uint64 shard_master_generation) + uint64 cluster_epoch, LOCKMODE current_mode, LOCKMODE requested_mode, + uint64 convert_request_id, uint64 old_request_id, int32 source_node_id, + uint64 shard_master_generation) { ClusterGrdEntry *entry = NULL; ClusterGrdEntryResult lookup_result; @@ -6728,13 +6546,11 @@ cluster_grd_convert_nowait(const ClusterResId *resid, int32 node_id, uint32 proc SpinLockAcquire(&entry->lock); hslot = grd_find_holder_slot(entry, node_id, procno, current_mode); - if (old_request_id == 0 || hslot < 0 - || entry->holders[hslot].request_id != old_request_id) { + if (old_request_id == 0 || hslot < 0 || entry->holders[hslot].request_id != old_request_id) { pg_atomic_fetch_add_u64(&cluster_grd_state->convert_illegal_count, 1); result = CLUSTER_GRD_CONVERT_ILLEGAL; } else - result = cluster_grd_entry_request_convert_nowait(entry, &creq, - &drain_hint); + result = cluster_grd_entry_request_convert_nowait(entry, &creq, &drain_hint); SpinLockRelease(&entry->lock); cluster_grd_entry_release(entry); if (result == CLUSTER_GRD_CONVERT_GRANTED_INPLACE) @@ -6847,9 +6663,8 @@ cluster_grd_release_and_drain(const ClusterResId *resid, const ClusterGrdHolderI lookup_result = cluster_grd_entry_lookup_or_create(resid, false, &entry); if (lookup_result != CLUSTER_GRD_ENTRY_OK || entry == NULL) - return lookup_result == CLUSTER_GRD_ENTRY_NOT_FOUND - ? CLUSTER_GRD_RELEASE_NOT_FOUND - : CLUSTER_GRD_RELEASE_NOT_READY; + return lookup_result == CLUSTER_GRD_ENTRY_NOT_FOUND ? CLUSTER_GRD_RELEASE_NOT_FOUND + : CLUSTER_GRD_RELEASE_NOT_READY; SpinLockAcquire(&entry->lock); @@ -7411,9 +7226,8 @@ cluster_grd_clean_leave_verify_no_leftover(int32 leaving_node) * current FAIL_STOP lineage. This is a read-only process-local snapshot; * later GRD gates/unfreeze and daemon state are deliberately not authority. */ bool -cluster_grd_rejoin_clear_snapshot( - const ClusterReconfigRejoinFailureSnapshotV1 *failure, - ClusterGrdRejoinClearSnapshotV1 *out_clear) +cluster_grd_rejoin_clear_snapshot(const ClusterReconfigRejoinFailureSnapshotV1 *failure, + ClusterGrdRejoinClearSnapshotV1 *out_clear) { ClusterReconfigRejoinFailureSnapshotV1 current; ClusterGrdRejoinClearSnapshotV1 clear; @@ -7423,50 +7237,44 @@ cluster_grd_rejoin_clear_snapshot( if (out_clear != NULL) memset(out_clear, 0, sizeof(*out_clear)); - if (out_clear == NULL || failure == NULL || cluster_grd_state == NULL || - failure->reconfig_kind != RECONFIG_KIND_FAIL_STOP || - failure->reserved0 != 0 || failure->reserved68 != 0 || - failure->event_id == 0 || failure->new_epoch == 0 || - failure->cssd_dead_generation == 0 || - failure->old_node_id < 0 || - failure->old_node_id >= CLUSTER_MAX_NODES || - failure->old_incarnation == 0) + if (out_clear == NULL || failure == NULL || cluster_grd_state == NULL + || failure->reconfig_kind != RECONFIG_KIND_FAIL_STOP || failure->reserved0 != 0 + || failure->reserved68 != 0 || failure->event_id == 0 || failure->new_epoch == 0 + || failure->cssd_dead_generation == 0 || failure->old_node_id < 0 + || failure->old_node_id >= CLUSTER_MAX_NODES || failure->old_incarnation == 0) return false; - for (i = 0; i < CLUSTER_RECONFIG_DEAD_BITMAP_BYTES; i++) - { + for (i = 0; i < CLUSTER_RECONFIG_DEAD_BITMAP_BYTES; i++) { uint8 survivors = failure->survivor_bitmap[i]; if ((failure->dead_bitmap[i] & survivors) != 0) return false; - while (survivors != 0) - { + while (survivors != 0) { survivor_count += survivors & 1; survivors >>= 1; } } - if (survivor_count < 1 || survivor_count >= CLUSTER_MAX_NODES || - (failure->dead_bitmap[failure->old_node_id / 8] & - (uint8)(UINT8_C(1) << (failure->old_node_id % 8))) == 0 || - (failure->survivor_bitmap[failure->old_node_id / 8] & - (uint8)(UINT8_C(1) << (failure->old_node_id % 8))) != 0) + if (survivor_count < 1 || survivor_count >= CLUSTER_MAX_NODES + || (failure->dead_bitmap[failure->old_node_id / 8] + & (uint8)(UINT8_C(1) << (failure->old_node_id % 8))) + == 0 + || (failure->survivor_bitmap[failure->old_node_id / 8] + & (uint8)(UINT8_C(1) << (failure->old_node_id % 8))) + != 0) return false; - if (!cluster_reconfig_rejoin_failure_snapshot(failure->old_node_id, - failure->old_incarnation, ¤t) || - memcmp(¤t, failure, sizeof(current)) != 0) + if (!cluster_reconfig_rejoin_failure_snapshot(failure->old_node_id, failure->old_incarnation, + ¤t) + || memcmp(¤t, failure, sizeof(current)) != 0) return false; dead_hash = cluster_grd_dead_bitmap_hash(failure->dead_bitmap); - if (dead_hash == 0 || - cluster_grd_recovery_episode_epoch_value() != failure->new_epoch || - cluster_grd_recovery_event_bitmap_hash_value() != dead_hash) + if (dead_hash == 0 || cluster_grd_recovery_episode_epoch_value() != failure->new_epoch + || cluster_grd_recovery_event_bitmap_hash_value() != dead_hash) return false; - for (i = 0; i < CLUSTER_MAX_NODES; i++) - { - if ((failure->survivor_bitmap[i / 8] & - (uint8)(UINT8_C(1) << (i % 8))) == 0) + for (i = 0; i < CLUSTER_MAX_NODES; i++) { + if ((failure->survivor_bitmap[i / 8] & (uint8)(UINT8_C(1) << (i % 8))) == 0) continue; - if (cluster_grd_recovery_done_epoch_for(i) != failure->new_epoch || - cluster_grd_recovery_done_bitmap_hash_for(i) != dead_hash) + if (cluster_grd_recovery_done_epoch_for(i) != failure->new_epoch + || cluster_grd_recovery_done_bitmap_hash_for(i) != dead_hash) return false; } if (!cluster_grd_clean_leave_verify_no_leftover(failure->old_node_id)) @@ -7475,8 +7283,7 @@ cluster_grd_rejoin_clear_snapshot( memset(&clear, 0, sizeof(clear)); clear.episode_epoch = failure->new_epoch; clear.dead_bitmap_hash = dead_hash; - memcpy(clear.survivor_bitmap, failure->survivor_bitmap, - sizeof(clear.survivor_bitmap)); + memcpy(clear.survivor_bitmap, failure->survivor_bitmap, sizeof(clear.survivor_bitmap)); *out_clear = clear; return true; } @@ -8349,8 +8156,7 @@ grd_promote_remote_grant_exact(const ClusterResId *resid, const ClusterGrdHolder Assert(resid != NULL && holder != NULL); - if (cluster_grd_entry_lookup_or_create(resid, false, &entry) - != CLUSTER_GRD_ENTRY_OK + if (cluster_grd_entry_lookup_or_create(resid, false, &entry) != CLUSTER_GRD_ENTRY_OK || entry == NULL) return CLUSTER_GRD_ENTRY_NOT_FOUND; @@ -8364,8 +8170,7 @@ grd_promote_remote_grant_exact(const ClusterResId *resid, const ClusterGrdHolder LOCKMODE mode = entry->reservations[i].mode; if (i < entry->nreservations - 1) - entry->reservations[i] - = entry->reservations[entry->nreservations - 1]; + entry->reservations[i] = entry->reservations[entry->nreservations - 1]; memset(&entry->reservations[entry->nreservations - 1], 0, sizeof(entry->reservations[0])); entry->nreservations--; @@ -8460,9 +8265,8 @@ cluster_grd_release_holder_by_id(const ClusterResId *resid, const ClusterGrdHold } bool -cluster_grd_holder_mode_by_id(const ClusterResId *resid, - const ClusterGrdHolderId *holder, - LOCKMODE *out_mode) +cluster_grd_holder_mode_by_id(const ClusterResId *resid, const ClusterGrdHolderId *holder, + LOCKMODE *out_mode) { ClusterGrdEntry *entry = NULL; ClusterGrdEntryResult er; diff --git a/src/backend/cluster/cluster_guc.c b/src/backend/cluster/cluster_guc.c index 58ddb5f64f7..6aad587da0a 100644 --- a/src/backend/cluster/cluster_guc.c +++ b/src/backend/cluster/cluster_guc.c @@ -42,7 +42,7 @@ #include "libpq/pqcomm.h" #include "cluster/cluster_block_recovery.h" /* spec-4.10 D1 online block recovery GUCs */ -#include "cluster/cluster_external_fence.h" /* STOP-04 external fence GUC defaults */ +#include "cluster/cluster_external_fence.h" /* STOP-04 external fence GUC defaults */ #include "cluster/cluster_thread_recovery.h" /* spec-4.11 D1 online thread recovery GUCs */ #include "cluster/cluster_write_fence.h" /* spec-4.12 D7 write-fence enforcement GUCs */ #include "cluster/cluster_conf.h" /* cluster_conf_has_peers (spec-3.18 D2b latch) */ @@ -82,8 +82,7 @@ char *cluster_wal_threads_dir = NULL; /* spec-4.1 D5; '' = flat pg_wal layout * #ifdef ENABLE_INJECTION char *cluster_pcm_x_retain_flush_error_target = NULL; -typedef struct ClusterPcmXRetainFlushErrorTarget -{ +typedef struct ClusterPcmXRetainFlushErrorTarget { bool valid; uint32 spc_oid; uint32 db_oid; @@ -879,8 +878,7 @@ int cluster_write_fence_lease_ms = 6000; /* STOP-04 §3.11: the socket endpoint is postmaster-frozen while the overall * acquisition deadline is sampled once per recovery attempt and may reload. */ char *cluster_external_fence_socket_path = NULL; -int cluster_external_fence_acquire_timeout_ms = - PGRAC_EXTERNAL_FENCE_ACQUIRE_TIMEOUT_DEFAULT_MS; +int cluster_external_fence_acquire_timeout_ms = PGRAC_EXTERNAL_FENCE_ACQUIRE_TIMEOUT_DEFAULT_MS; /* spec-4.12b D4: cooperative write-fence enforcement now ships default ON. The * spec-4.12b baseline-marker subsystem (D2) keeps a healthy steady-state cluster's @@ -1126,13 +1124,10 @@ external_fence_path_has_parent_component(const char *path) } static bool -check_cluster_external_fence_socket_path(char **newval, void **extra, - GucSource source) +check_cluster_external_fence_socket_path(char **newval, void **extra, GucSource source) { - if (*newval == NULL || (*newval)[0] == '\0' || - !is_absolute_path(*newval)) { - GUC_check_errdetail( - "cluster.external_fence_socket_path must be a nonempty absolute path."); + if (*newval == NULL || (*newval)[0] == '\0' || !is_absolute_path(*newval)) { + GUC_check_errdetail("cluster.external_fence_socket_path must be a nonempty absolute path."); return false; } if (external_fence_path_has_parent_component(*newval)) { @@ -1150,8 +1145,7 @@ check_cluster_external_fence_socket_path(char **newval, void **extra, #ifdef ENABLE_INJECTION static bool -cluster_pcm_x_retain_flush_error_parse_field(const char **cursor, bool last, - uint64 *out) +cluster_pcm_x_retain_flush_error_parse_field(const char **cursor, bool last, uint64 *out) { const char *p = *cursor; uint64 value = 0; @@ -1159,7 +1153,7 @@ cluster_pcm_x_retain_flush_error_parse_field(const char **cursor, bool last, if (*p < '0' || *p > '9') return false; do { - uint64 digit = (uint64) (*p - '0'); + uint64 digit = (uint64)(*p - '0'); if (value > (UINT64_MAX - digit) / 10) return false; @@ -1170,8 +1164,7 @@ cluster_pcm_x_retain_flush_error_parse_field(const char **cursor, bool last, if (last) { if (*p != '\0') return false; - } - else { + } else { if (*p != '/') return false; p++; @@ -1182,8 +1175,7 @@ cluster_pcm_x_retain_flush_error_parse_field(const char **cursor, bool last, } static bool -cluster_pcm_x_retain_flush_error_parse( - const char *value, ClusterPcmXRetainFlushErrorTarget *target) +cluster_pcm_x_retain_flush_error_parse(const char *value, ClusterPcmXRetainFlushErrorTarget *target) { const char *cursor = value; uint64 fields[5]; @@ -1196,40 +1188,36 @@ cluster_pcm_x_retain_flush_error_parse( return true; for (i = 0; i < lengthof(fields); i++) { - if (!cluster_pcm_x_retain_flush_error_parse_field( - &cursor, i == lengthof(fields) - 1, &fields[i])) + if (!cluster_pcm_x_retain_flush_error_parse_field(&cursor, i == lengthof(fields) - 1, + &fields[i])) return false; } - if (fields[0] == 0 || fields[0] > UINT32_MAX || - fields[1] == 0 || fields[1] > UINT32_MAX || - fields[2] == 0 || fields[2] > UINT32_MAX || - fields[3] > MAX_FORKNUM || fields[4] >= InvalidBlockNumber) + if (fields[0] == 0 || fields[0] > UINT32_MAX || fields[1] == 0 || fields[1] > UINT32_MAX + || fields[2] == 0 || fields[2] > UINT32_MAX || fields[3] > MAX_FORKNUM + || fields[4] >= InvalidBlockNumber) return false; target->valid = true; - target->spc_oid = (uint32) fields[0]; - target->db_oid = (uint32) fields[1]; - target->rel_number = (uint32) fields[2]; - target->fork_number = (int) fields[3]; - target->block_number = (uint32) fields[4]; + target->spc_oid = (uint32)fields[0]; + target->db_oid = (uint32)fields[1]; + target->rel_number = (uint32)fields[2]; + target->fork_number = (int)fields[3]; + target->block_number = (uint32)fields[4]; return true; } static bool -cluster_pcm_x_retain_flush_error_target_check_hook(char **newval, void **extra, - GucSource source) +cluster_pcm_x_retain_flush_error_target_check_hook(char **newval, void **extra, GucSource source) { ClusterPcmXRetainFlushErrorTarget parsed; ClusterPcmXRetainFlushErrorTarget *saved; - (void) source; - if (*newval == NULL || - !cluster_pcm_x_retain_flush_error_parse(*newval, &parsed)) { + (void)source; + if (*newval == NULL || !cluster_pcm_x_retain_flush_error_parse(*newval, &parsed)) { GUC_check_errcode(ERRCODE_INVALID_PARAMETER_VALUE); - GUC_check_errdetail( - "cluster.pcm_x_retain_flush_error_target must be empty or exactly " - "five unsigned decimal fields spcOid/dbOid/relNumber/forkNum/blockNum " - "within BufferTag ranges, with nonzero spcOid, dbOid, and relNumber."); + GUC_check_errdetail("cluster.pcm_x_retain_flush_error_target must be empty or exactly " + "five unsigned decimal fields spcOid/dbOid/relNumber/forkNum/blockNum " + "within BufferTag ranges, with nonzero spcOid, dbOid, and relNumber."); return false; } @@ -1242,28 +1230,26 @@ cluster_pcm_x_retain_flush_error_target_check_hook(char **newval, void **extra, } static void -cluster_pcm_x_retain_flush_error_target_assign_hook(const char *newval, - void *extra) +cluster_pcm_x_retain_flush_error_target_assign_hook(const char *newval, void *extra) { - (void) newval; + (void)newval; memset(&cluster_pcm_x_retain_flush_error_target_parsed, 0, sizeof(cluster_pcm_x_retain_flush_error_target_parsed)); if (extra != NULL) - cluster_pcm_x_retain_flush_error_target_parsed = - *((const ClusterPcmXRetainFlushErrorTarget *) extra); + cluster_pcm_x_retain_flush_error_target_parsed + = *((const ClusterPcmXRetainFlushErrorTarget *)extra); } bool -cluster_pcm_x_retain_flush_error_target_matches(uint32 spc_oid, uint32 db_oid, - uint32 rel_number, int fork_number, - uint32 block_number) +cluster_pcm_x_retain_flush_error_target_matches(uint32 spc_oid, uint32 db_oid, uint32 rel_number, + int fork_number, uint32 block_number) { - const ClusterPcmXRetainFlushErrorTarget *target = - &cluster_pcm_x_retain_flush_error_target_parsed; + const ClusterPcmXRetainFlushErrorTarget *target + = &cluster_pcm_x_retain_flush_error_target_parsed; - return target->valid && target->spc_oid == spc_oid && - target->db_oid == db_oid && target->rel_number == rel_number && - target->fork_number == fork_number && target->block_number == block_number; + return target->valid && target->spc_oid == spc_oid && target->db_oid == db_oid + && target->rel_number == rel_number && target->fork_number == fork_number + && target->block_number == block_number; } #endif @@ -2198,8 +2184,7 @@ cluster_init_guc(void) gettext_noop("External write-exclusion daemon socket path."), gettext_noop("Absolute Unix-domain socket path for the configured root fencing " "provider. Parent path components are forbidden."), - &cluster_external_fence_socket_path, - "/var/run/pgrac/pgrac-fenced.sock", PGC_POSTMASTER, 0, + &cluster_external_fence_socket_path, "/var/run/pgrac/pgrac-fenced.sock", PGC_POSTMASTER, 0, check_cluster_external_fence_socket_path, NULL, NULL); DefineCustomIntVariable( @@ -2207,9 +2192,8 @@ cluster_init_guc(void) gettext_noop("Overall external write-exclusion acquisition deadline (milliseconds)."), gettext_noop("One recovery attempt snapshots this deadline and shares it across all " "required victim admissions."), - &cluster_external_fence_acquire_timeout_ms, - PGRAC_EXTERNAL_FENCE_ACQUIRE_TIMEOUT_DEFAULT_MS, 1, 600000, - PGC_SIGHUP, GUC_UNIT_MS, NULL, NULL, NULL); + &cluster_external_fence_acquire_timeout_ms, PGRAC_EXTERNAL_FENCE_ACQUIRE_TIMEOUT_DEFAULT_MS, + 1, 600000, PGC_SIGHUP, GUC_UNIT_MS, NULL, NULL, NULL); /* * cluster.shared_data_dir -- shared data root for the cluster_fs diff --git a/src/backend/cluster/cluster_hw_remaster.c b/src/backend/cluster/cluster_hw_remaster.c index 6eb87f402ea..e75f7058e40 100644 --- a/src/backend/cluster/cluster_hw_remaster.c +++ b/src/backend/cluster/cluster_hw_remaster.c @@ -64,7 +64,7 @@ #include "storage/ipc.h" #include "utils/wait_event.h" -#include "cluster/cluster_conf.h" /* CLUSTER_MAX_NODES */ +#include "cluster/cluster_conf.h" /* CLUSTER_MAX_NODES */ #include "cluster/cluster_control_root.h" /* implementation: two-step root read (contract §A) */ #include "cluster/cluster_grd.h" #include "cluster/cluster_guc.h" /* cluster_node_id, cluster_wal_threads_dir */ @@ -72,10 +72,10 @@ #include "cluster/cluster_hw_remaster.h" #include "cluster/cluster_hw_snapshot.h" #include "cluster/cluster_semantic_activation.h" /* bit22 cutover latch (contract §B) */ -#include "cluster/cluster_thread_recovery.h" /* validated_end (torn-tail boundary) */ -#include "cluster/cluster_wal_state.h" /* read_slot (durable watermark) */ -#include "cluster/cluster_wal_thread.h" /* node id -> thread id */ -#include "cluster/storage/cluster_undo_xlog.h" /* xl_hw_reserve, XLOG_HW_RESERVE */ +#include "cluster/cluster_thread_recovery.h" /* validated_end (torn-tail boundary) */ +#include "cluster/cluster_wal_state.h" /* read_slot (durable watermark) */ +#include "cluster/cluster_wal_thread.h" /* node id -> thread id */ +#include "cluster/storage/cluster_undo_xlog.h" /* xl_hw_reserve, XLOG_HW_RESERVE */ /* One worker process owns exactly one dead origin / episode. */ static int hw_worker_dead_node = -1; @@ -511,8 +511,7 @@ cluster_hw_remaster_rebuild_origin(int dead_node_id, uint64 episode_epoch) * by exactly one survivor, so the lock-free read is the final * value (the minted-lost discriminator below stays intact: ABSENT * against a registry publication is still the danger state). */ - root_result = cluster_control_root_read_canonical_dead_origin( - dead_tid, &root_snap); + root_result = cluster_control_root_read_canonical_dead_origin(dead_tid, &root_snap); if (root_result != CLUSTER_CONTROL_ROOT_OK_PRIMARY && root_result != CLUSTER_CONTROL_ROOT_OK_PRIMARY_DEGRADED) { /* contract discriminator: the registry publication record. A @@ -532,7 +531,7 @@ cluster_hw_remaster_rebuild_origin(int dead_node_id, uint64 episode_epoch) * complete path below (the registry slot read either succeeds * or fails closed exactly as pre-bit22). */ } else { - validated_min = (XLogRecPtr) root_snap.validated_tail_lsn_exclusive; + validated_min = (XLogRecPtr)root_snap.validated_tail_lsn_exclusive; if (validated_min == 0) { cluster_hw_bump_failclosed(); ereport(LOG, (errmsg("cluster HW remaster: dead node %d canonical root has no " diff --git a/src/backend/cluster/cluster_ic.c b/src/backend/cluster/cluster_ic.c index 2efb400ba77..3ac2fba2efb 100644 --- a/src/backend/cluster/cluster_ic.c +++ b/src/backend/cluster/cluster_ic.c @@ -595,26 +595,17 @@ uint32 cluster_ic_local_capability_word(void) { uint32 capabilities - = PGRAC_IC_HELLO_CAP_UNDO_AUTHORITY_SERVE_V1 - | PGRAC_IC_HELLO_CAP_UNDO_HORIZON_V1 - | PGRAC_IC_HELLO_CAP_XID_NATIVE_DISABLE_V1 - | PGRAC_IC_HELLO_CAP_GCS_INVAL_BUSY_V1 - | PGRAC_IC_HELLO_CAP_UNDO_HORIZON_IDLE_V1 - | PGRAC_IC_HELLO_CAP_PCM_X_CONVERT_V1 - | PGRAC_IC_HELLO_CAP_PCM_X_REBASE_V1 - | PGRAC_IC_HELLO_CAP_PCM_X_SOURCE_FLOOR_V1 + = PGRAC_IC_HELLO_CAP_UNDO_AUTHORITY_SERVE_V1 | PGRAC_IC_HELLO_CAP_UNDO_HORIZON_V1 + | PGRAC_IC_HELLO_CAP_XID_NATIVE_DISABLE_V1 | PGRAC_IC_HELLO_CAP_GCS_INVAL_BUSY_V1 + | PGRAC_IC_HELLO_CAP_UNDO_HORIZON_IDLE_V1 | PGRAC_IC_HELLO_CAP_PCM_X_CONVERT_V1 + | PGRAC_IC_HELLO_CAP_PCM_X_REBASE_V1 | PGRAC_IC_HELLO_CAP_PCM_X_SOURCE_FLOOR_V1 | PGRAC_IC_HELLO_CAP_SEMANTIC_ACTIVATION_V1 - | PGRAC_IC_HELLO_CAP_SEMANTIC_ACTIVATION_ACK_V1 - | PGRAC_IC_HELLO_CAP_R4_SYNC_CR_V1 - | PGRAC_IC_HELLO_CAP_MULTIXACT_CURRENT_V1 - | PGRAC_IC_HELLO_CAP_GCS_RESOURCE_X_CONVERT_V1 - | PGRAC_IC_HELLO_CAP_CONTROL_ROOT_V1 - | PGRAC_IC_HELLO_CAP_CANDIDATE2_CORRECTED_A1_V1 - | PGRAC_IC_HELLO_CAP_UNDO_ROOT_DESCRIPTOR_V1 - | PGRAC_IC_HELLO_CAP_MULTIXACT_CTRC_V1; - - if (cluster_smart_fusion - && cluster_interconnect_tier == cluster_smart_fusion_tier_min) + | PGRAC_IC_HELLO_CAP_SEMANTIC_ACTIVATION_ACK_V1 | PGRAC_IC_HELLO_CAP_R4_SYNC_CR_V1 + | PGRAC_IC_HELLO_CAP_MULTIXACT_CURRENT_V1 | PGRAC_IC_HELLO_CAP_GCS_RESOURCE_X_CONVERT_V1 + | PGRAC_IC_HELLO_CAP_CONTROL_ROOT_V1 | PGRAC_IC_HELLO_CAP_CANDIDATE2_CORRECTED_A1_V1 + | PGRAC_IC_HELLO_CAP_UNDO_ROOT_DESCRIPTOR_V1 | PGRAC_IC_HELLO_CAP_MULTIXACT_CTRC_V1; + + if (cluster_smart_fusion && cluster_interconnect_tier == cluster_smart_fusion_tier_min) capabilities |= PGRAC_IC_HELLO_CAP_SMART_FUSION_REPLY_V2; if (!cluster_ic_suppress_caps_reply) capabilities |= PGRAC_IC_HELLO_CAP_CAPS_REPLY_V1; diff --git a/src/backend/cluster/cluster_ic_chunk.c b/src/backend/cluster/cluster_ic_chunk.c index 0303573bba2..0504f4dc0fa 100644 --- a/src/backend/cluster/cluster_ic_chunk.c +++ b/src/backend/cluster/cluster_ic_chunk.c @@ -44,8 +44,8 @@ #include "cluster/cluster_conf.h" /* CLUSTER_MAX_NODES */ #include "cluster/cluster_clean_leave.h" -#include "cluster/cluster_guc.h" /* cluster_node_id */ -#include "cluster/cluster_ic.h" /* cluster_ic_send_bytes */ +#include "cluster/cluster_guc.h" /* cluster_node_id */ +#include "cluster/cluster_ic.h" /* cluster_ic_send_bytes */ #include "cluster/cluster_ic_chunk.h" #include "cluster/cluster_ic_envelope.h" #include "cluster/cluster_ic_router.h" @@ -230,11 +230,9 @@ cluster_ic_send_envelope_chunked(uint8 inner_msg_type, int32 dest_node_id, const inner_msg_type, inner_info->name))); if ((ClusterICPlane)inner_info->plane == CLUSTER_IC_PLANE_DATA - && cluster_authority_readiness_managed() - && !cluster_serving_ready_is_current()) { - ereport(ERROR, - (errcode(ERRCODE_CLUSTER_LMS_UNAVAILABLE), - errmsg("cluster IC chunked data plane is not serving-ready"))); + && cluster_authority_readiness_managed() && !cluster_serving_ready_is_current()) { + ereport(ERROR, (errcode(ERRCODE_CLUSTER_LMS_UNAVAILABLE), + errmsg("cluster IC chunked data plane is not serving-ready"))); return false; } } diff --git a/src/backend/cluster/cluster_ic_rdma.c b/src/backend/cluster/cluster_ic_rdma.c index e9055e772e2..6cb4e7f24fe 100644 --- a/src/backend/cluster/cluster_ic_rdma.c +++ b/src/backend/cluster/cluster_ic_rdma.c @@ -2385,12 +2385,10 @@ cluster_ic_rdma_send_envelope_sge(uint8 msg_type, int32 dest_node_id, msg_type, info->name, (int)MyBackendType))); if ((ClusterICPlane)info->plane == CLUSTER_IC_PLANE_DATA - && cluster_authority_readiness_managed() - && !cluster_serving_ready_is_current()) { + && cluster_authority_readiness_managed() && !cluster_serving_ready_is_current()) { rdma_release_sge_callbacks(payload_sge, n_sge); - ereport(ERROR, - (errcode(ERRCODE_CLUSTER_LMS_UNAVAILABLE), - errmsg("cluster IC RDMA data plane is not serving-ready"))); + ereport(ERROR, (errcode(ERRCODE_CLUSTER_LMS_UNAVAILABLE), + errmsg("cluster IC RDMA data plane is not serving-ready"))); return CLUSTER_IC_SEND_HARD_ERROR; } diff --git a/src/backend/cluster/cluster_ic_router.c b/src/backend/cluster/cluster_ic_router.c index e972030d25d..3337e7dee85 100644 --- a/src/backend/cluster/cluster_ic_router.c +++ b/src/backend/cluster/cluster_ic_router.c @@ -59,8 +59,8 @@ #include "cluster/cluster_ic_envelope.h" #include "cluster/cluster_ic_rdma.h" #include "cluster/cluster_ic_router.h" -#include "cluster/cluster_ic_tier1.h" /* cluster_ic_tier1_get_peer_fd (spec-2.5 D2.5 fanout) */ -#include "cluster/cluster_lms.h" /* PGRAC: spec-7.3 D8 per-worker dispatch counter */ +#include "cluster/cluster_ic_tier1.h" /* cluster_ic_tier1_get_peer_fd (spec-2.5 D2.5 fanout) */ +#include "cluster/cluster_lms.h" /* PGRAC: spec-7.3 D8 per-worker dispatch counter */ #include "cluster/cluster_startup_phase.h" #include "cluster/cluster_xnode_profile.h" /* PGRAC: spec-5.59 D6 profiling */ @@ -202,8 +202,7 @@ cluster_ic_send_envelope(uint8 msg_type, int32 dest_node_id, const void *payload /* Scheme A service split: DATA is an ordinary serving capability, not * implied by CSSD ALIVE, quorum, MEMBER, or recovery LMS transport. */ if (!is_chunk_wrap && (ClusterICPlane)info->plane == CLUSTER_IC_PLANE_DATA - && cluster_authority_readiness_managed() - && !cluster_serving_ready_is_current()) + && cluster_authority_readiness_managed() && !cluster_serving_ready_is_current()) return CLUSTER_IC_SEND_HARD_ERROR; /* (3) dest = self -- short-circuit no-op success. spec-2.2 stub @@ -374,8 +373,7 @@ cluster_ic_dispatch_envelope(const ClusterICEnvelope *env, const void *payload, * because the authenticated peer connection is healthy; only the frame's * serving capability is absent. */ if ((ClusterICPlane)info->plane == CLUSTER_IC_PLANE_DATA - && cluster_authority_readiness_managed() - && !cluster_serving_ready_is_current()) + && cluster_authority_readiness_managed() && !cluster_serving_ready_is_current()) return true; /* diff --git a/src/backend/cluster/cluster_inject.c b/src/backend/cluster/cluster_inject.c index c23e95b997b..20761eda95e 100644 --- a/src/backend/cluster/cluster_inject.c +++ b/src/backend/cluster/cluster_inject.c @@ -1634,24 +1634,20 @@ cluster_inject_fault(PG_FUNCTION_ARGS) } } - if (strcmp(name, "cluster-ctrc-stage-barrier") == 0) - { + if (strcmp(name, "cluster-ctrc-stage-barrier") == 0) { bool armed = new_type != CLUSTER_FAULT_NONE; - if (armed && (new_type != CLUSTER_FAULT_SKIP - || param <= CTRC_TEST_BARRIER_NONE - || param >= CTRC_TEST_BARRIER_COUNT)) + if (armed + && (new_type != CLUSTER_FAULT_SKIP || param <= CTRC_TEST_BARRIER_NONE + || param >= CTRC_TEST_BARRIER_COUNT)) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("cluster-ctrc-stage-barrier requires fault_type skip and phase 1..%d", CTRC_TEST_BARRIER_COUNT - 1))); if (!cluster_ctrc_test_barrier_control( - armed ? (ClusterCtrcTestBarrierPhase)param - : CTRC_TEST_BARRIER_NONE, - armed)) - ereport(ERROR, - (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), - errmsg("CTRC shared test barrier is unavailable"))); + armed ? (ClusterCtrcTestBarrierPhase)param : CTRC_TEST_BARRIER_NONE, armed)) + ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), + errmsg("CTRC shared test barrier is unavailable"))); } cluster_injection_arm_internal(p, new_type, param); diff --git a/src/backend/cluster/cluster_ir.c b/src/backend/cluster/cluster_ir.c index 3bc79bf2866..dec0fb6fd44 100644 --- a/src/backend/cluster/cluster_ir.c +++ b/src/backend/cluster/cluster_ir.c @@ -28,8 +28,7 @@ #include "cluster/cluster_recovery_duty.h" bool -cluster_recovery_serial_resid_encode(const ClusterRecoveryDutyKey *duty, - ClusterResId *out) +cluster_recovery_serial_resid_encode(const ClusterRecoveryDutyKey *duty, ClusterResId *out) { ClusterResId encoded; diff --git a/src/backend/cluster/cluster_ir_lock.c b/src/backend/cluster/cluster_ir_lock.c index 6c78a68d6e0..2681c6f591c 100644 --- a/src/backend/cluster/cluster_ir_lock.c +++ b/src/backend/cluster/cluster_ir_lock.c @@ -69,10 +69,9 @@ cluster_ir_shmem_init(void) MAXALIGN(sizeof(ClusterIrShared)), &found); if (!IsUnderPostmaster) { ir_base_timeout_ms - = (cluster_ges_request_timeout_ms >= 1 - && cluster_ges_request_timeout_ms <= 600000) - ? cluster_ges_request_timeout_ms - : 600000; + = (cluster_ges_request_timeout_ms >= 1 && cluster_ges_request_timeout_ms <= 600000) + ? cluster_ges_request_timeout_ms + : 600000; pg_atomic_init_u64(&ir_state->grant_count, 0); pg_atomic_init_u64(&ir_state->busy_count, 0); pg_atomic_init_u64(&ir_state->retry_count, 0); @@ -125,91 +124,69 @@ cluster_recovery_serial_retry_count(void) uint64 cluster_recovery_serial_revalidate_reject_count(void) { - return ir_state != NULL - ? pg_atomic_read_u64(&ir_state->revalidate_reject_count) - : 0; + return ir_state != NULL ? pg_atomic_read_u64(&ir_state->revalidate_reject_count) : 0; } uint64 cluster_recovery_serial_node_cleanup_wait_count(void) { - return ir_state != NULL - ? pg_atomic_read_u64(&ir_state->node_cleanup_wait_count) - : 0; + return ir_state != NULL ? pg_atomic_read_u64(&ir_state->node_cleanup_wait_count) : 0; } uint64 cluster_recovery_serial_release_confirmed_count(void) { - return ir_state != NULL - ? pg_atomic_read_u64(&ir_state->release_confirmed_count) - : 0; + return ir_state != NULL ? pg_atomic_read_u64(&ir_state->release_confirmed_count) : 0; } uint64 cluster_recovery_serial_release_unconfirmed_count(void) { - return ir_state != NULL - ? pg_atomic_read_u64(&ir_state->release_unconfirmed_count) - : 0; + return ir_state != NULL ? pg_atomic_read_u64(&ir_state->release_unconfirmed_count) : 0; } uint64 cluster_recovery_serial_cold_set_grant_count(void) { - return ir_state != NULL - ? pg_atomic_read_u64(&ir_state->cold_set_grant_count) - : 0; + return ir_state != NULL ? pg_atomic_read_u64(&ir_state->cold_set_grant_count) : 0; } uint64 cluster_recovery_serial_capability_denied_count(void) { - return ir_state != NULL - ? pg_atomic_read_u64(&ir_state->capability_denied_count) - : 0; + return ir_state != NULL ? pg_atomic_read_u64(&ir_state->capability_denied_count) : 0; } uint64 cluster_recovery_serial_native_result_rejected_count(void) { - return ir_state != NULL - ? pg_atomic_read_u64(&ir_state->native_result_rejected_count) - : 0; + return ir_state != NULL ? pg_atomic_read_u64(&ir_state->native_result_rejected_count) : 0; } static bool -recovery_serial_root_token_matches_duty( - const ClusterControlRootReadToken *token, - const ClusterRecoveryDutyKey *duty) +recovery_serial_root_token_matches_duty(const ClusterControlRootReadToken *token, + const ClusterRecoveryDutyKey *duty) { - uint32 required_flags = CLUSTER_CONTROL_ROOT_FLAG_CLAIM_VALID - | CLUSTER_CONTROL_ROOT_FLAG_CHECKPOINT_VALID - | CLUSTER_CONTROL_ROOT_FLAG_TAIL_VALID - | CLUSTER_CONTROL_ROOT_FLAG_RECOVERED_VALID; - - return token != NULL && duty != NULL - && token->origin_thread_id == duty->origin_thread_id - && token->root_lineage_seq == duty->root_lineage_seq - && memcmp(token->authority_uuid, duty->authority_uuid, - sizeof(token->authority_uuid)) == 0 - && token->lifecycle - == CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_REQUIRED - && token->reserved20 == 0 && token->reserved32 == 0 - && token->file_txn_seq != 0 && token->root_publish_seq != 0 - && token->record_crc32c != 0 - && (token->root_flags & required_flags) == required_flags; + uint32 required_flags + = CLUSTER_CONTROL_ROOT_FLAG_CLAIM_VALID | CLUSTER_CONTROL_ROOT_FLAG_CHECKPOINT_VALID + | CLUSTER_CONTROL_ROOT_FLAG_TAIL_VALID | CLUSTER_CONTROL_ROOT_FLAG_RECOVERED_VALID; + + return token != NULL && duty != NULL && token->origin_thread_id == duty->origin_thread_id + && token->root_lineage_seq == duty->root_lineage_seq + && memcmp(token->authority_uuid, duty->authority_uuid, sizeof(token->authority_uuid)) + == 0 + && token->lifecycle == CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_REQUIRED + && token->reserved20 == 0 && token->reserved32 == 0 && token->file_txn_seq != 0 + && token->root_publish_seq != 0 && token->record_crc32c != 0 + && (token->root_flags & required_flags) == required_flags; } static bool recovery_serial_request_valid(const ClusterRecoverySerialRequest *request) { return request != NULL - && (request->mode == CLUSTER_RECOVERY_SERIAL_ONLINE - || request->mode == CLUSTER_RECOVERY_SERIAL_COLD_FORMED) - && cluster_recovery_duty_key_valid_v1(&request->duty) - && recovery_serial_root_token_matches_duty( - &request->expected_root_token, &request->duty) - && request->formation != NULL && request->fence_need_set != NULL - && request->fence_admission_set != NULL - && request->acquire_timeout_ms >= 1 - && request->acquire_timeout_ms <= 600000 - && request->release_timeout_ms >= 1 - && request->release_timeout_ms <= 600000; + && (request->mode == CLUSTER_RECOVERY_SERIAL_ONLINE + || request->mode == CLUSTER_RECOVERY_SERIAL_COLD_FORMED) + && cluster_recovery_duty_key_valid_v1(&request->duty) + && recovery_serial_root_token_matches_duty(&request->expected_root_token, &request->duty) + && request->formation != NULL && request->fence_need_set != NULL + && request->fence_admission_set != NULL && request->acquire_timeout_ms >= 1 + && request->acquire_timeout_ms <= 600000 && request->release_timeout_ms >= 1 + && request->release_timeout_ms <= 600000; } static bool @@ -221,32 +198,25 @@ recovery_serial_release_guard_valid(const ClusterRecoverySerialGuard *guard) || (guard->mode != CLUSTER_RECOVERY_SERIAL_ONLINE && guard->mode != CLUSTER_RECOVERY_SERIAL_COLD_FORMED) || guard->formation == NULL || guard->fence_need_set == NULL - || guard->fence_admission_set == NULL - || guard->release_timeout_ms < 1 - || guard->release_timeout_ms > 600000 - || !cluster_recovery_duty_key_valid_v1(&guard->duty) - || !cluster_recovery_serial_resid_encode(&guard->duty, - &expected_resid) + || guard->fence_admission_set == NULL || guard->release_timeout_ms < 1 + || guard->release_timeout_ms > 600000 || !cluster_recovery_duty_key_valid_v1(&guard->duty) + || !cluster_recovery_serial_resid_encode(&guard->duty, &expected_resid) || memcmp(&guard->resid, &expected_resid, sizeof(expected_resid)) != 0 - || memcmp(&guard->lock_request.resid, &guard->resid, - sizeof(guard->resid)) != 0 + || memcmp(&guard->lock_request.resid, &guard->resid, sizeof(guard->resid)) != 0 || guard->lock_request.lockmode != ExclusiveLock || guard->lock_request.op != CLUSTER_LOCK_OP_REQUEST || guard->lock_request.current_mode != NoLock - || guard->lock_request.lockmethod_id != DEFAULT_LOCKMETHOD - || !guard->lock_request.dontwait || guard->lock_request.sessionLock - || guard->lock_request.request_id == 0 - || guard->lock_request.holder.request_id - != guard->lock_request.request_id + || guard->lock_request.lockmethod_id != DEFAULT_LOCKMETHOD || !guard->lock_request.dontwait + || guard->lock_request.sessionLock || guard->lock_request.request_id == 0 + || guard->lock_request.holder.request_id != guard->lock_request.request_id || guard->lock_request.holder.cluster_epoch == 0 - || !recovery_serial_root_token_matches_duty( - &guard->root_read_token, &guard->duty)) + || !recovery_serial_root_token_matches_duty(&guard->root_read_token, &guard->duty)) return false; return true; } -static ClusterRecoverySerialReleaseResult recovery_serial_release_with_timeout( - ClusterRecoverySerialGuard *guard, int timeout_ms); +static ClusterRecoverySerialReleaseResult +recovery_serial_release_with_timeout(ClusterRecoverySerialGuard *guard, int timeout_ms); static ClusterRecoverySerialAcquireResult recovery_serial_preflight(const ClusterRecoverySerialRequest *request) @@ -255,33 +225,29 @@ recovery_serial_preflight(const ClusterRecoverySerialRequest *request) ClusterControlRootReadToken token; ClusterControlRootResult root_result; PgracExternalFenceDenyReason reason; - uint32 required_flags = CLUSTER_CONTROL_ROOT_FLAG_CLAIM_VALID - | CLUSTER_CONTROL_ROOT_FLAG_CHECKPOINT_VALID - | CLUSTER_CONTROL_ROOT_FLAG_TAIL_VALID - | CLUSTER_CONTROL_ROOT_FLAG_RECOVERED_VALID; - - root_result = cluster_control_root_read_canonical( - request->duty.origin_thread_id, &request->duty, - CLUSTER_CONTROL_ROOT_READ_STRONG, &snapshot, &token); - if (root_result != CLUSTER_CONTROL_ROOT_OK_PRIMARY && - root_result != CLUSTER_CONTROL_ROOT_OK_PRIMARY_DEGRADED) + uint32 required_flags + = CLUSTER_CONTROL_ROOT_FLAG_CLAIM_VALID | CLUSTER_CONTROL_ROOT_FLAG_CHECKPOINT_VALID + | CLUSTER_CONTROL_ROOT_FLAG_TAIL_VALID | CLUSTER_CONTROL_ROOT_FLAG_RECOVERED_VALID; + + root_result + = cluster_control_root_read_canonical(request->duty.origin_thread_id, &request->duty, + CLUSTER_CONTROL_ROOT_READ_STRONG, &snapshot, &token); + if (root_result != CLUSTER_CONTROL_ROOT_OK_PRIMARY + && root_result != CLUSTER_CONTROL_ROOT_OK_PRIMARY_DEGRADED) return CLUSTER_RECOVERY_SERIAL_ROOT_UNAVAILABLE; - if (cluster_recovery_duty_key_compare(&snapshot.identity, - &request->duty) != - CLUSTER_RECOVERY_DUTY_COMPARE_EXACT || - snapshot.lifecycle != - CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_REQUIRED || - (snapshot.root_flags & required_flags) != required_flags || - memcmp(&token, &request->expected_root_token, sizeof(token)) != 0) + if (cluster_recovery_duty_key_compare(&snapshot.identity, &request->duty) + != CLUSTER_RECOVERY_DUTY_COMPARE_EXACT + || snapshot.lifecycle != CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_REQUIRED + || (snapshot.root_flags & required_flags) != required_flags + || memcmp(&token, &request->expected_root_token, sizeof(token)) != 0) return CLUSTER_RECOVERY_SERIAL_STALE; - if (cluster_formation_witness_revalidate_nowait(request->formation) != - CLUSTER_FORMATION_WITNESS_READY) + if (cluster_formation_witness_revalidate_nowait(request->formation) + != CLUSTER_FORMATION_WITNESS_READY) return CLUSTER_RECOVERY_SERIAL_STALE; - if (!cluster_external_fence_need_set_revalidate_nowait( - request->fence_need_set, request->formation, &reason) || - !cluster_external_fence_revalidate_set_nowait( - request->fence_admission_set, request->fence_need_set, - request->formation, &reason)) + if (!cluster_external_fence_need_set_revalidate_nowait(request->fence_need_set, + request->formation, &reason) + || !cluster_external_fence_revalidate_set_nowait( + request->fence_admission_set, request->fence_need_set, request->formation, &reason)) return CLUSTER_RECOVERY_SERIAL_FENCE_DENIED; return CLUSTER_RECOVERY_SERIAL_GRANTED; } @@ -295,8 +261,7 @@ cluster_recovery_serial_acquire(const ClusterRecoverySerialRequest *request, ClusterLockAcquireResult lock_result; ClusterResId resid; PgracExternalFenceDenyReason reason; - ClusterRecoverySerialRevalidateResult stale_result = - CLUSTER_RECOVERY_SERIAL_CURRENT; + ClusterRecoverySerialRevalidateResult stale_result = CLUSTER_RECOVERY_SERIAL_CURRENT; if (guard == NULL) return CLUSTER_RECOVERY_SERIAL_INTERNAL_FAILURE; @@ -304,11 +269,10 @@ cluster_recovery_serial_acquire(const ClusterRecoverySerialRequest *request, if (!recovery_serial_request_valid(request)) return CLUSTER_RECOVERY_SERIAL_INTERNAL_FAILURE; preflight = recovery_serial_preflight(request); - if (preflight != CLUSTER_RECOVERY_SERIAL_GRANTED) - { - if (preflight == CLUSTER_RECOVERY_SERIAL_STALE || - preflight == CLUSTER_RECOVERY_SERIAL_ROOT_UNAVAILABLE || - preflight == CLUSTER_RECOVERY_SERIAL_CAPABILITY_UNAVAILABLE) + if (preflight != CLUSTER_RECOVERY_SERIAL_GRANTED) { + if (preflight == CLUSTER_RECOVERY_SERIAL_STALE + || preflight == CLUSTER_RECOVERY_SERIAL_ROOT_UNAVAILABLE + || preflight == CLUSTER_RECOVERY_SERIAL_CAPABILITY_UNAVAILABLE) IR_BUMP(capability_denied_count); return preflight; } @@ -324,29 +288,24 @@ cluster_recovery_serial_acquire(const ClusterRecoverySerialRequest *request, lock_request.dontwait = true; lock_request.sessionLock = false; lock_request.recovery_bootstrap = true; - lock_request.caller_local_start_ts_ms = - (uint64)(GetCurrentTimestamp() / 1000); - lock_request.timeout_ms = Min(request->acquire_timeout_ms, - ir_base_timeout_ms); + lock_request.caller_local_start_ts_ms = (uint64)(GetCurrentTimestamp() / 1000); + lock_request.timeout_ms = Min(request->acquire_timeout_ms, ir_base_timeout_ms); lock_request.wait_event = WAIT_EVENT_CLUSTER_GES_REPLY_WAIT; lock_result = cluster_lock_acquire_seven_step(&lock_request); - if (lock_result == CLUSTER_LOCK_ACQUIRE_NOT_AVAIL) - { + if (lock_result == CLUSTER_LOCK_ACQUIRE_NOT_AVAIL) { IR_BUMP(busy_count); return CLUSTER_RECOVERY_SERIAL_BUSY; } - if (lock_result == CLUSTER_LOCK_ACQUIRE_OK_NATIVE) - { + if (lock_result == CLUSTER_LOCK_ACQUIRE_OK_NATIVE) { IR_BUMP(native_result_rejected_count); IR_BUMP(retry_count); return CLUSTER_RECOVERY_SERIAL_RETRY; } if (lock_result == CLUSTER_LOCK_ACQUIRE_NEED_PG_NATIVE_LOCK) lock_result = cluster_lock_acquire_s5_promote(&lock_request); - if (lock_result != CLUSTER_LOCK_ACQUIRE_OK_GRANTED && - lock_result != CLUSTER_LOCK_ACQUIRE_OK_CONVERTED) - { + if (lock_result != CLUSTER_LOCK_ACQUIRE_OK_GRANTED + && lock_result != CLUSTER_LOCK_ACQUIRE_OK_CONVERTED) { IR_BUMP(retry_count); return CLUSTER_RECOVERY_SERIAL_RETRY; } @@ -366,28 +325,25 @@ cluster_recovery_serial_acquire(const ClusterRecoverySerialRequest *request, /* Post-grant checks are strictly no-wait: the authority holder must not * cross its first mutation gate on a proof that expired while IR was being * registered. */ - if (cluster_formation_witness_revalidate_nowait(guard->formation) != - CLUSTER_FORMATION_WITNESS_READY || - !cluster_external_fence_need_set_revalidate_nowait( - guard->fence_need_set, guard->formation, &reason)) + if (cluster_formation_witness_revalidate_nowait(guard->formation) + != CLUSTER_FORMATION_WITNESS_READY + || !cluster_external_fence_need_set_revalidate_nowait(guard->fence_need_set, + guard->formation, &reason)) stale_result = CLUSTER_RECOVERY_SERIAL_MEMBERSHIP_STALE; else if (!cluster_external_fence_revalidate_set_nowait( - guard->fence_admission_set, guard->fence_need_set, - guard->formation, &reason)) + guard->fence_admission_set, guard->fence_need_set, guard->formation, &reason)) stale_result = CLUSTER_RECOVERY_SERIAL_FENCE_STALE; - if (stale_result != CLUSTER_RECOVERY_SERIAL_CURRENT) - { - ClusterRecoverySerialReleaseResult release_result = - recovery_serial_release_with_timeout( - guard, guard->release_timeout_ms); + if (stale_result != CLUSTER_RECOVERY_SERIAL_CURRENT) { + ClusterRecoverySerialReleaseResult release_result + = recovery_serial_release_with_timeout(guard, guard->release_timeout_ms); IR_BUMP(revalidate_reject_count); if (release_result != CLUSTER_RECOVERY_SERIAL_RELEASE_CONFIRMED) return CLUSTER_RECOVERY_SERIAL_INTERNAL_FAILURE; memset(guard, 0, sizeof(*guard)); return stale_result == CLUSTER_RECOVERY_SERIAL_MEMBERSHIP_STALE - ? CLUSTER_RECOVERY_SERIAL_STALE - : CLUSTER_RECOVERY_SERIAL_FENCE_DENIED; + ? CLUSTER_RECOVERY_SERIAL_STALE + : CLUSTER_RECOVERY_SERIAL_FENCE_DENIED; } IR_BUMP(grant_count); return CLUSTER_RECOVERY_SERIAL_GRANTED; @@ -407,20 +363,17 @@ cluster_recovery_serial_revalidate(ClusterRecoverySerialGuard *guard) return CLUSTER_RECOVERY_SERIAL_FENCE_STALE; } - if (cluster_formation_witness_revalidate_nowait(guard->formation) != - CLUSTER_FORMATION_WITNESS_READY || - !cluster_external_fence_need_set_revalidate_nowait( + if (cluster_formation_witness_revalidate_nowait(guard->formation) + != CLUSTER_FORMATION_WITNESS_READY + || !cluster_external_fence_need_set_revalidate_nowait( guard->fence_need_set, guard->formation, - &(PgracExternalFenceDenyReason){ PGRAC_EXTERNAL_FENCE_DENY_NONE })) - { + &(PgracExternalFenceDenyReason){ PGRAC_EXTERNAL_FENCE_DENY_NONE })) { IR_BUMP(revalidate_reject_count); return CLUSTER_RECOVERY_SERIAL_MEMBERSHIP_STALE; } if (!cluster_external_fence_revalidate_set_nowait( - guard->fence_admission_set, guard->fence_need_set, - guard->formation, - &(PgracExternalFenceDenyReason){ PGRAC_EXTERNAL_FENCE_DENY_NONE })) - { + guard->fence_admission_set, guard->fence_need_set, guard->formation, + &(PgracExternalFenceDenyReason){ PGRAC_EXTERNAL_FENCE_DENY_NONE })) { IR_BUMP(revalidate_reject_count); return CLUSTER_RECOVERY_SERIAL_FENCE_STALE; } @@ -428,10 +381,9 @@ cluster_recovery_serial_revalidate(ClusterRecoverySerialGuard *guard) } ClusterRecoverySerialAcquireResult -cluster_recovery_serial_acquire_set( - const ClusterRecoverySerialRequest *requests, uint16 count, - int overall_acquire_timeout_ms, ClusterRecoverySerialGuardSet *set, - uint16 *failed_index) +cluster_recovery_serial_acquire_set(const ClusterRecoverySerialRequest *requests, uint16 count, + int overall_acquire_timeout_ms, + ClusterRecoverySerialGuardSet *set, uint16 *failed_index) { instr_time started; uint16 i; @@ -442,18 +394,13 @@ cluster_recovery_serial_acquire_set( return CLUSTER_RECOVERY_SERIAL_INTERNAL_FAILURE; memset(set, 0, sizeof(*set)); if (failed_index == NULL || requests == NULL || count == 0 - || count > CLUSTER_RECOVERY_SERIAL_SET_MAX - || overall_acquire_timeout_ms < 1 + || count > CLUSTER_RECOVERY_SERIAL_SET_MAX || overall_acquire_timeout_ms < 1 || overall_acquire_timeout_ms > 600000) return CLUSTER_RECOVERY_SERIAL_INTERNAL_FAILURE; for (i = 0; i < count; i++) { if (!recovery_serial_request_valid(&requests[i]) - || (i > 0 - && requests[i - 1].duty.origin_thread_id - >= requests[i].duty.origin_thread_id) - || (i > 0 - && requests[i - 1].release_timeout_ms - != requests[i].release_timeout_ms)) + || (i > 0 && requests[i - 1].duty.origin_thread_id >= requests[i].duty.origin_thread_id) + || (i > 0 && requests[i - 1].release_timeout_ms != requests[i].release_timeout_ms)) return CLUSTER_RECOVERY_SERIAL_INTERNAL_FAILURE; } @@ -490,8 +437,7 @@ cluster_recovery_serial_acquire_set( } *failed_index = i; rollback_result = cluster_recovery_serial_release_set(set); - if (rollback_result - != CLUSTER_RECOVERY_SERIAL_RELEASE_CONFIRMED) + if (rollback_result != CLUSTER_RECOVERY_SERIAL_RELEASE_CONFIRMED) return CLUSTER_RECOVERY_SERIAL_INTERNAL_FAILURE; return result; } @@ -506,8 +452,7 @@ cluster_recovery_serial_acquire_set( } static ClusterRecoverySerialReleaseResult -recovery_serial_release_with_timeout(ClusterRecoverySerialGuard *guard, - int timeout_ms) +recovery_serial_release_with_timeout(ClusterRecoverySerialGuard *guard, int timeout_ms) { ClusterLockAcquireRequest release_request; ClusterLockAcquireResult result; @@ -516,8 +461,7 @@ recovery_serial_release_with_timeout(ClusterRecoverySerialGuard *guard, return CLUSTER_RECOVERY_SERIAL_RELEASE_INVALID; if (!guard->held && !guard->release_uncertain) return CLUSTER_RECOVERY_SERIAL_RELEASE_NOT_HELD; - if (!recovery_serial_release_guard_valid(guard) || timeout_ms < 1 - || timeout_ms > 600000) + if (!recovery_serial_release_guard_valid(guard) || timeout_ms < 1 || timeout_ms > 600000) return CLUSTER_RECOVERY_SERIAL_RELEASE_INVALID; release_request = guard->lock_request; @@ -540,8 +484,7 @@ cluster_recovery_serial_release(ClusterRecoverySerialGuard *guard) { if (guard == NULL) return CLUSTER_RECOVERY_SERIAL_RELEASE_INVALID; - return recovery_serial_release_with_timeout(guard, - guard->release_timeout_ms); + return recovery_serial_release_with_timeout(guard, guard->release_timeout_ms); } ClusterRecoverySerialReleaseResult @@ -557,17 +500,15 @@ cluster_recovery_serial_release_set(ClusterRecoverySerialGuardSet *set) return CLUSTER_RECOVERY_SERIAL_RELEASE_INVALID; if (set->count == 0) return CLUSTER_RECOVERY_SERIAL_RELEASE_NOT_HELD; - if (set->count > CLUSTER_RECOVERY_SERIAL_SET_MAX - || set->release_timeout_ms < 1 + if (set->count > CLUSTER_RECOVERY_SERIAL_SET_MAX || set->release_timeout_ms < 1 || set->release_timeout_ms > 600000) return CLUSTER_RECOVERY_SERIAL_RELEASE_INVALID; for (i = 0; i < set->count; i++) { if (!recovery_serial_release_guard_valid(&set->guards[i]) - || set->guards[i].release_timeout_ms - != set->release_timeout_ms + || set->guards[i].release_timeout_ms != set->release_timeout_ms || (i > 0 && set->guards[i - 1].duty.origin_thread_id - >= set->guards[i].duty.origin_thread_id)) + >= set->guards[i].duty.origin_thread_id)) return CLUSTER_RECOVERY_SERIAL_RELEASE_INVALID; } @@ -606,8 +547,7 @@ cluster_recovery_serial_release_set(ClusterRecoverySerialGuardSet *set) survivors++; } } - memset(&set->guards[survivors], 0, - sizeof(set->guards) - sizeof(set->guards[0]) * survivors); + memset(&set->guards[survivors], 0, sizeof(set->guards) - sizeof(set->guards[0]) * survivors); set->count = survivors; if (unconfirmed || survivors != 0) return CLUSTER_RECOVERY_SERIAL_RELEASE_UNCONFIRMED; diff --git a/src/backend/cluster/cluster_itl_cleanout.c b/src/backend/cluster/cluster_itl_cleanout.c index 93912b6d980..042f2629f1c 100644 --- a/src/backend/cluster/cluster_itl_cleanout.c +++ b/src/backend/cluster/cluster_itl_cleanout.c @@ -63,8 +63,7 @@ cluster_itl_cleanout_can_stamp(const ClusterItlSlotData *slot, TransactionId exp { if (slot == NULL) return false; - if (slot->flags != ITL_FLAG_ACTIVE - && slot->flags != ITL_FLAG_NEEDS_CLEANOUT) + if (slot->flags != ITL_FLAG_ACTIVE && slot->flags != ITL_FLAG_NEEDS_CLEANOUT) return false; if (slot->xid != expected_xid) return false; @@ -75,12 +74,10 @@ cluster_itl_cleanout_can_stamp(const ClusterItlSlotData *slot, TransactionId exp */ if (!SCN_VALID(expected_commit_scn)) return false; - if (slot->flags == ITL_FLAG_ACTIVE) - { + if (slot->flags == ITL_FLAG_ACTIVE) { if (SCN_VALID(slot->commit_scn)) return false; - } - else if (slot->commit_scn != expected_commit_scn) + } else if (slot->commit_scn != expected_commit_scn) return false; return true; } diff --git a/src/backend/cluster/cluster_itl_touch.c b/src/backend/cluster/cluster_itl_touch.c index e94a4134885..60bed56283b 100644 --- a/src/backend/cluster/cluster_itl_touch.c +++ b/src/backend/cluster/cluster_itl_touch.c @@ -57,7 +57,7 @@ #include "cluster/cluster_guc.h" /* cluster_enabled */ #include "cluster/cluster_itl.h" /* stamp_committed / stamp_aborted */ #include "cluster/cluster_itl_touch.h" -#include "cluster/cluster_mode.h" /* cluster_storage_mode_enabled */ +#include "cluster/cluster_mode.h" /* cluster_storage_mode_enabled */ #include "cluster/cluster_sf_dep.h" #include "cluster/cluster_xnode_lever.h" /* stamp-skip counter */ #include "storage/bufmgr.h" @@ -95,8 +95,7 @@ itl_touch_handle_matches(const ClusterItlTouchHandle *left, const ClusterItlTouc * applied its dedupe policy. */ static void -itl_touch_append(const ClusterItlTouchHandle *handle, - const ClusterItlTerminalProof *proof, +itl_touch_append(const ClusterItlTouchHandle *handle, const ClusterItlTerminalProof *proof, const ClusterCtrcReceiptHandle *ctrc_handle) { if (touch_list == NULL) { @@ -119,8 +118,7 @@ itl_touch_append(const ClusterItlTouchHandle *handle, touch_list[touch_count].key = *handle; touch_list[touch_count].proof = *proof; - MemSet(&touch_list[touch_count].ctrc_handle, 0, - sizeof(touch_list[touch_count].ctrc_handle)); + MemSet(&touch_list[touch_count].ctrc_handle, 0, sizeof(touch_list[touch_count].ctrc_handle)); if (ctrc_handle != NULL && ctrc_handle->valid) touch_list[touch_count].ctrc_handle = *ctrc_handle; touch_count++; @@ -203,7 +201,7 @@ itl_touch_capture_proof(const ClusterItlTouchHandle *handle, Buffer buffer, Tran InitBufferTag(&expected_tag, &handle->rloc, handle->forknum, handle->block); if (!cluster_bufmgr_terminal_stamp_authority(buffer, &expected_tag, &own_generation, - &acquisition_epoch, &pcm_state)) + &acquisition_epoch, &pcm_state)) return; proof->own_generation = own_generation; @@ -213,9 +211,8 @@ itl_touch_capture_proof(const ClusterItlTouchHandle *handle, Buffer buffer, Tran } static void -itl_touch_register_exact_internal(const ClusterItlTouchHandle *handle, - Buffer buffer, TransactionId xid, - const ClusterCtrcReceiptHandle *ctrc_handle) +itl_touch_register_exact_internal(const ClusterItlTouchHandle *handle, Buffer buffer, + TransactionId xid, const ClusterCtrcReceiptHandle *ctrc_handle) { ClusterItlTerminalProof proof; uint32 range_start = 0; @@ -252,13 +249,11 @@ itl_touch_register_exact_internal(const ClusterItlTouchHandle *handle, */ existing->key.flags |= (handle->flags & CLUSTER_ITL_TOUCH_FLAG_NEEDS_WAL); MemSet(&existing->ctrc_handle, 0, sizeof(existing->ctrc_handle)); - if (proof.valid) - { + if (proof.valid) { existing->proof = proof; if (ctrc_handle != NULL && ctrc_handle->valid) existing->ctrc_handle = *ctrc_handle; - } - else + } else existing->proof.valid = false; return; } @@ -276,16 +271,16 @@ itl_touch_register_exact_internal(const ClusterItlTouchHandle *handle, } void -cluster_itl_touch_register_exact(const ClusterItlTouchHandle *handle, - Buffer buffer, TransactionId xid) +cluster_itl_touch_register_exact(const ClusterItlTouchHandle *handle, Buffer buffer, + TransactionId xid) { itl_touch_register_exact_internal(handle, buffer, xid, NULL); } void -cluster_itl_touch_register_exact_ctrc( - const ClusterItlTouchHandle *handle, Buffer buffer, TransactionId xid, - const ClusterCtrcReceiptHandle *ctrc_handle) +cluster_itl_touch_register_exact_ctrc(const ClusterItlTouchHandle *handle, Buffer buffer, + TransactionId xid, + const ClusterCtrcReceiptHandle *ctrc_handle) { /* Every caller reaches this point only after the protected page/WAL * mutation has completed. Record the causal ordering while the exact @@ -296,9 +291,8 @@ cluster_itl_touch_register_exact_ctrc( } bool -cluster_itl_touch_lookup_reusable_ctrc( - const ClusterItlTouchHandle *handle, Buffer buffer, TransactionId xid, - ClusterCtrcReceiptHandle *ctrc_handle_out) +cluster_itl_touch_lookup_reusable_ctrc(const ClusterItlTouchHandle *handle, Buffer buffer, + TransactionId xid, ClusterCtrcReceiptHandle *ctrc_handle_out) { ClusterItlTerminalProof current; uint32 range_start = 0; @@ -315,19 +309,17 @@ cluster_itl_touch_lookup_reusable_ctrc( if (subxact_depth > 0) range_start = subxact_stack[subxact_depth - 1].start_count; - for (i = touch_count; i > range_start; i--) - { + for (i = touch_count; i > range_start; i--) { const ClusterItlTouchRecord *existing = &touch_list[i - 1]; - if (!itl_touch_handle_matches(&existing->key, handle) - || !existing->ctrc_handle.valid + if (!itl_touch_handle_matches(&existing->key, handle) || !existing->ctrc_handle.valid || existing->proof.buffer_id != current.buffer_id - || !cluster_itl_terminal_proof_owner_exact( - &existing->proof, current.own_generation, - current.acquisition_epoch, current.pcm_state, true, 0, 0) - || !cluster_itl_terminal_proof_slot_exact( - &existing->proof, current.xid, current.slot_wrap, - current.slot_class, ¤t.undo_segment_head)) + || !cluster_itl_terminal_proof_owner_exact(&existing->proof, current.own_generation, + current.acquisition_epoch, current.pcm_state, + true, 0, 0) + || !cluster_itl_terminal_proof_slot_exact(&existing->proof, current.xid, + current.slot_wrap, current.slot_class, + ¤t.undo_segment_head)) continue; *ctrc_handle_out = existing->ctrc_handle; return true; @@ -622,7 +614,7 @@ typedef struct ItlFinishDischarge { uint8 dependency_index; } ItlFinishDischarge; -#define CLUSTER_ITL_FINISH_MAX_DISCHARGES \ +#define CLUSTER_ITL_FINISH_MAX_DISCHARGES \ (MAX_GENERIC_XLOG_PAGES * CLUSTER_ITL_INITRANS_DEFAULT * 2) static void @@ -638,10 +630,8 @@ itl_finish_expected_target(const ClusterItlTouchRecord *record, expected->itl_xid = record->proof.xid; expected->itl_slot_index = record->key.slot_idx; expected->itl_slot_wrap = record->proof.slot_wrap; - expected->itl_class - = record->proof.slot_class == ITL_FLAG_LOCK_ONLY_ACTIVE ? 2 : 1; - expected->needs_wal - = (record->key.flags & CLUSTER_ITL_TOUCH_FLAG_NEEDS_WAL) != 0; + expected->itl_class = record->proof.slot_class == ITL_FLAG_LOCK_ONLY_ACTIVE ? 2 : 1; + expected->needs_wal = (record->key.flags & CLUSTER_ITL_TOUCH_FLAG_NEEDS_WAL) != 0; memcpy(expected->uba, &record->proof.undo_segment_head, sizeof(record->proof.undo_segment_head)); } @@ -730,10 +720,8 @@ itl_finish_flush_batch(ItlFinishBatchCtx *bctx) slot = &ClusterPageGetItlSlots(live_page)[record->key.slot_idx]; ok = slot->xid == record->proof.xid && slot->wrap == record->proof.slot_wrap && slot->flags == record->proof.slot_class - && slot->undo_segment_head.raw[0] - == record->proof.undo_segment_head.raw[0] - && slot->undo_segment_head.raw[1] - == record->proof.undo_segment_head.raw[1]; + && slot->undo_segment_head.raw[0] == record->proof.undo_segment_head.raw[0] + && slot->undo_segment_head.raw[1] == record->proof.undo_segment_head.raw[1]; } stampable[r] = ok; if (ok) @@ -793,8 +781,7 @@ itl_finish_flush_batch(ItlFinishBatchCtx *bctx) /* Never wait for WAL or sample remote durability while holding a heap * content lock. A missing local WAL position simply retains every * logged receipt; no state is weakened to manufacture cleanup. */ - if (ndischarges > 0 - && (!bctx->needs_wal || !XLogRecPtrIsInvalid(batch_lsn))) { + if (ndischarges > 0 && (!bctx->needs_wal || !XLogRecPtrIsInvalid(batch_lsn))) { XLogRecPtr local_flush_lsn; uint32 d; @@ -803,8 +790,7 @@ itl_finish_flush_batch(ItlFinishBatchCtx *bctx) local_flush_lsn = GetFlushRecPtr(NULL); for (d = 0; d < ndischarges; d++) { const ItlFinishDischarge *pending = &discharges[d]; - const ClusterItlTouchRecord *record - = &touch_list[pending->record_index]; + const ClusterItlTouchRecord *record = &touch_list[pending->record_index]; ClusterCtrcItlTargetIdentity expected; ClusterCtrcDurability durability; int origin; @@ -812,18 +798,15 @@ itl_finish_flush_batch(ItlFinishBatchCtx *bctx) MemSet(&durability, 0, sizeof(durability)); durability.highest_local_lsn = batch_lsn; durability.local_flush_lsn = local_flush_lsn; - memcpy(durability.required_lsn, - dependency_vecs[pending->dependency_index].required, + memcpy(durability.required_lsn, dependency_vecs[pending->dependency_index].required, sizeof(durability.required_lsn)); for (origin = 0; origin < CLUSTER_SF_DEP_MAX_ORIGINS; origin++) durability.durable_lsn[origin] - = origin == cluster_node_id - ? local_flush_lsn - : cluster_sf_observed_origin_durable_lsn(origin); + = origin == cluster_node_id ? local_flush_lsn + : cluster_sf_observed_origin_durable_lsn(origin); itl_finish_expected_target(record, &expected); (void)cluster_ctrc_receipt_discharge_itl_shared( - &record->ctrc_handle, &expected, - CTRC_ITL_TERMINAL_INDEPENDENT, &durability); + &record->ctrc_handle, &expected, CTRC_ITL_TERMINAL_INDEPENDENT, &durability); } } @@ -982,18 +965,16 @@ cluster_itl_touch_register_exact(const ClusterItlTouchHandle *handle pg_attribut void cluster_itl_touch_register_exact_ctrc( - const ClusterItlTouchHandle *handle pg_attribute_unused(), - Buffer buffer pg_attribute_unused(), + const ClusterItlTouchHandle *handle pg_attribute_unused(), Buffer buffer pg_attribute_unused(), TransactionId xid pg_attribute_unused(), const ClusterCtrcReceiptHandle *ctrc_handle pg_attribute_unused()) {} bool -cluster_itl_touch_lookup_reusable_ctrc( - const ClusterItlTouchHandle *handle pg_attribute_unused(), - Buffer buffer pg_attribute_unused(), - TransactionId xid pg_attribute_unused(), - ClusterCtrcReceiptHandle *ctrc_handle_out) +cluster_itl_touch_lookup_reusable_ctrc(const ClusterItlTouchHandle *handle pg_attribute_unused(), + Buffer buffer pg_attribute_unused(), + TransactionId xid pg_attribute_unused(), + ClusterCtrcReceiptHandle *ctrc_handle_out) { if (ctrc_handle_out != NULL) MemSet(ctrc_handle_out, 0, sizeof(*ctrc_handle_out)); diff --git a/src/backend/cluster/cluster_ko_lock.c b/src/backend/cluster/cluster_ko_lock.c index 4a46b693020..7d238ff7e55 100644 --- a/src/backend/cluster/cluster_ko_lock.c +++ b/src/backend/cluster/cluster_ko_lock.c @@ -439,16 +439,14 @@ cluster_ko_flush_and_wait_ack(RelFileLocator rloc, char relpersistence) * runs. Refuse before KO, buffer invalidation or physical removal unless * every local receipt for the relfilenode is already terminal. */ - if (!cluster_ctrc_relation_removal_ready_shared( - (uint32)rloc.spcOid, (uint32)rloc.dbOid, - (uint32)rloc.relNumber)) - { + if (!cluster_ctrc_relation_removal_ready_shared((uint32)rloc.spcOid, (uint32)rloc.dbOid, + (uint32)rloc.relNumber)) { KO_BUMP(failclosed_count); ereport(ERROR, (errcode(ERRCODE_CLUSTER_OBJECT_FLUSH_UNAVAILABLE), - errmsg("could not drain terminal-reference receipts for relfilenode %u/%u/%u before reuse", - (unsigned)rloc.spcOid, (unsigned)rloc.dbOid, - (unsigned)rloc.relNumber), + errmsg("could not drain terminal-reference receipts for relfilenode %u/%u/%u " + "before reuse", + (unsigned)rloc.spcOid, (unsigned)rloc.dbOid, (unsigned)rloc.relNumber), errhint("Wait for canonical terminal-reference cleanout and retry."))); } if (!cluster_object_reuse_flush_enabled) @@ -655,10 +653,8 @@ cluster_ko_drain_inbound_and_apply(void) /* A peer may publish DONE only after its own bounded CTRC journal is * drained. No ACK makes the enqueuer fail closed without extending * the existing KO wire. */ - if (!cluster_ctrc_relation_removal_ready_shared( - (uint32)rloc.spcOid, (uint32)rloc.dbOid, - (uint32)rloc.relNumber)) - { + if (!cluster_ctrc_relation_removal_ready_shared((uint32)rloc.spcOid, (uint32)rloc.dbOid, + (uint32)rloc.relNumber)) { head = pg_atomic_read_u32(&ko_state->inbound_head); tail = pg_atomic_read_u32(&ko_state->inbound_tail); continue; diff --git a/src/backend/cluster/cluster_lmon.c b/src/backend/cluster/cluster_lmon.c index abaaa61cb56..ab1b9972148 100644 --- a/src/backend/cluster/cluster_lmon.c +++ b/src/backend/cluster/cluster_lmon.c @@ -694,8 +694,7 @@ cluster_lmon_pid(void) if (cluster_lmon_state == NULL) return 0; if (MyProc == NULL) { - if (!LWLockConditionalAcquire(&cluster_lmon_state->lwlock, - LW_SHARED)) + if (!LWLockConditionalAcquire(&cluster_lmon_state->lwlock, LW_SHARED)) return 0; } else LWLockAcquire(&cluster_lmon_state->lwlock, LW_SHARED); diff --git a/src/backend/cluster/cluster_lms.c b/src/backend/cluster/cluster_lms.c index 72fe110d88c..effe2ec0a08 100644 --- a/src/backend/cluster/cluster_lms.c +++ b/src/backend/cluster/cluster_lms.c @@ -290,7 +290,7 @@ lms_r4_publish_worker_incarnation(ClusterLmsSharedState *state, int worker_id) */ bool cluster_lms_r4_drain_request(ClusterLmsSharedState *state, uint64 generation, - uint64 *worker_incarnation) + uint64 *worker_incarnation) { uint64 current; bool requested = false; @@ -318,8 +318,7 @@ cluster_lms_r4_drain_request(ClusterLmsSharedState *state, uint64 generation, /* Publish only the ACK belonging to the exact live request identity. */ static bool -lms_r4_drain_ack(ClusterLmsSharedState *state, uint64 worker_incarnation, - uint64 generation) +lms_r4_drain_ack(ClusterLmsSharedState *state, uint64 worker_incarnation, uint64 generation) { bool published = false; @@ -327,8 +326,8 @@ lms_r4_drain_ack(ClusterLmsSharedState *state, uint64 worker_incarnation, return false; LWLockAcquire(&state->lwlock, LW_EXCLUSIVE); - if (state->r4_controls.data_worker_incarnation[0] == worker_incarnation && - state->r4_controls.drain_request_generation == generation) { + if (state->r4_controls.data_worker_incarnation[0] == worker_incarnation + && state->r4_controls.drain_request_generation == generation) { state->r4_controls.drain_ack_generation = generation; published = true; } @@ -341,8 +340,8 @@ lms_r4_drain_ack(ClusterLmsSharedState *state, uint64 worker_incarnation, /* Focused test-only observer; product reclaim co-samples this identity inside * its single EXCLUSIVE claim window and exposes no separate acceptance API. */ static bool -cluster_lms_r4_drain_ack_matches(ClusterLmsSharedState *state, - uint64 worker_incarnation, uint64 generation) +cluster_lms_r4_drain_ack_matches(ClusterLmsSharedState *state, uint64 worker_incarnation, + uint64 generation) { bool matches; @@ -350,9 +349,9 @@ cluster_lms_r4_drain_ack_matches(ClusterLmsSharedState *state, return false; LWLockAcquire(&state->lwlock, LW_SHARED); - matches = state->r4_controls.data_worker_incarnation[0] == worker_incarnation && - state->r4_controls.drain_request_generation == generation && - state->r4_controls.drain_ack_generation == generation; + matches = state->r4_controls.data_worker_incarnation[0] == worker_incarnation + && state->r4_controls.drain_request_generation == generation + && state->r4_controls.drain_ack_generation == generation; LWLockRelease(&state->lwlock); return matches; @@ -384,8 +383,7 @@ lms_r4_drain_ack_tick(ClusterLmsSharedState *state, uint64 worker_incarnation) for (peer = 0; peer < CLUSTER_MAX_NODES; peer++) { if (peer == cluster_node_id) continue; - if (cluster_ic_tier1_pending_outbound(peer) - || cluster_ic_rdma_pending_outbound(peer)) + if (cluster_ic_tier1_pending_outbound(peer) || cluster_ic_rdma_pending_outbound(peer)) return false; } @@ -407,23 +405,21 @@ cluster_lms_test_r4_drain_request(ClusterLmsSharedState *state, uint64 generatio } bool -cluster_lms_test_r4_drain_ack(ClusterLmsSharedState *state, - uint64 worker_incarnation, uint64 generation) +cluster_lms_test_r4_drain_ack(ClusterLmsSharedState *state, uint64 worker_incarnation, + uint64 generation) { return lms_r4_drain_ack(state, worker_incarnation, generation); } bool -cluster_lms_test_r4_drain_ack_matches(ClusterLmsSharedState *state, - uint64 worker_incarnation, - uint64 generation) +cluster_lms_test_r4_drain_ack_matches(ClusterLmsSharedState *state, uint64 worker_incarnation, + uint64 generation) { return cluster_lms_r4_drain_ack_matches(state, worker_incarnation, generation); } bool -cluster_lms_test_r4_drain_ack_tick(ClusterLmsSharedState *state, - uint64 worker_incarnation) +cluster_lms_test_r4_drain_ack_tick(ClusterLmsSharedState *state, uint64 worker_incarnation) { return lms_r4_drain_ack_tick(state, worker_incarnation); } @@ -563,9 +559,8 @@ cluster_lms_is_recovery_ready(void) generation = pg_atomic_read_u64(&cluster_lms_state->lms_restart_generation); state = lms_get_state(); return generation != 0 - && pg_atomic_read_u64(&cluster_lms_state->recovery_ready_generation) - == generation - && (state == CLUSTER_LMS_STARTING || state == CLUSTER_LMS_READY); + && pg_atomic_read_u64(&cluster_lms_state->recovery_ready_generation) == generation + && (state == CLUSTER_LMS_STARTING || state == CLUSTER_LMS_READY); } bool @@ -601,8 +596,7 @@ cluster_lms_request_serving(void) if (!cluster_lms_is_recovery_ready()) return false; generation = pg_atomic_read_u64(&cluster_lms_state->lms_restart_generation); - pg_atomic_write_u64(&cluster_lms_state->serving_requested_generation, - generation); + pg_atomic_write_u64(&cluster_lms_state->serving_requested_generation, generation); cluster_lms_wakeup(0); return true; } @@ -972,17 +966,16 @@ lms_note_pcm_x_finish_flush_injection_reload(int worker_id) armed = cluster_injection_is_armed("cluster-pcm-x-retain-flush-error"); value = cluster_injection_points != NULL ? cluster_injection_points : ""; target = cluster_pcm_x_retain_flush_error_target != NULL - ? cluster_pcm_x_retain_flush_error_target - : ""; - if (initialized && armed == was_armed && strcmp(value, was_value) == 0 && - strcmp(target, was_target) == 0) + ? cluster_pcm_x_retain_flush_error_target + : ""; + if (initialized && armed == was_armed && strcmp(value, was_value) == 0 + && strcmp(target, was_target) == 0) return; ereport(LOG, (errmsg_internal("cluster_lms: DATA worker=%d applied PCM-X finish Flush " "injection config: pid=%d armed=%s value=\"%s\" " "target=\"%s\"", - worker_id, (int)MyProcPid, armed ? "true" : "false", - value, target))); + worker_id, (int)MyProcPid, armed ? "true" : "false", value, target))); next_value = MemoryContextStrdup(TopMemoryContext, value); next_target = MemoryContextStrdup(TopMemoryContext, target); @@ -995,7 +988,7 @@ lms_note_pcm_x_finish_flush_injection_reload(int worker_id) was_armed = armed; initialized = true; #else - (void) worker_id; + (void)worker_id; #endif } @@ -1137,9 +1130,8 @@ LmsMain(void) "CreateSharedMemoryAndSemaphores()."))); r4_worker_incarnation = lms_r4_publish_worker_incarnation(cluster_lms_state, 0); if (r4_worker_incarnation == 0) - ereport(FATAL, - (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), - errmsg("cluster_lms DATA worker 0 incarnation exhausted"))); + ereport(FATAL, (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), + errmsg("cluster_lms DATA worker 0 incarnation exhausted"))); /* Publish STARTING + record pid / spawned_at. spec-7.3 D4: worker 0's * pid also goes to worker_pids[0] so cluster_lms_wakeup(0) is uniform with @@ -1166,19 +1158,16 @@ LmsMain(void) /* The phase-3 child first exposes only the exact recovery allowlist. A * legacy/unmanaged boot proceeds immediately, while a formed boot waits * for the post-recovery phase-4 request on the same child generation. */ - pg_atomic_write_u64(&cluster_lms_state->recovery_ready_generation, - recovery_generation); + pg_atomic_write_u64(&cluster_lms_state->recovery_ready_generation, recovery_generation); while (cluster_authority_readiness_managed() - && pg_atomic_read_u64( - &cluster_lms_state->serving_requested_generation) + && pg_atomic_read_u64(&cluster_lms_state->serving_requested_generation) != recovery_generation) { int rc; if (ShutdownRequestPending || lms_shutdown_requested()) break; - rc = WaitLatch(MyLatch, - WL_LATCH_SET | WL_TIMEOUT | WL_EXIT_ON_PM_DEATH, - 100L, WAIT_EVENT_PG_SLEEP); + rc = WaitLatch(MyLatch, WL_LATCH_SET | WL_TIMEOUT | WL_EXIT_ON_PM_DEATH, 100L, + WAIT_EVENT_PG_SLEEP); ResetLatch(MyLatch); if (rc & WL_EXIT_ON_PM_DEATH) proc_exit(1); @@ -1397,9 +1386,8 @@ LmsWorkerMain(int worker_id) errhint("cluster_lms_shmem_init() must run during " "CreateSharedMemoryAndSemaphores()."))); if (lms_r4_publish_worker_incarnation(cluster_lms_state, worker_id) == 0) - ereport(FATAL, - (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), - errmsg("cluster_lms DATA worker %d incarnation exhausted", worker_id))); + ereport(FATAL, (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), + errmsg("cluster_lms DATA worker %d incarnation exhausted", worker_id))); /* Publish this worker's pid so the D4 wakeup path can find it. */ LWLockAcquire(&cluster_lms_state->lwlock, LW_EXCLUSIVE); diff --git a/src/backend/cluster/cluster_lms_data_plane.c b/src/backend/cluster/cluster_lms_data_plane.c index 44850d5d56e..9c359021f3f 100644 --- a/src/backend/cluster/cluster_lms_data_plane.c +++ b/src/backend/cluster/cluster_lms_data_plane.c @@ -174,11 +174,9 @@ cluster_lms_data_plane_enabled(void) static void dp_close_peer_now(int32 peer_id, const char *reason) { - if (!dp_enabled || peer_id < 0 || peer_id >= CLUSTER_MAX_NODES - || peer_id == cluster_node_id) + if (!dp_enabled || peer_id < 0 || peer_id >= CLUSTER_MAX_NODES || peer_id == cluster_node_id) return; - if (dp_track[peer_id].fd < 0 - && dp_track[peer_id].substate == LMS_DP_DOWN) + if (dp_track[peer_id].fd < 0 && dp_track[peer_id].substate == LMS_DP_DOWN) return; cluster_ic_tier1_close_peer(peer_id, reason); @@ -195,9 +193,8 @@ cluster_lms_data_plane_close_peer_now(int32 peer_id) #ifdef USE_CLUSTER_UNIT void -cluster_lms_data_plane_test_seed_peer(int32 peer_id, int fd, - bool connected, bool enabled, - bool wes_dirty) +cluster_lms_data_plane_test_seed_peer(int32 peer_id, int fd, bool connected, bool enabled, + bool wes_dirty) { if (peer_id < 0 || peer_id >= CLUSTER_MAX_NODES) return; @@ -208,12 +205,11 @@ cluster_lms_data_plane_test_seed_peer(int32 peer_id, int fd, } bool -cluster_lms_data_plane_test_peer_snapshot(int32 peer_id, int *fd_out, - bool *down_out, - bool *wes_dirty_out) +cluster_lms_data_plane_test_peer_snapshot(int32 peer_id, int *fd_out, bool *down_out, + bool *wes_dirty_out) { - if (peer_id < 0 || peer_id >= CLUSTER_MAX_NODES - || fd_out == NULL || down_out == NULL || wes_dirty_out == NULL) + if (peer_id < 0 || peer_id >= CLUSTER_MAX_NODES || fd_out == NULL || down_out == NULL + || wes_dirty_out == NULL) return false; *fd_out = dp_track[peer_id].fd; *down_out = dp_track[peer_id].substate == LMS_DP_DOWN; diff --git a/src/backend/cluster/cluster_lms_outbound.c b/src/backend/cluster/cluster_lms_outbound.c index aa89a9696ae..6431cc8e134 100644 --- a/src/backend/cluster/cluster_lms_outbound.c +++ b/src/backend/cluster/cluster_lms_outbound.c @@ -86,8 +86,7 @@ typedef struct ClusterLmsOutboundSlot { uint8 payload[PGRAC_LMS_OUTBOUND_PAYLOAD_MAX]; } ClusterLmsOutboundSlot; -StaticAssertDecl(PGRAC_LMS_OUTBOUND_PAYLOAD_MAX - >= RESOURCE_X_PROOF_V1_BYTES, +StaticAssertDecl(PGRAC_LMS_OUTBOUND_PAYLOAD_MAX >= RESOURCE_X_PROOF_V1_BYTES, "LMS outbound slot must hold a Resource-X proof ACK"); StaticAssertDecl(sizeof(ClusterLmsOutboundSlot) == 384, "LMS outbound slot capability guard layout changed"); @@ -144,11 +143,8 @@ cluster_lms_outbound_shmem_init(void) "pgrac cluster lms data outbound", cluster_lms_outbound_shmem_size(), &found); cluster_lms_outbound_rings = cluster_lms_outbound_shared->rings; if (!found) { - memset(cluster_lms_outbound_shared, 0, - sizeof(*cluster_lms_outbound_shared)); - pg_atomic_init_u64( - &cluster_lms_outbound_shared->resource_x_transport_mutation_sequence, - 1); + memset(cluster_lms_outbound_shared, 0, sizeof(*cluster_lms_outbound_shared)); + pg_atomic_init_u64(&cluster_lms_outbound_shared->resource_x_transport_mutation_sequence, 1); } if (!IsBootstrapProcessingMode()) @@ -175,14 +171,14 @@ lms_outbound_resource_x_transport_mutation_mark(void) uint64 current; Assert(cluster_lms_outbound_shared != NULL); - current = pg_atomic_read_u64( - &cluster_lms_outbound_shared->resource_x_transport_mutation_sequence); + current + = pg_atomic_read_u64(&cluster_lms_outbound_shared->resource_x_transport_mutation_sequence); for (;;) { if (current == 0 || current == UINT64_MAX) return false; if (pg_atomic_compare_exchange_u64( - &cluster_lms_outbound_shared->resource_x_transport_mutation_sequence, - ¤t, current + 1)) + &cluster_lms_outbound_shared->resource_x_transport_mutation_sequence, ¤t, + current + 1)) return true; } } @@ -270,9 +266,8 @@ cluster_lms_outbound_enqueue(int worker_id, uint8 msg_type, uint32 dest_node_id, * second authority registry. */ ClusterPcmOwnResult cluster_lms_outbound_stage_resource_x_remote_s_status_exact( - int worker_id, uint32 dest_node_id, const void *payload, - uint16 payload_len, const ClusterPcmOwnSnapshot *expected_revoking, - ClusterLmsRemoteSStatusHandle *handle_out) + int worker_id, uint32 dest_node_id, const void *payload, uint16 payload_len, + const ClusterPcmOwnSnapshot *expected_revoking, ClusterLmsRemoteSStatusHandle *handle_out) { ClusterLmsOutboundState *ring; ClusterLmsOutboundSlot *slot; @@ -283,10 +278,9 @@ cluster_lms_outbound_stage_resource_x_remote_s_status_exact( if (handle_out != NULL) memset(handle_out, 0, sizeof(*handle_out)); if (worker_id < 0 || worker_id >= CLUSTER_LMS_MAX_WORKERS - || dest_node_id >= RESOURCE_X_PROTOCOL_NODE_LIMIT - || payload == NULL || payload_len != RESOURCE_X_CONTROL_V1_BYTES - || expected_revoking == NULL || handle_out == NULL - || expected_revoking->pcm_state != (uint8)PCM_STATE_S + || dest_node_id >= RESOURCE_X_PROTOCOL_NODE_LIMIT || payload == NULL + || payload_len != RESOURCE_X_CONTROL_V1_BYTES || expected_revoking == NULL + || handle_out == NULL || expected_revoking->pcm_state != (uint8)PCM_STATE_S || expected_revoking->flags != PCM_OWN_FLAG_REVOKING || expected_revoking->reservation_token == 0 || expected_revoking->writer_activation_token != 0 @@ -316,8 +310,7 @@ cluster_lms_outbound_stage_resource_x_remote_s_status_exact( memset(slot, 0, sizeof(*slot)); slot->dest_node_id = dest_node_id; slot->msg_type = RESOURCE_X_MSG_BLOCKED_TO_N; - slot->kind - = (uint8)CLUSTER_LMS_OUTBOUND_RESOURCE_X_REMOTE_S_STATUS_PENDING; + slot->kind = (uint8)CLUSTER_LMS_OUTBOUND_RESOURCE_X_REMOTE_S_STATUS_PENDING; slot->payload_len = payload_len; slot->local_tag = expected_revoking->tag; slot->local_slot_cookie = slot_cookie; @@ -338,46 +331,38 @@ cluster_lms_outbound_stage_resource_x_remote_s_status_exact( } static bool -lms_outbound_remote_s_status_handle_exact( - const ClusterLmsOutboundSlot *slot, - const ClusterLmsRemoteSStatusHandle *handle) +lms_outbound_remote_s_status_handle_exact(const ClusterLmsOutboundSlot *slot, + const ClusterLmsRemoteSStatusHandle *handle) { - return slot != NULL && handle != NULL - && handle->slot_cookie != 0 - && handle->reservation_token != 0 - && slot->msg_type == RESOURCE_X_MSG_BLOCKED_TO_N - && slot->payload_len == RESOURCE_X_CONTROL_V1_BYTES - && slot->local_slot_cookie == handle->slot_cookie - && slot->local_own_generation == handle->own_generation - && slot->local_reservation_token == handle->reservation_token - && BufferTagsEqual(&slot->local_tag, &handle->tag); + return slot != NULL && handle != NULL && handle->slot_cookie != 0 + && handle->reservation_token != 0 && slot->msg_type == RESOURCE_X_MSG_BLOCKED_TO_N + && slot->payload_len == RESOURCE_X_CONTROL_V1_BYTES + && slot->local_slot_cookie == handle->slot_cookie + && slot->local_own_generation == handle->own_generation + && slot->local_reservation_token == handle->reservation_token + && BufferTagsEqual(&slot->local_tag, &handle->tag); } ClusterPcmOwnResult cluster_lms_outbound_publish_resource_x_remote_s_status_exact( - const ClusterLmsRemoteSStatusHandle *handle, - const ClusterPcmOwnSnapshot *released_n) + const ClusterLmsRemoteSStatusHandle *handle, const ClusterPcmOwnSnapshot *released_n) { ClusterLmsOutboundState *ring; ClusterLmsOutboundSlot *slot; ClusterPcmOwnResult result = CLUSTER_PCM_OWN_STALE; LWLock *lock; - if (handle == NULL || released_n == NULL - || handle->worker_id < 0 + if (handle == NULL || released_n == NULL || handle->worker_id < 0 || handle->worker_id >= CLUSTER_LMS_MAX_WORKERS - || handle->slot_index >= PGRAC_LMS_OUTBOUND_CAPACITY - || handle->own_generation == UINT64_MAX - || released_n->pcm_state != (uint8)PCM_STATE_N - || released_n->flags != 0 + || handle->slot_index >= PGRAC_LMS_OUTBOUND_CAPACITY || handle->own_generation == UINT64_MAX + || released_n->pcm_state != (uint8)PCM_STATE_N || released_n->flags != 0 || released_n->generation != handle->own_generation + 1 || released_n->reservation_token != handle->reservation_token || released_n->writer_activation_token != 0 || released_n->resource_x_activation_generation != 0 || !BufferTagsEqual(&released_n->tag, &handle->tag)) return CLUSTER_PCM_OWN_STALE; - if (cluster_lms_outbound_rings == NULL - || OB_LOCK(handle->worker_id) == NULL) + if (cluster_lms_outbound_rings == NULL || OB_LOCK(handle->worker_id) == NULL) return CLUSTER_PCM_OWN_NOT_READY; ring = OB_RING(handle->worker_id); lock = OB_LOCK(handle->worker_id); @@ -385,16 +370,13 @@ cluster_lms_outbound_publish_resource_x_remote_s_status_exact( LWLockAcquire(lock, LW_EXCLUSIVE); slot = &ring->ring[handle->slot_index]; if (lms_outbound_remote_s_status_handle_exact(slot, handle) - && (slot->kind - == (uint8)CLUSTER_LMS_OUTBOUND_RESOURCE_X_REMOTE_S_STATUS_PENDING - || slot->kind - == (uint8)CLUSTER_LMS_OUTBOUND_RESOURCE_X_REMOTE_S_STATUS_READY)) { + && (slot->kind == (uint8)CLUSTER_LMS_OUTBOUND_RESOURCE_X_REMOTE_S_STATUS_PENDING + || slot->kind == (uint8)CLUSTER_LMS_OUTBOUND_RESOURCE_X_REMOTE_S_STATUS_READY)) { if (!lms_outbound_resource_x_transport_mutation_mark()) { LWLockRelease(lock); return CLUSTER_PCM_OWN_EXHAUSTED; } - slot->kind - = (uint8)CLUSTER_LMS_OUTBOUND_RESOURCE_X_REMOTE_S_STATUS_READY; + slot->kind = (uint8)CLUSTER_LMS_OUTBOUND_RESOURCE_X_REMOTE_S_STATUS_READY; result = CLUSTER_PCM_OWN_OK; } LWLockRelease(lock); @@ -412,28 +394,24 @@ cluster_lms_outbound_cancel_resource_x_remote_s_status_exact( ClusterPcmOwnResult result = CLUSTER_PCM_OWN_STALE; LWLock *lock; - if (handle == NULL || handle->worker_id < 0 - || handle->worker_id >= CLUSTER_LMS_MAX_WORKERS - || handle->slot_index >= PGRAC_LMS_OUTBOUND_CAPACITY - || handle->slot_cookie == 0 || handle->reservation_token == 0) + if (handle == NULL || handle->worker_id < 0 || handle->worker_id >= CLUSTER_LMS_MAX_WORKERS + || handle->slot_index >= PGRAC_LMS_OUTBOUND_CAPACITY || handle->slot_cookie == 0 + || handle->reservation_token == 0) return CLUSTER_PCM_OWN_INVALID; - if (cluster_lms_outbound_rings == NULL - || OB_LOCK(handle->worker_id) == NULL) + if (cluster_lms_outbound_rings == NULL || OB_LOCK(handle->worker_id) == NULL) return CLUSTER_PCM_OWN_NOT_READY; ring = OB_RING(handle->worker_id); lock = OB_LOCK(handle->worker_id); LWLockAcquire(lock, LW_EXCLUSIVE); slot = &ring->ring[handle->slot_index]; - if (slot->kind - == (uint8)CLUSTER_LMS_OUTBOUND_RESOURCE_X_REMOTE_S_STATUS_PENDING + if (slot->kind == (uint8)CLUSTER_LMS_OUTBOUND_RESOURCE_X_REMOTE_S_STATUS_PENDING && lms_outbound_remote_s_status_handle_exact(slot, handle)) { if (!lms_outbound_resource_x_transport_mutation_mark()) { LWLockRelease(lock); return CLUSTER_PCM_OWN_EXHAUSTED; } - slot->kind - = (uint8)CLUSTER_LMS_OUTBOUND_RESOURCE_X_REMOTE_S_STATUS_CANCELLED; + slot->kind = (uint8)CLUSTER_LMS_OUTBOUND_RESOURCE_X_REMOTE_S_STATUS_CANCELLED; result = CLUSTER_PCM_OWN_OK; } LWLockRelease(lock); @@ -469,66 +447,51 @@ lms_outbound_monotonic_us(void) static bool lms_outbound_resource_x_intent_valid(const ResourceXIntentSlot *intent) { - if (intent == NULL - || intent->logical_generation == 0 - || intent->logical_generation == UINT64_MAX - || intent->authority_generation == 0 - || intent->authority_generation == UINT64_MAX - || intent->first_armed_us == 0 + if (intent == NULL || intent->logical_generation == 0 + || intent->logical_generation == UINT64_MAX || intent->authority_generation == 0 + || intent->authority_generation == UINT64_MAX || intent->first_armed_us == 0 || intent->first_armed_us == UINT64_MAX || intent->destination_node >= RESOURCE_X_PROTOCOL_NODE_LIMIT || intent->state != RESOURCE_X_INTENT_SLOT_ARMED - || intent->body.owner_node >= RESOURCE_X_PROTOCOL_NODE_LIMIT - || intent->body.reserved != 0) + || intent->body.owner_node >= RESOURCE_X_PROTOCOL_NODE_LIMIT || intent->body.reserved != 0) return false; switch ((ResourceXIntentOwnerKind)intent->body.owner_kind) { case RESOURCE_X_INTENT_OWNER_MASTER_BLOCK: return intent->payload_bytes == RESOURCE_X_CONTROL_V1_BYTES - && intent->kind == RESOURCE_X_WIRE_BLOCK_TO_N - && intent->body.owner_generation - == intent->logical_generation - && intent->body.owner_index == intent->destination_node - && intent->body.assertion.requester_node - != (int32)intent->destination_node; + && intent->kind == RESOURCE_X_WIRE_BLOCK_TO_N + && intent->body.owner_generation == intent->logical_generation + && intent->body.owner_index == intent->destination_node + && intent->body.assertion.requester_node != (int32)intent->destination_node; case RESOURCE_X_INTENT_OWNER_HOLDER_STATUS: return (intent->payload_bytes == RESOURCE_X_CONTROL_V1_BYTES || intent->payload_bytes == RESOURCE_X_PROOF_V1_BYTES) - && intent->kind == RESOURCE_X_WIRE_BLOCKED_TO_N - && intent->body.owner_generation - == intent->logical_generation - && intent->body.owner_index == 0; + && intent->kind == RESOURCE_X_WIRE_BLOCKED_TO_N + && intent->body.owner_generation == intent->logical_generation + && intent->body.owner_index == 0; case RESOURCE_X_INTENT_OWNER_HOLDER_IMAGE: return intent->payload_bytes == RESOURCE_X_IMAGE_V1_BYTES - && intent->kind == RESOURCE_X_WIRE_IMAGE_ENVELOPE - && intent->body.assertion.requester_node - == (int32)intent->destination_node - && intent->body.owner_generation - == intent->logical_generation - && intent->body.owner_index == 0; + && intent->kind == RESOURCE_X_WIRE_IMAGE_ENVELOPE + && intent->body.assertion.requester_node == (int32)intent->destination_node + && intent->body.owner_generation == intent->logical_generation + && intent->body.owner_index == 0; case RESOURCE_X_INTENT_OWNER_MASTER_GRANT: return intent->payload_bytes == RESOURCE_X_PROOF_V1_BYTES - && intent->kind == RESOURCE_X_WIRE_AUTHORITY_GRANT - && intent->body.assertion.requester_node - == (int32)intent->destination_node - && intent->body.owner_generation - == intent->authority_generation - && intent->body.owner_index == 0; + && intent->kind == RESOURCE_X_WIRE_AUTHORITY_GRANT + && intent->body.assertion.requester_node == (int32)intent->destination_node + && intent->body.owner_generation == intent->authority_generation + && intent->body.owner_index == 0; case RESOURCE_X_INTENT_OWNER_REQUESTER_SETTLEMENT: return intent->payload_bytes == RESOURCE_X_SHORT_V1_BYTES - && intent->kind == RESOURCE_X_WIRE_INSTALL_SETTLEMENT - && intent->body.assertion.requester_node - == (int32)intent->body.owner_node - && intent->body.owner_generation - == intent->logical_generation - && intent->body.owner_index == 0; + && intent->kind == RESOURCE_X_WIRE_INSTALL_SETTLEMENT + && intent->body.assertion.requester_node == (int32)intent->body.owner_node + && intent->body.owner_generation == intent->logical_generation + && intent->body.owner_index == 0; case RESOURCE_X_INTENT_OWNER_HOLDER_RELEASE: return intent->payload_bytes == RESOURCE_X_PROOF_V1_BYTES - && intent->kind == RESOURCE_X_WIRE_SOURCE_SETTLEMENT_V2 - && intent->body.assertion.requester_node - != (int32)intent->destination_node - && intent->body.owner_generation - == intent->logical_generation - && intent->body.owner_index == 0; + && intent->kind == RESOURCE_X_WIRE_SOURCE_SETTLEMENT_V2 + && intent->body.assertion.requester_node != (int32)intent->destination_node + && intent->body.owner_generation == intent->logical_generation + && intent->body.owner_index == 0; default: return false; } @@ -556,32 +519,28 @@ lms_outbound_resource_x_intent_msg_type(const ResourceXIntentSlot *intent) } static bool -lms_outbound_resource_x_intent_identity_equal( - const ResourceXIntentSlot *left, const ResourceXIntentSlot *right) +lms_outbound_resource_x_intent_identity_equal(const ResourceXIntentSlot *left, + const ResourceXIntentSlot *right) { - return left != NULL && right != NULL - && left->logical_generation == right->logical_generation - && left->authority_generation == right->authority_generation - && left->first_armed_us == right->first_armed_us - && left->destination_node == right->destination_node - && left->payload_bytes == right->payload_bytes - && left->kind == right->kind - && memcmp(&left->body, &right->body, sizeof(left->body)) == 0; + return left != NULL && right != NULL && left->logical_generation == right->logical_generation + && left->authority_generation == right->authority_generation + && left->first_armed_us == right->first_armed_us + && left->destination_node == right->destination_node + && left->payload_bytes == right->payload_bytes && left->kind == right->kind + && memcmp(&left->body, &right->body, sizeof(left->body)) == 0; } bool -cluster_lms_outbound_enqueue_resource_x_intent( - int worker_id, const ResourceXIntentSlot *intent, - uint32 connection_generation, uint64 deadline_us) +cluster_lms_outbound_enqueue_resource_x_intent(int worker_id, const ResourceXIntentSlot *intent, + uint32 connection_generation, uint64 deadline_us) { ClusterLmsOutboundState *ring; ClusterLmsOutboundSlot *slot; LWLock *lock; uint64 now_us; - if (worker_id < 0 || worker_id >= CLUSTER_LMS_MAX_WORKERS - || connection_generation == 0 || deadline_us == 0 - || !lms_outbound_resource_x_intent_valid(intent) + if (worker_id < 0 || worker_id >= CLUSTER_LMS_MAX_WORKERS || connection_generation == 0 + || deadline_us == 0 || !lms_outbound_resource_x_intent_valid(intent) || cluster_lms_outbound_rings == NULL || OB_LOCK(worker_id) == NULL) return false; ring = OB_RING(worker_id); @@ -605,8 +564,7 @@ cluster_lms_outbound_enqueue_resource_x_intent( slot->msg_type = lms_outbound_resource_x_intent_msg_type(intent); slot->kind = (uint8)CLUSTER_LMS_OUTBOUND_RESOURCE_X_INTENT; slot->payload_len = sizeof(*intent); - slot->required_capability - = PGRAC_IC_HELLO_CAP_GCS_RESOURCE_X_CONVERT_V1; + slot->required_capability = PGRAC_IC_HELLO_CAP_GCS_RESOURCE_X_CONVERT_V1; slot->connection_generation = connection_generation; slot->deadline_us = deadline_us; memcpy(slot->payload, intent, sizeof(*intent)); @@ -617,13 +575,11 @@ cluster_lms_outbound_enqueue_resource_x_intent( { ResourceXIntentResult stage_result; - stage_result - = cluster_pcm_lock_resource_x_outbound_intent_stage_exact( - intent, now_us); + stage_result = cluster_pcm_lock_resource_x_outbound_intent_stage_exact(intent, now_us); if (stage_result != RESOURCE_X_INTENT_STAGED) { memset(slot, 0, sizeof(*slot)); LWLockRelease(lock); - return false; + return false; } } ring->head = (ring->head + 1) % PGRAC_LMS_OUTBOUND_CAPACITY; @@ -686,40 +642,32 @@ cluster_lms_outbound_resource_x_intent_pump(void) if (now_us == 0) continue; if ((int32)intent.destination_node == cluster_node_id) { - if ((cluster_ic_local_capability_word() - & PGRAC_IC_HELLO_CAP_GCS_RESOURCE_X_CONVERT_V1) == 0) { - (void)cluster_pcm_lock_resource_x_outbound_intent_not_admitted_exact( - &intent, now_us); + if ((cluster_ic_local_capability_word() & PGRAC_IC_HELLO_CAP_GCS_RESOURCE_X_CONVERT_V1) + == 0) { + (void)cluster_pcm_lock_resource_x_outbound_intent_not_admitted_exact(&intent, + now_us); continue; } connection_generation = 1; } else if (!cluster_sf_peer_capability_word_sample( - (int32)intent.destination_node, - PGRAC_IC_HELLO_CAP_GCS_RESOURCE_X_CONVERT_V1, - &capability_word, &connection_generation) + (int32)intent.destination_node, PGRAC_IC_HELLO_CAP_GCS_RESOURCE_X_CONVERT_V1, + &capability_word, &connection_generation) || connection_generation == 0) { - (void)cluster_pcm_lock_resource_x_outbound_intent_not_admitted_exact( - &intent, now_us); + (void)cluster_pcm_lock_resource_x_outbound_intent_not_admitted_exact(&intent, now_us); continue; } - worker_id = cluster_lms_shard_for_tag( - &intent.body.assertion.resource, cluster_lms_workers); + worker_id = cluster_lms_shard_for_tag(&intent.body.assertion.resource, cluster_lms_workers); /* The physical copy inherits the existing GCS DATA transport * deadline. Expiry returns only the ring ownership; it is not a * new Resource-X operation timeout or runtime policy. */ - timeout_us - = (uint64)Max(cluster_gcs_reply_timeout_ms, 1) * UINT64_C(1000); - deadline_us - = now_us > UINT64_MAX - timeout_us - ? UINT64_MAX - : now_us + timeout_us; + timeout_us = (uint64)Max(cluster_gcs_reply_timeout_ms, 1) * UINT64_C(1000); + deadline_us = now_us > UINT64_MAX - timeout_us ? UINT64_MAX : now_us + timeout_us; enqueued = cluster_lms_outbound_enqueue_resource_x_intent( worker_id, &intent, connection_generation, deadline_us); if (enqueued) staged++; else - (void)cluster_pcm_lock_resource_x_outbound_intent_not_admitted_exact( - &intent, now_us); + (void)cluster_pcm_lock_resource_x_outbound_intent_not_admitted_exact(&intent, now_us); } /* Preserve the frozen 4-probe/call and 16-call/iteration bounds without * turning a truthful MORE cursor into an artificial 100ms idle period. @@ -753,9 +701,9 @@ lms_outbound_r4_refusal_header_valid(const GcsBlockReplyHeader *header) static bool lms_outbound_enqueue_zero_block_reply_internal(int worker_id, uint32 dest_node_id, - const GcsBlockReplyHeader *header, - bool direct_land, uint32 required_capability, - uint32 connection_generation) + const GcsBlockReplyHeader *header, bool direct_land, + uint32 required_capability, + uint32 connection_generation) { ClusterLmsOutboundState *ring; LWLock *lock; @@ -802,17 +750,18 @@ bool cluster_lms_outbound_enqueue_zero_block_reply(int worker_id, uint32 dest_node_id, const GcsBlockReplyHeader *header, bool direct_land) { - return lms_outbound_enqueue_zero_block_reply_internal( - worker_id, dest_node_id, header, direct_land, 0, 0); + return lms_outbound_enqueue_zero_block_reply_internal(worker_id, dest_node_id, header, + direct_land, 0, 0); } /* PGRAC R4 adaptation: stage a typed 25/26 refusal on the requester's exact * HELLO-authenticated connection. The existing DATA slot remains 144 bytes; * only the 48-byte header is retained until drain expands the zero page. */ bool -cluster_lms_outbound_enqueue_zero_block_reply_cap_bound( - int worker_id, uint32 dest_node_id, const GcsBlockReplyHeader *header, - uint32 required_capability, uint32 connection_generation) +cluster_lms_outbound_enqueue_zero_block_reply_cap_bound(int worker_id, uint32 dest_node_id, + const GcsBlockReplyHeader *header, + uint32 required_capability, + uint32 connection_generation) { if (required_capability == 0) return false; @@ -877,8 +826,7 @@ cluster_lms_outbound_drain_send(int worker_id) ClusterLmsZeroBlockReplyWire zero_reply; ResourceXIntentSlot resource_x_intent; ResourceXIntentSlot resource_x_current; - ResourceXWireReject resource_x_reject - = RESOURCE_X_WIRE_REJECT_NONE; + ResourceXWireReject resource_x_reject = RESOURCE_X_WIRE_REJECT_NONE; uint8 resource_x_payload[RESOURCE_X_IMAGE_V1_BYTES]; const void *send_payload; uint32 send_payload_len; @@ -896,25 +844,18 @@ cluster_lms_outbound_drain_send(int worker_id) if (ring->count > 0) { slot = ring->ring[ring->tail]; remote_s_pending_slot - = slot.kind - == (uint8)CLUSTER_LMS_OUTBOUND_RESOURCE_X_REMOTE_S_STATUS_PENDING; + = slot.kind == (uint8)CLUSTER_LMS_OUTBOUND_RESOURCE_X_REMOTE_S_STATUS_PENDING; remote_s_status_slot - = slot.kind - == (uint8)CLUSTER_LMS_OUTBOUND_RESOURCE_X_REMOTE_S_STATUS_READY; + = slot.kind == (uint8)CLUSTER_LMS_OUTBOUND_RESOURCE_X_REMOTE_S_STATUS_READY; remote_s_cancelled_slot - = slot.kind - == (uint8)CLUSTER_LMS_OUTBOUND_RESOURCE_X_REMOTE_S_STATUS_CANCELLED; - resource_x_owned_slot - = slot.kind - == (uint8)CLUSTER_LMS_OUTBOUND_RESOURCE_X_INTENT; + = slot.kind == (uint8)CLUSTER_LMS_OUTBOUND_RESOURCE_X_REMOTE_S_STATUS_CANCELLED; + resource_x_owned_slot = slot.kind == (uint8)CLUSTER_LMS_OUTBOUND_RESOURCE_X_INTENT; if (!remote_s_pending_slot && !remote_s_status_slot) { - if (resource_x_owned_slot - && !lms_outbound_resource_x_transport_mutation_mark()) { + if (resource_x_owned_slot && !lms_outbound_resource_x_transport_mutation_mark()) { LWLockRelease(lock); return sent; } - ring->tail - = (ring->tail + 1) % PGRAC_LMS_OUTBOUND_CAPACITY; + ring->tail = (ring->tail + 1) % PGRAC_LMS_OUTBOUND_CAPACITY; ring->count--; } got = true; @@ -928,8 +869,7 @@ cluster_lms_outbound_drain_send(int worker_id) if (remote_s_cancelled_slot) continue; memset(&resource_x_intent, 0, sizeof(resource_x_intent)); - resource_x_slot - = slot.kind == (uint8)CLUSTER_LMS_OUTBOUND_RESOURCE_X_INTENT; + resource_x_slot = slot.kind == (uint8)CLUSTER_LMS_OUTBOUND_RESOURCE_X_INTENT; if (remote_s_status_slot && (slot.msg_type != RESOURCE_X_MSG_BLOCKED_TO_N || slot.payload_len != RESOURCE_X_CONTROL_V1_BYTES @@ -938,11 +878,8 @@ cluster_lms_outbound_drain_send(int worker_id) if (resource_x_slot) { if (slot.payload_len != sizeof(resource_x_intent)) continue; - memcpy(&resource_x_intent, slot.payload, - sizeof(resource_x_intent)); - if (slot.msg_type - != lms_outbound_resource_x_intent_msg_type( - &resource_x_intent)) + memcpy(&resource_x_intent, slot.payload, sizeof(resource_x_intent)); + if (slot.msg_type != lms_outbound_resource_x_intent_msg_type(&resource_x_intent)) continue; } /* Wire-version-sensitive slots are valid only for the exact @@ -951,8 +888,8 @@ cluster_lms_outbound_drain_send(int worker_id) * no protocol ACK is generated, so the armed reliable leg retries. */ if (slot.required_capability != 0 && (((int32)slot.dest_node_id == cluster_node_id - && (cluster_ic_local_capability_word() - & slot.required_capability) != slot.required_capability) + && (cluster_ic_local_capability_word() & slot.required_capability) + != slot.required_capability) || ((int32)slot.dest_node_id != cluster_node_id && !cluster_sf_peer_capability_generation_matches( (int32)slot.dest_node_id, slot.required_capability, @@ -974,12 +911,12 @@ cluster_lms_outbound_drain_send(int worker_id) continue; } if (cluster_pcm_lock_resource_x_outbound_intent_snapshot_exact( - &resource_x_intent, &resource_x_current, - resource_x_payload, sizeof(resource_x_payload)) + &resource_x_intent, &resource_x_current, resource_x_payload, + sizeof(resource_x_payload)) != RESOURCE_X_APPLY_APPLIED || resource_x_current.state != RESOURCE_X_INTENT_SLOT_STAGED - || !lms_outbound_resource_x_intent_identity_equal( - &resource_x_intent, &resource_x_current)) + || !lms_outbound_resource_x_intent_identity_equal(&resource_x_intent, + &resource_x_current)) continue; send_payload = resource_x_payload; send_payload_len = resource_x_current.payload_bytes; @@ -988,8 +925,7 @@ cluster_lms_outbound_drain_send(int worker_id) * requester ingress restores the canonical generation before it * compares a proof-bound image CRC. */ if (!cluster_resource_x_wire_rebind_sender_generation( - slot.msg_type, resource_x_payload, - (uint16)send_payload_len, + slot.msg_type, resource_x_payload, (uint16)send_payload_len, slot.connection_generation, &resource_x_reject)) { (void)cluster_pcm_lock_resource_x_outbound_intent_hard_rearm_exact( &resource_x_intent, lms_outbound_monotonic_us()); @@ -1006,23 +942,23 @@ cluster_lms_outbound_drain_send(int worker_id) * preserve that nonzero sender generation and let the ordinary * local envelope ingress revalidate formation/session/capability. */ if ((cluster_ic_local_capability_word() - & PGRAC_IC_HELLO_CAP_GCS_RESOURCE_X_CONVERT_V1) == 0) + & PGRAC_IC_HELLO_CAP_GCS_RESOURCE_X_CONVERT_V1) + == 0) break; } else { if (!cluster_sf_peer_capability_word_sample( - (int32)slot.dest_node_id, - PGRAC_IC_HELLO_CAP_GCS_RESOURCE_X_CONVERT_V1, + (int32)slot.dest_node_id, PGRAC_IC_HELLO_CAP_GCS_RESOURCE_X_CONVERT_V1, &capability_word, &connection_generation) || connection_generation == 0 || !cluster_resource_x_wire_rebind_sender_generation( - slot.msg_type, resource_x_payload, slot.payload_len, - connection_generation, &resource_x_reject)) + slot.msg_type, resource_x_payload, slot.payload_len, connection_generation, + &resource_x_reject)) break; } send_payload = resource_x_payload; send_payload_len = slot.payload_len; } else if (slot.kind == (uint8)CLUSTER_LMS_OUTBOUND_ZERO_BLOCK_REPLY - || slot.kind == (uint8)CLUSTER_LMS_OUTBOUND_DIRECT_ZERO_BLOCK_REPLY) { + || slot.kind == (uint8)CLUSTER_LMS_OUTBOUND_DIRECT_ZERO_BLOCK_REPLY) { if (slot.msg_type != PGRAC_IC_MSG_GCS_BLOCK_REPLY || slot.payload_len != sizeof(GcsBlockReplyHeader)) { rc = CLUSTER_IC_SEND_HARD_ERROR; @@ -1094,10 +1030,10 @@ cluster_lms_outbound_drain_send(int worker_id) rc = cluster_ic_send_envelope(slot.msg_type, (int32)slot.dest_node_id, send_payload, send_payload_len); -handle_send_result: + handle_send_result: /* Actual transport result, not admission or enqueue success. */ cluster_pcm_lock_resource_x_trace_wire(slot.msg_type, (int32)slot.dest_node_id, - send_payload, send_payload_len, (int32)rc); + send_payload, send_payload_len, (int32)rc); if (slot.kind == (uint8)CLUSTER_LMS_OUTBOUND_ZERO_BLOCK_REPLY || slot.kind == (uint8)CLUSTER_LMS_OUTBOUND_DIRECT_ZERO_BLOCK_REPLY) cluster_gcs_block_note_send_outcome(GCS_BLOCK_SEND_FAMILY_REPLY, rc); @@ -1106,20 +1042,16 @@ cluster_lms_outbound_drain_send(int worker_id) case CLUSTER_IC_SEND_WOULD_BLOCK: /* On the wire or admitted (transport owns a copy). */ if (resource_x_slot) { - if (resource_x_intent.body.owner_kind - == RESOURCE_X_INTENT_OWNER_HOLDER_RELEASE) + if (resource_x_intent.body.owner_kind == RESOURCE_X_INTENT_OWNER_HOLDER_RELEASE) (void)cluster_pcm_lock_resource_x_outbound_intent_hard_rearm_exact( - &resource_x_intent, - lms_outbound_monotonic_us()); + &resource_x_intent, lms_outbound_monotonic_us()); else (void)cluster_pcm_lock_resource_x_outbound_intent_complete_exact( &resource_x_intent); } if (remote_s_status_slot) { LWLockAcquire(lock, LW_EXCLUSIVE); - if (ring->count == 0 - || memcmp(&ring->ring[ring->tail], &slot, - sizeof(slot)) != 0) { + if (ring->count == 0 || memcmp(&ring->ring[ring->tail], &slot, sizeof(slot)) != 0) { LWLockRelease(lock); return sent; } @@ -1127,10 +1059,8 @@ cluster_lms_outbound_drain_send(int worker_id) LWLockRelease(lock); return sent; } - memset(&ring->ring[ring->tail], 0, - sizeof(ring->ring[ring->tail])); - ring->tail - = (ring->tail + 1) % PGRAC_LMS_OUTBOUND_CAPACITY; + memset(&ring->ring[ring->tail], 0, sizeof(ring->ring[ring->tail])); + ring->tail = (ring->tail + 1) % PGRAC_LMS_OUTBOUND_CAPACITY; ring->count--; LWLockRelease(lock); } @@ -1305,14 +1235,12 @@ cluster_lms_outbound_resource_x_staged_count(void) { ClusterLmsResourceXTransportSnapshot snapshot; - return cluster_lms_outbound_resource_x_transport_snapshot(&snapshot) - ? snapshot.staged_count - : UINT64_MAX; + return cluster_lms_outbound_resource_x_transport_snapshot(&snapshot) ? snapshot.staged_count + : UINT64_MAX; } bool -cluster_lms_outbound_resource_x_transport_snapshot( - ClusterLmsResourceXTransportSnapshot *out) +cluster_lms_outbound_resource_x_transport_snapshot(ClusterLmsResourceXTransportSnapshot *out) { uint64 sequence; int worker_id; @@ -1320,8 +1248,7 @@ cluster_lms_outbound_resource_x_transport_snapshot( if (out != NULL) memset(out, 0, sizeof(*out)); /* Absence of any production ring/lock is not an empty proof. */ - if (out == NULL || cluster_lms_outbound_shared == NULL - || cluster_lms_outbound_rings == NULL) + if (out == NULL || cluster_lms_outbound_shared == NULL || cluster_lms_outbound_rings == NULL) return false; for (worker_id = 0; worker_id < CLUSTER_LMS_MAX_WORKERS; worker_id++) if (OB_LOCK(worker_id) == NULL) @@ -1331,8 +1258,8 @@ cluster_lms_outbound_resource_x_transport_snapshot( * ring, so this creates one coherent all-ring snapshot without a new lock. */ for (worker_id = 0; worker_id < CLUSTER_LMS_MAX_WORKERS; worker_id++) LWLockAcquire(OB_LOCK(worker_id), LW_SHARED); - sequence = pg_atomic_read_u64( - &cluster_lms_outbound_shared->resource_x_transport_mutation_sequence); + sequence + = pg_atomic_read_u64(&cluster_lms_outbound_shared->resource_x_transport_mutation_sequence); if (sequence == 0 || sequence == UINT64_MAX) goto invalid; for (worker_id = 0; worker_id < CLUSTER_LMS_MAX_WORKERS; worker_id++) { @@ -1342,15 +1269,11 @@ cluster_lms_outbound_resource_x_transport_snapshot( ring = OB_RING(worker_id); for (offset = 0; offset < ring->count; offset++) { const ClusterLmsOutboundSlot *slot - = &ring->ring[(ring->tail + offset) - % PGRAC_LMS_OUTBOUND_CAPACITY]; - - if (slot->kind - == (uint8)CLUSTER_LMS_OUTBOUND_RESOURCE_X_INTENT - || slot->kind - == (uint8)CLUSTER_LMS_OUTBOUND_RESOURCE_X_REMOTE_S_STATUS_PENDING - || slot->kind - == (uint8)CLUSTER_LMS_OUTBOUND_RESOURCE_X_REMOTE_S_STATUS_READY) + = &ring->ring[(ring->tail + offset) % PGRAC_LMS_OUTBOUND_CAPACITY]; + + if (slot->kind == (uint8)CLUSTER_LMS_OUTBOUND_RESOURCE_X_INTENT + || slot->kind == (uint8)CLUSTER_LMS_OUTBOUND_RESOURCE_X_REMOTE_S_STATUS_PENDING + || slot->kind == (uint8)CLUSTER_LMS_OUTBOUND_RESOURCE_X_REMOTE_S_STATUS_READY) out->staged_count++; } } diff --git a/src/backend/cluster/cluster_membership.c b/src/backend/cluster/cluster_membership.c index e657917fa6b..75657a992d6 100644 --- a/src/backend/cluster/cluster_membership.c +++ b/src/backend/cluster/cluster_membership.c @@ -69,8 +69,7 @@ node_id_in_range(int32 node_id) static inline uint32 jcmk_get_le32(const uint8 *p) { - return (uint32)p[0] | ((uint32)p[1] << 8) | ((uint32)p[2] << 16) - | ((uint32)p[3] << 24); + return (uint32)p[0] | ((uint32)p[1] << 8) | ((uint32)p[2] << 16) | ((uint32)p[3] << 24); } static inline uint64 @@ -130,8 +129,8 @@ cluster_replacement_marker_v3_encode(const ClusterReplacementCommitMarkerV3 *m, if (m == NULL || out == NULL) return false; if (m->magic != CLUSTER_JCMK_MAGIC || m->version != CLUSTER_JCMK_REPLACEMENT_VERSION - || !node_id_in_range(m->target_node_id) || m->generation == 0 - || m->reserved0[0] != 0 || m->reserved0[1] != 0 || m->reserved0[2] != 0 + || !node_id_in_range(m->target_node_id) || m->generation == 0 || m->reserved0[0] != 0 + || m->reserved0[1] != 0 || m->reserved0[2] != 0 || !replacement_marker_v3_phase_valid(m->phase, m->ready_state_generation)) return false; @@ -166,8 +165,7 @@ cluster_replacement_marker_v3_decode(const uint8 bytes[CLUSTER_JCMK_REPLACEMENT_ if (jcmk_get_le32(bytes + 0) != CLUSTER_JCMK_MAGIC || jcmk_get_le32(bytes + 4) != CLUSTER_JCMK_REPLACEMENT_VERSION || (int32)jcmk_get_le32(bytes + 8) != expected_target_node || bytes[13] != 0 - || bytes[14] != 0 || bytes[15] != 0 - || jcmk_get_le64(bytes + 16) == 0 + || bytes[14] != 0 || bytes[15] != 0 || jcmk_get_le64(bytes + 16) == 0 || !replacement_marker_v3_phase_valid(bytes[12], jcmk_get_le32(bytes + 88)) || replacement_marker_v3_crc(bytes) != jcmk_get_le32(bytes + 92)) return false; @@ -215,9 +213,10 @@ cluster_replacement_marker_v3_same_image(const ClusterReplacementCommitMarkerV3 * winning group is found. */ int -cluster_replacement_marker_v3_select_majority( - const uint8 images[][CLUSTER_JCMK_REPLACEMENT_BYTES], int n, uint32 majority, - int32 expected_target_node, ClusterReplacementCommitMarkerV3 *out_marker, uint32 *out_agree) +cluster_replacement_marker_v3_select_majority(const uint8 images[][CLUSTER_JCMK_REPLACEMENT_BYTES], + int n, uint32 majority, int32 expected_target_node, + ClusterReplacementCommitMarkerV3 *out_marker, + uint32 *out_agree) { int a; int b; @@ -253,9 +252,8 @@ cluster_replacement_marker_v3_select_majority( * the old admitted floor; post-COMMIT phases pin the fresh incarnation. */ bool -cluster_replacement_marker_v3_floor_basis( - const uint8 bytes[CLUSTER_JCMK_REPLACEMENT_BYTES], int32 expected_target_node, - uint64 *out_incarnation_floor) +cluster_replacement_marker_v3_floor_basis(const uint8 bytes[CLUSTER_JCMK_REPLACEMENT_BYTES], + int32 expected_target_node, uint64 *out_incarnation_floor) { ClusterReplacementCommitMarkerV3 marker; uint64 floor; @@ -299,16 +297,16 @@ cluster_replacement_marker_v3_is_committed_closed_basis( } bool -cluster_replacement_marker_v3_is_admitted_basis( - const uint8 bytes[CLUSTER_JCMK_REPLACEMENT_BYTES], int32 expected_target_node, - uint64 *out_incarnation_floor, uint32 *out_ready_state_generation) +cluster_replacement_marker_v3_is_admitted_basis(const uint8 bytes[CLUSTER_JCMK_REPLACEMENT_BYTES], + int32 expected_target_node, + uint64 *out_incarnation_floor, + uint32 *out_ready_state_generation) { ClusterReplacementCommitMarkerV3 marker; if (out_incarnation_floor == NULL || out_ready_state_generation == NULL || !cluster_replacement_marker_v3_decode(bytes, expected_target_node, &marker) - || marker.phase != CLUSTER_JCMK_REPLACEMENT_PHASE_ADMITTED - || marker.fresh_incarnation == 0) + || marker.phase != CLUSTER_JCMK_REPLACEMENT_PHASE_ADMITTED || marker.fresh_incarnation == 0) return false; *out_incarnation_floor = marker.fresh_incarnation; *out_ready_state_generation = marker.ready_state_generation; diff --git a/src/backend/cluster/cluster_multixact.c b/src/backend/cluster/cluster_multixact.c index 805b2737a48..4874da676a2 100644 --- a/src/backend/cluster/cluster_multixact.c +++ b/src/backend/cluster/cluster_multixact.c @@ -168,10 +168,8 @@ cluster_multixact_shmem_register(void) static bool cluster_multixact_member_overlay_install_raw(const ClusterMultiXactKey *key, uint16 member_count, const ClusterMultiXactMember *members, - MultiXactOffset member_offset, - XLogRecPtr source_lsn, - XLogRecPtr source_end_lsn, - const uint16 *member_wraps) + MultiXactOffset member_offset, XLogRecPtr source_lsn, + XLogRecPtr source_end_lsn, const uint16 *member_wraps) { ClusterMultiXactOverlayEntry *e; bool found; @@ -206,8 +204,7 @@ cluster_multixact_member_overlay_install_raw(const ClusterMultiXactKey *key, uin e->source_end_lsn = source_end_lsn; memset(e->member_wraps, 0, sizeof(e->member_wraps)); if (member_wraps != NULL) - memcpy(e->member_wraps, member_wraps, - member_count * sizeof(*member_wraps)); + memcpy(e->member_wraps, member_wraps, member_count * sizeof(*member_wraps)); memcpy(e->members, members, member_count * sizeof(ClusterMultiXactMember)); LWLockRelease(ClusterMultiXactLock); @@ -218,8 +215,7 @@ cluster_multixact_member_overlay_install_raw(const ClusterMultiXactKey *key, uin static bool cluster_multixact_member_overlay_lookup_raw(const ClusterMultiXactKey *key, ClusterMultiXactMemberOverlayResult *out, - int max_members_buf, - bool allow_recovery_projection) + int max_members_buf, bool allow_recovery_projection) { const ClusterMultiXactOverlayEntry *e; uint32 current_epoch; @@ -256,10 +252,8 @@ cluster_multixact_member_overlay_lookup_raw(const ClusterMultiXactKey *key, * immediate post-read verifier only. Normal visibility has no fresh * retained-source carrier and therefore must not serve these bytes as an * exact composition after retirement/recycle/ABA could have occurred. */ - if (!allow_recovery_projection && - (e->source_lsn != InvalidXLogRecPtr || - e->source_end_lsn != InvalidXLogRecPtr)) - { + if (!allow_recovery_projection + && (e->source_lsn != InvalidXLogRecPtr || e->source_end_lsn != InvalidXLogRecPtr)) { LWLockRelease(ClusterMultiXactLock); pg_atomic_fetch_add_u64(&ClusterMultiXactState->overlay_miss_count, 1); return false; @@ -346,7 +340,7 @@ cluster_multixact_resolve_visibility_raw(const ClusterMultiXactMemberOverlayResu memset(&tt_request, 0, sizeof(tt_request)); tt_request.key = &ttkey; if (cluster_tt_status_source_dispatch(CLUSTER_TT_SOURCE_LOOKUP, &tt_request, - &tt_source_result) + &tt_source_result) != CLUSTER_SEMANTIC_ADMISSION_OK || !tt_source_result.bool_value || !tt_source_result.lookup.authoritative) return CLUSTER_VISIBILITY_UNKNOWN; @@ -508,8 +502,8 @@ cluster_multixact_remote_xmax_resolve_raw(uint16 origin_slot, MultiXactId mxid, mxres = (ClusterMultiXactMemberOverlayResult *)palloc0(resbuf_sz); - if (!cluster_multixact_member_overlay_lookup_raw(&mxkey, mxres, - CLUSTER_MULTIXACT_MAX_MEMBERS, false)) { + if (!cluster_multixact_member_overlay_lookup_raw(&mxkey, mxres, CLUSTER_MULTIXACT_MAX_MEMBERS, + false)) { pfree(mxres); /* spec-7.1 D3-b: overlay miss -> ask the origin (banner). */ return cluster_multixact_remote_xmax_ask_origin(origin_slot, mxid, snap); @@ -550,28 +544,26 @@ cluster_multixact_get_member_count_raw(const ClusterMultiXactKey *key) return count; } -#define RF_SIDE_MULTIXACT_OFFSETS_PER_PAGE \ - ((uint32) BLCKSZ / sizeof(MultiXactOffset)) -#define RF_SIDE_MULTIXACT_MEMBERGROUP_SIZE \ - (sizeof(TransactionId) * 4 + 4) -#define RF_SIDE_MULTIXACT_MEMBERS_PER_PAGE \ - (((uint32) BLCKSZ / RF_SIDE_MULTIXACT_MEMBERGROUP_SIZE) * 4) +#define RF_SIDE_MULTIXACT_OFFSETS_PER_PAGE ((uint32)BLCKSZ / sizeof(MultiXactOffset)) +#define RF_SIDE_MULTIXACT_MEMBERGROUP_SIZE (sizeof(TransactionId) * 4 + 4) +#define RF_SIDE_MULTIXACT_MEMBERS_PER_PAGE \ + (((uint32)BLCKSZ / RF_SIDE_MULTIXACT_MEMBERGROUP_SIZE) * 4) static bool -cluster_multixact_projection_page_range(int page_number, uint32 per_page, - uint32 *first, uint32 *count) +cluster_multixact_projection_page_range(int page_number, uint32 per_page, uint32 *first, + uint32 *count) { uint64 first64; uint64 remaining; if (page_number < 0 || first == NULL || count == NULL) return false; - first64 = (uint64) (uint32) page_number * per_page; + first64 = (uint64)(uint32)page_number * per_page; if (first64 > UINT32_MAX) return false; - remaining = (uint64) UINT32_MAX - first64 + 1; - *first = (uint32) first64; - *count = (uint32) Min((uint64) per_page, remaining); + remaining = (uint64)UINT32_MAX - first64 + 1; + *first = (uint32)first64; + *count = (uint32)Min((uint64)per_page, remaining); return true; } @@ -586,8 +578,8 @@ cluster_multixact_projection_in_range(uint32 value, uint32 start, uint32 end) } static bool -cluster_multixact_projection_member_overlap( - const ClusterMultiXactOverlayEntry *entry, uint32 start, uint32 end) +cluster_multixact_projection_member_overlap(const ClusterMultiXactOverlayEntry *entry, uint32 start, + uint32 end) { uint32 i; @@ -596,38 +588,34 @@ cluster_multixact_projection_member_overlap( if (entry->member_offset == 0) return true; for (i = 0; i < entry->member_count; i++) - if (cluster_multixact_projection_in_range( - entry->member_offset + i, start, end)) + if (cluster_multixact_projection_in_range(entry->member_offset + i, start, end)) return true; return false; } static bool -cluster_multixact_projection_entry_selected( - const ClusterMultiXactOverlayEntry *entry, int origin_slot, - uint32 cluster_epoch, const ClusterSideProjectionOperationV1 *operation) +cluster_multixact_projection_entry_selected(const ClusterMultiXactOverlayEntry *entry, + int origin_slot, uint32 cluster_epoch, + const ClusterSideProjectionOperationV1 *operation) { uint32 first; uint32 count; uint32 end; - if (entry->key.origin_node_id != (uint16) origin_slot || - entry->key.cluster_epoch != cluster_epoch) + if (entry->key.origin_node_id != (uint16)origin_slot + || entry->key.cluster_epoch != cluster_epoch) return false; - if (operation->action == CLUSTER_SIDE_PROJECTION_ACTION_ZERO_PAGE) - { - if (operation->normalized_info == XLOG_MULTIXACT_ZERO_OFF_PAGE) - { - if (!cluster_multixact_projection_page_range(operation->page_number, - RF_SIDE_MULTIXACT_OFFSETS_PER_PAGE, &first, &count)) + if (operation->action == CLUSTER_SIDE_PROJECTION_ACTION_ZERO_PAGE) { + if (operation->normalized_info == XLOG_MULTIXACT_ZERO_OFF_PAGE) { + if (!cluster_multixact_projection_page_range( + operation->page_number, RF_SIDE_MULTIXACT_OFFSETS_PER_PAGE, &first, &count)) return false; - return entry->key.multixact_id >= first && - (uint64) entry->key.multixact_id < (uint64) first + count; + return entry->key.multixact_id >= first + && (uint64)entry->key.multixact_id < (uint64)first + count; } - if (operation->normalized_info == XLOG_MULTIXACT_ZERO_MEM_PAGE) - { - if (!cluster_multixact_projection_page_range(operation->page_number, - RF_SIDE_MULTIXACT_MEMBERS_PER_PAGE, &first, &count)) + if (operation->normalized_info == XLOG_MULTIXACT_ZERO_MEM_PAGE) { + if (!cluster_multixact_projection_page_range( + operation->page_number, RF_SIDE_MULTIXACT_MEMBERS_PER_PAGE, &first, &count)) return false; end = first + count; return cluster_multixact_projection_member_overlap(entry, first, end); @@ -636,28 +624,27 @@ cluster_multixact_projection_entry_selected( } if (operation->action == CLUSTER_SIDE_PROJECTION_ACTION_TRUNCATE) return cluster_multixact_projection_in_range(entry->key.multixact_id, - operation->truncate_start_multixact, - operation->truncate_end_multixact) || - cluster_multixact_projection_member_overlap(entry, - operation->truncate_start_member, - operation->truncate_end_member); + operation->truncate_start_multixact, + operation->truncate_end_multixact) + || cluster_multixact_projection_member_overlap( + entry, operation->truncate_start_member, operation->truncate_end_member); return false; } static bool cluster_multixact_projection_build_members(uint32 cluster_epoch, - const MultiXactMember *native_members, uint32 member_count, - ClusterMultiXactMember *members, uint16 *wraps) + const MultiXactMember *native_members, + uint32 member_count, ClusterMultiXactMember *members, + uint16 *wraps) { uint32 i; - if (native_members == NULL || members == NULL || wraps == NULL || - member_count == 0 || member_count > CLUSTER_MULTIXACT_MAX_MEMBERS) + if (native_members == NULL || members == NULL || wraps == NULL || member_count == 0 + || member_count > CLUSTER_MULTIXACT_MAX_MEMBERS) return false; memset(members, 0, member_count * sizeof(*members)); memset(wraps, 0, member_count * sizeof(*wraps)); - for (i = 0; i < member_count; i++) - { + for (i = 0; i < member_count; i++) { int member_origin; uint16 segment = 0; uint16 slot = 0; @@ -665,31 +652,28 @@ cluster_multixact_projection_build_members(uint32 cluster_epoch, uint8 tt_status = TT_SLOT_INVALID; ClusterTTDurableLocate locate; - if (!TransactionIdIsNormal(native_members[i].xid) || - native_members[i].status < MultiXactStatusForKeyShare || - native_members[i].status > MaxMultiXactStatus) + if (!TransactionIdIsNormal(native_members[i].xid) + || native_members[i].status < MultiXactStatusForKeyShare + || native_members[i].status > MaxMultiXactStatus) return false; member_origin = cluster_xid_origin_slot(native_members[i].xid); if (member_origin < 0 || member_origin >= (1 << 7)) return false; locate = cluster_tt_slot_durable_locate_any_by_xid_origin( - member_origin, native_members[i].xid, &segment, &slot, &wrap, - &tt_status); - if (locate != CLUSTER_TT_DURABLE_LOCATE_FOUND) - { + member_origin, native_members[i].xid, &segment, &slot, &wrap, &tt_status); + if (locate != CLUSTER_TT_DURABLE_LOCATE_FOUND) { /* Lock-only members never affect tuple visibility. A complete * zero-match is exact negative TT evidence; updater members still * require a concrete owner and otherwise block the projection. */ - if (locate != CLUSTER_TT_DURABLE_LOCATE_MISSING || - native_members[i].status > MultiXactStatusForUpdate) + if (locate != CLUSTER_TT_DURABLE_LOCATE_MISSING + || native_members[i].status > MultiXactStatusForUpdate) return false; } members[i].xid = native_members[i].xid; - members[i].status = (uint8) native_members[i].status; - members[i].origin_node_id = (uint16) member_origin; + members[i].status = (uint8)native_members[i].status; + members[i].origin_node_id = (uint16)member_origin; members[i].epoch = cluster_epoch; - if (locate == CLUSTER_TT_DURABLE_LOCATE_FOUND) - { + if (locate == CLUSTER_TT_DURABLE_LOCATE_FOUND) { members[i].undo_segment_id = segment; members[i].tt_slot_id = cluster_tt_slot_offset_to_id(slot); wraps[i] = wrap; @@ -699,55 +683,50 @@ cluster_multixact_projection_build_members(uint32 cluster_epoch, } bool -cluster_multixact_recovery_projection_apply(void *arg, int origin_slot, - uint32 cluster_epoch, const ClusterSideProjectionOperationV1 *operation, - const uint8 *owned_payload, uint32 owned_payload_length, - XLogRecPtr source_lsn, XLogRecPtr source_end_lsn) +cluster_multixact_recovery_projection_apply(void *arg, int origin_slot, uint32 cluster_epoch, + const ClusterSideProjectionOperationV1 *operation, + const uint8 *owned_payload, uint32 owned_payload_length, + XLogRecPtr source_lsn, XLogRecPtr source_end_lsn) { - (void) arg; - if (ClusterMultiXactHTAB == NULL || operation == NULL || origin_slot < 0 || - origin_slot >= (1 << 7) || cluster_epoch == 0 || - cluster_epoch != (uint32) cluster_epoch_get_current() || - source_lsn == InvalidXLogRecPtr || source_end_lsn <= source_lsn) + (void)arg; + if (ClusterMultiXactHTAB == NULL || operation == NULL || origin_slot < 0 + || origin_slot >= (1 << 7) || cluster_epoch == 0 + || cluster_epoch != (uint32)cluster_epoch_get_current() || source_lsn == InvalidXLogRecPtr + || source_end_lsn <= source_lsn) return false; - if (operation->action == CLUSTER_SIDE_PROJECTION_ACTION_CREATE) - { + if (operation->action == CLUSTER_SIDE_PROJECTION_ACTION_CREATE) { ClusterMultiXactKey key; ClusterMultiXactMember members[CLUSTER_MULTIXACT_MAX_MEMBERS]; uint16 wraps[CLUSTER_MULTIXACT_MAX_MEMBERS]; - const MultiXactMember *native_members = - (const MultiXactMember *) owned_payload; - - if (cluster_mxid_origin_slot(operation->multixact_id) != origin_slot || - operation->member_count == 0 || - operation->member_count > CLUSTER_MULTIXACT_MAX_MEMBERS || - owned_payload_length != operation->member_count * - sizeof(MultiXactMember) || - !cluster_multixact_projection_build_members(cluster_epoch, - native_members, operation->member_count, members, wraps)) + const MultiXactMember *native_members = (const MultiXactMember *)owned_payload; + + if (cluster_mxid_origin_slot(operation->multixact_id) != origin_slot + || operation->member_count == 0 + || operation->member_count > CLUSTER_MULTIXACT_MAX_MEMBERS + || owned_payload_length != operation->member_count * sizeof(MultiXactMember) + || !cluster_multixact_projection_build_members(cluster_epoch, native_members, + operation->member_count, members, wraps)) return false; memset(&key, 0, sizeof(key)); - key.origin_node_id = (uint16) origin_slot; + key.origin_node_id = (uint16)origin_slot; key.multixact_id = operation->multixact_id; key.cluster_epoch = cluster_epoch; - return cluster_multixact_member_overlay_install_raw(&key, - (uint16) operation->member_count, members, operation->member_offset, - source_lsn, source_end_lsn, wraps); + return cluster_multixact_member_overlay_install_raw(&key, (uint16)operation->member_count, + members, operation->member_offset, + source_lsn, source_end_lsn, wraps); } if (owned_payload_length != 0) return false; - if (operation->action == CLUSTER_SIDE_PROJECTION_ACTION_ZERO_PAGE || - operation->action == CLUSTER_SIDE_PROJECTION_ACTION_TRUNCATE) - { + if (operation->action == CLUSTER_SIDE_PROJECTION_ACTION_ZERO_PAGE + || operation->action == CLUSTER_SIDE_PROJECTION_ACTION_TRUNCATE) { HASH_SEQ_STATUS sequence; ClusterMultiXactOverlayEntry *entry; LWLockAcquire(ClusterMultiXactLock, LW_EXCLUSIVE); hash_seq_init(&sequence, ClusterMultiXactHTAB); - while ((entry = (ClusterMultiXactOverlayEntry *) - hash_seq_search(&sequence)) != NULL) - if (cluster_multixact_projection_entry_selected(entry, origin_slot, - cluster_epoch, operation)) + while ((entry = (ClusterMultiXactOverlayEntry *)hash_seq_search(&sequence)) != NULL) + if (cluster_multixact_projection_entry_selected(entry, origin_slot, cluster_epoch, + operation)) hash_search(ClusterMultiXactHTAB, &entry->key, HASH_REMOVE, NULL); LWLockRelease(ClusterMultiXactLock); return true; @@ -756,68 +735,64 @@ cluster_multixact_recovery_projection_apply(void *arg, int origin_slot, } bool -cluster_multixact_recovery_projection_verify(void *arg, int origin_slot, - uint32 cluster_epoch, const ClusterSideProjectionOperationV1 *operation, - const uint8 *owned_payload, uint32 owned_payload_length, - XLogRecPtr source_lsn, XLogRecPtr source_end_lsn) +cluster_multixact_recovery_projection_verify(void *arg, int origin_slot, uint32 cluster_epoch, + const ClusterSideProjectionOperationV1 *operation, + const uint8 *owned_payload, + uint32 owned_payload_length, XLogRecPtr source_lsn, + XLogRecPtr source_end_lsn) { - (void) arg; - if (ClusterMultiXactHTAB == NULL || operation == NULL || origin_slot < 0 || - origin_slot >= (1 << 7) || cluster_epoch == 0 || - cluster_epoch != (uint32) cluster_epoch_get_current()) + (void)arg; + if (ClusterMultiXactHTAB == NULL || operation == NULL || origin_slot < 0 + || origin_slot >= (1 << 7) || cluster_epoch == 0 + || cluster_epoch != (uint32)cluster_epoch_get_current()) return false; - if (operation->action == CLUSTER_SIDE_PROJECTION_ACTION_CREATE) - { + if (operation->action == CLUSTER_SIDE_PROJECTION_ACTION_CREATE) { ClusterMultiXactKey key; ClusterMultiXactMember expected[CLUSTER_MULTIXACT_MAX_MEMBERS]; uint16 expected_wraps[CLUSTER_MULTIXACT_MAX_MEMBERS]; - Size result_size = offsetof(ClusterMultiXactMemberOverlayResult, members) + - (Size) operation->member_count * sizeof(ClusterMultiXactMember); + Size result_size = offsetof(ClusterMultiXactMemberOverlayResult, members) + + (Size)operation->member_count * sizeof(ClusterMultiXactMember); ClusterMultiXactMemberOverlayResult *result; bool matches; - if (cluster_mxid_origin_slot(operation->multixact_id) != origin_slot || - operation->member_count == 0 || - operation->member_count > CLUSTER_MULTIXACT_MAX_MEMBERS || - owned_payload_length != operation->member_count * - sizeof(MultiXactMember) || - !cluster_multixact_projection_build_members(cluster_epoch, - (const MultiXactMember *) owned_payload, operation->member_count, + if (cluster_mxid_origin_slot(operation->multixact_id) != origin_slot + || operation->member_count == 0 + || operation->member_count > CLUSTER_MULTIXACT_MAX_MEMBERS + || owned_payload_length != operation->member_count * sizeof(MultiXactMember) + || !cluster_multixact_projection_build_members( + cluster_epoch, (const MultiXactMember *)owned_payload, operation->member_count, expected, expected_wraps)) return false; memset(&key, 0, sizeof(key)); - key.origin_node_id = (uint16) origin_slot; + key.origin_node_id = (uint16)origin_slot; key.multixact_id = operation->multixact_id; key.cluster_epoch = cluster_epoch; - result = (ClusterMultiXactMemberOverlayResult *) palloc0(result_size); - matches = cluster_multixact_member_overlay_lookup_raw(&key, result, - (int) operation->member_count, true) && result->authoritative && - result->member_count == operation->member_count && - result->member_offset == operation->member_offset && - result->source_lsn == source_lsn && - result->source_end_lsn == source_end_lsn && - memcmp(result->members, expected, - operation->member_count * sizeof(*expected)) == 0 && - memcmp(result->member_wraps, expected_wraps, - operation->member_count * sizeof(*expected_wraps)) == 0; + result = (ClusterMultiXactMemberOverlayResult *)palloc0(result_size); + matches + = cluster_multixact_member_overlay_lookup_raw(&key, result, + (int)operation->member_count, true) + && result->authoritative && result->member_count == operation->member_count + && result->member_offset == operation->member_offset + && result->source_lsn == source_lsn && result->source_end_lsn == source_end_lsn + && memcmp(result->members, expected, operation->member_count * sizeof(*expected)) == 0 + && memcmp(result->member_wraps, expected_wraps, + operation->member_count * sizeof(*expected_wraps)) + == 0; pfree(result); return matches; } - if (owned_payload_length == 0 && - (operation->action == CLUSTER_SIDE_PROJECTION_ACTION_ZERO_PAGE || - operation->action == CLUSTER_SIDE_PROJECTION_ACTION_TRUNCATE)) - { + if (owned_payload_length == 0 + && (operation->action == CLUSTER_SIDE_PROJECTION_ACTION_ZERO_PAGE + || operation->action == CLUSTER_SIDE_PROJECTION_ACTION_TRUNCATE)) { HASH_SEQ_STATUS sequence; ClusterMultiXactOverlayEntry *entry; bool empty = true; LWLockAcquire(ClusterMultiXactLock, LW_SHARED); hash_seq_init(&sequence, ClusterMultiXactHTAB); - while ((entry = (ClusterMultiXactOverlayEntry *) - hash_seq_search(&sequence)) != NULL) - if (cluster_multixact_projection_entry_selected(entry, origin_slot, - cluster_epoch, operation)) - { + while ((entry = (ClusterMultiXactOverlayEntry *)hash_seq_search(&sequence)) != NULL) + if (cluster_multixact_projection_entry_selected(entry, origin_slot, cluster_epoch, + operation)) { empty = false; break; } @@ -902,10 +877,8 @@ cluster_multixact_shmem_register(void) static bool cluster_multixact_member_overlay_install_raw(const ClusterMultiXactKey *key, uint16 member_count, const ClusterMultiXactMember *members, - MultiXactOffset member_offset, - XLogRecPtr source_lsn, - XLogRecPtr source_end_lsn, - const uint16 *member_wraps) + MultiXactOffset member_offset, XLogRecPtr source_lsn, + XLogRecPtr source_end_lsn, const uint16 *member_wraps) { (void)key; (void)member_count; @@ -920,8 +893,7 @@ cluster_multixact_member_overlay_install_raw(const ClusterMultiXactKey *key, uin static bool cluster_multixact_member_overlay_lookup_raw(const ClusterMultiXactKey *key, ClusterMultiXactMemberOverlayResult *out, - int max_members_buf, - bool allow_recovery_projection) + int max_members_buf, bool allow_recovery_projection) { (void)key; (void)max_members_buf; @@ -973,36 +945,37 @@ cluster_multixact_purge_epoch(uint32 obsolete_epoch) } bool -cluster_multixact_recovery_projection_apply(void *arg, int origin_slot, - uint32 cluster_epoch, const ClusterSideProjectionOperationV1 *operation, - const uint8 *owned_payload, uint32 owned_payload_length, - XLogRecPtr source_lsn, XLogRecPtr source_end_lsn) +cluster_multixact_recovery_projection_apply(void *arg, int origin_slot, uint32 cluster_epoch, + const ClusterSideProjectionOperationV1 *operation, + const uint8 *owned_payload, uint32 owned_payload_length, + XLogRecPtr source_lsn, XLogRecPtr source_end_lsn) { - (void) arg; - (void) origin_slot; - (void) cluster_epoch; - (void) operation; - (void) owned_payload; - (void) owned_payload_length; - (void) source_lsn; - (void) source_end_lsn; + (void)arg; + (void)origin_slot; + (void)cluster_epoch; + (void)operation; + (void)owned_payload; + (void)owned_payload_length; + (void)source_lsn; + (void)source_end_lsn; return false; } bool -cluster_multixact_recovery_projection_verify(void *arg, int origin_slot, - uint32 cluster_epoch, const ClusterSideProjectionOperationV1 *operation, - const uint8 *owned_payload, uint32 owned_payload_length, - XLogRecPtr source_lsn, XLogRecPtr source_end_lsn) +cluster_multixact_recovery_projection_verify(void *arg, int origin_slot, uint32 cluster_epoch, + const ClusterSideProjectionOperationV1 *operation, + const uint8 *owned_payload, + uint32 owned_payload_length, XLogRecPtr source_lsn, + XLogRecPtr source_end_lsn) { - (void) arg; - (void) origin_slot; - (void) cluster_epoch; - (void) operation; - (void) owned_payload; - (void) owned_payload_length; - (void) source_lsn; - (void) source_end_lsn; + (void)arg; + (void)origin_slot; + (void)cluster_epoch; + (void)operation; + (void)owned_payload; + (void)owned_payload_length; + (void)source_lsn; + (void)source_end_lsn; return false; } @@ -1040,8 +1013,8 @@ cluster_multixact_source_dispatch_body(ClusterMultiXactSourceOp op, if (request == NULL || request->key == NULL || request->members == NULL) return CLUSTER_SEMANTIC_ADMISSION_CLOSED; result->bool_value = cluster_multixact_member_overlay_install_raw( - request->key, request->member_count, request->members, 0, - InvalidXLogRecPtr, InvalidXLogRecPtr, NULL); + request->key, request->member_count, request->members, 0, InvalidXLogRecPtr, + InvalidXLogRecPtr, NULL); break; case CLUSTER_MULTI_SOURCE_OVERLAY_LOOKUP: if (request == NULL || request->key == NULL || request->overlay_out == NULL) @@ -1155,9 +1128,8 @@ cluster_multixact_source_dispatch(ClusterMultiXactSourceOp op, * fence and must remain fail closed rather than crossing sides. */ ClusterSemanticAdmissionResult -cluster_multixact_remote_xmax_visibility_dispatch( - const ClusterMultiXactSourceRequest *request, - ClusterMultiXactSourceResult *result) +cluster_multixact_remote_xmax_visibility_dispatch(const ClusterMultiXactSourceRequest *request, + ClusterMultiXactSourceResult *result) { ClusterSemanticAdmissionToken token; ClusterMultiXactSourceResult local_result; @@ -1169,12 +1141,11 @@ cluster_multixact_remote_xmax_visibility_dispatch( if (result != NULL) memset(result, 0, sizeof(*result)); - admission = cluster_semantic_activation_enter( - CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, - CLUSTER_SEMANTIC_TARGET_SIDE, &token); + admission = cluster_semantic_activation_enter(CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, + CLUSTER_SEMANTIC_TARGET_SIDE, &token); if (admission == CLUSTER_SEMANTIC_ADMISSION_TARGET_DISABLED) - return cluster_multixact_source_dispatch( - CLUSTER_MULTI_SOURCE_REMOTE_XMAX_RESOLVE, request, result); + return cluster_multixact_source_dispatch(CLUSTER_MULTI_SOURCE_REMOTE_XMAX_RESOLVE, request, + result); if (admission != CLUSTER_SEMANTIC_ADMISSION_OK) return admission; @@ -1184,8 +1155,7 @@ cluster_multixact_remote_xmax_visibility_dispatch( admission = CLUSTER_SEMANTIC_ADMISSION_CLOSED; else admission = cluster_multixact_source_dispatch_body( - CLUSTER_MULTI_SOURCE_REMOTE_XMAX_RESOLVE, request, - &local_result); + CLUSTER_MULTI_SOURCE_REMOTE_XMAX_RESOLVE, request, &local_result); if (admission == CLUSTER_SEMANTIC_ADMISSION_OK) { if (!cluster_semantic_activation_recheck(&token)) diff --git a/src/backend/cluster/cluster_multixact_current.c b/src/backend/cluster/cluster_multixact_current.c index 71228aff19f..8140f827759 100644 --- a/src/backend/cluster/cluster_multixact_current.c +++ b/src/backend/cluster/cluster_multixact_current.c @@ -64,8 +64,7 @@ proof_key_is_zero(const ClusterCurrentMemberProofKey *key) static void -proof_key_set_unbound(ClusterCurrentMemberProofKey *proof_key, - const ClusterTTStatusKey *status_key) +proof_key_set_unbound(ClusterCurrentMemberProofKey *proof_key, const ClusterTTStatusKey *status_key) { memset(proof_key, 0, sizeof(*proof_key)); proof_key->origin_node_id = status_key->origin_node_id; @@ -91,65 +90,58 @@ tt_key_valid(const ClusterTTStatusKey *key, TransactionId xid, uint32 epoch, int static bool -tt_key_valid_holder(const ClusterTTStatusKey *key, TransactionId member_xid, - uint32 epoch, int expected_origin) +tt_key_valid_holder(const ClusterTTStatusKey *key, TransactionId member_xid, uint32 epoch, + int expected_origin) { return tt_key_valid(key, InvalidTransactionId, epoch, expected_origin) - && (key->local_xid == member_xid - || TransactionIdPrecedes(key->local_xid, member_xid)); + && (key->local_xid == member_xid || TransactionIdPrecedes(key->local_xid, member_xid)); } static bool -proof_key_valid_holder(const ClusterCurrentMemberProof *proof, - TransactionId member_xid, uint32 epoch, - int expected_origin) +proof_key_valid_holder(const ClusterCurrentMemberProof *proof, TransactionId member_xid, + uint32 epoch, int expected_origin) { ClusterTTStatusKey status_key; uint32 segment_generation; uint16 slot_wrap; - return ClusterCurrentMemberProofGetStatusKey( - proof, &status_key, &segment_generation, &slot_wrap) - && slot_wrap <= TT_WRAP_MAX - && tt_key_valid_holder(&status_key, member_xid, epoch, - expected_origin); + return ClusterCurrentMemberProofGetStatusKey(proof, &status_key, &segment_generation, + &slot_wrap) + && slot_wrap <= TT_WRAP_MAX + && tt_key_valid_holder(&status_key, member_xid, epoch, expected_origin); } bool -cluster_multixact_current_member_proof_bind_ctrc( - ClusterCurrentMemberProof *proof, const ClusterCtrcTxnKeyV1 *ctrc_key) +cluster_multixact_current_member_proof_bind_ctrc(ClusterCurrentMemberProof *proof, + const ClusterCtrcTxnKeyV1 *ctrc_key) { if (proof == NULL || ctrc_key == NULL || (proof->state != CCM_ACTIVE && proof->state != CCM_SELF) || ClusterCurrentMemberProofGetCtrcGrant(proof) == 0 || ctrc_key->format_version != CLUSTER_CTRC_FORMAT_VERSION - || ctrc_key->owner_instance != ctrc_key->origin_node_id + 1 - || ctrc_key->segment_id == 0 || ctrc_key->segment_id > UINT16_MAX - || ctrc_key->segment_generation == UINT32_MAX - || ctrc_key->slot_offset >= TT_SLOTS_PER_SEGMENT - || ctrc_key->slot_wrap > TT_WRAP_MAX + || ctrc_key->owner_instance != ctrc_key->origin_node_id + 1 || ctrc_key->segment_id == 0 + || ctrc_key->segment_id > UINT16_MAX || ctrc_key->segment_generation == UINT32_MAX + || ctrc_key->slot_offset >= TT_SLOTS_PER_SEGMENT || ctrc_key->slot_wrap > TT_WRAP_MAX || proof->key.origin_node_id != ctrc_key->origin_node_id || proof->key.undo_segment_id != (uint16)ctrc_key->segment_id - || proof->key.tt_slot_id - != cluster_tt_slot_offset_to_id(ctrc_key->slot_offset) + || proof->key.tt_slot_id != cluster_tt_slot_offset_to_id(ctrc_key->slot_offset) || proof->key.cluster_epoch != ctrc_key->cluster_epoch || proof->key.local_xid != ctrc_key->xid) return false; - ClusterCurrentMemberProofSetCtrcBinding( - proof, ctrc_key->segment_generation, ctrc_key->slot_wrap); + ClusterCurrentMemberProofSetCtrcBinding(proof, ctrc_key->segment_generation, + ctrc_key->slot_wrap); return true; } bool cluster_multixact_current_resolve_origin_member_proof( - TransactionId member_xid, uint8 member_status, uint16 member_ordinal, - uint16 member_origin_node, uint32 current_epoch, bool requester_self, - const ClusterTTStatusKey *initial_key, const ClusterTTStatusResult *initial_result, - ClusterCurrentMxExactLookupFn exact_lookup, void *exact_lookup_arg, - ClusterCurrentMemberProof *proof) + TransactionId member_xid, uint8 member_status, uint16 member_ordinal, uint16 member_origin_node, + uint32 current_epoch, bool requester_self, const ClusterTTStatusKey *initial_key, + const ClusterTTStatusResult *initial_result, ClusterCurrentMxExactLookupFn exact_lookup, + void *exact_lookup_arg, ClusterCurrentMemberProof *proof) { ClusterTTStatusKey seen_keys[CLUSTER_CURRENT_MX_MAX_PARENT_CHAIN_DEPTH + 1]; ClusterTTStatusKey resolved_key; @@ -161,9 +153,8 @@ cluster_multixact_current_resolve_origin_member_proof( memset(proof, 0, sizeof(*proof)); proof->state = CCM_UNKNOWN; } - if (proof == NULL || !TransactionIdIsNormal(member_xid) - || member_status > MaxMultiXactStatus || member_origin_node >= CLUSTER_MAX_NODES - || initial_key == NULL || initial_result == NULL + if (proof == NULL || !TransactionIdIsNormal(member_xid) || member_status > MaxMultiXactStatus + || member_origin_node >= CLUSTER_MAX_NODES || initial_key == NULL || initial_result == NULL || !initial_result->authoritative || initial_result->status_epoch != current_epoch || !tt_key_valid(initial_key, member_xid, current_epoch, member_origin_node)) return false; @@ -184,8 +175,7 @@ cluster_multixact_current_resolve_origin_member_proof( || seen_count >= lengthof(seen_keys)) goto unknown; parent_key = resolved_result.parent_key; - if (!tt_key_valid(&parent_key, InvalidTransactionId, current_epoch, - member_origin_node) + if (!tt_key_valid(&parent_key, InvalidTransactionId, current_epoch, member_origin_node) || !TransactionIdPrecedes(parent_key.local_xid, resolved_key.local_xid)) goto unknown; for (i = 0; i < seen_count; i++) @@ -236,10 +226,12 @@ cluster_multixact_current_resolve_origin_member_proof( ClusterUpdaterCandidateVerdict -cluster_multixact_current_updater_candidate_verdict( - const ClusterTTStatusKey *candidate, TransactionId updater_xid, - uint16 updater_origin_node, uint32 current_epoch, ClusterTTStatusKey *current_binding, - ClusterTTStatusResult *current_result) +cluster_multixact_current_updater_candidate_verdict(const ClusterTTStatusKey *candidate, + TransactionId updater_xid, + uint16 updater_origin_node, + uint32 current_epoch, + ClusterTTStatusKey *current_binding, + ClusterTTStatusResult *current_result) { ClusterTTStatusKey sampled_binding; ClusterTTStatusResult sampled_result; @@ -252,21 +244,19 @@ cluster_multixact_current_updater_candidate_verdict( current_result->commit_scn = InvalidScn; } if (candidate == NULL || current_binding == NULL || current_result == NULL - || updater_origin_node >= CLUSTER_MAX_NODES - || cluster_node_id < 0 || updater_origin_node != (uint16)cluster_node_id + || updater_origin_node >= CLUSTER_MAX_NODES || cluster_node_id < 0 + || updater_origin_node != (uint16)cluster_node_id || !tt_key_valid(candidate, updater_xid, current_epoch, updater_origin_node)) return CUCP_UNKNOWN; memset(&sampled_binding, 0, sizeof(sampled_binding)); memset(&sampled_result, 0, sizeof(sampled_result)); - if (!(cluster_runtime_visibility_current_owner_lookup_exact( - updater_xid, &sampled_binding, &sampled_result) - || cluster_runtime_visibility_local_terminal_lookup_exact( - updater_xid, &sampled_binding, &sampled_result)) - || !sampled_result.authoritative - || sampled_result.status_epoch != current_epoch - || !tt_key_valid(&sampled_binding, updater_xid, current_epoch, - updater_origin_node)) + if (!(cluster_runtime_visibility_current_owner_lookup_exact(updater_xid, &sampled_binding, + &sampled_result) + || cluster_runtime_visibility_local_terminal_lookup_exact(updater_xid, &sampled_binding, + &sampled_result)) + || !sampled_result.authoritative || sampled_result.status_epoch != current_epoch + || !tt_key_valid(&sampled_binding, updater_xid, current_epoch, updater_origin_node)) return CUCP_UNKNOWN; if (memcmp(candidate, &sampled_binding, sizeof(*candidate)) == 0) { @@ -283,9 +273,8 @@ cluster_multixact_current_updater_candidate_verdict( bool cluster_multixact_current_successor_provenance_well_formed( - const ClusterCurrentMxSuccessorAlias *alias, - const ClusterTxLocator *locator, TransactionId updater_xid, - uint16 updater_origin_node, uint32 current_epoch) + const ClusterCurrentMxSuccessorAlias *alias, const ClusterTxLocator *locator, + TransactionId updater_xid, uint16 updater_origin_node, uint32 current_epoch) { uint32 segment_id; uint32 block_no; @@ -294,30 +283,22 @@ cluster_multixact_current_successor_provenance_well_formed( uint32 derived_origin; bool data_kind; - if (alias == NULL || locator == NULL - || updater_origin_node >= CLUSTER_MAX_NODES + if (alias == NULL || locator == NULL || updater_origin_node >= CLUSTER_MAX_NODES || !TransactionIdIsNormal(updater_xid) - || !uba_decode_record(locator->uba, &segment_id, &block_no, - &tt_slot_offset, &row_offset)) + || !uba_decode_record(locator->uba, &segment_id, &block_no, &tt_slot_offset, &row_offset)) return false; - data_kind = locator->itl_kind == ITL_FLAG_ACTIVE - || locator->itl_kind == ITL_FLAG_COMMITTED + data_kind = locator->itl_kind == ITL_FLAG_ACTIVE || locator->itl_kind == ITL_FLAG_COMMITTED || locator->itl_kind == ITL_FLAG_ABORTED || locator->itl_kind == ITL_FLAG_NEEDS_CLEANOUT; derived_origin = (segment_id - 1) / CLUSTER_UNDO_SEGS_PER_INSTANCE; - return data_kind - && segment_id <= UINT16_MAX - && derived_origin == updater_origin_node - && row_offset - < (BLCKSZ - sizeof(UndoBlockHeader)) / sizeof(UndoSlotDirEntry) - && locator->xid == updater_xid - && locator->tt_wrap == TT_WRAP_INVALID + return data_kind && segment_id <= UINT16_MAX && derived_origin == updater_origin_node + && row_offset < (BLCKSZ - sizeof(UndoBlockHeader)) / sizeof(UndoSlotDirEntry) + && locator->xid == updater_xid && locator->tt_wrap == TT_WRAP_INVALID && locator->itl_slot_index < CLUSTER_ITL_INITRANS_DEFAULT && alias->origin_node_id == updater_origin_node && alias->undo_record_segment_id == (uint16)segment_id && alias->tt_slot_id == (uint32)tt_slot_offset + 1 - && alias->cluster_epoch == current_epoch - && alias->local_xid == updater_xid + && alias->cluster_epoch == current_epoch && alias->local_xid == updater_xid && alias->reserved32 == 0 && alias->reserved32_2 == 0; } @@ -327,11 +308,10 @@ cluster_multixact_current_successor_provenance_well_formed( * generation; terminal state is sampled from the exact current-or-rolled * physical slot and deliberately carries neither grant nor participant. */ static bool -current_mx_local_member_sample_exact( - TransactionId xid, ClusterTTStatusKey *key, - ClusterTTStatusResult *result, uint32 *ctrc_grant, - uint32 *participant_capability_generation, - ClusterCtrcTxnKeyV1 *ctrc_key_out) +current_mx_local_member_sample_exact(TransactionId xid, ClusterTTStatusKey *key, + ClusterTTStatusResult *result, uint32 *ctrc_grant, + uint32 *participant_capability_generation, + ClusterCtrcTxnKeyV1 *ctrc_key_out) { ClusterCtrcTxnKeyV1 ctrc_key; ClusterCtrcParticipantIdentity participant; @@ -349,14 +329,11 @@ current_mx_local_member_sample_exact( MemSet(&ctrc_key, 0, sizeof(ctrc_key)); MemSet(&participant, 0, sizeof(participant)); if (cluster_runtime_visibility_current_owner_lookup_exact_ctrc_full( - xid, key, result, ctrc_grant, &ctrc_key, &participant)) - { - if (result->status != CLUSTER_TT_STATUS_IN_PROGRESS - || *ctrc_grant == 0 + xid, key, result, ctrc_grant, &ctrc_key, &participant)) { + if (result->status != CLUSTER_TT_STATUS_IN_PROGRESS || *ctrc_grant == 0 || participant.capability_record_generation == 0) return false; - *participant_capability_generation - = participant.capability_record_generation; + *participant_capability_generation = participant.capability_record_generation; *ctrc_key_out = ctrc_key; return true; } @@ -366,10 +343,9 @@ current_mx_local_member_sample_exact( result->status = CLUSTER_TT_STATUS_UNKNOWN; result->commit_scn = InvalidScn; *ctrc_grant = 0; - return cluster_runtime_visibility_local_terminal_lookup_exact( - xid, key, result) - && (result->status == CLUSTER_TT_STATUS_COMMITTED - || result->status == CLUSTER_TT_STATUS_ABORTED); + return cluster_runtime_visibility_local_terminal_lookup_exact(xid, key, result) + && (result->status == CLUSTER_TT_STATUS_COMMITTED + || result->status == CLUSTER_TT_STATUS_ABORTED); } @@ -419,109 +395,100 @@ descriptor_shape_matches(const ClusterCurrentMxMemberDesc *members, uint16 nmemb bool -cluster_multixact_current_plan_heap_header( - const void *base_header, Size header_size, - const ClusterCurrentMxHeapHeaderPlan *plan, void *planned_header) +cluster_multixact_current_plan_heap_header(const void *base_header, Size header_size, + const ClusterCurrentMxHeapHeaderPlan *plan, + void *planned_header) { HeapTupleHeaderData storage; HeapTupleHeader header = &storage; if (base_header == NULL || plan == NULL || planned_header == NULL - || header_size != SizeofHeapTupleHeader - || plan->kind < CMX_HEAP_PUBLISH_DELETE - || plan->kind > CMX_HEAP_PUBLISH_TUPLE_LOCK - || !MultiXactIdIsValid(plan->multixact_id) + || header_size != SizeofHeapTupleHeader || plan->kind < CMX_HEAP_PUBLISH_DELETE + || plan->kind > CMX_HEAP_PUBLISH_TUPLE_LOCK || !MultiXactIdIsValid(plan->multixact_id) || (plan->infomask & HEAP_XMAX_IS_MULTI) == 0 || (plan->itl_slot_index != CLUSTER_ITL_SLOT_UNALLOCATED && plan->itl_slot_index >= CLUSTER_ITL_INITRANS_DEFAULT)) return false; if (!ItemPointerIsValid(&plan->self_tid) - || (plan->kind == CMX_HEAP_PUBLISH_UPDATE_OLD - && !ItemPointerIsValid(&plan->successor_tid))) + || (plan->kind == CMX_HEAP_PUBLISH_UPDATE_OLD && !ItemPointerIsValid(&plan->successor_tid))) return false; memcpy(&storage, base_header, header_size); - switch (plan->kind) - { - case CMX_HEAP_PUBLISH_DELETE: - header->t_infomask &= ~(HEAP_XMAX_BITS | HEAP_MOVED); - header->t_infomask2 &= ~HEAP_KEYS_UPDATED; - header->t_infomask |= plan->infomask; - header->t_infomask2 |= plan->infomask2; + switch (plan->kind) { + case CMX_HEAP_PUBLISH_DELETE: + header->t_infomask &= ~(HEAP_XMAX_BITS | HEAP_MOVED); + header->t_infomask2 &= ~HEAP_KEYS_UPDATED; + header->t_infomask |= plan->infomask; + header->t_infomask2 |= plan->infomask2; + HeapTupleHeaderClearHotUpdated(header); + HeapTupleHeaderSetXmax(header, plan->multixact_id); + HeapTupleHeaderSetCmax(header, plan->command_id, plan->command_is_combo); + header->t_ctid = plan->self_tid; + if (plan->changing_partition) + HeapTupleHeaderSetMovedPartitions(header); + break; + + case CMX_HEAP_PUBLISH_UPDATE_OLD: + if (plan->changing_partition) + return false; + if (plan->hot_update) + HeapTupleHeaderSetHotUpdated(header); + else HeapTupleHeaderClearHotUpdated(header); - HeapTupleHeaderSetXmax(header, plan->multixact_id); - HeapTupleHeaderSetCmax( - header, plan->command_id, plan->command_is_combo); - header->t_ctid = plan->self_tid; - if (plan->changing_partition) - HeapTupleHeaderSetMovedPartitions(header); - break; + header->t_infomask &= ~(HEAP_XMAX_BITS | HEAP_MOVED); + header->t_infomask2 &= ~HEAP_KEYS_UPDATED; + header->t_infomask |= plan->infomask; + header->t_infomask2 |= plan->infomask2; + HeapTupleHeaderSetXmax(header, plan->multixact_id); + HeapTupleHeaderSetCmax(header, plan->command_id, plan->command_is_combo); + header->t_ctid = plan->successor_tid; + break; - case CMX_HEAP_PUBLISH_UPDATE_OLD: - if (plan->changing_partition) - return false; - if (plan->hot_update) - HeapTupleHeaderSetHotUpdated(header); - else - HeapTupleHeaderClearHotUpdated(header); - header->t_infomask &= ~(HEAP_XMAX_BITS | HEAP_MOVED); - header->t_infomask2 &= ~HEAP_KEYS_UPDATED; - header->t_infomask |= plan->infomask; - header->t_infomask2 |= plan->infomask2; - HeapTupleHeaderSetXmax(header, plan->multixact_id); - HeapTupleHeaderSetCmax( - header, plan->command_id, plan->command_is_combo); - header->t_ctid = plan->successor_tid; - break; + case CMX_HEAP_PUBLISH_UPDATE_NEW: + if (plan->changing_partition || plan->command_is_combo + || !TransactionIdIsNormal(plan->xmin)) + return false; + header->t_infomask &= ~HEAP_XACT_MASK; + header->t_infomask2 &= ~HEAP2_XACT_MASK; + HeapTupleHeaderSetXmin(header, plan->xmin); + HeapTupleHeaderSetCmin(header, plan->command_id); + header->t_infomask |= HEAP_UPDATED | plan->infomask; + header->t_infomask2 |= plan->infomask2; + HeapTupleHeaderSetXmax(header, plan->multixact_id); + if (plan->hot_update) + HeapTupleHeaderSetHeapOnly(header); + else + HeapTupleHeaderClearHeapOnly(header); + header->t_ctid = plan->self_tid; + break; - case CMX_HEAP_PUBLISH_UPDATE_NEW: - if (plan->changing_partition || plan->command_is_combo - || !TransactionIdIsNormal(plan->xmin)) - return false; - header->t_infomask &= ~HEAP_XACT_MASK; - header->t_infomask2 &= ~HEAP2_XACT_MASK; - HeapTupleHeaderSetXmin(header, plan->xmin); - HeapTupleHeaderSetCmin(header, plan->command_id); - header->t_infomask |= HEAP_UPDATED | plan->infomask; - header->t_infomask2 |= plan->infomask2; - HeapTupleHeaderSetXmax(header, plan->multixact_id); - if (plan->hot_update) - HeapTupleHeaderSetHeapOnly(header); - else - HeapTupleHeaderClearHeapOnly(header); - header->t_ctid = plan->self_tid; - break; + case CMX_HEAP_PUBLISH_TEMP_LOCK: + if (plan->changing_partition || plan->hot_update) + return false; + header->t_infomask &= ~(HEAP_XMAX_BITS | HEAP_MOVED); + header->t_infomask2 &= ~HEAP_KEYS_UPDATED; + HeapTupleHeaderClearHotUpdated(header); + HeapTupleHeaderSetXmax(header, plan->multixact_id); + header->t_infomask |= plan->infomask; + header->t_infomask2 |= plan->infomask2; + HeapTupleHeaderSetCmax(header, plan->command_id, plan->command_is_combo); + header->t_ctid = plan->self_tid; + break; - case CMX_HEAP_PUBLISH_TEMP_LOCK: - if (plan->changing_partition || plan->hot_update) - return false; - header->t_infomask &= ~(HEAP_XMAX_BITS | HEAP_MOVED); - header->t_infomask2 &= ~HEAP_KEYS_UPDATED; + case CMX_HEAP_PUBLISH_TUPLE_LOCK: + if (plan->changing_partition || plan->hot_update || plan->command_is_combo) + return false; + header->t_infomask &= ~HEAP_XMAX_BITS; + header->t_infomask2 &= ~HEAP_KEYS_UPDATED; + header->t_infomask |= plan->infomask; + header->t_infomask2 |= plan->infomask2; + if (HEAP_XMAX_IS_LOCKED_ONLY(plan->infomask)) { HeapTupleHeaderClearHotUpdated(header); - HeapTupleHeaderSetXmax(header, plan->multixact_id); - header->t_infomask |= plan->infomask; - header->t_infomask2 |= plan->infomask2; - HeapTupleHeaderSetCmax( - header, plan->command_id, plan->command_is_combo); header->t_ctid = plan->self_tid; - break; - - case CMX_HEAP_PUBLISH_TUPLE_LOCK: - if (plan->changing_partition || plan->hot_update - || plan->command_is_combo) - return false; - header->t_infomask &= ~HEAP_XMAX_BITS; - header->t_infomask2 &= ~HEAP_KEYS_UPDATED; - header->t_infomask |= plan->infomask; - header->t_infomask2 |= plan->infomask2; - if (HEAP_XMAX_IS_LOCKED_ONLY(plan->infomask)) - { - HeapTupleHeaderClearHotUpdated(header); - header->t_ctid = plan->self_tid; - } - HeapTupleHeaderSetXmax(header, plan->multixact_id); - break; + } + HeapTupleHeaderSetXmax(header, plan->multixact_id); + break; } if (plan->itl_slot_index != CLUSTER_ITL_SLOT_UNALLOCATED) @@ -532,33 +499,27 @@ cluster_multixact_current_plan_heap_header( bool -cluster_multixact_current_heap_publish_transition( - ClusterCurrentMxHeapPublishStage stage, - ClusterCurrentMxHeapPublishEvent event, - ClusterCurrentMxHeapPublishStage *next_stage) +cluster_multixact_current_heap_publish_transition(ClusterCurrentMxHeapPublishStage stage, + ClusterCurrentMxHeapPublishEvent event, + ClusterCurrentMxHeapPublishStage *next_stage) { if (next_stage == NULL) return false; - if (stage == CMX_HEAP_STAGE_LOCAL_DESCRIPTOR - && event == CMX_HEAP_EVENT_PREPARE) + if (stage == CMX_HEAP_STAGE_LOCAL_DESCRIPTOR && event == CMX_HEAP_EVENT_PREPARE) *next_stage = CMX_HEAP_STAGE_RECEIPT_PREPARED; - else if (stage == CMX_HEAP_STAGE_RECEIPT_PREPARED - && event == CMX_HEAP_EVENT_RETRY) + else if (stage == CMX_HEAP_STAGE_RECEIPT_PREPARED && event == CMX_HEAP_EVENT_RETRY) *next_stage = CMX_HEAP_STAGE_CANCELLED; - else if ((stage == CMX_HEAP_STAGE_LOCAL_DESCRIPTOR - || stage == CMX_HEAP_STAGE_RECEIPT_PREPARED) + else if ((stage == CMX_HEAP_STAGE_LOCAL_DESCRIPTOR || stage == CMX_HEAP_STAGE_RECEIPT_PREPARED) && event == CMX_HEAP_EVENT_ERROR) *next_stage = CMX_HEAP_STAGE_CANCELLED; else if ((stage == CMX_HEAP_STAGE_RECEIPT_APPLIED || stage == CMX_HEAP_STAGE_REFERENCE_PUBLISHED) && event == CMX_HEAP_EVENT_ERROR) *next_stage = stage; - else if (stage == CMX_HEAP_STAGE_RECEIPT_PREPARED - && event == CMX_HEAP_EVENT_APPLY) + else if (stage == CMX_HEAP_STAGE_RECEIPT_PREPARED && event == CMX_HEAP_EVENT_APPLY) *next_stage = CMX_HEAP_STAGE_RECEIPT_APPLIED; - else if (stage == CMX_HEAP_STAGE_RECEIPT_APPLIED - && event == CMX_HEAP_EVENT_PUBLISH) + else if (stage == CMX_HEAP_STAGE_RECEIPT_APPLIED && event == CMX_HEAP_EVENT_PUBLISH) *next_stage = CMX_HEAP_STAGE_REFERENCE_PUBLISHED; else return false; @@ -654,19 +615,17 @@ proof_entry_semantic_valid(const ClusterCurrentMemberProof *proof, switch ((ClusterCurrentMemberState)proof->state) { case CCM_SELF: case CCM_ACTIVE: - return ClusterCurrentMemberProofGetCtrcGrant(proof) != 0 - && proof->commit_scn == InvalidScn - && proof_key_valid_holder(proof, proof->member_xid, epoch, - expected_origin); + return ClusterCurrentMemberProofGetCtrcGrant(proof) != 0 && proof->commit_scn == InvalidScn + && proof_key_valid_holder(proof, proof->member_xid, epoch, expected_origin); case CCM_COMMITTED: - return ClusterCurrentMemberProofGetCtrcGrant(proof) == 0 - && proof_key_is_zero(&proof->key) && SCN_VALID(proof->commit_scn); + return ClusterCurrentMemberProofGetCtrcGrant(proof) == 0 && proof_key_is_zero(&proof->key) + && SCN_VALID(proof->commit_scn); case CCM_ABORTED: case CCM_UNKNOWN: - return ClusterCurrentMemberProofGetCtrcGrant(proof) == 0 - && proof_key_is_zero(&proof->key) && proof->commit_scn == InvalidScn; + return ClusterCurrentMemberProofGetCtrcGrant(proof) == 0 && proof_key_is_zero(&proof->key) + && proof->commit_scn == InvalidScn; } return false; @@ -770,8 +729,7 @@ cluster_multixact_current_validate_proof_set(const ClusterCurrentMxKey *key, static bool validate_updater_proof_state(const ClusterCurrentMxKey *key, const ClusterCurrentMxMemberDesc *members, - const ClusterCurrentMemberProof *proofs, - uint16 nmembers, + const ClusterCurrentMemberProof *proofs, uint16 nmembers, const ClusterCurrentUpdaterChallenge *challenge, const ClusterCurrentUpdaterProof *updater_proof, uint16 updater_origin_node_id, @@ -801,18 +759,14 @@ validate_updater_proof_state(const ClusterCurrentMxKey *key, || challenge->updater_xid != members[updater_ordinal].xid || updater_proof->updater_xid != members[updater_ordinal].xid || !cluster_multixact_current_successor_provenance_well_formed( - &challenge->candidate_next_xmin_alias, - &challenge->candidate_next_xmin_locator, - members[updater_ordinal].xid, updater_origin_node_id, - key->cluster_epoch) - || memcmp(&challenge->candidate_next_xmin_alias, - &updater_proof->candidate_next_xmin_alias, + &challenge->candidate_next_xmin_alias, &challenge->candidate_next_xmin_locator, + members[updater_ordinal].xid, updater_origin_node_id, key->cluster_epoch) + || memcmp(&challenge->candidate_next_xmin_alias, &updater_proof->candidate_next_xmin_alias, sizeof(ClusterCurrentMxSuccessorAlias)) != 0 || updater_proof->candidate_next_xmin_locator.tt_wrap > TT_WRAP_MAX - || !cluster_tx_locator_reply_matches( - &challenge->candidate_next_xmin_locator, - &updater_proof->candidate_next_xmin_locator)) + || !cluster_tx_locator_reply_matches(&challenge->candidate_next_xmin_locator, + &updater_proof->candidate_next_xmin_locator)) return false; return true; @@ -827,9 +781,8 @@ cluster_multixact_current_validate_updater_proof(const ClusterCurrentMxKey *key, const ClusterCurrentUpdaterProof *updater_proof, uint16 updater_origin_node_id) { - return validate_updater_proof_state( - key, members, proofs, nmembers, challenge, updater_proof, - updater_origin_node_id, CCM_COMMITTED); + return validate_updater_proof_state(key, members, proofs, nmembers, challenge, updater_proof, + updater_origin_node_id, CCM_COMMITTED); } @@ -889,7 +842,8 @@ cluster_multixact_current_status_conflicts(uint8 member_status, LockTupleMode wa if (valid_out != NULL) *valid_out = true; - return DoLockModesConflict(held, wanted); + return DoLockModesConflict(held, + wanted); /* GES_MODE_OK: native tuple locks, not GES enqueue. */ } @@ -984,8 +938,8 @@ active_conflict_decision(const ClusterCurrentMxRequestContext *ctx, static ClusterCurrentMxDecision -current_mx_unknown(ClusterCurrentMxDecisionTrace *trace, - ClusterCurrentMxUnknownReason reason, int32 member_ordinal) +current_mx_unknown(ClusterCurrentMxDecisionTrace *trace, ClusterCurrentMxUnknownReason reason, + int32 member_ordinal) { if (trace != NULL) { trace->unknown_reason = reason; @@ -996,13 +950,13 @@ current_mx_unknown(ClusterCurrentMxDecisionTrace *trace, ClusterCurrentMxDecision -cluster_multixact_current_decide_observed( - const ClusterCurrentMxMemberDesc *members, - const ClusterCurrentMemberProof *proofs, uint16 nmembers, - const ClusterCurrentMxRequestContext *ctx, - const ClusterCurrentUpdaterChallenge *challenge, - const ClusterCurrentUpdaterProof *updater_proof, - ClusterTTStatusKey *wait_key, ClusterCurrentMxDecisionTrace *trace) +cluster_multixact_current_decide_observed(const ClusterCurrentMxMemberDesc *members, + const ClusterCurrentMemberProof *proofs, uint16 nmembers, + const ClusterCurrentMxRequestContext *ctx, + const ClusterCurrentUpdaterChallenge *challenge, + const ClusterCurrentUpdaterProof *updater_proof, + ClusterTTStatusKey *wait_key, + ClusterCurrentMxDecisionTrace *trace) { ClusterTTStatusKey selected_wait_key; ClusterCurrentMxDecision self_result = CMDL_CONTINUE; @@ -1025,8 +979,7 @@ cluster_multixact_current_decide_observed( return current_mx_unknown(trace, CMX_UNKNOWN_REQUEST_CONTEXT, -1); if (!descriptor_entries_valid(members, nmembers)) return current_mx_unknown(trace, CMX_UNKNOWN_DESCRIPTOR, -1); - if (!descriptor_shape_matches(members, nmembers, - (ClusterCurrentTupleShape)ctx->tuple_shape)) + if (!descriptor_shape_matches(members, nmembers, (ClusterCurrentTupleShape)ctx->tuple_shape)) return current_mx_unknown(trace, CMX_UNKNOWN_TUPLE_SHAPE, -1); if (proofs == NULL) return current_mx_unknown(trace, CMX_UNKNOWN_PROOFS_NULL, -1); @@ -1053,22 +1006,19 @@ cluster_multixact_current_decide_observed( self_result = ctx->tuple_cmax >= ctx->curcid ? CMDL_SELF_MODIFIED : CMDL_INVISIBLE; break; - case CCM_ACTIVE: - { + case CCM_ACTIVE: { ClusterTTStatusKey candidate_wait_key; uint32 segment_generation; uint16 slot_wrap; if (ISUPDATE_from_mxstatus(members[i].member_status)) active_updater = i; - if (!ClusterCurrentMemberProofGetStatusKey( - &proofs[i], &candidate_wait_key, - &segment_generation, &slot_wrap)) + if (!ClusterCurrentMemberProofGetStatusKey(&proofs[i], &candidate_wait_key, + &segment_generation, &slot_wrap)) return current_mx_unknown(trace, CMX_UNKNOWN_PROOF_ENTRY, i); if (conflicts && (!have_active_conflict - || wait_key_precedes(&candidate_wait_key, - &selected_wait_key))) { + || wait_key_precedes(&candidate_wait_key, &selected_wait_key))) { selected_wait_key = candidate_wait_key; have_active_conflict = true; } @@ -1102,8 +1052,7 @@ cluster_multixact_current_decide_observed( } if (have_unknown) - return current_mx_unknown(trace, CMX_UNKNOWN_MEMBER_STATE, - unknown_ordinal); + return current_mx_unknown(trace, CMX_UNKNOWN_MEMBER_STATE, unknown_ordinal); if (ctx->precheck_result == TM_Invisible) return CMDL_INVISIBLE; @@ -1117,13 +1066,13 @@ cluster_multixact_current_decide_observed( if (ctx->tuple_shape == CCM_SHAPE_DELETED) return CMDL_DELETED; if (ctx->tuple_shape != CCM_SHAPE_UPDATED) - return current_mx_unknown(trace, - CMX_UNKNOWN_COMMITTED_UPDATER_SHAPE, committed_updater); - if (!cluster_multixact_current_validate_updater_proof( - &ctx->mxkey, members, proofs, nmembers, challenge, updater_proof, - (uint16)ctx->updater_origin_node_id)) - return current_mx_unknown(trace, - CMX_UNKNOWN_COMMITTED_UPDATER_PROOF, committed_updater); + return current_mx_unknown(trace, CMX_UNKNOWN_COMMITTED_UPDATER_SHAPE, + committed_updater); + if (!cluster_multixact_current_validate_updater_proof(&ctx->mxkey, members, proofs, + nmembers, challenge, updater_proof, + (uint16)ctx->updater_origin_node_id)) + return current_mx_unknown(trace, CMX_UNKNOWN_COMMITTED_UPDATER_PROOF, + committed_updater); return CMDL_UPDATED; } @@ -1135,16 +1084,14 @@ cluster_multixact_current_decide_observed( * usable only after the same full-key proof required for a committed * updater. */ - if (active_updater >= 0 && !have_active_conflict - && ctx->action == CCM_ACTION_LOCK && ctx->follow_updates) { + if (active_updater >= 0 && !have_active_conflict && ctx->action == CCM_ACTION_LOCK + && ctx->follow_updates) { if (ctx->tuple_shape != CCM_SHAPE_UPDATED) - return current_mx_unknown(trace, - CMX_UNKNOWN_ACTIVE_UPDATER_SHAPE, active_updater); - if (!validate_updater_proof_state( - &ctx->mxkey, members, proofs, nmembers, challenge, updater_proof, - (uint16)ctx->updater_origin_node_id, CCM_ACTIVE)) - return current_mx_unknown(trace, - CMX_UNKNOWN_ACTIVE_UPDATER_PROOF, active_updater); + return current_mx_unknown(trace, CMX_UNKNOWN_ACTIVE_UPDATER_SHAPE, active_updater); + if (!validate_updater_proof_state(&ctx->mxkey, members, proofs, nmembers, challenge, + updater_proof, (uint16)ctx->updater_origin_node_id, + CCM_ACTIVE)) + return current_mx_unknown(trace, CMX_UNKNOWN_ACTIVE_UPDATER_PROOF, active_updater); return CMDL_FOLLOW_UPDATED; } @@ -1163,8 +1110,8 @@ cluster_multixact_current_decide(const ClusterCurrentMxMemberDesc *members, const ClusterCurrentUpdaterProof *updater_proof, ClusterTTStatusKey *wait_key) { - return cluster_multixact_current_decide_observed( - members, proofs, nmembers, ctx, challenge, updater_proof, wait_key, NULL); + return cluster_multixact_current_decide_observed(members, proofs, nmembers, ctx, challenge, + updater_proof, wait_key, NULL); } @@ -1192,8 +1139,7 @@ cluster_multixact_current_describe(const ClusterCurrentMxKey *key, return CMX_DESC_UNKNOWN; current_epoch = cluster_epoch_get_current(); - if (current_epoch > UINT32_MAX - || key->cluster_epoch != (uint32)current_epoch) + if (current_epoch > UINT32_MAX || key->cluster_epoch != (uint32)current_epoch) return CMX_DESC_UNKNOWN; origin_slot = cluster_mxid_origin_slot(key->multixact_id); @@ -1203,14 +1149,13 @@ cluster_multixact_current_describe(const ClusterCurrentMxKey *key, cluster_multixact_current_stats_bump(CMX_STAT_DESCRIBE_REMOTE_ASK); PG_TRY(); { - result = cluster_gcs_current_mx_describe_fetch_and_wait( - (int32)key->origin_node_id, key, members, members_cap, - nmembers, reported_total_members); + result = cluster_gcs_current_mx_describe_fetch_and_wait((int32)key->origin_node_id, key, + members, members_cap, nmembers, + reported_total_members); } PG_CATCH(); { - cluster_multixact_current_stats_bump( - CMX_STAT_DESCRIBE_REMOTE_UNKNOWN); + cluster_multixact_current_stats_bump(CMX_STAT_DESCRIBE_REMOTE_UNKNOWN); PG_RE_THROW(); } PG_END_TRY(); @@ -1222,8 +1167,7 @@ cluster_multixact_current_describe(const ClusterCurrentMxKey *key, cluster_multixact_current_stats_bump(CMX_STAT_DESCRIBE_REMOTE_DENIED); break; case CMX_DESC_SUPPORTED_LIMIT: - cluster_multixact_current_stats_bump( - CMX_STAT_DESCRIBE_REMOTE_SUPPORTED_LIMIT); + cluster_multixact_current_stats_bump(CMX_STAT_DESCRIBE_REMOTE_SUPPORTED_LIMIT); break; case CMX_DESC_TIMEOUT: cluster_multixact_current_stats_bump(CMX_STAT_DESCRIBE_REMOTE_TIMEOUT); @@ -1250,8 +1194,8 @@ cluster_multixact_current_describe(const ClusterCurrentMxKey *key, members[i].member_status = (uint8)native_members[i].status; } result = cluster_multixact_current_validate_descriptor( - key, (uint16)cluster_node_id, (uint32)current_epoch, members, - (uint16)native_count, (uint32)native_count); + key, (uint16)cluster_node_id, (uint32)current_epoch, members, (uint16)native_count, + (uint32)native_count); if (result == CMX_DESC_OK) { *nmembers = (uint16)native_count; *reported_total_members = (uint32)native_count; @@ -1271,14 +1215,10 @@ cluster_multixact_current_describe(const ClusterCurrentMxKey *key, static ClusterMxResolveResult cluster_multixact_current_members_resolve_internal( - const ClusterCurrentMxKey *key, - const ClusterCurrentMxMemberDesc *members, - uint16 nmembers, uint64 descriptor_hash, - const ClusterCurrentUpdaterChallenge *challenge, - ClusterCurrentMemberProof *proofs, - ClusterCurrentUpdaterProof *updater_proof, - uint32 *proof_capability_generations, - TimestampTz *operation_deadline_io) + const ClusterCurrentMxKey *key, const ClusterCurrentMxMemberDesc *members, uint16 nmembers, + uint64 descriptor_hash, const ClusterCurrentUpdaterChallenge *challenge, + ClusterCurrentMemberProof *proofs, ClusterCurrentUpdaterProof *updater_proof, + uint32 *proof_capability_generations, TimestampTz *operation_deadline_io) { ClusterCurrentMxProofRequestPlan plans[CLUSTER_CURRENT_MX_MAX_CHUNKS]; uint16 member_origins[CLUSTER_CURRENT_MX_MAX_MEMBERS]; @@ -1302,30 +1242,24 @@ cluster_multixact_current_members_resolve_internal( return CMX_RESOLVE_SUPPORTED_LIMIT; proof_array_set_unknown(proofs, nmembers); if (proof_capability_generations != NULL) - memset(proof_capability_generations, 0, - sizeof(*proof_capability_generations) * nmembers); + memset(proof_capability_generations, 0, sizeof(*proof_capability_generations) * nmembers); if (key == NULL || members == NULL || proofs == NULL || updater_proof == NULL - || proof_capability_generations == NULL - || nmembers < 1 || cluster_node_id < 0 || cluster_node_id >= CLUSTER_MAX_NODES) + || proof_capability_generations == NULL || nmembers < 1 || cluster_node_id < 0 + || cluster_node_id >= CLUSTER_MAX_NODES) return CMX_RESOLVE_UNKNOWN; current_epoch = cluster_epoch_get_current(); - operation_deadline = operation_deadline_io != NULL - ? *operation_deadline_io : 0; - if (operation_deadline == 0 && cluster_gcs_reply_timeout_ms > 0) - { - operation_deadline = TimestampTzPlusMilliseconds( - GetCurrentTimestamp(), cluster_gcs_reply_timeout_ms); + operation_deadline = operation_deadline_io != NULL ? *operation_deadline_io : 0; + if (operation_deadline == 0 && cluster_gcs_reply_timeout_ms > 0) { + operation_deadline + = TimestampTzPlusMilliseconds(GetCurrentTimestamp(), cluster_gcs_reply_timeout_ms); if (operation_deadline_io != NULL) *operation_deadline_io = operation_deadline; } - if (operation_deadline != 0 - && GetCurrentTimestamp() >= operation_deadline) + if (operation_deadline != 0 && GetCurrentTimestamp() >= operation_deadline) return CMX_RESOLVE_TIMEOUT; - if (current_epoch > UINT32_MAX - || key->cluster_epoch != (uint32)current_epoch - || descriptor_hash - != cluster_multixact_current_descriptor_hash(key, members, nmembers)) + if (current_epoch > UINT32_MAX || key->cluster_epoch != (uint32)current_epoch + || descriptor_hash != cluster_multixact_current_descriptor_hash(key, members, nmembers)) return CMX_RESOLVE_UNKNOWN; for (i = 0; i < nmembers; i++) { int origin = cluster_xid_origin_slot(members[i].xid); @@ -1342,40 +1276,33 @@ cluster_multixact_current_members_resolve_internal( return result; memset(seen, 0, sizeof(seen)); - memset(source_capability_generations, 0, - sizeof(source_capability_generations)); + memset(source_capability_generations, 0, sizeof(source_capability_generations)); memset(local_ctrc_keys, 0, sizeof(local_ctrc_keys)); memset(local_ctrc_grants, 0, sizeof(local_ctrc_grants)); - memset(local_ctrc_capability_generations, 0, - sizeof(local_ctrc_capability_generations)); + memset(local_ctrc_capability_generations, 0, sizeof(local_ctrc_capability_generations)); for (i = 0; i < plan_count; i++) { ClusterCurrentMemberProof chunk_proofs[CLUSTER_CURRENT_MX_MAX_PROOF_ASKS_PER_FRAME]; ClusterCurrentUpdaterProof chunk_updater; ClusterCurrentMxProofForwardV2 *request = &plans[i].request; uint16 chunk_count = 0; uint32 chunk_capability_generation = 0; - uint32 chunk_member_capability_generations[ - CLUSTER_CURRENT_MX_MAX_PROOF_ASKS_PER_FRAME]; + uint32 chunk_member_capability_generations[CLUSTER_CURRENT_MX_MAX_PROOF_ASKS_PER_FRAME]; uint16 j; - if (operation_deadline != 0 - && GetCurrentTimestamp() >= operation_deadline) - { + if (operation_deadline != 0 && GetCurrentTimestamp() >= operation_deadline) { result = CMX_RESOLVE_TIMEOUT; goto non_ok; } memset(chunk_proofs, 0, sizeof(chunk_proofs)); - memset(chunk_member_capability_generations, 0, - sizeof(chunk_member_capability_generations)); + memset(chunk_member_capability_generations, 0, sizeof(chunk_member_capability_generations)); memset(&chunk_updater, 0, sizeof(chunk_updater)); chunk_updater.verdict = CUCP_UNKNOWN; if (plans[i].destination_node_id == (uint16)cluster_node_id) { if (request->prefix.body_kind == CLUSTER_CURRENT_MX_PROOF_BODY_MEMBER_ASKS) { for (j = 0; j < request->prefix.entry_count; j++) { - const ClusterCurrentMxProofAskWire *ask - = &request->trailer.body.asks[j]; + const ClusterCurrentMxProofAskWire *ask = &request->trailer.body.asks[j]; ClusterTTStatusKey initial_key; ClusterTTStatusResult initial_result; ClusterCtrcTxnKeyV1 ctrc_key; @@ -1383,42 +1310,33 @@ cluster_multixact_current_members_resolve_internal( uint32 participant_capability_generation = 0; if (!current_mx_local_member_sample_exact( - ask->xid, &initial_key, &initial_result, - &ctrc_grant, &participant_capability_generation, - &ctrc_key) + ask->xid, &initial_key, &initial_result, &ctrc_grant, + &participant_capability_generation, &ctrc_key) || !cluster_multixact_current_resolve_origin_member_proof( ask->xid, ask->member_status, ask->member_ordinal, (uint16)cluster_node_id, (uint32)current_epoch, TransactionIdIsCurrentTransactionId(ask->xid), &initial_key, - &initial_result, NULL, NULL, - &chunk_proofs[j])) + &initial_result, NULL, NULL, &chunk_proofs[j])) goto unknown; - if (chunk_proofs[j].state == CCM_ACTIVE - || chunk_proofs[j].state == CCM_SELF) - { + if (chunk_proofs[j].state == CCM_ACTIVE || chunk_proofs[j].state == CCM_SELF) { if (ctrc_grant == 0) goto unknown; - ClusterCurrentMemberProofSetCtrcGrant( - &chunk_proofs[j], ctrc_grant); - if (!cluster_multixact_current_member_proof_bind_ctrc( - &chunk_proofs[j], &ctrc_key)) + ClusterCurrentMemberProofSetCtrcGrant(&chunk_proofs[j], ctrc_grant); + if (!cluster_multixact_current_member_proof_bind_ctrc(&chunk_proofs[j], + &ctrc_key)) goto unknown; if (participant_capability_generation == 0 || (chunk_capability_generation != 0 && chunk_capability_generation - != participant_capability_generation)) + != participant_capability_generation)) goto unknown; - chunk_capability_generation - = participant_capability_generation; - chunk_member_capability_generations[j] - = participant_capability_generation; + chunk_capability_generation = participant_capability_generation; + chunk_member_capability_generations[j] = participant_capability_generation; local_ctrc_keys[ask->member_ordinal] = ctrc_key; local_ctrc_grants[ask->member_ordinal] = ctrc_grant; local_ctrc_capability_generations[ask->member_ordinal] = participant_capability_generation; - } - else if (ctrc_grant != 0 - || participant_capability_generation != 0) + } else if (ctrc_grant != 0 || participant_capability_generation != 0) goto unknown; } chunk_count = request->prefix.entry_count; @@ -1434,51 +1352,38 @@ cluster_multixact_current_members_resolve_internal( bool cross_segment = false; if (!cluster_runtime_visibility_current_mx_updater_provenance_exact( - &wire_challenge->candidate_next_xmin_locator, - operation_deadline, &initial_key, &initial_result, - &ctrc_grant, &participant_capability_generation, - &ctrc_key, &canonical_locator, &cross_segment) + &wire_challenge->candidate_next_xmin_locator, operation_deadline, + &initial_key, &initial_result, &ctrc_grant, + &participant_capability_generation, &ctrc_key, &canonical_locator, + &cross_segment) || !cluster_multixact_current_resolve_origin_member_proof( wire_challenge->updater_xid, wire_challenge->member_status, wire_challenge->member_ordinal, (uint16)cluster_node_id, (uint32)current_epoch, TransactionIdIsCurrentTransactionId(wire_challenge->updater_xid), - &initial_key, &initial_result, NULL, NULL, - &chunk_proofs[0])) + &initial_key, &initial_result, NULL, NULL, &chunk_proofs[0])) goto unknown; - if (chunk_proofs[0].state == CCM_ACTIVE - || chunk_proofs[0].state == CCM_SELF) - { + if (chunk_proofs[0].state == CCM_ACTIVE || chunk_proofs[0].state == CCM_SELF) { if (ctrc_grant == 0) goto unknown; - ClusterCurrentMemberProofSetCtrcGrant( - &chunk_proofs[0], ctrc_grant); - if (!cluster_multixact_current_member_proof_bind_ctrc( - &chunk_proofs[0], &ctrc_key)) + ClusterCurrentMemberProofSetCtrcGrant(&chunk_proofs[0], ctrc_grant); + if (!cluster_multixact_current_member_proof_bind_ctrc(&chunk_proofs[0], + &ctrc_key)) goto unknown; if (participant_capability_generation == 0) goto unknown; - chunk_capability_generation - = participant_capability_generation; - chunk_member_capability_generations[0] + chunk_capability_generation = participant_capability_generation; + chunk_member_capability_generations[0] = participant_capability_generation; + local_ctrc_keys[wire_challenge->member_ordinal] = ctrc_key; + local_ctrc_grants[wire_challenge->member_ordinal] = ctrc_grant; + local_ctrc_capability_generations[wire_challenge->member_ordinal] = participant_capability_generation; - local_ctrc_keys[wire_challenge->member_ordinal] - = ctrc_key; - local_ctrc_grants[wire_challenge->member_ordinal] - = ctrc_grant; - local_ctrc_capability_generations[ - wire_challenge->member_ordinal] - = participant_capability_generation; - } - else if (ctrc_grant != 0 - || participant_capability_generation != 0) + } else if (ctrc_grant != 0 || participant_capability_generation != 0) goto unknown; chunk_count = 1; chunk_updater.mxkey = request->prefix.mxkey; - chunk_updater.candidate_next_xmin_alias - = wire_challenge->candidate_next_xmin_alias; - chunk_updater.candidate_next_xmin_locator - = canonical_locator; + chunk_updater.candidate_next_xmin_alias = wire_challenge->candidate_next_xmin_alias; + chunk_updater.candidate_next_xmin_locator = canonical_locator; chunk_updater.updater_xid = wire_challenge->updater_xid; chunk_updater.member_ordinal = wire_challenge->member_ordinal; chunk_updater.verdict = CUCP_MATCH; @@ -1491,14 +1396,12 @@ cluster_multixact_current_members_resolve_internal( PG_TRY(); { result = cluster_gcs_current_mx_member_proof_fetch_and_wait( - plans[i].destination_node_id, request, chunk_proofs, - lengthof(chunk_proofs), &chunk_count, &chunk_updater, - &chunk_capability_generation, operation_deadline); + plans[i].destination_node_id, request, chunk_proofs, lengthof(chunk_proofs), + &chunk_count, &chunk_updater, &chunk_capability_generation, operation_deadline); } PG_CATCH(); { - cluster_multixact_current_stats_bump( - CMX_STAT_MEMBER_PROOF_UNKNOWN); + cluster_multixact_current_stats_bump(CMX_STAT_MEMBER_PROOF_UNKNOWN); PG_RE_THROW(); } PG_END_TRY(); @@ -1510,8 +1413,7 @@ cluster_multixact_current_members_resolve_internal( cluster_multixact_current_stats_bump(CMX_STAT_MEMBER_PROOF_DENIED); break; case CMX_RESOLVE_SUPPORTED_LIMIT: - cluster_multixact_current_stats_bump( - CMX_STAT_MEMBER_PROOF_SUPPORTED_LIMIT); + cluster_multixact_current_stats_bump(CMX_STAT_MEMBER_PROOF_SUPPORTED_LIMIT); break; case CMX_RESOLVE_TIMEOUT: cluster_multixact_current_stats_bump(CMX_STAT_MEMBER_PROOF_TIMEOUT); @@ -1530,22 +1432,18 @@ cluster_multixact_current_members_resolve_internal( if (chunk_count != request->prefix.entry_count) goto unknown; - for (j = 0; j < chunk_count; j++) - { - if (chunk_proofs[j].state != CCM_ACTIVE - && chunk_proofs[j].state != CCM_SELF) + for (j = 0; j < chunk_count; j++) { + if (chunk_proofs[j].state != CCM_ACTIVE && chunk_proofs[j].state != CCM_SELF) continue; if (chunk_capability_generation == 0) goto unknown; if (plans[i].destination_node_id != (uint16)cluster_node_id) - chunk_member_capability_generations[j] - = chunk_capability_generation; + chunk_member_capability_generations[j] = chunk_capability_generation; } - if (chunk_capability_generation != 0) - { + if (chunk_capability_generation != 0) { if (source_capability_generations[plans[i].destination_node_id] != 0 && source_capability_generations[plans[i].destination_node_id] - != chunk_capability_generation) + != chunk_capability_generation) goto unknown; source_capability_generations[plans[i].destination_node_id] = chunk_capability_generation; @@ -1555,15 +1453,13 @@ cluster_multixact_current_members_resolve_internal( if (ordinal >= nmembers || seen[ordinal] || member_origins[ordinal] != plans[i].destination_node_id - || !proof_entry_semantic_valid( - &chunk_proofs[j], &members[ordinal], ordinal, (uint32)current_epoch, - plans[i].destination_node_id) + || !proof_entry_semantic_valid(&chunk_proofs[j], &members[ordinal], ordinal, + (uint32)current_epoch, plans[i].destination_node_id) || chunk_proofs[j].state == CCM_UNKNOWN) goto unknown; seen[ordinal] = true; proofs[ordinal] = chunk_proofs[j]; - proof_capability_generations[ordinal] - = chunk_member_capability_generations[j]; + proof_capability_generations[ordinal] = chunk_member_capability_generations[j]; } if (request->prefix.body_kind == CLUSTER_CURRENT_MX_PROOF_BODY_UPDATER_CHALLENGE) { @@ -1575,11 +1471,9 @@ cluster_multixact_current_members_resolve_internal( &wire_challenge->candidate_next_xmin_alias, sizeof(ClusterCurrentMxSuccessorAlias)) != 0 - || chunk_updater.candidate_next_xmin_locator.tt_wrap - > TT_WRAP_MAX - || !cluster_tx_locator_reply_matches( - &wire_challenge->candidate_next_xmin_locator, - &chunk_updater.candidate_next_xmin_locator) + || chunk_updater.candidate_next_xmin_locator.tt_wrap > TT_WRAP_MAX + || !cluster_tx_locator_reply_matches(&wire_challenge->candidate_next_xmin_locator, + &chunk_updater.candidate_next_xmin_locator) || chunk_updater.updater_xid != wire_challenge->updater_xid || chunk_updater.member_ordinal != wire_challenge->member_ordinal || chunk_updater.verdict > CUCP_UNKNOWN || chunk_updater.reserved8 != 0 @@ -1594,31 +1488,23 @@ cluster_multixact_current_members_resolve_internal( for (i = 0; i < nmembers; i++) if (!seen[i]) goto unknown; - if (operation_deadline != 0 - && GetCurrentTimestamp() >= operation_deadline) - { + if (operation_deadline != 0 && GetCurrentTimestamp() >= operation_deadline) { result = CMX_RESOLVE_TIMEOUT; goto non_ok; } - for (i = 0; i < nmembers; i++) - { + for (i = 0; i < nmembers; i++) { if (local_ctrc_grants[i] == 0) continue; memset(&local_participant, 0, sizeof(local_participant)); - local_participant.node_id = (uint16) cluster_node_id; - local_participant.capability_record_generation - = local_ctrc_capability_generations[i]; - local_participant.boot_incarnation - = local_ctrc_keys[i].origin_boot_incarnation; - local_participant.formation_epoch - = local_ctrc_keys[i].formation_epoch; + local_participant.node_id = (uint16)cluster_node_id; + local_participant.capability_record_generation = local_ctrc_capability_generations[i]; + local_participant.boot_incarnation = local_ctrc_keys[i].origin_boot_incarnation; + local_participant.formation_epoch = local_ctrc_keys[i].formation_epoch; local_participant.admission_record_generation = local_ctrc_keys[i].admission_record_generation; if (local_participant.capability_record_generation == 0 - || !cluster_ctrc_origin_grant_publishable( - &local_ctrc_keys[i], &local_participant, - local_ctrc_grants[i])) - { + || !cluster_ctrc_origin_grant_publishable(&local_ctrc_keys[i], &local_participant, + local_ctrc_grants[i])) { result = CMX_RESOLVE_RETRY; goto non_ok; } @@ -1627,16 +1513,14 @@ cluster_multixact_current_members_resolve_internal( non_ok: proof_array_set_unknown(proofs, nmembers); - memset(proof_capability_generations, 0, - sizeof(*proof_capability_generations) * nmembers); + memset(proof_capability_generations, 0, sizeof(*proof_capability_generations) * nmembers); memset(updater_proof, 0, sizeof(*updater_proof)); updater_proof->verdict = CUCP_UNKNOWN; return result; unknown: proof_array_set_unknown(proofs, nmembers); - memset(proof_capability_generations, 0, - sizeof(*proof_capability_generations) * nmembers); + memset(proof_capability_generations, 0, sizeof(*proof_capability_generations) * nmembers); memset(updater_proof, 0, sizeof(*updater_proof)); updater_proof->verdict = CUCP_UNKNOWN; return CMX_RESOLVE_UNKNOWN; @@ -1644,35 +1528,30 @@ cluster_multixact_current_members_resolve_internal( ClusterMxResolveResult -cluster_multixact_current_members_resolve( - const ClusterCurrentMxKey *key, - const ClusterCurrentMxMemberDesc *members, - uint16 nmembers, uint64 descriptor_hash, - const ClusterCurrentUpdaterChallenge *challenge, - ClusterCurrentMemberProof *proofs, - ClusterCurrentUpdaterProof *updater_proof, - uint32 *proof_capability_generations) +cluster_multixact_current_members_resolve(const ClusterCurrentMxKey *key, + const ClusterCurrentMxMemberDesc *members, + uint16 nmembers, uint64 descriptor_hash, + const ClusterCurrentUpdaterChallenge *challenge, + ClusterCurrentMemberProof *proofs, + ClusterCurrentUpdaterProof *updater_proof, + uint32 *proof_capability_generations) { return cluster_multixact_current_members_resolve_internal( - key, members, nmembers, descriptor_hash, challenge, proofs, - updater_proof, proof_capability_generations, NULL); + key, members, nmembers, descriptor_hash, challenge, proofs, updater_proof, + proof_capability_generations, NULL); } ClusterMxResolveResult cluster_multixact_current_members_resolve_until( - const ClusterCurrentMxKey *key, - const ClusterCurrentMxMemberDesc *members, - uint16 nmembers, uint64 descriptor_hash, - const ClusterCurrentUpdaterChallenge *challenge, - ClusterCurrentMemberProof *proofs, - ClusterCurrentUpdaterProof *updater_proof, - uint32 *proof_capability_generations, - TimestampTz *operation_deadline) + const ClusterCurrentMxKey *key, const ClusterCurrentMxMemberDesc *members, uint16 nmembers, + uint64 descriptor_hash, const ClusterCurrentUpdaterChallenge *challenge, + ClusterCurrentMemberProof *proofs, ClusterCurrentUpdaterProof *updater_proof, + uint32 *proof_capability_generations, TimestampTz *operation_deadline) { return cluster_multixact_current_members_resolve_internal( - key, members, nmembers, descriptor_hash, challenge, proofs, - updater_proof, proof_capability_generations, operation_deadline); + key, members, nmembers, descriptor_hash, challenge, proofs, updater_proof, + proof_capability_generations, operation_deadline); } @@ -1715,17 +1594,15 @@ cluster_multixact_current_recompose(const ClusterCurrentMxMemberDesc *members, switch ((ClusterCurrentMemberState)proof->state) { case CCM_SELF: case CCM_ACTIVE: - if (ClusterCurrentMemberProofGetCtrcGrant(proof) == 0 - || proof->commit_scn != InvalidScn - || !proof_key_valid_holder(proof, proof->member_xid, - proof->key.cluster_epoch, - proof->key.origin_node_id)) + if (ClusterCurrentMemberProofGetCtrcGrant(proof) == 0 || proof->commit_scn != InvalidScn + || !proof_key_valid_holder(proof, proof->member_xid, proof->key.cluster_epoch, + proof->key.origin_node_id)) return CMX_RECOMPOSE_UNKNOWN; keep = true; break; case CCM_COMMITTED: - if (ClusterCurrentMemberProofGetCtrcGrant(proof) != 0 - || !proof_key_is_zero(&proof->key) || !SCN_VALID(proof->commit_scn)) + if (ClusterCurrentMemberProofGetCtrcGrant(proof) != 0 || !proof_key_is_zero(&proof->key) + || !SCN_VALID(proof->commit_scn)) return CMX_RECOMPOSE_UNKNOWN; /* * A committed updater changes the tuple version and must have @@ -1736,8 +1613,8 @@ cluster_multixact_current_recompose(const ClusterCurrentMxMemberDesc *members, return CMX_RECOMPOSE_DENIED; break; case CCM_ABORTED: - if (ClusterCurrentMemberProofGetCtrcGrant(proof) != 0 - || !proof_key_is_zero(&proof->key) || proof->commit_scn != InvalidScn) + if (ClusterCurrentMemberProofGetCtrcGrant(proof) != 0 || !proof_key_is_zero(&proof->key) + || proof->commit_scn != InvalidScn) return CMX_RECOMPOSE_UNKNOWN; break; case CCM_UNKNOWN: @@ -1805,8 +1682,7 @@ cluster_multixact_current_recompose(const ClusterCurrentMxMemberDesc *members, } new_strength = Max(old_strength, new_strength); - updater = ISUPDATE_from_mxstatus(old_status) - || ISUPDATE_from_mxstatus(requester_status); + updater = ISUPDATE_from_mxstatus(old_status) || ISUPDATE_from_mxstatus(requester_status); if (updater) scratch[requester_index].status = new_strength == 3 ? MultiXactStatusUpdate : MultiXactStatusNoKeyUpdate; diff --git a/src/backend/cluster/cluster_multixact_current_stats.c b/src/backend/cluster/cluster_multixact_current_stats.c index add0836b0cd..64cc5bdc88f 100644 --- a/src/backend/cluster/cluster_multixact_current_stats.c +++ b/src/backend/cluster/cluster_multixact_current_stats.c @@ -50,13 +50,14 @@ void cluster_multixact_current_stats_shmem_init(void) { bool found; - int i; if (IsBootstrapProcessingMode() || !cluster_enabled || cluster_node_id < 0) return; ClusterCurrentMxStats = ShmemInitStruct("pgrac current multixact stats", - sizeof(ClusterCurrentMxStatsShmem), &found); + sizeof(ClusterCurrentMxStatsShmem), &found); if (!found) { + int i; + ClusterCurrentMxStats->stats_since = GetCurrentTimestamp(); for (i = 0; i < CMX_STAT_COUNT; i++) pg_atomic_init_u64(&ClusterCurrentMxStats->counters[i], 0); @@ -102,9 +103,8 @@ cluster_multixact_current_stats_since(void) } bool -cluster_multixact_current_stats_snapshot( - uint32 node_id, uint64 cluster_epoch, - ClusterCurrentMxStatsSnapshot *snapshot) +cluster_multixact_current_stats_snapshot(uint32 node_id, uint64 cluster_epoch, + ClusterCurrentMxStatsSnapshot *snapshot) { int i; @@ -115,8 +115,7 @@ cluster_multixact_current_stats_snapshot( snapshot->cluster_epoch = cluster_epoch; snapshot->stats_since = ClusterCurrentMxStats->stats_since; for (i = 0; i < CMX_STAT_COUNT; i++) - snapshot->counters[i] - = pg_atomic_read_u64(&ClusterCurrentMxStats->counters[i]); + snapshot->counters[i] = pg_atomic_read_u64(&ClusterCurrentMxStats->counters[i]); return snapshot->stats_since != 0; } @@ -142,30 +141,23 @@ cluster_multixact_current_stats_record_restarts(uint32 restarts) if (ClusterCurrentMxStats == NULL) return; - cluster_multixact_current_stats_bump( - cluster_multixact_current_restart_bucket(restarts)); + cluster_multixact_current_stats_bump(cluster_multixact_current_restart_bucket(restarts)); - expected = pg_atomic_read_u64( - &ClusterCurrentMxStats->counters[CMX_STAT_RESTART_MAX]); - while (expected < restarts && - !pg_atomic_compare_exchange_u64( - &ClusterCurrentMxStats->counters[CMX_STAT_RESTART_MAX], - &expected, restarts)) + expected = pg_atomic_read_u64(&ClusterCurrentMxStats->counters[CMX_STAT_RESTART_MAX]); + while (expected < restarts + && !pg_atomic_compare_exchange_u64( + &ClusterCurrentMxStats->counters[CMX_STAT_RESTART_MAX], &expected, restarts)) ; } void cluster_multixact_current_stats_alert_sample(void) { - static const ClusterCurrentMxStatId alert_stats[] = { - CMX_STAT_DESCRIBE_REMOTE_TIMEOUT, - CMX_STAT_DESCRIBE_REMOTE_UNKNOWN, - CMX_STAT_MEMBER_PROOF_UNKNOWN, - CMX_STAT_DESCRIBE_INVALID_REPLY, - CMX_STAT_MEMBER_PROOF_INVALID_REPLY, - CMX_STAT_RESTART_BUCKET_8_PLUS, - CMX_STAT_FOREIGN_SLRU_GUARD - }; + static const ClusterCurrentMxStatId alert_stats[] + = { CMX_STAT_DESCRIBE_REMOTE_TIMEOUT, CMX_STAT_DESCRIBE_REMOTE_UNKNOWN, + CMX_STAT_MEMBER_PROOF_UNKNOWN, CMX_STAT_DESCRIBE_INVALID_REPLY, + CMX_STAT_MEMBER_PROOF_INVALID_REPLY, CMX_STAT_RESTART_BUCKET_8_PLUS, + CMX_STAT_FOREIGN_SLRU_GUARD }; static uint64 previous[lengthof(alert_stats)]; static TimestampTz last_sample; TimestampTz now; @@ -177,17 +169,13 @@ cluster_multixact_current_stats_alert_sample(void) return; now = GetCurrentTimestamp(); - if (last_sample != 0 - && now >= last_sample - && now - last_sample < INT64CONST(60000000)) + if (last_sample != 0 && now >= last_sample && now - last_sample < INT64CONST(60000000)) return; for (i = 0; i < lengthof(alert_stats); i++) { uint64 current = cluster_multixact_current_stats_get(alert_stats[i]); - deltas[i] = current >= previous[i] - ? current - previous[i] - : current; + deltas[i] = current >= previous[i] ? current - previous[i] : current; previous[i] = current; changed |= deltas[i] != 0; } diff --git a/src/backend/cluster/cluster_multixact_current_wire.c b/src/backend/cluster/cluster_multixact_current_wire.c index 5f37611fb12..d9bdd7432e0 100644 --- a/src/backend/cluster/cluster_multixact_current_wire.c +++ b/src/backend/cluster/cluster_multixact_current_wire.c @@ -47,9 +47,8 @@ wire_epoch_valid(uint64 current_epoch) static bool wire_mxkey_valid(const ClusterCurrentMxKey *key, uint64 current_epoch) { - return key != NULL && wire_epoch_valid(current_epoch) - && key->origin_node_id < CLUSTER_MAX_NODES && key->reserved16 == 0 - && key->reserved32 == 0 && MultiXactIdIsValid(key->multixact_id) + return key != NULL && wire_epoch_valid(current_epoch) && key->origin_node_id < CLUSTER_MAX_NODES + && key->reserved16 == 0 && key->reserved32 == 0 && MultiXactIdIsValid(key->multixact_id) && key->cluster_epoch == (uint32)current_epoch; } @@ -66,18 +65,16 @@ wire_tt_key_valid(const ClusterTTStatusKey *key, uint64 current_epoch, int32 exp TransactionId expected_xid) { return key != NULL && wire_epoch_valid(current_epoch) && expected_origin >= 0 - && expected_origin < CLUSTER_MAX_NODES - && key->origin_node_id == (uint16)expected_origin && key->undo_segment_id != 0 - && key->tt_slot_id != 0 && key->cluster_epoch == (uint32)current_epoch - && TransactionIdIsNormal(key->local_xid) + && expected_origin < CLUSTER_MAX_NODES && key->origin_node_id == (uint16)expected_origin + && key->undo_segment_id != 0 && key->tt_slot_id != 0 + && key->cluster_epoch == (uint32)current_epoch && TransactionIdIsNormal(key->local_xid) && (!TransactionIdIsValid(expected_xid) || key->local_xid == expected_xid) && key->_reserved == 0 && key->_reserved2 == 0; } static bool -wire_proof_ask_valid(const ClusterCurrentMxProofAskWire *ask, uint32 total_count, - int32 local_node) +wire_proof_ask_valid(const ClusterCurrentMxProofAskWire *ask, uint32 total_count, int32 local_node) { return ask != NULL && TransactionIdIsNormal(ask->xid) && ask->member_ordinal < total_count && ask->member_status <= MaxMultiXactStatus && ask->reserved8 == 0 @@ -86,9 +83,10 @@ wire_proof_ask_valid(const ClusterCurrentMxProofAskWire *ask, uint32 total_count bool -cluster_multixact_current_wire_validate_describe_forward( - const void *payload, uint32 payload_length, int32 envelope_source, int32 local_node, - uint64 current_epoch, ClusterCurrentMxDescribeForwardV2 *decoded) +cluster_multixact_current_wire_validate_describe_forward(const void *payload, uint32 payload_length, + int32 envelope_source, int32 local_node, + uint64 current_epoch, + ClusterCurrentMxDescribeForwardV2 *decoded) { ClusterCurrentMxDescribeForwardV2 message; bool valid; @@ -122,9 +120,10 @@ cluster_multixact_current_wire_validate_describe_forward( bool -cluster_multixact_current_wire_validate_proof_forward( - const void *payload, uint32 payload_length, int32 envelope_source, int32 local_node, - uint64 current_epoch, ClusterCurrentMxProofForwardV2 *decoded) +cluster_multixact_current_wire_validate_proof_forward(const void *payload, uint32 payload_length, + int32 envelope_source, int32 local_node, + uint64 current_epoch, + ClusterCurrentMxProofForwardV2 *decoded) { ClusterCurrentMxProofForwardV2 message; uint16 semantic_chunk_count; @@ -143,8 +142,7 @@ cluster_multixact_current_wire_validate_proof_forward( || message.prefix.original_requester_node != envelope_source || message.prefix.requester_backend_id <= 0 || message.prefix.kind != GCS_BLOCK_FORWARD_KIND_CURRENT_MX_MEMBER_PROOF - || !wire_mxkey_valid(&message.prefix.mxkey, current_epoch) - || message.prefix.total_count < 1 + || !wire_mxkey_valid(&message.prefix.mxkey, current_epoch) || message.prefix.total_count < 1 || message.prefix.total_count > CLUSTER_CURRENT_MX_MAX_MEMBERS || semantic_chunk_count > message.prefix.total_count || semantic_chunk_count > CLUSTER_CURRENT_MX_MAX_CHUNKS @@ -165,20 +163,19 @@ cluster_multixact_current_wire_validate_proof_forward( for (i = 0; i < message.prefix.entry_count; i++) { uint8 j; - if (!wire_proof_ask_valid(&message.trailer.body.asks[i], - message.prefix.total_count, local_node)) + if (!wire_proof_ask_valid(&message.trailer.body.asks[i], message.prefix.total_count, + local_node)) return false; for (j = 0; j < i; j++) if (message.trailer.body.asks[j].member_ordinal == message.trailer.body.asks[i].member_ordinal - || message.trailer.body.asks[j].xid - == message.trailer.body.asks[i].xid) + || message.trailer.body.asks[j].xid == message.trailer.body.asks[i].xid) return false; } if (!bytes_are_zero(&message.trailer.body.asks[message.prefix.entry_count], - sizeof(message.trailer.body) - - message.prefix.entry_count - * sizeof(ClusterCurrentMxProofAskWire))) + sizeof(message.trailer.body) + - message.prefix.entry_count + * sizeof(ClusterCurrentMxProofAskWire))) return false; break; @@ -192,10 +189,8 @@ cluster_multixact_current_wire_validate_proof_forward( || !ISUPDATE_from_mxstatus(challenge->member_status) || challenge->reserved8 != 0 || cluster_xid_origin_slot(challenge->updater_xid) != local_node || !cluster_multixact_current_successor_provenance_well_formed( - &challenge->candidate_next_xmin_alias, - &challenge->candidate_next_xmin_locator, - challenge->updater_xid, (uint16)local_node, - (uint32)current_epoch)) + &challenge->candidate_next_xmin_alias, &challenge->candidate_next_xmin_locator, + challenge->updater_xid, (uint16)local_node, (uint32)current_epoch)) return false; break; } @@ -211,9 +206,9 @@ cluster_multixact_current_wire_validate_proof_forward( static void wire_init_proof_request(ClusterCurrentMxProofRequestPlan *plan, uint16 destination_node_id, - const ClusterCurrentMxKey *key, uint64 descriptor_hash, - uint32 total_count, uint64 request_id, uint64 current_epoch, - int32 requester_node, int32 requester_backend_id, uint8 body_kind) + const ClusterCurrentMxKey *key, uint64 descriptor_hash, uint32 total_count, + uint64 request_id, uint64 current_epoch, int32 requester_node, + int32 requester_backend_id, uint8 body_kind) { memset(plan, 0, sizeof(*plan)); plan->destination_node_id = destination_node_id; @@ -257,16 +252,13 @@ cluster_multixact_current_wire_build_proof_requests( if (nmembers > CLUSTER_CURRENT_MX_MAX_MEMBERS) return CMX_RESOLVE_SUPPORTED_LIMIT; if (key == NULL || members == NULL || member_origin_nodes == NULL || plans == NULL - || plan_count == NULL || nmembers < 1 || request_id == 0 - || !wire_epoch_valid(current_epoch) || requester_node < 0 - || requester_node >= CLUSTER_MAX_NODES - || (requester_backend_id <= 0 && !local_only) - || !wire_mxkey_valid(key, current_epoch) + || plan_count == NULL || nmembers < 1 || request_id == 0 || !wire_epoch_valid(current_epoch) + || requester_node < 0 || requester_node >= CLUSTER_MAX_NODES + || (requester_backend_id <= 0 && !local_only) || !wire_mxkey_valid(key, current_epoch) || cluster_multixact_current_validate_descriptor( key, key->origin_node_id, (uint32)current_epoch, members, nmembers, nmembers) != CMX_DESC_OK - || descriptor_hash - != cluster_multixact_current_descriptor_hash(key, members, nmembers)) + || descriptor_hash != cluster_multixact_current_descriptor_hash(key, members, nmembers)) return CMX_RESOLVE_UNKNOWN; memset(origin_counts, 0, sizeof(origin_counts)); @@ -287,10 +279,8 @@ cluster_multixact_current_wire_build_proof_requests( || challenge->member_ordinal != (uint16)updater_ordinal || challenge->updater_xid != members[updater_ordinal].xid || !cluster_multixact_current_successor_provenance_well_formed( - &challenge->candidate_next_xmin_alias, - &challenge->candidate_next_xmin_locator, - members[updater_ordinal].xid, - member_origin_nodes[updater_ordinal], + &challenge->candidate_next_xmin_alias, &challenge->candidate_next_xmin_locator, + members[updater_ordinal].xid, member_origin_nodes[updater_ordinal], (uint32)current_epoch)) return CMX_RESOLVE_UNKNOWN; Assert(origin_counts[member_origin_nodes[updater_ordinal]] > 0); @@ -321,8 +311,8 @@ cluster_multixact_current_wire_build_proof_requests( == CLUSTER_CURRENT_MX_MAX_PROOF_ASKS_PER_FRAME) { plan = &plans[built++]; wire_init_proof_request(plan, origin, key, descriptor_hash, nmembers, request_id, - current_epoch, requester_node, requester_backend_id, - CLUSTER_CURRENT_MX_PROOF_BODY_MEMBER_ASKS); + current_epoch, requester_node, requester_backend_id, + CLUSTER_CURRENT_MX_PROOF_BODY_MEMBER_ASKS); } ask = &plan->request.trailer.body.asks[plan->request.prefix.entry_count++]; ask->xid = members[i].xid; @@ -336,15 +326,13 @@ cluster_multixact_current_wire_build_proof_requests( ClusterCurrentMxUpdaterChallengeWire *wire_challenge; wire_init_proof_request(plan, member_origin_nodes[updater_ordinal], key, descriptor_hash, - nmembers, request_id, current_epoch, requester_node, - requester_backend_id, - CLUSTER_CURRENT_MX_PROOF_BODY_UPDATER_CHALLENGE); + nmembers, request_id, current_epoch, requester_node, + requester_backend_id, + CLUSTER_CURRENT_MX_PROOF_BODY_UPDATER_CHALLENGE); plan->request.prefix.entry_count = 1; wire_challenge = &plan->request.trailer.body.updater.challenge; - wire_challenge->candidate_next_xmin_alias - = challenge->candidate_next_xmin_alias; - wire_challenge->candidate_next_xmin_locator - = challenge->candidate_next_xmin_locator; + wire_challenge->candidate_next_xmin_alias = challenge->candidate_next_xmin_alias; + wire_challenge->candidate_next_xmin_locator = challenge->candidate_next_xmin_locator; wire_challenge->updater_xid = challenge->updater_xid; wire_challenge->member_ordinal = challenge->member_ordinal; wire_challenge->member_status = members[updater_ordinal].member_status; @@ -361,8 +349,8 @@ cluster_multixact_current_wire_build_proof_requests( static void -wire_proof_outputs_reset(ClusterCurrentMemberProof *proofs, uint16 proofs_cap, - uint16 *proof_count, ClusterCurrentUpdaterProof *updater_proof, +wire_proof_outputs_reset(ClusterCurrentMemberProof *proofs, uint16 proofs_cap, uint16 *proof_count, + ClusterCurrentUpdaterProof *updater_proof, uint32 *requester_capability_generation_out) { uint16 i; @@ -400,12 +388,11 @@ wire_member_proof_valid(const ClusterCurrentMemberProof *proof, switch ((ClusterCurrentMemberState)proof->state) { case CCM_ACTIVE: - return ClusterCurrentMemberProofGetCtrcGrant(proof) != 0 - && proof->commit_scn == InvalidScn - && ClusterCurrentMemberProofGetStatusKey( - proof, &status_key, &segment_generation, &slot_wrap) + return ClusterCurrentMemberProofGetCtrcGrant(proof) != 0 && proof->commit_scn == InvalidScn + && ClusterCurrentMemberProofGetStatusKey(proof, &status_key, &segment_generation, + &slot_wrap) && wire_tt_key_valid(&status_key, current_epoch, expected_source, - InvalidTransactionId) + InvalidTransactionId) && (status_key.local_xid == ask->xid || TransactionIdPrecedes(status_key.local_xid, ask->xid)); case CCM_COMMITTED: @@ -433,26 +420,23 @@ wire_updater_proof_valid(const ClusterCurrentUpdaterProof *proof, = &request->trailer.body.updater.challenge; return proof != NULL && wire_mxkey_equal(&proof->mxkey, &request->prefix.mxkey) - && memcmp(&proof->candidate_next_xmin_alias, - &challenge->candidate_next_xmin_alias, + && memcmp(&proof->candidate_next_xmin_alias, &challenge->candidate_next_xmin_alias, sizeof(ClusterCurrentMxSuccessorAlias)) == 0 && proof->candidate_next_xmin_locator.tt_wrap <= TT_WRAP_MAX - && cluster_tx_locator_reply_matches( - &challenge->candidate_next_xmin_locator, - &proof->candidate_next_xmin_locator) + && cluster_tx_locator_reply_matches(&challenge->candidate_next_xmin_locator, + &proof->candidate_next_xmin_locator) && proof->updater_xid == challenge->updater_xid - && proof->member_ordinal == challenge->member_ordinal - && proof->verdict < CUCP_UNKNOWN && proof->reserved8 == 0; + && proof->member_ordinal == challenge->member_ordinal && proof->verdict < CUCP_UNKNOWN + && proof->reserved8 == 0; } ClusterMxResolveResult cluster_multixact_current_wire_validate_proof_reply( const void *payload, uint32 payload_length, int32 expected_source, uint64 current_epoch, - const ClusterCurrentMxProofForwardV2 *expected_request, - ClusterCurrentMemberProof *proofs, uint16 proofs_cap, uint16 *proof_count, - ClusterCurrentUpdaterProof *updater_proof, + const ClusterCurrentMxProofForwardV2 *expected_request, ClusterCurrentMemberProof *proofs, + uint16 proofs_cap, uint16 *proof_count, ClusterCurrentUpdaterProof *updater_proof, uint32 *requester_capability_generation_out) { ClusterCurrentMxProofForwardV2 decoded_request; @@ -463,10 +447,10 @@ cluster_multixact_current_wire_validate_proof_reply( uint8 i; wire_proof_outputs_reset(proofs, proofs_cap, proof_count, updater_proof, - requester_capability_generation_out); + requester_capability_generation_out); if (payload == NULL || payload_length != sizeof(page) || expected_source < 0 - || expected_source >= CLUSTER_MAX_NODES || expected_request == NULL - || proof_count == NULL || updater_proof == NULL + || expected_source >= CLUSTER_MAX_NODES || expected_request == NULL || proof_count == NULL + || updater_proof == NULL || !cluster_multixact_current_wire_validate_proof_forward( expected_request, sizeof(*expected_request), expected_request->prefix.original_requester_node, expected_source, current_epoch, @@ -488,21 +472,20 @@ cluster_multixact_current_wire_validate_proof_reply( || header->chunk_ordinal != decoded_request.prefix.chunk_ordinal || header->chunk_count_minus_one != decoded_request.prefix.chunk_count_minus_one || header->result > CMX_RESOLVE_RETRY || header->result == CMX_RESOLVE_TIMEOUT - || header->reserved16 != 0 - || header->wire_length < sizeof(*header) || header->wire_length > sizeof(page)) + || header->reserved16 != 0 || header->wire_length < sizeof(*header) + || header->wire_length > sizeof(page)) return CMX_RESOLVE_UNKNOWN; result = (ClusterMxResolveResult)header->result; if (result != CMX_RESOLVE_OK) { - if (header->requester_capability_generation != 0 - || header->entry_count != 0 || header->wire_length != sizeof(*header) + if (header->requester_capability_generation != 0 || header->entry_count != 0 + || header->wire_length != sizeof(*header) || !bytes_are_zero((const uint8 *)&page + sizeof(*header), sizeof(page) - sizeof(*header))) return CMX_RESOLVE_UNKNOWN; return result; } - if (header->requester_capability_generation == 0 - || requester_capability_generation_out == NULL) + if (header->requester_capability_generation == 0 || requester_capability_generation_out == NULL) return CMX_RESOLVE_UNKNOWN; if (proofs == NULL) @@ -517,8 +500,8 @@ cluster_multixact_current_wire_validate_proof_reply( return CMX_RESOLVE_UNKNOWN; for (i = 0; i < header->entry_count; i++) if (!wire_member_proof_valid(&page.body.proofs[i], - &decoded_request.trailer.body.asks[i], - expected_source, current_epoch)) + &decoded_request.trailer.body.asks[i], expected_source, + current_epoch)) return CMX_RESOLVE_UNKNOWN; memcpy(proofs, page.body.proofs, sizeof(*proofs) * header->entry_count); break; @@ -528,16 +511,14 @@ cluster_multixact_current_wire_validate_proof_reply( memset(&updater_ask, 0, sizeof(updater_ask)); updater_ask.xid = decoded_request.trailer.body.updater.challenge.updater_xid; - updater_ask.member_ordinal - = decoded_request.trailer.body.updater.challenge.member_ordinal; - updater_ask.member_status - = decoded_request.trailer.body.updater.challenge.member_status; + updater_ask.member_ordinal = decoded_request.trailer.body.updater.challenge.member_ordinal; + updater_ask.member_status = decoded_request.trailer.body.updater.challenge.member_status; expected_wire_length = sizeof(*header) + sizeof(ClusterCurrentMemberProof) + sizeof(ClusterCurrentUpdaterProof); if (header->entry_count != 1 || proofs_cap < 1 || header->wire_length != expected_wire_length || !wire_member_proof_valid(&page.body.updater.member_proof, &updater_ask, - expected_source, current_epoch) + expected_source, current_epoch) || !wire_updater_proof_valid(&page.body.updater.updater_proof, &decoded_request)) return CMX_RESOLVE_UNKNOWN; proofs[0] = page.body.updater.member_proof; @@ -552,13 +533,12 @@ cluster_multixact_current_wire_validate_proof_reply( if (!bytes_are_zero((const uint8 *)&page + header->wire_length, sizeof(page) - header->wire_length)) { wire_proof_outputs_reset(proofs, proofs_cap, proof_count, updater_proof, - requester_capability_generation_out); + requester_capability_generation_out); return CMX_RESOLVE_UNKNOWN; } *proof_count = header->entry_count; - *requester_capability_generation_out - = header->requester_capability_generation; + *requester_capability_generation_out = header->requester_capability_generation; return CMX_RESOLVE_OK; } @@ -568,8 +548,7 @@ cluster_multixact_current_wire_validate_proof_reply_frame( const void *payload, uint32 payload_length, int32 expected_source, uint64 current_epoch, const ClusterCurrentMxProofForwardV2 *expected_request, ClusterMxResolveResult *result, ClusterCurrentMemberProof *proofs, uint16 proofs_cap, uint16 *proof_count, - ClusterCurrentUpdaterProof *updater_proof, - uint32 *requester_capability_generation_out) + ClusterCurrentUpdaterProof *updater_proof, uint32 *requester_capability_generation_out) { ClusterMxResolveResult decoded_result; @@ -581,8 +560,7 @@ cluster_multixact_current_wire_validate_proof_reply_frame( return false; decoded_result = cluster_multixact_current_wire_validate_proof_reply( payload, payload_length, expected_source, current_epoch, expected_request, proofs, - proofs_cap, proof_count, updater_proof, - requester_capability_generation_out); + proofs_cap, proof_count, updater_proof, requester_capability_generation_out); if (decoded_result != CMX_RESOLVE_UNKNOWN) { *result = decoded_result; return true; @@ -590,8 +568,7 @@ cluster_multixact_current_wire_validate_proof_reply_frame( if (payload != NULL && payload_length == sizeof(ClusterCurrentMxProofReplyPage)) { ClusterCurrentMxProofReplyPage page; - ClusterCurrentMemberProof scratch_proofs - [CLUSTER_CURRENT_MX_MAX_PROOF_ASKS_PER_FRAME]; + ClusterCurrentMemberProof scratch_proofs[CLUSTER_CURRENT_MX_MAX_PROOF_ASKS_PER_FRAME]; ClusterCurrentUpdaterProof scratch_updater; uint16 scratch_count = 0; uint32 scratch_capability_generation = 0; @@ -601,8 +578,8 @@ cluster_multixact_current_wire_validate_proof_reply_frame( page.header.result = CMX_RESOLVE_DENIED; if (cluster_multixact_current_wire_validate_proof_reply( &page, sizeof(page), expected_source, current_epoch, expected_request, - scratch_proofs, lengthof(scratch_proofs), &scratch_count, - &scratch_updater, &scratch_capability_generation) + scratch_proofs, lengthof(scratch_proofs), &scratch_count, &scratch_updater, + &scratch_capability_generation) == CMX_RESOLVE_DENIED) { *result = CMX_RESOLVE_UNKNOWN; return true; @@ -614,11 +591,13 @@ cluster_multixact_current_wire_validate_proof_reply_frame( ClusterMxDescribeResult -cluster_multixact_current_wire_validate_describe_reply( - const void *payload, uint32 payload_length, int32 expected_source, uint64 current_epoch, - uint64 expected_request_id, const ClusterCurrentMxKey *expected_key, - ClusterCurrentMxMemberDesc *members, uint16 members_cap, uint16 *members_count, - uint32 *reported_total_members) +cluster_multixact_current_wire_validate_describe_reply(const void *payload, uint32 payload_length, + int32 expected_source, uint64 current_epoch, + uint64 expected_request_id, + const ClusterCurrentMxKey *expected_key, + ClusterCurrentMxMemberDesc *members, + uint16 members_cap, uint16 *members_count, + uint32 *reported_total_members) { ClusterCurrentMxDescribeReplyPage page; const ClusterCurrentMxDescribeReplyHeader *header; @@ -646,10 +625,9 @@ cluster_multixact_current_wire_validate_describe_reply( || header->flags != CLUSTER_CURRENT_MX_WIRE_FLAGS_NONE || header->source_node_id != (uint32)expected_source || header->request_id != expected_request_id - || !wire_mxkey_equal(&header->mxkey, expected_key) - || header->result > CMX_DESC_UNKNOWN || header->result == CMX_DESC_TIMEOUT - || header->chunk_ordinal != 0 || header->chunk_count_minus_one != 0 - || header->reserved16 != 0 || header->reserved32 != 0 + || !wire_mxkey_equal(&header->mxkey, expected_key) || header->result > CMX_DESC_UNKNOWN + || header->result == CMX_DESC_TIMEOUT || header->chunk_ordinal != 0 + || header->chunk_count_minus_one != 0 || header->reserved16 != 0 || header->reserved32 != 0 || header->wire_length < sizeof(*header) || header->wire_length > sizeof(page)) return CMX_DESC_UNKNOWN; @@ -670,19 +648,18 @@ cluster_multixact_current_wire_validate_describe_reply( return result; } - expected_wire_length - = sizeof(*header) + sizeof(*page.members) * (Size)header->entry_count; + expected_wire_length = sizeof(*header) + sizeof(*page.members) * (Size)header->entry_count; if (header->total_count != header->entry_count || header->entry_count > members_cap || header->entry_count > CLUSTER_CURRENT_MX_MAX_MEMBERS || header->wire_length != expected_wire_length || members == NULL || members_count == NULL || reported_total_members == NULL - || cluster_multixact_current_validate_descriptor( - expected_key, (uint16)expected_source, (uint32)current_epoch, page.members, - header->entry_count, header->total_count) + || cluster_multixact_current_validate_descriptor(expected_key, (uint16)expected_source, + (uint32)current_epoch, page.members, + header->entry_count, header->total_count) != CMX_DESC_OK || header->descriptor_hash != cluster_multixact_current_descriptor_hash(expected_key, page.members, - header->entry_count) + header->entry_count) || !bytes_are_zero((const uint8 *)&page + header->wire_length, sizeof(page) - header->wire_length)) return CMX_DESC_UNKNOWN; diff --git a/src/backend/cluster/cluster_node_remove.c b/src/backend/cluster/cluster_node_remove.c index 430f0db5d0a..4f71b23dc12 100644 --- a/src/backend/cluster/cluster_node_remove.c +++ b/src/backend/cluster/cluster_node_remove.c @@ -627,9 +627,8 @@ cluster_node_remove_request(int32 node_id) int32 cur_target; CLUSTER_INJECTION_POINT("cluster-node-remove-request"); - if (!cluster_node_remove_startup_serving_allows( - cluster_authority_readiness_managed(), - cluster_serving_ready_is_current())) + if (!cluster_node_remove_startup_serving_allows(cluster_authority_readiness_managed(), + cluster_serving_ready_is_current())) return CLUSTER_REMOVE_REQ_NOT_SERVING; feature = cluster_online_node_removal; @@ -1017,9 +1016,8 @@ cluster_node_remove_lmon_tick(void) if (nr_state == NULL || !cluster_enabled || !cluster_online_node_removal) return; - if (!cluster_node_remove_startup_serving_allows( - cluster_authority_readiness_managed(), - cluster_serving_ready_is_current())) + if (!cluster_node_remove_startup_serving_allows(cluster_authority_readiness_managed(), + cluster_serving_ready_is_current())) return; if (!cluster_qvotec_in_quorum()) return; /* only an in-quorum survivor participates */ diff --git a/src/backend/cluster/cluster_node_remove_policy.c b/src/backend/cluster/cluster_node_remove_policy.c index 88a58fb1b50..1844c7b43ea 100644 --- a/src/backend/cluster/cluster_node_remove_policy.c +++ b/src/backend/cluster/cluster_node_remove_policy.c @@ -161,8 +161,7 @@ cluster_node_remove_request_result_str(ClusterRemoveRequestResult r) } bool -cluster_node_remove_startup_serving_allows(bool authority_managed, - bool serving_ready) +cluster_node_remove_startup_serving_allows(bool authority_managed, bool serving_ready) { return !authority_managed || serving_ready; } diff --git a/src/backend/cluster/cluster_node_remove_views.c b/src/backend/cluster/cluster_node_remove_views.c index 34e7ac12cdf..c5bcb0c746f 100644 --- a/src/backend/cluster/cluster_node_remove_views.c +++ b/src/backend/cluster/cluster_node_remove_views.c @@ -48,8 +48,10 @@ #include "miscadmin.h" /* superuser() */ #include "utils/builtins.h" /* cstring_to_text */ +#ifdef USE_PGRAC_CLUSTER #include "cluster/cluster_guc.h" /* cluster_enabled */ #include "cluster/cluster_node_remove.h" +#endif PG_FUNCTION_INFO_V1(cluster_get_node_removal_state); PG_FUNCTION_INFO_V1(pg_cluster_remove_node); diff --git a/src/backend/cluster/cluster_page_anchor_cache.c b/src/backend/cluster/cluster_page_anchor_cache.c index 3d67432528d..89da8fe0c12 100644 --- a/src/backend/cluster/cluster_page_anchor_cache.c +++ b/src/backend/cluster/cluster_page_anchor_cache.c @@ -10,10 +10,9 @@ #include "access/xloginsert.h" #include "cluster/cluster_page_anchor_cache.h" -typedef struct RfPageAnchorCacheEntryV1 -{ +typedef struct RfPageAnchorCacheEntryV1 { RfPageAnchorCacheKeyV1 key; - bool valid; + bool valid; } RfPageAnchorCacheEntryV1; static RfPageAnchorCacheEntryV1 anchor_cache[RF_PAGE_ANCHOR_CACHE_CAPACITY]; @@ -21,8 +20,8 @@ static RfPageAnchorCacheEntryV1 anchor_cache[RF_PAGE_ANCHOR_CACHE_CAPACITY]; static bool bytes_nonzero(const uint8 *bytes, size_t length) { - uint8 any = 0; - size_t i; + uint8 any = 0; + size_t i; for (i = 0; i < length; i++) any |= bytes[i]; @@ -32,51 +31,44 @@ bytes_nonzero(const uint8 *bytes, size_t length) bool rf_page_anchor_cache_key_valid_v1(const RfPageAnchorCacheKeyV1 *key) { - return key != NULL && - rf_page_identity_valid_v1(&key->page_identity) && - bytes_nonzero(key->segment_incarnation, 16) && - bytes_nonzero(key->root_lineage, 16) && - key->checkpoint_epoch != 0 && key->fpw_epoch != 0; + return key != NULL && rf_page_identity_valid_v1(&key->page_identity) + && bytes_nonzero(key->segment_incarnation, 16) && bytes_nonzero(key->root_lineage, 16) + && key->checkpoint_epoch != 0 && key->fpw_epoch != 0; } bool rf_page_anchor_cache_block_matches_v1(const RfPageAnchorCacheKeyV1 *key, - const RelFileLocator *locator, - ForkNumber forknum, + const RelFileLocator *locator, ForkNumber forknum, BlockNumber blockno) { - return rf_page_anchor_cache_key_valid_v1(key) && locator != NULL && - RelFileLocatorEquals(key->page_identity.locator, *locator) && - key->page_identity.forknum == (uint32) forknum && - key->page_identity.blockno == blockno; + return rf_page_anchor_cache_key_valid_v1(key) && locator != NULL + && RelFileLocatorEquals(key->page_identity.locator, *locator) + && key->page_identity.forknum == (uint32)forknum + && key->page_identity.blockno == blockno; } bool -rf_page_anchor_cache_incarnation_matches_v1( - const RfPageAnchorCacheKeyV1 *key, - const uint8 result_incarnation[16]) +rf_page_anchor_cache_incarnation_matches_v1(const RfPageAnchorCacheKeyV1 *key, + const uint8 result_incarnation[16]) { - return rf_page_anchor_cache_key_valid_v1(key) && - result_incarnation != NULL && - memcmp(key->segment_incarnation, result_incarnation, 16) == 0; + return rf_page_anchor_cache_key_valid_v1(key) && result_incarnation != NULL + && memcmp(key->segment_incarnation, result_incarnation, 16) == 0; } static bool -key_equal(const RfPageAnchorCacheKeyV1 *left, - const RfPageAnchorCacheKeyV1 *right) +key_equal(const RfPageAnchorCacheKeyV1 *left, const RfPageAnchorCacheKeyV1 *right) { - return rf_page_identity_equal_v1(&left->page_identity, - &right->page_identity) && - memcmp(left->segment_incarnation, right->segment_incarnation, 16) == 0 && - memcmp(left->root_lineage, right->root_lineage, 16) == 0 && - left->checkpoint_epoch == right->checkpoint_epoch && - left->fpw_epoch == right->fpw_epoch; + return rf_page_identity_equal_v1(&left->page_identity, &right->page_identity) + && memcmp(left->segment_incarnation, right->segment_incarnation, 16) == 0 + && memcmp(left->root_lineage, right->root_lineage, 16) == 0 + && left->checkpoint_epoch == right->checkpoint_epoch + && left->fpw_epoch == right->fpw_epoch; } bool rf_page_anchor_cache_should_force_v1(const RfPageAnchorCacheKeyV1 *key) { - int i; + int i; if (!rf_page_anchor_cache_key_valid_v1(key)) return true; @@ -87,8 +79,7 @@ rf_page_anchor_cache_should_force_v1(const RfPageAnchorCacheKeyV1 *key) } uint8 -rf_page_anchor_cache_registration_flags_v1(const RfPageAnchorCacheKeyV1 *key, - uint8 caller_flags) +rf_page_anchor_cache_registration_flags_v1(const RfPageAnchorCacheKeyV1 *key, uint8 caller_flags) { if (rf_page_anchor_cache_should_force_v1(key)) caller_flags |= REGBUF_FORCE_IMAGE; @@ -96,24 +87,19 @@ rf_page_anchor_cache_registration_flags_v1(const RfPageAnchorCacheKeyV1 *key, } bool -rf_page_anchor_cache_record_v1(const RfPageAnchorCacheKeyV1 *key, - bool insert_succeeded, +rf_page_anchor_cache_record_v1(const RfPageAnchorCacheKeyV1 *key, bool insert_succeeded, bool apply_image_emitted) { - int empty = -1; - int i; + int empty = -1; + int i; - if (!insert_succeeded || !apply_image_emitted || - !rf_page_anchor_cache_key_valid_v1(key)) + if (!insert_succeeded || !apply_image_emitted || !rf_page_anchor_cache_key_valid_v1(key)) return false; - for (i = 0; i < RF_PAGE_ANCHOR_CACHE_CAPACITY; i++) - { - if (anchor_cache[i].valid) - { + for (i = 0; i < RF_PAGE_ANCHOR_CACHE_CAPACITY; i++) { + if (anchor_cache[i].valid) { if (key_equal(&anchor_cache[i].key, key)) return true; - } - else if (empty < 0) + } else if (empty < 0) empty = i; } if (empty < 0) diff --git a/src/backend/cluster/cluster_page_apply.c b/src/backend/cluster/cluster_page_apply.c index 44b7769f261..01ff343dffc 100644 --- a/src/backend/cluster/cluster_page_apply.c +++ b/src/backend/cluster/cluster_page_apply.c @@ -35,26 +35,23 @@ cluster_page_mutation_admission(const ClusterPageMutationAdmission *admission) * never a temporary-failure-to-skip conversion. */ if (admission == NULL) return false; - return admission->duty_root_ok && admission->recoverer_active_ok - && admission->fence_ok && admission->serialization_ok - && admission->source_proof_fresh && admission->working_version_exact - && admission->retention_covers; + return admission->duty_root_ok && admission->recoverer_active_ok && admission->fence_ok + && admission->serialization_ok && admission->source_proof_fresh + && admission->working_version_exact && admission->retention_covers; } static ClusterPageSequenceResult -cluster_page_sequence_fail(ClusterPageRecoveryState state, - ClusterPageRecoveryOutcome outcome) +cluster_page_sequence_fail(ClusterPageRecoveryState state, ClusterPageRecoveryOutcome outcome) { ClusterPageSequenceResult r; - r.state = state; /* unchanged: no advance past a failed gate */ + r.state = state; /* unchanged: no advance past a failed gate */ r.outcome = outcome; return r; } ClusterPageSequenceResult -cluster_page_apply_step_durability(ClusterPageRecoveryState state, - bool durable_ok) +cluster_page_apply_step_durability(ClusterPageRecoveryState state, bool durable_ok) { ClusterPageSequenceResult r; @@ -73,8 +70,7 @@ cluster_page_apply_step_durability(ClusterPageRecoveryState state, } ClusterPageSequenceResult -cluster_page_apply_step_post_read(ClusterPageRecoveryState state, - bool post_read_ok) +cluster_page_apply_step_post_read(ClusterPageRecoveryState state, bool post_read_ok) { ClusterPageSequenceResult r; @@ -92,8 +88,7 @@ cluster_page_apply_step_post_read(ClusterPageRecoveryState state, } ClusterPageSequenceResult -cluster_page_apply_step_authority(ClusterPageRecoveryState state, - bool authority_ok) +cluster_page_apply_step_authority(ClusterPageRecoveryState state, bool authority_ok) { ClusterPageSequenceResult r; @@ -126,43 +121,42 @@ cluster_page_apply_midwrite_cut(void) ClusterPageRecoveryOutcome cluster_page_crash_matrix_verdict(ClusterPageCrashCut cut) { - switch (cut) - { - case CLUSTER_PAGE_CUT_BEFORE_SOURCE_PROOF: - /* §7.7: no trusted state -> rebuild the source census; + switch (cut) { + case CLUSTER_PAGE_CUT_BEFORE_SOURCE_PROOF: + /* §7.7: no trusted state -> rebuild the source census; * mutation=0. */ - return CLUSTER_PAGE_OUTCOME_BLOCKED_SOURCE; + return CLUSTER_PAGE_OUTCOME_BLOCKED_SOURCE; - case CLUSTER_PAGE_CUT_AFTER_SOURCE_PROOF: - /* Ephemeral proof only: the successor re-censuses and never + case CLUSTER_PAGE_CUT_AFTER_SOURCE_PROOF: + /* Ephemeral proof only: the successor re-censuses and never * adopts the predecessor-local plan (D3′). */ - return CLUSTER_PAGE_OUTCOME_BLOCKED_SOURCE; + return CLUSTER_PAGE_OUTCOME_BLOCKED_SOURCE; - case CLUSTER_PAGE_CUT_DURING_TARGET_WRITE: - /* Target may be torn: STOP-RF-PAGE-STABLE-BASE. */ - return CLUSTER_PAGE_OUTCOME_STABLE_BASE_UNRESOLVED; + case CLUSTER_PAGE_CUT_DURING_TARGET_WRITE: + /* Target may be torn: STOP-RF-PAGE-STABLE-BASE. */ + return CLUSTER_PAGE_OUTCOME_STABLE_BASE_UNRESOLVED; - case CLUSTER_PAGE_CUT_AFTER_WRITE_BEFORE_DURABILITY: - /* Non-durable/untrusted target: rebuild or BLOCKED. */ - return CLUSTER_PAGE_OUTCOME_BLOCKED_SOURCE; + case CLUSTER_PAGE_CUT_AFTER_WRITE_BEFORE_DURABILITY: + /* Non-durable/untrusted target: rebuild or BLOCKED. */ + return CLUSTER_PAGE_OUTCOME_BLOCKED_SOURCE; - case CLUSTER_PAGE_CUT_AFTER_DURABILITY_BEFORE_POST_READ: - /* Durable but unverified bytes: fresh post-read; failure => + case CLUSTER_PAGE_CUT_AFTER_DURABILITY_BEFORE_POST_READ: + /* Durable but unverified bytes: fresh post-read; failure => * rebuild/BLOCKED. */ - return CLUSTER_PAGE_OUTCOME_BLOCKED_SOURCE; + return CLUSTER_PAGE_OUTCOME_BLOCKED_SOURCE; - case CLUSTER_PAGE_CUT_AFTER_POST_READ_BEFORE_RELEASE: - /* Durable result re-verifiable: authority revalidate then + case CLUSTER_PAGE_CUT_AFTER_POST_READ_BEFORE_RELEASE: + /* Durable result re-verifiable: authority revalidate then * exact release (PU-29). */ - return CLUSTER_PAGE_OUTCOME_STALE_AUTHORITY; + return CLUSTER_PAGE_OUTCOME_STALE_AUTHORITY; - case CLUSTER_PAGE_CUT_AFTER_RELEASE: - /* Resource ready only; redo retirement stays RF-ROOT + case CLUSTER_PAGE_CUT_AFTER_RELEASE: + /* Resource ready only; redo retirement stays RF-ROOT * FND-10's decision — never implied by the release. */ - return CLUSTER_PAGE_OUTCOME_APPLY; + return CLUSTER_PAGE_OUTCOME_APPLY; - default: - /* Unknown cut: fail closed. */ - return CLUSTER_PAGE_OUTCOME_BLOCKED_CLASS; + default: + /* Unknown cut: fail closed. */ + return CLUSTER_PAGE_OUTCOME_BLOCKED_CLASS; } } diff --git a/src/backend/cluster/cluster_page_authority.c b/src/backend/cluster/cluster_page_authority.c index 75f69b30189..ac717155839 100644 --- a/src/backend/cluster/cluster_page_authority.c +++ b/src/backend/cluster/cluster_page_authority.c @@ -20,41 +20,38 @@ #define RF_PAGE_AUTHORITY_PREFLIGHT_MAGIC UINT32_C(0x52504150) #define RF_PAGE_AUTHORITY_GUARD_MAGIC UINT32_C(0x52504147) -typedef enum RfPageAuthorityStateV1 -{ +typedef enum RfPageAuthorityStateV1 { RF_PAGE_AUTHORITY_STATE_PREFLIGHTED = 1, RF_PAGE_AUTHORITY_STATE_PROMOTED = 2, RF_PAGE_AUTHORITY_STATE_RELEASED = 3 } RfPageAuthorityStateV1; -struct RfPageAuthorityGuardV1 -{ - uint32 magic; - uint8 state; - uint8 reserved_zero[3]; +struct RfPageAuthorityGuardV1 { + uint32 magic; + uint8 state; + uint8 reserved_zero[3]; struct RfPageAuthorityPreflightV1 *preflight; ClusterRecoverySerialGuard *serial_guard; - uint32 guard_count; - uint8 *target_guard_index; + uint32 guard_count; + uint8 *target_guard_index; RfPageGuardV1 page_guards[RF_PAGE_GUARD_PARTITIONS]; }; -struct RfPageAuthorityPreflightV1 -{ - uint32 magic; - uint8 state; - uint8 reserved_zero[3]; - uint32 target_count; +struct RfPageAuthorityPreflightV1 { + uint32 magic; + uint8 state; + uint8 reserved_zero[3]; + uint32 target_count; const ClusterFormationWitnessV1 *formation; const PgracExternalFenceNeedSetV1 *fence_need_set; const PgracExternalFenceAdmissionSetV1 *fence_admission_set; ClusterWalRetentionPin *retention_pin; const ClusterRecoveryDutyKey *duties; const ClusterControlRootReadToken *root_tokens; - uint32 participant_count; + uint32 participant_count; RfPageAuthorityTargetV1 *targets; RfPageGuardPreflightV1 *page_preflights; - uint8 *target_guard_index; + uint8 *target_guard_index; RfPageAuthorityGuardV1 guard_storage; }; @@ -75,8 +72,8 @@ authority_preflight_free(RfPageAuthorityPreflightV1 *preflight) static bool bytes_nonzero(const uint8 *bytes, Size length) { - uint8 value = 0; - Size i; + uint8 value = 0; + Size i; for (i = 0; i < length; i++) value |= bytes[i]; @@ -86,34 +83,34 @@ bytes_nonzero(const uint8 *bytes, Size length) static bool authority_identity_valid(const RfPageIdentityV1 *identity) { - return identity != NULL && identity->system_identifier != 0 && - bytes_nonzero(identity->storage_uuid, sizeof(identity->storage_uuid)) && - identity->locator.spcOid != InvalidOid && - identity->locator.dbOid != InvalidOid && - identity->locator.relNumber != InvalidRelFileNumber && - identity->blockno != InvalidBlockNumber && identity->reserved_zero == 0; + return identity != NULL && identity->system_identifier != 0 + && bytes_nonzero(identity->storage_uuid, sizeof(identity->storage_uuid)) + && identity->locator.spcOid != InvalidOid && identity->locator.dbOid != InvalidOid + && identity->locator.relNumber != InvalidRelFileNumber + && identity->blockno != InvalidBlockNumber && identity->reserved_zero == 0; } static bool -authority_identity_equal(const RfPageIdentityV1 *left, - const RfPageIdentityV1 *right) +authority_identity_equal(const RfPageIdentityV1 *left, const RfPageIdentityV1 *right) { - return left != NULL && right != NULL && - left->system_identifier == right->system_identifier && - memcmp(left->storage_uuid, right->storage_uuid, 16) == 0 && - RelFileLocatorEquals(left->locator, right->locator) && - left->forknum == right->forknum && left->blockno == right->blockno && - left->reserved_zero == 0 && right->reserved_zero == 0; + return left != NULL && right != NULL && left->system_identifier == right->system_identifier + && memcmp(left->storage_uuid, right->storage_uuid, 16) == 0 + && RelFileLocatorEquals(left->locator, right->locator) && left->forknum == right->forknum + && left->blockno == right->blockno && left->reserved_zero == 0 + && right->reserved_zero == 0; } static int -identity_compare(const RfPageIdentityV1 *left, - const RfPageIdentityV1 *right) +identity_compare(const RfPageIdentityV1 *left, const RfPageIdentityV1 *right) { -#define CMP_FIELD(field_) \ - do { if (left->field_ < right->field_) return -1; \ - if (left->field_ > right->field_) return 1; } while (0) - int cmp; +#define CMP_FIELD(field_) \ + do { \ + if (left->field_ < right->field_) \ + return -1; \ + if (left->field_ > right->field_) \ + return 1; \ + } while (0) + int cmp; CMP_FIELD(system_identifier); cmp = memcmp(left->storage_uuid, right->storage_uuid, 16); @@ -131,32 +128,28 @@ identity_compare(const RfPageIdentityV1 *left, static bool fence_current(const RfPageAuthorityPreflightV1 *preflight) { - PgracExternalFenceDenyReason reason = - PGRAC_EXTERNAL_FENCE_DENY_BAD_ARGUMENT; - - return cluster_external_fence_need_set_revalidate_nowait( - preflight->fence_need_set, preflight->formation, &reason) && - cluster_external_fence_revalidate_set_nowait( - preflight->fence_admission_set, preflight->fence_need_set, - preflight->formation, &reason); + PgracExternalFenceDenyReason reason = PGRAC_EXTERNAL_FENCE_DENY_BAD_ARGUMENT; + + return cluster_external_fence_need_set_revalidate_nowait(preflight->fence_need_set, + preflight->formation, &reason) + && cluster_external_fence_revalidate_set_nowait(preflight->fence_admission_set, + preflight->fence_need_set, + preflight->formation, &reason); } static bool stable_proofs_current(const RfPageAuthorityPreflightV1 *preflight) { - uint32 i; + uint32 i; - for (i = 0; i < preflight->target_count; i++) - { + for (i = 0; i < preflight->target_count; i++) { const RfPageAuthorityTargetV1 *target = &preflight->targets[i]; - if (!rf_page_stable_base_proof_matches_v1(target->stable_base, - &target->page_identity, &target->expected_result, - preflight->duties, preflight->root_tokens, - preflight->formation, preflight->fence_need_set, - preflight->fence_admission_set, - preflight->retention_pin, target->source, - target->contributors, preflight->participant_count)) + if (!rf_page_stable_base_proof_matches_v1( + target->stable_base, &target->page_identity, &target->expected_result, + preflight->duties, preflight->root_tokens, preflight->formation, + preflight->fence_need_set, preflight->fence_admission_set, preflight->retention_pin, + target->source, target->contributors, preflight->participant_count)) return false; } return true; @@ -168,29 +161,28 @@ owners_current(const RfPageAuthorityPreflightV1 *preflight, { ClusterRecoverySerialRevalidateResult serial_result; - if (preflight == NULL || serial_guard == NULL || - preflight->magic != RF_PAGE_AUTHORITY_PREFLIGHT_MAGIC || - preflight->state == RF_PAGE_AUTHORITY_STATE_RELEASED) + if (preflight == NULL || serial_guard == NULL + || preflight->magic != RF_PAGE_AUTHORITY_PREFLIGHT_MAGIC + || preflight->state == RF_PAGE_AUTHORITY_STATE_RELEASED) return RF_PAGE_AUTHORITY_INVALID_ARGUMENT; if (!serial_guard->held) return RF_PAGE_AUTHORITY_SERIAL_NOT_HELD; - if (serial_guard->formation != preflight->formation || - serial_guard->fence_need_set != preflight->fence_need_set || - serial_guard->fence_admission_set != - preflight->fence_admission_set) + if (serial_guard->formation != preflight->formation + || serial_guard->fence_need_set != preflight->fence_need_set + || serial_guard->fence_admission_set != preflight->fence_admission_set) return RF_PAGE_AUTHORITY_FENCE_STALE; - if (preflight->participant_count != 1 || - cluster_recovery_duty_key_compare(&preflight->duties[0], - &serial_guard->duty) != CLUSTER_RECOVERY_DUTY_COMPARE_EXACT) + if (preflight->participant_count != 1 + || cluster_recovery_duty_key_compare(&preflight->duties[0], &serial_guard->duty) + != CLUSTER_RECOVERY_DUTY_COMPARE_EXACT) return RF_PAGE_AUTHORITY_GENERATION_STALE; if (memcmp(&preflight->root_tokens[0], &serial_guard->root_read_token, - sizeof(serial_guard->root_read_token)) != 0) + sizeof(serial_guard->root_read_token)) + != 0) return RF_PAGE_AUTHORITY_ROOT_STALE; if (!stable_proofs_current(preflight)) return RF_PAGE_AUTHORITY_NO_STABLE_BASE; serial_result = cluster_recovery_serial_revalidate(serial_guard); - if (serial_result != CLUSTER_RECOVERY_SERIAL_CURRENT) - { + if (serial_result != CLUSTER_RECOVERY_SERIAL_CURRENT) { if (serial_result == CLUSTER_RECOVERY_SERIAL_NOT_HELD) return RF_PAGE_AUTHORITY_SERIAL_NOT_HELD; if (serial_result == CLUSTER_RECOVERY_SERIAL_FENCE_STALE) @@ -201,46 +193,39 @@ owners_current(const RfPageAuthorityPreflightV1 *preflight, } if (!fence_current(preflight)) return RF_PAGE_AUTHORITY_FENCE_STALE; - if (cluster_wal_retention_pin_revalidate(preflight->retention_pin) != - CLUSTER_WAL_PIN_OK) + if (cluster_wal_retention_pin_revalidate(preflight->retention_pin) != CLUSTER_WAL_PIN_OK) return RF_PAGE_AUTHORITY_RETENTION_STALE; return RF_PAGE_AUTHORITY_OK; } RfPageAuthorityVerdictV1 -rf_page_authority_batch_preflight_wait_v1( - const RfPageAuthorityBatchRequestV1 *request, int timeout_ms, - RfPageAuthorityPreflightV1 **out_preflight) +rf_page_authority_batch_preflight_wait_v1(const RfPageAuthorityBatchRequestV1 *request, + int timeout_ms, + RfPageAuthorityPreflightV1 **out_preflight) { RfPageAuthorityPreflightV1 *preflight; - uint32 i; + uint32 i; if (out_preflight == NULL) return RF_PAGE_AUTHORITY_INVALID_ARGUMENT; *out_preflight = NULL; - if (request == NULL || request->targets == NULL || - request->target_count == 0 || - request->target_count > RF_PAGE_STABLE_MAX_EDGES || - request->formation == NULL || request->fence_need_set == NULL || - request->fence_admission_set == NULL || - request->retention_pin == NULL || request->duties == NULL || - request->root_tokens == NULL || - request->participant_count == 0 || - request->participant_count != 1 || - request->flags != 0 || - timeout_ms < 0) + if (request == NULL || request->targets == NULL || request->target_count == 0 + || request->target_count > RF_PAGE_STABLE_MAX_EDGES || request->formation == NULL + || request->fence_need_set == NULL || request->fence_admission_set == NULL + || request->retention_pin == NULL || request->duties == NULL || request->root_tokens == NULL + || request->participant_count == 0 || request->participant_count != 1 || request->flags != 0 + || timeout_ms < 0) return RF_PAGE_AUTHORITY_INVALID_ARGUMENT; - for (i = 0; i < request->target_count; i++) - { - if (!authority_identity_valid(&request->targets[i].page_identity) || - !bytes_nonzero(request->targets[i].expected_result.segment_incarnation, - 16) || request->targets[i].expected_result.mutation_token == 0 || - request->targets[i].stable_base == NULL || - request->targets[i].source == NULL || - request->targets[i].contributors == NULL || - (i > 0 && identity_compare(&request->targets[i - 1].page_identity, - &request->targets[i].page_identity) >= 0)) - { + for (i = 0; i < request->target_count; i++) { + if (!authority_identity_valid(&request->targets[i].page_identity) + || !bytes_nonzero(request->targets[i].expected_result.segment_incarnation, 16) + || request->targets[i].expected_result.mutation_token == 0 + || request->targets[i].stable_base == NULL || request->targets[i].source == NULL + || request->targets[i].contributors == NULL + || (i > 0 + && identity_compare(&request->targets[i - 1].page_identity, + &request->targets[i].page_identity) + >= 0)) { if (request->targets[i].stable_base == NULL) return RF_PAGE_AUTHORITY_NO_STABLE_BASE; if (request->targets[i].contributors == NULL) @@ -248,20 +233,16 @@ rf_page_authority_batch_preflight_wait_v1( return RF_PAGE_AUTHORITY_IDENTITY_MISMATCH; } } - preflight = (RfPageAuthorityPreflightV1 *) - authority_alloc0(sizeof(*preflight)); + preflight = (RfPageAuthorityPreflightV1 *)authority_alloc0(sizeof(*preflight)); if (preflight == NULL) return RF_PAGE_AUTHORITY_OOM; - preflight->targets = (RfPageAuthorityTargetV1 *) authority_alloc0( - (Size) request->target_count * sizeof(*preflight->targets)); - preflight->page_preflights = (RfPageGuardPreflightV1 *) - authority_alloc0((Size) request->target_count * - sizeof(*preflight->page_preflights)); - preflight->target_guard_index = (uint8 *) - authority_alloc0((Size) request->target_count); - if (preflight->targets == NULL || preflight->page_preflights == NULL || - preflight->target_guard_index == NULL) - { + preflight->targets = (RfPageAuthorityTargetV1 *)authority_alloc0((Size)request->target_count + * sizeof(*preflight->targets)); + preflight->page_preflights = (RfPageGuardPreflightV1 *)authority_alloc0( + (Size)request->target_count * sizeof(*preflight->page_preflights)); + preflight->target_guard_index = (uint8 *)authority_alloc0((Size)request->target_count); + if (preflight->targets == NULL || preflight->page_preflights == NULL + || preflight->target_guard_index == NULL) { authority_preflight_free(preflight); return RF_PAGE_AUTHORITY_OOM; } @@ -275,23 +256,19 @@ rf_page_authority_batch_preflight_wait_v1( preflight->duties = request->duties; preflight->root_tokens = request->root_tokens; preflight->participant_count = request->participant_count; - for (i = 0; i < request->target_count; i++) - { + for (i = 0; i < request->target_count; i++) { preflight->targets[i] = request->targets[i]; if (!rf_page_guard_preflight_v1(&request->targets[i].page_identity, - &preflight->page_preflights[i])) - { + &preflight->page_preflights[i])) { authority_preflight_free(preflight); return RF_PAGE_AUTHORITY_INTERNAL; } } - if (!fence_current(preflight)) - { + if (!fence_current(preflight)) { authority_preflight_free(preflight); return RF_PAGE_AUTHORITY_FENCE_STALE; } - if (!stable_proofs_current(preflight)) - { + if (!stable_proofs_current(preflight)) { authority_preflight_free(preflight); return RF_PAGE_AUTHORITY_NO_STABLE_BASE; } @@ -302,7 +279,7 @@ rf_page_authority_batch_preflight_wait_v1( static void release_page_guards(RfPageAuthorityGuardV1 *guard) { - uint32 i; + uint32 i; for (i = guard->guard_count; i > 0; i--) rf_page_guard_release_v1(&guard->page_guards[i - 1]); @@ -310,22 +287,20 @@ release_page_guards(RfPageAuthorityGuardV1 *guard) } RfPageAuthorityVerdictV1 -rf_page_authority_batch_promote_nowait_v1( - RfPageAuthorityPreflightV1 *preflight, - ClusterRecoverySerialGuard *serial_guard, - RfPageAuthorityGuardV1 **out_guard) +rf_page_authority_batch_promote_nowait_v1(RfPageAuthorityPreflightV1 *preflight, + ClusterRecoverySerialGuard *serial_guard, + RfPageAuthorityGuardV1 **out_guard) { RfPageAuthorityGuardV1 *guard; RfPageAuthorityVerdictV1 verdict; - int16 partition_guard_index[RF_PAGE_GUARD_PARTITIONS]; - uint32 i; + int16 partition_guard_index[RF_PAGE_GUARD_PARTITIONS]; + uint32 i; if (out_guard == NULL) return RF_PAGE_AUTHORITY_INVALID_ARGUMENT; *out_guard = NULL; - if (preflight == NULL || - preflight->magic != RF_PAGE_AUTHORITY_PREFLIGHT_MAGIC || - preflight->state != RF_PAGE_AUTHORITY_STATE_PREFLIGHTED) + if (preflight == NULL || preflight->magic != RF_PAGE_AUTHORITY_PREFLIGHT_MAGIC + || preflight->state != RF_PAGE_AUTHORITY_STATE_PREFLIGHTED) return RF_PAGE_AUTHORITY_INVALID_ARGUMENT; verdict = owners_current(preflight, serial_guard); if (verdict != RF_PAGE_AUTHORITY_OK) @@ -337,31 +312,26 @@ rf_page_authority_batch_promote_nowait_v1( guard->serial_guard = serial_guard; guard->target_guard_index = preflight->target_guard_index; memset(partition_guard_index, -1, sizeof(partition_guard_index)); - for (i = 0; i < preflight->target_count; i++) - { - uint32 partition = preflight->page_preflights[i].partition; - int16 guard_index = partition_guard_index[partition]; + for (i = 0; i < preflight->target_count; i++) { + uint32 partition = preflight->page_preflights[i].partition; + int16 guard_index = partition_guard_index[partition]; - if (guard_index >= 0) - { - guard->target_guard_index[i] = (uint8) guard_index; + if (guard_index >= 0) { + guard->target_guard_index[i] = (uint8)guard_index; continue; } - if (!rf_page_guard_promote_nowait_v1( - &preflight->page_preflights[i], - &guard->page_guards[guard->guard_count])) - { + if (!rf_page_guard_promote_nowait_v1(&preflight->page_preflights[i], + &guard->page_guards[guard->guard_count])) { release_page_guards(guard); memset(guard, 0, sizeof(*guard)); return RF_PAGE_AUTHORITY_WOULD_BLOCK; } - guard->target_guard_index[i] = (uint8) guard->guard_count; - partition_guard_index[partition] = (int16) guard->guard_count; + guard->target_guard_index[i] = (uint8)guard->guard_count; + partition_guard_index[partition] = (int16)guard->guard_count; guard->guard_count++; } verdict = owners_current(preflight, serial_guard); - if (verdict != RF_PAGE_AUTHORITY_OK) - { + if (verdict != RF_PAGE_AUTHORITY_OK) { release_page_guards(guard); memset(guard, 0, sizeof(*guard)); return verdict; @@ -373,48 +343,45 @@ rf_page_authority_batch_promote_nowait_v1( } RfPageAuthorityVerdictV1 -rf_page_authority_batch_revalidate_nowait_v1( - const RfPageAuthorityGuardV1 *guard, - ClusterRecoverySerialGuard *serial_guard) +rf_page_authority_batch_revalidate_nowait_v1(const RfPageAuthorityGuardV1 *guard, + ClusterRecoverySerialGuard *serial_guard) { RfPageAuthorityVerdictV1 verdict; - uint32 i; + uint32 i; - if (guard == NULL || guard->magic != RF_PAGE_AUTHORITY_GUARD_MAGIC || - guard->state != RF_PAGE_AUTHORITY_STATE_PROMOTED || - guard->serial_guard != serial_guard || guard->preflight == NULL) + if (guard == NULL || guard->magic != RF_PAGE_AUTHORITY_GUARD_MAGIC + || guard->state != RF_PAGE_AUTHORITY_STATE_PROMOTED || guard->serial_guard != serial_guard + || guard->preflight == NULL) return RF_PAGE_AUTHORITY_INVALID_ARGUMENT; verdict = owners_current(guard->preflight, serial_guard); if (verdict != RF_PAGE_AUTHORITY_OK) return verdict; - for (i = 0; i < guard->preflight->target_count; i++) - { - uint8 guard_index = guard->target_guard_index[i]; + for (i = 0; i < guard->preflight->target_count; i++) { + uint8 guard_index = guard->target_guard_index[i]; - if (guard_index >= guard->guard_count || - !rf_page_guard_covers_nowait_v1(&guard->page_guards[guard_index], - &guard->preflight->targets[i].page_identity)) + if (guard_index >= guard->guard_count + || !rf_page_guard_covers_nowait_v1(&guard->page_guards[guard_index], + &guard->preflight->targets[i].page_identity)) return RF_PAGE_AUTHORITY_WOULD_BLOCK; } return RF_PAGE_AUTHORITY_OK; } bool -rf_page_authority_preflight_matches_target_v1( - const RfPageAuthorityPreflightV1 *preflight, - const RfPageIdentityV1 *identity, const uint8 incarnation[16]) +rf_page_authority_preflight_matches_target_v1(const RfPageAuthorityPreflightV1 *preflight, + const RfPageIdentityV1 *identity, + const uint8 incarnation[16]) { - uint32 i; + uint32 i; - if (preflight == NULL || identity == NULL || incarnation == NULL || - preflight->magic != RF_PAGE_AUTHORITY_PREFLIGHT_MAGIC || - preflight->state == RF_PAGE_AUTHORITY_STATE_RELEASED) + if (preflight == NULL || identity == NULL || incarnation == NULL + || preflight->magic != RF_PAGE_AUTHORITY_PREFLIGHT_MAGIC + || preflight->state == RF_PAGE_AUTHORITY_STATE_RELEASED) return false; for (i = 0; i < preflight->target_count; i++) - if (authority_identity_equal(&preflight->targets[i].page_identity, - identity) && - memcmp(preflight->targets[i].expected_result.segment_incarnation, - incarnation, 16) == 0) + if (authority_identity_equal(&preflight->targets[i].page_identity, identity) + && memcmp(preflight->targets[i].expected_result.segment_incarnation, incarnation, 16) + == 0) return true; return false; } @@ -427,8 +394,8 @@ rf_page_authority_guard_release_v1(RfPageAuthorityGuardV1 **guard_pointer) if (guard_pointer == NULL || *guard_pointer == NULL) return; guard = *guard_pointer; - if (guard->magic != RF_PAGE_AUTHORITY_GUARD_MAGIC || - guard->state != RF_PAGE_AUTHORITY_STATE_PROMOTED) + if (guard->magic != RF_PAGE_AUTHORITY_GUARD_MAGIC + || guard->state != RF_PAGE_AUTHORITY_STATE_PROMOTED) return; release_page_guards(guard); guard->state = RF_PAGE_AUTHORITY_STATE_RELEASED; @@ -438,16 +405,15 @@ rf_page_authority_guard_release_v1(RfPageAuthorityGuardV1 **guard_pointer) } void -rf_page_authority_preflight_destroy_v1( - RfPageAuthorityPreflightV1 **preflight_pointer) +rf_page_authority_preflight_destroy_v1(RfPageAuthorityPreflightV1 **preflight_pointer) { RfPageAuthorityPreflightV1 *preflight; if (preflight_pointer == NULL || *preflight_pointer == NULL) return; preflight = *preflight_pointer; - if (preflight->magic != RF_PAGE_AUTHORITY_PREFLIGHT_MAGIC || - preflight->state == RF_PAGE_AUTHORITY_STATE_PROMOTED) + if (preflight->magic != RF_PAGE_AUTHORITY_PREFLIGHT_MAGIC + || preflight->state == RF_PAGE_AUTHORITY_STATE_PROMOTED) return; preflight->magic = 0; authority_preflight_free(preflight); @@ -455,43 +421,39 @@ rf_page_authority_preflight_destroy_v1( } static bool -adapter_validate_identity(void *arg, const RfPageIdentityV1 *identity, - const uint8 incarnation[16]) +adapter_validate_identity(void *arg, const RfPageIdentityV1 *identity, const uint8 incarnation[16]) { - RfPageInstallAuthorityAdapterV1 *adapter = - (RfPageInstallAuthorityAdapterV1 *) arg; + RfPageInstallAuthorityAdapterV1 *adapter = (RfPageInstallAuthorityAdapterV1 *)arg; - if (adapter == NULL || - !rf_page_authority_preflight_matches_target_v1(adapter->preflight, - identity, incarnation)) + if (adapter == NULL + || !rf_page_authority_preflight_matches_target_v1(adapter->preflight, identity, + incarnation)) return false; if (adapter->guard != NULL) - return rf_page_authority_batch_revalidate_nowait_v1(adapter->guard, - adapter->serial_guard) == RF_PAGE_AUTHORITY_OK; - return owners_current(adapter->preflight, adapter->serial_guard) == - RF_PAGE_AUTHORITY_OK; + return rf_page_authority_batch_revalidate_nowait_v1(adapter->guard, adapter->serial_guard) + == RF_PAGE_AUTHORITY_OK; + return owners_current(adapter->preflight, adapter->serial_guard) == RF_PAGE_AUTHORITY_OK; } static bool adapter_promote(void *arg) { - RfPageInstallAuthorityAdapterV1 *adapter = - (RfPageInstallAuthorityAdapterV1 *) arg; + RfPageInstallAuthorityAdapterV1 *adapter = (RfPageInstallAuthorityAdapterV1 *)arg; - return adapter != NULL && adapter->guard == NULL && - rf_page_authority_batch_promote_nowait_v1(adapter->preflight, - adapter->serial_guard, &adapter->guard) == RF_PAGE_AUTHORITY_OK; + return adapter != NULL && adapter->guard == NULL + && rf_page_authority_batch_promote_nowait_v1(adapter->preflight, adapter->serial_guard, + &adapter->guard) + == RF_PAGE_AUTHORITY_OK; } static bool adapter_publish(void *arg) { - RfPageInstallAuthorityAdapterV1 *adapter = - (RfPageInstallAuthorityAdapterV1 *) arg; + RfPageInstallAuthorityAdapterV1 *adapter = (RfPageInstallAuthorityAdapterV1 *)arg; - if (adapter == NULL || adapter->proof_published || - rf_page_authority_batch_revalidate_nowait_v1(adapter->guard, - adapter->serial_guard) != RF_PAGE_AUTHORITY_OK) + if (adapter == NULL || adapter->proof_published + || rf_page_authority_batch_revalidate_nowait_v1(adapter->guard, adapter->serial_guard) + != RF_PAGE_AUTHORITY_OK) return false; adapter->proof_published = true; return true; @@ -500,8 +462,7 @@ adapter_publish(void *arg) static bool adapter_release(void *arg) { - RfPageInstallAuthorityAdapterV1 *adapter = - (RfPageInstallAuthorityAdapterV1 *) arg; + RfPageInstallAuthorityAdapterV1 *adapter = (RfPageInstallAuthorityAdapterV1 *)arg; if (adapter == NULL || adapter->guard == NULL) return false; @@ -510,14 +471,13 @@ adapter_release(void *arg) } bool -rf_page_install_authority_adapter_init_v1( - RfPageAuthorityPreflightV1 *preflight, - ClusterRecoverySerialGuard *serial_guard, - RfPageInstallAuthorityAdapterV1 *adapter) +rf_page_install_authority_adapter_init_v1(RfPageAuthorityPreflightV1 *preflight, + ClusterRecoverySerialGuard *serial_guard, + RfPageInstallAuthorityAdapterV1 *adapter) { - if (adapter == NULL || preflight == NULL || serial_guard == NULL || - preflight->magic != RF_PAGE_AUTHORITY_PREFLIGHT_MAGIC || - preflight->state != RF_PAGE_AUTHORITY_STATE_PREFLIGHTED) + if (adapter == NULL || preflight == NULL || serial_guard == NULL + || preflight->magic != RF_PAGE_AUTHORITY_PREFLIGHT_MAGIC + || preflight->state != RF_PAGE_AUTHORITY_STATE_PREFLIGHTED) return false; memset(adapter, 0, sizeof(*adapter)); adapter->preflight = preflight; diff --git a/src/backend/cluster/cluster_page_detached.c b/src/backend/cluster/cluster_page_detached.c index 9adf6d3bd14..96239805438 100644 --- a/src/backend/cluster/cluster_page_detached.c +++ b/src/backend/cluster/cluster_page_detached.c @@ -12,37 +12,39 @@ #include "cluster/cluster_page_detached.h" #include "storage/bufpage.h" -static RfPageProofDetailV1 detached_codec_preflight( - const RfDetachedPageCodecV1 *codec, const RfOpcodeRouteV1 *route, - const RfPageVersionEdgeEntryV1 *edge, const DecodedBkpBlock *block); -static RfPageProofDetailV1 detached_codec_apply(XLogReaderState *record, - uint8 block_id, uint64 result_token, const char old_page[BLCKSZ], - char new_page[BLCKSZ]); +static RfPageProofDetailV1 detached_codec_preflight(const RfDetachedPageCodecV1 *codec, + const RfOpcodeRouteV1 *route, + const RfPageVersionEdgeEntryV1 *edge, + const DecodedBkpBlock *block); +static RfPageProofDetailV1 detached_codec_apply(XLogReaderState *record, uint8 block_id, + uint64 result_token, const char old_page[BLCKSZ], + char new_page[BLCKSZ]); -#define RF_DETACHED_CODEC(codec_, rmid_) \ - {codec_, rmid_, CLUSTER_PAGE_DETACHED_INTERFACE_V1, \ - detached_codec_preflight, detached_codec_apply} +#define RF_DETACHED_CODEC(codec_, rmid_) \ + { \ + codec_, rmid_, CLUSTER_PAGE_DETACHED_INTERFACE_V1, detached_codec_preflight, \ + detached_codec_apply \ + } -static const RfDetachedPageCodecV1 detached_codecs[] = { - RF_DETACHED_CODEC(RF_ROUTE_CODEC_XLOG_FPI, RM_XLOG_ID), - RF_DETACHED_CODEC(RF_ROUTE_CODEC_HEAP2, RM_HEAP2_ID), - RF_DETACHED_CODEC(RF_ROUTE_CODEC_HEAP, RM_HEAP_ID), - RF_DETACHED_CODEC(RF_ROUTE_CODEC_BTREE, RM_BTREE_ID), - RF_DETACHED_CODEC(RF_ROUTE_CODEC_HASH, RM_HASH_ID), - RF_DETACHED_CODEC(RF_ROUTE_CODEC_GIN, RM_GIN_ID), - RF_DETACHED_CODEC(RF_ROUTE_CODEC_GIST, RM_GIST_ID), - RF_DETACHED_CODEC(RF_ROUTE_CODEC_SEQ, RM_SEQ_ID), - RF_DETACHED_CODEC(RF_ROUTE_CODEC_SPGIST, RM_SPGIST_ID), - RF_DETACHED_CODEC(RF_ROUTE_CODEC_BRIN, RM_BRIN_ID), - RF_DETACHED_CODEC(RF_ROUTE_CODEC_GENERIC, RM_GENERIC_ID) -}; +static const RfDetachedPageCodecV1 detached_codecs[] + = { RF_DETACHED_CODEC(RF_ROUTE_CODEC_XLOG_FPI, RM_XLOG_ID), + RF_DETACHED_CODEC(RF_ROUTE_CODEC_HEAP2, RM_HEAP2_ID), + RF_DETACHED_CODEC(RF_ROUTE_CODEC_HEAP, RM_HEAP_ID), + RF_DETACHED_CODEC(RF_ROUTE_CODEC_BTREE, RM_BTREE_ID), + RF_DETACHED_CODEC(RF_ROUTE_CODEC_HASH, RM_HASH_ID), + RF_DETACHED_CODEC(RF_ROUTE_CODEC_GIN, RM_GIN_ID), + RF_DETACHED_CODEC(RF_ROUTE_CODEC_GIST, RM_GIST_ID), + RF_DETACHED_CODEC(RF_ROUTE_CODEC_SEQ, RM_SEQ_ID), + RF_DETACHED_CODEC(RF_ROUTE_CODEC_SPGIST, RM_SPGIST_ID), + RF_DETACHED_CODEC(RF_ROUTE_CODEC_BRIN, RM_BRIN_ID), + RF_DETACHED_CODEC(RF_ROUTE_CODEC_GENERIC, RM_GENERIC_ID) }; #undef RF_DETACHED_CODEC const RfDetachedPageCodecV1 * rf_page_detached_codec_lookup_v1(uint8 codec_id) { - size_t i; + size_t i; for (i = 0; i < lengthof(detached_codecs); i++) if (detached_codecs[i].codec_id == codec_id) @@ -53,23 +55,20 @@ rf_page_detached_codec_lookup_v1(uint8 codec_id) static bool ordinary_fork(ForkNumber forknum) { - return forknum == MAIN_FORKNUM || forknum == VISIBILITYMAP_FORKNUM || - forknum == INIT_FORKNUM; + return forknum == MAIN_FORKNUM || forknum == VISIBILITYMAP_FORKNUM || forknum == INIT_FORKNUM; } static RfPageProofDetailV1 -detached_codec_preflight(const RfDetachedPageCodecV1 *codec, - const RfOpcodeRouteV1 *route, - const RfPageVersionEdgeEntryV1 *edge, - const DecodedBkpBlock *block) +detached_codec_preflight(const RfDetachedPageCodecV1 *codec, const RfOpcodeRouteV1 *route, + const RfPageVersionEdgeEntryV1 *edge, const DecodedBkpBlock *block) { - if (codec == NULL || route == NULL || edge == NULL || block == NULL || - route->record_owner != RF_ROUTE_OWNER_PAGE_CODEC || - route->codec_id != codec->codec_id || route->rmid != codec->rmid || - edge->page_class != RF_PAGE_CLASS_ORDINARY || !block->in_use) + if (codec == NULL || route == NULL || edge == NULL || block == NULL + || route->record_owner != RF_ROUTE_OWNER_PAGE_CODEC || route->codec_id != codec->codec_id + || route->rmid != codec->rmid || edge->page_class != RF_PAGE_CLASS_ORDINARY + || !block->in_use) return RF_PAGE_PROOF_DETAIL_OPCODE_UNSUPPORTED; - if (block->has_image && block->apply_image && - (block->bkp_image == NULL || block->bimg_len == 0)) + if (block->has_image && block->apply_image + && (block->bkp_image == NULL || block->bimg_len == 0)) return RF_PAGE_PROOF_DETAIL_IMAGE_DECODE_FAILED; return RF_PAGE_PROOF_DETAIL_OK; } @@ -77,25 +76,21 @@ detached_codec_preflight(const RfDetachedPageCodecV1 *codec, static bool detached_page_layout_valid(const char page[BLCKSZ]) { - const PageHeader header = (const PageHeader) page; + const PageHeader header = (const PageHeader)page; - return !PageIsNew((Page) page) && - header->pd_lower >= SizeOfPageHeaderData && - header->pd_lower <= header->pd_upper && - header->pd_upper <= header->pd_special && - header->pd_special <= BLCKSZ; + return !PageIsNew((Page)page) && header->pd_lower >= SizeOfPageHeaderData + && header->pd_lower <= header->pd_upper && header->pd_upper <= header->pd_special + && header->pd_special <= BLCKSZ; } static RfPageProofDetailV1 -detached_codec_apply(XLogReaderState *record, uint8 block_id, - uint64 result_token, const char old_page[BLCKSZ], - char new_page[BLCKSZ]) +detached_codec_apply(XLogReaderState *record, uint8 block_id, uint64 result_token, + const char old_page[BLCKSZ], char new_page[BLCKSZ]) { PGAlignedBlock scratch; ClusterBlkApplyResult result; - if (record == NULL || old_page == NULL || new_page == NULL || - result_token == 0) + if (record == NULL || old_page == NULL || new_page == NULL || result_token == 0) return RF_PAGE_PROOF_DETAIL_INVALID_ARGUMENT; memcpy(scratch.data, old_page, BLCKSZ); result = cluster_block_apply_one(record, block_id, scratch.data); @@ -105,16 +100,14 @@ detached_codec_apply(XLogReaderState *record, uint8 block_id, return RF_PAGE_PROOF_DETAIL_IMAGE_DECODE_FAILED; if (!detached_page_layout_valid(scratch.data)) return RF_PAGE_PROOF_DETAIL_IMAGE_INTEGRITY_FAILED; - ((PageHeader) scratch.data)->pd_block_scn = (SCN) result_token; + ((PageHeader)scratch.data)->pd_block_scn = (SCN)result_token; memcpy(new_page, scratch.data, BLCKSZ); return RF_PAGE_PROOF_DETAIL_OK; } static RfPageProofDetailV1 -preflight_external_owner(const RfDetachedOwnerOpsV1 *owner_ops, - RfDetachedOwnerPreflightV1 callback, - const RfOpcodeRouteV1 *route, - const RfPageVersionEdgeEntryV1 *edge, +preflight_external_owner(const RfDetachedOwnerOpsV1 *owner_ops, RfDetachedOwnerPreflightV1 callback, + const RfOpcodeRouteV1 *route, const RfPageVersionEdgeEntryV1 *edge, const DecodedBkpBlock *block) { if (owner_ops == NULL || callback == NULL) @@ -123,26 +116,23 @@ preflight_external_owner(const RfDetachedOwnerOpsV1 *owner_ops, } static void -set_component_versions(RfDetachedComponentPlanV1 *component, - const RfPageVersionEdgeEntryV1 *edge, +set_component_versions(RfDetachedComponentPlanV1 *component, const RfPageVersionEdgeEntryV1 *edge, uint64 result_token) { component->before = edge->before; - memcpy(component->result.segment_incarnation, - edge->result_incarnation, 16); + memcpy(component->result.segment_incarnation, edge->result_incarnation, 16); component->result.mutation_token = result_token; } RfPageProofDetailV1 rf_page_detached_preflight_v1(XLogReaderState *record, bool space_active, - const RfDetachedOwnerOpsV1 *owner_ops, - RfDetachedRecordPlanV1 *plan) + const RfDetachedOwnerOpsV1 *owner_ops, RfDetachedRecordPlanV1 *plan) { DecodedXLogRecord *decoded; RfDetachedRecordPlanV1 candidate; RfOpcodeRouteLookupResultV1 lookup; - uint32 block_count = 0; - uint32 i; + uint32 block_count = 0; + uint32 i; if (record == NULL || record->record == NULL || plan == NULL) return RF_PAGE_PROOF_DETAIL_INVALID_ARGUMENT; @@ -150,26 +140,24 @@ rf_page_detached_preflight_v1(XLogReaderState *record, bool space_active, if (decoded->max_block_id > XLR_MAX_BLOCK_ID) return RF_PAGE_PROOF_DETAIL_COMPONENT_INCOMPLETE; if (decoded->max_block_id >= 0) - for (i = 0; i <= (uint32) decoded->max_block_id; i++) + for (i = 0; i <= (uint32)decoded->max_block_id; i++) if (decoded->blocks[i].in_use) block_count++; memset(&candidate, 0, sizeof(candidate)); - lookup = rf_opcode_route_lookup_v1(decoded->header.xl_rmid, - decoded->header.xl_info, block_count != 0, space_active, - &candidate.route); + lookup = rf_opcode_route_lookup_v1(decoded->header.xl_rmid, decoded->header.xl_info, + block_count != 0, space_active, &candidate.route); if (lookup != RF_OPCODE_ROUTE_OK) return RF_PAGE_PROOF_DETAIL_OPCODE_UNSUPPORTED; candidate.source_record = record; - if (candidate.route.record_owner != RF_ROUTE_OWNER_PAGE_CODEC) - { + if (candidate.route.record_owner != RF_ROUTE_OWNER_PAGE_CODEC) { RfPageProofDetailV1 detail; if (decoded->has_page_version_edge) return RF_PAGE_PROOF_DETAIL_COMPONENT_INCOMPLETE; - detail = preflight_external_owner(owner_ops, - owner_ops != NULL ? owner_ops->preflight_side_record : NULL, + detail = preflight_external_owner( + owner_ops, owner_ops != NULL ? owner_ops->preflight_side_record : NULL, &candidate.route, NULL, NULL); if (detail != RF_PAGE_PROOF_DETAIL_OK) return detail; @@ -178,18 +166,16 @@ rf_page_detached_preflight_v1(XLogReaderState *record, bool space_active, return RF_PAGE_PROOF_DETAIL_OK; } - if (!decoded->has_page_version_edge || block_count == 0 || - decoded->page_version_edge.entry_count != block_count || - block_count > RF_PAGE_STABLE_MAX_COMPONENTS || - decoded->page_version_edge.result_token == 0) + if (!decoded->has_page_version_edge || block_count == 0 + || decoded->page_version_edge.entry_count != block_count + || block_count > RF_PAGE_STABLE_MAX_COMPONENTS + || decoded->page_version_edge.result_token == 0) return RF_PAGE_PROOF_DETAIL_COMPONENT_INCOMPLETE; candidate.result_token = decoded->page_version_edge.result_token; candidate.component_count = block_count; - for (i = 0; i < block_count; i++) - { - const RfPageVersionEdgeEntryV1 *edge = - &decoded->page_version_edge.entries[i]; + for (i = 0; i < block_count; i++) { + const RfPageVersionEdgeEntryV1 *edge = &decoded->page_version_edge.entries[i]; const DecodedBkpBlock *block; RfDetachedComponentPlanV1 *component = &candidate.components[i]; RfPageProofDetailV1 detail; @@ -197,8 +183,7 @@ rf_page_detached_preflight_v1(XLogReaderState *record, bool space_active, if (edge->block_id > decoded->max_block_id) return RF_PAGE_PROOF_DETAIL_COMPONENT_INCOMPLETE; block = &decoded->blocks[edge->block_id]; - if (!block->in_use || edge->component_ordinal != - block->component_ordinal) + if (!block->in_use || edge->component_ordinal != block->component_ordinal) return RF_PAGE_PROOF_DETAIL_COMPONENT_INCOMPLETE; component->block_id = edge->block_id; component->page_class = edge->page_class; @@ -208,54 +193,47 @@ rf_page_detached_preflight_v1(XLogReaderState *record, bool space_active, component->result_kind = edge->result_kind; set_component_versions(component, edge, candidate.result_token); - switch (edge->page_class) - { - case RF_PAGE_CLASS_ORDINARY: - { - const RfDetachedPageCodecV1 *codec; + switch (edge->page_class) { + case RF_PAGE_CLASS_ORDINARY: { + const RfDetachedPageCodecV1 *codec; - if (!ordinary_fork(block->forknum) || - !rf_page_version_present_v1(&component->result)) - return RF_PAGE_PROOF_DETAIL_CLASS_UNKNOWN; - codec = rf_page_detached_codec_lookup_v1( - candidate.route.codec_id); - if (codec == NULL) - return RF_PAGE_PROOF_DETAIL_OPCODE_UNSUPPORTED; - detail = codec->preflight(codec, &candidate.route, edge, - block); - if (detail != RF_PAGE_PROOF_DETAIL_OK) - return detail; - component->owner = RF_DETACHED_COMPONENT_PAGE_CODEC; - component->codec_id = codec->codec_id; - break; - } - case RF_PAGE_CLASS_REBUILDABLE_FSM: - if (block->forknum != FSM_FORKNUM) - return RF_PAGE_PROOF_DETAIL_CLASS_UNKNOWN; - detail = preflight_external_owner(owner_ops, - owner_ops != NULL ? - owner_ops->preflight_rebuildable_component : NULL, - &candidate.route, edge, block); - if (detail != RF_PAGE_PROOF_DETAIL_OK) - return detail; - component->owner = RF_DETACHED_COMPONENT_REBUILDABLE; - break; - case RF_PAGE_CLASS_ROUTED_SPACE: - if (!space_active || block->forknum != (ForkNumber) 4) - return RF_PAGE_PROOF_DETAIL_OPCODE_UNSUPPORTED; - /* FALLTHROUGH */ - case RF_PAGE_CLASS_ROUTED_HEADER: - case RF_PAGE_CLASS_ROUTED_SIDE: - detail = preflight_external_owner(owner_ops, - owner_ops != NULL ? - owner_ops->preflight_side_component : NULL, - &candidate.route, edge, block); - if (detail != RF_PAGE_PROOF_DETAIL_OK) - return detail; - component->owner = RF_DETACHED_COMPONENT_SIDE_TYPED; - break; - default: + if (!ordinary_fork(block->forknum) || !rf_page_version_present_v1(&component->result)) + return RF_PAGE_PROOF_DETAIL_CLASS_UNKNOWN; + codec = rf_page_detached_codec_lookup_v1(candidate.route.codec_id); + if (codec == NULL) + return RF_PAGE_PROOF_DETAIL_OPCODE_UNSUPPORTED; + detail = codec->preflight(codec, &candidate.route, edge, block); + if (detail != RF_PAGE_PROOF_DETAIL_OK) + return detail; + component->owner = RF_DETACHED_COMPONENT_PAGE_CODEC; + component->codec_id = codec->codec_id; + break; + } + case RF_PAGE_CLASS_REBUILDABLE_FSM: + if (block->forknum != FSM_FORKNUM) return RF_PAGE_PROOF_DETAIL_CLASS_UNKNOWN; + detail = preflight_external_owner( + owner_ops, owner_ops != NULL ? owner_ops->preflight_rebuildable_component : NULL, + &candidate.route, edge, block); + if (detail != RF_PAGE_PROOF_DETAIL_OK) + return detail; + component->owner = RF_DETACHED_COMPONENT_REBUILDABLE; + break; + case RF_PAGE_CLASS_ROUTED_SPACE: + if (!space_active || block->forknum != (ForkNumber)4) + return RF_PAGE_PROOF_DETAIL_OPCODE_UNSUPPORTED; + /* FALLTHROUGH */ + case RF_PAGE_CLASS_ROUTED_HEADER: + case RF_PAGE_CLASS_ROUTED_SIDE: + detail = preflight_external_owner( + owner_ops, owner_ops != NULL ? owner_ops->preflight_side_component : NULL, + &candidate.route, edge, block); + if (detail != RF_PAGE_PROOF_DETAIL_OK) + return detail; + component->owner = RF_DETACHED_COMPONENT_SIDE_TYPED; + break; + default: + return RF_PAGE_PROOF_DETAIL_CLASS_UNKNOWN; } } @@ -265,30 +243,25 @@ rf_page_detached_preflight_v1(XLogReaderState *record, bool space_active, } RfPageProofDetailV1 -rf_page_detached_apply_v1(const RfDetachedRecordPlanV1 *plan, - uint32 component_index, - const char old_page[BLCKSZ], - char new_page[BLCKSZ]) +rf_page_detached_apply_v1(const RfDetachedRecordPlanV1 *plan, uint32 component_index, + const char old_page[BLCKSZ], char new_page[BLCKSZ]) { const RfDetachedComponentPlanV1 *component; const RfDetachedPageCodecV1 *codec; - if (plan == NULL || !plan->preflight_complete || - plan->source_record == NULL || - component_index >= plan->component_count || old_page == NULL || - new_page == NULL) + if (plan == NULL || !plan->preflight_complete || plan->source_record == NULL + || component_index >= plan->component_count || old_page == NULL || new_page == NULL) return RF_PAGE_PROOF_DETAIL_INVALID_ARGUMENT; component = &plan->components[component_index]; - if (component->owner != RF_DETACHED_COMPONENT_PAGE_CODEC || - component->page_class != RF_PAGE_CLASS_ORDINARY || - component->result_kind != RF_PAGE_STATE_PRESENT || - !rf_page_version_present_v1(&component->result) || - component->result.mutation_token != plan->result_token) + if (component->owner != RF_DETACHED_COMPONENT_PAGE_CODEC + || component->page_class != RF_PAGE_CLASS_ORDINARY + || component->result_kind != RF_PAGE_STATE_PRESENT + || !rf_page_version_present_v1(&component->result) + || component->result.mutation_token != plan->result_token) return RF_PAGE_PROOF_DETAIL_CLASS_UNKNOWN; codec = rf_page_detached_codec_lookup_v1(component->codec_id); - if (codec == NULL || codec->codec_id != plan->route.codec_id || - codec->rmid != plan->route.rmid) + if (codec == NULL || codec->codec_id != plan->route.codec_id || codec->rmid != plan->route.rmid) return RF_PAGE_PROOF_DETAIL_OPCODE_UNSUPPORTED; - return codec->apply(plan->source_record, component->block_id, - plan->result_token, old_page, new_page); + return codec->apply(plan->source_record, component->block_id, plan->result_token, old_page, + new_page); } diff --git a/src/backend/cluster/cluster_page_guard.c b/src/backend/cluster/cluster_page_guard.c index 15eefd07e61..cc48d692cee 100644 --- a/src/backend/cluster/cluster_page_guard.c +++ b/src/backend/cluster/cluster_page_guard.c @@ -25,8 +25,8 @@ static bool page_guard_locks[RF_PAGE_GUARD_PARTITIONS]; static bool bytes_nonzero(const uint8 *bytes, Size length) { - uint8 value = 0; - Size i; + uint8 value = 0; + Size i; for (i = 0; i < length; i++) value |= bytes[i]; @@ -36,34 +36,30 @@ bytes_nonzero(const uint8 *bytes, Size length) static bool page_identity_valid(const RfPageIdentityV1 *identity) { - return identity != NULL && identity->system_identifier != 0 && - bytes_nonzero(identity->storage_uuid, sizeof(identity->storage_uuid)) && - identity->locator.spcOid != InvalidOid && - identity->locator.dbOid != InvalidOid && - identity->locator.relNumber != InvalidRelFileNumber && - identity->blockno != InvalidBlockNumber && identity->reserved_zero == 0; + return identity != NULL && identity->system_identifier != 0 + && bytes_nonzero(identity->storage_uuid, sizeof(identity->storage_uuid)) + && identity->locator.spcOid != InvalidOid && identity->locator.dbOid != InvalidOid + && identity->locator.relNumber != InvalidRelFileNumber + && identity->blockno != InvalidBlockNumber && identity->reserved_zero == 0; } static bool -page_identity_equal(const RfPageIdentityV1 *left, - const RfPageIdentityV1 *right) +page_identity_equal(const RfPageIdentityV1 *left, const RfPageIdentityV1 *right) { - return left != NULL && right != NULL && - left->system_identifier == right->system_identifier && - memcmp(left->storage_uuid, right->storage_uuid, 16) == 0 && - RelFileLocatorEquals(left->locator, right->locator) && - left->forknum == right->forknum && left->blockno == right->blockno && - left->reserved_zero == 0 && right->reserved_zero == 0; + return left != NULL && right != NULL && left->system_identifier == right->system_identifier + && memcmp(left->storage_uuid, right->storage_uuid, 16) == 0 + && RelFileLocatorEquals(left->locator, right->locator) && left->forknum == right->forknum + && left->blockno == right->blockno && left->reserved_zero == 0 + && right->reserved_zero == 0; } static uint64 fingerprint_bytes(uint64 hash, const void *bytes, Size length) { - const uint8 *input = (const uint8 *) bytes; - Size i; + const uint8 *input = (const uint8 *)bytes; + Size i; - for (i = 0; i < length; i++) - { + for (i = 0; i < length; i++) { hash ^= input[i]; hash *= UINT64CONST(1099511628211); } @@ -73,22 +69,17 @@ fingerprint_bytes(uint64 hash, const void *bytes, Size length) static uint64 page_identity_fingerprint(const RfPageIdentityV1 *identity) { - uint64 hash = UINT64CONST(1469598103934665603); + uint64 hash = UINT64CONST(1469598103934665603); hash = fingerprint_bytes(hash, &identity->system_identifier, - sizeof(identity->system_identifier)); - hash = fingerprint_bytes(hash, identity->storage_uuid, - sizeof(identity->storage_uuid)); - hash = fingerprint_bytes(hash, &identity->locator.spcOid, - sizeof(identity->locator.spcOid)); - hash = fingerprint_bytes(hash, &identity->locator.dbOid, - sizeof(identity->locator.dbOid)); + sizeof(identity->system_identifier)); + hash = fingerprint_bytes(hash, identity->storage_uuid, sizeof(identity->storage_uuid)); + hash = fingerprint_bytes(hash, &identity->locator.spcOid, sizeof(identity->locator.spcOid)); + hash = fingerprint_bytes(hash, &identity->locator.dbOid, sizeof(identity->locator.dbOid)); hash = fingerprint_bytes(hash, &identity->locator.relNumber, - sizeof(identity->locator.relNumber)); - hash = fingerprint_bytes(hash, &identity->forknum, - sizeof(identity->forknum)); - hash = fingerprint_bytes(hash, &identity->blockno, - sizeof(identity->blockno)); + sizeof(identity->locator.relNumber)); + hash = fingerprint_bytes(hash, &identity->forknum, sizeof(identity->forknum)); + hash = fingerprint_bytes(hash, &identity->blockno, sizeof(identity->blockno)); return hash == 0 ? UINT64CONST(1) : hash; } @@ -96,8 +87,7 @@ void rf_page_guard_request_lwlocks_v1(void) { #ifndef USE_CLUSTER_UNIT - RequestNamedLWLockTranche(RF_PAGE_GUARD_TRANCHE, - RF_PAGE_GUARD_PARTITIONS); + RequestNamedLWLockTranche(RF_PAGE_GUARD_TRANCHE, RF_PAGE_GUARD_PARTITIONS); #endif } @@ -112,10 +102,9 @@ rf_page_guard_shmem_init_v1(void) } bool -rf_page_guard_preflight_v1(const RfPageIdentityV1 *identity, - RfPageGuardPreflightV1 *preflight) +rf_page_guard_preflight_v1(const RfPageIdentityV1 *identity, RfPageGuardPreflightV1 *preflight) { - uint64 fingerprint; + uint64 fingerprint; if (preflight == NULL) return false; @@ -125,33 +114,27 @@ rf_page_guard_preflight_v1(const RfPageIdentityV1 *identity, fingerprint = page_identity_fingerprint(identity); preflight->page_identity = *identity; preflight->identity_fingerprint = fingerprint; - preflight->partition = (uint32) (fingerprint & - (RF_PAGE_GUARD_PARTITIONS - 1)); + preflight->partition = (uint32)(fingerprint & (RF_PAGE_GUARD_PARTITIONS - 1)); preflight->state = RF_PAGE_GUARD_PREFLIGHTED; return true; } bool -rf_page_guard_promote_nowait_v1(const RfPageGuardPreflightV1 *preflight, - RfPageGuardV1 *guard) +rf_page_guard_promote_nowait_v1(const RfPageGuardPreflightV1 *preflight, RfPageGuardV1 *guard) { - uint64 fingerprint; + uint64 fingerprint; - if (preflight == NULL || guard == NULL || - preflight->state != RF_PAGE_GUARD_PREFLIGHTED || - guard->state != RF_PAGE_GUARD_EMPTY || - !page_identity_valid(&preflight->page_identity)) + if (preflight == NULL || guard == NULL || preflight->state != RF_PAGE_GUARD_PREFLIGHTED + || guard->state != RF_PAGE_GUARD_EMPTY || !page_identity_valid(&preflight->page_identity)) return false; fingerprint = page_identity_fingerprint(&preflight->page_identity); - if (fingerprint != preflight->identity_fingerprint || - preflight->partition >= RF_PAGE_GUARD_PARTITIONS || - preflight->partition != (uint32) (fingerprint & - (RF_PAGE_GUARD_PARTITIONS - 1))) + if (fingerprint != preflight->identity_fingerprint + || preflight->partition >= RF_PAGE_GUARD_PARTITIONS + || preflight->partition != (uint32)(fingerprint & (RF_PAGE_GUARD_PARTITIONS - 1))) return false; #ifndef USE_CLUSTER_UNIT - if (page_guard_locks == NULL || - !LWLockConditionalAcquire(&page_guard_locks[preflight->partition].lock, - LW_EXCLUSIVE)) + if (page_guard_locks == NULL + || !LWLockConditionalAcquire(&page_guard_locks[preflight->partition].lock, LW_EXCLUSIVE)) return false; #else if (page_guard_locks[preflight->partition]) @@ -171,41 +154,35 @@ rf_page_guard_promote_nowait_v1(const RfPageGuardPreflightV1 *preflight, } bool -rf_page_guard_revalidate_nowait_v1(const RfPageGuardV1 *guard, - const RfPageIdentityV1 *identity) +rf_page_guard_revalidate_nowait_v1(const RfPageGuardV1 *guard, const RfPageIdentityV1 *identity) { - if (guard == NULL || guard->state != RF_PAGE_GUARD_PROMOTED || - guard->partition >= RF_PAGE_GUARD_PARTITIONS || - !page_identity_equal(&guard->page_identity, identity) || - guard->identity_fingerprint != page_identity_fingerprint(identity)) + if (guard == NULL || guard->state != RF_PAGE_GUARD_PROMOTED + || guard->partition >= RF_PAGE_GUARD_PARTITIONS + || !page_identity_equal(&guard->page_identity, identity) + || guard->identity_fingerprint != page_identity_fingerprint(identity)) return false; #ifndef USE_CLUSTER_UNIT - return page_guard_locks != NULL && guard->owner_pid == MyProcPid && - LWLockHeldByMeInMode(&page_guard_locks[guard->partition].lock, - LW_EXCLUSIVE); + return page_guard_locks != NULL && guard->owner_pid == MyProcPid + && LWLockHeldByMeInMode(&page_guard_locks[guard->partition].lock, LW_EXCLUSIVE); #else return guard->owner_pid == 1 && page_guard_locks[guard->partition]; #endif } bool -rf_page_guard_covers_nowait_v1(const RfPageGuardV1 *guard, - const RfPageIdentityV1 *identity) +rf_page_guard_covers_nowait_v1(const RfPageGuardV1 *guard, const RfPageIdentityV1 *identity) { - uint64 fingerprint; + uint64 fingerprint; - if (guard == NULL || guard->state != RF_PAGE_GUARD_PROMOTED || - guard->partition >= RF_PAGE_GUARD_PARTITIONS || - !page_identity_valid(identity)) + if (guard == NULL || guard->state != RF_PAGE_GUARD_PROMOTED + || guard->partition >= RF_PAGE_GUARD_PARTITIONS || !page_identity_valid(identity)) return false; fingerprint = page_identity_fingerprint(identity); - if (guard->partition != (uint32) (fingerprint & - (RF_PAGE_GUARD_PARTITIONS - 1))) + if (guard->partition != (uint32)(fingerprint & (RF_PAGE_GUARD_PARTITIONS - 1))) return false; #ifndef USE_CLUSTER_UNIT - return page_guard_locks != NULL && guard->owner_pid == MyProcPid && - LWLockHeldByMeInMode(&page_guard_locks[guard->partition].lock, - LW_EXCLUSIVE); + return page_guard_locks != NULL && guard->owner_pid == MyProcPid + && LWLockHeldByMeInMode(&page_guard_locks[guard->partition].lock, LW_EXCLUSIVE); #else return guard->owner_pid == 1 && page_guard_locks[guard->partition]; #endif @@ -214,13 +191,12 @@ rf_page_guard_covers_nowait_v1(const RfPageGuardV1 *guard, void rf_page_guard_release_v1(RfPageGuardV1 *guard) { - if (guard == NULL || guard->state != RF_PAGE_GUARD_PROMOTED || - guard->partition >= RF_PAGE_GUARD_PARTITIONS) + if (guard == NULL || guard->state != RF_PAGE_GUARD_PROMOTED + || guard->partition >= RF_PAGE_GUARD_PARTITIONS) return; #ifndef USE_CLUSTER_UNIT - if (page_guard_locks != NULL && guard->owner_pid == MyProcPid && - LWLockHeldByMeInMode(&page_guard_locks[guard->partition].lock, - LW_EXCLUSIVE)) + if (page_guard_locks != NULL && guard->owner_pid == MyProcPid + && LWLockHeldByMeInMode(&page_guard_locks[guard->partition].lock, LW_EXCLUSIVE)) LWLockRelease(&page_guard_locks[guard->partition].lock); #else page_guard_locks[guard->partition] = false; diff --git a/src/backend/cluster/cluster_page_handoff.c b/src/backend/cluster/cluster_page_handoff.c index bc114b7ff3c..1211e4bb59c 100644 --- a/src/backend/cluster/cluster_page_handoff.c +++ b/src/backend/cluster/cluster_page_handoff.c @@ -48,9 +48,9 @@ cluster_page_handoff_ready(const ClusterPageHandoffInput *in) * provides the torn target's stable base (§7.4 last sentence), so * retention_pinned alone cannot make this true. */ - return p->contributor_coverage && p->durability_barrier_ok - && p->post_read_ok && p->authority_revalidated - && in->side_proof_ok && in->retention_pinned && in->consumers_zero; + return p->contributor_coverage && p->durability_barrier_ok && p->post_read_ok + && p->authority_revalidated && in->side_proof_ok && in->retention_pinned + && in->consumers_zero; } bool diff --git a/src/backend/cluster/cluster_page_install.c b/src/backend/cluster/cluster_page_install.c index 34cdfdb77ac..e38094c158e 100644 --- a/src/backend/cluster/cluster_page_install.c +++ b/src/backend/cluster/cluster_page_install.c @@ -27,9 +27,9 @@ static bool page_all_zero(const char page[BLCKSZ]) { - const uint8 *bytes = (const uint8 *) page; - uint8 value = 0; - int i; + const uint8 *bytes = (const uint8 *)page; + uint8 value = 0; + int i; for (i = 0; i < BLCKSZ; i++) value |= bytes[i]; @@ -39,15 +39,12 @@ page_all_zero(const char page[BLCKSZ]) static bool page_layout_valid(const char page[BLCKSZ]) { - const PageHeader header = (const PageHeader) page; - - return !PageIsNew((Page) page) && - PageGetPageSize((Page) page) == BLCKSZ && - PageGetPageLayoutVersion((Page) page) == PG_PAGE_LAYOUT_VERSION && - header->pd_lower >= SizeOfPageHeaderData && - header->pd_lower <= header->pd_upper && - header->pd_upper <= header->pd_special && - header->pd_special <= BLCKSZ; + const PageHeader header = (const PageHeader)page; + + return !PageIsNew((Page)page) && PageGetPageSize((Page)page) == BLCKSZ + && PageGetPageLayoutVersion((Page)page) == PG_PAGE_LAYOUT_VERSION + && header->pd_lower >= SizeOfPageHeaderData && header->pd_lower <= header->pd_upper + && header->pd_upper <= header->pd_special && header->pd_special <= BLCKSZ; } static bool @@ -62,66 +59,63 @@ static bool component_versions_valid(const RfPageStorageInstallComponentV1 *component) { static const uint8 zero_reserved[7]; - bool ordinary_fork; - - ordinary_fork = component->page_identity.forknum == MAIN_FORKNUM || - component->page_identity.forknum == VISIBILITYMAP_FORKNUM || - component->page_identity.forknum == INIT_FORKNUM; - if (!rf_page_identity_valid_v1(&component->page_identity) || - !rf_page_version_present_v1(&component->expected_result) || - component->canonical_page == NULL || !ordinary_fork || - memcmp(component->reserved_zero, zero_reserved, - sizeof(zero_reserved)) != 0) + bool ordinary_fork; + + ordinary_fork = component->page_identity.forknum == MAIN_FORKNUM + || component->page_identity.forknum == VISIBILITYMAP_FORKNUM + || component->page_identity.forknum == INIT_FORKNUM; + if (!rf_page_identity_valid_v1(&component->page_identity) + || !rf_page_version_present_v1(&component->expected_result) + || component->canonical_page == NULL || !ordinary_fork + || memcmp(component->reserved_zero, zero_reserved, sizeof(zero_reserved)) != 0) + return false; + switch (component->before_kind) { + case RF_PAGE_STATE_PRESENT: + return rf_page_version_present_v1(&component->expected_before) + && memcmp(component->expected_before.segment_incarnation, + component->expected_result.segment_incarnation, 16) + == 0; + case RF_PAGE_STATE_UNFORMATTED: + return component->expected_before.mutation_token == 0 + && memcmp(component->expected_before.segment_incarnation, + component->expected_result.segment_incarnation, 16) + == 0; + case RF_PAGE_STATE_ABSENT: + return version_zero(&component->expected_before); + default: return false; - switch (component->before_kind) - { - case RF_PAGE_STATE_PRESENT: - return rf_page_version_present_v1(&component->expected_before) && - memcmp(component->expected_before.segment_incarnation, - component->expected_result.segment_incarnation, 16) == 0; - case RF_PAGE_STATE_UNFORMATTED: - return component->expected_before.mutation_token == 0 && - memcmp(component->expected_before.segment_incarnation, - component->expected_result.segment_incarnation, 16) == 0; - case RF_PAGE_STATE_ABSENT: - return version_zero(&component->expected_before); - default: - return false; } } static bool -page_checksum_valid(const RfPageInstallStorageOpsV1 *storage, - const RfPageIdentityV1 *identity, +page_checksum_valid(const RfPageInstallStorageOpsV1 *storage, const RfPageIdentityV1 *identity, const char page[BLCKSZ]) { if (!storage->checksums_enabled) - return ((const PageHeader) page)->pd_checksum == 0; - return ((const PageHeader) page)->pd_checksum == - storage->checksum(storage->arg, page, identity->blockno); + return ((const PageHeader)page)->pd_checksum == 0; + return ((const PageHeader)page)->pd_checksum + == storage->checksum(storage->arg, page, identity->blockno); } static bool canonicalize_page(const RfPageInstallStorageOpsV1 *storage, - const RfPageStorageInstallComponentV1 *component, - char page[BLCKSZ]) + const RfPageStorageInstallComponentV1 *component, char page[BLCKSZ]) { - PageHeader header = (PageHeader) page; + PageHeader header = (PageHeader)page; memcpy(page, component->canonical_page, BLCKSZ); - if (page_all_zero(page) || !page_layout_valid(page) || - header->pd_block_scn != component->expected_result.mutation_token) + if (page_all_zero(page) || !page_layout_valid(page) + || header->pd_block_scn != component->expected_result.mutation_token) return false; header->pd_checksum = 0; if (storage->checksums_enabled) - header->pd_checksum = storage->checksum(storage->arg, page, - component->page_identity.blockno); + header->pd_checksum + = storage->checksum(storage->arg, page, component->page_identity.blockno); return page_checksum_valid(storage, &component->page_identity, page); } static RfPageProofDetailV1 -release_after_failure(const RfPageInstallAuthorityOpsV1 *authority, - RfPageProofDetailV1 detail) +release_after_failure(const RfPageInstallAuthorityOpsV1 *authority, RfPageProofDetailV1 detail) { if (!authority->release(authority->arg)) return RF_PAGE_PROOF_DETAIL_ORDER_VIOLATION; @@ -129,42 +123,37 @@ release_after_failure(const RfPageInstallAuthorityOpsV1 *authority, } RfPageProofDetailV1 -rf_page_storage_install_execute_v1( - const RfPageStorageInstallRequestV1 *request, - RfPageStorageInstallProofV1 *proof) +rf_page_storage_install_execute_v1(const RfPageStorageInstallRequestV1 *request, + RfPageStorageInstallProofV1 *proof) { const RfPageInstallStorageOpsV1 *storage; const RfPageInstallAuthorityOpsV1 *authority; RfPageStorageInstallProofV1 completed; - bool *write_required; - bool *extend_required; + bool *write_required; + bool *extend_required; RfPageProofDetailV1 detail = RF_PAGE_PROOF_DETAIL_INTERNAL; - uint32 i; - - if (request == NULL || proof == NULL || request->components == NULL || - request->storage == NULL || request->authority == NULL || - request->prepared_pages == NULL || request->io_pages == NULL || - request->component_count == 0 || - request->component_count > RF_PAGE_STABLE_MAX_EDGES || - request->prepared_capacity < - (Size) request->component_count * BLCKSZ || - request->io_capacity < (Size) request->component_count * BLCKSZ) + uint32 i; + + if (request == NULL || proof == NULL || request->components == NULL || request->storage == NULL + || request->authority == NULL || request->prepared_pages == NULL + || request->io_pages == NULL || request->component_count == 0 + || request->component_count > RF_PAGE_STABLE_MAX_EDGES + || request->prepared_capacity < (Size)request->component_count * BLCKSZ + || request->io_capacity < (Size)request->component_count * BLCKSZ) return RF_PAGE_PROOF_DETAIL_INVALID_ARGUMENT; storage = request->storage; authority = request->authority; - if (storage->read == NULL || storage->write == NULL || - storage->sync == NULL || storage->checksum == NULL || - authority->validate_identity == NULL || authority->promote == NULL || - authority->publish == NULL || authority->release == NULL) + if (storage->read == NULL || storage->write == NULL || storage->sync == NULL + || storage->checksum == NULL || authority->validate_identity == NULL + || authority->promote == NULL || authority->publish == NULL || authority->release == NULL) return RF_PAGE_PROOF_DETAIL_INVALID_ARGUMENT; if (!request->global_preflight_ok) return RF_PAGE_PROOF_DETAIL_COMPONENT_INCOMPLETE; - write_required = (bool *) page_install_alloc0( - (Size) request->component_count * sizeof(*write_required)); - extend_required = (bool *) page_install_alloc0( - (Size) request->component_count * sizeof(*extend_required)); - if (write_required == NULL || extend_required == NULL) - { + write_required + = (bool *)page_install_alloc0((Size)request->component_count * sizeof(*write_required)); + extend_required + = (bool *)page_install_alloc0((Size)request->component_count * sizeof(*extend_required)); + if (write_required == NULL || extend_required == NULL) { if (extend_required != NULL) page_install_free(extend_required); if (write_required != NULL) @@ -172,22 +161,17 @@ rf_page_storage_install_execute_v1( return RF_PAGE_PROOF_DETAIL_OOM; } - for (i = 0; i < request->component_count; i++) - { - const RfPageStorageInstallComponentV1 *component = - &request->components[i]; - char *prepared = request->prepared_pages + (Size) i * BLCKSZ; - - if (!component_versions_valid(component) || - !authority->validate_identity(authority->arg, - &component->page_identity, - component->expected_result.segment_incarnation)) - { + for (i = 0; i < request->component_count; i++) { + const RfPageStorageInstallComponentV1 *component = &request->components[i]; + char *prepared = request->prepared_pages + (Size)i * BLCKSZ; + + if (!component_versions_valid(component) + || !authority->validate_identity(authority->arg, &component->page_identity, + component->expected_result.segment_incarnation)) { detail = RF_PAGE_PROOF_DETAIL_IDENTITY_MISMATCH; goto done; } - if (!canonicalize_page(storage, component, prepared)) - { + if (!canonicalize_page(storage, component, prepared)) { detail = RF_PAGE_PROOF_DETAIL_IMAGE_INTEGRITY_FAILED; goto done; } @@ -198,35 +182,26 @@ rf_page_storage_install_execute_v1( * certified target set. Keep all argument/image work before promotion, * but do not touch storage until promotion succeeds. */ - if (!authority->promote(authority->arg)) - { + if (!authority->promote(authority->arg)) { detail = RF_PAGE_PROOF_DETAIL_WOULD_BLOCK; goto done; } - for (i = 0; i < request->component_count; i++) - { - const RfPageStorageInstallComponentV1 *component = - &request->components[i]; - char *prepared = request->prepared_pages + (Size) i * BLCKSZ; - char *target = request->io_pages + (Size) i * BLCKSZ; - bool exists; - bool torn; - uint64 token; - - if (!storage->read(storage->arg, i, &component->page_identity, - target, &exists)) - { - detail = release_after_failure(authority, - RF_PAGE_PROOF_DETAIL_SOURCE_GAP); + for (i = 0; i < request->component_count; i++) { + const RfPageStorageInstallComponentV1 *component = &request->components[i]; + const char *prepared = request->prepared_pages + (Size)i * BLCKSZ; + char *target = request->io_pages + (Size)i * BLCKSZ; + bool exists; + bool torn; + uint64 token; + + if (!storage->read(storage->arg, i, &component->page_identity, target, &exists)) { + detail = release_after_failure(authority, RF_PAGE_PROOF_DETAIL_SOURCE_GAP); goto done; } - if (!exists) - { - if (component->before_kind != RF_PAGE_STATE_ABSENT) - { - detail = release_after_failure(authority, - RF_PAGE_PROOF_DETAIL_VERSION_MISMATCH); + if (!exists) { + if (component->before_kind != RF_PAGE_STATE_ABSENT) { + detail = release_after_failure(authority, RF_PAGE_PROOF_DETAIL_VERSION_MISMATCH); goto done; } write_required[i] = true; @@ -234,110 +209,81 @@ rf_page_storage_install_execute_v1( continue; } - torn = page_all_zero(target) || !page_layout_valid(target) || - !page_checksum_valid(storage, &component->page_identity, target); - if (torn) - { + torn = page_all_zero(target) || !page_layout_valid(target) + || !page_checksum_valid(storage, &component->page_identity, target); + if (torn) { write_required[i] = true; continue; } - token = ((PageHeader) target)->pd_block_scn; - if (token == component->expected_result.mutation_token) - { - if (memcmp(target, prepared, BLCKSZ) != 0) - { - detail = release_after_failure(authority, - RF_PAGE_PROOF_DETAIL_IMAGE_INTEGRITY_FAILED); + token = ((PageHeader)target)->pd_block_scn; + if (token == component->expected_result.mutation_token) { + if (memcmp(target, prepared, BLCKSZ) != 0) { + detail + = release_after_failure(authority, RF_PAGE_PROOF_DETAIL_IMAGE_INTEGRITY_FAILED); goto done; } continue; } - if (component->before_kind == RF_PAGE_STATE_PRESENT && - token == component->expected_before.mutation_token) - { + if (component->before_kind == RF_PAGE_STATE_PRESENT + && token == component->expected_before.mutation_token) { write_required[i] = true; continue; } - if (component->before_kind == RF_PAGE_STATE_UNFORMATTED && - token == 0) - { + if (component->before_kind == RF_PAGE_STATE_UNFORMATTED && token == 0) { write_required[i] = true; continue; } - detail = release_after_failure(authority, - RF_PAGE_PROOF_DETAIL_VERSION_MISMATCH); + detail = release_after_failure(authority, RF_PAGE_PROOF_DETAIL_VERSION_MISMATCH); goto done; } memset(&completed, 0, sizeof(completed)); completed.component_count = request->component_count; - for (i = 0; i < request->component_count; i++) - { - if (!write_required[i]) - { + for (i = 0; i < request->component_count; i++) { + if (!write_required[i]) { completed.result_skip_count++; continue; } - if (!storage->write(storage->arg, i, - &request->components[i].page_identity, - request->prepared_pages + (Size) i * BLCKSZ, - extend_required[i])) - { - detail = release_after_failure(authority, - RF_PAGE_PROOF_DETAIL_INTERNAL); + if (!storage->write(storage->arg, i, &request->components[i].page_identity, + request->prepared_pages + (Size)i * BLCKSZ, extend_required[i])) { + detail = release_after_failure(authority, RF_PAGE_PROOF_DETAIL_INTERNAL); goto done; } completed.write_count++; } - for (i = 0; i < request->component_count; i++) - { - if (!storage->sync(storage->arg, i, - &request->components[i].page_identity)) - { - detail = release_after_failure(authority, - RF_PAGE_PROOF_DETAIL_POSTREAD_FAILED); + for (i = 0; i < request->component_count; i++) { + if (!storage->sync(storage->arg, i, &request->components[i].page_identity)) { + detail = release_after_failure(authority, RF_PAGE_PROOF_DETAIL_POSTREAD_FAILED); goto done; } } completed.durability_complete = true; - for (i = 0; i < request->component_count; i++) - { - const RfPageStorageInstallComponentV1 *component = - &request->components[i]; - char *postread = request->io_pages + (Size) i * BLCKSZ; - const char *prepared = - request->prepared_pages + (Size) i * BLCKSZ; - bool exists; - - if (!storage->read(storage->arg, i, &component->page_identity, - postread, &exists) || !exists || page_all_zero(postread) || - !page_layout_valid(postread) || - ((PageHeader) postread)->pd_block_scn != - component->expected_result.mutation_token || - !page_checksum_valid(storage, &component->page_identity, - postread) || - !authority->validate_identity(authority->arg, - &component->page_identity, - component->expected_result.segment_incarnation) || - memcmp(postread, prepared, BLCKSZ) != 0) - { - detail = release_after_failure(authority, - RF_PAGE_PROOF_DETAIL_POSTREAD_FAILED); + for (i = 0; i < request->component_count; i++) { + const RfPageStorageInstallComponentV1 *component = &request->components[i]; + char *postread = request->io_pages + (Size)i * BLCKSZ; + const char *prepared = request->prepared_pages + (Size)i * BLCKSZ; + bool exists; + + if (!storage->read(storage->arg, i, &component->page_identity, postread, &exists) || !exists + || page_all_zero(postread) || !page_layout_valid(postread) + || ((PageHeader)postread)->pd_block_scn != component->expected_result.mutation_token + || !page_checksum_valid(storage, &component->page_identity, postread) + || !authority->validate_identity(authority->arg, &component->page_identity, + component->expected_result.segment_incarnation) + || memcmp(postread, prepared, BLCKSZ) != 0) { + detail = release_after_failure(authority, RF_PAGE_PROOF_DETAIL_POSTREAD_FAILED); goto done; } } completed.postread_complete = true; - if (!authority->publish(authority->arg)) - { - detail = release_after_failure(authority, - RF_PAGE_PROOF_DETAIL_INTERNAL); + if (!authority->publish(authority->arg)) { + detail = release_after_failure(authority, RF_PAGE_PROOF_DETAIL_INTERNAL); goto done; } completed.proof_published = true; - if (!authority->release(authority->arg)) - { + if (!authority->release(authority->arg)) { detail = RF_PAGE_PROOF_DETAIL_ORDER_VIOLATION; goto done; } @@ -353,41 +299,36 @@ rf_page_storage_install_execute_v1( #ifndef USE_CLUSTER_UNIT -struct RfPageSmgrPreopenV1 -{ +struct RfPageSmgrPreopenV1 { const RfPageStorageInstallRequestV1 *request; SMgrRelation *relations; - bool *opened; + bool *opened; }; -typedef struct RfPageSmgrAuthorityContextV1 -{ +typedef struct RfPageSmgrAuthorityContextV1 { const RfPageInstallAuthorityOpsV1 *delegate; - bool promoted; + bool promoted; } RfPageSmgrAuthorityContextV1; static SMgrRelation page_smgr_relation(RfPageSmgrPreopenV1 *context, uint32 index) { - if (context == NULL || index >= context->request->component_count || - !context->opened[index]) + if (context == NULL || index >= context->request->component_count || !context->opened[index]) return NULL; return context->relations[index]; } static bool -page_smgr_read(void *arg, uint32 index, - const RfPageIdentityV1 *identity, char page[BLCKSZ], +page_smgr_read(void *arg, uint32 index, const RfPageIdentityV1 *identity, char page[BLCKSZ], bool *exists) { - RfPageSmgrPreopenV1 *context = (RfPageSmgrPreopenV1 *) arg; + RfPageSmgrPreopenV1 *context = (RfPageSmgrPreopenV1 *)arg; SMgrRelation relation = page_smgr_relation(context, index); - ForkNumber forknum = (ForkNumber) identity->forknum; + ForkNumber forknum = (ForkNumber)identity->forknum; if (relation == NULL) return false; - *exists = smgrexists(relation, forknum) && - identity->blockno < smgrnblocks(relation, forknum); + *exists = smgrexists(relation, forknum) && identity->blockno < smgrnblocks(relation, forknum); if (*exists) smgrread(relation, forknum, identity->blockno, page); else @@ -396,13 +337,12 @@ page_smgr_read(void *arg, uint32 index, } static bool -page_smgr_write(void *arg, uint32 index, - const RfPageIdentityV1 *identity, - const char page[BLCKSZ], bool extend) +page_smgr_write(void *arg, uint32 index, const RfPageIdentityV1 *identity, const char page[BLCKSZ], + bool extend) { - RfPageSmgrPreopenV1 *context = (RfPageSmgrPreopenV1 *) arg; + RfPageSmgrPreopenV1 *context = (RfPageSmgrPreopenV1 *)arg; SMgrRelation relation = page_smgr_relation(context, index); - ForkNumber forknum = (ForkNumber) identity->forknum; + ForkNumber forknum = (ForkNumber)identity->forknum; BlockNumber nblocks; if (relation == NULL) @@ -410,14 +350,11 @@ page_smgr_write(void *arg, uint32 index, if (!smgrexists(relation, forknum)) return false; nblocks = smgrnblocks(relation, forknum); - if (extend) - { + if (extend) { if (identity->blockno != nblocks) return false; smgrextend(relation, forknum, identity->blockno, page, false); - } - else - { + } else { if (identity->blockno >= nblocks) return false; smgrwrite(relation, forknum, identity->blockno, page, false); @@ -426,52 +363,45 @@ page_smgr_write(void *arg, uint32 index, } static bool -page_smgr_sync(void *arg, uint32 index, - const RfPageIdentityV1 *identity) +page_smgr_sync(void *arg, uint32 index, const RfPageIdentityV1 *identity) { - RfPageSmgrPreopenV1 *context = (RfPageSmgrPreopenV1 *) arg; + RfPageSmgrPreopenV1 *context = (RfPageSmgrPreopenV1 *)arg; SMgrRelation relation; - uint32 i; + uint32 i; - for (i = 0; i < index; i++) - { - const RfPageIdentityV1 *prior = - &context->request->components[i].page_identity; + for (i = 0; i < index; i++) { + const RfPageIdentityV1 *prior = &context->request->components[i].page_identity; - if (RelFileLocatorEquals(prior->locator, identity->locator) && - prior->forknum == identity->forknum) + if (RelFileLocatorEquals(prior->locator, identity->locator) + && prior->forknum == identity->forknum) return true; } relation = page_smgr_relation(context, index); if (relation == NULL) return false; - smgrimmedsync(relation, (ForkNumber) identity->forknum); + smgrimmedsync(relation, (ForkNumber)identity->forknum); return true; } static uint16 -page_smgr_checksum(void *arg, const char page[BLCKSZ], - BlockNumber blockno) +page_smgr_checksum(void *arg, const char page[BLCKSZ], BlockNumber blockno) { - return pg_checksum_page((char *) page, blockno); + return pg_checksum_page((char *)page, blockno); } static bool page_smgr_authority_validate(void *arg, const RfPageIdentityV1 *identity, - const uint8 incarnation[16]) + const uint8 incarnation[16]) { - RfPageSmgrAuthorityContextV1 *context = - (RfPageSmgrAuthorityContextV1 *) arg; + RfPageSmgrAuthorityContextV1 *context = (RfPageSmgrAuthorityContextV1 *)arg; - return context->delegate->validate_identity(context->delegate->arg, - identity, incarnation); + return context->delegate->validate_identity(context->delegate->arg, identity, incarnation); } static bool page_smgr_authority_promote(void *arg) { - RfPageSmgrAuthorityContextV1 *context = - (RfPageSmgrAuthorityContextV1 *) arg; + RfPageSmgrAuthorityContextV1 *context = (RfPageSmgrAuthorityContextV1 *)arg; if (!context->delegate->promote(context->delegate->arg)) return false; @@ -482,8 +412,7 @@ page_smgr_authority_promote(void *arg) static bool page_smgr_authority_publish(void *arg) { - RfPageSmgrAuthorityContextV1 *context = - (RfPageSmgrAuthorityContextV1 *) arg; + RfPageSmgrAuthorityContextV1 *context = (RfPageSmgrAuthorityContextV1 *)arg; return context->delegate->publish(context->delegate->arg); } @@ -491,8 +420,7 @@ page_smgr_authority_publish(void *arg) static bool page_smgr_authority_release(void *arg) { - RfPageSmgrAuthorityContextV1 *context = - (RfPageSmgrAuthorityContextV1 *) arg; + RfPageSmgrAuthorityContextV1 *context = (RfPageSmgrAuthorityContextV1 *)arg; if (!context->delegate->release(context->delegate->arg)) return false; @@ -501,32 +429,25 @@ page_smgr_authority_release(void *arg) } RfPageProofDetailV1 -rf_page_storage_smgr_preopen_v1( - const RfPageStorageInstallRequestV1 *request, - RfPageSmgrPreopenV1 **out_preopen) +rf_page_storage_smgr_preopen_v1(const RfPageStorageInstallRequestV1 *request, + RfPageSmgrPreopenV1 **out_preopen) { RfPageSmgrPreopenV1 *context; - uint32 i; + uint32 i; if (out_preopen == NULL) return RF_PAGE_PROOF_DETAIL_INVALID_ARGUMENT; *out_preopen = NULL; - if (request == NULL || request->components == NULL || - request->component_count == 0 || - request->component_count > RF_PAGE_STABLE_MAX_EDGES || - request->storage != NULL) + if (request == NULL || request->components == NULL || request->component_count == 0 + || request->component_count > RF_PAGE_STABLE_MAX_EDGES || request->storage != NULL) return RF_PAGE_PROOF_DETAIL_INVALID_ARGUMENT; context = palloc0(sizeof(*context)); context->request = request; - context->relations = palloc0((Size) request->component_count * - sizeof(*context->relations)); - context->opened = palloc0((Size) request->component_count * - sizeof(*context->opened)); - for (i = 0; i < request->component_count; i++) - { - context->relations[i] = smgropen( - request->components[i].page_identity.locator, - InvalidBackendId); + context->relations = palloc0((Size)request->component_count * sizeof(*context->relations)); + context->opened = palloc0((Size)request->component_count * sizeof(*context->opened)); + for (i = 0; i < request->component_count; i++) { + context->relations[i] + = smgropen(request->components[i].page_identity.locator, InvalidBackendId); context->opened[i] = true; } *out_preopen = context; @@ -545,10 +466,9 @@ rf_page_storage_smgr_preopen_destroy_v1(RfPageSmgrPreopenV1 **preopen) } RfPageProofDetailV1 -rf_page_storage_install_smgr_preopened_v1( - const RfPageStorageInstallRequestV1 *request, - RfPageSmgrPreopenV1 *preopen, - RfPageStorageInstallProofV1 *proof) +rf_page_storage_install_smgr_preopened_v1(const RfPageStorageInstallRequestV1 *request, + RfPageSmgrPreopenV1 *preopen, + RfPageStorageInstallProofV1 *proof) { RfPageSmgrAuthorityContextV1 authority_context; RfPageInstallStorageOpsV1 storage; @@ -556,16 +476,11 @@ rf_page_storage_install_smgr_preopened_v1( RfPageStorageInstallRequestV1 smgr_request; RfPageProofDetailV1 detail = RF_PAGE_PROOF_DETAIL_INTERNAL; - if (request == NULL || request->components == NULL || - request->component_count == 0 || - request->component_count > RF_PAGE_STABLE_MAX_EDGES || - preopen == NULL || preopen->request != request || - request->storage != NULL || - request->authority == NULL || - request->authority->validate_identity == NULL || - request->authority->promote == NULL || - request->authority->publish == NULL || - request->authority->release == NULL) + if (request == NULL || request->components == NULL || request->component_count == 0 + || request->component_count > RF_PAGE_STABLE_MAX_EDGES || preopen == NULL + || preopen->request != request || request->storage != NULL || request->authority == NULL + || request->authority->validate_identity == NULL || request->authority->promote == NULL + || request->authority->publish == NULL || request->authority->release == NULL) return RF_PAGE_PROOF_DETAIL_INVALID_ARGUMENT; memset(&authority_context, 0, sizeof(authority_context)); authority_context.delegate = request->authority; @@ -592,7 +507,7 @@ rf_page_storage_install_smgr_preopened_v1( PG_CATCH(); { if (authority_context.promoted) - (void) request->authority->release(request->authority->arg); + (void)request->authority->release(request->authority->arg); PG_RE_THROW(); } PG_END_TRY(); @@ -600,9 +515,8 @@ rf_page_storage_install_smgr_preopened_v1( } RfPageProofDetailV1 -rf_page_storage_install_smgr_v1( - const RfPageStorageInstallRequestV1 *request, - RfPageStorageInstallProofV1 *proof) +rf_page_storage_install_smgr_v1(const RfPageStorageInstallRequestV1 *request, + RfPageStorageInstallProofV1 *proof) { RfPageSmgrPreopenV1 *preopen = NULL; RfPageProofDetailV1 detail; @@ -612,8 +526,7 @@ rf_page_storage_install_smgr_v1( return detail; PG_TRY(); { - detail = rf_page_storage_install_smgr_preopened_v1( - request, preopen, proof); + detail = rf_page_storage_install_smgr_preopened_v1(request, preopen, proof); } PG_CATCH(); { @@ -625,4 +538,4 @@ rf_page_storage_install_smgr_v1( return detail; } -#endif /* !USE_CLUSTER_UNIT */ +#endif /* !USE_CLUSTER_UNIT */ diff --git a/src/backend/cluster/cluster_page_online_plan.c b/src/backend/cluster/cluster_page_online_plan.c index b6a10ff5c81..75ccc7cf05a 100644 --- a/src/backend/cluster/cluster_page_online_plan.c +++ b/src/backend/cluster/cluster_page_online_plan.c @@ -17,49 +17,46 @@ #define online_free(pointer_) free((pointer_)) #else #define online_alloc0(size_) palloc0(size_) -#define online_realloc(pointer_, size_) \ +#define online_realloc(pointer_, size_) \ ((pointer_) == NULL ? palloc0(size_) : repalloc((pointer_), (size_))) #define online_free(pointer_) pfree(pointer_) #endif #define RF_PAGE_ONLINE_PLAN_MAGIC UINT32_C(0x52504f50) -typedef struct RfPageOnlineTargetV1 -{ +typedef struct RfPageOnlineTargetV1 { RfPageOnlineTargetViewV1 view; RfPagePinnedSourceV1 source; RfContributorVectorV1 contributors; RfPageStableGraphRequestV1 graph; RfContributorStreamCutV1 *cuts; RfPageStableEdgeInputV1 *edges; - uint32 edge_count; - uint32 edge_capacity; + uint32 edge_count; + uint32 edge_capacity; PGAlignedBlock canonical; } RfPageOnlineTargetV1; -struct RfPageOnlinePlanV1 -{ - uint32 magic; - bool sealed; - uint8 reserved_zero[3]; - uint64 system_identifier; - uint8 storage_uuid[16]; - uint32 participant_count; - uint32 target_count; - uint32 target_capacity; - Size memory_budget; - Size memory_used; - uint64 retention_binding_cookie; +struct RfPageOnlinePlanV1 { + uint32 magic; + bool sealed; + uint8 reserved_zero[3]; + uint64 system_identifier; + uint8 storage_uuid[16]; + uint32 participant_count; + uint32 target_count; + uint32 target_capacity; + Size memory_budget; + Size memory_used; + uint64 retention_binding_cookie; RfContributorStreamCutV1 *physical_cuts; XLogRecPtr *last_record_end; - bool *participant_seen; + bool *participant_seen; RfPageOnlineTargetV1 **targets; }; -typedef struct RfPageOnlinePendingV1 -{ +typedef struct RfPageOnlinePendingV1 { RfPageOnlineTargetV1 *target; - bool new_target; + bool new_target; RfPageStableEdgeInputV1 edge; PGAlignedBlock canonical; } RfPageOnlinePendingV1; @@ -67,8 +64,8 @@ typedef struct RfPageOnlinePendingV1 static bool bytes_nonzero(const uint8 *bytes, Size size) { - uint8 value = 0; - Size i; + uint8 value = 0; + Size i; for (i = 0; i < size; i++) value |= bytes[i]; @@ -78,26 +75,26 @@ bytes_nonzero(const uint8 *bytes, Size size) static bool page_layout_valid(const char page[BLCKSZ]) { - const PageHeader header = (const PageHeader) page; - - return !PageIsNew((Page) page) && - PageGetPageSize((Page) page) == BLCKSZ && - PageGetPageLayoutVersion((Page) page) == PG_PAGE_LAYOUT_VERSION && - header->pd_lower >= SizeOfPageHeaderData && - header->pd_lower <= header->pd_upper && - header->pd_upper <= header->pd_special && - header->pd_special <= BLCKSZ; + const PageHeader header = (const PageHeader)page; + + return !PageIsNew((Page)page) && PageGetPageSize((Page)page) == BLCKSZ + && PageGetPageLayoutVersion((Page)page) == PG_PAGE_LAYOUT_VERSION + && header->pd_lower >= SizeOfPageHeaderData && header->pd_lower <= header->pd_upper + && header->pd_upper <= header->pd_special && header->pd_special <= BLCKSZ; } static int -identity_compare(const RfPageIdentityV1 *left, - const RfPageIdentityV1 *right) +identity_compare(const RfPageIdentityV1 *left, const RfPageIdentityV1 *right) { - int cmp; - -#define CMP_FIELD(field_) \ - do { if (left->field_ < right->field_) return -1; \ - if (left->field_ > right->field_) return 1; } while (0) + int cmp; + +#define CMP_FIELD(field_) \ + do { \ + if (left->field_ < right->field_) \ + return -1; \ + if (left->field_ > right->field_) \ + return 1; \ + } while (0) CMP_FIELD(system_identifier); cmp = memcmp(left->storage_uuid, right->storage_uuid, 16); if (cmp != 0) @@ -114,54 +111,45 @@ identity_compare(const RfPageIdentityV1 *left, static int target_pointer_compare(const void *left, const void *right) { - const RfPageOnlineTargetV1 *const *left_target = - (const RfPageOnlineTargetV1 *const *) left; - const RfPageOnlineTargetV1 *const *right_target = - (const RfPageOnlineTargetV1 *const *) right; + const RfPageOnlineTargetV1 *const *left_target = (const RfPageOnlineTargetV1 *const *)left; + const RfPageOnlineTargetV1 *const *right_target = (const RfPageOnlineTargetV1 *const *)right; return identity_compare(&(*left_target)->view.page_identity, - &(*right_target)->view.page_identity); + &(*right_target)->view.page_identity); } static bool plan_reserve(RfPageOnlinePlanV1 *plan, Size additional) { - if (additional > plan->memory_budget || - plan->memory_used > plan->memory_budget - additional) + if (additional > plan->memory_budget || plan->memory_used > plan->memory_budget - additional) return false; plan->memory_used += additional; return true; } static RfPageOnlineTargetV1 * -target_create(RfPageOnlinePlanV1 *plan, - const RfPageIdentityV1 *identity) +target_create(RfPageOnlinePlanV1 *plan, const RfPageIdentityV1 *identity) { RfPageOnlineTargetV1 *target; - Size bytes = sizeof(*target) + - (Size) plan->participant_count * sizeof(*target->cuts); - uint32 i; + Size bytes = sizeof(*target) + (Size)plan->participant_count * sizeof(*target->cuts); + uint32 i; if (!plan_reserve(plan, bytes)) return NULL; - target = (RfPageOnlineTargetV1 *) online_alloc0(sizeof(*target)); + target = (RfPageOnlineTargetV1 *)online_alloc0(sizeof(*target)); if (target == NULL) return NULL; - target->cuts = (RfContributorStreamCutV1 *) online_alloc0( - (Size) plan->participant_count * sizeof(*target->cuts)); - if (target->cuts == NULL) - { + target->cuts = (RfContributorStreamCutV1 *)online_alloc0((Size)plan->participant_count + * sizeof(*target->cuts)); + if (target->cuts == NULL) { online_free(target); return NULL; } target->view.page_identity = *identity; - for (i = 0; i < plan->participant_count; i++) - { + for (i = 0; i < plan->participant_count; i++) { target->cuts[i] = plan->physical_cuts[i]; - target->cuts[i].flags = RF_CONTRIBUTOR_CUT_COMPLETE | - RF_CONTRIBUTOR_CUT_EXPLICIT_EMPTY; - target->cuts[i].scan_end_exclusive = - target->cuts[i].scan_begin_inclusive; + target->cuts[i].flags = RF_CONTRIBUTOR_CUT_COMPLETE | RF_CONTRIBUTOR_CUT_EXPLICIT_EMPTY; + target->cuts[i].scan_end_exclusive = target->cuts[i].scan_begin_inclusive; target->cuts[i].contributor_count = 0; target->cuts[i].component_count = 0; } @@ -181,14 +169,12 @@ target_destroy(RfPageOnlineTargetV1 *target) } static RfPageOnlineTargetV1 * -find_target(const RfPageOnlinePlanV1 *plan, - const RfPageIdentityV1 *identity) +find_target(const RfPageOnlinePlanV1 *plan, const RfPageIdentityV1 *identity) { - uint32 i; + uint32 i; for (i = 0; i < plan->target_count; i++) - if (rf_page_identity_equal_v1( - &plan->targets[i]->view.page_identity, identity)) + if (rf_page_identity_equal_v1(&plan->targets[i]->view.page_identity, identity)) return plan->targets[i]; return NULL; } @@ -196,18 +182,16 @@ find_target(const RfPageOnlinePlanV1 *plan, static bool ensure_target_capacity(RfPageOnlinePlanV1 *plan, uint32 additional) { - uint32 required = plan->target_count + additional; - uint32 capacity; - Size delta; - void *new_targets; + uint32 required = plan->target_count + additional; + uint32 capacity; + Size delta; + void *new_targets; if (required <= plan->target_capacity) return true; capacity = plan->target_capacity == 0 ? 8 : plan->target_capacity; - while (capacity < required) - { - if (capacity > RF_PAGE_STABLE_MAX_EDGES / 2) - { + while (capacity < required) { + if (capacity > RF_PAGE_STABLE_MAX_EDGES / 2) { capacity = RF_PAGE_STABLE_MAX_EDGES; break; } @@ -215,37 +199,31 @@ ensure_target_capacity(RfPageOnlinePlanV1 *plan, uint32 additional) } if (capacity < required) return false; - delta = (Size) (capacity - plan->target_capacity) * - sizeof(*plan->targets); + delta = (Size)(capacity - plan->target_capacity) * sizeof(*plan->targets); if (!plan_reserve(plan, delta)) return false; - new_targets = online_realloc(plan->targets, - (Size) capacity * sizeof(*plan->targets)); + new_targets = online_realloc(plan->targets, (Size)capacity * sizeof(*plan->targets)); if (new_targets == NULL) return false; - plan->targets = (RfPageOnlineTargetV1 **) new_targets; - memset(plan->targets + plan->target_capacity, 0, - delta); + plan->targets = (RfPageOnlineTargetV1 **)new_targets; + memset(plan->targets + plan->target_capacity, 0, delta); plan->target_capacity = capacity; return true; } static bool -ensure_edge_capacity(RfPageOnlinePlanV1 *plan, - RfPageOnlineTargetV1 *target, uint32 additional) +ensure_edge_capacity(RfPageOnlinePlanV1 *plan, RfPageOnlineTargetV1 *target, uint32 additional) { - uint32 required = target->edge_count + additional; - uint32 capacity; - Size delta; - void *new_edges; + uint32 required = target->edge_count + additional; + uint32 capacity; + Size delta; + void *new_edges; if (required <= target->edge_capacity) return true; capacity = target->edge_capacity == 0 ? 4 : target->edge_capacity; - while (capacity < required) - { - if (capacity > RF_PAGE_STABLE_MAX_EDGES / 2) - { + while (capacity < required) { + if (capacity > RF_PAGE_STABLE_MAX_EDGES / 2) { capacity = RF_PAGE_STABLE_MAX_EDGES; break; } @@ -253,15 +231,13 @@ ensure_edge_capacity(RfPageOnlinePlanV1 *plan, } if (capacity < required) return false; - delta = (Size) (capacity - target->edge_capacity) * - sizeof(*target->edges); + delta = (Size)(capacity - target->edge_capacity) * sizeof(*target->edges); if (!plan_reserve(plan, delta)) return false; - new_edges = online_realloc(target->edges, - (Size) capacity * sizeof(*target->edges)); + new_edges = online_realloc(target->edges, (Size)capacity * sizeof(*target->edges)); if (new_edges == NULL) return false; - target->edges = (RfPageStableEdgeInputV1 *) new_edges; + target->edges = (RfPageStableEdgeInputV1 *)new_edges; memset(target->edges + target->edge_capacity, 0, delta); target->edge_capacity = capacity; return true; @@ -271,14 +247,14 @@ static bool page_sha256(const char page[BLCKSZ], uint8 digest[32]) { pg_cryptohash_ctx *context; - bool ok; + bool ok; context = pg_cryptohash_create(PG_SHA256); if (context == NULL) return false; - ok = pg_cryptohash_init(context) >= 0 && - pg_cryptohash_update(context, (const uint8 *) page, BLCKSZ) >= 0 && - pg_cryptohash_final(context, digest, 32) >= 0; + ok = pg_cryptohash_init(context) >= 0 + && pg_cryptohash_update(context, (const uint8 *)page, BLCKSZ) >= 0 + && pg_cryptohash_final(context, digest, 32) >= 0; pg_cryptohash_free(context); return ok; } @@ -286,126 +262,110 @@ page_sha256(const char page[BLCKSZ], uint8 digest[32]) static bool anchor_flags(uint16 flags) { - return (flags & RF_PAGE_EDGE_FULL_COVERAGE) != 0 && - (flags & (RF_PAGE_EDGE_FULL_IMAGE_APPLY | - RF_PAGE_EDGE_WILL_INIT)) != 0; + return (flags & RF_PAGE_EDGE_FULL_COVERAGE) != 0 + && (flags & (RF_PAGE_EDGE_FULL_IMAGE_APPLY | RF_PAGE_EDGE_WILL_INIT)) != 0; } static RfPageProofDetailV1 -record_identity_validate(RfPageOnlinePlanV1 *plan, - const RfDetachedRecordPlanV1 *record_plan, - const RfPageOnlineRecordIdentityV1 *identity) +record_identity_validate(RfPageOnlinePlanV1 *plan, const RfDetachedRecordPlanV1 *record_plan, + const RfPageOnlineRecordIdentityV1 *identity) { const RfContributorStreamCutV1 *cut; const RfPageReplayRecordIdentityV1 *record; const XLogReaderState *reader; const DecodedXLogRecord *decoded; - if (record_plan == NULL || !record_plan->preflight_complete || - record_plan->source_record == NULL || - record_plan->source_record->record == NULL || identity == NULL) + if (record_plan == NULL || !record_plan->preflight_complete + || record_plan->source_record == NULL || record_plan->source_record->record == NULL + || identity == NULL) return RF_PAGE_PROOF_DETAIL_SOURCE_GAP; reader = record_plan->source_record; decoded = reader->record; record = &identity->record; - if (identity->reserved_zero != 0 || record->reserved_zero != 0 || - record->reserved_zero2 != 0 || - identity->participant_index >= plan->participant_count || - record->system_identifier != plan->system_identifier || - memcmp(record->storage_uuid, plan->storage_uuid, 16) != 0 || - record->origin_thread == 0 || record->timeline_id == 0 || - record->read_rec_ptr == InvalidXLogRecPtr || - record->end_rec_ptr == InvalidXLogRecPtr || - record->read_rec_ptr >= record->end_rec_ptr || - reader->system_identifier != record->system_identifier || - reader->ReadRecPtr != record->read_rec_ptr || - reader->EndRecPtr != record->end_rec_ptr || - decoded->lsn != record->read_rec_ptr || - decoded->next_lsn != record->end_rec_ptr || - (uint32) decoded->header.xl_crc != record->record_crc || - decoded->header.xl_rmid != record->rmid || - decoded->header.xl_info != record->info) + if (identity->reserved_zero != 0 || record->reserved_zero != 0 || record->reserved_zero2 != 0 + || identity->participant_index >= plan->participant_count + || record->system_identifier != plan->system_identifier + || memcmp(record->storage_uuid, plan->storage_uuid, 16) != 0 || record->origin_thread == 0 + || record->timeline_id == 0 || record->read_rec_ptr == InvalidXLogRecPtr + || record->end_rec_ptr == InvalidXLogRecPtr || record->read_rec_ptr >= record->end_rec_ptr + || reader->system_identifier != record->system_identifier + || reader->ReadRecPtr != record->read_rec_ptr || reader->EndRecPtr != record->end_rec_ptr + || decoded->lsn != record->read_rec_ptr || decoded->next_lsn != record->end_rec_ptr + || (uint32)decoded->header.xl_crc != record->record_crc + || decoded->header.xl_rmid != record->rmid || decoded->header.xl_info != record->info) return RF_PAGE_PROOF_DETAIL_IDENTITY_MISMATCH; cut = &plan->physical_cuts[identity->participant_index]; - if (record->origin_thread != cut->failed_thread || - record->timeline_id != cut->timeline_id) + if (record->origin_thread != cut->failed_thread || record->timeline_id != cut->timeline_id) return RF_PAGE_PROOF_DETAIL_IDENTITY_MISMATCH; - if ((cut->flags & RF_CONTRIBUTOR_CUT_EXPLICIT_EMPTY) != 0 || - record->read_rec_ptr < cut->scan_begin_inclusive || - record->end_rec_ptr > cut->scan_end_exclusive || - (plan->participant_seen[identity->participant_index] && - record->read_rec_ptr < - plan->last_record_end[identity->participant_index])) + if ((cut->flags & RF_CONTRIBUTOR_CUT_EXPLICIT_EMPTY) != 0 + || record->read_rec_ptr < cut->scan_begin_inclusive + || record->end_rec_ptr > cut->scan_end_exclusive + || (plan->participant_seen[identity->participant_index] + && record->read_rec_ptr < plan->last_record_end[identity->participant_index])) return RF_PAGE_PROOF_DETAIL_SOURCE_GAP; return RF_PAGE_PROOF_DETAIL_OK; } RfPageProofDetailV1 rf_page_online_plan_create_v1(const RfPageOnlinePlanRequestV1 *request, - RfPageOnlinePlanV1 **out_plan) + RfPageOnlinePlanV1 **out_plan) { RfPageOnlinePlanV1 *plan; - Size budget; - Size arrays_size; - uint32 i; + Size budget; + Size arrays_size; + uint32 i; if (out_plan == NULL) return RF_PAGE_PROOF_DETAIL_INVALID_ARGUMENT; *out_plan = NULL; - if (request == NULL || request->system_identifier == 0 || - !bytes_nonzero(request->storage_uuid, 16) || - request->physical_cuts == NULL || request->participant_count == 0 || - request->participant_count > RF_PAGE_STABLE_MAX_PARTICIPANTS || - request->retention_binding_cookie == 0) + if (request == NULL || request->system_identifier == 0 + || !bytes_nonzero(request->storage_uuid, 16) || request->physical_cuts == NULL + || request->participant_count == 0 + || request->participant_count > RF_PAGE_STABLE_MAX_PARTICIPANTS + || request->retention_binding_cookie == 0) return RF_PAGE_PROOF_DETAIL_INVALID_ARGUMENT; - budget = request->memory_budget == 0 ? RF_PAGE_ONLINE_PLAN_MAX_BYTES : - request->memory_budget; + budget = request->memory_budget == 0 ? RF_PAGE_ONLINE_PLAN_MAX_BYTES : request->memory_budget; if (budget > RF_PAGE_ONLINE_PLAN_MAX_BYTES || budget < sizeof(*plan)) return RF_PAGE_PROOF_DETAIL_INVALID_ARGUMENT; - for (i = 0; i < request->participant_count; i++) - { + for (i = 0; i < request->participant_count; i++) { const RfContributorStreamCutV1 *cut = &request->physical_cuts[i]; - bool empty = (cut->flags & - RF_CONTRIBUTOR_CUT_EXPLICIT_EMPTY) != 0; - - if (cut->failed_thread == 0 || cut->timeline_id == 0 || - (cut->flags & RF_CONTRIBUTOR_CUT_COMPLETE) == 0 || - (cut->flags & ~RF_CONTRIBUTOR_CUT_KNOWN_MASK) != 0 || - (empty && cut->scan_begin_inclusive != cut->scan_end_exclusive) || - (!empty && cut->scan_begin_inclusive >= cut->scan_end_exclusive) || - (i > 0 && request->physical_cuts[i - 1].failed_thread >= - cut->failed_thread)) + bool empty = (cut->flags & RF_CONTRIBUTOR_CUT_EXPLICIT_EMPTY) != 0; + + if (cut->failed_thread == 0 || cut->timeline_id == 0 + || (cut->flags & RF_CONTRIBUTOR_CUT_COMPLETE) == 0 + || (cut->flags & ~RF_CONTRIBUTOR_CUT_KNOWN_MASK) != 0 + || (empty && cut->scan_begin_inclusive != cut->scan_end_exclusive) + || (!empty && cut->scan_begin_inclusive >= cut->scan_end_exclusive) + || (i > 0 && request->physical_cuts[i - 1].failed_thread >= cut->failed_thread)) return RF_PAGE_PROOF_DETAIL_PARTICIPANT_MISSING; } - arrays_size = (Size) request->participant_count * - (sizeof(*plan->physical_cuts) + sizeof(*plan->last_record_end) + - sizeof(*plan->participant_seen)); + arrays_size = (Size)request->participant_count + * (sizeof(*plan->physical_cuts) + sizeof(*plan->last_record_end) + + sizeof(*plan->participant_seen)); if (sizeof(*plan) > budget - Min(budget, arrays_size)) return RF_PAGE_PROOF_DETAIL_CAPACITY; - plan = (RfPageOnlinePlanV1 *) online_alloc0(sizeof(*plan)); + plan = (RfPageOnlinePlanV1 *)online_alloc0(sizeof(*plan)); if (plan == NULL) return RF_PAGE_PROOF_DETAIL_OOM; plan->memory_budget = budget; plan->memory_used = sizeof(*plan); - if (!plan_reserve(plan, arrays_size)) - { + if (!plan_reserve(plan, arrays_size)) { online_free(plan); return RF_PAGE_PROOF_DETAIL_CAPACITY; } - plan->physical_cuts = (RfContributorStreamCutV1 *) online_alloc0( - (Size) request->participant_count * sizeof(*plan->physical_cuts)); - plan->last_record_end = (XLogRecPtr *) online_alloc0( - (Size) request->participant_count * sizeof(*plan->last_record_end)); - plan->participant_seen = (bool *) online_alloc0( - (Size) request->participant_count * sizeof(*plan->participant_seen)); - if (plan->physical_cuts == NULL || plan->last_record_end == NULL || - plan->participant_seen == NULL) - { + plan->physical_cuts = (RfContributorStreamCutV1 *)online_alloc0((Size)request->participant_count + * sizeof(*plan->physical_cuts)); + plan->last_record_end = (XLogRecPtr *)online_alloc0((Size)request->participant_count + * sizeof(*plan->last_record_end)); + plan->participant_seen + = (bool *)online_alloc0((Size)request->participant_count * sizeof(*plan->participant_seen)); + if (plan->physical_cuts == NULL || plan->last_record_end == NULL + || plan->participant_seen == NULL) { rf_page_online_plan_destroy_v1(&plan); return RF_PAGE_PROOF_DETAIL_OOM; } memcpy(plan->physical_cuts, request->physical_cuts, - (Size) request->participant_count * sizeof(*plan->physical_cuts)); + (Size)request->participant_count * sizeof(*plan->physical_cuts)); plan->magic = RF_PAGE_ONLINE_PLAN_MAGIC; plan->system_identifier = request->system_identifier; memcpy(plan->storage_uuid, request->storage_uuid, 16); @@ -417,17 +377,16 @@ rf_page_online_plan_create_v1(const RfPageOnlinePlanRequestV1 *request, RfPageProofDetailV1 rf_page_online_plan_feed_record_v1(RfPageOnlinePlanV1 *plan, - const RfDetachedRecordPlanV1 *record_plan, - const RfPageOnlineRecordIdentityV1 *identity) + const RfDetachedRecordPlanV1 *record_plan, + const RfPageOnlineRecordIdentityV1 *identity) { RfPageOnlinePendingV1 *pending; - uint32 page_count = 0; - uint32 new_target_count = 0; - uint32 i; + uint32 page_count = 0; + uint32 new_target_count = 0; + uint32 i; RfPageProofDetailV1 detail; - if (plan == NULL || plan->magic != RF_PAGE_ONLINE_PLAN_MAGIC || - plan->sealed) + if (plan == NULL || plan->magic != RF_PAGE_ONLINE_PLAN_MAGIC || plan->sealed) return RF_PAGE_PROOF_DETAIL_INVALID_ARGUMENT; detail = record_identity_validate(plan, record_plan, identity); if (detail != RF_PAGE_PROOF_DETAIL_OK) @@ -435,39 +394,31 @@ rf_page_online_plan_feed_record_v1(RfPageOnlinePlanV1 *plan, if (record_plan->component_count > RF_PAGE_STABLE_MAX_COMPONENTS) return RF_PAGE_PROOF_DETAIL_COMPONENT_INCOMPLETE; for (i = 0; i < record_plan->component_count; i++) - if (record_plan->components[i].owner == - RF_DETACHED_COMPONENT_PAGE_CODEC) + if (record_plan->components[i].owner == RF_DETACHED_COMPONENT_PAGE_CODEC) page_count++; - if (page_count == 0) - { + if (page_count == 0) { plan->participant_seen[identity->participant_index] = true; - plan->last_record_end[identity->participant_index] = - identity->record.end_rec_ptr; + plan->last_record_end[identity->participant_index] = identity->record.end_rec_ptr; return RF_PAGE_PROOF_DETAIL_OK; } - if (plan->memory_used > plan->memory_budget - - Min(plan->memory_budget, - (Size) page_count * sizeof(*pending))) + if (plan->memory_used + > plan->memory_budget - Min(plan->memory_budget, (Size)page_count * sizeof(*pending))) return RF_PAGE_PROOF_DETAIL_CAPACITY; - pending = (RfPageOnlinePendingV1 *) online_alloc0( - (Size) page_count * sizeof(*pending)); + pending = (RfPageOnlinePendingV1 *)online_alloc0((Size)page_count * sizeof(*pending)); if (pending == NULL) return RF_PAGE_PROOF_DETAIL_OOM; page_count = 0; - for (i = 0; i < record_plan->component_count; i++) - { - const RfDetachedComponentPlanV1 *component = - &record_plan->components[i]; + for (i = 0; i < record_plan->component_count; i++) { + const RfDetachedComponentPlanV1 *component = &record_plan->components[i]; const DecodedBkpBlock *block; RfPageOnlinePendingV1 *item; RfPageIdentityV1 page_identity; const char *old_page; - uint32 j; + uint32 j; if (component->owner != RF_DETACHED_COMPONENT_PAGE_CODEC) continue; - if (component->block_id > record_plan->source_record->record->max_block_id) - { + if (component->block_id > record_plan->source_record->record->max_block_id) { detail = RF_PAGE_PROOF_DETAIL_COMPONENT_INCOMPLETE; goto fail; } @@ -476,58 +427,47 @@ rf_page_online_plan_feed_record_v1(RfPageOnlinePlanV1 *plan, page_identity.system_identifier = plan->system_identifier; memcpy(page_identity.storage_uuid, plan->storage_uuid, 16); page_identity.locator = block->rlocator; - page_identity.forknum = (uint32) block->forknum; + page_identity.forknum = (uint32)block->forknum; page_identity.blockno = block->blkno; - if (!rf_page_identity_valid_v1(&page_identity)) - { + if (!rf_page_identity_valid_v1(&page_identity)) { detail = RF_PAGE_PROOF_DETAIL_IDENTITY_MISMATCH; goto fail; } for (j = 0; j < page_count; j++) - if (rf_page_identity_equal_v1( - &pending[j].edge.page_identity, &page_identity)) - { + if (rf_page_identity_equal_v1(&pending[j].edge.page_identity, &page_identity)) { detail = RF_PAGE_PROOF_DETAIL_COMPONENT_INCOMPLETE; goto fail; } item = &pending[page_count++]; item->target = find_target(plan, &page_identity); - if (item->target == NULL) - { - if (!anchor_flags(component->edge_flags)) - { + if (item->target == NULL) { + if (!anchor_flags(component->edge_flags)) { detail = RF_PAGE_PROOF_DETAIL_ANCHOR_MISSING; goto fail; } item->target = target_create(plan, &page_identity); - if (item->target == NULL) - { + if (item->target == NULL) { detail = RF_PAGE_PROOF_DETAIL_CAPACITY; goto fail; } item->new_target = true; new_target_count++; old_page = item->target->canonical.data; - } - else - { - if (component->before_kind != RF_PAGE_STATE_PRESENT || - !rf_page_version_equal_v1(&item->target->view.expected_result, - &component->before)) - { + } else { + if (component->before_kind != RF_PAGE_STATE_PRESENT + || !rf_page_version_equal_v1(&item->target->view.expected_result, + &component->before)) { detail = RF_PAGE_PROOF_DETAIL_EDGE_GAP; goto fail; } old_page = item->target->canonical.data; } - detail = rf_page_detached_apply_v1(record_plan, i, old_page, - item->canonical.data); + detail = rf_page_detached_apply_v1(record_plan, i, old_page, item->canonical.data); if (detail != RF_PAGE_PROOF_DETAIL_OK) goto fail; - if (!page_layout_valid(item->canonical.data) || - ((PageHeader) item->canonical.data)->pd_block_scn != - component->result.mutation_token) - { + if (!page_layout_valid(item->canonical.data) + || ((PageHeader)item->canonical.data)->pd_block_scn + != component->result.mutation_token) { detail = RF_PAGE_PROOF_DETAIL_IMAGE_INTEGRITY_FAILED; goto fail; } @@ -539,43 +479,36 @@ rf_page_online_plan_feed_record_v1(RfPageOnlinePlanV1 *plan, item->edge.edge.edge_flags = component->edge_flags; item->edge.edge.component_ordinal = component->component_ordinal; item->edge.edge.before = component->before; - memcpy(item->edge.edge.result_incarnation, - component->result.segment_incarnation, 16); + memcpy(item->edge.edge.result_incarnation, component->result.segment_incarnation, 16); item->edge.result_token = component->result.mutation_token; item->edge.record_identity = identity->record; item->edge.participant_index = identity->participant_index; - item->edge.component_count = (uint16) record_plan->component_count; + item->edge.component_count = (uint16)record_plan->component_count; item->edge.record_complete = true; item->edge.opcode_supported = true; item->edge.side_complete = true; item->edge.image_integrity_ok = true; - if (anchor_flags(component->edge_flags) && - !page_sha256(item->canonical.data, item->edge.anchor_digest)) - { + if (anchor_flags(component->edge_flags) + && !page_sha256(item->canonical.data, item->edge.anchor_digest)) { detail = RF_PAGE_PROOF_DETAIL_INTERNAL; goto fail; } } - if (!ensure_target_capacity(plan, new_target_count)) - { + if (!ensure_target_capacity(plan, new_target_count)) { detail = RF_PAGE_PROOF_DETAIL_CAPACITY; goto fail; } for (i = 0; i < page_count; i++) - if (!ensure_edge_capacity(plan, pending[i].target, 1)) - { + if (!ensure_edge_capacity(plan, pending[i].target, 1)) { detail = RF_PAGE_PROOF_DETAIL_CAPACITY; goto fail; } - for (i = 0; i < page_count; i++) - { + for (i = 0; i < page_count; i++) { RfPageOnlinePendingV1 *item = &pending[i]; RfPageOnlineTargetV1 *target = item->target; - RfContributorStreamCutV1 *cut = - &target->cuts[identity->participant_index]; + RfContributorStreamCutV1 *cut = &target->cuts[identity->participant_index]; - if (item->new_target) - { + if (item->new_target) { target->view.before_kind = item->edge.edge.before_kind; target->view.expected_before = item->edge.edge.before; plan->targets[plan->target_count++] = target; @@ -583,12 +516,11 @@ rf_page_online_plan_feed_record_v1(RfPageOnlinePlanV1 *plan, } target->edges[target->edge_count++] = item->edge; target->view.expected_result.segment_incarnation[0] = 0; - memcpy(target->view.expected_result.segment_incarnation, - item->edge.edge.result_incarnation, 16); + memcpy(target->view.expected_result.segment_incarnation, item->edge.edge.result_incarnation, + 16); target->view.expected_result.mutation_token = item->edge.result_token; memcpy(target->canonical.data, item->canonical.data, BLCKSZ); - if ((cut->flags & RF_CONTRIBUTOR_CUT_EXPLICIT_EMPTY) != 0) - { + if ((cut->flags & RF_CONTRIBUTOR_CUT_EXPLICIT_EMPTY) != 0) { cut->flags = RF_CONTRIBUTOR_CUT_COMPLETE; cut->scan_begin_inclusive = identity->record.read_rec_ptr; } @@ -599,8 +531,7 @@ rf_page_online_plan_feed_record_v1(RfPageOnlinePlanV1 *plan, target->source.source_version = target->view.expected_result; } plan->participant_seen[identity->participant_index] = true; - plan->last_record_end[identity->participant_index] = - identity->record.end_rec_ptr; + plan->last_record_end[identity->participant_index] = identity->record.end_rec_ptr; online_free(pending); return RF_PAGE_PROOF_DETAIL_OK; @@ -615,34 +546,26 @@ rf_page_online_plan_feed_record_v1(RfPageOnlinePlanV1 *plan, RfPageProofDetailV1 rf_page_online_plan_seal_v1(RfPageOnlinePlanV1 *plan) { - uint32 i; + uint32 i; - if (plan == NULL || plan->magic != RF_PAGE_ONLINE_PLAN_MAGIC || - plan->sealed) + if (plan == NULL || plan->magic != RF_PAGE_ONLINE_PLAN_MAGIC || plan->sealed) return RF_PAGE_PROOF_DETAIL_INVALID_ARGUMENT; - for (i = 0; i < plan->participant_count; i++) - { - bool empty = (plan->physical_cuts[i].flags & - RF_CONTRIBUTOR_CUT_EXPLICIT_EMPTY) != 0; - - if (empty != !plan->participant_seen[i] || - (!empty && plan->last_record_end[i] != - plan->physical_cuts[i].scan_end_exclusive)) + for (i = 0; i < plan->participant_count; i++) { + bool empty = (plan->physical_cuts[i].flags & RF_CONTRIBUTOR_CUT_EXPLICIT_EMPTY) != 0; + + if (empty != !plan->participant_seen[i] + || (!empty && plan->last_record_end[i] != plan->physical_cuts[i].scan_end_exclusive)) return RF_PAGE_PROOF_DETAIL_SOURCE_GAP; } - qsort(plan->targets, plan->target_count, sizeof(*plan->targets), - target_pointer_compare); - for (i = 0; i < plan->target_count; i++) - { + qsort(plan->targets, plan->target_count, sizeof(*plan->targets), target_pointer_compare); + for (i = 0; i < plan->target_count; i++) { RfPageOnlineTargetV1 *target = plan->targets[i]; - if (target->edge_count == 0 || - !rf_page_version_present_v1(&target->source.source_version)) + if (target->edge_count == 0 || !rf_page_version_present_v1(&target->source.source_version)) return RF_PAGE_PROOF_DETAIL_ANCHOR_MISSING; target->source.page_identity = target->view.page_identity; target->source.binding_cookie = plan->retention_binding_cookie; - target->source.current_binding_cookie = - plan->retention_binding_cookie; + target->source.current_binding_cookie = plan->retention_binding_cookie; target->source.identity_verified = true; target->source.integrity_verified = true; target->contributors.system_identifier = plan->system_identifier; @@ -669,16 +592,17 @@ rf_page_online_plan_seal_v1(RfPageOnlinePlanV1 *plan) uint32 rf_page_online_plan_target_count_v1(const RfPageOnlinePlanV1 *plan) { - return plan != NULL && plan->magic == RF_PAGE_ONLINE_PLAN_MAGIC && - plan->sealed ? plan->target_count : 0; + return plan != NULL && plan->magic == RF_PAGE_ONLINE_PLAN_MAGIC && plan->sealed + ? plan->target_count + : 0; } bool rf_page_online_plan_target_v1(const RfPageOnlinePlanV1 *plan, uint32 index, - RfPageOnlineTargetViewV1 *out_target) + RfPageOnlineTargetViewV1 *out_target) { - if (plan == NULL || plan->magic != RF_PAGE_ONLINE_PLAN_MAGIC || - !plan->sealed || index >= plan->target_count || out_target == NULL) + if (plan == NULL || plan->magic != RF_PAGE_ONLINE_PLAN_MAGIC || !plan->sealed + || index >= plan->target_count || out_target == NULL) return false; *out_target = plan->targets[index]->view; return true; @@ -688,13 +612,13 @@ void rf_page_online_plan_destroy_v1(RfPageOnlinePlanV1 **plan_pointer) { RfPageOnlinePlanV1 *plan; - uint32 i; if (plan_pointer == NULL || *plan_pointer == NULL) return; plan = *plan_pointer; - if (plan->magic == RF_PAGE_ONLINE_PLAN_MAGIC) - { + if (plan->magic == RF_PAGE_ONLINE_PLAN_MAGIC) { + uint32 i; + for (i = 0; i < plan->target_count; i++) target_destroy(plan->targets[i]); } diff --git a/src/backend/cluster/cluster_page_producer.c b/src/backend/cluster/cluster_page_producer.c index bef6aaf6786..0fc026574b2 100644 --- a/src/backend/cluster/cluster_page_producer.c +++ b/src/backend/cluster/cluster_page_producer.c @@ -14,8 +14,8 @@ static bool incarnation_nonzero(const uint8 incarnation[16]) { - uint8 any = 0; - int i; + uint8 any = 0; + int i; for (i = 0; i < 16; i++) any |= incarnation[i]; @@ -25,30 +25,28 @@ incarnation_nonzero(const uint8 incarnation[16]) uint64 rf_page_mutation_token_next(void) { - SCN token = cluster_scn_advance(); + SCN token = cluster_scn_advance(); - if (!SCN_VALID(token)) - { + if (!SCN_VALID(token)) { #ifdef USE_CLUSTER_UNIT return 0; #else elog(ERROR, "STOP-06 mutation-token allocator returned zero"); #endif } - return (uint64) token; + return (uint64)token; } void rf_page_mutation_token_observe(uint64 token) { - if (token == 0) - { + if (token == 0) { #ifndef USE_CLUSTER_UNIT elog(ERROR, "cannot observe a zero STOP-06 mutation token"); #endif return; } - cluster_scn_observe((SCN) token); + cluster_scn_observe((SCN)token); } static bool @@ -57,84 +55,71 @@ component_shape_valid(const RfPageProducerComponentV1 *component) if (component->reserved_zero != 0 || component->reserved_zero2 != 0) return false; - if (component->page_class == RF_PAGE_CLASS_ORDINARY) - { - uint64 before_token; + if (component->page_class == RF_PAGE_CLASS_ORDINARY) { + uint64 before_token; - if (component->page == NULL || - !incarnation_nonzero(component->segment_incarnation)) + if (component->page == NULL || !incarnation_nonzero(component->segment_incarnation)) + return false; + before_token = (uint64)((PageHeader)component->page)->pd_block_scn; + switch (component->before_kind) { + case RF_PAGE_STATE_PRESENT: + return !PageIsNew(component->page) && before_token != 0; + case RF_PAGE_STATE_UNFORMATTED: + case RF_PAGE_STATE_ABSENT: + return PageIsNew(component->page) && before_token == 0; + default: return false; - before_token = (uint64) ((PageHeader) component->page)->pd_block_scn; - switch (component->before_kind) - { - case RF_PAGE_STATE_PRESENT: - return !PageIsNew(component->page) && before_token != 0; - case RF_PAGE_STATE_UNFORMATTED: - case RF_PAGE_STATE_ABSENT: - return PageIsNew(component->page) && before_token == 0; - default: - return false; } } - if (incarnation_nonzero(component->segment_incarnation) || - component->page != NULL) + if (incarnation_nonzero(component->segment_incarnation) || component->page != NULL) return false; if (component->page_class == RF_PAGE_CLASS_REBUILDABLE_FSM) return component->before_kind == RF_PAGE_STATE_REBUILDABLE; - if (component->page_class == RF_PAGE_CLASS_ROUTED_SPACE || - component->page_class == RF_PAGE_CLASS_ROUTED_HEADER || - component->page_class == RF_PAGE_CLASS_ROUTED_SIDE) + if (component->page_class == RF_PAGE_CLASS_ROUTED_SPACE + || component->page_class == RF_PAGE_CLASS_ROUTED_HEADER + || component->page_class == RF_PAGE_CLASS_ROUTED_SIDE) return component->before_kind == RF_PAGE_STATE_ROUTED; return false; } bool -rf_page_producer_prepare_v1(const RfPageProducerComponentV1 *components, - uint8 component_count, +rf_page_producer_prepare_v1(const RfPageProducerComponentV1 *components, uint8 component_count, RfPageProducerBatchV1 *batch) { RfPageProducerBatchV1 prepared; - uint64 token; - int i; - int j; + uint64 token; + int i; + int j; - if (components == NULL || batch == NULL || component_count == 0 || - component_count > RF_PAGE_PRODUCER_MAX_COMPONENTS) + if (components == NULL || batch == NULL || component_count == 0 + || component_count > RF_PAGE_PRODUCER_MAX_COMPONENTS) return false; memset(&prepared, 0, sizeof(prepared)); - for (i = 0; i < component_count; i++) - { + for (i = 0; i < component_count; i++) { const RfPageProducerComponentV1 *component = &components[i]; RfPageVersionEdgeEntryV1 *entry = &prepared.entries[i]; - if (!component_shape_valid(component) || - component->component_ordinal != i || - (i > 0 && components[i - 1].block_id >= component->block_id)) + if (!component_shape_valid(component) || component->component_ordinal != i + || (i > 0 && components[i - 1].block_id >= component->block_id)) return false; for (j = 0; j < i; j++) - if (component->page != NULL && - component->page == components[j].page) + if (component->page != NULL && component->page == components[j].page) return false; entry->block_id = component->block_id; entry->page_class = component->page_class; entry->before_kind = component->before_kind; entry->component_ordinal = component->component_ordinal; - if (component->page_class == RF_PAGE_CLASS_ORDINARY) - { + if (component->page_class == RF_PAGE_CLASS_ORDINARY) { entry->result_kind = RF_PAGE_STATE_PRESENT; if (component->before_kind != RF_PAGE_STATE_ABSENT) - memcpy(entry->before.segment_incarnation, - component->segment_incarnation, 16); - entry->before.mutation_token = - (uint64) ((PageHeader) component->page)->pd_block_scn; - memcpy(entry->result_incarnation, - component->segment_incarnation, 16); + memcpy(entry->before.segment_incarnation, component->segment_incarnation, 16); + entry->before.mutation_token = (uint64)((PageHeader)component->page)->pd_block_scn; + memcpy(entry->result_incarnation, component->segment_incarnation, 16); prepared.ordinary_pages[i] = component->page; - } - else if (component->page_class == RF_PAGE_CLASS_REBUILDABLE_FSM) + } else if (component->page_class == RF_PAGE_CLASS_REBUILDABLE_FSM) entry->result_kind = RF_PAGE_STATE_REBUILDABLE; else entry->result_kind = RF_PAGE_STATE_ROUTED; @@ -154,34 +139,29 @@ rf_page_producer_prepare_v1(const RfPageProducerComponentV1 *components, bool rf_page_producer_stamp_v1(RfPageProducerBatchV1 *batch) { - int i; + int i; - if (batch == NULL || !batch->prepared || batch->result_token == 0 || - batch->entry_count == 0 || - batch->entry_count > RF_PAGE_PRODUCER_MAX_COMPONENTS) + if (batch == NULL || !batch->prepared || batch->result_token == 0 || batch->entry_count == 0 + || batch->entry_count > RF_PAGE_PRODUCER_MAX_COMPONENTS) return false; if (batch->stamped) return true; /* Global revalidation first: a failure must leave every page untouched. */ - for (i = 0; i < batch->entry_count; i++) - { + for (i = 0; i < batch->entry_count; i++) { const RfPageVersionEdgeEntryV1 *entry = &batch->entries[i]; - Page page = batch->ordinary_pages[i]; + Page page = batch->ordinary_pages[i]; if (entry->page_class != RF_PAGE_CLASS_ORDINARY) continue; - if (page == NULL || - (uint64) ((PageHeader) page)->pd_block_scn != - entry->before.mutation_token) + if (page == NULL + || (uint64)((PageHeader)page)->pd_block_scn != entry->before.mutation_token) return false; } - for (i = 0; i < batch->entry_count; i++) - { + for (i = 0; i < batch->entry_count; i++) { if (batch->entries[i].page_class == RF_PAGE_CLASS_ORDINARY) - ((PageHeader) batch->ordinary_pages[i])->pd_block_scn = - (SCN) batch->result_token; + ((PageHeader)batch->ordinary_pages[i])->pd_block_scn = (SCN)batch->result_token; } batch->stamped = true; return true; @@ -190,22 +170,19 @@ rf_page_producer_stamp_v1(RfPageProducerBatchV1 *batch) bool rf_page_producer_register_wal_v1(const RfPageProducerBatchV1 *batch) { - int i; + int i; - if (batch == NULL || !batch->prepared || !batch->stamped || - batch->result_token == 0 || batch->entry_count == 0 || - batch->entry_count > RF_PAGE_PRODUCER_MAX_COMPONENTS) + if (batch == NULL || !batch->prepared || !batch->stamped || batch->result_token == 0 + || batch->entry_count == 0 || batch->entry_count > RF_PAGE_PRODUCER_MAX_COMPONENTS) return false; - for (i = 0; i < batch->entry_count; i++) - { - if (batch->entries[i].page_class == RF_PAGE_CLASS_ORDINARY && - (batch->ordinary_pages[i] == NULL || - (uint64) ((PageHeader) batch->ordinary_pages[i])->pd_block_scn != - batch->result_token)) + for (i = 0; i < batch->entry_count; i++) { + if (batch->entries[i].page_class == RF_PAGE_CLASS_ORDINARY + && (batch->ordinary_pages[i] == NULL + || (uint64)((PageHeader)batch->ordinary_pages[i])->pd_block_scn + != batch->result_token)) return false; } - XLogRegisterPageVersionEdge(batch->result_token, batch->entries, - batch->entry_count); + XLogRegisterPageVersionEdge(batch->result_token, batch->entries, batch->entry_count); return true; } diff --git a/src/backend/cluster/cluster_page_recovery.c b/src/backend/cluster/cluster_page_recovery.c index 5b20eabc704..9700999401c 100644 --- a/src/backend/cluster/cluster_page_recovery.c +++ b/src/backend/cluster/cluster_page_recovery.c @@ -30,71 +30,69 @@ ClusterPageRecoveryAction cluster_page_class_recovery_action(ClusterPageClass page_class) { - switch (page_class) - { - case CLUSTER_PAGE_CLASS_NORMAL: - case CLUSTER_PAGE_CLASS_CLEANOUT: - /* + switch (page_class) { + case CLUSTER_PAGE_CLASS_NORMAL: + case CLUSTER_PAGE_CLASS_CLEANOUT: + /* * PC-NORMAL / PC-CLEANOUT: versioned deterministic delta * apply (the §3.2 gate decides per record; the cleanout codec * census is the apply layer's, spec §4.7 keeps the action * BLOCKED until producer + codec exist — this table only * assigns the row's action). */ - return CLUSTER_PAGE_ACTION_APPLY; + return CLUSTER_PAGE_ACTION_APPLY; - case CLUSTER_PAGE_CLASS_NEW: - /* PC-NEW: initialize only from a declared full-init rule. */ - return CLUSTER_PAGE_ACTION_INIT; + case CLUSTER_PAGE_CLASS_NEW: + /* PC-NEW: initialize only from a declared full-init rule. */ + return CLUSTER_PAGE_ACTION_INIT; - case CLUSTER_PAGE_CLASS_INCARNATION: - /* PC-INCARNATION: close the old contributor set, open the + case CLUSTER_PAGE_CLASS_INCARNATION: + /* PC-INCARNATION: close the old contributor set, open the * new; never merge incarnations. */ - return CLUSTER_PAGE_ACTION_INCARNATE; + return CLUSTER_PAGE_ACTION_INCARNATE; - case CLUSTER_PAGE_CLASS_TEMP: - /* PC-TEMP: discard/recreate with the owning-session proof. */ - return CLUSTER_PAGE_ACTION_DISCARD; + case CLUSTER_PAGE_CLASS_TEMP: + /* PC-TEMP: discard/recreate with the owning-session proof. */ + return CLUSTER_PAGE_ACTION_DISCARD; - case CLUSTER_PAGE_CLASS_REBUILDABLE: - /* PC-REBUILDABLE (FSM only, approved deviation): invalidate + case CLUSTER_PAGE_CLASS_REBUILDABLE: + /* PC-REBUILDABLE (FSM only, approved deviation): invalidate * and rebuild from heap truth + relation size. */ - return CLUSTER_PAGE_ACTION_REBUILD; + return CLUSTER_PAGE_ACTION_REBUILD; - case CLUSTER_PAGE_CLASS_HEADER: - /* PC-HEADER: route to the exact typed owner; generic page + case CLUSTER_PAGE_CLASS_HEADER: + /* PC-HEADER: route to the exact typed owner; generic page * replay never touches it (§4.5). */ - return CLUSTER_PAGE_ACTION_ROUTE; + return CLUSTER_PAGE_ACTION_ROUTE; - case CLUSTER_PAGE_CLASS_FULLIMAGE: - /* PC-FULLIMAGE: an image payload under provenance proof. */ - return CLUSTER_PAGE_ACTION_IMAGE; + case CLUSTER_PAGE_CLASS_FULLIMAGE: + /* PC-FULLIMAGE: an image payload under provenance proof. */ + return CLUSTER_PAGE_ACTION_IMAGE; - case CLUSTER_PAGE_CLASS_WILLINIT: - /* PC-WILLINIT: the attribute alone never authorizes init; + case CLUSTER_PAGE_CLASS_WILLINIT: + /* PC-WILLINIT: the attribute alone never authorizes init; * without the exact rmgr full-init rule the action is * BLOCKED (§4.6 / PU-17). */ - return CLUSTER_PAGE_ACTION_BLOCKED; + return CLUSTER_PAGE_ACTION_BLOCKED; - case CLUSTER_PAGE_CLASS_NONLOGGED: - /* PC-NONLOGGED: rebuild/route under a declared rebuild owner; + case CLUSTER_PAGE_CLASS_NONLOGGED: + /* PC-NONLOGGED: rebuild/route under a declared rebuild owner; * without one the apply layer must BLOCK (never treat as * WAL-covered). */ - return CLUSTER_PAGE_ACTION_REBUILD; + return CLUSTER_PAGE_ACTION_REBUILD; - case CLUSTER_PAGE_CLASS_UNCLASSIFIED: - case CLUSTER_PAGE_CLASS_UNKNOWN: - default: - /* PC-UNKNOWN (and the state-machine start value): mutation=0, + case CLUSTER_PAGE_CLASS_UNCLASSIFIED: + case CLUSTER_PAGE_CLASS_UNKNOWN: + default: + /* PC-UNKNOWN (and the state-machine start value): mutation=0, * never released (spec §4.1 / PGDEL-03 "unknown default 必须 * BLOCKED"). */ - return CLUSTER_PAGE_ACTION_BLOCKED; + return CLUSTER_PAGE_ACTION_BLOCKED; } } bool -cluster_page_state_advance(ClusterPageRecoveryState *state, - ClusterPageRecoveryState expected_next) +cluster_page_state_advance(ClusterPageRecoveryState *state, ClusterPageRecoveryState expected_next) { ClusterPageRecoveryState cur; @@ -113,8 +111,7 @@ cluster_page_state_advance(ClusterPageRecoveryState *state, } ClusterPageRecoveryOutcome -cluster_page_dispatcher_verdict(ClusterPageClass page_class, - ClusterPageApplyVerdict verdict) +cluster_page_dispatcher_verdict(ClusterPageClass page_class, ClusterPageApplyVerdict verdict) { /* The class layer's blocked branch is BLOCKED_CLASS. The finer * subdivisions (BLOCKED_SOURCE, BLOCKED_CONTRIBUTOR, diff --git a/src/backend/cluster/cluster_page_replay_batch.c b/src/backend/cluster/cluster_page_replay_batch.c index 67834dd0fb2..88b31877802 100644 --- a/src/backend/cluster/cluster_page_replay_batch.c +++ b/src/backend/cluster/cluster_page_replay_batch.c @@ -13,9 +13,9 @@ static bool page_all_zero(const char page[BLCKSZ]) { - const uint8 *bytes = (const uint8 *) page; - uint8 value = 0; - int i; + const uint8 *bytes = (const uint8 *)page; + uint8 value = 0; + int i; for (i = 0; i < BLCKSZ; i++) value |= bytes[i]; @@ -25,22 +25,18 @@ page_all_zero(const char page[BLCKSZ]) static bool page_layout_valid(const char page[BLCKSZ]) { - const PageHeader header = (const PageHeader) page; - - return !PageIsNew((Page) page) && - PageGetPageSize((Page) page) == BLCKSZ && - PageGetPageLayoutVersion((Page) page) == PG_PAGE_LAYOUT_VERSION && - header->pd_lower >= SizeOfPageHeaderData && - header->pd_lower <= header->pd_upper && - header->pd_upper <= header->pd_special && - header->pd_special <= BLCKSZ; + const PageHeader header = (const PageHeader)page; + + return !PageIsNew((Page)page) && PageGetPageSize((Page)page) == BLCKSZ + && PageGetPageLayoutVersion((Page)page) == PG_PAGE_LAYOUT_VERSION + && header->pd_lower >= SizeOfPageHeaderData && header->pd_lower <= header->pd_upper + && header->pd_upper <= header->pd_special && header->pd_special <= BLCKSZ; } static int -identity_compare(const RfPageIdentityV1 *left, - const RfPageIdentityV1 *right) +identity_compare(const RfPageIdentityV1 *left, const RfPageIdentityV1 *right) { - int cmp; + int cmp; if (left->system_identifier != right->system_identifier) return left->system_identifier < right->system_identifier ? -1 : 1; @@ -71,8 +67,8 @@ version_zero(const RfPageVersionV1 *version) static bool bytes_nonzero(const uint8 *bytes, Size size) { - uint8 value = 0; - Size i; + uint8 value = 0; + Size i; for (i = 0; i < size; i++) value |= bytes[i]; @@ -84,34 +80,31 @@ target_versions_valid(const RfPageReplayTargetV1 *target) { static const uint8 zero_reserved[7]; - if (!rf_page_identity_valid_v1(&target->page_identity) || - !rf_page_version_present_v1(&target->expected_result) || - target->base_page == NULL || - memcmp(target->reserved_zero, zero_reserved, - sizeof(zero_reserved)) != 0) + if (!rf_page_identity_valid_v1(&target->page_identity) + || !rf_page_version_present_v1(&target->expected_result) || target->base_page == NULL + || memcmp(target->reserved_zero, zero_reserved, sizeof(zero_reserved)) != 0) + return false; + switch (target->before_kind) { + case RF_PAGE_STATE_PRESENT: + return rf_page_version_present_v1(&target->expected_before) + && memcmp(target->expected_before.segment_incarnation, + target->expected_result.segment_incarnation, 16) + == 0; + case RF_PAGE_STATE_UNFORMATTED: + return target->expected_before.mutation_token == 0 + && memcmp(target->expected_before.segment_incarnation, + target->expected_result.segment_incarnation, 16) + == 0; + case RF_PAGE_STATE_ABSENT: + return version_zero(&target->expected_before); + default: return false; - switch (target->before_kind) - { - case RF_PAGE_STATE_PRESENT: - return rf_page_version_present_v1(&target->expected_before) && - memcmp(target->expected_before.segment_incarnation, - target->expected_result.segment_incarnation, 16) == 0; - case RF_PAGE_STATE_UNFORMATTED: - return target->expected_before.mutation_token == 0 && - memcmp(target->expected_before.segment_incarnation, - target->expected_result.segment_incarnation, 16) == 0; - case RF_PAGE_STATE_ABSENT: - return version_zero(&target->expected_before); - default: - return false; } } static bool -step_matches_target(const RfPageReplayBatchRequestV1 *request, - const RfPageReplayTargetV1 *target, - const RfPageReplayStepV1 *step, - const RfPageVersionV1 *expected_before, +step_matches_target(const RfPageReplayBatchRequestV1 *request, const RfPageReplayTargetV1 *target, + const RfPageReplayStepV1 *step, const RfPageVersionV1 *expected_before, uint8 expected_before_kind) { const RfDetachedRecordPlanV1 *plan; @@ -121,26 +114,24 @@ step_matches_target(const RfPageReplayBatchRequestV1 *request, if (step == NULL || step->record_index >= request->record_count) return false; plan = request->records[step->record_index].record_plan; - if (!plan->preflight_complete || plan->source_record == NULL || - plan->source_record->record == NULL || - step->component_index >= plan->component_count) + if (!plan->preflight_complete || plan->source_record == NULL + || plan->source_record->record == NULL || step->component_index >= plan->component_count) return false; component = &plan->components[step->component_index]; - if (component->owner != RF_DETACHED_COMPONENT_PAGE_CODEC || - component->page_class != RF_PAGE_CLASS_ORDINARY || - component->result_kind != RF_PAGE_STATE_PRESENT || - component->before.mutation_token != expected_before->mutation_token || - component->before_kind != expected_before_kind || - !rf_page_version_equal_v1(&component->before, expected_before) || - !rf_page_version_present_v1(&component->result) || - component->result.mutation_token != plan->result_token || - component->block_id > plan->source_record->record->max_block_id) + if (component->owner != RF_DETACHED_COMPONENT_PAGE_CODEC + || component->page_class != RF_PAGE_CLASS_ORDINARY + || component->result_kind != RF_PAGE_STATE_PRESENT + || component->before.mutation_token != expected_before->mutation_token + || component->before_kind != expected_before_kind + || !rf_page_version_equal_v1(&component->before, expected_before) + || !rf_page_version_present_v1(&component->result) + || component->result.mutation_token != plan->result_token + || component->block_id > plan->source_record->record->max_block_id) return false; block = &plan->source_record->record->blocks[component->block_id]; - return block->in_use && - RelFileLocatorEquals(block->rlocator, target->page_identity.locator) && - (uint32) block->forknum == target->page_identity.forknum && - block->blkno == target->page_identity.blockno; + return block->in_use && RelFileLocatorEquals(block->rlocator, target->page_identity.locator) + && (uint32)block->forknum == target->page_identity.forknum + && block->blkno == target->page_identity.blockno; } static bool @@ -154,67 +145,60 @@ first_step_is_full_anchor(const RfPageReplayBatchRequestV1 *request, return false; plan = request->records[target->steps[0].record_index].record_plan; component = &plan->components[target->steps[0].component_index]; - return (component->edge_flags & RF_PAGE_EDGE_FULL_COVERAGE) != 0 && - (component->edge_flags & (RF_PAGE_EDGE_FULL_IMAGE_APPLY | - RF_PAGE_EDGE_WILL_INIT)) != 0; + return (component->edge_flags & RF_PAGE_EDGE_FULL_COVERAGE) != 0 + && (component->edge_flags & (RF_PAGE_EDGE_FULL_IMAGE_APPLY | RF_PAGE_EDGE_WILL_INIT)) + != 0; } static RfPageProofDetailV1 -validate_target(const RfPageReplayBatchRequestV1 *request, - const RfPageReplayTargetV1 *target, uint32 *step_total) +validate_target(const RfPageReplayBatchRequestV1 *request, const RfPageReplayTargetV1 *target, + uint32 *step_total) { RfPageVersionV1 expected; - uint8 expected_kind; - uint32 i; + uint8 expected_kind; + uint32 i; if (!target_versions_valid(target)) return RF_PAGE_PROOF_DETAIL_IDENTITY_MISMATCH; - if (target->step_count == 0) - { - if (target->steps != NULL || target->before_kind != RF_PAGE_STATE_PRESENT || - !rf_page_version_equal_v1(&target->expected_before, - &target->expected_result) || - page_all_zero(target->base_page) || - !page_layout_valid(target->base_page) || - ((const PageHeader) target->base_page)->pd_block_scn != - target->expected_result.mutation_token) + if (target->step_count == 0) { + if (target->steps != NULL || target->before_kind != RF_PAGE_STATE_PRESENT + || !rf_page_version_equal_v1(&target->expected_before, &target->expected_result) + || page_all_zero(target->base_page) || !page_layout_valid(target->base_page) + || ((const PageHeader)target->base_page)->pd_block_scn + != target->expected_result.mutation_token) return RF_PAGE_PROOF_DETAIL_ANCHOR_MISSING; return RF_PAGE_PROOF_DETAIL_OK; } - if (target->steps == NULL || - target->step_count > RF_PAGE_STABLE_MAX_EDGES || - *step_total > RF_PAGE_STABLE_MAX_EDGES - target->step_count) + if (target->steps == NULL || target->step_count > RF_PAGE_STABLE_MAX_EDGES + || *step_total > RF_PAGE_STABLE_MAX_EDGES - target->step_count) return RF_PAGE_PROOF_DETAIL_CAPACITY; expected = target->expected_before; expected_kind = target->before_kind; - for (i = 0; i < target->step_count; i++) - { + for (i = 0; i < target->step_count; i++) { const RfPageReplayStepV1 *step = &target->steps[i]; const RfDetachedComponentPlanV1 *component; - if (!step_matches_target(request, target, step, &expected, - expected_kind)) + if (!step_matches_target(request, target, step, &expected, expected_kind)) return RF_PAGE_PROOF_DETAIL_COMPONENT_INCOMPLETE; - if (request->record_component_seen[ - (Size) step->record_index * RF_PAGE_STABLE_MAX_COMPONENTS + - step->component_index] != 0) + if (request->record_component_seen[(Size)step->record_index * RF_PAGE_STABLE_MAX_COMPONENTS + + step->component_index] + != 0) return RF_PAGE_PROOF_DETAIL_COMPONENT_INCOMPLETE; - request->record_component_seen[ - (Size) step->record_index * RF_PAGE_STABLE_MAX_COMPONENTS + - step->component_index] = 1; - component = &request->records[step->record_index].record_plan->components[ - step->component_index]; + request->record_component_seen[(Size)step->record_index * RF_PAGE_STABLE_MAX_COMPONENTS + + step->component_index] + = 1; + component + = &request->records[step->record_index].record_plan->components[step->component_index]; expected = component->result; expected_kind = RF_PAGE_STATE_PRESENT; } if (!rf_page_version_equal_v1(&expected, &target->expected_result)) return RF_PAGE_PROOF_DETAIL_EDGE_GAP; - if (!first_step_is_full_anchor(request, target) && - (target->before_kind == RF_PAGE_STATE_ABSENT || - page_all_zero(target->base_page) || - !page_layout_valid(target->base_page) || - ((const PageHeader) target->base_page)->pd_block_scn != - target->expected_before.mutation_token)) + if (!first_step_is_full_anchor(request, target) + && (target->before_kind == RF_PAGE_STATE_ABSENT || page_all_zero(target->base_page) + || !page_layout_valid(target->base_page) + || ((const PageHeader)target->base_page)->pd_block_scn + != target->expected_before.mutation_token)) return RF_PAGE_PROOF_DETAIL_ANCHOR_MISSING; *step_total += target->step_count; return RF_PAGE_PROOF_DETAIL_OK; @@ -223,115 +207,102 @@ validate_target(const RfPageReplayBatchRequestV1 *request, static RfPageProofDetailV1 validate_record_table(const RfPageReplayBatchRequestV1 *request) { - uint32 component_counts[RF_PAGE_STABLE_MAX_PARTICIPANTS]; - uint32 page_counts[RF_PAGE_STABLE_MAX_PARTICIPANTS]; - uint32 i; - - if (request->system_identifier == 0 || - !bytes_nonzero(request->storage_uuid, sizeof(request->storage_uuid)) || - request->participants == NULL || request->participant_count == 0 || - request->participant_count > RF_PAGE_STABLE_MAX_PARTICIPANTS) + uint32 component_counts[RF_PAGE_STABLE_MAX_PARTICIPANTS]; + uint32 page_counts[RF_PAGE_STABLE_MAX_PARTICIPANTS]; + uint32 i; + + if (request->system_identifier == 0 + || !bytes_nonzero(request->storage_uuid, sizeof(request->storage_uuid)) + || request->participants == NULL || request->participant_count == 0 + || request->participant_count > RF_PAGE_STABLE_MAX_PARTICIPANTS) return RF_PAGE_PROOF_DETAIL_PARTICIPANT_MISSING; memset(component_counts, 0, sizeof(component_counts)); memset(page_counts, 0, sizeof(page_counts)); - for (i = 0; i < request->participant_count; i++) - { + for (i = 0; i < request->participant_count; i++) { const RfContributorStreamCutV1 *cut = &request->participants[i]; - bool empty = - (cut->flags & RF_CONTRIBUTOR_CUT_EXPLICIT_EMPTY) != 0; - - if (cut->failed_thread == 0 || cut->timeline_id == 0 || - (cut->flags & RF_CONTRIBUTOR_CUT_COMPLETE) == 0 || - (cut->flags & ~RF_CONTRIBUTOR_CUT_KNOWN_MASK) != 0 || - (empty && (cut->flags != RF_CONTRIBUTOR_CUT_KNOWN_MASK || - cut->scan_begin_inclusive != cut->scan_end_exclusive || - cut->contributor_count != 0 || - cut->component_count != 0)) || - (!empty && (cut->flags != RF_CONTRIBUTOR_CUT_COMPLETE || - cut->scan_begin_inclusive >= - cut->scan_end_exclusive)) || - (i > 0 && - (request->participants[i - 1].failed_thread > cut->failed_thread || - (request->participants[i - 1].failed_thread == - cut->failed_thread && - request->participants[i - 1].timeline_id >= cut->timeline_id)))) + bool empty = (cut->flags & RF_CONTRIBUTOR_CUT_EXPLICIT_EMPTY) != 0; + + if (cut->failed_thread == 0 || cut->timeline_id == 0 + || (cut->flags & RF_CONTRIBUTOR_CUT_COMPLETE) == 0 + || (cut->flags & ~RF_CONTRIBUTOR_CUT_KNOWN_MASK) != 0 + || (empty + && (cut->flags != RF_CONTRIBUTOR_CUT_KNOWN_MASK + || cut->scan_begin_inclusive != cut->scan_end_exclusive + || cut->contributor_count != 0 || cut->component_count != 0)) + || (!empty + && (cut->flags != RF_CONTRIBUTOR_CUT_COMPLETE + || cut->scan_begin_inclusive >= cut->scan_end_exclusive)) + || (i > 0 + && (request->participants[i - 1].failed_thread > cut->failed_thread + || (request->participants[i - 1].failed_thread == cut->failed_thread + && request->participants[i - 1].timeline_id >= cut->timeline_id)))) return RF_PAGE_PROOF_DETAIL_PARTICIPANT_MISSING; } - if (request->record_count == 0) - { - if (request->records != NULL || request->record_component_seen != NULL || - request->record_component_seen_capacity != 0) + if (request->record_count == 0) { + if (request->records != NULL || request->record_component_seen != NULL + || request->record_component_seen_capacity != 0) return RF_PAGE_PROOF_DETAIL_INVALID_ARGUMENT; for (i = 0; i < request->participant_count; i++) - if ((request->participants[i].flags & - RF_CONTRIBUTOR_CUT_EXPLICIT_EMPTY) == 0) + if ((request->participants[i].flags & RF_CONTRIBUTOR_CUT_EXPLICIT_EMPTY) == 0) return RF_PAGE_PROOF_DETAIL_PARTICIPANT_MISSING; return RF_PAGE_PROOF_DETAIL_OK; } - if (request->record_count > RF_PAGE_STABLE_MAX_EDGES || - request->records == NULL || request->record_component_seen == NULL || - request->record_component_seen_capacity < - (Size) request->record_count * RF_PAGE_STABLE_MAX_COMPONENTS) + if (request->record_count > RF_PAGE_STABLE_MAX_EDGES || request->records == NULL + || request->record_component_seen == NULL + || request->record_component_seen_capacity + < (Size)request->record_count * RF_PAGE_STABLE_MAX_COMPONENTS) return RF_PAGE_PROOF_DETAIL_CAPACITY; memset(request->record_component_seen, 0, - (Size) request->record_count * RF_PAGE_STABLE_MAX_COMPONENTS); - for (i = 0; i < request->record_count; i++) - { + (Size)request->record_count * RF_PAGE_STABLE_MAX_COMPONENTS); + for (i = 0; i < request->record_count; i++) { const RfPageReplayRecordV1 *record = &request->records[i]; const RfDetachedRecordPlanV1 *plan = record->record_plan; const RfPageReplayRecordIdentityV1 *identity = &record->identity; const RfContributorStreamCutV1 *cut; - if (plan == NULL || !plan->preflight_complete || - plan->source_record == NULL || plan->source_record->record == NULL || - plan->component_count > RF_PAGE_STABLE_MAX_COMPONENTS || - record->reserved_zero != 0 || - record->participant_index >= request->participant_count) + if (plan == NULL || !plan->preflight_complete || plan->source_record == NULL + || plan->source_record->record == NULL + || plan->component_count > RF_PAGE_STABLE_MAX_COMPONENTS || record->reserved_zero != 0 + || record->participant_index >= request->participant_count) return RF_PAGE_PROOF_DETAIL_COMPONENT_INCOMPLETE; cut = &request->participants[record->participant_index]; - if (identity->system_identifier != request->system_identifier || - memcmp(identity->storage_uuid, request->storage_uuid, 16) != 0 || - identity->origin_thread != cut->failed_thread || - identity->timeline_id != cut->timeline_id || - identity->reserved_zero != 0 || identity->reserved_zero2 != 0 || - XLogRecPtrIsInvalid(identity->read_rec_ptr) || - XLogRecPtrIsInvalid(identity->end_rec_ptr) || - identity->read_rec_ptr >= identity->end_rec_ptr || - identity->read_rec_ptr != plan->source_record->ReadRecPtr || - identity->end_rec_ptr != plan->source_record->EndRecPtr || - identity->record_crc != plan->source_record->record->header.xl_crc || - identity->rmid != plan->source_record->record->header.xl_rmid || - identity->info != plan->source_record->record->header.xl_info || - (cut->flags & RF_CONTRIBUTOR_CUT_EXPLICIT_EMPTY) != 0 || - identity->read_rec_ptr < cut->scan_begin_inclusive || - identity->end_rec_ptr > cut->scan_end_exclusive) + if (identity->system_identifier != request->system_identifier + || memcmp(identity->storage_uuid, request->storage_uuid, 16) != 0 + || identity->origin_thread != cut->failed_thread + || identity->timeline_id != cut->timeline_id || identity->reserved_zero != 0 + || identity->reserved_zero2 != 0 || XLogRecPtrIsInvalid(identity->read_rec_ptr) + || XLogRecPtrIsInvalid(identity->end_rec_ptr) + || identity->read_rec_ptr >= identity->end_rec_ptr + || identity->read_rec_ptr != plan->source_record->ReadRecPtr + || identity->end_rec_ptr != plan->source_record->EndRecPtr + || identity->record_crc != plan->source_record->record->header.xl_crc + || identity->rmid != plan->source_record->record->header.xl_rmid + || identity->info != plan->source_record->record->header.xl_info + || (cut->flags & RF_CONTRIBUTOR_CUT_EXPLICIT_EMPTY) != 0 + || identity->read_rec_ptr < cut->scan_begin_inclusive + || identity->end_rec_ptr > cut->scan_end_exclusive) return RF_PAGE_PROOF_DETAIL_SOURCE_GAP; - if (i > 0 && - (request->records[i - 1].participant_index > - record->participant_index || - (request->records[i - 1].participant_index == - record->participant_index && - (request->records[i - 1].identity.read_rec_ptr > - identity->read_rec_ptr || - (request->records[i - 1].identity.read_rec_ptr == - identity->read_rec_ptr && - request->records[i - 1].identity.end_rec_ptr >= - identity->end_rec_ptr))))) + if (i > 0 + && (request->records[i - 1].participant_index > record->participant_index + || (request->records[i - 1].participant_index == record->participant_index + && (request->records[i - 1].identity.read_rec_ptr > identity->read_rec_ptr + || (request->records[i - 1].identity.read_rec_ptr == identity->read_rec_ptr + && request->records[i - 1].identity.end_rec_ptr + >= identity->end_rec_ptr))))) return RF_PAGE_PROOF_DETAIL_ORDER_VIOLATION; component_counts[record->participant_index] += plan->component_count; { - uint32 j; + uint32 j; for (j = 0; j < plan->component_count; j++) - if (plan->components[j].owner == - RF_DETACHED_COMPONENT_PAGE_CODEC) + if (plan->components[j].owner == RF_DETACHED_COMPONENT_PAGE_CODEC) page_counts[record->participant_index]++; } } for (i = 0; i < request->participant_count; i++) - if (component_counts[i] != request->participants[i].component_count || - page_counts[i] != request->participants[i].contributor_count) + if (component_counts[i] != request->participants[i].component_count + || page_counts[i] != request->participants[i].contributor_count) return RF_PAGE_PROOF_DETAIL_PARTICIPANT_MISSING; return RF_PAGE_PROOF_DETAIL_OK; } @@ -339,20 +310,17 @@ validate_record_table(const RfPageReplayBatchRequestV1 *request) static RfPageProofDetailV1 validate_record_component_closure(const RfPageReplayBatchRequestV1 *request) { - uint32 i; + uint32 i; - for (i = 0; i < request->record_count; i++) - { + for (i = 0; i < request->record_count; i++) { const RfDetachedRecordPlanV1 *plan = request->records[i].record_plan; - uint32 j; + uint32 j; - for (j = 0; j < plan->component_count; j++) - { - bool seen = request->record_component_seen[ - (Size) i * RF_PAGE_STABLE_MAX_COMPONENTS + j] != 0; + for (j = 0; j < plan->component_count; j++) { + bool seen + = request->record_component_seen[(Size)i * RF_PAGE_STABLE_MAX_COMPONENTS + j] != 0; - if ((plan->components[j].owner == - RF_DETACHED_COMPONENT_PAGE_CODEC) != seen) + if ((plan->components[j].owner == RF_DETACHED_COMPONENT_PAGE_CODEC) != seen) return RF_PAGE_PROOF_DETAIL_COMPONENT_INCOMPLETE; } } @@ -360,30 +328,24 @@ validate_record_component_closure(const RfPageReplayBatchRequestV1 *request) } static RfPageProofDetailV1 -rf_page_replay_batch_run(const RfPageReplayBatchRequestV1 *request, - RfPageReplayBatchProofV1 *proof, bool use_smgr) +rf_page_replay_batch_run(const RfPageReplayBatchRequestV1 *request, RfPageReplayBatchProofV1 *proof, + bool use_smgr) { RfPageStorageInstallComponentV1 components[RF_PAGE_STABLE_MAX_COMPONENTS]; RfPageStorageInstallRequestV1 install_request; RfPageReplayBatchProofV1 completed; - uint32 step_total = 0; - uint32 i; + uint32 step_total = 0; + uint32 i; RfPageProofDetailV1 detail; - if (request == NULL || proof == NULL || request->targets == NULL || - request->canonical_pages == NULL || - request->install_prepared_pages == NULL || - request->install_io_pages == NULL || request->authority == NULL || - request->target_count == 0 || - request->target_count > RF_PAGE_STABLE_MAX_COMPONENTS || - request->canonical_capacity < - (Size) request->target_count * BLCKSZ || - request->install_prepared_capacity < - (Size) request->target_count * BLCKSZ || - request->install_io_capacity < - (Size) request->target_count * BLCKSZ || - (!use_smgr && request->storage == NULL) || - (use_smgr && request->storage != NULL)) + if (request == NULL || proof == NULL || request->targets == NULL + || request->canonical_pages == NULL || request->install_prepared_pages == NULL + || request->install_io_pages == NULL || request->authority == NULL + || request->target_count == 0 || request->target_count > RF_PAGE_STABLE_MAX_COMPONENTS + || request->canonical_capacity < (Size)request->target_count * BLCKSZ + || request->install_prepared_capacity < (Size)request->target_count * BLCKSZ + || request->install_io_capacity < (Size)request->target_count * BLCKSZ + || (!use_smgr && request->storage == NULL) || (use_smgr && request->storage != NULL)) return RF_PAGE_PROOF_DETAIL_INVALID_ARGUMENT; if (!request->global_preflight_ok) return RF_PAGE_PROOF_DETAIL_COMPONENT_INCOMPLETE; @@ -391,15 +353,15 @@ rf_page_replay_batch_run(const RfPageReplayBatchRequestV1 *request, if (detail != RF_PAGE_PROOF_DETAIL_OK) return detail; - for (i = 0; i < request->target_count; i++) - { - if (request->targets[i].page_identity.system_identifier != - request->system_identifier || - memcmp(request->targets[i].page_identity.storage_uuid, - request->storage_uuid, 16) != 0) + for (i = 0; i < request->target_count; i++) { + if (request->targets[i].page_identity.system_identifier != request->system_identifier + || memcmp(request->targets[i].page_identity.storage_uuid, request->storage_uuid, 16) + != 0) return RF_PAGE_PROOF_DETAIL_IDENTITY_MISMATCH; - if (i > 0 && identity_compare(&request->targets[i - 1].page_identity, - &request->targets[i].page_identity) >= 0) + if (i > 0 + && identity_compare(&request->targets[i - 1].page_identity, + &request->targets[i].page_identity) + >= 0) return RF_PAGE_PROOF_DETAIL_ORDER_VIOLATION; detail = validate_target(request, &request->targets[i], &step_total); if (detail != RF_PAGE_PROOF_DETAIL_OK) @@ -410,27 +372,23 @@ rf_page_replay_batch_run(const RfPageReplayBatchRequestV1 *request, return detail; memset(components, 0, sizeof(components)); - for (i = 0; i < request->target_count; i++) - { + for (i = 0; i < request->target_count; i++) { const RfPageReplayTargetV1 *target = &request->targets[i]; - char *canonical = request->canonical_pages + (Size) i * BLCKSZ; - uint32 j; + char *canonical = request->canonical_pages + (Size)i * BLCKSZ; + uint32 j; memcpy(canonical, target->base_page, BLCKSZ); - for (j = 0; j < target->step_count; j++) - { - const RfDetachedRecordPlanV1 *plan = request->records[ - target->steps[j].record_index].record_plan; + for (j = 0; j < target->step_count; j++) { + const RfDetachedRecordPlanV1 *plan + = request->records[target->steps[j].record_index].record_plan; - detail = rf_page_detached_apply_v1( - plan, - target->steps[j].component_index, canonical, canonical); + detail = rf_page_detached_apply_v1(plan, target->steps[j].component_index, canonical, + canonical); if (detail != RF_PAGE_PROOF_DETAIL_OK) return detail; } - if (page_all_zero(canonical) || !page_layout_valid(canonical) || - ((PageHeader) canonical)->pd_block_scn != - target->expected_result.mutation_token) + if (page_all_zero(canonical) || !page_layout_valid(canonical) + || ((PageHeader)canonical)->pd_block_scn != target->expected_result.mutation_token) return RF_PAGE_PROOF_DETAIL_IMAGE_INTEGRITY_FAILED; components[i].page_identity = target->page_identity; components[i].before_kind = target->before_kind; @@ -452,12 +410,10 @@ rf_page_replay_batch_run(const RfPageReplayBatchRequestV1 *request, memset(&completed, 0, sizeof(completed)); #ifndef USE_CLUSTER_UNIT if (use_smgr) - detail = rf_page_storage_install_smgr_v1(&install_request, - &completed.install); + detail = rf_page_storage_install_smgr_v1(&install_request, &completed.install); else #endif - detail = rf_page_storage_install_execute_v1(&install_request, - &completed.install); + detail = rf_page_storage_install_execute_v1(&install_request, &completed.install); if (detail != RF_PAGE_PROOF_DETAIL_OK) return detail; completed.target_count = request->target_count; diff --git a/src/backend/cluster/cluster_page_rmgr.c b/src/backend/cluster/cluster_page_rmgr.c index 9c06a07d6ce..6d6c99701f8 100644 --- a/src/backend/cluster/cluster_page_rmgr.c +++ b/src/backend/cluster/cluster_page_rmgr.c @@ -53,40 +53,20 @@ * is forbidden, 8.A/R11). */ static const ClusterPageRmgrCensusEntry cluster_page_census_opcode[] = { - { - RM_HEAP_ID, XLOG_HEAP_INSERT, 0, - CLUSTER_PAGE_CLASS_NORMAL, true, true, false, false - }, - { - RM_HEAP_ID, XLOG_HEAP_DELETE, 0, - CLUSTER_PAGE_CLASS_NORMAL, true, true, false, false - }, - { - RM_HEAP_ID, XLOG_HEAP_UPDATE, 0, - CLUSTER_PAGE_CLASS_NORMAL, true, true, false, false - }, - { - RM_HEAP_ID, XLOG_HEAP_HOT_UPDATE, 0, - CLUSTER_PAGE_CLASS_NORMAL, true, true, false, false - }, - { - /* LOCK/CONFIRM/INPLACE: page-affecting NORMAL row, but no + { RM_HEAP_ID, XLOG_HEAP_INSERT, 0, CLUSTER_PAGE_CLASS_NORMAL, true, true, false, false }, + { RM_HEAP_ID, XLOG_HEAP_DELETE, 0, CLUSTER_PAGE_CLASS_NORMAL, true, true, false, false }, + { RM_HEAP_ID, XLOG_HEAP_UPDATE, 0, CLUSTER_PAGE_CLASS_NORMAL, true, true, false, false }, + { RM_HEAP_ID, XLOG_HEAP_HOT_UPDATE, 0, CLUSTER_PAGE_CLASS_NORMAL, true, true, false, false }, + { /* LOCK/CONFIRM/INPLACE: page-affecting NORMAL row, but no * differential evidence -> never registers -> UNKNOWN at runtime. */ - RM_HEAP_ID, XLOG_HEAP_LOCK, XLOG_HEAP_OPMASK, - CLUSTER_PAGE_CLASS_NORMAL, true, false, false, false - }, - { - /* XLOG_HEAP_INIT_PAGE: full page re-initialization ATTRIBUTE. + RM_HEAP_ID, XLOG_HEAP_LOCK, XLOG_HEAP_OPMASK, CLUSTER_PAGE_CLASS_NORMAL, true, false, false, + false }, + { /* XLOG_HEAP_INIT_PAGE: full page re-initialization ATTRIBUTE. * This row fact is not a §4.6 full-init RULE (expected class state * + result-version proof are RED), so the classifier still * returns UNKNOWN for WILL_INIT records (PU-17). */ - RM_HEAP_ID, XLOG_HEAP_INIT_PAGE, 0, - CLUSTER_PAGE_CLASS_NEW, true, false, true, false - }, - { - RM_GENERIC_ID, 0, 0, - CLUSTER_PAGE_CLASS_NORMAL, true, true, false, false - }, + RM_HEAP_ID, XLOG_HEAP_INIT_PAGE, 0, CLUSTER_PAGE_CLASS_NEW, true, false, true, false }, + { RM_GENERIC_ID, 0, 0, CLUSTER_PAGE_CLASS_NORMAL, true, true, false, false }, }; /* @@ -128,17 +108,16 @@ static const ClusterPageRmgrCensusEntry cluster_page_census_rmgr[] = { }; bool -cluster_page_rmgr_census_lookup(uint8 rmid, uint16 opcode, - ClusterPageRmgrCensusEntry *out) +cluster_page_rmgr_census_lookup(uint8 rmid, uint16 opcode, ClusterPageRmgrCensusEntry *out) { - int i; + int i; if (out == NULL) return false; memset(out, 0, sizeof(*out)); /* Opcode-granular rows first (exact or masked match). */ - for (i = 0; i < (int) lengthof(cluster_page_census_opcode); i++) { + for (i = 0; i < (int)lengthof(cluster_page_census_opcode); i++) { const ClusterPageRmgrCensusEntry *row = &cluster_page_census_opcode[i]; if (row->rmid != rmid) @@ -153,7 +132,7 @@ cluster_page_rmgr_census_lookup(uint8 rmid, uint16 opcode, } /* Rmgr-granular rows (any opcode of that rmgr). */ - for (i = 0; i < (int) lengthof(cluster_page_census_rmgr); i++) { + for (i = 0; i < (int)lengthof(cluster_page_census_rmgr); i++) { const ClusterPageRmgrCensusEntry *row = &cluster_page_census_rmgr[i]; if (row->rmid == rmid) { @@ -161,7 +140,7 @@ cluster_page_rmgr_census_lookup(uint8 rmid, uint16 opcode, return true; } } - return false; /* unknown rmgr: fail closed */ + return false; /* unknown rmgr: fail closed */ } /* --------------------------------------------------------------------- @@ -171,17 +150,16 @@ cluster_page_rmgr_census_lookup(uint8 rmid, uint16 opcode, void cluster_page_rmgr_populate_known_set(void) { - int i; + int i; /* Only rows with byte-for-byte differential evidence register: an * unproven opcode must keep classifying UNKNOWN (spec §4.2: a NORMAL * row without every producer/decoder/verifier is BLOCKED). */ - for (i = 0; i < (int) lengthof(cluster_page_census_opcode); i++) { + for (i = 0; i < (int)lengthof(cluster_page_census_opcode); i++) { const ClusterPageRmgrCensusEntry *row = &cluster_page_census_opcode[i]; if (row->known_delta && row->affects_page) - (void) cluster_page_class_register_known_opcode(row->rmid, - row->opcode); + (void)cluster_page_class_register_known_opcode(row->rmid, row->opcode); } } @@ -190,25 +168,23 @@ cluster_page_rmgr_populate_known_set(void) * --------------------------------------------------------------------- */ bool -cluster_page_redo_decode(XLogReaderState *record, uint8 block_id, - ClusterPageRedoDecoded *out) +cluster_page_redo_decode(XLogReaderState *record, uint8 block_id, ClusterPageRedoDecoded *out) { ClusterPageRmgrCensusEntry row; - DecodedBkpBlock *blk; - uint8 rmid; + const DecodedBkpBlock *blk; + uint8 rmid; if (record == NULL || out == NULL) return false; memset(out, 0, sizeof(*out)); if (!XLogRecHasBlockRef(record, block_id)) - return false; /* no block reference: nothing to decode */ + return false; /* no block reference: nothing to decode */ rmid = XLogRecGetRmid(record); - if (!cluster_page_rmgr_census_lookup(rmid, XLogRecGetInfo(record) & XLR_RMGR_INFO_MASK, - &row)) - return false; /* unknown rmgr/opcode: fail closed */ + if (!cluster_page_rmgr_census_lookup(rmid, XLogRecGetInfo(record) & XLR_RMGR_INFO_MASK, &row)) + return false; /* unknown rmgr/opcode: fail closed */ if (!row.affects_page) - return false; /* not a page-affecting record */ + return false; /* not a page-affecting record */ /* Identity comes straight from the decoded block reference (the * XLogRecGetBlockTag backend helper is not linked into the standalone @@ -218,8 +194,8 @@ cluster_page_redo_decode(XLogReaderState *record, uint8 block_id, out->identity.rlocator = blk->rlocator; out->identity.forknum = blk->forknum; out->identity.blocknum = blk->blkno; - out->full_image = XLogRecHasBlockImage(record, block_id) - && XLogRecBlockImageApply(record, block_id); + out->full_image + = XLogRecHasBlockImage(record, block_id) && XLogRecBlockImageApply(record, block_id); /* BKPBLOCK_WILL_INIT rides the block's fork_flags (xlogrecord.h). */ out->will_init = (blk->flags & BKPBLOCK_WILL_INIT) != 0; /* §3.1 hints: locator/hint only, never VersionToken. */ @@ -229,8 +205,8 @@ cluster_page_redo_decode(XLogReaderState *record, uint8 block_id, return true; } -#else /* !USE_PGRAC_CLUSTER */ +#else /* !USE_PGRAC_CLUSTER */ /* Disable-cluster build: this file compiles to nothing. */ -#endif /* USE_PGRAC_CLUSTER */ +#endif /* USE_PGRAC_CLUSTER */ diff --git a/src/backend/cluster/cluster_page_set.c b/src/backend/cluster/cluster_page_set.c index 5cc2acd5bcd..7f0ac46862b 100644 --- a/src/backend/cluster/cluster_page_set.c +++ b/src/backend/cluster/cluster_page_set.c @@ -29,8 +29,7 @@ * (equal SCN with different incarnation/identity is NOT adjacency, * spec §3.4/PU-06/PU-27). */ static bool -cluster_page_chain_adjacent(const ClusterPageRedoChange *a, - const ClusterPageRedoChange *b) +cluster_page_chain_adjacent(const ClusterPageRedoChange *a, const ClusterPageRedoChange *b) { if (!cluster_page_version_valid(&a->result_version) || !cluster_page_version_valid(&b->expected_before)) @@ -41,7 +40,7 @@ cluster_page_chain_adjacent(const ClusterPageRedoChange *a, ClusterPageClosureResult cluster_page_contributor_closure(const ClusterBlockRecoverySet *set) { - int i; + int i; if (set == NULL || set->n_contributors < 0) return CLUSTER_PAGE_CLOSURE_INVALID_INPUT; @@ -62,8 +61,7 @@ cluster_page_contributor_closure(const ClusterBlockRecoverySet *set) * the production stability witness the PGDEL-04 CURRENT validator * carries — the version equality here is the chain half of that). */ if (set->n_contributors == 0) { - if (cluster_page_version_equal(&set->source_version, - &set->terminal_version)) + if (cluster_page_version_equal(&set->source_version, &set->terminal_version)) return CLUSTER_PAGE_CLOSURE_OK; return CLUSTER_PAGE_CLOSURE_GAP; } @@ -90,16 +88,14 @@ cluster_page_contributor_closure(const ClusterBlockRecoverySet *set) /* First contributor must join from the selected source version. */ if (i == 0) { - if (!cluster_page_version_equal(&set->source_version, - &c->expected_before)) + if (!cluster_page_version_equal(&set->source_version, &c->expected_before)) return CLUSTER_PAGE_CLOSURE_GAP; } else if (!cluster_page_chain_adjacent(&set->contributors[i - 1], c)) { /* Incarnation boundary: the versions are unequal (equal SCN * with different incarnation is a mismatch, PU-06). Report * the incarnation cross distinctly so the caller can route * to the PC-INCARNATION lifecycle instead of a silent gap. */ - if (cluster_page_identity_equal(&set->contributors[i - 1].identity, - &c->identity) + if (cluster_page_identity_equal(&set->contributors[i - 1].identity, &c->identity) && set->contributors[i - 1].result_version.incarnation != c->expected_before.incarnation) return CLUSTER_PAGE_CLOSURE_INCARNATION_CROSS; @@ -110,9 +106,8 @@ cluster_page_contributor_closure(const ClusterBlockRecoverySet *set) /* Terminal: the last result must equal the required terminal EXACTLY * (terminal uniqueness by construction — a mismatch fails instead of * guessing). */ - if (!cluster_page_version_equal( - &set->contributors[set->n_contributors - 1].result_version, - &set->terminal_version)) + if (!cluster_page_version_equal(&set->contributors[set->n_contributors - 1].result_version, + &set->terminal_version)) return CLUSTER_PAGE_CLOSURE_TERMINAL_MISMATCH; return CLUSTER_PAGE_CLOSURE_OK; } @@ -121,11 +116,10 @@ bool cluster_page_contributor_chain_covers(const ClusterBlockRecoverySet *set, const ClusterPageVersion *from_version) { - int start; - int i; + int start; + int i; - if (set == NULL || from_version == NULL - || !cluster_page_version_valid(from_version)) + if (set == NULL || from_version == NULL || !cluster_page_version_valid(from_version)) return false; if (!cluster_page_version_valid(&set->source_version) || !cluster_page_version_valid(&set->terminal_version)) @@ -138,14 +132,13 @@ cluster_page_contributor_chain_covers(const ClusterBlockRecoverySet *set, * adjacent and lands on the terminal. */ start = -1; for (i = 0; i < set->n_contributors; i++) { - if (cluster_page_version_equal(&set->contributors[i].result_version, - from_version)) { + if (cluster_page_version_equal(&set->contributors[i].result_version, from_version)) { start = i; break; } } if (start < 0) - return false; /* from_version not produced by any change */ + return false; /* from_version not produced by any change */ for (i = start; i < set->n_contributors; i++) { const ClusterPageRedoChange *c = &set->contributors[i]; @@ -156,11 +149,9 @@ cluster_page_contributor_chain_covers(const ClusterBlockRecoverySet *set, if (!cluster_page_version_valid(&c->expected_before) || !cluster_page_version_valid(&c->result_version)) return false; - if (i > start && !cluster_page_chain_adjacent(&set->contributors[i - 1], - c)) + if (i > start && !cluster_page_chain_adjacent(&set->contributors[i - 1], c)) return false; } - return cluster_page_version_equal( - &set->contributors[set->n_contributors - 1].result_version, - &set->terminal_version); + return cluster_page_version_equal(&set->contributors[set->n_contributors - 1].result_version, + &set->terminal_version); } diff --git a/src/backend/cluster/cluster_page_source.c b/src/backend/cluster/cluster_page_source.c index 5b847400fb7..516852b54d1 100644 --- a/src/backend/cluster/cluster_page_source.c +++ b/src/backend/cluster/cluster_page_source.c @@ -58,8 +58,7 @@ cluster_page_source_validate_current(const ClusterPageSourceValidateInput *in) */ if (!cluster_page_source_base_ok(in)) return false; - return in->integrity_ok && in->stability_ok && in->lineage_ok - && in->owner_ok; + return in->integrity_ok && in->stability_ok && in->lineage_ok && in->owner_ok; } bool @@ -76,8 +75,8 @@ cluster_page_source_validate_pi(const ClusterPageSourceValidateInput *in) */ if (!cluster_page_source_base_ok(in)) return false; - return in->integrity_ok && in->ship_boundary_ok && in->stability_ok - && in->lineage_ok && in->owner_ok; + return in->integrity_ok && in->ship_boundary_ok && in->stability_ok && in->lineage_ok + && in->owner_ok; } bool @@ -101,55 +100,52 @@ cluster_page_source_validate_storage(const ClusterPageSourceValidateInput *in) */ if (!cluster_page_source_base_ok(in)) return false; - return in->integrity_ok && in->lineage_ok && in->anchored_ok - && in->coverage_ok && in->fresh_ok && in->contributors_closed; + return in->integrity_ok && in->lineage_ok && in->anchored_ok && in->coverage_ok && in->fresh_ok + && in->contributors_closed; } static int cluster_page_source_kind_rank(ClusterPageSourceKind kind) { - switch (kind) - { - case CLUSTER_PAGE_SOURCE_CURRENT: - return 0; /* §6.2: prefer CURRENT */ - case CLUSTER_PAGE_SOURCE_PI: - return 1; - case CLUSTER_PAGE_SOURCE_STORAGE: - return 2; /* last resort: checkpointed storage */ + switch (kind) { + case CLUSTER_PAGE_SOURCE_CURRENT: + return 0; /* §6.2: prefer CURRENT */ + case CLUSTER_PAGE_SOURCE_PI: + return 1; + case CLUSTER_PAGE_SOURCE_STORAGE: + return 2; /* last resort: checkpointed storage */ } return 3; } int cluster_page_source_select(const ClusterPageSourceKind *kinds, - const ClusterPageSourceValidateInput *inputs, - int n) + const ClusterPageSourceValidateInput *inputs, int n) { - bool valid[8]; - int nvalid = 0; - int first = -1; - int i; + bool valid[8]; + int nvalid = 0; + int first = -1; + int i; if (kinds == NULL || inputs == NULL || n < 0) return -1; - if (n > (int) lengthof(valid)) - return -1; /* bounded: fail closed beyond the table */ + if (n > (int)lengthof(valid)) + return -1; /* bounded: fail closed beyond the table */ for (i = 0; i < n; i++) { - switch (kinds[i]) - { - case CLUSTER_PAGE_SOURCE_CURRENT: - valid[i] = cluster_page_source_validate_current(&inputs[i]); - break; - case CLUSTER_PAGE_SOURCE_PI: - valid[i] = cluster_page_source_validate_pi(&inputs[i]); - break; - case CLUSTER_PAGE_SOURCE_STORAGE: - valid[i] = cluster_page_source_validate_storage(&inputs[i]); - break; - default: - valid[i] = false; - break; + switch (kinds[i]) { + case CLUSTER_PAGE_SOURCE_CURRENT: + valid[i] = cluster_page_source_validate_current(&inputs[i]); + break; + case CLUSTER_PAGE_SOURCE_PI: + valid[i] = cluster_page_source_validate_pi(&inputs[i]); + break; + case CLUSTER_PAGE_SOURCE_STORAGE: + valid[i] = cluster_page_source_validate_storage(&inputs[i]); + break; + default: + valid[i] = false; + break; } if (valid[i]) { nvalid++; @@ -166,16 +162,15 @@ cluster_page_source_select(const ClusterPageSourceKind *kinds, * corruption/BLOCKED — never max-SCN, max-LSN or majority. */ if (nvalid > 1) { for (i = 0; i < n; i++) { - int j; + int j; if (!valid[i]) continue; for (j = i + 1; j < n; j++) { if (!valid[j]) continue; - if (!cluster_page_version_equal(inputs[i].source_version, - inputs[j].source_version)) - return -1; /* conflicting versions: BLOCKED */ + if (!cluster_page_version_equal(inputs[i].source_version, inputs[j].source_version)) + return -1; /* conflicting versions: BLOCKED */ } } /* Equal versions: §6.2 preference CURRENT > PI > STORAGE. */ diff --git a/src/backend/cluster/cluster_page_stable_base.c b/src/backend/cluster/cluster_page_stable_base.c index baefbc445bc..0c5cfde1947 100644 --- a/src/backend/cluster/cluster_page_stable_base.c +++ b/src/backend/cluster/cluster_page_stable_base.c @@ -18,16 +18,15 @@ #define stable_alloc0(count_, size_) calloc((count_), (size_)) #define stable_free(pointer_) free((pointer_)) #else -#define stable_alloc0(count_, size_) palloc0((Size) (count_) * (size_)) +#define stable_alloc0(count_, size_) palloc0((Size)(count_) * (size_)) #define stable_free(pointer_) pfree((pointer_)) #endif #define RF_PAGE_STABLE_PROOF_MAGIC UINT32_C(0x52505350) -struct RfPageStableBaseProofV1 -{ - uint32 magic; - uint32 participant_count; +struct RfPageStableBaseProofV1 { + uint32 magic; + uint32 participant_count; RfPageIdentityV1 page_identity; RfPageVersionV1 expected_result; RfPageStableSelectionV1 selection; @@ -44,8 +43,8 @@ struct RfPageStableBaseProofV1 static bool bytes_nonzero(const uint8 *bytes, size_t size) { - uint8 value = 0; - size_t i; + uint8 value = 0; + size_t i; for (i = 0; i < size; i++) value |= bytes[i]; @@ -55,46 +54,40 @@ bytes_nonzero(const uint8 *bytes, size_t size) bool rf_page_identity_valid_v1(const RfPageIdentityV1 *identity) { - return identity != NULL && identity->system_identifier != 0 && - bytes_nonzero(identity->storage_uuid, sizeof(identity->storage_uuid)) && - identity->locator.spcOid != InvalidOid && - identity->locator.dbOid != InvalidOid && - identity->locator.relNumber != InvalidRelFileNumber && - identity->blockno != InvalidBlockNumber && identity->reserved_zero == 0; + return identity != NULL && identity->system_identifier != 0 + && bytes_nonzero(identity->storage_uuid, sizeof(identity->storage_uuid)) + && identity->locator.spcOid != InvalidOid && identity->locator.dbOid != InvalidOid + && identity->locator.relNumber != InvalidRelFileNumber + && identity->blockno != InvalidBlockNumber && identity->reserved_zero == 0; } bool -rf_page_identity_equal_v1(const RfPageIdentityV1 *left, - const RfPageIdentityV1 *right) +rf_page_identity_equal_v1(const RfPageIdentityV1 *left, const RfPageIdentityV1 *right) { - return left != NULL && right != NULL && - left->system_identifier == right->system_identifier && - memcmp(left->storage_uuid, right->storage_uuid, 16) == 0 && - RelFileLocatorEquals(left->locator, right->locator) && - left->forknum == right->forknum && left->blockno == right->blockno && - left->reserved_zero == 0 && right->reserved_zero == 0; + return left != NULL && right != NULL && left->system_identifier == right->system_identifier + && memcmp(left->storage_uuid, right->storage_uuid, 16) == 0 + && RelFileLocatorEquals(left->locator, right->locator) && left->forknum == right->forknum + && left->blockno == right->blockno && left->reserved_zero == 0 + && right->reserved_zero == 0; } bool rf_page_version_present_v1(const RfPageVersionV1 *version) { - return version != NULL && - bytes_nonzero(version->segment_incarnation, - sizeof(version->segment_incarnation)) && - version->mutation_token != 0; + return version != NULL + && bytes_nonzero(version->segment_incarnation, sizeof(version->segment_incarnation)) + && version->mutation_token != 0; } static void -edge_result_version(const RfPageStableEdgeInputV1 *edge, - RfPageVersionV1 *result) +edge_result_version(const RfPageStableEdgeInputV1 *edge, RfPageVersionV1 *result) { memcpy(result->segment_incarnation, edge->edge.result_incarnation, 16); result->mutation_token = edge->result_token; } static bool -edge_before_vertex_equal(const RfPageStableEdgeInputV1 *left, - const RfPageStableEdgeInputV1 *right) +edge_before_vertex_equal(const RfPageStableEdgeInputV1 *left, const RfPageStableEdgeInputV1 *right) { if (left->edge.before_kind != right->edge.before_kind) return false; @@ -102,8 +95,7 @@ edge_before_vertex_equal(const RfPageStableEdgeInputV1 *left, } static bool -edge_result_equal(const RfPageStableEdgeInputV1 *left, - const RfPageStableEdgeInputV1 *right) +edge_result_equal(const RfPageStableEdgeInputV1 *left, const RfPageStableEdgeInputV1 *right) { RfPageVersionV1 left_result; RfPageVersionV1 right_result; @@ -117,41 +109,35 @@ static bool record_identity_equal(const RfPageReplayRecordIdentityV1 *left, const RfPageReplayRecordIdentityV1 *right) { - return left->system_identifier == right->system_identifier && - memcmp(left->storage_uuid, right->storage_uuid, 16) == 0 && - left->origin_thread == right->origin_thread && - left->reserved_zero == right->reserved_zero && - left->timeline_id == right->timeline_id && - left->read_rec_ptr == right->read_rec_ptr && - left->end_rec_ptr == right->end_rec_ptr && - left->record_crc == right->record_crc && - left->rmid == right->rmid && left->info == right->info && - left->reserved_zero2 == right->reserved_zero2; + return left->system_identifier == right->system_identifier + && memcmp(left->storage_uuid, right->storage_uuid, 16) == 0 + && left->origin_thread == right->origin_thread + && left->reserved_zero == right->reserved_zero && left->timeline_id == right->timeline_id + && left->read_rec_ptr == right->read_rec_ptr && left->end_rec_ptr == right->end_rec_ptr + && left->record_crc == right->record_crc && left->rmid == right->rmid + && left->info == right->info && left->reserved_zero2 == right->reserved_zero2; } static bool -edge_exact_equal(const RfPageStableEdgeInputV1 *left, - const RfPageStableEdgeInputV1 *right) +edge_exact_equal(const RfPageStableEdgeInputV1 *left, const RfPageStableEdgeInputV1 *right) { - return record_identity_equal(&left->record_identity, - &right->record_identity) && - left->participant_index == right->participant_index && - left->component_count == right->component_count && - rf_page_identity_equal_v1(&left->page_identity, - &right->page_identity) && - memcmp(&left->edge, &right->edge, sizeof(left->edge)) == 0 && - left->result_token == right->result_token && - memcmp(left->anchor_digest, right->anchor_digest, 32) == 0 && - left->record_complete == right->record_complete && - left->opcode_supported == right->opcode_supported && - left->side_complete == right->side_complete && - left->image_integrity_ok == right->image_integrity_ok; + return record_identity_equal(&left->record_identity, &right->record_identity) + && left->participant_index == right->participant_index + && left->component_count == right->component_count + && rf_page_identity_equal_v1(&left->page_identity, &right->page_identity) + && memcmp(&left->edge, &right->edge, sizeof(left->edge)) == 0 + && left->result_token == right->result_token + && memcmp(left->anchor_digest, right->anchor_digest, 32) == 0 + && left->record_complete == right->record_complete + && left->opcode_supported == right->opcode_supported + && left->side_complete == right->side_complete + && left->image_integrity_ok == right->image_integrity_ok; } static bool edge_is_duplicate_of_prior(const RfContributorVectorV1 *vector, uint32 index) { - uint32 i; + uint32 i; for (i = 0; i < index; i++) if (edge_exact_equal(&vector->edges[i], &vector->edges[index])) @@ -162,28 +148,26 @@ edge_is_duplicate_of_prior(const RfContributorVectorV1 *vector, uint32 index) static bool edge_anchor_flags_valid(uint16 flags) { - return flags == (RF_PAGE_EDGE_FULL_IMAGE_APPLY | - RF_PAGE_EDGE_FULL_COVERAGE) || - flags == (RF_PAGE_EDGE_WILL_INIT | RF_PAGE_EDGE_FULL_COVERAGE) || - flags == (RF_PAGE_EDGE_FULL_IMAGE_APPLY | RF_PAGE_EDGE_WILL_INIT | - RF_PAGE_EDGE_FULL_COVERAGE); + return flags == (RF_PAGE_EDGE_FULL_IMAGE_APPLY | RF_PAGE_EDGE_FULL_COVERAGE) + || flags == (RF_PAGE_EDGE_WILL_INIT | RF_PAGE_EDGE_FULL_COVERAGE) + || flags + == (RF_PAGE_EDGE_FULL_IMAGE_APPLY | RF_PAGE_EDGE_WILL_INIT + | RF_PAGE_EDGE_FULL_COVERAGE); } static RfPageProofDetailV1 -validate_edge(const RfPageStableGraphRequestV1 *request, - const RfPageStableEdgeInputV1 *edge) +validate_edge(const RfPageStableGraphRequestV1 *request, const RfPageStableEdgeInputV1 *edge) { const RfContributorVectorV1 *vector = request->contributors; const RfContributorStreamCutV1 *cut; const RfPageReplayRecordIdentityV1 *record = &edge->record_identity; RfPageVersionV1 result; - bool before_uuid; + bool before_uuid; - if (!rf_page_identity_equal_v1(&request->page_identity, - &edge->page_identity)) + if (!rf_page_identity_equal_v1(&request->page_identity, &edge->page_identity)) return RF_PAGE_PROOF_DETAIL_IDENTITY_MISMATCH; - if (!edge->record_complete || edge->component_count == 0 || - edge->component_count > RF_PAGE_STABLE_MAX_COMPONENTS) + if (!edge->record_complete || edge->component_count == 0 + || edge->component_count > RF_PAGE_STABLE_MAX_COMPONENTS) return RF_PAGE_PROOF_DETAIL_COMPONENT_INCOMPLETE; if (!edge->opcode_supported) return RF_PAGE_PROOF_DETAIL_OPCODE_UNSUPPORTED; @@ -192,57 +176,49 @@ validate_edge(const RfPageStableGraphRequestV1 *request, if (edge->participant_index >= vector->participant_count) return RF_PAGE_PROOF_DETAIL_PARTICIPANT_MISSING; cut = &vector->cuts[edge->participant_index]; - if (record->reserved_zero != 0 || record->reserved_zero2 != 0 || - record->system_identifier != vector->system_identifier || - memcmp(record->storage_uuid, vector->storage_uuid, 16) != 0 || - record->origin_thread != cut->failed_thread || - record->timeline_id != cut->timeline_id || - record->read_rec_ptr == InvalidXLogRecPtr || - record->end_rec_ptr == InvalidXLogRecPtr || - record->read_rec_ptr >= record->end_rec_ptr || - record->read_rec_ptr < cut->scan_begin_inclusive || - record->end_rec_ptr > cut->scan_end_exclusive) + if (record->reserved_zero != 0 || record->reserved_zero2 != 0 + || record->system_identifier != vector->system_identifier + || memcmp(record->storage_uuid, vector->storage_uuid, 16) != 0 + || record->origin_thread != cut->failed_thread || record->timeline_id != cut->timeline_id + || record->read_rec_ptr == InvalidXLogRecPtr || record->end_rec_ptr == InvalidXLogRecPtr + || record->read_rec_ptr >= record->end_rec_ptr + || record->read_rec_ptr < cut->scan_begin_inclusive + || record->end_rec_ptr > cut->scan_end_exclusive) return RF_PAGE_PROOF_DETAIL_IDENTITY_MISMATCH; - if ( - edge->edge.page_class != RF_PAGE_CLASS_ORDINARY || - edge->edge.result_kind != RF_PAGE_STATE_PRESENT) + if (edge->edge.page_class != RF_PAGE_CLASS_ORDINARY + || edge->edge.result_kind != RF_PAGE_STATE_PRESENT) return RF_PAGE_PROOF_DETAIL_CLASS_UNKNOWN; edge_result_version(edge, &result); if (!rf_page_version_present_v1(&result)) return RF_PAGE_PROOF_DETAIL_VERSION_MISMATCH; before_uuid = bytes_nonzero(edge->edge.before.segment_incarnation, 16); - switch (edge->edge.before_kind) - { - case RF_PAGE_STATE_PRESENT: - if (!rf_page_version_present_v1(&edge->edge.before) || - memcmp(edge->edge.before.segment_incarnation, - result.segment_incarnation, 16) != 0) - return RF_PAGE_PROOF_DETAIL_INCARNATION_MISMATCH; - break; - case RF_PAGE_STATE_UNFORMATTED: - if (!before_uuid || edge->edge.before.mutation_token != 0 || - memcmp(edge->edge.before.segment_incarnation, - result.segment_incarnation, 16) != 0) - return RF_PAGE_PROOF_DETAIL_INCARNATION_MISMATCH; - break; - case RF_PAGE_STATE_ABSENT: - if (before_uuid || edge->edge.before.mutation_token != 0) - return RF_PAGE_PROOF_DETAIL_INCARNATION_MISMATCH; - break; - default: - return RF_PAGE_PROOF_DETAIL_CLASS_UNKNOWN; + switch (edge->edge.before_kind) { + case RF_PAGE_STATE_PRESENT: + if (!rf_page_version_present_v1(&edge->edge.before) + || memcmp(edge->edge.before.segment_incarnation, result.segment_incarnation, 16) != 0) + return RF_PAGE_PROOF_DETAIL_INCARNATION_MISMATCH; + break; + case RF_PAGE_STATE_UNFORMATTED: + if (!before_uuid || edge->edge.before.mutation_token != 0 + || memcmp(edge->edge.before.segment_incarnation, result.segment_incarnation, 16) != 0) + return RF_PAGE_PROOF_DETAIL_INCARNATION_MISMATCH; + break; + case RF_PAGE_STATE_ABSENT: + if (before_uuid || edge->edge.before.mutation_token != 0) + return RF_PAGE_PROOF_DETAIL_INCARNATION_MISMATCH; + break; + default: + return RF_PAGE_PROOF_DETAIL_CLASS_UNKNOWN; } - if (edge->edge.edge_flags == 0) - { + if (edge->edge.edge_flags == 0) { if (edge->edge.before_kind != RF_PAGE_STATE_PRESENT) return RF_PAGE_PROOF_DETAIL_ANCHOR_MISSING; - } - else if (!edge_anchor_flags_valid(edge->edge.edge_flags)) + } else if (!edge_anchor_flags_valid(edge->edge.edge_flags)) return RF_PAGE_PROOF_DETAIL_IMAGE_DECODE_FAILED; - else if (!edge->image_integrity_ok || - !bytes_nonzero(edge->anchor_digest, sizeof(edge->anchor_digest))) + else if (!edge->image_integrity_ok + || !bytes_nonzero(edge->anchor_digest, sizeof(edge->anchor_digest))) return RF_PAGE_PROOF_DETAIL_IMAGE_INTEGRITY_FAILED; return RF_PAGE_PROOF_DETAIL_OK; @@ -252,18 +228,16 @@ static RfPageProofDetailV1 validate_request(const RfPageStableGraphRequestV1 *request) { const RfContributorVectorV1 *vector; - uint64 contributor_total = 0; - uint64 component_total = 0; - uint32 *per_participant; - uint32 i; + uint64 contributor_total = 0; + uint64 component_total = 0; + uint32 *per_participant; + uint32 i; RfPageProofDetailV1 detail = RF_PAGE_PROOF_DETAIL_OK; - if (request == NULL || request->contributors == NULL || - request->source == NULL || request->flags != 0 || - !rf_page_identity_valid_v1(&request->page_identity) || - !rf_page_version_present_v1(&request->expected_result) || - request->participant_count == 0 || - request->participant_count > RF_PAGE_STABLE_MAX_PARTICIPANTS) + if (request == NULL || request->contributors == NULL || request->source == NULL + || request->flags != 0 || !rf_page_identity_valid_v1(&request->page_identity) + || !rf_page_version_present_v1(&request->expected_result) || request->participant_count == 0 + || request->participant_count > RF_PAGE_STABLE_MAX_PARTICIPANTS) return RF_PAGE_PROOF_DETAIL_INVALID_ARGUMENT; if (!request->root_current) return RF_PAGE_PROOF_DETAIL_ROOT_STALE; @@ -271,57 +245,51 @@ validate_request(const RfPageStableGraphRequestV1 *request) return RF_PAGE_PROOF_DETAIL_DUTY_STALE; if (!request->fence_current) return RF_PAGE_PROOF_DETAIL_FENCE_STALE; - if (!request->retention_current || request->retention_binding_cookie == 0 || - request->retention_binding_cookie != - request->current_retention_binding_cookie) + if (!request->retention_current || request->retention_binding_cookie == 0 + || request->retention_binding_cookie != request->current_retention_binding_cookie) return RF_PAGE_PROOF_DETAIL_RETENTION_STALE; - if (!request->source->identity_verified || - !request->source->integrity_verified || - request->source->binding_cookie == 0 || - request->source->binding_cookie != - request->source->current_binding_cookie) + if (!request->source->identity_verified || !request->source->integrity_verified + || request->source->binding_cookie == 0 + || request->source->binding_cookie != request->source->current_binding_cookie) return RF_PAGE_PROOF_DETAIL_SOURCE_GAP; - if (!rf_page_identity_equal_v1(&request->page_identity, - &request->source->page_identity)) + if (!rf_page_identity_equal_v1(&request->page_identity, &request->source->page_identity)) return RF_PAGE_PROOF_DETAIL_IDENTITY_MISMATCH; vector = request->contributors; - if (vector->participant_count != request->participant_count || - vector->cuts == NULL || - (vector->edge_count > 0 && vector->edges == NULL) || - vector->system_identifier != request->page_identity.system_identifier || - memcmp(vector->storage_uuid, request->page_identity.storage_uuid, 16) != 0) + if (vector->participant_count != request->participant_count || vector->cuts == NULL + || (vector->edge_count > 0 && vector->edges == NULL) + || vector->system_identifier != request->page_identity.system_identifier + || memcmp(vector->storage_uuid, request->page_identity.storage_uuid, 16) != 0) return RF_PAGE_PROOF_DETAIL_PARTICIPANT_MISSING; if (vector->edge_count > RF_PAGE_STABLE_MAX_EDGES) return RF_PAGE_PROOF_DETAIL_CAPACITY; - per_participant = (uint32 *) stable_alloc0(request->participant_count, - sizeof(uint32)); + per_participant = (uint32 *)stable_alloc0(request->participant_count, sizeof(uint32)); if (per_participant == NULL) return RF_PAGE_PROOF_DETAIL_OOM; - for (i = 0; i < vector->participant_count; i++) - { + for (i = 0; i < vector->participant_count; i++) { const RfContributorStreamCutV1 *cut = &vector->cuts[i]; bool empty = (cut->flags & RF_CONTRIBUTOR_CUT_EXPLICIT_EMPTY) != 0; - if (cut->failed_thread == 0 || cut->timeline_id == 0 || - (cut->flags & ~RF_CONTRIBUTOR_CUT_KNOWN_MASK) != 0 || - (cut->flags & RF_CONTRIBUTOR_CUT_COMPLETE) == 0 || - (i > 0 && (vector->cuts[i - 1].failed_thread > cut->failed_thread || - (vector->cuts[i - 1].failed_thread == cut->failed_thread && - vector->cuts[i - 1].timeline_id >= cut->timeline_id)))) - { + if (cut->failed_thread == 0 || cut->timeline_id == 0 + || (cut->flags & ~RF_CONTRIBUTOR_CUT_KNOWN_MASK) != 0 + || (cut->flags & RF_CONTRIBUTOR_CUT_COMPLETE) == 0 + || (i > 0 + && (vector->cuts[i - 1].failed_thread > cut->failed_thread + || (vector->cuts[i - 1].failed_thread == cut->failed_thread + && vector->cuts[i - 1].timeline_id >= cut->timeline_id)))) { detail = RF_PAGE_PROOF_DETAIL_PARTICIPANT_MISSING; goto done; } - if ((empty && (cut->flags != RF_CONTRIBUTOR_CUT_KNOWN_MASK || - cut->scan_begin_inclusive != cut->scan_end_exclusive || - cut->contributor_count != 0 || cut->component_count != 0)) || - (!empty && (cut->flags != RF_CONTRIBUTOR_CUT_COMPLETE || - cut->scan_begin_inclusive >= cut->scan_end_exclusive || - cut->contributor_count == 0))) - { + if ((empty + && (cut->flags != RF_CONTRIBUTOR_CUT_KNOWN_MASK + || cut->scan_begin_inclusive != cut->scan_end_exclusive + || cut->contributor_count != 0 || cut->component_count != 0)) + || (!empty + && (cut->flags != RF_CONTRIBUTOR_CUT_COMPLETE + || cut->scan_begin_inclusive >= cut->scan_end_exclusive + || cut->contributor_count == 0))) { detail = RF_PAGE_PROOF_DETAIL_PARTICIPANT_MISSING; goto done; } @@ -329,18 +297,15 @@ validate_request(const RfPageStableGraphRequestV1 *request) component_total += cut->component_count; } - if (contributor_total != vector->edge_count) - { + if (contributor_total != vector->edge_count) { detail = RF_PAGE_PROOF_DETAIL_PARTICIPANT_MISSING; goto done; } - for (i = 0; i < vector->edge_count; i++) - { + for (i = 0; i < vector->edge_count; i++) { const RfPageStableEdgeInputV1 *edge = &vector->edges[i]; - if (edge->participant_index >= request->participant_count) - { + if (edge->participant_index >= request->participant_count) { detail = RF_PAGE_PROOF_DETAIL_PARTICIPANT_MISSING; goto done; } @@ -349,10 +314,8 @@ validate_request(const RfPageStableGraphRequestV1 *request) if (detail != RF_PAGE_PROOF_DETAIL_OK) goto done; } - for (i = 0; i < request->participant_count; i++) - { - if (per_participant[i] != vector->cuts[i].contributor_count) - { + for (i = 0; i < request->participant_count; i++) { + if (per_participant[i] != vector->cuts[i].contributor_count) { detail = RF_PAGE_PROOF_DETAIL_PARTICIPANT_MISSING; goto done; } @@ -369,33 +332,30 @@ static bool edge_selected_or_duplicate(const RfContributorVectorV1 *vector, uint32 index, const uint32 *reverse_chain, uint32 chain_length) { - uint32 i; + uint32 i; - for (i = 0; i < chain_length; i++) - { - if (reverse_chain[i] == index || - edge_exact_equal(&vector->edges[reverse_chain[i]], - &vector->edges[index])) + for (i = 0; i < chain_length; i++) { + if (reverse_chain[i] == index + || edge_exact_equal(&vector->edges[reverse_chain[i]], &vector->edges[index])) return true; } return false; } RfPageProofDetailV1 -rf_page_stable_base_select_v1(const RfPageStableGraphRequestV1 *request, - uint32 *chain_indices, uint32 chain_capacity, - RfPageStableSelectionV1 *selection) +rf_page_stable_base_select_v1(const RfPageStableGraphRequestV1 *request, uint32 *chain_indices, + uint32 chain_capacity, RfPageStableSelectionV1 *selection) { const RfContributorVectorV1 *vector; RfPageStableSelectionV1 selected; RfPageVersionV1 current; - uint32 *reverse_chain; - uint32 reverse_length = 0; - uint32 nearest_anchor_reverse_pos = UINT32_MAX; - uint32 terminal_count = 0; - uint32 terminal_index = UINT32_MAX; - uint32 i; - uint32 j; + uint32 *reverse_chain; + uint32 reverse_length = 0; + uint32 nearest_anchor_reverse_pos = UINT32_MAX; + uint32 terminal_count = 0; + uint32 terminal_index = UINT32_MAX; + uint32 i; + uint32 j; RfPageProofDetailV1 detail; if (chain_indices == NULL || selection == NULL || chain_capacity == 0) @@ -405,10 +365,8 @@ rf_page_stable_base_select_v1(const RfPageStableGraphRequestV1 *request, return detail; vector = request->contributors; - if (vector->edge_count == 0) - { - if (!rf_page_version_equal_v1(&request->source->source_version, - &request->expected_result)) + if (vector->edge_count == 0) { + if (!rf_page_version_equal_v1(&request->source->source_version, &request->expected_result)) return RF_PAGE_PROOF_DETAIL_ANCHOR_MISSING; memset(&selected, 0, sizeof(selected)); selected.terminal_version = request->expected_result; @@ -420,13 +378,11 @@ rf_page_stable_base_select_v1(const RfPageStableGraphRequestV1 *request, if (chain_capacity < vector->edge_count) return RF_PAGE_PROOF_DETAIL_CAPACITY; - reverse_chain = (uint32 *) stable_alloc0(vector->edge_count, - sizeof(uint32)); + reverse_chain = (uint32 *)stable_alloc0(vector->edge_count, sizeof(uint32)); if (reverse_chain == NULL) return RF_PAGE_PROOF_DETAIL_OOM; - for (i = 0; i < vector->edge_count; i++) - { + for (i = 0; i < vector->edge_count; i++) { const RfPageStableEdgeInputV1 *left = &vector->edges[i]; RfPageVersionV1 left_result; bool has_outgoing = false; @@ -434,64 +390,52 @@ rf_page_stable_base_select_v1(const RfPageStableGraphRequestV1 *request, if (edge_is_duplicate_of_prior(vector, i)) continue; edge_result_version(left, &left_result); - if (left->edge.before_kind == RF_PAGE_STATE_PRESENT && - rf_page_version_equal_v1(&left->edge.before, &left_result)) - { + if (left->edge.before_kind == RF_PAGE_STATE_PRESENT + && rf_page_version_equal_v1(&left->edge.before, &left_result)) { detail = RF_PAGE_PROOF_DETAIL_EDGE_CYCLE; goto fail; } - for (j = i + 1; j < vector->edge_count; j++) - { + for (j = i + 1; j < vector->edge_count; j++) { const RfPageStableEdgeInputV1 *right = &vector->edges[j]; if (edge_is_duplicate_of_prior(vector, j)) continue; - if (record_identity_equal(&left->record_identity, - &right->record_identity) && - !edge_exact_equal(left, right)) - { + if (record_identity_equal(&left->record_identity, &right->record_identity) + && !edge_exact_equal(left, right)) { detail = RF_PAGE_PROOF_DETAIL_ANCHOR_AMBIGUOUS; goto fail; } - if (edge_before_vertex_equal(left, right)) - { + if (edge_before_vertex_equal(left, right)) { if (!edge_result_equal(left, right)) detail = RF_PAGE_PROOF_DETAIL_EDGE_BRANCH; else detail = RF_PAGE_PROOF_DETAIL_ANCHOR_AMBIGUOUS; goto fail; } - if (edge_result_equal(left, right)) - { + if (edge_result_equal(left, right)) { detail = RF_PAGE_PROOF_DETAIL_TERMINAL_AMBIGUOUS; goto fail; } } - for (j = 0; j < vector->edge_count; j++) - { + for (j = 0; j < vector->edge_count; j++) { if (edge_is_duplicate_of_prior(vector, j)) continue; - if (vector->edges[j].edge.before_kind == RF_PAGE_STATE_PRESENT && - rf_page_version_equal_v1(&vector->edges[j].edge.before, - &left_result)) - { + if (vector->edges[j].edge.before_kind == RF_PAGE_STATE_PRESENT + && rf_page_version_equal_v1(&vector->edges[j].edge.before, &left_result)) { has_outgoing = true; break; } } - if (!has_outgoing) - { + if (!has_outgoing) { terminal_count++; terminal_index = i; } } - if (terminal_count == 0) - { + if (terminal_count == 0) { detail = RF_PAGE_PROOF_DETAIL_EDGE_CYCLE; goto fail; } - if (terminal_count != 1) - { + if (terminal_count != 1) { detail = RF_PAGE_PROOF_DETAIL_TERMINAL_AMBIGUOUS; goto fail; } @@ -499,64 +443,53 @@ rf_page_stable_base_select_v1(const RfPageStableGraphRequestV1 *request, RfPageVersionV1 terminal; edge_result_version(&vector->edges[terminal_index], &terminal); - if (!rf_page_version_equal_v1(&terminal, &request->expected_result)) - { + if (!rf_page_version_equal_v1(&terminal, &request->expected_result)) { detail = RF_PAGE_PROOF_DETAIL_VERSION_MISMATCH; goto fail; } } current = request->expected_result; - for (;;) - { + for (;;) { uint32 predecessor = UINT32_MAX; uint32 predecessor_count = 0; const RfPageStableEdgeInputV1 *edge; - for (i = 0; i < vector->edge_count; i++) - { + for (i = 0; i < vector->edge_count; i++) { RfPageVersionV1 result; if (edge_is_duplicate_of_prior(vector, i)) continue; edge_result_version(&vector->edges[i], &result); - if (rf_page_version_equal_v1(&result, ¤t)) - { + if (rf_page_version_equal_v1(&result, ¤t)) { predecessor = i; predecessor_count++; } } - if (predecessor_count == 0) - { + if (predecessor_count == 0) { if (nearest_anchor_reverse_pos != UINT32_MAX) break; detail = RF_PAGE_PROOF_DETAIL_EDGE_GAP; goto fail; } - if (predecessor_count != 1 || reverse_length >= chain_capacity) - { - detail = predecessor_count != 1 ? - RF_PAGE_PROOF_DETAIL_TERMINAL_AMBIGUOUS : - RF_PAGE_PROOF_DETAIL_CAPACITY; + if (predecessor_count != 1 || reverse_length >= chain_capacity) { + detail = predecessor_count != 1 ? RF_PAGE_PROOF_DETAIL_TERMINAL_AMBIGUOUS + : RF_PAGE_PROOF_DETAIL_CAPACITY; goto fail; } - for (i = 0; i < reverse_length; i++) - { - if (reverse_chain[i] == predecessor) - { + for (i = 0; i < reverse_length; i++) { + if (reverse_chain[i] == predecessor) { detail = RF_PAGE_PROOF_DETAIL_EDGE_CYCLE; goto fail; } } reverse_chain[reverse_length++] = predecessor; edge = &vector->edges[predecessor]; - if (edge_anchor_flags_valid(edge->edge.edge_flags) && - nearest_anchor_reverse_pos == UINT32_MAX) + if (edge_anchor_flags_valid(edge->edge.edge_flags) + && nearest_anchor_reverse_pos == UINT32_MAX) nearest_anchor_reverse_pos = reverse_length - 1; - if (edge->edge.before_kind != RF_PAGE_STATE_PRESENT) - { - if (nearest_anchor_reverse_pos == UINT32_MAX) - { + if (edge->edge.before_kind != RF_PAGE_STATE_PRESENT) { + if (nearest_anchor_reverse_pos == UINT32_MAX) { detail = RF_PAGE_PROOF_DETAIL_ANCHOR_MISSING; goto fail; } @@ -565,11 +498,8 @@ rf_page_stable_base_select_v1(const RfPageStableGraphRequestV1 *request, current = edge->edge.before; } - for (i = 0; i < vector->edge_count; i++) - { - if (!edge_selected_or_duplicate(vector, i, reverse_chain, - reverse_length)) - { + for (i = 0; i < vector->edge_count; i++) { + if (!edge_selected_or_duplicate(vector, i, reverse_chain, reverse_length)) { detail = RF_PAGE_PROOF_DETAIL_TERMINAL_AMBIGUOUS; goto fail; } @@ -578,8 +508,7 @@ rf_page_stable_base_select_v1(const RfPageStableGraphRequestV1 *request, uint32 selected_length = nearest_anchor_reverse_pos + 1; for (i = 0; i < selected_length; i++) - chain_indices[i] = - reverse_chain[nearest_anchor_reverse_pos - i]; + chain_indices[i] = reverse_chain[nearest_anchor_reverse_pos - i]; memset(&selected, 0, sizeof(selected)); selected.terminal_version = request->expected_result; selected.anchor_edge_index = chain_indices[0]; @@ -596,65 +525,56 @@ rf_page_stable_base_select_v1(const RfPageStableGraphRequestV1 *request, } static RfPageProofDetailV1 -stable_owners_revalidate(const RfPageStableBaseProofRequestV1 *request, - bool bound_pin) +stable_owners_revalidate(const RfPageStableBaseProofRequestV1 *request, bool bound_pin) { const RfPageStableGraphRequestV1 *graph = request->graph; const RfContributorVectorV1 *contributors = graph->contributors; - PgracExternalFenceDenyReason fence_reason = - PGRAC_EXTERNAL_FENCE_DENY_BAD_ARGUMENT; - uint32 i; - - if (request->duties == NULL || request->root_tokens == NULL || - contributors == NULL || - contributors->cuts == NULL || graph->participant_count == 0 || - graph->participant_count > RF_PAGE_STABLE_MAX_PARTICIPANTS || - contributors->participant_count != graph->participant_count) + PgracExternalFenceDenyReason fence_reason = PGRAC_EXTERNAL_FENCE_DENY_BAD_ARGUMENT; + uint32 i; + + if (request->duties == NULL || request->root_tokens == NULL || contributors == NULL + || contributors->cuts == NULL || graph->participant_count == 0 + || graph->participant_count > RF_PAGE_STABLE_MAX_PARTICIPANTS + || contributors->participant_count != graph->participant_count) return RF_PAGE_PROOF_DETAIL_INVALID_ARGUMENT; - for (i = 0; i < graph->participant_count; i++) - { + for (i = 0; i < graph->participant_count; i++) { const ClusterControlRootReadToken *token = &request->root_tokens[i]; const ClusterRecoveryDutyKey *duty = &request->duties[i]; ClusterControlRootSnapshot snapshot; ClusterControlRootResult result; - if (!bytes_nonzero(token->authority_uuid, - sizeof(token->authority_uuid)) || - token->origin_thread_id != contributors->cuts[i].failed_thread || - token->origin_thread_id != duty->origin_thread_id || - token->root_lineage_seq != duty->root_lineage_seq || - memcmp(token->authority_uuid, duty->authority_uuid, 16) != 0 || - token->root_lineage_seq == 0 || token->reserved20 != 0 || - token->reserved32 != 0) + if (!bytes_nonzero(token->authority_uuid, sizeof(token->authority_uuid)) + || token->origin_thread_id != contributors->cuts[i].failed_thread + || token->origin_thread_id != duty->origin_thread_id + || token->root_lineage_seq != duty->root_lineage_seq + || memcmp(token->authority_uuid, duty->authority_uuid, 16) != 0 + || token->root_lineage_seq == 0 || token->reserved20 != 0 || token->reserved32 != 0) return RF_PAGE_PROOF_DETAIL_ROOT_STALE; result = cluster_control_root_revalidate(token, duty, &snapshot); - if ((result != CLUSTER_CONTROL_ROOT_OK_PRIMARY && - result != CLUSTER_CONTROL_ROOT_OK_PRIMARY_DEGRADED) || - snapshot.lifecycle != - CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_REQUIRED || - (snapshot.root_flags & CLUSTER_CONTROL_ROOT_FLAG_TAIL_VALID) == 0) + if ((result != CLUSTER_CONTROL_ROOT_OK_PRIMARY + && result != CLUSTER_CONTROL_ROOT_OK_PRIMARY_DEGRADED) + || snapshot.lifecycle != CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_REQUIRED + || (snapshot.root_flags & CLUSTER_CONTROL_ROOT_FLAG_TAIL_VALID) == 0) return RF_PAGE_PROOF_DETAIL_ROOT_STALE; } - if (cluster_formation_witness_revalidate_nowait(request->formation) != - CLUSTER_FORMATION_WITNESS_READY || - !cluster_external_fence_need_set_revalidate_nowait( - request->fence_need_set, request->formation, &fence_reason) || - !cluster_external_fence_revalidate_set_nowait( - request->fence_admission_set, request->fence_need_set, - request->formation, &fence_reason)) + if (cluster_formation_witness_revalidate_nowait(request->formation) + != CLUSTER_FORMATION_WITNESS_READY + || !cluster_external_fence_need_set_revalidate_nowait(request->fence_need_set, + request->formation, &fence_reason) + || !cluster_external_fence_revalidate_set_nowait(request->fence_admission_set, + request->fence_need_set, + request->formation, &fence_reason)) return RF_PAGE_PROOF_DETAIL_FENCE_STALE; - if ((bound_pin ? - cluster_wal_retention_pin_revalidate(request->retention_pin) : - cluster_wal_retention_pin_preflight_revalidate_wait_v1( - request->retention_pin)) != CLUSTER_WAL_PIN_OK) + if ((bound_pin ? cluster_wal_retention_pin_revalidate(request->retention_pin) + : cluster_wal_retention_pin_preflight_revalidate_wait_v1(request->retention_pin)) + != CLUSTER_WAL_PIN_OK) return RF_PAGE_PROOF_DETAIL_RETENTION_STALE; return RF_PAGE_PROOF_DETAIL_OK; } static RfPageProofDetailV1 -stable_proof_build(const RfPageStableBaseProofRequestV1 *request, - uint32 *chain_indices, uint32 chain_capacity, - RfPageStableBaseProofV1 **out_proof, bool bound_pin) +stable_proof_build(const RfPageStableBaseProofRequestV1 *request, uint32 *chain_indices, + uint32 chain_capacity, RfPageStableBaseProofV1 **out_proof, bool bound_pin) { RfPageStableBaseProofV1 *proof; RfPageStableSelectionV1 selection; @@ -664,11 +584,10 @@ stable_proof_build(const RfPageStableBaseProofRequestV1 *request, if (out_proof == NULL) return RF_PAGE_PROOF_DETAIL_INVALID_ARGUMENT; *out_proof = NULL; - if (request == NULL || request->graph == NULL || - request->duties == NULL || request->root_tokens == NULL || - request->formation == NULL || request->fence_need_set == NULL || - request->fence_admission_set == NULL || - request->retention_pin == NULL || request->flags != 0) + if (request == NULL || request->graph == NULL || request->duties == NULL + || request->root_tokens == NULL || request->formation == NULL + || request->fence_need_set == NULL || request->fence_admission_set == NULL + || request->retention_pin == NULL || request->flags != 0) return RF_PAGE_PROOF_DETAIL_INVALID_ARGUMENT; detail = stable_owners_revalidate(request, bound_pin); if (detail != RF_PAGE_PROOF_DETAIL_OK) @@ -680,11 +599,11 @@ stable_proof_build(const RfPageStableBaseProofRequestV1 *request, verified_graph.retention_current = true; verified_graph.retention_binding_cookie = 1; verified_graph.current_retention_binding_cookie = 1; - detail = rf_page_stable_base_select_v1(&verified_graph, chain_indices, - chain_capacity, &selection); + detail + = rf_page_stable_base_select_v1(&verified_graph, chain_indices, chain_capacity, &selection); if (detail != RF_PAGE_PROOF_DETAIL_OK) return detail; - proof = (RfPageStableBaseProofV1 *) stable_alloc0(1, sizeof(*proof)); + proof = (RfPageStableBaseProofV1 *)stable_alloc0(1, sizeof(*proof)); if (proof == NULL) return RF_PAGE_PROOF_DETAIL_OOM; proof->magic = RF_PAGE_STABLE_PROOF_MAGIC; @@ -705,57 +624,46 @@ stable_proof_build(const RfPageStableBaseProofRequestV1 *request, } RfPageProofDetailV1 -rf_page_stable_base_proof_build_wait_v1( - const RfPageStableBaseProofRequestV1 *request, - uint32 *chain_indices, uint32 chain_capacity, int timeout_ms, - RfPageStableBaseProofV1 **out_proof) +rf_page_stable_base_proof_build_wait_v1(const RfPageStableBaseProofRequestV1 *request, + uint32 *chain_indices, uint32 chain_capacity, + int timeout_ms, RfPageStableBaseProofV1 **out_proof) { if (out_proof == NULL) return RF_PAGE_PROOF_DETAIL_INVALID_ARGUMENT; *out_proof = NULL; if (timeout_ms < 0) return RF_PAGE_PROOF_DETAIL_INVALID_ARGUMENT; - return stable_proof_build(request, chain_indices, chain_capacity, - out_proof, false); + return stable_proof_build(request, chain_indices, chain_capacity, out_proof, false); } RfPageProofDetailV1 -rf_page_stable_base_proof_build_bound_v1( - const RfPageStableBaseProofRequestV1 *request, - uint32 *chain_indices, uint32 chain_capacity, - RfPageStableBaseProofV1 **out_proof) +rf_page_stable_base_proof_build_bound_v1(const RfPageStableBaseProofRequestV1 *request, + uint32 *chain_indices, uint32 chain_capacity, + RfPageStableBaseProofV1 **out_proof) { - return stable_proof_build(request, chain_indices, chain_capacity, - out_proof, true); + return stable_proof_build(request, chain_indices, chain_capacity, out_proof, true); } bool rf_page_stable_base_proof_matches_v1( - const RfPageStableBaseProofV1 *proof, - const RfPageIdentityV1 *page_identity, - const RfPageVersionV1 *expected_result, - const ClusterRecoveryDutyKey *duties, - const ClusterControlRootReadToken *root_tokens, - const ClusterFormationWitnessV1 *formation, + const RfPageStableBaseProofV1 *proof, const RfPageIdentityV1 *page_identity, + const RfPageVersionV1 *expected_result, const ClusterRecoveryDutyKey *duties, + const ClusterControlRootReadToken *root_tokens, const ClusterFormationWitnessV1 *formation, const PgracExternalFenceNeedSetV1 *fence_need_set, const PgracExternalFenceAdmissionSetV1 *fence_admission_set, - ClusterWalRetentionPin *retention_pin, - const RfPagePinnedSourceV1 *source, - const RfContributorVectorV1 *contributors, - uint32 participant_count) + ClusterWalRetentionPin *retention_pin, const RfPagePinnedSourceV1 *source, + const RfContributorVectorV1 *contributors, uint32 participant_count) { - return proof != NULL && proof->magic == RF_PAGE_STABLE_PROOF_MAGIC && - participant_count != 0 && - proof->participant_count == participant_count && - rf_page_identity_equal_v1(&proof->page_identity, page_identity) && - rf_page_version_equal_v1(&proof->expected_result, expected_result) && - rf_page_version_equal_v1(&proof->selection.terminal_version, - expected_result) && proof->duties == duties && - proof->root_tokens == root_tokens && proof->formation == formation && - proof->fence_need_set == fence_need_set && - proof->fence_admission_set == fence_admission_set && - proof->retention_pin == retention_pin && proof->source == source && - proof->contributors == contributors; + return proof != NULL && proof->magic == RF_PAGE_STABLE_PROOF_MAGIC && participant_count != 0 + && proof->participant_count == participant_count + && rf_page_identity_equal_v1(&proof->page_identity, page_identity) + && rf_page_version_equal_v1(&proof->expected_result, expected_result) + && rf_page_version_equal_v1(&proof->selection.terminal_version, expected_result) + && proof->duties == duties && proof->root_tokens == root_tokens + && proof->formation == formation && proof->fence_need_set == fence_need_set + && proof->fence_admission_set == fence_admission_set + && proof->retention_pin == retention_pin && proof->source == source + && proof->contributors == contributors; } void @@ -778,9 +686,9 @@ rf_page_stable_base_proof_destroy_v1(RfPageStableBaseProofV1 **proof_pointer) static bool page_all_zero(const char page[BLCKSZ]) { - const uint8 *bytes = (const uint8 *) page; - uint8 value = 0; - int i; + const uint8 *bytes = (const uint8 *)page; + uint8 value = 0; + int i; for (i = 0; i < BLCKSZ; i++) value |= bytes[i]; @@ -788,90 +696,80 @@ page_all_zero(const char page[BLCKSZ]) } RfPageProofDetailV1 -rf_page_stable_install_test_v1(const RfPageInstallRequestV1 *request, - RfPageInstallProofV1 *proof) +rf_page_stable_install_test_v1(const RfPageInstallRequestV1 *request, RfPageInstallProofV1 *proof) { RfPageInstallProofV1 completed; - char postread[BLCKSZ]; - uint32 i; - bool promoted = false; + char postread[BLCKSZ]; + uint32 i; + bool promoted = false; RfPageProofDetailV1 failure = RF_PAGE_PROOF_DETAIL_OK; - if (request == NULL || proof == NULL || request->components == NULL || - request->ops == NULL || request->prepared_pages == NULL || - request->component_count == 0 || - request->component_count > RF_PAGE_STABLE_MAX_COMPONENTS || - request->prepared_capacity < - (Size) request->component_count * BLCKSZ || - request->ops->canonicalize == NULL || request->ops->promote == NULL || - request->ops->write == NULL || request->ops->sync == NULL || - request->ops->postread == NULL || request->ops->publish == NULL || - request->ops->release == NULL) + if (request == NULL || proof == NULL || request->components == NULL || request->ops == NULL + || request->prepared_pages == NULL || request->component_count == 0 + || request->component_count > RF_PAGE_STABLE_MAX_COMPONENTS + || request->prepared_capacity < (Size)request->component_count * BLCKSZ + || request->ops->canonicalize == NULL || request->ops->promote == NULL + || request->ops->write == NULL || request->ops->sync == NULL + || request->ops->postread == NULL || request->ops->publish == NULL + || request->ops->release == NULL) return RF_PAGE_PROOF_DETAIL_INVALID_ARGUMENT; if (!request->global_preflight_ok) return RF_PAGE_PROOF_DETAIL_COMPONENT_INCOMPLETE; - for (i = 0; i < request->component_count; i++) - { + for (i = 0; i < request->component_count; i++) { const RfPageInstallComponentV1 *component = &request->components[i]; - char *prepared = request->prepared_pages + (Size) i * BLCKSZ; - - if (!rf_page_identity_valid_v1(&component->page_identity) || - !rf_page_version_present_v1(&component->expected_before) || - !rf_page_version_present_v1(&component->expected_result) || - component->canonical_page == NULL || !component->route_preflight_ok || - !component->side_preflight_ok || !component->scratch_ready || - !component->identity_authority_ok || !component->canonical_layout_ok) + char *prepared = request->prepared_pages + (Size)i * BLCKSZ; + + if (!rf_page_identity_valid_v1(&component->page_identity) + || !rf_page_version_present_v1(&component->expected_before) + || !rf_page_version_present_v1(&component->expected_result) + || component->canonical_page == NULL || !component->route_preflight_ok + || !component->side_preflight_ok || !component->scratch_ready + || !component->identity_authority_ok || !component->canonical_layout_ok) return RF_PAGE_PROOF_DETAIL_COMPONENT_INCOMPLETE; if (component->target_state == RF_PAGE_INSTALL_TARGET_UNRELATED) return RF_PAGE_PROOF_DETAIL_VERSION_MISMATCH; - if (component->target_state != RF_PAGE_INSTALL_TARGET_EXPECTED && - component->target_state != RF_PAGE_INSTALL_TARGET_RESULT && - component->target_state != RF_PAGE_INSTALL_TARGET_TORN) + if (component->target_state != RF_PAGE_INSTALL_TARGET_EXPECTED + && component->target_state != RF_PAGE_INSTALL_TARGET_RESULT + && component->target_state != RF_PAGE_INSTALL_TARGET_TORN) return RF_PAGE_PROOF_DETAIL_INVALID_ARGUMENT; memcpy(prepared, component->canonical_page, BLCKSZ); - if (page_all_zero(prepared) || - !request->ops->canonicalize(request->ops->arg, i, - component->checksums_enabled, prepared) || page_all_zero(prepared)) + if (page_all_zero(prepared) + || !request->ops->canonicalize(request->ops->arg, i, component->checksums_enabled, + prepared) + || page_all_zero(prepared)) return RF_PAGE_PROOF_DETAIL_IMAGE_INTEGRITY_FAILED; } if (!request->ops->promote(request->ops->arg)) return RF_PAGE_PROOF_DETAIL_WOULD_BLOCK; promoted = true; - for (i = 0; i < request->component_count; i++) - { + for (i = 0; i < request->component_count; i++) { const RfPageInstallComponentV1 *component = &request->components[i]; - const char *prepared = request->prepared_pages + (Size) i * BLCKSZ; + const char *prepared = request->prepared_pages + (Size)i * BLCKSZ; - if (component->target_state != RF_PAGE_INSTALL_TARGET_RESULT && - !request->ops->write(request->ops->arg, i, prepared)) - { + if (component->target_state != RF_PAGE_INSTALL_TARGET_RESULT + && !request->ops->write(request->ops->arg, i, prepared)) { failure = RF_PAGE_PROOF_DETAIL_INTERNAL; goto cleanup; } } - for (i = 0; i < request->component_count; i++) - { - if (!request->ops->sync(request->ops->arg, i)) - { + for (i = 0; i < request->component_count; i++) { + if (!request->ops->sync(request->ops->arg, i)) { failure = RF_PAGE_PROOF_DETAIL_POSTREAD_FAILED; goto cleanup; } } - for (i = 0; i < request->component_count; i++) - { - const char *prepared = request->prepared_pages + (Size) i * BLCKSZ; + for (i = 0; i < request->component_count; i++) { + const char *prepared = request->prepared_pages + (Size)i * BLCKSZ; - if (!request->ops->postread(request->ops->arg, i, postread) || - memcmp(postread, prepared, BLCKSZ) != 0) - { + if (!request->ops->postread(request->ops->arg, i, postread) + || memcmp(postread, prepared, BLCKSZ) != 0) { failure = RF_PAGE_PROOF_DETAIL_POSTREAD_FAILED; goto cleanup; } } - if (!request->ops->publish(request->ops->arg)) - { + if (!request->ops->publish(request->ops->arg)) { failure = RF_PAGE_PROOF_DETAIL_INTERNAL; goto cleanup; } @@ -894,4 +792,4 @@ rf_page_stable_install_test_v1(const RfPageInstallRequestV1 *request, return failure; } -#endif /* USE_CLUSTER_UNIT */ +#endif /* USE_CLUSTER_UNIT */ diff --git a/src/backend/cluster/cluster_page_stats.c b/src/backend/cluster/cluster_page_stats.c index 024cf39f1ec..1c67078b75a 100644 --- a/src/backend/cluster/cluster_page_stats.c +++ b/src/backend/cluster/cluster_page_stats.c @@ -28,38 +28,36 @@ void cluster_page_stats_init(ClusterPageRecoveryStats *stats) { - int i; + int i; pg_atomic_uint64 *fields; - int nfields; + int nfields; if (stats == NULL) return; - fields = (pg_atomic_uint64 *) stats; + fields = (pg_atomic_uint64 *)stats; nfields = sizeof(ClusterPageRecoveryStats) / sizeof(pg_atomic_uint64); for (i = 0; i < nfields; i++) pg_atomic_init_u64(&fields[i], 0); } void -cluster_page_stats_source_selected(ClusterPageRecoveryStats *stats, - ClusterPageSourceKind kind) +cluster_page_stats_source_selected(ClusterPageRecoveryStats *stats, ClusterPageSourceKind kind) { if (stats == NULL) return; - switch (kind) - { - case CLUSTER_PAGE_SOURCE_CURRENT: - pg_atomic_fetch_add_u64(&stats->source_selected_current, 1); - break; - case CLUSTER_PAGE_SOURCE_PI: - pg_atomic_fetch_add_u64(&stats->source_selected_pi, 1); - break; - case CLUSTER_PAGE_SOURCE_STORAGE: - pg_atomic_fetch_add_u64(&stats->source_selected_storage, 1); - break; - default: - pg_atomic_fetch_add_u64(&stats->source_invalid, 1); - break; + switch (kind) { + case CLUSTER_PAGE_SOURCE_CURRENT: + pg_atomic_fetch_add_u64(&stats->source_selected_current, 1); + break; + case CLUSTER_PAGE_SOURCE_PI: + pg_atomic_fetch_add_u64(&stats->source_selected_pi, 1); + break; + case CLUSTER_PAGE_SOURCE_STORAGE: + pg_atomic_fetch_add_u64(&stats->source_selected_storage, 1); + break; + default: + pg_atomic_fetch_add_u64(&stats->source_invalid, 1); + break; } } @@ -152,8 +150,8 @@ cluster_page_stats_stable_base_unresolved(ClusterPageRecoveryStats *stats) } void -cluster_page_stats_contributors(ClusterPageRecoveryStats *stats, uint64 records, - uint64 threads, uint64 gaps) +cluster_page_stats_contributors(ClusterPageRecoveryStats *stats, uint64 records, uint64 threads, + uint64 gaps) { if (stats == NULL) return; @@ -173,30 +171,28 @@ void cluster_page_stats_note_page_write(ClusterPageRecoveryStats *stats) { if (stats != NULL) - pg_atomic_write_u64(&stats->last_page_write_ts, (uint64) GetCurrentTimestamp()); + pg_atomic_write_u64(&stats->last_page_write_ts, (uint64)GetCurrentTimestamp()); } void cluster_page_stats_note_durability(ClusterPageRecoveryStats *stats) { if (stats != NULL) - pg_atomic_write_u64(&stats->last_durability_barrier_ts, - (uint64) GetCurrentTimestamp()); + pg_atomic_write_u64(&stats->last_durability_barrier_ts, (uint64)GetCurrentTimestamp()); } void cluster_page_stats_note_post_read(ClusterPageRecoveryStats *stats) { if (stats != NULL) - pg_atomic_write_u64(&stats->last_post_read_ts, (uint64) GetCurrentTimestamp()); + pg_atomic_write_u64(&stats->last_post_read_ts, (uint64)GetCurrentTimestamp()); } /* * G2 vocabulary: one kind per name, matching the cluster_pgstat registry * entries. The single table every consumer reads. */ -typedef struct ClusterPageStatName -{ +typedef struct ClusterPageStatName { const char *name; ClusterPageStatKind kind; } ClusterPageStatName; @@ -230,71 +226,61 @@ static const ClusterPageStatName cluster_page_stat_names[] = { bool cluster_page_stats_describe(const char *name, ClusterPageStatKind *kind) { - int i; + int i; if (name == NULL) return false; - for (i = 0; i < (int) lengthof(cluster_page_stat_names); i++) { + for (i = 0; i < (int)lengthof(cluster_page_stat_names); i++) { if (strcmp(cluster_page_stat_names[i].name, name) == 0) { if (kind != NULL) *kind = cluster_page_stat_names[i].kind; return true; } } - return false; /* unknown name: consumers fail closed */ + return false; /* unknown name: consumers fail closed */ } static const char * cluster_page_source_kind_name(ClusterPageSourceKind kind) { - switch (kind) - { - case CLUSTER_PAGE_SOURCE_CURRENT: - return "CURRENT"; - case CLUSTER_PAGE_SOURCE_PI: - return "PI"; - case CLUSTER_PAGE_SOURCE_STORAGE: - return "STORAGE"; + switch (kind) { + case CLUSTER_PAGE_SOURCE_CURRENT: + return "CURRENT"; + case CLUSTER_PAGE_SOURCE_PI: + return "PI"; + case CLUSTER_PAGE_SOURCE_STORAGE: + return "STORAGE"; } return "UNKNOWN"; } int -cluster_page_attempt_dump(const ClusterPageAttemptDump *dump, char *buf, - Size buflen) +cluster_page_attempt_dump(const ClusterPageAttemptDump *dump, char *buf, Size buflen) { - uint64 src_tok; - uint64 term_tok; - int written; + uint64 src_tok; + uint64 term_tok; + int written; if (dump == NULL) return 0; - src_tok = cluster_page_version_valid(&dump->source_version) - ? dump->source_version.token : 0; - term_tok = cluster_page_version_valid(&dump->terminal_version) - ? dump->terminal_version.token : 0; - written = snprintf(buf, buflen, - "page-attempt thread=%u gen=" UINT64_FORMAT - " rel=%u/%u/%u fork=%d block=%u class=%d source=%s" - " src_tok=" UINT64_FORMAT " term_tok=" UINT64_FORMAT - " contributors=" UINT64_FORMAT " threads=0x" UINT64_FORMAT - " applied=%d mismatch=%d durable=%d post_read=%d" - " authority=%d released=%d stop=%s", - (unsigned) dump->failed_origin_thread, - dump->failure_generation, - (unsigned) dump->identity.rlocator.spcOid, - (unsigned) dump->identity.rlocator.dbOid, - (unsigned) dump->identity.rlocator.relNumber, - (int) dump->identity.forknum, - (unsigned) dump->identity.blocknum, - (int) dump->page_class, - cluster_page_source_kind_name(dump->source_kind), - src_tok, term_tok, - dump->contributor_count, - dump->contributor_thread_set, - (int) dump->applied, (int) dump->version_mismatch, - (int) dump->durability_ok, (int) dump->post_read_ok, - (int) dump->authority_revalidated, (int) dump->released, - dump->stop_reason != NULL ? dump->stop_reason : "none"); + src_tok = cluster_page_version_valid(&dump->source_version) ? dump->source_version.token : 0; + term_tok + = cluster_page_version_valid(&dump->terminal_version) ? dump->terminal_version.token : 0; + written = snprintf( + buf, buflen, + "page-attempt thread=%u gen=" UINT64_FORMAT + " rel=%u/%u/%u fork=%d block=%u class=%d source=%s" + " src_tok=" UINT64_FORMAT " term_tok=" UINT64_FORMAT " contributors=" UINT64_FORMAT + " threads=0x" UINT64_FORMAT " applied=%d mismatch=%d durable=%d post_read=%d" + " authority=%d released=%d stop=%s", + (unsigned)dump->failed_origin_thread, dump->failure_generation, + (unsigned)dump->identity.rlocator.spcOid, (unsigned)dump->identity.rlocator.dbOid, + (unsigned)dump->identity.rlocator.relNumber, (int)dump->identity.forknum, + (unsigned)dump->identity.blocknum, (int)dump->page_class, + cluster_page_source_kind_name(dump->source_kind), src_tok, term_tok, + dump->contributor_count, dump->contributor_thread_set, (int)dump->applied, + (int)dump->version_mismatch, (int)dump->durability_ok, (int)dump->post_read_ok, + (int)dump->authority_revalidated, (int)dump->released, + dump->stop_reason != NULL ? dump->stop_reason : "none"); return written; } diff --git a/src/backend/cluster/cluster_page_version.c b/src/backend/cluster/cluster_page_version.c index 2d6340ef797..53a5432351a 100644 --- a/src/backend/cluster/cluster_page_version.c +++ b/src/backend/cluster/cluster_page_version.c @@ -39,8 +39,7 @@ cluster_page_identity_valid(const ClusterPageIdentity *identity) /* A zeroed RelFileLocator is the PG "never-set" identity; a fork/block * must be a real address. RelFileNumber is an Oid; InvalidOid is its * never-set value. */ - if (identity->rlocator.spcOid == InvalidOid - || identity->rlocator.dbOid == InvalidOid + if (identity->rlocator.spcOid == InvalidOid || identity->rlocator.dbOid == InvalidOid || identity->rlocator.relNumber == InvalidOid) return false; if (identity->forknum < 0 || identity->forknum > MAX_FORKNUM) @@ -51,14 +50,12 @@ cluster_page_identity_valid(const ClusterPageIdentity *identity) } bool -cluster_page_identity_equal(const ClusterPageIdentity *a, - const ClusterPageIdentity *b) +cluster_page_identity_equal(const ClusterPageIdentity *a, const ClusterPageIdentity *b) { if (a == NULL || b == NULL) return false; - return RelFileLocatorEquals(a->rlocator, b->rlocator) - && a->forknum == b->forknum - && a->blocknum == b->blocknum; + return RelFileLocatorEquals(a->rlocator, b->rlocator) && a->forknum == b->forknum + && a->blocknum == b->blocknum; } bool @@ -82,8 +79,7 @@ cluster_page_version_valid(const ClusterPageVersion *version) } bool -cluster_page_version_equal(const ClusterPageVersion *a, - const ClusterPageVersion *b) +cluster_page_version_equal(const ClusterPageVersion *a, const ClusterPageVersion *b) { /* * Exact equality only, and only between VALID versions. An invalid @@ -93,8 +89,7 @@ cluster_page_version_equal(const ClusterPageVersion *a, if (!cluster_page_version_valid(a) || !cluster_page_version_valid(b)) return false; return cluster_page_identity_equal(&a->identity, &b->identity) - && a->incarnation == b->incarnation - && a->token == b->token; + && a->incarnation == b->incarnation && a->token == b->token; } bool @@ -110,14 +105,13 @@ cluster_page_before_state_valid(const ClusterPageBeforeState *state) } bool -cluster_page_before_state_equal(const ClusterPageBeforeState *a, - const ClusterPageBeforeState *b) +cluster_page_before_state_equal(const ClusterPageBeforeState *a, const ClusterPageBeforeState *b) { /* Same strict rule as versions: valid-only exact equality. */ if (!cluster_page_before_state_valid(a) || !cluster_page_before_state_valid(b)) return false; return cluster_page_identity_equal(&a->identity, &b->identity) - && a->new_incarnation == b->new_incarnation; + && a->new_incarnation == b->new_incarnation; } /* --------------------------------------------------------------------- @@ -154,14 +148,12 @@ cluster_page_version_decide(const ClusterPageVersion *current_working, * newer and recoverer-local bitmaps are all deliberately absent * (spec §3.2 last paragraph). */ - if (result_version != NULL - && cluster_page_version_valid(result_version) + if (result_version != NULL && cluster_page_version_valid(result_version) && trusted_source_version != NULL && cluster_page_version_equal(trusted_source_version, result_version)) return CLUSTER_PAGE_APPLY_SKIP; - if (current_working == NULL || expected_before == NULL - || result_version == NULL + if (current_working == NULL || expected_before == NULL || result_version == NULL || !cluster_page_version_valid(result_version) || !cluster_page_version_valid(expected_before)) return CLUSTER_PAGE_APPLY_BLOCKED; @@ -184,22 +176,21 @@ cluster_page_version_decide(const ClusterPageVersion *current_working, */ #define CLUSTER_PAGE_KNOWN_OPCODE_MAX 64 -typedef struct ClusterPageKnownOpcode -{ - uint8 rmid; - uint16 opcode; +typedef struct ClusterPageKnownOpcode { + uint8 rmid; + uint16 opcode; } ClusterPageKnownOpcode; static ClusterPageKnownOpcode cluster_page_known_opcodes[CLUSTER_PAGE_KNOWN_OPCODE_MAX]; -static int cluster_page_known_opcode_count = 0; +static int cluster_page_known_opcode_count = 0; bool cluster_page_class_register_known_opcode(uint8 rmid, uint16 opcode) { if (cluster_page_class_is_known_opcode(rmid, opcode)) - return true; /* idempotent */ + return true; /* idempotent */ if (cluster_page_known_opcode_count >= CLUSTER_PAGE_KNOWN_OPCODE_MAX) - return false; /* fail-closed: registry full */ + return false; /* fail-closed: registry full */ cluster_page_known_opcodes[cluster_page_known_opcode_count].rmid = rmid; cluster_page_known_opcodes[cluster_page_known_opcode_count].opcode = opcode; cluster_page_known_opcode_count++; @@ -209,7 +200,7 @@ cluster_page_class_register_known_opcode(uint8 rmid, uint16 opcode) bool cluster_page_class_is_known_opcode(uint8 rmid, uint16 opcode) { - int i; + int i; for (i = 0; i < cluster_page_known_opcode_count; i++) if (cluster_page_known_opcodes[i].rmid == rmid @@ -229,9 +220,9 @@ cluster_page_class_is_known_opcode(uint8 rmid, uint16 opcode) ClusterPageClass cluster_page_classify(const ClusterPageClassifyInput *input) { - bool new_page; - bool full_image; - bool will_init; + bool new_page; + bool full_image; + bool will_init; if (input == NULL) return CLUSTER_PAGE_CLASS_UNKNOWN; @@ -248,17 +239,15 @@ cluster_page_classify(const ClusterPageClassifyInput *input) if (input->header_owner != CLUSTER_PAGE_HEADER_OWNER_NONE && (input->forknum == INIT_FORKNUM || input->forknum == FSM_FORKNUM - || input->relation_is_temp || full_image || will_init || new_page - || input->is_cleanout || input->relation_is_unlogged)) + || input->relation_is_temp || full_image || will_init || new_page || input->is_cleanout + || input->relation_is_unlogged)) return CLUSTER_PAGE_CLASS_UNKNOWN; if (input->forknum == FSM_FORKNUM - && (full_image || will_init || input->is_cleanout - || input->relation_is_unlogged)) + && (full_image || will_init || input->is_cleanout || input->relation_is_unlogged)) return CLUSTER_PAGE_CLASS_UNKNOWN; if (full_image && will_init) return CLUSTER_PAGE_CLASS_UNKNOWN; - if ((input->is_cleanout || input->relation_is_unlogged) - && (full_image || will_init)) + if ((input->is_cleanout || input->relation_is_unlogged) && (full_image || will_init)) return CLUSTER_PAGE_CLASS_UNKNOWN; /* diff --git a/src/backend/cluster/cluster_pcm_direct_init.c b/src/backend/cluster/cluster_pcm_direct_init.c index 98957e3e014..eff64ebd271 100644 --- a/src/backend/cluster/cluster_pcm_direct_init.c +++ b/src/backend/cluster/cluster_pcm_direct_init.c @@ -39,10 +39,8 @@ cluster_pcm_direct_init_snapshot_validate(ClusterPcmDirectInitKind kind, if ((snapshot->buf_state & BM_TAG_VALID) == 0 || (snapshot->buf_state & (BM_DIRTY | BM_JUST_DIRTIED | BM_IO_ERROR)) != 0 || snapshot->buffer_type != (uint8)BUF_TYPE_CURRENT - || snapshot->pcm_state != (uint8)PCM_STATE_N - || snapshot->writer_activation_token != 0 - || snapshot->resource_x_activation_generation != 0 - || !snapshot->page_is_new) + || snapshot->pcm_state != (uint8)PCM_STATE_N || snapshot->writer_activation_token != 0 + || snapshot->resource_x_activation_generation != 0 || !snapshot->page_is_new) return CLUSTER_PCM_OWN_STALE; valid_page_kind = kind == CLUSTER_PCM_DIRECT_INIT_VM || kind == CLUSTER_PCM_DIRECT_INIT_FSM; @@ -107,8 +105,7 @@ cluster_pcm_direct_init_proof_consume(ClusterPcmDirectInitKind kind, || snapshot->generation != expected->generation || snapshot->reservation_token != expected->reservation_token || snapshot->writer_activation_token != expected->writer_activation_token - || snapshot->resource_x_activation_generation - != expected->resource_x_activation_generation + || snapshot->resource_x_activation_generation != expected->resource_x_activation_generation || snapshot->private_refcount != expected->private_refcount) return CLUSTER_PCM_OWN_STALE; @@ -116,11 +113,10 @@ cluster_pcm_direct_init_proof_consume(ClusterPcmDirectInitKind kind, } static ClusterPcmOwnResult -cluster_pcm_direct_init_target_shape_validate( - ClusterPcmDirectInitKind kind, - const ClusterPcmDirectInitSnapshot *snapshot, - uint8 expected_buffer_type, uint8 expected_pcm_state, - uint32 expected_flags) +cluster_pcm_direct_init_target_shape_validate(ClusterPcmDirectInitKind kind, + const ClusterPcmDirectInitSnapshot *snapshot, + uint8 expected_buffer_type, uint8 expected_pcm_state, + uint32 expected_flags) { bool valid_page_kind; @@ -129,30 +125,22 @@ cluster_pcm_direct_init_target_shape_validate( if (snapshot->buf_id < 0 || snapshot->private_refcount <= 0 || BUF_STATE_GET_REFCOUNT(snapshot->buf_state) == 0 || (snapshot->buf_state & BM_TAG_VALID) == 0 - || (snapshot->buf_state - & (BM_DIRTY | BM_JUST_DIRTIED | BM_IO_ERROR)) != 0 + || (snapshot->buf_state & (BM_DIRTY | BM_JUST_DIRTIED | BM_IO_ERROR)) != 0 || snapshot->buffer_type != expected_buffer_type - || snapshot->pcm_state != expected_pcm_state - || snapshot->flags != expected_flags - || snapshot->writer_activation_token != 0 - || snapshot->resource_x_activation_generation != 0 + || snapshot->pcm_state != expected_pcm_state || snapshot->flags != expected_flags + || snapshot->writer_activation_token != 0 || snapshot->resource_x_activation_generation != 0 || !snapshot->page_is_new) return CLUSTER_PCM_OWN_STALE; - valid_page_kind - = kind == CLUSTER_PCM_DIRECT_INIT_VM - || kind == CLUSTER_PCM_DIRECT_INIT_FSM; + valid_page_kind = kind == CLUSTER_PCM_DIRECT_INIT_VM || kind == CLUSTER_PCM_DIRECT_INIT_FSM; if (valid_page_kind) { - if ((snapshot->buf_state & BM_VALID) == 0 - || (snapshot->buf_state & BM_IO_IN_PROGRESS) != 0) + if ((snapshot->buf_state & BM_VALID) == 0 || (snapshot->buf_state & BM_IO_IN_PROGRESS) != 0) return CLUSTER_PCM_OWN_STALE; } else if ((snapshot->buf_state & BM_VALID) != 0 || (snapshot->buf_state & BM_IO_IN_PROGRESS) == 0) return CLUSTER_PCM_OWN_STALE; - if ((kind == CLUSTER_PCM_DIRECT_INIT_VM - && snapshot->tag.forkNum != VISIBILITYMAP_FORKNUM) - || (kind == CLUSTER_PCM_DIRECT_INIT_FSM - && snapshot->tag.forkNum != FSM_FORKNUM)) + if ((kind == CLUSTER_PCM_DIRECT_INIT_VM && snapshot->tag.forkNum != VISIBILITYMAP_FORKNUM) + || (kind == CLUSTER_PCM_DIRECT_INIT_FSM && snapshot->tag.forkNum != FSM_FORKNUM)) return CLUSTER_PCM_OWN_STALE; return CLUSTER_PCM_OWN_OK; } @@ -162,49 +150,41 @@ cluster_pcm_direct_init_target_shape_validate( * initialization authority and cannot arm a proof: it only validates the * immutable known-new shape needed to join that existing Resource-X round. */ ClusterPcmOwnResult -cluster_pcm_direct_init_aux_pending_observer_validate( - ClusterPcmDirectInitKind kind, - const ClusterPcmDirectInitSnapshot *snapshot) +cluster_pcm_direct_init_aux_pending_observer_validate(ClusterPcmDirectInitKind kind, + const ClusterPcmDirectInitSnapshot *snapshot) { ClusterPcmOwnResult live_result; - if ((kind != CLUSTER_PCM_DIRECT_INIT_VM - && kind != CLUSTER_PCM_DIRECT_INIT_FSM) + if ((kind != CLUSTER_PCM_DIRECT_INIT_VM && kind != CLUSTER_PCM_DIRECT_INIT_FSM) || snapshot == NULL) return CLUSTER_PCM_OWN_INVALID; if (snapshot->generation == UINT64_MAX) return CLUSTER_PCM_OWN_EXHAUSTED; - if (snapshot->reservation_token == 0 - || snapshot->reservation_token == UINT64_MAX) + if (snapshot->reservation_token == 0 || snapshot->reservation_token == UINT64_MAX) return CLUSTER_PCM_OWN_STALE; if (snapshot->flags != PCM_OWN_FLAG_GRANT_PENDING) { - live_result = cluster_pcm_own_classify_live_flags( - snapshot->flags, snapshot->reservation_token); - return live_result == CLUSTER_PCM_OWN_OK - ? CLUSTER_PCM_OWN_STALE : live_result; + live_result + = cluster_pcm_own_classify_live_flags(snapshot->flags, snapshot->reservation_token); + return live_result == CLUSTER_PCM_OWN_OK ? CLUSTER_PCM_OWN_STALE : live_result; } return cluster_pcm_direct_init_target_shape_validate( - kind, snapshot, (uint8)BUF_TYPE_CURRENT, (uint8)PCM_STATE_N, - PCM_OWN_FLAG_GRANT_PENDING); + kind, snapshot, (uint8)BUF_TYPE_CURRENT, (uint8)PCM_STATE_N, PCM_OWN_FLAG_GRANT_PENDING); } static bool -cluster_pcm_direct_init_target_identity_matches( - const ClusterPcmDirectInitSnapshot *snapshot, - const ClusterPcmDirectInitSnapshot *identity) +cluster_pcm_direct_init_target_identity_matches(const ClusterPcmDirectInitSnapshot *snapshot, + const ClusterPcmDirectInitSnapshot *identity) { - return snapshot->buf_id == identity->buf_id - && BufferTagsEqual(&snapshot->tag, &identity->tag) - && snapshot->private_refcount == identity->private_refcount - && snapshot->writer_activation_token == 0 - && snapshot->resource_x_activation_generation == 0; + return snapshot->buf_id == identity->buf_id && BufferTagsEqual(&snapshot->tag, &identity->tag) + && snapshot->private_refcount == identity->private_refcount + && snapshot->writer_activation_token == 0 + && snapshot->resource_x_activation_generation == 0; } ClusterPcmOwnResult -cluster_pcm_direct_init_target_pending_validate( - ClusterPcmDirectInitKind kind, - const ClusterPcmDirectInitSnapshot *pending, - const ClusterPcmDirectInitProof *consumed_proof) +cluster_pcm_direct_init_target_pending_validate(ClusterPcmDirectInitKind kind, + const ClusterPcmDirectInitSnapshot *pending, + const ClusterPcmDirectInitProof *consumed_proof) { const ClusterPcmDirectInitSnapshot *identity; ClusterPcmOwnResult result; @@ -218,23 +198,20 @@ cluster_pcm_direct_init_target_pending_validate( if (result != CLUSTER_PCM_OWN_OK) return result; result = cluster_pcm_direct_init_target_shape_validate( - kind, pending, (uint8)BUF_TYPE_CURRENT, (uint8)PCM_STATE_N, - PCM_OWN_FLAG_GRANT_PENDING); + kind, pending, (uint8)BUF_TYPE_CURRENT, (uint8)PCM_STATE_N, PCM_OWN_FLAG_GRANT_PENDING); if (result != CLUSTER_PCM_OWN_OK) return result; if (!cluster_pcm_direct_init_target_identity_matches(pending, identity) - || pending->generation != identity->generation - || identity->reservation_token == UINT64_MAX + || pending->generation != identity->generation || identity->reservation_token == UINT64_MAX || pending->reservation_token != identity->reservation_token + 1) return CLUSTER_PCM_OWN_STALE; return CLUSTER_PCM_OWN_OK; } ClusterPcmOwnResult -cluster_pcm_direct_init_target_commit_validate( - ClusterPcmDirectInitKind kind, - const ClusterPcmDirectInitSnapshot *committed, - const ClusterPcmDirectInitProof *consumed_proof) +cluster_pcm_direct_init_target_commit_validate(ClusterPcmDirectInitKind kind, + const ClusterPcmDirectInitSnapshot *committed, + const ClusterPcmDirectInitProof *consumed_proof) { const ClusterPcmDirectInitSnapshot *identity; ClusterPcmOwnResult result; @@ -247,13 +224,12 @@ cluster_pcm_direct_init_target_commit_validate( result = cluster_pcm_direct_init_snapshot_validate(kind, identity); if (result != CLUSTER_PCM_OWN_OK) return result; - result = cluster_pcm_direct_init_target_shape_validate( - kind, committed, (uint8)BUF_TYPE_XCUR, (uint8)PCM_STATE_X, 0); + result = cluster_pcm_direct_init_target_shape_validate(kind, committed, (uint8)BUF_TYPE_XCUR, + (uint8)PCM_STATE_X, 0); if (result != CLUSTER_PCM_OWN_OK) return result; if (!cluster_pcm_direct_init_target_identity_matches(committed, identity) - || identity->generation == UINT64_MAX - || committed->generation != identity->generation + 1 + || identity->generation == UINT64_MAX || committed->generation != identity->generation + 1 || identity->reservation_token == UINT64_MAX || committed->reservation_token != identity->reservation_token + 1) return CLUSTER_PCM_OWN_STALE; diff --git a/src/backend/cluster/cluster_pcm_lock.c b/src/backend/cluster/cluster_pcm_lock.c index 67d58a12eff..f4ec1de96e8 100644 --- a/src/backend/cluster/cluster_pcm_lock.c +++ b/src/backend/cluster/cluster_pcm_lock.c @@ -52,7 +52,7 @@ #include "cluster/cluster_scn.h" #include "cluster/cluster_shmem.h" #include "miscadmin.h" -#include "port/atomics.h" /* PGRAC: spec-2.30 D1 — pg_atomic_uint32/64 */ +#include "port/atomics.h" /* PGRAC: spec-2.30 D1 — pg_atomic_uint32/64 */ #include "portability/instr_time.h" #include "storage/backendid.h" /* PGRAC: spec-6.14 D9 amend — no-backend-identity guard */ #include "storage/buf_internals.h" @@ -72,15 +72,13 @@ * fails closed below. */ #if defined(__GNUC__) || defined(__clang__) #pragma weak cluster_gcs_try_send_transition_and_wait -#define PCM_GCS_TRY_SENDER_LINKED() \ - (cluster_gcs_try_send_transition_and_wait != NULL) +#define PCM_GCS_TRY_SENDER_LINKED() (cluster_gcs_try_send_transition_and_wait != NULL) #else #define PCM_GCS_TRY_SENDER_LINKED() true #endif #define PGRAC_RESOURCE_X_RETAINED_SENDER_GENERATION UINT32_C(1) -#define PGRAC_RESOURCE_X_OUTBOUND_OWNER_SLOTS \ - (RESOURCE_X_PROTOCOL_NODE_LIMIT + 5) +#define PGRAC_RESOURCE_X_OUTBOUND_OWNER_SLOTS (RESOURCE_X_PROTOCOL_NODE_LIMIT + 5) #define PGRAC_RESOURCE_X_WORK_OWNER_SLOTS (PGRAC_RESOURCE_X_OUTBOUND_OWNER_SLOTS + 2) #define PGRAC_RESOURCE_X_PROOF_DIGEST_OFFSET UINT64_C(1469598103934665603) #define PGRAC_RESOURCE_X_PROOF_DIGEST_PRIME UINT64_C(1099511628211) @@ -89,20 +87,16 @@ /* PGRAC adaptation identifiers. The external cutover manifest binds this * semantic creator fingerprint to the exact product tree; neither byte array * is represented as an Oracle internal record. */ -static const uint8 pcm_resource_x_completion_product_fingerprint[ - RESOURCE_X_COMPLETION_FINGERPRINT_BYTES] = { - 0x75, 0x31, 0x09, 0x2d, 0x1d, 0x8f, 0x64, 0x6a, - 0x1e, 0x35, 0x65, 0x3b, 0x55, 0xb0, 0xe4, 0x2e, - 0x4a, 0x18, 0xe7, 0x90, 0xd9, 0x78, 0x35, 0x36, - 0x19, 0x28, 0x07, 0x90, 0x6c, 0xf6, 0x60, 0x90 -}; -static const uint8 pcm_resource_x_send_c1_manifest_fingerprint[ - RESOURCE_X_COMPLETION_FINGERPRINT_BYTES] = { - 0xdf, 0x14, 0x38, 0x29, 0x7a, 0x73, 0xcc, 0xbd, - 0x19, 0x0c, 0xc6, 0x66, 0xaa, 0x97, 0x74, 0xb4, - 0x96, 0x52, 0x61, 0xc1, 0xfd, 0xa8, 0x34, 0xeb, - 0x41, 0x23, 0x27, 0xf7, 0x10, 0x6c, 0x20, 0x95 -}; +static const uint8 + pcm_resource_x_completion_product_fingerprint[RESOURCE_X_COMPLETION_FINGERPRINT_BYTES] + = { 0x75, 0x31, 0x09, 0x2d, 0x1d, 0x8f, 0x64, 0x6a, 0x1e, 0x35, 0x65, + 0x3b, 0x55, 0xb0, 0xe4, 0x2e, 0x4a, 0x18, 0xe7, 0x90, 0xd9, 0x78, + 0x35, 0x36, 0x19, 0x28, 0x07, 0x90, 0x6c, 0xf6, 0x60, 0x90 }; +static const uint8 + pcm_resource_x_send_c1_manifest_fingerprint[RESOURCE_X_COMPLETION_FINGERPRINT_BYTES] + = { 0xdf, 0x14, 0x38, 0x29, 0x7a, 0x73, 0xcc, 0xbd, 0x19, 0x0c, 0xc6, + 0x66, 0xaa, 0x97, 0x74, 0xb4, 0x96, 0x52, 0x61, 0xc1, 0xfd, 0xa8, + 0x34, 0xeb, 0x41, 0x23, 0x27, 0xf7, 0x10, 0x6c, 0x20, 0x95 }; /* @@ -382,7 +376,7 @@ struct GrdEntry { * ONLY via cluster_pcm_lock_pi_watermark_lsn_query. * The two are ORTHOGONAL (§2.8.1): detector never reads lsn, serve-gate * never reads scn. Both monotone-max, both cleared together on retire. */ - SCN pi_watermark_scn; /* 8B [112, 120) spec-2.41 D2 §2.8 Option A */ + SCN pi_watermark_scn; /* 8B [112, 120) spec-2.41 D2 §2.8 Option A */ /* Stage 8 R9 Resource-X executor state. The entry's immutable tag is * the assertion resource; requester_node completes the D6 assertion. */ int32 resource_x_requester_node; @@ -664,8 +658,7 @@ typedef struct ClusterPcmResourceXMasterState { int32 holder_pair_drained_master_node; uint32 holder_pair_drained_reserved; ClusterPcmResourceXBootstrapPriority bootstrap_priority; - ClusterPcmResourceXBootstrapReceipt - bootstrap_receipts[RESOURCE_X_PROTOCOL_NODE_LIMIT]; + ClusterPcmResourceXBootstrapReceipt bootstrap_receipts[RESOURCE_X_PROTOCOL_NODE_LIMIT]; ClusterPcmResourceXMasterRequest requests[RESOURCE_X_PROTOCOL_NODE_LIMIT]; ClusterPcmResourceXTerminalTombstone terminal_tombstone; ClusterPcmResourceXBlockIntent block_intents[RESOURCE_X_PROTOCOL_NODE_LIMIT]; @@ -880,56 +873,49 @@ static void pcm_entry_retire_refused_mark(PcmRetireRefusal why); /* S3 forensics step 1b — watermark-advance provenance recorder (defined with * the watermark helpers below; used by the inline writer sites above them). * Caller MUST hold the tag's GRD entry_lock and call ONLY on actual advance. */ -static void pcm_wm_prov_record(BufferTag tag, uint64 binding_generation, - SCN old_scn, SCN new_scn, ClusterPcmWmSrc source, - int32 sender_node, uint64 request_id, uint64 epoch); +static void pcm_wm_prov_record(BufferTag tag, uint64 binding_generation, SCN old_scn, SCN new_scn, + ClusterPcmWmSrc source, int32 sender_node, uint64 request_id, + uint64 epoch); static bool pcm_wm_prov_validate_retire_exact_locked(const BufferTag *tag, - uint64 binding_generation, ClusterPcmWmProvSlot **slot_out); + uint64 binding_generation, + ClusterPcmWmProvSlot **slot_out); static void pcm_entry_lock_exclusive(struct GrdEntry *entry); -static ClusterPcmResourceXMasterState *pcm_resource_x_master_state_for_entry( - const struct GrdEntry *entry); -static ClusterPcmResourceXMasterRequest *pcm_resource_x_master_head( - ClusterPcmResourceXMasterState *state, int32 *requester_node_out); +static ClusterPcmResourceXMasterState * +pcm_resource_x_master_state_for_entry(const struct GrdEntry *entry); +static ClusterPcmResourceXMasterRequest * +pcm_resource_x_master_head(ClusterPcmResourceXMasterState *state, int32 *requester_node_out); static bool pcm_resource_x_s_barrier_active_locked(struct GrdEntry *entry); static bool pcm_resource_x_local_owner_round_exact_locked(struct GrdEntry *entry, const ClusterPcmResourceXBootstrapRound *round); -static bool pcm_resource_x_bootstrap_receipt_valid( - const ClusterPcmResourceXBootstrapReceipt *receipt); -static bool pcm_resource_x_local_owner_handle_valid( - const ResourceXLocalOwnerHandle *handle); -static void pcm_resource_x_bootstrap_receipt_invalidate( - ClusterPcmResourceXBootstrapReceipt *receipt); -static bool pcm_resource_x_bootstrap_priority_valid( - const ClusterPcmResourceXBootstrapPriority *priority); -static void pcm_resource_x_bootstrap_priority_clear( - ClusterPcmResourceXBootstrapPriority *priority); +static bool +pcm_resource_x_bootstrap_receipt_valid(const ClusterPcmResourceXBootstrapReceipt *receipt); +static bool pcm_resource_x_local_owner_handle_valid(const ResourceXLocalOwnerHandle *handle); +static void +pcm_resource_x_bootstrap_receipt_invalidate(ClusterPcmResourceXBootstrapReceipt *receipt); +static bool +pcm_resource_x_bootstrap_priority_valid(const ClusterPcmResourceXBootstrapPriority *priority); +static void pcm_resource_x_bootstrap_priority_clear(ClusterPcmResourceXBootstrapPriority *priority); static uint64 pcm_resource_x_source_fence_get_u64(const uint8 *bytes); -static ResourceXApplyResult -pcm_resource_x_holder_pair_precedes_local_bootstrap_locked( - struct GrdEntry *entry, int32 current_master_node, - uint64 current_master_session, uint64 current_formation, - uint64 expected_carrier_generation); +static ResourceXApplyResult pcm_resource_x_holder_pair_precedes_local_bootstrap_locked( + struct GrdEntry *entry, int32 current_master_node, uint64 current_master_session, + uint64 current_formation, uint64 expected_carrier_generation); static ResourceXApplyResult pcm_resource_x_predecessor_wait_observation_locked( struct GrdEntry *entry, int32 current_master_node, uint64 current_master_session, uint64 current_formation, uint64 expected_carrier_generation); static bool pcm_resource_x_s_predecessor_superseded_unbound_wait_locked( - struct GrdEntry *entry, const ResourceXAssertion *assertion, - int32 current_master_node, uint64 current_master_session, - uint64 current_formation); -static bool pcm_resource_x_common_equal( - const ResourceXDecodedCommon *left, - const ResourceXDecodedCommon *right); -static void pcm_resource_x_bootstrap_round_clear_binding_locked( - ClusterPcmResourceXBootstrapRound *round); -static bool pcm_resource_x_local_owner_valid_locked( - const ClusterPcmResourceXLocalOwner *owner); + struct GrdEntry *entry, const ResourceXAssertion *assertion, int32 current_master_node, + uint64 current_master_session, uint64 current_formation); +static bool pcm_resource_x_common_equal(const ResourceXDecodedCommon *left, + const ResourceXDecodedCommon *right); +static void +pcm_resource_x_bootstrap_round_clear_binding_locked(ClusterPcmResourceXBootstrapRound *round); +static bool pcm_resource_x_local_owner_valid_locked(const ClusterPcmResourceXLocalOwner *owner); static ResourceXApplyResult pcm_resource_x_source_finish_snapshot_locked(struct GrdEntry *entry, ResourceXSourceFinishClaim *out); static bool pcm_resource_x_source_finish_pending_locked(struct GrdEntry *entry); -static bool pcm_resource_x_local_handoff_valid( - const ClusterPcmResourceXLocalHandoff *handoff); +static bool pcm_resource_x_local_handoff_valid(const ClusterPcmResourceXLocalHandoff *handoff); static bool pcm_resource_x_local_owner_priority_clear_locked(struct GrdEntry *entry); static bool pcm_resource_x_local_owner_expire_locked(struct GrdEntry *entry, uint64 now_us); static uint64 pcm_resource_x_monotonic_us(void); @@ -942,20 +928,19 @@ static void pcm_resource_x_head_fail_locked(struct GrdEntry *entry, uint8 reason static uint32 pcm_holder_bit(int holder_node_id); static PcmState pcm_transition_target(PcmLockTransition trans); static ResourceXReclaimResult pcm_resource_x_reclaim_requester_locked( - struct GrdEntry *entry, ClusterPcmResourceXMasterState *state, - int32 dead_node, uint64 dead_formation, ResourceXReclaimWitness *out, - bool *broadcast_out); -static bool pcm_resource_x_arm_block_intents_locked( - struct GrdEntry *entry, ClusterPcmResourceXMasterState *state, - ClusterPcmResourceXMasterRequest *request, int32 requester_node); + struct GrdEntry *entry, ClusterPcmResourceXMasterState *state, int32 dead_node, + uint64 dead_formation, ResourceXReclaimWitness *out, bool *broadcast_out); +static bool pcm_resource_x_arm_block_intents_locked(struct GrdEntry *entry, + ClusterPcmResourceXMasterState *state, + ClusterPcmResourceXMasterRequest *request, + int32 requester_node); static ResourceXApplyResult pcm_resource_x_build_authority_grant_locked( - struct GrdEntry *entry, - const ClusterPcmResourceXMasterRequest *request, - int32 requester_node, uint64 final_authority_generation, - ResourceXDecodedFrame *out); -static bool pcm_resource_x_redrive_grant_intent_locked( - struct GrdEntry *entry, ClusterPcmResourceXMasterState *state, - ClusterPcmResourceXMasterRequest *request, int32 requester_node); + struct GrdEntry *entry, const ClusterPcmResourceXMasterRequest *request, int32 requester_node, + uint64 final_authority_generation, ResourceXDecodedFrame *out); +static bool pcm_resource_x_redrive_grant_intent_locked(struct GrdEntry *entry, + ClusterPcmResourceXMasterState *state, + ClusterPcmResourceXMasterRequest *request, + int32 requester_node); static bool pcm_resource_x_intent_identity_equal(const ResourceXIntentSlot *left, const ResourceXIntentSlot *right); static bool @@ -980,24 +965,24 @@ typedef struct PcmResourceXRetirementWitness { uint64 t_install_us; } PcmResourceXRetirementWitness; -static ResourceXApplyResult pcm_resource_x_requester_join_bindable_locked( - struct GrdEntry *entry, const ResourceXAcquisitionRef *ref); +static ResourceXApplyResult +pcm_resource_x_requester_join_bindable_locked(struct GrdEntry *entry, + const ResourceXAcquisitionRef *ref); static bool pcm_resource_x_active_empty_locked(const struct GrdEntry *entry); static bool pcm_resource_x_active_valid_locked(const struct GrdEntry *entry); -static bool pcm_resource_x_requester_join_empty_locked( - const ClusterPcmResourceXRequesterJoin *join); -static bool pcm_resource_x_requester_join_decode_locked( - const ClusterPcmResourceXRequesterJoin *join, - ResourceXDecodedFrame *grant_out, ResourceXDecodedFrame *image_out); -static bool pcm_resource_x_requester_join_snapshot_locked( - const ClusterPcmResourceXRequesterJoin *join, - ResourceXRequesterJoinSnapshot *out); +static bool +pcm_resource_x_requester_join_empty_locked(const ClusterPcmResourceXRequesterJoin *join); +static bool +pcm_resource_x_requester_join_decode_locked(const ClusterPcmResourceXRequesterJoin *join, + ResourceXDecodedFrame *grant_out, + ResourceXDecodedFrame *image_out); +static bool +pcm_resource_x_requester_join_snapshot_locked(const ClusterPcmResourceXRequesterJoin *join, + ResourceXRequesterJoinSnapshot *out); static bool pcm_resource_x_bootstrap_round_terminal_cover_exact_locked( - struct GrdEntry *entry, - const ClusterPcmResourceXBootstrapRound *round, - const ResourceXAcquisitionRef *ref, - uint64 master_session_incarnation, uint64 r4_record_generation, - uint64 cached_ownership_generation); + struct GrdEntry *entry, const ClusterPcmResourceXBootstrapRound *round, + const ResourceXAcquisitionRef *ref, uint64 master_session_incarnation, + uint64 r4_record_generation, uint64 cached_ownership_generation); static bool pcm_resource_x_requester_join_live_round_base_exact_locked( struct GrdEntry *entry, const ClusterPcmResourceXBootstrapRound *round, const ResourceXDecodedFrame *frame, int32 authenticated_source_node, @@ -1009,12 +994,14 @@ static ResourceXApplyResult pcm_resource_x_requester_retirement_prepare_locked( static bool pcm_resource_x_delivery_mutation_allowed_locked(const struct GrdEntry *entry, const ResourceXAcquisitionRef *ref, const ResourceXDeliveryClaim *claim); -static bool pcm_resource_x_requester_settlement_arm_locked( - struct GrdEntry *entry, const ResourceXAcquisitionRef *ref, - const PcmResourceXRetirementWitness *witness); -static void pcm_resource_x_requester_retirement_commit_locked( - struct GrdEntry *entry, const ResourceXAcquisitionRef *ref, - const PcmResourceXRetirementWitness *witness); +static bool +pcm_resource_x_requester_settlement_arm_locked(struct GrdEntry *entry, + const ResourceXAcquisitionRef *ref, + const PcmResourceXRetirementWitness *witness); +static void +pcm_resource_x_requester_retirement_commit_locked(struct GrdEntry *entry, + const ResourceXAcquisitionRef *ref, + const PcmResourceXRetirementWitness *witness); /* ============================================================ @@ -1181,8 +1168,7 @@ pcm_lowest_set_bit_node(uint32 bitmap) } static int32 -pcm_resource_x_select_shared_current_carrier_locked( - struct GrdEntry *entry, uint32 candidate_bitmap) +pcm_resource_x_select_shared_current_carrier_locked(struct GrdEntry *entry, uint32 candidate_bitmap) { uint32 local_bit; @@ -1380,21 +1366,18 @@ cluster_pcm_lock_resource_x_gate_bind_formation_exact(uint64 formation) if (ClusterPcm == NULL || formation == 0 || formation == UINT64_MAX) return RESOURCE_X_APPLY_INVALID; - if (pg_atomic_read_u32(&ClusterPcm->resource_x_gate_phase) - != RESOURCE_X_GATE_OPEN) + if (pg_atomic_read_u32(&ClusterPcm->resource_x_gate_phase) != RESOURCE_X_GATE_OPEN) return RESOURCE_X_APPLY_BAD_STATE; current = pg_atomic_read_u64(&ClusterPcm->resource_x_gate_formation); if (current == formation) return RESOURCE_X_APPLY_DUPLICATE; - if (pg_atomic_read_u64(&ClusterPcm->resource_x_activation_inflight_count) - != 0) + if (pg_atomic_read_u64(&ClusterPcm->resource_x_activation_inflight_count) != 0) return RESOURCE_X_APPLY_BAD_STATE; if (current != 0) return RESOURCE_X_APPLY_STALE; current = 0; - if (pg_atomic_compare_exchange_u64(&ClusterPcm->resource_x_gate_formation, ¤t, - formation)) + if (pg_atomic_compare_exchange_u64(&ClusterPcm->resource_x_gate_formation, ¤t, formation)) return RESOURCE_X_APPLY_APPLIED; return current == formation ? RESOURCE_X_APPLY_DUPLICATE : RESOURCE_X_APPLY_STALE; } @@ -1409,8 +1392,7 @@ cluster_pcm_lock_resource_x_gate_bind_formation_exact(uint64 formation) * or write a resource. */ bool -cluster_pcm_lock_resource_x_cutover_gate_snapshot_exact( - ResourceXGateSnapshot *snapshot_out) +cluster_pcm_lock_resource_x_cutover_gate_snapshot_exact(ResourceXGateSnapshot *snapshot_out) { ResourceXGateSnapshot snapshot; uint32 dead_requester_bitmap; @@ -1428,34 +1410,24 @@ cluster_pcm_lock_resource_x_cutover_gate_snapshot_exact( for (attempt = 0; attempt < 8; attempt++) { memset(&snapshot, 0, sizeof(snapshot)); - snapshot.phase - = pg_atomic_read_u32(&ClusterPcm->resource_x_gate_phase); + snapshot.phase = pg_atomic_read_u32(&ClusterPcm->resource_x_gate_phase); pg_read_barrier(); - snapshot.formation - = pg_atomic_read_u64(&ClusterPcm->resource_x_gate_formation); - snapshot.freeze_generation - = pg_atomic_read_u64(&ClusterPcm->resource_x_freeze_generation); - activation_inflight = pg_atomic_read_u64( - &ClusterPcm->resource_x_activation_inflight_count); - reconfig_old_formation = pg_atomic_read_u64( - &ClusterPcm->resource_x_reconfig_old_formation); - reconfig_new_formation = pg_atomic_read_u64( - &ClusterPcm->resource_x_reconfig_new_formation); - dead_requester_bitmap = pg_atomic_read_u32( - &ClusterPcm->resource_x_reconfig_dead_requester_bitmap); + snapshot.formation = pg_atomic_read_u64(&ClusterPcm->resource_x_gate_formation); + snapshot.freeze_generation = pg_atomic_read_u64(&ClusterPcm->resource_x_freeze_generation); + activation_inflight = pg_atomic_read_u64(&ClusterPcm->resource_x_activation_inflight_count); + reconfig_old_formation = pg_atomic_read_u64(&ClusterPcm->resource_x_reconfig_old_formation); + reconfig_new_formation = pg_atomic_read_u64(&ClusterPcm->resource_x_reconfig_new_formation); + dead_requester_bitmap + = pg_atomic_read_u32(&ClusterPcm->resource_x_reconfig_dead_requester_bitmap); pg_read_barrier(); - phase_after - = pg_atomic_read_u32(&ClusterPcm->resource_x_gate_phase); + phase_after = pg_atomic_read_u32(&ClusterPcm->resource_x_gate_phase); if (snapshot.phase != phase_after) continue; *snapshot_out = snapshot; - return snapshot.phase == RESOURCE_X_GATE_OPEN - && snapshot.formation != UINT64_MAX - && snapshot.freeze_generation == 0 - && activation_inflight == 0 - && reconfig_old_formation == 0 - && reconfig_new_formation == 0 - && dead_requester_bitmap == 0; + return snapshot.phase == RESOURCE_X_GATE_OPEN && snapshot.formation != UINT64_MAX + && snapshot.freeze_generation == 0 && activation_inflight == 0 + && reconfig_old_formation == 0 && reconfig_new_formation == 0 + && dead_requester_bitmap == 0; } return false; } @@ -1475,46 +1447,36 @@ cluster_pcm_lock_resource_x_gate_snapshot(ResourceXGateSnapshot *snapshot_out) for (attempt = 0; attempt < 8; attempt++) { memset(&snapshot, 0, sizeof(snapshot)); - snapshot.phase - = pg_atomic_read_u32(&ClusterPcm->resource_x_gate_phase); + snapshot.phase = pg_atomic_read_u32(&ClusterPcm->resource_x_gate_phase); pg_read_barrier(); - snapshot.formation - = pg_atomic_read_u64(&ClusterPcm->resource_x_gate_formation); - snapshot.freeze_generation - = pg_atomic_read_u64(&ClusterPcm->resource_x_freeze_generation); + snapshot.formation = pg_atomic_read_u64(&ClusterPcm->resource_x_gate_formation); + snapshot.freeze_generation = pg_atomic_read_u64(&ClusterPcm->resource_x_freeze_generation); pg_read_barrier(); - phase_after - = pg_atomic_read_u32(&ClusterPcm->resource_x_gate_phase); + phase_after = pg_atomic_read_u32(&ClusterPcm->resource_x_gate_phase); if (snapshot.phase != phase_after) continue; *snapshot_out = snapshot; - return snapshot.formation != 0 - && snapshot.formation != UINT64_MAX - && snapshot.freeze_generation != UINT64_MAX - && (snapshot.phase == RESOURCE_X_GATE_OPEN - || snapshot.phase == RESOURCE_X_GATE_FROZEN - || snapshot.phase == RESOURCE_X_GATE_RECOVERY_BLOCKED); + return snapshot.formation != 0 && snapshot.formation != UINT64_MAX + && snapshot.freeze_generation != UINT64_MAX + && (snapshot.phase == RESOURCE_X_GATE_OPEN + || snapshot.phase == RESOURCE_X_GATE_FROZEN + || snapshot.phase == RESOURCE_X_GATE_RECOVERY_BLOCKED); } return false; } ResourceXApplyResult -cluster_pcm_lock_resource_x_gate_fail_closed_exact( - const ResourceXGateSnapshot *expected) +cluster_pcm_lock_resource_x_gate_fail_closed_exact(const ResourceXGateSnapshot *expected) { uint32 phase; - if (ClusterPcm == NULL || expected == NULL - || expected->reserved != 0 - || expected->formation == 0 - || expected->formation == UINT64_MAX - || expected->freeze_generation == UINT64_MAX - || expected->phase != RESOURCE_X_GATE_OPEN) + if (ClusterPcm == NULL || expected == NULL || expected->reserved != 0 + || expected->formation == 0 || expected->formation == UINT64_MAX + || expected->freeze_generation == UINT64_MAX || expected->phase != RESOURCE_X_GATE_OPEN) return RESOURCE_X_APPLY_INVALID; - if (pg_atomic_read_u64(&ClusterPcm->resource_x_gate_formation) - != expected->formation + if (pg_atomic_read_u64(&ClusterPcm->resource_x_gate_formation) != expected->formation || pg_atomic_read_u64(&ClusterPcm->resource_x_freeze_generation) - != expected->freeze_generation) + != expected->freeze_generation) return RESOURCE_X_APPLY_STALE; phase = pg_atomic_read_u32(&ClusterPcm->resource_x_gate_phase); @@ -1525,11 +1487,9 @@ cluster_pcm_lock_resource_x_gate_fail_closed_exact( } if (phase != RESOURCE_X_GATE_OPEN) return RESOURCE_X_APPLY_STALE; - if (pg_atomic_compare_exchange_u32( - &ClusterPcm->resource_x_gate_phase, &phase, - RESOURCE_X_GATE_RECOVERY_BLOCKED)) { - pg_atomic_fetch_add_u64( - &ClusterPcm->resource_x_reconfig_blocked_count, 1); + if (pg_atomic_compare_exchange_u32(&ClusterPcm->resource_x_gate_phase, &phase, + RESOURCE_X_GATE_RECOVERY_BLOCKED)) { + pg_atomic_fetch_add_u64(&ClusterPcm->resource_x_reconfig_blocked_count, 1); cluster_pcm_rx_metric_note(PCM_RX_GLOBAL_FUSE_TRIGGER); return RESOURCE_X_APPLY_APPLIED; } @@ -1539,17 +1499,14 @@ cluster_pcm_lock_resource_x_gate_fail_closed_exact( bool cluster_pcm_lock_resource_x_gate_open_exact(uint64 formation) { - return formation != 0 && formation != UINT64_MAX - && ClusterPcm != NULL - && pg_atomic_read_u32(&ClusterPcm->resource_x_gate_phase) - == RESOURCE_X_GATE_OPEN - && pg_atomic_read_u64(&ClusterPcm->resource_x_gate_formation) - == formation; + return formation != 0 && formation != UINT64_MAX && ClusterPcm != NULL + && pg_atomic_read_u32(&ClusterPcm->resource_x_gate_phase) == RESOURCE_X_GATE_OPEN + && pg_atomic_read_u64(&ClusterPcm->resource_x_gate_formation) == formation; } bool cluster_pcm_lock_resource_x_executor_enter(const ResourceXAcquisitionRef *ref, - ResourceXActivationGateToken *out_gate) + ResourceXActivationGateToken *out_gate) { uint32 phase; uint64 formation; @@ -1568,8 +1525,7 @@ cluster_pcm_lock_resource_x_executor_enter(const ResourceXAcquisitionRef *ref, } out_gate->formation = formation; - out_gate->freeze_generation - = pg_atomic_read_u64(&ClusterPcm->resource_x_freeze_generation); + out_gate->freeze_generation = pg_atomic_read_u64(&ClusterPcm->resource_x_freeze_generation); out_gate->acquisition_generation = ref->acquisition_generation; out_gate->active = 1; return true; @@ -1604,33 +1560,24 @@ pcm_resource_x_reconfig_token_exact(const ResourceXReconfigToken *token) && token->new_formation == pg_atomic_read_u64(&ClusterPcm->resource_x_reconfig_new_formation) && token->dead_requester_bitmap - == pg_atomic_read_u32( - &ClusterPcm->resource_x_reconfig_dead_requester_bitmap) + == pg_atomic_read_u32(&ClusterPcm->resource_x_reconfig_dead_requester_bitmap) && token->freeze_generation == pg_atomic_read_u64(&ClusterPcm->resource_x_freeze_generation); } static bool -pcm_resource_x_reconfig_pending_token_exact( - const ResourceXReconfigToken *token) -{ - return token != NULL - && token->old_formation != 0 - && token->old_formation != UINT64_MAX - && token->new_formation == 0 - && token->freeze_generation != 0 - && token->freeze_generation != UINT64_MAX - && token->reserved == 0 - && token->old_formation - == pg_atomic_read_u64( - &ClusterPcm->resource_x_reconfig_old_formation) - && pg_atomic_read_u64( - &ClusterPcm->resource_x_reconfig_new_formation) == 0 - && token->dead_requester_bitmap - == pg_atomic_read_u32( - &ClusterPcm->resource_x_reconfig_dead_requester_bitmap) - && token->freeze_generation - == pg_atomic_read_u64(&ClusterPcm->resource_x_freeze_generation); +pcm_resource_x_reconfig_pending_token_exact(const ResourceXReconfigToken *token) +{ + return token != NULL && token->old_formation != 0 && token->old_formation != UINT64_MAX + && token->new_formation == 0 && token->freeze_generation != 0 + && token->freeze_generation != UINT64_MAX && token->reserved == 0 + && token->old_formation + == pg_atomic_read_u64(&ClusterPcm->resource_x_reconfig_old_formation) + && pg_atomic_read_u64(&ClusterPcm->resource_x_reconfig_new_formation) == 0 + && token->dead_requester_bitmap + == pg_atomic_read_u32(&ClusterPcm->resource_x_reconfig_dead_requester_bitmap) + && token->freeze_generation + == pg_atomic_read_u64(&ClusterPcm->resource_x_freeze_generation); } static void @@ -1660,11 +1607,9 @@ pcm_resource_x_semantic_mutation_mark(void) /* No proof exists while ordinary admission is OPEN. Restrict the global * sequence cache line to the frozen episode so the normal PCM hot path * pays only this phase read and never contends on a proof counter. */ - if (pg_atomic_read_u32(&ClusterPcm->resource_x_gate_phase) - != RESOURCE_X_GATE_FROZEN) + if (pg_atomic_read_u32(&ClusterPcm->resource_x_gate_phase) != RESOURCE_X_GATE_FROZEN) return; - current = pg_atomic_read_u64( - &ClusterPcm->resource_x_semantic_mutation_sequence); + current = pg_atomic_read_u64(&ClusterPcm->resource_x_semantic_mutation_sequence); for (;;) { if (current == 0 || current == UINT64_MAX) { pcm_resource_x_reconfig_block(); @@ -1674,9 +1619,8 @@ pcm_resource_x_semantic_mutation_mark(void) "PGRAC_NODE=%d PGRAC_ATTEMPT=0 ", cluster_node_id))); } - if (pg_atomic_compare_exchange_u64( - &ClusterPcm->resource_x_semantic_mutation_sequence, - ¤t, current + 1)) + if (pg_atomic_compare_exchange_u64(&ClusterPcm->resource_x_semantic_mutation_sequence, + ¤t, current + 1)) return; } } @@ -1691,16 +1635,14 @@ pcm_entry_lifecycle_mutation_mark(void) if (ClusterPcm == NULL) return false; - current = pg_atomic_read_u64( - &ClusterPcm->resource_x_semantic_mutation_sequence); + current = pg_atomic_read_u64(&ClusterPcm->resource_x_semantic_mutation_sequence); for (;;) { if (current == 0 || current == UINT64_MAX) { pcm_resource_x_reconfig_block(); return false; } - if (pg_atomic_compare_exchange_u64( - &ClusterPcm->resource_x_semantic_mutation_sequence, - ¤t, current + 1)) + if (pg_atomic_compare_exchange_u64(&ClusterPcm->resource_x_semantic_mutation_sequence, + ¤t, current + 1)) return true; } } @@ -1717,16 +1659,14 @@ pcm_entry_reclaim_request(void) * neither can reset an already-active scan. */ if (pg_atomic_read_u32(&ClusterPcm->reclaim_requested) == 0) { pg_atomic_write_u64(&ClusterPcm->reclaim_scan_cursor, 0); - (void)pg_atomic_compare_exchange_u32( - &ClusterPcm->reclaim_requested, &expected, 1); + (void)pg_atomic_compare_exchange_u32(&ClusterPcm->reclaim_requested, &expected, 1); } } static void pcm_entry_retire_refused_mark(PcmRetireRefusal why) { - if (ClusterPcm == NULL || why <= PCM_RETIRE_REFUSAL_NONE - || why >= PCM_RETIRE_REFUSAL_N) + if (ClusterPcm == NULL || why <= PCM_RETIRE_REFUSAL_NONE || why >= PCM_RETIRE_REFUSAL_N) return; pg_atomic_fetch_add_u64(&ClusterPcm->reclaim_refused[why], 1); } @@ -1738,8 +1678,7 @@ pcm_atomic_max_u64(pg_atomic_uint64 *value, uint64 candidate) Assert(value != NULL); current = pg_atomic_read_u64(value); - while (current < candidate - && !pg_atomic_compare_exchange_u64(value, ¤t, candidate)) + while (current < candidate && !pg_atomic_compare_exchange_u64(value, ¤t, candidate)) ; } @@ -1749,10 +1688,8 @@ pcm_entry_mark_quiescing_locked(struct GrdEntry *entry) uint32 lifecycle; Assert(entry != NULL); - Assert(LWLockHeldByMeInMode( - &entry->entry_lock.lock, LW_EXCLUSIVE)); - if (pg_atomic_read_u32(&ClusterPcm->resource_x_gate_phase) - != RESOURCE_X_GATE_OPEN + Assert(LWLockHeldByMeInMode(&entry->entry_lock.lock, LW_EXCLUSIVE)); + if (pg_atomic_read_u32(&ClusterPcm->resource_x_gate_phase) != RESOURCE_X_GATE_OPEN || pg_atomic_read_u64(&ClusterPcm->resource_x_gate_formation) == 0) return false; lifecycle = pg_atomic_read_u32(&entry->lifecycle); @@ -1785,24 +1722,24 @@ pcm_resource_x_proof_digest_tag(uint64 digest, const BufferTag *tag) digest = pcm_resource_x_proof_digest_u64(digest, (uint64)tag->spcOid); digest = pcm_resource_x_proof_digest_u64(digest, (uint64)tag->dbOid); digest = pcm_resource_x_proof_digest_u64(digest, (uint64)tag->relNumber); - digest = pcm_resource_x_proof_digest_u64( - digest, (uint64)(uint32)tag->forkNum); + digest = pcm_resource_x_proof_digest_u64(digest, (uint64)(uint32)tag->forkNum); return pcm_resource_x_proof_digest_u64(digest, (uint64)tag->blockNum); } -static ResourceXApplyResult pcm_resource_x_holder_pair_decode_locked( - const ClusterPcmResourceXMasterState *state, - ResourceXDecodedFrame *status_out, ResourceXDecodedFrame *image_out); +static ResourceXApplyResult +pcm_resource_x_holder_pair_decode_locked(const ClusterPcmResourceXMasterState *state, + ResourceXDecodedFrame *status_out, + ResourceXDecodedFrame *image_out); /* A committed drain leaves the canonical pair bytes in place so an exact * duplicate settlement can be authenticated without touching BufferDesc * again. Those bytes are terminal history only when the published pair, * empty send intents and drain tombstone all name the same episode. */ static bool -pcm_resource_x_holder_pair_drained_history_locked( - struct GrdEntry *entry, - const ClusterPcmResourceXMasterState *state, - ResourceXDecodedFrame *status_out, ResourceXDecodedFrame *image_out) +pcm_resource_x_holder_pair_drained_history_locked(struct GrdEntry *entry, + const ClusterPcmResourceXMasterState *state, + ResourceXDecodedFrame *status_out, + ResourceXDecodedFrame *image_out) { ResourceXDecodedFrame image; ResourceXDecodedFrame status; @@ -1811,27 +1748,20 @@ pcm_resource_x_holder_pair_drained_history_locked( Assert(entry != NULL); Assert(state != NULL); Assert(LWLockHeldByMeInMode(&entry->entry_lock.lock, LW_SHARED) - || LWLockHeldByMeInMode(&entry->entry_lock.lock, LW_EXCLUSIVE)); + || LWLockHeldByMeInMode(&entry->entry_lock.lock, LW_EXCLUSIVE)); if (state->holder_status.valid != RESOURCE_X_HOLDER_PAIR_PUBLISHED || state->holder_image.valid != RESOURCE_X_HOLDER_PAIR_PUBLISHED - || state->holder_status_intent.slot.state - != RESOURCE_X_INTENT_SLOT_EMPTY - || state->holder_image_intent.state - != RESOURCE_X_INTENT_SLOT_EMPTY - || pcm_resource_x_holder_pair_decode_locked( - state, &status, &image) != RESOURCE_X_APPLY_APPLIED) + || state->holder_status_intent.slot.state != RESOURCE_X_INTENT_SLOT_EMPTY + || state->holder_image_intent.state != RESOURCE_X_INTENT_SLOT_EMPTY + || pcm_resource_x_holder_pair_decode_locked(state, &status, &image) + != RESOURCE_X_APPLY_APPLIED) return false; requester_node = status.common.logical_assertion.requester_node; - if (requester_node < 0 - || requester_node >= RESOURCE_X_PROTOCOL_NODE_LIMIT - || state->holder_pair_drained_sequences[requester_node] - != status.common.assertion_sequence - || state->holder_pair_drained_resource_formation - != status.common.resource_formation - || state->holder_pair_drained_master_session - != status.common.master_session_incarnation - || state->holder_pair_drained_master_node - != (int32)state->holder_status.destination_node + if (requester_node < 0 || requester_node >= RESOURCE_X_PROTOCOL_NODE_LIMIT + || state->holder_pair_drained_sequences[requester_node] != status.common.assertion_sequence + || state->holder_pair_drained_resource_formation != status.common.resource_formation + || state->holder_pair_drained_master_session != status.common.master_session_incarnation + || state->holder_pair_drained_master_node != (int32)state->holder_status.destination_node || state->holder_pair_drained_reserved != 0) return false; if (status_out != NULL) @@ -1846,10 +1776,9 @@ pcm_resource_x_holder_pair_drained_history_locked( * kind-10 slot, and ACKED retains only the canonical payload as a bounded * duplicate tombstone. */ static bool -pcm_resource_x_source_settlement_debt_decode_locked( - struct GrdEntry *entry, - const ClusterPcmResourceXMasterState *state, - ResourceXDecodedFrame *settlement_out) +pcm_resource_x_source_settlement_debt_decode_locked(struct GrdEntry *entry, + const ClusterPcmResourceXMasterState *state, + ResourceXDecodedFrame *settlement_out) { static const ClusterPcmResourceXSourceSettlement empty_debt; static const ResourceXIntentSlot empty_slot; @@ -1861,23 +1790,18 @@ pcm_resource_x_source_settlement_debt_decode_locked( Assert(state != NULL); Assert(settlement_out != NULL); Assert(LWLockHeldByMeInMode(&entry->entry_lock.lock, LW_SHARED) - || LWLockHeldByMeInMode(&entry->entry_lock.lock, LW_EXCLUSIVE)); + || LWLockHeldByMeInMode(&entry->entry_lock.lock, LW_EXCLUSIVE)); memset(settlement_out, 0, sizeof(*settlement_out)); debt = &state->source_settlement; if (debt->state == RESOURCE_X_SOURCE_SETTLEMENT_NONE) return memcmp(debt, &empty_debt, sizeof(*debt)) == 0; if ((debt->state != RESOURCE_X_SOURCE_SETTLEMENT_PENDING - && debt->state != RESOURCE_X_SOURCE_SETTLEMENT_ACKED) - || memcmp(debt->reserved, (uint8[7]){0}, - sizeof(debt->reserved)) != 0 - || !cluster_resource_x_wire_decode( - RESOURCE_X_MSG_BLOCK_TO_N, debt->intent.payload, - RESOURCE_X_PROOF_V1_BYTES, settlement_out, &reject) - || settlement_out->kind - != RESOURCE_X_WIRE_SOURCE_SETTLEMENT_V2 - || !BufferTagsEqual( - &settlement_out->common.logical_assertion.resource, - &entry->tag)) + && debt->state != RESOURCE_X_SOURCE_SETTLEMENT_ACKED) + || memcmp(debt->reserved, (uint8[7]){ 0 }, sizeof(debt->reserved)) != 0 + || !cluster_resource_x_wire_decode(RESOURCE_X_MSG_BLOCK_TO_N, debt->intent.payload, + RESOURCE_X_PROOF_V1_BYTES, settlement_out, &reject) + || settlement_out->kind != RESOURCE_X_WIRE_SOURCE_SETTLEMENT_V2 + || !BufferTagsEqual(&settlement_out->common.logical_assertion.resource, &entry->tag)) return false; slot = &debt->intent.slot; @@ -1885,25 +1809,19 @@ pcm_resource_x_source_settlement_debt_decode_locked( return memcmp(slot, &empty_slot, sizeof(*slot)) == 0; return (slot->state == RESOURCE_X_INTENT_SLOT_ARMED || slot->state == RESOURCE_X_INTENT_SLOT_STAGED) - && slot->logical_generation - == settlement_out->common.assertion_sequence - && slot->authority_generation - == settlement_out->common.authority_generation - && slot->first_armed_us != 0 - && slot->first_armed_us != UINT64_MAX - && slot->last_attempt_us != UINT64_MAX - && slot->destination_node - == settlement_out->common.action_node - && slot->payload_bytes == RESOURCE_X_PROOF_V1_BYTES - && slot->kind == RESOURCE_X_WIRE_SOURCE_SETTLEMENT_V2 - && resource_x_assertion_equal( - &slot->body.assertion, - &settlement_out->common.logical_assertion) - && slot->body.owner_generation == slot->logical_generation - && slot->body.owner_node < RESOURCE_X_PROTOCOL_NODE_LIMIT - && slot->body.owner_kind - == RESOURCE_X_INTENT_OWNER_HOLDER_RELEASE - && slot->body.owner_index == 0 && slot->body.reserved == 0; + && slot->logical_generation == settlement_out->common.assertion_sequence + && slot->authority_generation == settlement_out->common.authority_generation + && slot->first_armed_us != 0 && slot->first_armed_us != UINT64_MAX + && slot->last_attempt_us != UINT64_MAX + && slot->destination_node == settlement_out->common.action_node + && slot->payload_bytes == RESOURCE_X_PROOF_V1_BYTES + && slot->kind == RESOURCE_X_WIRE_SOURCE_SETTLEMENT_V2 + && resource_x_assertion_equal(&slot->body.assertion, + &settlement_out->common.logical_assertion) + && slot->body.owner_generation == slot->logical_generation + && slot->body.owner_node < RESOURCE_X_PROTOCOL_NODE_LIMIT + && slot->body.owner_kind == RESOURCE_X_INTENT_OWNER_HOLDER_RELEASE + && slot->body.owner_index == 0 && slot->body.reserved == 0; } /* Stage 8 8.15-PRE-CAP D3: the sole production retire eligibility table. @@ -1911,8 +1829,8 @@ pcm_resource_x_source_settlement_debt_decode_locked( * helper is deliberately read-only; D4 owns sidecar clearing and HASH_REMOVE. */ static bool -pcm_entry_retire_eligible_locked(struct GrdEntry *entry, - uint64 expected_generation, PcmRetireRefusal *why) +pcm_entry_retire_eligible_locked(struct GrdEntry *entry, uint64 expected_generation, + PcmRetireRefusal *why) { static const ClusterPcmResourceXMasterRequest empty_request; static const ClusterPcmResourceXTerminalTombstone empty_tombstone; @@ -1926,14 +1844,11 @@ pcm_entry_retire_eligible_locked(struct GrdEntry *entry, Assert(entry != NULL); Assert(why != NULL); - Assert(LWLockHeldByMeInMode( - &ClusterPcm->htab_lock.lock, LW_EXCLUSIVE)); - Assert(LWLockHeldByMeInMode( - &entry->entry_lock.lock, LW_EXCLUSIVE)); + Assert(LWLockHeldByMeInMode(&ClusterPcm->htab_lock.lock, LW_EXCLUSIVE)); + Assert(LWLockHeldByMeInMode(&entry->entry_lock.lock, LW_EXCLUSIVE)); *why = PCM_RETIRE_REFUSAL_NONE; - if (pg_atomic_read_u32(&ClusterPcm->resource_x_gate_phase) - != RESOURCE_X_GATE_OPEN) { + if (pg_atomic_read_u32(&ClusterPcm->resource_x_gate_phase) != RESOURCE_X_GATE_OPEN) { *why = PCM_RETIRE_REFUSAL_GATE_NOT_OPEN; return false; } @@ -1963,10 +1878,8 @@ pcm_entry_retire_eligible_locked(struct GrdEntry *entry, *why = PCM_RETIRE_REFUSAL_PCM_MODE_NOT_N; return false; } - if (entry->x_holder_node != -1 - || pg_atomic_read_u32(&entry->s_holders_bitmap) != 0 - || entry->s_holder_refcount_local != 0 - || pcm_master_holder_is_valid(entry)) { + if (entry->x_holder_node != -1 || pg_atomic_read_u32(&entry->s_holders_bitmap) != 0 + || entry->s_holder_refcount_local != 0 || pcm_master_holder_is_valid(entry)) { *why = PCM_RETIRE_REFUSAL_HOLDER_PRESENT; return false; } @@ -1974,38 +1887,31 @@ pcm_entry_retire_eligible_locked(struct GrdEntry *entry, *why = PCM_RETIRE_REFUSAL_PI_PRESENT; return false; } - if (entry->pi_watermark_lsn != InvalidXLogRecPtr - || entry->pi_watermark_scn != InvalidScn) { + if (entry->pi_watermark_lsn != InvalidXLogRecPtr || entry->pi_watermark_scn != InvalidScn) { *why = PCM_RETIRE_REFUSAL_WATERMARK_PRESENT; return false; } - if (entry->pending_x_requester_node != -1 - || entry->pending_x_since_lsn != 0 + if (entry->pending_x_requester_node != -1 || entry->pending_x_since_lsn != 0 || entry->convert_queue != NULL) { *why = PCM_RETIRE_REFUSAL_CONVERT_PENDING; return false; } - gate_formation - = pg_atomic_read_u64(&ClusterPcm->resource_x_gate_formation); - if (entry->resource_x_formation != 0 - && entry->resource_x_formation != gate_formation) { + gate_formation = pg_atomic_read_u64(&ClusterPcm->resource_x_gate_formation); + if (entry->resource_x_formation != 0 && entry->resource_x_formation != gate_formation) { *why = PCM_RETIRE_REFUSAL_FORMATION_STALE; return false; } - if (!pcm_resource_x_local_owner_valid_locked( - &entry->resource_x_local_owner)) { + if (!pcm_resource_x_local_owner_valid_locked(&entry->resource_x_local_owner)) { *why = PCM_RETIRE_REFUSAL_SIDECAR_NOT_TERMINAL; return false; } - if (entry->registry_slot >= (uint32)pcm_grd_effective - || cluster_pcm_resource_x_slots == NULL + if (entry->registry_slot >= (uint32)pcm_grd_effective || cluster_pcm_resource_x_slots == NULL || cluster_pcm_resource_x_master_states == NULL) { *why = PCM_RETIRE_REFUSAL_IDENTITY_MISMATCH; return false; } registry_slot = &cluster_pcm_resource_x_slots[entry->registry_slot]; - if (registry_slot->state != PCM_REGISTRY_LIVE - || registry_slot->reserved != 0 + if (registry_slot->state != PCM_REGISTRY_LIVE || registry_slot->reserved != 0 || !BufferTagsEqual(®istry_slot->tag, &entry->tag) || registry_slot->binding_generation != expected_generation || registry_slot->retired_authority_generation != 0) { @@ -2018,53 +1924,39 @@ pcm_entry_retire_eligible_locked(struct GrdEntry *entry, return false; } if (state->holder_status.valid != 0 || state->holder_image.valid != 0 - || state->holder_status_intent.slot.state - != RESOURCE_X_INTENT_SLOT_EMPTY - || state->holder_image_intent.state - != RESOURCE_X_INTENT_SLOT_EMPTY) { + || state->holder_status_intent.slot.state != RESOURCE_X_INTENT_SLOT_EMPTY + || state->holder_image_intent.state != RESOURCE_X_INTENT_SLOT_EMPTY) { *why = PCM_RETIRE_REFUSAL_RETAINED_PAIR_PRESENT; return false; } - if (!pcm_resource_x_requester_join_empty_locked( - &state->requester_join) - || state->requester_settlement_intent.slot.state - != RESOURCE_X_INTENT_SLOT_EMPTY) { + if (!pcm_resource_x_requester_join_empty_locked(&state->requester_join) + || state->requester_settlement_intent.slot.state != RESOURCE_X_INTENT_SLOT_EMPTY) { *why = PCM_RETIRE_REFUSAL_REQUESTER_NOT_TERMINAL; return false; } - if (!pcm_resource_x_source_settlement_debt_decode_locked( - entry, state, &source_settlement)) { + if (!pcm_resource_x_source_settlement_debt_decode_locked(entry, state, &source_settlement)) { *why = PCM_RETIRE_REFUSAL_SIDECAR_NOT_TERMINAL; return false; } - if (state->source_settlement.state - == RESOURCE_X_SOURCE_SETTLEMENT_PENDING) { + if (state->source_settlement.state == RESOURCE_X_SOURCE_SETTLEMENT_PENDING) { *why = PCM_RETIRE_REFUSAL_REQUESTER_NOT_TERMINAL; return false; } - if (!pcm_resource_x_bootstrap_priority_valid( - &state->bootstrap_priority) - || state->bootstrap_priority.state - != RESOURCE_X_BOOTSTRAP_PRIORITY_EMPTY - || state->grant_intent.slot.state - != RESOURCE_X_INTENT_SLOT_EMPTY - || state->authority_generation == 0 - || state->authority_generation == UINT64_MAX - || state->next_enqueue_order == 0 - || state->next_enqueue_order == UINT64_MAX) { + if (!pcm_resource_x_bootstrap_priority_valid(&state->bootstrap_priority) + || state->bootstrap_priority.state != RESOURCE_X_BOOTSTRAP_PRIORITY_EMPTY + || state->grant_intent.slot.state != RESOURCE_X_INTENT_SLOT_EMPTY + || state->authority_generation == 0 || state->authority_generation == UINT64_MAX + || state->next_enqueue_order == 0 || state->next_enqueue_order == UINT64_MAX) { *why = PCM_RETIRE_REFUSAL_SIDECAR_NOT_TERMINAL; return false; } for (node = 0; node < RESOURCE_X_PROTOCOL_NODE_LIMIT; node++) { - const ClusterPcmResourceXBootstrapReceipt *receipt - = &state->bootstrap_receipts[node]; - const ClusterPcmResourceXMasterRequest *request - = &state->requests[node]; + const ClusterPcmResourceXBootstrapReceipt *receipt = &state->bootstrap_receipts[node]; + const ClusterPcmResourceXMasterRequest *request = &state->requests[node]; if (!pcm_resource_x_bootstrap_receipt_valid(receipt) || receipt->state != RESOURCE_X_BOOTSTRAP_RECEIPT_EMPTY - || state->block_intents[node].slot.state - != RESOURCE_X_INTENT_SLOT_EMPTY) { + || state->block_intents[node].slot.state != RESOURCE_X_INTENT_SLOT_EMPTY) { *why = PCM_RETIRE_REFUSAL_SIDECAR_NOT_TERMINAL; return false; } @@ -2073,10 +1965,8 @@ pcm_entry_retire_eligible_locked(struct GrdEntry *entry, *why = PCM_RETIRE_REFUSAL_SIDECAR_NOT_TERMINAL; return false; } - } else if (request->phase != RESOURCE_X_MASTER_RELEASED - || request->resource_formation == 0 - || request->resource_formation == UINT64_MAX - || request->assertion_sequence == 0 + } else if (request->phase != RESOURCE_X_MASTER_RELEASED || request->resource_formation == 0 + || request->resource_formation == UINT64_MAX || request->assertion_sequence == 0 || request->assertion_sequence == UINT64_MAX) { *why = PCM_RETIRE_REFUSAL_SIDECAR_NOT_TERMINAL; return false; @@ -2085,20 +1975,15 @@ pcm_entry_retire_eligible_locked(struct GrdEntry *entry, drained = true; } if (state->terminal_tombstone.valid == 0) { - if (memcmp(&state->terminal_tombstone, &empty_tombstone, - sizeof(empty_tombstone)) != 0) { + if (memcmp(&state->terminal_tombstone, &empty_tombstone, sizeof(empty_tombstone)) != 0) { *why = PCM_RETIRE_REFUSAL_SIDECAR_NOT_TERMINAL; return false; } - } else if (state->terminal_tombstone.valid != 1 - || state->terminal_tombstone.requester_node < 0 - || state->terminal_tombstone.requester_node - >= RESOURCE_X_PROTOCOL_NODE_LIMIT - || state->terminal_tombstone.request.phase - != RESOURCE_X_MASTER_RELEASED + } else if (state->terminal_tombstone.valid != 1 || state->terminal_tombstone.requester_node < 0 + || state->terminal_tombstone.requester_node >= RESOURCE_X_PROTOCOL_NODE_LIMIT + || state->terminal_tombstone.request.phase != RESOURCE_X_MASTER_RELEASED || state->terminal_tombstone.request.resource_formation == 0 - || state->terminal_tombstone.request.resource_formation - == UINT64_MAX) { + || state->terminal_tombstone.request.resource_formation == UINT64_MAX) { *why = PCM_RETIRE_REFUSAL_SIDECAR_NOT_TERMINAL; return false; } @@ -2108,8 +1993,7 @@ pcm_entry_retire_eligible_locked(struct GrdEntry *entry, || state->holder_pair_drained_master_session == 0 || state->holder_pair_drained_master_session == UINT64_MAX || state->holder_pair_drained_master_node < 0 - || state->holder_pair_drained_master_node - >= RESOURCE_X_PROTOCOL_NODE_LIMIT + || state->holder_pair_drained_master_node >= RESOURCE_X_PROTOCOL_NODE_LIMIT || state->holder_pair_drained_reserved != 0) { *why = PCM_RETIRE_REFUSAL_SIDECAR_NOT_TERMINAL; return false; @@ -2121,22 +2005,18 @@ pcm_entry_retire_eligible_locked(struct GrdEntry *entry, *why = PCM_RETIRE_REFUSAL_SIDECAR_NOT_TERMINAL; return false; } - if (entry->resource_x_bootstrap_round.highest_attempt_floor - == UINT64_MAX) { + if (entry->resource_x_bootstrap_round.highest_attempt_floor == UINT64_MAX) { *why = PCM_RETIRE_REFUSAL_SIDECAR_NOT_TERMINAL; return false; } - if (entry->resource_x_local_owner.state - != RESOURCE_X_LOCAL_OWNER_EMPTY - || entry->resource_x_bootstrap_round.phase - != RESOURCE_X_BOOTSTRAP_ROUND_EMPTY) { + if (entry->resource_x_local_owner.state != RESOURCE_X_LOCAL_OWNER_EMPTY + || entry->resource_x_bootstrap_round.phase != RESOURCE_X_BOOTSTRAP_ROUND_EMPTY) { *why = PCM_RETIRE_REFUSAL_RESOURCE_X_ACTIVE; return false; } if (!pcm_resource_x_active_empty_locked(entry)) { - *why = pcm_resource_x_active_valid_locked(entry) - ? PCM_RETIRE_REFUSAL_REQUESTER_NOT_TERMINAL - : PCM_RETIRE_REFUSAL_SIDECAR_NOT_TERMINAL; + *why = pcm_resource_x_active_valid_locked(entry) ? PCM_RETIRE_REFUSAL_REQUESTER_NOT_TERMINAL + : PCM_RETIRE_REFUSAL_SIDECAR_NOT_TERMINAL; return false; } return true; @@ -2146,8 +2026,8 @@ pcm_entry_retire_eligible_locked(struct GrdEntry *entry, * try-retire path. It follows the frozen retire lock order and never waits * for entry_lock while holding the directory EXCLUSIVE lock. */ bool -pcm_entry_retire_classify_exact(const BufferTag *tag, - uint64 expected_generation, PcmRetireRefusal *why) +pcm_entry_retire_classify_exact(const BufferTag *tag, uint64 expected_generation, + PcmRetireRefusal *why) { struct GrdEntry *entry; bool eligible; @@ -2155,14 +2035,11 @@ pcm_entry_retire_classify_exact(const BufferTag *tag, if (why != NULL) *why = PCM_RETIRE_REFUSAL_IDENTITY_MISMATCH; - if (tag == NULL || why == NULL || ClusterPcm == NULL - || cluster_pcm_htab == NULL) + if (tag == NULL || why == NULL || ClusterPcm == NULL || cluster_pcm_htab == NULL) return false; LWLockAcquire(&ClusterPcm->htab_lock.lock, LW_EXCLUSIVE); - entry = (struct GrdEntry *)hash_search( - cluster_pcm_htab, tag, HASH_FIND, &found); - if (!found || entry == NULL - || !BufferTagsEqual(&entry->tag, tag) + entry = (struct GrdEntry *)hash_search(cluster_pcm_htab, tag, HASH_FIND, &found); + if (!found || entry == NULL || !BufferTagsEqual(&entry->tag, tag) || entry->binding_generation != expected_generation) { LWLockRelease(&ClusterPcm->htab_lock.lock); return false; @@ -2172,16 +2049,14 @@ pcm_entry_retire_classify_exact(const BufferTag *tag, LWLockRelease(&ClusterPcm->htab_lock.lock); return false; } - eligible = pcm_entry_retire_eligible_locked( - entry, expected_generation, why); + eligible = pcm_entry_retire_eligible_locked(entry, expected_generation, why); LWLockRelease(&entry->entry_lock.lock); LWLockRelease(&ClusterPcm->htab_lock.lock); return eligible; } bool -pcm_entry_try_retire_exact(const BufferTag *tag, - uint64 binding_generation, PcmRetireReason reason) +pcm_entry_try_retire_exact(const BufferTag *tag, uint64 binding_generation, PcmRetireReason reason) { ClusterPcmResourceXMasterState *state; ClusterPcmResourceXSlot *registry_slot; @@ -2195,17 +2070,14 @@ pcm_entry_try_retire_exact(const BufferTag *tag, bool found; bool removed; - if (tag == NULL || binding_generation == 0 - || binding_generation == UINT64_MAX - || reason < PCM_RETIRE_REASON_HOLDER_RELEASE - || reason > PCM_RETIRE_REASON_BOUNDED_RECLAIM + if (tag == NULL || binding_generation == 0 || binding_generation == UINT64_MAX + || reason < PCM_RETIRE_REASON_HOLDER_RELEASE || reason > PCM_RETIRE_REASON_BOUNDED_RECLAIM || ClusterPcm == NULL || cluster_pcm_htab == NULL) return false; pg_atomic_fetch_add_u64(&ClusterPcm->reclaim_attempt_count, 1); LWLockAcquire(&ClusterPcm->htab_lock.lock, LW_EXCLUSIVE); - entry = (struct GrdEntry *)hash_search( - cluster_pcm_htab, tag, HASH_FIND, &found); + entry = (struct GrdEntry *)hash_search(cluster_pcm_htab, tag, HASH_FIND, &found); if (!found || entry == NULL || !BufferTagsEqual(&entry->tag, tag) || entry->binding_generation != binding_generation) { pcm_entry_retire_refused_mark(PCM_RETIRE_REFUSAL_IDENTITY_MISMATCH); @@ -2228,8 +2100,7 @@ pcm_entry_try_retire_exact(const BufferTag *tag, LWLockRelease(&ClusterPcm->htab_lock.lock); return false; } - if (!LWLockConditionalAcquire( - &ClusterPcm->wm_prov_lock.lock, LW_EXCLUSIVE)) { + if (!LWLockConditionalAcquire(&ClusterPcm->wm_prov_lock.lock, LW_EXCLUSIVE)) { pcm_entry_retire_refused_mark(PCM_RETIRE_REFUSAL_ENTRY_LOCK_BUSY); LWLockRelease(&entry->entry_lock.lock); LWLockRelease(&ClusterPcm->htab_lock.lock); @@ -2239,17 +2110,13 @@ pcm_entry_try_retire_exact(const BufferTag *tag, registry_slot = &cluster_pcm_resource_x_slots[entry->registry_slot]; state = &cluster_pcm_resource_x_master_states[entry->registry_slot]; authority_generation = state->authority_generation; - retired_authority_floor = pg_atomic_read_u64( - &ClusterPcm->resource_x_retired_authority_floor); - live_slots = pg_atomic_read_u64( - &ClusterPcm->resource_x_reconfig_slot_count); + retired_authority_floor = pg_atomic_read_u64(&ClusterPcm->resource_x_retired_authority_floor); + live_slots = pg_atomic_read_u64(&ClusterPcm->resource_x_reconfig_slot_count); if (registry_slot->state != PCM_REGISTRY_LIVE || registry_slot->binding_generation != binding_generation || registry_slot->retired_authority_generation != 0 - || state->binding_generation != binding_generation - || authority_generation == 0 - || authority_generation == UINT64_MAX - || retired_authority_floor == UINT64_MAX + || state->binding_generation != binding_generation || authority_generation == 0 + || authority_generation == UINT64_MAX || retired_authority_floor == UINT64_MAX || live_slots == 0) { pcm_entry_retire_refused_mark(PCM_RETIRE_REFUSAL_IDENTITY_MISMATCH); pcm_resource_x_reconfig_block(); @@ -2258,10 +2125,8 @@ pcm_entry_try_retire_exact(const BufferTag *tag, LWLockRelease(&ClusterPcm->htab_lock.lock); return false; } - if (!pcm_wm_prov_validate_retire_exact_locked( - tag, binding_generation, &provenance_slot)) { - pcm_entry_retire_refused_mark( - PCM_RETIRE_REFUSAL_SIDECAR_NOT_TERMINAL); + if (!pcm_wm_prov_validate_retire_exact_locked(tag, binding_generation, &provenance_slot)) { + pcm_entry_retire_refused_mark(PCM_RETIRE_REFUSAL_SIDECAR_NOT_TERMINAL); pcm_resource_x_reconfig_block(); LWLockRelease(&ClusterPcm->wm_prov_lock.lock); LWLockRelease(&entry->entry_lock.lock); @@ -2269,8 +2134,7 @@ pcm_entry_try_retire_exact(const BufferTag *tag, return false; } if (!pcm_entry_lifecycle_mutation_mark()) { - pcm_entry_retire_refused_mark( - PCM_RETIRE_REFUSAL_SIDECAR_NOT_TERMINAL); + pcm_entry_retire_refused_mark(PCM_RETIRE_REFUSAL_SIDECAR_NOT_TERMINAL); LWLockRelease(&ClusterPcm->wm_prov_lock.lock); LWLockRelease(&entry->entry_lock.lock); LWLockRelease(&ClusterPcm->htab_lock.lock); @@ -2278,11 +2142,8 @@ pcm_entry_try_retire_exact(const BufferTag *tag, } pg_atomic_write_u32(&entry->lifecycle, PCM_ENTRY_RETIRING); - if (authority_generation > binding_generation - && authority_generation > retired_authority_floor) - pg_atomic_write_u64( - &ClusterPcm->resource_x_retired_authority_floor, - authority_generation); + if (authority_generation > binding_generation && authority_generation > retired_authority_floor) + pg_atomic_write_u64(&ClusterPcm->resource_x_retired_authority_floor, authority_generation); if (provenance_slot != NULL) { memset(provenance_slot, 0, sizeof(*provenance_slot)); provenance_slot->tag = *tag; @@ -2294,8 +2155,7 @@ pcm_entry_try_retire_exact(const BufferTag *tag, registry_slot->retired_authority_generation = authority_generation; pg_write_barrier(); registry_slot->state = PCM_REGISTRY_TOMBSTONE; - pg_atomic_fetch_sub_u64( - &ClusterPcm->resource_x_reconfig_slot_count, 1); + pg_atomic_fetch_sub_u64(&ClusterPcm->resource_x_reconfig_slot_count, 1); pg_atomic_fetch_add_u64(&ClusterPcm->reclaim_tombstone_count, 1); remove_tag = *tag; @@ -2303,8 +2163,7 @@ pcm_entry_try_retire_exact(const BufferTag *tag, /* The directory EXCLUSIVE lock excludes all new lookups after RETIRING; * release the embedded lock before dynahash invalidates its storage. */ LWLockRelease(&entry->entry_lock.lock); - (void)hash_search( - cluster_pcm_htab, &remove_tag, HASH_REMOVE, &removed); + (void)hash_search(cluster_pcm_htab, &remove_tag, HASH_REMOVE, &removed); if (!removed) { pcm_resource_x_reconfig_block(); LWLockRelease(&ClusterPcm->htab_lock.lock); @@ -2323,14 +2182,11 @@ cluster_pcm_lock_reclaim_bounded(uint32 probe_budget, PcmReclaimBatch *out) if (out != NULL) memset(out, 0, sizeof(*out)); - if (out == NULL || probe_budget == 0 - || probe_budget > PCM_GRD_LMON_RECLAIM_BUDGET - || ClusterPcm == NULL || cluster_pcm_htab == NULL - || cluster_pcm_resource_x_slots == NULL + if (out == NULL || probe_budget == 0 || probe_budget > PCM_GRD_LMON_RECLAIM_BUDGET + || ClusterPcm == NULL || cluster_pcm_htab == NULL || cluster_pcm_resource_x_slots == NULL || pcm_grd_effective <= 0) return false; - if (pg_atomic_read_u32(&ClusterPcm->resource_x_gate_phase) - != RESOURCE_X_GATE_OPEN) + if (pg_atomic_read_u32(&ClusterPcm->resource_x_gate_phase) != RESOURCE_X_GATE_OPEN) return false; capacity = (uint64)pcm_grd_effective; @@ -2344,27 +2200,21 @@ cluster_pcm_lock_reclaim_bounded(uint32 probe_budget, PcmReclaimBatch *out) uint64 binding_generation = 0; uint32 state; - if (pg_atomic_read_u32(&ClusterPcm->resource_x_gate_phase) - != RESOURCE_X_GATE_OPEN) + if (pg_atomic_read_u32(&ClusterPcm->resource_x_gate_phase) != RESOURCE_X_GATE_OPEN) break; LWLockAcquire(&ClusterPcm->htab_lock.lock, LW_SHARED); state = cluster_pcm_resource_x_slots[cursor].state; if (state == PCM_REGISTRY_LIVE) { tag = cluster_pcm_resource_x_slots[cursor].tag; - binding_generation - = cluster_pcm_resource_x_slots[cursor].binding_generation; - if (cluster_pcm_resource_x_slots[cursor].reserved != 0 - || binding_generation == 0 + binding_generation = cluster_pcm_resource_x_slots[cursor].binding_generation; + if (cluster_pcm_resource_x_slots[cursor].reserved != 0 || binding_generation == 0 || binding_generation == UINT64_MAX - || cluster_pcm_resource_x_slots[cursor] - .retired_authority_generation != 0) { + || cluster_pcm_resource_x_slots[cursor].retired_authority_generation != 0) { LWLockRelease(&ClusterPcm->htab_lock.lock); pcm_resource_x_reconfig_block(); return false; } - } - else if (state != PCM_REGISTRY_EMPTY - && state != PCM_REGISTRY_TOMBSTONE) { + } else if (state != PCM_REGISTRY_EMPTY && state != PCM_REGISTRY_TOMBSTONE) { LWLockRelease(&ClusterPcm->htab_lock.lock); pcm_resource_x_reconfig_block(); return false; @@ -2376,8 +2226,7 @@ cluster_pcm_lock_reclaim_bounded(uint32 probe_budget, PcmReclaimBatch *out) if (state != PCM_REGISTRY_LIVE) continue; out->attempted_count++; - if (pcm_entry_try_retire_exact(&tag, binding_generation, - PCM_RETIRE_REASON_BOUNDED_RECLAIM)) + if (pcm_entry_try_retire_exact(&tag, binding_generation, PCM_RETIRE_REASON_BOUNDED_RECLAIM)) out->retired_count++; } if (cursor == capacity) { @@ -2397,28 +2246,23 @@ cluster_pcm_lock_lmon_reclaim_tick(void) uint64 live_slots; if (ClusterPcm == NULL || pcm_grd_effective <= 0 - || pg_atomic_read_u32(&ClusterPcm->resource_x_gate_phase) - != RESOURCE_X_GATE_OPEN) + || pg_atomic_read_u32(&ClusterPcm->resource_x_gate_phase) != RESOURCE_X_GATE_OPEN) return; - live_slots = pg_atomic_read_u64( - &ClusterPcm->resource_x_reconfig_slot_count); + live_slots = pg_atomic_read_u64(&ClusterPcm->resource_x_reconfig_slot_count); if (live_slots * UINT64_C(100) - >= (uint64)pcm_grd_effective - * (uint64)PCM_GRD_RECLAIM_SOFT_PERCENT) + >= (uint64)pcm_grd_effective * (uint64)PCM_GRD_RECLAIM_SOFT_PERCENT) pcm_entry_reclaim_request(); if (pg_atomic_read_u32(&ClusterPcm->reclaim_requested) == 0) return; - (void)cluster_pcm_lock_reclaim_bounded( - PCM_GRD_LMON_RECLAIM_BUDGET, &batch); + (void)cluster_pcm_lock_reclaim_bounded(PCM_GRD_LMON_RECLAIM_BUDGET, &batch); } static bool -pcm_resource_x_reconfig_proof_slot_locked( - struct GrdEntry *entry, - const ClusterPcmResourceXMasterState *state, - const ResourceXReconfigToken *token, uint64 *digest_io, - uint64 *successor_count_io, uint64 *terminal_count_io, - bool *old_residual_out) +pcm_resource_x_reconfig_proof_slot_locked(struct GrdEntry *entry, + const ClusterPcmResourceXMasterState *state, + const ResourceXReconfigToken *token, uint64 *digest_io, + uint64 *successor_count_io, uint64 *terminal_count_io, + bool *old_residual_out) { static const ClusterPcmResourceXMasterRequest empty_request; static const ClusterPcmResourceXTerminalTombstone empty_tombstone; @@ -2445,12 +2289,10 @@ pcm_resource_x_reconfig_proof_slot_locked( if (!pcm_resource_x_active_empty_locked(entry)) { if (entry->resource_x_requester_node < 0 - || entry->resource_x_requester_node - >= RESOURCE_X_PROTOCOL_NODE_LIMIT + || entry->resource_x_requester_node >= RESOURCE_X_PROTOCOL_NODE_LIMIT || entry->resource_x_acquisition_generation == 0 || entry->resource_x_acquisition_generation == UINT64_MAX - || (entry->resource_x_progress_flags - & ~RESOURCE_X_PROGRESS_KNOWN_MASK) != 0 + || (entry->resource_x_progress_flags & ~RESOURCE_X_PROGRESS_KNOWN_MASK) != 0 || (entry->resource_x_formation != token->old_formation && entry->resource_x_formation != token->new_formation)) return false; @@ -2458,29 +2300,21 @@ pcm_resource_x_reconfig_proof_slot_locked( *old_residual_out = true; else (*successor_count_io)++; - digest = pcm_resource_x_proof_digest_u64( - digest, entry->resource_x_formation); - digest = pcm_resource_x_proof_digest_u64( - digest, entry->resource_x_acquisition_generation); - digest = pcm_resource_x_proof_digest_u64( - digest, (uint64)entry->resource_x_progress_flags); + digest = pcm_resource_x_proof_digest_u64(digest, entry->resource_x_formation); + digest = pcm_resource_x_proof_digest_u64(digest, entry->resource_x_acquisition_generation); + digest = pcm_resource_x_proof_digest_u64(digest, (uint64)entry->resource_x_progress_flags); } local_owner = &entry->resource_x_local_owner; if (!pcm_resource_x_local_owner_valid_locked(local_owner)) return false; if (local_owner->state != RESOURCE_X_LOCAL_OWNER_EMPTY) { if (local_owner->state == RESOURCE_X_LOCAL_OWNER_HANDOFF) { - if (!BufferTagsEqual( - &local_owner->handoff.successor_assertion.resource, - &entry->tag)) + if (!BufferTagsEqual(&local_owner->handoff.successor_assertion.resource, &entry->tag)) return false; local_owner_formation = local_owner->handoff.holder_ref.formation; local_owner_generation = local_owner->highest_owner_generation; - } - else { - if (!BufferTagsEqual( - &local_owner->handle.ref.assertion.resource, - &entry->tag)) + } else { + if (!BufferTagsEqual(&local_owner->handle.ref.assertion.resource, &entry->tag)) return false; local_owner_formation = local_owner->handle.ref.formation; local_owner_generation = local_owner->handle.owner_generation; @@ -2492,76 +2326,52 @@ pcm_resource_x_reconfig_proof_slot_locked( *old_residual_out = true; else (*successor_count_io)++; - digest = pcm_resource_x_proof_digest_u64( - digest, local_owner_formation); - digest = pcm_resource_x_proof_digest_u64( - digest, local_owner_generation); - digest = pcm_resource_x_proof_digest_u64( - digest, (uint64)local_owner->state); + digest = pcm_resource_x_proof_digest_u64(digest, local_owner_formation); + digest = pcm_resource_x_proof_digest_u64(digest, local_owner_generation); + digest = pcm_resource_x_proof_digest_u64(digest, (uint64)local_owner->state); } priority = &state->bootstrap_priority; if (!pcm_resource_x_bootstrap_priority_valid(priority)) return false; - digest = pcm_resource_x_proof_digest_u64( - digest, (uint64)priority->state); + digest = pcm_resource_x_proof_digest_u64(digest, (uint64)priority->state); if (priority->state == RESOURCE_X_BOOTSTRAP_PRIORITY_NEXT_ADMISSION) { - if (!BufferTagsEqual( - &priority->request.logical_assertion.resource, &entry->tag) - || (priority->request.resource_formation - != token->old_formation - && priority->request.resource_formation - != token->new_formation)) + if (!BufferTagsEqual(&priority->request.logical_assertion.resource, &entry->tag) + || (priority->request.resource_formation != token->old_formation + && priority->request.resource_formation != token->new_formation)) return false; if (priority->request.resource_formation == token->old_formation) *old_residual_out = true; + digest = pcm_resource_x_proof_digest_u64(digest, priority->request.resource_formation); + digest = pcm_resource_x_proof_digest_u64(digest, priority->request.assertion_sequence); digest = pcm_resource_x_proof_digest_u64( - digest, priority->request.resource_formation); - digest = pcm_resource_x_proof_digest_u64( - digest, priority->request.assertion_sequence); - digest = pcm_resource_x_proof_digest_u64( - digest, (uint64)(uint32) - priority->request.logical_assertion.requester_node); + digest, (uint64)(uint32)priority->request.logical_assertion.requester_node); + digest = pcm_resource_x_proof_digest_u64(digest, priority->r4_record_generation); digest = pcm_resource_x_proof_digest_u64( - digest, priority->r4_record_generation); - digest = pcm_resource_x_proof_digest_u64( - digest, - (uint64)priority->authenticated_ingress_connection_generation); + digest, (uint64)priority->authenticated_ingress_connection_generation); digest = pcm_resource_x_proof_digest_u64( digest, (uint64)priority->master_sender_connection_generation); - digest = pcm_resource_x_proof_digest_u64( - digest, (uint64)priority->request.semantic_crc32c); + digest = pcm_resource_x_proof_digest_u64(digest, (uint64)priority->request.semantic_crc32c); } - for (requester_node = 0; - requester_node < RESOURCE_X_PROTOCOL_NODE_LIMIT; - requester_node++) { + for (requester_node = 0; requester_node < RESOURCE_X_PROTOCOL_NODE_LIMIT; requester_node++) { const ClusterPcmResourceXBootstrapReceipt *receipt = &state->bootstrap_receipts[requester_node]; - const ClusterPcmResourceXMasterRequest *request - = &state->requests[requester_node]; + const ClusterPcmResourceXMasterRequest *request = &state->requests[requester_node]; if (!pcm_resource_x_bootstrap_receipt_valid(receipt)) return false; - digest = pcm_resource_x_proof_digest_u64( - digest, receipt->highest_attempt_floor); + digest = pcm_resource_x_proof_digest_u64(digest, receipt->highest_attempt_floor); if (receipt->state != RESOURCE_X_BOOTSTRAP_RECEIPT_EMPTY) { - if (receipt->request.logical_assertion.requester_node - != requester_node - || (receipt->request.resource_formation - != token->old_formation - && receipt->request.resource_formation - != token->new_formation)) + if (receipt->request.logical_assertion.requester_node != requester_node + || (receipt->request.resource_formation != token->old_formation + && receipt->request.resource_formation != token->new_formation)) return false; - if (receipt->request.resource_formation - == token->old_formation) + if (receipt->request.resource_formation == token->old_formation) *old_residual_out = true; - digest = pcm_resource_x_proof_digest_u64( - digest, receipt->request.resource_formation); - digest = pcm_resource_x_proof_digest_u64( - digest, receipt->request.assertion_sequence); - digest = pcm_resource_x_proof_digest_u64( - digest, (uint64)receipt->state); + digest = pcm_resource_x_proof_digest_u64(digest, receipt->request.resource_formation); + digest = pcm_resource_x_proof_digest_u64(digest, receipt->request.assertion_sequence); + digest = pcm_resource_x_proof_digest_u64(digest, (uint64)receipt->state); } if (request->phase == RESOURCE_X_MASTER_NONE) { @@ -2569,8 +2379,7 @@ pcm_resource_x_reconfig_proof_slot_locked( return false; continue; } - if (request->phase > RESOURCE_X_MASTER_RELEASED - || request->resource_formation == 0 + if (request->phase > RESOURCE_X_MASTER_RELEASED || request->resource_formation == 0 || request->resource_formation == UINT64_MAX || (request->resource_formation != token->old_formation && request->resource_formation != token->new_formation)) @@ -2580,20 +2389,14 @@ pcm_resource_x_reconfig_proof_slot_locked( *old_residual_out = true; else (*terminal_count_io)++; - } - else + } else (*successor_count_io)++; - digest = pcm_resource_x_proof_digest_u64( - digest, request->resource_formation); - digest = pcm_resource_x_proof_digest_u64( - digest, request->assertion_sequence); - digest = pcm_resource_x_proof_digest_u64( - digest, (uint64)request->phase); + digest = pcm_resource_x_proof_digest_u64(digest, request->resource_formation); + digest = pcm_resource_x_proof_digest_u64(digest, request->assertion_sequence); + digest = pcm_resource_x_proof_digest_u64(digest, (uint64)request->phase); } - for (holder_node = 0; - holder_node < RESOURCE_X_PROTOCOL_NODE_LIMIT; holder_node++) { - const ResourceXIntentSlot *intent - = &state->block_intents[holder_node].slot; + for (holder_node = 0; holder_node < RESOURCE_X_PROTOCOL_NODE_LIMIT; holder_node++) { + const ResourceXIntentSlot *intent = &state->block_intents[holder_node].slot; const ClusterPcmResourceXMasterRequest *owner; int32 owner_node; @@ -2602,10 +2405,8 @@ pcm_resource_x_reconfig_proof_slot_locked( owner_node = intent->body.assertion.requester_node; if ((intent->state != RESOURCE_X_INTENT_SLOT_ARMED && intent->state != RESOURCE_X_INTENT_SLOT_STAGED) - || intent->body.owner_kind - != RESOURCE_X_INTENT_OWNER_MASTER_BLOCK - || intent->body.owner_index != (uint8)holder_node - || owner_node < 0 + || intent->body.owner_kind != RESOURCE_X_INTENT_OWNER_MASTER_BLOCK + || intent->body.owner_index != (uint8)holder_node || owner_node < 0 || owner_node >= RESOURCE_X_PROTOCOL_NODE_LIMIT) return false; owner = &state->requests[owner_node]; @@ -2620,95 +2421,71 @@ pcm_resource_x_reconfig_proof_slot_locked( } if (state->terminal_tombstone.valid == 0) { - if (memcmp(&state->terminal_tombstone, &empty_tombstone, - sizeof(empty_tombstone)) != 0) + if (memcmp(&state->terminal_tombstone, &empty_tombstone, sizeof(empty_tombstone)) != 0) return false; - } - else { - const ClusterPcmResourceXTerminalTombstone *tombstone - = &state->terminal_tombstone; + } else { + const ClusterPcmResourceXTerminalTombstone *tombstone = &state->terminal_tombstone; if (tombstone->valid != 1 || tombstone->requester_node < 0 || tombstone->requester_node >= RESOURCE_X_PROTOCOL_NODE_LIMIT || (tombstone->request.phase != RESOURCE_X_MASTER_SETTLED && tombstone->request.phase != RESOURCE_X_MASTER_RELEASED) || (tombstone->request.resource_formation != token->old_formation - && tombstone->request.resource_formation - != token->new_formation)) + && tombstone->request.resource_formation != token->new_formation)) return false; if (tombstone->request.resource_formation == token->old_formation && tombstone->request.phase != RESOURCE_X_MASTER_RELEASED) *old_residual_out = true; else (*terminal_count_io)++; - digest = pcm_resource_x_proof_digest_u64( - digest, tombstone->request.resource_formation); - digest = pcm_resource_x_proof_digest_u64( - digest, tombstone->request.assertion_sequence); - digest = pcm_resource_x_proof_digest_u64( - digest, (uint64)tombstone->request.phase); + digest = pcm_resource_x_proof_digest_u64(digest, tombstone->request.resource_formation); + digest = pcm_resource_x_proof_digest_u64(digest, tombstone->request.assertion_sequence); + digest = pcm_resource_x_proof_digest_u64(digest, (uint64)tombstone->request.phase); } - if (!pcm_resource_x_source_settlement_debt_decode_locked( - entry, state, &source_settlement)) + if (!pcm_resource_x_source_settlement_debt_decode_locked(entry, state, &source_settlement)) return false; - digest = pcm_resource_x_proof_digest_u64( - digest, (uint64)state->source_settlement.state); - if (state->source_settlement.state - != RESOURCE_X_SOURCE_SETTLEMENT_NONE) { - if (source_settlement.common.resource_formation - != token->old_formation - && source_settlement.common.resource_formation - != token->new_formation) + digest = pcm_resource_x_proof_digest_u64(digest, (uint64)state->source_settlement.state); + if (state->source_settlement.state != RESOURCE_X_SOURCE_SETTLEMENT_NONE) { + if (source_settlement.common.resource_formation != token->old_formation + && source_settlement.common.resource_formation != token->new_formation) return false; - if (state->source_settlement.state - == RESOURCE_X_SOURCE_SETTLEMENT_PENDING) { - if (source_settlement.common.resource_formation - == token->old_formation) + if (state->source_settlement.state == RESOURCE_X_SOURCE_SETTLEMENT_PENDING) { + if (source_settlement.common.resource_formation == token->old_formation) *old_residual_out = true; else (*successor_count_io)++; - } - else if (state->source_settlement.state - == RESOURCE_X_SOURCE_SETTLEMENT_ACKED) + } else if (state->source_settlement.state == RESOURCE_X_SOURCE_SETTLEMENT_ACKED) (*terminal_count_io)++; + digest + = pcm_resource_x_proof_digest_u64(digest, source_settlement.common.resource_formation); + digest + = pcm_resource_x_proof_digest_u64(digest, source_settlement.common.assertion_sequence); + digest = pcm_resource_x_proof_digest_u64(digest, + source_settlement.common.authority_generation); digest = pcm_resource_x_proof_digest_u64( - digest, source_settlement.common.resource_formation); - digest = pcm_resource_x_proof_digest_u64( - digest, source_settlement.common.assertion_sequence); - digest = pcm_resource_x_proof_digest_u64( - digest, source_settlement.common.authority_generation); - digest = pcm_resource_x_proof_digest_u64( - digest, - source_settlement.body.blocked_to_n.source_carrier_generation); + digest, source_settlement.body.blocked_to_n.source_carrier_generation); } if (state->holder_status.valid != 0) { if ((state->holder_status.valid != RESOURCE_X_HOLDER_PAIR_PENDING - && state->holder_status.valid - != RESOURCE_X_HOLDER_PAIR_PUBLISHED) - || (state->holder_status.resource_formation - != token->old_formation - && state->holder_status.resource_formation - != token->new_formation)) + && state->holder_status.valid != RESOURCE_X_HOLDER_PAIR_PUBLISHED) + || (state->holder_status.resource_formation != token->old_formation + && state->holder_status.resource_formation != token->new_formation)) return false; if (state->holder_status.resource_formation == token->old_formation) *old_residual_out = true; else (*successor_count_io)++; } - if (state->holder_status_intent.slot.state - != RESOURCE_X_INTENT_SLOT_EMPTY + if (state->holder_status_intent.slot.state != RESOURCE_X_INTENT_SLOT_EMPTY && state->holder_status.valid == 0) return false; if (state->holder_image.valid != 0) { if ((state->holder_image.valid != RESOURCE_X_HOLDER_PAIR_PENDING - && state->holder_image.valid - != RESOURCE_X_HOLDER_PAIR_PUBLISHED) - || (state->holder_image.resource_formation - != token->old_formation - && state->holder_image.resource_formation - != token->new_formation)) + && state->holder_image.valid != RESOURCE_X_HOLDER_PAIR_PUBLISHED) + || (state->holder_image.resource_formation != token->old_formation + && state->holder_image.resource_formation != token->new_formation)) return false; if (state->holder_image.resource_formation == token->old_formation) *old_residual_out = true; @@ -2718,10 +2495,8 @@ pcm_resource_x_reconfig_proof_slot_locked( if (state->holder_image_intent.state != RESOURCE_X_INTENT_SLOT_EMPTY && state->holder_image.valid == 0) return false; - if (!pcm_resource_x_requester_join_empty_locked( - &state->requester_join)) { - if (!pcm_resource_x_requester_join_snapshot_locked( - &state->requester_join, &join) + if (!pcm_resource_x_requester_join_empty_locked(&state->requester_join)) { + if (!pcm_resource_x_requester_join_snapshot_locked(&state->requester_join, &join) || (join.resource_formation != token->old_formation && join.resource_formation != token->new_formation)) return false; @@ -2731,8 +2506,7 @@ pcm_resource_x_reconfig_proof_slot_locked( (*successor_count_io)++; } if (state->grant_intent.slot.state != RESOURCE_X_INTENT_SLOT_EMPTY - || state->requester_settlement_intent.slot.state - != RESOURCE_X_INTENT_SLOT_EMPTY) { + || state->requester_settlement_intent.slot.state != RESOURCE_X_INTENT_SLOT_EMPTY) { const ResourceXIntentSlot *intents[2]; int intent_index; @@ -2748,14 +2522,12 @@ pcm_resource_x_reconfig_proof_slot_locked( owner_node = intent->body.assertion.requester_node; if ((intent->state != RESOURCE_X_INTENT_SLOT_ARMED && intent->state != RESOURCE_X_INTENT_SLOT_STAGED) - || owner_node < 0 - || owner_node >= RESOURCE_X_PROTOCOL_NODE_LIMIT) + || owner_node < 0 || owner_node >= RESOURCE_X_PROTOCOL_NODE_LIMIT) return false; owner = &state->requests[owner_node]; if (owner->phase == RESOURCE_X_MASTER_NONE) { if (state->terminal_tombstone.valid != 1 - || state->terminal_tombstone.requester_node - != owner_node) + || state->terminal_tombstone.requester_node != owner_node) return false; owner = &state->terminal_tombstone.request; } @@ -2772,8 +2544,7 @@ pcm_resource_x_reconfig_proof_slot_locked( { bool drained = false; - for (holder_node = 0; - holder_node < RESOURCE_X_PROTOCOL_NODE_LIMIT; holder_node++) + for (holder_node = 0; holder_node < RESOURCE_X_PROTOCOL_NODE_LIMIT; holder_node++) if (state->holder_pair_drained_sequences[holder_node] != 0) { drained = true; (*terminal_count_io)++; @@ -2784,75 +2555,60 @@ pcm_resource_x_reconfig_proof_slot_locked( || state->holder_pair_drained_master_session == 0 || state->holder_pair_drained_master_session == UINT64_MAX || state->holder_pair_drained_master_node < 0 - || state->holder_pair_drained_master_node - >= RESOURCE_X_PROTOCOL_NODE_LIMIT + || state->holder_pair_drained_master_node >= RESOURCE_X_PROTOCOL_NODE_LIMIT || state->holder_pair_drained_reserved != 0) return false; - } - else if (state->holder_pair_drained_resource_formation != 0 - || state->holder_pair_drained_master_session != 0 - || state->holder_pair_drained_master_node != 0 - || state->holder_pair_drained_reserved != 0) + } else if (state->holder_pair_drained_resource_formation != 0 + || state->holder_pair_drained_master_session != 0 + || state->holder_pair_drained_master_node != 0 + || state->holder_pair_drained_reserved != 0) return false; } - digest = pcm_resource_x_proof_digest_u64( - digest, state->authority_generation); - digest = pcm_resource_x_proof_digest_u64( - digest, state->next_enqueue_order); + digest = pcm_resource_x_proof_digest_u64(digest, state->authority_generation); + digest = pcm_resource_x_proof_digest_u64(digest, state->next_enqueue_order); *digest_io = digest; return true; } static bool -pcm_resource_x_zero_proof_phase_exact( - const ResourceXReconfigToken *token, - const ResourceXZeroResidualProof *proof, uint32 expected_phase) -{ - return token != NULL && proof != NULL - && memcmp(&proof->token, token, sizeof(*token)) == 0 - && proof->proof_generation == token->freeze_generation - && proof->scan_begin_cursor == 0 - && proof->scan_end_cursor == proof->scan_capacity - && proof->scan_capacity - == pg_atomic_read_u64( - &ClusterPcm->resource_x_reconfig_scan_capacity) - && proof->scan_begin_slot_count == proof->scan_end_slot_count - && proof->scan_end_slot_count - == pg_atomic_read_u64( - &ClusterPcm->resource_x_reconfig_slot_count) - && proof->final_mutation_sequence - == pg_atomic_read_u64( - &ClusterPcm->resource_x_semantic_mutation_sequence) - && proof->full_wrap_digest != 0 && proof->complete_wrap == 1 - && proof->zero_residual == 1 - && memcmp(proof->creator_product_fingerprint, - pcm_resource_x_completion_product_fingerprint, - RESOURCE_X_COMPLETION_FINGERPRINT_BYTES) == 0 - && (expected_phase == RESOURCE_X_GATE_FROZEN - || expected_phase == RESOURCE_X_GATE_OPEN) - && pg_atomic_read_u32(&ClusterPcm->resource_x_gate_phase) - == expected_phase - && (expected_phase != RESOURCE_X_GATE_OPEN - || pg_atomic_read_u64(&ClusterPcm->resource_x_gate_formation) - == token->new_formation) - && pcm_resource_x_reconfig_token_exact(token) - && pg_atomic_read_u64( - &ClusterPcm->resource_x_activation_inflight_count) == 0; +pcm_resource_x_zero_proof_phase_exact(const ResourceXReconfigToken *token, + const ResourceXZeroResidualProof *proof, + uint32 expected_phase) +{ + return token != NULL && proof != NULL && memcmp(&proof->token, token, sizeof(*token)) == 0 + && proof->proof_generation == token->freeze_generation && proof->scan_begin_cursor == 0 + && proof->scan_end_cursor == proof->scan_capacity + && proof->scan_capacity + == pg_atomic_read_u64(&ClusterPcm->resource_x_reconfig_scan_capacity) + && proof->scan_begin_slot_count == proof->scan_end_slot_count + && proof->scan_end_slot_count + == pg_atomic_read_u64(&ClusterPcm->resource_x_reconfig_slot_count) + && proof->final_mutation_sequence + == pg_atomic_read_u64(&ClusterPcm->resource_x_semantic_mutation_sequence) + && proof->full_wrap_digest != 0 && proof->complete_wrap == 1 && proof->zero_residual == 1 + && memcmp(proof->creator_product_fingerprint, + pcm_resource_x_completion_product_fingerprint, + RESOURCE_X_COMPLETION_FINGERPRINT_BYTES) + == 0 + && (expected_phase == RESOURCE_X_GATE_FROZEN || expected_phase == RESOURCE_X_GATE_OPEN) + && pg_atomic_read_u32(&ClusterPcm->resource_x_gate_phase) == expected_phase + && (expected_phase != RESOURCE_X_GATE_OPEN + || pg_atomic_read_u64(&ClusterPcm->resource_x_gate_formation) + == token->new_formation) + && pcm_resource_x_reconfig_token_exact(token) + && pg_atomic_read_u64(&ClusterPcm->resource_x_activation_inflight_count) == 0; } static bool -pcm_resource_x_zero_proof_live_exact( - const ResourceXReconfigToken *token, - const ResourceXZeroResidualProof *proof) +pcm_resource_x_zero_proof_live_exact(const ResourceXReconfigToken *token, + const ResourceXZeroResidualProof *proof) { - return pcm_resource_x_zero_proof_phase_exact( - token, proof, RESOURCE_X_GATE_FROZEN); + return pcm_resource_x_zero_proof_phase_exact(token, proof, RESOURCE_X_GATE_FROZEN); } bool -cluster_resource_x_reconfig_freeze_pending_exact(uint64 old_formation, - uint32 dead_requester_bitmap, - ResourceXReconfigToken *out) +cluster_resource_x_reconfig_freeze_pending_exact(uint64 old_formation, uint32 dead_requester_bitmap, + ResourceXReconfigToken *out) { ResourceXReconfigToken live; uint64 current_generation; @@ -2869,21 +2625,17 @@ cluster_resource_x_reconfig_freeze_pending_exact(uint64 old_formation, return false; phase = pg_atomic_read_u32(&ClusterPcm->resource_x_gate_phase); - live.old_formation - = pg_atomic_read_u64(&ClusterPcm->resource_x_reconfig_old_formation); - live.new_formation - = pg_atomic_read_u64(&ClusterPcm->resource_x_reconfig_new_formation); - live.freeze_generation - = pg_atomic_read_u64(&ClusterPcm->resource_x_freeze_generation); - live.dead_requester_bitmap = pg_atomic_read_u32( - &ClusterPcm->resource_x_reconfig_dead_requester_bitmap); + live.old_formation = pg_atomic_read_u64(&ClusterPcm->resource_x_reconfig_old_formation); + live.new_formation = pg_atomic_read_u64(&ClusterPcm->resource_x_reconfig_new_formation); + live.freeze_generation = pg_atomic_read_u64(&ClusterPcm->resource_x_freeze_generation); + live.dead_requester_bitmap + = pg_atomic_read_u32(&ClusterPcm->resource_x_reconfig_dead_requester_bitmap); live.reserved = 0; if (phase == RESOURCE_X_GATE_FROZEN && live.old_formation == old_formation - && live.dead_requester_bitmap == dead_requester_bitmap - && live.freeze_generation != 0 && live.freeze_generation != UINT64_MAX + && live.dead_requester_bitmap == dead_requester_bitmap && live.freeze_generation != 0 + && live.freeze_generation != UINT64_MAX && (live.new_formation == 0 - || (live.new_formation != old_formation - && live.new_formation != UINT64_MAX))) { + || (live.new_formation != old_formation && live.new_formation != UINT64_MAX))) { *out = live; return true; } @@ -2903,7 +2655,7 @@ cluster_resource_x_reconfig_freeze_pending_exact(uint64 old_formation, } expected_phase = RESOURCE_X_GATE_OPEN; if (!pg_atomic_compare_exchange_u32(&ClusterPcm->resource_x_gate_phase, &expected_phase, - RESOURCE_X_GATE_FROZEN)) { + RESOURCE_X_GATE_FROZEN)) { pcm_resource_x_reconfig_block(); return false; } @@ -2914,24 +2666,17 @@ cluster_resource_x_reconfig_freeze_pending_exact(uint64 old_formation, dead_requester_bitmap); pg_atomic_write_u64(&ClusterPcm->resource_x_freeze_generation, next_generation); pg_atomic_write_u64(&ClusterPcm->resource_x_reconfig_next_state_index, 0); - pg_atomic_write_u64(&ClusterPcm->resource_x_reconfig_scan_capacity, - (uint64)pcm_grd_effective); + pg_atomic_write_u64(&ClusterPcm->resource_x_reconfig_scan_capacity, (uint64)pcm_grd_effective); pg_atomic_write_u64(&ClusterPcm->resource_x_reconfig_zero_proof_generation, 0); pg_atomic_write_u64(&ClusterPcm->resource_x_reconfig_residual_count, 0); pg_atomic_write_u32(&ClusterPcm->resource_x_reconfig_proof_pass, 0); - pg_atomic_write_u64( - &ClusterPcm->resource_x_reconfig_proof_begin_sequence, 0); - pg_atomic_write_u64( - &ClusterPcm->resource_x_reconfig_proof_begin_slot_count, 0); + pg_atomic_write_u64(&ClusterPcm->resource_x_reconfig_proof_begin_sequence, 0); + pg_atomic_write_u64(&ClusterPcm->resource_x_reconfig_proof_begin_slot_count, 0); pg_atomic_write_u64(&ClusterPcm->resource_x_reconfig_proof_digest, 0); - pg_atomic_write_u64( - &ClusterPcm->resource_x_reconfig_proof_empty_slot_count, 0); - pg_atomic_write_u64( - &ClusterPcm->resource_x_reconfig_proof_successor_slot_count, 0); - pg_atomic_write_u64( - &ClusterPcm->resource_x_reconfig_proof_terminal_slot_count, 0); - pg_atomic_write_u64( - &ClusterPcm->resource_x_reconfig_proof_retry_revisit_count, 0); + pg_atomic_write_u64(&ClusterPcm->resource_x_reconfig_proof_empty_slot_count, 0); + pg_atomic_write_u64(&ClusterPcm->resource_x_reconfig_proof_successor_slot_count, 0); + pg_atomic_write_u64(&ClusterPcm->resource_x_reconfig_proof_terminal_slot_count, 0); + pg_atomic_write_u64(&ClusterPcm->resource_x_reconfig_proof_retry_revisit_count, 0); memset(&ClusterPcm->resource_x_zero_residual_proof, 0, sizeof(ClusterPcm->resource_x_zero_residual_proof)); memset(&ClusterPcm->resource_x_clean_completion_proof, 0, @@ -2946,16 +2691,14 @@ cluster_resource_x_reconfig_freeze_pending_exact(uint64 old_formation, } bool -cluster_resource_x_reconfig_freeze_pending(uint64 old_formation, - ResourceXReconfigToken *out) +cluster_resource_x_reconfig_freeze_pending(uint64 old_formation, ResourceXReconfigToken *out) { - return cluster_resource_x_reconfig_freeze_pending_exact(old_formation, 0, - out); + return cluster_resource_x_reconfig_freeze_pending_exact(old_formation, 0, out); } bool cluster_resource_x_reconfig_bind_new_formation_exact(ResourceXReconfigToken *token, - uint64 new_formation) + uint64 new_formation) { uint64 expected_formation; @@ -2966,14 +2709,12 @@ cluster_resource_x_reconfig_bind_new_formation_exact(ResourceXReconfigToken *tok || pg_atomic_read_u32(&ClusterPcm->resource_x_gate_phase) != RESOURCE_X_GATE_FROZEN || pg_atomic_read_u64(&ClusterPcm->resource_x_reconfig_old_formation) != token->old_formation - || pg_atomic_read_u64(&ClusterPcm->resource_x_freeze_generation) - != token->freeze_generation + || pg_atomic_read_u64(&ClusterPcm->resource_x_freeze_generation) != token->freeze_generation || pg_atomic_read_u32(&ClusterPcm->resource_x_reconfig_dead_requester_bitmap) != token->dead_requester_bitmap) return false; - expected_formation - = pg_atomic_read_u64(&ClusterPcm->resource_x_reconfig_new_formation); + expected_formation = pg_atomic_read_u64(&ClusterPcm->resource_x_reconfig_new_formation); if ((token->new_formation == 0 || token->new_formation == new_formation) && expected_formation == new_formation) { token->new_formation = new_formation; @@ -2998,10 +2739,8 @@ cluster_resource_x_reconfig_bind_new_formation_exact(ResourceXReconfigToken *tok } bool -cluster_resource_x_reconfig_freeze_exact(uint64 old_formation, - uint64 new_formation, - uint32 dead_requester_bitmap, - ResourceXReconfigToken *out) +cluster_resource_x_reconfig_freeze_exact(uint64 old_formation, uint64 new_formation, + uint32 dead_requester_bitmap, ResourceXReconfigToken *out) { ResourceXReconfigToken live; uint32 phase; @@ -3015,14 +2754,11 @@ cluster_resource_x_reconfig_freeze_exact(uint64 old_formation, return false; phase = pg_atomic_read_u32(&ClusterPcm->resource_x_gate_phase); - live.old_formation - = pg_atomic_read_u64(&ClusterPcm->resource_x_reconfig_old_formation); - live.new_formation - = pg_atomic_read_u64(&ClusterPcm->resource_x_reconfig_new_formation); - live.freeze_generation - = pg_atomic_read_u64(&ClusterPcm->resource_x_freeze_generation); - live.dead_requester_bitmap = pg_atomic_read_u32( - &ClusterPcm->resource_x_reconfig_dead_requester_bitmap); + live.old_formation = pg_atomic_read_u64(&ClusterPcm->resource_x_reconfig_old_formation); + live.new_formation = pg_atomic_read_u64(&ClusterPcm->resource_x_reconfig_new_formation); + live.freeze_generation = pg_atomic_read_u64(&ClusterPcm->resource_x_freeze_generation); + live.dead_requester_bitmap + = pg_atomic_read_u32(&ClusterPcm->resource_x_reconfig_dead_requester_bitmap); live.reserved = 0; if (phase == RESOURCE_X_GATE_FROZEN && live.old_formation == old_formation && live.new_formation == new_formation && live.freeze_generation != 0 @@ -3036,8 +2772,8 @@ cluster_resource_x_reconfig_freeze_exact(uint64 old_formation, pcm_resource_x_reconfig_block(); return false; } - if (!cluster_resource_x_reconfig_freeze_pending_exact( - old_formation, dead_requester_bitmap, out)) + if (!cluster_resource_x_reconfig_freeze_pending_exact(old_formation, dead_requester_bitmap, + out)) return false; return cluster_resource_x_reconfig_bind_new_formation_exact(out, new_formation); } @@ -3046,13 +2782,11 @@ bool cluster_resource_x_reconfig_freeze(uint64 old_formation, uint64 new_formation, ResourceXReconfigToken *out) { - return cluster_resource_x_reconfig_freeze_exact(old_formation, new_formation, - 0, out); + return cluster_resource_x_reconfig_freeze_exact(old_formation, new_formation, 0, out); } bool -cluster_resource_x_reconfig_cutover_begin_native_exact( - ResourceXReconfigToken *out) +cluster_resource_x_reconfig_cutover_begin_native_exact(ResourceXReconfigToken *out) { ResourceXGateSnapshot gate; ResourceXApplyResult bind_result; @@ -3062,46 +2796,37 @@ cluster_resource_x_reconfig_cutover_begin_native_exact( memset(out, 0, sizeof(*out)); if (!cluster_pcm_lock_resource_x_gate_snapshot(&gate)) { if (!cluster_pcm_lock_resource_x_cutover_gate_snapshot_exact(&gate) - || gate.phase != RESOURCE_X_GATE_OPEN - || gate.formation != 0) + || gate.phase != RESOURCE_X_GATE_OPEN || gate.formation != 0) return false; bind_result = cluster_pcm_lock_resource_x_gate_bind_formation_exact( PGRAC_RESOURCE_X_NATIVE_INITIAL_FORMATION); - if (bind_result != RESOURCE_X_APPLY_APPLIED - && bind_result != RESOURCE_X_APPLY_DUPLICATE) + if (bind_result != RESOURCE_X_APPLY_APPLIED && bind_result != RESOURCE_X_APPLY_DUPLICATE) return false; if (!cluster_pcm_lock_resource_x_gate_snapshot(&gate)) return false; } - if ((gate.phase != RESOURCE_X_GATE_OPEN - && gate.phase != RESOURCE_X_GATE_FROZEN) - || gate.formation == 0 || gate.formation == UINT64_MAX - || gate.reserved != 0) + if ((gate.phase != RESOURCE_X_GATE_OPEN && gate.phase != RESOURCE_X_GATE_FROZEN) + || gate.formation == 0 || gate.formation == UINT64_MAX || gate.reserved != 0) return false; - return cluster_resource_x_reconfig_freeze_pending_exact( - gate.formation, 0, out); + return cluster_resource_x_reconfig_freeze_pending_exact(gate.formation, 0, out); } bool -cluster_resource_x_reconfig_cutover_bind_native_successor_exact( - ResourceXReconfigToken *token) +cluster_resource_x_reconfig_cutover_bind_native_successor_exact(ResourceXReconfigToken *token) { uint64 successor; - if (token == NULL || token->old_formation == 0 - || token->old_formation >= UINT64_MAX - 1) { + if (token == NULL || token->old_formation == 0 || token->old_formation >= UINT64_MAX - 1) { pcm_resource_x_reconfig_block(); return false; } successor = token->old_formation + 1; - return cluster_resource_x_reconfig_bind_new_formation_exact( - token, successor); + return cluster_resource_x_reconfig_bind_new_formation_exact(token, successor); } static ResourceXReconfigResult -pcm_resource_x_reconfig_proof_sweep( - const ResourceXReconfigToken *token, uint32 probe_budget, - ResourceXReconfigBatch *out, uint64 capacity, uint64 cursor) +pcm_resource_x_reconfig_proof_sweep(const ResourceXReconfigToken *token, uint32 probe_budget, + ResourceXReconfigBatch *out, uint64 capacity, uint64 cursor) { ResourceXZeroResidualProof proof; uint64 begin_sequence; @@ -3113,65 +2838,50 @@ pcm_resource_x_reconfig_proof_sweep( uint64 retry_count; uint32 probes = 0; - begin_sequence = pg_atomic_read_u64( - &ClusterPcm->resource_x_reconfig_proof_begin_sequence); - begin_slot_count = pg_atomic_read_u64( - &ClusterPcm->resource_x_reconfig_proof_begin_slot_count); - digest = pg_atomic_read_u64( - &ClusterPcm->resource_x_reconfig_proof_digest); - empty_count = pg_atomic_read_u64( - &ClusterPcm->resource_x_reconfig_proof_empty_slot_count); - successor_count = pg_atomic_read_u64( - &ClusterPcm->resource_x_reconfig_proof_successor_slot_count); - terminal_count = pg_atomic_read_u64( - &ClusterPcm->resource_x_reconfig_proof_terminal_slot_count); - retry_count = pg_atomic_read_u64( - &ClusterPcm->resource_x_reconfig_proof_retry_revisit_count); - if (begin_sequence == 0 || begin_sequence == UINT64_MAX - || digest == 0 - || begin_sequence != pg_atomic_read_u64( - &ClusterPcm->resource_x_semantic_mutation_sequence) - || begin_slot_count != pg_atomic_read_u64( - &ClusterPcm->resource_x_reconfig_slot_count)) + begin_sequence = pg_atomic_read_u64(&ClusterPcm->resource_x_reconfig_proof_begin_sequence); + begin_slot_count = pg_atomic_read_u64(&ClusterPcm->resource_x_reconfig_proof_begin_slot_count); + digest = pg_atomic_read_u64(&ClusterPcm->resource_x_reconfig_proof_digest); + empty_count = pg_atomic_read_u64(&ClusterPcm->resource_x_reconfig_proof_empty_slot_count); + successor_count + = pg_atomic_read_u64(&ClusterPcm->resource_x_reconfig_proof_successor_slot_count); + terminal_count = pg_atomic_read_u64(&ClusterPcm->resource_x_reconfig_proof_terminal_slot_count); + retry_count = pg_atomic_read_u64(&ClusterPcm->resource_x_reconfig_proof_retry_revisit_count); + if (begin_sequence == 0 || begin_sequence == UINT64_MAX || digest == 0 + || begin_sequence != pg_atomic_read_u64(&ClusterPcm->resource_x_semantic_mutation_sequence) + || begin_slot_count != pg_atomic_read_u64(&ClusterPcm->resource_x_reconfig_slot_count)) goto retry_from_zero; while (probes < probe_budget && cursor < capacity) { - ClusterPcmResourceXSlot *registry_slot - = &cluster_pcm_resource_x_slots[cursor]; + ClusterPcmResourceXSlot *registry_slot = &cluster_pcm_resource_x_slots[cursor]; digest = pcm_resource_x_proof_digest_u64(digest, cursor); if (registry_slot->state == PCM_REGISTRY_EMPTY || registry_slot->state == PCM_REGISTRY_TOMBSTONE) { digest = pcm_resource_x_proof_digest_u64(digest, 0); empty_count++; - } - else if (registry_slot->state != PCM_REGISTRY_LIVE) { + } else if (registry_slot->state != PCM_REGISTRY_LIVE) { pcm_resource_x_reconfig_block(); return RESOURCE_X_RECONFIG_CORRUPT; - } - else { + } else { ClusterPcmResourceXMasterState *state; PcmEntryRef entry_ref; PcmEntryAcquireResult acquire_result; struct GrdEntry *entry; bool old_residual = false; - if (!pcm_entry_ref_acquire(®istry_slot->tag, false, - &entry_ref, &acquire_result)) { + if (!pcm_entry_ref_acquire(®istry_slot->tag, false, &entry_ref, &acquire_result)) { pcm_resource_x_reconfig_block(); return RESOURCE_X_RECONFIG_CORRUPT; } entry = entry_ref.entry; LWLockAcquire(&entry->entry_lock.lock, LW_SHARED); state = pcm_resource_x_master_state_for_entry(entry); - if (state == NULL - || !BufferTagsEqual(&entry->tag, ®istry_slot->tag) - || entry_ref.binding_generation - != registry_slot->binding_generation + if (state == NULL || !BufferTagsEqual(&entry->tag, ®istry_slot->tag) + || entry_ref.binding_generation != registry_slot->binding_generation || entry_ref.registry_slot != (uint32)cursor - || !pcm_resource_x_reconfig_proof_slot_locked( - entry, state, token, &digest, &successor_count, - &terminal_count, &old_residual)) { + || !pcm_resource_x_reconfig_proof_slot_locked(entry, state, token, &digest, + &successor_count, &terminal_count, + &old_residual)) { LWLockRelease(&entry->entry_lock.lock); pcm_entry_ref_release(&entry_ref); pcm_resource_x_reconfig_block(); @@ -3183,11 +2893,8 @@ pcm_resource_x_reconfig_proof_sweep( out->orphan_count = 1; out->residual_count = 1; out->next_state_index = cursor; - pg_atomic_write_u64( - &ClusterPcm->resource_x_reconfig_residual_count, 1); - pg_atomic_write_u64( - &ClusterPcm->resource_x_reconfig_next_state_index, - cursor); + pg_atomic_write_u64(&ClusterPcm->resource_x_reconfig_residual_count, 1); + pg_atomic_write_u64(&ClusterPcm->resource_x_reconfig_next_state_index, cursor); pcm_resource_x_reconfig_block(); return RESOURCE_X_RECONFIG_ORPHAN; } @@ -3195,39 +2902,26 @@ pcm_resource_x_reconfig_proof_sweep( cursor++; probes++; out->examined_count++; - pg_atomic_fetch_add_u64( - &ClusterPcm->resource_x_reconfig_slot_examined_count, 1); - } - - pg_atomic_write_u64( - &ClusterPcm->resource_x_reconfig_proof_digest, digest); - pg_atomic_write_u64( - &ClusterPcm->resource_x_reconfig_proof_empty_slot_count, - empty_count); - pg_atomic_write_u64( - &ClusterPcm->resource_x_reconfig_proof_successor_slot_count, - successor_count); - pg_atomic_write_u64( - &ClusterPcm->resource_x_reconfig_proof_terminal_slot_count, - terminal_count); - pg_atomic_write_u64( - &ClusterPcm->resource_x_reconfig_next_state_index, cursor); + pg_atomic_fetch_add_u64(&ClusterPcm->resource_x_reconfig_slot_examined_count, 1); + } + + pg_atomic_write_u64(&ClusterPcm->resource_x_reconfig_proof_digest, digest); + pg_atomic_write_u64(&ClusterPcm->resource_x_reconfig_proof_empty_slot_count, empty_count); + pg_atomic_write_u64(&ClusterPcm->resource_x_reconfig_proof_successor_slot_count, + successor_count); + pg_atomic_write_u64(&ClusterPcm->resource_x_reconfig_proof_terminal_slot_count, terminal_count); + pg_atomic_write_u64(&ClusterPcm->resource_x_reconfig_next_state_index, cursor); out->next_state_index = cursor; if (cursor < capacity) return RESOURCE_X_RECONFIG_MORE; LWLockAcquire(&ClusterPcm->htab_lock.lock, LW_EXCLUSIVE); - if (pg_atomic_read_u32(&ClusterPcm->resource_x_gate_phase) - != RESOURCE_X_GATE_FROZEN + if (pg_atomic_read_u32(&ClusterPcm->resource_x_gate_phase) != RESOURCE_X_GATE_FROZEN || !pcm_resource_x_reconfig_token_exact(token) - || pg_atomic_read_u64( - &ClusterPcm->resource_x_activation_inflight_count) != 0 - || begin_sequence != pg_atomic_read_u64( - &ClusterPcm->resource_x_semantic_mutation_sequence) - || begin_slot_count != pg_atomic_read_u64( - &ClusterPcm->resource_x_reconfig_slot_count) - || capacity != pg_atomic_read_u64( - &ClusterPcm->resource_x_reconfig_scan_capacity)) { + || pg_atomic_read_u64(&ClusterPcm->resource_x_activation_inflight_count) != 0 + || begin_sequence != pg_atomic_read_u64(&ClusterPcm->resource_x_semantic_mutation_sequence) + || begin_slot_count != pg_atomic_read_u64(&ClusterPcm->resource_x_reconfig_slot_count) + || capacity != pg_atomic_read_u64(&ClusterPcm->resource_x_reconfig_scan_capacity)) { LWLockRelease(&ClusterPcm->htab_lock.lock); goto retry_from_zero; } @@ -3245,21 +2939,17 @@ pcm_resource_x_reconfig_proof_sweep( proof.successor_slot_count = successor_count; proof.terminal_slot_count = terminal_count; proof.retry_revisit_count = retry_count; - memcpy(proof.creator_product_fingerprint, - pcm_resource_x_completion_product_fingerprint, + memcpy(proof.creator_product_fingerprint, pcm_resource_x_completion_product_fingerprint, RESOURCE_X_COMPLETION_FINGERPRINT_BYTES); proof.complete_wrap = 1; proof.zero_residual = 1; ClusterPcm->resource_x_zero_residual_proof = proof; memset(&ClusterPcm->resource_x_clean_completion_proof, 0, sizeof(ClusterPcm->resource_x_clean_completion_proof)); - pg_atomic_write_u64( - &ClusterPcm->resource_x_reconfig_zero_proof_generation, - token->freeze_generation); - pg_atomic_write_u32( - &ClusterPcm->resource_x_reconfig_proof_pass, 2); - pg_atomic_write_u64( - &ClusterPcm->resource_x_reconfig_next_state_index, 0); + pg_atomic_write_u64(&ClusterPcm->resource_x_reconfig_zero_proof_generation, + token->freeze_generation); + pg_atomic_write_u32(&ClusterPcm->resource_x_reconfig_proof_pass, 2); + pg_atomic_write_u64(&ClusterPcm->resource_x_reconfig_next_state_index, 0); LWLockRelease(&ClusterPcm->htab_lock.lock); out->next_state_index = 0; out->complete_wrap = 1; @@ -3268,25 +2958,18 @@ pcm_resource_x_reconfig_proof_sweep( retry_from_zero: retry_count++; - pg_atomic_write_u64( - &ClusterPcm->resource_x_reconfig_proof_retry_revisit_count, - retry_count); - pg_atomic_write_u32( - &ClusterPcm->resource_x_reconfig_proof_pass, 0); - pg_atomic_write_u64( - &ClusterPcm->resource_x_reconfig_next_state_index, 0); - pg_atomic_write_u64( - &ClusterPcm->resource_x_reconfig_zero_proof_generation, 0); + pg_atomic_write_u64(&ClusterPcm->resource_x_reconfig_proof_retry_revisit_count, retry_count); + pg_atomic_write_u32(&ClusterPcm->resource_x_reconfig_proof_pass, 0); + pg_atomic_write_u64(&ClusterPcm->resource_x_reconfig_next_state_index, 0); + pg_atomic_write_u64(&ClusterPcm->resource_x_reconfig_zero_proof_generation, 0); out->retry_count = 1; out->next_state_index = 0; - pg_atomic_fetch_add_u64( - &ClusterPcm->resource_x_reconfig_retry_count, 1); + pg_atomic_fetch_add_u64(&ClusterPcm->resource_x_reconfig_retry_count, 1); return RESOURCE_X_RECONFIG_RETRY; } static ResourceXReconfigResult -pcm_resource_x_reconfig_return_release(PcmEntryRef *entry_ref, - ResourceXReconfigResult result) +pcm_resource_x_reconfig_return_release(PcmEntryRef *entry_ref, ResourceXReconfigResult result) { if (entry_ref != NULL && entry_ref->pinned) pcm_entry_ref_release(entry_ref); @@ -3340,32 +3023,25 @@ cluster_resource_x_reconfig_sweep(const ResourceXReconfigToken *token, uint32 pr return RESOURCE_X_RECONFIG_CORRUPT; memset(out, 0, sizeof(*out)); memset(&entry_ref, 0, sizeof(entry_ref)); - pending_token = ClusterPcm != NULL - && pcm_resource_x_reconfig_pending_token_exact(token); + pending_token = ClusterPcm != NULL && pcm_resource_x_reconfig_pending_token_exact(token); if (ClusterPcm == NULL || cluster_pcm_htab == NULL || probe_budget == 0 || probe_budget > 4 || pg_atomic_read_u32(&ClusterPcm->resource_x_gate_phase) != RESOURCE_X_GATE_FROZEN || (!pending_token && !pcm_resource_x_reconfig_token_exact(token)) - || (pending_token - && pg_atomic_read_u32( - &ClusterPcm->resource_x_reconfig_proof_pass) != 0)) - return pcm_resource_x_reconfig_return_release( - &entry_ref, RESOURCE_X_RECONFIG_CORRUPT); + || (pending_token && pg_atomic_read_u32(&ClusterPcm->resource_x_reconfig_proof_pass) != 0)) + return pcm_resource_x_reconfig_return_release(&entry_ref, RESOURCE_X_RECONFIG_CORRUPT); if (pg_atomic_read_u64(&ClusterPcm->resource_x_activation_inflight_count) != 0) - return pcm_resource_x_reconfig_return_release( - &entry_ref, RESOURCE_X_RECONFIG_MORE); + return pcm_resource_x_reconfig_return_release(&entry_ref, RESOURCE_X_RECONFIG_MORE); capacity = pg_atomic_read_u64(&ClusterPcm->resource_x_reconfig_scan_capacity); if (capacity > (uint64)pcm_grd_effective || cluster_pcm_resource_x_slots == NULL) { pcm_resource_x_reconfig_block(); - return pcm_resource_x_reconfig_return_release( - &entry_ref, RESOURCE_X_RECONFIG_CORRUPT); + return pcm_resource_x_reconfig_return_release(&entry_ref, RESOURCE_X_RECONFIG_CORRUPT); } cursor = pg_atomic_read_u64(&ClusterPcm->resource_x_reconfig_next_state_index); if (cursor > capacity) { pcm_resource_x_reconfig_block(); - return pcm_resource_x_reconfig_return_release( - &entry_ref, RESOURCE_X_RECONFIG_CORRUPT); + return pcm_resource_x_reconfig_return_release(&entry_ref, RESOURCE_X_RECONFIG_CORRUPT); } if (pg_atomic_read_u32(&ClusterPcm->resource_x_reconfig_proof_pass) == 2) { bool proof_valid; @@ -3375,20 +3051,17 @@ cluster_resource_x_reconfig_sweep(const ResourceXReconfigToken *token, uint32 pr token, &ClusterPcm->resource_x_zero_residual_proof); LWLockRelease(&ClusterPcm->htab_lock.lock); if (!proof_valid) - return pcm_resource_x_reconfig_return_release( - &entry_ref, RESOURCE_X_RECONFIG_RETRY); + return pcm_resource_x_reconfig_return_release(&entry_ref, RESOURCE_X_RECONFIG_RETRY); out->complete_wrap = 1; out->zero_residual = 1; return RESOURCE_X_RECONFIG_DONE; } if (pg_atomic_read_u32(&ClusterPcm->resource_x_reconfig_proof_pass) == 1) - return pcm_resource_x_reconfig_proof_sweep( - token, probe_budget, out, capacity, cursor); + return pcm_resource_x_reconfig_proof_sweep(token, probe_budget, out, capacity, cursor); probes = 0; while (probes < probe_budget && cursor < capacity) { slot = &cluster_pcm_resource_x_slots[cursor]; - if (slot->state == PCM_REGISTRY_EMPTY - || slot->state == PCM_REGISTRY_TOMBSTONE) { + if (slot->state == PCM_REGISTRY_EMPTY || slot->state == PCM_REGISTRY_TOMBSTONE) { cursor++; probes++; out->examined_count++; @@ -3397,16 +3070,13 @@ cluster_resource_x_reconfig_sweep(const ResourceXReconfigToken *token, uint32 pr } if (slot->state != PCM_REGISTRY_LIVE) { pcm_resource_x_reconfig_block(); - return pcm_resource_x_reconfig_return_release( - &entry_ref, RESOURCE_X_RECONFIG_CORRUPT); + return pcm_resource_x_reconfig_return_release(&entry_ref, RESOURCE_X_RECONFIG_CORRUPT); } Assert(!entry_ref.pinned); - if (!pcm_entry_ref_acquire(&slot->tag, false, - &entry_ref, &acquire_result)) { + if (!pcm_entry_ref_acquire(&slot->tag, false, &entry_ref, &acquire_result)) { pcm_resource_x_reconfig_block(); - return pcm_resource_x_reconfig_return_release( - &entry_ref, RESOURCE_X_RECONFIG_CORRUPT); + return pcm_resource_x_reconfig_return_release(&entry_ref, RESOURCE_X_RECONFIG_CORRUPT); } entry = entry_ref.entry; pcm_entry_lock_exclusive(entry); @@ -3415,8 +3085,7 @@ cluster_resource_x_reconfig_sweep(const ResourceXReconfigToken *token, uint32 pr || entry_ref.registry_slot != (uint32)cursor) { LWLockRelease(&entry->entry_lock.lock); pcm_resource_x_reconfig_block(); - return pcm_resource_x_reconfig_return_release( - &entry_ref, RESOURCE_X_RECONFIG_CORRUPT); + return pcm_resource_x_reconfig_return_release(&entry_ref, RESOURCE_X_RECONFIG_CORRUPT); } formation = entry->resource_x_formation; progress_flags = entry->resource_x_progress_flags; @@ -3434,56 +3103,42 @@ cluster_resource_x_reconfig_sweep(const ResourceXReconfigToken *token, uint32 pr if (master_state == NULL) { LWLockRelease(&entry->entry_lock.lock); pcm_resource_x_reconfig_block(); - return pcm_resource_x_reconfig_return_release( - &entry_ref, RESOURCE_X_RECONFIG_CORRUPT); + return pcm_resource_x_reconfig_return_release(&entry_ref, RESOURCE_X_RECONFIG_CORRUPT); } - if (!pcm_resource_x_source_settlement_debt_decode_locked( - entry, master_state, &source_settlement) - || (master_state->source_settlement.state - != RESOURCE_X_SOURCE_SETTLEMENT_NONE - && source_settlement.common.resource_formation - != token->old_formation + if (!pcm_resource_x_source_settlement_debt_decode_locked(entry, master_state, + &source_settlement) + || (master_state->source_settlement.state != RESOURCE_X_SOURCE_SETTLEMENT_NONE + && source_settlement.common.resource_formation != token->old_formation && (token->new_formation == 0 - || source_settlement.common.resource_formation - != token->new_formation))) { + || source_settlement.common.resource_formation != token->new_formation))) { LWLockRelease(&entry->entry_lock.lock); pcm_resource_x_reconfig_block(); - return pcm_resource_x_reconfig_return_release( - &entry_ref, RESOURCE_X_RECONFIG_CORRUPT); + return pcm_resource_x_reconfig_return_release(&entry_ref, RESOURCE_X_RECONFIG_CORRUPT); } /* PENDING remains the sole retry owner for a possibly still-REVOKING * source and therefore survives R8 as an old residual. Only an exact * kind-11 ACK makes the bounded history safe to discard. */ - if (master_state->source_settlement.state - == RESOURCE_X_SOURCE_SETTLEMENT_ACKED - && source_settlement.common.resource_formation - == token->old_formation) - memset(&master_state->source_settlement, 0, - sizeof(master_state->source_settlement)); + if (master_state->source_settlement.state == RESOURCE_X_SOURCE_SETTLEMENT_ACKED + && source_settlement.common.resource_formation == token->old_formation) + memset(&master_state->source_settlement, 0, sizeof(master_state->source_settlement)); bootstrap_priority_invalidated = false; - if (!pcm_resource_x_bootstrap_priority_valid( - &master_state->bootstrap_priority) - || (master_state->bootstrap_priority.state - != RESOURCE_X_BOOTSTRAP_PRIORITY_EMPTY + if (!pcm_resource_x_bootstrap_priority_valid(&master_state->bootstrap_priority) + || (master_state->bootstrap_priority.state != RESOURCE_X_BOOTSTRAP_PRIORITY_EMPTY && (!BufferTagsEqual( - &master_state->bootstrap_priority.request - .logical_assertion.resource, + &master_state->bootstrap_priority.request.logical_assertion.resource, &entry->tag) - || (master_state->bootstrap_priority.request - .resource_formation != token->old_formation - && master_state->bootstrap_priority.request - .resource_formation != token->new_formation)))) { + || (master_state->bootstrap_priority.request.resource_formation + != token->old_formation + && master_state->bootstrap_priority.request.resource_formation + != token->new_formation)))) { LWLockRelease(&entry->entry_lock.lock); pcm_resource_x_reconfig_block(); - return pcm_resource_x_reconfig_return_release( - &entry_ref, RESOURCE_X_RECONFIG_CORRUPT); + return pcm_resource_x_reconfig_return_release(&entry_ref, RESOURCE_X_RECONFIG_CORRUPT); } - if (master_state->bootstrap_priority.state - == RESOURCE_X_BOOTSTRAP_PRIORITY_NEXT_ADMISSION + if (master_state->bootstrap_priority.state == RESOURCE_X_BOOTSTRAP_PRIORITY_NEXT_ADMISSION && master_state->bootstrap_priority.request.resource_formation - == token->old_formation) { - pcm_resource_x_bootstrap_priority_clear( - &master_state->bootstrap_priority); + == token->old_formation) { + pcm_resource_x_bootstrap_priority_clear(&master_state->bootstrap_priority); bootstrap_priority_invalidated = true; } bootstrap_receipt_invalidated = false; @@ -3491,108 +3146,85 @@ cluster_resource_x_reconfig_sweep(const ResourceXReconfigToken *token, uint32 pr bootstrap_requester_node < RESOURCE_X_PROTOCOL_NODE_LIMIT; bootstrap_requester_node++) { ClusterPcmResourceXBootstrapReceipt *receipt - = &master_state->bootstrap_receipts[ - bootstrap_requester_node]; + = &master_state->bootstrap_receipts[bootstrap_requester_node]; if (!pcm_resource_x_bootstrap_receipt_valid(receipt) || (receipt->state != RESOURCE_X_BOOTSTRAP_RECEIPT_EMPTY && receipt->request.logical_assertion.requester_node - != bootstrap_requester_node) + != bootstrap_requester_node) || (receipt->state != RESOURCE_X_BOOTSTRAP_RECEIPT_EMPTY - && receipt->request.resource_formation - != token->old_formation - && receipt->request.resource_formation - != token->new_formation)) { + && receipt->request.resource_formation != token->old_formation + && receipt->request.resource_formation != token->new_formation)) { LWLockRelease(&entry->entry_lock.lock); pcm_resource_x_reconfig_block(); - return pcm_resource_x_reconfig_return_release( - &entry_ref, RESOURCE_X_RECONFIG_CORRUPT); + return pcm_resource_x_reconfig_return_release(&entry_ref, + RESOURCE_X_RECONFIG_CORRUPT); } if (receipt->state != RESOURCE_X_BOOTSTRAP_RECEIPT_EMPTY - && receipt->request.resource_formation - == token->old_formation) { + && receipt->request.resource_formation == token->old_formation) { pcm_resource_x_bootstrap_receipt_invalidate(receipt); bootstrap_receipt_invalidated = true; } } bootstrap_round_invalidated = false; - if (!pcm_resource_x_local_owner_valid_locked( - &entry->resource_x_local_owner)) { + if (!pcm_resource_x_local_owner_valid_locked(&entry->resource_x_local_owner)) { LWLockRelease(&entry->entry_lock.lock); pcm_resource_x_reconfig_block(); - return pcm_resource_x_reconfig_return_release( - &entry_ref, RESOURCE_X_RECONFIG_CORRUPT); + return pcm_resource_x_reconfig_return_release(&entry_ref, RESOURCE_X_RECONFIG_CORRUPT); } local_priority_cleared = pcm_resource_x_local_owner_expire_locked(entry, pcm_resource_x_monotonic_us()); - if ((entry->resource_x_local_owner.state - == RESOURCE_X_LOCAL_OWNER_RECYCLING - || entry->resource_x_local_owner.state - == RESOURCE_X_LOCAL_OWNER_HANDOFF) - && pcm_resource_x_local_handoff_valid( - &entry->resource_x_local_owner.handoff) - && entry->resource_x_local_owner.handoff.holder_ref.formation - == token->old_formation) + if ((entry->resource_x_local_owner.state == RESOURCE_X_LOCAL_OWNER_RECYCLING + || entry->resource_x_local_owner.state == RESOURCE_X_LOCAL_OWNER_HANDOFF) + && pcm_resource_x_local_handoff_valid(&entry->resource_x_local_owner.handoff) + && entry->resource_x_local_owner.handoff.holder_ref.formation == token->old_formation) local_priority_cleared = pcm_resource_x_local_owner_priority_clear_locked(entry) || local_priority_cleared; if (local_priority_cleared) ConditionVariableBroadcast(&entry->wait_cv); - if (entry->resource_x_local_owner.state - != RESOURCE_X_LOCAL_OWNER_EMPTY) { + if (entry->resource_x_local_owner.state != RESOURCE_X_LOCAL_OWNER_EMPTY) { LWLockRelease(&entry->entry_lock.lock); - return pcm_resource_x_reconfig_return_release( - &entry_ref, RESOURCE_X_RECONFIG_MORE); + return pcm_resource_x_reconfig_return_release(&entry_ref, RESOURCE_X_RECONFIG_MORE); } - if (entry->resource_x_bootstrap_round.phase - != RESOURCE_X_BOOTSTRAP_ROUND_EMPTY) { - ClusterPcmResourceXBootstrapRound *round - = &entry->resource_x_bootstrap_round; + if (entry->resource_x_bootstrap_round.phase != RESOURCE_X_BOOTSTRAP_ROUND_EMPTY) { + ClusterPcmResourceXBootstrapRound *round = &entry->resource_x_bootstrap_round; if (round->phase > RESOURCE_X_BOOTSTRAP_ROUND_FAILED_CLOSED - || !resource_x_assertion_valid( - &round->request.logical_assertion) - || !BufferTagsEqual( - &round->request.logical_assertion.resource, &entry->tag) - || round->request.logical_assertion.requester_node - != cluster_node_id + || !resource_x_assertion_valid(&round->request.logical_assertion) + || !BufferTagsEqual(&round->request.logical_assertion.resource, &entry->tag) + || round->request.logical_assertion.requester_node != cluster_node_id || round->request.assertion_sequence == 0 || round->request.assertion_sequence == UINT64_MAX - || round->request.assertion_sequence - != round->highest_attempt_floor - || round->resource_formation - != round->request.resource_formation + || round->request.assertion_sequence != round->highest_attempt_floor + || round->resource_formation != round->request.resource_formation || (round->resource_formation != token->old_formation && round->resource_formation != token->new_formation)) { LWLockRelease(&entry->entry_lock.lock); pcm_resource_x_reconfig_block(); - return pcm_resource_x_reconfig_return_release( - &entry_ref, RESOURCE_X_RECONFIG_CORRUPT); + return pcm_resource_x_reconfig_return_release(&entry_ref, + RESOURCE_X_RECONFIG_CORRUPT); } if (round->resource_formation == token->old_formation) { pcm_resource_x_bootstrap_round_clear_binding_locked(round); bootstrap_round_invalidated = true; } - } else if (entry->resource_x_bootstrap_round.highest_attempt_floor - == UINT64_MAX) { + } else if (entry->resource_x_bootstrap_round.highest_attempt_floor == UINT64_MAX) { LWLockRelease(&entry->entry_lock.lock); pcm_resource_x_reconfig_block(); - return pcm_resource_x_reconfig_return_release( - &entry_ref, RESOURCE_X_RECONFIG_CORRUPT); + return pcm_resource_x_reconfig_return_release(&entry_ref, RESOURCE_X_RECONFIG_CORRUPT); } - if (bootstrap_priority_invalidated - || bootstrap_receipt_invalidated + if (bootstrap_priority_invalidated || bootstrap_receipt_invalidated || bootstrap_round_invalidated) ConditionVariableBroadcast(&entry->wait_cv); - if (!pcm_resource_x_requester_join_empty_locked( - &master_state->requester_join)) { - if (!pcm_resource_x_requester_join_decode_locked( - &master_state->requester_join, &join_grant, &join_image) - || !pcm_resource_x_requester_join_snapshot_locked( - &master_state->requester_join, &join_snapshot)) { + if (!pcm_resource_x_requester_join_empty_locked(&master_state->requester_join)) { + if (!pcm_resource_x_requester_join_decode_locked(&master_state->requester_join, + &join_grant, &join_image) + || !pcm_resource_x_requester_join_snapshot_locked(&master_state->requester_join, + &join_snapshot)) { LWLockRelease(&entry->entry_lock.lock); pcm_resource_x_reconfig_block(); - return pcm_resource_x_reconfig_return_release( - &entry_ref, RESOURCE_X_RECONFIG_CORRUPT); + return pcm_resource_x_reconfig_return_release(&entry_ref, + RESOURCE_X_RECONFIG_CORRUPT); } if (pcm_resource_x_active_empty_locked(entry)) { LWLockRelease(&entry->entry_lock.lock); @@ -3601,29 +3233,25 @@ cluster_resource_x_reconfig_sweep(const ResourceXReconfigToken *token, uint32 pr out->orphan_count = 1; out->residual_count = 1; out->next_state_index = cursor; - pg_atomic_fetch_add_u64( - &ClusterPcm->resource_x_reconfig_slot_examined_count, 1); - pg_atomic_fetch_add_u64( - &ClusterPcm->resource_x_reconfig_orphan_count, 1); - pg_atomic_write_u64( - &ClusterPcm->resource_x_reconfig_residual_count, 1); - pg_atomic_write_u64( - &ClusterPcm->resource_x_reconfig_next_state_index, cursor); + pg_atomic_fetch_add_u64(&ClusterPcm->resource_x_reconfig_slot_examined_count, 1); + pg_atomic_fetch_add_u64(&ClusterPcm->resource_x_reconfig_orphan_count, 1); + pg_atomic_write_u64(&ClusterPcm->resource_x_reconfig_residual_count, 1); + pg_atomic_write_u64(&ClusterPcm->resource_x_reconfig_next_state_index, cursor); pcm_resource_x_reconfig_block(); - return pcm_resource_x_reconfig_return_release( - &entry_ref, RESOURCE_X_RECONFIG_ORPHAN); + return pcm_resource_x_reconfig_return_release(&entry_ref, + RESOURCE_X_RECONFIG_ORPHAN); } if (!resource_x_assertion_equal( &join_snapshot.assertion, &(ResourceXAssertion){ .resource = entry->tag, - .requester_node = entry->resource_x_requester_node }) + .requester_node = entry->resource_x_requester_node }) || join_snapshot.resource_formation != entry->resource_x_formation || join_snapshot.requester_target_generation != entry->resource_x_acquisition_generation) { LWLockRelease(&entry->entry_lock.lock); pcm_resource_x_reconfig_block(); - return pcm_resource_x_reconfig_return_release( - &entry_ref, RESOURCE_X_RECONFIG_CORRUPT); + return pcm_resource_x_reconfig_return_release(&entry_ref, + RESOURCE_X_RECONFIG_CORRUPT); } } /* A proof-bearing image makes this the inseparable retained carrier @@ -3635,98 +3263,78 @@ cluster_resource_x_reconfig_sweep(const ResourceXReconfigToken *token, uint32 pr int32 pair_requester_node; bool pair_exactly_drained; - if (pcm_resource_x_holder_pair_decode_locked( - master_state, &holder_pair_status, - &holder_pair_image) != RESOURCE_X_APPLY_APPLIED - || (holder_pair_status.common.resource_formation - != token->old_formation - && holder_pair_status.common.resource_formation - != token->new_formation)) { + if (pcm_resource_x_holder_pair_decode_locked(master_state, &holder_pair_status, + &holder_pair_image) + != RESOURCE_X_APPLY_APPLIED + || (holder_pair_status.common.resource_formation != token->old_formation + && holder_pair_status.common.resource_formation != token->new_formation)) { LWLockRelease(&entry->entry_lock.lock); pcm_resource_x_reconfig_block(); - return pcm_resource_x_reconfig_return_release( - &entry_ref, RESOURCE_X_RECONFIG_CORRUPT); + return pcm_resource_x_reconfig_return_release(&entry_ref, + RESOURCE_X_RECONFIG_CORRUPT); } - pair_requester_node - = holder_pair_status.common.logical_assertion.requester_node; + pair_requester_node = holder_pair_status.common.logical_assertion.requester_node; pair_exactly_drained - = master_state->holder_status.valid - == RESOURCE_X_HOLDER_PAIR_PUBLISHED - && master_state->holder_image.valid - == RESOURCE_X_HOLDER_PAIR_PUBLISHED - && master_state->holder_status_intent.slot.state - == RESOURCE_X_INTENT_SLOT_EMPTY - && master_state->holder_image_intent.state - == RESOURCE_X_INTENT_SLOT_EMPTY - && pair_requester_node >= 0 - && pair_requester_node < RESOURCE_X_PROTOCOL_NODE_LIMIT - && master_state->holder_pair_drained_sequences[ - pair_requester_node] - == holder_pair_status.common.assertion_sequence - && master_state->holder_pair_drained_resource_formation - == holder_pair_status.common.resource_formation - && master_state->holder_pair_drained_master_session - == holder_pair_status.common.master_session_incarnation - && master_state->holder_pair_drained_master_node - == (int32)master_state->holder_status.destination_node - && master_state->holder_pair_drained_reserved == 0; - if (holder_pair_status.common.resource_formation - == token->old_formation) { + = master_state->holder_status.valid == RESOURCE_X_HOLDER_PAIR_PUBLISHED + && master_state->holder_image.valid == RESOURCE_X_HOLDER_PAIR_PUBLISHED + && master_state->holder_status_intent.slot.state == RESOURCE_X_INTENT_SLOT_EMPTY + && master_state->holder_image_intent.state == RESOURCE_X_INTENT_SLOT_EMPTY + && pair_requester_node >= 0 + && pair_requester_node < RESOURCE_X_PROTOCOL_NODE_LIMIT + && master_state->holder_pair_drained_sequences[pair_requester_node] + == holder_pair_status.common.assertion_sequence + && master_state->holder_pair_drained_resource_formation + == holder_pair_status.common.resource_formation + && master_state->holder_pair_drained_master_session + == holder_pair_status.common.master_session_incarnation + && master_state->holder_pair_drained_master_node + == (int32)master_state->holder_status.destination_node + && master_state->holder_pair_drained_reserved == 0; + if (holder_pair_status.common.resource_formation == token->old_formation) { if (!pair_exactly_drained) holder_pair_old_unsettled = true; else { - memset(&master_state->holder_status, 0, - sizeof(master_state->holder_status)); + memset(&master_state->holder_status, 0, sizeof(master_state->holder_status)); memset(&master_state->holder_status_intent, 0, - sizeof(master_state->holder_status_intent)); - memset(&master_state->holder_image, 0, - sizeof(master_state->holder_image)); + sizeof(master_state->holder_status_intent)); + memset(&master_state->holder_image, 0, sizeof(master_state->holder_image)); memset(&master_state->holder_image_intent, 0, - sizeof(master_state->holder_image_intent)); + sizeof(master_state->holder_image_intent)); } } - } - else { - if (master_state->holder_image_intent.state - != RESOURCE_X_INTENT_SLOT_EMPTY + } else { + if (master_state->holder_image_intent.state != RESOURCE_X_INTENT_SLOT_EMPTY || (master_state->holder_status.valid == 0 && master_state->holder_status_intent.slot.state - != RESOURCE_X_INTENT_SLOT_EMPTY)) { + != RESOURCE_X_INTENT_SLOT_EMPTY)) { LWLockRelease(&entry->entry_lock.lock); pcm_resource_x_reconfig_block(); - return pcm_resource_x_reconfig_return_release( - &entry_ref, RESOURCE_X_RECONFIG_CORRUPT); + return pcm_resource_x_reconfig_return_release(&entry_ref, + RESOURCE_X_RECONFIG_CORRUPT); } if (master_state->holder_status.valid != 0) { - if ((master_state->holder_status.valid - != RESOURCE_X_HOLDER_PAIR_PENDING - && master_state->holder_status.valid - != RESOURCE_X_HOLDER_PAIR_PUBLISHED) + if ((master_state->holder_status.valid != RESOURCE_X_HOLDER_PAIR_PENDING + && master_state->holder_status.valid != RESOURCE_X_HOLDER_PAIR_PUBLISHED) || master_state->holder_status.resource_formation == 0 - || (master_state->holder_status.resource_formation - != token->old_formation + || (master_state->holder_status.resource_formation != token->old_formation && master_state->holder_status.resource_formation - != token->new_formation)) { + != token->new_formation)) { LWLockRelease(&entry->entry_lock.lock); pcm_resource_x_reconfig_block(); - return pcm_resource_x_reconfig_return_release( - &entry_ref, RESOURCE_X_RECONFIG_CORRUPT); + return pcm_resource_x_reconfig_return_release(&entry_ref, + RESOURCE_X_RECONFIG_CORRUPT); } - if (master_state->holder_status.resource_formation - == token->old_formation) { - memset(&master_state->holder_status, 0, - sizeof(master_state->holder_status)); + if (master_state->holder_status.resource_formation == token->old_formation) { + memset(&master_state->holder_status, 0, sizeof(master_state->holder_status)); memset(&master_state->holder_status_intent, 0, - sizeof(master_state->holder_status_intent)); + sizeof(master_state->holder_status_intent)); } } } holder_pair_drained = false; - for (holder_pair_node = 0; - holder_pair_node < RESOURCE_X_PROTOCOL_NODE_LIMIT; + for (holder_pair_node = 0; holder_pair_node < RESOURCE_X_PROTOCOL_NODE_LIMIT; holder_pair_node++) - if (master_state->holder_pair_drained_sequences[holder_pair_node] - != 0) { + if (master_state->holder_pair_drained_sequences[holder_pair_node] != 0) { holder_pair_drained = true; break; } @@ -3734,20 +3342,17 @@ cluster_resource_x_reconfig_sweep(const ResourceXReconfigToken *token, uint32 pr if (master_state->holder_pair_drained_resource_formation == 0 || master_state->holder_pair_drained_master_session == 0 || master_state->holder_pair_drained_master_node < 0 - || master_state->holder_pair_drained_master_node - >= RESOURCE_X_PROTOCOL_NODE_LIMIT + || master_state->holder_pair_drained_master_node >= RESOURCE_X_PROTOCOL_NODE_LIMIT || master_state->holder_pair_drained_reserved != 0 - || (master_state->holder_pair_drained_resource_formation - != token->old_formation + || (master_state->holder_pair_drained_resource_formation != token->old_formation && master_state->holder_pair_drained_resource_formation - != token->new_formation)) { + != token->new_formation)) { LWLockRelease(&entry->entry_lock.lock); pcm_resource_x_reconfig_block(); - return pcm_resource_x_reconfig_return_release( - &entry_ref, RESOURCE_X_RECONFIG_CORRUPT); + return pcm_resource_x_reconfig_return_release(&entry_ref, + RESOURCE_X_RECONFIG_CORRUPT); } - if (master_state->holder_pair_drained_resource_formation - == token->old_formation + if (master_state->holder_pair_drained_resource_formation == token->old_formation && !holder_pair_old_unsettled) { memset(master_state->holder_pair_drained_sequences, 0, sizeof(master_state->holder_pair_drained_sequences)); @@ -3762,11 +3367,9 @@ cluster_resource_x_reconfig_sweep(const ResourceXReconfigToken *token, uint32 pr || master_state->holder_pair_drained_reserved != 0) { LWLockRelease(&entry->entry_lock.lock); pcm_resource_x_reconfig_block(); - return pcm_resource_x_reconfig_return_release( - &entry_ref, RESOURCE_X_RECONFIG_CORRUPT); + return pcm_resource_x_reconfig_return_release(&entry_ref, RESOURCE_X_RECONFIG_CORRUPT); } - for (dead_node = 0; dead_node < RESOURCE_X_PROTOCOL_NODE_LIMIT; - dead_node++) { + for (dead_node = 0; dead_node < RESOURCE_X_PROTOCOL_NODE_LIMIT; dead_node++) { ResourceXReclaimResult reclaim_result; ResourceXReclaimWitness *witness; bool reclaim_broadcast = false; @@ -3776,92 +3379,79 @@ cluster_resource_x_reconfig_sweep(const ResourceXReconfigToken *token, uint32 pr if (out->reclaim_count >= RESOURCE_X_RECONFIG_RECLAIM_WITNESS_MAX) { LWLockRelease(&entry->entry_lock.lock); pcm_resource_x_reconfig_block(); - return pcm_resource_x_reconfig_return_release( - &entry_ref, RESOURCE_X_RECONFIG_CORRUPT); + return pcm_resource_x_reconfig_return_release(&entry_ref, + RESOURCE_X_RECONFIG_CORRUPT); } witness = &out->reclaim_witnesses[out->reclaim_count]; reclaim_result = pcm_resource_x_reclaim_requester_locked( - entry, master_state, dead_node, token->old_formation, witness, - &reclaim_broadcast); + entry, master_state, dead_node, token->old_formation, witness, &reclaim_broadcast); if (reclaim_result == RESOURCE_X_RECLAIM_NONE) continue; out->reclaim_count++; switch (reclaim_result) { - case RESOURCE_X_RECLAIM_NONHEAD: - out->reclaim_nonhead_count++; - out->old_detached_count++; - pg_atomic_fetch_add_u64( - &ClusterPcm->resource_x_reconfig_reclaim_nonhead_count, 1); - pg_atomic_fetch_add_u64( - &ClusterPcm->resource_x_reconfig_old_detached_count, 1); - break; - case RESOURCE_X_RECLAIM_HEAD_SUCCESSOR_STARTED: - out->reclaim_head_count++; - out->old_detached_count++; - pg_atomic_fetch_add_u64( - &ClusterPcm->resource_x_reconfig_reclaim_head_count, 1); - pg_atomic_fetch_add_u64( - &ClusterPcm->resource_x_reconfig_old_detached_count, 1); - break; - case RESOURCE_X_RECLAIM_ORPHAN_BLOCKED: - out->reclaim_orphan_count++; - pg_atomic_fetch_add_u64( - &ClusterPcm->resource_x_reconfig_reclaim_orphan_count, 1); - result = RESOURCE_X_RECONFIG_ORPHAN; - first_orphan = true; - break; - case RESOURCE_X_RECLAIM_NONE: - default: - LWLockRelease(&entry->entry_lock.lock); - pcm_resource_x_reconfig_block(); - return pcm_resource_x_reconfig_return_release( - &entry_ref, RESOURCE_X_RECONFIG_CORRUPT); + case RESOURCE_X_RECLAIM_NONHEAD: + out->reclaim_nonhead_count++; + out->old_detached_count++; + pg_atomic_fetch_add_u64(&ClusterPcm->resource_x_reconfig_reclaim_nonhead_count, 1); + pg_atomic_fetch_add_u64(&ClusterPcm->resource_x_reconfig_old_detached_count, 1); + break; + case RESOURCE_X_RECLAIM_HEAD_SUCCESSOR_STARTED: + out->reclaim_head_count++; + out->old_detached_count++; + pg_atomic_fetch_add_u64(&ClusterPcm->resource_x_reconfig_reclaim_head_count, 1); + pg_atomic_fetch_add_u64(&ClusterPcm->resource_x_reconfig_old_detached_count, 1); + break; + case RESOURCE_X_RECLAIM_ORPHAN_BLOCKED: + out->reclaim_orphan_count++; + pg_atomic_fetch_add_u64(&ClusterPcm->resource_x_reconfig_reclaim_orphan_count, 1); + result = RESOURCE_X_RECONFIG_ORPHAN; + first_orphan = true; + break; + case RESOURCE_X_RECLAIM_NONE: + default: + LWLockRelease(&entry->entry_lock.lock); + pcm_resource_x_reconfig_block(); + return pcm_resource_x_reconfig_return_release(&entry_ref, + RESOURCE_X_RECONFIG_CORRUPT); } if (reclaim_broadcast) ConditionVariableBroadcast(&entry->wait_cv); } - if (formation == token->old_formation - && entry->resource_x_acquisition_generation != 0) { + if (formation == token->old_formation && entry->resource_x_acquisition_generation != 0) { if (entry->resource_x_requester_node < 0 || (progress_flags & ~RESOURCE_X_PROGRESS_KNOWN_MASK) != 0) { LWLockRelease(&entry->entry_lock.lock); pcm_resource_x_reconfig_block(); - return pcm_resource_x_reconfig_return_release( - &entry_ref, RESOURCE_X_RECONFIG_CORRUPT); + return pcm_resource_x_reconfig_return_release(&entry_ref, + RESOURCE_X_RECONFIG_CORRUPT); } /* A T2/T3-gap sidecar belongs to the buffer owner. Snapshot the * complete Resource-X identity, drop this entry lock, and never * carry the shared entry pointer across that authority boundary. */ if (progress_flags - == (RESOURCE_X_PROGRESS_BOUND | RESOURCE_X_PROGRESS_T1 - | RESOURCE_X_PROGRESS_T2)) { + == (RESOURCE_X_PROGRESS_BOUND | RESOURCE_X_PROGRESS_T1 | RESOURCE_X_PROGRESS_T2)) { snapshot_tag = entry->tag; snapshot_requester_node = entry->resource_x_requester_node; - snapshot_acquisition_generation - = entry->resource_x_acquisition_generation; + snapshot_acquisition_generation = entry->resource_x_acquisition_generation; snapshot_progress_flags = progress_flags; - snapshot_no_progress_generation - = entry->resource_x_no_progress_generation; + snapshot_no_progress_generation = entry->resource_x_no_progress_generation; snapshot_no_progress_reason = entry->resource_x_no_progress_reason; snapshot_dispatch_phase = entry->resource_x_dispatch_phase; LWLockRelease(&entry->entry_lock.lock); entry = NULL; sidecar_result = cluster_bufmgr_resource_x_neutralize_exact( - &snapshot_tag, token->old_formation, - snapshot_acquisition_generation); + &snapshot_tag, token->old_formation, snapshot_acquisition_generation); entry = entry_ref.entry; pcm_entry_lock_exclusive(entry); if (!BufferTagsEqual(&entry->tag, &snapshot_tag) || entry->resource_x_requester_node != snapshot_requester_node || entry->resource_x_formation != token->old_formation - || entry->resource_x_acquisition_generation - != snapshot_acquisition_generation + || entry->resource_x_acquisition_generation != snapshot_acquisition_generation || entry->resource_x_progress_flags != snapshot_progress_flags - || entry->resource_x_no_progress_generation - != snapshot_no_progress_generation + || entry->resource_x_no_progress_generation != snapshot_no_progress_generation || entry->resource_x_no_progress_reason != snapshot_no_progress_reason || entry->resource_x_dispatch_phase != snapshot_dispatch_phase) { LWLockRelease(&entry->entry_lock.lock); @@ -3869,43 +3459,39 @@ cluster_resource_x_reconfig_sweep(const ResourceXReconfigToken *token, uint32 pr out->next_state_index = cursor; pg_atomic_fetch_add_u64(&ClusterPcm->resource_x_reconfig_retry_count, 1); pg_atomic_fetch_add_u64( - &ClusterPcm->resource_x_reconfig_proof_retry_revisit_count, - 1); - pg_atomic_write_u64(&ClusterPcm->resource_x_reconfig_next_state_index, - cursor); - return pcm_resource_x_reconfig_return_release( - &entry_ref, RESOURCE_X_RECONFIG_RETRY); + &ClusterPcm->resource_x_reconfig_proof_retry_revisit_count, 1); + pg_atomic_write_u64(&ClusterPcm->resource_x_reconfig_next_state_index, cursor); + return pcm_resource_x_reconfig_return_release(&entry_ref, + RESOURCE_X_RECONFIG_RETRY); } switch (sidecar_result) { - case RESOURCE_X_SIDECAR_NEUTRALIZED: - out->sidecar_neutralized_count++; - pg_atomic_fetch_add_u64( - &ClusterPcm->resource_x_reconfig_sidecar_neutralized_count, 1); - break; - case RESOURCE_X_SIDECAR_ALREADY_CLEAR: - break; - case RESOURCE_X_SIDECAR_SUCCESSOR: - case RESOURCE_X_SIDECAR_STALE: - pg_atomic_fetch_add_u64( - &ClusterPcm->resource_x_reconfig_sidecar_stale_count, 1); - break; - case RESOURCE_X_SIDECAR_BUSY: - break; - case RESOURCE_X_SIDECAR_CORRUPT: - default: - LWLockRelease(&entry->entry_lock.lock); - pcm_resource_x_reconfig_block(); - return pcm_resource_x_reconfig_return_release( - &entry_ref, RESOURCE_X_RECONFIG_CORRUPT); + case RESOURCE_X_SIDECAR_NEUTRALIZED: + out->sidecar_neutralized_count++; + pg_atomic_fetch_add_u64( + &ClusterPcm->resource_x_reconfig_sidecar_neutralized_count, 1); + break; + case RESOURCE_X_SIDECAR_ALREADY_CLEAR: + break; + case RESOURCE_X_SIDECAR_SUCCESSOR: + case RESOURCE_X_SIDECAR_STALE: + pg_atomic_fetch_add_u64(&ClusterPcm->resource_x_reconfig_sidecar_stale_count, + 1); + break; + case RESOURCE_X_SIDECAR_BUSY: + break; + case RESOURCE_X_SIDECAR_CORRUPT: + default: + LWLockRelease(&entry->entry_lock.lock); + pcm_resource_x_reconfig_block(); + return pcm_resource_x_reconfig_return_release(&entry_ref, + RESOURCE_X_RECONFIG_CORRUPT); } - } - else if (progress_flags - != (RESOURCE_X_PROGRESS_BOUND | RESOURCE_X_PROGRESS_T1)) { + } else if (progress_flags != (RESOURCE_X_PROGRESS_BOUND | RESOURCE_X_PROGRESS_T1)) { LWLockRelease(&entry->entry_lock.lock); pcm_resource_x_reconfig_block(); - return pcm_resource_x_reconfig_return_release( - &entry_ref, RESOURCE_X_RECONFIG_CORRUPT); + return pcm_resource_x_reconfig_return_release(&entry_ref, + RESOURCE_X_RECONFIG_CORRUPT); } if ((progress_flags & RESOURCE_X_PROGRESS_RECOVERY_BLOCKED) == 0) { @@ -3913,19 +3499,15 @@ cluster_resource_x_reconfig_sweep(const ResourceXReconfigToken *token, uint32 pr first_orphan = true; } result = RESOURCE_X_RECONFIG_ORPHAN; - } - else if (token->new_formation != 0 - && formation == token->new_formation - && entry->resource_x_acquisition_generation != 0) { + } else if (token->new_formation != 0 && formation == token->new_formation + && entry->resource_x_acquisition_generation != 0) { out->successor_count++; pg_atomic_fetch_add_u64(&ClusterPcm->resource_x_reconfig_successor_count, 1); - } - else if (formation != 0 || entry->resource_x_acquisition_generation != 0 - || entry->resource_x_requester_node != -1 || progress_flags != 0) { + } else if (formation != 0 || entry->resource_x_acquisition_generation != 0 + || entry->resource_x_requester_node != -1 || progress_flags != 0) { LWLockRelease(&entry->entry_lock.lock); pcm_resource_x_reconfig_block(); - return pcm_resource_x_reconfig_return_release( - &entry_ref, RESOURCE_X_RECONFIG_CORRUPT); + return pcm_resource_x_reconfig_return_release(&entry_ref, RESOURCE_X_RECONFIG_CORRUPT); } LWLockRelease(&entry->entry_lock.lock); pcm_entry_ref_release(&entry_ref); @@ -3953,52 +3535,41 @@ cluster_resource_x_reconfig_sweep(const ResourceXReconfigToken *token, uint32 pr if (cursor < capacity) { pg_atomic_write_u64(&ClusterPcm->resource_x_reconfig_next_state_index, cursor); out->next_state_index = cursor; - return pcm_resource_x_reconfig_return_release( - &entry_ref, RESOURCE_X_RECONFIG_MORE); + return pcm_resource_x_reconfig_return_release(&entry_ref, RESOURCE_X_RECONFIG_MORE); } if (pending_token) { /* This is the required pre-bind active/join sweep, not an R8 zero * proof. Binding the externally current formation mutates the * sequence, after which the ordinary two-pass proof sweep starts at * cursor zero and publishes the immutable same-token proof. */ - pg_atomic_write_u64( - &ClusterPcm->resource_x_reconfig_residual_count, 0); - pg_atomic_write_u64( - &ClusterPcm->resource_x_reconfig_next_state_index, 0); + pg_atomic_write_u64(&ClusterPcm->resource_x_reconfig_residual_count, 0); + pg_atomic_write_u64(&ClusterPcm->resource_x_reconfig_next_state_index, 0); out->next_state_index = 0; out->complete_wrap = 1; out->zero_residual = 0; return RESOURCE_X_RECONFIG_DONE; } - pg_atomic_write_u64( - &ClusterPcm->resource_x_reconfig_proof_begin_sequence, - pg_atomic_read_u64( - &ClusterPcm->resource_x_semantic_mutation_sequence)); - pg_atomic_write_u64( - &ClusterPcm->resource_x_reconfig_proof_begin_slot_count, - pg_atomic_read_u64(&ClusterPcm->resource_x_reconfig_slot_count)); + pg_atomic_write_u64(&ClusterPcm->resource_x_reconfig_proof_begin_sequence, + pg_atomic_read_u64(&ClusterPcm->resource_x_semantic_mutation_sequence)); + pg_atomic_write_u64(&ClusterPcm->resource_x_reconfig_proof_begin_slot_count, + pg_atomic_read_u64(&ClusterPcm->resource_x_reconfig_slot_count)); pg_atomic_write_u64(&ClusterPcm->resource_x_reconfig_proof_digest, - PGRAC_RESOURCE_X_PROOF_DIGEST_OFFSET); - pg_atomic_write_u64( - &ClusterPcm->resource_x_reconfig_proof_empty_slot_count, 0); - pg_atomic_write_u64( - &ClusterPcm->resource_x_reconfig_proof_successor_slot_count, 0); - pg_atomic_write_u64( - &ClusterPcm->resource_x_reconfig_proof_terminal_slot_count, 0); + PGRAC_RESOURCE_X_PROOF_DIGEST_OFFSET); + pg_atomic_write_u64(&ClusterPcm->resource_x_reconfig_proof_empty_slot_count, 0); + pg_atomic_write_u64(&ClusterPcm->resource_x_reconfig_proof_successor_slot_count, 0); + pg_atomic_write_u64(&ClusterPcm->resource_x_reconfig_proof_terminal_slot_count, 0); pg_atomic_write_u32(&ClusterPcm->resource_x_reconfig_proof_pass, 1); - pg_atomic_write_u64(&ClusterPcm->resource_x_reconfig_zero_proof_generation, - 0); + pg_atomic_write_u64(&ClusterPcm->resource_x_reconfig_zero_proof_generation, 0); pg_atomic_write_u64(&ClusterPcm->resource_x_reconfig_next_state_index, 0); out->complete_wrap = 1; out->zero_residual = 0; - return pcm_resource_x_reconfig_return_release( - &entry_ref, RESOURCE_X_RECONFIG_MORE); + return pcm_resource_x_reconfig_return_release(&entry_ref, RESOURCE_X_RECONFIG_MORE); } bool -cluster_resource_x_reconfig_zero_proof_exact( - const ResourceXReconfigToken *token, ResourceXZeroResidualProof *out) +cluster_resource_x_reconfig_zero_proof_exact(const ResourceXReconfigToken *token, + ResourceXZeroResidualProof *out) { bool valid; @@ -4007,8 +3578,8 @@ cluster_resource_x_reconfig_zero_proof_exact( if (ClusterPcm == NULL || token == NULL || out == NULL) return false; LWLockAcquire(&ClusterPcm->htab_lock.lock, LW_SHARED); - valid = pcm_resource_x_zero_proof_live_exact( - token, &ClusterPcm->resource_x_zero_residual_proof); + valid + = pcm_resource_x_zero_proof_live_exact(token, &ClusterPcm->resource_x_zero_residual_proof); if (valid) *out = ClusterPcm->resource_x_zero_residual_proof; LWLockRelease(&ClusterPcm->htab_lock.lock); @@ -4016,9 +3587,8 @@ cluster_resource_x_reconfig_zero_proof_exact( } static bool -pcm_resource_x_terminal_request_identity_valid( - const ClusterPcmResourceXMasterRequest *request, - bool allow_settled) +pcm_resource_x_terminal_request_identity_valid(const ClusterPcmResourceXMasterRequest *request, + bool allow_settled) { if (request == NULL || (request->phase != RESOURCE_X_MASTER_RELEASED @@ -4047,14 +3617,11 @@ pcm_resource_x_terminal_request_identity_valid( return false; if (request->proof_kind == RESOURCE_X_PROOF_REMOTE_CARRIER) return request->source_carrier_generation != 0 - && request->source_carrier_generation != UINT64_MAX - && request->source_disposition - == RESOURCE_X_DISPOSITION_REMOTE_NONWRITABLE; + && request->source_carrier_generation != UINT64_MAX + && request->source_disposition == RESOURCE_X_DISPOSITION_REMOTE_NONWRITABLE; if (request->proof_kind == RESOURCE_X_PROOF_LOCAL_IMAGE) - return request->source_disposition - == RESOURCE_X_DISPOSITION_LOCAL_IMAGE; - return request->source_disposition - == RESOURCE_X_DISPOSITION_DURABLE_STORAGE; + return request->source_disposition == RESOURCE_X_DISPOSITION_LOCAL_IMAGE; + return request->source_disposition == RESOURCE_X_DISPOSITION_DURABLE_STORAGE; } /* One complete terminal-sidecar validity table serves both the frozen R10 @@ -4062,12 +3629,11 @@ pcm_resource_x_terminal_request_identity_valid( * exact stable cached residency, but never relaxes active/retained/invalid * state. */ static bool -pcm_resource_x_terminal_state_locked( - struct GrdEntry *entry, - const ClusterPcmResourceXMasterState *state, - bool allow_stable_residency, bool allow_drained_pair_history, - bool durable_stop_cut, - uint64 *terminal_request_count_io, uint64 *digest_io) +pcm_resource_x_terminal_state_locked(struct GrdEntry *entry, + const ClusterPcmResourceXMasterState *state, + bool allow_stable_residency, bool allow_drained_pair_history, + bool durable_stop_cut, uint64 *terminal_request_count_io, + uint64 *digest_io) { static const ClusterPcmResourceXMasterRequest empty_request; static const ClusterPcmResourceXTerminalTombstone empty_tombstone; @@ -4086,40 +3652,35 @@ pcm_resource_x_terminal_state_locked( Assert(terminal_request_count_io != NULL); Assert(digest_io != NULL); Assert(LWLockHeldByMeInMode(&entry->entry_lock.lock, LW_SHARED) - || LWLockHeldByMeInMode(&entry->entry_lock.lock, LW_EXCLUSIVE)); + || LWLockHeldByMeInMode(&entry->entry_lock.lock, LW_EXCLUSIVE)); memset(&empty_round, 0, sizeof(empty_round)); - empty_round.highest_attempt_floor - = entry->resource_x_bootstrap_round.highest_attempt_floor; + empty_round.highest_attempt_floor = entry->resource_x_bootstrap_round.highest_attempt_floor; empty_round.failed_attempt_floor = entry->resource_x_bootstrap_round.failed_attempt_floor; empty_round.cancelled_attempt_floor = entry->resource_x_bootstrap_round.cancelled_attempt_floor; - if (entry->resource_x_bootstrap_round.phase - == RESOURCE_X_BOOTSTRAP_ROUND_EMPTY) { + if (entry->resource_x_bootstrap_round.phase == RESOURCE_X_BOOTSTRAP_ROUND_EMPTY) { if (empty_round.highest_attempt_floor == UINT64_MAX || empty_round.failed_attempt_floor > empty_round.highest_attempt_floor || empty_round.cancelled_attempt_floor > empty_round.highest_attempt_floor || memcmp(&entry->resource_x_bootstrap_round, &empty_round, sizeof(empty_round)) != 0) return false; - } - else if (allow_stable_residency - && entry->resource_x_bootstrap_round.phase - == RESOURCE_X_BOOTSTRAP_ROUND_TERMINAL_X_CACHED - && pcm_resource_x_bootstrap_round_terminal_cover_exact_locked( - entry, &entry->resource_x_bootstrap_round, - &entry->resource_x_bootstrap_round.terminal_ref, - entry->resource_x_bootstrap_round.master_session_incarnation, - entry->resource_x_bootstrap_round.r4_record_generation, - entry->resource_x_bootstrap_round.cached_ownership_generation)) + } else if (allow_stable_residency + && entry->resource_x_bootstrap_round.phase + == RESOURCE_X_BOOTSTRAP_ROUND_TERMINAL_X_CACHED + && pcm_resource_x_bootstrap_round_terminal_cover_exact_locked( + entry, &entry->resource_x_bootstrap_round, + &entry->resource_x_bootstrap_round.terminal_ref, + entry->resource_x_bootstrap_round.master_session_incarnation, + entry->resource_x_bootstrap_round.r4_record_generation, + entry->resource_x_bootstrap_round.cached_ownership_generation)) ; else return false; if (state->holder_status.valid != 0 || state->holder_image.valid != 0 - || state->holder_status_intent.slot.state - != RESOURCE_X_INTENT_SLOT_EMPTY - || state->holder_image_intent.state - != RESOURCE_X_INTENT_SLOT_EMPTY) { + || state->holder_status_intent.slot.state != RESOURCE_X_INTENT_SLOT_EMPTY + || state->holder_image_intent.state != RESOURCE_X_INTENT_SLOT_EMPTY) { if (!allow_drained_pair_history - || !pcm_resource_x_holder_pair_drained_history_locked( - entry, state, &drained_status, &drained_image)) + || !pcm_resource_x_holder_pair_drained_history_locked(entry, state, &drained_status, + &drained_image)) return false; drained_pair_history = true; } @@ -4133,10 +3694,8 @@ pcm_resource_x_terminal_state_locked( || !pcm_resource_x_bootstrap_priority_valid(&state->bootstrap_priority) || state->bootstrap_priority.state != RESOURCE_X_BOOTSTRAP_PRIORITY_EMPTY) return false; - if (!pcm_resource_x_source_settlement_debt_decode_locked( - entry, state, &source_settlement) - || state->source_settlement.state - == RESOURCE_X_SOURCE_SETTLEMENT_PENDING) + if (!pcm_resource_x_source_settlement_debt_decode_locked(entry, state, &source_settlement) + || state->source_settlement.state == RESOURCE_X_SOURCE_SETTLEMENT_PENDING) return false; digest = pcm_resource_x_proof_digest_tag(*digest_io, &entry->tag); @@ -4148,56 +3707,42 @@ pcm_resource_x_terminal_state_locked( digest, entry->resource_x_bootstrap_round.cancelled_attempt_floor); digest = pcm_resource_x_proof_digest_u64( digest, entry->resource_x_local_owner.highest_owner_generation); - digest = pcm_resource_x_proof_digest_u64( - digest, (uint64)state->source_settlement.state); + digest = pcm_resource_x_proof_digest_u64(digest, (uint64)state->source_settlement.state); if (drained_pair_history) { (*terminal_request_count_io)++; + digest = pcm_resource_x_proof_digest_u64(digest, drained_status.common.assertion_sequence); + digest = pcm_resource_x_proof_digest_u64(digest, drained_status.common.semantic_crc32c); + digest = pcm_resource_x_proof_digest_u64(digest, drained_image.common.semantic_crc32c); digest = pcm_resource_x_proof_digest_u64( - digest, drained_status.common.assertion_sequence); - digest = pcm_resource_x_proof_digest_u64( - digest, drained_status.common.semantic_crc32c); - digest = pcm_resource_x_proof_digest_u64( - digest, drained_image.common.semantic_crc32c); - digest = pcm_resource_x_proof_digest_u64( - digest, - drained_image.body.image_envelope.source_carrier_generation); + digest, drained_image.body.image_envelope.source_carrier_generation); } - if (state->source_settlement.state - == RESOURCE_X_SOURCE_SETTLEMENT_ACKED) { + if (state->source_settlement.state == RESOURCE_X_SOURCE_SETTLEMENT_ACKED) { (*terminal_request_count_io)++; + digest + = pcm_resource_x_proof_digest_u64(digest, source_settlement.common.resource_formation); + digest + = pcm_resource_x_proof_digest_u64(digest, source_settlement.common.assertion_sequence); + digest = pcm_resource_x_proof_digest_u64(digest, + source_settlement.common.authority_generation); digest = pcm_resource_x_proof_digest_u64( - digest, source_settlement.common.resource_formation); - digest = pcm_resource_x_proof_digest_u64( - digest, source_settlement.common.assertion_sequence); - digest = pcm_resource_x_proof_digest_u64( - digest, source_settlement.common.authority_generation); - digest = pcm_resource_x_proof_digest_u64( - digest, - source_settlement.body.blocked_to_n.source_carrier_generation); + digest, source_settlement.body.blocked_to_n.source_carrier_generation); } for (node = 0; node < RESOURCE_X_PROTOCOL_NODE_LIMIT; node++) { - const ClusterPcmResourceXBootstrapReceipt *receipt - = &state->bootstrap_receipts[node]; - const ClusterPcmResourceXMasterRequest *request - = &state->requests[node]; + const ClusterPcmResourceXBootstrapReceipt *receipt = &state->bootstrap_receipts[node]; + const ClusterPcmResourceXMasterRequest *request = &state->requests[node]; if (!pcm_resource_x_bootstrap_receipt_valid(receipt) || receipt->state != RESOURCE_X_BOOTSTRAP_RECEIPT_EMPTY) return false; - digest = pcm_resource_x_proof_digest_u64( - digest, receipt->highest_attempt_floor); - if (state->block_intents[node].slot.state - != RESOURCE_X_INTENT_SLOT_EMPTY) + digest = pcm_resource_x_proof_digest_u64(digest, receipt->highest_attempt_floor); + if (state->block_intents[node].slot.state != RESOURCE_X_INTENT_SLOT_EMPTY) return false; if (request->phase == RESOURCE_X_MASTER_NONE) { if (memcmp(request, &empty_request, sizeof(*request)) != 0) return false; - } - else if (request->phase == RESOURCE_X_MASTER_RELEASED - || (allow_stable_residency - && request->phase == RESOURCE_X_MASTER_SETTLED)) { - if (!pcm_resource_x_terminal_request_identity_valid( - request, allow_stable_residency)) + } else if (request->phase == RESOURCE_X_MASTER_RELEASED + || (allow_stable_residency && request->phase == RESOURCE_X_MASTER_SETTLED)) { + if (!pcm_resource_x_terminal_request_identity_valid(request, allow_stable_residency)) return false; if (request->phase == RESOURCE_X_MASTER_SETTLED) { if (settled_terminal_node != -1) @@ -4205,47 +3750,34 @@ pcm_resource_x_terminal_state_locked( settled_terminal_node = node; } (*terminal_request_count_io)++; - digest = pcm_resource_x_proof_digest_u64( - digest, request->resource_formation); - digest = pcm_resource_x_proof_digest_u64( - digest, request->assertion_sequence); - } - else + digest = pcm_resource_x_proof_digest_u64(digest, request->resource_formation); + digest = pcm_resource_x_proof_digest_u64(digest, request->assertion_sequence); + } else return false; if (state->holder_pair_drained_sequences[node] != 0) { drained = true; (*terminal_request_count_io)++; - digest = pcm_resource_x_proof_digest_u64( - digest, - state->holder_pair_drained_sequences[node]); + digest = pcm_resource_x_proof_digest_u64(digest, + state->holder_pair_drained_sequences[node]); } } if (state->terminal_tombstone.valid == 0) { - if (memcmp(&state->terminal_tombstone, &empty_tombstone, - sizeof(empty_tombstone)) != 0) + if (memcmp(&state->terminal_tombstone, &empty_tombstone, sizeof(empty_tombstone)) != 0) return false; - } - else if (state->terminal_tombstone.valid != 1 - || state->terminal_tombstone.requester_node < 0 - || state->terminal_tombstone.requester_node - >= RESOURCE_X_PROTOCOL_NODE_LIMIT - || !pcm_resource_x_terminal_request_identity_valid( - &state->terminal_tombstone.request, - allow_stable_residency)) { + } else if (state->terminal_tombstone.valid != 1 || state->terminal_tombstone.requester_node < 0 + || state->terminal_tombstone.requester_node >= RESOURCE_X_PROTOCOL_NODE_LIMIT + || !pcm_resource_x_terminal_request_identity_valid( + &state->terminal_tombstone.request, allow_stable_residency)) { return false; - } - else { - if (state->terminal_tombstone.request.phase - == RESOURCE_X_MASTER_SETTLED) { + } else { + if (state->terminal_tombstone.request.phase == RESOURCE_X_MASTER_SETTLED) { if (!allow_stable_residency || settled_terminal_node != -1) return false; - settled_terminal_node - = state->terminal_tombstone.requester_node; + settled_terminal_node = state->terminal_tombstone.requester_node; } (*terminal_request_count_io)++; digest = pcm_resource_x_proof_digest_u64( - digest, - state->terminal_tombstone.request.assertion_sequence); + digest, state->terminal_tombstone.request.assertion_sequence); } if (drained) { if (state->holder_pair_drained_resource_formation == 0 @@ -4253,111 +3785,94 @@ pcm_resource_x_terminal_state_locked( || state->holder_pair_drained_master_session == 0 || state->holder_pair_drained_master_session == UINT64_MAX || state->holder_pair_drained_master_node < 0 - || state->holder_pair_drained_master_node - >= RESOURCE_X_PROTOCOL_NODE_LIMIT + || state->holder_pair_drained_master_node >= RESOURCE_X_PROTOCOL_NODE_LIMIT || state->holder_pair_drained_reserved != 0) return false; - } - else if (state->holder_pair_drained_resource_formation != 0 - || state->holder_pair_drained_master_session != 0 - || state->holder_pair_drained_master_node != 0 - || state->holder_pair_drained_reserved != 0) + } else if (state->holder_pair_drained_resource_formation != 0 + || state->holder_pair_drained_master_session != 0 + || state->holder_pair_drained_master_node != 0 + || state->holder_pair_drained_reserved != 0) return false; if (settled_terminal_node != -1) { - uint32 settled_bit - = UINT32_C(1) << (uint32)settled_terminal_node; + uint32 settled_bit = UINT32_C(1) << (uint32)settled_terminal_node; uint32 s_holders = pg_atomic_read_u32(&entry->s_holders_bitmap); uint32 pi_holders = pg_atomic_read_u32(&entry->pi_holders_bitmap); - PcmState master_state - = (PcmState)pg_atomic_read_u32(&entry->master_state); + PcmState master_state = (PcmState)pg_atomic_read_u32(&entry->master_state); bool stable_cached; if (master_state == PCM_STATE_X) - stable_cached = entry->x_holder_node == settled_terminal_node - && s_holders == 0; + stable_cached = entry->x_holder_node == settled_terminal_node && s_holders == 0; else if (master_state == PCM_STATE_S) - stable_cached = entry->x_holder_node == -1 - && (s_holders & settled_bit) != 0; + stable_cached = entry->x_holder_node == -1 && (s_holders & settled_bit) != 0; else - stable_cached = master_state == PCM_STATE_N - && entry->x_holder_node == -1 && s_holders == 0 - && ((pi_holders & settled_bit) != 0 || durable_stop_cut); + stable_cached = master_state == PCM_STATE_N && entry->x_holder_node == -1 + && s_holders == 0 + && ((pi_holders & settled_bit) != 0 || durable_stop_cut); if (!stable_cached || entry->pending_x_requester_node != -1 || entry->pending_x_since_lsn != 0) return false; } - if (state->authority_generation == 0 - || state->authority_generation == UINT64_MAX - || state->next_enqueue_order == 0 - || state->next_enqueue_order == UINT64_MAX) + if (state->authority_generation == 0 || state->authority_generation == UINT64_MAX + || state->next_enqueue_order == 0 || state->next_enqueue_order == UINT64_MAX) return false; - digest = pcm_resource_x_proof_digest_u64( - digest, state->authority_generation); - digest = pcm_resource_x_proof_digest_u64( - digest, state->next_enqueue_order); + digest = pcm_resource_x_proof_digest_u64(digest, state->authority_generation); + digest = pcm_resource_x_proof_digest_u64(digest, state->next_enqueue_order); *digest_io = digest; return true; } static bool -pcm_resource_x_clean_state_locked( - struct GrdEntry *entry, - const ClusterPcmResourceXMasterState *state, - uint64 *terminal_request_count_io, uint64 *digest_io) +pcm_resource_x_clean_state_locked(struct GrdEntry *entry, + const ClusterPcmResourceXMasterState *state, + uint64 *terminal_request_count_io, uint64 *digest_io) { - return pcm_resource_x_terminal_state_locked( - entry, state, false, false, false, terminal_request_count_io, digest_io); + return pcm_resource_x_terminal_state_locked(entry, state, false, false, false, + terminal_request_count_io, digest_io); } static bool -pcm_resource_x_clean_proof_phase_exact( - const ResourceXReconfigToken *token, - const ResourceXZeroResidualProof *zero_proof, - const ResourceXCleanCompletionProof *clean_proof, uint32 expected_phase) +pcm_resource_x_clean_proof_phase_exact(const ResourceXReconfigToken *token, + const ResourceXZeroResidualProof *zero_proof, + const ResourceXCleanCompletionProof *clean_proof, + uint32 expected_phase) { return token != NULL && zero_proof != NULL && clean_proof != NULL - && pcm_resource_x_zero_proof_phase_exact( - token, zero_proof, expected_phase) - && memcmp(zero_proof, &ClusterPcm->resource_x_zero_residual_proof, - sizeof(*zero_proof)) == 0 - && memcmp(&clean_proof->token, token, sizeof(*token)) == 0 - && clean_proof->proof_generation == token->freeze_generation - && clean_proof->final_mutation_sequence - == zero_proof->final_mutation_sequence - && clean_proof->final_mutation_sequence - == pg_atomic_read_u64( - &ClusterPcm->resource_x_semantic_mutation_sequence) - && clean_proof->scan_capacity == zero_proof->scan_capacity - && clean_proof->logical_slot_count - == zero_proof->scan_end_slot_count - && clean_proof->logical_digest != 0 - && clean_proof->transport_mutation_sequence != 0 - && clean_proof->transport_mutation_sequence != UINT64_MAX - && clean_proof->transport_staged_count == 0 - && clean_proof->logical_debt_zero == 1 - && clean_proof->transport_debt_zero == 1 - && memcmp(clean_proof->creator_product_fingerprint, - pcm_resource_x_completion_product_fingerprint, - RESOURCE_X_COMPLETION_FINGERPRINT_BYTES) == 0 - && memcmp(clean_proof->send_c1_manifest_fingerprint, - pcm_resource_x_send_c1_manifest_fingerprint, - RESOURCE_X_COMPLETION_FINGERPRINT_BYTES) == 0; + && pcm_resource_x_zero_proof_phase_exact(token, zero_proof, expected_phase) + && memcmp(zero_proof, &ClusterPcm->resource_x_zero_residual_proof, sizeof(*zero_proof)) + == 0 + && memcmp(&clean_proof->token, token, sizeof(*token)) == 0 + && clean_proof->proof_generation == token->freeze_generation + && clean_proof->final_mutation_sequence == zero_proof->final_mutation_sequence + && clean_proof->final_mutation_sequence + == pg_atomic_read_u64(&ClusterPcm->resource_x_semantic_mutation_sequence) + && clean_proof->scan_capacity == zero_proof->scan_capacity + && clean_proof->logical_slot_count == zero_proof->scan_end_slot_count + && clean_proof->logical_digest != 0 && clean_proof->transport_mutation_sequence != 0 + && clean_proof->transport_mutation_sequence != UINT64_MAX + && clean_proof->transport_staged_count == 0 && clean_proof->logical_debt_zero == 1 + && clean_proof->transport_debt_zero == 1 + && memcmp(clean_proof->creator_product_fingerprint, + pcm_resource_x_completion_product_fingerprint, + RESOURCE_X_COMPLETION_FINGERPRINT_BYTES) + == 0 + && memcmp(clean_proof->send_c1_manifest_fingerprint, + pcm_resource_x_send_c1_manifest_fingerprint, + RESOURCE_X_COMPLETION_FINGERPRINT_BYTES) + == 0; } static bool -pcm_resource_x_clean_proof_live_exact( - const ResourceXReconfigToken *token, - const ResourceXZeroResidualProof *zero_proof, - const ResourceXCleanCompletionProof *clean_proof) +pcm_resource_x_clean_proof_live_exact(const ResourceXReconfigToken *token, + const ResourceXZeroResidualProof *zero_proof, + const ResourceXCleanCompletionProof *clean_proof) { - return pcm_resource_x_clean_proof_phase_exact( - token, zero_proof, clean_proof, RESOURCE_X_GATE_FROZEN); + return pcm_resource_x_clean_proof_phase_exact(token, zero_proof, clean_proof, + RESOURCE_X_GATE_FROZEN); } bool cluster_pcm_lock_resource_x_clean_completion_prove_exact( - const ResourceXReconfigToken *token, - const ResourceXZeroResidualProof *zero_proof, + const ResourceXReconfigToken *token, const ResourceXZeroResidualProof *zero_proof, ResourceXCleanCompletionProof *out) { ClusterLmsResourceXTransportSnapshot transport_begin; @@ -4372,34 +3887,29 @@ cluster_pcm_lock_resource_x_clean_completion_prove_exact( if (out != NULL) memset(out, 0, sizeof(*out)); - if (ClusterPcm == NULL || cluster_pcm_resource_x_slots == NULL - || token == NULL || zero_proof == NULL || out == NULL) + if (ClusterPcm == NULL || cluster_pcm_resource_x_slots == NULL || token == NULL + || zero_proof == NULL || out == NULL) return false; - begin_sequence = pg_atomic_read_u64( - &ClusterPcm->resource_x_semantic_mutation_sequence); + begin_sequence = pg_atomic_read_u64(&ClusterPcm->resource_x_semantic_mutation_sequence); if (begin_sequence == 0 || begin_sequence == UINT64_MAX || !pcm_resource_x_zero_proof_live_exact(token, zero_proof) - || memcmp(zero_proof, &ClusterPcm->resource_x_zero_residual_proof, - sizeof(*zero_proof)) != 0) + || memcmp(zero_proof, &ClusterPcm->resource_x_zero_residual_proof, sizeof(*zero_proof)) + != 0) return false; if (!cluster_lms_outbound_resource_x_transport_snapshot(&transport_begin) - || transport_begin.mutation_sequence == 0 - || transport_begin.mutation_sequence == UINT64_MAX + || transport_begin.mutation_sequence == 0 || transport_begin.mutation_sequence == UINT64_MAX || transport_begin.staged_count != 0) return false; - slot_count = pg_atomic_read_u64( - &ClusterPcm->resource_x_reconfig_slot_count); + slot_count = pg_atomic_read_u64(&ClusterPcm->resource_x_reconfig_slot_count); for (cursor = 0; cursor < zero_proof->scan_capacity; cursor++) { - ClusterPcmResourceXSlot *registry_slot - = &cluster_pcm_resource_x_slots[cursor]; + ClusterPcmResourceXSlot *registry_slot = &cluster_pcm_resource_x_slots[cursor]; digest = pcm_resource_x_proof_digest_u64(digest, cursor); if (registry_slot->state == PCM_REGISTRY_EMPTY || registry_slot->state == PCM_REGISTRY_TOMBSTONE) { digest = pcm_resource_x_proof_digest_u64(digest, 0); continue; - } - else if (registry_slot->state != PCM_REGISTRY_LIVE) + } else if (registry_slot->state != PCM_REGISTRY_LIVE) return false; else { ClusterPcmResourceXMasterState *state; @@ -4407,19 +3917,16 @@ cluster_pcm_lock_resource_x_clean_completion_prove_exact( PcmEntryAcquireResult acquire_result; struct GrdEntry *entry; - if (!pcm_entry_ref_acquire(®istry_slot->tag, false, - &entry_ref, &acquire_result)) + if (!pcm_entry_ref_acquire(®istry_slot->tag, false, &entry_ref, &acquire_result)) return false; entry = entry_ref.entry; LWLockAcquire(&entry->entry_lock.lock, LW_SHARED); state = pcm_resource_x_master_state_for_entry(entry); - if (state == NULL - || !BufferTagsEqual(&entry->tag, ®istry_slot->tag) - || entry_ref.binding_generation - != registry_slot->binding_generation + if (state == NULL || !BufferTagsEqual(&entry->tag, ®istry_slot->tag) + || entry_ref.binding_generation != registry_slot->binding_generation || entry_ref.registry_slot != (uint32)cursor - || !pcm_resource_x_clean_state_locked( - entry, state, &terminal_request_count, &digest)) { + || !pcm_resource_x_clean_state_locked(entry, state, &terminal_request_count, + &digest)) { LWLockRelease(&entry->entry_lock.lock); pcm_entry_ref_release(&entry_ref); return false; @@ -4430,12 +3937,9 @@ cluster_pcm_lock_resource_x_clean_completion_prove_exact( } if (!cluster_lms_outbound_resource_x_transport_snapshot(&transport_end) || transport_end.staged_count != 0 - || transport_end.mutation_sequence - != transport_begin.mutation_sequence - || begin_sequence != pg_atomic_read_u64( - &ClusterPcm->resource_x_semantic_mutation_sequence) - || slot_count != pg_atomic_read_u64( - &ClusterPcm->resource_x_reconfig_slot_count)) + || transport_end.mutation_sequence != transport_begin.mutation_sequence + || begin_sequence != pg_atomic_read_u64(&ClusterPcm->resource_x_semantic_mutation_sequence) + || slot_count != pg_atomic_read_u64(&ClusterPcm->resource_x_reconfig_slot_count)) return false; memset(&proof, 0, sizeof(proof)); @@ -4446,26 +3950,21 @@ cluster_pcm_lock_resource_x_clean_completion_prove_exact( proof.logical_slot_count = slot_count; proof.terminal_request_count = terminal_request_count; proof.logical_digest = digest; - proof.transport_mutation_sequence - = transport_begin.mutation_sequence; + proof.transport_mutation_sequence = transport_begin.mutation_sequence; proof.transport_staged_count = 0; - memcpy(proof.creator_product_fingerprint, - pcm_resource_x_completion_product_fingerprint, + memcpy(proof.creator_product_fingerprint, pcm_resource_x_completion_product_fingerprint, RESOURCE_X_COMPLETION_FINGERPRINT_BYTES); - memcpy(proof.send_c1_manifest_fingerprint, - pcm_resource_x_send_c1_manifest_fingerprint, + memcpy(proof.send_c1_manifest_fingerprint, pcm_resource_x_send_c1_manifest_fingerprint, RESOURCE_X_COMPLETION_FINGERPRINT_BYTES); proof.logical_debt_zero = 1; proof.transport_debt_zero = 1; LWLockAcquire(&ClusterPcm->htab_lock.lock, LW_EXCLUSIVE); - if (begin_sequence != pg_atomic_read_u64( - &ClusterPcm->resource_x_semantic_mutation_sequence) - || slot_count != pg_atomic_read_u64( - &ClusterPcm->resource_x_reconfig_slot_count) + if (begin_sequence != pg_atomic_read_u64(&ClusterPcm->resource_x_semantic_mutation_sequence) + || slot_count != pg_atomic_read_u64(&ClusterPcm->resource_x_reconfig_slot_count) || !pcm_resource_x_zero_proof_live_exact(token, zero_proof) - || memcmp(zero_proof, &ClusterPcm->resource_x_zero_residual_proof, - sizeof(*zero_proof)) != 0) { + || memcmp(zero_proof, &ClusterPcm->resource_x_zero_residual_proof, sizeof(*zero_proof)) + != 0) { LWLockRelease(&ClusterPcm->htab_lock.lock); return false; } @@ -4473,10 +3972,8 @@ cluster_pcm_lock_resource_x_clean_completion_prove_exact( LWLockRelease(&ClusterPcm->htab_lock.lock); if (!cluster_lms_outbound_resource_x_transport_snapshot(&transport_final) || transport_final.staged_count != 0 - || transport_final.mutation_sequence - != proof.transport_mutation_sequence - || begin_sequence != pg_atomic_read_u64( - &ClusterPcm->resource_x_semantic_mutation_sequence)) + || transport_final.mutation_sequence != proof.transport_mutation_sequence + || begin_sequence != pg_atomic_read_u64(&ClusterPcm->resource_x_semantic_mutation_sequence)) return false; *out = proof; return true; @@ -4484,8 +3981,7 @@ cluster_pcm_lock_resource_x_clean_completion_prove_exact( bool cluster_pcm_lock_resource_x_clean_completion_proof_exact( - const ResourceXReconfigToken *token, - const ResourceXZeroResidualProof *zero_proof, + const ResourceXReconfigToken *token, const ResourceXZeroResidualProof *zero_proof, ResourceXCleanCompletionProof *out) { ClusterLmsResourceXTransportSnapshot transport_begin; @@ -4495,34 +3991,28 @@ cluster_pcm_lock_resource_x_clean_completion_proof_exact( if (out != NULL) memset(out, 0, sizeof(*out)); - if (ClusterPcm == NULL || token == NULL || zero_proof == NULL - || out == NULL) + if (ClusterPcm == NULL || token == NULL || zero_proof == NULL || out == NULL) return false; if (!cluster_lms_outbound_resource_x_transport_snapshot(&transport_begin) || transport_begin.staged_count != 0) return false; LWLockAcquire(&ClusterPcm->htab_lock.lock, LW_SHARED); proof = ClusterPcm->resource_x_clean_completion_proof; - valid = pcm_resource_x_clean_proof_live_exact( - token, zero_proof, &proof); + valid = pcm_resource_x_clean_proof_live_exact(token, zero_proof, &proof); LWLockRelease(&ClusterPcm->htab_lock.lock); - valid = valid - && cluster_lms_outbound_resource_x_transport_snapshot(&transport_end) - && transport_end.staged_count == 0 - && transport_begin.mutation_sequence - == proof.transport_mutation_sequence - && transport_end.mutation_sequence - == proof.transport_mutation_sequence; + valid = valid && cluster_lms_outbound_resource_x_transport_snapshot(&transport_end) + && transport_end.staged_count == 0 + && transport_begin.mutation_sequence == proof.transport_mutation_sequence + && transport_end.mutation_sequence == proof.transport_mutation_sequence; if (valid) *out = proof; return valid; } bool -cluster_pcm_lock_resource_x_cutover_proofs_exact( - ResourceXReconfigToken *token_out, - ResourceXZeroResidualProof *zero_proof_out, - ResourceXCleanCompletionProof *clean_proof_out) +cluster_pcm_lock_resource_x_cutover_proofs_exact(ResourceXReconfigToken *token_out, + ResourceXZeroResidualProof *zero_proof_out, + ResourceXCleanCompletionProof *clean_proof_out) { ResourceXReconfigToken token; ResourceXZeroResidualProof zero_proof; @@ -4545,15 +4035,12 @@ cluster_pcm_lock_resource_x_cutover_proofs_exact( LWLockAcquire(&ClusterPcm->htab_lock.lock, LW_SHARED); token = ClusterPcm->resource_x_zero_residual_proof.token; LWLockRelease(&ClusterPcm->htab_lock.lock); - if (token.old_formation == 0 || token.old_formation == UINT64_MAX - || token.new_formation == 0 || token.new_formation == UINT64_MAX - || token.old_formation == token.new_formation - || token.freeze_generation == 0 - || token.freeze_generation == UINT64_MAX || token.reserved != 0 - || !cluster_resource_x_reconfig_zero_proof_exact( - &token, &zero_proof) - || !cluster_pcm_lock_resource_x_clean_completion_proof_exact( - &token, &zero_proof, &clean_proof)) + if (token.old_formation == 0 || token.old_formation == UINT64_MAX || token.new_formation == 0 + || token.new_formation == UINT64_MAX || token.old_formation == token.new_formation + || token.freeze_generation == 0 || token.freeze_generation == UINT64_MAX + || token.reserved != 0 || !cluster_resource_x_reconfig_zero_proof_exact(&token, &zero_proof) + || !cluster_pcm_lock_resource_x_clean_completion_proof_exact(&token, &zero_proof, + &clean_proof)) return false; *token_out = token; @@ -4564,8 +4051,7 @@ cluster_pcm_lock_resource_x_cutover_proofs_exact( bool cluster_pcm_lock_resource_x_cutover_thawed_proofs_exact( - ResourceXReconfigToken *token_out, - ResourceXZeroResidualProof *zero_proof_out, + ResourceXReconfigToken *token_out, ResourceXZeroResidualProof *zero_proof_out, ResourceXCleanCompletionProof *clean_proof_out) { ClusterLmsResourceXTransportSnapshot transport_begin; @@ -4581,10 +4067,8 @@ cluster_pcm_lock_resource_x_cutover_thawed_proofs_exact( memset(zero_proof_out, 0, sizeof(*zero_proof_out)); if (clean_proof_out != NULL) memset(clean_proof_out, 0, sizeof(*clean_proof_out)); - if (ClusterPcm == NULL || token_out == NULL || zero_proof_out == NULL - || clean_proof_out == NULL - || !cluster_lms_outbound_resource_x_transport_snapshot( - &transport_begin) + if (ClusterPcm == NULL || token_out == NULL || zero_proof_out == NULL || clean_proof_out == NULL + || !cluster_lms_outbound_resource_x_transport_snapshot(&transport_begin) || transport_begin.staged_count != 0) return false; @@ -4592,24 +4076,17 @@ cluster_pcm_lock_resource_x_cutover_thawed_proofs_exact( token = ClusterPcm->resource_x_zero_residual_proof.token; zero_proof = ClusterPcm->resource_x_zero_residual_proof; clean_proof = ClusterPcm->resource_x_clean_completion_proof; - valid = token.old_formation != 0 - && token.old_formation != UINT64_MAX - && token.new_formation != 0 - && token.new_formation != UINT64_MAX - && token.old_formation != token.new_formation - && token.freeze_generation != 0 - && token.freeze_generation != UINT64_MAX - && token.reserved == 0 - && pcm_resource_x_clean_proof_phase_exact( - &token, &zero_proof, &clean_proof, RESOURCE_X_GATE_OPEN); + valid = token.old_formation != 0 && token.old_formation != UINT64_MAX + && token.new_formation != 0 && token.new_formation != UINT64_MAX + && token.old_formation != token.new_formation && token.freeze_generation != 0 + && token.freeze_generation != UINT64_MAX && token.reserved == 0 + && pcm_resource_x_clean_proof_phase_exact(&token, &zero_proof, &clean_proof, + RESOURCE_X_GATE_OPEN); LWLockRelease(&ClusterPcm->htab_lock.lock); - valid = valid - && cluster_lms_outbound_resource_x_transport_snapshot(&transport_end) - && transport_end.staged_count == 0 - && transport_begin.mutation_sequence - == clean_proof.transport_mutation_sequence - && transport_end.mutation_sequence - == clean_proof.transport_mutation_sequence; + valid = valid && cluster_lms_outbound_resource_x_transport_snapshot(&transport_end) + && transport_end.staged_count == 0 + && transport_begin.mutation_sequence == clean_proof.transport_mutation_sequence + && transport_end.mutation_sequence == clean_proof.transport_mutation_sequence; if (!valid) return false; @@ -4620,8 +4097,9 @@ cluster_pcm_lock_resource_x_cutover_thawed_proofs_exact( } bool -cluster_pcm_lock_resource_x_cutover_current_proof_digest_exact( - bool thawed, ResourceXReconfigToken *token_out, uint64 *digest_out) +cluster_pcm_lock_resource_x_cutover_current_proof_digest_exact(bool thawed, + ResourceXReconfigToken *token_out, + uint64 *digest_out) { ResourceXCleanCompletionProof clean; ResourceXReconfigToken token; @@ -4633,44 +4111,29 @@ cluster_pcm_lock_resource_x_cutover_current_proof_digest_exact( memset(token_out, 0, sizeof(*token_out)); *digest_out = 0; if (thawed) { - if (!cluster_pcm_lock_resource_x_cutover_thawed_proofs_exact( - &token, &zero, &clean)) + if (!cluster_pcm_lock_resource_x_cutover_thawed_proofs_exact(&token, &zero, &clean)) return false; - } - else if (!cluster_pcm_lock_resource_x_cutover_proofs_exact( - &token, &zero, &clean)) + } else if (!cluster_pcm_lock_resource_x_cutover_proofs_exact(&token, &zero, &clean)) return false; - if (token.reserved != 0 - || memcmp(&zero.token, &token, sizeof(token)) != 0 + if (token.reserved != 0 || memcmp(&zero.token, &token, sizeof(token)) != 0 || memcmp(&clean.token, &token, sizeof(token)) != 0 || zero.proof_generation != token.freeze_generation - || clean.proof_generation != token.freeze_generation - || zero.complete_wrap != 1 || zero.zero_residual != 1 - || clean.logical_debt_zero != 1 - || clean.transport_debt_zero != 1 + || clean.proof_generation != token.freeze_generation || zero.complete_wrap != 1 + || zero.zero_residual != 1 || clean.logical_debt_zero != 1 || clean.transport_debt_zero != 1 || clean.transport_staged_count != 0 - || zero.final_mutation_sequence - != clean.final_mutation_sequence) + || zero.final_mutation_sequence != clean.final_mutation_sequence) return false; /* Fold only explicit, exact fields. The result is a local prerequisite * identity, never authority and never a wire value. */ - digest = pcm_resource_x_proof_digest_u64( - digest, token.old_formation); - digest = pcm_resource_x_proof_digest_u64( - digest, token.new_formation); - digest = pcm_resource_x_proof_digest_u64( - digest, token.freeze_generation); - digest = pcm_resource_x_proof_digest_u64( - digest, (uint64)token.dead_requester_bitmap); - digest = pcm_resource_x_proof_digest_u64( - digest, zero.full_wrap_digest); - digest = pcm_resource_x_proof_digest_u64( - digest, zero.final_mutation_sequence); - digest = pcm_resource_x_proof_digest_u64( - digest, clean.logical_digest); - digest = pcm_resource_x_proof_digest_u64( - digest, clean.transport_mutation_sequence); + digest = pcm_resource_x_proof_digest_u64(digest, token.old_formation); + digest = pcm_resource_x_proof_digest_u64(digest, token.new_formation); + digest = pcm_resource_x_proof_digest_u64(digest, token.freeze_generation); + digest = pcm_resource_x_proof_digest_u64(digest, (uint64)token.dead_requester_bitmap); + digest = pcm_resource_x_proof_digest_u64(digest, zero.full_wrap_digest); + digest = pcm_resource_x_proof_digest_u64(digest, zero.final_mutation_sequence); + digest = pcm_resource_x_proof_digest_u64(digest, clean.logical_digest); + digest = pcm_resource_x_proof_digest_u64(digest, clean.transport_mutation_sequence); if (digest == 0) digest = PGRAC_RESOURCE_X_PROOF_DIGEST_OFFSET; *token_out = token; @@ -4690,14 +4153,14 @@ cluster_resource_x_reconfig_thaw_exact(const ResourceXReconfigToken *token) || pg_atomic_read_u64(&ClusterPcm->resource_x_reconfig_residual_count) != 0 || pg_atomic_read_u64(&ClusterPcm->resource_x_reconfig_zero_proof_generation) != token->freeze_generation - || !pcm_resource_x_zero_proof_live_exact( - token, &ClusterPcm->resource_x_zero_residual_proof)) + || !pcm_resource_x_zero_proof_live_exact(token, + &ClusterPcm->resource_x_zero_residual_proof)) return false; pg_atomic_write_u64(&ClusterPcm->resource_x_gate_formation, token->new_formation); expected_phase = RESOURCE_X_GATE_FROZEN; if (!pg_atomic_compare_exchange_u32(&ClusterPcm->resource_x_gate_phase, &expected_phase, - RESOURCE_X_GATE_OPEN)) + RESOURCE_X_GATE_OPEN)) return false; pg_atomic_fetch_add_u64(&ClusterPcm->resource_x_reconfig_thaw_count, 1); return true; @@ -4725,12 +4188,12 @@ cluster_resource_x_reconfig_stats_snapshot(ResourceXReconfigStats *out) out->retry_count = pg_atomic_read_u64(&ClusterPcm->resource_x_reconfig_retry_count); out->blocked_count = pg_atomic_read_u64(&ClusterPcm->resource_x_reconfig_blocked_count); out->thaw_count = pg_atomic_read_u64(&ClusterPcm->resource_x_reconfig_thaw_count); - out->reclaim_nonhead_count = pg_atomic_read_u64( - &ClusterPcm->resource_x_reconfig_reclaim_nonhead_count); - out->reclaim_head_count = pg_atomic_read_u64( - &ClusterPcm->resource_x_reconfig_reclaim_head_count); - out->reclaim_orphan_count = pg_atomic_read_u64( - &ClusterPcm->resource_x_reconfig_reclaim_orphan_count); + out->reclaim_nonhead_count + = pg_atomic_read_u64(&ClusterPcm->resource_x_reconfig_reclaim_nonhead_count); + out->reclaim_head_count + = pg_atomic_read_u64(&ClusterPcm->resource_x_reconfig_reclaim_head_count); + out->reclaim_orphan_count + = pg_atomic_read_u64(&ClusterPcm->resource_x_reconfig_reclaim_orphan_count); } void @@ -4741,24 +4204,24 @@ cluster_pcm_lock_resource_x_o1_stats_snapshot(ResourceXO1Stats *out) memset(out, 0, sizeof(*out)); if (ClusterPcm == NULL) return; - out->remote_install_observed_count = pg_atomic_read_u64( - &ClusterPcm->resource_x_o1_remote_install_observed_count); - out->remote_grant_after_image_count = pg_atomic_read_u64( - &ClusterPcm->resource_x_o1_remote_grant_after_image_count); - out->remote_image_at_or_after_grant_count = pg_atomic_read_u64( - &ClusterPcm->resource_x_o1_remote_image_at_or_after_grant_count); - out->remote_episode_excluded_no_install = pg_atomic_read_u64( - &ClusterPcm->resource_x_o1_remote_episode_excluded_no_install); - out->remote_episode_excluded_missing_grant = pg_atomic_read_u64( - &ClusterPcm->resource_x_o1_remote_episode_excluded_missing_grant); - out->remote_episode_excluded_missing_image = pg_atomic_read_u64( - &ClusterPcm->resource_x_o1_remote_episode_excluded_missing_image); - out->last_remote_t_image_us = pg_atomic_read_u64( - &ClusterPcm->resource_x_o1_last_remote_t_image_us); - out->last_remote_t_grant_us = pg_atomic_read_u64( - &ClusterPcm->resource_x_o1_last_remote_t_grant_us); - out->last_remote_t_install_us = pg_atomic_read_u64( - &ClusterPcm->resource_x_o1_last_remote_t_install_us); + out->remote_install_observed_count + = pg_atomic_read_u64(&ClusterPcm->resource_x_o1_remote_install_observed_count); + out->remote_grant_after_image_count + = pg_atomic_read_u64(&ClusterPcm->resource_x_o1_remote_grant_after_image_count); + out->remote_image_at_or_after_grant_count + = pg_atomic_read_u64(&ClusterPcm->resource_x_o1_remote_image_at_or_after_grant_count); + out->remote_episode_excluded_no_install + = pg_atomic_read_u64(&ClusterPcm->resource_x_o1_remote_episode_excluded_no_install); + out->remote_episode_excluded_missing_grant + = pg_atomic_read_u64(&ClusterPcm->resource_x_o1_remote_episode_excluded_missing_grant); + out->remote_episode_excluded_missing_image + = pg_atomic_read_u64(&ClusterPcm->resource_x_o1_remote_episode_excluded_missing_image); + out->last_remote_t_image_us + = pg_atomic_read_u64(&ClusterPcm->resource_x_o1_last_remote_t_image_us); + out->last_remote_t_grant_us + = pg_atomic_read_u64(&ClusterPcm->resource_x_o1_last_remote_t_grant_us); + out->last_remote_t_install_us + = pg_atomic_read_u64(&ClusterPcm->resource_x_o1_last_remote_t_install_us); } static uint32 @@ -4814,8 +4277,9 @@ cluster_pcm_lock_resource_x_trace_seal(uint64 epoch) && trace->state == RESOURCE_X_TRACE_RECORDING) { pg_atomic_write_u64(&ClusterPcm->trace_active_epoch, 0); trace->state = RESOURCE_X_TRACE_SEALED; - trace->sealed_us = trace->count == 0 ? now_us - : Max(now_us, pcm_rx_trace_events[trace->count - 1].time_us); + trace->sealed_us = trace->count == 0 + ? now_us + : Max(now_us, pcm_rx_trace_events[trace->count - 1].time_us); accepted = true; } SpinLockRelease(&ClusterPcm->trace_lock); @@ -4837,8 +4301,8 @@ cluster_pcm_lock_resource_x_trace_snapshot(ResourceXTraceStats *out) } uint32 -cluster_pcm_lock_resource_x_trace_read(uint64 epoch, uint64 first, - ResourceXTraceEvent *out, uint32 limit) +cluster_pcm_lock_resource_x_trace_read(uint64 epoch, uint64 first, ResourceXTraceEvent *out, + uint32 limit) { ResourceXTraceStats *trace; uint32 copied = 0; @@ -4909,10 +4373,9 @@ cluster_pcm_lock_resource_x_trace_note(const ResourceXTraceEvent *event) } void -cluster_pcm_lock_resource_x_trace_ref(uint16 kind, - const ResourceXAcquisitionRef *ref, uint64 value) +cluster_pcm_lock_resource_x_trace_ref(uint16 kind, const ResourceXAcquisitionRef *ref, uint64 value) { - ResourceXTraceEvent event = {0}; + ResourceXTraceEvent event = { 0 }; if (ref == NULL || ClusterPcm == NULL || pg_atomic_read_u64(&ClusterPcm->trace_active_epoch) == 0) @@ -4926,10 +4389,10 @@ cluster_pcm_lock_resource_x_trace_ref(uint16 kind, } void -cluster_pcm_lock_resource_x_trace_frame(uint16 kind, - const ResourceXDecodedFrame *frame, int32 peer, int32 result) +cluster_pcm_lock_resource_x_trace_frame(uint16 kind, const ResourceXDecodedFrame *frame, int32 peer, + int32 result) { - ResourceXTraceEvent event = {0}; + ResourceXTraceEvent event = { 0 }; if (frame == NULL || ClusterPcm == NULL || pg_atomic_read_u64(&ClusterPcm->trace_active_epoch) == 0) @@ -4952,8 +4415,8 @@ cluster_pcm_lock_resource_x_trace_frame(uint16 kind, } void -cluster_pcm_lock_resource_x_trace_wire(uint8 msg_type, int32 peer, - const void *payload, uint32 length, int32 result) +cluster_pcm_lock_resource_x_trace_wire(uint8 msg_type, int32 peer, const void *payload, + uint32 length, int32 result) { ResourceXDecodedFrame frame; ResourceXWireReject reject; @@ -4968,12 +4431,11 @@ cluster_pcm_lock_resource_x_trace_wire(uint8 msg_type, int32 peer, static bool pcm_resource_x_intent_body_valid(const ResourceXIntentBodyHandle *body) { - if (body == NULL || !resource_x_assertion_valid(&body->assertion) - || body->owner_generation == 0 || body->owner_generation == UINT64_MAX + if (body == NULL || !resource_x_assertion_valid(&body->assertion) || body->owner_generation == 0 + || body->owner_generation == UINT64_MAX || body->owner_node >= RESOURCE_X_PROTOCOL_NODE_LIMIT || body->owner_kind < RESOURCE_X_INTENT_OWNER_MASTER_BLOCK - || body->owner_kind > RESOURCE_X_INTENT_OWNER_HOLDER_RELEASE - || body->reserved != 0) + || body->owner_kind > RESOURCE_X_INTENT_OWNER_HOLDER_RELEASE || body->reserved != 0) return false; if (body->owner_kind == RESOURCE_X_INTENT_OWNER_MASTER_BLOCK) return body->owner_index < RESOURCE_X_PROTOCOL_NODE_LIMIT; @@ -4987,17 +4449,14 @@ pcm_resource_x_intent_mark_pending(bool wake) if (ClusterPcm == NULL) return false; - generation - = pg_atomic_read_u64(&ClusterPcm->resource_x_intent_arm_generation); + generation = pg_atomic_read_u64(&ClusterPcm->resource_x_intent_arm_generation); for (;;) { if (generation == UINT64_MAX) { - pg_atomic_write_u32( - &ClusterPcm->resource_x_intent_generation_exhausted, 1); + pg_atomic_write_u32(&ClusterPcm->resource_x_intent_generation_exhausted, 1); return false; } - if (pg_atomic_compare_exchange_u64( - &ClusterPcm->resource_x_intent_arm_generation, - &generation, generation + 1)) { + if (pg_atomic_compare_exchange_u64(&ClusterPcm->resource_x_intent_arm_generation, + &generation, generation + 1)) { if (wake) cluster_lms_wakeup(0); return true; @@ -5012,56 +4471,52 @@ pcm_resource_x_intent_mark_dirty(void) } static bool -pcm_resource_x_intent_payload_exact(ResourceXWireKind kind, - uint16 payload_bytes) +pcm_resource_x_intent_payload_exact(ResourceXWireKind kind, uint16 payload_bytes) { switch (kind) { - case RESOURCE_X_WIRE_PREASSERT_BOOTSTRAP: - /* Bootstrap staging is non-authority and never uses the retained + case RESOURCE_X_WIRE_PREASSERT_BOOTSTRAP: + /* Bootstrap staging is non-authority and never uses the retained * authority intent family. */ - return false; - case RESOURCE_X_WIRE_ASSERT_X: - case RESOURCE_X_WIRE_BLOCK_TO_N: - case RESOURCE_X_WIRE_RELEASE_X: - return payload_bytes == RESOURCE_X_CONTROL_V1_BYTES; - case RESOURCE_X_WIRE_LOCAL_PROOF_DECLARATION: - case RESOURCE_X_WIRE_INSTALL_SETTLEMENT: - return payload_bytes == RESOURCE_X_SHORT_V1_BYTES; - case RESOURCE_X_WIRE_BLOCKED_TO_N: - return payload_bytes == RESOURCE_X_CONTROL_V1_BYTES - || payload_bytes == RESOURCE_X_PROOF_V1_BYTES; - case RESOURCE_X_WIRE_SOURCE_SETTLEMENT_V2: - case RESOURCE_X_WIRE_SOURCE_SETTLEMENT_ACK_V2: - return payload_bytes == RESOURCE_X_PROOF_V1_BYTES; - case RESOURCE_X_WIRE_AUTHORITY_GRANT: - return payload_bytes == RESOURCE_X_PROOF_V1_BYTES; - case RESOURCE_X_WIRE_IMAGE_ENVELOPE: - return payload_bytes == RESOURCE_X_IMAGE_V1_BYTES; + return false; + case RESOURCE_X_WIRE_ASSERT_X: + case RESOURCE_X_WIRE_BLOCK_TO_N: + case RESOURCE_X_WIRE_RELEASE_X: + return payload_bytes == RESOURCE_X_CONTROL_V1_BYTES; + case RESOURCE_X_WIRE_LOCAL_PROOF_DECLARATION: + case RESOURCE_X_WIRE_INSTALL_SETTLEMENT: + return payload_bytes == RESOURCE_X_SHORT_V1_BYTES; + case RESOURCE_X_WIRE_BLOCKED_TO_N: + return payload_bytes == RESOURCE_X_CONTROL_V1_BYTES + || payload_bytes == RESOURCE_X_PROOF_V1_BYTES; + case RESOURCE_X_WIRE_SOURCE_SETTLEMENT_V2: + case RESOURCE_X_WIRE_SOURCE_SETTLEMENT_ACK_V2: + return payload_bytes == RESOURCE_X_PROOF_V1_BYTES; + case RESOURCE_X_WIRE_AUTHORITY_GRANT: + return payload_bytes == RESOURCE_X_PROOF_V1_BYTES; + case RESOURCE_X_WIRE_IMAGE_ENVELOPE: + return payload_bytes == RESOURCE_X_IMAGE_V1_BYTES; } return false; } bool -cluster_pcm_lock_resource_x_intent_arm_exact( - ResourceXIntentSlot *slot, const ResourceXIntentBodyHandle *body, - uint64 logical_generation, uint64 authority_generation, - uint64 now_us, uint32 destination_node, uint16 payload_bytes, - ResourceXWireKind kind) -{ - if (slot == NULL || !pcm_resource_x_intent_body_valid(body) - || logical_generation == 0 || logical_generation == UINT64_MAX - || authority_generation == 0 || authority_generation == UINT64_MAX - || now_us == 0 || now_us == UINT64_MAX +cluster_pcm_lock_resource_x_intent_arm_exact(ResourceXIntentSlot *slot, + const ResourceXIntentBodyHandle *body, + uint64 logical_generation, uint64 authority_generation, + uint64 now_us, uint32 destination_node, + uint16 payload_bytes, ResourceXWireKind kind) +{ + if (slot == NULL || !pcm_resource_x_intent_body_valid(body) || logical_generation == 0 + || logical_generation == UINT64_MAX || authority_generation == 0 + || authority_generation == UINT64_MAX || now_us == 0 || now_us == UINT64_MAX || destination_node >= RESOURCE_X_PROTOCOL_NODE_LIMIT || !pcm_resource_x_intent_payload_exact(kind, payload_bytes)) return false; if (slot->state != RESOURCE_X_INTENT_SLOT_EMPTY) return slot->logical_generation == logical_generation - && slot->authority_generation == authority_generation - && slot->destination_node == destination_node - && slot->payload_bytes == payload_bytes - && slot->kind == (uint8)kind - && memcmp(&slot->body, body, sizeof(*body)) == 0; + && slot->authority_generation == authority_generation + && slot->destination_node == destination_node && slot->payload_bytes == payload_bytes + && slot->kind == (uint8)kind && memcmp(&slot->body, body, sizeof(*body)) == 0; memset(slot, 0, sizeof(*slot)); slot->logical_generation = logical_generation; @@ -5076,18 +4531,16 @@ cluster_pcm_lock_resource_x_intent_arm_exact( } ResourceXIntentResult -cluster_pcm_lock_resource_x_intent_not_admitted_exact( - ResourceXIntentSlot *slot, const ResourceXIntentSlot *expected, - uint64 now_us) +cluster_pcm_lock_resource_x_intent_not_admitted_exact(ResourceXIntentSlot *slot, + const ResourceXIntentSlot *expected, + uint64 now_us) { - if (slot == NULL || expected == NULL || now_us == 0 - || now_us == UINT64_MAX + if (slot == NULL || expected == NULL || now_us == 0 || now_us == UINT64_MAX || slot->logical_generation != expected->logical_generation || slot->authority_generation != expected->authority_generation || slot->first_armed_us != expected->first_armed_us || slot->destination_node != expected->destination_node - || slot->payload_bytes != expected->payload_bytes - || slot->kind != expected->kind + || slot->payload_bytes != expected->payload_bytes || slot->kind != expected->kind || memcmp(&slot->body, &expected->body, sizeof(slot->body)) != 0 || slot->state != RESOURCE_X_INTENT_SLOT_ARMED) return RESOURCE_X_INTENT_STALE; @@ -5096,18 +4549,15 @@ cluster_pcm_lock_resource_x_intent_not_admitted_exact( } ResourceXIntentResult -cluster_pcm_lock_resource_x_intent_stage_exact( - ResourceXIntentSlot *slot, const ResourceXIntentSlot *expected, - uint64 now_us) +cluster_pcm_lock_resource_x_intent_stage_exact(ResourceXIntentSlot *slot, + const ResourceXIntentSlot *expected, uint64 now_us) { - if (slot == NULL || expected == NULL || now_us == 0 - || now_us == UINT64_MAX + if (slot == NULL || expected == NULL || now_us == 0 || now_us == UINT64_MAX || slot->logical_generation != expected->logical_generation || slot->authority_generation != expected->authority_generation || slot->first_armed_us != expected->first_armed_us || slot->destination_node != expected->destination_node - || slot->payload_bytes != expected->payload_bytes - || slot->kind != expected->kind + || slot->payload_bytes != expected->payload_bytes || slot->kind != expected->kind || memcmp(&slot->body, &expected->body, sizeof(slot->body)) != 0) return RESOURCE_X_INTENT_STALE; if (slot->state == RESOURCE_X_INTENT_SLOT_STAGED) @@ -5120,18 +4570,16 @@ cluster_pcm_lock_resource_x_intent_stage_exact( } ResourceXIntentResult -cluster_pcm_lock_resource_x_intent_hard_rearm_exact( - ResourceXIntentSlot *slot, const ResourceXIntentSlot *expected, - uint64 now_us) +cluster_pcm_lock_resource_x_intent_hard_rearm_exact(ResourceXIntentSlot *slot, + const ResourceXIntentSlot *expected, + uint64 now_us) { - if (slot == NULL || expected == NULL || now_us == 0 - || now_us == UINT64_MAX + if (slot == NULL || expected == NULL || now_us == 0 || now_us == UINT64_MAX || slot->logical_generation != expected->logical_generation || slot->authority_generation != expected->authority_generation || slot->first_armed_us != expected->first_armed_us || slot->destination_node != expected->destination_node - || slot->payload_bytes != expected->payload_bytes - || slot->kind != expected->kind + || slot->payload_bytes != expected->payload_bytes || slot->kind != expected->kind || memcmp(&slot->body, &expected->body, sizeof(slot->body)) != 0) return RESOURCE_X_INTENT_STALE; if (slot->state == RESOURCE_X_INTENT_SLOT_ARMED) @@ -5144,16 +4592,14 @@ cluster_pcm_lock_resource_x_intent_hard_rearm_exact( } bool -cluster_pcm_lock_resource_x_intent_complete_exact( - ResourceXIntentSlot *slot, const ResourceXIntentSlot *expected) +cluster_pcm_lock_resource_x_intent_complete_exact(ResourceXIntentSlot *slot, + const ResourceXIntentSlot *expected) { - if (slot == NULL || expected == NULL - || slot->logical_generation != expected->logical_generation + if (slot == NULL || expected == NULL || slot->logical_generation != expected->logical_generation || slot->authority_generation != expected->authority_generation || slot->first_armed_us != expected->first_armed_us || slot->destination_node != expected->destination_node - || slot->payload_bytes != expected->payload_bytes - || slot->kind != expected->kind + || slot->payload_bytes != expected->payload_bytes || slot->kind != expected->kind || memcmp(&slot->body, &expected->body, sizeof(slot->body)) != 0 || slot->state != RESOURCE_X_INTENT_SLOT_STAGED) return false; @@ -5183,8 +4629,7 @@ static bool pcm_resource_x_active_empty_locked(const struct GrdEntry *entry) { return entry->resource_x_requester_node == -1 && entry->resource_x_progress_flags == 0 - && entry->resource_x_formation == 0 - && entry->resource_x_acquisition_generation == 0 + && entry->resource_x_formation == 0 && entry->resource_x_acquisition_generation == 0 && entry->resource_x_no_progress_generation == 0 && entry->resource_x_no_progress_reason == RESOURCE_X_NO_PROGRESS_NONE && entry->resource_x_dispatch_phase == 0; @@ -5197,31 +4642,27 @@ pcm_resource_x_active_valid_locked(const struct GrdEntry *entry) if (entry->resource_x_requester_node < 0 || entry->resource_x_requester_node >= RESOURCE_X_PROTOCOL_NODE_LIMIT - || entry->resource_x_formation == 0 - || entry->resource_x_formation == UINT64_MAX + || entry->resource_x_formation == 0 || entry->resource_x_formation == UINT64_MAX || entry->resource_x_acquisition_generation == 0 || entry->resource_x_acquisition_generation == UINT64_MAX) return false; active_flags = entry->resource_x_progress_flags & ~RESOURCE_X_PROGRESS_RECOVERY_BLOCKED; if (active_flags != (RESOURCE_X_PROGRESS_BOUND | RESOURCE_X_PROGRESS_T1) && active_flags - != (RESOURCE_X_PROGRESS_BOUND | RESOURCE_X_PROGRESS_T1 | RESOURCE_X_PROGRESS_T2)) + != (RESOURCE_X_PROGRESS_BOUND | RESOURCE_X_PROGRESS_T1 | RESOURCE_X_PROGRESS_T2)) return false; if ((entry->resource_x_progress_flags & ~RESOURCE_X_PROGRESS_KNOWN_MASK) != 0 || (entry->resource_x_progress_flags & RESOURCE_X_PROGRESS_T3) != 0) return false; return (entry->resource_x_no_progress_generation == 0 && entry->resource_x_no_progress_reason == RESOURCE_X_NO_PROGRESS_NONE) - || (entry->resource_x_no_progress_generation - == entry->resource_x_acquisition_generation + || (entry->resource_x_no_progress_generation == entry->resource_x_acquisition_generation && entry->resource_x_no_progress_reason > RESOURCE_X_NO_PROGRESS_NONE - && entry->resource_x_no_progress_reason - <= RESOURCE_X_NO_PROGRESS_BUFFER_CORRUPT); + && entry->resource_x_no_progress_reason <= RESOURCE_X_NO_PROGRESS_BUFFER_CORRUPT); } static PcmResourceXRefClass -pcm_resource_x_ref_classify_locked(const struct GrdEntry *entry, - const ResourceXAcquisitionRef *ref) +pcm_resource_x_ref_classify_locked(const struct GrdEntry *entry, const ResourceXAcquisitionRef *ref) { bool active_empty; @@ -5233,8 +4674,8 @@ pcm_resource_x_ref_classify_locked(const struct GrdEntry *entry, if (!active_empty) { if (!pcm_resource_x_active_valid_locked(entry)) return PCM_RX_REF_CORRUPT; - return pcm_resource_x_entry_exact(entry, ref) - ? PCM_RX_REF_ACTIVE_EXACT : PCM_RX_REF_ACTIVE_OTHER; + return pcm_resource_x_entry_exact(entry, ref) ? PCM_RX_REF_ACTIVE_EXACT + : PCM_RX_REF_ACTIVE_OTHER; } if (ref->acquisition_generation < entry->resource_x_retired_acquisition_generation) return PCM_RX_REF_RETIRED_OLD; @@ -5284,13 +4725,12 @@ pcm_entry_ref_identity_exact(const PcmEntryRef *ref) { struct GrdEntry *entry; - if (ref == NULL || !ref->pinned || ref->entry == NULL - || ref->binding_generation == 0) + if (ref == NULL || !ref->pinned || ref->entry == NULL || ref->binding_generation == 0) return false; entry = ref->entry; return BufferTagsEqual(&entry->tag, &ref->tag) - && entry->binding_generation == ref->binding_generation - && entry->registry_slot == ref->registry_slot; + && entry->binding_generation == ref->binding_generation + && entry->registry_slot == ref->registry_slot; } static void @@ -5302,21 +4742,18 @@ pcm_entry_wait_ref_begin(PcmEntryWaitContext *context) Assert(context != NULL && !context->wait_registered); if (!pcm_entry_ref_identity_exact(&context->ref)) { pcm_resource_x_reconfig_block(); - ereport(ERROR, - (errcode(ERRCODE_DATA_CORRUPTED), - errmsg("PCM waiter entry identity changed before registration"))); + ereport(ERROR, (errcode(ERRCODE_DATA_CORRUPTED), + errmsg("PCM waiter entry identity changed before registration"))); } entry = context->ref.entry; refs = pg_atomic_read_u32(&entry->wait_refcount); for (;;) { if (refs == UINT32_MAX) { pcm_resource_x_reconfig_block(); - ereport(ERROR, - (errcode(ERRCODE_DATA_CORRUPTED), - errmsg("PCM entry wait reference count overflow"))); + ereport(ERROR, (errcode(ERRCODE_DATA_CORRUPTED), + errmsg("PCM entry wait reference count overflow"))); } - if (pg_atomic_compare_exchange_u32( - &entry->wait_refcount, &refs, refs + 1)) + if (pg_atomic_compare_exchange_u32(&entry->wait_refcount, &refs, refs + 1)) break; } context->wait_registered = true; @@ -5331,21 +4768,18 @@ pcm_entry_wait_ref_end(PcmEntryWaitContext *context) Assert(context != NULL && context->wait_registered); if (!pcm_entry_ref_identity_exact(&context->ref)) { pcm_resource_x_reconfig_block(); - ereport(ERROR, - (errcode(ERRCODE_DATA_CORRUPTED), - errmsg("PCM waiter entry identity changed before release"))); + ereport(ERROR, (errcode(ERRCODE_DATA_CORRUPTED), + errmsg("PCM waiter entry identity changed before release"))); } entry = context->ref.entry; refs = pg_atomic_read_u32(&entry->wait_refcount); for (;;) { if (refs == 0) { pcm_resource_x_reconfig_block(); - ereport(ERROR, - (errcode(ERRCODE_DATA_CORRUPTED), - errmsg("PCM entry wait reference count underflow"))); + ereport(ERROR, (errcode(ERRCODE_DATA_CORRUPTED), + errmsg("PCM entry wait reference count underflow"))); } - if (pg_atomic_compare_exchange_u32( - &entry->wait_refcount, &refs, refs - 1)) + if (pg_atomic_compare_exchange_u32(&entry->wait_refcount, &refs, refs - 1)) break; } context->wait_registered = false; @@ -5384,20 +4818,18 @@ static bool pcm_resource_x_executor_wait_ref_exact(const ResourceXAcquisitionRef *ref) { return ref != NULL - && resource_x_assertion_equal( - &pcm_resource_x_executor_wait_ref.assertion, &ref->assertion) - && pcm_resource_x_executor_wait_ref.formation == ref->formation - && pcm_resource_x_executor_wait_ref.acquisition_generation - == ref->acquisition_generation; + && resource_x_assertion_equal(&pcm_resource_x_executor_wait_ref.assertion, + &ref->assertion) + && pcm_resource_x_executor_wait_ref.formation == ref->formation + && pcm_resource_x_executor_wait_ref.acquisition_generation + == ref->acquisition_generation; } static void pcm_resource_x_executor_wait_cleanup(void) { - pcm_entry_wait_context_cleanup( - &pcm_resource_x_executor_wait_context); - memset(&pcm_resource_x_executor_wait_ref, 0, - sizeof(pcm_resource_x_executor_wait_ref)); + pcm_entry_wait_context_cleanup(&pcm_resource_x_executor_wait_context); + memset(&pcm_resource_x_executor_wait_ref, 0, sizeof(pcm_resource_x_executor_wait_ref)); } ResourceXApplyResult @@ -5413,8 +4845,7 @@ cluster_pcm_lock_resource_x_t1_grant_delivery_exact(const ResourceXAcquisitionRe if (!pcm_resource_x_ref_valid(ref)) return RESOURCE_X_APPLY_INVALID; - if (!pcm_entry_ref_acquire(&ref->assertion.resource, true, - &entry_ref, &acquire_result)) + if (!pcm_entry_ref_acquire(&ref->assertion.resource, true, &entry_ref, &acquire_result)) return RESOURCE_X_APPLY_NOT_FOUND; entry = entry_ref.entry; @@ -5450,8 +4881,7 @@ cluster_pcm_lock_resource_x_t1_grant_delivery_exact(const ResourceXAcquisitionRe entry->resource_x_requester_node = ref->assertion.requester_node; entry->resource_x_formation = ref->formation; entry->resource_x_acquisition_generation = ref->acquisition_generation; - entry->resource_x_progress_flags - = RESOURCE_X_PROGRESS_BOUND | RESOURCE_X_PROGRESS_T1; + entry->resource_x_progress_flags = RESOURCE_X_PROGRESS_BOUND | RESOURCE_X_PROGRESS_T1; entry->resource_x_no_progress_generation = 0; entry->resource_x_no_progress_reason = RESOURCE_X_NO_PROGRESS_NONE; entry->resource_x_dispatch_phase = 0; @@ -5477,7 +4907,7 @@ cluster_pcm_lock_resource_x_t1_grant_exact(const ResourceXAcquisitionRef *ref) ResourceXExecutorProbeResult cluster_pcm_lock_resource_x_executor_probe_exact(const ResourceXAcquisitionRef *ref, - ResourceXExecutorSnapshot *out_snapshot) + ResourceXExecutorSnapshot *out_snapshot) { PcmEntryAcquireResult acquire_result; struct GrdEntry *entry; @@ -5491,7 +4921,7 @@ cluster_pcm_lock_resource_x_executor_probe_exact(const ResourceXAcquisitionRef * return RESOURCE_X_EXECUTOR_CHANGED; pcm_resource_x_executor_wait_cleanup(); if (!pcm_entry_ref_acquire(&ref->assertion.resource, false, - &pcm_resource_x_executor_wait_context.ref, &acquire_result)) + &pcm_resource_x_executor_wait_context.ref, &acquire_result)) return RESOURCE_X_EXECUTOR_CHANGED; entry = pcm_resource_x_executor_wait_context.ref.entry; @@ -5509,15 +4939,14 @@ cluster_pcm_lock_resource_x_executor_probe_exact(const ResourceXAcquisitionRef * out_snapshot->progress_flags = RESOURCE_X_PROGRESS_T1 | RESOURCE_X_PROGRESS_T2 | RESOURCE_X_PROGRESS_T3; result = RESOURCE_X_EXECUTOR_COMPLETE; - } - else if (ref_class == PCM_RX_REF_CORRUPT) + } else if (ref_class == PCM_RX_REF_CORRUPT) result = RESOURCE_X_EXECUTOR_RECOVERY_BLOCKED; else if (ref_class != PCM_RX_REF_ACTIVE_EXACT) result = RESOURCE_X_EXECUTOR_CHANGED; else if ((entry->resource_x_progress_flags & RESOURCE_X_PROGRESS_RECOVERY_BLOCKED) != 0) result = RESOURCE_X_EXECUTOR_RECOVERY_BLOCKED; else if (entry->resource_x_no_progress_generation == ref->acquisition_generation - && entry->resource_x_no_progress_reason != RESOURCE_X_NO_PROGRESS_NONE) + && entry->resource_x_no_progress_reason != RESOURCE_X_NO_PROGRESS_NONE) result = RESOURCE_X_EXECUTOR_BLOCKED; else result = RESOURCE_X_EXECUTOR_READY; @@ -5533,8 +4962,7 @@ cluster_pcm_lock_resource_x_executor_probe_exact(const ResourceXAcquisitionRef * * {tag,binding_generation} handle keeps this wait_cv alive; the complete * logical ref check prevents a successor acquisition from borrowing it. */ ResourceXApplyResult -cluster_pcm_lock_resource_x_executor_wait_exact(const ResourceXAcquisitionRef *ref, - long timeout_ms) +cluster_pcm_lock_resource_x_executor_wait_exact(const ResourceXAcquisitionRef *ref, long timeout_ms) { struct GrdEntry *entry; ResourceXApplyResult result; @@ -5574,9 +5002,8 @@ cluster_pcm_lock_resource_x_executor_wait_exact(const ResourceXAcquisitionRef *r PG_TRY(); { (void)ConditionVariableTimedSleep(&entry->wait_cv, timeout_ms, - WAIT_EVENT_PCM_COMPATIBLE_STATE_WAIT); - if (!pcm_entry_ref_identity_exact( - &pcm_resource_x_executor_wait_context.ref)) { + WAIT_EVENT_PCM_COMPATIBLE_STATE_WAIT); + if (!pcm_entry_ref_identity_exact(&pcm_resource_x_executor_wait_context.ref)) { pcm_resource_x_reconfig_block(); ereport(ERROR, (errcode(ERRCODE_DATA_CORRUPTED), errmsg("Resource-X executor waiter entry identity changed " @@ -5609,8 +5036,7 @@ cluster_pcm_lock_resource_x_executor_rearm_exact(const ResourceXAcquisitionRef * if (!pcm_resource_x_ref_valid(ref)) return RESOURCE_X_APPLY_INVALID; - if (!pcm_entry_ref_acquire(&ref->assertion.resource, false, - &entry_ref, &acquire_result)) + if (!pcm_entry_ref_acquire(&ref->assertion.resource, false, &entry_ref, &acquire_result)) return RESOURCE_X_APPLY_NOT_FOUND; entry = entry_ref.entry; @@ -5634,14 +5060,11 @@ cluster_pcm_lock_resource_x_executor_rearm_exact(const ResourceXAcquisitionRef * || entry->resource_x_no_progress_reason <= RESOURCE_X_NO_PROGRESS_NONE || entry->resource_x_no_progress_reason > RESOURCE_X_NO_PROGRESS_BUFFER_CORRUPT) result = RESOURCE_X_APPLY_RECOVERY_BLOCKED; - else if (entry->resource_x_dispatch_phase == UINT32_MAX) - { + else if (entry->resource_x_dispatch_phase == UINT32_MAX) { entry->resource_x_progress_flags |= RESOURCE_X_PROGRESS_RECOVERY_BLOCKED; broadcast = true; result = RESOURCE_X_APPLY_RECOVERY_BLOCKED; - } - else - { + } else { entry->resource_x_dispatch_phase++; entry->resource_x_no_progress_generation = 0; entry->resource_x_no_progress_reason = RESOURCE_X_NO_PROGRESS_NONE; @@ -5678,8 +5101,7 @@ cluster_pcm_lock_resource_x_requester_apply_delivery_exact(const ResourceXAcquis return RESOURCE_X_APPLY_INVALID; if (proof->resource_x_activation_generation != ref->acquisition_generation) return RESOURCE_X_APPLY_STALE; - if (!pcm_entry_ref_acquire(&ref->assertion.resource, false, - &entry_ref, &acquire_result)) + if (!pcm_entry_ref_acquire(&ref->assertion.resource, false, &entry_ref, &acquire_result)) return RESOURCE_X_APPLY_NOT_FOUND; entry = entry_ref.entry; @@ -5692,11 +5114,9 @@ cluster_pcm_lock_resource_x_requester_apply_delivery_exact(const ResourceXAcquis } same_bootstrap_ref = round->phase == RESOURCE_X_BOOTSTRAP_ROUND_ASSERT_DISPATCHED - && resource_x_assertion_equal( - &round->request.logical_assertion, &ref->assertion) + && resource_x_assertion_equal(&round->request.logical_assertion, &ref->assertion) && round->resource_formation == ref->formation - && round->request.assertion_sequence - == ref->acquisition_generation; + && round->request.assertion_sequence == ref->acquisition_generation; ref_class = pcm_resource_x_ref_classify_locked(entry, ref); if (ref_class == PCM_RX_REF_RETIRED_OLD || ref_class == PCM_RX_REF_ACTIVE_OTHER) result = RESOURCE_X_APPLY_STALE; @@ -5708,22 +5128,17 @@ cluster_pcm_lock_resource_x_requester_apply_delivery_exact(const ResourceXAcquis || (entry->resource_x_progress_flags & RESOURCE_X_PROGRESS_RECOVERY_BLOCKED) != 0) result = RESOURCE_X_APPLY_RECOVERY_BLOCKED; else if ((entry->resource_x_progress_flags & RESOURCE_X_PROGRESS_T2) != 0) { - if (same_bootstrap_ref - && round->cached_ownership_generation != 0 - && round->cached_ownership_generation - != proof->ownership_generation) + if (same_bootstrap_ref && round->cached_ownership_generation != 0 + && round->cached_ownership_generation != proof->ownership_generation) result = RESOURCE_X_APPLY_STALE; else result = RESOURCE_X_APPLY_DUPLICATE; - } - else if ((entry->resource_x_progress_flags - & (RESOURCE_X_PROGRESS_BOUND | RESOURCE_X_PROGRESS_T1)) - != (RESOURCE_X_PROGRESS_BOUND | RESOURCE_X_PROGRESS_T1)) + } else if ((entry->resource_x_progress_flags + & (RESOURCE_X_PROGRESS_BOUND | RESOURCE_X_PROGRESS_T1)) + != (RESOURCE_X_PROGRESS_BOUND | RESOURCE_X_PROGRESS_T1)) result = RESOURCE_X_APPLY_BAD_STATE; - else if (same_bootstrap_ref - && round->cached_ownership_generation != 0 - && round->cached_ownership_generation - != proof->ownership_generation) + else if (same_bootstrap_ref && round->cached_ownership_generation != 0 + && round->cached_ownership_generation != proof->ownership_generation) result = RESOURCE_X_APPLY_STALE; else { /* Freeze the exact BufferDesc generation while the T2 writer fence is @@ -5731,8 +5146,7 @@ cluster_pcm_lock_resource_x_requester_apply_delivery_exact(const ResourceXAcquis * post-T3/pre-cover cross-lock interval without deriving authority from * an arbitrary cached X descriptor. */ if (same_bootstrap_ref) - round->cached_ownership_generation - = proof->ownership_generation; + round->cached_ownership_generation = proof->ownership_generation; entry->resource_x_progress_flags |= RESOURCE_X_PROGRESS_T2; entry->resource_x_no_progress_generation = 0; entry->resource_x_no_progress_reason = RESOURCE_X_NO_PROGRESS_NONE; @@ -5777,8 +5191,7 @@ cluster_pcm_lock_resource_x_requester_activate_delivery_exact( return RESOURCE_X_APPLY_INVALID; if (proof->writer_activation_token != 0 || proof->resource_x_activation_generation != 0) return RESOURCE_X_APPLY_STALE; - if (!pcm_entry_ref_acquire(&ref->assertion.resource, false, - &entry_ref, &acquire_result)) + if (!pcm_entry_ref_acquire(&ref->assertion.resource, false, &entry_ref, &acquire_result)) return RESOURCE_X_APPLY_NOT_FOUND; entry = entry_ref.entry; @@ -5800,10 +5213,8 @@ cluster_pcm_lock_resource_x_requester_activate_delivery_exact( || (entry->resource_x_progress_flags & RESOURCE_X_PROGRESS_RECOVERY_BLOCKED) != 0) result = RESOURCE_X_APPLY_RECOVERY_BLOCKED; else if ((entry->resource_x_progress_flags - & (RESOURCE_X_PROGRESS_BOUND | RESOURCE_X_PROGRESS_T1 - | RESOURCE_X_PROGRESS_T2)) - != (RESOURCE_X_PROGRESS_BOUND | RESOURCE_X_PROGRESS_T1 - | RESOURCE_X_PROGRESS_T2) + & (RESOURCE_X_PROGRESS_BOUND | RESOURCE_X_PROGRESS_T1 | RESOURCE_X_PROGRESS_T2)) + != (RESOURCE_X_PROGRESS_BOUND | RESOURCE_X_PROGRESS_T1 | RESOURCE_X_PROGRESS_T2) || entry->resource_x_no_progress_generation != 0 || entry->resource_x_no_progress_reason != RESOURCE_X_NO_PROGRESS_NONE) result = RESOURCE_X_APPLY_BAD_STATE; @@ -5812,54 +5223,40 @@ cluster_pcm_lock_resource_x_requester_activate_delivery_exact( == RESOURCE_X_APPLY_APPLIED) { same_bootstrap_ref = witness.had_join - && resource_x_assertion_equal( - &round->request.logical_assertion, &ref->assertion) + && resource_x_assertion_equal(&round->request.logical_assertion, &ref->assertion) && round->resource_formation == ref->formation - && round->request.assertion_sequence - == ref->acquisition_generation; + && round->request.assertion_sequence == ref->acquisition_generation; if (same_bootstrap_ref) { /* The requester round is the sole retained full-ref cover after * T3. Validate every fallible input before retirement, then publish * the cover in the same entry-lock commit. This removes the * post-T3/pre-cover observation window without deriving authority * from the retired floor or the local neutral GRD projection. */ - if (round->phase - != RESOURCE_X_BOOTSTRAP_ROUND_ASSERT_DISPATCHED - || round->highest_attempt_floor - != ref->acquisition_generation + if (round->phase != RESOURCE_X_BOOTSTRAP_ROUND_ASSERT_DISPATCHED + || round->highest_attempt_floor != ref->acquisition_generation || round->master_session_incarnation == 0 || round->master_session_incarnation == UINT64_MAX - || round->r4_record_generation == 0 - || round->r4_record_generation == UINT64_MAX - || round->accepted_base == 0 - || round->accepted_base >= UINT64_MAX - 1 - || round->cached_ownership_generation - != proof->ownership_generation + || round->r4_record_generation == 0 || round->r4_record_generation == UINT64_MAX + || round->accepted_base == 0 || round->accepted_base >= UINT64_MAX - 1 + || round->cached_ownership_generation != proof->ownership_generation || witness.already_settled - || witness.final_authority_generation - <= round->accepted_base + || witness.final_authority_generation <= round->accepted_base || witness.final_authority_generation == UINT64_MAX - || !cluster_pcm_lock_resource_x_gate_open_exact( - ref->formation)) + || !cluster_pcm_lock_resource_x_gate_open_exact(ref->formation)) result = RESOURCE_X_APPLY_STALE; else publish_terminal_cover = true; } if (result == RESOURCE_X_APPLY_APPLIED - && !pcm_resource_x_requester_settlement_arm_locked( - entry, ref, &witness)) + && !pcm_resource_x_requester_settlement_arm_locked(entry, ref, &witness)) result = RESOURCE_X_APPLY_RECOVERY_BLOCKED; else if (result == RESOURCE_X_APPLY_APPLIED) { - pcm_resource_x_requester_retirement_commit_locked( - entry, ref, &witness); + pcm_resource_x_requester_retirement_commit_locked(entry, ref, &witness); if (publish_terminal_cover) { round->terminal_ref = *ref; - round->terminal_authority_generation - = witness.final_authority_generation; - round->cached_ownership_generation - = proof->ownership_generation; - round->phase - = RESOURCE_X_BOOTSTRAP_ROUND_TERMINAL_X_CACHED; + round->terminal_authority_generation = witness.final_authority_generation; + round->cached_ownership_generation = proof->ownership_generation; + round->phase = RESOURCE_X_BOOTSTRAP_ROUND_TERMINAL_X_CACHED; } if (!pcm_resource_x_head_progress_ref_locked(entry, ref, pcm_resource_x_monotonic_us())) result = RESOURCE_X_APPLY_RECOVERY_BLOCKED; @@ -5882,7 +5279,7 @@ cluster_pcm_lock_resource_x_requester_activate_exact(const ResourceXAcquisitionR void cluster_pcm_lock_resource_x_publish_no_progress_exact(const ResourceXAcquisitionRef *ref, - ResourceXNoProgressReason reason) + ResourceXNoProgressReason reason) { PcmEntryRef entry_ref; PcmEntryAcquireResult acquire_result; @@ -5893,8 +5290,7 @@ cluster_pcm_lock_resource_x_publish_no_progress_exact(const ResourceXAcquisition if (!pcm_resource_x_ref_valid(ref) || reason <= RESOURCE_X_NO_PROGRESS_NONE || reason > RESOURCE_X_NO_PROGRESS_BUFFER_CORRUPT) return; - if (!pcm_entry_ref_acquire(&ref->assertion.resource, false, - &entry_ref, &acquire_result)) + if (!pcm_entry_ref_acquire(&ref->assertion.resource, false, &entry_ref, &acquire_result)) return; entry = entry_ref.entry; @@ -5902,9 +5298,7 @@ cluster_pcm_lock_resource_x_publish_no_progress_exact(const ResourceXAcquisition ref_class = pcm_resource_x_ref_classify_locked(entry, ref); if (ref_class == PCM_RX_REF_ACTIVE_EXACT && (entry->resource_x_progress_flags & RESOURCE_X_PROGRESS_T1) != 0 - && (entry->resource_x_progress_flags - & RESOURCE_X_PROGRESS_RECOVERY_BLOCKED) - == 0 + && (entry->resource_x_progress_flags & RESOURCE_X_PROGRESS_RECOVERY_BLOCKED) == 0 && (entry->resource_x_no_progress_generation != ref->acquisition_generation || entry->resource_x_no_progress_reason != (uint32)reason)) { entry->resource_x_no_progress_generation = ref->acquisition_generation; @@ -5949,8 +5343,7 @@ pcm_lock_try_reserve_pending_x_value(BufferTag tag, int32 requester_node, uint64 /* Admission itself is the first authoritative touch for a cold tag. Use * the canonical lazy allocator so both legacy and queue writers can arm * the barrier before any transition exists. */ - if (!pcm_entry_ref_acquire( - &tag, true, &entry_ref, &acquire_result)) + if (!pcm_entry_ref_acquire(&tag, true, &entry_ref, &acquire_result)) return PCM_PENDING_X_RESERVE_NO_CAPACITY; entry = entry_ref.entry; LWLockAcquire(&entry->entry_lock.lock, LW_EXCLUSIVE); @@ -6004,8 +5397,7 @@ cluster_pcm_lock_queue_pending_x_exact(BufferTag tag, int32 requester_node, uint if (ClusterPcm == NULL || cluster_pcm_htab == NULL || requester_node < 0 || requester_node >= 32 || !PcmPendingXQueueValue(ticket_id, &expected)) return false; - if (!pcm_entry_ref_acquire( - &tag, false, &entry_ref, &acquire_result)) + if (!pcm_entry_ref_acquire(&tag, false, &entry_ref, &acquire_result)) return false; entry = entry_ref.entry; LWLockAcquire(&entry->entry_lock.lock, LW_SHARED); @@ -6533,8 +5925,7 @@ cluster_gcs_block_master_rebuild_from_redeclare(BufferTag tag, uint8 held_mode, if (held_mode != (uint8)PCM_STATE_S && held_mode != (uint8)PCM_STATE_X) return false; - if (!pcm_entry_ref_acquire( - &tag, true, &entry_ref, &acquire_result)) + if (!pcm_entry_ref_acquire(&tag, true, &entry_ref, &acquire_result)) return false; /* HC59 cap fail-closed — leave unrebuilt; survivor re-sends */ entry = entry_ref.entry; @@ -6605,8 +5996,7 @@ cluster_gcs_block_master_rebuild_from_redeclare(BufferTag tag, uint8 held_mode, entry->pi_watermark_scn = page_scn; /* step 1b: only an ACTUAL advance is recorded (per-tag table). */ pcm_wm_prov_record(tag, entry->binding_generation, wm_old, page_scn, - CLUSTER_PCM_WM_SRC_REDECLARE, source_node, 0, - cluster_epoch); + CLUSTER_PCM_WM_SRC_REDECLARE, source_node, 0, cluster_epoch); } } @@ -6680,8 +6070,7 @@ cluster_pcm_lock_master_take_x_after_transfer(BufferTag tag, const PcmAuthorityS if (scn_local(page_scn) > scn_local(entry->pi_watermark_scn)) { entry->pi_watermark_scn = page_scn; pcm_wm_prov_record(tag, entry->binding_generation, wm_old, page_scn, - CLUSTER_PCM_WM_SRC_TAKE_X, holder_node, - request_id, epoch); + CLUSTER_PCM_WM_SRC_TAKE_X, holder_node, request_id, epoch); } } entry->last_transition_at = GetCurrentTimestamp(); @@ -6726,8 +6115,7 @@ cluster_pcm_lock_master_grant_x_to(BufferTag tag, int32 requester_node, XLogRecP "PGRAC_NODE=%d PGRAC_ATTEMPT=0 ", cluster_node_id))); - if (!pcm_entry_ref_acquire( - &tag, true, &entry_ref, &acquire_result)) + if (!pcm_entry_ref_acquire(&tag, true, &entry_ref, &acquire_result)) ereport(ERROR, (errcode(ERRCODE_OUT_OF_MEMORY), errmsg("cluster_pcm_lock_master_grant_x_to: PCM GRD HTAB FULL (cap=%d)", pcm_grd_effective), @@ -6755,8 +6143,7 @@ cluster_pcm_lock_master_grant_x_to(BufferTag tag, int32 requester_node, XLogRecP entry->pi_watermark_scn = page_scn; /* step 1b: record the granted requester's wire identity on advance. */ pcm_wm_prov_record(tag, entry->binding_generation, wm_old, page_scn, - CLUSTER_PCM_WM_SRC_GRANT_X, requester_node, - request_id, epoch); + CLUSTER_PCM_WM_SRC_GRANT_X, requester_node, request_id, epoch); } } LWLockRelease(&entry->entry_lock.lock); @@ -6861,17 +6248,15 @@ pcm_wm_prov_hash(const BufferTag *tag) } static void -pcm_wm_prov_record(BufferTag tag, uint64 binding_generation, - SCN old_scn, SCN new_scn, ClusterPcmWmSrc source, - int32 sender_node, uint64 request_id, uint64 epoch) +pcm_wm_prov_record(BufferTag tag, uint64 binding_generation, SCN old_scn, SCN new_scn, + ClusterPcmWmSrc source, int32 sender_node, uint64 request_id, uint64 epoch) { ClusterPcmWmProvSlot *first_tombstone = NULL; ClusterPcmWmProvSlot *target = NULL; uint32 start; uint32 probe; - if (ClusterPcm == NULL || binding_generation == 0 - || binding_generation == UINT64_MAX) + if (ClusterPcm == NULL || binding_generation == 0 || binding_generation == UINT64_MAX) return; start = pcm_wm_prov_hash(&tag) % (uint32)CLUSTER_PCM_WM_PROV_SLOTS; LWLockAcquire(&ClusterPcm->wm_prov_lock.lock, LW_EXCLUSIVE); @@ -6893,8 +6278,7 @@ pcm_wm_prov_record(BufferTag tag, uint64 binding_generation, pcm_resource_x_reconfig_block(); return; } - if (BufferTagsEqual(&slot->tag, &tag) - && slot->binding_generation == binding_generation) { + if (BufferTagsEqual(&slot->tag, &tag) && slot->binding_generation == binding_generation) { target = slot; break; } @@ -6923,8 +6307,8 @@ pcm_wm_prov_record(BufferTag tag, uint64 binding_generation, /* Caller holds wm_prov_lock EXCLUSIVE. This is deliberately read-only: * retire publishes RETIRING before clearing the returned exact slot. */ static bool -pcm_wm_prov_validate_retire_exact_locked(const BufferTag *tag, - uint64 binding_generation, ClusterPcmWmProvSlot **slot_out) +pcm_wm_prov_validate_retire_exact_locked(const BufferTag *tag, uint64 binding_generation, + ClusterPcmWmProvSlot **slot_out) { uint32 start; uint32 probe; @@ -6932,14 +6316,12 @@ pcm_wm_prov_validate_retire_exact_locked(const BufferTag *tag, Assert(tag != NULL); Assert(slot_out != NULL); Assert(binding_generation != 0 && binding_generation != UINT64_MAX); - Assert(LWLockHeldByMeInMode( - &ClusterPcm->wm_prov_lock.lock, LW_EXCLUSIVE)); + Assert(LWLockHeldByMeInMode(&ClusterPcm->wm_prov_lock.lock, LW_EXCLUSIVE)); *slot_out = NULL; start = pcm_wm_prov_hash(tag) % (uint32)CLUSTER_PCM_WM_PROV_SLOTS; for (probe = 0; probe < (uint32)CLUSTER_PCM_WM_PROV_SLOTS; probe++) { ClusterPcmWmProvSlot *slot - = &ClusterPcm->wm_prov[ - (start + probe) % (uint32)CLUSTER_PCM_WM_PROV_SLOTS]; + = &ClusterPcm->wm_prov[(start + probe) % (uint32)CLUSTER_PCM_WM_PROV_SLOTS]; if (slot->state == PCM_SIDECAR_EMPTY) return true; @@ -7013,8 +6395,7 @@ cluster_pcm_lock_pi_watermark_prov_query(BufferTag tag, ClusterPcmWmProv *out) break; if (slot->state == PCM_SIDECAR_TOMBSTONE) continue; - if (slot->state != PCM_SIDECAR_LIVE - || !BufferTagsEqual(&slot->tag, &tag) + if (slot->state != PCM_SIDECAR_LIVE || !BufferTagsEqual(&slot->tag, &tag) || slot->binding_generation != binding_generation) continue; out->source = (ClusterPcmWmSrc)slot->source; @@ -7069,8 +6450,8 @@ cluster_pcm_lock_pi_watermark_scn_advance(BufferTag tag, SCN page_scn, ClusterPc /* step 1b: record INSIDE the entry_lock critical section so the * per-tag slot's new_scn always equals the watermark this feed * produced; non-advancing (late) feeds are never recorded. */ - pcm_wm_prov_record(tag, entry->binding_generation, wm_old, page_scn, - source, sender_node, request_id, epoch); + pcm_wm_prov_record(tag, entry->binding_generation, wm_old, page_scn, source, + sender_node, request_id, epoch); } LWLockRelease(&entry->entry_lock.lock); } @@ -7314,17 +6695,15 @@ cluster_pcm_lock_pi_discard_collect(BufferTag tag, SCN written_scn, uint32 *hold } LWLockRelease(&ClusterPcm->htab_lock.lock); if (fast_retire) - (void)pcm_entry_try_retire_exact( - &tag, retire_generation, PCM_RETIRE_REASON_PI_DISCARDED); + (void)pcm_entry_try_retire_exact(&tag, retire_generation, PCM_RETIRE_REASON_PI_DISCARDED); return retired; } static void -pcm_transition_apply_internal(struct GrdEntry *entry, - PcmLockTransition trans, int holder_node_id, - bool preserve_resource_x_terminal_cover) +pcm_transition_apply_internal(struct GrdEntry *entry, PcmLockTransition trans, int holder_node_id, + bool preserve_resource_x_terminal_cover) { uint32 holder_bit; @@ -7469,8 +6848,7 @@ pcm_transition_apply_internal(struct GrdEntry *entry, && !(preserve_resource_x_terminal_cover && trans == PCM_TRANS_X_TO_N_RELEASE && entry->resource_x_bootstrap_round.phase == RESOURCE_X_BOOTSTRAP_ROUND_TERMINAL_X_CACHED)) { - pcm_resource_x_bootstrap_round_clear_binding_locked( - &entry->resource_x_bootstrap_round); + pcm_resource_x_bootstrap_round_clear_binding_locked(&entry->resource_x_bootstrap_round); ConditionVariableBroadcast(&entry->wait_cv); } @@ -7479,8 +6857,7 @@ pcm_transition_apply_internal(struct GrdEntry *entry, } void -cluster_pcm_transition_apply(struct GrdEntry *entry, - PcmLockTransition trans, int holder_node_id) +cluster_pcm_transition_apply(struct GrdEntry *entry, PcmLockTransition trans, int holder_node_id) { pcm_transition_apply_internal(entry, trans, holder_node_id, false); } @@ -7824,15 +7201,14 @@ cluster_pcm_get_trans_s_to_x_cleanout_count(void) static bool -pcm_lock_acquire_local_pinned(BufferTag tag, PcmLockMode mode, - PcmAuthoritySnapshot *remote_x_out, PcmEntryWaitContext *wait_context) +pcm_lock_acquire_local_pinned(BufferTag tag, PcmLockMode mode, PcmAuthoritySnapshot *remote_x_out, + PcmEntryWaitContext *wait_context) { struct GrdEntry *entry; int holder_node; uint32 holder_bit; - Assert(wait_context != NULL - && pcm_entry_ref_identity_exact(&wait_context->ref)); + Assert(wait_context != NULL && pcm_entry_ref_identity_exact(&wait_context->ref)); entry = wait_context->ref.entry; holder_node = cluster_node_id; @@ -8047,17 +7423,15 @@ pcm_lock_acquire_local_pinned(BufferTag tag, PcmLockMode mode, ConditionVariableSleep(&entry->wait_cv, WAIT_EVENT_PCM_COMPATIBLE_STATE_WAIT); if (!pcm_entry_ref_identity_exact(&wait_context->ref)) { pcm_resource_x_reconfig_block(); - ereport(ERROR, - (errcode(ERRCODE_DATA_CORRUPTED), - errmsg("PCM waiter entry identity changed after wakeup"))); + ereport(ERROR, (errcode(ERRCODE_DATA_CORRUPTED), + errmsg("PCM waiter entry identity changed after wakeup"))); } /* loop and re-check master_state */ } } static bool -pcm_lock_acquire_local(BufferTag tag, PcmLockMode mode, - PcmAuthoritySnapshot *remote_x_out) +pcm_lock_acquire_local(BufferTag tag, PcmLockMode mode, PcmAuthoritySnapshot *remote_x_out) { PcmEntryWaitContext wait_context; PcmEntryAcquireResult acquire_result; @@ -8098,8 +7472,7 @@ pcm_lock_acquire_local(BufferTag tag, PcmLockMode mode, cluster_node_id))); memset(&wait_context, 0, sizeof(wait_context)); - if (!pcm_entry_ref_acquire(&tag, true, &wait_context.ref, - &acquire_result)) + if (!pcm_entry_ref_acquire(&tag, true, &wait_context.ref, &acquire_result)) ereport(ERROR, (errcode(ERRCODE_OUT_OF_MEMORY), errmsg("cluster_pcm_lock_acquire: PCM GRD entry unavailable " "(cap=%d result=%d)", @@ -8110,8 +7483,7 @@ pcm_lock_acquire_local(BufferTag tag, PcmLockMode mode, PG_TRY(); { - acquired = pcm_lock_acquire_local_pinned( - tag, mode, remote_x_out, &wait_context); + acquired = pcm_lock_acquire_local_pinned(tag, mode, remote_x_out, &wait_context); } PG_FINALLY(); { @@ -8334,11 +7706,10 @@ cluster_pcm_lock_acquire_buffer(BufferDesc *buf, PcmLockMode mode, bool *out_ret * boundary forces a fresh BufferDesc/GRD generation sample. */ have_authority = cluster_pcm_lock_authority_snapshot(tag, &authority); - remote_x_exact = have_authority && authority.state == PCM_STATE_X - && authority.x_holder_node >= 0 - && authority.x_holder_node != cluster_node_id - && authority.s_holders_bitmap == 0 - && authority.master_holder.node_id == (uint32)authority.x_holder_node; + remote_x_exact + = have_authority && authority.state == PCM_STATE_X && authority.x_holder_node >= 0 + && authority.x_holder_node != cluster_node_id && authority.s_holders_bitmap == 0 + && authority.master_holder.node_id == (uint32)authority.x_holder_node; s_barrier_active = cluster_gcs_block_resource_x_local_s_barrier_active(tag); if (s_barrier_active && !remote_x_exact) { *out_retry_denied = true; @@ -8346,8 +7717,8 @@ cluster_pcm_lock_acquire_buffer(BufferDesc *buf, PcmLockMode mode, bool *out_ret } if (remote_x_exact) - return cluster_gcs_local_master_read_image_and_wait( - buf, &authority, s_barrier_active, out_retry_denied); + return cluster_gcs_local_master_read_image_and_wait(buf, &authority, s_barrier_active, + out_retry_denied); } else /* mode == PCM_LOCK_MODE_X */ { /* @@ -8420,8 +7791,7 @@ cluster_pcm_lock_acquire_buffer(BufferDesc *buf, PcmLockMode mode, bool *out_ret "retry the statement."))); } - if (pcm_entry_ref_acquire( - &tag, false, &entry_ref, &acquire_result)) { + if (pcm_entry_ref_acquire(&tag, false, &entry_ref, &acquire_result)) { entry = entry_ref.entry; pcm_entry_lock_exclusive(entry); /* Amendment v1.2 (R9): the completed S->X upgrade replaces @@ -8452,8 +7822,8 @@ cluster_pcm_lock_acquire_buffer(BufferDesc *buf, PcmLockMode mode, bool *out_ret if (!pcm_lock_acquire_local(tag, mode, &raced_remote_x)) { if (mode == PCM_LOCK_MODE_S) - return cluster_gcs_local_master_read_image_and_wait(buf, &raced_remote_x, - cluster_gcs_block_resource_x_local_s_barrier_active(tag), + return cluster_gcs_local_master_read_image_and_wait( + buf, &raced_remote_x, cluster_gcs_block_resource_x_local_s_barrier_active(tag), out_retry_denied); return cluster_gcs_local_master_x_transfer_and_wait(buf, &raced_remote_x, clean_eligible, out_retry_denied); @@ -8519,8 +7889,7 @@ cluster_pcm_lock_release(BufferTag tag) "PGRAC_NODE=%d PGRAC_ATTEMPT=0 ", cluster_node_id))); - if (!pcm_entry_ref_acquire( - &tag, false, &entry_ref, &acquire_result)) + if (!pcm_entry_ref_acquire(&tag, false, &entry_ref, &acquire_result)) ereport(ERROR, (errcode(ERRCODE_DATA_CORRUPTED), errmsg("cluster_pcm_lock_release: no PCM entry for BufferTag (released " "without prior acquire?)"), @@ -8610,8 +7979,8 @@ cluster_pcm_lock_release(BufferTag tag) ConditionVariableBroadcast(&entry->wait_cv); pcm_entry_ref_release(&entry_ref); if (fast_retire) - (void)pcm_entry_try_retire_exact( - &retire_tag, retire_generation, PCM_RETIRE_REASON_HOLDER_RELEASE); + (void)pcm_entry_try_retire_exact(&retire_tag, retire_generation, + PCM_RETIRE_REASON_HOLDER_RELEASE); } @@ -8671,11 +8040,9 @@ cluster_pcm_lock_release_saved_tag_for_eviction(BufferTag tag, PcmLockMode mode) * after the wait could mistake a concurrent rebind for this release. */ if (mode == PCM_LOCK_MODE_S && pcm_entry_ref_acquire(&tag, false, &local_projection_ref, - &local_projection_result)) - { + &local_projection_result)) { local_projection_tag = local_projection_ref.tag; - local_projection_generation - = local_projection_ref.binding_generation; + local_projection_generation = local_projection_ref.binding_generation; pcm_entry_ref_release(&local_projection_ref); } @@ -8701,8 +8068,7 @@ cluster_pcm_lock_release_saved_tag_for_eviction(BufferTag tag, PcmLockMode mode) return; } - if (mode == PCM_LOCK_MODE_S) - { + if (mode == PCM_LOCK_MODE_S) { /* * PGRAC adaptation: a remote X->S downgrade is deliberately * fire-and-forget. Cache replacement is the last local owner of @@ -8718,22 +8084,20 @@ cluster_pcm_lock_release_saved_tag_for_eviction(BufferTag tag, PcmLockMode mode) */ if (!PCM_GCS_TRY_SENDER_LINKED()) ereport(ERROR, - (errcode(ERRCODE_INTERNAL_ERROR), - errmsg("remote-S eviction lacks its GCS predecessor settlement owner"))); - (void) cluster_gcs_try_send_transition_and_wait( - tag, PCM_TRANS_X_TO_S_DOWNGRADE, master_node); + (errcode(ERRCODE_INTERNAL_ERROR), + errmsg("remote-S eviction lacks its GCS predecessor settlement owner"))); + (void)cluster_gcs_try_send_transition_and_wait(tag, PCM_TRANS_X_TO_S_DOWNGRADE, + master_node); trans = PCM_TRANS_S_TO_N_RELEASE; - } - else if (mode == PCM_LOCK_MODE_X) + } else if (mode == PCM_LOCK_MODE_X) trans = PCM_TRANS_X_TO_N_RELEASE; else return; /* nothing to release from the remote master */ cluster_gcs_send_transition_and_wait(tag, trans, master_node); if (mode == PCM_LOCK_MODE_S && local_projection_generation != 0) - (void)pcm_entry_try_retire_exact( - &local_projection_tag, local_projection_generation, - PCM_RETIRE_REASON_HOLDER_RELEASE); + (void)pcm_entry_try_retire_exact(&local_projection_tag, local_projection_generation, + PCM_RETIRE_REASON_HOLDER_RELEASE); return; } @@ -8825,8 +8189,7 @@ cluster_pcm_lock_upgrade(BufferTag tag) "PGRAC_NODE=%d PGRAC_ATTEMPT=0 ", cluster_node_id))); - if (!pcm_entry_ref_acquire( - &tag, false, &entry_ref, &acquire_result)) + if (!pcm_entry_ref_acquire(&tag, false, &entry_ref, &acquire_result)) ereport(ERROR, (errcode(ERRCODE_DATA_CORRUPTED), errmsg("cluster_pcm_lock_upgrade: no PCM entry for BufferTag (must " "acquire S first)"), @@ -8927,8 +8290,7 @@ cluster_pcm_lock_downgrade(BufferTag tag, PcmLockMode target_mode, bool keep_pi) "PGRAC_NODE=%d PGRAC_ATTEMPT=0 ", cluster_node_id))); - if (!pcm_entry_ref_acquire( - &tag, false, &entry_ref, &acquire_result)) + if (!pcm_entry_ref_acquire(&tag, false, &entry_ref, &acquire_result)) ereport(ERROR, (errcode(ERRCODE_DATA_CORRUPTED), errmsg("cluster_pcm_lock_downgrade: no PCM entry for BufferTag (must " "acquire X first)"), @@ -9021,8 +8383,7 @@ cluster_pcm_lock_query(BufferTag tag) if (cluster_pcm_htab == NULL) return PCM_LOCK_MODE_N; - if (!pcm_entry_ref_acquire( - &tag, false, &entry_ref, &acquire_result)) + if (!pcm_entry_ref_acquire(&tag, false, &entry_ref, &acquire_result)) return PCM_LOCK_MODE_N; entry = entry_ref.entry; @@ -9074,30 +8435,20 @@ cluster_pcm_grd_lifecycle_stats_snapshot(PcmGrdLifecycleStats *out) return; LWLockAcquire(&ClusterPcm->htab_lock.lock, LW_SHARED); - out->live_entries = pg_atomic_read_u64( - &ClusterPcm->resource_x_reconfig_slot_count); - out->tombstone_slots = pg_atomic_read_u64( - &ClusterPcm->reclaim_tombstone_count); - next_binding_generation = pg_atomic_read_u64( - &ClusterPcm->next_binding_generation); + out->live_entries = pg_atomic_read_u64(&ClusterPcm->resource_x_reconfig_slot_count); + out->tombstone_slots = pg_atomic_read_u64(&ClusterPcm->reclaim_tombstone_count); + next_binding_generation = pg_atomic_read_u64(&ClusterPcm->next_binding_generation); if (next_binding_generation > 1) - out->binding_generation = next_binding_generation == UINT64_MAX - ? UINT64_MAX - 1 : next_binding_generation - 1; - out->reclaim_attempt_count = pg_atomic_read_u64( - &ClusterPcm->reclaim_attempt_count); - out->reclaim_success_count = pg_atomic_read_u64( - &ClusterPcm->reclaim_success_count); - out->reclaim_reuse_count = pg_atomic_read_u64( - &ClusterPcm->reclaim_reuse_count); - out->capacity_retry_count = pg_atomic_read_u64( - &ClusterPcm->reclaim_capacity_retry_count); - out->capacity_fail_count = pg_atomic_read_u64( - &ClusterPcm->reclaim_capacity_fail_count); - out->peak_live_entries = pg_atomic_read_u64( - &ClusterPcm->reclaim_peak_live_entries); + out->binding_generation + = next_binding_generation == UINT64_MAX ? UINT64_MAX - 1 : next_binding_generation - 1; + out->reclaim_attempt_count = pg_atomic_read_u64(&ClusterPcm->reclaim_attempt_count); + out->reclaim_success_count = pg_atomic_read_u64(&ClusterPcm->reclaim_success_count); + out->reclaim_reuse_count = pg_atomic_read_u64(&ClusterPcm->reclaim_reuse_count); + out->capacity_retry_count = pg_atomic_read_u64(&ClusterPcm->reclaim_capacity_retry_count); + out->capacity_fail_count = pg_atomic_read_u64(&ClusterPcm->reclaim_capacity_fail_count); + out->peak_live_entries = pg_atomic_read_u64(&ClusterPcm->reclaim_peak_live_entries); for (refusal = 0; refusal < PCM_RETIRE_REFUSAL_N; refusal++) - out->reclaim_refused[refusal] = pg_atomic_read_u64( - &ClusterPcm->reclaim_refused[refusal]); + out->reclaim_refused[refusal] = pg_atomic_read_u64(&ClusterPcm->reclaim_refused[refusal]); LWLockRelease(&ClusterPcm->htab_lock.lock); } @@ -9330,7 +8681,7 @@ cluster_pcm_normal_stop_pi_retire(BufferTag *tag_out, uint32 *slot_out, const ch * diagnostic counters are never inputs to a stop decision. */ static bool pcm_resource_x_protocol_state_locked(struct GrdEntry *entry, bool *active_out, bool *retained_out, - bool durable_stop_cut) + bool durable_stop_cut) { ClusterPcmResourceXMasterState *state = NULL; ClusterPcmResourceXBootstrapRound *round; @@ -9445,8 +8796,8 @@ pcm_resource_x_protocol_state_locked(struct GrdEntry *entry, bool *active_out, b uint64 terminal_count = 0; uint64 digest = PGRAC_RESOURCE_X_PROOF_DIGEST_OFFSET; - if (!pcm_resource_x_terminal_state_locked(entry, state, true, true, durable_stop_cut, &terminal_count, - &digest)) + if (!pcm_resource_x_terminal_state_locked(entry, state, true, true, durable_stop_cut, + &terminal_count, &digest)) invalid = true; } } @@ -9559,8 +8910,7 @@ cluster_pcm_grd_shmem_size(void) */ sz = MAXALIGN(sizeof(ClusterPcmShared)); sz = add_size(sz, mul_size((Size)eff, sizeof(ClusterPcmResourceXSlot))); - sz = add_size(sz, mul_size((Size)eff, - sizeof(ClusterPcmResourceXMasterState))); + sz = add_size(sz, mul_size((Size)eff, sizeof(ClusterPcmResourceXMasterState))); sz = add_size(sz, mul_size(pcm_rx_trace_capacity(eff), sizeof(ResourceXTraceEvent))); sz = add_size(sz, hash_estimate_size((Size)eff, sizeof(struct GrdEntry))); return sz; @@ -9586,25 +8936,23 @@ cluster_pcm_grd_init(void) if (pcm_grd_effective == 0) return; header_size = add_size(MAXALIGN(sizeof(ClusterPcmShared)), - mul_size((Size)pcm_grd_effective, - sizeof(ClusterPcmResourceXSlot))); - header_size = add_size(header_size, - mul_size((Size)pcm_grd_effective, - sizeof(ClusterPcmResourceXMasterState))); - header_size = add_size(header_size, - mul_size(pcm_rx_trace_capacity(pcm_grd_effective), sizeof(ResourceXTraceEvent))); + mul_size((Size)pcm_grd_effective, sizeof(ClusterPcmResourceXSlot))); + header_size = add_size( + header_size, mul_size((Size)pcm_grd_effective, sizeof(ClusterPcmResourceXMasterState))); + header_size = add_size(header_size, mul_size(pcm_rx_trace_capacity(pcm_grd_effective), + sizeof(ResourceXTraceEvent))); pgstat_report_wait_start(WAIT_EVENT_PCM_GRD_INIT); - ClusterPcm = (ClusterPcmShared *)ShmemInitStruct("pgrac cluster pcm grd hdr", - header_size, &found); - cluster_pcm_resource_x_slots = (ClusterPcmResourceXSlot *) - ((char *)ClusterPcm + MAXALIGN(sizeof(ClusterPcmShared))); - cluster_pcm_resource_x_master_states = (ClusterPcmResourceXMasterState *) - ((char *)cluster_pcm_resource_x_slots - + mul_size((Size)pcm_grd_effective, - sizeof(ClusterPcmResourceXSlot))); - pcm_rx_trace_events = (ResourceXTraceEvent *) - (cluster_pcm_resource_x_master_states + pcm_grd_effective); + ClusterPcm + = (ClusterPcmShared *)ShmemInitStruct("pgrac cluster pcm grd hdr", header_size, &found); + cluster_pcm_resource_x_slots + = (ClusterPcmResourceXSlot *)((char *)ClusterPcm + MAXALIGN(sizeof(ClusterPcmShared))); + cluster_pcm_resource_x_master_states + = (ClusterPcmResourceXMasterState *)((char *)cluster_pcm_resource_x_slots + + mul_size((Size)pcm_grd_effective, + sizeof(ClusterPcmResourceXSlot))); + pcm_rx_trace_events + = (ResourceXTraceEvent *)(cluster_pcm_resource_x_master_states + pcm_grd_effective); if (!found) { /* @@ -9643,10 +8991,8 @@ cluster_pcm_grd_init(void) pg_atomic_init_u64(&ClusterPcm->block0_reply_wait_count[site][metric], 0); LWLockInitialize(&ClusterPcm->htab_lock.lock, LWTRANCHE_CLUSTER_PCM); pg_atomic_init_u64(&ClusterPcm->next_binding_generation, 1); - pg_atomic_init_u64( - &ClusterPcm->resource_x_retired_authority_floor, 0); - pg_atomic_init_u64( - &ClusterPcm->resource_x_bootstrap_next_attempt, 1); + pg_atomic_init_u64(&ClusterPcm->resource_x_retired_authority_floor, 0); + pg_atomic_init_u64(&ClusterPcm->resource_x_bootstrap_next_attempt, 1); pg_atomic_init_u32(&ClusterPcm->reclaim_requested, 0); pg_atomic_init_u64(&ClusterPcm->reclaim_scan_cursor, 0); pg_atomic_init_u64(&ClusterPcm->reclaim_attempt_count, 0); @@ -9657,8 +9003,7 @@ cluster_pcm_grd_init(void) pg_atomic_init_u64(&ClusterPcm->reclaim_peak_live_entries, 0); pg_atomic_init_u64(&ClusterPcm->reclaim_tombstone_count, 0); for (refusal = 0; refusal < PCM_RETIRE_REFUSAL_N; refusal++) - pg_atomic_init_u64( - &ClusterPcm->reclaim_refused[refusal], 0); + pg_atomic_init_u64(&ClusterPcm->reclaim_refused[refusal], 0); pg_atomic_init_u32(&ClusterPcm->resource_x_gate_phase, RESOURCE_X_GATE_OPEN); pg_atomic_init_u64(&ClusterPcm->resource_x_gate_formation, 0); pg_atomic_init_u64(&ClusterPcm->resource_x_freeze_generation, 0); @@ -9672,19 +9017,13 @@ cluster_pcm_grd_init(void) pg_atomic_init_u64(&ClusterPcm->resource_x_reconfig_residual_count, 0); pg_atomic_init_u64(&ClusterPcm->resource_x_semantic_mutation_sequence, 1); pg_atomic_init_u32(&ClusterPcm->resource_x_reconfig_proof_pass, 0); - pg_atomic_init_u64( - &ClusterPcm->resource_x_reconfig_proof_begin_sequence, 0); - pg_atomic_init_u64( - &ClusterPcm->resource_x_reconfig_proof_begin_slot_count, 0); + pg_atomic_init_u64(&ClusterPcm->resource_x_reconfig_proof_begin_sequence, 0); + pg_atomic_init_u64(&ClusterPcm->resource_x_reconfig_proof_begin_slot_count, 0); pg_atomic_init_u64(&ClusterPcm->resource_x_reconfig_proof_digest, 0); - pg_atomic_init_u64( - &ClusterPcm->resource_x_reconfig_proof_empty_slot_count, 0); - pg_atomic_init_u64( - &ClusterPcm->resource_x_reconfig_proof_successor_slot_count, 0); - pg_atomic_init_u64( - &ClusterPcm->resource_x_reconfig_proof_terminal_slot_count, 0); - pg_atomic_init_u64( - &ClusterPcm->resource_x_reconfig_proof_retry_revisit_count, 0); + pg_atomic_init_u64(&ClusterPcm->resource_x_reconfig_proof_empty_slot_count, 0); + pg_atomic_init_u64(&ClusterPcm->resource_x_reconfig_proof_successor_slot_count, 0); + pg_atomic_init_u64(&ClusterPcm->resource_x_reconfig_proof_terminal_slot_count, 0); + pg_atomic_init_u64(&ClusterPcm->resource_x_reconfig_proof_retry_revisit_count, 0); pg_atomic_init_u64(&ClusterPcm->resource_x_reconfig_freeze_count, 0); pg_atomic_init_u64(&ClusterPcm->resource_x_reconfig_slot_examined_count, 0); pg_atomic_init_u64(&ClusterPcm->resource_x_reconfig_old_detached_count, 0); @@ -9707,14 +9046,10 @@ cluster_pcm_grd_init(void) pg_atomic_init_u32(&ClusterPcm->resource_x_intent_generation_exhausted, 0); pg_atomic_init_u64(&ClusterPcm->resource_x_o1_remote_install_observed_count, 0); pg_atomic_init_u64(&ClusterPcm->resource_x_o1_remote_grant_after_image_count, 0); - pg_atomic_init_u64( - &ClusterPcm->resource_x_o1_remote_image_at_or_after_grant_count, 0); - pg_atomic_init_u64( - &ClusterPcm->resource_x_o1_remote_episode_excluded_no_install, 0); - pg_atomic_init_u64( - &ClusterPcm->resource_x_o1_remote_episode_excluded_missing_grant, 0); - pg_atomic_init_u64( - &ClusterPcm->resource_x_o1_remote_episode_excluded_missing_image, 0); + pg_atomic_init_u64(&ClusterPcm->resource_x_o1_remote_image_at_or_after_grant_count, 0); + pg_atomic_init_u64(&ClusterPcm->resource_x_o1_remote_episode_excluded_no_install, 0); + pg_atomic_init_u64(&ClusterPcm->resource_x_o1_remote_episode_excluded_missing_grant, 0); + pg_atomic_init_u64(&ClusterPcm->resource_x_o1_remote_episode_excluded_missing_image, 0); pg_atomic_init_u64(&ClusterPcm->resource_x_o1_last_remote_t_image_us, 0); pg_atomic_init_u64(&ClusterPcm->resource_x_o1_last_remote_t_grant_us, 0); pg_atomic_init_u64(&ClusterPcm->resource_x_o1_last_remote_t_install_us, 0); @@ -9776,8 +9111,8 @@ pcm_entry_binding_generation_next(uint64 *generation_out) for (;;) { if (current == 0 || current == UINT64_MAX) return false; - if (pg_atomic_compare_exchange_u64( - &ClusterPcm->next_binding_generation, ¤t, current + 1)) { + if (pg_atomic_compare_exchange_u64(&ClusterPcm->next_binding_generation, ¤t, + current + 1)) { *generation_out = current; return true; } @@ -9790,19 +9125,16 @@ pcm_entry_binding_generation_next(uint64 *generation_out) * per-entry floor remains an exact lower bound for an already-live resource; * the shared allocator is a stronger monotonic namespace, not authority. */ static bool -pcm_resource_x_bootstrap_attempt_allocate( - uint64 attempt_floor, uint64 *attempt_out) +pcm_resource_x_bootstrap_attempt_allocate(uint64 attempt_floor, uint64 *attempt_out) { uint64 candidate; uint64 current; if (attempt_out != NULL) *attempt_out = 0; - if (ClusterPcm == NULL || attempt_out == NULL - || attempt_floor == UINT64_MAX) + if (ClusterPcm == NULL || attempt_out == NULL || attempt_floor == UINT64_MAX) return false; - current = pg_atomic_read_u64( - &ClusterPcm->resource_x_bootstrap_next_attempt); + current = pg_atomic_read_u64(&ClusterPcm->resource_x_bootstrap_next_attempt); for (;;) { if (current == 0 || current == UINT64_MAX) return false; @@ -9811,9 +9143,8 @@ pcm_resource_x_bootstrap_attempt_allocate( candidate = attempt_floor + 1; if (candidate == UINT64_MAX) return false; - if (pg_atomic_compare_exchange_u64( - &ClusterPcm->resource_x_bootstrap_next_attempt, - ¤t, candidate + 1)) { + if (pg_atomic_compare_exchange_u64(&ClusterPcm->resource_x_bootstrap_next_attempt, ¤t, + candidate + 1)) { *attempt_out = candidate; return true; } @@ -9821,8 +9152,7 @@ pcm_resource_x_bootstrap_attempt_allocate( } static bool -pcm_entry_pin_under_htab_lock(struct GrdEntry *entry, - PcmEntryAcquireResult *result) +pcm_entry_pin_under_htab_lock(struct GrdEntry *entry, PcmEntryAcquireResult *result) { ClusterPcmResourceXMasterState *state; ClusterPcmResourceXSlot *slot; @@ -9832,10 +9162,8 @@ pcm_entry_pin_under_htab_lock(struct GrdEntry *entry, Assert(entry != NULL); Assert(result != NULL); Assert(LWLockHeldByMeInMode(&ClusterPcm->htab_lock.lock, LW_SHARED) - || LWLockHeldByMeInMode(&ClusterPcm->htab_lock.lock, - LW_EXCLUSIVE)); - if (entry->registry_slot >= (uint32)pcm_grd_effective - || cluster_pcm_resource_x_slots == NULL + || LWLockHeldByMeInMode(&ClusterPcm->htab_lock.lock, LW_EXCLUSIVE)); + if (entry->registry_slot >= (uint32)pcm_grd_effective || cluster_pcm_resource_x_slots == NULL || cluster_pcm_resource_x_master_states == NULL) { pcm_resource_x_reconfig_block(); *result = PCM_ENTRY_ACQUIRE_CORRUPT; @@ -9858,8 +9186,7 @@ pcm_entry_pin_under_htab_lock(struct GrdEntry *entry, return false; } if (lifecycle == PCM_ENTRY_QUIESCING) { - if (!pg_atomic_compare_exchange_u32( - &entry->lifecycle, &lifecycle, PCM_ENTRY_LIVE)) { + if (!pg_atomic_compare_exchange_u32(&entry->lifecycle, &lifecycle, PCM_ENTRY_LIVE)) { if (lifecycle == PCM_ENTRY_RETIRING) { *result = PCM_ENTRY_ACQUIRE_RETRY_CURRENT; return false; @@ -9883,8 +9210,7 @@ pcm_entry_pin_under_htab_lock(struct GrdEntry *entry, *result = PCM_ENTRY_ACQUIRE_CORRUPT; return false; } - if (pg_atomic_compare_exchange_u32( - &entry->pin_count, &pins, pins + 1)) + if (pg_atomic_compare_exchange_u32(&entry->pin_count, &pins, pins + 1)) break; } *result = PCM_ENTRY_ACQUIRE_OK; @@ -9892,8 +9218,7 @@ pcm_entry_pin_under_htab_lock(struct GrdEntry *entry, } static struct GrdEntry * -pcm_get_or_create_entry_under_htab_lock(BufferTag tag, - PcmEntryAcquireResult *result) +pcm_get_or_create_entry_under_htab_lock(BufferTag tag, PcmEntryAcquireResult *result) { ClusterPcmResourceXMasterState *master_state; ClusterPcmResourceXSlot *registry_slot; @@ -9914,14 +9239,12 @@ pcm_get_or_create_entry_under_htab_lock(BufferTag tag, Assert(result != NULL); Assert(LWLockHeldByMeInMode(&ClusterPcm->htab_lock.lock, LW_EXCLUSIVE)); *result = PCM_ENTRY_ACQUIRE_CORRUPT; - entry = (struct GrdEntry *)hash_search( - cluster_pcm_htab, &tag, HASH_FIND, &found); + entry = (struct GrdEntry *)hash_search(cluster_pcm_htab, &tag, HASH_FIND, &found); if (found && entry != NULL) { *result = PCM_ENTRY_ACQUIRE_OK; return entry; } - if (pg_atomic_read_u32(&ClusterPcm->resource_x_gate_phase) - != RESOURCE_X_GATE_OPEN) { + if (pg_atomic_read_u32(&ClusterPcm->resource_x_gate_phase) != RESOURCE_X_GATE_OPEN) { *result = PCM_ENTRY_ACQUIRE_RETRY_CURRENT; return NULL; } @@ -9948,8 +9271,7 @@ pcm_get_or_create_entry_under_htab_lock(BufferTag tag, slot_found = true; break; } - if (registry_slot->state != PCM_REGISTRY_LIVE - || registry_slot->reserved != 0 + if (registry_slot->state != PCM_REGISTRY_LIVE || registry_slot->reserved != 0 || registry_slot->binding_generation == 0 || registry_slot->binding_generation == UINT64_MAX || registry_slot->retired_authority_generation != 0 @@ -9969,12 +9291,9 @@ pcm_get_or_create_entry_under_htab_lock(BufferTag tag, } registry_slot = &cluster_pcm_resource_x_slots[slot_index]; slot_reused = registry_slot->state == PCM_REGISTRY_TOMBSTONE; - retired_authority_generation - = slot_reused ? registry_slot->retired_authority_generation : 0; - retired_authority_floor = pg_atomic_read_u64( - &ClusterPcm->resource_x_retired_authority_floor); - if (slot_reused - && pg_atomic_read_u64(&ClusterPcm->reclaim_tombstone_count) == 0) { + retired_authority_generation = slot_reused ? registry_slot->retired_authority_generation : 0; + retired_authority_floor = pg_atomic_read_u64(&ClusterPcm->resource_x_retired_authority_floor); + if (slot_reused && pg_atomic_read_u64(&ClusterPcm->reclaim_tombstone_count) == 0) { pcm_resource_x_reconfig_block(); *result = PCM_ENTRY_ACQUIRE_CORRUPT; return NULL; @@ -9989,31 +9308,25 @@ pcm_get_or_create_entry_under_htab_lock(BufferTag tag, *result = PCM_ENTRY_ACQUIRE_CORRUPT; return NULL; } - initial_authority_generation = retired_authority_floor == 0 - ? 1 : retired_authority_floor + 1; + initial_authority_generation = retired_authority_floor == 0 ? 1 : retired_authority_floor + 1; if (slot_reused) { - if (retired_authority_generation == 0 - || retired_authority_generation >= UINT64_MAX - 1) { + if (retired_authority_generation == 0 || retired_authority_generation >= UINT64_MAX - 1) { pcm_resource_x_reconfig_block(); *result = PCM_ENTRY_ACQUIRE_CORRUPT; return NULL; } - if (initial_authority_generation - < retired_authority_generation + 1) - initial_authority_generation - = retired_authority_generation + 1; + if (initial_authority_generation < retired_authority_generation + 1) + initial_authority_generation = retired_authority_generation + 1; if (initial_authority_generation < binding_generation) initial_authority_generation = binding_generation; } - if (initial_authority_generation == 0 - || initial_authority_generation == UINT64_MAX + if (initial_authority_generation == 0 || initial_authority_generation == UINT64_MAX || !pcm_entry_lifecycle_mutation_mark()) { pcm_resource_x_reconfig_block(); *result = PCM_ENTRY_ACQUIRE_CORRUPT; return NULL; } - entry = (struct GrdEntry *)hash_search( - cluster_pcm_htab, &tag, HASH_ENTER_NULL, &found); + entry = (struct GrdEntry *)hash_search(cluster_pcm_htab, &tag, HASH_ENTER_NULL, &found); if (entry == NULL) { *result = PCM_ENTRY_ACQUIRE_NO_CAPACITY; return NULL; @@ -10033,8 +9346,7 @@ pcm_get_or_create_entry_under_htab_lock(BufferTag tag, * the matching pre-transition baseline so its first N->X remains the * direct predecessor of the new Resource-X authority generation. A * first-generation binding still starts at zero. */ - pg_atomic_init_u64(&entry->transition_count_local, - initial_authority_generation - 1); + pg_atomic_init_u64(&entry->transition_count_local, initial_authority_generation - 1); entry->s_holder_refcount_local = 0; entry->pending_x_requester_node = -1; entry->pending_x_since_lsn = 0; @@ -10044,8 +9356,7 @@ pcm_get_or_create_entry_under_htab_lock(BufferTag tag, entry->resource_x_progress_flags = 0; entry->resource_x_formation = 0; entry->resource_x_acquisition_generation = 0; - entry->resource_x_requester_base_generation - = initial_authority_generation; + entry->resource_x_requester_base_generation = initial_authority_generation; entry->resource_x_retired_acquisition_generation = 0; entry->resource_x_no_progress_generation = 0; entry->resource_x_no_progress_reason = RESOURCE_X_NO_PROGRESS_NONE; @@ -10067,20 +9378,15 @@ pcm_get_or_create_entry_under_htab_lock(BufferTag tag, registry_slot->binding_generation = binding_generation; registry_slot->retired_authority_generation = 0; if (slot_reused) - pg_atomic_fetch_sub_u64( - &ClusterPcm->reclaim_tombstone_count, 1); + pg_atomic_fetch_sub_u64(&ClusterPcm->reclaim_tombstone_count, 1); if (slot_reused) - pg_atomic_fetch_add_u64( - &ClusterPcm->reclaim_reuse_count, 1); + pg_atomic_fetch_add_u64(&ClusterPcm->reclaim_reuse_count, 1); pg_write_barrier(); registry_slot->state = PCM_REGISTRY_LIVE; - live_slots = pg_atomic_fetch_add_u64( - &ClusterPcm->resource_x_reconfig_slot_count, 1) + 1; - pcm_atomic_max_u64( - &ClusterPcm->reclaim_peak_live_entries, live_slots); + live_slots = pg_atomic_fetch_add_u64(&ClusterPcm->resource_x_reconfig_slot_count, 1) + 1; + pcm_atomic_max_u64(&ClusterPcm->reclaim_peak_live_entries, live_slots); if (live_slots * UINT64_C(100) - >= (uint64)pcm_grd_effective - * (uint64)PCM_GRD_RECLAIM_SOFT_PERCENT) + >= (uint64)pcm_grd_effective * (uint64)PCM_GRD_RECLAIM_SOFT_PERCENT) pcm_entry_reclaim_request(); ConditionVariableInit(&entry->wait_cv); LWLockInitialize(&entry->entry_lock.lock, LWTRANCHE_CLUSTER_PCM); @@ -10090,8 +9396,8 @@ pcm_get_or_create_entry_under_htab_lock(BufferTag tag, } bool -pcm_entry_ref_acquire(const BufferTag *tag, bool create, - PcmEntryRef *out, PcmEntryAcquireResult *result) +pcm_entry_ref_acquire(const BufferTag *tag, bool create, PcmEntryRef *out, + PcmEntryAcquireResult *result) { PcmReclaimBatch reclaim_batch; struct GrdEntry *entry; @@ -10110,8 +9416,7 @@ pcm_entry_ref_acquire(const BufferTag *tag, bool create, } LWLockAcquire(&ClusterPcm->htab_lock.lock, LW_SHARED); - entry = (struct GrdEntry *)hash_search( - cluster_pcm_htab, tag, HASH_FIND, &found); + entry = (struct GrdEntry *)hash_search(cluster_pcm_htab, tag, HASH_FIND, &found); if (found && entry != NULL) { if (!pcm_entry_pin_under_htab_lock(entry, result)) { LWLockRelease(&ClusterPcm->htab_lock.lock); @@ -10137,19 +9442,14 @@ pcm_entry_ref_acquire(const BufferTag *tag, bool create, entry = pcm_get_or_create_entry_under_htab_lock(*tag, result); if (entry == NULL) { LWLockRelease(&ClusterPcm->htab_lock.lock); - if (*result == PCM_ENTRY_ACQUIRE_NO_CAPACITY - && !capacity_retried) { + if (*result == PCM_ENTRY_ACQUIRE_NO_CAPACITY && !capacity_retried) { capacity_retried = true; - pg_atomic_fetch_add_u64( - &ClusterPcm->reclaim_capacity_retry_count, 1); - (void)cluster_pcm_lock_reclaim_bounded( - PCM_GRD_SYNC_RECLAIM_BUDGET, &reclaim_batch); + pg_atomic_fetch_add_u64(&ClusterPcm->reclaim_capacity_retry_count, 1); + (void)cluster_pcm_lock_reclaim_bounded(PCM_GRD_SYNC_RECLAIM_BUDGET, &reclaim_batch); goto retry_create; } - if (*result == PCM_ENTRY_ACQUIRE_NO_CAPACITY - && capacity_retried) - pg_atomic_fetch_add_u64( - &ClusterPcm->reclaim_capacity_fail_count, 1); + if (*result == PCM_ENTRY_ACQUIRE_NO_CAPACITY && capacity_retried) + pg_atomic_fetch_add_u64(&ClusterPcm->reclaim_capacity_fail_count, 1); return false; } if (!pcm_entry_pin_under_htab_lock(entry, result)) { @@ -10178,40 +9478,34 @@ pcm_entry_ref_release(PcmEntryRef *ref) || entry->binding_generation != ref->binding_generation || entry->registry_slot != ref->registry_slot) { pcm_resource_x_reconfig_block(); - ereport(ERROR, - (errcode(ERRCODE_DATA_CORRUPTED), - errmsg("PCM entry ref identity changed while pinned"))); + ereport(ERROR, (errcode(ERRCODE_DATA_CORRUPTED), + errmsg("PCM entry ref identity changed while pinned"))); } pins = pg_atomic_read_u32(&entry->pin_count); for (;;) { if (pins == 0) { pcm_resource_x_reconfig_block(); ereport(ERROR, - (errcode(ERRCODE_DATA_CORRUPTED), - errmsg("PCM entry pin count underflow"))); + (errcode(ERRCODE_DATA_CORRUPTED), errmsg("PCM entry pin count underflow"))); } next_pins = pins - 1; - if (pg_atomic_compare_exchange_u32( - &entry->pin_count, &pins, next_pins)) + if (pg_atomic_compare_exchange_u32(&entry->pin_count, &pins, next_pins)) break; } - if (next_pins == 0 - && pg_atomic_read_u32(&entry->lifecycle) == PCM_ENTRY_QUIESCING) + if (next_pins == 0 && pg_atomic_read_u32(&entry->lifecycle) == PCM_ENTRY_QUIESCING) pcm_entry_reclaim_request(); memset(ref, 0, sizeof(*ref)); } bool -pcm_entry_transport_ref_begin(const PcmEntryRef *entry_ref, - PcmEntryTransportRef *transport_ref) +pcm_entry_transport_ref_begin(const PcmEntryRef *entry_ref, PcmEntryTransportRef *transport_ref) { struct GrdEntry *entry; uint32 refs; if (transport_ref != NULL) memset(transport_ref, 0, sizeof(*transport_ref)); - if (entry_ref == NULL || transport_ref == NULL - || !pcm_entry_ref_identity_exact(entry_ref)) + if (entry_ref == NULL || transport_ref == NULL || !pcm_entry_ref_identity_exact(entry_ref)) return false; entry = entry_ref->entry; refs = pg_atomic_read_u32(&entry->transport_refcount); @@ -10220,8 +9514,7 @@ pcm_entry_transport_ref_begin(const PcmEntryRef *entry_ref, pcm_resource_x_reconfig_block(); return false; } - if (pg_atomic_compare_exchange_u32( - &entry->transport_refcount, &refs, refs + 1)) + if (pg_atomic_compare_exchange_u32(&entry->transport_refcount, &refs, refs + 1)) break; } transport_ref->entry = entry; @@ -10238,27 +9531,23 @@ pcm_entry_transport_ref_end(PcmEntryTransportRef *transport_ref) struct GrdEntry *entry; uint32 refs; - Assert(transport_ref != NULL && transport_ref->held - && transport_ref->entry != NULL); + Assert(transport_ref != NULL && transport_ref->held && transport_ref->entry != NULL); entry = transport_ref->entry; if (!BufferTagsEqual(&entry->tag, &transport_ref->tag) || entry->binding_generation != transport_ref->binding_generation || entry->registry_slot != transport_ref->registry_slot) { pcm_resource_x_reconfig_block(); - ereport(ERROR, - (errcode(ERRCODE_DATA_CORRUPTED), - errmsg("PCM transport entry identity changed while retained"))); + ereport(ERROR, (errcode(ERRCODE_DATA_CORRUPTED), + errmsg("PCM transport entry identity changed while retained"))); } refs = pg_atomic_read_u32(&entry->transport_refcount); for (;;) { if (refs == 0) { pcm_resource_x_reconfig_block(); - ereport(ERROR, - (errcode(ERRCODE_DATA_CORRUPTED), - errmsg("PCM entry transport reference count underflow"))); + ereport(ERROR, (errcode(ERRCODE_DATA_CORRUPTED), + errmsg("PCM entry transport reference count underflow"))); } - if (pg_atomic_compare_exchange_u32( - &entry->transport_refcount, &refs, refs - 1)) + if (pg_atomic_compare_exchange_u32(&entry->transport_refcount, &refs, refs - 1)) break; } memset(transport_ref, 0, sizeof(*transport_ref)); @@ -10276,15 +9565,13 @@ pcm_resource_x_master_state_for_entry(const struct GrdEntry *entry) * and could mistake another resource's retire publication window for * corruption of this pinned resource. */ if (entry == NULL || cluster_pcm_resource_x_slots == NULL - || cluster_pcm_resource_x_master_states == NULL - || pcm_grd_effective <= 0 + || cluster_pcm_resource_x_master_states == NULL || pcm_grd_effective <= 0 || entry->registry_slot >= (uint32)pcm_grd_effective) return NULL; slot = &cluster_pcm_resource_x_slots[entry->registry_slot]; state = &cluster_pcm_resource_x_master_states[entry->registry_slot]; if (slot->state != PCM_REGISTRY_LIVE || slot->reserved != 0 - || !BufferTagsEqual(&slot->tag, &entry->tag) - || slot->binding_generation == 0 + || !BufferTagsEqual(&slot->tag, &entry->tag) || slot->binding_generation == 0 || slot->binding_generation == UINT64_MAX || slot->binding_generation != entry->binding_generation || slot->retired_authority_generation != 0 @@ -10294,16 +9581,13 @@ pcm_resource_x_master_state_for_entry(const struct GrdEntry *entry) } static ClusterPcmResourceXMasterRequest * -pcm_resource_x_master_head(ClusterPcmResourceXMasterState *state, - int32 *requester_node_out) +pcm_resource_x_master_head(ClusterPcmResourceXMasterState *state, int32 *requester_node_out) { ClusterPcmResourceXMasterRequest *head = NULL; int32 requester_node; - for (requester_node = 0; requester_node < RESOURCE_X_PROTOCOL_NODE_LIMIT; - requester_node++) { - ClusterPcmResourceXMasterRequest *candidate - = &state->requests[requester_node]; + for (requester_node = 0; requester_node < RESOURCE_X_PROTOCOL_NODE_LIMIT; requester_node++) { + ClusterPcmResourceXMasterRequest *candidate = &state->requests[requester_node]; if (candidate->phase == RESOURCE_X_MASTER_NONE || candidate->phase == RESOURCE_X_MASTER_SETTLED @@ -10342,8 +9626,7 @@ pcm_resource_x_s_barrier_active_locked(struct GrdEntry *entry) Assert(entry != NULL); state = pcm_resource_x_master_state_for_entry(entry); if (state == NULL || state->authority_generation == 0 - || state->authority_generation == UINT64_MAX - || state->next_enqueue_order == 0 + || state->authority_generation == UINT64_MAX || state->next_enqueue_order == 0 || state->next_enqueue_order == UINT64_MAX) { active = true; goto out; @@ -10353,41 +9636,34 @@ pcm_resource_x_s_barrier_active_locked(struct GrdEntry *entry) goto out; gate_phase = pg_atomic_read_u32(&ClusterPcm->resource_x_gate_phase); - gate_formation - = pg_atomic_read_u64(&ClusterPcm->resource_x_gate_formation); + gate_formation = pg_atomic_read_u64(&ClusterPcm->resource_x_gate_formation); if (head_node < 0 || head_node >= RESOURCE_X_PROTOCOL_NODE_LIMIT - || head->base_authority_generation == 0 - || head->base_authority_generation == UINT64_MAX - || head->resource_formation == 0 - || head->resource_formation == UINT64_MAX - || head->master_session_incarnation == 0 - || head->master_session_incarnation == UINT64_MAX - || head->assertion_sequence == 0 - || head->assertion_sequence == UINT64_MAX - || head->enqueue_order == 0 - || head->enqueue_order == UINT64_MAX - || gate_phase != RESOURCE_X_GATE_OPEN - || gate_formation != head->resource_formation) { + || head->base_authority_generation == 0 || head->base_authority_generation == UINT64_MAX + || head->resource_formation == 0 || head->resource_formation == UINT64_MAX + || head->master_session_incarnation == 0 || head->master_session_incarnation == UINT64_MAX + || head->assertion_sequence == 0 || head->assertion_sequence == UINT64_MAX + || head->enqueue_order == 0 || head->enqueue_order == UINT64_MAX + || gate_phase != RESOURCE_X_GATE_OPEN || gate_formation != head->resource_formation) { active = true; goto out; } switch (head->phase) { - case RESOURCE_X_MASTER_QUEUED: - case RESOURCE_X_MASTER_WAIT_BLOCKERS: - case RESOURCE_X_MASTER_WAIT_PROOF: - case RESOURCE_X_MASTER_GRANT_COMMITTED: - case RESOURCE_X_MASTER_RECOVERY_BLOCKED: - active = true; - break; - case RESOURCE_X_MASTER_NONE: - case RESOURCE_X_MASTER_SETTLED: - case RESOURCE_X_MASTER_RELEASED: - default: - /* NONE/terminal cannot be selected as head; reaching one here is + case RESOURCE_X_MASTER_QUEUED: + case RESOURCE_X_MASTER_WAIT_BLOCKERS: + case RESOURCE_X_MASTER_WAIT_PROOF: + case RESOURCE_X_MASTER_GRANT_COMMITTED: + case RESOURCE_X_MASTER_RECOVERY_BLOCKED: + active = true; + break; + case RESOURCE_X_MASTER_NONE: + case RESOURCE_X_MASTER_SETTLED: + case RESOURCE_X_MASTER_RELEASED: + default: + /* NONE/terminal cannot be selected as head; reaching one here is * therefore corruption and remains fail closed. */ - active = true; - break; + active = true; + break; } out: @@ -10404,8 +9680,7 @@ cluster_pcm_lock_resource_x_s_barrier_active_exact(const BufferTag *tag) if (tag == NULL || ClusterPcm == NULL) return false; - if (!pcm_entry_ref_acquire( - tag, false, &entry_ref, &acquire_result)) + if (!pcm_entry_ref_acquire(tag, false, &entry_ref, &acquire_result)) return false; entry = entry_ref.entry; @@ -10417,8 +9692,7 @@ cluster_pcm_lock_resource_x_s_barrier_active_exact(const BufferTag *tag) } bool -cluster_pcm_lock_resource_x_requester_s_barrier_active_exact( - const BufferTag *tag) +cluster_pcm_lock_resource_x_requester_s_barrier_active_exact(const BufferTag *tag) { ClusterPcmResourceXBootstrapRound *round; PcmEntryRef entry_ref; @@ -10435,27 +9709,24 @@ cluster_pcm_lock_resource_x_requester_s_barrier_active_exact( LWLockAcquire(&entry->entry_lock.lock, LW_SHARED); round = &entry->resource_x_bootstrap_round; switch (round->phase) { - case RESOURCE_X_BOOTSTRAP_ROUND_EMPTY: - case RESOURCE_X_BOOTSTRAP_ROUND_FAILED_CLOSED: - active = false; - break; - case RESOURCE_X_BOOTSTRAP_ROUND_TERMINAL_X_CACHED: - /* A terminal phase opens S admission only when the retained round + case RESOURCE_X_BOOTSTRAP_ROUND_EMPTY: + case RESOURCE_X_BOOTSTRAP_ROUND_FAILED_CLOSED: + active = false; + break; + case RESOURCE_X_BOOTSTRAP_ROUND_TERMINAL_X_CACHED: + /* A terminal phase opens S admission only when the retained round * still proves the exact local cached-X cover. Malformed terminal * state remains a conservative retry barrier. */ - active - = !pcm_resource_x_bootstrap_round_terminal_cover_exact_locked( - entry, round, &round->terminal_ref, - round->master_session_incarnation, - round->r4_record_generation, - round->cached_ownership_generation); - break; - case RESOURCE_X_BOOTSTRAP_ROUND_REQUEST_DISPATCHED: - case RESOURCE_X_BOOTSTRAP_ROUND_BASE_BOUND: - case RESOURCE_X_BOOTSTRAP_ROUND_ASSERT_DISPATCHED: - default: - active = true; - break; + active = !pcm_resource_x_bootstrap_round_terminal_cover_exact_locked( + entry, round, &round->terminal_ref, round->master_session_incarnation, + round->r4_record_generation, round->cached_ownership_generation); + break; + case RESOURCE_X_BOOTSTRAP_ROUND_REQUEST_DISPATCHED: + case RESOURCE_X_BOOTSTRAP_ROUND_BASE_BOUND: + case RESOURCE_X_BOOTSTRAP_ROUND_ASSERT_DISPATCHED: + default: + active = true; + break; } LWLockRelease(&entry->entry_lock.lock); pcm_entry_ref_release(&entry_ref); @@ -10463,8 +9734,7 @@ cluster_pcm_lock_resource_x_requester_s_barrier_active_exact( } static ClusterPcmResourceXMasterRequest * -pcm_resource_x_start_head_locked(struct GrdEntry *entry, - ClusterPcmResourceXMasterState *state, +pcm_resource_x_start_head_locked(struct GrdEntry *entry, ClusterPcmResourceXMasterState *state, int32 *requester_node_out) { ClusterPcmResourceXMasterRequest *request; @@ -10479,8 +9749,7 @@ pcm_resource_x_start_head_locked(struct GrdEntry *entry, if (request == NULL) return NULL; if (request->phase == RESOURCE_X_MASTER_QUEUED) { - request->head_transition_generation - = pg_atomic_read_u64(&entry->transition_count_local); + request->head_transition_generation = pg_atomic_read_u64(&entry->transition_count_local); if (request->head_transition_generation == UINT64_MAX) { request->phase = RESOURCE_X_MASTER_RECOVERY_BLOCKED; goto done; @@ -10491,14 +9760,13 @@ pcm_resource_x_start_head_locked(struct GrdEntry *entry, incompatible = UINT32_C(1) << (uint32)entry->x_holder_node; else if (pcm_state == PCM_STATE_S) incompatible = pg_atomic_read_u32(&entry->s_holders_bitmap) - & ~(UINT32_C(1) << (uint32)requester_node); + & ~(UINT32_C(1) << (uint32)requester_node); request->incompatible_holders_bitmap = incompatible; request->blocked_holders_bitmap = 0; - request->phase = incompatible != 0 ? RESOURCE_X_MASTER_WAIT_BLOCKERS - : RESOURCE_X_MASTER_WAIT_PROOF; + request->phase + = incompatible != 0 ? RESOURCE_X_MASTER_WAIT_BLOCKERS : RESOURCE_X_MASTER_WAIT_PROOF; if (incompatible != 0 - && !pcm_resource_x_arm_block_intents_locked( - entry, state, request, requester_node)) + && !pcm_resource_x_arm_block_intents_locked(entry, state, request, requester_node)) request->phase = RESOURCE_X_MASTER_RECOVERY_BLOCKED; } done: @@ -10536,52 +9804,43 @@ pcm_resource_x_master_snapshot(const BufferTag *tag, int32 requester_node, out->phase = request->phase; out->proof_kind = request->proof_kind; out->source_disposition = request->source_disposition; - (void)pcm_resource_x_master_head((ClusterPcmResourceXMasterState *)state, - &head_node); + (void)pcm_resource_x_master_head((ClusterPcmResourceXMasterState *)state, &head_node); out->is_head = head_node == requester_node ? 1 : 0; } static bool -pcm_resource_x_terminal_tombstone_valid( - const ClusterPcmResourceXTerminalTombstone *tombstone) +pcm_resource_x_terminal_tombstone_valid(const ClusterPcmResourceXTerminalTombstone *tombstone) { - return tombstone != NULL && tombstone->valid == 1 - && tombstone->requester_node >= 0 - && tombstone->requester_node < RESOURCE_X_PROTOCOL_NODE_LIMIT - && (tombstone->request.phase == RESOURCE_X_MASTER_SETTLED - || tombstone->request.phase == RESOURCE_X_MASTER_RELEASED); + return tombstone != NULL && tombstone->valid == 1 && tombstone->requester_node >= 0 + && tombstone->requester_node < RESOURCE_X_PROTOCOL_NODE_LIMIT + && (tombstone->request.phase == RESOURCE_X_MASTER_SETTLED + || tombstone->request.phase == RESOURCE_X_MASTER_RELEASED); } static void -pcm_resource_x_terminal_tombstone_snapshot( - const BufferTag *tag, const ClusterPcmResourceXMasterState *state, - const ClusterPcmResourceXTerminalTombstone *tombstone, - ResourceXMasterSnapshot *out) +pcm_resource_x_terminal_tombstone_snapshot(const BufferTag *tag, + const ClusterPcmResourceXMasterState *state, + const ClusterPcmResourceXTerminalTombstone *tombstone, + ResourceXMasterSnapshot *out) { Assert(pcm_resource_x_terminal_tombstone_valid(tombstone)); - pcm_resource_x_master_snapshot(tag, tombstone->requester_node, state, - &tombstone->request, out); + pcm_resource_x_master_snapshot(tag, tombstone->requester_node, state, &tombstone->request, out); if (out != NULL) out->is_head = 0; } static bool -pcm_resource_x_assert_common_matches_request( - const ResourceXDecodedCommon *common, - const ClusterPcmResourceXMasterRequest *request) +pcm_resource_x_assert_common_matches_request(const ResourceXDecodedCommon *common, + const ClusterPcmResourceXMasterRequest *request) { return common != NULL && request != NULL - && common->base_authority_generation - == request->base_authority_generation - && common->authority_generation - == request->base_authority_generation - && common->resource_formation == request->resource_formation - && common->master_session_incarnation - == request->master_session_incarnation - && common->assertion_sequence == request->assertion_sequence - && common->ordered_lane == request->ordered_lane - && common->sender_connection_generation - == request->sender_connection_generation; + && common->base_authority_generation == request->base_authority_generation + && common->authority_generation == request->base_authority_generation + && common->resource_formation == request->resource_formation + && common->master_session_incarnation == request->master_session_incarnation + && common->assertion_sequence == request->assertion_sequence + && common->ordered_lane == request->ordered_lane + && common->sender_connection_generation == request->sender_connection_generation; } static bool @@ -10589,18 +9848,16 @@ pcm_resource_x_assert_frame_valid(const ResourceXDecodedFrame *frame, int32 authenticated_source_node) { return frame != NULL && frame->kind == RESOURCE_X_WIRE_ASSERT_X - && resource_x_assertion_valid(&frame->common.logical_assertion) - && authenticated_source_node == frame->common.logical_assertion.requester_node - && frame->common.action_node == authenticated_source_node - && frame->common.base_authority_generation != 0 - && frame->common.authority_generation - == frame->common.base_authority_generation - && frame->common.resource_formation != 0 - && frame->common.master_session_incarnation != 0 - && frame->common.assertion_sequence != 0 - && frame->common.sender_connection_generation != 0 - && frame->common.target_mode == (uint8)PCM_STATE_X - && frame->common.outcome == RESOURCE_X_OUTCOME_NONE; + && resource_x_assertion_valid(&frame->common.logical_assertion) + && authenticated_source_node == frame->common.logical_assertion.requester_node + && frame->common.action_node == authenticated_source_node + && frame->common.base_authority_generation != 0 + && frame->common.authority_generation == frame->common.base_authority_generation + && frame->common.resource_formation != 0 && frame->common.master_session_incarnation != 0 + && frame->common.assertion_sequence != 0 + && frame->common.sender_connection_generation != 0 + && frame->common.target_mode == (uint8)PCM_STATE_X + && frame->common.outcome == RESOURCE_X_OUTCOME_NONE; } static void @@ -10611,11 +9868,9 @@ pcm_resource_x_common_copy(ResourceXDecodedCommon *destination, Assert(source != NULL); memset(destination, 0, sizeof(*destination)); destination->logical_assertion = source->logical_assertion; - destination->base_authority_generation - = source->base_authority_generation; + destination->base_authority_generation = source->base_authority_generation; destination->resource_formation = source->resource_formation; - destination->master_session_incarnation - = source->master_session_incarnation; + destination->master_session_incarnation = source->master_session_incarnation; destination->assertion_sequence = source->assertion_sequence; destination->ordered_lane = source->ordered_lane; destination->action_node = source->action_node; @@ -10623,8 +9878,7 @@ pcm_resource_x_common_copy(ResourceXDecodedCommon *destination, destination->target_mode = source->target_mode; destination->source_candidate = source->source_candidate; destination->retain_pi_if_dirty = source->retain_pi_if_dirty; - destination->sender_connection_generation - = source->sender_connection_generation; + destination->sender_connection_generation = source->sender_connection_generation; destination->outcome = source->outcome; destination->flags = source->flags; destination->authority_generation = source->authority_generation; @@ -10632,9 +9886,8 @@ pcm_resource_x_common_copy(ResourceXDecodedCommon *destination, } static void -pcm_resource_x_bootstrap_round_dispatch_snapshot( - const ClusterPcmResourceXBootstrapRound *round, - ResourceXDecodedFrame *dispatch_out) +pcm_resource_x_bootstrap_round_dispatch_snapshot(const ClusterPcmResourceXBootstrapRound *round, + ResourceXDecodedFrame *dispatch_out) { Assert(round != NULL); Assert(dispatch_out != NULL); @@ -10645,9 +9898,8 @@ pcm_resource_x_bootstrap_round_dispatch_snapshot( } static void -pcm_resource_x_bootstrap_round_assertion_snapshot( - const ClusterPcmResourceXBootstrapRound *round, - ResourceXDecodedFrame *dispatch_out) +pcm_resource_x_bootstrap_round_assertion_snapshot(const ClusterPcmResourceXBootstrapRound *round, + ResourceXDecodedFrame *dispatch_out) { Assert(round != NULL); Assert(dispatch_out != NULL); @@ -10658,9 +9910,8 @@ pcm_resource_x_bootstrap_round_assertion_snapshot( } static bool -pcm_resource_x_bootstrap_round_ack_matches_request( - const ResourceXDecodedFrame *ack, - const ClusterPcmResourceXBootstrapRound *round) +pcm_resource_x_bootstrap_round_ack_matches_request(const ResourceXDecodedFrame *ack, + const ClusterPcmResourceXBootstrapRound *round) { const ResourceXDecodedCommon *request; const ResourceXDecodedCommon *common; @@ -10670,28 +9921,20 @@ pcm_resource_x_bootstrap_round_ack_matches_request( request = &round->request; common = &ack->common; return ack->kind == RESOURCE_X_WIRE_PREASSERT_BOOTSTRAP - && ack->payload_bytes == RESOURCE_X_CONTROL_V1_BYTES - && !ack->blocked_has_remote_proof - && resource_x_assertion_equal(&common->logical_assertion, - &request->logical_assertion) - && common->base_authority_generation != 0 - && common->base_authority_generation != UINT64_MAX - && common->resource_formation == request->resource_formation - && common->master_session_incarnation - == request->master_session_incarnation - && common->assertion_sequence == request->assertion_sequence - && common->ordered_lane == 0 - && common->action_node - == request->logical_assertion.requester_node - && common->observed_mode == (uint8)PCM_STATE_N - && common->target_mode == (uint8)PCM_STATE_X - && common->source_candidate == 0 - && common->retain_pi_if_dirty == 0 - && common->sender_connection_generation != 0 - && common->sender_connection_generation != UINT32_MAX - && common->outcome == RESOURCE_X_OUTCOME_OK - && common->flags == 0 - && common->authority_generation == 0; + && ack->payload_bytes == RESOURCE_X_CONTROL_V1_BYTES && !ack->blocked_has_remote_proof + && resource_x_assertion_equal(&common->logical_assertion, &request->logical_assertion) + && common->base_authority_generation != 0 + && common->base_authority_generation != UINT64_MAX + && common->resource_formation == request->resource_formation + && common->master_session_incarnation == request->master_session_incarnation + && common->assertion_sequence == request->assertion_sequence && common->ordered_lane == 0 + && common->action_node == request->logical_assertion.requester_node + && common->observed_mode == (uint8)PCM_STATE_N + && common->target_mode == (uint8)PCM_STATE_X && common->source_candidate == 0 + && common->retain_pi_if_dirty == 0 && common->sender_connection_generation != 0 + && common->sender_connection_generation != UINT32_MAX + && common->outcome == RESOURCE_X_OUTCOME_OK && common->flags == 0 + && common->authority_generation == 0; } static bool @@ -11455,10 +10698,9 @@ pcm_resource_x_head_margin_note(const ClusterPcmResourceXBootstrapRound *round, } static void -pcm_rx_trace_head(const ClusterPcmResourceXBootstrapRound *round, uint32 flags, - uint64 now_us) +pcm_rx_trace_head(const ClusterPcmResourceXBootstrapRound *round, uint32 flags, uint64 now_us) { - ResourceXTraceEvent event = {0}; + ResourceXTraceEvent event = { 0 }; if (ClusterPcm == NULL || pg_atomic_read_u64(&ClusterPcm->trace_active_epoch) == 0) return; @@ -11483,7 +10725,7 @@ pcm_rx_trace_head(const ClusterPcmResourceXBootstrapRound *round, uint32 flags, static void pcm_rx_trace_join(const ClusterPcmResourceXBootstrapRound *round, uint64 now_us) { - ResourceXTraceEvent event = {0}; + ResourceXTraceEvent event = { 0 }; if (ClusterPcm == NULL || pg_atomic_read_u64(&ClusterPcm->trace_active_epoch) == 0) return; @@ -11607,8 +10849,7 @@ pcm_resource_x_head_progress_ref_locked(struct GrdEntry *entry, const ResourceXA } static void -pcm_resource_x_bootstrap_round_clear_binding_locked( - ClusterPcmResourceXBootstrapRound *round) +pcm_resource_x_bootstrap_round_clear_binding_locked(ClusterPcmResourceXBootstrapRound *round) { uint64 highest_attempt_floor; uint64 failed_attempt_floor; @@ -12295,14 +11536,11 @@ cluster_pcm_lock_resource_x_caller_observe_exact(const ResourceXAssertion *asser static bool pcm_resource_x_bootstrap_failed_round_rearmable_locked( struct GrdEntry *entry, const ClusterPcmResourceXBootstrapRound *round, - const ResourceXAssertion *assertion, int32 current_master_node, - uint64 resource_formation, uint64 master_session_incarnation, - uint64 r4_record_generation, - uint32 requester_sender_connection_generation, - uint32 master_ingress_connection_generation, + const ResourceXAssertion *assertion, int32 current_master_node, uint64 resource_formation, + uint64 master_session_incarnation, uint64 r4_record_generation, + uint32 requester_sender_connection_generation, uint32 master_ingress_connection_generation, uint64 absolute_deadline_us, uint64 now_us, uint64 retry_slice_us, - uint64 direct_init_ownership_generation, - uint64 direct_init_reservation_token) + uint64 direct_init_ownership_generation, uint64 direct_init_reservation_token) { static const ResourceXAcquisitionRef empty_ref; static const ResourceXDecodedCommon empty_common; @@ -12364,18 +11602,15 @@ pcm_resource_x_bootstrap_failed_round_rearmable_locked( pre_ack = round->accepted_base == 0; if (pre_ack) - return memcmp(&round->ack, &empty_common, - sizeof(empty_common)) == 0 - && memcmp(&round->assertion, &empty_common, - sizeof(empty_common)) == 0; + return memcmp(&round->ack, &empty_common, sizeof(empty_common)) == 0 + && memcmp(&round->assertion, &empty_common, sizeof(empty_common)) == 0; if (round->accepted_base == UINT64_MAX) return false; memset(&ack_frame, 0, sizeof(ack_frame)); ack_frame.kind = RESOURCE_X_WIRE_PREASSERT_BOOTSTRAP; ack_frame.payload_bytes = RESOURCE_X_CONTROL_V1_BYTES; ack_frame.common = round->ack; - if (!pcm_resource_x_bootstrap_round_ack_matches_request( - &ack_frame, round) + if (!pcm_resource_x_bootstrap_round_ack_matches_request(&ack_frame, round) || round->ack.base_authority_generation != round->accepted_base) return false; pcm_resource_x_common_copy(&expected_assertion, request); @@ -12384,109 +11619,85 @@ pcm_resource_x_bootstrap_failed_round_rearmable_locked( expected_assertion.outcome = RESOURCE_X_OUTCOME_NONE; expected_assertion.flags = 0; expected_assertion.semantic_crc32c = 0; - return pcm_resource_x_common_equal( - &round->assertion, &expected_assertion); + return pcm_resource_x_common_equal(&round->assertion, &expected_assertion); } static bool -pcm_resource_x_acquisition_ref_equal( - const ResourceXAcquisitionRef *left, - const ResourceXAcquisitionRef *right) +pcm_resource_x_acquisition_ref_equal(const ResourceXAcquisitionRef *left, + const ResourceXAcquisitionRef *right) { return left != NULL && right != NULL - && resource_x_assertion_equal(&left->assertion, &right->assertion) - && left->formation == right->formation - && left->acquisition_generation == right->acquisition_generation; + && resource_x_assertion_equal(&left->assertion, &right->assertion) + && left->formation == right->formation + && left->acquisition_generation == right->acquisition_generation; } static bool pcm_resource_x_bootstrap_round_terminal_cover_exact_locked( - struct GrdEntry *entry, - const ClusterPcmResourceXBootstrapRound *round, - const ResourceXAcquisitionRef *ref, - uint64 master_session_incarnation, uint64 r4_record_generation, - uint64 cached_ownership_generation) + struct GrdEntry *entry, const ClusterPcmResourceXBootstrapRound *round, + const ResourceXAcquisitionRef *ref, uint64 master_session_incarnation, + uint64 r4_record_generation, uint64 cached_ownership_generation) { Assert(entry != NULL); Assert(round != NULL); Assert(LWLockHeldByMeInMode(&entry->entry_lock.lock, LW_SHARED) || LWLockHeldByMeInMode(&entry->entry_lock.lock, LW_EXCLUSIVE)); return round->phase == RESOURCE_X_BOOTSTRAP_ROUND_TERMINAL_X_CACHED - && pcm_resource_x_ref_valid(ref) - && pcm_resource_x_ref_valid(&round->terminal_ref) - && pcm_resource_x_acquisition_ref_equal(&round->terminal_ref, ref) - && resource_x_assertion_equal( - &round->request.logical_assertion, &ref->assertion) - && round->resource_formation == ref->formation - && round->master_session_incarnation - == master_session_incarnation - && round->r4_record_generation == r4_record_generation - && round->request.assertion_sequence - == ref->acquisition_generation - && round->highest_attempt_floor == ref->acquisition_generation - && round->terminal_authority_generation > round->accepted_base - && round->terminal_authority_generation != UINT64_MAX - && round->cached_ownership_generation - == cached_ownership_generation - && pcm_resource_x_active_empty_locked(entry) - && entry->resource_x_retired_acquisition_generation - == ref->acquisition_generation; + && pcm_resource_x_ref_valid(ref) && pcm_resource_x_ref_valid(&round->terminal_ref) + && pcm_resource_x_acquisition_ref_equal(&round->terminal_ref, ref) + && resource_x_assertion_equal(&round->request.logical_assertion, &ref->assertion) + && round->resource_formation == ref->formation + && round->master_session_incarnation == master_session_incarnation + && round->r4_record_generation == r4_record_generation + && round->request.assertion_sequence == ref->acquisition_generation + && round->highest_attempt_floor == ref->acquisition_generation + && round->terminal_authority_generation > round->accepted_base + && round->terminal_authority_generation != UINT64_MAX + && round->cached_ownership_generation == cached_ownership_generation + && pcm_resource_x_active_empty_locked(entry) + && entry->resource_x_retired_acquisition_generation == ref->acquisition_generation; } static bool -pcm_resource_x_local_owner_handle_valid( - const ResourceXLocalOwnerHandle *handle) -{ - return handle != NULL - && pcm_resource_x_ref_valid(&handle->ref) - && handle->master_session_incarnation != 0 - && handle->master_session_incarnation != UINT64_MAX - && handle->r4_record_generation != 0 - && handle->r4_record_generation != UINT64_MAX - && handle->buffer_ownership_generation != 0 - && handle->buffer_ownership_generation != UINT64_MAX - && handle->reservation_token != 0 - && handle->reservation_token != UINT64_MAX - && handle->owner_generation != 0 - && handle->owner_generation != UINT64_MAX - && handle->absolute_deadline_us != 0 - && handle->absolute_deadline_us != UINT64_MAX - && handle->owner_procno >= 0 - && handle->reserved == 0; +pcm_resource_x_local_owner_handle_valid(const ResourceXLocalOwnerHandle *handle) +{ + return handle != NULL && pcm_resource_x_ref_valid(&handle->ref) + && handle->master_session_incarnation != 0 + && handle->master_session_incarnation != UINT64_MAX && handle->r4_record_generation != 0 + && handle->r4_record_generation != UINT64_MAX && handle->buffer_ownership_generation != 0 + && handle->buffer_ownership_generation != UINT64_MAX && handle->reservation_token != 0 + && handle->reservation_token != UINT64_MAX && handle->owner_generation != 0 + && handle->owner_generation != UINT64_MAX && handle->absolute_deadline_us != 0 + && handle->absolute_deadline_us != UINT64_MAX && handle->owner_procno >= 0 + && handle->reserved == 0; } static bool -pcm_resource_x_local_owner_handle_equal( - const ResourceXLocalOwnerHandle *left, - const ResourceXLocalOwnerHandle *right) +pcm_resource_x_local_owner_handle_equal(const ResourceXLocalOwnerHandle *left, + const ResourceXLocalOwnerHandle *right) { return pcm_resource_x_local_owner_handle_valid(left) - && pcm_resource_x_local_owner_handle_valid(right) - && pcm_resource_x_acquisition_ref_equal(&left->ref, &right->ref) - && left->master_session_incarnation - == right->master_session_incarnation - && left->r4_record_generation == right->r4_record_generation - && left->buffer_ownership_generation - == right->buffer_ownership_generation - && left->reservation_token == right->reservation_token - && left->owner_generation == right->owner_generation - && left->absolute_deadline_us == right->absolute_deadline_us - && left->owner_procno == right->owner_procno; + && pcm_resource_x_local_owner_handle_valid(right) + && pcm_resource_x_acquisition_ref_equal(&left->ref, &right->ref) + && left->master_session_incarnation == right->master_session_incarnation + && left->r4_record_generation == right->r4_record_generation + && left->buffer_ownership_generation == right->buffer_ownership_generation + && left->reservation_token == right->reservation_token + && left->owner_generation == right->owner_generation + && left->absolute_deadline_us == right->absolute_deadline_us + && left->owner_procno == right->owner_procno; } static bool -pcm_resource_x_local_handoff_empty( - const ClusterPcmResourceXLocalHandoff *handoff) +pcm_resource_x_local_handoff_empty(const ClusterPcmResourceXLocalHandoff *handoff) { static const ClusterPcmResourceXLocalHandoff empty_handoff; - return handoff != NULL - && memcmp(handoff, &empty_handoff, sizeof(empty_handoff)) == 0; + return handoff != NULL && memcmp(handoff, &empty_handoff, sizeof(empty_handoff)) == 0; } static bool -pcm_resource_x_local_handoff_valid( - const ClusterPcmResourceXLocalHandoff *handoff) +pcm_resource_x_local_handoff_valid(const ClusterPcmResourceXLocalHandoff *handoff) { static const uint8 zero_reserved[7]; @@ -12514,25 +11725,19 @@ pcm_resource_x_local_handoff_valid( } static bool -pcm_resource_x_local_handoff_matches_handle( - const ClusterPcmResourceXLocalHandoff *handoff, - const ResourceXLocalOwnerHandle *handle) +pcm_resource_x_local_handoff_matches_handle(const ClusterPcmResourceXLocalHandoff *handoff, + const ResourceXLocalOwnerHandle *handle) { return pcm_resource_x_local_handoff_valid(handoff) - && pcm_resource_x_local_owner_handle_valid(handle) - && pcm_resource_x_acquisition_ref_equal( - &handoff->holder_ref, &handle->ref) - && handoff->master_session_incarnation - == handle->master_session_incarnation - && handoff->r4_record_generation - == handle->r4_record_generation - && handoff->buffer_ownership_generation - == handle->buffer_ownership_generation; + && pcm_resource_x_local_owner_handle_valid(handle) + && pcm_resource_x_acquisition_ref_equal(&handoff->holder_ref, &handle->ref) + && handoff->master_session_incarnation == handle->master_session_incarnation + && handoff->r4_record_generation == handle->r4_record_generation + && handoff->buffer_ownership_generation == handle->buffer_ownership_generation; } static bool -pcm_resource_x_local_owner_valid_locked( - const ClusterPcmResourceXLocalOwner *owner) +pcm_resource_x_local_owner_valid_locked(const ClusterPcmResourceXLocalOwner *owner) { static const ResourceXLocalOwnerHandle empty_handle; static const uint8 zero_reserved[3]; @@ -12552,12 +11757,10 @@ pcm_resource_x_local_owner_valid_locked( handoff_empty = pcm_resource_x_local_handoff_empty(&owner->handoff); handoff_valid = pcm_resource_x_local_handoff_valid(&owner->handoff); if (owner->state == RESOURCE_X_LOCAL_OWNER_EMPTY) - return memcmp(&owner->handle, &empty_handle, - sizeof(empty_handle)) == 0 && handoff_empty; + return memcmp(&owner->handle, &empty_handle, sizeof(empty_handle)) == 0 && handoff_empty; if (owner->state == RESOURCE_X_LOCAL_OWNER_HANDOFF) - return memcmp(&owner->handle, &empty_handle, - sizeof(empty_handle)) == 0 - && handoff_valid && owner->highest_owner_generation != 0; + return memcmp(&owner->handle, &empty_handle, sizeof(empty_handle)) == 0 && handoff_valid + && owner->highest_owner_generation != 0; if ((owner->state != RESOURCE_X_LOCAL_OWNER_RECYCLING && owner->state != RESOURCE_X_LOCAL_OWNER_REVOKING && owner->state != RESOURCE_X_LOCAL_OWNER_REVOKE_DEFERRED @@ -12569,8 +11772,7 @@ pcm_resource_x_local_owner_valid_locked( if (owner->state == RESOURCE_X_LOCAL_OWNER_REVOKE_DEFERRED) return pcm_resource_x_local_handoff_matches_handle(&owner->handoff, &owner->handle); return handoff_empty - || pcm_resource_x_local_handoff_matches_handle( - &owner->handoff, &owner->handle); + || pcm_resource_x_local_handoff_matches_handle(&owner->handoff, &owner->handle); } static void @@ -12589,32 +11791,24 @@ pcm_resource_x_local_owner_clear_locked(struct GrdEntry *entry) } static bool -pcm_resource_x_local_handoff_round_current_locked( - const ClusterPcmResourceXLocalHandoff *handoff, - const ClusterPcmResourceXBootstrapRound *round) +pcm_resource_x_local_handoff_round_current_locked(const ClusterPcmResourceXLocalHandoff *handoff, + const ClusterPcmResourceXBootstrapRound *round) { - return pcm_resource_x_local_handoff_valid(handoff) - && round != NULL - && round->phase == RESOURCE_X_BOOTSTRAP_ROUND_TERMINAL_X_CACHED - && pcm_resource_x_acquisition_ref_equal( - &handoff->holder_ref, &round->terminal_ref) - && handoff->base_authority_generation - == round->terminal_authority_generation - && handoff->master_session_incarnation - == round->master_session_incarnation - && handoff->r4_record_generation - == round->r4_record_generation - && handoff->buffer_ownership_generation - == round->cached_ownership_generation - && handoff->master_node == round->current_master_node; + return pcm_resource_x_local_handoff_valid(handoff) && round != NULL + && round->phase == RESOURCE_X_BOOTSTRAP_ROUND_TERMINAL_X_CACHED + && pcm_resource_x_acquisition_ref_equal(&handoff->holder_ref, &round->terminal_ref) + && handoff->base_authority_generation == round->terminal_authority_generation + && handoff->master_session_incarnation == round->master_session_incarnation + && handoff->r4_record_generation == round->r4_record_generation + && handoff->buffer_ownership_generation == round->cached_ownership_generation + && handoff->master_node == round->current_master_node; } static bool -pcm_resource_x_local_owner_round_exact_locked( - struct GrdEntry *entry, const ClusterPcmResourceXBootstrapRound *round) +pcm_resource_x_local_owner_round_exact_locked(struct GrdEntry *entry, + const ClusterPcmResourceXBootstrapRound *round) { - const ClusterPcmResourceXLocalOwner *owner - = &entry->resource_x_local_owner; + const ClusterPcmResourceXLocalOwner *owner = &entry->resource_x_local_owner; Assert(entry != NULL); Assert(round != NULL); @@ -12624,28 +11818,22 @@ pcm_resource_x_local_owner_round_exact_locked( || owner->state == RESOURCE_X_LOCAL_OWNER_EMPTY) return false; if (owner->state == RESOURCE_X_LOCAL_OWNER_HANDOFF) - return pcm_resource_x_local_handoff_round_current_locked( - &owner->handoff, round); - return pcm_resource_x_acquisition_ref_equal( - &owner->handle.ref, &round->terminal_ref) - && owner->handle.master_session_incarnation - == round->master_session_incarnation - && owner->handle.r4_record_generation - == round->r4_record_generation - && owner->handle.buffer_ownership_generation - == round->cached_ownership_generation; + return pcm_resource_x_local_handoff_round_current_locked(&owner->handoff, round); + return pcm_resource_x_acquisition_ref_equal(&owner->handle.ref, &round->terminal_ref) + && owner->handle.master_session_incarnation == round->master_session_incarnation + && owner->handle.r4_record_generation == round->r4_record_generation + && owner->handle.buffer_ownership_generation == round->cached_ownership_generation; } static bool pcm_resource_x_local_handoff_deadline(uint64 now_us, uint64 *deadline_out) { - uint64 budget_us = (uint64)Max(cluster_gcs_reply_timeout_ms, 1) - * UINT64_C(1000); + uint64 budget_us = (uint64)Max(cluster_gcs_reply_timeout_ms, 1) * UINT64_C(1000); if (deadline_out != NULL) *deadline_out = 0; - if (deadline_out == NULL || now_us == 0 || now_us == UINT64_MAX - || budget_us == 0 || now_us >= UINT64_MAX - budget_us) + if (deadline_out == NULL || now_us == 0 || now_us == UINT64_MAX || budget_us == 0 + || now_us >= UINT64_MAX - budget_us) return false; *deadline_out = now_us + budget_us; return *deadline_out != UINT64_MAX; @@ -12686,11 +11874,11 @@ pcm_resource_x_local_owner_expire_locked(struct GrdEntry *entry, uint64 now_us) } static bool -pcm_resource_x_local_handoff_successor_exact( - const ClusterPcmResourceXLocalHandoff *handoff, - const ResourceXDecodedFrame *successor_block, - int32 authenticated_master_node, uint64 r4_record_generation, - uint64 cached_ownership_generation) +pcm_resource_x_local_handoff_successor_exact(const ClusterPcmResourceXLocalHandoff *handoff, + const ResourceXDecodedFrame *successor_block, + int32 authenticated_master_node, + uint64 r4_record_generation, + uint64 cached_ownership_generation) { return pcm_resource_x_local_handoff_valid(handoff) && successor_block != NULL && resource_x_assertion_equal(&handoff->successor_assertion, @@ -12715,12 +11903,12 @@ pcm_resource_x_local_handoff_successor_exact( } static ResourceXApplyResult -pcm_resource_x_local_handoff_build_locked( - ClusterPcmResourceXLocalHandoff *handoff, - const ClusterPcmResourceXBootstrapRound *round, - const ResourceXDecodedFrame *successor_block, - int32 authenticated_master_node, uint64 r4_record_generation, - uint64 cached_ownership_generation, uint64 now_us) +pcm_resource_x_local_handoff_build_locked(ClusterPcmResourceXLocalHandoff *handoff, + const ClusterPcmResourceXBootstrapRound *round, + const ResourceXDecodedFrame *successor_block, + int32 authenticated_master_node, + uint64 r4_record_generation, + uint64 cached_ownership_generation, uint64 now_us) { uint64 deadline_us; @@ -12733,28 +11921,22 @@ pcm_resource_x_local_handoff_build_locked( /* This is the bounded local first-observation deadline. It is neither * copied from nor represented as the requester R7 deadline, and every * later claim/yield preserves this exact value. */ - handoff->successor_assertion - = successor_block->common.logical_assertion; + handoff->successor_assertion = successor_block->common.logical_assertion; handoff->holder_ref = round->terminal_ref; - handoff->base_authority_generation - = successor_block->common.base_authority_generation; + handoff->base_authority_generation = successor_block->common.base_authority_generation; handoff->delegated_authority_generation = successor_block->common.flags == RESOURCE_X_COMMON_FLAG_AUTHORITY_WITH_IMAGE ? successor_block->common.authority_generation : 0; - handoff->master_session_incarnation - = successor_block->common.master_session_incarnation; - handoff->assertion_sequence - = successor_block->common.assertion_sequence; + handoff->master_session_incarnation = successor_block->common.master_session_incarnation; + handoff->assertion_sequence = successor_block->common.assertion_sequence; handoff->r4_record_generation = r4_record_generation; - handoff->buffer_ownership_generation - = cached_ownership_generation; + handoff->buffer_ownership_generation = cached_ownership_generation; handoff->deadline_us = deadline_us; handoff->master_node = authenticated_master_node; handoff->ordered_lane = successor_block->common.ordered_lane; handoff->valid = 1; - if (!pcm_resource_x_local_handoff_round_current_locked( - handoff, round)) { + if (!pcm_resource_x_local_handoff_round_current_locked(handoff, round)) { memset(handoff, 0, sizeof(*handoff)); return RESOURCE_X_APPLY_RECOVERY_BLOCKED; } @@ -12780,13 +11962,11 @@ pcm_resource_x_local_handoff_freeze_locked(struct GrdEntry *entry, || !pcm_resource_x_local_handoff_empty(&owner->handoff)) return RESOURCE_X_APPLY_RECOVERY_BLOCKED; result = pcm_resource_x_local_handoff_build_locked( - &owner->handoff, round, successor_block, - authenticated_master_node, r4_record_generation, + &owner->handoff, round, successor_block, authenticated_master_node, r4_record_generation, cached_ownership_generation, now_us); if (result != RESOURCE_X_APPLY_APPLIED) return result; - if (!pcm_resource_x_local_handoff_matches_handle( - &owner->handoff, &owner->handle)) { + if (!pcm_resource_x_local_handoff_matches_handle(&owner->handoff, &owner->handle)) { memset(&owner->handoff, 0, sizeof(owner->handoff)); return RESOURCE_X_APPLY_RECOVERY_BLOCKED; } @@ -12796,12 +11976,13 @@ pcm_resource_x_local_handoff_freeze_locked(struct GrdEntry *entry, } static ResourceXApplyResult -pcm_resource_x_local_owner_claim_locked( - struct GrdEntry *entry, uint8 state, - const ResourceXAcquisitionRef *ref, - uint64 master_session_incarnation, uint64 r4_record_generation, - uint64 cached_ownership_generation, uint64 reservation_token, - int32 owner_procno, ResourceXLocalOwnerHandle *handle_out) +pcm_resource_x_local_owner_claim_locked(struct GrdEntry *entry, uint8 state, + const ResourceXAcquisitionRef *ref, + uint64 master_session_incarnation, + uint64 r4_record_generation, + uint64 cached_ownership_generation, + uint64 reservation_token, int32 owner_procno, + ResourceXLocalOwnerHandle *handle_out) { ClusterPcmResourceXLocalOwner *owner; @@ -12835,11 +12016,9 @@ pcm_resource_x_local_owner_claim_locked( return RESOURCE_X_APPLY_RECOVERY_BLOCKED; owner->highest_owner_generation++; owner->handle.ref = *ref; - owner->handle.master_session_incarnation - = master_session_incarnation; + owner->handle.master_session_incarnation = master_session_incarnation; owner->handle.r4_record_generation = r4_record_generation; - owner->handle.buffer_ownership_generation - = cached_ownership_generation; + owner->handle.buffer_ownership_generation = cached_ownership_generation; owner->handle.reservation_token = reservation_token; owner->handle.owner_generation = owner->highest_owner_generation; owner->handle.absolute_deadline_us @@ -12851,9 +12030,8 @@ pcm_resource_x_local_owner_claim_locked( } static ResourceXApplyResult -pcm_resource_x_local_owner_release_locked( - struct GrdEntry *entry, uint8 expected_state, - const ResourceXLocalOwnerHandle *handle) +pcm_resource_x_local_owner_release_locked(struct GrdEntry *entry, uint8 expected_state, + const ResourceXLocalOwnerHandle *handle) { ClusterPcmResourceXLocalOwner *owner; @@ -12870,8 +12048,7 @@ pcm_resource_x_local_owner_release_locked( if (owner->state == RESOURCE_X_LOCAL_OWNER_EMPTY) return RESOURCE_X_APPLY_NOT_FOUND; if (owner->state != expected_state - || !pcm_resource_x_local_owner_handle_equal( - &owner->handle, handle)) + || !pcm_resource_x_local_owner_handle_equal(&owner->handle, handle)) return RESOURCE_X_APPLY_STALE; pcm_resource_x_local_owner_clear_locked(entry); return RESOURCE_X_APPLY_APPLIED; @@ -12882,9 +12059,9 @@ pcm_resource_x_local_owner_release_locked( * the same round's retained T1/T2 (or exact retired) state under entry_lock * and install the terminal cover in the same transaction. */ static bool -pcm_resource_x_bootstrap_round_direct_init_handoff_locked( - struct GrdEntry *entry, ClusterPcmResourceXBootstrapRound *round, - uint64 cached_ownership_generation) +pcm_resource_x_bootstrap_round_direct_init_handoff_locked(struct GrdEntry *entry, + ClusterPcmResourceXBootstrapRound *round, + uint64 cached_ownership_generation) { ResourceXAcquisitionRef ref; PcmResourceXRefClass ref_class; @@ -12916,27 +12093,21 @@ pcm_resource_x_bootstrap_round_direct_init_handoff_locked( ref_class = pcm_resource_x_ref_classify_locked(entry, &ref); if (ref_class == PCM_RX_REF_ACTIVE_EXACT) { if (entry->resource_x_progress_flags - != (RESOURCE_X_PROGRESS_BOUND | RESOURCE_X_PROGRESS_T1 - | RESOURCE_X_PROGRESS_T2) + != (RESOURCE_X_PROGRESS_BOUND | RESOURCE_X_PROGRESS_T1 | RESOURCE_X_PROGRESS_T2) || entry->resource_x_no_progress_generation != 0 - || entry->resource_x_no_progress_reason - != RESOURCE_X_NO_PROGRESS_NONE) + || entry->resource_x_no_progress_reason != RESOURCE_X_NO_PROGRESS_NONE) return false; result = pcm_resource_x_requester_retirement_prepare_locked(entry, &ref, true, false, &witness, NULL); if (result != RESOURCE_X_APPLY_APPLIED - || !pcm_resource_x_requester_settlement_arm_locked( - entry, &ref, &witness)) + || !pcm_resource_x_requester_settlement_arm_locked(entry, &ref, &witness)) return false; - pcm_resource_x_requester_retirement_commit_locked( - entry, &ref, &witness); - } - else if (ref_class != PCM_RX_REF_RETIRED_EXACT) + pcm_resource_x_requester_retirement_commit_locked(entry, &ref, &witness); + } else if (ref_class != PCM_RX_REF_RETIRED_EXACT) return false; if (!pcm_resource_x_active_empty_locked(entry) - || entry->resource_x_retired_acquisition_generation - != ref.acquisition_generation) + || entry->resource_x_retired_acquisition_generation != ref.acquisition_generation) return false; round->terminal_ref = ref; round->terminal_authority_generation = round->accepted_base + 1; @@ -12945,8 +12116,8 @@ pcm_resource_x_bootstrap_round_direct_init_handoff_locked( if (!pcm_resource_x_head_changed_locked(entry, true, pcm_resource_x_monotonic_us())) return false; return pcm_resource_x_bootstrap_round_terminal_cover_exact_locked( - entry, round, &ref, round->master_session_incarnation, - round->r4_record_generation, cached_ownership_generation); + entry, round, &ref, round->master_session_incarnation, round->r4_record_generation, + cached_ownership_generation); } /* Only the serialized driver may dispose of an obsolete terminal binding. @@ -13068,10 +12239,8 @@ pcm_resource_x_bootstrap_round_step_internal( != master_ingress_connection_generation))) return RESOURCE_X_BOOTSTRAP_ROUND_FAIL_CLOSED; - if (!pcm_entry_ref_acquire(&assertion->resource, allow_create, - &entry_ref, &acquire_result)) { - if (allow_create - && acquire_result == PCM_ENTRY_ACQUIRE_NO_CAPACITY) + if (!pcm_entry_ref_acquire(&assertion->resource, allow_create, &entry_ref, &acquire_result)) { + if (allow_create && acquire_result == PCM_ENTRY_ACQUIRE_NO_CAPACITY) return RESOURCE_X_BOOTSTRAP_ROUND_BACKPRESSURE; return RESOURCE_X_BOOTSTRAP_ROUND_FAIL_CLOSED; } @@ -13132,8 +12301,7 @@ pcm_resource_x_bootstrap_round_step_internal( return RESOURCE_X_BOOTSTRAP_ROUND_WAIT; } pcm_resource_x_semantic_mutation_mark(); - if (!pcm_resource_x_local_owner_valid_locked( - &entry->resource_x_local_owner)) { + if (!pcm_resource_x_local_owner_valid_locked(&entry->resource_x_local_owner)) { if (round->phase != RESOURCE_X_BOOTSTRAP_ROUND_EMPTY) pcm_resource_x_head_fail_locked(entry, RESOURCE_X_HEAD_FAILURE_NONE); ConditionVariableBroadcast(&entry->wait_cv); @@ -13145,13 +12313,10 @@ pcm_resource_x_bootstrap_round_step_internal( * A caller joining this head cannot clear another owner's handoff. */ if (allow_create && !cached_local_x && pcm_resource_x_bootstrap_failed_round_rearmable_locked( - entry, round, assertion, current_master_node, - resource_formation, master_session_incarnation, - r4_record_generation, - requester_sender_connection_generation, - master_ingress_connection_generation, - absolute_deadline_us, now_us, retry_slice_us, - direct_init_ownership_generation, + entry, round, assertion, current_master_node, resource_formation, + master_session_incarnation, r4_record_generation, + requester_sender_connection_generation, master_ingress_connection_generation, + absolute_deadline_us, now_us, retry_slice_us, direct_init_ownership_generation, direct_init_reservation_token)) { pcm_resource_x_bootstrap_round_clear_binding_locked(round); broadcast = true; @@ -13264,12 +12429,9 @@ pcm_resource_x_bootstrap_round_step_internal( action = RESOURCE_X_BOOTSTRAP_ROUND_FAIL_CLOSED; } else { attempt_floor = round->highest_attempt_floor; - if (attempt_floor - < entry->resource_x_retired_acquisition_generation) - attempt_floor - = entry->resource_x_retired_acquisition_generation; - if (!pcm_resource_x_bootstrap_attempt_allocate( - attempt_floor, &attempt_sequence)) { + if (attempt_floor < entry->resource_x_retired_acquisition_generation) + attempt_floor = entry->resource_x_retired_acquisition_generation; + if (!pcm_resource_x_bootstrap_attempt_allocate(attempt_floor, &attempt_sequence)) { action = RESOURCE_X_BOOTSTRAP_ROUND_FAIL_CLOSED; } else { failed_attempt_floor = round->failed_attempt_floor; @@ -13279,8 +12441,7 @@ pcm_resource_x_bootstrap_round_step_internal( round->cancelled_attempt_floor = cancelled_attempt_floor; round->highest_attempt_floor = attempt_sequence; round->resource_formation = resource_formation; - round->master_session_incarnation - = master_session_incarnation; + round->master_session_incarnation = master_session_incarnation; round->r4_record_generation = r4_record_generation; round->head_no_progress_budget_us = head_no_progress_budget_us; round->last_dispatch_us = now_us; @@ -13288,8 +12449,7 @@ pcm_resource_x_bootstrap_round_step_internal( round->current_master_node = current_master_node; round->requester_sender_connection_generation = requester_sender_connection_generation; - round->master_ingress_connection_generation - = master_ingress_connection_generation; + round->master_ingress_connection_generation = master_ingress_connection_generation; round->install_claim_pending_generation = direct_init_ownership_generation; round->install_claim_reservation_token = direct_init_reservation_token; round->install_claim_source = direct_init_reservation_token == 0 @@ -13299,10 +12459,8 @@ pcm_resource_x_bootstrap_round_step_internal( cluster_pcm_rx_metric_note(PCM_RX_CLAIM_BIND); round->request.logical_assertion = *assertion; round->request.resource_formation = resource_formation; - round->request.master_session_incarnation - = master_session_incarnation; - round->request.assertion_sequence - = round->highest_attempt_floor; + round->request.master_session_incarnation = master_session_incarnation; + round->request.assertion_sequence = round->highest_attempt_floor; round->request.action_node = assertion->requester_node; round->request.observed_mode = (uint8)PCM_STATE_N; round->request.target_mode = (uint8)PCM_STATE_X; @@ -13311,11 +12469,9 @@ pcm_resource_x_bootstrap_round_step_internal( round->request.outcome = RESOURCE_X_OUTCOME_NONE; round->request.flags = allow_remote_admission ? RESOURCE_X_COMMON_FLAG_REMOTE_ADMISSION : 0; - round->phase - = RESOURCE_X_BOOTSTRAP_ROUND_REQUEST_DISPATCHED; + round->phase = RESOURCE_X_BOOTSTRAP_ROUND_REQUEST_DISPATCHED; (void)pcm_resource_x_head_changed_locked(entry, true, now_us); - pcm_resource_x_bootstrap_round_dispatch_snapshot( - round, dispatch_out); + pcm_resource_x_bootstrap_round_dispatch_snapshot(round, dispatch_out); action = RESOURCE_X_BOOTSTRAP_ROUND_DISPATCH_REQUEST; } } @@ -13374,15 +12530,12 @@ pcm_resource_x_bootstrap_round_step_internal( diagnostic_accepted_base = round->accepted_base; diagnostic_r4_record_generation = round->r4_record_generation; diagnostic_resource_formation = round->resource_formation; - diagnostic_master_session_incarnation - = round->master_session_incarnation; + diagnostic_master_session_incarnation = round->master_session_incarnation; diagnostic_last_dispatch_us = round->last_dispatch_us; diagnostic_absolute_deadline_us = round->head_no_progress_deadline_us; diagnostic_master_node = round->current_master_node; - diagnostic_requester_sender_generation - = round->requester_sender_connection_generation; - diagnostic_master_ingress_generation - = round->master_ingress_connection_generation; + diagnostic_requester_sender_generation = round->requester_sender_connection_generation; + diagnostic_master_ingress_generation = round->master_ingress_connection_generation; diagnostic_identity_match = pcm_resource_x_request_observation_matches_locked( round, assertion, current_master_node, resource_formation, master_session_incarnation, r4_record_generation, requester_sender_connection_generation, @@ -13515,11 +12668,8 @@ cluster_pcm_lock_resource_x_bootstrap_round_step_direct_init_exact( * The observed head lease is never a caller budget; terminal has no expiry. */ ResourceXApplyResult cluster_pcm_lock_resource_x_bootstrap_round_direct_init_join_budget_exact( - const ResourceXAssertion *assertion, - uint64 direct_init_ownership_generation, - uint64 direct_init_reservation_token, - uint64 now_us, - uint64 *r4_record_generation_out, + const ResourceXAssertion *assertion, uint64 direct_init_ownership_generation, + uint64 direct_init_reservation_token, uint64 now_us, uint64 *r4_record_generation_out, uint64 *absolute_deadline_us_out) { ClusterPcmResourceXBootstrapRound *round; @@ -13532,17 +12682,12 @@ cluster_pcm_lock_resource_x_bootstrap_round_direct_init_join_budget_exact( *r4_record_generation_out = 0; if (absolute_deadline_us_out != NULL) *absolute_deadline_us_out = 0; - if (!resource_x_assertion_valid(assertion) - || assertion->requester_node != cluster_node_id - || direct_init_ownership_generation == UINT64_MAX - || direct_init_reservation_token == 0 - || direct_init_reservation_token == UINT64_MAX - || now_us == 0 || now_us == UINT64_MAX - || r4_record_generation_out == NULL - || absolute_deadline_us_out == NULL) + if (!resource_x_assertion_valid(assertion) || assertion->requester_node != cluster_node_id + || direct_init_ownership_generation == UINT64_MAX || direct_init_reservation_token == 0 + || direct_init_reservation_token == UINT64_MAX || now_us == 0 || now_us == UINT64_MAX + || r4_record_generation_out == NULL || absolute_deadline_us_out == NULL) return RESOURCE_X_APPLY_INVALID; - if (!pcm_entry_ref_acquire(&assertion->resource, false, - &entry_ref, &acquire_result)) + if (!pcm_entry_ref_acquire(&assertion->resource, false, &entry_ref, &acquire_result)) return RESOURCE_X_APPLY_NOT_FOUND; entry = entry_ref.entry; @@ -13607,11 +12752,9 @@ cluster_pcm_lock_resource_x_bootstrap_round_step_direct_init_join_exact( ResourceXApplyResult cluster_pcm_lock_resource_x_bootstrap_round_discard_pre_assert_authority_drift_exact( const ResourceXDecodedFrame *request, int32 expected_master_node, - uint64 expected_r4_record_generation, - uint32 expected_master_ingress_connection_generation, + uint64 expected_r4_record_generation, uint32 expected_master_ingress_connection_generation, uint64 expected_retry_slice_us, uint64 expected_absolute_deadline_us, - uint64 expected_direct_init_ownership_generation, - uint64 expected_direct_init_reservation_token) + uint64 expected_direct_init_ownership_generation, uint64 expected_direct_init_reservation_token) { ClusterPcmResourceXBootstrapRound *round; PcmEntryRef entry_ref; @@ -13620,32 +12763,24 @@ cluster_pcm_lock_resource_x_bootstrap_round_discard_pre_assert_authority_drift_e ResourceXApplyResult result; bool broadcast = false; - if (request == NULL - || request->kind != RESOURCE_X_WIRE_PREASSERT_BOOTSTRAP + if (request == NULL || request->kind != RESOURCE_X_WIRE_PREASSERT_BOOTSTRAP || request->payload_bytes != RESOURCE_X_CONTROL_V1_BYTES || request->blocked_has_remote_proof - || !resource_x_assertion_valid( - &request->common.logical_assertion) - || request->common.logical_assertion.requester_node - != cluster_node_id - || expected_master_node < 0 - || expected_master_node >= RESOURCE_X_PROTOCOL_NODE_LIMIT - || expected_r4_record_generation == 0 - || expected_r4_record_generation == UINT64_MAX + || !resource_x_assertion_valid(&request->common.logical_assertion) + || request->common.logical_assertion.requester_node != cluster_node_id + || expected_master_node < 0 || expected_master_node >= RESOURCE_X_PROTOCOL_NODE_LIMIT + || expected_r4_record_generation == 0 || expected_r4_record_generation == UINT64_MAX || expected_master_ingress_connection_generation == 0 || expected_master_ingress_connection_generation == UINT32_MAX - || expected_retry_slice_us == 0 - || expected_retry_slice_us == UINT64_MAX - || expected_absolute_deadline_us == 0 - || expected_absolute_deadline_us == UINT64_MAX + || expected_retry_slice_us == 0 || expected_retry_slice_us == UINT64_MAX + || expected_absolute_deadline_us == 0 || expected_absolute_deadline_us == UINT64_MAX || expected_direct_init_ownership_generation == UINT64_MAX || expected_direct_init_reservation_token == UINT64_MAX || (expected_direct_init_reservation_token == 0 && expected_direct_init_ownership_generation != 0)) return RESOURCE_X_APPLY_INVALID; - if (!pcm_entry_ref_acquire( - &request->common.logical_assertion.resource, false, - &entry_ref, &acquire_result)) + if (!pcm_entry_ref_acquire(&request->common.logical_assertion.resource, false, &entry_ref, + &acquire_result)) return RESOURCE_X_APPLY_NOT_FOUND; entry = entry_ref.entry; @@ -13662,24 +12797,20 @@ cluster_pcm_lock_resource_x_bootstrap_round_discard_pre_assert_authority_drift_e expected_direct_init_ownership_generation, expected_direct_init_reservation_token) || round->request.assertion_sequence != round->highest_attempt_floor) result = RESOURCE_X_APPLY_STALE; - else if (round->phase - != RESOURCE_X_BOOTSTRAP_ROUND_REQUEST_DISPATCHED) + else if (round->phase != RESOURCE_X_BOOTSTRAP_ROUND_REQUEST_DISPATCHED) result = RESOURCE_X_APPLY_BAD_STATE; else if (round->request.flags == RESOURCE_X_COMMON_FLAG_REMOTE_ADMISSION || round->delivery_target.buffer_id_plus_one != 0) /* An absent ACK cannot prove the master has not admitted this round. */ result = RESOURCE_X_APPLY_BAD_STATE; - else if (!pcm_resource_x_local_owner_valid_locked( - &entry->resource_x_local_owner)) + else if (!pcm_resource_x_local_owner_valid_locked(&entry->resource_x_local_owner)) result = RESOURCE_X_APPLY_RECOVERY_BLOCKED; else if (entry->resource_x_local_owner.state != RESOURCE_X_LOCAL_OWNER_EMPTY || round->install_claim_source != RESOURCE_X_INSTALL_CLAIM_NONE || !pcm_resource_x_active_empty_locked(entry)) result = RESOURCE_X_APPLY_BAD_STATE; - else if (round->accepted_base != 0 - || round->terminal_authority_generation != 0 - || round->cached_ownership_generation != 0 - || round->ack.assertion_sequence != 0 + else if (round->accepted_base != 0 || round->terminal_authority_generation != 0 + || round->cached_ownership_generation != 0 || round->ack.assertion_sequence != 0 || round->assertion.assertion_sequence != 0 || pcm_resource_x_ref_valid(&round->terminal_ref)) result = RESOURCE_X_APPLY_RECOVERY_BLOCKED; @@ -13726,19 +12857,15 @@ cluster_pcm_lock_resource_x_bootstrap_round_accept_ack_delivery_exact( if (assertion_out == NULL) return RESOURCE_X_BOOTSTRAP_ROUND_FAIL_CLOSED; memset(assertion_out, 0, sizeof(*assertion_out)); - if (ack == NULL - || !resource_x_assertion_valid(&ack->common.logical_assertion) + if (ack == NULL || !resource_x_assertion_valid(&ack->common.logical_assertion) || authenticated_master_node < 0 || authenticated_master_node >= RESOURCE_X_PROTOCOL_NODE_LIMIT || authenticated_ingress_connection_generation == 0 - || authenticated_ingress_connection_generation == UINT32_MAX - || r4_record_generation == 0 - || r4_record_generation == UINT64_MAX - || now_us == 0 || now_us == UINT64_MAX) + || authenticated_ingress_connection_generation == UINT32_MAX || r4_record_generation == 0 + || r4_record_generation == UINT64_MAX || now_us == 0 || now_us == UINT64_MAX) return RESOURCE_X_BOOTSTRAP_ROUND_FAIL_CLOSED; - if (!pcm_entry_ref_acquire( - &ack->common.logical_assertion.resource, false, - &entry_ref, &acquire_result)) + if (!pcm_entry_ref_acquire(&ack->common.logical_assertion.resource, false, &entry_ref, + &acquire_result)) return RESOURCE_X_BOOTSTRAP_ROUND_FAIL_CLOSED; entry = entry_ref.entry; @@ -13779,8 +12906,7 @@ cluster_pcm_lock_resource_x_bootstrap_round_accept_ack_delivery_exact( pcm_entry_ref_release(&entry_ref); return RESOURCE_X_BOOTSTRAP_ROUND_FAIL_CLOSED; } - pcm_resource_x_bootstrap_round_assertion_snapshot( - round, assertion_out); + pcm_resource_x_bootstrap_round_assertion_snapshot(round, assertion_out); broadcast = true; action = RESOURCE_X_BOOTSTRAP_ROUND_DISPATCH_ASSERT; } else if (round->phase == RESOURCE_X_BOOTSTRAP_ROUND_ASSERT_DISPATCHED @@ -13843,8 +12969,7 @@ pcm_resource_x_bootstrap_round_wait_internal( != master_ingress_connection_generation))) return RESOURCE_X_APPLY_STALE; memset(&wait_context, 0, sizeof(wait_context)); - if (!pcm_entry_ref_acquire(&assertion->resource, false, - &wait_context.ref, &acquire_result)) + if (!pcm_entry_ref_acquire(&assertion->resource, false, &wait_context.ref, &acquire_result)) return RESOURCE_X_APPLY_NOT_FOUND; entry = wait_context.ref.entry; @@ -13886,23 +13011,20 @@ pcm_resource_x_bootstrap_round_wait_internal( master_ingress_connection_generation); if (!terminal_identity_matches - || !pcm_resource_x_local_owner_valid_locked( - &entry->resource_x_local_owner)) + || !pcm_resource_x_local_owner_valid_locked(&entry->resource_x_local_owner)) result = RESOURCE_X_APPLY_STALE; - else if (entry->resource_x_local_owner.state - != RESOURCE_X_LOCAL_OWNER_EMPTY) + else if (entry->resource_x_local_owner.state != RESOURCE_X_LOCAL_OWNER_EMPTY) result = pcm_resource_x_local_owner_round_exact_locked(entry, round) - ? RESOURCE_X_APPLY_APPLIED : RESOURCE_X_APPLY_STALE; + ? RESOURCE_X_APPLY_APPLIED + : RESOURCE_X_APPLY_STALE; else if (round->delivery_target.buffer_id_plus_one != 0) result = RESOURCE_X_APPLY_APPLIED; else result = RESOURCE_X_APPLY_DUPLICATE; - } - else if (direct_init_ownership_generation == 0 - && direct_init_reservation_token == 0 - && pcm_resource_x_s_predecessor_superseded_unbound_wait_locked( - entry, assertion, current_master_node, - master_session_incarnation, resource_formation)) { + } else if (direct_init_ownership_generation == 0 && direct_init_reservation_token == 0 + && pcm_resource_x_s_predecessor_superseded_unbound_wait_locked( + entry, assertion, current_master_node, master_session_incarnation, + resource_formation)) { /* Retaining an exact remote-S predecessor may atomically cancel the * non-authoritative REQUEST_DISPATCHED round after its caller selected * WAIT but before this predicate recheck. The old wait has then been @@ -13953,7 +13075,7 @@ pcm_resource_x_bootstrap_round_wait_internal( PG_TRY(); { (void)ConditionVariableTimedSleep(&entry->wait_cv, timeout_ms, - WAIT_EVENT_PCM_COMPATIBLE_STATE_WAIT); + WAIT_EVENT_PCM_COMPATIBLE_STATE_WAIT); if (!pcm_entry_ref_identity_exact(&wait_context.ref)) { pcm_resource_x_reconfig_block(); ereport(ERROR, (errcode(ERRCODE_DATA_CORRUPTED), @@ -14128,15 +13250,11 @@ cluster_pcm_lock_resource_x_predecessor_wait_exact(const BufferTag *tag, int32 c * waiting on the existing per-resource CV. */ bool cluster_pcm_lock_resource_x_bootstrap_round_direct_init_inflight_exact( - const ResourceXAssertion *assertion, int32 current_master_node, - uint64 resource_formation, uint64 master_session_incarnation, - uint64 r4_record_generation, - uint32 requester_sender_connection_generation, - uint32 master_ingress_connection_generation, - uint64 retry_slice_us, - uint64 direct_init_ownership_generation, - uint64 direct_init_reservation_token, - const ClusterPcmOwnSnapshot *observed) + const ResourceXAssertion *assertion, int32 current_master_node, uint64 resource_formation, + uint64 master_session_incarnation, uint64 r4_record_generation, + uint32 requester_sender_connection_generation, uint32 master_ingress_connection_generation, + uint64 retry_slice_us, uint64 direct_init_ownership_generation, + uint64 direct_init_reservation_token, const ClusterPcmOwnSnapshot *observed) { ClusterPcmResourceXBootstrapRound *round; PcmEntryRef entry_ref; @@ -14146,16 +13264,12 @@ cluster_pcm_lock_resource_x_bootstrap_round_direct_init_inflight_exact( bool phase_matches = false; bool matches = false; - if (!resource_x_assertion_valid(assertion) - || assertion->requester_node != cluster_node_id - || direct_init_ownership_generation == UINT64_MAX - || direct_init_reservation_token == 0 - || direct_init_reservation_token == UINT64_MAX - || observed == NULL) + if (!resource_x_assertion_valid(assertion) || assertion->requester_node != cluster_node_id + || direct_init_ownership_generation == UINT64_MAX || direct_init_reservation_token == 0 + || direct_init_reservation_token == UINT64_MAX || observed == NULL) return false; committed_generation = direct_init_ownership_generation + 1; - if (!pcm_entry_ref_acquire(&assertion->resource, false, - &entry_ref, &acquire_result)) + if (!pcm_entry_ref_acquire(&assertion->resource, false, &entry_ref, &acquire_result)) return false; entry = entry_ref.entry; @@ -14166,31 +13280,23 @@ cluster_pcm_lock_resource_x_bootstrap_round_direct_init_inflight_exact( r4_record_generation, requester_sender_connection_generation, master_ingress_connection_generation, direct_init_ownership_generation, direct_init_reservation_token)) { - phase_matches = round->phase - == RESOURCE_X_BOOTSTRAP_ROUND_ASSERT_DISPATCHED; - if (!phase_matches - && round->phase - == RESOURCE_X_BOOTSTRAP_ROUND_TERMINAL_X_CACHED) - phase_matches - = pcm_resource_x_bootstrap_round_terminal_cover_exact_locked( - entry, round, &round->terminal_ref, - master_session_incarnation, r4_record_generation, - committed_generation); + phase_matches = round->phase == RESOURCE_X_BOOTSTRAP_ROUND_ASSERT_DISPATCHED; + if (!phase_matches && round->phase == RESOURCE_X_BOOTSTRAP_ROUND_TERMINAL_X_CACHED) + phase_matches = pcm_resource_x_bootstrap_round_terminal_cover_exact_locked( + entry, round, &round->terminal_ref, master_session_incarnation, + r4_record_generation, committed_generation); } - matches = phase_matches - && round->request.assertion_sequence != 0 - && round->request.assertion_sequence != UINT64_MAX - && round->request.assertion_sequence == round->highest_attempt_floor - && BufferTagsEqual(&observed->tag, &assertion->resource) - && observed->generation == committed_generation - && observed->reservation_token == direct_init_reservation_token - && observed->pcm_state == (uint8)PCM_STATE_X - && observed->flags == 0 - && observed->writer_activation_token - == direct_init_reservation_token - && (observed->resource_x_activation_generation == 0 - || observed->resource_x_activation_generation - == round->request.assertion_sequence); + matches + = phase_matches && round->request.assertion_sequence != 0 + && round->request.assertion_sequence != UINT64_MAX + && round->request.assertion_sequence == round->highest_attempt_floor + && BufferTagsEqual(&observed->tag, &assertion->resource) + && observed->generation == committed_generation + && observed->reservation_token == direct_init_reservation_token + && observed->pcm_state == (uint8)PCM_STATE_X && observed->flags == 0 + && observed->writer_activation_token == direct_init_reservation_token + && (observed->resource_x_activation_generation == 0 + || observed->resource_x_activation_generation == round->request.assertion_sequence); LWLockRelease(&entry->entry_lock.lock); pcm_entry_ref_release(&entry_ref); return matches; @@ -14199,13 +13305,10 @@ cluster_pcm_lock_resource_x_bootstrap_round_direct_init_inflight_exact( static bool pcm_resource_x_bootstrap_round_target_install_inflight_locked( struct GrdEntry *entry, ClusterPcmResourceXBootstrapRound *round, - const ResourceXAssertion *assertion, int32 current_master_node, - uint64 resource_formation, uint64 master_session_incarnation, - uint64 r4_record_generation, - uint32 requester_sender_connection_generation, - uint32 master_ingress_connection_generation, - uint64 retry_slice_us, - const ClusterPcmOwnSnapshot *observed) + const ResourceXAssertion *assertion, int32 current_master_node, uint64 resource_formation, + uint64 master_session_incarnation, uint64 r4_record_generation, + uint32 requester_sender_connection_generation, uint32 master_ingress_connection_generation, + uint64 retry_slice_us, const ClusterPcmOwnSnapshot *observed) { ResourceXAcquisitionRef ref; PcmResourceXRefClass ref_class; @@ -14223,12 +13326,9 @@ pcm_resource_x_bootstrap_round_target_install_inflight_locked( Assert(entry != NULL); Assert(round != NULL); - if (!resource_x_assertion_valid(assertion) - || assertion->requester_node != cluster_node_id - || observed == NULL - || !BufferTagsEqual(&observed->tag, &assertion->resource) - || observed->generation == UINT64_MAX - || observed->reservation_token == 0 + if (!resource_x_assertion_valid(assertion) || assertion->requester_node != cluster_node_id + || observed == NULL || !BufferTagsEqual(&observed->tag, &assertion->resource) + || observed->generation == UINT64_MAX || observed->reservation_token == 0 || observed->reservation_token == UINT64_MAX) return false; memset(&ref, 0, sizeof(ref)); @@ -14254,47 +13354,38 @@ pcm_resource_x_bootstrap_round_target_install_inflight_locked( master_ingress_connection_generation) && (!direct_init_round || direct_init_generation_exact); n_installing = observed->pcm_state == (uint8)PCM_STATE_N - && observed->flags == PCM_OWN_FLAG_GRANT_PENDING - && observed->writer_activation_token == 0 - && observed->resource_x_activation_generation == 0; - x_activation_fenced = observed->generation != 0 - && observed->pcm_state == (uint8)PCM_STATE_X - && observed->flags == 0 - && observed->writer_activation_token == observed->reservation_token - && (observed->resource_x_activation_generation == 0 - || observed->resource_x_activation_generation == attempt); - x_activation_cleared = observed->generation != 0 - && observed->pcm_state == (uint8)PCM_STATE_X - && observed->flags == 0 - && observed->writer_activation_token == 0 - && observed->resource_x_activation_generation == 0 - && (round->cached_ownership_generation == observed->generation - || direct_init_generation_exact); - x_activation_fenced_phase = x_activation_fenced - && ((observed->resource_x_activation_generation == 0 - && (progress_flags - == (RESOURCE_X_PROGRESS_BOUND - | RESOURCE_X_PROGRESS_T1) - || progress_flags - == (RESOURCE_X_PROGRESS_BOUND - | RESOURCE_X_PROGRESS_T1 - | RESOURCE_X_PROGRESS_T2))) - || (observed->resource_x_activation_generation == attempt - && (progress_flags - == (RESOURCE_X_PROGRESS_BOUND - | RESOURCE_X_PROGRESS_T1) - || progress_flags - == (RESOURCE_X_PROGRESS_BOUND - | RESOURCE_X_PROGRESS_T1 - | RESOURCE_X_PROGRESS_T2)))); - phase_exact = (n_installing - && progress_flags - == (RESOURCE_X_PROGRESS_BOUND | RESOURCE_X_PROGRESS_T1)) - || x_activation_fenced_phase - || (x_activation_cleared - && progress_flags - == (RESOURCE_X_PROGRESS_BOUND | RESOURCE_X_PROGRESS_T1 - | RESOURCE_X_PROGRESS_T2)); + && observed->flags == PCM_OWN_FLAG_GRANT_PENDING + && observed->writer_activation_token == 0 + && observed->resource_x_activation_generation == 0; + x_activation_fenced = observed->generation != 0 && observed->pcm_state == (uint8)PCM_STATE_X + && observed->flags == 0 + && observed->writer_activation_token == observed->reservation_token + && (observed->resource_x_activation_generation == 0 + || observed->resource_x_activation_generation == attempt); + x_activation_cleared = observed->generation != 0 && observed->pcm_state == (uint8)PCM_STATE_X + && observed->flags == 0 && observed->writer_activation_token == 0 + && observed->resource_x_activation_generation == 0 + && (round->cached_ownership_generation == observed->generation + || direct_init_generation_exact); + x_activation_fenced_phase + = x_activation_fenced + && ((observed->resource_x_activation_generation == 0 + && (progress_flags == (RESOURCE_X_PROGRESS_BOUND | RESOURCE_X_PROGRESS_T1) + || progress_flags + == (RESOURCE_X_PROGRESS_BOUND | RESOURCE_X_PROGRESS_T1 + | RESOURCE_X_PROGRESS_T2))) + || (observed->resource_x_activation_generation == attempt + && (progress_flags == (RESOURCE_X_PROGRESS_BOUND | RESOURCE_X_PROGRESS_T1) + || progress_flags + == (RESOURCE_X_PROGRESS_BOUND | RESOURCE_X_PROGRESS_T1 + | RESOURCE_X_PROGRESS_T2)))); + phase_exact + = (n_installing && progress_flags == (RESOURCE_X_PROGRESS_BOUND | RESOURCE_X_PROGRESS_T1)) + || x_activation_fenced_phase + || (x_activation_cleared + && progress_flags + == (RESOURCE_X_PROGRESS_BOUND | RESOURCE_X_PROGRESS_T1 + | RESOURCE_X_PROGRESS_T2)); /* dispatch_phase counts scheduled re-drive attempts; it is neither * authority nor ownership-loss evidence. An exact BUFFER_BUSY * observation is likewise the executor's BLOCKED state. Keep the local @@ -14302,25 +13393,20 @@ pcm_resource_x_bootstrap_round_target_install_inflight_locked( * transport tick can rearm and make one more conditional buffer attempt. */ executor_retry_state_exact = (entry->resource_x_no_progress_generation == 0 - && entry->resource_x_no_progress_reason - == RESOURCE_X_NO_PROGRESS_NONE) + && entry->resource_x_no_progress_reason == RESOURCE_X_NO_PROGRESS_NONE) || (entry->resource_x_no_progress_generation == attempt - && entry->resource_x_no_progress_reason - == RESOURCE_X_NO_PROGRESS_BUFFER_BUSY); + && entry->resource_x_no_progress_reason == RESOURCE_X_NO_PROGRESS_BUFFER_BUSY); ref_class = pcm_resource_x_ref_classify_locked(entry, &ref); - return round->phase == RESOURCE_X_BOOTSTRAP_ROUND_ASSERT_DISPATCHED - && identity_exact - && round->request.assertion_sequence != 0 - && round->request.assertion_sequence != UINT64_MAX - && round->request.assertion_sequence == round->highest_attempt_floor - && round->accepted_base != 0 - && round->accepted_base != UINT64_MAX - && pcm_resource_x_ref_valid(&ref) - && (ref_class == PCM_RX_REF_ACTIVE_EXACT - || (direct_init_generation_exact && x_activation_cleared - && ref_class == PCM_RX_REF_RETIRED_EXACT)) - && phase_exact - && executor_retry_state_exact; + return round->phase == RESOURCE_X_BOOTSTRAP_ROUND_ASSERT_DISPATCHED && identity_exact + && round->request.assertion_sequence != 0 + && round->request.assertion_sequence != UINT64_MAX + && round->request.assertion_sequence == round->highest_attempt_floor + && round->accepted_base != 0 && round->accepted_base != UINT64_MAX + && pcm_resource_x_ref_valid(&ref) + && (ref_class == PCM_RX_REF_ACTIVE_EXACT + || (direct_init_generation_exact && x_activation_cleared + && ref_class == PCM_RX_REF_RETIRED_EXACT)) + && phase_exact && executor_retry_state_exact; } /* BufferDesc and the requester ledger are separate lock domains. The R9 @@ -14333,13 +13419,10 @@ pcm_resource_x_bootstrap_round_target_install_inflight_locked( * generation/token; it is never exposed as authority to the follower. */ bool cluster_pcm_lock_resource_x_bootstrap_round_target_install_inflight_exact( - const ResourceXAssertion *assertion, int32 current_master_node, - uint64 resource_formation, uint64 master_session_incarnation, - uint64 r4_record_generation, - uint32 requester_sender_connection_generation, - uint32 master_ingress_connection_generation, - uint64 retry_slice_us, - const ClusterPcmOwnSnapshot *observed) + const ResourceXAssertion *assertion, int32 current_master_node, uint64 resource_formation, + uint64 master_session_incarnation, uint64 r4_record_generation, + uint32 requester_sender_connection_generation, uint32 master_ingress_connection_generation, + uint64 retry_slice_us, const ClusterPcmOwnSnapshot *observed) { ClusterPcmResourceXBootstrapRound *round; PcmEntryRef entry_ref; @@ -14349,16 +13432,14 @@ cluster_pcm_lock_resource_x_bootstrap_round_target_install_inflight_exact( if (!resource_x_assertion_valid(assertion) || observed == NULL) return false; - if (!pcm_entry_ref_acquire(&assertion->resource, false, - &entry_ref, &acquire_result)) + if (!pcm_entry_ref_acquire(&assertion->resource, false, &entry_ref, &acquire_result)) return false; entry = entry_ref.entry; LWLockAcquire(&entry->entry_lock.lock, LW_SHARED); round = &entry->resource_x_bootstrap_round; matches = pcm_resource_x_bootstrap_round_target_install_inflight_locked( entry, round, assertion, current_master_node, resource_formation, - master_session_incarnation, r4_record_generation, - requester_sender_connection_generation, + master_session_incarnation, r4_record_generation, requester_sender_connection_generation, master_ingress_connection_generation, retry_slice_us, observed); LWLockRelease(&entry->entry_lock.lock); pcm_entry_ref_release(&entry_ref); @@ -14367,8 +13448,7 @@ cluster_pcm_lock_resource_x_bootstrap_round_target_install_inflight_exact( static bool pcm_resource_x_target_install_continuation_valid( - const ResourceXTargetInstallContinuation *continuation, - ResourceXAssertion *assertion_out) + const ResourceXTargetInstallContinuation *continuation, ResourceXAssertion *assertion_out) { ResourceXAssertion assertion; @@ -14422,8 +13502,7 @@ pcm_resource_x_target_install_continuation_valid( static bool pcm_resource_x_target_install_round_identity_exact_locked( const ClusterPcmResourceXBootstrapRound *round, - const ResourceXTargetInstallContinuation *continuation, - const ResourceXAssertion *assertion) + const ResourceXTargetInstallContinuation *continuation, const ResourceXAssertion *assertion) { return pcm_resource_x_node_request_key_matches_locked( round, assertion, continuation->master_node, continuation->resource_formation, @@ -14456,8 +13535,7 @@ pcm_resource_x_target_install_claim_observation_exact_locked( * terminal evidence and never writer permission. */ static bool pcm_resource_x_target_install_preterminal_observation_exact( - const ResourceXTargetInstallContinuation *continuation, - const ClusterPcmOwnSnapshot *observed) + const ResourceXTargetInstallContinuation *continuation, const ClusterPcmOwnSnapshot *observed) { bool n_installing; bool x_activation_cleared; @@ -14468,30 +13546,21 @@ pcm_resource_x_target_install_preterminal_observation_exact( if (!BufferTagsEqual(&observed->tag, &continuation->resource) || observed->reservation_token != continuation->reservation_token) return false; - n_installing - = observed->pcm_state == (uint8)PCM_STATE_N - && observed->flags == PCM_OWN_FLAG_GRANT_PENDING - && observed->generation - == continuation->pending_ownership_generation - && observed->writer_activation_token == 0 - && observed->resource_x_activation_generation == 0; - x_activation_fenced - = observed->pcm_state == (uint8)PCM_STATE_X - && observed->flags == 0 - && observed->generation - == continuation->expected_x_ownership_generation - && observed->writer_activation_token - == continuation->reservation_token - && (observed->resource_x_activation_generation == 0 - || observed->resource_x_activation_generation - == continuation->acquisition_generation); - x_activation_cleared - = observed->pcm_state == (uint8)PCM_STATE_X - && observed->flags == 0 - && observed->generation - == continuation->expected_x_ownership_generation - && observed->writer_activation_token == 0 - && observed->resource_x_activation_generation == 0; + n_installing = observed->pcm_state == (uint8)PCM_STATE_N + && observed->flags == PCM_OWN_FLAG_GRANT_PENDING + && observed->generation == continuation->pending_ownership_generation + && observed->writer_activation_token == 0 + && observed->resource_x_activation_generation == 0; + x_activation_fenced = observed->pcm_state == (uint8)PCM_STATE_X && observed->flags == 0 + && observed->generation == continuation->expected_x_ownership_generation + && observed->writer_activation_token == continuation->reservation_token + && (observed->resource_x_activation_generation == 0 + || observed->resource_x_activation_generation + == continuation->acquisition_generation); + x_activation_cleared = observed->pcm_state == (uint8)PCM_STATE_X && observed->flags == 0 + && observed->generation == continuation->expected_x_ownership_generation + && observed->writer_activation_token == 0 + && observed->resource_x_activation_generation == 0; return n_installing || x_activation_fenced || x_activation_cleared; } @@ -14505,8 +13574,7 @@ pcm_resource_x_target_install_preterminal_observation_exact( * it never grants authority. */ static bool pcm_resource_x_target_install_postpreuse_observation_exact( - const ResourceXTargetInstallContinuation *continuation, - const ClusterPcmOwnSnapshot *observed) + const ResourceXTargetInstallContinuation *continuation, const ClusterPcmOwnSnapshot *observed) { bool x_revoke_or_abort; bool n_revoke_or_finish; @@ -14515,41 +13583,32 @@ pcm_resource_x_target_install_postpreuse_observation_exact( Assert(observed != NULL); if (!BufferTagsEqual(&observed->tag, &continuation->resource) || observed->reservation_token <= continuation->reservation_token - || observed->reservation_token == UINT64_MAX - || observed->writer_activation_token != 0 + || observed->reservation_token == UINT64_MAX || observed->writer_activation_token != 0 || observed->resource_x_activation_generation != 0) return false; - x_revoke_or_abort - = observed->pcm_state == (uint8)PCM_STATE_X - && observed->generation - == continuation->expected_x_ownership_generation - && (observed->flags == 0 - || observed->flags == PCM_OWN_FLAG_REVOKING); + x_revoke_or_abort = observed->pcm_state == (uint8)PCM_STATE_X + && observed->generation == continuation->expected_x_ownership_generation + && (observed->flags == 0 || observed->flags == PCM_OWN_FLAG_REVOKING); n_revoke_or_finish = continuation->expected_x_ownership_generation < UINT64_MAX - 1 && observed->pcm_state == (uint8)PCM_STATE_N - && observed->generation - == continuation->expected_x_ownership_generation + 1 - && (observed->flags == 0 - || observed->flags == PCM_OWN_FLAG_REVOKING); + && observed->generation == continuation->expected_x_ownership_generation + 1 + && (observed->flags == 0 || observed->flags == PCM_OWN_FLAG_REVOKING); return x_revoke_or_abort || n_revoke_or_finish; } static bool pcm_resource_x_target_install_terminal_observation_exact( - const ResourceXTargetInstallContinuation *continuation, - const ClusterPcmOwnSnapshot *observed) + const ResourceXTargetInstallContinuation *continuation, const ClusterPcmOwnSnapshot *observed) { Assert(continuation != NULL); Assert(observed != NULL); return BufferTagsEqual(&observed->tag, &continuation->resource) - && observed->pcm_state == (uint8)PCM_STATE_X - && observed->flags == 0 - && observed->generation - == continuation->expected_x_ownership_generation - && observed->reservation_token == continuation->reservation_token - && observed->writer_activation_token == 0 - && observed->resource_x_activation_generation == 0; + && observed->pcm_state == (uint8)PCM_STATE_X && observed->flags == 0 + && observed->generation == continuation->expected_x_ownership_generation + && observed->reservation_token == continuation->reservation_token + && observed->writer_activation_token == 0 + && observed->resource_x_activation_generation == 0; } /* A creator that deliberately dropped every pin can miss its completed @@ -14704,8 +13763,7 @@ pcm_resource_x_target_install_observation_retired_locked( static bool pcm_resource_x_target_install_superseded_round_exact_locked( struct GrdEntry *entry, const ClusterPcmResourceXBootstrapRound *round, - const ResourceXTargetInstallContinuation *continuation, - const ResourceXAssertion *assertion) + const ResourceXTargetInstallContinuation *continuation, const ResourceXAssertion *assertion) { Assert(entry != NULL); Assert(round != NULL); @@ -14732,8 +13790,7 @@ pcm_resource_x_target_install_superseded_round_exact_locked( static bool pcm_resource_x_target_install_captured_live_revoke_exact( const ClusterPcmResourceXLocalOwner *owner, - const ResourceXTargetInstallContinuation *continuation, - const ClusterPcmOwnSnapshot *observed) + const ResourceXTargetInstallContinuation *continuation, const ClusterPcmOwnSnapshot *observed) { Assert(owner != NULL); Assert(continuation != NULL); @@ -14754,20 +13811,16 @@ pcm_resource_x_target_install_captured_live_revoke_exact( static bool pcm_resource_x_target_install_owner_observation_exact_locked( const ClusterPcmResourceXLocalOwner *owner, - const ResourceXTargetInstallContinuation *continuation, - const ClusterPcmOwnSnapshot *observed) + const ResourceXTargetInstallContinuation *continuation, const ClusterPcmOwnSnapshot *observed) { Assert(owner != NULL); Assert(continuation != NULL); Assert(observed != NULL); - return pcm_resource_x_target_install_terminal_observation_exact( - continuation, observed) - || pcm_resource_x_target_install_preterminal_observation_exact( - continuation, observed) - || pcm_resource_x_target_install_postpreuse_observation_exact( - continuation, observed) - || pcm_resource_x_target_install_captured_live_revoke_exact( - owner, continuation, observed); + return pcm_resource_x_target_install_terminal_observation_exact(continuation, observed) + || pcm_resource_x_target_install_preterminal_observation_exact(continuation, observed) + || pcm_resource_x_target_install_postpreuse_observation_exact(continuation, observed) + || pcm_resource_x_target_install_captured_live_revoke_exact(owner, continuation, + observed); } /* A30: ordinary T1 names the requester attempt but carries no BufferDesc @@ -14779,8 +13832,7 @@ pcm_resource_x_target_install_owner_observation_exact_locked( static bool pcm_resource_x_target_install_late_misbound_i0_exact_locked( struct GrdEntry *entry, const ClusterPcmResourceXBootstrapRound *round, - const ResourceXTargetInstallContinuation *continuation, - const ClusterPcmOwnSnapshot *observed, + const ResourceXTargetInstallContinuation *continuation, const ClusterPcmOwnSnapshot *observed, const ResourceXAcquisitionRef *expected_ref) { const ClusterPcmResourceXLocalOwner *owner; @@ -14815,8 +13867,7 @@ pcm_resource_x_target_install_late_misbound_i0_exact_locked( && !pcm_resource_x_local_owner_round_exact_locked(entry, round))) return false; return pcm_resource_x_bootstrap_round_terminal_cover_exact_locked( - entry, round, expected_ref, - continuation->master_session_incarnation, + entry, round, expected_ref, continuation->master_session_incarnation, continuation->r4_record_generation, terminal_generation); } @@ -14829,8 +13880,7 @@ pcm_resource_x_target_install_late_misbound_i0_exact_locked( static bool pcm_resource_x_target_install_same_token_n_successor_exact_locked( struct GrdEntry *entry, const ClusterPcmResourceXBootstrapRound *round, - const ResourceXTargetInstallContinuation *continuation, - const ClusterPcmOwnSnapshot *observed, + const ResourceXTargetInstallContinuation *continuation, const ClusterPcmOwnSnapshot *observed, const ResourceXAcquisitionRef *expected_ref) { const ClusterPcmResourceXLocalOwner *owner; @@ -14863,8 +13913,7 @@ pcm_resource_x_target_install_same_token_n_successor_exact_locked( && !pcm_resource_x_local_owner_round_exact_locked(entry, round))) return false; return pcm_resource_x_bootstrap_round_terminal_cover_exact_locked( - entry, round, expected_ref, - continuation->master_session_incarnation, + entry, round, expected_ref, continuation->master_session_incarnation, continuation->r4_record_generation, terminal_generation); } @@ -14876,8 +13925,7 @@ pcm_resource_x_target_install_same_token_n_successor_exact_locked( static bool pcm_resource_x_target_install_capture_revoke_provenance_exact_locked( struct GrdEntry *entry, const ClusterPcmResourceXBootstrapRound *round, - const ResourceXTargetInstallContinuation *continuation, - const ResourceXAssertion *assertion, + const ResourceXTargetInstallContinuation *continuation, const ResourceXAssertion *assertion, const ClusterPcmOwnSnapshot *observed) { ResourceXAcquisitionRef expected_ref; @@ -14909,21 +13957,17 @@ pcm_resource_x_target_install_capture_revoke_provenance_exact_locked( memset(&expected_ref, 0, sizeof(expected_ref)); expected_ref.assertion = *assertion; expected_ref.formation = continuation->resource_formation; - expected_ref.acquisition_generation - = continuation->acquisition_generation; + expected_ref.acquisition_generation = continuation->acquisition_generation; return pcm_resource_x_bootstrap_round_terminal_cover_exact_locked( - entry, round, &expected_ref, - continuation->master_session_incarnation, + entry, round, &expected_ref, continuation->master_session_incarnation, continuation->r4_record_generation, terminal_generation); } static ResourceXTargetInstallFollowState pcm_resource_x_target_install_classify_locked( struct GrdEntry *entry, ClusterPcmResourceXBootstrapRound *round, - const ResourceXTargetInstallContinuation *continuation, - const ResourceXAssertion *assertion, - const ClusterPcmOwnSnapshot *observed, - ResourceXAcquisitionRef *terminal_ref_out) + const ResourceXTargetInstallContinuation *continuation, const ResourceXAssertion *assertion, + const ClusterPcmOwnSnapshot *observed, ResourceXAcquisitionRef *terminal_ref_out) { ResourceXAcquisitionRef expected_ref; ClusterPcmResourceXLocalOwner *owner; @@ -14950,21 +13994,17 @@ pcm_resource_x_target_install_classify_locked( assertion)) return RESOURCE_X_TARGET_INSTALL_RESAMPLE; postpreuse_observation - = pcm_resource_x_target_install_postpreuse_observation_exact( - continuation, observed); + = pcm_resource_x_target_install_postpreuse_observation_exact(continuation, observed); round_identity_exact - = pcm_resource_x_target_install_round_identity_exact_locked( - round, continuation, assertion); - if (!round_identity_exact - && postpreuse_observation - && pcm_resource_x_target_install_superseded_round_exact_locked( - entry, round, continuation, assertion)) + = pcm_resource_x_target_install_round_identity_exact_locked(round, continuation, assertion); + if (!round_identity_exact && postpreuse_observation + && pcm_resource_x_target_install_superseded_round_exact_locked(entry, round, continuation, + assertion)) return RESOURCE_X_TARGET_INSTALL_PREUSE_RETRY; if (round->phase == RESOURCE_X_BOOTSTRAP_ROUND_FAILED_CLOSED) return RESOURCE_X_TARGET_INSTALL_RECOVERY_BLOCKED; if (round->request.assertion_sequence != 0 - && round->request.assertion_sequence - != continuation->acquisition_generation) + && round->request.assertion_sequence != continuation->acquisition_generation) return RESOURCE_X_TARGET_INSTALL_STALE; if (round->phase < RESOURCE_X_BOOTSTRAP_ROUND_ASSERT_DISPATCHED) return RESOURCE_X_TARGET_INSTALL_RECOVERY_BLOCKED; @@ -14986,21 +14026,17 @@ pcm_resource_x_target_install_classify_locked( memset(&expected_ref, 0, sizeof(expected_ref)); expected_ref.assertion = *assertion; expected_ref.formation = continuation->resource_formation; - expected_ref.acquisition_generation - = continuation->acquisition_generation; - if (round->phase == RESOURCE_X_BOOTSTRAP_ROUND_TERMINAL_X_CACHED) - { - if (pcm_resource_x_target_install_late_misbound_i0_exact_locked( - entry, round, continuation, observed, &expected_ref)) + expected_ref.acquisition_generation = continuation->acquisition_generation; + if (round->phase == RESOURCE_X_BOOTSTRAP_ROUND_TERMINAL_X_CACHED) { + if (pcm_resource_x_target_install_late_misbound_i0_exact_locked(entry, round, continuation, + observed, &expected_ref)) return RESOURCE_X_TARGET_INSTALL_PREUSE_RETRY; terminal_cover_exact - = round->cached_ownership_generation - == continuation->expected_x_ownership_generation + = round->cached_ownership_generation == continuation->expected_x_ownership_generation && pcm_resource_x_bootstrap_round_terminal_cover_exact_locked( - entry, round, &expected_ref, - continuation->master_session_incarnation, - continuation->r4_record_generation, - continuation->expected_x_ownership_generation); + entry, round, &expected_ref, continuation->master_session_incarnation, + continuation->r4_record_generation, + continuation->expected_x_ownership_generation); if (!terminal_cover_exact) return RESOURCE_X_TARGET_INSTALL_RECOVERY_BLOCKED; if (round->delivery_target.buffer_id_plus_one != 0) { @@ -15018,17 +14054,14 @@ pcm_resource_x_target_install_classify_locked( if (pcm_resource_x_target_install_same_token_n_successor_exact_locked( entry, round, continuation, observed, &expected_ref)) return RESOURCE_X_TARGET_INSTALL_PREUSE_RETRY; - if (owner->state != RESOURCE_X_LOCAL_OWNER_EMPTY) - { + if (owner->state != RESOURCE_X_LOCAL_OWNER_EMPTY) { if (!pcm_resource_x_local_owner_round_exact_locked(entry, round) || !pcm_resource_x_target_install_owner_observation_exact_locked( owner, continuation, observed)) return RESOURCE_X_TARGET_INSTALL_RECOVERY_BLOCKED; return RESOURCE_X_TARGET_INSTALL_PREUSE_RETRY; } - if (pcm_resource_x_target_install_terminal_observation_exact( - continuation, observed)) - { + if (pcm_resource_x_target_install_terminal_observation_exact(continuation, observed)) { if (terminal_ref_out != NULL) *terminal_ref_out = expected_ref; return RESOURCE_X_TARGET_INSTALL_TERMINAL; @@ -15036,24 +14069,19 @@ pcm_resource_x_target_install_classify_locked( if (postpreuse_observation) return RESOURCE_X_TARGET_INSTALL_PREUSE_RETRY; if (observed->pcm_state == (uint8)PCM_STATE_N - && observed->generation - > continuation->expected_x_ownership_generation) + && observed->generation > continuation->expected_x_ownership_generation) return RESOURCE_X_TARGET_INSTALL_RECOVERY_BLOCKED; if (observed->reservation_token != continuation->reservation_token - || (observed->generation - != continuation->pending_ownership_generation - && observed->generation - != continuation->expected_x_ownership_generation)) + || (observed->generation != continuation->pending_ownership_generation + && observed->generation != continuation->expected_x_ownership_generation)) return RESOURCE_X_TARGET_INSTALL_STALE; return RESOURCE_X_TARGET_INSTALL_RECOVERY_BLOCKED; } if (round->phase != RESOURCE_X_BOOTSTRAP_ROUND_ASSERT_DISPATCHED) return RESOURCE_X_TARGET_INSTALL_RECOVERY_BLOCKED; if (observed->reservation_token != continuation->reservation_token - || (observed->generation - != continuation->pending_ownership_generation - && observed->generation - != continuation->expected_x_ownership_generation)) + || (observed->generation != continuation->pending_ownership_generation + && observed->generation != continuation->expected_x_ownership_generation)) return RESOURCE_X_TARGET_INSTALL_STALE; if (pcm_resource_x_bootstrap_round_target_install_inflight_locked( entry, round, assertion, continuation->master_node, continuation->resource_formation, @@ -15069,14 +14097,11 @@ pcm_resource_x_target_install_classify_locked( ResourceXTargetInstallFollowState cluster_pcm_lock_resource_x_bootstrap_round_target_install_capture_exact( - const ResourceXAssertion *assertion, int32 current_master_node, - uint64 resource_formation, uint64 master_session_incarnation, - uint64 r4_record_generation, - uint32 requester_sender_connection_generation, - uint32 master_ingress_connection_generation, + const ResourceXAssertion *assertion, int32 current_master_node, uint64 resource_formation, + uint64 master_session_incarnation, uint64 r4_record_generation, + uint32 requester_sender_connection_generation, uint32 master_ingress_connection_generation, uint64 retry_slice_us, uint64 caller_absolute_deadline_us, - const ClusterPcmOwnSnapshot *observed, - ResourceXTargetInstallContinuation *continuation_out) + const ClusterPcmOwnSnapshot *observed, ResourceXTargetInstallContinuation *continuation_out) { ResourceXTargetInstallContinuation continuation; ResourceXTargetInstallFollowState state; @@ -15088,25 +14113,18 @@ cluster_pcm_lock_resource_x_bootstrap_round_target_install_capture_exact( if (continuation_out != NULL) memset(continuation_out, 0, sizeof(*continuation_out)); if (continuation_out == NULL || !resource_x_assertion_valid(assertion) - || assertion->requester_node != cluster_node_id - || current_master_node < 0 - || current_master_node >= RESOURCE_X_PROTOCOL_NODE_LIMIT - || resource_formation == 0 || resource_formation == UINT64_MAX - || master_session_incarnation == 0 - || master_session_incarnation == UINT64_MAX - || r4_record_generation == 0 - || r4_record_generation == UINT64_MAX - || requester_sender_connection_generation == 0 + || assertion->requester_node != cluster_node_id || current_master_node < 0 + || current_master_node >= RESOURCE_X_PROTOCOL_NODE_LIMIT || resource_formation == 0 + || resource_formation == UINT64_MAX || master_session_incarnation == 0 + || master_session_incarnation == UINT64_MAX || r4_record_generation == 0 + || r4_record_generation == UINT64_MAX || requester_sender_connection_generation == 0 || requester_sender_connection_generation == UINT32_MAX || master_ingress_connection_generation == 0 - || master_ingress_connection_generation == UINT32_MAX - || retry_slice_us == 0 || retry_slice_us == UINT64_MAX - || caller_absolute_deadline_us == 0 - || caller_absolute_deadline_us == UINT64_MAX - || observed == NULL) + || master_ingress_connection_generation == UINT32_MAX || retry_slice_us == 0 + || retry_slice_us == UINT64_MAX || caller_absolute_deadline_us == 0 + || caller_absolute_deadline_us == UINT64_MAX || observed == NULL) return RESOURCE_X_TARGET_INSTALL_INVALID; - if (!pcm_entry_ref_acquire(&assertion->resource, false, - &entry_ref, &acquire_result)) + if (!pcm_entry_ref_acquire(&assertion->resource, false, &entry_ref, &acquire_result)) return RESOURCE_X_TARGET_INSTALL_STALE; entry = entry_ref.entry; LWLockAcquire(&entry->entry_lock.lock, LW_SHARED); @@ -15124,51 +14142,41 @@ cluster_pcm_lock_resource_x_bootstrap_round_target_install_capture_exact( || round->head_no_progress_deadline_us == UINT64_MAX) state = RESOURCE_X_TARGET_INSTALL_STALE; else if (!BufferTagsEqual(&observed->tag, &assertion->resource) - || observed->reservation_token == 0 - || observed->reservation_token == UINT64_MAX - || observed->generation == UINT64_MAX) + || observed->reservation_token == 0 || observed->reservation_token == UINT64_MAX + || observed->generation == UINT64_MAX) state = RESOURCE_X_TARGET_INSTALL_STALE; else if (round->phase == RESOURCE_X_BOOTSTRAP_ROUND_TERMINAL_X_CACHED - && round->cached_ownership_generation != 0 - && round->cached_ownership_generation < UINT64_MAX - 1 - && observed->pcm_state == (uint8)PCM_STATE_N - && (observed->flags == PCM_OWN_FLAG_GRANT_PENDING - || observed->flags == 0 - || observed->flags == PCM_OWN_FLAG_REVOKING) - && observed->generation == round->cached_ownership_generation + 1 - && observed->writer_activation_token == 0 - && observed->resource_x_activation_generation == 0) - { + && round->cached_ownership_generation != 0 + && round->cached_ownership_generation < UINT64_MAX - 1 + && observed->pcm_state == (uint8)PCM_STATE_N + && (observed->flags == PCM_OWN_FLAG_GRANT_PENDING || observed->flags == 0 + || observed->flags == PCM_OWN_FLAG_REVOKING) + && observed->generation == round->cached_ownership_generation + 1 + && observed->writer_activation_token == 0 + && observed->resource_x_activation_generation == 0) { /* This first sample already follows the round's cached terminal X. * It cannot seed an install continuation: doing so would invent an * expected X at G+2 and intercept the caller's local-pending or * retained-release path. STALE declines only this optional capture; * the caller must validate the N carrier before fresh authority. */ state = RESOURCE_X_TARGET_INSTALL_STALE; - } - else - { + } else { memset(&continuation, 0, sizeof(continuation)); continuation.resource = assertion->resource; continuation.requester_node = assertion->requester_node; continuation.master_node = current_master_node; - continuation.entry_binding_generation - = entry_ref.binding_generation; + continuation.entry_binding_generation = entry_ref.binding_generation; continuation.resource_formation = resource_formation; - continuation.master_session_incarnation - = master_session_incarnation; + continuation.master_session_incarnation = master_session_incarnation; continuation.r4_record_generation = r4_record_generation; - continuation.acquisition_generation - = round->request.assertion_sequence; - continuation.accepted_base_authority_generation - = round->accepted_base; + continuation.acquisition_generation = round->request.assertion_sequence; + continuation.accepted_base_authority_generation = round->accepted_base; continuation.observed_head_change_generation = round->head_change_generation; - continuation.caller_absolute_deadline_us - = caller_absolute_deadline_us; + continuation.caller_absolute_deadline_us = caller_absolute_deadline_us; continuation.requested_sleep_slice_us = retry_slice_us; - continuation.pending_ownership_generation - = observed->pcm_state == (uint8)PCM_STATE_N - ? observed->generation : observed->generation - 1; + continuation.pending_ownership_generation = observed->pcm_state == (uint8)PCM_STATE_N + ? observed->generation + : observed->generation - 1; continuation.expected_x_ownership_generation = continuation.pending_ownership_generation + 1; continuation.reservation_token = observed->reservation_token; @@ -15178,15 +14186,13 @@ cluster_pcm_lock_resource_x_bootstrap_round_target_install_capture_exact( continuation.capture_flags |= RESOURCE_X_TARGET_INSTALL_CAPTURE_DIRECT_INIT; continuation.requester_sender_connection_generation = requester_sender_connection_generation; - continuation.master_ingress_connection_generation - = master_ingress_connection_generation; + continuation.master_ingress_connection_generation = master_ingress_connection_generation; if (pcm_resource_x_target_install_capture_revoke_provenance_exact_locked( entry, round, &continuation, assertion, observed)) - continuation.capture_flags - |= RESOURCE_X_TARGET_INSTALL_CAPTURE_REVOKE_TOKEN; + continuation.capture_flags |= RESOURCE_X_TARGET_INSTALL_CAPTURE_REVOKE_TOKEN; continuation.valid = true; - state = pcm_resource_x_target_install_classify_locked( - entry, round, &continuation, assertion, observed, NULL); + state = pcm_resource_x_target_install_classify_locked(entry, round, &continuation, + assertion, observed, NULL); if (state == RESOURCE_X_TARGET_INSTALL_INFLIGHT || state == RESOURCE_X_TARGET_INSTALL_TERMINAL || state == RESOURCE_X_TARGET_INSTALL_PREUSE_RETRY) @@ -15199,8 +14205,7 @@ cluster_pcm_lock_resource_x_bootstrap_round_target_install_capture_exact( ResourceXTargetInstallFollowState cluster_pcm_lock_resource_x_bootstrap_round_target_install_classify_exact( - const ResourceXTargetInstallContinuation *continuation, - const ClusterPcmOwnSnapshot *observed, + const ResourceXTargetInstallContinuation *continuation, const ClusterPcmOwnSnapshot *observed, ResourceXAcquisitionRef *terminal_ref_out) { ResourceXAssertion assertion; @@ -15212,25 +14217,20 @@ cluster_pcm_lock_resource_x_bootstrap_round_target_install_classify_exact( if (terminal_ref_out != NULL) memset(terminal_ref_out, 0, sizeof(*terminal_ref_out)); - if (!pcm_resource_x_target_install_continuation_valid( - continuation, &assertion) + if (!pcm_resource_x_target_install_continuation_valid(continuation, &assertion) || observed == NULL) return RESOURCE_X_TARGET_INSTALL_INVALID; - if (!pcm_entry_ref_acquire(&continuation->resource, false, - &entry_ref, &acquire_result)) + if (!pcm_entry_ref_acquire(&continuation->resource, false, &entry_ref, &acquire_result)) return RESOURCE_X_TARGET_INSTALL_STALE; - if (entry_ref.binding_generation - != continuation->entry_binding_generation) - { + if (entry_ref.binding_generation != continuation->entry_binding_generation) { pcm_entry_ref_release(&entry_ref); return RESOURCE_X_TARGET_INSTALL_STALE; } entry = entry_ref.entry; LWLockAcquire(&entry->entry_lock.lock, LW_SHARED); round = &entry->resource_x_bootstrap_round; - state = pcm_resource_x_target_install_classify_locked( - entry, round, continuation, &assertion, observed, - terminal_ref_out); + state = pcm_resource_x_target_install_classify_locked(entry, round, continuation, &assertion, + observed, terminal_ref_out); LWLockRelease(&entry->entry_lock.lock); pcm_entry_ref_release(&entry_ref); return state; @@ -15242,10 +14242,8 @@ cluster_pcm_lock_resource_x_bootstrap_round_target_install_classify_exact( * exact entry predicate remains waitable; it carries no authority. */ static ResourceXApplyResult pcm_resource_x_target_install_wait_recheck_locked( - struct GrdEntry *entry, - ClusterPcmResourceXBootstrapRound *round, - const ResourceXTargetInstallContinuation *continuation, - const ResourceXAssertion *assertion, + struct GrdEntry *entry, ClusterPcmResourceXBootstrapRound *round, + const ResourceXTargetInstallContinuation *continuation, const ResourceXAssertion *assertion, ResourceXTargetInstallFollowState expected_follow_state) { static const ResourceXAcquisitionRef empty_ref; @@ -15260,11 +14258,9 @@ pcm_resource_x_target_install_wait_recheck_locked( Assert(LWLockHeldByMeInMode(&entry->entry_lock.lock, LW_SHARED) || LWLockHeldByMeInMode(&entry->entry_lock.lock, LW_EXCLUSIVE)); - if (!pcm_resource_x_local_owner_valid_locked( - &entry->resource_x_local_owner) + if (!pcm_resource_x_local_owner_valid_locked(&entry->resource_x_local_owner) || round->phase > RESOURCE_X_BOOTSTRAP_ROUND_FAILED_CLOSED - || (entry->resource_x_progress_flags - & ~RESOURCE_X_PROGRESS_KNOWN_MASK) != 0) + || (entry->resource_x_progress_flags & ~RESOURCE_X_PROGRESS_KNOWN_MASK) != 0) return RESOURCE_X_APPLY_RECOVERY_BLOCKED; if (round->phase == RESOURCE_X_BOOTSTRAP_ROUND_FAILED_CLOSED || continuation->acquisition_generation <= round->failed_attempt_floor @@ -15277,24 +14273,19 @@ pcm_resource_x_target_install_wait_recheck_locked( memset(&expected_ref, 0, sizeof(expected_ref)); expected_ref.assertion = *assertion; expected_ref.formation = continuation->resource_formation; - expected_ref.acquisition_generation - = continuation->acquisition_generation; + expected_ref.acquisition_generation = continuation->acquisition_generation; - if (expected_follow_state == RESOURCE_X_TARGET_INSTALL_PREUSE_RETRY) - { + if (expected_follow_state == RESOURCE_X_TARGET_INSTALL_PREUSE_RETRY) { /* Owner clear or a valid successor that won after the caller's * coherent classification is progress. Return immediately so the * caller can obtain a fresh B-E-B observation. */ - if (entry->resource_x_local_owner.state - == RESOURCE_X_LOCAL_OWNER_EMPTY) + if (entry->resource_x_local_owner.state == RESOURCE_X_LOCAL_OWNER_EMPTY) return RESOURCE_X_APPLY_DUPLICATE; - if (!pcm_resource_x_target_install_round_identity_exact_locked( - round, continuation, assertion)) + if (!pcm_resource_x_target_install_round_identity_exact_locked(round, continuation, + assertion)) return RESOURCE_X_APPLY_STALE; - if (round->phase - != RESOURCE_X_BOOTSTRAP_ROUND_TERMINAL_X_CACHED - || round->cached_ownership_generation - != continuation->expected_x_ownership_generation + if (round->phase != RESOURCE_X_BOOTSTRAP_ROUND_TERMINAL_X_CACHED + || round->cached_ownership_generation != continuation->expected_x_ownership_generation || !pcm_resource_x_local_owner_round_exact_locked(entry, round)) return RESOURCE_X_APPLY_RECOVERY_BLOCKED; /* The old terminal cover may coexist with a newer active attempt after @@ -15302,31 +14293,24 @@ pcm_resource_x_target_install_wait_recheck_locked( * only a structurally valid, same-formation, strictly newer attempt; * this is progress to re-probe, never authority for either attempt. */ if (pcm_resource_x_active_valid_locked(entry) - && entry->resource_x_formation - == continuation->resource_formation - && entry->resource_x_acquisition_generation - > continuation->acquisition_generation + && entry->resource_x_formation == continuation->resource_formation + && entry->resource_x_acquisition_generation > continuation->acquisition_generation && entry->resource_x_retired_acquisition_generation - == continuation->acquisition_generation - && pcm_resource_x_acquisition_ref_equal( - &round->terminal_ref, &expected_ref) - && round->terminal_authority_generation - > round->accepted_base + == continuation->acquisition_generation + && pcm_resource_x_acquisition_ref_equal(&round->terminal_ref, &expected_ref) + && round->terminal_authority_generation > round->accepted_base && round->terminal_authority_generation != UINT64_MAX) return RESOURCE_X_APPLY_DUPLICATE; if (!pcm_resource_x_bootstrap_round_terminal_cover_exact_locked( - entry, round, &expected_ref, - continuation->master_session_incarnation, - continuation->r4_record_generation, - continuation->expected_x_ownership_generation)) + entry, round, &expected_ref, continuation->master_session_incarnation, + continuation->r4_record_generation, continuation->expected_x_ownership_generation)) return RESOURCE_X_APPLY_RECOVERY_BLOCKED; return RESOURCE_X_APPLY_APPLIED; } if (expected_follow_state != RESOURCE_X_TARGET_INSTALL_INFLIGHT) return RESOURCE_X_APPLY_INVALID; - if (!pcm_resource_x_target_install_round_identity_exact_locked( - round, continuation, assertion)) + if (!pcm_resource_x_target_install_round_identity_exact_locked(round, continuation, assertion)) return RESOURCE_X_APPLY_STALE; if (!pcm_resource_x_target_install_claim_observation_exact_locked(round, continuation)) return continuation->observed_claim_reservation_token == 0 @@ -15338,57 +14322,40 @@ pcm_resource_x_target_install_wait_recheck_locked( && round->install_claim_source != RESOURCE_X_INSTALL_CLAIM_NONE ? RESOURCE_X_APPLY_DUPLICATE : RESOURCE_X_APPLY_STALE; - if (round->phase == RESOURCE_X_BOOTSTRAP_ROUND_TERMINAL_X_CACHED) - { - if (round->cached_ownership_generation - != continuation->expected_x_ownership_generation + if (round->phase == RESOURCE_X_BOOTSTRAP_ROUND_TERMINAL_X_CACHED) { + if (round->cached_ownership_generation != continuation->expected_x_ownership_generation || !pcm_resource_x_bootstrap_round_terminal_cover_exact_locked( - entry, round, &expected_ref, - continuation->master_session_incarnation, - continuation->r4_record_generation, - continuation->expected_x_ownership_generation)) + entry, round, &expected_ref, continuation->master_session_incarnation, + continuation->r4_record_generation, continuation->expected_x_ownership_generation)) return RESOURCE_X_APPLY_RECOVERY_BLOCKED; return round->delivery_target.buffer_id_plus_one != 0 ? RESOURCE_X_APPLY_APPLIED : RESOURCE_X_APPLY_DUPLICATE; } if (round->phase != RESOURCE_X_BOOTSTRAP_ROUND_ASSERT_DISPATCHED - || entry->resource_x_local_owner.state - != RESOURCE_X_LOCAL_OWNER_EMPTY + || entry->resource_x_local_owner.state != RESOURCE_X_LOCAL_OWNER_EMPTY || round->terminal_authority_generation != 0 - || memcmp(&round->terminal_ref, &empty_ref, - sizeof(empty_ref)) != 0) + || memcmp(&round->terminal_ref, &empty_ref, sizeof(empty_ref)) != 0) return RESOURCE_X_APPLY_RECOVERY_BLOCKED; ref_class = pcm_resource_x_ref_classify_locked(entry, &expected_ref); - if (ref_class == PCM_RX_REF_ACTIVE_OTHER - || ref_class == PCM_RX_REF_RETIRED_OLD) + if (ref_class == PCM_RX_REF_ACTIVE_OTHER || ref_class == PCM_RX_REF_RETIRED_OLD) return RESOURCE_X_APPLY_STALE; if (ref_class != PCM_RX_REF_ACTIVE_EXACT) return RESOURCE_X_APPLY_RECOVERY_BLOCKED; progress_flags = entry->resource_x_progress_flags; - if (progress_flags - == (RESOURCE_X_PROGRESS_BOUND | RESOURCE_X_PROGRESS_T1)) - { + if (progress_flags == (RESOURCE_X_PROGRESS_BOUND | RESOURCE_X_PROGRESS_T1)) { if (round->cached_ownership_generation != 0) return RESOURCE_X_APPLY_RECOVERY_BLOCKED; - } - else if (progress_flags - == (RESOURCE_X_PROGRESS_BOUND | RESOURCE_X_PROGRESS_T1 - | RESOURCE_X_PROGRESS_T2)) - { - if (round->cached_ownership_generation - != continuation->expected_x_ownership_generation) + } else if (progress_flags + == (RESOURCE_X_PROGRESS_BOUND | RESOURCE_X_PROGRESS_T1 | RESOURCE_X_PROGRESS_T2)) { + if (round->cached_ownership_generation != continuation->expected_x_ownership_generation) return RESOURCE_X_APPLY_RECOVERY_BLOCKED; - } - else + } else return RESOURCE_X_APPLY_RECOVERY_BLOCKED; if (entry->resource_x_no_progress_generation == 0 - && entry->resource_x_no_progress_reason - == RESOURCE_X_NO_PROGRESS_NONE) + && entry->resource_x_no_progress_reason == RESOURCE_X_NO_PROGRESS_NONE) return RESOURCE_X_APPLY_APPLIED; - if (entry->resource_x_no_progress_generation - == continuation->acquisition_generation - && entry->resource_x_no_progress_reason - == RESOURCE_X_NO_PROGRESS_BUFFER_BUSY) + if (entry->resource_x_no_progress_generation == continuation->acquisition_generation + && entry->resource_x_no_progress_reason == RESOURCE_X_NO_PROGRESS_BUFFER_BUSY) return RESOURCE_X_APPLY_APPLIED; return RESOURCE_X_APPLY_RECOVERY_BLOCKED; } @@ -15400,8 +14367,7 @@ pcm_resource_x_target_install_wait_recheck_locked( ResourceXApplyResult cluster_pcm_lock_resource_x_bootstrap_round_target_install_wait_exact( const ResourceXTargetInstallContinuation *continuation, - ResourceXTargetInstallFollowState expected_follow_state, - long timeout_ms) + ResourceXTargetInstallFollowState expected_follow_state, long timeout_ms) { ResourceXAssertion assertion; ClusterPcmResourceXBootstrapRound *round; @@ -15414,20 +14380,15 @@ cluster_pcm_lock_resource_x_bootstrap_round_target_install_wait_exact( uint64 remaining_us; long sleep_ms; - if (!pcm_resource_x_target_install_continuation_valid( - continuation, &assertion) + if (!pcm_resource_x_target_install_continuation_valid(continuation, &assertion) || (expected_follow_state != RESOURCE_X_TARGET_INSTALL_INFLIGHT - && expected_follow_state - != RESOURCE_X_TARGET_INSTALL_PREUSE_RETRY) + && expected_follow_state != RESOURCE_X_TARGET_INSTALL_PREUSE_RETRY) || timeout_ms <= 0) return RESOURCE_X_APPLY_INVALID; memset(&wait_context, 0, sizeof(wait_context)); - if (!pcm_entry_ref_acquire(&continuation->resource, false, - &wait_context.ref, &acquire_result)) + if (!pcm_entry_ref_acquire(&continuation->resource, false, &wait_context.ref, &acquire_result)) return RESOURCE_X_APPLY_STALE; - if (wait_context.ref.binding_generation - != continuation->entry_binding_generation) - { + if (wait_context.ref.binding_generation != continuation->entry_binding_generation) { pcm_entry_ref_release(&wait_context.ref); return RESOURCE_X_APPLY_STALE; } @@ -15437,8 +14398,8 @@ cluster_pcm_lock_resource_x_bootstrap_round_target_install_wait_exact( wait_context.cv_prepared = true; LWLockAcquire(&entry->entry_lock.lock, LW_SHARED); round = &entry->resource_x_bootstrap_round; - result = pcm_resource_x_target_install_wait_recheck_locked( - entry, round, continuation, &assertion, expected_follow_state); + result = pcm_resource_x_target_install_wait_recheck_locked(entry, round, continuation, + &assertion, expected_follow_state); now_us = pcm_resource_x_monotonic_us(); if (now_us == 0 || now_us == UINT64_MAX) result = RESOURCE_X_APPLY_INVALID; @@ -15457,13 +14418,13 @@ cluster_pcm_lock_resource_x_bootstrap_round_target_install_wait_exact( return RESOURCE_X_APPLY_APPLIED; } sleep_ms = timeout_ms; - if (deadline_ms < (uint64) sleep_ms) - sleep_ms = (long) deadline_ms; + if (deadline_ms < (uint64)sleep_ms) + sleep_ms = (long)deadline_ms; PG_TRY(); { (void)ConditionVariableTimedSleep(&entry->wait_cv, sleep_ms, - WAIT_EVENT_PCM_COMPATIBLE_STATE_WAIT); + WAIT_EVENT_PCM_COMPATIBLE_STATE_WAIT); if (!pcm_entry_ref_identity_exact(&wait_context.ref)) { pcm_resource_x_reconfig_block(); ereport(ERROR, (errcode(ERRCODE_DATA_CORRUPTED), @@ -15484,12 +14445,10 @@ cluster_pcm_lock_resource_x_bootstrap_round_target_install_wait_exact( ResourceXApplyResult cluster_pcm_lock_resource_x_bootstrap_round_failure_snapshot_exact( - const ResourceXAssertion *assertion, int32 current_master_node, - uint64 resource_formation, uint64 master_session_incarnation, - uint64 r4_record_generation, - uint32 requester_sender_connection_generation, - uint32 master_ingress_connection_generation, uint64 retry_slice_us, - ResourceXBootstrapRoundFailureSnapshot *out) + const ResourceXAssertion *assertion, int32 current_master_node, uint64 resource_formation, + uint64 master_session_incarnation, uint64 r4_record_generation, + uint32 requester_sender_connection_generation, uint32 master_ingress_connection_generation, + uint64 retry_slice_us, ResourceXBootstrapRoundFailureSnapshot *out) { ClusterPcmResourceXBootstrapRound *round; PcmEntryRef entry_ref; @@ -15500,22 +14459,17 @@ cluster_pcm_lock_resource_x_bootstrap_round_failure_snapshot_exact( if (out != NULL) memset(out, 0, sizeof(*out)); - if (out == NULL || !resource_x_assertion_valid(assertion) - || current_master_node < 0 - || current_master_node >= RESOURCE_X_PROTOCOL_NODE_LIMIT - || resource_formation == 0 || resource_formation == UINT64_MAX - || master_session_incarnation == 0 - || master_session_incarnation == UINT64_MAX - || r4_record_generation == 0 - || r4_record_generation == UINT64_MAX - || requester_sender_connection_generation == 0 + if (out == NULL || !resource_x_assertion_valid(assertion) || current_master_node < 0 + || current_master_node >= RESOURCE_X_PROTOCOL_NODE_LIMIT || resource_formation == 0 + || resource_formation == UINT64_MAX || master_session_incarnation == 0 + || master_session_incarnation == UINT64_MAX || r4_record_generation == 0 + || r4_record_generation == UINT64_MAX || requester_sender_connection_generation == 0 || requester_sender_connection_generation == UINT32_MAX || master_ingress_connection_generation == 0 - || master_ingress_connection_generation == UINT32_MAX - || retry_slice_us == 0 || retry_slice_us == UINT64_MAX) + || master_ingress_connection_generation == UINT32_MAX || retry_slice_us == 0 + || retry_slice_us == UINT64_MAX) return RESOURCE_X_APPLY_INVALID; - if (!pcm_entry_ref_acquire(&assertion->resource, false, - &entry_ref, &acquire_result)) + if (!pcm_entry_ref_acquire(&assertion->resource, false, &entry_ref, &acquire_result)) return RESOURCE_X_APPLY_NOT_FOUND; entry = entry_ref.entry; @@ -15524,10 +14478,9 @@ cluster_pcm_lock_resource_x_bootstrap_round_failure_snapshot_exact( if (round->phase == RESOURCE_X_BOOTSTRAP_ROUND_EMPTY) result = RESOURCE_X_APPLY_NOT_FOUND; else if (round->phase > RESOURCE_X_BOOTSTRAP_ROUND_FAILED_CLOSED - || round->request.assertion_sequence == 0 - || round->request.assertion_sequence == UINT64_MAX - || (entry->resource_x_progress_flags - & ~RESOURCE_X_PROGRESS_KNOWN_MASK) != 0) + || round->request.assertion_sequence == 0 + || round->request.assertion_sequence == UINT64_MAX + || (entry->resource_x_progress_flags & ~RESOURCE_X_PROGRESS_KNOWN_MASK) != 0) result = RESOURCE_X_APPLY_RECOVERY_BLOCKED; else if (!pcm_resource_x_node_request_key_matches_locked( round, assertion, current_master_node, resource_formation, @@ -15538,34 +14491,27 @@ cluster_pcm_lock_resource_x_bootstrap_round_failure_snapshot_exact( memset(&ref, 0, sizeof(ref)); ref.assertion = round->request.logical_assertion; ref.formation = round->resource_formation; - ref.acquisition_generation - = round->request.assertion_sequence; + ref.acquisition_generation = round->request.assertion_sequence; out->ref = ref; out->base_authority_generation = round->accepted_base; - out->authority_generation - = round->terminal_authority_generation; - out->buffer_ownership_generation - = round->cached_ownership_generation; + out->authority_generation = round->terminal_authority_generation; + out->buffer_ownership_generation = round->cached_ownership_generation; out->r4_record_generation = round->r4_record_generation; - out->master_session_incarnation - = round->master_session_incarnation; + out->master_session_incarnation = round->master_session_incarnation; out->absolute_deadline_us = round->head_no_progress_deadline_us; out->head_change_generation = round->head_change_generation; out->head_last_semantic_progress_us = round->head_last_semantic_progress_us; out->head_no_progress_budget_us = round->head_no_progress_budget_us; out->head_failure_reason = round->head_failure_reason; - out->requester_base_generation - = entry->resource_x_requester_base_generation; - out->retired_acquisition_generation - = entry->resource_x_retired_acquisition_generation; + out->requester_base_generation = entry->resource_x_requester_base_generation; + out->retired_acquisition_generation = entry->resource_x_retired_acquisition_generation; out->progress_flags = entry->resource_x_progress_flags; out->round_phase = round->phase; - out->terminal - = pcm_resource_x_bootstrap_round_terminal_cover_exact_locked( - entry, round, &ref, master_session_incarnation, - r4_record_generation, - round->cached_ownership_generation) - ? 1 : 0; + out->terminal = pcm_resource_x_bootstrap_round_terminal_cover_exact_locked( + entry, round, &ref, master_session_incarnation, r4_record_generation, + round->cached_ownership_generation) + ? 1 + : 0; result = RESOURCE_X_APPLY_APPLIED; } LWLockRelease(&entry->entry_lock.lock); @@ -15575,8 +14521,7 @@ cluster_pcm_lock_resource_x_bootstrap_round_failure_snapshot_exact( bool cluster_pcm_lock_resource_x_bootstrap_round_direct_init_snapshot_exact( - const ResourceXAcquisitionRef *ref, - uint64 *direct_init_ownership_generation_out, + const ResourceXAcquisitionRef *ref, uint64 *direct_init_ownership_generation_out, uint64 *direct_init_reservation_token_out) { ClusterPcmResourceXBootstrapRound *round; @@ -15589,12 +14534,10 @@ cluster_pcm_lock_resource_x_bootstrap_round_direct_init_snapshot_exact( *direct_init_ownership_generation_out = 0; if (direct_init_reservation_token_out != NULL) *direct_init_reservation_token_out = 0; - if (!pcm_resource_x_ref_valid(ref) - || direct_init_ownership_generation_out == NULL + if (!pcm_resource_x_ref_valid(ref) || direct_init_ownership_generation_out == NULL || direct_init_reservation_token_out == NULL) return false; - if (!pcm_entry_ref_acquire(&ref->assertion.resource, false, - &entry_ref, &acquire_result)) + if (!pcm_entry_ref_acquire(&ref->assertion.resource, false, &entry_ref, &acquire_result)) return false; entry = entry_ref.entry; @@ -15621,28 +14564,26 @@ cluster_pcm_lock_resource_x_bootstrap_round_direct_init_snapshot_exact( bool cluster_pcm_lock_resource_x_bootstrap_round_direct_init_matches_exact( - const ResourceXAcquisitionRef *ref, - uint64 direct_init_ownership_generation, + const ResourceXAcquisitionRef *ref, uint64 direct_init_ownership_generation, uint64 direct_init_reservation_token) { uint64 bound_generation; uint64 bound_token; - if (direct_init_ownership_generation == UINT64_MAX - || direct_init_reservation_token == 0 + if (direct_init_ownership_generation == UINT64_MAX || direct_init_reservation_token == 0 || direct_init_reservation_token == UINT64_MAX || !cluster_pcm_lock_resource_x_bootstrap_round_direct_init_snapshot_exact( ref, &bound_generation, &bound_token)) return false; return bound_generation == direct_init_ownership_generation - && bound_token == direct_init_reservation_token; + && bound_token == direct_init_reservation_token; } static bool -pcm_resource_x_terminal_x_lineage_args_valid( - const ResourceXDecodedFrame *successor_block, - int32 authenticated_master_node, uint64 r4_record_generation, - uint64 cached_ownership_generation) +pcm_resource_x_terminal_x_lineage_args_valid(const ResourceXDecodedFrame *successor_block, + int32 authenticated_master_node, + uint64 r4_record_generation, + uint64 cached_ownership_generation) { return successor_block != NULL && successor_block->kind == RESOURCE_X_WIRE_BLOCK_TO_N && successor_block->payload_bytes == RESOURCE_X_CONTROL_V1_BYTES @@ -15680,9 +14621,8 @@ pcm_resource_x_terminal_x_lineage_args_valid( static bool pcm_resource_x_terminal_x_lineage_locked( struct GrdEntry *entry, ClusterPcmResourceXBootstrapRound *round, - const ResourceXDecodedFrame *successor_block, - int32 authenticated_master_node, uint64 r4_record_generation, - uint64 cached_ownership_generation, bool require_direct_init, + const ResourceXDecodedFrame *successor_block, int32 authenticated_master_node, + uint64 r4_record_generation, uint64 cached_ownership_generation, bool require_direct_init, ResourceXTerminalXLineage *lineage_out) { uint64 final_authority_generation; @@ -15730,25 +14670,18 @@ pcm_resource_x_terminal_x_lineage_locked( if (!matches) return false; lineage_out->holder_assertion = round->terminal_ref.assertion; - lineage_out->holder_attempt - = round->terminal_ref.acquisition_generation; + lineage_out->holder_attempt = round->terminal_ref.acquisition_generation; lineage_out->resource_formation = round->resource_formation; - lineage_out->master_session_incarnation - = round->master_session_incarnation; - lineage_out->accepted_base_authority_generation - = round->accepted_base; - lineage_out->final_authority_generation - = final_authority_generation; + lineage_out->master_session_incarnation = round->master_session_incarnation; + lineage_out->accepted_base_authority_generation = round->accepted_base; + lineage_out->final_authority_generation = final_authority_generation; lineage_out->direct_init_ownership_generation = direct_init_lineage ? round->install_claim_pending_generation : 0; - lineage_out->cached_ownership_generation - = round->cached_ownership_generation; + lineage_out->cached_ownership_generation = round->cached_ownership_generation; lineage_out->r4_record_generation = round->r4_record_generation; - lineage_out->successor_attempt - = successor_block->common.assertion_sequence; + lineage_out->successor_attempt = successor_block->common.assertion_sequence; lineage_out->master_node = round->current_master_node; - lineage_out->successor_node - = successor_block->common.logical_assertion.requester_node; + lineage_out->successor_node = successor_block->common.logical_assertion.requester_node; return true; } @@ -15759,9 +14692,8 @@ pcm_resource_x_terminal_x_lineage_locked( * entry still own the downgrade decision. */ bool cluster_pcm_lock_resource_x_bootstrap_round_direct_init_terminal_holder_exact( - const ResourceXDecodedFrame *successor_block, - int32 authenticated_master_node, uint64 r4_record_generation, - uint64 cached_ownership_generation, + const ResourceXDecodedFrame *successor_block, int32 authenticated_master_node, + uint64 r4_record_generation, uint64 cached_ownership_generation, ResourceXTerminalXLineage *lineage_out) { ClusterPcmResourceXBootstrapRound *round; @@ -15773,26 +14705,22 @@ cluster_pcm_lock_resource_x_bootstrap_round_direct_init_terminal_holder_exact( if (lineage_out != NULL) memset(lineage_out, 0, sizeof(*lineage_out)); if (lineage_out == NULL - || !pcm_resource_x_terminal_x_lineage_args_valid( - successor_block, authenticated_master_node, - r4_record_generation, cached_ownership_generation)) + || !pcm_resource_x_terminal_x_lineage_args_valid(successor_block, authenticated_master_node, + r4_record_generation, + cached_ownership_generation)) return false; - if (!pcm_entry_ref_acquire( - &successor_block->common.logical_assertion.resource, false, - &entry_ref, &acquire_result)) + if (!pcm_entry_ref_acquire(&successor_block->common.logical_assertion.resource, false, + &entry_ref, &acquire_result)) return false; entry = entry_ref.entry; LWLockAcquire(&entry->entry_lock.lock, LW_SHARED); round = &entry->resource_x_bootstrap_round; - matches = entry->resource_x_local_owner.state - == RESOURCE_X_LOCAL_OWNER_EMPTY - && pcm_resource_x_local_owner_valid_locked( - &entry->resource_x_local_owner) - && pcm_resource_x_terminal_x_lineage_locked( - entry, round, successor_block, authenticated_master_node, - r4_record_generation, cached_ownership_generation, true, - lineage_out); + matches = entry->resource_x_local_owner.state == RESOURCE_X_LOCAL_OWNER_EMPTY + && pcm_resource_x_local_owner_valid_locked(&entry->resource_x_local_owner) + && pcm_resource_x_terminal_x_lineage_locked( + entry, round, successor_block, authenticated_master_node, r4_record_generation, + cached_ownership_generation, true, lineage_out); LWLockRelease(&entry->entry_lock.lock); pcm_entry_ref_release(&entry_ref); return matches; @@ -15804,9 +14732,8 @@ cluster_pcm_lock_resource_x_bootstrap_round_direct_init_terminal_holder_exact( * cached X generation. This retained lineage is not a second authority. */ bool cluster_pcm_lock_resource_x_bootstrap_round_terminal_holder_exact( - const ResourceXDecodedFrame *successor_block, - int32 authenticated_master_node, uint64 r4_record_generation, - uint64 cached_ownership_generation, + const ResourceXDecodedFrame *successor_block, int32 authenticated_master_node, + uint64 r4_record_generation, uint64 cached_ownership_generation, ResourceXTerminalXLineage *lineage_out) { static bool diagnostic_emitted = false; @@ -15839,39 +14766,32 @@ cluster_pcm_lock_resource_x_bootstrap_round_terminal_holder_exact( if (lineage_out != NULL) memset(lineage_out, 0, sizeof(*lineage_out)); if (lineage_out == NULL - || !pcm_resource_x_terminal_x_lineage_args_valid( - successor_block, authenticated_master_node, - r4_record_generation, cached_ownership_generation)) + || !pcm_resource_x_terminal_x_lineage_args_valid(successor_block, authenticated_master_node, + r4_record_generation, + cached_ownership_generation)) return false; - if (!pcm_entry_ref_acquire( - &successor_block->common.logical_assertion.resource, false, - &entry_ref, &acquire_result)) + if (!pcm_entry_ref_acquire(&successor_block->common.logical_assertion.resource, false, + &entry_ref, &acquire_result)) return false; entry = entry_ref.entry; LWLockAcquire(&entry->entry_lock.lock, LW_SHARED); round = &entry->resource_x_bootstrap_round; - matches = pcm_resource_x_local_owner_valid_locked( - &entry->resource_x_local_owner) - && pcm_resource_x_terminal_x_lineage_locked( - entry, round, successor_block, authenticated_master_node, - r4_record_generation, cached_ownership_generation, false, - lineage_out); + matches = pcm_resource_x_local_owner_valid_locked(&entry->resource_x_local_owner) + && pcm_resource_x_terminal_x_lineage_locked( + entry, round, successor_block, authenticated_master_node, r4_record_generation, + cached_ownership_generation, false, lineage_out); if (matches) { - ClusterPcmResourceXLocalOwner *owner - = &entry->resource_x_local_owner; + ClusterPcmResourceXLocalOwner *owner = &entry->resource_x_local_owner; matches = owner->state == RESOURCE_X_LOCAL_OWNER_EMPTY - || (owner->state == RESOURCE_X_LOCAL_OWNER_RECYCLING - && pcm_resource_x_local_owner_round_exact_locked( - entry, round)) - || (owner->state == RESOURCE_X_LOCAL_OWNER_HANDOFF - && pcm_resource_x_local_owner_round_exact_locked( - entry, round) - && pcm_resource_x_local_handoff_successor_exact( - &owner->handoff, successor_block, - authenticated_master_node, r4_record_generation, - cached_ownership_generation)); + || (owner->state == RESOURCE_X_LOCAL_OWNER_RECYCLING + && pcm_resource_x_local_owner_round_exact_locked(entry, round)) + || (owner->state == RESOURCE_X_LOCAL_OWNER_HANDOFF + && pcm_resource_x_local_owner_round_exact_locked(entry, round) + && pcm_resource_x_local_handoff_successor_exact( + &owner->handoff, successor_block, authenticated_master_node, + r4_record_generation, cached_ownership_generation)); } if (!matches && !diagnostic_emitted) { holder_assertion = round->request.logical_assertion; @@ -15884,76 +14804,66 @@ cluster_pcm_lock_resource_x_bootstrap_round_terminal_holder_exact( terminal_authority = round->terminal_authority_generation; round_cached_generation = round->cached_ownership_generation; round_r4_generation = round->r4_record_generation; - retired_generation - = entry->resource_x_retired_acquisition_generation; + retired_generation = entry->resource_x_retired_acquisition_generation; direct_init_generation = round->install_claim_pending_generation; direct_init_token = round->install_claim_reservation_token; local_owner_state = entry->resource_x_local_owner.state; current_master = round->current_master_node; round_phase = round->phase; - local_owner_valid = pcm_resource_x_local_owner_valid_locked( - &entry->resource_x_local_owner); + local_owner_valid = pcm_resource_x_local_owner_valid_locked(&entry->resource_x_local_owner); terminal_ref_valid = pcm_resource_x_ref_valid(&round->terminal_ref); - same_tag = BufferTagsEqual( - &round->request.logical_assertion.resource, - &successor_block->common.logical_assertion.resource); + same_tag = BufferTagsEqual(&round->request.logical_assertion.resource, + &successor_block->common.logical_assertion.resource); distinct_assertion = !resource_x_assertion_equal( - &round->request.logical_assertion, - &successor_block->common.logical_assertion); + &round->request.logical_assertion, &successor_block->common.logical_assertion); } LWLockRelease(&entry->entry_lock.lock); pcm_entry_ref_release(&entry_ref); if (!matches && !diagnostic_emitted) { diagnostic_emitted = true; - ereport(LOG, - (errmsg_internal("Resource-X terminal-X lineage diagnostic"), - errdetail("phase=%u local_owner=%u local_owner_valid=%s " - "holder=%d successor=%d same_tag=%s distinct=%s " - "terminal_ref_valid=%s holder_attempt=%llu " - "terminal_attempt=%llu highest=%llu retired=%llu " - "round_formation=%llu successor_formation=%llu " - "round_session=%llu successor_session=%llu " - "round_master=%d authenticated_master=%d " - "round_r4=%llu caller_r4=%llu accepted_base=%llu " - "terminal_authority=%llu successor_base=%llu " - "round_cached=%llu caller_cached=%llu " - "direct_init_generation=%llu direct_init_token=%llu", - (unsigned)round_phase, (unsigned)local_owner_state, - local_owner_valid ? "true" : "false", - holder_assertion.requester_node, - successor_block->common.logical_assertion.requester_node, - same_tag ? "true" : "false", - distinct_assertion ? "true" : "false", - terminal_ref_valid ? "true" : "false", - (unsigned long long)holder_attempt, - (unsigned long long)terminal_ref.acquisition_generation, - (unsigned long long)highest_attempt, - (unsigned long long)retired_generation, - (unsigned long long)resource_formation, - (unsigned long long)successor_block->common.resource_formation, - (unsigned long long)master_session, - (unsigned long long)successor_block->common.master_session_incarnation, - current_master, authenticated_master_node, - (unsigned long long)round_r4_generation, - (unsigned long long)r4_record_generation, - (unsigned long long)accepted_base, - (unsigned long long)terminal_authority, - (unsigned long long)successor_block->common.base_authority_generation, - (unsigned long long)round_cached_generation, - (unsigned long long)cached_ownership_generation, - (unsigned long long)direct_init_generation, - (unsigned long long)direct_init_token))); + ereport( + LOG, + (errmsg_internal("Resource-X terminal-X lineage diagnostic"), + errdetail("phase=%u local_owner=%u local_owner_valid=%s " + "holder=%d successor=%d same_tag=%s distinct=%s " + "terminal_ref_valid=%s holder_attempt=%llu " + "terminal_attempt=%llu highest=%llu retired=%llu " + "round_formation=%llu successor_formation=%llu " + "round_session=%llu successor_session=%llu " + "round_master=%d authenticated_master=%d " + "round_r4=%llu caller_r4=%llu accepted_base=%llu " + "terminal_authority=%llu successor_base=%llu " + "round_cached=%llu caller_cached=%llu " + "direct_init_generation=%llu direct_init_token=%llu", + (unsigned)round_phase, (unsigned)local_owner_state, + local_owner_valid ? "true" : "false", holder_assertion.requester_node, + successor_block->common.logical_assertion.requester_node, + same_tag ? "true" : "false", distinct_assertion ? "true" : "false", + terminal_ref_valid ? "true" : "false", (unsigned long long)holder_attempt, + (unsigned long long)terminal_ref.acquisition_generation, + (unsigned long long)highest_attempt, (unsigned long long)retired_generation, + (unsigned long long)resource_formation, + (unsigned long long)successor_block->common.resource_formation, + (unsigned long long)master_session, + (unsigned long long)successor_block->common.master_session_incarnation, + current_master, authenticated_master_node, + (unsigned long long)round_r4_generation, + (unsigned long long)r4_record_generation, (unsigned long long)accepted_base, + (unsigned long long)terminal_authority, + (unsigned long long)successor_block->common.base_authority_generation, + (unsigned long long)round_cached_generation, + (unsigned long long)cached_ownership_generation, + (unsigned long long)direct_init_generation, + (unsigned long long)direct_init_token))); } return matches; } ResourceXApplyResult cluster_pcm_lock_resource_x_itl_recycle_begin_exact( - const ResourceXAcquisitionRef *ref, - uint64 master_session_incarnation, uint64 r4_record_generation, - uint64 cached_ownership_generation, uint64 reservation_token, - int32 owner_procno, uint64 now_us pg_attribute_unused(), - ResourceXLocalOwnerHandle *handle_out) + const ResourceXAcquisitionRef *ref, uint64 master_session_incarnation, + uint64 r4_record_generation, uint64 cached_ownership_generation, uint64 reservation_token, + int32 owner_procno, uint64 now_us pg_attribute_unused(), ResourceXLocalOwnerHandle *handle_out) { ClusterPcmResourceXBootstrapRound *round; PcmEntryRef entry_ref; @@ -15964,39 +14874,33 @@ cluster_pcm_lock_resource_x_itl_recycle_begin_exact( if (handle_out != NULL) memset(handle_out, 0, sizeof(*handle_out)); - if (!pcm_resource_x_ref_valid(ref) || handle_out == NULL - || master_session_incarnation == 0 - || master_session_incarnation == UINT64_MAX - || r4_record_generation == 0 - || r4_record_generation == UINT64_MAX - || cached_ownership_generation == 0 - || cached_ownership_generation == UINT64_MAX - || reservation_token == 0 || reservation_token == UINT64_MAX - || owner_procno < 0 || now_us == 0 || now_us == UINT64_MAX) + if (!pcm_resource_x_ref_valid(ref) || handle_out == NULL || master_session_incarnation == 0 + || master_session_incarnation == UINT64_MAX || r4_record_generation == 0 + || r4_record_generation == UINT64_MAX || cached_ownership_generation == 0 + || cached_ownership_generation == UINT64_MAX || reservation_token == 0 + || reservation_token == UINT64_MAX || owner_procno < 0 || now_us == 0 + || now_us == UINT64_MAX) return RESOURCE_X_APPLY_INVALID; - if (!pcm_entry_ref_acquire(&ref->assertion.resource, false, - &entry_ref, &acquire_result)) + if (!pcm_entry_ref_acquire(&ref->assertion.resource, false, &entry_ref, &acquire_result)) return RESOURCE_X_APPLY_NOT_FOUND; entry = entry_ref.entry; pcm_entry_lock_exclusive(entry); round = &entry->resource_x_bootstrap_round; - if (!pcm_resource_x_local_owner_valid_locked( - &entry->resource_x_local_owner)) + if (!pcm_resource_x_local_owner_valid_locked(&entry->resource_x_local_owner)) result = RESOURCE_X_APPLY_RECOVERY_BLOCKED; else { broadcast = pcm_resource_x_local_owner_expire_locked(entry, now_us); if (!cluster_pcm_lock_resource_x_gate_open_exact(ref->formation) - || !pcm_resource_x_bootstrap_round_terminal_cover_exact_locked( - entry, round, ref, master_session_incarnation, - r4_record_generation, cached_ownership_generation)) + || !pcm_resource_x_bootstrap_round_terminal_cover_exact_locked( + entry, round, ref, master_session_incarnation, r4_record_generation, + cached_ownership_generation)) result = RESOURCE_X_APPLY_STALE; else result = pcm_resource_x_local_owner_claim_locked( - entry, RESOURCE_X_LOCAL_OWNER_RECYCLING, ref, - master_session_incarnation, r4_record_generation, - cached_ownership_generation, reservation_token, - owner_procno, handle_out); + entry, RESOURCE_X_LOCAL_OWNER_RECYCLING, ref, master_session_incarnation, + r4_record_generation, cached_ownership_generation, reservation_token, owner_procno, + handle_out); } if (broadcast || result == RESOURCE_X_APPLY_APPLIED) ConditionVariableBroadcast(&entry->wait_cv); @@ -16006,9 +14910,8 @@ cluster_pcm_lock_resource_x_itl_recycle_begin_exact( } ResourceXApplyResult -cluster_pcm_lock_resource_x_itl_recycle_finish_exact( - const ResourceXLocalOwnerHandle *handle, - uint64 now_us pg_attribute_unused()) +cluster_pcm_lock_resource_x_itl_recycle_finish_exact(const ResourceXLocalOwnerHandle *handle, + uint64 now_us pg_attribute_unused()) { ClusterPcmResourceXBootstrapRound *round; ClusterPcmResourceXLocalOwner *owner; @@ -16018,38 +14921,29 @@ cluster_pcm_lock_resource_x_itl_recycle_finish_exact( ResourceXApplyResult result; bool broadcast = false; - if (!pcm_resource_x_local_owner_handle_valid(handle) - || now_us == 0 || now_us == UINT64_MAX) + if (!pcm_resource_x_local_owner_handle_valid(handle) || now_us == 0 || now_us == UINT64_MAX) return RESOURCE_X_APPLY_INVALID; - if (!pcm_entry_ref_acquire(&handle->ref.assertion.resource, false, - &entry_ref, &acquire_result)) + if (!pcm_entry_ref_acquire(&handle->ref.assertion.resource, false, &entry_ref, &acquire_result)) return RESOURCE_X_APPLY_NOT_FOUND; entry = entry_ref.entry; pcm_entry_lock_exclusive(entry); round = &entry->resource_x_bootstrap_round; owner = &entry->resource_x_local_owner; - if (!pcm_resource_x_local_owner_valid_locked( - owner)) + if (!pcm_resource_x_local_owner_valid_locked(owner)) result = RESOURCE_X_APPLY_RECOVERY_BLOCKED; - else if (owner->state - != RESOURCE_X_LOCAL_OWNER_RECYCLING - || !pcm_resource_x_local_owner_handle_equal( - &owner->handle, handle)) + else if (owner->state != RESOURCE_X_LOCAL_OWNER_RECYCLING + || !pcm_resource_x_local_owner_handle_equal(&owner->handle, handle)) result = RESOURCE_X_APPLY_STALE; else { broadcast = pcm_resource_x_local_owner_expire_locked(entry, now_us); - if (!cluster_pcm_lock_resource_x_gate_open_exact( - handle->ref.formation) - || !pcm_resource_x_bootstrap_round_terminal_cover_exact_locked( - entry, round, &handle->ref, - handle->master_session_incarnation, - handle->r4_record_generation, - handle->buffer_ownership_generation)) { + if (!cluster_pcm_lock_resource_x_gate_open_exact(handle->ref.formation) + || !pcm_resource_x_bootstrap_round_terminal_cover_exact_locked( + entry, round, &handle->ref, handle->master_session_incarnation, + handle->r4_record_generation, handle->buffer_ownership_generation)) { broadcast = pcm_resource_x_local_owner_priority_clear_locked(entry) || broadcast; result = RESOURCE_X_APPLY_STALE; } else if (pcm_resource_x_local_handoff_valid(&owner->handoff)) { - if (!pcm_resource_x_local_handoff_round_current_locked( - &owner->handoff, round)) { + if (!pcm_resource_x_local_handoff_round_current_locked(&owner->handoff, round)) { broadcast = pcm_resource_x_local_owner_priority_clear_locked(entry) || broadcast; result = RESOURCE_X_APPLY_STALE; } else { @@ -16072,8 +14966,7 @@ cluster_pcm_lock_resource_x_itl_recycle_finish_exact( } ResourceXApplyResult -cluster_pcm_lock_resource_x_itl_recycle_cancel_exact( - const ResourceXLocalOwnerHandle *handle) +cluster_pcm_lock_resource_x_itl_recycle_cancel_exact(const ResourceXLocalOwnerHandle *handle) { PcmEntryRef entry_ref; PcmEntryAcquireResult acquire_result; @@ -16082,13 +14975,12 @@ cluster_pcm_lock_resource_x_itl_recycle_cancel_exact( if (!pcm_resource_x_local_owner_handle_valid(handle)) return RESOURCE_X_APPLY_INVALID; - if (!pcm_entry_ref_acquire(&handle->ref.assertion.resource, false, - &entry_ref, &acquire_result)) + if (!pcm_entry_ref_acquire(&handle->ref.assertion.resource, false, &entry_ref, &acquire_result)) return RESOURCE_X_APPLY_NOT_FOUND; entry = entry_ref.entry; pcm_entry_lock_exclusive(entry); - result = pcm_resource_x_local_owner_release_locked( - entry, RESOURCE_X_LOCAL_OWNER_RECYCLING, handle); + result = pcm_resource_x_local_owner_release_locked(entry, RESOURCE_X_LOCAL_OWNER_RECYCLING, + handle); if (result == RESOURCE_X_APPLY_APPLIED) ConditionVariableBroadcast(&entry->wait_cv); LWLockRelease(&entry->entry_lock.lock); @@ -16098,11 +14990,9 @@ cluster_pcm_lock_resource_x_itl_recycle_cancel_exact( ResourceXApplyResult cluster_pcm_lock_resource_x_terminal_x_revoke_claim_exact( - const ResourceXDecodedFrame *successor_block, - int32 authenticated_master_node, uint64 r4_record_generation, - uint64 cached_ownership_generation, uint64 reservation_token, - int32 owner_procno, uint64 now_us pg_attribute_unused(), - ResourceXTerminalXLineage *lineage_out, + const ResourceXDecodedFrame *successor_block, int32 authenticated_master_node, + uint64 r4_record_generation, uint64 cached_ownership_generation, uint64 reservation_token, + int32 owner_procno, uint64 now_us pg_attribute_unused(), ResourceXTerminalXLineage *lineage_out, ResourceXLocalOwnerHandle *handle_out) { ClusterPcmResourceXBootstrapRound *round; @@ -16119,23 +15009,21 @@ cluster_pcm_lock_resource_x_terminal_x_revoke_claim_exact( memset(lineage_out, 0, sizeof(*lineage_out)); if (handle_out != NULL) memset(handle_out, 0, sizeof(*handle_out)); - if (lineage_out == NULL || handle_out == NULL - || reservation_token == 0 || reservation_token == UINT64_MAX - || owner_procno < 0 || now_us == 0 || now_us == UINT64_MAX - || !pcm_resource_x_terminal_x_lineage_args_valid( - successor_block, authenticated_master_node, - r4_record_generation, cached_ownership_generation)) + if (lineage_out == NULL || handle_out == NULL || reservation_token == 0 + || reservation_token == UINT64_MAX || owner_procno < 0 || now_us == 0 + || now_us == UINT64_MAX + || !pcm_resource_x_terminal_x_lineage_args_valid(successor_block, authenticated_master_node, + r4_record_generation, + cached_ownership_generation)) return RESOURCE_X_APPLY_INVALID; - if (!pcm_entry_ref_acquire( - &successor_block->common.logical_assertion.resource, false, - &entry_ref, &acquire_result)) + if (!pcm_entry_ref_acquire(&successor_block->common.logical_assertion.resource, false, + &entry_ref, &acquire_result)) return RESOURCE_X_APPLY_NOT_FOUND; entry = entry_ref.entry; pcm_entry_lock_exclusive(entry); round = &entry->resource_x_bootstrap_round; owner = &entry->resource_x_local_owner; - if (!pcm_resource_x_local_owner_valid_locked( - owner)) + if (!pcm_resource_x_local_owner_valid_locked(owner)) result = RESOURCE_X_APPLY_RECOVERY_BLOCKED; else if (pcm_resource_x_local_owner_expire_locked(entry, now_us)) { broadcast = true; @@ -16149,15 +15037,13 @@ cluster_pcm_lock_resource_x_terminal_x_revoke_claim_exact( : RESOURCE_X_APPLY_STALE; } else { lineage_matches = pcm_resource_x_terminal_x_lineage_locked( - entry, round, successor_block, authenticated_master_node, - r4_record_generation, cached_ownership_generation, false, - lineage_out); + entry, round, successor_block, authenticated_master_node, r4_record_generation, + cached_ownership_generation, false, lineage_out); if (owner->state == RESOURCE_X_LOCAL_OWNER_RECYCLING) { if (!lineage_matches) { broadcast = pcm_resource_x_local_owner_priority_clear_locked(entry); result = RESOURCE_X_APPLY_STALE; - } else if (pcm_resource_x_local_handoff_empty( - &owner->handoff)) { + } else if (pcm_resource_x_local_handoff_empty(&owner->handoff)) { result = pcm_resource_x_local_handoff_freeze_locked( entry, round, successor_block, authenticated_master_node, r4_record_generation, cached_ownership_generation, now_us); @@ -16167,33 +15053,28 @@ cluster_pcm_lock_resource_x_terminal_x_revoke_claim_exact( } } else result = pcm_resource_x_local_handoff_successor_exact( - &owner->handoff, successor_block, - authenticated_master_node, r4_record_generation, - cached_ownership_generation) - ? RESOURCE_X_APPLY_BAD_STATE - : RESOURCE_X_APPLY_STALE; + &owner->handoff, successor_block, authenticated_master_node, + r4_record_generation, cached_ownership_generation) + ? RESOURCE_X_APPLY_BAD_STATE + : RESOURCE_X_APPLY_STALE; } else if (owner->state == RESOURCE_X_LOCAL_OWNER_HANDOFF) { - if (!pcm_resource_x_local_handoff_valid(&owner->handoff) - || !lineage_matches - || !pcm_resource_x_local_handoff_round_current_locked( - &owner->handoff, round)) { + if (!pcm_resource_x_local_handoff_valid(&owner->handoff) || !lineage_matches + || !pcm_resource_x_local_handoff_round_current_locked(&owner->handoff, round)) { broadcast = pcm_resource_x_local_owner_priority_clear_locked(entry); result = RESOURCE_X_APPLY_STALE; } else if (!pcm_resource_x_local_handoff_successor_exact( - &owner->handoff, successor_block, - authenticated_master_node, r4_record_generation, - cached_ownership_generation)) + &owner->handoff, successor_block, authenticated_master_node, + r4_record_generation, cached_ownership_generation)) result = RESOURCE_X_APPLY_STALE; else { retained_handoff = owner->handoff; pcm_resource_x_local_owner_clear_locked(entry); result = pcm_resource_x_local_owner_claim_locked( - entry, RESOURCE_X_LOCAL_OWNER_REVOKING, - &retained_handoff.holder_ref, + entry, RESOURCE_X_LOCAL_OWNER_REVOKING, &retained_handoff.holder_ref, retained_handoff.master_session_incarnation, retained_handoff.r4_record_generation, - retained_handoff.buffer_ownership_generation, - reservation_token, owner_procno, handle_out); + retained_handoff.buffer_ownership_generation, reservation_token, owner_procno, + handle_out); if (result == RESOURCE_X_APPLY_APPLIED) { owner->handoff = retained_handoff; if (!pcm_resource_x_local_owner_valid_locked(owner)) @@ -16207,17 +15088,15 @@ cluster_pcm_lock_resource_x_terminal_x_revoke_claim_exact( * active owner is retryable. A conflicting successor must not be * allowed to hide behind the same generic BUSY disposition: reject it * as STALE without changing owner, HANDOFF, or the local deadline. */ - if (!pcm_resource_x_local_handoff_valid(&owner->handoff) - || !lineage_matches + if (!pcm_resource_x_local_handoff_valid(&owner->handoff) || !lineage_matches || !pcm_resource_x_local_handoff_round_current_locked(&owner->handoff, round)) result = RESOURCE_X_APPLY_STALE; else result = pcm_resource_x_local_handoff_successor_exact( - &owner->handoff, successor_block, - authenticated_master_node, r4_record_generation, - cached_ownership_generation) - ? RESOURCE_X_APPLY_BAD_STATE - : RESOURCE_X_APPLY_STALE; + &owner->handoff, successor_block, authenticated_master_node, + r4_record_generation, cached_ownership_generation) + ? RESOURCE_X_APPLY_BAD_STATE + : RESOURCE_X_APPLY_STALE; } else if (!lineage_matches) result = RESOURCE_X_APPLY_STALE; else { @@ -16228,17 +15107,15 @@ cluster_pcm_lock_resource_x_terminal_x_revoke_claim_exact( * survives if either exact step fails. */ memset(&retained_handoff, 0, sizeof(retained_handoff)); result = pcm_resource_x_local_handoff_build_locked( - &retained_handoff, round, successor_block, - authenticated_master_node, r4_record_generation, - cached_ownership_generation, now_us); + &retained_handoff, round, successor_block, authenticated_master_node, + r4_record_generation, cached_ownership_generation, now_us); if (result == RESOURCE_X_APPLY_APPLIED) result = pcm_resource_x_local_owner_claim_locked( - entry, RESOURCE_X_LOCAL_OWNER_REVOKING, - &retained_handoff.holder_ref, + entry, RESOURCE_X_LOCAL_OWNER_REVOKING, &retained_handoff.holder_ref, retained_handoff.master_session_incarnation, retained_handoff.r4_record_generation, - retained_handoff.buffer_ownership_generation, - reservation_token, owner_procno, handle_out); + retained_handoff.buffer_ownership_generation, reservation_token, owner_procno, + handle_out); if (result == RESOURCE_X_APPLY_APPLIED) { owner->handoff = retained_handoff; if (!pcm_resource_x_local_owner_valid_locked(owner)) { @@ -16263,9 +15140,8 @@ cluster_pcm_lock_resource_x_terminal_x_revoke_claim_exact( * refreshes the HANDOFF owner or its original absolute deadline. */ ResourceXApplyResult cluster_pcm_lock_resource_x_terminal_x_revoke_replay_exact( - const ResourceXDecodedFrame *successor_block, - int32 authenticated_master_node, uint64 r4_record_generation, - uint64 cached_ownership_generation, uint64 now_us, + const ResourceXDecodedFrame *successor_block, int32 authenticated_master_node, + uint64 r4_record_generation, uint64 cached_ownership_generation, uint64 now_us, ResourceXTerminalXLineage *lineage_out) { ClusterPcmResourceXBootstrapRound *round; @@ -16278,13 +15154,12 @@ cluster_pcm_lock_resource_x_terminal_x_revoke_replay_exact( if (lineage_out != NULL) memset(lineage_out, 0, sizeof(*lineage_out)); if (lineage_out == NULL || now_us == 0 || now_us == UINT64_MAX - || !pcm_resource_x_terminal_x_lineage_args_valid( - successor_block, authenticated_master_node, - r4_record_generation, cached_ownership_generation)) + || !pcm_resource_x_terminal_x_lineage_args_valid(successor_block, authenticated_master_node, + r4_record_generation, + cached_ownership_generation)) return RESOURCE_X_APPLY_INVALID; - if (!pcm_entry_ref_acquire( - &successor_block->common.logical_assertion.resource, false, - &entry_ref, &acquire_result)) + if (!pcm_entry_ref_acquire(&successor_block->common.logical_assertion.resource, false, + &entry_ref, &acquire_result)) return RESOURCE_X_APPLY_NOT_FOUND; entry = entry_ref.entry; @@ -16304,8 +15179,8 @@ cluster_pcm_lock_resource_x_terminal_x_revoke_replay_exact( cached_ownership_generation, false, lineage_out)) result = RESOURCE_X_APPLY_RECOVERY_BLOCKED; else if (!pcm_resource_x_local_handoff_successor_exact( - &owner->handoff, successor_block, authenticated_master_node, - r4_record_generation, cached_ownership_generation)) + &owner->handoff, successor_block, authenticated_master_node, r4_record_generation, + cached_ownership_generation)) result = RESOURCE_X_APPLY_STALE; else result = RESOURCE_X_APPLY_BAD_STATE; @@ -16316,11 +15191,9 @@ cluster_pcm_lock_resource_x_terminal_x_revoke_replay_exact( bool cluster_pcm_lock_resource_x_terminal_x_revoke_revalidate_held_exact( - const ResourceXDecodedFrame *successor_block, - int32 authenticated_master_node, uint64 r4_record_generation, - uint64 cached_ownership_generation, - const ResourceXLocalOwnerHandle *handle, - ResourceXTerminalXLineage *lineage_out) + const ResourceXDecodedFrame *successor_block, int32 authenticated_master_node, + uint64 r4_record_generation, uint64 cached_ownership_generation, + const ResourceXLocalOwnerHandle *handle, ResourceXTerminalXLineage *lineage_out) { ClusterPcmResourceXBootstrapRound *round; PcmEntryRef entry_ref; @@ -16330,15 +15203,13 @@ cluster_pcm_lock_resource_x_terminal_x_revoke_revalidate_held_exact( if (lineage_out != NULL) memset(lineage_out, 0, sizeof(*lineage_out)); - if (lineage_out == NULL - || !pcm_resource_x_local_owner_handle_valid(handle) - || !pcm_resource_x_terminal_x_lineage_args_valid( - successor_block, authenticated_master_node, - r4_record_generation, cached_ownership_generation)) + if (lineage_out == NULL || !pcm_resource_x_local_owner_handle_valid(handle) + || !pcm_resource_x_terminal_x_lineage_args_valid(successor_block, authenticated_master_node, + r4_record_generation, + cached_ownership_generation)) return false; - if (!pcm_entry_ref_acquire( - &successor_block->common.logical_assertion.resource, false, - &entry_ref, &acquire_result)) + if (!pcm_entry_ref_acquire(&successor_block->common.logical_assertion.resource, false, + &entry_ref, &acquire_result)) return false; entry = entry_ref.entry; LWLockAcquire(&entry->entry_lock.lock, LW_SHARED); @@ -16366,11 +15237,9 @@ cluster_pcm_lock_resource_x_terminal_x_revoke_revalidate_held_exact( * process-local owner in one entry-lock critical section. */ ResourceXApplyResult cluster_pcm_lock_resource_x_terminal_x_revoke_finish_drop_exact( - const ResourceXDecodedFrame *successor_block, - int32 authenticated_master_node, uint64 r4_record_generation, - const ClusterPcmOwnSnapshot *revoking, - const ClusterPcmOwnSnapshot *dropped, - const ResourceXLocalOwnerHandle *handle) + const ResourceXDecodedFrame *successor_block, int32 authenticated_master_node, + uint64 r4_record_generation, const ClusterPcmOwnSnapshot *revoking, + const ClusterPcmOwnSnapshot *dropped, const ResourceXLocalOwnerHandle *handle) { ClusterPcmResourceXBootstrapRound *round; ClusterPcmResourceXLocalOwner *owner; @@ -16382,36 +15251,25 @@ cluster_pcm_lock_resource_x_terminal_x_revoke_finish_drop_exact( bool broadcast = false; memset(&lineage, 0, sizeof(lineage)); - if (!pcm_resource_x_local_owner_handle_valid(handle) - || revoking == NULL || dropped == NULL - || !pcm_resource_x_terminal_x_lineage_args_valid( - successor_block, authenticated_master_node, - r4_record_generation, revoking->generation) - || revoking->pcm_state != (uint8)PCM_STATE_X - || revoking->flags != PCM_OWN_FLAG_REVOKING - || revoking->generation == 0 - || revoking->generation == UINT64_MAX - || revoking->reservation_token == 0 - || revoking->reservation_token == UINT64_MAX - || revoking->writer_activation_token != 0 - || revoking->resource_x_activation_generation != 0 - || dropped->pcm_state != (uint8)PCM_STATE_N - || dropped->flags != 0 - || dropped->writer_activation_token != 0 - || dropped->resource_x_activation_generation != 0) + if (!pcm_resource_x_local_owner_handle_valid(handle) || revoking == NULL || dropped == NULL + || !pcm_resource_x_terminal_x_lineage_args_valid(successor_block, authenticated_master_node, + r4_record_generation, revoking->generation) + || revoking->pcm_state != (uint8)PCM_STATE_X || revoking->flags != PCM_OWN_FLAG_REVOKING + || revoking->generation == 0 || revoking->generation == UINT64_MAX + || revoking->reservation_token == 0 || revoking->reservation_token == UINT64_MAX + || revoking->writer_activation_token != 0 || revoking->resource_x_activation_generation != 0 + || dropped->pcm_state != (uint8)PCM_STATE_N || dropped->flags != 0 + || dropped->writer_activation_token != 0 || dropped->resource_x_activation_generation != 0) return RESOURCE_X_APPLY_INVALID; if (!BufferTagsEqual(&revoking->tag, &dropped->tag) - || !BufferTagsEqual( - &revoking->tag, - &successor_block->common.logical_assertion.resource) + || !BufferTagsEqual(&revoking->tag, &successor_block->common.logical_assertion.resource) || dropped->generation != revoking->generation + 1 || dropped->reservation_token != revoking->reservation_token || handle->buffer_ownership_generation != revoking->generation || revoking->reservation_token != handle->reservation_token + 1 || handle->r4_record_generation != r4_record_generation) return RESOURCE_X_APPLY_STALE; - if (!pcm_entry_ref_acquire(&revoking->tag, false, - &entry_ref, &acquire_result)) + if (!pcm_entry_ref_acquire(&revoking->tag, false, &entry_ref, &acquire_result)) return RESOURCE_X_APPLY_NOT_FOUND; entry = entry_ref.entry; @@ -16423,25 +15281,20 @@ cluster_pcm_lock_resource_x_terminal_x_revoke_finish_drop_exact( else if (owner->state == RESOURCE_X_LOCAL_OWNER_EMPTY) result = RESOURCE_X_APPLY_NOT_FOUND; else if (owner->state != RESOURCE_X_LOCAL_OWNER_REVOKING - || !pcm_resource_x_local_owner_handle_equal( - &owner->handle, handle) - || !pcm_resource_x_local_handoff_valid(&owner->handoff) - || !pcm_resource_x_local_handoff_successor_exact( - &owner->handoff, successor_block, - authenticated_master_node, r4_record_generation, - revoking->generation) - || !pcm_resource_x_local_handoff_round_current_locked( - &owner->handoff, round) - || !cluster_pcm_lock_resource_x_gate_open_exact( - successor_block->common.resource_formation) - || !pcm_resource_x_terminal_x_lineage_locked( - entry, round, successor_block, authenticated_master_node, - r4_record_generation, revoking->generation, false, &lineage) - || !pcm_resource_x_bootstrap_round_terminal_cover_exact_locked( - entry, round, &handle->ref, - handle->master_session_incarnation, - handle->r4_record_generation, - handle->buffer_ownership_generation)) + || !pcm_resource_x_local_owner_handle_equal(&owner->handle, handle) + || !pcm_resource_x_local_handoff_valid(&owner->handoff) + || !pcm_resource_x_local_handoff_successor_exact( + &owner->handoff, successor_block, authenticated_master_node, r4_record_generation, + revoking->generation) + || !pcm_resource_x_local_handoff_round_current_locked(&owner->handoff, round) + || !cluster_pcm_lock_resource_x_gate_open_exact( + successor_block->common.resource_formation) + || !pcm_resource_x_terminal_x_lineage_locked( + entry, round, successor_block, authenticated_master_node, r4_record_generation, + revoking->generation, false, &lineage) + || !pcm_resource_x_bootstrap_round_terminal_cover_exact_locked( + entry, round, &handle->ref, handle->master_session_incarnation, + handle->r4_record_generation, handle->buffer_ownership_generation)) result = RESOURCE_X_APPLY_STALE; else { pcm_resource_x_bootstrap_round_clear_binding_locked(round); @@ -16461,8 +15314,8 @@ cluster_pcm_lock_resource_x_terminal_x_revoke_finish_drop_exact( * not consume HANDOFF simply leaves the local-owner slot empty. The first * observation deadline and owner-generation floor are never refreshed. */ ResourceXApplyResult -cluster_pcm_lock_resource_x_terminal_x_revoke_yield_exact( - const ResourceXLocalOwnerHandle *handle, uint64 now_us) +cluster_pcm_lock_resource_x_terminal_x_revoke_yield_exact(const ResourceXLocalOwnerHandle *handle, + uint64 now_us) { ClusterPcmResourceXBootstrapRound *round; ClusterPcmResourceXLocalOwner *owner; @@ -16472,11 +15325,9 @@ cluster_pcm_lock_resource_x_terminal_x_revoke_yield_exact( ResourceXApplyResult result; bool broadcast = false; - if (!pcm_resource_x_local_owner_handle_valid(handle) - || now_us == 0 || now_us == UINT64_MAX) + if (!pcm_resource_x_local_owner_handle_valid(handle) || now_us == 0 || now_us == UINT64_MAX) return RESOURCE_X_APPLY_INVALID; - if (!pcm_entry_ref_acquire(&handle->ref.assertion.resource, false, - &entry_ref, &acquire_result)) + if (!pcm_entry_ref_acquire(&handle->ref.assertion.resource, false, &entry_ref, &acquire_result)) return RESOURCE_X_APPLY_NOT_FOUND; entry = entry_ref.entry; pcm_entry_lock_exclusive(entry); @@ -16485,20 +15336,15 @@ cluster_pcm_lock_resource_x_terminal_x_revoke_yield_exact( if (!pcm_resource_x_local_owner_valid_locked(owner)) result = RESOURCE_X_APPLY_RECOVERY_BLOCKED; else if (owner->state != RESOURCE_X_LOCAL_OWNER_REVOKING - || !pcm_resource_x_local_owner_handle_equal( - &owner->handle, handle)) + || !pcm_resource_x_local_owner_handle_equal(&owner->handle, handle)) result = RESOURCE_X_APPLY_STALE; else if (pcm_resource_x_local_handoff_valid(&owner->handoff)) { if (now_us >= owner->handoff.deadline_us - || !cluster_pcm_lock_resource_x_gate_open_exact( - handle->ref.formation) + || !cluster_pcm_lock_resource_x_gate_open_exact(handle->ref.formation) || !pcm_resource_x_bootstrap_round_terminal_cover_exact_locked( - entry, round, &handle->ref, - handle->master_session_incarnation, - handle->r4_record_generation, - handle->buffer_ownership_generation) - || !pcm_resource_x_local_handoff_round_current_locked( - &owner->handoff, round)) { + entry, round, &handle->ref, handle->master_session_incarnation, + handle->r4_record_generation, handle->buffer_ownership_generation) + || !pcm_resource_x_local_handoff_round_current_locked(&owner->handoff, round)) { pcm_resource_x_local_owner_clear_locked(entry); broadcast = true; result = RESOURCE_X_APPLY_STALE; @@ -16524,8 +15370,7 @@ cluster_pcm_lock_resource_x_terminal_x_revoke_yield_exact( } ResourceXApplyResult -cluster_pcm_lock_resource_x_terminal_x_revoke_release_exact( - const ResourceXLocalOwnerHandle *handle) +cluster_pcm_lock_resource_x_terminal_x_revoke_release_exact(const ResourceXLocalOwnerHandle *handle) { PcmEntryRef entry_ref; PcmEntryAcquireResult acquire_result; @@ -16534,13 +15379,12 @@ cluster_pcm_lock_resource_x_terminal_x_revoke_release_exact( if (!pcm_resource_x_local_owner_handle_valid(handle)) return RESOURCE_X_APPLY_INVALID; - if (!pcm_entry_ref_acquire(&handle->ref.assertion.resource, false, - &entry_ref, &acquire_result)) + if (!pcm_entry_ref_acquire(&handle->ref.assertion.resource, false, &entry_ref, &acquire_result)) return RESOURCE_X_APPLY_NOT_FOUND; entry = entry_ref.entry; pcm_entry_lock_exclusive(entry); - result = pcm_resource_x_local_owner_release_locked( - entry, RESOURCE_X_LOCAL_OWNER_REVOKING, handle); + result + = pcm_resource_x_local_owner_release_locked(entry, RESOURCE_X_LOCAL_OWNER_REVOKING, handle); if (result == RESOURCE_X_APPLY_APPLIED) ConditionVariableBroadcast(&entry->wait_cv); LWLockRelease(&entry->entry_lock.lock); @@ -16561,30 +15405,24 @@ cluster_pcm_lock_resource_x_bootstrap_round_publish_terminal_exact( ResourceXApplyResult result; bool broadcast = false; - if (!pcm_resource_x_ref_valid(ref) - || master_session_incarnation == 0 - || master_session_incarnation == UINT64_MAX - || r4_record_generation == 0 - || r4_record_generation == UINT64_MAX - || cached_ownership_generation == 0 - || cached_ownership_generation == UINT64_MAX - || terminal_authority_generation == 0 - || terminal_authority_generation == UINT64_MAX - || now_us == 0 || now_us == UINT64_MAX) + if (!pcm_resource_x_ref_valid(ref) || master_session_incarnation == 0 + || master_session_incarnation == UINT64_MAX || r4_record_generation == 0 + || r4_record_generation == UINT64_MAX || cached_ownership_generation == 0 + || cached_ownership_generation == UINT64_MAX || terminal_authority_generation == 0 + || terminal_authority_generation == UINT64_MAX || now_us == 0 || now_us == UINT64_MAX) return RESOURCE_X_APPLY_INVALID; - if (!pcm_entry_ref_acquire(&ref->assertion.resource, false, - &entry_ref, &acquire_result)) + if (!pcm_entry_ref_acquire(&ref->assertion.resource, false, &entry_ref, &acquire_result)) return RESOURCE_X_APPLY_NOT_FOUND; entry = entry_ref.entry; pcm_entry_lock_exclusive(entry); round = &entry->resource_x_bootstrap_round; if (pcm_resource_x_bootstrap_round_terminal_cover_exact_locked( - entry, round, ref, master_session_incarnation, - r4_record_generation, cached_ownership_generation)) - result = round->terminal_authority_generation - == terminal_authority_generation - ? RESOURCE_X_APPLY_DUPLICATE : RESOURCE_X_APPLY_STALE; + entry, round, ref, master_session_incarnation, r4_record_generation, + cached_ownership_generation)) + result = round->terminal_authority_generation == terminal_authority_generation + ? RESOURCE_X_APPLY_DUPLICATE + : RESOURCE_X_APPLY_STALE; else if (round->phase != RESOURCE_X_BOOTSTRAP_ROUND_ASSERT_DISPATCHED || !resource_x_assertion_equal(&round->request.logical_assertion, &ref->assertion) || round->resource_formation != ref->formation @@ -16600,8 +15438,7 @@ cluster_pcm_lock_resource_x_bootstrap_round_publish_terminal_exact( result = RESOURCE_X_APPLY_STALE; else { round->terminal_ref = *ref; - round->terminal_authority_generation - = terminal_authority_generation; + round->terminal_authority_generation = terminal_authority_generation; round->cached_ownership_generation = cached_ownership_generation; round->phase = RESOURCE_X_BOOTSTRAP_ROUND_TERMINAL_X_CACHED; broadcast = true; @@ -16617,9 +15454,10 @@ cluster_pcm_lock_resource_x_bootstrap_round_publish_terminal_exact( } bool -cluster_pcm_lock_resource_x_bootstrap_round_cover_matches_exact( - const ResourceXAcquisitionRef *ref, uint64 master_session_incarnation, - uint64 r4_record_generation, uint64 cached_ownership_generation) +cluster_pcm_lock_resource_x_bootstrap_round_cover_matches_exact(const ResourceXAcquisitionRef *ref, + uint64 master_session_incarnation, + uint64 r4_record_generation, + uint64 cached_ownership_generation) { ClusterPcmResourceXBootstrapRound *round; PcmEntryRef entry_ref; @@ -16627,68 +15465,58 @@ cluster_pcm_lock_resource_x_bootstrap_round_cover_matches_exact( struct GrdEntry *entry; bool matches; - if (!pcm_resource_x_ref_valid(ref) - || master_session_incarnation == 0 - || master_session_incarnation == UINT64_MAX - || r4_record_generation == 0 - || r4_record_generation == UINT64_MAX - || cached_ownership_generation == 0 + if (!pcm_resource_x_ref_valid(ref) || master_session_incarnation == 0 + || master_session_incarnation == UINT64_MAX || r4_record_generation == 0 + || r4_record_generation == UINT64_MAX || cached_ownership_generation == 0 || cached_ownership_generation == UINT64_MAX) return false; - if (!pcm_entry_ref_acquire(&ref->assertion.resource, false, - &entry_ref, &acquire_result)) + if (!pcm_entry_ref_acquire(&ref->assertion.resource, false, &entry_ref, &acquire_result)) return false; entry = entry_ref.entry; LWLockAcquire(&entry->entry_lock.lock, LW_SHARED); round = &entry->resource_x_bootstrap_round; matches = pcm_resource_x_bootstrap_round_terminal_cover_exact_locked( - entry, round, ref, master_session_incarnation, - r4_record_generation, cached_ownership_generation); + entry, round, ref, master_session_incarnation, r4_record_generation, + cached_ownership_generation); LWLockRelease(&entry->entry_lock.lock); pcm_entry_ref_release(&entry_ref); return matches; } static void -pcm_resource_x_target_evict_release_build_locked( - const ClusterPcmResourceXBootstrapRound *round, - uint32 sender_connection_generation, ResourceXDecodedFrame *release_out) +pcm_resource_x_target_evict_release_build_locked(const ClusterPcmResourceXBootstrapRound *round, + uint32 sender_connection_generation, + ResourceXDecodedFrame *release_out) { Assert(round != NULL); Assert(release_out != NULL); - Assert(sender_connection_generation != 0 - && sender_connection_generation != UINT32_MAX); + Assert(sender_connection_generation != 0 && sender_connection_generation != UINT32_MAX); memset(release_out, 0, sizeof(*release_out)); release_out->kind = RESOURCE_X_WIRE_RELEASE_X; release_out->payload_bytes = RESOURCE_X_CONTROL_V1_BYTES; release_out->common.logical_assertion = round->terminal_ref.assertion; release_out->common.base_authority_generation = round->accepted_base; - release_out->common.authority_generation - = round->terminal_authority_generation; + release_out->common.authority_generation = round->terminal_authority_generation; release_out->common.resource_formation = round->resource_formation; - release_out->common.master_session_incarnation - = round->master_session_incarnation; - release_out->common.assertion_sequence - = round->terminal_ref.acquisition_generation; + release_out->common.master_session_incarnation = round->master_session_incarnation; + release_out->common.assertion_sequence = round->terminal_ref.acquisition_generation; release_out->common.ordered_lane = round->request.ordered_lane; - release_out->common.action_node - = round->terminal_ref.assertion.requester_node; + release_out->common.action_node = round->terminal_ref.assertion.requester_node; release_out->common.observed_mode = (uint8)PCM_STATE_X; release_out->common.target_mode = (uint8)PCM_STATE_N; - release_out->common.sender_connection_generation - = sender_connection_generation; + release_out->common.sender_connection_generation = sender_connection_generation; release_out->common.outcome = RESOURCE_X_OUTCOME_OK; } static bool -pcm_resource_x_target_evict_owner_exact_locked( - const ClusterPcmResourceXLocalOwner *owner, - const ClusterPcmResourceXBootstrapRound *round, - uint64 master_session_incarnation, uint64 r4_record_generation, - uint64 cached_ownership_generation, uint64 reservation_token, - int32 owner_procno) +pcm_resource_x_target_evict_owner_exact_locked(const ClusterPcmResourceXLocalOwner *owner, + const ClusterPcmResourceXBootstrapRound *round, + uint64 master_session_incarnation, + uint64 r4_record_generation, + uint64 cached_ownership_generation, + uint64 reservation_token, int32 owner_procno) { return pcm_resource_x_local_owner_valid_locked(owner) && owner->state == RESOURCE_X_LOCAL_OWNER_EVICTING @@ -16703,11 +15531,10 @@ pcm_resource_x_target_evict_owner_exact_locked( ResourceXApplyResult cluster_pcm_lock_resource_x_target_evict_prepare_exact( - const BufferTag *tag, int32 current_master_node, - uint64 resource_formation, uint64 master_session_incarnation, - uint64 r4_record_generation, uint64 cached_ownership_generation, - uint64 reservation_token, uint32 sender_connection_generation, - int32 owner_procno, ResourceXDecodedFrame *release_out, + const BufferTag *tag, int32 current_master_node, uint64 resource_formation, + uint64 master_session_incarnation, uint64 r4_record_generation, + uint64 cached_ownership_generation, uint64 reservation_token, + uint32 sender_connection_generation, int32 owner_procno, ResourceXDecodedFrame *release_out, ResourceXLocalOwnerHandle *handle_out) { ClusterPcmResourceXBootstrapRound *round; @@ -16724,20 +15551,14 @@ cluster_pcm_lock_resource_x_target_evict_prepare_exact( memset(release_out, 0, sizeof(*release_out)); if (handle_out != NULL) memset(handle_out, 0, sizeof(*handle_out)); - if (tag == NULL || release_out == NULL || handle_out == NULL - || current_master_node < 0 - || current_master_node >= RESOURCE_X_PROTOCOL_NODE_LIMIT - || resource_formation == 0 || resource_formation == UINT64_MAX - || master_session_incarnation == 0 - || master_session_incarnation == UINT64_MAX - || r4_record_generation == 0 - || r4_record_generation == UINT64_MAX - || cached_ownership_generation == 0 - || cached_ownership_generation == UINT64_MAX - || reservation_token == 0 || reservation_token == UINT64_MAX - || sender_connection_generation == 0 - || sender_connection_generation == UINT32_MAX - || owner_procno < 0) + if (tag == NULL || release_out == NULL || handle_out == NULL || current_master_node < 0 + || current_master_node >= RESOURCE_X_PROTOCOL_NODE_LIMIT || resource_formation == 0 + || resource_formation == UINT64_MAX || master_session_incarnation == 0 + || master_session_incarnation == UINT64_MAX || r4_record_generation == 0 + || r4_record_generation == UINT64_MAX || cached_ownership_generation == 0 + || cached_ownership_generation == UINT64_MAX || reservation_token == 0 + || reservation_token == UINT64_MAX || sender_connection_generation == 0 + || sender_connection_generation == UINT32_MAX || owner_procno < 0) return RESOURCE_X_APPLY_INVALID; if (!pcm_entry_ref_acquire(tag, false, &entry_ref, &acquire_result)) return RESOURCE_X_APPLY_NOT_FOUND; @@ -16756,34 +15577,30 @@ cluster_pcm_lock_resource_x_target_evict_prepare_exact( || round->r4_record_generation != r4_record_generation || !cluster_pcm_lock_resource_x_gate_open_exact(resource_formation) || !pcm_resource_x_bootstrap_round_terminal_cover_exact_locked( - entry, round, &round->terminal_ref, - master_session_incarnation, r4_record_generation, + entry, round, &round->terminal_ref, master_session_incarnation, r4_record_generation, cached_ownership_generation)) result = RESOURCE_X_APPLY_STALE; else if (!pcm_resource_x_local_owner_valid_locked(owner)) result = RESOURCE_X_APPLY_RECOVERY_BLOCKED; - else if (current_master_node == cluster_node_id - && master_state == NULL) + else if (current_master_node == cluster_node_id && master_state == NULL) result = RESOURCE_X_APPLY_RECOVERY_BLOCKED; else if (successor != NULL) result = RESOURCE_X_APPLY_BAD_STATE; else if (owner->state == RESOURCE_X_LOCAL_OWNER_EMPTY) { result = pcm_resource_x_local_owner_claim_locked( - entry, RESOURCE_X_LOCAL_OWNER_EVICTING, - &round->terminal_ref, master_session_incarnation, - r4_record_generation, cached_ownership_generation, + entry, RESOURCE_X_LOCAL_OWNER_EVICTING, &round->terminal_ref, + master_session_incarnation, r4_record_generation, cached_ownership_generation, reservation_token, owner_procno, handle_out); if (result == RESOURCE_X_APPLY_APPLIED) { - pcm_resource_x_target_evict_release_build_locked( - round, sender_connection_generation, release_out); + pcm_resource_x_target_evict_release_build_locked(round, sender_connection_generation, + release_out); broadcast = true; } } else if (pcm_resource_x_target_evict_owner_exact_locked( - owner, round, master_session_incarnation, - r4_record_generation, cached_ownership_generation, - reservation_token, owner_procno)) { - pcm_resource_x_target_evict_release_build_locked( - round, sender_connection_generation, release_out); + owner, round, master_session_incarnation, r4_record_generation, + cached_ownership_generation, reservation_token, owner_procno)) { + pcm_resource_x_target_evict_release_build_locked(round, sender_connection_generation, + release_out); *handle_out = owner->handle; result = RESOURCE_X_APPLY_DUPLICATE; } else @@ -16796,8 +15613,7 @@ cluster_pcm_lock_resource_x_target_evict_prepare_exact( } ResourceXApplyResult -cluster_pcm_lock_resource_x_target_evict_abort_exact( - const ResourceXLocalOwnerHandle *handle) +cluster_pcm_lock_resource_x_target_evict_abort_exact(const ResourceXLocalOwnerHandle *handle) { ClusterPcmResourceXBootstrapRound *round; PcmEntryRef entry_ref; @@ -16807,8 +15623,7 @@ cluster_pcm_lock_resource_x_target_evict_abort_exact( if (!pcm_resource_x_local_owner_handle_valid(handle)) return RESOURCE_X_APPLY_INVALID; - if (!pcm_entry_ref_acquire(&handle->ref.assertion.resource, false, - &entry_ref, &acquire_result)) + if (!pcm_entry_ref_acquire(&handle->ref.assertion.resource, false, &entry_ref, &acquire_result)) return RESOURCE_X_APPLY_NOT_FOUND; entry = entry_ref.entry; pcm_entry_lock_exclusive(entry); @@ -16819,8 +15634,8 @@ cluster_pcm_lock_resource_x_target_evict_abort_exact( || handle->absolute_deadline_us != round->head_no_progress_deadline_us) result = RESOURCE_X_APPLY_STALE; else - result = pcm_resource_x_local_owner_release_locked( - entry, RESOURCE_X_LOCAL_OWNER_EVICTING, handle); + result = pcm_resource_x_local_owner_release_locked(entry, RESOURCE_X_LOCAL_OWNER_EVICTING, + handle); if (result == RESOURCE_X_APPLY_APPLIED) ConditionVariableBroadcast(&entry->wait_cv); LWLockRelease(&entry->entry_lock.lock); @@ -16830,28 +15645,21 @@ cluster_pcm_lock_resource_x_target_evict_abort_exact( static bool pcm_resource_x_target_evict_release_matches_locked( - struct GrdEntry *entry, - const ClusterPcmResourceXBootstrapRound *round, - const ResourceXDecodedFrame *release, int32 current_master_node, - uint64 r4_record_generation, uint64 cached_ownership_generation, - const ResourceXLocalOwnerHandle *handle) + struct GrdEntry *entry, const ClusterPcmResourceXBootstrapRound *round, + const ResourceXDecodedFrame *release, int32 current_master_node, uint64 r4_record_generation, + uint64 cached_ownership_generation, const ResourceXLocalOwnerHandle *handle) { const ResourceXDecodedCommon *common; Assert(entry != NULL); Assert(round != NULL); - Assert(LWLockHeldByMeInMode( - &entry->entry_lock.lock, LW_EXCLUSIVE)); + Assert(LWLockHeldByMeInMode(&entry->entry_lock.lock, LW_EXCLUSIVE)); if (release == NULL || release->kind != RESOURCE_X_WIRE_RELEASE_X || release->payload_bytes != RESOURCE_X_CONTROL_V1_BYTES - || release->blocked_has_remote_proof - || !pcm_resource_x_local_owner_handle_valid(handle) - || current_master_node < 0 - || current_master_node >= RESOURCE_X_PROTOCOL_NODE_LIMIT - || r4_record_generation == 0 - || r4_record_generation == UINT64_MAX - || cached_ownership_generation == 0 - || cached_ownership_generation == UINT64_MAX) + || release->blocked_has_remote_proof || !pcm_resource_x_local_owner_handle_valid(handle) + || current_master_node < 0 || current_master_node >= RESOURCE_X_PROTOCOL_NODE_LIMIT + || r4_record_generation == 0 || r4_record_generation == UINT64_MAX + || cached_ownership_generation == 0 || cached_ownership_generation == UINT64_MAX) return false; common = &release->common; return resource_x_assertion_valid(&common->logical_assertion) @@ -16881,10 +15689,11 @@ pcm_resource_x_target_evict_release_matches_locked( } ResourceXApplyResult -cluster_pcm_lock_resource_x_target_evict_commit_exact( - const ResourceXDecodedFrame *release, int32 current_master_node, - uint64 r4_record_generation, uint64 cached_ownership_generation, - const ResourceXLocalOwnerHandle *handle) +cluster_pcm_lock_resource_x_target_evict_commit_exact(const ResourceXDecodedFrame *release, + int32 current_master_node, + uint64 r4_record_generation, + uint64 cached_ownership_generation, + const ResourceXLocalOwnerHandle *handle) { ClusterPcmResourceXBootstrapRound *round; PcmEntryRef entry_ref; @@ -16895,16 +15704,15 @@ cluster_pcm_lock_resource_x_target_evict_commit_exact( if (release == NULL || !pcm_resource_x_local_owner_handle_valid(handle)) return RESOURCE_X_APPLY_INVALID; - if (!pcm_entry_ref_acquire( - &release->common.logical_assertion.resource, false, - &entry_ref, &acquire_result)) + if (!pcm_entry_ref_acquire(&release->common.logical_assertion.resource, false, &entry_ref, + &acquire_result)) return RESOURCE_X_APPLY_NOT_FOUND; entry = entry_ref.entry; pcm_entry_lock_exclusive(entry); round = &entry->resource_x_bootstrap_round; if (!pcm_resource_x_target_evict_release_matches_locked( - entry, round, release, current_master_node, - r4_record_generation, cached_ownership_generation, handle) + entry, round, release, current_master_node, r4_record_generation, + cached_ownership_generation, handle) || !pcm_entry_mark_quiescing_locked(entry)) { LWLockRelease(&entry->entry_lock.lock); pcm_entry_ref_release(&entry_ref); @@ -16918,7 +15726,7 @@ cluster_pcm_lock_resource_x_target_evict_commit_exact( LWLockRelease(&entry->entry_lock.lock); pcm_entry_ref_release(&entry_ref); (void)pcm_entry_try_retire_exact(&retire_tag, retire_generation, - PCM_RETIRE_REASON_RESOURCE_X_SETTLED); + PCM_RETIRE_REASON_RESOURCE_X_SETTLED); return RESOURCE_X_APPLY_APPLIED; } @@ -16929,36 +15737,28 @@ cluster_pcm_lock_resource_x_target_evict_commit_exact( * highest_attempt_floor and the retired acquisition floor remain monotone. */ ResourceXApplyResult cluster_pcm_lock_resource_x_bootstrap_round_invalidate_ownership_loss_exact( - const ResourceXAssertion *assertion, int32 current_master_node, - uint64 resource_formation, uint64 master_session_incarnation, - uint64 r4_record_generation, - uint32 requester_sender_connection_generation, - uint32 master_ingress_connection_generation, uint64 retry_slice_us, - const ClusterPcmOwnSnapshot *observed) + const ResourceXAssertion *assertion, int32 current_master_node, uint64 resource_formation, + uint64 master_session_incarnation, uint64 r4_record_generation, + uint32 requester_sender_connection_generation, uint32 master_ingress_connection_generation, + uint64 retry_slice_us, const ClusterPcmOwnSnapshot *observed) { PcmEntryRef entry_ref; PcmEntryAcquireResult acquire_result; struct GrdEntry *entry; ResourceXApplyResult result; - if (!resource_x_assertion_valid(assertion) - || assertion->requester_node != cluster_node_id - || current_master_node < 0 - || current_master_node >= RESOURCE_X_PROTOCOL_NODE_LIMIT + if (!resource_x_assertion_valid(assertion) || assertion->requester_node != cluster_node_id + || current_master_node < 0 || current_master_node >= RESOURCE_X_PROTOCOL_NODE_LIMIT || resource_formation == 0 || resource_formation == UINT64_MAX - || master_session_incarnation == 0 - || master_session_incarnation == UINT64_MAX - || r4_record_generation == 0 - || r4_record_generation == UINT64_MAX + || master_session_incarnation == 0 || master_session_incarnation == UINT64_MAX + || r4_record_generation == 0 || r4_record_generation == UINT64_MAX || requester_sender_connection_generation == 0 || requester_sender_connection_generation == UINT32_MAX || master_ingress_connection_generation == 0 - || master_ingress_connection_generation == UINT32_MAX - || retry_slice_us == 0 || retry_slice_us == UINT64_MAX - || observed == NULL) + || master_ingress_connection_generation == UINT32_MAX || retry_slice_us == 0 + || retry_slice_us == UINT64_MAX || observed == NULL) return RESOURCE_X_APPLY_INVALID; - if (!pcm_entry_ref_acquire(&assertion->resource, false, - &entry_ref, &acquire_result)) + if (!pcm_entry_ref_acquire(&assertion->resource, false, &entry_ref, &acquire_result)) return RESOURCE_X_APPLY_NOT_FOUND; entry = entry_ref.entry; @@ -16994,19 +15794,13 @@ cluster_pcm_lock_resource_x_bootstrap_round_x_to_s_preflight_exact( struct GrdEntry *entry; ResourceXApplyResult result; - if (current == NULL - || current->pcm_state != (uint8)PCM_STATE_X - || current->flags != 0 - || current->generation == 0 - || current->generation == UINT64_MAX - || current->reservation_token == 0 - || current->reservation_token == UINT64_MAX) + if (current == NULL || current->pcm_state != (uint8)PCM_STATE_X || current->flags != 0 + || current->generation == 0 || current->generation == UINT64_MAX + || current->reservation_token == 0 || current->reservation_token == UINT64_MAX) return RESOURCE_X_APPLY_INVALID; - if (current->writer_activation_token != 0 - || current->resource_x_activation_generation != 0) + if (current->writer_activation_token != 0 || current->resource_x_activation_generation != 0) return RESOURCE_X_APPLY_BAD_STATE; - if (!pcm_entry_ref_acquire(¤t->tag, false, - &entry_ref, &acquire_result)) + if (!pcm_entry_ref_acquire(¤t->tag, false, &entry_ref, &acquire_result)) return RESOURCE_X_APPLY_NOT_FOUND; entry = entry_ref.entry; @@ -17016,20 +15810,16 @@ cluster_pcm_lock_resource_x_bootstrap_round_x_to_s_preflight_exact( result = RESOURCE_X_APPLY_NOT_FOUND; else if (round->delivery_target.buffer_id_plus_one != 0) result = RESOURCE_X_APPLY_BAD_STATE; - else if (!pcm_resource_x_local_owner_valid_locked( - &entry->resource_x_local_owner)) + else if (!pcm_resource_x_local_owner_valid_locked(&entry->resource_x_local_owner)) result = RESOURCE_X_APPLY_RECOVERY_BLOCKED; - else if (entry->resource_x_local_owner.state - != RESOURCE_X_LOCAL_OWNER_EMPTY) + else if (entry->resource_x_local_owner.state != RESOURCE_X_LOCAL_OWNER_EMPTY) result = RESOURCE_X_APPLY_BAD_STATE; else if (round->terminal_ref.assertion.requester_node != cluster_node_id - || round->cached_ownership_generation != current->generation - || !cluster_pcm_lock_resource_x_gate_open_exact( - round->terminal_ref.formation) - || !pcm_resource_x_bootstrap_round_terminal_cover_exact_locked( - entry, round, &round->terminal_ref, - round->master_session_incarnation, - round->r4_record_generation, current->generation)) + || round->cached_ownership_generation != current->generation + || !cluster_pcm_lock_resource_x_gate_open_exact(round->terminal_ref.formation) + || !pcm_resource_x_bootstrap_round_terminal_cover_exact_locked( + entry, round, &round->terminal_ref, round->master_session_incarnation, + round->r4_record_generation, current->generation)) result = RESOURCE_X_APPLY_STALE; else result = RESOURCE_X_APPLY_APPLIED; @@ -17045,9 +15835,8 @@ cluster_pcm_lock_resource_x_bootstrap_round_x_to_s_preflight_exact( * consumes no authority: it only clears the retained binding whose local X * half was just replaced by the exact S tuple. */ ResourceXApplyResult -cluster_pcm_lock_resource_x_bootstrap_round_note_x_to_s_exact( - const ClusterPcmOwnSnapshot *revoking, - const ClusterPcmOwnSnapshot *shared) +cluster_pcm_lock_resource_x_bootstrap_round_note_x_to_s_exact(const ClusterPcmOwnSnapshot *revoking, + const ClusterPcmOwnSnapshot *shared) { ClusterPcmResourceXBootstrapRound *round; PcmEntryRef entry_ref; @@ -17056,30 +15845,21 @@ cluster_pcm_lock_resource_x_bootstrap_round_note_x_to_s_exact( ResourceXApplyResult result; bool broadcast = false; - if (revoking == NULL || shared == NULL - || revoking->pcm_state != (uint8)PCM_STATE_X - || revoking->flags != PCM_OWN_FLAG_REVOKING - || revoking->generation == 0 - || revoking->generation == UINT64_MAX - || revoking->reservation_token == 0 - || revoking->reservation_token == UINT64_MAX - || revoking->writer_activation_token != 0 + if (revoking == NULL || shared == NULL || revoking->pcm_state != (uint8)PCM_STATE_X + || revoking->flags != PCM_OWN_FLAG_REVOKING || revoking->generation == 0 + || revoking->generation == UINT64_MAX || revoking->reservation_token == 0 + || revoking->reservation_token == UINT64_MAX || revoking->writer_activation_token != 0 || revoking->resource_x_activation_generation != 0 - || shared->pcm_state != (uint8)PCM_STATE_S - || shared->flags != 0 - || shared->generation == 0 - || shared->generation == UINT64_MAX - || shared->reservation_token == 0 - || shared->reservation_token == UINT64_MAX - || shared->writer_activation_token != 0 + || shared->pcm_state != (uint8)PCM_STATE_S || shared->flags != 0 || shared->generation == 0 + || shared->generation == UINT64_MAX || shared->reservation_token == 0 + || shared->reservation_token == UINT64_MAX || shared->writer_activation_token != 0 || shared->resource_x_activation_generation != 0) return RESOURCE_X_APPLY_INVALID; if (!BufferTagsEqual(&revoking->tag, &shared->tag) || shared->generation != revoking->generation + 1 || shared->reservation_token != revoking->reservation_token) return RESOURCE_X_APPLY_STALE; - if (!pcm_entry_ref_acquire(&revoking->tag, false, - &entry_ref, &acquire_result)) + if (!pcm_entry_ref_acquire(&revoking->tag, false, &entry_ref, &acquire_result)) return RESOURCE_X_APPLY_NOT_FOUND; entry = entry_ref.entry; @@ -17089,20 +15869,16 @@ cluster_pcm_lock_resource_x_bootstrap_round_note_x_to_s_exact( result = RESOURCE_X_APPLY_NOT_FOUND; else if (round->delivery_target.buffer_id_plus_one != 0) result = RESOURCE_X_APPLY_BAD_STATE; - else if (!pcm_resource_x_local_owner_valid_locked( - &entry->resource_x_local_owner)) + else if (!pcm_resource_x_local_owner_valid_locked(&entry->resource_x_local_owner)) result = RESOURCE_X_APPLY_RECOVERY_BLOCKED; - else if (entry->resource_x_local_owner.state - != RESOURCE_X_LOCAL_OWNER_EMPTY) + else if (entry->resource_x_local_owner.state != RESOURCE_X_LOCAL_OWNER_EMPTY) result = RESOURCE_X_APPLY_BAD_STATE; else if (round->terminal_ref.assertion.requester_node != cluster_node_id - || round->cached_ownership_generation != revoking->generation - || !cluster_pcm_lock_resource_x_gate_open_exact( - round->terminal_ref.formation) - || !pcm_resource_x_bootstrap_round_terminal_cover_exact_locked( - entry, round, &round->terminal_ref, - round->master_session_incarnation, - round->r4_record_generation, revoking->generation)) + || round->cached_ownership_generation != revoking->generation + || !cluster_pcm_lock_resource_x_gate_open_exact(round->terminal_ref.formation) + || !pcm_resource_x_bootstrap_round_terminal_cover_exact_locked( + entry, round, &round->terminal_ref, round->master_session_incarnation, + round->r4_record_generation, revoking->generation)) result = RESOURCE_X_APPLY_STALE; else { pcm_resource_x_bootstrap_round_clear_binding_locked(round); @@ -17117,38 +15893,31 @@ cluster_pcm_lock_resource_x_bootstrap_round_note_x_to_s_exact( } static bool -pcm_resource_x_common_equal(const ResourceXDecodedCommon *left, - const ResourceXDecodedCommon *right) +pcm_resource_x_common_equal(const ResourceXDecodedCommon *left, const ResourceXDecodedCommon *right) { return left != NULL && right != NULL - && resource_x_assertion_equal(&left->logical_assertion, - &right->logical_assertion) - && left->base_authority_generation - == right->base_authority_generation - && left->resource_formation == right->resource_formation - && left->master_session_incarnation - == right->master_session_incarnation - && left->assertion_sequence == right->assertion_sequence - && left->ordered_lane == right->ordered_lane - && left->action_node == right->action_node - && left->observed_mode == right->observed_mode - && left->target_mode == right->target_mode - && left->source_candidate == right->source_candidate - && left->retain_pi_if_dirty == right->retain_pi_if_dirty - && left->sender_connection_generation - == right->sender_connection_generation - && left->outcome == right->outcome - && left->flags == right->flags - && left->authority_generation == right->authority_generation - && left->semantic_crc32c == right->semantic_crc32c; + && resource_x_assertion_equal(&left->logical_assertion, &right->logical_assertion) + && left->base_authority_generation == right->base_authority_generation + && left->resource_formation == right->resource_formation + && left->master_session_incarnation == right->master_session_incarnation + && left->assertion_sequence == right->assertion_sequence + && left->ordered_lane == right->ordered_lane && left->action_node == right->action_node + && left->observed_mode == right->observed_mode && left->target_mode == right->target_mode + && left->source_candidate == right->source_candidate + && left->retain_pi_if_dirty == right->retain_pi_if_dirty + && left->sender_connection_generation == right->sender_connection_generation + && left->outcome == right->outcome && left->flags == right->flags + && left->authority_generation == right->authority_generation + && left->semantic_crc32c == right->semantic_crc32c; } static bool -pcm_resource_x_bootstrap_request_valid( - const ResourceXDecodedFrame *request, int32 authenticated_source_node, - uint32 authenticated_ingress_connection_generation, - uint64 r4_record_generation, uint64 current_master_session_incarnation, - uint32 master_sender_connection_generation) +pcm_resource_x_bootstrap_request_valid(const ResourceXDecodedFrame *request, + int32 authenticated_source_node, + uint32 authenticated_ingress_connection_generation, + uint64 r4_record_generation, + uint64 current_master_session_incarnation, + uint32 master_sender_connection_generation) { return request != NULL && request->kind == RESOURCE_X_WIRE_PREASSERT_BOOTSTRAP && request->payload_bytes == RESOURCE_X_CONTROL_V1_BYTES @@ -17180,21 +15949,17 @@ pcm_resource_x_bootstrap_request_valid( } static bool -pcm_resource_x_bootstrap_priority_valid( - const ClusterPcmResourceXBootstrapPriority *priority) +pcm_resource_x_bootstrap_priority_valid(const ClusterPcmResourceXBootstrapPriority *priority) { static const ClusterPcmResourceXBootstrapPriority empty_priority; static const uint8 empty_reserved[7]; const ResourceXDecodedCommon *request; - if (priority == NULL - || memcmp(priority->reserved, empty_reserved, - sizeof(empty_reserved)) != 0) + if (priority == NULL || memcmp(priority->reserved, empty_reserved, sizeof(empty_reserved)) != 0) return false; if (priority->state == RESOURCE_X_BOOTSTRAP_PRIORITY_EMPTY) return memcmp(priority, &empty_priority, sizeof(*priority)) == 0; - if (priority->state - != RESOURCE_X_BOOTSTRAP_PRIORITY_NEXT_ADMISSION) + if (priority->state != RESOURCE_X_BOOTSTRAP_PRIORITY_NEXT_ADMISSION) return false; request = &priority->request; return resource_x_assertion_valid(&request->logical_assertion) @@ -17218,16 +15983,14 @@ pcm_resource_x_bootstrap_priority_valid( } static void -pcm_resource_x_bootstrap_priority_clear( - ClusterPcmResourceXBootstrapPriority *priority) +pcm_resource_x_bootstrap_priority_clear(ClusterPcmResourceXBootstrapPriority *priority) { Assert(priority != NULL); memset(priority, 0, sizeof(*priority)); } static void -pcm_resource_x_bootstrap_receipt_invalidate( - ClusterPcmResourceXBootstrapReceipt *receipt) +pcm_resource_x_bootstrap_receipt_invalidate(ClusterPcmResourceXBootstrapReceipt *receipt) { uint64 highest_attempt_floor; @@ -17238,30 +16001,23 @@ pcm_resource_x_bootstrap_receipt_invalidate( } static bool -pcm_resource_x_bootstrap_receipt_valid( - const ClusterPcmResourceXBootstrapReceipt *receipt) +pcm_resource_x_bootstrap_receipt_valid(const ClusterPcmResourceXBootstrapReceipt *receipt) { static const ResourceXDecodedCommon empty_common; static const uint8 empty_reserved[3]; const ResourceXDecodedCommon *request; const ResourceXDecodedCommon *ack; - if (receipt == NULL - || memcmp(receipt->reserved, empty_reserved, - sizeof(empty_reserved)) != 0) + if (receipt == NULL || memcmp(receipt->reserved, empty_reserved, sizeof(empty_reserved)) != 0) return false; if (receipt->state == RESOURCE_X_BOOTSTRAP_RECEIPT_EMPTY) - return memcmp(&receipt->request, &empty_common, - sizeof(empty_common)) == 0 - && memcmp(&receipt->ack, &empty_common, - sizeof(empty_common)) == 0 - && receipt->sampled_base == 0 - && receipt->r4_record_generation == 0 - && receipt->authenticated_ingress_connection_generation == 0 - && receipt->highest_attempt_floor != UINT64_MAX; + return memcmp(&receipt->request, &empty_common, sizeof(empty_common)) == 0 + && memcmp(&receipt->ack, &empty_common, sizeof(empty_common)) == 0 + && receipt->sampled_base == 0 && receipt->r4_record_generation == 0 + && receipt->authenticated_ingress_connection_generation == 0 + && receipt->highest_attempt_floor != UINT64_MAX; if (receipt->state != RESOURCE_X_BOOTSTRAP_RECEIPT_RECEIVED - && receipt->state - != RESOURCE_X_BOOTSTRAP_RECEIPT_CONSUMED_BY_ASSERT) + && receipt->state != RESOURCE_X_BOOTSTRAP_RECEIPT_CONSUMED_BY_ASSERT) return false; request = &receipt->request; ack = &receipt->ack; @@ -17299,9 +16055,8 @@ pcm_resource_x_bootstrap_receipt_valid( } static void -pcm_resource_x_bootstrap_ack_snapshot( - const ClusterPcmResourceXBootstrapReceipt *receipt, - ResourceXDecodedFrame *ack_out) +pcm_resource_x_bootstrap_ack_snapshot(const ClusterPcmResourceXBootstrapReceipt *receipt, + ResourceXDecodedFrame *ack_out) { Assert(receipt != NULL); Assert(ack_out != NULL); @@ -17335,8 +16090,8 @@ pcm_resource_x_dispatch_diagnostic_should_log(void) return false; pcm_resource_x_dispatch_diagnostic_next_log_at = now_us > UINT64_MAX - PCM_RESOURCE_X_DISPATCH_DIAGNOSTIC_INTERVAL_US - ? UINT64_MAX - : now_us + PCM_RESOURCE_X_DISPATCH_DIAGNOSTIC_INTERVAL_US; + ? UINT64_MAX + : now_us + PCM_RESOURCE_X_DISPATCH_DIAGNOSTIC_INTERVAL_US; return true; } @@ -17348,9 +16103,9 @@ pcm_resource_x_dispatch_diagnostic_should_log(void) * state; the separate single NEXT_ADMISSION identity provides bounded * priority without retaining a base or ACK. */ static PcmResourceXBootstrapDispatchState -pcm_resource_x_bootstrap_dispatch_state_locked( - struct GrdEntry *entry, const ClusterPcmResourceXMasterState *state, - int32 requester_node) +pcm_resource_x_bootstrap_dispatch_state_locked(struct GrdEntry *entry, + const ClusterPcmResourceXMasterState *state, + int32 requester_node) { static const ClusterPcmResourceXMasterRequest empty_request; ResourceXDecodedFrame source_settlement; @@ -17360,12 +16115,10 @@ pcm_resource_x_bootstrap_dispatch_state_locked( Assert(entry != NULL); Assert(state != NULL); - Assert(requester_node >= 0 - && requester_node < RESOURCE_X_PROTOCOL_NODE_LIMIT); + Assert(requester_node >= 0 && requester_node < RESOURCE_X_PROTOCOL_NODE_LIMIT); Assert(LWLockHeldByMeInMode(&entry->entry_lock.lock, LW_EXCLUSIVE)); requester_bit = UINT32_C(1) << (uint32)requester_node; - if (!pcm_resource_x_source_settlement_debt_decode_locked( - entry, state, &source_settlement)) + if (!pcm_resource_x_source_settlement_debt_decode_locked(entry, state, &source_settlement)) return PCM_RESOURCE_X_BOOTSTRAP_DISPATCH_CORRUPT; /* INSTALL_SETTLEMENT is transport-reliable but has no semantic ACK. Do * not admit another conversion while the previous exact former-source @@ -17373,8 +16126,7 @@ pcm_resource_x_bootstrap_dispatch_state_locked( * its sole debt and would strand the canonical request in GRANT_COMMITTED. * The bounded successor priority remains non-authoritative and retries the * same request after the exact source ACK changes PENDING to ACKED. */ - if (state->source_settlement.state - == RESOURCE_X_SOURCE_SETTLEMENT_PENDING) { + if (state->source_settlement.state == RESOURCE_X_SOURCE_SETTLEMENT_PENDING) { /* The selected former source still owns the preceding physical carrier * fence. SourceSettlementV2 makes its local reacquire request * ineligible until that exact debt settles, so a rejected kind-9 frame @@ -17385,22 +16137,17 @@ pcm_resource_x_bootstrap_dispatch_state_locked( occupied = true; } - for (candidate_node = 0; - candidate_node < RESOURCE_X_PROTOCOL_NODE_LIMIT; - candidate_node++) { + for (candidate_node = 0; candidate_node < RESOURCE_X_PROTOCOL_NODE_LIMIT; candidate_node++) { const ClusterPcmResourceXBootstrapReceipt *receipt = &state->bootstrap_receipts[candidate_node]; - const ClusterPcmResourceXMasterRequest *request - = &state->requests[candidate_node]; + const ClusterPcmResourceXMasterRequest *request = &state->requests[candidate_node]; if (!pcm_resource_x_bootstrap_receipt_valid(receipt)) { - ereport(LOG, - (errmsg_internal("Resource-X kind-9 dispatch blocker diagnostic"), - errdetail("requester=%d candidate=%d invalid_receipt=true " - "receipt_state=%u request_phase=%u", - requester_node, candidate_node, - (unsigned)receipt->state, - (unsigned)request->phase))); + ereport(LOG, (errmsg_internal("Resource-X kind-9 dispatch blocker diagnostic"), + errdetail("requester=%d candidate=%d invalid_receipt=true " + "receipt_state=%u request_phase=%u", + requester_node, candidate_node, (unsigned)receipt->state, + (unsigned)request->phase))); return PCM_RESOURCE_X_BOOTSTRAP_DISPATCH_CORRUPT; } /* An unresolved blocker of the active predecessor is about to lose its @@ -17418,80 +16165,63 @@ pcm_resource_x_bootstrap_dispatch_state_locked( return PCM_RESOURCE_X_BOOTSTRAP_DISPATCH_SOURCE_INELIGIBLE; if (receipt->state != RESOURCE_X_BOOTSTRAP_RECEIPT_EMPTY && (candidate_node != requester_node - || receipt->state - != RESOURCE_X_BOOTSTRAP_RECEIPT_RECEIVED)) { + || receipt->state != RESOURCE_X_BOOTSTRAP_RECEIPT_RECEIVED)) { if (pcm_resource_x_dispatch_diagnostic_should_log()) - ereport(LOG, - (errmsg_internal("Resource-X kind-9 dispatch blocker diagnostic"), - errdetail("requester=%d candidate=%d invalid_receipt=false " - "receipt_state=%u request_phase=%u", - requester_node, candidate_node, - (unsigned)receipt->state, - (unsigned)request->phase))); + ereport(LOG, (errmsg_internal("Resource-X kind-9 dispatch blocker diagnostic"), + errdetail("requester=%d candidate=%d invalid_receipt=false " + "receipt_state=%u request_phase=%u", + requester_node, candidate_node, (unsigned)receipt->state, + (unsigned)request->phase))); occupied = true; } if (request->phase != RESOURCE_X_MASTER_NONE || memcmp(request, &empty_request, sizeof(*request)) != 0) { if (pcm_resource_x_dispatch_diagnostic_should_log()) - ereport(LOG, - (errmsg_internal("Resource-X kind-9 dispatch blocker diagnostic"), - errdetail("requester=%d candidate=%d invalid_receipt=false " - "receipt_state=%u request_phase=%u", - requester_node, candidate_node, - (unsigned)receipt->state, - (unsigned)request->phase))); + ereport(LOG, (errmsg_internal("Resource-X kind-9 dispatch blocker diagnostic"), + errdetail("requester=%d candidate=%d invalid_receipt=false " + "receipt_state=%u request_phase=%u", + requester_node, candidate_node, (unsigned)receipt->state, + (unsigned)request->phase))); occupied = true; } } return occupied ? PCM_RESOURCE_X_BOOTSTRAP_DISPATCH_OCCUPIED - : PCM_RESOURCE_X_BOOTSTRAP_DISPATCH_AVAILABLE; + : PCM_RESOURCE_X_BOOTSTRAP_DISPATCH_AVAILABLE; } static bool pcm_resource_x_bootstrapped_assert_matches_receipt( - const ResourceXDecodedFrame *assertion, - const ClusterPcmResourceXBootstrapReceipt *receipt, - uint32 authenticated_ingress_connection_generation, - uint64 r4_record_generation, uint64 current_master_session_incarnation, - uint32 current_master_sender_connection_generation) + const ResourceXDecodedFrame *assertion, const ClusterPcmResourceXBootstrapReceipt *receipt, + uint32 authenticated_ingress_connection_generation, uint64 r4_record_generation, + uint64 current_master_session_incarnation, uint32 current_master_sender_connection_generation) { return assertion != NULL && receipt != NULL - && receipt->state == RESOURCE_X_BOOTSTRAP_RECEIPT_RECEIVED - && assertion->payload_bytes == RESOURCE_X_CONTROL_V1_BYTES - && !assertion->blocked_has_remote_proof - && resource_x_assertion_equal( - &assertion->common.logical_assertion, - &receipt->request.logical_assertion) - && assertion->common.base_authority_generation - == receipt->sampled_base - && assertion->common.authority_generation - == receipt->sampled_base - && assertion->common.resource_formation - == receipt->request.resource_formation - && assertion->common.master_session_incarnation - == receipt->request.master_session_incarnation - && assertion->common.assertion_sequence - == receipt->request.assertion_sequence - && assertion->common.ordered_lane == 0 - && assertion->common.action_node - == receipt->request.logical_assertion.requester_node - && assertion->common.observed_mode == (uint8)PCM_STATE_N - && assertion->common.target_mode == (uint8)PCM_STATE_X - && assertion->common.source_candidate == 0 - && assertion->common.retain_pi_if_dirty == 0 - && assertion->common.sender_connection_generation - == receipt->request.sender_connection_generation - && authenticated_ingress_connection_generation - == receipt->authenticated_ingress_connection_generation - && assertion->common.outcome == RESOURCE_X_OUTCOME_NONE - && assertion->common.flags == 0 - && receipt->sampled_base != 0 - && receipt->sampled_base != UINT64_MAX - && r4_record_generation == receipt->r4_record_generation - && current_master_session_incarnation - == receipt->request.master_session_incarnation - && current_master_sender_connection_generation - == receipt->ack.sender_connection_generation; + && receipt->state == RESOURCE_X_BOOTSTRAP_RECEIPT_RECEIVED + && assertion->payload_bytes == RESOURCE_X_CONTROL_V1_BYTES + && !assertion->blocked_has_remote_proof + && resource_x_assertion_equal(&assertion->common.logical_assertion, + &receipt->request.logical_assertion) + && assertion->common.base_authority_generation == receipt->sampled_base + && assertion->common.authority_generation == receipt->sampled_base + && assertion->common.resource_formation == receipt->request.resource_formation + && assertion->common.master_session_incarnation + == receipt->request.master_session_incarnation + && assertion->common.assertion_sequence == receipt->request.assertion_sequence + && assertion->common.ordered_lane == 0 + && assertion->common.action_node == receipt->request.logical_assertion.requester_node + && assertion->common.observed_mode == (uint8)PCM_STATE_N + && assertion->common.target_mode == (uint8)PCM_STATE_X + && assertion->common.source_candidate == 0 && assertion->common.retain_pi_if_dirty == 0 + && assertion->common.sender_connection_generation + == receipt->request.sender_connection_generation + && authenticated_ingress_connection_generation + == receipt->authenticated_ingress_connection_generation + && assertion->common.outcome == RESOURCE_X_OUTCOME_NONE && assertion->common.flags == 0 + && receipt->sampled_base != 0 && receipt->sampled_base != UINT64_MAX + && r4_record_generation == receipt->r4_record_generation + && current_master_session_incarnation == receipt->request.master_session_incarnation + && current_master_sender_connection_generation + == receipt->ack.sender_connection_generation; } /* The initial module values are not an authority witness once legacy PCM has @@ -17499,23 +16229,19 @@ pcm_resource_x_bootstrapped_assert_matches_receipt( * the exact selected-ticket base only while every Resource-X semantic owner * is still pristine. */ static bool -pcm_resource_x_master_state_pristine( - const ClusterPcmResourceXMasterState *state) +pcm_resource_x_master_state_pristine(const ClusterPcmResourceXMasterState *state) { static const ClusterPcmResourceXMasterState pristine; const char *semantic_tail; Size semantic_tail_bytes; - if (state == NULL || state->binding_generation == 0 - || state->binding_generation == UINT64_MAX - || state->authority_generation != 1 - || state->next_enqueue_order != 1) + if (state == NULL || state->binding_generation == 0 || state->binding_generation == UINT64_MAX + || state->authority_generation != 1 || state->next_enqueue_order != 1) return false; semantic_tail = (const char *)&state->bootstrap_priority; - semantic_tail_bytes = sizeof(*state) - - offsetof(ClusterPcmResourceXMasterState, bootstrap_priority); - return memcmp(semantic_tail, &pristine.bootstrap_priority, - semantic_tail_bytes) == 0; + semantic_tail_bytes + = sizeof(*state) - offsetof(ClusterPcmResourceXMasterState, bootstrap_priority); + return memcmp(semantic_tail, &pristine.bootstrap_priority, semantic_tail_bytes) == 0; } /* The promoted-successor adapter may advance an enqueue-time base only before @@ -17523,25 +16249,20 @@ pcm_resource_x_master_state_pristine( * RELEASED requests are retained terminal history, not a live assertion; any * nonterminal request or an exact-sequence terminal replay closes the window. */ static bool -pcm_resource_x_master_state_preassert_rebindable( - const ClusterPcmResourceXMasterState *state, - const ResourceXAssertion *assertion, uint64 assertion_sequence) +pcm_resource_x_master_state_preassert_rebindable(const ClusterPcmResourceXMasterState *state, + const ResourceXAssertion *assertion, + uint64 assertion_sequence) { static const ClusterPcmResourceXMasterRequest empty_request; int32 requester_node; if (state == NULL || state->authority_generation == 0 - || state->authority_generation == UINT64_MAX - || state->next_enqueue_order == 0 - || state->next_enqueue_order == UINT64_MAX - || !resource_x_assertion_valid(assertion) + || state->authority_generation == UINT64_MAX || state->next_enqueue_order == 0 + || state->next_enqueue_order == UINT64_MAX || !resource_x_assertion_valid(assertion) || assertion_sequence == 0 || assertion_sequence == UINT64_MAX) return false; - for (requester_node = 0; - requester_node < RESOURCE_X_PROTOCOL_NODE_LIMIT; - requester_node++) { - const ClusterPcmResourceXMasterRequest *request - = &state->requests[requester_node]; + for (requester_node = 0; requester_node < RESOURCE_X_PROTOCOL_NODE_LIMIT; requester_node++) { + const ClusterPcmResourceXMasterRequest *request = &state->requests[requester_node]; if (request->phase == RESOURCE_X_MASTER_NONE) { if (memcmp(request, &empty_request, sizeof(*request)) != 0) @@ -17552,14 +16273,10 @@ pcm_resource_x_master_state_preassert_rebindable( && request->phase != RESOURCE_X_MASTER_RELEASED) return false; if (request->base_authority_generation == 0 - || request->base_authority_generation == UINT64_MAX - || request->resource_formation == 0 - || request->resource_formation == UINT64_MAX - || request->master_session_incarnation == 0 - || request->assertion_sequence == 0 - || request->assertion_sequence == UINT64_MAX - || request->enqueue_order == 0 - || request->final_authority_generation == 0 + || request->base_authority_generation == UINT64_MAX || request->resource_formation == 0 + || request->resource_formation == UINT64_MAX || request->master_session_incarnation == 0 + || request->assertion_sequence == 0 || request->assertion_sequence == UINT64_MAX + || request->enqueue_order == 0 || request->final_authority_generation == 0 || request->final_authority_generation == UINT64_MAX || request->assertion_sequence == assertion_sequence) return false; @@ -17568,63 +16285,51 @@ pcm_resource_x_master_state_preassert_rebindable( } static bool -pcm_resource_x_legacy_authority_shape_valid( - const PcmAuthoritySnapshot *authority) +pcm_resource_x_legacy_authority_shape_valid(const PcmAuthoritySnapshot *authority) { if (authority == NULL || authority->transition_count == 0 || authority->transition_count == UINT64_MAX) return false; switch (authority->state) { - case PCM_STATE_N: - return authority->x_holder_node == -1 - && authority->s_holders_bitmap == 0 - && authority->master_holder.node_id - == INVALID_PCM_MASTER_HOLDER_NODE; - case PCM_STATE_S: - return authority->x_holder_node == -1 - && authority->s_holders_bitmap != 0 - && authority->master_holder.node_id - < RESOURCE_X_PROTOCOL_NODE_LIMIT - && (authority->s_holders_bitmap - & (UINT32_C(1) << authority->master_holder.node_id)) != 0; - case PCM_STATE_X: - return authority->x_holder_node >= 0 - && authority->x_holder_node < RESOURCE_X_PROTOCOL_NODE_LIMIT - && authority->s_holders_bitmap == 0 - && authority->master_holder.node_id - == (uint32)authority->x_holder_node; - default: - return false; + case PCM_STATE_N: + return authority->x_holder_node == -1 && authority->s_holders_bitmap == 0 + && authority->master_holder.node_id == INVALID_PCM_MASTER_HOLDER_NODE; + case PCM_STATE_S: + return authority->x_holder_node == -1 && authority->s_holders_bitmap != 0 + && authority->master_holder.node_id < RESOURCE_X_PROTOCOL_NODE_LIMIT + && (authority->s_holders_bitmap & (UINT32_C(1) << authority->master_holder.node_id)) + != 0; + case PCM_STATE_X: + return authority->x_holder_node >= 0 + && authority->x_holder_node < RESOURCE_X_PROTOCOL_NODE_LIMIT + && authority->s_holders_bitmap == 0 + && authority->master_holder.node_id == (uint32)authority->x_holder_node; + default: + return false; } } static bool -pcm_resource_x_legacy_authority_valid( - const PcmAuthoritySnapshot *authority, - uint64 base_authority_generation) +pcm_resource_x_legacy_authority_valid(const PcmAuthoritySnapshot *authority, + uint64 base_authority_generation) { - return base_authority_generation != 0 - && base_authority_generation != UINT64_MAX - && authority != NULL - && authority->transition_count == base_authority_generation - && authority->pending_x_requester_node == -1 - && authority->pending_x_since_lsn == 0 - && pcm_resource_x_legacy_authority_shape_valid(authority); + return base_authority_generation != 0 && base_authority_generation != UINT64_MAX + && authority != NULL && authority->transition_count == base_authority_generation + && authority->pending_x_requester_node == -1 && authority->pending_x_since_lsn == 0 + && pcm_resource_x_legacy_authority_shape_valid(authority); } /* A promoted head may already own the process-local pending-X barrier when * its enqueue-time base is refreshed. That barrier is admissible only when * the cookie names the same requester and immutable PCM-X ticket. */ static bool -pcm_resource_x_head_rebind_authority_valid( - const ResourceXAssertion *assertion, uint64 ticket_id, - const PcmAuthoritySnapshot *authority, - uint64 base_authority_generation) +pcm_resource_x_head_rebind_authority_valid(const ResourceXAssertion *assertion, uint64 ticket_id, + const PcmAuthoritySnapshot *authority, + uint64 base_authority_generation) { uint64 expected_pending_x; - if (assertion == NULL || authority == NULL - || base_authority_generation == 0 + if (assertion == NULL || authority == NULL || base_authority_generation == 0 || base_authority_generation == UINT64_MAX || authority->transition_count != base_authority_generation || !pcm_resource_x_legacy_authority_shape_valid(authority) @@ -17633,16 +16338,15 @@ pcm_resource_x_head_rebind_authority_valid( if (authority->pending_x_requester_node == -1) return authority->pending_x_since_lsn == 0; return authority->pending_x_requester_node == assertion->requester_node - && authority->pending_x_since_lsn == expected_pending_x; + && authority->pending_x_since_lsn == expected_pending_x; } static ResourceXApplyResult -pcm_resource_x_adapter_base_bind_exact( - const ResourceXAssertion *assertion, uint64 formation, - uint64 base_authority_generation, - const PcmAuthoritySnapshot *legacy_authority, - bool allow_preassert_rebind, uint64 assertion_sequence, - uint64 ticket_id) +pcm_resource_x_adapter_base_bind_exact(const ResourceXAssertion *assertion, uint64 formation, + uint64 base_authority_generation, + const PcmAuthoritySnapshot *legacy_authority, + bool allow_preassert_rebind, uint64 assertion_sequence, + uint64 ticket_id) { ClusterPcmResourceXMasterState *state; PcmEntryRef entry_ref; @@ -17651,41 +16355,34 @@ pcm_resource_x_adapter_base_bind_exact( struct GrdEntry *entry; ResourceXApplyResult result; - if (!resource_x_assertion_valid(assertion) || formation == 0 - || formation == UINT64_MAX + if (!resource_x_assertion_valid(assertion) || formation == 0 || formation == UINT64_MAX || !(allow_preassert_rebind - ? pcm_resource_x_head_rebind_authority_valid( - assertion, ticket_id, legacy_authority, - base_authority_generation) - : pcm_resource_x_legacy_authority_valid( - legacy_authority, base_authority_generation)) + ? pcm_resource_x_head_rebind_authority_valid( + assertion, ticket_id, legacy_authority, base_authority_generation) + : pcm_resource_x_legacy_authority_valid(legacy_authority, + base_authority_generation)) || ClusterPcm == NULL) return RESOURCE_X_APPLY_INVALID; - if (pg_atomic_read_u32(&ClusterPcm->resource_x_gate_phase) - != RESOURCE_X_GATE_OPEN - || pg_atomic_read_u64(&ClusterPcm->resource_x_gate_formation) - != formation) + if (pg_atomic_read_u32(&ClusterPcm->resource_x_gate_phase) != RESOURCE_X_GATE_OPEN + || pg_atomic_read_u64(&ClusterPcm->resource_x_gate_formation) != formation) return RESOURCE_X_APPLY_RECOVERY_BLOCKED; - if (!pcm_entry_ref_acquire(&assertion->resource, false, - &entry_ref, &acquire_result)) + if (!pcm_entry_ref_acquire(&assertion->resource, false, &entry_ref, &acquire_result)) return RESOURCE_X_APPLY_NOT_FOUND; entry = entry_ref.entry; pcm_entry_lock_exclusive(entry); pcm_authority_snapshot_locked(entry, ¤t); state = pcm_resource_x_master_state_for_entry(entry); - if (state == NULL || !pcm_authority_snapshot_equal( - ¤t, legacy_authority)) + if (state == NULL || !pcm_authority_snapshot_equal(¤t, legacy_authority)) result = RESOURCE_X_APPLY_STALE; else if (allow_preassert_rebind - && !pcm_resource_x_master_state_preassert_rebindable( - state, assertion, assertion_sequence)) + && !pcm_resource_x_master_state_preassert_rebindable(state, assertion, + assertion_sequence)) result = RESOURCE_X_APPLY_STALE; else if (state->authority_generation == base_authority_generation) result = RESOURCE_X_APPLY_DUPLICATE; else if (!pcm_resource_x_active_empty_locked(entry) - || (!allow_preassert_rebind - && !pcm_resource_x_master_state_pristine(state))) + || (!allow_preassert_rebind && !pcm_resource_x_master_state_pristine(state))) result = RESOURCE_X_APPLY_STALE; else { state->authority_generation = base_authority_generation; @@ -17697,26 +16394,25 @@ pcm_resource_x_adapter_base_bind_exact( } ResourceXApplyResult -cluster_pcm_lock_resource_x_adapter_base_bind_exact( - const ResourceXAssertion *assertion, uint64 formation, - uint64 base_authority_generation, - const PcmAuthoritySnapshot *legacy_authority) +cluster_pcm_lock_resource_x_adapter_base_bind_exact(const ResourceXAssertion *assertion, + uint64 formation, + uint64 base_authority_generation, + const PcmAuthoritySnapshot *legacy_authority) { - return pcm_resource_x_adapter_base_bind_exact( - assertion, formation, base_authority_generation, legacy_authority, - false, 0, 0); + return pcm_resource_x_adapter_base_bind_exact(assertion, formation, base_authority_generation, + legacy_authority, false, 0, 0); } ResourceXApplyResult -cluster_pcm_lock_resource_x_adapter_head_rebind_exact( - const ResourceXAssertion *assertion, uint64 assertion_sequence, - uint64 ticket_id, uint64 formation, - uint64 base_authority_generation, - const PcmAuthoritySnapshot *legacy_authority) +cluster_pcm_lock_resource_x_adapter_head_rebind_exact(const ResourceXAssertion *assertion, + uint64 assertion_sequence, uint64 ticket_id, + uint64 formation, + uint64 base_authority_generation, + const PcmAuthoritySnapshot *legacy_authority) { - return pcm_resource_x_adapter_base_bind_exact( - assertion, formation, base_authority_generation, legacy_authority, - true, assertion_sequence, ticket_id); + return pcm_resource_x_adapter_base_bind_exact(assertion, formation, base_authority_generation, + legacy_authority, true, assertion_sequence, + ticket_id); } /* A non-head PCM-X ticket must receive its first admission ACK so its @@ -17728,8 +16424,7 @@ cluster_pcm_lock_resource_x_adapter_head_rebind_exact( ResourceXApplyResult cluster_pcm_lock_resource_x_adapter_successor_base_exact( const ResourceXAssertion *assertion, uint64 formation, - const PcmAuthoritySnapshot *legacy_authority, - uint64 *base_authority_generation_out) + const PcmAuthoritySnapshot *legacy_authority, uint64 *base_authority_generation_out) { ClusterPcmResourceXMasterRequest *head; ClusterPcmResourceXMasterState *state; @@ -17742,27 +16437,21 @@ cluster_pcm_lock_resource_x_adapter_successor_base_exact( if (base_authority_generation_out != NULL) *base_authority_generation_out = 0; - if (!resource_x_assertion_valid(assertion) || formation == 0 - || formation == UINT64_MAX || legacy_authority == NULL - || base_authority_generation_out == NULL + if (!resource_x_assertion_valid(assertion) || formation == 0 || formation == UINT64_MAX + || legacy_authority == NULL || base_authority_generation_out == NULL || !pcm_resource_x_legacy_authority_shape_valid(legacy_authority) || (legacy_authority->pending_x_requester_node == -1 && legacy_authority->pending_x_since_lsn != 0) || (legacy_authority->pending_x_requester_node != -1 && (legacy_authority->pending_x_requester_node < 0 - || legacy_authority->pending_x_requester_node - >= RESOURCE_X_PROTOCOL_NODE_LIMIT - || (legacy_authority->pending_x_since_lsn - & PCM_PENDING_X_QUEUE_KIND) == 0)) + || legacy_authority->pending_x_requester_node >= RESOURCE_X_PROTOCOL_NODE_LIMIT + || (legacy_authority->pending_x_since_lsn & PCM_PENDING_X_QUEUE_KIND) == 0)) || ClusterPcm == NULL) return RESOURCE_X_APPLY_INVALID; - if (pg_atomic_read_u32(&ClusterPcm->resource_x_gate_phase) - != RESOURCE_X_GATE_OPEN - || pg_atomic_read_u64(&ClusterPcm->resource_x_gate_formation) - != formation) + if (pg_atomic_read_u32(&ClusterPcm->resource_x_gate_phase) != RESOURCE_X_GATE_OPEN + || pg_atomic_read_u64(&ClusterPcm->resource_x_gate_formation) != formation) return RESOURCE_X_APPLY_RECOVERY_BLOCKED; - if (!pcm_entry_ref_acquire(&assertion->resource, false, - &entry_ref, &acquire_result)) + if (!pcm_entry_ref_acquire(&assertion->resource, false, &entry_ref, &acquire_result)) return RESOURCE_X_APPLY_NOT_FOUND; entry = entry_ref.entry; @@ -17777,20 +16466,15 @@ cluster_pcm_lock_resource_x_adapter_successor_base_exact( else { head = pcm_resource_x_master_head(state, &head_node); if ((current.pending_x_requester_node != -1 - && (head == NULL - || current.pending_x_requester_node != head_node - || head_node == assertion->requester_node)) + && (head == NULL || current.pending_x_requester_node != head_node + || head_node == assertion->requester_node)) || (head != NULL && head_node == assertion->requester_node) - || (state->requests[assertion->requester_node].phase - != RESOURCE_X_MASTER_NONE - && state->requests[assertion->requester_node].phase - != RESOURCE_X_MASTER_SETTLED - && state->requests[assertion->requester_node].phase - != RESOURCE_X_MASTER_RELEASED)) + || (state->requests[assertion->requester_node].phase != RESOURCE_X_MASTER_NONE + && state->requests[assertion->requester_node].phase != RESOURCE_X_MASTER_SETTLED + && state->requests[assertion->requester_node].phase != RESOURCE_X_MASTER_RELEASED)) result = RESOURCE_X_APPLY_STALE; else { - *base_authority_generation_out - = state->authority_generation; + *base_authority_generation_out = state->authority_generation; result = RESOURCE_X_APPLY_APPLIED; } } @@ -17823,9 +16507,8 @@ pcm_resource_x_admitted_assertion_snapshot(const ClusterPcmResourceXBootstrapRec ResourceXApplyResult cluster_pcm_lock_resource_x_bootstrap_request_exact( const ResourceXDecodedFrame *request, int32 authenticated_source_node, - uint32 authenticated_ingress_connection_generation, - uint64 r4_record_generation, uint64 current_master_session_incarnation, - uint32 master_sender_connection_generation, + uint32 authenticated_ingress_connection_generation, uint64 r4_record_generation, + uint64 current_master_session_incarnation, uint32 master_sender_connection_generation, ResourceXDecodedFrame *ack_out) { ClusterPcmResourceXBootstrapPriority *priority; @@ -17849,40 +16532,33 @@ cluster_pcm_lock_resource_x_bootstrap_request_exact( memset(ack_out, 0, sizeof(*ack_out)); if (ack_out == NULL || !pcm_resource_x_bootstrap_request_valid( - request, authenticated_source_node, - authenticated_ingress_connection_generation, + request, authenticated_source_node, authenticated_ingress_connection_generation, r4_record_generation, current_master_session_incarnation, master_sender_connection_generation) || ClusterPcm == NULL) return RESOURCE_X_APPLY_INVALID; gate_phase = pg_atomic_read_u32(&ClusterPcm->resource_x_gate_phase); gate_formation = pg_atomic_read_u64(&ClusterPcm->resource_x_gate_formation); - if (gate_phase != RESOURCE_X_GATE_OPEN - || gate_formation != request->common.resource_formation) + if (gate_phase != RESOURCE_X_GATE_OPEN || gate_formation != request->common.resource_formation) return RESOURCE_X_APPLY_RECOVERY_BLOCKED; - if (!pcm_entry_ref_acquire( - &request->common.logical_assertion.resource, true, - &entry_ref, &acquire_result)) + if (!pcm_entry_ref_acquire(&request->common.logical_assertion.resource, true, &entry_ref, + &acquire_result)) return RESOURCE_X_APPLY_NOT_FOUND; entry = entry_ref.entry; requester_node = request->common.logical_assertion.requester_node; pcm_entry_lock_exclusive(entry); state = pcm_resource_x_master_state_for_entry(entry); if (state == NULL || state->authority_generation == 0 - || state->authority_generation == UINT64_MAX - || state->next_enqueue_order == 0) { + || state->authority_generation == UINT64_MAX || state->next_enqueue_order == 0) { LWLockRelease(&entry->entry_lock.lock); pcm_entry_ref_release(&entry_ref); return RESOURCE_X_APPLY_RECOVERY_BLOCKED; } priority = &state->bootstrap_priority; if (!pcm_resource_x_bootstrap_priority_valid(priority) - || (priority->state - == RESOURCE_X_BOOTSTRAP_PRIORITY_NEXT_ADMISSION - && !BufferTagsEqual( - &priority->request.logical_assertion.resource, - &entry->tag))) { + || (priority->state == RESOURCE_X_BOOTSTRAP_PRIORITY_NEXT_ADMISSION + && !BufferTagsEqual(&priority->request.logical_assertion.resource, &entry->tag))) { pcm_resource_x_bootstrap_priority_clear(priority); LWLockRelease(&entry->entry_lock.lock); pcm_entry_ref_release(&entry_ref); @@ -17890,8 +16566,7 @@ cluster_pcm_lock_resource_x_bootstrap_request_exact( } if (priority->state == RESOURCE_X_BOOTSTRAP_PRIORITY_NEXT_ADMISSION && (priority->request.resource_formation != gate_formation - || priority->request.master_session_incarnation - != current_master_session_incarnation + || priority->request.master_session_incarnation != current_master_session_incarnation || priority->r4_record_generation != r4_record_generation)) { pcm_resource_x_bootstrap_priority_clear(priority); LWLockRelease(&entry->entry_lock.lock); @@ -17900,24 +16575,20 @@ cluster_pcm_lock_resource_x_bootstrap_request_exact( } priority_same_attempt = priority->state == RESOURCE_X_BOOTSTRAP_PRIORITY_NEXT_ADMISSION - && resource_x_assertion_equal( - &priority->request.logical_assertion, - &request->common.logical_assertion) - && priority->request.resource_formation - == request->common.resource_formation - && priority->request.master_session_incarnation - == request->common.master_session_incarnation - && priority->request.assertion_sequence - == request->common.assertion_sequence; + && resource_x_assertion_equal(&priority->request.logical_assertion, + &request->common.logical_assertion) + && priority->request.resource_formation == request->common.resource_formation + && priority->request.master_session_incarnation + == request->common.master_session_incarnation + && priority->request.assertion_sequence == request->common.assertion_sequence; priority_exact_wire = priority_same_attempt - && pcm_resource_x_common_equal( - &priority->request, &request->common); + && pcm_resource_x_common_equal(&priority->request, &request->common); if (priority_same_attempt && (!priority_exact_wire || priority->authenticated_ingress_connection_generation - != authenticated_ingress_connection_generation + != authenticated_ingress_connection_generation || priority->master_sender_connection_generation - != master_sender_connection_generation)) { + != master_sender_connection_generation)) { pcm_resource_x_bootstrap_priority_clear(priority); LWLockRelease(&entry->entry_lock.lock); pcm_entry_ref_release(&entry_ref); @@ -17934,24 +16605,19 @@ cluster_pcm_lock_resource_x_bootstrap_request_exact( && (receipt->sampled_base != state->authority_generation || receipt->r4_record_generation != r4_record_generation || receipt->request.resource_formation != gate_formation - || receipt->request.master_session_incarnation - != current_master_session_incarnation + || receipt->request.master_session_incarnation != current_master_session_incarnation || receipt->request.sender_connection_generation - != request->common.sender_connection_generation + != request->common.sender_connection_generation || receipt->authenticated_ingress_connection_generation - != authenticated_ingress_connection_generation - || receipt->ack.sender_connection_generation - != master_sender_connection_generation)) + != authenticated_ingress_connection_generation + || receipt->ack.sender_connection_generation != master_sender_connection_generation)) pcm_resource_x_bootstrap_receipt_invalidate(receipt); attempt_floor = receipt->highest_attempt_floor; - if (pcm_resource_x_terminal_tombstone_valid( - &state->terminal_tombstone) + if (pcm_resource_x_terminal_tombstone_valid(&state->terminal_tombstone) && state->terminal_tombstone.requester_node == requester_node - && state->terminal_tombstone.request.assertion_sequence - > attempt_floor) - attempt_floor - = state->terminal_tombstone.request.assertion_sequence; + && state->terminal_tombstone.request.assertion_sequence > attempt_floor) + attempt_floor = state->terminal_tombstone.request.assertion_sequence; if (master_request->phase != RESOURCE_X_MASTER_NONE && master_request->assertion_sequence > attempt_floor) attempt_floor = master_request->assertion_sequence; @@ -17987,54 +16653,41 @@ cluster_pcm_lock_resource_x_bootstrap_request_exact( pcm_resource_x_bootstrap_priority_clear(priority); result = RESOURCE_X_APPLY_STALE; } else { - dispatch_state = pcm_resource_x_bootstrap_dispatch_state_locked( - entry, state, requester_node); - if (dispatch_state - == PCM_RESOURCE_X_BOOTSTRAP_DISPATCH_CORRUPT) { + dispatch_state + = pcm_resource_x_bootstrap_dispatch_state_locked(entry, state, requester_node); + if (dispatch_state == PCM_RESOURCE_X_BOOTSTRAP_DISPATCH_CORRUPT) { pcm_resource_x_bootstrap_priority_clear(priority); result = RESOURCE_X_APPLY_RECOVERY_BLOCKED; - } - else if (dispatch_state - == PCM_RESOURCE_X_BOOTSTRAP_DISPATCH_SOURCE_INELIGIBLE) + } else if (dispatch_state == PCM_RESOURCE_X_BOOTSTRAP_DISPATCH_SOURCE_INELIGIBLE) result = RESOURCE_X_APPLY_BAD_STATE; - else if (dispatch_state - == PCM_RESOURCE_X_BOOTSTRAP_DISPATCH_OCCUPIED) { + else if (dispatch_state == PCM_RESOURCE_X_BOOTSTRAP_DISPATCH_OCCUPIED) { /* Only a new successor is an admission. An already retained * exact priority remains owned work and keeps its original path. */ if (priority->state == RESOURCE_X_BOOTSTRAP_PRIORITY_EMPTY && cluster_normal_stop_service_new_work(true)) { - pcm_resource_x_common_copy( - &priority->request, &request->common); + pcm_resource_x_common_copy(&priority->request, &request->common); priority->r4_record_generation = r4_record_generation; priority->authenticated_ingress_connection_generation = authenticated_ingress_connection_generation; - priority->master_sender_connection_generation - = master_sender_connection_generation; - priority->state - = RESOURCE_X_BOOTSTRAP_PRIORITY_NEXT_ADMISSION; + priority->master_sender_connection_generation = master_sender_connection_generation; + priority->state = RESOURCE_X_BOOTSTRAP_PRIORITY_NEXT_ADMISSION; } result = RESOURCE_X_APPLY_BAD_STATE; - } - else if (priority->state - == RESOURCE_X_BOOTSTRAP_PRIORITY_NEXT_ADMISSION - && !priority_exact_wire) + } else if (priority->state == RESOURCE_X_BOOTSTRAP_PRIORITY_NEXT_ADMISSION + && !priority_exact_wire) result = RESOURCE_X_APPLY_BAD_STATE; else if (!priority_exact_wire && !cluster_normal_stop_service_new_work(true)) result = RESOURCE_X_APPLY_BAD_STATE; else { pcm_resource_x_bootstrap_receipt_invalidate(receipt); - pcm_resource_x_common_copy( - &receipt->request, &request->common); + pcm_resource_x_common_copy(&receipt->request, &request->common); pcm_resource_x_common_copy(&receipt->ack, &request->common); - receipt->ack.base_authority_generation - = state->authority_generation; - receipt->ack.sender_connection_generation - = master_sender_connection_generation; + receipt->ack.base_authority_generation = state->authority_generation; + receipt->ack.sender_connection_generation = master_sender_connection_generation; receipt->ack.outcome = RESOURCE_X_OUTCOME_OK; receipt->ack.flags = 0; receipt->ack.semantic_crc32c = 0; - receipt->highest_attempt_floor - = request->common.assertion_sequence; + receipt->highest_attempt_floor = request->common.assertion_sequence; receipt->sampled_base = state->authority_generation; receipt->r4_record_generation = r4_record_generation; receipt->authenticated_ingress_connection_generation @@ -18079,26 +16732,21 @@ cluster_pcm_lock_resource_x_s_barrier_active(const BufferTag *tag) if (tag == NULL) return true; - if (!pcm_entry_ref_acquire( - tag, false, &entry_ref, &acquire_result)) + if (!pcm_entry_ref_acquire(tag, false, &entry_ref, &acquire_result)) return false; entry = entry_ref.entry; LWLockAcquire(&entry->entry_lock.lock, LW_SHARED); state = pcm_resource_x_master_state_for_entry(entry); if (state == NULL || state->authority_generation == 0 - || state->authority_generation == UINT64_MAX - || state->next_enqueue_order == 0 + || state->authority_generation == UINT64_MAX || state->next_enqueue_order == 0 || state->next_enqueue_order == UINT64_MAX) { barrier_active = true; goto out; } - for (requester_node = 0; - requester_node < RESOURCE_X_PROTOCOL_NODE_LIMIT; - requester_node++) { + for (requester_node = 0; requester_node < RESOURCE_X_PROTOCOL_NODE_LIMIT; requester_node++) { const ClusterPcmResourceXBootstrapReceipt *receipt = &state->bootstrap_receipts[requester_node]; - const ClusterPcmResourceXMasterRequest *request - = &state->requests[requester_node]; + const ClusterPcmResourceXMasterRequest *request = &state->requests[requester_node]; if (!pcm_resource_x_bootstrap_receipt_valid(receipt) || receipt->state != RESOURCE_X_BOOTSTRAP_RECEIPT_EMPTY @@ -18116,13 +16764,13 @@ cluster_pcm_lock_resource_x_s_barrier_active(const BufferTag *tag) } static ResourceXApplyResult -pcm_resource_x_assert_exact_internal( - const ResourceXDecodedFrame *assertion, int32 authenticated_source_node, - bool require_bootstrap, - uint32 authenticated_ingress_connection_generation, - uint64 r4_record_generation, uint64 current_master_session_incarnation, - uint32 current_master_sender_connection_generation, - ResourceXMasterSnapshot *out) +pcm_resource_x_assert_exact_internal(const ResourceXDecodedFrame *assertion, + int32 authenticated_source_node, bool require_bootstrap, + uint32 authenticated_ingress_connection_generation, + uint64 r4_record_generation, + uint64 current_master_session_incarnation, + uint32 current_master_sender_connection_generation, + ResourceXMasterSnapshot *out) { PcmEntryRef entry_ref; PcmEntryAcquireResult acquire_result; @@ -18135,34 +16783,27 @@ pcm_resource_x_assert_exact_internal( memset(out, 0, sizeof(*out)); out->source_node = -1; } - if (out == NULL || !pcm_resource_x_assert_frame_valid(assertion, - authenticated_source_node) + if (out == NULL || !pcm_resource_x_assert_frame_valid(assertion, authenticated_source_node) || (require_bootstrap - && (assertion->payload_bytes - != RESOURCE_X_CONTROL_V1_BYTES + && (assertion->payload_bytes != RESOURCE_X_CONTROL_V1_BYTES || assertion->blocked_has_remote_proof - || assertion->common.base_authority_generation - == UINT64_MAX + || assertion->common.base_authority_generation == UINT64_MAX || assertion->common.resource_formation == UINT64_MAX || assertion->common.assertion_sequence == UINT64_MAX || assertion->common.ordered_lane != 0 || assertion->common.observed_mode != (uint8)PCM_STATE_N || assertion->common.source_candidate != 0 - || assertion->common.retain_pi_if_dirty != 0 - || assertion->common.flags != 0 + || assertion->common.retain_pi_if_dirty != 0 || assertion->common.flags != 0 || authenticated_ingress_connection_generation == 0 || authenticated_ingress_connection_generation == UINT32_MAX - || assertion->common.sender_connection_generation - == UINT32_MAX - || r4_record_generation == 0 - || r4_record_generation == UINT64_MAX + || assertion->common.sender_connection_generation == UINT32_MAX + || r4_record_generation == 0 || r4_record_generation == UINT64_MAX || current_master_session_incarnation == 0 || current_master_session_incarnation == UINT64_MAX || assertion->common.master_session_incarnation - != current_master_session_incarnation + != current_master_session_incarnation || current_master_sender_connection_generation == 0 - || current_master_sender_connection_generation - == UINT32_MAX)) + || current_master_sender_connection_generation == UINT32_MAX)) || ClusterPcm == NULL) return RESOURCE_X_APPLY_INVALID; gate_phase = pg_atomic_read_u32(&ClusterPcm->resource_x_gate_phase); @@ -18171,9 +16812,8 @@ pcm_resource_x_assert_exact_internal( || gate_formation != assertion->common.resource_formation) return RESOURCE_X_APPLY_RECOVERY_BLOCKED; - if (!pcm_entry_ref_acquire( - &assertion->common.logical_assertion.resource, true, - &entry_ref, &acquire_result)) + if (!pcm_entry_ref_acquire(&assertion->common.logical_assertion.resource, true, &entry_ref, + &acquire_result)) return RESOURCE_X_APPLY_NOT_FOUND; entry = entry_ref.entry; pcm_entry_lock_exclusive(entry); @@ -18204,55 +16844,44 @@ pcm_resource_x_assert_locked(struct GrdEntry *entry, const ResourceXDecodedFrame Assert(LWLockHeldByMeInMode(&entry->entry_lock.lock, LW_EXCLUSIVE)); state = pcm_resource_x_master_state_for_entry(entry); - if (state == NULL || state->authority_generation == 0 - || state->next_enqueue_order == 0) { + if (state == NULL || state->authority_generation == 0 || state->next_enqueue_order == 0) { result = RESOURCE_X_APPLY_RECOVERY_BLOCKED; goto unlock; } request = &state->requests[requester_node]; if (pcm_resource_x_terminal_tombstone_valid(&state->terminal_tombstone) && state->terminal_tombstone.requester_node == requester_node) { - ClusterPcmResourceXMasterRequest *terminal - = &state->terminal_tombstone.request; + ClusterPcmResourceXMasterRequest *terminal = &state->terminal_tombstone.request; - if (pcm_resource_x_assert_common_matches_request( - &assertion->common, terminal)) { - pcm_resource_x_terminal_tombstone_snapshot( - &entry->tag, state, &state->terminal_tombstone, out); + if (pcm_resource_x_assert_common_matches_request(&assertion->common, terminal)) { + pcm_resource_x_terminal_tombstone_snapshot(&entry->tag, state, + &state->terminal_tombstone, out); result = RESOURCE_X_APPLY_DUPLICATE; goto unlock; } - if (assertion->common.assertion_sequence - <= terminal->assertion_sequence) { - pcm_resource_x_terminal_tombstone_snapshot( - &entry->tag, state, &state->terminal_tombstone, out); + if (assertion->common.assertion_sequence <= terminal->assertion_sequence) { + pcm_resource_x_terminal_tombstone_snapshot(&entry->tag, state, + &state->terminal_tombstone, out); result = RESOURCE_X_APPLY_STALE; goto unlock; } } if (request->phase != RESOURCE_X_MASTER_NONE) { bool same_attempt - = pcm_resource_x_assert_common_matches_request( - &assertion->common, request); + = pcm_resource_x_assert_common_matches_request(&assertion->common, request); if (same_attempt || request->phase != RESOURCE_X_MASTER_RELEASED) { - if (same_attempt - && request->phase == RESOURCE_X_MASTER_WAIT_BLOCKERS - && !pcm_resource_x_arm_block_intents_locked( - entry, state, request, requester_node)) + if (same_attempt && request->phase == RESOURCE_X_MASTER_WAIT_BLOCKERS + && !pcm_resource_x_arm_block_intents_locked(entry, state, request, requester_node)) request->phase = RESOURCE_X_MASTER_RECOVERY_BLOCKED; - else if (same_attempt - && request->phase - == RESOURCE_X_MASTER_GRANT_COMMITTED - && !pcm_resource_x_redrive_grant_intent_locked( - entry, state, request, requester_node)) + else if (same_attempt && request->phase == RESOURCE_X_MASTER_GRANT_COMMITTED + && !pcm_resource_x_redrive_grant_intent_locked(entry, state, request, + requester_node)) request->phase = RESOURCE_X_MASTER_RECOVERY_BLOCKED; - pcm_resource_x_master_snapshot(&entry->tag, requester_node, state, - request, out); + pcm_resource_x_master_snapshot(&entry->tag, requester_node, state, request, out); result = request->phase == RESOURCE_X_MASTER_RECOVERY_BLOCKED - ? RESOURCE_X_APPLY_RECOVERY_BLOCKED - : (same_attempt ? RESOURCE_X_APPLY_DUPLICATE - : RESOURCE_X_APPLY_STALE); + ? RESOURCE_X_APPLY_RECOVERY_BLOCKED + : (same_attempt ? RESOURCE_X_APPLY_DUPLICATE : RESOURCE_X_APPLY_STALE); goto unlock; } } @@ -18263,21 +16892,19 @@ pcm_resource_x_assert_locked(struct GrdEntry *entry, const ResourceXDecodedFrame goto unlock; } if (!pcm_resource_x_bootstrapped_assert_matches_receipt( - assertion, receipt, - authenticated_ingress_connection_generation, + assertion, receipt, authenticated_ingress_connection_generation, r4_record_generation, current_master_session_incarnation, current_master_sender_connection_generation) || receipt->sampled_base != state->authority_generation) { if (receipt->state == RESOURCE_X_BOOTSTRAP_RECEIPT_RECEIVED && (receipt->sampled_base != state->authority_generation - || receipt->r4_record_generation - != r4_record_generation + || receipt->r4_record_generation != r4_record_generation || receipt->request.master_session_incarnation - != current_master_session_incarnation + != current_master_session_incarnation || receipt->authenticated_ingress_connection_generation - != authenticated_ingress_connection_generation + != authenticated_ingress_connection_generation || receipt->ack.sender_connection_generation - != current_master_sender_connection_generation)) + != current_master_sender_connection_generation)) pcm_resource_x_bootstrap_receipt_invalidate(receipt); result = RESOURCE_X_APPLY_STALE; goto unlock; @@ -18287,9 +16914,9 @@ pcm_resource_x_assert_locked(struct GrdEntry *entry, const ResourceXDecodedFrame || (entry->pending_x_requester_node != -1 && entry->pending_x_requester_node != requester_node) || state->next_enqueue_order == UINT64_MAX) { - result = assertion->common.base_authority_generation - != state->authority_generation - ? RESOURCE_X_APPLY_STALE : RESOURCE_X_APPLY_RECOVERY_BLOCKED; + result = assertion->common.base_authority_generation != state->authority_generation + ? RESOURCE_X_APPLY_STALE + : RESOURCE_X_APPLY_RECOVERY_BLOCKED; goto unlock; } /* A validated bootstrap receipt already owns this admission, including @@ -18309,8 +16936,7 @@ pcm_resource_x_assert_locked(struct GrdEntry *entry, const ResourceXDecodedFrame request->assertion_sequence = assertion->common.assertion_sequence; request->enqueue_order = state->next_enqueue_order++; request->ordered_lane = assertion->common.ordered_lane; - request->sender_connection_generation - = assertion->common.sender_connection_generation; + request->sender_connection_generation = assertion->common.sender_connection_generation; request->source_node = -1; request->phase = RESOURCE_X_MASTER_QUEUED; @@ -18333,21 +16959,20 @@ pcm_resource_x_assert_locked(struct GrdEntry *entry, const ResourceXDecodedFrame incompatible = UINT32_C(1) << (uint32)entry->x_holder_node; else if (pcm_state == PCM_STATE_S) incompatible = pg_atomic_read_u32(&entry->s_holders_bitmap) - & ~(UINT32_C(1) << (uint32)requester_node); + & ~(UINT32_C(1) << (uint32)requester_node); request->incompatible_holders_bitmap = incompatible; request->phase = incompatible != 0 ? RESOURCE_X_MASTER_WAIT_BLOCKERS - : RESOURCE_X_MASTER_WAIT_PROOF; + : RESOURCE_X_MASTER_WAIT_PROOF; if (incompatible != 0 - && !pcm_resource_x_arm_block_intents_locked( - entry, state, request, requester_node)) + && !pcm_resource_x_arm_block_intents_locked(entry, state, request, requester_node)) request->phase = RESOURCE_X_MASTER_RECOVERY_BLOCKED; } - assertion_head_done: - ; + assertion_head_done:; } pcm_resource_x_master_snapshot(&entry->tag, requester_node, state, request, out); result = request->phase == RESOURCE_X_MASTER_RECOVERY_BLOCKED - ? RESOURCE_X_APPLY_RECOVERY_BLOCKED : RESOURCE_X_APPLY_APPLIED; + ? RESOURCE_X_APPLY_RECOVERY_BLOCKED + : RESOURCE_X_APPLY_APPLIED; unlock: return result; @@ -18358,21 +16983,19 @@ cluster_pcm_lock_resource_x_assert_exact(const ResourceXDecodedFrame *assertion, int32 authenticated_source_node, ResourceXMasterSnapshot *out) { - return pcm_resource_x_assert_exact_internal( - assertion, authenticated_source_node, false, 0, 0, 0, 0, out); + return pcm_resource_x_assert_exact_internal(assertion, authenticated_source_node, false, 0, 0, + 0, 0, out); } ResourceXApplyResult cluster_pcm_lock_resource_x_assert_bootstrapped_exact( const ResourceXDecodedFrame *assertion, int32 authenticated_source_node, - uint32 authenticated_ingress_connection_generation, - uint64 r4_record_generation, uint64 current_master_session_incarnation, - uint32 current_master_sender_connection_generation, + uint32 authenticated_ingress_connection_generation, uint64 r4_record_generation, + uint64 current_master_session_incarnation, uint32 current_master_sender_connection_generation, ResourceXMasterSnapshot *out) { return pcm_resource_x_assert_exact_internal( - assertion, authenticated_source_node, true, - authenticated_ingress_connection_generation, + assertion, authenticated_source_node, true, authenticated_ingress_connection_generation, r4_record_generation, current_master_session_incarnation, current_master_sender_connection_generation, out); } @@ -18383,19 +17006,16 @@ pcm_resource_x_remote_proof_valid(const ResourceXDecodedFrame *frame) const ResourceXDecodedBlockedToN *proof = &frame->body.blocked_to_n; int dependency_index; - if (!frame->blocked_has_remote_proof - || proof->source_carrier_generation == 0 + if (!frame->blocked_has_remote_proof || proof->source_carrier_generation == 0 || proof->requester_target_generation == 0 || proof->proof_kind != RESOURCE_X_PROOF_REMOTE_CARRIER - || proof->source_disposition - != RESOURCE_X_DISPOSITION_REMOTE_NONWRITABLE - || proof->proof_flags != 0 - || proof->holder_connection_generation == 0 + || proof->source_disposition != RESOURCE_X_DISPOSITION_REMOTE_NONWRITABLE + || proof->proof_flags != 0 || proof->holder_connection_generation == 0 || proof->acting_formation != frame->common.resource_formation || proof->dependency_count > RESOURCE_X_DEPENDENCY_MAX) return false; - for (dependency_index = proof->dependency_count; - dependency_index < RESOURCE_X_DEPENDENCY_MAX; dependency_index++) + for (dependency_index = proof->dependency_count; dependency_index < RESOURCE_X_DEPENDENCY_MAX; + dependency_index++) if (proof->dependencies[dependency_index] != 0) return false; return true; @@ -18411,9 +17031,10 @@ pcm_resource_x_monotonic_us(void) } static bool -pcm_resource_x_arm_block_intents_locked( - struct GrdEntry *entry, ClusterPcmResourceXMasterState *state, - ClusterPcmResourceXMasterRequest *request, int32 requester_node) +pcm_resource_x_arm_block_intents_locked(struct GrdEntry *entry, + ClusterPcmResourceXMasterState *state, + ClusterPcmResourceXMasterRequest *request, + int32 requester_node) { ClusterPcmResourceXBlockIntent pending[RESOURCE_X_PROTOCOL_NODE_LIMIT]; PcmState pcm_state; @@ -18428,12 +17049,10 @@ pcm_resource_x_arm_block_intents_locked( Assert(state != NULL); Assert(request != NULL); Assert(LWLockHeldByMeInMode(&entry->entry_lock.lock, LW_EXCLUSIVE)); - incompatible = request->incompatible_holders_bitmap - & ~request->blocked_holders_bitmap; + incompatible = request->incompatible_holders_bitmap & ~request->blocked_holders_bitmap; if (incompatible == 0) return true; - if (cluster_node_id < 0 - || cluster_node_id >= RESOURCE_X_PROTOCOL_NODE_LIMIT) + if (cluster_node_id < 0 || cluster_node_id >= RESOURCE_X_PROTOCOL_NODE_LIMIT) return false; now_us = pcm_resource_x_monotonic_us(); if (now_us == 0 || now_us == UINT64_MAX) @@ -18442,19 +17061,15 @@ pcm_resource_x_arm_block_intents_locked( pcm_state = (PcmState)pg_atomic_read_u32(&entry->master_state); s_holders_bitmap = pg_atomic_read_u32(&entry->s_holders_bitmap); if (pcm_state == PCM_STATE_S && request->source_node == -1 - && (s_holders_bitmap - & (UINT32_C(1) << (uint32)requester_node)) == 0) { - uint32 candidates - = request->incompatible_holders_bitmap & s_holders_bitmap; + && (s_holders_bitmap & (UINT32_C(1) << (uint32)requester_node)) == 0) { + uint32 candidates = request->incompatible_holders_bitmap & s_holders_bitmap; request->source_node - = pcm_resource_x_select_shared_current_carrier_locked( - entry, candidates); + = pcm_resource_x_select_shared_current_carrier_locked(entry, candidates); if (request->source_node < 0) return false; } - for (holder_node = 0; holder_node < RESOURCE_X_PROTOCOL_NODE_LIMIT; - holder_node++) { + for (holder_node = 0; holder_node < RESOURCE_X_PROTOCOL_NODE_LIMIT; holder_node++) { ResourceXDecodedFrame block; ResourceXIntentBodyHandle body; ResourceXWireReject reject = RESOURCE_X_WIRE_REJECT_NONE; @@ -18466,14 +17081,10 @@ pcm_resource_x_arm_block_intents_locked( if ((incompatible & holder_bit) == 0) continue; - is_x_source = pcm_state == PCM_STATE_X - && entry->x_holder_node == holder_node; - if (!is_x_source - && (pcm_state != PCM_STATE_S - || (s_holders_bitmap & holder_bit) == 0)) + is_x_source = pcm_state == PCM_STATE_X && entry->x_holder_node == holder_node; + if (!is_x_source && (pcm_state != PCM_STATE_S || (s_holders_bitmap & holder_bit) == 0)) return false; - is_selected_s_source = pcm_state == PCM_STATE_S - && request->source_node == holder_node; + is_selected_s_source = pcm_state == PCM_STATE_S && request->source_node == holder_node; is_source = is_x_source || is_selected_s_source; if (is_source) { uint32 blockers = request->incompatible_holders_bitmap; @@ -18500,33 +17111,27 @@ pcm_resource_x_arm_block_intents_locked( block.payload_bytes = RESOURCE_X_CONTROL_V1_BYTES; block.common.logical_assertion.resource = entry->tag; block.common.logical_assertion.requester_node = requester_node; - block.common.base_authority_generation - = request->base_authority_generation; + block.common.base_authority_generation = request->base_authority_generation; block.common.resource_formation = request->resource_formation; - block.common.master_session_incarnation - = request->master_session_incarnation; + block.common.master_session_incarnation = request->master_session_incarnation; block.common.assertion_sequence = request->assertion_sequence; block.common.ordered_lane = request->ordered_lane; block.common.action_node = holder_node; - block.common.observed_mode - = (uint8)(is_x_source ? PCM_STATE_X : PCM_STATE_S); + block.common.observed_mode = (uint8)(is_x_source ? PCM_STATE_X : PCM_STATE_S); block.common.target_mode = (uint8)PCM_STATE_N; block.common.source_candidate = is_source ? 1 : 0; block.common.retain_pi_if_dirty = is_source ? 1 : 0; /* This retained wire-shaped body is not a physical frame yet. * sender freshness is rebound from the exact master-to-holder DATA * session by LMS immediately before transport admission. */ - block.common.sender_connection_generation - = PGRAC_RESOURCE_X_RETAINED_SENDER_GENERATION; + block.common.sender_connection_generation = PGRAC_RESOURCE_X_RETAINED_SENDER_GENERATION; block.common.outcome = RESOURCE_X_OUTCOME_NONE; block.common.authority_generation = is_source ? delegated_generation : request->base_authority_generation; block.common.flags = is_source ? RESOURCE_X_COMMON_FLAG_AUTHORITY_WITH_IMAGE : 0; if (!cluster_resource_x_wire_encode( - RESOURCE_X_MSG_BLOCK_TO_N, &block, - pending[holder_node].payload, - sizeof(pending[holder_node].payload), &payload_len, - &reject) + RESOURCE_X_MSG_BLOCK_TO_N, &block, pending[holder_node].payload, + sizeof(pending[holder_node].payload), &payload_len, &reject) || payload_len != RESOURCE_X_CONTROL_V1_BYTES) return false; memset(&body, 0, sizeof(body)); @@ -18536,41 +17141,31 @@ pcm_resource_x_arm_block_intents_locked( body.owner_kind = RESOURCE_X_INTENT_OWNER_MASTER_BLOCK; body.owner_index = (uint8)holder_node; if (!cluster_pcm_lock_resource_x_intent_arm_exact( - &pending[holder_node].slot, &body, - request->assertion_sequence, - request->base_authority_generation, now_us, - (uint32)holder_node, payload_len, + &pending[holder_node].slot, &body, request->assertion_sequence, + request->base_authority_generation, now_us, (uint32)holder_node, payload_len, RESOURCE_X_WIRE_BLOCK_TO_N)) return false; - if (state->block_intents[holder_node].slot.state - != RESOURCE_X_INTENT_SLOT_EMPTY) { - ResourceXIntentSlot *existing - = &state->block_intents[holder_node].slot; - ResourceXIntentSlot *candidate - = &pending[holder_node].slot; + if (state->block_intents[holder_node].slot.state != RESOURCE_X_INTENT_SLOT_EMPTY) { + ResourceXIntentSlot *existing = &state->block_intents[holder_node].slot; + ResourceXIntentSlot *candidate = &pending[holder_node].slot; if ((existing->state != RESOURCE_X_INTENT_SLOT_ARMED && existing->state != RESOURCE_X_INTENT_SLOT_STAGED) - || existing->logical_generation - != candidate->logical_generation - || existing->authority_generation - != candidate->authority_generation - || existing->destination_node - != candidate->destination_node + || existing->logical_generation != candidate->logical_generation + || existing->authority_generation != candidate->authority_generation + || existing->destination_node != candidate->destination_node || existing->payload_bytes != candidate->payload_bytes || existing->kind != candidate->kind - || memcmp(&existing->body, &candidate->body, - sizeof(existing->body)) != 0 - || memcmp(state->block_intents[holder_node].payload, - pending[holder_node].payload, - candidate->payload_bytes) != 0) + || memcmp(&existing->body, &candidate->body, sizeof(existing->body)) != 0 + || memcmp(state->block_intents[holder_node].payload, pending[holder_node].payload, + candidate->payload_bytes) + != 0) return false; continue; } armed_bitmap |= holder_bit; } - for (holder_node = 0; holder_node < RESOURCE_X_PROTOCOL_NODE_LIMIT; - holder_node++) { + for (holder_node = 0; holder_node < RESOURCE_X_PROTOCOL_NODE_LIMIT; holder_node++) { uint32 holder_bit = UINT32_C(1) << (uint32)holder_node; if ((incompatible & holder_bit) == 0) @@ -18588,8 +17183,7 @@ pcm_resource_x_arm_block_intents_locked( request->source_node = entry->x_holder_node; } if (!pcm_resource_x_intent_mark_dirty()) { - for (holder_node = 0; holder_node < RESOURCE_X_PROTOCOL_NODE_LIMIT; - holder_node++) + for (holder_node = 0; holder_node < RESOURCE_X_PROTOCOL_NODE_LIMIT; holder_node++) if ((armed_bitmap & (UINT32_C(1) << (uint32)holder_node)) != 0) memset(&state->block_intents[holder_node], 0, sizeof(state->block_intents[holder_node])); @@ -18599,10 +17193,10 @@ pcm_resource_x_arm_block_intents_locked( } ResourceXApplyResult -cluster_pcm_lock_resource_x_block_intent_snapshot_exact( - const ResourceXAssertion *assertion, int32 holder_node, - ResourceXIntentSlot *slot_out, void *payload_out, - uint16 payload_capacity) +cluster_pcm_lock_resource_x_block_intent_snapshot_exact(const ResourceXAssertion *assertion, + int32 holder_node, + ResourceXIntentSlot *slot_out, + void *payload_out, uint16 payload_capacity) { ClusterPcmResourceXBlockIntent *intent; ClusterPcmResourceXMasterRequest *request; @@ -18616,14 +17210,11 @@ cluster_pcm_lock_resource_x_block_intent_snapshot_exact( if (slot_out != NULL) memset(slot_out, 0, sizeof(*slot_out)); - if (!resource_x_assertion_valid(assertion) - || holder_node < 0 - || holder_node >= RESOURCE_X_PROTOCOL_NODE_LIMIT - || slot_out == NULL || payload_out == NULL + if (!resource_x_assertion_valid(assertion) || holder_node < 0 + || holder_node >= RESOURCE_X_PROTOCOL_NODE_LIMIT || slot_out == NULL || payload_out == NULL || payload_capacity < RESOURCE_X_CONTROL_V1_BYTES) return RESOURCE_X_APPLY_INVALID; - if (!pcm_entry_ref_acquire(&assertion->resource, false, - &entry_ref, &acquire_result)) + if (!pcm_entry_ref_acquire(&assertion->resource, false, &entry_ref, &acquire_result)) return RESOURCE_X_APPLY_NOT_FOUND; entry = entry_ref.entry; requester_node = assertion->requester_node; @@ -18649,15 +17240,12 @@ cluster_pcm_lock_resource_x_block_intent_snapshot_exact( || intent->slot.state > RESOURCE_X_INTENT_SLOT_STAGED || !pcm_resource_x_intent_body_valid(&intent->slot.body) || intent->slot.logical_generation != request->assertion_sequence - || intent->slot.authority_generation - != request->base_authority_generation + || intent->slot.authority_generation != request->base_authority_generation || intent->slot.destination_node != (uint32)holder_node || intent->slot.payload_bytes != RESOURCE_X_CONTROL_V1_BYTES || intent->slot.kind != RESOURCE_X_WIRE_BLOCK_TO_N - || intent->slot.body.owner_generation - != request->assertion_sequence - || intent->slot.body.owner_kind - != RESOURCE_X_INTENT_OWNER_MASTER_BLOCK + || intent->slot.body.owner_generation != request->assertion_sequence + || intent->slot.body.owner_kind != RESOURCE_X_INTENT_OWNER_MASTER_BLOCK || intent->slot.body.owner_index != (uint8)holder_node) { result = RESOURCE_X_APPLY_RECOVERY_BLOCKED; goto block_intent_snapshot_done; @@ -18673,51 +17261,40 @@ cluster_pcm_lock_resource_x_block_intent_snapshot_exact( } static bool -pcm_resource_x_holder_status_matches_block( - const ClusterPcmResourceXHolderStatus *record, - const ResourceXDecodedFrame *block, int32 authenticated_master_node) +pcm_resource_x_holder_status_matches_block(const ClusterPcmResourceXHolderStatus *record, + const ResourceXDecodedFrame *block, + int32 authenticated_master_node) { ResourceXDecodedFrame status; ResourceXWireReject reject = RESOURCE_X_WIRE_REJECT_NONE; if (record == NULL || block == NULL || record->valid != 1 || record->logical_generation != block->common.assertion_sequence - || record->authority_generation - != block->common.base_authority_generation + || record->authority_generation != block->common.base_authority_generation || record->resource_formation != block->common.resource_formation || record->destination_node != (uint32)authenticated_master_node || record->kind != RESOURCE_X_WIRE_BLOCKED_TO_N - || !resource_x_assertion_equal(&record->body.assertion, - &block->common.logical_assertion) - || !cluster_resource_x_wire_decode( - RESOURCE_X_MSG_BLOCKED_TO_N, record->payload, - record->payload_bytes, &status, &reject)) - return false; - return status.common.base_authority_generation - == block->common.base_authority_generation - && status.common.resource_formation - == block->common.resource_formation - && status.common.master_session_incarnation - == block->common.master_session_incarnation - && status.common.assertion_sequence - == block->common.assertion_sequence - && status.common.ordered_lane == block->common.ordered_lane - && status.common.action_node == block->common.action_node - && status.common.observed_mode == block->common.observed_mode - && status.common.target_mode == block->common.target_mode - && status.common.source_candidate - == block->common.source_candidate - && status.common.retain_pi_if_dirty - == block->common.retain_pi_if_dirty - && status.common.authority_generation - == block->common.authority_generation - && status.common.outcome == RESOURCE_X_OUTCOME_OK; + || !resource_x_assertion_equal(&record->body.assertion, &block->common.logical_assertion) + || !cluster_resource_x_wire_decode(RESOURCE_X_MSG_BLOCKED_TO_N, record->payload, + record->payload_bytes, &status, &reject)) + return false; + return status.common.base_authority_generation == block->common.base_authority_generation + && status.common.resource_formation == block->common.resource_formation + && status.common.master_session_incarnation == block->common.master_session_incarnation + && status.common.assertion_sequence == block->common.assertion_sequence + && status.common.ordered_lane == block->common.ordered_lane + && status.common.action_node == block->common.action_node + && status.common.observed_mode == block->common.observed_mode + && status.common.target_mode == block->common.target_mode + && status.common.source_candidate == block->common.source_candidate + && status.common.retain_pi_if_dirty == block->common.retain_pi_if_dirty + && status.common.authority_generation == block->common.authority_generation + && status.common.outcome == RESOURCE_X_OUTCOME_OK; } static bool -pcm_resource_x_rearm_holder_status_locked( - ClusterPcmResourceXMasterState *state, - const ClusterPcmResourceXHolderStatus *record) +pcm_resource_x_rearm_holder_status_locked(ClusterPcmResourceXMasterState *state, + const ClusterPcmResourceXHolderStatus *record) { ClusterPcmResourceXControlIntent *intent; uint64 now_us; @@ -18727,19 +17304,17 @@ pcm_resource_x_rearm_holder_status_locked( intent = &state->holder_status_intent; if (intent->slot.state != RESOURCE_X_INTENT_SLOT_EMPTY) return intent->slot.logical_generation == record->logical_generation - && intent->slot.authority_generation - == record->authority_generation - && intent->slot.destination_node == record->destination_node - && intent->slot.payload_bytes == record->payload_bytes - && intent->slot.kind == record->kind - && memcmp(&intent->slot.body, &record->body, - sizeof(record->body)) == 0; + && intent->slot.authority_generation == record->authority_generation + && intent->slot.destination_node == record->destination_node + && intent->slot.payload_bytes == record->payload_bytes + && intent->slot.kind == record->kind + && memcmp(&intent->slot.body, &record->body, sizeof(record->body)) == 0; memcpy(intent->payload, record->payload, record->payload_bytes); now_us = pcm_resource_x_monotonic_us(); if (!cluster_pcm_lock_resource_x_intent_arm_exact( - &intent->slot, &record->body, record->logical_generation, - record->authority_generation, now_us, record->destination_node, - record->payload_bytes, (ResourceXWireKind)record->kind) + &intent->slot, &record->body, record->logical_generation, record->authority_generation, + now_us, record->destination_node, record->payload_bytes, + (ResourceXWireKind)record->kind) || !pcm_resource_x_intent_mark_dirty()) { memset(intent, 0, sizeof(*intent)); return false; @@ -18775,16 +17350,12 @@ pcm_resource_x_holder_source_slots_exact(ClusterPcmResourceXMasterState *state, != 0)) return false; if (image_slot->state != RESOURCE_X_INTENT_SLOT_EMPTY - && (image_slot->logical_generation - != image_record->logical_generation - || image_slot->authority_generation - != image_record->authority_generation - || image_slot->destination_node - != image_record->destination_node + && (image_slot->logical_generation != image_record->logical_generation + || image_slot->authority_generation != image_record->authority_generation + || image_slot->destination_node != image_record->destination_node || image_slot->payload_bytes != image_record->payload_bytes || image_slot->kind != image_record->kind - || memcmp(&image_slot->body, &image_record->body, - sizeof(image_record->body)) != 0)) + || memcmp(&image_slot->body, &image_record->body, sizeof(image_record->body)) != 0)) return false; return true; } @@ -18814,26 +17385,20 @@ pcm_resource_x_rearm_holder_source_locked(ClusterPcmResourceXMasterState *state, /* The empty slot retains only its previous physical episode floor. */ now_us = Max(now_us, Max(status_floor, image_floor) + 1); if (status_slot->state == RESOURCE_X_INTENT_SLOT_EMPTY) { - memcpy(state->holder_status_intent.payload, - status_record->payload, status_record->payload_bytes); + memcpy(state->holder_status_intent.payload, status_record->payload, + status_record->payload_bytes); if (!cluster_pcm_lock_resource_x_intent_arm_exact( - status_slot, &status_record->body, - status_record->logical_generation, - status_record->authority_generation, now_us, - status_record->destination_node, - status_record->payload_bytes, - (ResourceXWireKind)status_record->kind)) + status_slot, &status_record->body, status_record->logical_generation, + status_record->authority_generation, now_us, status_record->destination_node, + status_record->payload_bytes, (ResourceXWireKind)status_record->kind)) return false; armed_status = true; } if (image_slot->state == RESOURCE_X_INTENT_SLOT_EMPTY) { if (!cluster_pcm_lock_resource_x_intent_arm_exact( - image_slot, &image_record->body, - image_record->logical_generation, - image_record->authority_generation, now_us, - image_record->destination_node, - image_record->payload_bytes, - (ResourceXWireKind)image_record->kind)) { + image_slot, &image_record->body, image_record->logical_generation, + image_record->authority_generation, now_us, image_record->destination_node, + image_record->payload_bytes, (ResourceXWireKind)image_record->kind)) { if (armed_status) { memset(status_slot, 0, sizeof(*status_slot)); status_slot->first_armed_us = status_floor; @@ -18844,8 +17409,7 @@ pcm_resource_x_rearm_holder_source_locked(ClusterPcmResourceXMasterState *state, } armed_image = true; } - if ((armed_status || armed_image) - && !pcm_resource_x_intent_mark_dirty()) { + if ((armed_status || armed_image) && !pcm_resource_x_intent_mark_dirty()) { if (armed_status) { memset(status_slot, 0, sizeof(*status_slot)); status_slot->first_armed_us = status_floor; @@ -18862,8 +17426,8 @@ pcm_resource_x_rearm_holder_source_locked(ClusterPcmResourceXMasterState *state, } ResourceXApplyResult -cluster_pcm_lock_resource_x_block_to_n_exact( - const ResourceXDecodedFrame *block, int32 authenticated_master_node) +cluster_pcm_lock_resource_x_block_to_n_exact(const ResourceXDecodedFrame *block, + int32 authenticated_master_node) { ClusterPcmResourceXControlIntent *intent; ClusterPcmResourceXHolderStatus *record; @@ -18884,31 +17448,24 @@ cluster_pcm_lock_resource_x_block_to_n_exact( if (block == NULL || block->kind != RESOURCE_X_WIRE_BLOCK_TO_N || !resource_x_assertion_valid(&block->common.logical_assertion) || authenticated_master_node < 0 - || authenticated_master_node >= RESOURCE_X_PROTOCOL_NODE_LIMIT - || cluster_node_id < 0 + || authenticated_master_node >= RESOURCE_X_PROTOCOL_NODE_LIMIT || cluster_node_id < 0 || cluster_node_id >= RESOURCE_X_PROTOCOL_NODE_LIMIT || block->common.action_node != cluster_node_id || block->common.base_authority_generation == 0 - || block->common.authority_generation - != block->common.base_authority_generation - || block->common.resource_formation == 0 - || block->common.master_session_incarnation == 0 - || block->common.assertion_sequence == 0 - || block->common.sender_connection_generation == 0 + || block->common.authority_generation != block->common.base_authority_generation + || block->common.resource_formation == 0 || block->common.master_session_incarnation == 0 + || block->common.assertion_sequence == 0 || block->common.sender_connection_generation == 0 || block->common.target_mode != (uint8)PCM_STATE_N - || block->common.outcome != RESOURCE_X_OUTCOME_NONE - || ClusterPcm == NULL + || block->common.outcome != RESOURCE_X_OUTCOME_NONE || ClusterPcm == NULL || cluster_gcs_lookup_master(block->common.logical_assertion.resource) != authenticated_master_node) return RESOURCE_X_APPLY_INVALID; - gate_formation - = pg_atomic_read_u64(&ClusterPcm->resource_x_gate_formation); - if (pg_atomic_read_u32(&ClusterPcm->resource_x_gate_phase) - != RESOURCE_X_GATE_OPEN + gate_formation = pg_atomic_read_u64(&ClusterPcm->resource_x_gate_formation); + if (pg_atomic_read_u32(&ClusterPcm->resource_x_gate_phase) != RESOURCE_X_GATE_OPEN || gate_formation != block->common.resource_formation) return RESOURCE_X_APPLY_RECOVERY_BLOCKED; - if (!pcm_entry_ref_acquire(&block->common.logical_assertion.resource, - false, &entry_ref, &acquire_result)) + if (!pcm_entry_ref_acquire(&block->common.logical_assertion.resource, false, &entry_ref, + &acquire_result)) return RESOURCE_X_APPLY_NOT_FOUND; entry = entry_ref.entry; holder_bit = UINT32_C(1) << (uint32)cluster_node_id; @@ -18921,8 +17478,7 @@ cluster_pcm_lock_resource_x_block_to_n_exact( record = &state->holder_status; intent = &state->holder_status_intent; if (record->valid != 0) { - if (!pcm_resource_x_holder_status_matches_block( - record, block, authenticated_master_node)) + if (!pcm_resource_x_holder_status_matches_block(record, block, authenticated_master_node)) result = RESOURCE_X_APPLY_STALE; else if (!pcm_resource_x_rearm_holder_status_locked(state, record)) result = RESOURCE_X_APPLY_RECOVERY_BLOCKED; @@ -18935,18 +17491,15 @@ cluster_pcm_lock_resource_x_block_to_n_exact( goto block_to_n_done; } pcm_state = (PcmState)pg_atomic_read_u32(&entry->master_state); - if (state->authority_generation - != block->common.base_authority_generation) { + if (state->authority_generation != block->common.base_authority_generation) { result = RESOURCE_X_APPLY_STALE; goto block_to_n_done; } /* The current slice closes the proof-free S blocker. An X source must * first freeze its immutable proof and page carrier; until that owner is * present it remains writable and this consumer fails closed. */ - if (pcm_state != PCM_STATE_S - || (pg_atomic_read_u32(&entry->s_holders_bitmap) & holder_bit) == 0 - || block->common.observed_mode != (uint8)PCM_STATE_S - || block->common.source_candidate != 0 + if (pcm_state != PCM_STATE_S || (pg_atomic_read_u32(&entry->s_holders_bitmap) & holder_bit) == 0 + || block->common.observed_mode != (uint8)PCM_STATE_S || block->common.source_candidate != 0 || block->common.retain_pi_if_dirty != 0) { result = RESOURCE_X_APPLY_BAD_STATE; goto block_to_n_done; @@ -18959,9 +17512,8 @@ cluster_pcm_lock_resource_x_block_to_n_exact( status.common.source_candidate = 0; status.common.retain_pi_if_dirty = 0; status.common.outcome = RESOURCE_X_OUTCOME_OK; - if (!cluster_resource_x_wire_encode( - RESOURCE_X_MSG_BLOCKED_TO_N, &status, record->payload, - sizeof(record->payload), &payload_len, &reject) + if (!cluster_resource_x_wire_encode(RESOURCE_X_MSG_BLOCKED_TO_N, &status, record->payload, + sizeof(record->payload), &payload_len, &reject) || payload_len != RESOURCE_X_CONTROL_V1_BYTES) { memset(record, 0, sizeof(*record)); result = RESOURCE_X_APPLY_RECOVERY_BLOCKED; @@ -18974,8 +17526,7 @@ cluster_pcm_lock_resource_x_block_to_n_exact( body.owner_kind = RESOURCE_X_INTENT_OWNER_HOLDER_STATUS; record->body = body; record->logical_generation = block->common.assertion_sequence; - record->authority_generation - = block->common.base_authority_generation; + record->authority_generation = block->common.base_authority_generation; record->resource_formation = block->common.resource_formation; record->destination_node = (uint32)authenticated_master_node; record->payload_bytes = payload_len; @@ -18986,8 +17537,7 @@ cluster_pcm_lock_resource_x_block_to_n_exact( result = RESOURCE_X_APPLY_RECOVERY_BLOCKED; goto block_to_n_done; } - cluster_pcm_transition_apply(entry, PCM_TRANS_S_TO_N_INVALIDATE, - cluster_node_id); + cluster_pcm_transition_apply(entry, PCM_TRANS_S_TO_N_INVALIDATE, cluster_node_id); broadcast = true; result = RESOURCE_X_APPLY_APPLIED; @@ -18999,9 +17549,10 @@ cluster_pcm_lock_resource_x_block_to_n_exact( return result; } -static ResourceXApplyResult pcm_resource_x_holder_pair_decode_locked( - const ClusterPcmResourceXMasterState *state, - ResourceXDecodedFrame *status_out, ResourceXDecodedFrame *image_out); +static ResourceXApplyResult +pcm_resource_x_holder_pair_decode_locked(const ClusterPcmResourceXMasterState *state, + ResourceXDecodedFrame *status_out, + ResourceXDecodedFrame *image_out); static ResourceXApplyResult pcm_resource_x_holder_pair_drain_domain_locked( const BufferTag *tag, const ClusterPcmResourceXMasterState *state, int32 authenticated_master_node, uint64 authenticated_master_session, @@ -19015,9 +17566,10 @@ static ResourceXApplyResult pcm_resource_x_holder_pair_drain_domain_locked( * identity drift remains fail closed; SourceSettlement therefore keeps its * frozen EMPTY-only cover table. */ static ResourceXApplyResult -pcm_resource_x_s_predecessor_cancel_unbound_round_locked( - struct GrdEntry *entry, const ResourceXDecodedFrame *block, - int32 authenticated_master_node, bool *broadcast) +pcm_resource_x_s_predecessor_cancel_unbound_round_locked(struct GrdEntry *entry, + const ResourceXDecodedFrame *block, + int32 authenticated_master_node, + bool *broadcast) { static const ResourceXAcquisitionRef empty_ref; static const ResourceXDecodedCommon empty_common; @@ -19038,8 +17590,7 @@ pcm_resource_x_s_predecessor_cancel_unbound_round_locked( return RESOURCE_X_APPLY_APPLIED; if (round->delivery_target.buffer_id_plus_one != 0) return RESOURCE_X_APPLY_BAD_STATE; - if (!pcm_resource_x_local_owner_valid_locked( - &entry->resource_x_local_owner)) + if (!pcm_resource_x_local_owner_valid_locked(&entry->resource_x_local_owner)) return RESOURCE_X_APPLY_APPLIED; if (entry->resource_x_local_owner.state != RESOURCE_X_LOCAL_OWNER_EMPTY) return RESOURCE_X_APPLY_APPLIED; @@ -19092,10 +17643,8 @@ pcm_resource_x_s_predecessor_cancel_unbound_round_locked( static bool pcm_resource_x_prepared_terminal_x_source_exact_locked( - struct GrdEntry *entry, const ResourceXDecodedFrame *block, - int32 authenticated_master_node, - const ClusterPcmOwnSnapshot *prepared_x_source, - const ResourceXLocalOwnerHandle *x_owner) + struct GrdEntry *entry, const ResourceXDecodedFrame *block, int32 authenticated_master_node, + const ClusterPcmOwnSnapshot *prepared_x_source, const ResourceXLocalOwnerHandle *x_owner) { ClusterPcmResourceXBootstrapRound *round; ClusterPcmResourceXLocalOwner *local_owner; @@ -19110,26 +17659,20 @@ pcm_resource_x_prepared_terminal_x_source_exact_locked( local_owner = &entry->resource_x_local_owner; memset(&lineage, 0, sizeof(lineage)); return pcm_resource_x_local_owner_valid_locked(local_owner) - && local_owner->state == RESOURCE_X_LOCAL_OWNER_REVOKING - && pcm_resource_x_local_owner_handle_equal( - &local_owner->handle, x_owner) - && pcm_resource_x_local_handoff_valid(&local_owner->handoff) - && pcm_resource_x_local_handoff_matches_handle( - &local_owner->handoff, x_owner) - && pcm_resource_x_local_handoff_successor_exact( - &local_owner->handoff, block, authenticated_master_node, - x_owner->r4_record_generation, prepared_x_source->generation) - && pcm_resource_x_local_handoff_round_current_locked( - &local_owner->handoff, round) - && pcm_resource_x_terminal_x_lineage_locked( - entry, round, block, authenticated_master_node, - x_owner->r4_record_generation, prepared_x_source->generation, - false, &lineage) - && pcm_resource_x_bootstrap_round_terminal_cover_exact_locked( - entry, round, &x_owner->ref, - x_owner->master_session_incarnation, - x_owner->r4_record_generation, - x_owner->buffer_ownership_generation); + && local_owner->state == RESOURCE_X_LOCAL_OWNER_REVOKING + && pcm_resource_x_local_owner_handle_equal(&local_owner->handle, x_owner) + && pcm_resource_x_local_handoff_valid(&local_owner->handoff) + && pcm_resource_x_local_handoff_matches_handle(&local_owner->handoff, x_owner) + && pcm_resource_x_local_handoff_successor_exact( + &local_owner->handoff, block, authenticated_master_node, + x_owner->r4_record_generation, prepared_x_source->generation) + && pcm_resource_x_local_handoff_round_current_locked(&local_owner->handoff, round) + && pcm_resource_x_terminal_x_lineage_locked( + entry, round, block, authenticated_master_node, x_owner->r4_record_generation, + prepared_x_source->generation, false, &lineage) + && pcm_resource_x_bootstrap_round_terminal_cover_exact_locked( + entry, round, &x_owner->ref, x_owner->master_session_incarnation, + x_owner->r4_record_generation, x_owner->buffer_ownership_generation); } /* Reconstruct local work only from the checked immutable pair and its exact @@ -19317,13 +17860,10 @@ cluster_pcm_lock_resource_x_source_finish_claim_exact(const ResourceXAcquisition static ResourceXApplyResult pcm_resource_x_block_to_n_source_exact_internal( const ResourceXDecodedFrame *block, int32 authenticated_master_node, - const ResourceXDecodedFrame *blocked_status, - const ResourceXDecodedFrame *image_envelope, - const ClusterPcmOwnSnapshot *prepared_s_source, - XLogRecPtr prepared_page_lsn, uint64 prepared_page_scn, - uint32 prepared_page_checksum, - const ClusterPcmOwnSnapshot *prepared_x_source, - const ResourceXLocalOwnerHandle *x_owner, + const ResourceXDecodedFrame *blocked_status, const ResourceXDecodedFrame *image_envelope, + const ClusterPcmOwnSnapshot *prepared_s_source, XLogRecPtr prepared_page_lsn, + uint64 prepared_page_scn, uint32 prepared_page_checksum, + const ClusterPcmOwnSnapshot *prepared_x_source, const ResourceXLocalOwnerHandle *x_owner, ClusterPcmXRevokeFinishMode required_x_finish_mode) { ClusterPcmResourceXHolderStatus status_record; @@ -19443,25 +17983,19 @@ pcm_resource_x_block_to_n_source_exact_internal( return RESOURCE_X_APPLY_STALE; if (shared_s_source) { if (prepared_s_source == NULL - || !BufferTagsEqual(&prepared_s_source->tag, - &block->common.logical_assertion.resource) - || prepared_s_source->generation == 0 - || prepared_s_source->generation == UINT64_MAX + || !BufferTagsEqual(&prepared_s_source->tag, &block->common.logical_assertion.resource) + || prepared_s_source->generation == 0 || prepared_s_source->generation == UINT64_MAX || prepared_s_source->reservation_token == 0 || prepared_s_source->flags != PCM_OWN_FLAG_REVOKING || prepared_s_source->pcm_state != (uint8)PCM_STATE_S || prepared_s_source->generation + 1 - != image_envelope->body.image_envelope.source_carrier_generation - || PageGetLSN((Page)image_envelope->body.image_envelope.page_bytes) - != prepared_page_lsn - || ((PageHeader)image_envelope->body.image_envelope.page_bytes) - ->pd_block_scn != prepared_page_scn - || image_envelope->body.image_envelope.page_scn_lsn - != prepared_page_scn - || image_envelope->body.image_envelope.page_checksum - != prepared_page_checksum - || image_envelope->body.image_envelope.source_fence[28] - != (uint8)PCM_STATE_S) + != image_envelope->body.image_envelope.source_carrier_generation + || PageGetLSN((Page)image_envelope->body.image_envelope.page_bytes) != prepared_page_lsn + || ((PageHeader)image_envelope->body.image_envelope.page_bytes)->pd_block_scn + != prepared_page_scn + || image_envelope->body.image_envelope.page_scn_lsn != prepared_page_scn + || image_envelope->body.image_envelope.page_checksum != prepared_page_checksum + || image_envelope->body.image_envelope.source_fence[28] != (uint8)PCM_STATE_S) return RESOURCE_X_APPLY_STALE; prepared_remote_s_source = true; } else if (prepared_s_source != NULL) { @@ -19469,44 +18003,35 @@ pcm_resource_x_block_to_n_source_exact_internal( } if (prepared_x_source != NULL || x_owner != NULL || required_x_finish_mode != CLUSTER_PCM_X_REVOKE_FINISH_INVALID) { - if (prepared_x_source == NULL || x_owner == NULL - || shared_s_source) + if (prepared_x_source == NULL || x_owner == NULL || shared_s_source) return RESOURCE_X_APPLY_INVALID; if ((required_x_finish_mode != CLUSTER_PCM_X_REVOKE_FINISH_RETAIN - && required_x_finish_mode != CLUSTER_PCM_X_REVOKE_FINISH_DROP) + && required_x_finish_mode != CLUSTER_PCM_X_REVOKE_FINISH_DROP) || !pcm_resource_x_local_owner_handle_valid(x_owner) - || cluster_pcm_x_revoke_finish_mode( - &block->common.logical_assertion.resource, 0) - != required_x_finish_mode - || !BufferTagsEqual(&prepared_x_source->tag, - &block->common.logical_assertion.resource) + || cluster_pcm_x_revoke_finish_mode(&block->common.logical_assertion.resource, 0) + != required_x_finish_mode + || !BufferTagsEqual(&prepared_x_source->tag, &block->common.logical_assertion.resource) || prepared_x_source->pcm_state != (uint8)PCM_STATE_X || prepared_x_source->flags != PCM_OWN_FLAG_REVOKING - || prepared_x_source->generation == 0 - || prepared_x_source->generation == UINT64_MAX + || prepared_x_source->generation == 0 || prepared_x_source->generation == UINT64_MAX || prepared_x_source->reservation_token == 0 || prepared_x_source->reservation_token == UINT64_MAX || prepared_x_source->writer_activation_token != 0 || prepared_x_source->resource_x_activation_generation != 0 - || x_owner->buffer_ownership_generation - != prepared_x_source->generation + || x_owner->buffer_ownership_generation != prepared_x_source->generation || x_owner->reservation_token == UINT64_MAX - || x_owner->reservation_token + 1 - != prepared_x_source->reservation_token + || x_owner->reservation_token + 1 != prepared_x_source->reservation_token || !BufferTagsEqual(&x_owner->ref.assertion.resource, - &block->common.logical_assertion.resource) - || x_owner->ref.formation - != block->common.resource_formation - || x_owner->master_session_incarnation - != block->common.master_session_incarnation - || pcm_resource_x_source_fence_get_u64( - image_envelope->body.image_envelope.source_fence + 20) - != prepared_x_source->generation - || image_envelope->body.image_envelope.source_fence[28] - != (uint8)PCM_STATE_X + &block->common.logical_assertion.resource) + || x_owner->ref.formation != block->common.resource_formation + || x_owner->master_session_incarnation != block->common.master_session_incarnation + || pcm_resource_x_source_fence_get_u64(image_envelope->body.image_envelope.source_fence + + 20) + != prepared_x_source->generation + || image_envelope->body.image_envelope.source_fence[28] != (uint8)PCM_STATE_X || image_envelope->body.image_envelope.source_fence[29] != 1 || image_envelope->body.image_envelope.source_carrier_generation - != prepared_x_source->generation + 1) + != prepared_x_source->generation + 1) return RESOURCE_X_APPLY_STALE; prepared_x_source_exact = true; } @@ -19520,29 +18045,25 @@ pcm_resource_x_block_to_n_source_exact_internal( canonical_image = *image_envelope; canonical_image.common.sender_connection_generation = PGRAC_RESOURCE_X_RETAINED_SENDER_GENERATION; - if (!cluster_resource_x_wire_encode( - RESOURCE_X_MSG_IMAGE_OR_GRANT, &canonical_image, - image_record.payload, sizeof(image_record.payload), - &image_payload_bytes, &reject) + if (!cluster_resource_x_wire_encode(RESOURCE_X_MSG_IMAGE_OR_GRANT, &canonical_image, + image_record.payload, sizeof(image_record.payload), + &image_payload_bytes, &reject) || image_payload_bytes != RESOURCE_X_IMAGE_V1_BYTES - || !cluster_resource_x_wire_decode( - RESOURCE_X_MSG_IMAGE_OR_GRANT, image_record.payload, - image_payload_bytes, &decoded_image, &reject) + || !cluster_resource_x_wire_decode(RESOURCE_X_MSG_IMAGE_OR_GRANT, image_record.payload, + image_payload_bytes, &decoded_image, &reject) || decoded_image.kind != RESOURCE_X_WIRE_IMAGE_ENVELOPE || decoded_image.common.sender_connection_generation - != PGRAC_RESOURCE_X_RETAINED_SENDER_GENERATION + != PGRAC_RESOURCE_X_RETAINED_SENDER_GENERATION || decoded_image.common.semantic_crc32c == 0) return RESOURCE_X_APPLY_INVALID; reject = RESOURCE_X_WIRE_REJECT_NONE; canonical_status = *blocked_status; canonical_status.common.sender_connection_generation = PGRAC_RESOURCE_X_RETAINED_SENDER_GENERATION; - canonical_status.body.blocked_to_n.source_proof_crc32c - = decoded_image.common.semantic_crc32c; - if (!cluster_resource_x_wire_encode( - RESOURCE_X_MSG_BLOCKED_TO_N, &canonical_status, - status_record.payload, sizeof(status_record.payload), - &status_payload_bytes, &reject) + canonical_status.body.blocked_to_n.source_proof_crc32c = decoded_image.common.semantic_crc32c; + if (!cluster_resource_x_wire_encode(RESOURCE_X_MSG_BLOCKED_TO_N, &canonical_status, + status_record.payload, sizeof(status_record.payload), + &status_payload_bytes, &reject) || status_payload_bytes != RESOURCE_X_PROOF_V1_BYTES) return RESOURCE_X_APPLY_INVALID; memset(&status_body, 0, sizeof(status_body)); @@ -19552,8 +18073,7 @@ pcm_resource_x_block_to_n_source_exact_internal( status_body.owner_kind = RESOURCE_X_INTENT_OWNER_HOLDER_STATUS; status_record.body = status_body; status_record.logical_generation = block->common.assertion_sequence; - status_record.authority_generation - = block->common.base_authority_generation; + status_record.authority_generation = block->common.base_authority_generation; status_record.resource_formation = block->common.resource_formation; status_record.destination_node = (uint32)authenticated_master_node; status_record.payload_bytes = status_payload_bytes; @@ -19566,22 +18086,18 @@ pcm_resource_x_block_to_n_source_exact_internal( image_body.owner_kind = RESOURCE_X_INTENT_OWNER_HOLDER_IMAGE; image_record.body = image_body; image_record.logical_generation = block->common.assertion_sequence; - image_record.authority_generation - = image_envelope->common.authority_generation; + image_record.authority_generation = image_envelope->common.authority_generation; image_record.resource_formation = block->common.resource_formation; - image_record.destination_node - = (uint32)block->common.logical_assertion.requester_node; + image_record.destination_node = (uint32)block->common.logical_assertion.requester_node; image_record.payload_bytes = image_payload_bytes; image_record.kind = RESOURCE_X_WIRE_IMAGE_ENVELOPE; image_record.valid = RESOURCE_X_HOLDER_PAIR_PENDING; - gate_formation - = pg_atomic_read_u64(&ClusterPcm->resource_x_gate_formation); - if (pg_atomic_read_u32(&ClusterPcm->resource_x_gate_phase) - != RESOURCE_X_GATE_OPEN + gate_formation = pg_atomic_read_u64(&ClusterPcm->resource_x_gate_formation); + if (pg_atomic_read_u32(&ClusterPcm->resource_x_gate_phase) != RESOURCE_X_GATE_OPEN || gate_formation != block->common.resource_formation) return RESOURCE_X_APPLY_RECOVERY_BLOCKED; - if (!pcm_entry_ref_acquire(&block->common.logical_assertion.resource, - false, &entry_ref, &acquire_result)) { + if (!pcm_entry_ref_acquire(&block->common.logical_assertion.resource, false, &entry_ref, + &acquire_result)) { if (acquire_result != PCM_ENTRY_ACQUIRE_NOT_FOUND) return RESOURCE_X_APPLY_RECOVERY_BLOCKED; /* The exact current-X carrier is a BufferDesc property on a node whose @@ -19589,8 +18105,8 @@ pcm_resource_x_block_to_n_source_exact_internal( * caller has already frozen and revalidated that BufferDesc lineage. * Allocate only the existing keyed Resource-X container so the retained * type-18/type-15 pair has a local owner; this does not create authority. */ - if (!pcm_entry_ref_acquire(&block->common.logical_assertion.resource, - true, &entry_ref, &acquire_result)) + if (!pcm_entry_ref_acquire(&block->common.logical_assertion.resource, true, &entry_ref, + &acquire_result)) return RESOURCE_X_APPLY_RECOVERY_BLOCKED; created_retention_container = true; } @@ -19618,14 +18134,12 @@ pcm_resource_x_block_to_n_source_exact_internal( * self-master DROP is instead admitted by local_grd_source below; its * exact REVOKING snapshot remains a physical-finish fence and must not * replace or veto that canonical local GRD authority. */ - if (prepared_x_source_exact - && authenticated_master_node != cluster_node_id + if (prepared_x_source_exact && authenticated_master_node != cluster_node_id && !prepared_terminal_x_source_exact) { ResourceXApplyResult result - = pcm_resource_x_local_owner_valid_locked( - &entry->resource_x_local_owner) - ? RESOURCE_X_APPLY_STALE - : RESOURCE_X_APPLY_RECOVERY_BLOCKED; + = pcm_resource_x_local_owner_valid_locked(&entry->resource_x_local_owner) + ? RESOURCE_X_APPLY_STALE + : RESOURCE_X_APPLY_RECOVERY_BLOCKED; LWLockRelease(&entry->entry_lock.lock); pcm_entry_ref_release(&entry_ref); @@ -19640,36 +18154,31 @@ pcm_resource_x_block_to_n_source_exact_internal( bool exact_drop_episode_restart = false; bool canonical_successor; - exact_existing = state->holder_status.valid - == state->holder_image.valid - && (state->holder_status.valid - == RESOURCE_X_HOLDER_PAIR_PENDING - || state->holder_status.valid - == RESOURCE_X_HOLDER_PAIR_PUBLISHED) - && state->holder_status.payload_bytes - == status_record.payload_bytes - && state->holder_image.payload_bytes - == image_record.payload_bytes - && memcmp(state->holder_status.payload, - status_record.payload, status_record.payload_bytes) == 0 - && memcmp(state->holder_image.payload, - image_record.payload, image_record.payload_bytes) == 0; + exact_existing = state->holder_status.valid == state->holder_image.valid + && (state->holder_status.valid == RESOURCE_X_HOLDER_PAIR_PENDING + || state->holder_status.valid == RESOURCE_X_HOLDER_PAIR_PUBLISHED) + && state->holder_status.payload_bytes == status_record.payload_bytes + && state->holder_image.payload_bytes == image_record.payload_bytes + && memcmp(state->holder_status.payload, status_record.payload, + status_record.payload_bytes) + == 0 + && memcmp(state->holder_image.payload, image_record.payload, + image_record.payload_bytes) + == 0; if (exact_existing) { /* A drained pair is a cleanup tombstone. Replaying its type-17 * cannot resurrect outbound payload ownership or physical PI. */ - exact_existing_drained = state->holder_pair_drained_sequences - [status_record.body.assertion.requester_node] - >= status_record.logical_generation - && state->holder_pair_drained_resource_formation - == status_record.resource_formation - && state->holder_pair_drained_master_session - == block->common.master_session_incarnation - && state->holder_pair_drained_master_node - == authenticated_master_node; + exact_existing_drained + = state->holder_pair_drained_sequences[status_record.body.assertion.requester_node] + >= status_record.logical_generation + && state->holder_pair_drained_resource_formation + == status_record.resource_formation + && state->holder_pair_drained_master_session + == block->common.master_session_incarnation + && state->holder_pair_drained_master_node == authenticated_master_node; if (!exact_existing_drained && prepared_remote_s_source) { - result - = pcm_resource_x_s_predecessor_cancel_unbound_round_locked( - entry, block, authenticated_master_node, &broadcast); + result = pcm_resource_x_s_predecessor_cancel_unbound_round_locked( + entry, block, authenticated_master_node, &broadcast); if (result != RESOURCE_X_APPLY_APPLIED) { LWLockRelease(&entry->entry_lock.lock); pcm_entry_ref_release(&entry_ref); @@ -19694,25 +18203,20 @@ pcm_resource_x_block_to_n_source_exact_internal( * requester is ordered here by exact drain and carrier or terminal * authority fences instead. The monotone per-requester tombstone remains * so a delayed old DRAIN still replays exactly. */ - result = pcm_resource_x_holder_pair_decode_locked( - state, &old_status, &old_image); - local_grd_source = state->authority_generation - == block->common.base_authority_generation - && (PcmState)pg_atomic_read_u32(&entry->master_state) - == PCM_STATE_X - && entry->x_holder_node == cluster_node_id; - installed_remote_source = authenticated_master_node != cluster_node_id - && entry->resource_x_requester_base_generation >= 1 - && entry->resource_x_requester_base_generation - <= block->common.base_authority_generation - && entry->resource_x_retired_acquisition_generation != 0 - && pcm_resource_x_active_empty_locked(entry) - && state->authority_generation - <= block->common.base_authority_generation - && (PcmState)pg_atomic_read_u32(&entry->master_state) - == PCM_STATE_N - && entry->x_holder_node == -1 - && pg_atomic_read_u32(&entry->s_holders_bitmap) == 0; + result = pcm_resource_x_holder_pair_decode_locked(state, &old_status, &old_image); + local_grd_source = state->authority_generation == block->common.base_authority_generation + && (PcmState)pg_atomic_read_u32(&entry->master_state) == PCM_STATE_X + && entry->x_holder_node == cluster_node_id; + installed_remote_source + = authenticated_master_node != cluster_node_id + && entry->resource_x_requester_base_generation >= 1 + && entry->resource_x_requester_base_generation + <= block->common.base_authority_generation + && entry->resource_x_retired_acquisition_generation != 0 + && pcm_resource_x_active_empty_locked(entry) + && state->authority_generation <= block->common.base_authority_generation + && (PcmState)pg_atomic_read_u32(&entry->master_state) == PCM_STATE_N + && entry->x_holder_node == -1 && pg_atomic_read_u32(&entry->s_holders_bitmap) == 0; /* Descriptor generations order one physical carrier episode only. * A later proven current-X acquisition has the same canonical order * for local/remote masters and RETAIN/DROP. Neither a bare mirror nor @@ -19758,13 +18262,11 @@ pcm_resource_x_block_to_n_source_exact_internal( && !exact_drop_episode_restart && !canonical_successor)) { LWLockRelease(&entry->entry_lock.lock); pcm_entry_ref_release(&entry_ref); - return result == RESOURCE_X_APPLY_RECOVERY_BLOCKED - ? result : RESOURCE_X_APPLY_STALE; + return result == RESOURCE_X_APPLY_RECOVERY_BLOCKED ? result : RESOURCE_X_APPLY_STALE; } if (prepared_remote_s_source) { - result - = pcm_resource_x_s_predecessor_cancel_unbound_round_locked( - entry, block, authenticated_master_node, &broadcast); + result = pcm_resource_x_s_predecessor_cancel_unbound_round_locked( + entry, block, authenticated_master_node, &broadcast); if (result != RESOURCE_X_APPLY_APPLIED) { LWLockRelease(&entry->entry_lock.lock); pcm_entry_ref_release(&entry_ref); @@ -19780,64 +18282,55 @@ pcm_resource_x_block_to_n_source_exact_internal( pcm_entry_ref_release(&entry_ref); return RESOURCE_X_APPLY_APPLIED; } - local_grd_source = state->authority_generation - == block->common.base_authority_generation - && (PcmState)pg_atomic_read_u32(&entry->master_state) == PCM_STATE_X - && entry->x_holder_node == cluster_node_id; + local_grd_source = state->authority_generation == block->common.base_authority_generation + && (PcmState)pg_atomic_read_u32(&entry->master_state) == PCM_STATE_X + && entry->x_holder_node == cluster_node_id; /* A remote Resource-X master is authoritative for the type-17 current-X * selection. The installed holder's local GRD entry is intentionally a * non-authoritative N mirror; bind it instead to the exact final authority * recorded by the completed requester install. The caller has already * frozen and encoded the matching BufferDesc X+REVOKING lineage. */ - installed_remote_source = authenticated_master_node != cluster_node_id - && entry->resource_x_requester_base_generation >= 1 - && entry->resource_x_requester_base_generation - <= block->common.base_authority_generation - && entry->resource_x_retired_acquisition_generation != 0 - && pcm_resource_x_active_empty_locked(entry) - && state->authority_generation - <= block->common.base_authority_generation - && (PcmState)pg_atomic_read_u32(&entry->master_state) == PCM_STATE_N - && entry->x_holder_node == -1 - && pg_atomic_read_u32(&entry->s_holders_bitmap) == 0; + installed_remote_source + = authenticated_master_node != cluster_node_id + && entry->resource_x_requester_base_generation >= 1 + && entry->resource_x_requester_base_generation <= block->common.base_authority_generation + && entry->resource_x_retired_acquisition_generation != 0 + && pcm_resource_x_active_empty_locked(entry) + && state->authority_generation <= block->common.base_authority_generation + && (PcmState)pg_atomic_read_u32(&entry->master_state) == PCM_STATE_N + && entry->x_holder_node == -1 && pg_atomic_read_u32(&entry->s_holders_bitmap) == 0; /* PGRAC adaptation for the direct last-current carrier: only a container * that was absent at this call and is still byte-for-byte pristine on all * authority/lifecycle axes may retain the pair. It remains N/no-holder; * bitmap or historical PI provenance never enters this decision. Base 1 * is the frozen clean-formation slice; later bases require installed-holder * lineage above and fail closed here. */ - pristine_remote_source = !shared_s_source && created_retention_container - && authenticated_master_node != cluster_node_id - && block->common.base_authority_generation == UINT64_C(1) - && state->authority_generation == UINT64_C(1) - && state->next_enqueue_order == UINT64_C(1) - && entry->resource_x_requester_base_generation == UINT64_C(1) - && entry->resource_x_retired_acquisition_generation == 0 - && pcm_resource_x_active_empty_locked(entry) - && pcm_resource_x_requester_join_empty_locked(&state->requester_join) - && state->grant_intent.slot.state == RESOURCE_X_INTENT_SLOT_EMPTY - && state->requester_settlement_intent.slot.state - == RESOURCE_X_INTENT_SLOT_EMPTY - && (PcmState)pg_atomic_read_u32(&entry->master_state) == PCM_STATE_N - && entry->x_holder_node == -1 - && pg_atomic_read_u32(&entry->s_holders_bitmap) == 0 - && pg_atomic_read_u32(&entry->pi_holders_bitmap) == 0 - && pg_atomic_read_u64(&entry->transition_count_local) == 0; - if ((!local_grd_source && !installed_remote_source - && !pristine_remote_source && !prepared_remote_s_source - && !prepared_terminal_x_source_exact) - || state->holder_status_intent.slot.state - != RESOURCE_X_INTENT_SLOT_EMPTY - || state->holder_image_intent.state - != RESOURCE_X_INTENT_SLOT_EMPTY) { + pristine_remote_source + = !shared_s_source && created_retention_container + && authenticated_master_node != cluster_node_id + && block->common.base_authority_generation == UINT64_C(1) + && state->authority_generation == UINT64_C(1) && state->next_enqueue_order == UINT64_C(1) + && entry->resource_x_requester_base_generation == UINT64_C(1) + && entry->resource_x_retired_acquisition_generation == 0 + && pcm_resource_x_active_empty_locked(entry) + && pcm_resource_x_requester_join_empty_locked(&state->requester_join) + && state->grant_intent.slot.state == RESOURCE_X_INTENT_SLOT_EMPTY + && state->requester_settlement_intent.slot.state == RESOURCE_X_INTENT_SLOT_EMPTY + && (PcmState)pg_atomic_read_u32(&entry->master_state) == PCM_STATE_N + && entry->x_holder_node == -1 && pg_atomic_read_u32(&entry->s_holders_bitmap) == 0 + && pg_atomic_read_u32(&entry->pi_holders_bitmap) == 0 + && pg_atomic_read_u64(&entry->transition_count_local) == 0; + if ((!local_grd_source && !installed_remote_source && !pristine_remote_source + && !prepared_remote_s_source && !prepared_terminal_x_source_exact) + || state->holder_status_intent.slot.state != RESOURCE_X_INTENT_SLOT_EMPTY + || state->holder_image_intent.state != RESOURCE_X_INTENT_SLOT_EMPTY) { LWLockRelease(&entry->entry_lock.lock); pcm_entry_ref_release(&entry_ref); return RESOURCE_X_APPLY_BAD_STATE; } if (prepared_remote_s_source) { - ResourceXApplyResult result - = pcm_resource_x_s_predecessor_cancel_unbound_round_locked( - entry, block, authenticated_master_node, &broadcast); + ResourceXApplyResult result = pcm_resource_x_s_predecessor_cancel_unbound_round_locked( + entry, block, authenticated_master_node, &broadcast); if (result != RESOURCE_X_APPLY_APPLIED) { LWLockRelease(&entry->entry_lock.lock); @@ -19852,14 +18345,13 @@ pcm_resource_x_block_to_n_source_exact_internal( * master X until the retained BLOCKED_TO_N is authenticated and applied. * A remote-master holder owns only its local mirror and may retire it now. */ if (authenticated_master_node != cluster_node_id && local_grd_source) - cluster_pcm_transition_apply(entry, PCM_TRANS_X_TO_N_DOWNGRADE, - cluster_node_id); + cluster_pcm_transition_apply(entry, PCM_TRANS_X_TO_N_DOWNGRADE, cluster_node_id); broadcast = true; LWLockRelease(&entry->entry_lock.lock); if (broadcast) ConditionVariableBroadcast(&entry->wait_cv); pcm_entry_ref_release(&entry_ref); -return RESOURCE_X_APPLY_APPLIED; + return RESOURCE_X_APPLY_APPLIED; } /* Classify an exact replay without touching transport state. APPLIED means @@ -19870,9 +18362,10 @@ return RESOURCE_X_APPLY_APPLIED; * the caller may build current frames, but the source replacement contract * still requires the predecessor's DRAIN tombstone before publishing them. */ ResourceXApplyResult -cluster_pcm_lock_resource_x_holder_pair_publish_needed_exact( - const ResourceXAssertion *assertion, uint64 assertion_sequence, - int32 authenticated_master_node, uint64 authenticated_master_session) +cluster_pcm_lock_resource_x_holder_pair_publish_needed_exact(const ResourceXAssertion *assertion, + uint64 assertion_sequence, + int32 authenticated_master_node, + uint64 authenticated_master_session) { ClusterPcmResourceXMasterState *state; ResourceXDecodedFrame image; @@ -19884,13 +18377,11 @@ cluster_pcm_lock_resource_x_holder_pair_publish_needed_exact( uint64 gate_formation; if (!resource_x_assertion_valid(assertion) || assertion_sequence == 0 - || assertion_sequence == UINT64_MAX - || authenticated_master_node < 0 + || assertion_sequence == UINT64_MAX || authenticated_master_node < 0 || authenticated_master_node >= RESOURCE_X_PROTOCOL_NODE_LIMIT || authenticated_master_session == 0 || ClusterPcm == NULL) return RESOURCE_X_APPLY_INVALID; - if (!pcm_entry_ref_acquire(&assertion->resource, false, - &entry_ref, &acquire_result)) + if (!pcm_entry_ref_acquire(&assertion->resource, false, &entry_ref, &acquire_result)) return RESOURCE_X_APPLY_NOT_FOUND; entry = entry_ref.entry; LWLockAcquire(&entry->entry_lock.lock, LW_SHARED); @@ -19900,24 +18391,19 @@ cluster_pcm_lock_resource_x_holder_pair_publish_needed_exact( goto pair_needed_done; } result = pcm_resource_x_holder_pair_drain_domain_locked( - &entry->tag, state, authenticated_master_node, - authenticated_master_session, assertion, assertion_sequence); - if (result == RESOURCE_X_APPLY_DUPLICATE - || result == RESOURCE_X_APPLY_RECOVERY_BLOCKED + &entry->tag, state, authenticated_master_node, authenticated_master_session, assertion, + assertion_sequence); + if (result == RESOURCE_X_APPLY_DUPLICATE || result == RESOURCE_X_APPLY_RECOVERY_BLOCKED || result == RESOURCE_X_APPLY_STALE) goto pair_needed_done; result = pcm_resource_x_holder_pair_decode_locked(state, &status, &image); if (result != RESOURCE_X_APPLY_APPLIED) goto pair_needed_done; - gate_formation - = pg_atomic_read_u64(&ClusterPcm->resource_x_gate_formation); - if (!resource_x_assertion_equal( - assertion, &status.common.logical_assertion) + gate_formation = pg_atomic_read_u64(&ClusterPcm->resource_x_gate_formation); + if (!resource_x_assertion_equal(assertion, &status.common.logical_assertion) || status.common.resource_formation != gate_formation - || status.common.master_session_incarnation - != authenticated_master_session - || state->holder_status.destination_node - != (uint32)authenticated_master_node) { + || status.common.master_session_incarnation != authenticated_master_session + || state->holder_status.destination_node != (uint32)authenticated_master_node) { result = RESOURCE_X_APPLY_STALE; goto pair_needed_done; } @@ -19931,12 +18417,9 @@ cluster_pcm_lock_resource_x_holder_pair_publish_needed_exact( } if (state->holder_status.valid == RESOURCE_X_HOLDER_PAIR_PUBLISHED) result = RESOURCE_X_APPLY_DUPLICATE; - else if (state->holder_status.valid - == RESOURCE_X_HOLDER_PAIR_PENDING - && state->holder_status_intent.slot.state - == RESOURCE_X_INTENT_SLOT_EMPTY - && state->holder_image_intent.state - == RESOURCE_X_INTENT_SLOT_EMPTY) + else if (state->holder_status.valid == RESOURCE_X_HOLDER_PAIR_PENDING + && state->holder_status_intent.slot.state == RESOURCE_X_INTENT_SLOT_EMPTY + && state->holder_image_intent.state == RESOURCE_X_INTENT_SLOT_EMPTY) result = RESOURCE_X_APPLY_APPLIED; else result = RESOURCE_X_APPLY_RECOVERY_BLOCKED; @@ -19969,13 +18452,11 @@ pcm_resource_x_holder_pair_publish_internal(const ResourceXAssertion *assertion, bool status_ready; if (!resource_x_assertion_valid(assertion) || assertion_sequence == 0 - || assertion_sequence == UINT64_MAX - || authenticated_master_node < 0 + || assertion_sequence == UINT64_MAX || authenticated_master_node < 0 || authenticated_master_node >= RESOURCE_X_PROTOCOL_NODE_LIMIT || authenticated_master_session == 0 || ClusterPcm == NULL) return RESOURCE_X_APPLY_INVALID; - if (!pcm_entry_ref_acquire(&assertion->resource, false, - &entry_ref, &acquire_result)) + if (!pcm_entry_ref_acquire(&assertion->resource, false, &entry_ref, &acquire_result)) return RESOURCE_X_APPLY_NOT_FOUND; entry = entry_ref.entry; pcm_entry_lock_exclusive(entry); @@ -19985,32 +18466,25 @@ pcm_resource_x_holder_pair_publish_internal(const ResourceXAssertion *assertion, goto pair_publish_done; } result = pcm_resource_x_holder_pair_drain_domain_locked( - &entry->tag, state, authenticated_master_node, - authenticated_master_session, assertion, assertion_sequence); - if (result == RESOURCE_X_APPLY_DUPLICATE - || result == RESOURCE_X_APPLY_RECOVERY_BLOCKED + &entry->tag, state, authenticated_master_node, authenticated_master_session, assertion, + assertion_sequence); + if (result == RESOURCE_X_APPLY_DUPLICATE || result == RESOURCE_X_APPLY_RECOVERY_BLOCKED || result == RESOURCE_X_APPLY_STALE) goto pair_publish_done; result = pcm_resource_x_holder_pair_decode_locked(state, &status, &image); if (result != RESOURCE_X_APPLY_APPLIED) goto pair_publish_done; - gate_formation - = pg_atomic_read_u64(&ClusterPcm->resource_x_gate_formation); - if (!resource_x_assertion_equal( - assertion, &status.common.logical_assertion) + gate_formation = pg_atomic_read_u64(&ClusterPcm->resource_x_gate_formation); + if (!resource_x_assertion_equal(assertion, &status.common.logical_assertion) || status.common.assertion_sequence != assertion_sequence || status.common.resource_formation != gate_formation - || status.common.master_session_incarnation - != authenticated_master_session - || state->holder_status.destination_node - != (uint32)authenticated_master_node) { + || status.common.master_session_incarnation != authenticated_master_session + || state->holder_status.destination_node != (uint32)authenticated_master_node) { result = RESOURCE_X_APPLY_STALE; goto pair_publish_done; } - status_ready = state->holder_status_intent.slot.state - != RESOURCE_X_INTENT_SLOT_EMPTY; - image_ready = state->holder_image_intent.state - != RESOURCE_X_INTENT_SLOT_EMPTY; + status_ready = state->holder_status_intent.slot.state != RESOURCE_X_INTENT_SLOT_EMPTY; + image_ready = state->holder_image_intent.state != RESOURCE_X_INTENT_SLOT_EMPTY; if (replay) { if (state->holder_status.valid != RESOURCE_X_HOLDER_PAIR_PUBLISHED || !pcm_resource_x_holder_source_slots_exact(state, &state->holder_status, @@ -20035,20 +18509,19 @@ pcm_resource_x_holder_pair_publish_internal(const ResourceXAssertion *assertion, } if (state->holder_status.valid == RESOURCE_X_HOLDER_PAIR_PUBLISHED) { if (!status_ready - || !pcm_resource_x_rearm_holder_source_locked( - state, &state->holder_status, &state->holder_image)) + || !pcm_resource_x_rearm_holder_source_locked(state, &state->holder_status, + &state->holder_image)) result = RESOURCE_X_APPLY_RECOVERY_BLOCKED; else result = RESOURCE_X_APPLY_DUPLICATE; goto pair_publish_done; } - if (state->holder_status.valid != RESOURCE_X_HOLDER_PAIR_PENDING - || status_ready) { + if (state->holder_status.valid != RESOURCE_X_HOLDER_PAIR_PENDING || status_ready) { result = RESOURCE_X_APPLY_RECOVERY_BLOCKED; goto pair_publish_done; } - if (!pcm_resource_x_rearm_holder_source_locked( - state, &state->holder_status, &state->holder_image)) { + if (!pcm_resource_x_rearm_holder_source_locked(state, &state->holder_status, + &state->holder_image)) { result = RESOURCE_X_APPLY_RECOVERY_BLOCKED; goto pair_publish_done; } @@ -20092,10 +18565,11 @@ cluster_pcm_lock_resource_x_holder_pair_replay_exact(const ResourceXAssertion *a * carrier generation additionally binds the result to a sampled BufferDesc * carrier; zero is used only by the pre-round ordering check. */ static ResourceXApplyResult -pcm_resource_x_holder_pair_precedes_local_bootstrap_locked( - struct GrdEntry *entry, int32 current_master_node, - uint64 current_master_session, uint64 current_formation, - uint64 expected_carrier_generation) +pcm_resource_x_holder_pair_precedes_local_bootstrap_locked(struct GrdEntry *entry, + int32 current_master_node, + uint64 current_master_session, + uint64 current_formation, + uint64 expected_carrier_generation) { ClusterPcmResourceXMasterState *state; ResourceXDecodedFrame image; @@ -20108,56 +18582,42 @@ pcm_resource_x_holder_pair_precedes_local_bootstrap_locked( Assert(entry != NULL); Assert(LWLockHeldByMeInMode(&entry->entry_lock.lock, LW_SHARED) - || LWLockHeldByMeInMode(&entry->entry_lock.lock, LW_EXCLUSIVE)); + || LWLockHeldByMeInMode(&entry->entry_lock.lock, LW_EXCLUSIVE)); state = pcm_resource_x_master_state_for_entry(entry); if (state == NULL) return RESOURCE_X_APPLY_RECOVERY_BLOCKED; - decoded = pcm_resource_x_holder_pair_decode_locked( - state, &status, &image); + decoded = pcm_resource_x_holder_pair_decode_locked(state, &status, &image); if (decoded != RESOURCE_X_APPLY_APPLIED) return decoded; domain = pcm_resource_x_holder_pair_drain_domain_locked( - &entry->tag, state, current_master_node, - current_master_session, &status.common.logical_assertion, - status.common.assertion_sequence); + &entry->tag, state, current_master_node, current_master_session, + &status.common.logical_assertion, status.common.assertion_sequence); if (domain == RESOURCE_X_APPLY_DUPLICATE) return RESOURCE_X_APPLY_NOT_FOUND; if (domain != RESOURCE_X_APPLY_NOT_FOUND) return domain; source_mode = status.common.observed_mode; - source_generation = pcm_resource_x_source_fence_get_u64( - image.body.image_envelope.source_fence + 20); - carrier_generation - = image.body.image_envelope.source_carrier_generation; + source_generation + = pcm_resource_x_source_fence_get_u64(image.body.image_envelope.source_fence + 20); + carrier_generation = image.body.image_envelope.source_carrier_generation; if (state->holder_status.valid != state->holder_image.valid - || (state->holder_status.valid - != RESOURCE_X_HOLDER_PAIR_PENDING - && state->holder_status.valid - != RESOURCE_X_HOLDER_PAIR_PUBLISHED) - || state->holder_status.destination_node - != (uint32)current_master_node + || (state->holder_status.valid != RESOURCE_X_HOLDER_PAIR_PENDING + && state->holder_status.valid != RESOURCE_X_HOLDER_PAIR_PUBLISHED) + || state->holder_status.destination_node != (uint32)current_master_node || status.common.resource_formation != current_formation || image.common.resource_formation != current_formation - || status.common.master_session_incarnation - != current_master_session - || image.common.master_session_incarnation - != current_master_session + || status.common.master_session_incarnation != current_master_session + || image.common.master_session_incarnation != current_master_session || status.common.action_node != cluster_node_id || status.common.target_mode != (uint8)PCM_STATE_N - || status.common.flags - != RESOURCE_X_COMMON_FLAG_PI_ESTABLISHED - || (source_mode != (uint8)PCM_STATE_X - && source_mode != (uint8)PCM_STATE_S) + || status.common.flags != RESOURCE_X_COMMON_FLAG_PI_ESTABLISHED + || (source_mode != (uint8)PCM_STATE_X && source_mode != (uint8)PCM_STATE_S) || image.common.observed_mode != source_mode || status.body.blocked_to_n.source_fence[28] != source_mode - || image.body.image_envelope.source_fence[28] != source_mode - || source_generation == 0 - || source_generation == UINT64_MAX - || carrier_generation == 0 - || carrier_generation == UINT64_MAX - || carrier_generation != source_generation + 1 - || (expected_carrier_generation != 0 - && carrier_generation != expected_carrier_generation)) + || image.body.image_envelope.source_fence[28] != source_mode || source_generation == 0 + || source_generation == UINT64_MAX || carrier_generation == 0 + || carrier_generation == UINT64_MAX || carrier_generation != source_generation + 1 + || (expected_carrier_generation != 0 && carrier_generation != expected_carrier_generation)) return RESOURCE_X_APPLY_STALE; return RESOURCE_X_APPLY_APPLIED; } @@ -20200,10 +18660,11 @@ pcm_resource_x_predecessor_wait_observation_locked(struct GrdEntry *entry, * no authority and creates no replacement round; it merely prevents the old * waiter from turning a successful rollback into terminal STALE. */ static bool -pcm_resource_x_s_predecessor_superseded_unbound_wait_locked( - struct GrdEntry *entry, const ResourceXAssertion *assertion, - int32 current_master_node, uint64 current_master_session, - uint64 current_formation) +pcm_resource_x_s_predecessor_superseded_unbound_wait_locked(struct GrdEntry *entry, + const ResourceXAssertion *assertion, + int32 current_master_node, + uint64 current_master_session, + uint64 current_formation) { ClusterPcmResourceXBootstrapRound *round; ClusterPcmResourceXMasterState *state; @@ -20212,30 +18673,26 @@ pcm_resource_x_s_predecessor_superseded_unbound_wait_locked( Assert(entry != NULL); Assert(LWLockHeldByMeInMode(&entry->entry_lock.lock, LW_SHARED) - || LWLockHeldByMeInMode(&entry->entry_lock.lock, LW_EXCLUSIVE)); - if (assertion == NULL - || assertion->requester_node != cluster_node_id + || LWLockHeldByMeInMode(&entry->entry_lock.lock, LW_EXCLUSIVE)); + if (assertion == NULL || assertion->requester_node != cluster_node_id || !BufferTagsEqual(&assertion->resource, &entry->tag)) return false; round = &entry->resource_x_bootstrap_round; - if (round->phase != RESOURCE_X_BOOTSTRAP_ROUND_EMPTY - || round->highest_attempt_floor == 0 + if (round->phase != RESOURCE_X_BOOTSTRAP_ROUND_EMPTY || round->highest_attempt_floor == 0 || round->highest_attempt_floor == UINT64_MAX - || !pcm_resource_x_local_owner_valid_locked( - &entry->resource_x_local_owner) - || entry->resource_x_local_owner.state - != RESOURCE_X_LOCAL_OWNER_EMPTY + || !pcm_resource_x_local_owner_valid_locked(&entry->resource_x_local_owner) + || entry->resource_x_local_owner.state != RESOURCE_X_LOCAL_OWNER_EMPTY || pcm_resource_x_holder_pair_precedes_local_bootstrap_locked( - entry, current_master_node, current_master_session, - current_formation, 0) != RESOURCE_X_APPLY_APPLIED) + entry, current_master_node, current_master_session, current_formation, 0) + != RESOURCE_X_APPLY_APPLIED) return false; state = pcm_resource_x_master_state_for_entry(entry); if (state == NULL - || pcm_resource_x_holder_pair_decode_locked( - state, &status, &image) != RESOURCE_X_APPLY_APPLIED) + || pcm_resource_x_holder_pair_decode_locked(state, &status, &image) + != RESOURCE_X_APPLY_APPLIED) return false; return status.common.observed_mode == (uint8)PCM_STATE_S - && image.common.observed_mode == (uint8)PCM_STATE_S; + && image.common.observed_mode == (uint8)PCM_STATE_S; } /* A former holder's local target acquire may observe the physical N+PI @@ -20244,28 +18701,22 @@ pcm_resource_x_s_predecessor_superseded_unbound_wait_locked( * generation to one current, PENDING/PUBLISHED and not-yet-drained retained * pair so the caller can wait locally before starting a new bootstrap round. */ static bool -pcm_resource_x_holder_pair_retained_fence_internal( - const BufferTag *tag, int32 current_master_node, - uint64 current_master_session, uint64 current_formation, - uint64 retained_generation) +pcm_resource_x_holder_pair_retained_fence_internal(const BufferTag *tag, int32 current_master_node, + uint64 current_master_session, + uint64 current_formation, + uint64 retained_generation) { PcmEntryRef entry_ref; PcmEntryAcquireResult acquire_result; struct GrdEntry *entry; bool matches = false; - if (tag == NULL - || current_master_node < 0 - || current_master_node >= RESOURCE_X_PROTOCOL_NODE_LIMIT - || current_master_session == 0 - || current_master_session == UINT64_MAX - || current_formation == 0 - || current_formation == UINT64_MAX - || retained_generation == 0 - || retained_generation == UINT64_MAX - || cluster_node_id < 0 - || cluster_node_id >= RESOURCE_X_PROTOCOL_NODE_LIMIT - || ClusterPcm == NULL) + if (tag == NULL || current_master_node < 0 + || current_master_node >= RESOURCE_X_PROTOCOL_NODE_LIMIT || current_master_session == 0 + || current_master_session == UINT64_MAX || current_formation == 0 + || current_formation == UINT64_MAX || retained_generation == 0 + || retained_generation == UINT64_MAX || cluster_node_id < 0 + || cluster_node_id >= RESOURCE_X_PROTOCOL_NODE_LIMIT || ClusterPcm == NULL) return false; if (!pcm_entry_ref_acquire(tag, false, &entry_ref, &acquire_result)) return false; @@ -20273,8 +18724,9 @@ pcm_resource_x_holder_pair_retained_fence_internal( LWLockAcquire(&entry->entry_lock.lock, LW_SHARED); matches = pcm_resource_x_holder_pair_precedes_local_bootstrap_locked( - entry, current_master_node, current_master_session, - current_formation, retained_generation) == RESOURCE_X_APPLY_APPLIED; + entry, current_master_node, current_master_session, current_formation, + retained_generation) + == RESOURCE_X_APPLY_APPLIED; LWLockRelease(&entry->entry_lock.lock); pcm_entry_ref_release(&entry_ref); @@ -20282,20 +18734,21 @@ pcm_resource_x_holder_pair_retained_fence_internal( } bool -cluster_pcm_lock_resource_x_holder_pair_retained_fence_exact( - const BufferTag *tag, int32 current_master_node, - uint64 current_master_session, uint64 current_formation, - uint64 retained_generation) +cluster_pcm_lock_resource_x_holder_pair_retained_fence_exact(const BufferTag *tag, + int32 current_master_node, + uint64 current_master_session, + uint64 current_formation, + uint64 retained_generation) { return pcm_resource_x_holder_pair_retained_fence_internal( - tag, current_master_node, current_master_session, - current_formation, retained_generation); + tag, current_master_node, current_master_session, current_formation, retained_generation); } ResourceXApplyResult -cluster_pcm_lock_resource_x_holder_status_intent_snapshot_exact( - const ResourceXAssertion *assertion, ResourceXIntentSlot *slot_out, - void *payload_out, uint16 payload_capacity) +cluster_pcm_lock_resource_x_holder_status_intent_snapshot_exact(const ResourceXAssertion *assertion, + ResourceXIntentSlot *slot_out, + void *payload_out, + uint16 payload_capacity) { ClusterPcmResourceXControlIntent *intent; ClusterPcmResourceXMasterState *state; @@ -20306,12 +18759,10 @@ cluster_pcm_lock_resource_x_holder_status_intent_snapshot_exact( if (slot_out != NULL) memset(slot_out, 0, sizeof(*slot_out)); - if (!resource_x_assertion_valid(assertion) || slot_out == NULL - || payload_out == NULL + if (!resource_x_assertion_valid(assertion) || slot_out == NULL || payload_out == NULL || payload_capacity < RESOURCE_X_CONTROL_V1_BYTES) return RESOURCE_X_APPLY_INVALID; - if (!pcm_entry_ref_acquire(&assertion->resource, false, - &entry_ref, &acquire_result)) + if (!pcm_entry_ref_acquire(&assertion->resource, false, &entry_ref, &acquire_result)) return RESOURCE_X_APPLY_NOT_FOUND; entry = entry_ref.entry; LWLockAcquire(&entry->entry_lock.lock, LW_SHARED); @@ -20325,24 +18776,20 @@ cluster_pcm_lock_resource_x_holder_status_intent_snapshot_exact( result = RESOURCE_X_APPLY_NOT_FOUND; goto holder_status_intent_done; } - if (!resource_x_assertion_equal(assertion, - &intent->slot.body.assertion)) { + if (!resource_x_assertion_equal(assertion, &intent->slot.body.assertion)) { result = RESOURCE_X_APPLY_STALE; goto holder_status_intent_done; } if (intent->slot.state > RESOURCE_X_INTENT_SLOT_STAGED || !pcm_resource_x_intent_body_valid(&intent->slot.body) || (intent->slot.payload_bytes == RESOURCE_X_PROOF_V1_BYTES - && state->holder_status.valid - != RESOURCE_X_HOLDER_PAIR_PUBLISHED) + && state->holder_status.valid != RESOURCE_X_HOLDER_PAIR_PUBLISHED) || intent->slot.payload_bytes > payload_capacity || (intent->slot.payload_bytes != RESOURCE_X_CONTROL_V1_BYTES && intent->slot.payload_bytes != RESOURCE_X_PROOF_V1_BYTES) || intent->slot.kind != RESOURCE_X_WIRE_BLOCKED_TO_N - || intent->slot.body.owner_kind - != RESOURCE_X_INTENT_OWNER_HOLDER_STATUS - || intent->slot.body.owner_node - >= RESOURCE_X_PROTOCOL_NODE_LIMIT + || intent->slot.body.owner_kind != RESOURCE_X_INTENT_OWNER_HOLDER_STATUS + || intent->slot.body.owner_node >= RESOURCE_X_PROTOCOL_NODE_LIMIT || intent->slot.body.owner_index != 0) { result = RESOURCE_X_APPLY_RECOVERY_BLOCKED; goto holder_status_intent_done; @@ -20358,73 +18805,63 @@ cluster_pcm_lock_resource_x_holder_status_intent_snapshot_exact( } ResourceXApplyResult -cluster_pcm_lock_resource_x_block_to_n_source_exact( - const ResourceXDecodedFrame *block, int32 authenticated_master_node, - const ResourceXDecodedFrame *blocked_status, - const ResourceXDecodedFrame *image_envelope) +cluster_pcm_lock_resource_x_block_to_n_source_exact(const ResourceXDecodedFrame *block, + int32 authenticated_master_node, + const ResourceXDecodedFrame *blocked_status, + const ResourceXDecodedFrame *image_envelope) { return pcm_resource_x_block_to_n_source_exact_internal( - block, authenticated_master_node, blocked_status, image_envelope, - NULL, InvalidXLogRecPtr, 0, 0, NULL, NULL, - CLUSTER_PCM_X_REVOKE_FINISH_INVALID); + block, authenticated_master_node, blocked_status, image_envelope, NULL, InvalidXLogRecPtr, + 0, 0, NULL, NULL, CLUSTER_PCM_X_REVOKE_FINISH_INVALID); } ResourceXApplyResult cluster_pcm_lock_resource_x_block_to_n_drop_x_source_exact( const ResourceXDecodedFrame *block, int32 authenticated_master_node, - const ResourceXDecodedFrame *blocked_status, - const ResourceXDecodedFrame *image_envelope, - const ClusterPcmOwnSnapshot *revoking, - const ResourceXLocalOwnerHandle *owner) + const ResourceXDecodedFrame *blocked_status, const ResourceXDecodedFrame *image_envelope, + const ClusterPcmOwnSnapshot *revoking, const ResourceXLocalOwnerHandle *owner) { if (revoking == NULL || owner == NULL) return RESOURCE_X_APPLY_INVALID; return pcm_resource_x_block_to_n_source_exact_internal( - block, authenticated_master_node, blocked_status, image_envelope, - NULL, InvalidXLogRecPtr, 0, 0, revoking, owner, - CLUSTER_PCM_X_REVOKE_FINISH_DROP); + block, authenticated_master_node, blocked_status, image_envelope, NULL, InvalidXLogRecPtr, + 0, 0, revoking, owner, CLUSTER_PCM_X_REVOKE_FINISH_DROP); } ResourceXApplyResult cluster_pcm_lock_resource_x_block_to_n_prepared_x_source_exact( const ResourceXDecodedFrame *block, int32 authenticated_master_node, - const ResourceXDecodedFrame *blocked_status, - const ResourceXDecodedFrame *image_envelope, - const ClusterPcmOwnSnapshot *revoking, - const ResourceXLocalOwnerHandle *owner) + const ResourceXDecodedFrame *blocked_status, const ResourceXDecodedFrame *image_envelope, + const ClusterPcmOwnSnapshot *revoking, const ResourceXLocalOwnerHandle *owner) { if (block == NULL || revoking == NULL || owner == NULL || block->common.observed_mode != (uint8)PCM_STATE_X) return RESOURCE_X_APPLY_INVALID; return pcm_resource_x_block_to_n_source_exact_internal( - block, authenticated_master_node, blocked_status, image_envelope, - NULL, InvalidXLogRecPtr, 0, 0, revoking, owner, - CLUSTER_PCM_X_REVOKE_FINISH_RETAIN); + block, authenticated_master_node, blocked_status, image_envelope, NULL, InvalidXLogRecPtr, + 0, 0, revoking, owner, CLUSTER_PCM_X_REVOKE_FINISH_RETAIN); } ResourceXApplyResult cluster_pcm_lock_resource_x_block_to_n_prepared_s_source_exact( const ResourceXDecodedFrame *block, int32 authenticated_master_node, - const ResourceXDecodedFrame *blocked_status, - const ResourceXDecodedFrame *image_envelope, - const ClusterPcmOwnSnapshot *prepared_source, - XLogRecPtr prepared_page_lsn, uint64 prepared_page_scn, - uint32 prepared_page_checksum) -{ - if (block == NULL - || block->common.observed_mode != (uint8)PCM_STATE_S) + const ResourceXDecodedFrame *blocked_status, const ResourceXDecodedFrame *image_envelope, + const ClusterPcmOwnSnapshot *prepared_source, XLogRecPtr prepared_page_lsn, + uint64 prepared_page_scn, uint32 prepared_page_checksum) +{ + if (block == NULL || block->common.observed_mode != (uint8)PCM_STATE_S) return RESOURCE_X_APPLY_INVALID; return pcm_resource_x_block_to_n_source_exact_internal( - block, authenticated_master_node, blocked_status, image_envelope, - prepared_source, prepared_page_lsn, prepared_page_scn, - prepared_page_checksum, NULL, NULL, + block, authenticated_master_node, blocked_status, image_envelope, prepared_source, + prepared_page_lsn, prepared_page_scn, prepared_page_checksum, NULL, NULL, CLUSTER_PCM_X_REVOKE_FINISH_INVALID); } ResourceXApplyResult -cluster_pcm_lock_resource_x_holder_image_intent_snapshot_exact( - const ResourceXAssertion *assertion, ResourceXIntentSlot *slot_out, - void *payload_out, uint16 payload_capacity) +cluster_pcm_lock_resource_x_holder_image_intent_snapshot_exact(const ResourceXAssertion *assertion, + ResourceXIntentSlot *slot_out, + void *payload_out, + uint16 payload_capacity) { ClusterPcmResourceXMasterState *state; PcmEntryRef entry_ref; @@ -20435,12 +18872,10 @@ cluster_pcm_lock_resource_x_holder_image_intent_snapshot_exact( if (slot_out != NULL) memset(slot_out, 0, sizeof(*slot_out)); - if (!resource_x_assertion_valid(assertion) || slot_out == NULL - || payload_out == NULL + if (!resource_x_assertion_valid(assertion) || slot_out == NULL || payload_out == NULL || payload_capacity < RESOURCE_X_IMAGE_V1_BYTES) return RESOURCE_X_APPLY_INVALID; - if (!pcm_entry_ref_acquire(&assertion->resource, false, - &entry_ref, &acquire_result)) + if (!pcm_entry_ref_acquire(&assertion->resource, false, &entry_ref, &acquire_result)) return RESOURCE_X_APPLY_NOT_FOUND; entry = entry_ref.entry; LWLockAcquire(&entry->entry_lock.lock, LW_SHARED); @@ -20465,19 +18900,15 @@ cluster_pcm_lock_resource_x_holder_image_intent_snapshot_exact( || intent->body.owner_kind != RESOURCE_X_INTENT_OWNER_HOLDER_IMAGE || intent->body.owner_node >= RESOURCE_X_PROTOCOL_NODE_LIMIT || intent->body.owner_index != 0 - || state->holder_image.valid - != RESOURCE_X_HOLDER_PAIR_PUBLISHED + || state->holder_image.valid != RESOURCE_X_HOLDER_PAIR_PUBLISHED || state->holder_image.payload_bytes != intent->payload_bytes - || state->holder_image.logical_generation - != intent->logical_generation - || state->holder_image.authority_generation - != intent->authority_generation) { + || state->holder_image.logical_generation != intent->logical_generation + || state->holder_image.authority_generation != intent->authority_generation) { result = RESOURCE_X_APPLY_RECOVERY_BLOCKED; goto holder_image_intent_done; } *slot_out = *intent; - memcpy(payload_out, state->holder_image.payload, - intent->payload_bytes); + memcpy(payload_out, state->holder_image.payload, intent->payload_bytes); result = RESOURCE_X_APPLY_APPLIED; holder_image_intent_done: @@ -20487,8 +18918,8 @@ cluster_pcm_lock_resource_x_holder_image_intent_snapshot_exact( } ResourceXApplyResult -cluster_pcm_lock_resource_x_holder_status_exact( - const ResourceXAssertion *assertion, ResourceXDecodedFrame *out) +cluster_pcm_lock_resource_x_holder_status_exact(const ResourceXAssertion *assertion, + ResourceXDecodedFrame *out) { ClusterPcmResourceXHolderStatus *record; ClusterPcmResourceXMasterState *state; @@ -20502,8 +18933,7 @@ cluster_pcm_lock_resource_x_holder_status_exact( memset(out, 0, sizeof(*out)); if (!resource_x_assertion_valid(assertion) || out == NULL) return RESOURCE_X_APPLY_INVALID; - if (!pcm_entry_ref_acquire(&assertion->resource, false, - &entry_ref, &acquire_result)) + if (!pcm_entry_ref_acquire(&assertion->resource, false, &entry_ref, &acquire_result)) return RESOURCE_X_APPLY_NOT_FOUND; entry = entry_ref.entry; LWLockAcquire(&entry->entry_lock.lock, LW_SHARED); @@ -20523,17 +18953,14 @@ cluster_pcm_lock_resource_x_holder_status_exact( } if ((record->valid != RESOURCE_X_HOLDER_PAIR_PENDING && record->valid != RESOURCE_X_HOLDER_PAIR_PUBLISHED) - || record->body.owner_kind - != RESOURCE_X_INTENT_OWNER_HOLDER_STATUS + || record->body.owner_kind != RESOURCE_X_INTENT_OWNER_HOLDER_STATUS || record->body.owner_index != 0 || record->body.owner_generation != record->logical_generation - || record->resource_formation == 0 - || record->payload_bytes < RESOURCE_X_CONTROL_V1_BYTES + || record->resource_formation == 0 || record->payload_bytes < RESOURCE_X_CONTROL_V1_BYTES || record->payload_bytes > RESOURCE_X_PROOF_V1_BYTES || record->kind != RESOURCE_X_WIRE_BLOCKED_TO_N - || !cluster_resource_x_wire_decode( - RESOURCE_X_MSG_BLOCKED_TO_N, record->payload, - record->payload_bytes, out, &reject)) { + || !cluster_resource_x_wire_decode(RESOURCE_X_MSG_BLOCKED_TO_N, record->payload, + record->payload_bytes, out, &reject)) { result = RESOURCE_X_APPLY_RECOVERY_BLOCKED; goto holder_status_done; } @@ -20550,8 +18977,8 @@ cluster_pcm_lock_resource_x_holder_status_exact( } ResourceXApplyResult -cluster_pcm_lock_resource_x_holder_image_exact( - const ResourceXAssertion *assertion, ResourceXDecodedFrame *out) +cluster_pcm_lock_resource_x_holder_image_exact(const ResourceXAssertion *assertion, + ResourceXDecodedFrame *out) { ClusterPcmResourceXHolderImage *record; ClusterPcmResourceXMasterState *state; @@ -20565,8 +18992,7 @@ cluster_pcm_lock_resource_x_holder_image_exact( memset(out, 0, sizeof(*out)); if (!resource_x_assertion_valid(assertion) || out == NULL) return RESOURCE_X_APPLY_INVALID; - if (!pcm_entry_ref_acquire(&assertion->resource, false, - &entry_ref, &acquire_result)) + if (!pcm_entry_ref_acquire(&assertion->resource, false, &entry_ref, &acquire_result)) return RESOURCE_X_APPLY_NOT_FOUND; entry = entry_ref.entry; LWLockAcquire(&entry->entry_lock.lock, LW_SHARED); @@ -20587,20 +19013,16 @@ cluster_pcm_lock_resource_x_holder_image_exact( if ((record->valid != RESOURCE_X_HOLDER_PAIR_PENDING && record->valid != RESOURCE_X_HOLDER_PAIR_PUBLISHED) || record->payload_bytes != RESOURCE_X_IMAGE_V1_BYTES - || record->kind != RESOURCE_X_WIRE_IMAGE_ENVELOPE - || record->logical_generation == 0 - || record->authority_generation == 0 - || record->resource_formation == 0 + || record->kind != RESOURCE_X_WIRE_IMAGE_ENVELOPE || record->logical_generation == 0 + || record->authority_generation == 0 || record->resource_formation == 0 || record->destination_node >= RESOURCE_X_PROTOCOL_NODE_LIMIT || record->body.owner_kind != RESOURCE_X_INTENT_OWNER_HOLDER_IMAGE || record->body.owner_index != 0 || record->body.owner_generation != record->logical_generation - || !cluster_resource_x_wire_decode( - RESOURCE_X_MSG_IMAGE_OR_GRANT, record->payload, - record->payload_bytes, out, &reject) + || !cluster_resource_x_wire_decode(RESOURCE_X_MSG_IMAGE_OR_GRANT, record->payload, + record->payload_bytes, out, &reject) || out->kind != RESOURCE_X_WIRE_IMAGE_ENVELOPE - || !resource_x_assertion_equal( - assertion, &out->common.logical_assertion) + || !resource_x_assertion_equal(assertion, &out->common.logical_assertion) || out->common.resource_formation != record->resource_formation) { memset(out, 0, sizeof(*out)); result = RESOURCE_X_APPLY_RECOVERY_BLOCKED; @@ -20618,9 +19040,9 @@ cluster_pcm_lock_resource_x_holder_image_exact( * Neither record is independently sufficient: every lineage field must * agree before a DRAIN may touch the physical N+PI carrier. */ static ResourceXApplyResult -pcm_resource_x_holder_pair_decode_locked( - const ClusterPcmResourceXMasterState *state, - ResourceXDecodedFrame *status_out, ResourceXDecodedFrame *image_out) +pcm_resource_x_holder_pair_decode_locked(const ClusterPcmResourceXMasterState *state, + ResourceXDecodedFrame *status_out, + ResourceXDecodedFrame *image_out) { const ClusterPcmResourceXHolderStatus *status_record; const ClusterPcmResourceXHolderImage *image_record; @@ -20648,22 +19070,16 @@ pcm_resource_x_holder_pair_decode_locked( || status_record->resource_formation != image_record->resource_formation || status_record->destination_node >= RESOURCE_X_PROTOCOL_NODE_LIMIT || image_record->destination_node >= RESOURCE_X_PROTOCOL_NODE_LIMIT - || status_record->body.owner_kind - != RESOURCE_X_INTENT_OWNER_HOLDER_STATUS - || image_record->body.owner_kind - != RESOURCE_X_INTENT_OWNER_HOLDER_IMAGE - || status_record->body.owner_index != 0 - || image_record->body.owner_index != 0 - || status_record->body.owner_generation - != status_record->logical_generation - || image_record->body.owner_generation - != image_record->logical_generation + || status_record->body.owner_kind != RESOURCE_X_INTENT_OWNER_HOLDER_STATUS + || image_record->body.owner_kind != RESOURCE_X_INTENT_OWNER_HOLDER_IMAGE + || status_record->body.owner_index != 0 || image_record->body.owner_index != 0 + || status_record->body.owner_generation != status_record->logical_generation + || image_record->body.owner_generation != image_record->logical_generation || status_record->body.owner_node != image_record->body.owner_node || !resource_x_assertion_equal(&status_record->body.assertion, - &image_record->body.assertion) - || !cluster_resource_x_wire_decode( - RESOURCE_X_MSG_BLOCKED_TO_N, status_record->payload, - status_record->payload_bytes, status_out, &reject)) + &image_record->body.assertion) + || !cluster_resource_x_wire_decode(RESOURCE_X_MSG_BLOCKED_TO_N, status_record->payload, + status_record->payload_bytes, status_out, &reject)) return RESOURCE_X_APPLY_RECOVERY_BLOCKED; reject = RESOURCE_X_WIRE_REJECT_NONE; if (!cluster_resource_x_wire_decode(RESOURCE_X_MSG_IMAGE_OR_GRANT, image_record->payload, @@ -20736,31 +19152,27 @@ pcm_resource_x_holder_pair_decode_locked( } static ResourceXApplyResult -pcm_resource_x_holder_pair_drain_domain_locked( - const BufferTag *tag, const ClusterPcmResourceXMasterState *state, - int32 authenticated_master_node, uint64 authenticated_master_session, - const ResourceXAssertion *assertion, uint64 assertion_sequence) +pcm_resource_x_holder_pair_drain_domain_locked(const BufferTag *tag, + const ClusterPcmResourceXMasterState *state, + int32 authenticated_master_node, + uint64 authenticated_master_session, + const ResourceXAssertion *assertion, + uint64 assertion_sequence) { uint64 gate_formation; Assert(tag != NULL); Assert(state != NULL); Assert(assertion != NULL); - gate_formation - = pg_atomic_read_u64(&ClusterPcm->resource_x_gate_formation); - if (pg_atomic_read_u32(&ClusterPcm->resource_x_gate_phase) - != RESOURCE_X_GATE_OPEN + gate_formation = pg_atomic_read_u64(&ClusterPcm->resource_x_gate_formation); + if (pg_atomic_read_u32(&ClusterPcm->resource_x_gate_phase) != RESOURCE_X_GATE_OPEN || cluster_gcs_lookup_master(*tag) != authenticated_master_node) return RESOURCE_X_APPLY_RECOVERY_BLOCKED; - if (state->holder_pair_drained_sequences[assertion->requester_node] - >= assertion_sequence - && state->holder_pair_drained_sequences[assertion->requester_node] - != 0) { + if (state->holder_pair_drained_sequences[assertion->requester_node] >= assertion_sequence + && state->holder_pair_drained_sequences[assertion->requester_node] != 0) { if (state->holder_pair_drained_resource_formation != gate_formation - || state->holder_pair_drained_master_session - != authenticated_master_session - || state->holder_pair_drained_master_node - != authenticated_master_node + || state->holder_pair_drained_master_session != authenticated_master_session + || state->holder_pair_drained_master_node != authenticated_master_node || state->holder_pair_drained_reserved != 0) return RESOURCE_X_APPLY_STALE; return RESOURCE_X_APPLY_DUPLICATE; @@ -20769,9 +19181,10 @@ pcm_resource_x_holder_pair_drain_domain_locked( } ResourceXApplyResult -cluster_pcm_lock_resource_x_holder_pair_supersedes_exact( - const ResourceXAssertion *assertion, uint64 assertion_sequence, - int32 authenticated_master_node, uint64 authenticated_master_session) +cluster_pcm_lock_resource_x_holder_pair_supersedes_exact(const ResourceXAssertion *assertion, + uint64 assertion_sequence, + int32 authenticated_master_node, + uint64 authenticated_master_session) { ClusterPcmResourceXMasterState *state; PcmEntryRef entry_ref; @@ -20783,13 +19196,11 @@ cluster_pcm_lock_resource_x_holder_pair_supersedes_exact( uint64 gate_formation; if (!resource_x_assertion_valid(assertion) || assertion_sequence == 0 - || assertion_sequence == UINT64_MAX - || authenticated_master_node < 0 + || assertion_sequence == UINT64_MAX || authenticated_master_node < 0 || authenticated_master_node >= RESOURCE_X_PROTOCOL_NODE_LIMIT || authenticated_master_session == 0 || ClusterPcm == NULL) return RESOURCE_X_APPLY_INVALID; - if (!pcm_entry_ref_acquire(&assertion->resource, false, - &entry_ref, &acquire_result)) + if (!pcm_entry_ref_acquire(&assertion->resource, false, &entry_ref, &acquire_result)) return RESOURCE_X_APPLY_NOT_FOUND; entry = entry_ref.entry; LWLockAcquire(&entry->entry_lock.lock, LW_SHARED); @@ -20801,23 +19212,17 @@ cluster_pcm_lock_resource_x_holder_pair_supersedes_exact( result = pcm_resource_x_holder_pair_decode_locked(state, &status, &image); if (result != RESOURCE_X_APPLY_APPLIED) goto pair_supersedes_done; - gate_formation - = pg_atomic_read_u64(&ClusterPcm->resource_x_gate_formation); - if (pg_atomic_read_u32(&ClusterPcm->resource_x_gate_phase) - != RESOURCE_X_GATE_OPEN - || cluster_gcs_lookup_master(entry->tag) - != authenticated_master_node) { + gate_formation = pg_atomic_read_u64(&ClusterPcm->resource_x_gate_formation); + if (pg_atomic_read_u32(&ClusterPcm->resource_x_gate_phase) != RESOURCE_X_GATE_OPEN + || cluster_gcs_lookup_master(entry->tag) != authenticated_master_node) { result = RESOURCE_X_APPLY_RECOVERY_BLOCKED; goto pair_supersedes_done; } - if (!resource_x_assertion_equal( - assertion, &status.common.logical_assertion) + if (!resource_x_assertion_equal(assertion, &status.common.logical_assertion) || status.common.assertion_sequence <= assertion_sequence || status.common.resource_formation != gate_formation - || status.common.master_session_incarnation - != authenticated_master_session - || state->holder_status.destination_node - != (uint32)authenticated_master_node) + || status.common.master_session_incarnation != authenticated_master_session + || state->holder_status.destination_node != (uint32)authenticated_master_node) result = RESOURCE_X_APPLY_STALE; else result = RESOURCE_X_APPLY_APPLIED; @@ -20829,10 +19234,11 @@ cluster_pcm_lock_resource_x_holder_pair_supersedes_exact( } ResourceXApplyResult -cluster_pcm_lock_resource_x_holder_pair_drain_prepare_exact( - const ResourceXAssertion *assertion, uint64 assertion_sequence, - int32 authenticated_master_node, uint64 authenticated_master_session, - uint64 *source_generation_out) +cluster_pcm_lock_resource_x_holder_pair_drain_prepare_exact(const ResourceXAssertion *assertion, + uint64 assertion_sequence, + int32 authenticated_master_node, + uint64 authenticated_master_session, + uint64 *source_generation_out) { ClusterPcmResourceXMasterState *state; PcmEntryRef entry_ref; @@ -20846,14 +19252,11 @@ cluster_pcm_lock_resource_x_holder_pair_drain_prepare_exact( if (source_generation_out != NULL) *source_generation_out = 0; if (!resource_x_assertion_valid(assertion) || assertion_sequence == 0 - || assertion_sequence == UINT64_MAX - || authenticated_master_node < 0 + || assertion_sequence == UINT64_MAX || authenticated_master_node < 0 || authenticated_master_node >= RESOURCE_X_PROTOCOL_NODE_LIMIT - || authenticated_master_session == 0 || source_generation_out == NULL - || ClusterPcm == NULL) + || authenticated_master_session == 0 || source_generation_out == NULL || ClusterPcm == NULL) return RESOURCE_X_APPLY_INVALID; - if (!pcm_entry_ref_acquire(&assertion->resource, false, - &entry_ref, &acquire_result)) + if (!pcm_entry_ref_acquire(&assertion->resource, false, &entry_ref, &acquire_result)) return RESOURCE_X_APPLY_NOT_FOUND; entry = entry_ref.entry; LWLockAcquire(&entry->entry_lock.lock, LW_SHARED); @@ -20863,46 +19266,37 @@ cluster_pcm_lock_resource_x_holder_pair_drain_prepare_exact( goto pair_prepare_done; } result = pcm_resource_x_holder_pair_drain_domain_locked( - &entry->tag, state, authenticated_master_node, - authenticated_master_session, assertion, assertion_sequence); - if (result == RESOURCE_X_APPLY_DUPLICATE - || result == RESOURCE_X_APPLY_RECOVERY_BLOCKED + &entry->tag, state, authenticated_master_node, authenticated_master_session, assertion, + assertion_sequence); + if (result == RESOURCE_X_APPLY_DUPLICATE || result == RESOURCE_X_APPLY_RECOVERY_BLOCKED || result == RESOURCE_X_APPLY_STALE) goto pair_prepare_done; result = pcm_resource_x_holder_pair_decode_locked(state, &status, &image); if (result != RESOURCE_X_APPLY_APPLIED) goto pair_prepare_done; - if (!resource_x_assertion_equal( - assertion, &status.common.logical_assertion) + if (!resource_x_assertion_equal(assertion, &status.common.logical_assertion) || status.common.assertion_sequence != assertion_sequence) { result = RESOURCE_X_APPLY_NOT_FOUND; goto pair_prepare_done; } - gate_formation - = pg_atomic_read_u64(&ClusterPcm->resource_x_gate_formation); + gate_formation = pg_atomic_read_u64(&ClusterPcm->resource_x_gate_formation); if (status.common.resource_formation != gate_formation - || status.common.master_session_incarnation - != authenticated_master_session - || state->holder_status.destination_node - != (uint32)authenticated_master_node) { + || status.common.master_session_incarnation != authenticated_master_session + || state->holder_status.destination_node != (uint32)authenticated_master_node) { result = RESOURCE_X_APPLY_STALE; goto pair_prepare_done; } if (state->holder_status.valid != RESOURCE_X_HOLDER_PAIR_PUBLISHED - || state->holder_image.valid - != RESOURCE_X_HOLDER_PAIR_PUBLISHED) { + || state->holder_image.valid != RESOURCE_X_HOLDER_PAIR_PUBLISHED) { result = RESOURCE_X_APPLY_BAD_STATE; goto pair_prepare_done; } - if (state->holder_status_intent.slot.state - != RESOURCE_X_INTENT_SLOT_EMPTY - || state->holder_image_intent.state - != RESOURCE_X_INTENT_SLOT_EMPTY) { + if (state->holder_status_intent.slot.state != RESOURCE_X_INTENT_SLOT_EMPTY + || state->holder_image_intent.state != RESOURCE_X_INTENT_SLOT_EMPTY) { result = RESOURCE_X_APPLY_BAD_STATE; goto pair_prepare_done; } - *source_generation_out - = image.body.image_envelope.source_carrier_generation - 1; + *source_generation_out = image.body.image_envelope.source_carrier_generation - 1; result = RESOURCE_X_APPLY_APPLIED; pair_prepare_done: @@ -20912,10 +19306,11 @@ cluster_pcm_lock_resource_x_holder_pair_drain_prepare_exact( } ResourceXApplyResult -cluster_pcm_lock_resource_x_holder_pair_drain_commit_exact( - const ResourceXAssertion *assertion, uint64 assertion_sequence, - int32 authenticated_master_node, uint64 authenticated_master_session, - uint64 source_generation) +cluster_pcm_lock_resource_x_holder_pair_drain_commit_exact(const ResourceXAssertion *assertion, + uint64 assertion_sequence, + int32 authenticated_master_node, + uint64 authenticated_master_session, + uint64 source_generation) { ClusterPcmResourceXMasterState *state; PcmEntryRef entry_ref; @@ -20927,14 +19322,12 @@ cluster_pcm_lock_resource_x_holder_pair_drain_commit_exact( uint64 gate_formation; if (!resource_x_assertion_valid(assertion) || assertion_sequence == 0 - || assertion_sequence == UINT64_MAX - || authenticated_master_node < 0 + || assertion_sequence == UINT64_MAX || authenticated_master_node < 0 || authenticated_master_node >= RESOURCE_X_PROTOCOL_NODE_LIMIT || authenticated_master_session == 0 || source_generation == UINT64_MAX || ClusterPcm == NULL) return RESOURCE_X_APPLY_INVALID; - if (!pcm_entry_ref_acquire(&assertion->resource, false, - &entry_ref, &acquire_result)) + if (!pcm_entry_ref_acquire(&assertion->resource, false, &entry_ref, &acquire_result)) return RESOURCE_X_APPLY_NOT_FOUND; entry = entry_ref.entry; pcm_entry_lock_exclusive(entry); @@ -20944,48 +19337,37 @@ cluster_pcm_lock_resource_x_holder_pair_drain_commit_exact( goto pair_commit_done; } result = pcm_resource_x_holder_pair_drain_domain_locked( - &entry->tag, state, authenticated_master_node, - authenticated_master_session, assertion, assertion_sequence); - if (result == RESOURCE_X_APPLY_DUPLICATE - || result == RESOURCE_X_APPLY_RECOVERY_BLOCKED + &entry->tag, state, authenticated_master_node, authenticated_master_session, assertion, + assertion_sequence); + if (result == RESOURCE_X_APPLY_DUPLICATE || result == RESOURCE_X_APPLY_RECOVERY_BLOCKED || result == RESOURCE_X_APPLY_STALE) goto pair_commit_done; result = pcm_resource_x_holder_pair_decode_locked(state, &status, &image); if (result != RESOURCE_X_APPLY_APPLIED) goto pair_commit_done; - gate_formation - = pg_atomic_read_u64(&ClusterPcm->resource_x_gate_formation); - if (!resource_x_assertion_equal( - assertion, &status.common.logical_assertion) + gate_formation = pg_atomic_read_u64(&ClusterPcm->resource_x_gate_formation); + if (!resource_x_assertion_equal(assertion, &status.common.logical_assertion) || status.common.assertion_sequence != assertion_sequence || status.common.resource_formation != gate_formation - || status.common.master_session_incarnation - != authenticated_master_session - || state->holder_status.destination_node - != (uint32)authenticated_master_node - || image.body.image_envelope.source_carrier_generation - != source_generation + 1) { + || status.common.master_session_incarnation != authenticated_master_session + || state->holder_status.destination_node != (uint32)authenticated_master_node + || image.body.image_envelope.source_carrier_generation != source_generation + 1) { result = RESOURCE_X_APPLY_STALE; goto pair_commit_done; } if (state->holder_status.valid != RESOURCE_X_HOLDER_PAIR_PUBLISHED - || state->holder_image.valid - != RESOURCE_X_HOLDER_PAIR_PUBLISHED) { + || state->holder_image.valid != RESOURCE_X_HOLDER_PAIR_PUBLISHED) { result = RESOURCE_X_APPLY_BAD_STATE; goto pair_commit_done; } - if (state->holder_status_intent.slot.state - != RESOURCE_X_INTENT_SLOT_EMPTY - || state->holder_image_intent.state - != RESOURCE_X_INTENT_SLOT_EMPTY) { + if (state->holder_status_intent.slot.state != RESOURCE_X_INTENT_SLOT_EMPTY + || state->holder_image_intent.state != RESOURCE_X_INTENT_SLOT_EMPTY) { result = RESOURCE_X_APPLY_BAD_STATE; goto pair_commit_done; } - state->holder_pair_drained_sequences[assertion->requester_node] - = assertion_sequence; + state->holder_pair_drained_sequences[assertion->requester_node] = assertion_sequence; state->holder_pair_drained_resource_formation = gate_formation; - state->holder_pair_drained_master_session - = authenticated_master_session; + state->holder_pair_drained_master_session = authenticated_master_session; state->holder_pair_drained_master_node = authenticated_master_node; state->holder_pair_drained_reserved = 0; result = RESOURCE_X_APPLY_APPLIED; @@ -20997,10 +19379,9 @@ cluster_pcm_lock_resource_x_holder_pair_drain_commit_exact( } static bool -pcm_resource_x_source_settlement_matches_pair( - const ResourceXDecodedFrame *settlement, - const ResourceXDecodedFrame *status, - const ResourceXDecodedFrame *image) +pcm_resource_x_source_settlement_matches_pair(const ResourceXDecodedFrame *settlement, + const ResourceXDecodedFrame *status, + const ResourceXDecodedFrame *image) { const ResourceXDecodedBlockedToN *left; const ResourceXDecodedBlockedToN *right; @@ -21037,24 +19418,18 @@ pcm_resource_x_source_settlement_matches_pair( return false; left = &settlement->body.blocked_to_n; right = &status->body.blocked_to_n; - return left->source_carrier_generation - == right->source_carrier_generation - && left->requester_target_generation - == right->requester_target_generation - && left->page_scn_lsn == right->page_scn_lsn - && left->dependency_count == right->dependency_count - && left->source_proof_crc32c == right->source_proof_crc32c - && left->page_checksum == right->page_checksum - && left->source_disposition == right->source_disposition - && left->proof_kind == right->proof_kind - && left->proof_flags == right->proof_flags - && left->holder_connection_generation - == right->holder_connection_generation - && left->acting_formation == right->acting_formation - && memcmp(left->source_fence, right->source_fence, - sizeof(left->source_fence)) == 0 - && memcmp(left->dependencies, right->dependencies, - sizeof(left->dependencies)) == 0; + return left->source_carrier_generation == right->source_carrier_generation + && left->requester_target_generation == right->requester_target_generation + && left->page_scn_lsn == right->page_scn_lsn + && left->dependency_count == right->dependency_count + && left->source_proof_crc32c == right->source_proof_crc32c + && left->page_checksum == right->page_checksum + && left->source_disposition == right->source_disposition + && left->proof_kind == right->proof_kind && left->proof_flags == right->proof_flags + && left->holder_connection_generation == right->holder_connection_generation + && left->acting_formation == right->acting_formation + && memcmp(left->source_fence, right->source_fence, sizeof(left->source_fence)) == 0 + && memcmp(left->dependencies, right->dependencies, sizeof(left->dependencies)) == 0; } static uint64 @@ -21070,8 +19445,7 @@ pcm_resource_x_source_fence_get_u64(const uint8 *bytes) } static bool -pcm_resource_x_source_settlement_plan_valid( - const ResourceXSourceSettlementPlan *plan) +pcm_resource_x_source_settlement_plan_valid(const ResourceXSourceSettlementPlan *plan) { ResourceXAcquisitionRef empty_ref; @@ -21101,24 +19475,20 @@ pcm_resource_x_source_settlement_plan_valid( return false; memset(&empty_ref, 0, sizeof(empty_ref)); if (plan->cover_action == RESOURCE_X_SETTLEMENT_COVER_NO_COVER) - return plan->terminal_cached_generation == 0 - && plan->terminal_authority_generation == 0 - && plan->terminal_r4_record_generation == 0 - && memcmp(&plan->terminal_ref, &empty_ref, - sizeof(empty_ref)) == 0; - return plan->source_mode == (uint8)PCM_STATE_X - && pcm_resource_x_ref_valid(&plan->terminal_ref) - && plan->terminal_cached_generation == plan->source_generation - && plan->terminal_authority_generation != 0 - && plan->terminal_authority_generation != UINT64_MAX - && plan->terminal_r4_record_generation != 0 - && plan->terminal_r4_record_generation != UINT64_MAX; + return plan->terminal_cached_generation == 0 && plan->terminal_authority_generation == 0 + && plan->terminal_r4_record_generation == 0 + && memcmp(&plan->terminal_ref, &empty_ref, sizeof(empty_ref)) == 0; + return plan->source_mode == (uint8)PCM_STATE_X && pcm_resource_x_ref_valid(&plan->terminal_ref) + && plan->terminal_cached_generation == plan->source_generation + && plan->terminal_authority_generation != 0 + && plan->terminal_authority_generation != UINT64_MAX + && plan->terminal_r4_record_generation != 0 + && plan->terminal_r4_record_generation != UINT64_MAX; } static bool -pcm_resource_x_source_settlement_plan_equal( - const ResourceXSourceSettlementPlan *left, - const ResourceXSourceSettlementPlan *right) +pcm_resource_x_source_settlement_plan_equal(const ResourceXSourceSettlementPlan *left, + const ResourceXSourceSettlementPlan *right) { if (!pcm_resource_x_source_settlement_plan_valid(left) || !pcm_resource_x_source_settlement_plan_valid(right) @@ -21139,20 +19509,15 @@ pcm_resource_x_source_settlement_plan_equal( return false; if (left->cover_action == RESOURCE_X_SETTLEMENT_COVER_NO_COVER) return true; - return pcm_resource_x_acquisition_ref_equal( - &left->terminal_ref, &right->terminal_ref) - && left->terminal_cached_generation - == right->terminal_cached_generation - && left->terminal_authority_generation - == right->terminal_authority_generation - && left->terminal_r4_record_generation - == right->terminal_r4_record_generation; + return pcm_resource_x_acquisition_ref_equal(&left->terminal_ref, &right->terminal_ref) + && left->terminal_cached_generation == right->terminal_cached_generation + && left->terminal_authority_generation == right->terminal_authority_generation + && left->terminal_r4_record_generation == right->terminal_r4_record_generation; } static void pcm_resource_x_source_settlement_observe_round_locked( - struct GrdEntry *entry, - ResourceXSourceSettlementCommitObservation *observation) + struct GrdEntry *entry, ResourceXSourceSettlementCommitObservation *observation) { ClusterPcmResourceXBootstrapRound *round; ClusterPcmResourceXLocalOwner *owner; @@ -21160,30 +19525,27 @@ pcm_resource_x_source_settlement_observe_round_locked( Assert(entry != NULL); Assert(observation != NULL); Assert(LWLockHeldByMeInMode(&entry->entry_lock.lock, LW_SHARED) - || LWLockHeldByMeInMode(&entry->entry_lock.lock, LW_EXCLUSIVE)); + || LWLockHeldByMeInMode(&entry->entry_lock.lock, LW_EXCLUSIVE)); round = &entry->resource_x_bootstrap_round; owner = &entry->resource_x_local_owner; observation->current_round_phase = round->phase; observation->current_owner_state = owner->state; observation->current_master_node = round->current_master_node; - observation->current_master_session - = round->master_session_incarnation; - observation->current_terminal_authority_generation - = round->terminal_authority_generation; - observation->current_cached_ownership_generation - = round->cached_ownership_generation; + observation->current_master_session = round->master_session_incarnation; + observation->current_terminal_authority_generation = round->terminal_authority_generation; + observation->current_cached_ownership_generation = round->cached_ownership_generation; observation->current_terminal_cover_present = round->phase == RESOURCE_X_BOOTSTRAP_ROUND_TERMINAL_X_CACHED; } static ResourceXApplyResult -pcm_resource_x_source_settlement_plan_build_locked( - struct GrdEntry *entry, ClusterPcmResourceXMasterState *state, - const ResourceXDecodedFrame *settlement, - int32 authenticated_master_node, - const ResourceXDecodedFrame *status, - const ResourceXDecodedFrame *image, - ResourceXSourceSettlementPlan *plan_out) +pcm_resource_x_source_settlement_plan_build_locked(struct GrdEntry *entry, + ClusterPcmResourceXMasterState *state, + const ResourceXDecodedFrame *settlement, + int32 authenticated_master_node, + const ResourceXDecodedFrame *status, + const ResourceXDecodedFrame *image, + ResourceXSourceSettlementPlan *plan_out) { ClusterPcmResourceXBootstrapRound *round; ClusterPcmResourceXLocalOwner *owner; @@ -21199,43 +19561,34 @@ pcm_resource_x_source_settlement_plan_build_locked( Assert(image != NULL); Assert(plan_out != NULL); Assert(LWLockHeldByMeInMode(&entry->entry_lock.lock, LW_SHARED) - || LWLockHeldByMeInMode(&entry->entry_lock.lock, LW_EXCLUSIVE)); + || LWLockHeldByMeInMode(&entry->entry_lock.lock, LW_EXCLUSIVE)); memset(plan_out, 0, sizeof(*plan_out)); memset(&candidate, 0, sizeof(candidate)); - if (!pcm_resource_x_source_settlement_matches_pair( - settlement, status, image) - || state->holder_status.destination_node - != (uint32)authenticated_master_node) + if (!pcm_resource_x_source_settlement_matches_pair(settlement, status, image) + || state->holder_status.destination_node != (uint32)authenticated_master_node) return RESOURCE_X_APPLY_STALE; if (state->holder_status.valid != RESOURCE_X_HOLDER_PAIR_PUBLISHED || state->holder_image.valid != RESOURCE_X_HOLDER_PAIR_PUBLISHED - || state->holder_status_intent.slot.state - != RESOURCE_X_INTENT_SLOT_EMPTY - || state->holder_image_intent.state - != RESOURCE_X_INTENT_SLOT_EMPTY) + || state->holder_status_intent.slot.state != RESOURCE_X_INTENT_SLOT_EMPTY + || state->holder_image_intent.state != RESOURCE_X_INTENT_SLOT_EMPTY) return RESOURCE_X_APPLY_BAD_STATE; - if (!cluster_pcm_lock_resource_x_gate_open_exact( - settlement->common.resource_formation)) + if (!cluster_pcm_lock_resource_x_gate_open_exact(settlement->common.resource_formation)) return RESOURCE_X_APPLY_STALE; source_mode = status->common.observed_mode; - source_generation = pcm_resource_x_source_fence_get_u64( - image->body.image_envelope.source_fence + 20); - carrier_generation - = image->body.image_envelope.source_carrier_generation; - if ((source_mode != (uint8)PCM_STATE_X - && source_mode != (uint8)PCM_STATE_S) + source_generation + = pcm_resource_x_source_fence_get_u64(image->body.image_envelope.source_fence + 20); + carrier_generation = image->body.image_envelope.source_carrier_generation; + if ((source_mode != (uint8)PCM_STATE_X && source_mode != (uint8)PCM_STATE_S) || image->common.observed_mode != source_mode || status->body.blocked_to_n.source_fence[28] != source_mode || image->body.image_envelope.source_fence[28] != source_mode || status->body.blocked_to_n.source_fence[29] != 1 || image->body.image_envelope.source_fence[29] != 1) return RESOURCE_X_APPLY_INVALID; - if (source_generation == 0 || source_generation == UINT64_MAX - || carrier_generation == 0 || carrier_generation == UINT64_MAX - || carrier_generation != source_generation + 1) + if (source_generation == 0 || source_generation == UINT64_MAX || carrier_generation == 0 + || carrier_generation == UINT64_MAX || carrier_generation != source_generation + 1) return RESOURCE_X_APPLY_INVALID; - if (status->common.semantic_crc32c == 0 - || image->common.semantic_crc32c == 0) + if (status->common.semantic_crc32c == 0 || image->common.semantic_crc32c == 0) return RESOURCE_X_APPLY_INVALID; owner = &entry->resource_x_local_owner; if (!pcm_resource_x_local_owner_valid_locked(owner)) @@ -21244,18 +19597,12 @@ pcm_resource_x_source_settlement_plan_build_locked( return RESOURCE_X_APPLY_BAD_STATE; candidate.assertion = settlement->common.logical_assertion; - candidate.resource_formation - = settlement->common.resource_formation; - candidate.master_session_incarnation - = settlement->common.master_session_incarnation; - candidate.assertion_sequence - = settlement->common.assertion_sequence; - candidate.pair_base_authority_generation - = status->common.base_authority_generation; - candidate.pair_image_authority_generation - = image->common.authority_generation; - candidate.settlement_authority_generation - = settlement->common.authority_generation; + candidate.resource_formation = settlement->common.resource_formation; + candidate.master_session_incarnation = settlement->common.master_session_incarnation; + candidate.assertion_sequence = settlement->common.assertion_sequence; + candidate.pair_base_authority_generation = status->common.base_authority_generation; + candidate.pair_image_authority_generation = image->common.authority_generation; + candidate.settlement_authority_generation = settlement->common.authority_generation; candidate.authority_with_image = image->common.flags == RESOURCE_X_COMMON_FLAG_AUTHORITY_WITH_IMAGE; candidate.source_generation = source_generation; @@ -21267,37 +19614,26 @@ pcm_resource_x_source_settlement_plan_build_locked( round = &entry->resource_x_bootstrap_round; if (round->phase == RESOURCE_X_BOOTSTRAP_ROUND_EMPTY) candidate.cover_action = RESOURCE_X_SETTLEMENT_COVER_NO_COVER; - else if (round->phase - == RESOURCE_X_BOOTSTRAP_ROUND_TERMINAL_X_CACHED) { + else if (round->phase == RESOURCE_X_BOOTSTRAP_ROUND_TERMINAL_X_CACHED) { if (source_mode == (uint8)PCM_STATE_S) return RESOURCE_X_APPLY_RECOVERY_BLOCKED; if (settlement->common.action_node != cluster_node_id - || round->terminal_ref.assertion.requester_node - != cluster_node_id + || round->terminal_ref.assertion.requester_node != cluster_node_id || round->current_master_node != authenticated_master_node - || round->resource_formation - != settlement->common.resource_formation - || round->master_session_incarnation - != settlement->common.master_session_incarnation - || round->terminal_authority_generation - != settlement->common.base_authority_generation + || round->resource_formation != settlement->common.resource_formation + || round->master_session_incarnation != settlement->common.master_session_incarnation + || round->terminal_authority_generation != settlement->common.base_authority_generation || round->cached_ownership_generation != source_generation || !pcm_resource_x_bootstrap_round_terminal_cover_exact_locked( - entry, round, &round->terminal_ref, - round->master_session_incarnation, + entry, round, &round->terminal_ref, round->master_session_incarnation, round->r4_record_generation, source_generation)) return RESOURCE_X_APPLY_STALE; candidate.terminal_ref = round->terminal_ref; - candidate.terminal_cached_generation - = round->cached_ownership_generation; - candidate.terminal_authority_generation - = round->terminal_authority_generation; - candidate.terminal_r4_record_generation - = round->r4_record_generation; - candidate.cover_action - = RESOURCE_X_SETTLEMENT_COVER_CLOSE_EXACT_X; - } - else if (round->phase == RESOURCE_X_BOOTSTRAP_ROUND_FAILED_CLOSED) + candidate.terminal_cached_generation = round->cached_ownership_generation; + candidate.terminal_authority_generation = round->terminal_authority_generation; + candidate.terminal_r4_record_generation = round->r4_record_generation; + candidate.cover_action = RESOURCE_X_SETTLEMENT_COVER_CLOSE_EXACT_X; + } else if (round->phase == RESOURCE_X_BOOTSTRAP_ROUND_FAILED_CLOSED) return RESOURCE_X_APPLY_RECOVERY_BLOCKED; else return RESOURCE_X_APPLY_BAD_STATE; @@ -21330,69 +19666,52 @@ pcm_resource_x_source_settlement_prepare_internal( memset(plan_out, 0, sizeof(*plan_out)); if (observation_out != NULL) memset(observation_out, 0, sizeof(*observation_out)); - if (settlement == NULL - || !resource_x_assertion_valid( - &settlement->common.logical_assertion) + if (settlement == NULL || !resource_x_assertion_valid(&settlement->common.logical_assertion) || authenticated_master_node < 0 - || authenticated_master_node >= RESOURCE_X_PROTOCOL_NODE_LIMIT - || plan_out == NULL || ClusterPcm == NULL) + || authenticated_master_node >= RESOURCE_X_PROTOCOL_NODE_LIMIT || plan_out == NULL + || ClusterPcm == NULL) return RESOURCE_X_APPLY_INVALID; - if (!pcm_entry_ref_acquire(&settlement->common.logical_assertion.resource, - false, &entry_ref, &acquire_result)) { + if (!pcm_entry_ref_acquire(&settlement->common.logical_assertion.resource, false, &entry_ref, + &acquire_result)) { if (observation_out != NULL) - observation_out->commit_stage - = RESOURCE_X_SOURCE_SETTLEMENT_COMMIT_STAGE_ENTRY_LOOKUP; + observation_out->commit_stage = RESOURCE_X_SOURCE_SETTLEMENT_COMMIT_STAGE_ENTRY_LOOKUP; return RESOURCE_X_APPLY_NOT_FOUND; } entry = entry_ref.entry; LWLockAcquire(&entry->entry_lock.lock, LW_SHARED); round = &entry->resource_x_bootstrap_round; owner = &entry->resource_x_local_owner; - gate_formation - = pg_atomic_read_u64(&ClusterPcm->resource_x_gate_formation); + gate_formation = pg_atomic_read_u64(&ClusterPcm->resource_x_gate_formation); if (observation_out != NULL) { - pcm_resource_x_source_settlement_observe_round_locked( - entry, observation_out); + pcm_resource_x_source_settlement_observe_round_locked(entry, observation_out); observation_out->current_resource_formation = gate_formation; } state = pcm_resource_x_master_state_for_entry(entry); if (state == NULL) { if (observation_out != NULL) - observation_out->commit_stage - = RESOURCE_X_SOURCE_SETTLEMENT_COMMIT_STAGE_MASTER_STATE; + observation_out->commit_stage = RESOURCE_X_SOURCE_SETTLEMENT_COMMIT_STAGE_MASTER_STATE; result = RESOURCE_X_APPLY_RECOVERY_BLOCKED; goto source_prepare_done; } if (observation_out != NULL) { - observation_out->current_holder_status_valid - = state->holder_status.valid; - observation_out->current_holder_image_valid - = state->holder_image.valid; - observation_out->current_status_intent_state - = state->holder_status_intent.slot.state; - observation_out->current_image_intent_state - = state->holder_image_intent.state; - observation_out->current_pair_destination_node - = state->holder_status.destination_node; + observation_out->current_holder_status_valid = state->holder_status.valid; + observation_out->current_holder_image_valid = state->holder_image.valid; + observation_out->current_status_intent_state = state->holder_status_intent.slot.state; + observation_out->current_image_intent_state = state->holder_image_intent.state; + observation_out->current_pair_destination_node = state->holder_status.destination_node; } domain = pcm_resource_x_holder_pair_drain_domain_locked( &entry->tag, state, authenticated_master_node, - settlement->common.master_session_incarnation, - &settlement->common.logical_assertion, + settlement->common.master_session_incarnation, &settlement->common.logical_assertion, settlement->common.assertion_sequence); - if (domain == RESOURCE_X_APPLY_RECOVERY_BLOCKED - || domain == RESOURCE_X_APPLY_STALE) { + if (domain == RESOURCE_X_APPLY_RECOVERY_BLOCKED || domain == RESOURCE_X_APPLY_STALE) { if (observation_out != NULL) { - observation_out->commit_stage - = RESOURCE_X_SOURCE_SETTLEMENT_COMMIT_STAGE_DRAIN_DOMAIN; - if (pg_atomic_read_u32(&ClusterPcm->resource_x_gate_phase) - != RESOURCE_X_GATE_OPEN - || gate_formation - != settlement->common.resource_formation) + observation_out->commit_stage = RESOURCE_X_SOURCE_SETTLEMENT_COMMIT_STAGE_DRAIN_DOMAIN; + if (pg_atomic_read_u32(&ClusterPcm->resource_x_gate_phase) != RESOURCE_X_GATE_OPEN + || gate_formation != settlement->common.resource_formation) observation_out->mismatch_mask |= RESOURCE_X_SOURCE_SETTLEMENT_MISMATCH_GATE_FORMATION; - if (cluster_gcs_lookup_master(entry->tag) - != authenticated_master_node) + if (cluster_gcs_lookup_master(entry->tag) != authenticated_master_node) observation_out->mismatch_mask |= RESOURCE_X_SOURCE_SETTLEMENT_MISMATCH_TERMINAL_MASTER; } @@ -21402,44 +19721,35 @@ pcm_resource_x_source_settlement_prepare_internal( result = pcm_resource_x_holder_pair_decode_locked(state, &status, &image); if (result != RESOURCE_X_APPLY_APPLIED) { if (observation_out != NULL) { - observation_out->commit_stage - = RESOURCE_X_SOURCE_SETTLEMENT_COMMIT_STAGE_PAIR_DECODE; - observation_out->mismatch_mask - |= RESOURCE_X_SOURCE_SETTLEMENT_MISMATCH_PAIR_BYTES; + observation_out->commit_stage = RESOURCE_X_SOURCE_SETTLEMENT_COMMIT_STAGE_PAIR_DECODE; + observation_out->mismatch_mask |= RESOURCE_X_SOURCE_SETTLEMENT_MISMATCH_PAIR_BYTES; } goto source_prepare_done; } if (observation_out != NULL) { - observation_out->current_pair_resource_formation - = image.common.resource_formation; - observation_out->current_pair_master_session - = image.common.master_session_incarnation; - observation_out->current_pair_assertion_sequence - = image.common.assertion_sequence; + observation_out->current_pair_resource_formation = image.common.resource_formation; + observation_out->current_pair_master_session = image.common.master_session_incarnation; + observation_out->current_pair_assertion_sequence = image.common.assertion_sequence; observation_out->current_pair_source_generation - = pcm_resource_x_source_fence_get_u64( - image.body.image_envelope.source_fence + 20); + = pcm_resource_x_source_fence_get_u64(image.body.image_envelope.source_fence + 20); observation_out->current_pair_carrier_generation = image.body.image_envelope.source_carrier_generation; - observation_out->current_pair_observed_mode - = image.common.observed_mode; + observation_out->current_pair_observed_mode = image.common.observed_mode; } if (domain == RESOURCE_X_APPLY_DUPLICATE) { if (observation_out != NULL) - observation_out->commit_stage - = RESOURCE_X_SOURCE_SETTLEMENT_COMMIT_STAGE_DRAIN_DOMAIN; + observation_out->commit_stage = RESOURCE_X_SOURCE_SETTLEMENT_COMMIT_STAGE_DRAIN_DOMAIN; result = RESOURCE_X_APPLY_DUPLICATE; goto source_prepare_done; } result = pcm_resource_x_source_settlement_plan_build_locked( - entry, state, settlement, authenticated_master_node, - &status, &image, plan_out); + entry, state, settlement, authenticated_master_node, &status, &image, plan_out); if (observation_out != NULL) { observation_out->current_cover_action = plan_out->cover_action; observation_out->commit_stage = round->phase == RESOURCE_X_BOOTSTRAP_ROUND_TERMINAL_X_CACHED - ? RESOURCE_X_SOURCE_SETTLEMENT_COMMIT_STAGE_TERMINAL_COVER - : RESOURCE_X_SOURCE_SETTLEMENT_COMMIT_STAGE_PAIR_STATE; + ? RESOURCE_X_SOURCE_SETTLEMENT_COMMIT_STAGE_TERMINAL_COVER + : RESOURCE_X_SOURCE_SETTLEMENT_COMMIT_STAGE_PAIR_STATE; if (result != RESOURCE_X_APPLY_APPLIED) { if (!pcm_resource_x_local_owner_valid_locked(owner)) observation_out->mismatch_mask @@ -21447,49 +19757,44 @@ pcm_resource_x_source_settlement_prepare_internal( else if (owner->state != RESOURCE_X_LOCAL_OWNER_EMPTY) observation_out->mismatch_mask |= RESOURCE_X_SOURCE_SETTLEMENT_MISMATCH_TERMINAL_OWNER_NONEMPTY; - if (round->phase - == RESOURCE_X_BOOTSTRAP_ROUND_TERMINAL_X_CACHED) { + if (round->phase == RESOURCE_X_BOOTSTRAP_ROUND_TERMINAL_X_CACHED) { if (status.common.observed_mode == (uint8)PCM_STATE_S) observation_out->mismatch_mask |= RESOURCE_X_SOURCE_SETTLEMENT_MISMATCH_TERMINAL_COVER; if (settlement->common.action_node != cluster_node_id) observation_out->mismatch_mask |= RESOURCE_X_SOURCE_SETTLEMENT_MISMATCH_TERMINAL_ACTION; - if (round->terminal_ref.assertion.requester_node - != cluster_node_id) + if (round->terminal_ref.assertion.requester_node != cluster_node_id) observation_out->mismatch_mask |= RESOURCE_X_SOURCE_SETTLEMENT_MISMATCH_TERMINAL_REQUESTER; if (round->current_master_node != authenticated_master_node) observation_out->mismatch_mask |= RESOURCE_X_SOURCE_SETTLEMENT_MISMATCH_TERMINAL_MASTER; - if (round->resource_formation - != settlement->common.resource_formation) + if (round->resource_formation != settlement->common.resource_formation) observation_out->mismatch_mask |= RESOURCE_X_SOURCE_SETTLEMENT_MISMATCH_TERMINAL_FORMATION; if (round->master_session_incarnation - != settlement->common.master_session_incarnation) + != settlement->common.master_session_incarnation) observation_out->mismatch_mask |= RESOURCE_X_SOURCE_SETTLEMENT_MISMATCH_TERMINAL_SESSION; if (round->terminal_authority_generation - != settlement->common.base_authority_generation) + != settlement->common.base_authority_generation) observation_out->mismatch_mask |= RESOURCE_X_SOURCE_SETTLEMENT_MISMATCH_TERMINAL_AUTHORITY; if (round->cached_ownership_generation - != observation_out->current_pair_source_generation) + != observation_out->current_pair_source_generation) observation_out->mismatch_mask |= RESOURCE_X_SOURCE_SETTLEMENT_MISMATCH_TERMINAL_OWNERSHIP; if (status.common.observed_mode == (uint8)PCM_STATE_X && !pcm_resource_x_bootstrap_round_terminal_cover_exact_locked( - entry, round, &round->terminal_ref, - round->master_session_incarnation, + entry, round, &round->terminal_ref, round->master_session_incarnation, round->r4_record_generation, observation_out->current_pair_source_generation)) observation_out->mismatch_mask |= RESOURCE_X_SOURCE_SETTLEMENT_MISMATCH_TERMINAL_COVER; } if (observation_out->mismatch_mask == 0) - observation_out->mismatch_mask - |= RESOURCE_X_SOURCE_SETTLEMENT_MISMATCH_PAIR_BYTES; + observation_out->mismatch_mask |= RESOURCE_X_SOURCE_SETTLEMENT_MISMATCH_PAIR_BYTES; } } @@ -21500,12 +19805,12 @@ pcm_resource_x_source_settlement_prepare_internal( } ResourceXApplyResult -cluster_pcm_lock_resource_x_source_settlement_prepare_exact( - const ResourceXDecodedFrame *settlement, int32 authenticated_master_node, - ResourceXSourceSettlementPlan *plan_out) +cluster_pcm_lock_resource_x_source_settlement_prepare_exact(const ResourceXDecodedFrame *settlement, + int32 authenticated_master_node, + ResourceXSourceSettlementPlan *plan_out) { - return pcm_resource_x_source_settlement_prepare_internal( - settlement, authenticated_master_node, plan_out, NULL); + return pcm_resource_x_source_settlement_prepare_internal(settlement, authenticated_master_node, + plan_out, NULL); } ResourceXApplyResult @@ -21516,8 +19821,8 @@ cluster_pcm_lock_resource_x_source_settlement_prepare_observed_exact( { if (observation_out == NULL) return RESOURCE_X_APPLY_INVALID; - return pcm_resource_x_source_settlement_prepare_internal( - settlement, authenticated_master_node, plan_out, observation_out); + return pcm_resource_x_source_settlement_prepare_internal(settlement, authenticated_master_node, + plan_out, observation_out); } /* Close only the exact terminal-X episode frozen by prepare. NO_COVER is @@ -21525,8 +19830,7 @@ cluster_pcm_lock_resource_x_source_settlement_prepare_observed_exact( * every non-terminal phase here is therefore post-prepare drift, not absence. */ static ResourceXApplyResult pcm_resource_x_source_settlement_close_terminal_cover_locked( - struct GrdEntry *entry, const ResourceXSourceSettlementPlan *plan, - bool *cleared_out, + struct GrdEntry *entry, const ResourceXSourceSettlementPlan *plan, bool *cleared_out, ResourceXSourceSettlementCommitObservation *observation) { ClusterPcmResourceXBootstrapRound *round; @@ -21544,69 +19848,47 @@ pcm_resource_x_source_settlement_close_terminal_cover_locked( observation->current_round_phase = round->phase; observation->current_owner_state = owner->state; observation->current_master_node = round->current_master_node; - observation->current_master_session - = round->master_session_incarnation; - observation->current_terminal_authority_generation - = round->terminal_authority_generation; - observation->current_cached_ownership_generation - = round->cached_ownership_generation; - if (plan->cover_action - != RESOURCE_X_SETTLEMENT_COVER_CLOSE_EXACT_X + observation->current_master_session = round->master_session_incarnation; + observation->current_terminal_authority_generation = round->terminal_authority_generation; + observation->current_cached_ownership_generation = round->cached_ownership_generation; + if (plan->cover_action != RESOURCE_X_SETTLEMENT_COVER_CLOSE_EXACT_X || plan->source_mode != (uint8)PCM_STATE_X) return RESOURCE_X_APPLY_INVALID; if (round->phase != RESOURCE_X_BOOTSTRAP_ROUND_TERMINAL_X_CACHED) { - observation->mismatch_mask - |= RESOURCE_X_SOURCE_SETTLEMENT_MISMATCH_TERMINAL_COVER; + observation->mismatch_mask |= RESOURCE_X_SOURCE_SETTLEMENT_MISMATCH_TERMINAL_COVER; return RESOURCE_X_APPLY_STALE; } if (!pcm_resource_x_local_owner_valid_locked(owner)) { - observation->mismatch_mask - |= RESOURCE_X_SOURCE_SETTLEMENT_MISMATCH_TERMINAL_OWNER_INVALID; + observation->mismatch_mask |= RESOURCE_X_SOURCE_SETTLEMENT_MISMATCH_TERMINAL_OWNER_INVALID; return RESOURCE_X_APPLY_RECOVERY_BLOCKED; } if (owner->state != RESOURCE_X_LOCAL_OWNER_EMPTY) { - observation->mismatch_mask - |= RESOURCE_X_SOURCE_SETTLEMENT_MISMATCH_TERMINAL_OWNER_NONEMPTY; + observation->mismatch_mask |= RESOURCE_X_SOURCE_SETTLEMENT_MISMATCH_TERMINAL_OWNER_NONEMPTY; return RESOURCE_X_APPLY_BAD_STATE; } - if (!pcm_resource_x_acquisition_ref_equal( - &round->terminal_ref, &plan->terminal_ref) + if (!pcm_resource_x_acquisition_ref_equal(&round->terminal_ref, &plan->terminal_ref) || round->terminal_ref.assertion.requester_node != cluster_node_id) - mismatch_mask - |= RESOURCE_X_SOURCE_SETTLEMENT_MISMATCH_TERMINAL_REQUESTER; + mismatch_mask |= RESOURCE_X_SOURCE_SETTLEMENT_MISMATCH_TERMINAL_REQUESTER; if (round->current_master_node != plan->authenticated_master_node) - mismatch_mask - |= RESOURCE_X_SOURCE_SETTLEMENT_MISMATCH_TERMINAL_MASTER; + mismatch_mask |= RESOURCE_X_SOURCE_SETTLEMENT_MISMATCH_TERMINAL_MASTER; if (round->resource_formation != plan->resource_formation) - mismatch_mask - |= RESOURCE_X_SOURCE_SETTLEMENT_MISMATCH_TERMINAL_FORMATION; - if (round->master_session_incarnation - != plan->master_session_incarnation) - mismatch_mask - |= RESOURCE_X_SOURCE_SETTLEMENT_MISMATCH_TERMINAL_SESSION; - if (round->terminal_authority_generation - != plan->terminal_authority_generation) - mismatch_mask - |= RESOURCE_X_SOURCE_SETTLEMENT_MISMATCH_TERMINAL_AUTHORITY; + mismatch_mask |= RESOURCE_X_SOURCE_SETTLEMENT_MISMATCH_TERMINAL_FORMATION; + if (round->master_session_incarnation != plan->master_session_incarnation) + mismatch_mask |= RESOURCE_X_SOURCE_SETTLEMENT_MISMATCH_TERMINAL_SESSION; + if (round->terminal_authority_generation != plan->terminal_authority_generation) + mismatch_mask |= RESOURCE_X_SOURCE_SETTLEMENT_MISMATCH_TERMINAL_AUTHORITY; if (round->cached_ownership_generation != plan->source_generation - || round->cached_ownership_generation - != plan->terminal_cached_generation) - mismatch_mask - |= RESOURCE_X_SOURCE_SETTLEMENT_MISMATCH_TERMINAL_OWNERSHIP; - if (round->r4_record_generation - != plan->terminal_r4_record_generation) - mismatch_mask - |= RESOURCE_X_SOURCE_SETTLEMENT_MISMATCH_TERMINAL_COVER; + || round->cached_ownership_generation != plan->terminal_cached_generation) + mismatch_mask |= RESOURCE_X_SOURCE_SETTLEMENT_MISMATCH_TERMINAL_OWNERSHIP; + if (round->r4_record_generation != plan->terminal_r4_record_generation) + mismatch_mask |= RESOURCE_X_SOURCE_SETTLEMENT_MISMATCH_TERMINAL_COVER; if (round->delivery_target.buffer_id_plus_one != 0) mismatch_mask |= RESOURCE_X_SOURCE_SETTLEMENT_MISMATCH_TERMINAL_COVER; if (mismatch_mask == 0 && !pcm_resource_x_bootstrap_round_terminal_cover_exact_locked( - entry, round, &plan->terminal_ref, - plan->master_session_incarnation, - plan->terminal_r4_record_generation, - plan->source_generation)) - mismatch_mask - |= RESOURCE_X_SOURCE_SETTLEMENT_MISMATCH_TERMINAL_COVER; + entry, round, &plan->terminal_ref, plan->master_session_incarnation, + plan->terminal_r4_record_generation, plan->source_generation)) + mismatch_mask |= RESOURCE_X_SOURCE_SETTLEMENT_MISMATCH_TERMINAL_COVER; observation->mismatch_mask |= mismatch_mask; if (mismatch_mask != 0) return RESOURCE_X_APPLY_STALE; @@ -21636,98 +19918,72 @@ cluster_pcm_lock_resource_x_source_settlement_commit_exact( if (observation_out != NULL) memset(observation_out, 0, sizeof(*observation_out)); - if (settlement == NULL - || !resource_x_assertion_valid( - &settlement->common.logical_assertion) + if (settlement == NULL || !resource_x_assertion_valid(&settlement->common.logical_assertion) || authenticated_master_node < 0 || authenticated_master_node >= RESOURCE_X_PROTOCOL_NODE_LIMIT || !pcm_resource_x_source_settlement_plan_valid(plan) || authenticated_master_node != plan->authenticated_master_node - || !resource_x_assertion_equal( - &settlement->common.logical_assertion, &plan->assertion) - || settlement->common.resource_formation - != plan->resource_formation - || settlement->common.master_session_incarnation - != plan->master_session_incarnation - || settlement->common.assertion_sequence - != plan->assertion_sequence - || ClusterPcm == NULL + || !resource_x_assertion_equal(&settlement->common.logical_assertion, &plan->assertion) + || settlement->common.resource_formation != plan->resource_formation + || settlement->common.master_session_incarnation != plan->master_session_incarnation + || settlement->common.assertion_sequence != plan->assertion_sequence || ClusterPcm == NULL || observation_out == NULL) return RESOURCE_X_APPLY_INVALID; - if (!pcm_entry_ref_acquire(&settlement->common.logical_assertion.resource, - false, &entry_ref, &acquire_result)) { - observation_out->commit_stage - = RESOURCE_X_SOURCE_SETTLEMENT_COMMIT_STAGE_ENTRY_LOOKUP; + if (!pcm_entry_ref_acquire(&settlement->common.logical_assertion.resource, false, &entry_ref, + &acquire_result)) { + observation_out->commit_stage = RESOURCE_X_SOURCE_SETTLEMENT_COMMIT_STAGE_ENTRY_LOOKUP; return RESOURCE_X_APPLY_NOT_FOUND; } entry = entry_ref.entry; pcm_entry_lock_exclusive(entry); - pcm_resource_x_source_settlement_observe_round_locked( - entry, observation_out); + pcm_resource_x_source_settlement_observe_round_locked(entry, observation_out); observation_out->current_cover_action = plan->cover_action; state = pcm_resource_x_master_state_for_entry(entry); if (state == NULL) { - observation_out->commit_stage - = RESOURCE_X_SOURCE_SETTLEMENT_COMMIT_STAGE_MASTER_STATE; + observation_out->commit_stage = RESOURCE_X_SOURCE_SETTLEMENT_COMMIT_STAGE_MASTER_STATE; result = RESOURCE_X_APPLY_RECOVERY_BLOCKED; goto source_commit_done; } observation_out->current_holder_status_valid = state->holder_status.valid; observation_out->current_holder_image_valid = state->holder_image.valid; - observation_out->current_status_intent_state - = state->holder_status_intent.slot.state; - observation_out->current_image_intent_state - = state->holder_image_intent.state; - observation_out->current_pair_destination_node - = state->holder_status.destination_node; + observation_out->current_status_intent_state = state->holder_status_intent.slot.state; + observation_out->current_image_intent_state = state->holder_image_intent.state; + observation_out->current_pair_destination_node = state->holder_status.destination_node; domain = pcm_resource_x_holder_pair_drain_domain_locked( &entry->tag, state, authenticated_master_node, - settlement->common.master_session_incarnation, - &settlement->common.logical_assertion, + settlement->common.master_session_incarnation, &settlement->common.logical_assertion, settlement->common.assertion_sequence); - if (domain == RESOURCE_X_APPLY_DUPLICATE - || domain == RESOURCE_X_APPLY_RECOVERY_BLOCKED + if (domain == RESOURCE_X_APPLY_DUPLICATE || domain == RESOURCE_X_APPLY_RECOVERY_BLOCKED || domain == RESOURCE_X_APPLY_STALE) { - observation_out->commit_stage - = RESOURCE_X_SOURCE_SETTLEMENT_COMMIT_STAGE_DRAIN_DOMAIN; + observation_out->commit_stage = RESOURCE_X_SOURCE_SETTLEMENT_COMMIT_STAGE_DRAIN_DOMAIN; result = domain; goto source_commit_done; } result = pcm_resource_x_holder_pair_decode_locked(state, &status, &image); if (result != RESOURCE_X_APPLY_APPLIED) { - observation_out->commit_stage - = RESOURCE_X_SOURCE_SETTLEMENT_COMMIT_STAGE_PAIR_DECODE; + observation_out->commit_stage = RESOURCE_X_SOURCE_SETTLEMENT_COMMIT_STAGE_PAIR_DECODE; goto source_commit_done; } - observation_out->current_pair_resource_formation - = image.common.resource_formation; - observation_out->current_pair_master_session - = image.common.master_session_incarnation; - observation_out->current_pair_assertion_sequence - = image.common.assertion_sequence; + observation_out->current_pair_resource_formation = image.common.resource_formation; + observation_out->current_pair_master_session = image.common.master_session_incarnation; + observation_out->current_pair_assertion_sequence = image.common.assertion_sequence; observation_out->current_pair_source_generation - = pcm_resource_x_source_fence_get_u64( - image.body.image_envelope.source_fence + 20); + = pcm_resource_x_source_fence_get_u64(image.body.image_envelope.source_fence + 20); observation_out->current_pair_carrier_generation = image.body.image_envelope.source_carrier_generation; observation_out->current_pair_observed_mode = image.common.observed_mode; - gate_formation - = pg_atomic_read_u64(&ClusterPcm->resource_x_gate_formation); + gate_formation = pg_atomic_read_u64(&ClusterPcm->resource_x_gate_formation); observation_out->current_resource_formation = gate_formation; memset(¤t_plan, 0, sizeof(current_plan)); result = pcm_resource_x_source_settlement_plan_build_locked( - entry, state, settlement, authenticated_master_node, - &status, &image, ¤t_plan); + entry, state, settlement, authenticated_master_node, &status, &image, ¤t_plan); if (result != RESOURCE_X_APPLY_APPLIED) { observation_out->commit_stage - = (entry->resource_x_bootstrap_round.phase - != RESOURCE_X_BOOTSTRAP_ROUND_EMPTY) - ? RESOURCE_X_SOURCE_SETTLEMENT_COMMIT_STAGE_TERMINAL_COVER - : RESOURCE_X_SOURCE_SETTLEMENT_COMMIT_STAGE_PAIR_STATE; - if (entry->resource_x_bootstrap_round.phase - != RESOURCE_X_BOOTSTRAP_ROUND_EMPTY) - observation_out->mismatch_mask - |= RESOURCE_X_SOURCE_SETTLEMENT_MISMATCH_TERMINAL_COVER; + = (entry->resource_x_bootstrap_round.phase != RESOURCE_X_BOOTSTRAP_ROUND_EMPTY) + ? RESOURCE_X_SOURCE_SETTLEMENT_COMMIT_STAGE_TERMINAL_COVER + : RESOURCE_X_SOURCE_SETTLEMENT_COMMIT_STAGE_PAIR_STATE; + if (entry->resource_x_bootstrap_round.phase != RESOURCE_X_BOOTSTRAP_ROUND_EMPTY) + observation_out->mismatch_mask |= RESOURCE_X_SOURCE_SETTLEMENT_MISMATCH_TERMINAL_COVER; goto source_commit_done; } observation_out->current_cover_action = current_plan.cover_action; @@ -21737,49 +19993,40 @@ cluster_pcm_lock_resource_x_source_settlement_commit_exact( observation_out->mismatch_mask |= RESOURCE_X_SOURCE_SETTLEMENT_MISMATCH_SOURCE_GENERATION; if (plan->cover_action != current_plan.cover_action) - observation_out->mismatch_mask - |= RESOURCE_X_SOURCE_SETTLEMENT_MISMATCH_TERMINAL_COVER; - if (plan->terminal_cached_generation - != current_plan.terminal_cached_generation) + observation_out->mismatch_mask |= RESOURCE_X_SOURCE_SETTLEMENT_MISMATCH_TERMINAL_COVER; + if (plan->terminal_cached_generation != current_plan.terminal_cached_generation) observation_out->mismatch_mask |= RESOURCE_X_SOURCE_SETTLEMENT_MISMATCH_TERMINAL_OWNERSHIP; - if (plan->terminal_authority_generation - != current_plan.terminal_authority_generation) + if (plan->terminal_authority_generation != current_plan.terminal_authority_generation) observation_out->mismatch_mask |= RESOURCE_X_SOURCE_SETTLEMENT_MISMATCH_TERMINAL_AUTHORITY; - if (plan->master_session_incarnation - != current_plan.master_session_incarnation) + if (plan->master_session_incarnation != current_plan.master_session_incarnation) observation_out->mismatch_mask |= RESOURCE_X_SOURCE_SETTLEMENT_MISMATCH_TERMINAL_SESSION; if (observation_out->mismatch_mask == 0) - observation_out->mismatch_mask - |= RESOURCE_X_SOURCE_SETTLEMENT_MISMATCH_PAIR_BYTES; + observation_out->mismatch_mask |= RESOURCE_X_SOURCE_SETTLEMENT_MISMATCH_PAIR_BYTES; observation_out->commit_stage = (observation_out->mismatch_mask - & (RESOURCE_X_SOURCE_SETTLEMENT_MISMATCH_TERMINAL_COVER - | RESOURCE_X_SOURCE_SETTLEMENT_MISMATCH_TERMINAL_OWNERSHIP - | RESOURCE_X_SOURCE_SETTLEMENT_MISMATCH_TERMINAL_AUTHORITY - | RESOURCE_X_SOURCE_SETTLEMENT_MISMATCH_TERMINAL_SESSION)) - ? RESOURCE_X_SOURCE_SETTLEMENT_COMMIT_STAGE_TERMINAL_COVER - : RESOURCE_X_SOURCE_SETTLEMENT_COMMIT_STAGE_PAIR_IDENTITY; + & (RESOURCE_X_SOURCE_SETTLEMENT_MISMATCH_TERMINAL_COVER + | RESOURCE_X_SOURCE_SETTLEMENT_MISMATCH_TERMINAL_OWNERSHIP + | RESOURCE_X_SOURCE_SETTLEMENT_MISMATCH_TERMINAL_AUTHORITY + | RESOURCE_X_SOURCE_SETTLEMENT_MISMATCH_TERMINAL_SESSION)) + ? RESOURCE_X_SOURCE_SETTLEMENT_COMMIT_STAGE_TERMINAL_COVER + : RESOURCE_X_SOURCE_SETTLEMENT_COMMIT_STAGE_PAIR_IDENTITY; result = RESOURCE_X_APPLY_STALE; goto source_commit_done; } - observation_out->commit_stage - = RESOURCE_X_SOURCE_SETTLEMENT_COMMIT_STAGE_TERMINAL_COVER; - if (plan->cover_action - == RESOURCE_X_SETTLEMENT_COVER_CLOSE_EXACT_X) { + observation_out->commit_stage = RESOURCE_X_SOURCE_SETTLEMENT_COMMIT_STAGE_TERMINAL_COVER; + if (plan->cover_action == RESOURCE_X_SETTLEMENT_COVER_CLOSE_EXACT_X) { result = pcm_resource_x_source_settlement_close_terminal_cover_locked( entry, plan, &terminal_cover_cleared, observation_out); if (result != RESOURCE_X_APPLY_APPLIED) goto source_commit_done; } - state->holder_pair_drained_sequences[ - settlement->common.logical_assertion.requester_node] + state->holder_pair_drained_sequences[settlement->common.logical_assertion.requester_node] = settlement->common.assertion_sequence; state->holder_pair_drained_resource_formation = gate_formation; - state->holder_pair_drained_master_session - = settlement->common.master_session_incarnation; + state->holder_pair_drained_master_session = settlement->common.master_session_incarnation; state->holder_pair_drained_master_node = authenticated_master_node; state->holder_pair_drained_reserved = 0; settlement_committed = true; @@ -21795,30 +20042,26 @@ cluster_pcm_lock_resource_x_source_settlement_commit_exact( ResourceXApplyResult cluster_pcm_lock_resource_x_source_settlement_ack_build_exact( - const ResourceXDecodedFrame *settlement, - uint32 sender_connection_generation, ResourceXDecodedFrame *ack_out) + const ResourceXDecodedFrame *settlement, uint32 sender_connection_generation, + ResourceXDecodedFrame *ack_out) { if (ack_out != NULL) memset(ack_out, 0, sizeof(*ack_out)); if (settlement == NULL || ack_out == NULL || settlement->kind != RESOURCE_X_WIRE_SOURCE_SETTLEMENT_V2 || !settlement->blocked_has_remote_proof - || !resource_x_assertion_valid( - &settlement->common.logical_assertion) + || !resource_x_assertion_valid(&settlement->common.logical_assertion) || settlement->common.ordered_lane != 0 || settlement->common.observed_mode != (uint8)PCM_STATE_N || settlement->common.target_mode != (uint8)PCM_STATE_N - || settlement->common.source_candidate != 1 - || settlement->common.retain_pi_if_dirty != 1 - || settlement->common.outcome != RESOURCE_X_OUTCOME_NONE - || settlement->common.flags != 0 + || settlement->common.source_candidate != 1 || settlement->common.retain_pi_if_dirty != 1 + || settlement->common.outcome != RESOURCE_X_OUTCOME_NONE || settlement->common.flags != 0 || sender_connection_generation == 0) return RESOURCE_X_APPLY_INVALID; *ack_out = *settlement; ack_out->kind = RESOURCE_X_WIRE_SOURCE_SETTLEMENT_ACK_V2; ack_out->payload_bytes = RESOURCE_X_PROOF_V1_BYTES; - ack_out->common.sender_connection_generation - = sender_connection_generation; + ack_out->common.sender_connection_generation = sender_connection_generation; ack_out->common.outcome = RESOURCE_X_OUTCOME_OK; ack_out->common.semantic_crc32c = 0; return RESOURCE_X_APPLY_APPLIED; @@ -21829,9 +20072,8 @@ cluster_pcm_lock_resource_x_source_settlement_ack_build_exact( * stable across a reconnect. All other wire semantics, including the * semantic CRC over the canonical bytes, remain frozen. */ static bool -pcm_resource_x_requester_join_normalize( - const ResourceXDecodedFrame *frame, uint8 *payload, uint16 capacity, - uint16 *payload_bytes_out) +pcm_resource_x_requester_join_normalize(const ResourceXDecodedFrame *frame, uint8 *payload, + uint16 capacity, uint16 *payload_bytes_out) { ResourceXDecodedFrame canonical; ResourceXWireReject reject = RESOURCE_X_WIRE_REJECT_NONE; @@ -21843,16 +20085,13 @@ pcm_resource_x_requester_join_normalize( && frame->kind != RESOURCE_X_WIRE_IMAGE_ENVELOPE)) return false; canonical = *frame; - canonical.common.sender_connection_generation - = PGRAC_RESOURCE_X_RETAINED_SENDER_GENERATION; - return cluster_resource_x_wire_encode( - RESOURCE_X_MSG_IMAGE_OR_GRANT, &canonical, payload, capacity, - payload_bytes_out, &reject); + canonical.common.sender_connection_generation = PGRAC_RESOURCE_X_RETAINED_SENDER_GENERATION; + return cluster_resource_x_wire_encode(RESOURCE_X_MSG_IMAGE_OR_GRANT, &canonical, payload, + capacity, payload_bytes_out, &reject); } static bool -pcm_resource_x_requester_join_empty_locked( - const ClusterPcmResourceXRequesterJoin *join) +pcm_resource_x_requester_join_empty_locked(const ClusterPcmResourceXRequesterJoin *join) { static const ClusterPcmResourceXRequesterJoin empty_join; @@ -21861,9 +20100,9 @@ pcm_resource_x_requester_join_empty_locked( } static bool -pcm_resource_x_requester_join_decode_locked( - const ClusterPcmResourceXRequesterJoin *join, - ResourceXDecodedFrame *grant_out, ResourceXDecodedFrame *image_out) +pcm_resource_x_requester_join_decode_locked(const ClusterPcmResourceXRequesterJoin *join, + ResourceXDecodedFrame *grant_out, + ResourceXDecodedFrame *image_out) { ResourceXWireReject reject = RESOURCE_X_WIRE_REJECT_NONE; @@ -21880,34 +20119,31 @@ pcm_resource_x_requester_join_decode_locked( if (join->grant_valid != 0 && (join->grant_valid != 1 || grant_out == NULL || join->grant_payload_bytes != RESOURCE_X_PROOF_V1_BYTES - || !cluster_resource_x_wire_decode( - RESOURCE_X_MSG_IMAGE_OR_GRANT, join->grant_payload, - join->grant_payload_bytes, grant_out, &reject) + || !cluster_resource_x_wire_decode(RESOURCE_X_MSG_IMAGE_OR_GRANT, join->grant_payload, + join->grant_payload_bytes, grant_out, &reject) || grant_out->kind != RESOURCE_X_WIRE_AUTHORITY_GRANT)) return false; reject = RESOURCE_X_WIRE_REJECT_NONE; if (join->image_valid != 0 && (join->image_valid != 1 || image_out == NULL || join->image_payload_bytes != RESOURCE_X_IMAGE_V1_BYTES - || !cluster_resource_x_wire_decode( - RESOURCE_X_MSG_IMAGE_OR_GRANT, join->image_payload, - join->image_payload_bytes, image_out, &reject) + || !cluster_resource_x_wire_decode(RESOURCE_X_MSG_IMAGE_OR_GRANT, join->image_payload, + join->image_payload_bytes, image_out, &reject) || image_out->kind != RESOURCE_X_WIRE_IMAGE_ENVELOPE)) return false; return true; } static bool -pcm_resource_x_requester_join_pair_matches( - const ResourceXDecodedFrame *grant, const ResourceXDecodedFrame *image, - uint32 image_semantic_crc32c) +pcm_resource_x_requester_join_pair_matches(const ResourceXDecodedFrame *grant, + const ResourceXDecodedFrame *image, + uint32 image_semantic_crc32c) { const ResourceXDecodedAuthorityGrant *grant_body; const ResourceXDecodedImageEnvelope *image_body; uint8 source_mode; - if (grant == NULL || image == NULL - || grant->kind != RESOURCE_X_WIRE_AUTHORITY_GRANT + if (grant == NULL || image == NULL || grant->kind != RESOURCE_X_WIRE_AUTHORITY_GRANT || image->kind != RESOURCE_X_WIRE_IMAGE_ENVELOPE) return false; grant_body = &grant->body.authority_grant; @@ -21956,9 +20192,8 @@ pcm_resource_x_requester_join_pair_matches( } static bool -pcm_resource_x_requester_join_snapshot_locked( - const ClusterPcmResourceXRequesterJoin *join, - ResourceXRequesterJoinSnapshot *out) +pcm_resource_x_requester_join_snapshot_locked(const ClusterPcmResourceXRequesterJoin *join, + ResourceXRequesterJoinSnapshot *out) { ResourceXDecodedFrame grant; ResourceXDecodedFrame image; @@ -21973,14 +20208,11 @@ pcm_resource_x_requester_join_snapshot_locked( return true; identity = join->grant_valid != 0 ? &grant : ℑ out->assertion = identity->common.logical_assertion; - out->base_authority_generation - = identity->common.base_authority_generation; + out->base_authority_generation = identity->common.base_authority_generation; out->resource_formation = identity->common.resource_formation; - out->master_session_incarnation - = identity->common.master_session_incarnation; + out->master_session_incarnation = identity->common.master_session_incarnation; out->assertion_sequence = identity->common.assertion_sequence; - out->final_authority_generation - = identity->common.authority_generation; + out->final_authority_generation = identity->common.authority_generation; out->t_image_us = join->t_image_us; out->t_grant_us = join->t_grant_us; out->t_install_us = join->t_install_us; @@ -21990,25 +20222,20 @@ pcm_resource_x_requester_join_snapshot_locked( out->grant_source_node = join->grant_source_node; out->image_source_node = join->image_source_node; if (join->grant_valid != 0) { - out->source_carrier_generation - = grant.body.authority_grant.source_carrier_generation; - out->requester_target_generation - = grant.body.authority_grant.requester_target_generation; + out->source_carrier_generation = grant.body.authority_grant.source_carrier_generation; + out->requester_target_generation = grant.body.authority_grant.requester_target_generation; out->flags |= RESOURCE_X_REQUESTER_JOIN_HAS_GRANT; } else { - out->source_carrier_generation - = image.body.image_envelope.source_carrier_generation; - out->requester_target_generation - = image.body.image_envelope.requester_target_generation; + out->source_carrier_generation = image.body.image_envelope.source_carrier_generation; + out->requester_target_generation = image.body.image_envelope.requester_target_generation; } if (join->image_valid != 0) out->flags |= RESOURCE_X_REQUESTER_JOIN_HAS_IMAGE; if (join->grant_valid != 0 - && (grant.body.authority_grant.proof_kind - != RESOURCE_X_PROOF_REMOTE_CARRIER + && (grant.body.authority_grant.proof_kind != RESOURCE_X_PROOF_REMOTE_CARRIER || (join->image_valid != 0 - && pcm_resource_x_requester_join_pair_matches( - &grant, &image, join->image_semantic_crc32c)))) + && pcm_resource_x_requester_join_pair_matches(&grant, &image, + join->image_semantic_crc32c)))) out->flags |= RESOURCE_X_REQUESTER_JOIN_READY; if (join->settled != 0) out->flags |= RESOURCE_X_REQUESTER_JOIN_TERMINAL; @@ -22016,8 +20243,8 @@ pcm_resource_x_requester_join_snapshot_locked( } static ResourceXApplyResult -pcm_resource_x_requester_join_bindable_locked( - struct GrdEntry *entry, const ResourceXAcquisitionRef *ref) +pcm_resource_x_requester_join_bindable_locked(struct GrdEntry *entry, + const ResourceXAcquisitionRef *ref) { ClusterPcmResourceXMasterState *state; ClusterPcmResourceXRequesterJoin *join; @@ -22039,10 +20266,10 @@ pcm_resource_x_requester_join_bindable_locked( if (!pcm_resource_x_requester_join_snapshot_locked(join, &snapshot)) return RESOURCE_X_APPLY_RECOVERY_BLOCKED; return resource_x_assertion_equal(&snapshot.assertion, &ref->assertion) - && snapshot.resource_formation == ref->formation - && snapshot.requester_target_generation - == ref->acquisition_generation - ? RESOURCE_X_APPLY_APPLIED : RESOURCE_X_APPLY_STALE; + && snapshot.resource_formation == ref->formation + && snapshot.requester_target_generation == ref->acquisition_generation + ? RESOURCE_X_APPLY_APPLIED + : RESOURCE_X_APPLY_STALE; } static ResourceXApplyResult @@ -22069,8 +20296,7 @@ pcm_resource_x_requester_retirement_prepare_locked(struct GrdEntry *entry, if (entry->resource_x_requester_base_generation < 1 || entry->resource_x_requester_base_generation == UINT64_MAX || entry->resource_x_retired_acquisition_generation == UINT64_MAX - || ref->acquisition_generation - <= entry->resource_x_retired_acquisition_generation) + || ref->acquisition_generation <= entry->resource_x_retired_acquisition_generation) return RESOURCE_X_APPLY_RECOVERY_BLOCKED; state = pcm_resource_x_master_state_for_entry(entry); if (state == NULL || ClusterPcm == NULL) @@ -22082,35 +20308,30 @@ pcm_resource_x_requester_retirement_prepare_locked(struct GrdEntry *entry, return RESOURCE_X_APPLY_APPLIED; if (!pcm_resource_x_requester_join_snapshot_locked(join, &snapshot)) return RESOURCE_X_APPLY_RECOVERY_BLOCKED; - if ((snapshot.flags & RESOURCE_X_REQUESTER_JOIN_READY) == 0 - || join->grant_valid == 0 + if ((snapshot.flags & RESOURCE_X_REQUESTER_JOIN_READY) == 0 || join->grant_valid == 0 || !resource_x_assertion_equal(&snapshot.assertion, &ref->assertion) || snapshot.resource_formation != ref->formation || snapshot.requester_target_generation != ref->acquisition_generation) return RESOURCE_X_APPLY_BAD_STATE; - if (snapshot.final_authority_generation - <= entry->resource_x_requester_base_generation) { + if (snapshot.final_authority_generation <= entry->resource_x_requester_base_generation) { now_us = pcm_resource_x_monotonic_us(); live_round_base_exact = pcm_resource_x_requester_join_live_round_base_exact_locked( entry, &entry->resource_x_bootstrap_round, join->authority_with_image ? &image : &grant, join->authority_with_image ? join->image_source_node : join->grant_source_node, ref->acquisition_generation, now_us, claim); } - if (snapshot.final_authority_generation < 2 - || snapshot.final_authority_generation == UINT64_MAX - || (snapshot.final_authority_generation - <= entry->resource_x_requester_base_generation + if (snapshot.final_authority_generation < 2 || snapshot.final_authority_generation == UINT64_MAX + || (snapshot.final_authority_generation <= entry->resource_x_requester_base_generation && !live_round_base_exact) || grant.common.authority_generation - != grant.body.authority_grant.final_authority_generation) + != grant.body.authority_grant.final_authority_generation) return RESOURCE_X_APPLY_STALE; proof_kind = grant.body.authority_grant.proof_kind; - if (proof_kind < RESOURCE_X_PROOF_KIND_MIN - || proof_kind > RESOURCE_X_PROOF_KIND_MAX) + if (proof_kind < RESOURCE_X_PROOF_KIND_MIN || proof_kind > RESOURCE_X_PROOF_KIND_MAX) return RESOURCE_X_APPLY_RECOVERY_BLOCKED; if (join->settled != 0) { - if (join->settled != 1 || join->proof_kind != proof_kind - || join->install_succeeded > 1 || join->requester_loss_seen > 1) + if (join->settled != 1 || join->proof_kind != proof_kind || join->install_succeeded > 1 + || join->requester_loss_seen > 1) return RESOURCE_X_APPLY_RECOVERY_BLOCKED; witness_out->already_settled = true; witness_out->install_succeeded = join->install_succeeded; @@ -22133,25 +20354,23 @@ pcm_resource_x_requester_retirement_prepare_locked(struct GrdEntry *entry, witness_out->diagnostic_base_generation = snapshot.base_authority_generation; if (proof_kind == RESOURCE_X_PROOF_REMOTE_CARRIER && join->image_valid != 0) witness_out->diagnostic_source_mode = image.body.image_envelope.source_fence[28]; - witness_out->final_authority_generation - = snapshot.final_authority_generation; + witness_out->final_authority_generation = snapshot.final_authority_generation; witness_out->t_image_us = join->t_image_us; witness_out->t_grant_us = join->t_grant_us; return RESOURCE_X_APPLY_APPLIED; } static void -pcm_resource_x_requester_settlement_clear( - ClusterPcmResourceXControlIntent *intent) +pcm_resource_x_requester_settlement_clear(ClusterPcmResourceXControlIntent *intent) { Assert(intent != NULL); memset(intent, 0, sizeof(*intent)); } static bool -pcm_resource_x_requester_settlement_arm_locked( - struct GrdEntry *entry, const ResourceXAcquisitionRef *ref, - const PcmResourceXRetirementWitness *witness) +pcm_resource_x_requester_settlement_arm_locked(struct GrdEntry *entry, + const ResourceXAcquisitionRef *ref, + const PcmResourceXRetirementWitness *witness) { ClusterPcmResourceXMasterState *state; ClusterPcmResourceXRequesterJoin *join; @@ -22171,71 +20390,54 @@ pcm_resource_x_requester_settlement_arm_locked( if (!witness->had_join) return true; state = pcm_resource_x_master_state_for_entry(entry); - if (state == NULL || cluster_node_id < 0 - || cluster_node_id >= RESOURCE_X_PROTOCOL_NODE_LIMIT) + if (state == NULL || cluster_node_id < 0 || cluster_node_id >= RESOURCE_X_PROTOCOL_NODE_LIMIT) return false; join = &state->requester_join; intent = &state->requester_settlement_intent; - if (!pcm_resource_x_requester_join_decode_locked(join, &grant, &image) - || join->grant_valid == 0 - || join->grant_source_node < 0 - || join->grant_source_node >= RESOURCE_X_PROTOCOL_NODE_LIMIT - || witness->already_settled || !witness->install_succeeded - || witness->requester_loss_seen + if (!pcm_resource_x_requester_join_decode_locked(join, &grant, &image) || join->grant_valid == 0 + || join->grant_source_node < 0 || join->grant_source_node >= RESOURCE_X_PROTOCOL_NODE_LIMIT + || witness->already_settled || !witness->install_succeeded || witness->requester_loss_seen || witness->t_install_us == 0 - || !resource_x_assertion_equal( - &grant.common.logical_assertion, &ref->assertion) + || !resource_x_assertion_equal(&grant.common.logical_assertion, &ref->assertion) || grant.common.resource_formation != ref->formation || grant.common.assertion_sequence != ref->acquisition_generation - || grant.common.authority_generation - != witness->final_authority_generation + || grant.common.authority_generation != witness->final_authority_generation || grant.body.authority_grant.final_authority_generation - != witness->final_authority_generation) + != witness->final_authority_generation) return false; memset(&settlement, 0, sizeof(settlement)); settlement.kind = RESOURCE_X_WIRE_INSTALL_SETTLEMENT; settlement.payload_bytes = RESOURCE_X_SHORT_V1_BYTES; settlement.common.logical_assertion = grant.common.logical_assertion; - settlement.common.base_authority_generation - = grant.common.base_authority_generation; + settlement.common.base_authority_generation = grant.common.base_authority_generation; settlement.common.resource_formation = grant.common.resource_formation; - settlement.common.master_session_incarnation - = grant.common.master_session_incarnation; + settlement.common.master_session_incarnation = grant.common.master_session_incarnation; settlement.common.assertion_sequence = grant.common.assertion_sequence; settlement.common.ordered_lane = grant.common.ordered_lane; settlement.common.action_node = cluster_node_id; settlement.common.observed_mode = (uint8)PCM_STATE_N; settlement.common.target_mode = (uint8)PCM_STATE_X; - settlement.common.sender_connection_generation - = PGRAC_RESOURCE_X_RETAINED_SENDER_GENERATION; + settlement.common.sender_connection_generation = PGRAC_RESOURCE_X_RETAINED_SENDER_GENERATION; settlement.common.outcome = RESOURCE_X_OUTCOME_OK; - settlement.common.authority_generation - = witness->final_authority_generation; + settlement.common.authority_generation = witness->final_authority_generation; settlement.body.install_settlement.conversion_base_generation = grant.common.base_authority_generation; settlement.body.install_settlement.final_authority_generation = witness->final_authority_generation; settlement.body.install_settlement.requester_connection_generation = grant.body.authority_grant.requester_connection_generation; - settlement.body.install_settlement.requester_target_generation - = ref->acquisition_generation; - settlement.body.install_settlement.page_scn_lsn - = grant.body.authority_grant.page_scn_lsn; - settlement.body.install_settlement.page_checksum - = grant.body.authority_grant.page_checksum; + settlement.body.install_settlement.requester_target_generation = ref->acquisition_generation; + settlement.body.install_settlement.page_scn_lsn = grant.body.authority_grant.page_scn_lsn; + settlement.body.install_settlement.page_checksum = grant.body.authority_grant.page_checksum; settlement.body.install_settlement.source_proof_crc32c = grant.body.authority_grant.source_proof_crc32c; settlement.body.install_settlement.installed_mode = (uint8)PCM_STATE_X; - settlement.body.install_settlement.requester_role - = RESOURCE_X_REQUESTER_ROLE_ACQUIRER; - settlement.body.install_settlement.terminal_outcome - = RESOURCE_X_OUTCOME_OK; - settlement.body.install_settlement.terminal_state - = RESOURCE_X_SETTLEMENT_TERMINAL_INSTALLED; - if (!cluster_resource_x_wire_encode( - RESOURCE_X_MSG_SETTLEMENT_OR_RELEASE, &settlement, payload, - sizeof(payload), &payload_bytes, &reject) + settlement.body.install_settlement.requester_role = RESOURCE_X_REQUESTER_ROLE_ACQUIRER; + settlement.body.install_settlement.terminal_outcome = RESOURCE_X_OUTCOME_OK; + settlement.body.install_settlement.terminal_state = RESOURCE_X_SETTLEMENT_TERMINAL_INSTALLED; + if (!cluster_resource_x_wire_encode(RESOURCE_X_MSG_SETTLEMENT_OR_RELEASE, &settlement, payload, + sizeof(payload), &payload_bytes, &reject) || payload_bytes != RESOURCE_X_SHORT_V1_BYTES) return false; @@ -22246,19 +20448,16 @@ pcm_resource_x_requester_settlement_arm_locked( body.owner_kind = RESOURCE_X_INTENT_OWNER_REQUESTER_SETTLEMENT; if (intent->slot.state != RESOURCE_X_INTENT_SLOT_EMPTY) return intent->slot.logical_generation == ref->acquisition_generation - && intent->slot.authority_generation - == witness->final_authority_generation - && intent->slot.destination_node - == (uint32)join->grant_source_node - && intent->slot.payload_bytes == payload_bytes - && intent->slot.kind == RESOURCE_X_WIRE_INSTALL_SETTLEMENT - && memcmp(&intent->slot.body, &body, sizeof(body)) == 0 - && memcmp(intent->payload, payload, payload_bytes) == 0; + && intent->slot.authority_generation == witness->final_authority_generation + && intent->slot.destination_node == (uint32)join->grant_source_node + && intent->slot.payload_bytes == payload_bytes + && intent->slot.kind == RESOURCE_X_WIRE_INSTALL_SETTLEMENT + && memcmp(&intent->slot.body, &body, sizeof(body)) == 0 + && memcmp(intent->payload, payload, payload_bytes) == 0; memcpy(intent->payload, payload, payload_bytes); if (!cluster_pcm_lock_resource_x_intent_arm_exact( - &intent->slot, &body, ref->acquisition_generation, - witness->final_authority_generation, witness->t_install_us, - (uint32)join->grant_source_node, payload_bytes, + &intent->slot, &body, ref->acquisition_generation, witness->final_authority_generation, + witness->t_install_us, (uint32)join->grant_source_node, payload_bytes, RESOURCE_X_WIRE_INSTALL_SETTLEMENT) || !pcm_resource_x_intent_mark_dirty()) { pcm_resource_x_requester_settlement_clear(intent); @@ -22268,9 +20467,9 @@ pcm_resource_x_requester_settlement_arm_locked( } static void -pcm_resource_x_requester_retirement_commit_locked( - struct GrdEntry *entry, const ResourceXAcquisitionRef *ref, - const PcmResourceXRetirementWitness *witness) +pcm_resource_x_requester_retirement_commit_locked(struct GrdEntry *entry, + const ResourceXAcquisitionRef *ref, + const PcmResourceXRetirementWitness *witness) { ClusterPcmResourceXMasterState *state; ClusterPcmResourceXRequesterJoin *join; @@ -22284,7 +20483,7 @@ pcm_resource_x_requester_retirement_commit_locked( join = &state->requester_join; if (witness->had_join && !witness->already_settled) { ClusterPcmResourceXBootstrapRound *round = &entry->resource_x_bootstrap_round; - ResourceXTraceEvent event = {0}; + ResourceXTraceEvent event = { 0 }; event.kind = RESOURCE_X_TRACE_RETIRE; event.detail = witness->proof_kind; @@ -22340,21 +20539,18 @@ pcm_resource_x_requester_retirement_commit_locked( if (witness->proof_kind == RESOURCE_X_PROOF_REMOTE_CARRIER && !witness->requester_loss_seen && !join->authority_with_image) { if (witness->t_image_us != 0) - pg_atomic_write_u64( - &ClusterPcm->resource_x_o1_last_remote_t_image_us, - witness->t_image_us); + pg_atomic_write_u64(&ClusterPcm->resource_x_o1_last_remote_t_image_us, + witness->t_image_us); if (witness->t_grant_us != 0) - pg_atomic_write_u64( - &ClusterPcm->resource_x_o1_last_remote_t_grant_us, - witness->t_grant_us); + pg_atomic_write_u64(&ClusterPcm->resource_x_o1_last_remote_t_grant_us, + witness->t_grant_us); if (witness->t_install_us != 0) - pg_atomic_write_u64( - &ClusterPcm->resource_x_o1_last_remote_t_install_us, - witness->t_install_us); - if (witness->install_succeeded && witness->t_image_us != 0 - && witness->t_grant_us != 0 && witness->t_install_us != 0) { - pg_atomic_fetch_add_u64( - &ClusterPcm->resource_x_o1_remote_install_observed_count, 1); + pg_atomic_write_u64(&ClusterPcm->resource_x_o1_last_remote_t_install_us, + witness->t_install_us); + if (witness->install_succeeded && witness->t_image_us != 0 && witness->t_grant_us != 0 + && witness->t_install_us != 0) { + pg_atomic_fetch_add_u64(&ClusterPcm->resource_x_o1_remote_install_observed_count, + 1); if (witness->t_grant_us > witness->t_image_us) pg_atomic_fetch_add_u64( &ClusterPcm->resource_x_o1_remote_grant_after_image_count, 1); @@ -22374,11 +20570,9 @@ pcm_resource_x_requester_retirement_commit_locked( } } memset(join, 0, sizeof(*join)); - entry->resource_x_retired_acquisition_generation - = ref->acquisition_generation; + entry->resource_x_retired_acquisition_generation = ref->acquisition_generation; if (witness->had_join) - entry->resource_x_requester_base_generation - = witness->final_authority_generation; + entry->resource_x_requester_base_generation = witness->final_authority_generation; pcm_resource_x_active_clear_locked(entry); } @@ -22512,16 +20706,13 @@ pcm_resource_x_requester_join_internal( && frame->kind != RESOURCE_X_WIRE_IMAGE_ENVELOPE) || !resource_x_assertion_valid(&frame->common.logical_assertion) || authenticated_source_node < 0 - || authenticated_source_node >= RESOURCE_X_PROTOCOL_NODE_LIMIT - || cluster_node_id < 0 + || authenticated_source_node >= RESOURCE_X_PROTOCOL_NODE_LIMIT || cluster_node_id < 0 || cluster_node_id >= RESOURCE_X_PROTOCOL_NODE_LIMIT || frame->common.logical_assertion.requester_node != cluster_node_id - || frame->common.action_node != cluster_node_id - || frame->common.resource_formation == 0 + || frame->common.action_node != cluster_node_id || frame->common.resource_formation == 0 || frame->common.authority_generation == 0 || frame->common.sender_connection_generation == 0 - || (frame->kind == RESOURCE_X_WIRE_IMAGE_ENVELOPE - && frame->common.semantic_crc32c == 0) + || (frame->kind == RESOURCE_X_WIRE_IMAGE_ENVELOPE && frame->common.semantic_crc32c == 0) || ClusterPcm == NULL) return RESOURCE_X_APPLY_INVALID; is_grant = frame->kind == RESOURCE_X_WIRE_AUTHORITY_GRANT; @@ -22542,40 +20733,34 @@ pcm_resource_x_requester_join_internal( != frame->common.assertion_sequence) return RESOURCE_X_APPLY_INVALID; } - requester_target_generation = is_grant - ? frame->body.authority_grant.requester_target_generation - : frame->body.image_envelope.requester_target_generation; + requester_target_generation = is_grant ? frame->body.authority_grant.requester_target_generation + : frame->body.image_envelope.requester_target_generation; final_authority_generation = frame->common.authority_generation; - if (requester_target_generation == 0 - || requester_target_generation == UINT64_MAX + if (requester_target_generation == 0 || requester_target_generation == UINT64_MAX || frame->common.assertion_sequence != requester_target_generation - || final_authority_generation < 2 - || final_authority_generation == UINT64_MAX + || final_authority_generation < 2 || final_authority_generation == UINT64_MAX || (is_grant && frame->body.authority_grant.final_authority_generation - != final_authority_generation)) + != final_authority_generation)) return RESOURCE_X_APPLY_INVALID; if ((is_grant - && cluster_gcs_lookup_master(frame->common.logical_assertion.resource) + && cluster_gcs_lookup_master(frame->common.logical_assertion.resource) != authenticated_source_node) || (!is_grant && authenticated_source_node == cluster_node_id) - || !pcm_resource_x_requester_join_normalize( - frame, normalized, sizeof(normalized), &normalized_bytes) + || !pcm_resource_x_requester_join_normalize(frame, normalized, sizeof(normalized), + &normalized_bytes) || (is_grant && normalized_bytes != RESOURCE_X_PROOF_V1_BYTES) || (!is_grant && normalized_bytes != RESOURCE_X_IMAGE_V1_BYTES)) return RESOURCE_X_APPLY_INVALID; - if (!cluster_resource_x_wire_decode( - RESOURCE_X_MSG_IMAGE_OR_GRANT, normalized, normalized_bytes, - &normalized_frame, &reject) + if (!cluster_resource_x_wire_decode(RESOURCE_X_MSG_IMAGE_OR_GRANT, normalized, normalized_bytes, + &normalized_frame, &reject) || normalized_frame.kind != frame->kind || normalized_frame.common.sender_connection_generation - != PGRAC_RESOURCE_X_RETAINED_SENDER_GENERATION - || (!is_grant - && normalized_frame.common.semantic_crc32c == 0)) + != PGRAC_RESOURCE_X_RETAINED_SENDER_GENERATION + || (!is_grant && normalized_frame.common.semantic_crc32c == 0)) return RESOURCE_X_APPLY_INVALID; gate_formation = pg_atomic_read_u64(&ClusterPcm->resource_x_gate_formation); - if (pg_atomic_read_u32(&ClusterPcm->resource_x_gate_phase) - != RESOURCE_X_GATE_OPEN + if (pg_atomic_read_u32(&ClusterPcm->resource_x_gate_phase) != RESOURCE_X_GATE_OPEN || gate_formation != frame->common.resource_formation) return RESOURCE_X_APPLY_RECOVERY_BLOCKED; /* A retained grant/image is allowed to arrive before T1 creates the @@ -22686,20 +20871,16 @@ pcm_resource_x_requester_join_internal( goto requester_join_done; } } - if (final_authority_generation - <= entry->resource_x_requester_base_generation - && (ref_class == PCM_RX_REF_FUTURE_EMPTY - || ref_class == PCM_RX_REF_ACTIVE_EXACT)) { + if (final_authority_generation <= entry->resource_x_requester_base_generation + && (ref_class == PCM_RX_REF_FUTURE_EMPTY || ref_class == PCM_RX_REF_ACTIVE_EXACT)) { now_us = pcm_resource_x_monotonic_us(); live_round_base_exact = pcm_resource_x_requester_join_live_round_base_exact_locked( entry, effective_round, frame, authenticated_source_node, requester_target_generation, now_us, claim); } - if (ref_class == PCM_RX_REF_RETIRED_OLD - || ref_class == PCM_RX_REF_RETIRED_EXACT + if (ref_class == PCM_RX_REF_RETIRED_OLD || ref_class == PCM_RX_REF_RETIRED_EXACT || ref_class == PCM_RX_REF_ACTIVE_OTHER - || (final_authority_generation - <= entry->resource_x_requester_base_generation + || (final_authority_generation <= entry->resource_x_requester_base_generation && !live_round_base_exact)) { result = RESOURCE_X_APPLY_STALE; goto requester_join_done; @@ -22719,27 +20900,23 @@ pcm_resource_x_requester_join_internal( result = RESOURCE_X_APPLY_STALE; goto requester_join_done; } - if ((is_grant && join->grant_valid != 0) - || (!is_grant && join->image_valid != 0)) { - const uint8 *retained = is_grant - ? join->grant_payload : join->image_payload; - uint16 retained_bytes = is_grant - ? join->grant_payload_bytes : join->image_payload_bytes; + if ((is_grant && join->grant_valid != 0) || (!is_grant && join->image_valid != 0)) { + const uint8 *retained = is_grant ? join->grant_payload : join->image_payload; + uint16 retained_bytes = is_grant ? join->grant_payload_bytes : join->image_payload_bytes; result = retained_bytes == normalized_bytes - && memcmp(retained, normalized, normalized_bytes) == 0 - ? RESOURCE_X_APPLY_DUPLICATE : RESOURCE_X_APPLY_STALE; + && memcmp(retained, normalized, normalized_bytes) == 0 + ? RESOURCE_X_APPLY_DUPLICATE + : RESOURCE_X_APPLY_STALE; if (!pcm_resource_x_requester_join_snapshot_locked(join, out)) result = RESOURCE_X_APPLY_RECOVERY_BLOCKED; goto requester_join_done; } if ((is_grant && join->image_valid != 0 - && !pcm_resource_x_requester_join_pair_matches( - frame, &image, join->image_semantic_crc32c)) + && !pcm_resource_x_requester_join_pair_matches(frame, &image, join->image_semantic_crc32c)) || (!is_grant && join->grant_valid != 0 && !pcm_resource_x_requester_join_pair_matches( - &grant, &normalized_frame, - normalized_frame.common.semantic_crc32c))) { + &grant, &normalized_frame, normalized_frame.common.semantic_crc32c))) { (void)pcm_resource_x_requester_join_snapshot_locked(join, out); result = RESOURCE_X_APPLY_STALE; goto requester_join_done; @@ -22784,8 +20961,7 @@ pcm_resource_x_requester_join_internal( join->image_payload_bytes = normalized_bytes; join->image_source_node = authenticated_source_node; join->t_image_us = now_us; - join->image_semantic_crc32c - = normalized_frame.common.semantic_crc32c; + join->image_semantic_crc32c = normalized_frame.common.semantic_crc32c; join->image_valid = 1; } if (!pcm_resource_x_requester_join_snapshot_locked(join, out)) { @@ -22865,9 +21041,10 @@ cluster_pcm_lock_resource_x_requester_join_delivery_exact( } ResourceXApplyResult -cluster_pcm_lock_resource_x_requester_join_frames_exact( - const ResourceXAssertion *assertion, ResourceXDecodedFrame *grant_out, - ResourceXDecodedFrame *image_out, ResourceXRequesterJoinSnapshot *out) +cluster_pcm_lock_resource_x_requester_join_frames_exact(const ResourceXAssertion *assertion, + ResourceXDecodedFrame *grant_out, + ResourceXDecodedFrame *image_out, + ResourceXRequesterJoinSnapshot *out) { ClusterPcmResourceXMasterState *state; ClusterPcmResourceXRequesterJoin *join; @@ -22882,11 +21059,10 @@ cluster_pcm_lock_resource_x_requester_join_frames_exact( memset(image_out, 0, sizeof(*image_out)); if (out != NULL) memset(out, 0, sizeof(*out)); - if (!resource_x_assertion_valid(assertion) || grant_out == NULL - || image_out == NULL || out == NULL) + if (!resource_x_assertion_valid(assertion) || grant_out == NULL || image_out == NULL + || out == NULL) return RESOURCE_X_APPLY_INVALID; - if (!pcm_entry_ref_acquire(&assertion->resource, false, - &entry_ref, &acquire_result)) + if (!pcm_entry_ref_acquire(&assertion->resource, false, &entry_ref, &acquire_result)) return RESOURCE_X_APPLY_NOT_FOUND; entry = entry_ref.entry; LWLockAcquire(&entry->entry_lock.lock, LW_SHARED); @@ -22896,8 +21072,7 @@ cluster_pcm_lock_resource_x_requester_join_frames_exact( goto requester_join_frames_done; } join = &state->requester_join; - if (!pcm_resource_x_requester_join_decode_locked(join, grant_out, - image_out) + if (!pcm_resource_x_requester_join_decode_locked(join, grant_out, image_out) || !pcm_resource_x_requester_join_snapshot_locked(join, out)) { result = RESOURCE_X_APPLY_RECOVERY_BLOCKED; goto requester_join_frames_done; @@ -22925,10 +21100,10 @@ cluster_pcm_lock_resource_x_requester_join_frames_exact( } static ResourceXApplyResult -pcm_resource_x_build_authority_grant_locked( - struct GrdEntry *entry, const ClusterPcmResourceXMasterRequest *request, - int32 requester_node, uint64 final_authority_generation, - ResourceXDecodedFrame *out) +pcm_resource_x_build_authority_grant_locked(struct GrdEntry *entry, + const ClusterPcmResourceXMasterRequest *request, + int32 requester_node, uint64 final_authority_generation, + ResourceXDecodedFrame *out) { ResourceXDecodedAuthorityGrant *grant; uint64 requester_connection_generation; @@ -22939,26 +21114,20 @@ pcm_resource_x_build_authority_grant_locked( Assert(LWLockHeldByMeInMode(&entry->entry_lock.lock, LW_SHARED) || LWLockHeldByMeInMode(&entry->entry_lock.lock, LW_EXCLUSIVE)); memset(out, 0, sizeof(*out)); - requester_connection_generation - = request->requester_connection_generation != 0 - ? request->requester_connection_generation - : (uint64)request->sender_connection_generation; - if (final_authority_generation == 0 - || request->requester_target_generation == 0 - || requester_connection_generation == 0 - || request->proof_kind < RESOURCE_X_PROOF_KIND_MIN + requester_connection_generation = request->requester_connection_generation != 0 + ? request->requester_connection_generation + : (uint64)request->sender_connection_generation; + if (final_authority_generation == 0 || request->requester_target_generation == 0 + || requester_connection_generation == 0 || request->proof_kind < RESOURCE_X_PROOF_KIND_MIN || request->proof_kind > RESOURCE_X_PROOF_KIND_MAX || request->dependency_count > RESOURCE_X_DEPENDENCY_MAX || (request->proof_kind == RESOURCE_X_PROOF_REMOTE_CARRIER && (request->source_carrier_generation == 0 - || request->source_disposition - != RESOURCE_X_DISPOSITION_REMOTE_NONWRITABLE)) + || request->source_disposition != RESOURCE_X_DISPOSITION_REMOTE_NONWRITABLE)) || (request->proof_kind == RESOURCE_X_PROOF_LOCAL_IMAGE - && request->source_disposition - != RESOURCE_X_DISPOSITION_LOCAL_IMAGE) + && request->source_disposition != RESOURCE_X_DISPOSITION_LOCAL_IMAGE) || (request->proof_kind == RESOURCE_X_PROOF_DURABLE_STORAGE - && request->source_disposition - != RESOURCE_X_DISPOSITION_DURABLE_STORAGE)) + && request->source_disposition != RESOURCE_X_DISPOSITION_DURABLE_STORAGE)) return RESOURCE_X_APPLY_BAD_STATE; out->kind = RESOURCE_X_WIRE_AUTHORITY_GRANT; out->payload_bytes = RESOURCE_X_PROOF_V1_BYTES; @@ -22966,35 +21135,30 @@ pcm_resource_x_build_authority_grant_locked( out->common.logical_assertion.requester_node = requester_node; out->common.base_authority_generation = request->base_authority_generation; out->common.resource_formation = request->resource_formation; - out->common.master_session_incarnation - = request->master_session_incarnation; + out->common.master_session_incarnation = request->master_session_incarnation; out->common.assertion_sequence = request->assertion_sequence; out->common.ordered_lane = request->ordered_lane; out->common.action_node = requester_node; out->common.observed_mode = (uint8)PCM_STATE_N; out->common.target_mode = (uint8)PCM_STATE_X; - out->common.sender_connection_generation - = request->sender_connection_generation; + out->common.sender_connection_generation = request->sender_connection_generation; out->common.outcome = RESOURCE_X_OUTCOME_OK; if (request->proof_kind == RESOURCE_X_PROOF_REMOTE_CARRIER) out->common.flags = RESOURCE_X_COMMON_FLAG_REMOTE_IMAGE_REQUIRED; out->common.authority_generation = final_authority_generation; grant = &out->body.authority_grant; - memcpy(grant->source_fence, request->source_fence, - sizeof(grant->source_fence)); + memcpy(grant->source_fence, request->source_fence, sizeof(grant->source_fence)); grant->final_authority_generation = final_authority_generation; grant->source_carrier_generation = request->source_carrier_generation; grant->requester_target_generation = request->requester_target_generation; grant->page_scn_lsn = request->page_scn_lsn; grant->dependency_count = request->dependency_count; - memcpy(grant->dependencies, request->dependencies, - sizeof(grant->dependencies)); + memcpy(grant->dependencies, request->dependencies, sizeof(grant->dependencies)); grant->source_proof_crc32c = request->source_proof_crc32c; grant->page_checksum = request->page_checksum; grant->proof_kind = request->proof_kind; grant->source_disposition = request->source_disposition; - grant->requester_connection_generation - = requester_connection_generation; + grant->requester_connection_generation = requester_connection_generation; return RESOURCE_X_APPLY_APPLIED; } @@ -23004,9 +21168,10 @@ pcm_resource_x_build_authority_grant_locked( * copy has completed. This changes only the retained physical-send owner: * authority, request identity, attempt, formation and session remain fixed. */ static bool -pcm_resource_x_redrive_grant_intent_locked( - struct GrdEntry *entry, ClusterPcmResourceXMasterState *state, - ClusterPcmResourceXMasterRequest *request, int32 requester_node) +pcm_resource_x_redrive_grant_intent_locked(struct GrdEntry *entry, + ClusterPcmResourceXMasterState *state, + ClusterPcmResourceXMasterRequest *request, + int32 requester_node) { ClusterPcmResourceXControlIntent pending; ClusterPcmResourceXControlIntent *intent; @@ -23088,31 +21253,23 @@ pcm_resource_x_redrive_grant_intent_locked( cluster_pcm_rx_metric_note(PCM_RX_DELIVERY_SOURCE_REDRIVE); return true; } - if (requester_node < 0 - || requester_node >= RESOURCE_X_PROTOCOL_NODE_LIMIT - || cluster_node_id < 0 - || cluster_node_id >= RESOURCE_X_PROTOCOL_NODE_LIMIT - || request->phase != RESOURCE_X_MASTER_GRANT_COMMITTED - || request->assertion_sequence == 0 - || request->assertion_sequence == UINT64_MAX - || request->final_authority_generation == 0 + if (requester_node < 0 || requester_node >= RESOURCE_X_PROTOCOL_NODE_LIMIT + || cluster_node_id < 0 || cluster_node_id >= RESOURCE_X_PROTOCOL_NODE_LIMIT + || request->phase != RESOURCE_X_MASTER_GRANT_COMMITTED || request->assertion_sequence == 0 + || request->assertion_sequence == UINT64_MAX || request->final_authority_generation == 0 || request->final_authority_generation == UINT64_MAX - || state->authority_generation - != request->final_authority_generation - || (PcmState)pg_atomic_read_u32(&entry->master_state) - != PCM_STATE_X + || state->authority_generation != request->final_authority_generation + || (PcmState)pg_atomic_read_u32(&entry->master_state) != PCM_STATE_X || entry->x_holder_node != requester_node || pg_atomic_read_u32(&entry->s_holders_bitmap) != 0 - || pcm_resource_x_build_authority_grant_locked( - entry, request, requester_node, - request->final_authority_generation, &grant) - != RESOURCE_X_APPLY_APPLIED) + || pcm_resource_x_build_authority_grant_locked(entry, request, requester_node, + request->final_authority_generation, &grant) + != RESOURCE_X_APPLY_APPLIED) return false; memset(&pending, 0, sizeof(pending)); - if (!cluster_resource_x_wire_encode( - RESOURCE_X_MSG_IMAGE_OR_GRANT, &grant, pending.payload, - sizeof(pending.payload), &payload_len, &reject) + if (!cluster_resource_x_wire_encode(RESOURCE_X_MSG_IMAGE_OR_GRANT, &grant, pending.payload, + sizeof(pending.payload), &payload_len, &reject) || payload_len != RESOURCE_X_PROOF_V1_BYTES) return false; memset(&body, 0, sizeof(body)); @@ -23124,23 +21281,19 @@ pcm_resource_x_redrive_grant_intent_locked( if (intent->slot.state != RESOURCE_X_INTENT_SLOT_EMPTY) return (intent->slot.state == RESOURCE_X_INTENT_SLOT_ARMED || intent->slot.state == RESOURCE_X_INTENT_SLOT_STAGED) - && intent->slot.logical_generation - == request->assertion_sequence - && intent->slot.authority_generation - == request->final_authority_generation - && intent->slot.destination_node == (uint32)requester_node - && intent->slot.payload_bytes == payload_len - && intent->slot.kind == RESOURCE_X_WIRE_AUTHORITY_GRANT - && memcmp(&intent->slot.body, &body, sizeof(body)) == 0 - && memcmp(intent->payload, pending.payload, payload_len) == 0; + && intent->slot.logical_generation == request->assertion_sequence + && intent->slot.authority_generation == request->final_authority_generation + && intent->slot.destination_node == (uint32)requester_node + && intent->slot.payload_bytes == payload_len + && intent->slot.kind == RESOURCE_X_WIRE_AUTHORITY_GRANT + && memcmp(&intent->slot.body, &body, sizeof(body)) == 0 + && memcmp(intent->payload, pending.payload, payload_len) == 0; now_us = pcm_resource_x_monotonic_us(); if (now_us == 0 || now_us == UINT64_MAX || !cluster_pcm_lock_resource_x_intent_arm_exact( - &pending.slot, &body, request->assertion_sequence, - request->final_authority_generation, now_us, - (uint32)requester_node, payload_len, - RESOURCE_X_WIRE_AUTHORITY_GRANT) + &pending.slot, &body, request->assertion_sequence, request->final_authority_generation, + now_us, (uint32)requester_node, payload_len, RESOURCE_X_WIRE_AUTHORITY_GRANT) || !pcm_resource_x_intent_mark_dirty()) return false; *intent = pending; @@ -23148,10 +21301,8 @@ pcm_resource_x_redrive_grant_intent_locked( } static ResourceXApplyResult -pcm_resource_x_commit_grant_locked(struct GrdEntry *entry, - ClusterPcmResourceXMasterState *state, - ClusterPcmResourceXMasterRequest *request, - int32 requester_node) +pcm_resource_x_commit_grant_locked(struct GrdEntry *entry, ClusterPcmResourceXMasterState *state, + ClusterPcmResourceXMasterRequest *request, int32 requester_node) { ResourceXDecodedFrame grant; ResourceXIntentBodyHandle body; @@ -23176,8 +21327,7 @@ pcm_resource_x_commit_grant_locked(struct GrdEntry *entry, Assert(LWLockHeldByMeInMode(&entry->entry_lock.lock, LW_EXCLUSIVE)); current_state = (PcmState)pg_atomic_read_u32(&entry->master_state); s_holders = pg_atomic_read_u32(&entry->s_holders_bitmap); - current_transition_generation - = pg_atomic_read_u64(&entry->transition_count_local); + current_transition_generation = pg_atomic_read_u64(&entry->transition_count_local); expected_transition_generation = 0; if (request->proof_kind < RESOURCE_X_PROOF_KIND_MIN || request->proof_kind > RESOURCE_X_PROOF_KIND_MAX) @@ -23188,12 +21338,10 @@ pcm_resource_x_commit_grant_locked(struct GrdEntry *entry, request->phase = RESOURCE_X_MASTER_RECOVERY_BLOCKED; return RESOURCE_X_APPLY_RECOVERY_BLOCKED; } - } else if (current_state == PCM_STATE_S - && entry->x_holder_node == -1 + } else if (current_state == PCM_STATE_S && entry->x_holder_node == -1 && s_holders == requester_bit) transition = PCM_TRANS_S_TO_X_UPGRADE; - else if (current_state == PCM_STATE_X - && entry->x_holder_node == requester_node + else if (current_state == PCM_STATE_X && entry->x_holder_node == requester_node && s_holders == 0) transition_needed = false; else { @@ -23211,21 +21359,15 @@ pcm_resource_x_commit_grant_locked(struct GrdEntry *entry, blocker_count++; } if (request->head_transition_generation == UINT64_MAX - || request->head_transition_generation - > UINT64_MAX - blocker_count) { + || request->head_transition_generation > UINT64_MAX - blocker_count) { request->phase = RESOURCE_X_MASTER_RECOVERY_BLOCKED; return RESOURCE_X_APPLY_RECOVERY_BLOCKED; } - expected_transition_generation - = request->head_transition_generation + blocker_count; - if (state->authority_generation == UINT64_MAX - || current_transition_generation == UINT64_MAX - || state->authority_generation - != request->base_authority_generation - || request->base_authority_generation - > UINT64_MAX - blocker_count - || current_transition_generation - != expected_transition_generation) { + expected_transition_generation = request->head_transition_generation + blocker_count; + if (state->authority_generation == UINT64_MAX || current_transition_generation == UINT64_MAX + || state->authority_generation != request->base_authority_generation + || request->base_authority_generation > UINT64_MAX - blocker_count + || current_transition_generation != expected_transition_generation) { request->phase = RESOURCE_X_MASTER_RECOVERY_BLOCKED; return RESOURCE_X_APPLY_RECOVERY_BLOCKED; } @@ -23235,14 +21377,12 @@ pcm_resource_x_commit_grant_locked(struct GrdEntry *entry, * count after the legacy counter has passed the floor/ceiling check above. * Taking Max(base, legacy) loses the pristine-N one-step origin offset when * the two axes become equal after X->N. */ - generation_frontier - = state->authority_generation + blocker_count; + generation_frontier = state->authority_generation + blocker_count; if (generation_frontier >= UINT64_MAX - 1) { request->phase = RESOURCE_X_MASTER_RECOVERY_BLOCKED; return RESOURCE_X_APPLY_RECOVERY_BLOCKED; } - if (state->grant_intent.slot.state != RESOURCE_X_INTENT_SLOT_EMPTY - || cluster_node_id < 0 + if (state->grant_intent.slot.state != RESOURCE_X_INTENT_SLOT_EMPTY || cluster_node_id < 0 || cluster_node_id >= RESOURCE_X_PROTOCOL_NODE_LIMIT) { request->phase = RESOURCE_X_MASTER_RECOVERY_BLOCKED; return RESOURCE_X_APPLY_RECOVERY_BLOCKED; @@ -23264,18 +21404,17 @@ pcm_resource_x_commit_grant_locked(struct GrdEntry *entry, request->phase = RESOURCE_X_MASTER_RECOVERY_BLOCKED; return RESOURCE_X_APPLY_RECOVERY_BLOCKED; } - build_result = pcm_resource_x_build_authority_grant_locked( - entry, request, requester_node, final_authority_generation, &grant); + build_result = pcm_resource_x_build_authority_grant_locked(entry, request, requester_node, + final_authority_generation, &grant); if (build_result != RESOURCE_X_APPLY_APPLIED || !cluster_resource_x_wire_encode( - RESOURCE_X_MSG_IMAGE_OR_GRANT, &grant, - state->grant_intent.payload, sizeof(state->grant_intent.payload), - &payload_len, &reject) + RESOURCE_X_MSG_IMAGE_OR_GRANT, &grant, state->grant_intent.payload, + sizeof(state->grant_intent.payload), &payload_len, &reject) || payload_len != RESOURCE_X_PROOF_V1_BYTES) { memset(&state->grant_intent, 0, sizeof(state->grant_intent)); request->phase = RESOURCE_X_MASTER_RECOVERY_BLOCKED; - return build_result == RESOURCE_X_APPLY_APPLIED - ? RESOURCE_X_APPLY_RECOVERY_BLOCKED : build_result; + return build_result == RESOURCE_X_APPLY_APPLIED ? RESOURCE_X_APPLY_RECOVERY_BLOCKED + : build_result; } memset(&body, 0, sizeof(body)); body.assertion = grant.common.logical_assertion; @@ -23285,8 +21424,8 @@ pcm_resource_x_commit_grant_locked(struct GrdEntry *entry, now_us = pcm_resource_x_monotonic_us(); if (!cluster_pcm_lock_resource_x_intent_arm_exact( &state->grant_intent.slot, &body, request->assertion_sequence, - final_authority_generation, now_us, (uint32)requester_node, - payload_len, RESOURCE_X_WIRE_AUTHORITY_GRANT) + final_authority_generation, now_us, (uint32)requester_node, payload_len, + RESOURCE_X_WIRE_AUTHORITY_GRANT) || !pcm_resource_x_intent_mark_dirty()) { memset(&state->grant_intent, 0, sizeof(state->grant_intent)); request->phase = RESOURCE_X_MASTER_RECOVERY_BLOCKED; @@ -23308,11 +21447,11 @@ pcm_resource_x_commit_grant_locked(struct GrdEntry *entry, * one state-producing edge gives type-18 ingress a single mutation boundary: * removing the edge leaves both the holder and queue unchanged. */ static ResourceXApplyResult -pcm_resource_x_apply_blocked_holder_locked( - struct GrdEntry *entry, ClusterPcmResourceXMasterState *state, - ClusterPcmResourceXMasterRequest *request, int32 requester_node, - int32 authenticated_source_node, uint32 source_bit, bool is_x_source, - bool *broadcast) +pcm_resource_x_apply_blocked_holder_locked(struct GrdEntry *entry, + ClusterPcmResourceXMasterState *state, + ClusterPcmResourceXMasterRequest *request, + int32 requester_node, int32 authenticated_source_node, + uint32 source_bit, bool is_x_source, bool *broadcast) { static const ClusterPcmResourceXMasterRequest empty_request; ClusterPcmResourceXMasterRequest *source_request = NULL; @@ -23329,42 +21468,36 @@ pcm_resource_x_apply_blocked_holder_locked( source_request = &state->requests[authenticated_source_node]; if (source_request->phase == RESOURCE_X_MASTER_NONE) { /* Bootstrap legacy X has no prior Resource-X requester record. */ - if (memcmp(source_request, &empty_request, - sizeof(*source_request)) != 0) { + if (memcmp(source_request, &empty_request, sizeof(*source_request)) != 0) { request->phase = RESOURCE_X_MASTER_RECOVERY_BLOCKED; return RESOURCE_X_APPLY_RECOVERY_BLOCKED; } } else if ((source_request->phase == RESOURCE_X_MASTER_SETTLED || source_request->phase == RESOURCE_X_MASTER_RELEASED) && source_request != request - && source_request->resource_formation - == request->resource_formation + && source_request->resource_formation == request->resource_formation && source_request->master_session_incarnation - == request->master_session_incarnation + == request->master_session_incarnation && source_request->final_authority_generation - == request->base_authority_generation) - release_source_request - = source_request->phase == RESOURCE_X_MASTER_SETTLED; + == request->base_authority_generation) + release_source_request = source_request->phase == RESOURCE_X_MASTER_SETTLED; else { request->phase = RESOURCE_X_MASTER_RECOVERY_BLOCKED; return RESOURCE_X_APPLY_RECOVERY_BLOCKED; } - cluster_pcm_transition_apply(entry, PCM_TRANS_X_TO_N_DOWNGRADE, - authenticated_source_node); + cluster_pcm_transition_apply(entry, PCM_TRANS_X_TO_N_DOWNGRADE, authenticated_source_node); /* The authenticated type-18 is the exact physical terminal edge for * the old current X requester. Retire that direct record with the same * entry lock; historical PI bits never participate in this decision. */ if (release_source_request) source_request->phase = RESOURCE_X_MASTER_RELEASED; } else if ((pg_atomic_read_u32(&entry->s_holders_bitmap) & source_bit) != 0) - cluster_pcm_transition_apply(entry, PCM_TRANS_S_TO_N_INVALIDATE, - authenticated_source_node); + cluster_pcm_transition_apply(entry, PCM_TRANS_S_TO_N_INVALIDATE, authenticated_source_node); request->blocked_holders_bitmap |= source_bit; if (request->blocked_holders_bitmap == request->incompatible_holders_bitmap) { if (request->proof_kind == RESOURCE_X_PROOF_REMOTE_CARRIER) { ResourceXApplyResult commit_result - = pcm_resource_x_commit_grant_locked(entry, state, request, - requester_node); + = pcm_resource_x_commit_grant_locked(entry, state, request, requester_node); *broadcast = commit_result == RESOURCE_X_APPLY_APPLIED; if (*broadcast && state->deferred_settlement.present != 0 @@ -23377,26 +21510,25 @@ pcm_resource_x_apply_blocked_holder_locked( } else if (!pcm_resource_x_arm_block_intents_locked(entry, state, request, requester_node)) { request->phase = RESOURCE_X_MASTER_RECOVERY_BLOCKED; } - return request->phase == RESOURCE_X_MASTER_RECOVERY_BLOCKED - ? RESOURCE_X_APPLY_RECOVERY_BLOCKED : RESOURCE_X_APPLY_APPLIED; + return request->phase == RESOURCE_X_MASTER_RECOVERY_BLOCKED ? RESOURCE_X_APPLY_RECOVERY_BLOCKED + : RESOURCE_X_APPLY_APPLIED; } static bool -pcm_resource_x_post_grant_blocker_state_exact( - const ClusterPcmResourceXMasterRequest *request, uint32 source_bit) +pcm_resource_x_post_grant_blocker_state_exact(const ClusterPcmResourceXMasterRequest *request, + uint32 source_bit) { Assert(request != NULL); Assert(request->phase == RESOURCE_X_MASTER_GRANT_COMMITTED); - return request->blocked_holders_bitmap - == request->incompatible_holders_bitmap - && (request->blocked_holders_bitmap & source_bit) != 0; + return request->blocked_holders_bitmap == request->incompatible_holders_bitmap + && (request->blocked_holders_bitmap & source_bit) != 0; } ResourceXApplyResult cluster_pcm_lock_resource_x_blocked_to_n_exact(const ResourceXDecodedFrame *blocked, - int32 authenticated_source_node, - ResourceXMasterSnapshot *out) + int32 authenticated_source_node, + ResourceXMasterSnapshot *out) { ClusterPcmResourceXMasterState *state; ClusterPcmResourceXMasterRequest *request; @@ -23415,8 +21547,7 @@ cluster_pcm_lock_resource_x_blocked_to_n_exact(const ResourceXDecodedFrame *bloc memset(out, 0, sizeof(*out)); out->source_node = -1; } - if (out == NULL || blocked == NULL - || blocked->kind != RESOURCE_X_WIRE_BLOCKED_TO_N + if (out == NULL || blocked == NULL || blocked->kind != RESOURCE_X_WIRE_BLOCKED_TO_N || !resource_x_assertion_valid(&blocked->common.logical_assertion) || authenticated_source_node < 0 || authenticated_source_node >= RESOURCE_X_PROTOCOL_NODE_LIMIT @@ -23424,8 +21555,8 @@ cluster_pcm_lock_resource_x_blocked_to_n_exact(const ResourceXDecodedFrame *bloc || blocked->common.outcome == RESOURCE_X_OUTCOME_NONE || blocked->common.resource_formation == 0) return RESOURCE_X_APPLY_INVALID; - if (!pcm_entry_ref_acquire(&blocked->common.logical_assertion.resource, - false, &entry_ref, &acquire_result)) + if (!pcm_entry_ref_acquire(&blocked->common.logical_assertion.resource, false, &entry_ref, + &acquire_result)) return RESOURCE_X_APPLY_NOT_FOUND; entry = entry_ref.entry; requester_node = blocked->common.logical_assertion.requester_node; @@ -23444,16 +21575,12 @@ cluster_pcm_lock_resource_x_blocked_to_n_exact(const ResourceXDecodedFrame *bloc return RESOURCE_X_APPLY_NOT_FOUND; } if (head_node != requester_node - || blocked->common.base_authority_generation - != request->base_authority_generation + || blocked->common.base_authority_generation != request->base_authority_generation || blocked->common.resource_formation != request->resource_formation - || blocked->common.master_session_incarnation - != request->master_session_incarnation + || blocked->common.master_session_incarnation != request->master_session_incarnation || blocked->common.assertion_sequence != request->assertion_sequence - || blocked->common.authority_generation - != request->base_authority_generation) { - pcm_resource_x_master_snapshot(&entry->tag, requester_node, state, - request, out); + || blocked->common.authority_generation != request->base_authority_generation) { + pcm_resource_x_master_snapshot(&entry->tag, requester_node, state, request, out); LWLockRelease(&entry->entry_lock.lock); pcm_entry_ref_release(&entry_ref); return RESOURCE_X_APPLY_STALE; @@ -23462,18 +21589,15 @@ cluster_pcm_lock_resource_x_blocked_to_n_exact(const ResourceXDecodedFrame *bloc if ((request->incompatible_holders_bitmap & source_bit) == 0 || (request->phase != RESOURCE_X_MASTER_WAIT_BLOCKERS && request->phase != RESOURCE_X_MASTER_GRANT_COMMITTED)) { - pcm_resource_x_master_snapshot(&entry->tag, requester_node, state, - request, out); + pcm_resource_x_master_snapshot(&entry->tag, requester_node, state, request, out); LWLockRelease(&entry->entry_lock.lock); pcm_entry_ref_release(&entry_ref); return RESOURCE_X_APPLY_BAD_STATE; } if (request->phase == RESOURCE_X_MASTER_GRANT_COMMITTED - && !pcm_resource_x_post_grant_blocker_state_exact(request, - source_bit)) { + && !pcm_resource_x_post_grant_blocker_state_exact(request, source_bit)) { request->phase = RESOURCE_X_MASTER_RECOVERY_BLOCKED; - pcm_resource_x_master_snapshot(&entry->tag, requester_node, state, - request, out); + pcm_resource_x_master_snapshot(&entry->tag, requester_node, state, request, out); LWLockRelease(&entry->entry_lock.lock); pcm_entry_ref_release(&entry_ref); return RESOURCE_X_APPLY_RECOVERY_BLOCKED; @@ -23483,60 +21607,54 @@ cluster_pcm_lock_resource_x_blocked_to_n_exact(const ResourceXDecodedFrame *bloc if (!blocked->blocked_has_remote_proof) result = request->source_node != authenticated_source_node - && blocked->common.observed_mode == (uint8)PCM_STATE_S - && blocked->common.target_mode == (uint8)PCM_STATE_N - ? RESOURCE_X_APPLY_DUPLICATE : RESOURCE_X_APPLY_STALE; + && blocked->common.observed_mode == (uint8)PCM_STATE_S + && blocked->common.target_mode == (uint8)PCM_STATE_N + ? RESOURCE_X_APPLY_DUPLICATE + : RESOURCE_X_APPLY_STALE; else result = request->proof_kind == RESOURCE_X_PROOF_REMOTE_CARRIER - && pcm_resource_x_remote_proof_valid(blocked) - && request->source_node == authenticated_source_node - && (blocked->common.observed_mode == (uint8)PCM_STATE_X - || blocked->common.observed_mode == (uint8)PCM_STATE_S) - && request->source_carrier_generation - == blocked->body.blocked_to_n.source_carrier_generation - && request->requester_target_generation - == blocked->body.blocked_to_n.requester_target_generation - && request->page_scn_lsn - == blocked->body.blocked_to_n.page_scn_lsn - && request->dependency_count - == blocked->body.blocked_to_n.dependency_count - && request->proof_flags - == blocked->body.blocked_to_n.proof_flags - && request->source_proof_crc32c - == blocked->body.blocked_to_n.source_proof_crc32c - && request->page_checksum - == blocked->body.blocked_to_n.page_checksum - && request->holder_connection_generation - == blocked->body.blocked_to_n.holder_connection_generation - && request->acting_formation - == blocked->body.blocked_to_n.acting_formation - && memcmp(request->source_fence, - blocked->body.blocked_to_n.source_fence, - sizeof(request->source_fence)) == 0 - && memcmp(request->dependencies, - blocked->body.blocked_to_n.dependencies, - sizeof(request->dependencies)) == 0 - ? RESOURCE_X_APPLY_DUPLICATE : RESOURCE_X_APPLY_STALE; - - pcm_resource_x_master_snapshot(&entry->tag, requester_node, state, - request, out); + && pcm_resource_x_remote_proof_valid(blocked) + && request->source_node == authenticated_source_node + && (blocked->common.observed_mode == (uint8)PCM_STATE_X + || blocked->common.observed_mode == (uint8)PCM_STATE_S) + && request->source_carrier_generation + == blocked->body.blocked_to_n.source_carrier_generation + && request->requester_target_generation + == blocked->body.blocked_to_n.requester_target_generation + && request->page_scn_lsn == blocked->body.blocked_to_n.page_scn_lsn + && request->dependency_count + == blocked->body.blocked_to_n.dependency_count + && request->proof_flags == blocked->body.blocked_to_n.proof_flags + && request->source_proof_crc32c + == blocked->body.blocked_to_n.source_proof_crc32c + && request->page_checksum == blocked->body.blocked_to_n.page_checksum + && request->holder_connection_generation + == blocked->body.blocked_to_n.holder_connection_generation + && request->acting_formation + == blocked->body.blocked_to_n.acting_formation + && memcmp(request->source_fence, blocked->body.blocked_to_n.source_fence, + sizeof(request->source_fence)) + == 0 + && memcmp(request->dependencies, blocked->body.blocked_to_n.dependencies, + sizeof(request->dependencies)) + == 0 + ? RESOURCE_X_APPLY_DUPLICATE + : RESOURCE_X_APPLY_STALE; + + pcm_resource_x_master_snapshot(&entry->tag, requester_node, state, request, out); LWLockRelease(&entry->entry_lock.lock); pcm_entry_ref_release(&entry_ref); return result; } - direct_x_source - = (PcmState)pg_atomic_read_u32(&entry->master_state) == PCM_STATE_X - && entry->x_holder_node == authenticated_source_node; - selected_s_source - = request->source_node == authenticated_source_node - && (PcmState)pg_atomic_read_u32(&entry->master_state) == PCM_STATE_S - && (pg_atomic_read_u32(&entry->s_holders_bitmap) & source_bit) != 0 - && blocked->common.observed_mode == (uint8)PCM_STATE_S; - if (blocked->blocked_has_remote_proof - && !direct_x_source && !selected_s_source) { - pcm_resource_x_master_snapshot(&entry->tag, requester_node, state, - request, out); + direct_x_source = (PcmState)pg_atomic_read_u32(&entry->master_state) == PCM_STATE_X + && entry->x_holder_node == authenticated_source_node; + selected_s_source = request->source_node == authenticated_source_node + && (PcmState)pg_atomic_read_u32(&entry->master_state) == PCM_STATE_S + && (pg_atomic_read_u32(&entry->s_holders_bitmap) & source_bit) != 0 + && blocked->common.observed_mode == (uint8)PCM_STATE_S; + if (blocked->blocked_has_remote_proof && !direct_x_source && !selected_s_source) { + pcm_resource_x_master_snapshot(&entry->tag, requester_node, state, request, out); LWLockRelease(&entry->entry_lock.lock); pcm_entry_ref_release(&entry_ref); return RESOURCE_X_APPLY_BAD_STATE; @@ -23549,8 +21667,7 @@ cluster_pcm_lock_resource_x_blocked_to_n_exact(const ResourceXDecodedFrame *bloc || !pcm_resource_x_remote_proof_valid(blocked) || blocked->common.observed_mode != (uint8)(direct_x_source ? PCM_STATE_X : PCM_STATE_S) || blocked->common.target_mode != (uint8)PCM_STATE_N)) { - pcm_resource_x_master_snapshot(&entry->tag, requester_node, state, - request, out); + pcm_resource_x_master_snapshot(&entry->tag, requester_node, state, request, out); LWLockRelease(&entry->entry_lock.lock); pcm_entry_ref_release(&entry_ref); return RESOURCE_X_APPLY_BAD_STATE; @@ -23559,16 +21676,14 @@ cluster_pcm_lock_resource_x_blocked_to_n_exact(const ResourceXDecodedFrame *bloc && (request->source_node == authenticated_source_node || blocked->common.observed_mode != (uint8)PCM_STATE_S || blocked->common.target_mode != (uint8)PCM_STATE_N)) { - pcm_resource_x_master_snapshot(&entry->tag, requester_node, state, - request, out); + pcm_resource_x_master_snapshot(&entry->tag, requester_node, state, request, out); LWLockRelease(&entry->entry_lock.lock); pcm_entry_ref_release(&entry_ref); return RESOURCE_X_APPLY_BAD_STATE; } if (blocked->blocked_has_remote_proof) { if (!pcm_resource_x_remote_proof_valid(blocked)) { - pcm_resource_x_master_snapshot(&entry->tag, requester_node, state, - request, out); + pcm_resource_x_master_snapshot(&entry->tag, requester_node, state, request, out); LWLockRelease(&entry->entry_lock.lock); pcm_entry_ref_release(&entry_ref); return RESOURCE_X_APPLY_INVALID; @@ -23581,24 +21696,19 @@ cluster_pcm_lock_resource_x_blocked_to_n_exact(const ResourceXDecodedFrame *bloc return RESOURCE_X_APPLY_RECOVERY_BLOCKED; } request->proof_kind = RESOURCE_X_PROOF_REMOTE_CARRIER; - request->source_disposition - = RESOURCE_X_DISPOSITION_REMOTE_NONWRITABLE; + request->source_disposition = RESOURCE_X_DISPOSITION_REMOTE_NONWRITABLE; if (direct_x_source) request->source_node = authenticated_source_node; - memcpy(request->source_fence, - blocked->body.blocked_to_n.source_fence, + memcpy(request->source_fence, blocked->body.blocked_to_n.source_fence, sizeof(request->source_fence)); - request->source_carrier_generation - = blocked->body.blocked_to_n.source_carrier_generation; + request->source_carrier_generation = blocked->body.blocked_to_n.source_carrier_generation; request->requester_target_generation = blocked->body.blocked_to_n.requester_target_generation; request->page_scn_lsn = blocked->body.blocked_to_n.page_scn_lsn; - request->dependency_count - = blocked->body.blocked_to_n.dependency_count; + request->dependency_count = blocked->body.blocked_to_n.dependency_count; memcpy(request->dependencies, blocked->body.blocked_to_n.dependencies, sizeof(request->dependencies)); - request->source_proof_crc32c - = blocked->body.blocked_to_n.source_proof_crc32c; + request->source_proof_crc32c = blocked->body.blocked_to_n.source_proof_crc32c; request->page_checksum = blocked->body.blocked_to_n.page_checksum; request->holder_connection_generation = blocked->body.blocked_to_n.holder_connection_generation; @@ -23606,9 +21716,9 @@ cluster_pcm_lock_resource_x_blocked_to_n_exact(const ResourceXDecodedFrame *bloc request->proof_flags = blocked->body.blocked_to_n.proof_flags; } - result = pcm_resource_x_apply_blocked_holder_locked( - entry, state, request, requester_node, authenticated_source_node, - source_bit, direct_x_source, &broadcast); + result = pcm_resource_x_apply_blocked_holder_locked(entry, state, request, requester_node, + authenticated_source_node, source_bit, + direct_x_source, &broadcast); pcm_resource_x_master_snapshot(&entry->tag, requester_node, state, request, out); LWLockRelease(&entry->entry_lock.lock); if (broadcast) @@ -23619,15 +21729,13 @@ cluster_pcm_lock_resource_x_blocked_to_n_exact(const ResourceXDecodedFrame *bloc static bool pcm_resource_x_common_matches_request(const ResourceXDecodedCommon *common, - const ClusterPcmResourceXMasterRequest *request) + const ClusterPcmResourceXMasterRequest *request) { - return common->base_authority_generation - == request->base_authority_generation - && common->authority_generation == request->base_authority_generation - && common->resource_formation == request->resource_formation - && common->master_session_incarnation - == request->master_session_incarnation - && common->assertion_sequence == request->assertion_sequence; + return common->base_authority_generation == request->base_authority_generation + && common->authority_generation == request->base_authority_generation + && common->resource_formation == request->resource_formation + && common->master_session_incarnation == request->master_session_incarnation + && common->assertion_sequence == request->assertion_sequence; } ResourceXApplyResult @@ -23653,21 +21761,18 @@ cluster_pcm_lock_resource_x_local_proof_exact(const ResourceXDecodedFrame *local if (out == NULL || local_proof == NULL || local_proof->kind != RESOURCE_X_WIRE_LOCAL_PROOF_DECLARATION || !resource_x_assertion_valid(&local_proof->common.logical_assertion) - || authenticated_source_node - != local_proof->common.logical_assertion.requester_node + || authenticated_source_node != local_proof->common.logical_assertion.requester_node || local_proof->common.action_node != authenticated_source_node || local_proof->common.outcome == RESOURCE_X_OUTCOME_NONE || local_proof->common.target_mode != (uint8)PCM_STATE_X) return RESOURCE_X_APPLY_INVALID; proof = &local_proof->body.local_proof; - if (proof->local_holder_authority_generation == 0 - || proof->requester_target_generation == 0 + if (proof->local_holder_authority_generation == 0 || proof->requester_target_generation == 0 || proof->dependency_count > RESOURCE_X_DEPENDENCY_MAX - || proof->requester_connection_generation == 0 - || proof->local_proof_generation == 0) + || proof->requester_connection_generation == 0 || proof->local_proof_generation == 0) return RESOURCE_X_APPLY_INVALID; - if (!pcm_entry_ref_acquire(&local_proof->common.logical_assertion.resource, - false, &entry_ref, &acquire_result)) + if (!pcm_entry_ref_acquire(&local_proof->common.logical_assertion.resource, false, &entry_ref, + &acquire_result)) return RESOURCE_X_APPLY_NOT_FOUND; entry = entry_ref.entry; requester_node = local_proof->common.logical_assertion.requester_node; @@ -23687,41 +21792,35 @@ cluster_pcm_lock_resource_x_local_proof_exact(const ResourceXDecodedFrame *local } if (head_node != requester_node || !pcm_resource_x_common_matches_request(&local_proof->common, request)) { - pcm_resource_x_master_snapshot(&entry->tag, requester_node, state, - request, out); + pcm_resource_x_master_snapshot(&entry->tag, requester_node, state, request, out); LWLockRelease(&entry->entry_lock.lock); pcm_entry_ref_release(&entry_ref); return RESOURCE_X_APPLY_STALE; } if (request->phase == RESOURCE_X_MASTER_GRANT_COMMITTED) { - result = request->proof_kind == RESOURCE_X_PROOF_LOCAL_IMAGE - && request->local_holder_authority_generation - == proof->local_holder_authority_generation - && request->requester_target_generation - == proof->requester_target_generation - && request->page_scn_lsn == proof->page_scn_lsn - && request->dependency_count == proof->dependency_count - && request->dependency_vector_crc32c - == proof->dependency_vector_crc32c - && request->page_checksum == proof->page_checksum - && request->source_proof_crc32c - == proof->local_image_proof_crc32c - && request->requester_connection_generation - == proof->requester_connection_generation - && request->local_proof_generation - == proof->local_proof_generation - ? RESOURCE_X_APPLY_DUPLICATE : RESOURCE_X_APPLY_STALE; - pcm_resource_x_master_snapshot(&entry->tag, requester_node, state, - request, out); + result + = request->proof_kind == RESOURCE_X_PROOF_LOCAL_IMAGE + && request->local_holder_authority_generation + == proof->local_holder_authority_generation + && request->requester_target_generation == proof->requester_target_generation + && request->page_scn_lsn == proof->page_scn_lsn + && request->dependency_count == proof->dependency_count + && request->dependency_vector_crc32c == proof->dependency_vector_crc32c + && request->page_checksum == proof->page_checksum + && request->source_proof_crc32c == proof->local_image_proof_crc32c + && request->requester_connection_generation + == proof->requester_connection_generation + && request->local_proof_generation == proof->local_proof_generation + ? RESOURCE_X_APPLY_DUPLICATE + : RESOURCE_X_APPLY_STALE; + pcm_resource_x_master_snapshot(&entry->tag, requester_node, state, request, out); LWLockRelease(&entry->entry_lock.lock); pcm_entry_ref_release(&entry_ref); return result; } if (request->phase != RESOURCE_X_MASTER_WAIT_PROOF - || request->incompatible_holders_bitmap - != request->blocked_holders_bitmap) { - pcm_resource_x_master_snapshot(&entry->tag, requester_node, state, - request, out); + || request->incompatible_holders_bitmap != request->blocked_holders_bitmap) { + pcm_resource_x_master_snapshot(&entry->tag, requester_node, state, request, out); LWLockRelease(&entry->entry_lock.lock); pcm_entry_ref_release(&entry_ref); return RESOURCE_X_APPLY_BAD_STATE; @@ -23729,19 +21828,16 @@ cluster_pcm_lock_resource_x_local_proof_exact(const ResourceXDecodedFrame *local request->proof_kind = RESOURCE_X_PROOF_LOCAL_IMAGE; request->source_disposition = RESOURCE_X_DISPOSITION_LOCAL_IMAGE; request->source_node = requester_node; - request->local_holder_authority_generation - = proof->local_holder_authority_generation; + request->local_holder_authority_generation = proof->local_holder_authority_generation; request->requester_target_generation = proof->requester_target_generation; request->page_scn_lsn = proof->page_scn_lsn; request->dependency_count = proof->dependency_count; request->dependency_vector_crc32c = proof->dependency_vector_crc32c; request->page_checksum = proof->page_checksum; request->source_proof_crc32c = proof->local_image_proof_crc32c; - request->requester_connection_generation - = proof->requester_connection_generation; + request->requester_connection_generation = proof->requester_connection_generation; request->local_proof_generation = proof->local_proof_generation; - result = pcm_resource_x_commit_grant_locked(entry, state, request, - requester_node); + result = pcm_resource_x_commit_grant_locked(entry, state, request, requester_node); broadcast = result == RESOURCE_X_APPLY_APPLIED; pcm_resource_x_master_snapshot(&entry->tag, requester_node, state, request, out); LWLockRelease(&entry->entry_lock.lock); @@ -23771,14 +21867,12 @@ cluster_pcm_lock_resource_x_durable_proof_exact(const ResourceXDurableProof *dur } if (out == NULL || durable_proof == NULL || !resource_x_assertion_valid(&durable_proof->assertion) - || durable_proof->base_authority_generation == 0 - || durable_proof->resource_formation == 0 - || durable_proof->master_session_incarnation == 0 - || durable_proof->assertion_sequence == 0 + || durable_proof->base_authority_generation == 0 || durable_proof->resource_formation == 0 + || durable_proof->master_session_incarnation == 0 || durable_proof->assertion_sequence == 0 || durable_proof->requester_target_generation == 0) return RESOURCE_X_APPLY_INVALID; - if (!pcm_entry_ref_acquire(&durable_proof->assertion.resource, false, - &entry_ref, &acquire_result)) + if (!pcm_entry_ref_acquire(&durable_proof->assertion.resource, false, &entry_ref, + &acquire_result)) return RESOURCE_X_APPLY_NOT_FOUND; entry = entry_ref.entry; requester_node = durable_proof->assertion.requester_node; @@ -23797,42 +21891,35 @@ cluster_pcm_lock_resource_x_durable_proof_exact(const ResourceXDurableProof *dur return RESOURCE_X_APPLY_NOT_FOUND; } if (head_node != requester_node - || request->base_authority_generation - != durable_proof->base_authority_generation + || request->base_authority_generation != durable_proof->base_authority_generation || request->resource_formation != durable_proof->resource_formation - || request->master_session_incarnation - != durable_proof->master_session_incarnation + || request->master_session_incarnation != durable_proof->master_session_incarnation || request->assertion_sequence != durable_proof->assertion_sequence) { - pcm_resource_x_master_snapshot(&entry->tag, requester_node, state, - request, out); + pcm_resource_x_master_snapshot(&entry->tag, requester_node, state, request, out); LWLockRelease(&entry->entry_lock.lock); pcm_entry_ref_release(&entry_ref); return RESOURCE_X_APPLY_STALE; } if (request->phase == RESOURCE_X_MASTER_GRANT_COMMITTED) { result = request->proof_kind == RESOURCE_X_PROOF_DURABLE_STORAGE - && request->requester_target_generation - == durable_proof->requester_target_generation - && request->page_scn_lsn == durable_proof->page_scn_lsn - && request->page_checksum == durable_proof->page_checksum - && request->source_proof_crc32c - == durable_proof->source_proof_crc32c - ? RESOURCE_X_APPLY_DUPLICATE : RESOURCE_X_APPLY_STALE; - pcm_resource_x_master_snapshot(&entry->tag, requester_node, state, - request, out); + && request->requester_target_generation + == durable_proof->requester_target_generation + && request->page_scn_lsn == durable_proof->page_scn_lsn + && request->page_checksum == durable_proof->page_checksum + && request->source_proof_crc32c == durable_proof->source_proof_crc32c + ? RESOURCE_X_APPLY_DUPLICATE + : RESOURCE_X_APPLY_STALE; + pcm_resource_x_master_snapshot(&entry->tag, requester_node, state, request, out); LWLockRelease(&entry->entry_lock.lock); pcm_entry_ref_release(&entry_ref); return result; } if (request->phase != RESOURCE_X_MASTER_WAIT_PROOF - || request->incompatible_holders_bitmap - != request->blocked_holders_bitmap + || request->incompatible_holders_bitmap != request->blocked_holders_bitmap || (PcmState)pg_atomic_read_u32(&entry->master_state) != PCM_STATE_N - || entry->x_holder_node != -1 - || pg_atomic_read_u32(&entry->s_holders_bitmap) != 0 + || entry->x_holder_node != -1 || pg_atomic_read_u32(&entry->s_holders_bitmap) != 0 || pg_atomic_read_u32(&entry->pi_holders_bitmap) != 0) { - pcm_resource_x_master_snapshot(&entry->tag, requester_node, state, - request, out); + pcm_resource_x_master_snapshot(&entry->tag, requester_node, state, request, out); LWLockRelease(&entry->entry_lock.lock); pcm_entry_ref_release(&entry_ref); return RESOURCE_X_APPLY_BAD_STATE; @@ -23840,13 +21927,11 @@ cluster_pcm_lock_resource_x_durable_proof_exact(const ResourceXDurableProof *dur request->proof_kind = RESOURCE_X_PROOF_DURABLE_STORAGE; request->source_disposition = RESOURCE_X_DISPOSITION_DURABLE_STORAGE; request->source_node = -1; - request->requester_target_generation - = durable_proof->requester_target_generation; + request->requester_target_generation = durable_proof->requester_target_generation; request->page_scn_lsn = durable_proof->page_scn_lsn; request->page_checksum = durable_proof->page_checksum; request->source_proof_crc32c = durable_proof->source_proof_crc32c; - result = pcm_resource_x_commit_grant_locked(entry, state, request, - requester_node); + result = pcm_resource_x_commit_grant_locked(entry, state, request, requester_node); broadcast = result == RESOURCE_X_APPLY_APPLIED; pcm_resource_x_master_snapshot(&entry->tag, requester_node, state, request, out); LWLockRelease(&entry->entry_lock.lock); @@ -23857,8 +21942,8 @@ cluster_pcm_lock_resource_x_durable_proof_exact(const ResourceXDurableProof *dur } ResourceXApplyResult -cluster_pcm_lock_resource_x_master_snapshot_exact( - const ResourceXAssertion *assertion, ResourceXMasterSnapshot *out) +cluster_pcm_lock_resource_x_master_snapshot_exact(const ResourceXAssertion *assertion, + ResourceXMasterSnapshot *out) { ClusterPcmResourceXMasterState *state; ClusterPcmResourceXMasterRequest *request; @@ -23873,8 +21958,7 @@ cluster_pcm_lock_resource_x_master_snapshot_exact( } if (out == NULL || !resource_x_assertion_valid(assertion)) return RESOURCE_X_APPLY_INVALID; - if (!pcm_entry_ref_acquire(&assertion->resource, false, - &entry_ref, &acquire_result)) + if (!pcm_entry_ref_acquire(&assertion->resource, false, &entry_ref, &acquire_result)) return RESOURCE_X_APPLY_NOT_FOUND; entry = entry_ref.entry; requester_node = assertion->requester_node; @@ -23887,11 +21971,10 @@ cluster_pcm_lock_resource_x_master_snapshot_exact( } request = &state->requests[requester_node]; if (request->phase == RESOURCE_X_MASTER_NONE) { - if (pcm_resource_x_terminal_tombstone_valid( - &state->terminal_tombstone) + if (pcm_resource_x_terminal_tombstone_valid(&state->terminal_tombstone) && state->terminal_tombstone.requester_node == requester_node) { - pcm_resource_x_terminal_tombstone_snapshot( - &entry->tag, state, &state->terminal_tombstone, out); + pcm_resource_x_terminal_tombstone_snapshot(&entry->tag, state, + &state->terminal_tombstone, out); LWLockRelease(&entry->entry_lock.lock); pcm_entry_ref_release(&entry_ref); return RESOURCE_X_APPLY_APPLIED; @@ -23900,8 +21983,7 @@ cluster_pcm_lock_resource_x_master_snapshot_exact( pcm_entry_ref_release(&entry_ref); return RESOURCE_X_APPLY_NOT_FOUND; } - pcm_resource_x_master_snapshot(&entry->tag, requester_node, state, request, - out); + pcm_resource_x_master_snapshot(&entry->tag, requester_node, state, request, out); LWLockRelease(&entry->entry_lock.lock); pcm_entry_ref_release(&entry_ref); return RESOURCE_X_APPLY_APPLIED; @@ -23917,8 +21999,8 @@ cluster_pcm_lock_resource_x_master_snapshot_exact( * registry. */ ResourceXApplyResult -cluster_pcm_lock_resource_x_current_x_successor_exact( - const BufferTag *tag, int32 holder_node, bool *preserve_current_x_out) +cluster_pcm_lock_resource_x_current_x_successor_exact(const BufferTag *tag, int32 holder_node, + bool *preserve_current_x_out) { ClusterPcmResourceXMasterState *state; PcmEntryRef entry_ref; @@ -23929,8 +22011,8 @@ cluster_pcm_lock_resource_x_current_x_successor_exact( if (preserve_current_x_out != NULL) *preserve_current_x_out = false; - if (tag == NULL || preserve_current_x_out == NULL - || holder_node < 0 || holder_node >= RESOURCE_X_PROTOCOL_NODE_LIMIT) + if (tag == NULL || preserve_current_x_out == NULL || holder_node < 0 + || holder_node >= RESOURCE_X_PROTOCOL_NODE_LIMIT) return RESOURCE_X_APPLY_INVALID; if (!pcm_entry_ref_acquire(tag, false, &entry_ref, &acquire_result)) return RESOURCE_X_APPLY_NOT_FOUND; @@ -23941,13 +22023,11 @@ cluster_pcm_lock_resource_x_current_x_successor_exact( if (state == NULL || state->authority_generation == 0 || state->authority_generation == UINT64_MAX) result = RESOURCE_X_APPLY_RECOVERY_BLOCKED; - else if ((PcmState)pg_atomic_read_u32(&entry->master_state) - != PCM_STATE_X + else if ((PcmState)pg_atomic_read_u32(&entry->master_state) != PCM_STATE_X || entry->x_holder_node != holder_node) result = RESOURCE_X_APPLY_BAD_STATE; else { - for (requester_node = 0; - requester_node < RESOURCE_X_PROTOCOL_NODE_LIMIT; + for (requester_node = 0; requester_node < RESOURCE_X_PROTOCOL_NODE_LIMIT; requester_node++) { ClusterPcmResourceXMasterRequest *request; @@ -23962,12 +22042,9 @@ cluster_pcm_lock_resource_x_current_x_successor_exact( || request->phase > RESOURCE_X_MASTER_RELEASED || request->base_authority_generation == 0 || request->base_authority_generation == UINT64_MAX - || request->resource_formation == 0 - || request->master_session_incarnation == 0 - || request->assertion_sequence == 0 - || request->assertion_sequence == UINT64_MAX - || request->enqueue_order == 0 - || request->enqueue_order == UINT64_MAX) { + || request->resource_formation == 0 || request->master_session_incarnation == 0 + || request->assertion_sequence == 0 || request->assertion_sequence == UINT64_MAX + || request->enqueue_order == 0 || request->enqueue_order == UINT64_MAX) { result = RESOURCE_X_APPLY_RECOVERY_BLOCKED; break; } @@ -23981,45 +22058,36 @@ cluster_pcm_lock_resource_x_current_x_successor_exact( } static bool -pcm_resource_x_settled_snapshot_matches_request( - const ResourceXAssertion *assertion, uint64 assertion_sequence, - const ResourceXMasterSnapshot *settled, - const ClusterPcmResourceXMasterRequest *request, int32 requester_node) -{ - return resource_x_assertion_valid(assertion) && settled != NULL - && request != NULL - && resource_x_assertion_equal(assertion, &settled->assertion) - && assertion->requester_node == requester_node - && assertion_sequence != 0 - && assertion_sequence != UINT64_MAX - && assertion_sequence == request->assertion_sequence - && settled->base_authority_generation - == request->base_authority_generation - && settled->resource_formation == request->resource_formation - && settled->master_session_incarnation - == request->master_session_incarnation - && settled->assertion_sequence == request->assertion_sequence - && settled->final_authority_generation - == request->final_authority_generation - && settled->source_carrier_generation - == request->source_carrier_generation - && settled->requester_target_generation - == request->requester_target_generation - && settled->incompatible_holders_bitmap - == request->incompatible_holders_bitmap - && settled->blocked_holders_bitmap - == request->blocked_holders_bitmap - && settled->source_node == request->source_node - && settled->phase == RESOURCE_X_MASTER_SETTLED - && request->phase == RESOURCE_X_MASTER_SETTLED - && settled->proof_kind == request->proof_kind - && settled->source_disposition == request->source_disposition; +pcm_resource_x_settled_snapshot_matches_request(const ResourceXAssertion *assertion, + uint64 assertion_sequence, + const ResourceXMasterSnapshot *settled, + const ClusterPcmResourceXMasterRequest *request, + int32 requester_node) +{ + return resource_x_assertion_valid(assertion) && settled != NULL && request != NULL + && resource_x_assertion_equal(assertion, &settled->assertion) + && assertion->requester_node == requester_node && assertion_sequence != 0 + && assertion_sequence != UINT64_MAX && assertion_sequence == request->assertion_sequence + && settled->base_authority_generation == request->base_authority_generation + && settled->resource_formation == request->resource_formation + && settled->master_session_incarnation == request->master_session_incarnation + && settled->assertion_sequence == request->assertion_sequence + && settled->final_authority_generation == request->final_authority_generation + && settled->source_carrier_generation == request->source_carrier_generation + && settled->requester_target_generation == request->requester_target_generation + && settled->incompatible_holders_bitmap == request->incompatible_holders_bitmap + && settled->blocked_holders_bitmap == request->blocked_holders_bitmap + && settled->source_node == request->source_node + && settled->phase == RESOURCE_X_MASTER_SETTLED + && request->phase == RESOURCE_X_MASTER_SETTLED + && settled->proof_kind == request->proof_kind + && settled->source_disposition == request->source_disposition; } ResourceXApplyResult -cluster_pcm_lock_resource_x_settled_retire_exact( - const ResourceXAssertion *assertion, uint64 assertion_sequence, - const ResourceXMasterSnapshot *settled) +cluster_pcm_lock_resource_x_settled_retire_exact(const ResourceXAssertion *assertion, + uint64 assertion_sequence, + const ResourceXMasterSnapshot *settled) { ClusterPcmResourceXBootstrapReceipt *receipt; ClusterPcmResourceXTerminalTombstone *tombstone; @@ -24030,11 +22098,10 @@ cluster_pcm_lock_resource_x_settled_retire_exact( struct GrdEntry *entry; int32 requester_node; - if (!resource_x_assertion_valid(assertion) || settled == NULL - || assertion_sequence == 0 || assertion_sequence == UINT64_MAX) + if (!resource_x_assertion_valid(assertion) || settled == NULL || assertion_sequence == 0 + || assertion_sequence == UINT64_MAX) return RESOURCE_X_APPLY_INVALID; - if (!pcm_entry_ref_acquire(&assertion->resource, false, - &entry_ref, &acquire_result)) + if (!pcm_entry_ref_acquire(&assertion->resource, false, &entry_ref, &acquire_result)) return RESOURCE_X_APPLY_NOT_FOUND; entry = entry_ref.entry; requester_node = assertion->requester_node; @@ -24049,21 +22116,20 @@ cluster_pcm_lock_resource_x_settled_retire_exact( receipt = &state->bootstrap_receipts[requester_node]; request = &state->requests[requester_node]; if (request->phase == RESOURCE_X_MASTER_NONE) { - ResourceXApplyResult result - = pcm_resource_x_terminal_tombstone_valid(tombstone) - && tombstone->requester_node == requester_node - && pcm_resource_x_settled_snapshot_matches_request( - assertion, assertion_sequence, settled, - &tombstone->request, requester_node) - ? RESOURCE_X_APPLY_DUPLICATE - : RESOURCE_X_APPLY_STALE; + ResourceXApplyResult result = pcm_resource_x_terminal_tombstone_valid(tombstone) + && tombstone->requester_node == requester_node + && pcm_resource_x_settled_snapshot_matches_request( + assertion, assertion_sequence, settled, + &tombstone->request, requester_node) + ? RESOURCE_X_APPLY_DUPLICATE + : RESOURCE_X_APPLY_STALE; LWLockRelease(&entry->entry_lock.lock); pcm_entry_ref_release(&entry_ref); return result; } - if (!pcm_resource_x_settled_snapshot_matches_request( - assertion, assertion_sequence, settled, request, requester_node)) { + if (!pcm_resource_x_settled_snapshot_matches_request(assertion, assertion_sequence, settled, + request, requester_node)) { LWLockRelease(&entry->entry_lock.lock); pcm_entry_ref_release(&entry_ref); return RESOURCE_X_APPLY_STALE; @@ -24112,10 +22178,10 @@ pcm_resource_x_reclaim_witness(const BufferTag *tag, int32 requester_node, } static ResourceXReclaimResult -pcm_resource_x_reclaim_requester_locked( - struct GrdEntry *entry, ClusterPcmResourceXMasterState *state, - int32 dead_node, uint64 dead_formation, ResourceXReclaimWitness *out, - bool *broadcast_out) +pcm_resource_x_reclaim_requester_locked(struct GrdEntry *entry, + ClusterPcmResourceXMasterState *state, int32 dead_node, + uint64 dead_formation, ResourceXReclaimWitness *out, + bool *broadcast_out) { ClusterPcmResourceXMasterRequest *request; ClusterPcmResourceXMasterRequest *successor = NULL; @@ -24135,8 +22201,7 @@ pcm_resource_x_reclaim_requester_locked( if (dead_node < 0 || dead_node >= RESOURCE_X_PROTOCOL_NODE_LIMIT) return RESOURCE_X_RECLAIM_NONE; request = &state->requests[dead_node]; - if (request->phase == RESOURCE_X_MASTER_NONE - || request->phase == RESOURCE_X_MASTER_RELEASED + if (request->phase == RESOURCE_X_MASTER_NONE || request->phase == RESOURCE_X_MASTER_RELEASED || request->resource_formation != dead_formation) return RESOURCE_X_RECLAIM_NONE; (void)pcm_resource_x_master_head(state, &head_node); @@ -24147,8 +22212,7 @@ pcm_resource_x_reclaim_requester_locked( if (request->phase == RESOURCE_X_MASTER_QUEUED) { memset(request, 0, sizeof(*request)); result = RESOURCE_X_RECLAIM_NONHEAD; - } - else { + } else { request->phase = RESOURCE_X_MASTER_RECOVERY_BLOCKED; result = RESOURCE_X_RECLAIM_ORPHAN_BLOCKED; } @@ -24158,8 +22222,7 @@ pcm_resource_x_reclaim_requester_locked( && request->final_authority_generation == 0 && request->delegated_authority_generation == 0 && request->proof_kind == 0) { memset(request, 0, sizeof(*request)); - successor = pcm_resource_x_start_head_locked(entry, state, - &successor_node); + successor = pcm_resource_x_start_head_locked(entry, state, &successor_node); result = RESOURCE_X_RECLAIM_HEAD_SUCCESSOR_STARTED; *broadcast_out = true; if (successor != NULL) { @@ -24177,9 +22240,9 @@ pcm_resource_x_reclaim_requester_locked( } ResourceXReclaimResult -cluster_pcm_lock_resource_x_reclaim_requester_exact( - const BufferTag *tag, int32 dead_node, uint64 dead_formation, - ResourceXReclaimWitness *out) +cluster_pcm_lock_resource_x_reclaim_requester_exact(const BufferTag *tag, int32 dead_node, + uint64 dead_formation, + ResourceXReclaimWitness *out) { ClusterPcmResourceXMasterState *state; PcmEntryRef entry_ref; @@ -24193,16 +22256,13 @@ cluster_pcm_lock_resource_x_reclaim_requester_exact( out->successor_node = -1; out->result = RESOURCE_X_RECLAIM_NONE; } - if (tag == NULL || out == NULL || dead_node < 0 - || dead_node >= RESOURCE_X_PROTOCOL_NODE_LIMIT || dead_formation == 0 - || dead_formation == UINT64_MAX || ClusterPcm == NULL - || pg_atomic_read_u32(&ClusterPcm->resource_x_gate_phase) - != RESOURCE_X_GATE_FROZEN - || pg_atomic_read_u64(&ClusterPcm->resource_x_reconfig_old_formation) - != dead_formation - || (pg_atomic_read_u32( - &ClusterPcm->resource_x_reconfig_dead_requester_bitmap) - & (UINT32_C(1) << (uint32)dead_node)) == 0) + if (tag == NULL || out == NULL || dead_node < 0 || dead_node >= RESOURCE_X_PROTOCOL_NODE_LIMIT + || dead_formation == 0 || dead_formation == UINT64_MAX || ClusterPcm == NULL + || pg_atomic_read_u32(&ClusterPcm->resource_x_gate_phase) != RESOURCE_X_GATE_FROZEN + || pg_atomic_read_u64(&ClusterPcm->resource_x_reconfig_old_formation) != dead_formation + || (pg_atomic_read_u32(&ClusterPcm->resource_x_reconfig_dead_requester_bitmap) + & (UINT32_C(1) << (uint32)dead_node)) + == 0) return RESOURCE_X_RECLAIM_NONE; if (!pcm_entry_ref_acquire(tag, false, &entry_ref, &acquire_result)) @@ -24215,8 +22275,8 @@ cluster_pcm_lock_resource_x_reclaim_requester_exact( pcm_entry_ref_release(&entry_ref); return RESOURCE_X_RECLAIM_NONE; } - result = pcm_resource_x_reclaim_requester_locked( - entry, state, dead_node, dead_formation, out, &broadcast); + result = pcm_resource_x_reclaim_requester_locked(entry, state, dead_node, dead_formation, out, + &broadcast); LWLockRelease(&entry->entry_lock.lock); if (broadcast) ConditionVariableBroadcast(&entry->wait_cv); @@ -24225,8 +22285,8 @@ cluster_pcm_lock_resource_x_reclaim_requester_exact( } ResourceXApplyResult -cluster_pcm_lock_resource_x_authority_grant_exact( - const ResourceXAssertion *assertion, ResourceXDecodedFrame *out) +cluster_pcm_lock_resource_x_authority_grant_exact(const ResourceXAssertion *assertion, + ResourceXDecodedFrame *out) { ClusterPcmResourceXMasterState *state; ClusterPcmResourceXMasterRequest *request; @@ -24240,8 +22300,7 @@ cluster_pcm_lock_resource_x_authority_grant_exact( memset(out, 0, sizeof(*out)); if (out == NULL || !resource_x_assertion_valid(assertion)) return RESOURCE_X_APPLY_INVALID; - if (!pcm_entry_ref_acquire(&assertion->resource, false, - &entry_ref, &acquire_result)) + if (!pcm_entry_ref_acquire(&assertion->resource, false, &entry_ref, &acquire_result)) return RESOURCE_X_APPLY_NOT_FOUND; entry = entry_ref.entry; requester_node = assertion->requester_node; @@ -24260,8 +22319,8 @@ cluster_pcm_lock_resource_x_authority_grant_exact( result = RESOURCE_X_APPLY_BAD_STATE; goto authority_grant_done; } - result = pcm_resource_x_build_authority_grant_locked( - entry, request, requester_node, request->final_authority_generation, out); + result = pcm_resource_x_build_authority_grant_locked(entry, request, requester_node, + request->final_authority_generation, out); authority_grant_done: LWLockRelease(&entry->entry_lock.lock); @@ -24270,9 +22329,9 @@ cluster_pcm_lock_resource_x_authority_grant_exact( } ResourceXApplyResult -cluster_pcm_lock_resource_x_grant_intent_snapshot_exact( - const ResourceXAssertion *assertion, ResourceXIntentSlot *slot_out, - void *payload_out, uint16 payload_capacity) +cluster_pcm_lock_resource_x_grant_intent_snapshot_exact(const ResourceXAssertion *assertion, + ResourceXIntentSlot *slot_out, + void *payload_out, uint16 payload_capacity) { ClusterPcmResourceXMasterState *state; ClusterPcmResourceXMasterRequest *request; @@ -24285,11 +22344,10 @@ cluster_pcm_lock_resource_x_grant_intent_snapshot_exact( if (slot_out != NULL) memset(slot_out, 0, sizeof(*slot_out)); - if (!resource_x_assertion_valid(assertion) || slot_out == NULL - || payload_out == NULL || payload_capacity < RESOURCE_X_PROOF_V1_BYTES) + if (!resource_x_assertion_valid(assertion) || slot_out == NULL || payload_out == NULL + || payload_capacity < RESOURCE_X_PROOF_V1_BYTES) return RESOURCE_X_APPLY_INVALID; - if (!pcm_entry_ref_acquire(&assertion->resource, false, - &entry_ref, &acquire_result)) + if (!pcm_entry_ref_acquire(&assertion->resource, false, &entry_ref, &acquire_result)) return RESOURCE_X_APPLY_NOT_FOUND; entry = entry_ref.entry; requester_node = assertion->requester_node; @@ -24314,15 +22372,12 @@ cluster_pcm_lock_resource_x_grant_intent_snapshot_exact( || intent->slot.state > RESOURCE_X_INTENT_SLOT_STAGED || !pcm_resource_x_intent_body_valid(&intent->slot.body) || intent->slot.logical_generation != request->assertion_sequence - || intent->slot.authority_generation - != request->final_authority_generation + || intent->slot.authority_generation != request->final_authority_generation || intent->slot.destination_node != (uint32)requester_node || intent->slot.payload_bytes != RESOURCE_X_PROOF_V1_BYTES || intent->slot.kind != RESOURCE_X_WIRE_AUTHORITY_GRANT - || intent->slot.body.owner_generation - != request->final_authority_generation - || intent->slot.body.owner_kind - != RESOURCE_X_INTENT_OWNER_MASTER_GRANT) { + || intent->slot.body.owner_generation != request->final_authority_generation + || intent->slot.body.owner_kind != RESOURCE_X_INTENT_OWNER_MASTER_GRANT) { result = RESOURCE_X_APPLY_RECOVERY_BLOCKED; goto grant_intent_snapshot_done; } @@ -24337,8 +22392,8 @@ cluster_pcm_lock_resource_x_grant_intent_snapshot_exact( } static ResourceXIntentSlot * -pcm_resource_x_grant_intent_lock_exact( - const ResourceXIntentSlot *expected, PcmEntryRef *entry_ref_out) +pcm_resource_x_grant_intent_lock_exact(const ResourceXIntentSlot *expected, + PcmEntryRef *entry_ref_out) { ClusterPcmResourceXMasterState *state; PcmEntryAcquireResult acquire_result; @@ -24347,13 +22402,12 @@ pcm_resource_x_grant_intent_lock_exact( Assert(entry_ref_out != NULL); memset(entry_ref_out, 0, sizeof(*entry_ref_out)); if (expected == NULL || !pcm_resource_x_intent_body_valid(&expected->body) - || expected->body.owner_kind - != RESOURCE_X_INTENT_OWNER_MASTER_GRANT + || expected->body.owner_kind != RESOURCE_X_INTENT_OWNER_MASTER_GRANT || expected->kind != RESOURCE_X_WIRE_AUTHORITY_GRANT || expected->payload_bytes != RESOURCE_X_PROOF_V1_BYTES) return NULL; - if (!pcm_entry_ref_acquire(&expected->body.assertion.resource, false, - entry_ref_out, &acquire_result)) + if (!pcm_entry_ref_acquire(&expected->body.assertion.resource, false, entry_ref_out, + &acquire_result)) return NULL; entry = entry_ref_out->entry; pcm_entry_lock_exclusive(entry); @@ -24367,8 +22421,8 @@ pcm_resource_x_grant_intent_lock_exact( } ResourceXIntentResult -cluster_pcm_lock_resource_x_grant_intent_not_admitted_exact( - const ResourceXIntentSlot *expected, uint64 now_us) +cluster_pcm_lock_resource_x_grant_intent_not_admitted_exact(const ResourceXIntentSlot *expected, + uint64 now_us) { PcmEntryRef entry_ref; ResourceXIntentSlot *slot; @@ -24377,10 +22431,8 @@ cluster_pcm_lock_resource_x_grant_intent_not_admitted_exact( slot = pcm_resource_x_grant_intent_lock_exact(expected, &entry_ref); if (slot == NULL) return RESOURCE_X_INTENT_STALE; - result = cluster_pcm_lock_resource_x_intent_not_admitted_exact( - slot, expected, now_us); - if (result == RESOURCE_X_INTENT_NOT_ADMITTED - && !pcm_resource_x_intent_mark_dirty()) + result = cluster_pcm_lock_resource_x_intent_not_admitted_exact(slot, expected, now_us); + if (result == RESOURCE_X_INTENT_NOT_ADMITTED && !pcm_resource_x_intent_mark_dirty()) result = RESOURCE_X_INTENT_STALE; LWLockRelease(&entry_ref.entry->entry_lock.lock); pcm_entry_ref_release(&entry_ref); @@ -24388,8 +22440,8 @@ cluster_pcm_lock_resource_x_grant_intent_not_admitted_exact( } ResourceXIntentResult -cluster_pcm_lock_resource_x_grant_intent_stage_exact( - const ResourceXIntentSlot *expected, uint64 now_us) +cluster_pcm_lock_resource_x_grant_intent_stage_exact(const ResourceXIntentSlot *expected, + uint64 now_us) { PcmEntryRef entry_ref; ResourceXIntentSlot *slot; @@ -24398,16 +22450,15 @@ cluster_pcm_lock_resource_x_grant_intent_stage_exact( slot = pcm_resource_x_grant_intent_lock_exact(expected, &entry_ref); if (slot == NULL) return RESOURCE_X_INTENT_STALE; - result = cluster_pcm_lock_resource_x_intent_stage_exact( - slot, expected, now_us); + result = cluster_pcm_lock_resource_x_intent_stage_exact(slot, expected, now_us); LWLockRelease(&entry_ref.entry->entry_lock.lock); pcm_entry_ref_release(&entry_ref); return result; } ResourceXIntentResult -cluster_pcm_lock_resource_x_grant_intent_hard_rearm_exact( - const ResourceXIntentSlot *expected, uint64 now_us) +cluster_pcm_lock_resource_x_grant_intent_hard_rearm_exact(const ResourceXIntentSlot *expected, + uint64 now_us) { PcmEntryRef entry_ref; ResourceXIntentSlot *slot; @@ -24416,10 +22467,8 @@ cluster_pcm_lock_resource_x_grant_intent_hard_rearm_exact( slot = pcm_resource_x_grant_intent_lock_exact(expected, &entry_ref); if (slot == NULL) return RESOURCE_X_INTENT_STALE; - result = cluster_pcm_lock_resource_x_intent_hard_rearm_exact( - slot, expected, now_us); - if (result == RESOURCE_X_INTENT_HARD_REARMED - && !pcm_resource_x_intent_mark_dirty()) + result = cluster_pcm_lock_resource_x_intent_hard_rearm_exact(slot, expected, now_us); + if (result == RESOURCE_X_INTENT_HARD_REARMED && !pcm_resource_x_intent_mark_dirty()) result = RESOURCE_X_INTENT_STALE; LWLockRelease(&entry_ref.entry->entry_lock.lock); pcm_entry_ref_release(&entry_ref); @@ -24427,8 +22476,7 @@ cluster_pcm_lock_resource_x_grant_intent_hard_rearm_exact( } bool -cluster_pcm_lock_resource_x_grant_intent_complete_exact( - const ResourceXIntentSlot *expected) +cluster_pcm_lock_resource_x_grant_intent_complete_exact(const ResourceXIntentSlot *expected) { PcmEntryRef entry_ref; ResourceXIntentSlot *slot; @@ -24447,20 +22495,17 @@ static bool pcm_resource_x_intent_identity_equal(const ResourceXIntentSlot *left, const ResourceXIntentSlot *right) { - return left != NULL && right != NULL - && left->logical_generation == right->logical_generation - && left->authority_generation == right->authority_generation - && left->first_armed_us == right->first_armed_us - && left->destination_node == right->destination_node - && left->payload_bytes == right->payload_bytes - && left->kind == right->kind - && memcmp(&left->body, &right->body, sizeof(left->body)) == 0; + return left != NULL && right != NULL && left->logical_generation == right->logical_generation + && left->authority_generation == right->authority_generation + && left->first_armed_us == right->first_armed_us + && left->destination_node == right->destination_node + && left->payload_bytes == right->payload_bytes && left->kind == right->kind + && memcmp(&left->body, &right->body, sizeof(left->body)) == 0; } static ResourceXIntentSlot * -pcm_resource_x_outbound_intent_lock_exact( - const ResourceXIntentSlot *expected, PcmEntryRef *entry_ref_out, - uint8 **payload_out) +pcm_resource_x_outbound_intent_lock_exact(const ResourceXIntentSlot *expected, + PcmEntryRef *entry_ref_out, uint8 **payload_out) { ClusterPcmResourceXMasterState *state; PcmEntryAcquireResult acquire_result; @@ -24471,8 +22516,7 @@ pcm_resource_x_outbound_intent_lock_exact( Assert(payload_out != NULL); memset(entry_ref_out, 0, sizeof(*entry_ref_out)); *payload_out = NULL; - if (expected == NULL - || !pcm_resource_x_intent_body_valid(&expected->body)) + if (expected == NULL || !pcm_resource_x_intent_body_valid(&expected->body)) return NULL; switch ((ResourceXIntentOwnerKind)expected->body.owner_kind) { case RESOURCE_X_INTENT_OWNER_MASTER_BLOCK: @@ -24510,8 +22554,8 @@ pcm_resource_x_outbound_intent_lock_exact( default: return NULL; } - if (!pcm_entry_ref_acquire(&expected->body.assertion.resource, false, - entry_ref_out, &acquire_result)) + if (!pcm_entry_ref_acquire(&expected->body.assertion.resource, false, entry_ref_out, + &acquire_result)) return NULL; entry = entry_ref_out->entry; pcm_entry_lock_exclusive(entry); @@ -24524,8 +22568,7 @@ pcm_resource_x_outbound_intent_lock_exact( switch ((ResourceXIntentOwnerKind)expected->body.owner_kind) { case RESOURCE_X_INTENT_OWNER_MASTER_BLOCK: slot = &state->block_intents[expected->body.owner_index].slot; - *payload_out - = state->block_intents[expected->body.owner_index].payload; + *payload_out = state->block_intents[expected->body.owner_index].payload; break; case RESOURCE_X_INTENT_OWNER_HOLDER_STATUS: slot = &state->holder_status_intent.slot; @@ -24556,9 +22599,10 @@ pcm_resource_x_outbound_intent_lock_exact( } ResourceXApplyResult -cluster_pcm_lock_resource_x_outbound_intent_snapshot_exact( - const ResourceXIntentSlot *expected, ResourceXIntentSlot *slot_out, - void *payload_out, uint16 payload_capacity) +cluster_pcm_lock_resource_x_outbound_intent_snapshot_exact(const ResourceXIntentSlot *expected, + ResourceXIntentSlot *slot_out, + void *payload_out, + uint16 payload_capacity) { ClusterPcmResourceXMasterState *state; PcmEntryRef entry_ref; @@ -24572,8 +22616,7 @@ cluster_pcm_lock_resource_x_outbound_intent_snapshot_exact( memset(slot_out, 0, sizeof(*slot_out)); if (expected == NULL || slot_out == NULL || payload_out == NULL) return RESOURCE_X_APPLY_INVALID; - slot = pcm_resource_x_outbound_intent_lock_exact( - expected, &entry_ref, &payload); + slot = pcm_resource_x_outbound_intent_lock_exact(expected, &entry_ref, &payload); if (slot == NULL) return RESOURCE_X_APPLY_STALE; entry = entry_ref.entry; @@ -24583,23 +22626,17 @@ cluster_pcm_lock_resource_x_outbound_intent_snapshot_exact( return RESOURCE_X_APPLY_NOT_FOUND; } if (!pcm_resource_x_intent_identity_equal(slot, expected) - || slot->state > RESOURCE_X_INTENT_SLOT_STAGED - || payload_capacity < slot->payload_bytes) { + || slot->state > RESOURCE_X_INTENT_SLOT_STAGED || payload_capacity < slot->payload_bytes) { LWLockRelease(&entry->entry_lock.lock); pcm_entry_ref_release(&entry_ref); return RESOURCE_X_APPLY_STALE; } - if (expected->body.owner_kind - == RESOURCE_X_INTENT_OWNER_HOLDER_IMAGE) { + if (expected->body.owner_kind == RESOURCE_X_INTENT_OWNER_HOLDER_IMAGE) { state = pcm_resource_x_master_state_for_entry(entry); - if (state == NULL - || state->holder_status.valid - != RESOURCE_X_HOLDER_PAIR_PUBLISHED - || state->holder_image.valid - != RESOURCE_X_HOLDER_PAIR_PUBLISHED - || pcm_resource_x_holder_pair_decode_locked( - state, &pair_status, &pair_image) - != RESOURCE_X_APPLY_APPLIED) { + if (state == NULL || state->holder_status.valid != RESOURCE_X_HOLDER_PAIR_PUBLISHED + || state->holder_image.valid != RESOURCE_X_HOLDER_PAIR_PUBLISHED + || pcm_resource_x_holder_pair_decode_locked(state, &pair_status, &pair_image) + != RESOURCE_X_APPLY_APPLIED) { LWLockRelease(&entry->entry_lock.lock); pcm_entry_ref_release(&entry_ref); return RESOURCE_X_APPLY_RECOVERY_BLOCKED; @@ -24613,22 +22650,19 @@ cluster_pcm_lock_resource_x_outbound_intent_snapshot_exact( } ResourceXIntentResult -cluster_pcm_lock_resource_x_outbound_intent_not_admitted_exact( - const ResourceXIntentSlot *expected, uint64 now_us) +cluster_pcm_lock_resource_x_outbound_intent_not_admitted_exact(const ResourceXIntentSlot *expected, + uint64 now_us) { PcmEntryRef entry_ref; ResourceXIntentSlot *slot; ResourceXIntentResult result; uint8 *payload; - slot = pcm_resource_x_outbound_intent_lock_exact( - expected, &entry_ref, &payload); + slot = pcm_resource_x_outbound_intent_lock_exact(expected, &entry_ref, &payload); if (slot == NULL) return RESOURCE_X_INTENT_STALE; - result = cluster_pcm_lock_resource_x_intent_not_admitted_exact( - slot, expected, now_us); - if (result == RESOURCE_X_INTENT_NOT_ADMITTED - && !pcm_resource_x_intent_mark_dirty()) + result = cluster_pcm_lock_resource_x_intent_not_admitted_exact(slot, expected, now_us); + if (result == RESOURCE_X_INTENT_NOT_ADMITTED && !pcm_resource_x_intent_mark_dirty()) result = RESOURCE_X_INTENT_STALE; LWLockRelease(&entry_ref.entry->entry_lock.lock); pcm_entry_ref_release(&entry_ref); @@ -24636,16 +22670,15 @@ cluster_pcm_lock_resource_x_outbound_intent_not_admitted_exact( } ResourceXIntentResult -cluster_pcm_lock_resource_x_outbound_intent_stage_exact( - const ResourceXIntentSlot *expected, uint64 now_us) +cluster_pcm_lock_resource_x_outbound_intent_stage_exact(const ResourceXIntentSlot *expected, + uint64 now_us) { PcmEntryRef entry_ref; ResourceXIntentSlot *slot; ResourceXIntentResult result; uint8 *payload; - slot = pcm_resource_x_outbound_intent_lock_exact( - expected, &entry_ref, &payload); + slot = pcm_resource_x_outbound_intent_lock_exact(expected, &entry_ref, &payload); if (slot == NULL) return RESOURCE_X_INTENT_STALE; /* Physical queue ownership is not the idempotent semantic stage API. @@ -24660,22 +22693,19 @@ cluster_pcm_lock_resource_x_outbound_intent_stage_exact( } ResourceXIntentResult -cluster_pcm_lock_resource_x_outbound_intent_hard_rearm_exact( - const ResourceXIntentSlot *expected, uint64 now_us) +cluster_pcm_lock_resource_x_outbound_intent_hard_rearm_exact(const ResourceXIntentSlot *expected, + uint64 now_us) { PcmEntryRef entry_ref; ResourceXIntentSlot *slot; ResourceXIntentResult result; uint8 *payload; - slot = pcm_resource_x_outbound_intent_lock_exact( - expected, &entry_ref, &payload); + slot = pcm_resource_x_outbound_intent_lock_exact(expected, &entry_ref, &payload); if (slot == NULL) return RESOURCE_X_INTENT_STALE; - result = cluster_pcm_lock_resource_x_intent_hard_rearm_exact( - slot, expected, now_us); - if (result == RESOURCE_X_INTENT_HARD_REARMED - && !pcm_resource_x_intent_mark_dirty()) + result = cluster_pcm_lock_resource_x_intent_hard_rearm_exact(slot, expected, now_us); + if (result == RESOURCE_X_INTENT_HARD_REARMED && !pcm_resource_x_intent_mark_dirty()) result = RESOURCE_X_INTENT_STALE; LWLockRelease(&entry_ref.entry->entry_lock.lock); pcm_entry_ref_release(&entry_ref); @@ -24683,20 +22713,17 @@ cluster_pcm_lock_resource_x_outbound_intent_hard_rearm_exact( } bool -cluster_pcm_lock_resource_x_outbound_intent_complete_exact( - const ResourceXIntentSlot *expected) +cluster_pcm_lock_resource_x_outbound_intent_complete_exact(const ResourceXIntentSlot *expected) { PcmEntryRef entry_ref; ResourceXIntentSlot *slot; uint8 *payload; bool completed; - slot = pcm_resource_x_outbound_intent_lock_exact( - expected, &entry_ref, &payload); + slot = pcm_resource_x_outbound_intent_lock_exact(expected, &entry_ref, &payload); if (slot == NULL) return false; - completed = cluster_pcm_lock_resource_x_intent_complete_exact( - slot, expected); + completed = cluster_pcm_lock_resource_x_intent_complete_exact(slot, expected); if (completed) { ClusterPcmResourceXMasterState *state = pcm_resource_x_master_state_for_entry(entry_ref.entry); @@ -24713,9 +22740,8 @@ cluster_pcm_lock_resource_x_outbound_intent_complete_exact( } static void -pcm_resource_x_outbound_owner_at( - ClusterPcmResourceXMasterState *state, uint32 owner_index, - ResourceXIntentSlot **slot_out, uint8 **payload_out) +pcm_resource_x_outbound_owner_at(ClusterPcmResourceXMasterState *state, uint32 owner_index, + ResourceXIntentSlot **slot_out, uint8 **payload_out) { Assert(state != NULL); Assert(slot_out != NULL); @@ -24744,56 +22770,48 @@ pcm_resource_x_outbound_owner_at( } static bool -pcm_resource_x_outbound_owner_valid(const ResourceXIntentSlot *slot, - uint32 owner_index) +pcm_resource_x_outbound_owner_valid(const ResourceXIntentSlot *slot, uint32 owner_index) { if (slot == NULL || !pcm_resource_x_intent_body_valid(&slot->body)) return false; if (owner_index < RESOURCE_X_PROTOCOL_NODE_LIMIT) - return slot->body.owner_kind - == RESOURCE_X_INTENT_OWNER_MASTER_BLOCK - && slot->body.owner_index == owner_index - && slot->body.owner_generation == slot->logical_generation - && slot->destination_node == owner_index - && slot->kind == RESOURCE_X_WIRE_BLOCK_TO_N - && slot->payload_bytes == RESOURCE_X_CONTROL_V1_BYTES; + return slot->body.owner_kind == RESOURCE_X_INTENT_OWNER_MASTER_BLOCK + && slot->body.owner_index == owner_index + && slot->body.owner_generation == slot->logical_generation + && slot->destination_node == owner_index && slot->kind == RESOURCE_X_WIRE_BLOCK_TO_N + && slot->payload_bytes == RESOURCE_X_CONTROL_V1_BYTES; if (owner_index == RESOURCE_X_PROTOCOL_NODE_LIMIT) - return slot->body.owner_kind - == RESOURCE_X_INTENT_OWNER_HOLDER_STATUS - && slot->body.owner_index == 0 - && slot->body.owner_generation == slot->logical_generation - && slot->kind == RESOURCE_X_WIRE_BLOCKED_TO_N - && (slot->payload_bytes == RESOURCE_X_CONTROL_V1_BYTES - || slot->payload_bytes == RESOURCE_X_PROOF_V1_BYTES); + return slot->body.owner_kind == RESOURCE_X_INTENT_OWNER_HOLDER_STATUS + && slot->body.owner_index == 0 + && slot->body.owner_generation == slot->logical_generation + && slot->kind == RESOURCE_X_WIRE_BLOCKED_TO_N + && (slot->payload_bytes == RESOURCE_X_CONTROL_V1_BYTES + || slot->payload_bytes == RESOURCE_X_PROOF_V1_BYTES); if (owner_index == RESOURCE_X_PROTOCOL_NODE_LIMIT + 1) - return slot->body.owner_kind - == RESOURCE_X_INTENT_OWNER_MASTER_GRANT - && slot->body.owner_index == 0 - && slot->body.owner_generation == slot->authority_generation - && slot->kind == RESOURCE_X_WIRE_AUTHORITY_GRANT - && slot->payload_bytes == RESOURCE_X_PROOF_V1_BYTES; + return slot->body.owner_kind == RESOURCE_X_INTENT_OWNER_MASTER_GRANT + && slot->body.owner_index == 0 + && slot->body.owner_generation == slot->authority_generation + && slot->kind == RESOURCE_X_WIRE_AUTHORITY_GRANT + && slot->payload_bytes == RESOURCE_X_PROOF_V1_BYTES; if (owner_index == RESOURCE_X_PROTOCOL_NODE_LIMIT + 2) - return slot->body.owner_kind - == RESOURCE_X_INTENT_OWNER_HOLDER_IMAGE - && slot->body.owner_index == 0 - && slot->body.owner_generation == slot->logical_generation - && slot->kind == RESOURCE_X_WIRE_IMAGE_ENVELOPE - && slot->payload_bytes == RESOURCE_X_IMAGE_V1_BYTES; + return slot->body.owner_kind == RESOURCE_X_INTENT_OWNER_HOLDER_IMAGE + && slot->body.owner_index == 0 + && slot->body.owner_generation == slot->logical_generation + && slot->kind == RESOURCE_X_WIRE_IMAGE_ENVELOPE + && slot->payload_bytes == RESOURCE_X_IMAGE_V1_BYTES; if (owner_index == RESOURCE_X_PROTOCOL_NODE_LIMIT + 3) - return slot->body.owner_kind - == RESOURCE_X_INTENT_OWNER_REQUESTER_SETTLEMENT - && slot->body.owner_index == 0 - && slot->body.owner_generation == slot->logical_generation - && slot->body.assertion.requester_node == cluster_node_id - && slot->kind == RESOURCE_X_WIRE_INSTALL_SETTLEMENT - && slot->payload_bytes == RESOURCE_X_SHORT_V1_BYTES; + return slot->body.owner_kind == RESOURCE_X_INTENT_OWNER_REQUESTER_SETTLEMENT + && slot->body.owner_index == 0 + && slot->body.owner_generation == slot->logical_generation + && slot->body.assertion.requester_node == cluster_node_id + && slot->kind == RESOURCE_X_WIRE_INSTALL_SETTLEMENT + && slot->payload_bytes == RESOURCE_X_SHORT_V1_BYTES; if (owner_index == RESOURCE_X_PROTOCOL_NODE_LIMIT + 4) - return slot->body.owner_kind - == RESOURCE_X_INTENT_OWNER_HOLDER_RELEASE - && slot->body.owner_index == 0 - && slot->body.owner_generation == slot->logical_generation - && slot->kind == RESOURCE_X_WIRE_SOURCE_SETTLEMENT_V2 - && slot->payload_bytes == RESOURCE_X_PROOF_V1_BYTES; + return slot->body.owner_kind == RESOURCE_X_INTENT_OWNER_HOLDER_RELEASE + && slot->body.owner_index == 0 + && slot->body.owner_generation == slot->logical_generation + && slot->kind == RESOURCE_X_WIRE_SOURCE_SETTLEMENT_V2 + && slot->payload_bytes == RESOURCE_X_PROOF_V1_BYTES; return false; } @@ -24858,9 +22876,10 @@ cluster_pcm_lock_resource_x_ready_intent_probe_exact(const BufferTag *tag, uint3 } ResourceXIntentProbeResult -cluster_pcm_lock_resource_x_outbound_intent_probe_exact( - uint32 probe_budget, ResourceXIntentSlot *slot_out, void *payload_out, - uint16 payload_capacity, uint32 *examined_out) +cluster_pcm_lock_resource_x_outbound_intent_probe_exact(uint32 probe_budget, + ResourceXIntentSlot *slot_out, + void *payload_out, uint16 payload_capacity, + uint32 *examined_out) { ResourceXAcquisitionRef delivery; @@ -24897,29 +22916,21 @@ cluster_pcm_lock_resource_x_outbound_work_probe_exact(uint32 probe_budget, || pg_atomic_read_u32(&ClusterPcm->resource_x_intent_generation_exhausted) != 0) return RESOURCE_X_INTENT_PROBE_CORRUPT; capacity = (uint64)pcm_grd_effective; - arm_generation - = pg_atomic_read_u64(&ClusterPcm->resource_x_intent_arm_generation); - cursor = pg_atomic_read_u64( - &ClusterPcm->resource_x_intent_next_state_index); - owner_cursor = pg_atomic_read_u32( - &ClusterPcm->resource_x_intent_next_owner_index); - scan_generation = pg_atomic_read_u64( - &ClusterPcm->resource_x_intent_scan_generation); - completed_generation = pg_atomic_read_u64( - &ClusterPcm->resource_x_intent_completed_generation); + arm_generation = pg_atomic_read_u64(&ClusterPcm->resource_x_intent_arm_generation); + cursor = pg_atomic_read_u64(&ClusterPcm->resource_x_intent_next_state_index); + owner_cursor = pg_atomic_read_u32(&ClusterPcm->resource_x_intent_next_owner_index); + scan_generation = pg_atomic_read_u64(&ClusterPcm->resource_x_intent_scan_generation); + completed_generation = pg_atomic_read_u64(&ClusterPcm->resource_x_intent_completed_generation); if (cursor > capacity || owner_cursor >= PGRAC_RESOURCE_X_WORK_OWNER_SLOTS) return RESOURCE_X_INTENT_PROBE_CORRUPT; if (cursor == 0 && owner_cursor == 0) { if (completed_generation == arm_generation) return RESOURCE_X_INTENT_PROBE_IDLE; scan_generation = arm_generation; - pg_atomic_write_u64( - &ClusterPcm->resource_x_intent_scan_generation, - scan_generation); + pg_atomic_write_u64(&ClusterPcm->resource_x_intent_scan_generation, scan_generation); } while (cursor < capacity && examined < probe_budget) { - ClusterPcmResourceXSlot *registry_slot - = &cluster_pcm_resource_x_slots[cursor]; + ClusterPcmResourceXSlot *registry_slot = &cluster_pcm_resource_x_slots[cursor]; ClusterPcmResourceXMasterState *state; PcmEntryRef entry_ref; PcmEntryAcquireResult acquire_result; @@ -24937,17 +22948,14 @@ cluster_pcm_lock_resource_x_outbound_work_probe_exact(uint32 probe_budget, *examined_out = examined; return RESOURCE_X_INTENT_PROBE_CORRUPT; } - if (!pcm_entry_ref_acquire(®istry_slot->tag, false, - &entry_ref, &acquire_result)) { + if (!pcm_entry_ref_acquire(®istry_slot->tag, false, &entry_ref, &acquire_result)) { *examined_out = examined; return RESOURCE_X_INTENT_PROBE_CORRUPT; } entry = entry_ref.entry; LWLockAcquire(&entry->entry_lock.lock, LW_SHARED); state = pcm_resource_x_master_state_for_entry(entry); - if (state == NULL - || entry_ref.binding_generation - != registry_slot->binding_generation + if (state == NULL || entry_ref.binding_generation != registry_slot->binding_generation || entry_ref.registry_slot != (uint32)cursor) { LWLockRelease(&entry->entry_lock.lock); pcm_entry_ref_release(&entry_ref); @@ -25020,8 +23028,7 @@ cluster_pcm_lock_resource_x_outbound_work_probe_exact(uint32 probe_budget, *examined_out = examined; return RESOURCE_X_INTENT_PROBE_DELIVERY; } - pcm_resource_x_outbound_owner_at( - state, owner_index, &slot, &payload); + pcm_resource_x_outbound_owner_at(state, owner_index, &slot, &payload); if (slot == NULL || payload == NULL) { LWLockRelease(&entry->entry_lock.lock); pcm_entry_ref_release(&entry_ref); @@ -25032,9 +23039,8 @@ cluster_pcm_lock_resource_x_outbound_work_probe_exact(uint32 probe_budget, || slot->state == RESOURCE_X_INTENT_SLOT_STAGED) continue; if (slot->state != RESOURCE_X_INTENT_SLOT_ARMED - || !pcm_resource_x_outbound_owner_valid( - slot, owner_index) - || slot->payload_bytes > payload_capacity) { + || !pcm_resource_x_outbound_owner_valid(slot, owner_index) + || slot->payload_bytes > payload_capacity) { LWLockRelease(&entry->entry_lock.lock); pcm_entry_ref_release(&entry_ref); *examined_out = examined; @@ -25049,12 +23055,8 @@ cluster_pcm_lock_resource_x_outbound_work_probe_exact(uint32 probe_budget, } LWLockRelease(&entry->entry_lock.lock); pcm_entry_ref_release(&entry_ref); - pg_atomic_write_u64( - &ClusterPcm->resource_x_intent_next_state_index, - cursor); - pg_atomic_write_u32( - &ClusterPcm->resource_x_intent_next_owner_index, - owner_cursor); + pg_atomic_write_u64(&ClusterPcm->resource_x_intent_next_state_index, cursor); + pg_atomic_write_u32(&ClusterPcm->resource_x_intent_next_owner_index, owner_cursor); *examined_out = examined; return RESOURCE_X_INTENT_PROBE_FOUND; } @@ -25064,159 +23066,122 @@ cluster_pcm_lock_resource_x_outbound_work_probe_exact(uint32 probe_budget, owner_cursor = 0; } *examined_out = examined; - pg_atomic_write_u64( - &ClusterPcm->resource_x_intent_next_state_index, cursor); - pg_atomic_write_u32( - &ClusterPcm->resource_x_intent_next_owner_index, owner_cursor); + pg_atomic_write_u64(&ClusterPcm->resource_x_intent_next_state_index, cursor); + pg_atomic_write_u32(&ClusterPcm->resource_x_intent_next_owner_index, owner_cursor); if (cursor < capacity) return RESOURCE_X_INTENT_PROBE_MORE; - pg_atomic_write_u64( - &ClusterPcm->resource_x_intent_next_state_index, 0); - pg_atomic_write_u32( - &ClusterPcm->resource_x_intent_next_owner_index, 0); - pg_atomic_write_u64( - &ClusterPcm->resource_x_intent_completed_generation, - scan_generation); + pg_atomic_write_u64(&ClusterPcm->resource_x_intent_next_state_index, 0); + pg_atomic_write_u32(&ClusterPcm->resource_x_intent_next_owner_index, 0); + pg_atomic_write_u64(&ClusterPcm->resource_x_intent_completed_generation, scan_generation); return RESOURCE_X_INTENT_PROBE_COMPLETE; } static bool -pcm_resource_x_final_common_matches_request( - const ResourceXDecodedCommon *common, - const ClusterPcmResourceXMasterRequest *request) +pcm_resource_x_final_common_matches_request(const ResourceXDecodedCommon *common, + const ClusterPcmResourceXMasterRequest *request) { - return common->base_authority_generation - == request->base_authority_generation - && common->authority_generation == request->final_authority_generation - && common->resource_formation == request->resource_formation - && common->master_session_incarnation - == request->master_session_incarnation - && common->assertion_sequence == request->assertion_sequence - && common->ordered_lane == request->ordered_lane; + return common->base_authority_generation == request->base_authority_generation + && common->authority_generation == request->final_authority_generation + && common->resource_formation == request->resource_formation + && common->master_session_incarnation == request->master_session_incarnation + && common->assertion_sequence == request->assertion_sequence + && common->ordered_lane == request->ordered_lane; } static bool -pcm_resource_x_install_settlement_valid( - const ResourceXDecodedFrame *settlement, int32 authenticated_source_node) +pcm_resource_x_install_settlement_valid(const ResourceXDecodedFrame *settlement, + int32 authenticated_source_node) { const ResourceXDecodedInstallSettlement *body; - if (settlement == NULL - || settlement->kind != RESOURCE_X_WIRE_INSTALL_SETTLEMENT + if (settlement == NULL || settlement->kind != RESOURCE_X_WIRE_INSTALL_SETTLEMENT || !resource_x_assertion_valid(&settlement->common.logical_assertion) - || authenticated_source_node - != settlement->common.logical_assertion.requester_node + || authenticated_source_node != settlement->common.logical_assertion.requester_node || settlement->common.action_node != authenticated_source_node || settlement->common.target_mode != (uint8)PCM_STATE_X - || settlement->common.source_candidate != 0 - || settlement->common.retain_pi_if_dirty != 0 + || settlement->common.source_candidate != 0 || settlement->common.retain_pi_if_dirty != 0 || settlement->common.sender_connection_generation == 0 - || settlement->common.outcome != RESOURCE_X_OUTCOME_OK - || settlement->common.flags != 0) + || settlement->common.outcome != RESOURCE_X_OUTCOME_OK || settlement->common.flags != 0) return false; body = &settlement->body.install_settlement; - return body->conversion_base_generation - == settlement->common.base_authority_generation - && body->final_authority_generation - == settlement->common.authority_generation - && body->requester_connection_generation != 0 - && body->requester_target_generation != 0 - && body->installed_mode == (uint8)PCM_STATE_X - && body->requester_role == RESOURCE_X_REQUESTER_ROLE_ACQUIRER - && body->terminal_outcome == RESOURCE_X_OUTCOME_OK - && body->terminal_state == RESOURCE_X_SETTLEMENT_TERMINAL_INSTALLED - && body->settlement_flags == 0; + return body->conversion_base_generation == settlement->common.base_authority_generation + && body->final_authority_generation == settlement->common.authority_generation + && body->requester_connection_generation != 0 && body->requester_target_generation != 0 + && body->installed_mode == (uint8)PCM_STATE_X + && body->requester_role == RESOURCE_X_REQUESTER_ROLE_ACQUIRER + && body->terminal_outcome == RESOURCE_X_OUTCOME_OK + && body->terminal_state == RESOURCE_X_SETTLEMENT_TERMINAL_INSTALLED + && body->settlement_flags == 0; } static bool -pcm_resource_x_install_settlement_matches_request( - const ResourceXDecodedFrame *settlement, - const ClusterPcmResourceXMasterRequest *request) +pcm_resource_x_install_settlement_matches_request(const ResourceXDecodedFrame *settlement, + const ClusterPcmResourceXMasterRequest *request) { const ResourceXDecodedInstallSettlement *body; if (settlement == NULL || request == NULL - || !pcm_resource_x_final_common_matches_request( - &settlement->common, request)) + || !pcm_resource_x_final_common_matches_request(&settlement->common, request)) return false; body = &settlement->body.install_settlement; - return body->conversion_base_generation - == request->base_authority_generation - && body->final_authority_generation - == request->final_authority_generation - && body->requester_connection_generation - == request->settlement_requester_connection_generation - && body->requester_target_generation - == request->requester_target_generation - && body->page_scn_lsn == request->page_scn_lsn - && body->page_checksum == request->page_checksum - && body->source_proof_crc32c == request->source_proof_crc32c; + return body->conversion_base_generation == request->base_authority_generation + && body->final_authority_generation == request->final_authority_generation + && body->requester_connection_generation + == request->settlement_requester_connection_generation + && body->requester_target_generation == request->requester_target_generation + && body->page_scn_lsn == request->page_scn_lsn + && body->page_checksum == request->page_checksum + && body->source_proof_crc32c == request->source_proof_crc32c; } static bool -pcm_resource_x_source_settlement_ack_matches_retained( - const ResourceXDecodedFrame *ack, - const ResourceXDecodedFrame *retained) +pcm_resource_x_source_settlement_ack_matches_retained(const ResourceXDecodedFrame *ack, + const ResourceXDecodedFrame *retained) { const ResourceXDecodedBlockedToN *left; const ResourceXDecodedBlockedToN *right; - if (ack == NULL || retained == NULL - || ack->kind != RESOURCE_X_WIRE_SOURCE_SETTLEMENT_ACK_V2 - || retained->kind != RESOURCE_X_WIRE_SOURCE_SETTLEMENT_V2 - || !ack->blocked_has_remote_proof + if (ack == NULL || retained == NULL || ack->kind != RESOURCE_X_WIRE_SOURCE_SETTLEMENT_ACK_V2 + || retained->kind != RESOURCE_X_WIRE_SOURCE_SETTLEMENT_V2 || !ack->blocked_has_remote_proof || !retained->blocked_has_remote_proof - || !resource_x_assertion_equal( - &ack->common.logical_assertion, - &retained->common.logical_assertion) - || ack->common.base_authority_generation - != retained->common.base_authority_generation - || ack->common.authority_generation - != retained->common.authority_generation - || ack->common.resource_formation - != retained->common.resource_formation - || ack->common.master_session_incarnation - != retained->common.master_session_incarnation - || ack->common.assertion_sequence - != retained->common.assertion_sequence + || !resource_x_assertion_equal(&ack->common.logical_assertion, + &retained->common.logical_assertion) + || ack->common.base_authority_generation != retained->common.base_authority_generation + || ack->common.authority_generation != retained->common.authority_generation + || ack->common.resource_formation != retained->common.resource_formation + || ack->common.master_session_incarnation != retained->common.master_session_incarnation + || ack->common.assertion_sequence != retained->common.assertion_sequence || ack->common.ordered_lane != retained->common.ordered_lane || ack->common.action_node != retained->common.action_node || ack->common.observed_mode != retained->common.observed_mode || ack->common.target_mode != retained->common.target_mode - || ack->common.source_candidate - != retained->common.source_candidate - || ack->common.retain_pi_if_dirty - != retained->common.retain_pi_if_dirty + || ack->common.source_candidate != retained->common.source_candidate + || ack->common.retain_pi_if_dirty != retained->common.retain_pi_if_dirty || ack->common.sender_connection_generation == 0 || ack->common.outcome != RESOURCE_X_OUTCOME_OK || ack->common.flags != retained->common.flags) return false; left = &ack->body.blocked_to_n; right = &retained->body.blocked_to_n; - return left->source_carrier_generation - == right->source_carrier_generation - && left->requester_target_generation - == right->requester_target_generation - && left->page_scn_lsn == right->page_scn_lsn - && left->dependency_count == right->dependency_count - && left->source_proof_crc32c == right->source_proof_crc32c - && left->page_checksum == right->page_checksum - && left->source_disposition == right->source_disposition - && left->proof_kind == right->proof_kind - && left->proof_flags == right->proof_flags - && left->holder_connection_generation - == right->holder_connection_generation - && left->acting_formation == right->acting_formation - && memcmp(left->source_fence, right->source_fence, - sizeof(left->source_fence)) == 0 - && memcmp(left->dependencies, right->dependencies, - sizeof(left->dependencies)) == 0; + return left->source_carrier_generation == right->source_carrier_generation + && left->requester_target_generation == right->requester_target_generation + && left->page_scn_lsn == right->page_scn_lsn + && left->dependency_count == right->dependency_count + && left->source_proof_crc32c == right->source_proof_crc32c + && left->page_checksum == right->page_checksum + && left->source_disposition == right->source_disposition + && left->proof_kind == right->proof_kind && left->proof_flags == right->proof_flags + && left->holder_connection_generation == right->holder_connection_generation + && left->acting_formation == right->acting_formation + && memcmp(left->source_fence, right->source_fence, sizeof(left->source_fence)) == 0 + && memcmp(left->dependencies, right->dependencies, sizeof(left->dependencies)) == 0; } static ResourceXApplyResult -pcm_resource_x_arm_source_settlement_locked( - struct GrdEntry *entry, ClusterPcmResourceXMasterState *state, - ClusterPcmResourceXMasterRequest *request, int32 requester_node) +pcm_resource_x_arm_source_settlement_locked(struct GrdEntry *entry, + ClusterPcmResourceXMasterState *state, + ClusterPcmResourceXMasterRequest *request, + int32 requester_node) { ResourceXDecodedBlockedToN *body; ResourceXDecodedFrame settlement; @@ -25229,21 +23194,14 @@ pcm_resource_x_arm_source_settlement_locked( Assert(state != NULL); Assert(request != NULL); Assert(LWLockHeldByMeInMode(&entry->entry_lock.lock, LW_EXCLUSIVE)); - if (request->ordered_lane != 0 - || request->proof_kind != RESOURCE_X_PROOF_REMOTE_CARRIER - || request->source_node < 0 - || request->source_node >= RESOURCE_X_PROTOCOL_NODE_LIMIT + if (request->ordered_lane != 0 || request->proof_kind != RESOURCE_X_PROOF_REMOTE_CARRIER + || request->source_node < 0 || request->source_node >= RESOURCE_X_PROTOCOL_NODE_LIMIT || request->source_node == requester_node - || request->final_authority_generation - <= request->base_authority_generation - || (state->source_settlement.state - != RESOURCE_X_SOURCE_SETTLEMENT_NONE - && state->source_settlement.state - != RESOURCE_X_SOURCE_SETTLEMENT_ACKED) - || state->source_settlement.intent.slot.state - != RESOURCE_X_INTENT_SLOT_EMPTY - || cluster_node_id < 0 - || cluster_node_id >= RESOURCE_X_PROTOCOL_NODE_LIMIT) + || request->final_authority_generation <= request->base_authority_generation + || (state->source_settlement.state != RESOURCE_X_SOURCE_SETTLEMENT_NONE + && state->source_settlement.state != RESOURCE_X_SOURCE_SETTLEMENT_ACKED) + || state->source_settlement.intent.slot.state != RESOURCE_X_INTENT_SLOT_EMPTY + || cluster_node_id < 0 || cluster_node_id >= RESOURCE_X_PROTOCOL_NODE_LIMIT) return RESOURCE_X_APPLY_RECOVERY_BLOCKED; memset(&settlement, 0, sizeof(settlement)); settlement.kind = RESOURCE_X_WIRE_SOURCE_SETTLEMENT_V2; @@ -25251,13 +23209,10 @@ pcm_resource_x_arm_source_settlement_locked( settlement.blocked_has_remote_proof = true; settlement.common.logical_assertion.resource = entry->tag; settlement.common.logical_assertion.requester_node = requester_node; - settlement.common.base_authority_generation - = request->base_authority_generation; - settlement.common.authority_generation - = request->final_authority_generation; + settlement.common.base_authority_generation = request->base_authority_generation; + settlement.common.authority_generation = request->final_authority_generation; settlement.common.resource_formation = request->resource_formation; - settlement.common.master_session_incarnation - = request->master_session_incarnation; + settlement.common.master_session_incarnation = request->master_session_incarnation; settlement.common.assertion_sequence = request->assertion_sequence; settlement.common.ordered_lane = 0; settlement.common.action_node = request->source_node; @@ -25265,34 +23220,27 @@ pcm_resource_x_arm_source_settlement_locked( settlement.common.target_mode = (uint8)PCM_STATE_N; settlement.common.source_candidate = 1; settlement.common.retain_pi_if_dirty = 1; - settlement.common.sender_connection_generation - = PGRAC_RESOURCE_X_RETAINED_SENDER_GENERATION; + settlement.common.sender_connection_generation = PGRAC_RESOURCE_X_RETAINED_SENDER_GENERATION; settlement.common.outcome = RESOURCE_X_OUTCOME_NONE; body = &settlement.body.blocked_to_n; - memcpy(body->source_fence, request->source_fence, - sizeof(body->source_fence)); + memcpy(body->source_fence, request->source_fence, sizeof(body->source_fence)); body->source_carrier_generation = request->source_carrier_generation; body->requester_target_generation = request->requester_target_generation; body->page_scn_lsn = request->page_scn_lsn; body->dependency_count = request->dependency_count; - memcpy(body->dependencies, request->dependencies, - sizeof(body->dependencies)); + memcpy(body->dependencies, request->dependencies, sizeof(body->dependencies)); body->source_proof_crc32c = request->source_proof_crc32c; body->page_checksum = request->page_checksum; body->source_disposition = request->source_disposition; body->proof_kind = request->proof_kind; body->proof_flags = request->proof_flags; - body->holder_connection_generation - = request->holder_connection_generation; + body->holder_connection_generation = request->holder_connection_generation; body->acting_formation = request->acting_formation; if (!cluster_resource_x_wire_encode( - RESOURCE_X_MSG_BLOCK_TO_N, &settlement, - state->source_settlement.intent.payload, - sizeof(state->source_settlement.intent.payload), - &payload_len, &reject) + RESOURCE_X_MSG_BLOCK_TO_N, &settlement, state->source_settlement.intent.payload, + sizeof(state->source_settlement.intent.payload), &payload_len, &reject) || payload_len != RESOURCE_X_PROOF_V1_BYTES) { - memset(&state->source_settlement, 0, - sizeof(state->source_settlement)); + memset(&state->source_settlement, 0, sizeof(state->source_settlement)); return RESOURCE_X_APPLY_RECOVERY_BLOCKED; } memset(&owner, 0, sizeof(owner)); @@ -25302,14 +23250,11 @@ pcm_resource_x_arm_source_settlement_locked( owner.owner_kind = RESOURCE_X_INTENT_OWNER_HOLDER_RELEASE; now_us = pcm_resource_x_monotonic_us(); if (!cluster_pcm_lock_resource_x_intent_arm_exact( - &state->source_settlement.intent.slot, &owner, - request->assertion_sequence, - request->final_authority_generation, now_us, - (uint32)request->source_node, payload_len, + &state->source_settlement.intent.slot, &owner, request->assertion_sequence, + request->final_authority_generation, now_us, (uint32)request->source_node, payload_len, RESOURCE_X_WIRE_SOURCE_SETTLEMENT_V2) || !pcm_resource_x_intent_mark_dirty()) { - memset(&state->source_settlement, 0, - sizeof(state->source_settlement)); + memset(&state->source_settlement, 0, sizeof(state->source_settlement)); return RESOURCE_X_APPLY_RECOVERY_BLOCKED; } state->source_settlement.state = RESOURCE_X_SOURCE_SETTLEMENT_PENDING; @@ -25456,9 +23401,9 @@ pcm_resource_x_deferred_settlement_keep_locked(ClusterPcmResourceXMasterState *s } ResourceXApplyResult -cluster_pcm_lock_resource_x_install_settlement_exact( - const ResourceXDecodedFrame *settlement, int32 authenticated_source_node, - ResourceXMasterSnapshot *out) +cluster_pcm_lock_resource_x_install_settlement_exact(const ResourceXDecodedFrame *settlement, + int32 authenticated_source_node, + ResourceXMasterSnapshot *out) { ClusterPcmResourceXMasterState *state; ClusterPcmResourceXMasterRequest *request; @@ -25473,11 +23418,10 @@ cluster_pcm_lock_resource_x_install_settlement_exact( out->source_node = -1; } if (out == NULL - || !pcm_resource_x_install_settlement_valid(settlement, - authenticated_source_node)) + || !pcm_resource_x_install_settlement_valid(settlement, authenticated_source_node)) return RESOURCE_X_APPLY_INVALID; - if (!pcm_entry_ref_acquire(&settlement->common.logical_assertion.resource, - false, &entry_ref, &acquire_result)) + if (!pcm_entry_ref_acquire(&settlement->common.logical_assertion.resource, false, &entry_ref, + &acquire_result)) return RESOURCE_X_APPLY_NOT_FOUND; entry = entry_ref.entry; requester_node = settlement->common.logical_assertion.requester_node; @@ -25491,20 +23435,19 @@ cluster_pcm_lock_resource_x_install_settlement_exact( request = &state->requests[requester_node]; if (pcm_resource_x_terminal_tombstone_valid(&state->terminal_tombstone) && state->terminal_tombstone.requester_node == requester_node - && pcm_resource_x_install_settlement_matches_request( - settlement, &state->terminal_tombstone.request)) { - pcm_resource_x_terminal_tombstone_snapshot( - &entry->tag, state, &state->terminal_tombstone, out); + && pcm_resource_x_install_settlement_matches_request(settlement, + &state->terminal_tombstone.request)) { + pcm_resource_x_terminal_tombstone_snapshot(&entry->tag, state, &state->terminal_tombstone, + out); LWLockRelease(&entry->entry_lock.lock); pcm_entry_ref_release(&entry_ref); return RESOURCE_X_APPLY_DUPLICATE; } if (request->phase == RESOURCE_X_MASTER_NONE) { - if (pcm_resource_x_terminal_tombstone_valid( - &state->terminal_tombstone) + if (pcm_resource_x_terminal_tombstone_valid(&state->terminal_tombstone) && state->terminal_tombstone.requester_node == requester_node) { - pcm_resource_x_terminal_tombstone_snapshot( - &entry->tag, state, &state->terminal_tombstone, out); + pcm_resource_x_terminal_tombstone_snapshot(&entry->tag, state, + &state->terminal_tombstone, out); LWLockRelease(&entry->entry_lock.lock); pcm_entry_ref_release(&entry_ref); return RESOURCE_X_APPLY_STALE; @@ -25520,8 +23463,7 @@ cluster_pcm_lock_resource_x_install_settlement_exact( else result = pcm_resource_x_install_settlement_apply_locked(entry, state, request, requester_node, settlement); - pcm_resource_x_master_snapshot(&entry->tag, requester_node, state, request, - out); + pcm_resource_x_master_snapshot(&entry->tag, requester_node, state, request, out); LWLockRelease(&entry->entry_lock.lock); if (result == RESOURCE_X_APPLY_APPLIED && out->phase == RESOURCE_X_MASTER_SETTLED) ConditionVariableBroadcast(&entry->wait_cv); @@ -25531,8 +23473,8 @@ cluster_pcm_lock_resource_x_install_settlement_exact( ResourceXApplyResult cluster_pcm_lock_resource_x_source_settlement_intent_snapshot_exact( - const ResourceXAssertion *assertion, ResourceXIntentSlot *slot_out, - void *payload_out, uint16 payload_capacity) + const ResourceXAssertion *assertion, ResourceXIntentSlot *slot_out, void *payload_out, + uint16 payload_capacity) { ClusterPcmResourceXSourceSettlement *debt; ClusterPcmResourceXControlIntent *intent; @@ -25544,12 +23486,10 @@ cluster_pcm_lock_resource_x_source_settlement_intent_snapshot_exact( if (slot_out != NULL) memset(slot_out, 0, sizeof(*slot_out)); - if (!resource_x_assertion_valid(assertion) || slot_out == NULL - || payload_out == NULL + if (!resource_x_assertion_valid(assertion) || slot_out == NULL || payload_out == NULL || payload_capacity < RESOURCE_X_PROOF_V1_BYTES) return RESOURCE_X_APPLY_INVALID; - if (!pcm_entry_ref_acquire(&assertion->resource, false, - &entry_ref, &acquire_result)) + if (!pcm_entry_ref_acquire(&assertion->resource, false, &entry_ref, &acquire_result)) return RESOURCE_X_APPLY_NOT_FOUND; entry = entry_ref.entry; LWLockAcquire(&entry->entry_lock.lock, LW_SHARED); @@ -25566,22 +23506,18 @@ cluster_pcm_lock_resource_x_source_settlement_intent_snapshot_exact( result = RESOURCE_X_APPLY_NOT_FOUND; goto source_settlement_intent_done; } - if (!resource_x_assertion_equal(assertion, - &intent->slot.body.assertion)) { + if (!resource_x_assertion_equal(assertion, &intent->slot.body.assertion)) { result = RESOURCE_X_APPLY_STALE; goto source_settlement_intent_done; } if (debt->state != RESOURCE_X_SOURCE_SETTLEMENT_PENDING - || memcmp(debt->reserved, (uint8[7]){0}, - sizeof(debt->reserved)) != 0 + || memcmp(debt->reserved, (uint8[7]){ 0 }, sizeof(debt->reserved)) != 0 || intent->slot.state > RESOURCE_X_INTENT_SLOT_STAGED || !pcm_resource_x_intent_body_valid(&intent->slot.body) || intent->slot.payload_bytes != RESOURCE_X_PROOF_V1_BYTES || intent->slot.kind != RESOURCE_X_WIRE_SOURCE_SETTLEMENT_V2 - || intent->slot.body.owner_generation - != intent->slot.logical_generation - || intent->slot.body.owner_kind - != RESOURCE_X_INTENT_OWNER_HOLDER_RELEASE) { + || intent->slot.body.owner_generation != intent->slot.logical_generation + || intent->slot.body.owner_kind != RESOURCE_X_INTENT_OWNER_HOLDER_RELEASE) { result = RESOURCE_X_APPLY_RECOVERY_BLOCKED; goto source_settlement_intent_done; } @@ -25596,9 +23532,9 @@ cluster_pcm_lock_resource_x_source_settlement_intent_snapshot_exact( } ResourceXApplyResult -cluster_pcm_lock_resource_x_source_settlement_ack_exact( - const ResourceXDecodedFrame *ack, int32 authenticated_source_node, - ResourceXMasterSnapshot *out) +cluster_pcm_lock_resource_x_source_settlement_ack_exact(const ResourceXDecodedFrame *ack, + int32 authenticated_source_node, + ResourceXMasterSnapshot *out) { ClusterPcmResourceXSourceSettlement *debt; ClusterPcmResourceXMasterState *state; @@ -25613,15 +23549,14 @@ cluster_pcm_lock_resource_x_source_settlement_ack_exact( memset(out, 0, sizeof(*out)); out->source_node = -1; } - if (ack == NULL || out == NULL - || ack->kind != RESOURCE_X_WIRE_SOURCE_SETTLEMENT_ACK_V2 + if (ack == NULL || out == NULL || ack->kind != RESOURCE_X_WIRE_SOURCE_SETTLEMENT_ACK_V2 || !resource_x_assertion_valid(&ack->common.logical_assertion) || authenticated_source_node < 0 || authenticated_source_node >= RESOURCE_X_PROTOCOL_NODE_LIMIT || ack->common.action_node != authenticated_source_node) return RESOURCE_X_APPLY_INVALID; - if (!pcm_entry_ref_acquire(&ack->common.logical_assertion.resource, - false, &entry_ref, &acquire_result)) + if (!pcm_entry_ref_acquire(&ack->common.logical_assertion.resource, false, &entry_ref, + &acquire_result)) return RESOURCE_X_APPLY_NOT_FOUND; entry = entry_ref.entry; pcm_entry_lock_exclusive(entry); @@ -25636,39 +23571,32 @@ cluster_pcm_lock_resource_x_source_settlement_ack_exact( goto source_settlement_ack_done; } if ((debt->state != RESOURCE_X_SOURCE_SETTLEMENT_PENDING - && debt->state != RESOURCE_X_SOURCE_SETTLEMENT_ACKED) - || memcmp(debt->reserved, (uint8[7]){0}, - sizeof(debt->reserved)) != 0 - || !cluster_resource_x_wire_decode( - RESOURCE_X_MSG_BLOCK_TO_N, debt->intent.payload, - RESOURCE_X_PROOF_V1_BYTES, &retained, &reject)) { + && debt->state != RESOURCE_X_SOURCE_SETTLEMENT_ACKED) + || memcmp(debt->reserved, (uint8[7]){ 0 }, sizeof(debt->reserved)) != 0 + || !cluster_resource_x_wire_decode(RESOURCE_X_MSG_BLOCK_TO_N, debt->intent.payload, + RESOURCE_X_PROOF_V1_BYTES, &retained, &reject)) { result = RESOURCE_X_APPLY_RECOVERY_BLOCKED; goto source_settlement_ack_done; } if (authenticated_source_node != retained.common.action_node - || !pcm_resource_x_source_settlement_ack_matches_retained( - ack, &retained)) { + || !pcm_resource_x_source_settlement_ack_matches_retained(ack, &retained)) { result = RESOURCE_X_APPLY_STALE; goto source_settlement_ack_done; } if (debt->state == RESOURCE_X_SOURCE_SETTLEMENT_ACKED) { result = debt->intent.slot.state == RESOURCE_X_INTENT_SLOT_EMPTY - ? RESOURCE_X_APPLY_DUPLICATE - : RESOURCE_X_APPLY_RECOVERY_BLOCKED; + ? RESOURCE_X_APPLY_DUPLICATE + : RESOURCE_X_APPLY_RECOVERY_BLOCKED; goto source_settlement_ack_done; } if ((debt->intent.slot.state != RESOURCE_X_INTENT_SLOT_ARMED - && debt->intent.slot.state != RESOURCE_X_INTENT_SLOT_STAGED) - || debt->intent.slot.destination_node - != (uint32)authenticated_source_node - || debt->intent.slot.kind - != RESOURCE_X_WIRE_SOURCE_SETTLEMENT_V2 + && debt->intent.slot.state != RESOURCE_X_INTENT_SLOT_STAGED) + || debt->intent.slot.destination_node != (uint32)authenticated_source_node + || debt->intent.slot.kind != RESOURCE_X_WIRE_SOURCE_SETTLEMENT_V2 || debt->intent.slot.payload_bytes != RESOURCE_X_PROOF_V1_BYTES - || debt->intent.slot.body.owner_kind - != RESOURCE_X_INTENT_OWNER_HOLDER_RELEASE - || !resource_x_assertion_equal( - &debt->intent.slot.body.assertion, - &retained.common.logical_assertion)) { + || debt->intent.slot.body.owner_kind != RESOURCE_X_INTENT_OWNER_HOLDER_RELEASE + || !resource_x_assertion_equal(&debt->intent.slot.body.assertion, + &retained.common.logical_assertion)) { result = RESOURCE_X_APPLY_RECOVERY_BLOCKED; goto source_settlement_ack_done; } @@ -25683,43 +23611,36 @@ cluster_pcm_lock_resource_x_source_settlement_ack_exact( } static bool -pcm_resource_x_release_valid(const ResourceXDecodedFrame *release, - int32 authenticated_source_node) +pcm_resource_x_release_valid(const ResourceXDecodedFrame *release, int32 authenticated_source_node) { return release != NULL && release->kind == RESOURCE_X_WIRE_RELEASE_X - && resource_x_assertion_valid(&release->common.logical_assertion) - && authenticated_source_node - == release->common.logical_assertion.requester_node - && release->common.action_node == authenticated_source_node - && release->common.observed_mode == (uint8)PCM_STATE_X - && release->common.target_mode == (uint8)PCM_STATE_N - && release->common.source_candidate == 0 - && release->common.retain_pi_if_dirty == 0 - && release->common.sender_connection_generation != 0 - && release->common.outcome == RESOURCE_X_OUTCOME_OK - && release->common.flags == 0; + && resource_x_assertion_valid(&release->common.logical_assertion) + && authenticated_source_node == release->common.logical_assertion.requester_node + && release->common.action_node == authenticated_source_node + && release->common.observed_mode == (uint8)PCM_STATE_X + && release->common.target_mode == (uint8)PCM_STATE_N + && release->common.source_candidate == 0 && release->common.retain_pi_if_dirty == 0 + && release->common.sender_connection_generation != 0 + && release->common.outcome == RESOURCE_X_OUTCOME_OK && release->common.flags == 0; } static void -pcm_resource_x_release_snapshot( - const BufferTag *tag, const ClusterPcmResourceXMasterState *state, - const ClusterPcmResourceXMasterRequest *request, - const ClusterPcmResourceXTerminalTombstone *tombstone, - bool tombstone_request, int32 requester_node, - ResourceXMasterSnapshot *out) +pcm_resource_x_release_snapshot(const BufferTag *tag, const ClusterPcmResourceXMasterState *state, + const ClusterPcmResourceXMasterRequest *request, + const ClusterPcmResourceXTerminalTombstone *tombstone, + bool tombstone_request, int32 requester_node, + ResourceXMasterSnapshot *out) { if (tombstone_request) - pcm_resource_x_terminal_tombstone_snapshot( - tag, state, tombstone, out); + pcm_resource_x_terminal_tombstone_snapshot(tag, state, tombstone, out); else - pcm_resource_x_master_snapshot( - tag, requester_node, state, request, out); + pcm_resource_x_master_snapshot(tag, requester_node, state, request, out); } ResourceXApplyResult -cluster_pcm_lock_resource_x_release_x_exact( - const ResourceXDecodedFrame *release, int32 authenticated_source_node, - ResourceXMasterSnapshot *out) +cluster_pcm_lock_resource_x_release_x_exact(const ResourceXDecodedFrame *release, + int32 authenticated_source_node, + ResourceXMasterSnapshot *out) { BufferTag retire_tag; ClusterPcmResourceXMasterState *state; @@ -25742,11 +23663,10 @@ cluster_pcm_lock_resource_x_release_x_exact( memset(out, 0, sizeof(*out)); out->source_node = -1; } - if (out == NULL - || !pcm_resource_x_release_valid(release, authenticated_source_node)) + if (out == NULL || !pcm_resource_x_release_valid(release, authenticated_source_node)) return RESOURCE_X_APPLY_INVALID; - if (!pcm_entry_ref_acquire(&release->common.logical_assertion.resource, - false, &entry_ref, &acquire_result)) + if (!pcm_entry_ref_acquire(&release->common.logical_assertion.resource, false, &entry_ref, + &acquire_result)) return RESOURCE_X_APPLY_NOT_FOUND; entry = entry_ref.entry; requester_node = release->common.logical_assertion.requester_node; @@ -25767,37 +23687,30 @@ cluster_pcm_lock_resource_x_release_x_exact( pcm_entry_ref_release(&entry_ref); return RESOURCE_X_APPLY_NOT_FOUND; } - if (!pcm_resource_x_final_common_matches_request( - &release->common, &tombstone->request)) { - pcm_resource_x_terminal_tombstone_snapshot( - &entry->tag, state, tombstone, out); + if (!pcm_resource_x_final_common_matches_request(&release->common, &tombstone->request)) { + pcm_resource_x_terminal_tombstone_snapshot(&entry->tag, state, tombstone, out); LWLockRelease(&entry->entry_lock.lock); pcm_entry_ref_release(&entry_ref); return RESOURCE_X_APPLY_STALE; } request = &tombstone->request; tombstone_request = true; - } - else if (!pcm_resource_x_final_common_matches_request( - &release->common, request)) { + } else if (!pcm_resource_x_final_common_matches_request(&release->common, request)) { if (pcm_resource_x_terminal_tombstone_valid(tombstone) && tombstone->requester_node == requester_node - && pcm_resource_x_final_common_matches_request( - &release->common, &tombstone->request)) { + && pcm_resource_x_final_common_matches_request(&release->common, &tombstone->request)) { request = &tombstone->request; tombstone_request = true; - } - else { - pcm_resource_x_master_snapshot(&entry->tag, requester_node, state, - request, out); + } else { + pcm_resource_x_master_snapshot(&entry->tag, requester_node, state, request, out); LWLockRelease(&entry->entry_lock.lock); pcm_entry_ref_release(&entry_ref); return RESOURCE_X_APPLY_STALE; } } if (request->phase == RESOURCE_X_MASTER_RELEASED) { - pcm_resource_x_release_snapshot(&entry->tag, state, request, - tombstone, tombstone_request, requester_node, out); + pcm_resource_x_release_snapshot(&entry->tag, state, request, tombstone, tombstone_request, + requester_node, out); LWLockRelease(&entry->entry_lock.lock); pcm_entry_ref_release(&entry_ref); return RESOURCE_X_APPLY_DUPLICATE; @@ -25808,21 +23721,18 @@ cluster_pcm_lock_resource_x_release_x_exact( if (tombstone_request && ((PcmState)pg_atomic_read_u32(&entry->master_state) != PCM_STATE_X || entry->x_holder_node != requester_node)) { - pcm_resource_x_terminal_tombstone_snapshot( - &entry->tag, state, tombstone, out); + pcm_resource_x_terminal_tombstone_snapshot(&entry->tag, state, tombstone, out); LWLockRelease(&entry->entry_lock.lock); pcm_entry_ref_release(&entry_ref); return RESOURCE_X_APPLY_DUPLICATE; } if (request->phase != RESOURCE_X_MASTER_SETTLED || (PcmState)pg_atomic_read_u32(&entry->master_state) != PCM_STATE_X - || entry->x_holder_node != requester_node - || entry->pending_x_requester_node != -1 + || entry->x_holder_node != requester_node || entry->pending_x_requester_node != -1 || (tombstone_request - && state->authority_generation - != request->final_authority_generation)) { - pcm_resource_x_release_snapshot(&entry->tag, state, request, - tombstone, tombstone_request, requester_node, out); + && state->authority_generation != request->final_authority_generation)) { + pcm_resource_x_release_snapshot(&entry->tag, state, request, tombstone, tombstone_request, + requester_node, out); LWLockRelease(&entry->entry_lock.lock); pcm_entry_ref_release(&entry_ref); return RESOURCE_X_APPLY_BAD_STATE; @@ -25856,8 +23766,8 @@ cluster_pcm_lock_resource_x_release_x_exact( entry->resource_x_bootstrap_round.r4_record_generation, entry->resource_x_bootstrap_round.cached_ownership_generation); if (!preserve_local_terminal_cover) { - pcm_resource_x_release_snapshot(&entry->tag, state, request, - tombstone, tombstone_request, requester_node, out); + pcm_resource_x_release_snapshot(&entry->tag, state, request, tombstone, + tombstone_request, requester_node, out); LWLockRelease(&entry->entry_lock.lock); pcm_entry_ref_release(&entry_ref); return RESOURCE_X_APPLY_STALE; @@ -25866,8 +23776,8 @@ cluster_pcm_lock_resource_x_release_x_exact( * eviction cannot repurpose the same local X or call start_head(), which * would mutate blocker intents before the BufferDesc commit. */ if (pcm_resource_x_master_head(state, NULL) != NULL) { - pcm_resource_x_release_snapshot(&entry->tag, state, request, - tombstone, tombstone_request, requester_node, out); + pcm_resource_x_release_snapshot(&entry->tag, state, request, tombstone, + tombstone_request, requester_node, out); LWLockRelease(&entry->entry_lock.lock); pcm_entry_ref_release(&entry_ref); return RESOURCE_X_APPLY_BAD_STATE; @@ -25890,10 +23800,8 @@ cluster_pcm_lock_resource_x_release_x_exact( * relation is not current-holder lineage and must stop before release. * This is the A' RETURN_MAINLINE lifecycle repair, not PI promotion or * an expansion of the FIFO-successor late-bind contract. */ - legacy_generation - = pg_atomic_read_u64(&entry->transition_count_local); - if (state->authority_generation == 0 - || state->authority_generation == UINT64_MAX + legacy_generation = pg_atomic_read_u64(&entry->transition_count_local); + if (state->authority_generation == 0 || state->authority_generation == UINT64_MAX || legacy_generation == UINT64_MAX || (legacy_generation != state->authority_generation && legacy_generation + 1 != state->authority_generation) @@ -25905,8 +23813,8 @@ cluster_pcm_lock_resource_x_release_x_exact( * state merely to report the refusal. */ if (!tombstone_request) request->phase = RESOURCE_X_MASTER_RECOVERY_BLOCKED; - pcm_resource_x_release_snapshot(&entry->tag, state, request, - tombstone, tombstone_request, requester_node, out); + pcm_resource_x_release_snapshot(&entry->tag, state, request, tombstone, + tombstone_request, requester_node, out); LWLockRelease(&entry->entry_lock.lock); pcm_entry_ref_release(&entry_ref); return RESOURCE_X_APPLY_RECOVERY_BLOCKED; @@ -25915,25 +23823,25 @@ cluster_pcm_lock_resource_x_release_x_exact( * requester release commit share this entry. The pre-mutation gate * above proved the exact cover, and this transition must preserve it * until the following requester commit clears the binding. */ - pcm_transition_apply_internal(entry, PCM_TRANS_X_TO_N_RELEASE, - requester_node, preserve_local_terminal_cover); + pcm_transition_apply_internal(entry, PCM_TRANS_X_TO_N_RELEASE, requester_node, + preserve_local_terminal_cover); state->authority_generation = legacy_generation + 1; released_without_successor = true; } else if (successor->phase != RESOURCE_X_MASTER_WAIT_BLOCKERS - || (successor->incompatible_holders_bitmap & requester_bit) == 0 - || (successor->blocked_holders_bitmap & requester_bit) != 0) { - pcm_resource_x_release_snapshot(&entry->tag, state, request, - tombstone, tombstone_request, requester_node, out); + || (successor->incompatible_holders_bitmap & requester_bit) == 0 + || (successor->blocked_holders_bitmap & requester_bit) != 0) { + pcm_resource_x_release_snapshot(&entry->tag, state, request, tombstone, tombstone_request, + requester_node, out); LWLockRelease(&entry->entry_lock.lock); pcm_entry_ref_release(&entry_ref); return successor->phase == RESOURCE_X_MASTER_RECOVERY_BLOCKED - ? RESOURCE_X_APPLY_RECOVERY_BLOCKED : RESOURCE_X_APPLY_BAD_STATE; + ? RESOURCE_X_APPLY_RECOVERY_BLOCKED + : RESOURCE_X_APPLY_BAD_STATE; } request->phase = RESOURCE_X_MASTER_RELEASED; - pcm_resource_x_release_snapshot(&entry->tag, state, request, - tombstone, tombstone_request, requester_node, out); - if (tombstone_request && released_without_successor - && pcm_entry_mark_quiescing_locked(entry)) { + pcm_resource_x_release_snapshot(&entry->tag, state, request, tombstone, tombstone_request, + requester_node, out); + if (tombstone_request && released_without_successor && pcm_entry_mark_quiescing_locked(entry)) { retire_tag = entry_ref.tag; retire_generation = entry_ref.binding_generation; fast_retire = true; @@ -25943,7 +23851,7 @@ cluster_pcm_lock_resource_x_release_x_exact( pcm_entry_ref_release(&entry_ref); if (fast_retire) (void)pcm_entry_try_retire_exact(&retire_tag, retire_generation, - PCM_RETIRE_REASON_RESOURCE_X_SETTLED); + PCM_RETIRE_REASON_RESOURCE_X_SETTLED); return RESOURCE_X_APPLY_APPLIED; } diff --git a/src/backend/cluster/cluster_pcm_own.c b/src/backend/cluster/cluster_pcm_own.c index 0fdeb670827..73c758bb463 100644 --- a/src/backend/cluster/cluster_pcm_own.c +++ b/src/backend/cluster/cluster_pcm_own.c @@ -345,8 +345,8 @@ cluster_pcm_own_writer_activation_clear_exact(int buf_id, uint64 expected_genera ClusterPcmOwnResult cluster_pcm_own_resource_x_activation_bind_exact(int buf_id, uint64 expected_generation, - uint64 reservation_token, - uint64 acquisition_generation) + uint64 reservation_token, + uint64 acquisition_generation) { ClusterPcmOwnEntry *entry; uint64 live_activation; @@ -365,7 +365,7 @@ cluster_pcm_own_resource_x_activation_bind_exact(int buf_id, uint64 expected_gen live_resource_x = pg_atomic_read_u64(&entry->resource_x_activation_generation); if (live_activation != reservation_token) return live_activation == 0 && live_resource_x != 0 ? CLUSTER_PCM_OWN_CORRUPT - : CLUSTER_PCM_OWN_STALE; + : CLUSTER_PCM_OWN_STALE; if (live_resource_x == acquisition_generation) return CLUSTER_PCM_OWN_OK; if (live_resource_x != 0) @@ -377,8 +377,8 @@ cluster_pcm_own_resource_x_activation_bind_exact(int buf_id, uint64 expected_gen ClusterPcmOwnResult cluster_pcm_own_resource_x_activation_clear_exact(int buf_id, uint64 expected_generation, - uint64 reservation_token, - uint64 acquisition_generation) + uint64 reservation_token, + uint64 acquisition_generation) { ClusterPcmOwnEntry *entry; @@ -390,8 +390,7 @@ cluster_pcm_own_resource_x_activation_clear_exact(int buf_id, uint64 expected_ge || pg_atomic_read_u64(&entry->reservation_token) != reservation_token || pg_atomic_read_u32(&entry->flags) != 0 || pg_atomic_read_u64(&entry->writer_activation_token) != reservation_token - || pg_atomic_read_u64(&entry->resource_x_activation_generation) - != acquisition_generation) + || pg_atomic_read_u64(&entry->resource_x_activation_generation) != acquisition_generation) return CLUSTER_PCM_OWN_STALE; /* T3 ordering is part of the local write fence: remove the target @@ -403,9 +402,8 @@ cluster_pcm_own_resource_x_activation_clear_exact(int buf_id, uint64 expected_ge ClusterPcmOwnResult cluster_pcm_own_resource_x_neutralize_exact(int buf_id, uint64 expected_generation, - uint64 reservation_token, - uint64 acquisition_generation, - uint64 *out_neutral_generation) + uint64 reservation_token, uint64 acquisition_generation, + uint64 *out_neutral_generation) { ClusterPcmOwnEntry *entry; uint64 next_generation; @@ -421,8 +419,7 @@ cluster_pcm_own_resource_x_neutralize_exact(int buf_id, uint64 expected_generati || pg_atomic_read_u64(&entry->reservation_token) != reservation_token || pg_atomic_read_u32(&entry->flags) != 0 || pg_atomic_read_u64(&entry->writer_activation_token) != reservation_token - || pg_atomic_read_u64(&entry->resource_x_activation_generation) - != acquisition_generation) + || pg_atomic_read_u64(&entry->resource_x_activation_generation) != acquisition_generation) return CLUSTER_PCM_OWN_STALE; if (expected_generation == UINT64_MAX) return CLUSTER_PCM_OWN_EXHAUSTED; diff --git a/src/backend/cluster/cluster_qvotec.c b/src/backend/cluster/cluster_qvotec.c index 759cd7ed2aa..06533a65c97 100644 --- a/src/backend/cluster/cluster_qvotec.c +++ b/src/backend/cluster/cluster_qvotec.c @@ -98,7 +98,7 @@ #include "cluster/cluster_elog.h" /* CLUSTER_LOG (best-effort logging) */ #include "cluster/cluster_epoch.h" /* spec-4.12b D2/D5: current-epoch upper-bound Assert */ #include "cluster/cluster_epoch_ballot.h" -#include "cluster/cluster_guc.h" /* cluster_enabled */ +#include "cluster/cluster_guc.h" /* cluster_enabled */ #include "cluster/cluster_inject.h" #include "cluster/cluster_replacement_request.h" #include "cluster/cluster_semantic_activation.h" @@ -177,13 +177,13 @@ typedef struct ClusterQvotecShmem { } ClusterQvotecShmem; StaticAssertDecl(sizeof(ClusterQvotecShmem) == CLUSTER_QVOTEC_SHMEM_BYTES, - "ClusterQvotecShmem must be exactly 448 bytes"); + "ClusterQvotecShmem must be exactly 448 bytes"); StaticAssertDecl(offsetof(ClusterQvotecShmem, self_incarnation) == 64, - "ClusterQvotecShmem self incarnation offset"); + "ClusterQvotecShmem self incarnation offset"); StaticAssertDecl(offsetof(ClusterQvotecShmem, prior_unclean_death) == 72, - "prior_unclean_death must sit at offset 72 (queue lane owns 64..71)"); + "prior_unclean_death must sit at offset 72 (queue lane owns 64..71)"); StaticAssertDecl(offsetof(ClusterQvotecShmem, mailbox) == CLUSTER_QVOTEC_SHMEM_PREFIX_BYTES, - "ClusterQvotecShmem mailbox must start at absolute offset 128"); + "ClusterQvotecShmem mailbox must start at absolute offset 128"); StaticAssertDecl(offsetof(ClusterQvotecShmem, diagnostic_cycle_started_us) == 80, "diagnostic timestamps must occupy only the former reserved prefix"); @@ -542,9 +542,9 @@ cluster_qvotec_mailbox_restart_reset(ClusterQvotecMailbox *mailbox) } ClusterQvotecMailboxSubmitStatus -cluster_qvotec_mailbox_lmon_submit( - ClusterQvotecMailbox *mailbox, ClusterQvotecMailboxOpcode opcode, - const uint8 request_value[CLUSTER_QVOTEC_AUTHORITY_VALUE_BYTES], uint64 *request_seq_out) +cluster_qvotec_mailbox_lmon_submit(ClusterQvotecMailbox *mailbox, ClusterQvotecMailboxOpcode opcode, + const uint8 request_value[CLUSTER_QVOTEC_AUTHORITY_VALUE_BYTES], + uint64 *request_seq_out) { uint64 request_seq; uint64 completion_seq; @@ -584,7 +584,7 @@ cluster_qvotec_mailbox_lmon_submit( bool cluster_qvotec_mailbox_qvotec_poll(ClusterQvotecMailbox *mailbox, - ClusterQvotecMailboxRequest *request_out) + ClusterQvotecMailboxRequest *request_out) { ClusterQvotecMailboxRequest snapshot; uint64 request_seq_before; @@ -615,7 +615,7 @@ cluster_qvotec_mailbox_qvotec_poll(ClusterQvotecMailbox *mailbox, || !qvotec_mailbox_opcode_valid(opcode) || (opcode == CLUSTER_QVOTEC_MAILBOX_RECOVER_HEAD && !qvotec_mailbox_bytes_are_zero(snapshot.request_value, - CLUSTER_QVOTEC_AUTHORITY_VALUE_BYTES))) + CLUSTER_QVOTEC_AUTHORITY_VALUE_BYTES))) return false; *request_out = snapshot; @@ -623,9 +623,8 @@ cluster_qvotec_mailbox_qvotec_poll(ClusterQvotecMailbox *mailbox, } bool -cluster_qvotec_mailbox_qvotec_complete( - ClusterQvotecMailbox *mailbox, uint8 configured_disk_bitmap, - const ClusterQvotecMailboxCompletion *completion) +cluster_qvotec_mailbox_qvotec_complete(ClusterQvotecMailbox *mailbox, uint8 configured_disk_bitmap, + const ClusterQvotecMailboxCompletion *completion) { uint64 request_seq; uint64 completion_seq; @@ -665,9 +664,8 @@ cluster_qvotec_mailbox_qvotec_complete( } bool -cluster_qvotec_mailbox_lmon_poll_completion( - ClusterQvotecMailbox *mailbox, uint64 request_seq, - ClusterQvotecMailboxCompletion *completion_out) +cluster_qvotec_mailbox_lmon_poll_completion(ClusterQvotecMailbox *mailbox, uint64 request_seq, + ClusterQvotecMailboxCompletion *completion_out) { ClusterQvotecMailboxCompletion snapshot; uint64 completion_seq_before; @@ -690,8 +688,7 @@ cluster_qvotec_mailbox_lmon_poll_completion( snapshot.request_seq = request_seq; result = pg_atomic_read_u32(&mailbox->completion_result); snapshot.result = (ClusterQvotecMailboxResult)result; - memcpy(snapshot.completion_value, mailbox->completion_value, - sizeof(snapshot.completion_value)); + memcpy(snapshot.completion_value, mailbox->completion_value, sizeof(snapshot.completion_value)); memcpy(snapshot.completion_ballot, mailbox->completion_ballot, sizeof(snapshot.completion_ballot)); snapshot.observed_disk_bitmap = mailbox->observed_disk_bitmap; @@ -713,23 +710,22 @@ cluster_qvotec_mailbox_lmon_poll_completion( ClusterQvotecMailboxSubmitStatus cluster_qvotec_authority_lmon_submit( ClusterQvotecMailboxOpcode opcode, - const uint8 request_value[CLUSTER_QVOTEC_AUTHORITY_VALUE_BYTES], - uint64 *request_seq_out) + const uint8 request_value[CLUSTER_QVOTEC_AUTHORITY_VALUE_BYTES], uint64 *request_seq_out) { if (QvotecShmem == NULL) return CLUSTER_QVOTEC_MAILBOX_SUBMIT_HOLD; - return cluster_qvotec_mailbox_lmon_submit( - &QvotecShmem->mailbox, opcode, request_value, request_seq_out); + return cluster_qvotec_mailbox_lmon_submit(&QvotecShmem->mailbox, opcode, request_value, + request_seq_out); } bool -cluster_qvotec_authority_lmon_poll_completion( - uint64 request_seq, ClusterQvotecMailboxCompletion *completion_out) +cluster_qvotec_authority_lmon_poll_completion(uint64 request_seq, + ClusterQvotecMailboxCompletion *completion_out) { if (QvotecShmem == NULL) return false; - return cluster_qvotec_mailbox_lmon_poll_completion( - &QvotecShmem->mailbox, request_seq, completion_out); + return cluster_qvotec_mailbox_lmon_poll_completion(&QvotecShmem->mailbox, request_seq, + completion_out); } Size @@ -1097,8 +1093,7 @@ cluster_writes_currently_frozen(void) * ============================================================ */ #include "cluster/cluster_voting_disk_io.h" /* fd open/close + format */ -StaticAssertDecl(CLUSTER_UNDO_ROOT_DESCRIPTOR_FILE_BYTES_MIN - == CLUSTER_VOTING_PGRD_FILE_BYTES_MIN, +StaticAssertDecl(CLUSTER_UNDO_ROOT_DESCRIPTOR_FILE_BYTES_MIN == CLUSTER_VOTING_PGRD_FILE_BYTES_MIN, "PGRD voting capacity bounds must match"); static bool @@ -1114,15 +1109,13 @@ qvotec_pgsa_bytes_are_zero(const uint8 bytes[CLUSTER_SEMANTIC_ACTIVATION_RECORD_ } static ClusterUndoRootDescriptorState qvotec_undo_root_descriptor_read_fds( - const int *fds, int n_disks, uint64 system_identifier, - uint8 root_kind, int32 owner_node, ClusterUndoRootDescriptorV1 *out, - uint8 *out_observed_disk_bitmap); + const int *fds, int n_disks, uint64 system_identifier, uint8 root_kind, int32 owner_node, + ClusterUndoRootDescriptorV1 *out, uint8 *out_observed_disk_bitmap); static bool -qvotec_undo_root_descriptor_provision_fds( - const int *fds, int n_disks, uint64 system_identifier, - const uint8 desired[CLUSTER_UNDO_ROOT_DESCRIPTOR_BYTES], - uint8 *out_completed_disk_bitmap) +qvotec_undo_root_descriptor_provision_fds(const int *fds, int n_disks, uint64 system_identifier, + const uint8 desired[CLUSTER_UNDO_ROOT_DESCRIPTOR_BYTES], + uint8 *out_completed_disk_bitmap) { bool eligible[CLUSTER_MAX_VOTING_DISKS] = { false }; bool wrote[CLUSTER_MAX_VOTING_DISKS] = { false }; @@ -1136,18 +1129,16 @@ qvotec_undo_root_descriptor_provision_fds( int majority; int i; - if (fds == NULL || desired == NULL || out_completed_disk_bitmap == NULL - || n_disks <= 0 || n_disks > CLUSTER_MAX_VOTING_DISKS - || cluster_undo_root_descriptor_decode( - desired, system_identifier, &descriptor) + if (fds == NULL || desired == NULL || out_completed_disk_bitmap == NULL || n_disks <= 0 + || n_disks > CLUSTER_MAX_VOTING_DISKS + || cluster_undo_root_descriptor_decode(desired, system_identifier, &descriptor) != CLUSTER_UNDO_ROOT_DESCRIPTOR_VALID || descriptor.descriptor_incarnation != 1) return false; if (descriptor.root_kind == CLUSTER_UNDO_ROOT_KIND_SHARED) offset = CLUSTER_UNDO_ROOT_DESCRIPTOR_SHARED_OFFSET; else if (descriptor.root_kind == CLUSTER_UNDO_ROOT_KIND_LOCAL) - offset = CLUSTER_UNDO_ROOT_DESCRIPTOR_LOCAL_OFFSET( - descriptor.owner_node); + offset = CLUSTER_UNDO_ROOT_DESCRIPTOR_LOCAL_OFFSET(descriptor.owner_node); else return false; @@ -1158,8 +1149,7 @@ qvotec_undo_root_descriptor_provision_fds( ClusterUndoRootDescriptorState descriptor_state; memset(image, 0, sizeof(image)); - read_state = cluster_voting_disk_read_raw_slot_at( - fds[i], offset, image); + read_state = cluster_voting_disk_read_raw_slot_at(fds[i], offset, image); if (read_state == CLUSTER_VOTING_DISK_RAW_READ_CLEAN_EOF) { eligible[i] = true; eligible_count++; @@ -1169,8 +1159,7 @@ qvotec_undo_root_descriptor_provision_fds( return false; if (read_state != CLUSTER_VOTING_DISK_RAW_READ_FULL) continue; - descriptor_state = cluster_undo_root_descriptor_decode( - image, system_identifier, &observed); + descriptor_state = cluster_undo_root_descriptor_decode(image, system_identifier, &observed); if (descriptor_state == CLUSTER_UNDO_ROOT_DESCRIPTOR_UNPROVISIONED || (descriptor_state == CLUSTER_UNDO_ROOT_DESCRIPTOR_VALID && memcmp(image, desired, sizeof(image)) == 0)) { @@ -1201,9 +1190,8 @@ qvotec_undo_root_descriptor_provision_fds( } if (completed_count < majority) return false; - if (qvotec_undo_root_descriptor_read_fds( - fds, n_disks, system_identifier, descriptor.root_kind, - descriptor.owner_node, &committed, &observed_bitmap) + if (qvotec_undo_root_descriptor_read_fds(fds, n_disks, system_identifier, descriptor.root_kind, + descriptor.owner_node, &committed, &observed_bitmap) != CLUSTER_UNDO_ROOT_DESCRIPTOR_VALID || !cluster_undo_root_descriptor_encode(&committed, image) || memcmp(image, desired, sizeof(image)) != 0) @@ -1213,13 +1201,12 @@ qvotec_undo_root_descriptor_provision_fds( } static ClusterUndoRootDescriptorState -qvotec_undo_root_descriptor_read_fds( - const int *fds, int n_disks, uint64 system_identifier, - uint8 root_kind, int32 owner_node, ClusterUndoRootDescriptorV1 *out, - uint8 *out_observed_disk_bitmap) +qvotec_undo_root_descriptor_read_fds(const int *fds, int n_disks, uint64 system_identifier, + uint8 root_kind, int32 owner_node, + ClusterUndoRootDescriptorV1 *out, + uint8 *out_observed_disk_bitmap) { - uint8 images[CLUSTER_MAX_VOTING_DISKS] - [CLUSTER_UNDO_ROOT_DESCRIPTOR_BYTES]; + uint8 images[CLUSTER_MAX_VOTING_DISKS][CLUSTER_UNDO_ROOT_DESCRIPTOR_BYTES]; ClusterUndoRootDescriptorV1 descriptors[CLUSTER_MAX_VOTING_DISKS]; ClusterUndoRootDescriptorState states[CLUSTER_MAX_VOTING_DISKS]; bool valid[CLUSTER_MAX_VOTING_DISKS] = { false }; @@ -1232,8 +1219,7 @@ qvotec_undo_root_descriptor_read_fds( memset(out, 0, sizeof(*out)); if (out_observed_disk_bitmap != NULL) *out_observed_disk_bitmap = 0; - if (fds == NULL || n_disks <= 0 - || n_disks > CLUSTER_MAX_VOTING_DISKS || system_identifier == 0 + if (fds == NULL || n_disks <= 0 || n_disks > CLUSTER_MAX_VOTING_DISKS || system_identifier == 0 || out == NULL || out_observed_disk_bitmap == NULL) return CLUSTER_UNDO_ROOT_DESCRIPTOR_HOLD; if (root_kind == CLUSTER_UNDO_ROOT_KIND_SHARED && owner_node == -1) @@ -1251,8 +1237,7 @@ qvotec_undo_root_descriptor_read_fds( for (i = 0; i < n_disks; i++) { ClusterVotingDiskRawReadState read_state; - read_state = cluster_voting_disk_read_raw_slot_at( - fds[i], offset, images[i]); + read_state = cluster_voting_disk_read_raw_slot_at(fds[i], offset, images[i]); if (read_state == CLUSTER_VOTING_DISK_RAW_READ_CLEAN_EOF) { states[i] = CLUSTER_UNDO_ROOT_DESCRIPTOR_UNPROVISIONED; valid[i] = true; @@ -1260,8 +1245,8 @@ qvotec_undo_root_descriptor_read_fds( } if (read_state != CLUSTER_VOTING_DISK_RAW_READ_FULL) return CLUSTER_UNDO_ROOT_DESCRIPTOR_HOLD; - states[i] = cluster_undo_root_descriptor_decode( - images[i], system_identifier, &descriptors[i]); + states[i] + = cluster_undo_root_descriptor_decode(images[i], system_identifier, &descriptors[i]); if (states[i] == CLUSTER_UNDO_ROOT_DESCRIPTOR_UNPROVISIONED) valid[i] = true; else if (states[i] == CLUSTER_UNDO_ROOT_DESCRIPTOR_VALID @@ -1279,8 +1264,7 @@ qvotec_undo_root_descriptor_read_fds( continue; for (j = i + 1; j < n_disks; j++) { if (states[j] == CLUSTER_UNDO_ROOT_DESCRIPTOR_VALID - && descriptors[i].descriptor_incarnation - == descriptors[j].descriptor_incarnation + && descriptors[i].descriptor_incarnation == descriptors[j].descriptor_incarnation && memcmp(images[i], images[j], sizeof(images[i])) != 0) return CLUSTER_UNDO_ROOT_DESCRIPTOR_HOLD; } @@ -1293,8 +1277,7 @@ qvotec_undo_root_descriptor_read_fds( if (!valid[i]) continue; for (j = 0; j < n_disks; j++) { - if (valid[j] - && memcmp(images[i], images[j], sizeof(images[i])) == 0) + if (valid[j] && memcmp(images[i], images[j], sizeof(images[i])) == 0) identical++; } if (identical >= majority) { @@ -1306,8 +1289,7 @@ qvotec_undo_root_descriptor_read_fds( return CLUSTER_UNDO_ROOT_DESCRIPTOR_HOLD; for (i = 0; i < n_disks; i++) { - if (valid[i] - && memcmp(images[selected], images[i], sizeof(images[i])) == 0) + if (valid[i] && memcmp(images[selected], images[i], sizeof(images[i])) == 0) *out_observed_disk_bitmap |= (uint8)(UINT8_C(1) << i); } if (states[selected] == CLUSTER_UNDO_ROOT_DESCRIPTOR_UNPROVISIONED) @@ -1317,13 +1299,11 @@ qvotec_undo_root_descriptor_read_fds( } static bool -qvotec_undo_root_descriptor_formation_attested_fds( - const int *fds, int n_disks) +qvotec_undo_root_descriptor_formation_attested_fds(const int *fds, int n_disks) { int i; - if (fds == NULL - || (n_disks != 1 && n_disks != 3 && n_disks != 5 && n_disks != 7)) + if (fds == NULL || (n_disks != 1 && n_disks != 3 && n_disks != 5 && n_disks != 7)) return false; for (i = 0; i < n_disks; i++) { if (!cluster_voting_disk_pgrd_authority_attest(fds[i])) @@ -1334,12 +1314,10 @@ qvotec_undo_root_descriptor_formation_attested_fds( static ClusterSemanticActivationResult qvotec_semantic_activation_record_read_fds( - const int *fds, int n_disks, - uint8 selected_bytes[CLUSTER_SEMANTIC_ACTIVATION_RECORD_BYTES], + const int *fds, int n_disks, uint8 selected_bytes[CLUSTER_SEMANTIC_ACTIVATION_RECORD_BYTES], bool *implicit_open) { - uint8 images[CLUSTER_MAX_VOTING_DISKS] - [CLUSTER_SEMANTIC_ACTIVATION_RECORD_BYTES]; + uint8 images[CLUSTER_MAX_VOTING_DISKS][CLUSTER_SEMANTIC_ACTIVATION_RECORD_BYTES]; ClusterSemanticActivationRecord records[CLUSTER_MAX_VOTING_DISKS]; bool valid[CLUSTER_MAX_VOTING_DISKS]; bool nonzero[CLUSTER_MAX_VOTING_DISKS]; @@ -1348,13 +1326,11 @@ qvotec_semantic_activation_record_read_fds( int i; if (selected_bytes != NULL) - memset(selected_bytes, 0, - CLUSTER_SEMANTIC_ACTIVATION_RECORD_BYTES); + memset(selected_bytes, 0, CLUSTER_SEMANTIC_ACTIVATION_RECORD_BYTES); if (implicit_open != NULL) *implicit_open = false; - if (fds == NULL || n_disks <= 0 - || n_disks > CLUSTER_MAX_VOTING_DISKS - || selected_bytes == NULL || implicit_open == NULL) + if (fds == NULL || n_disks <= 0 || n_disks > CLUSTER_MAX_VOTING_DISKS || selected_bytes == NULL + || implicit_open == NULL) return CLUSTER_SEMANTIC_ACTIVATION_QUORUM_HOLD; memset(images, 0, sizeof(images)); @@ -1376,8 +1352,7 @@ qvotec_semantic_activation_record_read_fds( valid[i] = true; continue; } - if (cluster_semantic_activation_record_decode( - images[i], &records[i], NULL)) { + if (cluster_semantic_activation_record_decode(images[i], &records[i], NULL)) { valid[i] = true; nonzero[i] = true; } @@ -1390,8 +1365,7 @@ qvotec_semantic_activation_record_read_fds( if (!valid[i]) continue; for (j = 0; j < n_disks; j++) { - if (valid[j] - && memcmp(images[i], images[j], sizeof(images[i])) == 0) + if (valid[j] && memcmp(images[i], images[j], sizeof(images[i])) == 0) identical++; } if (identical >= majority) { @@ -1400,8 +1374,7 @@ qvotec_semantic_activation_record_read_fds( } } if (selected >= 0) { - memcpy(selected_bytes, images[selected], - CLUSTER_SEMANTIC_ACTIVATION_RECORD_BYTES); + memcpy(selected_bytes, images[selected], CLUSTER_SEMANTIC_ACTIVATION_RECORD_BYTES); *implicit_open = !nonzero[selected]; return CLUSTER_SEMANTIC_ACTIVATION_OK; } @@ -1413,8 +1386,7 @@ qvotec_semantic_activation_record_read_fds( continue; for (j = i + 1; j < n_disks; j++) { if (valid[j] && nonzero[j] - && records[i].record_generation - == records[j].record_generation + && records[i].record_generation == records[j].record_generation && memcmp(images[i], images[j], sizeof(images[i])) != 0) return CLUSTER_SEMANTIC_ACTIVATION_RECORD_CONFLICT; } @@ -1490,7 +1462,7 @@ cluster_qvotec_bootstrap_read_undo_root_descriptor( int n_disks; int i; uint8 bitmap; - uint8 bytes[CLUSTER_UNDO_ROOT_DESCRIPTOR_BYTES] = {0}; + uint8 bytes[CLUSTER_UNDO_ROOT_DESCRIPTOR_BYTES] = { 0 }; ClusterUndoRootDescriptorV1 descriptor; ClusterUndoRootDescriptorState result; @@ -1499,8 +1471,8 @@ cluster_qvotec_bootstrap_read_undo_root_descriptor( n_disks = qvotec_bootstrap_open_readonly(fds); if (n_disks < 0) return CLUSTER_UNDO_ROOT_DESCRIPTOR_HOLD; - result = qvotec_undo_root_descriptor_read_fds(fds, n_disks, system_identifier, - CLUSTER_UNDO_ROOT_KIND_SHARED, -1, &descriptor, &bitmap); + result = qvotec_undo_root_descriptor_read_fds( + fds, n_disks, system_identifier, CLUSTER_UNDO_ROOT_KIND_SHARED, -1, &descriptor, &bitmap); for (i = 0; i < n_disks; i++) cluster_voting_disk_close(fds[i]); if (result == CLUSTER_UNDO_ROOT_DESCRIPTOR_HOLD @@ -1535,8 +1507,7 @@ cluster_qvotec_bootstrap_read_semantic_activation( static ClusterSemanticActivationResult qvotec_semantic_activation_record_cas_write_fds( - const int *fds, int n_disks, uint64 expected_generation, - uint64 expected_source_feature_bitmap, + const int *fds, int n_disks, uint64 expected_generation, uint64 expected_source_feature_bitmap, const uint8 desired_bytes[CLUSTER_SEMANTIC_ACTIVATION_RECORD_BYTES]) { uint8 current_images[CLUSTER_MAX_VOTING_DISKS][CLUSTER_SEMANTIC_ACTIVATION_RECORD_BYTES]; @@ -1570,7 +1541,7 @@ qvotec_semantic_activation_record_cas_write_fds( } else if (read_state == CLUSTER_VOTING_DISK_RAW_READ_FULL && (qvotec_pgsa_bytes_are_zero(current_images[i]) || cluster_semantic_activation_record_decode(current_images[i], - ¤t_record, NULL))) + ¤t_record, NULL))) current_valid[i] = true; } @@ -1595,30 +1566,29 @@ qvotec_semantic_activation_record_cas_write_fds( if (selected < 0) return CLUSTER_SEMANTIC_ACTIVATION_QUORUM_HOLD; - if (memcmp(current_images[selected], desired_bytes, - CLUSTER_SEMANTIC_ACTIVATION_RECORD_BYTES) + if (memcmp(current_images[selected], desired_bytes, CLUSTER_SEMANTIC_ACTIVATION_RECORD_BYTES) == 0) return CLUSTER_SEMANTIC_ACTIVATION_OK; memset(¤t_record, 0, sizeof(current_record)); if (!qvotec_pgsa_bytes_are_zero(current_images[selected]) && !cluster_semantic_activation_record_decode(current_images[selected], ¤t_record, - NULL)) + NULL)) return CLUSTER_SEMANTIC_ACTIVATION_QUORUM_HOLD; if (qvotec_pgsa_bytes_are_zero(current_images[selected])) current_source_feature_bitmap = 0; else { switch (current_record.phase) { - case CLUSTER_SEMANTIC_PHASE_PREPARE: - case CLUSTER_SEMANTIC_PHASE_COMMIT: - current_source_feature_bitmap = current_record.source_feature_bitmap; - break; - case CLUSTER_SEMANTIC_PHASE_OPEN: - case CLUSTER_SEMANTIC_PHASE_ROLLBACK_COMPLETE: - current_source_feature_bitmap = current_record.target_feature_bitmap; - break; - default: - return CLUSTER_SEMANTIC_ACTIVATION_QUORUM_HOLD; + case CLUSTER_SEMANTIC_PHASE_PREPARE: + case CLUSTER_SEMANTIC_PHASE_COMMIT: + current_source_feature_bitmap = current_record.source_feature_bitmap; + break; + case CLUSTER_SEMANTIC_PHASE_OPEN: + case CLUSTER_SEMANTIC_PHASE_ROLLBACK_COMPLETE: + current_source_feature_bitmap = current_record.target_feature_bitmap; + break; + default: + return CLUSTER_SEMANTIC_ACTIVATION_QUORUM_HOLD; } } if (current_record.record_generation != expected_generation @@ -1626,7 +1596,7 @@ qvotec_semantic_activation_record_cas_write_fds( return CLUSTER_SEMANTIC_ACTIVATION_RECORD_CONFLICT; for (i = 0; i < n_disks; i++) - (void) cluster_voting_disk_write_raw_tail_slot(fds[i], desired_bytes); + (void)cluster_voting_disk_write_raw_tail_slot(fds[i], desired_bytes); { int desired_count = 0; @@ -1635,14 +1605,13 @@ qvotec_semantic_activation_record_cas_write_fds( uint8 reread[CLUSTER_SEMANTIC_ACTIVATION_RECORD_BYTES]; ClusterVotingDiskRawReadState read_state; - read_state - = cluster_voting_disk_read_raw_tail_slot(fds[i], reread); + read_state = cluster_voting_disk_read_raw_tail_slot(fds[i], reread); if (read_state == CLUSTER_VOTING_DISK_RAW_READ_FULL && memcmp(reread, desired_bytes, sizeof(reread)) == 0) desired_count++; } return desired_count >= majority ? CLUSTER_SEMANTIC_ACTIVATION_OK - : CLUSTER_SEMANTIC_ACTIVATION_QUORUM_HOLD; + : CLUSTER_SEMANTIC_ACTIVATION_QUORUM_HOLD; } } @@ -1661,18 +1630,17 @@ cluster_semantic_activation_record_cas_write( * Keeping the per-disk intersection here prevents two different majorities * (write success on A/B, stale exact bytes on B/C) from forming a false ACK. */ static bool -qvotec_join_marker_ack_proven_fds( - const int *fds, int n_disks, int32 target_node, - const uint8 staged_slot[CLUSTER_VOTING_SLOT_BYTES], - const bool write_succeeded[CLUSTER_MAX_VOTING_DISKS]) +qvotec_join_marker_ack_proven_fds(const int *fds, int n_disks, int32 target_node, + const uint8 staged_slot[CLUSTER_VOTING_SLOT_BYTES], + const bool write_succeeded[CLUSTER_MAX_VOTING_DISKS]) { uint32 exact = 0; uint32 majority; int i; - if (fds == NULL || staged_slot == NULL || write_succeeded == NULL - || n_disks <= 0 || n_disks > CLUSTER_MAX_VOTING_DISKS - || target_node < 0 || target_node >= CLUSTER_MAX_NODES) + if (fds == NULL || staged_slot == NULL || write_succeeded == NULL || n_disks <= 0 + || n_disks > CLUSTER_MAX_VOTING_DISKS || target_node < 0 + || target_node >= CLUSTER_MAX_NODES) return false; majority = ((uint32)n_disks / 2u) + 1u; @@ -1682,8 +1650,7 @@ qvotec_join_marker_ack_proven_fds( if (!write_succeeded[i]) continue; memset(reread, 0, sizeof(reread)); - if (cluster_voting_disk_read_join_slot( - fds[i], (uint32)target_node, reread) + if (cluster_voting_disk_read_join_slot(fds[i], (uint32)target_node, reread) == CLUSTER_VOTING_DISK_IO_OK && memcmp(reread, staged_slot, sizeof(reread)) == 0) exact++; @@ -1709,9 +1676,8 @@ qvotec_join_marker_verify_committed_closed_fds( if (verified_image96 == NULL) return false; memset(verified_image96, 0, CLUSTER_JCMK_REPLACEMENT_BYTES); - if (fds == NULL || n_disks <= 0 - || n_disks > CLUSTER_MAX_VOTING_DISKS - || target_node < 0 || target_node >= CLUSTER_MAX_NODES) + if (fds == NULL || n_disks <= 0 || n_disks > CLUSTER_MAX_VOTING_DISKS || target_node < 0 + || target_node >= CLUSTER_MAX_NODES) return false; memset(images, 0, sizeof(images)); @@ -1720,42 +1686,39 @@ qvotec_join_marker_verify_committed_closed_fds( uint64 incarnation_floor; memset(slot, 0, sizeof(slot)); - if (cluster_voting_disk_read_join_slot( - fds[i], (uint32)target_node, slot) + if (cluster_voting_disk_read_join_slot(fds[i], (uint32)target_node, slot) == CLUSTER_VOTING_DISK_IO_OK - && cluster_replacement_marker_v3_is_committed_closed_basis( - slot, target_node, &incarnation_floor)) + && cluster_replacement_marker_v3_is_committed_closed_basis(slot, target_node, + &incarnation_floor)) memcpy(images[i], slot, CLUSTER_JCMK_REPLACEMENT_BYTES); } majority = ((uint32)n_disks / 2u) + 1u; - selected = cluster_replacement_marker_v3_select_majority( - images, n_disks, majority, target_node, &winner, NULL); - if (selected < 0 - || !cluster_replacement_marker_v3_encode(&winner, canonical) + selected = cluster_replacement_marker_v3_select_majority(images, n_disks, majority, target_node, + &winner, NULL); + if (selected < 0 || !cluster_replacement_marker_v3_encode(&winner, canonical) || memcmp(canonical, images[selected], sizeof(canonical)) != 0) return false; memcpy(verified_image96, canonical, sizeof(canonical)); return true; } -static bool qvotec_epoch_ballot_phase1_promise_fds( - const int *fds, int n_disks, uint64 system_identifier, - const uint64 admitted_incarnations[CLUSTER_MAX_NODES], - int32 proposer_node_id, const ClusterEpochBallotId *ballot, - uint8 *out_completed_disk_bitmap) pg_attribute_unused(); +static bool +qvotec_epoch_ballot_phase1_promise_fds(const int *fds, int n_disks, uint64 system_identifier, + const uint64 admitted_incarnations[CLUSTER_MAX_NODES], + int32 proposer_node_id, const ClusterEpochBallotId *ballot, + uint8 *out_completed_disk_bitmap) pg_attribute_unused(); static bool -qvotec_epoch_ballot_component_monotone( - const ClusterEpochBallotId *older_ballot, - const ClusterEpochAuthorityValue *older_value, - const ClusterEpochBallotId *newer_ballot, - const ClusterEpochAuthorityValue *newer_value) +qvotec_epoch_ballot_component_monotone(const ClusterEpochBallotId *older_ballot, + const ClusterEpochAuthorityValue *older_value, + const ClusterEpochBallotId *newer_ballot, + const ClusterEpochAuthorityValue *newer_value) { - bool older_zero = qvotec_mailbox_bytes_are_zero( - (const uint8 *)older_ballot, sizeof(*older_ballot)); - bool newer_zero = qvotec_mailbox_bytes_are_zero( - (const uint8 *)newer_ballot, sizeof(*newer_ballot)); + bool older_zero + = qvotec_mailbox_bytes_are_zero((const uint8 *)older_ballot, sizeof(*older_ballot)); + bool newer_zero + = qvotec_mailbox_bytes_are_zero((const uint8 *)newer_ballot, sizeof(*newer_ballot)); int cmp; if (older_zero) @@ -1763,25 +1726,20 @@ qvotec_epoch_ballot_component_monotone( if (newer_zero) return false; cmp = cluster_epoch_ballot_id_compare(older_ballot, newer_ballot); - return cmp < 0 - || (cmp == 0 - && memcmp(older_value, newer_value, sizeof(*older_value)) == 0); + return cmp < 0 || (cmp == 0 && memcmp(older_value, newer_value, sizeof(*older_value)) == 0); } static bool -qvotec_epoch_ballot_lane_monotone( - const ClusterEpochBallotLane *older, - const ClusterEpochBallotLane *newer) +qvotec_epoch_ballot_lane_monotone(const ClusterEpochBallotLane *older, + const ClusterEpochBallotLane *newer) { return older->lane_generation < newer->lane_generation - && cluster_epoch_ballot_id_compare( - &older->promised_ballot, &newer->promised_ballot) <= 0 + && cluster_epoch_ballot_id_compare(&older->promised_ballot, &newer->promised_ballot) <= 0 && qvotec_epoch_ballot_component_monotone( - &older->accepted_ballot, &older->accepted_value, - &newer->accepted_ballot, &newer->accepted_value) - && qvotec_epoch_ballot_component_monotone( - &older->settled_ballot, &older->settled_value, - &newer->settled_ballot, &newer->settled_value); + &older->accepted_ballot, &older->accepted_value, &newer->accepted_ballot, + &newer->accepted_value) + && qvotec_epoch_ballot_component_monotone(&older->settled_ballot, &older->settled_value, + &newer->settled_ballot, &newer->settled_value); } /* Execute only the durable PHASE-1 primitive from spec-5.15A §2.1A.2. @@ -1789,11 +1747,10 @@ qvotec_epoch_ballot_lane_monotone( * ballot reached durable disks before a later all-lane scan observed a higher * promise, so the owning actor must RECOVER before minting its retry. */ static bool -qvotec_epoch_ballot_phase1_promise_fds( - const int *fds, int n_disks, uint64 system_identifier, - const uint64 admitted_incarnations[CLUSTER_MAX_NODES], - int32 proposer_node_id, const ClusterEpochBallotId *ballot, - uint8 *out_completed_disk_bitmap) +qvotec_epoch_ballot_phase1_promise_fds(const int *fds, int n_disks, uint64 system_identifier, + const uint64 admitted_incarnations[CLUSTER_MAX_NODES], + int32 proposer_node_id, const ClusterEpochBallotId *ballot, + uint8 *out_completed_disk_bitmap) { ClusterEpochBallotLane base; ClusterEpochBallotLane promised; @@ -1809,17 +1766,13 @@ qvotec_epoch_ballot_phase1_promise_fds( if (out_completed_disk_bitmap != NULL) *out_completed_disk_bitmap = 0; - if (fds == NULL || admitted_incarnations == NULL - || out_completed_disk_bitmap == NULL || ballot == NULL - || n_disks <= 0 || n_disks > CLUSTER_MAX_VOTING_DISKS - || (n_disks != 1 && n_disks != 3 && n_disks != 5 && n_disks != 7) - || system_identifier == 0 || proposer_node_id < 0 - || proposer_node_id >= CLUSTER_MAX_NODES - || admitted_incarnations[proposer_node_id] == 0 - || !cluster_epoch_ballot_id_is_valid(ballot) + if (fds == NULL || admitted_incarnations == NULL || out_completed_disk_bitmap == NULL + || ballot == NULL || n_disks <= 0 || n_disks > CLUSTER_MAX_VOTING_DISKS + || (n_disks != 1 && n_disks != 3 && n_disks != 5 && n_disks != 7) || system_identifier == 0 + || proposer_node_id < 0 || proposer_node_id >= CLUSTER_MAX_NODES + || admitted_incarnations[proposer_node_id] == 0 || !cluster_epoch_ballot_id_is_valid(ballot) || ballot->proposer_node_id != proposer_node_id - || ballot->proposer_admitted_incarnation - != admitted_incarnations[proposer_node_id]) + || ballot->proposer_admitted_incarnation != admitted_incarnations[proposer_node_id]) return false; memset(&base, 0, sizeof(base)); @@ -1837,18 +1790,15 @@ qvotec_epoch_ballot_phase1_promise_fds( for (d = 0; d < n_disks; d++) { uint8 image[CLUSTER_EPOCH_BALLOT_LANE_BYTES]; - if (cluster_voting_disk_read_epoch_ballot_slot( - fds[d], (uint32)proposer, image) - != CLUSTER_VOTING_DISK_IO_OK) + if (cluster_voting_disk_read_epoch_ballot_slot(fds[d], (uint32)proposer, image) + != CLUSTER_VOTING_DISK_IO_OK) return false; if (qvotec_mailbox_bytes_are_zero(image, sizeof(image))) continue; if (admitted_incarnations[proposer] == 0 || !cluster_epoch_ballot_lane_decode( - image, proposer, (uint32)n_disks, - admitted_incarnations[proposer], system_identifier, - CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT, - &lanes[d])) + image, proposer, (uint32)n_disks, admitted_incarnations[proposer], + system_identifier, CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT, &lanes[d])) return false; valid[d] = true; } @@ -1862,30 +1812,25 @@ qvotec_epoch_ballot_phase1_promise_fds( if (!valid[other]) continue; - if (lanes[d].lane_generation - == lanes[other].lane_generation) { - if (memcmp(&lanes[d], &lanes[other], - sizeof(lanes[d])) != 0) + if (lanes[d].lane_generation == lanes[other].lane_generation) { + if (memcmp(&lanes[d], &lanes[other], sizeof(lanes[d])) != 0) return false; continue; } - older = lanes[d].lane_generation - < lanes[other].lane_generation - ? &lanes[d] : &lanes[other]; + older = lanes[d].lane_generation < lanes[other].lane_generation ? &lanes[d] + : &lanes[other]; newer = older == &lanes[d] ? &lanes[other] : &lanes[d]; if (!qvotec_epoch_ballot_lane_monotone(older, newer)) return false; } if (!have_max_observed_promise - || cluster_epoch_ballot_id_compare( - &lanes[d].promised_ballot, - &max_observed_promise) > 0) { + || cluster_epoch_ballot_id_compare(&lanes[d].promised_ballot, &max_observed_promise) + > 0) { max_observed_promise = lanes[d].promised_ballot; have_max_observed_promise = true; } if (proposer == proposer_node_id - && (!have_base - || lanes[d].lane_generation > base.lane_generation)) { + && (!have_base || lanes[d].lane_generation > base.lane_generation)) { base = lanes[d]; have_base = true; } @@ -1893,8 +1838,7 @@ qvotec_epoch_ballot_phase1_promise_fds( } if (have_max_observed_promise - && cluster_epoch_ballot_id_compare( - ballot, &max_observed_promise) <= 0) + && cluster_epoch_ballot_id_compare(ballot, &max_observed_promise) <= 0) return false; if (have_base) { @@ -1908,31 +1852,27 @@ qvotec_epoch_ballot_phase1_promise_fds( promised.version = CLUSTER_EPOCH_BALLOT_VERSION; promised.proposer_node_id = proposer_node_id; promised.configured_disk_count = (uint32)n_disks; - promised.proposer_admitted_incarnation - = admitted_incarnations[proposer_node_id]; + promised.proposer_admitted_incarnation = admitted_incarnations[proposer_node_id]; promised.lane_generation = 1; promised.system_identifier = system_identifier; - promised.grammar_fingerprint - = CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT; + promised.grammar_fingerprint = CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT; } promised.last_write_phase = CLUSTER_EPOCH_BALLOT_PHASE_PROMISED; promised.promised_ballot = *ballot; promised.crc32c = 0; if (!cluster_epoch_ballot_lane_encode( - &promised, proposer_node_id, (uint32)n_disks, - admitted_incarnations[proposer_node_id], system_identifier, - CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT, promised_image)) + &promised, proposer_node_id, (uint32)n_disks, admitted_incarnations[proposer_node_id], + system_identifier, CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT, promised_image)) return false; for (d = 0; d < n_disks; d++) { uint8 reread[CLUSTER_EPOCH_BALLOT_LANE_BYTES]; - if (cluster_voting_disk_write_epoch_ballot_slot( - fds[d], (uint32)proposer_node_id, promised_image) - == CLUSTER_VOTING_DISK_IO_OK - && cluster_voting_disk_read_epoch_ballot_slot( - fds[d], (uint32)proposer_node_id, reread) + if (cluster_voting_disk_write_epoch_ballot_slot(fds[d], (uint32)proposer_node_id, + promised_image) == CLUSTER_VOTING_DISK_IO_OK + && cluster_voting_disk_read_epoch_ballot_slot(fds[d], (uint32)proposer_node_id, reread) + == CLUSTER_VOTING_DISK_IO_OK && memcmp(reread, promised_image, sizeof(reread)) == 0) { completed_disk_bitmap |= (uint8)(1u << d); completed_disks++; @@ -1950,19 +1890,16 @@ qvotec_epoch_ballot_phase1_promise_fds( ClusterEpochBallotLane lane; uint8 image[CLUSTER_EPOCH_BALLOT_LANE_BYTES]; - if (cluster_voting_disk_read_epoch_ballot_slot( - fds[d], (uint32)proposer, image) - != CLUSTER_VOTING_DISK_IO_OK) + if (cluster_voting_disk_read_epoch_ballot_slot(fds[d], (uint32)proposer, image) + != CLUSTER_VOTING_DISK_IO_OK) return false; if (qvotec_mailbox_bytes_are_zero(image, sizeof(image))) continue; if (admitted_incarnations[proposer] == 0 || !cluster_epoch_ballot_lane_decode( - image, proposer, (uint32)n_disks, - admitted_incarnations[proposer], system_identifier, - CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT, &lane) - || cluster_epoch_ballot_id_compare( - &lane.promised_ballot, ballot) > 0) + image, proposer, (uint32)n_disks, admitted_incarnations[proposer], + system_identifier, CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT, &lane) + || cluster_epoch_ballot_id_compare(&lane.promised_ballot, ballot) > 0) return false; } } @@ -1976,12 +1913,11 @@ qvotec_epoch_ballot_phase1_promise_fds( * is deliberate: the settled head must be known before accepted generations * can be classified as historical, next, or corruptly skipped. */ static ClusterQvotecMailboxResult -qvotec_epoch_ballot_recover_head_fds( - const int *fds, int n_disks, uint64 system_identifier, - const uint64 admitted_incarnations[CLUSTER_MAX_NODES], - uint8 out_value[CLUSTER_QVOTEC_AUTHORITY_VALUE_BYTES], - uint8 out_ballot[CLUSTER_QVOTEC_BALLOT_BYTES], - uint8 *out_observed_disk_bitmap) +qvotec_epoch_ballot_recover_head_fds(const int *fds, int n_disks, uint64 system_identifier, + const uint64 admitted_incarnations[CLUSTER_MAX_NODES], + uint8 out_value[CLUSTER_QVOTEC_AUTHORITY_VALUE_BYTES], + uint8 out_ballot[CLUSTER_QVOTEC_BALLOT_BYTES], + uint8 *out_observed_disk_bitmap) { ClusterEpochAuthorityValue settled_value; ClusterEpochBallotId settled_ballot; @@ -2000,9 +1936,8 @@ qvotec_epoch_ballot_recover_head_fds( memset(out_ballot, 0, CLUSTER_QVOTEC_BALLOT_BYTES); if (out_observed_disk_bitmap != NULL) *out_observed_disk_bitmap = 0; - if (fds == NULL || admitted_incarnations == NULL || out_value == NULL - || out_ballot == NULL || out_observed_disk_bitmap == NULL - || n_disks <= 0 || n_disks > CLUSTER_MAX_VOTING_DISKS + if (fds == NULL || admitted_incarnations == NULL || out_value == NULL || out_ballot == NULL + || out_observed_disk_bitmap == NULL || n_disks <= 0 || n_disks > CLUSTER_MAX_VOTING_DISKS || system_identifier == 0) return CLUSTER_QVOTEC_MAILBOX_HOLD; @@ -2023,14 +1958,11 @@ qvotec_epoch_ballot_recover_head_fds( for (d = 0; d < n_disks; d++) { uint8 image[CLUSTER_EPOCH_BALLOT_LANE_BYTES]; - if (cluster_voting_disk_read_epoch_ballot_slot( - fds[d], (uint32)proposer, image) + if (cluster_voting_disk_read_epoch_ballot_slot(fds[d], (uint32)proposer, image) == CLUSTER_VOTING_DISK_IO_OK && cluster_epoch_ballot_lane_decode( - image, proposer, (uint32)n_disks, - admitted_incarnations[proposer], system_identifier, - CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT, - &lanes[d])) + image, proposer, (uint32)n_disks, admitted_incarnations[proposer], + system_identifier, CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT, &lanes[d])) valid[d] = true; } @@ -2043,12 +1975,10 @@ qvotec_epoch_ballot_recover_head_fds( continue; for (other = 0; other < n_disks; other++) { if (valid[other] - && memcmp(&lanes[d].settled_ballot, - &lanes[other].settled_ballot, + && memcmp(&lanes[d].settled_ballot, &lanes[other].settled_ballot, sizeof(lanes[d].settled_ballot)) == 0 - && memcmp(&lanes[d].settled_value, - &lanes[other].settled_value, + && memcmp(&lanes[d].settled_value, &lanes[other].settled_value, sizeof(lanes[d].settled_value)) == 0) { count++; @@ -2066,11 +1996,10 @@ qvotec_epoch_ballot_recover_head_fds( have_settled = true; } else if (lanes[d].settled_value.authority_generation == settled_value.authority_generation) { - if (memcmp(&lanes[d].settled_value, &settled_value, - sizeof(settled_value)) != 0) + if (memcmp(&lanes[d].settled_value, &settled_value, sizeof(settled_value)) != 0) return CLUSTER_QVOTEC_MAILBOX_HOLD; - if (cluster_epoch_ballot_id_compare( - &lanes[d].settled_ballot, &settled_ballot) > 0) { + if (cluster_epoch_ballot_id_compare(&lanes[d].settled_ballot, &settled_ballot) + > 0) { settled_ballot = lanes[d].settled_ballot; settled_disk_bitmap = agreeing; } @@ -2092,14 +2021,11 @@ qvotec_epoch_ballot_recover_head_fds( for (d = 0; d < n_disks; d++) { uint8 image[CLUSTER_EPOCH_BALLOT_LANE_BYTES]; - if (cluster_voting_disk_read_epoch_ballot_slot( - fds[d], (uint32)proposer, image) + if (cluster_voting_disk_read_epoch_ballot_slot(fds[d], (uint32)proposer, image) == CLUSTER_VOTING_DISK_IO_OK && cluster_epoch_ballot_lane_decode( - image, proposer, (uint32)n_disks, - admitted_incarnations[proposer], system_identifier, - CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT, - &lanes[d])) + image, proposer, (uint32)n_disks, admitted_incarnations[proposer], + system_identifier, CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT, &lanes[d])) valid[d] = true; } for (d = 0; d < n_disks; d++) { @@ -2111,12 +2037,10 @@ qvotec_epoch_ballot_recover_head_fds( continue; for (other = 0; other < n_disks; other++) { if (valid[other] - && memcmp(&lanes[d].accepted_ballot, - &lanes[other].accepted_ballot, + && memcmp(&lanes[d].accepted_ballot, &lanes[other].accepted_ballot, sizeof(lanes[d].accepted_ballot)) == 0 - && memcmp(&lanes[d].accepted_value, - &lanes[other].accepted_value, + && memcmp(&lanes[d].accepted_value, &lanes[other].accepted_value, sizeof(lanes[d].accepted_value)) == 0) { count++; @@ -2126,44 +2050,40 @@ qvotec_epoch_ballot_recover_head_fds( if (count < majority) continue; if (lanes[d].accepted_value.authority_generation - > settled_value.authority_generation + 1) + > settled_value.authority_generation + 1) return CLUSTER_QVOTEC_MAILBOX_HOLD; - if (lanes[d].accepted_value.authority_generation - == settled_value.authority_generation - && memcmp(&lanes[d].accepted_value, &settled_value, - sizeof(settled_value)) != 0) + if (lanes[d].accepted_value.authority_generation == settled_value.authority_generation + && memcmp(&lanes[d].accepted_value, &settled_value, sizeof(settled_value)) != 0) return CLUSTER_QVOTEC_MAILBOX_HOLD; if (lanes[d].accepted_value.authority_generation - != settled_value.authority_generation + 1) + != settled_value.authority_generation + 1) continue; if (!have_accepted - || cluster_epoch_ballot_id_compare( - &lanes[d].accepted_ballot, &accepted_ballot) > 0) { + || cluster_epoch_ballot_id_compare(&lanes[d].accepted_ballot, &accepted_ballot) + > 0) { accepted_value = lanes[d].accepted_value; accepted_ballot = lanes[d].accepted_ballot; accepted_disk_bitmap = agreeing; have_accepted = true; - } else if (cluster_epoch_ballot_id_compare( - &lanes[d].accepted_ballot, &accepted_ballot) == 0 - && memcmp(&lanes[d].accepted_value, &accepted_value, - sizeof(accepted_value)) != 0) + } else if (cluster_epoch_ballot_id_compare(&lanes[d].accepted_ballot, &accepted_ballot) + == 0 + && memcmp(&lanes[d].accepted_value, &accepted_value, sizeof(accepted_value)) + != 0) return CLUSTER_QVOTEC_MAILBOX_HOLD; } } if (have_accepted) { if (!cluster_epoch_authority_value_encode( - &accepted_value, CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT, - out_value) + &accepted_value, CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT, out_value) || !cluster_epoch_ballot_id_encode(&accepted_ballot, out_ballot)) return CLUSTER_QVOTEC_MAILBOX_HOLD; *out_observed_disk_bitmap = accepted_disk_bitmap; return CLUSTER_QVOTEC_MAILBOX_ADOPTED_OTHER; } - if (!cluster_epoch_authority_value_encode( - &settled_value, CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT, - out_value) + if (!cluster_epoch_authority_value_encode(&settled_value, + CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT, out_value) || !cluster_epoch_ballot_id_encode(&settled_ballot, out_ballot)) return CLUSTER_QVOTEC_MAILBOX_HOLD; *out_observed_disk_bitmap = settled_disk_bitmap; @@ -2182,8 +2102,7 @@ qvotec_epoch_ballot_formation_attested_fds(const int *fds, int n_disks) { int i; - if (fds == NULL - || (n_disks != 1 && n_disks != 3 && n_disks != 5 && n_disks != 7)) + if (fds == NULL || (n_disks != 1 && n_disks != 3 && n_disks != 5 && n_disks != 7)) return false; for (i = 0; i < n_disks; i++) { if (!cluster_voting_disk_epoch_ballot_authority_attest(fds[i])) @@ -2201,87 +2120,71 @@ qvotec_epoch_ballot_mailbox_tick(void) uint8 configured_disk_bitmap; int i; - if (QvotecShmem == NULL - || !cluster_qvotec_mailbox_qvotec_poll( - &QvotecShmem->mailbox, &request)) + if (QvotecShmem == NULL || !cluster_qvotec_mailbox_qvotec_poll(&QvotecShmem->mailbox, &request)) return; memset(&completion, 0, sizeof(completion)); completion.request_seq = request.request_seq; completion.actor_phase = CLUSTER_QVOTEC_ACTOR_RECOVER_SCAN_A; - if (!qvotec_epoch_ballot_formation_attested_fds( - qvotec_fds, qvotec_n_disks) + if (!qvotec_epoch_ballot_formation_attested_fds(qvotec_fds, qvotec_n_disks) || request.opcode != CLUSTER_QVOTEC_MAILBOX_RECOVER_HEAD) { completion.result = CLUSTER_QVOTEC_MAILBOX_HOLD; completion.actor_phase = CLUSTER_QVOTEC_ACTOR_HOLD; } else { for (i = 0; i < CLUSTER_MAX_NODES; i++) - admitted_incarnations[i] - = cluster_membership_get_last_admitted_incarnation(i); + admitted_incarnations[i] = cluster_membership_get_last_admitted_incarnation(i); completion.result = qvotec_epoch_ballot_recover_head_fds( - qvotec_fds, qvotec_n_disks, GetSystemIdentifier(), - admitted_incarnations, completion.completion_value, - completion.completion_ballot, + qvotec_fds, qvotec_n_disks, GetSystemIdentifier(), admitted_incarnations, + completion.completion_value, completion.completion_ballot, &completion.observed_disk_bitmap); - completion.actor_phase - = completion.result == CLUSTER_QVOTEC_MAILBOX_HOLD - ? CLUSTER_QVOTEC_ACTOR_HOLD - : CLUSTER_QVOTEC_ACTOR_RECOVER_SCAN_B; + completion.actor_phase = completion.result == CLUSTER_QVOTEC_MAILBOX_HOLD + ? CLUSTER_QVOTEC_ACTOR_HOLD + : CLUSTER_QVOTEC_ACTOR_RECOVER_SCAN_B; } - configured_disk_bitmap - = (uint8)((UINT32_C(1) << qvotec_n_disks) - UINT32_C(1)); - (void)cluster_qvotec_mailbox_qvotec_complete( - &QvotecShmem->mailbox, configured_disk_bitmap, &completion); + configured_disk_bitmap = (uint8)((UINT32_C(1) << qvotec_n_disks) - UINT32_C(1)); + (void)cluster_qvotec_mailbox_qvotec_complete(&QvotecShmem->mailbox, configured_disk_bitmap, + &completion); } #ifdef CLUSTER_QVOTEC_PGSA_UNIT_TEST extern ClusterSemanticActivationResult cluster_qvotec_test_semantic_activation_record_cas_write( - const int *fds, int n_disks, uint64 expected_generation, - uint64 expected_source_feature_bitmap, + const int *fds, int n_disks, uint64 expected_generation, uint64 expected_source_feature_bitmap, const uint8 desired_bytes[CLUSTER_SEMANTIC_ACTIVATION_RECORD_BYTES]); extern ClusterSemanticActivationResult cluster_qvotec_test_semantic_activation_record_read( - const int *fds, int n_disks, - uint8 selected_bytes[CLUSTER_SEMANTIC_ACTIVATION_RECORD_BYTES], + const int *fds, int n_disks, uint8 selected_bytes[CLUSTER_SEMANTIC_ACTIVATION_RECORD_BYTES], bool *implicit_open); -extern bool cluster_qvotec_test_join_marker_ack_proven( - const int *fds, int n_disks, int32 target_node, - const uint8 *staged_slot, uint32 writes_ok); +extern bool cluster_qvotec_test_join_marker_ack_proven(const int *fds, int n_disks, + int32 target_node, const uint8 *staged_slot, + uint32 writes_ok); extern bool cluster_qvotec_test_join_marker_verify_committed_closed( const int *fds, int n_disks, int32 target_node, uint8 verified_image96[CLUSTER_JCMK_REPLACEMENT_BYTES]); -extern ClusterQvotecMailboxResult cluster_qvotec_test_epoch_ballot_recover_head( - const int *fds, int n_disks, uint64 system_identifier, - const uint64 admitted_incarnations[CLUSTER_MAX_NODES], - uint8 out_value[CLUSTER_QVOTEC_AUTHORITY_VALUE_BYTES], - uint8 out_ballot[CLUSTER_QVOTEC_BALLOT_BYTES], - uint8 *out_observed_disk_bitmap); +extern ClusterQvotecMailboxResult +cluster_qvotec_test_epoch_ballot_recover_head(const int *fds, int n_disks, uint64 system_identifier, + const uint64 admitted_incarnations[CLUSTER_MAX_NODES], + uint8 out_value[CLUSTER_QVOTEC_AUTHORITY_VALUE_BYTES], + uint8 out_ballot[CLUSTER_QVOTEC_BALLOT_BYTES], + uint8 *out_observed_disk_bitmap); extern bool cluster_qvotec_test_epoch_ballot_phase1_promise( const int *fds, int n_disks, uint64 system_identifier, - const uint64 admitted_incarnations[CLUSTER_MAX_NODES], - int32 proposer_node_id, const ClusterEpochBallotId *ballot, - uint8 *out_completed_disk_bitmap); -extern bool cluster_qvotec_test_epoch_ballot_formation_attested( - const int *fds, int n_disks); -extern bool cluster_qvotec_test_undo_root_descriptor_formation_attested( - const int *fds, int n_disks); + const uint64 admitted_incarnations[CLUSTER_MAX_NODES], int32 proposer_node_id, + const ClusterEpochBallotId *ballot, uint8 *out_completed_disk_bitmap); +extern bool cluster_qvotec_test_epoch_ballot_formation_attested(const int *fds, int n_disks); +extern bool cluster_qvotec_test_undo_root_descriptor_formation_attested(const int *fds, + int n_disks); extern bool cluster_qvotec_test_undo_root_descriptor_provision( const int *fds, int n_disks, uint64 system_identifier, - const uint8 desired[CLUSTER_UNDO_ROOT_DESCRIPTOR_BYTES], - uint8 *out_completed_disk_bitmap); -extern ClusterUndoRootDescriptorState -cluster_qvotec_test_undo_root_descriptor_read( - const int *fds, int n_disks, uint64 system_identifier, - uint8 root_kind, int32 owner_node, ClusterUndoRootDescriptorV1 *out, - uint8 *out_observed_disk_bitmap); + const uint8 desired[CLUSTER_UNDO_ROOT_DESCRIPTOR_BYTES], uint8 *out_completed_disk_bitmap); +extern ClusterUndoRootDescriptorState cluster_qvotec_test_undo_root_descriptor_read( + const int *fds, int n_disks, uint64 system_identifier, uint8 root_kind, int32 owner_node, + ClusterUndoRootDescriptorV1 *out, uint8 *out_observed_disk_bitmap); extern ClusterReplacementRequestSlotState -cluster_qvotec_test_replacement_request_preserve( - ClusterVotingSlot *next, const ClusterVotingSlot *prior); -extern long cluster_qvotec_test_poll_wait_timeout_ms( - uint64 elapsed_us, int poll_interval_ms); +cluster_qvotec_test_replacement_request_preserve(ClusterVotingSlot *next, + const ClusterVotingSlot *prior); +extern long cluster_qvotec_test_poll_wait_timeout_ms(uint64 elapsed_us, int poll_interval_ms); ClusterSemanticActivationResult cluster_qvotec_test_semantic_activation_record_cas_write( - const int *fds, int n_disks, uint64 expected_generation, - uint64 expected_source_feature_bitmap, + const int *fds, int n_disks, uint64 expected_generation, uint64 expected_source_feature_bitmap, const uint8 desired_bytes[CLUSTER_SEMANTIC_ACTIVATION_RECORD_BYTES]) { return qvotec_semantic_activation_record_cas_write_fds( @@ -2290,18 +2193,15 @@ cluster_qvotec_test_semantic_activation_record_cas_write( ClusterSemanticActivationResult cluster_qvotec_test_semantic_activation_record_read( - const int *fds, int n_disks, - uint8 selected_bytes[CLUSTER_SEMANTIC_ACTIVATION_RECORD_BYTES], + const int *fds, int n_disks, uint8 selected_bytes[CLUSTER_SEMANTIC_ACTIVATION_RECORD_BYTES], bool *implicit_open) { - return qvotec_semantic_activation_record_read_fds( - fds, n_disks, selected_bytes, implicit_open); + return qvotec_semantic_activation_record_read_fds(fds, n_disks, selected_bytes, implicit_open); } bool -cluster_qvotec_test_join_marker_ack_proven( - const int *fds, int n_disks, int32 target_node, - const uint8 *staged_slot, uint32 writes_ok) +cluster_qvotec_test_join_marker_ack_proven(const int *fds, int n_disks, int32 target_node, + const uint8 *staged_slot, uint32 writes_ok) { bool write_succeeded[CLUSTER_MAX_VOTING_DISKS] = { false }; uint32 bounded_writes; @@ -2312,8 +2212,8 @@ cluster_qvotec_test_join_marker_ack_proven( bounded_writes = Min(writes_ok, (uint32)n_disks); for (i = 0; i < bounded_writes; i++) write_succeeded[i] = true; - return qvotec_join_marker_ack_proven_fds( - fds, n_disks, target_node, staged_slot, write_succeeded); + return qvotec_join_marker_ack_proven_fds(fds, n_disks, target_node, staged_slot, + write_succeeded); } bool @@ -2321,70 +2221,62 @@ cluster_qvotec_test_join_marker_verify_committed_closed( const int *fds, int n_disks, int32 target_node, uint8 verified_image96[CLUSTER_JCMK_REPLACEMENT_BYTES]) { - return qvotec_join_marker_verify_committed_closed_fds( - fds, n_disks, target_node, verified_image96); + return qvotec_join_marker_verify_committed_closed_fds(fds, n_disks, target_node, + verified_image96); } ClusterQvotecMailboxResult -cluster_qvotec_test_epoch_ballot_recover_head( - const int *fds, int n_disks, uint64 system_identifier, - const uint64 admitted_incarnations[CLUSTER_MAX_NODES], - uint8 out_value[CLUSTER_QVOTEC_AUTHORITY_VALUE_BYTES], - uint8 out_ballot[CLUSTER_QVOTEC_BALLOT_BYTES], - uint8 *out_observed_disk_bitmap) +cluster_qvotec_test_epoch_ballot_recover_head(const int *fds, int n_disks, uint64 system_identifier, + const uint64 admitted_incarnations[CLUSTER_MAX_NODES], + uint8 out_value[CLUSTER_QVOTEC_AUTHORITY_VALUE_BYTES], + uint8 out_ballot[CLUSTER_QVOTEC_BALLOT_BYTES], + uint8 *out_observed_disk_bitmap) { - return qvotec_epoch_ballot_recover_head_fds( - fds, n_disks, system_identifier, admitted_incarnations, - out_value, out_ballot, out_observed_disk_bitmap); + return qvotec_epoch_ballot_recover_head_fds(fds, n_disks, system_identifier, + admitted_incarnations, out_value, out_ballot, + out_observed_disk_bitmap); } bool cluster_qvotec_test_epoch_ballot_phase1_promise( const int *fds, int n_disks, uint64 system_identifier, - const uint64 admitted_incarnations[CLUSTER_MAX_NODES], - int32 proposer_node_id, const ClusterEpochBallotId *ballot, - uint8 *out_completed_disk_bitmap) + const uint64 admitted_incarnations[CLUSTER_MAX_NODES], int32 proposer_node_id, + const ClusterEpochBallotId *ballot, uint8 *out_completed_disk_bitmap) { - return qvotec_epoch_ballot_phase1_promise_fds( - fds, n_disks, system_identifier, admitted_incarnations, - proposer_node_id, ballot, out_completed_disk_bitmap); + return qvotec_epoch_ballot_phase1_promise_fds(fds, n_disks, system_identifier, + admitted_incarnations, proposer_node_id, ballot, + out_completed_disk_bitmap); } bool -cluster_qvotec_test_epoch_ballot_formation_attested( - const int *fds, int n_disks) +cluster_qvotec_test_epoch_ballot_formation_attested(const int *fds, int n_disks) { return qvotec_epoch_ballot_formation_attested_fds(fds, n_disks); } bool -cluster_qvotec_test_undo_root_descriptor_formation_attested( - const int *fds, int n_disks) +cluster_qvotec_test_undo_root_descriptor_formation_attested(const int *fds, int n_disks) { - return qvotec_undo_root_descriptor_formation_attested_fds( - fds, n_disks); + return qvotec_undo_root_descriptor_formation_attested_fds(fds, n_disks); } bool cluster_qvotec_test_undo_root_descriptor_provision( const int *fds, int n_disks, uint64 system_identifier, - const uint8 desired[CLUSTER_UNDO_ROOT_DESCRIPTOR_BYTES], - uint8 *out_completed_disk_bitmap) + const uint8 desired[CLUSTER_UNDO_ROOT_DESCRIPTOR_BYTES], uint8 *out_completed_disk_bitmap) { - return qvotec_undo_root_descriptor_provision_fds( - fds, n_disks, system_identifier, desired, - out_completed_disk_bitmap); + return qvotec_undo_root_descriptor_provision_fds(fds, n_disks, system_identifier, desired, + out_completed_disk_bitmap); } ClusterUndoRootDescriptorState -cluster_qvotec_test_undo_root_descriptor_read( - const int *fds, int n_disks, uint64 system_identifier, - uint8 root_kind, int32 owner_node, ClusterUndoRootDescriptorV1 *out, - uint8 *out_observed_disk_bitmap) +cluster_qvotec_test_undo_root_descriptor_read(const int *fds, int n_disks, uint64 system_identifier, + uint8 root_kind, int32 owner_node, + ClusterUndoRootDescriptorV1 *out, + uint8 *out_observed_disk_bitmap) { - return qvotec_undo_root_descriptor_read_fds( - fds, n_disks, system_identifier, root_kind, owner_node, out, - out_observed_disk_bitmap); + return qvotec_undo_root_descriptor_read_fds(fds, n_disks, system_identifier, root_kind, + owner_node, out, out_observed_disk_bitmap); } #endif @@ -2414,25 +2306,22 @@ qvotec_close_disks_atexit(int code pg_attribute_unused(), Datum arg pg_attribute * over that disk. */ static ClusterReplacementRequestSlotState -qvotec_replacement_request_preserve(ClusterVotingSlot *next, - const ClusterVotingSlot *prior) +qvotec_replacement_request_preserve(ClusterVotingSlot *next, const ClusterVotingSlot *prior) { ClusterReplacementRequestSlotState state; if (next == NULL || prior == NULL) return CLUSTER_REPLACEMENT_REQUEST_SLOT_HOLD; - state = cluster_replacement_request_slot_state( - prior->flags, prior->_reserved1, (int32)next->node_id, - next->incarnation, NULL); + state = cluster_replacement_request_slot_state(prior->flags, prior->_reserved1, + (int32)next->node_id, next->incarnation, NULL); if (state == CLUSTER_REPLACEMENT_REQUEST_SLOT_VALID - && (prior->node_id != next->node_id - || prior->incarnation != next->incarnation)) + && (prior->node_id != next->node_id || prior->incarnation != next->incarnation)) return CLUSTER_REPLACEMENT_REQUEST_SLOT_HOLD; if (state != CLUSTER_REPLACEMENT_REQUEST_SLOT_VALID) return state; - return cluster_replacement_request_preserve_per_disk( - prior->flags, prior->_reserved1, (int32)next->node_id, - next->incarnation, &next->flags, next->_reserved1); + return cluster_replacement_request_preserve_per_disk(prior->flags, prior->_reserved1, + (int32)next->node_id, next->incarnation, + &next->flags, next->_reserved1); } #ifdef CLUSTER_QVOTEC_PGSA_UNIT_TEST @@ -2466,15 +2355,14 @@ cluster_qvotec_test_poll_pre_injection(void) } ClusterReplacementRequestSlotState -cluster_qvotec_test_replacement_request_preserve( - ClusterVotingSlot *next, const ClusterVotingSlot *prior) +cluster_qvotec_test_replacement_request_preserve(ClusterVotingSlot *next, + const ClusterVotingSlot *prior) { return qvotec_replacement_request_preserve(next, prior); } long -cluster_qvotec_test_poll_wait_timeout_ms(uint64 elapsed_us, - int poll_interval_ms) +cluster_qvotec_test_poll_wait_timeout_ms(uint64 elapsed_us, int poll_interval_ms) { return qvotec_poll_wait_timeout_ms(elapsed_us, poll_interval_ms); } @@ -2572,8 +2460,7 @@ qvotec_clear_self_alive_on_clean_shutdown(void) */ blanked.flags = 0; memset(blanked._reserved1, 0, sizeof(blanked._reserved1)); - rrc = cluster_voting_disk_read_slot( - qvotec_fds[i], i, (uint32)cluster_node_id, &existing); + rrc = cluster_voting_disk_read_slot(qvotec_fds[i], i, (uint32)cluster_node_id, &existing); if (rrc != CLUSTER_VOTING_DISK_IO_OK) { if (normal_stop) qvotec_shutdown_failure(i, "QVOTEC_SELF_SLOT_READ", (int)rrc); @@ -2588,8 +2475,7 @@ qvotec_clear_self_alive_on_clean_shutdown(void) all_cleared = false; continue; } - cluster_removal_marker_preserve_per_disk( - blanked._reserved1, existing._reserved1); + cluster_removal_marker_preserve_per_disk(blanked._reserved1, existing._reserved1); rplm_state = qvotec_replacement_request_preserve(&blanked, &existing); if (rplm_state == CLUSTER_REPLACEMENT_REQUEST_SLOT_HOLD) { if (normal_stop) @@ -2781,8 +2667,7 @@ qvotec_build_baseline_marker(ClusterFenceMarker *out) int f; for (f = 0; f < CLUSTER_MAX_NODES; f++) { - uint64 departed_epoch - = cluster_reconfig_get_clean_departed_epoch(f); + uint64 departed_epoch = cluster_reconfig_get_clean_departed_epoch(f); if (departed_epoch > floor_epoch) floor_epoch = departed_epoch; @@ -2944,55 +2829,45 @@ qvotec_poll_once(void) ClusterAdgApplyMasterLease apply_lease_request; ClusterAdgApplyMasterLeaseQuorum apply_lease_winner; bool have_apply_lease_request; - ClusterFenceMarker baseline_marker; /* spec-4.12b D2 */ - bool author_baseline = false; /* spec-4.12b D2: wrote a baseline this cycle */ - bool is_leader = false; /* spec-4.12b D6: lowest-live baseline leader */ - bool durable_has_authority = false; /* exact authority observed on disk THIS poll */ + ClusterFenceMarker baseline_marker; /* spec-4.12b D2 */ + bool author_baseline = false; /* spec-4.12b D2: wrote a baseline this cycle */ + bool is_leader = false; /* spec-4.12b D6: lowest-live baseline leader */ + bool durable_has_authority = false; /* exact authority observed on disk THIS poll */ ClusterFenceMarker durable_authority_marker; /* exact tuple observed this poll */ - bool fence_majority_written = false; /* RF-ROOT P6: this poll's marker tuple + bool fence_majority_written = false; /* RF-ROOT P6: this poll's marker tuple * reached quorum-majority durability */ qvotec_diagnostic_phase_enter(QVOTEC_DIAG_SEMANTIC_MAILBOX); - if (cluster_semantic_activation_qvotec_poll_record_read( - &semantic_record_read_request)) { + if (cluster_semantic_activation_qvotec_poll_record_read(&semantic_record_read_request)) { uint8 selected[CLUSTER_SEMANTIC_ACTIVATION_RECORD_BYTES]; bool implicit_open = false; - ClusterSemanticActivationResult result - = qvotec_semantic_activation_record_read_fds( - qvotec_fds, qvotec_n_disks, selected, &implicit_open); + ClusterSemanticActivationResult result = qvotec_semantic_activation_record_read_fds( + qvotec_fds, qvotec_n_disks, selected, &implicit_open); (void)cluster_semantic_activation_qvotec_complete_record_read( - semantic_record_read_request.request_seq, result, - implicit_open, selected); - } else if (cluster_semantic_activation_qvotec_poll_record_cas( - &semantic_record_cas_request)) { + semantic_record_read_request.request_seq, result, implicit_open, selected); + } else if (cluster_semantic_activation_qvotec_poll_record_cas(&semantic_record_cas_request)) { ClusterSemanticActivationResult semantic_record_cas_result = cluster_semantic_activation_record_cas_write( semantic_record_cas_request.expected_generation, semantic_record_cas_request.expected_source_feature_bitmap, semantic_record_cas_request.desired_bytes); - (void) cluster_semantic_activation_qvotec_complete_record_cas( - semantic_record_cas_request.request_seq, - semantic_record_cas_result); + (void)cluster_semantic_activation_qvotec_complete_record_cas( + semantic_record_cas_request.request_seq, semantic_record_cas_result); } else if (cluster_semantic_activation_qvotec_poll_undo_root_descriptor_read( &undo_root_descriptor_read_request)) { ClusterUndoRootDescriptorV1 descriptor; uint8 selected[CLUSTER_UNDO_ROOT_DESCRIPTOR_BYTES] = { 0 }; uint8 observed_disk_bitmap = 0; - ClusterUndoRootDescriptorState state - = CLUSTER_UNDO_ROOT_DESCRIPTOR_HOLD; + ClusterUndoRootDescriptorState state = CLUSTER_UNDO_ROOT_DESCRIPTOR_HOLD; - if (qvotec_undo_root_descriptor_formation_attested_fds( - qvotec_fds, qvotec_n_disks)) { + if (qvotec_undo_root_descriptor_formation_attested_fds(qvotec_fds, qvotec_n_disks)) { state = qvotec_undo_root_descriptor_read_fds( - qvotec_fds, qvotec_n_disks, - undo_root_descriptor_read_request.system_identifier, - CLUSTER_UNDO_ROOT_KIND_SHARED, -1, &descriptor, - &observed_disk_bitmap); + qvotec_fds, qvotec_n_disks, undo_root_descriptor_read_request.system_identifier, + CLUSTER_UNDO_ROOT_KIND_SHARED, -1, &descriptor, &observed_disk_bitmap); if (state == CLUSTER_UNDO_ROOT_DESCRIPTOR_VALID - && !cluster_undo_root_descriptor_encode( - &descriptor, selected)) + && !cluster_undo_root_descriptor_encode(&descriptor, selected)) state = CLUSTER_UNDO_ROOT_DESCRIPTOR_HOLD; } (void)observed_disk_bitmap; @@ -3002,13 +2877,11 @@ qvotec_poll_once(void) &undo_root_descriptor_request)) { uint8 completed_disk_bitmap; ClusterSemanticActivationResult result - = qvotec_undo_root_descriptor_formation_attested_fds( - qvotec_fds, qvotec_n_disks) - && qvotec_undo_root_descriptor_provision_fds( - qvotec_fds, qvotec_n_disks, - undo_root_descriptor_request.system_identifier, - undo_root_descriptor_request.desired_bytes, - &completed_disk_bitmap) + = qvotec_undo_root_descriptor_formation_attested_fds(qvotec_fds, qvotec_n_disks) + && qvotec_undo_root_descriptor_provision_fds( + qvotec_fds, qvotec_n_disks, + undo_root_descriptor_request.system_identifier, + undo_root_descriptor_request.desired_bytes, &completed_disk_bitmap) ? CLUSTER_SEMANTIC_ACTIVATION_OK : CLUSTER_SEMANTIC_ACTIVATION_QUORUM_HOLD; @@ -3042,9 +2915,8 @@ qvotec_poll_once(void) * leave marker (this node's own slot) it is written to the JOINER's region-3 * slot (join_target_node) on every disk in the same write loop below and acked * majority-durable. */ - have_join_submit - = cluster_reconfig_join_qvotec_poll_pending( - &join_marker_operation, &join_target_node, join_marker_slot); + have_join_submit = cluster_reconfig_join_qvotec_poll_pending( + &join_marker_operation, &join_target_node, join_marker_slot); /* RF-ROOT P9 verification (cold-formation cold-formation ruling): pick * up a pending cold-formation marker submit. The arbiter LMON staged a @@ -3052,8 +2924,7 @@ qvotec_poll_once(void) * every target member's region-7 slot on every disk and ACKs only on a * majority write + majority exact readback. */ have_formation_marker_submit - = cluster_reconfig_formation_qvotec_poll_pending( - &formation_marker_request); + = cluster_reconfig_formation_qvotec_poll_pending(&formation_marker_request); /* spec-5.18 §2.5: pick up a pending removal-marker submit too. It rides THIS * node's own self-slot _reserved1[64..] (right after the 4.12 fence marker), @@ -3078,8 +2949,8 @@ qvotec_poll_once(void) if (have_leave_submit) cluster_clean_leave_qvotec_complete(false); /* no disk -> no majority */ if (have_join_submit) - cluster_reconfig_join_qvotec_complete( - join_marker_operation, false, NULL); /* no disk -> no majority */ + cluster_reconfig_join_qvotec_complete(join_marker_operation, false, + NULL); /* no disk -> no majority */ if (have_formation_marker_submit) cluster_reconfig_formation_qvotec_complete(false); /* no disk */ if (have_removal_submit) @@ -3091,16 +2962,14 @@ qvotec_poll_once(void) } if (have_join_submit - && join_marker_operation - == CLUSTER_JOIN_MARKER_MAILBOX_VERIFY_COMMITTED_CLOSED) { + && join_marker_operation == CLUSTER_JOIN_MARKER_MAILBOX_VERIFY_COMMITTED_CLOSED) { uint8 verified_image[CLUSTER_JCMK_REPLACEMENT_BYTES]; bool verified; - verified = qvotec_join_marker_verify_committed_closed_fds( - qvotec_fds, qvotec_n_disks, join_target_node, verified_image); - cluster_reconfig_join_qvotec_complete( - join_marker_operation, verified, - verified ? verified_image : NULL); + verified = qvotec_join_marker_verify_committed_closed_fds(qvotec_fds, qvotec_n_disks, + join_target_node, verified_image); + cluster_reconfig_join_qvotec_complete(join_marker_operation, verified, + verified ? verified_image : NULL); have_join_submit = false; } @@ -3114,8 +2983,8 @@ qvotec_poll_once(void) if (have_leave_submit) cluster_clean_leave_qvotec_complete(false); /* cannot author self slot */ if (have_join_submit) - cluster_reconfig_join_qvotec_complete( - join_marker_operation, false, NULL); /* cannot author self slot */ + cluster_reconfig_join_qvotec_complete(join_marker_operation, false, + NULL); /* cannot author self slot */ if (have_removal_submit) cluster_node_remove_qvotec_complete(false); /* cannot author self slot */ if (have_apply_lease_request) @@ -3166,8 +3035,7 @@ qvotec_poll_once(void) ClusterVotingDiskIoState rrc; rrc = cluster_voting_disk_read_slot(qvotec_fds[i], i, node, cell); - if (node == (uint32)cluster_node_id - && rrc == CLUSTER_VOTING_DISK_IO_OK) + if (node == (uint32)cluster_node_id && rrc == CLUSTER_VOTING_DISK_IO_OK) own_prior_read_ok[i] = true; if (rrc != CLUSTER_VOTING_DISK_IO_OK) { /* Per-slot miss is no-data;whole-disk failure only @@ -3271,8 +3139,8 @@ qvotec_poll_once(void) int d; int win; - (void)cluster_reconfig_qvotec_observe_replacement_admitted( - qvotec_fds, qvotec_n_disks, qvotec_self_incarnation); + (void)cluster_reconfig_qvotec_observe_replacement_admitted(qvotec_fds, qvotec_n_disks, + qvotec_self_incarnation); for (d = 0; d < qvotec_n_disks; d++) { union { @@ -3528,8 +3396,7 @@ qvotec_poll_once(void) * withheld and counted failed below. */ if (own_prior_read_ok[i]) - rplm_state - = qvotec_replacement_request_preserve(&self_slot, own_prior); + rplm_state = qvotec_replacement_request_preserve(&self_slot, own_prior); else rplm_state = CLUSTER_REPLACEMENT_REQUEST_SLOT_HOLD; @@ -3584,7 +3451,7 @@ qvotec_poll_once(void) */ if (have_join_submit && join_target_node >= 0 && cluster_voting_disk_write_join_slot(qvotec_fds[i], (uint32)join_target_node, - join_marker_slot) + join_marker_slot) == CLUSTER_VOTING_DISK_IO_OK) join_disk_write_succeeded[i] = true; @@ -3593,18 +3460,15 @@ qvotec_poll_once(void) * write the staged cold-formation marker into EVERY target member's * region-7 slot on this disk (the JCMK coordinator-write pattern). */ - if (have_formation_marker_submit) - { - int tm; + if (have_formation_marker_submit) { + int tm; - for (tm = 0; tm < CLUSTER_MAX_NODES; tm++) - { - if ((formation_marker_request.target_members[tm / 8] - & (uint8) (1u << (tm % 8))) == 0) + for (tm = 0; tm < CLUSTER_MAX_NODES; tm++) { + if ((formation_marker_request.target_members[tm / 8] & (uint8)(1u << (tm % 8))) + == 0) continue; - (void) cluster_voting_disk_write_formation_slot( - qvotec_fds[i], (uint32) tm, - formation_marker_request.marker_bytes); + (void)cluster_voting_disk_write_formation_slot( + qvotec_fds[i], (uint32)tm, formation_marker_request.marker_bytes); } } } @@ -3673,47 +3537,40 @@ qvotec_poll_once(void) /* spec-5.15 §2.6: ACK only after a strict majority of the same * disks complete write + durability + exact region-3 readback. */ - if (have_join_submit) - { - bool proven; + if (have_join_submit) { + bool proven; - proven = qvotec_join_marker_ack_proven_fds( - qvotec_fds, qvotec_n_disks, join_target_node, - join_marker_slot, join_disk_write_succeeded); - cluster_reconfig_join_qvotec_complete( - join_marker_operation, proven, NULL); - } + proven = qvotec_join_marker_ack_proven_fds(qvotec_fds, qvotec_n_disks, join_target_node, + join_marker_slot, join_disk_write_succeeded); + cluster_reconfig_join_qvotec_complete(join_marker_operation, proven, NULL); + } /* RF-ROOT P9 verification (cold-formation cold-formation ruling): * ACK the cold-formation marker submit only when EVERY target * member's region-7 slot carries the EXACT image on a strict * majority of disks (write + readback). */ - if (have_formation_marker_submit) - { - bool proven = true; - int tm; + if (have_formation_marker_submit) { + bool proven = true; + int tm; - for (tm = 0; tm < CLUSTER_MAX_NODES && proven; tm++) - { - uint32 exact = 0; - int d; + for (tm = 0; tm < CLUSTER_MAX_NODES && proven; tm++) { + uint32 exact = 0; + int d; - if ((formation_marker_request.target_members[tm / 8] - & (uint8) (1u << (tm % 8))) == 0) + if ((formation_marker_request.target_members[tm / 8] & (uint8)(1u << (tm % 8))) + == 0) continue; - for (d = 0; d < qvotec_n_disks; d++) - { - uint8 reread[CLUSTER_VOTING_SLOT_BYTES]; + for (d = 0; d < qvotec_n_disks; d++) { + uint8 reread[CLUSTER_VOTING_SLOT_BYTES]; - if (cluster_voting_disk_read_formation_slot( - qvotec_fds[d], (uint32) tm, reread) + if (cluster_voting_disk_read_formation_slot(qvotec_fds[d], (uint32)tm, reread) == CLUSTER_VOTING_DISK_IO_OK - && memcmp(reread, - formation_marker_request.marker_bytes, - CLUSTER_VOTING_SLOT_BYTES) == 0) + && memcmp(reread, formation_marker_request.marker_bytes, + CLUSTER_VOTING_SLOT_BYTES) + == 0) exact++; } - if (exact < (uint32) qvotec_n_disks / 2u + 1u) + if (exact < (uint32)qvotec_n_disks / 2u + 1u) proven = false; } cluster_reconfig_formation_qvotec_complete(proven); @@ -3803,51 +3660,43 @@ qvotec_poll_once(void) * published for the cold-formation admission; otherwise the observation * is cleared (fail-closed: no marker, no admission). */ { - uint8 images[CLUSTER_MAX_VOTING_DISKS][CLUSTER_VOTING_SLOT_BYTES]; - bool valid[CLUSTER_MAX_VOTING_DISKS]; - int selected = -1; - uint32 majority = (uint32) qvotec_n_disks / 2u + 1u; - int d; + uint8 images[CLUSTER_MAX_VOTING_DISKS][CLUSTER_VOTING_SLOT_BYTES]; + bool valid[CLUSTER_MAX_VOTING_DISKS]; + int selected = -1; + uint32 majority = (uint32)qvotec_n_disks / 2u + 1u; + int d; qvotec_diagnostic_phase_enter(QVOTEC_DIAG_FORMATION); memset(valid, 0, sizeof(valid)); - for (d = 0; d < qvotec_n_disks; d++) - { - if (cluster_voting_disk_read_formation_slot( - qvotec_fds[d], (uint32) cluster_node_id, images[d]) - == CLUSTER_VOTING_DISK_IO_OK) - { + for (d = 0; d < qvotec_n_disks; d++) { + if (cluster_voting_disk_read_formation_slot(qvotec_fds[d], (uint32)cluster_node_id, + images[d]) + == CLUSTER_VOTING_DISK_IO_OK) { ClusterFormationCommitMarker dec; if (cluster_formation_marker_validate(images[d], &dec, NULL)) valid[d] = true; } } - for (d = 0; d < qvotec_n_disks && selected < 0; d++) - { - uint32 same = 0; - int e; + for (d = 0; d < qvotec_n_disks && selected < 0; d++) { + uint32 same = 0; + int e; if (!valid[d]) continue; for (e = 0; e < qvotec_n_disks; e++) - if (valid[e] - && memcmp(images[d], images[e], CLUSTER_VOTING_SLOT_BYTES) == 0) + if (valid[e] && memcmp(images[d], images[e], CLUSTER_VOTING_SLOT_BYTES) == 0) same++; if (same >= majority) selected = d; } - if (selected >= 0) - { + if (selected >= 0) { ClusterFormationCommitMarker dec; - uint64 incarnation_by_node[CLUSTER_MAX_NODES]; + uint64 incarnation_by_node[CLUSTER_MAX_NODES]; - if (cluster_formation_marker_decode( - images[selected], &dec, incarnation_by_node)) - cluster_reconfig_formation_qvotec_publish_observed( - &dec, incarnation_by_node); - } - else + if (cluster_formation_marker_decode(images[selected], &dec, incarnation_by_node)) + cluster_reconfig_formation_qvotec_publish_observed(&dec, incarnation_by_node); + } else cluster_reconfig_formation_qvotec_clear_observed(); } @@ -3875,7 +3724,7 @@ qvotec_poll_once(void) uint64 best_gen = 0; uint64 best_incarnation = 0; uint64 best_epoch = 0; - bool fresh; + bool fresh; for (i = 0; i < qvotec_n_disks; i++) { ClusterVotingSlot *cell = &qvotec_slot_matrix[i * CLUSTER_MAX_NODES + node]; @@ -3886,14 +3735,13 @@ qvotec_poll_once(void) best_epoch = cell->current_epoch; } } - cluster_reconfig_record_observed_slot((int32)node, best_incarnation, - best_gen, best_epoch); - fresh = (decision.alive_bitmap[node / 8] - & (uint8) (1u << (node % 8))) != 0; + cluster_reconfig_record_observed_slot((int32)node, best_incarnation, best_gen, + best_epoch); + fresh = (decision.alive_bitmap[node / 8] & (uint8)(1u << (node % 8))) != 0; cluster_reconfig_record_observed_fresh_alive((int32)node, fresh); } - cluster_reconfig_bootstrap_publish_in_quorum( - decision.quorum_state == CLUSTER_QVOTEC_QUORUM_OK); + cluster_reconfig_bootstrap_publish_in_quorum(decision.quorum_state + == CLUSTER_QVOTEC_QUORUM_OK); cluster_reconfig_bootstrap_publish_end(); } } @@ -4032,9 +3880,8 @@ ClusterQvotecMain(void) /* spec-5.15A §2.4.1: start-current invalidates both volatile * completions under the reconfig lock before any latch is published. */ - if (!cluster_reconfig_qvotec_lifecycle_transition( - &QvotecShmem->mailbox, &QvotecShmem->state, - CLUSTER_QVOTEC_STARTING)) + if (!cluster_reconfig_qvotec_lifecycle_transition(&QvotecShmem->mailbox, &QvotecShmem->state, + CLUSTER_QVOTEC_STARTING)) ereport(FATAL, (errmsg("qvotec could not establish STARTING lifecycle cut"))); /* @@ -4111,23 +3958,19 @@ ClusterQvotecMain(void) * formation commits its CURRENT boot incarnations (a new postmaster * never resumes a previous marker's incarnation). */ { - uint64 max_generation = 0; - int n; + uint64 max_generation = 0; + int n; - for (n = 0; n < CLUSTER_MAX_NODES; n++) - { - int d; + for (n = 0; n < CLUSTER_MAX_NODES; n++) { + int d; - for (d = 0; d < qvotec_n_disks; d++) - { - uint8 slot_bytes[CLUSTER_VOTING_SLOT_BYTES]; + for (d = 0; d < qvotec_n_disks; d++) { + uint8 slot_bytes[CLUSTER_VOTING_SLOT_BYTES]; ClusterFormationCommitMarker dec; - if (cluster_voting_disk_read_formation_slot( - qvotec_fds[d], (uint32) n, slot_bytes) + if (cluster_voting_disk_read_formation_slot(qvotec_fds[d], (uint32)n, slot_bytes) == CLUSTER_VOTING_DISK_IO_OK - && cluster_formation_marker_validate( - slot_bytes, &dec, NULL) + && cluster_formation_marker_validate(slot_bytes, &dec, NULL) && dec.formation_generation > max_generation) max_generation = dec.formation_generation; } @@ -4242,9 +4085,8 @@ ClusterQvotecMain(void) } } - if (!cluster_reconfig_qvotec_lifecycle_transition( - &QvotecShmem->mailbox, &QvotecShmem->state, - CLUSTER_QVOTEC_READY)) + if (!cluster_reconfig_qvotec_lifecycle_transition(&QvotecShmem->mailbox, &QvotecShmem->state, + CLUSTER_QVOTEC_READY)) ereport(FATAL, (errmsg("qvotec could not publish READY lifecycle cut"))); for (;;) { @@ -4273,10 +4115,8 @@ ClusterQvotecMain(void) if (ShutdownRequestPending || pg_atomic_read_u32(&QvotecShmem->state) == CLUSTER_QVOTEC_SHUTTING_DOWN) { if (!cluster_reconfig_qvotec_lifecycle_transition( - &QvotecShmem->mailbox, &QvotecShmem->state, - CLUSTER_QVOTEC_SHUTTING_DOWN)) - ereport(FATAL, - (errmsg("qvotec could not publish SHUTTING_DOWN lifecycle cut"))); + &QvotecShmem->mailbox, &QvotecShmem->state, CLUSTER_QVOTEC_SHUTTING_DOWN)) + ereport(FATAL, (errmsg("qvotec could not publish SHUTTING_DOWN lifecycle cut"))); break; } @@ -4298,9 +4138,8 @@ ClusterQvotecMain(void) pg_atomic_fetch_add_u32(&QvotecShmem->poll_cycle_count, 1); cluster_pgstat_inc(qvotec_counter_poll_cycle); - timeout_ms = qvotec_poll_wait_timeout_ms( - INSTR_TIME_GET_MICROSEC(cycle_finished), - cluster_quorum_poll_interval_ms); + timeout_ms = qvotec_poll_wait_timeout_ms(INSTR_TIME_GET_MICROSEC(cycle_finished), + cluster_quorum_poll_interval_ms); qvotec_diagnostic_phase_enter(QVOTEC_DIAG_IDLE); rc = WaitLatch(MyLatch, WL_LATCH_SET | WL_TIMEOUT | WL_EXIT_ON_PM_DEATH, timeout_ms, @@ -4319,9 +4158,8 @@ ClusterQvotecMain(void) if (!qvotec_clear_self_alive_on_clean_shutdown()) ereport(FATAL, (errmsg("qvotec could not complete normal shutdown self-slot clear"))); qvotec_close_disks(); - if (!cluster_reconfig_qvotec_lifecycle_transition( - &QvotecShmem->mailbox, &QvotecShmem->state, - CLUSTER_QVOTEC_DOWN)) + if (!cluster_reconfig_qvotec_lifecycle_transition(&QvotecShmem->mailbox, &QvotecShmem->state, + CLUSTER_QVOTEC_DOWN)) ereport(FATAL, (errmsg("qvotec could not publish DOWN lifecycle cut"))); proc_exit(0); @@ -4365,9 +4203,8 @@ cluster_qvotec_request_shutdown(void) if (QvotecShmem == NULL) return; - (void)cluster_reconfig_qvotec_lifecycle_transition( - &QvotecShmem->mailbox, &QvotecShmem->state, - CLUSTER_QVOTEC_SHUTTING_DOWN); + (void)cluster_reconfig_qvotec_lifecycle_transition(&QvotecShmem->mailbox, &QvotecShmem->state, + CLUSTER_QVOTEC_SHUTTING_DOWN); } diff --git a/src/backend/cluster/cluster_reconfig.c b/src/backend/cluster/cluster_reconfig.c index 32fe963c83a..6bcd14adc07 100644 --- a/src/backend/cluster/cluster_reconfig.c +++ b/src/backend/cluster/cluster_reconfig.c @@ -41,7 +41,7 @@ */ #include "postgres.h" -#include "port/pg_bitutils.h" /* pg_number_of_ones (cold-formation bitmap) */ +#include "port/pg_bitutils.h" /* pg_number_of_ones (cold-formation bitmap) */ #include "cluster/cluster_reconfig.h" #include "cluster/cluster_recovery_duty.h" @@ -55,11 +55,10 @@ * external admissions and IR remain process-local and are rebuilt by the * worker; no pointer or dead-bitmap pair crosses bgw_extra. */ bool -cluster_reconfig_thread_recovery_eligibility_consume( - uint16 origin_thread, - ClusterThreadRecLaunchEligibility *out) +cluster_reconfig_thread_recovery_eligibility_consume(uint16 origin_thread, + ClusterThreadRecLaunchEligibility *out) { - ReconfigEvent event = {0}; + ReconfigEvent event = { 0 }; ClusterControlRootIdentity identity; ClusterControlRootSnapshot snapshot; ClusterControlRootReadToken token; @@ -68,29 +67,25 @@ cluster_reconfig_thread_recovery_eligibility_consume( if (out != NULL) memset(out, 0, sizeof(*out)); - if (out == NULL || origin_thread == 0 || - origin_thread > CLUSTER_MAX_NODES) + if (out == NULL || origin_thread == 0 || origin_thread > CLUSTER_MAX_NODES) return false; #ifndef USE_PGRAC_CLUSTER return false; #else origin_node = (int32)origin_thread - 1; cluster_reconfig_get_last_event(&event); - if (event.reconfig_kind != RECONFIG_KIND_FAIL_STOP || - event.event_id == 0 || event.new_epoch == 0 || - (event.dead_bitmap[origin_node / 8] & - (uint8)(UINT8_C(1) << (origin_node % 8))) == 0) - return false; - root_result = cluster_control_root_lookup_owner_by_node_runtime( - origin_node, &identity, &snapshot, &token); - if ((root_result != CLUSTER_CONTROL_ROOT_OK_PRIMARY && - root_result != CLUSTER_CONTROL_ROOT_OK_PRIMARY_DEGRADED) || - !cluster_recovery_duty_key_valid_v1(&identity) || - identity.origin_thread_id != origin_thread || - identity.origin_node_id != origin_node || - snapshot.lifecycle != - CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_REQUIRED || - memcmp(&snapshot.identity, &identity, sizeof(identity)) != 0) + if (event.reconfig_kind != RECONFIG_KIND_FAIL_STOP || event.event_id == 0 + || event.new_epoch == 0 + || (event.dead_bitmap[origin_node / 8] & (uint8)(UINT8_C(1) << (origin_node % 8))) == 0) + return false; + root_result = cluster_control_root_lookup_owner_by_node_runtime(origin_node, &identity, + &snapshot, &token); + if ((root_result != CLUSTER_CONTROL_ROOT_OK_PRIMARY + && root_result != CLUSTER_CONTROL_ROOT_OK_PRIMARY_DEGRADED) + || !cluster_recovery_duty_key_valid_v1(&identity) + || identity.origin_thread_id != origin_thread || identity.origin_node_id != origin_node + || snapshot.lifecycle != CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_REQUIRED + || memcmp(&snapshot.identity, &identity, sizeof(identity)) != 0) return false; out->origin_thread = origin_thread; out->attempt_stamp = event.new_epoch; @@ -103,13 +98,13 @@ cluster_reconfig_thread_recovery_eligibility_consume( #include -#include "access/transam.h" /* TransactionIdIsValid */ -#include "access/xact.h" /* IsTransactionState (Step 2 D4) */ -#include "access/xlog.h" /* GetXLogInsertRecPtr (Step 2 D2) */ -#include "common/hashfn.h" /* hash_bytes_extended */ -#include "fmgr.h" /* PG_FUNCTION_ARGS (Step 3 D5b SRF) */ -#include "funcapi.h" /* InitMaterializedSRF (Step 3 D5b SRF) */ -#include "miscadmin.h" /* MyProcPid */ +#include "access/transam.h" /* TransactionIdIsValid */ +#include "access/xact.h" /* IsTransactionState (Step 2 D4) */ +#include "access/xlog.h" /* GetXLogInsertRecPtr (Step 2 D2) */ +#include "common/hashfn.h" /* hash_bytes_extended */ +#include "fmgr.h" /* PG_FUNCTION_ARGS (Step 3 D5b SRF) */ +#include "funcapi.h" /* InitMaterializedSRF (Step 3 D5b SRF) */ +#include "miscadmin.h" /* MyProcPid */ #include "postmaster/interrupt.h" /* ShutdownRequestPending */ #include "storage/lwlock.h" #include "storage/proc.h" /* PGPROC */ @@ -120,21 +115,21 @@ cluster_reconfig_thread_recovery_eligibility_consume( #include "utils/timestamp.h" #include "utils/wait_event.h" /* WAIT_EVENT_CLUSTER_BGPROC_LMON_RECONFIG_TICK (D9) */ -#include "cluster/cluster_conf.h" /* cluster_conf_lookup_node */ -#include "cluster/cluster_cssd.h" /* cluster_cssd_get_peer_state, get_dead_generation */ -#include "cluster/cluster_elog.h" /* cluster_node_id */ -#include "cluster/cluster_epoch.h" /* advance + observe + set_changed_at_lsn */ +#include "cluster/cluster_conf.h" /* cluster_conf_lookup_node */ +#include "cluster/cluster_cssd.h" /* cluster_cssd_get_peer_state, get_dead_generation */ +#include "cluster/cluster_elog.h" /* cluster_node_id */ +#include "cluster/cluster_epoch.h" /* advance + observe + set_changed_at_lsn */ #include "cluster/cluster_external_fence.h" /* STOP04 rejoin snapshots */ -#include "cluster/cluster_gcs_block.h" /* spec-2.34 D4 — eager epoch wake hook */ -#include "cluster/cluster_grd.h" /* spec-5.16 D3b — arm join PCM block fence */ -#include "cluster/cluster_ic.h" /* Candidate2 HELLO capability */ -#include "cluster/cluster_startup_phase.h" /* RF-ROOT P04 serving split */ -#include "cluster/cluster_ic_router.h" /* phase-3 target-LMON CONTROL send */ -#include "cluster/cluster_ic_tier1.h" /* close peer after send HARD_ERROR */ -#include "cluster/cluster_sinval.h" /* spec-2.39 D14 — RESET-all reconfig hook */ -#include "cluster/cluster_tt_status.h" /* spec-3.1 D7 — TT status overlay flush hook */ +#include "cluster/cluster_gcs_block.h" /* spec-2.34 D4 — eager epoch wake hook */ +#include "cluster/cluster_grd.h" /* spec-5.16 D3b — arm join PCM block fence */ +#include "cluster/cluster_ic.h" /* Candidate2 HELLO capability */ +#include "cluster/cluster_startup_phase.h" /* RF-ROOT P04 serving split */ +#include "cluster/cluster_ic_router.h" /* phase-3 target-LMON CONTROL send */ +#include "cluster/cluster_ic_tier1.h" /* close peer after send HARD_ERROR */ +#include "cluster/cluster_sinval.h" /* spec-2.39 D14 — RESET-all reconfig hook */ +#include "cluster/cluster_tt_status.h" /* spec-3.1 D7 — TT status overlay flush hook */ #include "cluster/storage/cluster_undo_block0.h" /* instantaneous R4A READY */ -#include "storage/ipc.h" /* on_shmem_exit (spec-5.15 D4 latch clear) */ +#include "storage/ipc.h" /* on_shmem_exit (spec-5.15 D4 latch clear) */ #include "storage/latch.h" /* Latch / SetLatch (spec-5.15 D4 marker mailbox) */ #include "cluster/cluster_clean_leave.h" /* v1.0.4 — cluster_clean_leave_in_progress (serialize) */ #include "cluster/cluster_guc.h" /* cluster_enabled, cluster_online_join */ @@ -201,37 +196,29 @@ cluster_reconfig_membership_floor_diagnostic(const char *stage) if (ReconfigShmem == NULL || stage == NULL) return; for (node = 0; node < 4; node++) { - floor[node] - = cluster_membership_get_last_admitted_incarnation(node); + floor[node] = cluster_membership_get_last_admitted_incarnation(node); state[node] = (uint8)cluster_membership_get_state(node); - if (state[node] == (uint8)CLUSTER_MEMBER_MEMBER - && floor[node] == 0) + if (state[node] == (uint8)CLUSTER_MEMBER_MEMBER && floor[node] == 0) invalid = true; - if (initialized && prior_floor[node] != 0 - && floor[node] < prior_floor[node]) + if (initialized && prior_floor[node] != 0 && floor[node] < prior_floor[node]) regressed = true; } if (invalid || regressed) - ereport(LOG, - (errmsg_internal("cluster membership floor diagnostic"), - errdetail("stage=%s invalid=%u regressed=%u " - "m0=%u/%llu<- %u/%llu " - "m1=%u/%llu<- %u/%llu " - "m2=%u/%llu<- %u/%llu " - "m3=%u/%llu<- %u/%llu", - stage, invalid ? 1U : 0U, regressed ? 1U : 0U, - state[0], (unsigned long long)floor[0], - prior_state[0], - (unsigned long long)prior_floor[0], - state[1], (unsigned long long)floor[1], - prior_state[1], - (unsigned long long)prior_floor[1], - state[2], (unsigned long long)floor[2], - prior_state[2], - (unsigned long long)prior_floor[2], - state[3], (unsigned long long)floor[3], - prior_state[3], - (unsigned long long)prior_floor[3]))); + ereport( + LOG, + (errmsg_internal("cluster membership floor diagnostic"), + errdetail("stage=%s invalid=%u regressed=%u " + "m0=%u/%llu<- %u/%llu " + "m1=%u/%llu<- %u/%llu " + "m2=%u/%llu<- %u/%llu " + "m3=%u/%llu<- %u/%llu", + stage, invalid ? 1U : 0U, regressed ? 1U : 0U, state[0], + (unsigned long long)floor[0], prior_state[0], + (unsigned long long)prior_floor[0], state[1], (unsigned long long)floor[1], + prior_state[1], (unsigned long long)prior_floor[1], state[2], + (unsigned long long)floor[2], prior_state[2], + (unsigned long long)prior_floor[2], state[3], (unsigned long long)floor[3], + prior_state[3], (unsigned long long)prior_floor[3]))); memcpy(prior_floor, floor, sizeof(prior_floor)); memcpy(prior_state, state, sizeof(prior_state)); initialized = true; @@ -244,15 +231,14 @@ cluster_reconfig_membership_floor_diagnostic(const char *stage) * consumes admission_done) so the self-state decision can keep the * marker-admitted node MEMBER instead of demoting it back to JOINING. */ -typedef struct ClusterColdFormationState -{ - bool observe_passed; - uint64 observe_ticks; - uint64 coboot_lo; - uint64 coboot_hi; - bool arbiter_submitted; - uint64 arbiter_seq; - bool admission_done; +typedef struct ClusterColdFormationState { + bool observe_passed; + uint64 observe_ticks; + uint64 coboot_lo; + uint64 coboot_hi; + bool arbiter_submitted; + uint64 arbiter_seq; + bool admission_done; } ClusterColdFormationState; static ClusterColdFormationState cold_formation_state; @@ -578,21 +564,18 @@ cluster_reconfig_normal_stop_poll(const char **domain_out, uint64 *key_out, cons } static bool cluster_reconfig_join_marker_request_word_decode( - uint32 word, ClusterJoinMarkerMailboxOperationV1 *operation_out, - int32 *target_node_out); -static bool cluster_reconfig_stage_join_marker_locked( - int32 target_node, ClusterJoinMarkerMailboxOperationV1 operation, - uint32 version, const void *image, Size image_len); + uint32 word, ClusterJoinMarkerMailboxOperationV1 *operation_out, int32 *target_node_out); +static bool cluster_reconfig_stage_join_marker_locked(int32 target_node, + ClusterJoinMarkerMailboxOperationV1 operation, + uint32 version, const void *image, + Size image_len); static bool cluster_reconfig_terminal_closed_matches_episode( - const ClusterEpochAuthorityValue *head, - const ClusterEpochBallotId *ballot, - const ClusterReplacementCommitMarkerV3 *marker, - const ClusterReplacementEpisode *episode); + const ClusterEpochAuthorityValue *head, const ClusterEpochBallotId *ballot, + const ClusterReplacementCommitMarkerV3 *marker, const ClusterReplacementEpisode *episode); static void cluster_reconfig_release_ready_stage(void); static bool cluster_reconfig_lmon_submit_ready_observer_pair(TimestampTz now); -static bool cluster_reconfig_lmon_ready_cache_current( - int32 *coordinator_node_id); +static bool cluster_reconfig_lmon_ready_cache_current(int32 *coordinator_node_id); /* ============================================================ @@ -692,11 +675,9 @@ cluster_reconfig_shmem_init(void) pg_atomic_init_u64(&ReconfigShmem->observed_formation_marker_generation, 0); pg_atomic_init_u64(&ReconfigShmem->observed_formation_marker_epoch, 0); pg_atomic_init_u64(&ReconfigShmem->observed_formation_marker_arbiter_node, 0); - pg_atomic_init_u64( - &ReconfigShmem->observed_formation_marker_arbiter_incarnation, 0); + pg_atomic_init_u64(&ReconfigShmem->observed_formation_marker_arbiter_incarnation, 0); for (int n = 0; n < CLUSTER_MAX_NODES; n++) - pg_atomic_init_u64( - &ReconfigShmem->observed_formation_marker_incarnation[n], 0); + pg_atomic_init_u64(&ReconfigShmem->observed_formation_marker_incarnation[n], 0); /* spec-5.15 D4 — join-marker submit mailbox (latch published by qvotec). */ ReconfigShmem->join_qvotec_latch = NULL; @@ -772,7 +753,7 @@ cluster_reconfig_get_last_event(ReconfigEvent *out) bool cluster_reconfig_capture_formation_snapshot_v1(uint16 origin_thread, - ClusterFormationSnapshotV1 *out) + ClusterFormationSnapshotV1 *out) { const ReconfigEvent *src; int32 origin_node; @@ -811,14 +792,11 @@ cluster_reconfig_capture_formation_snapshot_v1(uint16 origin_thread, sizeof(out->pending_join_bitmap)); memcpy(out->clean_departed_bitmap, ReconfigShmem->clean_departed_bitmap, sizeof(out->clean_departed_bitmap)); - memcpy(out->removed_bitmap, ReconfigShmem->removed_bitmap, - sizeof(out->removed_bitmap)); + memcpy(out->removed_bitmap, ReconfigShmem->removed_bitmap, sizeof(out->removed_bitmap)); for (i = 0; i < CLUSTER_RECONFIG_DEAD_BITMAP_BYTES; i++) out->excluded_bitmap[i] = src->dead_bitmap[i] | ReconfigShmem->removed_bitmap[i]; - out->victim_incarnation - = ReconfigShmem->membership.last_admitted_incarnation[origin_node]; - out->prebump_sync_active - = pg_atomic_read_u32(&ReconfigShmem->prebump_sync_active); + out->victim_incarnation = ReconfigShmem->membership.last_admitted_incarnation[origin_node]; + out->prebump_sync_active = pg_atomic_read_u32(&ReconfigShmem->prebump_sync_active); out->self_join_admitted = ReconfigShmem->self_join_admitted; out->self_join_failed = ReconfigShmem->self_join_failed; LWLockRelease(&ReconfigShmem->lock); @@ -831,8 +809,7 @@ cluster_reconfig_set_prebump_sync_active(uint32 value) { uint64 cache_mutation; - if (ReconfigShmem == NULL - || pg_atomic_read_u32(&ReconfigShmem->prebump_sync_active) == value) + if (ReconfigShmem == NULL || pg_atomic_read_u32(&ReconfigShmem->prebump_sync_active) == value) return; cache_mutation = cluster_write_fence_authority_cache_mutation_begin(); pg_atomic_write_u32(&ReconfigShmem->prebump_sync_active, value); @@ -1062,21 +1039,20 @@ replacement_event_id_put_le64(uint8 *out, uint64 value) bool -cluster_reconfig_build_replacement_committed_event( - const ClusterReplacementEpisode *episode, int32 observer_role, - TimestampTz applied_at, ReconfigEvent *out_event) +cluster_reconfig_build_replacement_committed_event(const ClusterReplacementEpisode *episode, + int32 observer_role, TimestampTz applied_at, + ReconfigEvent *out_event) { - uint8 hash_input[1 + 4 + 8 + 8 + 8 + 8 + 8 - + CLUSTER_RECONFIG_DEAD_BITMAP_BYTES + 8]; + uint8 hash_input[1 + 4 + 8 + 8 + 8 + 8 + 8 + CLUSTER_RECONFIG_DEAD_BITMAP_BYTES + 8]; ReconfigEvent event; Size off = 0; - if (episode == NULL || out_event == NULL - || !cluster_replacement_episode_is_valid(episode) + if (episode == NULL || out_event == NULL || !cluster_replacement_episode_is_valid(episode) || (episode->phase != CLUSTER_REPLACEMENT_EPISODE_COMMITTED_CLOSED && episode->phase != CLUSTER_REPLACEMENT_EPISODE_POST_EPOCH) || memcmp(episode->acknowledgements, episode->expected_survivors, - sizeof(episode->acknowledgements)) != 0 + sizeof(episode->acknowledgements)) + != 0 || (observer_role != CLUSTER_RECONFIG_OBSERVER_COORDINATOR && observer_role != CLUSTER_RECONFIG_OBSERVER_SURVIVOR)) return false; @@ -1084,27 +1060,21 @@ cluster_reconfig_build_replacement_committed_event( /* Spec-5.15A §2.4 exact identity, encoded explicitly so identical * observers hash identical bytes independent of host padding/layout. */ hash_input[off++] = RECONFIG_KIND_REPLACEMENT_COMMITTED; - replacement_event_id_put_le32(hash_input + off, - (uint32)episode->target_node_id); + replacement_event_id_put_le32(hash_input + off, (uint32)episode->target_node_id); off += 4; replacement_event_id_put_le64(hash_input + off, episode->baseline_epoch); off += 8; - replacement_event_id_put_le64( - hash_input + off, episode->reserved_or_committed_epoch); + replacement_event_id_put_le64(hash_input + off, episode->reserved_or_committed_epoch); off += 8; - replacement_event_id_put_le64( - hash_input + off, episode->old_admitted_incarnation); + replacement_event_id_put_le64(hash_input + off, episode->old_admitted_incarnation); off += 8; - replacement_event_id_put_le64( - hash_input + off, episode->fresh_incarnation); + replacement_event_id_put_le64(hash_input + off, episode->fresh_incarnation); off += 8; replacement_event_id_put_le64(hash_input + off, episode->request_nonce); off += 8; - memcpy(hash_input + off, episode->expected_survivors, - CLUSTER_RECONFIG_DEAD_BITMAP_BYTES); + memcpy(hash_input + off, episode->expected_survivors, CLUSTER_RECONFIG_DEAD_BITMAP_BYTES); off += CLUSTER_RECONFIG_DEAD_BITMAP_BYTES; - replacement_event_id_put_le64( - hash_input + off, episode->grammar_fingerprint); + replacement_event_id_put_le64(hash_input + off, episode->grammar_fingerprint); off += 8; Assert(off == sizeof(hash_input)); @@ -1127,60 +1097,50 @@ cluster_reconfig_build_replacement_committed_event( bool cluster_reconfig_replacement_grd_basis_authorized( const ReconfigEvent *event, const ClusterReplacementEpisode *episode, - const ClusterReplacementCommitMarkerV3 *committed_marker, - int32 local_node_id, - uint8 out_survivors[CLUSTER_RECONFIG_DEAD_BITMAP_BYTES], - uint64 *out_epoch) + const ClusterReplacementCommitMarkerV3 *committed_marker, int32 local_node_id, + uint8 out_survivors[CLUSTER_RECONFIG_DEAD_BITMAP_BYTES], uint64 *out_epoch) { ReconfigEvent expected_event; uint8 marker_image[CLUSTER_JCMK_REPLACEMENT_BYTES]; int32 expected_role; - if (event == NULL || episode == NULL || committed_marker == NULL - || out_survivors == NULL || out_epoch == NULL - || local_node_id < 0 || local_node_id >= CLUSTER_MAX_NODES + if (event == NULL || episode == NULL || committed_marker == NULL || out_survivors == NULL + || out_epoch == NULL || local_node_id < 0 || local_node_id >= CLUSTER_MAX_NODES || !cluster_replacement_episode_is_valid(episode) - || (episode->phase - != CLUSTER_REPLACEMENT_EPISODE_COMMITTED_CLOSED + || (episode->phase != CLUSTER_REPLACEMENT_EPISODE_COMMITTED_CLOSED && episode->phase != CLUSTER_REPLACEMENT_EPISODE_POST_EPOCH) || memcmp(episode->acknowledgements, episode->expected_survivors, - sizeof(episode->acknowledgements)) != 0 + sizeof(episode->acknowledgements)) + != 0 || local_node_id == episode->target_node_id || !dead_bitmap_test_bit(episode->expected_survivors, local_node_id) - || !cluster_replacement_marker_v3_encode( - committed_marker, marker_image) - || committed_marker->phase - != CLUSTER_JCMK_REPLACEMENT_PHASE_COMMITTED_CLOSED + || !cluster_replacement_marker_v3_encode(committed_marker, marker_image) + || committed_marker->phase != CLUSTER_JCMK_REPLACEMENT_PHASE_COMMITTED_CLOSED || committed_marker->ready_state_generation != 0 || committed_marker->target_node_id != episode->target_node_id - || committed_marker->old_admitted_incarnation - != episode->old_admitted_incarnation - || committed_marker->fresh_incarnation - != episode->fresh_incarnation + || committed_marker->old_admitted_incarnation != episode->old_admitted_incarnation + || committed_marker->fresh_incarnation != episode->fresh_incarnation || committed_marker->baseline_epoch != episode->baseline_epoch - || committed_marker->reserved_or_committed_epoch - != episode->reserved_or_committed_epoch + || committed_marker->reserved_or_committed_epoch != episode->reserved_or_committed_epoch || committed_marker->request_nonce != episode->request_nonce - || memcmp(committed_marker->expected_purge_survivors, - episode->expected_survivors, - sizeof(episode->expected_survivors)) != 0 - || committed_marker->grammar_fingerprint - != episode->grammar_fingerprint) + || memcmp(committed_marker->expected_purge_survivors, episode->expected_survivors, + sizeof(episode->expected_survivors)) + != 0 + || committed_marker->grammar_fingerprint != episode->grammar_fingerprint) return false; expected_role = local_node_id == episode->coordinator_node_id - ? CLUSTER_RECONFIG_OBSERVER_COORDINATOR - : CLUSTER_RECONFIG_OBSERVER_SURVIVOR; + ? CLUSTER_RECONFIG_OBSERVER_COORDINATOR + : CLUSTER_RECONFIG_OBSERVER_SURVIVOR; if (event->event_seq == 0 || event->observer_role != expected_role - || !cluster_reconfig_build_replacement_committed_event( - episode, expected_role, event->applied_at, &expected_event)) + || !cluster_reconfig_build_replacement_committed_event(episode, expected_role, + event->applied_at, &expected_event)) return false; expected_event.event_seq = event->event_seq; if (memcmp(event, &expected_event, sizeof(*event)) != 0) return false; - memcpy(out_survivors, episode->expected_survivors, - CLUSTER_RECONFIG_DEAD_BITMAP_BYTES); + memcpy(out_survivors, episode->expected_survivors, CLUSTER_RECONFIG_DEAD_BITMAP_BYTES); *out_epoch = episode->reserved_or_committed_epoch; return true; } @@ -1188,8 +1148,7 @@ cluster_reconfig_replacement_grd_basis_authorized( bool cluster_reconfig_lmon_snapshot_replacement_grd_basis( - uint8 out_survivors[CLUSTER_RECONFIG_DEAD_BITMAP_BYTES], - uint64 *out_epoch) + uint8 out_survivors[CLUSTER_RECONFIG_DEAD_BITMAP_BYTES], uint64 *out_epoch) { ClusterReplacementEpisode episode; ClusterReplacementCommitMarkerV3 committed; @@ -1200,36 +1159,28 @@ cluster_reconfig_lmon_snapshot_replacement_grd_basis( uint64 completion_seq; bool valid = false; - if (ReconfigShmem == NULL || out_survivors == NULL || out_epoch == NULL - || cluster_node_id < 0 || cluster_node_id >= CLUSTER_MAX_NODES) + if (ReconfigShmem == NULL || out_survivors == NULL || out_epoch == NULL || cluster_node_id < 0 + || cluster_node_id >= CLUSTER_MAX_NODES) return false; request_seq = pg_atomic_read_u64(&ReconfigShmem->join_marker_request_seq); - completion_seq - = pg_atomic_read_u64(&ReconfigShmem->join_marker_completion_seq); + completion_seq = pg_atomic_read_u64(&ReconfigShmem->join_marker_completion_seq); if (request_seq == 0 || request_seq != completion_seq - || pg_atomic_read_u32(&ReconfigShmem->join_marker_result) - != CLUSTER_JOIN_MARKER_SUBMIT_ACK) + || pg_atomic_read_u32(&ReconfigShmem->join_marker_result) != CLUSTER_JOIN_MARKER_SUBMIT_ACK) return false; pg_read_barrier(); LWLockAcquire(&ReconfigShmem->lock, LW_SHARED); episode = ReconfigShmem->replacement_episode; event = ReconfigShmem->last_applied; - if (pg_atomic_read_u64(&ReconfigShmem->join_marker_request_seq) - != request_seq - || pg_atomic_read_u64(&ReconfigShmem->join_marker_completion_seq) - != completion_seq - || pg_atomic_read_u32(&ReconfigShmem->join_marker_result) - != CLUSTER_JOIN_MARKER_SUBMIT_ACK - || episode.reserved_or_committed_epoch - != cluster_epoch_get_current() - || !cluster_replacement_marker_v3_decode( - ReconfigShmem->join_pending_marker, episode.target_node_id, - &committed) - || !cluster_reconfig_replacement_grd_basis_authorized( - &event, &episode, &committed, cluster_node_id, - survivors, &epoch)) + if (pg_atomic_read_u64(&ReconfigShmem->join_marker_request_seq) != request_seq + || pg_atomic_read_u64(&ReconfigShmem->join_marker_completion_seq) != completion_seq + || pg_atomic_read_u32(&ReconfigShmem->join_marker_result) != CLUSTER_JOIN_MARKER_SUBMIT_ACK + || episode.reserved_or_committed_epoch != cluster_epoch_get_current() + || !cluster_replacement_marker_v3_decode(ReconfigShmem->join_pending_marker, + episode.target_node_id, &committed) + || !cluster_reconfig_replacement_grd_basis_authorized(&event, &episode, &committed, + cluster_node_id, survivors, &epoch)) goto out; valid = true; @@ -1250,8 +1201,7 @@ cluster_reconfig_lmon_snapshot_replacement_grd_basis( * before deriving or publishing ADMITTED state. */ static bool -cluster_reconfig_replacement_candidate2_capabilities_current( - ClusterReplacementEpisode *out_episode) +cluster_reconfig_replacement_candidate2_capabilities_current(ClusterReplacementEpisode *out_episode) { ClusterReplacementEpisode snapshot; int node; @@ -1267,16 +1217,14 @@ cluster_reconfig_replacement_candidate2_capabilities_current( return false; for (node = 0; node < CLUSTER_MAX_NODES; node++) { - bool required - = node == snapshot.target_node_id - || dead_bitmap_test_bit(snapshot.expected_survivors, node); + bool required = node == snapshot.target_node_id + || dead_bitmap_test_bit(snapshot.expected_survivors, node); /* The running coordinator binary is its own compiled proof. */ if (!required || node == cluster_node_id) continue; if (!cluster_sf_peer_capability_family_sample( - node, PGRAC_IC_HELLO_CAP_CANDIDATE2_CORRECTED_A1_V1, - 0, NULL, NULL)) + node, PGRAC_IC_HELLO_CAP_CANDIDATE2_CORRECTED_A1_V1, 0, NULL, NULL)) return false; } @@ -1288,14 +1236,12 @@ cluster_reconfig_replacement_candidate2_capabilities_current( /* Caller holds ReconfigShmem->lock. Before ADMITTED, the immutable survivor * bitmap is the complete live MEMBER set and the fenced target is still out. */ static bool -cluster_reconfig_replacement_membership_current_locked( - const ClusterReplacementEpisode *episode) +cluster_reconfig_replacement_membership_current_locked(const ClusterReplacementEpisode *episode) { int node; for (node = 0; node < CLUSTER_MAX_NODES; node++) { - bool expected_member - = dead_bitmap_test_bit(episode->expected_survivors, node); + bool expected_member = dead_bitmap_test_bit(episode->expected_survivors, node); if (cluster_membership_is_member(node) != expected_member) return false; @@ -1314,9 +1260,8 @@ cluster_reconfig_replacement_membership_current_locked( */ bool cluster_reconfig_replacement_purge_request_authorized( - const ClusterReplacementWireMessage *request, - int32 authenticated_source_node_id, int32 local_receiver_node_id, - const ClusterEpochAuthorityValue *settled_reserve, + const ClusterReplacementWireMessage *request, int32 authenticated_source_node_id, + int32 local_receiver_node_id, const ClusterEpochAuthorityValue *settled_reserve, const ClusterEpochBallotId *settled_ballot, const ClusterReplacementCommitMarkerV3 *durable_prepare) { @@ -1328,99 +1273,75 @@ cluster_reconfig_replacement_purge_request_authorized( bool authorized = false; if (ReconfigShmem == NULL || request == NULL || settled_reserve == NULL - || settled_ballot == NULL || durable_prepare == NULL - || cluster_node_id < 0 || cluster_node_id >= CLUSTER_MAX_NODES - || local_receiver_node_id != cluster_node_id - || authenticated_source_node_id < 0 - || authenticated_source_node_id >= CLUSTER_MAX_NODES + || settled_ballot == NULL || durable_prepare == NULL || cluster_node_id < 0 + || cluster_node_id >= CLUSTER_MAX_NODES || local_receiver_node_id != cluster_node_id + || authenticated_source_node_id < 0 || authenticated_source_node_id >= CLUSTER_MAX_NODES || authenticated_source_node_id == local_receiver_node_id || request->phase != CLUSTER_REPLACEMENT_WIRE_PHASE_PURGE_REQUEST - || request->grammar_fingerprint - != CLUSTER_REPLACEMENT_EPISODE_GRAMMAR_FINGERPRINT - || !cluster_epoch_authority_value_is_valid( - settled_reserve, CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT) + || request->grammar_fingerprint != CLUSTER_REPLACEMENT_EPISODE_GRAMMAR_FINGERPRINT + || !cluster_epoch_authority_value_is_valid(settled_reserve, + CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT) || settled_reserve->transition != CLUSTER_EPOCH_AUTHORITY_RESERVE - || settled_reserve->event_kind - != CLUSTER_EPOCH_EVENT_SAME_NODE_REPLACEMENT + || settled_reserve->event_kind != CLUSTER_EPOCH_EVENT_SAME_NODE_REPLACEMENT || !cluster_epoch_ballot_id_is_valid(settled_ballot) - || settled_ballot->proposer_node_id - != authenticated_source_node_id - || !cluster_replacement_marker_v3_encode( - durable_prepare, prepare_image) - || durable_prepare->phase - != CLUSTER_JCMK_REPLACEMENT_PHASE_PREPARE + || settled_ballot->proposer_node_id != authenticated_source_node_id + || !cluster_replacement_marker_v3_encode(durable_prepare, prepare_image) + || durable_prepare->phase != CLUSTER_JCMK_REPLACEMENT_PHASE_PREPARE || durable_prepare->ready_state_generation != 0) return false; - if (!cluster_reconfig_replacement_candidate2_capabilities_current( - &capability_episode)) + if (!cluster_reconfig_replacement_candidate2_capabilities_current(&capability_episode)) return false; LWLockAcquire(&ReconfigShmem->lock, LW_SHARED); episode = &ReconfigShmem->replacement_episode; - if (episode->target_node_id >= 0 - && episode->target_node_id < CLUSTER_MAX_NODES) - subject[episode->target_node_id / 8] - = (uint8)(1u << (episode->target_node_id % 8)); + if (episode->target_node_id >= 0 && episode->target_node_id < CLUSTER_MAX_NODES) + subject[episode->target_node_id / 8] = (uint8)(1u << (episode->target_node_id % 8)); if (memcmp(episode, &capability_episode, sizeof(*episode)) != 0 || !cluster_replacement_episode_is_valid(episode) - || (episode->phase - != CLUSTER_REPLACEMENT_EPISODE_PREPARE_DURABLE + || (episode->phase != CLUSTER_REPLACEMENT_EPISODE_PREPARE_DURABLE && episode->phase != CLUSTER_REPLACEMENT_EPISODE_PURGING) || episode->readiness_flags != 0 - || memcmp(episode->acknowledgements, zero_acks, - sizeof(zero_acks)) != 0 - || episode->coordinator_node_id - != authenticated_source_node_id - || !dead_bitmap_test_bit(episode->expected_survivors, - authenticated_source_node_id) - || !dead_bitmap_test_bit(episode->expected_survivors, - local_receiver_node_id) + || memcmp(episode->acknowledgements, zero_acks, sizeof(zero_acks)) != 0 + || episode->coordinator_node_id != authenticated_source_node_id + || !dead_bitmap_test_bit(episode->expected_survivors, authenticated_source_node_id) + || !dead_bitmap_test_bit(episode->expected_survivors, local_receiver_node_id) || !cluster_reconfig_replacement_membership_current_locked(episode) || cluster_epoch_get_current() != episode->baseline_epoch - || cluster_membership_get_last_admitted_incarnation( - authenticated_source_node_id) + || cluster_membership_get_last_admitted_incarnation(authenticated_source_node_id) != settled_ballot->proposer_admitted_incarnation - || cluster_membership_get_last_admitted_incarnation( - episode->target_node_id) + || cluster_membership_get_last_admitted_incarnation(episode->target_node_id) != episode->old_admitted_incarnation || request->target_node_id != episode->target_node_id || request->epoch != episode->baseline_epoch || request->request_nonce != episode->request_nonce || request->identity0 != episode->old_admitted_incarnation || request->identity1 != episode->fresh_incarnation - || memcmp(request->body.bitmap, episode->expected_survivors, - sizeof(request->body.bitmap)) != 0 + || memcmp(request->body.bitmap, episode->expected_survivors, sizeof(request->body.bitmap)) + != 0 || request->grammar_fingerprint != episode->grammar_fingerprint || settled_reserve->request_origin_node != episode->target_node_id || settled_reserve->target_node_id != episode->target_node_id || settled_reserve->baseline_epoch != episode->baseline_epoch - || settled_reserve->reserved_epoch - != episode->reserved_or_committed_epoch - || settled_reserve->old_incarnation - != episode->old_admitted_incarnation + || settled_reserve->reserved_epoch != episode->reserved_or_committed_epoch + || settled_reserve->old_incarnation != episode->old_admitted_incarnation || settled_reserve->fresh_incarnation != episode->fresh_incarnation || settled_reserve->request_nonce != episode->request_nonce - || memcmp(settled_reserve->authority_member_bitmap, - episode->expected_survivors, - sizeof(settled_reserve->authority_member_bitmap)) != 0 - || memcmp(settled_reserve->event_subject_bitmap, subject, - sizeof(subject)) != 0 - || settled_reserve->grammar_fingerprint - != episode->grammar_fingerprint + || memcmp(settled_reserve->authority_member_bitmap, episode->expected_survivors, + sizeof(settled_reserve->authority_member_bitmap)) + != 0 + || memcmp(settled_reserve->event_subject_bitmap, subject, sizeof(subject)) != 0 + || settled_reserve->grammar_fingerprint != episode->grammar_fingerprint || durable_prepare->target_node_id != episode->target_node_id - || durable_prepare->old_admitted_incarnation - != episode->old_admitted_incarnation + || durable_prepare->old_admitted_incarnation != episode->old_admitted_incarnation || durable_prepare->fresh_incarnation != episode->fresh_incarnation || durable_prepare->baseline_epoch != episode->baseline_epoch - || durable_prepare->reserved_or_committed_epoch - != episode->reserved_or_committed_epoch + || durable_prepare->reserved_or_committed_epoch != episode->reserved_or_committed_epoch || durable_prepare->request_nonce != episode->request_nonce - || memcmp(durable_prepare->expected_purge_survivors, - episode->expected_survivors, - sizeof(durable_prepare->expected_purge_survivors)) != 0 - || durable_prepare->grammar_fingerprint - != episode->grammar_fingerprint) + || memcmp(durable_prepare->expected_purge_survivors, episode->expected_survivors, + sizeof(durable_prepare->expected_purge_survivors)) + != 0 + || durable_prepare->grammar_fingerprint != episode->grammar_fingerprint) goto out; authorized = true; @@ -1437,8 +1358,7 @@ bool cluster_reconfig_replacement_purge_request_ingress_authorized( const ClusterICEnvelope *env, const void *payload, uint32 payload_length, int32 authenticated_source_node_id, int32 local_receiver_node_id, - const ClusterEpochAuthorityValue *settled_reserve, - const ClusterEpochBallotId *settled_ballot, + const ClusterEpochAuthorityValue *settled_reserve, const ClusterEpochBallotId *settled_ballot, const ClusterReplacementCommitMarkerV3 *durable_prepare, ClusterReplacementWireMessage *out_request) { @@ -1447,21 +1367,18 @@ cluster_reconfig_replacement_purge_request_ingress_authorized( if (env == NULL || payload == NULL || out_request == NULL || payload_length != CLUSTER_REPLACEMENT_WIRE_BYTES || env->msg_type != PGRAC_IC_MSG_GES_REQUEST - || env->payload_length != CLUSTER_REPLACEMENT_WIRE_BYTES - || authenticated_source_node_id < 0 - || authenticated_source_node_id >= CLUSTER_MAX_NODES - || local_receiver_node_id < 0 + || env->payload_length != CLUSTER_REPLACEMENT_WIRE_BYTES || authenticated_source_node_id < 0 + || authenticated_source_node_id >= CLUSTER_MAX_NODES || local_receiver_node_id < 0 || local_receiver_node_id >= CLUSTER_MAX_NODES || authenticated_source_node_id == local_receiver_node_id || env->source_node_id != (uint32)authenticated_source_node_id || env->dest_node_id != (uint32)local_receiver_node_id || env->epoch != cluster_epoch_get_current() - || !cluster_replacement_wire_decode( - (const uint8 *)payload, &request) + || !cluster_replacement_wire_decode((const uint8 *)payload, &request) || request.epoch != env->epoch || !cluster_reconfig_replacement_purge_request_authorized( - &request, authenticated_source_node_id, local_receiver_node_id, - settled_reserve, settled_ballot, durable_prepare)) + &request, authenticated_source_node_id, local_receiver_node_id, settled_reserve, + settled_ballot, durable_prepare)) return false; *out_request = request; return true; @@ -1476,12 +1393,10 @@ cluster_reconfig_replacement_purge_request_ingress_authorized( */ bool cluster_reconfig_replacement_purge_ack_authorized( - const ClusterReplacementWireMessage *ack, - int32 authenticated_source_node_id, int32 local_receiver_node_id, - const ClusterEpochAuthorityValue *settled_reserve, + const ClusterReplacementWireMessage *ack, int32 authenticated_source_node_id, + int32 local_receiver_node_id, const ClusterEpochAuthorityValue *settled_reserve, const ClusterEpochBallotId *settled_ballot, - const ClusterReplacementCommitMarkerV3 *durable_prepare, - int32 *out_ack_node_id) + const ClusterReplacementCommitMarkerV3 *durable_prepare, int32 *out_ack_node_id) { ClusterReplacementEpisode capability_episode; ClusterReplacementEpisode *episode; @@ -1489,96 +1404,72 @@ cluster_reconfig_replacement_purge_ack_authorized( uint8 subject[CLUSTER_RECONFIG_DEAD_BITMAP_BYTES] = { 0 }; bool authorized = false; - if (ReconfigShmem == NULL || ack == NULL || settled_reserve == NULL - || settled_ballot == NULL || durable_prepare == NULL - || out_ack_node_id == NULL || cluster_node_id < 0 - || cluster_node_id >= CLUSTER_MAX_NODES - || local_receiver_node_id != cluster_node_id - || authenticated_source_node_id < 0 - || authenticated_source_node_id >= CLUSTER_MAX_NODES + if (ReconfigShmem == NULL || ack == NULL || settled_reserve == NULL || settled_ballot == NULL + || durable_prepare == NULL || out_ack_node_id == NULL || cluster_node_id < 0 + || cluster_node_id >= CLUSTER_MAX_NODES || local_receiver_node_id != cluster_node_id + || authenticated_source_node_id < 0 || authenticated_source_node_id >= CLUSTER_MAX_NODES || authenticated_source_node_id == local_receiver_node_id || ack->phase != CLUSTER_REPLACEMENT_WIRE_PHASE_PURGE_ACK - || ack->grammar_fingerprint - != CLUSTER_REPLACEMENT_EPISODE_GRAMMAR_FINGERPRINT - || !cluster_epoch_authority_value_is_valid( - settled_reserve, CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT) + || ack->grammar_fingerprint != CLUSTER_REPLACEMENT_EPISODE_GRAMMAR_FINGERPRINT + || !cluster_epoch_authority_value_is_valid(settled_reserve, + CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT) || settled_reserve->transition != CLUSTER_EPOCH_AUTHORITY_RESERVE - || settled_reserve->event_kind - != CLUSTER_EPOCH_EVENT_SAME_NODE_REPLACEMENT + || settled_reserve->event_kind != CLUSTER_EPOCH_EVENT_SAME_NODE_REPLACEMENT || !cluster_epoch_ballot_id_is_valid(settled_ballot) || settled_ballot->proposer_node_id != local_receiver_node_id - || !cluster_replacement_marker_v3_encode( - durable_prepare, prepare_image) - || durable_prepare->phase - != CLUSTER_JCMK_REPLACEMENT_PHASE_PREPARE + || !cluster_replacement_marker_v3_encode(durable_prepare, prepare_image) + || durable_prepare->phase != CLUSTER_JCMK_REPLACEMENT_PHASE_PREPARE || durable_prepare->ready_state_generation != 0) return false; - if (!cluster_reconfig_replacement_candidate2_capabilities_current( - &capability_episode)) + if (!cluster_reconfig_replacement_candidate2_capabilities_current(&capability_episode)) return false; LWLockAcquire(&ReconfigShmem->lock, LW_SHARED); episode = &ReconfigShmem->replacement_episode; - if (episode->target_node_id >= 0 - && episode->target_node_id < CLUSTER_MAX_NODES) - subject[episode->target_node_id / 8] - = (uint8)(1u << (episode->target_node_id % 8)); + if (episode->target_node_id >= 0 && episode->target_node_id < CLUSTER_MAX_NODES) + subject[episode->target_node_id / 8] = (uint8)(1u << (episode->target_node_id % 8)); if (memcmp(episode, &capability_episode, sizeof(*episode)) != 0 || !cluster_replacement_episode_is_valid(episode) || (episode->phase != CLUSTER_REPLACEMENT_EPISODE_PURGING && episode->phase != CLUSTER_REPLACEMENT_EPISODE_PURGE_COMPLETE) - || episode->readiness_flags != 0 - || episode->coordinator_node_id != local_receiver_node_id - || !dead_bitmap_test_bit(episode->expected_survivors, - authenticated_source_node_id) - || !dead_bitmap_test_bit(episode->expected_survivors, - local_receiver_node_id) + || episode->readiness_flags != 0 || episode->coordinator_node_id != local_receiver_node_id + || !dead_bitmap_test_bit(episode->expected_survivors, authenticated_source_node_id) + || !dead_bitmap_test_bit(episode->expected_survivors, local_receiver_node_id) || !cluster_reconfig_replacement_membership_current_locked(episode) || cluster_epoch_get_current() != episode->baseline_epoch - || cluster_membership_get_last_admitted_incarnation( - local_receiver_node_id) + || cluster_membership_get_last_admitted_incarnation(local_receiver_node_id) != settled_ballot->proposer_admitted_incarnation - || cluster_membership_get_last_admitted_incarnation( - episode->target_node_id) + || cluster_membership_get_last_admitted_incarnation(episode->target_node_id) != episode->old_admitted_incarnation - || ack->target_node_id != episode->target_node_id - || ack->epoch != episode->baseline_epoch + || ack->target_node_id != episode->target_node_id || ack->epoch != episode->baseline_epoch || ack->request_nonce != episode->request_nonce || ack->identity0 != episode->old_admitted_incarnation || ack->identity1 != episode->fresh_incarnation - || memcmp(ack->body.bitmap, episode->expected_survivors, - sizeof(ack->body.bitmap)) != 0 + || memcmp(ack->body.bitmap, episode->expected_survivors, sizeof(ack->body.bitmap)) != 0 || ack->grammar_fingerprint != episode->grammar_fingerprint || settled_reserve->request_origin_node != episode->target_node_id || settled_reserve->target_node_id != episode->target_node_id || settled_reserve->baseline_epoch != episode->baseline_epoch - || settled_reserve->reserved_epoch - != episode->reserved_or_committed_epoch - || settled_reserve->old_incarnation - != episode->old_admitted_incarnation + || settled_reserve->reserved_epoch != episode->reserved_or_committed_epoch + || settled_reserve->old_incarnation != episode->old_admitted_incarnation || settled_reserve->fresh_incarnation != episode->fresh_incarnation || settled_reserve->request_nonce != episode->request_nonce - || memcmp(settled_reserve->authority_member_bitmap, - episode->expected_survivors, - sizeof(settled_reserve->authority_member_bitmap)) != 0 - || memcmp(settled_reserve->event_subject_bitmap, subject, - sizeof(subject)) != 0 - || settled_reserve->grammar_fingerprint - != episode->grammar_fingerprint + || memcmp(settled_reserve->authority_member_bitmap, episode->expected_survivors, + sizeof(settled_reserve->authority_member_bitmap)) + != 0 + || memcmp(settled_reserve->event_subject_bitmap, subject, sizeof(subject)) != 0 + || settled_reserve->grammar_fingerprint != episode->grammar_fingerprint || durable_prepare->target_node_id != episode->target_node_id - || durable_prepare->old_admitted_incarnation - != episode->old_admitted_incarnation + || durable_prepare->old_admitted_incarnation != episode->old_admitted_incarnation || durable_prepare->fresh_incarnation != episode->fresh_incarnation || durable_prepare->baseline_epoch != episode->baseline_epoch - || durable_prepare->reserved_or_committed_epoch - != episode->reserved_or_committed_epoch + || durable_prepare->reserved_or_committed_epoch != episode->reserved_or_committed_epoch || durable_prepare->request_nonce != episode->request_nonce - || memcmp(durable_prepare->expected_purge_survivors, - episode->expected_survivors, - sizeof(durable_prepare->expected_purge_survivors)) != 0 - || durable_prepare->grammar_fingerprint - != episode->grammar_fingerprint) + || memcmp(durable_prepare->expected_purge_survivors, episode->expected_survivors, + sizeof(durable_prepare->expected_purge_survivors)) + != 0 + || durable_prepare->grammar_fingerprint != episode->grammar_fingerprint) goto out; authorized = true; @@ -1596,32 +1487,27 @@ bool cluster_reconfig_replacement_purge_ack_ingress_authorized( const ClusterICEnvelope *env, const void *payload, uint32 payload_length, int32 authenticated_source_node_id, int32 local_receiver_node_id, - const ClusterEpochAuthorityValue *settled_reserve, - const ClusterEpochBallotId *settled_ballot, - const ClusterReplacementCommitMarkerV3 *durable_prepare, - int32 *out_ack_node_id) + const ClusterEpochAuthorityValue *settled_reserve, const ClusterEpochBallotId *settled_ballot, + const ClusterReplacementCommitMarkerV3 *durable_prepare, int32 *out_ack_node_id) { ClusterReplacementWireMessage ack; if (env == NULL || payload == NULL || out_ack_node_id == NULL || payload_length != CLUSTER_REPLACEMENT_WIRE_BYTES || env->msg_type != PGRAC_IC_MSG_GES_REQUEST - || env->payload_length != CLUSTER_REPLACEMENT_WIRE_BYTES - || authenticated_source_node_id < 0 - || authenticated_source_node_id >= CLUSTER_MAX_NODES - || local_receiver_node_id < 0 + || env->payload_length != CLUSTER_REPLACEMENT_WIRE_BYTES || authenticated_source_node_id < 0 + || authenticated_source_node_id >= CLUSTER_MAX_NODES || local_receiver_node_id < 0 || local_receiver_node_id >= CLUSTER_MAX_NODES || authenticated_source_node_id == local_receiver_node_id || env->source_node_id != (uint32)authenticated_source_node_id || env->dest_node_id != (uint32)local_receiver_node_id || env->epoch != cluster_epoch_get_current() - || !cluster_replacement_wire_decode( - (const uint8 *)payload, &ack) + || !cluster_replacement_wire_decode((const uint8 *)payload, &ack) || ack.epoch != env->epoch) return false; return cluster_reconfig_replacement_purge_ack_authorized( - &ack, authenticated_source_node_id, local_receiver_node_id, - settled_reserve, settled_ballot, durable_prepare, out_ack_node_id); + &ack, authenticated_source_node_id, local_receiver_node_id, settled_reserve, settled_ballot, + durable_prepare, out_ack_node_id); } @@ -1659,8 +1545,7 @@ cluster_reconfig_fast_rejoin_actions_snapshot(void) { bool active; - if (ReconfigShmem == NULL || cluster_online_join - || !cluster_controlfile_shared_authority) + if (ReconfigShmem == NULL || cluster_online_join || !cluster_controlfile_shared_authority) return false; LWLockAcquire(&ReconfigShmem->lock, LW_SHARED); active = !dead_bitmap_is_zero(ReconfigShmem->fast_rejoin_bitmap); @@ -1819,8 +1704,7 @@ cluster_reconfig_compute_join_bitmap(uint8 join_bitmap[CLUSTER_RECONFIG_DEAD_BIT * JOIN_PENDING here would advance the epoch and destroy the proof the * next bootstrap tick needs. Keep the existing exact founding proof * as the only ABSENT admission owner at INITIAL. */ - if (ms == CLUSTER_MEMBER_ABSENT - && cluster_epoch_get_current() == CLUSTER_EPOCH_INITIAL) + if (ms == CLUSTER_MEMBER_ABSENT && cluster_epoch_get_current() == CLUSTER_EPOCH_INITIAL) continue; if (cluster_cssd_get_peer_state(i) != CLUSTER_CSSD_PEER_ALIVE) @@ -1905,12 +1789,10 @@ cluster_reconfig_get_observed_committed_join(int32 node_id, uint64 *incarnation, /* Exact torn-free sample: incarnation is the publish gate; read it * before and after the epoch and retry on any concurrent publish. */ do { - inc = pg_atomic_read_u64( - &ReconfigShmem->observed_committed_join_incarnation[node_id]); - ep = pg_atomic_read_u64( - &ReconfigShmem->observed_committed_join_epoch[node_id]); - inc_after = pg_atomic_read_u64( - &ReconfigShmem->observed_committed_join_incarnation[node_id]); + inc = pg_atomic_read_u64(&ReconfigShmem->observed_committed_join_incarnation[node_id]); + ep = pg_atomic_read_u64(&ReconfigShmem->observed_committed_join_epoch[node_id]); + inc_after + = pg_atomic_read_u64(&ReconfigShmem->observed_committed_join_incarnation[node_id]); } while (inc != inc_after); if (incarnation != NULL) *incarnation = inc; @@ -1944,14 +1826,10 @@ cluster_reconfig_get_observed_slot(int32 node_id, uint64 *incarnation, uint64 *g /* RF-ROOT P6: generation is the publish gate (written last by the * producer); re-checking it before/after the data reads yields one * exact torn-free sample. */ - do - { - generation_before = pg_atomic_read_u64( - &ReconfigShmem->observed_generation[node_id]); - inc = pg_atomic_read_u64( - &ReconfigShmem->observed_incarnation[node_id]); - generation_after = pg_atomic_read_u64( - &ReconfigShmem->observed_generation[node_id]); + do { + generation_before = pg_atomic_read_u64(&ReconfigShmem->observed_generation[node_id]); + inc = pg_atomic_read_u64(&ReconfigShmem->observed_incarnation[node_id]); + generation_after = pg_atomic_read_u64(&ReconfigShmem->observed_generation[node_id]); } while (generation_before != generation_after); if (incarnation != NULL) @@ -1965,8 +1843,8 @@ cluster_reconfig_get_observed_slot(int32 node_id, uint64 *incarnation, uint64 *g * generation is a torn-write counter only and must never be substituted with * an incarnation, membership epoch or failure generation. */ bool -cluster_reconfig_get_observed_slot_coherent( - int32 node_id, uint64 *out_incarnation, uint64 *out_generation) +cluster_reconfig_get_observed_slot_coherent(int32 node_id, uint64 *out_incarnation, + uint64 *out_generation) { uint64 generation_before; uint64 generation_after; @@ -1976,19 +1854,14 @@ cluster_reconfig_get_observed_slot_coherent( *out_incarnation = 0; if (out_generation != NULL) *out_generation = 0; - if (ReconfigShmem == NULL || node_id < 0 || - node_id >= CLUSTER_MAX_NODES || out_incarnation == NULL || - out_generation == NULL) + if (ReconfigShmem == NULL || node_id < 0 || node_id >= CLUSTER_MAX_NODES + || out_incarnation == NULL || out_generation == NULL) return false; - do - { - generation_before = pg_atomic_read_u64( - &ReconfigShmem->observed_generation[node_id]); - incarnation = pg_atomic_read_u64( - &ReconfigShmem->observed_incarnation[node_id]); - generation_after = pg_atomic_read_u64( - &ReconfigShmem->observed_generation[node_id]); + do { + generation_before = pg_atomic_read_u64(&ReconfigShmem->observed_generation[node_id]); + incarnation = pg_atomic_read_u64(&ReconfigShmem->observed_incarnation[node_id]); + generation_after = pg_atomic_read_u64(&ReconfigShmem->observed_generation[node_id]); } while (generation_before != generation_after); if (generation_after == 0) @@ -1999,26 +1872,23 @@ cluster_reconfig_get_observed_slot_coherent( } static bool -rejoin_bitmap_shape_valid( - const uint8 dead_bitmap[CLUSTER_RECONFIG_DEAD_BITMAP_BYTES], - const uint8 survivor_bitmap[CLUSTER_RECONFIG_DEAD_BITMAP_BYTES], - int32 old_node_id) +rejoin_bitmap_shape_valid(const uint8 dead_bitmap[CLUSTER_RECONFIG_DEAD_BITMAP_BYTES], + const uint8 survivor_bitmap[CLUSTER_RECONFIG_DEAD_BITMAP_BYTES], + int32 old_node_id) { int survivor_count = 0; int i; - if (old_node_id < 0 || old_node_id >= CLUSTER_MAX_NODES || - !dead_bitmap_test_bit(dead_bitmap, old_node_id) || - dead_bitmap_test_bit(survivor_bitmap, old_node_id)) + if (old_node_id < 0 || old_node_id >= CLUSTER_MAX_NODES + || !dead_bitmap_test_bit(dead_bitmap, old_node_id) + || dead_bitmap_test_bit(survivor_bitmap, old_node_id)) return false; - for (i = 0; i < CLUSTER_RECONFIG_DEAD_BITMAP_BYTES; i++) - { + for (i = 0; i < CLUSTER_RECONFIG_DEAD_BITMAP_BYTES; i++) { uint8 survivors = survivor_bitmap[i]; if ((dead_bitmap[i] & survivors) != 0) return false; - while (survivors != 0) - { + while (survivors != 0) { survivor_count += survivors & 1; survivors >>= 1; } @@ -2027,23 +1897,19 @@ rejoin_bitmap_shape_valid( } static bool -rejoin_failure_value_valid( - const ClusterReconfigRejoinFailureSnapshotV1 *failure) +rejoin_failure_value_valid(const ClusterReconfigRejoinFailureSnapshotV1 *failure) { - return failure != NULL && - failure->reconfig_kind == RECONFIG_KIND_FAIL_STOP && - failure->reserved0 == 0 && failure->reserved68 == 0 && - failure->event_id != 0 && failure->new_epoch != 0 && - failure->cssd_dead_generation != 0 && - failure->old_incarnation != 0 && - rejoin_bitmap_shape_valid(failure->dead_bitmap, - failure->survivor_bitmap, failure->old_node_id); + return failure != NULL && failure->reconfig_kind == RECONFIG_KIND_FAIL_STOP + && failure->reserved0 == 0 && failure->reserved68 == 0 && failure->event_id != 0 + && failure->new_epoch != 0 && failure->cssd_dead_generation != 0 + && failure->old_incarnation != 0 + && rejoin_bitmap_shape_valid(failure->dead_bitmap, failure->survivor_bitmap, + failure->old_node_id); } bool -cluster_reconfig_rejoin_failure_snapshot( - int32 old_node_id, uint64 old_incarnation, - ClusterReconfigRejoinFailureSnapshotV1 *out_failure) +cluster_reconfig_rejoin_failure_snapshot(int32 old_node_id, uint64 old_incarnation, + ClusterReconfigRejoinFailureSnapshotV1 *out_failure) { ClusterReconfigRejoinFailureSnapshotV1 failure; const ReconfigEvent *event; @@ -2052,40 +1918,34 @@ cluster_reconfig_rejoin_failure_snapshot( if (out_failure != NULL) memset(out_failure, 0, sizeof(*out_failure)); - if (out_failure == NULL || ReconfigShmem == NULL || old_node_id < 0 || - old_node_id >= CLUSTER_MAX_NODES || old_incarnation == 0) + if (out_failure == NULL || ReconfigShmem == NULL || old_node_id < 0 + || old_node_id >= CLUSTER_MAX_NODES || old_incarnation == 0) return false; memset(&failure, 0, sizeof(failure)); LWLockAcquire(&ReconfigShmem->lock, LW_SHARED); event = &ReconfigShmem->last_applied; - if (event->reconfig_kind != RECONFIG_KIND_FAIL_STOP || - event->event_id == 0 || event->new_epoch == 0 || - event->cssd_dead_generation == 0 || - !dead_bitmap_test_bit(event->dead_bitmap, old_node_id) || - ReconfigShmem->membership.last_admitted_incarnation[old_node_id] - != old_incarnation) + if (event->reconfig_kind != RECONFIG_KIND_FAIL_STOP || event->event_id == 0 + || event->new_epoch == 0 || event->cssd_dead_generation == 0 + || !dead_bitmap_test_bit(event->dead_bitmap, old_node_id) + || ReconfigShmem->membership.last_admitted_incarnation[old_node_id] != old_incarnation) goto fail; failure.reconfig_kind = RECONFIG_KIND_FAIL_STOP; failure.event_id = event->event_id; failure.new_epoch = event->new_epoch; failure.cssd_dead_generation = event->cssd_dead_generation; - memcpy(failure.dead_bitmap, event->dead_bitmap, - sizeof(failure.dead_bitmap)); - for (i = 0; i < CLUSTER_MAX_NODES; i++) - { - if (ReconfigShmem->membership.membership_state[i] == - (uint8) CLUSTER_MEMBER_MEMBER) - { + memcpy(failure.dead_bitmap, event->dead_bitmap, sizeof(failure.dead_bitmap)); + for (i = 0; i < CLUSTER_MAX_NODES; i++) { + if (ReconfigShmem->membership.membership_state[i] == (uint8)CLUSTER_MEMBER_MEMBER) { dead_bitmap_set_bit(failure.survivor_bitmap, i); survivor_count++; } } failure.old_node_id = old_node_id; failure.old_incarnation = old_incarnation; - if (survivor_count < 1 || survivor_count >= CLUSTER_MAX_NODES || - !rejoin_failure_value_valid(&failure)) + if (survivor_count < 1 || survivor_count >= CLUSTER_MAX_NODES + || !rejoin_failure_value_valid(&failure)) goto fail; LWLockRelease(&ReconfigShmem->lock); *out_failure = failure; @@ -2097,17 +1957,15 @@ cluster_reconfig_rejoin_failure_snapshot( } static bool -rejoin_bitmap_is_exact_singleton( - const uint8 bitmap[CLUSTER_RECONFIG_DEAD_BITMAP_BYTES], int32 node_id) +rejoin_bitmap_is_exact_singleton(const uint8 bitmap[CLUSTER_RECONFIG_DEAD_BITMAP_BYTES], + int32 node_id) { int i; if (node_id < 0 || node_id >= CLUSTER_MAX_NODES) return false; - for (i = 0; i < CLUSTER_RECONFIG_DEAD_BITMAP_BYTES; i++) - { - uint8 expected = (i == node_id / 8) - ? (uint8)(UINT8_C(1) << (node_id % 8)) : 0; + for (i = 0; i < CLUSTER_RECONFIG_DEAD_BITMAP_BYTES; i++) { + uint8 expected = (i == node_id / 8) ? (uint8)(UINT8_C(1) << (node_id % 8)) : 0; if (bitmap[i] != expected) return false; @@ -2142,12 +2000,10 @@ cluster_reconfig_fast_rejoin_control_arm(const ReconfigEvent *event) cluster_reconfig_fast_rejoin_control_clear(); return; } - if (event == NULL || ReconfigShmem == NULL || MyBackendType != B_LMON - || cluster_online_join - || !cluster_controlfile_shared_authority - || event->reconfig_kind != RECONFIG_KIND_FAIL_STOP - || event->observer_role != CLUSTER_RECONFIG_OBSERVER_COORDINATOR - || event->event_id == 0 || event->new_epoch == 0) + if (event == NULL || ReconfigShmem == NULL || MyBackendType != B_LMON || cluster_online_join + || !cluster_controlfile_shared_authority || event->reconfig_kind != RECONFIG_KIND_FAIL_STOP + || event->observer_role != CLUSTER_RECONFIG_OBSERVER_COORDINATOR || event->event_id == 0 + || event->new_epoch == 0) return; LWLockAcquire(&ReconfigShmem->lock, LW_SHARED); @@ -2162,15 +2018,14 @@ cluster_reconfig_fast_rejoin_control_arm(const ReconfigEvent *event) target = i; prior_incarnation = ReconfigShmem->fast_rejoin_incarnation[i]; } - if (target < 0 - || cluster_membership_get_state(target) != CLUSTER_MEMBER_DEAD) { + if (target < 0 || cluster_membership_get_state(target) != CLUSTER_MEMBER_DEAD) { LWLockRelease(&ReconfigShmem->lock); return; } LWLockRelease(&ReconfigShmem->lock); - if (!cluster_reconfig_get_observed_slot_coherent( - target, &target_incarnation, &target_generation) + if (!cluster_reconfig_get_observed_slot_coherent(target, &target_incarnation, + &target_generation) || target_generation == 0 || target_incarnation <= prior_incarnation || !cluster_reconfig_get_observed_fresh_alive(target)) return; @@ -2208,14 +2063,12 @@ cluster_reconfig_fast_rejoin_control_snapshot(uint64 *target_incarnation_out) if (!fast_rejoin_control.active) return -1; target = fast_rejoin_control.target_node_id; - if (ReconfigShmem == NULL || target < 0 || target >= CLUSTER_MAX_NODES - || cluster_online_join || !cluster_controlfile_shared_authority - || cluster_qvotec_get_self_incarnation() - != fast_rejoin_control.boot_incarnation - || cluster_lms_get_lms_restart_generation() - != fast_rejoin_control.lms_generation - || !cluster_reconfig_get_observed_slot_coherent( - target, &observed_incarnation, &observed_generation) + if (ReconfigShmem == NULL || target < 0 || target >= CLUSTER_MAX_NODES || cluster_online_join + || !cluster_controlfile_shared_authority + || cluster_qvotec_get_self_incarnation() != fast_rejoin_control.boot_incarnation + || cluster_lms_get_lms_restart_generation() != fast_rejoin_control.lms_generation + || !cluster_reconfig_get_observed_slot_coherent(target, &observed_incarnation, + &observed_generation) || observed_generation == 0 || observed_incarnation != fast_rejoin_control.target_incarnation || !cluster_reconfig_get_observed_fresh_alive(target)) @@ -2223,10 +2076,8 @@ cluster_reconfig_fast_rejoin_control_snapshot(uint64 *target_incarnation_out) LWLockAcquire(&ReconfigShmem->lock, LW_SHARED); event = ReconfigShmem->last_applied; - fast_bit = dead_bitmap_test_bit(ReconfigShmem->fast_rejoin_bitmap, - target); - pending_bit = dead_bitmap_test_bit(ReconfigShmem->pending_join_bitmap, - target); + fast_bit = dead_bitmap_test_bit(ReconfigShmem->fast_rejoin_bitmap, target); + pending_bit = dead_bitmap_test_bit(ReconfigShmem->pending_join_bitmap, target); membership_state = cluster_membership_get_state(target); LWLockRelease(&ReconfigShmem->lock); if (!fast_bit || membership_state == CLUSTER_MEMBER_REMOVED) @@ -2239,14 +2090,11 @@ cluster_reconfig_fast_rejoin_control_snapshot(uint64 *target_incarnation_out) goto invalid; if (pending_bit) { if (!join_prepare_stage.async.has_staged_event - || !rejoin_bitmap_is_exact_singleton( - join_prepare_stage.join_bitmap, target) + || !rejoin_bitmap_is_exact_singleton(join_prepare_stage.join_bitmap, target) || join_prepare_stage.joiner_incarnations[target] != fast_rejoin_control.target_incarnation - || join_prepare_stage.event.old_epoch - != fast_rejoin_control.failstop_epoch - || join_prepare_stage.event.new_epoch - != fast_rejoin_control.failstop_epoch + 1) + || join_prepare_stage.event.old_epoch != fast_rejoin_control.failstop_epoch + || join_prepare_stage.event.new_epoch != fast_rejoin_control.failstop_epoch + 1) goto invalid; } else if (membership_state != CLUSTER_MEMBER_DEAD) goto invalid; @@ -2270,20 +2118,17 @@ cluster_reconfig_fast_rejoin_control_snapshot(uint64 *target_incarnation_out) static void -cluster_reconfig_fast_rejoin_control_finish(int32 node_id, - uint64 admitted_incarnation) +cluster_reconfig_fast_rejoin_control_finish(int32 node_id, uint64 admitted_incarnation) { - if (fast_rejoin_control.active - && fast_rejoin_control.target_node_id == node_id + if (fast_rejoin_control.active && fast_rejoin_control.target_node_id == node_id && fast_rejoin_control.target_incarnation == admitted_incarnation) cluster_reconfig_fast_rejoin_control_clear(); } bool -cluster_reconfig_rejoin_pending_snapshot( - const ClusterReconfigRejoinFailureSnapshotV1 *failure, - uint64 candidate_incarnation, - ClusterReconfigRejoinPendingSnapshotV1 *out_pending) +cluster_reconfig_rejoin_pending_snapshot(const ClusterReconfigRejoinFailureSnapshotV1 *failure, + uint64 candidate_incarnation, + ClusterReconfigRejoinPendingSnapshotV1 *out_pending) { ClusterReconfigRejoinPendingSnapshotV1 pending; uint64 incarnations[CLUSTER_MAX_NODES]; @@ -2295,14 +2140,13 @@ cluster_reconfig_rejoin_pending_snapshot( if (out_pending != NULL) memset(out_pending, 0, sizeof(*out_pending)); - if (out_pending == NULL || ReconfigShmem == NULL || - !rejoin_failure_value_valid(failure) || - candidate_incarnation <= failure->old_incarnation) + if (out_pending == NULL || ReconfigShmem == NULL || !rejoin_failure_value_valid(failure) + || candidate_incarnation <= failure->old_incarnation) return false; node_id = failure->old_node_id; - if (!cluster_reconfig_get_observed_slot_coherent(node_id, - &observed_incarnation, &observed_generation) || - observed_incarnation != candidate_incarnation) + if (!cluster_reconfig_get_observed_slot_coherent(node_id, &observed_incarnation, + &observed_generation) + || observed_incarnation != candidate_incarnation) return false; memset(&pending, 0, sizeof(pending)); @@ -2310,28 +2154,22 @@ cluster_reconfig_rejoin_pending_snapshot( incarnations[node_id] = candidate_incarnation; LWLockAcquire(&ReconfigShmem->lock, LW_SHARED); event = &ReconfigShmem->last_applied; - if (event->reconfig_kind != RECONFIG_KIND_JOIN_PENDING || - event->event_id == 0 || event->old_epoch != failure->new_epoch || - failure->new_epoch == UINT64_MAX || - event->new_epoch != event->old_epoch + 1 || - event->cssd_dead_generation == 0 || - ReconfigShmem->membership.membership_state[node_id] != - (uint8) CLUSTER_MEMBER_JOINING || - ReconfigShmem->membership.last_admitted_incarnation[node_id] != - failure->old_incarnation || - !rejoin_bitmap_is_exact_singleton(event->join_bitmap, node_id) || - !rejoin_bitmap_is_exact_singleton( - ReconfigShmem->pending_join_bitmap, node_id)) + if (event->reconfig_kind != RECONFIG_KIND_JOIN_PENDING || event->event_id == 0 + || event->old_epoch != failure->new_epoch || failure->new_epoch == UINT64_MAX + || event->new_epoch != event->old_epoch + 1 || event->cssd_dead_generation == 0 + || ReconfigShmem->membership.membership_state[node_id] != (uint8)CLUSTER_MEMBER_JOINING + || ReconfigShmem->membership.last_admitted_incarnation[node_id] != failure->old_incarnation + || !rejoin_bitmap_is_exact_singleton(event->join_bitmap, node_id) + || !rejoin_bitmap_is_exact_singleton(ReconfigShmem->pending_join_bitmap, node_id)) goto pending_fail; - for (i = 0; i < CLUSTER_RECONFIG_DEAD_BITMAP_BYTES; i++) - { + for (i = 0; i < CLUSTER_RECONFIG_DEAD_BITMAP_BYTES; i++) { if (event->dead_bitmap[i] != 0) goto pending_fail; } - if (event->event_id != cluster_reconfig_compute_event_id_v2( - RECONFIG_KIND_JOIN_PENDING, event->dead_bitmap, - event->join_bitmap, incarnations, - event->cssd_dead_generation)) + if (event->event_id + != cluster_reconfig_compute_event_id_v2(RECONFIG_KIND_JOIN_PENDING, event->dead_bitmap, + event->join_bitmap, incarnations, + event->cssd_dead_generation)) goto pending_fail; pending.reconfig_kind = RECONFIG_KIND_JOIN_PENDING; @@ -2339,10 +2177,8 @@ cluster_reconfig_rejoin_pending_snapshot( pending.old_epoch = event->old_epoch; pending.new_epoch = event->new_epoch; pending.cssd_dead_generation = event->cssd_dead_generation; - memcpy(pending.dead_bitmap, event->dead_bitmap, - sizeof(pending.dead_bitmap)); - memcpy(pending.join_bitmap, event->join_bitmap, - sizeof(pending.join_bitmap)); + memcpy(pending.dead_bitmap, event->dead_bitmap, sizeof(pending.dead_bitmap)); + memcpy(pending.join_bitmap, event->join_bitmap, sizeof(pending.join_bitmap)); pending.node_id = node_id; pending.candidate_incarnation = candidate_incarnation; pending.observed_slot_generation = observed_generation; @@ -2402,8 +2238,7 @@ void cluster_reconfig_bootstrap_publish_in_quorum(bool in_quorum) { if (ReconfigShmem != NULL) - pg_atomic_write_u64(&ReconfigShmem->bootstrap_in_quorum, - in_quorum ? 1 : 0); + pg_atomic_write_u64(&ReconfigShmem->bootstrap_in_quorum, in_quorum ? 1 : 0); } void @@ -2439,36 +2274,33 @@ cluster_reconfig_bootstrap_proof_node(int32 node_id, uint64 *out_incarnation) /* cold-formation ruling: bounded retries only — this runs under the reconfig * EXCLUSIVE lock, so an odd/CHANGED seqlock window must return false * (retry next tick), never spin forever. */ - int attempt; + int attempt; for (attempt = 0; attempt < 8; attempt++) { - uint64 seq_before; - uint64 seq_after; - uint64 target_inc = 0; - bool in_quorum; - bool target_ok = false; - bool running_cluster = false; - uint32 declared = 0; - uint32 proven = 0; - int i; - - if (ReconfigShmem == NULL || node_id < 0 - || node_id >= CLUSTER_MAX_NODES) + uint64 seq_before; + uint64 seq_after; + uint64 target_inc = 0; + bool in_quorum; + bool target_ok = false; + bool running_cluster = false; + uint32 declared = 0; + uint32 proven = 0; + int i; + + if (ReconfigShmem == NULL || node_id < 0 || node_id >= CLUSTER_MAX_NODES) return false; if (out_incarnation != NULL) *out_incarnation = 0; - seq_before = pg_atomic_read_u64( - &ReconfigShmem->observed_bootstrap_seq); + seq_before = pg_atomic_read_u64(&ReconfigShmem->observed_bootstrap_seq); if ((seq_before & UINT64_C(1)) != 0) - continue; /* writer in progress: retry */ + continue; /* writer in progress: retry */ pg_read_barrier(); - in_quorum = pg_atomic_read_u64( - &ReconfigShmem->bootstrap_in_quorum) != 0; + in_quorum = pg_atomic_read_u64(&ReconfigShmem->bootstrap_in_quorum) != 0; for (i = 0; i < CLUSTER_MAX_NODES; i++) { - uint64 inc; - uint64 gen; - uint64 ep; - bool fresh; + uint64 inc; + uint64 gen; + uint64 ep; + bool fresh; if (cluster_conf_lookup_node(i) == NULL) continue; @@ -2478,20 +2310,16 @@ cluster_reconfig_bootstrap_proof_node(int32 node_id, uint64 *out_incarnation) proven++; continue; } - inc = pg_atomic_read_u64( - &ReconfigShmem->observed_incarnation[i]); - gen = pg_atomic_read_u64( - &ReconfigShmem->observed_generation[i]); + inc = pg_atomic_read_u64(&ReconfigShmem->observed_incarnation[i]); + gen = pg_atomic_read_u64(&ReconfigShmem->observed_generation[i]); ep = pg_atomic_read_u64(&ReconfigShmem->observed_epoch[i]); - fresh = pg_atomic_read_u64( - &ReconfigShmem->observed_fresh_alive[i]) != 0; + fresh = pg_atomic_read_u64(&ReconfigShmem->observed_fresh_alive[i]) != 0; /* any declared peer past INITIAL => a running cluster, NOT a * founding bootstrap (same rule as * cluster_reconfig_bootstrap_quorum_at_initial) */ if (ep > CLUSTER_EPOCH_INITIAL) running_cluster = true; - if (i == node_id && fresh && gen > 0 && inc != 0 - && ep == CLUSTER_EPOCH_INITIAL) { + if (i == node_id && fresh && gen > 0 && inc != 0 && ep == CLUSTER_EPOCH_INITIAL) { target_inc = inc; target_ok = true; } @@ -2499,17 +2327,18 @@ cluster_reconfig_bootstrap_proof_node(int32 node_id, uint64 *out_incarnation) proven++; } pg_read_barrier(); - seq_after = pg_atomic_read_u64( - &ReconfigShmem->observed_bootstrap_seq); + seq_after = pg_atomic_read_u64(&ReconfigShmem->observed_bootstrap_seq); if (seq_after != seq_before) - continue; /* writer crossed: retry */ + continue; /* writer crossed: retry */ if (declared == 0 || running_cluster || !in_quorum || !target_ok || proven < (declared / 2u) + 1u) - return false; /* fail-closed on the stable snapshot */ + return false; /* fail-closed on the stable snapshot */ if (out_incarnation != NULL) *out_incarnation = target_inc; return true; } + /* No stable publication was observed; retry on a later membership tick. */ + return false; } @@ -2889,26 +2718,23 @@ cluster_reconfig_join_converged(int joiner) } bool -cluster_reconfig_rejoin_pending_ready( - const ClusterReconfigRejoinPendingSnapshotV1 *pending) +cluster_reconfig_rejoin_pending_ready(const ClusterReconfigRejoinPendingSnapshotV1 *pending) { uint64 observed_incarnation; uint64 observed_generation; - if (pending == NULL || pending->reconfig_kind != - RECONFIG_KIND_JOIN_PENDING || pending->reserved0 != 0 || - pending->node_id < 0 || pending->node_id >= CLUSTER_MAX_NODES || - pending->candidate_incarnation == 0 || - pending->observed_slot_generation == 0 || - !cluster_reconfig_get_observed_slot_coherent(pending->node_id, - &observed_incarnation, &observed_generation) || - observed_incarnation != pending->candidate_incarnation || - observed_generation != pending->observed_slot_generation || - !cluster_reconfig_join_converged(pending->node_id)) + if (pending == NULL || pending->reconfig_kind != RECONFIG_KIND_JOIN_PENDING + || pending->reserved0 != 0 || pending->node_id < 0 || pending->node_id >= CLUSTER_MAX_NODES + || pending->candidate_incarnation == 0 || pending->observed_slot_generation == 0 + || !cluster_reconfig_get_observed_slot_coherent(pending->node_id, &observed_incarnation, + &observed_generation) + || observed_incarnation != pending->candidate_incarnation + || observed_generation != pending->observed_slot_generation + || !cluster_reconfig_join_converged(pending->node_id)) return false; - return cluster_membership_vet_joiner(pending->node_id, - pending->candidate_incarnation, pending->observed_slot_generation) == - CLUSTER_JOIN_ACCEPT; + return cluster_membership_vet_joiner(pending->node_id, pending->candidate_incarnation, + pending->observed_slot_generation) + == CLUSTER_JOIN_ACCEPT; } static void @@ -2919,8 +2745,7 @@ cluster_reconfig_external_rejoin_release_slot(int node_id) if (node_id < 0 || node_id >= CLUSTER_MAX_NODES) return; slot = &external_rejoin_slots[node_id]; - cluster_external_fence_rejoin_authority_clear_release( - &slot->authority_clear); + cluster_external_fence_rejoin_authority_clear_release(&slot->authority_clear); cluster_external_fence_rejoin_release(&slot->op); memset(slot, 0, sizeof(*slot)); } @@ -2937,7 +2762,7 @@ cluster_reconfig_external_rejoin_release_all(void) static void cluster_reconfig_external_rejoin_on_exit(int code pg_attribute_unused(), - Datum arg pg_attribute_unused()) + Datum arg pg_attribute_unused()) { cluster_reconfig_external_rejoin_release_all(); } @@ -2954,40 +2779,35 @@ cluster_reconfig_external_rejoin_has_slot(void) } static bool -cluster_reconfig_external_rejoin_terminal( - PgracExternalFenceRejoinStatus status) +cluster_reconfig_external_rejoin_terminal(PgracExternalFenceRejoinStatus status) { - return status == PGRAC_EXTERNAL_FENCE_REJOIN_REJECTED || - status == PGRAC_EXTERNAL_FENCE_REJOIN_UNKNOWN || - status == PGRAC_EXTERNAL_FENCE_REJOIN_UNAVAILABLE || - status == PGRAC_EXTERNAL_FENCE_REJOIN_STALE || - status == PGRAC_EXTERNAL_FENCE_REJOIN_CONSUMED; + return status == PGRAC_EXTERNAL_FENCE_REJOIN_REJECTED + || status == PGRAC_EXTERNAL_FENCE_REJOIN_UNKNOWN + || status == PGRAC_EXTERNAL_FENCE_REJOIN_UNAVAILABLE + || status == PGRAC_EXTERNAL_FENCE_REJOIN_STALE + || status == PGRAC_EXTERNAL_FENCE_REJOIN_CONSUMED; } static bool cluster_reconfig_external_rejoin_required(int node_id) { - return cluster_external_fence_runtime_active() && node_id >= 0 && - node_id < CLUSTER_MAX_NODES && - cluster_membership_get_last_admitted_incarnation(node_id) > 0 && - !cluster_reconfig_is_clean_departed(node_id); + return cluster_external_fence_runtime_active() && node_id >= 0 && node_id < CLUSTER_MAX_NODES + && cluster_membership_get_last_admitted_incarnation(node_id) > 0 + && !cluster_reconfig_is_clean_departed(node_id); } static bool -cluster_reconfig_external_rejoin_authorized(int node_id, - uint64 candidate_incarnation) +cluster_reconfig_external_rejoin_authorized(int node_id, uint64 candidate_incarnation) { ClusterExternalRejoinSlot *slot; - if (!cluster_reconfig_external_rejoin_required(node_id) || - candidate_incarnation == 0) + if (!cluster_reconfig_external_rejoin_required(node_id) || candidate_incarnation == 0) return false; slot = &external_rejoin_slots[node_id]; - return slot->op != NULL && - slot->candidate_incarnation == candidate_incarnation && - slot->failure.old_node_id == node_id && - slot->phase >= CLUSTER_EXTERNAL_REJOIN_WAITING_JOINER && - slot->phase <= CLUSTER_EXTERNAL_REJOIN_COMMITTING; + return slot->op != NULL && slot->candidate_incarnation == candidate_incarnation + && slot->failure.old_node_id == node_id + && slot->phase >= CLUSTER_EXTERNAL_REJOIN_WAITING_JOINER + && slot->phase <= CLUSTER_EXTERNAL_REJOIN_COMMITTING; } /* STOP04 §11.8: coordinator-LMON drives the opaque provider object without @@ -3006,7 +2826,7 @@ cluster_reconfig_external_rejoin_tick(void) return; } if (!external_rejoin_exit_registered) { - on_shmem_exit(cluster_reconfig_external_rejoin_on_exit, (Datum) 0); + on_shmem_exit(cluster_reconfig_external_rejoin_on_exit, (Datum)0); external_rejoin_exit_registered = true; } @@ -3014,20 +2834,18 @@ cluster_reconfig_external_rejoin_tick(void) for (i = 0; i < CLUSTER_MAX_NODES; i++) { ClusterExternalRejoinSlot *slot = &external_rejoin_slots[i]; - if (slot->op == NULL || - slot->phase == CLUSTER_EXTERNAL_REJOIN_COMMITTING) + if (slot->op == NULL || slot->phase == CLUSTER_EXTERNAL_REJOIN_COMMITTING) continue; - status = cluster_external_fence_rejoin_poll_nowait(slot->op, - &reason); + status = cluster_external_fence_rejoin_poll_nowait(slot->op, &reason); if (cluster_reconfig_external_rejoin_terminal(status)) { cluster_reconfig_external_rejoin_release_slot(i); continue; } - if (slot->phase == CLUSTER_EXTERNAL_REJOIN_WAITING_ON && - status == PGRAC_EXTERNAL_FENCE_REJOIN_WAITING_JOINER) + if (slot->phase == CLUSTER_EXTERNAL_REJOIN_WAITING_ON + && status == PGRAC_EXTERNAL_FENCE_REJOIN_WAITING_JOINER) slot->phase = CLUSTER_EXTERNAL_REJOIN_WAITING_JOINER; - else if (slot->phase == CLUSTER_EXTERNAL_REJOIN_WAITING_REFRESH && - status == PGRAC_EXTERNAL_FENCE_REJOIN_READY) + else if (slot->phase == CLUSTER_EXTERNAL_REJOIN_WAITING_REFRESH + && status == PGRAC_EXTERNAL_FENCE_REJOIN_READY) slot->phase = CLUSTER_EXTERNAL_REJOIN_READY; } @@ -3035,73 +2853,60 @@ cluster_reconfig_external_rejoin_tick(void) if (external_rejoin_claim_op != NULL) { const PgracExternalFenceRejoinOfferV1 *offer; - status = cluster_external_fence_rejoin_poll_nowait( - external_rejoin_claim_op, &reason); + status = cluster_external_fence_rejoin_poll_nowait(external_rejoin_claim_op, &reason); if (status == PGRAC_EXTERNAL_FENCE_REJOIN_OFFERED) { - offer = cluster_external_fence_rejoin_offer( - external_rejoin_claim_op); - if (offer == NULL || offer->old_node_id < 0 || - offer->old_node_id >= CLUSTER_MAX_NODES || - offer->old_incarnation == 0 || - offer->candidate_incarnation == 0 || - external_rejoin_slots[offer->old_node_id].phase != - CLUSTER_EXTERNAL_REJOIN_EMPTY) - cluster_external_fence_rejoin_release( - &external_rejoin_claim_op); + offer = cluster_external_fence_rejoin_offer(external_rejoin_claim_op); + if (offer == NULL || offer->old_node_id < 0 || offer->old_node_id >= CLUSTER_MAX_NODES + || offer->old_incarnation == 0 || offer->candidate_incarnation == 0 + || external_rejoin_slots[offer->old_node_id].phase != CLUSTER_EXTERNAL_REJOIN_EMPTY) + cluster_external_fence_rejoin_release(&external_rejoin_claim_op); else { - ClusterExternalRejoinSlot *slot = - &external_rejoin_slots[offer->old_node_id]; + ClusterExternalRejoinSlot *slot = &external_rejoin_slots[offer->old_node_id]; slot->op = external_rejoin_claim_op; external_rejoin_claim_op = NULL; - slot->candidate_incarnation = - offer->candidate_incarnation; + slot->candidate_incarnation = offer->candidate_incarnation; slot->phase = CLUSTER_EXTERNAL_REJOIN_OFFERED; } } else if (cluster_reconfig_external_rejoin_terminal(status)) - cluster_external_fence_rejoin_release( - &external_rejoin_claim_op); + cluster_external_fence_rejoin_release(&external_rejoin_claim_op); } for (i = 0; i < CLUSTER_MAX_NODES; i++) { ClusterExternalRejoinPhase phase = external_rejoin_slots[i].phase; - if (phase == CLUSTER_EXTERNAL_REJOIN_OFFERED || - phase == CLUSTER_EXTERNAL_REJOIN_WAITING_ROOT || - phase == CLUSTER_EXTERNAL_REJOIN_WAITING_JOINER) { + if (phase == CLUSTER_EXTERNAL_REJOIN_OFFERED + || phase == CLUSTER_EXTERNAL_REJOIN_WAITING_ROOT + || phase == CLUSTER_EXTERNAL_REJOIN_WAITING_JOINER) { advance_node = i; break; } } if (advance_node >= 0) { - ClusterExternalRejoinSlot *slot = - &external_rejoin_slots[advance_node]; + ClusterExternalRejoinSlot *slot = &external_rejoin_slots[advance_node]; if (slot->phase == CLUSTER_EXTERNAL_REJOIN_OFFERED) { - const PgracExternalFenceRejoinOfferV1 *offer = - cluster_external_fence_rejoin_offer(slot->op); + const PgracExternalFenceRejoinOfferV1 *offer + = cluster_external_fence_rejoin_offer(slot->op); ClusterGrdRejoinClearSnapshotV1 grd_clear; memset(&slot->failure, 0, sizeof(slot->failure)); memset(&grd_clear, 0, sizeof(grd_clear)); - if (offer == NULL || - !cluster_reconfig_rejoin_failure_snapshot( - offer->old_node_id, offer->old_incarnation, - &slot->failure)) { + if (offer == NULL + || !cluster_reconfig_rejoin_failure_snapshot( + offer->old_node_id, offer->old_incarnation, &slot->failure)) { cluster_reconfig_external_rejoin_release_slot(advance_node); return; } /* G is a positive all-survivor cut. Not-yet-DONE is a retry, * not authority to discard the still-fresh OFFER or actuate ON. */ - if (!cluster_grd_rejoin_clear_snapshot(&slot->failure, - &grd_clear)) + if (!cluster_grd_rejoin_clear_snapshot(&slot->failure, &grd_clear)) return; status = cluster_external_fence_rejoin_authority_clear_build( - slot->op, &slot->failure, &grd_clear, - &slot->authority_clear, &reason); - if (status != PGRAC_EXTERNAL_FENCE_REJOIN_WAITING_ROOT || - slot->authority_clear == NULL) { + slot->op, &slot->failure, &grd_clear, &slot->authority_clear, &reason); + if (status != PGRAC_EXTERNAL_FENCE_REJOIN_WAITING_ROOT + || slot->authority_clear == NULL) { cluster_reconfig_external_rejoin_release_slot(advance_node); return; } @@ -3116,22 +2921,18 @@ cluster_reconfig_external_rejoin_tick(void) memset(&identity, 0, sizeof(identity)); memset(&snapshot, 0, sizeof(snapshot)); memset(&token, 0, sizeof(token)); - memset(protected_set_digest, 0, - sizeof(protected_set_digest)); - root_result = cluster_control_root_lookup_owner_by_node_runtime( - advance_node, &identity, &snapshot, &token); - if ((root_result != CLUSTER_CONTROL_ROOT_OK_PRIMARY && - root_result != CLUSTER_CONTROL_ROOT_OK_PRIMARY_DEGRADED) || - snapshot.lifecycle != - CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_COMPLETE || - !cluster_external_fence_rejoin_protected_set_digest( - protected_set_digest)) + memset(protected_set_digest, 0, sizeof(protected_set_digest)); + root_result = cluster_control_root_lookup_owner_by_node_runtime(advance_node, &identity, + &snapshot, &token); + if ((root_result != CLUSTER_CONTROL_ROOT_OK_PRIMARY + && root_result != CLUSTER_CONTROL_ROOT_OK_PRIMARY_DEGRADED) + || snapshot.lifecycle != CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_COMPLETE + || !cluster_external_fence_rejoin_protected_set_digest(protected_set_digest)) return; status = cluster_external_fence_rejoin_authorize_on_async( - slot->op, &slot->authority_clear, &identity, &snapshot, - &token, protected_set_digest, &reason); - if (status == PGRAC_EXTERNAL_FENCE_REJOIN_PENDING && - slot->authority_clear == NULL) + slot->op, &slot->authority_clear, &identity, &snapshot, &token, + protected_set_digest, &reason); + if (status == PGRAC_EXTERNAL_FENCE_REJOIN_PENDING && slot->authority_clear == NULL) slot->phase = CLUSTER_EXTERNAL_REJOIN_WAITING_ON; else if (status != PGRAC_EXTERNAL_FENCE_REJOIN_WAITING_ROOT) cluster_reconfig_external_rejoin_release_slot(advance_node); @@ -3140,35 +2941,29 @@ cluster_reconfig_external_rejoin_tick(void) memset(&pending, 0, sizeof(pending)); if (!cluster_reconfig_rejoin_pending_snapshot(&slot->failure, - slot->candidate_incarnation, &pending) || - !cluster_reconfig_rejoin_pending_ready(&pending)) + slot->candidate_incarnation, &pending) + || !cluster_reconfig_rejoin_pending_ready(&pending)) return; - status = cluster_external_fence_rejoin_refresh_on_async( - slot->op, &pending, &reason); + status = cluster_external_fence_rejoin_refresh_on_async(slot->op, &pending, &reason); if (status == PGRAC_EXTERNAL_FENCE_REJOIN_PENDING) { slot->commit_pending = pending; slot->phase = CLUSTER_EXTERNAL_REJOIN_WAITING_REFRESH; - } else if (status != - PGRAC_EXTERNAL_FENCE_REJOIN_WAITING_JOINER) + } else if (status != PGRAC_EXTERNAL_FENCE_REJOIN_WAITING_JOINER) cluster_reconfig_external_rejoin_release_slot(advance_node); } } /* The frozen linear chain admits only one live CLAIM/OFFER at a time. */ - if (external_rejoin_claim_op == NULL && - !cluster_reconfig_external_rejoin_has_slot()) { + if (external_rejoin_claim_op == NULL && !cluster_reconfig_external_rejoin_has_slot()) { status = cluster_external_fence_rejoin_start_async( - PGRAC_EXTERNAL_FENCE_ACQUIRE_TIMEOUT_DEFAULT_MS, - &external_rejoin_claim_op); + PGRAC_EXTERNAL_FENCE_ACQUIRE_TIMEOUT_DEFAULT_MS, &external_rejoin_claim_op); if (cluster_reconfig_external_rejoin_terminal(status)) - cluster_external_fence_rejoin_release( - &external_rejoin_claim_op); + cluster_external_fence_rejoin_release(&external_rejoin_claim_op); } } static bool -cluster_reconfig_external_rejoin_prepare_commit(int node_id, - uint64 candidate_incarnation) +cluster_reconfig_external_rejoin_prepare_commit(int node_id, uint64 candidate_incarnation) { ClusterExternalRejoinSlot *slot; ClusterReconfigRejoinPendingSnapshotV1 pending; @@ -3178,17 +2973,15 @@ cluster_reconfig_external_rejoin_prepare_commit(int node_id, if (!cluster_reconfig_external_rejoin_required(node_id)) return true; slot = &external_rejoin_slots[node_id]; - if (slot->op == NULL || slot->phase != CLUSTER_EXTERNAL_REJOIN_READY || - slot->candidate_incarnation != candidate_incarnation) + if (slot->op == NULL || slot->phase != CLUSTER_EXTERNAL_REJOIN_READY + || slot->candidate_incarnation != candidate_incarnation) return false; memset(&pending, 0, sizeof(pending)); memset(&fresh_root, 0, sizeof(fresh_root)); - if (!cluster_reconfig_rejoin_pending_snapshot(&slot->failure, - candidate_incarnation, &pending) || - !cluster_reconfig_rejoin_pending_ready(&pending) || - memcmp(&pending, &slot->commit_pending, sizeof(pending)) != 0 || - !cluster_external_fence_rejoin_revalidate_root(slot->op, - &fresh_root, &reason)) { + if (!cluster_reconfig_rejoin_pending_snapshot(&slot->failure, candidate_incarnation, &pending) + || !cluster_reconfig_rejoin_pending_ready(&pending) + || memcmp(&pending, &slot->commit_pending, sizeof(pending)) != 0 + || !cluster_external_fence_rejoin_revalidate_root(slot->op, &fresh_root, &reason)) { cluster_reconfig_external_rejoin_release_slot(node_id); return false; } @@ -3335,8 +3128,7 @@ cluster_reconfig_poll_failstop_fence_stage(void) elapsed_us); if (result == CLUSTER_FENCE_MARKER_SUBMIT_ACK) { cluster_reconfig_publish_event(&failstop_fence_stage.event); - cluster_reconfig_fast_rejoin_control_arm( - &failstop_fence_stage.event); + cluster_reconfig_fast_rejoin_control_arm(&failstop_fence_stage.event); cluster_reconfig_log_failstop_epoch_bump(&failstop_fence_stage.event); cluster_reconfig_broadcast_local_procsig(); } else { @@ -3546,8 +3338,7 @@ cluster_reconfig_release_join_commit_stage(void) cluster_marker_async_release_stage(&join_commit_stage.async); cluster_marker_async_release_stage(&join_commit_stage.fence_async); memset(&join_commit_stage.marker, 0, sizeof(join_commit_stage.marker)); - memset(&join_commit_stage.fence_marker, 0, - sizeof(join_commit_stage.fence_marker)); + memset(&join_commit_stage.fence_marker, 0, sizeof(join_commit_stage.fence_marker)); memset(&join_commit_stage.event, 0, sizeof(join_commit_stage.event)); join_commit_stage.expected_last_event_id = 0; join_commit_stage.node_id = -1; @@ -3590,10 +3381,8 @@ cluster_reconfig_prepare_join_commit(int32 node_id, uint64 admitted_incarnation, return false; } expected_last_event_id = ReconfigShmem->last_applied.event_id; - memcpy(remaining_dead, ReconfigShmem->last_applied.dead_bitmap, - sizeof(remaining_dead)); - memcpy(removed_bitmap, ReconfigShmem->removed_bitmap, - sizeof(removed_bitmap)); + memcpy(remaining_dead, ReconfigShmem->last_applied.dead_bitmap, sizeof(remaining_dead)); + memcpy(removed_bitmap, ReconfigShmem->removed_bitmap, sizeof(removed_bitmap)); LWLockRelease(&ReconfigShmem->lock); remaining_dead[node_id / 8] &= (uint8) ~(1u << (node_id % 8)); cssd_dead_generation = cluster_cssd_get_dead_generation(); @@ -3621,8 +3410,7 @@ cluster_reconfig_prepare_join_commit(int32 node_id, uint64 admitted_incarnation, memset(&evt, 0, sizeof(evt)); evt.event_id = cluster_reconfig_compute_event_id_v2( - RECONFIG_KIND_JOIN_COMMITTED, remaining_dead, jb, incs, - cssd_dead_generation); + RECONFIG_KIND_JOIN_COMMITTED, remaining_dead, jb, incs, cssd_dead_generation); evt.coordinator_node_id = cluster_node_id; evt.old_epoch = old_epoch; evt.new_epoch = new_epoch; @@ -3645,8 +3433,7 @@ cluster_reconfig_prepare_join_commit(int32 node_id, uint64 admitted_incarnation, * valid even when the admitted owner was the final excluded origin. */ fence_marker.marker_kind = CLUSTER_FENCE_MARKER_KIND_BASELINE; for (b = 0; b < CLUSTER_RECONFIG_DEAD_BITMAP_BYTES; b++) - fence_marker.fenced_dead_bitmap[b] - = remaining_dead[b] | removed_bitmap[b]; + fence_marker.fenced_dead_bitmap[b] = remaining_dead[b] | removed_bitmap[b]; join_commit_stage.event = evt; join_commit_stage.fence_marker = fence_marker; @@ -3667,37 +3454,29 @@ cluster_reconfig_publish_prepared_join_commit(void) int b; if (!join_commit_stage.fence_ready - || cluster_epoch_get_current() != join_commit_stage.event.new_epoch) - { + || cluster_epoch_get_current() != join_commit_stage.event.new_epoch) { return false; } LWLockAcquire(&ReconfigShmem->lock, LW_EXCLUSIVE); - memcpy(expected_dead, ReconfigShmem->last_applied.dead_bitmap, - sizeof(expected_dead)); + memcpy(expected_dead, ReconfigShmem->last_applied.dead_bitmap, sizeof(expected_dead)); expected_dead[join_commit_stage.node_id / 8] &= (uint8) ~(1u << (join_commit_stage.node_id % 8)); for (b = 0; b < CLUSTER_RECONFIG_DEAD_BITMAP_BYTES; b++) expected_fenced[b] = expected_dead[b] | ReconfigShmem->removed_bitmap[b]; - if (cluster_membership_get_state(join_commit_stage.node_id) - == CLUSTER_MEMBER_JOINING - && dead_bitmap_test_bit(ReconfigShmem->pending_join_bitmap, - join_commit_stage.node_id) - && ReconfigShmem->last_applied.event_id - == join_commit_stage.expected_last_event_id - && memcmp(expected_dead, join_commit_stage.event.dead_bitmap, - sizeof(expected_dead)) == 0 - && memcmp(expected_fenced, - join_commit_stage.fence_marker.fenced_dead_bitmap, - sizeof(expected_fenced)) == 0) { + if (cluster_membership_get_state(join_commit_stage.node_id) == CLUSTER_MEMBER_JOINING + && dead_bitmap_test_bit(ReconfigShmem->pending_join_bitmap, join_commit_stage.node_id) + && ReconfigShmem->last_applied.event_id == join_commit_stage.expected_last_event_id + && memcmp(expected_dead, join_commit_stage.event.dead_bitmap, sizeof(expected_dead)) == 0 + && memcmp(expected_fenced, join_commit_stage.fence_marker.fenced_dead_bitmap, + sizeof(expected_fenced)) + == 0) { /* fall through to publish */ cluster_write_fence_authority_cache_invalidate(); - cluster_membership_set_state(join_commit_stage.node_id, - CLUSTER_MEMBER_MEMBER); - cluster_membership_record_admitted( - join_commit_stage.node_id, - join_commit_stage.admitted_incarnation); + cluster_membership_set_state(join_commit_stage.node_id, CLUSTER_MEMBER_MEMBER); + cluster_membership_record_admitted(join_commit_stage.node_id, + join_commit_stage.admitted_incarnation); ReconfigShmem->fast_rejoin_incarnation[join_commit_stage.node_id] = join_commit_stage.admitted_incarnation; ReconfigShmem->fast_rejoin_bitmap[join_commit_stage.node_id / 8] @@ -3714,9 +3493,8 @@ cluster_reconfig_publish_prepared_join_commit(void) pg_atomic_fetch_add_u64(&ReconfigShmem->clean_departed_cleared_count, 1); cluster_reconfig_clear_clean_departed(join_commit_stage.node_id); cluster_reconfig_publish_event(&join_commit_stage.event); - cluster_reconfig_fast_rejoin_control_finish( - join_commit_stage.node_id, - join_commit_stage.admitted_incarnation); + cluster_reconfig_fast_rejoin_control_finish(join_commit_stage.node_id, + join_commit_stage.admitted_incarnation); pg_atomic_fetch_add_u64(&ReconfigShmem->join_apply_count, 1); return true; } @@ -3732,38 +3510,33 @@ cluster_reconfig_poll_join_fence_stage(TimestampTz now) bool fence_submit_ok; fence_submit_ok = cluster_write_fence_submit_marker_async( - &join_commit_stage.fence_async, - &join_commit_stage.fence_marker, - CLUSTER_MARKER_KIND_JOIN_COMMITTED, - join_commit_stage.node_id, now); + &join_commit_stage.fence_async, &join_commit_stage.fence_marker, + CLUSTER_MARKER_KIND_JOIN_COMMITTED, join_commit_stage.node_id, now); if (!fence_submit_ok) return true; return true; } - pr = cluster_write_fence_poll_marker_async(&join_commit_stage.fence_async, - now, &result, &elapsed_us); + pr = cluster_write_fence_poll_marker_async(&join_commit_stage.fence_async, now, &result, + &elapsed_us); if (pr == CLUSTER_MARKER_POLL_PENDING || pr == CLUSTER_MARKER_POLL_IDLE) return true; if (pr == CLUSTER_MARKER_POLL_TIMEOUT) { cluster_reconfig_note_marker_timeout(CLUSTER_MARKER_KIND_JOIN_COMMITTED, - join_commit_stage.node_id, - elapsed_us); + join_commit_stage.node_id, elapsed_us); pg_atomic_fetch_add_u64(&ReconfigShmem->join_reject_count, 1); cluster_reconfig_release_join_commit_stage(); return true; } cluster_reconfig_note_marker_slow_ack(CLUSTER_MARKER_KIND_JOIN_COMMITTED, - join_commit_stage.node_id, - elapsed_us); + join_commit_stage.node_id, elapsed_us); if (result != CLUSTER_FENCE_MARKER_SUBMIT_ACK || !cluster_reconfig_publish_prepared_join_commit()) { - ereport(LOG, - (errmsg("cluster membership: JOIN baseline marker for node %d did not " - "reach a voting-disk majority or its predecessor changed; " - "not committing (will retry)", - join_commit_stage.node_id))); + ereport(LOG, (errmsg("cluster membership: JOIN baseline marker for node %d did not " + "reach a voting-disk majority or its predecessor changed; " + "not committing (will retry)", + join_commit_stage.node_id))); pg_atomic_fetch_add_u64(&ReconfigShmem->join_reject_count, 1); cluster_reconfig_release_join_commit_stage(); return true; @@ -3821,8 +3594,8 @@ cluster_reconfig_poll_join_commit_stage(void) } /* STOP04 §11.7/§11.9: a consumed external rejoin can never publish MEMBER * without the mandatory durable excluded-set shrink. */ - if (join_commit_stage.external_rejoin_consumed && - cluster_write_fence_enforcement != CLUSTER_WRITE_FENCE_ENFORCE_ON) { + if (join_commit_stage.external_rejoin_consumed + && cluster_write_fence_enforcement != CLUSTER_WRITE_FENCE_ENFORCE_ON) { pg_atomic_fetch_add_u64(&ReconfigShmem->join_reject_count, 1); cluster_reconfig_release_join_commit_stage(); return true; @@ -3834,13 +3607,12 @@ cluster_reconfig_poll_join_commit_stage(void) || cluster_membership_vet_joiner(join_commit_stage.node_id, admitted_incarnation, admitted_generation) != CLUSTER_JOIN_ACCEPT - || (!join_commit_stage.external_rejoin_consumed && - !cluster_recovery_owner_rejoin_v1( - join_commit_stage.node_id, - join_commit_stage.admitted_incarnation)) + || (!join_commit_stage.external_rejoin_consumed + && !cluster_recovery_owner_rejoin_v1(join_commit_stage.node_id, + join_commit_stage.admitted_incarnation)) || !cluster_reconfig_prepare_join_commit(join_commit_stage.node_id, - join_commit_stage.admitted_incarnation, - join_commit_stage.async.staged_expect_epoch)) { + join_commit_stage.admitted_incarnation, + join_commit_stage.async.staged_expect_epoch)) { pg_atomic_fetch_add_u64(&ReconfigShmem->join_reject_count, 1); cluster_reconfig_release_join_commit_stage(); return true; @@ -3861,8 +3633,7 @@ cluster_reconfig_poll_join_commit_stage(void) * whose convergence is met -> re-vet (TOCTOU, INV-J1) -> commit_member. */ static void -cluster_reconfig_drive_joins(int coordinator, int32 control_target, - uint64 control_incarnation) +cluster_reconfig_drive_joins(int coordinator, int32 control_target, uint64 control_incarnation) { ClusterReconfigState *state = ReconfigShmem; uint8 join_bitmap[CLUSTER_RECONFIG_DEAD_BITMAP_BYTES]; @@ -3903,8 +3674,7 @@ cluster_reconfig_drive_joins(int coordinator, int32 control_target, continue; (void)cluster_reconfig_get_observed_slot(i, &joiner_incarnations[i], NULL); } - if (control_target >= 0 - && joiner_incarnations[control_target] != control_incarnation) + if (control_target >= 0 && joiner_incarnations[control_target] != control_incarnation) return; /* STOP04 §11.9 F→...→P: a previously admitted/excluded origin * cannot enter JOIN_PENDING before its exact provider operation has @@ -3912,16 +3682,14 @@ cluster_reconfig_drive_joins(int coordinator, int32 control_target, * required singleton P; clean first joins remain on the ordinary path. */ if (cluster_external_fence_runtime_active()) { for (i = 0; i < CLUSTER_MAX_NODES; i++) { - if (!dead_bitmap_test_bit(join_bitmap, i) || - !cluster_reconfig_external_rejoin_required(i)) + if (!dead_bitmap_test_bit(join_bitmap, i) + || !cluster_reconfig_external_rejoin_required(i)) continue; - if (external_selected < 0 && - cluster_reconfig_external_rejoin_authorized( - i, joiner_incarnations[i])) + if (external_selected < 0 + && cluster_reconfig_external_rejoin_authorized(i, joiner_incarnations[i])) external_selected = i; else - join_bitmap[i / 8] &= - (uint8) ~(1u << (i % 8)); + join_bitmap[i / 8] &= (uint8) ~(1u << (i % 8)); } if (external_selected >= 0) { memset(join_bitmap, 0, sizeof(join_bitmap)); @@ -3952,8 +3720,7 @@ cluster_reconfig_drive_joins(int coordinator, int32 control_target, if (!cluster_reconfig_get_observed_slot(i, &admitted_incarnation, &admitted_generation)) continue; /* no valid slot now -> wait */ if (control_target >= 0 - && (i != control_target - || admitted_incarnation != control_incarnation)) + && (i != control_target || admitted_incarnation != control_incarnation)) continue; /* authoritative re-vet at the commit point (TOCTOU, INV-J1): stale / * not-ready / out-of-quorum -> skip (the joiner times out -> REJECT). */ @@ -3962,8 +3729,7 @@ cluster_reconfig_drive_joins(int coordinator, int32 control_target, pg_atomic_fetch_add_u64(&ReconfigShmem->join_reject_count, 1); continue; } - if (!cluster_reconfig_external_rejoin_prepare_commit( - i, admitted_incarnation)) + if (!cluster_reconfig_external_rejoin_prepare_commit(i, admitted_incarnation)) continue; (void)cluster_reconfig_commit_member(i, admitted_incarnation); } @@ -3989,8 +3755,7 @@ cluster_reconfig_self_join_gate_verdict(void) } static bool -cluster_reconfig_is_local_admitted_replacement( - const ClusterReplacementEpisode *episode) +cluster_reconfig_is_local_admitted_replacement(const ClusterReplacementEpisode *episode) { return cluster_replacement_episode_is_valid(episode) && episode->phase == CLUSTER_REPLACEMENT_EPISODE_ADMITTED @@ -3999,8 +3764,7 @@ cluster_reconfig_is_local_admitted_replacement( } static bool -cluster_reconfig_has_replacement_episode( - const ClusterReplacementEpisode *episode) +cluster_reconfig_has_replacement_episode(const ClusterReplacementEpisode *episode) { /* Only the all-zero canonical image means the ordinary-join lane. A torn * or otherwise invalid nonempty mirror remains replacement state and must @@ -4009,8 +3773,7 @@ cluster_reconfig_has_replacement_episode( } bool -cluster_reconfig_lmon_observe_replacement_ready( - const ClusterReplacementPhase3HandoffItem *item) +cluster_reconfig_lmon_observe_replacement_ready(const ClusterReplacementPhase3HandoffItem *item) { ClusterReplacementCommitMarkerV3 marker; ClusterReplacementEpisode *episode; @@ -4023,37 +3786,27 @@ cluster_reconfig_lmon_observe_replacement_ready( return false; request_seq = pg_atomic_read_u64(&ReconfigShmem->join_marker_request_seq); - completion_seq - = pg_atomic_read_u64(&ReconfigShmem->join_marker_completion_seq); + completion_seq = pg_atomic_read_u64(&ReconfigShmem->join_marker_completion_seq); if (request_seq == 0 || request_seq != completion_seq - || pg_atomic_read_u32(&ReconfigShmem->join_marker_result) - != CLUSTER_JOIN_MARKER_SUBMIT_ACK) + || pg_atomic_read_u32(&ReconfigShmem->join_marker_result) != CLUSTER_JOIN_MARKER_SUBMIT_ACK) return false; pg_read_barrier(); LWLockAcquire(&ReconfigShmem->lock, LW_EXCLUSIVE); episode = &ReconfigShmem->replacement_episode; - if (pg_atomic_read_u64(&ReconfigShmem->join_marker_request_seq) - != request_seq - || pg_atomic_read_u64(&ReconfigShmem->join_marker_completion_seq) - != completion_seq - || pg_atomic_read_u32(&ReconfigShmem->join_marker_result) - != CLUSTER_JOIN_MARKER_SUBMIT_ACK - || !cluster_replacement_marker_v3_decode( - ReconfigShmem->join_pending_marker, item->message.target_node_id, - &marker) + if (pg_atomic_read_u64(&ReconfigShmem->join_marker_request_seq) != request_seq + || pg_atomic_read_u64(&ReconfigShmem->join_marker_completion_seq) != completion_seq + || pg_atomic_read_u32(&ReconfigShmem->join_marker_result) != CLUSTER_JOIN_MARKER_SUBMIT_ACK + || !cluster_replacement_marker_v3_decode(ReconfigShmem->join_pending_marker, + item->message.target_node_id, &marker) || !cluster_replacement_episode_is_valid(episode) || (episode->phase != CLUSTER_REPLACEMENT_EPISODE_COMMITTED_CLOSED && episode->phase != CLUSTER_REPLACEMENT_EPISODE_POST_EPOCH) - || (episode->readiness_flags - & CLUSTER_REPLACEMENT_EPISODE_INTENT_CLEARED) - == 0 + || (episode->readiness_flags & CLUSTER_REPLACEMENT_EPISODE_INTENT_CLEARED) == 0 || marker.phase != CLUSTER_JCMK_REPLACEMENT_PHASE_COMMITTED_CLOSED || marker.ready_state_generation != 0 - || marker.generation - != item->message.body.phase3.jcmk_generation - || episode->state_generation - != item->message.body.phase3.episode_state_generation + || marker.generation != item->message.body.phase3.jcmk_generation + || episode->state_generation != item->message.body.phase3.episode_state_generation || episode->target_node_id != item->authenticated_source_node_id || episode->target_node_id != item->message.target_node_id || episode->coordinator_node_id != cluster_node_id @@ -4063,25 +3816,20 @@ cluster_reconfig_lmon_observe_replacement_ready( || episode->request_nonce != item->message.request_nonce || episode->old_admitted_incarnation != item->message.identity0 || episode->fresh_incarnation != item->message.identity1 - || episode->grammar_fingerprint - != item->message.grammar_fingerprint + || episode->grammar_fingerprint != item->message.grammar_fingerprint || marker.target_node_id != episode->target_node_id - || marker.old_admitted_incarnation - != episode->old_admitted_incarnation + || marker.old_admitted_incarnation != episode->old_admitted_incarnation || marker.fresh_incarnation != episode->fresh_incarnation || marker.baseline_epoch != episode->baseline_epoch - || marker.reserved_or_committed_epoch - != episode->reserved_or_committed_epoch + || marker.reserved_or_committed_epoch != episode->reserved_or_committed_epoch || marker.request_nonce != episode->request_nonce - || memcmp(marker.expected_purge_survivors, - episode->expected_survivors, + || memcmp(marker.expected_purge_survivors, episode->expected_survivors, sizeof(marker.expected_purge_survivors)) != 0 || marker.grammar_fingerprint != episode->grammar_fingerprint) goto out; - episode->readiness_flags - |= CLUSTER_REPLACEMENT_EPISODE_R4A_TARGET_READY; + episode->readiness_flags |= CLUSTER_REPLACEMENT_EPISODE_R4A_TARGET_READY; accepted = true; out: @@ -4090,9 +3838,8 @@ cluster_reconfig_lmon_observe_replacement_ready( } bool -cluster_reconfig_lmon_build_replacement_admitted( - const ClusterEpochAuthorityValue *terminal_head, - ClusterReplacementCommitMarkerV3 *out_marker) +cluster_reconfig_lmon_build_replacement_admitted(const ClusterEpochAuthorityValue *terminal_head, + ClusterReplacementCommitMarkerV3 *out_marker) { ClusterReplacementCommitMarkerV3 committed; ClusterReplacementCommitMarkerV3 candidate; @@ -4104,89 +3851,66 @@ cluster_reconfig_lmon_build_replacement_admitted( uint64 completion_seq; bool built = false; - if (ReconfigShmem == NULL || terminal_head == NULL || out_marker == NULL - || cluster_node_id < 0 || cluster_node_id >= CLUSTER_MAX_NODES - || !cluster_epoch_authority_value_is_valid( - terminal_head, CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT) - || terminal_head->transition - != CLUSTER_EPOCH_AUTHORITY_COMMIT_CLOSED - || terminal_head->event_kind - != CLUSTER_EPOCH_EVENT_SAME_NODE_REPLACEMENT) + if (ReconfigShmem == NULL || terminal_head == NULL || out_marker == NULL || cluster_node_id < 0 + || cluster_node_id >= CLUSTER_MAX_NODES + || !cluster_epoch_authority_value_is_valid(terminal_head, + CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT) + || terminal_head->transition != CLUSTER_EPOCH_AUTHORITY_COMMIT_CLOSED + || terminal_head->event_kind != CLUSTER_EPOCH_EVENT_SAME_NODE_REPLACEMENT) return false; - if (!cluster_reconfig_replacement_candidate2_capabilities_current( - &capability_episode)) + if (!cluster_reconfig_replacement_candidate2_capabilities_current(&capability_episode)) return false; request_seq = pg_atomic_read_u64(&ReconfigShmem->join_marker_request_seq); - completion_seq - = pg_atomic_read_u64(&ReconfigShmem->join_marker_completion_seq); + completion_seq = pg_atomic_read_u64(&ReconfigShmem->join_marker_completion_seq); if (request_seq == 0 || request_seq != completion_seq - || pg_atomic_read_u32(&ReconfigShmem->join_marker_result) - != CLUSTER_JOIN_MARKER_SUBMIT_ACK) + || pg_atomic_read_u32(&ReconfigShmem->join_marker_result) != CLUSTER_JOIN_MARKER_SUBMIT_ACK) return false; pg_read_barrier(); LWLockAcquire(&ReconfigShmem->lock, LW_SHARED); episode = &ReconfigShmem->replacement_episode; - if (episode->target_node_id >= 0 - && episode->target_node_id < CLUSTER_MAX_NODES) - subject[episode->target_node_id / 8] - = (uint8)(1u << (episode->target_node_id % 8)); - if (pg_atomic_read_u64(&ReconfigShmem->join_marker_request_seq) - != request_seq - || pg_atomic_read_u64(&ReconfigShmem->join_marker_completion_seq) - != completion_seq - || pg_atomic_read_u32(&ReconfigShmem->join_marker_result) - != CLUSTER_JOIN_MARKER_SUBMIT_ACK - || !cluster_replacement_marker_v3_decode( - ReconfigShmem->join_pending_marker, episode->target_node_id, - &committed) + if (episode->target_node_id >= 0 && episode->target_node_id < CLUSTER_MAX_NODES) + subject[episode->target_node_id / 8] = (uint8)(1u << (episode->target_node_id % 8)); + if (pg_atomic_read_u64(&ReconfigShmem->join_marker_request_seq) != request_seq + || pg_atomic_read_u64(&ReconfigShmem->join_marker_completion_seq) != completion_seq + || pg_atomic_read_u32(&ReconfigShmem->join_marker_result) != CLUSTER_JOIN_MARKER_SUBMIT_ACK + || !cluster_replacement_marker_v3_decode(ReconfigShmem->join_pending_marker, + episode->target_node_id, &committed) || memcmp(episode, &capability_episode, sizeof(*episode)) != 0 || !cluster_replacement_episode_is_valid(episode) || !cluster_reconfig_replacement_membership_current_locked(episode) || (episode->phase != CLUSTER_REPLACEMENT_EPISODE_COMMITTED_CLOSED && episode->phase != CLUSTER_REPLACEMENT_EPISODE_POST_EPOCH) - || episode->readiness_flags - != CLUSTER_REPLACEMENT_EPISODE_READINESS_MASK + || episode->readiness_flags != CLUSTER_REPLACEMENT_EPISODE_READINESS_MASK || episode->state_generation == 0 - || episode->reserved_or_committed_epoch - != cluster_epoch_get_current() - || committed.phase - != CLUSTER_JCMK_REPLACEMENT_PHASE_COMMITTED_CLOSED - || committed.ready_state_generation != 0 - || committed.generation == UINT64_MAX + || episode->reserved_or_committed_epoch != cluster_epoch_get_current() + || committed.phase != CLUSTER_JCMK_REPLACEMENT_PHASE_COMMITTED_CLOSED + || committed.ready_state_generation != 0 || committed.generation == UINT64_MAX || committed.target_node_id != episode->target_node_id - || committed.old_admitted_incarnation - != episode->old_admitted_incarnation + || committed.old_admitted_incarnation != episode->old_admitted_incarnation || committed.fresh_incarnation != episode->fresh_incarnation || committed.baseline_epoch != episode->baseline_epoch - || committed.reserved_or_committed_epoch - != episode->reserved_or_committed_epoch + || committed.reserved_or_committed_epoch != episode->reserved_or_committed_epoch || committed.request_nonce != episode->request_nonce - || memcmp(committed.expected_purge_survivors, - episode->expected_survivors, + || memcmp(committed.expected_purge_survivors, episode->expected_survivors, sizeof(committed.expected_purge_survivors)) != 0 - || committed.grammar_fingerprint - != episode->grammar_fingerprint + || committed.grammar_fingerprint != episode->grammar_fingerprint || terminal_head->request_origin_node != episode->target_node_id || terminal_head->target_node_id != episode->target_node_id || terminal_head->baseline_epoch != episode->baseline_epoch - || terminal_head->reserved_epoch - != episode->reserved_or_committed_epoch - || terminal_head->old_incarnation - != episode->old_admitted_incarnation + || terminal_head->reserved_epoch != episode->reserved_or_committed_epoch + || terminal_head->old_incarnation != episode->old_admitted_incarnation || terminal_head->fresh_incarnation != episode->fresh_incarnation || terminal_head->request_nonce != episode->request_nonce - || memcmp(terminal_head->authority_member_bitmap, - episode->expected_survivors, + || memcmp(terminal_head->authority_member_bitmap, episode->expected_survivors, sizeof(terminal_head->authority_member_bitmap)) != 0 || memcmp(terminal_head->event_subject_bitmap, subject, sizeof(terminal_head->event_subject_bitmap)) != 0 - || terminal_head->grammar_fingerprint - != episode->grammar_fingerprint) + || terminal_head->grammar_fingerprint != episode->grammar_fingerprint) goto out; candidate = committed; @@ -4216,101 +3940,73 @@ cluster_reconfig_lmon_finalize_replacement_admitted( uint64 completion_seq; bool finalized = false; - if (ReconfigShmem == NULL || terminal_head == NULL - || admitted_marker == NULL || cluster_node_id < 0 - || cluster_node_id >= CLUSTER_MAX_NODES - || !cluster_epoch_authority_value_is_valid( - terminal_head, CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT) - || terminal_head->transition - != CLUSTER_EPOCH_AUTHORITY_COMMIT_CLOSED - || terminal_head->event_kind - != CLUSTER_EPOCH_EVENT_SAME_NODE_REPLACEMENT - || admitted_marker->phase - != CLUSTER_JCMK_REPLACEMENT_PHASE_ADMITTED + if (ReconfigShmem == NULL || terminal_head == NULL || admitted_marker == NULL + || cluster_node_id < 0 || cluster_node_id >= CLUSTER_MAX_NODES + || !cluster_epoch_authority_value_is_valid(terminal_head, + CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT) + || terminal_head->transition != CLUSTER_EPOCH_AUTHORITY_COMMIT_CLOSED + || terminal_head->event_kind != CLUSTER_EPOCH_EVENT_SAME_NODE_REPLACEMENT + || admitted_marker->phase != CLUSTER_JCMK_REPLACEMENT_PHASE_ADMITTED || admitted_marker->ready_state_generation == 0) return false; - if (!cluster_reconfig_replacement_candidate2_capabilities_current( - &capability_episode)) + if (!cluster_reconfig_replacement_candidate2_capabilities_current(&capability_episode)) return false; request_seq = pg_atomic_read_u64(&ReconfigShmem->join_marker_request_seq); - completion_seq - = pg_atomic_read_u64(&ReconfigShmem->join_marker_completion_seq); + completion_seq = pg_atomic_read_u64(&ReconfigShmem->join_marker_completion_seq); if (request_seq == 0 || request_seq != completion_seq - || pg_atomic_read_u32(&ReconfigShmem->join_marker_result) - != CLUSTER_JOIN_MARKER_SUBMIT_ACK) + || pg_atomic_read_u32(&ReconfigShmem->join_marker_result) != CLUSTER_JOIN_MARKER_SUBMIT_ACK) return false; pg_read_barrier(); LWLockAcquire(&ReconfigShmem->lock, LW_EXCLUSIVE); episode = &ReconfigShmem->replacement_episode; - if (episode->target_node_id >= 0 - && episode->target_node_id < CLUSTER_MAX_NODES) - subject[episode->target_node_id / 8] - = (uint8)(1u << (episode->target_node_id % 8)); - if (pg_atomic_read_u64(&ReconfigShmem->join_marker_request_seq) - != request_seq - || pg_atomic_read_u64(&ReconfigShmem->join_marker_completion_seq) - != completion_seq - || pg_atomic_read_u32(&ReconfigShmem->join_marker_result) - != CLUSTER_JOIN_MARKER_SUBMIT_ACK - || !cluster_replacement_marker_v3_decode( - ReconfigShmem->join_pending_marker, admitted_marker->target_node_id, - &durable) - || !cluster_replacement_marker_v3_same_image( - &durable, admitted_marker) + if (episode->target_node_id >= 0 && episode->target_node_id < CLUSTER_MAX_NODES) + subject[episode->target_node_id / 8] = (uint8)(1u << (episode->target_node_id % 8)); + if (pg_atomic_read_u64(&ReconfigShmem->join_marker_request_seq) != request_seq + || pg_atomic_read_u64(&ReconfigShmem->join_marker_completion_seq) != completion_seq + || pg_atomic_read_u32(&ReconfigShmem->join_marker_result) != CLUSTER_JOIN_MARKER_SUBMIT_ACK + || !cluster_replacement_marker_v3_decode(ReconfigShmem->join_pending_marker, + admitted_marker->target_node_id, &durable) + || !cluster_replacement_marker_v3_same_image(&durable, admitted_marker) || memcmp(episode, &capability_episode, sizeof(*episode)) != 0 || !cluster_replacement_episode_is_valid(episode) || !cluster_reconfig_replacement_membership_current_locked(episode) || (episode->phase != CLUSTER_REPLACEMENT_EPISODE_COMMITTED_CLOSED && episode->phase != CLUSTER_REPLACEMENT_EPISODE_POST_EPOCH) - || episode->readiness_flags - != CLUSTER_REPLACEMENT_EPISODE_READINESS_MASK - || episode->state_generation - != admitted_marker->ready_state_generation + || episode->readiness_flags != CLUSTER_REPLACEMENT_EPISODE_READINESS_MASK + || episode->state_generation != admitted_marker->ready_state_generation || episode->coordinator_node_id != cluster_node_id || episode->target_node_id != admitted_marker->target_node_id - || episode->old_admitted_incarnation - != admitted_marker->old_admitted_incarnation - || episode->fresh_incarnation - != admitted_marker->fresh_incarnation + || episode->old_admitted_incarnation != admitted_marker->old_admitted_incarnation + || episode->fresh_incarnation != admitted_marker->fresh_incarnation || episode->baseline_epoch != admitted_marker->baseline_epoch - || episode->reserved_or_committed_epoch - != admitted_marker->reserved_or_committed_epoch - || episode->reserved_or_committed_epoch - != cluster_epoch_get_current() + || episode->reserved_or_committed_epoch != admitted_marker->reserved_or_committed_epoch + || episode->reserved_or_committed_epoch != cluster_epoch_get_current() || episode->request_nonce != admitted_marker->request_nonce - || memcmp(episode->expected_survivors, - admitted_marker->expected_purge_survivors, + || memcmp(episode->expected_survivors, admitted_marker->expected_purge_survivors, sizeof(episode->expected_survivors)) != 0 - || episode->grammar_fingerprint - != admitted_marker->grammar_fingerprint + || episode->grammar_fingerprint != admitted_marker->grammar_fingerprint || terminal_head->request_origin_node != episode->target_node_id || terminal_head->target_node_id != episode->target_node_id || terminal_head->baseline_epoch != episode->baseline_epoch - || terminal_head->reserved_epoch - != episode->reserved_or_committed_epoch - || terminal_head->old_incarnation - != episode->old_admitted_incarnation + || terminal_head->reserved_epoch != episode->reserved_or_committed_epoch + || terminal_head->old_incarnation != episode->old_admitted_incarnation || terminal_head->fresh_incarnation != episode->fresh_incarnation || terminal_head->request_nonce != episode->request_nonce - || memcmp(terminal_head->authority_member_bitmap, - episode->expected_survivors, + || memcmp(terminal_head->authority_member_bitmap, episode->expected_survivors, sizeof(terminal_head->authority_member_bitmap)) != 0 || memcmp(terminal_head->event_subject_bitmap, subject, sizeof(terminal_head->event_subject_bitmap)) != 0 - || terminal_head->grammar_fingerprint - != episode->grammar_fingerprint) + || terminal_head->grammar_fingerprint != episode->grammar_fingerprint) goto out; episode->phase = CLUSTER_REPLACEMENT_EPISODE_ADMITTED; - cluster_membership_set_state(episode->target_node_id, - CLUSTER_MEMBER_MEMBER); - cluster_membership_record_admitted(episode->target_node_id, - episode->fresh_incarnation); + cluster_membership_set_state(episode->target_node_id, CLUSTER_MEMBER_MEMBER); + cluster_membership_record_admitted(episode->target_node_id, episode->fresh_incarnation); finalized = true; out: @@ -4327,9 +4023,8 @@ cluster_reconfig_lmon_finalize_replacement_admitted( * carrier and is deliberately not inferred from this process-local mailbox. */ bool -cluster_reconfig_lmon_snapshot_replacement_admitted( - ClusterReplacementEpisode *out_episode, - ClusterReplacementCommitMarkerV3 *out_marker) +cluster_reconfig_lmon_snapshot_replacement_admitted(ClusterReplacementEpisode *out_episode, + ClusterReplacementCommitMarkerV3 *out_marker) { ClusterReplacementEpisode observed_episode; ClusterReplacementCommitMarkerV3 observed_marker; @@ -4339,63 +4034,48 @@ cluster_reconfig_lmon_snapshot_replacement_admitted( bool valid = false; int node; - if (ReconfigShmem == NULL || out_episode == NULL || out_marker == NULL - || cluster_node_id < 0 || cluster_node_id >= CLUSTER_MAX_NODES) + if (ReconfigShmem == NULL || out_episode == NULL || out_marker == NULL || cluster_node_id < 0 + || cluster_node_id >= CLUSTER_MAX_NODES) return false; request_seq = pg_atomic_read_u64(&ReconfigShmem->join_marker_request_seq); - completion_seq - = pg_atomic_read_u64(&ReconfigShmem->join_marker_completion_seq); + completion_seq = pg_atomic_read_u64(&ReconfigShmem->join_marker_completion_seq); if (request_seq == 0 || request_seq != completion_seq - || pg_atomic_read_u32(&ReconfigShmem->join_marker_result) - != CLUSTER_JOIN_MARKER_SUBMIT_ACK) + || pg_atomic_read_u32(&ReconfigShmem->join_marker_result) != CLUSTER_JOIN_MARKER_SUBMIT_ACK) return false; pg_read_barrier(); LWLockAcquire(&ReconfigShmem->lock, LW_SHARED); episode = &ReconfigShmem->replacement_episode; - if (pg_atomic_read_u64(&ReconfigShmem->join_marker_request_seq) - != request_seq - || pg_atomic_read_u64(&ReconfigShmem->join_marker_completion_seq) - != completion_seq - || pg_atomic_read_u32(&ReconfigShmem->join_marker_result) - != CLUSTER_JOIN_MARKER_SUBMIT_ACK + if (pg_atomic_read_u64(&ReconfigShmem->join_marker_request_seq) != request_seq + || pg_atomic_read_u64(&ReconfigShmem->join_marker_completion_seq) != completion_seq + || pg_atomic_read_u32(&ReconfigShmem->join_marker_result) != CLUSTER_JOIN_MARKER_SUBMIT_ACK || !cluster_replacement_episode_is_valid(episode) || episode->phase != CLUSTER_REPLACEMENT_EPISODE_ADMITTED - || episode->readiness_flags - != CLUSTER_REPLACEMENT_EPISODE_READINESS_MASK + || episode->readiness_flags != CLUSTER_REPLACEMENT_EPISODE_READINESS_MASK || episode->coordinator_node_id != cluster_node_id - || episode->reserved_or_committed_epoch - != cluster_epoch_get_current() - || !cluster_replacement_marker_v3_decode( - ReconfigShmem->join_pending_marker, episode->target_node_id, - &observed_marker) - || observed_marker.phase - != CLUSTER_JCMK_REPLACEMENT_PHASE_ADMITTED - || observed_marker.ready_state_generation - != episode->state_generation + || episode->reserved_or_committed_epoch != cluster_epoch_get_current() + || !cluster_replacement_marker_v3_decode(ReconfigShmem->join_pending_marker, + episode->target_node_id, &observed_marker) + || observed_marker.phase != CLUSTER_JCMK_REPLACEMENT_PHASE_ADMITTED + || observed_marker.ready_state_generation != episode->state_generation || observed_marker.target_node_id != episode->target_node_id - || observed_marker.old_admitted_incarnation - != episode->old_admitted_incarnation + || observed_marker.old_admitted_incarnation != episode->old_admitted_incarnation || observed_marker.fresh_incarnation != episode->fresh_incarnation || observed_marker.baseline_epoch != episode->baseline_epoch - || observed_marker.reserved_or_committed_epoch - != episode->reserved_or_committed_epoch + || observed_marker.reserved_or_committed_epoch != episode->reserved_or_committed_epoch || observed_marker.request_nonce != episode->request_nonce - || memcmp(observed_marker.expected_purge_survivors, - episode->expected_survivors, + || memcmp(observed_marker.expected_purge_survivors, episode->expected_survivors, sizeof(observed_marker.expected_purge_survivors)) != 0 - || observed_marker.grammar_fingerprint - != episode->grammar_fingerprint - || cluster_membership_get_last_admitted_incarnation( - episode->target_node_id) != episode->fresh_incarnation) + || observed_marker.grammar_fingerprint != episode->grammar_fingerprint + || cluster_membership_get_last_admitted_incarnation(episode->target_node_id) + != episode->fresh_incarnation) goto out; for (node = 0; node < CLUSTER_MAX_NODES; node++) { - bool expected_member - = node == episode->target_node_id - || dead_bitmap_test_bit(episode->expected_survivors, node); + bool expected_member = node == episode->target_node_id + || dead_bitmap_test_bit(episode->expected_survivors, node); if (cluster_membership_is_member(node) != expected_member) goto out; @@ -4422,14 +4102,13 @@ cluster_reconfig_lmon_snapshot_replacement_admitted( * no evidence outside the caller's stack. */ bool -cluster_reconfig_snapshot_initial_clean_formation( - ClusterInitialCleanFormationSnapshot *out) +cluster_reconfig_snapshot_initial_clean_formation(ClusterInitialCleanFormationSnapshot *out) { ClusterInitialCleanFormationSnapshot snapshot; - uint64 bootstrap_incarnation[4] = {0}; - uint64 bootstrap_generation[4] = {0}; - uint64 bootstrap_epoch[4] = {0}; - bool bootstrap_fresh[4] = {false}; + uint64 bootstrap_incarnation[4] = { 0 }; + uint64 bootstrap_generation[4] = { 0 }; + uint64 bootstrap_epoch[4] = { 0 }; + bool bootstrap_fresh[4] = { false }; uint64 bootstrap_seq = 0; uint64 bootstrap_seq_after = 0; uint64 marker_generation; @@ -4444,147 +4123,120 @@ cluster_reconfig_snapshot_initial_clean_formation( if (out == NULL) return false; memset(out, 0, sizeof(*out)); - if (ReconfigShmem == NULL || cluster_node_id < 0 - || cluster_node_id >= 4) + if (ReconfigShmem == NULL || cluster_node_id < 0 || cluster_node_id >= 4) return false; - marker_generation = pg_atomic_read_u64( - &ReconfigShmem->observed_formation_marker_generation); + marker_generation = pg_atomic_read_u64(&ReconfigShmem->observed_formation_marker_generation); memset(&snapshot, 0, sizeof(snapshot)); current_epoch = cluster_epoch_get_current(); initial_basis = marker_generation == 0; if (initial_basis) { if (current_epoch != CLUSTER_EPOCH_INITIAL) return false; - bootstrap_seq = pg_atomic_read_u64( - &ReconfigShmem->observed_bootstrap_seq); + bootstrap_seq = pg_atomic_read_u64(&ReconfigShmem->observed_bootstrap_seq); if (bootstrap_seq == 0 || (bootstrap_seq & UINT64_C(1)) != 0) return false; pg_read_barrier(); if (pg_atomic_read_u64(&ReconfigShmem->bootstrap_in_quorum) == 0) return false; for (node = 0; node < 4; node++) { - bootstrap_incarnation[node] = pg_atomic_read_u64( - &ReconfigShmem->observed_incarnation[node]); - bootstrap_generation[node] = pg_atomic_read_u64( - &ReconfigShmem->observed_generation[node]); - bootstrap_epoch[node] = pg_atomic_read_u64( - &ReconfigShmem->observed_epoch[node]); - bootstrap_fresh[node] = pg_atomic_read_u64( - &ReconfigShmem->observed_fresh_alive[node]) != 0; + bootstrap_incarnation[node] + = pg_atomic_read_u64(&ReconfigShmem->observed_incarnation[node]); + bootstrap_generation[node] + = pg_atomic_read_u64(&ReconfigShmem->observed_generation[node]); + bootstrap_epoch[node] = pg_atomic_read_u64(&ReconfigShmem->observed_epoch[node]); + bootstrap_fresh[node] + = pg_atomic_read_u64(&ReconfigShmem->observed_fresh_alive[node]) != 0; } pg_read_barrier(); - if (pg_atomic_read_u64( - &ReconfigShmem->observed_bootstrap_seq) != bootstrap_seq - || pg_atomic_read_u64( - &ReconfigShmem->observed_formation_marker_generation) != 0) + if (pg_atomic_read_u64(&ReconfigShmem->observed_bootstrap_seq) != bootstrap_seq + || pg_atomic_read_u64(&ReconfigShmem->observed_formation_marker_generation) != 0) return false; snapshot.formation_epoch = current_epoch; } else { pg_read_barrier(); snapshot.formation_marker_generation = marker_generation; - snapshot.formation_epoch = pg_atomic_read_u64( - &ReconfigShmem->observed_formation_marker_epoch); - snapshot.arbiter_node = pg_atomic_read_u64( - &ReconfigShmem->observed_formation_marker_arbiter_node); - snapshot.arbiter_incarnation = pg_atomic_read_u64( - &ReconfigShmem->observed_formation_marker_arbiter_incarnation); + snapshot.formation_epoch + = pg_atomic_read_u64(&ReconfigShmem->observed_formation_marker_epoch); + snapshot.arbiter_node + = pg_atomic_read_u64(&ReconfigShmem->observed_formation_marker_arbiter_node); + snapshot.arbiter_incarnation + = pg_atomic_read_u64(&ReconfigShmem->observed_formation_marker_arbiter_incarnation); for (node = 0; node < 4; node++) - snapshot.admitted_incarnation[node] = pg_atomic_read_u64( - &ReconfigShmem->observed_formation_marker_incarnation[node]); + snapshot.admitted_incarnation[node] + = pg_atomic_read_u64(&ReconfigShmem->observed_formation_marker_incarnation[node]); pg_read_barrier(); - if (pg_atomic_read_u64( - &ReconfigShmem->observed_formation_marker_generation) + if (pg_atomic_read_u64(&ReconfigShmem->observed_formation_marker_generation) != marker_generation) return false; } self_incarnation = cluster_qvotec_get_self_incarnation(); LWLockAcquire(&ReconfigShmem->lock, LW_SHARED); - if (snapshot.formation_epoch != current_epoch - || ReconfigShmem->last_applied.event_id != 0 + if (snapshot.formation_epoch != current_epoch || ReconfigShmem->last_applied.event_id != 0 || ReconfigShmem->last_applied.reconfig_kind != RECONFIG_KIND_NONE || pg_atomic_read_u64(&ReconfigShmem->apply_counter) != 0 || pg_atomic_read_u32(&ReconfigShmem->prebump_sync_active) != 0 - || ReconfigShmem->self_join_admitted != 1 - || ReconfigShmem->self_join_failed != 0 + || ReconfigShmem->self_join_admitted != 1 || ReconfigShmem->self_join_failed != 0 || !dead_bitmap_is_zero(ReconfigShmem->pending_join_bitmap) || !dead_bitmap_is_zero(ReconfigShmem->clean_departed_bitmap) || !dead_bitmap_is_zero(ReconfigShmem->removed_bitmap) || !dead_bitmap_is_zero(ReconfigShmem->fast_rejoin_bitmap) - || !cluster_replacement_episode_is_empty( - &ReconfigShmem->replacement_episode) + || !cluster_replacement_episode_is_empty(&ReconfigShmem->replacement_episode) || pg_atomic_read_u64(&ReconfigShmem->join_marker_request_seq) != 0 || pg_atomic_read_u64(&ReconfigShmem->join_marker_completion_seq) != 0 || (initial_basis - && (pg_atomic_read_u64( - &ReconfigShmem->formation_marker_request_seq) != 0 - || pg_atomic_read_u64( - &ReconfigShmem->formation_marker_completion_seq) != 0 - || pg_atomic_read_u64( - &ReconfigShmem->formation_marker_max_generation) != 0)) + && (pg_atomic_read_u64(&ReconfigShmem->formation_marker_request_seq) != 0 + || pg_atomic_read_u64(&ReconfigShmem->formation_marker_completion_seq) != 0 + || pg_atomic_read_u64(&ReconfigShmem->formation_marker_max_generation) != 0)) || (!initial_basis - && (snapshot.arbiter_node >= 4 - || snapshot.arbiter_incarnation == 0 + && (snapshot.arbiter_node >= 4 || snapshot.arbiter_incarnation == 0 || snapshot.admitted_incarnation[snapshot.arbiter_node] - != snapshot.arbiter_incarnation))) + != snapshot.arbiter_incarnation))) goto out; for (node = 0; node < CLUSTER_MAX_NODES; node++) { if ((node < 4) != (cluster_conf_lookup_node(node) != NULL)) goto out; if (node < 4) { - uint64 admitted_incarnation - = cluster_membership_get_last_admitted_incarnation(node); + uint64 admitted_incarnation = cluster_membership_get_last_admitted_incarnation(node); if (admitted_incarnation == 0 - || cluster_membership_get_state(node) - != CLUSTER_MEMBER_MEMBER - || (!initial_basis - && admitted_incarnation - != snapshot.admitted_incarnation[node])) + || cluster_membership_get_state(node) != CLUSTER_MEMBER_MEMBER + || (!initial_basis && admitted_incarnation != snapshot.admitted_incarnation[node])) goto out; if (initial_basis) { - snapshot.admitted_incarnation[node] - = admitted_incarnation; + snapshot.admitted_incarnation[node] = admitted_incarnation; if (node == cluster_node_id) { - if (self_incarnation == 0 - || admitted_incarnation != self_incarnation) + if (self_incarnation == 0 || admitted_incarnation != self_incarnation) goto out; bootstrap_proven++; - } else if (bootstrap_fresh[node] - && bootstrap_generation[node] > 0 - && bootstrap_epoch[node] - == CLUSTER_EPOCH_INITIAL) { - if (bootstrap_incarnation[node] - != admitted_incarnation) + } else if (bootstrap_fresh[node] && bootstrap_generation[node] > 0 + && bootstrap_epoch[node] == CLUSTER_EPOCH_INITIAL) { + if (bootstrap_incarnation[node] != admitted_incarnation) goto out; bootstrap_proven++; - } else if (bootstrap_epoch[node] - > CLUSTER_EPOCH_INITIAL) + } else if (bootstrap_epoch[node] > CLUSTER_EPOCH_INITIAL) goto out; } snapshot.members_lo |= UINT64_C(1) << node; - } else if (cluster_membership_get_state(node) - == CLUSTER_MEMBER_MEMBER - || (!initial_basis && pg_atomic_read_u64( - &ReconfigShmem->observed_formation_marker_incarnation[node]) - != 0)) + } else if (cluster_membership_get_state(node) == CLUSTER_MEMBER_MEMBER + || (!initial_basis + && pg_atomic_read_u64( + &ReconfigShmem->observed_formation_marker_incarnation[node]) + != 0)) goto out; } if (initial_basis && bootstrap_proven < UINT32_C(3)) goto out; - marker_generation_after = pg_atomic_read_u64( - &ReconfigShmem->observed_formation_marker_generation); - bootstrap_seq_after = pg_atomic_read_u64( - &ReconfigShmem->observed_bootstrap_seq); + marker_generation_after + = pg_atomic_read_u64(&ReconfigShmem->observed_formation_marker_generation); + bootstrap_seq_after = pg_atomic_read_u64(&ReconfigShmem->observed_bootstrap_seq); if ((!initial_basis && marker_generation_after != marker_generation) || (initial_basis - && (marker_generation_after != 0 - || bootstrap_seq_after != bootstrap_seq + && (marker_generation_after != 0 || bootstrap_seq_after != bootstrap_seq || (bootstrap_seq_after & UINT64_C(1)) != 0 - || pg_atomic_read_u64( - &ReconfigShmem->bootstrap_in_quorum) == 0)) + || pg_atomic_read_u64(&ReconfigShmem->bootstrap_in_quorum) == 0)) || cluster_epoch_get_current() != current_epoch) goto out; valid = !initial_basis || cluster_qvotec_in_quorum(); @@ -4607,51 +4259,42 @@ cluster_reconfig_lmon_replacement_ready_tick(void) uint32 marker_result = CLUSTER_JOIN_MARKER_SUBMIT_FAILED; uint64 elapsed_us = 0; - if (!cluster_enabled || MyBackendType != B_LMON - || !cluster_qvotec_in_quorum() || cluster_node_id < 0 - || cluster_node_id >= CLUSTER_MAX_NODES) + if (!cluster_enabled || MyBackendType != B_LMON || !cluster_qvotec_in_quorum() + || cluster_node_id < 0 || cluster_node_id >= CLUSTER_MAX_NODES) return; - if (replacement_ready_stage.phase - == CLUSTER_REPLACEMENT_READY_STAGE_IDLE) { + if (replacement_ready_stage.phase == CLUSTER_REPLACEMENT_READY_STAGE_IDLE) { cluster_marker_async_init(&replacement_ready_stage.marker_async); - (void)cluster_reconfig_lmon_submit_ready_observer_pair( - GetCurrentTimestamp()); + (void)cluster_reconfig_lmon_submit_ready_observer_pair(GetCurrentTimestamp()); return; } - if (replacement_ready_stage.phase - == CLUSTER_REPLACEMENT_READY_STAGE_DRAIN_AUTHORITY) { + if (replacement_ready_stage.phase == CLUSTER_REPLACEMENT_READY_STAGE_DRAIN_AUTHORITY) { /* The pair was irrevocably discarded. Poll once only to consume a * visible completion; a pending or restart-reset authority mailbox is * handled by the next fresh submit's existing BUSY/ACCEPTED result. */ (void)cluster_qvotec_authority_lmon_poll_completion( - replacement_ready_stage.authority_request_seq, - &ignored_completion); + replacement_ready_stage.authority_request_seq, &ignored_completion); cluster_reconfig_release_ready_stage(); return; } - if (replacement_ready_stage.phase - == CLUSTER_REPLACEMENT_READY_STAGE_WAIT_PAIR) { + if (replacement_ready_stage.phase == CLUSTER_REPLACEMENT_READY_STAGE_WAIT_PAIR) { if (!replacement_ready_stage.marker_completed) { marker_poll = cluster_reconfig_poll_join_marker_async( - &replacement_ready_stage.marker_async, - GetCurrentTimestamp(), &marker_result, &elapsed_us); + &replacement_ready_stage.marker_async, GetCurrentTimestamp(), &marker_result, + &elapsed_us); if (marker_poll == CLUSTER_MARKER_POLL_PENDING || marker_poll == CLUSTER_MARKER_POLL_IDLE) return; if (marker_poll != CLUSTER_MARKER_POLL_ACKED || marker_result != CLUSTER_JOIN_MARKER_SUBMIT_ACK) { - memset(&join_marker_lmon_owner, 0, - sizeof(join_marker_lmon_owner)); - replacement_ready_stage.phase - = CLUSTER_REPLACEMENT_READY_STAGE_DRAIN_AUTHORITY; + memset(&join_marker_lmon_owner, 0, sizeof(join_marker_lmon_owner)); + replacement_ready_stage.phase = CLUSTER_REPLACEMENT_READY_STAGE_DRAIN_AUTHORITY; return; } replacement_ready_stage.marker_completed = true; } snapshot = cluster_undo_block0_r4_prerequisite_snapshot(); - if (snapshot.status != CLUSTER_R4_PREREQUISITE_R4A_READY - || !snapshot.ready) + if (snapshot.status != CLUSTER_R4_PREREQUISITE_R4A_READY || !snapshot.ready) return; if (!cluster_replacement_wire_encode_phase3_snapshot( &snapshot, replacement_ready_stage.cached_image)) { @@ -4659,21 +4302,17 @@ cluster_reconfig_lmon_replacement_ready_tick(void) return; } replacement_ready_stage.cached_snapshot = snapshot; - replacement_ready_stage.phase - = CLUSTER_REPLACEMENT_READY_STAGE_CACHED; + replacement_ready_stage.phase = CLUSTER_REPLACEMENT_READY_STAGE_CACHED; } - if (!cluster_reconfig_lmon_ready_cache_current( - &coordinator_node_id)) + if (!cluster_reconfig_lmon_ready_cache_current(&coordinator_node_id)) return; - send_result = cluster_ic_send_envelope( - PGRAC_IC_MSG_GES_REQUEST, coordinator_node_id, - replacement_ready_stage.cached_image, - CLUSTER_REPLACEMENT_WIRE_BYTES); + send_result = cluster_ic_send_envelope(PGRAC_IC_MSG_GES_REQUEST, coordinator_node_id, + replacement_ready_stage.cached_image, + CLUSTER_REPLACEMENT_WIRE_BYTES); if (send_result == CLUSTER_IC_SEND_HARD_ERROR) - cluster_ic_tier1_close_peer( - coordinator_node_id, "replacement READY send hard error"); + cluster_ic_tier1_close_peer(coordinator_node_id, "replacement READY send hard error"); } ClusterR4PrerequisiteSnapshot @@ -4682,7 +4321,7 @@ cluster_reconfig_r4_prerequisite_snapshot(void) ClusterR4PrerequisiteSnapshot dormant = { .status = CLUSTER_R4_PREREQUISITE_RF_DEFERRED, .ready = false, - .reserved0 = {0, 0, 0}, + .reserved0 = { 0, 0, 0 }, .target_node_id = -1, }; ClusterR4PrerequisiteSnapshot snapshot; @@ -4700,92 +4339,71 @@ cluster_reconfig_r4_prerequisite_snapshot(void) bool keep_waiting = false; bool valid = false; - if (ReconfigShmem == NULL || MyBackendType != B_LMON - || cluster_node_id < 0 + if (ReconfigShmem == NULL || MyBackendType != B_LMON || cluster_node_id < 0 || cluster_node_id >= CLUSTER_MAX_NODES) return dormant; capabilities_current - = cluster_reconfig_replacement_candidate2_capabilities_current( - &capability_episode); + = cluster_reconfig_replacement_candidate2_capabilities_current(&capability_episode); LWLockAcquire(&ReconfigShmem->lock, LW_EXCLUSIVE); if (!join_marker_lmon_owner.reserved - || join_marker_lmon_owner.purpose - != CLUSTER_JOIN_MARKER_LMON_READY_SERIALIZE - || join_marker_lmon_owner.operation - != CLUSTER_JOIN_MARKER_MAILBOX_VERIFY_COMMITTED_CLOSED + || join_marker_lmon_owner.purpose != CLUSTER_JOIN_MARKER_LMON_READY_SERIALIZE + || join_marker_lmon_owner.operation != CLUSTER_JOIN_MARKER_MAILBOX_VERIFY_COMMITTED_CLOSED || join_marker_lmon_owner.marker_request_seq == 0 - || replacement_ready_stage.phase - != CLUSTER_REPLACEMENT_READY_STAGE_WAIT_PAIR + || replacement_ready_stage.phase != CLUSTER_REPLACEMENT_READY_STAGE_WAIT_PAIR || !replacement_ready_stage.marker_completed || replacement_ready_stage.authority_request_seq == 0 - || replacement_ready_stage.marker_request_seq - != join_marker_lmon_owner.marker_request_seq) + || replacement_ready_stage.marker_request_seq != join_marker_lmon_owner.marker_request_seq) goto out; if (!capabilities_current - || memcmp(&ReconfigShmem->replacement_episode, - &capability_episode, sizeof(capability_episode)) != 0 + || memcmp(&ReconfigShmem->replacement_episode, &capability_episode, + sizeof(capability_episode)) + != 0 || cluster_qvotec_get_status() != CLUSTER_QVOTEC_READY) goto out; if (!cluster_qvotec_authority_lmon_poll_completion( - replacement_ready_stage.authority_request_seq, - &completion)) { + replacement_ready_stage.authority_request_seq, &completion)) { keep_waiting = true; goto out; } if (completion.result != CLUSTER_QVOTEC_MAILBOX_CHOSEN || completion.actor_phase != CLUSTER_QVOTEC_ACTOR_RECOVER_SCAN_B - || !cluster_epoch_authority_value_decode( - completion.completion_value, - CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT, &head) - || !cluster_epoch_ballot_id_decode( - completion.completion_ballot, &ballot)) + || !cluster_epoch_authority_value_decode(completion.completion_value, + CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT, &head) + || !cluster_epoch_ballot_id_decode(completion.completion_ballot, &ballot)) goto out; if (pg_atomic_read_u64(&ReconfigShmem->join_marker_request_seq) != replacement_ready_stage.marker_request_seq || pg_atomic_read_u64(&ReconfigShmem->join_marker_completion_seq) != replacement_ready_stage.marker_request_seq - || pg_atomic_read_u32(&ReconfigShmem->join_marker_result) - != CLUSTER_JOIN_MARKER_SUBMIT_ACK) + || pg_atomic_read_u32(&ReconfigShmem->join_marker_result) != CLUSTER_JOIN_MARKER_SUBMIT_ACK) goto out; request_word = ReconfigShmem->join_marker_request_word; - if (!cluster_reconfig_join_marker_request_word_decode( - request_word, &operation, &request_target) - || operation - != CLUSTER_JOIN_MARKER_MAILBOX_VERIFY_COMMITTED_CLOSED) + if (!cluster_reconfig_join_marker_request_word_decode(request_word, &operation, &request_target) + || operation != CLUSTER_JOIN_MARKER_MAILBOX_VERIFY_COMMITTED_CLOSED) goto out; episode = &ReconfigShmem->replacement_episode; if (cluster_replacement_episode_is_valid(episode) && (episode->phase == CLUSTER_REPLACEMENT_EPISODE_COMMITTED_CLOSED || episode->phase == CLUSTER_REPLACEMENT_EPISODE_POST_EPOCH) - && (episode->readiness_flags - & CLUSTER_REPLACEMENT_EPISODE_R4A_TARGET_READY) != 0 - && episode->state_generation != 0 - && episode->target_node_id == cluster_node_id - && episode->reserved_or_committed_epoch - == cluster_epoch_get_current() - && ReconfigShmem->self_join_admitted == 0 - && ReconfigShmem->self_join_failed == 0 + && (episode->readiness_flags & CLUSTER_REPLACEMENT_EPISODE_R4A_TARGET_READY) != 0 + && episode->state_generation != 0 && episode->target_node_id == cluster_node_id + && episode->reserved_or_committed_epoch == cluster_epoch_get_current() + && ReconfigShmem->self_join_admitted == 0 && ReconfigShmem->self_join_failed == 0 && cluster_reconfig_replacement_membership_current_locked(episode) - && cluster_membership_get_last_admitted_incarnation( - episode->target_node_id) + && cluster_membership_get_last_admitted_incarnation(episode->target_node_id) == episode->old_admitted_incarnation - && cluster_replacement_marker_v3_decode( - ReconfigShmem->join_pending_marker, request_target, - &marker) + && cluster_replacement_marker_v3_decode(ReconfigShmem->join_pending_marker, request_target, + &marker) && marker.generation != 0 - && cluster_reconfig_terminal_closed_matches_episode( - &head, &ballot, &marker, episode) + && cluster_reconfig_terminal_closed_matches_episode(&head, &ballot, &marker, episode) && cluster_qvotec_authority_lmon_poll_completion( - replacement_ready_stage.authority_request_seq, - &repeated_completion) - && memcmp(&completion, &repeated_completion, - sizeof(completion)) == 0 + replacement_ready_stage.authority_request_seq, &repeated_completion) + && memcmp(&completion, &repeated_completion, sizeof(completion)) == 0 && pg_atomic_read_u64(&ReconfigShmem->join_marker_request_seq) == replacement_ready_stage.marker_request_seq && pg_atomic_read_u64(&ReconfigShmem->join_marker_completion_seq) == replacement_ready_stage.marker_request_seq - && pg_atomic_read_u32(&ReconfigShmem->join_marker_result) - == CLUSTER_JOIN_MARKER_SUBMIT_ACK + && pg_atomic_read_u32(&ReconfigShmem->join_marker_result) == CLUSTER_JOIN_MARKER_SUBMIT_ACK && ReconfigShmem->join_marker_request_word == request_word && cluster_qvotec_get_status() == CLUSTER_QVOTEC_READY) { memset(&snapshot, 0, sizeof(snapshot)); @@ -4795,14 +4413,12 @@ cluster_reconfig_r4_prerequisite_snapshot(void) snapshot.episode_state_generation = episode->state_generation; snapshot.jcmk_generation = marker.generation; snapshot.request_nonce = episode->request_nonce; - snapshot.old_admitted_incarnation - = episode->old_admitted_incarnation; + snapshot.old_admitted_incarnation = episode->old_admitted_incarnation; snapshot.fresh_incarnation = episode->fresh_incarnation; snapshot.committed_epoch = episode->reserved_or_committed_epoch; snapshot.grammar_fingerprint = episode->grammar_fingerprint; valid = true; - memset(&join_marker_lmon_owner, 0, - sizeof(join_marker_lmon_owner)); + memset(&join_marker_lmon_owner, 0, sizeof(join_marker_lmon_owner)); } out: @@ -4937,54 +4553,40 @@ cluster_reconfig_replacement_admit_preflight(void) uint64 completion_seq; bool ready = false; - if (ReconfigShmem == NULL || cluster_node_id < 0 - || cluster_node_id >= CLUSTER_MAX_NODES) + if (ReconfigShmem == NULL || cluster_node_id < 0 || cluster_node_id >= CLUSTER_MAX_NODES) return false; request_seq = pg_atomic_read_u64(&ReconfigShmem->join_marker_request_seq); - completion_seq - = pg_atomic_read_u64(&ReconfigShmem->join_marker_completion_seq); + completion_seq = pg_atomic_read_u64(&ReconfigShmem->join_marker_completion_seq); if (request_seq == 0 || request_seq != completion_seq - || pg_atomic_read_u32(&ReconfigShmem->join_marker_result) - != CLUSTER_JOIN_MARKER_SUBMIT_ACK) + || pg_atomic_read_u32(&ReconfigShmem->join_marker_result) != CLUSTER_JOIN_MARKER_SUBMIT_ACK) return false; pg_read_barrier(); LWLockAcquire(&ReconfigShmem->lock, LW_SHARED); episode = &ReconfigShmem->replacement_episode; - if (pg_atomic_read_u64(&ReconfigShmem->join_marker_request_seq) - == request_seq - && pg_atomic_read_u64(&ReconfigShmem->join_marker_completion_seq) - == completion_seq - && pg_atomic_read_u32(&ReconfigShmem->join_marker_result) - == CLUSTER_JOIN_MARKER_SUBMIT_ACK + if (pg_atomic_read_u64(&ReconfigShmem->join_marker_request_seq) == request_seq + && pg_atomic_read_u64(&ReconfigShmem->join_marker_completion_seq) == completion_seq + && pg_atomic_read_u32(&ReconfigShmem->join_marker_result) == CLUSTER_JOIN_MARKER_SUBMIT_ACK && cluster_replacement_episode_is_valid(episode) && (episode->phase == CLUSTER_REPLACEMENT_EPISODE_COMMITTED_CLOSED || episode->phase == CLUSTER_REPLACEMENT_EPISODE_POST_EPOCH) - && episode->readiness_flags - == CLUSTER_REPLACEMENT_EPISODE_READINESS_MASK + && episode->readiness_flags == CLUSTER_REPLACEMENT_EPISODE_READINESS_MASK && episode->coordinator_node_id == cluster_node_id - && episode->reserved_or_committed_epoch - == cluster_epoch_get_current() - && cluster_replacement_marker_v3_decode( - ReconfigShmem->join_pending_marker, episode->target_node_id, - &committed) - && committed.phase - == CLUSTER_JCMK_REPLACEMENT_PHASE_COMMITTED_CLOSED + && episode->reserved_or_committed_epoch == cluster_epoch_get_current() + && cluster_replacement_marker_v3_decode(ReconfigShmem->join_pending_marker, + episode->target_node_id, &committed) + && committed.phase == CLUSTER_JCMK_REPLACEMENT_PHASE_COMMITTED_CLOSED && committed.ready_state_generation == 0 && committed.target_node_id == episode->target_node_id - && committed.old_admitted_incarnation - == episode->old_admitted_incarnation + && committed.old_admitted_incarnation == episode->old_admitted_incarnation && committed.fresh_incarnation == episode->fresh_incarnation && committed.baseline_epoch == episode->baseline_epoch - && committed.reserved_or_committed_epoch - == episode->reserved_or_committed_epoch + && committed.reserved_or_committed_epoch == episode->reserved_or_committed_epoch && committed.request_nonce == episode->request_nonce - && memcmp(committed.expected_purge_survivors, - episode->expected_survivors, + && memcmp(committed.expected_purge_survivors, episode->expected_survivors, sizeof(committed.expected_purge_survivors)) == 0 - && committed.grammar_fingerprint - == episode->grammar_fingerprint) + && committed.grammar_fingerprint == episode->grammar_fingerprint) ready = true; LWLockRelease(&ReconfigShmem->lock); return ready; @@ -5007,12 +4609,11 @@ cluster_reconfig_lmon_replacement_admit_tick(void) case CLUSTER_REPLACEMENT_ADMIT_IDLE: if (!cluster_reconfig_replacement_admit_preflight()) return; - submit_status = cluster_qvotec_authority_lmon_submit( - CLUSTER_QVOTEC_MAILBOX_RECOVER_HEAD, zero_value, - &replacement_admit_stage.authority_request_seq); + submit_status + = cluster_qvotec_authority_lmon_submit(CLUSTER_QVOTEC_MAILBOX_RECOVER_HEAD, zero_value, + &replacement_admit_stage.authority_request_seq); if (submit_status == CLUSTER_QVOTEC_MAILBOX_SUBMIT_ACCEPTED) - replacement_admit_stage.phase - = CLUSTER_REPLACEMENT_ADMIT_PRE_HEAD_WAIT; + replacement_admit_stage.phase = CLUSTER_REPLACEMENT_ADMIT_PRE_HEAD_WAIT; return; case CLUSTER_REPLACEMENT_ADMIT_PRE_HEAD_WAIT: @@ -5020,86 +4621,71 @@ cluster_reconfig_lmon_replacement_admit_tick(void) replacement_admit_stage.authority_request_seq, &completion)) return; if (completion.result != CLUSTER_QVOTEC_MAILBOX_CHOSEN - || !cluster_epoch_authority_value_decode( - completion.completion_value, - CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT, - &terminal_head) - || !cluster_epoch_ballot_id_decode( - completion.completion_ballot, &terminal_ballot) + || !cluster_epoch_authority_value_decode(completion.completion_value, + CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT, + &terminal_head) + || !cluster_epoch_ballot_id_decode(completion.completion_ballot, &terminal_ballot) || terminal_ballot.proposer_node_id != cluster_node_id || terminal_ballot.proposer_admitted_incarnation - != cluster_membership_get_last_admitted_incarnation( - cluster_node_id) + != cluster_membership_get_last_admitted_incarnation(cluster_node_id) || !cluster_reconfig_lmon_build_replacement_admitted( &terminal_head, &replacement_admit_stage.admitted_marker)) { cluster_reconfig_reset_replacement_admit_stage(); return; } - memcpy(replacement_admit_stage.pre_head_value, - completion.completion_value, + memcpy(replacement_admit_stage.pre_head_value, completion.completion_value, sizeof(replacement_admit_stage.pre_head_value)); - memcpy(replacement_admit_stage.pre_head_ballot, - completion.completion_ballot, + memcpy(replacement_admit_stage.pre_head_ballot, completion.completion_ballot, sizeof(replacement_admit_stage.pre_head_ballot)); - replacement_admit_stage.phase - = CLUSTER_REPLACEMENT_ADMIT_MARKER_SUBMIT; + replacement_admit_stage.phase = CLUSTER_REPLACEMENT_ADMIT_MARKER_SUBMIT; return; - case CLUSTER_REPLACEMENT_ADMIT_MARKER_SUBMIT: - { - ClusterReplacementCommitMarkerV3 revalidated_marker; + case CLUSTER_REPLACEMENT_ADMIT_MARKER_SUBMIT: { + ClusterReplacementCommitMarkerV3 revalidated_marker; - /* The candidate can wait one or more LMON ticks before its + /* The candidate can wait one or more LMON ticks before its * majority write. Rebuild it from the retained exact terminal * head so a capability/episode/marker drift in that window resets * the stage without writing stale ADMITTED bytes. */ - if (!cluster_epoch_authority_value_decode( - replacement_admit_stage.pre_head_value, - CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT, - &terminal_head) - || !cluster_reconfig_lmon_build_replacement_admitted( - &terminal_head, &revalidated_marker) - || !cluster_replacement_marker_v3_same_image( - &revalidated_marker, - &replacement_admit_stage.admitted_marker)) { - cluster_reconfig_reset_replacement_admit_stage(); - return; - } + if (!cluster_epoch_authority_value_decode(replacement_admit_stage.pre_head_value, + CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT, + &terminal_head) + || !cluster_reconfig_lmon_build_replacement_admitted(&terminal_head, + &revalidated_marker) + || !cluster_replacement_marker_v3_same_image( + &revalidated_marker, &replacement_admit_stage.admitted_marker)) { + cluster_reconfig_reset_replacement_admit_stage(); + return; } + } now = GetCurrentTimestamp(); if (cluster_reconfig_submit_replacement_marker_v3_async( &replacement_admit_stage.marker_async, replacement_admit_stage.admitted_marker.target_node_id, - &replacement_admit_stage.admitted_marker, - CLUSTER_MARKER_KIND_JOIN_COMMITTED, now)) - replacement_admit_stage.phase - = CLUSTER_REPLACEMENT_ADMIT_MARKER_WAIT; + &replacement_admit_stage.admitted_marker, CLUSTER_MARKER_KIND_JOIN_COMMITTED, now)) + replacement_admit_stage.phase = CLUSTER_REPLACEMENT_ADMIT_MARKER_WAIT; return; case CLUSTER_REPLACEMENT_ADMIT_MARKER_WAIT: now = GetCurrentTimestamp(); - marker_poll = cluster_reconfig_poll_join_marker_async( - &replacement_admit_stage.marker_async, now, &marker_result, - &elapsed_us); - if (marker_poll == CLUSTER_MARKER_POLL_PENDING - || marker_poll == CLUSTER_MARKER_POLL_IDLE) + marker_poll = cluster_reconfig_poll_join_marker_async(&replacement_admit_stage.marker_async, + now, &marker_result, &elapsed_us); + if (marker_poll == CLUSTER_MARKER_POLL_PENDING || marker_poll == CLUSTER_MARKER_POLL_IDLE) return; if (marker_poll != CLUSTER_MARKER_POLL_ACKED || marker_result != CLUSTER_JOIN_MARKER_SUBMIT_ACK) { cluster_reconfig_reset_replacement_admit_stage(); return; } - replacement_admit_stage.phase - = CLUSTER_REPLACEMENT_ADMIT_POST_HEAD_SUBMIT; + replacement_admit_stage.phase = CLUSTER_REPLACEMENT_ADMIT_POST_HEAD_SUBMIT; return; case CLUSTER_REPLACEMENT_ADMIT_POST_HEAD_SUBMIT: - submit_status = cluster_qvotec_authority_lmon_submit( - CLUSTER_QVOTEC_MAILBOX_RECOVER_HEAD, zero_value, - &replacement_admit_stage.authority_request_seq); + submit_status + = cluster_qvotec_authority_lmon_submit(CLUSTER_QVOTEC_MAILBOX_RECOVER_HEAD, zero_value, + &replacement_admit_stage.authority_request_seq); if (submit_status == CLUSTER_QVOTEC_MAILBOX_SUBMIT_ACCEPTED) - replacement_admit_stage.phase - = CLUSTER_REPLACEMENT_ADMIT_POST_HEAD_WAIT; + replacement_admit_stage.phase = CLUSTER_REPLACEMENT_ADMIT_POST_HEAD_WAIT; return; case CLUSTER_REPLACEMENT_ADMIT_POST_HEAD_WAIT: @@ -5107,16 +4693,15 @@ cluster_reconfig_lmon_replacement_admit_tick(void) replacement_admit_stage.authority_request_seq, &completion)) return; if (completion.result == CLUSTER_QVOTEC_MAILBOX_CHOSEN - && memcmp(completion.completion_value, - replacement_admit_stage.pre_head_value, - sizeof(completion.completion_value)) == 0 - && memcmp(completion.completion_ballot, - replacement_admit_stage.pre_head_ballot, - sizeof(completion.completion_ballot)) == 0 - && cluster_epoch_authority_value_decode( - completion.completion_value, - CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT, - &terminal_head)) + && memcmp(completion.completion_value, replacement_admit_stage.pre_head_value, + sizeof(completion.completion_value)) + == 0 + && memcmp(completion.completion_ballot, replacement_admit_stage.pre_head_ballot, + sizeof(completion.completion_ballot)) + == 0 + && cluster_epoch_authority_value_decode(completion.completion_value, + CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT, + &terminal_head)) (void)cluster_reconfig_lmon_finalize_replacement_admitted( &terminal_head, &replacement_admit_stage.admitted_marker); cluster_reconfig_reset_replacement_admit_stage(); @@ -5132,19 +4717,16 @@ cluster_reconfig_publish_replacement_member_closed( { bool current_empty; - if (ReconfigShmem == NULL || cluster_node_id < 0 - || cluster_node_id >= CLUSTER_MAX_NODES + if (ReconfigShmem == NULL || cluster_node_id < 0 || cluster_node_id >= CLUSTER_MAX_NODES || !cluster_reconfig_is_local_admitted_replacement(admitted_episode)) return false; LWLockAcquire(&ReconfigShmem->lock, LW_EXCLUSIVE); - current_empty - = cluster_replacement_episode_is_empty(&ReconfigShmem->replacement_episode); + current_empty = cluster_replacement_episode_is_empty(&ReconfigShmem->replacement_episode); if ((!current_empty - && memcmp(&ReconfigShmem->replacement_episode, admitted_episode, - sizeof(*admitted_episode)) != 0) - || clean_departed_test_bit_locked(ReconfigShmem->removed_bitmap, - cluster_node_id) + && memcmp(&ReconfigShmem->replacement_episode, admitted_episode, sizeof(*admitted_episode)) + != 0) + || clean_departed_test_bit_locked(ReconfigShmem->removed_bitmap, cluster_node_id) || cluster_membership_get_state(cluster_node_id) == CLUSTER_MEMBER_REMOVED) { LWLockRelease(&ReconfigShmem->lock); return false; @@ -5157,8 +4739,7 @@ cluster_reconfig_publish_replacement_member_closed( } cluster_write_fence_authority_cache_invalidate(); - memcpy(&ReconfigShmem->replacement_episode, admitted_episode, - sizeof(*admitted_episode)); + memcpy(&ReconfigShmem->replacement_episode, admitted_episode, sizeof(*admitted_episode)); cluster_membership_set_state(cluster_node_id, CLUSTER_MEMBER_MEMBER); ReconfigShmem->self_join_admitted = 0; ReconfigShmem->self_join_failed = 0; @@ -5172,8 +4753,8 @@ cluster_reconfig_publish_replacement_member_closed( * lock then co-samples the live episode, immutable formation tuple, current * epoch and publish proof before changing only MEMBER metadata. */ bool -cluster_reconfig_qvotec_observe_replacement_admitted( - const int *fds, int n_disks, uint64 live_incarnation) +cluster_reconfig_qvotec_observe_replacement_admitted(const int *fds, int n_disks, + uint64 live_incarnation) { uint8 images[CLUSTER_MAX_VOTING_DISKS][CLUSTER_JCMK_REPLACEMENT_BYTES]; ClusterReplacementCommitMarkerV3 admitted; @@ -5187,30 +4768,26 @@ cluster_reconfig_qvotec_observe_replacement_admitted( int d; int node; - if (ReconfigShmem == NULL || fds == NULL || n_disks <= 0 - || n_disks > CLUSTER_MAX_VOTING_DISKS || live_incarnation == 0 - || cluster_node_id < 0 || cluster_node_id >= CLUSTER_MAX_NODES) + if (ReconfigShmem == NULL || fds == NULL || n_disks <= 0 || n_disks > CLUSTER_MAX_VOTING_DISKS + || live_incarnation == 0 || cluster_node_id < 0 || cluster_node_id >= CLUSTER_MAX_NODES) return false; majority = ((uint32)n_disks / 2u) + 1u; for (d = 0; d < n_disks; d++) { uint8 slot[CLUSTER_VOTING_SLOT_BYTES]; memset(slot, 0, sizeof(slot)); - if (cluster_voting_disk_read_join_slot( - fds[d], (uint32)cluster_node_id, slot) - != CLUSTER_VOTING_DISK_IO_OK) + if (cluster_voting_disk_read_join_slot(fds[d], (uint32)cluster_node_id, slot) + != CLUSTER_VOTING_DISK_IO_OK) continue; memcpy(images[n_images++], slot, CLUSTER_JCMK_REPLACEMENT_BYTES); } - if (cluster_replacement_marker_v3_select_majority( - images, n_images, majority, cluster_node_id, &admitted, NULL) - < 0 + if (cluster_replacement_marker_v3_select_majority(images, n_images, majority, cluster_node_id, + &admitted, NULL) + < 0 || admitted.phase != CLUSTER_JCMK_REPLACEMENT_PHASE_ADMITTED - || admitted.fresh_incarnation != live_incarnation - || admitted.ready_state_generation == 0) + || admitted.fresh_incarnation != live_incarnation || admitted.ready_state_generation == 0) return false; - if (!cluster_reconfig_replacement_candidate2_capabilities_current( - &capability_episode)) + if (!cluster_reconfig_replacement_candidate2_capabilities_current(&capability_episode)) return false; LWLockAcquire(&ReconfigShmem->lock, LW_EXCLUSIVE); @@ -5219,43 +4796,35 @@ cluster_reconfig_qvotec_observe_replacement_admitted( || !cluster_replacement_episode_is_valid(episode) || (episode->phase != CLUSTER_REPLACEMENT_EPISODE_COMMITTED_CLOSED && episode->phase != CLUSTER_REPLACEMENT_EPISODE_POST_EPOCH) - || episode->readiness_flags - != CLUSTER_REPLACEMENT_EPISODE_READINESS_MASK + || episode->readiness_flags != CLUSTER_REPLACEMENT_EPISODE_READINESS_MASK || episode->target_node_id != cluster_node_id || episode->state_generation != admitted.ready_state_generation - || episode->old_admitted_incarnation - != admitted.old_admitted_incarnation + || episode->old_admitted_incarnation != admitted.old_admitted_incarnation || episode->fresh_incarnation != admitted.fresh_incarnation || episode->baseline_epoch != admitted.baseline_epoch - || episode->reserved_or_committed_epoch - != admitted.reserved_or_committed_epoch + || episode->reserved_or_committed_epoch != admitted.reserved_or_committed_epoch || episode->reserved_or_committed_epoch != cluster_epoch_get_current() || episode->request_nonce != admitted.request_nonce - || memcmp(episode->expected_survivors, - admitted.expected_purge_survivors, - sizeof(episode->expected_survivors)) != 0 + || memcmp(episode->expected_survivors, admitted.expected_purge_survivors, + sizeof(episode->expected_survivors)) + != 0 || episode->grammar_fingerprint != admitted.grammar_fingerprint - || cluster_membership_get_state(cluster_node_id) - == CLUSTER_MEMBER_REMOVED - || clean_departed_test_bit_locked(ReconfigShmem->removed_bitmap, - cluster_node_id)) + || cluster_membership_get_state(cluster_node_id) == CLUSTER_MEMBER_REMOVED + || clean_departed_test_bit_locked(ReconfigShmem->removed_bitmap, cluster_node_id)) goto out; /* Publish-proven is evaluated over the immutable pre-replacement survivor * bitmap, not caller-relative mutable membership. */ for (node = 0; node < CLUSTER_MAX_NODES; node++) { - bool in_expected - = dead_bitmap_test_bit(episode->expected_survivors, node); + bool in_expected = dead_bitmap_test_bit(episode->expected_survivors, node); if (node == cluster_node_id) continue; if (in_expected) { - if (cluster_conf_lookup_node(node) == NULL - || !cluster_membership_is_member(node)) + if (cluster_conf_lookup_node(node) == NULL || !cluster_membership_is_member(node)) goto out; expected++; - if (cluster_reconfig_get_observed_epoch(node) - >= episode->reserved_or_committed_epoch) + if (cluster_reconfig_get_observed_epoch(node) >= episode->reserved_or_committed_epoch) advanced++; } else if (cluster_membership_is_member(node)) goto out; @@ -5266,8 +4835,7 @@ cluster_reconfig_qvotec_observe_replacement_admitted( cluster_write_fence_authority_cache_invalidate(); episode->phase = CLUSTER_REPLACEMENT_EPISODE_ADMITTED; cluster_membership_set_state(cluster_node_id, CLUSTER_MEMBER_MEMBER); - cluster_membership_record_admitted(cluster_node_id, - admitted.fresh_incarnation); + cluster_membership_record_admitted(cluster_node_id, admitted.fresh_incarnation); ReconfigShmem->self_join_admitted = 0; ReconfigShmem->self_join_failed = 0; ReconfigShmem->self_join_deadline_us = 0; @@ -5279,9 +4847,8 @@ cluster_reconfig_qvotec_observe_replacement_admitted( } bool -cluster_reconfig_open_replacement_admission( - const ClusterReplacementEpisode *expected_episode, - uint32 expected_state_generation) +cluster_reconfig_open_replacement_admission(const ClusterReplacementEpisode *expected_episode, + uint32 expected_state_generation) { if (ReconfigShmem == NULL || expected_state_generation == 0 || !cluster_reconfig_is_local_admitted_replacement(expected_episode) @@ -5289,10 +4856,9 @@ cluster_reconfig_open_replacement_admission( return false; LWLockAcquire(&ReconfigShmem->lock, LW_EXCLUSIVE); - if (ReconfigShmem->replacement_episode.state_generation - != expected_state_generation - || memcmp(&ReconfigShmem->replacement_episode, expected_episode, - sizeof(*expected_episode)) != 0 + if (ReconfigShmem->replacement_episode.state_generation != expected_state_generation + || memcmp(&ReconfigShmem->replacement_episode, expected_episode, sizeof(*expected_episode)) + != 0 || cluster_membership_get_state(cluster_node_id) != CLUSTER_MEMBER_MEMBER || ReconfigShmem->self_join_failed != 0) { LWLockRelease(&ReconfigShmem->lock); @@ -5319,8 +4885,8 @@ cluster_reconfig_note_self_admitted(uint64 admitted_epoch) /* The ordinary v2 callback never opens a replacement episode, including a * nonempty image that fails structural validation. */ LWLockAcquire(&ReconfigShmem->lock, LW_SHARED); - replacement_admitted = cluster_reconfig_has_replacement_episode( - &ReconfigShmem->replacement_episode); + replacement_admitted + = cluster_reconfig_has_replacement_episode(&ReconfigShmem->replacement_episode); LWLockRelease(&ReconfigShmem->lock); if (replacement_admitted) return; @@ -5411,17 +4977,13 @@ cluster_reconfig_note_self_admitted(uint64 admitted_epoch) * still invalidate through this same gate. */ if (!ReconfigShmem->self_join_admitted - || cluster_membership_get_state(cluster_node_id) - != CLUSTER_MEMBER_MEMBER - || cluster_reconfig_has_replacement_episode( - &ReconfigShmem->replacement_episode)) + || cluster_membership_get_state(cluster_node_id) != CLUSTER_MEMBER_MEMBER + || cluster_reconfig_has_replacement_episode(&ReconfigShmem->replacement_episode)) cluster_write_fence_authority_cache_invalidate(); /* Close the check/use race with a concurrent replacement publisher. */ - if (cluster_reconfig_has_replacement_episode( - &ReconfigShmem->replacement_episode)) { + if (cluster_reconfig_has_replacement_episode(&ReconfigShmem->replacement_episode)) { ReconfigShmem->self_join_admitted = 0; - if (cluster_reconfig_is_local_admitted_replacement( - &ReconfigShmem->replacement_episode)) + if (cluster_reconfig_is_local_admitted_replacement(&ReconfigShmem->replacement_episode)) cluster_membership_set_state(cluster_node_id, CLUSTER_MEMBER_MEMBER); LWLockRelease(&ReconfigShmem->lock); return; @@ -5435,8 +4997,7 @@ cluster_reconfig_note_self_admitted(uint64 admitted_epoch) * (the witness comment's "LMON publishes the exact admitted-incarnation * floor" transient). Monotonic-max: a stale lower value never regresses. */ - cluster_membership_record_admitted(cluster_node_id, - cluster_qvotec_get_self_incarnation()); + cluster_membership_record_admitted(cluster_node_id, cluster_qvotec_get_self_incarnation()); cluster_membership_set_state(cluster_node_id, CLUSTER_MEMBER_MEMBER); ReconfigShmem->self_join_admitted = 1; ReconfigShmem->self_join_failed = 0; @@ -5492,8 +5053,7 @@ cluster_reconfig_observed_peer_epoch_current(int32 node_id, uint64 *out_epoch) if (out_epoch != NULL) *out_epoch = 0; - if (ReconfigShmem == NULL || node_id < 0 - || node_id >= CLUSTER_MAX_NODES || out_epoch == NULL) + if (ReconfigShmem == NULL || node_id < 0 || node_id >= CLUSTER_MAX_NODES || out_epoch == NULL) return false; for (attempt = 0; attempt < 8; attempt++) { @@ -5504,22 +5064,16 @@ cluster_reconfig_observed_peer_epoch_current(int32 node_id, uint64 *out_epoch) uint64 seq_after; uint64 seq_before; - seq_before = pg_atomic_read_u64( - &ReconfigShmem->observed_bootstrap_seq); + seq_before = pg_atomic_read_u64(&ReconfigShmem->observed_bootstrap_seq); if ((seq_before & UINT64_C(1)) != 0) continue; pg_read_barrier(); - incarnation = pg_atomic_read_u64( - &ReconfigShmem->observed_incarnation[node_id]); - generation = pg_atomic_read_u64( - &ReconfigShmem->observed_generation[node_id]); - epoch = pg_atomic_read_u64( - &ReconfigShmem->observed_epoch[node_id]); - fresh = pg_atomic_read_u64( - &ReconfigShmem->observed_fresh_alive[node_id]); + incarnation = pg_atomic_read_u64(&ReconfigShmem->observed_incarnation[node_id]); + generation = pg_atomic_read_u64(&ReconfigShmem->observed_generation[node_id]); + epoch = pg_atomic_read_u64(&ReconfigShmem->observed_epoch[node_id]); + fresh = pg_atomic_read_u64(&ReconfigShmem->observed_fresh_alive[node_id]); pg_read_barrier(); - seq_after = pg_atomic_read_u64( - &ReconfigShmem->observed_bootstrap_seq); + seq_after = pg_atomic_read_u64(&ReconfigShmem->observed_bootstrap_seq); if (seq_after != seq_before) continue; if (incarnation == 0 || generation == 0 || fresh == 0) @@ -5539,16 +5093,14 @@ typedef struct ClusterEpoch0LateFounderPeer { /* Capture one admitted peer from one stable QVOTEC publication window. The * no-PGPROC phase-3 caller must never queue on this lock. */ static bool -cluster_reconfig_epoch0_peer_capture_current( - int32 node_id, ClusterEpoch0LateFounderPeer *out) +cluster_reconfig_epoch0_peer_capture_current(int32 node_id, ClusterEpoch0LateFounderPeer *out) { bool current = false; int attempt; memset(out, 0, sizeof(*out)); - if (ReconfigShmem == NULL || node_id < 0 - || node_id >= CLUSTER_MAX_NODES || node_id == cluster_node_id - || cluster_conf_lookup_node(node_id) == NULL) + if (ReconfigShmem == NULL || node_id < 0 || node_id >= CLUSTER_MAX_NODES + || node_id == cluster_node_id || cluster_conf_lookup_node(node_id) == NULL) return false; if (MyProc == NULL) { if (!LWLockConditionalAcquire(&ReconfigShmem->lock, LW_SHARED)) @@ -5564,28 +5116,20 @@ cluster_reconfig_epoch0_peer_capture_current( uint64 seq_after; uint64 seq_before; - seq_before = pg_atomic_read_u64( - &ReconfigShmem->observed_bootstrap_seq); + seq_before = pg_atomic_read_u64(&ReconfigShmem->observed_bootstrap_seq); if ((seq_before & UINT64_C(1)) != 0) continue; pg_read_barrier(); - incarnation = pg_atomic_read_u64( - &ReconfigShmem->observed_incarnation[node_id]); - generation = pg_atomic_read_u64( - &ReconfigShmem->observed_generation[node_id]); - epoch = pg_atomic_read_u64( - &ReconfigShmem->observed_epoch[node_id]); - fresh = pg_atomic_read_u64( - &ReconfigShmem->observed_fresh_alive[node_id]); + incarnation = pg_atomic_read_u64(&ReconfigShmem->observed_incarnation[node_id]); + generation = pg_atomic_read_u64(&ReconfigShmem->observed_generation[node_id]); + epoch = pg_atomic_read_u64(&ReconfigShmem->observed_epoch[node_id]); + fresh = pg_atomic_read_u64(&ReconfigShmem->observed_fresh_alive[node_id]); current = incarnation != 0 && generation != 0 && fresh != 0 - && epoch == CLUSTER_EPOCH_INITIAL - && cluster_membership_get_state(node_id) - == CLUSTER_MEMBER_MEMBER - && cluster_membership_get_last_admitted_incarnation(node_id) - == incarnation; + && epoch == CLUSTER_EPOCH_INITIAL + && cluster_membership_get_state(node_id) == CLUSTER_MEMBER_MEMBER + && cluster_membership_get_last_admitted_incarnation(node_id) == incarnation; pg_read_barrier(); - seq_after = pg_atomic_read_u64( - &ReconfigShmem->observed_bootstrap_seq); + seq_after = pg_atomic_read_u64(&ReconfigShmem->observed_bootstrap_seq); if (seq_after != seq_before) { current = false; continue; @@ -5603,9 +5147,8 @@ cluster_reconfig_epoch0_peer_capture_current( } static bool -cluster_reconfig_epoch0_peer_active_matches( - const ClusterEpoch0LateFounderPeer *peer, - const ClusterWalStateSlot *slot) +cluster_reconfig_epoch0_peer_active_matches(const ClusterEpoch0LateFounderPeer *peer, + const ClusterWalStateSlot *slot) { uint16 thread_id; @@ -5613,12 +5156,10 @@ cluster_reconfig_epoch0_peer_active_matches( || peer->incarnation > (uint64)PG_INT64_MAX) return false; thread_id = cluster_wal_thread_id_for(true, peer->node_id); - return thread_id != XLP_THREAD_ID_LEGACY - && slot->thread_id == thread_id - && slot->node_id == peer->node_id - && slot->state == CLUSTER_WAL_SLOT_STATE_ACTIVE - && slot->started_at >= (int64)peer->incarnation - && slot->last_updated >= slot->started_at; + return thread_id != XLP_THREAD_ID_LEGACY && slot->thread_id == thread_id + && slot->node_id == peer->node_id && slot->state == CLUSTER_WAL_SLOT_STATE_ACTIVE + && slot->started_at >= (int64)peer->incarnation + && slot->last_updated >= slot->started_at; } /* @@ -5638,12 +5179,10 @@ cluster_reconfig_epoch0_late_founder_evidence_current(void) { int i; - if (ReconfigShmem == NULL || !cluster_online_join - || cluster_node_id < 0 || cluster_node_id >= CLUSTER_MAX_NODES - || cluster_epoch_get_current() != CLUSTER_EPOCH_INITIAL - || !cluster_qvotec_in_quorum() - || cluster_xid_stripe_disk_state() - != CLUSTER_XID_STRIPE_DISK_PUBLISHED) + if (ReconfigShmem == NULL || !cluster_online_join || cluster_node_id < 0 + || cluster_node_id >= CLUSTER_MAX_NODES + || cluster_epoch_get_current() != CLUSTER_EPOCH_INITIAL || !cluster_qvotec_in_quorum() + || cluster_xid_stripe_disk_state() != CLUSTER_XID_STRIPE_DISK_PUBLISHED) return false; for (i = 0; i < CLUSTER_MAX_NODES; i++) { @@ -5656,20 +5195,15 @@ cluster_reconfig_epoch0_late_founder_evidence_current(void) if (!cluster_reconfig_epoch0_peer_capture_current(i, &before)) continue; thread_id = cluster_wal_thread_id_for(true, i); - if (cluster_wal_state_read_slot(thread_id, &wal_before) - != CLUSTER_WAL_SLOT_OK - || !cluster_reconfig_epoch0_peer_active_matches( - &before, &wal_before)) + if (cluster_wal_state_read_slot(thread_id, &wal_before) != CLUSTER_WAL_SLOT_OK + || !cluster_reconfig_epoch0_peer_active_matches(&before, &wal_before)) continue; if (!cluster_reconfig_epoch0_peer_capture_current(i, &after) || memcmp(&before, &after, sizeof(before)) != 0 - || cluster_epoch_get_current() != CLUSTER_EPOCH_INITIAL - || !cluster_qvotec_in_quorum() - || cluster_xid_stripe_disk_state() - != CLUSTER_XID_STRIPE_DISK_PUBLISHED) + || cluster_epoch_get_current() != CLUSTER_EPOCH_INITIAL || !cluster_qvotec_in_quorum() + || cluster_xid_stripe_disk_state() != CLUSTER_XID_STRIPE_DISK_PUBLISHED) continue; - if (cluster_wal_state_read_slot(thread_id, &wal_after) - != CLUSTER_WAL_SLOT_OK + if (cluster_wal_state_read_slot(thread_id, &wal_after) != CLUSTER_WAL_SLOT_OK || memcmp(&wal_before, &wal_after, sizeof(wal_before)) != 0) continue; return true; @@ -5693,51 +5227,46 @@ cluster_reconfig_handoff_lock_acquire(LWLockMode mode) * the locked transition; a changed sample leaves JOINING write-closed and is * retried from current evidence rather than rolling membership back. */ static bool -cluster_reconfig_pre_publish_handoff_external_current( - uint64 expected_self_incarnation, uint64 expected_predecessor_floor, - bool require_recovery_complete) -{ - return ReconfigShmem != NULL && cluster_online_join - && cluster_node_id >= 0 && cluster_node_id < CLUSTER_MAX_NODES - && expected_self_incarnation != 0 - && (expected_predecessor_floor == 0 - || expected_predecessor_floor < expected_self_incarnation) - && cluster_authority_handoff_identity_current( - expected_self_incarnation, expected_predecessor_floor) - && cluster_authority_readiness_managed() - && cluster_authority_readiness_get() == CLUSTER_AUTHORITY_OFF - && cluster_epoch_get_current() == CLUSTER_EPOCH_INITIAL - && (!require_recovery_complete || !RecoveryInProgress()) - && !cluster_clean_leave_in_progress() - && !cluster_reconfig_is_removed_unlocked(cluster_node_id) - && cluster_qvotec_get_self_incarnation() - == expected_self_incarnation - && cluster_membership_get_last_admitted_incarnation(cluster_node_id) - == expected_predecessor_floor - && cluster_reconfig_epoch0_late_founder_evidence_current(); +cluster_reconfig_pre_publish_handoff_external_current(uint64 expected_self_incarnation, + uint64 expected_predecessor_floor, + bool require_recovery_complete) +{ + return ReconfigShmem != NULL && cluster_online_join && cluster_node_id >= 0 + && cluster_node_id < CLUSTER_MAX_NODES && expected_self_incarnation != 0 + && (expected_predecessor_floor == 0 + || expected_predecessor_floor < expected_self_incarnation) + && cluster_authority_handoff_identity_current(expected_self_incarnation, + expected_predecessor_floor) + && cluster_authority_readiness_managed() + && cluster_authority_readiness_get() == CLUSTER_AUTHORITY_OFF + && cluster_epoch_get_current() == CLUSTER_EPOCH_INITIAL + && (!require_recovery_complete || !RecoveryInProgress()) + && !cluster_clean_leave_in_progress() + && !cluster_reconfig_is_removed_unlocked(cluster_node_id) + && cluster_qvotec_get_self_incarnation() == expected_self_incarnation + && cluster_membership_get_last_admitted_incarnation(cluster_node_id) + == expected_predecessor_floor + && cluster_reconfig_epoch0_late_founder_evidence_current(); } static bool -cluster_reconfig_pre_publish_handoff_locked_current( - uint64 expected_self_incarnation, uint64 expected_predecessor_floor, - bool allow_member) +cluster_reconfig_pre_publish_handoff_locked_current(uint64 expected_self_incarnation, + uint64 expected_predecessor_floor, + bool allow_member) { ClusterMembershipState membership; membership = cluster_membership_get_state(cluster_node_id); - return ReconfigShmem->self_join_admitted == 0 - && ReconfigShmem->self_join_failed == 0 - && ReconfigShmem->self_join_deadline_us == 0 - && cluster_replacement_episode_is_empty( - &ReconfigShmem->replacement_episode) - && !clean_departed_test_bit_locked(ReconfigShmem->removed_bitmap, - cluster_node_id) - && cluster_membership_get_last_admitted_incarnation(cluster_node_id) - == expected_predecessor_floor - && (expected_predecessor_floor == 0 - || expected_predecessor_floor < expected_self_incarnation) - && (membership == CLUSTER_MEMBER_JOINING - || (allow_member && membership == CLUSTER_MEMBER_MEMBER)); + return ReconfigShmem->self_join_admitted == 0 && ReconfigShmem->self_join_failed == 0 + && ReconfigShmem->self_join_deadline_us == 0 + && cluster_replacement_episode_is_empty(&ReconfigShmem->replacement_episode) + && !clean_departed_test_bit_locked(ReconfigShmem->removed_bitmap, cluster_node_id) + && cluster_membership_get_last_admitted_incarnation(cluster_node_id) + == expected_predecessor_floor + && (expected_predecessor_floor == 0 + || expected_predecessor_floor < expected_self_incarnation) + && (membership == CLUSTER_MEMBER_JOINING + || (allow_member && membership == CLUSTER_MEMBER_MEMBER)); } /* @@ -5747,28 +5276,25 @@ cluster_reconfig_pre_publish_handoff_locked_current( * idempotent success; no deadline, admission bit, or auxiliary latch is reset. */ bool -cluster_reconfig_stage_pre_publish_join_handoff( - uint64 expected_self_incarnation, uint64 expected_predecessor_floor) +cluster_reconfig_stage_pre_publish_join_handoff(uint64 expected_self_incarnation, + uint64 expected_predecessor_floor) { bool exact; - if (!cluster_reconfig_pre_publish_handoff_external_current( - expected_self_incarnation, expected_predecessor_floor, false)) + if (!cluster_reconfig_pre_publish_handoff_external_current(expected_self_incarnation, + expected_predecessor_floor, false)) return false; if (!cluster_reconfig_handoff_lock_acquire(LW_EXCLUSIVE)) return false; - exact = cluster_reconfig_pre_publish_handoff_locked_current( - expected_self_incarnation, expected_predecessor_floor, true); - if (exact - && cluster_membership_get_state(cluster_node_id) - == CLUSTER_MEMBER_MEMBER) - cluster_membership_set_state(cluster_node_id, - CLUSTER_MEMBER_JOINING); + exact = cluster_reconfig_pre_publish_handoff_locked_current(expected_self_incarnation, + expected_predecessor_floor, true); + if (exact && cluster_membership_get_state(cluster_node_id) == CLUSTER_MEMBER_MEMBER) + cluster_membership_set_state(cluster_node_id, CLUSTER_MEMBER_JOINING); LWLockRelease(&ReconfigShmem->lock); if (!exact) return false; - return cluster_reconfig_pre_publish_handoff_external_current( - expected_self_incarnation, expected_predecessor_floor, false); + return cluster_reconfig_pre_publish_handoff_external_current(expected_self_incarnation, + expected_predecessor_floor, false); } /* Read-only LMON classifier for the staged tuple. Both external evidence and @@ -5784,20 +5310,19 @@ cluster_reconfig_pre_publish_join_handoff_current(void) if (ReconfigShmem == NULL) return false; expected_self_incarnation = cluster_qvotec_get_self_incarnation(); - expected_predecessor_floor - = cluster_membership_get_last_admitted_incarnation(cluster_node_id); - if (!cluster_reconfig_pre_publish_handoff_external_current( - expected_self_incarnation, expected_predecessor_floor, true)) + expected_predecessor_floor = cluster_membership_get_last_admitted_incarnation(cluster_node_id); + if (!cluster_reconfig_pre_publish_handoff_external_current(expected_self_incarnation, + expected_predecessor_floor, true)) return false; if (!cluster_reconfig_handoff_lock_acquire(LW_SHARED)) return false; - exact = cluster_reconfig_pre_publish_handoff_locked_current( - expected_self_incarnation, expected_predecessor_floor, false); + exact = cluster_reconfig_pre_publish_handoff_locked_current(expected_self_incarnation, + expected_predecessor_floor, false); LWLockRelease(&ReconfigShmem->lock); if (!exact) return false; - return cluster_reconfig_pre_publish_handoff_external_current( - expected_self_incarnation, expected_predecessor_floor, true); + return cluster_reconfig_pre_publish_handoff_external_current(expected_self_incarnation, + expected_predecessor_floor, true); } /* @@ -5985,16 +5510,14 @@ cluster_reconfig_self_is_stripe_seed_candidate(void) * floor, but it never publishes MEMBER until the current formation and the * stored floor are byte-for-byte equal. */ static bool -cluster_reconfig_publish_self_current_floor_locked(int32 self_id, - uint64 sampled_incarnation) +cluster_reconfig_publish_self_current_floor_locked(int32 self_id, uint64 sampled_incarnation) { uint64 current_incarnation; if (sampled_incarnation == 0) return false; current_incarnation = cluster_qvotec_get_self_incarnation(); - if (current_incarnation == 0 - || current_incarnation != sampled_incarnation) + if (current_incarnation == 0 || current_incarnation != sampled_incarnation) return false; /* A steady LMON tick must not destroy the live-formation proof that phase 3 @@ -6002,15 +5525,13 @@ cluster_reconfig_publish_self_current_floor_locked(int32 self_id, * mutators below already invalidate on changed bytes; retain the leading * invalidation only when this compound edge will actually change its floor * or state. */ - if (cluster_membership_get_last_admitted_incarnation(self_id) - != sampled_incarnation + if (cluster_membership_get_last_admitted_incarnation(self_id) != sampled_incarnation || cluster_membership_get_state(self_id) != CLUSTER_MEMBER_MEMBER) cluster_write_fence_authority_cache_invalidate(); cluster_membership_record_admitted(self_id, sampled_incarnation); current_incarnation = cluster_qvotec_get_self_incarnation(); if (current_incarnation != sampled_incarnation - || cluster_membership_get_last_admitted_incarnation(self_id) - != sampled_incarnation) + || cluster_membership_get_last_admitted_incarnation(self_id) != sampled_incarnation) return false; cluster_membership_set_state(self_id, CLUSTER_MEMBER_MEMBER); @@ -6027,8 +5548,7 @@ cluster_reconfig_joiner_self_tick(void) bool in_quorum; uint64 now_us; - if (ReconfigShmem == NULL - || (!cluster_online_join && !offpath_fast_rejoin_active_local)) + if (ReconfigShmem == NULL || (!cluster_online_join && !offpath_fast_rejoin_active_local)) return; if (cluster_node_id < 0 || cluster_node_id >= CLUSTER_MAX_NODES) return; @@ -6047,8 +5567,8 @@ cluster_reconfig_joiner_self_tick(void) /* spec-5.15A: ordinary bootstrap/rejoin classification has no authority to * open or time out an exact replacement ADMITTED episode. */ LWLockAcquire(&ReconfigShmem->lock, LW_SHARED); - replacement_admitted = cluster_reconfig_has_replacement_episode( - &ReconfigShmem->replacement_episode); + replacement_admitted + = cluster_reconfig_has_replacement_episode(&ReconfigShmem->replacement_episode); LWLockRelease(&ReconfigShmem->lock); if (replacement_admitted) return; @@ -6060,12 +5580,10 @@ cluster_reconfig_joiner_self_tick(void) * phase-3 staged tuple: current self incarnation/floor, zero admission/ * failure/deadline, no competing membership episode, recovery complete, * and the same current epoch-0 late-founder evidence. */ - managed_join_readonly_pivot - = cluster_reconfig_pre_publish_join_handoff_current(); + managed_join_readonly_pivot = cluster_reconfig_pre_publish_join_handoff_current(); epoch0_late_founder = !RecoveryInProgress() - && (!cluster_authority_readiness_managed() - || managed_join_readonly_pivot) - && cluster_reconfig_epoch0_late_founder_evidence_current(); + && (!cluster_authority_readiness_managed() || managed_join_readonly_pivot) + && cluster_reconfig_epoch0_late_founder_evidence_current(); /* * Catch up to the cluster epoch observed on the durable voting disk (quorum- @@ -6109,8 +5627,7 @@ cluster_reconfig_joiner_self_tick(void) * pending via cluster_reconfig_join_in_progress). */ if (!joiner_gate_decided && !clean_leave_active) { - if (offpath_fast_rejoin_active_local - || cluster_reconfig_cluster_already_running() + if (offpath_fast_rejoin_active_local || cluster_reconfig_cluster_already_running() || epoch0_late_founder) { /* REJOINER: a running cluster exists. Close the gate and classify * the ordinary join. Its convergence deadline remains unowned until @@ -6136,8 +5653,7 @@ cluster_reconfig_joiner_self_tick(void) ReconfigShmem->self_join_admitted = 0; ReconfigShmem->self_join_failed = 0; ReconfigShmem->self_join_deadline_us = 0; - cluster_membership_set_state(cluster_node_id, - CLUSTER_MEMBER_JOINING); + cluster_membership_set_state(cluster_node_id, CLUSTER_MEMBER_JOINING); LWLockRelease(&ReconfigShmem->lock); } ereport(LOG, @@ -6198,11 +5714,10 @@ cluster_reconfig_joiner_self_tick(void) ReconfigShmem->self_join_failed = 0; ReconfigShmem->self_join_deadline_us = 0; if (sv != CLUSTER_XID_STRIPE_JOIN_HOLD - || !cluster_reconfig_publish_self_current_floor_locked( - cluster_node_id, control_incarnation)) { + || !cluster_reconfig_publish_self_current_floor_locked(cluster_node_id, + control_incarnation)) { cluster_write_fence_authority_cache_invalidate(); - cluster_membership_set_state( - cluster_node_id, CLUSTER_MEMBER_JOINING); + cluster_membership_set_state(cluster_node_id, CLUSTER_MEMBER_JOINING); } LWLockRelease(&ReconfigShmem->lock); return; @@ -6213,14 +5728,13 @@ cluster_reconfig_joiner_self_tick(void) * zero/drifting incarnation keeps this decision retryable. */ bootstrap_incarnation = cluster_qvotec_get_self_incarnation(); LWLockAcquire(&ReconfigShmem->lock, LW_EXCLUSIVE); - if (!cluster_reconfig_publish_self_current_floor_locked( - cluster_node_id, bootstrap_incarnation)) { + if (!cluster_reconfig_publish_self_current_floor_locked(cluster_node_id, + bootstrap_incarnation)) { cluster_write_fence_authority_cache_invalidate(); ReconfigShmem->self_join_admitted = 0; ReconfigShmem->self_join_failed = 0; ReconfigShmem->self_join_deadline_us = 0; - cluster_membership_set_state(cluster_node_id, - CLUSTER_MEMBER_JOINING); + cluster_membership_set_state(cluster_node_id, CLUSTER_MEMBER_JOINING); LWLockRelease(&ReconfigShmem->lock); return; } @@ -6267,24 +5781,19 @@ cluster_reconfig_joiner_self_tick(void) LWLockAcquire(&ReconfigShmem->lock, LW_EXCLUSIVE); cluster_write_fence_authority_cache_invalidate(); { - bool preserve; - uint64 self_incarnation; + bool preserve; + uint64 self_incarnation; self_incarnation = cluster_qvotec_get_self_incarnation(); preserve = ReconfigShmem->self_join_admitted != 0 - && cluster_external_fence_runtime_active() - && cluster_qvotec_in_quorum() - && cluster_membership_get_state(cluster_node_id) - == CLUSTER_MEMBER_MEMBER - && cluster_membership_get_last_admitted_incarnation( - cluster_node_id) != 0 - && cluster_membership_get_last_admitted_incarnation( - cluster_node_id) == self_incarnation; - if (!preserve) - { + && cluster_external_fence_runtime_active() && cluster_qvotec_in_quorum() + && cluster_membership_get_state(cluster_node_id) == CLUSTER_MEMBER_MEMBER + && cluster_membership_get_last_admitted_incarnation(cluster_node_id) != 0 + && cluster_membership_get_last_admitted_incarnation(cluster_node_id) + == self_incarnation; + if (!preserve) { ReconfigShmem->self_join_admitted = 0; - cluster_membership_set_state(cluster_node_id, - CLUSTER_MEMBER_JOINING); + cluster_membership_set_state(cluster_node_id, CLUSTER_MEMBER_JOINING); } } LWLockRelease(&ReconfigShmem->lock); @@ -6310,41 +5819,34 @@ cluster_reconfig_joiner_self_tick(void) */ if (!clean_leave_active && !ReconfigShmem->self_join_admitted && !ReconfigShmem->self_join_failed) { - ClusterXidStripeJoinProgress progress - = cluster_xid_stripe_join_progress(false); + ClusterXidStripeJoinProgress progress = cluster_xid_stripe_join_progress(false); if (progress == STRIPE_JOIN_REFUSE) { static bool stripe_join_refuse_logged = false; LWLockAcquire(&ReconfigShmem->lock, LW_EXCLUSIVE); - if (!ReconfigShmem->self_join_admitted - && !ReconfigShmem->self_join_failed) { + if (!ReconfigShmem->self_join_admitted && !ReconfigShmem->self_join_failed) { cluster_write_fence_authority_cache_invalidate(); ReconfigShmem->self_join_failed = 1; ReconfigShmem->self_join_deadline_us = 0; - cluster_membership_set_state(cluster_node_id, - CLUSTER_MEMBER_REJECTED); + cluster_membership_set_state(cluster_node_id, CLUSTER_MEMBER_REJECTED); } LWLockRelease(&ReconfigShmem->lock); if (!stripe_join_refuse_logged) { stripe_join_refuse_logged = true; - ereport(LOG, - (errcode(ERRCODE_CLUSTER_XID_STRIPE_JOIN_MISMATCH), - errmsg("cluster xid stripe: refusing ordinary join of node %d — " - "stripe prerequisite mismatch (SQLSTATE 53RB1)", - cluster_node_id))); + ereport(LOG, (errcode(ERRCODE_CLUSTER_XID_STRIPE_JOIN_MISMATCH), + errmsg("cluster xid stripe: refusing ordinary join of node %d — " + "stripe prerequisite mismatch (SQLSTATE 53RB1)", + cluster_node_id))); } return; } - if (progress == STRIPE_JOIN_CLAIM_OWNED - || progress == STRIPE_JOIN_PROCEED) { + if (progress == STRIPE_JOIN_CLAIM_OWNED || progress == STRIPE_JOIN_PROCEED) { LWLockAcquire(&ReconfigShmem->lock, LW_EXCLUSIVE); - if (!ReconfigShmem->self_join_admitted - && !ReconfigShmem->self_join_failed + if (!ReconfigShmem->self_join_admitted && !ReconfigShmem->self_join_failed && ReconfigShmem->self_join_deadline_us == 0) ReconfigShmem->self_join_deadline_us - = now_us - + (uint64)cluster_join_convergence_timeout_ms * 1000ULL; + = now_us + (uint64)cluster_join_convergence_timeout_ms * 1000ULL; LWLockRelease(&ReconfigShmem->lock); } } @@ -6402,8 +5904,7 @@ cluster_reconfig_joiner_self_tick(void) */ /* Forward: three-state cold-formation observation window (defined below * with the cold-formation state machine). */ -typedef enum ClusterColdFormationVerdict -{ +typedef enum ClusterColdFormationVerdict { CLUSTER_COLD_FORMATION_PENDING = 0, /* no survivor seen; quorum not yet fresh */ CLUSTER_COLD_FORMATION_SURVIVOR, /* a fresh slot is past INITIAL: never form */ CLUSTER_COLD_FORMATION_COBOOT /* quorum fresh, no survivor: window passed */ @@ -6412,8 +5913,8 @@ typedef enum ClusterColdFormationVerdict /* 连续满足观察窗的 tick 数(~300 ms at the 100 ms LMON tick)。 */ #define CLUSTER_COLD_FORMATION_WINDOW_TICKS 3 -static ClusterColdFormationVerdict cluster_reconfig_cold_formation_window( - uint64 *out_coboot_lo, uint64 *out_coboot_hi); +static ClusterColdFormationVerdict cluster_reconfig_cold_formation_window(uint64 *out_coboot_lo, + uint64 *out_coboot_hi); /* * RF-ROOT P9 verification / cold-formation cold-formation ruling: true only @@ -6428,17 +5929,16 @@ cold_formation_survivor_verdict(void) { static uint64 survivor_ticks = 0; - switch (cluster_reconfig_cold_formation_window(NULL, NULL)) - { - case CLUSTER_COLD_FORMATION_SURVIVOR: - if (++survivor_ticks >= CLUSTER_COLD_FORMATION_WINDOW_TICKS) - return true; - return false; - case CLUSTER_COLD_FORMATION_COBOOT: - case CLUSTER_COLD_FORMATION_PENDING: - default: - survivor_ticks = 0; - return false; + switch (cluster_reconfig_cold_formation_window(NULL, NULL)) { + case CLUSTER_COLD_FORMATION_SURVIVOR: + if (++survivor_ticks >= CLUSTER_COLD_FORMATION_WINDOW_TICKS) + return true; + return false; + case CLUSTER_COLD_FORMATION_COBOOT: + case CLUSTER_COLD_FORMATION_PENDING: + default: + survivor_ticks = 0; + return false; } } @@ -6456,15 +5956,13 @@ cluster_reconfig_offpath_rejoin_tick(void) * admission callback opened the existing gate and every survivor's * existing JOIN re-declare barrier is complete. Until both are true, * the epoch-independent boot barrier remains the read fence. */ - if (offpath_fast_rejoin_active_local - && ReconfigShmem->self_join_admitted + if (offpath_fast_rejoin_active_local && ReconfigShmem->self_join_admitted && cluster_grd_join_view_rebuilt()) { cluster_grd_set_offpath_boot_decided(); offpath_fast_rejoin_active_local = false; - ereport(LOG, - (errmsg("cluster membership: node %d shared-CF fast-rejoin " - "admission and re-declare complete — boot fence lifted", - cluster_node_id))); + ereport(LOG, (errmsg("cluster membership: node %d shared-CF fast-rejoin " + "admission and re-declare complete — boot fence lifted", + cluster_node_id))); } return; /* once per incarnation (LMON-local) */ } @@ -6498,10 +5996,9 @@ cluster_reconfig_offpath_rejoin_tick(void) if (cold_formation_state.admission_done) { cluster_grd_set_offpath_boot_decided(); offpath_decided_local = true; - ereport(LOG, - (errmsg("cluster membership: node %d cold-formation admitted " - "(online_join=off) — no re-declare fence armed", - cluster_node_id))); + ereport(LOG, (errmsg("cluster membership: node %d cold-formation admitted " + "(online_join=off) — no re-declare fence armed", + cluster_node_id))); return; } @@ -6522,9 +6019,7 @@ cluster_reconfig_offpath_rejoin_tick(void) * (prior_unclean_death), so that path still takes the REJOIN arm * below with the full self-fence + re-declare barrier. */ - if (cluster_reconfig_cluster_already_running() - && !cluster_qvotec_prior_unclean_death()) - { + if (cluster_reconfig_cluster_already_running() && !cluster_qvotec_prior_unclean_death()) { /* * RF-ROOT P9 verification / cold-formation cold-formation ruling: * the clean-reopen self-admission must NOT fire while a cold @@ -6551,17 +6046,18 @@ cluster_reconfig_offpath_rejoin_tick(void) * in 53R61. Stay UNDECIDED (fail-closed, no fence) and retry * next tick. */ - if (cold_formation_survivor_verdict()) - { + if (cold_formation_survivor_verdict()) { cluster_grd_set_offpath_boot_decided(); offpath_decided_local = true; - ereport(LOG, - (errmsg("cluster membership: node %d clean reopen detected (cluster.online_join=off) " - "— thread clean-closed, no re-declare fence armed", - cluster_node_id))); + ereport( + LOG, + (errmsg( + "cluster membership: node %d clean reopen detected (cluster.online_join=off) " + "— thread clean-closed, no re-declare fence armed", + cluster_node_id))); return; } - return; /* clean-reopen candidate: never crash-rejoin */ + return; /* clean-reopen candidate: never crash-rejoin */ } /* @@ -6684,14 +6180,13 @@ cluster_reconfig_lmon_tick(void) * remain live before OPEN, but runtime replacement/readmission is serving * work. A cluster that entered the managed startup lifecycle may not drive * those actions from STARTING or RECOVERY_AUTHORITY_READY. */ - ordinary_actions_allowed - = !cluster_authority_readiness_managed() - || cluster_authority_serving_rebind_lmon() - /* RF-ROOT P6 (L5 shutdown handoff): the committed LEAVER re-binds + ordinary_actions_allowed = !cluster_authority_readiness_managed() + || cluster_authority_serving_rebind_lmon() + /* RF-ROOT P6 (L5 shutdown handoff): the committed LEAVER re-binds * its serving authority from its own applied CLEAN_LEAVE evidence * (no local episode closes for its own departure), so its shutdown * checkpoint / THREAD_CLEAN_CLOSE CF acquires keep working. */ - || cluster_authority_serving_rebind_leaver(); + || cluster_authority_serving_rebind_leaver(); /* * RF-ROOT P6 (t/243 cast wedge + L5 shutdown handoff): a shutdown- @@ -6706,15 +6201,12 @@ cluster_reconfig_lmon_tick(void) */ if (ShutdownRequestPending || cluster_lmon_reconfig_suppressed()) return; - offpath_fast_rejoin_actions - = cluster_reconfig_fast_rejoin_actions_snapshot(); + offpath_fast_rejoin_actions = cluster_reconfig_fast_rejoin_actions_snapshot(); fast_rejoin_control_target - = cluster_reconfig_fast_rejoin_control_snapshot( - &fast_rejoin_control_incarnation); + = cluster_reconfig_fast_rejoin_control_snapshot(&fast_rejoin_control_incarnation); fast_rejoin_control_actions = fast_rejoin_control_target >= 0; runtime_join_allowed = cluster_online_join || offpath_fast_rejoin_actions; - external_rejoin_active - = ordinary_actions_allowed && cluster_external_fence_runtime_active(); + external_rejoin_active = ordinary_actions_allowed && cluster_external_fence_runtime_active(); if (!external_rejoin_active) { cluster_reconfig_external_rejoin_release_all(); if (join_commit_stage.external_rejoin_consumed) @@ -6826,10 +6318,9 @@ cluster_reconfig_lmon_tick(void) * reaches this choke only after its separate admission edge opened the byte; * config-off additionally needs Shape-A's positive boot decision because the * shmem default byte is not authority by itself. */ - self_floor_authority - = cluster_online_join || offpath_fast_rejoin_active_local - || cluster_grd_offpath_boot_decided() - || cold_formation_state.admission_done; + self_floor_authority = cluster_online_join || offpath_fast_rejoin_active_local + || cluster_grd_offpath_boot_decided() + || cold_formation_state.admission_done; if (self_floor_authority) self_floor_incarnation = cluster_qvotec_get_self_incarnation(); @@ -6841,8 +6332,7 @@ cluster_reconfig_lmon_tick(void) * exclusive mutation below revalidates the exact incarnation before use. * Serializing one origin per tick also preserves the one-bit JOIN clear rule. */ - if (ordinary_actions_allowed && ReconfigShmem != NULL - && runtime_join_allowed) { + if (ordinary_actions_allowed && ReconfigShmem != NULL && runtime_join_allowed) { uint64 candidate_incarnation = 0; LWLockAcquire(&ReconfigShmem->lock, LW_SHARED); @@ -6851,10 +6341,8 @@ cluster_reconfig_lmon_tick(void) || cluster_membership_get_state(i) != CLUSTER_MEMBER_DEAD || cluster_cssd_get_peer_state(i) != CLUSTER_CSSD_PEER_ALIVE) continue; - if (cluster_reconfig_get_observed_committed_join( - i, &candidate_incarnation, NULL) - && candidate_incarnation - > cluster_membership_get_last_admitted_incarnation(i)) { + if (cluster_reconfig_get_observed_committed_join(i, &candidate_incarnation, NULL) + && candidate_incarnation > cluster_membership_get_last_admitted_incarnation(i)) { root_gated_join_node = i; break; } @@ -6862,8 +6350,7 @@ cluster_reconfig_lmon_tick(void) LWLockRelease(&ReconfigShmem->lock); if (root_gated_join_node >= 0 - && cluster_recovery_owner_rejoin_v1(root_gated_join_node, - candidate_incarnation)) + && cluster_recovery_owner_rejoin_v1(root_gated_join_node, candidate_incarnation)) root_gated_join_incarnation = candidate_incarnation; else root_gated_join_node = -1; @@ -6922,7 +6409,7 @@ cluster_reconfig_lmon_tick(void) * do not collapse it back to ordinary JOINING merely because the shared * write byte remains zero. Otherwise self-state follows the v2 gate. */ else if (cluster_reconfig_is_local_admitted_replacement( - &ReconfigShmem->replacement_episode)) + &ReconfigShmem->replacement_episode)) cluster_membership_set_state(self_id, CLUSTER_MEMBER_MEMBER); /* A terminal stripe prerequisite refusal is stronger than the generic * closed-gate JOINING fallback below and remains fail-closed. */ @@ -6932,21 +6419,17 @@ cluster_reconfig_lmon_tick(void) * published this exact epoch-0 MEMBER floor while the xid-stripe gate * is still HOLD. Preserve only that same retryable, write-closed * identity; the process-local bootstrap decision remains unlatched. */ - else if (cluster_online_join && !joiner_gate_decided - && !ReconfigShmem->self_join_admitted + else if (cluster_online_join && !joiner_gate_decided && !ReconfigShmem->self_join_admitted && !ReconfigShmem->self_join_failed && cluster_epoch_get_current() == CLUSTER_EPOCH_INITIAL && cluster_reconfig_bootstrap_quorum_at_initial() - && cluster_membership_get_state(self_id) - == CLUSTER_MEMBER_MEMBER - && cluster_reconfig_publish_self_current_floor_locked( - self_id, self_floor_incarnation)) { + && cluster_membership_get_state(self_id) == CLUSTER_MEMBER_MEMBER + && cluster_reconfig_publish_self_current_floor_locked(self_id, + self_floor_incarnation)) { /* Exact helper retained MEMBER; ordinary writes remain closed. */ - } - else if ((ReconfigShmem->self_join_admitted - && !ReconfigShmem->self_join_failed - && (cluster_online_join - /* + } else if ((ReconfigShmem->self_join_admitted && !ReconfigShmem->self_join_failed + && (cluster_online_join + /* * RF-ROOT P6 (crash-rejoin): a durably admitted * shared-CF fast rejoiner keeps self MEMBER while the * boot-decided latch is still held. The admission is @@ -6961,10 +6444,9 @@ cluster_reconfig_lmon_tick(void) * membership byte, and the re-declare ingress that * would lift the latch is exactly what they gate. */ - || offpath_fast_rejoin_active_local - || (self_floor_authority - && cluster_grd_offpath_boot_decided())) - /* + || offpath_fast_rejoin_active_local + || (self_floor_authority && cluster_grd_offpath_boot_decided())) + /* * RF-ROOT P9 verification / cold-formation cold-formation * ruling: after the quorum-majority COMMITTED formation * marker admitted this co-boot (self_join_admitted is set @@ -6978,13 +6460,11 @@ cluster_reconfig_lmon_tick(void) * the cluster wedged in phase 3 with both nodes seeing * each other MEMBER and themselves JOINING. */ - || cold_formation_state.admission_done) - && cluster_reconfig_publish_self_current_floor_locked( - self_id, self_floor_incarnation)) { + || cold_formation_state.admission_done) + && cluster_reconfig_publish_self_current_floor_locked(self_id, + self_floor_incarnation)) { /* Exact helper already published MEMBER. */ - } - else - { + } else { cluster_membership_set_state(self_id, CLUSTER_MEMBER_JOINING); } @@ -7002,11 +6482,10 @@ cluster_reconfig_lmon_tick(void) ms = cluster_membership_get_state(i); prior_incarnation = ReconfigShmem->fast_rejoin_incarnation[i]; if (!cluster_online_join && cluster_controlfile_shared_authority - && ms == CLUSTER_MEMBER_MEMBER - && prior_incarnation == 0 + && ms == CLUSTER_MEMBER_MEMBER && prior_incarnation == 0 && cluster_reconfig_get_observed_fresh_alive(i) - && cluster_reconfig_get_observed_slot( - i, &observed_incarnation, &observed_generation) + && cluster_reconfig_get_observed_slot(i, &observed_incarnation, + &observed_generation) && observed_incarnation > 0) { /* A stale provisioning slot is not identity authority. The first * fresh-alive slot seen for an already-formed peer establishes the @@ -7034,17 +6513,15 @@ cluster_reconfig_lmon_tick(void) && prior_incarnation > 0 && cluster_cssd_get_peer_state(i) == CLUSTER_CSSD_PEER_ALIVE && cluster_reconfig_get_observed_fresh_alive(i) - && cluster_reconfig_get_observed_slot( - i, &observed_incarnation, &observed_generation) + && cluster_reconfig_get_observed_slot(i, &observed_incarnation, + &observed_generation) && observed_incarnation > prior_incarnation) { if (!dead_bitmap_test_bit(ReconfigShmem->fast_rejoin_bitmap, i)) - ereport(LOG, - (errmsg("cluster membership: shared-CF fast-rejoin " - "evicting prior incarnation of node %d " - "(%llu -> %llu)", - i, - (unsigned long long)prior_incarnation, - (unsigned long long)observed_incarnation))); + ereport(LOG, (errmsg("cluster membership: shared-CF fast-rejoin " + "evicting prior incarnation of node %d " + "(%llu -> %llu)", + i, (unsigned long long)prior_incarnation, + (unsigned long long)observed_incarnation))); dead_bitmap_set_bit(ReconfigShmem->fast_rejoin_bitmap, i); dead_bitmap_set_bit(dead_bitmap, i); offpath_fast_rejoin_actions = true; @@ -7095,18 +6572,16 @@ cluster_reconfig_lmon_tick(void) * node in a LIVE cluster (fresh slot past INITIAL) never * passes the window and keeps the ordinary join/JCMK path. */ - uint64 obs_inc = 0; + uint64 obs_inc = 0; if (cluster_epoch_get_current() == CLUSTER_EPOCH_INITIAL) { if (!cluster_reconfig_bootstrap_proof_node(i, &obs_inc)) - continue; /* stays ABSENT; retried next tick */ + continue; /* stays ABSENT; retried next tick */ cluster_membership_record_admitted(i, obs_inc); - if (cluster_membership_get_last_admitted_incarnation(i) - != obs_inc) - continue; /* floor did not land exactly — do not admit */ + if (cluster_membership_get_last_admitted_incarnation(i) != obs_inc) + continue; /* floor did not land exactly — do not admit */ } else if (cluster_reconfig_get_observed_fresh_alive(i) - && cluster_reconfig_get_observed_epoch(i) - > CLUSTER_EPOCH_INITIAL) { + && cluster_reconfig_get_observed_epoch(i) > CLUSTER_EPOCH_INITIAL) { /* * RF-ROOT P9 verification / cold-formation cold-formation * ruling — LIVE-SURVIVOR identity: an ABSENT peer whose @@ -7143,24 +6618,21 @@ cluster_reconfig_lmon_tick(void) * (publish-proof counts only MEMBER survivors) and * either times out 53R61 or wedges phase 3. */ - uint64 marker_inc = pg_atomic_read_u64( + uint64 marker_inc = pg_atomic_read_u64( &ReconfigShmem->observed_formation_marker_incarnation[i]); - uint64 survivor_inc; - uint64 survivor_gen = 0; + uint64 survivor_inc; + uint64 survivor_gen = 0; if (marker_inc != 0) survivor_inc = marker_inc; - else - { - (void) cluster_reconfig_get_observed_slot( - i, &survivor_inc, &survivor_gen); + else { + (void)cluster_reconfig_get_observed_slot(i, &survivor_inc, &survivor_gen); if (survivor_gen == 0 || survivor_inc == 0) - continue; /* no durable identity yet: retry */ + continue; /* no durable identity yet: retry */ } cluster_membership_record_admitted(i, survivor_inc); - if (cluster_membership_get_last_admitted_incarnation(i) - != survivor_inc) - continue; /* floor did not land exactly — no MEMBER */ + if (cluster_membership_get_last_admitted_incarnation(i) != survivor_inc) + continue; /* floor did not land exactly — no MEMBER */ } else { /* Cold-formation path: admission is marker-driven and * happens for the whole co-boot set at once (the state @@ -7179,17 +6651,14 @@ cluster_reconfig_lmon_tick(void) * masked (its fail-stop suppressed) and the survivor * wedges: observed t243 L4 (kill -9 after a clean- * departed rejoin). */ - if (clean_departed_test_bit_locked( - ReconfigShmem->clean_departed_bitmap, i) + if (clean_departed_test_bit_locked(ReconfigShmem->clean_departed_bitmap, i) || ReconfigShmem->clean_departed_epoch[i] != 0) cluster_write_fence_authority_cache_invalidate(); - ReconfigShmem->clean_departed_bitmap[i / 8] - &= (uint8) ~(1u << (i % 8)); + ReconfigShmem->clean_departed_bitmap[i / 8] &= (uint8) ~(1u << (i % 8)); ReconfigShmem->clean_departed_epoch[i] = 0; - } - else if (runtime_join_allowed && i == root_gated_join_node - && ms == CLUSTER_MEMBER_DEAD - && cluster_cssd_get_peer_state(i) == CLUSTER_CSSD_PEER_ALIVE) { + } else if (runtime_join_allowed && i == root_gated_join_node + && ms == CLUSTER_MEMBER_DEAD + && cluster_cssd_get_peer_state(i) == CLUSTER_CSSD_PEER_ALIVE) { /* * spec-5.16 (3-node join participation) — survivor-side runtime * readmit. A DEAD peer whose durable COMMITTED join marker (observed @@ -7209,8 +6678,7 @@ cluster_reconfig_lmon_tick(void) cluster_membership_set_state(i, CLUSTER_MEMBER_MEMBER); cluster_membership_record_admitted(i, obs_inc); ReconfigShmem->fast_rejoin_incarnation[i] = obs_inc; - ReconfigShmem->fast_rejoin_bitmap[i / 8] - &= (uint8) ~(1u << (i % 8)); + ReconfigShmem->fast_rejoin_bitmap[i / 8] &= (uint8) ~(1u << (i % 8)); dead_bitmap_set_bit(newly_joined, i); any_joined = true; } @@ -7236,16 +6704,14 @@ cluster_reconfig_lmon_tick(void) * CSSD sees its restarted process ALIVE. Only the individually * ROOT-gated JOIN above may remove its bit. */ dead_bitmap[b] &= (uint8) ~(ReconfigShmem->clean_departed_bitmap[b] - | ReconfigShmem->removed_bitmap[b]); + | ReconfigShmem->removed_bitmap[b]); if (dead_bitmap[b] != 0 - && cssd_dead_generation - != ReconfigShmem->last_applied.cssd_dead_generation) + && cssd_dead_generation != ReconfigShmem->last_applied.cssd_dead_generation) failure_generation_changed = true; new_failure_bitmap[b] - = dead_bitmap[b] - & (uint8) ~ReconfigShmem->last_applied.dead_bitmap[b]; + = dead_bitmap[b] & (uint8)~ReconfigShmem->last_applied.dead_bitmap[b]; dead_bitmap[b] |= ReconfigShmem->last_applied.dead_bitmap[b]; - dead_bitmap[b] &= (uint8) ~newly_joined[b]; + dead_bitmap[b] &= (uint8)~newly_joined[b]; } if (any_joined) { memcpy(join_remaining_dead, ReconfigShmem->last_applied.dead_bitmap, @@ -7264,16 +6730,13 @@ cluster_reconfig_lmon_tick(void) * the mailbox submit (no blocking). No-op once every declared * peer is formed. */ - if (cluster_epoch_get_current() > CLUSTER_EPOCH_INITIAL) - { - bool any_absent = false; + if (cluster_epoch_get_current() > CLUSTER_EPOCH_INITIAL) { + bool any_absent = false; - for (i = 0; i < CLUSTER_MAX_NODES; i++) - { + for (i = 0; i < CLUSTER_MAX_NODES; i++) { if (cluster_conf_lookup_node(i) == NULL) continue; - if (cluster_membership_get_state(i) == CLUSTER_MEMBER_ABSENT) - { + if (cluster_membership_get_state(i) == CLUSTER_MEMBER_ABSENT) { any_absent = true; break; } @@ -7283,8 +6746,7 @@ cluster_reconfig_lmon_tick(void) } LWLockRelease(&ReconfigShmem->lock); - cluster_reconfig_membership_floor_diagnostic( - "after-membership-reconcile"); + cluster_reconfig_membership_floor_diagnostic("after-membership-reconcile"); /* * spec-5.16 (3-node join participation) — publish an observer-role @@ -7332,16 +6794,13 @@ cluster_reconfig_lmon_tick(void) if (!dead_bitmap_test_bit(newly_joined, jn)) continue; - if (cluster_reconfig_get_observed_committed_join(jn, &jinc, - &jepoch) - && jinc == root_gated_join_incarnation - && jepoch != 0) + if (cluster_reconfig_get_observed_committed_join(jn, &jinc, &jepoch) + && jinc == root_gated_join_incarnation && jepoch != 0) jevt.new_epoch = jepoch; else jevt.new_epoch = jevt.old_epoch; } - memcpy(jevt.dead_bitmap, join_remaining_dead, - CLUSTER_RECONFIG_DEAD_BITMAP_BYTES); + memcpy(jevt.dead_bitmap, join_remaining_dead, CLUSTER_RECONFIG_DEAD_BITMAP_BYTES); memcpy(jevt.join_bitmap, newly_joined, CLUSTER_RECONFIG_DEAD_BITMAP_BYTES); jevt.applied_at = GetCurrentTimestamp(); jevt.observer_role = CLUSTER_RECONFIG_OBSERVER_SURVIVOR; @@ -7379,8 +6838,7 @@ cluster_reconfig_lmon_tick(void) * ReconfigEvent; neither early-returns past the other. */ if (!failstop_stage_handled - && (!dead_bitmap_is_zero(new_failure_bitmap) - || failure_generation_changed)) { + && (!dead_bitmap_is_zero(new_failure_bitmap) || failure_generation_changed)) { CLUSTER_INJECTION_POINT("cluster-reconfig-decide-coordinator"); /* §3.2 P1.2: event_id from dead_bitmap + dead_generation snapshot. */ @@ -7450,18 +6908,14 @@ cluster_reconfig_lmon_tick(void) * retry next tick once the leave finishes; the leave side symmetrically refuses * to start while a join is pending. */ - if (runtime_join_allowed - && (ordinary_actions_allowed - || fast_rejoin_control_actions) - && self_id == coordinator && - !cluster_clean_leave_in_progress() + if (runtime_join_allowed && (ordinary_actions_allowed || fast_rejoin_control_actions) + && self_id == coordinator && !cluster_clean_leave_in_progress() && (cluster_online_join - || (dead_bitmap_is_zero(new_failure_bitmap) - && !failure_generation_changed))) { + || (dead_bitmap_is_zero(new_failure_bitmap) && !failure_generation_changed))) { if (external_rejoin_active) cluster_reconfig_external_rejoin_tick(); - cluster_reconfig_drive_joins(coordinator, - fast_rejoin_control_actions ? fast_rejoin_control_target : -1, + cluster_reconfig_drive_joins( + coordinator, fast_rejoin_control_actions ? fast_rejoin_control_target : -1, fast_rejoin_control_actions ? fast_rejoin_control_incarnation : 0); } else { cluster_reconfig_external_rejoin_release_all(); @@ -7863,13 +7317,11 @@ cluster_reconfig_apply_node_removed_as_coordinator(int32 removed_node_id, uint64 * consumes it during that callback, so the removed node must be present * even when a prior clean leave kept it out of last_applied.dead_bitmap. */ LWLockAcquire(&ReconfigShmem->lock, LW_SHARED); - memcpy(current_dead, ReconfigShmem->last_applied.dead_bitmap, - sizeof(current_dead)); - memcpy(removed_with_n, ReconfigShmem->removed_bitmap, - sizeof(removed_with_n)); + memcpy(current_dead, ReconfigShmem->last_applied.dead_bitmap, sizeof(current_dead)); + memcpy(removed_with_n, ReconfigShmem->removed_bitmap, sizeof(removed_with_n)); for (b = 0; b < CLUSTER_RECONFIG_DEAD_BITMAP_BYTES; b++) - excluded_with_n[b] = ReconfigShmem->last_applied.dead_bitmap[b] - | ReconfigShmem->removed_bitmap[b]; + excluded_with_n[b] + = ReconfigShmem->last_applied.dead_bitmap[b] | ReconfigShmem->removed_bitmap[b]; LWLockRelease(&ReconfigShmem->lock); removed_with_n[removed_node_id / 8] |= (uint8)(1u << (removed_node_id % 8)); excluded_with_n[removed_node_id / 8] |= (uint8)(1u << (removed_node_id % 8)); @@ -7919,8 +7371,7 @@ cluster_reconfig_apply_node_removed_as_coordinator(int32 removed_node_id, uint64 marker.fence_generation = cssd_dead_generation; marker.issuer_node_id = cluster_node_id; marker.marker_kind = CLUSTER_FENCE_MARKER_KIND_NODE_REMOVED; - memcpy(marker.fenced_dead_bitmap, excluded_with_n, - CLUSTER_RECONFIG_DEAD_BITMAP_BYTES); + memcpy(marker.fenced_dead_bitmap, excluded_with_n, CLUSTER_RECONFIG_DEAD_BITMAP_BYTES); node_removed_fence_stage.event.event_id = cluster_reconfig_compute_removal_event_id(removed_with_n, removal_event_id); @@ -7987,34 +7438,29 @@ static ClusterJoinMarkerMailboxOperationV1 join_qvotec_inflight_marker_operation static bool join_qvotec_marker_inflight = false; bool -cluster_reconfig_qvotec_lifecycle_transition( - ClusterQvotecMailbox *authority_mailbox, - pg_atomic_uint32 *qvotec_status, ClusterQvotecStatus next_status) +cluster_reconfig_qvotec_lifecycle_transition(ClusterQvotecMailbox *authority_mailbox, + pg_atomic_uint32 *qvotec_status, + ClusterQvotecStatus next_status) { bool invalidate; - if (ReconfigShmem == NULL || authority_mailbox == NULL - || qvotec_status == NULL - || (next_status != CLUSTER_QVOTEC_STARTING - && next_status != CLUSTER_QVOTEC_READY - && next_status != CLUSTER_QVOTEC_SHUTTING_DOWN - && next_status != CLUSTER_QVOTEC_DOWN)) + if (ReconfigShmem == NULL || authority_mailbox == NULL || qvotec_status == NULL + || (next_status != CLUSTER_QVOTEC_STARTING && next_status != CLUSTER_QVOTEC_READY + && next_status != CLUSTER_QVOTEC_SHUTTING_DOWN && next_status != CLUSTER_QVOTEC_DOWN)) return false; - invalidate = next_status == CLUSTER_QVOTEC_STARTING - || next_status == CLUSTER_QVOTEC_SHUTTING_DOWN; + invalidate + = next_status == CLUSTER_QVOTEC_STARTING || next_status == CLUSTER_QVOTEC_SHUTTING_DOWN; LWLockAcquire(&ReconfigShmem->lock, LW_EXCLUSIVE); pg_atomic_write_u32(qvotec_status, (uint32)next_status); if (invalidate) { cluster_qvotec_mailbox_restart_reset(authority_mailbox); - pg_atomic_write_u32(&ReconfigShmem->join_marker_result, - CLUSTER_JOIN_MARKER_SUBMIT_FAILED); + pg_atomic_write_u32(&ReconfigShmem->join_marker_result, CLUSTER_JOIN_MARKER_SUBMIT_FAILED); pg_atomic_write_u64(&ReconfigShmem->join_marker_completion_seq, 0); pg_write_barrier(); join_qvotec_inflight_marker_seq = 0; join_qvotec_last_processed_marker_seq = 0; - join_qvotec_inflight_marker_operation - = CLUSTER_JOIN_MARKER_MAILBOX_WRITE_EXACT; + join_qvotec_inflight_marker_operation = CLUSTER_JOIN_MARKER_MAILBOX_WRITE_EXACT; join_qvotec_marker_inflight = false; } LWLockRelease(&ReconfigShmem->lock); @@ -8024,16 +7470,14 @@ cluster_reconfig_qvotec_lifecycle_transition( } static bool -cluster_reconfig_join_marker_request_word_encode( - ClusterJoinMarkerMailboxOperationV1 operation, int32 target_node, - uint32 *word_out) +cluster_reconfig_join_marker_request_word_encode(ClusterJoinMarkerMailboxOperationV1 operation, + int32 target_node, uint32 *word_out) { uint32 word; if (word_out == NULL || target_node < 0 || target_node >= CLUSTER_MAX_NODES || (operation != CLUSTER_JOIN_MARKER_MAILBOX_WRITE_EXACT - && operation - != CLUSTER_JOIN_MARKER_MAILBOX_VERIFY_COMMITTED_CLOSED)) + && operation != CLUSTER_JOIN_MARKER_MAILBOX_VERIFY_COMMITTED_CLOSED)) return false; word = (uint32)target_node; if (operation == CLUSTER_JOIN_MARKER_MAILBOX_VERIFY_COMMITTED_CLOSED) @@ -8043,9 +7487,9 @@ cluster_reconfig_join_marker_request_word_encode( } static bool -cluster_reconfig_join_marker_request_word_decode( - uint32 word, ClusterJoinMarkerMailboxOperationV1 *operation_out, - int32 *target_node_out) +cluster_reconfig_join_marker_request_word_decode(uint32 word, + ClusterJoinMarkerMailboxOperationV1 *operation_out, + int32 *target_node_out) { uint32 target; @@ -8055,10 +7499,9 @@ cluster_reconfig_join_marker_request_word_decode( target = word & CLUSTER_JOIN_MARKER_REQUEST_TARGET_MASK; if (target >= CLUSTER_MAX_NODES) return false; - *operation_out - = (word & CLUSTER_JOIN_MARKER_REQUEST_VERIFY_COMMITTED_CLOSED) != 0 - ? CLUSTER_JOIN_MARKER_MAILBOX_VERIFY_COMMITTED_CLOSED - : CLUSTER_JOIN_MARKER_MAILBOX_WRITE_EXACT; + *operation_out = (word & CLUSTER_JOIN_MARKER_REQUEST_VERIFY_COMMITTED_CLOSED) != 0 + ? CLUSTER_JOIN_MARKER_MAILBOX_VERIFY_COMMITTED_CLOSED + : CLUSTER_JOIN_MARKER_MAILBOX_WRITE_EXACT; *target_node_out = (int32)target; return true; } @@ -8070,24 +7513,22 @@ cluster_reconfig_join_marker_request_word_decode( * remains the caller's commit point. */ static bool -cluster_reconfig_stage_join_marker_locked( - int32 target_node, ClusterJoinMarkerMailboxOperationV1 operation, - uint32 version, const void *image, Size image_len) +cluster_reconfig_stage_join_marker_locked(int32 target_node, + ClusterJoinMarkerMailboxOperationV1 operation, + uint32 version, const void *image, Size image_len) { Size expected_len; uint32 request_word; if (ReconfigShmem == NULL - || !cluster_reconfig_join_marker_request_word_encode( - operation, target_node, &request_word)) + || !cluster_reconfig_join_marker_request_word_encode(operation, target_node, &request_word)) return false; if (operation == CLUSTER_JOIN_MARKER_MAILBOX_VERIFY_COMMITTED_CLOSED) { if (image != NULL || image_len != 0 || version != 0) return false; ReconfigShmem->join_marker_request_word = request_word; - memset(ReconfigShmem->join_pending_marker, 0, - sizeof(ReconfigShmem->join_pending_marker)); + memset(ReconfigShmem->join_pending_marker, 0, sizeof(ReconfigShmem->join_pending_marker)); return true; } if (image == NULL) @@ -8107,8 +7548,7 @@ cluster_reconfig_stage_join_marker_locked( return false; ReconfigShmem->join_marker_request_word = request_word; - memset(ReconfigShmem->join_pending_marker, 0, - sizeof(ReconfigShmem->join_pending_marker)); + memset(ReconfigShmem->join_pending_marker, 0, sizeof(ReconfigShmem->join_pending_marker)); memcpy(ReconfigShmem->join_pending_marker, image, image_len); return true; } @@ -8117,12 +7557,9 @@ static void cluster_reconfig_release_ready_stage(void) { if (join_marker_lmon_owner.reserved - && join_marker_lmon_owner.purpose - == CLUSTER_JOIN_MARKER_LMON_READY_SERIALIZE) - memset(&join_marker_lmon_owner, 0, - sizeof(join_marker_lmon_owner)); - memset(&replacement_ready_stage, 0, - sizeof(replacement_ready_stage)); + && join_marker_lmon_owner.purpose == CLUSTER_JOIN_MARKER_LMON_READY_SERIALIZE) + memset(&join_marker_lmon_owner, 0, sizeof(join_marker_lmon_owner)); + memset(&replacement_ready_stage, 0, sizeof(replacement_ready_stage)); cluster_marker_async_init(&replacement_ready_stage.marker_async); } @@ -8137,8 +7574,7 @@ cluster_reconfig_lmon_submit_ready_observer_pair(TimestampTz now) bool marker_submitted; int wait_ms; - if (!cluster_reconfig_replacement_candidate2_capabilities_current( - &capability_episode)) + if (!cluster_reconfig_replacement_candidate2_capabilities_current(&capability_episode)) return false; wait_ms = cluster_quorum_poll_interval_ms * 3 + 2000; LWLockAcquire(&ReconfigShmem->lock, LW_EXCLUSIVE); @@ -8146,77 +7582,56 @@ cluster_reconfig_lmon_submit_ready_observer_pair(TimestampTz now) if (cluster_qvotec_get_status() != CLUSTER_QVOTEC_READY || memcmp(episode, &capability_episode, sizeof(*episode)) != 0 || !cluster_replacement_episode_is_valid(episode) - || (episode->phase - != CLUSTER_REPLACEMENT_EPISODE_COMMITTED_CLOSED + || (episode->phase != CLUSTER_REPLACEMENT_EPISODE_COMMITTED_CLOSED && episode->phase != CLUSTER_REPLACEMENT_EPISODE_POST_EPOCH) - || (episode->readiness_flags - & CLUSTER_REPLACEMENT_EPISODE_R4A_TARGET_READY) == 0 - || episode->state_generation == 0 - || episode->target_node_id != cluster_node_id - || episode->reserved_or_committed_epoch - != cluster_epoch_get_current() - || ReconfigShmem->self_join_admitted != 0 - || ReconfigShmem->self_join_failed != 0 + || (episode->readiness_flags & CLUSTER_REPLACEMENT_EPISODE_R4A_TARGET_READY) == 0 + || episode->state_generation == 0 || episode->target_node_id != cluster_node_id + || episode->reserved_or_committed_epoch != cluster_epoch_get_current() + || ReconfigShmem->self_join_admitted != 0 || ReconfigShmem->self_join_failed != 0 || !cluster_reconfig_replacement_membership_current_locked(episode) - || cluster_membership_get_last_admitted_incarnation( - episode->target_node_id) + || cluster_membership_get_last_admitted_incarnation(episode->target_node_id) != episode->old_admitted_incarnation || join_marker_lmon_owner.reserved - || cluster_marker_async_mailbox_busy( - &ReconfigShmem->join_marker_request_seq, - &ReconfigShmem->join_marker_completion_seq)) { + || cluster_marker_async_mailbox_busy(&ReconfigShmem->join_marker_request_seq, + &ReconfigShmem->join_marker_completion_seq)) { LWLockRelease(&ReconfigShmem->lock); return false; } join_marker_lmon_owner.reserved = true; - join_marker_lmon_owner.purpose - = CLUSTER_JOIN_MARKER_LMON_READY_SERIALIZE; - join_marker_lmon_owner.operation - = CLUSTER_JOIN_MARKER_MAILBOX_VERIFY_COMMITTED_CLOSED; + join_marker_lmon_owner.purpose = CLUSTER_JOIN_MARKER_LMON_READY_SERIALIZE; + join_marker_lmon_owner.operation = CLUSTER_JOIN_MARKER_MAILBOX_VERIFY_COMMITTED_CLOSED; join_marker_lmon_owner.marker_request_seq = 0; - authority_status = cluster_qvotec_authority_lmon_submit( - CLUSTER_QVOTEC_MAILBOX_RECOVER_HEAD, zero_value, - &replacement_ready_stage.authority_request_seq); + authority_status + = cluster_qvotec_authority_lmon_submit(CLUSTER_QVOTEC_MAILBOX_RECOVER_HEAD, zero_value, + &replacement_ready_stage.authority_request_seq); if (authority_status != CLUSTER_QVOTEC_MAILBOX_SUBMIT_ACCEPTED) { - memset(&join_marker_lmon_owner, 0, - sizeof(join_marker_lmon_owner)); + memset(&join_marker_lmon_owner, 0, sizeof(join_marker_lmon_owner)); LWLockRelease(&ReconfigShmem->lock); return false; } if (!cluster_reconfig_stage_join_marker_locked( - episode->target_node_id, - CLUSTER_JOIN_MARKER_MAILBOX_VERIFY_COMMITTED_CLOSED, - 0, NULL, 0)) { - memset(&join_marker_lmon_owner, 0, - sizeof(join_marker_lmon_owner)); - replacement_ready_stage.phase - = CLUSTER_REPLACEMENT_READY_STAGE_DRAIN_AUTHORITY; + episode->target_node_id, CLUSTER_JOIN_MARKER_MAILBOX_VERIFY_COMMITTED_CLOSED, 0, NULL, + 0)) { + memset(&join_marker_lmon_owner, 0, sizeof(join_marker_lmon_owner)); + replacement_ready_stage.phase = CLUSTER_REPLACEMENT_READY_STAGE_DRAIN_AUTHORITY; LWLockRelease(&ReconfigShmem->lock); return false; } marker_submitted = cluster_marker_async_submit( - &replacement_ready_stage.marker_async, - &ReconfigShmem->join_marker_request_seq, - &ReconfigShmem->join_marker_completion_seq, NULL, now, - (uint64)wait_ms * 1000ULL, - CLUSTER_MARKER_KIND_REPLACEMENT_VERIFY_COMMITTED_CLOSED, - episode->target_node_id); + &replacement_ready_stage.marker_async, &ReconfigShmem->join_marker_request_seq, + &ReconfigShmem->join_marker_completion_seq, NULL, now, (uint64)wait_ms * 1000ULL, + CLUSTER_MARKER_KIND_REPLACEMENT_VERIFY_COMMITTED_CLOSED, episode->target_node_id); if (!marker_submitted) { - memset(&join_marker_lmon_owner, 0, - sizeof(join_marker_lmon_owner)); - replacement_ready_stage.phase - = CLUSTER_REPLACEMENT_READY_STAGE_DRAIN_AUTHORITY; + memset(&join_marker_lmon_owner, 0, sizeof(join_marker_lmon_owner)); + replacement_ready_stage.phase = CLUSTER_REPLACEMENT_READY_STAGE_DRAIN_AUTHORITY; LWLockRelease(&ReconfigShmem->lock); return false; } - replacement_ready_stage.marker_request_seq - = replacement_ready_stage.marker_async.inflight_seq; - join_marker_lmon_owner.marker_request_seq - = replacement_ready_stage.marker_request_seq; + replacement_ready_stage.marker_request_seq = replacement_ready_stage.marker_async.inflight_seq; + join_marker_lmon_owner.marker_request_seq = replacement_ready_stage.marker_request_seq; replacement_ready_stage.marker_completed = false; - replacement_ready_stage.phase - = CLUSTER_REPLACEMENT_READY_STAGE_WAIT_PAIR; + replacement_ready_stage.phase = CLUSTER_REPLACEMENT_READY_STAGE_WAIT_PAIR; qlatch = ReconfigShmem->join_qvotec_latch; LWLockRelease(&ReconfigShmem->lock); if (qlatch != NULL) @@ -8240,88 +7655,66 @@ cluster_reconfig_lmon_ready_cache_current(int32 *coordinator_node_id) bool valid = false; if (coordinator_node_id == NULL - || replacement_ready_stage.phase - != CLUSTER_REPLACEMENT_READY_STAGE_CACHED - || !cluster_reconfig_replacement_candidate2_capabilities_current( - &capability_episode)) { + || replacement_ready_stage.phase != CLUSTER_REPLACEMENT_READY_STAGE_CACHED + || !cluster_reconfig_replacement_candidate2_capabilities_current(&capability_episode)) { cluster_reconfig_release_ready_stage(); return false; } LWLockAcquire(&ReconfigShmem->lock, LW_SHARED); episode = &ReconfigShmem->replacement_episode; - if (join_marker_lmon_owner.reserved - || cluster_qvotec_get_status() != CLUSTER_QVOTEC_READY + if (join_marker_lmon_owner.reserved || cluster_qvotec_get_status() != CLUSTER_QVOTEC_READY || memcmp(episode, &capability_episode, sizeof(*episode)) != 0 || !cluster_replacement_episode_is_valid(episode) - || (episode->phase - != CLUSTER_REPLACEMENT_EPISODE_COMMITTED_CLOSED + || (episode->phase != CLUSTER_REPLACEMENT_EPISODE_COMMITTED_CLOSED && episode->phase != CLUSTER_REPLACEMENT_EPISODE_POST_EPOCH) - || (episode->readiness_flags - & CLUSTER_REPLACEMENT_EPISODE_R4A_TARGET_READY) == 0 + || (episode->readiness_flags & CLUSTER_REPLACEMENT_EPISODE_R4A_TARGET_READY) == 0 || episode->target_node_id != cluster_node_id - || episode->target_node_id - != replacement_ready_stage.cached_snapshot.target_node_id + || episode->target_node_id != replacement_ready_stage.cached_snapshot.target_node_id || episode->state_generation != replacement_ready_stage.cached_snapshot.episode_state_generation - || episode->request_nonce - != replacement_ready_stage.cached_snapshot.request_nonce + || episode->request_nonce != replacement_ready_stage.cached_snapshot.request_nonce || episode->old_admitted_incarnation != replacement_ready_stage.cached_snapshot.old_admitted_incarnation - || episode->fresh_incarnation - != replacement_ready_stage.cached_snapshot.fresh_incarnation + || episode->fresh_incarnation != replacement_ready_stage.cached_snapshot.fresh_incarnation || episode->reserved_or_committed_epoch != replacement_ready_stage.cached_snapshot.committed_epoch || episode->grammar_fingerprint != replacement_ready_stage.cached_snapshot.grammar_fingerprint - || episode->reserved_or_committed_epoch - != cluster_epoch_get_current() - || ReconfigShmem->self_join_admitted != 0 - || ReconfigShmem->self_join_failed != 0 + || episode->reserved_or_committed_epoch != cluster_epoch_get_current() + || ReconfigShmem->self_join_admitted != 0 || ReconfigShmem->self_join_failed != 0 || !cluster_reconfig_replacement_membership_current_locked(episode) - || cluster_membership_get_last_admitted_incarnation( - episode->target_node_id) + || cluster_membership_get_last_admitted_incarnation(episode->target_node_id) != episode->old_admitted_incarnation || !cluster_qvotec_authority_lmon_poll_completion( - replacement_ready_stage.authority_request_seq, - &completion) + replacement_ready_stage.authority_request_seq, &completion) || completion.result != CLUSTER_QVOTEC_MAILBOX_CHOSEN || completion.actor_phase != CLUSTER_QVOTEC_ACTOR_RECOVER_SCAN_B - || !cluster_epoch_authority_value_decode( - completion.completion_value, - CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT, &head) - || !cluster_epoch_ballot_id_decode( - completion.completion_ballot, &ballot) + || !cluster_epoch_authority_value_decode(completion.completion_value, + CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT, &head) + || !cluster_epoch_ballot_id_decode(completion.completion_ballot, &ballot) || pg_atomic_read_u64(&ReconfigShmem->join_marker_request_seq) != replacement_ready_stage.marker_request_seq || pg_atomic_read_u64(&ReconfigShmem->join_marker_completion_seq) != replacement_ready_stage.marker_request_seq - || pg_atomic_read_u32(&ReconfigShmem->join_marker_result) - != CLUSTER_JOIN_MARKER_SUBMIT_ACK) + || pg_atomic_read_u32(&ReconfigShmem->join_marker_result) != CLUSTER_JOIN_MARKER_SUBMIT_ACK) goto out; request_word = ReconfigShmem->join_marker_request_word; - if (!cluster_reconfig_join_marker_request_word_decode( - request_word, &operation, &request_target) - || operation - != CLUSTER_JOIN_MARKER_MAILBOX_VERIFY_COMMITTED_CLOSED + if (!cluster_reconfig_join_marker_request_word_decode(request_word, &operation, &request_target) + || operation != CLUSTER_JOIN_MARKER_MAILBOX_VERIFY_COMMITTED_CLOSED || request_target != episode->target_node_id - || !cluster_replacement_marker_v3_decode( - ReconfigShmem->join_pending_marker, request_target, &marker) - || marker.generation - != replacement_ready_stage.cached_snapshot.jcmk_generation - || !cluster_reconfig_terminal_closed_matches_episode( - &head, &ballot, &marker, episode) + || !cluster_replacement_marker_v3_decode(ReconfigShmem->join_pending_marker, request_target, + &marker) + || marker.generation != replacement_ready_stage.cached_snapshot.jcmk_generation + || !cluster_reconfig_terminal_closed_matches_episode(&head, &ballot, &marker, episode) || !cluster_qvotec_authority_lmon_poll_completion( - replacement_ready_stage.authority_request_seq, - &repeated_completion) - || memcmp(&completion, &repeated_completion, - sizeof(completion)) != 0 + replacement_ready_stage.authority_request_seq, &repeated_completion) + || memcmp(&completion, &repeated_completion, sizeof(completion)) != 0 || pg_atomic_read_u64(&ReconfigShmem->join_marker_request_seq) != replacement_ready_stage.marker_request_seq || pg_atomic_read_u64(&ReconfigShmem->join_marker_completion_seq) != replacement_ready_stage.marker_request_seq - || pg_atomic_read_u32(&ReconfigShmem->join_marker_result) - != CLUSTER_JOIN_MARKER_SUBMIT_ACK + || pg_atomic_read_u32(&ReconfigShmem->join_marker_result) != CLUSTER_JOIN_MARKER_SUBMIT_ACK || ReconfigShmem->join_marker_request_word != request_word || cluster_qvotec_get_status() != CLUSTER_QVOTEC_READY) goto out; @@ -8342,22 +7735,16 @@ cluster_reconfig_r4_membership_observations_current( { int node; - if (candidate == NULL - || cluster_qvotec_get_status() != CLUSTER_QVOTEC_READY - || !cluster_qvotec_in_quorum() - || cluster_epoch_get_current() != candidate->formation_epoch - || cluster_qvotec_get_self_incarnation() - != candidate->local_self_boot_incarnation) + if (candidate == NULL || cluster_qvotec_get_status() != CLUSTER_QVOTEC_READY + || !cluster_qvotec_in_quorum() || cluster_epoch_get_current() != candidate->formation_epoch + || cluster_qvotec_get_self_incarnation() != candidate->local_self_boot_incarnation) return false; for (node = 0; node < CLUSTER_MAX_NODES; node++) { uint64 generation = 0; uint64 incarnation = 0; - bool admitted - = node < 64 - ? (candidate->admitted_members_lo - & (UINT64_C(1) << node)) != 0 - : (candidate->admitted_members_hi - & (UINT64_C(1) << (node - 64))) != 0; + bool admitted = node < 64 + ? (candidate->admitted_members_lo & (UINT64_C(1) << node)) != 0 + : (candidate->admitted_members_hi & (UINT64_C(1) << (node - 64))) != 0; if (!admitted) continue; @@ -8394,14 +7781,12 @@ cluster_reconfig_lmon_snapshot_r4_membership_internal( if (out != NULL) memset(out, 0, sizeof(*out)); - if (ReconfigShmem == NULL || out == NULL - || cluster_node_id < 0 || cluster_node_id >= CLUSTER_MAX_NODES - || cluster_qvotec_get_status() != CLUSTER_QVOTEC_READY - || !cluster_qvotec_in_quorum()) + if (ReconfigShmem == NULL || out == NULL || cluster_node_id < 0 + || cluster_node_id >= CLUSTER_MAX_NODES + || cluster_qvotec_get_status() != CLUSTER_QVOTEC_READY || !cluster_qvotec_in_quorum()) return false; memset(&candidate, 0, sizeof(candidate)); - candidate.local_self_boot_incarnation - = cluster_qvotec_get_self_incarnation(); + candidate.local_self_boot_incarnation = cluster_qvotec_get_self_incarnation(); if (candidate.local_self_boot_incarnation == 0) return false; @@ -8420,14 +7805,12 @@ cluster_reconfig_lmon_snapshot_r4_membership_internal( if (node < 64) candidate.admitted_members_lo |= UINT64_C(1) << node; else - candidate.admitted_members_hi - |= UINT64_C(1) << (node - 64); + candidate.admitted_members_hi |= UINT64_C(1) << (node - 64); candidate.admitted_incarnation[node] = floor; } LWLockRelease(&ReconfigShmem->lock); - self_bit = UINT64_C(1) << (cluster_node_id < 64 - ? cluster_node_id : cluster_node_id - 64); + self_bit = UINT64_C(1) << (cluster_node_id < 64 ? cluster_node_id : cluster_node_id - 64); if (!exact || (candidate.admitted_members_lo | candidate.admitted_members_hi) == 0 || (cluster_node_id < 64 ? (candidate.admitted_members_lo & self_bit) == 0 : (candidate.admitted_members_hi & self_bit) == 0) @@ -8440,15 +7823,11 @@ cluster_reconfig_lmon_snapshot_r4_membership_internal( if (cluster_epoch_get_current() != candidate.formation_epoch) exact = false; for (node = 0; exact && node < CLUSTER_MAX_NODES; node++) { - bool admitted - = node < 64 - ? (candidate.admitted_members_lo - & (UINT64_C(1) << node)) != 0 - : (candidate.admitted_members_hi - & (UINT64_C(1) << (node - 64))) != 0; - - if ((cluster_membership_get_state(node) == CLUSTER_MEMBER_MEMBER) - != admitted + bool admitted = node < 64 + ? (candidate.admitted_members_lo & (UINT64_C(1) << node)) != 0 + : (candidate.admitted_members_hi & (UINT64_C(1) << (node - 64))) != 0; + + if ((cluster_membership_get_state(node) == CLUSTER_MEMBER_MEMBER) != admitted || (admitted && (cluster_conf_lookup_node(node) == NULL || cluster_membership_get_last_admitted_incarnation(node) @@ -8473,9 +7852,8 @@ cluster_reconfig_lmon_snapshot_r4_membership(ClusterR4MembershipSnapshot *out) /* Compatibility projection for callers that consume only the global bitmap * and formation epoch. Exactness comes from the stack-only snapshot above. */ bool -cluster_reconfig_lmon_snapshot_admitted_membership( - uint64 *out_members_lo, uint64 *out_members_hi, - uint64 *out_formation_epoch) +cluster_reconfig_lmon_snapshot_admitted_membership(uint64 *out_members_lo, uint64 *out_members_hi, + uint64 *out_formation_epoch) { ClusterR4MembershipSnapshot snapshot; @@ -8485,8 +7863,7 @@ cluster_reconfig_lmon_snapshot_admitted_membership( *out_members_hi = 0; if (out_formation_epoch != NULL) *out_formation_epoch = 0; - if (out_members_lo == NULL || out_members_hi == NULL - || out_formation_epoch == NULL + if (out_members_lo == NULL || out_members_hi == NULL || out_formation_epoch == NULL || !cluster_reconfig_lmon_snapshot_r4_membership(&snapshot)) return false; *out_members_lo = snapshot.admitted_members_lo; @@ -8522,12 +7899,9 @@ static void cluster_reconfig_release_closed_stage(void) { if (join_marker_lmon_owner.reserved - && join_marker_lmon_owner.purpose - == CLUSTER_JOIN_MARKER_LMON_CLOSED_APPLY) - memset(&join_marker_lmon_owner, 0, - sizeof(join_marker_lmon_owner)); - memset(&replacement_closed_stage, 0, - sizeof(replacement_closed_stage)); + && join_marker_lmon_owner.purpose == CLUSTER_JOIN_MARKER_LMON_CLOSED_APPLY) + memset(&join_marker_lmon_owner, 0, sizeof(join_marker_lmon_owner)); + memset(&replacement_closed_stage, 0, sizeof(replacement_closed_stage)); cluster_marker_async_init(&replacement_closed_stage.marker_async); } @@ -8542,8 +7916,7 @@ cluster_reconfig_lmon_submit_closed_observer_pair(TimestampTz now) bool marker_submitted; int wait_ms; - if (!cluster_reconfig_replacement_candidate2_capabilities_current( - &capability_episode)) + if (!cluster_reconfig_replacement_candidate2_capabilities_current(&capability_episode)) return false; wait_ms = cluster_quorum_poll_interval_ms * 3 + 2000; LWLockAcquire(&ReconfigShmem->lock, LW_EXCLUSIVE); @@ -8553,71 +7926,54 @@ cluster_reconfig_lmon_submit_closed_observer_pair(TimestampTz now) || !cluster_replacement_episode_is_valid(episode) || episode->phase != CLUSTER_REPLACEMENT_EPISODE_PURGE_COMPLETE || episode->readiness_flags != 0 - || memcmp(episode->acknowledgements, - episode->expected_survivors, - sizeof(episode->acknowledgements)) != 0 + || memcmp(episode->acknowledgements, episode->expected_survivors, + sizeof(episode->acknowledgements)) + != 0 || (cluster_node_id != episode->target_node_id - && !dead_bitmap_test_bit( - episode->expected_survivors, cluster_node_id)) + && !dead_bitmap_test_bit(episode->expected_survivors, cluster_node_id)) || !cluster_reconfig_replacement_membership_current_locked(episode) - || cluster_membership_get_last_admitted_incarnation( - episode->target_node_id) + || cluster_membership_get_last_admitted_incarnation(episode->target_node_id) != episode->old_admitted_incarnation - || cluster_epoch_get_current() != episode->baseline_epoch - || join_marker_lmon_owner.reserved - || cluster_marker_async_mailbox_busy( - &ReconfigShmem->join_marker_request_seq, - &ReconfigShmem->join_marker_completion_seq)) { + || cluster_epoch_get_current() != episode->baseline_epoch || join_marker_lmon_owner.reserved + || cluster_marker_async_mailbox_busy(&ReconfigShmem->join_marker_request_seq, + &ReconfigShmem->join_marker_completion_seq)) { LWLockRelease(&ReconfigShmem->lock); return false; } join_marker_lmon_owner.reserved = true; - join_marker_lmon_owner.purpose - = CLUSTER_JOIN_MARKER_LMON_CLOSED_APPLY; - join_marker_lmon_owner.operation - = CLUSTER_JOIN_MARKER_MAILBOX_VERIFY_COMMITTED_CLOSED; + join_marker_lmon_owner.purpose = CLUSTER_JOIN_MARKER_LMON_CLOSED_APPLY; + join_marker_lmon_owner.operation = CLUSTER_JOIN_MARKER_MAILBOX_VERIFY_COMMITTED_CLOSED; join_marker_lmon_owner.marker_request_seq = 0; - authority_status = cluster_qvotec_authority_lmon_submit( - CLUSTER_QVOTEC_MAILBOX_RECOVER_HEAD, zero_value, - &replacement_closed_stage.authority_request_seq); + authority_status + = cluster_qvotec_authority_lmon_submit(CLUSTER_QVOTEC_MAILBOX_RECOVER_HEAD, zero_value, + &replacement_closed_stage.authority_request_seq); if (authority_status != CLUSTER_QVOTEC_MAILBOX_SUBMIT_ACCEPTED) { - memset(&join_marker_lmon_owner, 0, - sizeof(join_marker_lmon_owner)); + memset(&join_marker_lmon_owner, 0, sizeof(join_marker_lmon_owner)); LWLockRelease(&ReconfigShmem->lock); return false; } if (!cluster_reconfig_stage_join_marker_locked( - episode->target_node_id, - CLUSTER_JOIN_MARKER_MAILBOX_VERIFY_COMMITTED_CLOSED, - 0, NULL, 0)) { - memset(&join_marker_lmon_owner, 0, - sizeof(join_marker_lmon_owner)); - replacement_closed_stage.phase - = CLUSTER_REPLACEMENT_CLOSED_STAGE_DRAIN_AUTHORITY; + episode->target_node_id, CLUSTER_JOIN_MARKER_MAILBOX_VERIFY_COMMITTED_CLOSED, 0, NULL, + 0)) { + memset(&join_marker_lmon_owner, 0, sizeof(join_marker_lmon_owner)); + replacement_closed_stage.phase = CLUSTER_REPLACEMENT_CLOSED_STAGE_DRAIN_AUTHORITY; LWLockRelease(&ReconfigShmem->lock); return false; } marker_submitted = cluster_marker_async_submit( - &replacement_closed_stage.marker_async, - &ReconfigShmem->join_marker_request_seq, - &ReconfigShmem->join_marker_completion_seq, NULL, now, - (uint64)wait_ms * 1000ULL, - CLUSTER_MARKER_KIND_REPLACEMENT_VERIFY_COMMITTED_CLOSED, - episode->target_node_id); + &replacement_closed_stage.marker_async, &ReconfigShmem->join_marker_request_seq, + &ReconfigShmem->join_marker_completion_seq, NULL, now, (uint64)wait_ms * 1000ULL, + CLUSTER_MARKER_KIND_REPLACEMENT_VERIFY_COMMITTED_CLOSED, episode->target_node_id); if (!marker_submitted) { - memset(&join_marker_lmon_owner, 0, - sizeof(join_marker_lmon_owner)); - replacement_closed_stage.phase - = CLUSTER_REPLACEMENT_CLOSED_STAGE_DRAIN_AUTHORITY; + memset(&join_marker_lmon_owner, 0, sizeof(join_marker_lmon_owner)); + replacement_closed_stage.phase = CLUSTER_REPLACEMENT_CLOSED_STAGE_DRAIN_AUTHORITY; LWLockRelease(&ReconfigShmem->lock); return false; } - join_marker_lmon_owner.marker_request_seq - = replacement_closed_stage.marker_async.inflight_seq; + join_marker_lmon_owner.marker_request_seq = replacement_closed_stage.marker_async.inflight_seq; replacement_closed_stage.marker_completed = false; - replacement_closed_stage.phase - = CLUSTER_REPLACEMENT_CLOSED_STAGE_WAIT_PAIR; + replacement_closed_stage.phase = CLUSTER_REPLACEMENT_CLOSED_STAGE_WAIT_PAIR; qlatch = ReconfigShmem->join_qvotec_latch; LWLockRelease(&ReconfigShmem->lock); if (qlatch != NULL) @@ -8626,63 +7982,52 @@ cluster_reconfig_lmon_submit_closed_observer_pair(TimestampTz now) } static bool -cluster_reconfig_terminal_closed_matches_episode( - const ClusterEpochAuthorityValue *head, - const ClusterEpochBallotId *ballot, - const ClusterReplacementCommitMarkerV3 *marker, - const ClusterReplacementEpisode *episode) +cluster_reconfig_terminal_closed_matches_episode(const ClusterEpochAuthorityValue *head, + const ClusterEpochBallotId *ballot, + const ClusterReplacementCommitMarkerV3 *marker, + const ClusterReplacementEpisode *episode) { uint8 subject[CLUSTER_RECONFIG_DEAD_BITMAP_BYTES] = { 0 }; if (head == NULL || ballot == NULL || marker == NULL || episode == NULL) return false; - subject[episode->target_node_id / 8] - = (uint8)(1u << (episode->target_node_id % 8)); + subject[episode->target_node_id / 8] = (uint8)(1u << (episode->target_node_id % 8)); return head->transition == CLUSTER_EPOCH_AUTHORITY_COMMIT_CLOSED - && head->event_kind - == CLUSTER_EPOCH_EVENT_SAME_NODE_REPLACEMENT + && head->event_kind == CLUSTER_EPOCH_EVENT_SAME_NODE_REPLACEMENT && head->request_origin_node == episode->target_node_id && head->target_node_id == episode->target_node_id && head->baseline_epoch == episode->baseline_epoch - && head->reserved_epoch - == episode->reserved_or_committed_epoch - && head->old_incarnation - == episode->old_admitted_incarnation + && head->reserved_epoch == episode->reserved_or_committed_epoch + && head->old_incarnation == episode->old_admitted_incarnation && head->fresh_incarnation == episode->fresh_incarnation && head->request_nonce == episode->request_nonce - && memcmp(head->authority_member_bitmap, - episode->expected_survivors, - sizeof(head->authority_member_bitmap)) == 0 - && memcmp(head->event_subject_bitmap, subject, - sizeof(subject)) == 0 + && memcmp(head->authority_member_bitmap, episode->expected_survivors, + sizeof(head->authority_member_bitmap)) + == 0 + && memcmp(head->event_subject_bitmap, subject, sizeof(subject)) == 0 && head->grammar_fingerprint == episode->grammar_fingerprint && ballot->proposer_node_id == episode->coordinator_node_id && ballot->proposer_admitted_incarnation - == cluster_membership_get_last_admitted_incarnation( - episode->coordinator_node_id) - && marker->phase - == CLUSTER_JCMK_REPLACEMENT_PHASE_COMMITTED_CLOSED + == cluster_membership_get_last_admitted_incarnation(episode->coordinator_node_id) + && marker->phase == CLUSTER_JCMK_REPLACEMENT_PHASE_COMMITTED_CLOSED && marker->ready_state_generation == 0 && marker->target_node_id == episode->target_node_id - && marker->old_admitted_incarnation - == episode->old_admitted_incarnation + && marker->old_admitted_incarnation == episode->old_admitted_incarnation && marker->fresh_incarnation == episode->fresh_incarnation && marker->baseline_epoch == episode->baseline_epoch - && marker->reserved_or_committed_epoch - == episode->reserved_or_committed_epoch + && marker->reserved_or_committed_epoch == episode->reserved_or_committed_epoch && marker->request_nonce == episode->request_nonce - && memcmp(marker->expected_purge_survivors, - episode->expected_survivors, - sizeof(marker->expected_purge_survivors)) == 0 + && memcmp(marker->expected_purge_survivors, episode->expected_survivors, + sizeof(marker->expected_purge_survivors)) + == 0 && marker->grammar_fingerprint == episode->grammar_fingerprint; } ClusterReplacementCommittedClosedPublishResultV1 -cluster_reconfig_lmon_publish_replacement_committed_closed( - uint64 authority_request_seq, uint64 marker_request_seq) +cluster_reconfig_lmon_publish_replacement_committed_closed(uint64 authority_request_seq, + uint64 marker_request_seq) { - ClusterReplacementCommittedClosedPublishResultV1 result - = CLUSTER_REPLACEMENT_CLOSED_RETRY; + ClusterReplacementCommittedClosedPublishResultV1 result = CLUSTER_REPLACEMENT_CLOSED_RETRY; ClusterQvotecMailboxCompletion completion; ClusterEpochAuthorityValue head; ClusterEpochBallotId ballot; @@ -8699,19 +8044,15 @@ cluster_reconfig_lmon_publish_replacement_committed_closed( uint64 current_epoch; bool release_owner = true; - if (ReconfigShmem == NULL || MyBackendType != B_LMON - || authority_request_seq == 0 - || (authority_request_seq & UINT64_C(1)) != 0 - || marker_request_seq == 0) + if (ReconfigShmem == NULL || MyBackendType != B_LMON || authority_request_seq == 0 + || (authority_request_seq & UINT64_C(1)) != 0 || marker_request_seq == 0) return CLUSTER_REPLACEMENT_CLOSED_INVALID; - if (!cluster_reconfig_replacement_candidate2_capabilities_current( - &capability_episode)) + if (!cluster_reconfig_replacement_candidate2_capabilities_current(&capability_episode)) return CLUSTER_REPLACEMENT_CLOSED_HOLD_IDENTITY; LWLockAcquire(&ReconfigShmem->lock, LW_EXCLUSIVE); if (!join_marker_lmon_owner.reserved - || join_marker_lmon_owner.purpose - != CLUSTER_JOIN_MARKER_LMON_CLOSED_APPLY + || join_marker_lmon_owner.purpose != CLUSTER_JOIN_MARKER_LMON_CLOSED_APPLY || join_marker_lmon_owner.marker_request_seq != marker_request_seq) { result = CLUSTER_REPLACEMENT_CLOSED_RETRY; goto out; @@ -8720,25 +8061,20 @@ cluster_reconfig_lmon_publish_replacement_committed_closed( result = CLUSTER_REPLACEMENT_CLOSED_RETRY; goto out; } - if (!cluster_qvotec_authority_lmon_poll_completion( - authority_request_seq, &completion)) { + if (!cluster_qvotec_authority_lmon_poll_completion(authority_request_seq, &completion)) { result = CLUSTER_REPLACEMENT_CLOSED_BLOCKED_QVOTEC; release_owner = false; goto out; } if (completion.result != CLUSTER_QVOTEC_MAILBOX_CHOSEN - || !cluster_epoch_authority_value_decode( - completion.completion_value, - CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT, &head) - || !cluster_epoch_ballot_id_decode( - completion.completion_ballot, &ballot)) { + || !cluster_epoch_authority_value_decode(completion.completion_value, + CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT, &head) + || !cluster_epoch_ballot_id_decode(completion.completion_ballot, &ballot)) { result = CLUSTER_REPLACEMENT_CLOSED_BLOCKED_QVOTEC; goto out; } - if (pg_atomic_read_u64(&ReconfigShmem->join_marker_request_seq) - != marker_request_seq - || pg_atomic_read_u64(&ReconfigShmem->join_marker_completion_seq) - != marker_request_seq + if (pg_atomic_read_u64(&ReconfigShmem->join_marker_request_seq) != marker_request_seq + || pg_atomic_read_u64(&ReconfigShmem->join_marker_completion_seq) != marker_request_seq || pg_atomic_read_u32(&ReconfigShmem->join_marker_result) != CLUSTER_JOIN_MARKER_SUBMIT_ACK) { result = CLUSTER_REPLACEMENT_CLOSED_BLOCKED_JCMK; @@ -8746,68 +8082,55 @@ cluster_reconfig_lmon_publish_replacement_committed_closed( goto out; } request_word = ReconfigShmem->join_marker_request_word; - if (!cluster_reconfig_join_marker_request_word_decode( - request_word, &operation, &request_target) + if (!cluster_reconfig_join_marker_request_word_decode(request_word, &operation, &request_target) || operation != join_marker_lmon_owner.operation - || !((completion.actor_phase - == CLUSTER_QVOTEC_ACTOR_RECOVER_SCAN_B - && operation - == CLUSTER_JOIN_MARKER_MAILBOX_VERIFY_COMMITTED_CLOSED) - || (completion.actor_phase - == CLUSTER_QVOTEC_ACTOR_SETTLE_WRITE - && operation - == CLUSTER_JOIN_MARKER_MAILBOX_WRITE_EXACT))) { + || !((completion.actor_phase == CLUSTER_QVOTEC_ACTOR_RECOVER_SCAN_B + && operation == CLUSTER_JOIN_MARKER_MAILBOX_VERIFY_COMMITTED_CLOSED) + || (completion.actor_phase == CLUSTER_QVOTEC_ACTOR_SETTLE_WRITE + && operation == CLUSTER_JOIN_MARKER_MAILBOX_WRITE_EXACT))) { result = CLUSTER_REPLACEMENT_CLOSED_HOLD_IDENTITY; goto out; } - if (!cluster_replacement_marker_v3_decode( - ReconfigShmem->join_pending_marker, request_target, &marker)) { + if (!cluster_replacement_marker_v3_decode(ReconfigShmem->join_pending_marker, request_target, + &marker)) { result = CLUSTER_REPLACEMENT_CLOSED_BLOCKED_JCMK; goto out; } - if (memcmp(&ReconfigShmem->replacement_episode, - &capability_episode, sizeof(capability_episode)) != 0 - || !cluster_replacement_episode_is_valid( - &ReconfigShmem->replacement_episode) - || (ReconfigShmem->replacement_episode.phase - != CLUSTER_REPLACEMENT_EPISODE_PURGE_COMPLETE + if (memcmp(&ReconfigShmem->replacement_episode, &capability_episode, sizeof(capability_episode)) + != 0 + || !cluster_replacement_episode_is_valid(&ReconfigShmem->replacement_episode) + || (ReconfigShmem->replacement_episode.phase != CLUSTER_REPLACEMENT_EPISODE_PURGE_COMPLETE && ReconfigShmem->replacement_episode.phase - != CLUSTER_REPLACEMENT_EPISODE_COMMITTED_CLOSED) + != CLUSTER_REPLACEMENT_EPISODE_COMMITTED_CLOSED) || ReconfigShmem->replacement_episode.readiness_flags != 0 || memcmp(ReconfigShmem->replacement_episode.acknowledgements, ReconfigShmem->replacement_episode.expected_survivors, - sizeof(ReconfigShmem->replacement_episode.acknowledgements)) != 0 - || (cluster_node_id - != ReconfigShmem->replacement_episode.target_node_id - && !dead_bitmap_test_bit( - ReconfigShmem->replacement_episode.expected_survivors, - cluster_node_id)) + sizeof(ReconfigShmem->replacement_episode.acknowledgements)) + != 0 + || (cluster_node_id != ReconfigShmem->replacement_episode.target_node_id + && !dead_bitmap_test_bit(ReconfigShmem->replacement_episode.expected_survivors, + cluster_node_id)) || !cluster_reconfig_replacement_membership_current_locked( &ReconfigShmem->replacement_episode) || cluster_membership_get_last_admitted_incarnation( ReconfigShmem->replacement_episode.target_node_id) != ReconfigShmem->replacement_episode.old_admitted_incarnation - || !cluster_reconfig_terminal_closed_matches_episode( - &head, &ballot, &marker, - &ReconfigShmem->replacement_episode)) { + || !cluster_reconfig_terminal_closed_matches_episode(&head, &ballot, &marker, + &ReconfigShmem->replacement_episode)) { result = CLUSTER_REPLACEMENT_CLOSED_HOLD_IDENTITY; goto out; } current_epoch = cluster_epoch_get_current(); if (current_epoch != ReconfigShmem->replacement_episode.baseline_epoch - && current_epoch - != ReconfigShmem->replacement_episode.reserved_or_committed_epoch) { + && current_epoch != ReconfigShmem->replacement_episode.reserved_or_committed_epoch) { result = CLUSTER_REPLACEMENT_CLOSED_HOLD_IDENTITY; goto out; } - observer_role - = cluster_node_id - == ReconfigShmem->replacement_episode.coordinator_node_id - ? CLUSTER_RECONFIG_OBSERVER_COORDINATOR - : CLUSTER_RECONFIG_OBSERVER_SURVIVOR; - if (ReconfigShmem->replacement_episode.phase - == CLUSTER_REPLACEMENT_EPISODE_COMMITTED_CLOSED) { + observer_role = cluster_node_id == ReconfigShmem->replacement_episode.coordinator_node_id + ? CLUSTER_RECONFIG_OBSERVER_COORDINATOR + : CLUSTER_RECONFIG_OBSERVER_SURVIVOR; + if (ReconfigShmem->replacement_episode.phase == CLUSTER_REPLACEMENT_EPISODE_COMMITTED_CLOSED) { if (!cluster_reconfig_build_replacement_committed_event( &ReconfigShmem->replacement_episode, observer_role, ReconfigShmem->last_applied.applied_at, &expected_event)) { @@ -8815,52 +8138,45 @@ cluster_reconfig_lmon_publish_replacement_committed_closed( goto out; } expected_event.event_seq = ReconfigShmem->last_applied.event_seq; - result = memcmp(&expected_event, &ReconfigShmem->last_applied, - sizeof(expected_event)) == 0 - ? CLUSTER_REPLACEMENT_CLOSED_ALREADY_CURRENT - : CLUSTER_REPLACEMENT_CLOSED_HOLD_IDENTITY; + result = memcmp(&expected_event, &ReconfigShmem->last_applied, sizeof(expected_event)) == 0 + ? CLUSTER_REPLACEMENT_CLOSED_ALREADY_CURRENT + : CLUSTER_REPLACEMENT_CLOSED_HOLD_IDENTITY; goto out; } candidate = ReconfigShmem->replacement_episode; - if (!cluster_replacement_episode_next_generation( - candidate.state_generation, &next_generation)) { + if (!cluster_replacement_episode_next_generation(candidate.state_generation, + &next_generation)) { result = CLUSTER_REPLACEMENT_CLOSED_HOLD_IDENTITY; goto out; } candidate.state_generation = next_generation; candidate.phase = CLUSTER_REPLACEMENT_EPISODE_COMMITTED_CLOSED; - if (!cluster_reconfig_build_replacement_committed_event( - &candidate, observer_role, GetCurrentTimestamp(), &event)) { + if (!cluster_reconfig_build_replacement_committed_event(&candidate, observer_role, + GetCurrentTimestamp(), &event)) { result = CLUSTER_REPLACEMENT_CLOSED_HOLD_IDENTITY; goto out; } - if (pg_atomic_read_u64(&ReconfigShmem->join_marker_request_seq) - != marker_request_seq - || pg_atomic_read_u64(&ReconfigShmem->join_marker_completion_seq) - != marker_request_seq + if (pg_atomic_read_u64(&ReconfigShmem->join_marker_request_seq) != marker_request_seq + || pg_atomic_read_u64(&ReconfigShmem->join_marker_completion_seq) != marker_request_seq || ReconfigShmem->join_marker_request_word != request_word) { result = CLUSTER_REPLACEMENT_CLOSED_RETRY; goto out; } if (current_epoch == candidate.baseline_epoch) - (void)cluster_epoch_observe_remote( - candidate.reserved_or_committed_epoch); - if (cluster_epoch_get_current() - != candidate.reserved_or_committed_epoch) { + (void)cluster_epoch_observe_remote(candidate.reserved_or_committed_epoch); + if (cluster_epoch_get_current() != candidate.reserved_or_committed_epoch) { result = CLUSTER_REPLACEMENT_CLOSED_HOLD_IDENTITY; goto out; } - event.event_seq - = pg_atomic_fetch_add_u64(&ReconfigShmem->apply_counter, 1) + 1; + event.event_seq = pg_atomic_fetch_add_u64(&ReconfigShmem->apply_counter, 1) + 1; ReconfigShmem->replacement_episode = candidate; ReconfigShmem->last_applied = event; result = CLUSTER_REPLACEMENT_CLOSED_PUBLISHED; out: if (release_owner) - memset(&join_marker_lmon_owner, 0, - sizeof(join_marker_lmon_owner)); + memset(&join_marker_lmon_owner, 0, sizeof(join_marker_lmon_owner)); LWLockRelease(&ReconfigShmem->lock); return result; } @@ -8875,22 +8191,17 @@ cluster_reconfig_lmon_replacement_closed_tick(void) uint64 elapsed_us = 0; TimestampTz now; - if (!cluster_enabled || MyBackendType != B_LMON - || !cluster_qvotec_in_quorum() || cluster_node_id < 0 - || cluster_node_id >= CLUSTER_MAX_NODES) + if (!cluster_enabled || MyBackendType != B_LMON || !cluster_qvotec_in_quorum() + || cluster_node_id < 0 || cluster_node_id >= CLUSTER_MAX_NODES) return; - if (replacement_closed_stage.phase - == CLUSTER_REPLACEMENT_CLOSED_STAGE_IDLE) { + if (replacement_closed_stage.phase == CLUSTER_REPLACEMENT_CLOSED_STAGE_IDLE) { cluster_marker_async_init(&replacement_closed_stage.marker_async); - (void)cluster_reconfig_lmon_submit_closed_observer_pair( - GetCurrentTimestamp()); + (void)cluster_reconfig_lmon_submit_closed_observer_pair(GetCurrentTimestamp()); return; } - if (replacement_closed_stage.phase - == CLUSTER_REPLACEMENT_CLOSED_STAGE_DRAIN_AUTHORITY) { + if (replacement_closed_stage.phase == CLUSTER_REPLACEMENT_CLOSED_STAGE_DRAIN_AUTHORITY) { (void)cluster_qvotec_authority_lmon_poll_completion( - replacement_closed_stage.authority_request_seq, - &ignored_completion); + replacement_closed_stage.authority_request_seq, &ignored_completion); cluster_reconfig_release_closed_stage(); return; } @@ -8898,10 +8209,8 @@ cluster_reconfig_lmon_replacement_closed_tick(void) now = GetCurrentTimestamp(); if (!replacement_closed_stage.marker_completed) { marker_poll = cluster_reconfig_poll_join_marker_async( - &replacement_closed_stage.marker_async, now, &marker_result, - &elapsed_us); - if (marker_poll == CLUSTER_MARKER_POLL_PENDING - || marker_poll == CLUSTER_MARKER_POLL_IDLE) + &replacement_closed_stage.marker_async, now, &marker_result, &elapsed_us); + if (marker_poll == CLUSTER_MARKER_POLL_PENDING || marker_poll == CLUSTER_MARKER_POLL_IDLE) return; if (marker_poll != CLUSTER_MARKER_POLL_ACKED || marker_result != CLUSTER_JOIN_MARKER_SUBMIT_ACK) { @@ -8910,10 +8219,9 @@ cluster_reconfig_lmon_replacement_closed_tick(void) } replacement_closed_stage.marker_completed = true; } - publish_result - = cluster_reconfig_lmon_publish_replacement_committed_closed( - replacement_closed_stage.authority_request_seq, - replacement_closed_stage.marker_async.inflight_seq); + publish_result = cluster_reconfig_lmon_publish_replacement_committed_closed( + replacement_closed_stage.authority_request_seq, + replacement_closed_stage.marker_async.inflight_seq); if (publish_result == CLUSTER_REPLACEMENT_CLOSED_BLOCKED_QVOTEC || publish_result == CLUSTER_REPLACEMENT_CLOSED_BLOCKED_JCMK) return; @@ -8936,12 +8244,11 @@ cluster_reconfig_submit_join_marker(int32 target_node, const ClusterJoinCommitMa /* Serialize staging with QVOTEC lifecycle/final receipt use. */ LWLockAcquire(&ReconfigShmem->lock, LW_EXCLUSIVE); if (join_marker_lmon_owner.reserved - || cluster_marker_async_mailbox_busy( - &ReconfigShmem->join_marker_request_seq, - &ReconfigShmem->join_marker_completion_seq) - || !cluster_reconfig_stage_join_marker_locked( - target_node, CLUSTER_JOIN_MARKER_MAILBOX_WRITE_EXACT, - CLUSTER_JCMK_VERSION, m, sizeof(*m))) { + || cluster_marker_async_mailbox_busy(&ReconfigShmem->join_marker_request_seq, + &ReconfigShmem->join_marker_completion_seq) + || !cluster_reconfig_stage_join_marker_locked(target_node, + CLUSTER_JOIN_MARKER_MAILBOX_WRITE_EXACT, + CLUSTER_JCMK_VERSION, m, sizeof(*m))) { LWLockRelease(&ReconfigShmem->lock); return CLUSTER_JOIN_MARKER_SUBMIT_FAILED; } @@ -8988,18 +8295,17 @@ cluster_reconfig_submit_join_marker_async(ClusterMarkerAsync *a, int32 target_no wait_ms = cluster_quorum_poll_interval_ms * 3 + 2000; LWLockAcquire(&ReconfigShmem->lock, LW_EXCLUSIVE); if (join_marker_lmon_owner.reserved - || cluster_marker_async_mailbox_busy( - &ReconfigShmem->join_marker_request_seq, - &ReconfigShmem->join_marker_completion_seq) - || !cluster_reconfig_stage_join_marker_locked( - target_node, CLUSTER_JOIN_MARKER_MAILBOX_WRITE_EXACT, - CLUSTER_JCMK_VERSION, m, sizeof(*m))) { + || cluster_marker_async_mailbox_busy(&ReconfigShmem->join_marker_request_seq, + &ReconfigShmem->join_marker_completion_seq) + || !cluster_reconfig_stage_join_marker_locked(target_node, + CLUSTER_JOIN_MARKER_MAILBOX_WRITE_EXACT, + CLUSTER_JCMK_VERSION, m, sizeof(*m))) { LWLockRelease(&ReconfigShmem->lock); return false; } - submitted = cluster_marker_async_submit( - a, &ReconfigShmem->join_marker_request_seq, &ReconfigShmem->join_marker_completion_seq, - NULL, now, (uint64)wait_ms * 1000ULL, kind, target_node); + submitted = cluster_marker_async_submit(a, &ReconfigShmem->join_marker_request_seq, + &ReconfigShmem->join_marker_completion_seq, NULL, now, + (uint64)wait_ms * 1000ULL, kind, target_node); qlatch = ReconfigShmem->join_qvotec_latch; LWLockRelease(&ReconfigShmem->lock); if (submitted && qlatch != NULL) @@ -9008,10 +8314,9 @@ cluster_reconfig_submit_join_marker_async(ClusterMarkerAsync *a, int32 target_no } bool -cluster_reconfig_submit_replacement_marker_v3_async( - ClusterMarkerAsync *a, int32 target_node, - const ClusterReplacementCommitMarkerV3 *marker, - ClusterMarkerAsyncKind kind, TimestampTz now) +cluster_reconfig_submit_replacement_marker_v3_async(ClusterMarkerAsync *a, int32 target_node, + const ClusterReplacementCommitMarkerV3 *marker, + ClusterMarkerAsyncKind kind, TimestampTz now) { uint8 image[CLUSTER_JCMK_REPLACEMENT_BYTES]; int wait_ms; @@ -9030,18 +8335,17 @@ cluster_reconfig_submit_replacement_marker_v3_async( wait_ms = cluster_quorum_poll_interval_ms * 3 + 2000; LWLockAcquire(&ReconfigShmem->lock, LW_EXCLUSIVE); if (join_marker_lmon_owner.reserved - || cluster_marker_async_mailbox_busy( - &ReconfigShmem->join_marker_request_seq, - &ReconfigShmem->join_marker_completion_seq) + || cluster_marker_async_mailbox_busy(&ReconfigShmem->join_marker_request_seq, + &ReconfigShmem->join_marker_completion_seq) || !cluster_reconfig_stage_join_marker_locked( - target_node, CLUSTER_JOIN_MARKER_MAILBOX_WRITE_EXACT, - CLUSTER_JCMK_REPLACEMENT_VERSION, image, sizeof(image))) { + target_node, CLUSTER_JOIN_MARKER_MAILBOX_WRITE_EXACT, CLUSTER_JCMK_REPLACEMENT_VERSION, + image, sizeof(image))) { LWLockRelease(&ReconfigShmem->lock); return false; } - submitted = cluster_marker_async_submit( - a, &ReconfigShmem->join_marker_request_seq, &ReconfigShmem->join_marker_completion_seq, - NULL, now, (uint64)wait_ms * 1000ULL, kind, target_node); + submitted = cluster_marker_async_submit(a, &ReconfigShmem->join_marker_request_seq, + &ReconfigShmem->join_marker_completion_seq, NULL, now, + (uint64)wait_ms * 1000ULL, kind, target_node); qlatch = ReconfigShmem->join_qvotec_latch; LWLockRelease(&ReconfigShmem->lock); if (submitted && qlatch != NULL) @@ -9050,37 +8354,31 @@ cluster_reconfig_submit_replacement_marker_v3_async( } bool -cluster_reconfig_verify_replacement_committed_closed_async( - ClusterMarkerAsync *a, int32 target_node, TimestampTz now) +cluster_reconfig_verify_replacement_committed_closed_async(ClusterMarkerAsync *a, int32 target_node, + TimestampTz now) { int wait_ms; struct Latch *qlatch; bool submitted; - if (ReconfigShmem == NULL || a == NULL || target_node < 0 - || target_node >= CLUSTER_MAX_NODES) + if (ReconfigShmem == NULL || a == NULL || target_node < 0 || target_node >= CLUSTER_MAX_NODES) return false; if (cluster_marker_async_is_submitted(a)) return true; wait_ms = cluster_quorum_poll_interval_ms * 3 + 2000; LWLockAcquire(&ReconfigShmem->lock, LW_EXCLUSIVE); if (join_marker_lmon_owner.reserved - || cluster_marker_async_mailbox_busy( - &ReconfigShmem->join_marker_request_seq, - &ReconfigShmem->join_marker_completion_seq) + || cluster_marker_async_mailbox_busy(&ReconfigShmem->join_marker_request_seq, + &ReconfigShmem->join_marker_completion_seq) || !cluster_reconfig_stage_join_marker_locked( - target_node, - CLUSTER_JOIN_MARKER_MAILBOX_VERIFY_COMMITTED_CLOSED, - 0, NULL, 0)) { + target_node, CLUSTER_JOIN_MARKER_MAILBOX_VERIFY_COMMITTED_CLOSED, 0, NULL, 0)) { LWLockRelease(&ReconfigShmem->lock); return false; } submitted = cluster_marker_async_submit( - a, &ReconfigShmem->join_marker_request_seq, - &ReconfigShmem->join_marker_completion_seq, NULL, now, - (uint64)wait_ms * 1000ULL, - CLUSTER_MARKER_KIND_REPLACEMENT_VERIFY_COMMITTED_CLOSED, - target_node); + a, &ReconfigShmem->join_marker_request_seq, &ReconfigShmem->join_marker_completion_seq, + NULL, now, (uint64)wait_ms * 1000ULL, + CLUSTER_MARKER_KIND_REPLACEMENT_VERIFY_COMMITTED_CLOSED, target_node); qlatch = ReconfigShmem->join_qvotec_latch; LWLockRelease(&ReconfigShmem->lock); if (submitted && qlatch != NULL) @@ -9100,9 +8398,8 @@ cluster_reconfig_poll_join_marker_async(ClusterMarkerAsync *a, TimestampTz now, } bool -cluster_reconfig_join_qvotec_poll_pending( - ClusterJoinMarkerMailboxOperationV1 *operation_out, - int32 *target_node_out, void *write_slot512_out) +cluster_reconfig_join_qvotec_poll_pending(ClusterJoinMarkerMailboxOperationV1 *operation_out, + int32 *target_node_out, void *write_slot512_out) { uint64 request_seq_before; uint64 request_seq_after; @@ -9110,18 +8407,15 @@ cluster_reconfig_join_qvotec_poll_pending( ClusterJoinMarkerMailboxOperationV1 operation; int32 target_node; - if (ReconfigShmem == NULL || operation_out == NULL - || target_node_out == NULL || write_slot512_out == NULL - || join_qvotec_marker_inflight) + if (ReconfigShmem == NULL || operation_out == NULL || target_node_out == NULL + || write_slot512_out == NULL || join_qvotec_marker_inflight) return false; *operation_out = CLUSTER_JOIN_MARKER_MAILBOX_WRITE_EXACT; *target_node_out = -1; memset(write_slot512_out, 0, CLUSTER_VOTING_SLOT_BYTES); - request_seq_before - = pg_atomic_read_u64(&ReconfigShmem->join_marker_request_seq); - if (request_seq_before == 0 - || request_seq_before == join_qvotec_last_processed_marker_seq) + request_seq_before = pg_atomic_read_u64(&ReconfigShmem->join_marker_request_seq); + if (request_seq_before == 0 || request_seq_before == join_qvotec_last_processed_marker_seq) return false; /* nothing new */ pg_read_barrier(); @@ -9129,23 +8423,18 @@ cluster_reconfig_join_qvotec_poll_pending( memcpy(write_slot512_out, ReconfigShmem->join_pending_marker, sizeof(ReconfigShmem->join_pending_marker)); pg_read_barrier(); - request_seq_after - = pg_atomic_read_u64(&ReconfigShmem->join_marker_request_seq); + request_seq_after = pg_atomic_read_u64(&ReconfigShmem->join_marker_request_seq); if (request_seq_before != request_seq_after) return false; - if (!cluster_reconfig_join_marker_request_word_decode( - request_word, &operation, &target_node)) { + if (!cluster_reconfig_join_marker_request_word_decode(request_word, &operation, &target_node)) { LWLockAcquire(&ReconfigShmem->lock, LW_EXCLUSIVE); - if (pg_atomic_read_u64(&ReconfigShmem->join_marker_request_seq) - == request_seq_before) { + if (pg_atomic_read_u64(&ReconfigShmem->join_marker_request_seq) == request_seq_before) { memset(ReconfigShmem->join_pending_marker, 0, sizeof(ReconfigShmem->join_pending_marker)); pg_atomic_write_u32(&ReconfigShmem->join_marker_result, - CLUSTER_JOIN_MARKER_SUBMIT_FAILED); + CLUSTER_JOIN_MARKER_SUBMIT_FAILED); pg_write_barrier(); - pg_atomic_write_u64( - &ReconfigShmem->join_marker_completion_seq, - request_seq_before); + pg_atomic_write_u64(&ReconfigShmem->join_marker_completion_seq, request_seq_before); join_qvotec_last_processed_marker_seq = request_seq_before; } LWLockRelease(&ReconfigShmem->lock); @@ -9153,8 +8442,7 @@ cluster_reconfig_join_qvotec_poll_pending( memset(write_slot512_out, 0, CLUSTER_VOTING_SLOT_BYTES); return false; } - if (operation - == CLUSTER_JOIN_MARKER_MAILBOX_VERIFY_COMMITTED_CLOSED) + if (operation == CLUSTER_JOIN_MARKER_MAILBOX_VERIFY_COMMITTED_CLOSED) memset(write_slot512_out, 0, CLUSTER_VOTING_SLOT_BYTES); *operation_out = operation; *target_node_out = target_node; @@ -9165,9 +8453,8 @@ cluster_reconfig_join_qvotec_poll_pending( } void -cluster_reconfig_join_qvotec_complete( - ClusterJoinMarkerMailboxOperationV1 operation, bool acked, - const uint8 *verified_image96) +cluster_reconfig_join_qvotec_complete(ClusterJoinMarkerMailboxOperationV1 operation, bool acked, + const uint8 *verified_image96) { ClusterJoinMarkerMailboxOperationV1 request_operation; ClusterReplacementCommitMarkerV3 verified_marker; @@ -9180,16 +8467,13 @@ cluster_reconfig_join_qvotec_complete( return; LWLockAcquire(&ReconfigShmem->lock, LW_EXCLUSIVE); - call_matches - = operation == join_qvotec_inflight_marker_operation - && pg_atomic_read_u64(&ReconfigShmem->join_marker_request_seq) - == join_qvotec_inflight_marker_seq - && cluster_reconfig_join_marker_request_word_decode( - ReconfigShmem->join_marker_request_word, - &request_operation, &target_node) - && request_operation == join_qvotec_inflight_marker_operation; - if (call_matches - && operation == CLUSTER_JOIN_MARKER_MAILBOX_WRITE_EXACT) { + call_matches = operation == join_qvotec_inflight_marker_operation + && pg_atomic_read_u64(&ReconfigShmem->join_marker_request_seq) + == join_qvotec_inflight_marker_seq + && cluster_reconfig_join_marker_request_word_decode( + ReconfigShmem->join_marker_request_word, &request_operation, &target_node) + && request_operation == join_qvotec_inflight_marker_operation; + if (call_matches && operation == CLUSTER_JOIN_MARKER_MAILBOX_WRITE_EXACT) { if (verified_image96 != NULL) { call_matches = false; clear_payload = true; @@ -9199,32 +8483,25 @@ cluster_reconfig_join_qvotec_complete( if (acked) { call_matches = verified_image96 != NULL - && cluster_replacement_marker_v3_decode( - verified_image96, target_node, &verified_marker) - && verified_marker.phase - == CLUSTER_JCMK_REPLACEMENT_PHASE_COMMITTED_CLOSED + && cluster_replacement_marker_v3_decode(verified_image96, target_node, + &verified_marker) + && verified_marker.phase == CLUSTER_JCMK_REPLACEMENT_PHASE_COMMITTED_CLOSED && verified_marker.ready_state_generation == 0 - && cluster_replacement_marker_v3_encode( - &verified_marker, canonical) - && memcmp(canonical, verified_image96, - CLUSTER_JCMK_REPLACEMENT_BYTES) == 0; + && cluster_replacement_marker_v3_encode(&verified_marker, canonical) + && memcmp(canonical, verified_image96, CLUSTER_JCMK_REPLACEMENT_BYTES) == 0; } else if (verified_image96 != NULL) call_matches = false; } if (!call_matches) clear_payload = true; if (clear_payload) - memset(ReconfigShmem->join_pending_marker, 0, - sizeof(ReconfigShmem->join_pending_marker)); - if (call_matches && acked - && operation - == CLUSTER_JOIN_MARKER_MAILBOX_VERIFY_COMMITTED_CLOSED) + memset(ReconfigShmem->join_pending_marker, 0, sizeof(ReconfigShmem->join_pending_marker)); + if (call_matches && acked && operation == CLUSTER_JOIN_MARKER_MAILBOX_VERIFY_COMMITTED_CLOSED) memcpy(ReconfigShmem->join_pending_marker, verified_image96, CLUSTER_JCMK_REPLACEMENT_BYTES); pg_atomic_write_u32(&ReconfigShmem->join_marker_result, - call_matches && acked - ? CLUSTER_JOIN_MARKER_SUBMIT_ACK - : CLUSTER_JOIN_MARKER_SUBMIT_FAILED); + call_matches && acked ? CLUSTER_JOIN_MARKER_SUBMIT_ACK + : CLUSTER_JOIN_MARKER_SUBMIT_FAILED); pg_write_barrier(); pg_atomic_write_u64(&ReconfigShmem->join_marker_completion_seq, join_qvotec_inflight_marker_seq); @@ -9256,8 +8533,8 @@ static uint64 formation_qvotec_last_processed_seq = 0; static uint32 formation_bitmap_popcount(const uint8 *bmp, int bytes) { - uint32 pop = 0; - int i; + uint32 pop = 0; + int i; for (i = 0; i < bytes; i++) pop += pg_number_of_ones[bmp[i]]; @@ -9269,12 +8546,12 @@ formation_bitmap_popcount(const uint8 *bmp, int bytes) static uint64 cluster_reconfig_cold_formation_observed_incarnation(int32 node_id) { - uint64 inc = 0; - uint64 gen = 0; + uint64 inc = 0; + uint64 gen = 0; if (node_id < 0 || node_id >= CLUSTER_MAX_NODES) return 0; - (void) cluster_reconfig_get_observed_slot(node_id, &inc, &gen); + (void)cluster_reconfig_get_observed_slot(node_id, &inc, &gen); return gen > 0 ? inc : 0; } @@ -9284,25 +8561,21 @@ cluster_reconfig_cold_formation_observed_incarnation(int32 node_id) * consumer = qvotec). */ bool -cluster_reconfig_formation_qvotec_poll_pending( - ClusterFormationMarkerSubmitRequest *out) +cluster_reconfig_formation_qvotec_poll_pending(ClusterFormationMarkerSubmitRequest *out) { - uint64 seq_before; - uint64 seq_after; + uint64 seq_before; + uint64 seq_after; if (ReconfigShmem == NULL || out == NULL) return false; memset(out, 0, sizeof(*out)); - seq_before = pg_atomic_read_u64( - &ReconfigShmem->formation_marker_request_seq); - if (seq_before == 0 - || seq_before == formation_qvotec_last_processed_seq) - return false; /* nothing new */ + seq_before = pg_atomic_read_u64(&ReconfigShmem->formation_marker_request_seq); + if (seq_before == 0 || seq_before == formation_qvotec_last_processed_seq) + return false; /* nothing new */ pg_read_barrier(); *out = ReconfigShmem->formation_marker_request; pg_read_barrier(); - seq_after = pg_atomic_read_u64( - &ReconfigShmem->formation_marker_request_seq); + seq_after = pg_atomic_read_u64(&ReconfigShmem->formation_marker_request_seq); if (seq_before != seq_after) return false; formation_qvotec_last_processed_seq = seq_before; @@ -9314,12 +8587,10 @@ cluster_reconfig_formation_qvotec_complete(bool success) { if (ReconfigShmem == NULL) return; - pg_atomic_write_u32(&ReconfigShmem->formation_marker_result, - success ? 1 : 0); + pg_atomic_write_u32(&ReconfigShmem->formation_marker_result, success ? 1 : 0); pg_write_barrier(); pg_atomic_write_u64(&ReconfigShmem->formation_marker_completion_seq, - pg_atomic_read_u64( - &ReconfigShmem->formation_marker_request_seq)); + pg_atomic_read_u64(&ReconfigShmem->formation_marker_request_seq)); cluster_lmon_marker_complete_wakeup(); } @@ -9331,34 +8602,28 @@ cluster_reconfig_formation_qvotec_note_max_generation(uint64 generation) { if (ReconfigShmem == NULL) return; - if (generation - > pg_atomic_read_u64(&ReconfigShmem->formation_marker_max_generation)) - pg_atomic_write_u64(&ReconfigShmem->formation_marker_max_generation, - generation); + if (generation > pg_atomic_read_u64(&ReconfigShmem->formation_marker_max_generation)) + pg_atomic_write_u64(&ReconfigShmem->formation_marker_max_generation, generation); } /* qvotec publishes this node's OWN region-7 slot observation (CRC-valid * COMMITTED marker only). The cold-formation admission consumes it. */ void -cluster_reconfig_formation_qvotec_publish_observed( - const ClusterFormationCommitMarker *marker, - const uint64 *incarnation_by_node) +cluster_reconfig_formation_qvotec_publish_observed(const ClusterFormationCommitMarker *marker, + const uint64 *incarnation_by_node) { - int i; + int i; if (ReconfigShmem == NULL || marker == NULL) return; for (i = 0; i < CLUSTER_MAX_NODES; i++) - pg_atomic_write_u64( - &ReconfigShmem->observed_formation_marker_incarnation[i], - incarnation_by_node != NULL ? incarnation_by_node[i] : 0); - pg_atomic_write_u64(&ReconfigShmem->observed_formation_marker_epoch, - marker->formation_epoch); + pg_atomic_write_u64(&ReconfigShmem->observed_formation_marker_incarnation[i], + incarnation_by_node != NULL ? incarnation_by_node[i] : 0); + pg_atomic_write_u64(&ReconfigShmem->observed_formation_marker_epoch, marker->formation_epoch); pg_atomic_write_u64(&ReconfigShmem->observed_formation_marker_arbiter_node, marker->arbiter_node); - pg_atomic_write_u64( - &ReconfigShmem->observed_formation_marker_arbiter_incarnation, - marker->arbiter_incarnation); + pg_atomic_write_u64(&ReconfigShmem->observed_formation_marker_arbiter_incarnation, + marker->arbiter_incarnation); pg_write_barrier(); pg_atomic_write_u64(&ReconfigShmem->observed_formation_marker_generation, marker->formation_generation); @@ -9375,11 +8640,10 @@ cluster_reconfig_formation_qvotec_clear_observed(void) /* Arbiter submit: stage the marker image + target member set into the * mailbox and wake qvotec. */ static bool -cluster_reconfig_formation_marker_submit( - const uint8 marker_bytes[CLUSTER_VOTING_SLOT_BYTES], - const uint8 *target_members) +cluster_reconfig_formation_marker_submit(const uint8 marker_bytes[CLUSTER_VOTING_SLOT_BYTES], + const uint8 *target_members) { - uint64 seq; + uint64 seq; if (ReconfigShmem == NULL || marker_bytes == NULL || target_members == NULL) return false; @@ -9387,16 +8651,15 @@ cluster_reconfig_formation_marker_submit( * the mailbox is single-producer (arbiter LMON) so no lock is needed * for the submit itself — just the torn-free seq pairing. */ seq = pg_atomic_read_u64(&ReconfigShmem->formation_marker_request_seq); - if (seq != pg_atomic_read_u64( - &ReconfigShmem->formation_marker_completion_seq) + if (seq != pg_atomic_read_u64(&ReconfigShmem->formation_marker_completion_seq) || seq == UINT64_MAX) - return false; /* in-flight or exhausted */ + return false; /* in-flight or exhausted */ memset(&ReconfigShmem->formation_marker_request, 0, sizeof(ReconfigShmem->formation_marker_request)); - memcpy(ReconfigShmem->formation_marker_request.marker_bytes, - marker_bytes, CLUSTER_VOTING_SLOT_BYTES); - memcpy(ReconfigShmem->formation_marker_request.target_members, - target_members, CLUSTER_FORMATION_MARKER_BITMAP_BYTES); + memcpy(ReconfigShmem->formation_marker_request.marker_bytes, marker_bytes, + CLUSTER_VOTING_SLOT_BYTES); + memcpy(ReconfigShmem->formation_marker_request.target_members, target_members, + CLUSTER_FORMATION_MARKER_BITMAP_BYTES); ReconfigShmem->formation_marker_request.active = true; pg_write_barrier(); pg_atomic_write_u64(&ReconfigShmem->formation_marker_request_seq, seq + 1); @@ -9417,31 +8680,28 @@ cluster_reconfig_formation_marker_submit( * cluster, not a cold co-boot). */ static ClusterColdFormationVerdict -cluster_reconfig_cold_formation_window(uint64 *out_coboot_lo, - uint64 *out_coboot_hi) +cluster_reconfig_cold_formation_window(uint64 *out_coboot_lo, uint64 *out_coboot_hi) { - uint64 fresh_lo = 0; - uint64 fresh_hi = 0; - uint32 declared = 0; - uint32 fresh_count = 0; - bool survivor = false; - int i; + uint64 fresh_lo = 0; + uint64 fresh_hi = 0; + uint32 declared = 0; + uint32 fresh_count = 0; + bool survivor = false; + int i; if (cluster_membership_get_state(cluster_node_id) == CLUSTER_MEMBER_MEMBER) return CLUSTER_COLD_FORMATION_SURVIVOR; /* this node is already formed */ - for (i = 0; i < CLUSTER_MAX_NODES; i++) - { - uint64 inc = 0; - uint64 gen = 0; - uint64 ep; - bool fresh; + for (i = 0; i < CLUSTER_MAX_NODES; i++) { + uint64 inc = 0; + uint64 gen = 0; + uint64 ep; + bool fresh; if (cluster_conf_lookup_node(i) == NULL) continue; declared++; - if (i == cluster_node_id) - { + if (i == cluster_node_id) { fresh_count++; if (i < 64) fresh_lo |= UINT64_C(1) << i; @@ -9449,11 +8709,10 @@ cluster_reconfig_cold_formation_window(uint64 *out_coboot_lo, fresh_hi |= UINT64_C(1) << (i - 64); continue; } - (void) cluster_reconfig_get_observed_slot(i, &inc, &gen); + (void)cluster_reconfig_get_observed_slot(i, &inc, &gen); ep = cluster_reconfig_get_observed_epoch(i); fresh = cluster_reconfig_get_observed_fresh_alive(i); - if (fresh && gen > 0) - { + if (fresh && gen > 0) { fresh_count++; if (i < 64) fresh_lo |= UINT64_C(1) << i; @@ -9483,23 +8742,21 @@ cluster_reconfig_cold_formation_admit(const ClusterFormationCommitMarker *marker const uint64 *incarnation_by_node) { ClusterXidStripeJoinVerdict stripe_verdict; - uint64 self_incarnation; - int i; + uint64 self_incarnation; + int i; if (marker == NULL || incarnation_by_node == NULL) return; if (cluster_node_id < 0 || cluster_node_id >= CLUSTER_MAX_NODES - || (marker->admitted_nodes[cluster_node_id / 8] - & (uint8) (1u << (cluster_node_id % 8))) == 0) + || (marker->admitted_nodes[cluster_node_id / 8] & (uint8)(1u << (cluster_node_id % 8))) + == 0) return; self_incarnation = cluster_qvotec_get_self_incarnation(); - if (self_incarnation == 0 - || incarnation_by_node[cluster_node_id] != self_incarnation) + if (self_incarnation == 0 || incarnation_by_node[cluster_node_id] != self_incarnation) return; - if (cluster_membership_get_last_admitted_incarnation(cluster_node_id) != 0) - { + if (cluster_membership_get_last_admitted_incarnation(cluster_node_id) != 0) { cold_formation_state.admission_done = true; - return; /* already admitted */ + return; /* already admitted */ } /* @@ -9512,54 +8769,44 @@ cluster_reconfig_cold_formation_admit(const ClusterFormationCommitMarker *marker * is never allowed to seed PGXA here. */ stripe_verdict = cluster_xid_stripe_join_gate(false); - if (stripe_verdict != CLUSTER_XID_STRIPE_JOIN_PROCEED) - { + if (stripe_verdict != CLUSTER_XID_STRIPE_JOIN_PROCEED) { static bool stripe_formation_admit_logged = false; - if (!stripe_formation_admit_logged) - { + if (!stripe_formation_admit_logged) { stripe_formation_admit_logged = true; if (stripe_verdict == CLUSTER_XID_STRIPE_JOIN_REFUSE) - ereport(LOG, - (errcode(ERRCODE_CLUSTER_XID_STRIPE_JOIN_MISMATCH), - errmsg("cluster xid stripe: refusing cold-formation " - "admission of node %d — stripe mode handshake " - "mismatch (SQLSTATE 53RB1)", - cluster_node_id), - errhint("cluster.xid_striping must match the cluster's " - "durable activation state on every node; repair the " - "voting-disk stripe region if it is corrupt."))); + ereport(LOG, (errcode(ERRCODE_CLUSTER_XID_STRIPE_JOIN_MISMATCH), + errmsg("cluster xid stripe: refusing cold-formation " + "admission of node %d — stripe mode handshake " + "mismatch (SQLSTATE 53RB1)", + cluster_node_id), + errhint("cluster.xid_striping must match the cluster's " + "durable activation state on every node; repair the " + "voting-disk stripe region if it is corrupt."))); else - ereport(LOG, - (errmsg("cluster xid stripe: holding cold-formation " - "admission of node %d until the stripe activation " - "state is resolved", - cluster_node_id))); + ereport(LOG, (errmsg("cluster xid stripe: holding cold-formation " + "admission of node %d until the stripe activation " + "state is resolved", + cluster_node_id))); } return; } - for (i = 0; i < CLUSTER_MAX_NODES; i++) - { - if ((marker->admitted_nodes[i / 8] - & (uint8) (1u << (i % 8))) == 0) + for (i = 0; i < CLUSTER_MAX_NODES; i++) { + if ((marker->admitted_nodes[i / 8] & (uint8)(1u << (i % 8))) == 0) continue; if (incarnation_by_node[i] == 0) - return; /* marker incomplete: never admit */ + return; /* marker incomplete: never admit */ cluster_membership_record_admitted(i, incarnation_by_node[i]); } - for (i = 0; i < CLUSTER_MAX_NODES; i++) - { - if ((marker->admitted_nodes[i / 8] - & (uint8) (1u << (i % 8))) == 0) + for (i = 0; i < CLUSTER_MAX_NODES; i++) { + if ((marker->admitted_nodes[i / 8] & (uint8)(1u << (i % 8))) == 0) continue; /* exact equality — the floor must have landed exactly */ - if (cluster_membership_get_last_admitted_incarnation(i) - != incarnation_by_node[i]) - return; /* did not land: no MEMBER */ + if (cluster_membership_get_last_admitted_incarnation(i) != incarnation_by_node[i]) + return; /* did not land: no MEMBER */ } for (i = 0; i < CLUSTER_MAX_NODES; i++) - if ((marker->admitted_nodes[i / 8] - & (uint8) (1u << (i % 8))) != 0) + if ((marker->admitted_nodes[i / 8] & (uint8)(1u << (i % 8))) != 0) cluster_membership_set_state(i, CLUSTER_MEMBER_MEMBER); /* * RF-ROOT P9 verification / cold-formation cold-formation ruling: @@ -9576,13 +8823,11 @@ cluster_reconfig_cold_formation_admit(const ClusterFormationCommitMarker *marker ReconfigShmem->self_join_failed = 0; ReconfigShmem->self_join_deadline_us = 0; cold_formation_state.admission_done = true; - ereport(LOG, - (errmsg("cluster membership: node %d cold formation admitted " - "(generation %llu, %u members) via quorum-majority " - "formation marker", - cluster_node_id, - (unsigned long long) marker->formation_generation, - (unsigned) marker->n_admitted))); + ereport(LOG, (errmsg("cluster membership: node %d cold formation admitted " + "(generation %llu, %u members) via quorum-majority " + "formation marker", + cluster_node_id, (unsigned long long)marker->formation_generation, + (unsigned)marker->n_admitted))); } /* @@ -9592,221 +8837,187 @@ cluster_reconfig_cold_formation_admit(const ClusterFormationCommitMarker *marker void cluster_reconfig_cold_formation_tick(void) { - uint64 coboot_lo; - uint64 coboot_hi; - int arbiter; + uint64 coboot_lo; + uint64 coboot_hi; + int arbiter; if (cold_formation_state.admission_done) return; /* 1. Observation window (three-state; quorum-stable, no survivor * past INITIAL). */ - switch (cluster_reconfig_cold_formation_window(&coboot_lo, &coboot_hi)) - { - case CLUSTER_COLD_FORMATION_PENDING: - cold_formation_state.observe_ticks = 0; - cold_formation_state.observe_passed = false; - cold_formation_state.arbiter_submitted = false; - return; - case CLUSTER_COLD_FORMATION_SURVIVOR: - /* A formed survivor is live: never a cold formation. (This + switch (cluster_reconfig_cold_formation_window(&coboot_lo, &coboot_hi)) { + case CLUSTER_COLD_FORMATION_PENDING: + cold_formation_state.observe_ticks = 0; + cold_formation_state.observe_passed = false; + cold_formation_state.arbiter_submitted = false; + return; + case CLUSTER_COLD_FORMATION_SURVIVOR: + /* A formed survivor is live: never a cold formation. (This * node stays un-formed and the ordinary join/JCMK path takes * over.) */ - cold_formation_state.observe_ticks = 0; - cold_formation_state.observe_passed = false; - cold_formation_state.arbiter_submitted = false; - return; - case CLUSTER_COLD_FORMATION_COBOOT: - break; + cold_formation_state.observe_ticks = 0; + cold_formation_state.observe_passed = false; + cold_formation_state.arbiter_submitted = false; + return; + case CLUSTER_COLD_FORMATION_COBOOT: + break; } if (++cold_formation_state.observe_ticks < CLUSTER_COLD_FORMATION_WINDOW_TICKS) return; - if (!cold_formation_state.observe_passed) - { + if (!cold_formation_state.observe_passed) { cold_formation_state.observe_passed = true; cold_formation_state.coboot_lo = coboot_lo; cold_formation_state.coboot_hi = coboot_hi; cold_formation_state.arbiter_submitted = false; - ereport(LOG, - (errmsg("cluster membership: node %d cold-formation window " - "passed (co-boot set %llx/%llx)", - cluster_node_id, - (unsigned long long) coboot_lo, - (unsigned long long) coboot_hi))); + ereport(LOG, (errmsg("cluster membership: node %d cold-formation window " + "passed (co-boot set %llx/%llx)", + cluster_node_id, (unsigned long long)coboot_lo, + (unsigned long long)coboot_hi))); } { - uint8 coboot_bmp[CLUSTER_FORMATION_MARKER_BITMAP_BYTES]; + uint8 coboot_bmp[CLUSTER_FORMATION_MARKER_BITMAP_BYTES]; memset(coboot_bmp, 0, sizeof(coboot_bmp)); for (int i = 0; i < 64 && i < CLUSTER_MAX_NODES; i++) if ((coboot_lo & (UINT64_C(1) << i)) != 0) - coboot_bmp[i / 8] |= (uint8) (1u << (i % 8)); + coboot_bmp[i / 8] |= (uint8)(1u << (i % 8)); arbiter = dead_bitmap_lowest_bit_set(coboot_bmp); } - if (arbiter < 0) - { + if (arbiter < 0) { cold_formation_state.observe_passed = false; return; } - if (arbiter == cluster_node_id) - { + if (arbiter == cluster_node_id) { /* ---- arbiter: submit the COMMITTED marker ---- */ ClusterFormationCommitMarker marker; - uint64 incarnation_by_node[CLUSTER_MAX_NODES]; - uint8 marker_bytes[CLUSTER_VOTING_SLOT_BYTES]; - uint64 generation; - uint64 comp_seq; - uint32 result; - int i; - - if (cold_formation_state.arbiter_submitted) - { - comp_seq = pg_atomic_read_u64( - &ReconfigShmem->formation_marker_completion_seq); + uint64 incarnation_by_node[CLUSTER_MAX_NODES]; + uint8 marker_bytes[CLUSTER_VOTING_SLOT_BYTES]; + uint64 generation; + uint64 comp_seq; + uint32 result; + int i; + + if (cold_formation_state.arbiter_submitted) { + comp_seq = pg_atomic_read_u64(&ReconfigShmem->formation_marker_completion_seq); if (comp_seq != cold_formation_state.arbiter_seq) - return; /* qvotec still writing */ - result = pg_atomic_read_u32( - &ReconfigShmem->formation_marker_result); - if (result == 0) - { + return; /* qvotec still writing */ + result = pg_atomic_read_u32(&ReconfigShmem->formation_marker_result); + if (result == 0) { /* Failed to reach majority — retry the whole submission. */ cold_formation_state.arbiter_submitted = false; return; } /* Marker durable: admit from the marker we built. */ memset(incarnation_by_node, 0, sizeof(incarnation_by_node)); - for (i = 0; i < CLUSTER_MAX_NODES; i++) - { - uint64 bit = i < 64 - ? (cold_formation_state.coboot_lo - & (UINT64_C(1) << i)) - : (cold_formation_state.coboot_hi - & (UINT64_C(1) << (i - 64))); + for (i = 0; i < CLUSTER_MAX_NODES; i++) { + uint64 bit = i < 64 ? (cold_formation_state.coboot_lo & (UINT64_C(1) << i)) + : (cold_formation_state.coboot_hi & (UINT64_C(1) << (i - 64))); if (bit != 0) incarnation_by_node[i] = i == cluster_node_id - ? cluster_qvotec_get_self_incarnation() - : cluster_reconfig_cold_formation_observed_incarnation(i); + ? cluster_qvotec_get_self_incarnation() + : cluster_reconfig_cold_formation_observed_incarnation(i); } /* Re-decode the marker we submitted (self-proof). */ if (!cluster_formation_marker_decode( - ReconfigShmem->formation_marker_request.marker_bytes, - &marker, incarnation_by_node)) - return; /* cannot happen: we encoded it */ + ReconfigShmem->formation_marker_request.marker_bytes, &marker, + incarnation_by_node)) + return; /* cannot happen: we encoded it */ cluster_reconfig_cold_formation_admit(&marker, incarnation_by_node); return; } /* Build the marker: max existing generation + 1 (monotonic * takeover), CURRENT boot incarnations (never inherited). */ - generation = pg_atomic_read_u64( - &ReconfigShmem->formation_marker_max_generation) + 1; + generation = pg_atomic_read_u64(&ReconfigShmem->formation_marker_max_generation) + 1; memset(&marker, 0, sizeof(marker)); marker.magic = CLUSTER_FORMATION_MARKER_MAGIC; marker.version = CLUSTER_FORMATION_MARKER_VERSION; marker.phase = CLUSTER_FORMATION_MARKER_PHASE_COMMITTED; marker.formation_generation = generation; marker.formation_epoch = cluster_epoch_get_current(); - marker.arbiter_node = (uint64) cluster_node_id; - marker.arbiter_incarnation - = cluster_qvotec_get_self_incarnation(); + marker.arbiter_node = (uint64)cluster_node_id; + marker.arbiter_incarnation = cluster_qvotec_get_self_incarnation(); cold_formation_commit_nonce++; marker.commit_nonce = cold_formation_commit_nonce; - for (i = 0; i < CLUSTER_MAX_NODES; i++) - { - uint64 bit = i < 64 - ? (UINT64_C(1) << i) - : (cold_formation_state.coboot_hi - & (UINT64_C(1) << (i - 64))); + for (i = 0; i < CLUSTER_MAX_NODES; i++) { + uint64 bit = i < 64 ? (UINT64_C(1) << i) + : (cold_formation_state.coboot_hi & (UINT64_C(1) << (i - 64))); - if (i < 64) - { + if (i < 64) { if ((cold_formation_state.coboot_lo & bit) != 0) - marker.admitted_nodes[i / 8] - |= (uint8) (1u << (i % 8)); - } - else if (bit != 0) - marker.admitted_nodes[i / 8] - |= (uint8) (1u << (i % 8)); + marker.admitted_nodes[i / 8] |= (uint8)(1u << (i % 8)); + } else if (bit != 0) + marker.admitted_nodes[i / 8] |= (uint8)(1u << (i % 8)); } memset(incarnation_by_node, 0, sizeof(incarnation_by_node)); - for (i = 0; i < CLUSTER_MAX_NODES; i++) - { - if ((marker.admitted_nodes[i / 8] - & (uint8) (1u << (i % 8))) == 0) + for (i = 0; i < CLUSTER_MAX_NODES; i++) { + if ((marker.admitted_nodes[i / 8] & (uint8)(1u << (i % 8))) == 0) continue; - incarnation_by_node[i] - = i == cluster_node_id - ? cluster_qvotec_get_self_incarnation() - : cluster_reconfig_cold_formation_observed_incarnation(i); + incarnation_by_node[i] = i == cluster_node_id + ? cluster_qvotec_get_self_incarnation() + : cluster_reconfig_cold_formation_observed_incarnation(i); if (incarnation_by_node[i] == 0) - return; /* peer not observed yet: retry next tick */ + return; /* peer not observed yet: retry next tick */ } - marker.n_admitted = (uint16) formation_bitmap_popcount( + marker.n_admitted = (uint16)formation_bitmap_popcount( marker.admitted_nodes, CLUSTER_FORMATION_MARKER_BITMAP_BYTES); cluster_formation_marker_compute_crc(&marker); - if (!cluster_formation_marker_encode(&marker, incarnation_by_node, - marker_bytes)) + if (!cluster_formation_marker_encode(&marker, incarnation_by_node, marker_bytes)) return; { - uint8 targets[CLUSTER_FORMATION_MARKER_BITMAP_BYTES]; + uint8 targets[CLUSTER_FORMATION_MARKER_BITMAP_BYTES]; - memcpy(targets, marker.admitted_nodes, - CLUSTER_FORMATION_MARKER_BITMAP_BYTES); - if (!cluster_reconfig_formation_marker_submit(marker_bytes, - targets)) + memcpy(targets, marker.admitted_nodes, CLUSTER_FORMATION_MARKER_BITMAP_BYTES); + if (!cluster_reconfig_formation_marker_submit(marker_bytes, targets)) return; } - cold_formation_state.arbiter_seq = pg_atomic_read_u64( - &ReconfigShmem->formation_marker_request_seq); + cold_formation_state.arbiter_seq + = pg_atomic_read_u64(&ReconfigShmem->formation_marker_request_seq); cold_formation_state.arbiter_submitted = true; - ereport(LOG, - (errmsg("cluster membership: node %d cold-formation arbiter " - "submitted formation marker (generation %llu, " - "members %u)", - cluster_node_id, - (unsigned long long) generation, - (unsigned) marker.n_admitted))); + ereport(LOG, (errmsg("cluster membership: node %d cold-formation arbiter " + "submitted formation marker (generation %llu, " + "members %u)", + cluster_node_id, (unsigned long long)generation, + (unsigned)marker.n_admitted))); return; } /* ---- non-arbiter: wait for our own region-7 slot marker ---- */ { - uint64 generation; - uint64 incarnation_by_node[CLUSTER_MAX_NODES]; - int i; + uint64 generation; + uint64 incarnation_by_node[CLUSTER_MAX_NODES]; + int i; - generation = pg_atomic_read_u64( - &ReconfigShmem->observed_formation_marker_generation); + generation = pg_atomic_read_u64(&ReconfigShmem->observed_formation_marker_generation); if (generation == 0) - return; /* arbiter has not written yet */ + return; /* arbiter has not written yet */ memset(incarnation_by_node, 0, sizeof(incarnation_by_node)); for (i = 0; i < CLUSTER_MAX_NODES; i++) - incarnation_by_node[i] = pg_atomic_read_u64( - &ReconfigShmem->observed_formation_marker_incarnation[i]); + incarnation_by_node[i] + = pg_atomic_read_u64(&ReconfigShmem->observed_formation_marker_incarnation[i]); /* Our own incarnation in the marker must be EXACTLY ours. */ - if (incarnation_by_node[cluster_node_id] - != cluster_qvotec_get_self_incarnation()) - return; /* not our marker: keep waiting */ + if (incarnation_by_node[cluster_node_id] != cluster_qvotec_get_self_incarnation()) + return; /* not our marker: keep waiting */ { ClusterFormationCommitMarker marker; memset(&marker, 0, sizeof(marker)); marker.formation_generation = generation; - marker.formation_epoch = pg_atomic_read_u64( - &ReconfigShmem->observed_formation_marker_epoch); - marker.arbiter_node = pg_atomic_read_u64( - &ReconfigShmem->observed_formation_marker_arbiter_node); - marker.arbiter_incarnation = pg_atomic_read_u64( - &ReconfigShmem->observed_formation_marker_arbiter_incarnation); + marker.formation_epoch + = pg_atomic_read_u64(&ReconfigShmem->observed_formation_marker_epoch); + marker.arbiter_node + = pg_atomic_read_u64(&ReconfigShmem->observed_formation_marker_arbiter_node); + marker.arbiter_incarnation + = pg_atomic_read_u64(&ReconfigShmem->observed_formation_marker_arbiter_incarnation); for (i = 0; i < CLUSTER_MAX_NODES; i++) if (incarnation_by_node[i] != 0) - marker.admitted_nodes[i / 8] - |= (uint8) (1u << (i % 8)); - marker.n_admitted = (uint16) formation_bitmap_popcount( + marker.admitted_nodes[i / 8] |= (uint8)(1u << (i % 8)); + marker.n_admitted = (uint16)formation_bitmap_popcount( marker.admitted_nodes, CLUSTER_FORMATION_MARKER_BITMAP_BYTES); cluster_reconfig_cold_formation_admit(&marker, incarnation_by_node); } @@ -9826,8 +9037,7 @@ cluster_reconfig_publish_formation_qvotec_latch(struct Latch *latch) { if (ReconfigShmem == NULL) return; - if (ReconfigShmem->formation_qvotec_latch == NULL) - { + if (ReconfigShmem->formation_qvotec_latch == NULL) { ReconfigShmem->formation_qvotec_latch = latch; before_shmem_exit(formation_clear_qvotec_latch, 0); } @@ -9963,14 +9173,12 @@ cluster_reconfig_apply_join_as_coordinator( memset(external_authorized, 0, sizeof(external_authorized)); for (i = 0; i < CLUSTER_MAX_NODES; i++) if (dead_bitmap_test_bit(join_bitmap, i)) - external_authorized[i] = - cluster_reconfig_external_rejoin_authorized( - i, joiner_incarnations[i]); + external_authorized[i] + = cluster_reconfig_external_rejoin_authorized(i, joiner_incarnations[i]); cssd_dead_generation = cluster_cssd_get_dead_generation(); LWLockAcquire(&ReconfigShmem->lock, LW_SHARED); - memcpy(pending_dead, ReconfigShmem->last_applied.dead_bitmap, - sizeof(pending_dead)); + memcpy(pending_dead, ReconfigShmem->last_applied.dead_bitmap, sizeof(pending_dead)); for (i = 0; i < CLUSTER_RECONFIG_DEAD_BITMAP_BYTES; i++) pending_dead[i] |= ReconfigShmem->fast_rejoin_bitmap[i]; LWLockRelease(&ReconfigShmem->lock); @@ -10005,9 +9213,9 @@ cluster_reconfig_apply_join_as_coordinator( LWLockRelease(&ReconfigShmem->lock); memset(&evt, 0, sizeof(evt)); - evt.event_id - = cluster_reconfig_compute_event_id_v2(RECONFIG_KIND_JOIN_PENDING, pending_dead, join_bitmap, - joiner_incarnations, cssd_dead_generation); + evt.event_id = cluster_reconfig_compute_event_id_v2(RECONFIG_KIND_JOIN_PENDING, pending_dead, + join_bitmap, joiner_incarnations, + cssd_dead_generation); evt.coordinator_node_id = coordinator_node_id; evt.old_epoch = old_epoch; evt.new_epoch = new_epoch; @@ -10082,22 +9290,19 @@ cluster_reconfig_commit_member(int32 node_id, uint64 admitted_incarnation) /* STOP04 §11.9 C: after the fully normalized COMMITTED candidate exists, * consume the exact READY operation once and only then expose the JCMK to * qvotec. No marker mailbox operation may precede this call. */ - external_required = - cluster_reconfig_external_rejoin_required(node_id); + external_required = cluster_reconfig_external_rejoin_required(node_id); if (external_required) { ClusterExternalRejoinSlot *slot = &external_rejoin_slots[node_id]; ClusterReconfigRejoinPendingSnapshotV1 current_pending; memset(¤t_pending, 0, sizeof(current_pending)); - if (slot->op == NULL || - slot->phase != CLUSTER_EXTERNAL_REJOIN_COMMIT_READY || - slot->candidate_incarnation != admitted_incarnation || - !cluster_reconfig_rejoin_pending_snapshot(&slot->failure, - admitted_incarnation, ¤t_pending) || - memcmp(¤t_pending, &slot->commit_pending, - sizeof(current_pending)) != 0 || - !cluster_external_fence_rejoin_consume_nowait(slot->op, - ¤t_pending, &m, &reason)) { + if (slot->op == NULL || slot->phase != CLUSTER_EXTERNAL_REJOIN_COMMIT_READY + || slot->candidate_incarnation != admitted_incarnation + || !cluster_reconfig_rejoin_pending_snapshot(&slot->failure, admitted_incarnation, + ¤t_pending) + || memcmp(¤t_pending, &slot->commit_pending, sizeof(current_pending)) != 0 + || !cluster_external_fence_rejoin_consume_nowait(slot->op, ¤t_pending, &m, + &reason)) { cluster_reconfig_external_rejoin_release_slot(node_id); return false; } @@ -10106,8 +9311,7 @@ cluster_reconfig_commit_member(int32 node_id, uint64 admitted_incarnation) cluster_marker_async_init(&join_commit_stage.async); cluster_marker_async_init(&join_commit_stage.fence_async); join_commit_stage.marker = m; - memset(&join_commit_stage.fence_marker, 0, - sizeof(join_commit_stage.fence_marker)); + memset(&join_commit_stage.fence_marker, 0, sizeof(join_commit_stage.fence_marker)); memset(&join_commit_stage.event, 0, sizeof(join_commit_stage.event)); join_commit_stage.expected_last_event_id = 0; join_commit_stage.node_id = node_id; @@ -10605,17 +9809,16 @@ cluster_reconfig_submit_replacement_marker_v3_async( bool cluster_reconfig_verify_replacement_committed_closed_async( - ClusterMarkerAsync *a pg_attribute_unused(), - int32 target_node pg_attribute_unused(), + ClusterMarkerAsync *a pg_attribute_unused(), int32 target_node pg_attribute_unused(), TimestampTz now pg_attribute_unused()) { return false; } bool -cluster_reconfig_join_qvotec_poll_pending( - ClusterJoinMarkerMailboxOperationV1 *operation_out, - int32 *target_node_out, void *write_slot512_out pg_attribute_unused()) +cluster_reconfig_join_qvotec_poll_pending(ClusterJoinMarkerMailboxOperationV1 *operation_out, + int32 *target_node_out, + void *write_slot512_out pg_attribute_unused()) { if (operation_out != NULL) *operation_out = CLUSTER_JOIN_MARKER_MAILBOX_WRITE_EXACT; @@ -10627,8 +9830,7 @@ cluster_reconfig_join_qvotec_poll_pending( void cluster_reconfig_join_qvotec_complete( ClusterJoinMarkerMailboxOperationV1 operation pg_attribute_unused(), - bool acked pg_attribute_unused(), - const uint8 *verified_image96 pg_attribute_unused()) + bool acked pg_attribute_unused(), const uint8 *verified_image96 pg_attribute_unused()) {} bool @@ -10643,8 +9845,7 @@ cluster_reconfig_formation_qvotec_complete(bool success pg_attribute_unused()) {} void -cluster_reconfig_formation_qvotec_note_max_generation( - uint64 generation pg_attribute_unused()) +cluster_reconfig_formation_qvotec_note_max_generation(uint64 generation pg_attribute_unused()) {} void @@ -10666,10 +9867,10 @@ cluster_reconfig_cold_formation_tick(void) {} bool -cluster_reconfig_qvotec_lifecycle_transition( - ClusterQvotecMailbox *authority_mailbox pg_attribute_unused(), - pg_atomic_uint32 *qvotec_status pg_attribute_unused(), - ClusterQvotecStatus next_status pg_attribute_unused()) +cluster_reconfig_qvotec_lifecycle_transition(ClusterQvotecMailbox *authority_mailbox + pg_attribute_unused(), + pg_atomic_uint32 *qvotec_status pg_attribute_unused(), + ClusterQvotecStatus next_status pg_attribute_unused()) { return false; } @@ -10715,17 +9916,17 @@ cluster_reconfig_publish_replacement_member_closed( } bool -cluster_reconfig_qvotec_observe_replacement_admitted( - const int *fds pg_attribute_unused(), int n_disks pg_attribute_unused(), - uint64 live_incarnation pg_attribute_unused()) +cluster_reconfig_qvotec_observe_replacement_admitted(const int *fds pg_attribute_unused(), + int n_disks pg_attribute_unused(), + uint64 live_incarnation pg_attribute_unused()) { return false; } bool -cluster_reconfig_open_replacement_admission( - const ClusterReplacementEpisode *expected_episode pg_attribute_unused(), - uint32 expected_state_generation pg_attribute_unused()) +cluster_reconfig_open_replacement_admission(const ClusterReplacementEpisode *expected_episode + pg_attribute_unused(), + uint32 expected_state_generation pg_attribute_unused()) { return false; } @@ -10782,8 +9983,7 @@ cluster_reconfig_lmon_snapshot_replacement_admitted( } bool -cluster_reconfig_snapshot_initial_clean_formation( - ClusterInitialCleanFormationSnapshot *out) +cluster_reconfig_snapshot_initial_clean_formation(ClusterInitialCleanFormationSnapshot *out) { if (out != NULL) memset(out, 0, sizeof(*out)); @@ -10791,9 +9991,8 @@ cluster_reconfig_snapshot_initial_clean_formation( } bool -cluster_reconfig_lmon_snapshot_admitted_membership( - uint64 *out_members_lo, uint64 *out_members_hi, - uint64 *out_formation_epoch) +cluster_reconfig_lmon_snapshot_admitted_membership(uint64 *out_members_lo, uint64 *out_members_hi, + uint64 *out_formation_epoch) { if (out_members_lo != NULL) *out_members_lo = 0; @@ -10805,8 +10004,7 @@ cluster_reconfig_lmon_snapshot_admitted_membership( } bool -cluster_reconfig_lmon_snapshot_r4_membership( - ClusterR4MembershipSnapshot *out) +cluster_reconfig_lmon_snapshot_r4_membership(ClusterR4MembershipSnapshot *out) { if (out != NULL) memset(out, 0, sizeof(*out)); @@ -10829,7 +10027,7 @@ cluster_reconfig_r4_prerequisite_snapshot(void) return (ClusterR4PrerequisiteSnapshot){ .status = CLUSTER_R4_PREREQUISITE_RF_DEFERRED, .ready = false, - .reserved0 = {0, 0, 0}, + .reserved0 = { 0, 0, 0 }, .target_node_id = -1, }; } diff --git a/src/backend/cluster/cluster_recovery_anchor.c b/src/backend/cluster/cluster_recovery_anchor.c index 17d2c6f93ba..48c971ad831 100644 --- a/src/backend/cluster/cluster_recovery_anchor.c +++ b/src/backend/cluster/cluster_recovery_anchor.c @@ -359,21 +359,19 @@ checkpoint_phase4_publisher_is_current(uint64 self_incarnation) own_thread = cluster_wal_thread_id(); if (own_thread < XLP_THREAD_ID_FIRST_REAL || own_thread > CLUSTER_WAL_THREAD_MAX || !cluster_wal_thread_dir_configured() || !cluster_wal_thread_dir_validated() - || cluster_wal_thread_dump_thread_id() != own_thread - || !cluster_wal_state_registry_ready()) + || cluster_wal_thread_dump_thread_id() != own_thread || !cluster_wal_state_registry_ready()) return false; phase4_started_at = cluster_phase_started_at(CLUSTER_PHASE_4_NORMAL); stats_spawned_at = cluster_stats_spawned_at(); - if (phase4_started_at == 0 || stats_spawned_at == 0 - || stats_spawned_at < phase4_started_at) + if (phase4_started_at == 0 || stats_spawned_at == 0 || stats_spawned_at < phase4_started_at) return false; memset(&slot, 0, sizeof(slot)); verdict = cluster_wal_state_read_slot(own_thread, &slot); return verdict == CLUSTER_WAL_SLOT_OK && slot.thread_id == own_thread - && slot.node_id == cluster_node_id && slot.state == CLUSTER_WAL_SLOT_STATE_ACTIVE - && slot.started_at == stats_spawned_at && slot.started_at >= phase4_started_at; + && slot.node_id == cluster_node_id && slot.state == CLUSTER_WAL_SLOT_STATE_ACTIVE + && slot.started_at == stats_spawned_at && slot.started_at >= phase4_started_at; } static bool @@ -381,8 +379,7 @@ checkpoint_publisher_is_current(uint64 expected_sysid) { uint64 self_incarnation; - if (expected_sysid == 0 || cluster_node_id < 0 - || cluster_node_id >= CLUSTER_MAX_NODES) + if (expected_sysid == 0 || cluster_node_id < 0 || cluster_node_id >= CLUSTER_MAX_NODES) return false; /* The delegated EOR checkpointer runs before steady membership admission; * its existing boot-local OWNER handoff is the sole recovery-actor arm. */ @@ -398,17 +395,14 @@ checkpoint_publisher_is_current(uint64 expected_sysid) * CF(X). This restores the frozen clean-seed path without allowing a * formed or stale member to use native bootstrap as a publication bypass. */ - if (!cluster_enabled && cluster_controlfile_shared_authority - && self_incarnation == 0 + if (!cluster_enabled && cluster_controlfile_shared_authority && self_incarnation == 0 && cluster_membership_get_state(cluster_node_id) == CLUSTER_MEMBER_ABSENT && cluster_membership_get_last_admitted_incarnation(cluster_node_id) == 0 - && cluster_cf_exactly_one_declared_node() - && cluster_cf_held(ExclusiveLock)) + && cluster_cf_exactly_one_declared_node() && cluster_cf_held(ExclusiveLock)) return true; if (self_incarnation != 0 && cluster_membership_get_state(cluster_node_id) == CLUSTER_MEMBER_MEMBER - && cluster_membership_get_last_admitted_incarnation(cluster_node_id) - == self_incarnation) + && cluster_membership_get_last_admitted_incarnation(cluster_node_id) == self_incarnation) return true; return checkpoint_phase4_publisher_is_current(self_incarnation); } @@ -468,8 +462,7 @@ cluster_recovery_anchor_publish_checkpoint(XLogRecPtr checkpoint_lsn, * this checkpoint before its caller can recycle WAL. */ cluster_write_fence_reject_if_fenced("recovery anchor checkpoint post-publication"); if (!checkpoint_publisher_is_current(sysid)) - ereport(PANIC, - (errmsg("cluster recovery checkpoint publisher changed before WAL reuse"))); + ereport(PANIC, (errmsg("cluster recovery checkpoint publisher changed before WAL reuse"))); } /* diff --git a/src/backend/cluster/cluster_recovery_duty.c b/src/backend/cluster/cluster_recovery_duty.c index 8634440de6e..b974562d356 100644 --- a/src/backend/cluster/cluster_recovery_duty.c +++ b/src/backend/cluster/cluster_recovery_duty.c @@ -15,7 +15,7 @@ #include "cluster/cluster_membership.h" #include "cluster/cluster_reconfig.h" #include "cluster/cluster_semantic_activation.h" /* R4 cutover ACK proof (G3) */ -#include "cluster/cluster_wal_state.h" /* G4 runtime census gate (bit22) */ +#include "cluster/cluster_wal_state.h" /* G4 runtime census gate (bit22) */ #include "cluster/cluster_recovery_duty.h" #include "cluster_control_root_private.h" #include "cluster/cluster_startup_phase.h" /* serving rebind (recovery path retry) */ @@ -45,9 +45,8 @@ static ClusterControlRootPublishAuthorityV1 root_publish_authority; static void cluster_control_root_publish_authority_clear_v1(void); bool -cluster_control_root_create_authority_current_v1( - const ClusterControlRootMigrationImage *image, - const ClusterControlRootMigrationRoundV1 *round) +cluster_control_root_create_authority_current_v1(const ClusterControlRootMigrationImage *image, + const ClusterControlRootMigrationRoundV1 *round) { /* RF-ROOT P7 G3 (R4 cutover batch, Stage 8 contract): the * coordinator's exact one-shot proof, replacing the P5 refusal. This @@ -61,7 +60,7 @@ cluster_control_root_create_authority_current_v1( if (image == NULL || round == NULL || cluster_node_id < 0 || cluster_node_id >= CLUSTER_MAX_NODES) return false; - if ((int32) round->coordinator_node_id != cluster_node_id) + if ((int32)round->coordinator_node_id != cluster_node_id) return false; /* RF-ROOT P9 verification (contract, follow-up option b): the bit22 cutover * round's create is EXEMPT from the SAMPLE-stage ACK precondition — @@ -72,29 +71,23 @@ cluster_control_root_create_authority_current_v1( * capability sampling, which the cutover round bypasses (member set + * capabilities come from current_authority + IC sampling in begin). * R4 rounds (no bit22) keep the frozen precondition. */ - if ((round->target_feature_bitmap - & PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1) == 0 + if ((round->target_feature_bitmap & PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1) == 0 && !cluster_semantic_activation_ack_complete_matches( - round->transition_epoch, round->prepare_generation, - round->admitted_bitmap_low, round->admitted_bitmap_high, - round->source_feature_bitmap, round->target_feature_bitmap, - round->capability_sample_digest, - CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_SAMPLE)) + round->transition_epoch, round->prepare_generation, round->admitted_bitmap_low, + round->admitted_bitmap_high, round->source_feature_bitmap, round->target_feature_bitmap, + round->capability_sample_digest, CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_SAMPLE)) return false; - if (!cluster_control_root_feature_bitmap_is_known( - round->source_feature_bitmap) - || !cluster_control_root_feature_bitmap_is_known( - round->target_feature_bitmap) - || (round->target_feature_bitmap - & PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1) == 0) + if (!cluster_control_root_feature_bitmap_is_known(round->source_feature_bitmap) + || !cluster_control_root_feature_bitmap_is_known(round->target_feature_bitmap) + || (round->target_feature_bitmap & PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1) + == 0) return false; return true; } bool cluster_control_root_activate_authority_current_v1( - const ClusterControlRootFileToken *expected_token, - const uint8 expected_round_sha256[32], + const ClusterControlRootFileToken *expected_token, const uint8 expected_round_sha256[32], const ClusterControlRootMigrationRoundV1 *round) { /* RF-ROOT P7 G3 (R4 cutover batch, Stage 8 contract + implementation / @@ -113,30 +106,25 @@ cluster_control_root_activate_authority_current_v1( if (expected_token == NULL || expected_round_sha256 == NULL || round == NULL || cluster_node_id < 0 || cluster_node_id >= CLUSTER_MAX_NODES) return false; - if ((int32) round->coordinator_node_id != cluster_node_id) + if ((int32)round->coordinator_node_id != cluster_node_id) return false; if (!cluster_semantic_activation_ack_complete_matches( - round->transition_epoch, round->prepare_generation, - round->admitted_bitmap_low, round->admitted_bitmap_high, - round->source_feature_bitmap, round->target_feature_bitmap, - round->capability_sample_digest, - CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_PREPARED)) + round->transition_epoch, round->prepare_generation, round->admitted_bitmap_low, + round->admitted_bitmap_high, round->source_feature_bitmap, round->target_feature_bitmap, + round->capability_sample_digest, CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_PREPARED)) return false; - if (!cluster_control_root_feature_bitmap_is_known( - round->source_feature_bitmap) - || !cluster_control_root_feature_bitmap_is_known( - round->target_feature_bitmap) - || (round->target_feature_bitmap - & PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1) == 0) + if (!cluster_control_root_feature_bitmap_is_known(round->source_feature_bitmap) + || !cluster_control_root_feature_bitmap_is_known(round->target_feature_bitmap) + || (round->target_feature_bitmap & PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1) + == 0) return false; return true; } static bool -cluster_control_root_publish_authority_bind_v1( - const ClusterControlRootReadToken *expected_token, - const ClusterControlRootPatch *patch, - ClusterControlRootPublishReason reason) +cluster_control_root_publish_authority_bind_v1(const ClusterControlRootReadToken *expected_token, + const ClusterControlRootPatch *patch, + ClusterControlRootPublishReason reason) { if (root_publish_authority.active || expected_token == NULL || patch == NULL || (reason != CLUSTER_CONTROL_ROOT_PUBLISH_OWNER_REJOIN @@ -163,11 +151,10 @@ cluster_control_root_publish_authority_bind_v1( } ClusterControlRootResult -cluster_control_root_recovery_complete_publish_v1( - const ClusterControlRootReadToken *expected_token, - const ClusterControlRootPatch *patch, - ClusterControlRootSnapshot *out_snapshot, - ClusterControlRootReadToken *out_token) +cluster_control_root_recovery_complete_publish_v1(const ClusterControlRootReadToken *expected_token, + const ClusterControlRootPatch *patch, + ClusterControlRootSnapshot *out_snapshot, + ClusterControlRootReadToken *out_token) { ClusterControlRootResult result; @@ -175,21 +162,18 @@ cluster_control_root_recovery_complete_publish_v1( memset(out_snapshot, 0, sizeof(*out_snapshot)); if (out_token != NULL) memset(out_token, 0, sizeof(*out_token)); - if (expected_token == NULL || patch == NULL || - patch->mask != (CLUSTER_CONTROL_ROOT_PATCH_LIFECYCLE | - CLUSTER_CONTROL_ROOT_PATCH_RECOVERY_PROGRESS) || - patch->expected_lifecycle != - CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_REQUIRED || - patch->desired.lifecycle != - CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_COMPLETE || - !cluster_control_root_publish_authority_bind_v1( - expected_token, patch, - CLUSTER_CONTROL_ROOT_PUBLISH_RECOVERY_COMPLETE)) + if (expected_token == NULL || patch == NULL + || patch->mask + != (CLUSTER_CONTROL_ROOT_PATCH_LIFECYCLE + | CLUSTER_CONTROL_ROOT_PATCH_RECOVERY_PROGRESS) + || patch->expected_lifecycle != CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_REQUIRED + || patch->desired.lifecycle != CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_COMPLETE + || !cluster_control_root_publish_authority_bind_v1( + expected_token, patch, CLUSTER_CONTROL_ROOT_PUBLISH_RECOVERY_COMPLETE)) return CLUSTER_CONTROL_ROOT_INVALID_ARGUMENT; result = cluster_control_root_compare_and_publish( - expected_token, patch, - CLUSTER_CONTROL_ROOT_PUBLISH_RECOVERY_COMPLETE, - out_snapshot, out_token); + expected_token, patch, CLUSTER_CONTROL_ROOT_PUBLISH_RECOVERY_COMPLETE, out_snapshot, + out_token); cluster_control_root_publish_authority_clear_v1(); return result; } @@ -201,16 +185,15 @@ cluster_control_root_publish_authority_clear_v1(void) } bool -cluster_control_root_publish_authority_current_v1( - const ClusterControlRootReadToken *expected_token, - const ClusterControlRootPatch *patch, - ClusterControlRootPublishReason reason) +cluster_control_root_publish_authority_current_v1(const ClusterControlRootReadToken *expected_token, + const ClusterControlRootPatch *patch, + ClusterControlRootPublishReason reason) { - bool exact = root_publish_authority.active && expected_token != NULL - && patch != NULL && reason == root_publish_authority.reason - && memcmp(expected_token, &root_publish_authority.token, - sizeof(*expected_token)) == 0 - && memcmp(patch, &root_publish_authority.patch, sizeof(*patch)) == 0; + bool exact + = root_publish_authority.active && expected_token != NULL && patch != NULL + && reason == root_publish_authority.reason + && memcmp(expected_token, &root_publish_authority.token, sizeof(*expected_token)) == 0 + && memcmp(patch, &root_publish_authority.patch, sizeof(*patch)) == 0; /* One exact compare-and-publish attempt consumes the authority before the * control-root layer can acquire CF or touch storage. A failed or nested @@ -248,9 +231,8 @@ write_u64_le(uint8 *dst, uint64 value) } bool -cluster_recovery_duty_key_encode_v1( - const ClusterRecoveryDutyKey *key, - uint8 out[CLUSTER_RECOVERY_DUTY_KEY_V1_BYTES]) +cluster_recovery_duty_key_encode_v1(const ClusterRecoveryDutyKey *key, + uint8 out[CLUSTER_RECOVERY_DUTY_KEY_V1_BYTES]) { if (out == NULL) return false; @@ -285,8 +267,7 @@ cluster_recovery_duty_key_compare(const ClusterRecoveryDutyKey *expected, } bool -cluster_recovery_duty_digest_v1(const ClusterRecoveryDutyKey *key, - ClusterRecoveryDutyDigest *out) +cluster_recovery_duty_digest_v1(const ClusterRecoveryDutyKey *key, ClusterRecoveryDutyDigest *out) { static const uint8 domain[19] = "PGRAC-ROOT-DUTY-V1"; uint8 preimage[19 + 4 + CLUSTER_RECOVERY_DUTY_KEY_V1_BYTES]; @@ -298,14 +279,12 @@ cluster_recovery_duty_digest_v1(const ClusterRecoveryDutyKey *key, memset(out, 0, sizeof(*out)); memcpy(preimage, domain, sizeof(domain)); write_u32_le(preimage + sizeof(domain), CLUSTER_RECOVERY_DUTY_KEY_V1_BYTES); - if (!cluster_recovery_duty_key_encode_v1( - key, preimage + sizeof(domain) + sizeof(uint32))) + if (!cluster_recovery_duty_key_encode_v1(key, preimage + sizeof(domain) + sizeof(uint32))) return false; ctx = pg_cryptohash_create(PG_SHA256); if (ctx == NULL) return false; - if (pg_cryptohash_init(ctx) >= 0 - && pg_cryptohash_update(ctx, preimage, sizeof(preimage)) >= 0 + if (pg_cryptohash_init(ctx) >= 0 && pg_cryptohash_update(ctx, preimage, sizeof(preimage)) >= 0 && pg_cryptohash_final(ctx, out->bytes, sizeof(out->bytes)) >= 0) success = true; pg_cryptohash_free(ctx); @@ -331,10 +310,8 @@ owner_marker_committed_valid(const ClusterJoinCommitMarker *marker, int32 node_i { pg_crc32c crc; - if (marker->magic != CLUSTER_JCMK_MAGIC - || marker->version != CLUSTER_JCMK_VERSION - || marker->node_id != node_id - || marker->phase != CLUSTER_JCMK_PHASE_COMMITTED + if (marker->magic != CLUSTER_JCMK_MAGIC || marker->version != CLUSTER_JCMK_VERSION + || marker->node_id != node_id || marker->phase != CLUSTER_JCMK_PHASE_COMMITTED || marker->admitted_incarnation == 0) return false; INIT_CRC32C(crc); @@ -344,11 +321,11 @@ owner_marker_committed_valid(const ClusterJoinCommitMarker *marker, int32 node_i } ClusterRecoveryOwnerImportResult -cluster_recovery_owner_import_select_v1( - int32 node_id, const ClusterWalThreadClaim *immutable_claim, - uint64 frozen_admitted_bitmap_low, uint64 frozen_admitted_bitmap_high, - const ClusterRecoveryOwnerDiskSampleV1 *samples, int total_disk_count, - uint64 *out_incarnation) +cluster_recovery_owner_import_select_v1(int32 node_id, const ClusterWalThreadClaim *immutable_claim, + uint64 frozen_admitted_bitmap_low, + uint64 frozen_admitted_bitmap_high, + const ClusterRecoveryOwnerDiskSampleV1 *samples, + int total_disk_count, uint64 *out_incarnation) { ClusterJoinCommitMarker committed[CLUSTER_MAX_VOTING_DISKS]; uint32 majority; @@ -360,17 +337,15 @@ cluster_recovery_owner_import_select_v1( if (out_incarnation != NULL) *out_incarnation = 0; - if (out_incarnation == NULL || immutable_claim == NULL || samples == NULL - || node_id < 0 || node_id >= CLUSTER_MAX_NODES - || total_disk_count <= 0 || total_disk_count > CLUSTER_MAX_VOTING_DISKS) + if (out_incarnation == NULL || immutable_claim == NULL || samples == NULL || node_id < 0 + || node_id >= CLUSTER_MAX_NODES || total_disk_count <= 0 + || total_disk_count > CLUSTER_MAX_VOTING_DISKS) return CLUSTER_RECOVERY_OWNER_IMPORT_BAD_ARGUMENT; - if (!cluster_wal_thread_claim_validate( - immutable_claim, (uint16)(node_id + 1), node_id, NULL)) + if (!cluster_wal_thread_claim_validate(immutable_claim, (uint16)(node_id + 1), node_id, NULL)) return CLUSTER_RECOVERY_OWNER_IMPORT_CLAIM_MISMATCH; initial_member = node_id < 64 - ? (frozen_admitted_bitmap_low & (UINT64_C(1) << node_id)) != 0 - : (frozen_admitted_bitmap_high - & (UINT64_C(1) << (node_id - 64))) != 0; + ? (frozen_admitted_bitmap_low & (UINT64_C(1) << node_id)) != 0 + : (frozen_admitted_bitmap_high & (UINT64_C(1) << (node_id - 64))) != 0; majority = (uint32)(total_disk_count / 2) + 1; for (i = 0; i < total_disk_count; i++) { const ClusterJoinCommitMarker *marker = &samples[i].join_marker; @@ -412,8 +387,7 @@ cluster_recovery_owner_import_select_v1( int j; if (samples[i].slot_io_state != CLUSTER_VOTING_DISK_IO_OK - || samples[i].slot.node_id != (uint32)node_id - || samples[i].slot.incarnation == 0) + || samples[i].slot.node_id != (uint32)node_id || samples[i].slot.incarnation == 0) continue; candidate = samples[i].slot.incarnation; for (j = 0; j < total_disk_count; j++) @@ -443,18 +417,16 @@ cluster_recovery_owner_rejoin_v1(int32 node_id, uint64 admitted_incarnation) ClusterWalThreadClaim immutable_claim; uint64 proven_incarnation = 0; - if (node_id < 0 || node_id >= CLUSTER_MAX_NODES - || admitted_incarnation == 0) + if (node_id < 0 || node_id >= CLUSTER_MAX_NODES || admitted_incarnation == 0) return false; - root_result = cluster_control_root_lookup_owner_by_node_runtime( - node_id, &identity, &snapshot, &token); + root_result + = cluster_control_root_lookup_owner_by_node_runtime(node_id, &identity, &snapshot, &token); if ((root_result != CLUSTER_CONTROL_ROOT_OK_PRIMARY && root_result != CLUSTER_CONTROL_ROOT_OK_PRIMARY_DEGRADED) || !cluster_recovery_duty_key_valid_v1(&identity) || cluster_recovery_duty_key_compare(&identity, &snapshot.identity) != CLUSTER_RECOVERY_DUTY_COMPARE_EXACT - || (snapshot.lifecycle - != CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_COMPLETE + || (snapshot.lifecycle != CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_COMPLETE && snapshot.lifecycle != CLUSTER_CONTROL_ROOT_LIFECYCLE_OPEN /* RF-ROOT P6 (STOP-01 contract, corrected * design): a CLOSED root is the same-owner clean release @@ -486,20 +458,18 @@ cluster_recovery_owner_rejoin_v1(int32 node_id, uint64 admitted_incarnation) * incarnation (admitted == root owner) fails closed AT THE CAS and * converges once the qvotec prior-incarnation slot ages out — the * head gate only needs the exhausted-lineage reject. */ - || (snapshot.lifecycle - == CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_COMPLETE + || (snapshot.lifecycle == CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_COMPLETE && (identity.root_lineage_seq == UINT64_MAX || identity.origin_owner_incarnation >= admitted_incarnation)) || (snapshot.lifecycle == CLUSTER_CONTROL_ROOT_LIFECYCLE_CLOSED && identity.root_lineage_seq == UINT64_MAX)) return false; - cluster_wal_thread_claim_fill( - &immutable_claim, identity.origin_thread_id, identity.origin_node_id, - identity.thread_claim_created_at); + cluster_wal_thread_claim_fill(&immutable_claim, identity.origin_thread_id, + identity.origin_node_id, identity.thread_claim_created_at); if (immutable_claim.crc != identity.thread_claim_crc32c) return false; - owner_result = cluster_recovery_owner_import_read_v1( - node_id, &immutable_claim, 0, 0, &proven_incarnation); + owner_result = cluster_recovery_owner_import_read_v1(node_id, &immutable_claim, 0, 0, + &proven_incarnation); if (owner_result != CLUSTER_RECOVERY_OWNER_IMPORT_JCMK || proven_incarnation != admitted_incarnation) return false; @@ -511,19 +481,16 @@ cluster_recovery_owner_rejoin_v1(int32 node_id, uint64 admitted_incarnation) return true; memset(&patch, 0, sizeof(patch)); - patch.mask = CLUSTER_CONTROL_ROOT_PATCH_LIFECYCLE - | CLUSTER_CONTROL_ROOT_PATCH_OWNER_LINEAGE - | CLUSTER_CONTROL_ROOT_PATCH_CHECKPOINT - | CLUSTER_CONTROL_ROOT_PATCH_TAIL + patch.mask = CLUSTER_CONTROL_ROOT_PATCH_LIFECYCLE | CLUSTER_CONTROL_ROOT_PATCH_OWNER_LINEAGE + | CLUSTER_CONTROL_ROOT_PATCH_CHECKPOINT | CLUSTER_CONTROL_ROOT_PATCH_TAIL | CLUSTER_CONTROL_ROOT_PATCH_RECOVERY_PROGRESS; /* Frozen shapes (STOP-01 §17.4 + STOP-02): OWNER_REJOIN admits only the * RECOVERY_COMPLETE pre-lifecycle (crash-rejoin mainline); a CLOSED root * (clean release) reopens under the THREAD_OPEN reason with its frozen * CLOSED -> OPEN shape. Same owner-lineage monotonicity + proof set. */ - patch.expected_lifecycle = - (snapshot.lifecycle == CLUSTER_CONTROL_ROOT_LIFECYCLE_CLOSED) - ? CLUSTER_CONTROL_ROOT_LIFECYCLE_CLOSED - : CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_COMPLETE; + patch.expected_lifecycle = (snapshot.lifecycle == CLUSTER_CONTROL_ROOT_LIFECYCLE_CLOSED) + ? CLUSTER_CONTROL_ROOT_LIFECYCLE_CLOSED + : CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_COMPLETE; patch.desired.lifecycle = CLUSTER_CONTROL_ROOT_LIFECYCLE_OPEN; patch.desired.identity.origin_owner_incarnation = admitted_incarnation; patch.desired.identity.root_lineage_seq = identity.root_lineage_seq + 1; @@ -534,28 +501,25 @@ cluster_recovery_owner_rejoin_v1(int32 node_id, uint64 admitted_incarnation) patch.desired.checkpoint_record_crc32c = snapshot.checkpoint_record_crc32c; patch.desired.tail_tli = snapshot.tail_tli; patch.desired.tail_validation_kind = snapshot.tail_validation_kind; - patch.desired.validated_tail_lsn_exclusive = - snapshot.validated_tail_lsn_exclusive; + patch.desired.validated_tail_lsn_exclusive = snapshot.validated_tail_lsn_exclusive; patch.desired.tail_last_record_lsn = snapshot.tail_last_record_lsn; patch.desired.tail_last_record_crc32c = snapshot.tail_last_record_crc32c; patch.desired.recovered_tli = snapshot.recovered_tli; - patch.desired.recovered_through_lsn_exclusive = - snapshot.recovered_through_lsn_exclusive; + patch.desired.recovered_through_lsn_exclusive = snapshot.recovered_through_lsn_exclusive; patch.desired.recovered_last_record_lsn = snapshot.recovered_last_record_lsn; - patch.desired.recovered_last_record_crc32c = - snapshot.recovered_last_record_crc32c; + patch.desired.recovered_last_record_crc32c = snapshot.recovered_last_record_crc32c; if (!cluster_control_root_publish_authority_bind_v1( &token, &patch, (snapshot.lifecycle == CLUSTER_CONTROL_ROOT_LIFECYCLE_CLOSED) - ? CLUSTER_CONTROL_ROOT_PUBLISH_THREAD_OPEN - : CLUSTER_CONTROL_ROOT_PUBLISH_OWNER_REJOIN)) + ? CLUSTER_CONTROL_ROOT_PUBLISH_THREAD_OPEN + : CLUSTER_CONTROL_ROOT_PUBLISH_OWNER_REJOIN)) return false; root_result = cluster_control_root_compare_and_publish( &token, &patch, (snapshot.lifecycle == CLUSTER_CONTROL_ROOT_LIFECYCLE_CLOSED) - ? CLUSTER_CONTROL_ROOT_PUBLISH_THREAD_OPEN - : CLUSTER_CONTROL_ROOT_PUBLISH_OWNER_REJOIN, + ? CLUSTER_CONTROL_ROOT_PUBLISH_THREAD_OPEN + : CLUSTER_CONTROL_ROOT_PUBLISH_OWNER_REJOIN, &published, &published_token); cluster_control_root_publish_authority_clear_v1(); if (root_result == CLUSTER_CONTROL_ROOT_OK_PRIMARY @@ -598,8 +562,8 @@ cluster_control_root_thread_clean_close_publish(void) if (cluster_node_id < 0 || cluster_node_id >= CLUSTER_MAX_NODES) return false; - root_result = cluster_control_root_lookup_owner_by_node_runtime( - cluster_node_id, &identity, &snapshot, &token); + root_result = cluster_control_root_lookup_owner_by_node_runtime(cluster_node_id, &identity, + &snapshot, &token); if ((root_result != CLUSTER_CONTROL_ROOT_OK_PRIMARY && root_result != CLUSTER_CONTROL_ROOT_OK_PRIMARY_DEGRADED) || !cluster_recovery_duty_key_valid_v1(&identity) @@ -609,10 +573,8 @@ cluster_control_root_thread_clean_close_publish(void) return false; /* not an open owner of this thread: nothing to close */ memset(&patch, 0, sizeof(patch)); - patch.mask = CLUSTER_CONTROL_ROOT_PATCH_LIFECYCLE - | CLUSTER_CONTROL_ROOT_PATCH_CHECKPOINT - | CLUSTER_CONTROL_ROOT_PATCH_TAIL - | CLUSTER_CONTROL_ROOT_PATCH_RECOVERY_PROGRESS; + patch.mask = CLUSTER_CONTROL_ROOT_PATCH_LIFECYCLE | CLUSTER_CONTROL_ROOT_PATCH_CHECKPOINT + | CLUSTER_CONTROL_ROOT_PATCH_TAIL | CLUSTER_CONTROL_ROOT_PATCH_RECOVERY_PROGRESS; patch.expected_lifecycle = CLUSTER_CONTROL_ROOT_LIFECYCLE_OPEN; patch.desired.lifecycle = CLUSTER_CONTROL_ROOT_LIFECYCLE_CLOSED; patch.desired.root_flags = snapshot.root_flags; @@ -622,31 +584,27 @@ cluster_control_root_thread_clean_close_publish(void) patch.desired.checkpoint_record_crc32c = snapshot.checkpoint_record_crc32c; patch.desired.tail_tli = snapshot.tail_tli; patch.desired.tail_validation_kind = snapshot.tail_validation_kind; - patch.desired.validated_tail_lsn_exclusive = - snapshot.validated_tail_lsn_exclusive; + patch.desired.validated_tail_lsn_exclusive = snapshot.validated_tail_lsn_exclusive; patch.desired.tail_last_record_lsn = snapshot.tail_last_record_lsn; patch.desired.tail_last_record_crc32c = snapshot.tail_last_record_crc32c; patch.desired.recovered_tli = snapshot.recovered_tli; - patch.desired.recovered_through_lsn_exclusive = - snapshot.recovered_through_lsn_exclusive; + patch.desired.recovered_through_lsn_exclusive = snapshot.recovered_through_lsn_exclusive; patch.desired.recovered_last_record_lsn = snapshot.recovered_last_record_lsn; - patch.desired.recovered_last_record_crc32c = - snapshot.recovered_last_record_crc32c; + patch.desired.recovered_last_record_crc32c = snapshot.recovered_last_record_crc32c; if (!cluster_control_root_publish_authority_bind_v1( &token, &patch, CLUSTER_CONTROL_ROOT_PUBLISH_THREAD_CLEAN_CLOSE)) return false; root_result = cluster_control_root_compare_and_publish( - &token, &patch, CLUSTER_CONTROL_ROOT_PUBLISH_THREAD_CLEAN_CLOSE, - &published, &published_token); + &token, &patch, CLUSTER_CONTROL_ROOT_PUBLISH_THREAD_CLEAN_CLOSE, &published, + &published_token); cluster_control_root_publish_authority_clear_v1(); if (root_result == CLUSTER_CONTROL_ROOT_OK_PRIMARY && published.lifecycle == CLUSTER_CONTROL_ROOT_LIFECYCLE_CLOSED) { - ereport(LOG, - (errmsg("cluster control root: thread %u clean-closed by owner node %d " - "(owner incarnation " UINT64_FORMAT ")", - identity.origin_thread_id, cluster_node_id, - identity.origin_owner_incarnation))); + ereport(LOG, (errmsg("cluster control root: thread %u clean-closed by owner node %d " + "(owner incarnation " UINT64_FORMAT ")", + identity.origin_thread_id, cluster_node_id, + identity.origin_owner_incarnation))); return true; } return false; @@ -676,11 +634,10 @@ cluster_control_root_thread_open_publish(uint64 boot_incarnation) ClusterControlRootPatch patch; ClusterControlRootResult root_result; - if (cluster_node_id < 0 || cluster_node_id >= CLUSTER_MAX_NODES - || boot_incarnation == 0) + if (cluster_node_id < 0 || cluster_node_id >= CLUSTER_MAX_NODES || boot_incarnation == 0) return false; - root_result = cluster_control_root_lookup_owner_by_node_runtime( - cluster_node_id, &identity, &snapshot, &token); + root_result = cluster_control_root_lookup_owner_by_node_runtime(cluster_node_id, &identity, + &snapshot, &token); if ((root_result != CLUSTER_CONTROL_ROOT_OK_PRIMARY && root_result != CLUSTER_CONTROL_ROOT_OK_PRIMARY_DEGRADED) || !cluster_recovery_duty_key_valid_v1(&identity) @@ -692,10 +649,8 @@ cluster_control_root_thread_open_publish(uint64 boot_incarnation) return false; /* not a clean-closed thread of this owner, or stale */ memset(&patch, 0, sizeof(patch)); - patch.mask = CLUSTER_CONTROL_ROOT_PATCH_LIFECYCLE - | CLUSTER_CONTROL_ROOT_PATCH_OWNER_LINEAGE - | CLUSTER_CONTROL_ROOT_PATCH_CHECKPOINT - | CLUSTER_CONTROL_ROOT_PATCH_TAIL + patch.mask = CLUSTER_CONTROL_ROOT_PATCH_LIFECYCLE | CLUSTER_CONTROL_ROOT_PATCH_OWNER_LINEAGE + | CLUSTER_CONTROL_ROOT_PATCH_CHECKPOINT | CLUSTER_CONTROL_ROOT_PATCH_TAIL | CLUSTER_CONTROL_ROOT_PATCH_RECOVERY_PROGRESS; patch.expected_lifecycle = CLUSTER_CONTROL_ROOT_LIFECYCLE_CLOSED; patch.desired.lifecycle = CLUSTER_CONTROL_ROOT_LIFECYCLE_OPEN; @@ -708,23 +663,19 @@ cluster_control_root_thread_open_publish(uint64 boot_incarnation) patch.desired.checkpoint_record_crc32c = snapshot.checkpoint_record_crc32c; patch.desired.tail_tli = snapshot.tail_tli; patch.desired.tail_validation_kind = snapshot.tail_validation_kind; - patch.desired.validated_tail_lsn_exclusive = - snapshot.validated_tail_lsn_exclusive; + patch.desired.validated_tail_lsn_exclusive = snapshot.validated_tail_lsn_exclusive; patch.desired.tail_last_record_lsn = snapshot.tail_last_record_lsn; patch.desired.tail_last_record_crc32c = snapshot.tail_last_record_crc32c; patch.desired.recovered_tli = snapshot.recovered_tli; - patch.desired.recovered_through_lsn_exclusive = - snapshot.recovered_through_lsn_exclusive; + patch.desired.recovered_through_lsn_exclusive = snapshot.recovered_through_lsn_exclusive; patch.desired.recovered_last_record_lsn = snapshot.recovered_last_record_lsn; - patch.desired.recovered_last_record_crc32c = - snapshot.recovered_last_record_crc32c; + patch.desired.recovered_last_record_crc32c = snapshot.recovered_last_record_crc32c; - if (!cluster_control_root_publish_authority_bind_v1( - &token, &patch, CLUSTER_CONTROL_ROOT_PUBLISH_THREAD_OPEN)) + if (!cluster_control_root_publish_authority_bind_v1(&token, &patch, + CLUSTER_CONTROL_ROOT_PUBLISH_THREAD_OPEN)) return false; root_result = cluster_control_root_compare_and_publish( - &token, &patch, CLUSTER_CONTROL_ROOT_PUBLISH_THREAD_OPEN, - &published, &published_token); + &token, &patch, CLUSTER_CONTROL_ROOT_PUBLISH_THREAD_OPEN, &published, &published_token); cluster_control_root_publish_authority_clear_v1(); if (root_result == CLUSTER_CONTROL_ROOT_OK_PRIMARY && published.lifecycle == CLUSTER_CONTROL_ROOT_LIFECYCLE_OPEN @@ -732,11 +683,9 @@ cluster_control_root_thread_open_publish(uint64 boot_incarnation) && published.identity.root_lineage_seq == identity.root_lineage_seq + 1) { ereport(LOG, (errmsg("cluster control root: thread %u reopened by owner node %d " - "(owner incarnation %llu -> " UINT64_FORMAT ", lineage " - UINT64_FORMAT ")", + "(owner incarnation %llu -> " UINT64_FORMAT ", lineage " UINT64_FORMAT ")", identity.origin_thread_id, cluster_node_id, - (unsigned long long)identity.origin_owner_incarnation, - boot_incarnation, + (unsigned long long)identity.origin_owner_incarnation, boot_incarnation, identity.root_lineage_seq + 1))); return true; } @@ -763,11 +712,9 @@ cluster_control_root_thread_open_publish(uint64 boot_incarnation) * record (read back by the caller after XLogFlush). */ bool -cluster_control_root_checkpoint_advance_publish(XLogRecPtr redo, - TimeLineID tli, +cluster_control_root_checkpoint_advance_publish(XLogRecPtr redo, TimeLineID tli, XLogRecPtr ckpt_record_start, - XLogRecPtr ckpt_record_end, - uint32 record_crc32c) + XLogRecPtr ckpt_record_end, uint32 record_crc32c) { ClusterControlRootIdentity identity; ClusterControlRootSnapshot snapshot; @@ -777,14 +724,12 @@ cluster_control_root_checkpoint_advance_publish(XLogRecPtr redo, ClusterControlRootPatch patch; ClusterControlRootResult root_result; - if (cluster_node_id < 0 || cluster_node_id >= CLUSTER_MAX_NODES - || XLogRecPtrIsInvalid(redo) || tli == 0 || record_crc32c == 0 - || XLogRecPtrIsInvalid(ckpt_record_start) - || XLogRecPtrIsInvalid(ckpt_record_end) - || ckpt_record_start >= ckpt_record_end) + if (cluster_node_id < 0 || cluster_node_id >= CLUSTER_MAX_NODES || XLogRecPtrIsInvalid(redo) + || tli == 0 || record_crc32c == 0 || XLogRecPtrIsInvalid(ckpt_record_start) + || XLogRecPtrIsInvalid(ckpt_record_end) || ckpt_record_start >= ckpt_record_end) return false; - root_result = cluster_control_root_lookup_owner_by_node_runtime( - cluster_node_id, &identity, &snapshot, &token); + root_result = cluster_control_root_lookup_owner_by_node_runtime(cluster_node_id, &identity, + &snapshot, &token); if ((root_result != CLUSTER_CONTROL_ROOT_OK_PRIMARY && root_result != CLUSTER_CONTROL_ROOT_OK_PRIMARY_DEGRADED) || !cluster_recovery_duty_key_valid_v1(&identity) @@ -800,23 +745,21 @@ cluster_control_root_checkpoint_advance_publish(XLogRecPtr redo, * (e.g. an end-of-recovery re-checkpoint) is a no-op — never move the * advertised bound backwards. */ - if ((uint64) redo <= snapshot.checkpoint_lower_lsn) + if ((uint64)redo <= snapshot.checkpoint_lower_lsn) return false; memset(&patch, 0, sizeof(patch)); - patch.mask = CLUSTER_CONTROL_ROOT_PATCH_CHECKPOINT - | CLUSTER_CONTROL_ROOT_PATCH_TAIL + patch.mask = CLUSTER_CONTROL_ROOT_PATCH_CHECKPOINT | CLUSTER_CONTROL_ROOT_PATCH_TAIL | CLUSTER_CONTROL_ROOT_PATCH_RECOVERY_PROGRESS; patch.expected_lifecycle = CLUSTER_CONTROL_ROOT_LIFECYCLE_OPEN; /* No LIFECYCLE bit in the 0x38 mask: the shape rule requires the * unmasked desired.lifecycle to stay at the zero value (UNUSED). */ patch.desired.lifecycle = CLUSTER_CONTROL_ROOT_LIFECYCLE_UNUSED; - patch.desired.root_flags = snapshot.root_flags - | CLUSTER_CONTROL_ROOT_FLAG_TAIL_VALID + patch.desired.root_flags = snapshot.root_flags | CLUSTER_CONTROL_ROOT_FLAG_TAIL_VALID | CLUSTER_CONTROL_ROOT_FLAG_TAIL_LAST_RECORD_VALID; patch.desired.checkpoint_tli = tli; patch.desired.checkpoint_source_kind = CLUSTER_CONTROL_ROOT_CHECKPOINT_NATIVE_V1; - patch.desired.checkpoint_lower_lsn = (uint64) redo; + patch.desired.checkpoint_lower_lsn = (uint64)redo; patch.desired.checkpoint_record_crc32c = record_crc32c; /* * The just-written checkpoint record is the WAL-extent validation point: @@ -827,42 +770,38 @@ cluster_control_root_checkpoint_advance_publish(XLogRecPtr redo, */ patch.desired.tail_tli = tli; patch.desired.tail_validation_kind = CLUSTER_CONTROL_ROOT_TAIL_WAL_RECORD_SCAN_V1; - patch.desired.validated_tail_lsn_exclusive = (uint64) ckpt_record_end; - patch.desired.tail_last_record_lsn = (uint64) ckpt_record_start; + patch.desired.validated_tail_lsn_exclusive = (uint64)ckpt_record_end; + patch.desired.tail_last_record_lsn = (uint64)ckpt_record_start; patch.desired.tail_last_record_crc32c = record_crc32c; /* recovery progress preserved from the durable snapshot. */ patch.desired.recovered_tli = snapshot.recovered_tli; - patch.desired.recovered_through_lsn_exclusive = - snapshot.recovered_through_lsn_exclusive; + patch.desired.recovered_through_lsn_exclusive = snapshot.recovered_through_lsn_exclusive; patch.desired.recovered_last_record_lsn = snapshot.recovered_last_record_lsn; - patch.desired.recovered_last_record_crc32c = - snapshot.recovered_last_record_crc32c; + patch.desired.recovered_last_record_crc32c = snapshot.recovered_last_record_crc32c; if (!cluster_control_root_publish_authority_bind_v1( &token, &patch, CLUSTER_CONTROL_ROOT_PUBLISH_CHECKPOINT_ADVANCE)) return false; root_result = cluster_control_root_compare_and_publish( - &token, &patch, CLUSTER_CONTROL_ROOT_PUBLISH_CHECKPOINT_ADVANCE, - &published, &published_token); + &token, &patch, CLUSTER_CONTROL_ROOT_PUBLISH_CHECKPOINT_ADVANCE, &published, + &published_token); cluster_control_root_publish_authority_clear_v1(); if (root_result == CLUSTER_CONTROL_ROOT_OK_PRIMARY && published.lifecycle == CLUSTER_CONTROL_ROOT_LIFECYCLE_OPEN - && published.checkpoint_lower_lsn == (uint64) redo + && published.checkpoint_lower_lsn == (uint64)redo && published.checkpoint_record_crc32c == record_crc32c - && published.validated_tail_lsn_exclusive == (uint64) ckpt_record_end) { - ereport(LOG, - (errmsg("cluster control root: thread %u checkpoint advanced by node %d " - "(redo %X/%X, tli %u, tail %X/%X, root publish seq " UINT64_FORMAT ")", - identity.origin_thread_id, cluster_node_id, - LSN_FORMAT_ARGS(redo), (unsigned) tli, - LSN_FORMAT_ARGS(ckpt_record_end), - published.root_publish_seq))); + && published.validated_tail_lsn_exclusive == (uint64)ckpt_record_end) { + ereport(LOG, (errmsg("cluster control root: thread %u checkpoint advanced by node %d " + "(redo %X/%X, tli %u, tail %X/%X, root publish seq " UINT64_FORMAT ")", + identity.origin_thread_id, cluster_node_id, LSN_FORMAT_ARGS(redo), + (unsigned)tli, LSN_FORMAT_ARGS(ckpt_record_end), + published.root_publish_seq))); return true; } ereport(WARNING, (errmsg("cluster control root: checkpoint advance publish failed for thread %u " "(result %d); the next checkpoint will retry", - identity.origin_thread_id, (int) root_result))); + identity.origin_thread_id, (int)root_result))); return false; } @@ -884,9 +823,9 @@ cluster_control_root_checkpoint_advance_publish(XLogRecPtr redo, bool cluster_control_root_thread_clean_close_publish_retry(void) { - TimestampTz deadline = TimestampTzPlusMilliseconds( - GetCurrentTimestamp(), CLUSTER_CLEAN_CLOSE_RETRY_MS); - bool closed_ok = false; + TimestampTz deadline + = TimestampTzPlusMilliseconds(GetCurrentTimestamp(), CLUSTER_CLEAN_CLOSE_RETRY_MS); + bool closed_ok = false; for (;;) { closed_ok = cluster_control_root_thread_clean_close_publish(); @@ -895,20 +834,18 @@ cluster_control_root_thread_clean_close_publish_retry(void) /* Re-validate / re-bind the leaver serving authority (the LMON-tick * rebind may not have landed inside this shutdown window) before * the next attempt. */ - (void) cluster_authority_serving_rebind_leaver(); + (void)cluster_authority_serving_rebind_leaver(); if (GetCurrentTimestamp() >= deadline) break; - (void) WaitLatch(MyLatch, - WL_LATCH_SET | WL_TIMEOUT | WL_EXIT_ON_PM_DEATH, - 50, WAIT_EVENT_CHECKPOINTER_MAIN); + (void)WaitLatch(MyLatch, WL_LATCH_SET | WL_TIMEOUT | WL_EXIT_ON_PM_DEATH, 50, + WAIT_EVENT_CHECKPOINTER_MAIN); ResetLatch(MyLatch); CHECK_FOR_INTERRUPTS(); } if (!closed_ok) - ereport(LOG, - (errmsg("cluster control root: THREAD_CLEAN_CLOSE could not be published " - "within the bounded shutdown window; the root stays OPEN and the " - "restart takes the ordinary crash-rejoin chain (fail-closed)"))); + ereport(LOG, (errmsg("cluster control root: THREAD_CLEAN_CLOSE could not be published " + "within the bounded shutdown window; the root stays OPEN and the " + "restart takes the ordinary crash-rejoin chain (fail-closed)"))); return closed_ok; } @@ -936,8 +873,8 @@ cluster_control_root_fpw_sticky_publish(void) if (cluster_node_id < 0 || cluster_node_id >= CLUSTER_MAX_NODES) return false; - root_result = cluster_control_root_lookup_owner_by_node_runtime( - cluster_node_id, &identity, &snapshot, &token); + root_result = cluster_control_root_lookup_owner_by_node_runtime(cluster_node_id, &identity, + &snapshot, &token); if ((root_result != CLUSTER_CONTROL_ROOT_OK_PRIMARY && root_result != CLUSTER_CONTROL_ROOT_OK_PRIMARY_DEGRADED) || !cluster_recovery_duty_key_valid_v1(&identity) @@ -953,29 +890,25 @@ cluster_control_root_fpw_sticky_publish(void) patch.expected_lifecycle = CLUSTER_CONTROL_ROOT_LIFECYCLE_OPEN; /* No LIFECYCLE bit in the 0x40 mask: desired.lifecycle stays 0. */ patch.desired.lifecycle = CLUSTER_CONTROL_ROOT_LIFECYCLE_UNUSED; - patch.desired.root_flags = snapshot.root_flags - | CLUSTER_CONTROL_ROOT_FLAG_FPW_WAS_OFF; + patch.desired.root_flags = snapshot.root_flags | CLUSTER_CONTROL_ROOT_FLAG_FPW_WAS_OFF; - if (!cluster_control_root_publish_authority_bind_v1( - &token, &patch, CLUSTER_CONTROL_ROOT_PUBLISH_FPW_STICKY)) + if (!cluster_control_root_publish_authority_bind_v1(&token, &patch, + CLUSTER_CONTROL_ROOT_PUBLISH_FPW_STICKY)) return false; root_result = cluster_control_root_compare_and_publish( - &token, &patch, CLUSTER_CONTROL_ROOT_PUBLISH_FPW_STICKY, - &published, &published_token); + &token, &patch, CLUSTER_CONTROL_ROOT_PUBLISH_FPW_STICKY, &published, &published_token); cluster_control_root_publish_authority_clear_v1(); if (root_result == CLUSTER_CONTROL_ROOT_OK_PRIMARY && (published.root_flags & CLUSTER_CONTROL_ROOT_FLAG_FPW_WAS_OFF) != 0) { ereport(LOG, (errmsg("cluster control root: thread %u FPW-off sticky published by node %d " "(root publish seq " UINT64_FORMAT ")", - identity.origin_thread_id, cluster_node_id, - published.root_publish_seq))); + identity.origin_thread_id, cluster_node_id, published.root_publish_seq))); return true; } - ereport(WARNING, - (errmsg("cluster control root: FPW sticky publish failed for thread %u " - "(result %d); the next checkpoint will retry", - identity.origin_thread_id, (int) root_result))); + ereport(WARNING, (errmsg("cluster control root: FPW sticky publish failed for thread %u " + "(result %d); the next checkpoint will retry", + identity.origin_thread_id, (int)root_result))); return false; } @@ -998,8 +931,7 @@ formation_bitmap_nonempty(const uint8 bitmap[CLUSTER_RECONFIG_DEAD_BITMAP_BYTES] } static void -formation_expected_marker(const ClusterFormationSnapshotV1 *snapshot, - ClusterFenceMarker *expected) +formation_expected_marker(const ClusterFormationSnapshotV1 *snapshot, ClusterFenceMarker *expected) { memset(expected, 0, sizeof(*expected)); expected->magic = CLUSTER_FENCE_MARKER_MAGIC; @@ -1012,16 +944,15 @@ formation_expected_marker(const ClusterFormationSnapshotV1 *snapshot, : snapshot->applied.coordinator_node_id; memcpy(expected->fenced_dead_bitmap, snapshot->excluded_bitmap, sizeof(expected->fenced_dead_bitmap)); - expected->marker_kind = snapshot->applied.event_id == 0 - ? CLUSTER_FENCE_MARKER_KIND_BASELINE - : CLUSTER_FENCE_MARKER_KIND_FENCE; + expected->marker_kind = snapshot->applied.event_id == 0 ? CLUSTER_FENCE_MARKER_KIND_BASELINE + : CLUSTER_FENCE_MARKER_KIND_FENCE; } ClusterFormationWitnessResult cluster_formation_witness_decide_v1(const ClusterFormationSnapshotV1 *f1, const ClusterFenceAuthorityProof *authority, - const ClusterFormationSnapshotV1 *f2, - uint16 origin_thread, bool opening_new_duty) + const ClusterFormationSnapshotV1 *f2, uint16 origin_thread, + bool opening_new_duty) { ClusterFenceMarker expected; int32 origin_node; @@ -1050,12 +981,10 @@ cluster_formation_witness_decide_v1(const ClusterFormationSnapshotV1 *f1, origin_node = (int32)origin_thread - 1; if (!formation_bitmap_has_node(f2->excluded_bitmap, origin_node) - || (opening_new_duty - && !formation_bitmap_has_node(f2->applied.dead_bitmap, origin_node))) + || (opening_new_duty && !formation_bitmap_has_node(f2->applied.dead_bitmap, origin_node))) return CLUSTER_FORMATION_WITNESS_ORIGIN_NOT_EXCLUDED; if (f2->victim_incarnation == 0 - || f2->victim_incarnation - != f2->membership.last_admitted_incarnation[origin_node] + || f2->victim_incarnation != f2->membership.last_admitted_incarnation[origin_node] || (f2->membership.membership_state[origin_node] != CLUSTER_MEMBER_DEAD && f2->membership.membership_state[origin_node] != CLUSTER_MEMBER_REMOVED)) return CLUSTER_FORMATION_WITNESS_OWNER_MISMATCH; @@ -1076,23 +1005,20 @@ cluster_formation_witness_decide_v1(const ClusterFormationSnapshotV1 *f1, static ClusterFormationWitnessResult formation_witness_decide_live_v1(const ClusterFormationSnapshotV1 *f1, const ClusterFenceAuthorityProof *authority, - const ClusterFormationSnapshotV1 *f2, - uint16 origin_thread) + const ClusterFormationSnapshotV1 *f2, uint16 origin_thread) { ClusterFenceMarker expected; int32 origin_node; - int i; + int i; if (f1 == NULL || authority == NULL || f2 == NULL || origin_thread == 0 || origin_thread > CLUSTER_MAX_NODES) return CLUSTER_FORMATION_WITNESS_BAD_ARGUMENT; if (memcmp(f1, f2, sizeof(*f1)) != 0) return CLUSTER_FORMATION_WITNESS_UNSTABLE; - if (f2->prebump_sync_active != 0 || !f2->self_join_admitted - || f2->self_join_failed + if (f2->prebump_sync_active != 0 || !f2->self_join_admitted || f2->self_join_failed || formation_bitmap_nonempty(f2->pending_join_bitmap) - || f2->applied.reconfig_kind == RECONFIG_KIND_JOIN_PENDING) - { + || f2->applied.reconfig_kind == RECONFIG_KIND_JOIN_PENDING) { return CLUSTER_FORMATION_WITNESS_UNSTABLE; } /* @@ -1109,8 +1035,7 @@ formation_witness_decide_live_v1(const ClusterFormationSnapshotV1 *f1, * whole phase3_timeout on every crash-rejoin. */ if (f2->local_epoch != f2->applied.new_epoch - && !(f2->self_join_admitted - && f2->local_epoch > f2->applied.new_epoch)) + && !(f2->self_join_admitted && f2->local_epoch > f2->applied.new_epoch)) return CLUSTER_FORMATION_WITNESS_UNSTABLE; if (authority->total_disk_count == 0 || authority->agree_disk_count <= authority->total_disk_count / 2 @@ -1137,19 +1062,16 @@ formation_witness_decide_live_v1(const ClusterFormationSnapshotV1 *f1, * admission proof, and only while the adopted epoch is strictly newer * than the stale applied epoch. */ - if ((!f2->self_join_admitted - || f2->local_epoch <= f2->applied.new_epoch) + if ((!f2->self_join_admitted || f2->local_epoch <= f2->applied.new_epoch) && (!cluster_fence_marker_valid_v1(&expected) - || !cluster_fence_marker_tuple_equal(&authority->marker, &expected))) - { + || !cluster_fence_marker_tuple_equal(&authority->marker, &expected))) { return CLUSTER_FORMATION_WITNESS_MARKER_UNPROVEN; } origin_node = (int32)origin_thread - 1; if (f2->membership.membership_state[origin_node] != CLUSTER_MEMBER_MEMBER || f2->membership.last_admitted_incarnation[origin_node] == 0 - || formation_bitmap_has_node(f2->excluded_bitmap, origin_node)) - { + || formation_bitmap_has_node(f2->excluded_bitmap, origin_node)) { return CLUSTER_FORMATION_WITNESS_OWNER_MISMATCH; } /* @@ -1162,8 +1084,7 @@ formation_witness_decide_live_v1(const ClusterFormationSnapshotV1 *f1, * publishing floors the witness stays OWNER_MISMATCH, the same transient * the phase-3 deadline loop already retries. */ - for (i = 0; i < CLUSTER_MAX_NODES; i++) - { + for (i = 0; i < CLUSTER_MAX_NODES; i++) { if (f2->membership.membership_state[i] != CLUSTER_MEMBER_MEMBER || formation_bitmap_has_node(f2->excluded_bitmap, i)) continue; @@ -1179,10 +1100,10 @@ formation_witness_decide_live_v1(const ClusterFormationSnapshotV1 *f1, * live witness: only the exact epoch-0 baseline with no reconfiguration debt * may omit self_join_admitted. */ static ClusterFormationWitnessResult -formation_witness_decide_recovery_control_v1( - const ClusterFormationSnapshotV1 *f1, - const ClusterFenceAuthorityProof *authority, - const ClusterFormationSnapshotV1 *f2, uint16 origin_thread) +formation_witness_decide_recovery_control_v1(const ClusterFormationSnapshotV1 *f1, + const ClusterFenceAuthorityProof *authority, + const ClusterFormationSnapshotV1 *f2, + uint16 origin_thread) { ClusterFenceMarker expected; int32 origin_node; @@ -1192,8 +1113,7 @@ formation_witness_decide_recovery_control_v1( || origin_thread > CLUSTER_MAX_NODES) return CLUSTER_FORMATION_WITNESS_BAD_ARGUMENT; if (f2->self_join_admitted) - return formation_witness_decide_live_v1( - f1, authority, f2, origin_thread); + return formation_witness_decide_live_v1(f1, authority, f2, origin_thread); if (memcmp(f1, f2, sizeof(*f1)) != 0) return CLUSTER_FORMATION_WITNESS_UNSTABLE; if (f2->prebump_sync_active != 0 || f2->self_join_failed @@ -1201,13 +1121,10 @@ formation_witness_decide_recovery_control_v1( || formation_bitmap_nonempty(f2->clean_departed_bitmap) || formation_bitmap_nonempty(f2->removed_bitmap) || formation_bitmap_nonempty(f2->excluded_bitmap) - || f2->local_epoch != CLUSTER_EPOCH_INITIAL - || f2->applied.event_id != 0 + || f2->local_epoch != CLUSTER_EPOCH_INITIAL || f2->applied.event_id != 0 || f2->applied.old_epoch != CLUSTER_EPOCH_INITIAL - || f2->applied.new_epoch != CLUSTER_EPOCH_INITIAL - || f2->applied.event_seq != 0 - || f2->applied.cssd_dead_generation != 0 - || f2->applied.reconfig_kind != RECONFIG_KIND_NONE + || f2->applied.new_epoch != CLUSTER_EPOCH_INITIAL || f2->applied.event_seq != 0 + || f2->applied.cssd_dead_generation != 0 || f2->applied.reconfig_kind != RECONFIG_KIND_NONE || formation_bitmap_nonempty(f2->applied.dead_bitmap) || formation_bitmap_nonempty(f2->applied.join_bitmap)) return CLUSTER_FORMATION_WITNESS_UNSTABLE; @@ -1265,29 +1182,27 @@ static ClusterFormationWitnessResult formation_authority_result(ClusterFenceAuthorityReadResult result) { switch (result) { - case CLUSTER_FENCE_AUTHORITY_OK: - return CLUSTER_FORMATION_WITNESS_READY; - case CLUSTER_FENCE_AUTHORITY_NO_MAJORITY: - return CLUSTER_FORMATION_WITNESS_MARKER_UNPROVEN; - case CLUSTER_FENCE_AUTHORITY_IO_UNAVAILABLE: - return CLUSTER_FORMATION_WITNESS_IO_FAILED; - case CLUSTER_FENCE_AUTHORITY_ENFORCEMENT_OFF: - case CLUSTER_FENCE_AUTHORITY_NO_CONFIG: - return CLUSTER_FORMATION_WITNESS_CAPABILITY_UNAVAILABLE; - case CLUSTER_FENCE_AUTHORITY_BAD_ARGUMENT: - case CLUSTER_FENCE_AUTHORITY_BAD_CONFIG: - case CLUSTER_FENCE_AUTHORITY_MIXED_VERSION: - case CLUSTER_FENCE_AUTHORITY_CORRUPT: - default: - return CLUSTER_FORMATION_WITNESS_CORRUPT; + case CLUSTER_FENCE_AUTHORITY_OK: + return CLUSTER_FORMATION_WITNESS_READY; + case CLUSTER_FENCE_AUTHORITY_NO_MAJORITY: + return CLUSTER_FORMATION_WITNESS_MARKER_UNPROVEN; + case CLUSTER_FENCE_AUTHORITY_IO_UNAVAILABLE: + return CLUSTER_FORMATION_WITNESS_IO_FAILED; + case CLUSTER_FENCE_AUTHORITY_ENFORCEMENT_OFF: + case CLUSTER_FENCE_AUTHORITY_NO_CONFIG: + return CLUSTER_FORMATION_WITNESS_CAPABILITY_UNAVAILABLE; + case CLUSTER_FENCE_AUTHORITY_BAD_ARGUMENT: + case CLUSTER_FENCE_AUTHORITY_BAD_CONFIG: + case CLUSTER_FENCE_AUTHORITY_MIXED_VERSION: + case CLUSTER_FENCE_AUTHORITY_CORRUPT: + default: + return CLUSTER_FORMATION_WITNESS_CORRUPT; } } static ClusterFormationWitnessResult -formation_witness_build_wait_internal(uint16 origin_thread, - bool opening_new_duty, - ClusterFormationWitnessMode mode, - int timeout_ms, +formation_witness_build_wait_internal(uint16 origin_thread, bool opening_new_duty, + ClusterFormationWitnessMode mode, int timeout_ms, ClusterFormationWitnessV1 **out) { ClusterFormationWitnessResult last = CLUSTER_FORMATION_WITNESS_UNSTABLE; @@ -1310,8 +1225,7 @@ formation_witness_build_wait_internal(uint16 origin_thread, uint64 now_us; proof_sequence = cluster_write_fence_authority_cache_sequence(); - if ((proof_sequence & UINT64_C(1)) != 0 - || proof_sequence >= UINT64_MAX - 1) { + if ((proof_sequence & UINT64_C(1)) != 0 || proof_sequence >= UINT64_MAX - 1) { last = CLUSTER_FORMATION_WITNESS_UNSTABLE; goto retry; } @@ -1323,15 +1237,13 @@ formation_witness_build_wait_internal(uint16 origin_thread, if (!cluster_reconfig_capture_formation_snapshot_v1(origin_thread, &f2)) return CLUSTER_FORMATION_WITNESS_CAPABILITY_UNAVAILABLE; if (mode == CLUSTER_FORMATION_WITNESS_MODE_LIVE) - last = formation_witness_decide_live_v1( - &f1, &authority, &f2, origin_thread); + last = formation_witness_decide_live_v1(&f1, &authority, &f2, origin_thread); else if (mode == CLUSTER_FORMATION_WITNESS_MODE_RECOVERY_CONTROL) - last = formation_witness_decide_recovery_control_v1( - &f1, &authority, &f2, origin_thread); + last = formation_witness_decide_recovery_control_v1(&f1, &authority, &f2, + origin_thread); else - last = cluster_formation_witness_decide_v1( - &f1, &authority, &f2, origin_thread, - opening_new_duty); + last = cluster_formation_witness_decide_v1(&f1, &authority, &f2, origin_thread, + opening_new_duty); if (last == CLUSTER_FORMATION_WITNESS_READY) { ClusterFormationWitnessV1 *witness; @@ -1353,10 +1265,8 @@ formation_witness_build_wait_internal(uint16 origin_thread, witness->f1 = f1; witness->f2 = f2; if (mode == CLUSTER_FORMATION_WITNESS_MODE_RECOVERY_CONTROL) { - witness->f1.reserved[0] - = CLUSTER_FORMATION_SNAPSHOT_RECOVERY_CONTROL; - witness->f2.reserved[0] - = CLUSTER_FORMATION_SNAPSHOT_RECOVERY_CONTROL; + witness->f1.reserved[0] = CLUSTER_FORMATION_SNAPSHOT_RECOVERY_CONTROL; + witness->f2.reserved[0] = CLUSTER_FORMATION_SNAPSHOT_RECOVERY_CONTROL; } *out = witness; return CLUSTER_FORMATION_WITNESS_READY; @@ -1375,32 +1285,27 @@ formation_witness_build_wait_internal(uint16 origin_thread, } ClusterFormationWitnessResult -cluster_formation_witness_build_wait(uint16 origin_thread, - bool opening_new_duty, int timeout_ms, +cluster_formation_witness_build_wait(uint16 origin_thread, bool opening_new_duty, int timeout_ms, ClusterFormationWitnessV1 **out) { return formation_witness_build_wait_internal( - origin_thread, opening_new_duty, - CLUSTER_FORMATION_WITNESS_MODE_DUTY, timeout_ms, out); + origin_thread, opening_new_duty, CLUSTER_FORMATION_WITNESS_MODE_DUTY, timeout_ms, out); } ClusterFormationWitnessResult -cluster_formation_witness_build_live_wait(uint16 origin_thread, - int timeout_ms, - ClusterFormationWitnessV1 **out) +cluster_formation_witness_build_live_wait(uint16 origin_thread, int timeout_ms, + ClusterFormationWitnessV1 **out) { return formation_witness_build_wait_internal( - origin_thread, false, CLUSTER_FORMATION_WITNESS_MODE_LIVE, - timeout_ms, out); + origin_thread, false, CLUSTER_FORMATION_WITNESS_MODE_LIVE, timeout_ms, out); } ClusterFormationWitnessResult -cluster_formation_witness_build_recovery_control_wait( - uint16 origin_thread, int timeout_ms, ClusterFormationWitnessV1 **out) +cluster_formation_witness_build_recovery_control_wait(uint16 origin_thread, int timeout_ms, + ClusterFormationWitnessV1 **out) { return formation_witness_build_wait_internal( - origin_thread, false, - CLUSTER_FORMATION_WITNESS_MODE_RECOVERY_CONTROL, timeout_ms, out); + origin_thread, false, CLUSTER_FORMATION_WITNESS_MODE_RECOVERY_CONTROL, timeout_ms, out); } ClusterFormationWitnessResult @@ -1416,15 +1321,15 @@ cluster_formation_witness_revalidate_nowait(const ClusterFormationWitnessV1 *wit return CLUSTER_FORMATION_WITNESS_CAPABILITY_UNAVAILABLE; result = cluster_write_fence_revalidate_cached_nowait(&witness->authority.marker, now_us); switch (result) { - case CLUSTER_FENCE_CACHE_MATCH: - return CLUSTER_FORMATION_WITNESS_READY; - case CLUSTER_FENCE_CACHE_STALE: - case CLUSTER_FENCE_CACHE_EXPIRED: - return CLUSTER_FORMATION_WITNESS_UNSTABLE; - case CLUSTER_FENCE_CACHE_INVALID: - case CLUSTER_FENCE_CACHE_UNAVAILABLE: - default: - return CLUSTER_FORMATION_WITNESS_CAPABILITY_UNAVAILABLE; + case CLUSTER_FENCE_CACHE_MATCH: + return CLUSTER_FORMATION_WITNESS_READY; + case CLUSTER_FENCE_CACHE_STALE: + case CLUSTER_FENCE_CACHE_EXPIRED: + return CLUSTER_FORMATION_WITNESS_UNSTABLE; + case CLUSTER_FENCE_CACHE_INVALID: + case CLUSTER_FENCE_CACHE_UNAVAILABLE: + default: + return CLUSTER_FORMATION_WITNESS_CAPABILITY_UNAVAILABLE; } } @@ -1433,9 +1338,8 @@ cluster_formation_witness_revalidate_nowait(const ClusterFormationWitnessV1 *wit * classification additionally tolerates only its one monotone local edge: * self_join_admitted 0 -> 1 after StartupXLOG completes the stripe gate. */ bool -cluster_formation_snapshot_matches_v1( - const ClusterFormationSnapshotV1 *expected, - const ClusterFormationSnapshotV1 *observed) +cluster_formation_snapshot_matches_v1(const ClusterFormationSnapshotV1 *expected, + const ClusterFormationSnapshotV1 *observed) { ClusterFormationSnapshotV1 normalized; @@ -1443,16 +1347,13 @@ cluster_formation_snapshot_matches_v1( return false; if (expected->reserved[0] == 0 && expected->reserved[1] == 0) return memcmp(expected, observed, sizeof(*expected)) == 0; - if (expected->reserved[0] - != CLUSTER_FORMATION_SNAPSHOT_RECOVERY_CONTROL - || expected->reserved[1] != 0 - || observed->reserved[0] != 0 || observed->reserved[1] != 0) + if (expected->reserved[0] != CLUSTER_FORMATION_SNAPSHOT_RECOVERY_CONTROL + || expected->reserved[1] != 0 || observed->reserved[0] != 0 || observed->reserved[1] != 0) return false; normalized = *observed; normalized.reserved[0] = CLUSTER_FORMATION_SNAPSHOT_RECOVERY_CONTROL; - if (expected->self_join_admitted == 0 - && normalized.self_join_admitted == 1) + if (expected->self_join_admitted == 0 && normalized.self_join_admitted == 1) normalized.self_join_admitted = 0; return memcmp(expected, &normalized, sizeof(*expected)) == 0; } @@ -1462,16 +1363,16 @@ cluster_formation_snapshot_matches_v1( * generation-bound counterpart of copy_classification_v1(): a copied proof * never becomes a timeless authority token. */ ClusterFormationWitnessResult -cluster_formation_classification_revalidate_nowait( - uint16 origin_thread, const ClusterFenceAuthorityProof *authority, - const ClusterFormationSnapshotV1 *snapshot) +cluster_formation_classification_revalidate_nowait(uint16 origin_thread, + const ClusterFenceAuthorityProof *authority, + const ClusterFormationSnapshotV1 *snapshot) { ClusterFormationSnapshotV1 current; ClusterFenceAuthorityCacheResult cache_result; uint64 now_us; - if (origin_thread == 0 || origin_thread > CLUSTER_MAX_NODES - || authority == NULL || snapshot == NULL) + if (origin_thread == 0 || origin_thread > CLUSTER_MAX_NODES || authority == NULL + || snapshot == NULL) return CLUSTER_FORMATION_WITNESS_BAD_ARGUMENT; if (!cluster_reconfig_capture_formation_snapshot_v1(origin_thread, ¤t)) return CLUSTER_FORMATION_WITNESS_CAPABILITY_UNAVAILABLE; @@ -1481,23 +1382,22 @@ cluster_formation_classification_revalidate_nowait( now_us = formation_monotonic_us(); if (now_us == 0) return CLUSTER_FORMATION_WITNESS_CAPABILITY_UNAVAILABLE; - cache_result = cluster_write_fence_revalidate_cached_nowait( - &authority->marker, now_us); - return cache_result == CLUSTER_FENCE_CACHE_MATCH - ? CLUSTER_FORMATION_WITNESS_READY - : (cache_result == CLUSTER_FENCE_CACHE_STALE - || cache_result == CLUSTER_FENCE_CACHE_EXPIRED) - ? CLUSTER_FORMATION_WITNESS_UNSTABLE - : CLUSTER_FORMATION_WITNESS_CAPABILITY_UNAVAILABLE; + cache_result = cluster_write_fence_revalidate_cached_nowait(&authority->marker, now_us); + return cache_result == CLUSTER_FENCE_CACHE_MATCH ? CLUSTER_FORMATION_WITNESS_READY + : (cache_result == CLUSTER_FENCE_CACHE_STALE + || cache_result == CLUSTER_FENCE_CACHE_EXPIRED) + ? CLUSTER_FORMATION_WITNESS_UNSTABLE + : CLUSTER_FORMATION_WITNESS_CAPABILITY_UNAVAILABLE; } bool -cluster_formation_witness_copy_classification_v1( - const ClusterFormationWitnessV1 *witness, uint16 *origin_thread, - ClusterFenceAuthorityProof *authority, ClusterFormationSnapshotV1 *snapshot) +cluster_formation_witness_copy_classification_v1(const ClusterFormationWitnessV1 *witness, + uint16 *origin_thread, + ClusterFenceAuthorityProof *authority, + ClusterFormationSnapshotV1 *snapshot) { - if (witness == NULL || witness->magic != CLUSTER_FORMATION_WITNESS_MAGIC || - origin_thread == NULL || authority == NULL || snapshot == NULL) + if (witness == NULL || witness->magic != CLUSTER_FORMATION_WITNESS_MAGIC + || origin_thread == NULL || authority == NULL || snapshot == NULL) return false; *origin_thread = witness->origin_thread; *authority = witness->authority; diff --git a/src/backend/cluster/cluster_recovery_merge.c b/src/backend/cluster/cluster_recovery_merge.c index 1af8452c994..168e56f8f67 100644 --- a/src/backend/cluster/cluster_recovery_merge.c +++ b/src/backend/cluster/cluster_recovery_merge.c @@ -84,8 +84,7 @@ bool cluster_recmerge_apply_foreign = false; #define CLUSTER_RECOVERY_FENCE_PLAN_MAGIC UINT32_C(0x52465034) /* "RFP4" */ -typedef struct ClusterRecoveryFenceOrigin -{ +typedef struct ClusterRecoveryFenceOrigin { uint16 origin_thread; ClusterRecoveryDutyKey duty; ClusterControlRootReadToken root_token; @@ -94,8 +93,7 @@ typedef struct ClusterRecoveryFenceOrigin PgracExternalFenceAdmissionSetV1 *admissions; } ClusterRecoveryFenceOrigin; -struct ClusterRecoveryFencePlan -{ +struct ClusterRecoveryFencePlan { uint32 magic; int32 owner_pid; uint16 own_thread; @@ -1000,26 +998,22 @@ cluster_recovery_merge_project_readonly(uint16 own_thread, XLogRecPtr own_redo, ClusterControlRootResult root_result; root_result = cluster_control_root_lookup_owner_by_node_runtime( - (int) tid - 1, &root_identity, &root_snapshot, &root_token); + (int)tid - 1, &root_identity, &root_snapshot, &root_token); if ((root_result != CLUSTER_CONTROL_ROOT_OK_PRIMARY && root_result != CLUSTER_CONTROL_ROOT_OK_PRIMARY_DEGRADED) || !cluster_recovery_duty_key_valid_v1(&root_identity) - || cluster_recovery_duty_key_compare(&root_identity, - &root_snapshot.identity) + || cluster_recovery_duty_key_compare(&root_identity, &root_snapshot.identity) != CLUSTER_RECOVERY_DUTY_COMPARE_EXACT) { - appendStringInfo(&blockers, - "%sthread %u canonical root unreadable (result %d)", - blockers.len ? "; " : "", (unsigned) tid, - (int) root_result); + appendStringInfo(&blockers, "%sthread %u canonical root unreadable (result %d)", + blockers.len ? "; " : "", (unsigned)tid, (int)root_result); } else { if (root_snapshot.checkpoint_lower_lsn == 0) appendStringInfo(&blockers, "%sthread %u has no checkpoint redo start", - blockers.len ? "; " : "", (unsigned) tid); - if ((root_snapshot.root_flags - & CLUSTER_CONTROL_ROOT_FLAG_FPW_WAS_OFF) != 0) + blockers.len ? "; " : "", (unsigned)tid); + if ((root_snapshot.root_flags & CLUSTER_CONTROL_ROOT_FLAG_FPW_WAS_OFF) != 0) appendStringInfo(&blockers, "%sthread %u ran with full_page_writes=off", - blockers.len ? "; " : "", (unsigned) tid); - out_start[tid] = (XLogRecPtr) root_snapshot.checkpoint_lower_lsn; + blockers.len ? "; " : "", (unsigned)tid); + out_start[tid] = (XLogRecPtr)root_snapshot.checkpoint_lower_lsn; } } } @@ -1038,10 +1032,10 @@ cluster_recovery_merge_project_readonly(uint16 own_thread, XLogRecPtr own_redo, static bool recovery_fence_plan_valid(const ClusterRecoveryFencePlan *plan) { - return plan != NULL && plan->magic == CLUSTER_RECOVERY_FENCE_PLAN_MAGIC && - plan->owner_pid == MyProcPid && plan->own_thread >= 1 && - plan->own_thread <= CLUSTER_WAL_STATE_SLOT_COUNT && - plan->origin_count <= CLUSTER_WAL_STATE_SLOT_COUNT; + return plan != NULL && plan->magic == CLUSTER_RECOVERY_FENCE_PLAN_MAGIC + && plan->owner_pid == MyProcPid && plan->own_thread >= 1 + && plan->own_thread <= CLUSTER_WAL_STATE_SLOT_COUNT + && plan->origin_count <= CLUSTER_WAL_STATE_SLOT_COUNT; } static void @@ -1051,8 +1045,7 @@ recovery_fence_plan_release_members(ClusterRecoveryFencePlan *plan) if (plan == NULL) return; - for (i = plan->origin_count; i > 0; i--) - { + for (i = plan->origin_count; i > 0; i--) { ClusterRecoveryFenceOrigin *origin = &plan->origins[i - 1]; cluster_external_fence_admission_set_release(&origin->admissions); @@ -1061,14 +1054,14 @@ recovery_fence_plan_release_members(ClusterRecoveryFencePlan *plan) } } -static void pg_attribute_noreturn() -recovery_fence_unavailable(int32 node_id, uint64 incarnation, - int verdict, int reason, const char *stage) +static void +pg_attribute_noreturn() recovery_fence_unavailable(int32 node_id, uint64 incarnation, int verdict, + int reason, const char *stage) { ereport(FATAL, (errcode(ERRCODE_CLUSTER_EXTERNAL_FENCE_UNAVAILABLE), - errmsg("external write exclusion is not proven for node %d incarnation " - UINT64_FORMAT, node_id, incarnation), + errmsg("external write exclusion is not proven for node %d incarnation " UINT64_FORMAT, + node_id, incarnation), errdetail("Cold recovery external-fence stage %s returned verdict %d, reason %d.", stage, verdict, reason), errhint("Restore the configured root fencing provider and retry; do not disable " @@ -1077,13 +1070,11 @@ recovery_fence_unavailable(int32 node_id, uint64 incarnation, } static int -recovery_fence_plan_find_origin(const ClusterRecoveryFencePlan *plan, - uint16 origin_thread) +recovery_fence_plan_find_origin(const ClusterRecoveryFencePlan *plan, uint16 origin_thread) { uint16 i; - for (i = 0; i < plan->origin_count; i++) - { + for (i = 0; i < plan->origin_count; i++) { if (plan->origins[i].origin_thread == origin_thread) return (int)i; } @@ -1096,8 +1087,7 @@ recovery_fence_plan_find_origin(const ClusterRecoveryFencePlan *plan, * failure destroys the complete plan; no subset can reach the merge claim. */ ClusterMergeEngage -cluster_recovery_merge_preflight_readonly(uint16 own_thread, - XLogRecPtr own_redo, +cluster_recovery_merge_preflight_readonly(uint16 own_thread, XLogRecPtr own_redo, ClusterRecoveryFencePlan **out_plan) { ClusterRecoveryFencePlan *plan; @@ -1105,10 +1095,9 @@ cluster_recovery_merge_preflight_readonly(uint16 own_thread, instr_time admission_started; uint16 origin_threads[CLUSTER_WAL_STATE_SLOT_COUNT]; uint16 tid; - uint32 required_flags = CLUSTER_CONTROL_ROOT_FLAG_CLAIM_VALID | - CLUSTER_CONTROL_ROOT_FLAG_CHECKPOINT_VALID | - CLUSTER_CONTROL_ROOT_FLAG_TAIL_VALID | - CLUSTER_CONTROL_ROOT_FLAG_RECOVERED_VALID; + uint32 required_flags + = CLUSTER_CONTROL_ROOT_FLAG_CLAIM_VALID | CLUSTER_CONTROL_ROOT_FLAG_CHECKPOINT_VALID + | CLUSTER_CONTROL_ROOT_FLAG_TAIL_VALID | CLUSTER_CONTROL_ROOT_FLAG_RECOVERED_VALID; if (out_plan == NULL || *out_plan != NULL) return CLUSTER_MERGE_NO_NO_PLAN; @@ -1116,12 +1105,10 @@ cluster_recovery_merge_preflight_readonly(uint16 own_thread, plan->magic = CLUSTER_RECOVERY_FENCE_PLAN_MAGIC; plan->owner_pid = MyProcPid; plan->own_thread = own_thread; - plan->acquire_timeout_ms_snapshot = - cluster_external_fence_acquire_timeout_ms; - engage = cluster_recovery_merge_project_readonly( - own_thread, own_redo, plan->replay_thread_bitmap, plan->start_lsn); - if (engage != CLUSTER_MERGE_ENGAGE) - { + plan->acquire_timeout_ms_snapshot = cluster_external_fence_acquire_timeout_ms; + engage = cluster_recovery_merge_project_readonly(own_thread, own_redo, + plan->replay_thread_bitmap, plan->start_lsn); + if (engage != CLUSTER_MERGE_ENGAGE) { MemSet(plan, 0, sizeof(*plan)); pfree(plan); return engage; @@ -1129,13 +1116,11 @@ cluster_recovery_merge_preflight_readonly(uint16 own_thread, plan->foreign_origin_bitmap[0] = plan->replay_thread_bitmap[0]; plan->foreign_origin_bitmap[1] = plan->replay_thread_bitmap[1]; - plan->foreign_origin_bitmap[(own_thread - 1) / 64] &= - ~(UINT64_C(1) << ((own_thread - 1) % 64)); + plan->foreign_origin_bitmap[(own_thread - 1) / 64] &= ~(UINT64_C(1) << ((own_thread - 1) % 64)); /* First close every classification. No provider call is reachable from * this loop, so a late non-current origin still yields zero sockets. */ - for (tid = 1; tid <= CLUSTER_WAL_STATE_SLOT_COUNT; tid++) - { + for (tid = 1; tid <= CLUSTER_WAL_STATE_SLOT_COUNT; tid++) { ClusterControlRootIdentity identity; ClusterControlRootSnapshot snapshot; ClusterControlRootReadToken token; @@ -1143,53 +1128,41 @@ cluster_recovery_merge_preflight_readonly(uint16 own_thread, ClusterRecoveryFenceOrigin *origin; int32 node_id; - if ((plan->foreign_origin_bitmap[(tid - 1) / 64] & - (UINT64_C(1) << ((tid - 1) % 64))) == 0) + if ((plan->foreign_origin_bitmap[(tid - 1) / 64] & (UINT64_C(1) << ((tid - 1) % 64))) == 0) continue; node_id = (int32)tid - 1; MemSet(&identity, 0, sizeof(identity)); MemSet(&snapshot, 0, sizeof(snapshot)); MemSet(&token, 0, sizeof(token)); - root_result = cluster_control_root_lookup_owner_by_node_runtime( - node_id, &identity, &snapshot, &token); - if ((root_result != CLUSTER_CONTROL_ROOT_OK_PRIMARY && - root_result != CLUSTER_CONTROL_ROOT_OK_PRIMARY_DEGRADED) || - !cluster_recovery_duty_key_valid_v1(&identity) || - identity.origin_thread_id != tid || - identity.origin_node_id != node_id || - cluster_recovery_duty_key_compare(&snapshot.identity, &identity) != - CLUSTER_RECOVERY_DUTY_COMPARE_EXACT) - { + root_result = cluster_control_root_lookup_owner_by_node_runtime(node_id, &identity, + &snapshot, &token); + if ((root_result != CLUSTER_CONTROL_ROOT_OK_PRIMARY + && root_result != CLUSTER_CONTROL_ROOT_OK_PRIMARY_DEGRADED) + || !cluster_recovery_duty_key_valid_v1(&identity) || identity.origin_thread_id != tid + || identity.origin_node_id != node_id + || cluster_recovery_duty_key_compare(&snapshot.identity, &identity) + != CLUSTER_RECOVERY_DUTY_COMPARE_EXACT) { recovery_fence_plan_release_members(plan); MemSet(plan, 0, sizeof(*plan)); pfree(plan); - recovery_fence_unavailable(node_id, - identity.origin_owner_incarnation, - PGRAC_EXTERNAL_FENCE_UNAVAILABLE, (int)root_result, - "root-classification"); + recovery_fence_unavailable(node_id, identity.origin_owner_incarnation, + PGRAC_EXTERNAL_FENCE_UNAVAILABLE, (int)root_result, + "root-classification"); } - if (snapshot.lifecycle == - CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_COMPLETE) - { - plan->replay_thread_bitmap[(tid - 1) / 64] &= - ~(UINT64_C(1) << ((tid - 1) % 64)); - plan->foreign_origin_bitmap[(tid - 1) / 64] &= - ~(UINT64_C(1) << ((tid - 1) % 64)); + if (snapshot.lifecycle == CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_COMPLETE) { + plan->replay_thread_bitmap[(tid - 1) / 64] &= ~(UINT64_C(1) << ((tid - 1) % 64)); + plan->foreign_origin_bitmap[(tid - 1) / 64] &= ~(UINT64_C(1) << ((tid - 1) % 64)); plan->start_lsn[tid] = InvalidXLogRecPtr; continue; } - if (snapshot.lifecycle != - CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_REQUIRED || - (snapshot.root_flags & required_flags) != required_flags) - { + if (snapshot.lifecycle != CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_REQUIRED + || (snapshot.root_flags & required_flags) != required_flags) { recovery_fence_plan_release_members(plan); MemSet(plan, 0, sizeof(*plan)); pfree(plan); - recovery_fence_unavailable(node_id, - identity.origin_owner_incarnation, - PGRAC_EXTERNAL_FENCE_UNAVAILABLE, - PGRAC_EXTERNAL_FENCE_DENY_ROOT_NOT_COMPLETE, - "root-lifecycle"); + recovery_fence_unavailable( + node_id, identity.origin_owner_incarnation, PGRAC_EXTERNAL_FENCE_UNAVAILABLE, + PGRAC_EXTERNAL_FENCE_DENY_ROOT_NOT_COMPLETE, "root-lifecycle"); } origin = &plan->origins[plan->origin_count]; origin->origin_thread = tid; @@ -1199,17 +1172,14 @@ cluster_recovery_merge_preflight_readonly(uint16 own_thread, plan->origin_count++; } - if (plan->origin_count == 0) - { + if (plan->origin_count == 0) { MemSet(plan, 0, sizeof(*plan)); pfree(plan); return CLUSTER_MERGE_NO_NO_CANDIDATES; } - if (!cluster_recovery_fence_plan_shape_valid( - own_thread, plan->replay_thread_bitmap, - plan->foreign_origin_bitmap, origin_threads, - plan->origin_count)) - { + if (!cluster_recovery_fence_plan_shape_valid(own_thread, plan->replay_thread_bitmap, + plan->foreign_origin_bitmap, origin_threads, + plan->origin_count)) { MemSet(plan, 0, sizeof(*plan)); pfree(plan); return CLUSTER_MERGE_NO_NO_PLAN; @@ -1217,51 +1187,42 @@ cluster_recovery_merge_preflight_readonly(uint16 own_thread, /* Then build every formation/NeedSet. Only after all nonwaitable * classification gates are closed may the aggregate admission loop run. */ - for (tid = 0; tid < plan->origin_count; tid++) - { + for (tid = 0; tid < plan->origin_count; tid++) { ClusterRecoveryFenceOrigin *origin = &plan->origins[tid]; ClusterFormationWitnessResult formation_result; formation_result = cluster_formation_witness_build_wait( - origin->origin_thread, false, - plan->acquire_timeout_ms_snapshot, - &origin->formation); - if (formation_result != CLUSTER_FORMATION_WITNESS_READY) - { + origin->origin_thread, false, plan->acquire_timeout_ms_snapshot, &origin->formation); + if (formation_result != CLUSTER_FORMATION_WITNESS_READY) { int32 node_id = origin->duty.origin_node_id; uint64 incarnation = origin->duty.origin_owner_incarnation; recovery_fence_plan_release_members(plan); MemSet(plan, 0, sizeof(*plan)); pfree(plan); - recovery_fence_unavailable(node_id, incarnation, - PGRAC_EXTERNAL_FENCE_UNAVAILABLE, (int)formation_result, - "formation"); + recovery_fence_unavailable(node_id, incarnation, PGRAC_EXTERNAL_FENCE_UNAVAILABLE, + (int)formation_result, "formation"); } } - for (tid = 0; tid < plan->origin_count; tid++) - { + for (tid = 0; tid < plan->origin_count; tid++) { ClusterRecoveryFenceOrigin *origin = &plan->origins[tid]; PgracExternalFenceNeedSetResult need_result; - need_result = cluster_external_fence_need_set_build( - &origin->duty, origin->formation, &origin->needs); - if (need_result != PGRAC_EXTERNAL_FENCE_NEED_SET_OK) - { + need_result = cluster_external_fence_need_set_build(&origin->duty, origin->formation, + &origin->needs); + if (need_result != PGRAC_EXTERNAL_FENCE_NEED_SET_OK) { int32 node_id = origin->duty.origin_node_id; uint64 incarnation = origin->duty.origin_owner_incarnation; recovery_fence_plan_release_members(plan); MemSet(plan, 0, sizeof(*plan)); pfree(plan); - recovery_fence_unavailable(node_id, incarnation, - PGRAC_EXTERNAL_FENCE_UNAVAILABLE, (int)need_result, - "need-set"); + recovery_fence_unavailable(node_id, incarnation, PGRAC_EXTERNAL_FENCE_UNAVAILABLE, + (int)need_result, "need-set"); } } INSTR_TIME_SET_CURRENT(admission_started); - for (tid = 0; tid < plan->origin_count; tid++) - { + for (tid = 0; tid < plan->origin_count; tid++) { ClusterRecoveryFenceOrigin *origin = &plan->origins[tid]; PgracExternalFenceVerdict verdict; PgracExternalFenceDenyReason reason; @@ -1276,30 +1237,24 @@ cluster_recovery_merge_preflight_readonly(uint16 own_thread, elapsed_ms_ceil = (int)elapsed_ms; if ((double)elapsed_ms_ceil < elapsed_ms) elapsed_ms_ceil++; - remaining_ms = plan->acquire_timeout_ms_snapshot - - elapsed_ms_ceil; - if (remaining_ms <= 0) - { + remaining_ms = plan->acquire_timeout_ms_snapshot - elapsed_ms_ceil; + if (remaining_ms <= 0) { verdict = PGRAC_EXTERNAL_FENCE_UNAVAILABLE; reason = PGRAC_EXTERNAL_FENCE_DENY_TIMEOUT; - } - else - { - verdict = cluster_external_fence_admit_set_wait( - origin->needs, origin->formation, remaining_ms, - &origin->admissions); + } else { + verdict = cluster_external_fence_admit_set_wait(origin->needs, origin->formation, + remaining_ms, &origin->admissions); reason = cluster_external_fence_last_deny_reason(); } - if (verdict != PGRAC_EXTERNAL_FENCE_WRITE_EXCLUDED) - { + if (verdict != PGRAC_EXTERNAL_FENCE_WRITE_EXCLUDED) { int32 node_id = origin->duty.origin_node_id; uint64 incarnation = origin->duty.origin_owner_incarnation; recovery_fence_plan_release_members(plan); MemSet(plan, 0, sizeof(*plan)); pfree(plan); - recovery_fence_unavailable(node_id, incarnation, - (int)verdict, (int)reason, "admission-set"); + recovery_fence_unavailable(node_id, incarnation, (int)verdict, (int)reason, + "admission-set"); } } @@ -1309,20 +1264,18 @@ cluster_recovery_merge_preflight_readonly(uint16 own_thread, } bool -cluster_recovery_merge_fence_plan_acquire_serial( - ClusterRecoveryFencePlan *plan) +cluster_recovery_merge_fence_plan_acquire_serial(ClusterRecoveryFencePlan *plan) { ClusterRecoverySerialRequest *requests; ClusterRecoverySerialAcquireResult result; uint16 failed_index; uint16 i; - if (!recovery_fence_plan_valid(plan) || !plan->sealed || - plan->serial_held || plan->committed || plan->origin_count == 0) + if (!recovery_fence_plan_valid(plan) || !plan->sealed || plan->serial_held || plan->committed + || plan->origin_count == 0) return false; requests = palloc0(sizeof(*requests) * plan->origin_count); - for (i = 0; i < plan->origin_count; i++) - { + for (i = 0; i < plan->origin_count; i++) { ClusterRecoveryFenceOrigin *origin = &plan->origins[i]; requests[i].mode = CLUSTER_RECOVERY_SERIAL_COLD_FORMED; @@ -1331,15 +1284,12 @@ cluster_recovery_merge_fence_plan_acquire_serial( requests[i].formation = origin->formation; requests[i].fence_need_set = origin->needs; requests[i].fence_admission_set = origin->admissions; - requests[i].acquire_timeout_ms = - plan->acquire_timeout_ms_snapshot; - requests[i].release_timeout_ms = - plan->acquire_timeout_ms_snapshot; + requests[i].acquire_timeout_ms = plan->acquire_timeout_ms_snapshot; + requests[i].release_timeout_ms = plan->acquire_timeout_ms_snapshot; } - result = cluster_recovery_serial_acquire_set( - requests, plan->origin_count, - plan->acquire_timeout_ms_snapshot, - &plan->serial_guards, &failed_index); + result = cluster_recovery_serial_acquire_set(requests, plan->origin_count, + plan->acquire_timeout_ms_snapshot, + &plan->serial_guards, &failed_index); pfree(requests); if (result != CLUSTER_RECOVERY_SERIAL_GRANTED) return false; @@ -1350,7 +1300,7 @@ cluster_recovery_merge_fence_plan_acquire_serial( bool cluster_recovery_merge_commit_plan_nowait(ClusterRecoveryFencePlan *plan) { - uint64 current_replay[2] = {0, 0}; + uint64 current_replay[2] = { 0, 0 }; uint64 current_foreign[2]; XLogRecPtr current_start[CLUSTER_WAL_STATE_SLOT_COUNT + 1]; uint16 current_origins[CLUSTER_WAL_STATE_SLOT_COUNT]; @@ -1358,62 +1308,50 @@ cluster_recovery_merge_commit_plan_nowait(ClusterRecoveryFencePlan *plan) ClusterMergeEngage engage; uint16 tid; - if (!recovery_fence_plan_valid(plan) || !plan->sealed || - !plan->serial_held || plan->committed) + if (!recovery_fence_plan_valid(plan) || !plan->sealed || !plan->serial_held || plan->committed) return false; MemSet(current_start, 0, sizeof(current_start)); engage = cluster_recovery_merge_project_readonly( - plan->own_thread, plan->start_lsn[plan->own_thread], - current_replay, current_start); + plan->own_thread, plan->start_lsn[plan->own_thread], current_replay, current_start); if (engage != CLUSTER_MERGE_ENGAGE) return false; current_foreign[0] = current_replay[0]; current_foreign[1] = current_replay[1]; - current_foreign[(plan->own_thread - 1) / 64] &= - ~(UINT64_C(1) << ((plan->own_thread - 1) % 64)); + current_foreign[(plan->own_thread - 1) / 64] &= ~(UINT64_C(1) << ((plan->own_thread - 1) % 64)); - for (tid = 1; tid <= CLUSTER_WAL_STATE_SLOT_COUNT; tid++) - { + for (tid = 1; tid <= CLUSTER_WAL_STATE_SLOT_COUNT; tid++) { ClusterControlRootSnapshot snapshot; ClusterControlRootReadToken token; ClusterControlRootResult root_result; int origin_index; - if ((current_foreign[(tid - 1) / 64] & - (UINT64_C(1) << ((tid - 1) % 64))) == 0) + if ((current_foreign[(tid - 1) / 64] & (UINT64_C(1) << ((tid - 1) % 64))) == 0) continue; origin_index = recovery_fence_plan_find_origin(plan, tid); if (origin_index < 0) return false; - root_result = cluster_control_root_read_canonical( - tid, &plan->origins[origin_index].duty, - CLUSTER_CONTROL_ROOT_READ_STRONG, &snapshot, &token); - if ((root_result != CLUSTER_CONTROL_ROOT_OK_PRIMARY && - root_result != CLUSTER_CONTROL_ROOT_OK_PRIMARY_DEGRADED) || - snapshot.lifecycle != - CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_REQUIRED || - cluster_recovery_duty_key_compare( - &snapshot.identity, &plan->origins[origin_index].duty) != - CLUSTER_RECOVERY_DUTY_COMPARE_EXACT || - memcmp(&token, &plan->origins[origin_index].root_token, - sizeof(token)) != 0) + root_result = cluster_control_root_read_canonical(tid, &plan->origins[origin_index].duty, + CLUSTER_CONTROL_ROOT_READ_STRONG, + &snapshot, &token); + if ((root_result != CLUSTER_CONTROL_ROOT_OK_PRIMARY + && root_result != CLUSTER_CONTROL_ROOT_OK_PRIMARY_DEGRADED) + || snapshot.lifecycle != CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_REQUIRED + || cluster_recovery_duty_key_compare(&snapshot.identity, + &plan->origins[origin_index].duty) + != CLUSTER_RECOVERY_DUTY_COMPARE_EXACT + || memcmp(&token, &plan->origins[origin_index].root_token, sizeof(token)) != 0) return false; current_origins[current_count++] = tid; } - if (!cluster_recovery_fence_plan_shape_valid( - plan->own_thread, current_replay, current_foreign, - current_origins, current_count) || - memcmp(current_replay, plan->replay_thread_bitmap, - sizeof(current_replay)) != 0 || - memcmp(current_foreign, plan->foreign_origin_bitmap, - sizeof(current_foreign)) != 0 || - current_count != plan->origin_count) + if (!cluster_recovery_fence_plan_shape_valid(plan->own_thread, current_replay, current_foreign, + current_origins, current_count) + || memcmp(current_replay, plan->replay_thread_bitmap, sizeof(current_replay)) != 0 + || memcmp(current_foreign, plan->foreign_origin_bitmap, sizeof(current_foreign)) != 0 + || current_count != plan->origin_count) return false; - for (tid = 1; tid <= CLUSTER_WAL_STATE_SLOT_COUNT; tid++) - { - if ((current_replay[(tid - 1) / 64] & - (UINT64_C(1) << ((tid - 1) % 64))) != 0 && - current_start[tid] != plan->start_lsn[tid]) + for (tid = 1; tid <= CLUSTER_WAL_STATE_SLOT_COUNT; tid++) { + if ((current_replay[(tid - 1) / 64] & (UINT64_C(1) << ((tid - 1) % 64))) != 0 + && current_start[tid] != plan->start_lsn[tid]) return false; } if (!cluster_recovery_merge_fence_plan_revalidate_nowait(plan)) @@ -1423,55 +1361,47 @@ cluster_recovery_merge_commit_plan_nowait(ClusterRecoveryFencePlan *plan) } bool -cluster_recovery_merge_fence_plan_copy_replay( - const ClusterRecoveryFencePlan *plan, uint64 out_bitmap[2], - XLogRecPtr *out_start) +cluster_recovery_merge_fence_plan_copy_replay(const ClusterRecoveryFencePlan *plan, + uint64 out_bitmap[2], XLogRecPtr *out_start) { uint16 tid; - if (!recovery_fence_plan_valid(plan) || !plan->committed || - out_bitmap == NULL || out_start == NULL) + if (!recovery_fence_plan_valid(plan) || !plan->committed || out_bitmap == NULL + || out_start == NULL) return false; - memcpy(out_bitmap, plan->replay_thread_bitmap, - sizeof(plan->replay_thread_bitmap)); + memcpy(out_bitmap, plan->replay_thread_bitmap, sizeof(plan->replay_thread_bitmap)); for (tid = 0; tid <= CLUSTER_WAL_STATE_SLOT_COUNT; tid++) out_start[tid] = plan->start_lsn[tid]; return true; } bool -cluster_recovery_merge_fence_plan_revalidate_nowait( - ClusterRecoveryFencePlan *plan) +cluster_recovery_merge_fence_plan_revalidate_nowait(ClusterRecoveryFencePlan *plan) { PgracExternalFenceDenyReason reason; uint16 i; - if (!recovery_fence_plan_valid(plan) || !plan->sealed || - !plan->serial_held || plan->origin_count == 0 || - plan->serial_guards.count != plan->origin_count) + if (!recovery_fence_plan_valid(plan) || !plan->sealed || !plan->serial_held + || plan->origin_count == 0 || plan->serial_guards.count != plan->origin_count) return false; - for (i = 0; i < plan->origin_count; i++) - { + for (i = 0; i < plan->origin_count; i++) { ClusterRecoveryFenceOrigin *origin = &plan->origins[i]; - if (cluster_recovery_serial_revalidate( - &plan->serial_guards.guards[i]) != - CLUSTER_RECOVERY_SERIAL_CURRENT || - cluster_formation_witness_revalidate_nowait( - origin->formation) != CLUSTER_FORMATION_WITNESS_READY || - !cluster_external_fence_need_set_revalidate_nowait( - origin->needs, origin->formation, &reason) || - !cluster_external_fence_revalidate_set_nowait( - origin->admissions, origin->needs, origin->formation, - &reason)) + if (cluster_recovery_serial_revalidate(&plan->serial_guards.guards[i]) + != CLUSTER_RECOVERY_SERIAL_CURRENT + || cluster_formation_witness_revalidate_nowait(origin->formation) + != CLUSTER_FORMATION_WITNESS_READY + || !cluster_external_fence_need_set_revalidate_nowait(origin->needs, origin->formation, + &reason) + || !cluster_external_fence_revalidate_set_nowait(origin->admissions, origin->needs, + origin->formation, &reason)) return false; } return true; } bool -cluster_recovery_merge_fence_plan_release_serial( - ClusterRecoveryFencePlan *plan) +cluster_recovery_merge_fence_plan_release_serial(ClusterRecoveryFencePlan *plan) { ClusterRecoverySerialReleaseResult result; @@ -1654,16 +1584,13 @@ cluster_recovery_merge_begin_internal(const uint64 merge_bitmap[2], const XLogRe if (!restore_mode) { root_result = cluster_control_root_lookup_owner_by_node_runtime( - (int) tid - 1, &root_identity, &root_snapshot, &root_token); + (int)tid - 1, &root_identity, &root_snapshot, &root_token); if ((root_result == CLUSTER_CONTROL_ROOT_OK_PRIMARY || root_result == CLUSTER_CONTROL_ROOT_OK_PRIMARY_DEGRADED) - && cluster_recovery_duty_key_compare( - &root_identity, &root_snapshot.identity) + && cluster_recovery_duty_key_compare(&root_identity, &root_snapshot.identity) == CLUSTER_RECOVERY_DUTY_COMPARE_EXACT - && root_snapshot.validated_tail_lsn_exclusive - > (uint64) start_lsn[tid]) - validated_min = - (XLogRecPtr) root_snapshot.validated_tail_lsn_exclusive; + && root_snapshot.validated_tail_lsn_exclusive > (uint64)start_lsn[tid]) + validated_min = (XLogRecPtr)root_snapshot.validated_tail_lsn_exclusive; } ms->valid_end = merge_compute_valid_end(ms->dir, start_lsn[tid], validated_min, !restore_mode && tid != own_thread, tid, tli, diff --git a/src/backend/cluster/cluster_recovery_plan.c b/src/backend/cluster/cluster_recovery_plan.c index 152c2e40cfc..93fe25ba08f 100644 --- a/src/backend/cluster/cluster_recovery_plan.c +++ b/src/backend/cluster/cluster_recovery_plan.c @@ -314,11 +314,10 @@ cluster_recovery_plan_generate(uint32 dbstate_at_startup, bool local_recovery_ne * §A two-step discovered-identity pattern (the startup process * is the frozen CF(S)-capable recovery admission, AD-023 §4). */ - root_result = cluster_control_root_read_canonical_discovered( - tid, &snapshot, &token); + root_result = cluster_control_root_read_canonical_discovered(tid, &snapshot, &token); read_verdict = (int)root_result; - verdict = cluster_recovery_classify_root_slot( - root_result, &snapshot, own_thread, tid, now_us, CheckPointTimeout); + verdict = cluster_recovery_classify_root_slot(root_result, &snapshot, own_thread, tid, + now_us, CheckPointTimeout); if (root_result == CLUSTER_CONTROL_ROOT_OK_PRIMARY || root_result == CLUSTER_CONTROL_ROOT_OK_PRIMARY_DEGRADED) { @@ -347,8 +346,7 @@ cluster_recovery_plan_generate(uint32 dbstate_at_startup, bool local_recovery_ne */ v = cluster_wal_state_read_slot(tid, &slot); read_verdict = (int)v; - verdict = cluster_recovery_classify_slot(v, &slot, own_thread, tid, - now_us, + verdict = cluster_recovery_classify_slot(v, &slot, own_thread, tid, now_us, cluster_recovery_stale_active_ms); if (v == CLUSTER_WAL_SLOT_OK) { if (slot.highest_lsn > plan.max_highest_lsn) @@ -382,9 +380,9 @@ cluster_recovery_plan_generate(uint32 dbstate_at_startup, bool local_recovery_ne } if (verdict != CLUSTER_RECOVERY_THREAD_EMPTY) - ereport(DEBUG1, (errmsg("recovery plan: thread %u verdict %d (read verdict %d, bit22=%d)", - (unsigned)tid, (int)verdict, read_verdict, - bit22_active ? 1 : 0))); + ereport(DEBUG1, + (errmsg("recovery plan: thread %u verdict %d (read verdict %d, bit22=%d)", + (unsigned)tid, (int)verdict, read_verdict, bit22_active ? 1 : 0))); } plan.generated = true; @@ -459,8 +457,7 @@ cluster_thread_recovery_pin_projection(uint16 dead_tid, uint64 episode_epoch) slot = cluster_thread_recovery_replay_slot(dead_tid); if (slot == NULL) return false; - root_result = cluster_control_root_read_canonical_discovered( - dead_tid, &snapshot, &token); + root_result = cluster_control_root_read_canonical_discovered(dead_tid, &snapshot, &token); if (root_result != CLUSTER_CONTROL_ROOT_OK_PRIMARY && root_result != CLUSTER_CONTROL_ROOT_OK_PRIMARY_DEGRADED) return false; @@ -487,18 +484,16 @@ cluster_thread_recovery_pin_projection(uint16 dead_tid, uint64 episode_epoch) bool cluster_thread_recovery_projection_current(uint16 dead_tid, uint64 episode_epoch, ClusterControlRootReadToken *token_out, - uint64 *validated_tail_out, - uint64 *checkpoint_lower_out, - uint64 *lifecycle_out, - uint32 *tail_tli_out, + uint64 *validated_tail_out, uint64 *checkpoint_lower_out, + uint64 *lifecycle_out, uint32 *tail_tli_out, uint32 *checkpoint_tli_out) { ClusterThreadReplaySlot *slot; slot = cluster_thread_recovery_replay_slot(dead_tid); - return cluster_thread_recovery_projection_read( - slot, episode_epoch, token_out, validated_tail_out, checkpoint_lower_out, - lifecycle_out, tail_tli_out, checkpoint_tli_out); + return cluster_thread_recovery_projection_read(slot, episode_epoch, token_out, + validated_tail_out, checkpoint_lower_out, + lifecycle_out, tail_tli_out, checkpoint_tli_out); } /* diff --git a/src/backend/cluster/cluster_recovery_worker.c b/src/backend/cluster/cluster_recovery_worker.c index 93f66455c58..ae0361812e6 100644 --- a/src/backend/cluster/cluster_recovery_worker.c +++ b/src/backend/cluster/cluster_recovery_worker.c @@ -213,8 +213,7 @@ validate_stream_from_root(uint16 tid, const ClusterControlRootSnapshot *snapshot return CLUSTER_RECOVERY_STREAM_SUSPECT; if (!cluster_recovery_worker_target_page(snapshot->validated_tail_lsn_exclusive, - wal_segment_size, &segno, - &page_offset, &pageaddr)) + wal_segment_size, &segno, &page_offset, &pageaddr)) return CLUSTER_RECOVERY_STREAM_UNREADABLE; /* no written bytes */ /* Segment file name is CONSTRUCTED (never a directory scan; the @@ -257,8 +256,7 @@ cluster_recovery_worker_revalidate(uint16 thread_id) ClusterControlRootReadToken token; ClusterControlRootResult root_result; - root_result = cluster_control_root_read_canonical_discovered( - thread_id, &snapshot, &token); + root_result = cluster_control_root_read_canonical_discovered(thread_id, &snapshot, &token); if (root_result != CLUSTER_CONTROL_ROOT_OK_PRIMARY && root_result != CLUSTER_CONTROL_ROOT_OK_PRIMARY_DEGRADED) return CLUSTER_RECOVERY_STREAM_UNREADABLE; @@ -342,32 +340,30 @@ cluster_recovery_worker_main(Datum main_arg) * or stale projection fails closed. */ if (!cluster_thread_recovery_projection_current( - tid, (uint64) pool->generation, &pin_token, - &pin_validated_tail, &pin_checkpoint_lower, - &pin_lifecycle, &pin_tail_tli, - &pin_checkpoint_tli)) { + tid, (uint64)pool->generation, &pin_token, &pin_validated_tail, + &pin_checkpoint_lower, &pin_lifecycle, &pin_tail_tli, &pin_checkpoint_tli)) { sv = CLUSTER_RECOVERY_STREAM_UNREADABLE; } else { memset(&pin_snapshot, 0, sizeof(pin_snapshot)); pin_snapshot.identity.origin_thread_id = tid; - pin_snapshot.identity.origin_node_id = (int32) tid - 1; - pin_snapshot.lifecycle = (uint32) pin_lifecycle; + pin_snapshot.identity.origin_node_id = (int32)tid - 1; + pin_snapshot.lifecycle = (uint32)pin_lifecycle; pin_snapshot.validated_tail_lsn_exclusive = pin_validated_tail; pin_snapshot.checkpoint_lower_lsn = pin_checkpoint_lower; pin_snapshot.tail_tli = pin_tail_tli; pin_snapshot.checkpoint_tli = pin_checkpoint_tli; - (void) pin_token; - (void) pin_checkpoint_lower; - (void) pin_checkpoint_tli; + (void)pin_token; + (void)pin_checkpoint_lower; + (void)pin_checkpoint_tli; /* * Re-classify from the pinned lifecycle (ALIVE-biased, * contract): a peer with a recent publication is * SKIPPED. Only CRASHED_CANDIDATE gets validated. */ - if (cluster_recovery_classify_root_slot( - CLUSTER_CONTROL_ROOT_OK_PRIMARY, &pin_snapshot, - own_thread, tid, now_us, CheckPointTimeout) + if (cluster_recovery_classify_root_slot(CLUSTER_CONTROL_ROOT_OK_PRIMARY, + &pin_snapshot, own_thread, tid, now_us, + CheckPointTimeout) != CLUSTER_RECOVERY_THREAD_CRASHED_CANDIDATE) { sv = CLUSTER_RECOVERY_STREAM_SKIPPED; } else { @@ -389,11 +385,9 @@ cluster_recovery_worker_main(Datum main_arg) } else { ClusterRecoveryThreadVerdict verdict; - verdict = cluster_recovery_classify_slot( - v, ®_slot, own_thread, tid, now_us, - cluster_recovery_stale_active_ms); - if (verdict - != CLUSTER_RECOVERY_THREAD_CRASHED_CANDIDATE) { + verdict = cluster_recovery_classify_slot(v, ®_slot, own_thread, tid, now_us, + cluster_recovery_stale_active_ms); + if (verdict != CLUSTER_RECOVERY_THREAD_CRASHED_CANDIDATE) { sv = CLUSTER_RECOVERY_STREAM_SKIPPED; } else { sv = validate_stream(tid, ®_slot); @@ -480,12 +474,10 @@ cluster_recovery_workers_launch(void) * will refuse it (UNREADABLE verdict). */ for (tid = XLP_THREAD_ID_FIRST_REAL; tid <= CLUSTER_WAL_THREAD_MAX; tid++) { - if ((plan.candidate_bitmap[(tid - 1) / 64] - & (UINT64_C(1) << ((tid - 1) % 64))) == 0) + if ((plan.candidate_bitmap[(tid - 1) / 64] & (UINT64_C(1) << ((tid - 1) % 64))) == 0) continue; if (cluster_r4_bit22_cutover_active()) { - (void) cluster_thread_recovery_pin_projection( - tid, (uint64) pool->generation); + (void)cluster_thread_recovery_pin_projection(tid, (uint64)pool->generation); } } diff --git a/src/backend/cluster/cluster_remote_xact.c b/src/backend/cluster/cluster_remote_xact.c index c401b64f670..c83c599ec8d 100644 --- a/src/backend/cluster/cluster_remote_xact.c +++ b/src/backend/cluster/cluster_remote_xact.c @@ -158,9 +158,9 @@ cluster_remote_xact_shmem_init(void) * (SlruInternalWritePage O_CREAT creates the FILE, not the DIR). */ if (MakePGDirectory(CLUSTER_REMOTE_XACT_DIR_V2) < 0 && errno != EEXIST) - ereport(FATAL, (errcode_for_file_access(), - errmsg("could not create directory \"%s\": %m", - CLUSTER_REMOTE_XACT_DIR_V2))); + ereport(FATAL, + (errcode_for_file_access(), + errmsg("could not create directory \"%s\": %m", CLUSTER_REMOTE_XACT_DIR_V2))); } else { Assert(found); } @@ -214,8 +214,8 @@ remote_xact_open_page(int origin_node, TransactionId xid, bool create) static void remote_xact_force_durable(int pageno) { - FileTag tag; - char path[MAXPGPATH]; + FileTag tag; + char path[MAXPGPATH]; /* * RF-SIDE pending/projection readiness is allowed only after stable @@ -223,65 +223,59 @@ remote_xact_force_durable(int pageno) * force the exact segment synchronously before returning to the caller. */ SimpleLruWriteAll(ClusterRemoteXactCtl, true); - MemSet(&tag, 0, sizeof(tag)); - tag.segno = (uint32) (pageno / SLRU_PAGES_PER_SEGMENT); + memset(&tag, 0, sizeof(tag)); + tag.segno = (uint32)(pageno / SLRU_PAGES_PER_SEGMENT); if (SlruSyncFileTag(ClusterRemoteXactCtl, &tag, path) != 0) ereport(ERROR, (errcode_for_file_access(), - errmsg("could not synchronize remote transaction segment \"%s\": %m", - path))); + errmsg("could not synchronize remote transaction segment \"%s\": %m", path))); fsync_fname(CLUSTER_REMOTE_XACT_DIR_V2, true); } static ClusterRemoteXactMutationV2 remote_xact_mutation_from_transition(ClusterRemoteXactEntryTransitionV2 transition) { - switch (transition) - { - case CLUSTER_REMOTE_XACT_ENTRY_WRITE: - return CLUSTER_REMOTE_XACT_MUTATION_STORED; - case CLUSTER_REMOTE_XACT_ENTRY_NOOP: - return CLUSTER_REMOTE_XACT_MUTATION_UNCHANGED; - case CLUSTER_REMOTE_XACT_ENTRY_CONFLICT: - return CLUSTER_REMOTE_XACT_MUTATION_CONFLICT; - case CLUSTER_REMOTE_XACT_ENTRY_INVALID: - default: - return CLUSTER_REMOTE_XACT_MUTATION_INVALID; + switch (transition) { + case CLUSTER_REMOTE_XACT_ENTRY_WRITE: + return CLUSTER_REMOTE_XACT_MUTATION_STORED; + case CLUSTER_REMOTE_XACT_ENTRY_NOOP: + return CLUSTER_REMOTE_XACT_MUTATION_UNCHANGED; + case CLUSTER_REMOTE_XACT_ENTRY_CONFLICT: + return CLUSTER_REMOTE_XACT_MUTATION_CONFLICT; + case CLUSTER_REMOTE_XACT_ENTRY_INVALID: + default: + return CLUSTER_REMOTE_XACT_MUTATION_INVALID; } } ClusterRemoteXactMutationV2 -cluster_remote_xact_store_prepared_v2( - int origin_node, TransactionId xid, - const uint8 digest[CLUSTER_REMOTE_XACT_PREPARE_DIGEST_BYTES]) +cluster_remote_xact_store_prepared_v2(int origin_node, TransactionId xid, + const uint8 digest[CLUSTER_REMOTE_XACT_PREPARE_DIGEST_BYTES]) { ClusterRemoteXactEntryV2 *entry; ClusterRemoteXactEntryV2 next; ClusterRemoteXactEntryTransitionV2 transition; - int pageno; - int slotno; + int pageno; + int slotno; - if (RemoteXactShared == NULL || origin_node < 0 || origin_node >= (1 << 7) || - !TransactionIdIsNormal(xid) || digest == NULL) + if (RemoteXactShared == NULL || origin_node < 0 || origin_node >= (1 << 7) + || !TransactionIdIsNormal(xid) || digest == NULL) return CLUSTER_REMOTE_XACT_MUTATION_INVALID; - Assert(!IsUnderPostmaster || - cluster_remote_xact_writer_allowed(AmStartupProcess(), - remote_xact_online_writer_depth_v)); + Assert(!IsUnderPostmaster + || cluster_remote_xact_writer_allowed(AmStartupProcess(), + remote_xact_online_writer_depth_v)); pageno = cluster_remote_xact_pageno(origin_node, xid); slotno = remote_xact_open_page(origin_node, xid, true); - entry = (ClusterRemoteXactEntryV2 *) - (ClusterRemoteXactCtl->shared->page_buffer[slotno] + - (Size) cluster_remote_xact_entryno(xid) * sizeof(*entry)); - transition = cluster_remote_xact_entry_prepare_transition_v2( - entry, digest, &next); - if (transition == CLUSTER_REMOTE_XACT_ENTRY_WRITE) - { + entry = (ClusterRemoteXactEntryV2 *)(ClusterRemoteXactCtl->shared->page_buffer[slotno] + + (Size)cluster_remote_xact_entryno(xid) * sizeof(*entry)); + transition = cluster_remote_xact_entry_prepare_transition_v2(entry, digest, &next); + if (transition == CLUSTER_REMOTE_XACT_ENTRY_WRITE) { *entry = next; ClusterRemoteXactCtl->shared->page_dirty[slotno] = true; } LWLockRelease(ClusterRemoteXactCtl->shared->ControlLock); - if (transition == CLUSTER_REMOTE_XACT_ENTRY_WRITE || - transition == CLUSTER_REMOTE_XACT_ENTRY_NOOP) + if (transition == CLUSTER_REMOTE_XACT_ENTRY_WRITE + || transition == CLUSTER_REMOTE_XACT_ENTRY_NOOP) remote_xact_force_durable(pageno); return remote_xact_mutation_from_transition(transition); } @@ -290,102 +284,92 @@ ClusterRemoteXactMutationV2 cluster_remote_xact_store_terminal_v2( int origin_node, TransactionId xid, bool require_prepared, const uint8 expected_prepare_digest[CLUSTER_REMOTE_XACT_PREPARE_DIGEST_BYTES], - ClusterRemoteXactOutcome outcome, SCN commit_scn, - TimestampTz commit_timestamp, bool wrap_valid, uint16 wrap) + ClusterRemoteXactOutcome outcome, SCN commit_scn, TimestampTz commit_timestamp, bool wrap_valid, + uint16 wrap) { ClusterRemoteXactEntryV2 *entry; ClusterRemoteXactEntryV2 candidate; ClusterRemoteXactEntryV2 next; ClusterRemoteXactEntryTransitionV2 transition; - int pageno; - int slotno; - - if (RemoteXactShared == NULL || origin_node < 0 || origin_node >= (1 << 7) || - !TransactionIdIsNormal(xid) || - (require_prepared && expected_prepare_digest == NULL) || - !cluster_remote_xact_entry_encode_terminal_v2(&candidate, outcome, - commit_scn, commit_timestamp, wrap_valid, wrap)) + int pageno; + int slotno; + + if (RemoteXactShared == NULL || origin_node < 0 || origin_node >= (1 << 7) + || !TransactionIdIsNormal(xid) || (require_prepared && expected_prepare_digest == NULL) + || !cluster_remote_xact_entry_encode_terminal_v2(&candidate, outcome, commit_scn, + commit_timestamp, wrap_valid, wrap)) return CLUSTER_REMOTE_XACT_MUTATION_INVALID; - Assert(!IsUnderPostmaster || - cluster_remote_xact_writer_allowed(AmStartupProcess(), - remote_xact_online_writer_depth_v)); + Assert(!IsUnderPostmaster + || cluster_remote_xact_writer_allowed(AmStartupProcess(), + remote_xact_online_writer_depth_v)); pageno = cluster_remote_xact_pageno(origin_node, xid); slotno = remote_xact_open_page(origin_node, xid, true); - entry = (ClusterRemoteXactEntryV2 *) - (ClusterRemoteXactCtl->shared->page_buffer[slotno] + - (Size) cluster_remote_xact_entryno(xid) * sizeof(*entry)); + entry = (ClusterRemoteXactEntryV2 *)(ClusterRemoteXactCtl->shared->page_buffer[slotno] + + (Size)cluster_remote_xact_entryno(xid) * sizeof(*entry)); transition = cluster_remote_xact_entry_terminal_transition_v2( - entry, require_prepared, expected_prepare_digest, outcome, commit_scn, - commit_timestamp, wrap_valid, wrap, &next); - if (transition == CLUSTER_REMOTE_XACT_ENTRY_WRITE) - { + entry, require_prepared, expected_prepare_digest, outcome, commit_scn, commit_timestamp, + wrap_valid, wrap, &next); + if (transition == CLUSTER_REMOTE_XACT_ENTRY_WRITE) { *entry = next; ClusterRemoteXactCtl->shared->page_dirty[slotno] = true; } LWLockRelease(ClusterRemoteXactCtl->shared->ControlLock); - if (transition == CLUSTER_REMOTE_XACT_ENTRY_WRITE || - transition == CLUSTER_REMOTE_XACT_ENTRY_NOOP) + if (transition == CLUSTER_REMOTE_XACT_ENTRY_WRITE + || transition == CLUSTER_REMOTE_XACT_ENTRY_NOOP) remote_xact_force_durable(pageno); return remote_xact_mutation_from_transition(transition); } bool -cluster_remote_xact_pending_matches_v2( - int origin_node, TransactionId xid, - const uint8 digest[CLUSTER_REMOTE_XACT_PREPARE_DIGEST_BYTES]) +cluster_remote_xact_pending_matches_v2(int origin_node, TransactionId xid, + const uint8 digest[CLUSTER_REMOTE_XACT_PREPARE_DIGEST_BYTES]) { const ClusterRemoteXactEntryV2 *entry; - bool matches; - int slotno; + bool matches; + int slotno; - if (RemoteXactShared == NULL || origin_node < 0 || origin_node >= (1 << 7) || - !TransactionIdIsNormal(xid) || digest == NULL) + if (RemoteXactShared == NULL || origin_node < 0 || origin_node >= (1 << 7) + || !TransactionIdIsNormal(xid) || digest == NULL) return false; slotno = remote_xact_open_page(origin_node, xid, false); - if (slotno < 0) - { + if (slotno < 0) { LWLockRelease(ClusterRemoteXactCtl->shared->ControlLock); return false; } - entry = (const ClusterRemoteXactEntryV2 *) - (ClusterRemoteXactCtl->shared->page_buffer[slotno] + - (Size) cluster_remote_xact_entryno(xid) * sizeof(*entry)); + entry = (const ClusterRemoteXactEntryV2 *)(ClusterRemoteXactCtl->shared->page_buffer[slotno] + + (Size)cluster_remote_xact_entryno(xid) + * sizeof(*entry)); matches = cluster_remote_xact_entry_pending_matches_v2(entry, digest); LWLockRelease(ClusterRemoteXactCtl->shared->ControlLock); return matches; } bool -cluster_remote_xact_range_empty_v2(int origin_node, TransactionId first_xid, - uint32 count) +cluster_remote_xact_range_empty_v2(int origin_node, TransactionId first_xid, uint32 count) { - uint64 cursor; - uint64 end; + uint64 cursor; + uint64 end; - if (RemoteXactShared == NULL || - !cluster_remote_xact_reset_range_valid_v2(origin_node, first_xid, count)) + if (RemoteXactShared == NULL + || !cluster_remote_xact_reset_range_valid_v2(origin_node, first_xid, count)) return false; cursor = first_xid; end = cursor + count; - while (cursor < end) - { - TransactionId xid = (TransactionId) cursor; - uint32 entryno = (uint32) cluster_remote_xact_entryno(xid); - uint32 page_count = (uint32) Min(end - cursor, - (uint64) CLUSTER_REMOTE_XACT_ENTRIES_PER_PAGE - entryno); + while (cursor < end) { + TransactionId xid = (TransactionId)cursor; + uint32 entryno = (uint32)cluster_remote_xact_entryno(xid); + uint32 page_count + = (uint32)Min(end - cursor, (uint64)CLUSTER_REMOTE_XACT_ENTRIES_PER_PAGE - entryno); int slotno = remote_xact_open_page(origin_node, xid, false); - if (slotno >= 0) - { - const ClusterRemoteXactEntryV2 *entries = - (const ClusterRemoteXactEntryV2 *) - ClusterRemoteXactCtl->shared->page_buffer[slotno]; + if (slotno >= 0) { + const ClusterRemoteXactEntryV2 *entries + = (const ClusterRemoteXactEntryV2 *) + ClusterRemoteXactCtl->shared->page_buffer[slotno]; uint32 i; for (i = 0; i < page_count; i++) - if (!cluster_remote_xact_entry_is_empty_v2( - &entries[entryno + i])) - { + if (!cluster_remote_xact_entry_is_empty_v2(&entries[entryno + i])) { LWLockRelease(ClusterRemoteXactCtl->shared->ControlLock); return false; } @@ -397,66 +381,56 @@ cluster_remote_xact_range_empty_v2(int origin_node, TransactionId first_xid, } bool -cluster_remote_xact_reset_range_v2(int origin_node, TransactionId first_xid, - uint32 count) +cluster_remote_xact_reset_range_v2(int origin_node, TransactionId first_xid, uint32 count) { - uint32 touched_segments[6]; - uint32 touched_count = 0; - uint64 cursor; - uint64 end; - bool changed = false; - - if (RemoteXactShared == NULL || - !cluster_remote_xact_reset_range_valid_v2(origin_node, first_xid, count)) + uint32 touched_segments[6]; + uint32 touched_count = 0; + uint64 cursor; + uint64 end; + bool changed = false; + + if (RemoteXactShared == NULL + || !cluster_remote_xact_reset_range_valid_v2(origin_node, first_xid, count)) return false; - Assert(!IsUnderPostmaster || - cluster_remote_xact_writer_allowed(AmStartupProcess(), - remote_xact_online_writer_depth_v)); + Assert(!IsUnderPostmaster + || cluster_remote_xact_writer_allowed(AmStartupProcess(), + remote_xact_online_writer_depth_v)); cursor = first_xid; end = cursor + count; - while (cursor < end) - { - TransactionId xid = (TransactionId) cursor; - uint32 entryno = (uint32) cluster_remote_xact_entryno(xid); - uint32 page_count = (uint32) Min(end - cursor, - (uint64) CLUSTER_REMOTE_XACT_ENTRIES_PER_PAGE - entryno); + while (cursor < end) { + TransactionId xid = (TransactionId)cursor; + uint32 entryno = (uint32)cluster_remote_xact_entryno(xid); + uint32 page_count + = (uint32)Min(end - cursor, (uint64)CLUSTER_REMOTE_XACT_ENTRIES_PER_PAGE - entryno); int pageno = cluster_remote_xact_pageno(origin_node, xid); int slotno = remote_xact_open_page(origin_node, xid, false); - if (slotno >= 0) - { - ClusterRemoteXactEntryV2 *entries = (ClusterRemoteXactEntryV2 *) - ClusterRemoteXactCtl->shared->page_buffer[slotno]; + if (slotno >= 0) { + ClusterRemoteXactEntryV2 *entries + = (ClusterRemoteXactEntryV2 *)ClusterRemoteXactCtl->shared->page_buffer[slotno]; uint32 i; bool page_changed = false; - for (i = 0; i < page_count; i++) - { + for (i = 0; i < page_count; i++) { ClusterRemoteXactEntryV2 next; - if (cluster_remote_xact_entry_reset_transition_v2( - &entries[entryno + i], &next) == - CLUSTER_REMOTE_XACT_ENTRY_WRITE) - { + if (cluster_remote_xact_entry_reset_transition_v2(&entries[entryno + i], &next) + == CLUSTER_REMOTE_XACT_ENTRY_WRITE) { entries[entryno + i] = next; page_changed = true; } } - if (page_changed) - { - uint32 segno = (uint32) (pageno / SLRU_PAGES_PER_SEGMENT); - uint32 i; + if (page_changed) { + uint32 segno = (uint32)(pageno / SLRU_PAGES_PER_SEGMENT); ClusterRemoteXactCtl->shared->page_dirty[slotno] = true; changed = true; for (i = 0; i < touched_count; i++) if (touched_segments[i] == segno) break; - if (i == touched_count) - { + if (i == touched_count) { Assert(touched_count < lengthof(touched_segments)); - if (touched_count >= lengthof(touched_segments)) - { + if (touched_count >= lengthof(touched_segments)) { LWLockRelease(ClusterRemoteXactCtl->shared->ControlLock); return false; } @@ -467,17 +441,15 @@ cluster_remote_xact_reset_range_v2(int origin_node, TransactionId first_xid, LWLockRelease(ClusterRemoteXactCtl->shared->ControlLock); cursor += page_count; } - if (changed) - { + if (changed) { uint32 i; SimpleLruWriteAll(ClusterRemoteXactCtl, true); - for (i = 0; i < touched_count; i++) - { + for (i = 0; i < touched_count; i++) { FileTag tag; char path[MAXPGPATH]; - MemSet(&tag, 0, sizeof(tag)); + memset(&tag, 0, sizeof(tag)); tag.segno = touched_segments[i]; if (SlruSyncFileTag(ClusterRemoteXactCtl, &tag, path) != 0) ereport(ERROR, @@ -490,27 +462,24 @@ cluster_remote_xact_reset_range_v2(int origin_node, TransactionId first_xid, return cluster_remote_xact_range_empty_v2(origin_node, first_xid, count); } -typedef struct RemoteXactTruncateContextV2 -{ - int64 origin_first_page; - int64 origin_end_page; - int64 cutoff_page; - bool ok; - bool deleted; +typedef struct RemoteXactTruncateContextV2 { + int64 origin_first_page; + int64 origin_end_page; + int64 cutoff_page; + bool ok; + bool deleted; } RemoteXactTruncateContextV2; static bool -remote_xact_truncate_origin_callback(SlruCtl ctl, char *filename, - int segpage, void *arg) +remote_xact_truncate_origin_callback(SlruCtl ctl, char *filename, int segpage, void *arg) { - RemoteXactTruncateContextV2 *context = - (RemoteXactTruncateContextV2 *) arg; + RemoteXactTruncateContextV2 *context = (RemoteXactTruncateContextV2 *)arg; int64 first = segpage; int64 last = first + SLRU_PAGES_PER_SEGMENT - 1; - (void) filename; - if (first < context->origin_first_page || - first >= context->origin_end_page || last >= context->cutoff_page) + (void)filename; + if (first < context->origin_first_page || first >= context->origin_end_page + || last >= context->cutoff_page) return false; SlruDeleteSegment(ctl, segpage / SLRU_PAGES_PER_SEGMENT); context->deleted = true; @@ -520,44 +489,40 @@ remote_xact_truncate_origin_callback(SlruCtl ctl, char *filename, } bool -cluster_remote_xact_truncate_before_v2(int origin_node, - TransactionId oldest_xid) +cluster_remote_xact_truncate_before_v2(int origin_node, TransactionId oldest_xid) { RemoteXactTruncateContextV2 context; - if (RemoteXactShared == NULL || origin_node < 0 || origin_node >= (1 << 7) || - !TransactionIdIsNormal(oldest_xid)) + if (RemoteXactShared == NULL || origin_node < 0 || origin_node >= (1 << 7) + || !TransactionIdIsNormal(oldest_xid)) return false; - Assert(!IsUnderPostmaster || - cluster_remote_xact_writer_allowed(AmStartupProcess(), - remote_xact_online_writer_depth_v)); + Assert(!IsUnderPostmaster + || cluster_remote_xact_writer_allowed(AmStartupProcess(), + remote_xact_online_writer_depth_v)); memset(&context, 0, sizeof(context)); context.origin_first_page = cluster_remote_xact_pageno(origin_node, 0); - context.origin_end_page = context.origin_first_page + - ((int64) 1 << CLUSTER_REMOTE_XACT_ORIGIN_PAGE_SHIFT); + context.origin_end_page + = context.origin_first_page + ((int64)1 << CLUSTER_REMOTE_XACT_ORIGIN_PAGE_SHIFT); context.cutoff_page = cluster_remote_xact_pageno(origin_node, oldest_xid); context.ok = true; - (void) SlruScanDirectory(ClusterRemoteXactCtl, - remote_xact_truncate_origin_callback, &context); + (void)SlruScanDirectory(ClusterRemoteXactCtl, remote_xact_truncate_origin_callback, &context); if (context.deleted) fsync_fname(CLUSTER_REMOTE_XACT_DIR_V2, true); return context.ok; } static void -cluster_remote_xact_require_mutation(ClusterRemoteXactMutationV2 result, - int blocked_elevel, int origin_node, - TransactionId xid, const char *operation) +cluster_remote_xact_require_mutation(ClusterRemoteXactMutationV2 result, int blocked_elevel, + int origin_node, TransactionId xid, const char *operation) { - if (result == CLUSTER_REMOTE_XACT_MUTATION_STORED || - result == CLUSTER_REMOTE_XACT_MUTATION_UNCHANGED) + if (result == CLUSTER_REMOTE_XACT_MUTATION_STORED + || result == CLUSTER_REMOTE_XACT_MUTATION_UNCHANGED) return; - ereport(blocked_elevel, - (errcode(ERRCODE_CLUSTER_MERGED_RECOVERY_BLOCKED), - errmsg("merged recovery: conflicting remote transaction %s " - "(origin node %d, xid %u)", - operation, origin_node, xid), - errdetail("durable transition result=%d", (int) result))); + ereport(blocked_elevel, (errcode(ERRCODE_CLUSTER_MERGED_RECOVERY_BLOCKED), + errmsg("merged recovery: conflicting remote transaction %s " + "(origin node %d, xid %u)", + operation, origin_node, xid), + errdetail("durable transition result=%d", (int)result))); } ClusterRemoteXactOutcome @@ -759,19 +724,17 @@ cluster_remote_commit_outcome_ex(int origin_node, TransactionId xid, SCN *commit pg_atomic_fetch_add_u64(&RemoteXactShared->outcome_indoubt_count, 1); return CLUSTER_REMOTE_XACT_INDOUBT; } - entry = (const ClusterRemoteXactEntryV2 *) - (ClusterRemoteXactCtl->shared->page_buffer[slotno] + - (Size) cluster_remote_xact_entryno(xid) * sizeof(*entry)); + entry = (const ClusterRemoteXactEntryV2 *)(ClusterRemoteXactCtl->shared->page_buffer[slotno] + + (Size)cluster_remote_xact_entryno(xid) + * sizeof(*entry)); stored = *entry; LWLockRelease(ClusterRemoteXactCtl->shared->ControlLock); - if (!cluster_remote_xact_entry_decode_terminal_v2(&stored, &decoded)) - { + if (!cluster_remote_xact_entry_decode_terminal_v2(&stored, &decoded)) { pg_atomic_fetch_add_u64(&RemoteXactShared->outcome_indoubt_count, 1); return CLUSTER_REMOTE_XACT_INDOUBT; } - if (decoded.outcome == CLUSTER_REMOTE_XACT_COMMITTED) - { + if (decoded.outcome == CLUSTER_REMOTE_XACT_COMMITTED) { if (commit_scn != NULL) *commit_scn = decoded.commit_scn; if (out_wrap != NULL) @@ -788,35 +751,32 @@ cluster_remote_commit_outcome_ex(int origin_node, TransactionId xid, SCN *commit } bool -cluster_remote_commit_timestamp(int origin_node, TransactionId xid, - TimestampTz *commit_timestamp) +cluster_remote_commit_timestamp(int origin_node, TransactionId xid, TimestampTz *commit_timestamp) { const ClusterRemoteXactEntryV2 *entry; ClusterRemoteXactEntryV2 stored; ClusterRemoteXactEntryDecodedV2 decoded; - int slotno; + int slotno; if (commit_timestamp != NULL) *commit_timestamp = 0; - if (RemoteXactShared == NULL || commit_timestamp == NULL || - origin_node < 0 || origin_node >= (1 << 7) || - !TransactionIdIsNormal(xid)) + if (RemoteXactShared == NULL || commit_timestamp == NULL || origin_node < 0 + || origin_node >= (1 << 7) || !TransactionIdIsNormal(xid)) return false; slotno = remote_xact_open_page(origin_node, xid, false); - if (slotno < 0) - { + if (slotno < 0) { LWLockRelease(ClusterRemoteXactCtl->shared->ControlLock); return false; } - entry = (const ClusterRemoteXactEntryV2 *) - (ClusterRemoteXactCtl->shared->page_buffer[slotno] + - (Size) cluster_remote_xact_entryno(xid) * sizeof(*entry)); + entry = (const ClusterRemoteXactEntryV2 *)(ClusterRemoteXactCtl->shared->page_buffer[slotno] + + (Size)cluster_remote_xact_entryno(xid) + * sizeof(*entry)); stored = *entry; LWLockRelease(ClusterRemoteXactCtl->shared->ControlLock); - if (!cluster_remote_xact_entry_decode_terminal_v2(&stored, &decoded) || - decoded.outcome != CLUSTER_REMOTE_XACT_COMMITTED) + if (!cluster_remote_xact_entry_decode_terminal_v2(&stored, &decoded) + || decoded.outcome != CLUSTER_REMOTE_XACT_COMMITTED) return false; - *commit_timestamp = (TimestampTz) decoded.commit_timestamp; + *commit_timestamp = (TimestampTz)decoded.commit_timestamp; return true; } @@ -1085,13 +1045,13 @@ cluster_remote_xact_apply(int origin_node, XLogReaderState *record, bool online) cluster_scn_recovery_replay_observe(parsed.scn); commit_wrap_valid = cluster_remote_xact_commit_wrap_proof( origin_node, xid, &parsed, blocked_elevel, false, &commit_wrap); - commit_timestamp = (parsed.xinfo & XACT_XINFO_HAS_ORIGIN) != 0 - ? parsed.origin_timestamp : parsed.xact_time; + commit_timestamp = (parsed.xinfo & XACT_XINFO_HAS_ORIGIN) != 0 ? parsed.origin_timestamp + : parsed.xact_time; mutation = cluster_remote_xact_store_terminal_v2( - origin_node, xid, false, NULL, CLUSTER_REMOTE_XACT_COMMITTED, - parsed.scn, commit_timestamp, commit_wrap_valid, commit_wrap); - cluster_remote_xact_require_mutation(mutation, blocked_elevel, - origin_node, xid, "commit projection"); + origin_node, xid, false, NULL, CLUSTER_REMOTE_XACT_COMMITTED, parsed.scn, + commit_timestamp, commit_wrap_valid, commit_wrap); + cluster_remote_xact_require_mutation(mutation, blocked_elevel, origin_node, xid, + "commit projection"); pg_atomic_fetch_add_u64(&RemoteXactShared->diverted_commit_count, 1); /* spec-6.14 D9: execute the record's side effects (outcome first, @@ -1151,25 +1111,25 @@ cluster_remote_xact_apply(int origin_node, XLogReaderState *record, bool online) origin_node, xid), errhint("spec-1.18 stamps every prepared commit record; a missing SCN " "means a pre-cluster WAL stream, which cannot be merged."))); - if (!cluster_remote_xact_prepare_digest_v2( - GetSystemIdentifier(), origin_node, xid, parsed.dbId, - parsed.twophase_gid, prepared_digest)) + if (!cluster_remote_xact_prepare_digest_v2(GetSystemIdentifier(), origin_node, xid, + parsed.dbId, parsed.twophase_gid, + prepared_digest)) ereport(blocked_elevel, (errcode(ERRCODE_CLUSTER_MERGED_RECOVERY_BLOCKED), errmsg("merged recovery: prepared commit lacks exact pending identity " - "(origin node %d, xid %u)", origin_node, xid))); + "(origin node %d, xid %u)", + origin_node, xid))); cluster_scn_recovery_replay_observe(parsed.scn); commit_wrap_valid = cluster_remote_xact_commit_wrap_proof( origin_node, xid, &parsed, blocked_elevel, true, &commit_wrap); - commit_timestamp = (parsed.xinfo & XACT_XINFO_HAS_ORIGIN) != 0 - ? parsed.origin_timestamp : parsed.xact_time; + commit_timestamp = (parsed.xinfo & XACT_XINFO_HAS_ORIGIN) != 0 ? parsed.origin_timestamp + : parsed.xact_time; mutation = cluster_remote_xact_store_terminal_v2( - origin_node, xid, true, prepared_digest, - CLUSTER_REMOTE_XACT_COMMITTED, parsed.scn, commit_timestamp, - commit_wrap_valid, commit_wrap); - cluster_remote_xact_require_mutation(mutation, blocked_elevel, - origin_node, xid, "prepared commit"); + origin_node, xid, true, prepared_digest, CLUSTER_REMOTE_XACT_COMMITTED, parsed.scn, + commit_timestamp, commit_wrap_valid, commit_wrap); + cluster_remote_xact_require_mutation(mutation, blocked_elevel, origin_node, xid, + "prepared commit"); pg_atomic_fetch_add_u64(&RemoteXactShared->diverted_commit_count, 1); /* spec-6.14 D9: see the plain-commit arm. */ @@ -1200,10 +1160,9 @@ cluster_remote_xact_apply(int origin_node, XLogReaderState *record, bool online) /* Mirror xact_redo_abort's Lamport observe (see the commit arm). */ cluster_scn_recovery_replay_observe(parsed.scn); mutation = cluster_remote_xact_store_terminal_v2( - origin_node, xid, false, NULL, CLUSTER_REMOTE_XACT_ABORTED, - InvalidScn, 0, false, 0); - cluster_remote_xact_require_mutation(mutation, blocked_elevel, - origin_node, xid, "abort projection"); + origin_node, xid, false, NULL, CLUSTER_REMOTE_XACT_ABORTED, InvalidScn, 0, false, 0); + cluster_remote_xact_require_mutation(mutation, blocked_elevel, origin_node, xid, + "abort projection"); pg_atomic_fetch_add_u64(&RemoteXactShared->diverted_abort_count, 1); /* spec-6.14 D9: an aborted xact's delete-on-abort relfiles (files it @@ -1240,20 +1199,21 @@ cluster_remote_xact_apply(int origin_node, XLogReaderState *record, bool online) "side effect (origin node %d, xid %u)", origin_node, xid), errhint("Recover with cluster.merged_recovery=off."))); - if (!cluster_remote_xact_prepare_digest_v2( - GetSystemIdentifier(), origin_node, xid, parsed.dbId, - parsed.twophase_gid, prepared_digest)) + if (!cluster_remote_xact_prepare_digest_v2(GetSystemIdentifier(), origin_node, xid, + parsed.dbId, parsed.twophase_gid, + prepared_digest)) ereport(blocked_elevel, (errcode(ERRCODE_CLUSTER_MERGED_RECOVERY_BLOCKED), errmsg("merged recovery: prepared abort lacks exact pending identity " - "(origin node %d, xid %u)", origin_node, xid))); + "(origin node %d, xid %u)", + origin_node, xid))); cluster_scn_recovery_replay_observe(parsed.scn); - mutation = cluster_remote_xact_store_terminal_v2( - origin_node, xid, true, prepared_digest, - CLUSTER_REMOTE_XACT_ABORTED, InvalidScn, 0, false, 0); - cluster_remote_xact_require_mutation(mutation, blocked_elevel, - origin_node, xid, "prepared abort"); + mutation = cluster_remote_xact_store_terminal_v2(origin_node, xid, true, prepared_digest, + CLUSTER_REMOTE_XACT_ABORTED, InvalidScn, 0, + false, 0); + cluster_remote_xact_require_mutation(mutation, blocked_elevel, origin_node, xid, + "prepared abort"); pg_atomic_fetch_add_u64(&RemoteXactShared->diverted_abort_count, 1); /* spec-6.14 D9: see the plain-abort arm. */ @@ -1293,17 +1253,17 @@ cluster_remote_xact_apply(int origin_node, XLogReaderState *record, bool online) "COMMIT PREPARED or ABORT PREPARED record is replayed."))); /* Never expose a peer xid through local pg_prepared_xacts. */ - if (!cluster_remote_xact_prepare_digest_v2( - GetSystemIdentifier(), origin_node, xid, parsed.dbId, - parsed.twophase_gid, prepared_digest)) + if (!cluster_remote_xact_prepare_digest_v2(GetSystemIdentifier(), origin_node, xid, + parsed.dbId, parsed.twophase_gid, + prepared_digest)) ereport(blocked_elevel, (errcode(ERRCODE_CLUSTER_MERGED_RECOVERY_BLOCKED), errmsg("merged recovery: foreign prepare lacks exact durable identity " - "(origin node %d, xid %u)", origin_node, xid))); - mutation = cluster_remote_xact_store_prepared_v2( - origin_node, xid, prepared_digest); - cluster_remote_xact_require_mutation(mutation, blocked_elevel, - origin_node, xid, "prepare pending state"); + "(origin node %d, xid %u)", + origin_node, xid))); + mutation = cluster_remote_xact_store_prepared_v2(origin_node, xid, prepared_digest); + cluster_remote_xact_require_mutation(mutation, blocked_elevel, origin_node, xid, + "prepare pending state"); break; } default: diff --git a/src/backend/cluster/cluster_remote_xact_identity.c b/src/backend/cluster/cluster_remote_xact_identity.c index a83e56c8e9c..a8ea39fbef9 100644 --- a/src/backend/cluster/cluster_remote_xact_identity.c +++ b/src/backend/cluster/cluster_remote_xact_identity.c @@ -15,51 +15,49 @@ #ifdef USE_PGRAC_CLUSTER bool -cluster_remote_xact_prepare_digest_v2( - uint64 system_identifier, int origin_node, TransactionId xid, - Oid database, const char *gid, - uint8 digest[CLUSTER_REMOTE_XACT_PREPARE_DIGEST_BYTES]) +cluster_remote_xact_prepare_digest_v2(uint64 system_identifier, int origin_node, TransactionId xid, + Oid database, const char *gid, + uint8 digest[CLUSTER_REMOTE_XACT_PREPARE_DIGEST_BYTES]) { static const uint8 domain[] = "PGRAC-RF-SIDE-PREPARE-V2"; - uint8 identity[20]; - uint8 sha256[PG_SHA256_DIGEST_LENGTH]; - size_t gid_len; + uint8 identity[20]; + uint8 sha256[PG_SHA256_DIGEST_LENGTH]; + size_t gid_len; pg_cryptohash_ctx *context; - bool ok; - int i; + bool ok; + int i; - if (system_identifier == 0 || origin_node < 0 || origin_node >= (1 << 7) || - !TransactionIdIsNormal(xid) || !OidIsValid(database) || - gid == NULL || digest == NULL) + if (system_identifier == 0 || origin_node < 0 || origin_node >= (1 << 7) + || !TransactionIdIsNormal(xid) || !OidIsValid(database) || gid == NULL || digest == NULL) return false; gid_len = strnlen(gid, GIDSIZE); if (gid_len == 0 || gid_len >= GIDSIZE) return false; - MemSet(identity, 0, sizeof(identity)); + memset(identity, 0, sizeof(identity)); for (i = 0; i < 8; i++) - identity[i] = (uint8) (system_identifier >> (56 - i * 8)); - identity[8] = (uint8) origin_node; + identity[i] = (uint8)(system_identifier >> (56 - i * 8)); + identity[8] = (uint8)origin_node; identity[9] = CLUSTER_REMOTE_XACT_ENTRY_FORMAT_V2; - identity[10] = (uint8) ((uint32) xid >> 24); - identity[11] = (uint8) ((uint32) xid >> 16); - identity[12] = (uint8) ((uint32) xid >> 8); - identity[13] = (uint8) xid; - identity[14] = (uint8) ((uint32) database >> 24); - identity[15] = (uint8) ((uint32) database >> 16); - identity[16] = (uint8) ((uint32) database >> 8); - identity[17] = (uint8) database; - identity[18] = (uint8) (gid_len >> 8); - identity[19] = (uint8) gid_len; + identity[10] = (uint8)((uint32)xid >> 24); + identity[11] = (uint8)((uint32)xid >> 16); + identity[12] = (uint8)((uint32)xid >> 8); + identity[13] = (uint8)xid; + identity[14] = (uint8)((uint32)database >> 24); + identity[15] = (uint8)((uint32)database >> 16); + identity[16] = (uint8)((uint32)database >> 8); + identity[17] = (uint8)database; + identity[18] = (uint8)(gid_len >> 8); + identity[19] = (uint8)gid_len; context = pg_cryptohash_create(PG_SHA256); if (context == NULL) return false; - ok = pg_cryptohash_init(context) >= 0 && - pg_cryptohash_update(context, domain, sizeof(domain) - 1) >= 0 && - pg_cryptohash_update(context, identity, sizeof(identity)) >= 0 && - pg_cryptohash_update(context, (const uint8 *) gid, gid_len) >= 0 && - pg_cryptohash_final(context, sha256, sizeof(sha256)) >= 0; + ok = pg_cryptohash_init(context) >= 0 + && pg_cryptohash_update(context, domain, sizeof(domain) - 1) >= 0 + && pg_cryptohash_update(context, identity, sizeof(identity)) >= 0 + && pg_cryptohash_update(context, (const uint8 *)gid, gid_len) >= 0 + && pg_cryptohash_final(context, sha256, sizeof(sha256)) >= 0; pg_cryptohash_free(context); if (ok) memcpy(digest, sha256, CLUSTER_REMOTE_XACT_PREPARE_DIGEST_BYTES); diff --git a/src/backend/cluster/cluster_replacement_episode.c b/src/backend/cluster/cluster_replacement_episode.c index 7427fb1c3a5..998865fc3e4 100644 --- a/src/backend/cluster/cluster_replacement_episode.c +++ b/src/backend/cluster/cluster_replacement_episode.c @@ -24,8 +24,7 @@ replacement_episode_phase_valid(uint8 phase) } static bool -replacement_episode_bitmap_empty( - const uint8 bitmap[CLUSTER_REPLACEMENT_EPISODE_BITMAP_BYTES]) +replacement_episode_bitmap_empty(const uint8 bitmap[CLUSTER_REPLACEMENT_EPISODE_BITMAP_BYTES]) { int i; @@ -37,8 +36,8 @@ replacement_episode_bitmap_empty( } static bool -replacement_episode_bitmap_has( - const uint8 bitmap[CLUSTER_REPLACEMENT_EPISODE_BITMAP_BYTES], int32 node_id) +replacement_episode_bitmap_has(const uint8 bitmap[CLUSTER_REPLACEMENT_EPISODE_BITMAP_BYTES], + int32 node_id) { return (bitmap[node_id / 8] & (uint8)(1u << (node_id % 8))) != 0; } @@ -58,7 +57,7 @@ replacement_episode_acks_bounded(const ClusterReplacementEpisode *episode) bool cluster_replacement_episode_is_empty(const ClusterReplacementEpisode *episode) { - static const ClusterReplacementEpisode empty_episode = {0}; + static const ClusterReplacementEpisode empty_episode = { 0 }; return episode != NULL && memcmp(episode, &empty_episode, sizeof(*episode)) == 0; } @@ -80,17 +79,15 @@ cluster_replacement_episode_is_valid(const ClusterReplacementEpisode *episode) || episode->fresh_incarnation <= episode->old_admitted_incarnation || episode->baseline_epoch == UINT64_MAX || episode->reserved_or_committed_epoch != episode->baseline_epoch + 1 - || episode->grammar_fingerprint - != CLUSTER_REPLACEMENT_EPISODE_GRAMMAR_FINGERPRINT) + || episode->grammar_fingerprint != CLUSTER_REPLACEMENT_EPISODE_GRAMMAR_FINGERPRINT) return false; if (!replacement_episode_node_valid(episode->target_node_id) || !replacement_episode_node_valid(episode->coordinator_node_id) || replacement_episode_bitmap_empty(episode->expected_survivors) - || replacement_episode_bitmap_has(episode->expected_survivors, - episode->target_node_id) + || replacement_episode_bitmap_has(episode->expected_survivors, episode->target_node_id) || !replacement_episode_bitmap_has(episode->expected_survivors, - episode->coordinator_node_id) + episode->coordinator_node_id) || !replacement_episode_acks_bounded(episode)) return false; diff --git a/src/backend/cluster/cluster_replacement_request.c b/src/backend/cluster/cluster_replacement_request.c index d38529fe1b9..917f3314e0b 100644 --- a/src/backend/cluster/cluster_replacement_request.c +++ b/src/backend/cluster/cluster_replacement_request.c @@ -98,30 +98,24 @@ rplm_crc32c(const uint8 bytes[CLUSTER_REPLACEMENT_MARKER_BYTES]) static bool -rplm_marker_valid(const ClusterReplacementRequestMarker *marker, - int32 expected_target_node) +rplm_marker_valid(const ClusterReplacementRequestMarker *marker, int32 expected_target_node) { - return marker != NULL - && marker->magic == CLUSTER_REPLACEMENT_MARKER_MAGIC + return marker != NULL && marker->magic == CLUSTER_REPLACEMENT_MARKER_MAGIC && marker->version == CLUSTER_REPLACEMENT_MARKER_VERSION - && marker->phase == CLUSTER_REPLACEMENT_MARKER_PHASE_REQUESTED - && marker->reserved0 == 0 && marker->reserved1 == 0 - && marker->reserved2 == 0 && marker->target_node_id >= 0 + && marker->phase == CLUSTER_REPLACEMENT_MARKER_PHASE_REQUESTED && marker->reserved0 == 0 + && marker->reserved1 == 0 && marker->reserved2 == 0 && marker->target_node_id >= 0 && marker->target_node_id < CLUSTER_MAX_NODES - && (expected_target_node < 0 - || marker->target_node_id == expected_target_node) + && (expected_target_node < 0 || marker->target_node_id == expected_target_node) && marker->old_admitted_incarnation != 0 && marker->fresh_incarnation > marker->old_admitted_incarnation && marker->request_nonce != 0 - && marker->grammar_fingerprint - == CLUSTER_REPLACEMENT_EPISODE_GRAMMAR_FINGERPRINT; + && marker->grammar_fingerprint == CLUSTER_REPLACEMENT_EPISODE_GRAMMAR_FINGERPRINT; } bool -cluster_replacement_request_encode( - const ClusterReplacementRequestMarker *marker, - uint8 out[CLUSTER_REPLACEMENT_MARKER_BYTES]) +cluster_replacement_request_encode(const ClusterReplacementRequestMarker *marker, + uint8 out[CLUSTER_REPLACEMENT_MARKER_BYTES]) { uint8 image[CLUSTER_REPLACEMENT_MARKER_BYTES]; @@ -133,13 +127,10 @@ cluster_replacement_request_encode( image[RPLM_OFF_PHASE] = marker->phase; rplm_put_le32(image + RPLM_OFF_TARGET, (uint32)marker->target_node_id); rplm_put_le64(image + RPLM_OFF_BASELINE_EPOCH, marker->baseline_epoch); - rplm_put_le64(image + RPLM_OFF_OLD_INCARNATION, - marker->old_admitted_incarnation); - rplm_put_le64(image + RPLM_OFF_FRESH_INCARNATION, - marker->fresh_incarnation); + rplm_put_le64(image + RPLM_OFF_OLD_INCARNATION, marker->old_admitted_incarnation); + rplm_put_le64(image + RPLM_OFF_FRESH_INCARNATION, marker->fresh_incarnation); rplm_put_le64(image + RPLM_OFF_REQUEST_NONCE, marker->request_nonce); - rplm_put_le64(image + RPLM_OFF_GRAMMAR_FINGERPRINT, - marker->grammar_fingerprint); + rplm_put_le64(image + RPLM_OFF_GRAMMAR_FINGERPRINT, marker->grammar_fingerprint); rplm_put_le32(image + RPLM_OFF_CRC32C, rplm_crc32c(image)); memcpy(out, image, sizeof(image)); return true; @@ -147,15 +138,13 @@ cluster_replacement_request_encode( bool -cluster_replacement_request_decode( - const uint8 bytes[CLUSTER_REPLACEMENT_MARKER_BYTES], - int32 expected_target_node, ClusterReplacementRequestMarker *out) +cluster_replacement_request_decode(const uint8 bytes[CLUSTER_REPLACEMENT_MARKER_BYTES], + int32 expected_target_node, ClusterReplacementRequestMarker *out) { ClusterReplacementRequestMarker decoded; if (bytes == NULL || out == NULL || expected_target_node < 0 - || expected_target_node >= CLUSTER_MAX_NODES - || bytes[RPLM_OFF_RESERVED0] != 0 + || expected_target_node >= CLUSTER_MAX_NODES || bytes[RPLM_OFF_RESERVED0] != 0 || rplm_get_le32(bytes + RPLM_OFF_RESERVED1) != 0 || rplm_get_le32(bytes + RPLM_OFF_RESERVED2) != 0 || rplm_get_le32(bytes + RPLM_OFF_CRC32C) != rplm_crc32c(bytes)) @@ -167,13 +156,10 @@ cluster_replacement_request_decode( decoded.phase = bytes[RPLM_OFF_PHASE]; decoded.target_node_id = (int32)rplm_get_le32(bytes + RPLM_OFF_TARGET); decoded.baseline_epoch = rplm_get_le64(bytes + RPLM_OFF_BASELINE_EPOCH); - decoded.old_admitted_incarnation - = rplm_get_le64(bytes + RPLM_OFF_OLD_INCARNATION); - decoded.fresh_incarnation - = rplm_get_le64(bytes + RPLM_OFF_FRESH_INCARNATION); + decoded.old_admitted_incarnation = rplm_get_le64(bytes + RPLM_OFF_OLD_INCARNATION); + decoded.fresh_incarnation = rplm_get_le64(bytes + RPLM_OFF_FRESH_INCARNATION); decoded.request_nonce = rplm_get_le64(bytes + RPLM_OFF_REQUEST_NONCE); - decoded.grammar_fingerprint - = rplm_get_le64(bytes + RPLM_OFF_GRAMMAR_FINGERPRINT); + decoded.grammar_fingerprint = rplm_get_le64(bytes + RPLM_OFF_GRAMMAR_FINGERPRINT); decoded.crc32c = rplm_get_le32(bytes + RPLM_OFF_CRC32C); if (!rplm_marker_valid(&decoded, expected_target_node)) return false; @@ -183,35 +169,31 @@ cluster_replacement_request_decode( bool -cluster_replacement_request_pack( - uint8 reserved1[CLUSTER_REPLACEMENT_REQUEST_RESERVED1_BYTES], - const ClusterReplacementRequestMarker *marker) +cluster_replacement_request_pack(uint8 reserved1[CLUSTER_REPLACEMENT_REQUEST_RESERVED1_BYTES], + const ClusterReplacementRequestMarker *marker) { uint8 image[CLUSTER_REPLACEMENT_MARKER_BYTES]; if (reserved1 == NULL || !cluster_replacement_request_encode(marker, image)) return false; - memcpy(reserved1 + CLUSTER_REPLACEMENT_MARKER_RESERVED1_OFFSET, - image, sizeof(image)); + memcpy(reserved1 + CLUSTER_REPLACEMENT_MARKER_RESERVED1_OFFSET, image, sizeof(image)); return true; } bool cluster_replacement_request_unpack( - const uint8 reserved1[CLUSTER_REPLACEMENT_REQUEST_RESERVED1_BYTES], - int32 expected_target_node, ClusterReplacementRequestMarker *out) + const uint8 reserved1[CLUSTER_REPLACEMENT_REQUEST_RESERVED1_BYTES], int32 expected_target_node, + ClusterReplacementRequestMarker *out) { return reserved1 != NULL && cluster_replacement_request_decode( - reserved1 + CLUSTER_REPLACEMENT_MARKER_RESERVED1_OFFSET, - expected_target_node, out); + reserved1 + CLUSTER_REPLACEMENT_MARKER_RESERVED1_OFFSET, expected_target_node, out); } void -cluster_replacement_request_clear( - uint8 reserved1[CLUSTER_REPLACEMENT_REQUEST_RESERVED1_BYTES]) +cluster_replacement_request_clear(uint8 reserved1[CLUSTER_REPLACEMENT_REQUEST_RESERVED1_BYTES]) { if (reserved1 != NULL) memset(reserved1 + CLUSTER_REPLACEMENT_MARKER_RESERVED1_OFFSET, 0, @@ -237,14 +219,12 @@ cluster_replacement_request_is_clear( ClusterReplacementRequestSlotState cluster_replacement_request_slot_state( - uint64 flags, - const uint8 reserved1[CLUSTER_REPLACEMENT_REQUEST_RESERVED1_BYTES], + uint64 flags, const uint8 reserved1[CLUSTER_REPLACEMENT_REQUEST_RESERVED1_BYTES], int32 expected_target_node, uint64 expected_slot_incarnation, ClusterReplacementRequestMarker *out) { ClusterReplacementRequestMarker decoded; - bool requested - = (flags & CLUSTER_VOTING_SLOT_FLAG_REPLACEMENT_REQUESTED) != 0; + bool requested = (flags & CLUSTER_VOTING_SLOT_FLAG_REPLACEMENT_REQUESTED) != 0; if (reserved1 == NULL || expected_slot_incarnation == 0) return CLUSTER_REPLACEMENT_REQUEST_SLOT_HOLD; @@ -252,8 +232,7 @@ cluster_replacement_request_slot_state( return cluster_replacement_request_is_clear(reserved1) ? CLUSTER_REPLACEMENT_REQUEST_SLOT_CLEAR : CLUSTER_REPLACEMENT_REQUEST_SLOT_HOLD; - if (!cluster_replacement_request_unpack( - reserved1, expected_target_node, &decoded) + if (!cluster_replacement_request_unpack(reserved1, expected_target_node, &decoded) || decoded.fresh_incarnation != expected_slot_incarnation) return CLUSTER_REPLACEMENT_REQUEST_SLOT_HOLD; if (out != NULL) @@ -264,10 +243,8 @@ cluster_replacement_request_slot_state( ClusterReplacementRequestSlotState cluster_replacement_request_preserve_per_disk( - uint64 prior_flags, - const uint8 prior_reserved1[CLUSTER_REPLACEMENT_REQUEST_RESERVED1_BYTES], - int32 expected_target_node, uint64 expected_slot_incarnation, - uint64 *new_flags, + uint64 prior_flags, const uint8 prior_reserved1[CLUSTER_REPLACEMENT_REQUEST_RESERVED1_BYTES], + int32 expected_target_node, uint64 expected_slot_incarnation, uint64 *new_flags, uint8 new_reserved1[CLUSTER_REPLACEMENT_REQUEST_RESERVED1_BYTES]) { ClusterReplacementRequestSlotState state; @@ -275,8 +252,7 @@ cluster_replacement_request_preserve_per_disk( if (new_flags == NULL || new_reserved1 == NULL) return CLUSTER_REPLACEMENT_REQUEST_SLOT_HOLD; state = cluster_replacement_request_slot_state( - prior_flags, prior_reserved1, expected_target_node, - expected_slot_incarnation, NULL); + prior_flags, prior_reserved1, expected_target_node, expected_slot_incarnation, NULL); if (state != CLUSTER_REPLACEMENT_REQUEST_SLOT_VALID) return state; diff --git a/src/backend/cluster/cluster_replacement_wire.c b/src/backend/cluster/cluster_replacement_wire.c index 2318db12638..84f5df5e5cc 100644 --- a/src/backend/cluster/cluster_replacement_wire.c +++ b/src/backend/cluster/cluster_replacement_wire.c @@ -82,11 +82,9 @@ replacement_wire_message_valid(const ClusterReplacementWireMessage *message) { if (message == NULL || !replacement_wire_phase_valid(message->phase)) return false; - if (message->grammar_fingerprint - != CANDIDATE2_CORRECTED_A1_GRAMMAR_FINGERPRINT) + if (message->grammar_fingerprint != CANDIDATE2_CORRECTED_A1_GRAMMAR_FINGERPRINT) return false; - if (message->phase - == CLUSTER_REPLACEMENT_WIRE_PHASE_TARGET_RECOVERY_READY) + if (message->phase == CLUSTER_REPLACEMENT_WIRE_PHASE_TARGET_RECOVERY_READY) return message->body.phase3.jcmk_generation != 0 && message->body.phase3.episode_state_generation != 0 && message->body.phase3.reserved == 0; @@ -104,32 +102,25 @@ cluster_replacement_wire_encode(const ClusterReplacementWireMessage *message, return false; memset(image, 0, sizeof(image)); replacement_wire_put_le32(image + REPLACEMENT_WIRE_OFF_OPCODE, - GES_REQ_OPCODE_REPLACEMENT_EPISODE); - replacement_wire_put_le32(image + REPLACEMENT_WIRE_OFF_PHASE, - message->phase); - replacement_wire_put_le32(image + REPLACEMENT_WIRE_OFF_TARGET, - (uint32)message->target_node_id); + GES_REQ_OPCODE_REPLACEMENT_EPISODE); + replacement_wire_put_le32(image + REPLACEMENT_WIRE_OFF_PHASE, message->phase); + replacement_wire_put_le32(image + REPLACEMENT_WIRE_OFF_TARGET, (uint32)message->target_node_id); replacement_wire_put_le32(image + REPLACEMENT_WIRE_OFF_VERSION, - CLUSTER_REPLACEMENT_WIRE_VERSION); - replacement_wire_put_le64(image + REPLACEMENT_WIRE_OFF_EPOCH, - message->epoch); - replacement_wire_put_le64(image + REPLACEMENT_WIRE_OFF_NONCE, - message->request_nonce); - replacement_wire_put_le64(image + REPLACEMENT_WIRE_OFF_IDENTITY0, - message->identity0); - replacement_wire_put_le64(image + REPLACEMENT_WIRE_OFF_IDENTITY1, - message->identity1); - if (message->phase - == CLUSTER_REPLACEMENT_WIRE_PHASE_TARGET_RECOVERY_READY) { + CLUSTER_REPLACEMENT_WIRE_VERSION); + replacement_wire_put_le64(image + REPLACEMENT_WIRE_OFF_EPOCH, message->epoch); + replacement_wire_put_le64(image + REPLACEMENT_WIRE_OFF_NONCE, message->request_nonce); + replacement_wire_put_le64(image + REPLACEMENT_WIRE_OFF_IDENTITY0, message->identity0); + replacement_wire_put_le64(image + REPLACEMENT_WIRE_OFF_IDENTITY1, message->identity1); + if (message->phase == CLUSTER_REPLACEMENT_WIRE_PHASE_TARGET_RECOVERY_READY) { replacement_wire_put_le64(image + REPLACEMENT_WIRE_OFF_BODY, - message->body.phase3.jcmk_generation); + message->body.phase3.jcmk_generation); replacement_wire_put_le32(image + REPLACEMENT_WIRE_OFF_BODY + 8, - message->body.phase3.episode_state_generation); + message->body.phase3.episode_state_generation); } else memcpy(image + REPLACEMENT_WIRE_OFF_BODY, message->body.bitmap, CLUSTER_REPLACEMENT_WIRE_BITMAP_BYTES); replacement_wire_put_le64(image + REPLACEMENT_WIRE_OFF_FINGERPRINT, - message->grammar_fingerprint); + message->grammar_fingerprint); memcpy(out, image, sizeof(image)); return true; } @@ -142,25 +133,20 @@ cluster_replacement_wire_encode(const ClusterReplacementWireMessage *message, * leaves the caller's output untouched on every refusal. */ bool -cluster_replacement_wire_encode_phase3_snapshot( - const ClusterR4PrerequisiteSnapshot *snapshot, - uint8 out[CLUSTER_REPLACEMENT_WIRE_BYTES]) +cluster_replacement_wire_encode_phase3_snapshot(const ClusterR4PrerequisiteSnapshot *snapshot, + uint8 out[CLUSTER_REPLACEMENT_WIRE_BYTES]) { ClusterReplacementWireMessage message; uint8 image[CLUSTER_REPLACEMENT_WIRE_BYTES]; - if (snapshot == NULL || out == NULL - || snapshot->status != CLUSTER_R4_PREREQUISITE_R4A_READY - || !snapshot->ready - || snapshot->reserved0[0] != 0 || snapshot->reserved0[1] != 0 + if (snapshot == NULL || out == NULL || snapshot->status != CLUSTER_R4_PREREQUISITE_R4A_READY + || !snapshot->ready || snapshot->reserved0[0] != 0 || snapshot->reserved0[1] != 0 || snapshot->reserved0[2] != 0 || snapshot->target_node_id < 0 - || snapshot->episode_state_generation == 0 - || snapshot->jcmk_generation == 0 || snapshot->request_nonce == 0 - || snapshot->old_admitted_incarnation == 0 + || snapshot->episode_state_generation == 0 || snapshot->jcmk_generation == 0 + || snapshot->request_nonce == 0 || snapshot->old_admitted_incarnation == 0 || snapshot->fresh_incarnation <= snapshot->old_admitted_incarnation || snapshot->committed_epoch == 0 - || snapshot->grammar_fingerprint - != CANDIDATE2_CORRECTED_A1_GRAMMAR_FINGERPRINT) + || snapshot->grammar_fingerprint != CANDIDATE2_CORRECTED_A1_GRAMMAR_FINGERPRINT) return false; memset(&message, 0, sizeof(message)); @@ -171,8 +157,7 @@ cluster_replacement_wire_encode_phase3_snapshot( message.identity0 = snapshot->old_admitted_incarnation; message.identity1 = snapshot->fresh_incarnation; message.body.phase3.jcmk_generation = snapshot->jcmk_generation; - message.body.phase3.episode_state_generation - = snapshot->episode_state_generation; + message.body.phase3.episode_state_generation = snapshot->episode_state_generation; message.grammar_fingerprint = snapshot->grammar_fingerprint; if (!cluster_replacement_wire_encode(&message, image)) return false; @@ -182,9 +167,8 @@ cluster_replacement_wire_encode_phase3_snapshot( bool -cluster_replacement_wire_decode( - const uint8 bytes[CLUSTER_REPLACEMENT_WIRE_BYTES], - ClusterReplacementWireMessage *out) +cluster_replacement_wire_decode(const uint8 bytes[CLUSTER_REPLACEMENT_WIRE_BYTES], + ClusterReplacementWireMessage *out) { ClusterReplacementWireMessage decoded; uint32 phase; @@ -199,21 +183,16 @@ cluster_replacement_wire_decode( if (!replacement_wire_phase_valid(phase)) return false; if (phase == CLUSTER_REPLACEMENT_WIRE_PHASE_TARGET_RECOVERY_READY - && replacement_wire_get_le32(bytes + REPLACEMENT_WIRE_OFF_BODY + 12) - != 0) + && replacement_wire_get_le32(bytes + REPLACEMENT_WIRE_OFF_BODY + 12) != 0) return false; memset(&decoded, 0, sizeof(decoded)); decoded.phase = phase; - decoded.target_node_id - = (int32)replacement_wire_get_le32(bytes + REPLACEMENT_WIRE_OFF_TARGET); + decoded.target_node_id = (int32)replacement_wire_get_le32(bytes + REPLACEMENT_WIRE_OFF_TARGET); decoded.epoch = replacement_wire_get_le64(bytes + REPLACEMENT_WIRE_OFF_EPOCH); - decoded.request_nonce - = replacement_wire_get_le64(bytes + REPLACEMENT_WIRE_OFF_NONCE); - decoded.identity0 - = replacement_wire_get_le64(bytes + REPLACEMENT_WIRE_OFF_IDENTITY0); - decoded.identity1 - = replacement_wire_get_le64(bytes + REPLACEMENT_WIRE_OFF_IDENTITY1); + decoded.request_nonce = replacement_wire_get_le64(bytes + REPLACEMENT_WIRE_OFF_NONCE); + decoded.identity0 = replacement_wire_get_le64(bytes + REPLACEMENT_WIRE_OFF_IDENTITY0); + decoded.identity1 = replacement_wire_get_le64(bytes + REPLACEMENT_WIRE_OFF_IDENTITY1); if (phase == CLUSTER_REPLACEMENT_WIRE_PHASE_TARGET_RECOVERY_READY) { decoded.body.phase3.jcmk_generation = replacement_wire_get_le64(bytes + REPLACEMENT_WIRE_OFF_BODY); @@ -240,8 +219,7 @@ cluster_replacement_phase3_handoff_init(ClusterReplacementPhase3Handoff *handoff uint32 -cluster_replacement_phase3_handoff_pending( - const ClusterReplacementPhase3Handoff *handoff) +cluster_replacement_phase3_handoff_pending(const ClusterReplacementPhase3Handoff *handoff) { uint64 pending; @@ -255,9 +233,8 @@ cluster_replacement_phase3_handoff_pending( bool -cluster_replacement_phase3_handoff_poll( - ClusterReplacementPhase3Handoff *handoff, - ClusterReplacementPhase3HandoffItem *out) +cluster_replacement_phase3_handoff_poll(ClusterReplacementPhase3Handoff *handoff, + ClusterReplacementPhase3HandoffItem *out) { uint64 pending; @@ -266,19 +243,18 @@ cluster_replacement_phase3_handoff_poll( pending = handoff->producer_seq - handoff->consumer_seq; if (pending == 0 || pending > CLUSTER_REPLACEMENT_PHASE3_HANDOFF_CAPACITY) return false; - *out = handoff->items[handoff->consumer_seq - % CLUSTER_REPLACEMENT_PHASE3_HANDOFF_CAPACITY]; + *out = handoff->items[handoff->consumer_seq % CLUSTER_REPLACEMENT_PHASE3_HANDOFF_CAPACITY]; handoff->consumer_seq++; return true; } ClusterReplacementPhase3IngressResult -cluster_replacement_wire_phase3_ingress( - ClusterReplacementPhase3Handoff *handoff, const ClusterICEnvelope *env, - const void *payload, uint32 payload_length, int32 authenticated_source_node_id, - int32 local_receiver_node_id, uint64 current_epoch, - uint32 control_connection_generation) +cluster_replacement_wire_phase3_ingress(ClusterReplacementPhase3Handoff *handoff, + const ClusterICEnvelope *env, const void *payload, + uint32 payload_length, int32 authenticated_source_node_id, + int32 local_receiver_node_id, uint64 current_epoch, + uint32 control_connection_generation) { ClusterReplacementWireMessage message; ClusterReplacementPhase3HandoffItem item; @@ -287,20 +263,17 @@ cluster_replacement_wire_phase3_ingress( if (handoff == NULL || env == NULL || payload == NULL || payload_length != CLUSTER_REPLACEMENT_WIRE_BYTES || env->msg_type != PGRAC_IC_MSG_GES_REQUEST - || env->payload_length != CLUSTER_REPLACEMENT_WIRE_BYTES - || authenticated_source_node_id < 0 || local_receiver_node_id < 0 - || authenticated_source_node_id == local_receiver_node_id + || env->payload_length != CLUSTER_REPLACEMENT_WIRE_BYTES || authenticated_source_node_id < 0 + || local_receiver_node_id < 0 || authenticated_source_node_id == local_receiver_node_id || env->source_node_id != (uint32)authenticated_source_node_id - || env->dest_node_id != (uint32)local_receiver_node_id - || env->epoch != current_epoch || control_connection_generation == 0) + || env->dest_node_id != (uint32)local_receiver_node_id || env->epoch != current_epoch + || control_connection_generation == 0) return CLUSTER_REPLACEMENT_PHASE3_INGRESS_REJECTED; if (!cluster_replacement_wire_decode((const uint8 *)payload, &message) - || message.phase - != CLUSTER_REPLACEMENT_WIRE_PHASE_TARGET_RECOVERY_READY - || message.target_node_id != authenticated_source_node_id - || message.epoch == UINT64_MAX || message.epoch + 1 != current_epoch - || message.request_nonce == 0 + || message.phase != CLUSTER_REPLACEMENT_WIRE_PHASE_TARGET_RECOVERY_READY + || message.target_node_id != authenticated_source_node_id || message.epoch == UINT64_MAX + || message.epoch + 1 != current_epoch || message.request_nonce == 0 || message.identity0 == 0 || message.identity1 <= message.identity0) return CLUSTER_REPLACEMENT_PHASE3_INGRESS_REJECTED; @@ -316,40 +289,37 @@ cluster_replacement_wire_phase3_ingress( item.authenticated_source_node_id = authenticated_source_node_id; item.local_receiver_node_id = local_receiver_node_id; item.control_connection_generation = control_connection_generation; - handoff->items[handoff->producer_seq - % CLUSTER_REPLACEMENT_PHASE3_HANDOFF_CAPACITY] = item; + handoff->items[handoff->producer_seq % CLUSTER_REPLACEMENT_PHASE3_HANDOFF_CAPACITY] = item; handoff->producer_seq++; return CLUSTER_REPLACEMENT_PHASE3_INGRESS_ENQUEUED; } ClusterReplacementPhase3IngressResult -cluster_replacement_wire_phase3_ingress_local( - const ClusterICEnvelope *env, const void *payload, uint32 payload_length, - int32 authenticated_source_node_id, int32 local_receiver_node_id, - uint64 current_epoch, uint32 control_connection_generation) +cluster_replacement_wire_phase3_ingress_local(const ClusterICEnvelope *env, const void *payload, + uint32 payload_length, + int32 authenticated_source_node_id, + int32 local_receiver_node_id, uint64 current_epoch, + uint32 control_connection_generation) { - return cluster_replacement_wire_phase3_ingress( - &replacement_phase3_local_handoff, env, payload, payload_length, - authenticated_source_node_id, local_receiver_node_id, current_epoch, - control_connection_generation); + return cluster_replacement_wire_phase3_ingress(&replacement_phase3_local_handoff, env, payload, + payload_length, authenticated_source_node_id, + local_receiver_node_id, current_epoch, + control_connection_generation); } bool -cluster_replacement_phase3_handoff_poll_local( - ClusterReplacementPhase3HandoffItem *out) +cluster_replacement_phase3_handoff_poll_local(ClusterReplacementPhase3HandoffItem *out) { - return cluster_replacement_phase3_handoff_poll( - &replacement_phase3_local_handoff, out); + return cluster_replacement_phase3_handoff_poll(&replacement_phase3_local_handoff, out); } uint32 cluster_replacement_phase3_handoff_pending_local(void) { - return cluster_replacement_phase3_handoff_pending( - &replacement_phase3_local_handoff); + return cluster_replacement_phase3_handoff_pending(&replacement_phase3_local_handoff); } uint64 diff --git a/src/backend/cluster/cluster_resource_x_identity.c b/src/backend/cluster/cluster_resource_x_identity.c index 0b8f4f7fac6..3a2fa7d0b2a 100644 --- a/src/backend/cluster/cluster_resource_x_identity.c +++ b/src/backend/cluster/cluster_resource_x_identity.c @@ -17,8 +17,7 @@ resource_x_hash_scalar(uint64 hash, uint64 value) { int i; - for (i = 0; i < 8; i++) - { + for (i = 0; i < 8; i++) { hash ^= (uint8)(value & UINT64CONST(0xff)); hash *= RESOURCE_X_HASH_PRIME; value >>= 8; @@ -33,16 +32,14 @@ resource_x_assertion_valid(const ResourceXAssertion *assertion) return false; if (!RelFileNumberIsValid(assertion->resource.relNumber) || assertion->resource.blockNum == InvalidBlockNumber - || assertion->resource.forkNum < MAIN_FORKNUM - || assertion->resource.forkNum > MAX_FORKNUM) + || assertion->resource.forkNum < MAIN_FORKNUM || assertion->resource.forkNum > MAX_FORKNUM) return false; return assertion->requester_node >= 0 - && assertion->requester_node < RESOURCE_X_PROTOCOL_NODE_LIMIT; + && assertion->requester_node < RESOURCE_X_PROTOCOL_NODE_LIMIT; } bool -resource_x_assertion_init(const BufferTag *tag, int32 requester_node, - ResourceXAssertion *out) +resource_x_assertion_init(const BufferTag *tag, int32 requester_node, ResourceXAssertion *out) { ResourceXAssertion candidate; @@ -57,13 +54,11 @@ resource_x_assertion_init(const BufferTag *tag, int32 requester_node, } bool -resource_x_assertion_equal(const ResourceXAssertion *left, - const ResourceXAssertion *right) +resource_x_assertion_equal(const ResourceXAssertion *left, const ResourceXAssertion *right) { - return resource_x_assertion_valid(left) - && resource_x_assertion_valid(right) - && BufferTagsEqual(&left->resource, &right->resource) - && left->requester_node == right->requester_node; + return resource_x_assertion_valid(left) && resource_x_assertion_valid(right) + && BufferTagsEqual(&left->resource, &right->resource) + && left->requester_node == right->requester_node; } uint32 @@ -83,8 +78,7 @@ resource_x_assertion_hash(const ResourceXAssertion *assertion) } bool -resource_x_attempt_init(const ResourceXAssertion *assertion, - uint64 base_authority_generation, +resource_x_attempt_init(const ResourceXAssertion *assertion, uint64 base_authority_generation, ResourceXAttemptWitness *out) { ResourceXAttemptWitness candidate; @@ -102,8 +96,8 @@ resource_x_attempt_matches(const ResourceXAttemptWitness *left, const ResourceXAttemptWitness *right) { return left != NULL && right != NULL - && resource_x_assertion_equal(&left->assertion, &right->assertion) - && left->base_authority_generation == right->base_authority_generation; + && resource_x_assertion_equal(&left->assertion, &right->assertion) + && left->base_authority_generation == right->base_authority_generation; } const char * diff --git a/src/backend/cluster/cluster_resource_x_node_wire.c b/src/backend/cluster/cluster_resource_x_node_wire.c index 1b9c82fec20..2bd664659f6 100644 --- a/src/backend/cluster/cluster_resource_x_node_wire.c +++ b/src/backend/cluster/cluster_resource_x_node_wire.c @@ -57,8 +57,7 @@ resource_x_get_u16(const uint8 *in) static uint32 resource_x_get_u32(const uint8 *in) { - return ((uint32)in[0] << 24) | ((uint32)in[1] << 16) - | ((uint32)in[2] << 8) | (uint32)in[3]; + return ((uint32)in[0] << 24) | ((uint32)in[1] << 16) | ((uint32)in[2] << 8) | (uint32)in[3]; } @@ -89,7 +88,7 @@ resource_x_bytes_zero(const uint8 *bytes, Size len) static uint32 resource_x_wire_crc(const uint8 *bytes, uint16 len) { - static const uint8 zero_crc[4] = {0, 0, 0, 0}; + static const uint8 zero_crc[4] = { 0, 0, 0, 0 }; pg_crc32c crc; INIT_CRC32C(crc); @@ -131,40 +130,30 @@ static bool resource_x_pair_length(uint8 msg_type, ResourceXWireKind kind, uint16 len) { if (kind == RESOURCE_X_WIRE_PREASSERT_BOOTSTRAP) - return (msg_type == RESOURCE_X_MSG_ASSERT_X - || msg_type == RESOURCE_X_MSG_IMAGE_OR_GRANT) - && len == RESOURCE_X_CONTROL_V1_BYTES; + return (msg_type == RESOURCE_X_MSG_ASSERT_X || msg_type == RESOURCE_X_MSG_IMAGE_OR_GRANT) + && len == RESOURCE_X_CONTROL_V1_BYTES; if (kind == RESOURCE_X_WIRE_ASSERT_X) - return msg_type == RESOURCE_X_MSG_ASSERT_X - && len == RESOURCE_X_CONTROL_V1_BYTES; + return msg_type == RESOURCE_X_MSG_ASSERT_X && len == RESOURCE_X_CONTROL_V1_BYTES; if (kind == RESOURCE_X_WIRE_LOCAL_PROOF_DECLARATION) - return msg_type == RESOURCE_X_MSG_ASSERT_X - && len == RESOURCE_X_SHORT_V1_BYTES; + return msg_type == RESOURCE_X_MSG_ASSERT_X && len == RESOURCE_X_SHORT_V1_BYTES; if (kind == RESOURCE_X_WIRE_BLOCK_TO_N) - return msg_type == RESOURCE_X_MSG_BLOCK_TO_N - && len == RESOURCE_X_CONTROL_V1_BYTES; + return msg_type == RESOURCE_X_MSG_BLOCK_TO_N && len == RESOURCE_X_CONTROL_V1_BYTES; if (kind == RESOURCE_X_WIRE_BLOCKED_TO_N) return msg_type == RESOURCE_X_MSG_BLOCKED_TO_N - && (len == RESOURCE_X_CONTROL_V1_BYTES - || len == RESOURCE_X_PROOF_V1_BYTES); + && (len == RESOURCE_X_CONTROL_V1_BYTES || len == RESOURCE_X_PROOF_V1_BYTES); if (kind == RESOURCE_X_WIRE_IMAGE_ENVELOPE) - return msg_type == RESOURCE_X_MSG_IMAGE_OR_GRANT - && len == RESOURCE_X_IMAGE_V1_BYTES; + return msg_type == RESOURCE_X_MSG_IMAGE_OR_GRANT && len == RESOURCE_X_IMAGE_V1_BYTES; if (kind == RESOURCE_X_WIRE_AUTHORITY_GRANT) - return msg_type == RESOURCE_X_MSG_IMAGE_OR_GRANT - && len == RESOURCE_X_PROOF_V1_BYTES; + return msg_type == RESOURCE_X_MSG_IMAGE_OR_GRANT && len == RESOURCE_X_PROOF_V1_BYTES; if (kind == RESOURCE_X_WIRE_RELEASE_X) return msg_type == RESOURCE_X_MSG_SETTLEMENT_OR_RELEASE - && len == RESOURCE_X_CONTROL_V1_BYTES; + && len == RESOURCE_X_CONTROL_V1_BYTES; if (kind == RESOURCE_X_WIRE_INSTALL_SETTLEMENT) - return msg_type == RESOURCE_X_MSG_SETTLEMENT_OR_RELEASE - && len == RESOURCE_X_SHORT_V1_BYTES; + return msg_type == RESOURCE_X_MSG_SETTLEMENT_OR_RELEASE && len == RESOURCE_X_SHORT_V1_BYTES; if (kind == RESOURCE_X_WIRE_SOURCE_SETTLEMENT_V2) - return msg_type == RESOURCE_X_MSG_BLOCK_TO_N - && len == RESOURCE_X_PROOF_V1_BYTES; + return msg_type == RESOURCE_X_MSG_BLOCK_TO_N && len == RESOURCE_X_PROOF_V1_BYTES; if (kind == RESOURCE_X_WIRE_SOURCE_SETTLEMENT_ACK_V2) - return msg_type == RESOURCE_X_MSG_BLOCKED_TO_N - && len == RESOURCE_X_PROOF_V1_BYTES; + return msg_type == RESOURCE_X_MSG_BLOCKED_TO_N && len == RESOURCE_X_PROOF_V1_BYTES; return false; } @@ -180,8 +169,8 @@ resource_x_frame_length(const ResourceXDecodedFrame *frame, uint16 *len) *len = RESOURCE_X_CONTROL_V1_BYTES; return true; case RESOURCE_X_WIRE_BLOCKED_TO_N: - *len = frame->blocked_has_remote_proof - ? RESOURCE_X_PROOF_V1_BYTES : RESOURCE_X_CONTROL_V1_BYTES; + *len = frame->blocked_has_remote_proof ? RESOURCE_X_PROOF_V1_BYTES + : RESOURCE_X_CONTROL_V1_BYTES; return true; case RESOURCE_X_WIRE_LOCAL_PROOF_DECLARATION: case RESOURCE_X_WIRE_INSTALL_SETTLEMENT: @@ -202,8 +191,7 @@ resource_x_frame_length(const ResourceXDecodedFrame *frame, uint16 *len) static bool -resource_x_bootstrap_common_valid(uint8 msg_type, - const ResourceXDecodedCommon *common, +resource_x_bootstrap_common_valid(uint8 msg_type, const ResourceXDecodedCommon *common, ResourceXWireReject *reject) { bool request = msg_type == RESOURCE_X_MSG_ASSERT_X; @@ -218,27 +206,19 @@ resource_x_bootstrap_common_valid(uint8 msg_type, return false; } if ((request && common->base_authority_generation != 0) - || (ack && common->base_authority_generation == 0) - || common->resource_formation == 0 - || common->master_session_incarnation == 0 - || common->assertion_sequence == 0 - || common->sender_connection_generation == 0 - || common->authority_generation != 0) { + || (ack && common->base_authority_generation == 0) || common->resource_formation == 0 + || common->master_session_incarnation == 0 || common->assertion_sequence == 0 + || common->sender_connection_generation == 0 || common->authority_generation != 0) { resource_x_wire_reject(reject, RESOURCE_X_WIRE_REJECT_GENERATION); return false; } - if (common->ordered_lane != 0 - || common->action_node - != common->logical_assertion.requester_node - || common->observed_mode != (uint8)PCM_STATE_N - || common->target_mode != (uint8)PCM_STATE_X - || common->source_candidate != 0 - || common->retain_pi_if_dirty != 0) { + if (common->ordered_lane != 0 || common->action_node != common->logical_assertion.requester_node + || common->observed_mode != (uint8)PCM_STATE_N || common->target_mode != (uint8)PCM_STATE_X + || common->source_candidate != 0 || common->retain_pi_if_dirty != 0) { resource_x_wire_reject(reject, RESOURCE_X_WIRE_REJECT_ROLE); return false; } - if (common->outcome - != (request ? RESOURCE_X_OUTCOME_NONE : RESOURCE_X_OUTCOME_OK)) { + if (common->outcome != (request ? RESOURCE_X_OUTCOME_NONE : RESOURCE_X_OUTCOME_OK)) { resource_x_wire_reject(reject, RESOURCE_X_WIRE_REJECT_ENUM); return false; } @@ -252,15 +232,14 @@ resource_x_bootstrap_common_valid(uint8 msg_type, static bool -resource_x_source_settlement_common_valid( - uint8 msg_type, ResourceXWireKind kind, - const ResourceXDecodedCommon *common, ResourceXWireReject *reject) +resource_x_source_settlement_common_valid(uint8 msg_type, ResourceXWireKind kind, + const ResourceXDecodedCommon *common, + ResourceXWireReject *reject) { bool request = kind == RESOURCE_X_WIRE_SOURCE_SETTLEMENT_V2; bool ack = kind == RESOURCE_X_WIRE_SOURCE_SETTLEMENT_ACK_V2; - if ((!request && !ack) - || (request && msg_type != RESOURCE_X_MSG_BLOCK_TO_N) + if ((!request && !ack) || (request && msg_type != RESOURCE_X_MSG_BLOCK_TO_N) || (ack && msg_type != RESOURCE_X_MSG_BLOCKED_TO_N)) { resource_x_wire_reject(reject, RESOURCE_X_WIRE_REJECT_TYPE_KIND); return false; @@ -269,32 +248,23 @@ resource_x_source_settlement_common_valid( resource_x_wire_reject(reject, RESOURCE_X_WIRE_REJECT_IDENTITY); return false; } - if (common->base_authority_generation == 0 - || common->base_authority_generation == UINT64_MAX - || common->authority_generation - <= common->base_authority_generation - || common->authority_generation == UINT64_MAX - || common->resource_formation == 0 - || common->master_session_incarnation == 0 - || common->assertion_sequence == 0 + if (common->base_authority_generation == 0 || common->base_authority_generation == UINT64_MAX + || common->authority_generation <= common->base_authority_generation + || common->authority_generation == UINT64_MAX || common->resource_formation == 0 + || common->master_session_incarnation == 0 || common->assertion_sequence == 0 || common->sender_connection_generation == 0) { resource_x_wire_reject(reject, RESOURCE_X_WIRE_REJECT_GENERATION); return false; } - if (common->ordered_lane != 0 - || common->action_node < 0 + if (common->ordered_lane != 0 || common->action_node < 0 || common->action_node >= RESOURCE_X_PROTOCOL_NODE_LIMIT - || common->action_node - == common->logical_assertion.requester_node - || common->observed_mode != (uint8)PCM_STATE_N - || common->target_mode != (uint8)PCM_STATE_N - || common->source_candidate != 1 - || common->retain_pi_if_dirty != 1) { + || common->action_node == common->logical_assertion.requester_node + || common->observed_mode != (uint8)PCM_STATE_N || common->target_mode != (uint8)PCM_STATE_N + || common->source_candidate != 1 || common->retain_pi_if_dirty != 1) { resource_x_wire_reject(reject, RESOURCE_X_WIRE_REJECT_ROLE); return false; } - if (common->outcome - != (request ? RESOURCE_X_OUTCOME_NONE : RESOURCE_X_OUTCOME_OK)) { + if (common->outcome != (request ? RESOURCE_X_OUTCOME_NONE : RESOURCE_X_OUTCOME_OK)) { resource_x_wire_reject(reject, RESOURCE_X_WIRE_REJECT_ENUM); return false; } @@ -307,8 +277,7 @@ resource_x_source_settlement_common_valid( static bool -resource_x_common_valid(ResourceXWireKind kind, - const ResourceXDecodedCommon *common, +resource_x_common_valid(ResourceXWireKind kind, const ResourceXDecodedCommon *common, ResourceXWireReject *reject) { uint8 allowed_flags = 0; @@ -317,48 +286,38 @@ resource_x_common_valid(ResourceXWireKind kind, resource_x_wire_reject(reject, RESOURCE_X_WIRE_REJECT_IDENTITY); return false; } - if (common->base_authority_generation == 0 - || common->resource_formation == 0 - || common->master_session_incarnation == 0 - || common->assertion_sequence == 0 - || common->sender_connection_generation == 0 - || common->authority_generation == 0) { + if (common->base_authority_generation == 0 || common->resource_formation == 0 + || common->master_session_incarnation == 0 || common->assertion_sequence == 0 + || common->sender_connection_generation == 0 || common->authority_generation == 0) { resource_x_wire_reject(reject, RESOURCE_X_WIRE_REJECT_GENERATION); return false; } - if (common->action_node < 0 - || common->action_node >= RESOURCE_X_PROTOCOL_NODE_LIMIT) { + if (common->action_node < 0 || common->action_node >= RESOURCE_X_PROTOCOL_NODE_LIMIT) { resource_x_wire_reject(reject, RESOURCE_X_WIRE_REJECT_ROLE); return false; } - if (common->observed_mode > (uint8)PCM_STATE_X - || common->target_mode > (uint8)PCM_STATE_X - || common->source_candidate > 1 - || common->retain_pi_if_dirty > 1 + if (common->observed_mode > (uint8)PCM_STATE_X || common->target_mode > (uint8)PCM_STATE_X + || common->source_candidate > 1 || common->retain_pi_if_dirty > 1 || common->outcome > RESOURCE_X_OUTCOME_CORRUPT) { resource_x_wire_reject(reject, RESOURCE_X_WIRE_REJECT_ENUM); return false; } if (kind == RESOURCE_X_WIRE_ASSERT_X) { if (common->action_node != common->logical_assertion.requester_node - || common->source_candidate != 0 - || common->retain_pi_if_dirty != 0 + || common->source_candidate != 0 || common->retain_pi_if_dirty != 0 || common->outcome != RESOURCE_X_OUTCOME_NONE) { resource_x_wire_reject(reject, RESOURCE_X_WIRE_REJECT_ROLE); return false; } } else if (kind == RESOURCE_X_WIRE_BLOCK_TO_N) { bool direct_x_source = common->observed_mode == (uint8)PCM_STATE_X - && common->source_candidate == 1 - && common->retain_pi_if_dirty == 1; + && common->source_candidate == 1 && common->retain_pi_if_dirty == 1; bool shared_s_holder = common->observed_mode == (uint8)PCM_STATE_S - && common->source_candidate - == common->retain_pi_if_dirty; + && common->source_candidate == common->retain_pi_if_dirty; allowed_flags = RESOURCE_X_COMMON_FLAG_AUTHORITY_WITH_IMAGE; - if (common->target_mode != (uint8)PCM_STATE_N - || (!direct_x_source && !shared_s_holder)) { + if (common->target_mode != (uint8)PCM_STATE_N || (!direct_x_source && !shared_s_holder)) { resource_x_wire_reject(reject, RESOURCE_X_WIRE_REJECT_ROLE); return false; } @@ -368,8 +327,7 @@ resource_x_common_valid(ResourceXWireKind kind, } } else if (kind == RESOURCE_X_WIRE_BLOCKED_TO_N) { allowed_flags = RESOURCE_X_COMMON_FLAG_PI_ESTABLISHED; - if (common->source_candidate != 0 - || common->retain_pi_if_dirty != 0 + if (common->source_candidate != 0 || common->retain_pi_if_dirty != 0 || common->outcome == RESOURCE_X_OUTCOME_NONE || ((common->flags & RESOURCE_X_COMMON_FLAG_PI_ESTABLISHED) != 0 && common->outcome != RESOURCE_X_OUTCOME_OK)) { @@ -378,8 +336,7 @@ resource_x_common_valid(ResourceXWireKind kind, } } else if (kind == RESOURCE_X_WIRE_RELEASE_X) { if (common->action_node != common->logical_assertion.requester_node - || common->source_candidate != 0 - || common->retain_pi_if_dirty != 0 + || common->source_candidate != 0 || common->retain_pi_if_dirty != 0 || common->outcome == RESOURCE_X_OUTCOME_NONE) { resource_x_wire_reject(reject, RESOURCE_X_WIRE_REJECT_ROLE); return false; @@ -387,8 +344,7 @@ resource_x_common_valid(ResourceXWireKind kind, } else if (kind == RESOURCE_X_WIRE_AUTHORITY_GRANT) { allowed_flags = RESOURCE_X_COMMON_FLAG_REMOTE_IMAGE_REQUIRED; if (common->action_node != common->logical_assertion.requester_node - || common->source_candidate != 0 - || common->retain_pi_if_dirty != 0 + || common->source_candidate != 0 || common->retain_pi_if_dirty != 0 || common->target_mode != (uint8)PCM_STATE_X || common->outcome == RESOURCE_X_OUTCOME_NONE) { resource_x_wire_reject(reject, RESOURCE_X_WIRE_REJECT_ROLE); @@ -397,8 +353,7 @@ resource_x_common_valid(ResourceXWireKind kind, } else if (kind == RESOURCE_X_WIRE_LOCAL_PROOF_DECLARATION || kind == RESOURCE_X_WIRE_INSTALL_SETTLEMENT) { if (common->action_node != common->logical_assertion.requester_node - || common->source_candidate != 0 - || common->retain_pi_if_dirty != 0 + || common->source_candidate != 0 || common->retain_pi_if_dirty != 0 || common->target_mode != (uint8)PCM_STATE_X || common->outcome == RESOURCE_X_OUTCOME_NONE) { resource_x_wire_reject(reject, RESOURCE_X_WIRE_REJECT_ROLE); @@ -406,8 +361,7 @@ resource_x_common_valid(ResourceXWireKind kind, } } else if (kind == RESOURCE_X_WIRE_IMAGE_ENVELOPE) { allowed_flags = RESOURCE_X_COMMON_FLAG_AUTHORITY_WITH_IMAGE; - if (common->source_candidate != 0 - || common->retain_pi_if_dirty != 0 + if (common->source_candidate != 0 || common->retain_pi_if_dirty != 0 || common->target_mode != (uint8)PCM_STATE_X || common->outcome == RESOURCE_X_OUTCOME_NONE) { resource_x_wire_reject(reject, RESOURCE_X_WIRE_REJECT_ROLE); @@ -444,22 +398,20 @@ resource_x_common_valid(ResourceXWireKind kind, static bool resource_x_pair_common_valid(uint8 msg_type, ResourceXWireKind kind, - const ResourceXDecodedCommon *common, - ResourceXWireReject *reject) + const ResourceXDecodedCommon *common, ResourceXWireReject *reject) { if (kind == RESOURCE_X_WIRE_PREASSERT_BOOTSTRAP) return resource_x_bootstrap_common_valid(msg_type, common, reject); if (kind == RESOURCE_X_WIRE_SOURCE_SETTLEMENT_V2 || kind == RESOURCE_X_WIRE_SOURCE_SETTLEMENT_ACK_V2) - return resource_x_source_settlement_common_valid( - msg_type, kind, common, reject); + return resource_x_source_settlement_common_valid(msg_type, kind, common, reject); return resource_x_common_valid(kind, common, reject); } static void -resource_x_common_encode(uint8 *bytes, ResourceXWireKind kind, - const ResourceXDecodedCommon *common, uint16 len) +resource_x_common_encode(uint8 *bytes, ResourceXWireKind kind, const ResourceXDecodedCommon *common, + uint16 len) { bytes[0] = RESOURCE_X_WIRE_VERSION; bytes[1] = (uint8)kind; @@ -483,10 +435,8 @@ resource_x_common_encode(uint8 *bytes, ResourceXWireKind kind, static bool -resource_x_common_decode(uint8 msg_type, const uint8 *bytes, - ResourceXWireKind kind, - ResourceXDecodedCommon *common, - ResourceXWireReject *reject) +resource_x_common_decode(uint8 msg_type, const uint8 *bytes, ResourceXWireKind kind, + ResourceXDecodedCommon *common, ResourceXWireReject *reject) { memset(common, 0, sizeof(*common)); if (!resource_x_bytes_zero(bytes + 82, 6)) { @@ -539,8 +489,7 @@ resource_x_disposition_matches(uint8 proof_kind, uint8 disposition) static bool -resource_x_body_valid(const ResourceXDecodedFrame *frame, - ResourceXWireReject *reject) +resource_x_body_valid(const ResourceXDecodedFrame *frame, ResourceXWireReject *reject) { bool valid = true; @@ -557,113 +506,75 @@ resource_x_body_valid(const ResourceXDecodedFrame *frame, const ResourceXDecodedBlockedToN *body = &frame->body.blocked_to_n; valid = body->source_carrier_generation != 0 - && body->requester_target_generation - == frame->common.assertion_sequence - && body->proof_kind == RESOURCE_X_PROOF_REMOTE_CARRIER - && body->source_disposition - == RESOURCE_X_DISPOSITION_REMOTE_NONWRITABLE - && body->proof_flags == 0 - && body->holder_connection_generation != 0 - && body->acting_formation == frame->common.resource_formation - && resource_x_dependencies_valid(body->dependencies, - body->dependency_count); + && body->requester_target_generation == frame->common.assertion_sequence + && body->proof_kind == RESOURCE_X_PROOF_REMOTE_CARRIER + && body->source_disposition == RESOURCE_X_DISPOSITION_REMOTE_NONWRITABLE + && body->proof_flags == 0 && body->holder_connection_generation != 0 + && body->acting_formation == frame->common.resource_formation + && resource_x_dependencies_valid(body->dependencies, body->dependency_count); } break; case RESOURCE_X_WIRE_SOURCE_SETTLEMENT_V2: - case RESOURCE_X_WIRE_SOURCE_SETTLEMENT_ACK_V2: - { - const ResourceXDecodedBlockedToN *body - = &frame->body.blocked_to_n; + case RESOURCE_X_WIRE_SOURCE_SETTLEMENT_ACK_V2: { + const ResourceXDecodedBlockedToN *body = &frame->body.blocked_to_n; - valid = frame->blocked_has_remote_proof - && body->source_carrier_generation != 0 - && body->requester_target_generation - == frame->common.assertion_sequence + valid = frame->blocked_has_remote_proof && body->source_carrier_generation != 0 + && body->requester_target_generation == frame->common.assertion_sequence && body->proof_kind == RESOURCE_X_PROOF_REMOTE_CARRIER - && body->source_disposition - == RESOURCE_X_DISPOSITION_REMOTE_NONWRITABLE - && body->proof_flags == 0 - && body->holder_connection_generation != 0 - && body->acting_formation - == frame->common.resource_formation - && resource_x_dependencies_valid( - body->dependencies, body->dependency_count); - } - break; + && body->source_disposition == RESOURCE_X_DISPOSITION_REMOTE_NONWRITABLE + && body->proof_flags == 0 && body->holder_connection_generation != 0 + && body->acting_formation == frame->common.resource_formation + && resource_x_dependencies_valid(body->dependencies, body->dependency_count); + } break; case RESOURCE_X_WIRE_LOCAL_PROOF_DECLARATION: valid = frame->body.local_proof.local_holder_authority_generation != 0 - && frame->body.local_proof.requester_target_generation - == frame->common.assertion_sequence - && frame->body.local_proof.dependency_count <= RESOURCE_X_DEPENDENCY_MAX - && frame->body.local_proof.requester_connection_generation != 0 - && frame->body.local_proof.local_proof_generation != 0; + && frame->body.local_proof.requester_target_generation + == frame->common.assertion_sequence + && frame->body.local_proof.dependency_count <= RESOURCE_X_DEPENDENCY_MAX + && frame->body.local_proof.requester_connection_generation != 0 + && frame->body.local_proof.local_proof_generation != 0; break; - case RESOURCE_X_WIRE_AUTHORITY_GRANT: - { - const ResourceXDecodedAuthorityGrant *body - = &frame->body.authority_grant; - bool remote = body->proof_kind == RESOURCE_X_PROOF_REMOTE_CARRIER; - - valid = body->final_authority_generation - == frame->common.authority_generation - && body->requester_target_generation - == frame->common.assertion_sequence + case RESOURCE_X_WIRE_AUTHORITY_GRANT: { + const ResourceXDecodedAuthorityGrant *body = &frame->body.authority_grant; + bool remote = body->proof_kind == RESOURCE_X_PROOF_REMOTE_CARRIER; + + valid = body->final_authority_generation == frame->common.authority_generation + && body->requester_target_generation == frame->common.assertion_sequence && body->proof_kind >= RESOURCE_X_PROOF_KIND_MIN && body->proof_kind <= RESOURCE_X_PROOF_KIND_MAX - && resource_x_disposition_matches(body->proof_kind, - body->source_disposition) - && body->grant_flags == 0 - && body->requester_connection_generation != 0 - && resource_x_dependencies_valid(body->dependencies, - body->dependency_count) - && (((frame->common.flags - & RESOURCE_X_COMMON_FLAG_REMOTE_IMAGE_REQUIRED) != 0) + && resource_x_disposition_matches(body->proof_kind, body->source_disposition) + && body->grant_flags == 0 && body->requester_connection_generation != 0 + && resource_x_dependencies_valid(body->dependencies, body->dependency_count) + && (((frame->common.flags & RESOURCE_X_COMMON_FLAG_REMOTE_IMAGE_REQUIRED) != 0) == remote) && (!remote || body->source_carrier_generation != 0); - } - break; - case RESOURCE_X_WIRE_IMAGE_ENVELOPE: - { - const ResourceXDecodedImageEnvelope *body - = &frame->body.image_envelope; + } break; + case RESOURCE_X_WIRE_IMAGE_ENVELOPE: { + const ResourceXDecodedImageEnvelope *body = &frame->body.image_envelope; - valid = body->conversion_base_generation - == frame->common.base_authority_generation + valid = body->conversion_base_generation == frame->common.base_authority_generation && body->source_carrier_generation != 0 - && body->requester_target_generation - == frame->common.assertion_sequence + && body->requester_target_generation == frame->common.assertion_sequence && body->image_length == RESOURCE_X_PAGE_BYTES - && body->source_disposition - == RESOURCE_X_DISPOSITION_REMOTE_NONWRITABLE - && body->proof_kind == RESOURCE_X_PROOF_REMOTE_CARRIER - && body->image_flags == 0 - && resource_x_dependencies_valid(body->dependencies, - body->dependency_count); - } - break; - case RESOURCE_X_WIRE_INSTALL_SETTLEMENT: - { - const ResourceXDecodedInstallSettlement *body - = &frame->body.install_settlement; - - valid = body->conversion_base_generation - == frame->common.base_authority_generation - && body->final_authority_generation - == frame->common.authority_generation + && body->source_disposition == RESOURCE_X_DISPOSITION_REMOTE_NONWRITABLE + && body->proof_kind == RESOURCE_X_PROOF_REMOTE_CARRIER && body->image_flags == 0 + && resource_x_dependencies_valid(body->dependencies, body->dependency_count); + } break; + case RESOURCE_X_WIRE_INSTALL_SETTLEMENT: { + const ResourceXDecodedInstallSettlement *body = &frame->body.install_settlement; + + valid = body->conversion_base_generation == frame->common.base_authority_generation + && body->final_authority_generation == frame->common.authority_generation && body->requester_connection_generation != 0 - && body->requester_target_generation - == frame->common.assertion_sequence + && body->requester_target_generation == frame->common.assertion_sequence && body->installed_mode == (uint8)PCM_STATE_X && body->requester_role == RESOURCE_X_REQUESTER_ROLE_ACQUIRER && body->terminal_outcome > RESOURCE_X_OUTCOME_NONE && body->terminal_outcome <= RESOURCE_X_OUTCOME_CORRUPT - && body->terminal_state - >= RESOURCE_X_SETTLEMENT_TERMINAL_INSTALLED - && body->terminal_state - <= RESOURCE_X_SETTLEMENT_TERMINAL_EXCLUDED + && body->terminal_state >= RESOURCE_X_SETTLEMENT_TERMINAL_INSTALLED + && body->terminal_state <= RESOURCE_X_SETTLEMENT_TERMINAL_EXCLUDED && body->settlement_flags == 0; - } - break; + } break; default: valid = false; break; @@ -699,23 +610,15 @@ resource_x_body_encode(uint8 *bytes, const ResourceXDecodedFrame *frame) { switch (frame->kind) { case RESOURCE_X_WIRE_LOCAL_PROOF_DECLARATION: - resource_x_put_u64(bytes + 96, - frame->body.local_proof.local_holder_authority_generation); - resource_x_put_u64(bytes + 104, - frame->body.local_proof.requester_target_generation); + resource_x_put_u64(bytes + 96, frame->body.local_proof.local_holder_authority_generation); + resource_x_put_u64(bytes + 104, frame->body.local_proof.requester_target_generation); resource_x_put_u64(bytes + 112, frame->body.local_proof.page_scn_lsn); - resource_x_put_u16(bytes + 120, - frame->body.local_proof.dependency_count); - resource_x_put_u32(bytes + 124, - frame->body.local_proof.dependency_vector_crc32c); - resource_x_put_u32(bytes + 128, - frame->body.local_proof.page_checksum); - resource_x_put_u32(bytes + 132, - frame->body.local_proof.local_image_proof_crc32c); - resource_x_put_u64(bytes + 136, - frame->body.local_proof.requester_connection_generation); - resource_x_put_u64(bytes + 144, - frame->body.local_proof.local_proof_generation); + resource_x_put_u16(bytes + 120, frame->body.local_proof.dependency_count); + resource_x_put_u32(bytes + 124, frame->body.local_proof.dependency_vector_crc32c); + resource_x_put_u32(bytes + 128, frame->body.local_proof.page_checksum); + resource_x_put_u32(bytes + 132, frame->body.local_proof.local_image_proof_crc32c); + resource_x_put_u64(bytes + 136, frame->body.local_proof.requester_connection_generation); + resource_x_put_u64(bytes + 144, frame->body.local_proof.local_proof_generation); break; case RESOURCE_X_WIRE_BLOCKED_TO_N: case RESOURCE_X_WIRE_SOURCE_SETTLEMENT_V2: @@ -738,68 +641,58 @@ resource_x_body_encode(uint8 *bytes, const ResourceXDecodedFrame *frame) resource_x_put_u64(bytes + 304, body->acting_formation); } break; - case RESOURCE_X_WIRE_AUTHORITY_GRANT: - { - const ResourceXDecodedAuthorityGrant *body - = &frame->body.authority_grant; - - memcpy(bytes + 96, body->source_fence, RESOURCE_X_SOURCE_FENCE_BYTES); - resource_x_put_u64(bytes + 130, body->final_authority_generation); - resource_x_put_u64(bytes + 138, body->source_carrier_generation); - resource_x_put_u64(bytes + 146, body->requester_target_generation); - resource_x_put_u64(bytes + 154, body->page_scn_lsn); - resource_x_put_u16(bytes + 162, body->dependency_count); - resource_x_dependencies_encode(bytes + 164, body->dependencies); - resource_x_put_u32(bytes + 292, body->source_proof_crc32c); - resource_x_put_u32(bytes + 296, body->page_checksum); - bytes[300] = body->proof_kind; - bytes[301] = body->source_disposition; - resource_x_put_u16(bytes + 302, body->grant_flags); - resource_x_put_u64(bytes + 304, body->requester_connection_generation); - } - break; - case RESOURCE_X_WIRE_IMAGE_ENVELOPE: - { - const ResourceXDecodedImageEnvelope *body - = &frame->body.image_envelope; - - memcpy(bytes + 96, body->request_tail, RESOURCE_X_REQUEST_TAIL_BYTES); - resource_x_put_u64(bytes + 116, body->conversion_base_generation); - memcpy(bytes + 124, body->source_fence, RESOURCE_X_SOURCE_FENCE_BYTES); - resource_x_put_u64(bytes + 158, body->source_carrier_generation); - resource_x_put_u64(bytes + 166, body->requester_target_generation); - resource_x_put_u64(bytes + 174, body->page_scn_lsn); - resource_x_put_u16(bytes + 182, body->dependency_count); - resource_x_dependencies_encode(bytes + 184, body->dependencies); - resource_x_put_u32(bytes + 312, body->dependency_vector_crc32c); - resource_x_put_u32(bytes + 316, body->page_checksum); - resource_x_put_u32(bytes + 320, body->image_length); - bytes[324] = body->source_disposition; - bytes[325] = body->proof_kind; - resource_x_put_u16(bytes + 326, body->image_flags); - memcpy(bytes + 328, body->page_bytes, RESOURCE_X_PAGE_BYTES); - } - break; - case RESOURCE_X_WIRE_INSTALL_SETTLEMENT: - { - const ResourceXDecodedInstallSettlement *body - = &frame->body.install_settlement; - - resource_x_put_u64(bytes + 96, body->conversion_base_generation); - resource_x_put_u64(bytes + 104, body->final_authority_generation); - resource_x_put_u64(bytes + 112, - body->requester_connection_generation); - resource_x_put_u64(bytes + 120, body->requester_target_generation); - resource_x_put_u64(bytes + 128, body->page_scn_lsn); - resource_x_put_u32(bytes + 136, body->page_checksum); - resource_x_put_u32(bytes + 140, body->source_proof_crc32c); - bytes[144] = body->installed_mode; - bytes[145] = body->requester_role; - bytes[146] = body->terminal_outcome; - bytes[147] = body->terminal_state; - resource_x_put_u32(bytes + 148, body->settlement_flags); - } - break; + case RESOURCE_X_WIRE_AUTHORITY_GRANT: { + const ResourceXDecodedAuthorityGrant *body = &frame->body.authority_grant; + + memcpy(bytes + 96, body->source_fence, RESOURCE_X_SOURCE_FENCE_BYTES); + resource_x_put_u64(bytes + 130, body->final_authority_generation); + resource_x_put_u64(bytes + 138, body->source_carrier_generation); + resource_x_put_u64(bytes + 146, body->requester_target_generation); + resource_x_put_u64(bytes + 154, body->page_scn_lsn); + resource_x_put_u16(bytes + 162, body->dependency_count); + resource_x_dependencies_encode(bytes + 164, body->dependencies); + resource_x_put_u32(bytes + 292, body->source_proof_crc32c); + resource_x_put_u32(bytes + 296, body->page_checksum); + bytes[300] = body->proof_kind; + bytes[301] = body->source_disposition; + resource_x_put_u16(bytes + 302, body->grant_flags); + resource_x_put_u64(bytes + 304, body->requester_connection_generation); + } break; + case RESOURCE_X_WIRE_IMAGE_ENVELOPE: { + const ResourceXDecodedImageEnvelope *body = &frame->body.image_envelope; + + memcpy(bytes + 96, body->request_tail, RESOURCE_X_REQUEST_TAIL_BYTES); + resource_x_put_u64(bytes + 116, body->conversion_base_generation); + memcpy(bytes + 124, body->source_fence, RESOURCE_X_SOURCE_FENCE_BYTES); + resource_x_put_u64(bytes + 158, body->source_carrier_generation); + resource_x_put_u64(bytes + 166, body->requester_target_generation); + resource_x_put_u64(bytes + 174, body->page_scn_lsn); + resource_x_put_u16(bytes + 182, body->dependency_count); + resource_x_dependencies_encode(bytes + 184, body->dependencies); + resource_x_put_u32(bytes + 312, body->dependency_vector_crc32c); + resource_x_put_u32(bytes + 316, body->page_checksum); + resource_x_put_u32(bytes + 320, body->image_length); + bytes[324] = body->source_disposition; + bytes[325] = body->proof_kind; + resource_x_put_u16(bytes + 326, body->image_flags); + memcpy(bytes + 328, body->page_bytes, RESOURCE_X_PAGE_BYTES); + } break; + case RESOURCE_X_WIRE_INSTALL_SETTLEMENT: { + const ResourceXDecodedInstallSettlement *body = &frame->body.install_settlement; + + resource_x_put_u64(bytes + 96, body->conversion_base_generation); + resource_x_put_u64(bytes + 104, body->final_authority_generation); + resource_x_put_u64(bytes + 112, body->requester_connection_generation); + resource_x_put_u64(bytes + 120, body->requester_target_generation); + resource_x_put_u64(bytes + 128, body->page_scn_lsn); + resource_x_put_u32(bytes + 136, body->page_checksum); + resource_x_put_u32(bytes + 140, body->source_proof_crc32c); + bytes[144] = body->installed_mode; + bytes[145] = body->requester_role; + bytes[146] = body->terminal_outcome; + bytes[147] = body->terminal_state; + resource_x_put_u32(bytes + 148, body->settlement_flags); + } break; default: break; } @@ -808,7 +701,7 @@ resource_x_body_encode(uint8 *bytes, const ResourceXDecodedFrame *frame) static bool resource_x_body_decode(const uint8 *bytes, ResourceXDecodedFrame *frame, - ResourceXWireReject *reject) + ResourceXWireReject *reject) { switch (frame->kind) { case RESOURCE_X_WIRE_LOCAL_PROOF_DECLARATION: @@ -816,21 +709,15 @@ resource_x_body_decode(const uint8 *bytes, ResourceXDecodedFrame *frame, resource_x_wire_reject(reject, RESOURCE_X_WIRE_REJECT_RESERVED); return false; } - frame->body.local_proof.local_holder_authority_generation - = resource_x_get_u64(bytes + 96); - frame->body.local_proof.requester_target_generation - = resource_x_get_u64(bytes + 104); + frame->body.local_proof.local_holder_authority_generation = resource_x_get_u64(bytes + 96); + frame->body.local_proof.requester_target_generation = resource_x_get_u64(bytes + 104); frame->body.local_proof.page_scn_lsn = resource_x_get_u64(bytes + 112); frame->body.local_proof.dependency_count = resource_x_get_u16(bytes + 120); - frame->body.local_proof.dependency_vector_crc32c - = resource_x_get_u32(bytes + 124); + frame->body.local_proof.dependency_vector_crc32c = resource_x_get_u32(bytes + 124); frame->body.local_proof.page_checksum = resource_x_get_u32(bytes + 128); - frame->body.local_proof.local_image_proof_crc32c - = resource_x_get_u32(bytes + 132); - frame->body.local_proof.requester_connection_generation - = resource_x_get_u64(bytes + 136); - frame->body.local_proof.local_proof_generation - = resource_x_get_u64(bytes + 144); + frame->body.local_proof.local_image_proof_crc32c = resource_x_get_u32(bytes + 132); + frame->body.local_proof.requester_connection_generation = resource_x_get_u64(bytes + 136); + frame->body.local_proof.local_proof_generation = resource_x_get_u64(bytes + 144); break; case RESOURCE_X_WIRE_BLOCKED_TO_N: case RESOURCE_X_WIRE_SOURCE_SETTLEMENT_V2: @@ -853,65 +740,58 @@ resource_x_body_decode(const uint8 *bytes, ResourceXDecodedFrame *frame, body->acting_formation = resource_x_get_u64(bytes + 304); } break; - case RESOURCE_X_WIRE_AUTHORITY_GRANT: - { - ResourceXDecodedAuthorityGrant *body = &frame->body.authority_grant; - - memcpy(body->source_fence, bytes + 96, RESOURCE_X_SOURCE_FENCE_BYTES); - body->final_authority_generation = resource_x_get_u64(bytes + 130); - body->source_carrier_generation = resource_x_get_u64(bytes + 138); - body->requester_target_generation = resource_x_get_u64(bytes + 146); - body->page_scn_lsn = resource_x_get_u64(bytes + 154); - body->dependency_count = resource_x_get_u16(bytes + 162); - resource_x_dependencies_decode(bytes + 164, body->dependencies); - body->source_proof_crc32c = resource_x_get_u32(bytes + 292); - body->page_checksum = resource_x_get_u32(bytes + 296); - body->proof_kind = bytes[300]; - body->source_disposition = bytes[301]; - body->grant_flags = resource_x_get_u16(bytes + 302); - body->requester_connection_generation = resource_x_get_u64(bytes + 304); - } - break; - case RESOURCE_X_WIRE_IMAGE_ENVELOPE: - { - ResourceXDecodedImageEnvelope *body = &frame->body.image_envelope; - - memcpy(body->request_tail, bytes + 96, RESOURCE_X_REQUEST_TAIL_BYTES); - body->conversion_base_generation = resource_x_get_u64(bytes + 116); - memcpy(body->source_fence, bytes + 124, RESOURCE_X_SOURCE_FENCE_BYTES); - body->source_carrier_generation = resource_x_get_u64(bytes + 158); - body->requester_target_generation = resource_x_get_u64(bytes + 166); - body->page_scn_lsn = resource_x_get_u64(bytes + 174); - body->dependency_count = resource_x_get_u16(bytes + 182); - resource_x_dependencies_decode(bytes + 184, body->dependencies); - body->dependency_vector_crc32c = resource_x_get_u32(bytes + 312); - body->page_checksum = resource_x_get_u32(bytes + 316); - body->image_length = resource_x_get_u32(bytes + 320); - body->source_disposition = bytes[324]; - body->proof_kind = bytes[325]; - body->image_flags = resource_x_get_u16(bytes + 326); - memcpy(body->page_bytes, bytes + 328, RESOURCE_X_PAGE_BYTES); - } - break; - case RESOURCE_X_WIRE_INSTALL_SETTLEMENT: - { - ResourceXDecodedInstallSettlement *body - = &frame->body.install_settlement; - - body->conversion_base_generation = resource_x_get_u64(bytes + 96); - body->final_authority_generation = resource_x_get_u64(bytes + 104); - body->requester_connection_generation = resource_x_get_u64(bytes + 112); - body->requester_target_generation = resource_x_get_u64(bytes + 120); - body->page_scn_lsn = resource_x_get_u64(bytes + 128); - body->page_checksum = resource_x_get_u32(bytes + 136); - body->source_proof_crc32c = resource_x_get_u32(bytes + 140); - body->installed_mode = bytes[144]; - body->requester_role = bytes[145]; - body->terminal_outcome = bytes[146]; - body->terminal_state = bytes[147]; - body->settlement_flags = resource_x_get_u32(bytes + 148); - } - break; + case RESOURCE_X_WIRE_AUTHORITY_GRANT: { + ResourceXDecodedAuthorityGrant *body = &frame->body.authority_grant; + + memcpy(body->source_fence, bytes + 96, RESOURCE_X_SOURCE_FENCE_BYTES); + body->final_authority_generation = resource_x_get_u64(bytes + 130); + body->source_carrier_generation = resource_x_get_u64(bytes + 138); + body->requester_target_generation = resource_x_get_u64(bytes + 146); + body->page_scn_lsn = resource_x_get_u64(bytes + 154); + body->dependency_count = resource_x_get_u16(bytes + 162); + resource_x_dependencies_decode(bytes + 164, body->dependencies); + body->source_proof_crc32c = resource_x_get_u32(bytes + 292); + body->page_checksum = resource_x_get_u32(bytes + 296); + body->proof_kind = bytes[300]; + body->source_disposition = bytes[301]; + body->grant_flags = resource_x_get_u16(bytes + 302); + body->requester_connection_generation = resource_x_get_u64(bytes + 304); + } break; + case RESOURCE_X_WIRE_IMAGE_ENVELOPE: { + ResourceXDecodedImageEnvelope *body = &frame->body.image_envelope; + + memcpy(body->request_tail, bytes + 96, RESOURCE_X_REQUEST_TAIL_BYTES); + body->conversion_base_generation = resource_x_get_u64(bytes + 116); + memcpy(body->source_fence, bytes + 124, RESOURCE_X_SOURCE_FENCE_BYTES); + body->source_carrier_generation = resource_x_get_u64(bytes + 158); + body->requester_target_generation = resource_x_get_u64(bytes + 166); + body->page_scn_lsn = resource_x_get_u64(bytes + 174); + body->dependency_count = resource_x_get_u16(bytes + 182); + resource_x_dependencies_decode(bytes + 184, body->dependencies); + body->dependency_vector_crc32c = resource_x_get_u32(bytes + 312); + body->page_checksum = resource_x_get_u32(bytes + 316); + body->image_length = resource_x_get_u32(bytes + 320); + body->source_disposition = bytes[324]; + body->proof_kind = bytes[325]; + body->image_flags = resource_x_get_u16(bytes + 326); + memcpy(body->page_bytes, bytes + 328, RESOURCE_X_PAGE_BYTES); + } break; + case RESOURCE_X_WIRE_INSTALL_SETTLEMENT: { + ResourceXDecodedInstallSettlement *body = &frame->body.install_settlement; + + body->conversion_base_generation = resource_x_get_u64(bytes + 96); + body->final_authority_generation = resource_x_get_u64(bytes + 104); + body->requester_connection_generation = resource_x_get_u64(bytes + 112); + body->requester_target_generation = resource_x_get_u64(bytes + 120); + body->page_scn_lsn = resource_x_get_u64(bytes + 128); + body->page_checksum = resource_x_get_u32(bytes + 136); + body->source_proof_crc32c = resource_x_get_u32(bytes + 140); + body->installed_mode = bytes[144]; + body->requester_role = bytes[145]; + body->terminal_outcome = bytes[146]; + body->terminal_state = bytes[147]; + body->settlement_flags = resource_x_get_u32(bytes + 148); + } break; default: break; } @@ -920,9 +800,9 @@ resource_x_body_decode(const uint8 *bytes, ResourceXDecodedFrame *frame, bool -cluster_resource_x_wire_encode(uint8 msg_type, - const ResourceXDecodedFrame *frame, void *payload, uint16 payload_capacity, - uint16 *payload_len_out, ResourceXWireReject *reject) +cluster_resource_x_wire_encode(uint8 msg_type, const ResourceXDecodedFrame *frame, void *payload, + uint16 payload_capacity, uint16 *payload_len_out, + ResourceXWireReject *reject) { uint8 encoded[RESOURCE_X_IMAGE_V1_BYTES]; uint32 crc; @@ -940,8 +820,7 @@ cluster_resource_x_wire_encode(uint8 msg_type, resource_x_wire_reject(reject, RESOURCE_X_WIRE_REJECT_DECLARED_LENGTH); return false; } - if (!resource_x_pair_common_valid( - msg_type, frame->kind, &frame->common, reject)) + if (!resource_x_pair_common_valid(msg_type, frame->kind, &frame->common, reject)) return false; if (!resource_x_body_valid(frame, reject)) return false; @@ -959,9 +838,8 @@ cluster_resource_x_wire_encode(uint8 msg_type, bool -cluster_resource_x_wire_decode(uint8 msg_type, const void *payload, - uint16 payload_len, ResourceXDecodedFrame *out, - ResourceXWireReject *reject) +cluster_resource_x_wire_decode(uint8 msg_type, const void *payload, uint16 payload_len, + ResourceXDecodedFrame *out, ResourceXWireReject *reject) { const uint8 *bytes = (const uint8 *)payload; ResourceXDecodedFrame decoded; @@ -970,10 +848,8 @@ cluster_resource_x_wire_decode(uint8 msg_type, const void *payload, resource_x_wire_reject(reject, RESOURCE_X_WIRE_REJECT_BAD_ARGUMENT); if (bytes == NULL || out == NULL) return false; - if (payload_len != RESOURCE_X_CONTROL_V1_BYTES - && payload_len != RESOURCE_X_SHORT_V1_BYTES - && payload_len != RESOURCE_X_PROOF_V1_BYTES - && payload_len != RESOURCE_X_IMAGE_V1_BYTES) { + if (payload_len != RESOURCE_X_CONTROL_V1_BYTES && payload_len != RESOURCE_X_SHORT_V1_BYTES + && payload_len != RESOURCE_X_PROOF_V1_BYTES && payload_len != RESOURCE_X_IMAGE_V1_BYTES) { resource_x_wire_reject(reject, RESOURCE_X_WIRE_REJECT_LEGACY_LENGTH); return false; } @@ -998,12 +874,10 @@ cluster_resource_x_wire_decode(uint8 msg_type, const void *payload, decoded.kind = kind; decoded.payload_bytes = payload_len; decoded.blocked_has_remote_proof - = (kind == RESOURCE_X_WIRE_BLOCKED_TO_N - || kind == RESOURCE_X_WIRE_SOURCE_SETTLEMENT_V2 + = (kind == RESOURCE_X_WIRE_BLOCKED_TO_N || kind == RESOURCE_X_WIRE_SOURCE_SETTLEMENT_V2 || kind == RESOURCE_X_WIRE_SOURCE_SETTLEMENT_ACK_V2) && payload_len == RESOURCE_X_PROOF_V1_BYTES; - if (!resource_x_common_decode( - msg_type, bytes, kind, &decoded.common, reject)) + if (!resource_x_common_decode(msg_type, bytes, kind, &decoded.common, reject)) return false; decoded.common.semantic_crc32c = resource_x_get_u32(bytes + 4); if (!resource_x_body_decode(bytes, &decoded, reject)) @@ -1020,9 +894,9 @@ cluster_resource_x_wire_decode(uint8 msg_type, const void *payload, * Decode first so malformed retained bytes can never be repaired into a * sendable frame merely by resealing their CRC. */ bool -cluster_resource_x_wire_rebind_sender_generation(uint8 msg_type, - void *payload, uint16 payload_len, uint32 sender_connection_generation, - ResourceXWireReject *reject) +cluster_resource_x_wire_rebind_sender_generation(uint8 msg_type, void *payload, uint16 payload_len, + uint32 sender_connection_generation, + ResourceXWireReject *reject) { ResourceXDecodedFrame decoded; uint8 *bytes = (uint8 *)payload; @@ -1030,8 +904,7 @@ cluster_resource_x_wire_rebind_sender_generation(uint8 msg_type, resource_x_wire_reject(reject, RESOURCE_X_WIRE_REJECT_BAD_ARGUMENT); if (bytes == NULL || sender_connection_generation == 0 - || !cluster_resource_x_wire_decode( - msg_type, bytes, payload_len, &decoded, reject)) + || !cluster_resource_x_wire_decode(msg_type, bytes, payload_len, &decoded, reject)) return false; resource_x_put_u32(bytes + 76, sender_connection_generation); resource_x_put_u32(bytes + 4, 0); diff --git a/src/backend/cluster/cluster_resource_x_retry.c b/src/backend/cluster/cluster_resource_x_retry.c index 62debc15961..41df8706cf7 100644 --- a/src/backend/cluster/cluster_resource_x_retry.c +++ b/src/backend/cluster/cluster_resource_x_retry.c @@ -17,8 +17,7 @@ resource_x_retry_saturating_add(uint64 base, uint64 delta) static bool -resource_x_retry_policy_encode(uint32 max_retries, uint32 initial_backoff_ms, - uint16 *encoded_out) +resource_x_retry_policy_encode(uint32 max_retries, uint32 initial_backoff_ms, uint16 *encoded_out) { uint32 encoded; @@ -27,7 +26,7 @@ resource_x_retry_policy_encode(uint32 max_retries, uint32 initial_backoff_ms, || initial_backoff_ms > RESOURCE_X_RETRY_MAX_BACKOFF_MS) return false; encoded = max_retries * RESOURCE_X_RETRY_MAX_BACKOFF_MS - + (initial_backoff_ms - RESOURCE_X_RETRY_MIN_BACKOFF_MS); + + (initial_backoff_ms - RESOURCE_X_RETRY_MIN_BACKOFF_MS); if (encoded > UINT16_MAX) return false; *encoded_out = (uint16)encoded; @@ -45,8 +44,8 @@ resource_x_retry_policy_decode(uint16 encoded, uint32 *max_retries_out, if (max_retries_out == NULL || initial_backoff_ms_out == NULL) return false; max_retries = encoded / RESOURCE_X_RETRY_MAX_BACKOFF_MS; - initial_backoff_ms = (encoded % RESOURCE_X_RETRY_MAX_BACKOFF_MS) - + RESOURCE_X_RETRY_MIN_BACKOFF_MS; + initial_backoff_ms + = (encoded % RESOURCE_X_RETRY_MAX_BACKOFF_MS) + RESOURCE_X_RETRY_MIN_BACKOFF_MS; if (max_retries > RESOURCE_X_RETRY_MAX_RETRIES) return false; *max_retries_out = max_retries; @@ -66,10 +65,8 @@ resource_x_retry_state_valid(const ResourceXRetryStateV1 *state) || state->first_submit_mono_us == 0 || state->next_retry_due_mono_us < state->first_submit_mono_us || state->terminal_deadline_mono_us < state->next_retry_due_mono_us - || !resource_x_retry_policy_decode(state->flags, &max_retries, - &initial_backoff_ms) - || state->retry_count > max_retries - || state->last_phase < RESOURCE_X_RETRY_PRE_NO_RETURN + || !resource_x_retry_policy_decode(state->flags, &max_retries, &initial_backoff_ms) + || state->retry_count > max_retries || state->last_phase < RESOURCE_X_RETRY_PRE_NO_RETURN || state->last_phase > RESOURCE_X_RETRY_PHASE_RECOVERY_BLOCKED) return false; if (state->last_phase == RESOURCE_X_RETRY_TERMINAL) @@ -118,8 +115,7 @@ resource_x_terminal_record_publish(const ResourceXRetryStateV1 *terminal, { ResourceXTerminalRecordV1 record; - if (terminal == NULL || record_out == NULL - || !resource_x_retry_state_valid(terminal) + if (terminal == NULL || record_out == NULL || !resource_x_retry_state_valid(terminal) || terminal->last_phase != RESOURCE_X_RETRY_TERMINAL || terminal->next_retry_due_mono_us != terminal->terminal_deadline_mono_us) return false; @@ -138,8 +134,7 @@ resource_x_terminal_record_replay(const ResourceXTerminalRecordV1 *record, if (record == NULL || attempt == NULL || state_out == NULL || !resource_x_retry_state_valid(&record->state) || record->state.last_phase != RESOURCE_X_RETRY_TERMINAL - || record->state.next_retry_due_mono_us - != record->state.terminal_deadline_mono_us + || record->state.next_retry_due_mono_us != record->state.terminal_deadline_mono_us || !resource_x_attempt_matches(&record->state.attempt, attempt)) return false; *state_out = record->state; @@ -150,17 +145,14 @@ static bool resource_x_retry_transport_valid(const ResourceXTransportWitness *transport) { return transport != NULL && transport->cluster_epoch != 0 - && transport->peer_session_incarnation != 0 - && transport->connection_generation != 0 && transport->flags == 0; + && transport->peer_session_incarnation != 0 && transport->connection_generation != 0 + && transport->flags == 0; } bool -resource_x_retry_state_init(const ResourceXAttemptWitness *attempt, - uint64 first_submit_mono_us, - uint64 terminal_deadline_mono_us, - uint32 max_retries, - uint32 initial_backoff_ms, - uint32 state_generation, +resource_x_retry_state_init(const ResourceXAttemptWitness *attempt, uint64 first_submit_mono_us, + uint64 terminal_deadline_mono_us, uint32 max_retries, + uint32 initial_backoff_ms, uint32 state_generation, ResourceXRetryStateV1 *out) { ResourceXRetryStateV1 candidate; @@ -168,17 +160,14 @@ resource_x_retry_state_init(const ResourceXAttemptWitness *attempt, uint64 next_retry_due_mono_us; uint16 encoded_policy; - if (attempt == NULL || out == NULL - || !resource_x_attempt_matches(attempt, attempt) - || first_submit_mono_us == 0 - || terminal_deadline_mono_us < first_submit_mono_us - || !resource_x_retry_policy_encode(max_retries, initial_backoff_ms, - &encoded_policy) + if (attempt == NULL || out == NULL || !resource_x_attempt_matches(attempt, attempt) + || first_submit_mono_us == 0 || terminal_deadline_mono_us < first_submit_mono_us + || !resource_x_retry_policy_encode(max_retries, initial_backoff_ms, &encoded_policy) || state_generation == 0) return false; initial_delay_us = (uint64)initial_backoff_ms * UINT64_C(1000); - next_retry_due_mono_us = resource_x_retry_saturating_add( - first_submit_mono_us, initial_delay_us); + next_retry_due_mono_us + = resource_x_retry_saturating_add(first_submit_mono_us, initial_delay_us); if (next_retry_due_mono_us > terminal_deadline_mono_us) next_retry_due_mono_us = terminal_deadline_mono_us; memset(&candidate, 0, sizeof(candidate)); @@ -213,21 +202,17 @@ resource_x_retry_state_is_clear(const ResourceXRetryStateV1 *state) bool -resource_x_retry_policy_exact(const ResourceXRetryStateV1 *state, - uint32 *max_retries_out, +resource_x_retry_policy_exact(const ResourceXRetryStateV1 *state, uint32 *max_retries_out, uint32 *initial_backoff_ms_out) { return state != NULL - && resource_x_retry_policy_decode(state->flags, max_retries_out, - initial_backoff_ms_out); + && resource_x_retry_policy_decode(state->flags, max_retries_out, initial_backoff_ms_out); } bool -resource_x_retry_next_due_exact(const ResourceXRetryStateV1 *state, - uint64 last_admitted_mono_us, - uint32 admitted_retry_count, - uint64 *next_due_out) +resource_x_retry_next_due_exact(const ResourceXRetryStateV1 *state, uint64 last_admitted_mono_us, + uint32 admitted_retry_count, uint64 *next_due_out) { uint64 delay_us; uint64 next_due; @@ -235,15 +220,12 @@ resource_x_retry_next_due_exact(const ResourceXRetryStateV1 *state, uint32 max_retries; if (next_due_out == NULL || !resource_x_retry_state_valid(state) - || !resource_x_retry_policy_exact(state, &max_retries, - &initial_backoff_ms) - || admitted_retry_count > max_retries - || last_admitted_mono_us < state->first_submit_mono_us + || !resource_x_retry_policy_exact(state, &max_retries, &initial_backoff_ms) + || admitted_retry_count > max_retries || last_admitted_mono_us < state->first_submit_mono_us || last_admitted_mono_us > state->terminal_deadline_mono_us) return false; delay_us = (uint64)initial_backoff_ms * UINT64_C(1000); - if (admitted_retry_count >= 64 - || delay_us > (UINT64_MAX >> admitted_retry_count)) + if (admitted_retry_count >= 64 || delay_us > (UINT64_MAX >> admitted_retry_count)) delay_us = UINT64_MAX; else delay_us <<= admitted_retry_count; @@ -257,20 +239,16 @@ resource_x_retry_next_due_exact(const ResourceXRetryStateV1 *state, ResourceXRetryApplyResult resource_x_retry_terminalize_exact(const ResourceXRetryStateV1 *current, - const ResourceXRetryStateV1 *expected, - uint32 terminal_errcode, - uint64 terminal_at_mono_us, - ResourceXRetryStateV1 *terminal_out) + const ResourceXRetryStateV1 *expected, uint32 terminal_errcode, + uint64 terminal_at_mono_us, ResourceXRetryStateV1 *terminal_out) { ResourceXRetryStateV1 terminal; resource_x_retry_state_clear(terminal_out); - if (current == NULL || expected == NULL || terminal_out == NULL - || terminal_errcode == 0 || terminal_at_mono_us == 0 - || resource_x_terminal_reason_decode(terminal_errcode) - == RESOURCE_X_TERMINAL_REASON_INVALID - || !resource_x_retry_state_valid(current) - || !resource_x_retry_state_valid(expected)) + if (current == NULL || expected == NULL || terminal_out == NULL || terminal_errcode == 0 + || terminal_at_mono_us == 0 + || resource_x_terminal_reason_decode(terminal_errcode) == RESOURCE_X_TERMINAL_REASON_INVALID + || !resource_x_retry_state_valid(current) || !resource_x_retry_state_valid(expected)) return RESOURCE_X_RETRY_APPLY_RECOVERY_BLOCKED; if (current->last_phase == RESOURCE_X_RETRY_TERMINAL) { if (!resource_x_attempt_matches(¤t->attempt, &expected->attempt)) @@ -306,8 +284,7 @@ ResourceXRetryDecision resource_x_retry_classify_exact(const ResourceXRetryStateV1 *state, const ResourceXAttemptWitness *current_attempt, const ResourceXTransportWitness *fresh_transport, - uint64 now_mono_us, - ResourceXRetryAction *out) + uint64 now_mono_us, ResourceXRetryAction *out) { ResourceXRetryAction action; uint32 initial_backoff_ms; @@ -326,14 +303,14 @@ resource_x_retry_classify_exact(const ResourceXRetryStateV1 *state, return RESOURCE_X_RETRY_TERMINAL_DENIED; if (now_mono_us >= state->terminal_deadline_mono_us) return state->last_phase == RESOURCE_X_RETRY_PRE_NO_RETURN - ? RESOURCE_X_RETRY_TERMINAL_EXHAUSTED - : RESOURCE_X_RETRY_ROLL_FORWARD; + ? RESOURCE_X_RETRY_TERMINAL_EXHAUSTED + : RESOURCE_X_RETRY_ROLL_FORWARD; if (!resource_x_retry_policy_exact(state, &max_retries, &initial_backoff_ms)) return RESOURCE_X_RETRY_RECOVERY_BLOCKED; if (state->retry_count >= max_retries) return state->last_phase == RESOURCE_X_RETRY_PRE_NO_RETURN - ? RESOURCE_X_RETRY_TERMINAL_EXHAUSTED - : RESOURCE_X_RETRY_ROLL_FORWARD; + ? RESOURCE_X_RETRY_TERMINAL_EXHAUSTED + : RESOURCE_X_RETRY_ROLL_FORWARD; if (now_mono_us < state->next_retry_due_mono_us) return RESOURCE_X_RETRY_NOT_DUE; if (!resource_x_retry_transport_valid(fresh_transport)) diff --git a/src/backend/cluster/cluster_rf_route.c b/src/backend/cluster/cluster_rf_route.c index ad1a273093c..6070f2b59e3 100644 --- a/src/backend/cluster/cluster_rf_route.c +++ b/src/backend/cluster/cluster_rf_route.c @@ -12,16 +12,19 @@ #include "access/xlogrecord.h" #include "cluster/cluster_rf_route.h" -typedef struct RfOpcodeRouteManifestEntryV1 -{ +typedef struct RfOpcodeRouteManifestEntryV1 { RfOpcodeRouteV1 route; - bool active; + bool active; + /* Retain the manifest label for debugger inspection of generated rows. */ + /* cppcheck-suppress unusedStructMember */ const char *diagnostic_name; } RfOpcodeRouteManifestEntryV1; -#define RF_ROUTE(rmid_, info_, flags_, owner_, blocks_, codec_, active_, name_) \ - {{(uint8) (rmid_), (uint8) (info_), (uint8) (flags_), (uint8) (owner_), \ - (uint8) (blocks_), (uint8) (codec_), 0}, (active_), (name_)}, +#define RF_ROUTE(rmid_, info_, flags_, owner_, blocks_, codec_, active_, name_) \ + { { (uint8)(rmid_), (uint8)(info_), (uint8)(flags_), (uint8)(owner_), (uint8)(blocks_), \ + (uint8)(codec_), 0 }, \ + (active_), \ + (name_) }, static const RfOpcodeRouteManifestEntryV1 rf_opcode_route_manifest_v1[] = { #include "cluster/cluster_rf_route_manifest.def" }; @@ -32,63 +35,41 @@ StaticAssertDecl(RM_XACT_ID == 1, "STOP-06 manifest assumes RM_XACT_ID 1"); StaticAssertDecl(RM_SMGR_ID == 2, "STOP-06 manifest assumes RM_SMGR_ID 2"); StaticAssertDecl(RM_CLOG_ID == 3, "STOP-06 manifest assumes RM_CLOG_ID 3"); StaticAssertDecl(RM_DBASE_ID == 4, "STOP-06 manifest assumes RM_DBASE_ID 4"); -StaticAssertDecl(RM_TBLSPC_ID == 5, - "STOP-06 manifest assumes RM_TBLSPC_ID 5"); -StaticAssertDecl(RM_MULTIXACT_ID == 6, - "STOP-06 manifest assumes RM_MULTIXACT_ID 6"); -StaticAssertDecl(RM_RELMAP_ID == 7, - "STOP-06 manifest assumes RM_RELMAP_ID 7"); -StaticAssertDecl(RM_STANDBY_ID == 8, - "STOP-06 manifest assumes RM_STANDBY_ID 8"); -StaticAssertDecl(RM_HEAP2_ID == 9, - "STOP-06 manifest assumes RM_HEAP2_ID 9"); -StaticAssertDecl(RM_HEAP_ID == 10, - "STOP-06 manifest assumes RM_HEAP_ID 10"); -StaticAssertDecl(RM_BTREE_ID == 11, - "STOP-06 manifest assumes RM_BTREE_ID 11"); -StaticAssertDecl(RM_HASH_ID == 12, - "STOP-06 manifest assumes RM_HASH_ID 12"); -StaticAssertDecl(RM_GIN_ID == 13, - "STOP-06 manifest assumes RM_GIN_ID 13"); -StaticAssertDecl(RM_GIST_ID == 14, - "STOP-06 manifest assumes RM_GIST_ID 14"); -StaticAssertDecl(RM_SEQ_ID == 15, - "STOP-06 manifest assumes RM_SEQ_ID 15"); -StaticAssertDecl(RM_SPGIST_ID == 16, - "STOP-06 manifest assumes RM_SPGIST_ID 16"); -StaticAssertDecl(RM_BRIN_ID == 17, - "STOP-06 manifest assumes RM_BRIN_ID 17"); -StaticAssertDecl(RM_COMMIT_TS_ID == 18, - "STOP-06 manifest assumes RM_COMMIT_TS_ID 18"); -StaticAssertDecl(RM_REPLORIGIN_ID == 19, - "STOP-06 manifest assumes RM_REPLORIGIN_ID 19"); -StaticAssertDecl(RM_GENERIC_ID == 20, - "STOP-06 manifest assumes RM_GENERIC_ID 20"); -StaticAssertDecl(RM_LOGICALMSG_ID == 21, - "STOP-06 manifest assumes RM_LOGICALMSG_ID 21"); -StaticAssertDecl(RM_CLUSTER_UNDO_ID == 22, - "STOP-06 manifest assumes RM_CLUSTER_UNDO_ID 22"); +StaticAssertDecl(RM_TBLSPC_ID == 5, "STOP-06 manifest assumes RM_TBLSPC_ID 5"); +StaticAssertDecl(RM_MULTIXACT_ID == 6, "STOP-06 manifest assumes RM_MULTIXACT_ID 6"); +StaticAssertDecl(RM_RELMAP_ID == 7, "STOP-06 manifest assumes RM_RELMAP_ID 7"); +StaticAssertDecl(RM_STANDBY_ID == 8, "STOP-06 manifest assumes RM_STANDBY_ID 8"); +StaticAssertDecl(RM_HEAP2_ID == 9, "STOP-06 manifest assumes RM_HEAP2_ID 9"); +StaticAssertDecl(RM_HEAP_ID == 10, "STOP-06 manifest assumes RM_HEAP_ID 10"); +StaticAssertDecl(RM_BTREE_ID == 11, "STOP-06 manifest assumes RM_BTREE_ID 11"); +StaticAssertDecl(RM_HASH_ID == 12, "STOP-06 manifest assumes RM_HASH_ID 12"); +StaticAssertDecl(RM_GIN_ID == 13, "STOP-06 manifest assumes RM_GIN_ID 13"); +StaticAssertDecl(RM_GIST_ID == 14, "STOP-06 manifest assumes RM_GIST_ID 14"); +StaticAssertDecl(RM_SEQ_ID == 15, "STOP-06 manifest assumes RM_SEQ_ID 15"); +StaticAssertDecl(RM_SPGIST_ID == 16, "STOP-06 manifest assumes RM_SPGIST_ID 16"); +StaticAssertDecl(RM_BRIN_ID == 17, "STOP-06 manifest assumes RM_BRIN_ID 17"); +StaticAssertDecl(RM_COMMIT_TS_ID == 18, "STOP-06 manifest assumes RM_COMMIT_TS_ID 18"); +StaticAssertDecl(RM_REPLORIGIN_ID == 19, "STOP-06 manifest assumes RM_REPLORIGIN_ID 19"); +StaticAssertDecl(RM_GENERIC_ID == 20, "STOP-06 manifest assumes RM_GENERIC_ID 20"); +StaticAssertDecl(RM_LOGICALMSG_ID == 21, "STOP-06 manifest assumes RM_LOGICALMSG_ID 21"); +StaticAssertDecl(RM_CLUSTER_UNDO_ID == 22, "STOP-06 manifest assumes RM_CLUSTER_UNDO_ID 22"); StaticAssertDecl(RM_CLUSTER_RAW_LAYOUT_ID == 23, "STOP-06 manifest assumes RM_CLUSTER_RAW_LAYOUT_ID 23"); -StaticAssertDecl(RM_CLUSTER_ADG_ID == 24, - "STOP-06 manifest assumes RM_CLUSTER_ADG_ID 24"); +StaticAssertDecl(RM_CLUSTER_ADG_ID == 24, "STOP-06 manifest assumes RM_CLUSTER_ADG_ID 24"); StaticAssertDecl(RM_CLUSTER_XID_STRIPE_ID == 25, "STOP-06 manifest assumes RM_CLUSTER_XID_STRIPE_ID 25"); -StaticAssertDecl(RM_N_BUILTIN_IDS == 26, - "STOP-06 manifest must cover exactly 26 built-in rmgrs"); +StaticAssertDecl(RM_N_BUILTIN_IDS == 26, "STOP-06 manifest must cover exactly 26 built-in rmgrs"); -enum -{ +enum { RF_OPCODE_ROUTE_MANIFEST_COUNT_V1 = 0 -#define RF_ROUTE(rmid_, info_, flags_, owner_, blocks_, codec_, active_, name_) + 1 +#define RF_ROUTE(rmid_, info_, flags_, owner_, blocks_, codec_, active_, name_) +1 #include "cluster/cluster_rf_route_manifest.def" #undef RF_ROUTE }; -enum -{ +enum { RF_OPCODE_ROUTE_MANIFEST_LIVE_COUNT_V1 = 0 -#define RF_ROUTE(rmid_, info_, flags_, owner_, blocks_, codec_, active_, name_) + ((active_) ? 1 : 0) +#define RF_ROUTE(rmid_, info_, flags_, owner_, blocks_, codec_, active_, name_) +((active_) ? 1 : 0) #include "cluster/cluster_rf_route_manifest.def" #undef RF_ROUTE }; @@ -97,8 +78,7 @@ StaticAssertDecl(RF_OPCODE_ROUTE_MANIFEST_COUNT_V1 == 138, "STOP-06 manifest must contain exactly 138 rows"); StaticAssertDecl(RF_OPCODE_ROUTE_MANIFEST_LIVE_COUNT_V1 == 138, "STOP-06 manifest must contain exactly 138 live rows"); -StaticAssertDecl(lengthof(rf_opcode_route_manifest_v1) == - RF_OPCODE_ROUTE_MANIFEST_COUNT_V1, +StaticAssertDecl(lengthof(rf_opcode_route_manifest_v1) == RF_OPCODE_ROUTE_MANIFEST_COUNT_V1, "STOP-06 generated table count must match manifest count"); size_t @@ -114,11 +94,9 @@ rf_opcode_route_manifest_live_count_v1(void) } bool -rf_opcode_route_manifest_entry_v1(size_t index, RfOpcodeRouteV1 *route, - bool *active) +rf_opcode_route_manifest_entry_v1(size_t index, RfOpcodeRouteV1 *route, bool *active) { - if (index >= lengthof(rf_opcode_route_manifest_v1) || - route == NULL || active == NULL) + if (index >= lengthof(rf_opcode_route_manifest_v1) || route == NULL || active == NULL) return false; *route = rf_opcode_route_manifest_v1[index].route; @@ -127,33 +105,27 @@ rf_opcode_route_manifest_entry_v1(size_t index, RfOpcodeRouteV1 *route, } RfOpcodeRouteLookupResultV1 -rf_opcode_route_lookup_v1(uint8 rmid, uint8 raw_info, bool has_blocks, - bool space_active, RfOpcodeRouteV1 *route) +rf_opcode_route_lookup_v1(uint8 rmid, uint8 raw_info, bool has_blocks, bool space_active, + RfOpcodeRouteV1 *route) { const RfOpcodeRouteManifestEntryV1 *entry = NULL; - uint8 normalized_info; - uint8 info_flags = 0; - size_t i; + uint8 normalized_info; + uint8 info_flags = 0; + size_t i; if (rmid >= RM_MIN_CUSTOM_ID || rmid >= RM_N_BUILTIN_IDS) return RF_OPCODE_ROUTE_RMID_UNSUPPORTED; - if (rmid == RM_XACT_ID) - { + if (rmid == RM_XACT_ID) { normalized_info = raw_info & XLOG_XACT_OPMASK; info_flags = raw_info & XLOG_XACT_HAS_INFO; - } - else + } else normalized_info = raw_info & ~XLR_INFO_MASK; - for (i = 0; i < lengthof(rf_opcode_route_manifest_v1); i++) - { - const RfOpcodeRouteManifestEntryV1 *candidate = - &rf_opcode_route_manifest_v1[i]; + for (i = 0; i < lengthof(rf_opcode_route_manifest_v1); i++) { + const RfOpcodeRouteManifestEntryV1 *candidate = &rf_opcode_route_manifest_v1[i]; - if (candidate->route.rmid == rmid && - candidate->route.normalized_info == normalized_info) - { + if (candidate->route.rmid == rmid && candidate->route.normalized_info == normalized_info) { entry = candidate; break; } @@ -165,10 +137,8 @@ rf_opcode_route_lookup_v1(uint8 rmid, uint8 raw_info, bool has_blocks, return RF_OPCODE_ROUTE_FLAG_ILLEGAL; if (!entry->active && !space_active) return RF_OPCODE_ROUTE_OPCODE_UNSUPPORTED; - if ((entry->route.block_policy == RF_ROUTE_BLOCKS_REQUIRED && - !has_blocks) || - (entry->route.block_policy == RF_ROUTE_BLOCKS_FORBIDDEN && - has_blocks)) + if ((entry->route.block_policy == RF_ROUTE_BLOCKS_REQUIRED && !has_blocks) + || (entry->route.block_policy == RF_ROUTE_BLOCKS_FORBIDDEN && has_blocks)) return RF_OPCODE_ROUTE_BLOCK_SHAPE_INVALID; if (route == NULL) return RF_OPCODE_ROUTE_NESTED_VALUE_INVALID; diff --git a/src/backend/cluster/cluster_runtime_visibility.c b/src/backend/cluster/cluster_runtime_visibility.c index 438f96dc428..2b1696b7ef7 100644 --- a/src/backend/cluster/cluster_runtime_visibility.c +++ b/src/backend/cluster/cluster_runtime_visibility.c @@ -79,8 +79,8 @@ #include "cluster/cluster_undo_record.h" #include "cluster/cluster_undo_record_api.h" #include "cluster/cluster_undo_segment.h" -#include "cluster/cluster_undo_verdict.h" /* verdict taxonomy + entry (D3-3/D3-4) */ -#include "cluster/cluster_undo_horizon.h" /* D5-8 read admission (spec-5.22e) */ +#include "cluster/cluster_undo_verdict.h" /* verdict taxonomy + entry (D3-3/D3-4) */ +#include "cluster/cluster_undo_horizon.h" /* D5-8 read admission (spec-5.22e) */ #include "cluster/cluster_xid_stripe.h" #include "cluster/storage/cluster_undo_block0_current.h" #include "cluster/storage/cluster_undo_buf.h" @@ -109,20 +109,17 @@ cluster_runtime_visibility_ensure_exit_hooks(void) * origin proof so a cutover cannot turn an epoch-zero syntax match into * authority. The caller owns cluster_semantic_activation_leave(). */ bool -cluster_runtime_visibility_zero_epoch_pair_admission_enter( - ClusterSemanticAdmissionToken *token) +cluster_runtime_visibility_zero_epoch_pair_admission_enter(ClusterSemanticAdmissionToken *token) { ClusterSemanticAdmissionResult result; if (token != NULL) memset(token, 0, sizeof(*token)); - if (token == NULL || cluster_conf_node_count() != 4 - || !cluster_storage_mode_enabled() || cluster_recmerge_window_active - || cluster_epoch_get_current() != 0) + if (token == NULL || cluster_conf_node_count() != 4 || !cluster_storage_mode_enabled() + || cluster_recmerge_window_active || cluster_epoch_get_current() != 0) return false; - result = cluster_semantic_activation_enter( - CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, - CLUSTER_SEMANTIC_TARGET_SIDE, token); + result = cluster_semantic_activation_enter(CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, + CLUSTER_SEMANTIC_TARGET_SIDE, token); if (result != CLUSTER_SEMANTIC_ADMISSION_OK) return false; if (token->record_generation == 0 || token->formation_epoch != 0 @@ -266,12 +263,12 @@ cluster_runtime_visibility_candidate_cleanup(int code, Datum arg) } static ClusterUndoBlock0CurrentStep -cluster_runtime_visibility_candidate_acquire_until( - const ClusterUndoBlock0LogicalKey *logical, - const ClusterSemanticAdmissionToken *admission, - ClusterUndoBlock0CurrentGuard *guard, - ClusterRuntimeCandidateCleanup *cleanup, - ClusterUndoBlock0Result *failure, TimestampTz deadline) +cluster_runtime_visibility_candidate_acquire_until(const ClusterUndoBlock0LogicalKey *logical, + const ClusterSemanticAdmissionToken *admission, + ClusterUndoBlock0CurrentGuard *guard, + ClusterRuntimeCandidateCleanup *cleanup, + ClusterUndoBlock0Result *failure, + TimestampTz deadline) { ClusterUndoBlock0CurrentStep step; int timeout_ms = 0; @@ -285,13 +282,12 @@ cluster_runtime_visibility_candidate_acquire_until( return CLUSTER_UNDO_BLOCK0_CURRENT_FAILED; } remaining_us = deadline - now; - timeout_ms = remaining_us / 1000 >= INT_MAX - ? INT_MAX : (int)Max((remaining_us + 999) / 1000, 1); + timeout_ms + = remaining_us / 1000 >= INT_MAX ? INT_MAX : (int)Max((remaining_us + 999) / 1000, 1); } step = cluster_undo_block0_current_acquire_begin_admitted( - logical, CLUSTER_UNDO_BLOCK0_SCUR, timeout_ms, admission, guard, - failure); + logical, CLUSTER_UNDO_BLOCK0_SCUR, timeout_ms, admission, guard, failure); if (cleanup != NULL && (step == CLUSTER_UNDO_BLOCK0_CURRENT_PENDING || step == CLUSTER_UNDO_BLOCK0_CURRENT_HELD)) @@ -312,8 +308,7 @@ cluster_runtime_visibility_candidate_acquire_until( guard, CLUSTER_UNDO_BLOCK0_WAIT_RUNTIME_VIS_ACQUIRE)) pg_usleep(1000L); } - if (step != CLUSTER_UNDO_BLOCK0_CURRENT_HELD - && cleanup != NULL && cleanup->active) { + if (step != CLUSTER_UNDO_BLOCK0_CURRENT_HELD && cleanup != NULL && cleanup->active) { cluster_undo_block0_current_cancel(guard); cleanup->active = false; } @@ -326,21 +321,20 @@ cluster_runtime_visibility_candidate_acquire_until( } static ClusterUndoBlock0CurrentStep -cluster_runtime_visibility_candidate_acquire( - const ClusterUndoBlock0LogicalKey *logical, - const ClusterSemanticAdmissionToken *admission, - ClusterUndoBlock0CurrentGuard *guard, - ClusterRuntimeCandidateCleanup *cleanup, - ClusterUndoBlock0Result *failure) +cluster_runtime_visibility_candidate_acquire(const ClusterUndoBlock0LogicalKey *logical, + const ClusterSemanticAdmissionToken *admission, + ClusterUndoBlock0CurrentGuard *guard, + ClusterRuntimeCandidateCleanup *cleanup, + ClusterUndoBlock0Result *failure) { - return cluster_runtime_visibility_candidate_acquire_until( - logical, admission, guard, cleanup, failure, 0); + return cluster_runtime_visibility_candidate_acquire_until(logical, admission, guard, cleanup, + failure, 0); } static ClusterUndoBlock0CurrentStep -cluster_runtime_visibility_candidate_release_until( - ClusterUndoBlock0CurrentGuard *guard, ClusterUndoBlock0Result *failure, - TimestampTz deadline) +cluster_runtime_visibility_candidate_release_until(ClusterUndoBlock0CurrentGuard *guard, + ClusterUndoBlock0Result *failure, + TimestampTz deadline) { ClusterUndoBlock0CurrentStep step; @@ -367,30 +361,27 @@ cluster_runtime_visibility_candidate_release_until( } static ClusterUndoBlock0CurrentStep -cluster_runtime_visibility_candidate_release( - ClusterUndoBlock0CurrentGuard *guard, ClusterUndoBlock0Result *failure) +cluster_runtime_visibility_candidate_release(ClusterUndoBlock0CurrentGuard *guard, + ClusterUndoBlock0Result *failure) { - return cluster_runtime_visibility_candidate_release_until( - guard, failure, 0); + return cluster_runtime_visibility_candidate_release_until(guard, failure, 0); } static bool -cluster_runtime_visibility_candidate_root_matches( - const ClusterUndoBlock0ResolvedRoot *left, - const ClusterUndoBlock0ResolvedRoot *right) +cluster_runtime_visibility_candidate_root_matches(const ClusterUndoBlock0ResolvedRoot *left, + const ClusterUndoBlock0ResolvedRoot *right) { return left != NULL && right != NULL && left->intent == right->intent - && left->root_id == right->root_id - && left->root_generation == right->root_generation; + && left->root_id == right->root_id && left->root_generation == right->root_generation; } static ClusterTxOutcome -cluster_runtime_visibility_candidate_decide( - const ClusterTxLocator *locator, ClusterTxResolveMode mode, - const TTSlot *exact_slot, - TransactionId *top_xid_out, ClusterTxProofKind *proof_kind_out, - SCN *commit_scn_out, ClusterTxResolveReason *reason_out, - ClusterRuntimeVisibilityCanonicalDiagnostic *diagnostic) +cluster_runtime_visibility_candidate_decide(const ClusterTxLocator *locator, + ClusterTxResolveMode mode, const TTSlot *exact_slot, + TransactionId *top_xid_out, + ClusterTxProofKind *proof_kind_out, SCN *commit_scn_out, + ClusterTxResolveReason *reason_out, + ClusterRuntimeVisibilityCanonicalDiagnostic *diagnostic) { XidStatus native_status; TransactionId top_xid = locator->xid; @@ -408,16 +399,13 @@ cluster_runtime_visibility_candidate_decide( } if (exact_slot->status > TT_SLOT_RECYCLABLE) { if (diagnostic != NULL) - diagnostic->first_failure - = CLUSTER_RUNTIME_VISIBILITY_CANONICAL_FAILURE_SLOT_DOMAIN; + diagnostic->first_failure = CLUSTER_RUNTIME_VISIBILITY_CANONICAL_FAILURE_SLOT_DOMAIN; *reason_out = CLUSTER_TX_RESOLVE_AUTHORITY_UNAVAILABLE; return CLUSTER_TX_UNKNOWN; } - if (exact_slot->xid != locator->xid - || exact_slot->wrap != locator->tt_wrap) { + if (exact_slot->xid != locator->xid || exact_slot->wrap != locator->tt_wrap) { if (diagnostic != NULL) - diagnostic->first_failure - = CLUSTER_RUNTIME_VISIBILITY_CANONICAL_FAILURE_SLOT_IDENTITY; + diagnostic->first_failure = CLUSTER_RUNTIME_VISIBILITY_CANONICAL_FAILURE_SLOT_IDENTITY; *reason_out = CLUSTER_TX_RESOLVE_AUTHORITY_UNAVAILABLE; return CLUSTER_TX_UNKNOWN; } @@ -430,13 +418,12 @@ cluster_runtime_visibility_candidate_decide( if (native_status == TRANSACTION_STATUS_SUB_COMMITTED) { ClusterRuntimeSubtransSample subtrans; - if (!cluster_runtime_visibility_sample_subtrans( - locator->xid, &subtrans, reason_out)) + if (!cluster_runtime_visibility_sample_subtrans(locator->xid, &subtrans, reason_out)) return CLUSTER_TX_UNKNOWN; top_xid = subtrans.xids[subtrans.count - 1]; native_status = cluster_runtime_visibility_direct_xid_status(top_xid); - native_status = cluster_runtime_visibility_recheck_prepared( - top_xid, native_status, &prepared); + native_status + = cluster_runtime_visibility_recheck_prepared(top_xid, native_status, &prepared); if (diagnostic != NULL) { diagnostic->prepared_sampled = true; diagnostic->prepared = prepared; @@ -447,13 +434,13 @@ cluster_runtime_visibility_candidate_decide( proof_kind = CLUSTER_TX_PROOF_ORIGIN_SUBTRANS_TOP; if (native_status == TRANSACTION_STATUS_COMMITTED) { *reason_out = exact_slot->status == TT_SLOT_ABORTED - ? CLUSTER_TX_RESOLVE_AUTHORITY_CONFLICT - : CLUSTER_TX_RESOLVE_COVERAGE_GAP; + ? CLUSTER_TX_RESOLVE_AUTHORITY_CONFLICT + : CLUSTER_TX_RESOLVE_COVERAGE_GAP; return CLUSTER_TX_UNKNOWN; } } else if (native_status == TRANSACTION_STATUS_IN_PROGRESS) { - native_status = cluster_runtime_visibility_recheck_prepared( - locator->xid, native_status, &prepared); + native_status + = cluster_runtime_visibility_recheck_prepared(locator->xid, native_status, &prepared); if (diagnostic != NULL) { diagnostic->prepared_sampled = true; diagnostic->prepared = prepared; @@ -478,8 +465,7 @@ cluster_runtime_visibility_candidate_decide( *reason_out = CLUSTER_TX_RESOLVE_AUTHORITY_CONFLICT; return CLUSTER_TX_UNKNOWN; } - if (exact_slot->status != TT_SLOT_COMMITTED - || !SCN_VALID(exact_slot->commit_scn)) { + if (exact_slot->status != TT_SLOT_COMMITTED || !SCN_VALID(exact_slot->commit_scn)) { *reason_out = CLUSTER_TX_RESOLVE_COVERAGE_GAP; return CLUSTER_TX_UNKNOWN; } @@ -491,8 +477,7 @@ cluster_runtime_visibility_candidate_decide( } if (native_status == TRANSACTION_STATUS_IN_PROGRESS) { if (prepared - && (exact_slot->status == TT_SLOT_ACTIVE - || exact_slot->status == TT_SLOT_ABORTED)) { + && (exact_slot->status == TT_SLOT_ACTIVE || exact_slot->status == TT_SLOT_ABORTED)) { *top_xid_out = top_xid; *proof_kind_out = proof_kind; *commit_scn_out = InvalidScn; @@ -510,16 +495,14 @@ cluster_runtime_visibility_candidate_decide( } if (diagnostic != NULL) - diagnostic->first_failure - = CLUSTER_RUNTIME_VISIBILITY_CANONICAL_FAILURE_NATIVE_OUTCOME; + diagnostic->first_failure = CLUSTER_RUNTIME_VISIBILITY_CANONICAL_FAILURE_NATIVE_OUTCOME; *reason_out = CLUSTER_TX_RESOLVE_AUTHORITY_UNAVAILABLE; return CLUSTER_TX_UNKNOWN; } static bool -cluster_runtime_visibility_admission_current( - ClusterTxResolveMode mode, - const ClusterSemanticAdmissionToken *admission) +cluster_runtime_visibility_admission_current(ClusterTxResolveMode mode, + const ClusterSemanticAdmissionToken *admission) { if (mode == CLUSTER_TX_RESOLVE_VISIBILITY) return cluster_semantic_activation_recheck(admission); @@ -529,11 +512,11 @@ cluster_runtime_visibility_admission_current( } static bool -cluster_runtime_visibility_resolve_root_admitted( - ClusterTxResolveMode mode, - const ClusterSemanticAdmissionToken *admission, ClusterUndoPathIntent intent, - uint32 owner_instance, uint32 segment_id, - ClusterUndoBlock0ResolvedRoot *out) +cluster_runtime_visibility_resolve_root_admitted(ClusterTxResolveMode mode, + const ClusterSemanticAdmissionToken *admission, + ClusterUndoPathIntent intent, + uint32 owner_instance, uint32 segment_id, + ClusterUndoBlock0ResolvedRoot *out) { if (mode == CLUSTER_TX_RESOLVE_VISIBILITY) return cluster_semantic_activation_resolve_shared_undo_root( @@ -545,16 +528,14 @@ cluster_runtime_visibility_resolve_root_admitted( } static bool -cluster_runtime_visibility_current_owner_shape_valid( - TransactionId xid, const ClusterTTSlotCurrentOwner *owner) -{ - if (owner == NULL || cluster_node_id < 0 - || cluster_node_id >= CLUSTER_MAX_NODES - || !TransactionIdIsNormal(xid) || owner->xid != xid - || owner->segment_id == 0 || owner->segment_id > UINT16_MAX - || owner->slot_offset >= TT_SLOTS_PER_SEGMENT - || owner->wrap == TT_WRAP_INVALID || owner->reserved8[0] != 0 - || owner->reserved8[1] != 0 || owner->reserved8[2] != 0) +cluster_runtime_visibility_current_owner_shape_valid(TransactionId xid, + const ClusterTTSlotCurrentOwner *owner) +{ + if (owner == NULL || cluster_node_id < 0 || cluster_node_id >= CLUSTER_MAX_NODES + || !TransactionIdIsNormal(xid) || owner->xid != xid || owner->segment_id == 0 + || owner->segment_id > UINT16_MAX || owner->slot_offset >= TT_SLOTS_PER_SEGMENT + || owner->wrap == TT_WRAP_INVALID || owner->reserved8[0] != 0 || owner->reserved8[1] != 0 + || owner->reserved8[2] != 0) return false; switch ((ClusterTTSlotAllocStatus)owner->status) { case CTS_ACTIVE: @@ -569,30 +550,25 @@ cluster_runtime_visibility_current_owner_shape_valid( } static bool -cluster_runtime_visibility_current_owner_slot_matches( - const ClusterTTSlotCurrentOwner *owner, const TTSlot *slot, - ClusterTxOutcome outcome, SCN commit_scn) +cluster_runtime_visibility_current_owner_slot_matches(const ClusterTTSlotCurrentOwner *owner, + const TTSlot *slot, ClusterTxOutcome outcome, + SCN commit_scn) { - if (owner == NULL || slot == NULL || slot->xid != owner->xid - || slot->wrap != owner->wrap) + if (owner == NULL || slot == NULL || slot->xid != owner->xid || slot->wrap != owner->wrap) return false; switch ((ClusterTTSlotAllocStatus)owner->status) { case CTS_ACTIVE: return outcome == CLUSTER_TX_IN_PROGRESS - && (slot->status == TT_SLOT_ACTIVE - || (slot->status == TT_SLOT_COMMITTED - && SCN_VALID(slot->commit_scn))) - && commit_scn == InvalidScn; + && (slot->status == TT_SLOT_ACTIVE + || (slot->status == TT_SLOT_COMMITTED && SCN_VALID(slot->commit_scn))) + && commit_scn == InvalidScn; case CTS_COMMITTED: - return outcome == CLUSTER_TX_COMMITTED - && slot->status == TT_SLOT_COMMITTED - && SCN_VALID(commit_scn) - && commit_scn == slot->commit_scn - && commit_scn == owner->commit_scn; + return outcome == CLUSTER_TX_COMMITTED && slot->status == TT_SLOT_COMMITTED + && SCN_VALID(commit_scn) && commit_scn == slot->commit_scn + && commit_scn == owner->commit_scn; case CTS_ABORTED: - return outcome == CLUSTER_TX_ABORTED - && slot->status == TT_SLOT_ABORTED - && commit_scn == InvalidScn; + return outcome == CLUSTER_TX_ABORTED && slot->status == TT_SLOT_ABORTED + && commit_scn == InvalidScn; case CTS_FREE: break; } @@ -600,51 +576,41 @@ cluster_runtime_visibility_current_owner_slot_matches( } static bool -cluster_runtime_visibility_physical_locator_shape_valid( - const ClusterTTSlotPhysicalLocator *locator) +cluster_runtime_visibility_physical_locator_shape_valid(const ClusterTTSlotPhysicalLocator *locator) { - return locator != NULL && cluster_node_id >= 0 - && cluster_node_id < CLUSTER_MAX_NODES - && locator->segment_id > 0 && locator->segment_id <= UINT16_MAX - && TransactionIdIsNormal(locator->xid) - && locator->slot_offset < TT_SLOTS_PER_SEGMENT - && locator->wrap != TT_WRAP_INVALID && locator->reserved32 == 0; + return locator != NULL && cluster_node_id >= 0 && cluster_node_id < CLUSTER_MAX_NODES + && locator->segment_id > 0 && locator->segment_id <= UINT16_MAX + && TransactionIdIsNormal(locator->xid) && locator->slot_offset < TT_SLOTS_PER_SEGMENT + && locator->wrap != TT_WRAP_INVALID && locator->reserved32 == 0; } static bool cluster_runtime_visibility_physical_locator_owner_matches( - const ClusterTTSlotPhysicalLocator *locator, - const ClusterTTSlotCurrentOwner *owner) + const ClusterTTSlotPhysicalLocator *locator, const ClusterTTSlotCurrentOwner *owner) { - return locator != NULL && owner != NULL - && locator->segment_id == owner->segment_id - && locator->xid == owner->xid - && locator->slot_offset == owner->slot_offset - && locator->wrap == owner->wrap - && cluster_runtime_visibility_current_owner_shape_valid( - locator->xid, owner); + return locator != NULL && owner != NULL && locator->segment_id == owner->segment_id + && locator->xid == owner->xid && locator->slot_offset == owner->slot_offset + && locator->wrap == owner->wrap + && cluster_runtime_visibility_current_owner_shape_valid(locator->xid, owner); } static bool cluster_runtime_visibility_physical_locator_slot_matches( - const ClusterTTSlotPhysicalLocator *locator, const TTSlot *slot, - ClusterTxOutcome outcome, SCN commit_scn) + const ClusterTTSlotPhysicalLocator *locator, const TTSlot *slot, ClusterTxOutcome outcome, + SCN commit_scn) { - if (locator == NULL || slot == NULL || slot->xid != locator->xid - || slot->wrap != locator->wrap) + if (locator == NULL || slot == NULL || slot->xid != locator->xid || slot->wrap != locator->wrap) return false; switch (outcome) { case CLUSTER_TX_IN_PROGRESS: return commit_scn == InvalidScn - && (slot->status == TT_SLOT_ACTIVE - || (slot->status == TT_SLOT_COMMITTED - && SCN_VALID(slot->commit_scn))); + && (slot->status == TT_SLOT_ACTIVE + || (slot->status == TT_SLOT_COMMITTED && SCN_VALID(slot->commit_scn))); case CLUSTER_TX_COMMITTED: - return slot->status == TT_SLOT_COMMITTED - && SCN_VALID(commit_scn) && commit_scn == slot->commit_scn; + return slot->status == TT_SLOT_COMMITTED && SCN_VALID(commit_scn) + && commit_scn == slot->commit_scn; case CLUSTER_TX_ABORTED: - return slot->status == TT_SLOT_ABORTED - && commit_scn == InvalidScn; + return slot->status == TT_SLOT_ABORTED && commit_scn == InvalidScn; case CLUSTER_TX_UNKNOWN: case CLUSTER_TX_PREPARED: break; @@ -654,12 +620,9 @@ cluster_runtime_visibility_physical_locator_slot_matches( bool cluster_runtime_visibility_physical_locator_sample_held( - const ClusterTTSlotPhysicalLocator *locator, - const ClusterSemanticAdmissionToken *admission, - ClusterUndoBlock0CurrentGuard *guard, - const ClusterUndoBlock0ResolvedRoot *root, - ClusterTTStatusKey *key_out, ClusterTTStatusResult *result_out, - bool *ctrc_physical_active_out) + const ClusterTTSlotPhysicalLocator *locator, const ClusterSemanticAdmissionToken *admission, + ClusterUndoBlock0CurrentGuard *guard, const ClusterUndoBlock0ResolvedRoot *root, + ClusterTTStatusKey *key_out, ClusterTTStatusResult *result_out, bool *ctrc_physical_active_out) { ClusterUndoBlock0Generation generation = { false, 0 }; ClusterUndoBlock0Generation final_generation = { false, 0 }; @@ -695,12 +658,10 @@ cluster_runtime_visibility_physical_locator_sample_held( memset(¤t_owner, 0, sizeof(current_owner)); memset(&final_owner, 0, sizeof(final_owner)); memset(&tx_locator, 0, sizeof(tx_locator)); - if (key_out == NULL || result_out == NULL || admission == NULL - || guard == NULL || root == NULL + if (key_out == NULL || result_out == NULL || admission == NULL || guard == NULL || root == NULL || root->intent != CLUSTER_UNDO_PATH_RUNTIME_SHARED || !cluster_runtime_visibility_physical_locator_shape_valid(locator) - || !cluster_runtime_visibility_admission_current( - CLUSTER_TX_RESOLVE_VISIBILITY, admission)) + || !cluster_runtime_visibility_admission_current(CLUSTER_TX_RESOLVE_VISIBILITY, admission)) return false; epoch = cluster_epoch_get_current(); if (epoch > UINT32_MAX || admission->formation_epoch != epoch) @@ -714,67 +675,61 @@ cluster_runtime_visibility_physical_locator_sample_held( return false; current_allocator_exact = current_segment == locator->segment_id; if (current_allocator_exact) { - current_owner_found = cluster_tt_slot_current_owner_by_xid( - cluster_node_id, locator->xid, ¤t_owner); + current_owner_found + = cluster_tt_slot_current_owner_by_xid(cluster_node_id, locator->xid, ¤t_owner); if (current_owner_found - && !cluster_runtime_visibility_physical_locator_owner_matches( - locator, ¤t_owner)) + && !cluster_runtime_visibility_physical_locator_owner_matches(locator, ¤t_owner)) return false; } - if (cluster_undo_block0_current_sample_generation( - guard, root, &generation) != CLUSTER_UNDO_BLOCK0_OK + if (cluster_undo_block0_current_sample_generation(guard, root, &generation) + != CLUSTER_UNDO_BLOCK0_OK || !generation.known || generation.value == UINT32_MAX - || cluster_undo_block0_current_copy_resident( - guard, root, &generation, block0.data) != CLUSTER_UNDO_BLOCK0_OK) + || cluster_undo_block0_current_copy_resident(guard, root, &generation, block0.data) + != CLUSTER_UNDO_BLOCK0_OK) return false; header = (const UndoSegmentHeaderData *)block0.data; exact_slot = header->tt_slots[locator->slot_offset]; tx_locator.xid = locator->xid; tx_locator.tt_wrap = locator->wrap; outcome = cluster_runtime_visibility_candidate_decide( - &tx_locator, CLUSTER_TX_RESOLVE_VISIBILITY, &exact_slot, &top_xid, - &proof_kind, &commit_scn, &reason, NULL); - if (outcome == CLUSTER_TX_UNKNOWN || outcome == CLUSTER_TX_PREPARED - || top_xid != locator->xid + &tx_locator, CLUSTER_TX_RESOLVE_VISIBILITY, &exact_slot, &top_xid, &proof_kind, &commit_scn, + &reason, NULL); + if (outcome == CLUSTER_TX_UNKNOWN || outcome == CLUSTER_TX_PREPARED || top_xid != locator->xid || !cluster_tx_outcome_proof_is_valid(outcome, proof_kind) - || !cluster_runtime_visibility_physical_locator_slot_matches( - locator, &exact_slot, outcome, commit_scn) + || !cluster_runtime_visibility_physical_locator_slot_matches(locator, &exact_slot, outcome, + commit_scn) || (current_allocator_exact && ((outcome == CLUSTER_TX_IN_PROGRESS && !current_owner_found) || (current_owner_found && !cluster_runtime_visibility_current_owner_slot_matches( ¤t_owner, &exact_slot, outcome, commit_scn)))) - || cluster_undo_block0_current_sample_generation( - guard, root, &final_generation) != CLUSTER_UNDO_BLOCK0_OK - || !final_generation.known - || final_generation.value != generation.value) + || cluster_undo_block0_current_sample_generation(guard, root, &final_generation) + != CLUSTER_UNDO_BLOCK0_OK + || !final_generation.known || final_generation.value != generation.value) return false; final_current_segment = cluster_tt_slot_current_segment(cluster_node_id); if (final_current_segment != current_segment) return false; if (current_allocator_exact) { - final_owner_found = cluster_tt_slot_current_owner_by_xid( - cluster_node_id, locator->xid, &final_owner); + final_owner_found + = cluster_tt_slot_current_owner_by_xid(cluster_node_id, locator->xid, &final_owner); if (final_owner_found != current_owner_found || (current_owner_found && memcmp(&final_owner, ¤t_owner, sizeof(final_owner)) != 0)) return false; } if (!cluster_runtime_visibility_resolve_root_admitted( - CLUSTER_TX_RESOLVE_VISIBILITY, admission, - CLUSTER_UNDO_PATH_RUNTIME_SHARED, + CLUSTER_TX_RESOLVE_VISIBILITY, admission, CLUSTER_UNDO_PATH_RUNTIME_SHARED, (uint32)cluster_node_id + 1, locator->segment_id, &final_root) || !cluster_runtime_visibility_candidate_root_matches(root, &final_root) - || !cluster_runtime_visibility_admission_current( - CLUSTER_TX_RESOLVE_VISIBILITY, admission)) + || !cluster_runtime_visibility_admission_current(CLUSTER_TX_RESOLVE_VISIBILITY, admission)) return false; key_out->origin_node_id = (uint16)cluster_node_id; key_out->undo_segment_id = (uint16)locator->segment_id; - key_out->tt_slot_id - = cluster_tt_slot_offset_to_id(locator->slot_offset); + key_out->tt_slot_id = cluster_tt_slot_offset_to_id(locator->slot_offset); key_out->cluster_epoch = (uint32)epoch; key_out->local_xid = locator->xid; result_out->status_epoch = (uint32)epoch; @@ -795,28 +750,23 @@ cluster_runtime_visibility_physical_locator_sample_held( return false; } if (ctrc_physical_active_out != NULL) - *ctrc_physical_active_out = exact_slot.xid == locator->xid - && exact_slot.wrap == locator->wrap - && exact_slot.status == TT_SLOT_ACTIVE - && exact_slot.commit_scn == InvalidScn; + *ctrc_physical_active_out + = exact_slot.xid == locator->xid && exact_slot.wrap == locator->wrap + && exact_slot.status == TT_SLOT_ACTIVE && exact_slot.commit_scn == InvalidScn; return true; } static bool cluster_runtime_visibility_current_owner_from_local_binding( - TransactionId xid, const ClusterCanonicalTxnBinding *binding, - ClusterTTSlotCurrentOwner *owner) + TransactionId xid, const ClusterCanonicalTxnBinding *binding, ClusterTTSlotCurrentOwner *owner) { if (binding == NULL || owner == NULL || cluster_node_id < 0 - || cluster_node_id >= CLUSTER_MAX_NODES - || binding->segment_id == 0 || binding->segment_id > UINT16_MAX - || binding->segment_generation == UINT32_MAX - || binding->xid != xid - || binding->slot_offset >= TT_SLOTS_PER_SEGMENT + || cluster_node_id >= CLUSTER_MAX_NODES || binding->segment_id == 0 + || binding->segment_id > UINT16_MAX || binding->segment_generation == UINT32_MAX + || binding->xid != xid || binding->slot_offset >= TT_SLOTS_PER_SEGMENT || binding->slot_wrap == TT_WRAP_INVALID || binding->origin_instance != (uint8)((uint32)cluster_node_id + 1) - || binding->publish_state != CLUSTER_CANONICAL_TXN_PUBLISHED - || binding->reserved16 != 0 + || binding->publish_state != CLUSTER_CANONICAL_TXN_PUBLISHED || binding->reserved16 != 0 || XLogRecPtrIsInvalid(binding->active_lsn)) return false; @@ -831,36 +781,31 @@ cluster_runtime_visibility_current_owner_from_local_binding( } static bool -cluster_runtime_visibility_current_owner_recheck( - TransactionId xid, const ClusterTTSlotCurrentOwner *expected_owner, - const ClusterCanonicalTxnBinding *expected_binding) +cluster_runtime_visibility_current_owner_recheck(TransactionId xid, + const ClusterTTSlotCurrentOwner *expected_owner, + const ClusterCanonicalTxnBinding *expected_binding) { ClusterTTSlotCurrentOwner final_owner; memset(&final_owner, 0, sizeof(final_owner)); - if (expected_binding != NULL) - { + if (expected_binding != NULL) { ClusterCanonicalTxnBinding final_binding; memset(&final_binding, 0, sizeof(final_binding)); if (!cluster_tt_local_get_published_binding(xid, &final_binding) || final_binding.segment_id != expected_binding->segment_id - || final_binding.segment_generation - != expected_binding->segment_generation + || final_binding.segment_generation != expected_binding->segment_generation || final_binding.xid != expected_binding->xid || final_binding.slot_offset != expected_binding->slot_offset || final_binding.slot_wrap != expected_binding->slot_wrap - || final_binding.origin_instance - != expected_binding->origin_instance + || final_binding.origin_instance != expected_binding->origin_instance || final_binding.publish_state != expected_binding->publish_state || final_binding.reserved16 != expected_binding->reserved16 || final_binding.active_lsn != expected_binding->active_lsn - || !cluster_runtime_visibility_current_owner_from_local_binding( - xid, &final_binding, &final_owner)) + || !cluster_runtime_visibility_current_owner_from_local_binding(xid, &final_binding, + &final_owner)) return false; - } - else if (!cluster_tt_slot_current_owner_by_xid( - cluster_node_id, xid, &final_owner)) + } else if (!cluster_tt_slot_current_owner_by_xid(cluster_node_id, xid, &final_owner)) return false; return memcmp(&final_owner, expected_owner, sizeof(final_owner)) == 0; @@ -870,11 +815,9 @@ static bool cluster_runtime_visibility_current_owner_sample_held_internal( TransactionId xid, const ClusterTTSlotCurrentOwner *expected_owner, const ClusterCanonicalTxnBinding *expected_binding, - const ClusterSemanticAdmissionToken *admission, - ClusterUndoBlock0CurrentGuard *guard, - const ClusterUndoBlock0ResolvedRoot *root, - ClusterTTStatusKey *key_out, ClusterTTStatusResult *result_out, - bool *ctrc_physical_active_out) + const ClusterSemanticAdmissionToken *admission, ClusterUndoBlock0CurrentGuard *guard, + const ClusterUndoBlock0ResolvedRoot *root, ClusterTTStatusKey *key_out, + ClusterTTStatusResult *result_out, bool *ctrc_physical_active_out) { ClusterUndoBlock0Generation generation; ClusterUndoBlock0Generation final_generation; @@ -903,57 +846,46 @@ cluster_runtime_visibility_current_owner_sample_held_internal( memset(&final_generation, 0, sizeof(final_generation)); memset(&final_root, 0, sizeof(final_root)); memset(&locator, 0, sizeof(locator)); - if (key_out == NULL || result_out == NULL || admission == NULL - || guard == NULL || root == NULL + if (key_out == NULL || result_out == NULL || admission == NULL || guard == NULL || root == NULL || root->intent != CLUSTER_UNDO_PATH_RUNTIME_SHARED - || !cluster_runtime_visibility_current_owner_shape_valid( - xid, expected_owner) - || !cluster_runtime_visibility_admission_current( - CLUSTER_TX_RESOLVE_VISIBILITY, admission)) + || !cluster_runtime_visibility_current_owner_shape_valid(xid, expected_owner) + || !cluster_runtime_visibility_admission_current(CLUSTER_TX_RESOLVE_VISIBILITY, admission)) return false; epoch = cluster_epoch_get_current(); if (epoch > UINT32_MAX || admission->formation_epoch != epoch) return false; - if (cluster_undo_block0_current_sample_generation( - guard, root, &generation) != CLUSTER_UNDO_BLOCK0_OK + if (cluster_undo_block0_current_sample_generation(guard, root, &generation) + != CLUSTER_UNDO_BLOCK0_OK || !generation.known || generation.value == UINT32_MAX - || (expected_binding != NULL - && generation.value != expected_binding->segment_generation) - || cluster_undo_block0_current_copy_resident( - guard, root, &generation, block0.data) != CLUSTER_UNDO_BLOCK0_OK) + || (expected_binding != NULL && generation.value != expected_binding->segment_generation) + || cluster_undo_block0_current_copy_resident(guard, root, &generation, block0.data) + != CLUSTER_UNDO_BLOCK0_OK) return false; header = (const UndoSegmentHeaderData *)block0.data; exact_slot = header->tt_slots[expected_owner->slot_offset]; locator.xid = xid; locator.tt_wrap = expected_owner->wrap; - outcome = cluster_runtime_visibility_candidate_decide( - &locator, CLUSTER_TX_RESOLVE_VISIBILITY, &exact_slot, &top_xid, - &proof_kind, &commit_scn, &reason, NULL); - if (outcome == CLUSTER_TX_UNKNOWN || outcome == CLUSTER_TX_PREPARED - || top_xid != xid + outcome = cluster_runtime_visibility_candidate_decide(&locator, CLUSTER_TX_RESOLVE_VISIBILITY, + &exact_slot, &top_xid, &proof_kind, + &commit_scn, &reason, NULL); + if (outcome == CLUSTER_TX_UNKNOWN || outcome == CLUSTER_TX_PREPARED || top_xid != xid || !cluster_tx_outcome_proof_is_valid(outcome, proof_kind) - || !cluster_runtime_visibility_current_owner_slot_matches( - expected_owner, &exact_slot, outcome, commit_scn) - || cluster_undo_block0_current_sample_generation( - guard, root, &final_generation) != CLUSTER_UNDO_BLOCK0_OK - || !final_generation.known - || final_generation.value != generation.value - || !cluster_runtime_visibility_current_owner_recheck( - xid, expected_owner, expected_binding) + || !cluster_runtime_visibility_current_owner_slot_matches(expected_owner, &exact_slot, + outcome, commit_scn) + || cluster_undo_block0_current_sample_generation(guard, root, &final_generation) + != CLUSTER_UNDO_BLOCK0_OK + || !final_generation.known || final_generation.value != generation.value + || !cluster_runtime_visibility_current_owner_recheck(xid, expected_owner, expected_binding) || !cluster_runtime_visibility_resolve_root_admitted( - CLUSTER_TX_RESOLVE_VISIBILITY, admission, - CLUSTER_UNDO_PATH_RUNTIME_SHARED, - (uint32)cluster_node_id + 1, expected_owner->segment_id, - &final_root) + CLUSTER_TX_RESOLVE_VISIBILITY, admission, CLUSTER_UNDO_PATH_RUNTIME_SHARED, + (uint32)cluster_node_id + 1, expected_owner->segment_id, &final_root) || !cluster_runtime_visibility_candidate_root_matches(root, &final_root) - || !cluster_runtime_visibility_admission_current( - CLUSTER_TX_RESOLVE_VISIBILITY, admission)) + || !cluster_runtime_visibility_admission_current(CLUSTER_TX_RESOLVE_VISIBILITY, admission)) return false; key_out->origin_node_id = (uint16)cluster_node_id; key_out->undo_segment_id = (uint16)expected_owner->segment_id; - key_out->tt_slot_id - = cluster_tt_slot_offset_to_id(expected_owner->slot_offset); + key_out->tt_slot_id = cluster_tt_slot_offset_to_id(expected_owner->slot_offset); key_out->cluster_epoch = (uint32)epoch; key_out->local_xid = xid; result_out->status_epoch = (uint32)epoch; @@ -974,21 +906,18 @@ cluster_runtime_visibility_current_owner_sample_held_internal( return false; } if (ctrc_physical_active_out != NULL) - *ctrc_physical_active_out = exact_slot.xid == xid - && exact_slot.wrap == expected_owner->wrap - && exact_slot.status == TT_SLOT_ACTIVE - && exact_slot.commit_scn == InvalidScn; + *ctrc_physical_active_out = exact_slot.xid == xid && exact_slot.wrap == expected_owner->wrap + && exact_slot.status == TT_SLOT_ACTIVE + && exact_slot.commit_scn == InvalidScn; return true; } bool cluster_runtime_visibility_current_owner_sample_held( TransactionId xid, const ClusterTTSlotCurrentOwner *expected_owner, - const ClusterSemanticAdmissionToken *admission, - ClusterUndoBlock0CurrentGuard *guard, - const ClusterUndoBlock0ResolvedRoot *root, - ClusterTTStatusKey *key_out, ClusterTTStatusResult *result_out, - bool *ctrc_physical_active_out) + const ClusterSemanticAdmissionToken *admission, ClusterUndoBlock0CurrentGuard *guard, + const ClusterUndoBlock0ResolvedRoot *root, ClusterTTStatusKey *key_out, + ClusterTTStatusResult *result_out, bool *ctrc_physical_active_out) { return cluster_runtime_visibility_current_owner_sample_held_internal( xid, expected_owner, NULL, admission, guard, root, key_out, result_out, @@ -996,29 +925,25 @@ cluster_runtime_visibility_current_owner_sample_held( } static bool -cluster_runtime_visibility_ctrc_key_fill( - const ClusterTTSlotCurrentOwner *owner, - const ClusterUndoBlock0Generation *generation, - const ClusterUndoBlock0ResolvedRoot *root, - const ClusterSemanticAdmissionToken *admission, - ClusterCtrcTxnKeyV1 *key) +cluster_runtime_visibility_ctrc_key_fill(const ClusterTTSlotCurrentOwner *owner, + const ClusterUndoBlock0Generation *generation, + const ClusterUndoBlock0ResolvedRoot *root, + const ClusterSemanticAdmissionToken *admission, + ClusterCtrcTxnKeyV1 *key) { uint64 epoch; uint64 boot_incarnation; uint64 system_identifier; - if (owner == NULL || generation == NULL || root == NULL - || admission == NULL || key == NULL || cluster_node_id < 0 - || cluster_node_id >= CLUSTER_CTRC_MAX_PARTICIPANTS + if (owner == NULL || generation == NULL || root == NULL || admission == NULL || key == NULL + || cluster_node_id < 0 || cluster_node_id >= CLUSTER_CTRC_MAX_PARTICIPANTS || !generation->known || generation->value == UINT32_MAX - || admission->record_generation == 0 - || root->root_id == 0 || root->root_generation == 0) + || admission->record_generation == 0 || root->root_id == 0 || root->root_generation == 0) return false; epoch = cluster_epoch_get_current(); boot_incarnation = cluster_qvotec_get_self_incarnation(); system_identifier = GetSystemIdentifier(); - if (epoch > UINT32_MAX || boot_incarnation == 0 - || system_identifier == 0 + if (epoch > UINT32_MAX || boot_incarnation == 0 || system_identifier == 0 || admission->formation_epoch != epoch) return false; @@ -1044,9 +969,8 @@ cluster_runtime_visibility_ctrc_key_fill( static bool cluster_runtime_visibility_current_owner_lookup_internal( - TransactionId xid, ClusterTTStatusKey *key_out, - ClusterTTStatusResult *result_out, bool ctrc_required, - uint32 *ctrc_grant_out, ClusterCtrcTxnKeyV1 *ctrc_key_out, + TransactionId xid, ClusterTTStatusKey *key_out, ClusterTTStatusResult *result_out, + bool ctrc_required, uint32 *ctrc_grant_out, ClusterCtrcTxnKeyV1 *ctrc_key_out, ClusterCtrcParticipantIdentity *participant_out) { ClusterSemanticAdmissionToken admission; @@ -1089,96 +1013,80 @@ cluster_runtime_visibility_current_owner_lookup_internal( memset(&participant, 0, sizeof(participant)); memset(&local_binding, 0, sizeof(local_binding)); if (key_out == NULL || result_out == NULL || cluster_node_id < 0 - || cluster_node_id >= CLUSTER_MAX_NODES - || (ctrc_required && ctrc_grant_out == NULL) + || cluster_node_id >= CLUSTER_MAX_NODES || (ctrc_required && ctrc_grant_out == NULL) || cluster_xid_origin_slot(xid) != cluster_node_id - || cluster_semantic_activation_enter( - CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, - CLUSTER_SEMANTIC_TARGET_SIDE, &admission) - != CLUSTER_SEMANTIC_ADMISSION_OK) + || cluster_semantic_activation_enter(CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, + CLUSTER_SEMANTIC_TARGET_SIDE, &admission) + != CLUSTER_SEMANTIC_ADMISSION_OK) return false; - if (cluster_tt_local_get_published_binding(xid, &local_binding)) - { - if (!cluster_runtime_visibility_current_owner_from_local_binding( - xid, &local_binding, &owner)) + if (cluster_tt_local_get_published_binding(xid, &local_binding)) { + if (!cluster_runtime_visibility_current_owner_from_local_binding(xid, &local_binding, + &owner)) goto done; expected_binding = &local_binding; - } - else if (!cluster_tt_slot_current_owner_by_xid( - cluster_node_id, xid, &owner) - || !cluster_runtime_visibility_current_owner_shape_valid(xid, &owner)) + } else if (!cluster_tt_slot_current_owner_by_xid(cluster_node_id, xid, &owner) + || !cluster_runtime_visibility_current_owner_shape_valid(xid, &owner)) goto done; logical.owner_instance = (uint8)((uint32)cluster_node_id + 1); logical.segment_id = owner.segment_id; if (!cluster_runtime_visibility_resolve_root_admitted( - CLUSTER_TX_RESOLVE_VISIBILITY, &admission, - CLUSTER_UNDO_PATH_RUNTIME_SHARED, logical.owner_instance, - logical.segment_id, &root) - || !cluster_runtime_visibility_admission_current( - CLUSTER_TX_RESOLVE_VISIBILITY, &admission)) + CLUSTER_TX_RESOLVE_VISIBILITY, &admission, CLUSTER_UNDO_PATH_RUNTIME_SHARED, + logical.owner_instance, logical.segment_id, &root) + || !cluster_runtime_visibility_admission_current(CLUSTER_TX_RESOLVE_VISIBILITY, &admission)) goto done; cluster_runtime_visibility_ensure_exit_hooks(); PG_ENSURE_ERROR_CLEANUP(cluster_runtime_visibility_candidate_cleanup, - PointerGetDatum(&cleanup)); + PointerGetDatum(&cleanup)); { - if (cluster_runtime_visibility_candidate_acquire( - &logical, &admission, &guard, &cleanup, ¤t_result) + if (cluster_runtime_visibility_candidate_acquire(&logical, &admission, &guard, &cleanup, + ¤t_result) == CLUSTER_UNDO_BLOCK0_CURRENT_HELD) sampled = cluster_runtime_visibility_current_owner_sample_held_internal( - xid, &owner, expected_binding, &admission, &guard, &root, - key_out, result_out, &ctrc_physical_active); + xid, &owner, expected_binding, &admission, &guard, &root, key_out, result_out, + &ctrc_physical_active); if (sampled && ctrc_required && !ctrc_physical_active) sampled = false; - if (sampled && ctrc_required - && result_out->status == CLUSTER_TT_STATUS_IN_PROGRESS) - { + if (sampled && ctrc_required && result_out->status == CLUSTER_TT_STATUS_IN_PROGRESS) { ClusterCtrcTouchResult touch_result; if (admission.record_generation > UINT32_MAX - || cluster_undo_block0_current_sample_generation( - &guard, &root, &ctrc_generation) != CLUSTER_UNDO_BLOCK0_OK - || !cluster_runtime_visibility_ctrc_key_fill( - &owner, &ctrc_generation, &root, &admission, &ctrc_key)) + || cluster_undo_block0_current_sample_generation(&guard, &root, &ctrc_generation) + != CLUSTER_UNDO_BLOCK0_OK + || !cluster_runtime_visibility_ctrc_key_fill(&owner, &ctrc_generation, &root, + &admission, &ctrc_key)) sampled = false; - else - { + else { participant.node_id = (uint16)cluster_node_id; - participant.capability_record_generation - = (uint32)admission.record_generation; - participant.boot_incarnation - = ctrc_key.origin_boot_incarnation; + participant.capability_record_generation = (uint32)admission.record_generation; + participant.boot_incarnation = ctrc_key.origin_boot_incarnation; participant.formation_epoch = admission.formation_epoch; - participant.admission_record_generation - = admission.record_generation; - touch_result = cluster_ctrc_origin_touch_exact( - &ctrc_key, &participant, CTRC_PROOF_ACTIVE, &grant); + participant.admission_record_generation = admission.record_generation; + touch_result = cluster_ctrc_origin_touch_exact(&ctrc_key, &participant, + CTRC_PROOF_ACTIVE, &grant); sampled = touch_result == CLUSTER_CTRC_TOUCH_RECORDED - || touch_result == CLUSTER_CTRC_TOUCH_DUPLICATE; + || touch_result == CLUSTER_CTRC_TOUCH_DUPLICATE; if (sampled && (grant == 0 - || cluster_undo_block0_current_sample_generation( - &guard, &root, &final_generation) - != CLUSTER_UNDO_BLOCK0_OK + || cluster_undo_block0_current_sample_generation(&guard, &root, + &final_generation) + != CLUSTER_UNDO_BLOCK0_OK || !final_generation.known || final_generation.value != ctrc_generation.value || !cluster_runtime_visibility_resolve_root_admitted( CLUSTER_TX_RESOLVE_VISIBILITY, &admission, - CLUSTER_UNDO_PATH_RUNTIME_SHARED, - (uint32)cluster_node_id + 1, owner.segment_id, - &final_root) - || !cluster_runtime_visibility_candidate_root_matches( - &root, &final_root) + CLUSTER_UNDO_PATH_RUNTIME_SHARED, (uint32)cluster_node_id + 1, + owner.segment_id, &final_root) + || !cluster_runtime_visibility_candidate_root_matches(&root, &final_root) || !cluster_runtime_visibility_admission_current( CLUSTER_TX_RESOLVE_VISIBILITY, &admission) || cluster_qvotec_get_self_incarnation() - != ctrc_key.origin_boot_incarnation)) + != ctrc_key.origin_boot_incarnation)) sampled = false; } } if (cleanup.active) { - if (cluster_runtime_visibility_candidate_release( - &guard, ¤t_result) + if (cluster_runtime_visibility_candidate_release(&guard, ¤t_result) != CLUSTER_UNDO_BLOCK0_CURRENT_RELEASED) { cluster_undo_block0_current_cancel(&guard); sampled = false; @@ -1187,7 +1095,7 @@ cluster_runtime_visibility_current_owner_lookup_internal( } } PG_END_ENSURE_ERROR_CLEANUP(cluster_runtime_visibility_candidate_cleanup, - PointerGetDatum(&cleanup)); + PointerGetDatum(&cleanup)); done: cluster_semantic_activation_leave(&admission); @@ -1200,8 +1108,7 @@ cluster_runtime_visibility_current_owner_lookup_internal( } if (ctrc_grant_out != NULL) *ctrc_grant_out = grant; - if (sampled && ctrc_required) - { + if (sampled && ctrc_required) { if (ctrc_key_out != NULL) *ctrc_key_out = ctrc_key; if (participant_out != NULL) @@ -1211,35 +1118,34 @@ cluster_runtime_visibility_current_owner_lookup_internal( } bool -cluster_runtime_visibility_current_owner_lookup_exact( - TransactionId xid, ClusterTTStatusKey *key_out, - ClusterTTStatusResult *result_out) +cluster_runtime_visibility_current_owner_lookup_exact(TransactionId xid, + ClusterTTStatusKey *key_out, + ClusterTTStatusResult *result_out) { - return cluster_runtime_visibility_current_owner_lookup_internal( - xid, key_out, result_out, false, NULL, NULL, NULL); + return cluster_runtime_visibility_current_owner_lookup_internal(xid, key_out, result_out, false, + NULL, NULL, NULL); } bool -cluster_runtime_visibility_current_owner_lookup_exact_ctrc( - TransactionId xid, ClusterTTStatusKey *key_out, - ClusterTTStatusResult *result_out, uint32 *ctrc_grant_out) +cluster_runtime_visibility_current_owner_lookup_exact_ctrc(TransactionId xid, + ClusterTTStatusKey *key_out, + ClusterTTStatusResult *result_out, + uint32 *ctrc_grant_out) { - return cluster_runtime_visibility_current_owner_lookup_internal( - xid, key_out, result_out, true, ctrc_grant_out, NULL, NULL); + return cluster_runtime_visibility_current_owner_lookup_internal(xid, key_out, result_out, true, + ctrc_grant_out, NULL, NULL); } bool cluster_runtime_visibility_current_owner_lookup_exact_ctrc_full( - TransactionId xid, ClusterTTStatusKey *key_out, - ClusterTTStatusResult *result_out, uint32 *ctrc_grant_out, - ClusterCtrcTxnKeyV1 *ctrc_key_out, + TransactionId xid, ClusterTTStatusKey *key_out, ClusterTTStatusResult *result_out, + uint32 *ctrc_grant_out, ClusterCtrcTxnKeyV1 *ctrc_key_out, ClusterCtrcParticipantIdentity *participant_out) { if (ctrc_key_out == NULL || participant_out == NULL) return false; return cluster_runtime_visibility_current_owner_lookup_internal( - xid, key_out, result_out, true, ctrc_grant_out, - ctrc_key_out, participant_out); + xid, key_out, result_out, true, ctrc_grant_out, ctrc_key_out, participant_out); } @@ -1255,17 +1161,16 @@ cluster_runtime_visibility_current_owner_lookup_exact_ctrc_full( * which records the participant touch and returns a nonzero grant. */ bool -cluster_runtime_visibility_local_terminal_lookup_exact( - TransactionId xid, ClusterTTStatusKey *key_out, - ClusterTTStatusResult *result_out) +cluster_runtime_visibility_local_terminal_lookup_exact(TransactionId xid, + ClusterTTStatusKey *key_out, + ClusterTTStatusResult *result_out) { ClusterSemanticAdmissionToken admission; ClusterUndoBlock0LogicalKey logical; ClusterUndoBlock0ResolvedRoot root; ClusterUndoBlock0CurrentGuard guard = { 0 }; ClusterRuntimeCandidateCleanup cleanup = { &guard, false }; - ClusterUndoBlock0Result current_result - = CLUSTER_UNDO_BLOCK0_AUTHORITY_DENIED; + ClusterUndoBlock0Result current_result = CLUSTER_UNDO_BLOCK0_AUTHORITY_DENIED; ClusterTTSlotPhysicalLocator locator; ClusterTTDurableLocate locate_result; uint16 segment_id = 0; @@ -1277,8 +1182,7 @@ cluster_runtime_visibility_local_terminal_lookup_exact( if (key_out != NULL) MemSet(key_out, 0, sizeof(*key_out)); - if (result_out != NULL) - { + if (result_out != NULL) { MemSet(result_out, 0, sizeof(*result_out)); result_out->status = CLUSTER_TT_STATUS_UNKNOWN; result_out->commit_scn = InvalidScn; @@ -1287,9 +1191,8 @@ cluster_runtime_visibility_local_terminal_lookup_exact( MemSet(&logical, 0, sizeof(logical)); MemSet(&root, 0, sizeof(root)); MemSet(&locator, 0, sizeof(locator)); - if (key_out == NULL || result_out == NULL - || cluster_node_id < 0 || cluster_node_id >= CLUSTER_MAX_NODES - || !TransactionIdIsNormal(xid) + if (key_out == NULL || result_out == NULL || cluster_node_id < 0 + || cluster_node_id >= CLUSTER_MAX_NODES || !TransactionIdIsNormal(xid) || cluster_xid_origin_slot(xid) != cluster_node_id) return false; epoch = cluster_epoch_get_current(); @@ -1300,52 +1203,44 @@ cluster_runtime_visibility_local_terminal_lookup_exact( return false; locate_result = cluster_tt_slot_durable_locate_any_by_xid_origin( cluster_node_id, xid, &segment_id, &slot_offset, &slot_wrap, NULL); - if (locate_result != CLUSTER_TT_DURABLE_LOCATE_FOUND - || segment_id == 0 || slot_offset >= TT_SLOTS_PER_SEGMENT - || slot_wrap == TT_WRAP_INVALID) + if (locate_result != CLUSTER_TT_DURABLE_LOCATE_FOUND || segment_id == 0 + || slot_offset >= TT_SLOTS_PER_SEGMENT || slot_wrap == TT_WRAP_INVALID) return false; locator.segment_id = segment_id; locator.xid = xid; locator.slot_offset = slot_offset; locator.wrap = slot_wrap; - if (cluster_semantic_activation_enter( - CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, - CLUSTER_SEMANTIC_TARGET_SIDE, &admission) - != CLUSTER_SEMANTIC_ADMISSION_OK + if (cluster_semantic_activation_enter(CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, + CLUSTER_SEMANTIC_TARGET_SIDE, &admission) + != CLUSTER_SEMANTIC_ADMISSION_OK || admission.formation_epoch != epoch) goto done; logical.owner_instance = (uint8)((uint32)cluster_node_id + 1); logical.segment_id = segment_id; if (!cluster_runtime_visibility_resolve_root_admitted( - CLUSTER_TX_RESOLVE_VISIBILITY, &admission, - CLUSTER_UNDO_PATH_RUNTIME_SHARED, logical.owner_instance, - logical.segment_id, &root) - || !cluster_runtime_visibility_admission_current( - CLUSTER_TX_RESOLVE_VISIBILITY, &admission)) + CLUSTER_TX_RESOLVE_VISIBILITY, &admission, CLUSTER_UNDO_PATH_RUNTIME_SHARED, + logical.owner_instance, logical.segment_id, &root) + || !cluster_runtime_visibility_admission_current(CLUSTER_TX_RESOLVE_VISIBILITY, &admission)) goto done; cluster_runtime_visibility_ensure_exit_hooks(); PG_ENSURE_ERROR_CLEANUP(cluster_runtime_visibility_candidate_cleanup, - PointerGetDatum(&cleanup)); + PointerGetDatum(&cleanup)); { - if (cluster_runtime_visibility_candidate_acquire( - &logical, &admission, &guard, &cleanup, ¤t_result) + if (cluster_runtime_visibility_candidate_acquire(&logical, &admission, &guard, &cleanup, + ¤t_result) == CLUSTER_UNDO_BLOCK0_CURRENT_HELD) sampled = cluster_runtime_visibility_physical_locator_sample_held( - &locator, &admission, &guard, &root, key_out, result_out, - &physical_active); + &locator, &admission, &guard, &root, key_out, result_out, &physical_active); if (sampled && (physical_active || (result_out->status != CLUSTER_TT_STATUS_COMMITTED && result_out->status != CLUSTER_TT_STATUS_ABORTED))) sampled = false; - if (cleanup.active) - { - if (cluster_runtime_visibility_candidate_release( - &guard, ¤t_result) - != CLUSTER_UNDO_BLOCK0_CURRENT_RELEASED) - { + if (cleanup.active) { + if (cluster_runtime_visibility_candidate_release(&guard, ¤t_result) + != CLUSTER_UNDO_BLOCK0_CURRENT_RELEASED) { cluster_undo_block0_current_cancel(&guard); sampled = false; } @@ -1353,18 +1248,17 @@ cluster_runtime_visibility_local_terminal_lookup_exact( } } PG_END_ENSURE_ERROR_CLEANUP(cluster_runtime_visibility_candidate_cleanup, - PointerGetDatum(&cleanup)); + PointerGetDatum(&cleanup)); if (sampled && (cluster_epoch_get_current() != epoch - || !cluster_runtime_visibility_admission_current( - CLUSTER_TX_RESOLVE_VISIBILITY, &admission))) + || !cluster_runtime_visibility_admission_current(CLUSTER_TX_RESOLVE_VISIBILITY, + &admission))) sampled = false; done: if (admission.entered) cluster_semantic_activation_leave(&admission); - if (!sampled) - { + if (!sampled) { MemSet(key_out, 0, sizeof(*key_out)); MemSet(result_out, 0, sizeof(*result_out)); result_out->status = CLUSTER_TT_STATUS_UNKNOWN; @@ -1376,8 +1270,7 @@ cluster_runtime_visibility_local_terminal_lookup_exact( bool cluster_runtime_visibility_active_proof_ctrc_identity_exact( const ClusterCurrentMemberProofKey *proof_key, uint32 ctrc_grant, - uint32 requester_capability_generation, - ClusterCtrcTxnKeyV1 *ctrc_key_out, + uint32 requester_capability_generation, ClusterCtrcTxnKeyV1 *ctrc_key_out, ClusterCtrcParticipantIdentity *participant_out) { ClusterSemanticAdmissionToken admission; @@ -1406,19 +1299,15 @@ cluster_runtime_visibility_active_proof_ctrc_identity_exact( memset(&final_root, 0, sizeof(final_root)); memset(&key, 0, sizeof(key)); memset(&participant, 0, sizeof(participant)); - if (proof_key == NULL || ctrc_key_out == NULL || participant_out == NULL - || ctrc_grant == 0 || requester_capability_generation == 0 - || cluster_node_id < 0 + if (proof_key == NULL || ctrc_key_out == NULL || participant_out == NULL || ctrc_grant == 0 + || requester_capability_generation == 0 || cluster_node_id < 0 || cluster_node_id >= CLUSTER_CTRC_MAX_PARTICIPANTS || proof_key->origin_node_id >= CLUSTER_CTRC_MAX_PARTICIPANTS || proof_key->undo_segment_id == 0 || proof_key->tt_slot_id == 0 || !TransactionIdIsNormal(proof_key->local_xid) - || proof_key->binding_version - != CLUSTER_CURRENT_MEMBER_PROOF_BINDING_VERSION - || proof_key->segment_generation == UINT32_MAX - || proof_key->slot_wrap > TT_WRAP_MAX - || cluster_xid_origin_slot(proof_key->local_xid) - != proof_key->origin_node_id) + || proof_key->binding_version != CLUSTER_CURRENT_MEMBER_PROOF_BINDING_VERSION + || proof_key->segment_generation == UINT32_MAX || proof_key->slot_wrap > TT_WRAP_MAX + || cluster_xid_origin_slot(proof_key->local_xid) != proof_key->origin_node_id) return false; epoch = cluster_epoch_get_current(); if (epoch > UINT32_MAX || proof_key->cluster_epoch != (uint32)epoch) @@ -1433,34 +1322,30 @@ cluster_runtime_visibility_active_proof_ctrc_identity_exact( return false; slot_offset = cluster_tt_slot_id_to_offset(proof_key->tt_slot_id); - if (cluster_semantic_activation_enter( - CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, - CLUSTER_SEMANTIC_TARGET_SIDE, &admission) + if (cluster_semantic_activation_enter(CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, + CLUSTER_SEMANTIC_TARGET_SIDE, &admission) != CLUSTER_SEMANTIC_ADMISSION_OK) return false; entered = true; - if (admission.record_generation == 0 - || admission.formation_epoch != epoch) + if (admission.record_generation == 0 || admission.formation_epoch != epoch) goto done; logical.owner_instance = (uint8)(proof_key->origin_node_id + 1); logical.segment_id = segment_id; if (!cluster_runtime_visibility_resolve_root_admitted( - CLUSTER_TX_RESOLVE_VISIBILITY, &admission, - CLUSTER_UNDO_PATH_RUNTIME_SHARED, logical.owner_instance, - logical.segment_id, &root)) + CLUSTER_TX_RESOLVE_VISIBILITY, &admission, CLUSTER_UNDO_PATH_RUNTIME_SHARED, + logical.owner_instance, logical.segment_id, &root)) goto done; participant_boot = cluster_qvotec_get_self_incarnation(); system_identifier = GetSystemIdentifier(); if (proof_key->origin_node_id == (uint16)cluster_node_id) origin_boot = participant_boot; - else if (!cluster_reconfig_get_observed_slot(proof_key->origin_node_id, - &origin_boot, &observed_generation) - || origin_boot == 0 || observed_generation == 0 - || cluster_reconfig_get_observed_epoch(proof_key->origin_node_id) - != epoch - || cluster_membership_get_last_admitted_incarnation( - proof_key->origin_node_id) != origin_boot) + else if (!cluster_reconfig_get_observed_slot(proof_key->origin_node_id, &origin_boot, + &observed_generation) + || origin_boot == 0 || observed_generation == 0 + || cluster_reconfig_get_observed_epoch(proof_key->origin_node_id) != epoch + || cluster_membership_get_last_admitted_incarnation(proof_key->origin_node_id) + != origin_boot) goto done; if (participant_boot == 0 || origin_boot == 0 || system_identifier == 0) goto done; @@ -1484,37 +1369,29 @@ cluster_runtime_visibility_active_proof_ctrc_identity_exact( key.root_id = root.root_id; key.root_generation = root.root_generation; participant.node_id = (uint16)cluster_node_id; - participant.capability_record_generation - = requester_capability_generation; + participant.capability_record_generation = requester_capability_generation; participant.boot_incarnation = participant_boot; participant.formation_epoch = admission.formation_epoch; - participant.admission_record_generation - = admission.record_generation; + participant.admission_record_generation = admission.record_generation; if (!cluster_runtime_visibility_resolve_root_admitted( - CLUSTER_TX_RESOLVE_VISIBILITY, &admission, - CLUSTER_UNDO_PATH_RUNTIME_SHARED, logical.owner_instance, - logical.segment_id, &final_root) - || !cluster_runtime_visibility_candidate_root_matches( - &root, &final_root) + CLUSTER_TX_RESOLVE_VISIBILITY, &admission, CLUSTER_UNDO_PATH_RUNTIME_SHARED, + logical.owner_instance, logical.segment_id, &final_root) + || !cluster_runtime_visibility_candidate_root_matches(&root, &final_root) || cluster_epoch_get_current() != epoch || cluster_qvotec_get_self_incarnation() != participant_boot - || !cluster_runtime_visibility_admission_current( - CLUSTER_TX_RESOLVE_VISIBILITY, &admission)) + || !cluster_runtime_visibility_admission_current(CLUSTER_TX_RESOLVE_VISIBILITY, &admission)) goto done; valid = true; - if (proof_key->origin_node_id != (uint16)cluster_node_id) - { + if (proof_key->origin_node_id != (uint16)cluster_node_id) { uint64 final_origin_boot = 0; uint64 final_observed_generation = 0; - if (!cluster_reconfig_get_observed_slot(proof_key->origin_node_id, - &final_origin_boot, &final_observed_generation) - || final_origin_boot != origin_boot - || final_observed_generation != observed_generation - || cluster_reconfig_get_observed_epoch(proof_key->origin_node_id) - != epoch - || cluster_membership_get_last_admitted_incarnation( - proof_key->origin_node_id) != origin_boot) + if (!cluster_reconfig_get_observed_slot(proof_key->origin_node_id, &final_origin_boot, + &final_observed_generation) + || final_origin_boot != origin_boot || final_observed_generation != observed_generation + || cluster_reconfig_get_observed_epoch(proof_key->origin_node_id) != epoch + || cluster_membership_get_last_admitted_incarnation(proof_key->origin_node_id) + != origin_boot) valid = false; } @@ -1551,34 +1428,28 @@ typedef struct ClusterRuntimeVisibilityOriginPlanData { } ClusterRuntimeVisibilityOriginPlanData; StaticAssertDecl(sizeof(ClusterRuntimeVisibilityOriginPlanData) - <= CLUSTER_RUNTIME_VISIBILITY_ORIGIN_PLAN_BYTES, + <= CLUSTER_RUNTIME_VISIBILITY_ORIGIN_PLAN_BYTES, "exact origin continuation must fit its process-local envelope"); static ClusterRuntimeVisibilityOriginPlanData * -cluster_runtime_visibility_origin_plan_data( - ClusterRuntimeVisibilityOriginPlan *plan) +cluster_runtime_visibility_origin_plan_data(ClusterRuntimeVisibilityOriginPlan *plan) { - return plan == NULL - ? NULL : (ClusterRuntimeVisibilityOriginPlanData *)plan->opaque; + return plan == NULL ? NULL : (ClusterRuntimeVisibilityOriginPlanData *)plan->opaque; } static const ClusterRuntimeVisibilityOriginPlanData * -cluster_runtime_visibility_origin_plan_data_const( - const ClusterRuntimeVisibilityOriginPlan *plan) +cluster_runtime_visibility_origin_plan_data_const(const ClusterRuntimeVisibilityOriginPlan *plan) { - return plan == NULL - ? NULL : (const ClusterRuntimeVisibilityOriginPlanData *)plan->opaque; + return plan == NULL ? NULL : (const ClusterRuntimeVisibilityOriginPlanData *)plan->opaque; } static void -cluster_runtime_visibility_origin_candidate_stamp( - ClusterTxResolution *candidate, - const ClusterSemanticAdmissionToken *admission) +cluster_runtime_visibility_origin_candidate_stamp(ClusterTxResolution *candidate, + const ClusterSemanticAdmissionToken *admission) { candidate->authority.origin_epoch = cluster_epoch_get_current(); candidate->authority.live_hwm_lsn = GetFlushRecPtr(NULL); - candidate->authority.tt_generation - = cluster_undo_tt_retention_rollover_count(); + candidate->authority.tt_generation = cluster_undo_tt_retention_rollover_count(); candidate->authority.authority_scn = cluster_scn_current(); (void)admission; } @@ -1633,18 +1504,19 @@ cluster_runtime_visibility_origin_recycled_abort_sample( * not a replacement for candidate_decide's exact identity guard. Whole- * segment rebirth clears slots and restarts their wraps. Neither an empty * slot nor a newer occupant proves the old transaction's status: the old - * ABORT must be proved independently at its origin. */ + * ABORT must be proved independently at its origin. Terminal census consumes + * exactly that same proof; it must not strand an aborted ITL after TT reuse. + * This does not admit nonterminal outcomes to the census publication filter. */ static bool cluster_runtime_visibility_origin_recycled_abort_candidate( const ClusterTxLocator *locator, ClusterTxResolveMode mode, const TTSlot *slot, - uint32 sampled_generation, - ClusterRuntimeVisibilityCanonicalDiagnostic *diagnostic) + uint32 sampled_generation, ClusterRuntimeVisibilityCanonicalDiagnostic *diagnostic) { - if (mode != CLUSTER_TX_RESOLVE_VISIBILITY || !TransactionIdIsNormal(locator->xid) - || locator->tt_wrap > TT_WRAP_MAX) + if ((mode != CLUSTER_TX_RESOLVE_VISIBILITY && mode != CLUSTER_TX_RESOLVE_TERMINAL_CENSUS) + || !TransactionIdIsNormal(locator->xid) || locator->tt_wrap > TT_WRAP_MAX) return false; if (slot->status == TT_SLOT_UNUSED) { - const TTSlot empty = {0}; + const TTSlot empty = { 0 }; if (sampled_generation == 0 || sampled_generation == UINT32_MAX || memcmp(slot, &empty, sizeof(empty)) != 0) @@ -1729,20 +1601,18 @@ cluster_runtime_visibility_origin_plan_freeze_data_internal( memset(&final_generation, 0, sizeof(final_generation)); memset(&canonical_locator, 0, sizeof(canonical_locator)); - if (locator == NULL || out == NULL || admission == NULL || guard == NULL - || root == NULL || plan == NULL - || (mode != CLUSTER_TX_RESOLVE_VISIBILITY - && mode != CLUSTER_TX_RESOLVE_TERMINAL_CENSUS)) { - reason = locator == NULL ? CLUSTER_TX_RESOLVE_BAD_LOCATOR - : CLUSTER_TX_RESOLVE_PROTOCOL; + if (locator == NULL || out == NULL || admission == NULL || guard == NULL || root == NULL + || plan == NULL + || (mode != CLUSTER_TX_RESOLVE_VISIBILITY && mode != CLUSTER_TX_RESOLVE_TERMINAL_CENSUS)) { + reason = locator == NULL ? CLUSTER_TX_RESOLVE_BAD_LOCATOR : CLUSTER_TX_RESOLVE_PROTOCOL; goto failed; } if (!cluster_runtime_visibility_admission_current(mode, admission)) { reason = CLUSTER_TX_RESOLVE_AUTHORITY_STALE; goto failed; } - if (!uba_decode(locator->uba, &segment_id, &block_no, &tt_slot_offset, - &row_offset) || block_no == 0) { + if (!uba_decode(locator->uba, &segment_id, &block_no, &tt_slot_offset, &row_offset) + || block_no == 0) { reason = CLUSTER_TX_RESOLVE_BAD_UBA; goto failed; } @@ -1755,28 +1625,25 @@ cluster_runtime_visibility_origin_plan_freeze_data_internal( goto failed; plan_data = cluster_runtime_visibility_origin_plan_data(plan); - plan_data->data_logical.owner_instance - = (uint8)((uint32)origin + 1); + plan_data->data_logical.owner_instance = (uint8)((uint32)origin + 1); plan_data->data_logical.segment_id = segment_id; - if (cluster_undo_block0_current_sample_generation( - guard, root, &generation) != CLUSTER_UNDO_BLOCK0_OK + if (cluster_undo_block0_current_sample_generation(guard, root, &generation) + != CLUSTER_UNDO_BLOCK0_OK || !generation.known || generation.value == UINT32_MAX) goto failed; if (expected_generation != NULL - && (!expected_generation->known - || expected_generation->value == UINT32_MAX + && (!expected_generation->known || expected_generation->value == UINT32_MAX || expected_generation->value != generation.value)) goto failed; - if (cluster_undo_block0_current_copy_resident( - guard, root, &generation, block0.data) != CLUSTER_UNDO_BLOCK0_OK) + if (cluster_undo_block0_current_copy_resident(guard, root, &generation, block0.data) + != CLUSTER_UNDO_BLOCK0_OK) goto failed; if (!cluster_runtime_visibility_origin_data_copy(segment_id, plan_data->data_logical.owner_instance, block_no, data_page.data, allow_readthrough)) goto failed; - if (!cluster_cr_r4_extract_resident_record( - data_page.data, locator, record_buf.data, &record_length, - &canonical_locator) + if (!cluster_cr_r4_extract_resident_record(data_page.data, locator, record_buf.data, + &record_length, &canonical_locator) || record_length < sizeof(UndoRecordHeader)) goto failed; @@ -1799,8 +1666,7 @@ cluster_runtime_visibility_origin_plan_freeze_data_internal( plan_data->tt_slot_offset = tt_slot_offset; plan_data->record_length = record_length; memcpy(plan_data->record_buf.data, record_buf.data, record_length); - plan_data->tt_logical.owner_instance - = plan_data->data_logical.owner_instance; + plan_data->tt_logical.owner_instance = plan_data->data_logical.owner_instance; plan_data->tt_logical.segment_id = tt_segment_id; if (tt_segment_id != segment_id) { if (reason_out != NULL) @@ -1811,11 +1677,10 @@ cluster_runtime_visibility_origin_plan_freeze_data_internal( header = (const UndoSegmentHeaderData *)block0.data; exact_slot = header->tt_slots[tt_slot_offset]; outcome = cluster_runtime_visibility_candidate_decide( - &canonical_locator, mode, &exact_slot, &top_xid, &proof_kind, - &commit_scn, &reason, NULL); + &canonical_locator, mode, &exact_slot, &top_xid, &proof_kind, &commit_scn, &reason, NULL); if (outcome == CLUSTER_TX_UNKNOWN - && cluster_runtime_visibility_origin_recycled_abort_candidate(&canonical_locator, mode, - &exact_slot, generation.value, NULL)) { + && cluster_runtime_visibility_origin_recycled_abort_candidate( + &canonical_locator, mode, &exact_slot, generation.value, NULL)) { outcome = CLUSTER_TX_ABORTED; top_xid = canonical_locator.xid; proof_kind = CLUSTER_TX_PROOF_ORIGIN_DURABLE_TT_CLOG; @@ -1829,21 +1694,16 @@ cluster_runtime_visibility_origin_plan_freeze_data_internal( plan_data->candidate.outcome = outcome; plan_data->candidate.proof_kind = proof_kind; plan_data->candidate.commit_scn = commit_scn; - cluster_runtime_visibility_origin_candidate_stamp( - &plan_data->candidate, admission); - if (plan_data->candidate.authority.origin_epoch - != admission->formation_epoch - || XLogRecPtrIsInvalid( - plan_data->candidate.authority.live_hwm_lsn) + cluster_runtime_visibility_origin_candidate_stamp(&plan_data->candidate, admission); + if (plan_data->candidate.authority.origin_epoch != admission->formation_epoch + || XLogRecPtrIsInvalid(plan_data->candidate.authority.live_hwm_lsn) || !SCN_VALID(plan_data->candidate.authority.authority_scn) - || cluster_undo_block0_current_sample_generation( - guard, root, &final_generation) != CLUSTER_UNDO_BLOCK0_OK - || !final_generation.known - || final_generation.value != generation.value + || cluster_undo_block0_current_sample_generation(guard, root, &final_generation) + != CLUSTER_UNDO_BLOCK0_OK + || !final_generation.known || final_generation.value != generation.value || !cluster_runtime_visibility_resolve_root_admitted( mode, admission, CLUSTER_UNDO_PATH_RUNTIME_SHARED, - plan_data->data_logical.owner_instance, - plan_data->data_logical.segment_id, &final_root) + plan_data->data_logical.owner_instance, plan_data->data_logical.segment_id, &final_root) || !cluster_runtime_visibility_candidate_root_matches(root, &final_root) || !cluster_runtime_visibility_admission_current(mode, admission)) { reason = CLUSTER_TX_RESOLVE_AUTHORITY_STALE; @@ -1877,17 +1737,15 @@ cluster_runtime_visibility_origin_plan_freeze_data_held( bool cluster_runtime_visibility_origin_plan_canonical_logical( - const ClusterRuntimeVisibilityOriginPlan *plan, - ClusterUndoBlock0LogicalKey *logical_out) + const ClusterRuntimeVisibilityOriginPlan *plan, ClusterUndoBlock0LogicalKey *logical_out) { const ClusterRuntimeVisibilityOriginPlanData *plan_data = cluster_runtime_visibility_origin_plan_data_const(plan); if (plan_data == NULL || logical_out == NULL - || plan_data->magic != CLUSTER_RUNTIME_VISIBILITY_ORIGIN_PLAN_MAGIC - || !plan_data->valid || plan_data->candidate_valid - || plan_data->tt_logical.segment_id - == plan_data->data_logical.segment_id) + || plan_data->magic != CLUSTER_RUNTIME_VISIBILITY_ORIGIN_PLAN_MAGIC || !plan_data->valid + || plan_data->candidate_valid + || plan_data->tt_logical.segment_id == plan_data->data_logical.segment_id) return false; *logical_out = plan_data->tt_logical; return true; @@ -1895,8 +1753,8 @@ cluster_runtime_visibility_origin_plan_canonical_logical( bool cluster_runtime_visibility_origin_plan_canonical_physical( - const ClusterRuntimeVisibilityOriginPlan *plan, - ClusterTTSlotPhysicalLocator *locator_out, bool *same_segment_out) + const ClusterRuntimeVisibilityOriginPlan *plan, ClusterTTSlotPhysicalLocator *locator_out, + bool *same_segment_out) { const ClusterRuntimeVisibilityOriginPlanData *plan_data = cluster_runtime_visibility_origin_plan_data_const(plan); @@ -1906,8 +1764,8 @@ cluster_runtime_visibility_origin_plan_canonical_physical( if (same_segment_out != NULL) *same_segment_out = false; if (plan_data == NULL || locator_out == NULL || same_segment_out == NULL - || plan_data->magic != CLUSTER_RUNTIME_VISIBILITY_ORIGIN_PLAN_MAGIC - || !plan_data->valid || plan_data->tt_logical.segment_id == 0 + || plan_data->magic != CLUSTER_RUNTIME_VISIBILITY_ORIGIN_PLAN_MAGIC || !plan_data->valid + || plan_data->tt_logical.segment_id == 0 || !TransactionIdIsNormal(plan_data->canonical_locator.xid) || plan_data->canonical_locator.tt_wrap == TT_WRAP_INVALID || plan_data->canonical_locator.tt_wrap > TT_WRAP_MAX @@ -1918,18 +1776,15 @@ cluster_runtime_visibility_origin_plan_canonical_physical( locator_out->xid = plan_data->canonical_locator.xid; locator_out->slot_offset = plan_data->tt_slot_offset; locator_out->wrap = plan_data->canonical_locator.tt_wrap; - *same_segment_out = plan_data->tt_logical.segment_id - == plan_data->data_logical.segment_id; + *same_segment_out = plan_data->tt_logical.segment_id == plan_data->data_logical.segment_id; return true; } bool cluster_runtime_visibility_origin_plan_sample_canonical_held( ClusterRuntimeVisibilityOriginPlan *plan, ClusterTxResolveMode mode, - const ClusterSemanticAdmissionToken *admission, - ClusterUndoBlock0CurrentGuard *guard, - const ClusterUndoBlock0ResolvedRoot *root, - ClusterTxResolveReason *reason_out) + const ClusterSemanticAdmissionToken *admission, ClusterUndoBlock0CurrentGuard *guard, + const ClusterUndoBlock0ResolvedRoot *root, ClusterTxResolveReason *reason_out) { ClusterRuntimeVisibilityOriginPlanData *plan_data = cluster_runtime_visibility_origin_plan_data(plan); @@ -1955,38 +1810,29 @@ cluster_runtime_visibility_origin_plan_sample_canonical_held( memset(&generation, 0, sizeof(generation)); memset(&final_generation, 0, sizeof(final_generation)); if (plan_data == NULL || admission == NULL || guard == NULL || root == NULL - || plan_data->magic != CLUSTER_RUNTIME_VISIBILITY_ORIGIN_PLAN_MAGIC - || !plan_data->valid || plan_data->candidate_valid - || plan_data->mode != mode - || plan_data->tt_logical.segment_id - == plan_data->data_logical.segment_id) { + || plan_data->magic != CLUSTER_RUNTIME_VISIBILITY_ORIGIN_PLAN_MAGIC || !plan_data->valid + || plan_data->candidate_valid || plan_data->mode != mode + || plan_data->tt_logical.segment_id == plan_data->data_logical.segment_id) { reason = CLUSTER_TX_RESOLVE_AUTHORITY_STALE; goto failed; } - memset(&plan_data->canonical_diagnostic, 0, - sizeof(plan_data->canonical_diagnostic)); + memset(&plan_data->canonical_diagnostic, 0, sizeof(plan_data->canonical_diagnostic)); plan_data->canonical_diagnostic.valid = true; plan_data->canonical_diagnostic.resident_copy_result = -1; - plan_data->canonical_diagnostic.locator_xid - = plan_data->canonical_locator.xid; - plan_data->canonical_diagnostic.locator_wrap - = plan_data->canonical_locator.tt_wrap; - plan_data->canonical_diagnostic.tt_slot_offset - = plan_data->tt_slot_offset; + plan_data->canonical_diagnostic.locator_xid = plan_data->canonical_locator.xid; + plan_data->canonical_diagnostic.locator_wrap = plan_data->canonical_locator.tt_wrap; + plan_data->canonical_diagnostic.tt_slot_offset = plan_data->tt_slot_offset; plan_data->canonical_diagnostic.root_id = root->root_id; plan_data->canonical_diagnostic.root_generation = root->root_generation; - admission_current - = cluster_runtime_visibility_admission_current(mode, admission); - plan_data->canonical_diagnostic.initial_admission_current - = admission_current; + admission_current = cluster_runtime_visibility_admission_current(mode, admission); + plan_data->canonical_diagnostic.initial_admission_current = admission_current; if (!admission_current) { plan_data->canonical_diagnostic.first_failure = CLUSTER_RUNTIME_VISIBILITY_CANONICAL_FAILURE_PLAN_CURRENT; reason = CLUSTER_TX_RESOLVE_AUTHORITY_STALE; goto failed; } - generation_result = cluster_undo_block0_current_sample_generation( - guard, root, &generation); + generation_result = cluster_undo_block0_current_sample_generation(guard, root, &generation); plan_data->canonical_diagnostic.generation_result = generation_result; plan_data->canonical_diagnostic.generation_known = generation.known; plan_data->canonical_diagnostic.generation_value = generation.value; @@ -2005,10 +1851,9 @@ cluster_runtime_visibility_origin_plan_sample_canonical_held( = CLUSTER_RUNTIME_VISIBILITY_CANONICAL_FAILURE_GENERATION_OVERFLOW; goto failed; } - resident_copy_result = cluster_undo_block0_current_copy_resident( - guard, root, &generation, block0.data); - plan_data->canonical_diagnostic.resident_copy_result - = resident_copy_result; + resident_copy_result + = cluster_undo_block0_current_copy_resident(guard, root, &generation, block0.data); + plan_data->canonical_diagnostic.resident_copy_result = resident_copy_result; if (resident_copy_result != CLUSTER_UNDO_BLOCK0_OK) { plan_data->canonical_diagnostic.first_failure = CLUSTER_RUNTIME_VISIBILITY_CANONICAL_FAILURE_RESIDENT_COPY; @@ -2017,8 +1862,8 @@ cluster_runtime_visibility_origin_plan_sample_canonical_held( header = (const UndoSegmentHeaderData *)block0.data; exact_slot = header->tt_slots[plan_data->tt_slot_offset]; outcome = cluster_runtime_visibility_candidate_decide( - &plan_data->canonical_locator, mode, &exact_slot, &top_xid, &proof_kind, - &commit_scn, &reason, &plan_data->canonical_diagnostic); + &plan_data->canonical_locator, mode, &exact_slot, &top_xid, &proof_kind, &commit_scn, + &reason, &plan_data->canonical_diagnostic); if (outcome == CLUSTER_TX_UNKNOWN && cluster_runtime_visibility_origin_recycled_abort_candidate( &plan_data->canonical_locator, mode, &exact_slot, generation.value, @@ -2037,22 +1882,18 @@ cluster_runtime_visibility_origin_plan_sample_canonical_held( plan_data->candidate.outcome = outcome; plan_data->candidate.proof_kind = proof_kind; plan_data->candidate.commit_scn = commit_scn; - cluster_runtime_visibility_origin_candidate_stamp( - &plan_data->candidate, admission); - if (plan_data->candidate.authority.origin_epoch - != admission->formation_epoch - || XLogRecPtrIsInvalid( - plan_data->candidate.authority.live_hwm_lsn) + cluster_runtime_visibility_origin_candidate_stamp(&plan_data->candidate, admission); + if (plan_data->candidate.authority.origin_epoch != admission->formation_epoch + || XLogRecPtrIsInvalid(plan_data->candidate.authority.live_hwm_lsn) || !SCN_VALID(plan_data->candidate.authority.authority_scn)) { plan_data->canonical_diagnostic.first_failure = CLUSTER_RUNTIME_VISIBILITY_CANONICAL_FAILURE_AUTHORITY_STAMP; reason = CLUSTER_TX_RESOLVE_AUTHORITY_STALE; goto failed; } - generation_result = cluster_undo_block0_current_sample_generation( - guard, root, &final_generation); - if (generation_result != CLUSTER_UNDO_BLOCK0_OK - || !final_generation.known + generation_result + = cluster_undo_block0_current_sample_generation(guard, root, &final_generation); + if (generation_result != CLUSTER_UNDO_BLOCK0_OK || !final_generation.known || final_generation.value != generation.value) { plan_data->canonical_diagnostic.first_failure = CLUSTER_RUNTIME_VISIBILITY_CANONICAL_FAILURE_GENERATION_RECHECK; @@ -2060,26 +1901,21 @@ cluster_runtime_visibility_origin_plan_sample_canonical_held( goto failed; } root_sampled = cluster_runtime_visibility_resolve_root_admitted( - mode, admission, CLUSTER_UNDO_PATH_RUNTIME_SHARED, - plan_data->tt_logical.owner_instance, + mode, admission, CLUSTER_UNDO_PATH_RUNTIME_SHARED, plan_data->tt_logical.owner_instance, plan_data->tt_logical.segment_id, &final_root); plan_data->canonical_diagnostic.final_root_sampled = root_sampled; if (root_sampled) { plan_data->canonical_diagnostic.final_root_id = final_root.root_id; - plan_data->canonical_diagnostic.final_root_generation - = final_root.root_generation; + plan_data->canonical_diagnostic.final_root_generation = final_root.root_generation; } - if (!root_sampled - || !cluster_runtime_visibility_candidate_root_matches(root, &final_root)) { + if (!root_sampled || !cluster_runtime_visibility_candidate_root_matches(root, &final_root)) { plan_data->canonical_diagnostic.first_failure = CLUSTER_RUNTIME_VISIBILITY_CANONICAL_FAILURE_ROOT_RECHECK; reason = CLUSTER_TX_RESOLVE_AUTHORITY_STALE; goto failed; } - admission_current - = cluster_runtime_visibility_admission_current(mode, admission); - plan_data->canonical_diagnostic.final_admission_current - = admission_current; + admission_current = cluster_runtime_visibility_admission_current(mode, admission); + plan_data->canonical_diagnostic.final_admission_current = admission_current; if (!admission_current) { plan_data->canonical_diagnostic.first_failure = CLUSTER_RUNTIME_VISIBILITY_CANONICAL_FAILURE_ADMISSION_RECHECK; @@ -2110,8 +1946,8 @@ cluster_runtime_visibility_origin_plan_canonical_diagnostic( if (out != NULL) memset(out, 0, sizeof(*out)); if (plan_data == NULL || out == NULL - || plan_data->magic != CLUSTER_RUNTIME_VISIBILITY_ORIGIN_PLAN_MAGIC - || !plan_data->valid || !plan_data->canonical_diagnostic.valid) + || plan_data->magic != CLUSTER_RUNTIME_VISIBILITY_ORIGIN_PLAN_MAGIC || !plan_data->valid + || !plan_data->canonical_diagnostic.valid) return false; *out = plan_data->canonical_diagnostic; return true; @@ -2143,13 +1979,10 @@ cluster_runtime_visibility_origin_plan_recheck_data_internal( memset(&generation, 0, sizeof(generation)); memset(&final_generation, 0, sizeof(final_generation)); memset(&rechecked_locator, 0, sizeof(rechecked_locator)); - if (plan_data == NULL || admission == NULL || guard == NULL || root == NULL - || out == NULL - || plan_data->magic != CLUSTER_RUNTIME_VISIBILITY_ORIGIN_PLAN_MAGIC - || !plan_data->valid || !plan_data->candidate_valid - || plan_data->mode != mode - || !cluster_runtime_visibility_candidate_root_matches( - &plan_data->data_root, root) + if (plan_data == NULL || admission == NULL || guard == NULL || root == NULL || out == NULL + || plan_data->magic != CLUSTER_RUNTIME_VISIBILITY_ORIGIN_PLAN_MAGIC || !plan_data->valid + || !plan_data->candidate_valid || plan_data->mode != mode + || !cluster_runtime_visibility_candidate_root_matches(&plan_data->data_root, root) || !cluster_runtime_visibility_admission_current(mode, admission)) { reason = CLUSTER_TX_RESOLVE_AUTHORITY_STALE; goto failed; @@ -2226,13 +2059,10 @@ cluster_runtime_visibility_origin_plan_copy_data_held( bool cluster_runtime_visibility_current_mx_updater_provenance_exact( - const ClusterTxLocator *locator, TimestampTz deadline, - ClusterTTStatusKey *key_out, ClusterTTStatusResult *result_out, - uint32 *ctrc_grant_out, - uint32 *participant_capability_generation_out, - ClusterCtrcTxnKeyV1 *ctrc_key_out, - ClusterTxLocator *canonical_locator_out, - bool *cross_segment_out) + const ClusterTxLocator *locator, TimestampTz deadline, ClusterTTStatusKey *key_out, + ClusterTTStatusResult *result_out, uint32 *ctrc_grant_out, + uint32 *participant_capability_generation_out, ClusterCtrcTxnKeyV1 *ctrc_key_out, + ClusterTxLocator *canonical_locator_out, bool *cross_segment_out) { ClusterSemanticAdmissionToken admission; ClusterUndoBlock0LogicalKey data_logical; @@ -2253,8 +2083,7 @@ cluster_runtime_visibility_current_mx_updater_provenance_exact( ClusterRuntimeVisibilityOriginStep origin_step; ClusterUndoBlock0Generation generation = { false, 0 }; ClusterUndoBlock0Generation final_generation = { false, 0 }; - ClusterUndoBlock0Result current_result - = CLUSTER_UNDO_BLOCK0_AUTHORITY_DENIED; + ClusterUndoBlock0Result current_result = CLUSTER_UNDO_BLOCK0_AUTHORITY_DENIED; ClusterCtrcTxnKeyV1 ctrc_key; ClusterCtrcParticipantIdentity participant; ClusterCtrcTouchResult touch_result; @@ -2306,17 +2135,12 @@ cluster_runtime_visibility_current_mx_updater_provenance_exact( memset(&ctrc_key, 0, sizeof(ctrc_key)); memset(&participant, 0, sizeof(participant)); - if (locator == NULL || key_out == NULL || result_out == NULL - || ctrc_grant_out == NULL - || participant_capability_generation_out == NULL - || ctrc_key_out == NULL - || canonical_locator_out == NULL - || cross_segment_out == NULL - || cluster_node_id < 0 || cluster_node_id >= CLUSTER_MAX_NODES - || !TransactionIdIsNormal(locator->xid) + if (locator == NULL || key_out == NULL || result_out == NULL || ctrc_grant_out == NULL + || participant_capability_generation_out == NULL || ctrc_key_out == NULL + || canonical_locator_out == NULL || cross_segment_out == NULL || cluster_node_id < 0 + || cluster_node_id >= CLUSTER_MAX_NODES || !TransactionIdIsNormal(locator->xid) || locator->tt_wrap != TT_WRAP_INVALID - || !uba_decode(locator->uba, &data_segment, &block_no, - &tt_slot_offset, &row_offset) + || !uba_decode(locator->uba, &data_segment, &block_no, &tt_slot_offset, &row_offset) || block_no == 0 || tt_slot_offset >= TT_SLOTS_PER_SEGMENT || (origin = uba_origin_node_id(locator->uba)) == InvalidNodeId || origin != (NodeId)cluster_node_id @@ -2325,10 +2149,9 @@ cluster_runtime_visibility_current_mx_updater_provenance_exact( return false; epoch = cluster_epoch_get_current(); if (epoch > UINT32_MAX - || cluster_semantic_activation_enter( - CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, - CLUSTER_SEMANTIC_TARGET_SIDE, &admission) - != CLUSTER_SEMANTIC_ADMISSION_OK) + || cluster_semantic_activation_enter(CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, + CLUSTER_SEMANTIC_TARGET_SIDE, &admission) + != CLUSTER_SEMANTIC_ADMISSION_OK) return false; entered = true; if (admission.formation_epoch != epoch) @@ -2337,63 +2160,52 @@ cluster_runtime_visibility_current_mx_updater_provenance_exact( data_logical.owner_instance = (uint8)((uint32)origin + 1); data_logical.segment_id = data_segment; if (!cluster_runtime_visibility_resolve_root_admitted( - CLUSTER_TX_RESOLVE_VISIBILITY, &admission, - CLUSTER_UNDO_PATH_RUNTIME_SHARED, data_logical.owner_instance, - data_logical.segment_id, &data_root) - || !cluster_runtime_visibility_admission_current( - CLUSTER_TX_RESOLVE_VISIBILITY, &admission)) + CLUSTER_TX_RESOLVE_VISIBILITY, &admission, CLUSTER_UNDO_PATH_RUNTIME_SHARED, + data_logical.owner_instance, data_logical.segment_id, &data_root) + || !cluster_runtime_visibility_admission_current(CLUSTER_TX_RESOLVE_VISIBILITY, &admission)) goto done; cluster_runtime_visibility_ensure_exit_hooks(); PG_ENSURE_ERROR_CLEANUP(cluster_runtime_visibility_candidate_cleanup, - PointerGetDatum(&cleanup)); + PointerGetDatum(&cleanup)); { - if (cluster_runtime_visibility_candidate_acquire_until( - &data_logical, &admission, &guard, &cleanup, - ¤t_result, deadline) + if (cluster_runtime_visibility_candidate_acquire_until(&data_logical, &admission, &guard, + &cleanup, ¤t_result, deadline) != CLUSTER_UNDO_BLOCK0_CURRENT_HELD) goto protected_done; phase_root = data_root; origin_step = cluster_runtime_visibility_origin_plan_freeze_data_held( - locator, CLUSTER_TX_RESOLVE_VISIBILITY, &admission, NULL, - &guard, &phase_root, &plan, &resolution, &reason); + locator, CLUSTER_TX_RESOLVE_VISIBILITY, &admission, NULL, &guard, &phase_root, &plan, + &resolution, &reason); if (origin_step == CLUSTER_RUNTIME_VISIBILITY_ORIGIN_FAILED - || !cluster_runtime_visibility_origin_plan_canonical_physical( - &plan, &physical, &same_segment) - || (origin_step == CLUSTER_RUNTIME_VISIBILITY_ORIGIN_COMPLETE - && !same_segment) - || (origin_step - == CLUSTER_RUNTIME_VISIBILITY_ORIGIN_NEEDS_CANONICAL - && same_segment)) + || !cluster_runtime_visibility_origin_plan_canonical_physical(&plan, &physical, + &same_segment) + || (origin_step == CLUSTER_RUNTIME_VISIBILITY_ORIGIN_COMPLETE && !same_segment) + || (origin_step == CLUSTER_RUNTIME_VISIBILITY_ORIGIN_NEEDS_CANONICAL && same_segment)) goto protected_done; if (!same_segment) { - if (cluster_runtime_visibility_candidate_release_until( - &guard, ¤t_result, deadline) + if (cluster_runtime_visibility_candidate_release_until(&guard, ¤t_result, + deadline) != CLUSTER_UNDO_BLOCK0_CURRENT_RELEASED) goto protected_done; cleanup.active = false; memset(&guard, 0, sizeof(guard)); - if (!cluster_runtime_visibility_origin_plan_canonical_logical( - &plan, &tt_logical) + if (!cluster_runtime_visibility_origin_plan_canonical_logical(&plan, &tt_logical) || !cluster_runtime_visibility_resolve_root_admitted( - CLUSTER_TX_RESOLVE_VISIBILITY, &admission, - CLUSTER_UNDO_PATH_RUNTIME_SHARED, - tt_logical.owner_instance, tt_logical.segment_id, - &phase_root) + CLUSTER_TX_RESOLVE_VISIBILITY, &admission, CLUSTER_UNDO_PATH_RUNTIME_SHARED, + tt_logical.owner_instance, tt_logical.segment_id, &phase_root) || cluster_runtime_visibility_candidate_acquire_until( - &tt_logical, &admission, &guard, &cleanup, - ¤t_result, deadline) - != CLUSTER_UNDO_BLOCK0_CURRENT_HELD + &tt_logical, &admission, &guard, &cleanup, ¤t_result, deadline) + != CLUSTER_UNDO_BLOCK0_CURRENT_HELD || !cluster_runtime_visibility_origin_plan_sample_canonical_held( - &plan, CLUSTER_TX_RESOLVE_VISIBILITY, &admission, &guard, - &phase_root, &reason)) + &plan, CLUSTER_TX_RESOLVE_VISIBILITY, &admission, &guard, &phase_root, &reason)) goto protected_done; } if (!cluster_runtime_visibility_physical_locator_sample_held( - &physical, &admission, &guard, &phase_root, &sampled_key, - &sampled_result, &physical_active)) + &physical, &admission, &guard, &phase_root, &sampled_key, &sampled_result, + &physical_active)) goto protected_done; if (sampled_result.status == CLUSTER_TT_STATUS_IN_PROGRESS) { owner.segment_id = physical.segment_id; @@ -2401,39 +2213,31 @@ cluster_runtime_visibility_current_mx_updater_provenance_exact( owner.slot_offset = physical.slot_offset; owner.wrap = physical.wrap; if (!physical_active || admission.record_generation > UINT32_MAX - || cluster_undo_block0_current_sample_generation( - &guard, &phase_root, &generation) - != CLUSTER_UNDO_BLOCK0_OK - || !cluster_runtime_visibility_ctrc_key_fill( - &owner, &generation, &phase_root, &admission, &ctrc_key)) + || cluster_undo_block0_current_sample_generation(&guard, &phase_root, &generation) + != CLUSTER_UNDO_BLOCK0_OK + || !cluster_runtime_visibility_ctrc_key_fill(&owner, &generation, &phase_root, + &admission, &ctrc_key)) goto protected_done; participant.node_id = (uint16)cluster_node_id; - participant.capability_record_generation - = (uint32)admission.record_generation; + participant.capability_record_generation = (uint32)admission.record_generation; participant.boot_incarnation = ctrc_key.origin_boot_incarnation; participant.formation_epoch = admission.formation_epoch; - participant.admission_record_generation - = admission.record_generation; - touch_result = cluster_ctrc_origin_touch_exact( - &ctrc_key, &participant, CTRC_PROOF_ACTIVE, &grant); + participant.admission_record_generation = admission.record_generation; + touch_result = cluster_ctrc_origin_touch_exact(&ctrc_key, &participant, + CTRC_PROOF_ACTIVE, &grant); if ((touch_result != CLUSTER_CTRC_TOUCH_RECORDED && touch_result != CLUSTER_CTRC_TOUCH_DUPLICATE) || grant == 0 - || cluster_undo_block0_current_sample_generation( - &guard, &phase_root, &final_generation) - != CLUSTER_UNDO_BLOCK0_OK - || !final_generation.known - || final_generation.value != generation.value + || cluster_undo_block0_current_sample_generation(&guard, &phase_root, + &final_generation) + != CLUSTER_UNDO_BLOCK0_OK + || !final_generation.known || final_generation.value != generation.value || !cluster_runtime_visibility_resolve_root_admitted( - CLUSTER_TX_RESOLVE_VISIBILITY, &admission, - CLUSTER_UNDO_PATH_RUNTIME_SHARED, - same_segment ? data_logical.owner_instance - : tt_logical.owner_instance, + CLUSTER_TX_RESOLVE_VISIBILITY, &admission, CLUSTER_UNDO_PATH_RUNTIME_SHARED, + same_segment ? data_logical.owner_instance : tt_logical.owner_instance, physical.segment_id, &final_tt_root) - || !cluster_runtime_visibility_candidate_root_matches( - &phase_root, &final_tt_root) - || cluster_qvotec_get_self_incarnation() - != ctrc_key.origin_boot_incarnation) + || !cluster_runtime_visibility_candidate_root_matches(&phase_root, &final_tt_root) + || cluster_qvotec_get_self_incarnation() != ctrc_key.origin_boot_incarnation) goto protected_done; } else if (physical_active || (sampled_result.status != CLUSTER_TT_STATUS_COMMITTED @@ -2441,48 +2245,41 @@ cluster_runtime_visibility_current_mx_updater_provenance_exact( goto protected_done; if (!same_segment) { - if (cluster_runtime_visibility_candidate_release_until( - &guard, ¤t_result, deadline) + if (cluster_runtime_visibility_candidate_release_until(&guard, ¤t_result, + deadline) != CLUSTER_UNDO_BLOCK0_CURRENT_RELEASED) goto protected_done; cleanup.active = false; memset(&guard, 0, sizeof(guard)); if (!cluster_runtime_visibility_resolve_root_admitted( - CLUSTER_TX_RESOLVE_VISIBILITY, &admission, - CLUSTER_UNDO_PATH_RUNTIME_SHARED, - data_logical.owner_instance, data_logical.segment_id, - &final_data_root) - || !cluster_runtime_visibility_candidate_root_matches( - &data_root, &final_data_root) + CLUSTER_TX_RESOLVE_VISIBILITY, &admission, CLUSTER_UNDO_PATH_RUNTIME_SHARED, + data_logical.owner_instance, data_logical.segment_id, &final_data_root) + || !cluster_runtime_visibility_candidate_root_matches(&data_root, &final_data_root) || cluster_runtime_visibility_candidate_acquire_until( - &data_logical, &admission, &guard, &cleanup, - ¤t_result, deadline) - != CLUSTER_UNDO_BLOCK0_CURRENT_HELD) + &data_logical, &admission, &guard, &cleanup, ¤t_result, deadline) + != CLUSTER_UNDO_BLOCK0_CURRENT_HELD) goto protected_done; phase_root = final_data_root; } outcome = cluster_runtime_visibility_origin_plan_recheck_data_held( - &plan, CLUSTER_TX_RESOLVE_VISIBILITY, &admission, &guard, - &phase_root, &resolution, &reason); + &plan, CLUSTER_TX_RESOLVE_VISIBILITY, &admission, &guard, &phase_root, &resolution, + &reason); if (outcome == CLUSTER_TX_UNKNOWN - || !cluster_tx_locator_reply_matches(locator, - &resolution.locator_echo) + || !cluster_tx_locator_reply_matches(locator, &resolution.locator_echo) || (outcome == CLUSTER_TX_IN_PROGRESS && sampled_result.status != CLUSTER_TT_STATUS_IN_PROGRESS) || (outcome == CLUSTER_TX_COMMITTED && sampled_result.status != CLUSTER_TT_STATUS_COMMITTED) - || (outcome == CLUSTER_TX_ABORTED - && sampled_result.status != CLUSTER_TT_STATUS_ABORTED) + || (outcome == CLUSTER_TX_ABORTED && sampled_result.status != CLUSTER_TT_STATUS_ABORTED) || (grant != 0 - && !cluster_ctrc_origin_grant_publishable( - &ctrc_key, &participant, grant))) + && !cluster_ctrc_origin_grant_publishable(&ctrc_key, &participant, grant))) goto protected_done; sampled = true; -protected_done: + protected_done: if (cleanup.active) { - if (cluster_runtime_visibility_candidate_release_until( - &guard, ¤t_result, deadline) + if (cluster_runtime_visibility_candidate_release_until(&guard, ¤t_result, + deadline) != CLUSTER_UNDO_BLOCK0_CURRENT_RELEASED) { cluster_undo_block0_current_cancel(&guard); sampled = false; @@ -2491,15 +2288,14 @@ cluster_runtime_visibility_current_mx_updater_provenance_exact( } } PG_END_ENSURE_ERROR_CLEANUP(cluster_runtime_visibility_candidate_cleanup, - PointerGetDatum(&cleanup)); + PointerGetDatum(&cleanup)); if (sampled && (cluster_epoch_get_current() != epoch - || !cluster_runtime_visibility_admission_current( - CLUSTER_TX_RESOLVE_VISIBILITY, &admission) + || !cluster_runtime_visibility_admission_current(CLUSTER_TX_RESOLVE_VISIBILITY, + &admission) || (grant != 0 - && !cluster_ctrc_origin_grant_publishable( - &ctrc_key, &participant, grant)))) + && !cluster_ctrc_origin_grant_publishable(&ctrc_key, &participant, grant)))) sampled = false; done: @@ -2510,8 +2306,8 @@ cluster_runtime_visibility_current_mx_updater_provenance_exact( *key_out = sampled_key; *result_out = sampled_result; *ctrc_grant_out = grant; - *participant_capability_generation_out = grant == 0 - ? 0 : participant.capability_record_generation; + *participant_capability_generation_out + = grant == 0 ? 0 : participant.capability_record_generation; if (grant != 0) *ctrc_key_out = ctrc_key; *canonical_locator_out = resolution.locator_echo; @@ -2523,8 +2319,7 @@ ClusterTxOutcome cluster_runtime_visibility_resolve_exact_origin_held( const ClusterTxLocator *locator, ClusterTxResolveMode mode, const ClusterSemanticAdmissionToken *admission, - const ClusterUndoBlock0Generation *expected_generation, - ClusterUndoBlock0CurrentGuard *guard, + const ClusterUndoBlock0Generation *expected_generation, ClusterUndoBlock0CurrentGuard *guard, const ClusterUndoBlock0ResolvedRoot *root, ClusterTxResolution *out, ClusterTxResolveReason *reason_out) { @@ -2554,20 +2349,17 @@ cluster_runtime_visibility_resolve_exact_origin_held( phase_cleanup.guard = guard; phase_cleanup.active = false; - if (locator == NULL || out == NULL || admission == NULL || guard == NULL - || root == NULL - || (mode != CLUSTER_TX_RESOLVE_VISIBILITY - && mode != CLUSTER_TX_RESOLVE_TERMINAL_CENSUS)) { - reason = locator == NULL ? CLUSTER_TX_RESOLVE_BAD_LOCATOR - : CLUSTER_TX_RESOLVE_PROTOCOL; + if (locator == NULL || out == NULL || admission == NULL || guard == NULL || root == NULL + || (mode != CLUSTER_TX_RESOLVE_VISIBILITY && mode != CLUSTER_TX_RESOLVE_TERMINAL_CENSUS)) { + reason = locator == NULL ? CLUSTER_TX_RESOLVE_BAD_LOCATOR : CLUSTER_TX_RESOLVE_PROTOCOL; goto done; } if (!cluster_runtime_visibility_admission_current(mode, admission)) { reason = CLUSTER_TX_RESOLVE_AUTHORITY_STALE; goto done; } - if (!uba_decode(locator->uba, &segment_id, &block_no, &tt_slot_offset, - &row_offset) || block_no == 0) { + if (!uba_decode(locator->uba, &segment_id, &block_no, &tt_slot_offset, &row_offset) + || block_no == 0) { reason = CLUSTER_TX_RESOLVE_BAD_UBA; goto done; } @@ -2599,18 +2391,17 @@ cluster_runtime_visibility_resolve_exact_origin_held( != CLUSTER_UNDO_BLOCK0_CURRENT_RELEASED) goto done; memset(guard, 0, sizeof(*guard)); - if (!cluster_runtime_visibility_origin_plan_canonical_logical( - &plan, &tt_logical) + if (!cluster_runtime_visibility_origin_plan_canonical_logical(&plan, &tt_logical) || !cluster_runtime_visibility_resolve_root_admitted( - mode, admission, CLUSTER_UNDO_PATH_RUNTIME_SHARED, - tt_logical.owner_instance, tt_logical.segment_id, &tt_root) + mode, admission, CLUSTER_UNDO_PATH_RUNTIME_SHARED, tt_logical.owner_instance, + tt_logical.segment_id, &tt_root) || !cluster_runtime_visibility_admission_current(mode, admission) - || cluster_runtime_visibility_candidate_acquire( - &tt_logical, admission, guard, &phase_cleanup, ¤t_result) + || cluster_runtime_visibility_candidate_acquire(&tt_logical, admission, guard, + &phase_cleanup, ¤t_result) != CLUSTER_UNDO_BLOCK0_CURRENT_HELD) goto done; - if (!cluster_runtime_visibility_origin_plan_sample_canonical_held( - &plan, mode, admission, guard, &tt_root, &reason)) + if (!cluster_runtime_visibility_origin_plan_sample_canonical_held(&plan, mode, admission, guard, + &tt_root, &reason)) goto done; if (cluster_runtime_visibility_candidate_release(guard, ¤t_result) != CLUSTER_UNDO_BLOCK0_CURRENT_RELEASED) @@ -2618,11 +2409,11 @@ cluster_runtime_visibility_resolve_exact_origin_held( phase_cleanup.active = false; memset(guard, 0, sizeof(*guard)); if (!cluster_runtime_visibility_resolve_root_admitted( - mode, admission, CLUSTER_UNDO_PATH_RUNTIME_SHARED, - logical.owner_instance, logical.segment_id, &final_root) + mode, admission, CLUSTER_UNDO_PATH_RUNTIME_SHARED, logical.owner_instance, + logical.segment_id, &final_root) || !cluster_runtime_visibility_candidate_root_matches(root, &final_root) - || cluster_runtime_visibility_candidate_acquire( - &logical, admission, guard, &phase_cleanup, ¤t_result) + || cluster_runtime_visibility_candidate_acquire(&logical, admission, guard, &phase_cleanup, + ¤t_result) != CLUSTER_UNDO_BLOCK0_CURRENT_HELD) goto done; outcome = cluster_runtime_visibility_origin_plan_recheck_data_internal( @@ -2665,18 +2456,16 @@ cluster_runtime_visibility_resolve_exact_origin_admitted( *reason_out = reason; memset(&root, 0, sizeof(root)); if (locator == NULL || out == NULL || admission == NULL - || (mode != CLUSTER_TX_RESOLVE_VISIBILITY - && mode != CLUSTER_TX_RESOLVE_TERMINAL_CENSUS)) { - reason = locator == NULL ? CLUSTER_TX_RESOLVE_BAD_LOCATOR - : CLUSTER_TX_RESOLVE_PROTOCOL; + || (mode != CLUSTER_TX_RESOLVE_VISIBILITY && mode != CLUSTER_TX_RESOLVE_TERMINAL_CENSUS)) { + reason = locator == NULL ? CLUSTER_TX_RESOLVE_BAD_LOCATOR : CLUSTER_TX_RESOLVE_PROTOCOL; goto done; } if (!cluster_runtime_visibility_admission_current(mode, admission)) { reason = CLUSTER_TX_RESOLVE_AUTHORITY_STALE; goto done; } - if (!uba_decode(locator->uba, &segment_id, &block_no, &tt_slot_offset, - &row_offset) || block_no == 0) { + if (!uba_decode(locator->uba, &segment_id, &block_no, &tt_slot_offset, &row_offset) + || block_no == 0) { reason = CLUSTER_TX_RESOLVE_BAD_UBA; goto done; } @@ -2696,26 +2485,25 @@ cluster_runtime_visibility_resolve_exact_origin_admitted( logical.owner_instance = (uint8)((uint32)origin + 1); logical.segment_id = segment_id; if (!cluster_runtime_visibility_resolve_root_admitted( - mode, admission, CLUSTER_UNDO_PATH_RUNTIME_SHARED, - logical.owner_instance, logical.segment_id, &root)) + mode, admission, CLUSTER_UNDO_PATH_RUNTIME_SHARED, logical.owner_instance, + logical.segment_id, &root)) goto done; cluster_runtime_visibility_ensure_exit_hooks(); PG_ENSURE_ERROR_CLEANUP(cluster_runtime_visibility_candidate_cleanup, PointerGetDatum(&cleanup)); { - if (cluster_runtime_visibility_candidate_acquire( - &logical, admission, &guard, &cleanup, ¤t_result) + if (cluster_runtime_visibility_candidate_acquire(&logical, admission, &guard, &cleanup, + ¤t_result) != CLUSTER_UNDO_BLOCK0_CURRENT_HELD) goto candidate_done; held = true; outcome = cluster_runtime_visibility_resolve_exact_origin_held( locator, mode, admission, NULL, &guard, &root, out, &reason); -candidate_done: + candidate_done: if (cleanup.active) { - if (cluster_runtime_visibility_candidate_release( - &guard, ¤t_result) + if (cluster_runtime_visibility_candidate_release(&guard, ¤t_result) != CLUSTER_UNDO_BLOCK0_CURRENT_RELEASED) { cluster_undo_block0_current_cancel(&guard); outcome = CLUSTER_TX_UNKNOWN; @@ -2726,7 +2514,7 @@ cluster_runtime_visibility_resolve_exact_origin_admitted( } } PG_END_ENSURE_ERROR_CLEANUP(cluster_runtime_visibility_candidate_cleanup, - PointerGetDatum(&cleanup)); + PointerGetDatum(&cleanup)); if (!held) goto done; @@ -2774,49 +2562,37 @@ cluster_runtime_visibility_resolve_terminal_census_retained_remote_exact( if (reason_out != NULL) *reason_out = reason; if (locator == NULL || out == NULL || admission == NULL - || locator->itl_kind != ITL_FLAG_NEEDS_CLEANOUT - || locator->tt_wrap != TT_WRAP_INVALID - || !TransactionIdIsNormal(locator->xid) - || !SCN_VALID(retained_commit_scn) - || admission->formation_epoch > UINT32_MAX) - { - reason = locator == NULL ? CLUSTER_TX_RESOLVE_BAD_LOCATOR - : CLUSTER_TX_RESOLVE_PROTOCOL; + || locator->itl_kind != ITL_FLAG_NEEDS_CLEANOUT || locator->tt_wrap != TT_WRAP_INVALID + || !TransactionIdIsNormal(locator->xid) || !SCN_VALID(retained_commit_scn) + || admission->formation_epoch > UINT32_MAX) { + reason = locator == NULL ? CLUSTER_TX_RESOLVE_BAD_LOCATOR : CLUSTER_TX_RESOLVE_PROTOCOL; goto failed; } - if (!cluster_runtime_visibility_admission_current( - CLUSTER_TX_RESOLVE_TERMINAL_CENSUS, admission)) - { + if (!cluster_runtime_visibility_admission_current(CLUSTER_TX_RESOLVE_TERMINAL_CENSUS, + admission)) { reason = CLUSTER_TX_RESOLVE_AUTHORITY_STALE; goto failed; } - if (!uba_decode(locator->uba, &segment_id, &block_no, &tt_slot_offset, - &row_offset) + if (!uba_decode(locator->uba, &segment_id, &block_no, &tt_slot_offset, &row_offset) || block_no == 0 || segment_id == 0 || segment_id > UINT16_MAX - || tt_slot_offset >= TT_SLOTS_PER_SEGMENT) - { + || tt_slot_offset >= TT_SLOTS_PER_SEGMENT) { reason = CLUSTER_TX_RESOLVE_BAD_UBA; goto failed; } origin = uba_origin_node_id(locator->uba); - if (origin == InvalidNodeId || cluster_node_id < 0 - || origin == (NodeId) cluster_node_id) - { + if (origin == InvalidNodeId || cluster_node_id < 0 || origin == (NodeId)cluster_node_id) { reason = CLUSTER_TX_RESOLVE_BAD_UBA; goto failed; } verdict = cluster_undo_verdict_resolve_freshref_c1b_pair( - (int) origin, segment_id, locator->xid, locator->xid, - (uint32) tt_slot_offset + 1, - (uint32) admission->formation_epoch, retained_commit_scn, - InvalidScn); + (int)origin, segment_id, locator->xid, locator->xid, (uint32)tt_slot_offset + 1, + (uint32)admission->formation_epoch, retained_commit_scn, InvalidScn); if (verdict.kind != CLUSTER_UNDO_VERDICT_COMMITTED_EXACT || verdict.commit_scn != retained_commit_scn) goto failed; - if (!cluster_runtime_visibility_admission_current( - CLUSTER_TX_RESOLVE_TERMINAL_CENSUS, admission)) - { + if (!cluster_runtime_visibility_admission_current(CLUSTER_TX_RESOLVE_TERMINAL_CENSUS, + admission)) { reason = CLUSTER_TX_RESOLVE_AUTHORITY_STALE; goto failed; } @@ -2830,9 +2606,8 @@ cluster_runtime_visibility_resolve_terminal_census_retained_remote_exact( if (out->authority.origin_epoch != admission->formation_epoch || XLogRecPtrIsInvalid(out->authority.live_hwm_lsn) || !SCN_VALID(out->authority.authority_scn) - || !cluster_runtime_visibility_admission_current( - CLUSTER_TX_RESOLVE_TERMINAL_CENSUS, admission)) - { + || !cluster_runtime_visibility_admission_current(CLUSTER_TX_RESOLVE_TERMINAL_CENSUS, + admission)) { reason = CLUSTER_TX_RESOLVE_AUTHORITY_STALE; goto failed; } @@ -2841,7 +2616,8 @@ cluster_runtime_visibility_resolve_terminal_census_retained_remote_exact( return CLUSTER_TX_COMMITTED; failed: - memset(out, 0, sizeof(*out)); + if (out != NULL) + memset(out, 0, sizeof(*out)); if (reason_out != NULL) *reason_out = reason; return CLUSTER_TX_UNKNOWN; @@ -2856,9 +2632,9 @@ cluster_runtime_visibility_resolve_terminal_census_retained_remote_exact( */ ClusterTxOutcome cluster_runtime_visibility_resolve_exact_origin(const ClusterTxLocator *locator, - ClusterTxResolveMode mode, uint64 formation_epoch, - ClusterTxResolution *out, - ClusterTxResolveReason *reason_out) + ClusterTxResolveMode mode, uint64 formation_epoch, + ClusterTxResolution *out, + ClusterTxResolveReason *reason_out) { PGAlignedBlock record_buf; const UndoRecordHeader *record; @@ -2887,9 +2663,7 @@ cluster_runtime_visibility_resolve_exact_origin(const ClusterTxLocator *locator, reason = CLUSTER_TX_RESOLVE_BAD_LOCATOR; goto unknown; } - if (out == NULL - || (unsigned int)mode - > (unsigned int)CLUSTER_TX_RESOLVE_TERMINAL_CENSUS) { + if (out == NULL || (unsigned int)mode > (unsigned int)CLUSTER_TX_RESOLVE_TERMINAL_CENSUS) { reason = CLUSTER_TX_RESOLVE_PROTOCOL; goto unknown; } @@ -2925,16 +2699,15 @@ cluster_runtime_visibility_resolve_exact_origin(const ClusterTxLocator *locator, && SCN_VALID(commit_scn)) { outcome = CLUSTER_TX_COMMITTED; } else { - if (!cluster_tt_slot_durable_read_exact_stable(record->tt_slot_segment_id, - tt_slot_offset, locator->xid, - locator->tt_wrap, &exact_slot)) { + if (!cluster_tt_slot_durable_read_exact_stable(record->tt_slot_segment_id, tt_slot_offset, + locator->xid, locator->tt_wrap, + &exact_slot)) { reason = CLUSTER_TX_RESOLVE_AUTHORITY_UNAVAILABLE; goto unknown; } native_status = cluster_runtime_visibility_direct_xid_status(locator->xid); - if ((exact_slot.status == TT_SLOT_COMMITTED - && native_status == TRANSACTION_STATUS_ABORTED) + if ((exact_slot.status == TT_SLOT_COMMITTED && native_status == TRANSACTION_STATUS_ABORTED) || (exact_slot.status == TT_SLOT_ABORTED && native_status == TRANSACTION_STATUS_COMMITTED)) { reason = CLUSTER_TX_RESOLVE_AUTHORITY_CONFLICT; @@ -2951,8 +2724,8 @@ cluster_runtime_visibility_resolve_exact_origin(const ClusterTxLocator *locator, goto unknown; top_xid = subtrans.xids[subtrans.count - 1]; native_status = cluster_runtime_visibility_direct_xid_status(top_xid); - native_status = cluster_runtime_visibility_recheck_prepared(top_xid, - native_status, &prepared); + native_status + = cluster_runtime_visibility_recheck_prepared(top_xid, native_status, &prepared); if (!cluster_runtime_visibility_recheck_subtrans(&subtrans, &reason)) goto unknown; @@ -3009,8 +2782,7 @@ cluster_runtime_visibility_resolve_exact_origin(const ClusterTxLocator *locator, goto unknown; } outcome = CLUSTER_TX_ABORTED; - } - else if (native_status == TRANSACTION_STATUS_IN_PROGRESS) { + } else if (native_status == TRANSACTION_STATUS_IN_PROGRESS) { if (prepared && (exact_slot.status == TT_SLOT_ACTIVE || exact_slot.status == TT_SLOT_ABORTED)) { @@ -3237,10 +3009,9 @@ cluster_undo_block_fetch_for_visibility(int origin_node, UBA uba, char *out_page */ static bool rtvis_try_origin_verdict(int origin_node, uint32 undo_segment_id, TransactionId raw_xid, - uint32 expected_tt_slot_id, uint32 ref_epoch, - SCN freshref_pair_scn, SCN demand_scn, SCN read_scn, - bool authoritative, bool *out_committed, bool *out_in_progress, - SCN *out_commit_scn, bool *out_commit_scn_is_bound) + uint32 expected_tt_slot_id, uint32 ref_epoch, SCN freshref_pair_scn, + SCN demand_scn, SCN read_scn, bool authoritative, bool *out_committed, + bool *out_in_progress, SCN *out_commit_scn, bool *out_commit_scn_is_bound) { ClusterGcsUndoVerdictPage verdict; ClusterLiveAuthority auth; @@ -3264,13 +3035,12 @@ rtvis_try_origin_verdict(int origin_node, uint32 undo_segment_id, TransactionId } cluster_rtvis_verdict_note_wire(); - if (freshref_pair - ? !cluster_gcs_block_undo_freshref_c1b_pair_fetch_and_wait( - (int32)origin_node, undo_segment_id, expected_tt_slot_id, raw_xid, - ref_epoch, freshref_pair_scn, &verdict, &auth) - : !cluster_gcs_block_undo_verdict_fetch_and_wait( - (int32)origin_node, undo_segment_id, expected_tt_slot_id, raw_xid, - authoritative, &verdict, &auth)) { + if (freshref_pair ? !cluster_gcs_block_undo_freshref_c1b_pair_fetch_and_wait( + (int32)origin_node, undo_segment_id, expected_tt_slot_id, raw_xid, + ref_epoch, freshref_pair_scn, &verdict, &auth) + : !cluster_gcs_block_undo_verdict_fetch_and_wait( + (int32)origin_node, undo_segment_id, expected_tt_slot_id, raw_xid, + authoritative, &verdict, &auth)) { cluster_rtvis_verdict_note_failclosed(); return false; } @@ -3281,16 +3051,14 @@ rtvis_try_origin_verdict(int origin_node, uint32 undo_segment_id, TransactionId cluster_scn_observe((SCN)verdict.commit_scn); cluster_scn_observe(auth.authority_scn); - if (!cluster_vis_live_authority_covers( - freshref_pair ? freshref_pair_scn : demand_scn, auth)) { + if (!cluster_vis_live_authority_covers(freshref_pair ? freshref_pair_scn : demand_scn, auth)) { cluster_vis_bump_covers_scn_refuse_count(); /* spec-7.1a D6 */ cluster_vis53r97_note_covers_refuse(); /* spec-7.1 D0 census (union) */ cluster_rtvis_verdict_note_failclosed(); return false; } if (freshref_pair - && (verdict.verdict - != (uint8)CLUSTER_GCS_UNDO_VERDICT_COMMITTED_EXACT + && (verdict.verdict != (uint8)CLUSTER_GCS_UNDO_VERDICT_COMMITTED_EXACT || verdict.commit_scn != freshref_pair_scn)) { cluster_rtvis_verdict_note_failclosed(); return false; @@ -3309,8 +3077,7 @@ rtvis_try_origin_verdict(int origin_node, uint32 undo_segment_id, TransactionId return false; } *out_in_progress = true; - elog(DEBUG1, - "rtvis verdict: xid %u origin %d IN_PROGRESS exact segment %u slot %u", + elog(DEBUG1, "rtvis verdict: xid %u origin %d IN_PROGRESS exact segment %u slot %u", raw_xid, origin_node, undo_segment_id, expected_tt_slot_id); return true; @@ -3394,10 +3161,9 @@ rtvis_try_origin_verdict(int origin_node, uint32 undo_segment_id, TransactionId static bool rtvis_try_resolve_remote_internal(int origin_node, uint32 undo_segment_id, uint32 expected_tt_slot_id, TransactionId raw_xid, - uint32 ref_epoch, SCN freshref_pair_scn, - SCN read_scn, bool authoritative, bool *out_committed, - bool *out_in_progress, SCN *out_commit_scn, - bool *out_commit_scn_is_bound) + uint32 ref_epoch, SCN freshref_pair_scn, SCN read_scn, + bool authoritative, bool *out_committed, bool *out_in_progress, + SCN *out_commit_scn, bool *out_commit_scn_is_bound) { PGAlignedBlock page; ClusterLiveAuthority auth; @@ -3536,10 +3302,10 @@ rtvis_try_resolve_remote_internal(int origin_node, uint32 undo_segment_id, * fetch/covers miss proves nothing either — ask the origin for the * complete own-TT verdict instead of failing closed outright. */ - if (rtvis_try_origin_verdict( - origin_node, undo_segment_id, raw_xid, expected_tt_slot_id, ref_epoch, - freshref_pair_scn, demand_scn, read_scn, authoritative, out_committed, - out_in_progress, out_commit_scn, out_commit_scn_is_bound)) { + if (rtvis_try_origin_verdict(origin_node, undo_segment_id, raw_xid, expected_tt_slot_id, + ref_epoch, freshref_pair_scn, demand_scn, read_scn, authoritative, + out_committed, out_in_progress, out_commit_scn, + out_commit_scn_is_bound)) { if (*out_in_progress) { /* Non-terminal positive proof: do not fold it into either of the * terminal committed/aborted census buckets. */ @@ -3561,15 +3327,13 @@ bool cluster_runtime_visibility_try_resolve_remote(int origin_node, uint32 undo_segment_id, TransactionId raw_xid, SCN read_scn, bool authoritative, bool *out_committed, - SCN *out_commit_scn, - bool *out_commit_scn_is_bound) + SCN *out_commit_scn, bool *out_commit_scn_is_bound) { bool in_progress = false; - if (!rtvis_try_resolve_remote_internal( - origin_node, undo_segment_id, 0, raw_xid, 0, InvalidScn, - read_scn, authoritative, - out_committed, &in_progress, out_commit_scn, out_commit_scn_is_bound)) + if (!rtvis_try_resolve_remote_internal(origin_node, undo_segment_id, 0, raw_xid, 0, InvalidScn, + read_scn, authoritative, out_committed, &in_progress, + out_commit_scn, out_commit_scn_is_bound)) return false; if (in_progress) { cluster_rtvis_resolve_note_failclosed(); @@ -3632,21 +3396,19 @@ rtvis_resolve_own_xid(TransactionId raw_xid, SCN read_scn, bool ordinary_single) } static bool -rtvis_local_freshref_c1b_pair_eligible( - int origin_node, uint32 undo_segment_id, TransactionId raw_xid, - TransactionId ref_xid, uint32 expected_tt_slot_id, uint32 ref_epoch, - SCN retained_commit_scn) +rtvis_local_freshref_c1b_pair_eligible(int origin_node, uint32 undo_segment_id, + TransactionId raw_xid, TransactionId ref_xid, + uint32 expected_tt_slot_id, uint32 ref_epoch, + SCN retained_commit_scn) { uint64 current_epoch = cluster_epoch_get_current(); return origin_node == cluster_node_id && cluster_node_id >= 0 - && cluster_node_id < CLUSTER_MAX_NODES - && TransactionIdIsNormal(raw_xid) && ref_xid == raw_xid - && SCN_VALID(retained_commit_scn) && current_epoch <= UINT32_MAX - && ref_epoch == (uint32) current_epoch - && undo_segment_id > 0 && undo_segment_id <= UINT16_MAX - && expected_tt_slot_id >= 1 - && expected_tt_slot_id <= TT_SLOTS_PER_SEGMENT; + && cluster_node_id < CLUSTER_MAX_NODES && TransactionIdIsNormal(raw_xid) + && ref_xid == raw_xid && SCN_VALID(retained_commit_scn) && current_epoch <= UINT32_MAX + && ref_epoch == (uint32)current_epoch && undo_segment_id > 0 + && undo_segment_id <= UINT16_MAX && expected_tt_slot_id >= 1 + && expected_tt_slot_id <= TT_SLOTS_PER_SEGMENT; } static ClusterUndoVerdictResult @@ -3654,10 +3416,8 @@ rtvis_resolve_own_xid_freshref_c1b_pair(TransactionId raw_xid, uint32 undo_segme uint32 expected_tt_slot_id, SCN retained_commit_scn, SCN read_scn) { - ClusterUndoVerdictResult result = { - .kind = CLUSTER_UNDO_VERDICT_UNKNOWN_FAIL_CLOSED, - .commit_scn = InvalidScn, - .wrap = 0}; + ClusterUndoVerdictResult result + = { .kind = CLUSTER_UNDO_VERDICT_UNKNOWN_FAIL_CLOSED, .commit_scn = InvalidScn, .wrap = 0 }; uint16 wrap = 0; /* A local immutable read can consume an already-proved origin terminal. @@ -3745,39 +3505,29 @@ cluster_runtime_visibility_resolve_terminal_census_retained_local_exact( if (reason_out != NULL) *reason_out = reason; if (locator == NULL || out == NULL || admission == NULL - || locator->itl_kind != ITL_FLAG_NEEDS_CLEANOUT - || locator->tt_wrap != TT_WRAP_INVALID - || !TransactionIdIsNormal(locator->xid) - || !SCN_VALID(retained_commit_scn) - || admission->formation_epoch > UINT32_MAX) - { - reason = locator == NULL ? CLUSTER_TX_RESOLVE_BAD_LOCATOR - : CLUSTER_TX_RESOLVE_PROTOCOL; + || locator->itl_kind != ITL_FLAG_NEEDS_CLEANOUT || locator->tt_wrap != TT_WRAP_INVALID + || !TransactionIdIsNormal(locator->xid) || !SCN_VALID(retained_commit_scn) + || admission->formation_epoch > UINT32_MAX) { + reason = locator == NULL ? CLUSTER_TX_RESOLVE_BAD_LOCATOR : CLUSTER_TX_RESOLVE_PROTOCOL; goto failed; } - if (!cluster_runtime_visibility_admission_current( - CLUSTER_TX_RESOLVE_TERMINAL_CENSUS, admission)) - { + if (!cluster_runtime_visibility_admission_current(CLUSTER_TX_RESOLVE_TERMINAL_CENSUS, + admission)) { reason = CLUSTER_TX_RESOLVE_AUTHORITY_STALE; goto failed; } - if (!uba_decode(locator->uba, &segment_id, &block_no, &tt_slot_offset, - &row_offset) + if (!uba_decode(locator->uba, &segment_id, &block_no, &tt_slot_offset, &row_offset) || block_no == 0 || segment_id == 0 || segment_id > UINT16_MAX - || tt_slot_offset >= TT_SLOTS_PER_SEGMENT) - { + || tt_slot_offset >= TT_SLOTS_PER_SEGMENT) { reason = CLUSTER_TX_RESOLVE_BAD_UBA; goto failed; } origin = uba_origin_node_id(locator->uba); - if (origin == InvalidNodeId || cluster_node_id < 0 - || origin != (NodeId) cluster_node_id + if (origin == InvalidNodeId || cluster_node_id < 0 || origin != (NodeId)cluster_node_id || !cluster_crossnode_runtime_visibility || !rtvis_local_freshref_c1b_pair_eligible( - (int) origin, segment_id, locator->xid, locator->xid, - (uint32) tt_slot_offset + 1, - (uint32) admission->formation_epoch, retained_commit_scn)) - { + (int)origin, segment_id, locator->xid, locator->xid, (uint32)tt_slot_offset + 1, + (uint32)admission->formation_epoch, retained_commit_scn)) { reason = CLUSTER_TX_RESOLVE_BAD_UBA; goto failed; } @@ -3787,9 +3537,8 @@ cluster_runtime_visibility_resolve_terminal_census_retained_local_exact( if (verdict.kind != CLUSTER_UNDO_VERDICT_COMMITTED_EXACT || verdict.commit_scn != retained_commit_scn) goto failed; - if (!cluster_runtime_visibility_admission_current( - CLUSTER_TX_RESOLVE_TERMINAL_CENSUS, admission)) - { + if (!cluster_runtime_visibility_admission_current(CLUSTER_TX_RESOLVE_TERMINAL_CENSUS, + admission)) { reason = CLUSTER_TX_RESOLVE_AUTHORITY_STALE; goto failed; } @@ -3803,9 +3552,8 @@ cluster_runtime_visibility_resolve_terminal_census_retained_local_exact( if (out->authority.origin_epoch != admission->formation_epoch || XLogRecPtrIsInvalid(out->authority.live_hwm_lsn) || !SCN_VALID(out->authority.authority_scn) - || !cluster_runtime_visibility_admission_current( - CLUSTER_TX_RESOLVE_TERMINAL_CENSUS, admission)) - { + || !cluster_runtime_visibility_admission_current(CLUSTER_TX_RESOLVE_TERMINAL_CENSUS, + admission)) { reason = CLUSTER_TX_RESOLVE_AUTHORITY_STALE; goto failed; } @@ -3829,8 +3577,7 @@ cluster_runtime_visibility_resolve_terminal_census_retained_exact( { NodeId origin; - if (locator == NULL) - { + if (locator == NULL) { if (out != NULL) memset(out, 0, sizeof(*out)); if (reason_out != NULL) @@ -3838,7 +3585,7 @@ cluster_runtime_visibility_resolve_terminal_census_retained_exact( return CLUSTER_TX_UNKNOWN; } origin = uba_origin_node_id(locator->uba); - if (cluster_node_id >= 0 && origin == (NodeId) cluster_node_id) + if (cluster_node_id >= 0 && origin == (NodeId)cluster_node_id) return cluster_runtime_visibility_resolve_terminal_census_retained_local_exact( locator, retained_commit_scn, admission, out, reason_out); return cluster_runtime_visibility_resolve_terminal_census_retained_remote_exact( @@ -3897,10 +3644,10 @@ rtvis_authority_serve_block0(int origin_node, uint32 undo_segment_id, Transactio * verdict page. */ static ClusterUndoVerdictResult -cluster_undo_verdict_resolve_internal( - int origin_node, uint32 undo_segment_id, TransactionId raw_xid, - uint32 expected_tt_slot_id, SCN read_scn, bool authoritative, - TransactionId ref_xid, uint32 ref_epoch, SCN freshref_pair_scn) +cluster_undo_verdict_resolve_internal(int origin_node, uint32 undo_segment_id, + TransactionId raw_xid, uint32 expected_tt_slot_id, + SCN read_scn, bool authoritative, TransactionId ref_xid, + uint32 ref_epoch, SCN freshref_pair_scn) { ClusterUndoVerdictResult unknown = { .kind = CLUSTER_UNDO_VERDICT_UNKNOWN_FAIL_CLOSED, .commit_scn = InvalidScn, .wrap = 0 }; @@ -3917,14 +3664,13 @@ cluster_undo_verdict_resolve_internal( if (freshref_pair && (!authoritative || !(origin_node == cluster_node_id - ? rtvis_local_freshref_c1b_pair_eligible( - origin_node, undo_segment_id, raw_xid, ref_xid, - expected_tt_slot_id, ref_epoch, freshref_pair_scn) + ? rtvis_local_freshref_c1b_pair_eligible(origin_node, undo_segment_id, raw_xid, + ref_xid, expected_tt_slot_id, + ref_epoch, freshref_pair_scn) : cluster_vis_freshref_c1b_pair_request_eligible( - raw_xid, ref_xid, true, freshref_pair_scn, - ref_epoch, cluster_epoch_get_current(), origin_node, - cluster_node_id, undo_segment_id, - expected_tt_slot_id)))) + raw_xid, ref_xid, true, freshref_pair_scn, ref_epoch, + cluster_epoch_get_current(), origin_node, cluster_node_id, + undo_segment_id, expected_tt_slot_id)))) return unknown; /* @@ -4023,31 +3769,26 @@ cluster_undo_verdict_resolve_internal( * unchanged pair request below. This creates no new proof kind, authority * or state, and a generic bound remains a bound. */ - if (rtvis_try_resolve_remote_internal( - origin_node, undo_segment_id, expected_tt_slot_id, raw_xid, - 0, InvalidScn, read_scn, true, &committed, &in_progress, - &commit_scn, &is_bound)) { + if (rtvis_try_resolve_remote_internal(origin_node, undo_segment_id, expected_tt_slot_id, + raw_xid, 0, InvalidScn, read_scn, true, &committed, + &in_progress, &commit_scn, &is_bound)) { if (in_progress) { - ClusterUndoVerdictResult live - = { .kind = CLUSTER_UNDO_VERDICT_IN_PROGRESS, - .commit_scn = InvalidScn, - .wrap = 0 }; + ClusterUndoVerdictResult live = { .kind = CLUSTER_UNDO_VERDICT_IN_PROGRESS, + .commit_scn = InvalidScn, + .wrap = 0 }; return live; } - return cluster_undo_verdict_from_resolve(true, committed, commit_scn, - is_bound); + return cluster_undo_verdict_from_resolve(true, committed, commit_scn, is_bound); } } - if (rtvis_try_resolve_remote_internal( - origin_node, undo_segment_id, expected_tt_slot_id, raw_xid, - ref_epoch, freshref_pair_scn, read_scn, authoritative, &committed, - &in_progress, &commit_scn, &is_bound)) { + if (rtvis_try_resolve_remote_internal(origin_node, undo_segment_id, expected_tt_slot_id, + raw_xid, ref_epoch, freshref_pair_scn, read_scn, + authoritative, &committed, &in_progress, &commit_scn, + &is_bound)) { if (in_progress) { ClusterUndoVerdictResult live - = { .kind = CLUSTER_UNDO_VERDICT_IN_PROGRESS, - .commit_scn = InvalidScn, - .wrap = 0 }; + = { .kind = CLUSTER_UNDO_VERDICT_IN_PROGRESS, .commit_scn = InvalidScn, .wrap = 0 }; return live; } @@ -4057,24 +3798,23 @@ cluster_undo_verdict_resolve_internal( } ClusterUndoVerdictResult -cluster_undo_verdict_resolve(int origin_node, uint32 undo_segment_id, - TransactionId raw_xid, uint32 expected_tt_slot_id, - SCN read_scn, bool authoritative) +cluster_undo_verdict_resolve(int origin_node, uint32 undo_segment_id, TransactionId raw_xid, + uint32 expected_tt_slot_id, SCN read_scn, bool authoritative) { - return cluster_undo_verdict_resolve_internal( - origin_node, undo_segment_id, raw_xid, expected_tt_slot_id, read_scn, - authoritative, InvalidTransactionId, 0, InvalidScn); + return cluster_undo_verdict_resolve_internal(origin_node, undo_segment_id, raw_xid, + expected_tt_slot_id, read_scn, authoritative, + InvalidTransactionId, 0, InvalidScn); } ClusterUndoVerdictResult -cluster_undo_verdict_resolve_freshref_c1b_pair( - int origin_node, uint32 undo_segment_id, TransactionId raw_xid, - TransactionId ref_xid, uint32 expected_tt_slot_id, uint32 ref_epoch, - SCN cached_commit_scn, SCN read_scn) -{ - return cluster_undo_verdict_resolve_internal( - origin_node, undo_segment_id, raw_xid, expected_tt_slot_id, read_scn, - true, ref_xid, ref_epoch, cached_commit_scn); +cluster_undo_verdict_resolve_freshref_c1b_pair(int origin_node, uint32 undo_segment_id, + TransactionId raw_xid, TransactionId ref_xid, + uint32 expected_tt_slot_id, uint32 ref_epoch, + SCN cached_commit_scn, SCN read_scn) +{ + return cluster_undo_verdict_resolve_internal(origin_node, undo_segment_id, raw_xid, + expected_tt_slot_id, read_scn, true, ref_xid, + ref_epoch, cached_commit_scn); } #endif /* USE_PGRAC_CLUSTER */ diff --git a/src/backend/cluster/cluster_runtime_visibility_policy.c b/src/backend/cluster/cluster_runtime_visibility_policy.c index 60c12e6ea53..365d7c81c78 100644 --- a/src/backend/cluster/cluster_runtime_visibility_policy.c +++ b/src/backend/cluster/cluster_runtime_visibility_policy.c @@ -91,21 +91,18 @@ cluster_vis_live_authority_covers_policy(SCN demand_scn, ClusterLiveAuthority au } bool -cluster_vis_freshref_c1b_pair_request_eligible( - TransactionId raw_xid, TransactionId ref_xid, bool has_cached_status, - SCN cached_commit_scn, uint32 ref_epoch, uint64 current_epoch, - int32 origin_node, int32 local_node, uint32 segment_id, - uint32 expected_tt_slot_id) +cluster_vis_freshref_c1b_pair_request_eligible(TransactionId raw_xid, TransactionId ref_xid, + bool has_cached_status, SCN cached_commit_scn, + uint32 ref_epoch, uint64 current_epoch, + int32 origin_node, int32 local_node, + uint32 segment_id, uint32 expected_tt_slot_id) { - return TransactionIdIsNormal(raw_xid) && ref_xid == raw_xid - && has_cached_status && SCN_VALID(cached_commit_scn) - && current_epoch <= UINT32_MAX - && ref_epoch == (uint32)current_epoch - && origin_node >= 0 && origin_node < CLUSTER_MAX_NODES - && local_node >= 0 && local_node < CLUSTER_MAX_NODES - && origin_node != local_node && segment_id > 0 - && segment_id <= UINT16_MAX && expected_tt_slot_id >= 1 - && expected_tt_slot_id <= TT_SLOTS_PER_SEGMENT; + return TransactionIdIsNormal(raw_xid) && ref_xid == raw_xid && has_cached_status + && SCN_VALID(cached_commit_scn) && current_epoch <= UINT32_MAX + && ref_epoch == (uint32)current_epoch && origin_node >= 0 + && origin_node < CLUSTER_MAX_NODES && local_node >= 0 && local_node < CLUSTER_MAX_NODES + && origin_node != local_node && segment_id > 0 && segment_id <= UINT16_MAX + && expected_tt_slot_id >= 1 && expected_tt_slot_id <= TT_SLOTS_PER_SEGMENT; } /* diff --git a/src/backend/cluster/cluster_scn.c b/src/backend/cluster/cluster_scn.c index 33dbea324a5..55e19a83290 100644 --- a/src/backend/cluster/cluster_scn.c +++ b/src/backend/cluster/cluster_scn.c @@ -1932,10 +1932,9 @@ cluster_scn_lmon_drain_boc_broadcast(void) break; } } - frontier_advanced - = cluster_boc_event_publish && SCN_VALID(frontier) - && (!SCN_VALID(last_fanout_frontier) - || scn_total_cmp(frontier, last_fanout_frontier) > 0); + frontier_advanced = cluster_boc_event_publish && SCN_VALID(frontier) + && (!SCN_VALID(last_fanout_frontier) + || scn_total_cmp(frontier, last_fanout_frontier) > 0); new_publication = sweep_count != last_drained_sweep_count || frontier_advanced || (event_pending && !have_retry); if (!new_publication && !have_retry) @@ -1971,8 +1970,7 @@ cluster_scn_lmon_drain_boc_broadcast(void) last_fanout_frontier = frontier; for (peer = 0; peer < CLUSTER_MAX_NODES; peer++) { - peer_retry[peer].pending - = per_peer[peer] == CLUSTER_IC_FANOUT_NOT_ADMITTED; + peer_retry[peer].pending = per_peer[peer] == CLUSTER_IC_FANOUT_NOT_ADMITTED; if (peer_retry[peer].pending) { peer_retry[peer].payload_len = send_len; peer_retry[peer].frontier = frontier; @@ -1993,9 +1991,8 @@ cluster_scn_lmon_drain_boc_broadcast(void) cluster_scn_boc_payload_encode(peer_retry[peer].frontier, retry_payload); retry_send_payload = retry_payload; } - send_result = cluster_ic_send_envelope(PGRAC_IC_MSG_BOC_BROADCAST, peer, - retry_send_payload, - peer_retry[peer].payload_len); + send_result = cluster_ic_send_envelope( + PGRAC_IC_MSG_BOC_BROADCAST, peer, retry_send_payload, peer_retry[peer].payload_len); switch (send_result) { case CLUSTER_IC_SEND_DONE: per_peer[peer] = CLUSTER_IC_FANOUT_DONE; diff --git a/src/backend/cluster/cluster_semantic_activation.c b/src/backend/cluster/cluster_semantic_activation.c index 9e0d9892eb7..0799812d94e 100644 --- a/src/backend/cluster/cluster_semantic_activation.c +++ b/src/backend/cluster/cluster_semantic_activation.c @@ -59,12 +59,10 @@ #define CLUSTER_SEMANTIC_ADMISSION_SNAPSHOT_TRIES 3 #define CLUSTER_SEMANTIC_ADMISSION_COUNTER_TRIES 16 #define CLUSTER_SEMANTIC_UTILITY_WAIT_STEP_US 10000L -#define CLUSTER_SEMANTIC_REPLACEMENT_REQUIRED_CAPS \ - (PGRAC_IC_HELLO_CAP_SEMANTIC_ACTIVATION_V1 | PGRAC_IC_HELLO_CAP_R4_SYNC_CR_V1 \ - | PGRAC_IC_HELLO_CAP_CANDIDATE2_CORRECTED_A1_V1 \ - | PGRAC_IC_HELLO_CAP_UNDO_ROOT_DESCRIPTOR_V1) -#define CLUSTER_REPLACEMENT_PHASE3_REQUIRED_CAPS \ - PGRAC_IC_HELLO_CAP_CANDIDATE2_CORRECTED_A1_V1 +#define CLUSTER_SEMANTIC_REPLACEMENT_REQUIRED_CAPS \ + (PGRAC_IC_HELLO_CAP_SEMANTIC_ACTIVATION_V1 | PGRAC_IC_HELLO_CAP_R4_SYNC_CR_V1 \ + | PGRAC_IC_HELLO_CAP_CANDIDATE2_CORRECTED_A1_V1 | PGRAC_IC_HELLO_CAP_UNDO_ROOT_DESCRIPTOR_V1) +#define CLUSTER_REPLACEMENT_PHASE3_REQUIRED_CAPS PGRAC_IC_HELLO_CAP_CANDIDATE2_CORRECTED_A1_V1 typedef struct ClusterSemanticRecordSample { bool readable; @@ -124,37 +122,32 @@ StaticAssertDecl(offsetof(ClusterSemanticActivationShmem, inflight) == 588, "semantic admission inflight offset must remain stable"); StaticAssertDecl(sizeof(ClusterSemanticActivationShmem) == 1104, "semantic activation shared gate must retain its frozen layout"); -StaticAssertDecl(offsetof(ClusterSemanticActivationUtilityMailboxShmem, - utility_request_seq) == 0, +StaticAssertDecl(offsetof(ClusterSemanticActivationUtilityMailboxShmem, utility_request_seq) == 0, "semantic utility request sequence offset must remain stable"); -StaticAssertDecl(offsetof(ClusterSemanticActivationUtilityMailboxShmem, - utility_mailbox_state) == 16, +StaticAssertDecl(offsetof(ClusterSemanticActivationUtilityMailboxShmem, utility_mailbox_state) + == 16, "semantic utility mailbox state offset must remain stable"); StaticAssertDecl(offsetof(ClusterSemanticActivationUtilityMailboxShmem, - utility_expected_record_generation) == 48, + utility_expected_record_generation) + == 48, "semantic utility expected generation offset must remain stable"); -StaticAssertDecl(offsetof(ClusterSemanticActivationUtilityMailboxShmem, - utility_result_feature_bit) == 64, +StaticAssertDecl(offsetof(ClusterSemanticActivationUtilityMailboxShmem, utility_result_feature_bit) + == 64, "semantic utility refusal feature offset must remain stable"); StaticAssertDecl(sizeof(ClusterSemanticActivationUtilityMailboxShmem) == 80, "semantic utility mailbox must retain its natural layout"); -StaticAssertDecl(offsetof(ClusterSemanticActivationPgrdSnapshotShmem, - publication_seq) == 0, +StaticAssertDecl(offsetof(ClusterSemanticActivationPgrdSnapshotShmem, publication_seq) == 0, "semantic PGRD snapshot publication sequence must be first"); -StaticAssertDecl(offsetof(ClusterSemanticActivationPgrdSnapshotShmem, - present) == 8, +StaticAssertDecl(offsetof(ClusterSemanticActivationPgrdSnapshotShmem, present) == 8, "semantic PGRD snapshot presence offset must remain stable"); -StaticAssertDecl(offsetof(ClusterSemanticActivationPgrdSnapshotShmem, - descriptor_bytes) == 16, +StaticAssertDecl(offsetof(ClusterSemanticActivationPgrdSnapshotShmem, descriptor_bytes) == 16, "semantic PGRD snapshot bytes offset must remain stable"); StaticAssertDecl(sizeof(ClusterSemanticActivationPgrdSnapshotShmem) == 528, "semantic PGRD snapshot must retain its natural layout"); static ClusterSemanticActivationShmem *SemanticActivationShmem = NULL; -static ClusterSemanticActivationUtilityMailboxShmem - *SemanticActivationUtilityMailbox = NULL; -static ClusterSemanticActivationPgrdSnapshotShmem - *SemanticActivationPgrdSnapshot = NULL; +static ClusterSemanticActivationUtilityMailboxShmem *SemanticActivationUtilityMailbox = NULL; +static ClusterSemanticActivationPgrdSnapshotShmem *SemanticActivationPgrdSnapshot = NULL; /* Startup observation only: 0 unproved, 1 clean, 2 not clean. Never authority. */ static pg_atomic_uint32 *SemanticActivationCleanStart = NULL; @@ -300,8 +293,7 @@ static uint64 semantic_activation_lmon_pgrd_request_seq; static uint64 semantic_activation_lmon_pgrd_utility_request_seq; static ClusterSemanticFormationBinding semantic_activation_lmon_pgrd_formation; static uint64 semantic_activation_lmon_pgrd_candidate_request_seq; -static uint8 semantic_activation_lmon_pgrd_candidate - [CLUSTER_UNDO_ROOT_DESCRIPTOR_BYTES]; +static uint8 semantic_activation_lmon_pgrd_candidate[CLUSTER_UNDO_ROOT_DESCRIPTOR_BYTES]; static uint64 semantic_activation_lmon_pgrd_read_request_seq; static uint64 semantic_activation_lmon_pgrd_read_utility_request_seq; static ClusterSemanticFormationBinding semantic_activation_lmon_pgrd_read_formation; @@ -322,39 +314,36 @@ static bool semantic_activation_record_cas_mailbox_submit( pg_attribute_unused(); static bool semantic_activation_record_cas_mailbox_poll_completion( uint64 request_seq, ClusterSemanticActivationResult *out_result) pg_attribute_unused(); -static bool semantic_activation_record_read_mailbox_submit( - uint64 *out_request_seq); +static bool semantic_activation_record_read_mailbox_submit(uint64 *out_request_seq); static int semantic_activation_authority_mailbox_owner(bool include_stop); static bool semantic_activation_record_read_mailbox_poll_completion( uint64 request_seq, ClusterSemanticActivationReadCompletion *out); static bool semantic_activation_authority_mailbox_submit( ClusterSemanticAuthorityRequestKind request_kind, uint64 expected_generation, uint64 expected_source_feature_bitmap, - const uint8 desired_bytes[CLUSTER_SEMANTIC_ACTIVATION_RECORD_BYTES], - uint64 *out_request_seq); -static bool semantic_activation_authority_mailbox_complete( - ClusterSemanticAuthorityRequestKind request_kind, uint64 request_seq, - ClusterSemanticActivationResult result); + const uint8 desired_bytes[CLUSTER_SEMANTIC_ACTIVATION_RECORD_BYTES], uint64 *out_request_seq); +static bool +semantic_activation_authority_mailbox_complete(ClusterSemanticAuthorityRequestKind request_kind, + uint64 request_seq, + ClusterSemanticActivationResult result); static bool semantic_activation_authority_mailbox_completion_matches( ClusterSemanticAuthorityRequestKind request_kind, uint64 request_seq); static bool semantic_activation_authority_mailbox_poll_completion( ClusterSemanticAuthorityRequestKind request_kind, uint64 request_seq, ClusterSemanticActivationResult *out_result); static bool semantic_activation_authority_request_formation_binding( - ClusterSemanticAuthorityRequestKind request_kind, - ClusterSemanticFormationBinding *out); -static bool semantic_activation_record_cas_formation_matches( - const ClusterSemanticFormationBinding *formation, - const ClusterSemanticActivationRecord *desired); + ClusterSemanticAuthorityRequestKind request_kind, ClusterSemanticFormationBinding *out); +static bool +semantic_activation_record_cas_formation_matches(const ClusterSemanticFormationBinding *formation, + const ClusterSemanticActivationRecord *desired); static void semantic_activation_pgrd_snapshot_clear(void); static bool semantic_activation_pgrd_snapshot_publish( const uint8 descriptor_bytes[CLUSTER_UNDO_ROOT_DESCRIPTOR_BYTES]); -static bool semantic_activation_pgrd_snapshot_copy( - uint8 descriptor_bytes[CLUSTER_UNDO_ROOT_DESCRIPTOR_BYTES]); +static bool +semantic_activation_pgrd_snapshot_copy(uint8 descriptor_bytes[CLUSTER_UNDO_ROOT_DESCRIPTOR_BYTES]); static bool semantic_activation_undo_root_descriptor_read_mailbox_poll_completion( uint64 request_seq, ClusterUndoRootDescriptorReadCompletion *out); -static bool semantic_activation_lmon_shared_pgrd_root_directory( - char root_directory[MAXPGPATH]); +static bool semantic_activation_lmon_shared_pgrd_root_directory(char root_directory[MAXPGPATH]); typedef enum SemanticActivationUtilityMailboxState { SEMANTIC_ACTIVATION_UTILITY_MAILBOX_IDLE = 0, @@ -372,20 +361,23 @@ typedef struct SemanticActivationUtilityRequest { ClusterSemanticActivationAction action; } SemanticActivationUtilityRequest; -static bool semantic_activation_utility_mailbox_submit( - ClusterSemanticActivationAction action, uint64 source_feature_bitmap, - uint64 target_feature_bitmap, uint64 rollback_feature_bitmap, - uint64 expected_record_generation, uint64 *out_request_seq); -static bool semantic_activation_utility_mailbox_poll( - SemanticActivationUtilityRequest *out); -static bool semantic_activation_utility_mailbox_complete( - uint64 request_seq, ClusterSemanticActivationResult result, - uint64 feature_bit, uint64 expected_generation); -static bool semantic_activation_utility_mailbox_poll_completion( - uint64 request_seq, ClusterSemanticActivationRefusal *out_refusal); +static bool semantic_activation_utility_mailbox_submit(ClusterSemanticActivationAction action, + uint64 source_feature_bitmap, + uint64 target_feature_bitmap, + uint64 rollback_feature_bitmap, + uint64 expected_record_generation, + uint64 *out_request_seq); +static bool semantic_activation_utility_mailbox_poll(SemanticActivationUtilityRequest *out); +static bool semantic_activation_utility_mailbox_complete(uint64 request_seq, + ClusterSemanticActivationResult result, + uint64 feature_bit, + uint64 expected_generation); +static bool +semantic_activation_utility_mailbox_poll_completion(uint64 request_seq, + ClusterSemanticActivationRefusal *out_refusal); static ClusterSemanticActivationResult -semantic_activation_utility_mailbox_wait( - uint64 request_seq, ClusterSemanticActivationRefusal *out_refusal); +semantic_activation_utility_mailbox_wait(uint64 request_seq, + ClusterSemanticActivationRefusal *out_refusal); typedef enum SemanticActivationState { SEMANTIC_ACTIVATION_STATE_INVALID = -1, @@ -470,8 +462,7 @@ typedef struct SemanticActivationAckIngressItem { typedef struct SemanticActivationAckIngress { uint64 producer_seq; uint64 consumer_seq; - SemanticActivationAckIngressItem - items[CLUSTER_SEMANTIC_ACTIVATION_ACK_INGRESS_CAPACITY]; + SemanticActivationAckIngressItem items[CLUSTER_SEMANTIC_ACTIVATION_ACK_INGRESS_CAPACITY]; } SemanticActivationAckIngress; typedef struct SemanticActivationAckPendingSend { @@ -493,8 +484,7 @@ typedef struct SemanticActivationAckRequestOrigin { typedef struct SemanticActivationAckStageAhead { uint32 count; - SemanticActivationAckIngressItem - items[SEMANTIC_ACTIVATION_ACK_STAGE_AHEAD_CAPACITY]; + SemanticActivationAckIngressItem items[SEMANTIC_ACTIVATION_ACK_STAGE_AHEAD_CAPACITY]; } SemanticActivationAckStageAhead; /* Process-local, single-slot retention for one exact stage-ahead request. @@ -535,14 +525,10 @@ typedef enum SemanticActivationAckSendResult { } SemanticActivationAckSendResult; static SemanticActivationAckIngress semantic_activation_ack_local_ingress; -static SemanticActivationAckPendingSend - semantic_activation_ack_local_pending_send; -static SemanticActivationAckRequestOrigin - semantic_activation_ack_local_request_origin; -static SemanticActivationAckStageAhead - semantic_activation_ack_local_stage_ahead; -static SemanticActivationAckRequestAhead - semantic_activation_ack_local_request_ahead; +static SemanticActivationAckPendingSend semantic_activation_ack_local_pending_send; +static SemanticActivationAckRequestOrigin semantic_activation_ack_local_request_origin; +static SemanticActivationAckStageAhead semantic_activation_ack_local_stage_ahead; +static SemanticActivationAckRequestAhead semantic_activation_ack_local_request_ahead; typedef struct SemanticActivationRestart { bool disabled; @@ -579,11 +565,10 @@ static uint64 semantic_activation_lmon_bit22_prepare_cas_seq = 0; static bool semantic_activation_lmon_bit22_prepare_cas_done = false; static uint64 semantic_activation_ack_ingress_result_count[3]; -StaticAssertDecl(sizeof(SemanticActivationAckTuple) - == CLUSTER_SEMANTIC_ACTIVATION_ACK_TUPLE_BYTES, +StaticAssertDecl(sizeof(SemanticActivationAckTuple) == CLUSTER_SEMANTIC_ACTIVATION_ACK_TUPLE_BYTES, "semantic activation ACK tuple must remain 64 bytes"); StaticAssertDecl(sizeof(ClusterSemanticActivationAckTableV1) - == CLUSTER_SEMANTIC_ACTIVATION_ACK_TABLE_BYTES, + == CLUSTER_SEMANTIC_ACTIVATION_ACK_TABLE_BYTES, "semantic activation ACK table must remain 16496 bytes"); StaticAssertDecl(sizeof(SemanticActivationAckIngressItem) == 136, "semantic activation ACK ingress item must remain 136 bytes"); @@ -592,41 +577,34 @@ StaticAssertDecl(sizeof(SemanticActivationAckIngress) == 34832, static ClusterSemanticActivationAckTableV1 *SemanticActivationAckTable = NULL; static bool semantic_activation_member_pgrd_read_mailbox_submit( - const ClusterSemanticActivationAckTableV1 *expected_table, - uint64 *out_request_seq); + const ClusterSemanticActivationAckTableV1 *expected_table, uint64 *out_request_seq); /* RF-ROOT P7 (contract): bit22 cutover round — member-side OPEN_APPLIED * stage apply. Round-parameterized (member set driven by the ACK table, * target must carry bit22); deliberately does NOT reuse the R4 * four-member hardcoded checks (contract option A). */ static bool semantic_activation_ack_member_open_applied_image_current( - const ClusterSemanticActivationAckTableV1 *image, - SemanticActivationAckTuple *out_self); + const ClusterSemanticActivationAckTableV1 *image, SemanticActivationAckTuple *out_self); static bool semantic_activation_ack_member_bit22_stage_image_current( - const ClusterSemanticActivationAckTableV1 *image, - uint32 stage, SemanticActivationAckTuple *out_self); + const ClusterSemanticActivationAckTableV1 *image, uint32 stage, + SemanticActivationAckTuple *out_self); static bool semantic_activation_ack_lmon_progress_member_open_applied( const ClusterSemanticActivationAckTableV1 *before); static bool semantic_activation_ack_lmon_finish_member_open_applied( - const ClusterSemanticActivationAckTableV1 *before, - bool latch_applied); + const ClusterSemanticActivationAckTableV1 *before, bool latch_applied); static bool semantic_activation_ack_lmon_finish_member_prepared( const ClusterSemanticActivationAckTableV1 *before, ClusterSemanticActivationResult callback_result); static bool semantic_activation_ack_member_prepared_image_current_bit22( - const ClusterSemanticActivationAckTableV1 *image, - SemanticActivationAckTuple *out_self); -static bool semantic_activation_ack_lmon_send_bit22_prepared_requests( - uint32 stage); + const ClusterSemanticActivationAckTableV1 *image, SemanticActivationAckTuple *out_self); +static bool semantic_activation_ack_lmon_send_bit22_prepared_requests(uint32 stage); static bool semantic_activation_ack_lmon_bit22_commit_applied_begin( - const ClusterSemanticActivationAckTableV1 *before, - uint64 current_members_lo, uint64 current_members_hi, - uint64 current_epoch, int32 current_coordinator_node, + const ClusterSemanticActivationAckTableV1 *before, uint64 current_members_lo, + uint64 current_members_hi, uint64 current_epoch, int32 current_coordinator_node, uint32 local_capability_word); static bool semantic_activation_ack_lmon_bit22_open_applied_begin( - const ClusterSemanticActivationAckTableV1 *before, - uint64 current_members_lo, uint64 current_members_hi, - uint64 current_epoch, int32 current_coordinator_node, + const ClusterSemanticActivationAckTableV1 *before, uint64 current_members_lo, + uint64 current_members_hi, uint64 current_epoch, int32 current_coordinator_node, uint32 local_capability_word); static bool semantic_activation_ack_lmon_bit22_advance(void); static bool semantic_activation_ack_lmon_progress_member_commit_applied_bit22( @@ -634,105 +612,101 @@ static bool semantic_activation_ack_lmon_progress_member_commit_applied_bit22( static bool semantic_activation_ack_lmon_progress_member_barrier_bit22( const ClusterSemanticActivationAckTableV1 *before); -static void semantic_activation_ack_ingress_init( - SemanticActivationAckIngress *ingress) pg_attribute_unused(); -static uint32 semantic_activation_ack_ingress_pending( - const SemanticActivationAckIngress *ingress) pg_attribute_unused(); -static bool semantic_activation_ack_ingress_push( - SemanticActivationAckIngress *ingress, - const SemanticActivationAckIngressItem *item) pg_attribute_unused(); -static bool semantic_activation_ack_ingress_poll( - SemanticActivationAckIngress *ingress, - SemanticActivationAckIngressItem *out) pg_attribute_unused(); -static SemanticActivationAckSendResult -semantic_activation_ack_pending_send_note_result( - SemanticActivationAckPendingSend *pending, int32 dest_node_id, - ClusterICSendResult send_result) pg_attribute_unused(); +static void semantic_activation_ack_ingress_init(SemanticActivationAckIngress *ingress) + pg_attribute_unused(); +static uint32 semantic_activation_ack_ingress_pending(const SemanticActivationAckIngress *ingress) + pg_attribute_unused(); +static bool semantic_activation_ack_ingress_push(SemanticActivationAckIngress *ingress, + const SemanticActivationAckIngressItem *item) + pg_attribute_unused(); +static bool semantic_activation_ack_ingress_poll(SemanticActivationAckIngress *ingress, + SemanticActivationAckIngressItem *out) + pg_attribute_unused(); +static SemanticActivationAckSendResult semantic_activation_ack_pending_send_note_result( + SemanticActivationAckPendingSend *pending, int32 dest_node_id, ClusterICSendResult send_result) + pg_attribute_unused(); static bool semantic_activation_ack_pending_send_begin_positive( - SemanticActivationAckPendingSend *pending, - const ClusterSemanticActivationAckWireV1 *request, - int32 local_node_id, - const SemanticActivationAckTuple *self) pg_attribute_unused(); + SemanticActivationAckPendingSend *pending, const ClusterSemanticActivationAckWireV1 *request, + int32 local_node_id, const SemanticActivationAckTuple *self) pg_attribute_unused(); static bool semantic_activation_ack_pending_send_begin_refused( - SemanticActivationAckPendingSend *pending, - const SemanticActivationAckIngressItem *item, + SemanticActivationAckPendingSend *pending, const SemanticActivationAckIngressItem *item, ClusterSemanticActivationResult reason) pg_attribute_unused(); -static bool semantic_activation_ack_lmon_begin_sample_round( - const SemanticActivationUtilityRequest *request, - const SemanticActivationAdmissionSnapshot *snapshot) +static bool +semantic_activation_ack_lmon_begin_sample_round(const SemanticActivationUtilityRequest *request, + const SemanticActivationAdmissionSnapshot *snapshot) + pg_attribute_unused(); +static bool +semantic_activation_ack_lmon_submit_prepare(const SemanticActivationUtilityRequest *request, + const SemanticActivationAdmissionSnapshot *snapshot) + pg_attribute_unused(); +static bool +semantic_activation_ack_lmon_install_prepare(const SemanticActivationUtilityRequest *request) + pg_attribute_unused(); +static bool +semantic_activation_ack_lmon_submit_commit(const SemanticActivationUtilityRequest *request, + const ClusterSemanticActivationRecord *prepare) + pg_attribute_unused(); +static bool +semantic_activation_ack_lmon_install_commit(const SemanticActivationUtilityRequest *request) + pg_attribute_unused(); +static bool +semantic_activation_ack_lmon_install_open(const SemanticActivationUtilityRequest *request) pg_attribute_unused(); -static bool semantic_activation_ack_lmon_submit_prepare( - const SemanticActivationUtilityRequest *request, - const SemanticActivationAdmissionSnapshot *snapshot) +static bool +semantic_activation_ack_lmon_begin_barrier_round(const SemanticActivationUtilityRequest *request, + const ClusterSemanticActivationRecord *prepare) pg_attribute_unused(); -static bool semantic_activation_ack_lmon_install_prepare( - const SemanticActivationUtilityRequest *request) pg_attribute_unused(); -static bool semantic_activation_ack_lmon_submit_commit( - const SemanticActivationUtilityRequest *request, - const ClusterSemanticActivationRecord *prepare) pg_attribute_unused(); -static bool semantic_activation_ack_lmon_install_commit( - const SemanticActivationUtilityRequest *request) pg_attribute_unused(); -static bool semantic_activation_ack_lmon_install_open( - const SemanticActivationUtilityRequest *request) pg_attribute_unused(); -static bool semantic_activation_ack_lmon_begin_barrier_round( - const SemanticActivationUtilityRequest *request, - const ClusterSemanticActivationRecord *prepare) pg_attribute_unused(); -static bool semantic_activation_snapshot( - SemanticActivationAdmissionSnapshot *snapshot); +static bool semantic_activation_snapshot(SemanticActivationAdmissionSnapshot *snapshot); static SemanticActivationAckIngressResult -semantic_activation_ack_ingress_receive( - SemanticActivationAckIngress *ingress, const ClusterICEnvelope *env, - const void *payload, uint32 payload_length, - int32 local_receiver_node_id, uint64 current_epoch) pg_attribute_unused(); -static bool semantic_activation_ack_remote_tuple( - const SemanticActivationAckIngressItem *item, - uint64 current_members_lo, uint64 current_members_hi, - uint64 current_epoch, int32 current_coordinator_node, - SemanticActivationAckTuple *out) pg_attribute_unused(); -static bool semantic_activation_ack_self_tuple( - int32 local_node_id, uint32 local_capability_word, - uint64 transition_epoch, uint64 record_generation, - SemanticActivationAckTuple *out) pg_attribute_unused(); +semantic_activation_ack_ingress_receive(SemanticActivationAckIngress *ingress, + const ClusterICEnvelope *env, const void *payload, + uint32 payload_length, int32 local_receiver_node_id, + uint64 current_epoch) pg_attribute_unused(); +static bool semantic_activation_ack_remote_tuple(const SemanticActivationAckIngressItem *item, + uint64 current_members_lo, + uint64 current_members_hi, uint64 current_epoch, + int32 current_coordinator_node, + SemanticActivationAckTuple *out) + pg_attribute_unused(); +static bool semantic_activation_ack_self_tuple(int32 local_node_id, uint32 local_capability_word, + uint64 transition_epoch, uint64 record_generation, + SemanticActivationAckTuple *out) + pg_attribute_unused(); static bool semantic_activation_ack_complete_image_current( - const ClusterSemanticActivationAckTableV1 *image, - uint64 current_members_lo, uint64 current_members_hi, - uint64 current_epoch, int32 current_coordinator_node, - int32 local_node_id, - uint32 local_capability_word) pg_attribute_unused(); + const ClusterSemanticActivationAckTableV1 *image, uint64 current_members_lo, + uint64 current_members_hi, uint64 current_epoch, int32 current_coordinator_node, + int32 local_node_id, uint32 local_capability_word) pg_attribute_unused(); static ClusterSemanticResourceXPeerOpenResult semantic_activation_ack_expected_image_check(const ClusterSemanticActivationAckTableV1 *image, uint64 current_members_lo, uint64 current_members_hi, uint64 current_epoch, int32 current_coordinator_node, int32 local_node_id, uint32 local_capability_word); static bool semantic_activation_lmon_utility_round_retained(void); -static bool semantic_activation_ack_current_authority( - int32 local_node_id, uint64 *out_members_lo, uint64 *out_members_hi, - uint64 *out_formation_epoch, - int32 *out_coordinator_node) pg_attribute_unused(); +static bool semantic_activation_ack_current_authority(int32 local_node_id, uint64 *out_members_lo, + uint64 *out_members_hi, + uint64 *out_formation_epoch, + int32 *out_coordinator_node) + pg_attribute_unused(); static bool semantic_activation_ack_terminal_identity_not_contradicted( const ClusterSemanticActivationAckTableV1 *image); -static bool semantic_activation_ack_member_present( - uint64 members_lo, uint64 members_hi, int32 node_id); -static bool semantic_activation_ack_wire_value_valid( - const ClusterSemanticActivationAckWireV1 *message); -static bool semantic_activation_bytes_are_zero( - const uint8 *bytes, Size len); -static bool semantic_activation_ack_sample_digest( - const ClusterSemanticActivationAckTableV1 *image, - uint64 *digest_out); -static bool semantic_activation_r4_initial_clean_sample_basis( - uint64 expected_generation, bool coordinator_only); +static bool semantic_activation_ack_member_present(uint64 members_lo, uint64 members_hi, + int32 node_id); +static bool +semantic_activation_ack_wire_value_valid(const ClusterSemanticActivationAckWireV1 *message); +static bool semantic_activation_bytes_are_zero(const uint8 *bytes, Size len); +static bool semantic_activation_ack_sample_digest(const ClusterSemanticActivationAckTableV1 *image, + uint64 *digest_out); +static bool semantic_activation_r4_initial_clean_sample_basis(uint64 expected_generation, + bool coordinator_only); static bool semantic_activation_round_descriptor( - uint64 source_feature_bitmap, uint64 target_feature_bitmap, - uint64 rollback_feature_bitmap, - const ClusterSemanticActivationDescriptor **descriptor_out, - uint32 *required_caps_out); -static bool semantic_activation_ack_round_required_caps( - uint64 source_feature_bitmap, uint64 target_feature_bitmap, - uint64 rollback_feature_bitmap, uint32 *required_caps_out); + uint64 source_feature_bitmap, uint64 target_feature_bitmap, uint64 rollback_feature_bitmap, + const ClusterSemanticActivationDescriptor **descriptor_out, uint32 *required_caps_out); +static bool semantic_activation_ack_round_required_caps(uint64 source_feature_bitmap, + uint64 target_feature_bitmap, + uint64 rollback_feature_bitmap, + uint32 *required_caps_out); static bool semantic_activation_ack_member_prepared_image_current( - const ClusterSemanticActivationAckTableV1 *image, - SemanticActivationAckTuple *out_self); + const ClusterSemanticActivationAckTableV1 *image, SemanticActivationAckTuple *out_self); static void semantic_activation_ack_lmon_invalidate_active(void); static void @@ -743,8 +717,7 @@ semantic_activation_ack_ingress_init(SemanticActivationAckIngress *ingress) } static uint32 -semantic_activation_ack_ingress_pending( - const SemanticActivationAckIngress *ingress) +semantic_activation_ack_ingress_pending(const SemanticActivationAckIngress *ingress) { uint64 pending; @@ -757,9 +730,8 @@ semantic_activation_ack_ingress_pending( } static bool -semantic_activation_ack_ingress_push( - SemanticActivationAckIngress *ingress, - const SemanticActivationAckIngressItem *item) +semantic_activation_ack_ingress_push(SemanticActivationAckIngress *ingress, + const SemanticActivationAckIngressItem *item) { uint64 pending; @@ -768,41 +740,38 @@ semantic_activation_ack_ingress_push( pending = ingress->producer_seq - ingress->consumer_seq; if (pending >= CLUSTER_SEMANTIC_ACTIVATION_ACK_INGRESS_CAPACITY) return false; - ingress->items[ingress->producer_seq - % CLUSTER_SEMANTIC_ACTIVATION_ACK_INGRESS_CAPACITY] = *item; + ingress->items[ingress->producer_seq % CLUSTER_SEMANTIC_ACTIVATION_ACK_INGRESS_CAPACITY] + = *item; ingress->producer_seq++; return true; } static bool -semantic_activation_ack_ingress_poll( - SemanticActivationAckIngress *ingress, - SemanticActivationAckIngressItem *out) +semantic_activation_ack_ingress_poll(SemanticActivationAckIngress *ingress, + SemanticActivationAckIngressItem *out) { uint64 pending; if (ingress == NULL || out == NULL) return false; pending = ingress->producer_seq - ingress->consumer_seq; - if (pending == 0 - || pending > CLUSTER_SEMANTIC_ACTIVATION_ACK_INGRESS_CAPACITY) + if (pending == 0 || pending > CLUSTER_SEMANTIC_ACTIVATION_ACK_INGRESS_CAPACITY) return false; - *out = ingress->items[ingress->consumer_seq - % CLUSTER_SEMANTIC_ACTIVATION_ACK_INGRESS_CAPACITY]; + *out = ingress->items[ingress->consumer_seq % CLUSTER_SEMANTIC_ACTIVATION_ACK_INGRESS_CAPACITY]; ingress->consumer_seq++; return true; } static SemanticActivationAckSendResult -semantic_activation_ack_pending_send_note_result( - SemanticActivationAckPendingSend *pending, int32 dest_node_id, - ClusterICSendResult send_result) +semantic_activation_ack_pending_send_note_result(SemanticActivationAckPendingSend *pending, + int32 dest_node_id, + ClusterICSendResult send_result) { uint64 member_bit; uint64 *pending_members; - if (pending == NULL || pending->invalidated - || dest_node_id < 0 || dest_node_id >= CLUSTER_MAX_NODES) + if (pending == NULL || pending->invalidated || dest_node_id < 0 + || dest_node_id >= CLUSTER_MAX_NODES) return SEMANTIC_ACTIVATION_ACK_SEND_REJECTED; if (dest_node_id < 64) { member_bit = UINT64_C(1) << dest_node_id; @@ -832,17 +801,14 @@ semantic_activation_ack_pending_send_note_result( static bool semantic_activation_ack_pending_send_begin_positive( - SemanticActivationAckPendingSend *pending, - const ClusterSemanticActivationAckWireV1 *request, - int32 local_node_id, - const SemanticActivationAckTuple *self) + SemanticActivationAckPendingSend *pending, const ClusterSemanticActivationAckWireV1 *request, + int32 local_node_id, const SemanticActivationAckTuple *self) { SemanticActivationAckPendingSend candidate; uint64 self_bit; - if (pending == NULL || request == NULL || self == NULL - || local_node_id < 0 || local_node_id >= CLUSTER_MAX_NODES - || self->node_id != (uint32)local_node_id) + if (pending == NULL || request == NULL || self == NULL || local_node_id < 0 + || local_node_id >= CLUSTER_MAX_NODES || self->node_id != (uint32)local_node_id) return false; memset(&candidate, 0, sizeof(candidate)); candidate.message = *request; @@ -855,8 +821,7 @@ semantic_activation_ack_pending_send_begin_positive( candidate.message.capability_word = self->capability_word; candidate.pending_members_lo = request->admitted_members_lo; candidate.pending_members_hi = request->admitted_members_hi; - self_bit = UINT64_C(1) << (local_node_id < 64 - ? local_node_id : local_node_id - 64); + self_bit = UINT64_C(1) << (local_node_id < 64 ? local_node_id : local_node_id - 64); if (local_node_id < 64) candidate.pending_members_lo &= ~self_bit; else @@ -874,47 +839,36 @@ semantic_activation_ack_pending_send_begin_positive( * retaining the send does not install an ACK table row or create a deadline. */ static bool -semantic_activation_ack_pending_send_begin_refused( - SemanticActivationAckPendingSend *pending, - const SemanticActivationAckIngressItem *item, - ClusterSemanticActivationResult reason) +semantic_activation_ack_pending_send_begin_refused(SemanticActivationAckPendingSend *pending, + const SemanticActivationAckIngressItem *item, + ClusterSemanticActivationResult reason) { SemanticActivationAckPendingSend candidate; const ClusterSemanticActivationAckWireV1 *request; uint64 coordinator_bit; int32 local_node_id; - if (pending == NULL || item == NULL - || reason != CLUSTER_SEMANTIC_ACTIVATION_RF_DEFERRED) + if (pending == NULL || item == NULL || reason != CLUSTER_SEMANTIC_ACTIVATION_RF_DEFERRED) return false; request = &item->message; local_node_id = item->local_receiver_node_id; if (!semantic_activation_ack_wire_value_valid(request) - || request->kind - != CLUSTER_SEMANTIC_ACTIVATION_ACK_KIND_REQUEST - || request->stage - != CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_SAMPLE - || request->result - != CLUSTER_SEMANTIC_ACTIVATION_ACK_RESULT_REQUEST - || request->coordinator_node != UINT32_C(0) - || item->authenticated_source_node_id != 0 - || local_node_id <= 0 || local_node_id >= 4 - || request->member_node != (uint32)local_node_id - || request->admitted_members_lo != UINT64_C(0x0f) - || request->admitted_members_hi != 0 + || request->kind != CLUSTER_SEMANTIC_ACTIVATION_ACK_KIND_REQUEST + || request->stage != CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_SAMPLE + || request->result != CLUSTER_SEMANTIC_ACTIVATION_ACK_RESULT_REQUEST + || request->coordinator_node != UINT32_C(0) || item->authenticated_source_node_id != 0 + || local_node_id <= 0 || local_node_id >= 4 || request->member_node != (uint32)local_node_id + || request->admitted_members_lo != UINT64_C(0x0f) || request->admitted_members_hi != 0 || request->source_feature_bitmap != 0 - || request->target_feature_bitmap - != CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1 - || request->rollback_feature_bitmap != 0 - || request->capability_sample_digest != 0 + || request->target_feature_bitmap != CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1 + || request->rollback_feature_bitmap != 0 || request->capability_sample_digest != 0 || item->sampled_capability_generation == 0) return false; memset(&candidate, 0, sizeof(candidate)); candidate.message = *request; candidate.message.kind = CLUSTER_SEMANTIC_ACTIVATION_ACK_KIND_ACK; - candidate.message.result - = CLUSTER_SEMANTIC_ACTIVATION_ACK_RESULT_REFUSED; + candidate.message.result = CLUSTER_SEMANTIC_ACTIVATION_ACK_RESULT_REFUSED; candidate.message.reason = (uint32)reason; candidate.message.member_node = (uint32)local_node_id; candidate.message.boot_id = 0; @@ -922,21 +876,15 @@ semantic_activation_ack_pending_send_begin_refused( candidate.message.capability_word = 0; coordinator_bit = UINT64_C(1) << request->coordinator_node; candidate.pending_members_lo = coordinator_bit; - candidate.refusal_connection_generation - = item->sampled_capability_generation; + candidate.refusal_connection_generation = item->sampled_capability_generation; if (!semantic_activation_ack_wire_value_valid(&candidate.message)) return false; /* The already-admitted exact refusal remains the duplicate receipt. */ - if (!pending->invalidated - && pending->message.kind - == CLUSTER_SEMANTIC_ACTIVATION_ACK_KIND_ACK - && pending->message.result - == CLUSTER_SEMANTIC_ACTIVATION_ACK_RESULT_REFUSED - && memcmp(&pending->message, &candidate.message, - sizeof(candidate.message)) == 0 - && pending->refusal_connection_generation - == candidate.refusal_connection_generation) + if (!pending->invalidated && pending->message.kind == CLUSTER_SEMANTIC_ACTIVATION_ACK_KIND_ACK + && pending->message.result == CLUSTER_SEMANTIC_ACTIVATION_ACK_RESULT_REFUSED + && memcmp(&pending->message, &candidate.message, sizeof(candidate.message)) == 0 + && pending->refusal_connection_generation == candidate.refusal_connection_generation) return true; if (pending->invalidated || pending->pending_members_lo != 0 || pending->pending_members_hi != 0) @@ -946,10 +894,10 @@ semantic_activation_ack_pending_send_begin_refused( } static SemanticActivationAckIngressResult -semantic_activation_ack_ingress_receive( - SemanticActivationAckIngress *ingress, const ClusterICEnvelope *env, - const void *payload, uint32 payload_length, - int32 local_receiver_node_id, uint64 current_epoch) +semantic_activation_ack_ingress_receive(SemanticActivationAckIngress *ingress, + const ClusterICEnvelope *env, const void *payload, + uint32 payload_length, int32 local_receiver_node_id, + uint64 current_epoch) { ClusterSemanticActivationAckWireV1 message; SemanticActivationAckIngressItem item; @@ -963,25 +911,19 @@ semantic_activation_ack_ingress_receive( if (ingress == NULL || env == NULL || payload == NULL || payload_length != CLUSTER_SEMANTIC_ACTIVATION_ACK_WIRE_BYTES || env->payload_length != CLUSTER_SEMANTIC_ACTIVATION_ACK_WIRE_BYTES - || env->msg_type != PGRAC_IC_MSG_SEMANTIC_ACTIVATION_ACK_V1 - || local_receiver_node_id < 0 - || local_receiver_node_id >= CLUSTER_MAX_NODES - || env->source_node_id >= CLUSTER_MAX_NODES + || env->msg_type != PGRAC_IC_MSG_SEMANTIC_ACTIVATION_ACK_V1 || local_receiver_node_id < 0 + || local_receiver_node_id >= CLUSTER_MAX_NODES || env->source_node_id >= CLUSTER_MAX_NODES || env->source_node_id == (uint32)local_receiver_node_id - || env->dest_node_id != (uint32)local_receiver_node_id - || env->epoch != current_epoch - || !cluster_semantic_activation_ack_wire_decode( - (const uint8 *)payload, &message) + || env->dest_node_id != (uint32)local_receiver_node_id || env->epoch != current_epoch + || !cluster_semantic_activation_ack_wire_decode((const uint8 *)payload, &message) || message.transition_epoch != env->epoch) return SEMANTIC_ACTIVATION_ACK_INGRESS_REJECTED; authenticated_source_node_id = (int32)env->source_node_id; local_is_admitted = local_receiver_node_id < 64 - ? (message.admitted_members_lo - & (UINT64_C(1) << local_receiver_node_id)) != 0 - : (message.admitted_members_hi - & (UINT64_C(1) << (local_receiver_node_id - 64))) != 0; + ? (message.admitted_members_lo & (UINT64_C(1) << local_receiver_node_id)) != 0 + : (message.admitted_members_hi & (UINT64_C(1) << (local_receiver_node_id - 64))) != 0; if (!local_is_admitted) return SEMANTIC_ACTIVATION_ACK_INGRESS_REJECTED; @@ -995,8 +937,7 @@ semantic_activation_ack_ingress_receive( if (message.result == CLUSTER_SEMANTIC_ACTIVATION_ACK_RESULT_OK) { if (message.boot_id != message.admitted_incarnation) return SEMANTIC_ACTIVATION_ACK_INGRESS_REJECTED; - } else if (message.result - == CLUSTER_SEMANTIC_ACTIVATION_ACK_RESULT_REFUSED) { + } else if (message.result == CLUSTER_SEMANTIC_ACTIVATION_ACK_RESULT_REFUSED) { if (message.coordinator_node != (uint32)local_receiver_node_id) return SEMANTIC_ACTIVATION_ACK_INGRESS_REJECTED; } else @@ -1005,13 +946,11 @@ semantic_activation_ack_ingress_receive( return SEMANTIC_ACTIVATION_ACK_INGRESS_REJECTED; if (!semantic_activation_ack_round_required_caps( - message.source_feature_bitmap, - message.target_feature_bitmap, + message.source_feature_bitmap, message.target_feature_bitmap, message.rollback_feature_bitmap, &required_caps)) return SEMANTIC_ACTIVATION_ACK_INGRESS_REJECTED; - if (!cluster_sf_peer_capability_word_sample( - authenticated_source_node_id, required_caps, - &capability_word, &capability_generation) + if (!cluster_sf_peer_capability_word_sample(authenticated_source_node_id, required_caps, + &capability_word, &capability_generation) || capability_generation == 0 || (message.kind == CLUSTER_SEMANTIC_ACTIVATION_ACK_KIND_ACK && message.result == CLUSTER_SEMANTIC_ACTIVATION_ACK_RESULT_OK @@ -1036,11 +975,10 @@ semantic_activation_ack_ingress_receive( } static bool -semantic_activation_ack_remote_tuple( - const SemanticActivationAckIngressItem *item, - uint64 current_members_lo, uint64 current_members_hi, - uint64 current_epoch, int32 current_coordinator_node, - SemanticActivationAckTuple *out) +semantic_activation_ack_remote_tuple(const SemanticActivationAckIngressItem *item, + uint64 current_members_lo, uint64 current_members_hi, + uint64 current_epoch, int32 current_coordinator_node, + SemanticActivationAckTuple *out) { SemanticActivationAckTuple tuple; const ClusterSemanticActivationAckWireV1 *message; @@ -1049,65 +987,54 @@ semantic_activation_ack_remote_tuple( bool source_is_admitted; bool coordinator_is_admitted; - if (item == NULL || out == NULL - || current_coordinator_node < 0 + if (item == NULL || out == NULL || current_coordinator_node < 0 || current_coordinator_node >= CLUSTER_MAX_NODES || (current_members_lo == 0 && current_members_hi == 0)) return false; message = &item->message; if (!semantic_activation_ack_round_required_caps( - message->source_feature_bitmap, - message->target_feature_bitmap, + message->source_feature_bitmap, message->target_feature_bitmap, message->rollback_feature_bitmap, &required_caps)) return false; source_node = item->authenticated_source_node_id; if (source_node < 0 || source_node >= CLUSTER_MAX_NODES - || !semantic_activation_ack_member_present( - current_members_lo, current_members_hi, - item->local_receiver_node_id) + || !semantic_activation_ack_member_present(current_members_lo, current_members_hi, + item->local_receiver_node_id) || message->kind != CLUSTER_SEMANTIC_ACTIVATION_ACK_KIND_ACK || message->result != CLUSTER_SEMANTIC_ACTIVATION_ACK_RESULT_OK || message->coordinator_node != (uint32)current_coordinator_node || message->member_node != (uint32)source_node || message->admitted_members_lo != current_members_lo || message->admitted_members_hi != current_members_hi - || message->transition_epoch != current_epoch - || message->boot_id == 0 + || message->transition_epoch != current_epoch || message->boot_id == 0 || message->boot_id != message->admitted_incarnation || item->sampled_capability_generation == 0 || item->sampled_capability_word != message->capability_word || (item->sampled_capability_word & required_caps) != required_caps) return false; - source_is_admitted - = source_node < 64 - ? (current_members_lo & (UINT64_C(1) << source_node)) != 0 - : (current_members_hi - & (UINT64_C(1) << (source_node - 64))) != 0; + source_is_admitted = source_node < 64 + ? (current_members_lo & (UINT64_C(1) << source_node)) != 0 + : (current_members_hi & (UINT64_C(1) << (source_node - 64))) != 0; coordinator_is_admitted = current_coordinator_node < 64 - ? (current_members_lo - & (UINT64_C(1) << current_coordinator_node)) != 0 - : (current_members_hi - & (UINT64_C(1) << (current_coordinator_node - 64))) != 0; + ? (current_members_lo & (UINT64_C(1) << current_coordinator_node)) != 0 + : (current_members_hi & (UINT64_C(1) << (current_coordinator_node - 64))) != 0; if (!source_is_admitted || !coordinator_is_admitted || cluster_membership_get_state(source_node) != CLUSTER_MEMBER_MEMBER || cluster_membership_get_last_admitted_incarnation(source_node) - != message->admitted_incarnation - || !cluster_sf_peer_capability_generation_matches( - source_node, required_caps, - item->sampled_capability_generation)) + != message->admitted_incarnation + || !cluster_sf_peer_capability_generation_matches(source_node, required_caps, + item->sampled_capability_generation)) return false; memset(&tuple, 0, sizeof(tuple)); tuple.node_id = (uint32)source_node; tuple.boot_id = message->boot_id; tuple.admitted_incarnation = message->admitted_incarnation; - tuple.control_connection_generation - = (uint64)item->sampled_capability_generation; + tuple.control_connection_generation = (uint64)item->sampled_capability_generation; tuple.capability_word = item->sampled_capability_word; - tuple.capability_generation - = (uint64)item->sampled_capability_generation; + tuple.capability_generation = (uint64)item->sampled_capability_generation; tuple.transition_epoch = message->transition_epoch; tuple.record_generation = message->record_generation; *out = tuple; @@ -1115,27 +1042,22 @@ semantic_activation_ack_remote_tuple( } static bool -semantic_activation_ack_self_tuple( - int32 local_node_id, uint32 local_capability_word, - uint64 transition_epoch, uint64 record_generation, - SemanticActivationAckTuple *out) +semantic_activation_ack_self_tuple(int32 local_node_id, uint32 local_capability_word, + uint64 transition_epoch, uint64 record_generation, + SemanticActivationAckTuple *out) { SemanticActivationAckTuple tuple; uint64 self_incarnation; - if (out == NULL || local_node_id < 0 - || local_node_id >= CLUSTER_MAX_NODES + if (out == NULL || local_node_id < 0 || local_node_id >= CLUSTER_MAX_NODES || record_generation == 0 - || (local_capability_word - & CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS) - != CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS) + || (local_capability_word & CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS) + != CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS) return false; self_incarnation = cluster_qvotec_get_self_incarnation(); if (self_incarnation == 0 - || cluster_membership_get_state(local_node_id) - != CLUSTER_MEMBER_MEMBER - || cluster_membership_get_last_admitted_incarnation(local_node_id) - != self_incarnation) + || cluster_membership_get_state(local_node_id) != CLUSTER_MEMBER_MEMBER + || cluster_membership_get_last_admitted_incarnation(local_node_id) != self_incarnation) return false; memset(&tuple, 0, sizeof(tuple)); @@ -1165,8 +1087,8 @@ semantic_activation_ack_current_authority_internal( int32 node; bool local_is_member; - if (out_members_lo == NULL || out_members_hi == NULL - || out_formation_epoch == NULL || out_coordinator_node == NULL) + if (out_members_lo == NULL || out_members_hi == NULL || out_formation_epoch == NULL + || out_coordinator_node == NULL) return false; *out_members_lo = 0; *out_members_hi = 0; @@ -1182,21 +1104,16 @@ semantic_activation_ack_current_authority_internal( return false; current_epoch = cluster_epoch_get_current(); - local_is_member - = local_node_id < 64 - ? (members_lo & (UINT64_C(1) << local_node_id)) != 0 - : (members_hi - & (UINT64_C(1) << (local_node_id - 64))) != 0; + local_is_member = local_node_id < 64 + ? (members_lo & (UINT64_C(1) << local_node_id)) != 0 + : (members_hi & (UINT64_C(1) << (local_node_id - 64))) != 0; if (!local_is_member || formation_epoch != current_epoch - || cluster_membership_get_state(local_node_id) - != CLUSTER_MEMBER_MEMBER) + || cluster_membership_get_state(local_node_id) != CLUSTER_MEMBER_MEMBER) return false; for (node = 0; node < CLUSTER_MAX_NODES; node++) { - bool is_member - = node < 64 - ? (members_lo & (UINT64_C(1) << node)) != 0 - : (members_hi & (UINT64_C(1) << (node - 64))) != 0; + bool is_member = node < 64 ? (members_lo & (UINT64_C(1) << node)) != 0 + : (members_hi & (UINT64_C(1) << (node - 64))) != 0; if (is_member) { coordinator_node = node; @@ -1204,10 +1121,8 @@ semantic_activation_ack_current_authority_internal( } } if (coordinator_node < 0 - || cluster_membership_get_state(coordinator_node) - != CLUSTER_MEMBER_MEMBER - || !cluster_qvotec_in_quorum() - || cluster_epoch_get_current() != current_epoch) + || cluster_membership_get_state(coordinator_node) != CLUSTER_MEMBER_MEMBER + || !cluster_qvotec_in_quorum() || cluster_epoch_get_current() != current_epoch) return false; *out_members_lo = members_lo; @@ -1243,16 +1158,14 @@ semantic_activation_ack_terminal_identity_not_contradicted( uint64 snapshot_epoch = 0; int node; - if (image == NULL - || (image->expected_members_lo == 0 - && image->expected_members_hi == 0) + if (image == NULL || (image->expected_members_lo == 0 && image->expected_members_hi == 0) || cluster_epoch_get_current() != image->transition_epoch) return false; /* A successfully captured snapshot is positive evidence. If its exact * identity differs, this is drift rather than temporary unavailability. */ - if (cluster_reconfig_lmon_snapshot_admitted_membership( - &snapshot_members_lo, &snapshot_members_hi, &snapshot_epoch) + if (cluster_reconfig_lmon_snapshot_admitted_membership(&snapshot_members_lo, + &snapshot_members_hi, &snapshot_epoch) && (snapshot_members_lo != image->expected_members_lo || snapshot_members_hi != image->expected_members_hi || snapshot_epoch != image->transition_epoch)) @@ -1268,29 +1181,26 @@ semantic_activation_ack_terminal_identity_not_contradicted( return false; continue; } - if (state != CLUSTER_MEMBER_MEMBER - || image->expected[node].node_id != (uint32)node + if (state != CLUSTER_MEMBER_MEMBER || image->expected[node].node_id != (uint32)node || image->expected[node].admitted_incarnation == 0 || cluster_membership_get_last_admitted_incarnation(node) - != image->expected[node].admitted_incarnation) + != image->expected[node].admitted_incarnation) return false; if (node == cluster_node_id) { uint64 self_incarnation = cluster_qvotec_get_self_incarnation(); - if (self_incarnation != 0 - && self_incarnation != image->expected[node].boot_id) + if (self_incarnation != 0 && self_incarnation != image->expected[node].boot_id) return false; } else { uint64 observed_incarnation = 0; uint64 observed_generation = 0; - if (cluster_reconfig_get_observed_slot( - node, &observed_incarnation, &observed_generation) + if (cluster_reconfig_get_observed_slot(node, &observed_incarnation, + &observed_generation) && (observed_generation == 0 || observed_incarnation != image->expected[node].boot_id - || cluster_reconfig_get_observed_epoch(node) - != image->transition_epoch)) + || cluster_reconfig_get_observed_epoch(node) != image->transition_epoch)) return false; } } @@ -1299,15 +1209,14 @@ semantic_activation_ack_terminal_identity_not_contradicted( } void -cluster_semantic_activation_ack_handler( - const ClusterICEnvelope *env, const void *payload) +cluster_semantic_activation_ack_handler(const ClusterICEnvelope *env, const void *payload) { SemanticActivationAckIngressResult result; uint32 payload_length = env != NULL ? env->payload_length : 0; - result = semantic_activation_ack_ingress_receive( - &semantic_activation_ack_local_ingress, env, payload, - payload_length, cluster_node_id, cluster_epoch_get_current()); + result = semantic_activation_ack_ingress_receive(&semantic_activation_ack_local_ingress, env, + payload, payload_length, cluster_node_id, + cluster_epoch_get_current()); if (result < SEMANTIC_ACTIVATION_ACK_INGRESS_REJECTED || result > SEMANTIC_ACTIVATION_ACK_INGRESS_FULL) result = SEMANTIC_ACTIVATION_ACK_INGRESS_REJECTED; @@ -1329,16 +1238,13 @@ cluster_semantic_activation_ack_handler( * activate proof (only the PREPARED-stage all-member ACK is the CLOSED * binding that opens bit22). */ -static bool semantic_activation_ack_table_snapshot( - ClusterSemanticActivationAckTableV1 *out); +static bool semantic_activation_ack_table_snapshot(ClusterSemanticActivationAckTableV1 *out); bool cluster_semantic_activation_ack_complete_matches( - uint64 transition_epoch, uint64 record_generation, - uint64 expected_members_lo, uint64 expected_members_hi, - uint64 source_feature_bitmap, uint64 target_feature_bitmap, - uint64 capability_sample_digest, - ClusterSemanticActivationAckStage minimum_stage) + uint64 transition_epoch, uint64 record_generation, uint64 expected_members_lo, + uint64 expected_members_hi, uint64 source_feature_bitmap, uint64 target_feature_bitmap, + uint64 capability_sample_digest, ClusterSemanticActivationAckStage minimum_stage) { ClusterSemanticActivationAckTableV1 current; @@ -1352,18 +1258,17 @@ cluster_semantic_activation_ack_complete_matches( if (current.stage < minimum_stage) return false; return current.transition_epoch == transition_epoch - && current.record_generation == record_generation - && current.expected_members_lo == expected_members_lo - && current.expected_members_hi == expected_members_hi - && current.observed_members_lo == current.expected_members_lo - && current.observed_members_hi == current.expected_members_hi - && current.source_feature_bitmap == source_feature_bitmap - && current.target_feature_bitmap == target_feature_bitmap - && current.capability_sample_digest == capability_sample_digest; + && current.record_generation == record_generation + && current.expected_members_lo == expected_members_lo + && current.expected_members_hi == expected_members_hi + && current.observed_members_lo == current.expected_members_lo + && current.observed_members_hi == current.expected_members_hi + && current.source_feature_bitmap == source_feature_bitmap + && current.target_feature_bitmap == target_feature_bitmap + && current.capability_sample_digest == capability_sample_digest; } -static bool semantic_activation_ack_table_snapshot( - ClusterSemanticActivationAckTableV1 *out); +static bool semantic_activation_ack_table_snapshot(ClusterSemanticActivationAckTableV1 *out); static bool semantic_activation_ack_table_snapshot(ClusterSemanticActivationAckTableV1 *out) @@ -1376,17 +1281,14 @@ semantic_activation_ack_table_snapshot(ClusterSemanticActivationAckTableV1 *out) if (SemanticActivationAckTable == NULL || out == NULL) return false; for (attempt = 0; attempt < 3; attempt++) { - seq_before = pg_atomic_read_u64( - &SemanticActivationAckTable->publication_seq); + seq_before = pg_atomic_read_u64(&SemanticActivationAckTable->publication_seq); if ((seq_before & UINT64_C(1)) != 0) continue; pg_read_barrier(); memcpy(&candidate, SemanticActivationAckTable, sizeof(candidate)); pg_read_barrier(); - seq_after = pg_atomic_read_u64( - &SemanticActivationAckTable->publication_seq); - if (seq_before == seq_after - && (seq_after & UINT64_C(1)) == 0) { + seq_after = pg_atomic_read_u64(&SemanticActivationAckTable->publication_seq); + if (seq_before == seq_after && (seq_after & UINT64_C(1)) == 0) { memcpy(out, &candidate, sizeof(candidate)); return true; } @@ -1394,43 +1296,35 @@ semantic_activation_ack_table_snapshot(ClusterSemanticActivationAckTableV1 *out) return false; } -static bool semantic_activation_ack_table_publish( - const ClusterSemanticActivationAckTableV1 *image) pg_attribute_unused(); -static bool semantic_activation_ack_matches( - const SemanticActivationAckTuple *observed, - const SemanticActivationAckTuple *expected); +static bool semantic_activation_ack_table_publish(const ClusterSemanticActivationAckTableV1 *image) + pg_attribute_unused(); +static bool semantic_activation_ack_matches(const SemanticActivationAckTuple *observed, + const SemanticActivationAckTuple *expected); static bool semantic_activation_full_ack_table_matches( - const SemanticActivationAckTuple observed[CLUSTER_MAX_NODES], - uint64 observed_members_lo, uint64 observed_members_hi, - const SemanticActivationAckTuple expected[CLUSTER_MAX_NODES], + const SemanticActivationAckTuple observed[CLUSTER_MAX_NODES], uint64 observed_members_lo, + uint64 observed_members_hi, const SemanticActivationAckTuple expected[CLUSTER_MAX_NODES], uint64 expected_members_lo, uint64 expected_members_hi); static SemanticActivationAckConsumeResult -semantic_activation_ack_lmon_apply_item( - const SemanticActivationAckIngressItem *item, - uint64 current_members_lo, uint64 current_members_hi, - uint64 current_epoch, - int32 current_coordinator_node) pg_attribute_unused(); -static SemanticActivationAckConsumeResult -semantic_activation_ack_lmon_install_authorized_request( - const SemanticActivationAckIngressItem *item, - uint64 current_members_lo, uint64 current_members_hi, - uint64 current_epoch, int32 current_coordinator_node, +semantic_activation_ack_lmon_apply_item(const SemanticActivationAckIngressItem *item, + uint64 current_members_lo, uint64 current_members_hi, + uint64 current_epoch, int32 current_coordinator_node) + pg_attribute_unused(); +static SemanticActivationAckConsumeResult semantic_activation_ack_lmon_install_authorized_request( + const SemanticActivationAckIngressItem *item, uint64 current_members_lo, + uint64 current_members_hi, uint64 current_epoch, int32 current_coordinator_node, uint32 local_capability_word) pg_attribute_unused(); static SemanticActivationAckConsumeResult semantic_activation_ack_lmon_accept_current_sample_request( const SemanticActivationAckIngressItem *item, - const SemanticActivationAdmissionSnapshot *snapshot, - uint64 current_members_lo, uint64 current_members_hi, - uint64 current_epoch, int32 current_coordinator_node, + const SemanticActivationAdmissionSnapshot *snapshot, uint64 current_members_lo, + uint64 current_members_hi, uint64 current_epoch, int32 current_coordinator_node, uint32 local_capability_word) pg_attribute_unused(); static SemanticActivationAckConsumeResult semantic_activation_ack_lmon_accept_current_barrier_request( const SemanticActivationAckIngressItem *item, - const SemanticActivationAdmissionSnapshot *snapshot, - uint64 current_members_lo, uint64 current_members_hi, - uint64 current_epoch, int32 current_coordinator_node, - uint32 local_capability_word) - pg_attribute_unused(); + const SemanticActivationAdmissionSnapshot *snapshot, uint64 current_members_lo, + uint64 current_members_hi, uint64 current_epoch, int32 current_coordinator_node, + uint32 local_capability_word) pg_attribute_unused(); /* * semantic_activation_ack_lmon_accept_current_barrier_request_bit22 -- * RF-ROOT P9 verification (verified implementation): member-side acceptance of the @@ -1445,9 +1339,8 @@ semantic_activation_ack_lmon_accept_current_barrier_request( static SemanticActivationAckConsumeResult semantic_activation_ack_lmon_accept_current_barrier_request_bit22( const SemanticActivationAckIngressItem *item, - const SemanticActivationAdmissionSnapshot *snapshot, - uint64 current_members_lo, uint64 current_members_hi, - uint64 current_epoch, int32 current_coordinator_node) + const SemanticActivationAdmissionSnapshot *snapshot, uint64 current_members_lo, + uint64 current_members_hi, uint64 current_epoch, int32 current_coordinator_node) { ClusterSemanticActivationAckTableV1 current; ClusterSemanticActivationAckTableV1 next; @@ -1456,49 +1349,36 @@ semantic_activation_ack_lmon_accept_current_barrier_request_bit22( int32 local_node_id; int node; - if (item == NULL || snapshot == NULL - || !semantic_activation_ack_table_snapshot(¤t)) + if (item == NULL || snapshot == NULL || !semantic_activation_ack_table_snapshot(¤t)) return SEMANTIC_ACTIVATION_ACK_CONSUME_REJECTED; message = &item->message; local_node_id = item->local_receiver_node_id; if (!semantic_activation_ack_wire_value_valid(message) - || message->kind - != CLUSTER_SEMANTIC_ACTIVATION_ACK_KIND_REQUEST - || message->stage - != CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_BARRIER - || message->result - != CLUSTER_SEMANTIC_ACTIVATION_ACK_RESULT_REQUEST - || current_coordinator_node < 0 - || current_coordinator_node >= CLUSTER_MAX_NODES + || message->kind != CLUSTER_SEMANTIC_ACTIVATION_ACK_KIND_REQUEST + || message->stage != CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_BARRIER + || message->result != CLUSTER_SEMANTIC_ACTIVATION_ACK_RESULT_REQUEST + || current_coordinator_node < 0 || current_coordinator_node >= CLUSTER_MAX_NODES || local_node_id < 0 || local_node_id >= CLUSTER_MAX_NODES || local_node_id == current_coordinator_node - || item->authenticated_source_node_id - != current_coordinator_node - || message->coordinator_node - != (uint32)current_coordinator_node + || item->authenticated_source_node_id != current_coordinator_node + || message->coordinator_node != (uint32)current_coordinator_node || message->member_node != (uint32)local_node_id || message->admitted_members_lo != current_members_lo || message->admitted_members_hi != current_members_hi || message->transition_epoch != current_epoch - || !semantic_activation_ack_member_present( - current_members_lo, current_members_hi, - current_coordinator_node) - || !semantic_activation_ack_member_present( - current_members_lo, current_members_hi, local_node_id) - || cluster_membership_get_state(current_coordinator_node) - != CLUSTER_MEMBER_MEMBER - || (message->target_feature_bitmap - & PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1) == 0 - || (item->sampled_capability_word - & CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS) - != CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS - || snapshot->transition_closed - || snapshot->formation_epoch != current_epoch + || !semantic_activation_ack_member_present(current_members_lo, current_members_hi, + current_coordinator_node) + || !semantic_activation_ack_member_present(current_members_lo, current_members_hi, + local_node_id) + || cluster_membership_get_state(current_coordinator_node) != CLUSTER_MEMBER_MEMBER + || (message->target_feature_bitmap & PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1) + == 0 + || (item->sampled_capability_word & CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS) + != CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS + || snapshot->transition_closed || snapshot->formation_epoch != current_epoch || snapshot->record_generation == UINT64_MAX - || message->record_generation - != snapshot->record_generation + 1 - || snapshot->active_bits != message->source_feature_bitmap - || snapshot->active_bits != 0 + || message->record_generation != snapshot->record_generation + 1 + || snapshot->active_bits != message->source_feature_bitmap || snapshot->active_bits != 0 || message->rollback_feature_bitmap != 0) return SEMANTIC_ACTIVATION_ACK_CONSUME_REJECTED; @@ -1526,13 +1406,13 @@ semantic_activation_ack_lmon_accept_current_barrier_request_bit22( for (node = 0; node < CLUSTER_MAX_NODES; node++) { SemanticActivationAckTuple tuple; - if (!semantic_activation_ack_member_present( - next.expected_members_lo, next.expected_members_hi, node)) + if (!semantic_activation_ack_member_present(next.expected_members_lo, + next.expected_members_hi, node)) continue; if (node == local_node_id) { - if (!semantic_activation_ack_self_tuple( - node, local_capability_word, next.transition_epoch, - next.record_generation, &next.expected[node])) + if (!semantic_activation_ack_self_tuple(node, local_capability_word, + next.transition_epoch, next.record_generation, + &next.expected[node])) return SEMANTIC_ACTIVATION_ACK_CONSUME_REJECTED; continue; } @@ -1541,12 +1421,10 @@ semantic_activation_ack_lmon_accept_current_barrier_request_bit22( uint32 peer_word = 0; uint32 peer_gen = 0; - peer_admitted - = cluster_membership_get_last_admitted_incarnation(node); + peer_admitted = cluster_membership_get_last_admitted_incarnation(node); if (peer_admitted == 0 || !cluster_sf_peer_capability_word_sample( - node, CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS, - &peer_word, &peer_gen) + node, CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS, &peer_word, &peer_gen) || peer_gen == 0) return SEMANTIC_ACTIVATION_ACK_CONSUME_REJECTED; memset(&tuple, 0, sizeof(tuple)); @@ -1561,16 +1439,15 @@ semantic_activation_ack_lmon_accept_current_barrier_request_bit22( next.expected[node] = tuple; } } - return semantic_activation_ack_table_publish(&next) - ? SEMANTIC_ACTIVATION_ACK_CONSUME_APPLIED - : SEMANTIC_ACTIVATION_ACK_CONSUME_REJECTED; + return semantic_activation_ack_table_publish(&next) ? SEMANTIC_ACTIVATION_ACK_CONSUME_APPLIED + : SEMANTIC_ACTIVATION_ACK_CONSUME_REJECTED; } -static bool semantic_activation_ack_expected_image_current( - const ClusterSemanticActivationAckTableV1 *image, - uint64 current_members_lo, uint64 current_members_hi, - uint64 current_epoch, int32 current_coordinator_node, - int32 local_node_id, uint32 local_capability_word); +static bool +semantic_activation_ack_expected_image_current(const ClusterSemanticActivationAckTableV1 *image, + uint64 current_members_lo, uint64 current_members_hi, + uint64 current_epoch, int32 current_coordinator_node, + int32 local_node_id, uint32 local_capability_word); /* * semantic_activation_ack_lmon_accept_current_request_bit22 -- RF-ROOT @@ -1597,9 +1474,8 @@ static bool semantic_activation_ack_expected_image_current( static SemanticActivationAckConsumeResult semantic_activation_ack_lmon_accept_current_request_bit22( const SemanticActivationAckIngressItem *item, - const SemanticActivationAdmissionSnapshot *snapshot, - uint64 current_members_lo, uint64 current_members_hi, - uint64 current_epoch, int32 current_coordinator_node, + const SemanticActivationAdmissionSnapshot *snapshot, uint64 current_members_lo, + uint64 current_members_hi, uint64 current_epoch, int32 current_coordinator_node, uint32 local_capability_word) { ClusterSemanticActivationAckTableV1 current; @@ -1613,8 +1489,7 @@ semantic_activation_ack_lmon_accept_current_request_bit22( int32 local_node_id; int node; - if (item == NULL || snapshot == NULL - || !semantic_activation_ack_table_snapshot(¤t)) + if (item == NULL || snapshot == NULL || !semantic_activation_ack_table_snapshot(¤t)) return SEMANTIC_ACTIVATION_ACK_CONSUME_REJECTED; message = &item->message; local_node_id = item->local_receiver_node_id; @@ -1635,75 +1510,52 @@ semantic_activation_ack_lmon_accept_current_request_bit22( return SEMANTIC_ACTIVATION_ACK_CONSUME_REJECTED; self_bit = UINT64_C(1) << local_node_id; if (!semantic_activation_ack_wire_value_valid(message) - || message->kind - != CLUSTER_SEMANTIC_ACTIVATION_ACK_KIND_REQUEST - || message->stage != stage - || message->result - != CLUSTER_SEMANTIC_ACTIVATION_ACK_RESULT_REQUEST - || current_coordinator_node < 0 - || current_coordinator_node >= CLUSTER_MAX_NODES + || message->kind != CLUSTER_SEMANTIC_ACTIVATION_ACK_KIND_REQUEST || message->stage != stage + || message->result != CLUSTER_SEMANTIC_ACTIVATION_ACK_RESULT_REQUEST + || current_coordinator_node < 0 || current_coordinator_node >= CLUSTER_MAX_NODES || local_node_id < 0 || local_node_id >= CLUSTER_MAX_NODES || local_node_id == current_coordinator_node - || item->authenticated_source_node_id - != current_coordinator_node - || message->coordinator_node - != (uint32)current_coordinator_node + || item->authenticated_source_node_id != current_coordinator_node + || message->coordinator_node != (uint32)current_coordinator_node || message->member_node != (uint32)local_node_id || message->admitted_members_lo != current_members_lo || message->admitted_members_hi != current_members_hi || message->transition_epoch != current_epoch - || !semantic_activation_ack_member_present( - current_members_lo, current_members_hi, - current_coordinator_node) - || !semantic_activation_ack_member_present( - current_members_lo, current_members_hi, local_node_id) - || cluster_membership_get_state(current_coordinator_node) - != CLUSTER_MEMBER_MEMBER - || (message->target_feature_bitmap - & PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1) == 0 - || (item->sampled_capability_word - & CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS) - != CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS + || !semantic_activation_ack_member_present(current_members_lo, current_members_hi, + current_coordinator_node) + || !semantic_activation_ack_member_present(current_members_lo, current_members_hi, + local_node_id) + || cluster_membership_get_state(current_coordinator_node) != CLUSTER_MEMBER_MEMBER + || (message->target_feature_bitmap & PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1) + == 0 + || (item->sampled_capability_word & CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS) + != CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS || item->sampled_capability_generation == 0 || !cluster_sf_peer_capability_generation_matches( - current_coordinator_node, - CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS, + current_coordinator_node, CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS, item->sampled_capability_generation) - || (snapshot->seq & UINT64_C(1)) != 0 - || !snapshot->transition_closed - || snapshot->formation_epoch != current_epoch - || snapshot->record_generation == UINT64_MAX - || snapshot->record_generation + stage_gen_offset - != message->record_generation - || snapshot->active_bits != message->source_feature_bitmap - || snapshot->active_bits != 0 - || message->rollback_feature_bitmap != 0 - || current.stage != prev_stage - || current.flags - != CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID + || (snapshot->seq & UINT64_C(1)) != 0 || !snapshot->transition_closed + || snapshot->formation_epoch != current_epoch || snapshot->record_generation == UINT64_MAX + || snapshot->record_generation + stage_gen_offset != message->record_generation + || snapshot->active_bits != message->source_feature_bitmap || snapshot->active_bits != 0 + || message->rollback_feature_bitmap != 0 || current.stage != prev_stage + || current.flags != CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID || current.coordinator_node != message->coordinator_node || current.round_nonce != message->round_nonce || current.expected_members_lo != message->admitted_members_lo || current.expected_members_hi != message->admitted_members_hi || current.transition_epoch != message->transition_epoch || current.record_generation != prev_gen - || current.source_feature_bitmap - != message->source_feature_bitmap - || current.target_feature_bitmap - != message->target_feature_bitmap - || current.rollback_feature_bitmap - != message->rollback_feature_bitmap + || current.source_feature_bitmap != message->source_feature_bitmap + || current.target_feature_bitmap != message->target_feature_bitmap + || current.rollback_feature_bitmap != message->rollback_feature_bitmap || current.capability_sample_digest == 0 - || current.capability_sample_digest - != message->capability_sample_digest - || current.observed_members_lo != self_bit - || current.observed_members_hi != 0 - || !semantic_activation_ack_member_present( - current.expected_members_lo, current.expected_members_hi, - local_node_id) - || !semantic_activation_ack_matches( - ¤t.observed[local_node_id], - ¤t.expected[local_node_id])) + || current.capability_sample_digest != message->capability_sample_digest + || current.observed_members_lo != self_bit || current.observed_members_hi != 0 + || !semantic_activation_ack_member_present(current.expected_members_lo, + current.expected_members_hi, local_node_id) + || !semantic_activation_ack_matches(¤t.observed[local_node_id], + ¤t.expected[local_node_id])) return SEMANTIC_ACTIVATION_ACK_CONSUME_REJECTED; if (current.stage == stage) return SEMANTIC_ACTIVATION_ACK_CONSUME_DUPLICATE; @@ -1716,41 +1568,34 @@ semantic_activation_ack_lmon_accept_current_request_bit22( next.observed_members_hi = 0; memset(next.observed, 0, sizeof(next.observed)); for (node = 0; node < CLUSTER_MAX_NODES; node++) - if (semantic_activation_ack_member_present( - next.expected_members_lo, next.expected_members_hi, node)) - next.expected[node].record_generation - = message->record_generation; + if (semantic_activation_ack_member_present(next.expected_members_lo, + next.expected_members_hi, node)) + next.expected[node].record_generation = message->record_generation; if (!semantic_activation_ack_expected_image_current( - &next, current_members_lo, current_members_hi, current_epoch, - current_coordinator_node, local_node_id, - local_capability_word)) + &next, current_members_lo, current_members_hi, current_epoch, current_coordinator_node, + local_node_id, local_capability_word)) return SEMANTIC_ACTIVATION_ACK_CONSUME_REJECTED; - return semantic_activation_ack_table_publish(&next) - ? SEMANTIC_ACTIVATION_ACK_CONSUME_APPLIED - : SEMANTIC_ACTIVATION_ACK_CONSUME_REJECTED; + return semantic_activation_ack_table_publish(&next) ? SEMANTIC_ACTIVATION_ACK_CONSUME_APPLIED + : SEMANTIC_ACTIVATION_ACK_CONSUME_REJECTED; } static SemanticActivationAckConsumeResult semantic_activation_ack_lmon_accept_current_prepared_request( const SemanticActivationAckIngressItem *item, - const SemanticActivationAdmissionSnapshot *snapshot, - uint64 current_members_lo, uint64 current_members_hi, - uint64 current_epoch, int32 current_coordinator_node, + const SemanticActivationAdmissionSnapshot *snapshot, uint64 current_members_lo, + uint64 current_members_hi, uint64 current_epoch, int32 current_coordinator_node, uint32 local_capability_word) pg_attribute_unused(); static SemanticActivationAckConsumeResult semantic_activation_ack_lmon_accept_current_commit_applied_request( const SemanticActivationAckIngressItem *item, - const SemanticActivationAdmissionSnapshot *snapshot, - uint64 current_members_lo, uint64 current_members_hi, - uint64 current_epoch, int32 current_coordinator_node, + const SemanticActivationAdmissionSnapshot *snapshot, uint64 current_members_lo, + uint64 current_members_hi, uint64 current_epoch, int32 current_coordinator_node, uint32 local_capability_word) pg_attribute_unused(); static bool -semantic_activation_ack_table_publish( - const ClusterSemanticActivationAckTableV1 *image) +semantic_activation_ack_table_publish(const ClusterSemanticActivationAckTableV1 *image) { - const Size payload_offset - = offsetof(ClusterSemanticActivationAckTableV1, stage); + const Size payload_offset = offsetof(ClusterSemanticActivationAckTableV1, stage); uint64 seq; if (SemanticActivationAckTable == NULL || image == NULL) @@ -1770,36 +1615,30 @@ semantic_activation_ack_table_publish( } static bool -semantic_activation_ack_member_present( - uint64 members_lo, uint64 members_hi, int32 node_id) +semantic_activation_ack_member_present(uint64 members_lo, uint64 members_hi, int32 node_id) { if (node_id < 0 || node_id >= CLUSTER_MAX_NODES) return false; - return node_id < 64 - ? (members_lo & (UINT64_C(1) << node_id)) != 0 - : (members_hi & (UINT64_C(1) << (node_id - 64))) != 0; + return node_id < 64 ? (members_lo & (UINT64_C(1) << node_id)) != 0 + : (members_hi & (UINT64_C(1) << (node_id - 64))) != 0; } static bool -semantic_activation_ack_tuple_structural( - const SemanticActivationAckTuple *tuple, int32 node_id, - uint64 transition_epoch, uint64 record_generation, - uint32 required_caps) +semantic_activation_ack_tuple_structural(const SemanticActivationAckTuple *tuple, int32 node_id, + uint64 transition_epoch, uint64 record_generation, + uint32 required_caps) { return tuple != NULL && node_id >= 0 && node_id < CLUSTER_MAX_NODES - && tuple->node_id == (uint32)node_id - && tuple->boot_id != 0 + && tuple->node_id == (uint32)node_id && tuple->boot_id != 0 && tuple->boot_id == tuple->admitted_incarnation && tuple->control_connection_generation != 0 && (tuple->capability_word & required_caps) == required_caps - && tuple->capability_generation != 0 - && tuple->transition_epoch == transition_epoch + && tuple->capability_generation != 0 && tuple->transition_epoch == transition_epoch && tuple->record_generation == record_generation; } static bool -semantic_activation_ack_image_structural( - const ClusterSemanticActivationAckTableV1 *image) +semantic_activation_ack_image_structural(const ClusterSemanticActivationAckTableV1 *image) { uint32 required_caps; int node; @@ -1808,26 +1647,24 @@ semantic_activation_ack_image_structural( || !semantic_activation_ack_round_required_caps( image->source_feature_bitmap, image->target_feature_bitmap, image->rollback_feature_bitmap, &required_caps) - || (image->expected_members_lo == 0 - && image->expected_members_hi == 0) + || (image->expected_members_lo == 0 && image->expected_members_hi == 0) || image->observed_members_lo != image->expected_members_lo || image->observed_members_hi != image->expected_members_hi) return false; for (node = 0; node < CLUSTER_MAX_NODES; node++) { - if (!semantic_activation_ack_member_present( - image->expected_members_lo, image->expected_members_hi, node)) + if (!semantic_activation_ack_member_present(image->expected_members_lo, + image->expected_members_hi, node)) continue; - if (!semantic_activation_ack_tuple_structural( - &image->observed[node], node, image->transition_epoch, - image->record_generation, required_caps)) + if (!semantic_activation_ack_tuple_structural(&image->observed[node], node, + image->transition_epoch, + image->record_generation, required_caps)) return false; } return true; } static bool -semantic_activation_ack_image_invalidate( - ClusterSemanticActivationAckTableV1 *image) +semantic_activation_ack_image_invalidate(ClusterSemanticActivationAckTableV1 *image) { if (semantic_activation_restart.requested && !semantic_activation_restart.opened) semantic_activation_restart.failed = true; @@ -1849,100 +1686,77 @@ semantic_activation_ack_image_invalidate( static SemanticActivationAckConsumeResult semantic_activation_ack_lmon_install_authorized_request( - const SemanticActivationAckIngressItem *item, - uint64 current_members_lo, uint64 current_members_hi, - uint64 current_epoch, int32 current_coordinator_node, + const SemanticActivationAckIngressItem *item, uint64 current_members_lo, + uint64 current_members_hi, uint64 current_epoch, int32 current_coordinator_node, uint32 local_capability_word) { ClusterSemanticActivationAckTableV1 current; ClusterSemanticActivationAckTableV1 next; SemanticActivationAckTuple self; const ClusterSemanticActivationAckWireV1 *message; - const Size payload_offset - = offsetof(ClusterSemanticActivationAckTableV1, stage); + const Size payload_offset = offsetof(ClusterSemanticActivationAckTableV1, stage); uint32 required_caps; int32 local_node_id; - if (item == NULL - || !semantic_activation_ack_table_snapshot(¤t)) + if (item == NULL || !semantic_activation_ack_table_snapshot(¤t)) return SEMANTIC_ACTIVATION_ACK_CONSUME_REJECTED; message = &item->message; local_node_id = item->local_receiver_node_id; if (!semantic_activation_ack_wire_value_valid(message) - || message->kind - != CLUSTER_SEMANTIC_ACTIVATION_ACK_KIND_REQUEST - || message->stage - != CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_SAMPLE - || message->result - != CLUSTER_SEMANTIC_ACTIVATION_ACK_RESULT_REQUEST - || current_coordinator_node < 0 - || current_coordinator_node >= CLUSTER_MAX_NODES + || message->kind != CLUSTER_SEMANTIC_ACTIVATION_ACK_KIND_REQUEST + || message->stage != CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_SAMPLE + || message->result != CLUSTER_SEMANTIC_ACTIVATION_ACK_RESULT_REQUEST + || current_coordinator_node < 0 || current_coordinator_node >= CLUSTER_MAX_NODES || local_node_id < 0 || local_node_id >= CLUSTER_MAX_NODES || local_node_id == current_coordinator_node - || item->authenticated_source_node_id - != current_coordinator_node - || message->coordinator_node - != (uint32)current_coordinator_node + || item->authenticated_source_node_id != current_coordinator_node + || message->coordinator_node != (uint32)current_coordinator_node || message->member_node != (uint32)local_node_id || message->admitted_members_lo != current_members_lo || message->admitted_members_hi != current_members_hi || message->transition_epoch != current_epoch || !semantic_activation_ack_round_required_caps( - message->source_feature_bitmap, - message->target_feature_bitmap, + message->source_feature_bitmap, message->target_feature_bitmap, message->rollback_feature_bitmap, &required_caps) - || !semantic_activation_ack_member_present( - current_members_lo, current_members_hi, - current_coordinator_node) - || !semantic_activation_ack_member_present( - current_members_lo, current_members_hi, local_node_id) - || cluster_membership_get_state(current_coordinator_node) - != CLUSTER_MEMBER_MEMBER + || !semantic_activation_ack_member_present(current_members_lo, current_members_hi, + current_coordinator_node) + || !semantic_activation_ack_member_present(current_members_lo, current_members_hi, + local_node_id) + || cluster_membership_get_state(current_coordinator_node) != CLUSTER_MEMBER_MEMBER || item->sampled_capability_generation == 0 || (item->sampled_capability_word & required_caps) != required_caps || (local_capability_word & required_caps) != required_caps - || !cluster_sf_peer_capability_generation_matches( - current_coordinator_node, required_caps, - item->sampled_capability_generation) - || !semantic_activation_ack_self_tuple( - local_node_id, local_capability_word, current_epoch, - message->record_generation, &self)) + || !cluster_sf_peer_capability_generation_matches(current_coordinator_node, required_caps, + item->sampled_capability_generation) + || !semantic_activation_ack_self_tuple(local_node_id, local_capability_word, current_epoch, + message->record_generation, &self)) return SEMANTIC_ACTIVATION_ACK_CONSUME_REJECTED; /* An exact directed SAMPLE REQUEST is idempotent for the lifetime of its * installed round. Peer ACKs may already have populated observed rows; * replay must not erase them or restart the local positive fan-out. */ if (current.stage == CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_SAMPLE - && (current.expected_members_lo != 0 - || current.expected_members_hi != 0)) { - uint64 self_bit = UINT64_C(1) - << (local_node_id < 64 ? local_node_id : local_node_id - 64); + && (current.expected_members_lo != 0 || current.expected_members_hi != 0)) { + uint64 self_bit = UINT64_C(1) << (local_node_id < 64 ? local_node_id : local_node_id - 64); bool exact = current.coordinator_node == message->coordinator_node - && current.round_nonce == message->round_nonce - && current.expected_members_lo == message->admitted_members_lo - && current.expected_members_hi == message->admitted_members_hi - && current.transition_epoch == message->transition_epoch - && current.record_generation == message->record_generation - && current.source_feature_bitmap - == message->source_feature_bitmap - && current.target_feature_bitmap - == message->target_feature_bitmap - && current.rollback_feature_bitmap - == message->rollback_feature_bitmap - && current.capability_sample_digest - == message->capability_sample_digest - && (current.observed_members_lo - & ~current.expected_members_lo) == 0 - && (current.observed_members_hi - & ~current.expected_members_hi) == 0 - && (current.flags - & ~(CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID - | CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE)) == 0 - && (local_node_id < 64 - ? (current.observed_members_lo & self_bit) != 0 - : (current.observed_members_hi & self_bit) != 0) - && semantic_activation_ack_matches( - ¤t.observed[local_node_id], &self); + && current.round_nonce == message->round_nonce + && current.expected_members_lo == message->admitted_members_lo + && current.expected_members_hi == message->admitted_members_hi + && current.transition_epoch == message->transition_epoch + && current.record_generation == message->record_generation + && current.source_feature_bitmap == message->source_feature_bitmap + && current.target_feature_bitmap == message->target_feature_bitmap + && current.rollback_feature_bitmap == message->rollback_feature_bitmap + && current.capability_sample_digest == message->capability_sample_digest + && (current.observed_members_lo & ~current.expected_members_lo) == 0 + && (current.observed_members_hi & ~current.expected_members_hi) == 0 + && (current.flags + & ~(CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID + | CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE)) + == 0 + && (local_node_id < 64 ? (current.observed_members_lo & self_bit) != 0 + : (current.observed_members_hi & self_bit) != 0) + && semantic_activation_ack_matches(¤t.observed[local_node_id], &self); if (exact) return SEMANTIC_ACTIVATION_ACK_CONSUME_DUPLICATE; @@ -1960,8 +1774,7 @@ semantic_activation_ack_lmon_install_authorized_request( if (local_node_id < 64) next.observed_members_lo = UINT64_C(1) << local_node_id; else - next.observed_members_hi - = UINT64_C(1) << (local_node_id - 64); + next.observed_members_hi = UINT64_C(1) << (local_node_id - 64); next.transition_epoch = message->transition_epoch; next.record_generation = message->record_generation; next.source_feature_bitmap = message->source_feature_bitmap; @@ -1970,20 +1783,18 @@ semantic_activation_ack_lmon_install_authorized_request( next.capability_sample_digest = message->capability_sample_digest; next.observed[local_node_id] = self; - if (memcmp((const uint8 *)¤t + payload_offset, - (const uint8 *)&next + payload_offset, - sizeof(current) - payload_offset) == 0) + if (memcmp((const uint8 *)¤t + payload_offset, (const uint8 *)&next + payload_offset, + sizeof(current) - payload_offset) + == 0) return SEMANTIC_ACTIVATION_ACK_CONSUME_DUPLICATE; - return semantic_activation_ack_table_publish(&next) - ? SEMANTIC_ACTIVATION_ACK_CONSUME_APPLIED - : SEMANTIC_ACTIVATION_ACK_CONSUME_REJECTED; + return semantic_activation_ack_table_publish(&next) ? SEMANTIC_ACTIVATION_ACK_CONSUME_APPLIED + : SEMANTIC_ACTIVATION_ACK_CONSUME_REJECTED; } static SemanticActivationAckConsumeResult -semantic_activation_ack_lmon_apply_item( - const SemanticActivationAckIngressItem *item, - uint64 current_members_lo, uint64 current_members_hi, - uint64 current_epoch, int32 current_coordinator_node) +semantic_activation_ack_lmon_apply_item(const SemanticActivationAckIngressItem *item, + uint64 current_members_lo, uint64 current_members_hi, + uint64 current_epoch, int32 current_coordinator_node) { ClusterSemanticActivationAckTableV1 image; SemanticActivationAckTuple tuple; @@ -1992,11 +1803,9 @@ semantic_activation_ack_lmon_apply_item( bool member_was_observed; int32 source_node; - if (item == NULL - || !semantic_activation_ack_table_snapshot(&image)) + if (item == NULL || !semantic_activation_ack_table_snapshot(&image)) return SEMANTIC_ACTIVATION_ACK_CONSUME_REJECTED; - if ((image.expected_members_lo == 0 - && image.expected_members_hi == 0) + if ((image.expected_members_lo == 0 && image.expected_members_hi == 0) || image.stage < CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_SAMPLE || image.stage > CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_OPEN_APPLIED || image.round_nonce == 0) @@ -2011,8 +1820,7 @@ semantic_activation_ack_lmon_apply_item( } message = &item->message; - if (message->kind != CLUSTER_SEMANTIC_ACTIVATION_ACK_KIND_ACK - || message->stage != image.stage + if (message->kind != CLUSTER_SEMANTIC_ACTIVATION_ACK_KIND_ACK || message->stage != image.stage || message->coordinator_node != image.coordinator_node || message->round_nonce != image.round_nonce || message->admitted_members_lo != image.expected_members_lo @@ -2022,77 +1830,60 @@ semantic_activation_ack_lmon_apply_item( || message->source_feature_bitmap != image.source_feature_bitmap || message->target_feature_bitmap != image.target_feature_bitmap || message->rollback_feature_bitmap != image.rollback_feature_bitmap - || message->capability_sample_digest - != image.capability_sample_digest) + || message->capability_sample_digest != image.capability_sample_digest) return SEMANTIC_ACTIVATION_ACK_CONSUME_STALE; if (message->result == CLUSTER_SEMANTIC_ACTIVATION_ACK_RESULT_REFUSED) { uint32 required_caps; bool exact_initial_r4_refusal = semantic_activation_ack_wire_value_valid(message) - && image.stage - == CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_SAMPLE - && image.source_feature_bitmap == 0 - && image.target_feature_bitmap - == CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1 - && image.rollback_feature_bitmap == 0 - && image.expected_members_lo == UINT64_C(0x0f) - && image.expected_members_hi == 0 - && message->reason - == CLUSTER_SEMANTIC_ACTIVATION_RF_DEFERRED - && item->local_receiver_node_id == current_coordinator_node - && item->authenticated_source_node_id - == (int32)message->member_node - && item->authenticated_source_node_id > 0 - && item->authenticated_source_node_id < 4 - && cluster_membership_get_state( - item->authenticated_source_node_id) - == CLUSTER_MEMBER_MEMBER - && item->sampled_capability_generation != 0 - && semantic_activation_ack_round_required_caps( - message->source_feature_bitmap, - message->target_feature_bitmap, - message->rollback_feature_bitmap, &required_caps) - && (item->sampled_capability_word & required_caps) - == required_caps - && cluster_sf_peer_capability_generation_matches( - item->authenticated_source_node_id, required_caps, - item->sampled_capability_generation); + && image.stage == CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_SAMPLE + && image.source_feature_bitmap == 0 + && image.target_feature_bitmap == CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1 + && image.rollback_feature_bitmap == 0 && image.expected_members_lo == UINT64_C(0x0f) + && image.expected_members_hi == 0 + && message->reason == CLUSTER_SEMANTIC_ACTIVATION_RF_DEFERRED + && item->local_receiver_node_id == current_coordinator_node + && item->authenticated_source_node_id == (int32)message->member_node + && item->authenticated_source_node_id > 0 && item->authenticated_source_node_id < 4 + && cluster_membership_get_state(item->authenticated_source_node_id) + == CLUSTER_MEMBER_MEMBER + && item->sampled_capability_generation != 0 + && semantic_activation_ack_round_required_caps( + message->source_feature_bitmap, message->target_feature_bitmap, + message->rollback_feature_bitmap, &required_caps) + && (item->sampled_capability_word & required_caps) == required_caps + && cluster_sf_peer_capability_generation_matches(item->authenticated_source_node_id, + required_caps, + item->sampled_capability_generation); if (!semantic_activation_ack_image_invalidate(&image)) return SEMANTIC_ACTIVATION_ACK_CONSUME_REJECTED; if (exact_initial_r4_refusal) (void)semantic_activation_utility_mailbox_complete( - message->round_nonce, - CLUSTER_SEMANTIC_ACTIVATION_RF_DEFERRED, - CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, - message->record_generation - 1); + message->round_nonce, CLUSTER_SEMANTIC_ACTIVATION_RF_DEFERRED, + CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, message->record_generation - 1); return SEMANTIC_ACTIVATION_ACK_CONSUME_INVALIDATED; } if (message->result != CLUSTER_SEMANTIC_ACTIVATION_ACK_RESULT_OK - || !semantic_activation_ack_remote_tuple( - item, current_members_lo, current_members_hi, current_epoch, - current_coordinator_node, &tuple)) { + || !semantic_activation_ack_remote_tuple(item, current_members_lo, current_members_hi, + current_epoch, current_coordinator_node, &tuple)) { return semantic_activation_ack_image_invalidate(&image) ? SEMANTIC_ACTIVATION_ACK_CONSUME_INVALIDATED : SEMANTIC_ACTIVATION_ACK_CONSUME_REJECTED; } source_node = item->authenticated_source_node_id; - if (!semantic_activation_ack_member_present( - image.expected_members_lo, image.expected_members_hi, source_node)) { + if (!semantic_activation_ack_member_present(image.expected_members_lo, + image.expected_members_hi, source_node)) { return semantic_activation_ack_image_invalidate(&image) ? SEMANTIC_ACTIVATION_ACK_CONSUME_INVALIDATED : SEMANTIC_ACTIVATION_ACK_CONSUME_REJECTED; } - member_bit = UINT64_C(1) << (source_node < 64 ? source_node - : source_node - 64); - member_was_observed - = source_node < 64 - ? (image.observed_members_lo & member_bit) != 0 - : (image.observed_members_hi & member_bit) != 0; + member_bit = UINT64_C(1) << (source_node < 64 ? source_node : source_node - 64); + member_was_observed = source_node < 64 ? (image.observed_members_lo & member_bit) != 0 + : (image.observed_members_hi & member_bit) != 0; if (member_was_observed) { - if (semantic_activation_ack_matches( - &image.observed[source_node], &tuple)) + if (semantic_activation_ack_matches(&image.observed[source_node], &tuple)) return SEMANTIC_ACTIVATION_ACK_CONSUME_DUPLICATE; return semantic_activation_ack_image_invalidate(&image) ? SEMANTIC_ACTIVATION_ACK_CONSUME_INVALIDATED @@ -2122,9 +1913,8 @@ semantic_activation_ack_lmon_apply_item( : SEMANTIC_ACTIVATION_ACK_CONSUME_REJECTED; } memcpy(image.expected, image.observed, sizeof(image.expected)); - image.flags - = CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID - | CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE; + image.flags = CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID + | CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE; } else if (semantic_activation_full_ack_table_matches( image.observed, image.observed_members_lo, image.observed_members_hi, image.expected, image.expected_members_lo, image.expected_members_hi)) @@ -2137,15 +1927,13 @@ semantic_activation_ack_lmon_apply_item( } else image.flags &= ~CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE; - return semantic_activation_ack_table_publish(&image) - ? SEMANTIC_ACTIVATION_ACK_CONSUME_APPLIED - : SEMANTIC_ACTIVATION_ACK_CONSUME_REJECTED; + return semantic_activation_ack_table_publish(&image) ? SEMANTIC_ACTIVATION_ACK_CONSUME_APPLIED + : SEMANTIC_ACTIVATION_ACK_CONSUME_REJECTED; } static bool -semantic_activation_ack_stage_ahead_identity_matches( - const SemanticActivationAckIngressItem *left, - const SemanticActivationAckIngressItem *right) +semantic_activation_ack_stage_ahead_identity_matches(const SemanticActivationAckIngressItem *left, + const SemanticActivationAckIngressItem *right) { const ClusterSemanticActivationAckWireV1 *a; const ClusterSemanticActivationAckWireV1 *b; @@ -2154,26 +1942,23 @@ semantic_activation_ack_stage_ahead_identity_matches( return false; a = &left->message; b = &right->message; - return left->local_receiver_node_id == right->local_receiver_node_id - && a->stage == b->stage + return left->local_receiver_node_id == right->local_receiver_node_id && a->stage == b->stage && a->coordinator_node == b->coordinator_node && a->transition_epoch == b->transition_epoch - && a->record_generation == b->record_generation - && a->round_nonce == b->round_nonce + && a->record_generation == b->record_generation && a->round_nonce == b->round_nonce && a->source_feature_bitmap == b->source_feature_bitmap && a->target_feature_bitmap == b->target_feature_bitmap && a->rollback_feature_bitmap == b->rollback_feature_bitmap && a->admitted_members_lo == b->admitted_members_lo && a->admitted_members_hi == b->admitted_members_hi - && a->capability_sample_digest - == b->capability_sample_digest; + && a->capability_sample_digest == b->capability_sample_digest; } static bool -semantic_activation_ack_stage_ahead_refusal_exact( - const SemanticActivationAckIngressItem *item, - uint64 current_members_lo, uint64 current_members_hi, - uint64 current_epoch, int32 current_coordinator_node) +semantic_activation_ack_stage_ahead_refusal_exact(const SemanticActivationAckIngressItem *item, + uint64 current_members_lo, + uint64 current_members_hi, uint64 current_epoch, + int32 current_coordinator_node) { ClusterSemanticActivationAckTableV1 image; const ClusterSemanticActivationAckWireV1 *message; @@ -2182,75 +1967,60 @@ semantic_activation_ack_stage_ahead_refusal_exact( uint64 expected_generation; int32 source_node; - if (item == NULL - || !semantic_activation_ack_table_snapshot(&image)) + if (item == NULL || !semantic_activation_ack_table_snapshot(&image)) return false; message = &item->message; source_node = item->authenticated_source_node_id; if (!semantic_activation_ack_wire_value_valid(message) || message->kind != CLUSTER_SEMANTIC_ACTIVATION_ACK_KIND_ACK - || message->result - != CLUSTER_SEMANTIC_ACTIVATION_ACK_RESULT_REFUSED - || source_node < 0 || source_node >= CLUSTER_MAX_NODES - || source_node == item->local_receiver_node_id + || message->result != CLUSTER_SEMANTIC_ACTIVATION_ACK_RESULT_REFUSED || source_node < 0 + || source_node >= CLUSTER_MAX_NODES || source_node == item->local_receiver_node_id || item->local_receiver_node_id != current_coordinator_node || message->member_node != (uint32)source_node || image.stage < CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_SAMPLE || image.stage >= CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_OPEN_APPLIED - || message->stage != image.stage + 1 - || image.coordinator_node != message->coordinator_node + || message->stage != image.stage + 1 || image.coordinator_node != message->coordinator_node || image.coordinator_node != (uint32)current_coordinator_node || image.round_nonce != message->round_nonce || image.expected_members_lo != current_members_lo || image.expected_members_hi != current_members_hi || message->admitted_members_lo != current_members_lo || message->admitted_members_hi != current_members_hi - || image.transition_epoch != current_epoch - || message->transition_epoch != current_epoch + || image.transition_epoch != current_epoch || message->transition_epoch != current_epoch || image.source_feature_bitmap != message->source_feature_bitmap || image.target_feature_bitmap != message->target_feature_bitmap - || image.rollback_feature_bitmap - != message->rollback_feature_bitmap - || image.capability_sample_digest - != message->capability_sample_digest + || image.rollback_feature_bitmap != message->rollback_feature_bitmap + || image.capability_sample_digest != message->capability_sample_digest || (image.flags & (CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID | CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE)) - != (CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID - | CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE) - || !semantic_activation_ack_member_present( - current_members_lo, current_members_hi, source_node) + != (CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID + | CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE) + || !semantic_activation_ack_member_present(current_members_lo, current_members_hi, + source_node) || !semantic_activation_ack_round_required_caps( - message->source_feature_bitmap, - message->target_feature_bitmap, + message->source_feature_bitmap, message->target_feature_bitmap, message->rollback_feature_bitmap, &required_caps) || item->sampled_capability_generation == 0 || (item->sampled_capability_word & required_caps) != required_caps) return false; - expected_generation - = image.stage <= CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_BARRIER - ? image.record_generation - : image.record_generation + 1; - if (image.record_generation == UINT64_MAX - || message->record_generation != expected_generation) + expected_generation = image.stage <= CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_BARRIER + ? image.record_generation + : image.record_generation + 1; + if (image.record_generation == UINT64_MAX || message->record_generation != expected_generation) return false; expected = &image.expected[source_node]; - return expected->node_id == (uint32)source_node - && expected->admitted_incarnation != 0 - && expected->control_connection_generation - == item->sampled_capability_generation - && expected->capability_word == item->sampled_capability_word - && expected->capability_generation - == item->sampled_capability_generation - && expected->transition_epoch == current_epoch - && cluster_membership_get_state(source_node) - == CLUSTER_MEMBER_MEMBER - && cluster_membership_get_last_admitted_incarnation(source_node) - == expected->admitted_incarnation - && cluster_sf_peer_capability_generation_matches( - source_node, required_caps, - item->sampled_capability_generation); + return expected->node_id == (uint32)source_node && expected->admitted_incarnation != 0 + && expected->control_connection_generation == item->sampled_capability_generation + && expected->capability_word == item->sampled_capability_word + && expected->capability_generation == item->sampled_capability_generation + && expected->transition_epoch == current_epoch + && cluster_membership_get_state(source_node) == CLUSTER_MEMBER_MEMBER + && cluster_membership_get_last_admitted_incarnation(source_node) + == expected->admitted_incarnation + && cluster_sf_peer_capability_generation_matches(source_node, required_caps, + item->sampled_capability_generation); } /* @@ -2264,16 +2034,14 @@ semantic_activation_ack_stage_ahead_refusal_exact( */ static bool semantic_activation_ack_before_sample_request_candidate( - const SemanticActivationAckIngressItem *item, - uint64 current_members_lo, uint64 current_members_hi, - uint64 current_epoch, int32 current_coordinator_node) + const SemanticActivationAckIngressItem *item, uint64 current_members_lo, + uint64 current_members_hi, uint64 current_epoch, int32 current_coordinator_node) { ClusterSemanticActivationAckTableV1 image; SemanticActivationAdmissionSnapshot snapshot; SemanticActivationAckTuple tuple; const ClusterSemanticActivationAckWireV1 *message; - const Size payload_offset - = offsetof(ClusterSemanticActivationAckTableV1, stage); + const Size payload_offset = offsetof(ClusterSemanticActivationAckTableV1, stage); uint32 local_capability_word; uint32 required_caps; bool complete_open_predecessor; @@ -2281,8 +2049,7 @@ semantic_activation_ack_before_sample_request_candidate( int32 local_node_id; int32 source_node; - if (item == NULL - || !semantic_activation_ack_table_snapshot(&image) + if (item == NULL || !semantic_activation_ack_table_snapshot(&image) || !semantic_activation_snapshot(&snapshot)) return false; message = &item->message; @@ -2291,98 +2058,69 @@ semantic_activation_ack_before_sample_request_candidate( local_capability_word = cluster_ic_local_capability_word(); if (!semantic_activation_ack_wire_value_valid(message) || message->kind != CLUSTER_SEMANTIC_ACTIVATION_ACK_KIND_ACK - || message->stage - != CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_SAMPLE + || message->stage != CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_SAMPLE || message->result != CLUSTER_SEMANTIC_ACTIVATION_ACK_RESULT_OK - || message->reason != CLUSTER_SEMANTIC_ACTIVATION_OK - || local_node_id != cluster_node_id + || message->reason != CLUSTER_SEMANTIC_ACTIVATION_OK || local_node_id != cluster_node_id || local_node_id < 0 || local_node_id >= CLUSTER_MAX_NODES - || local_node_id == current_coordinator_node - || source_node < 0 || source_node >= CLUSTER_MAX_NODES - || source_node == local_node_id - || message->coordinator_node - != (uint32)current_coordinator_node + || local_node_id == current_coordinator_node || source_node < 0 + || source_node >= CLUSTER_MAX_NODES || source_node == local_node_id + || message->coordinator_node != (uint32)current_coordinator_node || message->member_node != (uint32)source_node || message->admitted_members_lo != current_members_lo || message->admitted_members_hi != current_members_hi - || current_members_lo != UINT64_C(0x0f) - || current_members_hi != 0 - || current_coordinator_node != 0 - || message->transition_epoch != current_epoch - || message->rollback_feature_bitmap != 0 - || message->capability_sample_digest != 0 + || current_members_lo != UINT64_C(0x0f) || current_members_hi != 0 + || current_coordinator_node != 0 || message->transition_epoch != current_epoch + || message->rollback_feature_bitmap != 0 || message->capability_sample_digest != 0 || !semantic_activation_ack_round_required_caps( - message->source_feature_bitmap, - message->target_feature_bitmap, + message->source_feature_bitmap, message->target_feature_bitmap, message->rollback_feature_bitmap, &required_caps) - || !semantic_activation_ack_member_present( - current_members_lo, current_members_hi, - current_coordinator_node) - || !semantic_activation_ack_member_present( - current_members_lo, current_members_hi, local_node_id) - || !semantic_activation_ack_member_present( - current_members_lo, current_members_hi, source_node) - || cluster_membership_get_state(current_coordinator_node) - != CLUSTER_MEMBER_MEMBER - || cluster_membership_get_state(local_node_id) - != CLUSTER_MEMBER_MEMBER + || !semantic_activation_ack_member_present(current_members_lo, current_members_hi, + current_coordinator_node) + || !semantic_activation_ack_member_present(current_members_lo, current_members_hi, + local_node_id) + || !semantic_activation_ack_member_present(current_members_lo, current_members_hi, + source_node) + || cluster_membership_get_state(current_coordinator_node) != CLUSTER_MEMBER_MEMBER + || cluster_membership_get_state(local_node_id) != CLUSTER_MEMBER_MEMBER || (local_capability_word & required_caps) != required_caps - || (snapshot.seq & UINT64_C(1)) != 0 - || snapshot.formation_epoch != current_epoch + || (snapshot.seq & UINT64_C(1)) != 0 || snapshot.formation_epoch != current_epoch || snapshot.record_generation == UINT64_MAX - || !semantic_activation_ack_remote_tuple( - item, current_members_lo, current_members_hi, current_epoch, - current_coordinator_node, &tuple)) - return false; - - exact_basis - = !snapshot.transition_closed - && snapshot.record_generation == 0 - && snapshot.active_bits == 0 - && message->source_feature_bitmap == 0 - && message->record_generation == 1 - && message->target_feature_bitmap - == CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1 - && semantic_activation_r4_initial_clean_sample_basis(0, false) - && semantic_activation_bytes_are_zero( - (const uint8 *)&image + payload_offset, - sizeof(image) - payload_offset); + || !semantic_activation_ack_remote_tuple(item, current_members_lo, current_members_hi, + current_epoch, current_coordinator_node, &tuple)) + return false; + + exact_basis = !snapshot.transition_closed && snapshot.record_generation == 0 + && snapshot.active_bits == 0 && message->source_feature_bitmap == 0 + && message->record_generation == 1 + && message->target_feature_bitmap == CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1 + && semantic_activation_r4_initial_clean_sample_basis(0, false) + && semantic_activation_bytes_are_zero((const uint8 *)&image + payload_offset, + sizeof(image) - payload_offset); if (!exact_basis) { complete_open_predecessor - = image.stage - == CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_OPEN_APPLIED + = image.stage == CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_OPEN_APPLIED && image.flags - == (CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID - | CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE) + == (CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID + | CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE) && image.record_generation != UINT64_MAX - && message->record_generation - == image.record_generation + 1 - && image.target_feature_bitmap - == message->source_feature_bitmap - && image.rollback_feature_bitmap == 0 - && image.capability_sample_digest != 0 + && message->record_generation == image.record_generation + 1 + && image.target_feature_bitmap == message->source_feature_bitmap + && image.rollback_feature_bitmap == 0 && image.capability_sample_digest != 0 && semantic_activation_ack_complete_image_current( - &image, current_members_lo, current_members_hi, - current_epoch, current_coordinator_node, local_node_id, - local_capability_word); - exact_basis - = complete_open_predecessor - && ((!snapshot.transition_closed - && snapshot.record_generation - == image.record_generation - && snapshot.active_bits - == image.target_feature_bitmap) - || (snapshot.transition_closed - && snapshot.record_generation + 1 - == image.record_generation - && snapshot.active_bits - == image.source_feature_bitmap)); + &image, current_members_lo, current_members_hi, current_epoch, + current_coordinator_node, local_node_id, local_capability_word); + exact_basis = complete_open_predecessor + && ((!snapshot.transition_closed + && snapshot.record_generation == image.record_generation + && snapshot.active_bits == image.target_feature_bitmap) + || (snapshot.transition_closed + && snapshot.record_generation + 1 == image.record_generation + && snapshot.active_bits == image.source_feature_bitmap)); } if (!exact_basis) return false; - return semantic_activation_ack_tuple_structural( - &tuple, source_node, current_epoch, message->record_generation, - required_caps); + return semantic_activation_ack_tuple_structural(&tuple, source_node, current_epoch, + message->record_generation, required_caps); } /* A completed OPEN_APPLIED table may precede this member's local gate @@ -2392,9 +2130,8 @@ semantic_activation_ack_before_sample_request_candidate( static SemanticActivationAckRequestAheadState semantic_activation_ack_sample_request_ahead_state( const SemanticActivationAckIngressItem *item, - const SemanticActivationAdmissionSnapshot *snapshot, - uint64 current_members_lo, uint64 current_members_hi, - uint64 current_epoch, int32 current_coordinator_node, + const SemanticActivationAdmissionSnapshot *snapshot, uint64 current_members_lo, + uint64 current_members_hi, uint64 current_epoch, int32 current_coordinator_node, uint32 local_capability_word) { ClusterSemanticActivationAckTableV1 current; @@ -2402,29 +2139,21 @@ semantic_activation_ack_sample_request_ahead_state( uint32 required_caps; int32 local_node_id; - if (item == NULL || snapshot == NULL - || !semantic_activation_ack_table_snapshot(¤t)) + if (item == NULL || snapshot == NULL || !semantic_activation_ack_table_snapshot(¤t)) return SEMANTIC_ACTIVATION_ACK_REQUEST_AHEAD_INVALID; message = &item->message; local_node_id = item->local_receiver_node_id; if (!semantic_activation_ack_wire_value_valid(message) - || message->kind - != CLUSTER_SEMANTIC_ACTIVATION_ACK_KIND_REQUEST - || message->stage - != CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_SAMPLE - || message->result - != CLUSTER_SEMANTIC_ACTIVATION_ACK_RESULT_REQUEST - || message->source_feature_bitmap - != CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1 + || message->kind != CLUSTER_SEMANTIC_ACTIVATION_ACK_KIND_REQUEST + || message->stage != CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_SAMPLE + || message->result != CLUSTER_SEMANTIC_ACTIVATION_ACK_RESULT_REQUEST + || message->source_feature_bitmap != CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1 || message->target_feature_bitmap - != (CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1 - | CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1) - || message->rollback_feature_bitmap != 0 - || message->capability_sample_digest != 0 - || current_members_lo != UINT64_C(0x0f) - || current_members_hi != 0 - || current_coordinator_node != 0 - || local_node_id <= 0 || local_node_id >= 4 + != (CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1 + | CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1) + || message->rollback_feature_bitmap != 0 || message->capability_sample_digest != 0 + || current_members_lo != UINT64_C(0x0f) || current_members_hi != 0 + || current_coordinator_node != 0 || local_node_id <= 0 || local_node_id >= 4 || item->authenticated_source_node_id != current_coordinator_node || message->coordinator_node != (uint32)current_coordinator_node || message->member_node != (uint32)local_node_id @@ -2432,27 +2161,21 @@ semantic_activation_ack_sample_request_ahead_state( || message->admitted_members_hi != current_members_hi || message->transition_epoch != current_epoch || !semantic_activation_ack_round_required_caps( - message->source_feature_bitmap, - message->target_feature_bitmap, + message->source_feature_bitmap, message->target_feature_bitmap, message->rollback_feature_bitmap, &required_caps) || item->sampled_capability_generation == 0 || (item->sampled_capability_word & required_caps) != required_caps || (local_capability_word & required_caps) != required_caps - || !cluster_sf_peer_capability_generation_matches( - current_coordinator_node, required_caps, - item->sampled_capability_generation) - || cluster_membership_get_state(current_coordinator_node) - != CLUSTER_MEMBER_MEMBER - || cluster_membership_get_state(local_node_id) - != CLUSTER_MEMBER_MEMBER - || (snapshot->seq & UINT64_C(1)) != 0 - || snapshot->formation_epoch != current_epoch + || !cluster_sf_peer_capability_generation_matches(current_coordinator_node, required_caps, + item->sampled_capability_generation) + || cluster_membership_get_state(current_coordinator_node) != CLUSTER_MEMBER_MEMBER + || cluster_membership_get_state(local_node_id) != CLUSTER_MEMBER_MEMBER + || (snapshot->seq & UINT64_C(1)) != 0 || snapshot->formation_epoch != current_epoch || snapshot->record_generation == UINT64_MAX - || current.stage - != CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_OPEN_APPLIED + || current.stage != CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_OPEN_APPLIED || current.flags - != (CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID - | CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE) + != (CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID + | CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE) || current.coordinator_node != message->coordinator_node || current.expected_members_lo != message->admitted_members_lo || current.expected_members_hi != message->admitted_members_hi @@ -2461,22 +2184,17 @@ semantic_activation_ack_sample_request_ahead_state( || current.transition_epoch != message->transition_epoch || current.record_generation == UINT64_MAX || message->record_generation != current.record_generation + 1 - || current.target_feature_bitmap - != message->source_feature_bitmap - || current.rollback_feature_bitmap != 0 - || current.capability_sample_digest == 0 + || current.target_feature_bitmap != message->source_feature_bitmap + || current.rollback_feature_bitmap != 0 || current.capability_sample_digest == 0 || !semantic_activation_ack_complete_image_current( - ¤t, current_members_lo, current_members_hi, - current_epoch, current_coordinator_node, local_node_id, - local_capability_word)) + ¤t, current_members_lo, current_members_hi, current_epoch, + current_coordinator_node, local_node_id, local_capability_word)) return SEMANTIC_ACTIVATION_ACK_REQUEST_AHEAD_INVALID; - if (!snapshot->transition_closed - && snapshot->record_generation == current.record_generation + if (!snapshot->transition_closed && snapshot->record_generation == current.record_generation && snapshot->active_bits == current.target_feature_bitmap) return SEMANTIC_ACTIVATION_ACK_REQUEST_AHEAD_READY; - if (snapshot->transition_closed - && snapshot->record_generation + 1 == current.record_generation + if (snapshot->transition_closed && snapshot->record_generation + 1 == current.record_generation && snapshot->active_bits == current.source_feature_bitmap) return SEMANTIC_ACTIVATION_ACK_REQUEST_AHEAD_WAIT; return SEMANTIC_ACTIVATION_ACK_REQUEST_AHEAD_INVALID; @@ -2484,77 +2202,65 @@ semantic_activation_ack_sample_request_ahead_state( static bool semantic_activation_ack_expected_predecessor_current( - const ClusterSemanticActivationAckTableV1 *image, - uint64 current_members_lo, uint64 current_members_hi, - uint64 current_epoch, int32 current_coordinator_node, + const ClusterSemanticActivationAckTableV1 *image, uint64 current_members_lo, + uint64 current_members_hi, uint64 current_epoch, int32 current_coordinator_node, int32 local_node_id, uint32 local_capability_word) { bool complete; int node; - if (image == NULL - || image->stage < CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_BARRIER + if (image == NULL || image->stage < CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_BARRIER || image->stage >= CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_OPEN_APPLIED || image->flags - & ~(CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID - | CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE) - || (image->flags - & CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID) == 0 + & ~(CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID + | CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE) + || (image->flags & CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID) == 0 || (image->observed_members_lo & ~image->expected_members_lo) != 0 || (image->observed_members_hi & ~image->expected_members_hi) != 0 || !semantic_activation_ack_expected_image_current( - image, current_members_lo, current_members_hi, current_epoch, - current_coordinator_node, local_node_id, - local_capability_word)) + image, current_members_lo, current_members_hi, current_epoch, current_coordinator_node, + local_node_id, local_capability_word)) return false; - complete - = image->observed_members_lo == image->expected_members_lo - && image->observed_members_hi == image->expected_members_hi; - if (complete - ? image->flags - != (CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID - | CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE) - : image->flags != CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID) + complete = image->observed_members_lo == image->expected_members_lo + && image->observed_members_hi == image->expected_members_hi; + if (complete ? image->flags + != (CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID + | CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE) + : image->flags != CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID) return false; for (node = 0; node < CLUSTER_MAX_NODES; node++) { - bool member = semantic_activation_ack_member_present( - image->expected_members_lo, image->expected_members_hi, node); - bool observed = semantic_activation_ack_member_present( - image->observed_members_lo, image->observed_members_hi, node); + bool member = semantic_activation_ack_member_present(image->expected_members_lo, + image->expected_members_hi, node); + bool observed = semantic_activation_ack_member_present(image->observed_members_lo, + image->observed_members_hi, node); if (!member) { - if (!semantic_activation_bytes_are_zero( - (const uint8 *)&image->expected[node], - sizeof(image->expected[node])) - || !semantic_activation_bytes_are_zero( - (const uint8 *)&image->observed[node], - sizeof(image->observed[node]))) + if (!semantic_activation_bytes_are_zero((const uint8 *)&image->expected[node], + sizeof(image->expected[node])) + || !semantic_activation_bytes_are_zero((const uint8 *)&image->observed[node], + sizeof(image->observed[node]))) return false; continue; } if (observed) { - if (!semantic_activation_ack_matches( - &image->observed[node], &image->expected[node])) + if (!semantic_activation_ack_matches(&image->observed[node], &image->expected[node])) return false; - } else if (!semantic_activation_bytes_are_zero( - (const uint8 *)&image->observed[node], - sizeof(image->observed[node]))) + } else if (!semantic_activation_bytes_are_zero((const uint8 *)&image->observed[node], + sizeof(image->observed[node]))) return false; } return !complete || semantic_activation_ack_complete_image_current( - image, current_members_lo, current_members_hi, - current_epoch, current_coordinator_node, local_node_id, - local_capability_word); + image, current_members_lo, current_members_hi, current_epoch, + current_coordinator_node, local_node_id, local_capability_word); } static bool -semantic_activation_ack_stage_ahead_candidate( - const SemanticActivationAckIngressItem *item, - uint64 current_members_lo, uint64 current_members_hi, - uint64 current_epoch, int32 current_coordinator_node) +semantic_activation_ack_stage_ahead_candidate(const SemanticActivationAckIngressItem *item, + uint64 current_members_lo, uint64 current_members_hi, + uint64 current_epoch, int32 current_coordinator_node) { ClusterSemanticActivationAckTableV1 image; SemanticActivationAckTuple expected; @@ -2564,8 +2270,7 @@ semantic_activation_ack_stage_ahead_candidate( uint64 expected_generation; int32 source_node; - if (item == NULL - || !semantic_activation_ack_table_snapshot(&image)) + if (item == NULL || !semantic_activation_ack_table_snapshot(&image)) return false; message = &item->message; source_node = item->authenticated_source_node_id; @@ -2574,49 +2279,39 @@ semantic_activation_ack_stage_ahead_candidate( || message->kind != CLUSTER_SEMANTIC_ACTIVATION_ACK_KIND_ACK || message->result != CLUSTER_SEMANTIC_ACTIVATION_ACK_RESULT_OK || message->reason != CLUSTER_SEMANTIC_ACTIVATION_OK - || item->local_receiver_node_id != cluster_node_id - || source_node < 0 || source_node >= CLUSTER_MAX_NODES - || message->member_node != (uint32)source_node + || item->local_receiver_node_id != cluster_node_id || source_node < 0 + || source_node >= CLUSTER_MAX_NODES || message->member_node != (uint32)source_node || image.stage < CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_SAMPLE || image.stage >= CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_OPEN_APPLIED - || message->stage != image.stage + 1 - || image.coordinator_node != message->coordinator_node + || message->stage != image.stage + 1 || image.coordinator_node != message->coordinator_node || image.coordinator_node != (uint32)current_coordinator_node || image.round_nonce != message->round_nonce || image.expected_members_lo != current_members_lo || image.expected_members_hi != current_members_hi || message->admitted_members_lo != current_members_lo || message->admitted_members_hi != current_members_hi - || image.transition_epoch != current_epoch - || message->transition_epoch != current_epoch + || image.transition_epoch != current_epoch || message->transition_epoch != current_epoch || image.source_feature_bitmap != message->source_feature_bitmap || image.target_feature_bitmap != message->target_feature_bitmap - || image.rollback_feature_bitmap - != message->rollback_feature_bitmap + || image.rollback_feature_bitmap != message->rollback_feature_bitmap || (image.stage == CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_SAMPLE - ? message->capability_sample_digest == 0 - : image.capability_sample_digest - != message->capability_sample_digest) + ? message->capability_sample_digest == 0 + : image.capability_sample_digest != message->capability_sample_digest) || !(image.stage == CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_SAMPLE - ? semantic_activation_ack_complete_image_current( - &image, current_members_lo, current_members_hi, - current_epoch, current_coordinator_node, - cluster_node_id, local_capability_word) - : semantic_activation_ack_expected_predecessor_current( - &image, current_members_lo, current_members_hi, - current_epoch, current_coordinator_node, - cluster_node_id, local_capability_word)) - || !semantic_activation_ack_remote_tuple( - item, current_members_lo, current_members_hi, current_epoch, - current_coordinator_node, &tuple)) + ? semantic_activation_ack_complete_image_current( + &image, current_members_lo, current_members_hi, current_epoch, + current_coordinator_node, cluster_node_id, local_capability_word) + : semantic_activation_ack_expected_predecessor_current( + &image, current_members_lo, current_members_hi, current_epoch, + current_coordinator_node, cluster_node_id, local_capability_word)) + || !semantic_activation_ack_remote_tuple(item, current_members_lo, current_members_hi, + current_epoch, current_coordinator_node, &tuple)) return false; - expected_generation - = image.stage <= CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_BARRIER - ? image.record_generation - : image.record_generation + 1; - if (image.record_generation == UINT64_MAX - || message->record_generation != expected_generation) + expected_generation = image.stage <= CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_BARRIER + ? image.record_generation + : image.record_generation + 1; + if (image.record_generation == UINT64_MAX || message->record_generation != expected_generation) return false; expected = image.expected[source_node]; expected.record_generation = expected_generation; @@ -2624,34 +2319,29 @@ semantic_activation_ack_stage_ahead_candidate( } static SemanticActivationAckConsumeResult -semantic_activation_ack_lmon_retain_stage_ahead( - const SemanticActivationAckIngressItem *item, - uint64 current_members_lo, uint64 current_members_hi, - uint64 current_epoch, int32 current_coordinator_node) +semantic_activation_ack_lmon_retain_stage_ahead(const SemanticActivationAckIngressItem *item, + uint64 current_members_lo, + uint64 current_members_hi, uint64 current_epoch, + int32 current_coordinator_node) { - SemanticActivationAckStageAhead *retained - = &semantic_activation_ack_local_stage_ahead; + SemanticActivationAckStageAhead *retained = &semantic_activation_ack_local_stage_ahead; uint32 index; - if (!semantic_activation_ack_stage_ahead_candidate( - item, current_members_lo, current_members_hi, current_epoch, - current_coordinator_node) + if (!semantic_activation_ack_stage_ahead_candidate(item, current_members_lo, current_members_hi, + current_epoch, current_coordinator_node) && !semantic_activation_ack_before_sample_request_candidate( item, current_members_lo, current_members_hi, current_epoch, current_coordinator_node)) { - if (semantic_activation_ack_stage_ahead_refusal_exact( - item, current_members_lo, current_members_hi, current_epoch, - current_coordinator_node)) { + if (semantic_activation_ack_stage_ahead_refusal_exact(item, current_members_lo, + current_members_hi, current_epoch, + current_coordinator_node)) { semantic_activation_ack_lmon_invalidate_active(); return SEMANTIC_ACTIVATION_ACK_CONSUME_INVALIDATED; } if (retained->count != 0 && item != NULL - && item->message.kind - == CLUSTER_SEMANTIC_ACTIVATION_ACK_KIND_ACK - && item->message.result - == CLUSTER_SEMANTIC_ACTIVATION_ACK_RESULT_OK - && item->local_receiver_node_id - == retained->items[0].local_receiver_node_id + && item->message.kind == CLUSTER_SEMANTIC_ACTIVATION_ACK_KIND_ACK + && item->message.result == CLUSTER_SEMANTIC_ACTIVATION_ACK_RESULT_OK + && item->local_receiver_node_id == retained->items[0].local_receiver_node_id && item->message.stage == retained->items[0].message.stage) { semantic_activation_ack_lmon_invalidate_active(); return SEMANTIC_ACTIVATION_ACK_CONSUME_INVALIDATED; @@ -2660,8 +2350,7 @@ semantic_activation_ack_lmon_retain_stage_ahead( } if (retained->count != 0 - && !semantic_activation_ack_stage_ahead_identity_matches( - item, &retained->items[0])) { + && !semantic_activation_ack_stage_ahead_identity_matches(item, &retained->items[0])) { semantic_activation_ack_lmon_invalidate_active(); return SEMANTIC_ACTIVATION_ACK_CONSUME_INVALIDATED; } @@ -2683,19 +2372,17 @@ semantic_activation_ack_lmon_retain_stage_ahead( } static bool -semantic_activation_ack_lmon_apply_stage_ahead( - const SemanticActivationAckIngressItem *request, - SemanticActivationAckConsumeResult request_result, - uint64 current_members_lo, uint64 current_members_hi, - uint64 current_epoch, int32 current_coordinator_node) +semantic_activation_ack_lmon_apply_stage_ahead(const SemanticActivationAckIngressItem *request, + SemanticActivationAckConsumeResult request_result, + uint64 current_members_lo, uint64 current_members_hi, + uint64 current_epoch, int32 current_coordinator_node) { SemanticActivationAckStageAhead retained; uint32 index; - if (semantic_activation_ack_local_stage_ahead.count == 0 - || request == NULL + if (semantic_activation_ack_local_stage_ahead.count == 0 || request == NULL || request->message.stage - != semantic_activation_ack_local_stage_ahead.items[0].message.stage) + != semantic_activation_ack_local_stage_ahead.items[0].message.stage) return true; if (request_result != SEMANTIC_ACTIVATION_ACK_CONSUME_APPLIED || !semantic_activation_ack_stage_ahead_identity_matches( @@ -2708,11 +2395,9 @@ semantic_activation_ack_lmon_apply_stage_ahead( memset(&semantic_activation_ack_local_stage_ahead, 0, sizeof(semantic_activation_ack_local_stage_ahead)); for (index = 0; index < retained.count; index++) { - SemanticActivationAckConsumeResult result - = semantic_activation_ack_lmon_apply_item( - &retained.items[index], current_members_lo, - current_members_hi, current_epoch, - current_coordinator_node); + SemanticActivationAckConsumeResult result = semantic_activation_ack_lmon_apply_item( + &retained.items[index], current_members_lo, current_members_hi, current_epoch, + current_coordinator_node); if (result != SEMANTIC_ACTIVATION_ACK_CONSUME_APPLIED && result != SEMANTIC_ACTIVATION_ACK_CONSUME_DUPLICATE) { @@ -2726,9 +2411,8 @@ semantic_activation_ack_lmon_apply_stage_ahead( static SemanticActivationAckRequestAheadState semantic_activation_ack_barrier_request_ahead_state( const SemanticActivationAckIngressItem *item, - const SemanticActivationAdmissionSnapshot *snapshot, - uint64 current_members_lo, uint64 current_members_hi, - uint64 current_epoch, int32 current_coordinator_node, + const SemanticActivationAdmissionSnapshot *snapshot, uint64 current_members_lo, + uint64 current_members_hi, uint64 current_epoch, int32 current_coordinator_node, uint32 local_capability_word) { ClusterSemanticActivationAckTableV1 current; @@ -2738,74 +2422,54 @@ semantic_activation_ack_barrier_request_ahead_state( int32 local_node_id; int node; - if (item == NULL || snapshot == NULL - || !semantic_activation_ack_table_snapshot(¤t)) + if (item == NULL || snapshot == NULL || !semantic_activation_ack_table_snapshot(¤t)) return SEMANTIC_ACTIVATION_ACK_REQUEST_AHEAD_INVALID; message = &item->message; local_node_id = item->local_receiver_node_id; if (!semantic_activation_ack_wire_value_valid(message) - || message->kind - != CLUSTER_SEMANTIC_ACTIVATION_ACK_KIND_REQUEST - || message->stage - != CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_BARRIER - || message->result - != CLUSTER_SEMANTIC_ACTIVATION_ACK_RESULT_REQUEST - || message->source_feature_bitmap - != CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1 + || message->kind != CLUSTER_SEMANTIC_ACTIVATION_ACK_KIND_REQUEST + || message->stage != CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_BARRIER + || message->result != CLUSTER_SEMANTIC_ACTIVATION_ACK_RESULT_REQUEST + || message->source_feature_bitmap != CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1 || message->target_feature_bitmap - != (CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1 - | CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1) - || message->rollback_feature_bitmap != 0 - || current_coordinator_node < 0 - || current_coordinator_node >= CLUSTER_MAX_NODES - || local_node_id < 0 || local_node_id >= CLUSTER_MAX_NODES - || local_node_id == current_coordinator_node - || item->authenticated_source_node_id - != current_coordinator_node - || message->coordinator_node - != (uint32) current_coordinator_node - || message->member_node != (uint32) local_node_id + != (CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1 + | CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1) + || message->rollback_feature_bitmap != 0 || current_coordinator_node < 0 + || current_coordinator_node >= CLUSTER_MAX_NODES || local_node_id < 0 + || local_node_id >= CLUSTER_MAX_NODES || local_node_id == current_coordinator_node + || item->authenticated_source_node_id != current_coordinator_node + || message->coordinator_node != (uint32)current_coordinator_node + || message->member_node != (uint32)local_node_id || message->admitted_members_lo != current_members_lo || message->admitted_members_hi != current_members_hi || message->transition_epoch != current_epoch || !semantic_activation_ack_round_required_caps( - message->source_feature_bitmap, - message->target_feature_bitmap, + message->source_feature_bitmap, message->target_feature_bitmap, message->rollback_feature_bitmap, &required_caps) - || !semantic_activation_ack_member_present( - current_members_lo, current_members_hi, - current_coordinator_node) - || !semantic_activation_ack_member_present( - current_members_lo, current_members_hi, local_node_id) - || cluster_membership_get_state(current_coordinator_node) - != CLUSTER_MEMBER_MEMBER + || !semantic_activation_ack_member_present(current_members_lo, current_members_hi, + current_coordinator_node) + || !semantic_activation_ack_member_present(current_members_lo, current_members_hi, + local_node_id) + || cluster_membership_get_state(current_coordinator_node) != CLUSTER_MEMBER_MEMBER || item->sampled_capability_generation == 0 || (item->sampled_capability_word & required_caps) != required_caps || (local_capability_word & required_caps) != required_caps - || !cluster_sf_peer_capability_generation_matches( - current_coordinator_node, required_caps, - item->sampled_capability_generation) - || (snapshot->seq & UINT64_C(1)) != 0 - || snapshot->transition_closed - || snapshot->formation_epoch != current_epoch - || snapshot->record_generation == UINT64_MAX - || message->record_generation - != snapshot->record_generation + 1 + || !cluster_sf_peer_capability_generation_matches(current_coordinator_node, required_caps, + item->sampled_capability_generation) + || (snapshot->seq & UINT64_C(1)) != 0 || snapshot->transition_closed + || snapshot->formation_epoch != current_epoch || snapshot->record_generation == UINT64_MAX + || message->record_generation != snapshot->record_generation + 1 || snapshot->active_bits != message->source_feature_bitmap - || current.stage - != CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_SAMPLE + || current.stage != CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_SAMPLE || current.coordinator_node != message->coordinator_node || current.round_nonce != message->round_nonce || current.expected_members_lo != message->admitted_members_lo || current.expected_members_hi != message->admitted_members_hi || current.transition_epoch != message->transition_epoch || current.record_generation != message->record_generation - || current.source_feature_bitmap - != message->source_feature_bitmap - || current.target_feature_bitmap - != message->target_feature_bitmap - || current.rollback_feature_bitmap - != message->rollback_feature_bitmap + || current.source_feature_bitmap != message->source_feature_bitmap + || current.target_feature_bitmap != message->target_feature_bitmap + || current.rollback_feature_bitmap != message->rollback_feature_bitmap || current.capability_sample_digest != 0 || (current.observed_members_lo & ~current.expected_members_lo) != 0 || (current.observed_members_hi & ~current.expected_members_hi) != 0) @@ -2815,41 +2479,36 @@ semantic_activation_ack_barrier_request_ahead_state( && (current.observed_members_lo != current.expected_members_lo || current.observed_members_hi != current.expected_members_hi)) { for (node = 0; node < CLUSTER_MAX_NODES; node++) { - bool member = semantic_activation_ack_member_present( - current.expected_members_lo, current.expected_members_hi, - node); + bool member = semantic_activation_ack_member_present(current.expected_members_lo, + current.expected_members_hi, node); bool observed = semantic_activation_ack_member_present( - current.observed_members_lo, current.observed_members_hi, - node); + current.observed_members_lo, current.observed_members_hi, node); - if (!semantic_activation_bytes_are_zero( - (const uint8 *) ¤t.expected[node], - sizeof(current.expected[node]))) + if (!semantic_activation_bytes_are_zero((const uint8 *)¤t.expected[node], + sizeof(current.expected[node]))) return SEMANTIC_ACTIVATION_ACK_REQUEST_AHEAD_INVALID; if (!member || !observed) { - if (!semantic_activation_bytes_are_zero( - (const uint8 *) ¤t.observed[node], - sizeof(current.observed[node]))) + if (!semantic_activation_bytes_are_zero((const uint8 *)¤t.observed[node], + sizeof(current.observed[node]))) return SEMANTIC_ACTIVATION_ACK_REQUEST_AHEAD_INVALID; continue; } - if (!semantic_activation_ack_tuple_structural( - ¤t.observed[node], node, current_epoch, - current.record_generation, required_caps)) + if (!semantic_activation_ack_tuple_structural(¤t.observed[node], node, + current_epoch, current.record_generation, + required_caps)) return SEMANTIC_ACTIVATION_ACK_REQUEST_AHEAD_INVALID; } return SEMANTIC_ACTIVATION_ACK_REQUEST_AHEAD_WAIT; } if (current.flags - != (CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID - | CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE) + != (CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID + | CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE) || current.observed_members_lo != current.expected_members_lo || current.observed_members_hi != current.expected_members_hi || !semantic_activation_ack_complete_image_current( - ¤t, current_members_lo, current_members_hi, - current_epoch, current_coordinator_node, local_node_id, - local_capability_word) + ¤t, current_members_lo, current_members_hi, current_epoch, + current_coordinator_node, local_node_id, local_capability_word) || !semantic_activation_ack_sample_digest(¤t, &digest) || digest != message->capability_sample_digest) return SEMANTIC_ACTIVATION_ACK_REQUEST_AHEAD_INVALID; @@ -2859,9 +2518,8 @@ semantic_activation_ack_barrier_request_ahead_state( static SemanticActivationAckRequestAheadState semantic_activation_ack_bit22_later_request_ahead_state( const SemanticActivationAckIngressItem *item, - const SemanticActivationAdmissionSnapshot *snapshot, - uint64 current_members_lo, uint64 current_members_hi, - uint64 current_epoch, int32 current_coordinator_node, + const SemanticActivationAdmissionSnapshot *snapshot, uint64 current_members_lo, + uint64 current_members_hi, uint64 current_epoch, int32 current_coordinator_node, uint32 local_capability_word) { ClusterSemanticActivationAckTableV1 current; @@ -2873,15 +2531,12 @@ semantic_activation_ack_bit22_later_request_ahead_state( uint64 self_bit; int32 local_node_id; - if (item == NULL || snapshot == NULL - || !semantic_activation_ack_table_snapshot(¤t)) + if (item == NULL || snapshot == NULL || !semantic_activation_ack_table_snapshot(¤t)) return SEMANTIC_ACTIVATION_ACK_REQUEST_AHEAD_INVALID; message = &item->message; local_node_id = item->local_receiver_node_id; - if (message->stage - == CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_PREPARED) { - predecessor_stage - = CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_BARRIER; + if (message->stage == CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_PREPARED) { + predecessor_stage = CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_BARRIER; if (snapshot->transition_closed) { predecessor_generation = snapshot->record_generation; request_generation = snapshot->record_generation; @@ -2891,71 +2546,54 @@ semantic_activation_ack_bit22_later_request_ahead_state( predecessor_generation = snapshot->record_generation + 1; request_generation = snapshot->record_generation + 1; } - } else if (message->stage - == CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_COMMIT_APPLIED) { + } else if (message->stage == CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_COMMIT_APPLIED) { if (snapshot->record_generation == UINT64_MAX) return SEMANTIC_ACTIVATION_ACK_REQUEST_AHEAD_INVALID; - predecessor_stage - = CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_PREPARED; + predecessor_stage = CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_PREPARED; predecessor_generation = snapshot->record_generation; request_generation = snapshot->record_generation + 1; - } else if (message->stage - == CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_OPEN_APPLIED) { + } else if (message->stage == CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_OPEN_APPLIED) { if (snapshot->record_generation > UINT64_MAX - 2) return SEMANTIC_ACTIVATION_ACK_REQUEST_AHEAD_INVALID; - predecessor_stage - = CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_COMMIT_APPLIED; + predecessor_stage = CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_COMMIT_APPLIED; predecessor_generation = snapshot->record_generation + 1; request_generation = snapshot->record_generation + 2; } else return SEMANTIC_ACTIVATION_ACK_REQUEST_AHEAD_INVALID; if (!semantic_activation_ack_wire_value_valid(message) - || message->kind - != CLUSTER_SEMANTIC_ACTIVATION_ACK_KIND_REQUEST - || message->result - != CLUSTER_SEMANTIC_ACTIVATION_ACK_RESULT_REQUEST - || (message->target_feature_bitmap - & PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1) == 0 - || message->source_feature_bitmap != 0 - || message->rollback_feature_bitmap != 0 - || current_coordinator_node < 0 - || current_coordinator_node >= CLUSTER_MAX_NODES + || message->kind != CLUSTER_SEMANTIC_ACTIVATION_ACK_KIND_REQUEST + || message->result != CLUSTER_SEMANTIC_ACTIVATION_ACK_RESULT_REQUEST + || (message->target_feature_bitmap & PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1) + == 0 + || message->source_feature_bitmap != 0 || message->rollback_feature_bitmap != 0 + || current_coordinator_node < 0 || current_coordinator_node >= CLUSTER_MAX_NODES || local_node_id < 0 || local_node_id >= CLUSTER_MAX_NODES || local_node_id == current_coordinator_node - || item->authenticated_source_node_id - != current_coordinator_node - || message->coordinator_node - != (uint32)current_coordinator_node + || item->authenticated_source_node_id != current_coordinator_node + || message->coordinator_node != (uint32)current_coordinator_node || message->member_node != (uint32)local_node_id || message->admitted_members_lo != current_members_lo || message->admitted_members_hi != current_members_hi || message->transition_epoch != current_epoch - || !semantic_activation_ack_member_present( - current_members_lo, current_members_hi, - current_coordinator_node) - || !semantic_activation_ack_member_present( - current_members_lo, current_members_hi, local_node_id) - || cluster_membership_get_state(current_coordinator_node) - != CLUSTER_MEMBER_MEMBER + || !semantic_activation_ack_member_present(current_members_lo, current_members_hi, + current_coordinator_node) + || !semantic_activation_ack_member_present(current_members_lo, current_members_hi, + local_node_id) + || cluster_membership_get_state(current_coordinator_node) != CLUSTER_MEMBER_MEMBER || !semantic_activation_ack_round_required_caps( - message->source_feature_bitmap, - message->target_feature_bitmap, + message->source_feature_bitmap, message->target_feature_bitmap, message->rollback_feature_bitmap, &required_caps) || item->sampled_capability_generation == 0 - || (item->sampled_capability_word & required_caps) - != required_caps + || (item->sampled_capability_word & required_caps) != required_caps || (local_capability_word & required_caps) != required_caps - || !cluster_sf_peer_capability_generation_matches( - current_coordinator_node, required_caps, - item->sampled_capability_generation) - || (snapshot->seq & UINT64_C(1)) != 0 - || snapshot->formation_epoch != current_epoch + || !cluster_sf_peer_capability_generation_matches(current_coordinator_node, required_caps, + item->sampled_capability_generation) + || (snapshot->seq & UINT64_C(1)) != 0 || snapshot->formation_epoch != current_epoch || snapshot->record_generation == UINT64_MAX || snapshot->active_bits != message->source_feature_bitmap || current.stage != predecessor_stage - || current.flags - != CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID + || current.flags != CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID || current.coordinator_node != message->coordinator_node || current.round_nonce != message->round_nonce || current.expected_members_lo != message->admitted_members_lo @@ -2963,19 +2601,14 @@ semantic_activation_ack_bit22_later_request_ahead_state( || current.transition_epoch != message->transition_epoch || current.record_generation != predecessor_generation || message->record_generation != request_generation - || current.source_feature_bitmap - != message->source_feature_bitmap - || current.target_feature_bitmap - != message->target_feature_bitmap - || current.rollback_feature_bitmap - != message->rollback_feature_bitmap + || current.source_feature_bitmap != message->source_feature_bitmap + || current.target_feature_bitmap != message->target_feature_bitmap + || current.rollback_feature_bitmap != message->rollback_feature_bitmap || current.capability_sample_digest == 0 - || current.capability_sample_digest - != message->capability_sample_digest + || current.capability_sample_digest != message->capability_sample_digest || !semantic_activation_ack_expected_predecessor_current( - ¤t, current_members_lo, current_members_hi, - current_epoch, current_coordinator_node, local_node_id, - local_capability_word)) + ¤t, current_members_lo, current_members_hi, current_epoch, + current_coordinator_node, local_node_id, local_capability_word)) return SEMANTIC_ACTIVATION_ACK_REQUEST_AHEAD_INVALID; /* The local bit22 predecessor has exactly two legal evidence shapes: @@ -2983,25 +2616,20 @@ semantic_activation_ack_bit22_later_request_ahead_state( * after that callback. Other peer rows are coordinator-local and cannot * be used to make this member ready. */ self_bit = UINT64_C(1) << local_node_id; - if (current.observed_members_lo == 0 - && current.observed_members_hi == 0) { - if (message->stage - == CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_PREPARED + if (current.observed_members_lo == 0 && current.observed_members_hi == 0) { + if (message->stage == CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_PREPARED && !snapshot->transition_closed) { if (snapshot->record_generation == UINT64_MAX - || snapshot->record_generation + 1 - != message->record_generation) + || snapshot->record_generation + 1 != message->record_generation) return SEMANTIC_ACTIVATION_ACK_REQUEST_AHEAD_INVALID; } else if (!snapshot->transition_closed) return SEMANTIC_ACTIVATION_ACK_REQUEST_AHEAD_INVALID; return SEMANTIC_ACTIVATION_ACK_REQUEST_AHEAD_WAIT; } - if (!snapshot->transition_closed - || current.observed_members_lo != self_bit + if (!snapshot->transition_closed || current.observed_members_lo != self_bit || current.observed_members_hi != 0 - || !semantic_activation_ack_matches( - ¤t.observed[local_node_id], - ¤t.expected[local_node_id])) + || !semantic_activation_ack_matches(¤t.observed[local_node_id], + ¤t.expected[local_node_id])) return SEMANTIC_ACTIVATION_ACK_REQUEST_AHEAD_INVALID; return SEMANTIC_ACTIVATION_ACK_REQUEST_AHEAD_READY; } @@ -3009,9 +2637,8 @@ semantic_activation_ack_bit22_later_request_ahead_state( static SemanticActivationAckRequestAheadState semantic_activation_ack_later_request_ahead_state( const SemanticActivationAckIngressItem *item, - const SemanticActivationAdmissionSnapshot *snapshot, - uint64 current_members_lo, uint64 current_members_hi, - uint64 current_epoch, int32 current_coordinator_node, + const SemanticActivationAdmissionSnapshot *snapshot, uint64 current_members_lo, + uint64 current_members_hi, uint64 current_epoch, int32 current_coordinator_node, uint32 local_capability_word) { ClusterSemanticActivationAckTableV1 current; @@ -3020,28 +2647,22 @@ semantic_activation_ack_later_request_ahead_state( uint64 expected_generation; int32 local_node_id; - if (item == NULL || snapshot == NULL - || !semantic_activation_ack_table_snapshot(¤t)) + if (item == NULL || snapshot == NULL || !semantic_activation_ack_table_snapshot(¤t)) return SEMANTIC_ACTIVATION_ACK_REQUEST_AHEAD_INVALID; message = &item->message; local_node_id = item->local_receiver_node_id; - if ((message->target_feature_bitmap - & PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1) != 0) + if ((message->target_feature_bitmap & PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1) + != 0) return semantic_activation_ack_bit22_later_request_ahead_state( - item, snapshot, current_members_lo, current_members_hi, - current_epoch, current_coordinator_node, - local_capability_word); + item, snapshot, current_members_lo, current_members_hi, current_epoch, + current_coordinator_node, local_capability_word); if (!semantic_activation_ack_wire_value_valid(message) - || message->kind - != CLUSTER_SEMANTIC_ACTIVATION_ACK_KIND_REQUEST + || message->kind != CLUSTER_SEMANTIC_ACTIVATION_ACK_KIND_REQUEST || message->stage < CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_PREPARED || message->stage > CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_OPEN_APPLIED - || message->result - != CLUSTER_SEMANTIC_ACTIVATION_ACK_RESULT_REQUEST - || current_members_lo != UINT64_C(0x0f) - || current_members_hi != 0 - || current_coordinator_node != 0 - || local_node_id <= 0 || local_node_id >= 4 + || message->result != CLUSTER_SEMANTIC_ACTIVATION_ACK_RESULT_REQUEST + || current_members_lo != UINT64_C(0x0f) || current_members_hi != 0 + || current_coordinator_node != 0 || local_node_id <= 0 || local_node_id >= 4 || item->authenticated_source_node_id != current_coordinator_node || message->coordinator_node != (uint32)current_coordinator_node || message->member_node != (uint32)local_node_id @@ -3049,19 +2670,15 @@ semantic_activation_ack_later_request_ahead_state( || message->admitted_members_hi != current_members_hi || message->transition_epoch != current_epoch || !semantic_activation_ack_round_required_caps( - message->source_feature_bitmap, - message->target_feature_bitmap, + message->source_feature_bitmap, message->target_feature_bitmap, message->rollback_feature_bitmap, &required_caps) - || cluster_membership_get_state(current_coordinator_node) - != CLUSTER_MEMBER_MEMBER + || cluster_membership_get_state(current_coordinator_node) != CLUSTER_MEMBER_MEMBER || item->sampled_capability_generation == 0 || (item->sampled_capability_word & required_caps) != required_caps || (local_capability_word & required_caps) != required_caps - || !cluster_sf_peer_capability_generation_matches( - current_coordinator_node, required_caps, - item->sampled_capability_generation) - || (snapshot->seq & UINT64_C(1)) != 0 - || snapshot->formation_epoch != current_epoch + || !cluster_sf_peer_capability_generation_matches(current_coordinator_node, required_caps, + item->sampled_capability_generation) + || (snapshot->seq & UINT64_C(1)) != 0 || snapshot->formation_epoch != current_epoch || snapshot->record_generation == UINT64_MAX || snapshot->active_bits != message->source_feature_bitmap || current.stage + 1 != message->stage @@ -3070,96 +2687,75 @@ semantic_activation_ack_later_request_ahead_state( || current.expected_members_lo != message->admitted_members_lo || current.expected_members_hi != message->admitted_members_hi || current.transition_epoch != message->transition_epoch - || current.source_feature_bitmap - != message->source_feature_bitmap - || current.target_feature_bitmap - != message->target_feature_bitmap - || current.rollback_feature_bitmap - != message->rollback_feature_bitmap + || current.source_feature_bitmap != message->source_feature_bitmap + || current.target_feature_bitmap != message->target_feature_bitmap + || current.rollback_feature_bitmap != message->rollback_feature_bitmap || current.capability_sample_digest == 0 - || current.capability_sample_digest - != message->capability_sample_digest + || current.capability_sample_digest != message->capability_sample_digest || !semantic_activation_ack_expected_predecessor_current( - ¤t, current_members_lo, current_members_hi, - current_epoch, current_coordinator_node, local_node_id, - local_capability_word)) + ¤t, current_members_lo, current_members_hi, current_epoch, + current_coordinator_node, local_node_id, local_capability_word)) return SEMANTIC_ACTIVATION_ACK_REQUEST_AHEAD_INVALID; - expected_generation - = current.stage == CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_BARRIER - ? current.record_generation - : current.record_generation + 1; - if (current.record_generation == UINT64_MAX - || message->record_generation != expected_generation + expected_generation = current.stage == CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_BARRIER + ? current.record_generation + : current.record_generation + 1; + if (current.record_generation == UINT64_MAX || message->record_generation != expected_generation || (message->stage == CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_PREPARED - ? (snapshot->transition_closed - ? snapshot->record_generation - != message->record_generation - : snapshot->record_generation == UINT64_MAX - || snapshot->record_generation + 1 - != message->record_generation) - : !snapshot->transition_closed - || snapshot->record_generation + 1 - != message->record_generation)) + ? (snapshot->transition_closed + ? snapshot->record_generation != message->record_generation + : snapshot->record_generation == UINT64_MAX + || snapshot->record_generation + 1 != message->record_generation) + : !snapshot->transition_closed + || snapshot->record_generation + 1 != message->record_generation)) return SEMANTIC_ACTIVATION_ACK_REQUEST_AHEAD_INVALID; if (!snapshot->transition_closed) return SEMANTIC_ACTIVATION_ACK_REQUEST_AHEAD_WAIT; return current.observed_members_lo == current.expected_members_lo - && current.observed_members_hi == current.expected_members_hi - ? SEMANTIC_ACTIVATION_ACK_REQUEST_AHEAD_READY - : SEMANTIC_ACTIVATION_ACK_REQUEST_AHEAD_WAIT; + && current.observed_members_hi == current.expected_members_hi + ? SEMANTIC_ACTIVATION_ACK_REQUEST_AHEAD_READY + : SEMANTIC_ACTIVATION_ACK_REQUEST_AHEAD_WAIT; } static SemanticActivationAckRequestAheadState -semantic_activation_ack_request_ahead_state( - const SemanticActivationAckIngressItem *item, - const SemanticActivationAdmissionSnapshot *snapshot, - uint64 current_members_lo, uint64 current_members_hi, - uint64 current_epoch, int32 current_coordinator_node, - uint32 local_capability_word) +semantic_activation_ack_request_ahead_state(const SemanticActivationAckIngressItem *item, + const SemanticActivationAdmissionSnapshot *snapshot, + uint64 current_members_lo, uint64 current_members_hi, + uint64 current_epoch, int32 current_coordinator_node, + uint32 local_capability_word) { - if (item != NULL - && item->message.stage - == CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_SAMPLE) + if (item != NULL && item->message.stage == CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_SAMPLE) return semantic_activation_ack_sample_request_ahead_state( - item, snapshot, current_members_lo, current_members_hi, - current_epoch, current_coordinator_node, - local_capability_word); - if (item != NULL - && item->message.stage - == CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_BARRIER) + item, snapshot, current_members_lo, current_members_hi, current_epoch, + current_coordinator_node, local_capability_word); + if (item != NULL && item->message.stage == CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_BARRIER) return semantic_activation_ack_barrier_request_ahead_state( - item, snapshot, current_members_lo, current_members_hi, - current_epoch, current_coordinator_node, - local_capability_word); + item, snapshot, current_members_lo, current_members_hi, current_epoch, + current_coordinator_node, local_capability_word); return semantic_activation_ack_later_request_ahead_state( - item, snapshot, current_members_lo, current_members_hi, - current_epoch, current_coordinator_node, local_capability_word); + item, snapshot, current_members_lo, current_members_hi, current_epoch, + current_coordinator_node, local_capability_word); } static SemanticActivationAckConsumeResult semantic_activation_ack_lmon_retain_request_ahead( const SemanticActivationAckIngressItem *item, - const SemanticActivationAdmissionSnapshot *snapshot, - uint64 current_members_lo, uint64 current_members_hi, - uint64 current_epoch, int32 current_coordinator_node, + const SemanticActivationAdmissionSnapshot *snapshot, uint64 current_members_lo, + uint64 current_members_hi, uint64 current_epoch, int32 current_coordinator_node, uint32 local_capability_word) { - SemanticActivationAckRequestAhead *retained - = &semantic_activation_ack_local_request_ahead; + SemanticActivationAckRequestAhead *retained = &semantic_activation_ack_local_request_ahead; SemanticActivationAckRequestAheadState state; state = semantic_activation_ack_request_ahead_state( - item, snapshot, current_members_lo, current_members_hi, - current_epoch, current_coordinator_node, local_capability_word); + item, snapshot, current_members_lo, current_members_hi, current_epoch, + current_coordinator_node, local_capability_word); if (state != SEMANTIC_ACTIVATION_ACK_REQUEST_AHEAD_WAIT) { if (retained->valid && item != NULL - && item->message.kind - == CLUSTER_SEMANTIC_ACTIVATION_ACK_KIND_REQUEST + && item->message.kind == CLUSTER_SEMANTIC_ACTIVATION_ACK_KIND_REQUEST && item->message.stage == retained->item.message.stage - && item->local_receiver_node_id - == retained->item.local_receiver_node_id) { + && item->local_receiver_node_id == retained->item.local_receiver_node_id) { semantic_activation_ack_lmon_invalidate_active(); return SEMANTIC_ACTIVATION_ACK_CONSUME_INVALIDATED; } @@ -3177,9 +2773,9 @@ semantic_activation_ack_lmon_retain_request_ahead( } static bool -semantic_activation_ack_lmon_consume_request_ahead( - uint64 current_members_lo, uint64 current_members_hi, - uint64 current_epoch, int32 current_coordinator_node) +semantic_activation_ack_lmon_consume_request_ahead(uint64 current_members_lo, + uint64 current_members_hi, uint64 current_epoch, + int32 current_coordinator_node) { ClusterSemanticActivationAckTableV1 image; SemanticActivationAckIngressItem request; @@ -3197,8 +2793,8 @@ semantic_activation_ack_lmon_consume_request_ahead( local_capability_word = cluster_ic_local_capability_word(); request = semantic_activation_ack_local_request_ahead.item; state = semantic_activation_ack_request_ahead_state( - &request, &snapshot, current_members_lo, current_members_hi, - current_epoch, current_coordinator_node, local_capability_word); + &request, &snapshot, current_members_lo, current_members_hi, current_epoch, + current_coordinator_node, local_capability_word); if (state == SEMANTIC_ACTIVATION_ACK_REQUEST_AHEAD_WAIT) return true; if (state != SEMANTIC_ACTIVATION_ACK_REQUEST_AHEAD_READY) { @@ -3213,36 +2809,28 @@ semantic_activation_ack_lmon_consume_request_ahead( || semantic_activation_ack_local_pending_send.pending_members_hi != 0) return true; - if (request.message.stage - == CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_SAMPLE) + if (request.message.stage == CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_SAMPLE) result = semantic_activation_ack_lmon_accept_current_sample_request( - &request, &snapshot, current_members_lo, current_members_hi, - current_epoch, current_coordinator_node, - local_capability_word); - else if (request.message.stage - == CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_BARRIER) + &request, &snapshot, current_members_lo, current_members_hi, current_epoch, + current_coordinator_node, local_capability_word); + else if (request.message.stage == CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_BARRIER) result = semantic_activation_ack_lmon_accept_current_barrier_request( - &request, &snapshot, current_members_lo, current_members_hi, - current_epoch, current_coordinator_node, - local_capability_word); + &request, &snapshot, current_members_lo, current_members_hi, current_epoch, + current_coordinator_node, local_capability_word); else if ((request.message.target_feature_bitmap - & PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1) != 0) + & PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1) + != 0) result = semantic_activation_ack_lmon_accept_current_request_bit22( - &request, &snapshot, current_members_lo, current_members_hi, - current_epoch, current_coordinator_node, - local_capability_word); - else if (request.message.stage - == CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_PREPARED) + &request, &snapshot, current_members_lo, current_members_hi, current_epoch, + current_coordinator_node, local_capability_word); + else if (request.message.stage == CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_PREPARED) result = semantic_activation_ack_lmon_accept_current_prepared_request( - &request, &snapshot, current_members_lo, current_members_hi, - current_epoch, current_coordinator_node, - local_capability_word); + &request, &snapshot, current_members_lo, current_members_hi, current_epoch, + current_coordinator_node, local_capability_word); else - result - = semantic_activation_ack_lmon_accept_current_commit_applied_request( - &request, &snapshot, current_members_lo, - current_members_hi, current_epoch, - current_coordinator_node, local_capability_word); + result = semantic_activation_ack_lmon_accept_current_commit_applied_request( + &request, &snapshot, current_members_lo, current_members_hi, current_epoch, + current_coordinator_node, local_capability_word); if (result != SEMANTIC_ACTIVATION_ACK_CONSUME_APPLIED && result != SEMANTIC_ACTIVATION_ACK_CONSUME_DUPLICATE) { semantic_activation_ack_lmon_invalidate_active(); @@ -3250,17 +2838,15 @@ semantic_activation_ack_lmon_consume_request_ahead( } memset(&semantic_activation_ack_local_request_ahead, 0, sizeof(semantic_activation_ack_local_request_ahead)); - if (!semantic_activation_ack_lmon_apply_stage_ahead( - &request, result, current_members_lo, current_members_hi, - current_epoch, current_coordinator_node)) + if (!semantic_activation_ack_lmon_apply_stage_ahead(&request, result, current_members_lo, + current_members_hi, current_epoch, + current_coordinator_node)) return false; - if (request.message.stage - == CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_SAMPLE + if (request.message.stage == CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_SAMPLE && (result != SEMANTIC_ACTIVATION_ACK_CONSUME_APPLIED || !semantic_activation_ack_table_snapshot(&image) || !semantic_activation_ack_pending_send_begin_positive( - &semantic_activation_ack_local_pending_send, - &request.message, cluster_node_id, + &semantic_activation_ack_local_pending_send, &request.message, cluster_node_id, &image.observed[cluster_node_id]))) { semantic_activation_ack_lmon_invalidate_active(); return false; @@ -3282,8 +2868,7 @@ semantic_activation_ack_lmon_invalidate_active(void) memset(&semantic_activation_ack_local_request_origin, 0, sizeof(semantic_activation_ack_local_request_origin)); if (!semantic_activation_ack_table_snapshot(&image) - || (image.expected_members_lo == 0 - && image.expected_members_hi == 0)) + || (image.expected_members_lo == 0 && image.expected_members_hi == 0)) return; (void)semantic_activation_ack_image_invalidate(&image); } @@ -3293,8 +2878,7 @@ semantic_activation_ack_lmon_send_pending(void) { ClusterSemanticActivationAckTableV1 image; SemanticActivationAdmissionSnapshot snapshot; - SemanticActivationAckPendingSend *pending - = &semantic_activation_ack_local_pending_send; + SemanticActivationAckPendingSend *pending = &semantic_activation_ack_local_pending_send; uint8 payload[CLUSTER_SEMANTIC_ACTIVATION_ACK_WIRE_BYTES]; uint32 required_caps; bool refused; @@ -3302,79 +2886,55 @@ semantic_activation_ack_lmon_send_pending(void) int32 node; if (pending->invalidated - || (pending->pending_members_lo == 0 - && pending->pending_members_hi == 0)) + || (pending->pending_members_lo == 0 && pending->pending_members_hi == 0)) return; - refused = pending->message.result - == CLUSTER_SEMANTIC_ACTIVATION_ACK_RESULT_REFUSED; + refused = pending->message.result == CLUSTER_SEMANTIC_ACTIVATION_ACK_RESULT_REFUSED; invalid = !semantic_activation_ack_round_required_caps( - pending->message.source_feature_bitmap, - pending->message.target_feature_bitmap, - pending->message.rollback_feature_bitmap, &required_caps) - || pending->message.kind - != CLUSTER_SEMANTIC_ACTIVATION_ACK_KIND_ACK - || !cluster_semantic_activation_ack_wire_encode( - &pending->message, payload); + pending->message.source_feature_bitmap, pending->message.target_feature_bitmap, + pending->message.rollback_feature_bitmap, &required_caps) + || pending->message.kind != CLUSTER_SEMANTIC_ACTIVATION_ACK_KIND_ACK + || !cluster_semantic_activation_ack_wire_encode(&pending->message, payload); if (!invalid && refused) { - uint64 coordinator_bit - = UINT64_C(1) << pending->message.coordinator_node; - - invalid = pending->message.stage - != CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_SAMPLE - || pending->message.reason - != CLUSTER_SEMANTIC_ACTIVATION_RF_DEFERRED - || pending->message.coordinator_node != UINT32_C(0) - || pending->message.member_node != (uint32)cluster_node_id - || pending->message.admitted_members_lo != UINT64_C(0x0f) - || pending->message.admitted_members_hi != 0 - || pending->message.source_feature_bitmap != 0 - || pending->message.target_feature_bitmap - != CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1 - || pending->message.rollback_feature_bitmap != 0 - || pending->message.capability_sample_digest != 0 - || pending->pending_members_lo != coordinator_bit - || pending->pending_members_hi != 0 - || pending->refusal_connection_generation == 0 - || !cluster_qvotec_in_quorum() - || pending->message.transition_epoch - != cluster_epoch_get_current() - || (cluster_ic_local_capability_word() & required_caps) - != required_caps - || !semantic_activation_snapshot(&snapshot) - || snapshot.transition_closed - || snapshot.formation_epoch - != pending->message.transition_epoch - || snapshot.active_bits - != pending->message.source_feature_bitmap - || snapshot.record_generation == UINT64_MAX - || snapshot.record_generation + 1 - != pending->message.record_generation - || !cluster_sf_peer_capability_generation_matches( - (int32)pending->message.coordinator_node, required_caps, - pending->refusal_connection_generation); + uint64 coordinator_bit = UINT64_C(1) << pending->message.coordinator_node; + + invalid + = pending->message.stage != CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_SAMPLE + || pending->message.reason != CLUSTER_SEMANTIC_ACTIVATION_RF_DEFERRED + || pending->message.coordinator_node != UINT32_C(0) + || pending->message.member_node != (uint32)cluster_node_id + || pending->message.admitted_members_lo != UINT64_C(0x0f) + || pending->message.admitted_members_hi != 0 + || pending->message.source_feature_bitmap != 0 + || pending->message.target_feature_bitmap != CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1 + || pending->message.rollback_feature_bitmap != 0 + || pending->message.capability_sample_digest != 0 + || pending->pending_members_lo != coordinator_bit || pending->pending_members_hi != 0 + || pending->refusal_connection_generation == 0 || !cluster_qvotec_in_quorum() + || pending->message.transition_epoch != cluster_epoch_get_current() + || (cluster_ic_local_capability_word() & required_caps) != required_caps + || !semantic_activation_snapshot(&snapshot) || snapshot.transition_closed + || snapshot.formation_epoch != pending->message.transition_epoch + || snapshot.active_bits != pending->message.source_feature_bitmap + || snapshot.record_generation == UINT64_MAX + || snapshot.record_generation + 1 != pending->message.record_generation + || !cluster_sf_peer_capability_generation_matches( + (int32)pending->message.coordinator_node, required_caps, + pending->refusal_connection_generation); } else if (!invalid) { - invalid = pending->message.result - != CLUSTER_SEMANTIC_ACTIVATION_ACK_RESULT_OK - || !semantic_activation_ack_table_snapshot(&image) - || (image.expected_members_lo == 0 - && image.expected_members_hi == 0) - || pending->message.stage != image.stage - || pending->message.coordinator_node != image.coordinator_node - || pending->message.round_nonce != image.round_nonce - || pending->message.admitted_members_lo - != image.expected_members_lo - || pending->message.admitted_members_hi - != image.expected_members_hi - || pending->message.transition_epoch != image.transition_epoch - || pending->message.record_generation != image.record_generation - || pending->message.source_feature_bitmap - != image.source_feature_bitmap - || pending->message.target_feature_bitmap - != image.target_feature_bitmap - || pending->message.rollback_feature_bitmap - != image.rollback_feature_bitmap - || pending->message.capability_sample_digest - != image.capability_sample_digest; + invalid = pending->message.result != CLUSTER_SEMANTIC_ACTIVATION_ACK_RESULT_OK + || !semantic_activation_ack_table_snapshot(&image) + || (image.expected_members_lo == 0 && image.expected_members_hi == 0) + || pending->message.stage != image.stage + || pending->message.coordinator_node != image.coordinator_node + || pending->message.round_nonce != image.round_nonce + || pending->message.admitted_members_lo != image.expected_members_lo + || pending->message.admitted_members_hi != image.expected_members_hi + || pending->message.transition_epoch != image.transition_epoch + || pending->message.record_generation != image.record_generation + || pending->message.source_feature_bitmap != image.source_feature_bitmap + || pending->message.target_feature_bitmap != image.target_feature_bitmap + || pending->message.rollback_feature_bitmap != image.rollback_feature_bitmap + || pending->message.capability_sample_digest != image.capability_sample_digest; } if (invalid) { pending->pending_members_lo = 0; @@ -3389,12 +2949,9 @@ semantic_activation_ack_lmon_send_pending(void) ClusterICSendResult send_result; uint32 capability_word; uint32 capability_generation; - bool is_pending - = node < 64 - ? (pending->pending_members_lo - & (UINT64_C(1) << node)) != 0 - : (pending->pending_members_hi - & (UINT64_C(1) << (node - 64))) != 0; + bool is_pending = node < 64 + ? (pending->pending_members_lo & (UINT64_C(1) << node)) != 0 + : (pending->pending_members_hi & (UINT64_C(1) << (node - 64))) != 0; if (!is_pending) continue; @@ -3404,27 +2961,21 @@ semantic_activation_ack_lmon_send_pending(void) && pending->message.stage == CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_OPEN_APPLIED && !semantic_activation_restart_ready_current()) return; - if (!cluster_sf_peer_capability_word_sample( - node, required_caps, - &capability_word, &capability_generation) + if (!cluster_sf_peer_capability_word_sample(node, required_caps, &capability_word, + &capability_generation) || capability_generation == 0 - || (refused - && capability_generation - != pending->refusal_connection_generation)) { + || (refused && capability_generation != pending->refusal_connection_generation)) { pending->pending_members_lo = 0; pending->pending_members_hi = 0; pending->invalidated = true; semantic_activation_ack_lmon_invalidate_active(); return; } - send_result = cluster_ic_send_envelope( - PGRAC_IC_MSG_SEMANTIC_ACTIVATION_ACK_V1, node, - payload, sizeof(payload)); - disposition = semantic_activation_ack_pending_send_note_result( - pending, node, send_result); + send_result = cluster_ic_send_envelope(PGRAC_IC_MSG_SEMANTIC_ACTIVATION_ACK_V1, node, + payload, sizeof(payload)); + disposition = semantic_activation_ack_pending_send_note_result(pending, node, send_result); if (disposition == SEMANTIC_ACTIVATION_ACK_SEND_INVALIDATED) { - cluster_ic_tier1_close_peer( - node, "semantic activation ACK send failed"); + cluster_ic_tier1_close_peer(node, "semantic activation ACK send failed"); semantic_activation_ack_lmon_invalidate_active(); return; } @@ -3446,8 +2997,7 @@ semantic_activation_ack_lmon_send_pending(void) * continue through the existing pending-send retry path. */ static bool semantic_activation_ack_lmon_send_coordinator_observation( - const ClusterSemanticActivationAckTableV1 *image, - SemanticActivationAckRequestOrigin *origin) + const ClusterSemanticActivationAckTableV1 *image, SemanticActivationAckRequestOrigin *origin) { SemanticActivationAckPendingSend pending; ClusterSemanticActivationAckWireV1 request; @@ -3460,18 +3010,16 @@ semantic_activation_ack_lmon_send_coordinator_observation( if (image == NULL || origin == NULL || !origin->active) return false; coordinator_node = (int32)image->coordinator_node; - if (coordinator_node != cluster_node_id - || coordinator_node < 0 || coordinator_node >= 64) + if (coordinator_node != cluster_node_id || coordinator_node < 0 || coordinator_node >= 64) return false; self_bit = UINT64_C(1) << coordinator_node; if ((image->observed_members_lo & self_bit) == 0) return true; self = &image->observed[coordinator_node]; local_capability_word = cluster_ic_local_capability_word(); - if (!semantic_activation_ack_self_tuple( - coordinator_node, local_capability_word, - image->transition_epoch, image->record_generation, - ¤t_self) + if (!semantic_activation_ack_self_tuple(coordinator_node, local_capability_word, + image->transition_epoch, image->record_generation, + ¤t_self) || !semantic_activation_ack_matches(self, ¤t_self)) { semantic_activation_ack_lmon_invalidate_active(); return false; @@ -3498,11 +3046,10 @@ semantic_activation_ack_lmon_send_coordinator_observation( request.rollback_feature_bitmap = image->rollback_feature_bitmap; request.admitted_members_lo = image->expected_members_lo; request.admitted_members_hi = image->expected_members_hi; - request.capability_sample_digest - = image->capability_sample_digest; + request.capability_sample_digest = image->capability_sample_digest; memset(&pending, 0, sizeof(pending)); - if (!semantic_activation_ack_pending_send_begin_positive( - &pending, &request, coordinator_node, self)) { + if (!semantic_activation_ack_pending_send_begin_positive(&pending, &request, + coordinator_node, self)) { semantic_activation_ack_lmon_invalidate_active(); return false; } @@ -3519,8 +3066,7 @@ semantic_activation_ack_lmon_send_coordinator_observation( static bool semantic_activation_ack_lmon_send_origin_requests(void) { - SemanticActivationAckRequestOrigin *origin - = &semantic_activation_ack_local_request_origin; + SemanticActivationAckRequestOrigin *origin = &semantic_activation_ack_local_request_origin; ClusterSemanticActivationAckTableV1 image; uint8 payload[CLUSTER_SEMANTIC_ACTIVATION_ACK_WIRE_BYTES]; uint32 required_caps; @@ -3557,93 +3103,68 @@ semantic_activation_ack_lmon_send_origin_requests(void) uint64 member_bit; int32 node; - if (pending->pending_members_lo == 0 - && pending->pending_members_hi == 0) { + if (pending->pending_members_lo == 0 && pending->pending_members_hi == 0) { for (node = 1; node < 4; node++) { member_bit = UINT64_C(1) << node; if ((origin->unsent_members_lo & member_bit) != 0) break; } if (node == 4) - return semantic_activation_ack_lmon_send_coordinator_observation( - &image, origin); + return semantic_activation_ack_lmon_send_coordinator_observation(&image, origin); memset(pending, 0, sizeof(*pending)); - pending->message.kind - = CLUSTER_SEMANTIC_ACTIVATION_ACK_KIND_REQUEST; + pending->message.kind = CLUSTER_SEMANTIC_ACTIVATION_ACK_KIND_REQUEST; pending->message.stage = image.stage; - pending->message.result - = CLUSTER_SEMANTIC_ACTIVATION_ACK_RESULT_REQUEST; + pending->message.result = CLUSTER_SEMANTIC_ACTIVATION_ACK_RESULT_REQUEST; pending->message.coordinator_node = image.coordinator_node; pending->message.member_node = (uint32)node; pending->message.transition_epoch = image.transition_epoch; pending->message.record_generation = image.record_generation; pending->message.round_nonce = image.round_nonce; - pending->message.source_feature_bitmap - = image.source_feature_bitmap; - pending->message.target_feature_bitmap - = image.target_feature_bitmap; - pending->message.rollback_feature_bitmap - = image.rollback_feature_bitmap; - pending->message.admitted_members_lo - = image.expected_members_lo; - pending->message.admitted_members_hi - = image.expected_members_hi; - pending->message.capability_sample_digest - = image.capability_sample_digest; + pending->message.source_feature_bitmap = image.source_feature_bitmap; + pending->message.target_feature_bitmap = image.target_feature_bitmap; + pending->message.rollback_feature_bitmap = image.rollback_feature_bitmap; + pending->message.admitted_members_lo = image.expected_members_lo; + pending->message.admitted_members_hi = image.expected_members_hi; + pending->message.capability_sample_digest = image.capability_sample_digest; pending->pending_members_lo = member_bit; origin->unsent_members_lo &= ~member_bit; } node = (int32)pending->message.member_node; - if (node <= 0 || node >= 4 - || pending->invalidated) { + if (node <= 0 || node >= 4 || pending->invalidated) { semantic_activation_ack_lmon_invalidate_active(); return false; } member_bit = UINT64_C(1) << node; - if (pending->pending_members_hi != 0 - || pending->pending_members_lo != member_bit - || pending->message.kind - != CLUSTER_SEMANTIC_ACTIVATION_ACK_KIND_REQUEST + if (pending->pending_members_hi != 0 || pending->pending_members_lo != member_bit + || pending->message.kind != CLUSTER_SEMANTIC_ACTIVATION_ACK_KIND_REQUEST || pending->message.stage != image.stage - || pending->message.result - != CLUSTER_SEMANTIC_ACTIVATION_ACK_RESULT_REQUEST + || pending->message.result != CLUSTER_SEMANTIC_ACTIVATION_ACK_RESULT_REQUEST || pending->message.coordinator_node != image.coordinator_node || pending->message.transition_epoch != image.transition_epoch || pending->message.record_generation != image.record_generation || pending->message.round_nonce != image.round_nonce - || pending->message.source_feature_bitmap - != image.source_feature_bitmap - || pending->message.target_feature_bitmap - != image.target_feature_bitmap - || pending->message.rollback_feature_bitmap - != image.rollback_feature_bitmap - || pending->message.admitted_members_lo - != image.expected_members_lo - || pending->message.admitted_members_hi - != image.expected_members_hi - || pending->message.capability_sample_digest - != image.capability_sample_digest - || !cluster_semantic_activation_ack_wire_encode( - &pending->message, payload) - || !cluster_sf_peer_capability_word_sample( - node, required_caps, - &capability_word, &capability_generation) + || pending->message.source_feature_bitmap != image.source_feature_bitmap + || pending->message.target_feature_bitmap != image.target_feature_bitmap + || pending->message.rollback_feature_bitmap != image.rollback_feature_bitmap + || pending->message.admitted_members_lo != image.expected_members_lo + || pending->message.admitted_members_hi != image.expected_members_hi + || pending->message.capability_sample_digest != image.capability_sample_digest + || !cluster_semantic_activation_ack_wire_encode(&pending->message, payload) + || !cluster_sf_peer_capability_word_sample(node, required_caps, &capability_word, + &capability_generation) || capability_generation == 0) { semantic_activation_ack_lmon_invalidate_active(); return false; } - send_result = cluster_ic_send_envelope( - PGRAC_IC_MSG_SEMANTIC_ACTIVATION_ACK_V1, node, - payload, sizeof(payload)); - disposition = semantic_activation_ack_pending_send_note_result( - pending, node, send_result); + send_result = cluster_ic_send_envelope(PGRAC_IC_MSG_SEMANTIC_ACTIVATION_ACK_V1, node, + payload, sizeof(payload)); + disposition = semantic_activation_ack_pending_send_note_result(pending, node, send_result); if (disposition == SEMANTIC_ACTIVATION_ACK_SEND_RETAINED) return true; if (disposition == SEMANTIC_ACTIVATION_ACK_SEND_INVALIDATED) { - cluster_ic_tier1_close_peer( - node, "semantic activation SAMPLE request send failed"); + cluster_ic_tier1_close_peer(node, "semantic activation SAMPLE request send failed"); semantic_activation_ack_lmon_invalidate_active(); return false; } @@ -3655,12 +3176,10 @@ semantic_activation_ack_lmon_send_origin_requests(void) } static bool -semantic_activation_ack_lmon_begin_sample_round( - const SemanticActivationUtilityRequest *request, - const SemanticActivationAdmissionSnapshot *snapshot) +semantic_activation_ack_lmon_begin_sample_round(const SemanticActivationUtilityRequest *request, + const SemanticActivationAdmissionSnapshot *snapshot) { - SemanticActivationAckRequestOrigin *origin - = &semantic_activation_ack_local_request_origin; + SemanticActivationAckRequestOrigin *origin = &semantic_activation_ack_local_request_origin; ClusterSemanticActivationAckTableV1 current; ClusterSemanticActivationAckTableV1 next; SemanticActivationAckTuple self; @@ -3672,59 +3191,46 @@ semantic_activation_ack_lmon_begin_sample_round( int32 current_coordinator_node; int32 node; - if (request == NULL || snapshot == NULL - || request->request_seq == 0 - || request->expected_record_generation == UINT64_MAX - || (snapshot->seq & UINT64_C(1)) != 0 - || snapshot->transition_closed - || snapshot->active_bits != request->source_feature_bitmap - || snapshot->record_generation - != request->expected_record_generation + if (request == NULL || snapshot == NULL || request->request_seq == 0 + || request->expected_record_generation == UINT64_MAX || (snapshot->seq & UINT64_C(1)) != 0 + || snapshot->transition_closed || snapshot->active_bits != request->source_feature_bitmap + || snapshot->record_generation != request->expected_record_generation || snapshot->record_generation == UINT64_MAX || !semantic_activation_ack_round_required_caps( - request->source_feature_bitmap, - request->target_feature_bitmap, + request->source_feature_bitmap, request->target_feature_bitmap, request->rollback_feature_bitmap, &required_caps) - || !semantic_activation_ack_current_authority( - cluster_node_id, ¤t_members_lo, ¤t_members_hi, - ¤t_epoch, ¤t_coordinator_node) + || !semantic_activation_ack_current_authority(cluster_node_id, ¤t_members_lo, + ¤t_members_hi, ¤t_epoch, + ¤t_coordinator_node) || cluster_node_id != 0 || current_coordinator_node != 0 - || current_members_lo != UINT64_C(0x0f) - || current_members_hi != 0 + || current_members_lo != UINT64_C(0x0f) || current_members_hi != 0 || snapshot->formation_epoch != current_epoch) return false; local_capability_word = cluster_ic_local_capability_word(); if ((local_capability_word & required_caps) != required_caps - || !semantic_activation_ack_self_tuple( - cluster_node_id, local_capability_word, current_epoch, - snapshot->record_generation + 1, &self)) + || !semantic_activation_ack_self_tuple(cluster_node_id, local_capability_word, + current_epoch, snapshot->record_generation + 1, + &self)) return false; if (!semantic_activation_ack_table_snapshot(¤t)) return false; - if (current.expected_members_lo != 0 - || current.expected_members_hi != 0) { + if (current.expected_members_lo != 0 || current.expected_members_hi != 0) { if (origin->active) { - if (current.stage - != CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_SAMPLE + if (current.stage != CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_SAMPLE || current.coordinator_node != UINT32_C(0) || current.round_nonce != request->request_seq || current.expected_members_lo != current_members_lo || current.expected_members_hi != current_members_hi || current.transition_epoch != current_epoch - || current.record_generation - != snapshot->record_generation + 1 - || current.source_feature_bitmap - != request->source_feature_bitmap - || current.target_feature_bitmap - != request->target_feature_bitmap - || current.rollback_feature_bitmap - != request->rollback_feature_bitmap + || current.record_generation != snapshot->record_generation + 1 + || current.source_feature_bitmap != request->source_feature_bitmap + || current.target_feature_bitmap != request->target_feature_bitmap + || current.rollback_feature_bitmap != request->rollback_feature_bitmap || current.capability_sample_digest != 0 || (current.observed_members_lo & UINT64_C(1)) == 0 - || !semantic_activation_ack_matches( - ¤t.observed[0], &self)) + || !semantic_activation_ack_matches(¤t.observed[0], &self)) return false; return semantic_activation_ack_lmon_send_origin_requests(); } @@ -3733,20 +3239,16 @@ semantic_activation_ack_lmon_begin_sample_round( * Replace it only when it is the exact current OPEN predecessor of this * request. No partial or stale observation is carried into the new * SAMPLE image. */ - if (current.stage - != CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_OPEN_APPLIED + if (current.stage != CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_OPEN_APPLIED || current.flags - != (CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID - | CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE) + != (CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID + | CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE) || current.record_generation != snapshot->record_generation - || current.target_feature_bitmap - != request->source_feature_bitmap - || current.rollback_feature_bitmap != 0 - || current.capability_sample_digest == 0 + || current.target_feature_bitmap != request->source_feature_bitmap + || current.rollback_feature_bitmap != 0 || current.capability_sample_digest == 0 || !semantic_activation_ack_complete_image_current( - ¤t, current_members_lo, current_members_hi, - current_epoch, current_coordinator_node, - cluster_node_id, local_capability_word)) + ¤t, current_members_lo, current_members_hi, current_epoch, + current_coordinator_node, cluster_node_id, local_capability_word)) return false; } @@ -3754,9 +3256,8 @@ semantic_activation_ack_lmon_begin_sample_round( uint32 capability_word; uint32 capability_generation; - if (!cluster_sf_peer_capability_word_sample( - node, required_caps, - &capability_word, &capability_generation) + if (!cluster_sf_peer_capability_word_sample(node, required_caps, &capability_word, + &capability_generation) || capability_generation == 0) return false; } @@ -3784,15 +3285,13 @@ semantic_activation_ack_lmon_begin_sample_round( } static void -semantic_activation_ack_lmon_revalidate_active( - uint64 current_members_lo, uint64 current_members_hi, - uint64 current_epoch, int32 current_coordinator_node) +semantic_activation_ack_lmon_revalidate_active(uint64 current_members_lo, uint64 current_members_hi, + uint64 current_epoch, int32 current_coordinator_node) { ClusterSemanticActivationAckTableV1 image; if (!semantic_activation_ack_table_snapshot(&image) - || (image.expected_members_lo == 0 - && image.expected_members_hi == 0)) + || (image.expected_members_lo == 0 && image.expected_members_hi == 0)) return; if (image.expected_members_lo != current_members_lo || image.expected_members_hi != current_members_hi @@ -3847,13 +3346,10 @@ semantic_activation_ack_carrier_not_contradicted( } else if (snapshot->record_generation != image->record_generation) return false; - all_observed - = image->observed_members_lo == image->expected_members_lo; + all_observed = image->observed_members_lo == image->expected_members_lo; if (image->flags - != (CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID - | (all_observed - ? CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE - : 0)) + != (CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID + | (all_observed ? CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE : 0)) || (image->stage == CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_SAMPLE && image->capability_sample_digest != 0) || (image->stage != CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_SAMPLE @@ -3870,27 +3366,21 @@ semantic_activation_ack_carrier_not_contradicted( observed_mask = image->observed_members_lo; for (node = 0; node < CLUSTER_MAX_NODES; node++) { - bool expected = semantic_activation_ack_member_present( - image->expected_members_lo, image->expected_members_hi, node); - bool observed = node < 64 - ? (observed_mask & (UINT64_C(1) << node)) != 0 - : false; + bool expected = semantic_activation_ack_member_present(image->expected_members_lo, + image->expected_members_hi, node); + bool observed = node < 64 ? (observed_mask & (UINT64_C(1) << node)) != 0 : false; if (!expected) { - if (!semantic_activation_bytes_are_zero( - (const uint8 *)&image->expected[node], - sizeof(image->expected[node])) - || !semantic_activation_bytes_are_zero( - (const uint8 *)&image->observed[node], - sizeof(image->observed[node]))) + if (!semantic_activation_bytes_are_zero((const uint8 *)&image->expected[node], + sizeof(image->expected[node])) + || !semantic_activation_bytes_are_zero((const uint8 *)&image->observed[node], + sizeof(image->observed[node]))) return false; } else if (observed) { - if (!semantic_activation_ack_matches( - &image->observed[node], &image->expected[node])) + if (!semantic_activation_ack_matches(&image->observed[node], &image->expected[node])) return false; - } else if (!semantic_activation_bytes_are_zero( - (const uint8 *)&image->observed[node], - sizeof(image->observed[node]))) + } else if (!semantic_activation_bytes_are_zero((const uint8 *)&image->observed[node], + sizeof(image->observed[node]))) return false; } @@ -3899,8 +3389,7 @@ semantic_activation_ack_carrier_not_contradicted( * durable generation is the corresponding local proof. */ if (cluster_node_id == (int32)image->coordinator_node && (semantic_activation_lmon_prepare_cas_seq == 0 - || semantic_activation_lmon_prepare_cas_utility_request_seq - != image->round_nonce)) + || semantic_activation_lmon_prepare_cas_utility_request_seq != image->round_nonce)) return false; return true; @@ -3937,28 +3426,25 @@ semantic_activation_ack_lmon_drain(void) return; } - if (semantic_activation_ack_ingress_pending( - &semantic_activation_ack_local_ingress) == 0) { + if (semantic_activation_ack_ingress_pending(&semantic_activation_ack_local_ingress) == 0) { if (SemanticActivationAckTable == NULL) return; - publication_seq = pg_atomic_read_u64( - &SemanticActivationAckTable->publication_seq); + publication_seq = pg_atomic_read_u64(&SemanticActivationAckTable->publication_seq); if ((publication_seq & UINT64_C(1)) == 0 && SemanticActivationAckTable->expected_members_lo == 0 && SemanticActivationAckTable->expected_members_hi == 0) return; } - if (!semantic_activation_ack_current_authority( - cluster_node_id, ¤t_members_lo, ¤t_members_hi, - ¤t_epoch, ¤t_coordinator_node)) { + if (!semantic_activation_ack_current_authority(cluster_node_id, ¤t_members_lo, + ¤t_members_hi, ¤t_epoch, + ¤t_coordinator_node)) { /* A coherent admitted snapshot can be briefly unavailable while QVOTEC * publishes its next observation. Absence alone cannot erase either a * completed OPEN carrier or an exact source-closed in-progress carrier. * Consumers and stage drivers remain fail-closed until current authority * is visible again; observable contradictions still invalidate the whole * round below. */ - if (semantic_activation_ack_ingress_pending( - &semantic_activation_ack_local_ingress) == 0 + if (semantic_activation_ack_ingress_pending(&semantic_activation_ack_local_ingress) == 0 && semantic_activation_ack_local_pending_send.pending_members_lo == 0 && semantic_activation_ack_local_pending_send.pending_members_hi == 0 && !semantic_activation_ack_local_pending_send.invalidated @@ -3967,36 +3453,25 @@ semantic_activation_ack_lmon_drain(void) && !semantic_activation_ack_local_request_ahead.valid && semantic_activation_ack_table_snapshot(&terminal_image) && semantic_activation_snapshot(&terminal_snapshot) - && terminal_image.stage - == CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_OPEN_APPLIED + && terminal_image.stage == CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_OPEN_APPLIED && terminal_image.flags - == (CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID - | CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE) + == (CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID + | CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE) && terminal_image.expected_members_lo != 0 - && terminal_image.observed_members_lo - == terminal_image.expected_members_lo - && terminal_image.observed_members_hi - == terminal_image.expected_members_hi + && terminal_image.observed_members_lo == terminal_image.expected_members_lo + && terminal_image.observed_members_hi == terminal_image.expected_members_hi && terminal_image.rollback_feature_bitmap == 0 && semantic_activation_ack_image_structural(&terminal_image) && semantic_activation_full_ack_table_matches( - terminal_image.observed, - terminal_image.observed_members_lo, - terminal_image.observed_members_hi, - terminal_image.expected, - terminal_image.expected_members_lo, - terminal_image.expected_members_hi) + terminal_image.observed, terminal_image.observed_members_lo, + terminal_image.observed_members_hi, terminal_image.expected, + terminal_image.expected_members_lo, terminal_image.expected_members_hi) && !terminal_snapshot.transition_closed - && terminal_snapshot.active_bits - == terminal_image.target_feature_bitmap - && terminal_snapshot.record_generation - == terminal_image.record_generation - && terminal_snapshot.formation_epoch - == terminal_image.transition_epoch - && cluster_epoch_get_current() - == terminal_snapshot.formation_epoch - && semantic_activation_ack_terminal_identity_not_contradicted( - &terminal_image)) + && terminal_snapshot.active_bits == terminal_image.target_feature_bitmap + && terminal_snapshot.record_generation == terminal_image.record_generation + && terminal_snapshot.formation_epoch == terminal_image.transition_epoch + && cluster_epoch_get_current() == terminal_snapshot.formation_epoch + && semantic_activation_ack_terminal_identity_not_contradicted(&terminal_image)) return; if (semantic_activation_ack_table_snapshot(&closed_image) && semantic_activation_snapshot(&closed_snapshot) @@ -4009,14 +3484,14 @@ semantic_activation_ack_lmon_drain(void) if ((semantic_activation_ack_local_pending_send.pending_members_lo != 0 || semantic_activation_ack_local_pending_send.pending_members_hi != 0) && semantic_activation_ack_local_pending_send.message.result - != CLUSTER_SEMANTIC_ACTIVATION_ACK_RESULT_REFUSED) { + != CLUSTER_SEMANTIC_ACTIVATION_ACK_RESULT_REFUSED) { semantic_activation_ack_local_pending_send.pending_members_lo = 0; semantic_activation_ack_local_pending_send.pending_members_hi = 0; semantic_activation_ack_local_pending_send.invalidated = true; } while (consumed < CLUSTER_SEMANTIC_ACTIVATION_ACK_INGRESS_CAPACITY - && semantic_activation_ack_ingress_poll( - &semantic_activation_ack_local_ingress, &item)) { + && semantic_activation_ack_ingress_poll(&semantic_activation_ack_local_ingress, + &item)) { consumed++; if (!semantic_activation_ack_pending_send_begin_refused( &semantic_activation_ack_local_pending_send, &item, @@ -4026,20 +3501,17 @@ semantic_activation_ack_lmon_drain(void) semantic_activation_ack_lmon_send_pending(); return; } - semantic_activation_ack_lmon_revalidate_active( - current_members_lo, current_members_hi, current_epoch, - current_coordinator_node); - (void) semantic_activation_ack_lmon_consume_request_ahead( - current_members_lo, current_members_hi, current_epoch, - current_coordinator_node); + semantic_activation_ack_lmon_revalidate_active(current_members_lo, current_members_hi, + current_epoch, current_coordinator_node); + (void)semantic_activation_ack_lmon_consume_request_ahead( + current_members_lo, current_members_hi, current_epoch, current_coordinator_node); while (consumed < CLUSTER_SEMANTIC_ACTIVATION_ACK_INGRESS_CAPACITY - && semantic_activation_ack_ingress_poll( - &semantic_activation_ack_local_ingress, &item)) { + && semantic_activation_ack_ingress_poll(&semantic_activation_ack_local_ingress, &item)) { consumed++; - if (!semantic_activation_ack_current_authority( - cluster_node_id, ¤t_members_lo, ¤t_members_hi, - ¤t_epoch, ¤t_coordinator_node)) { + if (!semantic_activation_ack_current_authority(cluster_node_id, ¤t_members_lo, + ¤t_members_hi, ¤t_epoch, + ¤t_coordinator_node)) { semantic_activation_ack_lmon_invalidate_active(); continue; } @@ -4047,110 +3519,74 @@ semantic_activation_ack_lmon_drain(void) continue; if (item.message.kind == CLUSTER_SEMANTIC_ACTIVATION_ACK_KIND_ACK) { SemanticActivationAckConsumeResult apply_result - = semantic_activation_ack_lmon_apply_item( - &item, current_members_lo, current_members_hi, - current_epoch, current_coordinator_node); + = semantic_activation_ack_lmon_apply_item(&item, current_members_lo, + current_members_hi, current_epoch, + current_coordinator_node); if (apply_result == SEMANTIC_ACTIVATION_ACK_CONSUME_STALE) - apply_result - = semantic_activation_ack_lmon_retain_stage_ahead( - &item, current_members_lo, current_members_hi, - current_epoch, current_coordinator_node); - - ereport(LOG, - (errmsg("bit22 cutover (node %d): coordinator applied " - "member ACK stage=%u src=%d result=%d", - cluster_node_id, - (unsigned) item.message.stage, - item.authenticated_source_node_id, - (int) apply_result))); - (void) apply_result; - (void) semantic_activation_ack_lmon_consume_request_ahead( - current_members_lo, current_members_hi, current_epoch, - current_coordinator_node); - } else if (item.message.kind - == CLUSTER_SEMANTIC_ACTIVATION_ACK_KIND_REQUEST) { + apply_result = semantic_activation_ack_lmon_retain_stage_ahead( + &item, current_members_lo, current_members_hi, current_epoch, + current_coordinator_node); + + ereport(LOG, (errmsg("bit22 cutover (node %d): coordinator applied " + "member ACK stage=%u src=%d result=%d", + cluster_node_id, (unsigned)item.message.stage, + item.authenticated_source_node_id, (int)apply_result))); + (void)apply_result; + (void)semantic_activation_ack_lmon_consume_request_ahead( + current_members_lo, current_members_hi, current_epoch, current_coordinator_node); + } else if (item.message.kind == CLUSTER_SEMANTIC_ACTIVATION_ACK_KIND_REQUEST) { SemanticActivationAdmissionSnapshot snapshot; ClusterSemanticActivationAckTableV1 image; SemanticActivationAckConsumeResult result; - uint32 local_capability_word - = cluster_ic_local_capability_word(); + uint32 local_capability_word = cluster_ic_local_capability_word(); if (!semantic_activation_snapshot(&snapshot)) continue; - if (item.message.stage - == CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_SAMPLE) { - result - = semantic_activation_ack_lmon_accept_current_sample_request( - &item, &snapshot, current_members_lo, - current_members_hi, current_epoch, - current_coordinator_node, - local_capability_word); - if (result - == SEMANTIC_ACTIVATION_ACK_CONSUME_REJECTED) { - result - = semantic_activation_ack_lmon_retain_request_ahead( - &item, &snapshot, current_members_lo, - current_members_hi, current_epoch, - current_coordinator_node, - local_capability_word); - if (result - == SEMANTIC_ACTIVATION_ACK_CONSUME_APPLIED - || result - == SEMANTIC_ACTIVATION_ACK_CONSUME_DUPLICATE - || result - == SEMANTIC_ACTIVATION_ACK_CONSUME_INVALIDATED) + if (item.message.stage == CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_SAMPLE) { + result = semantic_activation_ack_lmon_accept_current_sample_request( + &item, &snapshot, current_members_lo, current_members_hi, current_epoch, + current_coordinator_node, local_capability_word); + if (result == SEMANTIC_ACTIVATION_ACK_CONSUME_REJECTED) { + result = semantic_activation_ack_lmon_retain_request_ahead( + &item, &snapshot, current_members_lo, current_members_hi, current_epoch, + current_coordinator_node, local_capability_word); + if (result == SEMANTIC_ACTIVATION_ACK_CONSUME_APPLIED + || result == SEMANTIC_ACTIVATION_ACK_CONSUME_DUPLICATE + || result == SEMANTIC_ACTIVATION_ACK_CONSUME_INVALIDATED) continue; } - } - else if (item.message.stage - == CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_BARRIER) { - bool bit22 - = (item.message.target_feature_bitmap - & PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1) != 0; + } else if (item.message.stage == CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_BARRIER) { + bool bit22 = (item.message.target_feature_bitmap + & PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1) + != 0; if (bit22) - result - = semantic_activation_ack_lmon_accept_current_barrier_request_bit22( - &item, &snapshot, current_members_lo, - current_members_hi, current_epoch, + result = semantic_activation_ack_lmon_accept_current_barrier_request_bit22( + &item, &snapshot, current_members_lo, current_members_hi, current_epoch, current_coordinator_node); else - result - = semantic_activation_ack_lmon_accept_current_barrier_request( - &item, &snapshot, current_members_lo, - current_members_hi, current_epoch, - current_coordinator_node, - local_capability_word); - if (!bit22 - && result - == SEMANTIC_ACTIVATION_ACK_CONSUME_REJECTED) { - result - = semantic_activation_ack_lmon_retain_request_ahead( - &item, &snapshot, current_members_lo, - current_members_hi, current_epoch, - current_coordinator_node, - local_capability_word); - if (result - == SEMANTIC_ACTIVATION_ACK_CONSUME_APPLIED - || result - == SEMANTIC_ACTIVATION_ACK_CONSUME_DUPLICATE - || result - == SEMANTIC_ACTIVATION_ACK_CONSUME_INVALIDATED) + result = semantic_activation_ack_lmon_accept_current_barrier_request( + &item, &snapshot, current_members_lo, current_members_hi, current_epoch, + current_coordinator_node, local_capability_word); + if (!bit22 && result == SEMANTIC_ACTIVATION_ACK_CONSUME_REJECTED) { + result = semantic_activation_ack_lmon_retain_request_ahead( + &item, &snapshot, current_members_lo, current_members_hi, current_epoch, + current_coordinator_node, local_capability_word); + if (result == SEMANTIC_ACTIVATION_ACK_CONSUME_APPLIED + || result == SEMANTIC_ACTIVATION_ACK_CONSUME_DUPLICATE + || result == SEMANTIC_ACTIVATION_ACK_CONSUME_INVALIDATED) continue; } if (!semantic_activation_ack_lmon_apply_stage_ahead( - &item, result, current_members_lo, - current_members_hi, current_epoch, + &item, result, current_members_lo, current_members_hi, current_epoch, current_coordinator_node)) continue; continue; - } else if (item.message.stage - == CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_PREPARED - || item.message.stage - == CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_COMMIT_APPLIED - || item.message.stage - == CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_OPEN_APPLIED) { + } else if (item.message.stage == CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_PREPARED + || item.message.stage == CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_COMMIT_APPLIED + || item.message.stage + == CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_OPEN_APPLIED) { /* RF-ROOT P9 verification (cold-formation): the bit22 * cutover round's later-stage requests use the * round-parameterized accept (member set from the ACK @@ -4159,66 +3595,48 @@ semantic_activation_ack_lmon_drain(void) SemanticActivationAckConsumeResult acc; if ((item.message.target_feature_bitmap - & PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1) != 0) { - acc - = semantic_activation_ack_lmon_accept_current_request_bit22( - &item, &snapshot, current_members_lo, - current_members_hi, current_epoch, - current_coordinator_node, - local_capability_word); - - ereport(LOG, - (errmsg("bit22 cutover (node %d): member accept " - "stage=%u result=%d", - cluster_node_id, - (unsigned) item.message.stage, - (int) acc))); - (void) acc; - } else if (item.message.stage - == CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_PREPARED) - acc - = semantic_activation_ack_lmon_accept_current_prepared_request( - &item, &snapshot, current_members_lo, - current_members_hi, current_epoch, - current_coordinator_node, - local_capability_word); + & PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1) + != 0) { + acc = semantic_activation_ack_lmon_accept_current_request_bit22( + &item, &snapshot, current_members_lo, current_members_hi, current_epoch, + current_coordinator_node, local_capability_word); + + ereport(LOG, (errmsg("bit22 cutover (node %d): member accept " + "stage=%u result=%d", + cluster_node_id, (unsigned)item.message.stage, (int)acc))); + (void)acc; + } else if (item.message.stage == CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_PREPARED) + acc = semantic_activation_ack_lmon_accept_current_prepared_request( + &item, &snapshot, current_members_lo, current_members_hi, current_epoch, + current_coordinator_node, local_capability_word); else - acc - = semantic_activation_ack_lmon_accept_current_commit_applied_request( - &item, &snapshot, current_members_lo, - current_members_hi, current_epoch, - current_coordinator_node, - local_capability_word); - if (acc - == SEMANTIC_ACTIVATION_ACK_CONSUME_REJECTED) { + acc = semantic_activation_ack_lmon_accept_current_commit_applied_request( + &item, &snapshot, current_members_lo, current_members_hi, current_epoch, + current_coordinator_node, local_capability_word); + if (acc == SEMANTIC_ACTIVATION_ACK_CONSUME_REJECTED) { acc = semantic_activation_ack_lmon_retain_request_ahead( - &item, &snapshot, current_members_lo, - current_members_hi, current_epoch, - current_coordinator_node, - local_capability_word); + &item, &snapshot, current_members_lo, current_members_hi, current_epoch, + current_coordinator_node, local_capability_word); if (acc == SEMANTIC_ACTIVATION_ACK_CONSUME_APPLIED - || acc - == SEMANTIC_ACTIVATION_ACK_CONSUME_DUPLICATE - || acc - == SEMANTIC_ACTIVATION_ACK_CONSUME_INVALIDATED) + || acc == SEMANTIC_ACTIVATION_ACK_CONSUME_DUPLICATE + || acc == SEMANTIC_ACTIVATION_ACK_CONSUME_INVALIDATED) continue; } (void)semantic_activation_ack_lmon_apply_stage_ahead( - &item, acc, current_members_lo, current_members_hi, - current_epoch, current_coordinator_node); + &item, acc, current_members_lo, current_members_hi, current_epoch, + current_coordinator_node); continue; } else continue; - if (!semantic_activation_ack_lmon_apply_stage_ahead( - &item, result, current_members_lo, current_members_hi, - current_epoch, current_coordinator_node)) + if (!semantic_activation_ack_lmon_apply_stage_ahead(&item, result, current_members_lo, + current_members_hi, current_epoch, + current_coordinator_node)) continue; if (result != SEMANTIC_ACTIVATION_ACK_CONSUME_APPLIED) continue; if (!semantic_activation_ack_table_snapshot(&image) || !semantic_activation_ack_pending_send_begin_positive( - &semantic_activation_ack_local_pending_send, - &item.message, cluster_node_id, + &semantic_activation_ack_local_pending_send, &item.message, cluster_node_id, &image.observed[cluster_node_id])) semantic_activation_ack_lmon_invalidate_active(); } @@ -4263,14 +3681,13 @@ typedef enum SemanticActivationEffect { } SemanticActivationEffect; static bool semantic_activation_snapshot(SemanticActivationAdmissionSnapshot *snapshot); -static bool semantic_activation_lmon_publish_gate( - const SemanticActivationAdmissionSnapshot *snapshot, uint64 active_bits, - uint64 record_generation, uint64 formation_epoch, - bool transition_closed); +static bool +semantic_activation_lmon_publish_gate(const SemanticActivationAdmissionSnapshot *snapshot, + uint64 active_bits, uint64 record_generation, + uint64 formation_epoch, bool transition_closed); static bool semantic_activation_counter_increment(pg_atomic_uint32 *counter); static bool semantic_activation_ensure_exit_hook(void); -static void semantic_activation_release_debt(ClusterSemanticAdmissionSide side, - int feature_index); +static void semantic_activation_release_debt(ClusterSemanticAdmissionSide side, int feature_index); static uint16 semantic_activation_read_u16_le(const uint8 *bytes) @@ -4492,17 +3909,16 @@ semantic_activation_failure_policy(SemanticActivationState state, return true; } -static bool semantic_activation_ack_tuple_encode( - const SemanticActivationAckTuple *tuple, - uint8 bytes[CLUSTER_SEMANTIC_ACTIVATION_ACK_TUPLE_BYTES]) pg_attribute_unused(); -static bool semantic_activation_ack_sample_digest( - const ClusterSemanticActivationAckTableV1 *image, - uint64 *digest_out) pg_attribute_unused(); +static bool +semantic_activation_ack_tuple_encode(const SemanticActivationAckTuple *tuple, + uint8 bytes[CLUSTER_SEMANTIC_ACTIVATION_ACK_TUPLE_BYTES]) + pg_attribute_unused(); +static bool semantic_activation_ack_sample_digest(const ClusterSemanticActivationAckTableV1 *image, + uint64 *digest_out) pg_attribute_unused(); static bool -semantic_activation_ack_tuple_encode( - const SemanticActivationAckTuple *tuple, - uint8 bytes[CLUSTER_SEMANTIC_ACTIVATION_ACK_TUPLE_BYTES]) +semantic_activation_ack_tuple_encode(const SemanticActivationAckTuple *tuple, + uint8 bytes[CLUSTER_SEMANTIC_ACTIVATION_ACK_TUPLE_BYTES]) { uint8 encoded[CLUSTER_SEMANTIC_ACTIVATION_ACK_TUPLE_BYTES]; @@ -4512,8 +3928,7 @@ semantic_activation_ack_tuple_encode( semantic_activation_write_u32_le(encoded, tuple->node_id); semantic_activation_write_u64_le(encoded + 8, tuple->boot_id); semantic_activation_write_u64_le(encoded + 16, tuple->admitted_incarnation); - semantic_activation_write_u64_le(encoded + 24, - tuple->control_connection_generation); + semantic_activation_write_u64_le(encoded + 24, tuple->control_connection_generation); semantic_activation_write_u32_le(encoded + 32, tuple->capability_word); semantic_activation_write_u64_le(encoded + 40, tuple->capability_generation); semantic_activation_write_u64_le(encoded + 48, tuple->transition_epoch); @@ -4523,9 +3938,8 @@ semantic_activation_ack_tuple_encode( } static bool -semantic_activation_ack_sample_digest( - const ClusterSemanticActivationAckTableV1 *image, - uint64 *digest_out) +semantic_activation_ack_sample_digest(const ClusterSemanticActivationAckTableV1 *image, + uint64 *digest_out) { uint8 input[72 + 4 * CLUSTER_SEMANTIC_ACTIVATION_ACK_TUPLE_BYTES]; uint8 sha256[PG_SHA256_DIGEST_LENGTH]; @@ -4538,59 +3952,43 @@ semantic_activation_ack_sample_digest( if (digest_out == NULL) return false; *digest_out = 0; - if (image == NULL - || image->stage != CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_SAMPLE + if (image == NULL || image->stage != CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_SAMPLE || image->flags - != (CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID - | CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE) - || image->coordinator_node != UINT32_C(0) - || image->round_nonce == 0 - || image->expected_members_lo != UINT64_C(0x0f) - || image->expected_members_hi != 0 - || image->observed_members_lo != UINT64_C(0x0f) - || image->observed_members_hi != 0 - || image->record_generation == 0 - || image->capability_sample_digest != 0 + != (CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID + | CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE) + || image->coordinator_node != UINT32_C(0) || image->round_nonce == 0 + || image->expected_members_lo != UINT64_C(0x0f) || image->expected_members_hi != 0 + || image->observed_members_lo != UINT64_C(0x0f) || image->observed_members_hi != 0 + || image->record_generation == 0 || image->capability_sample_digest != 0 || !semantic_activation_ack_image_structural(image) || !semantic_activation_full_ack_table_matches( - image->observed, image->observed_members_lo, - image->observed_members_hi, image->expected, - image->expected_members_lo, image->expected_members_hi)) + image->observed, image->observed_members_lo, image->observed_members_hi, + image->expected, image->expected_members_lo, image->expected_members_hi)) return false; memset(input, 0, sizeof(input)); - semantic_activation_write_u32_le(input, - CLUSTER_SEMANTIC_ACTIVATION_ACK_WIRE_MAGIC); - semantic_activation_write_u16_le(input + 4, - CLUSTER_SEMANTIC_ACTIVATION_ACK_WIRE_VERSION); - semantic_activation_write_u16_le( - input + 6, CLUSTER_SEMANTIC_ACTIVATION_ACK_TUPLE_BYTES); + semantic_activation_write_u32_le(input, CLUSTER_SEMANTIC_ACTIVATION_ACK_WIRE_MAGIC); + semantic_activation_write_u16_le(input + 4, CLUSTER_SEMANTIC_ACTIVATION_ACK_WIRE_VERSION); + semantic_activation_write_u16_le(input + 6, CLUSTER_SEMANTIC_ACTIVATION_ACK_TUPLE_BYTES); semantic_activation_write_u64_le(input + 8, image->transition_epoch); semantic_activation_write_u64_le(input + 16, image->record_generation); - semantic_activation_write_u64_le(input + 24, - image->expected_members_lo); - semantic_activation_write_u64_le(input + 32, - image->expected_members_hi); - semantic_activation_write_u64_le(input + 40, - image->source_feature_bitmap); - semantic_activation_write_u64_le(input + 48, - image->target_feature_bitmap); - semantic_activation_write_u64_le(input + 56, - image->rollback_feature_bitmap); + semantic_activation_write_u64_le(input + 24, image->expected_members_lo); + semantic_activation_write_u64_le(input + 32, image->expected_members_hi); + semantic_activation_write_u64_le(input + 40, image->source_feature_bitmap); + semantic_activation_write_u64_le(input + 48, image->target_feature_bitmap); + semantic_activation_write_u64_le(input + 56, image->rollback_feature_bitmap); semantic_activation_write_u32_le(input + 64, UINT32_C(4)); for (node = 0; node < 4; node++) { if (!semantic_activation_ack_tuple_encode( &image->expected[node], - input + 72 - + node * CLUSTER_SEMANTIC_ACTIVATION_ACK_TUPLE_BYTES)) + input + 72 + node * CLUSTER_SEMANTIC_ACTIVATION_ACK_TUPLE_BYTES)) return false; } ctx = pg_cryptohash_create(PG_SHA256); if (ctx == NULL) return false; - if (pg_cryptohash_init(ctx) < 0 - || pg_cryptohash_update(ctx, input, sizeof(input)) < 0 + if (pg_cryptohash_init(ctx) < 0 || pg_cryptohash_update(ctx, input, sizeof(input)) < 0 || pg_cryptohash_final(ctx, sha256, sizeof(sha256)) < 0) goto done; for (i = 0; i < 8; i++) @@ -4616,50 +4014,42 @@ semantic_activation_ack_matches(const SemanticActivationAckTuple *observed, && observed->capability_word == expected->capability_word && observed->capability_generation == expected->capability_generation && observed->transition_epoch == expected->transition_epoch - && observed->record_generation == expected->record_generation; + && observed->record_generation == expected->record_generation; } /* The ACK bitmap is part of the proof, not a cache hint: no missing or extra * node may be ignored, and every member must match its complete current tuple. */ static bool semantic_activation_full_ack_table_matches( - const SemanticActivationAckTuple observed[CLUSTER_MAX_NODES], - uint64 observed_members_lo, uint64 observed_members_hi, - const SemanticActivationAckTuple expected[CLUSTER_MAX_NODES], + const SemanticActivationAckTuple observed[CLUSTER_MAX_NODES], uint64 observed_members_lo, + uint64 observed_members_hi, const SemanticActivationAckTuple expected[CLUSTER_MAX_NODES], uint64 expected_members_lo, uint64 expected_members_hi) pg_attribute_unused(); static bool semantic_activation_full_ack_table_matches( - const SemanticActivationAckTuple observed[CLUSTER_MAX_NODES], - uint64 observed_members_lo, uint64 observed_members_hi, - const SemanticActivationAckTuple expected[CLUSTER_MAX_NODES], + const SemanticActivationAckTuple observed[CLUSTER_MAX_NODES], uint64 observed_members_lo, + uint64 observed_members_hi, const SemanticActivationAckTuple expected[CLUSTER_MAX_NODES], uint64 expected_members_lo, uint64 expected_members_hi) { int node; if (observed == NULL || expected == NULL || (expected_members_lo == 0 && expected_members_hi == 0) - || observed_members_lo != expected_members_lo - || observed_members_hi != expected_members_hi) + || observed_members_lo != expected_members_lo || observed_members_hi != expected_members_hi) return false; for (node = 0; node < CLUSTER_MAX_NODES; node++) { - bool member = node < 64 - ? (expected_members_lo & (UINT64_C(1) << node)) != 0 - : (expected_members_hi & (UINT64_C(1) << (node - 64))) != 0; + bool member = node < 64 ? (expected_members_lo & (UINT64_C(1) << node)) != 0 + : (expected_members_hi & (UINT64_C(1) << (node - 64))) != 0; if (!member) continue; - if (expected[node].node_id != (uint32)node - || expected[node].boot_id == 0 + if (expected[node].node_id != (uint32)node || expected[node].boot_id == 0 || expected[node].admitted_incarnation == 0 || expected[node].control_connection_generation == 0 - || (expected[node].capability_word - & CLUSTER_SEMANTIC_REPLACEMENT_REQUIRED_CAPS) + || (expected[node].capability_word & CLUSTER_SEMANTIC_REPLACEMENT_REQUIRED_CAPS) != CLUSTER_SEMANTIC_REPLACEMENT_REQUIRED_CAPS - || expected[node].capability_generation == 0 - || expected[node].record_generation == 0 - || !semantic_activation_ack_matches(&observed[node], - &expected[node])) + || expected[node].capability_generation == 0 || expected[node].record_generation == 0 + || !semantic_activation_ack_matches(&observed[node], &expected[node])) return false; } return true; @@ -4829,8 +4219,7 @@ semantic_activation_ack_expected_image_check(const ClusterSemanticActivationAckT | CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE; candidate.observed_members_lo = candidate.expected_members_lo; candidate.observed_members_hi = candidate.expected_members_hi; - memcpy(candidate.observed, candidate.expected, - sizeof(candidate.observed)); + memcpy(candidate.observed, candidate.expected, sizeof(candidate.observed)); return semantic_activation_ack_complete_image_check( &candidate, current_members_lo, current_members_hi, current_epoch, current_coordinator_node, local_node_id, local_capability_word); @@ -4849,119 +4238,88 @@ semantic_activation_ack_expected_image_current(const ClusterSemanticActivationAc } static bool -semantic_activation_ack_lmon_prepare_cas_active( - const SemanticActivationUtilityRequest *request, - const SemanticActivationAdmissionSnapshot *snapshot) +semantic_activation_ack_lmon_prepare_cas_active(const SemanticActivationUtilityRequest *request, + const SemanticActivationAdmissionSnapshot *snapshot) { ClusterSemanticActivationRecord desired; uint64 request_seq; uint64 completion_seq; - if (request == NULL || snapshot == NULL - || SemanticActivationShmem == NULL + if (request == NULL || snapshot == NULL || SemanticActivationShmem == NULL || request->expected_record_generation == UINT64_MAX || semantic_activation_lmon_prepare_cas_seq == 0 - || semantic_activation_lmon_prepare_cas_utility_request_seq - != request->request_seq) + || semantic_activation_lmon_prepare_cas_utility_request_seq != request->request_seq) return false; - request_seq = pg_atomic_read_u64( - &SemanticActivationShmem->record_cas_request_seq); - completion_seq = pg_atomic_read_u64( - &SemanticActivationShmem->record_cas_completion_seq); + request_seq = pg_atomic_read_u64(&SemanticActivationShmem->record_cas_request_seq); + completion_seq = pg_atomic_read_u64(&SemanticActivationShmem->record_cas_completion_seq); if (request_seq != semantic_activation_lmon_prepare_cas_seq || (completion_seq != request_seq - && (completion_seq == UINT64_MAX - || completion_seq + 1 != request_seq))) + && (completion_seq == UINT64_MAX || completion_seq + 1 != request_seq))) return false; pg_read_barrier(); - if (pg_atomic_read_u32( - &SemanticActivationShmem->record_cas_request_kind) + if (pg_atomic_read_u32(&SemanticActivationShmem->record_cas_request_kind) != CLUSTER_SEMANTIC_AUTHORITY_REQUEST_RECORD_CAS || SemanticActivationShmem->record_cas_expected_generation - != request->expected_record_generation + != request->expected_record_generation || SemanticActivationShmem->record_cas_expected_source_feature_bitmap - != request->source_feature_bitmap + != request->source_feature_bitmap || !cluster_semantic_activation_record_decode( - SemanticActivationShmem->record_cas_desired_bytes, - &desired, NULL) + SemanticActivationShmem->record_cas_desired_bytes, &desired, NULL) || desired.phase != CLUSTER_SEMANTIC_PHASE_PREPARE - || desired.record_generation - != request->expected_record_generation + 1 + || desired.record_generation != request->expected_record_generation + 1 || desired.transition_epoch != snapshot->formation_epoch - || desired.source_feature_bitmap - != request->source_feature_bitmap - || desired.target_feature_bitmap - != request->target_feature_bitmap - || desired.rollback_feature_bitmap - != request->rollback_feature_bitmap - || desired.admitted_members_lo != UINT64_C(0x0f) - || desired.admitted_members_hi != 0 - || desired.capability_sample_digest == 0 - || desired.coordinator_node != UINT32_C(0) - || desired.coordinator_incarnation - != cluster_qvotec_get_self_incarnation()) + || desired.source_feature_bitmap != request->source_feature_bitmap + || desired.target_feature_bitmap != request->target_feature_bitmap + || desired.rollback_feature_bitmap != request->rollback_feature_bitmap + || desired.admitted_members_lo != UINT64_C(0x0f) || desired.admitted_members_hi != 0 + || desired.capability_sample_digest == 0 || desired.coordinator_node != UINT32_C(0) + || desired.coordinator_incarnation != cluster_qvotec_get_self_incarnation()) return false; return true; } static bool -semantic_activation_ack_lmon_commit_cas_active( - const SemanticActivationUtilityRequest *request, - const SemanticActivationAdmissionSnapshot *snapshot) +semantic_activation_ack_lmon_commit_cas_active(const SemanticActivationUtilityRequest *request, + const SemanticActivationAdmissionSnapshot *snapshot) { ClusterSemanticActivationRecord desired; uint64 request_seq; uint64 completion_seq; - if (request == NULL || snapshot == NULL - || SemanticActivationShmem == NULL + if (request == NULL || snapshot == NULL || SemanticActivationShmem == NULL || request->expected_record_generation > UINT64_MAX - 2 || semantic_activation_lmon_commit_cas_seq == 0 - || semantic_activation_lmon_commit_cas_utility_request_seq - != request->request_seq) + || semantic_activation_lmon_commit_cas_utility_request_seq != request->request_seq) return false; - request_seq = pg_atomic_read_u64( - &SemanticActivationShmem->record_cas_request_seq); - completion_seq = pg_atomic_read_u64( - &SemanticActivationShmem->record_cas_completion_seq); + request_seq = pg_atomic_read_u64(&SemanticActivationShmem->record_cas_request_seq); + completion_seq = pg_atomic_read_u64(&SemanticActivationShmem->record_cas_completion_seq); if (request_seq != semantic_activation_lmon_commit_cas_seq || (completion_seq != request_seq - && (completion_seq == UINT64_MAX - || completion_seq + 1 != request_seq))) + && (completion_seq == UINT64_MAX || completion_seq + 1 != request_seq))) return false; pg_read_barrier(); - if (pg_atomic_read_u32( - &SemanticActivationShmem->record_cas_request_kind) + if (pg_atomic_read_u32(&SemanticActivationShmem->record_cas_request_kind) != CLUSTER_SEMANTIC_AUTHORITY_REQUEST_RECORD_CAS || SemanticActivationShmem->record_cas_expected_generation - != request->expected_record_generation + 1 + != request->expected_record_generation + 1 || SemanticActivationShmem->record_cas_expected_source_feature_bitmap - != request->source_feature_bitmap + != request->source_feature_bitmap || !cluster_semantic_activation_record_decode( - SemanticActivationShmem->record_cas_desired_bytes, - &desired, NULL) + SemanticActivationShmem->record_cas_desired_bytes, &desired, NULL) || desired.phase != CLUSTER_SEMANTIC_PHASE_COMMIT - || desired.record_generation - != request->expected_record_generation + 2 - || desired.source_feature_bitmap - != request->source_feature_bitmap - || desired.target_feature_bitmap - != request->target_feature_bitmap - || desired.rollback_feature_bitmap - != request->rollback_feature_bitmap - || desired.admitted_members_lo != UINT64_C(0x0f) - || desired.admitted_members_hi != 0 - || desired.capability_sample_digest == 0 - || desired.coordinator_node != UINT32_C(0) - || desired.coordinator_incarnation - != cluster_qvotec_get_self_incarnation()) + || desired.record_generation != request->expected_record_generation + 2 + || desired.source_feature_bitmap != request->source_feature_bitmap + || desired.target_feature_bitmap != request->target_feature_bitmap + || desired.rollback_feature_bitmap != request->rollback_feature_bitmap + || desired.admitted_members_lo != UINT64_C(0x0f) || desired.admitted_members_hi != 0 + || desired.capability_sample_digest == 0 || desired.coordinator_node != UINT32_C(0) + || desired.coordinator_incarnation != cluster_qvotec_get_self_incarnation()) return false; return true; } static bool -semantic_activation_ack_lmon_open_cas_active( - const SemanticActivationUtilityRequest *request) +semantic_activation_ack_lmon_open_cas_active(const SemanticActivationUtilityRequest *request) { ClusterSemanticActivationRecord desired; uint64 request_seq; @@ -4970,55 +4328,39 @@ semantic_activation_ack_lmon_open_cas_active( if (request == NULL || SemanticActivationShmem == NULL || request->expected_record_generation > UINT64_MAX - 3 || semantic_activation_lmon_open_cas_seq == 0 - || semantic_activation_lmon_open_cas_utility_request_seq - != request->request_seq) + || semantic_activation_lmon_open_cas_utility_request_seq != request->request_seq) return false; - request_seq = pg_atomic_read_u64( - &SemanticActivationShmem->record_cas_request_seq); - completion_seq = pg_atomic_read_u64( - &SemanticActivationShmem->record_cas_completion_seq); + request_seq = pg_atomic_read_u64(&SemanticActivationShmem->record_cas_request_seq); + completion_seq = pg_atomic_read_u64(&SemanticActivationShmem->record_cas_completion_seq); if (request_seq != semantic_activation_lmon_open_cas_seq || (completion_seq != request_seq - && (completion_seq == UINT64_MAX - || completion_seq + 1 != request_seq))) + && (completion_seq == UINT64_MAX || completion_seq + 1 != request_seq))) return false; pg_read_barrier(); - if (pg_atomic_read_u32( - &SemanticActivationShmem->record_cas_request_kind) + if (pg_atomic_read_u32(&SemanticActivationShmem->record_cas_request_kind) != CLUSTER_SEMANTIC_AUTHORITY_REQUEST_RECORD_CAS || SemanticActivationShmem->record_cas_expected_generation - != request->expected_record_generation + 2 - || SemanticActivationShmem - ->record_cas_expected_source_feature_bitmap - != request->source_feature_bitmap + != request->expected_record_generation + 2 + || SemanticActivationShmem->record_cas_expected_source_feature_bitmap + != request->source_feature_bitmap || !cluster_semantic_activation_record_decode( - SemanticActivationShmem->record_cas_desired_bytes, - &desired, NULL) + SemanticActivationShmem->record_cas_desired_bytes, &desired, NULL) || desired.phase != CLUSTER_SEMANTIC_PHASE_OPEN - || desired.record_generation - != request->expected_record_generation + 3 - || desired.source_feature_bitmap - != request->source_feature_bitmap - || desired.target_feature_bitmap - != request->target_feature_bitmap - || desired.rollback_feature_bitmap - != request->rollback_feature_bitmap - || desired.admitted_members_lo != UINT64_C(0x0f) - || desired.admitted_members_hi != 0 - || desired.capability_sample_digest == 0 - || desired.coordinator_node != UINT32_C(0) - || desired.coordinator_incarnation - != cluster_qvotec_get_self_incarnation()) + || desired.record_generation != request->expected_record_generation + 3 + || desired.source_feature_bitmap != request->source_feature_bitmap + || desired.target_feature_bitmap != request->target_feature_bitmap + || desired.rollback_feature_bitmap != request->rollback_feature_bitmap + || desired.admitted_members_lo != UINT64_C(0x0f) || desired.admitted_members_hi != 0 + || desired.capability_sample_digest == 0 || desired.coordinator_node != UINT32_C(0) + || desired.coordinator_incarnation != cluster_qvotec_get_self_incarnation()) return false; return true; } static bool -semantic_activation_ack_lmon_install_commit( - const SemanticActivationUtilityRequest *request) +semantic_activation_ack_lmon_install_commit(const SemanticActivationUtilityRequest *request) { - SemanticActivationAckRequestOrigin *origin - = &semantic_activation_ack_local_request_origin; + SemanticActivationAckRequestOrigin *origin = &semantic_activation_ack_local_request_origin; ClusterSemanticActivationAckTableV1 before; ClusterSemanticActivationAckTableV1 after; ClusterSemanticActivationAckTableV1 next; @@ -5042,15 +4384,13 @@ semantic_activation_ack_lmon_install_commit( memset(&after, 0, sizeof(after)); memset(¤t_snapshot, 0, sizeof(current_snapshot)); if (request == NULL || !semantic_activation_snapshot(&snapshot) - || !semantic_activation_ack_lmon_commit_cas_active( - request, &snapshot) + || !semantic_activation_ack_lmon_commit_cas_active(request, &snapshot) || !cluster_semantic_activation_record_decode( - SemanticActivationShmem->record_cas_desired_bytes, - &desired, NULL)) + SemanticActivationShmem->record_cas_desired_bytes, &desired, NULL)) return false; - if (!semantic_activation_ack_current_authority( - cluster_node_id, ¤t_members_lo, ¤t_members_hi, - ¤t_epoch, ¤t_coordinator_node) + if (!semantic_activation_ack_current_authority(cluster_node_id, ¤t_members_lo, + ¤t_members_hi, ¤t_epoch, + ¤t_coordinator_node) || cluster_node_id != 0 || current_coordinator_node != 0 || current_members_lo != desired.admitted_members_lo || current_members_hi != desired.admitted_members_hi @@ -5064,123 +4404,90 @@ semantic_activation_ack_lmon_install_commit( || before.transition_epoch != desired.transition_epoch || before.source_feature_bitmap != desired.source_feature_bitmap || before.target_feature_bitmap != desired.target_feature_bitmap - || before.rollback_feature_bitmap - != desired.rollback_feature_bitmap - || before.capability_sample_digest - != desired.capability_sample_digest) + || before.rollback_feature_bitmap != desired.rollback_feature_bitmap + || before.capability_sample_digest != desired.capability_sample_digest) return false; local_capability_word = cluster_ic_local_capability_word(); - if ((desired.target_feature_bitmap - & PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1) == 0 + if ((desired.target_feature_bitmap & PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1) == 0 && (!semantic_activation_round_descriptor( - desired.source_feature_bitmap, - desired.target_feature_bitmap, - desired.rollback_feature_bitmap, &round_descriptor, - &required_caps) + desired.source_feature_bitmap, desired.target_feature_bitmap, + desired.rollback_feature_bitmap, &round_descriptor, &required_caps) || (local_capability_word & required_caps) != required_caps)) return false; - if (snapshot.transition_closed - && snapshot.active_bits == desired.source_feature_bitmap + if (snapshot.transition_closed && snapshot.active_bits == desired.source_feature_bitmap && snapshot.record_generation == desired.record_generation && snapshot.formation_epoch == desired.transition_epoch) { - if (before.stage - != CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_COMMIT_APPLIED - || before.record_generation != desired.record_generation - || !origin->active + if (before.stage != CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_COMMIT_APPLIED + || before.record_generation != desired.record_generation || !origin->active || !semantic_activation_ack_expected_image_current( - &before, current_members_lo, current_members_hi, - current_epoch, current_coordinator_node, - cluster_node_id, local_capability_word)) + &before, current_members_lo, current_members_hi, current_epoch, + current_coordinator_node, cluster_node_id, local_capability_word)) return false; if (round_descriptor != NULL) { - if (!semantic_activation_ack_member_prepared_image_current( - &before, NULL)) + if (!semantic_activation_ack_member_prepared_image_current(&before, NULL)) return false; self_bit = UINT64_C(1) << cluster_node_id; if ((before.observed_members_lo & self_bit) == 0) { if (round_descriptor->feature_bit == CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1) return false; - result = round_descriptor->apply_target_closed( - desired.record_generation); - return semantic_activation_ack_lmon_finish_member_prepared( - &before, result); + result = round_descriptor->apply_target_closed(desired.record_generation); + return semantic_activation_ack_lmon_finish_member_prepared(&before, result); } - if ((before.flags - & CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE) != 0) { + if ((before.flags & CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE) != 0) { open_record = desired; open_record.phase = CLUSTER_SEMANTIC_PHASE_OPEN; open_record.record_generation++; - if (!cluster_semantic_activation_record_encode( - &open_record, desired_bytes) + if (!cluster_semantic_activation_record_encode(&open_record, desired_bytes) || !semantic_activation_snapshot(¤t_snapshot) || current_snapshot.seq != snapshot.seq || current_snapshot.active_bits != snapshot.active_bits - || current_snapshot.record_generation - != snapshot.record_generation - || current_snapshot.formation_epoch - != snapshot.formation_epoch - || current_snapshot.transition_closed - != snapshot.transition_closed + || current_snapshot.record_generation != snapshot.record_generation + || current_snapshot.formation_epoch != snapshot.formation_epoch + || current_snapshot.transition_closed != snapshot.transition_closed || !semantic_activation_ack_current_authority( - cluster_node_id, ¤t_members_lo, - ¤t_members_hi, ¤t_epoch, + cluster_node_id, ¤t_members_lo, ¤t_members_hi, ¤t_epoch, ¤t_coordinator_node) - || current_members_lo - != desired.admitted_members_lo - || current_members_hi - != desired.admitted_members_hi + || current_members_lo != desired.admitted_members_lo + || current_members_hi != desired.admitted_members_hi || current_epoch != desired.transition_epoch - || current_coordinator_node - != (int32)desired.coordinator_node - || cluster_ic_local_capability_word() - != local_capability_word - || cluster_qvotec_get_self_incarnation() - != desired.coordinator_incarnation + || current_coordinator_node != (int32)desired.coordinator_node + || cluster_ic_local_capability_word() != local_capability_word + || cluster_qvotec_get_self_incarnation() != desired.coordinator_incarnation || !semantic_activation_ack_table_snapshot(&after) || memcmp(&before, &after, sizeof(before)) != 0 || !semantic_activation_ack_complete_image_current( - &after, current_members_lo, - current_members_hi, current_epoch, - current_coordinator_node, cluster_node_id, - local_capability_word)) + &after, current_members_lo, current_members_hi, current_epoch, + current_coordinator_node, cluster_node_id, local_capability_word)) return false; - if (!semantic_activation_record_cas_mailbox_submit( - desired.record_generation, - desired.source_feature_bitmap, desired_bytes, - &cas_seq)) + if (!semantic_activation_record_cas_mailbox_submit(desired.record_generation, + desired.source_feature_bitmap, + desired_bytes, &cas_seq)) return false; semantic_activation_lmon_open_cas_seq = cas_seq; - semantic_activation_lmon_open_cas_utility_request_seq - = request->request_seq; + semantic_activation_lmon_open_cas_utility_request_seq = request->request_seq; return true; } - } else if (before.flags - != CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID - || before.observed_members_lo != 0 - || before.observed_members_hi != 0 - || !semantic_activation_bytes_are_zero( - (const uint8 *)before.observed, - sizeof(before.observed))) + } else if (before.flags != CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID + || before.observed_members_lo != 0 || before.observed_members_hi != 0 + || !semantic_activation_bytes_are_zero((const uint8 *)before.observed, + sizeof(before.observed))) return false; return semantic_activation_ack_lmon_send_origin_requests(); } - if (!snapshot.transition_closed - || snapshot.active_bits != desired.source_feature_bitmap + if (!snapshot.transition_closed || snapshot.active_bits != desired.source_feature_bitmap || snapshot.record_generation + 1 != desired.record_generation || snapshot.formation_epoch != desired.transition_epoch - || before.stage - != CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_PREPARED + || before.stage != CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_PREPARED || before.flags - != (CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID - | CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE) + != (CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID + | CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE) || before.record_generation != snapshot.record_generation || !semantic_activation_ack_complete_image_current( - &before, current_members_lo, current_members_hi, - current_epoch, current_coordinator_node, cluster_node_id, - local_capability_word)) + &before, current_members_lo, current_members_hi, current_epoch, + current_coordinator_node, cluster_node_id, local_capability_word)) return false; /* RF-ROOT P7 (contract, step ②): the bit22 cutover round branches off * here — the PREPARED-stage all-member CLOSED-ACK (W6 clause 3) is @@ -5195,78 +4502,66 @@ semantic_activation_ack_lmon_install_commit( * the majority COMMIT(P+1) record (durable) before advancing — the * root is activated only after COMMIT durability, then the * COMMIT_APPLIED stage verifies the ACTIVE root member-side. */ - if ((desired.target_feature_bitmap - & PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1) != 0) { + if ((desired.target_feature_bitmap & PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1) + != 0) { if (result != CLUSTER_SEMANTIC_ACTIVATION_OK) return false; return semantic_activation_ack_lmon_bit22_commit_applied_begin( - &before, current_members_lo, current_members_hi, - current_epoch, current_coordinator_node, - local_capability_word); + &before, current_members_lo, current_members_hi, current_epoch, + current_coordinator_node, local_capability_word); } if (result != CLUSTER_SEMANTIC_ACTIVATION_OK) return false; - if (!semantic_activation_snapshot(¤t_snapshot) - || current_snapshot.seq != snapshot.seq + if (!semantic_activation_snapshot(¤t_snapshot) || current_snapshot.seq != snapshot.seq || current_snapshot.active_bits != snapshot.active_bits || current_snapshot.record_generation != snapshot.record_generation || current_snapshot.formation_epoch != snapshot.formation_epoch || current_snapshot.transition_closed != snapshot.transition_closed) return false; - if (!semantic_activation_ack_current_authority( - cluster_node_id, ¤t_members_lo, ¤t_members_hi, - ¤t_epoch, ¤t_coordinator_node) + if (!semantic_activation_ack_current_authority(cluster_node_id, ¤t_members_lo, + ¤t_members_hi, ¤t_epoch, + ¤t_coordinator_node) || current_members_lo != desired.admitted_members_lo || current_members_hi != desired.admitted_members_hi || current_epoch != desired.transition_epoch || current_coordinator_node != (int32)desired.coordinator_node || cluster_ic_local_capability_word() != local_capability_word - || cluster_qvotec_get_self_incarnation() - != desired.coordinator_incarnation) + || cluster_qvotec_get_self_incarnation() != desired.coordinator_incarnation) return false; if (!semantic_activation_ack_table_snapshot(&after) || memcmp(&before, &after, sizeof(before)) != 0 || !semantic_activation_ack_complete_image_current( - &after, current_members_lo, current_members_hi, - current_epoch, current_coordinator_node, cluster_node_id, - local_capability_word)) + &after, current_members_lo, current_members_hi, current_epoch, current_coordinator_node, + cluster_node_id, local_capability_word)) return false; if (round_descriptor != NULL - && round_descriptor->feature_bit - == CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1) { - result = round_descriptor->apply_target_closed( - request->expected_record_generation + 1); + && round_descriptor->feature_bit == CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1) { + result = round_descriptor->apply_target_closed(request->expected_record_generation + 1); if (result != CLUSTER_SEMANTIC_ACTIVATION_OK || !semantic_activation_snapshot(¤t_snapshot) || current_snapshot.seq != snapshot.seq || current_snapshot.active_bits != snapshot.active_bits - || current_snapshot.record_generation - != snapshot.record_generation - || current_snapshot.formation_epoch - != snapshot.formation_epoch - || current_snapshot.transition_closed - != snapshot.transition_closed - || !semantic_activation_ack_current_authority( - cluster_node_id, ¤t_members_lo, ¤t_members_hi, - ¤t_epoch, ¤t_coordinator_node) + || current_snapshot.record_generation != snapshot.record_generation + || current_snapshot.formation_epoch != snapshot.formation_epoch + || current_snapshot.transition_closed != snapshot.transition_closed + || !semantic_activation_ack_current_authority(cluster_node_id, ¤t_members_lo, + ¤t_members_hi, ¤t_epoch, + ¤t_coordinator_node) || current_members_lo != desired.admitted_members_lo || current_members_hi != desired.admitted_members_hi || current_epoch != desired.transition_epoch - || current_coordinator_node - != (int32)desired.coordinator_node - || cluster_ic_local_capability_word() - != local_capability_word + || current_coordinator_node != (int32)desired.coordinator_node + || cluster_ic_local_capability_word() != local_capability_word || !semantic_activation_ack_table_snapshot(&after) || memcmp(&before, &after, sizeof(before)) != 0 || !semantic_activation_ack_complete_image_current( - &after, current_members_lo, current_members_hi, - current_epoch, current_coordinator_node, - cluster_node_id, local_capability_word)) + &after, current_members_lo, current_members_hi, current_epoch, + current_coordinator_node, cluster_node_id, local_capability_word)) return false; } - if (!semantic_activation_lmon_publish_gate( - ¤t_snapshot, desired.source_feature_bitmap, - desired.record_generation, desired.transition_epoch, true)) + if (!semantic_activation_lmon_publish_gate(¤t_snapshot, desired.source_feature_bitmap, + desired.record_generation, desired.transition_epoch, + true)) return false; next = after; @@ -5279,20 +4574,17 @@ semantic_activation_ack_lmon_install_commit( for (node = 0; node < 4; node++) next.expected[node].record_generation = desired.record_generation; if (round_descriptor != NULL - && round_descriptor->feature_bit - == CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1) { + && round_descriptor->feature_bit == CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1) { next.observed_members_lo = UINT64_C(1); next.observed[0] = next.expected[0]; } - if (!semantic_activation_snapshot(¤t_snapshot) - || !current_snapshot.transition_closed + if (!semantic_activation_snapshot(¤t_snapshot) || !current_snapshot.transition_closed || current_snapshot.active_bits != desired.source_feature_bitmap || current_snapshot.record_generation != desired.record_generation || current_snapshot.formation_epoch != desired.transition_epoch || !semantic_activation_ack_expected_image_current( - &next, current_members_lo, current_members_hi, - current_epoch, current_coordinator_node, cluster_node_id, - local_capability_word) + &next, current_members_lo, current_members_hi, current_epoch, current_coordinator_node, + cluster_node_id, local_capability_word) || !semantic_activation_ack_table_publish(&next)) return false; @@ -5300,23 +4592,18 @@ semantic_activation_ack_lmon_install_commit( origin->unsent_members_lo = UINT64_C(0x0e); origin->active = true; if (round_descriptor != NULL - && round_descriptor->feature_bit - == CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1) { - result = round_descriptor->apply_target_closed( - desired.record_generation); + && round_descriptor->feature_bit == CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1) { + result = round_descriptor->apply_target_closed(desired.record_generation); if (result == CLUSTER_SEMANTIC_ACTIVATION_OK) - return semantic_activation_ack_lmon_finish_member_prepared( - &next, result); + return semantic_activation_ack_lmon_finish_member_prepared(&next, result); } return semantic_activation_ack_lmon_send_origin_requests(); } static bool -semantic_activation_ack_lmon_install_open( - const SemanticActivationUtilityRequest *request) +semantic_activation_ack_lmon_install_open(const SemanticActivationUtilityRequest *request) { - SemanticActivationAckRequestOrigin *origin - = &semantic_activation_ack_local_request_origin; + SemanticActivationAckRequestOrigin *origin = &semantic_activation_ack_local_request_origin; ClusterSemanticActivationAckTableV1 before; ClusterSemanticActivationAckTableV1 after; ClusterSemanticActivationAckTableV1 next; @@ -5336,25 +4623,20 @@ semantic_activation_ack_lmon_install_open( bool all_observed; int node; - if (request == NULL - || !semantic_activation_ack_lmon_open_cas_active(request) + if (request == NULL || !semantic_activation_ack_lmon_open_cas_active(request) || !cluster_semantic_activation_record_decode( - SemanticActivationShmem->record_cas_desired_bytes, - &desired, NULL) + SemanticActivationShmem->record_cas_desired_bytes, &desired, NULL) || desired.phase != CLUSTER_SEMANTIC_PHASE_OPEN || !semantic_activation_round_descriptor( - desired.source_feature_bitmap, - desired.target_feature_bitmap, - desired.rollback_feature_bitmap, &round_descriptor, - &required_caps) - || (round_descriptor->feature_bit - != CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1 + desired.source_feature_bitmap, desired.target_feature_bitmap, + desired.rollback_feature_bitmap, &round_descriptor, &required_caps) + || (round_descriptor->feature_bit != CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1 && round_descriptor->feature_bit - != CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1) + != CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1) || !semantic_activation_snapshot(&snapshot) - || !semantic_activation_ack_current_authority( - cluster_node_id, ¤t_members_lo, ¤t_members_hi, - ¤t_epoch, ¤t_coordinator_node) + || !semantic_activation_ack_current_authority(cluster_node_id, ¤t_members_lo, + ¤t_members_hi, ¤t_epoch, + ¤t_coordinator_node) || cluster_node_id != 0 || current_coordinator_node != 0 || current_members_lo != desired.admitted_members_lo || current_members_hi != desired.admitted_members_hi @@ -5367,29 +4649,23 @@ semantic_activation_ack_lmon_install_open( || before.transition_epoch != desired.transition_epoch || before.source_feature_bitmap != desired.source_feature_bitmap || before.target_feature_bitmap != desired.target_feature_bitmap - || before.rollback_feature_bitmap - != desired.rollback_feature_bitmap - || before.capability_sample_digest - != desired.capability_sample_digest) + || before.rollback_feature_bitmap != desired.rollback_feature_bitmap + || before.capability_sample_digest != desired.capability_sample_digest) return false; local_capability_word = cluster_ic_local_capability_word(); if ((local_capability_word & required_caps) != required_caps) return false; - if (!snapshot.transition_closed - && snapshot.active_bits == desired.target_feature_bitmap + if (!snapshot.transition_closed && snapshot.active_bits == desired.target_feature_bitmap && snapshot.record_generation == desired.record_generation && snapshot.formation_epoch == desired.transition_epoch) { - if (before.stage - != CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_OPEN_APPLIED + if (before.stage != CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_OPEN_APPLIED || before.record_generation != desired.record_generation || !semantic_activation_ack_complete_image_current( - &before, current_members_lo, current_members_hi, - current_epoch, current_coordinator_node, - cluster_node_id, local_capability_word) + &before, current_members_lo, current_members_hi, current_epoch, + current_coordinator_node, cluster_node_id, local_capability_word) || !semantic_activation_utility_mailbox_complete( - request->request_seq, CLUSTER_SEMANTIC_ACTIVATION_OK, - 0, desired.record_generation)) + request->request_seq, CLUSTER_SEMANTIC_ACTIVATION_OK, 0, desired.record_generation)) return false; memset(origin, 0, sizeof(*origin)); semantic_activation_lmon_prepare_cas_seq = 0; @@ -5401,20 +4677,17 @@ semantic_activation_ack_lmon_install_open( return true; } - if (!snapshot.transition_closed - || snapshot.active_bits != desired.source_feature_bitmap + if (!snapshot.transition_closed || snapshot.active_bits != desired.source_feature_bitmap || snapshot.record_generation == UINT64_MAX || snapshot.record_generation + 1 != desired.record_generation || snapshot.formation_epoch != desired.transition_epoch) return false; - if (before.stage - == CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_COMMIT_APPLIED) { + if (before.stage == CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_COMMIT_APPLIED) { if (before.record_generation + 1 != desired.record_generation || !semantic_activation_ack_complete_image_current( - &before, current_members_lo, current_members_hi, - current_epoch, current_coordinator_node, - cluster_node_id, local_capability_word)) + &before, current_members_lo, current_members_hi, current_epoch, + current_coordinator_node, cluster_node_id, local_capability_word)) return false; if (!semantic_activation_record_cas_mailbox_poll_completion( semantic_activation_lmon_open_cas_seq, &result)) @@ -5423,30 +4696,23 @@ semantic_activation_ack_lmon_install_open( || !semantic_activation_snapshot(¤t_snapshot) || current_snapshot.seq != snapshot.seq || current_snapshot.active_bits != snapshot.active_bits - || current_snapshot.record_generation - != snapshot.record_generation - || current_snapshot.formation_epoch - != snapshot.formation_epoch - || current_snapshot.transition_closed - != snapshot.transition_closed - || !semantic_activation_ack_current_authority( - cluster_node_id, ¤t_members_lo, ¤t_members_hi, - ¤t_epoch, ¤t_coordinator_node) + || current_snapshot.record_generation != snapshot.record_generation + || current_snapshot.formation_epoch != snapshot.formation_epoch + || current_snapshot.transition_closed != snapshot.transition_closed + || !semantic_activation_ack_current_authority(cluster_node_id, ¤t_members_lo, + ¤t_members_hi, ¤t_epoch, + ¤t_coordinator_node) || current_members_lo != desired.admitted_members_lo || current_members_hi != desired.admitted_members_hi || current_epoch != desired.transition_epoch - || current_coordinator_node - != (int32)desired.coordinator_node - || cluster_ic_local_capability_word() - != local_capability_word - || cluster_qvotec_get_self_incarnation() - != desired.coordinator_incarnation + || current_coordinator_node != (int32)desired.coordinator_node + || cluster_ic_local_capability_word() != local_capability_word + || cluster_qvotec_get_self_incarnation() != desired.coordinator_incarnation || !semantic_activation_ack_table_snapshot(&after) || memcmp(&before, &after, sizeof(before)) != 0 || !semantic_activation_ack_complete_image_current( - &after, current_members_lo, current_members_hi, - current_epoch, current_coordinator_node, - cluster_node_id, local_capability_word)) + &after, current_members_lo, current_members_hi, current_epoch, + current_coordinator_node, cluster_node_id, local_capability_word)) return false; next = after; @@ -5457,13 +4723,11 @@ semantic_activation_ack_lmon_install_open( next.observed_members_hi = 0; memset(next.observed, 0, sizeof(next.observed)); for (node = 0; node < 4; node++) - next.expected[node].record_generation - = desired.record_generation; + next.expected[node].record_generation = desired.record_generation; next.observed[0] = next.expected[0]; if (!semantic_activation_ack_expected_image_current( - &next, current_members_lo, current_members_hi, - current_epoch, current_coordinator_node, - cluster_node_id, local_capability_word) + &next, current_members_lo, current_members_hi, current_epoch, + current_coordinator_node, cluster_node_id, local_capability_word) || !semantic_activation_ack_table_publish(&next)) return false; memset(origin, 0, sizeof(*origin)); @@ -5472,64 +4736,48 @@ semantic_activation_ack_lmon_install_open( return semantic_activation_ack_lmon_send_origin_requests(); } - if (before.stage - != CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_OPEN_APPLIED - || before.record_generation != desired.record_generation - || !origin->active + if (before.stage != CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_OPEN_APPLIED + || before.record_generation != desired.record_generation || !origin->active || !semantic_activation_ack_expected_image_current( - &before, current_members_lo, current_members_hi, - current_epoch, current_coordinator_node, - cluster_node_id, local_capability_word) - || (before.observed_members_lo - & ~before.expected_members_lo) != 0 + &before, current_members_lo, current_members_hi, current_epoch, + current_coordinator_node, cluster_node_id, local_capability_word) + || (before.observed_members_lo & ~before.expected_members_lo) != 0 || before.observed_members_hi != 0) return false; - all_observed - = before.observed_members_lo == before.expected_members_lo; + all_observed = before.observed_members_lo == before.expected_members_lo; if (before.flags != (CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID - | (all_observed - ? CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE - : 0))) + | (all_observed ? CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE : 0))) return false; for (node = 0; node < CLUSTER_MAX_NODES; node++) { bool member = node < 4; bool observed - = node < 64 - ? (before.observed_members_lo - & (UINT64_C(1) << node)) != 0 - : false; + = node < 64 ? (before.observed_members_lo & (UINT64_C(1) << node)) != 0 : false; if (!member) { - if (!semantic_activation_bytes_are_zero( - (const uint8 *)&before.expected[node], - sizeof(before.expected[node])) - || !semantic_activation_bytes_are_zero( - (const uint8 *)&before.observed[node], - sizeof(before.observed[node]))) + if (!semantic_activation_bytes_are_zero((const uint8 *)&before.expected[node], + sizeof(before.expected[node])) + || !semantic_activation_bytes_are_zero((const uint8 *)&before.observed[node], + sizeof(before.observed[node]))) return false; continue; } if (observed) { - if (!semantic_activation_ack_matches( - &before.observed[node], &before.expected[node])) + if (!semantic_activation_ack_matches(&before.observed[node], &before.expected[node])) return false; - } else if (!semantic_activation_bytes_are_zero( - (const uint8 *)&before.observed[node], - sizeof(before.observed[node]))) + } else if (!semantic_activation_bytes_are_zero((const uint8 *)&before.observed[node], + sizeof(before.observed[node]))) return false; } if (!all_observed) return semantic_activation_ack_lmon_send_origin_requests(); if (!semantic_activation_ack_complete_image_current( &before, current_members_lo, current_members_hi, current_epoch, - current_coordinator_node, cluster_node_id, - local_capability_word)) + current_coordinator_node, cluster_node_id, local_capability_word)) return false; callback_generation - = round_descriptor->feature_bit - == CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1 + = round_descriptor->feature_bit == CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1 ? request->expected_record_generation + 1 : desired.record_generation; result = round_descriptor->open_target_admission(callback_generation); @@ -5540,12 +4788,10 @@ semantic_activation_ack_lmon_install_open( * Resource-X proof has not been thawed locally yet. Retain this utility * round only for that fully revalidated shape; drift and every other * callback refusal remain terminal and fail closed. */ - if (round_descriptor->feature_bit - == CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1 + if (round_descriptor->feature_bit == CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1 && result == CLUSTER_SEMANTIC_ACTIVATION_BAD_STATE && cluster_semantic_activation_r11_cutover_snapshot(&cutover) - && cutover.phase - == CLUSTER_SEMANTIC_R11_CUTOVER_DURABLE_OPEN_PENDING_LOCAL + && cutover.phase == CLUSTER_SEMANTIC_R11_CUTOVER_DURABLE_OPEN_PENDING_LOCAL && cutover.record_generation == callback_generation && cutover.formation_epoch == desired.transition_epoch && semantic_activation_ack_table_snapshot(&after) @@ -5553,15 +4799,14 @@ semantic_activation_ack_lmon_install_open( return true; return false; } - if (!semantic_activation_snapshot(¤t_snapshot) - || current_snapshot.seq != snapshot.seq + if (!semantic_activation_snapshot(¤t_snapshot) || current_snapshot.seq != snapshot.seq || current_snapshot.active_bits != snapshot.active_bits || current_snapshot.record_generation != snapshot.record_generation || current_snapshot.formation_epoch != snapshot.formation_epoch || current_snapshot.transition_closed != snapshot.transition_closed - || !semantic_activation_ack_current_authority( - cluster_node_id, ¤t_members_lo, ¤t_members_hi, - ¤t_epoch, ¤t_coordinator_node) + || !semantic_activation_ack_current_authority(cluster_node_id, ¤t_members_lo, + ¤t_members_hi, ¤t_epoch, + ¤t_coordinator_node) || current_members_lo != desired.admitted_members_lo || current_members_hi != desired.admitted_members_hi || current_epoch != desired.transition_epoch @@ -5570,17 +4815,15 @@ semantic_activation_ack_lmon_install_open( || !semantic_activation_ack_table_snapshot(&after) || memcmp(&before, &after, sizeof(before)) != 0 || !semantic_activation_ack_complete_image_current( - &after, current_members_lo, current_members_hi, - current_epoch, current_coordinator_node, cluster_node_id, - local_capability_word)) + &after, current_members_lo, current_members_hi, current_epoch, current_coordinator_node, + cluster_node_id, local_capability_word)) return false; - if (!semantic_activation_lmon_publish_gate( - ¤t_snapshot, desired.target_feature_bitmap, - desired.record_generation, desired.transition_epoch, false)) + if (!semantic_activation_lmon_publish_gate(¤t_snapshot, desired.target_feature_bitmap, + desired.record_generation, desired.transition_epoch, + false)) return false; if (!semantic_activation_utility_mailbox_complete( - request->request_seq, CLUSTER_SEMANTIC_ACTIVATION_OK, 0, - desired.record_generation)) + request->request_seq, CLUSTER_SEMANTIC_ACTIVATION_OK, 0, desired.record_generation)) return false; memset(origin, 0, sizeof(*origin)); @@ -5610,9 +4853,8 @@ semantic_activation_ack_lmon_install_open( */ static bool semantic_activation_ack_lmon_bit22_commit_applied_begin( - const ClusterSemanticActivationAckTableV1 *before, - uint64 current_members_lo, uint64 current_members_hi, - uint64 current_epoch, int32 current_coordinator_node, + const ClusterSemanticActivationAckTableV1 *before, uint64 current_members_lo, + uint64 current_members_hi, uint64 current_epoch, int32 current_coordinator_node, uint32 local_capability_word) { ClusterSemanticActivationAckTableV1 after; @@ -5625,37 +4867,30 @@ semantic_activation_ack_lmon_bit22_commit_applied_begin( uint64 self_bit; int node; - if (before == NULL || before->stage - != CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_PREPARED + if (before == NULL || before->stage != CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_PREPARED || SemanticActivationBit22Seam == NULL || pg_atomic_read_u32(&SemanticActivationBit22Seam->valid) == 0 - || SemanticActivationBit22Seam->transition_epoch - != before->transition_epoch) - return true; /* seam not staged / round mismatch: retry later */ + || SemanticActivationBit22Seam->transition_epoch != before->transition_epoch) + return true; /* seam not staged / round mismatch: retry later */ act_result = cluster_control_root_activate_prepared( - &SemanticActivationBit22Seam->file_token, - SemanticActivationBit22Seam->round_sha, + &SemanticActivationBit22Seam->file_token, SemanticActivationBit22Seam->round_sha, &SemanticActivationBit22Seam->round, &out_token); if (act_result != CLUSTER_CONTROL_ROOT_OK_PRIMARY && act_result != CLUSTER_CONTROL_ROOT_OK_PRIMARY_DEGRADED) { - ereport(LOG, - (errmsg("bit22 cutover: activate_prepared refused (result %d) " - "— the round stays PREPARED (fail-closed)", - (int) act_result))); - return true; /* fail-closed: the round stays PREPARED */ + ereport(LOG, (errmsg("bit22 cutover: activate_prepared refused (result %d) " + "— the round stays PREPARED (fail-closed)", + (int)act_result))); + return true; /* fail-closed: the round stays PREPARED */ } - ereport(LOG, - (errmsg("bit22 cutover: root activated ACTIVE (gen %llu) — " - "publishing COMMIT_APPLIED", - (unsigned long long) before->record_generation))); + ereport(LOG, (errmsg("bit22 cutover: root activated ACTIVE (gen %llu) — " + "publishing COMMIT_APPLIED", + (unsigned long long)before->record_generation))); if (!semantic_activation_ack_table_snapshot(&after) || memcmp(before, &after, sizeof(after)) != 0 - || !semantic_activation_ack_self_tuple( - cluster_node_id, local_capability_word, current_epoch, - after.record_generation, &self) - || !semantic_activation_ack_matches( - &after.expected[cluster_node_id], &self)) + || !semantic_activation_ack_self_tuple(cluster_node_id, local_capability_word, + current_epoch, after.record_generation, &self) + || !semantic_activation_ack_matches(&after.expected[cluster_node_id], &self)) return true; self_bit = UINT64_C(1) << cluster_node_id; @@ -5667,10 +4902,9 @@ semantic_activation_ack_lmon_bit22_commit_applied_begin( next.observed_members_hi = 0; memset(next.observed, 0, sizeof(next.observed)); for (node = 0; node < CLUSTER_MAX_NODES; node++) - if (semantic_activation_ack_member_present( - after.expected_members_lo, after.expected_members_hi, node)) - next.expected[node].record_generation - = after.record_generation + 1; + if (semantic_activation_ack_member_present(after.expected_members_lo, + after.expected_members_hi, node)) + next.expected[node].record_generation = after.record_generation + 1; /* RF-ROOT P9 verification / cold-formation: the coordinator's own * COMMIT_APPLIED observation is its locally-verified ACTIVE root — * mark it self-observed (its expected tuple, generation-bumped above) @@ -5706,12 +4940,10 @@ semantic_activation_ack_lmon_bit22_commit_applied_begin( * path and silently invalidated the REQUEST (kind check), so the member * never saw this stage and the round stalled after root ACTIVE. */ { - SemanticActivationAckRequestOrigin *origin - = &semantic_activation_ack_local_request_origin; + SemanticActivationAckRequestOrigin *origin = &semantic_activation_ack_local_request_origin; memset(origin, 0, sizeof(*origin)); - origin->unsent_members_lo = next.expected_members_lo - & ~(UINT64_C(1) << cluster_node_id); + origin->unsent_members_lo = next.expected_members_lo & ~(UINT64_C(1) << cluster_node_id); origin->active = true; } return semantic_activation_ack_lmon_send_bit22_prepared_requests( @@ -5727,9 +4959,8 @@ semantic_activation_ack_lmon_bit22_commit_applied_begin( */ static bool semantic_activation_ack_lmon_bit22_open_applied_begin( - const ClusterSemanticActivationAckTableV1 *before, - uint64 current_members_lo, uint64 current_members_hi, - uint64 current_epoch, int32 current_coordinator_node, + const ClusterSemanticActivationAckTableV1 *before, uint64 current_members_lo, + uint64 current_members_hi, uint64 current_epoch, int32 current_coordinator_node, uint32 local_capability_word) { ClusterSemanticActivationAckTableV1 after; @@ -5739,33 +4970,27 @@ semantic_activation_ack_lmon_bit22_open_applied_begin( ClusterSemanticActivationAckWireV1 request; uint64 self_bit; - if (before == NULL || before->stage - != CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_COMMIT_APPLIED) + if (before == NULL || before->stage != CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_COMMIT_APPLIED) return false; if (!semantic_activation_ack_table_snapshot(&after) || memcmp(before, &after, sizeof(after)) != 0 - || !semantic_activation_ack_self_tuple( - cluster_node_id, local_capability_word, current_epoch, - after.record_generation, &self) - || !semantic_activation_ack_matches( - &after.expected[cluster_node_id], &self)) + || !semantic_activation_ack_self_tuple(cluster_node_id, local_capability_word, + current_epoch, after.record_generation, &self) + || !semantic_activation_ack_matches(&after.expected[cluster_node_id], &self)) return true; /* RF-ROOT P9 verification (contract / follow-up): the coordinator's latch * MUST flip (and the return be checked) BEFORE its observed bit is * published. */ - if (!cluster_r4_bit22_cutover_latch_apply( - after.transition_epoch, after.record_generation)) { - ereport(LOG, - (errmsg("bit22 cutover: coordinator latch_apply refused " - "(gen %llu) — OPEN_APPLIED not published", - (unsigned long long) after.record_generation))); + if (!cluster_r4_bit22_cutover_latch_apply(after.transition_epoch, after.record_generation)) { + ereport(LOG, (errmsg("bit22 cutover: coordinator latch_apply refused " + "(gen %llu) — OPEN_APPLIED not published", + (unsigned long long)after.record_generation))); return true; } - ereport(LOG, - (errmsg("bit22 cutover: coordinator latch flipped — publishing " - "OPEN_APPLIED (gen %llu)", - (unsigned long long) after.record_generation))); + ereport(LOG, (errmsg("bit22 cutover: coordinator latch flipped — publishing " + "OPEN_APPLIED (gen %llu)", + (unsigned long long)after.record_generation))); self_bit = UINT64_C(1) << cluster_node_id; next = after; @@ -5797,12 +5022,10 @@ semantic_activation_ack_lmon_bit22_open_applied_begin( * send_pending() is ACK-only and silently dropped the REQUEST (the * member would never latch). */ { - SemanticActivationAckRequestOrigin *origin - = &semantic_activation_ack_local_request_origin; + SemanticActivationAckRequestOrigin *origin = &semantic_activation_ack_local_request_origin; memset(origin, 0, sizeof(*origin)); - origin->unsent_members_lo = after.expected_members_lo - & ~(UINT64_C(1) << cluster_node_id); + origin->unsent_members_lo = after.expected_members_lo & ~(UINT64_C(1) << cluster_node_id); origin->active = true; } return semantic_activation_ack_lmon_send_bit22_prepared_requests( @@ -5846,13 +5069,11 @@ semantic_activation_ack_lmon_bit22_advance(void) int32 current_coordinator_node; if (!semantic_activation_ack_table_snapshot(&table) - || (table.target_feature_bitmap - & PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1) == 0 - || SemanticActivationBit22Seam == NULL - || cluster_node_id != (int32)table.coordinator_node - || !semantic_activation_ack_current_authority( - cluster_node_id, ¤t_members_lo, ¤t_members_hi, - ¤t_epoch, ¤t_coordinator_node) + || (table.target_feature_bitmap & PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1) == 0 + || SemanticActivationBit22Seam == NULL || cluster_node_id != (int32)table.coordinator_node + || !semantic_activation_ack_current_authority(cluster_node_id, ¤t_members_lo, + ¤t_members_hi, ¤t_epoch, + ¤t_coordinator_node) || current_members_lo != table.expected_members_lo || current_members_hi != table.expected_members_hi || current_epoch != table.transition_epoch @@ -5862,8 +5083,7 @@ semantic_activation_ack_lmon_bit22_advance(void) * runs there); the PREPARED+ stages bind to it. */ if (table.stage != CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_BARRIER && (pg_atomic_read_u32(&SemanticActivationBit22Seam->valid) == 0 - || table.transition_epoch - != SemanticActivationBit22Seam->transition_epoch)) + || table.transition_epoch != SemanticActivationBit22Seam->transition_epoch)) return false; /* RF-ROOT P9 verification: the BARRIER REQUEST is sent by the LMON — * the ic msg-type gate restricts semantic-activation ACK sends to the @@ -5871,16 +5091,15 @@ semantic_activation_ack_lmon_bit22_advance(void) * first sight of the BARRIER table (begin() runs in a SQL backend and * cannot arm the LMON's origin). Idempotent: unsent clears once. */ if (table.stage == CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_BARRIER) { - SemanticActivationAckRequestOrigin *origin - = &semantic_activation_ack_local_request_origin; + SemanticActivationAckRequestOrigin *origin = &semantic_activation_ack_local_request_origin; if (!origin->active) { memset(origin, 0, sizeof(*origin)); - origin->unsent_members_lo = table.expected_members_lo - & ~(UINT64_C(1) << cluster_node_id); + origin->unsent_members_lo + = table.expected_members_lo & ~(UINT64_C(1) << cluster_node_id); origin->active = true; } - (void) semantic_activation_ack_lmon_send_bit22_prepared_requests( + (void)semantic_activation_ack_lmon_send_bit22_prepared_requests( CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_BARRIER); } local_capability_word = cluster_ic_local_capability_word(); @@ -5899,12 +5118,10 @@ semantic_activation_ack_lmon_bit22_advance(void) uint8 sha[PG_SHA256_DIGEST_LENGTH]; int node; - if ((table.flags - & CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE) == 0 + if ((table.flags & CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE) == 0 || !semantic_activation_ack_complete_image_current( - &table, current_members_lo, current_members_hi, - current_epoch, current_coordinator_node, - cluster_node_id, local_capability_word)) + &table, current_members_lo, current_members_hi, current_epoch, + current_coordinator_node, cluster_node_id, local_capability_word)) return false; /* RF-ROOT P9 verification (cold-formation): the BARRIER is COMPLETE — * write the PREPARE record (generation 1) over the majority legacy- @@ -5925,48 +5142,39 @@ semantic_activation_ack_lmon_bit22_advance(void) desired.record_generation = table.record_generation; desired.admitted_members_lo = table.expected_members_lo; desired.admitted_members_hi = table.expected_members_hi; - desired.capability_sample_digest - = table.capability_sample_digest; - desired.rollback_feature_bitmap - = table.rollback_feature_bitmap; - desired.coordinator_incarnation - = cluster_qvotec_get_self_incarnation(); + desired.capability_sample_digest = table.capability_sample_digest; + desired.rollback_feature_bitmap = table.rollback_feature_bitmap; + desired.coordinator_incarnation = cluster_qvotec_get_self_incarnation(); desired.coordinator_node = table.coordinator_node; desired.phase = CLUSTER_SEMANTIC_PHASE_PREPARE; - if (!cluster_semantic_activation_record_encode( - &desired, desired_bytes) + if (!cluster_semantic_activation_record_encode(&desired, desired_bytes) || !semantic_activation_record_cas_mailbox_submit( - 0, 0, desired_bytes, - &semantic_activation_lmon_bit22_prepare_cas_seq)) { - ereport(LOG, - (errmsg("bit22 cutover: PREPARE(P) CAS submit " - "refused (gen %llu)", - (unsigned long long) - table.record_generation))); + 0, 0, desired_bytes, &semantic_activation_lmon_bit22_prepare_cas_seq)) { + ereport(LOG, (errmsg("bit22 cutover: PREPARE(P) CAS submit " + "refused (gen %llu)", + (unsigned long long)table.record_generation))); return false; } - ereport(LOG, - (errmsg("bit22 cutover: PREPARE(P) CAS submitted " - "(seq %llu) — minting the PREPARED root", - (unsigned long long) - semantic_activation_lmon_bit22_prepare_cas_seq))); + ereport( + LOG, + (errmsg("bit22 cutover: PREPARE(P) CAS submitted " + "(seq %llu) — minting the PREPARED root", + (unsigned long long)semantic_activation_lmon_bit22_prepare_cas_seq))); return true; } if (!semantic_activation_record_cas_mailbox_poll_completion( semantic_activation_lmon_bit22_prepare_cas_seq, &result)) return true; if (result != CLUSTER_SEMANTIC_ACTIVATION_OK) { - ereport(LOG, - (errmsg("bit22 cutover: PREPARE(P) CAS failed " - "(result %d)", - (int) result))); + ereport(LOG, (errmsg("bit22 cutover: PREPARE(P) CAS failed " + "(result %d)", + (int)result))); return false; } semantic_activation_lmon_bit22_prepare_cas_done = true; - ereport(LOG, - (errmsg("bit22 cutover: PREPARE(P) durable (gen %llu) — " - "minting the PREPARED root", - (unsigned long long) table.record_generation))); + ereport(LOG, (errmsg("bit22 cutover: PREPARE(P) durable (gen %llu) — " + "minting the PREPARED root", + (unsigned long long)table.record_generation))); } memset(&round, 0, sizeof(round)); memcpy(round.magic, "PCRM", 4); @@ -5979,37 +5187,31 @@ semantic_activation_ack_lmon_bit22_advance(void) round.admitted_bitmap_low = table.expected_members_lo; round.admitted_bitmap_high = table.expected_members_hi; round.capability_sample_digest = table.capability_sample_digest; - round.coordinator_incarnation - = cluster_qvotec_get_self_incarnation(); + round.coordinator_incarnation = cluster_qvotec_get_self_incarnation(); round.coordinator_node_id = (int32)table.coordinator_node; - create_result = cluster_control_root_build_migration_image( - &round, &image); + create_result = cluster_control_root_build_migration_image(&round, &image); if (create_result != CLUSTER_CONTROL_ROOT_OK_PRIMARY && create_result != CLUSTER_CONTROL_ROOT_OK_PRIMARY_DEGRADED) { ereport(LOG, (errmsg("bit22 cutover: migration image build refused " "(result %d, round gen %llu)", - (int) create_result, - (unsigned long long) round.prepare_generation))); + (int)create_result, (unsigned long long)round.prepare_generation))); return false; } - create_result = cluster_control_root_create_prepared( - &image, &round, &token); + create_result = cluster_control_root_create_prepared(&image, &round, &token); if (create_result != CLUSTER_CONTROL_ROOT_OK_PRIMARY || !cluster_control_root_round_sha256(&round, sha) || !cluster_r4_bit22_cutover_seam_store(&token, sha, &round)) { ereport(LOG, (errmsg("bit22 cutover: create_prepared/seam refused " "(result %d, round gen %llu)", - (int) create_result, - (unsigned long long) round.prepare_generation))); + (int)create_result, (unsigned long long)round.prepare_generation))); return false; } - ereport(LOG, - (errmsg("bit22 cutover: PREPARED root minted (gen %llu, " - "token seq %llu) — staging the PREPARED stage", - (unsigned long long) round.prepare_generation, - (unsigned long long) token.file_txn_seq))); + ereport(LOG, (errmsg("bit22 cutover: PREPARED root minted (gen %llu, " + "token seq %llu) — staging the PREPARED stage", + (unsigned long long)round.prepare_generation, + (unsigned long long)token.file_txn_seq))); /* RF-ROOT P9 verification (cold-formation): the all-member * source-close BARRIER is COMPLETE — every node's wal-state * writers are frozen — so publish the closed-source snapshot @@ -6019,9 +5221,9 @@ semantic_activation_ack_lmon_bit22_advance(void) * this the bit22 round never left the BARRIER stage (the R4 * utility path was the only publish_gate caller). */ if (!semantic_activation_snapshot(&snapshot) - || !semantic_activation_lmon_publish_gate( - &snapshot, table.source_feature_bitmap, - table.record_generation, table.transition_epoch, true)) + || !semantic_activation_lmon_publish_gate(&snapshot, table.source_feature_bitmap, + table.record_generation, + table.transition_epoch, true)) return false; memset(&prepared, 0, sizeof(prepared)); prepared.stage = CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_PREPARED; @@ -6041,27 +5243,23 @@ semantic_activation_ack_lmon_bit22_advance(void) uint32 peer_word; uint32 peer_gen; - if (!semantic_activation_ack_member_present( - current_members_lo, current_members_hi, node)) + if (!semantic_activation_ack_member_present(current_members_lo, current_members_hi, + node)) continue; if (node == cluster_node_id) { if (!semantic_activation_ack_self_tuple( - node, local_capability_word, - round.transition_epoch, - round.prepare_generation, - &prepared.expected[node])) + node, local_capability_word, round.transition_epoch, + round.prepare_generation, &prepared.expected[node])) return false; continue; } memset(&remote, 0, sizeof(remote)); remote.node_id = (uint32)node; - remote.boot_id - = cluster_membership_get_last_admitted_incarnation(node); + remote.boot_id = cluster_membership_get_last_admitted_incarnation(node); remote.admitted_incarnation = remote.boot_id; if (remote.boot_id == 0 || !cluster_sf_peer_capability_word_sample( - node, CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS, - &peer_word, &peer_gen) + node, CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS, &peer_word, &peer_gen) || peer_gen == 0) return false; remote.control_connection_generation = (uint64)peer_gen; @@ -6071,11 +5269,10 @@ semantic_activation_ack_lmon_bit22_advance(void) remote.record_generation = round.prepare_generation; prepared.expected[node] = remote; } - if (!semantic_activation_ack_self_tuple( - cluster_node_id, local_capability_word, - round.transition_epoch, round.prepare_generation, &self) - || !semantic_activation_ack_matches( - &prepared.expected[cluster_node_id], &self)) + if (!semantic_activation_ack_self_tuple(cluster_node_id, local_capability_word, + round.transition_epoch, round.prepare_generation, + &self) + || !semantic_activation_ack_matches(&prepared.expected[cluster_node_id], &self)) return false; /* RF-ROOT P9 verification / cold-formation: mark the coordinator * self-observed in the PREPARED stage too — the coordinator's own @@ -6095,26 +5292,23 @@ semantic_activation_ack_lmon_bit22_advance(void) = &semantic_activation_ack_local_request_origin; memset(origin, 0, sizeof(*origin)); - origin->unsent_members_lo = prepared.expected_members_lo - & ~(UINT64_C(1) << cluster_node_id); + origin->unsent_members_lo + = prepared.expected_members_lo & ~(UINT64_C(1) << cluster_node_id); origin->active = true; } return semantic_activation_ack_lmon_send_bit22_prepared_requests( CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_PREPARED); } if (table.stage == CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_PREPARED) { - if ((table.flags - & CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE) == 0) + if ((table.flags & CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE) == 0) return false; - if (!semantic_activation_snapshot(&snapshot) - || !snapshot.transition_closed + if (!semantic_activation_snapshot(&snapshot) || !snapshot.transition_closed || snapshot.active_bits != table.source_feature_bitmap || snapshot.record_generation != table.record_generation || snapshot.formation_epoch != table.transition_epoch || !semantic_activation_ack_complete_image_current( - &table, current_members_lo, current_members_hi, - current_epoch, current_coordinator_node, - cluster_node_id, local_capability_word)) + &table, current_members_lo, current_members_hi, current_epoch, + current_coordinator_node, cluster_node_id, local_capability_word)) return false; if (semantic_activation_lmon_commit_cas_seq == 0) { memset(&desired, 0, sizeof(desired)); @@ -6126,43 +5320,35 @@ semantic_activation_ack_lmon_bit22_advance(void) desired.admitted_members_lo = table.expected_members_lo; desired.admitted_members_hi = table.expected_members_hi; desired.transition_epoch = table.transition_epoch; - desired.capability_sample_digest - = table.capability_sample_digest; + desired.capability_sample_digest = table.capability_sample_digest; desired.coordinator_node = table.coordinator_node; - desired.coordinator_incarnation - = cluster_qvotec_get_self_incarnation(); - if (!cluster_semantic_activation_record_encode( - &desired, desired_bytes) - || !semantic_activation_record_cas_mailbox_submit( - table.record_generation, - table.source_feature_bitmap, desired_bytes, - &cas_seq)) { + desired.coordinator_incarnation = cluster_qvotec_get_self_incarnation(); + if (!cluster_semantic_activation_record_encode(&desired, desired_bytes) + || !semantic_activation_record_cas_mailbox_submit(table.record_generation, + table.source_feature_bitmap, + desired_bytes, &cas_seq)) { ClusterSemanticActivationAckTableV1 dbg; - ereport(LOG, - (errmsg("bit22 cutover: COMMIT(P+1) CAS submit refused " - "(gen %llu, table stage=%u flags=0x%x)", - (unsigned long long) table.record_generation, - (unsigned) table.stage, - (unsigned) table.flags))); + ereport(LOG, (errmsg("bit22 cutover: COMMIT(P+1) CAS submit refused " + "(gen %llu, table stage=%u flags=0x%x)", + (unsigned long long)table.record_generation, + (unsigned)table.stage, (unsigned)table.flags))); if (semantic_activation_ack_table_snapshot(&dbg)) - ereport(LOG, - (errmsg("bit22 cutover: COMMIT(P+1) CAS submit " - "refused — live table stage=%u flags=0x%x " - "gen=%llu observed=%llx/%llx expected=%llx/%llx", - (unsigned) dbg.stage, (unsigned) dbg.flags, - (unsigned long long) dbg.record_generation, - (unsigned long long) dbg.observed_members_lo, - (unsigned long long) dbg.observed_members_hi, - (unsigned long long) dbg.expected_members_lo, - (unsigned long long) dbg.expected_members_hi))); + ereport(LOG, (errmsg("bit22 cutover: COMMIT(P+1) CAS submit " + "refused — live table stage=%u flags=0x%x " + "gen=%llu observed=%llx/%llx expected=%llx/%llx", + (unsigned)dbg.stage, (unsigned)dbg.flags, + (unsigned long long)dbg.record_generation, + (unsigned long long)dbg.observed_members_lo, + (unsigned long long)dbg.observed_members_hi, + (unsigned long long)dbg.expected_members_lo, + (unsigned long long)dbg.expected_members_hi))); return false; } semantic_activation_lmon_commit_cas_seq = cas_seq; - ereport(LOG, - (errmsg("bit22 cutover: COMMIT(P+1) CAS submitted (seq %llu) " - "— awaiting durable record", - (unsigned long long) cas_seq))); + ereport(LOG, (errmsg("bit22 cutover: COMMIT(P+1) CAS submitted (seq %llu) " + "— awaiting durable record", + (unsigned long long)cas_seq))); return true; } if (!semantic_activation_record_cas_mailbox_poll_completion( @@ -6170,81 +5356,66 @@ semantic_activation_ack_lmon_bit22_advance(void) return true; if (result != CLUSTER_SEMANTIC_ACTIVATION_OK) { ereport(LOG, - (errmsg("bit22 cutover: COMMIT(P+1) CAS failed (result %d)", - (int) result))); + (errmsg("bit22 cutover: COMMIT(P+1) CAS failed (result %d)", (int)result))); return false; } - ereport(LOG, - (errmsg("bit22 cutover: COMMIT(P+1) durable — activating the " - "PREPARED root (gen %llu)", - (unsigned long long) table.record_generation))); + ereport(LOG, (errmsg("bit22 cutover: COMMIT(P+1) durable — activating the " + "PREPARED root (gen %llu)", + (unsigned long long)table.record_generation))); return semantic_activation_ack_lmon_bit22_commit_applied_begin( - &table, current_members_lo, current_members_hi, - current_epoch, current_coordinator_node, + &table, current_members_lo, current_members_hi, current_epoch, current_coordinator_node, local_capability_word); } if (table.stage == CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_COMMIT_APPLIED) { - if ((table.flags - & CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE) == 0) + if ((table.flags & CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE) == 0) return false; if (!semantic_activation_ack_complete_image_current( - &table, current_members_lo, current_members_hi, - current_epoch, current_coordinator_node, - cluster_node_id, local_capability_word)) + &table, current_members_lo, current_members_hi, current_epoch, + current_coordinator_node, cluster_node_id, local_capability_word)) return false; if (semantic_activation_lmon_open_cas_seq == 0) { if (SemanticActivationShmem == NULL || !cluster_semantic_activation_record_decode( - SemanticActivationShmem->record_cas_desired_bytes, - &commit, NULL) + SemanticActivationShmem->record_cas_desired_bytes, &commit, NULL) || commit.phase != CLUSTER_SEMANTIC_PHASE_COMMIT || commit.record_generation != table.record_generation) return false; desired = commit; desired.record_generation = commit.record_generation + 1; desired.phase = CLUSTER_SEMANTIC_PHASE_OPEN; - if (!cluster_semantic_activation_record_encode( - &desired, desired_bytes) - || !semantic_activation_record_cas_mailbox_submit( - commit.record_generation, - commit.source_feature_bitmap, desired_bytes, - &cas_seq)) { - ereport(LOG, - (errmsg("bit22 cutover: OPEN(P+2) CAS submit refused " - "(gen %llu)", - (unsigned long long) table.record_generation))); + if (!cluster_semantic_activation_record_encode(&desired, desired_bytes) + || !semantic_activation_record_cas_mailbox_submit(commit.record_generation, + commit.source_feature_bitmap, + desired_bytes, &cas_seq)) { + ereport(LOG, (errmsg("bit22 cutover: OPEN(P+2) CAS submit refused " + "(gen %llu)", + (unsigned long long)table.record_generation))); return false; } semantic_activation_lmon_open_cas_seq = cas_seq; - ereport(LOG, - (errmsg("bit22 cutover: OPEN(P+2) CAS submitted (seq %llu) " - "— awaiting durable Target OPEN proof", - (unsigned long long) cas_seq))); + ereport(LOG, (errmsg("bit22 cutover: OPEN(P+2) CAS submitted (seq %llu) " + "— awaiting durable Target OPEN proof", + (unsigned long long)cas_seq))); return true; } if (!semantic_activation_record_cas_mailbox_poll_completion( semantic_activation_lmon_open_cas_seq, &result)) return true; if (result != CLUSTER_SEMANTIC_ACTIVATION_OK) { - ereport(LOG, - (errmsg("bit22 cutover: OPEN(P+2) CAS failed (result %d)", - (int) result))); + ereport(LOG, (errmsg("bit22 cutover: OPEN(P+2) CAS failed (result %d)", (int)result))); return false; } - ereport(LOG, - (errmsg("bit22 cutover: OPEN(P+2) durable — Target OPEN proof " - "holds; flipping the coordinator latch"))); + ereport(LOG, (errmsg("bit22 cutover: OPEN(P+2) durable — Target OPEN proof " + "holds; flipping the coordinator latch"))); return semantic_activation_ack_lmon_bit22_open_applied_begin( - &table, current_members_lo, current_members_hi, - current_epoch, current_coordinator_node, + &table, current_members_lo, current_members_hi, current_epoch, current_coordinator_node, local_capability_word); } return false; } static bool -semantic_activation_ack_lmon_install_prepare( - const SemanticActivationUtilityRequest *request) +semantic_activation_ack_lmon_install_prepare(const SemanticActivationUtilityRequest *request) { ClusterSemanticActivationAckTableV1 before; ClusterSemanticActivationAckTableV1 after; @@ -6265,26 +5436,20 @@ semantic_activation_ack_lmon_install_prepare( return semantic_activation_ack_lmon_install_open(request); if (semantic_activation_lmon_commit_cas_seq != 0) return semantic_activation_ack_lmon_install_commit(request); - if (!semantic_activation_ack_lmon_prepare_cas_active( - request, &snapshot) + if (!semantic_activation_ack_lmon_prepare_cas_active(request, &snapshot) || !cluster_semantic_activation_record_decode( - SemanticActivationShmem->record_cas_desired_bytes, - &desired, NULL)) + SemanticActivationShmem->record_cas_desired_bytes, &desired, NULL)) return false; /* The successful projection is idempotent while the utility owner remains * pending. In particular, do not rerun the generation-g preflight after * installing the durable generation-(g+1) PREPARE image. */ - if (snapshot.transition_closed - && snapshot.active_bits == desired.source_feature_bitmap + if (snapshot.transition_closed && snapshot.active_bits == desired.source_feature_bitmap && snapshot.record_generation == desired.record_generation && snapshot.formation_epoch == desired.transition_epoch) - return semantic_activation_ack_lmon_begin_barrier_round( - request, &desired); - if (snapshot.transition_closed - || snapshot.active_bits != request->source_feature_bitmap - || snapshot.record_generation - != request->expected_record_generation + return semantic_activation_ack_lmon_begin_barrier_round(request, &desired); + if (snapshot.transition_closed || snapshot.active_bits != request->source_feature_bitmap + || snapshot.record_generation != request->expected_record_generation || snapshot.formation_epoch != desired.transition_epoch) return false; @@ -6292,9 +5457,9 @@ semantic_activation_ack_lmon_install_prepare( semantic_activation_lmon_prepare_cas_seq, &result)) return true; if (result != CLUSTER_SEMANTIC_ACTIVATION_OK - || !semantic_activation_ack_current_authority( - cluster_node_id, ¤t_members_lo, ¤t_members_hi, - ¤t_epoch, ¤t_coordinator_node) + || !semantic_activation_ack_current_authority(cluster_node_id, ¤t_members_lo, + ¤t_members_hi, ¤t_epoch, + ¤t_coordinator_node) || cluster_node_id != 0 || current_coordinator_node != 0 || current_members_lo != desired.admitted_members_lo || current_members_hi != desired.admitted_members_hi @@ -6312,22 +5477,20 @@ semantic_activation_ack_lmon_install_prepare( local_capability_word = cluster_ic_local_capability_word(); if (!semantic_activation_ack_complete_image_current( - &before, current_members_lo, current_members_hi, - current_epoch, current_coordinator_node, cluster_node_id, - local_capability_word) + &before, current_members_lo, current_members_hi, current_epoch, + current_coordinator_node, cluster_node_id, local_capability_word) || !semantic_activation_ack_sample_digest(&before, &digest) || digest != desired.capability_sample_digest) return false; - if (!semantic_activation_snapshot(¤t_snapshot) - || current_snapshot.seq != snapshot.seq + if (!semantic_activation_snapshot(¤t_snapshot) || current_snapshot.seq != snapshot.seq || current_snapshot.active_bits != snapshot.active_bits || current_snapshot.record_generation != snapshot.record_generation || current_snapshot.formation_epoch != snapshot.formation_epoch || current_snapshot.transition_closed != snapshot.transition_closed - || !semantic_activation_ack_current_authority( - cluster_node_id, ¤t_members_lo, ¤t_members_hi, - ¤t_epoch, ¤t_coordinator_node) + || !semantic_activation_ack_current_authority(cluster_node_id, ¤t_members_lo, + ¤t_members_hi, ¤t_epoch, + ¤t_coordinator_node) || current_members_lo != desired.admitted_members_lo || current_members_hi != desired.admitted_members_hi || current_epoch != desired.transition_epoch @@ -6336,20 +5499,18 @@ semantic_activation_ack_lmon_install_prepare( || !semantic_activation_ack_table_snapshot(&after) || memcmp(&before, &after, sizeof(before)) != 0 || !semantic_activation_ack_complete_image_current( - &after, current_members_lo, current_members_hi, - current_epoch, current_coordinator_node, cluster_node_id, - local_capability_word)) + &after, current_members_lo, current_members_hi, current_epoch, current_coordinator_node, + cluster_node_id, local_capability_word)) return false; - return semantic_activation_lmon_publish_gate( - ¤t_snapshot, desired.source_feature_bitmap, - desired.record_generation, desired.transition_epoch, true); + return semantic_activation_lmon_publish_gate(¤t_snapshot, desired.source_feature_bitmap, + desired.record_generation, + desired.transition_epoch, true); } static bool -semantic_activation_ack_lmon_submit_prepare( - const SemanticActivationUtilityRequest *request, - const SemanticActivationAdmissionSnapshot *snapshot) +semantic_activation_ack_lmon_submit_prepare(const SemanticActivationUtilityRequest *request, + const SemanticActivationAdmissionSnapshot *snapshot) { ClusterSemanticActivationAckTableV1 before; ClusterSemanticActivationAckTableV1 after; @@ -6366,71 +5527,54 @@ semantic_activation_ack_lmon_submit_prepare( int32 current_coordinator_node; if (semantic_activation_lmon_prepare_cas_seq != 0) - return semantic_activation_ack_lmon_prepare_cas_active( - request, snapshot); - if (request == NULL || snapshot == NULL - || request->request_seq == 0 - || request->expected_record_generation == UINT64_MAX - || snapshot->transition_closed + return semantic_activation_ack_lmon_prepare_cas_active(request, snapshot); + if (request == NULL || snapshot == NULL || request->request_seq == 0 + || request->expected_record_generation == UINT64_MAX || snapshot->transition_closed || snapshot->active_bits != request->source_feature_bitmap - || snapshot->record_generation - != request->expected_record_generation + || snapshot->record_generation != request->expected_record_generation || !semantic_activation_ack_round_required_caps( - request->source_feature_bitmap, - request->target_feature_bitmap, + request->source_feature_bitmap, request->target_feature_bitmap, request->rollback_feature_bitmap, &required_caps) - || !semantic_activation_ack_current_authority( - cluster_node_id, ¤t_members_lo, ¤t_members_hi, - ¤t_epoch, ¤t_coordinator_node) + || !semantic_activation_ack_current_authority(cluster_node_id, ¤t_members_lo, + ¤t_members_hi, ¤t_epoch, + ¤t_coordinator_node) || cluster_node_id != 0 || current_coordinator_node != 0 - || current_members_lo != UINT64_C(0x0f) - || current_members_hi != 0 + || current_members_lo != UINT64_C(0x0f) || current_members_hi != 0 || snapshot->formation_epoch != current_epoch || !semantic_activation_ack_table_snapshot(&before) || before.stage != CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_SAMPLE - || before.coordinator_node != UINT32_C(0) - || before.round_nonce != request->request_seq + || before.coordinator_node != UINT32_C(0) || before.round_nonce != request->request_seq || before.transition_epoch != current_epoch - || before.record_generation - != request->expected_record_generation + 1 - || before.source_feature_bitmap - != request->source_feature_bitmap - || before.target_feature_bitmap - != request->target_feature_bitmap - || before.rollback_feature_bitmap - != request->rollback_feature_bitmap) + || before.record_generation != request->expected_record_generation + 1 + || before.source_feature_bitmap != request->source_feature_bitmap + || before.target_feature_bitmap != request->target_feature_bitmap + || before.rollback_feature_bitmap != request->rollback_feature_bitmap) return false; local_capability_word = cluster_ic_local_capability_word(); if ((local_capability_word & required_caps) != required_caps || !semantic_activation_ack_complete_image_current( - &before, current_members_lo, current_members_hi, - current_epoch, current_coordinator_node, cluster_node_id, - local_capability_word) - || !semantic_activation_ack_sample_digest(&before, &digest) - || digest == 0) + &before, current_members_lo, current_members_hi, current_epoch, + current_coordinator_node, cluster_node_id, local_capability_word) + || !semantic_activation_ack_sample_digest(&before, &digest) || digest == 0) return false; - if (!semantic_activation_snapshot(¤t_snapshot) - || current_snapshot.seq != snapshot->seq + if (!semantic_activation_snapshot(¤t_snapshot) || current_snapshot.seq != snapshot->seq || current_snapshot.active_bits != snapshot->active_bits || current_snapshot.record_generation != snapshot->record_generation || current_snapshot.formation_epoch != snapshot->formation_epoch || current_snapshot.transition_closed != snapshot->transition_closed - || !semantic_activation_ack_current_authority( - cluster_node_id, ¤t_members_lo, ¤t_members_hi, - ¤t_epoch, ¤t_coordinator_node) - || current_members_lo != UINT64_C(0x0f) - || current_members_hi != 0 - || current_epoch != snapshot->formation_epoch - || current_coordinator_node != 0 + || !semantic_activation_ack_current_authority(cluster_node_id, ¤t_members_lo, + ¤t_members_hi, ¤t_epoch, + ¤t_coordinator_node) + || current_members_lo != UINT64_C(0x0f) || current_members_hi != 0 + || current_epoch != snapshot->formation_epoch || current_coordinator_node != 0 || cluster_ic_local_capability_word() != local_capability_word || !semantic_activation_ack_table_snapshot(&after) || memcmp(&before, &after, sizeof(before)) != 0 || !semantic_activation_ack_complete_image_current( - &after, current_members_lo, current_members_hi, - current_epoch, current_coordinator_node, cluster_node_id, - local_capability_word)) + &after, current_members_lo, current_members_hi, current_epoch, current_coordinator_node, + cluster_node_id, local_capability_word)) return false; memset(&desired, 0, sizeof(desired)); @@ -6442,28 +5586,24 @@ semantic_activation_ack_lmon_submit_prepare( desired.admitted_members_hi = current_members_hi; desired.capability_sample_digest = digest; desired.rollback_feature_bitmap = request->rollback_feature_bitmap; - desired.coordinator_incarnation - = cluster_qvotec_get_self_incarnation(); + desired.coordinator_incarnation = cluster_qvotec_get_self_incarnation(); desired.coordinator_node = UINT32_C(0); desired.phase = CLUSTER_SEMANTIC_PHASE_PREPARE; if (desired.coordinator_incarnation == 0 - || !cluster_semantic_activation_record_encode( - &desired, desired_bytes) - || !semantic_activation_record_cas_mailbox_submit( - request->expected_record_generation, - request->source_feature_bitmap, desired_bytes, &cas_seq)) + || !cluster_semantic_activation_record_encode(&desired, desired_bytes) + || !semantic_activation_record_cas_mailbox_submit(request->expected_record_generation, + request->source_feature_bitmap, + desired_bytes, &cas_seq)) return false; semantic_activation_lmon_prepare_cas_seq = cas_seq; - semantic_activation_lmon_prepare_cas_utility_request_seq - = request->request_seq; + semantic_activation_lmon_prepare_cas_utility_request_seq = request->request_seq; return true; } static bool -semantic_activation_ack_lmon_submit_commit( - const SemanticActivationUtilityRequest *request, - const ClusterSemanticActivationRecord *prepare) +semantic_activation_ack_lmon_submit_commit(const SemanticActivationUtilityRequest *request, + const ClusterSemanticActivationRecord *prepare) { ClusterSemanticActivationAckTableV1 before; ClusterSemanticActivationAckTableV1 after; @@ -6479,98 +5619,77 @@ semantic_activation_ack_lmon_submit_commit( int32 current_coordinator_node; if (semantic_activation_lmon_commit_cas_seq != 0) - return request != NULL - && semantic_activation_snapshot(&snapshot) - && semantic_activation_ack_lmon_commit_cas_active( - request, &snapshot); - if (request == NULL || prepare == NULL - || request->expected_record_generation > UINT64_MAX - 2 + return request != NULL && semantic_activation_snapshot(&snapshot) + && semantic_activation_ack_lmon_commit_cas_active(request, &snapshot); + if (request == NULL || prepare == NULL || request->expected_record_generation > UINT64_MAX - 2 || prepare->phase != CLUSTER_SEMANTIC_PHASE_PREPARE - || prepare->record_generation - != request->expected_record_generation + 1 - || prepare->source_feature_bitmap - != request->source_feature_bitmap - || prepare->target_feature_bitmap - != request->target_feature_bitmap - || prepare->rollback_feature_bitmap - != request->rollback_feature_bitmap - || prepare->capability_sample_digest == 0 - || !semantic_activation_snapshot(&snapshot) - || !snapshot.transition_closed - || snapshot.active_bits != prepare->source_feature_bitmap + || prepare->record_generation != request->expected_record_generation + 1 + || prepare->source_feature_bitmap != request->source_feature_bitmap + || prepare->target_feature_bitmap != request->target_feature_bitmap + || prepare->rollback_feature_bitmap != request->rollback_feature_bitmap + || prepare->capability_sample_digest == 0 || !semantic_activation_snapshot(&snapshot) + || !snapshot.transition_closed || snapshot.active_bits != prepare->source_feature_bitmap || snapshot.record_generation != prepare->record_generation || snapshot.formation_epoch != prepare->transition_epoch - || !semantic_activation_ack_current_authority( - cluster_node_id, ¤t_members_lo, ¤t_members_hi, - ¤t_epoch, ¤t_coordinator_node) + || !semantic_activation_ack_current_authority(cluster_node_id, ¤t_members_lo, + ¤t_members_hi, ¤t_epoch, + ¤t_coordinator_node) || cluster_node_id != 0 || current_coordinator_node != 0 || current_members_lo != prepare->admitted_members_lo || current_members_hi != prepare->admitted_members_hi || current_epoch != prepare->transition_epoch || !semantic_activation_ack_table_snapshot(&before) - || before.stage - != CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_PREPARED + || before.stage != CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_PREPARED || before.flags - != (CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID - | CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE) + != (CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID + | CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE) || before.coordinator_node != prepare->coordinator_node || before.round_nonce != request->request_seq || before.expected_members_lo != prepare->admitted_members_lo || before.expected_members_hi != prepare->admitted_members_hi || before.transition_epoch != prepare->transition_epoch || before.record_generation != prepare->record_generation - || before.source_feature_bitmap - != prepare->source_feature_bitmap - || before.target_feature_bitmap - != prepare->target_feature_bitmap - || before.rollback_feature_bitmap - != prepare->rollback_feature_bitmap - || before.capability_sample_digest - != prepare->capability_sample_digest) + || before.source_feature_bitmap != prepare->source_feature_bitmap + || before.target_feature_bitmap != prepare->target_feature_bitmap + || before.rollback_feature_bitmap != prepare->rollback_feature_bitmap + || before.capability_sample_digest != prepare->capability_sample_digest) return false; local_capability_word = cluster_ic_local_capability_word(); if (!semantic_activation_ack_complete_image_current( - &before, current_members_lo, current_members_hi, - current_epoch, current_coordinator_node, cluster_node_id, - local_capability_word)) + &before, current_members_lo, current_members_hi, current_epoch, + current_coordinator_node, cluster_node_id, local_capability_word)) return false; desired = *prepare; desired.record_generation = prepare->record_generation + 1; desired.phase = CLUSTER_SEMANTIC_PHASE_COMMIT; - if (!cluster_semantic_activation_record_encode( - &desired, desired_bytes) - || !semantic_activation_snapshot(¤t_snapshot) - || current_snapshot.seq != snapshot.seq + if (!cluster_semantic_activation_record_encode(&desired, desired_bytes) + || !semantic_activation_snapshot(¤t_snapshot) || current_snapshot.seq != snapshot.seq || current_snapshot.active_bits != snapshot.active_bits || current_snapshot.record_generation != snapshot.record_generation || current_snapshot.formation_epoch != snapshot.formation_epoch || current_snapshot.transition_closed != snapshot.transition_closed - || !semantic_activation_ack_current_authority( - cluster_node_id, ¤t_members_lo, ¤t_members_hi, - ¤t_epoch, ¤t_coordinator_node) + || !semantic_activation_ack_current_authority(cluster_node_id, ¤t_members_lo, + ¤t_members_hi, ¤t_epoch, + ¤t_coordinator_node) || current_members_lo != desired.admitted_members_lo || current_members_hi != desired.admitted_members_hi || current_epoch != desired.transition_epoch || current_coordinator_node != (int32)desired.coordinator_node || cluster_ic_local_capability_word() != local_capability_word - || cluster_qvotec_get_self_incarnation() - != desired.coordinator_incarnation + || cluster_qvotec_get_self_incarnation() != desired.coordinator_incarnation || !semantic_activation_ack_table_snapshot(&after) || memcmp(&before, &after, sizeof(before)) != 0 || !semantic_activation_ack_complete_image_current( - &after, current_members_lo, current_members_hi, - current_epoch, current_coordinator_node, cluster_node_id, - local_capability_word) + &after, current_members_lo, current_members_hi, current_epoch, current_coordinator_node, + cluster_node_id, local_capability_word) || !semantic_activation_record_cas_mailbox_submit( - prepare->record_generation, - prepare->source_feature_bitmap, desired_bytes, &cas_seq)) + prepare->record_generation, prepare->source_feature_bitmap, desired_bytes, &cas_seq)) return false; semantic_activation_lmon_commit_cas_seq = cas_seq; - semantic_activation_lmon_commit_cas_utility_request_seq - = request->request_seq; + semantic_activation_lmon_commit_cas_utility_request_seq = request->request_seq; return true; } @@ -6599,15 +5718,11 @@ semantic_activation_r4_prepare_basis_matches( || majority_admitted->target_node_id >= CLUSTER_MAX_NODES || majority_admitted->phase != CLUSTER_JCMK_REPLACEMENT_PHASE_ADMITTED || majority_admitted->reserved0[0] != 0 || majority_admitted->reserved0[1] != 0 - || majority_admitted->reserved0[2] != 0 - || majority_admitted->ready_state_generation == 0 + || majority_admitted->reserved0[2] != 0 || majority_admitted->ready_state_generation == 0 || majority_admitted->old_admitted_incarnation == 0 - || majority_admitted->fresh_incarnation - <= majority_admitted->old_admitted_incarnation - || majority_admitted->request_nonce == 0 - || majority_admitted->baseline_epoch == UINT64_MAX - || majority_admitted->reserved_or_committed_epoch - != majority_admitted->baseline_epoch + 1 + || majority_admitted->fresh_incarnation <= majority_admitted->old_admitted_incarnation + || majority_admitted->request_nonce == 0 || majority_admitted->baseline_epoch == UINT64_MAX + || majority_admitted->reserved_or_committed_epoch != majority_admitted->baseline_epoch + 1 || majority_admitted->grammar_fingerprint == 0) return false; if (!cluster_replacement_episode_is_valid(episode) @@ -6616,18 +5731,15 @@ semantic_activation_r4_prepare_basis_matches( return false; return episode->target_node_id == majority_admitted->target_node_id - && episode->state_generation - == majority_admitted->ready_state_generation + && episode->state_generation == majority_admitted->ready_state_generation && episode->request_nonce == majority_admitted->request_nonce - && episode->old_admitted_incarnation - == majority_admitted->old_admitted_incarnation + && episode->old_admitted_incarnation == majority_admitted->old_admitted_incarnation && episode->fresh_incarnation == majority_admitted->fresh_incarnation && episode->baseline_epoch == majority_admitted->baseline_epoch - && episode->reserved_or_committed_epoch - == majority_admitted->reserved_or_committed_epoch - && memcmp(episode->expected_survivors, - majority_admitted->expected_purge_survivors, - sizeof(episode->expected_survivors)) == 0 + && episode->reserved_or_committed_epoch == majority_admitted->reserved_or_committed_epoch + && memcmp(episode->expected_survivors, majority_admitted->expected_purge_survivors, + sizeof(episode->expected_survivors)) + == 0 && episode->grammar_fingerprint == majority_admitted->grammar_fingerprint; } @@ -6650,17 +5762,14 @@ semantic_activation_r4_current_admitted_basis(void) } static bool -semantic_activation_initial_clean_snapshot_equal( - const ClusterInitialCleanFormationSnapshot *left, - const ClusterInitialCleanFormationSnapshot *right) +semantic_activation_initial_clean_snapshot_equal(const ClusterInitialCleanFormationSnapshot *left, + const ClusterInitialCleanFormationSnapshot *right) { - return left != NULL && right != NULL - && memcmp(left, right, sizeof(*left)) == 0; + return left != NULL && right != NULL && memcmp(left, right, sizeof(*left)) == 0; } static bool -semantic_activation_initial_clean_pgrd_mirror( - uint8 out[CLUSTER_UNDO_ROOT_DESCRIPTOR_BYTES]) +semantic_activation_initial_clean_pgrd_mirror(uint8 out[CLUSTER_UNDO_ROOT_DESCRIPTOR_BYTES]) { ClusterUndoRootDescriptorV1 descriptor; uint8 snapshot[CLUSTER_UNDO_ROOT_DESCRIPTOR_BYTES]; @@ -6668,18 +5777,13 @@ semantic_activation_initial_clean_pgrd_mirror( uint8 mirror[CLUSTER_UNDO_ROOT_DESCRIPTOR_BYTES]; char root_directory[MAXPGPATH]; - if (out == NULL - || !semantic_activation_pgrd_snapshot_copy(snapshot) - || cluster_undo_root_descriptor_decode( - snapshot, GetSystemIdentifier(), &descriptor) - != CLUSTER_UNDO_ROOT_DESCRIPTOR_VALID - || descriptor.root_kind != CLUSTER_UNDO_ROOT_KIND_SHARED - || descriptor.owner_node != -1 - || !semantic_activation_lmon_shared_pgrd_root_directory( - root_directory) - || cluster_undo_smgr_root_descriptor_read_candidate( - root_directory, mirror) - != CLUSTER_UNDO_SMGR_ROOT_MIRROR_EXACT + if (out == NULL || !semantic_activation_pgrd_snapshot_copy(snapshot) + || cluster_undo_root_descriptor_decode(snapshot, GetSystemIdentifier(), &descriptor) + != CLUSTER_UNDO_ROOT_DESCRIPTOR_VALID + || descriptor.root_kind != CLUSTER_UNDO_ROOT_KIND_SHARED || descriptor.owner_node != -1 + || !semantic_activation_lmon_shared_pgrd_root_directory(root_directory) + || cluster_undo_smgr_root_descriptor_read_candidate(root_directory, mirror) + != CLUSTER_UNDO_SMGR_ROOT_MIRROR_EXACT || memcmp(snapshot, mirror, sizeof(snapshot)) != 0 || !semantic_activation_pgrd_snapshot_copy(snapshot_after) || memcmp(snapshot, snapshot_after, sizeof(snapshot)) != 0) @@ -6691,8 +5795,7 @@ semantic_activation_initial_clean_pgrd_mirror( /* Pre-SAMPLE only. The exact clean identity and PGRD/mirror permit LMON to * ask all four current members for ACKs; they do not authorize RECORD_CAS. */ static bool -semantic_activation_r4_initial_clean_sample_basis( - uint64 expected_generation, bool coordinator_only) +semantic_activation_r4_initial_clean_sample_basis(uint64 expected_generation, bool coordinator_only) { ClusterInitialCleanFormationSnapshot clean_before; ClusterInitialCleanFormationSnapshot clean_after; @@ -6708,61 +5811,49 @@ semantic_activation_r4_initial_clean_sample_basis( int32 coordinator_node; int node; - if (expected_generation != 0 - || cluster_grd_recovery_state_value() != GRD_RECOVERY_IDLE - || !cluster_reconfig_snapshot_initial_clean_formation( - &clean_before) + if (expected_generation != 0 || cluster_grd_recovery_state_value() != GRD_RECOVERY_IDLE + || !cluster_reconfig_snapshot_initial_clean_formation(&clean_before) || (clean_before.formation_marker_generation == 0 && clean_before.formation_epoch != CLUSTER_EPOCH_INITIAL) - || clean_before.members_lo != UINT64_C(0x0f) - || clean_before.members_hi != 0 + || clean_before.members_lo != UINT64_C(0x0f) || clean_before.members_hi != 0 || clean_before.formation_epoch != cluster_epoch_get_current() || !semantic_activation_initial_clean_pgrd_mirror(pgrd_before) - || !semantic_activation_snapshot(&gate) - || gate.active_bits != 0 || gate.record_generation != 0 - || gate.transition_closed + || !semantic_activation_snapshot(&gate) || gate.active_bits != 0 + || gate.record_generation != 0 || gate.transition_closed || gate.formation_epoch != clean_before.formation_epoch - || !semantic_activation_ack_current_authority( - cluster_node_id, &members_lo, &members_hi, &formation_epoch, - &coordinator_node) - || members_lo != clean_before.members_lo - || members_hi != clean_before.members_hi - || formation_epoch != clean_before.formation_epoch - || coordinator_node != 0 + || !semantic_activation_ack_current_authority(cluster_node_id, &members_lo, &members_hi, + &formation_epoch, &coordinator_node) + || members_lo != clean_before.members_lo || members_hi != clean_before.members_hi + || formation_epoch != clean_before.formation_epoch || coordinator_node != 0 || (coordinator_only && cluster_node_id != coordinator_node)) return false; local_capability_word = cluster_ic_local_capability_word(); - if ((local_capability_word - & CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS) + if ((local_capability_word & CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS) != CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS) return false; for (node = 0; node < 4; node++) { if (cluster_membership_get_state(node) != CLUSTER_MEMBER_MEMBER || cluster_membership_get_last_admitted_incarnation(node) - != clean_before.admitted_incarnation[node]) + != clean_before.admitted_incarnation[node]) return false; if (node == cluster_node_id) { - if (cluster_qvotec_get_self_incarnation() - != clean_before.admitted_incarnation[node]) + if (cluster_qvotec_get_self_incarnation() != clean_before.admitted_incarnation[node]) return false; continue; } - if (!cluster_sf_peer_capability_word_sample( - node, CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS, - &capability_word, &capability_generation) + if (!cluster_sf_peer_capability_word_sample(node, + CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS, + &capability_word, &capability_generation) || capability_generation == 0 - || (capability_word - & CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS) - != CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS) + || (capability_word & CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS) + != CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS) return false; } return cluster_grd_recovery_state_value() == GRD_RECOVERY_IDLE - && cluster_reconfig_snapshot_initial_clean_formation( - &clean_after) - && semantic_activation_initial_clean_snapshot_equal( - &clean_before, &clean_after) + && cluster_reconfig_snapshot_initial_clean_formation(&clean_after) + && semantic_activation_initial_clean_snapshot_equal(&clean_before, &clean_after) && semantic_activation_initial_clean_pgrd_mirror(pgrd_after) && memcmp(pgrd_before, pgrd_after, sizeof(pgrd_before)) == 0 && cluster_qvotec_in_quorum() @@ -6770,11 +5861,9 @@ semantic_activation_r4_initial_clean_sample_basis( } static bool -semantic_activation_r4_initial_clean_sample_candidate( - uint64 expected_generation) +semantic_activation_r4_initial_clean_sample_candidate(uint64 expected_generation) { - return semantic_activation_r4_initial_clean_sample_basis( - expected_generation, true); + return semantic_activation_r4_initial_clean_sample_basis(expected_generation, true); } /* @@ -6800,40 +5889,34 @@ semantic_activation_r4_invalidator_rescan_matches( uint8 expected_subject[CLUSTER_EPOCH_BALLOT_BITMAP_BYTES] = { 0 }; if (completion == NULL - || !semantic_activation_r4_prepare_basis_matches( - majority_admitted, episode) - || completion->request_seq == 0 - || (completion->request_seq & UINT64_C(1)) != 0 + || !semantic_activation_r4_prepare_basis_matches(majority_admitted, episode) + || completion->request_seq == 0 || (completion->request_seq & UINT64_C(1)) != 0 || completion->result != CLUSTER_QVOTEC_MAILBOX_CHOSEN || completion->actor_phase != CLUSTER_QVOTEC_ACTOR_RECOVER_SCAN_B || completion->observed_disk_bitmap == 0 || completion->detail != 0 - || !cluster_epoch_authority_value_decode( - completion->completion_value, - CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT, &head) - || !cluster_epoch_ballot_id_decode( - completion->completion_ballot, &ballot)) + || !cluster_epoch_authority_value_decode(completion->completion_value, + CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT, &head) + || !cluster_epoch_ballot_id_decode(completion->completion_ballot, &ballot)) return false; (void)ballot; - expected_subject[episode->target_node_id / 8] - = (uint8)(1u << (episode->target_node_id % 8)); + expected_subject[episode->target_node_id / 8] = (uint8)(1u << (episode->target_node_id % 8)); return head.value_version == CLUSTER_EPOCH_AUTHORITY_VALUE_VERSION && head.transition == CLUSTER_EPOCH_AUTHORITY_COMMIT_CLOSED && head.event_kind == CLUSTER_EPOCH_EVENT_SAME_NODE_REPLACEMENT && head.request_origin_node == episode->target_node_id - && head.target_node_id == episode->target_node_id - && head.authority_generation != 0 + && head.target_node_id == episode->target_node_id && head.authority_generation != 0 && head.authority_generation != UINT64_MAX && head.baseline_epoch == episode->baseline_epoch && head.reserved_epoch == episode->reserved_or_committed_epoch && head.old_incarnation == episode->old_admitted_incarnation && head.fresh_incarnation == episode->fresh_incarnation && head.request_nonce == episode->request_nonce - && memcmp(head.authority_member_bitmap, - episode->expected_survivors, - sizeof(head.authority_member_bitmap)) == 0 - && memcmp(head.event_subject_bitmap, expected_subject, - sizeof(head.event_subject_bitmap)) == 0 + && memcmp(head.authority_member_bitmap, episode->expected_survivors, + sizeof(head.authority_member_bitmap)) + == 0 + && memcmp(head.event_subject_bitmap, expected_subject, sizeof(head.event_subject_bitmap)) + == 0 && head.grammar_fingerprint == episode->grammar_fingerprint; } @@ -6859,10 +5942,9 @@ semantic_activation_admission_policy(uint64 feature_bit, uint64 active_bits, boo } static ClusterSemanticAdmissionResult -semantic_activation_r4_terminal_census_policy( - uint64 feature_bit, bool transition_closed, - ClusterSemanticAdmissionSide side, uint64 expected_generation, - uint64 current_generation) +semantic_activation_r4_terminal_census_policy(uint64 feature_bit, bool transition_closed, + ClusterSemanticAdmissionSide side, + uint64 expected_generation, uint64 current_generation) { if (feature_bit != CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1 || side != CLUSTER_SEMANTIC_TARGET_SIDE) @@ -6878,13 +5960,11 @@ static bool semantic_activation_modifier_policy(uint64 active_bits, uint64 record_generation, bool transition_closed) { - const uint64 supported_active_bits - = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1 - | CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1; + const uint64 supported_active_bits = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1 + | CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1; if ((active_bits & ~supported_active_bits) != 0 - || ((active_bits - & CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1) != 0 + || ((active_bits & CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1) != 0 && (active_bits & CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1) == 0)) return false; @@ -6982,9 +6062,8 @@ semantic_activation_preflight(ClusterSemanticActivationAction action, uint64 exp * mirror publication. Every other refusal remains mutation-free. */ static bool -semantic_activation_preopen_pgrd_setup_allowed( - ClusterSemanticActivationAction action, - ClusterSemanticActivationResult preflight_result) +semantic_activation_preopen_pgrd_setup_allowed(ClusterSemanticActivationAction action, + ClusterSemanticActivationResult preflight_result) { return action == CLUSTER_SEMANTIC_ENABLE_ALL && (preflight_result == CLUSTER_SEMANTIC_ACTIVATION_OK @@ -7013,12 +6092,12 @@ semantic_activation_actor_edge_allowed(SemanticActivationActor from, SemanticAct * and QVOTEC alone owns the PGSA voting-disk write. */ static bool semantic_activation_actor_effect_allowed(SemanticActivationActor actor, - SemanticActivationEffect effect) + SemanticActivationEffect effect) pg_attribute_unused(); static bool semantic_activation_actor_effect_allowed(SemanticActivationActor actor, - SemanticActivationEffect effect) + SemanticActivationEffect effect) { switch (actor) { case SEMANTIC_ACTIVATION_ACTOR_PROCESS_UTILITY: @@ -7042,11 +6121,9 @@ r4_pre_prepare_readiness(uint64 expected_generation, ClusterSemanticActivationRe { bool admitted_basis = semantic_activation_r4_current_admitted_basis(); bool initial_clean_basis - = semantic_activation_r4_initial_clean_sample_candidate( - expected_generation); + = semantic_activation_r4_initial_clean_sample_candidate(expected_generation); ClusterSemanticActivationResult result - = (cluster_ctrc_shmem_ready() - && (admitted_basis || initial_clean_basis)) + = (cluster_ctrc_shmem_ready() && (admitted_basis || initial_clean_basis)) ? CLUSTER_SEMANTIC_ACTIVATION_OK : CLUSTER_SEMANTIC_ACTIVATION_RF_DEFERRED; @@ -7076,25 +6153,21 @@ r4_close_source_admission(uint64 generation) SemanticActivationAdmissionSnapshot snapshot; uint32 debt; - if (!semantic_activation_snapshot(&snapshot) - || generation == 0 || snapshot.record_generation != generation + if (!semantic_activation_snapshot(&snapshot) || generation == 0 + || snapshot.record_generation != generation || snapshot.formation_epoch != cluster_epoch_get_current() - || (snapshot.active_bits - & CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1) != 0) + || (snapshot.active_bits & CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1) != 0) return CLUSTER_SEMANTIC_ACTIVATION_BAD_STATE; if (!snapshot.transition_closed - && !semantic_activation_lmon_publish_gate( - &snapshot, snapshot.active_bits, snapshot.record_generation, - snapshot.formation_epoch, true)) + && !semantic_activation_lmon_publish_gate(&snapshot, snapshot.active_bits, + snapshot.record_generation, + snapshot.formation_epoch, true)) return CLUSTER_SEMANTIC_ACTIVATION_MEMBERSHIP_CHANGED; pg_read_barrier(); - debt = pg_atomic_read_u32( - &SemanticActivationShmem - ->inflight[CLUSTER_SEMANTIC_SOURCE_SIDE][0]); - return debt == 0 ? CLUSTER_SEMANTIC_ACTIVATION_OK - : CLUSTER_SEMANTIC_ACTIVATION_DEBT_NONZERO; + debt = pg_atomic_read_u32(&SemanticActivationShmem->inflight[CLUSTER_SEMANTIC_SOURCE_SIDE][0]); + return debt == 0 ? CLUSTER_SEMANTIC_ACTIVATION_OK : CLUSTER_SEMANTIC_ACTIVATION_DEBT_NONZERO; } static ClusterSemanticActivationResult @@ -7109,30 +6182,22 @@ r4_source_logical_debt_zero(uint64 generation, ClusterSemanticZeroProof *proof) if (generation == 0 || !semantic_activation_snapshot(&snapshot) || snapshot.record_generation != generation - || snapshot.formation_epoch != cluster_epoch_get_current() - || !snapshot.transition_closed - || (snapshot.active_bits - & CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1) != 0) + || snapshot.formation_epoch != cluster_epoch_get_current() || !snapshot.transition_closed + || (snapshot.active_bits & CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1) != 0) return CLUSTER_SEMANTIC_ACTIVATION_BAD_STATE; - source_debt = pg_atomic_read_u32( - &SemanticActivationShmem - ->inflight[CLUSTER_SEMANTIC_SOURCE_SIDE][0]); + source_debt + = pg_atomic_read_u32(&SemanticActivationShmem->inflight[CLUSTER_SEMANTIC_SOURCE_SIDE][0]); if (source_debt != 0) return CLUSTER_SEMANTIC_ACTIVATION_DEBT_NONZERO; /* Closed admission prevents a new source owner after the zero sample; * re-sample the complete authority tuple before exposing the proof. */ - if (!semantic_activation_snapshot(&snapshot) - || snapshot.record_generation != generation - || snapshot.formation_epoch != cluster_epoch_get_current() - || !snapshot.transition_closed - || (snapshot.active_bits - & CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1) != 0) + if (!semantic_activation_snapshot(&snapshot) || snapshot.record_generation != generation + || snapshot.formation_epoch != cluster_epoch_get_current() || !snapshot.transition_closed + || (snapshot.active_bits & CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1) != 0) return CLUSTER_SEMANTIC_ACTIVATION_BAD_STATE; - if (pg_atomic_read_u32( - &SemanticActivationShmem - ->inflight[CLUSTER_SEMANTIC_SOURCE_SIDE][0]) + if (pg_atomic_read_u32(&SemanticActivationShmem->inflight[CLUSTER_SEMANTIC_SOURCE_SIDE][0]) != 0) return CLUSTER_SEMANTIC_ACTIVATION_DEBT_NONZERO; @@ -7163,24 +6228,20 @@ r4_source_transport_zero(uint64 generation, ClusterSemanticZeroProof *proof) if (generation == 0 || !semantic_activation_snapshot(&snapshot) || snapshot.record_generation != generation - || snapshot.formation_epoch != cluster_epoch_get_current() - || !snapshot.transition_closed) + || snapshot.formation_epoch != cluster_epoch_get_current() || !snapshot.transition_closed) return CLUSTER_SEMANTIC_ACTIVATION_BAD_STATE; - target_debt = pg_atomic_read_u32( - &SemanticActivationShmem - ->inflight[CLUSTER_SEMANTIC_TARGET_SIDE][0]); + target_debt + = pg_atomic_read_u32(&SemanticActivationShmem->inflight[CLUSTER_SEMANTIC_TARGET_SIDE][0]); if (target_debt != 0) return CLUSTER_SEMANTIC_ACTIVATION_DEBT_NONZERO; lms_state = cluster_lms_shared_state(); if (lms_state == NULL - || !cluster_lms_r4_drain_request( - lms_state, generation, &worker_incarnation)) + || !cluster_lms_r4_drain_request(lms_state, generation, &worker_incarnation)) return CLUSTER_SEMANTIC_ACTIVATION_TRANSPORT_NONZERO; cluster_lms_wakeup(0); - if (!cluster_cr_server_r4_lmon_reclaim_closed( - worker_incarnation, generation)) + if (!cluster_cr_server_r4_lmon_reclaim_closed(worker_incarnation, generation)) return CLUSTER_SEMANTIC_ACTIVATION_TRANSPORT_NONZERO; (void)cluster_gcs_block_dedup_r4_route_purge_closed(); @@ -7190,14 +6251,11 @@ r4_source_transport_zero(uint64 generation, ClusterSemanticZeroProof *proof) /* Bind the proof to a final coherent gate sample; no partial proof escapes * if the formation/generation/close edge moved during convergence. */ - if (!semantic_activation_snapshot(&snapshot) - || snapshot.record_generation != generation - || snapshot.formation_epoch != cluster_epoch_get_current() - || !snapshot.transition_closed) + if (!semantic_activation_snapshot(&snapshot) || snapshot.record_generation != generation + || snapshot.formation_epoch != cluster_epoch_get_current() || !snapshot.transition_closed) return CLUSTER_SEMANTIC_ACTIVATION_BAD_STATE; - target_debt = pg_atomic_read_u32( - &SemanticActivationShmem - ->inflight[CLUSTER_SEMANTIC_TARGET_SIDE][0]); + target_debt + = pg_atomic_read_u32(&SemanticActivationShmem->inflight[CLUSTER_SEMANTIC_TARGET_SIDE][0]); if (target_debt != 0) return CLUSTER_SEMANTIC_ACTIVATION_DEBT_NONZERO; @@ -7211,8 +6269,7 @@ r4_source_transport_zero(uint64 generation, ClusterSemanticZeroProof *proof) static bool semantic_activation_ack_member_prepared_image_current( - const ClusterSemanticActivationAckTableV1 *image, - SemanticActivationAckTuple *out_self) + const ClusterSemanticActivationAckTableV1 *image, SemanticActivationAckTuple *out_self) { SemanticActivationAdmissionSnapshot snapshot; SemanticActivationAckTuple self; @@ -7230,80 +6287,62 @@ semantic_activation_ack_member_prepared_image_current( /* RF-ROOT P7 (contract): the bit22 cutover round uses the * round-parameterized check (member set from the ACK table, target * carries bit22) instead of the R4 four-member hardcoded shape. */ - if (image != NULL && (image->target_feature_bitmap - & PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1) != 0) - return semantic_activation_ack_member_prepared_image_current_bit22( - image, out_self); + if (image != NULL + && (image->target_feature_bitmap & PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1) + != 0) + return semantic_activation_ack_member_prepared_image_current_bit22(image, out_self); if (image == NULL || cluster_node_id < 0 || cluster_node_id >= 4 - || (image->stage - != CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_PREPARED - && image->stage - != CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_COMMIT_APPLIED) - || image->coordinator_node != UINT32_C(0) - || image->expected_members_lo != UINT64_C(0x0f) - || image->expected_members_hi != 0 - || image->round_nonce == 0 || image->record_generation == 0 + || (image->stage != CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_PREPARED + && image->stage != CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_COMMIT_APPLIED) + || image->coordinator_node != UINT32_C(0) || image->expected_members_lo != UINT64_C(0x0f) + || image->expected_members_hi != 0 || image->round_nonce == 0 + || image->record_generation == 0 || !semantic_activation_round_descriptor( - image->source_feature_bitmap, - image->target_feature_bitmap, - image->rollback_feature_bitmap, &round_descriptor, - &required_caps) + image->source_feature_bitmap, image->target_feature_bitmap, + image->rollback_feature_bitmap, &round_descriptor, &required_caps) || image->capability_sample_digest == 0 - || (image->observed_members_lo - & ~image->expected_members_lo) != 0 - || image->observed_members_hi != 0 - || semantic_activation_lmon_record_read_seq != 0 + || (image->observed_members_lo & ~image->expected_members_lo) != 0 + || image->observed_members_hi != 0 || semantic_activation_lmon_record_read_seq != 0 || semantic_activation_ack_local_pending_send.pending_members_lo != 0 || semantic_activation_ack_local_pending_send.pending_members_hi != 0 || semantic_activation_ack_local_pending_send.invalidated) return false; - all_observed - = image->observed_members_lo == image->expected_members_lo; + all_observed = image->observed_members_lo == image->expected_members_lo; if (image->flags != (CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID - | (all_observed - ? CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE - : 0))) + | (all_observed ? CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE : 0))) return false; for (node = 0; node < CLUSTER_MAX_NODES; node++) { bool member = node < 4; bool observed - = node < 64 - ? (image->observed_members_lo - & (UINT64_C(1) << node)) != 0 - : false; + = node < 64 ? (image->observed_members_lo & (UINT64_C(1) << node)) != 0 : false; if (!member) { - if (!semantic_activation_bytes_are_zero( - (const uint8 *)&image->expected[node], - sizeof(image->expected[node])) - || !semantic_activation_bytes_are_zero( - (const uint8 *)&image->observed[node], - sizeof(image->observed[node]))) + if (!semantic_activation_bytes_are_zero((const uint8 *)&image->expected[node], + sizeof(image->expected[node])) + || !semantic_activation_bytes_are_zero((const uint8 *)&image->observed[node], + sizeof(image->observed[node]))) return false; continue; } if (observed) { - if (!semantic_activation_ack_matches( - &image->observed[node], &image->expected[node])) + if (!semantic_activation_ack_matches(&image->observed[node], &image->expected[node])) return false; - } else if (!semantic_activation_bytes_are_zero( - (const uint8 *)&image->observed[node], - sizeof(image->observed[node]))) + } else if (!semantic_activation_bytes_are_zero((const uint8 *)&image->observed[node], + sizeof(image->observed[node]))) return false; } - if (!semantic_activation_ack_current_authority( - cluster_node_id, ¤t_members_lo, ¤t_members_hi, - ¤t_epoch, ¤t_coordinator_node) + if (!semantic_activation_ack_current_authority(cluster_node_id, ¤t_members_lo, + ¤t_members_hi, ¤t_epoch, + ¤t_coordinator_node) || current_members_lo != image->expected_members_lo || current_members_hi != image->expected_members_hi || current_epoch != image->transition_epoch || current_coordinator_node != (int32)image->coordinator_node - || !semantic_activation_snapshot(&snapshot) - || !snapshot.transition_closed + || !semantic_activation_snapshot(&snapshot) || !snapshot.transition_closed || snapshot.active_bits != image->source_feature_bitmap || snapshot.record_generation != image->record_generation || snapshot.formation_epoch != image->transition_epoch) @@ -7311,20 +6350,16 @@ semantic_activation_ack_member_prepared_image_current( local_capability_word = cluster_ic_local_capability_word(); if ((local_capability_word & required_caps) != required_caps || !semantic_activation_ack_expected_image_current( - image, current_members_lo, current_members_hi, current_epoch, - current_coordinator_node, cluster_node_id, - local_capability_word) - || !semantic_activation_ack_self_tuple( - cluster_node_id, local_capability_word, current_epoch, - image->record_generation, &self) - || !semantic_activation_ack_matches( - &image->expected[cluster_node_id], &self)) + image, current_members_lo, current_members_hi, current_epoch, current_coordinator_node, + cluster_node_id, local_capability_word) + || !semantic_activation_ack_self_tuple(cluster_node_id, local_capability_word, + current_epoch, image->record_generation, &self) + || !semantic_activation_ack_matches(&image->expected[cluster_node_id], &self)) return false; self_bit = UINT64_C(1) << cluster_node_id; if ((image->observed_members_lo & self_bit) != 0 - && !semantic_activation_ack_matches( - &image->observed[cluster_node_id], &self)) + && !semantic_activation_ack_matches(&image->observed[cluster_node_id], &self)) return false; if (out_self != NULL) *out_self = self; @@ -7346,12 +6381,10 @@ semantic_activation_ack_lmon_finish_member_prepared( if (callback_result != CLUSTER_SEMANTIC_ACTIVATION_OK) return true; - if (!semantic_activation_ack_member_prepared_image_current( - before, &self) + if (!semantic_activation_ack_member_prepared_image_current(before, &self) || !semantic_activation_ack_table_snapshot(&after) || memcmp(before, &after, sizeof(after)) != 0 - || !semantic_activation_ack_member_prepared_image_current( - &after, &self)) + || !semantic_activation_ack_member_prepared_image_current(&after, &self)) return true; self_bit = UINT64_C(1) << cluster_node_id; @@ -7374,15 +6407,14 @@ semantic_activation_ack_lmon_finish_member_prepared( request.admitted_members_hi = after.expected_members_hi; request.capability_sample_digest = after.capability_sample_digest; memset(&pending, 0, sizeof(pending)); - if (!semantic_activation_ack_pending_send_begin_positive( - &pending, &request, cluster_node_id, &self)) + if (!semantic_activation_ack_pending_send_begin_positive(&pending, &request, cluster_node_id, + &self)) return true; next = after; next.observed_members_lo |= self_bit; next.observed[cluster_node_id] = self; - all_observed - = next.observed_members_lo == next.expected_members_lo; + all_observed = next.observed_members_lo == next.expected_members_lo; next.flags = CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID; if (all_observed) next.flags |= CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE; @@ -7409,8 +6441,7 @@ semantic_activation_ack_lmon_finish_member_prepared( * fail-closed here. */ static bool -r4_initial_clean_stage_current(uint64 generation, - ClusterSemanticActivationAckStage stage) +r4_initial_clean_stage_current(uint64 generation, ClusterSemanticActivationAckStage stage) { ClusterInitialCleanFormationSnapshot clean_before; ClusterInitialCleanFormationSnapshot clean_after; @@ -7430,99 +6461,75 @@ r4_initial_clean_stage_current(uint64 generation, if (generation == 0 || (stage != CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_PREPARED - && stage - != CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_COMMIT_APPLIED - && stage - != CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_OPEN_APPLIED) + && stage != CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_COMMIT_APPLIED + && stage != CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_OPEN_APPLIED) || cluster_grd_recovery_state_value() != GRD_RECOVERY_IDLE - || !cluster_reconfig_snapshot_initial_clean_formation( - &clean_before) + || !cluster_reconfig_snapshot_initial_clean_formation(&clean_before) || (clean_before.formation_marker_generation == 0 && clean_before.formation_epoch != CLUSTER_EPOCH_INITIAL) - || clean_before.members_lo != UINT64_C(0x0f) - || clean_before.members_hi != 0 + || clean_before.members_lo != UINT64_C(0x0f) || clean_before.members_hi != 0 || clean_before.arbiter_node != 0 || !semantic_activation_initial_clean_pgrd_mirror(pgrd_before) - || !semantic_activation_ack_table_snapshot(&table_before) - || table_before.stage != stage - || table_before.coordinator_node != UINT32_C(0) - || table_before.round_nonce == 0 + || !semantic_activation_ack_table_snapshot(&table_before) || table_before.stage != stage + || table_before.coordinator_node != UINT32_C(0) || table_before.round_nonce == 0 || table_before.record_generation != generation || table_before.expected_members_lo != clean_before.members_lo || table_before.expected_members_hi != clean_before.members_hi || table_before.transition_epoch != clean_before.formation_epoch || table_before.source_feature_bitmap != 0 - || table_before.target_feature_bitmap - != CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1 - || table_before.rollback_feature_bitmap != 0 - || table_before.capability_sample_digest == 0 - || !semantic_activation_snapshot(&gate_before) - || !gate_before.transition_closed + || table_before.target_feature_bitmap != CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1 + || table_before.rollback_feature_bitmap != 0 || table_before.capability_sample_digest == 0 + || !semantic_activation_snapshot(&gate_before) || !gate_before.transition_closed || gate_before.active_bits != 0 || gate_before.formation_epoch != clean_before.formation_epoch - || !semantic_activation_ack_current_authority( - cluster_node_id, &members_lo, &members_hi, ¤t_epoch, - &coordinator_node) - || members_lo != clean_before.members_lo - || members_hi != clean_before.members_hi + || !semantic_activation_ack_current_authority(cluster_node_id, &members_lo, &members_hi, + ¤t_epoch, &coordinator_node) + || members_lo != clean_before.members_lo || members_hi != clean_before.members_hi || current_epoch != clean_before.formation_epoch || coordinator_node != clean_before.arbiter_node) return false; expected_gate_generation - = stage == CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_OPEN_APPLIED - ? generation - 1 - : generation; + = stage == CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_OPEN_APPLIED ? generation - 1 : generation; if (gate_before.record_generation != expected_gate_generation - || (clean_before.formation_marker_generation == 0 - && clean_before.arbiter_incarnation != 0) + || (clean_before.formation_marker_generation == 0 && clean_before.arbiter_incarnation != 0) || (clean_before.formation_marker_generation != 0 - && clean_before.arbiter_incarnation - != table_before.expected[0].admitted_incarnation)) + && clean_before.arbiter_incarnation != table_before.expected[0].admitted_incarnation)) return false; for (node = 0; node < 4; node++) { if (clean_before.admitted_incarnation[node] == 0 || clean_before.admitted_incarnation[node] - != table_before.expected[node].admitted_incarnation) + != table_before.expected[node].admitted_incarnation) return false; } local_capability_word = cluster_ic_local_capability_word(); - if ((local_capability_word - & CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS) + if ((local_capability_word & CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS) != CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS) return false; if (stage == CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_OPEN_APPLIED) { - if (!semantic_activation_ack_complete_image_current( - &table_before, members_lo, members_hi, current_epoch, - coordinator_node, cluster_node_id, local_capability_word)) + if (!semantic_activation_ack_complete_image_current(&table_before, members_lo, members_hi, + current_epoch, coordinator_node, + cluster_node_id, local_capability_word)) return false; - } else if (!semantic_activation_ack_member_prepared_image_current( - &table_before, NULL)) + } else if (!semantic_activation_ack_member_prepared_image_current(&table_before, NULL)) return false; return cluster_grd_recovery_state_value() == GRD_RECOVERY_IDLE - && cluster_reconfig_snapshot_initial_clean_formation( - &clean_after) - && semantic_activation_initial_clean_snapshot_equal( - &clean_before, &clean_after) + && cluster_reconfig_snapshot_initial_clean_formation(&clean_after) + && semantic_activation_initial_clean_snapshot_equal(&clean_before, &clean_after) && semantic_activation_initial_clean_pgrd_mirror(pgrd_after) && memcmp(pgrd_before, pgrd_after, sizeof(pgrd_before)) == 0 && semantic_activation_ack_table_snapshot(&table_after) - && memcmp(&table_before, &table_after, - sizeof(table_before)) == 0 - && semantic_activation_snapshot(&gate_after) - && gate_after.seq == gate_before.seq + && memcmp(&table_before, &table_after, sizeof(table_before)) == 0 + && semantic_activation_snapshot(&gate_after) && gate_after.seq == gate_before.seq && gate_after.active_bits == gate_before.active_bits - && gate_after.record_generation - == gate_before.record_generation + && gate_after.record_generation == gate_before.record_generation && gate_after.formation_epoch == gate_before.formation_epoch && gate_after.transition_closed == gate_before.transition_closed - && semantic_activation_ack_current_authority( - cluster_node_id, &members_lo, &members_hi, ¤t_epoch, - &coordinator_node) - && members_lo == clean_before.members_lo - && members_hi == clean_before.members_hi + && semantic_activation_ack_current_authority(cluster_node_id, &members_lo, &members_hi, + ¤t_epoch, &coordinator_node) + && members_lo == clean_before.members_lo && members_hi == clean_before.members_hi && current_epoch == clean_before.formation_epoch && coordinator_node == clean_before.arbiter_node && cluster_ic_local_capability_word() == local_capability_word; @@ -7531,9 +6538,8 @@ r4_initial_clean_stage_current(uint64 generation, static ClusterSemanticActivationResult r4_prepare_target(uint64 generation) { - return r4_initial_clean_stage_current( - generation, - CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_PREPARED) + return r4_initial_clean_stage_current(generation, + CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_PREPARED) ? CLUSTER_SEMANTIC_ACTIVATION_OK : CLUSTER_SEMANTIC_ACTIVATION_RF_DEFERRED; } @@ -7541,9 +6547,8 @@ r4_prepare_target(uint64 generation) static ClusterSemanticActivationResult r4_apply_target_closed(uint64 generation) { - return r4_initial_clean_stage_current( - generation, - CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_COMMIT_APPLIED) + return r4_initial_clean_stage_current(generation, + CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_COMMIT_APPLIED) ? CLUSTER_SEMANTIC_ACTIVATION_OK : CLUSTER_SEMANTIC_ACTIVATION_RF_DEFERRED; } @@ -7551,9 +6556,8 @@ r4_apply_target_closed(uint64 generation) static ClusterSemanticActivationResult r4_open_target_admission(uint64 generation) { - return r4_initial_clean_stage_current( - generation, - CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_OPEN_APPLIED) + return r4_initial_clean_stage_current(generation, + CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_OPEN_APPLIED) ? CLUSTER_SEMANTIC_ACTIVATION_OK : CLUSTER_SEMANTIC_ACTIVATION_RF_DEFERRED; } @@ -7567,7 +6571,7 @@ r4_open_target_admission(uint64 generation) static ClusterSemanticActivationResult bit22_stage_ok(uint64 record_generation) { - (void) record_generation; + (void)record_generation; return CLUSTER_SEMANTIC_ACTIVATION_OK; } @@ -7576,9 +6580,9 @@ bit22_stage_ok(uint64 record_generation) * revalidated as an independent freshness coordinate. Neither view grants * authority; every callback only verifies one exact local prerequisite. */ static bool -r11_resource_x_cutover_digest_exact( - uint64 generation, ClusterSemanticR11CutoverPhase expected_phase, - bool thawed, uint64 *digest_out) +r11_resource_x_cutover_digest_exact(uint64 generation, + ClusterSemanticR11CutoverPhase expected_phase, bool thawed, + uint64 *digest_out) { ClusterSemanticR11CutoverSnapshot after; ClusterSemanticR11CutoverSnapshot before; @@ -7588,23 +6592,17 @@ r11_resource_x_cutover_digest_exact( return false; *digest_out = 0; return generation != 0 && generation != UINT64_MAX - && cluster_semantic_activation_r11_cutover_snapshot(&before) - && before.phase == expected_phase - && before.record_generation == generation - && before.formation_epoch == cluster_epoch_get_current() - && cluster_pcm_lock_resource_x_cutover_current_proof_digest_exact( - thawed, &token, digest_out) - && token.old_formation != 0 - && token.old_formation != UINT64_MAX - && token.new_formation != 0 - && token.new_formation != UINT64_MAX - && token.old_formation != token.new_formation - && token.freeze_generation != 0 - && token.freeze_generation != UINT64_MAX - && token.reserved == 0 - && *digest_out != 0 - && cluster_semantic_activation_r11_cutover_snapshot(&after) - && memcmp(&before, &after, sizeof(before)) == 0; + && cluster_semantic_activation_r11_cutover_snapshot(&before) + && before.phase == expected_phase && before.record_generation == generation + && before.formation_epoch == cluster_epoch_get_current() + && cluster_pcm_lock_resource_x_cutover_current_proof_digest_exact(thawed, &token, + digest_out) + && token.old_formation != 0 && token.old_formation != UINT64_MAX + && token.new_formation != 0 && token.new_formation != UINT64_MAX + && token.old_formation != token.new_formation && token.freeze_generation != 0 + && token.freeze_generation != UINT64_MAX && token.reserved == 0 && *digest_out != 0 + && cluster_semantic_activation_r11_cutover_snapshot(&after) + && memcmp(&before, &after, sizeof(before)) == 0; } /* Bound OPEN and FROZEN gates use the ordinary exact snapshot. The narrow @@ -7614,8 +6612,8 @@ static bool r11_resource_x_gate_snapshot_exact(ResourceXGateSnapshot *gate) { return gate != NULL - && (cluster_pcm_lock_resource_x_gate_snapshot(gate) - || cluster_pcm_lock_resource_x_cutover_gate_snapshot_exact(gate)); + && (cluster_pcm_lock_resource_x_gate_snapshot(gate) + || cluster_pcm_lock_resource_x_cutover_gate_snapshot_exact(gate)); } static ClusterSemanticActivationResult @@ -7624,15 +6622,13 @@ r11_resource_x_frozen_stage(uint64 generation) uint64 digest; return r11_resource_x_cutover_digest_exact( - generation, CLUSTER_SEMANTIC_R11_CUTOVER_SOURCE_CLOSED, - false, &digest) - ? CLUSTER_SEMANTIC_ACTIVATION_OK - : CLUSTER_SEMANTIC_ACTIVATION_BAD_STATE; + generation, CLUSTER_SEMANTIC_R11_CUTOVER_SOURCE_CLOSED, false, &digest) + ? CLUSTER_SEMANTIC_ACTIVATION_OK + : CLUSTER_SEMANTIC_ACTIVATION_BAD_STATE; } static ClusterSemanticActivationResult -r11_resource_x_readiness(uint64 expected_generation, - ClusterSemanticActivationRefusal *refusal) +r11_resource_x_readiness(uint64 expected_generation, ClusterSemanticActivationRefusal *refusal) { ResourceXGateSnapshot gate; ResourceXWriterPath writer_path; @@ -7640,22 +6636,19 @@ r11_resource_x_readiness(uint64 expected_generation, uint64 r4_generation = 0; writer_path = cluster_resource_x_writer_path_snapshot(&r4_generation); - result = expected_generation != 0 - && expected_generation != UINT64_MAX - && writer_path == RESOURCE_X_WRITER_CLOSED - && r4_generation == expected_generation - && r11_resource_x_gate_snapshot_exact(&gate) - && gate.phase == RESOURCE_X_GATE_OPEN - && gate.freeze_generation == 0 && gate.reserved == 0 - && gate.formation != UINT64_MAX - ? CLUSTER_SEMANTIC_ACTIVATION_OK - : CLUSTER_SEMANTIC_ACTIVATION_BAD_STATE; - semantic_activation_set_refusal( - refusal, result, - result == CLUSTER_SEMANTIC_ACTIVATION_OK - ? 0 - : CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1, - expected_generation); + result = expected_generation != 0 && expected_generation != UINT64_MAX + && writer_path == RESOURCE_X_WRITER_CLOSED + && r4_generation == expected_generation + && r11_resource_x_gate_snapshot_exact(&gate) + && gate.phase == RESOURCE_X_GATE_OPEN && gate.freeze_generation == 0 + && gate.reserved == 0 && gate.formation != UINT64_MAX + ? CLUSTER_SEMANTIC_ACTIVATION_OK + : CLUSTER_SEMANTIC_ACTIVATION_BAD_STATE; + semantic_activation_set_refusal(refusal, result, + result == CLUSTER_SEMANTIC_ACTIVATION_OK + ? 0 + : CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1, + expected_generation); return result; } @@ -7670,17 +6663,14 @@ r11_resource_x_close_source(uint64 generation) || cutover.phase != CLUSTER_SEMANTIC_R11_CUTOVER_SOURCE_CLOSED || cutover.record_generation != generation || cutover.formation_epoch != cluster_epoch_get_current() - || !r11_resource_x_gate_snapshot_exact(&gate) - || gate.reserved != 0 - || (gate.phase != RESOURCE_X_GATE_OPEN - && gate.phase != RESOURCE_X_GATE_FROZEN)) + || !r11_resource_x_gate_snapshot_exact(&gate) || gate.reserved != 0 + || (gate.phase != RESOURCE_X_GATE_OPEN && gate.phase != RESOURCE_X_GATE_FROZEN)) return CLUSTER_SEMANTIC_ACTIVATION_BAD_STATE; return CLUSTER_SEMANTIC_ACTIVATION_OK; } static ClusterSemanticActivationResult -r11_resource_x_logical_zero(uint64 generation, - ClusterSemanticZeroProof *proof) +r11_resource_x_logical_zero(uint64 generation, ClusterSemanticZeroProof *proof) { ClusterSemanticR11CutoverSnapshot cutover; ResourceXGateSnapshot gate; @@ -7694,13 +6684,10 @@ r11_resource_x_logical_zero(uint64 generation, || cutover.record_generation != generation || cutover.formation_epoch != cluster_epoch_get_current()) return CLUSTER_SEMANTIC_ACTIVATION_BAD_STATE; - if (!r11_resource_x_cutover_digest_exact( - generation, CLUSTER_SEMANTIC_R11_CUTOVER_SOURCE_CLOSED, - false, &digest)) { - if (!r11_resource_x_gate_snapshot_exact(&gate) - || gate.reserved != 0 - || (gate.phase != RESOURCE_X_GATE_OPEN - && gate.phase != RESOURCE_X_GATE_FROZEN)) + if (!r11_resource_x_cutover_digest_exact(generation, CLUSTER_SEMANTIC_R11_CUTOVER_SOURCE_CLOSED, + false, &digest)) { + if (!r11_resource_x_gate_snapshot_exact(&gate) || gate.reserved != 0 + || (gate.phase != RESOURCE_X_GATE_OPEN && gate.phase != RESOURCE_X_GATE_FROZEN)) return CLUSTER_SEMANTIC_ACTIVATION_BAD_STATE; return CLUSTER_SEMANTIC_ACTIVATION_DEBT_NONZERO; } @@ -7711,8 +6698,7 @@ r11_resource_x_logical_zero(uint64 generation, } static ClusterSemanticActivationResult -r11_resource_x_transport_zero(uint64 generation, - ClusterSemanticZeroProof *proof) +r11_resource_x_transport_zero(uint64 generation, ClusterSemanticZeroProof *proof) { return r11_resource_x_logical_zero(generation, proof); } @@ -7732,7 +6718,7 @@ r11_resource_x_apply_target_closed(uint64 generation) static ClusterSemanticActivationResult r11_resource_x_revert_source_closed(uint64 generation) { - (void) generation; + (void)generation; return CLUSTER_SEMANTIC_ACTIVATION_BAD_STATE; } @@ -7742,11 +6728,9 @@ r11_resource_x_open_target(uint64 generation) uint64 digest; return r11_resource_x_cutover_digest_exact( - generation, - CLUSTER_SEMANTIC_R11_CUTOVER_DURABLE_OPEN_PENDING_LOCAL, - true, &digest) - ? CLUSTER_SEMANTIC_ACTIVATION_OK - : CLUSTER_SEMANTIC_ACTIVATION_BAD_STATE; + generation, CLUSTER_SEMANTIC_R11_CUTOVER_DURABLE_OPEN_PENDING_LOCAL, true, &digest) + ? CLUSTER_SEMANTIC_ACTIVATION_OK + : CLUSTER_SEMANTIC_ACTIVATION_BAD_STATE; } static const ClusterSemanticActivationDescriptor r4_descriptor = { @@ -7768,8 +6752,8 @@ static const ClusterSemanticActivationDescriptor r4_descriptor = { static const ClusterSemanticActivationDescriptor r11_resource_x_descriptor = { .name = "R11_RESOURCE_X_D5_CUTOVER_V1", .feature_bit = CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1, - .required_hello_caps = PGRAC_IC_HELLO_CAP_SEMANTIC_ACTIVATION_V1 - | PGRAC_IC_HELLO_CAP_GCS_RESOURCE_X_CONVERT_V1, + .required_hello_caps + = PGRAC_IC_HELLO_CAP_SEMANTIC_ACTIVATION_V1 | PGRAC_IC_HELLO_CAP_GCS_RESOURCE_X_CONVERT_V1, .required_active_bits = 0, .source_available = CLUSTER_SEMANTIC_R11_RESOURCE_X_SOURCE_AVAILABLE, .pre_prepare_readiness = r11_resource_x_readiness, @@ -7782,33 +6766,30 @@ static const ClusterSemanticActivationDescriptor r11_resource_x_descriptor = { .open_target_admission = r11_resource_x_open_target, }; -StaticAssertDecl( - (CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1 - & CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1) == 0, - "R11 Resource-X cutover feature bit must be unique"); -StaticAssertDecl(PGRAC_IC_HELLO_CAP_GCS_RESOURCE_X_CONVERT_V1 - == UINT32_C(0x00020000), - "R11 Resource-X cutover must retain the R10 capability value"); +StaticAssertDecl((CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1 + & CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1) + == 0, + "R11 Resource-X cutover feature bit must be unique"); +StaticAssertDecl(PGRAC_IC_HELLO_CAP_GCS_RESOURCE_X_CONVERT_V1 == UINT32_C(0x00020000), + "R11 Resource-X cutover must retain the R10 capability value"); /* Immutable after postmaster module registration. R4 occupies bit zero in * every build; later feature modules register their compile-time descriptor * during the same shared-memory registration window. */ -static const ClusterSemanticActivationDescriptor - *SemanticActivationDescriptors[64] = { - [0] = &r4_descriptor, - [10] = &r11_resource_x_descriptor, - }; +static const ClusterSemanticActivationDescriptor *SemanticActivationDescriptors[64] = { + [0] = &r4_descriptor, + [10] = &r11_resource_x_descriptor, +}; /* One durable R4 round may add exactly one compiled feature. R4 itself is * the initial 0->bit0 round and remains present as the carrier for every * later round. The descriptor and its HELLO requirements are derived from * the immutable registry; the helper owns no activation state. */ static bool -semantic_activation_round_descriptor( - uint64 source_feature_bitmap, uint64 target_feature_bitmap, - uint64 rollback_feature_bitmap, - const ClusterSemanticActivationDescriptor **descriptor_out, - uint32 *required_caps_out) +semantic_activation_round_descriptor(uint64 source_feature_bitmap, uint64 target_feature_bitmap, + uint64 rollback_feature_bitmap, + const ClusterSemanticActivationDescriptor **descriptor_out, + uint32 *required_caps_out) { const ClusterSemanticActivationDescriptor *descriptor; uint64 added; @@ -7819,27 +6800,24 @@ semantic_activation_round_descriptor( *descriptor_out = NULL; *required_caps_out = 0; compiled = cluster_semantic_activation_compiled_feature_bitmap(); - if (rollback_feature_bitmap != 0 - || (source_feature_bitmap & ~compiled) != 0 + if (rollback_feature_bitmap != 0 || (source_feature_bitmap & ~compiled) != 0 || (target_feature_bitmap & ~compiled) != 0 - || (target_feature_bitmap & source_feature_bitmap) - != source_feature_bitmap) + || (target_feature_bitmap & source_feature_bitmap) != source_feature_bitmap) return false; added = target_feature_bitmap & ~source_feature_bitmap; if (added == 0 || (added & (added - 1)) != 0) return false; if (added != CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1 - && (source_feature_bitmap - & CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1) == 0) + && (source_feature_bitmap & CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1) == 0) return false; descriptor = cluster_semantic_activation_descriptor(added); if (descriptor == NULL || descriptor->feature_bit != added || (descriptor->required_active_bits & source_feature_bitmap) - != descriptor->required_active_bits) + != descriptor->required_active_bits) return false; *descriptor_out = descriptor; - *required_caps_out = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS - | descriptor->required_hello_caps; + *required_caps_out + = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS | descriptor->required_hello_caps; return true; } @@ -7847,23 +6825,23 @@ semantic_activation_round_descriptor( * contract byte-for-byte; ordinary semantic-activation rounds derive their * exact capability set from the one feature added by the compiled registry. */ static bool -semantic_activation_ack_round_required_caps( - uint64 source_feature_bitmap, uint64 target_feature_bitmap, - uint64 rollback_feature_bitmap, uint32 *required_caps_out) +semantic_activation_ack_round_required_caps(uint64 source_feature_bitmap, + uint64 target_feature_bitmap, + uint64 rollback_feature_bitmap, + uint32 *required_caps_out) { const ClusterSemanticActivationDescriptor *descriptor; if (required_caps_out == NULL) return false; *required_caps_out = 0; - if ((target_feature_bitmap - & PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1) != 0) { + if ((target_feature_bitmap & PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1) != 0) { *required_caps_out = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS; return true; } - return semantic_activation_round_descriptor( - source_feature_bitmap, target_feature_bitmap, - rollback_feature_bitmap, &descriptor, required_caps_out); + return semantic_activation_round_descriptor(source_feature_bitmap, target_feature_bitmap, + rollback_feature_bitmap, &descriptor, + required_caps_out); } /* @@ -7878,12 +6856,10 @@ semantic_activation_ack_round_required_caps( */ static bool semantic_activation_ack_member_open_applied_image_current( - const ClusterSemanticActivationAckTableV1 *image, - SemanticActivationAckTuple *out_self) + const ClusterSemanticActivationAckTableV1 *image, SemanticActivationAckTuple *out_self) { return semantic_activation_ack_member_bit22_stage_image_current( - image, CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_OPEN_APPLIED, - out_self); + image, CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_OPEN_APPLIED, out_self); } /* RF-ROOT P9 verification (implementation): stage-parameterized bit22 member image @@ -7891,8 +6867,8 @@ semantic_activation_ack_member_open_applied_image_current( * stages share the same shape (bit22 target, parameterized member set). */ static bool semantic_activation_ack_member_bit22_stage_image_current( - const ClusterSemanticActivationAckTableV1 *image, - uint32 stage, SemanticActivationAckTuple *out_self) + const ClusterSemanticActivationAckTableV1 *image, uint32 stage, + SemanticActivationAckTuple *out_self) { SemanticActivationAckTuple self; uint64 current_members_lo; @@ -7901,31 +6877,28 @@ semantic_activation_ack_member_bit22_stage_image_current( uint32 local_capability_word; int32 current_coordinator_node; - if (image == NULL || out_self == NULL - || cluster_node_id < 0 || cluster_node_id >= CLUSTER_MAX_NODES - || image->stage != stage - || image->coordinator_node == (uint32)cluster_node_id - || image->round_nonce == 0 + if (image == NULL || out_self == NULL || cluster_node_id < 0 + || cluster_node_id >= CLUSTER_MAX_NODES || image->stage != stage + || image->coordinator_node == (uint32)cluster_node_id || image->round_nonce == 0 || image->record_generation == 0 - || (image->target_feature_bitmap - & PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1) == 0 + || (image->target_feature_bitmap & PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1) + == 0 || (image->flags & ~(CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID - | CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE)) != 0 - || (image->flags - & CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID) == 0 + | CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE)) + != 0 + || (image->flags & CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID) == 0 || image->expected_members_lo == 0 || image->expected_members_hi != 0 /* members < 64 (2-node t243) */ - || (image->observed_members_lo - & ~image->expected_members_lo) != 0 + || (image->observed_members_lo & ~image->expected_members_lo) != 0 || image->observed_members_hi != 0 || semantic_activation_ack_local_pending_send.pending_members_lo != 0 || semantic_activation_ack_local_pending_send.pending_members_hi != 0 || semantic_activation_ack_local_pending_send.invalidated) return false; - if (!semantic_activation_ack_current_authority( - cluster_node_id, ¤t_members_lo, ¤t_members_hi, - ¤t_epoch, ¤t_coordinator_node) + if (!semantic_activation_ack_current_authority(cluster_node_id, ¤t_members_lo, + ¤t_members_hi, ¤t_epoch, + ¤t_coordinator_node) || current_members_lo != image->expected_members_lo || current_members_hi != image->expected_members_hi || current_epoch != image->transition_epoch @@ -7933,14 +6906,11 @@ semantic_activation_ack_member_bit22_stage_image_current( return false; local_capability_word = cluster_ic_local_capability_word(); if (!semantic_activation_ack_expected_image_current( - image, current_members_lo, current_members_hi, current_epoch, - current_coordinator_node, cluster_node_id, - local_capability_word) - || !semantic_activation_ack_self_tuple( - cluster_node_id, local_capability_word, current_epoch, - image->record_generation, &self) - || !semantic_activation_ack_matches( - &image->expected[cluster_node_id], &self)) + image, current_members_lo, current_members_hi, current_epoch, current_coordinator_node, + cluster_node_id, local_capability_word) + || !semantic_activation_ack_self_tuple(cluster_node_id, local_capability_word, + current_epoch, image->record_generation, &self) + || !semantic_activation_ack_matches(&image->expected[cluster_node_id], &self)) return false; *out_self = self; return true; @@ -7948,8 +6918,7 @@ semantic_activation_ack_member_bit22_stage_image_current( static bool semantic_activation_ack_lmon_finish_member_open_applied( - const ClusterSemanticActivationAckTableV1 *before, - bool latch_applied) + const ClusterSemanticActivationAckTableV1 *before, bool latch_applied) { ClusterSemanticActivationAckTableV1 after; ClusterSemanticActivationAckTableV1 next; @@ -7964,12 +6933,10 @@ semantic_activation_ack_lmon_finish_member_open_applied( * COMPLETE and the coordinator's deadline fails the cutover. */ if (!latch_applied) return true; - if (!semantic_activation_ack_member_open_applied_image_current( - before, &self) + if (!semantic_activation_ack_member_open_applied_image_current(before, &self) || !semantic_activation_ack_table_snapshot(&after) || memcmp(before, &after, sizeof(after)) != 0 - || !semantic_activation_ack_member_open_applied_image_current( - &after, &self)) + || !semantic_activation_ack_member_open_applied_image_current(&after, &self)) return true; self_bit = UINT64_C(1) << cluster_node_id; @@ -7992,15 +6959,14 @@ semantic_activation_ack_lmon_finish_member_open_applied( request.admitted_members_hi = after.expected_members_hi; request.capability_sample_digest = after.capability_sample_digest; memset(&pending, 0, sizeof(pending)); - if (!semantic_activation_ack_pending_send_begin_positive( - &pending, &request, cluster_node_id, &self)) + if (!semantic_activation_ack_pending_send_begin_positive(&pending, &request, cluster_node_id, + &self)) return true; next = after; next.observed_members_lo |= self_bit; next.observed[cluster_node_id] = self; - all_observed - = next.observed_members_lo == next.expected_members_lo; + all_observed = next.observed_members_lo == next.expected_members_lo; next.flags = CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID; if (all_observed) next.flags |= CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE; @@ -8019,22 +6985,19 @@ semantic_activation_ack_lmon_progress_member_open_applied( uint64 self_bit; bool latch_applied; - if (before == NULL || before->stage - != CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_OPEN_APPLIED) + if (before == NULL || before->stage != CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_OPEN_APPLIED) return false; if (cluster_node_id == (int32)before->coordinator_node) - return false; /* the coordinator drives, it does not apply */ - if (!semantic_activation_ack_member_open_applied_image_current( - before, &self)) - return true; /* image not current: retry on the next tick */ + return false; /* the coordinator drives, it does not apply */ + if (!semantic_activation_ack_member_open_applied_image_current(before, &self)) + return true; /* image not current: retry on the next tick */ self_bit = UINT64_C(1) << cluster_node_id; if ((before->observed_members_lo & self_bit) != 0) - return true; /* idempotent: this member already applied */ + return true; /* idempotent: this member already applied */ - latch_applied = cluster_r4_bit22_cutover_latch_apply( - before->transition_epoch, before->record_generation); - return semantic_activation_ack_lmon_finish_member_open_applied( - before, latch_applied); + latch_applied + = cluster_r4_bit22_cutover_latch_apply(before->transition_epoch, before->record_generation); + return semantic_activation_ack_lmon_finish_member_open_applied(before, latch_applied); } /* @@ -8058,8 +7021,7 @@ semantic_activation_ack_lmon_progress_member_barrier_bit22( bool all_observed; int i; - if (before == NULL || before->stage - != CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_BARRIER) + if (before == NULL || before->stage != CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_BARRIER) return false; if (cluster_node_id == (int32)before->coordinator_node) return false; @@ -8068,22 +7030,19 @@ semantic_activation_ack_lmon_progress_member_barrier_bit22( return true; self_bit = UINT64_C(1) << cluster_node_id; if ((before->observed_members_lo & self_bit) != 0) - return true; /* idempotent */ + return true; /* idempotent */ /* Freeze the local source for this exact round, then drain in-flight * writers (bounded). */ - if (!cluster_r4_bit22_source_close_begin( - before->transition_epoch, before->record_generation)) - return true; /* fail-closed: retry on the next tick */ + if (!cluster_r4_bit22_source_close_begin(before->transition_epoch, before->record_generation)) + return true; /* fail-closed: retry on the next tick */ for (i = 0; i < 1000; i++) { - if (pg_atomic_read_u32( - &SemanticActivationBit22SourceClose->writer_count) == 0) + if (pg_atomic_read_u32(&SemanticActivationBit22SourceClose->writer_count) == 0) break; pg_usleep(5000L); /* 5 ms; up to ~5 s */ } - if (pg_atomic_read_u32( - &SemanticActivationBit22SourceClose->writer_count) != 0) - return true; /* writers still draining: retry */ + if (pg_atomic_read_u32(&SemanticActivationBit22SourceClose->writer_count) != 0) + return true; /* writers still draining: retry */ /* RF-ROOT P9 verification (cold-formation): this member's source is now * frozen — publish the closed-source snapshot (transition_closed=1 at @@ -8096,9 +7055,9 @@ semantic_activation_ack_lmon_progress_member_barrier_bit22( SemanticActivationAdmissionSnapshot snap; if (!semantic_activation_snapshot(&snap) - || !semantic_activation_lmon_publish_gate( - &snap, before->source_feature_bitmap, - before->record_generation, before->transition_epoch, true)) + || !semantic_activation_lmon_publish_gate(&snap, before->source_feature_bitmap, + before->record_generation, + before->transition_epoch, true)) return true; } @@ -8124,15 +7083,14 @@ semantic_activation_ack_lmon_progress_member_barrier_bit22( request.admitted_members_hi = after.expected_members_hi; request.capability_sample_digest = after.capability_sample_digest; memset(&pending, 0, sizeof(pending)); - if (!semantic_activation_ack_pending_send_begin_positive( - &pending, &request, cluster_node_id, &self)) + if (!semantic_activation_ack_pending_send_begin_positive(&pending, &request, cluster_node_id, + &self)) return true; next = after; next.observed_members_lo |= self_bit; next.observed[cluster_node_id] = self; - all_observed - = next.observed_members_lo == next.expected_members_lo; + all_observed = next.observed_members_lo == next.expected_members_lo; next.flags = CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID; if (all_observed) next.flags |= CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE; @@ -8166,27 +7124,23 @@ semantic_activation_ack_lmon_progress_member_commit_applied_bit22( uint64 self_bit; bool all_observed; - if (before == NULL || before->stage - != CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_COMMIT_APPLIED) + if (before == NULL || before->stage != CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_COMMIT_APPLIED) return false; if (cluster_node_id == (int32)before->coordinator_node) - return false; /* the coordinator drives, it does not apply */ + return false; /* the coordinator drives, it does not apply */ if (!semantic_activation_ack_member_bit22_stage_image_current( - before, CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_COMMIT_APPLIED, - &self)) { - ereport(LOG, - (errmsg("bit22 cutover (node %d): COMMIT_APPLIED stage image " - "not current (stage=%u flags=0x%x gen=%llu observed=%llx) " - "— retrying", - cluster_node_id, (unsigned) before->stage, - (unsigned) before->flags, - (unsigned long long) before->record_generation, - (unsigned long long) before->observed_members_lo))); - return true; /* image not current: retry on the next tick */ + before, CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_COMMIT_APPLIED, &self)) { + ereport(LOG, (errmsg("bit22 cutover (node %d): COMMIT_APPLIED stage image " + "not current (stage=%u flags=0x%x gen=%llu observed=%llx) " + "— retrying", + cluster_node_id, (unsigned)before->stage, (unsigned)before->flags, + (unsigned long long)before->record_generation, + (unsigned long long)before->observed_members_lo))); + return true; /* image not current: retry on the next tick */ } self_bit = UINT64_C(1) << cluster_node_id; if ((before->observed_members_lo & self_bit) != 0) - return true; /* idempotent: this member already applied */ + return true; /* idempotent: this member already applied */ /* The ACTIVE canonical root must be bound to this exact round. The * seam (full round + sha) is coordinator-ONLY shmem — other NODES @@ -8194,24 +7148,22 @@ semantic_activation_ack_lmon_progress_member_commit_applied_bit22( * it holds (epoch / prepare-generation / bitmaps) plus the non-zero * round sha the coordinator wrote under the create/activate proofs. */ root_result = cluster_control_root_bootstrap_validate_active_round_fields( - before->transition_epoch, before->record_generation - 1, - before->source_feature_bitmap, before->target_feature_bitmap); + before->transition_epoch, before->record_generation - 1, before->source_feature_bitmap, + before->target_feature_bitmap); if (root_result != CLUSTER_CONTROL_ROOT_OK_PRIMARY && root_result != CLUSTER_CONTROL_ROOT_OK_PRIMARY_DEGRADED) { - ereport(LOG, - (errmsg("bit22 cutover (node %d): ACTIVE root field binding " - "refused (result %d, gen %llu) — no ACK until the " - "root verifies", - cluster_node_id, (int) root_result, - (unsigned long long) before->record_generation))); - return true; /* fail-closed: no ACK until the root verifies */ + ereport(LOG, (errmsg("bit22 cutover (node %d): ACTIVE root field binding " + "refused (result %d, gen %llu) — no ACK until the " + "root verifies", + cluster_node_id, (int)root_result, + (unsigned long long)before->record_generation))); + return true; /* fail-closed: no ACK until the root verifies */ } if (!semantic_activation_ack_table_snapshot(&after) || memcmp(before, &after, sizeof(after)) != 0 || !semantic_activation_ack_member_bit22_stage_image_current( - &after, CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_COMMIT_APPLIED, - &self)) + &after, CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_COMMIT_APPLIED, &self)) return true; memset(&request, 0, sizeof(request)); @@ -8230,15 +7182,14 @@ semantic_activation_ack_lmon_progress_member_commit_applied_bit22( request.admitted_members_hi = after.expected_members_hi; request.capability_sample_digest = after.capability_sample_digest; memset(&pending, 0, sizeof(pending)); - if (!semantic_activation_ack_pending_send_begin_positive( - &pending, &request, cluster_node_id, &self)) + if (!semantic_activation_ack_pending_send_begin_positive(&pending, &request, cluster_node_id, + &self)) return true; next = after; next.observed_members_lo |= self_bit; next.observed[cluster_node_id] = self; - all_observed - = next.observed_members_lo == next.expected_members_lo; + all_observed = next.observed_members_lo == next.expected_members_lo; next.flags = CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID; if (all_observed) next.flags |= CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE; @@ -8273,44 +7224,34 @@ semantic_activation_ack_lmon_progress_member_commit_applied( bool all_observed; int node; - if (before == NULL || before->stage - != CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_COMMIT_APPLIED) + if (before == NULL || before->stage != CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_COMMIT_APPLIED) return false; /* The approved happy path is the exact four-member formation. Any * mismatch retains closed admission and consumes no legacy sync path. */ - if (cluster_node_id <= 0 || cluster_node_id >= 4 - || before->coordinator_node != UINT32_C(0) - || before->expected_members_lo != UINT64_C(0x0f) - || before->expected_members_hi != 0 + if (cluster_node_id <= 0 || cluster_node_id >= 4 || before->coordinator_node != UINT32_C(0) + || before->expected_members_lo != UINT64_C(0x0f) || before->expected_members_hi != 0 || before->round_nonce == 0 || before->record_generation == 0 || !semantic_activation_round_descriptor( - before->source_feature_bitmap, - before->target_feature_bitmap, - before->rollback_feature_bitmap, &round_descriptor, - &required_caps) + before->source_feature_bitmap, before->target_feature_bitmap, + before->rollback_feature_bitmap, &round_descriptor, &required_caps) || before->capability_sample_digest == 0 || (before->flags & ~(CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID - | CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE)) != 0 - || (before->flags - & CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID) == 0 - || (before->observed_members_lo - & ~before->expected_members_lo) != 0 + | CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE)) + != 0 + || (before->flags & CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID) == 0 + || (before->observed_members_lo & ~before->expected_members_lo) != 0 || before->observed_members_hi != 0 || semantic_activation_ack_local_pending_send.pending_members_lo != 0 || semantic_activation_ack_local_pending_send.pending_members_hi != 0 || semantic_activation_ack_local_pending_send.invalidated) return true; - all_observed - = before->observed_members_lo == before->expected_members_lo; - if (all_observed - != ((before->flags - & CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE) != 0)) + all_observed = before->observed_members_lo == before->expected_members_lo; + if (all_observed != ((before->flags & CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE) != 0)) return true; callback_generation = before->record_generation; - if (round_descriptor->feature_bit - == CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1) { + if (round_descriptor->feature_bit == CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1) { if (callback_generation <= 1) return true; callback_generation--; @@ -8318,68 +7259,54 @@ semantic_activation_ack_lmon_progress_member_commit_applied( for (node = 0; node < CLUSTER_MAX_NODES; node++) { bool member = node < 4; bool observed - = node < 64 - ? (before->observed_members_lo - & (UINT64_C(1) << node)) != 0 - : false; + = node < 64 ? (before->observed_members_lo & (UINT64_C(1) << node)) != 0 : false; if (!member) { - if (!semantic_activation_bytes_are_zero( - (const uint8 *)&before->expected[node], - sizeof(before->expected[node])) - || !semantic_activation_bytes_are_zero( - (const uint8 *)&before->observed[node], - sizeof(before->observed[node]))) + if (!semantic_activation_bytes_are_zero((const uint8 *)&before->expected[node], + sizeof(before->expected[node])) + || !semantic_activation_bytes_are_zero((const uint8 *)&before->observed[node], + sizeof(before->observed[node]))) return true; continue; } if (observed) { - if (!semantic_activation_ack_matches( - &before->observed[node], &before->expected[node])) + if (!semantic_activation_ack_matches(&before->observed[node], &before->expected[node])) return true; - } else if (!semantic_activation_bytes_are_zero( - (const uint8 *)&before->observed[node], - sizeof(before->observed[node]))) + } else if (!semantic_activation_bytes_are_zero((const uint8 *)&before->observed[node], + sizeof(before->observed[node]))) return true; } - if (!semantic_activation_ack_current_authority( - cluster_node_id, ¤t_members_lo, ¤t_members_hi, - ¤t_epoch, ¤t_coordinator_node) + if (!semantic_activation_ack_current_authority(cluster_node_id, ¤t_members_lo, + ¤t_members_hi, ¤t_epoch, + ¤t_coordinator_node) || current_members_lo != before->expected_members_lo || current_members_hi != before->expected_members_hi || current_epoch != before->transition_epoch || current_coordinator_node != (int32)before->coordinator_node - || !semantic_activation_snapshot(&snapshot) - || !snapshot.transition_closed + || !semantic_activation_snapshot(&snapshot) || !snapshot.transition_closed || snapshot.active_bits != before->source_feature_bitmap || snapshot.formation_epoch != before->transition_epoch) return true; local_capability_word = cluster_ic_local_capability_word(); if ((local_capability_word & required_caps) != required_caps || !semantic_activation_ack_expected_image_current( - before, current_members_lo, current_members_hi, current_epoch, - current_coordinator_node, cluster_node_id, - local_capability_word) - || !semantic_activation_ack_self_tuple( - cluster_node_id, local_capability_word, current_epoch, - before->record_generation, &self) - || !semantic_activation_ack_matches( - &before->expected[cluster_node_id], &self)) + before, current_members_lo, current_members_hi, current_epoch, current_coordinator_node, + cluster_node_id, local_capability_word) + || !semantic_activation_ack_self_tuple(cluster_node_id, local_capability_word, + current_epoch, before->record_generation, &self) + || !semantic_activation_ack_matches(&before->expected[cluster_node_id], &self)) return true; self_bit = UINT64_C(1) << cluster_node_id; if ((before->observed_members_lo & self_bit) != 0) return snapshot.record_generation == before->record_generation - && semantic_activation_ack_matches( - &before->observed[cluster_node_id], &self); + && semantic_activation_ack_matches(&before->observed[cluster_node_id], &self); if (snapshot.record_generation == before->record_generation) { if (semantic_activation_lmon_record_read_seq != 0) return true; - result = round_descriptor->apply_target_closed( - callback_generation); - return semantic_activation_ack_lmon_finish_member_prepared( - before, result); + result = round_descriptor->apply_target_closed(callback_generation); + return semantic_activation_ack_lmon_finish_member_prepared(before, result); } if (snapshot.record_generation == UINT64_MAX || snapshot.record_generation + 1 != before->record_generation) @@ -8394,36 +7321,28 @@ semantic_activation_ack_lmon_progress_member_commit_applied( semantic_activation_lmon_record_read_seq, &completion)) return true; semantic_activation_lmon_record_read_seq = 0; - if (completion.result != CLUSTER_SEMANTIC_ACTIVATION_OK - || completion.implicit_open - || !cluster_semantic_activation_record_decode( - completion.selected_bytes, &commit, NULL) + if (completion.result != CLUSTER_SEMANTIC_ACTIVATION_OK || completion.implicit_open + || !cluster_semantic_activation_record_decode(completion.selected_bytes, &commit, NULL) || commit.phase != CLUSTER_SEMANTIC_PHASE_COMMIT || commit.record_generation != before->record_generation || commit.transition_epoch != before->transition_epoch || commit.coordinator_node != before->coordinator_node || commit.coordinator_incarnation - != before->expected[before->coordinator_node] - .admitted_incarnation + != before->expected[before->coordinator_node].admitted_incarnation || commit.admitted_members_lo != before->expected_members_lo || commit.admitted_members_hi != before->expected_members_hi - || commit.source_feature_bitmap - != before->source_feature_bitmap - || commit.target_feature_bitmap - != before->target_feature_bitmap - || commit.rollback_feature_bitmap - != before->rollback_feature_bitmap - || commit.capability_sample_digest - != before->capability_sample_digest - || !semantic_activation_snapshot(¤t_snapshot) - || current_snapshot.seq != snapshot.seq + || commit.source_feature_bitmap != before->source_feature_bitmap + || commit.target_feature_bitmap != before->target_feature_bitmap + || commit.rollback_feature_bitmap != before->rollback_feature_bitmap + || commit.capability_sample_digest != before->capability_sample_digest + || !semantic_activation_snapshot(¤t_snapshot) || current_snapshot.seq != snapshot.seq || current_snapshot.active_bits != snapshot.active_bits || current_snapshot.record_generation != snapshot.record_generation || current_snapshot.formation_epoch != snapshot.formation_epoch || current_snapshot.transition_closed != snapshot.transition_closed - || !semantic_activation_ack_current_authority( - cluster_node_id, ¤t_members_lo, ¤t_members_hi, - ¤t_epoch, ¤t_coordinator_node) + || !semantic_activation_ack_current_authority(cluster_node_id, ¤t_members_lo, + ¤t_members_hi, ¤t_epoch, + ¤t_coordinator_node) || current_members_lo != before->expected_members_lo || current_members_hi != before->expected_members_hi || current_epoch != before->transition_epoch @@ -8432,17 +7351,15 @@ semantic_activation_ack_lmon_progress_member_commit_applied( || !semantic_activation_ack_table_snapshot(&after) || memcmp(before, &after, sizeof(after)) != 0 || !semantic_activation_ack_expected_image_current( - &after, current_members_lo, current_members_hi, - current_epoch, current_coordinator_node, cluster_node_id, - local_capability_word) - || !semantic_activation_lmon_publish_gate( - ¤t_snapshot, commit.source_feature_bitmap, - commit.record_generation, commit.transition_epoch, true)) + &after, current_members_lo, current_members_hi, current_epoch, current_coordinator_node, + cluster_node_id, local_capability_word) + || !semantic_activation_lmon_publish_gate(¤t_snapshot, commit.source_feature_bitmap, + commit.record_generation, commit.transition_epoch, + true)) return true; result = round_descriptor->apply_target_closed(callback_generation); - return semantic_activation_ack_lmon_finish_member_prepared( - &after, result); + return semantic_activation_ack_lmon_finish_member_prepared(&after, result); } /* A descriptor-backed round opens only after this member has read the exact @@ -8478,42 +7395,32 @@ semantic_activation_ack_lmon_progress_member_open_applied_round( bool post_open; int node; - if (before == NULL || before->stage - != CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_OPEN_APPLIED) + if (before == NULL || before->stage != CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_OPEN_APPLIED) return false; - if (cluster_node_id <= 0 || cluster_node_id >= 4 - || before->coordinator_node != UINT32_C(0) - || before->expected_members_lo != UINT64_C(0x0f) - || before->expected_members_hi != 0 + if (cluster_node_id <= 0 || cluster_node_id >= 4 || before->coordinator_node != UINT32_C(0) + || before->expected_members_lo != UINT64_C(0x0f) || before->expected_members_hi != 0 || before->round_nonce == 0 || before->record_generation == 0 || !semantic_activation_round_descriptor( - before->source_feature_bitmap, - before->target_feature_bitmap, - before->rollback_feature_bitmap, &round_descriptor, - &required_caps) + before->source_feature_bitmap, before->target_feature_bitmap, + before->rollback_feature_bitmap, &round_descriptor, &required_caps) || before->capability_sample_digest == 0 || (before->flags & ~(CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID - | CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE)) != 0 - || (before->flags - & CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID) == 0 - || (before->observed_members_lo - & ~before->expected_members_lo) != 0 + | CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE)) + != 0 + || (before->flags & CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID) == 0 + || (before->observed_members_lo & ~before->expected_members_lo) != 0 || before->observed_members_hi != 0 || semantic_activation_ack_local_pending_send.pending_members_lo != 0 || semantic_activation_ack_local_pending_send.pending_members_hi != 0 || semantic_activation_ack_local_pending_send.invalidated) return true; - all_observed - = before->observed_members_lo == before->expected_members_lo; - if (all_observed - != ((before->flags - & CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE) != 0)) + all_observed = before->observed_members_lo == before->expected_members_lo; + if (all_observed != ((before->flags & CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE) != 0)) return true; callback_generation = before->record_generation; - if (round_descriptor->feature_bit - == CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1) { + if (round_descriptor->feature_bit == CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1) { if (callback_generation <= 2) return true; callback_generation -= 2; @@ -8521,34 +7428,27 @@ semantic_activation_ack_lmon_progress_member_open_applied_round( for (node = 0; node < CLUSTER_MAX_NODES; node++) { bool member = node < 4; bool observed - = node < 64 - ? (before->observed_members_lo - & (UINT64_C(1) << node)) != 0 - : false; + = node < 64 ? (before->observed_members_lo & (UINT64_C(1) << node)) != 0 : false; if (!member) { - if (!semantic_activation_bytes_are_zero( - (const uint8 *)&before->expected[node], - sizeof(before->expected[node])) - || !semantic_activation_bytes_are_zero( - (const uint8 *)&before->observed[node], - sizeof(before->observed[node]))) + if (!semantic_activation_bytes_are_zero((const uint8 *)&before->expected[node], + sizeof(before->expected[node])) + || !semantic_activation_bytes_are_zero((const uint8 *)&before->observed[node], + sizeof(before->observed[node]))) return true; continue; } if (observed) { - if (!semantic_activation_ack_matches( - &before->observed[node], &before->expected[node])) + if (!semantic_activation_ack_matches(&before->observed[node], &before->expected[node])) return true; - } else if (!semantic_activation_bytes_are_zero( - (const uint8 *)&before->observed[node], - sizeof(before->observed[node]))) + } else if (!semantic_activation_bytes_are_zero((const uint8 *)&before->observed[node], + sizeof(before->observed[node]))) return true; } - if (!semantic_activation_ack_current_authority( - cluster_node_id, ¤t_members_lo, ¤t_members_hi, - ¤t_epoch, ¤t_coordinator_node) + if (!semantic_activation_ack_current_authority(cluster_node_id, ¤t_members_lo, + ¤t_members_hi, ¤t_epoch, + ¤t_coordinator_node) || current_members_lo != before->expected_members_lo || current_members_hi != before->expected_members_hi || current_epoch != before->transition_epoch @@ -8558,28 +7458,21 @@ semantic_activation_ack_lmon_progress_member_open_applied_round( local_capability_word = cluster_ic_local_capability_word(); if ((local_capability_word & required_caps) != required_caps || !semantic_activation_ack_expected_image_current( - before, current_members_lo, current_members_hi, current_epoch, - current_coordinator_node, cluster_node_id, - local_capability_word) - || !semantic_activation_ack_self_tuple( - cluster_node_id, local_capability_word, current_epoch, - before->record_generation, &self) - || !semantic_activation_ack_matches( - &before->expected[cluster_node_id], &self)) + before, current_members_lo, current_members_hi, current_epoch, current_coordinator_node, + cluster_node_id, local_capability_word) + || !semantic_activation_ack_self_tuple(cluster_node_id, local_capability_word, + current_epoch, before->record_generation, &self) + || !semantic_activation_ack_matches(&before->expected[cluster_node_id], &self)) return true; self_bit = UINT64_C(1) << cluster_node_id; - post_open = !snapshot.transition_closed - && snapshot.active_bits == before->target_feature_bitmap - && snapshot.record_generation == before->record_generation - && snapshot.formation_epoch == before->transition_epoch; + post_open = !snapshot.transition_closed && snapshot.active_bits == before->target_feature_bitmap + && snapshot.record_generation == before->record_generation + && snapshot.formation_epoch == before->transition_epoch; if (post_open) - return all_observed - && (before->observed_members_lo & self_bit) != 0 - && semantic_activation_ack_matches( - &before->observed[cluster_node_id], &self); - if (!snapshot.transition_closed - || snapshot.active_bits != before->source_feature_bitmap + return all_observed && (before->observed_members_lo & self_bit) != 0 + && semantic_activation_ack_matches(&before->observed[cluster_node_id], &self); + if (!snapshot.transition_closed || snapshot.active_bits != before->source_feature_bitmap || snapshot.record_generation == UINT64_MAX || snapshot.record_generation + 1 != before->record_generation || snapshot.formation_epoch != before->transition_epoch) @@ -8595,54 +7488,40 @@ semantic_activation_ack_lmon_progress_member_open_applied_round( semantic_activation_lmon_record_read_seq, &completion)) return true; semantic_activation_lmon_record_read_seq = 0; - if (completion.result != CLUSTER_SEMANTIC_ACTIVATION_OK - || completion.implicit_open - || !cluster_semantic_activation_record_decode( - completion.selected_bytes, &open_record, NULL) + if (completion.result != CLUSTER_SEMANTIC_ACTIVATION_OK || completion.implicit_open + || !cluster_semantic_activation_record_decode(completion.selected_bytes, &open_record, + NULL) || open_record.phase != CLUSTER_SEMANTIC_PHASE_OPEN || open_record.record_generation != before->record_generation || open_record.transition_epoch != before->transition_epoch || open_record.coordinator_node != before->coordinator_node || open_record.coordinator_incarnation - != before->expected[before->coordinator_node] - .admitted_incarnation - || open_record.admitted_members_lo - != before->expected_members_lo - || open_record.admitted_members_hi - != before->expected_members_hi - || open_record.source_feature_bitmap - != before->source_feature_bitmap - || open_record.target_feature_bitmap - != before->target_feature_bitmap - || open_record.rollback_feature_bitmap - != before->rollback_feature_bitmap - || open_record.capability_sample_digest - != before->capability_sample_digest + != before->expected[before->coordinator_node].admitted_incarnation + || open_record.admitted_members_lo != before->expected_members_lo + || open_record.admitted_members_hi != before->expected_members_hi + || open_record.source_feature_bitmap != before->source_feature_bitmap + || open_record.target_feature_bitmap != before->target_feature_bitmap + || open_record.rollback_feature_bitmap != before->rollback_feature_bitmap + || open_record.capability_sample_digest != before->capability_sample_digest || !semantic_activation_snapshot(¤t_snapshot) || current_snapshot.seq != snapshot.seq || current_snapshot.active_bits != snapshot.active_bits - || current_snapshot.record_generation - != snapshot.record_generation - || current_snapshot.formation_epoch - != snapshot.formation_epoch - || current_snapshot.transition_closed - != snapshot.transition_closed - || !semantic_activation_ack_current_authority( - cluster_node_id, ¤t_members_lo, ¤t_members_hi, - ¤t_epoch, ¤t_coordinator_node) + || current_snapshot.record_generation != snapshot.record_generation + || current_snapshot.formation_epoch != snapshot.formation_epoch + || current_snapshot.transition_closed != snapshot.transition_closed + || !semantic_activation_ack_current_authority(cluster_node_id, ¤t_members_lo, + ¤t_members_hi, ¤t_epoch, + ¤t_coordinator_node) || current_members_lo != before->expected_members_lo || current_members_hi != before->expected_members_hi || current_epoch != before->transition_epoch - || current_coordinator_node - != (int32)before->coordinator_node - || cluster_ic_local_capability_word() - != local_capability_word + || current_coordinator_node != (int32)before->coordinator_node + || cluster_ic_local_capability_word() != local_capability_word || !semantic_activation_ack_table_snapshot(&after) || memcmp(before, &after, sizeof(after)) != 0 || !semantic_activation_ack_expected_image_current( - &after, current_members_lo, current_members_hi, - current_epoch, current_coordinator_node, cluster_node_id, - local_capability_word)) + &after, current_members_lo, current_members_hi, current_epoch, + current_coordinator_node, cluster_node_id, local_capability_word)) return true; memset(&request, 0, sizeof(request)); @@ -8661,15 +7540,14 @@ semantic_activation_ack_lmon_progress_member_open_applied_round( request.admitted_members_hi = after.expected_members_hi; request.capability_sample_digest = after.capability_sample_digest; memset(&pending, 0, sizeof(pending)); - if (!semantic_activation_ack_pending_send_begin_positive( - &pending, &request, cluster_node_id, &self)) + if (!semantic_activation_ack_pending_send_begin_positive(&pending, &request, + cluster_node_id, &self)) return true; next = after; next.observed_members_lo |= self_bit; next.observed[cluster_node_id] = self; - all_observed - = next.observed_members_lo == next.expected_members_lo; + all_observed = next.observed_members_lo == next.expected_members_lo; next.flags = CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID; if (all_observed) next.flags |= CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE; @@ -8682,25 +7560,22 @@ semantic_activation_ack_lmon_progress_member_open_applied_round( if (!all_observed || semantic_activation_lmon_record_read_seq != 0 || !semantic_activation_ack_complete_image_current( - before, current_members_lo, current_members_hi, current_epoch, - current_coordinator_node, cluster_node_id, - local_capability_word) + before, current_members_lo, current_members_hi, current_epoch, current_coordinator_node, + cluster_node_id, local_capability_word) || !semantic_activation_ack_table_snapshot(&after) || memcmp(before, &after, sizeof(after)) != 0) return true; - result = round_descriptor->open_target_admission( - callback_generation); - if (result != CLUSTER_SEMANTIC_ACTIVATION_OK - || !semantic_activation_snapshot(¤t_snapshot) + result = round_descriptor->open_target_admission(callback_generation); + if (result != CLUSTER_SEMANTIC_ACTIVATION_OK || !semantic_activation_snapshot(¤t_snapshot) || current_snapshot.seq != snapshot.seq || current_snapshot.active_bits != snapshot.active_bits || current_snapshot.record_generation != snapshot.record_generation || current_snapshot.formation_epoch != snapshot.formation_epoch || current_snapshot.transition_closed != snapshot.transition_closed - || !semantic_activation_ack_current_authority( - cluster_node_id, ¤t_members_lo, ¤t_members_hi, - ¤t_epoch, ¤t_coordinator_node) + || !semantic_activation_ack_current_authority(cluster_node_id, ¤t_members_lo, + ¤t_members_hi, ¤t_epoch, + ¤t_coordinator_node) || current_members_lo != before->expected_members_lo || current_members_hi != before->expected_members_hi || current_epoch != before->transition_epoch @@ -8709,12 +7584,11 @@ semantic_activation_ack_lmon_progress_member_open_applied_round( || !semantic_activation_ack_table_snapshot(&after) || memcmp(before, &after, sizeof(after)) != 0 || !semantic_activation_ack_complete_image_current( - &after, current_members_lo, current_members_hi, - current_epoch, current_coordinator_node, cluster_node_id, - local_capability_word) - || !semantic_activation_lmon_publish_gate( - ¤t_snapshot, before->target_feature_bitmap, - before->record_generation, before->transition_epoch, false)) + &after, current_members_lo, current_members_hi, current_epoch, current_coordinator_node, + cluster_node_id, local_capability_word) + || !semantic_activation_lmon_publish_gate(¤t_snapshot, before->target_feature_bitmap, + before->record_generation, + before->transition_epoch, false)) return true; return true; } @@ -8726,8 +7600,7 @@ semantic_activation_ack_lmon_progress_member_open_applied_round( */ static bool semantic_activation_ack_member_prepared_image_current_bit22( - const ClusterSemanticActivationAckTableV1 *image, - SemanticActivationAckTuple *out_self) + const ClusterSemanticActivationAckTableV1 *image, SemanticActivationAckTuple *out_self) { SemanticActivationAckTuple self; uint64 current_members_lo; @@ -8736,31 +7609,28 @@ semantic_activation_ack_member_prepared_image_current_bit22( uint32 local_capability_word; int32 current_coordinator_node; - if (image == NULL || out_self == NULL - || cluster_node_id < 0 || cluster_node_id >= CLUSTER_MAX_NODES + if (image == NULL || out_self == NULL || cluster_node_id < 0 + || cluster_node_id >= CLUSTER_MAX_NODES || image->stage != CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_PREPARED - || image->coordinator_node == (uint32)cluster_node_id - || image->round_nonce == 0 + || image->coordinator_node == (uint32)cluster_node_id || image->round_nonce == 0 || image->record_generation == 0 - || (image->target_feature_bitmap - & PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1) == 0 + || (image->target_feature_bitmap & PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1) + == 0 || (image->flags & ~(CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID - | CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE)) != 0 - || (image->flags - & CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID) == 0 - || image->expected_members_lo == 0 - || image->expected_members_hi != 0 - || (image->observed_members_lo - & ~image->expected_members_lo) != 0 + | CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE)) + != 0 + || (image->flags & CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID) == 0 + || image->expected_members_lo == 0 || image->expected_members_hi != 0 + || (image->observed_members_lo & ~image->expected_members_lo) != 0 || image->observed_members_hi != 0 || semantic_activation_ack_local_pending_send.pending_members_lo != 0 || semantic_activation_ack_local_pending_send.pending_members_hi != 0 || semantic_activation_ack_local_pending_send.invalidated) return false; - if (!semantic_activation_ack_current_authority( - cluster_node_id, ¤t_members_lo, ¤t_members_hi, - ¤t_epoch, ¤t_coordinator_node) + if (!semantic_activation_ack_current_authority(cluster_node_id, ¤t_members_lo, + ¤t_members_hi, ¤t_epoch, + ¤t_coordinator_node) || current_members_lo != image->expected_members_lo || current_members_hi != image->expected_members_hi || current_epoch != image->transition_epoch @@ -8768,14 +7638,11 @@ semantic_activation_ack_member_prepared_image_current_bit22( return false; local_capability_word = cluster_ic_local_capability_word(); if (!semantic_activation_ack_expected_image_current( - image, current_members_lo, current_members_hi, current_epoch, - current_coordinator_node, cluster_node_id, - local_capability_word) - || !semantic_activation_ack_self_tuple( - cluster_node_id, local_capability_word, current_epoch, - image->record_generation, &self) - || !semantic_activation_ack_matches( - &image->expected[cluster_node_id], &self)) + image, current_members_lo, current_members_hi, current_epoch, current_coordinator_node, + cluster_node_id, local_capability_word) + || !semantic_activation_ack_self_tuple(cluster_node_id, local_capability_word, + current_epoch, image->record_generation, &self) + || !semantic_activation_ack_matches(&image->expected[cluster_node_id], &self)) return false; *out_self = self; return true; @@ -8794,45 +7661,36 @@ semantic_activation_ack_lmon_member_pgrd_ready( char root_directory[MAXPGPATH]; if (expected_table == NULL - || !semantic_activation_ack_member_prepared_image_current( - expected_table, &self)) + || !semantic_activation_ack_member_prepared_image_current(expected_table, &self)) return false; if (semantic_activation_initial_clean_pgrd_mirror(published)) return true; if (semantic_activation_lmon_member_pgrd_read_request_seq == 0) { if (!semantic_activation_member_pgrd_read_mailbox_submit( - expected_table, - &semantic_activation_lmon_member_pgrd_read_request_seq)) + expected_table, &semantic_activation_lmon_member_pgrd_read_request_seq)) return false; return false; } memset(&completion, 0, sizeof(completion)); if (!semantic_activation_undo_root_descriptor_read_mailbox_poll_completion( - semantic_activation_lmon_member_pgrd_read_request_seq, - &completion) + semantic_activation_lmon_member_pgrd_read_request_seq, &completion) || completion.state != CLUSTER_UNDO_ROOT_DESCRIPTOR_VALID - || !semantic_activation_lmon_shared_pgrd_root_directory( - root_directory)) + || !semantic_activation_lmon_shared_pgrd_root_directory(root_directory)) return false; - mirror_state = cluster_undo_smgr_root_descriptor_read_candidate( - root_directory, mirror); + mirror_state = cluster_undo_smgr_root_descriptor_read_candidate(root_directory, mirror); if (mirror_state != CLUSTER_UNDO_SMGR_ROOT_MIRROR_EXACT || memcmp(mirror, completion.selected_bytes, sizeof(mirror)) != 0 || !semantic_activation_ack_table_snapshot(¤t) || memcmp(expected_table, ¤t, sizeof(current)) != 0 - || !semantic_activation_ack_member_prepared_image_current( - ¤t, &self) - || !semantic_activation_pgrd_snapshot_publish( - completion.selected_bytes) + || !semantic_activation_ack_member_prepared_image_current(¤t, &self) + || !semantic_activation_pgrd_snapshot_publish(completion.selected_bytes) || !semantic_activation_initial_clean_pgrd_mirror(published) - || memcmp(published, completion.selected_bytes, - sizeof(published)) != 0 + || memcmp(published, completion.selected_bytes, sizeof(published)) != 0 || !semantic_activation_ack_table_snapshot(¤t) || memcmp(expected_table, ¤t, sizeof(current)) != 0 - || !semantic_activation_ack_member_prepared_image_current( - ¤t, &self)) { + || !semantic_activation_ack_member_prepared_image_current(¤t, &self)) { semantic_activation_pgrd_snapshot_clear(); return false; } @@ -8874,56 +7732,43 @@ semantic_activation_ack_lmon_progress_member_barrier(void) /* RF-ROOT P9 verification (implementation): bit22 cutover round member BARRIER — * freeze the local wal-state source and ACK. */ if (before.stage == CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_BARRIER - && (before.target_feature_bitmap - & PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1) != 0) - return semantic_activation_ack_lmon_progress_member_barrier_bit22( - &before); - if (before.stage - == CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_COMMIT_APPLIED) { + && (before.target_feature_bitmap & PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1) + != 0) + return semantic_activation_ack_lmon_progress_member_barrier_bit22(&before); + if (before.stage == CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_COMMIT_APPLIED) { /* RF-ROOT P9 verification (implementation): the bit22 cutover round's member * COMMIT_APPLIED verifies the ACTIVE root (no four-member R4 * shape). */ - if ((before.target_feature_bitmap - & PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1) != 0) - return semantic_activation_ack_lmon_progress_member_commit_applied_bit22( - &before); - return semantic_activation_ack_lmon_progress_member_commit_applied( - &before); + if ((before.target_feature_bitmap & PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1) + != 0) + return semantic_activation_ack_lmon_progress_member_commit_applied_bit22(&before); + return semantic_activation_ack_lmon_progress_member_commit_applied(&before); } if (before.stage != CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_BARRIER && before.stage != CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_PREPARED - && before.stage - != CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_OPEN_APPLIED) + && before.stage != CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_OPEN_APPLIED) return false; - if ((before.target_feature_bitmap - & PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1) != 0) { + if ((before.target_feature_bitmap & PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1) + != 0) { round_descriptor = &r4_descriptor; required_caps = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS; } else if (!semantic_activation_round_descriptor( - before.source_feature_bitmap, - before.target_feature_bitmap, - before.rollback_feature_bitmap, &round_descriptor, - &required_caps)) + before.source_feature_bitmap, before.target_feature_bitmap, + before.rollback_feature_bitmap, &round_descriptor, &required_caps)) return true; /* RF-ROOT P7 (contract): bit22 cutover round — the member applies the * bit22 latch at OPEN_APPLIED (one-shot, monotonic). */ - if (before.stage - == CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_OPEN_APPLIED) { - if ((before.target_feature_bitmap - & PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1) != 0) - return semantic_activation_ack_lmon_progress_member_open_applied( - &before); - return semantic_activation_ack_lmon_progress_member_open_applied_round( - &before); + if (before.stage == CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_OPEN_APPLIED) { + if ((before.target_feature_bitmap & PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1) + != 0) + return semantic_activation_ack_lmon_progress_member_open_applied(&before); + return semantic_activation_ack_lmon_progress_member_open_applied_round(&before); } if (before.stage == CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_PREPARED) { - if (!semantic_activation_ack_member_prepared_image_current( - &before, &self)) + if (!semantic_activation_ack_member_prepared_image_current(&before, &self)) return true; - if (round_descriptor == &r4_descriptor - && before.source_feature_bitmap == 0 - && before.target_feature_bitmap - == CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1 + if (round_descriptor == &r4_descriptor && before.source_feature_bitmap == 0 + && before.target_feature_bitmap == CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1 && before.rollback_feature_bitmap == 0 && !semantic_activation_ack_lmon_member_pgrd_ready(&before)) return true; @@ -8932,14 +7777,12 @@ semantic_activation_ack_lmon_progress_member_barrier(void) return true; /* RF-ROOT P7 (contract): the bit22 cutover round has no member * PREPARED action — no-op OK; R4 keeps its cr-sync callback. */ - if ((before.target_feature_bitmap - & PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1) != 0) + if ((before.target_feature_bitmap & PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1) + != 0) result = bit22_stage_ok(before.record_generation); else - result = round_descriptor->prepare_target( - before.record_generation); - return semantic_activation_ack_lmon_finish_member_prepared( - &before, result); + result = round_descriptor->prepare_target(before.record_generation); + return semantic_activation_ack_lmon_finish_member_prepared(&before, result); } if (before.stage != CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_BARRIER) return false; @@ -8947,61 +7790,47 @@ semantic_activation_ack_lmon_progress_member_barrier(void) /* The approved Stage 8 path is the exact four-member formation. Once a * member has retained its BARRIER request, any mismatch stays closed and * must not fall through to the legacy majority-zero reader. */ - if (cluster_node_id <= 0 || cluster_node_id >= 4 - || before.coordinator_node != UINT32_C(0) - || before.expected_members_lo != UINT64_C(0x0f) - || before.expected_members_hi != 0 - || before.round_nonce == 0 - || before.record_generation == 0 + if (cluster_node_id <= 0 || cluster_node_id >= 4 || before.coordinator_node != UINT32_C(0) + || before.expected_members_lo != UINT64_C(0x0f) || before.expected_members_hi != 0 + || before.round_nonce == 0 || before.record_generation == 0 || before.capability_sample_digest == 0 - || (before.flags - & CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID) == 0 + || (before.flags & CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID) == 0 || (before.flags & ~(CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID - | CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE)) != 0 - || (before.observed_members_lo - & ~before.expected_members_lo) != 0 + | CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE)) + != 0 + || (before.observed_members_lo & ~before.expected_members_lo) != 0 || before.observed_members_hi != 0) return true; - all_observed - = before.observed_members_lo == before.expected_members_lo; - if (all_observed - != ((before.flags - & CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE) != 0)) + all_observed = before.observed_members_lo == before.expected_members_lo; + if (all_observed != ((before.flags & CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE) != 0)) return true; for (node = 0; node < CLUSTER_MAX_NODES; node++) { bool expected_member = node < 4; bool observed_member - = node < 64 - ? (before.observed_members_lo - & (UINT64_C(1) << node)) != 0 - : (before.observed_members_hi - & (UINT64_C(1) << (node - 64))) != 0; + = node < 64 ? (before.observed_members_lo & (UINT64_C(1) << node)) != 0 + : (before.observed_members_hi & (UINT64_C(1) << (node - 64))) != 0; if (!expected_member) { - if (!semantic_activation_bytes_are_zero( - (const uint8 *)&before.expected[node], - sizeof(before.expected[node])) - || !semantic_activation_bytes_are_zero( - (const uint8 *)&before.observed[node], - sizeof(before.observed[node]))) + if (!semantic_activation_bytes_are_zero((const uint8 *)&before.expected[node], + sizeof(before.expected[node])) + || !semantic_activation_bytes_are_zero((const uint8 *)&before.observed[node], + sizeof(before.observed[node]))) return true; continue; } if (observed_member) { - if (!semantic_activation_ack_matches( - &before.observed[node], &before.expected[node])) + if (!semantic_activation_ack_matches(&before.observed[node], &before.expected[node])) return true; - } else if (!semantic_activation_bytes_are_zero( - (const uint8 *)&before.observed[node], - sizeof(before.observed[node]))) + } else if (!semantic_activation_bytes_are_zero((const uint8 *)&before.observed[node], + sizeof(before.observed[node]))) return true; } - if (!semantic_activation_ack_current_authority( - cluster_node_id, ¤t_members_lo, ¤t_members_hi, - ¤t_epoch, ¤t_coordinator_node) + if (!semantic_activation_ack_current_authority(cluster_node_id, ¤t_members_lo, + ¤t_members_hi, ¤t_epoch, + ¤t_coordinator_node) || current_members_lo != before.expected_members_lo || current_members_hi != before.expected_members_hi || current_epoch != before.transition_epoch @@ -9010,19 +7839,15 @@ semantic_activation_ack_lmon_progress_member_barrier(void) local_capability_word = cluster_ic_local_capability_word(); if ((local_capability_word & required_caps) != required_caps || !semantic_activation_ack_expected_image_current( - &before, current_members_lo, current_members_hi, - current_epoch, current_coordinator_node, cluster_node_id, - local_capability_word) - || !semantic_activation_ack_self_tuple( - cluster_node_id, local_capability_word, current_epoch, - before.record_generation, &self) - || !semantic_activation_ack_matches( - &before.expected[cluster_node_id], &self)) + &before, current_members_lo, current_members_hi, current_epoch, + current_coordinator_node, cluster_node_id, local_capability_word) + || !semantic_activation_ack_self_tuple(cluster_node_id, local_capability_word, + current_epoch, before.record_generation, &self) + || !semantic_activation_ack_matches(&before.expected[cluster_node_id], &self)) return true; self_bit = UINT64_C(1) << cluster_node_id; if ((before.observed_members_lo & self_bit) != 0) - return semantic_activation_ack_matches( - &before.observed[cluster_node_id], &self); + return semantic_activation_ack_matches(&before.observed[cluster_node_id], &self); if (semantic_activation_lmon_record_read_seq == 0) { if (semantic_activation_record_read_mailbox_submit(&request_seq)) @@ -9033,27 +7858,20 @@ semantic_activation_ack_lmon_progress_member_barrier(void) semantic_activation_lmon_record_read_seq, &completion)) return true; semantic_activation_lmon_record_read_seq = 0; - if (completion.result != CLUSTER_SEMANTIC_ACTIVATION_OK - || completion.implicit_open - || !cluster_semantic_activation_record_decode( - completion.selected_bytes, &prepare, NULL) + if (completion.result != CLUSTER_SEMANTIC_ACTIVATION_OK || completion.implicit_open + || !cluster_semantic_activation_record_decode(completion.selected_bytes, &prepare, NULL) || prepare.phase != CLUSTER_SEMANTIC_PHASE_PREPARE || prepare.record_generation != before.record_generation || prepare.transition_epoch != before.transition_epoch || prepare.coordinator_node != before.coordinator_node || prepare.coordinator_incarnation - != before.expected[before.coordinator_node] - .admitted_incarnation + != before.expected[before.coordinator_node].admitted_incarnation || prepare.admitted_members_lo != before.expected_members_lo || prepare.admitted_members_hi != before.expected_members_hi - || prepare.source_feature_bitmap - != before.source_feature_bitmap - || prepare.target_feature_bitmap - != before.target_feature_bitmap - || prepare.rollback_feature_bitmap - != before.rollback_feature_bitmap - || prepare.capability_sample_digest - != before.capability_sample_digest + || prepare.source_feature_bitmap != before.source_feature_bitmap + || prepare.target_feature_bitmap != before.target_feature_bitmap + || prepare.rollback_feature_bitmap != before.rollback_feature_bitmap + || prepare.capability_sample_digest != before.capability_sample_digest || !semantic_activation_snapshot(&snapshot) || snapshot.formation_epoch != before.transition_epoch || snapshot.active_bits != before.source_feature_bitmap) @@ -9063,63 +7881,52 @@ semantic_activation_ack_lmon_progress_member_barrier(void) return true; } else { if (snapshot.record_generation == UINT64_MAX - || snapshot.record_generation + 1 - != before.record_generation - || !semantic_activation_lmon_publish_gate( - &snapshot, before.source_feature_bitmap, - before.record_generation, before.transition_epoch, true)) + || snapshot.record_generation + 1 != before.record_generation + || !semantic_activation_lmon_publish_gate(&snapshot, before.source_feature_bitmap, + before.record_generation, + before.transition_epoch, true)) return true; } - result = round_descriptor->close_source_admission( - before.record_generation); + result = round_descriptor->close_source_admission(before.record_generation); if (result == CLUSTER_SEMANTIC_ACTIVATION_DEBT_NONZERO) return true; if (result != CLUSTER_SEMANTIC_ACTIVATION_OK) return true; - result = round_descriptor->source_logical_debt_zero( - before.record_generation, &proof); + result = round_descriptor->source_logical_debt_zero(before.record_generation, &proof); if (result == CLUSTER_SEMANTIC_ACTIVATION_DEBT_NONZERO) return true; if (result != CLUSTER_SEMANTIC_ACTIVATION_OK - || proof.record_generation != before.record_generation - || proof.debt_count != 0) + || proof.record_generation != before.record_generation || proof.debt_count != 0) return true; - result = round_descriptor->source_transport_zero( - before.record_generation, &proof); + result = round_descriptor->source_transport_zero(before.record_generation, &proof); if (result == CLUSTER_SEMANTIC_ACTIVATION_DEBT_NONZERO || result == CLUSTER_SEMANTIC_ACTIVATION_TRANSPORT_NONZERO) return true; if (result != CLUSTER_SEMANTIC_ACTIVATION_OK - || proof.record_generation != before.record_generation - || proof.debt_count != 0) + || proof.record_generation != before.record_generation || proof.debt_count != 0) return true; - if (!semantic_activation_snapshot(&snapshot) - || !snapshot.transition_closed + if (!semantic_activation_snapshot(&snapshot) || !snapshot.transition_closed || snapshot.active_bits != before.source_feature_bitmap || snapshot.record_generation != before.record_generation || snapshot.formation_epoch != before.transition_epoch - || !semantic_activation_ack_current_authority( - cluster_node_id, ¤t_members_lo, ¤t_members_hi, - ¤t_epoch, ¤t_coordinator_node) + || !semantic_activation_ack_current_authority(cluster_node_id, ¤t_members_lo, + ¤t_members_hi, ¤t_epoch, + ¤t_coordinator_node) || current_members_lo != before.expected_members_lo || current_members_hi != before.expected_members_hi || current_epoch != before.transition_epoch || current_coordinator_node != (int32)before.coordinator_node - || cluster_ic_local_capability_word() - != local_capability_word + || cluster_ic_local_capability_word() != local_capability_word || !semantic_activation_ack_table_snapshot(&after) || memcmp(&before, &after, sizeof(before)) != 0 || !semantic_activation_ack_expected_image_current( - &after, current_members_lo, current_members_hi, - current_epoch, current_coordinator_node, cluster_node_id, - local_capability_word) - || !semantic_activation_ack_self_tuple( - cluster_node_id, local_capability_word, current_epoch, - after.record_generation, &self) - || !semantic_activation_ack_matches( - &after.expected[cluster_node_id], &self) + &after, current_members_lo, current_members_hi, current_epoch, current_coordinator_node, + cluster_node_id, local_capability_word) + || !semantic_activation_ack_self_tuple(cluster_node_id, local_capability_word, + current_epoch, after.record_generation, &self) + || !semantic_activation_ack_matches(&after.expected[cluster_node_id], &self) || semantic_activation_ack_local_pending_send.pending_members_lo != 0 || semantic_activation_ack_local_pending_send.pending_members_hi != 0 || semantic_activation_ack_local_pending_send.invalidated) @@ -9141,15 +7948,14 @@ semantic_activation_ack_lmon_progress_member_barrier(void) request.admitted_members_hi = after.expected_members_hi; request.capability_sample_digest = after.capability_sample_digest; memset(&pending, 0, sizeof(pending)); - if (!semantic_activation_ack_pending_send_begin_positive( - &pending, &request, cluster_node_id, &self)) + if (!semantic_activation_ack_pending_send_begin_positive(&pending, &request, cluster_node_id, + &self)) return true; next = after; next.observed_members_lo |= self_bit; next.observed[cluster_node_id] = self; - all_observed - = next.observed_members_lo == next.expected_members_lo; + all_observed = next.observed_members_lo == next.expected_members_lo; next.flags = CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID; if (all_observed) next.flags |= CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE; @@ -9161,12 +7967,10 @@ semantic_activation_ack_lmon_progress_member_barrier(void) } static bool -semantic_activation_ack_lmon_begin_barrier_round( - const SemanticActivationUtilityRequest *request, - const ClusterSemanticActivationRecord *prepare) +semantic_activation_ack_lmon_begin_barrier_round(const SemanticActivationUtilityRequest *request, + const ClusterSemanticActivationRecord *prepare) { - SemanticActivationAckRequestOrigin *origin - = &semantic_activation_ack_local_request_origin; + SemanticActivationAckRequestOrigin *origin = &semantic_activation_ack_local_request_origin; ClusterSemanticActivationAckTableV1 before; ClusterSemanticActivationAckTableV1 after; ClusterSemanticActivationAckTableV1 next; @@ -9185,40 +7989,32 @@ semantic_activation_ack_lmon_begin_barrier_round( int32 current_coordinator_node; bool bit22_round; - bit22_round - = (prepare != NULL - && (prepare->target_feature_bitmap - & PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1) != 0); + bit22_round = (prepare != NULL + && (prepare->target_feature_bitmap + & PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1) + != 0); if (bit22_round) { round_descriptor = &r4_descriptor; required_caps = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS; } - if (request == NULL || prepare == NULL - || prepare->phase != CLUSTER_SEMANTIC_PHASE_PREPARE - || prepare->record_generation == 0 - || request->expected_record_generation == UINT64_MAX - || prepare->record_generation - != request->expected_record_generation + 1 + if (request == NULL || prepare == NULL || prepare->phase != CLUSTER_SEMANTIC_PHASE_PREPARE + || prepare->record_generation == 0 || request->expected_record_generation == UINT64_MAX + || prepare->record_generation != request->expected_record_generation + 1 || prepare->source_feature_bitmap != request->source_feature_bitmap || prepare->target_feature_bitmap != request->target_feature_bitmap - || prepare->rollback_feature_bitmap - != request->rollback_feature_bitmap + || prepare->rollback_feature_bitmap != request->rollback_feature_bitmap || (!bit22_round && !semantic_activation_round_descriptor( - prepare->source_feature_bitmap, - prepare->target_feature_bitmap, - prepare->rollback_feature_bitmap, &round_descriptor, - &required_caps)) - || prepare->capability_sample_digest == 0 - || !semantic_activation_snapshot(&snapshot) - || !snapshot.transition_closed - || snapshot.active_bits != prepare->source_feature_bitmap + prepare->source_feature_bitmap, prepare->target_feature_bitmap, + prepare->rollback_feature_bitmap, &round_descriptor, &required_caps)) + || prepare->capability_sample_digest == 0 || !semantic_activation_snapshot(&snapshot) + || !snapshot.transition_closed || snapshot.active_bits != prepare->source_feature_bitmap || snapshot.record_generation != prepare->record_generation || snapshot.formation_epoch != prepare->transition_epoch - || !semantic_activation_ack_current_authority( - cluster_node_id, ¤t_members_lo, ¤t_members_hi, - ¤t_epoch, ¤t_coordinator_node) + || !semantic_activation_ack_current_authority(cluster_node_id, ¤t_members_lo, + ¤t_members_hi, ¤t_epoch, + ¤t_coordinator_node) || cluster_node_id != 0 || current_coordinator_node != 0 || current_members_lo != prepare->admitted_members_lo || current_members_hi != prepare->admitted_members_hi @@ -9232,16 +8028,13 @@ semantic_activation_ack_lmon_begin_barrier_round( || before.record_generation != prepare->record_generation || before.source_feature_bitmap != prepare->source_feature_bitmap || before.target_feature_bitmap != prepare->target_feature_bitmap - || before.rollback_feature_bitmap - != prepare->rollback_feature_bitmap) + || before.rollback_feature_bitmap != prepare->rollback_feature_bitmap) return false; local_capability_word = cluster_ic_local_capability_word(); - if ((!bit22_round - && (local_capability_word & required_caps) != required_caps) - || !semantic_activation_ack_self_tuple( - cluster_node_id, local_capability_word, current_epoch, - prepare->record_generation, &self)) + if ((!bit22_round && (local_capability_word & required_caps) != required_caps) + || !semantic_activation_ack_self_tuple(cluster_node_id, local_capability_word, + current_epoch, prepare->record_generation, &self)) return false; if (before.stage == CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_PREPARED) { @@ -9249,71 +8042,51 @@ semantic_activation_ack_lmon_begin_barrier_round( if (before.flags != (CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID - | (before.observed_members_lo - == before.expected_members_lo + | (before.observed_members_lo == before.expected_members_lo ? CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE : 0)) - || before.capability_sample_digest - != prepare->capability_sample_digest - || !origin->active - || before.observed_members_hi != 0 - || (before.observed_members_lo - & ~before.expected_members_lo) != 0 + || before.capability_sample_digest != prepare->capability_sample_digest + || !origin->active || before.observed_members_hi != 0 + || (before.observed_members_lo & ~before.expected_members_lo) != 0 || !semantic_activation_ack_expected_image_current( - &before, current_members_lo, current_members_hi, - current_epoch, current_coordinator_node, - cluster_node_id, local_capability_word)) + &before, current_members_lo, current_members_hi, current_epoch, + current_coordinator_node, cluster_node_id, local_capability_word)) return false; if ((before.observed_members_lo & self_bit) == 0) { /* RF-ROOT P7 (contract): bit22 round -> no-op member PREPARED. */ if (bit22_round) result = bit22_stage_ok(before.record_generation); else - result = round_descriptor->prepare_target( - before.record_generation); - return semantic_activation_ack_lmon_finish_member_prepared( - &before, result); + result = round_descriptor->prepare_target(before.record_generation); + return semantic_activation_ack_lmon_finish_member_prepared(&before, result); } - if (!semantic_activation_ack_matches( - &before.observed[cluster_node_id], - &before.expected[cluster_node_id])) + if (!semantic_activation_ack_matches(&before.observed[cluster_node_id], + &before.expected[cluster_node_id])) return false; - if ((before.flags - & CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE) != 0) { + if ((before.flags & CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE) != 0) { if (!semantic_activation_ack_complete_image_current( - &before, current_members_lo, current_members_hi, - current_epoch, current_coordinator_node, - cluster_node_id, local_capability_word)) + &before, current_members_lo, current_members_hi, current_epoch, + current_coordinator_node, cluster_node_id, local_capability_word)) return false; - return semantic_activation_ack_lmon_submit_commit( - request, prepare); + return semantic_activation_ack_lmon_submit_commit(request, prepare); } return semantic_activation_ack_lmon_send_origin_requests(); } if (before.stage == CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_BARRIER) { - bool complete_current - = semantic_activation_ack_complete_image_current( - &before, current_members_lo, current_members_hi, - current_epoch, current_coordinator_node, - cluster_node_id, local_capability_word); - if ((before.flags - & CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID) == 0 - || before.capability_sample_digest - != prepare->capability_sample_digest - || !origin->active - || (before.observed_members_lo & UINT64_C(1)) == 0 + bool complete_current = semantic_activation_ack_complete_image_current( + &before, current_members_lo, current_members_hi, current_epoch, + current_coordinator_node, cluster_node_id, local_capability_word); + if ((before.flags & CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID) == 0 + || before.capability_sample_digest != prepare->capability_sample_digest + || !origin->active || (before.observed_members_lo & UINT64_C(1)) == 0 || !semantic_activation_full_ack_table_matches( - before.expected, before.expected_members_lo, - before.expected_members_hi, before.expected, - before.expected_members_lo, before.expected_members_hi) - || !semantic_activation_ack_matches( - &before.expected[0], &self) - || !semantic_activation_ack_matches( - &before.observed[0], &self)) + before.expected, before.expected_members_lo, before.expected_members_hi, + before.expected, before.expected_members_lo, before.expected_members_hi) + || !semantic_activation_ack_matches(&before.expected[0], &self) + || !semantic_activation_ack_matches(&before.observed[0], &self)) return false; - if ((before.flags - & CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE) == 0) + if ((before.flags & CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE) == 0) return semantic_activation_ack_lmon_send_origin_requests(); if (before.flags != (CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID @@ -9327,49 +8100,38 @@ semantic_activation_ack_lmon_begin_barrier_round( * PREPARED publication. The initial R4 and bit22 contracts retain * their frozen ordering. */ if (round_descriptor == &r11_resource_x_descriptor) { - result = round_descriptor->source_transport_zero( - before.record_generation, &proof); + result = round_descriptor->source_transport_zero(before.record_generation, &proof); if (result == CLUSTER_SEMANTIC_ACTIVATION_DEBT_NONZERO - || result - == CLUSTER_SEMANTIC_ACTIVATION_TRANSPORT_NONZERO) + || result == CLUSTER_SEMANTIC_ACTIVATION_TRANSPORT_NONZERO) return true; if (result != CLUSTER_SEMANTIC_ACTIVATION_OK - || proof.record_generation != before.record_generation - || proof.debt_count != 0 + || proof.record_generation != before.record_generation || proof.debt_count != 0 || !semantic_activation_snapshot(¤t_snapshot) || current_snapshot.seq != snapshot.seq || current_snapshot.active_bits != snapshot.active_bits - || current_snapshot.record_generation - != snapshot.record_generation - || current_snapshot.formation_epoch - != snapshot.formation_epoch - || current_snapshot.transition_closed - != snapshot.transition_closed - || !semantic_activation_ack_current_authority( - cluster_node_id, ¤t_members_lo, - ¤t_members_hi, ¤t_epoch, - ¤t_coordinator_node) + || current_snapshot.record_generation != snapshot.record_generation + || current_snapshot.formation_epoch != snapshot.formation_epoch + || current_snapshot.transition_closed != snapshot.transition_closed + || !semantic_activation_ack_current_authority(cluster_node_id, ¤t_members_lo, + ¤t_members_hi, ¤t_epoch, + ¤t_coordinator_node) || current_members_lo != prepare->admitted_members_lo || current_members_hi != prepare->admitted_members_hi || current_epoch != prepare->transition_epoch - || current_coordinator_node - != (int32)prepare->coordinator_node - || cluster_ic_local_capability_word() - != local_capability_word + || current_coordinator_node != (int32)prepare->coordinator_node + || cluster_ic_local_capability_word() != local_capability_word || !semantic_activation_ack_table_snapshot(&after) || memcmp(&before, &after, sizeof(before)) != 0 || !semantic_activation_ack_complete_image_current( - &after, current_members_lo, current_members_hi, - current_epoch, current_coordinator_node, - cluster_node_id, local_capability_word)) + &after, current_members_lo, current_members_hi, current_epoch, + current_coordinator_node, cluster_node_id, local_capability_word)) return false; before = after; } next = before; next.stage = CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_PREPARED; - next.flags - = CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID; + next.flags = CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID; next.observed_members_lo = 0; next.observed_members_hi = 0; memset(next.observed, 0, sizeof(next.observed)); @@ -9383,52 +8145,45 @@ semantic_activation_ack_lmon_begin_barrier_round( if (before.stage != CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_SAMPLE || before.flags - != (CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID - | CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE) + != (CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID + | CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE) || before.capability_sample_digest != 0 || !semantic_activation_ack_complete_image_current( - &before, current_members_lo, current_members_hi, - current_epoch, current_coordinator_node, cluster_node_id, - local_capability_word) + &before, current_members_lo, current_members_hi, current_epoch, + current_coordinator_node, cluster_node_id, local_capability_word) || !semantic_activation_ack_sample_digest(&before, &digest) || digest != prepare->capability_sample_digest) return false; - result = round_descriptor->close_source_admission( - prepare->record_generation); + result = round_descriptor->close_source_admission(prepare->record_generation); if (result == CLUSTER_SEMANTIC_ACTIVATION_DEBT_NONZERO) return true; if (result != CLUSTER_SEMANTIC_ACTIVATION_OK) return false; - result = round_descriptor->source_logical_debt_zero( - prepare->record_generation, &proof); + result = round_descriptor->source_logical_debt_zero(prepare->record_generation, &proof); if (result == CLUSTER_SEMANTIC_ACTIVATION_DEBT_NONZERO) return true; if (result != CLUSTER_SEMANTIC_ACTIVATION_OK - || proof.record_generation != prepare->record_generation - || proof.debt_count != 0) + || proof.record_generation != prepare->record_generation || proof.debt_count != 0) return false; if (round_descriptor != &r11_resource_x_descriptor) { - result = round_descriptor->source_transport_zero( - prepare->record_generation, &proof); + result = round_descriptor->source_transport_zero(prepare->record_generation, &proof); if (result == CLUSTER_SEMANTIC_ACTIVATION_DEBT_NONZERO || result == CLUSTER_SEMANTIC_ACTIVATION_TRANSPORT_NONZERO) return true; if (result != CLUSTER_SEMANTIC_ACTIVATION_OK - || proof.record_generation != prepare->record_generation - || proof.debt_count != 0) + || proof.record_generation != prepare->record_generation || proof.debt_count != 0) return false; } - if (!semantic_activation_snapshot(¤t_snapshot) - || current_snapshot.seq != snapshot.seq + if (!semantic_activation_snapshot(¤t_snapshot) || current_snapshot.seq != snapshot.seq || current_snapshot.active_bits != snapshot.active_bits || current_snapshot.record_generation != snapshot.record_generation || current_snapshot.formation_epoch != snapshot.formation_epoch || current_snapshot.transition_closed != snapshot.transition_closed - || !semantic_activation_ack_current_authority( - cluster_node_id, ¤t_members_lo, ¤t_members_hi, - ¤t_epoch, ¤t_coordinator_node) + || !semantic_activation_ack_current_authority(cluster_node_id, ¤t_members_lo, + ¤t_members_hi, ¤t_epoch, + ¤t_coordinator_node) || current_members_lo != prepare->admitted_members_lo || current_members_hi != prepare->admitted_members_hi || current_epoch != prepare->transition_epoch @@ -9437,9 +8192,8 @@ semantic_activation_ack_lmon_begin_barrier_round( || !semantic_activation_ack_table_snapshot(&after) || memcmp(&before, &after, sizeof(before)) != 0 || !semantic_activation_ack_complete_image_current( - &after, current_members_lo, current_members_hi, - current_epoch, current_coordinator_node, cluster_node_id, - local_capability_word)) + &after, current_members_lo, current_members_hi, current_epoch, current_coordinator_node, + cluster_node_id, local_capability_word)) return false; memcpy(&next, &after, sizeof(next)); @@ -9450,8 +8204,7 @@ semantic_activation_ack_lmon_begin_barrier_round( next.capability_sample_digest = prepare->capability_sample_digest; memset(next.observed, 0, sizeof(next.observed)); next.observed[0] = self; - if (!semantic_activation_ack_matches( - &next.expected[0], &next.observed[0]) + if (!semantic_activation_ack_matches(&next.expected[0], &next.observed[0]) || !semantic_activation_ack_table_publish(&next)) return false; @@ -9466,8 +8219,7 @@ semantic_activation_feature_bit_index(uint64 feature_bit, int *feature_index) { int index = 0; - if (feature_bit == 0 || feature_index == NULL - || (feature_bit & (feature_bit - 1)) != 0) + if (feature_bit == 0 || feature_index == NULL || (feature_bit & (feature_bit - 1)) != 0) return false; while ((feature_bit & UINT64_C(1)) == 0) { feature_bit >>= 1; @@ -9556,40 +8308,29 @@ cluster_semantic_activation_phase1_pristine(void) uint32 reserved; int attempt; - if (!semantic_activation_snapshot(&snapshot) - || snapshot.active_bits != 0 - || snapshot.record_generation != 0 - || snapshot.formation_epoch != 0 - || snapshot.transition_closed - || !semantic_activation_ack_table_snapshot(&table)) + if (!semantic_activation_snapshot(&snapshot) || snapshot.active_bits != 0 + || snapshot.record_generation != 0 || snapshot.formation_epoch != 0 + || snapshot.transition_closed || !semantic_activation_ack_table_snapshot(&table)) return false; memset(&empty_table, 0, sizeof(empty_table)); - if (memcmp(&table, &empty_table, sizeof(table)) != 0 - || SemanticActivationPgrdSnapshot == NULL) + if (memcmp(&table, &empty_table, sizeof(table)) != 0 || SemanticActivationPgrdSnapshot == NULL) return false; memset(zero_bytes, 0, sizeof(zero_bytes)); - for (attempt = 0; - attempt < CLUSTER_SEMANTIC_ADMISSION_SNAPSHOT_TRIES; - attempt++) { - seq_before = pg_atomic_read_u64( - &SemanticActivationPgrdSnapshot->publication_seq); + for (attempt = 0; attempt < CLUSTER_SEMANTIC_ADMISSION_SNAPSHOT_TRIES; attempt++) { + seq_before = pg_atomic_read_u64(&SemanticActivationPgrdSnapshot->publication_seq); if ((seq_before & UINT64_C(1)) != 0) continue; pg_read_barrier(); - present = pg_atomic_read_u32( - &SemanticActivationPgrdSnapshot->present); + present = pg_atomic_read_u32(&SemanticActivationPgrdSnapshot->present); reserved = SemanticActivationPgrdSnapshot->reserved; - memcpy(descriptor_bytes, - SemanticActivationPgrdSnapshot->descriptor_bytes, + memcpy(descriptor_bytes, SemanticActivationPgrdSnapshot->descriptor_bytes, sizeof(descriptor_bytes)); pg_read_barrier(); - seq_after = pg_atomic_read_u64( - &SemanticActivationPgrdSnapshot->publication_seq); + seq_after = pg_atomic_read_u64(&SemanticActivationPgrdSnapshot->publication_seq); if (seq_before == seq_after && (seq_after & UINT64_C(1)) == 0) return seq_after == 0 && present == 0 && reserved == 0 - && memcmp(descriptor_bytes, zero_bytes, - sizeof(descriptor_bytes)) == 0; + && memcmp(descriptor_bytes, zero_bytes, sizeof(descriptor_bytes)) == 0; } return false; } @@ -9609,22 +8350,18 @@ cluster_resource_x_writer_path_snapshot(uint64 *r4_generation_out) || (snapshot.record_generation != 0 && snapshot.formation_epoch != cluster_epoch_get_current())) return RESOURCE_X_WRITER_CLOSED; - if ((snapshot.active_bits - & CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1) != 0) + if ((snapshot.active_bits & CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1) != 0) return RESOURCE_X_WRITER_TARGET; - return CLUSTER_SEMANTIC_R11_RESOURCE_X_SOURCE_AVAILABLE - ? RESOURCE_X_WRITER_SOURCE - : RESOURCE_X_WRITER_CLOSED; + return CLUSTER_SEMANTIC_R11_RESOURCE_X_SOURCE_AVAILABLE ? RESOURCE_X_WRITER_SOURCE + : RESOURCE_X_WRITER_CLOSED; } bool -cluster_semantic_activation_r11_cutover_snapshot( - ClusterSemanticR11CutoverSnapshot *out) +cluster_semantic_activation_r11_cutover_snapshot(ClusterSemanticR11CutoverSnapshot *out) { const uint64 source_bits = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1; - const uint64 target_bits - = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1 - | CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1; + const uint64 target_bits = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1 + | CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1; ClusterSemanticActivationAckTableV1 table; SemanticActivationAdmissionSnapshot snapshot; uint64 sample_digest; @@ -9639,17 +8376,15 @@ cluster_semantic_activation_r11_cutover_snapshot( memset(out, 0, sizeof(*out)); if (semantic_activation_restart_cutover(out)) return true; - if (!semantic_activation_snapshot(&snapshot) - || snapshot.record_generation == 0 + if (!semantic_activation_snapshot(&snapshot) || snapshot.record_generation == 0 || snapshot.record_generation == UINT64_MAX - || !semantic_activation_ack_current_authority( - cluster_node_id, ¤t_members_lo, ¤t_members_hi, - ¤t_epoch, ¤t_coordinator_node) + || !semantic_activation_ack_current_authority(cluster_node_id, ¤t_members_lo, + ¤t_members_hi, ¤t_epoch, + ¤t_coordinator_node) || snapshot.formation_epoch != current_epoch) return false; - if (!snapshot.transition_closed - && snapshot.active_bits == target_bits) { + if (!snapshot.transition_closed && snapshot.active_bits == target_bits) { out->record_generation = snapshot.record_generation; out->formation_epoch = snapshot.formation_epoch; out->phase = CLUSTER_SEMANTIC_R11_CUTOVER_TARGET_OPEN; @@ -9660,21 +8395,17 @@ cluster_semantic_activation_r11_cutover_snapshot( || table.coordinator_node != (uint32)current_coordinator_node || table.expected_members_lo != current_members_lo || table.expected_members_hi != current_members_hi - || table.transition_epoch != current_epoch - || table.source_feature_bitmap != source_bits - || table.target_feature_bitmap != target_bits - || table.rollback_feature_bitmap != 0) + || table.transition_epoch != current_epoch || table.source_feature_bitmap != source_bits + || table.target_feature_bitmap != target_bits || table.rollback_feature_bitmap != 0) return false; local_capability_word = cluster_ic_local_capability_word(); if (!semantic_activation_ack_expected_image_current( - &table, current_members_lo, current_members_hi, current_epoch, - current_coordinator_node, cluster_node_id, - local_capability_word)) + &table, current_members_lo, current_members_hi, current_epoch, current_coordinator_node, + cluster_node_id, local_capability_word)) return false; if (table.stage == CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_SAMPLE) { if (table.capability_sample_digest != 0 - || !semantic_activation_ack_sample_digest(&table, &sample_digest) - || sample_digest == 0) + || !semantic_activation_ack_sample_digest(&table, &sample_digest) || sample_digest == 0) return false; } else if (table.capability_sample_digest == 0) return false; @@ -9682,10 +8413,9 @@ cluster_semantic_activation_r11_cutover_snapshot( if (table.stage >= CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_SAMPLE && table.stage < CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_OPEN_APPLIED && table.record_generation == snapshot.record_generation) { - out->record_generation - = table.stage == CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_COMMIT_APPLIED - ? table.record_generation - 1 - : table.record_generation; + out->record_generation = table.stage == CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_COMMIT_APPLIED + ? table.record_generation - 1 + : table.record_generation; if (out->record_generation == 0) return false; out->formation_epoch = table.transition_epoch; @@ -9693,16 +8423,13 @@ cluster_semantic_activation_r11_cutover_snapshot( return true; } if (table.stage == CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_OPEN_APPLIED - && snapshot.record_generation + 1 == table.record_generation - && table.record_generation > 2 + && snapshot.record_generation + 1 == table.record_generation && table.record_generation > 2 && semantic_activation_ack_complete_image_current( - &table, current_members_lo, current_members_hi, current_epoch, - current_coordinator_node, cluster_node_id, - local_capability_word)) { + &table, current_members_lo, current_members_hi, current_epoch, current_coordinator_node, + cluster_node_id, local_capability_word)) { out->record_generation = table.record_generation - 2; out->formation_epoch = table.transition_epoch; - out->phase - = CLUSTER_SEMANTIC_R11_CUTOVER_DURABLE_OPEN_PENDING_LOCAL; + out->phase = CLUSTER_SEMANTIC_R11_CUTOVER_DURABLE_OPEN_PENDING_LOCAL; return true; } return false; @@ -9718,9 +8445,8 @@ cluster_semantic_activation_r11_cutover_snapshot( static SemanticActivationAckConsumeResult semantic_activation_ack_lmon_accept_current_sample_request( const SemanticActivationAckIngressItem *item, - const SemanticActivationAdmissionSnapshot *snapshot, - uint64 current_members_lo, uint64 current_members_hi, - uint64 current_epoch, int32 current_coordinator_node, + const SemanticActivationAdmissionSnapshot *snapshot, uint64 current_members_lo, + uint64 current_members_hi, uint64 current_epoch, int32 current_coordinator_node, uint32 local_capability_word) { const ClusterSemanticActivationAckWireV1 *message; @@ -9729,31 +8455,26 @@ semantic_activation_ack_lmon_accept_current_sample_request( if (item == NULL || snapshot == NULL) return SEMANTIC_ACTIVATION_ACK_CONSUME_REJECTED; message = &item->message; - if ((snapshot->seq & UINT64_C(1)) != 0 - || snapshot->transition_closed - || snapshot->formation_epoch != current_epoch - || snapshot->record_generation == UINT64_MAX - || message->record_generation - != snapshot->record_generation + 1 + if ((snapshot->seq & UINT64_C(1)) != 0 || snapshot->transition_closed + || snapshot->formation_epoch != current_epoch || snapshot->record_generation == UINT64_MAX + || message->record_generation != snapshot->record_generation + 1 || message->source_feature_bitmap != snapshot->active_bits || !semantic_activation_ack_round_required_caps( - message->source_feature_bitmap, - message->target_feature_bitmap, + message->source_feature_bitmap, message->target_feature_bitmap, message->rollback_feature_bitmap, &required_caps) || (local_capability_word & required_caps) != required_caps) return SEMANTIC_ACTIVATION_ACK_CONSUME_REJECTED; return semantic_activation_ack_lmon_install_authorized_request( - item, current_members_lo, current_members_hi, current_epoch, - current_coordinator_node, local_capability_word); + item, current_members_lo, current_members_hi, current_epoch, current_coordinator_node, + local_capability_word); } static SemanticActivationAckConsumeResult semantic_activation_ack_lmon_accept_current_barrier_request( const SemanticActivationAckIngressItem *item, - const SemanticActivationAdmissionSnapshot *snapshot, - uint64 current_members_lo, uint64 current_members_hi, - uint64 current_epoch, int32 current_coordinator_node, + const SemanticActivationAdmissionSnapshot *snapshot, uint64 current_members_lo, + uint64 current_members_hi, uint64 current_epoch, int32 current_coordinator_node, uint32 local_capability_word) { ClusterSemanticActivationAckTableV1 current; @@ -9762,53 +8483,39 @@ semantic_activation_ack_lmon_accept_current_barrier_request( uint32 required_caps; int32 local_node_id; - if (item == NULL || snapshot == NULL - || !semantic_activation_ack_table_snapshot(¤t)) + if (item == NULL || snapshot == NULL || !semantic_activation_ack_table_snapshot(¤t)) return SEMANTIC_ACTIVATION_ACK_CONSUME_REJECTED; message = &item->message; local_node_id = item->local_receiver_node_id; if (!semantic_activation_ack_wire_value_valid(message) - || message->kind - != CLUSTER_SEMANTIC_ACTIVATION_ACK_KIND_REQUEST - || message->stage - != CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_BARRIER - || message->result - != CLUSTER_SEMANTIC_ACTIVATION_ACK_RESULT_REQUEST - || current_coordinator_node < 0 - || current_coordinator_node >= CLUSTER_MAX_NODES + || message->kind != CLUSTER_SEMANTIC_ACTIVATION_ACK_KIND_REQUEST + || message->stage != CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_BARRIER + || message->result != CLUSTER_SEMANTIC_ACTIVATION_ACK_RESULT_REQUEST + || current_coordinator_node < 0 || current_coordinator_node >= CLUSTER_MAX_NODES || local_node_id < 0 || local_node_id >= CLUSTER_MAX_NODES || local_node_id == current_coordinator_node - || item->authenticated_source_node_id - != current_coordinator_node - || message->coordinator_node - != (uint32)current_coordinator_node + || item->authenticated_source_node_id != current_coordinator_node + || message->coordinator_node != (uint32)current_coordinator_node || message->member_node != (uint32)local_node_id || message->admitted_members_lo != current_members_lo || message->admitted_members_hi != current_members_hi || message->transition_epoch != current_epoch || !semantic_activation_ack_round_required_caps( - message->source_feature_bitmap, - message->target_feature_bitmap, + message->source_feature_bitmap, message->target_feature_bitmap, message->rollback_feature_bitmap, &required_caps) - || !semantic_activation_ack_member_present( - current_members_lo, current_members_hi, - current_coordinator_node) - || !semantic_activation_ack_member_present( - current_members_lo, current_members_hi, local_node_id) - || cluster_membership_get_state(current_coordinator_node) - != CLUSTER_MEMBER_MEMBER + || !semantic_activation_ack_member_present(current_members_lo, current_members_hi, + current_coordinator_node) + || !semantic_activation_ack_member_present(current_members_lo, current_members_hi, + local_node_id) + || cluster_membership_get_state(current_coordinator_node) != CLUSTER_MEMBER_MEMBER || item->sampled_capability_generation == 0 || (item->sampled_capability_word & required_caps) != required_caps || (local_capability_word & required_caps) != required_caps - || !cluster_sf_peer_capability_generation_matches( - current_coordinator_node, required_caps, - item->sampled_capability_generation) - || (snapshot->seq & UINT64_C(1)) != 0 - || snapshot->transition_closed - || snapshot->formation_epoch != current_epoch - || snapshot->record_generation == UINT64_MAX - || message->record_generation - != snapshot->record_generation + 1 + || !cluster_sf_peer_capability_generation_matches(current_coordinator_node, required_caps, + item->sampled_capability_generation) + || (snapshot->seq & UINT64_C(1)) != 0 || snapshot->transition_closed + || snapshot->formation_epoch != current_epoch || snapshot->record_generation == UINT64_MAX + || message->record_generation != snapshot->record_generation + 1 || snapshot->active_bits != message->source_feature_bitmap || current.coordinator_node != message->coordinator_node || current.round_nonce != message->round_nonce @@ -9816,42 +8523,33 @@ semantic_activation_ack_lmon_accept_current_barrier_request( || current.expected_members_hi != message->admitted_members_hi || current.transition_epoch != message->transition_epoch || current.record_generation != message->record_generation - || current.source_feature_bitmap - != message->source_feature_bitmap - || current.target_feature_bitmap - != message->target_feature_bitmap - || current.rollback_feature_bitmap - != message->rollback_feature_bitmap) + || current.source_feature_bitmap != message->source_feature_bitmap + || current.target_feature_bitmap != message->target_feature_bitmap + || current.rollback_feature_bitmap != message->rollback_feature_bitmap) return SEMANTIC_ACTIVATION_ACK_CONSUME_REJECTED; if (current.stage == CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_BARRIER) { - if (current.flags - != CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID - || current.capability_sample_digest - != message->capability_sample_digest - || current.observed_members_lo != 0 - || current.observed_members_hi != 0 - || !semantic_activation_bytes_are_zero( - (const uint8 *)current.observed, - sizeof(current.observed))) + if (current.flags != CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID + || current.capability_sample_digest != message->capability_sample_digest + || current.observed_members_lo != 0 || current.observed_members_hi != 0 + || !semantic_activation_bytes_are_zero((const uint8 *)current.observed, + sizeof(current.observed))) return SEMANTIC_ACTIVATION_ACK_CONSUME_REJECTED; return SEMANTIC_ACTIVATION_ACK_CONSUME_DUPLICATE; } if (current.stage != CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_SAMPLE || current.flags - != (CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID - | CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE) + != (CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID + | CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE) || current.capability_sample_digest != 0 || current.observed_members_lo != current.expected_members_lo || current.observed_members_hi != current.expected_members_hi || !semantic_activation_full_ack_table_matches( - current.observed, current.observed_members_lo, - current.observed_members_hi, current.expected, - current.expected_members_lo, current.expected_members_hi) + current.observed, current.observed_members_lo, current.observed_members_hi, + current.expected, current.expected_members_lo, current.expected_members_hi) || !semantic_activation_ack_complete_image_current( - ¤t, current_members_lo, current_members_hi, - current_epoch, current_coordinator_node, local_node_id, - local_capability_word)) + ¤t, current_members_lo, current_members_hi, current_epoch, + current_coordinator_node, local_node_id, local_capability_word)) return SEMANTIC_ACTIVATION_ACK_CONSUME_REJECTED; memcpy(&next, ¤t, sizeof(next)); @@ -9861,17 +8559,15 @@ semantic_activation_ack_lmon_accept_current_barrier_request( next.observed_members_hi = 0; next.capability_sample_digest = message->capability_sample_digest; memset(next.observed, 0, sizeof(next.observed)); - return semantic_activation_ack_table_publish(&next) - ? SEMANTIC_ACTIVATION_ACK_CONSUME_APPLIED - : SEMANTIC_ACTIVATION_ACK_CONSUME_REJECTED; + return semantic_activation_ack_table_publish(&next) ? SEMANTIC_ACTIVATION_ACK_CONSUME_APPLIED + : SEMANTIC_ACTIVATION_ACK_CONSUME_REJECTED; } static SemanticActivationAckConsumeResult semantic_activation_ack_lmon_accept_current_prepared_request( const SemanticActivationAckIngressItem *item, - const SemanticActivationAdmissionSnapshot *snapshot, - uint64 current_members_lo, uint64 current_members_hi, - uint64 current_epoch, int32 current_coordinator_node, + const SemanticActivationAdmissionSnapshot *snapshot, uint64 current_members_lo, + uint64 current_members_hi, uint64 current_epoch, int32 current_coordinator_node, uint32 local_capability_word) { ClusterSemanticActivationAckTableV1 current; @@ -9880,22 +8576,16 @@ semantic_activation_ack_lmon_accept_current_prepared_request( uint32 required_caps; int32 local_node_id; - if (item == NULL || snapshot == NULL - || !semantic_activation_ack_table_snapshot(¤t)) + if (item == NULL || snapshot == NULL || !semantic_activation_ack_table_snapshot(¤t)) return SEMANTIC_ACTIVATION_ACK_CONSUME_REJECTED; message = &item->message; local_node_id = item->local_receiver_node_id; if (!semantic_activation_ack_wire_value_valid(message) - || message->kind - != CLUSTER_SEMANTIC_ACTIVATION_ACK_KIND_REQUEST - || message->stage - != CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_PREPARED - || message->result - != CLUSTER_SEMANTIC_ACTIVATION_ACK_RESULT_REQUEST - || current_members_lo != UINT64_C(0x0f) - || current_members_hi != 0 - || current_coordinator_node != 0 - || local_node_id <= 0 || local_node_id >= 4 + || message->kind != CLUSTER_SEMANTIC_ACTIVATION_ACK_KIND_REQUEST + || message->stage != CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_PREPARED + || message->result != CLUSTER_SEMANTIC_ACTIVATION_ACK_RESULT_REQUEST + || current_members_lo != UINT64_C(0x0f) || current_members_hi != 0 + || current_coordinator_node != 0 || local_node_id <= 0 || local_node_id >= 4 || item->authenticated_source_node_id != current_coordinator_node || message->coordinator_node != (uint32)current_coordinator_node || message->member_node != (uint32)local_node_id @@ -9903,49 +8593,38 @@ semantic_activation_ack_lmon_accept_current_prepared_request( || message->admitted_members_hi != current_members_hi || message->transition_epoch != current_epoch || !semantic_activation_ack_round_required_caps( - message->source_feature_bitmap, - message->target_feature_bitmap, + message->source_feature_bitmap, message->target_feature_bitmap, message->rollback_feature_bitmap, &required_caps) - || cluster_membership_get_state(current_coordinator_node) - != CLUSTER_MEMBER_MEMBER + || cluster_membership_get_state(current_coordinator_node) != CLUSTER_MEMBER_MEMBER || item->sampled_capability_generation == 0 - || (item->sampled_capability_word & required_caps) - != required_caps + || (item->sampled_capability_word & required_caps) != required_caps || (local_capability_word & required_caps) != required_caps - || !cluster_sf_peer_capability_generation_matches( - current_coordinator_node, required_caps, - item->sampled_capability_generation) - || (snapshot->seq & UINT64_C(1)) != 0 - || !snapshot->transition_closed + || !cluster_sf_peer_capability_generation_matches(current_coordinator_node, required_caps, + item->sampled_capability_generation) + || (snapshot->seq & UINT64_C(1)) != 0 || !snapshot->transition_closed || snapshot->formation_epoch != current_epoch || snapshot->record_generation != message->record_generation || snapshot->active_bits != message->source_feature_bitmap - || current.stage - != CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_BARRIER + || current.stage != CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_BARRIER || current.flags - != (CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID - | CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE) + != (CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID + | CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE) || current.coordinator_node != message->coordinator_node || current.round_nonce != message->round_nonce || current.expected_members_lo != message->admitted_members_lo || current.expected_members_hi != message->admitted_members_hi || current.transition_epoch != message->transition_epoch || current.record_generation != message->record_generation - || current.source_feature_bitmap - != message->source_feature_bitmap - || current.target_feature_bitmap - != message->target_feature_bitmap - || current.rollback_feature_bitmap - != message->rollback_feature_bitmap + || current.source_feature_bitmap != message->source_feature_bitmap + || current.target_feature_bitmap != message->target_feature_bitmap + || current.rollback_feature_bitmap != message->rollback_feature_bitmap || current.capability_sample_digest == 0 - || current.capability_sample_digest - != message->capability_sample_digest + || current.capability_sample_digest != message->capability_sample_digest || current.observed_members_lo != current.expected_members_lo || current.observed_members_hi != current.expected_members_hi || !semantic_activation_ack_complete_image_current( - ¤t, current_members_lo, current_members_hi, - current_epoch, current_coordinator_node, local_node_id, - local_capability_word)) + ¤t, current_members_lo, current_members_hi, current_epoch, + current_coordinator_node, local_node_id, local_capability_word)) return SEMANTIC_ACTIVATION_ACK_CONSUME_REJECTED; next = current; @@ -9954,17 +8633,15 @@ semantic_activation_ack_lmon_accept_current_prepared_request( next.observed_members_lo = 0; next.observed_members_hi = 0; memset(next.observed, 0, sizeof(next.observed)); - return semantic_activation_ack_table_publish(&next) - ? SEMANTIC_ACTIVATION_ACK_CONSUME_APPLIED - : SEMANTIC_ACTIVATION_ACK_CONSUME_REJECTED; + return semantic_activation_ack_table_publish(&next) ? SEMANTIC_ACTIVATION_ACK_CONSUME_APPLIED + : SEMANTIC_ACTIVATION_ACK_CONSUME_REJECTED; } static SemanticActivationAckConsumeResult semantic_activation_ack_lmon_accept_current_commit_applied_request( const SemanticActivationAckIngressItem *item, - const SemanticActivationAdmissionSnapshot *snapshot, - uint64 current_members_lo, uint64 current_members_hi, - uint64 current_epoch, int32 current_coordinator_node, + const SemanticActivationAdmissionSnapshot *snapshot, uint64 current_members_lo, + uint64 current_members_hi, uint64 current_epoch, int32 current_coordinator_node, uint32 local_capability_word) { ClusterSemanticActivationAckTableV1 current; @@ -9975,24 +8652,17 @@ semantic_activation_ack_lmon_accept_current_commit_applied_request( uint32 predecessor_stage; int node; - if (item == NULL || snapshot == NULL - || !semantic_activation_ack_table_snapshot(¤t)) + if (item == NULL || snapshot == NULL || !semantic_activation_ack_table_snapshot(¤t)) return SEMANTIC_ACTIVATION_ACK_CONSUME_REJECTED; message = &item->message; local_node_id = item->local_receiver_node_id; if (!semantic_activation_ack_wire_value_valid(message) - || message->kind - != CLUSTER_SEMANTIC_ACTIVATION_ACK_KIND_REQUEST - || (message->stage - != CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_COMMIT_APPLIED - && message->stage - != CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_OPEN_APPLIED) - || message->result - != CLUSTER_SEMANTIC_ACTIVATION_ACK_RESULT_REQUEST - || current_members_lo != UINT64_C(0x0f) - || current_members_hi != 0 - || current_coordinator_node != 0 - || local_node_id <= 0 || local_node_id >= 4 + || message->kind != CLUSTER_SEMANTIC_ACTIVATION_ACK_KIND_REQUEST + || (message->stage != CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_COMMIT_APPLIED + && message->stage != CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_OPEN_APPLIED) + || message->result != CLUSTER_SEMANTIC_ACTIVATION_ACK_RESULT_REQUEST + || current_members_lo != UINT64_C(0x0f) || current_members_hi != 0 + || current_coordinator_node != 0 || local_node_id <= 0 || local_node_id >= 4 || item->authenticated_source_node_id != current_coordinator_node || message->coordinator_node != (uint32)current_coordinator_node || message->member_node != (uint32)local_node_id @@ -10000,54 +8670,41 @@ semantic_activation_ack_lmon_accept_current_commit_applied_request( || message->admitted_members_hi != current_members_hi || message->transition_epoch != current_epoch || !semantic_activation_ack_round_required_caps( - message->source_feature_bitmap, - message->target_feature_bitmap, + message->source_feature_bitmap, message->target_feature_bitmap, message->rollback_feature_bitmap, &required_caps) - || cluster_membership_get_state(current_coordinator_node) - != CLUSTER_MEMBER_MEMBER + || cluster_membership_get_state(current_coordinator_node) != CLUSTER_MEMBER_MEMBER || item->sampled_capability_generation == 0 - || (item->sampled_capability_word & required_caps) - != required_caps + || (item->sampled_capability_word & required_caps) != required_caps || (local_capability_word & required_caps) != required_caps - || !cluster_sf_peer_capability_generation_matches( - current_coordinator_node, required_caps, - item->sampled_capability_generation) - || (snapshot->seq & UINT64_C(1)) != 0 - || !snapshot->transition_closed - || snapshot->formation_epoch != current_epoch - || snapshot->record_generation == UINT64_MAX - || snapshot->record_generation + 1 - != message->record_generation + || !cluster_sf_peer_capability_generation_matches(current_coordinator_node, required_caps, + item->sampled_capability_generation) + || (snapshot->seq & UINT64_C(1)) != 0 || !snapshot->transition_closed + || snapshot->formation_epoch != current_epoch || snapshot->record_generation == UINT64_MAX + || snapshot->record_generation + 1 != message->record_generation || snapshot->active_bits != message->source_feature_bitmap || current.stage - != (message->stage - == CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_COMMIT_APPLIED - ? CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_PREPARED - : CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_COMMIT_APPLIED) + != (message->stage == CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_COMMIT_APPLIED + ? CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_PREPARED + : CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_COMMIT_APPLIED) || current.flags - != (CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID - | CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE) + != (CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID + | CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE) || current.coordinator_node != message->coordinator_node || current.round_nonce != message->round_nonce || current.expected_members_lo != message->admitted_members_lo || current.expected_members_hi != message->admitted_members_hi || current.transition_epoch != message->transition_epoch || current.record_generation != snapshot->record_generation - || current.source_feature_bitmap - != message->source_feature_bitmap - || current.target_feature_bitmap - != message->target_feature_bitmap - || current.rollback_feature_bitmap - != message->rollback_feature_bitmap + || current.source_feature_bitmap != message->source_feature_bitmap + || current.target_feature_bitmap != message->target_feature_bitmap + || current.rollback_feature_bitmap != message->rollback_feature_bitmap || current.capability_sample_digest == 0 - || current.capability_sample_digest - != message->capability_sample_digest + || current.capability_sample_digest != message->capability_sample_digest || current.observed_members_lo != current.expected_members_lo || current.observed_members_hi != current.expected_members_hi || !semantic_activation_ack_complete_image_current( - ¤t, current_members_lo, current_members_hi, - current_epoch, current_coordinator_node, local_node_id, - local_capability_word)) + ¤t, current_members_lo, current_members_hi, current_epoch, + current_coordinator_node, local_node_id, local_capability_word)) return SEMANTIC_ACTIVATION_ACK_CONSUME_REJECTED; predecessor_stage = current.stage; @@ -10062,23 +8719,17 @@ semantic_activation_ack_lmon_accept_current_commit_applied_request( next.expected[node].record_generation = message->record_generation; /* Preserve an explicit predecessor-stage read in this shared COMMIT/OPEN * validator so a future stage extension cannot silently skip one link. */ - if ((message->stage - == CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_COMMIT_APPLIED - && predecessor_stage - != CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_PREPARED) - || (message->stage - == CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_OPEN_APPLIED - && predecessor_stage - != CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_COMMIT_APPLIED)) + if ((message->stage == CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_COMMIT_APPLIED + && predecessor_stage != CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_PREPARED) + || (message->stage == CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_OPEN_APPLIED + && predecessor_stage != CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_COMMIT_APPLIED)) return SEMANTIC_ACTIVATION_ACK_CONSUME_REJECTED; if (!semantic_activation_ack_expected_image_current( - &next, current_members_lo, current_members_hi, - current_epoch, current_coordinator_node, local_node_id, - local_capability_word)) + &next, current_members_lo, current_members_hi, current_epoch, current_coordinator_node, + local_node_id, local_capability_word)) return SEMANTIC_ACTIVATION_ACK_CONSUME_REJECTED; - return semantic_activation_ack_table_publish(&next) - ? SEMANTIC_ACTIVATION_ACK_CONSUME_APPLIED - : SEMANTIC_ACTIVATION_ACK_CONSUME_REJECTED; + return semantic_activation_ack_table_publish(&next) ? SEMANTIC_ACTIVATION_ACK_CONSUME_APPLIED + : SEMANTIC_ACTIVATION_ACK_CONSUME_REJECTED; } static bool @@ -10194,9 +8845,8 @@ semantic_activation_release_debt(ClusterSemanticAdmissionSide side, int feature_ } static ClusterSemanticAdmissionResult -semantic_activation_enter_internal(uint64 feature_bit, - ClusterSemanticAdmissionSide side, ClusterSemanticAdmissionToken *token, - bool terminal_census) +semantic_activation_enter_internal(uint64 feature_bit, ClusterSemanticAdmissionSide side, + ClusterSemanticAdmissionToken *token, bool terminal_census) { SemanticActivationAdmissionSnapshot before; SemanticActivationAdmissionSnapshot after; @@ -10278,24 +8928,22 @@ semantic_activation_enter_internal(uint64 feature_bit, } ClusterSemanticAdmissionResult -cluster_semantic_activation_enter(uint64 feature_bit, - ClusterSemanticAdmissionSide side, ClusterSemanticAdmissionToken *token) +cluster_semantic_activation_enter(uint64 feature_bit, ClusterSemanticAdmissionSide side, + ClusterSemanticAdmissionToken *token) { return semantic_activation_enter_internal(feature_bit, side, token, false); } ClusterSemanticAdmissionResult -cluster_semantic_activation_enter_r4_terminal_census( - ClusterSemanticAdmissionToken *token) +cluster_semantic_activation_enter_r4_terminal_census(ClusterSemanticAdmissionToken *token) { - return semantic_activation_enter_internal( - CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, - CLUSTER_SEMANTIC_TARGET_SIDE, token, true); + return semantic_activation_enter_internal(CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, + CLUSTER_SEMANTIC_TARGET_SIDE, token, true); } ClusterSemanticAdmissionResult cluster_semantic_activation_modifier_enter(bool writable_admission, - ClusterSemanticAdmissionToken *token) + ClusterSemanticAdmissionToken *token) { SemanticActivationAdmissionSnapshot snapshot; ClusterSemanticAdmissionSide side; @@ -10316,16 +8964,15 @@ cluster_semantic_activation_modifier_enter(bool writable_admission, return CLUSTER_SEMANTIC_ADMISSION_CLOSED; return semantic_activation_modifier_enter_bootstrap(writable_admission, token); } else { - if (!semantic_activation_modifier_policy( - snapshot.active_bits, snapshot.record_generation, snapshot.transition_closed)) + if (!semantic_activation_modifier_policy(snapshot.active_bits, snapshot.record_generation, + snapshot.transition_closed)) return CLUSTER_SEMANTIC_ADMISSION_CLOSED; side = (snapshot.active_bits & CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1) != 0 ? CLUSTER_SEMANTIC_TARGET_SIDE : CLUSTER_SEMANTIC_SOURCE_SIDE; } - return cluster_semantic_activation_enter( - CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, side, token); + return cluster_semantic_activation_enter(CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, side, token); } bool @@ -10409,30 +9056,26 @@ semantic_activation_pgrd_snapshot_clear(void) if (SemanticActivationPgrdSnapshot == NULL) return; - seq = pg_atomic_read_u64( - &SemanticActivationPgrdSnapshot->publication_seq); + seq = pg_atomic_read_u64(&SemanticActivationPgrdSnapshot->publication_seq); if ((seq & UINT64_C(1)) != 0) { pg_atomic_write_u32(&SemanticActivationPgrdSnapshot->present, 0); return; } if (seq > UINT64_MAX - 2) { - pg_atomic_write_u64(&SemanticActivationPgrdSnapshot->publication_seq, - UINT64_MAX); + pg_atomic_write_u64(&SemanticActivationPgrdSnapshot->publication_seq, UINT64_MAX); pg_write_barrier(); pg_atomic_write_u32(&SemanticActivationPgrdSnapshot->present, 0); return; } - pg_atomic_write_u64(&SemanticActivationPgrdSnapshot->publication_seq, - seq + 1); + pg_atomic_write_u64(&SemanticActivationPgrdSnapshot->publication_seq, seq + 1); pg_write_barrier(); pg_atomic_write_u32(&SemanticActivationPgrdSnapshot->present, 0); memset(SemanticActivationPgrdSnapshot->descriptor_bytes, 0, sizeof(SemanticActivationPgrdSnapshot->descriptor_bytes)); SemanticActivationPgrdSnapshot->reserved = 0; pg_write_barrier(); - pg_atomic_write_u64(&SemanticActivationPgrdSnapshot->publication_seq, - seq + 2); + pg_atomic_write_u64(&SemanticActivationPgrdSnapshot->publication_seq, seq + 2); } static bool @@ -10443,43 +9086,35 @@ semantic_activation_pgrd_snapshot_publish( uint64 seq; if (SemanticActivationPgrdSnapshot == NULL || descriptor_bytes == NULL - || cluster_undo_root_descriptor_decode( - descriptor_bytes, GetSystemIdentifier(), &descriptor) + || cluster_undo_root_descriptor_decode(descriptor_bytes, GetSystemIdentifier(), &descriptor) != CLUSTER_UNDO_ROOT_DESCRIPTOR_VALID - || descriptor.root_kind != CLUSTER_UNDO_ROOT_KIND_SHARED - || descriptor.owner_node != -1) + || descriptor.root_kind != CLUSTER_UNDO_ROOT_KIND_SHARED || descriptor.owner_node != -1) return false; - seq = pg_atomic_read_u64( - &SemanticActivationPgrdSnapshot->publication_seq); + seq = pg_atomic_read_u64(&SemanticActivationPgrdSnapshot->publication_seq); if ((seq & UINT64_C(1)) != 0) return false; if (seq > UINT64_MAX - 2) { - pg_atomic_write_u64(&SemanticActivationPgrdSnapshot->publication_seq, - UINT64_MAX); + pg_atomic_write_u64(&SemanticActivationPgrdSnapshot->publication_seq, UINT64_MAX); pg_write_barrier(); pg_atomic_write_u32(&SemanticActivationPgrdSnapshot->present, 0); return false; } - pg_atomic_write_u64(&SemanticActivationPgrdSnapshot->publication_seq, - seq + 1); + pg_atomic_write_u64(&SemanticActivationPgrdSnapshot->publication_seq, seq + 1); pg_write_barrier(); pg_atomic_write_u32(&SemanticActivationPgrdSnapshot->present, 0); - memcpy(SemanticActivationPgrdSnapshot->descriptor_bytes, - descriptor_bytes, + memcpy(SemanticActivationPgrdSnapshot->descriptor_bytes, descriptor_bytes, sizeof(SemanticActivationPgrdSnapshot->descriptor_bytes)); SemanticActivationPgrdSnapshot->reserved = 0; pg_write_barrier(); pg_atomic_write_u32(&SemanticActivationPgrdSnapshot->present, 1); pg_write_barrier(); - pg_atomic_write_u64(&SemanticActivationPgrdSnapshot->publication_seq, - seq + 2); + pg_atomic_write_u64(&SemanticActivationPgrdSnapshot->publication_seq, seq + 2); return true; } static bool -semantic_activation_pgrd_snapshot_copy( - uint8 descriptor_bytes[CLUSTER_UNDO_ROOT_DESCRIPTOR_BYTES]) +semantic_activation_pgrd_snapshot_copy(uint8 descriptor_bytes[CLUSTER_UNDO_ROOT_DESCRIPTOR_BYTES]) { uint64 seq_before; uint64 seq_after; @@ -10488,35 +9123,29 @@ semantic_activation_pgrd_snapshot_copy( if (SemanticActivationPgrdSnapshot == NULL || descriptor_bytes == NULL) return false; - for (attempt = 0; attempt < CLUSTER_SEMANTIC_ADMISSION_SNAPSHOT_TRIES; - attempt++) { - seq_before = pg_atomic_read_u64( - &SemanticActivationPgrdSnapshot->publication_seq); + for (attempt = 0; attempt < CLUSTER_SEMANTIC_ADMISSION_SNAPSHOT_TRIES; attempt++) { + seq_before = pg_atomic_read_u64(&SemanticActivationPgrdSnapshot->publication_seq); if ((seq_before & UINT64_C(1)) != 0) continue; pg_read_barrier(); - if (pg_atomic_read_u32(&SemanticActivationPgrdSnapshot->present) - != 1) + if (pg_atomic_read_u32(&SemanticActivationPgrdSnapshot->present) != 1) return false; - memcpy(descriptor_bytes, - SemanticActivationPgrdSnapshot->descriptor_bytes, + memcpy(descriptor_bytes, SemanticActivationPgrdSnapshot->descriptor_bytes, CLUSTER_UNDO_ROOT_DESCRIPTOR_BYTES); reserved = SemanticActivationPgrdSnapshot->reserved; pg_read_barrier(); - seq_after = pg_atomic_read_u64( - &SemanticActivationPgrdSnapshot->publication_seq); - if (seq_before == seq_after - && (seq_after & UINT64_C(1)) == 0) + seq_after = pg_atomic_read_u64(&SemanticActivationPgrdSnapshot->publication_seq); + if (seq_before == seq_after && (seq_after & UINT64_C(1)) == 0) return reserved == 0; } return false; } static bool -semantic_activation_resolve_shared_undo_root( - const ClusterSemanticAdmissionToken *token, ClusterUndoPathIntent intent, - uint32 owner_instance, uint32 segment_id, - ClusterUndoBlock0ResolvedRoot *out, bool terminal_census) +semantic_activation_resolve_shared_undo_root(const ClusterSemanticAdmissionToken *token, + ClusterUndoPathIntent intent, uint32 owner_instance, + uint32 segment_id, ClusterUndoBlock0ResolvedRoot *out, + bool terminal_census) { ClusterUndoBlock0ResolvedRoot resolved; ClusterUndoRootDescriptorV1 descriptor; @@ -10525,18 +9154,15 @@ semantic_activation_resolve_shared_undo_root( if (token == NULL || out == NULL || !token->entered || token->feature_bit != CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1 || token->side != CLUSTER_SEMANTIC_TARGET_SIDE - || !(terminal_census - ? cluster_semantic_activation_recheck_r4_terminal_census(token) - : cluster_semantic_activation_recheck(token)) + || !(terminal_census ? cluster_semantic_activation_recheck_r4_terminal_census(token) + : cluster_semantic_activation_recheck(token)) || !semantic_activation_pgrd_snapshot_copy(descriptor_bytes) - || cluster_undo_root_descriptor_decode( - descriptor_bytes, GetSystemIdentifier(), &descriptor) + || cluster_undo_root_descriptor_decode(descriptor_bytes, GetSystemIdentifier(), &descriptor) != CLUSTER_UNDO_ROOT_DESCRIPTOR_VALID - || !cluster_undo_root_descriptor_resolve( - &descriptor, intent, owner_instance, segment_id, &resolved) - || !(terminal_census - ? cluster_semantic_activation_recheck_r4_terminal_census(token) - : cluster_semantic_activation_recheck(token))) + || !cluster_undo_root_descriptor_resolve(&descriptor, intent, owner_instance, segment_id, + &resolved) + || !(terminal_census ? cluster_semantic_activation_recheck_r4_terminal_census(token) + : cluster_semantic_activation_recheck(token))) return false; *out = resolved; @@ -10544,32 +9170,30 @@ semantic_activation_resolve_shared_undo_root( } bool -cluster_semantic_activation_resolve_shared_undo_root( - const ClusterSemanticAdmissionToken *token, ClusterUndoPathIntent intent, - uint32 owner_instance, uint32 segment_id, - ClusterUndoBlock0ResolvedRoot *out) +cluster_semantic_activation_resolve_shared_undo_root(const ClusterSemanticAdmissionToken *token, + ClusterUndoPathIntent intent, + uint32 owner_instance, uint32 segment_id, + ClusterUndoBlock0ResolvedRoot *out) { - return semantic_activation_resolve_shared_undo_root( - token, intent, owner_instance, segment_id, out, false); + return semantic_activation_resolve_shared_undo_root(token, intent, owner_instance, segment_id, + out, false); } bool cluster_semantic_activation_resolve_shared_undo_root_r4_terminal_census( - const ClusterSemanticAdmissionToken *token, ClusterUndoPathIntent intent, - uint32 owner_instance, uint32 segment_id, - ClusterUndoBlock0ResolvedRoot *out) + const ClusterSemanticAdmissionToken *token, ClusterUndoPathIntent intent, uint32 owner_instance, + uint32 segment_id, ClusterUndoBlock0ResolvedRoot *out) { if (intent != CLUSTER_UNDO_PATH_RUNTIME_SHARED) return false; - return semantic_activation_resolve_shared_undo_root( - token, intent, owner_instance, segment_id, out, true); + return semantic_activation_resolve_shared_undo_root(token, intent, owner_instance, segment_id, + out, true); } bool cluster_semantic_activation_resolve_shared_undo_root_live_owner_source( - const ClusterSemanticAdmissionToken *token, ClusterUndoPathIntent intent, - uint32 owner_instance, uint32 segment_id, - ClusterUndoBlock0ResolvedRoot *out) + const ClusterSemanticAdmissionToken *token, ClusterUndoPathIntent intent, uint32 owner_instance, + uint32 segment_id, ClusterUndoBlock0ResolvedRoot *out) { ClusterUndoBlock0ResolvedRoot resolved; ClusterUndoRootDescriptorV1 descriptor; @@ -10577,17 +9201,14 @@ cluster_semantic_activation_resolve_shared_undo_root_live_owner_source( if (token == NULL || out == NULL || !token->entered || token->feature_bit != CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1 - || token->side != CLUSTER_SEMANTIC_SOURCE_SIDE - || intent != CLUSTER_UNDO_PATH_RUNTIME_SHARED - || cluster_node_id < 0 - || owner_instance != (uint32)cluster_node_id + 1 + || token->side != CLUSTER_SEMANTIC_SOURCE_SIDE || intent != CLUSTER_UNDO_PATH_RUNTIME_SHARED + || cluster_node_id < 0 || owner_instance != (uint32)cluster_node_id + 1 || !cluster_semantic_activation_recheck(token) || !semantic_activation_pgrd_snapshot_copy(descriptor_bytes) - || cluster_undo_root_descriptor_decode( - descriptor_bytes, GetSystemIdentifier(), &descriptor) - != CLUSTER_UNDO_ROOT_DESCRIPTOR_VALID - || !cluster_undo_root_descriptor_resolve( - &descriptor, intent, owner_instance, segment_id, &resolved) + || cluster_undo_root_descriptor_decode(descriptor_bytes, GetSystemIdentifier(), &descriptor) + != CLUSTER_UNDO_ROOT_DESCRIPTOR_VALID + || !cluster_undo_root_descriptor_resolve(&descriptor, intent, owner_instance, segment_id, + &resolved) || !cluster_semantic_activation_recheck(token)) return false; @@ -10636,8 +9257,7 @@ cluster_semantic_activation_restore_open_proof_if_active(void) bool implicit_open = false; int node; - if (SemanticActivationAckTable == NULL - || !cluster_r4_bit22_cutover_active() + if (SemanticActivationAckTable == NULL || !cluster_r4_bit22_cutover_active() || !semantic_activation_ack_table_snapshot(&table)) return false; if ((table.flags & CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_OPEN_PROOF) != 0) @@ -10656,37 +9276,32 @@ cluster_semantic_activation_restore_open_proof_if_active(void) * the latch restore (contract). `implicit_open` is NOT a gate: it * only reports the all-zero pre-R4 sentinel, while a real durable * OPEN(P+2) record reads back nonzero. */ - qv_result = cluster_qvotec_bootstrap_read_semantic_activation( - selected, &implicit_open); - (void) implicit_open; + qv_result = cluster_qvotec_bootstrap_read_semantic_activation(selected, &implicit_open); + (void)implicit_open; if (qv_result != CLUSTER_SEMANTIC_ACTIVATION_OK || !cluster_semantic_activation_record_decode(selected, &open, NULL) - || open.phase != CLUSTER_SEMANTIC_PHASE_OPEN - || open.record_generation < 3) + || open.phase != CLUSTER_SEMANTIC_PHASE_OPEN || open.record_generation < 3) return false; root_result = cluster_control_root_bootstrap_validate_active_round_fields( - open.transition_epoch, open.record_generation - 2, - open.source_feature_bitmap, open.target_feature_bitmap); + open.transition_epoch, open.record_generation - 2, open.source_feature_bitmap, + open.target_feature_bitmap); if (root_result != CLUSTER_CONTROL_ROOT_OK_PRIMARY && root_result != CLUSTER_CONTROL_ROOT_OK_PRIMARY_DEGRADED) return false; /* Current formation/member revalidation (§4). */ - if (!semantic_activation_ack_current_authority( - cluster_node_id, &members_lo, &members_hi, &formation_epoch, - ¤t_coordinator_node) - || members_lo != open.admitted_members_lo - || members_hi != open.admitted_members_hi - || (uint32) current_coordinator_node != open.coordinator_node + if (!semantic_activation_ack_current_authority(cluster_node_id, &members_lo, &members_hi, + &formation_epoch, ¤t_coordinator_node) + || members_lo != open.admitted_members_lo || members_hi != open.admitted_members_hi + || (uint32)current_coordinator_node != open.coordinator_node || formation_epoch != open.transition_epoch) return false; current_epoch = cluster_epoch_get_current(); if (formation_epoch != current_epoch) return false; local_capability_word = cluster_ic_local_capability_word(); - if (!semantic_activation_ack_self_tuple( - cluster_node_id, local_capability_word, - open.transition_epoch, open.record_generation, &self)) + if (!semantic_activation_ack_self_tuple(cluster_node_id, local_capability_word, + open.transition_epoch, open.record_generation, &self)) return false; memset(&rebuilt, 0, sizeof(rebuilt)); @@ -10695,7 +9310,7 @@ cluster_semantic_activation_restore_open_proof_if_active(void) | CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE | CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_OPEN_PROOF; rebuilt.coordinator_node = open.coordinator_node; - rebuilt.round_nonce = 1; /* reconstruction: no pre-restart nonce + rebuilt.round_nonce = 1; /* reconstruction: no pre-restart nonce * survives; identity is epoch+generation */ rebuilt.transition_epoch = open.transition_epoch; rebuilt.record_generation = open.record_generation; @@ -10712,8 +9327,7 @@ cluster_semantic_activation_restore_open_proof_if_active(void) uint32 peer_word; uint32 peer_gen; - if (!semantic_activation_ack_member_present( - members_lo, members_hi, node)) + if (!semantic_activation_ack_member_present(members_lo, members_hi, node)) continue; if (node == cluster_node_id) { rebuilt.expected[node] = self; @@ -10721,19 +9335,17 @@ cluster_semantic_activation_restore_open_proof_if_active(void) continue; } memset(&remote, 0, sizeof(remote)); - remote.node_id = (uint32) node; - remote.boot_id - = cluster_membership_get_last_admitted_incarnation(node); + remote.node_id = (uint32)node; + remote.boot_id = cluster_membership_get_last_admitted_incarnation(node); remote.admitted_incarnation = remote.boot_id; if (remote.boot_id == 0 || !cluster_sf_peer_capability_word_sample( - node, CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS, - &peer_word, &peer_gen) + node, CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS, &peer_word, &peer_gen) || peer_gen == 0) return false; - remote.control_connection_generation = (uint64) peer_gen; + remote.control_connection_generation = (uint64)peer_gen; remote.capability_word = peer_word; - remote.capability_generation = (uint64) peer_gen; + remote.capability_generation = (uint64)peer_gen; remote.transition_epoch = open.transition_epoch; remote.record_generation = open.record_generation; rebuilt.expected[node] = remote; @@ -10741,18 +9353,18 @@ cluster_semantic_activation_restore_open_proof_if_active(void) } if (!semantic_activation_ack_table_publish(&rebuilt)) return false; - ereport(LOG, - (errmsg("bit22 cutover: OPEN_PROOF reconstructed from durable " - "OPEN (gen %llu, epoch %llu) — post-bit22 gates armed", - (unsigned long long) open.record_generation, - (unsigned long long) open.transition_epoch))); + ereport(LOG, (errmsg("bit22 cutover: OPEN_PROOF reconstructed from durable " + "OPEN (gen %llu, epoch %llu) — post-bit22 gates armed", + (unsigned long long)open.record_generation, + (unsigned long long)open.transition_epoch))); return true; } bool -cluster_semantic_activation_peer_open_matches( - const ClusterSemanticAdmissionToken *token, int32 authenticated_peer_node_id, - uint32 required_hello_caps, uint32 sampled_capability_generation) +cluster_semantic_activation_peer_open_matches(const ClusterSemanticAdmissionToken *token, + int32 authenticated_peer_node_id, + uint32 required_hello_caps, + uint32 sampled_capability_generation) { ClusterSemanticActivationAckTableV1 table; uint64 members_lo; @@ -10804,15 +9416,13 @@ cluster_semantic_activation_peer_open_matches( * accepting the authenticated peer generation so a partial or cross-round * ACK table never authorizes kind-9 traffic. */ ClusterSemanticResourceXPeerOpenResult -cluster_semantic_activation_resource_x_peer_open_check( - const ClusterSemanticAdmissionToken *token, - int32 authenticated_peer_node_id, - uint32 sampled_capability_generation) +cluster_semantic_activation_resource_x_peer_open_check(const ClusterSemanticAdmissionToken *token, + int32 authenticated_peer_node_id, + uint32 sampled_capability_generation) { const uint64 source_bits = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1; - const uint64 target_bits - = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1 - | CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1; + const uint64 target_bits = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1 + | CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1; ClusterSemanticActivationAckTableV1 table; uint64 current_members_lo; uint64 current_members_hi; @@ -10824,12 +9434,9 @@ cluster_semantic_activation_resource_x_peer_open_check( bool capability_pending; if (token == NULL || !token->entered - || token->feature_bit - != CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1 - || token->side != CLUSTER_SEMANTIC_TARGET_SIDE - || authenticated_peer_node_id < 0 - || authenticated_peer_node_id >= CLUSTER_MAX_NODES - || sampled_capability_generation == 0) + || token->feature_bit != CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1 + || token->side != CLUSTER_SEMANTIC_TARGET_SIDE || authenticated_peer_node_id < 0 + || authenticated_peer_node_id >= CLUSTER_MAX_NODES || sampled_capability_generation == 0) return CLUSTER_SEMANTIC_RESOURCE_X_PEER_OPEN_INVALID_INPUT; if (!cluster_semantic_activation_recheck(token)) return CLUSTER_SEMANTIC_RESOURCE_X_PEER_OPEN_ADMISSION_DRIFT; @@ -10840,16 +9447,15 @@ cluster_semantic_activation_resource_x_peer_open_check( && ((capability.bits & PGRAC_IC_HELLO_CAP_GCS_RESOURCE_X_CONVERT_V1) == 0 || capability.generation != sampled_capability_generation)) return CLUSTER_SEMANTIC_RESOURCE_X_PEER_OPEN_CAPABILITY_DRIFT; - if (!semantic_activation_ack_current_authority( - cluster_node_id, ¤t_members_lo, ¤t_members_hi, - ¤t_epoch, ¤t_coordinator_node)) + if (!semantic_activation_ack_current_authority(cluster_node_id, ¤t_members_lo, + ¤t_members_hi, ¤t_epoch, + ¤t_coordinator_node)) return CLUSTER_SEMANTIC_RESOURCE_X_PEER_OPEN_AUTHORITY_UNAVAILABLE; if (SemanticActivationAckTable == NULL) return CLUSTER_SEMANTIC_RESOURCE_X_PEER_OPEN_TABLE_UNAVAILABLE; if (!semantic_activation_ack_table_snapshot(&table)) return CLUSTER_SEMANTIC_RESOURCE_X_PEER_OPEN_TABLE_TORN; - if (table.stage - != CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_OPEN_APPLIED) + if (table.stage != CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_OPEN_APPLIED) return CLUSTER_SEMANTIC_RESOURCE_X_PEER_OPEN_STAGE_MISMATCH; if (table.flags != (CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID @@ -10859,17 +9465,14 @@ cluster_semantic_activation_resource_x_peer_open_check( return CLUSTER_SEMANTIC_RESOURCE_X_PEER_OPEN_RECORD_MISMATCH; if (table.transition_epoch != token->formation_epoch) return CLUSTER_SEMANTIC_RESOURCE_X_PEER_OPEN_FORMATION_MISMATCH; - if (table.source_feature_bitmap != source_bits - || table.target_feature_bitmap != target_bits + if (table.source_feature_bitmap != source_bits || table.target_feature_bitmap != target_bits || table.rollback_feature_bitmap != 0) return CLUSTER_SEMANTIC_RESOURCE_X_PEER_OPEN_FEATURE_MISMATCH; if (!semantic_activation_ack_member_present( - table.expected_members_lo, table.expected_members_hi, - authenticated_peer_node_id)) + table.expected_members_lo, table.expected_members_hi, authenticated_peer_node_id)) return CLUSTER_SEMANTIC_RESOURCE_X_PEER_OPEN_PEER_ABSENT; - if (!semantic_activation_ack_matches( - &table.observed[authenticated_peer_node_id], - &table.expected[authenticated_peer_node_id])) + if (!semantic_activation_ack_matches(&table.observed[authenticated_peer_node_id], + &table.expected[authenticated_peer_node_id])) return CLUSTER_SEMANTIC_RESOURCE_X_PEER_OPEN_PEER_ROW_MISMATCH; local_capability_word = cluster_ic_local_capability_word(); @@ -10884,15 +9487,13 @@ cluster_semantic_activation_resource_x_peer_open_check( } bool -cluster_semantic_activation_resource_x_peer_open_matches( - const ClusterSemanticAdmissionToken *token, - int32 authenticated_peer_node_id, - uint32 sampled_capability_generation) +cluster_semantic_activation_resource_x_peer_open_matches(const ClusterSemanticAdmissionToken *token, + int32 authenticated_peer_node_id, + uint32 sampled_capability_generation) { - return cluster_semantic_activation_resource_x_peer_open_check( - token, authenticated_peer_node_id, - sampled_capability_generation) - == CLUSTER_SEMANTIC_RESOURCE_X_PEER_OPEN_MATCH; + return cluster_semantic_activation_resource_x_peer_open_check(token, authenticated_peer_node_id, + sampled_capability_generation) + == CLUSTER_SEMANTIC_RESOURCE_X_PEER_OPEN_MATCH; } void @@ -10987,10 +9588,8 @@ cluster_semantic_activation_shmem_init(void) pg_atomic_init_u64(&SemanticActivationAckTable->publication_seq, 0); } if (!pgrd_snapshot_found) { - memset(SemanticActivationPgrdSnapshot, 0, - sizeof(*SemanticActivationPgrdSnapshot)); - pg_atomic_init_u64( - &SemanticActivationPgrdSnapshot->publication_seq, 0); + memset(SemanticActivationPgrdSnapshot, 0, sizeof(*SemanticActivationPgrdSnapshot)); + pg_atomic_init_u64(&SemanticActivationPgrdSnapshot->publication_seq, 0); pg_atomic_init_u32(&SemanticActivationPgrdSnapshot->present, 0); } @@ -11013,20 +9612,15 @@ cluster_semantic_activation_shmem_init(void) pg_atomic_init_u32(&SemanticActivationShmem->transition_closed, 1); for (side = 0; side < 2; side++) { for (feature_index = 0; feature_index < 64; feature_index++) - pg_atomic_init_u32( - &SemanticActivationShmem->inflight[side][feature_index], 0); + pg_atomic_init_u32(&SemanticActivationShmem->inflight[side][feature_index], 0); } } if (!mailbox_found) { - pg_atomic_init_u64( - &SemanticActivationUtilityMailbox->utility_request_seq, 0); - pg_atomic_init_u64( - &SemanticActivationUtilityMailbox->utility_completion_seq, 0); - pg_atomic_init_u32( - &SemanticActivationUtilityMailbox->utility_mailbox_state, - SEMANTIC_ACTIVATION_UTILITY_MAILBOX_IDLE); - SemanticActivationUtilityMailbox->utility_action - = CLUSTER_SEMANTIC_ENABLE_ALL; + pg_atomic_init_u64(&SemanticActivationUtilityMailbox->utility_request_seq, 0); + pg_atomic_init_u64(&SemanticActivationUtilityMailbox->utility_completion_seq, 0); + pg_atomic_init_u32(&SemanticActivationUtilityMailbox->utility_mailbox_state, + SEMANTIC_ACTIVATION_UTILITY_MAILBOX_IDLE); + SemanticActivationUtilityMailbox->utility_action = CLUSTER_SEMANTIC_ENABLE_ALL; SemanticActivationUtilityMailbox->utility_source_feature_bitmap = 0; SemanticActivationUtilityMailbox->utility_target_feature_bitmap = 0; SemanticActivationUtilityMailbox->utility_rollback_feature_bitmap = 0; @@ -11054,8 +9648,7 @@ cluster_semantic_activation_shmem_init(void) sizeof(SemanticActivationBit22Seam->file_token)); memset(SemanticActivationBit22Seam->round_sha, 0, sizeof(SemanticActivationBit22Seam->round_sha)); - memset(&SemanticActivationBit22Seam->round, 0, - sizeof(SemanticActivationBit22Seam->round)); + memset(&SemanticActivationBit22Seam->round, 0, sizeof(SemanticActivationBit22Seam->round)); } } @@ -11071,7 +9664,7 @@ cluster_r4_bit22_cutover_active(void) /* Reader gate: TARGET_BOOTSTRAP (1) and TARGET_VERIFIED (2) both * select the root. */ return SemanticActivationBit22Latch != NULL - && pg_atomic_read_u32(&SemanticActivationBit22Latch->active) != 0; + && pg_atomic_read_u32(&SemanticActivationBit22Latch->active) != 0; } /* @@ -11083,8 +9676,8 @@ bool cluster_r4_bit22_cutover_verified(void) { return SemanticActivationBit22Latch != NULL - && pg_atomic_read_u32(&SemanticActivationBit22Latch->active) - == CLUSTER_R4_BIT22_TARGET_VERIFIED; + && pg_atomic_read_u32(&SemanticActivationBit22Latch->active) + == CLUSTER_R4_BIT22_TARGET_VERIFIED; } /* @@ -11101,8 +9694,7 @@ cluster_r4_bit22_cutover_latch_verify(void) if (SemanticActivationBit22Latch == NULL) return false; expected = CLUSTER_R4_BIT22_TARGET_BOOTSTRAP; - if (!pg_atomic_compare_exchange_u32(&SemanticActivationBit22Latch->active, - &expected, + if (!pg_atomic_compare_exchange_u32(&SemanticActivationBit22Latch->active, &expected, CLUSTER_R4_BIT22_TARGET_VERIFIED)) return false; return true; @@ -11125,16 +9717,14 @@ cluster_r4_bit22_cutover_latch_verify(void) * While any deferred site remains the apply is refused (fail-closed). */ bool -cluster_r4_bit22_cutover_latch_apply(uint64 transition_epoch, - uint64 round_generation) +cluster_r4_bit22_cutover_latch_apply(uint64 transition_epoch, uint64 round_generation) { uint32 expected = CLUSTER_R4_BIT22_SOURCE; /* RF-ROOT P9 verification: a fresh cluster's bit22 round legitimately * runs at formation epoch 0 (no R4 history); only the round * generation must be nonzero. */ - if (SemanticActivationBit22Latch == NULL - || round_generation == 0) + if (SemanticActivationBit22Latch == NULL || round_generation == 0) return false; if (!cluster_wal_state_correctness_census_ok()) return false; @@ -11150,39 +9740,32 @@ cluster_r4_bit22_cutover_latch_apply(uint64 transition_epoch, * loser reads back either its own value (winner not yet overwritten) * or the same-round winner's — both match. Cross-round concurrent * applies cannot occur (cutover rounds are driver-serialized). */ - if (pg_atomic_read_u32(&SemanticActivationBit22Latch->active) != 0) - { - int i; + if (pg_atomic_read_u32(&SemanticActivationBit22Latch->active) != 0) { + int i; - if (pg_atomic_read_u64( - &SemanticActivationBit22Latch->transition_epoch) == transition_epoch - && pg_atomic_read_u64( - &SemanticActivationBit22Latch->round_generation) == round_generation) + if (pg_atomic_read_u64(&SemanticActivationBit22Latch->transition_epoch) == transition_epoch + && pg_atomic_read_u64(&SemanticActivationBit22Latch->round_generation) + == round_generation) return true; - for (i = 0; i < 8; i++) - { + for (i = 0; i < 8; i++) { pg_read_barrier(); - if (pg_atomic_read_u64( - &SemanticActivationBit22Latch->transition_epoch) == transition_epoch - && pg_atomic_read_u64( - &SemanticActivationBit22Latch->round_generation) == round_generation) + if (pg_atomic_read_u64(&SemanticActivationBit22Latch->transition_epoch) + == transition_epoch + && pg_atomic_read_u64(&SemanticActivationBit22Latch->round_generation) + == round_generation) return true; } return false; } - pg_atomic_write_u64(&SemanticActivationBit22Latch->transition_epoch, - transition_epoch); - pg_atomic_write_u64(&SemanticActivationBit22Latch->round_generation, - round_generation); + pg_atomic_write_u64(&SemanticActivationBit22Latch->transition_epoch, transition_epoch); + pg_atomic_write_u64(&SemanticActivationBit22Latch->round_generation, round_generation); pg_write_barrier(); - if (pg_atomic_compare_exchange_u32(&SemanticActivationBit22Latch->active, - &expected, - CLUSTER_R4_BIT22_TARGET_BOOTSTRAP)) + if (pg_atomic_compare_exchange_u32(&SemanticActivationBit22Latch->active, &expected, + CLUSTER_R4_BIT22_TARGET_BOOTSTRAP)) return true; - return pg_atomic_read_u64( - &SemanticActivationBit22Latch->transition_epoch) == transition_epoch - && pg_atomic_read_u64( - &SemanticActivationBit22Latch->round_generation) == round_generation; + return pg_atomic_read_u64(&SemanticActivationBit22Latch->transition_epoch) == transition_epoch + && pg_atomic_read_u64(&SemanticActivationBit22Latch->round_generation) + == round_generation; } /* @@ -11221,28 +9804,23 @@ cluster_r4_bit22_source_writer_leave(void) * closed is refused. The caller then waits for writer_count==0. */ bool -cluster_r4_bit22_source_close_begin(uint64 transition_epoch, - uint64 prepare_generation) +cluster_r4_bit22_source_close_begin(uint64 transition_epoch, uint64 prepare_generation) { uint32 expected = 0; - if (SemanticActivationBit22SourceClose == NULL - || prepare_generation == 0) + if (SemanticActivationBit22SourceClose == NULL || prepare_generation == 0) return false; if (pg_atomic_read_u32(&SemanticActivationBit22SourceClose->closed) != 0) - return pg_atomic_read_u64( - &SemanticActivationBit22SourceClose->transition_epoch) + return pg_atomic_read_u64(&SemanticActivationBit22SourceClose->transition_epoch) == transition_epoch - && pg_atomic_read_u64( - &SemanticActivationBit22SourceClose->prepare_generation) - == prepare_generation; - pg_atomic_write_u64(&SemanticActivationBit22SourceClose->transition_epoch, - transition_epoch); + && pg_atomic_read_u64(&SemanticActivationBit22SourceClose->prepare_generation) + == prepare_generation; + pg_atomic_write_u64(&SemanticActivationBit22SourceClose->transition_epoch, transition_epoch); pg_atomic_write_u64(&SemanticActivationBit22SourceClose->prepare_generation, prepare_generation); pg_write_barrier(); - return pg_atomic_compare_exchange_u32( - &SemanticActivationBit22SourceClose->closed, &expected, 1); + return pg_atomic_compare_exchange_u32(&SemanticActivationBit22SourceClose->closed, &expected, + 1); } /* @@ -11250,17 +9828,14 @@ cluster_r4_bit22_source_close_begin(uint64 transition_epoch, * is the source frozen for exactly this round? */ bool -cluster_r4_bit22_source_close_current(uint64 transition_epoch, - uint64 prepare_generation) +cluster_r4_bit22_source_close_current(uint64 transition_epoch, uint64 prepare_generation) { return SemanticActivationBit22SourceClose != NULL - && pg_atomic_read_u32(&SemanticActivationBit22SourceClose->closed) != 0 - && pg_atomic_read_u64( - &SemanticActivationBit22SourceClose->transition_epoch) - == transition_epoch - && pg_atomic_read_u64( - &SemanticActivationBit22SourceClose->prepare_generation) - == prepare_generation; + && pg_atomic_read_u32(&SemanticActivationBit22SourceClose->closed) != 0 + && pg_atomic_read_u64(&SemanticActivationBit22SourceClose->transition_epoch) + == transition_epoch + && pg_atomic_read_u64(&SemanticActivationBit22SourceClose->prepare_generation) + == prepare_generation; } /* @@ -11277,9 +9852,8 @@ cluster_r4_bit22_source_close_current(uint64 transition_epoch, * CLOSED-ACK is COMPLETE. */ bool -cluster_r4_bit22_cutover_begin( - const ClusterControlRootMigrationImage *image, - const ClusterControlRootMigrationRoundV1 *round) +cluster_r4_bit22_cutover_begin(const ClusterControlRootMigrationImage *image, + const ClusterControlRootMigrationRoundV1 *round) { ClusterControlRootFileToken token; ClusterSemanticActivationAckTableV1 table; @@ -11297,19 +9871,16 @@ cluster_r4_bit22_cutover_begin( int node; if (round == NULL - || (round->target_feature_bitmap - & PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1) == 0 - || SemanticActivationAckTable == NULL - || SemanticActivationBit22Seam == NULL + || (round->target_feature_bitmap & PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1) + == 0 + || SemanticActivationAckTable == NULL || SemanticActivationBit22Seam == NULL || !semantic_activation_snapshot(&snapshot) - || !semantic_activation_ack_current_authority( - cluster_node_id, ¤t_members_lo, ¤t_members_hi, - ¤t_epoch, ¤t_coordinator_node) - || cluster_node_id != current_coordinator_node - || round->transition_epoch != current_epoch + || !semantic_activation_ack_current_authority(cluster_node_id, ¤t_members_lo, + ¤t_members_hi, ¤t_epoch, + ¤t_coordinator_node) + || cluster_node_id != current_coordinator_node || round->transition_epoch != current_epoch || round->admitted_bitmap_low != current_members_lo - || round->admitted_bitmap_high != current_members_hi - || round->prepare_generation == 0) + || round->admitted_bitmap_high != current_members_hi || round->prepare_generation == 0) return false; /* RF-ROOT P9 verification (implementation): source-close BARRIER first. Freeze @@ -11318,20 +9889,17 @@ cluster_r4_bit22_cutover_begin( * The migration image is built ONLY after the all-member BARRIER * COMPLETE (LMON tick, bit22_advance), so ACTIVE slots are provably * quiesced — no offline STOPPED requirement. */ - if (!cluster_r4_bit22_source_close_begin( - round->transition_epoch, round->prepare_generation)) + if (!cluster_r4_bit22_source_close_begin(round->transition_epoch, round->prepare_generation)) return false; { int i; for (i = 0; i < 1000; i++) { - if (pg_atomic_read_u32( - &SemanticActivationBit22SourceClose->writer_count) == 0) + if (pg_atomic_read_u32(&SemanticActivationBit22SourceClose->writer_count) == 0) break; pg_usleep(5000L); /* 5 ms; up to ~5 s */ } - if (pg_atomic_read_u32( - &SemanticActivationBit22SourceClose->writer_count) != 0) + if (pg_atomic_read_u32(&SemanticActivationBit22SourceClose->writer_count) != 0) return false; } @@ -11355,25 +9923,22 @@ cluster_r4_bit22_cutover_begin( uint32 peer_word; uint32 peer_gen; - if (!semantic_activation_ack_member_present( - current_members_lo, current_members_hi, node)) + if (!semantic_activation_ack_member_present(current_members_lo, current_members_hi, node)) continue; if (node == cluster_node_id) { if (!semantic_activation_ack_self_tuple( - node, local_capability_word, round->transition_epoch, - round->prepare_generation, &table.expected[node])) + node, local_capability_word, round->transition_epoch, round->prepare_generation, + &table.expected[node])) return false; continue; } memset(&remote, 0, sizeof(remote)); remote.node_id = (uint32)node; - remote.boot_id - = cluster_membership_get_last_admitted_incarnation(node); + remote.boot_id = cluster_membership_get_last_admitted_incarnation(node); remote.admitted_incarnation = remote.boot_id; if (remote.boot_id == 0 || !cluster_sf_peer_capability_word_sample( - node, CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS, - &peer_word, &peer_gen) + node, CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS, &peer_word, &peer_gen) || peer_gen == 0) return false; remote.control_connection_generation = (uint64)peer_gen; @@ -11399,19 +9964,17 @@ cluster_r4_bit22_cutover_begin( if (!semantic_activation_ack_table_publish(&table)) return false; - (void) request; - (void) pending; - (void) self; - (void) create_result; - (void) sha; - (void) token; + (void)request; + (void)pending; + (void)self; + (void)create_result; + (void)sha; + (void)token; { - SemanticActivationAckRequestOrigin *origin - = &semantic_activation_ack_local_request_origin; + SemanticActivationAckRequestOrigin *origin = &semantic_activation_ack_local_request_origin; memset(origin, 0, sizeof(*origin)); - origin->unsent_members_lo = table.expected_members_lo - & ~(UINT64_C(1) << cluster_node_id); + origin->unsent_members_lo = table.expected_members_lo & ~(UINT64_C(1) << cluster_node_id); origin->active = true; } /* RF-ROOT P9 verification: the BARRIER REQUEST is sent by the LMON @@ -11432,24 +9995,18 @@ cluster_r4_bit22_cutover_begin( static bool semantic_activation_ack_lmon_send_bit22_prepared_requests(uint32 stage) { - SemanticActivationAckRequestOrigin *origin - = &semantic_activation_ack_local_request_origin; + SemanticActivationAckRequestOrigin *origin = &semantic_activation_ack_local_request_origin; ClusterSemanticActivationAckTableV1 image; uint8 payload[CLUSTER_SEMANTIC_ACTIVATION_ACK_WIRE_BYTES]; if (!origin->active) return false; - if (!semantic_activation_ack_table_snapshot(&image) - || image.stage != stage - || image.round_nonce == 0 - || image.record_generation == 0 - || (image.target_feature_bitmap - & PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1) == 0 - || image.expected_members_lo == 0 - || image.expected_members_hi != 0 + if (!semantic_activation_ack_table_snapshot(&image) || image.stage != stage + || image.round_nonce == 0 || image.record_generation == 0 + || (image.target_feature_bitmap & PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1) == 0 + || image.expected_members_lo == 0 || image.expected_members_hi != 0 || image.capability_sample_digest == 0 - || (image.flags - & CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID) == 0) { + || (image.flags & CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID) == 0) { semantic_activation_ack_lmon_invalidate_active(); return false; } @@ -11460,8 +10017,7 @@ semantic_activation_ack_lmon_send_bit22_prepared_requests(uint32 stage) uint64 member_bit; int32 node; - if (pending->pending_members_lo == 0 - && pending->pending_members_hi == 0) { + if (pending->pending_members_lo == 0 && pending->pending_members_hi == 0) { for (node = 0; node < CLUSTER_MAX_NODES; node++) { member_bit = UINT64_C(1) << node; if ((origin->unsent_members_lo & member_bit) != 0) @@ -11470,81 +10026,60 @@ semantic_activation_ack_lmon_send_bit22_prepared_requests(uint32 stage) if (node == CLUSTER_MAX_NODES) return true; memset(pending, 0, sizeof(*pending)); - pending->message.kind - = CLUSTER_SEMANTIC_ACTIVATION_ACK_KIND_REQUEST; + pending->message.kind = CLUSTER_SEMANTIC_ACTIVATION_ACK_KIND_REQUEST; pending->message.stage = image.stage; - pending->message.result - = CLUSTER_SEMANTIC_ACTIVATION_ACK_RESULT_REQUEST; + pending->message.result = CLUSTER_SEMANTIC_ACTIVATION_ACK_RESULT_REQUEST; pending->message.coordinator_node = image.coordinator_node; pending->message.member_node = (uint32)node; pending->message.transition_epoch = image.transition_epoch; pending->message.record_generation = image.record_generation; pending->message.round_nonce = image.round_nonce; - pending->message.source_feature_bitmap - = image.source_feature_bitmap; - pending->message.target_feature_bitmap - = image.target_feature_bitmap; - pending->message.rollback_feature_bitmap - = image.rollback_feature_bitmap; - pending->message.admitted_members_lo - = image.expected_members_lo; - pending->message.admitted_members_hi - = image.expected_members_hi; - pending->message.capability_sample_digest - = image.capability_sample_digest; + pending->message.source_feature_bitmap = image.source_feature_bitmap; + pending->message.target_feature_bitmap = image.target_feature_bitmap; + pending->message.rollback_feature_bitmap = image.rollback_feature_bitmap; + pending->message.admitted_members_lo = image.expected_members_lo; + pending->message.admitted_members_hi = image.expected_members_hi; + pending->message.capability_sample_digest = image.capability_sample_digest; pending->pending_members_lo = member_bit; origin->unsent_members_lo &= ~member_bit; } node = (int32)pending->message.member_node; - if (node < 0 || node >= CLUSTER_MAX_NODES - || pending->invalidated) { + if (node < 0 || node >= CLUSTER_MAX_NODES || pending->invalidated) { semantic_activation_ack_lmon_invalidate_active(); return false; } member_bit = UINT64_C(1) << node; - if (pending->pending_members_hi != 0 - || pending->pending_members_lo != member_bit - || pending->message.kind - != CLUSTER_SEMANTIC_ACTIVATION_ACK_KIND_REQUEST + if (pending->pending_members_hi != 0 || pending->pending_members_lo != member_bit + || pending->message.kind != CLUSTER_SEMANTIC_ACTIVATION_ACK_KIND_REQUEST || pending->message.stage != image.stage - || pending->message.result - != CLUSTER_SEMANTIC_ACTIVATION_ACK_RESULT_REQUEST + || pending->message.result != CLUSTER_SEMANTIC_ACTIVATION_ACK_RESULT_REQUEST || pending->message.coordinator_node != image.coordinator_node || pending->message.transition_epoch != image.transition_epoch || pending->message.record_generation != image.record_generation || pending->message.round_nonce != image.round_nonce - || pending->message.source_feature_bitmap - != image.source_feature_bitmap - || pending->message.target_feature_bitmap - != image.target_feature_bitmap - || pending->message.rollback_feature_bitmap - != image.rollback_feature_bitmap - || pending->message.admitted_members_lo - != image.expected_members_lo - || pending->message.admitted_members_hi - != image.expected_members_hi - || pending->message.capability_sample_digest - != image.capability_sample_digest - || !cluster_semantic_activation_ack_wire_encode( - &pending->message, payload)) { + || pending->message.source_feature_bitmap != image.source_feature_bitmap + || pending->message.target_feature_bitmap != image.target_feature_bitmap + || pending->message.rollback_feature_bitmap != image.rollback_feature_bitmap + || pending->message.admitted_members_lo != image.expected_members_lo + || pending->message.admitted_members_hi != image.expected_members_hi + || pending->message.capability_sample_digest != image.capability_sample_digest + || !cluster_semantic_activation_ack_wire_encode(&pending->message, payload)) { semantic_activation_ack_lmon_invalidate_active(); return false; } - send_result = cluster_ic_send_envelope( - PGRAC_IC_MSG_SEMANTIC_ACTIVATION_ACK_V1, node, - payload, sizeof(payload)); + send_result = cluster_ic_send_envelope(PGRAC_IC_MSG_SEMANTIC_ACTIVATION_ACK_V1, node, + payload, sizeof(payload)); { SemanticActivationAckSendResult disposition - = semantic_activation_ack_pending_send_note_result( - pending, node, send_result); + = semantic_activation_ack_pending_send_note_result(pending, node, send_result); if (disposition == SEMANTIC_ACTIVATION_ACK_SEND_RETAINED) return true; if (disposition == SEMANTIC_ACTIVATION_ACK_SEND_INVALIDATED) { - cluster_ic_tier1_close_peer( - node, "semantic activation PREPARED request send failed"); + cluster_ic_tier1_close_peer(node, + "semantic activation PREPARED request send failed"); semantic_activation_ack_lmon_invalidate_active(); return false; } @@ -11566,24 +10101,19 @@ semantic_activation_ack_lmon_send_bit22_prepared_requests(uint32 stage) * is inert). Fail-closed on NULL/zero inputs. */ bool -cluster_r4_bit22_cutover_seam_store( - const ClusterControlRootFileToken *file_token, - const uint8 round_sha[PG_SHA256_DIGEST_LENGTH], - const ClusterControlRootMigrationRoundV1 *round) +cluster_r4_bit22_cutover_seam_store(const ClusterControlRootFileToken *file_token, + const uint8 round_sha[PG_SHA256_DIGEST_LENGTH], + const ClusterControlRootMigrationRoundV1 *round) { - if (SemanticActivationBit22Seam == NULL || file_token == NULL - || round_sha == NULL || round == NULL - || file_token->file_txn_seq == 0 - || semantic_activation_bytes_are_zero( - round_sha, PG_SHA256_DIGEST_LENGTH)) + if (SemanticActivationBit22Seam == NULL || file_token == NULL || round_sha == NULL + || round == NULL || file_token->file_txn_seq == 0 + || semantic_activation_bytes_are_zero(round_sha, PG_SHA256_DIGEST_LENGTH)) return false; SemanticActivationBit22Seam->file_token = *file_token; - memcpy(SemanticActivationBit22Seam->round_sha, round_sha, - PG_SHA256_DIGEST_LENGTH); + memcpy(SemanticActivationBit22Seam->round_sha, round_sha, PG_SHA256_DIGEST_LENGTH); SemanticActivationBit22Seam->round = *round; SemanticActivationBit22Seam->transition_epoch = round->transition_epoch; - SemanticActivationBit22Seam->prepare_generation - = round->prepare_generation; + SemanticActivationBit22Seam->prepare_generation = round->prepare_generation; pg_write_barrier(); pg_atomic_write_u32(&SemanticActivationBit22Seam->valid, 1); return true; @@ -11596,24 +10126,24 @@ cluster_r4_bit22_cutover_seam_store( * This mailbox carries no PGSA bytes and cannot bypass QVOTEC. */ static bool -semantic_activation_utility_mailbox_submit( - ClusterSemanticActivationAction action, uint64 source_feature_bitmap, - uint64 target_feature_bitmap, uint64 rollback_feature_bitmap, - uint64 expected_record_generation, uint64 *out_request_seq) +semantic_activation_utility_mailbox_submit(ClusterSemanticActivationAction action, + uint64 source_feature_bitmap, + uint64 target_feature_bitmap, + uint64 rollback_feature_bitmap, + uint64 expected_record_generation, + uint64 *out_request_seq) { uint32 expected_state = SEMANTIC_ACTIVATION_UTILITY_MAILBOX_IDLE; uint64 request_seq; if (SemanticActivationUtilityMailbox == NULL || out_request_seq == NULL - || action < CLUSTER_SEMANTIC_ENABLE_ALL - || action > CLUSTER_SEMANTIC_ROLLBACK_ABORT - || !pg_atomic_compare_exchange_u32( - &SemanticActivationUtilityMailbox->utility_mailbox_state, - &expected_state, SEMANTIC_ACTIVATION_UTILITY_MAILBOX_WRITING)) + || action < CLUSTER_SEMANTIC_ENABLE_ALL || action > CLUSTER_SEMANTIC_ROLLBACK_ABORT + || !pg_atomic_compare_exchange_u32(&SemanticActivationUtilityMailbox->utility_mailbox_state, + &expected_state, + SEMANTIC_ACTIVATION_UTILITY_MAILBOX_WRITING)) return false; - request_seq = pg_atomic_read_u64( - &SemanticActivationUtilityMailbox->utility_request_seq); + request_seq = pg_atomic_read_u64(&SemanticActivationUtilityMailbox->utility_request_seq); if (request_seq == UINT64_MAX) { pg_atomic_write_u32(&SemanticActivationUtilityMailbox->utility_mailbox_state, SEMANTIC_ACTIVATION_UTILITY_MAILBOX_IDLE); @@ -11622,16 +10152,12 @@ semantic_activation_utility_mailbox_submit( request_seq++; SemanticActivationUtilityMailbox->utility_action = (uint32)action; - SemanticActivationUtilityMailbox->utility_source_feature_bitmap - = source_feature_bitmap; - SemanticActivationUtilityMailbox->utility_target_feature_bitmap - = target_feature_bitmap; - SemanticActivationUtilityMailbox->utility_rollback_feature_bitmap - = rollback_feature_bitmap; + SemanticActivationUtilityMailbox->utility_source_feature_bitmap = source_feature_bitmap; + SemanticActivationUtilityMailbox->utility_target_feature_bitmap = target_feature_bitmap; + SemanticActivationUtilityMailbox->utility_rollback_feature_bitmap = rollback_feature_bitmap; SemanticActivationUtilityMailbox->utility_expected_record_generation = expected_record_generation; - pg_atomic_write_u64(&SemanticActivationUtilityMailbox->utility_request_seq, - request_seq); + pg_atomic_write_u64(&SemanticActivationUtilityMailbox->utility_request_seq, request_seq); pg_write_barrier(); pg_atomic_write_u32(&SemanticActivationUtilityMailbox->utility_mailbox_state, SEMANTIC_ACTIVATION_UTILITY_MAILBOX_PENDING); @@ -11645,29 +10171,22 @@ semantic_activation_utility_mailbox_poll(SemanticActivationUtilityRequest *out) uint64 request_seq; if (SemanticActivationUtilityMailbox == NULL || out == NULL - || pg_atomic_read_u32( - &SemanticActivationUtilityMailbox->utility_mailbox_state) + || pg_atomic_read_u32(&SemanticActivationUtilityMailbox->utility_mailbox_state) != SEMANTIC_ACTIVATION_UTILITY_MAILBOX_PENDING) return false; pg_read_barrier(); - request_seq = pg_atomic_read_u64( - &SemanticActivationUtilityMailbox->utility_request_seq); + request_seq = pg_atomic_read_u64(&SemanticActivationUtilityMailbox->utility_request_seq); if (request_seq == 0 - || pg_atomic_read_u64( - &SemanticActivationUtilityMailbox->utility_completion_seq) - + 1 != request_seq - || SemanticActivationUtilityMailbox->utility_action - > CLUSTER_SEMANTIC_ROLLBACK_ABORT) + || pg_atomic_read_u64(&SemanticActivationUtilityMailbox->utility_completion_seq) + 1 + != request_seq + || SemanticActivationUtilityMailbox->utility_action > CLUSTER_SEMANTIC_ROLLBACK_ABORT) return false; out->request_seq = request_seq; - out->action = (ClusterSemanticActivationAction) - SemanticActivationUtilityMailbox->utility_action; - out->source_feature_bitmap - = SemanticActivationUtilityMailbox->utility_source_feature_bitmap; - out->target_feature_bitmap - = SemanticActivationUtilityMailbox->utility_target_feature_bitmap; + out->action = (ClusterSemanticActivationAction)SemanticActivationUtilityMailbox->utility_action; + out->source_feature_bitmap = SemanticActivationUtilityMailbox->utility_source_feature_bitmap; + out->target_feature_bitmap = SemanticActivationUtilityMailbox->utility_target_feature_bitmap; out->rollback_feature_bitmap = SemanticActivationUtilityMailbox->utility_rollback_feature_bitmap; out->expected_record_generation @@ -11676,28 +10195,22 @@ semantic_activation_utility_mailbox_poll(SemanticActivationUtilityRequest *out) } static bool -semantic_activation_utility_mailbox_complete( - uint64 request_seq, ClusterSemanticActivationResult result, - uint64 feature_bit, uint64 expected_generation) +semantic_activation_utility_mailbox_complete(uint64 request_seq, + ClusterSemanticActivationResult result, + uint64 feature_bit, uint64 expected_generation) { if (SemanticActivationUtilityMailbox == NULL || request_seq == 0 - || result < CLUSTER_SEMANTIC_ACTIVATION_OK - || result > CLUSTER_SEMANTIC_ACTIVATION_BAD_STATE - || pg_atomic_read_u32( - &SemanticActivationUtilityMailbox->utility_mailbox_state) + || result < CLUSTER_SEMANTIC_ACTIVATION_OK || result > CLUSTER_SEMANTIC_ACTIVATION_BAD_STATE + || pg_atomic_read_u32(&SemanticActivationUtilityMailbox->utility_mailbox_state) != SEMANTIC_ACTIVATION_UTILITY_MAILBOX_PENDING - || pg_atomic_read_u64( - &SemanticActivationUtilityMailbox->utility_request_seq) + || pg_atomic_read_u64(&SemanticActivationUtilityMailbox->utility_request_seq) != request_seq) return false; - pg_atomic_write_u32(&SemanticActivationUtilityMailbox->utility_result, - (uint32)result); + pg_atomic_write_u32(&SemanticActivationUtilityMailbox->utility_result, (uint32)result); SemanticActivationUtilityMailbox->utility_result_feature_bit = feature_bit; - SemanticActivationUtilityMailbox->utility_result_expected_generation - = expected_generation; - pg_atomic_write_u64(&SemanticActivationUtilityMailbox->utility_completion_seq, - request_seq); + SemanticActivationUtilityMailbox->utility_result_expected_generation = expected_generation; + pg_atomic_write_u64(&SemanticActivationUtilityMailbox->utility_completion_seq, request_seq); pg_write_barrier(); pg_atomic_write_u32(&SemanticActivationUtilityMailbox->utility_mailbox_state, SEMANTIC_ACTIVATION_UTILITY_MAILBOX_COMPLETE); @@ -11705,47 +10218,40 @@ semantic_activation_utility_mailbox_complete( } static bool -semantic_activation_utility_mailbox_poll_completion( - uint64 request_seq, ClusterSemanticActivationRefusal *out_refusal) +semantic_activation_utility_mailbox_poll_completion(uint64 request_seq, + ClusterSemanticActivationRefusal *out_refusal) { uint32 expected_state = SEMANTIC_ACTIVATION_UTILITY_MAILBOX_COMPLETE; - if (SemanticActivationUtilityMailbox == NULL || request_seq == 0 - || out_refusal == NULL - || pg_atomic_read_u32( - &SemanticActivationUtilityMailbox->utility_mailbox_state) + if (SemanticActivationUtilityMailbox == NULL || request_seq == 0 || out_refusal == NULL + || pg_atomic_read_u32(&SemanticActivationUtilityMailbox->utility_mailbox_state) != SEMANTIC_ACTIVATION_UTILITY_MAILBOX_COMPLETE - || pg_atomic_read_u64( - &SemanticActivationUtilityMailbox->utility_completion_seq) + || pg_atomic_read_u64(&SemanticActivationUtilityMailbox->utility_completion_seq) != request_seq) return false; pg_read_barrier(); - out_refusal->result = (ClusterSemanticActivationResult) - pg_atomic_read_u32(&SemanticActivationUtilityMailbox->utility_result); - out_refusal->feature_bit - = SemanticActivationUtilityMailbox->utility_result_feature_bit; + out_refusal->result = (ClusterSemanticActivationResult)pg_atomic_read_u32( + &SemanticActivationUtilityMailbox->utility_result); + out_refusal->feature_bit = SemanticActivationUtilityMailbox->utility_result_feature_bit; out_refusal->expected_generation = SemanticActivationUtilityMailbox->utility_result_expected_generation; - return pg_atomic_compare_exchange_u32( - &SemanticActivationUtilityMailbox->utility_mailbox_state, - &expected_state, - SEMANTIC_ACTIVATION_UTILITY_MAILBOX_IDLE); + return pg_atomic_compare_exchange_u32(&SemanticActivationUtilityMailbox->utility_mailbox_state, + &expected_state, + SEMANTIC_ACTIVATION_UTILITY_MAILBOX_IDLE); } static ClusterSemanticActivationResult -semantic_activation_utility_mailbox_wait( - uint64 request_seq, ClusterSemanticActivationRefusal *out_refusal) +semantic_activation_utility_mailbox_wait(uint64 request_seq, + ClusterSemanticActivationRefusal *out_refusal) { if (out_refusal == NULL || request_seq == 0) { - semantic_activation_set_refusal( - out_refusal, CLUSTER_SEMANTIC_ACTIVATION_BAD_STATE, 0, 0); + semantic_activation_set_refusal(out_refusal, CLUSTER_SEMANTIC_ACTIVATION_BAD_STATE, 0, 0); return CLUSTER_SEMANTIC_ACTIVATION_BAD_STATE; } for (;;) { - if (semantic_activation_utility_mailbox_poll_completion( - request_seq, out_refusal)) + if (semantic_activation_utility_mailbox_poll_completion(request_seq, out_refusal)) return out_refusal->result; CHECK_FOR_INTERRUPTS(); pg_usleep(CLUSTER_SEMANTIC_UTILITY_WAIT_STEP_US); @@ -11761,30 +10267,27 @@ semantic_activation_record_cas_mailbox_submit( ClusterSemanticFormationBinding formation; if (expected_generation == UINT64_MAX || desired_bytes == NULL - || SemanticActivationUtilityMailbox == NULL - || cluster_node_id < 0 || cluster_node_id >= CLUSTER_MAX_NODES - || !cluster_semantic_activation_record_decode( - desired_bytes, &desired, NULL) + || SemanticActivationUtilityMailbox == NULL || cluster_node_id < 0 + || cluster_node_id >= CLUSTER_MAX_NODES + || !cluster_semantic_activation_record_decode(desired_bytes, &desired, NULL) || desired.record_generation != expected_generation + 1 || desired.coordinator_node != (uint32)cluster_node_id) return false; formation = (ClusterSemanticFormationBinding){ - .utility_request_seq = pg_atomic_read_u64( - &SemanticActivationUtilityMailbox->utility_request_seq), + .utility_request_seq + = pg_atomic_read_u64(&SemanticActivationUtilityMailbox->utility_request_seq), .formation_epoch = desired.transition_epoch, .coordinator_incarnation = desired.coordinator_incarnation, .expected_record_generation = expected_generation, }; - if (!semantic_activation_record_cas_formation_matches( - &formation, &desired)) + if (!semantic_activation_record_cas_formation_matches(&formation, &desired)) return false; /* RECORD_CAS already carries epoch/incarnation in its durable desired * image. Reuse the utility result words for the pending utility sequence * and a second incarnation copy, so utility-slot ABA and byte mutation are * rejected without widening either shared mailbox. */ - SemanticActivationUtilityMailbox->utility_result_feature_bit - = formation.utility_request_seq; + SemanticActivationUtilityMailbox->utility_result_feature_bit = formation.utility_request_seq; SemanticActivationUtilityMailbox->utility_result_expected_generation = formation.coordinator_incarnation; return semantic_activation_authority_mailbox_submit( @@ -11798,29 +10301,23 @@ semantic_activation_record_read_mailbox_submit(uint64 *out_request_seq) uint8 zero[CLUSTER_SEMANTIC_ACTIVATION_RECORD_BYTES] = { 0 }; return semantic_activation_authority_mailbox_submit( - CLUSTER_SEMANTIC_AUTHORITY_REQUEST_RECORD_READ, 0, 0, zero, - out_request_seq); + CLUSTER_SEMANTIC_AUTHORITY_REQUEST_RECORD_READ, 0, 0, zero, out_request_seq); } static bool semantic_activation_authority_mailbox_submit( ClusterSemanticAuthorityRequestKind request_kind, uint64 expected_generation, uint64 expected_source_feature_bitmap, - const uint8 desired_bytes[CLUSTER_SEMANTIC_ACTIVATION_RECORD_BYTES], - uint64 *out_request_seq) + const uint8 desired_bytes[CLUSTER_SEMANTIC_ACTIVATION_RECORD_BYTES], uint64 *out_request_seq) { uint64 request_seq; uint64 completion_seq; - if (SemanticActivationShmem == NULL || desired_bytes == NULL - || out_request_seq == NULL + if (SemanticActivationShmem == NULL || desired_bytes == NULL || out_request_seq == NULL || (request_kind != CLUSTER_SEMANTIC_AUTHORITY_REQUEST_RECORD_CAS - && request_kind - != CLUSTER_SEMANTIC_AUTHORITY_REQUEST_UNDO_ROOT_DESCRIPTOR - && request_kind - != CLUSTER_SEMANTIC_AUTHORITY_REQUEST_RECORD_READ - && request_kind - != CLUSTER_SEMANTIC_AUTHORITY_REQUEST_UNDO_ROOT_DESCRIPTOR_READ)) + && request_kind != CLUSTER_SEMANTIC_AUTHORITY_REQUEST_UNDO_ROOT_DESCRIPTOR + && request_kind != CLUSTER_SEMANTIC_AUTHORITY_REQUEST_RECORD_READ + && request_kind != CLUSTER_SEMANTIC_AUTHORITY_REQUEST_UNDO_ROOT_DESCRIPTOR_READ)) return false; request_seq = pg_atomic_read_u64(&SemanticActivationShmem->record_cas_request_seq); @@ -11833,8 +10330,7 @@ semantic_activation_authority_mailbox_submit( = expected_source_feature_bitmap; memcpy(SemanticActivationShmem->record_cas_desired_bytes, desired_bytes, sizeof(SemanticActivationShmem->record_cas_desired_bytes)); - pg_atomic_write_u32(&SemanticActivationShmem->record_cas_request_kind, - request_kind); + pg_atomic_write_u32(&SemanticActivationShmem->record_cas_request_kind, request_kind); pg_write_barrier(); request_seq++; pg_atomic_write_u64(&SemanticActivationShmem->record_cas_request_seq, request_seq); @@ -11847,8 +10343,7 @@ semantic_activation_authority_mailbox_submit( * expected_source_feature_bitmap; the remaining identity is re-derived from * the current ACK table and local admitted incarnation on every poll. */ static bool -semantic_activation_member_pgrd_formation_binding( - ClusterSemanticFormationBinding *out) +semantic_activation_member_pgrd_formation_binding(ClusterSemanticFormationBinding *out) { ClusterSemanticActivationAckTableV1 table; SemanticActivationAckTuple self; @@ -11857,23 +10352,17 @@ semantic_activation_member_pgrd_formation_binding( return true; if (out == NULL || SemanticActivationShmem == NULL - || pg_atomic_read_u32( - &SemanticActivationShmem->record_cas_request_kind) + || pg_atomic_read_u32(&SemanticActivationShmem->record_cas_request_kind) != CLUSTER_SEMANTIC_AUTHORITY_REQUEST_UNDO_ROOT_DESCRIPTOR_READ || !semantic_activation_ack_table_snapshot(&table) || table.stage != CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_PREPARED || table.source_feature_bitmap != 0 - || table.target_feature_bitmap - != CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1 - || table.rollback_feature_bitmap != 0 - || table.round_nonce == 0 - || table.round_nonce - != SemanticActivationShmem - ->record_cas_expected_source_feature_bitmap + || table.target_feature_bitmap != CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1 + || table.rollback_feature_bitmap != 0 || table.round_nonce == 0 + || table.round_nonce != SemanticActivationShmem->record_cas_expected_source_feature_bitmap || cluster_node_id < 0 || cluster_node_id >= 4 || cluster_node_id == (int32)table.coordinator_node - || !semantic_activation_ack_member_prepared_image_current( - &table, &self)) + || !semantic_activation_ack_member_prepared_image_current(&table, &self)) return false; out->utility_request_seq = table.round_nonce; @@ -11885,60 +10374,47 @@ semantic_activation_member_pgrd_formation_binding( static bool semantic_activation_authority_request_formation_binding( - ClusterSemanticAuthorityRequestKind request_kind, - ClusterSemanticFormationBinding *out) + ClusterSemanticAuthorityRequestKind request_kind, ClusterSemanticFormationBinding *out) { ClusterSemanticActivationRecord desired; uint64 expected_generation; - if (SemanticActivationShmem == NULL - || SemanticActivationUtilityMailbox == NULL || out == NULL) + if (SemanticActivationShmem == NULL || SemanticActivationUtilityMailbox == NULL || out == NULL) return false; memset(out, 0, sizeof(*out)); pg_read_barrier(); - if (pg_atomic_read_u32( - &SemanticActivationShmem->record_cas_request_kind) - != request_kind) + if (pg_atomic_read_u32(&SemanticActivationShmem->record_cas_request_kind) != request_kind) return false; switch (request_kind) { case CLUSTER_SEMANTIC_AUTHORITY_REQUEST_RECORD_CAS: - expected_generation - = SemanticActivationShmem->record_cas_expected_generation; + expected_generation = SemanticActivationShmem->record_cas_expected_generation; if (expected_generation == UINT64_MAX || cluster_node_id < 0 || cluster_node_id >= CLUSTER_MAX_NODES || !cluster_semantic_activation_record_decode( - SemanticActivationShmem->record_cas_desired_bytes, - &desired, NULL) + SemanticActivationShmem->record_cas_desired_bytes, &desired, NULL) || desired.record_generation != expected_generation + 1 || desired.coordinator_node != (uint32)cluster_node_id || desired.coordinator_incarnation - != SemanticActivationUtilityMailbox - ->utility_result_expected_generation) + != SemanticActivationUtilityMailbox->utility_result_expected_generation) return false; - out->utility_request_seq - = SemanticActivationUtilityMailbox->utility_result_feature_bit; + out->utility_request_seq = SemanticActivationUtilityMailbox->utility_result_feature_bit; out->formation_epoch = desired.transition_epoch; out->coordinator_incarnation = desired.coordinator_incarnation; out->expected_record_generation = expected_generation; return true; case CLUSTER_SEMANTIC_AUTHORITY_REQUEST_UNDO_ROOT_DESCRIPTOR: case CLUSTER_SEMANTIC_AUTHORITY_REQUEST_UNDO_ROOT_DESCRIPTOR_READ: - if (request_kind - == CLUSTER_SEMANTIC_AUTHORITY_REQUEST_UNDO_ROOT_DESCRIPTOR_READ + if (request_kind == CLUSTER_SEMANTIC_AUTHORITY_REQUEST_UNDO_ROOT_DESCRIPTOR_READ && semantic_activation_member_pgrd_formation_binding(out)) return true; out->utility_request_seq - = SemanticActivationShmem - ->record_cas_expected_source_feature_bitmap; - out->formation_epoch - = SemanticActivationUtilityMailbox->utility_result_feature_bit; + = SemanticActivationShmem->record_cas_expected_source_feature_bitmap; + out->formation_epoch = SemanticActivationUtilityMailbox->utility_result_feature_bit; out->coordinator_incarnation - = SemanticActivationUtilityMailbox - ->utility_result_expected_generation; + = SemanticActivationUtilityMailbox->utility_result_expected_generation; out->expected_record_generation - = SemanticActivationUtilityMailbox - ->utility_expected_record_generation; + = SemanticActivationUtilityMailbox->utility_expected_record_generation; return true; case CLUSTER_SEMANTIC_AUTHORITY_REQUEST_NONE: case CLUSTER_SEMANTIC_AUTHORITY_REQUEST_RECORD_READ: @@ -11971,10 +10447,8 @@ cluster_semantic_activation_qvotec_poll_record_cas(ClusterSemanticActivationCasR if (!semantic_activation_authority_request_formation_binding( CLUSTER_SEMANTIC_AUTHORITY_REQUEST_RECORD_CAS, &formation) || !cluster_semantic_activation_record_decode( - SemanticActivationShmem->record_cas_desired_bytes, - &desired, NULL) - || !semantic_activation_record_cas_formation_matches( - &formation, &desired)) { + SemanticActivationShmem->record_cas_desired_bytes, &desired, NULL) + || !semantic_activation_record_cas_formation_matches(&formation, &desired)) { (void)cluster_semantic_activation_qvotec_complete_record_cas( request_seq, CLUSTER_SEMANTIC_ACTIVATION_QUORUM_HOLD); memset(out, 0, sizeof(*out)); @@ -11991,31 +10465,27 @@ cluster_semantic_activation_qvotec_poll_record_cas(ClusterSemanticActivationCasR bool cluster_semantic_activation_qvotec_complete_record_cas(uint64 request_seq, - ClusterSemanticActivationResult result) + ClusterSemanticActivationResult result) { return semantic_activation_authority_mailbox_complete( CLUSTER_SEMANTIC_AUTHORITY_REQUEST_RECORD_CAS, request_seq, result); } bool -cluster_semantic_activation_qvotec_poll_record_read( - ClusterSemanticActivationReadRequest *out) +cluster_semantic_activation_qvotec_poll_record_read(ClusterSemanticActivationReadRequest *out) { uint64 request_seq; uint64 completion_seq; if (SemanticActivationShmem == NULL || out == NULL) return false; - request_seq = pg_atomic_read_u64( - &SemanticActivationShmem->record_cas_request_seq); - completion_seq = pg_atomic_read_u64( - &SemanticActivationShmem->record_cas_completion_seq); + request_seq = pg_atomic_read_u64(&SemanticActivationShmem->record_cas_request_seq); + completion_seq = pg_atomic_read_u64(&SemanticActivationShmem->record_cas_completion_seq); if (request_seq == completion_seq || completion_seq == UINT64_MAX || request_seq != completion_seq + 1) return false; pg_read_barrier(); - if (pg_atomic_read_u32( - &SemanticActivationShmem->record_cas_request_kind) + if (pg_atomic_read_u32(&SemanticActivationShmem->record_cas_request_kind) != CLUSTER_SEMANTIC_AUTHORITY_REQUEST_RECORD_READ) return false; out->request_seq = request_seq; @@ -12024,8 +10494,7 @@ cluster_semantic_activation_qvotec_poll_record_read( bool cluster_semantic_activation_qvotec_complete_record_read( - uint64 request_seq, ClusterSemanticActivationResult result, - bool implicit_open, + uint64 request_seq, ClusterSemanticActivationResult result, bool implicit_open, const uint8 selected_bytes[CLUSTER_SEMANTIC_ACTIVATION_RECORD_BYTES]) { ClusterSemanticActivationRecord decoded; @@ -12033,21 +10502,18 @@ cluster_semantic_activation_qvotec_complete_record_read( if (!semantic_activation_authority_mailbox_completion_matches( CLUSTER_SEMANTIC_AUTHORITY_REQUEST_RECORD_READ, request_seq) - || result < CLUSTER_SEMANTIC_ACTIVATION_OK - || result > CLUSTER_SEMANTIC_ACTIVATION_BAD_STATE + || result < CLUSTER_SEMANTIC_ACTIVATION_OK || result > CLUSTER_SEMANTIC_ACTIVATION_BAD_STATE || (result == CLUSTER_SEMANTIC_ACTIVATION_OK && (selected_bytes == NULL || (implicit_open - && !semantic_activation_bytes_are_zero( - selected_bytes, sizeof(zero))) + && !semantic_activation_bytes_are_zero(selected_bytes, sizeof(zero))) || (!implicit_open - && !cluster_semantic_activation_record_decode( - selected_bytes, &decoded, NULL))))) + && !cluster_semantic_activation_record_decode(selected_bytes, &decoded, + NULL))))) return false; memcpy(SemanticActivationShmem->record_cas_desired_bytes, - result == CLUSTER_SEMANTIC_ACTIVATION_OK ? selected_bytes : zero, - sizeof(zero)); + result == CLUSTER_SEMANTIC_ACTIVATION_OK ? selected_bytes : zero, sizeof(zero)); SemanticActivationShmem->record_cas_expected_source_feature_bitmap = result == CLUSTER_SEMANTIC_ACTIVATION_OK && implicit_open ? 1 : 0; pg_write_barrier(); @@ -12071,21 +10537,18 @@ semantic_activation_authority_mailbox_completion_matches( || completion_seq + 1 != request_seq) return false; pg_read_barrier(); - if (pg_atomic_read_u32(&SemanticActivationShmem->record_cas_request_kind) - != request_kind) + if (pg_atomic_read_u32(&SemanticActivationShmem->record_cas_request_kind) != request_kind) return false; return true; } static bool -semantic_activation_authority_mailbox_complete( - ClusterSemanticAuthorityRequestKind request_kind, uint64 request_seq, - ClusterSemanticActivationResult result) +semantic_activation_authority_mailbox_complete(ClusterSemanticAuthorityRequestKind request_kind, + uint64 request_seq, + ClusterSemanticActivationResult result) { - if (result < CLUSTER_SEMANTIC_ACTIVATION_OK - || result > CLUSTER_SEMANTIC_ACTIVATION_BAD_STATE - || !semantic_activation_authority_mailbox_completion_matches( - request_kind, request_seq)) + if (result < CLUSTER_SEMANTIC_ACTIVATION_OK || result > CLUSTER_SEMANTIC_ACTIVATION_BAD_STATE + || !semantic_activation_authority_mailbox_completion_matches(request_kind, request_seq)) return false; pg_atomic_write_u32(&SemanticActivationShmem->record_cas_result, (uint32)result); @@ -12096,7 +10559,7 @@ semantic_activation_authority_mailbox_complete( static bool semantic_activation_record_cas_mailbox_poll_completion(uint64 request_seq, - ClusterSemanticActivationResult *out_result) + ClusterSemanticActivationResult *out_result) { ClusterSemanticActivationRecord desired; ClusterSemanticFormationBinding formation; @@ -12104,17 +10567,14 @@ semantic_activation_record_cas_mailbox_poll_completion(uint64 request_seq, if (out_result == NULL || !semantic_activation_authority_mailbox_poll_completion( - CLUSTER_SEMANTIC_AUTHORITY_REQUEST_RECORD_CAS, request_seq, - &result)) + CLUSTER_SEMANTIC_AUTHORITY_REQUEST_RECORD_CAS, request_seq, &result)) return false; if (result == CLUSTER_SEMANTIC_ACTIVATION_OK && (!semantic_activation_authority_request_formation_binding( CLUSTER_SEMANTIC_AUTHORITY_REQUEST_RECORD_CAS, &formation) || !cluster_semantic_activation_record_decode( - SemanticActivationShmem->record_cas_desired_bytes, - &desired, NULL) - || !semantic_activation_record_cas_formation_matches( - &formation, &desired))) + SemanticActivationShmem->record_cas_desired_bytes, &desired, NULL) + || !semantic_activation_record_cas_formation_matches(&formation, &desired))) result = CLUSTER_SEMANTIC_ACTIVATION_QUORUM_HOLD; *out_result = result; return true; @@ -12128,18 +10588,13 @@ semantic_activation_record_read_mailbox_poll_completion( if (out == NULL || !semantic_activation_authority_mailbox_poll_completion( - CLUSTER_SEMANTIC_AUTHORITY_REQUEST_RECORD_READ, request_seq, - &result)) + CLUSTER_SEMANTIC_AUTHORITY_REQUEST_RECORD_READ, request_seq, &result)) return false; memset(out, 0, sizeof(*out)); out->result = result; - out->implicit_open - = SemanticActivationShmem - ->record_cas_expected_source_feature_bitmap - != 0; - memcpy(out->selected_bytes, - SemanticActivationShmem->record_cas_desired_bytes, + out->implicit_open = SemanticActivationShmem->record_cas_expected_source_feature_bitmap != 0; + memcpy(out->selected_bytes, SemanticActivationShmem->record_cas_desired_bytes, sizeof(out->selected_bytes)); return true; } @@ -12150,13 +10605,11 @@ semantic_activation_authority_mailbox_poll_completion( ClusterSemanticActivationResult *out_result) { if (SemanticActivationShmem == NULL || out_result == NULL - || pg_atomic_read_u64(&SemanticActivationShmem->record_cas_completion_seq) - != request_seq) + || pg_atomic_read_u64(&SemanticActivationShmem->record_cas_completion_seq) != request_seq) return false; pg_read_barrier(); - if (pg_atomic_read_u32(&SemanticActivationShmem->record_cas_request_kind) - != request_kind) + if (pg_atomic_read_u32(&SemanticActivationShmem->record_cas_request_kind) != request_kind) return false; *out_result = (ClusterSemanticActivationResult)pg_atomic_read_u32( &SemanticActivationShmem->record_cas_result); @@ -12165,50 +10618,39 @@ semantic_activation_authority_mailbox_poll_completion( bool cluster_semantic_activation_undo_root_descriptor_mailbox_submit( - const ClusterSemanticFormationBinding *formation, - uint64 system_identifier, - const uint8 desired_bytes[CLUSTER_SEMANTIC_ACTIVATION_RECORD_BYTES], - uint64 *out_request_seq) + const ClusterSemanticFormationBinding *formation, uint64 system_identifier, + const uint8 desired_bytes[CLUSTER_SEMANTIC_ACTIVATION_RECORD_BYTES], uint64 *out_request_seq) { if (formation == NULL || formation->utility_request_seq == 0 - || formation->coordinator_incarnation == 0 - || system_identifier == 0 + || formation->coordinator_incarnation == 0 || system_identifier == 0 || SemanticActivationUtilityMailbox == NULL - || pg_atomic_read_u32( - &SemanticActivationUtilityMailbox->utility_mailbox_state) + || pg_atomic_read_u32(&SemanticActivationUtilityMailbox->utility_mailbox_state) != SEMANTIC_ACTIVATION_UTILITY_MAILBOX_PENDING - || pg_atomic_read_u64( - &SemanticActivationUtilityMailbox->utility_request_seq) + || pg_atomic_read_u64(&SemanticActivationUtilityMailbox->utility_request_seq) != formation->utility_request_seq || SemanticActivationUtilityMailbox->utility_expected_record_generation != formation->expected_record_generation - || !cluster_semantic_activation_qvotec_pgrd_formation_matches( - formation)) + || !cluster_semantic_activation_qvotec_pgrd_formation_matches(formation)) return false; - SemanticActivationUtilityMailbox->utility_result_feature_bit - = formation->formation_epoch; + SemanticActivationUtilityMailbox->utility_result_feature_bit = formation->formation_epoch; SemanticActivationUtilityMailbox->utility_result_expected_generation = formation->coordinator_incarnation; return semantic_activation_authority_mailbox_submit( - CLUSTER_SEMANTIC_AUTHORITY_REQUEST_UNDO_ROOT_DESCRIPTOR, - system_identifier, formation->utility_request_seq, desired_bytes, - out_request_seq); + CLUSTER_SEMANTIC_AUTHORITY_REQUEST_UNDO_ROOT_DESCRIPTOR, system_identifier, + formation->utility_request_seq, desired_bytes, out_request_seq); } bool -cluster_semantic_activation_qvotec_poll_undo_root_descriptor( - ClusterUndoRootDescriptorRequest *out) +cluster_semantic_activation_qvotec_poll_undo_root_descriptor(ClusterUndoRootDescriptorRequest *out) { uint64 request_seq; uint64 completion_seq; if (SemanticActivationShmem == NULL || out == NULL) return false; - request_seq = pg_atomic_read_u64( - &SemanticActivationShmem->record_cas_request_seq); - completion_seq = pg_atomic_read_u64( - &SemanticActivationShmem->record_cas_completion_seq); + request_seq = pg_atomic_read_u64(&SemanticActivationShmem->record_cas_request_seq); + completion_seq = pg_atomic_read_u64(&SemanticActivationShmem->record_cas_completion_seq); if (request_seq == completion_seq || completion_seq == UINT64_MAX || request_seq != completion_seq + 1) return false; @@ -12217,17 +10659,13 @@ cluster_semantic_activation_qvotec_poll_undo_root_descriptor( != CLUSTER_SEMANTIC_AUTHORITY_REQUEST_UNDO_ROOT_DESCRIPTOR) return false; out->request_seq = request_seq; - out->system_identifier - = SemanticActivationShmem->record_cas_expected_generation; - memcpy(out->desired_bytes, - SemanticActivationShmem->record_cas_desired_bytes, + out->system_identifier = SemanticActivationShmem->record_cas_expected_generation; + memcpy(out->desired_bytes, SemanticActivationShmem->record_cas_desired_bytes, sizeof(out->desired_bytes)); if (out->system_identifier == 0 || !semantic_activation_authority_request_formation_binding( - CLUSTER_SEMANTIC_AUTHORITY_REQUEST_UNDO_ROOT_DESCRIPTOR, - &out->formation) - || !cluster_semantic_activation_qvotec_pgrd_formation_matches( - &out->formation)) { + CLUSTER_SEMANTIC_AUTHORITY_REQUEST_UNDO_ROOT_DESCRIPTOR, &out->formation) + || !cluster_semantic_activation_qvotec_pgrd_formation_matches(&out->formation)) { (void)cluster_semantic_activation_qvotec_complete_undo_root_descriptor( request_seq, CLUSTER_SEMANTIC_ACTIVATION_QUORUM_HOLD); memset(out, 0, sizeof(*out)); @@ -12241,8 +10679,7 @@ cluster_semantic_activation_qvotec_complete_undo_root_descriptor( uint64 request_seq, ClusterSemanticActivationResult result) { return semantic_activation_authority_mailbox_complete( - CLUSTER_SEMANTIC_AUTHORITY_REQUEST_UNDO_ROOT_DESCRIPTOR, - request_seq, result); + CLUSTER_SEMANTIC_AUTHORITY_REQUEST_UNDO_ROOT_DESCRIPTOR, request_seq, result); } bool @@ -12250,71 +10687,58 @@ cluster_semantic_activation_undo_root_descriptor_mailbox_poll_completion( uint64 request_seq, ClusterSemanticActivationResult *out_result) { return semantic_activation_authority_mailbox_poll_completion( - CLUSTER_SEMANTIC_AUTHORITY_REQUEST_UNDO_ROOT_DESCRIPTOR, - request_seq, out_result); + CLUSTER_SEMANTIC_AUTHORITY_REQUEST_UNDO_ROOT_DESCRIPTOR, request_seq, out_result); } static bool semantic_activation_undo_root_descriptor_read_mailbox_submit( - const ClusterSemanticFormationBinding *formation, - uint64 system_identifier, uint64 *out_request_seq) + const ClusterSemanticFormationBinding *formation, uint64 system_identifier, + uint64 *out_request_seq) { uint8 zero[CLUSTER_UNDO_ROOT_DESCRIPTOR_BYTES] = { 0 }; if (formation == NULL || formation->utility_request_seq == 0 - || formation->coordinator_incarnation == 0 - || system_identifier == 0 + || formation->coordinator_incarnation == 0 || system_identifier == 0 || SemanticActivationUtilityMailbox == NULL - || pg_atomic_read_u32( - &SemanticActivationUtilityMailbox->utility_mailbox_state) + || pg_atomic_read_u32(&SemanticActivationUtilityMailbox->utility_mailbox_state) != SEMANTIC_ACTIVATION_UTILITY_MAILBOX_PENDING - || pg_atomic_read_u64( - &SemanticActivationUtilityMailbox->utility_request_seq) + || pg_atomic_read_u64(&SemanticActivationUtilityMailbox->utility_request_seq) != formation->utility_request_seq || SemanticActivationUtilityMailbox->utility_expected_record_generation != formation->expected_record_generation - || !cluster_semantic_activation_qvotec_pgrd_formation_matches( - formation)) + || !cluster_semantic_activation_qvotec_pgrd_formation_matches(formation)) return false; - SemanticActivationUtilityMailbox->utility_result_feature_bit - = formation->formation_epoch; + SemanticActivationUtilityMailbox->utility_result_feature_bit = formation->formation_epoch; SemanticActivationUtilityMailbox->utility_result_expected_generation = formation->coordinator_incarnation; return semantic_activation_authority_mailbox_submit( - CLUSTER_SEMANTIC_AUTHORITY_REQUEST_UNDO_ROOT_DESCRIPTOR_READ, - system_identifier, formation->utility_request_seq, zero, - out_request_seq); + CLUSTER_SEMANTIC_AUTHORITY_REQUEST_UNDO_ROOT_DESCRIPTOR_READ, system_identifier, + formation->utility_request_seq, zero, out_request_seq); } static bool semantic_activation_member_pgrd_read_mailbox_submit( - const ClusterSemanticActivationAckTableV1 *expected_table, - uint64 *out_request_seq) + const ClusterSemanticActivationAckTableV1 *expected_table, uint64 *out_request_seq) { ClusterSemanticActivationAckTableV1 current; SemanticActivationAckTuple self; uint8 zero[CLUSTER_UNDO_ROOT_DESCRIPTOR_BYTES] = { 0 }; uint64 system_identifier = GetSystemIdentifier(); - if (expected_table == NULL || out_request_seq == NULL - || system_identifier == 0 + if (expected_table == NULL || out_request_seq == NULL || system_identifier == 0 || !semantic_activation_ack_table_snapshot(¤t) || memcmp(expected_table, ¤t, sizeof(current)) != 0 || current.stage != CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_PREPARED || current.source_feature_bitmap != 0 - || current.target_feature_bitmap - != CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1 - || current.rollback_feature_bitmap != 0 - || current.round_nonce == 0 - || cluster_node_id < 0 || cluster_node_id >= 4 - || cluster_node_id == (int32)current.coordinator_node - || !semantic_activation_ack_member_prepared_image_current( - ¤t, &self)) + || current.target_feature_bitmap != CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1 + || current.rollback_feature_bitmap != 0 || current.round_nonce == 0 || cluster_node_id < 0 + || cluster_node_id >= 4 || cluster_node_id == (int32)current.coordinator_node + || !semantic_activation_ack_member_prepared_image_current(¤t, &self)) return false; return semantic_activation_authority_mailbox_submit( - CLUSTER_SEMANTIC_AUTHORITY_REQUEST_UNDO_ROOT_DESCRIPTOR_READ, - system_identifier, current.round_nonce, zero, out_request_seq); + CLUSTER_SEMANTIC_AUTHORITY_REQUEST_UNDO_ROOT_DESCRIPTOR_READ, system_identifier, + current.round_nonce, zero, out_request_seq); } bool @@ -12327,27 +10751,21 @@ cluster_semantic_activation_qvotec_poll_undo_root_descriptor_read( if (SemanticActivationShmem == NULL || out == NULL) return false; - request_seq = pg_atomic_read_u64( - &SemanticActivationShmem->record_cas_request_seq); - completion_seq = pg_atomic_read_u64( - &SemanticActivationShmem->record_cas_completion_seq); + request_seq = pg_atomic_read_u64(&SemanticActivationShmem->record_cas_request_seq); + completion_seq = pg_atomic_read_u64(&SemanticActivationShmem->record_cas_completion_seq); if (request_seq == completion_seq || completion_seq == UINT64_MAX || request_seq != completion_seq + 1) return false; pg_read_barrier(); - if (pg_atomic_read_u32( - &SemanticActivationShmem->record_cas_request_kind) + if (pg_atomic_read_u32(&SemanticActivationShmem->record_cas_request_kind) != CLUSTER_SEMANTIC_AUTHORITY_REQUEST_UNDO_ROOT_DESCRIPTOR_READ) return false; out->request_seq = request_seq; - out->system_identifier - = SemanticActivationShmem->record_cas_expected_generation; + out->system_identifier = SemanticActivationShmem->record_cas_expected_generation; if (out->system_identifier == 0 || !semantic_activation_authority_request_formation_binding( - CLUSTER_SEMANTIC_AUTHORITY_REQUEST_UNDO_ROOT_DESCRIPTOR_READ, - &out->formation) - || !cluster_semantic_activation_qvotec_pgrd_formation_matches( - &out->formation)) { + CLUSTER_SEMANTIC_AUTHORITY_REQUEST_UNDO_ROOT_DESCRIPTOR_READ, &out->formation) + || !cluster_semantic_activation_qvotec_pgrd_formation_matches(&out->formation)) { (void)cluster_semantic_activation_qvotec_complete_undo_root_descriptor_read( request_seq, CLUSTER_UNDO_ROOT_DESCRIPTOR_HOLD, zero); memset(out, 0, sizeof(*out)); @@ -12358,8 +10776,7 @@ cluster_semantic_activation_qvotec_poll_undo_root_descriptor_read( static bool semantic_activation_qvotec_formation_matches_expected( - const ClusterSemanticFormationBinding *formation, - uint64 utility_expected_record_generation, + const ClusterSemanticFormationBinding *formation, uint64 utility_expected_record_generation, bool require_r4_admitted_basis) { SemanticActivationAdmissionSnapshot snapshot; @@ -12367,15 +10784,12 @@ semantic_activation_qvotec_formation_matches_expected( uint64 current_incarnation; if (formation == NULL || formation->utility_request_seq == 0 - || formation->coordinator_incarnation == 0 - || SemanticActivationUtilityMailbox == NULL - || SemanticActivationShmem == NULL - || cluster_node_id < 0 || cluster_node_id >= CLUSTER_MAX_NODES - || pg_atomic_read_u32( - &SemanticActivationUtilityMailbox->utility_mailbox_state) + || formation->coordinator_incarnation == 0 || SemanticActivationUtilityMailbox == NULL + || SemanticActivationShmem == NULL || cluster_node_id < 0 + || cluster_node_id >= CLUSTER_MAX_NODES + || pg_atomic_read_u32(&SemanticActivationUtilityMailbox->utility_mailbox_state) != SEMANTIC_ACTIVATION_UTILITY_MAILBOX_PENDING - || pg_atomic_read_u64( - &SemanticActivationUtilityMailbox->utility_request_seq) + || pg_atomic_read_u64(&SemanticActivationUtilityMailbox->utility_request_seq) != formation->utility_request_seq || SemanticActivationUtilityMailbox->utility_expected_record_generation != utility_expected_record_generation @@ -12388,22 +10802,18 @@ semantic_activation_qvotec_formation_matches_expected( || current_incarnation != formation->coordinator_incarnation || !semantic_activation_snapshot(&snapshot) || snapshot.formation_epoch != formation->formation_epoch - || snapshot.record_generation - != formation->expected_record_generation - || (require_r4_admitted_basis - && !semantic_activation_r4_current_admitted_basis())) + || snapshot.record_generation != formation->expected_record_generation + || (require_r4_admitted_basis && !semantic_activation_r4_current_admitted_basis())) return false; - return cluster_qvotec_in_quorum() - && cluster_epoch_get_current() == current_epoch + return cluster_qvotec_in_quorum() && cluster_epoch_get_current() == current_epoch && cluster_qvotec_get_self_incarnation() == current_incarnation; } static bool -semantic_activation_r4_initial_clean_cas_matches( - const ClusterSemanticFormationBinding *formation, - const ClusterSemanticActivationRecord *desired, - uint64 utility_expected_record_generation) +semantic_activation_r4_initial_clean_cas_matches(const ClusterSemanticFormationBinding *formation, + const ClusterSemanticActivationRecord *desired, + uint64 utility_expected_record_generation) { ClusterInitialCleanFormationSnapshot clean_before; ClusterInitialCleanFormationSnapshot clean_after; @@ -12420,34 +10830,28 @@ semantic_activation_r4_initial_clean_cas_matches( int32 coordinator_node; int node; - if (formation == NULL || desired == NULL - || utility_expected_record_generation != 0 + if (formation == NULL || desired == NULL || utility_expected_record_generation != 0 || desired->source_feature_bitmap != 0 - || desired->target_feature_bitmap - != CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1 - || desired->rollback_feature_bitmap != 0 - || desired->capability_sample_digest == 0) + || desired->target_feature_bitmap != CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1 + || desired->rollback_feature_bitmap != 0 || desired->capability_sample_digest == 0) return false; switch (desired->phase) { case CLUSTER_SEMANTIC_PHASE_PREPARE: if (desired->record_generation != 1) return false; - expected_table_stage - = CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_SAMPLE; + expected_table_stage = CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_SAMPLE; expected_table_generation = desired->record_generation; break; case CLUSTER_SEMANTIC_PHASE_COMMIT: if (desired->record_generation != 2) return false; - expected_table_stage - = CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_PREPARED; + expected_table_stage = CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_PREPARED; expected_table_generation = desired->record_generation - 1; break; case CLUSTER_SEMANTIC_PHASE_OPEN: if (desired->record_generation != 3) return false; - expected_table_stage - = CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_COMMIT_APPLIED; + expected_table_stage = CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_COMMIT_APPLIED; expected_table_generation = desired->record_generation - 1; break; default: @@ -12457,24 +10861,19 @@ semantic_activation_r4_initial_clean_cas_matches( if (cluster_grd_recovery_state_value() != GRD_RECOVERY_IDLE || !semantic_activation_qvotec_formation_matches_expected( formation, utility_expected_record_generation, false) - || !cluster_reconfig_snapshot_initial_clean_formation( - &clean_before) + || !cluster_reconfig_snapshot_initial_clean_formation(&clean_before) || (clean_before.formation_marker_generation == 0 && clean_before.formation_epoch != CLUSTER_EPOCH_INITIAL) - || clean_before.members_lo != UINT64_C(0x0f) - || clean_before.members_hi != 0 + || clean_before.members_lo != UINT64_C(0x0f) || clean_before.members_hi != 0 || clean_before.formation_epoch != desired->transition_epoch || desired->admitted_members_lo != clean_before.members_lo - || desired->admitted_members_hi != clean_before.members_hi - || desired->coordinator_node != 0 - || desired->coordinator_incarnation - != clean_before.admitted_incarnation[0] + || desired->admitted_members_hi != clean_before.members_hi || desired->coordinator_node != 0 + || desired->coordinator_incarnation != clean_before.admitted_incarnation[0] || !semantic_activation_initial_clean_pgrd_mirror(pgrd_before) - || !semantic_activation_ack_table_snapshot(&table) - || table.stage != expected_table_stage + || !semantic_activation_ack_table_snapshot(&table) || table.stage != expected_table_stage || table.flags - != (CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID - | CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE) + != (CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID + | CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE) || table.transition_epoch != desired->transition_epoch || table.record_generation != expected_table_generation || table.coordinator_node != desired->coordinator_node @@ -12484,43 +10883,34 @@ semantic_activation_r4_initial_clean_cas_matches( || table.source_feature_bitmap != desired->source_feature_bitmap || table.target_feature_bitmap != desired->target_feature_bitmap || table.rollback_feature_bitmap != desired->rollback_feature_bitmap - || !semantic_activation_ack_current_authority( - cluster_node_id, &members_lo, &members_hi, &formation_epoch, - &coordinator_node) - || members_lo != clean_before.members_lo - || members_hi != clean_before.members_hi - || formation_epoch != clean_before.formation_epoch - || coordinator_node != 0 || cluster_node_id != coordinator_node) + || !semantic_activation_ack_current_authority(cluster_node_id, &members_lo, &members_hi, + &formation_epoch, &coordinator_node) + || members_lo != clean_before.members_lo || members_hi != clean_before.members_hi + || formation_epoch != clean_before.formation_epoch || coordinator_node != 0 + || cluster_node_id != coordinator_node) return false; local_capability_word = cluster_ic_local_capability_word(); - if (!semantic_activation_ack_complete_image_current( - &table, members_lo, members_hi, formation_epoch, - coordinator_node, cluster_node_id, local_capability_word)) + if (!semantic_activation_ack_complete_image_current(&table, members_lo, members_hi, + formation_epoch, coordinator_node, + cluster_node_id, local_capability_word)) return false; if (desired->phase == CLUSTER_SEMANTIC_PHASE_PREPARE) { if (table.capability_sample_digest != 0 - || !semantic_activation_ack_sample_digest( - &table, &capability_sample_digest) - || capability_sample_digest - != desired->capability_sample_digest) + || !semantic_activation_ack_sample_digest(&table, &capability_sample_digest) + || capability_sample_digest != desired->capability_sample_digest) return false; - } else if (table.capability_sample_digest - != desired->capability_sample_digest) + } else if (table.capability_sample_digest != desired->capability_sample_digest) return false; for (node = 0; node < 4; node++) { - if (table.expected[node].admitted_incarnation - != clean_before.admitted_incarnation[node] - || table.observed[node].admitted_incarnation - != clean_before.admitted_incarnation[node]) + if (table.expected[node].admitted_incarnation != clean_before.admitted_incarnation[node] + || table.observed[node].admitted_incarnation != clean_before.admitted_incarnation[node]) return false; } return cluster_grd_recovery_state_value() == GRD_RECOVERY_IDLE - && cluster_reconfig_snapshot_initial_clean_formation( - &clean_after) - && semantic_activation_initial_clean_snapshot_equal( - &clean_before, &clean_after) + && cluster_reconfig_snapshot_initial_clean_formation(&clean_after) + && semantic_activation_initial_clean_snapshot_equal(&clean_before, &clean_after) && semantic_activation_initial_clean_pgrd_mirror(pgrd_after) && memcmp(pgrd_before, pgrd_after, sizeof(pgrd_before)) == 0 && cluster_qvotec_in_quorum() @@ -12541,16 +10931,14 @@ semantic_activation_r4_initial_clean_cas_matches( * generation above the COMMIT_APPLIED table. */ static bool -semantic_activation_bit22_cas_table_binding_matches( - const ClusterSemanticActivationRecord *desired) +semantic_activation_bit22_cas_table_binding_matches(const ClusterSemanticActivationRecord *desired) { ClusterSemanticActivationAckTableV1 table; uint64 expected_table_generation; if (desired == NULL || SemanticActivationAckTable == NULL || !semantic_activation_ack_table_snapshot(&table) - || (table.target_feature_bitmap - & PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1) == 0 + || (table.target_feature_bitmap & PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1) == 0 || table.transition_epoch != desired->transition_epoch || table.coordinator_node != desired->coordinator_node || table.expected_members_lo != desired->admitted_members_lo @@ -12558,10 +10946,8 @@ semantic_activation_bit22_cas_table_binding_matches( || table.source_feature_bitmap != desired->source_feature_bitmap || table.target_feature_bitmap != desired->target_feature_bitmap || table.rollback_feature_bitmap != desired->rollback_feature_bitmap - || table.capability_sample_digest - != desired->capability_sample_digest - || desired->coordinator_incarnation - != cluster_qvotec_get_self_incarnation()) + || table.capability_sample_digest != desired->capability_sample_digest + || desired->coordinator_incarnation != cluster_qvotec_get_self_incarnation()) return false; switch (desired->phase) { case CLUSTER_SEMANTIC_PHASE_PREPARE: @@ -12591,21 +10977,17 @@ semantic_activation_bit22_cas_table_binding_matches( } static bool -semantic_activation_record_cas_formation_matches( - const ClusterSemanticFormationBinding *formation, - const ClusterSemanticActivationRecord *desired) +semantic_activation_record_cas_formation_matches(const ClusterSemanticFormationBinding *formation, + const ClusterSemanticActivationRecord *desired) { uint64 utility_expected_record_generation; uint32 required_caps; bool require_r4_admitted_basis; - if (formation == NULL || desired == NULL - || formation->expected_record_generation == UINT64_MAX - || desired->record_generation - != formation->expected_record_generation + 1 + if (formation == NULL || desired == NULL || formation->expected_record_generation == UINT64_MAX + || desired->record_generation != formation->expected_record_generation + 1 || desired->transition_epoch != formation->formation_epoch - || desired->coordinator_incarnation - != formation->coordinator_incarnation + || desired->coordinator_incarnation != formation->coordinator_incarnation || cluster_node_id < 0 || cluster_node_id >= CLUSTER_MAX_NODES || desired->coordinator_node != (uint32)cluster_node_id) return false; @@ -12616,19 +10998,15 @@ semantic_activation_record_cas_formation_matches( * utility mailbox. They bind to the ACK table's round identity * instead — the table is constructed by begin() from the same round * and every member ACKs it before the CAS is submitted. */ - if ((desired->target_feature_bitmap - & PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1) != 0) - return semantic_activation_bit22_cas_table_binding_matches( - desired); + if ((desired->target_feature_bitmap & PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1) + != 0) + return semantic_activation_bit22_cas_table_binding_matches(desired); if (!semantic_activation_ack_round_required_caps( - desired->source_feature_bitmap, - desired->target_feature_bitmap, + desired->source_feature_bitmap, desired->target_feature_bitmap, desired->rollback_feature_bitmap, &required_caps) - || required_caps == 0 - || SemanticActivationUtilityMailbox == NULL - || SemanticActivationUtilityMailbox->utility_action - != CLUSTER_SEMANTIC_ENABLE_ALL + || required_caps == 0 || SemanticActivationUtilityMailbox == NULL + || SemanticActivationUtilityMailbox->utility_action != CLUSTER_SEMANTIC_ENABLE_ALL || SemanticActivationUtilityMailbox->utility_source_feature_bitmap != desired->source_feature_bitmap || SemanticActivationUtilityMailbox->utility_target_feature_bitmap @@ -12638,19 +11016,16 @@ semantic_activation_record_cas_formation_matches( return false; require_r4_admitted_basis = desired->source_feature_bitmap == 0 - && desired->target_feature_bitmap - == CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1; + && desired->target_feature_bitmap == CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1; switch (desired->phase) { case CLUSTER_SEMANTIC_PHASE_PREPARE: - utility_expected_record_generation - = formation->expected_record_generation; + utility_expected_record_generation = formation->expected_record_generation; break; case CLUSTER_SEMANTIC_PHASE_COMMIT: if (formation->expected_record_generation == 0) return false; - utility_expected_record_generation - = formation->expected_record_generation - 1; + utility_expected_record_generation = formation->expected_record_generation - 1; break; case CLUSTER_SEMANTIC_PHASE_OPEN: /* RF-ROOT P9 verification (verified implementation): the bit22 cutover @@ -12660,8 +11035,7 @@ semantic_activation_record_cas_formation_matches( * expected - 2. */ if (formation->expected_record_generation < 2) return false; - utility_expected_record_generation - = formation->expected_record_generation - 2; + utility_expected_record_generation = formation->expected_record_generation - 2; break; default: return false; @@ -12673,8 +11047,8 @@ semantic_activation_record_cas_formation_matches( if (semantic_activation_qvotec_formation_matches_expected( formation, utility_expected_record_generation, true)) return true; - return semantic_activation_r4_initial_clean_cas_matches( - formation, desired, utility_expected_record_generation); + return semantic_activation_r4_initial_clean_cas_matches(formation, desired, + utility_expected_record_generation); } bool @@ -12687,49 +11061,37 @@ cluster_semantic_activation_qvotec_pgrd_formation_matches( uint64 current_incarnation; if (formation == NULL || formation->utility_request_seq == 0 - || formation->coordinator_incarnation == 0 - || SemanticActivationShmem == NULL + || formation->coordinator_incarnation == 0 || SemanticActivationShmem == NULL || cluster_node_id < 0 || cluster_node_id >= CLUSTER_MAX_NODES || !cluster_qvotec_in_quorum()) return false; memset(&member_binding, 0, sizeof(member_binding)); - if (semantic_activation_member_pgrd_formation_binding( - &member_binding) - && member_binding.utility_request_seq - == formation->utility_request_seq + if (semantic_activation_member_pgrd_formation_binding(&member_binding) + && member_binding.utility_request_seq == formation->utility_request_seq && member_binding.formation_epoch == formation->formation_epoch - && member_binding.coordinator_incarnation - == formation->coordinator_incarnation - && member_binding.expected_record_generation - == formation->expected_record_generation) { + && member_binding.coordinator_incarnation == formation->coordinator_incarnation + && member_binding.expected_record_generation == formation->expected_record_generation) { current_epoch = cluster_epoch_get_current(); current_incarnation = cluster_qvotec_get_self_incarnation(); return current_epoch == formation->formation_epoch - && current_incarnation - == formation->coordinator_incarnation - && cluster_qvotec_in_quorum() - && cluster_epoch_get_current() == current_epoch - && cluster_qvotec_get_self_incarnation() - == current_incarnation; + && current_incarnation == formation->coordinator_incarnation + && cluster_qvotec_in_quorum() && cluster_epoch_get_current() == current_epoch + && cluster_qvotec_get_self_incarnation() == current_incarnation; } if (SemanticActivationUtilityMailbox == NULL - || pg_atomic_read_u32( - &SemanticActivationUtilityMailbox->utility_mailbox_state) + || pg_atomic_read_u32(&SemanticActivationUtilityMailbox->utility_mailbox_state) != SEMANTIC_ACTIVATION_UTILITY_MAILBOX_PENDING - || pg_atomic_read_u64( - &SemanticActivationUtilityMailbox->utility_request_seq) + || pg_atomic_read_u64(&SemanticActivationUtilityMailbox->utility_request_seq) != formation->utility_request_seq - || SemanticActivationUtilityMailbox->utility_action - != CLUSTER_SEMANTIC_ENABLE_ALL + || SemanticActivationUtilityMailbox->utility_action != CLUSTER_SEMANTIC_ENABLE_ALL || SemanticActivationUtilityMailbox->utility_source_feature_bitmap != 0 || SemanticActivationUtilityMailbox->utility_target_feature_bitmap != CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1 || SemanticActivationUtilityMailbox->utility_rollback_feature_bitmap != 0 || SemanticActivationUtilityMailbox->utility_expected_record_generation - != formation->expected_record_generation - ) + != formation->expected_record_generation) return false; current_epoch = cluster_epoch_get_current(); @@ -12738,13 +11100,11 @@ cluster_semantic_activation_qvotec_pgrd_formation_matches( || current_incarnation != formation->coordinator_incarnation || !semantic_activation_snapshot(&snapshot) || snapshot.formation_epoch != formation->formation_epoch - || snapshot.record_generation - != formation->expected_record_generation + || snapshot.record_generation != formation->expected_record_generation || snapshot.active_bits != 0 || snapshot.transition_closed) return false; - return cluster_qvotec_in_quorum() - && cluster_epoch_get_current() == current_epoch + return cluster_qvotec_in_quorum() && cluster_epoch_get_current() == current_epoch && cluster_qvotec_get_self_incarnation() == current_incarnation; } @@ -12758,20 +11118,15 @@ cluster_semantic_activation_qvotec_complete_undo_root_descriptor_read( uint64 system_identifier; if (!semantic_activation_authority_mailbox_completion_matches( - CLUSTER_SEMANTIC_AUTHORITY_REQUEST_UNDO_ROOT_DESCRIPTOR_READ, - request_seq) + CLUSTER_SEMANTIC_AUTHORITY_REQUEST_UNDO_ROOT_DESCRIPTOR_READ, request_seq) || state < CLUSTER_UNDO_ROOT_DESCRIPTOR_UNPROVISIONED - || state > CLUSTER_UNDO_ROOT_DESCRIPTOR_HOLD - || selected_bytes == NULL) + || state > CLUSTER_UNDO_ROOT_DESCRIPTOR_HOLD || selected_bytes == NULL) return false; - system_identifier - = SemanticActivationShmem->record_cas_expected_generation; + system_identifier = SemanticActivationShmem->record_cas_expected_generation; if ((state == CLUSTER_UNDO_ROOT_DESCRIPTOR_UNPROVISIONED - && !semantic_activation_bytes_are_zero( - selected_bytes, sizeof(zero))) + && !semantic_activation_bytes_are_zero(selected_bytes, sizeof(zero))) || (state == CLUSTER_UNDO_ROOT_DESCRIPTOR_VALID - && (cluster_undo_root_descriptor_decode( - selected_bytes, system_identifier, &descriptor) + && (cluster_undo_root_descriptor_decode(selected_bytes, system_identifier, &descriptor) != CLUSTER_UNDO_ROOT_DESCRIPTOR_VALID || descriptor.descriptor_incarnation != 1 || descriptor.root_kind != CLUSTER_UNDO_ROOT_KIND_SHARED @@ -12779,13 +11134,11 @@ cluster_semantic_activation_qvotec_complete_undo_root_descriptor_read( return false; memcpy(SemanticActivationShmem->record_cas_desired_bytes, - state == CLUSTER_UNDO_ROOT_DESCRIPTOR_VALID ? selected_bytes - : zero, - sizeof(zero)); + state == CLUSTER_UNDO_ROOT_DESCRIPTOR_VALID ? selected_bytes : zero, sizeof(zero)); pg_write_barrier(); return semantic_activation_authority_mailbox_complete( - CLUSTER_SEMANTIC_AUTHORITY_REQUEST_UNDO_ROOT_DESCRIPTOR_READ, - request_seq, (ClusterSemanticActivationResult)state); + CLUSTER_SEMANTIC_AUTHORITY_REQUEST_UNDO_ROOT_DESCRIPTOR_READ, request_seq, + (ClusterSemanticActivationResult)state); } static bool @@ -12795,21 +11148,17 @@ semantic_activation_undo_root_descriptor_read_mailbox_poll_completion( uint32 state; if (SemanticActivationShmem == NULL || out == NULL - || pg_atomic_read_u64( - &SemanticActivationShmem->record_cas_completion_seq) - != request_seq) + || pg_atomic_read_u64(&SemanticActivationShmem->record_cas_completion_seq) != request_seq) return false; pg_read_barrier(); - if (pg_atomic_read_u32( - &SemanticActivationShmem->record_cas_request_kind) + if (pg_atomic_read_u32(&SemanticActivationShmem->record_cas_request_kind) != CLUSTER_SEMANTIC_AUTHORITY_REQUEST_UNDO_ROOT_DESCRIPTOR_READ) return false; state = pg_atomic_read_u32(&SemanticActivationShmem->record_cas_result); if (state > CLUSTER_UNDO_ROOT_DESCRIPTOR_HOLD) return false; out->state = (ClusterUndoRootDescriptorState)state; - memcpy(out->selected_bytes, - SemanticActivationShmem->record_cas_desired_bytes, + memcpy(out->selected_bytes, SemanticActivationShmem->record_cas_desired_bytes, sizeof(out->selected_bytes)); return true; } @@ -12817,20 +11166,17 @@ semantic_activation_undo_root_descriptor_read_mailbox_poll_completion( static bool semantic_activation_lmon_submit_pgrd_candidate( const uint8 candidate[CLUSTER_UNDO_ROOT_DESCRIPTOR_BYTES], - const ClusterSemanticFormationBinding *formation, - uint64 system_identifier, + const ClusterSemanticFormationBinding *formation, uint64 system_identifier, uint64 *out_request_seq) { ClusterUndoRootDescriptorV1 descriptor; uint64 request_seq; if (candidate == NULL || system_identifier == 0 || out_request_seq == NULL - || cluster_undo_root_descriptor_decode( - candidate, system_identifier, &descriptor) + || cluster_undo_root_descriptor_decode(candidate, system_identifier, &descriptor) != CLUSTER_UNDO_ROOT_DESCRIPTOR_VALID || descriptor.descriptor_incarnation != 1 - || descriptor.root_kind != CLUSTER_UNDO_ROOT_KIND_SHARED - || descriptor.owner_node != -1) + || descriptor.root_kind != CLUSTER_UNDO_ROOT_KIND_SHARED || descriptor.owner_node != -1) return false; if (!cluster_semantic_activation_undo_root_descriptor_mailbox_submit( @@ -12844,49 +11190,42 @@ semantic_activation_lmon_submit_pgrd_candidate( } static bool -semantic_activation_lmon_submit_pgrd_exact_retry( - const char *root_directory, - const ClusterSemanticFormationBinding *formation, - uint64 system_identifier, - uint64 *out_request_seq) +semantic_activation_lmon_submit_pgrd_exact_retry(const char *root_directory, + const ClusterSemanticFormationBinding *formation, + uint64 system_identifier, uint64 *out_request_seq) { uint8 candidate[CLUSTER_UNDO_ROOT_DESCRIPTOR_BYTES]; - if (cluster_undo_smgr_root_descriptor_read_candidate( - root_directory, candidate) + if (cluster_undo_smgr_root_descriptor_read_candidate(root_directory, candidate) != CLUSTER_UNDO_SMGR_ROOT_MIRROR_EXACT) return false; - return semantic_activation_lmon_submit_pgrd_candidate( - candidate, formation, system_identifier, out_request_seq); + return semantic_activation_lmon_submit_pgrd_candidate(candidate, formation, system_identifier, + out_request_seq); } static bool -semantic_activation_lmon_shared_pgrd_root_directory( - char root_directory[MAXPGPATH]) +semantic_activation_lmon_shared_pgrd_root_directory(char root_directory[MAXPGPATH]) { int path_len; if (root_directory == NULL || cluster_shared_data_dir == NULL || cluster_shared_data_dir[0] == '\0') return false; - path_len = snprintf(root_directory, MAXPGPATH, "%s/pg_undo", - cluster_shared_data_dir); + path_len = snprintf(root_directory, MAXPGPATH, "%s/pg_undo", cluster_shared_data_dir); return path_len >= 0 && path_len < MAXPGPATH; } static bool -semantic_activation_lmon_publish_fresh_shared_pgrd( - const char *root_directory, - const ClusterSemanticFormationBinding *formation, - uint64 system_identifier, - uint64 *out_request_seq) +semantic_activation_lmon_publish_fresh_shared_pgrd(const char *root_directory, + const ClusterSemanticFormationBinding *formation, + uint64 system_identifier, + uint64 *out_request_seq) { ClusterUndoRootDescriptorV1 descriptor; ClusterUndoSmgrRootMirrorState publish_state; uint8 desired[CLUSTER_UNDO_ROOT_DESCRIPTOR_BYTES]; - if (root_directory == NULL || system_identifier == 0 - || out_request_seq == NULL) + if (root_directory == NULL || system_identifier == 0 || out_request_seq == NULL) return false; memset(&descriptor, 0, sizeof(descriptor)); descriptor.descriptor_incarnation = 1; @@ -12894,21 +11233,18 @@ semantic_activation_lmon_publish_fresh_shared_pgrd( descriptor.owner_node = -1; descriptor.root_ordinal = 0; descriptor.system_identifier = system_identifier; - if (!cluster_undo_root_namespace_id( - descriptor.descriptor_incarnation, descriptor.root_ordinal, - &descriptor.namespace_id) - || !pg_strong_random(descriptor.root_uuid, - sizeof(descriptor.root_uuid)) + if (!cluster_undo_root_namespace_id(descriptor.descriptor_incarnation, descriptor.root_ordinal, + &descriptor.namespace_id) + || !pg_strong_random(descriptor.root_uuid, sizeof(descriptor.root_uuid)) || !cluster_undo_root_descriptor_encode(&descriptor, desired)) return false; - publish_state = cluster_undo_smgr_root_descriptor_publish( - root_directory, desired); + publish_state = cluster_undo_smgr_root_descriptor_publish(root_directory, desired); if (publish_state != CLUSTER_UNDO_SMGR_ROOT_MIRROR_PUBLISHED && publish_state != CLUSTER_UNDO_SMGR_ROOT_MIRROR_EXACT) return false; - return semantic_activation_lmon_submit_pgrd_candidate( - desired, formation, system_identifier, out_request_seq); + return semantic_activation_lmon_submit_pgrd_candidate(desired, formation, system_identifier, + out_request_seq); } void @@ -12917,38 +11253,29 @@ cluster_semantic_activation_register(const ClusterSemanticActivationDescriptor * int feature_index; int index; - if (descriptor == NULL || descriptor->name == NULL - || descriptor->name[0] == '\0' - || !semantic_activation_feature_bit_index( - descriptor->feature_bit, &feature_index) - || descriptor->required_hello_caps == 0 - || descriptor->pre_prepare_readiness == NULL + if (descriptor == NULL || descriptor->name == NULL || descriptor->name[0] == '\0' + || !semantic_activation_feature_bit_index(descriptor->feature_bit, &feature_index) + || descriptor->required_hello_caps == 0 || descriptor->pre_prepare_readiness == NULL || descriptor->close_source_admission == NULL - || descriptor->source_logical_debt_zero == NULL - || descriptor->source_transport_zero == NULL - || descriptor->prepare_target == NULL - || descriptor->apply_target_closed == NULL - || descriptor->revert_source_closed == NULL - || descriptor->open_target_admission == NULL) - ereport(FATAL, - (errcode(ERRCODE_INTERNAL_ERROR), - errmsg("invalid semantic activation descriptor"))); + || descriptor->source_logical_debt_zero == NULL || descriptor->source_transport_zero == NULL + || descriptor->prepare_target == NULL || descriptor->apply_target_closed == NULL + || descriptor->revert_source_closed == NULL || descriptor->open_target_admission == NULL) + ereport(FATAL, (errcode(ERRCODE_INTERNAL_ERROR), + errmsg("invalid semantic activation descriptor"))); if (SemanticActivationDescriptors[feature_index] != NULL) { if (SemanticActivationDescriptors[feature_index] == descriptor) return; - ereport(FATAL, - (errcode(ERRCODE_INTERNAL_ERROR), - errmsg("duplicate semantic activation feature bit"))); + ereport(FATAL, (errcode(ERRCODE_INTERNAL_ERROR), + errmsg("duplicate semantic activation feature bit"))); } for (index = 0; index < 64; index++) { const ClusterSemanticActivationDescriptor *registered = SemanticActivationDescriptors[index]; if (registered != NULL && strcmp(registered->name, descriptor->name) == 0) - ereport(FATAL, - (errcode(ERRCODE_INTERNAL_ERROR), - errmsg("duplicate semantic activation feature name"))); + ereport(FATAL, (errcode(ERRCODE_INTERNAL_ERROR), + errmsg("duplicate semantic activation feature name"))); } SemanticActivationDescriptors[feature_index] = descriptor; } @@ -12976,11 +11303,9 @@ cluster_semantic_activation_compiled_feature_bitmap(void) } static bool -semantic_activation_ack_wire_value_valid( - const ClusterSemanticActivationAckWireV1 *message) +semantic_activation_ack_wire_value_valid(const ClusterSemanticActivationAckWireV1 *message) { - if (message == NULL - || message->kind < CLUSTER_SEMANTIC_ACTIVATION_ACK_KIND_REQUEST + if (message == NULL || message->kind < CLUSTER_SEMANTIC_ACTIVATION_ACK_KIND_REQUEST || message->kind > CLUSTER_SEMANTIC_ACTIVATION_ACK_KIND_ACK || message->stage < CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_SAMPLE || message->stage > CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_OPEN_APPLIED @@ -12988,15 +11313,13 @@ semantic_activation_ack_wire_value_valid( || message->coordinator_node >= CLUSTER_MAX_NODES || message->member_node >= CLUSTER_MAX_NODES || (message->coordinator_node < 64 - ? (message->admitted_members_lo - & (UINT64_C(1) << message->coordinator_node)) == 0 - : (message->admitted_members_hi - & (UINT64_C(1) << (message->coordinator_node - 64))) == 0) + ? (message->admitted_members_lo & (UINT64_C(1) << message->coordinator_node)) == 0 + : (message->admitted_members_hi & (UINT64_C(1) << (message->coordinator_node - 64))) + == 0) || (message->member_node < 64 - ? (message->admitted_members_lo - & (UINT64_C(1) << message->member_node)) == 0 - : (message->admitted_members_hi - & (UINT64_C(1) << (message->member_node - 64))) == 0) + ? (message->admitted_members_lo & (UINT64_C(1) << message->member_node)) == 0 + : (message->admitted_members_hi & (UINT64_C(1) << (message->member_node - 64))) + == 0) || message->record_generation == 0 || message->round_nonce == 0 || (message->stage == CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_SAMPLE && message->capability_sample_digest != 0) @@ -13004,30 +11327,22 @@ semantic_activation_ack_wire_value_valid( && message->capability_sample_digest == 0)) return false; if (message->kind == CLUSTER_SEMANTIC_ACTIVATION_ACK_KIND_REQUEST) - return message->result - == CLUSTER_SEMANTIC_ACTIVATION_ACK_RESULT_REQUEST - && message->reason == 0 - && message->boot_id == 0 - && message->admitted_incarnation == 0 - && message->capability_word == 0; + return message->result == CLUSTER_SEMANTIC_ACTIVATION_ACK_RESULT_REQUEST + && message->reason == 0 && message->boot_id == 0 + && message->admitted_incarnation == 0 && message->capability_word == 0; if (message->result == CLUSTER_SEMANTIC_ACTIVATION_ACK_RESULT_OK) - return message->reason == 0 - && message->boot_id != 0 - && message->admitted_incarnation != 0 - && message->capability_word != 0; + return message->reason == 0 && message->boot_id != 0 && message->admitted_incarnation != 0 + && message->capability_word != 0; if (message->result == CLUSTER_SEMANTIC_ACTIVATION_ACK_RESULT_REFUSED) return message->reason > CLUSTER_SEMANTIC_ACTIVATION_OK - && message->reason <= CLUSTER_SEMANTIC_ACTIVATION_BAD_STATE - && message->boot_id == 0 - && message->admitted_incarnation == 0 - && message->capability_word == 0; + && message->reason <= CLUSTER_SEMANTIC_ACTIVATION_BAD_STATE && message->boot_id == 0 + && message->admitted_incarnation == 0 && message->capability_word == 0; return false; } bool -cluster_semantic_activation_ack_wire_encode( - const ClusterSemanticActivationAckWireV1 *message, - uint8 bytes[CLUSTER_SEMANTIC_ACTIVATION_ACK_WIRE_BYTES]) +cluster_semantic_activation_ack_wire_encode(const ClusterSemanticActivationAckWireV1 *message, + uint8 bytes[CLUSTER_SEMANTIC_ACTIVATION_ACK_WIRE_BYTES]) { uint8 encoded[CLUSTER_SEMANTIC_ACTIVATION_ACK_WIRE_BYTES]; @@ -13035,10 +11350,8 @@ cluster_semantic_activation_ack_wire_encode( return false; memset(encoded, 0, sizeof(encoded)); - semantic_activation_write_u32_le(encoded, - CLUSTER_SEMANTIC_ACTIVATION_ACK_WIRE_MAGIC); - semantic_activation_write_u16_le(encoded + 4, - CLUSTER_SEMANTIC_ACTIVATION_ACK_WIRE_VERSION); + semantic_activation_write_u32_le(encoded, CLUSTER_SEMANTIC_ACTIVATION_ACK_WIRE_MAGIC); + semantic_activation_write_u16_le(encoded + 4, CLUSTER_SEMANTIC_ACTIVATION_ACK_WIRE_VERSION); encoded[6] = message->kind; encoded[7] = message->stage; semantic_activation_write_u32_le(encoded + 8, message->result); @@ -13070,10 +11383,9 @@ cluster_semantic_activation_ack_wire_decode( if (bytes == NULL || message == NULL) return false; - if (semantic_activation_read_u32_le(bytes) - != CLUSTER_SEMANTIC_ACTIVATION_ACK_WIRE_MAGIC + if (semantic_activation_read_u32_le(bytes) != CLUSTER_SEMANTIC_ACTIVATION_ACK_WIRE_MAGIC || semantic_activation_read_u16_le(bytes + 4) - != CLUSTER_SEMANTIC_ACTIVATION_ACK_WIRE_VERSION + != CLUSTER_SEMANTIC_ACTIVATION_ACK_WIRE_VERSION || !semantic_activation_bytes_are_zero(bytes + 116, 4)) return false; @@ -13217,23 +11529,18 @@ semantic_activation_lmon_consume_phase3(void) /* The GES ingress already checked these fields. Formation LMON * rechecks them after the process-local handoff so a reconnect or * formation change between producer and consumer is zero-mutation. */ - if (message->phase - != CLUSTER_REPLACEMENT_WIRE_PHASE_TARGET_RECOVERY_READY + if (message->phase != CLUSTER_REPLACEMENT_WIRE_PHASE_TARGET_RECOVERY_READY || message->target_node_id != item.authenticated_source_node_id || item.local_receiver_node_id != cluster_node_id - || item.control_connection_generation == 0 - || message->epoch == UINT64_MAX - || message->epoch + 1 != current_epoch - || message->body.phase3.jcmk_generation == 0 + || item.control_connection_generation == 0 || message->epoch == UINT64_MAX + || message->epoch + 1 != current_epoch || message->body.phase3.jcmk_generation == 0 || message->body.phase3.episode_state_generation == 0 || message->body.phase3.reserved != 0 - || message->grammar_fingerprint - != CANDIDATE2_CORRECTED_A1_GRAMMAR_FINGERPRINT) + || message->grammar_fingerprint != CANDIDATE2_CORRECTED_A1_GRAMMAR_FINGERPRINT) continue; - if (!cluster_sf_peer_capability_generation_matches( - item.authenticated_source_node_id, - CLUSTER_REPLACEMENT_PHASE3_REQUIRED_CAPS, - item.control_connection_generation)) + if (!cluster_sf_peer_capability_generation_matches(item.authenticated_source_node_id, + CLUSTER_REPLACEMENT_PHASE3_REQUIRED_CAPS, + item.control_connection_generation)) continue; (void)cluster_reconfig_lmon_observe_replacement_ready(&item); } @@ -13393,61 +11700,49 @@ semantic_activation_lmon_consume_utility(void) memset(&refusal, 0, sizeof(refusal)); if (request.action != CLUSTER_SEMANTIC_ENABLE_ALL || !semantic_activation_round_descriptor( - request.source_feature_bitmap, - request.target_feature_bitmap, - request.rollback_feature_bitmap, &round_descriptor, - &required_caps)) { - semantic_activation_set_refusal( - &refusal, CLUSTER_SEMANTIC_ACTIVATION_BAD_STATE, 0, - request.expected_record_generation); + request.source_feature_bitmap, request.target_feature_bitmap, + request.rollback_feature_bitmap, &round_descriptor, &required_caps)) { + semantic_activation_set_refusal(&refusal, CLUSTER_SEMANTIC_ACTIVATION_BAD_STATE, 0, + request.expected_record_generation); } else { if (semantic_activation_lmon_prepare_cas_seq != 0) { if (semantic_activation_ack_lmon_install_prepare(&request)) return; if (semantic_activation_lmon_utility_round_retained()) return; - semantic_activation_set_refusal( - &refusal, CLUSTER_SEMANTIC_ACTIVATION_QUORUM_HOLD, - CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, - request.expected_record_generation); + semantic_activation_set_refusal(&refusal, CLUSTER_SEMANTIC_ACTIVATION_QUORUM_HOLD, + CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, + request.expected_record_generation); goto complete; } if (round_descriptor != &r4_descriptor) { SemanticActivationAdmissionSnapshot snapshot; uint32 local_capability_word; - result = round_descriptor->pre_prepare_readiness( - request.expected_record_generation, &refusal); + result = round_descriptor->pre_prepare_readiness(request.expected_record_generation, + &refusal); local_capability_word = cluster_ic_local_capability_word(); if (result == CLUSTER_SEMANTIC_ACTIVATION_OK && (local_capability_word & required_caps) == required_caps - && semantic_activation_snapshot(&snapshot) - && semantic_activation_ack_lmon_begin_sample_round( - &request, &snapshot)) { - (void) semantic_activation_ack_lmon_submit_prepare( - &request, &snapshot); + && semantic_activation_snapshot(&snapshot) + && semantic_activation_ack_lmon_begin_sample_round(&request, &snapshot)) { + (void)semantic_activation_ack_lmon_submit_prepare(&request, &snapshot); return; } if (result == CLUSTER_SEMANTIC_ACTIVATION_OK) - semantic_activation_set_refusal( - &refusal, - CLUSTER_SEMANTIC_ACTIVATION_QUORUM_HOLD, - round_descriptor->feature_bit, - request.expected_record_generation); + semantic_activation_set_refusal(&refusal, CLUSTER_SEMANTIC_ACTIVATION_QUORUM_HOLD, + round_descriptor->feature_bit, + request.expected_record_generation); goto complete; } - result = semantic_activation_preflight( - request.action, request.expected_record_generation, &refusal, - &effects); - if (semantic_activation_preopen_pgrd_setup_allowed( - request.action, result)) { + result = semantic_activation_preflight(request.action, request.expected_record_generation, + &refusal, &effects); + if (semantic_activation_preopen_pgrd_setup_allowed(request.action, result)) { ClusterSemanticFormationBinding formation = { .utility_request_seq = request.request_seq, .formation_epoch = cluster_epoch_get_current(), - .coordinator_incarnation - = cluster_qvotec_get_self_incarnation(), - .expected_record_generation - = request.expected_record_generation, + .coordinator_incarnation = cluster_qvotec_get_self_incarnation(), + .expected_record_generation = request.expected_record_generation, }; ClusterUndoRootDescriptorReadCompletion pgrd_read_completion; ClusterSemanticActivationResult pgrd_result; @@ -13458,44 +11753,36 @@ semantic_activation_lmon_consume_utility(void) bool have_root_directory; if (semantic_activation_lmon_pgrd_request_seq != 0) { - if (semantic_activation_lmon_pgrd_utility_request_seq - != request.request_seq) { + if (semantic_activation_lmon_pgrd_utility_request_seq != request.request_seq) { semantic_activation_set_refusal( &refusal, CLUSTER_SEMANTIC_ACTIVATION_QUORUM_HOLD, - CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, - request.expected_record_generation); - } else if (!cluster_semantic_activation_undo_root_descriptor_mailbox_poll_completion( - semantic_activation_lmon_pgrd_request_seq, - &pgrd_result)) { + CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, request.expected_record_generation); + } else if ( + !cluster_semantic_activation_undo_root_descriptor_mailbox_poll_completion( + semantic_activation_lmon_pgrd_request_seq, &pgrd_result)) { return; } else { - uint64 completed_request_seq - = semantic_activation_lmon_pgrd_request_seq; + uint64 completed_request_seq = semantic_activation_lmon_pgrd_request_seq; bool proof_valid = false; semantic_activation_lmon_pgrd_request_seq = 0; semantic_activation_lmon_pgrd_utility_request_seq = 0; have_root_directory - = semantic_activation_lmon_shared_pgrd_root_directory( - root_directory); + = semantic_activation_lmon_shared_pgrd_root_directory(root_directory); if (pgrd_result == CLUSTER_SEMANTIC_ACTIVATION_OK && semantic_activation_lmon_pgrd_candidate_request_seq == completed_request_seq && cluster_semantic_activation_qvotec_pgrd_formation_matches( &semantic_activation_lmon_pgrd_formation) && have_root_directory) { - mirror_state - = cluster_undo_smgr_root_descriptor_read_candidate( - root_directory, candidate); - proof_valid - = mirror_state - == CLUSTER_UNDO_SMGR_ROOT_MIRROR_EXACT - && memcmp(candidate, - semantic_activation_lmon_pgrd_candidate, - CLUSTER_UNDO_ROOT_DESCRIPTOR_BYTES) - == 0 - && semantic_activation_pgrd_snapshot_publish( - semantic_activation_lmon_pgrd_candidate); + mirror_state = cluster_undo_smgr_root_descriptor_read_candidate( + root_directory, candidate); + proof_valid = mirror_state == CLUSTER_UNDO_SMGR_ROOT_MIRROR_EXACT + && memcmp(candidate, semantic_activation_lmon_pgrd_candidate, + CLUSTER_UNDO_ROOT_DESCRIPTOR_BYTES) + == 0 + && semantic_activation_pgrd_snapshot_publish( + semantic_activation_lmon_pgrd_candidate); } semantic_activation_lmon_pgrd_candidate_request_seq = 0; memset(semantic_activation_lmon_pgrd_candidate, 0, @@ -13503,28 +11790,24 @@ semantic_activation_lmon_consume_utility(void) if (!proof_valid) { semantic_activation_pgrd_snapshot_clear(); if (pgrd_result != CLUSTER_SEMANTIC_ACTIVATION_OK) - semantic_activation_set_refusal( - &refusal, pgrd_result, - CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, - request.expected_record_generation); + semantic_activation_set_refusal(&refusal, pgrd_result, + CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, + request.expected_record_generation); else - semantic_activation_set_refusal( - &refusal, - CLUSTER_SEMANTIC_ACTIVATION_QUORUM_HOLD, - CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, - request.expected_record_generation); + semantic_activation_set_refusal(&refusal, + CLUSTER_SEMANTIC_ACTIVATION_QUORUM_HOLD, + CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, + request.expected_record_generation); } } } else if (semantic_activation_lmon_pgrd_read_request_seq != 0) { - if (semantic_activation_lmon_pgrd_read_utility_request_seq - != request.request_seq) { + if (semantic_activation_lmon_pgrd_read_utility_request_seq != request.request_seq) { semantic_activation_set_refusal( &refusal, CLUSTER_SEMANTIC_ACTIVATION_QUORUM_HOLD, - CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, - request.expected_record_generation); + CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, request.expected_record_generation); } else if (!semantic_activation_undo_root_descriptor_read_mailbox_poll_completion( - semantic_activation_lmon_pgrd_read_request_seq, - &pgrd_read_completion)) { + semantic_activation_lmon_pgrd_read_request_seq, + &pgrd_read_completion)) { return; } else { semantic_activation_lmon_pgrd_read_request_seq = 0; @@ -13532,63 +11815,49 @@ semantic_activation_lmon_consume_utility(void) semantic_activation_lmon_pgrd_formation = semantic_activation_lmon_pgrd_read_formation; have_root_directory - = semantic_activation_lmon_shared_pgrd_root_directory( - root_directory); + = semantic_activation_lmon_shared_pgrd_root_directory(root_directory); if (!cluster_semantic_activation_qvotec_pgrd_formation_matches( &semantic_activation_lmon_pgrd_read_formation) - || pgrd_read_completion.state - != CLUSTER_UNDO_ROOT_DESCRIPTOR_UNPROVISIONED + || pgrd_read_completion.state != CLUSTER_UNDO_ROOT_DESCRIPTOR_UNPROVISIONED || !have_root_directory || !semantic_activation_lmon_publish_fresh_shared_pgrd( - root_directory, - &semantic_activation_lmon_pgrd_formation, - system_identifier, - &semantic_activation_lmon_pgrd_request_seq)) { + root_directory, &semantic_activation_lmon_pgrd_formation, + system_identifier, &semantic_activation_lmon_pgrd_request_seq)) { semantic_activation_pgrd_snapshot_clear(); - semantic_activation_set_refusal( - &refusal, - CLUSTER_SEMANTIC_ACTIVATION_QUORUM_HOLD, - CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, - request.expected_record_generation); + semantic_activation_set_refusal(&refusal, + CLUSTER_SEMANTIC_ACTIVATION_QUORUM_HOLD, + CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, + request.expected_record_generation); } else { - semantic_activation_lmon_pgrd_utility_request_seq - = request.request_seq; + semantic_activation_lmon_pgrd_utility_request_seq = request.request_seq; return; } } } else { have_root_directory - = semantic_activation_lmon_shared_pgrd_root_directory( - root_directory); + = semantic_activation_lmon_shared_pgrd_root_directory(root_directory); if (have_root_directory - && !cluster_semantic_activation_qvotec_pgrd_formation_matches( - &formation)) { + && !cluster_semantic_activation_qvotec_pgrd_formation_matches(&formation)) { semantic_activation_set_refusal( &refusal, CLUSTER_SEMANTIC_ACTIVATION_QUORUM_HOLD, - CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, - request.expected_record_generation); + CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, request.expected_record_generation); } else if (have_root_directory) { - mirror_state - = cluster_undo_smgr_root_descriptor_read_candidate( - root_directory, candidate); + mirror_state = cluster_undo_smgr_root_descriptor_read_candidate(root_directory, + candidate); if (mirror_state != CLUSTER_UNDO_SMGR_ROOT_MIRROR_EXACT) semantic_activation_pgrd_snapshot_clear(); semantic_activation_lmon_pgrd_formation = formation; if (mirror_state == CLUSTER_UNDO_SMGR_ROOT_MIRROR_EXACT && semantic_activation_lmon_submit_pgrd_candidate( - candidate, - &semantic_activation_lmon_pgrd_formation, - system_identifier, + candidate, &semantic_activation_lmon_pgrd_formation, system_identifier, &semantic_activation_lmon_pgrd_request_seq)) { - semantic_activation_lmon_pgrd_utility_request_seq - = request.request_seq; + semantic_activation_lmon_pgrd_utility_request_seq = request.request_seq; return; } semantic_activation_lmon_pgrd_read_formation = formation; if (mirror_state == CLUSTER_UNDO_SMGR_ROOT_MIRROR_ABSENT && semantic_activation_undo_root_descriptor_read_mailbox_submit( - &semantic_activation_lmon_pgrd_read_formation, - system_identifier, + &semantic_activation_lmon_pgrd_read_formation, system_identifier, &semantic_activation_lmon_pgrd_read_request_seq)) { semantic_activation_lmon_pgrd_read_utility_request_seq = request.request_seq; @@ -13596,8 +11865,7 @@ semantic_activation_lmon_consume_utility(void) } semantic_activation_set_refusal( &refusal, CLUSTER_SEMANTIC_ACTIVATION_QUORUM_HOLD, - CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, - request.expected_record_generation); + CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, request.expected_record_generation); } } @@ -13606,39 +11874,31 @@ semantic_activation_lmon_consume_utility(void) * remains nonterminal until that state is installed. */ if (refusal.result == CLUSTER_SEMANTIC_ACTIVATION_OK) { SemanticActivationAdmissionSnapshot snapshot; - uint32 local_capability_word - = cluster_ic_local_capability_word(); + uint32 local_capability_word = cluster_ic_local_capability_word(); - if ((local_capability_word & required_caps) - == required_caps) { + if ((local_capability_word & required_caps) == required_caps) { if (semantic_activation_snapshot(&snapshot) - && semantic_activation_ack_lmon_begin_sample_round( - &request, &snapshot)) { - (void)semantic_activation_ack_lmon_submit_prepare( - &request, &snapshot); + && semantic_activation_ack_lmon_begin_sample_round(&request, &snapshot)) { + (void)semantic_activation_ack_lmon_submit_prepare(&request, &snapshot); return; } semantic_activation_set_refusal( - &refusal, - CLUSTER_SEMANTIC_ACTIVATION_QUORUM_HOLD, - round_descriptor->feature_bit, - request.expected_record_generation); + &refusal, CLUSTER_SEMANTIC_ACTIVATION_QUORUM_HOLD, + round_descriptor->feature_bit, request.expected_record_generation); } } if (refusal.result == CLUSTER_SEMANTIC_ACTIVATION_OK) { result = CLUSTER_SEMANTIC_ACTIVATION_RF_DEFERRED; - semantic_activation_set_refusal( - &refusal, result, - CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, - request.expected_record_generation); + semantic_activation_set_refusal(&refusal, result, + CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, + request.expected_record_generation); } } } complete: (void)semantic_activation_utility_mailbox_complete( - request.request_seq, refusal.result, refusal.feature_bit, - refusal.expected_generation); + request.request_seq, refusal.result, refusal.feature_bit, refusal.expected_generation); } static bool @@ -13705,16 +11965,13 @@ semantic_activation_lmon_sync_durable_record(const SemanticActivationAdmissionSn || membership_epoch != current_epoch || cluster_epoch_get_current() != current_epoch || cluster_node_id < 0 || cluster_node_id >= CLUSTER_MAX_NODES) return; - local_is_member - = cluster_node_id < 64 - ? (members_lo & (UINT64_C(1) << cluster_node_id)) != 0 - : (members_hi - & (UINT64_C(1) << (cluster_node_id - 64))) != 0; + local_is_member = cluster_node_id < 64 + ? (members_lo & (UINT64_C(1) << cluster_node_id)) != 0 + : (members_hi & (UINT64_C(1) << (cluster_node_id - 64))) != 0; if (!local_is_member) return; - (void)semantic_activation_lmon_publish_gate( - snapshot, 0, 0, current_epoch, false); + (void)semantic_activation_lmon_publish_gate(snapshot, 0, 0, current_epoch, false); } void @@ -14844,7 +13101,7 @@ cluster_semantic_activation_lmon_tick(void) * recovery-only OPEN_APPLIED bootstrap from the durable OPEN and arm * OPEN_PROOF before any gate/advance consumes the table. Fail-closed * and idempotent; the tick retries until every precondition holds. */ - (void) cluster_semantic_activation_restore_open_proof_if_active(); + (void)cluster_semantic_activation_restore_open_proof_if_active(); semantic_activation_lmon_consume_phase3(); if (semantic_activation_ack_lmon_progress_member_barrier()) return; @@ -14863,22 +13120,19 @@ cluster_semantic_activation_lmon_tick(void) current_epoch = cluster_epoch_get_current(); if (snapshot.formation_epoch == current_epoch) { - if (snapshot.transition_closed - && semantic_activation_lmon_prepare_cas_seq == 0) - semantic_activation_lmon_sync_durable_record( - &snapshot, current_epoch); + if (snapshot.transition_closed && semantic_activation_lmon_prepare_cas_seq == 0) + semantic_activation_lmon_sync_durable_record(&snapshot, current_epoch); return; } if (snapshot.seq > UINT64_MAX - 2) ereport(PANIC, (errcode(ERRCODE_INTERNAL_ERROR), - errmsg("semantic activation admission sequence exhausted"), - errhint("Retain the shared-memory image and restart the cluster."))); + errmsg("semantic activation admission sequence exhausted"), + errhint("Retain the shared-memory image and restart the cluster."))); semantic_activation_lmon_member_pgrd_read_request_seq = 0; semantic_activation_pgrd_snapshot_clear(); - (void)semantic_activation_lmon_publish_gate( - &snapshot, snapshot.active_bits, snapshot.record_generation, - current_epoch, true); + (void)semantic_activation_lmon_publish_gate(&snapshot, snapshot.active_bits, + snapshot.record_generation, current_epoch, true); } ClusterSemanticActivationResult @@ -14896,17 +13150,14 @@ cluster_semantic_activation_submit(ClusterSemanticActivationAction action, uint32 effects; if (!semantic_activation_snapshot(&snapshot)) { - semantic_activation_set_refusal( - refusal, CLUSTER_SEMANTIC_ACTIVATION_BAD_STATE, 0, 0); + semantic_activation_set_refusal(refusal, CLUSTER_SEMANTIC_ACTIVATION_BAD_STATE, 0, 0); return CLUSTER_SEMANTIC_ACTIVATION_BAD_STATE; } compiled_bits = cluster_semantic_activation_compiled_feature_bitmap(); - if (action != CLUSTER_SEMANTIC_ENABLE_ALL - || (snapshot.active_bits & ~compiled_bits) != 0) { - semantic_activation_set_refusal( - refusal, CLUSTER_SEMANTIC_ACTIVATION_BAD_STATE, 0, - snapshot.record_generation); + if (action != CLUSTER_SEMANTIC_ENABLE_ALL || (snapshot.active_bits & ~compiled_bits) != 0) { + semantic_activation_set_refusal(refusal, CLUSTER_SEMANTIC_ACTIVATION_BAD_STATE, 0, + snapshot.record_generation); return CLUSTER_SEMANTIC_ACTIVATION_BAD_STATE; } @@ -14915,46 +13166,37 @@ cluster_semantic_activation_submit(ClusterSemanticActivationAction action, else { remaining_bits = compiled_bits & ~snapshot.active_bits; if (snapshot.transition_closed - || (snapshot.active_bits - & CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1) == 0 - || remaining_bits == 0 - || (remaining_bits & (remaining_bits - 1)) != 0) { - semantic_activation_set_refusal( - refusal, CLUSTER_SEMANTIC_ACTIVATION_BAD_STATE, 0, - snapshot.record_generation); + || (snapshot.active_bits & CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1) == 0 + || remaining_bits == 0 || (remaining_bits & (remaining_bits - 1)) != 0) { + semantic_activation_set_refusal(refusal, CLUSTER_SEMANTIC_ACTIVATION_BAD_STATE, 0, + snapshot.record_generation); return CLUSTER_SEMANTIC_ACTIVATION_BAD_STATE; } target_bits = snapshot.active_bits | remaining_bits; } - if (!semantic_activation_round_descriptor( - snapshot.active_bits, target_bits, 0, &round_descriptor, - &required_caps)) { - semantic_activation_set_refusal( - refusal, CLUSTER_SEMANTIC_ACTIVATION_BAD_STATE, 0, - snapshot.record_generation); + if (!semantic_activation_round_descriptor(snapshot.active_bits, target_bits, 0, + &round_descriptor, &required_caps)) { + semantic_activation_set_refusal(refusal, CLUSTER_SEMANTIC_ACTIVATION_BAD_STATE, 0, + snapshot.record_generation); return CLUSTER_SEMANTIC_ACTIVATION_BAD_STATE; } if (round_descriptor == &r4_descriptor) { - result = semantic_activation_preflight( - action, snapshot.record_generation, refusal, &effects); + result + = semantic_activation_preflight(action, snapshot.record_generation, refusal, &effects); if (!semantic_activation_preopen_pgrd_setup_allowed(action, result)) return result; } else { - result = round_descriptor->pre_prepare_readiness( - snapshot.record_generation, refusal); + result = round_descriptor->pre_prepare_readiness(snapshot.record_generation, refusal); if (result != CLUSTER_SEMANTIC_ACTIVATION_OK) return result; } - if (!semantic_activation_utility_mailbox_submit( - action, snapshot.active_bits, - target_bits, 0, - snapshot.record_generation, &request_seq)) { - semantic_activation_set_refusal( - refusal, CLUSTER_SEMANTIC_ACTIVATION_QUORUM_HOLD, 0, - snapshot.record_generation); + if (!semantic_activation_utility_mailbox_submit(action, snapshot.active_bits, target_bits, 0, + snapshot.record_generation, &request_seq)) { + semantic_activation_set_refusal(refusal, CLUSTER_SEMANTIC_ACTIVATION_QUORUM_HOLD, 0, + snapshot.record_generation); return CLUSTER_SEMANTIC_ACTIVATION_QUORUM_HOLD; } @@ -15003,8 +13245,7 @@ cutover_round_capability_digest(uint64 members_lo) digest ^= (uint64)node * UINT64_C(0x100000001b3); digest ^= cluster_membership_get_last_admitted_incarnation(node); if (cluster_sf_peer_capability_word_sample( - node, CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS, - &word, &gen)) + node, CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS, &word, &gen)) digest ^= (uint64)word ^ ((uint64)gen << 32); } return digest; @@ -15029,14 +13270,13 @@ pgrac_r4_bit22_cutover_begin(PG_FUNCTION_ARGS) int32 current_coordinator_node; if (!superuser()) - ereport(ERROR, - (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), - errmsg("permission denied for pgrac_r4_bit22_cutover_begin"), - errhint("Only the cluster superuser may drive the bit22 cutover."))); + ereport(ERROR, (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), + errmsg("permission denied for pgrac_r4_bit22_cutover_begin"), + errhint("Only the cluster superuser may drive the bit22 cutover."))); if (!semantic_activation_snapshot(&snapshot) - || !semantic_activation_ack_current_authority( - cluster_node_id, ¤t_members_lo, ¤t_members_hi, - ¤t_epoch, ¤t_coordinator_node) + || !semantic_activation_ack_current_authority(cluster_node_id, ¤t_members_lo, + ¤t_members_hi, ¤t_epoch, + ¤t_coordinator_node) || cluster_node_id != current_coordinator_node) PG_RETURN_BOOL(false); @@ -15050,12 +13290,11 @@ pgrac_r4_bit22_cutover_begin(PG_FUNCTION_ARGS) round.prepare_generation = snapshot.record_generation + 1; round.transition_epoch = current_epoch; round.source_feature_bitmap = snapshot.active_bits; - round.target_feature_bitmap = snapshot.active_bits - | PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1; + round.target_feature_bitmap + = snapshot.active_bits | PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1; round.admitted_bitmap_low = current_members_lo; round.admitted_bitmap_high = current_members_hi; - round.capability_sample_digest - = cutover_round_capability_digest(current_members_lo); + round.capability_sample_digest = cutover_round_capability_digest(current_members_lo); round.coordinator_incarnation = cluster_qvotec_get_self_incarnation(); round.coordinator_node_id = cluster_node_id; diff --git a/src/backend/cluster/cluster_sf_dep.c b/src/backend/cluster/cluster_sf_dep.c index c28cd7caae1..e63f08a3501 100644 --- a/src/backend/cluster/cluster_sf_dep.c +++ b/src/backend/cluster/cluster_sf_dep.c @@ -498,8 +498,8 @@ cluster_sf_peer_pcm_x_source_floor_sample(int32 peer_id, bool *source_floor_out, /* Generic, record-coherent required/optional capability sample. */ bool cluster_sf_peer_capability_family_sample(int32 peer_id, uint32 required_capabilities, - uint32 optional_capabilities, - bool *optional_supported_out, uint32 *generation_out) + uint32 optional_capabilities, bool *optional_supported_out, + uint32 *generation_out) { bool supported; @@ -511,9 +511,9 @@ cluster_sf_peer_capability_family_sample(int32 peer_id, uint32 required_capabili return false; LWLockAcquire(&ClusterSfDep->lock, LW_SHARED); - supported = cluster_sf_peer_cap_family_sample( - &ClusterSfDep->peer_capabilities[peer_id], required_capabilities, optional_capabilities, - optional_supported_out, generation_out); + supported = cluster_sf_peer_cap_family_sample(&ClusterSfDep->peer_capabilities[peer_id], + required_capabilities, optional_capabilities, + optional_supported_out, generation_out); LWLockRelease(&ClusterSfDep->lock); return supported; } @@ -552,8 +552,7 @@ cluster_sf_peer_capability_word_sample(int32 peer_id, uint32 required_capabiliti LWLockAcquire(&ClusterSfDep->lock, LW_SHARED); cap = &ClusterSfDep->peer_capabilities[peer_id]; - if (cap->valid - && (cap->bits & required_capabilities) == required_capabilities) { + if (cap->valid && (cap->bits & required_capabilities) == required_capabilities) { capability_word = cap->bits; generation = cap->generation; supported = true; @@ -572,8 +571,7 @@ cluster_sf_peer_capability_word_sample(int32 peer_id, uint32 required_capabiliti /* Spec-3.6b: sample Current-MX authority and its connection generation from * the same CONTROL-owned HELLO record. */ bool -cluster_sf_peer_multixact_current_capability_generation( - int32 peer_id, uint32 *generation_out) +cluster_sf_peer_multixact_current_capability_generation(int32 peer_id, uint32 *generation_out) { bool supported; @@ -583,9 +581,9 @@ cluster_sf_peer_multixact_current_capability_generation( return false; LWLockAcquire(&ClusterSfDep->lock, LW_SHARED); - supported = cluster_sf_peer_cap_generation_for_bits( - &ClusterSfDep->peer_capabilities[peer_id], - PGRAC_IC_HELLO_CAP_MULTIXACT_CURRENT_V1, generation_out); + supported = cluster_sf_peer_cap_generation_for_bits(&ClusterSfDep->peer_capabilities[peer_id], + PGRAC_IC_HELLO_CAP_MULTIXACT_CURRENT_V1, + generation_out); LWLockRelease(&ClusterSfDep->lock); return supported; } diff --git a/src/backend/cluster/cluster_shmem.c b/src/backend/cluster/cluster_shmem.c index 3fc815a9d0f..3ac0773a9c5 100644 --- a/src/backend/cluster/cluster_shmem.c +++ b/src/backend/cluster/cluster_shmem.c @@ -93,7 +93,7 @@ #include "cluster/cluster_ges_dedup.h" /* cluster_ges_dedup_shmem_register (spec-2.27 D2) */ #include "cluster/cluster_wal_thread.h" /* cluster_wal_thread_shmem_register (spec-4.1 D7) */ #include "cluster/cluster_recovery_plan.h" /* cluster_recovery_plan_shmem_register (spec-4.3 D4) */ -#include "cluster/cluster_page_guard.h" /* STOP-06 no-wait PAGE protection */ +#include "cluster/cluster_page_guard.h" /* STOP-06 no-wait PAGE protection */ #include "cluster/cluster_block_recovery.h" /* cluster_block_recovery_shmem_register (spec-4.10 D6) */ #include "cluster/cluster_grd_outbound.h" /* cluster_grd_outbound_shmem_register (spec-2.16 D4) */ #include "cluster/cluster_grd_work_queue.h" /* cluster_grd_work_queue_shmem_register (spec-2.16 D5) */ @@ -111,8 +111,8 @@ #include "cluster/cluster_tx_enqueue.h" /* cluster_tx_enqueue_shmem_register (spec-5.2 D4/D6) */ #include "cluster/cluster_multixact_current_stats.h" #include "cluster/cluster_terminal_ref_census.h" -#include "cluster/cluster_subtrans.h" /* cluster_subtrans_shmem_register (spec-3.5 D5) */ -#include "cluster/cluster_multixact.h" /* cluster_multixact_shmem_register (spec-3.6 D2) */ +#include "cluster/cluster_subtrans.h" /* cluster_subtrans_shmem_register (spec-3.5 D5) */ +#include "cluster/cluster_multixact.h" /* cluster_multixact_shmem_register (spec-3.6 D2) */ #include "cluster/cluster_undo_record_api.h" /* cluster_undo_record_shmem_register (spec-3.7 D5) */ #include "cluster/cluster_cr.h" /* cluster_cr_shmem_register (spec-3.9 D2) */ #include "cluster/cluster_cr_pool.h" /* cluster_cr_pool_shmem_register (spec-5.51 D1) */ @@ -514,8 +514,7 @@ cluster_init_shmem_module(void) cluster_multixact_current_stats_shmem_register(); /* Spec-8.4D: activation-sized CTRC keys, receipts and ACK summaries. */ - if (cluster_shmem_lookup_region( - "pgrac cluster terminal reference census") == NULL) + if (cluster_shmem_lookup_region("pgrac cluster terminal reference census") == NULL) cluster_ctrc_shmem_register(); /* diff --git a/src/backend/cluster/cluster_side_online_owner.c b/src/backend/cluster/cluster_side_online_owner.c index 89b40f9aa6c..715e1336c8d 100644 --- a/src/backend/cluster/cluster_side_online_owner.c +++ b/src/backend/cluster/cluster_side_online_owner.c @@ -13,18 +13,16 @@ static bool side_owner_authority_fresh(RfSideOnlineProductionOwnerV1 *owner) { - return owner != NULL && owner->revalidate_authority != NULL && - owner->revalidate_authority(owner->authority_arg); + return owner != NULL && owner->revalidate_authority != NULL + && owner->revalidate_authority(owner->authority_arg); } static bool side_owner_begin_protected_set(void *arg) { - RfSideOnlineProductionOwnerV1 *owner = - (RfSideOnlineProductionOwnerV1 *) arg; + RfSideOnlineProductionOwnerV1 *owner = (RfSideOnlineProductionOwnerV1 *)arg; - if (owner == NULL || owner->protected_set_active || - !side_owner_authority_fresh(owner)) + if (owner == NULL || owner->protected_set_active || !side_owner_authority_fresh(owner)) return false; cluster_remote_xact_online_writer_push(); owner->protected_set_active = true; @@ -35,122 +33,97 @@ side_owner_begin_protected_set(void *arg) static void side_owner_end_protected_set(void *arg, bool complete) { - RfSideOnlineProductionOwnerV1 *owner = - (RfSideOnlineProductionOwnerV1 *) arg; + RfSideOnlineProductionOwnerV1 *owner = (RfSideOnlineProductionOwnerV1 *)arg; if (owner == NULL || !owner->protected_set_active) return; - owner->protected_set_complete = complete && - side_owner_authority_fresh(owner); + owner->protected_set_complete = complete && side_owner_authority_fresh(owner); owner->protected_set_active = false; cluster_remote_xact_online_writer_pop(); } static bool -side_owner_preflight_xact(void *arg, - const RfSideOnlineOperationV1 *operation) +side_owner_preflight_xact(void *arg, const RfSideOnlineOperationV1 *operation) { - RfSideOnlineProductionOwnerV1 *owner = - (RfSideOnlineProductionOwnerV1 *) arg; - - return owner != NULL && owner->protected_set_active && - side_owner_authority_fresh(owner) && operation != NULL && - operation->kind == RF_SIDE_ONLINE_OPERATION_XACT && - rf_side_xact_target_preflight_owned_v1(&operation->xact, - operation->owned_payload, operation->owned_payload_length) == - RF_SIDE_XACT_APPLY_OK; + RfSideOnlineProductionOwnerV1 *owner = (RfSideOnlineProductionOwnerV1 *)arg; + + return owner != NULL && owner->protected_set_active && side_owner_authority_fresh(owner) + && operation != NULL && operation->kind == RF_SIDE_ONLINE_OPERATION_XACT + && rf_side_xact_target_preflight_owned_v1(&operation->xact, operation->owned_payload, + operation->owned_payload_length) + == RF_SIDE_XACT_APPLY_OK; } static bool -side_owner_preflight_undo(void *arg, - const RfSideOnlineOperationV1 *operation) +side_owner_preflight_undo(void *arg, const RfSideOnlineOperationV1 *operation) { - RfSideOnlineProductionOwnerV1 *owner = - (RfSideOnlineProductionOwnerV1 *) arg; + RfSideOnlineProductionOwnerV1 *owner = (RfSideOnlineProductionOwnerV1 *)arg; ClusterUndoTargetPreflightV1 target; - if (owner == NULL || !owner->protected_set_active || - !side_owner_authority_fresh(owner) || operation == NULL || - operation->kind != RF_SIDE_ONLINE_OPERATION_UNDO) + if (owner == NULL || !owner->protected_set_active || !side_owner_authority_fresh(owner) + || operation == NULL || operation->kind != RF_SIDE_ONLINE_OPERATION_UNDO) return false; target = cluster_undo_preflight_tt_target_v1(&operation->undo); - return target == CLUSTER_UNDO_TARGET_APPLY || - target == CLUSTER_UNDO_TARGET_PROVED_NOOP; + return target == CLUSTER_UNDO_TARGET_APPLY || target == CLUSTER_UNDO_TARGET_PROVED_NOOP; } static bool -side_owner_preflight_projection(void *arg, - const RfSideOnlineOperationV1 *operation) +side_owner_preflight_projection(void *arg, const RfSideOnlineOperationV1 *operation) { - RfSideOnlineProductionOwnerV1 *owner = - (RfSideOnlineProductionOwnerV1 *) arg; + RfSideOnlineProductionOwnerV1 *owner = (RfSideOnlineProductionOwnerV1 *)arg; - return owner != NULL && owner->protected_set_active && - side_owner_authority_fresh(owner) && - rf_side_online_projection_preflight_owned_v1(&owner->projection, - operation); + return owner != NULL && owner->protected_set_active && side_owner_authority_fresh(owner) + && rf_side_online_projection_preflight_owned_v1(&owner->projection, operation); } static bool -side_owner_apply_xact(void *arg, - const RfSideOnlineOperationV1 *operation) +side_owner_apply_xact(void *arg, const RfSideOnlineOperationV1 *operation) { - RfSideOnlineProductionOwnerV1 *owner = - (RfSideOnlineProductionOwnerV1 *) arg; - - return owner != NULL && owner->protected_set_active && - side_owner_authority_fresh(owner) && operation != NULL && - operation->kind == RF_SIDE_ONLINE_OPERATION_XACT && - rf_side_xact_apply_owned_v1(&operation->xact, - operation->owned_payload, operation->owned_payload_length) == - RF_SIDE_XACT_APPLY_OK; + RfSideOnlineProductionOwnerV1 *owner = (RfSideOnlineProductionOwnerV1 *)arg; + + return owner != NULL && owner->protected_set_active && side_owner_authority_fresh(owner) + && operation != NULL && operation->kind == RF_SIDE_ONLINE_OPERATION_XACT + && rf_side_xact_apply_owned_v1(&operation->xact, operation->owned_payload, + operation->owned_payload_length) + == RF_SIDE_XACT_APPLY_OK; } static bool -side_owner_apply_undo(void *arg, - const RfSideOnlineOperationV1 *operation) +side_owner_apply_undo(void *arg, const RfSideOnlineOperationV1 *operation) { - RfSideOnlineProductionOwnerV1 *owner = - (RfSideOnlineProductionOwnerV1 *) arg; - - return owner != NULL && owner->protected_set_active && - side_owner_authority_fresh(owner) && operation != NULL && - operation->kind == RF_SIDE_ONLINE_OPERATION_UNDO && - cluster_undo_apply_tt_v1(&operation->undo) == - CLUSTER_UNDO_APPLY_OK; + RfSideOnlineProductionOwnerV1 *owner = (RfSideOnlineProductionOwnerV1 *)arg; + + return owner != NULL && owner->protected_set_active && side_owner_authority_fresh(owner) + && operation != NULL && operation->kind == RF_SIDE_ONLINE_OPERATION_UNDO + && cluster_undo_apply_tt_v1(&operation->undo) == CLUSTER_UNDO_APPLY_OK; } static bool -side_owner_apply_projection(void *arg, - const RfSideOnlineOperationV1 *operation) +side_owner_apply_projection(void *arg, const RfSideOnlineOperationV1 *operation) { - RfSideOnlineProductionOwnerV1 *owner = - (RfSideOnlineProductionOwnerV1 *) arg; + RfSideOnlineProductionOwnerV1 *owner = (RfSideOnlineProductionOwnerV1 *)arg; - return owner != NULL && owner->protected_set_active && - side_owner_authority_fresh(owner) && - rf_side_online_projection_apply_owned_v1(&owner->projection, - operation); + return owner != NULL && owner->protected_set_active && side_owner_authority_fresh(owner) + && rf_side_online_projection_apply_owned_v1(&owner->projection, operation); } bool -rf_side_online_production_owner_init_v1( - RfSideOnlineProductionOwnerV1 *owner, void *authority_arg, - RfSideOnlineFreshAuthorityV1 revalidate_authority, uint32 cluster_epoch, - bool failed_origin_redo_retained) +rf_side_online_production_owner_init_v1(RfSideOnlineProductionOwnerV1 *owner, void *authority_arg, + RfSideOnlineFreshAuthorityV1 revalidate_authority, + uint32 cluster_epoch, bool failed_origin_redo_retained) { if (owner == NULL || revalidate_authority == NULL || cluster_epoch == 0) return false; memset(owner, 0, sizeof(*owner)); owner->authority_arg = authority_arg; owner->revalidate_authority = revalidate_authority; - return rf_side_online_projection_owner_init_v1(&owner->projection, - cluster_epoch, failed_origin_redo_retained); + return rf_side_online_projection_owner_init_v1(&owner->projection, cluster_epoch, + failed_origin_redo_retained); } RfPageProofDetailV1 rf_side_online_production_preflight_v1(const RfSideOnlinePlanV1 *plan, - RfSideOnlineProductionOwnerV1 *owner) + RfSideOnlineProductionOwnerV1 *owner) { RfSideOnlineApplyOpsV1 ops; @@ -172,7 +145,7 @@ rf_side_online_production_preflight_v1(const RfSideOnlinePlanV1 *plan, RfPageProofDetailV1 rf_side_online_production_apply_v1(const RfSideOnlinePlanV1 *plan, - RfSideOnlineProductionOwnerV1 *owner) + RfSideOnlineProductionOwnerV1 *owner) { RfSideOnlineApplyOpsV1 ops; RfPageProofDetailV1 detail; @@ -193,8 +166,7 @@ rf_side_online_production_apply_v1(const RfSideOnlinePlanV1 *plan, detail = rf_side_online_plan_apply_v1(plan, &ops); if (detail != RF_PAGE_PROOF_DETAIL_OK) return detail; - if (rf_side_online_plan_operation_count_v1(plan) == 0) - { + if (rf_side_online_plan_operation_count_v1(plan) == 0) { /* * A sealed empty SIDE proof set closes without taking the online * writer barrier: there are no SIDE bytes to protect or mutate. It @@ -202,8 +174,8 @@ rf_side_online_production_apply_v1(const RfSideOnlinePlanV1 *plan, */ owner->protected_set_complete = side_owner_authority_fresh(owner); } - return owner->protected_set_complete ? RF_PAGE_PROOF_DETAIL_OK : - RF_PAGE_PROOF_DETAIL_SIDE_INCOMPLETE; + return owner->protected_set_complete ? RF_PAGE_PROOF_DETAIL_OK + : RF_PAGE_PROOF_DETAIL_SIDE_INCOMPLETE; } #endif diff --git a/src/backend/cluster/cluster_side_online_plan.c b/src/backend/cluster/cluster_side_online_plan.c index 52bbf97ab82..4abcd56ab6d 100644 --- a/src/backend/cluster/cluster_side_online_plan.c +++ b/src/backend/cluster/cluster_side_online_plan.c @@ -25,32 +25,31 @@ #define RF_SIDE_ONLINE_PLAN_MAGIC UINT32_C(0x53495031) -struct RfSideOnlinePlanV1 -{ - uint32 magic; - bool sealed; - uint8 reserved5[3]; - uint64 system_identifier; - uint8 storage_uuid[16]; - Size memory_budget; - Size memory_used; - uint32 participant_count; +struct RfSideOnlinePlanV1 { + uint32 magic; + bool sealed; + uint8 reserved5[3]; + uint64 system_identifier; + uint8 storage_uuid[16]; + Size memory_budget; + Size memory_used; + uint32 participant_count; RfContributorStreamCutV1 *physical_cuts; XLogRecPtr *last_record_end; - bool *participant_seen; + bool *participant_seen; RfSideOnlineOperationV1 *operations; - uint32 operation_count; - uint32 operation_capacity; - uint8 *owned_payload; - uint32 owned_payload_bytes; - uint32 owned_payload_capacity; + uint32 operation_count; + uint32 operation_capacity; + uint8 *owned_payload; + uint32 owned_payload_bytes; + uint32 owned_payload_capacity; }; static bool side_bytes_nonzero(const uint8 *bytes, Size length) { - uint8 seen = 0; - Size i; + uint8 seen = 0; + Size i; for (i = 0; i < length; i++) seen |= bytes[i]; @@ -67,47 +66,40 @@ side_plan_reserve(RfSideOnlinePlanV1 *plan, Size bytes) } static RfPageProofDetailV1 -side_record_identity_validate(RfSideOnlinePlanV1 *plan, - const RfDetachedRecordPlanV1 *record_plan, - const RfPageOnlineRecordIdentityV1 *identity) +side_record_identity_validate(RfSideOnlinePlanV1 *plan, const RfDetachedRecordPlanV1 *record_plan, + const RfPageOnlineRecordIdentityV1 *identity) { const RfContributorStreamCutV1 *cut; const RfPageReplayRecordIdentityV1 *record; const XLogReaderState *reader; const DecodedXLogRecord *decoded; - if (record_plan == NULL || !record_plan->preflight_complete || - record_plan->source_record == NULL || - record_plan->source_record->record == NULL || identity == NULL) + if (record_plan == NULL || !record_plan->preflight_complete + || record_plan->source_record == NULL || record_plan->source_record->record == NULL + || identity == NULL) return RF_PAGE_PROOF_DETAIL_SOURCE_GAP; reader = record_plan->source_record; decoded = reader->record; record = &identity->record; - if (identity->reserved_zero != 0 || record->reserved_zero != 0 || - record->reserved_zero2 != 0 || - identity->participant_index >= plan->participant_count || - record->system_identifier != plan->system_identifier || - memcmp(record->storage_uuid, plan->storage_uuid, 16) != 0 || - record->origin_thread == 0 || record->timeline_id == 0 || - record->read_rec_ptr == InvalidXLogRecPtr || - record->end_rec_ptr <= record->read_rec_ptr || - reader->system_identifier != record->system_identifier || - reader->ReadRecPtr != record->read_rec_ptr || - reader->EndRecPtr != record->end_rec_ptr || - decoded->lsn != record->read_rec_ptr || - decoded->next_lsn != record->end_rec_ptr || - (uint32) decoded->header.xl_crc != record->record_crc || - decoded->header.xl_rmid != record->rmid || - decoded->header.xl_info != record->info) + if (identity->reserved_zero != 0 || record->reserved_zero != 0 || record->reserved_zero2 != 0 + || identity->participant_index >= plan->participant_count + || record->system_identifier != plan->system_identifier + || memcmp(record->storage_uuid, plan->storage_uuid, 16) != 0 || record->origin_thread == 0 + || record->timeline_id == 0 || record->read_rec_ptr == InvalidXLogRecPtr + || record->end_rec_ptr <= record->read_rec_ptr + || reader->system_identifier != record->system_identifier + || reader->ReadRecPtr != record->read_rec_ptr || reader->EndRecPtr != record->end_rec_ptr + || decoded->lsn != record->read_rec_ptr || decoded->next_lsn != record->end_rec_ptr + || (uint32)decoded->header.xl_crc != record->record_crc + || decoded->header.xl_rmid != record->rmid || decoded->header.xl_info != record->info) return RF_PAGE_PROOF_DETAIL_IDENTITY_MISMATCH; cut = &plan->physical_cuts[identity->participant_index]; - if (record->origin_thread != cut->failed_thread || - record->timeline_id != cut->timeline_id || - (cut->flags & RF_CONTRIBUTOR_CUT_EXPLICIT_EMPTY) != 0 || - record->read_rec_ptr < cut->scan_begin_inclusive || - record->end_rec_ptr > cut->scan_end_exclusive || - (plan->participant_seen[identity->participant_index] && - record->read_rec_ptr < plan->last_record_end[identity->participant_index])) + if (record->origin_thread != cut->failed_thread || record->timeline_id != cut->timeline_id + || (cut->flags & RF_CONTRIBUTOR_CUT_EXPLICIT_EMPTY) != 0 + || record->read_rec_ptr < cut->scan_begin_inclusive + || record->end_rec_ptr > cut->scan_end_exclusive + || (plan->participant_seen[identity->participant_index] + && record->read_rec_ptr < plan->last_record_end[identity->participant_index])) return RF_PAGE_PROOF_DETAIL_SOURCE_GAP; return RF_PAGE_PROOF_DETAIL_OK; } @@ -116,31 +108,26 @@ static bool side_ensure_operation_capacity(RfSideOnlinePlanV1 *plan) { RfSideOnlineOperationV1 *operations; - uint32 capacity; - Size delta; + uint32 capacity; + Size delta; if (plan->operation_count < plan->operation_capacity) return true; - capacity = plan->operation_capacity == 0 ? 16 : - plan->operation_capacity * 2; + capacity = plan->operation_capacity == 0 ? 16 : plan->operation_capacity * 2; if (capacity < plan->operation_capacity) return false; - delta = (Size) (capacity - plan->operation_capacity) * - sizeof(*operations); + delta = (Size)(capacity - plan->operation_capacity) * sizeof(*operations); if (!side_plan_reserve(plan, delta)) return false; if (plan->operations == NULL) - operations = (RfSideOnlineOperationV1 *) side_alloc0( - (Size) capacity * sizeof(*operations)); - else - { - operations = (RfSideOnlineOperationV1 *) side_realloc(plan->operations, - (Size) capacity * sizeof(*operations)); + operations = (RfSideOnlineOperationV1 *)side_alloc0((Size)capacity * sizeof(*operations)); + else { + operations = (RfSideOnlineOperationV1 *)side_realloc(plan->operations, + (Size)capacity * sizeof(*operations)); if (operations != NULL) memset(operations + plan->operation_capacity, 0, delta); } - if (operations == NULL) - { + if (operations == NULL) { plan->memory_used -= delta; return false; } @@ -152,10 +139,10 @@ side_ensure_operation_capacity(RfSideOnlinePlanV1 *plan) static bool side_ensure_payload_capacity(RfSideOnlinePlanV1 *plan, uint32 additional) { - uint8 *payload; - uint32 needed; - uint32 capacity; - Size delta; + uint8 *payload; + uint32 needed; + uint32 capacity; + Size delta; if (additional == 0) return true; @@ -164,26 +151,22 @@ side_ensure_payload_capacity(RfSideOnlinePlanV1 *plan, uint32 additional) needed = plan->owned_payload_bytes + additional; if (needed <= plan->owned_payload_capacity) return true; - capacity = plan->owned_payload_capacity == 0 ? BLCKSZ : - plan->owned_payload_capacity; - while (capacity < needed) - { - if (capacity > UINT32_MAX / 2) - { + capacity = plan->owned_payload_capacity == 0 ? BLCKSZ : plan->owned_payload_capacity; + while (capacity < needed) { + if (capacity > UINT32_MAX / 2) { capacity = needed; break; } capacity *= 2; } - delta = (Size) capacity - plan->owned_payload_capacity; + delta = (Size)capacity - plan->owned_payload_capacity; if (!side_plan_reserve(plan, delta)) return false; if (plan->owned_payload == NULL) - payload = (uint8 *) side_alloc0(capacity); + payload = (uint8 *)side_alloc0(capacity); else - payload = (uint8 *) side_realloc(plan->owned_payload, capacity); - if (payload == NULL) - { + payload = (uint8 *)side_realloc(plan->owned_payload, capacity); + if (payload == NULL) { plan->memory_used -= delta; return false; } @@ -194,32 +177,29 @@ side_ensure_payload_capacity(RfSideOnlinePlanV1 *plan, uint32 additional) static bool side_projection_decode(const RfDetachedRecordPlanV1 *record_plan, - RfSideOnlineOperationV1 *candidate, uint32 *payload_offset, - uint32 *payload_length) + RfSideOnlineOperationV1 *candidate, uint32 *payload_offset, + uint32 *payload_length) { const XLogReaderState *record = record_plan->source_record; const char *data = XLogRecGetData(record); - uint32 data_length = XLogRecGetDataLen(record); - uint8 info = record_plan->route.normalized_info; + uint32 data_length = XLogRecGetDataLen(record); + uint8 info = record_plan->route.normalized_info; ClusterSideProjectionOperationV1 *projection = &candidate->projection; *payload_offset = 0; *payload_length = 0; projection->normalized_info = info; projection->page_number = -1; - if (record_plan->route.rmid == RM_CLOG_ID) - { + if (record_plan->route.rmid == RM_CLOG_ID) { projection->kind = CLUSTER_SIDE_PROJECTION_CLOG; - if (info == CLOG_ZEROPAGE) - { + if (info == CLOG_ZEROPAGE) { if (data_length != sizeof(int)) return false; memcpy(&projection->page_number, data, sizeof(int)); projection->action = CLUSTER_SIDE_PROJECTION_ACTION_ZERO_PAGE; return projection->page_number >= 0; } - if (info == CLOG_TRUNCATE) - { + if (info == CLOG_TRUNCATE) { xl_clog_truncate trunc; if (data_length != sizeof(trunc)) @@ -229,24 +209,21 @@ side_projection_decode(const RfDetachedRecordPlanV1 *record_plan, projection->page_number = trunc.pageno; projection->oldest_xid = trunc.oldestXact; projection->oldest_database = trunc.oldestXactDb; - return trunc.pageno >= 0 && TransactionIdIsNormal(trunc.oldestXact) && - OidIsValid(trunc.oldestXactDb); + return trunc.pageno >= 0 && TransactionIdIsNormal(trunc.oldestXact) + && OidIsValid(trunc.oldestXactDb); } return false; } - if (record_plan->route.rmid == RM_COMMIT_TS_ID) - { + if (record_plan->route.rmid == RM_COMMIT_TS_ID) { projection->kind = CLUSTER_SIDE_PROJECTION_COMMIT_TS; - if (info == COMMIT_TS_ZEROPAGE) - { + if (info == COMMIT_TS_ZEROPAGE) { if (data_length != sizeof(int)) return false; memcpy(&projection->page_number, data, sizeof(int)); projection->action = CLUSTER_SIDE_PROJECTION_ACTION_ZERO_PAGE; return projection->page_number >= 0; } - if (info == COMMIT_TS_TRUNCATE) - { + if (info == COMMIT_TS_TRUNCATE) { xl_commit_ts_truncate trunc; if (data_length != SizeOfCommitTsTruncate) @@ -260,20 +237,16 @@ side_projection_decode(const RfDetachedRecordPlanV1 *record_plan, } return false; } - if (record_plan->route.rmid == RM_MULTIXACT_ID) - { + if (record_plan->route.rmid == RM_MULTIXACT_ID) { projection->kind = CLUSTER_SIDE_PROJECTION_MULTIXACT; - if (info == XLOG_MULTIXACT_ZERO_OFF_PAGE || - info == XLOG_MULTIXACT_ZERO_MEM_PAGE) - { + if (info == XLOG_MULTIXACT_ZERO_OFF_PAGE || info == XLOG_MULTIXACT_ZERO_MEM_PAGE) { if (data_length != sizeof(int)) return false; memcpy(&projection->page_number, data, sizeof(int)); projection->action = CLUSTER_SIDE_PROJECTION_ACTION_ZERO_PAGE; return projection->page_number >= 0; } - if (info == XLOG_MULTIXACT_CREATE_ID) - { + if (info == XLOG_MULTIXACT_CREATE_ID) { xl_multixact_create header; Size expected; int i; @@ -282,34 +255,30 @@ side_projection_decode(const RfDetachedRecordPlanV1 *record_plan, return false; memset(&header, 0, sizeof(header)); memcpy(&header, data, SizeOfMultiXactCreate); - if (header.nmembers <= 0 || header.nmembers > 256 || - !MultiXactIdIsValid(header.mid) || header.moff == 0) + if (header.nmembers <= 0 || header.nmembers > 256 || !MultiXactIdIsValid(header.mid) + || header.moff == 0) return false; - expected = SizeOfMultiXactCreate + - (Size) header.nmembers * sizeof(MultiXactMember); + expected = SizeOfMultiXactCreate + (Size)header.nmembers * sizeof(MultiXactMember); if (expected != data_length) return false; - for (i = 0; i < header.nmembers; i++) - { + for (i = 0; i < header.nmembers; i++) { MultiXactMember member; - memcpy(&member, data + SizeOfMultiXactCreate + - (Size) i * sizeof(member), sizeof(member)); - if (!TransactionIdIsNormal(member.xid) || - member.status < MultiXactStatusForKeyShare || - member.status > MaxMultiXactStatus) + memcpy(&member, data + SizeOfMultiXactCreate + (Size)i * sizeof(member), + sizeof(member)); + if (!TransactionIdIsNormal(member.xid) || member.status < MultiXactStatusForKeyShare + || member.status > MaxMultiXactStatus) return false; } projection->action = CLUSTER_SIDE_PROJECTION_ACTION_CREATE; projection->multixact_id = header.mid; projection->member_offset = header.moff; - projection->member_count = (uint32) header.nmembers; + projection->member_count = (uint32)header.nmembers; *payload_offset = SizeOfMultiXactCreate; *payload_length = data_length - SizeOfMultiXactCreate; return true; } - if (info == XLOG_MULTIXACT_TRUNCATE_ID) - { + if (info == XLOG_MULTIXACT_TRUNCATE_ID) { xl_multixact_truncate trunc; if (data_length != SizeOfMultiXactTruncate) @@ -321,48 +290,40 @@ side_projection_decode(const RfDetachedRecordPlanV1 *record_plan, projection->truncate_end_multixact = trunc.endTruncOff; projection->truncate_start_member = trunc.startTruncMemb; projection->truncate_end_member = trunc.endTruncMemb; - return OidIsValid(trunc.oldestMultiDB) && - MultiXactIdIsValid(trunc.startTruncOff) && - MultiXactIdIsValid(trunc.endTruncOff); + return OidIsValid(trunc.oldestMultiDB) && MultiXactIdIsValid(trunc.startTruncOff) + && MultiXactIdIsValid(trunc.endTruncOff); } } return false; } static bool -side_plan_commit_prepared_dependencies_closed( - const RfSideOnlinePlanV1 *plan, uint32 terminal_index) +side_plan_commit_prepared_dependencies_closed(const RfSideOnlinePlanV1 *plan, uint32 terminal_index) { const RfSideOnlineOperationV1 *terminal = &plan->operations[terminal_index]; RfSideXactCommitPreparedRequirementsV1 requirements; - uint16 i; + uint16 i; - if (rf_side_xact_commit_prepared_requirements_v1(&terminal->xact, - &requirements) != RF_SIDE_XACT_APPLY_OK) + if (rf_side_xact_commit_prepared_requirements_v1(&terminal->xact, &requirements) + != RF_SIDE_XACT_APPLY_OK) return false; - for (i = 0; i < requirements.count; i++) - { - const RfSideXactTTCommitRequirementV1 *required = - &requirements.bindings[i]; - uint32 matches = 0; - uint32 j; + for (i = 0; i < requirements.count; i++) { + const RfSideXactTTCommitRequirementV1 *required = &requirements.bindings[i]; + uint32 matches = 0; + uint32 j; if (!required->requires_apply) continue; - for (j = 0; j < terminal_index; j++) - { + for (j = 0; j < terminal_index; j++) { const RfSideOnlineOperationV1 *candidate = &plan->operations[j]; const ClusterUndoDecoded *undo = &candidate->undo; - if (candidate->kind == RF_SIDE_ONLINE_OPERATION_UNDO && - candidate->identity.participant_index == - terminal->identity.participant_index && - undo->kind == CLUSTER_UNDO_KIND_TT_COMMIT && - undo->instance == required->instance && - undo->segment_id == required->segment_id && - undo->slot_offset == required->slot_offset && - undo->wrap == required->wrap && undo->xid == required->xid && - undo->commit_scn == required->commit_scn) + if (candidate->kind == RF_SIDE_ONLINE_OPERATION_UNDO + && candidate->identity.participant_index == terminal->identity.participant_index + && undo->kind == CLUSTER_UNDO_KIND_TT_COMMIT && undo->instance == required->instance + && undo->segment_id == required->segment_id + && undo->slot_offset == required->slot_offset && undo->wrap == required->wrap + && undo->xid == required->xid && undo->commit_scn == required->commit_scn) matches++; } if (matches != 1) @@ -372,38 +333,32 @@ side_plan_commit_prepared_dependencies_closed( } static bool -side_plan_abort_prepared_dependencies_closed( - const RfSideOnlinePlanV1 *plan, uint32 terminal_index) +side_plan_abort_prepared_dependencies_closed(const RfSideOnlinePlanV1 *plan, uint32 terminal_index) { const RfSideOnlineOperationV1 *terminal = &plan->operations[terminal_index]; RfSideXactAbortPreparedRequirementsV1 requirements; - uint16 i; + uint16 i; - if (rf_side_xact_abort_prepared_requirements_v1(&terminal->xact, - &requirements) != RF_SIDE_XACT_APPLY_OK) + if (rf_side_xact_abort_prepared_requirements_v1(&terminal->xact, &requirements) + != RF_SIDE_XACT_APPLY_OK) return false; - for (i = 0; i < requirements.count; i++) - { - const RfSideXactTTAbortRequirementV1 *required = - &requirements.bindings[i]; - uint32 matches = 0; - uint32 j; + for (i = 0; i < requirements.count; i++) { + const RfSideXactTTAbortRequirementV1 *required = &requirements.bindings[i]; + uint32 matches = 0; + uint32 j; if (!required->requires_apply) continue; - for (j = 0; j < terminal_index; j++) - { + for (j = 0; j < terminal_index; j++) { const RfSideOnlineOperationV1 *candidate = &plan->operations[j]; const ClusterUndoDecoded *undo = &candidate->undo; - if (candidate->kind != RF_SIDE_ONLINE_OPERATION_UNDO || - candidate->identity.participant_index != - terminal->identity.participant_index) + if (candidate->kind != RF_SIDE_ONLINE_OPERATION_UNDO + || candidate->identity.participant_index != terminal->identity.participant_index) continue; - if (undo->kind == CLUSTER_UNDO_KIND_TT_ABORT && - undo->instance == required->instance && - undo->segment_id == required->segment_id && - undo->slot_offset == required->slot_offset && - undo->wrap == required->wrap && undo->xid == required->xid) + if (undo->kind == CLUSTER_UNDO_KIND_TT_ABORT && undo->instance == required->instance + && undo->segment_id == required->segment_id + && undo->slot_offset == required->slot_offset && undo->wrap == required->wrap + && undo->xid == required->xid) matches++; } if (matches != 1) @@ -414,63 +369,59 @@ side_plan_abort_prepared_dependencies_closed( RfPageProofDetailV1 rf_side_online_plan_create_v1(const RfSideOnlinePlanRequestV1 *request, - RfSideOnlinePlanV1 **out_plan) + RfSideOnlinePlanV1 **out_plan) { RfSideOnlinePlanV1 *plan; - Size budget; - Size arrays_size; - uint32 i; + Size budget; + Size arrays_size; + uint32 i; if (out_plan == NULL) return RF_PAGE_PROOF_DETAIL_INVALID_ARGUMENT; *out_plan = NULL; - if (request == NULL || request->system_identifier == 0 || - !side_bytes_nonzero(request->storage_uuid, 16) || - request->physical_cuts == NULL || request->participant_count == 0 || - request->participant_count > RF_PAGE_STABLE_MAX_PARTICIPANTS) + if (request == NULL || request->system_identifier == 0 + || !side_bytes_nonzero(request->storage_uuid, 16) || request->physical_cuts == NULL + || request->participant_count == 0 + || request->participant_count > RF_PAGE_STABLE_MAX_PARTICIPANTS) return RF_PAGE_PROOF_DETAIL_INVALID_ARGUMENT; - budget = request->memory_budget == 0 ? RF_SIDE_ONLINE_PLAN_MAX_BYTES : - request->memory_budget; + budget = request->memory_budget == 0 ? RF_SIDE_ONLINE_PLAN_MAX_BYTES : request->memory_budget; if (budget > RF_SIDE_ONLINE_PLAN_MAX_BYTES || budget < sizeof(*plan)) return RF_PAGE_PROOF_DETAIL_INVALID_ARGUMENT; - for (i = 0; i < request->participant_count; i++) - { + for (i = 0; i < request->participant_count; i++) { const RfContributorStreamCutV1 *cut = &request->physical_cuts[i]; bool empty = (cut->flags & RF_CONTRIBUTOR_CUT_EXPLICIT_EMPTY) != 0; - if (cut->failed_thread == 0 || cut->timeline_id == 0 || - (cut->flags & RF_CONTRIBUTOR_CUT_COMPLETE) == 0 || - (cut->flags & ~RF_CONTRIBUTOR_CUT_KNOWN_MASK) != 0 || - (empty && cut->scan_begin_inclusive != cut->scan_end_exclusive) || - (!empty && cut->scan_begin_inclusive >= cut->scan_end_exclusive) || - (i > 0 && request->physical_cuts[i - 1].failed_thread >= - cut->failed_thread)) + if (cut->failed_thread == 0 || cut->timeline_id == 0 + || (cut->flags & RF_CONTRIBUTOR_CUT_COMPLETE) == 0 + || (cut->flags & ~RF_CONTRIBUTOR_CUT_KNOWN_MASK) != 0 + || (empty && cut->scan_begin_inclusive != cut->scan_end_exclusive) + || (!empty && cut->scan_begin_inclusive >= cut->scan_end_exclusive) + || (i > 0 && request->physical_cuts[i - 1].failed_thread >= cut->failed_thread)) return RF_PAGE_PROOF_DETAIL_PARTICIPANT_MISSING; } - arrays_size = (Size) request->participant_count * - (sizeof(*plan->physical_cuts) + sizeof(*plan->last_record_end) + - sizeof(*plan->participant_seen)); + arrays_size = (Size)request->participant_count + * (sizeof(*plan->physical_cuts) + sizeof(*plan->last_record_end) + + sizeof(*plan->participant_seen)); if (sizeof(*plan) > budget - Min(budget, arrays_size)) return RF_PAGE_PROOF_DETAIL_CAPACITY; - plan = (RfSideOnlinePlanV1 *) side_alloc0(sizeof(*plan)); + plan = (RfSideOnlinePlanV1 *)side_alloc0(sizeof(*plan)); if (plan == NULL) return RF_PAGE_PROOF_DETAIL_OOM; plan->memory_budget = budget; plan->memory_used = sizeof(*plan) + arrays_size; - plan->physical_cuts = (RfContributorStreamCutV1 *) side_alloc0( - (Size) request->participant_count * sizeof(*plan->physical_cuts)); - plan->last_record_end = (XLogRecPtr *) side_alloc0( - (Size) request->participant_count * sizeof(*plan->last_record_end)); - plan->participant_seen = (bool *) side_alloc0( - (Size) request->participant_count * sizeof(*plan->participant_seen)); - if (plan->physical_cuts == NULL || plan->last_record_end == NULL || - plan->participant_seen == NULL) - { + plan->physical_cuts = (RfContributorStreamCutV1 *)side_alloc0((Size)request->participant_count + * sizeof(*plan->physical_cuts)); + plan->last_record_end = (XLogRecPtr *)side_alloc0((Size)request->participant_count + * sizeof(*plan->last_record_end)); + plan->participant_seen + = (bool *)side_alloc0((Size)request->participant_count * sizeof(*plan->participant_seen)); + if (plan->physical_cuts == NULL || plan->last_record_end == NULL + || plan->participant_seen == NULL) { rf_side_online_plan_destroy_v1(&plan); return RF_PAGE_PROOF_DETAIL_OOM; } memcpy(plan->physical_cuts, request->physical_cuts, - (Size) request->participant_count * sizeof(*plan->physical_cuts)); + (Size)request->participant_count * sizeof(*plan->physical_cuts)); plan->magic = RF_SIDE_ONLINE_PLAN_MAGIC; plan->system_identifier = request->system_identifier; memcpy(plan->storage_uuid, request->storage_uuid, 16); @@ -481,12 +432,12 @@ rf_side_online_plan_create_v1(const RfSideOnlinePlanRequestV1 *request, RfPageProofDetailV1 rf_side_online_plan_feed_record_v1(RfSideOnlinePlanV1 *plan, - const RfDetachedRecordPlanV1 *record_plan, - const RfPageOnlineRecordIdentityV1 *identity) + const RfDetachedRecordPlanV1 *record_plan, + const RfPageOnlineRecordIdentityV1 *identity) { RfSideOnlineOperationV1 candidate; RfPageProofDetailV1 detail; - uint16 participant; + uint16 participant; if (plan == NULL || plan->magic != RF_SIDE_ONLINE_PLAN_MAGIC || plan->sealed) return RF_PAGE_PROOF_DETAIL_INVALID_ARGUMENT; @@ -494,101 +445,79 @@ rf_side_online_plan_feed_record_v1(RfSideOnlinePlanV1 *plan, if (detail != RF_PAGE_PROOF_DETAIL_OK) return detail; memset(&candidate, 0, sizeof(candidate)); - if (record_plan->route.record_owner == RF_ROUTE_OWNER_SIDE_TYPED) - { - if (record_plan->route.rmid == RM_XACT_ID && - record_plan->route.codec_id == RF_ROUTE_CODEC_SIDE_STANDARD) - { - if (!rf_side_xact_decode_v1(record_plan->source_record, - plan->system_identifier, identity->record.origin_thread, - &candidate.xact)) + if (record_plan->route.record_owner == RF_ROUTE_OWNER_SIDE_TYPED) { + if (record_plan->route.rmid == RM_XACT_ID + && record_plan->route.codec_id == RF_ROUTE_CODEC_SIDE_STANDARD) { + if (!rf_side_xact_decode_v1(record_plan->source_record, plan->system_identifier, + identity->record.origin_thread, &candidate.xact)) return RF_PAGE_PROOF_DETAIL_SIDE_INCOMPLETE; candidate.kind = RF_SIDE_ONLINE_OPERATION_XACT; - if (candidate.xact.kind == RF_SIDE_XACT_PREPARE) - { - uint32 record_length = - XLogRecGetDataLen(record_plan->source_record); - - if (record_length == 0 || record_length != - candidate.xact.prepare_payload_length || - !side_ensure_operation_capacity(plan) || - !side_ensure_payload_capacity(plan, record_length)) + if (candidate.xact.kind == RF_SIDE_XACT_PREPARE) { + uint32 record_length = XLogRecGetDataLen(record_plan->source_record); + + if (record_length == 0 || record_length != candidate.xact.prepare_payload_length + || !side_ensure_operation_capacity(plan) + || !side_ensure_payload_capacity(plan, record_length)) return RF_PAGE_PROOF_DETAIL_CAPACITY; candidate.owned_payload_offset = plan->owned_payload_bytes; candidate.owned_payload_length = record_length; memcpy(plan->owned_payload + plan->owned_payload_bytes, - XLogRecGetData(record_plan->source_record), record_length); + XLogRecGetData(record_plan->source_record), record_length); plan->owned_payload_bytes += record_length; } - } - else if (record_plan->route.rmid == RM_CLUSTER_UNDO_ID && - record_plan->route.codec_id == - RF_ROUTE_CODEC_SIDE_CLUSTER_UNDO) - { + } else if (record_plan->route.rmid == RM_CLUSTER_UNDO_ID + && record_plan->route.codec_id == RF_ROUTE_CODEC_SIDE_CLUSTER_UNDO) { const char *record_data = XLogRecGetData(record_plan->source_record); - uint32 record_length = - XLogRecGetDataLen(record_plan->source_record); - - if (!cluster_undo_decode(record_plan->source_record, - &candidate.undo) || - !cluster_undo_preflight(&candidate.undo) || - candidate.undo.instance != identity->record.origin_thread || - candidate.undo.payload_offset > record_length || - candidate.undo.payload_length > - record_length - candidate.undo.payload_offset) + uint32 record_length = XLogRecGetDataLen(record_plan->source_record); + + if (!cluster_undo_decode(record_plan->source_record, &candidate.undo) + || !cluster_undo_preflight(&candidate.undo) + || candidate.undo.instance != identity->record.origin_thread + || candidate.undo.payload_offset > record_length + || candidate.undo.payload_length > record_length - candidate.undo.payload_offset) return RF_PAGE_PROOF_DETAIL_SIDE_INCOMPLETE; candidate.kind = RF_SIDE_ONLINE_OPERATION_UNDO; candidate.owned_payload_length = candidate.undo.payload_length; if (!side_ensure_operation_capacity(plan)) return RF_PAGE_PROOF_DETAIL_CAPACITY; - if (candidate.owned_payload_length > 0) - { - if (!side_ensure_payload_capacity(plan, - candidate.owned_payload_length)) + if (candidate.owned_payload_length > 0) { + if (!side_ensure_payload_capacity(plan, candidate.owned_payload_length)) return RF_PAGE_PROOF_DETAIL_CAPACITY; candidate.owned_payload_offset = plan->owned_payload_bytes; memcpy(plan->owned_payload + plan->owned_payload_bytes, - record_data + candidate.undo.payload_offset, - candidate.owned_payload_length); + record_data + candidate.undo.payload_offset, candidate.owned_payload_length); plan->owned_payload_bytes += candidate.owned_payload_length; } - } - else if ((record_plan->route.rmid == RM_CLOG_ID || - record_plan->route.rmid == RM_MULTIXACT_ID || - record_plan->route.rmid == RM_COMMIT_TS_ID) && - record_plan->route.codec_id == RF_ROUTE_CODEC_SIDE_STANDARD) - { + } else if ((record_plan->route.rmid == RM_CLOG_ID + || record_plan->route.rmid == RM_MULTIXACT_ID + || record_plan->route.rmid == RM_COMMIT_TS_ID) + && record_plan->route.codec_id == RF_ROUTE_CODEC_SIDE_STANDARD) { uint32 payload_offset; uint32 payload_length; - if (!side_projection_decode(record_plan, &candidate, - &payload_offset, &payload_length)) + if (!side_projection_decode(record_plan, &candidate, &payload_offset, &payload_length)) return RF_PAGE_PROOF_DETAIL_SIDE_INCOMPLETE; if (!side_ensure_operation_capacity(plan)) return RF_PAGE_PROOF_DETAIL_CAPACITY; candidate.kind = RF_SIDE_ONLINE_OPERATION_PROJECTION; candidate.owned_payload_length = payload_length; - if (payload_length > 0) - { + if (payload_length > 0) { if (!side_ensure_payload_capacity(plan, payload_length)) return RF_PAGE_PROOF_DETAIL_CAPACITY; candidate.owned_payload_offset = plan->owned_payload_bytes; memcpy(plan->owned_payload + plan->owned_payload_bytes, - XLogRecGetData(record_plan->source_record) + payload_offset, - payload_length); + XLogRecGetData(record_plan->source_record) + payload_offset, payload_length); plan->owned_payload_bytes += payload_length; } - } - else + } else return RF_PAGE_PROOF_DETAIL_OPCODE_UNSUPPORTED; candidate.identity = *identity; candidate.route = record_plan->route; if (!side_ensure_operation_capacity(plan)) return RF_PAGE_PROOF_DETAIL_CAPACITY; plan->operations[plan->operation_count++] = candidate; - } - else if (record_plan->route.record_owner != RF_ROUTE_OWNER_PAGE_CODEC && - record_plan->route.record_owner != RF_ROUTE_OWNER_LOGICAL_NOOP) + } else if (record_plan->route.record_owner != RF_ROUTE_OWNER_PAGE_CODEC + && record_plan->route.record_owner != RF_ROUTE_OWNER_LOGICAL_NOOP) return RF_PAGE_PROOF_DETAIL_OPCODE_UNSUPPORTED; participant = identity->participant_index; plan->participant_seen[participant] = true; @@ -599,18 +528,18 @@ rf_side_online_plan_feed_record_v1(RfSideOnlinePlanV1 *plan, RfPageProofDetailV1 rf_side_online_plan_seal_v1(RfSideOnlinePlanV1 *plan) { - uint32 i; + uint32 i; if (plan == NULL || plan->magic != RF_SIDE_ONLINE_PLAN_MAGIC || plan->sealed) return RF_PAGE_PROOF_DETAIL_INVALID_ARGUMENT; - for (i = 0; i < plan->participant_count; i++) - { + for (i = 0; i < plan->participant_count; i++) { const RfContributorStreamCutV1 *cut = &plan->physical_cuts[i]; bool empty = (cut->flags & RF_CONTRIBUTOR_CUT_EXPLICIT_EMPTY) != 0; - if ((empty && plan->participant_seen[i]) || - (!empty && (!plan->participant_seen[i] || - plan->last_record_end[i] != cut->scan_end_exclusive))) + if ((empty && plan->participant_seen[i]) + || (!empty + && (!plan->participant_seen[i] + || plan->last_record_end[i] != cut->scan_end_exclusive))) return RF_PAGE_PROOF_DETAIL_SOURCE_GAP; } plan->sealed = true; @@ -620,51 +549,47 @@ rf_side_online_plan_seal_v1(RfSideOnlinePlanV1 *plan) uint32 rf_side_online_plan_operation_count_v1(const RfSideOnlinePlanV1 *plan) { - return plan != NULL && plan->magic == RF_SIDE_ONLINE_PLAN_MAGIC && - plan->sealed ? plan->operation_count : 0; + return plan != NULL && plan->magic == RF_SIDE_ONLINE_PLAN_MAGIC && plan->sealed + ? plan->operation_count + : 0; } bool -rf_side_online_plan_operation_v1(const RfSideOnlinePlanV1 *plan, - uint32 index, RfSideOnlineOperationV1 *out_operation) +rf_side_online_plan_operation_v1(const RfSideOnlinePlanV1 *plan, uint32 index, + RfSideOnlineOperationV1 *out_operation) { - if (plan == NULL || plan->magic != RF_SIDE_ONLINE_PLAN_MAGIC || - !plan->sealed || index >= plan->operation_count || out_operation == NULL) + if (plan == NULL || plan->magic != RF_SIDE_ONLINE_PLAN_MAGIC || !plan->sealed + || index >= plan->operation_count || out_operation == NULL) return false; *out_operation = plan->operations[index]; if (out_operation->owned_payload_length > 0) - out_operation->owned_payload = plan->owned_payload + - out_operation->owned_payload_offset; + out_operation->owned_payload = plan->owned_payload + out_operation->owned_payload_offset; return true; } static bool -side_plan_apply_ops_valid(const RfSideOnlinePlanV1 *plan, - const RfSideOnlineApplyOpsV1 *ops) +side_plan_apply_ops_valid(const RfSideOnlinePlanV1 *plan, const RfSideOnlineApplyOpsV1 *ops) { - uint32 i; + uint32 i; - if (plan == NULL || plan->magic != RF_SIDE_ONLINE_PLAN_MAGIC || - !plan->sealed || ops == NULL) + if (plan == NULL || plan->magic != RF_SIDE_ONLINE_PLAN_MAGIC || !plan->sealed || ops == NULL) return false; if (ops->begin_protected_set == NULL || ops->end_protected_set == NULL) return false; for (i = 0; i < plan->operation_count; i++) - if ((plan->operations[i].kind == RF_SIDE_ONLINE_OPERATION_XACT && - (ops->preflight_xact == NULL || ops->apply_xact == NULL)) || - (plan->operations[i].kind == RF_SIDE_ONLINE_OPERATION_UNDO && - (ops->preflight_undo == NULL || ops->apply_undo == NULL)) || - (plan->operations[i].kind == RF_SIDE_ONLINE_OPERATION_PROJECTION && - (ops->preflight_projection == NULL || - ops->apply_projection == NULL)) || - plan->operations[i].kind == RF_SIDE_ONLINE_OPERATION_INVALID) + if ((plan->operations[i].kind == RF_SIDE_ONLINE_OPERATION_XACT + && (ops->preflight_xact == NULL || ops->apply_xact == NULL)) + || (plan->operations[i].kind == RF_SIDE_ONLINE_OPERATION_UNDO + && (ops->preflight_undo == NULL || ops->apply_undo == NULL)) + || (plan->operations[i].kind == RF_SIDE_ONLINE_OPERATION_PROJECTION + && (ops->preflight_projection == NULL || ops->apply_projection == NULL)) + || plan->operations[i].kind == RF_SIDE_ONLINE_OPERATION_INVALID) return false; return true; } static RfPageProofDetailV1 -side_plan_preflight_active(const RfSideOnlinePlanV1 *plan, - const RfSideOnlineApplyOpsV1 *ops) +side_plan_preflight_active(const RfSideOnlinePlanV1 *plan, const RfSideOnlineApplyOpsV1 *ops) { uint32 i; @@ -673,22 +598,20 @@ side_plan_preflight_active(const RfSideOnlinePlanV1 *plan, * byte changes. The caller keeps its protected-set certification stable * across this pass and the mutation pass below. */ - for (i = 0; i < plan->operation_count; i++) - { + for (i = 0; i < plan->operation_count; i++) { RfSideOnlineOperationV1 operation = plan->operations[i]; - bool accepted; + bool accepted; - if (operation.kind == RF_SIDE_ONLINE_OPERATION_XACT && - operation.xact.kind == RF_SIDE_XACT_COMMIT_PREPARED && - !side_plan_commit_prepared_dependencies_closed(plan, i)) + if (operation.kind == RF_SIDE_ONLINE_OPERATION_XACT + && operation.xact.kind == RF_SIDE_XACT_COMMIT_PREPARED + && !side_plan_commit_prepared_dependencies_closed(plan, i)) return RF_PAGE_PROOF_DETAIL_SIDE_INCOMPLETE; - if (operation.kind == RF_SIDE_ONLINE_OPERATION_XACT && - operation.xact.kind == RF_SIDE_XACT_ABORT_PREPARED && - !side_plan_abort_prepared_dependencies_closed(plan, i)) + if (operation.kind == RF_SIDE_ONLINE_OPERATION_XACT + && operation.xact.kind == RF_SIDE_XACT_ABORT_PREPARED + && !side_plan_abort_prepared_dependencies_closed(plan, i)) return RF_PAGE_PROOF_DETAIL_SIDE_INCOMPLETE; if (operation.owned_payload_length > 0) - operation.owned_payload = plan->owned_payload + - operation.owned_payload_offset; + operation.owned_payload = plan->owned_payload + operation.owned_payload_offset; if (operation.kind == RF_SIDE_ONLINE_OPERATION_XACT) accepted = ops->preflight_xact(ops->arg, &operation); else if (operation.kind == RF_SIDE_ONLINE_OPERATION_UNDO) @@ -702,8 +625,7 @@ side_plan_preflight_active(const RfSideOnlinePlanV1 *plan, } RfPageProofDetailV1 -rf_side_online_plan_preflight_v1(const RfSideOnlinePlanV1 *plan, - const RfSideOnlineApplyOpsV1 *ops) +rf_side_online_plan_preflight_v1(const RfSideOnlinePlanV1 *plan, const RfSideOnlineApplyOpsV1 *ops) { RfPageProofDetailV1 detail; @@ -720,11 +642,10 @@ rf_side_online_plan_preflight_v1(const RfSideOnlinePlanV1 *plan, } RfPageProofDetailV1 -rf_side_online_plan_apply_v1(const RfSideOnlinePlanV1 *plan, - const RfSideOnlineApplyOpsV1 *ops) +rf_side_online_plan_apply_v1(const RfSideOnlinePlanV1 *plan, const RfSideOnlineApplyOpsV1 *ops) { RfPageProofDetailV1 detail; - uint32 i; + uint32 i; if (!side_plan_apply_ops_valid(plan, ops)) return RF_PAGE_PROOF_DETAIL_INVALID_ARGUMENT; @@ -733,27 +654,23 @@ rf_side_online_plan_apply_v1(const RfSideOnlinePlanV1 *plan, if (!ops->begin_protected_set(ops->arg)) return RF_PAGE_PROOF_DETAIL_SIDE_INCOMPLETE; detail = side_plan_preflight_active(plan, ops); - if (detail != RF_PAGE_PROOF_DETAIL_OK) - { + if (detail != RF_PAGE_PROOF_DETAIL_OK) { ops->end_protected_set(ops->arg, false); return detail; } - for (i = 0; i < plan->operation_count; i++) - { + for (i = 0; i < plan->operation_count; i++) { RfSideOnlineOperationV1 operation = plan->operations[i]; - bool applied; + bool applied; if (operation.owned_payload_length > 0) - operation.owned_payload = plan->owned_payload + - operation.owned_payload_offset; + operation.owned_payload = plan->owned_payload + operation.owned_payload_offset; if (operation.kind == RF_SIDE_ONLINE_OPERATION_XACT) applied = ops->apply_xact(ops->arg, &operation); else if (operation.kind == RF_SIDE_ONLINE_OPERATION_UNDO) applied = ops->apply_undo(ops->arg, &operation); else applied = ops->apply_projection(ops->arg, &operation); - if (!applied) - { + if (!applied) { ops->end_protected_set(ops->arg, false); return RF_PAGE_PROOF_DETAIL_SIDE_INCOMPLETE; } diff --git a/src/backend/cluster/cluster_side_prepared.c b/src/backend/cluster/cluster_side_prepared.c index 278c3431b30..13697eafd72 100644 --- a/src/backend/cluster/cluster_side_prepared.c +++ b/src/backend/cluster/cluster_side_prepared.c @@ -37,8 +37,8 @@ cluster_side_prepared_verdict(const ClusterSidePreparedInput *in) */ if (in == NULL) return CLUSTER_SIDE_PREPARED_BLOCKED; - if (!in->prepare_redo_ok || !in->pending_durable_ok - || !in->tt_undo_match || !in->gid_identity_match) + if (!in->prepare_redo_ok || !in->pending_durable_ok || !in->tt_undo_match + || !in->gid_identity_match) return CLUSTER_SIDE_PREPARED_BLOCKED; return CLUSTER_SIDE_PREPARED_IN_DOUBT; } @@ -64,8 +64,7 @@ cluster_side_prepared_resolve_ready(const ClusterSidePreparedResolveInput *in) } bool -cluster_side_prepared_gid_identity_ok(const char *gid, uint16 gidlen, - uint32 available_bytes) +cluster_side_prepared_gid_identity_ok(const char *gid, uint16 gidlen, uint32 available_bytes) { /* * GID identity leg (implementation): a well-formed GID is @@ -75,8 +74,7 @@ cluster_side_prepared_gid_identity_ok(const char *gid, uint16 gidlen, * oversized or truncated GID can never name a matching pending * entry — identity is BLOCKED, never guessed. */ - if (gid == NULL || gidlen == 0 || gidlen > MAXPGPATH - || available_bytes < (uint32) gidlen) + if (gid == NULL || gidlen == 0 || gidlen > MAXPGPATH || available_bytes < (uint32)gidlen) return false; return gid[0] != '\0'; } diff --git a/src/backend/cluster/cluster_side_projection.c b/src/backend/cluster/cluster_side_projection.c index f3f3271328e..8fc6368eeb6 100644 --- a/src/backend/cluster/cluster_side_projection.c +++ b/src/backend/cluster/cluster_side_projection.c @@ -26,23 +26,21 @@ #include "cluster/cluster_side_online_plan.h" #include "cluster/cluster_side_projection.h" -#define RF_SIDE_CLOG_XACTS_PER_PAGE ((uint32) BLCKSZ * 4) +#define RF_SIDE_CLOG_XACTS_PER_PAGE ((uint32)BLCKSZ * 4) #define RF_SIDE_COMMIT_TS_ENTRY_BYTES UINT32_C(10) -#define RF_SIDE_COMMIT_TS_XACTS_PER_PAGE \ - ((uint32) BLCKSZ / RF_SIDE_COMMIT_TS_ENTRY_BYTES) +#define RF_SIDE_COMMIT_TS_XACTS_PER_PAGE ((uint32)BLCKSZ / RF_SIDE_COMMIT_TS_ENTRY_BYTES) static bool -cluster_side_projection_zero_range( - const ClusterSideProjectionApplyInputV1 *input, - TransactionId *first_xid, uint32 *xid_count) +cluster_side_projection_zero_range(const ClusterSideProjectionApplyInputV1 *input, + TransactionId *first_xid, uint32 *xid_count) { const ClusterSideProjectionOperationV1 *operation = input->operation; uint32 per_page; uint64 first; uint64 remaining; - if (operation->action != CLUSTER_SIDE_PROJECTION_ACTION_ZERO_PAGE || - operation->page_number < 0 || first_xid == NULL || xid_count == NULL) + if (operation->action != CLUSTER_SIDE_PROJECTION_ACTION_ZERO_PAGE || operation->page_number < 0 + || first_xid == NULL || xid_count == NULL) return false; if (operation->kind == CLUSTER_SIDE_PROJECTION_CLOG) per_page = RF_SIDE_CLOG_XACTS_PER_PAGE; @@ -50,200 +48,166 @@ cluster_side_projection_zero_range( per_page = RF_SIDE_COMMIT_TS_XACTS_PER_PAGE; else return false; - first = (uint64) (uint32) operation->page_number * per_page; + first = (uint64)(uint32)operation->page_number * per_page; if (first > UINT32_MAX) return false; - remaining = (uint64) UINT32_MAX - first + 1; - *first_xid = (TransactionId) first; - *xid_count = (uint32) Min((uint64) per_page, remaining); - return cluster_remote_xact_reset_range_valid_v2( - input->origin_thread - 1, *first_xid, *xid_count); + remaining = (uint64)UINT32_MAX - first + 1; + *first_xid = (TransactionId)first; + *xid_count = (uint32)Min((uint64)per_page, remaining); + return cluster_remote_xact_reset_range_valid_v2(input->origin_thread - 1, *first_xid, + *xid_count); } ClusterSideProjectionApplyResultV1 -cluster_side_projection_target_preflight_v1( - const ClusterSideProjectionApplyInputV1 *input) +cluster_side_projection_target_preflight_v1(const ClusterSideProjectionApplyInputV1 *input) { const ClusterSideProjectionOperationV1 *operation; TransactionId first_xid; uint32 xid_count; - if (input == NULL || input->operation == NULL || input->origin_thread == 0 || - input->origin_thread > (1 << 7)) + if (input == NULL || input->operation == NULL || input->origin_thread == 0 + || input->origin_thread > (1 << 7)) return CLUSTER_SIDE_PROJECTION_APPLY_BLOCKED; operation = input->operation; - if (operation->kind == CLUSTER_SIDE_PROJECTION_MULTIXACT) - { + if (operation->kind == CLUSTER_SIDE_PROJECTION_MULTIXACT) { uint32 i; - if (!input->source_retained || input->cluster_epoch == 0 || - input->source_lsn == InvalidXLogRecPtr || - input->source_end_lsn <= input->source_lsn) + if (!input->source_retained || input->cluster_epoch == 0 + || input->source_lsn == InvalidXLogRecPtr || input->source_end_lsn <= input->source_lsn) return CLUSTER_SIDE_PROJECTION_APPLY_BLOCKED; - if (operation->action == CLUSTER_SIDE_PROJECTION_ACTION_CREATE) - { - const MultiXactMember *members = - (const MultiXactMember *) input->owned_payload; + if (operation->action == CLUSTER_SIDE_PROJECTION_ACTION_CREATE) { + const MultiXactMember *members = (const MultiXactMember *)input->owned_payload; - if (operation->normalized_info != XLOG_MULTIXACT_CREATE_ID || - !MultiXactIdIsValid(operation->multixact_id) || - operation->member_offset == 0 || - operation->member_count == 0 || - operation->member_count > 256 || members == NULL || - input->owned_payload_length != operation->member_count * - sizeof(MultiXactMember)) + if (operation->normalized_info != XLOG_MULTIXACT_CREATE_ID + || !MultiXactIdIsValid(operation->multixact_id) || operation->member_offset == 0 + || operation->member_count == 0 || operation->member_count > 256 || members == NULL + || input->owned_payload_length != operation->member_count * sizeof(MultiXactMember)) return CLUSTER_SIDE_PROJECTION_APPLY_BLOCKED; for (i = 0; i < operation->member_count; i++) - if (!TransactionIdIsNormal(members[i].xid) || - members[i].status < MultiXactStatusForKeyShare || - members[i].status > MaxMultiXactStatus) + if (!TransactionIdIsNormal(members[i].xid) + || members[i].status < MultiXactStatusForKeyShare + || members[i].status > MaxMultiXactStatus) return CLUSTER_SIDE_PROJECTION_APPLY_BLOCKED; - } - else if (operation->action == CLUSTER_SIDE_PROJECTION_ACTION_ZERO_PAGE) - { - if ((operation->normalized_info != XLOG_MULTIXACT_ZERO_OFF_PAGE && - operation->normalized_info != XLOG_MULTIXACT_ZERO_MEM_PAGE) || - operation->page_number < 0 || input->owned_payload_length != 0) + } else if (operation->action == CLUSTER_SIDE_PROJECTION_ACTION_ZERO_PAGE) { + if ((operation->normalized_info != XLOG_MULTIXACT_ZERO_OFF_PAGE + && operation->normalized_info != XLOG_MULTIXACT_ZERO_MEM_PAGE) + || operation->page_number < 0 || input->owned_payload_length != 0) return CLUSTER_SIDE_PROJECTION_APPLY_BLOCKED; - } - else if (operation->action == CLUSTER_SIDE_PROJECTION_ACTION_TRUNCATE) - { - if (operation->normalized_info != XLOG_MULTIXACT_TRUNCATE_ID || - !OidIsValid(operation->oldest_database) || - !MultiXactIdIsValid(operation->truncate_start_multixact) || - !MultiXactIdIsValid(operation->truncate_end_multixact) || - input->owned_payload_length != 0) + } else if (operation->action == CLUSTER_SIDE_PROJECTION_ACTION_TRUNCATE) { + if (operation->normalized_info != XLOG_MULTIXACT_TRUNCATE_ID + || !OidIsValid(operation->oldest_database) + || !MultiXactIdIsValid(operation->truncate_start_multixact) + || !MultiXactIdIsValid(operation->truncate_end_multixact) + || input->owned_payload_length != 0) return CLUSTER_SIDE_PROJECTION_APPLY_BLOCKED; - } - else + } else return CLUSTER_SIDE_PROJECTION_APPLY_BLOCKED; return CLUSTER_SIDE_PROJECTION_APPLY_OK; } - if (operation->kind != CLUSTER_SIDE_PROJECTION_CLOG && - operation->kind != CLUSTER_SIDE_PROJECTION_COMMIT_TS) + if (operation->kind != CLUSTER_SIDE_PROJECTION_CLOG + && operation->kind != CLUSTER_SIDE_PROJECTION_COMMIT_TS) return CLUSTER_SIDE_PROJECTION_APPLY_BLOCKED; - if (operation->kind == CLUSTER_SIDE_PROJECTION_COMMIT_TS && - !input->source_retained) + if (operation->kind == CLUSTER_SIDE_PROJECTION_COMMIT_TS && !input->source_retained) return CLUSTER_SIDE_PROJECTION_APPLY_BLOCKED; if (operation->action == CLUSTER_SIDE_PROJECTION_ACTION_ZERO_PAGE) return cluster_side_projection_zero_range(input, &first_xid, &xid_count) - ? CLUSTER_SIDE_PROJECTION_APPLY_OK - : CLUSTER_SIDE_PROJECTION_APPLY_BLOCKED; - if (operation->action == CLUSTER_SIDE_PROJECTION_ACTION_TRUNCATE && - operation->page_number >= 0 && - TransactionIdIsNormal(operation->oldest_xid)) + ? CLUSTER_SIDE_PROJECTION_APPLY_OK + : CLUSTER_SIDE_PROJECTION_APPLY_BLOCKED; + if (operation->action == CLUSTER_SIDE_PROJECTION_ACTION_TRUNCATE && operation->page_number >= 0 + && TransactionIdIsNormal(operation->oldest_xid)) return CLUSTER_SIDE_PROJECTION_APPLY_OK; return CLUSTER_SIDE_PROJECTION_APPLY_BLOCKED; } ClusterSideProjectionApplyResultV1 -cluster_side_projection_apply_owned_v1( - const ClusterSideProjectionApplyInputV1 *input, - const ClusterSideProjectionApplyOpsV1 *ops) +cluster_side_projection_apply_owned_v1(const ClusterSideProjectionApplyInputV1 *input, + const ClusterSideProjectionApplyOpsV1 *ops) { const ClusterSideProjectionOperationV1 *operation; TransactionId first_xid; uint32 xid_count; int origin_slot; - if (cluster_side_projection_target_preflight_v1(input) != - CLUSTER_SIDE_PROJECTION_APPLY_OK || ops == NULL) + if (cluster_side_projection_target_preflight_v1(input) != CLUSTER_SIDE_PROJECTION_APPLY_OK + || ops == NULL) return CLUSTER_SIDE_PROJECTION_APPLY_BLOCKED; operation = input->operation; origin_slot = input->origin_thread - 1; - if (operation->kind == CLUSTER_SIDE_PROJECTION_MULTIXACT) - { - if (ops->apply_multixact_projection == NULL || - ops->verify_multixact_projection == NULL || - !ops->apply_multixact_projection(ops->arg, origin_slot, - input->cluster_epoch, operation, input->owned_payload, - input->owned_payload_length, input->source_lsn, - input->source_end_lsn)) + if (operation->kind == CLUSTER_SIDE_PROJECTION_MULTIXACT) { + if (ops->apply_multixact_projection == NULL || ops->verify_multixact_projection == NULL + || !ops->apply_multixact_projection( + ops->arg, origin_slot, input->cluster_epoch, operation, input->owned_payload, + input->owned_payload_length, input->source_lsn, input->source_end_lsn)) return CLUSTER_SIDE_PROJECTION_APPLY_BLOCKED; - if (!ops->verify_multixact_projection(ops->arg, origin_slot, - input->cluster_epoch, operation, input->owned_payload, - input->owned_payload_length, input->source_lsn, - input->source_end_lsn)) + if (!ops->verify_multixact_projection( + ops->arg, origin_slot, input->cluster_epoch, operation, input->owned_payload, + input->owned_payload_length, input->source_lsn, input->source_end_lsn)) return CLUSTER_SIDE_PROJECTION_APPLY_POST_READ_FAILED; return CLUSTER_SIDE_PROJECTION_APPLY_OK; } - if (operation->action == CLUSTER_SIDE_PROJECTION_ACTION_ZERO_PAGE) - { - if (ops->reset_remote_xact_range == NULL || - ops->remote_xact_range_empty == NULL || - !cluster_side_projection_zero_range(input, &first_xid, &xid_count) || - !ops->reset_remote_xact_range(ops->arg, origin_slot, - first_xid, xid_count)) + if (operation->action == CLUSTER_SIDE_PROJECTION_ACTION_ZERO_PAGE) { + if (ops->reset_remote_xact_range == NULL || ops->remote_xact_range_empty == NULL + || !cluster_side_projection_zero_range(input, &first_xid, &xid_count) + || !ops->reset_remote_xact_range(ops->arg, origin_slot, first_xid, xid_count)) return CLUSTER_SIDE_PROJECTION_APPLY_BLOCKED; - if (!ops->remote_xact_range_empty(ops->arg, origin_slot, - first_xid, xid_count)) + if (!ops->remote_xact_range_empty(ops->arg, origin_slot, first_xid, xid_count)) return CLUSTER_SIDE_PROJECTION_APPLY_POST_READ_FAILED; return CLUSTER_SIDE_PROJECTION_APPLY_OK; } - if (ops->truncate_remote_xact_before == NULL || - !ops->truncate_remote_xact_before(ops->arg, origin_slot, - operation->oldest_xid)) + if (ops->truncate_remote_xact_before == NULL + || !ops->truncate_remote_xact_before(ops->arg, origin_slot, operation->oldest_xid)) return CLUSTER_SIDE_PROJECTION_APPLY_BLOCKED; return CLUSTER_SIDE_PROJECTION_APPLY_OK; } static bool -side_projection_reset_remote_xact_range(void *arg, int origin_slot, - TransactionId first_xid, uint32 xid_count) +side_projection_reset_remote_xact_range(void *arg, int origin_slot, TransactionId first_xid, + uint32 xid_count) { - (void) arg; - return cluster_remote_xact_reset_range_v2(origin_slot, first_xid, - xid_count); + (void)arg; + return cluster_remote_xact_reset_range_v2(origin_slot, first_xid, xid_count); } static bool -side_projection_remote_xact_range_empty(void *arg, int origin_slot, - TransactionId first_xid, uint32 xid_count) +side_projection_remote_xact_range_empty(void *arg, int origin_slot, TransactionId first_xid, + uint32 xid_count) { - (void) arg; - return cluster_remote_xact_range_empty_v2(origin_slot, first_xid, - xid_count); + (void)arg; + return cluster_remote_xact_range_empty_v2(origin_slot, first_xid, xid_count); } static bool -side_projection_truncate_remote_xact_before(void *arg, int origin_slot, - TransactionId oldest_xid) +side_projection_truncate_remote_xact_before(void *arg, int origin_slot, TransactionId oldest_xid) { - (void) arg; + (void)arg; return cluster_remote_xact_truncate_before_v2(origin_slot, oldest_xid); } bool -rf_side_online_projection_owner_init_v1( - RfSideOnlineProjectionOwnerV1 *owner, uint32 cluster_epoch, - bool failed_origin_redo_retained) +rf_side_online_projection_owner_init_v1(RfSideOnlineProjectionOwnerV1 *owner, uint32 cluster_epoch, + bool failed_origin_redo_retained) { if (owner == NULL || cluster_epoch == 0) return false; memset(owner, 0, sizeof(*owner)); owner->cluster_epoch = cluster_epoch; owner->failed_origin_redo_retained = failed_origin_redo_retained; - owner->projection_ops.reset_remote_xact_range = - side_projection_reset_remote_xact_range; - owner->projection_ops.remote_xact_range_empty = - side_projection_remote_xact_range_empty; - owner->projection_ops.truncate_remote_xact_before = - side_projection_truncate_remote_xact_before; - owner->projection_ops.apply_multixact_projection = - cluster_multixact_recovery_projection_apply; - owner->projection_ops.verify_multixact_projection = - cluster_multixact_recovery_projection_verify; + owner->projection_ops.reset_remote_xact_range = side_projection_reset_remote_xact_range; + owner->projection_ops.remote_xact_range_empty = side_projection_remote_xact_range_empty; + owner->projection_ops.truncate_remote_xact_before = side_projection_truncate_remote_xact_before; + owner->projection_ops.apply_multixact_projection = cluster_multixact_recovery_projection_apply; + owner->projection_ops.verify_multixact_projection + = cluster_multixact_recovery_projection_verify; return true; } static bool side_projection_owned_input(RfSideOnlineProjectionOwnerV1 *owner, - const RfSideOnlineOperationV1 *operation, - ClusterSideProjectionApplyInputV1 *input) + const RfSideOnlineOperationV1 *operation, + ClusterSideProjectionApplyInputV1 *input) { - if (owner == NULL || operation == NULL || input == NULL || - owner->cluster_epoch == 0 || - operation->kind != RF_SIDE_ONLINE_OPERATION_PROJECTION) + if (owner == NULL || operation == NULL || input == NULL || owner->cluster_epoch == 0 + || operation->kind != RF_SIDE_ONLINE_OPERATION_PROJECTION) return false; memset(input, 0, sizeof(*input)); input->operation = &operation->projection; @@ -258,29 +222,25 @@ side_projection_owned_input(RfSideOnlineProjectionOwnerV1 *owner, } bool -rf_side_online_projection_preflight_owned_v1(void *arg, - const RfSideOnlineOperationV1 *operation) +rf_side_online_projection_preflight_owned_v1(void *arg, const RfSideOnlineOperationV1 *operation) { - RfSideOnlineProjectionOwnerV1 *owner = - (RfSideOnlineProjectionOwnerV1 *) arg; + RfSideOnlineProjectionOwnerV1 *owner = (RfSideOnlineProjectionOwnerV1 *)arg; ClusterSideProjectionApplyInputV1 input; - return side_projection_owned_input(owner, operation, &input) && - cluster_side_projection_target_preflight_v1(&input) == - CLUSTER_SIDE_PROJECTION_APPLY_OK; + return side_projection_owned_input(owner, operation, &input) + && cluster_side_projection_target_preflight_v1(&input) + == CLUSTER_SIDE_PROJECTION_APPLY_OK; } bool -rf_side_online_projection_apply_owned_v1(void *arg, - const RfSideOnlineOperationV1 *operation) +rf_side_online_projection_apply_owned_v1(void *arg, const RfSideOnlineOperationV1 *operation) { - RfSideOnlineProjectionOwnerV1 *owner = - (RfSideOnlineProjectionOwnerV1 *) arg; + RfSideOnlineProjectionOwnerV1 *owner = (RfSideOnlineProjectionOwnerV1 *)arg; ClusterSideProjectionApplyInputV1 input; - return side_projection_owned_input(owner, operation, &input) && - cluster_side_projection_apply_owned_v1(&input, - &owner->projection_ops) == CLUSTER_SIDE_PROJECTION_APPLY_OK; + return side_projection_owned_input(owner, operation, &input) + && cluster_side_projection_apply_owned_v1(&input, &owner->projection_ops) + == CLUSTER_SIDE_PROJECTION_APPLY_OK; } bool @@ -302,16 +262,14 @@ cluster_side_projection_verified(ClusterSideProjectionKind kind, return false; /* The kind itself only selects the contract; the facts are the same * three. A kind value out of range fails closed. */ - if (kind != CLUSTER_SIDE_PROJECTION_CLOG - && kind != CLUSTER_SIDE_PROJECTION_MULTIXACT + if (kind != CLUSTER_SIDE_PROJECTION_CLOG && kind != CLUSTER_SIDE_PROJECTION_MULTIXACT && kind != CLUSTER_SIDE_PROJECTION_COMMIT_TS) return false; return true; } bool -cluster_side_projection_rebuildable(ClusterSideProjectionKind kind, - bool source_retained, +cluster_side_projection_rebuildable(ClusterSideProjectionKind kind, bool source_retained, bool canonical_producer_ok) { /* @@ -327,13 +285,12 @@ cluster_side_projection_rebuildable(ClusterSideProjectionKind kind, */ if (!canonical_producer_ok) return false; - switch (kind) - { - case CLUSTER_SIDE_PROJECTION_CLOG: - return true; /* canonical truth rebuild */ - case CLUSTER_SIDE_PROJECTION_MULTIXACT: - case CLUSTER_SIDE_PROJECTION_COMMIT_TS: - return source_retained; + switch (kind) { + case CLUSTER_SIDE_PROJECTION_CLOG: + return true; /* canonical truth rebuild */ + case CLUSTER_SIDE_PROJECTION_MULTIXACT: + case CLUSTER_SIDE_PROJECTION_COMMIT_TS: + return source_retained; } return false; } @@ -345,5 +302,5 @@ cluster_side_projection_lookup(bool verified) * completes — the judgement adds no synchronous network or durable * I/O (pure function). */ return verified ? CLUSTER_SIDE_PROJECTION_LOOKUP_OK - : CLUSTER_SIDE_PROJECTION_LOOKUP_FAIL_CLOSED; + : CLUSTER_SIDE_PROJECTION_LOOKUP_FAIL_CLOSED; } diff --git a/src/backend/cluster/cluster_side_recovery.c b/src/backend/cluster/cluster_side_recovery.c index af2e4cd71b5..9c920da62cc 100644 --- a/src/backend/cluster/cluster_side_recovery.c +++ b/src/backend/cluster/cluster_side_recovery.c @@ -44,8 +44,8 @@ cluster_side_page_consumer_ready(const ClusterSidePageConsumeInput *in) if (in->page_class == CLUSTER_PAGE_CLASS_UNKNOWN || in->page_class == CLUSTER_PAGE_CLASS_UNCLASSIFIED) return false; - return in->contributor_coverage && in->durability_barrier_ok - && in->post_read_ok && in->authority_revalidated; + return in->contributor_coverage && in->durability_barrier_ok && in->post_read_ok + && in->authority_revalidated; } bool @@ -71,8 +71,7 @@ cluster_side_retention_proof_ready(const ClusterSideRetentionProof *proof) * and no exact consumer may remain. A missing post-read is a * precise denial — logical DONE never substitutes (spec §4 rows). */ - if (proof == NULL || proof->failed_origin_thread == 0 - || proof->affected_count == 0) + if (proof == NULL || proof->failed_origin_thread == 0 || proof->affected_count == 0) return CLUSTER_SIDE_RETENTION_DENY_INVALID; if (!proof->all_bytes_durable) return CLUSTER_SIDE_RETENTION_DENY_NOT_DURABLE; diff --git a/src/backend/cluster/cluster_side_route.c b/src/backend/cluster/cluster_side_route.c index b8dec4fad55..57cf8aec90f 100644 --- a/src/backend/cluster/cluster_side_route.c +++ b/src/backend/cluster/cluster_side_route.c @@ -26,13 +26,13 @@ #ifdef USE_PGRAC_CLUSTER -#include "access/rmgr.h" /* RM_* IDs */ +#include "access/rmgr.h" /* RM_* IDs */ #include "access/xact.h" #include "catalog/pg_control.h" /* XLOG_* opcodes */ #include "cluster/cluster_rf_route.h" #include "cluster/cluster_side_route.h" #include "cluster/storage/cluster_undo_xlog.h" -#include "storage/standbydefs.h" /* XLOG_STANDBY_* */ +#include "storage/standbydefs.h" /* XLOG_STANDBY_* */ /* * D-SIDE-01 consumes the same exhaustive generated opcode manifest as @@ -42,32 +42,26 @@ * silently drift apart. */ static bool -side_manifest_find(uint8 rmid, uint16 opcode, RfOpcodeRouteV1 *route, - bool *active) +side_manifest_find(uint8 rmid, uint16 opcode, RfOpcodeRouteV1 *route, bool *active) { - uint8 normalized; - size_t i; + uint8 normalized; + size_t i; if (opcode > UINT8_MAX || route == NULL || active == NULL) return false; if (rmid == RM_XACT_ID) - normalized = (uint8) opcode & XLOG_XACT_OPMASK; + normalized = (uint8)opcode & XLOG_XACT_OPMASK; else - normalized = (uint8) opcode & ~XLR_INFO_MASK; - for (i = 0; i < rf_opcode_route_manifest_count_v1(); i++) - { + normalized = (uint8)opcode & ~XLR_INFO_MASK; + for (i = 0; i < rf_opcode_route_manifest_count_v1(); i++) { RfOpcodeRouteV1 candidate; - bool candidate_active; + bool candidate_active; - if (!rf_opcode_route_manifest_entry_v1(i, &candidate, - &candidate_active)) + if (!rf_opcode_route_manifest_entry_v1(i, &candidate, &candidate_active)) return false; - if (candidate.rmid == rmid && - candidate.normalized_info == normalized) - { - if (rmid == RM_XACT_ID && - (((uint8) opcode & XLOG_XACT_HAS_INFO) & - ~candidate.legal_info_flags) != 0) + if (candidate.rmid == rmid && candidate.normalized_info == normalized) { + if (rmid == RM_XACT_ID + && (((uint8)opcode & XLOG_XACT_HAS_INFO) & ~candidate.legal_info_flags) != 0) return false; *route = candidate; *active = candidate_active; @@ -78,8 +72,7 @@ side_manifest_find(uint8 rmid, uint16 opcode, RfOpcodeRouteV1 *route, } static void -side_manifest_disposition(const RfOpcodeRouteV1 *route, bool active, - ClusterSideRouteRow *out) +side_manifest_disposition(const RfOpcodeRouteV1 *route, bool active, ClusterSideRouteRow *out) { out->rmid = route->rmid; out->opcode = route->normalized_info; @@ -87,13 +80,11 @@ side_manifest_disposition(const RfOpcodeRouteV1 *route, bool active, out->kind = CLUSTER_SIDE_ROUTE_BLOCKED; if (!active) return; - if (route->record_owner == RF_ROUTE_OWNER_PAGE_CODEC) - { + if (route->record_owner == RF_ROUTE_OWNER_PAGE_CODEC) { out->kind = CLUSTER_SIDE_ROUTE_PAGE; return; } - if (route->record_owner == RF_ROUTE_OWNER_LOGICAL_NOOP) - { + if (route->record_owner == RF_ROUTE_OWNER_LOGICAL_NOOP) { out->kind = CLUSTER_SIDE_ROUTE_PROVED_NOOP; out->noop_reason = "LOGICAL_MESSAGE_ONLY"; return; @@ -101,8 +92,7 @@ side_manifest_disposition(const RfOpcodeRouteV1 *route, bool active, if (route->record_owner != RF_ROUTE_OWNER_SIDE_TYPED) return; - if (route->codec_id == RF_ROUTE_CODEC_SIDE_CLUSTER_UNDO) - { + if (route->codec_id == RF_ROUTE_CODEC_SIDE_CLUSTER_UNDO) { if (route->normalized_info != XLOG_HW_RESERVE) out->kind = CLUSTER_SIDE_ROUTE_TT_UNDO; return; @@ -110,57 +100,51 @@ side_manifest_disposition(const RfOpcodeRouteV1 *route, bool active, if (route->codec_id != RF_ROUTE_CODEC_SIDE_STANDARD) return; - switch (route->rmid) - { - case RM_XLOG_ID: - if (route->normalized_info == XLOG_NOOP || - route->normalized_info == XLOG_SWITCH || - route->normalized_info == XLOG_RESTORE_POINT || - route->normalized_info == XLOG_BACKUP_END) - { - out->kind = CLUSTER_SIDE_ROUTE_PROVED_NOOP; - out->noop_reason = "CONTROL_ONLY"; - } - break; - case RM_XACT_ID: - if (route->normalized_info != XLOG_XACT_INVALIDATIONS) - out->kind = CLUSTER_SIDE_ROUTE_TT_UNDO; - break; - case RM_SMGR_ID: - out->kind = CLUSTER_SIDE_ROUTE_STORAGE; - break; - case RM_CLOG_ID: - case RM_MULTIXACT_ID: - case RM_COMMIT_TS_ID: - out->kind = CLUSTER_SIDE_ROUTE_PROJECTION; - break; - case RM_STANDBY_ID: - if (route->normalized_info == XLOG_STANDBY_LOCK || - route->normalized_info == XLOG_RUNNING_XACTS) - { - out->kind = CLUSTER_SIDE_ROUTE_PROVED_NOOP; - out->noop_reason = "PRIMARY_NO_STANDBY_CONSUMER"; - } - break; - case RM_HEAP2_ID: - /* XLOG_HEAP2_NEW_CID: physical recovery has no logical + switch (route->rmid) { + case RM_XLOG_ID: + if (route->normalized_info == XLOG_NOOP || route->normalized_info == XLOG_SWITCH + || route->normalized_info == XLOG_RESTORE_POINT + || route->normalized_info == XLOG_BACKUP_END) { + out->kind = CLUSTER_SIDE_ROUTE_PROVED_NOOP; + out->noop_reason = "CONTROL_ONLY"; + } + break; + case RM_XACT_ID: + if (route->normalized_info != XLOG_XACT_INVALIDATIONS) + out->kind = CLUSTER_SIDE_ROUTE_TT_UNDO; + break; + case RM_SMGR_ID: + out->kind = CLUSTER_SIDE_ROUTE_STORAGE; + break; + case RM_CLOG_ID: + case RM_MULTIXACT_ID: + case RM_COMMIT_TS_ID: + out->kind = CLUSTER_SIDE_ROUTE_PROJECTION; + break; + case RM_STANDBY_ID: + if (route->normalized_info == XLOG_STANDBY_LOCK + || route->normalized_info == XLOG_RUNNING_XACTS) { + out->kind = CLUSTER_SIDE_ROUTE_PROVED_NOOP; + out->noop_reason = "PRIMARY_NO_STANDBY_CONSUMER"; + } + break; + case RM_HEAP2_ID: + /* XLOG_HEAP2_NEW_CID: physical recovery has no logical * decoding consumer. REWRITE remains authority-blocked. */ - if (route->normalized_info == 0x70) - { - out->kind = CLUSTER_SIDE_ROUTE_PROVED_NOOP; - out->noop_reason = "LOGICAL_ONLY"; - } - break; - case RM_GIST_ID: - /* XLOG_GIST_ASSIGN_LSN is the rmgr-declared no-op. */ - if (route->normalized_info == 0x70) - { - out->kind = CLUSTER_SIDE_ROUTE_PROVED_NOOP; - out->noop_reason = "DECLARED_RMGR_NOOP"; - } - break; - default: - break; + if (route->normalized_info == 0x70) { + out->kind = CLUSTER_SIDE_ROUTE_PROVED_NOOP; + out->noop_reason = "LOGICAL_ONLY"; + } + break; + case RM_GIST_ID: + /* XLOG_GIST_ASSIGN_LSN is the rmgr-declared no-op. */ + if (route->normalized_info == 0x70) { + out->kind = CLUSTER_SIDE_ROUTE_PROVED_NOOP; + out->noop_reason = "DECLARED_RMGR_NOOP"; + } + break; + default: + break; } } @@ -168,7 +152,7 @@ bool cluster_side_route_lookup(uint8 rmid, uint16 opcode, ClusterSideRouteRow *out) { RfOpcodeRouteV1 route; - bool active; + bool active; if (out == NULL) return false; @@ -187,23 +171,22 @@ cluster_side_route_verdict(const ClusterSideRouteRow *row) * applies under its owning primitive or is BLOCKED. */ if (row == NULL) return CLUSTER_SIDE_ROUTE_VERDICT_BLOCKED; - switch (row->kind) - { - case CLUSTER_SIDE_ROUTE_PROVED_NOOP: - return CLUSTER_SIDE_ROUTE_VERDICT_PROVED_NOOP; - case CLUSTER_SIDE_ROUTE_PAGE: - case CLUSTER_SIDE_ROUTE_TT_UNDO: - case CLUSTER_SIDE_ROUTE_PROJECTION: - case CLUSTER_SIDE_ROUTE_STORAGE: - return CLUSTER_SIDE_ROUTE_VERDICT_APPLY; - case CLUSTER_SIDE_ROUTE_BLOCKED: - default: - return CLUSTER_SIDE_ROUTE_VERDICT_BLOCKED; + switch (row->kind) { + case CLUSTER_SIDE_ROUTE_PROVED_NOOP: + return CLUSTER_SIDE_ROUTE_VERDICT_PROVED_NOOP; + case CLUSTER_SIDE_ROUTE_PAGE: + case CLUSTER_SIDE_ROUTE_TT_UNDO: + case CLUSTER_SIDE_ROUTE_PROJECTION: + case CLUSTER_SIDE_ROUTE_STORAGE: + return CLUSTER_SIDE_ROUTE_VERDICT_APPLY; + case CLUSTER_SIDE_ROUTE_BLOCKED: + default: + return CLUSTER_SIDE_ROUTE_VERDICT_BLOCKED; } } -#else /* !USE_PGRAC_CLUSTER */ +#else /* !USE_PGRAC_CLUSTER */ /* Disable-cluster build: this file compiles to nothing. */ -#endif /* USE_PGRAC_CLUSTER */ +#endif /* USE_PGRAC_CLUSTER */ diff --git a/src/backend/cluster/cluster_side_space.c b/src/backend/cluster/cluster_side_space.c index 66ccacdae88..161dee781cb 100644 --- a/src/backend/cluster/cluster_side_space.c +++ b/src/backend/cluster/cluster_side_space.c @@ -34,8 +34,7 @@ cluster_side_space_metadata_mutation_allowed(ClusterSideSpaceKind kind) * API (U-SIDE-18: the STOP cannot be turned off by config or test). * "never raise shmem and call complete" (spec §3.2 HW row). */ - if (kind != CLUSTER_SIDE_SPACE_HWM - && kind != CLUSTER_SIDE_SPACE_EXTENT + if (kind != CLUSTER_SIDE_SPACE_HWM && kind != CLUSTER_SIDE_SPACE_EXTENT && kind != CLUSTER_SIDE_SPACE_BITMAP) return false; return false; @@ -57,10 +56,9 @@ cluster_side_space_metadata_page_verdict(ClusterSideSpaceKind kind, * result; expected-before apply only on an exact match). The kind * is validated for the contract but does not change the maths. */ - if (kind != CLUSTER_SIDE_SPACE_HWM - && kind != CLUSTER_SIDE_SPACE_EXTENT + if (kind != CLUSTER_SIDE_SPACE_HWM && kind != CLUSTER_SIDE_SPACE_EXTENT && kind != CLUSTER_SIDE_SPACE_BITMAP) return CLUSTER_PAGE_APPLY_BLOCKED; - return cluster_page_version_decide(current_working, expected_before, - result_version, trusted_source_version); + return cluster_page_version_decide(current_working, expected_before, result_version, + trusted_source_version); } diff --git a/src/backend/cluster/cluster_side_stats.c b/src/backend/cluster/cluster_side_stats.c index 29b45de10d7..989f7ba4352 100644 --- a/src/backend/cluster/cluster_side_stats.c +++ b/src/backend/cluster/cluster_side_stats.c @@ -26,13 +26,13 @@ void cluster_side_stats_init(ClusterSideStats *stats) { - int i; + int i; pg_atomic_uint64 *fields; - int nfields; + int nfields; if (stats == NULL) return; - fields = (pg_atomic_uint64 *) stats; + fields = (pg_atomic_uint64 *)stats; nfields = sizeof(ClusterSideStats) / sizeof(pg_atomic_uint64); for (i = 0; i < nfields; i++) pg_atomic_init_u64(&fields[i], 0); @@ -43,18 +43,17 @@ cluster_side_stats_route(ClusterSideStats *stats, int verdict) { if (stats == NULL) return; - switch ((ClusterSideRouteVerdict) verdict) - { - case CLUSTER_SIDE_ROUTE_VERDICT_APPLY: - pg_atomic_fetch_add_u64(&stats->route_applies, 1); - break; - case CLUSTER_SIDE_ROUTE_VERDICT_PROVED_NOOP: - pg_atomic_fetch_add_u64(&stats->route_noops, 1); - break; - case CLUSTER_SIDE_ROUTE_VERDICT_BLOCKED: - default: - pg_atomic_fetch_add_u64(&stats->route_blocked, 1); - break; + switch ((ClusterSideRouteVerdict)verdict) { + case CLUSTER_SIDE_ROUTE_VERDICT_APPLY: + pg_atomic_fetch_add_u64(&stats->route_applies, 1); + break; + case CLUSTER_SIDE_ROUTE_VERDICT_PROVED_NOOP: + pg_atomic_fetch_add_u64(&stats->route_noops, 1); + break; + case CLUSTER_SIDE_ROUTE_VERDICT_BLOCKED: + default: + pg_atomic_fetch_add_u64(&stats->route_blocked, 1); + break; } } @@ -63,19 +62,18 @@ cluster_side_stats_domain(ClusterSideStats *stats, int route_kind) { if (stats == NULL) return; - switch ((ClusterSideRouteKind) route_kind) - { - case CLUSTER_SIDE_ROUTE_TT_UNDO: - pg_atomic_fetch_add_u64(&stats->domain_tt_undo, 1); - break; - case CLUSTER_SIDE_ROUTE_PROJECTION: - pg_atomic_fetch_add_u64(&stats->domain_projection, 1); - break; - case CLUSTER_SIDE_ROUTE_STORAGE: - pg_atomic_fetch_add_u64(&stats->domain_storage, 1); - break; - default: - break; /* PAGE/NOOP/BLOCKED are not domain events */ + switch ((ClusterSideRouteKind)route_kind) { + case CLUSTER_SIDE_ROUTE_TT_UNDO: + pg_atomic_fetch_add_u64(&stats->domain_tt_undo, 1); + break; + case CLUSTER_SIDE_ROUTE_PROJECTION: + pg_atomic_fetch_add_u64(&stats->domain_projection, 1); + break; + case CLUSTER_SIDE_ROUTE_STORAGE: + pg_atomic_fetch_add_u64(&stats->domain_storage, 1); + break; + default: + break; /* PAGE/NOOP/BLOCKED are not domain events */ } } @@ -105,33 +103,27 @@ cluster_side_stats_durability(ClusterSideStats *stats) } /* G2 vocabulary: all EVENT; unknown names fail closed. */ -typedef struct ClusterSideStatName -{ +typedef struct ClusterSideStatName { const char *name; - int kind; /* 0 = EVENT (the only kind here) */ + int kind; /* 0 = EVENT (the only kind here) */ } ClusterSideStatName; static const ClusterSideStatName cluster_side_stat_names[] = { - { "cluster.side.route_applies", 0 }, - { "cluster.side.route_noops", 0 }, - { "cluster.side.route_blocked", 0 }, - { "cluster.side.domain_tt_undo", 0 }, - { "cluster.side.domain_projection", 0 }, - { "cluster.side.domain_storage", 0 }, - { "cluster.side.blocked_unknown_class", 0 }, - { "cluster.side.blocked_authority", 0 }, - { "cluster.side.rebuild_events", 0 }, - { "cluster.side.durability_events", 0 }, + { "cluster.side.route_applies", 0 }, { "cluster.side.route_noops", 0 }, + { "cluster.side.route_blocked", 0 }, { "cluster.side.domain_tt_undo", 0 }, + { "cluster.side.domain_projection", 0 }, { "cluster.side.domain_storage", 0 }, + { "cluster.side.blocked_unknown_class", 0 }, { "cluster.side.blocked_authority", 0 }, + { "cluster.side.rebuild_events", 0 }, { "cluster.side.durability_events", 0 }, }; bool cluster_side_stats_describe(const char *name, int *kind) { - int i; + int i; if (name == NULL) return false; - for (i = 0; i < (int) lengthof(cluster_side_stat_names); i++) { + for (i = 0; i < (int)lengthof(cluster_side_stat_names); i++) { if (strcmp(cluster_side_stat_names[i].name, name) == 0) { if (kind != NULL) *kind = cluster_side_stat_names[i].kind; diff --git a/src/backend/cluster/cluster_side_undo.c b/src/backend/cluster/cluster_side_undo.c index 86a01d9d771..6bb1a17ab91 100644 --- a/src/backend/cluster/cluster_side_undo.c +++ b/src/backend/cluster/cluster_side_undo.c @@ -39,30 +39,29 @@ static ClusterUndoDecodedKind cluster_undo_kind_for_opcode(uint16 opcode) { - switch (opcode) - { - case XLOG_UNDO_SEGMENT_INIT: - return CLUSTER_UNDO_KIND_SEGMENT_INIT; - case XLOG_UNDO_TT_SLOT_BIND: - return CLUSTER_UNDO_KIND_TT_BIND; - case XLOG_UNDO_TT_SLOT_COMMIT: - return CLUSTER_UNDO_KIND_TT_COMMIT; - case XLOG_UNDO_TT_SLOT_ABORT: - return CLUSTER_UNDO_KIND_TT_ABORT; - case XLOG_UNDO_TT_SLOT_SET_HEAD: - return CLUSTER_UNDO_KIND_TT_SET_HEAD; - case XLOG_UNDO_TT_SLOT_CTRC_RELEASE: - return CLUSTER_UNDO_KIND_TT_CTRC_RELEASE; - case XLOG_UNDO_SEGMENT_RECYCLE: - return CLUSTER_UNDO_KIND_SEGMENT_RECYCLE; - case XLOG_UNDO_SEGMENT_REUSE: - return CLUSTER_UNDO_KIND_SEGMENT_REUSE; - case XLOG_UNDO_BLOCK_WRITE: - return CLUSTER_UNDO_KIND_BLOCK_WRITE; - case XLOG_UNDO_BLOCK_WRITE_MULTI: - return CLUSTER_UNDO_KIND_BLOCK_WRITE_MULTI; - case XLOG_HW_RESERVE: - return CLUSTER_UNDO_KIND_HW_RESERVE; + switch (opcode) { + case XLOG_UNDO_SEGMENT_INIT: + return CLUSTER_UNDO_KIND_SEGMENT_INIT; + case XLOG_UNDO_TT_SLOT_BIND: + return CLUSTER_UNDO_KIND_TT_BIND; + case XLOG_UNDO_TT_SLOT_COMMIT: + return CLUSTER_UNDO_KIND_TT_COMMIT; + case XLOG_UNDO_TT_SLOT_ABORT: + return CLUSTER_UNDO_KIND_TT_ABORT; + case XLOG_UNDO_TT_SLOT_SET_HEAD: + return CLUSTER_UNDO_KIND_TT_SET_HEAD; + case XLOG_UNDO_TT_SLOT_CTRC_RELEASE: + return CLUSTER_UNDO_KIND_TT_CTRC_RELEASE; + case XLOG_UNDO_SEGMENT_RECYCLE: + return CLUSTER_UNDO_KIND_SEGMENT_RECYCLE; + case XLOG_UNDO_SEGMENT_REUSE: + return CLUSTER_UNDO_KIND_SEGMENT_REUSE; + case XLOG_UNDO_BLOCK_WRITE: + return CLUSTER_UNDO_KIND_BLOCK_WRITE; + case XLOG_UNDO_BLOCK_WRITE_MULTI: + return CLUSTER_UNDO_KIND_BLOCK_WRITE_MULTI; + case XLOG_HW_RESERVE: + return CLUSTER_UNDO_KIND_HW_RESERVE; } return CLUSTER_UNDO_KIND_UNKNOWN; } @@ -70,303 +69,268 @@ cluster_undo_kind_for_opcode(uint16 opcode) bool cluster_undo_decode(XLogReaderState *record, ClusterUndoDecoded *out) { - uint16 opcode; + uint16 opcode; ClusterUndoDecodedKind kind; if (record == NULL || out == NULL) return false; memset(out, 0, sizeof(*out)); if (XLogRecGetRmid(record) != RM_CLUSTER_UNDO_ID) - return false; /* not a cluster-undo record */ + return false; /* not a cluster-undo record */ opcode = XLogRecGetInfo(record) & XLR_RMGR_INFO_MASK; kind = cluster_undo_kind_for_opcode(opcode); if (kind == CLUSTER_UNDO_KIND_UNKNOWN) - return false; /* unknown/illegal info: BLOCKED */ + return false; /* unknown/illegal info: BLOCKED */ out->kind = kind; out->opcode = opcode; /* Per-kind parse: exact payload length + field extraction (the same * shapes the production redo handlers validate). */ - switch (kind) - { - case CLUSTER_UNDO_KIND_TT_BIND: - { - xl_undo_tt_slot_bind rec; - - if (XLogRecGetDataLen(record) != sizeof(rec)) - return false; - memcpy(&rec, XLogRecGetData(record), sizeof(rec)); - if (rec.format_version != CLUSTER_UNDO_TT_BIND_VERSION - || rec.flags != 0 || rec.reserved8 != 0 - || rec.reserved32 != 0) - return false; - out->instance = rec.instance; - out->segment_id = rec.segment_id; - out->expected_generation = rec.segment_generation; - out->slot_offset = rec.slot_offset; - out->wrap = rec.wrap; - out->xid = rec.xid; - out->format_version = rec.format_version; - out->flags = rec.flags; - break; - } - case CLUSTER_UNDO_KIND_TT_COMMIT: - { - xl_undo_tt_slot_commit rec; - - if (XLogRecGetDataLen(record) != sizeof(rec)) - return false; /* malformed: BLOCKED (U-SIDE-04) */ - memcpy(&rec, XLogRecGetData(record), sizeof(rec)); - if (rec._pad[0] != 0 || rec._pad[1] != 0 || rec._pad[2] != 0) - return false; - out->instance = rec.instance; - out->segment_id = rec.segment_id; - out->slot_offset = rec.slot_offset; - out->wrap = rec.wrap; - out->xid = rec.xid; - out->commit_scn = rec.commit_scn; - break; - } - case CLUSTER_UNDO_KIND_TT_ABORT: - { - if (XLogRecGetDataLen(record) - == sizeof(xl_undo_tt_slot_abort_exact)) { - xl_undo_tt_slot_abort_exact rec; - - memcpy(&rec, XLogRecGetData(record), sizeof(rec)); - if (rec.format_version - != CLUSTER_UNDO_TT_ABORT_EXACT_VERSION - || rec.flags != 0 || rec.reserved != 0) - return false; - out->instance = rec.instance; - out->segment_id = rec.segment_id; - out->expected_generation = rec.segment_generation; - out->slot_offset = rec.slot_offset; - out->wrap = rec.wrap; - out->xid = rec.xid; - out->format_version = rec.format_version; - out->flags = rec.flags; - } else { - xl_undo_tt_slot_abort rec; - - if (XLogRecGetDataLen(record) != sizeof(rec)) - return false; - memcpy(&rec, XLogRecGetData(record), sizeof(rec)); - if (rec._pad[0] != 0 || rec._pad[1] != 0 - || rec._pad[2] != 0) - return false; - out->instance = rec.instance; - out->segment_id = rec.segment_id; - out->slot_offset = rec.slot_offset; - out->wrap = rec.wrap; - out->xid = rec.xid; - } - break; - } - case CLUSTER_UNDO_KIND_TT_SET_HEAD: - { - xl_undo_tt_slot_set_head rec; - - if (XLogRecGetDataLen(record) != sizeof(rec)) - return false; - memcpy(&rec, XLogRecGetData(record), sizeof(rec)); - if (rec._pad[0] != 0 || rec._pad[1] != 0 || rec._pad[2] != 0) - return false; - out->instance = rec.instance; - out->segment_id = rec.segment_id; - out->slot_offset = rec.slot_offset; - out->wrap = rec.wrap; - out->xid = rec.xid; - out->first_undo_block = rec.first_undo_block; - break; - } - case CLUSTER_UNDO_KIND_TT_CTRC_RELEASE: - { - xl_undo_tt_slot_ctrc_release_v1 rec; - - if (XLogRecGetDataLen(record) - != CLUSTER_UNDO_TT_CTRC_RELEASE_BYTES - || !cluster_undo_tt_ctrc_release_decode( - (const uint8 *)XLogRecGetData(record), &rec)) - return false; - out->instance = rec.owner_instance; - out->segment_id = rec.segment_id; - out->expected_generation = rec.segment_generation; - out->slot_offset = rec.slot_offset; - out->wrap = rec.slot_wrap; - out->xid = rec.xid; - out->cluster_epoch = rec.cluster_epoch; - out->root_id = rec.root_id; - out->root_generation = rec.root_generation; - out->formation_epoch = rec.formation_epoch; - out->admission_record_generation - = rec.admission_record_generation; - out->seal_generation = rec.seal_generation; - out->touched_nodes_low = rec.touched_nodes_low; - out->touched_nodes_high = rec.touched_nodes_high; - memcpy(out->ack_set_digest, rec.ack_set_digest, - sizeof(out->ack_set_digest)); - out->format_version = rec.format_version; - out->flags = rec.flags; - out->terminal_status = rec.terminal_status; - break; - } - case CLUSTER_UNDO_KIND_SEGMENT_RECYCLE: - { - xl_undo_segment_recycle rec; - - if (XLogRecGetDataLen(record) != sizeof(rec)) - return false; - memcpy(&rec, XLogRecGetData(record), sizeof(rec)); - if (rec._pad != 0) - return false; - out->instance = rec.instance; - out->segment_id = rec.segment_id; - out->expected_generation = rec.expected_generation; - out->old_state = rec.old_state; - out->new_state = rec.new_state; - break; - } - case CLUSTER_UNDO_KIND_SEGMENT_REUSE: - { - xl_undo_segment_reuse rec; - - if (XLogRecGetDataLen(record) != sizeof(rec) + BLCKSZ) - return false; - memcpy(&rec, XLogRecGetData(record), sizeof(rec)); - if (rec._pad[0] != 0 || rec._pad[1] != 0 || rec._pad[2] != 0) - return false; - out->instance = rec.instance; - out->segment_id = rec.segment_id; - out->expected_generation = rec.old_generation; - out->new_generation = rec.new_generation; - out->has_payload = true; - out->has_fpi = true; - out->payload_offset = sizeof(rec); - out->payload_length = BLCKSZ; - break; - } - case CLUSTER_UNDO_KIND_BLOCK_WRITE: - { - xl_undo_block_write rec; - uint32 body_len; - uint32 expected; - - if (XLogRecGetDataLen(record) < sizeof(rec)) - return false; - memcpy(&rec, XLogRecGetData(record), sizeof(rec)); - body_len = XLogRecGetDataLen(record) - sizeof(rec); - if (rec.has_fpi > 1 || rec.block_no == 0) - return false; - if (rec.has_fpi == 1) - { - if (body_len != BLCKSZ || rec.rec_off != 0 || - rec.rec_len != 0 || rec.slot_off != 0) - return false; - } - else - { - expected = UNDO_BLOCK_HDR_PREFIX_LEN + rec.rec_len + - sizeof(UndoSlotDirEntry); - if (rec.rec_off < sizeof(UndoBlockHeader) || - rec.rec_len == 0 || - (uint32) rec.rec_off + rec.rec_len > BLCKSZ || - rec.slot_off < sizeof(UndoBlockHeader) || - (uint32) rec.slot_off + sizeof(UndoSlotDirEntry) > - BLCKSZ || body_len != expected) - return false; - } - out->instance = rec.instance; - out->segment_id = rec.segment_id; - out->block_no = rec.block_no; - out->has_payload = true; - out->has_fpi = rec.has_fpi == 1; - out->rec_off = rec.rec_off; - out->rec_len = rec.rec_len; - out->slot_off = rec.slot_off; - out->slot_len = sizeof(UndoSlotDirEntry); - out->payload_offset = sizeof(rec); - out->payload_length = body_len; - break; - } - case CLUSTER_UNDO_KIND_BLOCK_WRITE_MULTI: - { - xl_undo_block_write_multi rec; - uint32 body_len; - uint32 expected; - - if (XLogRecGetDataLen(record) < sizeof(rec)) - return false; - memcpy(&rec, XLogRecGetData(record), sizeof(rec)); - body_len = XLogRecGetDataLen(record) - sizeof(rec); - if (rec._pad != 0 || rec.has_fpi > 1 || rec.block_no == 0) - return false; - if (rec.has_fpi == 1) - { - if (body_len != BLCKSZ || rec.rec_off != 0 || - rec.rec_len != 0 || rec.slot_off != 0 || - rec.slot_len != 0) - return false; - } - else - { - expected = UNDO_BLOCK_HDR_PREFIX_LEN + rec.rec_len + - rec.slot_len; - if (rec.rec_off < sizeof(UndoBlockHeader) || - rec.rec_len == 0 || - (uint32) rec.rec_off + rec.rec_len > BLCKSZ || - rec.slot_off < sizeof(UndoBlockHeader) || - rec.slot_len == 0 || rec.slot_len % - sizeof(UndoSlotDirEntry) != 0 || - (uint32) rec.slot_off + rec.slot_len > BLCKSZ || - body_len != expected) - return false; - } - out->instance = rec.instance; - out->segment_id = rec.segment_id; - out->block_no = rec.block_no; - out->has_payload = true; - out->has_fpi = rec.has_fpi == 1; - out->rec_off = rec.rec_off; - out->rec_len = rec.rec_len; - out->slot_off = rec.slot_off; - out->slot_len = rec.slot_len; - out->payload_offset = sizeof(rec); - out->payload_length = body_len; - break; - } - case CLUSTER_UNDO_KIND_SEGMENT_INIT: - { - xl_cluster_undo_segment_init rec; - - if (XLogRecGetDataLen(record) != sizeof(rec) + BLCKSZ) - return false; - memcpy(&rec, XLogRecGetData(record), sizeof(rec)); - if (rec._pad[0] != 0 || rec._pad2[0] != 0 || rec._pad2[1] != 0) - return false; - out->instance = rec.instance; - out->segment_id = rec.segment_id; - out->has_payload = true; - out->has_fpi = true; - out->payload_offset = sizeof(rec); - out->payload_length = BLCKSZ; - break; - } - case CLUSTER_UNDO_KIND_HW_RESERVE: - { - const xl_hw_reserve *rec; - - if (XLogRecGetDataLen(record) != sizeof(*rec)) - return false; - rec = (const xl_hw_reserve *) XLogRecGetData(record); - /* HWM carries relation/block facts, not undo segment + switch (kind) { + case CLUSTER_UNDO_KIND_TT_BIND: { + xl_undo_tt_slot_bind rec; + + if (XLogRecGetDataLen(record) != sizeof(rec)) + return false; + memcpy(&rec, XLogRecGetData(record), sizeof(rec)); + if (rec.format_version != CLUSTER_UNDO_TT_BIND_VERSION || rec.flags != 0 + || rec.reserved8 != 0 || rec.reserved32 != 0) + return false; + out->instance = rec.instance; + out->segment_id = rec.segment_id; + out->expected_generation = rec.segment_generation; + out->slot_offset = rec.slot_offset; + out->wrap = rec.wrap; + out->xid = rec.xid; + out->format_version = rec.format_version; + out->flags = rec.flags; + break; + } + case CLUSTER_UNDO_KIND_TT_COMMIT: { + xl_undo_tt_slot_commit rec; + + if (XLogRecGetDataLen(record) != sizeof(rec)) + return false; /* malformed: BLOCKED (U-SIDE-04) */ + memcpy(&rec, XLogRecGetData(record), sizeof(rec)); + if (rec._pad[0] != 0 || rec._pad[1] != 0 || rec._pad[2] != 0) + return false; + out->instance = rec.instance; + out->segment_id = rec.segment_id; + out->slot_offset = rec.slot_offset; + out->wrap = rec.wrap; + out->xid = rec.xid; + out->commit_scn = rec.commit_scn; + break; + } + case CLUSTER_UNDO_KIND_TT_ABORT: { + if (XLogRecGetDataLen(record) == sizeof(xl_undo_tt_slot_abort_exact)) { + xl_undo_tt_slot_abort_exact rec; + + memcpy(&rec, XLogRecGetData(record), sizeof(rec)); + if (rec.format_version != CLUSTER_UNDO_TT_ABORT_EXACT_VERSION || rec.flags != 0 + || rec.reserved != 0) + return false; + out->instance = rec.instance; + out->segment_id = rec.segment_id; + out->expected_generation = rec.segment_generation; + out->slot_offset = rec.slot_offset; + out->wrap = rec.wrap; + out->xid = rec.xid; + out->format_version = rec.format_version; + out->flags = rec.flags; + } else { + xl_undo_tt_slot_abort rec; + + if (XLogRecGetDataLen(record) != sizeof(rec)) + return false; + memcpy(&rec, XLogRecGetData(record), sizeof(rec)); + if (rec._pad[0] != 0 || rec._pad[1] != 0 || rec._pad[2] != 0) + return false; + out->instance = rec.instance; + out->segment_id = rec.segment_id; + out->slot_offset = rec.slot_offset; + out->wrap = rec.wrap; + out->xid = rec.xid; + } + break; + } + case CLUSTER_UNDO_KIND_TT_SET_HEAD: { + xl_undo_tt_slot_set_head rec; + + if (XLogRecGetDataLen(record) != sizeof(rec)) + return false; + memcpy(&rec, XLogRecGetData(record), sizeof(rec)); + if (rec._pad[0] != 0 || rec._pad[1] != 0 || rec._pad[2] != 0) + return false; + out->instance = rec.instance; + out->segment_id = rec.segment_id; + out->slot_offset = rec.slot_offset; + out->wrap = rec.wrap; + out->xid = rec.xid; + out->first_undo_block = rec.first_undo_block; + break; + } + case CLUSTER_UNDO_KIND_TT_CTRC_RELEASE: { + xl_undo_tt_slot_ctrc_release_v1 rec; + + if (XLogRecGetDataLen(record) != CLUSTER_UNDO_TT_CTRC_RELEASE_BYTES + || !cluster_undo_tt_ctrc_release_decode((const uint8 *)XLogRecGetData(record), &rec)) + return false; + out->instance = rec.owner_instance; + out->segment_id = rec.segment_id; + out->expected_generation = rec.segment_generation; + out->slot_offset = rec.slot_offset; + out->wrap = rec.slot_wrap; + out->xid = rec.xid; + out->cluster_epoch = rec.cluster_epoch; + out->root_id = rec.root_id; + out->root_generation = rec.root_generation; + out->formation_epoch = rec.formation_epoch; + out->admission_record_generation = rec.admission_record_generation; + out->seal_generation = rec.seal_generation; + out->touched_nodes_low = rec.touched_nodes_low; + out->touched_nodes_high = rec.touched_nodes_high; + memcpy(out->ack_set_digest, rec.ack_set_digest, sizeof(out->ack_set_digest)); + out->format_version = rec.format_version; + out->flags = rec.flags; + out->terminal_status = rec.terminal_status; + break; + } + case CLUSTER_UNDO_KIND_SEGMENT_RECYCLE: { + xl_undo_segment_recycle rec; + + if (XLogRecGetDataLen(record) != sizeof(rec)) + return false; + memcpy(&rec, XLogRecGetData(record), sizeof(rec)); + if (rec._pad != 0) + return false; + out->instance = rec.instance; + out->segment_id = rec.segment_id; + out->expected_generation = rec.expected_generation; + out->old_state = rec.old_state; + out->new_state = rec.new_state; + break; + } + case CLUSTER_UNDO_KIND_SEGMENT_REUSE: { + xl_undo_segment_reuse rec; + + if (XLogRecGetDataLen(record) != sizeof(rec) + BLCKSZ) + return false; + memcpy(&rec, XLogRecGetData(record), sizeof(rec)); + if (rec._pad[0] != 0 || rec._pad[1] != 0 || rec._pad[2] != 0) + return false; + out->instance = rec.instance; + out->segment_id = rec.segment_id; + out->expected_generation = rec.old_generation; + out->new_generation = rec.new_generation; + out->has_payload = true; + out->has_fpi = true; + out->payload_offset = sizeof(rec); + out->payload_length = BLCKSZ; + break; + } + case CLUSTER_UNDO_KIND_BLOCK_WRITE: { + xl_undo_block_write rec; + uint32 body_len; + + if (XLogRecGetDataLen(record) < sizeof(rec)) + return false; + memcpy(&rec, XLogRecGetData(record), sizeof(rec)); + body_len = XLogRecGetDataLen(record) - sizeof(rec); + if (rec.has_fpi > 1 || rec.block_no == 0) + return false; + if (rec.has_fpi == 1) { + if (body_len != BLCKSZ || rec.rec_off != 0 || rec.rec_len != 0 || rec.slot_off != 0) + return false; + } else { + uint32 expected = UNDO_BLOCK_HDR_PREFIX_LEN + rec.rec_len + sizeof(UndoSlotDirEntry); + + if (rec.rec_off < sizeof(UndoBlockHeader) || rec.rec_len == 0 + || (uint32)rec.rec_off + rec.rec_len > BLCKSZ + || rec.slot_off < sizeof(UndoBlockHeader) + || (uint32)rec.slot_off + sizeof(UndoSlotDirEntry) > BLCKSZ || body_len != expected) + return false; + } + out->instance = rec.instance; + out->segment_id = rec.segment_id; + out->block_no = rec.block_no; + out->has_payload = true; + out->has_fpi = rec.has_fpi == 1; + out->rec_off = rec.rec_off; + out->rec_len = rec.rec_len; + out->slot_off = rec.slot_off; + out->slot_len = sizeof(UndoSlotDirEntry); + out->payload_offset = sizeof(rec); + out->payload_length = body_len; + break; + } + case CLUSTER_UNDO_KIND_BLOCK_WRITE_MULTI: { + xl_undo_block_write_multi rec; + uint32 body_len; + + if (XLogRecGetDataLen(record) < sizeof(rec)) + return false; + memcpy(&rec, XLogRecGetData(record), sizeof(rec)); + body_len = XLogRecGetDataLen(record) - sizeof(rec); + if (rec._pad != 0 || rec.has_fpi > 1 || rec.block_no == 0) + return false; + if (rec.has_fpi == 1) { + if (body_len != BLCKSZ || rec.rec_off != 0 || rec.rec_len != 0 || rec.slot_off != 0 + || rec.slot_len != 0) + return false; + } else { + uint32 expected = UNDO_BLOCK_HDR_PREFIX_LEN + rec.rec_len + rec.slot_len; + + if (rec.rec_off < sizeof(UndoBlockHeader) || rec.rec_len == 0 + || (uint32)rec.rec_off + rec.rec_len > BLCKSZ + || rec.slot_off < sizeof(UndoBlockHeader) || rec.slot_len == 0 + || rec.slot_len % sizeof(UndoSlotDirEntry) != 0 + || (uint32)rec.slot_off + rec.slot_len > BLCKSZ || body_len != expected) + return false; + } + out->instance = rec.instance; + out->segment_id = rec.segment_id; + out->block_no = rec.block_no; + out->has_payload = true; + out->has_fpi = rec.has_fpi == 1; + out->rec_off = rec.rec_off; + out->rec_len = rec.rec_len; + out->slot_off = rec.slot_off; + out->slot_len = rec.slot_len; + out->payload_offset = sizeof(rec); + out->payload_length = body_len; + break; + } + case CLUSTER_UNDO_KIND_SEGMENT_INIT: { + xl_cluster_undo_segment_init rec; + + if (XLogRecGetDataLen(record) != sizeof(rec) + BLCKSZ) + return false; + memcpy(&rec, XLogRecGetData(record), sizeof(rec)); + if (rec._pad[0] != 0 || rec._pad2[0] != 0 || rec._pad2[1] != 0) + return false; + out->instance = rec.instance; + out->segment_id = rec.segment_id; + out->has_payload = true; + out->has_fpi = true; + out->payload_offset = sizeof(rec); + out->payload_length = BLCKSZ; + break; + } + case CLUSTER_UNDO_KIND_HW_RESERVE: { + const xl_hw_reserve *rec; + + if (XLogRecGetDataLen(record) != sizeof(*rec)) + return false; + rec = (const xl_hw_reserve *)XLogRecGetData(record); + /* HWM carries relation/block facts, not undo segment * identity; it stays BLOCKED at preflight anyway * (STOP-RF-SIDE-SPACE-ABI). */ - out->block_no = rec->new_hwm; - break; - } - default: - return false; + out->block_no = rec->new_hwm; + break; + } + default: + return false; } return true; } @@ -375,7 +339,7 @@ bool cluster_undo_preflight(const ClusterUndoDecoded *decoded) { ClusterSideRouteRow route; - uint16 opcode; + uint16 opcode; if (decoded == NULL || decoded->kind == CLUSTER_UNDO_KIND_UNKNOWN) return false; @@ -392,118 +356,94 @@ cluster_undo_preflight(const ClusterUndoDecoded *decoded) /* Field integrity: TT slots must be in range (mirrors the production * handler's PANIC checks as pre-mutation gates — a malformed record * is BLOCKED, never half-applied). */ - if (decoded->kind != CLUSTER_UNDO_KIND_HW_RESERVE) - { + if (decoded->kind != CLUSTER_UNDO_KIND_HW_RESERVE) { uint32 owner; - if (decoded->instance == 0 || decoded->instance > 128 || - decoded->segment_id == 0) + if (decoded->instance == 0 || decoded->instance > 128 || decoded->segment_id == 0) return false; - owner = ((decoded->segment_id - 1) / - CLUSTER_UNDO_SEGS_PER_INSTANCE) + 1; + owner = ((decoded->segment_id - 1) / CLUSTER_UNDO_SEGS_PER_INSTANCE) + 1; if (owner != decoded->instance) return false; } - switch (decoded->kind) - { - case CLUSTER_UNDO_KIND_TT_BIND: - if (decoded->slot_offset >= TT_SLOTS_PER_SEGMENT - || !TransactionIdIsNormal(decoded->xid) - || decoded->wrap == TT_WRAP_INVALID - || decoded->format_version != CLUSTER_UNDO_TT_BIND_VERSION - || decoded->flags != 0) - return false; - break; - case CLUSTER_UNDO_KIND_TT_COMMIT: - case CLUSTER_UNDO_KIND_TT_SET_HEAD: - if (decoded->slot_offset >= TT_SLOTS_PER_SEGMENT) - return false; - if (!TransactionIdIsNormal(decoded->xid) || decoded->wrap == 0) - return false; - if (decoded->kind == CLUSTER_UNDO_KIND_TT_COMMIT && - !SCN_VALID(decoded->commit_scn)) - return false; - if (decoded->kind == CLUSTER_UNDO_KIND_TT_SET_HEAD) - { - uint32 segment_id; - uint32 block_no; - uint16 slot_offset; - uint16 row_offset; - - if (!uba_decode_record(decoded->first_undo_block, &segment_id, - &block_no, &slot_offset, &row_offset) || - segment_id != decoded->segment_id || - slot_offset != decoded->slot_offset) - return false; - } - break; - case CLUSTER_UNDO_KIND_TT_ABORT: - if (decoded->slot_offset >= TT_SLOTS_PER_SEGMENT - || !TransactionIdIsNormal(decoded->xid)) - return false; - if (decoded->format_version - == CLUSTER_UNDO_TT_ABORT_EXACT_VERSION) { - if (decoded->expected_generation == UINT32_MAX - || decoded->wrap == TT_WRAP_INVALID - || decoded->flags != 0) - return false; - } else if (decoded->format_version != 0 || decoded->wrap == 0) - return false; - break; - case CLUSTER_UNDO_KIND_TT_CTRC_RELEASE: - if (decoded->slot_offset >= TT_SLOTS_PER_SEGMENT - || !TransactionIdIsNormal(decoded->xid) - || decoded->expected_generation == 0 - || decoded->wrap == TT_WRAP_INVALID - || decoded->cluster_epoch == 0 - || decoded->root_id == 0 - || decoded->root_generation == 0 - || decoded->formation_epoch == 0 - || decoded->admission_record_generation == 0 - || decoded->seal_generation == 0 - || decoded->touched_nodes_high != 0 - || (decoded->touched_nodes_low & ~UINT64_C(0xffff)) != 0 - || (decoded->terminal_status != TT_SLOT_COMMITTED - && decoded->terminal_status != TT_SLOT_ABORTED) - || decoded->format_version - != CLUSTER_UNDO_TT_CTRC_RELEASE_VERSION - || decoded->flags - != CLUSTER_UNDO_TT_CTRC_RELEASE_ALL_TOUCHED_ACKED) - return false; - break; - case CLUSTER_UNDO_KIND_SEGMENT_RECYCLE: - if (decoded->old_state != SEGMENT_COMMITTED || - decoded->new_state != SEGMENT_RECYCLABLE) - return false; - break; - case CLUSTER_UNDO_KIND_SEGMENT_REUSE: - if (decoded->new_generation != - decoded->expected_generation + 1 || - !decoded->has_fpi || decoded->payload_length != BLCKSZ) - return false; - break; - case CLUSTER_UNDO_KIND_SEGMENT_INIT: - if (!decoded->has_fpi || decoded->payload_length != BLCKSZ) + switch (decoded->kind) { + case CLUSTER_UNDO_KIND_TT_BIND: + if (decoded->slot_offset >= TT_SLOTS_PER_SEGMENT || !TransactionIdIsNormal(decoded->xid) + || decoded->wrap == TT_WRAP_INVALID + || decoded->format_version != CLUSTER_UNDO_TT_BIND_VERSION || decoded->flags != 0) + return false; + break; + case CLUSTER_UNDO_KIND_TT_COMMIT: + case CLUSTER_UNDO_KIND_TT_SET_HEAD: + if (decoded->slot_offset >= TT_SLOTS_PER_SEGMENT) + return false; + if (!TransactionIdIsNormal(decoded->xid) || decoded->wrap == 0) + return false; + if (decoded->kind == CLUSTER_UNDO_KIND_TT_COMMIT && !SCN_VALID(decoded->commit_scn)) + return false; + if (decoded->kind == CLUSTER_UNDO_KIND_TT_SET_HEAD) { + uint32 segment_id; + uint32 block_no; + uint16 slot_offset; + uint16 row_offset; + + if (!uba_decode_record(decoded->first_undo_block, &segment_id, &block_no, &slot_offset, + &row_offset) + || segment_id != decoded->segment_id || slot_offset != decoded->slot_offset) return false; - break; - case CLUSTER_UNDO_KIND_BLOCK_WRITE: - case CLUSTER_UNDO_KIND_BLOCK_WRITE_MULTI: - if (decoded->block_no == 0 || !decoded->has_payload || - decoded->payload_length == 0) + } + break; + case CLUSTER_UNDO_KIND_TT_ABORT: + if (decoded->slot_offset >= TT_SLOTS_PER_SEGMENT || !TransactionIdIsNormal(decoded->xid)) + return false; + if (decoded->format_version == CLUSTER_UNDO_TT_ABORT_EXACT_VERSION) { + if (decoded->expected_generation == UINT32_MAX || decoded->wrap == TT_WRAP_INVALID + || decoded->flags != 0) return false; - break; - default: - break; + } else if (decoded->format_version != 0 || decoded->wrap == 0) + return false; + break; + case CLUSTER_UNDO_KIND_TT_CTRC_RELEASE: + if (decoded->slot_offset >= TT_SLOTS_PER_SEGMENT || !TransactionIdIsNormal(decoded->xid) + || decoded->expected_generation == 0 || decoded->wrap == TT_WRAP_INVALID + || decoded->cluster_epoch == 0 || decoded->root_id == 0 || decoded->root_generation == 0 + || decoded->formation_epoch == 0 || decoded->admission_record_generation == 0 + || decoded->seal_generation == 0 || decoded->touched_nodes_high != 0 + || (decoded->touched_nodes_low & ~UINT64_C(0xffff)) != 0 + || (decoded->terminal_status != TT_SLOT_COMMITTED + && decoded->terminal_status != TT_SLOT_ABORTED) + || decoded->format_version != CLUSTER_UNDO_TT_CTRC_RELEASE_VERSION + || decoded->flags != CLUSTER_UNDO_TT_CTRC_RELEASE_ALL_TOUCHED_ACKED) + return false; + break; + case CLUSTER_UNDO_KIND_SEGMENT_RECYCLE: + if (decoded->old_state != SEGMENT_COMMITTED || decoded->new_state != SEGMENT_RECYCLABLE) + return false; + break; + case CLUSTER_UNDO_KIND_SEGMENT_REUSE: + if (decoded->new_generation != decoded->expected_generation + 1 || !decoded->has_fpi + || decoded->payload_length != BLCKSZ) + return false; + break; + case CLUSTER_UNDO_KIND_SEGMENT_INIT: + if (!decoded->has_fpi || decoded->payload_length != BLCKSZ) + return false; + break; + case CLUSTER_UNDO_KIND_BLOCK_WRITE: + case CLUSTER_UNDO_KIND_BLOCK_WRITE_MULTI: + if (decoded->block_no == 0 || !decoded->has_payload || decoded->payload_length == 0) + return false; + break; + default: + break; } return true; } static bool cluster_undo_ctrc_release_from_decoded(const ClusterUndoDecoded *decoded, - xl_undo_tt_slot_ctrc_release_v1 *record) + xl_undo_tt_slot_ctrc_release_v1 *record) { - if (decoded == NULL || record == NULL - || decoded->kind != CLUSTER_UNDO_KIND_TT_CTRC_RELEASE) + if (decoded == NULL || record == NULL || decoded->kind != CLUSTER_UNDO_KIND_TT_CTRC_RELEASE) return false; memset(record, 0, sizeof(*record)); record->segment_id = decoded->segment_id; @@ -513,13 +453,11 @@ cluster_undo_ctrc_release_from_decoded(const ClusterUndoDecoded *decoded, record->root_id = decoded->root_id; record->root_generation = decoded->root_generation; record->formation_epoch = decoded->formation_epoch; - record->admission_record_generation - = decoded->admission_record_generation; + record->admission_record_generation = decoded->admission_record_generation; record->seal_generation = decoded->seal_generation; record->touched_nodes_low = decoded->touched_nodes_low; record->touched_nodes_high = decoded->touched_nodes_high; - memcpy(record->ack_set_digest, decoded->ack_set_digest, - sizeof(record->ack_set_digest)); + memcpy(record->ack_set_digest, decoded->ack_set_digest, sizeof(record->ack_set_digest)); record->slot_offset = decoded->slot_offset; record->slot_wrap = decoded->wrap; record->owner_instance = decoded->instance; @@ -532,20 +470,14 @@ cluster_undo_ctrc_release_from_decoded(const ClusterUndoDecoded *decoded, ClusterUndoTargetPreflightV1 cluster_undo_preflight_tt_target_v1(const ClusterUndoDecoded *decoded) { - TTSlot slot; - ClusterTTActiveTransitionDecision bind_decision; - ClusterTTTerminalTransitionDecision abort_decision; - ClusterUndoTtCtrcReleaseRedoDecision release_decision; - xl_undo_tt_slot_ctrc_release_v1 release_record; + TTSlot slot; if (!cluster_undo_preflight(decoded)) return CLUSTER_UNDO_TARGET_BLOCKED; - if (decoded->kind == CLUSTER_UNDO_KIND_TT_BIND) - { - bind_decision = cluster_tt_durable_bind_preflight_exact( - decoded->instance, decoded->segment_id, - decoded->expected_generation, decoded->slot_offset, - decoded->wrap, decoded->xid); + if (decoded->kind == CLUSTER_UNDO_KIND_TT_BIND) { + ClusterTTActiveTransitionDecision bind_decision = cluster_tt_durable_bind_preflight_exact( + decoded->instance, decoded->segment_id, decoded->expected_generation, + decoded->slot_offset, decoded->wrap, decoded->xid); if (bind_decision == CLUSTER_TT_ACTIVE_APPLY) return CLUSTER_UNDO_TARGET_APPLY; if (bind_decision == CLUSTER_TT_ACTIVE_IDEMPOTENT) @@ -555,12 +487,11 @@ cluster_undo_preflight_tt_target_v1(const ClusterUndoDecoded *decoded) return CLUSTER_UNDO_TARGET_BLOCKED; } if (decoded->kind == CLUSTER_UNDO_KIND_TT_ABORT - && decoded->format_version == CLUSTER_UNDO_TT_ABORT_EXACT_VERSION) - { - abort_decision = cluster_tt_durable_abort_preflight_exact( - decoded->instance, decoded->segment_id, - decoded->expected_generation, decoded->slot_offset, - decoded->wrap, decoded->xid); + && decoded->format_version == CLUSTER_UNDO_TT_ABORT_EXACT_VERSION) { + ClusterTTTerminalTransitionDecision abort_decision + = cluster_tt_durable_abort_preflight_exact( + decoded->instance, decoded->segment_id, decoded->expected_generation, + decoded->slot_offset, decoded->wrap, decoded->xid); if (abort_decision == CLUSTER_TT_TERMINAL_APPLY) return CLUSTER_UNDO_TARGET_APPLY; if (abort_decision == CLUSTER_TT_TERMINAL_IDEMPOTENT @@ -568,69 +499,57 @@ cluster_undo_preflight_tt_target_v1(const ClusterUndoDecoded *decoded) return CLUSTER_UNDO_TARGET_PROVED_NOOP; return CLUSTER_UNDO_TARGET_BLOCKED; } - if (decoded->kind == CLUSTER_UNDO_KIND_TT_CTRC_RELEASE) - { - if (!cluster_undo_ctrc_release_from_decoded(decoded, - &release_record)) + if (decoded->kind == CLUSTER_UNDO_KIND_TT_CTRC_RELEASE) { + ClusterUndoTtCtrcReleaseRedoDecision release_decision; + xl_undo_tt_slot_ctrc_release_v1 release_record; + + if (!cluster_undo_ctrc_release_from_decoded(decoded, &release_record)) return CLUSTER_UNDO_TARGET_BLOCKED; - release_decision - = cluster_tt_durable_ctrc_release_preflight_exact( - &release_record); - if (release_decision - == CLUSTER_UNDO_TT_CTRC_RELEASE_REDO_APPLY) + release_decision = cluster_tt_durable_ctrc_release_preflight_exact(&release_record); + if (release_decision == CLUSTER_UNDO_TT_CTRC_RELEASE_REDO_APPLY) return CLUSTER_UNDO_TARGET_APPLY; - if (release_decision - == CLUSTER_UNDO_TT_CTRC_RELEASE_REDO_IDEMPOTENT - || release_decision - == CLUSTER_UNDO_TT_CTRC_RELEASE_REDO_SKIP_STALE) + if (release_decision == CLUSTER_UNDO_TT_CTRC_RELEASE_REDO_IDEMPOTENT + || release_decision == CLUSTER_UNDO_TT_CTRC_RELEASE_REDO_SKIP_STALE) return CLUSTER_UNDO_TARGET_PROVED_NOOP; return CLUSTER_UNDO_TARGET_BLOCKED; } - if (decoded->kind != CLUSTER_UNDO_KIND_TT_COMMIT && - decoded->kind != CLUSTER_UNDO_KIND_TT_ABORT && - decoded->kind != CLUSTER_UNDO_KIND_TT_SET_HEAD) + if (decoded->kind != CLUSTER_UNDO_KIND_TT_COMMIT && decoded->kind != CLUSTER_UNDO_KIND_TT_ABORT + && decoded->kind != CLUSTER_UNDO_KIND_TT_SET_HEAD) return CLUSTER_UNDO_TARGET_BLOCKED; - if (!cluster_tt_slot_durable_read_exact_stable(decoded->segment_id, - decoded->slot_offset, decoded->xid, decoded->wrap, &slot)) + if (!cluster_tt_slot_durable_read_exact_stable(decoded->segment_id, decoded->slot_offset, + decoded->xid, decoded->wrap, &slot)) return CLUSTER_UNDO_TARGET_BLOCKED; - switch (decoded->kind) - { - case CLUSTER_UNDO_KIND_TT_BIND: - cluster_tt_durable_redo_bind_slot(decoded->instance, - decoded->segment_id, decoded->expected_generation, - decoded->slot_offset, decoded->wrap, decoded->xid); - break; - case CLUSTER_UNDO_KIND_TT_COMMIT: - if (slot.status == TT_SLOT_COMMITTED && - slot.commit_scn == decoded->commit_scn && - UBA_is_invalid(slot.first_undo_block)) - return CLUSTER_UNDO_TARGET_PROVED_NOOP; - if (slot.status == TT_SLOT_ACTIVE && - !SCN_VALID(slot.commit_scn)) - return CLUSTER_UNDO_TARGET_APPLY; - break; - case CLUSTER_UNDO_KIND_TT_ABORT: - if (slot.status == TT_SLOT_ABORTED && - !SCN_VALID(slot.commit_scn) && - UBA_is_invalid(slot.first_undo_block)) - return CLUSTER_UNDO_TARGET_PROVED_NOOP; - if (slot.status == TT_SLOT_ACTIVE && - !SCN_VALID(slot.commit_scn)) - return CLUSTER_UNDO_TARGET_APPLY; - break; - case CLUSTER_UNDO_KIND_TT_SET_HEAD: - if (slot.status != TT_SLOT_ABORTED || - SCN_VALID(slot.commit_scn)) - break; - if (memcmp(&slot.first_undo_block, &decoded->first_undo_block, - sizeof(UBA)) == 0) - return CLUSTER_UNDO_TARGET_PROVED_NOOP; - if (UBA_is_invalid(slot.first_undo_block)) - return CLUSTER_UNDO_TARGET_APPLY; - break; - default: + switch (decoded->kind) { + case CLUSTER_UNDO_KIND_TT_BIND: + cluster_tt_durable_redo_bind_slot(decoded->instance, decoded->segment_id, + decoded->expected_generation, decoded->slot_offset, + decoded->wrap, decoded->xid); + break; + case CLUSTER_UNDO_KIND_TT_COMMIT: + if (slot.status == TT_SLOT_COMMITTED && slot.commit_scn == decoded->commit_scn + && UBA_is_invalid(slot.first_undo_block)) + return CLUSTER_UNDO_TARGET_PROVED_NOOP; + if (slot.status == TT_SLOT_ACTIVE && !SCN_VALID(slot.commit_scn)) + return CLUSTER_UNDO_TARGET_APPLY; + break; + case CLUSTER_UNDO_KIND_TT_ABORT: + if (slot.status == TT_SLOT_ABORTED && !SCN_VALID(slot.commit_scn) + && UBA_is_invalid(slot.first_undo_block)) + return CLUSTER_UNDO_TARGET_PROVED_NOOP; + if (slot.status == TT_SLOT_ACTIVE && !SCN_VALID(slot.commit_scn)) + return CLUSTER_UNDO_TARGET_APPLY; + break; + case CLUSTER_UNDO_KIND_TT_SET_HEAD: + if (slot.status != TT_SLOT_ABORTED || SCN_VALID(slot.commit_scn)) break; + if (memcmp(&slot.first_undo_block, &decoded->first_undo_block, sizeof(UBA)) == 0) + return CLUSTER_UNDO_TARGET_PROVED_NOOP; + if (UBA_is_invalid(slot.first_undo_block)) + return CLUSTER_UNDO_TARGET_APPLY; + break; + default: + break; } return CLUSTER_UNDO_TARGET_BLOCKED; } @@ -638,7 +557,7 @@ cluster_undo_preflight_tt_target_v1(const ClusterUndoDecoded *decoded) ClusterUndoApplyResultV1 cluster_undo_apply_tt_v1(const ClusterUndoDecoded *decoded) { - TTSlot post_slot; + TTSlot post_slot; ClusterUndoTargetPreflightV1 target; xl_undo_tt_slot_ctrc_release_v1 release_record; @@ -647,94 +566,79 @@ cluster_undo_apply_tt_v1(const ClusterUndoDecoded *decoded) return CLUSTER_UNDO_APPLY_BLOCKED; if (target == CLUSTER_UNDO_TARGET_PROVED_NOOP) return CLUSTER_UNDO_APPLY_OK; - switch (decoded->kind) - { - case CLUSTER_UNDO_KIND_TT_BIND: - cluster_tt_durable_redo_bind_slot(decoded->instance, - decoded->segment_id, decoded->expected_generation, + switch (decoded->kind) { + case CLUSTER_UNDO_KIND_TT_BIND: + cluster_tt_durable_redo_bind_slot(decoded->instance, decoded->segment_id, + decoded->expected_generation, decoded->slot_offset, + decoded->wrap, decoded->xid); + break; + case CLUSTER_UNDO_KIND_TT_COMMIT: + cluster_tt_durable_redo_stamp_slot(decoded->instance, decoded->segment_id, + decoded->slot_offset, decoded->wrap, decoded->xid, + decoded->commit_scn); + break; + case CLUSTER_UNDO_KIND_TT_ABORT: + if (decoded->format_version == CLUSTER_UNDO_TT_ABORT_EXACT_VERSION) { + cluster_tt_durable_redo_abort_slot_exact( + decoded->instance, decoded->segment_id, decoded->expected_generation, decoded->slot_offset, decoded->wrap, decoded->xid); - break; - case CLUSTER_UNDO_KIND_TT_COMMIT: - cluster_tt_durable_redo_stamp_slot(decoded->instance, - decoded->segment_id, decoded->slot_offset, decoded->wrap, - decoded->xid, decoded->commit_scn); - break; - case CLUSTER_UNDO_KIND_TT_ABORT: - if (decoded->format_version - == CLUSTER_UNDO_TT_ABORT_EXACT_VERSION) - { - cluster_tt_durable_redo_abort_slot_exact(decoded->instance, - decoded->segment_id, decoded->expected_generation, - decoded->slot_offset, decoded->wrap, decoded->xid); - if (cluster_tt_durable_abort_preflight_exact( - decoded->instance, decoded->segment_id, - decoded->expected_generation, decoded->slot_offset, - decoded->wrap, decoded->xid) - != CLUSTER_TT_TERMINAL_IDEMPOTENT) - return CLUSTER_UNDO_APPLY_POST_READ_FAILED; - return CLUSTER_UNDO_APPLY_OK; - } - cluster_tt_durable_redo_abort_slot(decoded->instance, - decoded->segment_id, decoded->slot_offset, decoded->wrap, - decoded->xid); - break; - case CLUSTER_UNDO_KIND_TT_CTRC_RELEASE: - if (!cluster_undo_ctrc_release_from_decoded(decoded, - &release_record)) - return CLUSTER_UNDO_APPLY_BLOCKED; - cluster_tt_durable_redo_ctrc_release_slot_exact( - &release_record); - if (cluster_undo_preflight_tt_target_v1(decoded) - != CLUSTER_UNDO_TARGET_PROVED_NOOP) + if (cluster_tt_durable_abort_preflight_exact( + decoded->instance, decoded->segment_id, decoded->expected_generation, + decoded->slot_offset, decoded->wrap, decoded->xid) + != CLUSTER_TT_TERMINAL_IDEMPOTENT) return CLUSTER_UNDO_APPLY_POST_READ_FAILED; return CLUSTER_UNDO_APPLY_OK; - case CLUSTER_UNDO_KIND_TT_SET_HEAD: - cluster_tt_durable_redo_set_head_slot(decoded->instance, - decoded->segment_id, decoded->slot_offset, decoded->wrap, - decoded->xid, decoded->first_undo_block); - break; - default: + } + cluster_tt_durable_redo_abort_slot(decoded->instance, decoded->segment_id, + decoded->slot_offset, decoded->wrap, decoded->xid); + break; + case CLUSTER_UNDO_KIND_TT_CTRC_RELEASE: + if (!cluster_undo_ctrc_release_from_decoded(decoded, &release_record)) return CLUSTER_UNDO_APPLY_BLOCKED; + cluster_tt_durable_redo_ctrc_release_slot_exact(&release_record); + if (cluster_undo_preflight_tt_target_v1(decoded) != CLUSTER_UNDO_TARGET_PROVED_NOOP) + return CLUSTER_UNDO_APPLY_POST_READ_FAILED; + return CLUSTER_UNDO_APPLY_OK; + case CLUSTER_UNDO_KIND_TT_SET_HEAD: + cluster_tt_durable_redo_set_head_slot(decoded->instance, decoded->segment_id, + decoded->slot_offset, decoded->wrap, decoded->xid, + decoded->first_undo_block); + break; + default: + return CLUSTER_UNDO_APPLY_BLOCKED; } - if (!cluster_tt_slot_durable_read_exact_stable(decoded->segment_id, - decoded->slot_offset, decoded->xid, decoded->wrap, &post_slot)) + if (!cluster_tt_slot_durable_read_exact_stable(decoded->segment_id, decoded->slot_offset, + decoded->xid, decoded->wrap, &post_slot)) return CLUSTER_UNDO_APPLY_POST_READ_FAILED; - switch (decoded->kind) - { - case CLUSTER_UNDO_KIND_TT_BIND: - if (post_slot.status != TT_SLOT_ACTIVE || - SCN_VALID(post_slot.commit_scn) || - post_slot.flags != TT_FLAGS_RESERVED || - !UBA_is_invalid(post_slot.first_undo_block)) - return CLUSTER_UNDO_APPLY_POST_READ_FAILED; - break; - case CLUSTER_UNDO_KIND_TT_COMMIT: - if (post_slot.status != TT_SLOT_COMMITTED || - post_slot.commit_scn != decoded->commit_scn || - !UBA_is_invalid(post_slot.first_undo_block)) - return CLUSTER_UNDO_APPLY_POST_READ_FAILED; - break; - case CLUSTER_UNDO_KIND_TT_ABORT: - if (post_slot.status != TT_SLOT_ABORTED || - SCN_VALID(post_slot.commit_scn) || - !UBA_is_invalid(post_slot.first_undo_block)) - return CLUSTER_UNDO_APPLY_POST_READ_FAILED; - break; - case CLUSTER_UNDO_KIND_TT_SET_HEAD: - if (post_slot.status != TT_SLOT_ABORTED || - SCN_VALID(post_slot.commit_scn) || - memcmp(&post_slot.first_undo_block, - &decoded->first_undo_block, sizeof(UBA)) != 0) - return CLUSTER_UNDO_APPLY_POST_READ_FAILED; - break; - default: - return CLUSTER_UNDO_APPLY_BLOCKED; + switch (decoded->kind) { + case CLUSTER_UNDO_KIND_TT_BIND: + if (post_slot.status != TT_SLOT_ACTIVE || SCN_VALID(post_slot.commit_scn) + || post_slot.flags != TT_FLAGS_RESERVED || !UBA_is_invalid(post_slot.first_undo_block)) + return CLUSTER_UNDO_APPLY_POST_READ_FAILED; + break; + case CLUSTER_UNDO_KIND_TT_COMMIT: + if (post_slot.status != TT_SLOT_COMMITTED || post_slot.commit_scn != decoded->commit_scn + || !UBA_is_invalid(post_slot.first_undo_block)) + return CLUSTER_UNDO_APPLY_POST_READ_FAILED; + break; + case CLUSTER_UNDO_KIND_TT_ABORT: + if (post_slot.status != TT_SLOT_ABORTED || SCN_VALID(post_slot.commit_scn) + || !UBA_is_invalid(post_slot.first_undo_block)) + return CLUSTER_UNDO_APPLY_POST_READ_FAILED; + break; + case CLUSTER_UNDO_KIND_TT_SET_HEAD: + if (post_slot.status != TT_SLOT_ABORTED || SCN_VALID(post_slot.commit_scn) + || memcmp(&post_slot.first_undo_block, &decoded->first_undo_block, sizeof(UBA)) != 0) + return CLUSTER_UNDO_APPLY_POST_READ_FAILED; + break; + default: + return CLUSTER_UNDO_APPLY_BLOCKED; } return CLUSTER_UNDO_APPLY_OK; } -#else /* !USE_PGRAC_CLUSTER */ +#else /* !USE_PGRAC_CLUSTER */ /* Disable-cluster build: this file compiles to nothing. */ -#endif /* USE_PGRAC_CLUSTER */ +#endif /* USE_PGRAC_CLUSTER */ diff --git a/src/backend/cluster/cluster_side_xact.c b/src/backend/cluster/cluster_side_xact.c index 033ec1dd9e1..f2a680c0835 100644 --- a/src/backend/cluster/cluster_side_xact.c +++ b/src/backend/cluster/cluster_side_xact.c @@ -23,30 +23,26 @@ #include "cluster/storage/cluster_undo_alloc.h" #include "cluster/storage/cluster_undo_xlog.h" -#define RF_SIDE_XACT_KNOWN_XINFO \ - (XACT_XINFO_HAS_DBINFO | XACT_XINFO_HAS_SUBXACTS | \ - XACT_XINFO_HAS_RELFILELOCATORS | XACT_XINFO_HAS_INVALS | \ - XACT_XINFO_HAS_TWOPHASE | XACT_XINFO_HAS_ORIGIN | \ - XACT_XINFO_HAS_AE_LOCKS | XACT_XINFO_HAS_GID | \ - XACT_XINFO_HAS_DROPPED_STATS | XACT_XINFO_HAS_SCN | \ - XACT_XINFO_HAS_TT_COMMIT) +#define RF_SIDE_XACT_KNOWN_XINFO \ + (XACT_XINFO_HAS_DBINFO | XACT_XINFO_HAS_SUBXACTS | XACT_XINFO_HAS_RELFILELOCATORS \ + | XACT_XINFO_HAS_INVALS | XACT_XINFO_HAS_TWOPHASE | XACT_XINFO_HAS_ORIGIN \ + | XACT_XINFO_HAS_AE_LOCKS | XACT_XINFO_HAS_GID | XACT_XINFO_HAS_DROPPED_STATS \ + | XACT_XINFO_HAS_SCN | XACT_XINFO_HAS_TT_COMMIT) #define RF_SIDE_XACT_TWOPHASE_MAGIC UINT32_C(0x57F94534) -typedef struct RfSideXactCursorV1 -{ +typedef struct RfSideXactCursorV1 { const char *position; const char *end; } RfSideXactCursorV1; -typedef struct RfSideTwoPhaseRecordOnDiskV1 -{ - uint32 len; +typedef struct RfSideTwoPhaseRecordOnDiskV1 { + uint32 len; TwoPhaseRmgrId rmid; - uint16 info; + uint16 info; } RfSideTwoPhaseRecordOnDiskV1; StaticAssertDecl(sizeof(RfSideTwoPhaseRecordOnDiskV1) == 8, - "RF-SIDE two-phase record header must match PostgreSQL's 8-byte layout"); + "RF-SIDE two-phase record header must match PostgreSQL's 8-byte layout"); static void side_xact_payload_free(void *payload) @@ -61,7 +57,7 @@ side_xact_payload_free(void *payload) static bool side_xact_take(RfSideXactCursorV1 *cursor, Size bytes, const char **start) { - if (cursor == NULL || bytes > (Size) (cursor->end - cursor->position)) + if (cursor == NULL || bytes > (Size)(cursor->end - cursor->position)) return false; if (start != NULL) *start = cursor->position; @@ -73,127 +69,106 @@ static bool side_xact_take_counted(RfSideXactCursorV1 *cursor, Size element_size) { const char *count_bytes; - int count; + int count; if (!side_xact_take(cursor, sizeof(count), &count_bytes)) return false; memcpy(&count, count_bytes, sizeof(count)); - return count >= 0 && - (Size) count <= (Size) (cursor->end - cursor->position) / - element_size && - side_xact_take(cursor, (Size) count * element_size, NULL); + return count >= 0 && (Size)count <= (Size)(cursor->end - cursor->position) / element_size + && side_xact_take(cursor, (Size)count * element_size, NULL); } static bool -side_xact_take_aligned_array(RfSideXactCursorV1 *cursor, int32 count, - Size element_size) +side_xact_take_aligned_array(RfSideXactCursorV1 *cursor, int32 count, Size element_size) { - Size bytes; + Size bytes; - if (count < 0 || (Size) count > - (Size) (cursor->end - cursor->position) / element_size) + if (count < 0 || (Size)count > (Size)(cursor->end - cursor->position) / element_size) return false; - bytes = (Size) count * element_size; + bytes = (Size)count * element_size; return side_xact_take(cursor, MAXALIGN(bytes), NULL); } static bool -side_xact_prepare_payload_valid(const char *data, uint32 data_len, - RfSideXactOperationV1 *candidate) +side_xact_prepare_payload_valid(const char *data, uint32 data_len, RfSideXactOperationV1 *candidate) { RfSideXactCursorV1 cursor; xl_xact_prepare header; ClusterTT2PCParsed parsed_tt; const char *gid; - bool found_cluster_tt = false; - bool found_end = false; - uint16 i; + bool found_cluster_tt = false; + bool found_end = false; + uint16 i; - if (candidate == NULL || data == NULL || - data_len < MAXALIGN(sizeof(header))) + if (candidate == NULL || data == NULL || data_len < MAXALIGN(sizeof(header))) return false; memcpy(&header, data, sizeof(header)); - if (header.magic != RF_SIDE_XACT_TWOPHASE_MAGIC || - (uint64) header.total_len != (uint64) data_len + sizeof(pg_crc32c) || - header.gidlen <= 1 || header.gidlen > GIDSIZE) + if (header.magic != RF_SIDE_XACT_TWOPHASE_MAGIC + || (uint64)header.total_len != (uint64)data_len + sizeof(pg_crc32c) || header.gidlen <= 1 + || header.gidlen > GIDSIZE) return false; cursor.position = data + MAXALIGN(sizeof(header)); cursor.end = data + data_len; - if (!side_xact_take(&cursor, MAXALIGN(header.gidlen), &gid) || - gid[header.gidlen - 1] != '\0' || - memchr(gid, '\0', header.gidlen - 1) != NULL || - !side_xact_take_aligned_array(&cursor, header.nsubxacts, - sizeof(TransactionId)) || - !side_xact_take_aligned_array(&cursor, header.ncommitrels, - sizeof(RelFileLocator)) || - !side_xact_take_aligned_array(&cursor, header.nabortrels, - sizeof(RelFileLocator)) || - !side_xact_take_aligned_array(&cursor, header.ncommitstats, - sizeof(xl_xact_stats_item)) || - !side_xact_take_aligned_array(&cursor, header.nabortstats, - sizeof(xl_xact_stats_item)) || - !side_xact_take_aligned_array(&cursor, header.ninvalmsgs, - sizeof(SharedInvalidationMessage))) + if (!side_xact_take(&cursor, MAXALIGN(header.gidlen), &gid) || gid[header.gidlen - 1] != '\0' + || memchr(gid, '\0', header.gidlen - 1) != NULL + || !side_xact_take_aligned_array(&cursor, header.nsubxacts, sizeof(TransactionId)) + || !side_xact_take_aligned_array(&cursor, header.ncommitrels, sizeof(RelFileLocator)) + || !side_xact_take_aligned_array(&cursor, header.nabortrels, sizeof(RelFileLocator)) + || !side_xact_take_aligned_array(&cursor, header.ncommitstats, sizeof(xl_xact_stats_item)) + || !side_xact_take_aligned_array(&cursor, header.nabortstats, sizeof(xl_xact_stats_item)) + || !side_xact_take_aligned_array(&cursor, header.ninvalmsgs, + sizeof(SharedInvalidationMessage))) return false; - while (cursor.position < cursor.end) - { + while (cursor.position < cursor.end) { RfSideTwoPhaseRecordOnDiskV1 disk_record; const char *record_header; const char *record_data; - Size aligned_len; + Size aligned_len; - if (!side_xact_take(&cursor, MAXALIGN(sizeof(disk_record)), - &record_header)) + if (!side_xact_take(&cursor, MAXALIGN(sizeof(disk_record)), &record_header)) return false; memcpy(&disk_record, record_header, sizeof(disk_record)); - if (disk_record.rmid == TWOPHASE_RM_END_ID) - { - if (disk_record.len != 0 || disk_record.info != 0 || - cursor.position != cursor.end) + if (disk_record.rmid == TWOPHASE_RM_END_ID) { + if (disk_record.len != 0 || disk_record.info != 0 || cursor.position != cursor.end) return false; found_end = true; break; } - if (disk_record.rmid > TWOPHASE_RM_MAX_ID || - disk_record.len > (uint32) (cursor.end - cursor.position)) + if (disk_record.rmid > TWOPHASE_RM_MAX_ID + || disk_record.len > (uint32)(cursor.end - cursor.position)) return false; - aligned_len = MAXALIGN((Size) disk_record.len); - if (aligned_len < disk_record.len || - !side_xact_take(&cursor, aligned_len, &record_data)) + aligned_len = MAXALIGN((Size)disk_record.len); + if (aligned_len < disk_record.len || !side_xact_take(&cursor, aligned_len, &record_data)) return false; if (disk_record.rmid != TWOPHASE_RM_CLUSTER_TT_ID) continue; - if (found_cluster_tt || disk_record.info != 0 || - !cluster_tt_2pc_parse_record(record_data, disk_record.len, - &parsed_tt) || parsed_tt.nbindings == 0) + if (found_cluster_tt || disk_record.info != 0 + || !cluster_tt_2pc_parse_record(record_data, disk_record.len, &parsed_tt) + || parsed_tt.nbindings == 0) return false; found_cluster_tt = true; candidate->prepared_record_version = parsed_tt.version; candidate->prepared_binding_count = parsed_tt.nbindings; candidate->prepared_sublink_count = parsed_tt.nsublinks; memcpy(candidate->prepared_bindings, parsed_tt.bindings, - (Size) parsed_tt.nbindings * sizeof(*parsed_tt.bindings)); + (Size)parsed_tt.nbindings * sizeof(*parsed_tt.bindings)); if (parsed_tt.nsublinks > 0) memcpy(candidate->prepared_sublinks, parsed_tt.sublinks, - (Size) parsed_tt.nsublinks * sizeof(*parsed_tt.sublinks)); + (Size)parsed_tt.nsublinks * sizeof(*parsed_tt.sublinks)); if (parsed_tt.heads != NULL) memcpy(candidate->prepared_heads, parsed_tt.heads, - (Size) parsed_tt.nbindings * sizeof(*parsed_tt.heads)); + (Size)parsed_tt.nbindings * sizeof(*parsed_tt.heads)); } if (!found_end || !found_cluster_tt) return false; - for (i = 0; i < candidate->prepared_binding_count; i++) - { - const ClusterTT2PCBinding *binding = - &candidate->prepared_bindings[i]; - - if (binding->undo_segment_id == 0 || - ((binding->undo_segment_id - 1) / - CLUSTER_UNDO_SEGS_PER_INSTANCE) + 1 != - candidate->origin_thread || - binding->slot_offset >= TT_SLOTS_PER_SEGMENT || - binding->wrap == 0 || binding->cluster_epoch == 0 || - !TransactionIdIsNormal(binding->xid)) + for (i = 0; i < candidate->prepared_binding_count; i++) { + const ClusterTT2PCBinding *binding = &candidate->prepared_bindings[i]; + + if (binding->undo_segment_id == 0 + || ((binding->undo_segment_id - 1) / CLUSTER_UNDO_SEGS_PER_INSTANCE) + 1 + != candidate->origin_thread + || binding->slot_offset >= TT_SLOTS_PER_SEGMENT || binding->wrap == 0 + || binding->cluster_epoch == 0 || !TransactionIdIsNormal(binding->xid)) return false; } if (!OidIsValid(header.owner)) @@ -208,11 +183,11 @@ side_xact_prepare_payload_valid(const char *data, uint32 data_len, } static bool -side_xact_prepare_shape_valid(XLogReaderState *record, - RfSideXactOperationV1 *candidate) +side_xact_prepare_shape_valid(XLogReaderState *record, RfSideXactOperationV1 *candidate) { - return record != NULL && side_xact_prepare_payload_valid( - XLogRecGetData(record), XLogRecGetDataLen(record), candidate); + return record != NULL + && side_xact_prepare_payload_valid(XLogRecGetData(record), XLogRecGetDataLen(record), + candidate); } static bool @@ -220,9 +195,9 @@ side_xact_completion_shape_valid(XLogReaderState *record, bool commit) { RfSideXactCursorV1 cursor; const char *xinfo_bytes; - uint32 xinfo = 0; - Size base_size = commit ? MinSizeOfXactCommit : MinSizeOfXactAbort; - uint32 data_len; + uint32 xinfo = 0; + Size base_size = commit ? MinSizeOfXactCommit : MinSizeOfXactAbort; + uint32 data_len; const char *data; const char *terminator; @@ -232,55 +207,48 @@ side_xact_completion_shape_valid(XLogReaderState *record, bool commit) return false; cursor.position = data + base_size; cursor.end = data + data_len; - if ((XLogRecGetInfo(record) & XLOG_XACT_HAS_INFO) != 0) - { + if ((XLogRecGetInfo(record) & XLOG_XACT_HAS_INFO) != 0) { if (!side_xact_take(&cursor, sizeof(xl_xact_xinfo), &xinfo_bytes)) return false; memcpy(&xinfo, xinfo_bytes, sizeof(xinfo)); } - if ((xinfo & ~RF_SIDE_XACT_KNOWN_XINFO) != 0 || - ((xinfo & XACT_XINFO_HAS_GID) != 0 && - (xinfo & XACT_XINFO_HAS_TWOPHASE) == 0) || - (!commit && (xinfo & XACT_XINFO_HAS_TT_COMMIT) != 0)) + if ((xinfo & ~RF_SIDE_XACT_KNOWN_XINFO) != 0 + || ((xinfo & XACT_XINFO_HAS_GID) != 0 && (xinfo & XACT_XINFO_HAS_TWOPHASE) == 0) + || (!commit && (xinfo & XACT_XINFO_HAS_TT_COMMIT) != 0)) return false; - if ((xinfo & XACT_XINFO_HAS_DBINFO) != 0 && - !side_xact_take(&cursor, sizeof(xl_xact_dbinfo), NULL)) + if ((xinfo & XACT_XINFO_HAS_DBINFO) != 0 + && !side_xact_take(&cursor, sizeof(xl_xact_dbinfo), NULL)) return false; - if ((xinfo & XACT_XINFO_HAS_SUBXACTS) != 0 && - !side_xact_take_counted(&cursor, sizeof(TransactionId))) + if ((xinfo & XACT_XINFO_HAS_SUBXACTS) != 0 + && !side_xact_take_counted(&cursor, sizeof(TransactionId))) return false; - if ((xinfo & XACT_XINFO_HAS_RELFILELOCATORS) != 0 && - !side_xact_take_counted(&cursor, sizeof(RelFileLocator))) + if ((xinfo & XACT_XINFO_HAS_RELFILELOCATORS) != 0 + && !side_xact_take_counted(&cursor, sizeof(RelFileLocator))) return false; - if ((xinfo & XACT_XINFO_HAS_DROPPED_STATS) != 0 && - !side_xact_take_counted(&cursor, sizeof(xl_xact_stats_item))) + if ((xinfo & XACT_XINFO_HAS_DROPPED_STATS) != 0 + && !side_xact_take_counted(&cursor, sizeof(xl_xact_stats_item))) return false; - if (commit && (xinfo & XACT_XINFO_HAS_INVALS) != 0 && - !side_xact_take_counted(&cursor, sizeof(SharedInvalidationMessage))) + if (commit && (xinfo & XACT_XINFO_HAS_INVALS) != 0 + && !side_xact_take_counted(&cursor, sizeof(SharedInvalidationMessage))) return false; - if ((xinfo & XACT_XINFO_HAS_TWOPHASE) != 0) - { + if ((xinfo & XACT_XINFO_HAS_TWOPHASE) != 0) { if (!side_xact_take(&cursor, sizeof(xl_xact_twophase), NULL)) return false; - if ((xinfo & XACT_XINFO_HAS_GID) != 0) - { + if ((xinfo & XACT_XINFO_HAS_GID) != 0) { terminator = memchr(cursor.position, '\0', - Min((Size) GIDSIZE, - (Size) (cursor.end - cursor.position))); - if (terminator == NULL || terminator == cursor.position || - !side_xact_take(&cursor, - (Size) (terminator - cursor.position) + 1, NULL)) + Min((Size)GIDSIZE, (Size)(cursor.end - cursor.position))); + if (terminator == NULL || terminator == cursor.position + || !side_xact_take(&cursor, (Size)(terminator - cursor.position) + 1, NULL)) return false; } } - if ((xinfo & XACT_XINFO_HAS_ORIGIN) != 0 && - !side_xact_take(&cursor, sizeof(xl_xact_origin), NULL)) + if ((xinfo & XACT_XINFO_HAS_ORIGIN) != 0 + && !side_xact_take(&cursor, sizeof(xl_xact_origin), NULL)) return false; - if ((xinfo & XACT_XINFO_HAS_SCN) != 0 && - !side_xact_take(&cursor, sizeof(xl_xact_scn), NULL)) + if ((xinfo & XACT_XINFO_HAS_SCN) != 0 && !side_xact_take(&cursor, sizeof(xl_xact_scn), NULL)) return false; - if (commit && (xinfo & XACT_XINFO_HAS_TT_COMMIT) != 0 && - !side_xact_take(&cursor, sizeof(xl_xact_tt_commit), NULL)) + if (commit && (xinfo & XACT_XINFO_HAS_TT_COMMIT) != 0 + && !side_xact_take(&cursor, sizeof(xl_xact_tt_commit), NULL)) return false; return cursor.position == cursor.end; } @@ -288,151 +256,128 @@ side_xact_completion_shape_valid(XLogReaderState *record, bool commit) static bool side_xact_no_commit_effects(const xl_xact_parsed_commit *parsed) { - return parsed->nsubxacts == 0 && parsed->nrels == 0 && - parsed->nstats == 0 && parsed->nmsgs == 0; + return parsed->nsubxacts == 0 && parsed->nrels == 0 && parsed->nstats == 0 + && parsed->nmsgs == 0; } static bool side_xact_no_abort_effects(const xl_xact_parsed_abort *parsed) { - return parsed->nsubxacts == 0 && parsed->nrels == 0 && - parsed->nstats == 0; + return parsed->nsubxacts == 0 && parsed->nrels == 0 && parsed->nstats == 0; } static bool -side_xact_tt_delta_valid(const xl_xact_tt_commit *delta, - uint16 origin_thread, TransactionId xid, SCN scn) +side_xact_tt_delta_valid(const xl_xact_tt_commit *delta, uint16 origin_thread, TransactionId xid, + SCN scn) { - return delta != NULL && delta->instance == origin_thread && - delta->segment_id != 0 && delta->segment_generation != UINT32_MAX && - delta->slot_offset < TT_SLOTS_PER_SEGMENT && - delta->wrap != TT_WRAP_INVALID && delta->xid == xid && - delta->format_version == CLUSTER_XACT_TT_COMMIT_VERSION && - delta->flags == 0 && delta->reserved == 0 && - delta->commit_scn == scn; + return delta != NULL && delta->instance == origin_thread && delta->segment_id != 0 + && delta->segment_generation != UINT32_MAX && delta->slot_offset < TT_SLOTS_PER_SEGMENT + && delta->wrap != TT_WRAP_INVALID && delta->xid == xid + && delta->format_version == CLUSTER_XACT_TT_COMMIT_VERSION && delta->flags == 0 + && delta->reserved == 0 && delta->commit_scn == scn; } static bool -side_xact_key_matches_binding(const ClusterTTStatusKey *key, - const ClusterTT2PCBinding *binding, +side_xact_key_matches_binding(const ClusterTTStatusKey *key, const ClusterTT2PCBinding *binding, uint16 origin_thread) { - return key->origin_node_id == origin_thread - 1 && - key->undo_segment_id == binding->undo_segment_id && - key->tt_slot_id == - cluster_tt_slot_offset_to_id(binding->slot_offset) && - key->cluster_epoch == binding->cluster_epoch && - key->local_xid == binding->xid && key->_reserved == 0 && - key->_reserved2 == 0; + return key->origin_node_id == origin_thread - 1 + && key->undo_segment_id == binding->undo_segment_id + && key->tt_slot_id == cluster_tt_slot_offset_to_id(binding->slot_offset) + && key->cluster_epoch == binding->cluster_epoch && key->local_xid == binding->xid + && key->_reserved == 0 && key->_reserved2 == 0; } static int -side_xact_binding_for_key(const RfSideXactOperationV1 *operation, - const ClusterTTStatusKey *key) +side_xact_binding_for_key(const RfSideXactOperationV1 *operation, const ClusterTTStatusKey *key) { - uint16 i; + uint16 i; for (i = 0; i < operation->prepared_binding_count; i++) - if (side_xact_key_matches_binding(key, - &operation->prepared_bindings[i], operation->origin_thread)) - return (int) i; + if (side_xact_key_matches_binding(key, &operation->prepared_bindings[i], + operation->origin_thread)) + return (int)i; return -1; } static bool side_xact_prepared_material_valid(const RfSideXactOperationV1 *operation) { - bool top_seen = false; - uint16 i; - uint32 j; - - if ((operation->prepared_record_version != - CLUSTER_TT_2PC_VERSION_NO_HEADS && - operation->prepared_record_version != CLUSTER_TT_2PC_VERSION) || - operation->prepared_binding_count == 0 || - operation->prepared_binding_count > CLUSTER_TT_2PC_MAX_BINDINGS || - operation->prepared_sublink_count > CLUSTER_TT_2PC_MAX_SUBLINKS) + bool top_seen = false; + uint16 i; + uint32 j; + + if ((operation->prepared_record_version != CLUSTER_TT_2PC_VERSION_NO_HEADS + && operation->prepared_record_version != CLUSTER_TT_2PC_VERSION) + || operation->prepared_binding_count == 0 + || operation->prepared_binding_count > CLUSTER_TT_2PC_MAX_BINDINGS + || operation->prepared_sublink_count > CLUSTER_TT_2PC_MAX_SUBLINKS) return false; - for (i = 0; i < operation->prepared_binding_count; i++) - { - const ClusterTT2PCBinding *binding = - &operation->prepared_bindings[i]; - uint32 owner; - uint32 head_segment; - uint32 head_block; - uint16 head_slot; - uint16 head_row; - uint16 k; + for (i = 0; i < operation->prepared_binding_count; i++) { + const ClusterTT2PCBinding *binding = &operation->prepared_bindings[i]; + uint32 owner; + uint32 head_segment; + uint32 head_block; + uint16 head_slot; + uint16 head_row; + uint16 k; if (binding->undo_segment_id == 0) return false; - owner = ((binding->undo_segment_id - 1) / - CLUSTER_UNDO_SEGS_PER_INSTANCE) + 1; - if (owner != operation->origin_thread || - binding->slot_offset >= TT_SLOTS_PER_SEGMENT || - binding->wrap == 0 || binding->cluster_epoch == 0 || - !TransactionIdIsNormal(binding->xid)) + owner = ((binding->undo_segment_id - 1) / CLUSTER_UNDO_SEGS_PER_INSTANCE) + 1; + if (owner != operation->origin_thread || binding->slot_offset >= TT_SLOTS_PER_SEGMENT + || binding->wrap == 0 || binding->cluster_epoch == 0 + || !TransactionIdIsNormal(binding->xid)) return false; for (k = 0; k < i; k++) - if (operation->prepared_bindings[k].undo_segment_id == - binding->undo_segment_id && - operation->prepared_bindings[k].slot_offset == - binding->slot_offset) + if (operation->prepared_bindings[k].undo_segment_id == binding->undo_segment_id + && operation->prepared_bindings[k].slot_offset == binding->slot_offset) return false; if (binding->xid == operation->xid) top_seen = true; - if (operation->prepared_record_version == - CLUSTER_TT_2PC_VERSION_NO_HEADS) - { + if (operation->prepared_record_version == CLUSTER_TT_2PC_VERSION_NO_HEADS) { if (!UBA_is_invalid(operation->prepared_heads[i])) return false; - } - else if (!UBA_is_invalid(operation->prepared_heads[i]) && - (!uba_decode_record(operation->prepared_heads[i], &head_segment, - &head_block, &head_slot, &head_row) || - head_segment != binding->undo_segment_id || - head_slot != binding->slot_offset)) + } else if (!UBA_is_invalid(operation->prepared_heads[i]) + && (!uba_decode_record(operation->prepared_heads[i], &head_segment, &head_block, + &head_slot, &head_row) + || head_segment != binding->undo_segment_id + || head_slot != binding->slot_offset)) return false; } if (!top_seen) return false; - for (j = 0; j < operation->prepared_sublink_count; j++) - { + for (j = 0; j < operation->prepared_sublink_count; j++) { const ClusterTT2PCSubLink *link = &operation->prepared_sublinks[j]; - uint32 k; + uint32 k; - if (side_xact_binding_for_key(operation, &link->child_key) < 0 || - side_xact_binding_for_key(operation, &link->parent_key) < 0 || - link->child_key.local_xid == link->parent_key.local_xid) + if (side_xact_binding_for_key(operation, &link->child_key) < 0 + || side_xact_binding_for_key(operation, &link->parent_key) < 0 + || link->child_key.local_xid == link->parent_key.local_xid) return false; for (k = 0; k < j; k++) - if (memcmp(&operation->prepared_sublinks[k].child_key, - &link->child_key, sizeof(link->child_key)) == 0) + if (memcmp(&operation->prepared_sublinks[k].child_key, &link->child_key, + sizeof(link->child_key)) + == 0) return false; } - for (i = 0; i < operation->prepared_binding_count; i++) - { + for (i = 0; i < operation->prepared_binding_count; i++) { ClusterTTStatusKey key; - uint32 depth; + uint32 depth; if (operation->prepared_bindings[i].xid == operation->xid) continue; memset(&key, 0, sizeof(key)); key.origin_node_id = operation->origin_thread - 1; - key.undo_segment_id = - (uint16) operation->prepared_bindings[i].undo_segment_id; - key.tt_slot_id = cluster_tt_slot_offset_to_id( - operation->prepared_bindings[i].slot_offset); + key.undo_segment_id = (uint16)operation->prepared_bindings[i].undo_segment_id; + key.tt_slot_id = cluster_tt_slot_offset_to_id(operation->prepared_bindings[i].slot_offset); key.cluster_epoch = operation->prepared_bindings[i].cluster_epoch; key.local_xid = operation->prepared_bindings[i].xid; - for (depth = 0; depth <= operation->prepared_sublink_count; depth++) - { + for (depth = 0; depth <= operation->prepared_sublink_count; depth++) { const ClusterTT2PCSubLink *link = NULL; for (j = 0; j < operation->prepared_sublink_count; j++) - if (memcmp(&operation->prepared_sublinks[j].child_key, - &key, sizeof(key)) == 0) - { + if (memcmp(&operation->prepared_sublinks[j].child_key, &key, sizeof(key)) == 0) { link = &operation->prepared_sublinks[j]; break; } @@ -451,97 +396,79 @@ side_xact_prepared_material_valid(const RfSideXactOperationV1 *operation) static TimestampTz side_xact_commit_timestamp(const xl_xact_parsed_commit *parsed) { - return (parsed->xinfo & XACT_XINFO_HAS_ORIGIN) != 0 - ? parsed->origin_timestamp : parsed->xact_time; + return (parsed->xinfo & XACT_XINFO_HAS_ORIGIN) != 0 ? parsed->origin_timestamp + : parsed->xact_time; } bool -rf_side_xact_structural_preflight_v1( - const RfSideXactOperationV1 *operation) +rf_side_xact_structural_preflight_v1(const RfSideXactOperationV1 *operation) { - uint8 binding_seen = 0; + uint8 binding_seen = 0; const char *gid_end; - Size i; + Size i; - if (operation == NULL || operation->system_identifier == 0 || - operation->kind == RF_SIDE_XACT_INVALID || - operation->origin_thread == 0 || operation->origin_thread > 128 || - operation->reserved_zero != 0 || - !TransactionIdIsNormal(operation->xid)) + if (operation == NULL || operation->system_identifier == 0 + || operation->kind == RF_SIDE_XACT_INVALID || operation->origin_thread == 0 + || operation->origin_thread > 128 || operation->reserved_zero != 0 + || !TransactionIdIsNormal(operation->xid)) return false; for (i = 0; i < sizeof(operation->reserved49); i++) if (operation->reserved49[i] != 0) return false; for (i = 0; i < sizeof(operation->prepare_binding); i++) binding_seen |= operation->prepare_binding[i]; - gid_end = memchr(operation->prepare_gid, '\0', - sizeof(operation->prepare_gid)); - - switch (operation->kind) - { - case RF_SIDE_XACT_COMMIT: - return SCN_VALID(operation->terminal_scn) && - operation->terminal_timestamp != 0 && - operation->has_tt_delta && - side_xact_tt_delta_valid(&operation->tt_delta, - operation->origin_thread, operation->xid, - operation->terminal_scn) && binding_seen == 0 && - operation->prepared_owner == InvalidOid && - operation->prepare_payload_length == 0 && - operation->prepared_at == 0 && operation->prepare_gid[0] == '\0'; - case RF_SIDE_XACT_ABORT: - return SCN_VALID(operation->terminal_scn) && - operation->terminal_timestamp == 0 && - !operation->has_tt_delta && binding_seen == 0 && - operation->prepared_owner == InvalidOid && - operation->prepare_payload_length == 0 && - operation->prepared_at == 0 && operation->prepare_gid[0] == '\0'; - case RF_SIDE_XACT_PREPARE: - return OidIsValid(operation->database) && - OidIsValid(operation->prepared_owner) && - operation->prepare_payload_length > 0 && - gid_end != NULL && gid_end != operation->prepare_gid && - operation->terminal_scn == InvalidScn && - operation->terminal_timestamp == 0 && - !operation->has_tt_delta && binding_seen != 0 && - side_xact_prepared_material_valid(operation); - case RF_SIDE_XACT_COMMIT_PREPARED: - return OidIsValid(operation->database) && - operation->prepared_owner == InvalidOid && - operation->prepare_payload_length == 0 && - operation->prepared_at == 0 && gid_end != NULL && - gid_end != operation->prepare_gid && - SCN_VALID(operation->terminal_scn) && - operation->terminal_timestamp != 0 && - !operation->has_tt_delta && binding_seen != 0; - case RF_SIDE_XACT_ABORT_PREPARED: - return OidIsValid(operation->database) && - operation->prepared_owner == InvalidOid && - operation->prepare_payload_length == 0 && - operation->prepared_at == 0 && gid_end != NULL && - gid_end != operation->prepare_gid && - SCN_VALID(operation->terminal_scn) && - operation->terminal_timestamp == 0 && - !operation->has_tt_delta && binding_seen != 0; - default: - return false; + gid_end = memchr(operation->prepare_gid, '\0', sizeof(operation->prepare_gid)); + + switch (operation->kind) { + case RF_SIDE_XACT_COMMIT: + return SCN_VALID(operation->terminal_scn) && operation->terminal_timestamp != 0 + && operation->has_tt_delta + && side_xact_tt_delta_valid(&operation->tt_delta, operation->origin_thread, + operation->xid, operation->terminal_scn) + && binding_seen == 0 && operation->prepared_owner == InvalidOid + && operation->prepare_payload_length == 0 && operation->prepared_at == 0 + && operation->prepare_gid[0] == '\0'; + case RF_SIDE_XACT_ABORT: + return SCN_VALID(operation->terminal_scn) && operation->terminal_timestamp == 0 + && !operation->has_tt_delta && binding_seen == 0 + && operation->prepared_owner == InvalidOid && operation->prepare_payload_length == 0 + && operation->prepared_at == 0 && operation->prepare_gid[0] == '\0'; + case RF_SIDE_XACT_PREPARE: + return OidIsValid(operation->database) && OidIsValid(operation->prepared_owner) + && operation->prepare_payload_length > 0 && gid_end != NULL + && gid_end != operation->prepare_gid && operation->terminal_scn == InvalidScn + && operation->terminal_timestamp == 0 && !operation->has_tt_delta + && binding_seen != 0 && side_xact_prepared_material_valid(operation); + case RF_SIDE_XACT_COMMIT_PREPARED: + return OidIsValid(operation->database) && operation->prepared_owner == InvalidOid + && operation->prepare_payload_length == 0 && operation->prepared_at == 0 + && gid_end != NULL && gid_end != operation->prepare_gid + && SCN_VALID(operation->terminal_scn) && operation->terminal_timestamp != 0 + && !operation->has_tt_delta && binding_seen != 0; + case RF_SIDE_XACT_ABORT_PREPARED: + return OidIsValid(operation->database) && operation->prepared_owner == InvalidOid + && operation->prepare_payload_length == 0 && operation->prepared_at == 0 + && gid_end != NULL && gid_end != operation->prepare_gid + && SCN_VALID(operation->terminal_scn) && operation->terminal_timestamp == 0 + && !operation->has_tt_delta && binding_seen != 0; + default: + return false; } } bool -rf_side_xact_decode_v1(XLogReaderState *record, uint64 system_identifier, - uint16 origin_thread, RfSideXactOperationV1 *out) +rf_side_xact_decode_v1(XLogReaderState *record, uint64 system_identifier, uint16 origin_thread, + RfSideXactOperationV1 *out) { RfSideXactOperationV1 candidate; - uint8 opcode; + uint8 opcode; TransactionId xid; if (out == NULL) return false; memset(out, 0, sizeof(*out)); - if (record == NULL || record->record == NULL || system_identifier == 0 || - origin_thread == 0 || origin_thread > 128 || - XLogRecGetRmid(record) != RM_XACT_ID) + if (record == NULL || record->record == NULL || system_identifier == 0 || origin_thread == 0 + || origin_thread > 128 || XLogRecGetRmid(record) != RM_XACT_ID) return false; memset(&candidate, 0, sizeof(candidate)); candidate.system_identifier = system_identifier; @@ -549,137 +476,119 @@ rf_side_xact_decode_v1(XLogReaderState *record, uint64 system_identifier, opcode = XLogRecGetInfo(record) & XLOG_XACT_OPMASK; xid = XLogRecGetXid(record); - switch (opcode) - { - case XLOG_XACT_COMMIT: - { - xl_xact_parsed_commit parsed; + switch (opcode) { + case XLOG_XACT_COMMIT: { + xl_xact_parsed_commit parsed; - if (!side_xact_completion_shape_valid(record, true) || - !TransactionIdIsNormal(xid)) - return false; - ParseCommitRecord(XLogRecGetInfo(record), - (xl_xact_commit *) XLogRecGetData(record), &parsed); - if (!side_xact_no_commit_effects(&parsed) || - (parsed.xinfo & XACT_XINFO_HAS_TWOPHASE) != 0 || - !SCN_VALID(parsed.scn) || side_xact_commit_timestamp(&parsed) == 0 || - !parsed.has_tt_commit || - !side_xact_tt_delta_valid(&parsed.tt_commit, origin_thread, - xid, parsed.scn)) - return false; - candidate.kind = RF_SIDE_XACT_COMMIT; - candidate.xid = xid; - candidate.database = parsed.dbId; - candidate.xinfo = parsed.xinfo; - candidate.terminal_scn = parsed.scn; - candidate.terminal_timestamp = side_xact_commit_timestamp(&parsed); - candidate.has_tt_delta = true; - candidate.tt_delta = parsed.tt_commit; - break; - } - case XLOG_XACT_ABORT: - { - xl_xact_parsed_abort parsed; + if (!side_xact_completion_shape_valid(record, true) || !TransactionIdIsNormal(xid)) + return false; + ParseCommitRecord(XLogRecGetInfo(record), (xl_xact_commit *)XLogRecGetData(record), + &parsed); + if (!side_xact_no_commit_effects(&parsed) || (parsed.xinfo & XACT_XINFO_HAS_TWOPHASE) != 0 + || !SCN_VALID(parsed.scn) || side_xact_commit_timestamp(&parsed) == 0 + || !parsed.has_tt_commit + || !side_xact_tt_delta_valid(&parsed.tt_commit, origin_thread, xid, parsed.scn)) + return false; + candidate.kind = RF_SIDE_XACT_COMMIT; + candidate.xid = xid; + candidate.database = parsed.dbId; + candidate.xinfo = parsed.xinfo; + candidate.terminal_scn = parsed.scn; + candidate.terminal_timestamp = side_xact_commit_timestamp(&parsed); + candidate.has_tt_delta = true; + candidate.tt_delta = parsed.tt_commit; + break; + } + case XLOG_XACT_ABORT: { + xl_xact_parsed_abort parsed; - if (!side_xact_completion_shape_valid(record, false) || - !TransactionIdIsNormal(xid)) - return false; - ParseAbortRecord(XLogRecGetInfo(record), - (xl_xact_abort *) XLogRecGetData(record), &parsed); - if (!side_xact_no_abort_effects(&parsed) || - (parsed.xinfo & XACT_XINFO_HAS_TWOPHASE) != 0 || - !SCN_VALID(parsed.scn)) - return false; - candidate.kind = RF_SIDE_XACT_ABORT; - candidate.xid = xid; - candidate.database = parsed.dbId; - candidate.xinfo = parsed.xinfo; - candidate.terminal_scn = parsed.scn; - break; - } - case XLOG_XACT_PREPARE: - { - xl_xact_prepare *xlrec; - xl_xact_parsed_prepare parsed; + if (!side_xact_completion_shape_valid(record, false) || !TransactionIdIsNormal(xid)) + return false; + ParseAbortRecord(XLogRecGetInfo(record), (xl_xact_abort *)XLogRecGetData(record), &parsed); + if (!side_xact_no_abort_effects(&parsed) || (parsed.xinfo & XACT_XINFO_HAS_TWOPHASE) != 0 + || !SCN_VALID(parsed.scn)) + return false; + candidate.kind = RF_SIDE_XACT_ABORT; + candidate.xid = xid; + candidate.database = parsed.dbId; + candidate.xinfo = parsed.xinfo; + candidate.terminal_scn = parsed.scn; + break; + } + case XLOG_XACT_PREPARE: { + xl_xact_prepare *xlrec; + xl_xact_parsed_prepare parsed; - if (!side_xact_prepare_shape_valid(record, &candidate)) - return false; - xlrec = (xl_xact_prepare *) XLogRecGetData(record); - ParsePrepareRecord(XLogRecGetInfo(record), xlrec, &parsed); - xid = parsed.twophase_xid; - if (!TransactionIdIsNormal(xid) || !OidIsValid(parsed.dbId) || - parsed.nsubxacts != 0 || parsed.nrels != 0 || - parsed.nabortrels != 0 || parsed.nstats != 0 || - parsed.nabortstats != 0 || parsed.nmsgs != 0 || - xlrec->initfileinval || - !cluster_remote_xact_prepare_digest_v2(system_identifier, - origin_thread - 1, xid, parsed.dbId, parsed.twophase_gid, - candidate.prepare_binding)) - return false; - candidate.kind = RF_SIDE_XACT_PREPARE; - candidate.xid = xid; - candidate.database = parsed.dbId; - break; - } - case XLOG_XACT_COMMIT_PREPARED: - { - xl_xact_parsed_commit parsed; + if (!side_xact_prepare_shape_valid(record, &candidate)) + return false; + xlrec = (xl_xact_prepare *)XLogRecGetData(record); + ParsePrepareRecord(XLogRecGetInfo(record), xlrec, &parsed); + xid = parsed.twophase_xid; + if (!TransactionIdIsNormal(xid) || !OidIsValid(parsed.dbId) || parsed.nsubxacts != 0 + || parsed.nrels != 0 || parsed.nabortrels != 0 || parsed.nstats != 0 + || parsed.nabortstats != 0 || parsed.nmsgs != 0 || xlrec->initfileinval + || !cluster_remote_xact_prepare_digest_v2(system_identifier, origin_thread - 1, xid, + parsed.dbId, parsed.twophase_gid, + candidate.prepare_binding)) + return false; + candidate.kind = RF_SIDE_XACT_PREPARE; + candidate.xid = xid; + candidate.database = parsed.dbId; + break; + } + case XLOG_XACT_COMMIT_PREPARED: { + xl_xact_parsed_commit parsed; - if (!side_xact_completion_shape_valid(record, true)) - return false; - ParseCommitRecord(XLogRecGetInfo(record), - (xl_xact_commit *) XLogRecGetData(record), &parsed); - xid = parsed.twophase_xid; - if (!TransactionIdIsNormal(xid) || !side_xact_no_commit_effects(&parsed) || - (parsed.xinfo & (XACT_XINFO_HAS_TWOPHASE | XACT_XINFO_HAS_GID | - XACT_XINFO_HAS_DBINFO)) != - (XACT_XINFO_HAS_TWOPHASE | XACT_XINFO_HAS_GID | - XACT_XINFO_HAS_DBINFO) || - !SCN_VALID(parsed.scn) || side_xact_commit_timestamp(&parsed) == 0 || - parsed.has_tt_commit || - !cluster_remote_xact_prepare_digest_v2(system_identifier, - origin_thread - 1, xid, parsed.dbId, parsed.twophase_gid, - candidate.prepare_binding)) - return false; - candidate.kind = RF_SIDE_XACT_COMMIT_PREPARED; - candidate.xid = xid; - candidate.database = parsed.dbId; - candidate.xinfo = parsed.xinfo; - candidate.terminal_scn = parsed.scn; - candidate.terminal_timestamp = side_xact_commit_timestamp(&parsed); - strlcpy(candidate.prepare_gid, parsed.twophase_gid, - sizeof(candidate.prepare_gid)); - break; - } - case XLOG_XACT_ABORT_PREPARED: - { - xl_xact_parsed_abort parsed; + if (!side_xact_completion_shape_valid(record, true)) + return false; + ParseCommitRecord(XLogRecGetInfo(record), (xl_xact_commit *)XLogRecGetData(record), + &parsed); + xid = parsed.twophase_xid; + if (!TransactionIdIsNormal(xid) || !side_xact_no_commit_effects(&parsed) + || (parsed.xinfo + & (XACT_XINFO_HAS_TWOPHASE | XACT_XINFO_HAS_GID | XACT_XINFO_HAS_DBINFO)) + != (XACT_XINFO_HAS_TWOPHASE | XACT_XINFO_HAS_GID | XACT_XINFO_HAS_DBINFO) + || !SCN_VALID(parsed.scn) || side_xact_commit_timestamp(&parsed) == 0 + || parsed.has_tt_commit + || !cluster_remote_xact_prepare_digest_v2(system_identifier, origin_thread - 1, xid, + parsed.dbId, parsed.twophase_gid, + candidate.prepare_binding)) + return false; + candidate.kind = RF_SIDE_XACT_COMMIT_PREPARED; + candidate.xid = xid; + candidate.database = parsed.dbId; + candidate.xinfo = parsed.xinfo; + candidate.terminal_scn = parsed.scn; + candidate.terminal_timestamp = side_xact_commit_timestamp(&parsed); + strlcpy(candidate.prepare_gid, parsed.twophase_gid, sizeof(candidate.prepare_gid)); + break; + } + case XLOG_XACT_ABORT_PREPARED: { + xl_xact_parsed_abort parsed; - if (!side_xact_completion_shape_valid(record, false)) - return false; - ParseAbortRecord(XLogRecGetInfo(record), - (xl_xact_abort *) XLogRecGetData(record), &parsed); - xid = parsed.twophase_xid; - if (!TransactionIdIsNormal(xid) || !side_xact_no_abort_effects(&parsed) || - (parsed.xinfo & (XACT_XINFO_HAS_TWOPHASE | XACT_XINFO_HAS_GID | - XACT_XINFO_HAS_DBINFO)) != - (XACT_XINFO_HAS_TWOPHASE | XACT_XINFO_HAS_GID | - XACT_XINFO_HAS_DBINFO) || !SCN_VALID(parsed.scn) || - !cluster_remote_xact_prepare_digest_v2(system_identifier, - origin_thread - 1, xid, parsed.dbId, parsed.twophase_gid, - candidate.prepare_binding)) - return false; - candidate.kind = RF_SIDE_XACT_ABORT_PREPARED; - candidate.xid = xid; - candidate.database = parsed.dbId; - candidate.xinfo = parsed.xinfo; - candidate.terminal_scn = parsed.scn; - strlcpy(candidate.prepare_gid, parsed.twophase_gid, - sizeof(candidate.prepare_gid)); - break; - } - default: + if (!side_xact_completion_shape_valid(record, false)) + return false; + ParseAbortRecord(XLogRecGetInfo(record), (xl_xact_abort *)XLogRecGetData(record), &parsed); + xid = parsed.twophase_xid; + if (!TransactionIdIsNormal(xid) || !side_xact_no_abort_effects(&parsed) + || (parsed.xinfo + & (XACT_XINFO_HAS_TWOPHASE | XACT_XINFO_HAS_GID | XACT_XINFO_HAS_DBINFO)) + != (XACT_XINFO_HAS_TWOPHASE | XACT_XINFO_HAS_GID | XACT_XINFO_HAS_DBINFO) + || !SCN_VALID(parsed.scn) + || !cluster_remote_xact_prepare_digest_v2(system_identifier, origin_thread - 1, xid, + parsed.dbId, parsed.twophase_gid, + candidate.prepare_binding)) return false; + candidate.kind = RF_SIDE_XACT_ABORT_PREPARED; + candidate.xid = xid; + candidate.database = parsed.dbId; + candidate.xinfo = parsed.xinfo; + candidate.terminal_scn = parsed.scn; + strlcpy(candidate.prepare_gid, parsed.twophase_gid, sizeof(candidate.prepare_gid)); + break; + } + default: + return false; } if (!rf_side_xact_structural_preflight_v1(&candidate)) return false; @@ -693,50 +602,46 @@ side_xact_apply_commit_v1(const RfSideXactOperationV1 *operation) ClusterRemoteXactMutationV2 mutation; ClusterRemoteXactOutcome outcome; TimestampTz timestamp; - SCN post_scn; - SCN durable_scn; - uint16 post_wrap; - uint16 durable_segment; - uint16 durable_slot; - uint16 durable_wrap; - bool post_wrap_valid; + SCN post_scn; + SCN durable_scn; + uint16 post_wrap; + uint16 durable_segment; + uint16 durable_slot; + uint16 durable_wrap; + bool post_wrap_valid; /* Canonical TT truth first, using only the frozen typed delta. */ - cluster_tt_durable_redo_stamp_slot_exact(operation->tt_delta.instance, - operation->tt_delta.segment_id, - operation->tt_delta.segment_generation, - operation->tt_delta.slot_offset, - operation->tt_delta.wrap, operation->tt_delta.xid, - operation->tt_delta.commit_scn); + cluster_tt_durable_redo_stamp_slot_exact( + operation->tt_delta.instance, operation->tt_delta.segment_id, + operation->tt_delta.segment_generation, operation->tt_delta.slot_offset, + operation->tt_delta.wrap, operation->tt_delta.xid, operation->tt_delta.commit_scn); if (cluster_tt_slot_durable_resolve_by_xid_origin( - operation->origin_thread - 1, operation->xid, - operation->tt_delta.wrap, &durable_scn, &durable_segment, - &durable_slot, &durable_wrap) != CLUSTER_TT_DURABLE_RESOLVED_SCN || - durable_scn != operation->terminal_scn || - durable_segment != operation->tt_delta.segment_id || - durable_slot != operation->tt_delta.slot_offset || - durable_wrap != operation->tt_delta.wrap) + operation->origin_thread - 1, operation->xid, operation->tt_delta.wrap, &durable_scn, + &durable_segment, &durable_slot, &durable_wrap) + != CLUSTER_TT_DURABLE_RESOLVED_SCN + || durable_scn != operation->terminal_scn + || durable_segment != operation->tt_delta.segment_id + || durable_slot != operation->tt_delta.slot_offset + || durable_wrap != operation->tt_delta.wrap) return RF_SIDE_XACT_APPLY_POST_READ_FAILED; cluster_scn_recovery_replay_observe(operation->terminal_scn); mutation = cluster_remote_xact_store_terminal_v2( - operation->origin_thread - 1, operation->xid, false, NULL, - CLUSTER_REMOTE_XACT_COMMITTED, operation->terminal_scn, - operation->terminal_timestamp, true, operation->tt_delta.wrap); + operation->origin_thread - 1, operation->xid, false, NULL, CLUSTER_REMOTE_XACT_COMMITTED, + operation->terminal_scn, operation->terminal_timestamp, true, operation->tt_delta.wrap); if (mutation == CLUSTER_REMOTE_XACT_MUTATION_CONFLICT) return RF_SIDE_XACT_APPLY_CONFLICT; - if (mutation != CLUSTER_REMOTE_XACT_MUTATION_STORED && - mutation != CLUSTER_REMOTE_XACT_MUTATION_UNCHANGED) + if (mutation != CLUSTER_REMOTE_XACT_MUTATION_STORED + && mutation != CLUSTER_REMOTE_XACT_MUTATION_UNCHANGED) return RF_SIDE_XACT_APPLY_BLOCKED; - outcome = cluster_remote_commit_outcome_ex(operation->origin_thread - 1, - operation->xid, &post_scn, &post_wrap, &post_wrap_valid); - if (outcome != CLUSTER_REMOTE_XACT_COMMITTED || - post_scn != operation->terminal_scn || !post_wrap_valid || - post_wrap != operation->tt_delta.wrap || - !cluster_remote_commit_timestamp(operation->origin_thread - 1, - operation->xid, ×tamp) || - timestamp != operation->terminal_timestamp) + outcome = cluster_remote_commit_outcome_ex(operation->origin_thread - 1, operation->xid, + &post_scn, &post_wrap, &post_wrap_valid); + if (outcome != CLUSTER_REMOTE_XACT_COMMITTED || post_scn != operation->terminal_scn + || !post_wrap_valid || post_wrap != operation->tt_delta.wrap + || !cluster_remote_commit_timestamp(operation->origin_thread - 1, operation->xid, + ×tamp) + || timestamp != operation->terminal_timestamp) return RF_SIDE_XACT_APPLY_POST_READ_FAILED; return RF_SIDE_XACT_APPLY_OK; } @@ -744,53 +649,50 @@ side_xact_apply_commit_v1(const RfSideXactOperationV1 *operation) static RfSideXactApplyResultV1 side_xact_map_pending_result(TwoPhaseRecoveryPendingResult result) { - switch (result) - { - case TWOPHASE_RECOVERY_PENDING_OK: - return RF_SIDE_XACT_APPLY_OK; - case TWOPHASE_RECOVERY_PENDING_CONFLICT: - return RF_SIDE_XACT_APPLY_CONFLICT; - case TWOPHASE_RECOVERY_PENDING_POST_READ_FAILED: - return RF_SIDE_XACT_APPLY_POST_READ_FAILED; - case TWOPHASE_RECOVERY_PENDING_BLOCKED: - default: - return RF_SIDE_XACT_APPLY_BLOCKED; + switch (result) { + case TWOPHASE_RECOVERY_PENDING_OK: + return RF_SIDE_XACT_APPLY_OK; + case TWOPHASE_RECOVERY_PENDING_CONFLICT: + return RF_SIDE_XACT_APPLY_CONFLICT; + case TWOPHASE_RECOVERY_PENDING_POST_READ_FAILED: + return RF_SIDE_XACT_APPLY_POST_READ_FAILED; + case TWOPHASE_RECOVERY_PENDING_BLOCKED: + default: + return RF_SIDE_XACT_APPLY_BLOCKED; } } static RfSideXactApplyResultV1 side_xact_read_prepared_material(const RfSideXactOperationV1 *operation, - RfSideXactOperationV1 *prepared, uint8 **payload_out, - uint32 *payload_length_out) + RfSideXactOperationV1 *prepared, uint8 **payload_out, + uint32 *payload_length_out) { TwoPhaseRecoveryPendingResult pending; - void *payload = NULL; - uint32 payload_length = 0; - uint8 digest[CLUSTER_REMOTE_XACT_PREPARE_DIGEST_BYTES]; + void *payload = NULL; + uint32 payload_length = 0; + uint8 digest[CLUSTER_REMOTE_XACT_PREPARE_DIGEST_BYTES]; if (prepared == NULL || payload_out == NULL || payload_length_out == NULL) return RF_SIDE_XACT_APPLY_BLOCKED; memset(prepared, 0, sizeof(*prepared)); *payload_out = NULL; *payload_length_out = 0; - pending = TwoPhaseRecoveryPendingReadExact(operation->xid, - operation->database, operation->prepare_gid, &payload, - &payload_length); + pending = TwoPhaseRecoveryPendingReadExact(operation->xid, operation->database, + operation->prepare_gid, &payload, &payload_length); if (pending != TWOPHASE_RECOVERY_PENDING_OK) return side_xact_map_pending_result(pending); prepared->system_identifier = operation->system_identifier; prepared->origin_thread = operation->origin_thread; prepared->kind = RF_SIDE_XACT_PREPARE; - if (!side_xact_prepare_payload_valid(payload, payload_length, prepared) || - !TransactionIdEquals(prepared->xid, operation->xid) || - prepared->database != operation->database || - strcmp(prepared->prepare_gid, operation->prepare_gid) != 0 || - !cluster_remote_xact_prepare_digest_v2(operation->system_identifier, - operation->origin_thread - 1, operation->xid, - operation->database, operation->prepare_gid, digest) || - memcmp(digest, operation->prepare_binding, sizeof(digest)) != 0 || - !side_xact_prepared_material_valid(prepared)) - { + if (!side_xact_prepare_payload_valid(payload, payload_length, prepared) + || !TransactionIdEquals(prepared->xid, operation->xid) + || prepared->database != operation->database + || strcmp(prepared->prepare_gid, operation->prepare_gid) != 0 + || !cluster_remote_xact_prepare_digest_v2( + operation->system_identifier, operation->origin_thread - 1, operation->xid, + operation->database, operation->prepare_gid, digest) + || memcmp(digest, operation->prepare_binding, sizeof(digest)) != 0 + || !side_xact_prepared_material_valid(prepared)) { side_xact_payload_free(payload); return RF_SIDE_XACT_APPLY_CONFLICT; } @@ -801,27 +703,23 @@ side_xact_read_prepared_material(const RfSideXactOperationV1 *operation, } static bool -side_xact_prepared_commit_tt_requirements( - const RfSideXactOperationV1 *prepared, SCN terminal_scn, - RfSideXactCommitPreparedRequirementsV1 *requirements) +side_xact_prepared_commit_tt_requirements(const RfSideXactOperationV1 *prepared, SCN terminal_scn, + RfSideXactCommitPreparedRequirementsV1 *requirements) { - uint16 i; + uint16 i; if (requirements == NULL) return false; memset(requirements, 0, sizeof(*requirements)); for (i = 0; i < prepared->prepared_binding_count; i++) - if (cluster_xid_origin_slot(prepared->prepared_bindings[i].xid) != - (int) prepared->origin_thread - 1) + if (cluster_xid_origin_slot(prepared->prepared_bindings[i].xid) + != (int)prepared->origin_thread - 1) return false; requirements->count = prepared->prepared_binding_count; - for (i = 0; i < prepared->prepared_binding_count; i++) - { - const ClusterTT2PCBinding *binding = - &prepared->prepared_bindings[i]; - RfSideXactTTCommitRequirementV1 *requirement = - &requirements->bindings[i]; - TTSlot slot; + for (i = 0; i < prepared->prepared_binding_count; i++) { + const ClusterTT2PCBinding *binding = &prepared->prepared_bindings[i]; + RfSideXactTTCommitRequirementV1 *requirement = &requirements->bindings[i]; + TTSlot slot; requirement->instance = prepared->origin_thread; requirement->segment_id = binding->undo_segment_id; @@ -830,18 +728,15 @@ side_xact_prepared_commit_tt_requirements( requirement->xid = binding->xid; requirement->commit_scn = terminal_scn; if (!cluster_tt_slot_durable_read_exact_stable( - binding->undo_segment_id, binding->slot_offset, binding->xid, - binding->wrap, &slot)) + binding->undo_segment_id, binding->slot_offset, binding->xid, binding->wrap, &slot)) return false; - if (slot.status == TT_SLOT_COMMITTED && - slot.commit_scn == terminal_scn && - UBA_is_invalid(slot.first_undo_block)) + if (slot.status == TT_SLOT_COMMITTED && slot.commit_scn == terminal_scn + && UBA_is_invalid(slot.first_undo_block)) continue; - if (slot.status == TT_SLOT_ACTIVE && - !SCN_VALID(slot.commit_scn) && - memcmp(&slot.first_undo_block, &prepared->prepared_heads[i], - sizeof(slot.first_undo_block)) == 0) - { + if (slot.status == TT_SLOT_ACTIVE && !SCN_VALID(slot.commit_scn) + && memcmp(&slot.first_undo_block, &prepared->prepared_heads[i], + sizeof(slot.first_undo_block)) + == 0) { requirement->requires_apply = true; continue; } @@ -857,37 +752,34 @@ rf_side_xact_commit_prepared_requirements_v1( { RfSideXactOperationV1 prepared; RfSideXactApplyResultV1 result; - uint8 *payload = NULL; - uint32 payload_length = 0; + uint8 *payload = NULL; + uint32 payload_length = 0; if (out_requirements == NULL) return RF_SIDE_XACT_APPLY_BLOCKED; memset(out_requirements, 0, sizeof(*out_requirements)); - if (!rf_side_xact_structural_preflight_v1(operation) || - operation->kind != RF_SIDE_XACT_COMMIT_PREPARED || - operation->system_identifier != GetSystemIdentifier() || - cluster_xid_origin_slot(operation->xid) != - (int) operation->origin_thread - 1) + if (!rf_side_xact_structural_preflight_v1(operation) + || operation->kind != RF_SIDE_XACT_COMMIT_PREPARED + || operation->system_identifier != GetSystemIdentifier() + || cluster_xid_origin_slot(operation->xid) != (int)operation->origin_thread - 1) return RF_SIDE_XACT_APPLY_BLOCKED; - result = side_xact_read_prepared_material(operation, &prepared, &payload, - &payload_length); + result = side_xact_read_prepared_material(operation, &prepared, &payload, &payload_length); if (result != RF_SIDE_XACT_APPLY_OK) return result; - result = side_xact_prepared_commit_tt_requirements(&prepared, - operation->terminal_scn, out_requirements) ? RF_SIDE_XACT_APPLY_OK : - RF_SIDE_XACT_APPLY_BLOCKED; + result = side_xact_prepared_commit_tt_requirements(&prepared, operation->terminal_scn, + out_requirements) + ? RF_SIDE_XACT_APPLY_OK + : RF_SIDE_XACT_APPLY_BLOCKED; side_xact_payload_free(payload); return result; } static RfSideXactApplyResultV1 -side_xact_preflight_commit_prepared( - const RfSideXactOperationV1 *operation) +side_xact_preflight_commit_prepared(const RfSideXactOperationV1 *operation) { RfSideXactCommitPreparedRequirementsV1 requirements; - return rf_side_xact_commit_prepared_requirements_v1(operation, - &requirements); + return rf_side_xact_commit_prepared_requirements_v1(operation, &requirements); } static RfSideXactApplyResultV1 @@ -898,104 +790,88 @@ side_xact_apply_commit_prepared(const RfSideXactOperationV1 *operation) TwoPhaseRecoveryPendingResult pending; ClusterRemoteXactMutationV2 mutation; ClusterRemoteXactOutcome outcome; - uint8 *payload = NULL; - uint32 payload_length = 0; - SCN post_scn; + uint8 *payload = NULL; + uint32 payload_length = 0; + SCN post_scn; TimestampTz post_timestamp; - uint16 post_wrap; - uint16 top_wrap = 0; - bool post_wrap_valid; - uint16 i; + uint16 post_wrap; + uint16 top_wrap = 0; + bool post_wrap_valid; + uint16 i; RfSideXactCommitPreparedRequirementsV1 requirements; - result = side_xact_read_prepared_material(operation, &prepared, &payload, - &payload_length); + result = side_xact_read_prepared_material(operation, &prepared, &payload, &payload_length); if (result != RF_SIDE_XACT_APPLY_OK) return result; - if (!side_xact_prepared_commit_tt_requirements(&prepared, - operation->terminal_scn, &requirements)) - { + if (!side_xact_prepared_commit_tt_requirements(&prepared, operation->terminal_scn, + &requirements)) { side_xact_payload_free(payload); return RF_SIDE_XACT_APPLY_BLOCKED; } for (i = 0; i < requirements.count; i++) - if (requirements.bindings[i].requires_apply) - { + if (requirements.bindings[i].requires_apply) { side_xact_payload_free(payload); return RF_SIDE_XACT_APPLY_BLOCKED; } for (i = 0; i < prepared.prepared_binding_count; i++) - if (TransactionIdEquals(prepared.prepared_bindings[i].xid, - operation->xid)) - { + if (TransactionIdEquals(prepared.prepared_bindings[i].xid, operation->xid)) { top_wrap = prepared.prepared_bindings[i].wrap; break; } - if (top_wrap == 0) - { + if (top_wrap == 0) { side_xact_payload_free(payload); return RF_SIDE_XACT_APPLY_CONFLICT; } cluster_scn_recovery_replay_observe(operation->terminal_scn); mutation = cluster_remote_xact_store_terminal_v2( - operation->origin_thread - 1, operation->xid, true, - operation->prepare_binding, CLUSTER_REMOTE_XACT_COMMITTED, - operation->terminal_scn, operation->terminal_timestamp, true, + operation->origin_thread - 1, operation->xid, true, operation->prepare_binding, + CLUSTER_REMOTE_XACT_COMMITTED, operation->terminal_scn, operation->terminal_timestamp, true, top_wrap); - if (mutation == CLUSTER_REMOTE_XACT_MUTATION_CONFLICT) - { + if (mutation == CLUSTER_REMOTE_XACT_MUTATION_CONFLICT) { side_xact_payload_free(payload); return RF_SIDE_XACT_APPLY_CONFLICT; } - if (mutation != CLUSTER_REMOTE_XACT_MUTATION_STORED && - mutation != CLUSTER_REMOTE_XACT_MUTATION_UNCHANGED) - { + if (mutation != CLUSTER_REMOTE_XACT_MUTATION_STORED + && mutation != CLUSTER_REMOTE_XACT_MUTATION_UNCHANGED) { side_xact_payload_free(payload); return RF_SIDE_XACT_APPLY_BLOCKED; } - outcome = cluster_remote_commit_outcome_ex(operation->origin_thread - 1, - operation->xid, &post_scn, &post_wrap, &post_wrap_valid); - if (outcome != CLUSTER_REMOTE_XACT_COMMITTED || - post_scn != operation->terminal_scn || !post_wrap_valid || - post_wrap != top_wrap || - !cluster_remote_commit_timestamp(operation->origin_thread - 1, - operation->xid, &post_timestamp) || - post_timestamp != operation->terminal_timestamp) - { + outcome = cluster_remote_commit_outcome_ex(operation->origin_thread - 1, operation->xid, + &post_scn, &post_wrap, &post_wrap_valid); + if (outcome != CLUSTER_REMOTE_XACT_COMMITTED || post_scn != operation->terminal_scn + || !post_wrap_valid || post_wrap != top_wrap + || !cluster_remote_commit_timestamp(operation->origin_thread - 1, operation->xid, + &post_timestamp) + || post_timestamp != operation->terminal_timestamp) { side_xact_payload_free(payload); return RF_SIDE_XACT_APPLY_POST_READ_FAILED; } - pending = TwoPhaseRecoveryPendingResolveExact(operation->xid, - operation->database, operation->prepare_gid, payload, payload_length, - true); + pending = TwoPhaseRecoveryPendingResolveExact( + operation->xid, operation->database, operation->prepare_gid, payload, payload_length, true); side_xact_payload_free(payload); return side_xact_map_pending_result(pending); } static bool -side_xact_prepared_abort_tt_requirements( - const RfSideXactOperationV1 *prepared, - RfSideXactAbortPreparedRequirementsV1 *requirements) +side_xact_prepared_abort_tt_requirements(const RfSideXactOperationV1 *prepared, + RfSideXactAbortPreparedRequirementsV1 *requirements) { - uint16 i; + uint16 i; if (requirements == NULL) return false; memset(requirements, 0, sizeof(*requirements)); for (i = 0; i < prepared->prepared_binding_count; i++) - if (cluster_xid_origin_slot(prepared->prepared_bindings[i].xid) != - (int) prepared->origin_thread - 1) + if (cluster_xid_origin_slot(prepared->prepared_bindings[i].xid) + != (int)prepared->origin_thread - 1) return false; requirements->count = prepared->prepared_binding_count; - for (i = 0; i < prepared->prepared_binding_count; i++) - { - const ClusterTT2PCBinding *binding = - &prepared->prepared_bindings[i]; - RfSideXactTTAbortRequirementV1 *requirement = - &requirements->bindings[i]; - TTSlot slot; + for (i = 0; i < prepared->prepared_binding_count; i++) { + const ClusterTT2PCBinding *binding = &prepared->prepared_bindings[i]; + RfSideXactTTAbortRequirementV1 *requirement = &requirements->bindings[i]; + TTSlot slot; /* * RF-SIDE §2.3/§4: a nonempty prepared undo chain needs a @@ -1015,17 +891,15 @@ side_xact_prepared_abort_tt_requirements( requirement->wrap = binding->wrap; requirement->xid = binding->xid; if (!cluster_tt_slot_durable_read_exact_stable( - binding->undo_segment_id, binding->slot_offset, binding->xid, - binding->wrap, &slot)) + binding->undo_segment_id, binding->slot_offset, binding->xid, binding->wrap, &slot)) return false; - if (slot.status == TT_SLOT_ACTIVE && !SCN_VALID(slot.commit_scn) && - UBA_is_invalid(slot.first_undo_block)) - { + if (slot.status == TT_SLOT_ACTIVE && !SCN_VALID(slot.commit_scn) + && UBA_is_invalid(slot.first_undo_block)) { requirement->requires_apply = true; continue; } - if (slot.status == TT_SLOT_ABORTED && !SCN_VALID(slot.commit_scn) && - UBA_is_invalid(slot.first_undo_block)) + if (slot.status == TT_SLOT_ABORTED && !SCN_VALID(slot.commit_scn) + && UBA_is_invalid(slot.first_undo_block)) continue; return false; } @@ -1033,43 +907,38 @@ side_xact_prepared_abort_tt_requirements( } RfSideXactApplyResultV1 -rf_side_xact_abort_prepared_requirements_v1( - const RfSideXactOperationV1 *operation, - RfSideXactAbortPreparedRequirementsV1 *out_requirements) +rf_side_xact_abort_prepared_requirements_v1(const RfSideXactOperationV1 *operation, + RfSideXactAbortPreparedRequirementsV1 *out_requirements) { RfSideXactOperationV1 prepared; RfSideXactApplyResultV1 result; - uint8 *payload = NULL; - uint32 payload_length = 0; + uint8 *payload = NULL; + uint32 payload_length = 0; if (out_requirements == NULL) return RF_SIDE_XACT_APPLY_BLOCKED; memset(out_requirements, 0, sizeof(*out_requirements)); - if (!rf_side_xact_structural_preflight_v1(operation) || - operation->kind != RF_SIDE_XACT_ABORT_PREPARED || - operation->system_identifier != GetSystemIdentifier() || - cluster_xid_origin_slot(operation->xid) != - (int) operation->origin_thread - 1) + if (!rf_side_xact_structural_preflight_v1(operation) + || operation->kind != RF_SIDE_XACT_ABORT_PREPARED + || operation->system_identifier != GetSystemIdentifier() + || cluster_xid_origin_slot(operation->xid) != (int)operation->origin_thread - 1) return RF_SIDE_XACT_APPLY_BLOCKED; - result = side_xact_read_prepared_material(operation, &prepared, &payload, - &payload_length); + result = side_xact_read_prepared_material(operation, &prepared, &payload, &payload_length); if (result != RF_SIDE_XACT_APPLY_OK) return result; - result = side_xact_prepared_abort_tt_requirements(&prepared, - out_requirements) ? RF_SIDE_XACT_APPLY_OK : - RF_SIDE_XACT_APPLY_BLOCKED; + result = side_xact_prepared_abort_tt_requirements(&prepared, out_requirements) + ? RF_SIDE_XACT_APPLY_OK + : RF_SIDE_XACT_APPLY_BLOCKED; side_xact_payload_free(payload); return result; } static RfSideXactApplyResultV1 -side_xact_preflight_abort_prepared( - const RfSideXactOperationV1 *operation) +side_xact_preflight_abort_prepared(const RfSideXactOperationV1 *operation) { RfSideXactAbortPreparedRequirementsV1 requirements; - return rf_side_xact_abort_prepared_requirements_v1(operation, - &requirements); + return rf_side_xact_abort_prepared_requirements_v1(operation, &requirements); } static RfSideXactApplyResultV1 @@ -1080,58 +949,50 @@ side_xact_apply_abort_prepared(const RfSideXactOperationV1 *operation) TwoPhaseRecoveryPendingResult pending; ClusterRemoteXactMutationV2 mutation; ClusterRemoteXactOutcome outcome; - uint8 *payload = NULL; - uint32 payload_length = 0; - SCN post_scn; - uint16 post_wrap; - bool post_wrap_valid; + uint8 *payload = NULL; + uint32 payload_length = 0; + SCN post_scn; + uint16 post_wrap; + bool post_wrap_valid; RfSideXactAbortPreparedRequirementsV1 requirements; - uint16 i; + uint16 i; - result = side_xact_read_prepared_material(operation, &prepared, &payload, - &payload_length); + result = side_xact_read_prepared_material(operation, &prepared, &payload, &payload_length); if (result != RF_SIDE_XACT_APPLY_OK) return result; - if (!side_xact_prepared_abort_tt_requirements(&prepared, &requirements)) - { + if (!side_xact_prepared_abort_tt_requirements(&prepared, &requirements)) { side_xact_payload_free(payload); return RF_SIDE_XACT_APPLY_BLOCKED; } for (i = 0; i < requirements.count; i++) - if (requirements.bindings[i].requires_apply) - { + if (requirements.bindings[i].requires_apply) { side_xact_payload_free(payload); return RF_SIDE_XACT_APPLY_BLOCKED; } cluster_scn_recovery_replay_observe(operation->terminal_scn); mutation = cluster_remote_xact_store_terminal_v2( - operation->origin_thread - 1, operation->xid, true, - operation->prepare_binding, CLUSTER_REMOTE_XACT_ABORTED, InvalidScn, - 0, false, 0); - if (mutation == CLUSTER_REMOTE_XACT_MUTATION_CONFLICT) - { + operation->origin_thread - 1, operation->xid, true, operation->prepare_binding, + CLUSTER_REMOTE_XACT_ABORTED, InvalidScn, 0, false, 0); + if (mutation == CLUSTER_REMOTE_XACT_MUTATION_CONFLICT) { side_xact_payload_free(payload); return RF_SIDE_XACT_APPLY_CONFLICT; } - if (mutation != CLUSTER_REMOTE_XACT_MUTATION_STORED && - mutation != CLUSTER_REMOTE_XACT_MUTATION_UNCHANGED) - { + if (mutation != CLUSTER_REMOTE_XACT_MUTATION_STORED + && mutation != CLUSTER_REMOTE_XACT_MUTATION_UNCHANGED) { side_xact_payload_free(payload); return RF_SIDE_XACT_APPLY_BLOCKED; } - outcome = cluster_remote_commit_outcome_ex(operation->origin_thread - 1, - operation->xid, &post_scn, &post_wrap, &post_wrap_valid); - if (outcome != CLUSTER_REMOTE_XACT_ABORTED || SCN_VALID(post_scn) || - post_wrap_valid) - { + outcome = cluster_remote_commit_outcome_ex(operation->origin_thread - 1, operation->xid, + &post_scn, &post_wrap, &post_wrap_valid); + if (outcome != CLUSTER_REMOTE_XACT_ABORTED || SCN_VALID(post_scn) || post_wrap_valid) { side_xact_payload_free(payload); return RF_SIDE_XACT_APPLY_POST_READ_FAILED; } - pending = TwoPhaseRecoveryPendingResolveExact(operation->xid, - operation->database, operation->prepare_gid, payload, payload_length, - false); + pending = TwoPhaseRecoveryPendingResolveExact(operation->xid, operation->database, + operation->prepare_gid, payload, payload_length, + false); side_xact_payload_free(payload); return side_xact_map_pending_result(pending); } @@ -1139,77 +1000,72 @@ side_xact_apply_abort_prepared(const RfSideXactOperationV1 *operation) static bool side_xact_prepared_tt_undo_exact(const RfSideXactOperationV1 *operation) { - uint16 i; + uint16 i; /* Classify every top/subtransaction origin before the first target read. */ for (i = 0; i < operation->prepared_binding_count; i++) - if (cluster_xid_origin_slot(operation->prepared_bindings[i].xid) != - (int) operation->origin_thread - 1) + if (cluster_xid_origin_slot(operation->prepared_bindings[i].xid) + != (int)operation->origin_thread - 1) return false; - for (i = 0; i < operation->prepared_binding_count; i++) - { - const ClusterTT2PCBinding *binding = - &operation->prepared_bindings[i]; - TTSlot slot; + for (i = 0; i < operation->prepared_binding_count; i++) { + const ClusterTT2PCBinding *binding = &operation->prepared_bindings[i]; + TTSlot slot; if (!cluster_tt_slot_durable_read_exact_stable( - binding->undo_segment_id, binding->slot_offset, - binding->xid, binding->wrap, &slot) || - slot.status != TT_SLOT_ACTIVE || SCN_VALID(slot.commit_scn) || - memcmp(&slot.first_undo_block, &operation->prepared_heads[i], - sizeof(slot.first_undo_block)) != 0) + binding->undo_segment_id, binding->slot_offset, binding->xid, binding->wrap, &slot) + || slot.status != TT_SLOT_ACTIVE || SCN_VALID(slot.commit_scn) + || memcmp(&slot.first_undo_block, &operation->prepared_heads[i], + sizeof(slot.first_undo_block)) + != 0) return false; } return true; } RfSideXactApplyResultV1 -rf_side_xact_target_preflight_owned_v1( - const RfSideXactOperationV1 *operation, const uint8 *owned_payload, - uint32 owned_payload_length) +rf_side_xact_target_preflight_owned_v1(const RfSideXactOperationV1 *operation, + const uint8 *owned_payload, uint32 owned_payload_length) { TwoPhaseRecoveryPendingResult pending; - if (!rf_side_xact_structural_preflight_v1(operation) || - operation->system_identifier != GetSystemIdentifier() || - cluster_xid_origin_slot(operation->xid) != - (int) operation->origin_thread - 1) + if (!rf_side_xact_structural_preflight_v1(operation) + || operation->system_identifier != GetSystemIdentifier() + || cluster_xid_origin_slot(operation->xid) != (int)operation->origin_thread - 1) return RF_SIDE_XACT_APPLY_BLOCKED; if (operation->kind == RF_SIDE_XACT_COMMIT) - return owned_payload == NULL && owned_payload_length == 0 - ? RF_SIDE_XACT_APPLY_OK : RF_SIDE_XACT_APPLY_BLOCKED; + return owned_payload == NULL && owned_payload_length == 0 ? RF_SIDE_XACT_APPLY_OK + : RF_SIDE_XACT_APPLY_BLOCKED; if (operation->kind == RF_SIDE_XACT_COMMIT_PREPARED) return owned_payload == NULL && owned_payload_length == 0 - ? side_xact_preflight_commit_prepared(operation) - : RF_SIDE_XACT_APPLY_BLOCKED; + ? side_xact_preflight_commit_prepared(operation) + : RF_SIDE_XACT_APPLY_BLOCKED; if (operation->kind == RF_SIDE_XACT_ABORT_PREPARED) return owned_payload == NULL && owned_payload_length == 0 - ? side_xact_preflight_abort_prepared(operation) - : RF_SIDE_XACT_APPLY_BLOCKED; - if (operation->kind != RF_SIDE_XACT_PREPARE || owned_payload == NULL || - owned_payload_length != operation->prepare_payload_length || - !side_xact_prepared_tt_undo_exact(operation)) + ? side_xact_preflight_abort_prepared(operation) + : RF_SIDE_XACT_APPLY_BLOCKED; + if (operation->kind != RF_SIDE_XACT_PREPARE || owned_payload == NULL + || owned_payload_length != operation->prepare_payload_length + || !side_xact_prepared_tt_undo_exact(operation)) return RF_SIDE_XACT_APPLY_BLOCKED; - pending = TwoPhaseRecoveryPendingPreflight(operation->xid, - operation->database, operation->prepared_owner, - operation->prepared_at, operation->prepare_gid, owned_payload, - owned_payload_length); + pending = TwoPhaseRecoveryPendingPreflight( + operation->xid, operation->database, operation->prepared_owner, operation->prepared_at, + operation->prepare_gid, owned_payload, owned_payload_length); return side_xact_map_pending_result(pending); } RfSideXactApplyResultV1 -rf_side_xact_apply_owned_v1(const RfSideXactOperationV1 *operation, - const uint8 *owned_payload, uint32 owned_payload_length) +rf_side_xact_apply_owned_v1(const RfSideXactOperationV1 *operation, const uint8 *owned_payload, + uint32 owned_payload_length) { RfSideXactApplyResultV1 preflight; TwoPhaseRecoveryPendingResult pending; ClusterRemoteXactMutationV2 mutation; - preflight = rf_side_xact_target_preflight_owned_v1(operation, - owned_payload, owned_payload_length); + preflight + = rf_side_xact_target_preflight_owned_v1(operation, owned_payload, owned_payload_length); if (preflight != RF_SIDE_XACT_APPLY_OK) return preflight; if (operation->kind == RF_SIDE_XACT_COMMIT) @@ -1225,25 +1081,22 @@ rf_side_xact_apply_owned_v1(const RfSideXactOperationV1 *operation, * projection be materialized; that projection never grants PREPARED, * terminal state, readiness, or OPEN by itself. */ - pending = TwoPhaseRecoveryPendingInstall(operation->xid, - operation->database, operation->prepared_owner, - operation->prepared_at, operation->prepare_gid, owned_payload, - owned_payload_length); + pending = TwoPhaseRecoveryPendingInstall( + operation->xid, operation->database, operation->prepared_owner, operation->prepared_at, + operation->prepare_gid, owned_payload, owned_payload_length); preflight = side_xact_map_pending_result(pending); if (preflight != RF_SIDE_XACT_APPLY_OK) return preflight; - mutation = cluster_remote_xact_store_prepared_v2( - operation->origin_thread - 1, operation->xid, - operation->prepare_binding); + mutation = cluster_remote_xact_store_prepared_v2(operation->origin_thread - 1, operation->xid, + operation->prepare_binding); if (mutation == CLUSTER_REMOTE_XACT_MUTATION_CONFLICT) return RF_SIDE_XACT_APPLY_CONFLICT; - if (mutation != CLUSTER_REMOTE_XACT_MUTATION_STORED && - mutation != CLUSTER_REMOTE_XACT_MUTATION_UNCHANGED) + if (mutation != CLUSTER_REMOTE_XACT_MUTATION_STORED + && mutation != CLUSTER_REMOTE_XACT_MUTATION_UNCHANGED) return RF_SIDE_XACT_APPLY_BLOCKED; - if (!cluster_remote_xact_pending_matches_v2( - operation->origin_thread - 1, operation->xid, - operation->prepare_binding)) + if (!cluster_remote_xact_pending_matches_v2(operation->origin_thread - 1, operation->xid, + operation->prepare_binding)) return RF_SIDE_XACT_APPLY_POST_READ_FAILED; return RF_SIDE_XACT_APPLY_OK; } diff --git a/src/backend/cluster/cluster_startup_phase.c b/src/backend/cluster/cluster_startup_phase.c index 37412864595..21a5bb749da 100644 --- a/src/backend/cluster/cluster_startup_phase.c +++ b/src/backend/cluster/cluster_startup_phase.c @@ -55,11 +55,11 @@ #include "utils/elog.h" #include "utils/timestamp.h" -#include "cluster/cluster_elog.h" /* cluster_phase legacy mirror (HC2) */ +#include "cluster/cluster_elog.h" /* cluster_phase legacy mirror (HC2) */ #include "cluster/cluster_cf_enqueue.h" #include "cluster/cluster_hw_remaster.h" /* contract: worker CF(S) admission */ -#include "cluster/cluster_cf_phase2.h" /* RF-ROOT P6: storage contract verify */ -#include "cluster/cluster_cssd.h" /* cluster_cssd_start / wait_for_ready (2.5 Sprint A) */ +#include "cluster/cluster_cf_phase2.h" /* RF-ROOT P6: storage contract verify */ +#include "cluster/cluster_cssd.h" /* cluster_cssd_start / wait_for_ready (2.5 Sprint A) */ #include "cluster/cluster_qvotec.h" /* cluster_qvotec_start / wait_for_ready (spec-2.6 Step 3 D8) */ #include "cluster/cluster_diag.h" /* cluster_diag_start / wait_for_ready (1.13 Sprint A) */ #include "cluster/cluster_epoch.h" /* cluster_epoch_get_current (RF-ROOT P6 diag) */ @@ -73,10 +73,10 @@ #include "cluster/cluster_membership.h" #include "cluster/cluster_recovery_duty.h" /* live formation witness (RF-ROOT P6) */ #include "cluster/cluster_reconfig.h" -#include "cluster/cluster_scn.h" /* SCN_NODE_ID_VALID (spec-1.16 D13) */ -#include "cluster/cluster_shmem.h" /* cluster_shmem_register_region */ +#include "cluster/cluster_scn.h" /* SCN_NODE_ID_VALID (spec-1.16 D13) */ +#include "cluster/cluster_shmem.h" /* cluster_shmem_register_region */ #include "cluster/cluster_startup_phase.h" -#include "cluster/cluster_wal_state.h" /* spec-4.2 publish_active (phase->RUNNING) */ +#include "cluster/cluster_wal_state.h" /* spec-4.2 publish_active (phase->RUNNING) */ #include "cluster/cluster_wal_retention.h" #include "cluster/cluster_write_fence.h" /* spec-4.12 D6 rejoin self-fence gate (Q5=C) */ #include "storage/proc.h" @@ -159,8 +159,7 @@ cluster_current_phase(void) * a torn value. */ if (cluster_phase_state == NULL) return CLUSTER_PHASE_PRE_INIT; - return (ClusterStartupPhase)pg_atomic_read_u32( - &cluster_phase_state->current_phase); + return (ClusterStartupPhase)pg_atomic_read_u32(&cluster_phase_state->current_phase); } ClusterAuthorityReadiness @@ -171,8 +170,7 @@ cluster_authority_readiness_get(void) * the new value, never a torn mix. */ if (cluster_phase_state == NULL) return CLUSTER_AUTHORITY_OFF; - return (ClusterAuthorityReadiness)pg_atomic_read_u32( - &cluster_phase_state->authority_readiness); + return (ClusterAuthorityReadiness)pg_atomic_read_u32(&cluster_phase_state->authority_readiness); } bool @@ -193,14 +191,13 @@ cluster_authority_binding_copy(ClusterAuthorityBindingLocal *out) if (!cluster_phase_state_lock_acquire(LW_SHARED)) return false; if (pg_atomic_read_u32(&cluster_phase_state->authority_managed) == 0 - || (ClusterAuthorityReadiness)pg_atomic_read_u32( - &cluster_phase_state->authority_readiness) + || (ClusterAuthorityReadiness)pg_atomic_read_u32(&cluster_phase_state->authority_readiness) == CLUSTER_AUTHORITY_OFF) { LWLockRelease(&cluster_phase_state->lwlock); return false; } - out->state = (ClusterAuthorityReadiness)pg_atomic_read_u32( - &cluster_phase_state->authority_readiness); + out->state + = (ClusterAuthorityReadiness)pg_atomic_read_u32(&cluster_phase_state->authority_readiness); out->origin_thread = cluster_phase_state->authority_origin_thread; out->boot_incarnation = cluster_phase_state->authority_boot_incarnation; out->lms_generation = cluster_phase_state->authority_lms_generation; @@ -211,9 +208,8 @@ cluster_authority_binding_copy(ClusterAuthorityBindingLocal *out) } static bool -cluster_authority_clear_matching_internal( - const ClusterAuthorityBindingLocal *binding, const char *caller, - bool preserve_handoff_identity) +cluster_authority_clear_matching_internal(const ClusterAuthorityBindingLocal *binding, + const char *caller, bool preserve_handoff_identity) { bool cleared = false; @@ -222,20 +218,18 @@ cluster_authority_clear_matching_internal( if (!cluster_phase_state_lock_acquire(LW_EXCLUSIVE)) return false; if (pg_atomic_read_u32(&cluster_phase_state->authority_managed) != 0 - && (ClusterAuthorityReadiness)pg_atomic_read_u32( - &cluster_phase_state->authority_readiness) == binding->state - && cluster_phase_state->authority_origin_thread - == binding->origin_thread - && cluster_phase_state->authority_boot_incarnation - == binding->boot_incarnation - && cluster_phase_state->authority_lms_generation - == binding->lms_generation - && memcmp(&cluster_phase_state->authority_fence, - &binding->authority, sizeof(binding->authority)) == 0 - && memcmp(&cluster_phase_state->authority_formation, - &binding->formation, sizeof(binding->formation)) == 0) { - pg_atomic_write_u32(&cluster_phase_state->authority_readiness, - CLUSTER_AUTHORITY_OFF); + && (ClusterAuthorityReadiness)pg_atomic_read_u32(&cluster_phase_state->authority_readiness) + == binding->state + && cluster_phase_state->authority_origin_thread == binding->origin_thread + && cluster_phase_state->authority_boot_incarnation == binding->boot_incarnation + && cluster_phase_state->authority_lms_generation == binding->lms_generation + && memcmp(&cluster_phase_state->authority_fence, &binding->authority, + sizeof(binding->authority)) + == 0 + && memcmp(&cluster_phase_state->authority_formation, &binding->formation, + sizeof(binding->formation)) + == 0) { + pg_atomic_write_u32(&cluster_phase_state->authority_readiness, CLUSTER_AUTHORITY_OFF); /* Managed is a boot-lifetime fail-closed latch. Losing a bound * generation invalidates readiness; it must never reactivate the * legacy one-dimensional LMS/native fallback in the same postmaster. */ @@ -251,12 +245,11 @@ cluster_authority_clear_matching_internal( if (preserve_handoff_identity) { int32 origin_node = (int32)binding->origin_thread - 1; - cluster_phase_state->authority_formation.membership - .membership_state[origin_node] = CLUSTER_MEMBER_MEMBER; + cluster_phase_state->authority_formation.membership.membership_state[origin_node] + = CLUSTER_MEMBER_MEMBER; cluster_phase_state->authority_formation.membership .last_admitted_incarnation[origin_node] - = binding->formation.membership - .last_admitted_incarnation[origin_node]; + = binding->formation.membership.last_admitted_incarnation[origin_node]; } cleared = true; } @@ -265,11 +258,9 @@ cluster_authority_clear_matching_internal( } static bool -cluster_authority_clear_matching(const ClusterAuthorityBindingLocal *binding, - const char *caller) +cluster_authority_clear_matching(const ClusterAuthorityBindingLocal *binding, const char *caller) { - return cluster_authority_clear_matching_internal( - binding, caller, false); + return cluster_authority_clear_matching_internal(binding, caller, false); } /* The exact pivot clears authority readiness and every authority-bearing @@ -277,16 +268,14 @@ cluster_authority_clear_matching(const ClusterAuthorityBindingLocal *binding, * phase-state storage. OFF remains non-authoritative; the carrier exists * solely so the forked LMON can reject floor or incarnation drift. */ static bool -cluster_authority_clear_matching_for_handoff( - const ClusterAuthorityBindingLocal *binding) +cluster_authority_clear_matching_for_handoff(const ClusterAuthorityBindingLocal *binding) { - return cluster_authority_clear_matching_internal( - binding, "phase3_join_readonly_pivot", true); + return cluster_authority_clear_matching_internal(binding, "phase3_join_readonly_pivot", true); } bool -cluster_authority_handoff_identity_current( - uint64 expected_self_incarnation, uint64 expected_predecessor_floor) +cluster_authority_handoff_identity_current(uint64 expected_self_incarnation, + uint64 expected_predecessor_floor) { ClusterFenceAuthorityProof zero_fence; bool current = false; @@ -301,20 +290,16 @@ cluster_authority_handoff_identity_current( memset(&zero_fence, 0, sizeof(zero_fence)); if (origin_node >= 0 && origin_node < CLUSTER_MAX_NODES && pg_atomic_read_u32(&cluster_phase_state->authority_managed) != 0 - && (ClusterAuthorityReadiness)pg_atomic_read_u32( - &cluster_phase_state->authority_readiness) + && (ClusterAuthorityReadiness)pg_atomic_read_u32(&cluster_phase_state->authority_readiness) == CLUSTER_AUTHORITY_OFF - && cluster_phase_state->authority_origin_thread - == (uint16)(origin_node + 1) - && cluster_phase_state->authority_boot_incarnation - == expected_self_incarnation + && cluster_phase_state->authority_origin_thread == (uint16)(origin_node + 1) + && cluster_phase_state->authority_boot_incarnation == expected_self_incarnation && cluster_phase_state->authority_lms_generation == 0 - && memcmp(&cluster_phase_state->authority_fence, &zero_fence, - sizeof(zero_fence)) == 0 - && cluster_phase_state->authority_formation.membership - .membership_state[origin_node] == CLUSTER_MEMBER_MEMBER + && memcmp(&cluster_phase_state->authority_fence, &zero_fence, sizeof(zero_fence)) == 0 + && cluster_phase_state->authority_formation.membership.membership_state[origin_node] + == CLUSTER_MEMBER_MEMBER && cluster_phase_state->authority_formation.membership - .last_admitted_incarnation[origin_node] + .last_admitted_incarnation[origin_node] == expected_predecessor_floor) current = true; LWLockRelease(&cluster_phase_state->lwlock); @@ -328,15 +313,13 @@ cluster_authority_readiness_clear(void) return; if (!cluster_phase_state_lock_acquire(LW_EXCLUSIVE)) return; - pg_atomic_write_u32(&cluster_phase_state->authority_readiness, - CLUSTER_AUTHORITY_OFF); + pg_atomic_write_u32(&cluster_phase_state->authority_readiness, CLUSTER_AUTHORITY_OFF); /* Preserve authority_managed once set; shmem reinitialization is the only * transition back to an unmanaged boot. */ cluster_phase_state->authority_origin_thread = 0; cluster_phase_state->authority_boot_incarnation = 0; cluster_phase_state->authority_lms_generation = 0; - memset(&cluster_phase_state->authority_fence, 0, - sizeof(cluster_phase_state->authority_fence)); + memset(&cluster_phase_state->authority_fence, 0, sizeof(cluster_phase_state->authority_fence)); memset(&cluster_phase_state->authority_formation, 0, sizeof(cluster_phase_state->authority_formation)); LWLockRelease(&cluster_phase_state->lwlock); @@ -348,13 +331,11 @@ cluster_authority_setup_phase_current(void) ClusterStartupPhase phase = cluster_current_phase(); return phase == CLUSTER_PHASE_3_RECOVERY - || (phase == CLUSTER_PHASE_4_NORMAL - && phase3_join_readonly_deferred); + || (phase == CLUSTER_PHASE_4_NORMAL && phase3_join_readonly_deferred); } static bool -cluster_authority_binding_preseal_current( - const ClusterAuthorityBindingLocal *binding) +cluster_authority_binding_preseal_current(const ClusterAuthorityBindingLocal *binding) { uint64 formation_floor; uint64 live_floor; @@ -362,29 +343,25 @@ cluster_authority_binding_preseal_current( if (binding == NULL || binding->origin_thread == 0 || binding->origin_thread > CLUSTER_MAX_NODES) return false; - formation_floor = binding->formation.membership - .last_admitted_incarnation[binding->origin_thread - 1]; - live_floor = cluster_membership_get_last_admitted_incarnation( - cluster_node_id); - return binding != NULL && binding->boot_incarnation != 0 - && binding->lms_generation != 0 - && cluster_authority_setup_phase_current() - && cluster_cssd_get_status() == CLUSTER_CSSD_READY - && cluster_qvotec_get_status() == CLUSTER_QVOTEC_READY - && cluster_qvotec_in_quorum() - && cluster_qvotec_get_self_incarnation() == binding->boot_incarnation - && binding->formation.membership - .membership_state[binding->origin_thread - 1] - == CLUSTER_MEMBER_MEMBER - && formation_floor == live_floor - && (live_floor == binding->boot_incarnation - || (!cluster_reconfig_self_join_admitted() - && live_floor < binding->boot_incarnation)) - && cluster_lms_get_lms_restart_generation() == binding->lms_generation - && cluster_lms_is_recovery_ready() - && cluster_formation_classification_revalidate_nowait( - binding->origin_thread, &binding->authority, - &binding->formation) == CLUSTER_FORMATION_WITNESS_READY; + formation_floor + = binding->formation.membership.last_admitted_incarnation[binding->origin_thread - 1]; + live_floor = cluster_membership_get_last_admitted_incarnation(cluster_node_id); + return binding != NULL && binding->boot_incarnation != 0 && binding->lms_generation != 0 + && cluster_authority_setup_phase_current() + && cluster_cssd_get_status() == CLUSTER_CSSD_READY + && cluster_qvotec_get_status() == CLUSTER_QVOTEC_READY && cluster_qvotec_in_quorum() + && cluster_qvotec_get_self_incarnation() == binding->boot_incarnation + && binding->formation.membership.membership_state[binding->origin_thread - 1] + == CLUSTER_MEMBER_MEMBER + && formation_floor == live_floor + && (live_floor == binding->boot_incarnation + || (!cluster_reconfig_self_join_admitted() + && live_floor < binding->boot_incarnation)) + && cluster_lms_get_lms_restart_generation() == binding->lms_generation + && cluster_lms_is_recovery_ready() + && cluster_formation_classification_revalidate_nowait( + binding->origin_thread, &binding->authority, &binding->formation) + == CLUSTER_FORMATION_WITNESS_READY; } /* A sealed serving generation must continue to match the live formation, but @@ -396,10 +373,8 @@ cluster_serving_formation_current(const ClusterAuthorityBindingLocal *binding) ClusterFormationSnapshotV1 current; return binding != NULL && cluster_reconfig_self_join_admitted() - && cluster_reconfig_capture_formation_snapshot_v1( - binding->origin_thread, ¤t) - && cluster_formation_snapshot_matches_v1( - &binding->formation, ¤t); + && cluster_reconfig_capture_formation_snapshot_v1(binding->origin_thread, ¤t) + && cluster_formation_snapshot_matches_v1(&binding->formation, ¤t); } /* The formation and GRD seal may be replaced only by LMON after the ordinary @@ -410,19 +385,16 @@ cluster_serving_generation_current(const ClusterAuthorityBindingLocal *binding) { ClusterStartupPhase phase = cluster_current_phase(); - return binding != NULL - && binding->state == CLUSTER_AUTHORITY_SERVING_READY - && binding->boot_incarnation != 0 - && binding->lms_generation != 0 - && phase >= CLUSTER_PHASE_4_NORMAL && phase < CLUSTER_PHASE_SHUTDOWN - && cluster_cssd_get_status() == CLUSTER_CSSD_READY - && cluster_qvotec_get_status() == CLUSTER_QVOTEC_READY - && cluster_qvotec_in_quorum() - && cluster_qvotec_get_self_incarnation() == binding->boot_incarnation - && cluster_membership_get_last_admitted_incarnation(cluster_node_id) - == binding->boot_incarnation - && cluster_lms_get_lms_restart_generation() == binding->lms_generation - && cluster_lms_is_ready(); + return binding != NULL && binding->state == CLUSTER_AUTHORITY_SERVING_READY + && binding->boot_incarnation != 0 && binding->lms_generation != 0 + && phase >= CLUSTER_PHASE_4_NORMAL && phase < CLUSTER_PHASE_SHUTDOWN + && cluster_cssd_get_status() == CLUSTER_CSSD_READY + && cluster_qvotec_get_status() == CLUSTER_QVOTEC_READY && cluster_qvotec_in_quorum() + && cluster_qvotec_get_self_incarnation() == binding->boot_incarnation + && cluster_membership_get_last_admitted_incarnation(cluster_node_id) + == binding->boot_incarnation + && cluster_lms_get_lms_restart_generation() == binding->lms_generation + && cluster_lms_is_ready(); } /* AD-023 §3: component drift (CSSD/QVOTEC/quorum/incarnation/formation/LMS @@ -431,99 +403,85 @@ cluster_serving_generation_current(const ClusterAuthorityBindingLocal *binding) * allowlist phase gate rejected this request" from "the binding itself is * stale". */ static bool -cluster_authority_binding_components_current_internal( - const ClusterAuthorityBindingLocal *binding, bool serving, bool require_seal, - bool require_member) +cluster_authority_binding_components_current_internal(const ClusterAuthorityBindingLocal *binding, + bool serving, bool require_seal, + bool require_member) { - if (binding == NULL || binding->boot_incarnation == 0 - || binding->lms_generation == 0 + if (binding == NULL || binding->boot_incarnation == 0 || binding->lms_generation == 0 || cluster_cssd_get_status() != CLUSTER_CSSD_READY - || cluster_qvotec_get_status() != CLUSTER_QVOTEC_READY - || !cluster_qvotec_in_quorum() + || cluster_qvotec_get_status() != CLUSTER_QVOTEC_READY || !cluster_qvotec_in_quorum() || cluster_qvotec_get_self_incarnation() != binding->boot_incarnation || cluster_membership_get_last_admitted_incarnation(cluster_node_id) != binding->boot_incarnation || cluster_lms_get_lms_restart_generation() != binding->lms_generation || (require_member && !cluster_membership_is_member(cluster_node_id)) - || (serving - ? !cluster_serving_formation_current(binding) - : cluster_formation_classification_revalidate_nowait( - binding->origin_thread, &binding->authority, - &binding->formation) - != CLUSTER_FORMATION_WITNESS_READY) + || (serving ? !cluster_serving_formation_current(binding) + : cluster_formation_classification_revalidate_nowait( + binding->origin_thread, &binding->authority, &binding->formation) + != CLUSTER_FORMATION_WITNESS_READY) || (require_seal - && !cluster_grd_recovery_authority_is_current( - binding->boot_incarnation, binding->lms_generation))) + && !cluster_grd_recovery_authority_is_current(binding->boot_incarnation, + binding->lms_generation))) return false; return true; } static bool -cluster_authority_binding_components_current( - const ClusterAuthorityBindingLocal *binding, bool serving) +cluster_authority_binding_components_current(const ClusterAuthorityBindingLocal *binding, + bool serving) { - return cluster_authority_binding_components_current_internal( - binding, serving, true, true); + return cluster_authority_binding_components_current_internal(binding, serving, true, true); } static bool -cluster_authority_binding_external_current( - const ClusterAuthorityBindingLocal *binding, bool serving) +cluster_authority_binding_external_current(const ClusterAuthorityBindingLocal *binding, + bool serving) { ClusterStartupPhase phase = cluster_current_phase(); if (!cluster_authority_binding_components_current(binding, serving)) return false; if (serving) - return binding->state == CLUSTER_AUTHORITY_SERVING_READY - && phase >= CLUSTER_PHASE_4_NORMAL && phase < CLUSTER_PHASE_SHUTDOWN - && cluster_lms_is_ready(); - return binding->state == CLUSTER_AUTHORITY_RECOVERY_READY - && phase == CLUSTER_PHASE_3_RECOVERY - && cluster_lms_is_recovery_ready(); + return binding->state == CLUSTER_AUTHORITY_SERVING_READY && phase >= CLUSTER_PHASE_4_NORMAL + && phase < CLUSTER_PHASE_SHUTDOWN && cluster_lms_is_ready(); + return binding->state == CLUSTER_AUTHORITY_RECOVERY_READY && phase == CLUSTER_PHASE_3_RECOVERY + && cluster_lms_is_recovery_ready(); } bool -cluster_authority_readiness_begin( - uint16 origin_thread, const ClusterFenceAuthorityProof *authority, - const ClusterFormationSnapshotV1 *formation) +cluster_authority_readiness_begin(uint16 origin_thread, const ClusterFenceAuthorityProof *authority, + const ClusterFormationSnapshotV1 *formation) { uint64 boot_incarnation; uint64 formation_floor; uint64 live_floor; int32 origin_node; - if (cluster_phase_state == NULL || authority == NULL || formation == NULL - || origin_thread == 0 || origin_thread > CLUSTER_MAX_NODES - || !cluster_authority_setup_phase_current()) + if (cluster_phase_state == NULL || authority == NULL || formation == NULL || origin_thread == 0 + || origin_thread > CLUSTER_MAX_NODES || !cluster_authority_setup_phase_current()) return false; origin_node = (int32)origin_thread - 1; boot_incarnation = cluster_qvotec_get_self_incarnation(); - formation_floor - = formation->membership.last_admitted_incarnation[origin_node]; + formation_floor = formation->membership.last_admitted_incarnation[origin_node]; live_floor = cluster_membership_get_last_admitted_incarnation(origin_node); if (origin_node != cluster_node_id || boot_incarnation == 0 - || formation->membership.membership_state[origin_node] - != CLUSTER_MEMBER_MEMBER + || formation->membership.membership_state[origin_node] != CLUSTER_MEMBER_MEMBER || formation_floor != live_floor || (live_floor != boot_incarnation - && (cluster_reconfig_self_join_admitted() - || live_floor >= boot_incarnation)) - || cluster_formation_classification_revalidate_nowait( - origin_thread, authority, formation) != CLUSTER_FORMATION_WITNESS_READY) + && (cluster_reconfig_self_join_admitted() || live_floor >= boot_incarnation)) + || cluster_formation_classification_revalidate_nowait(origin_thread, authority, formation) + != CLUSTER_FORMATION_WITNESS_READY) return false; if (!cluster_phase_state_lock_acquire(LW_EXCLUSIVE)) return false; - if ((ClusterAuthorityReadiness)pg_atomic_read_u32( - &cluster_phase_state->authority_readiness) + if ((ClusterAuthorityReadiness)pg_atomic_read_u32(&cluster_phase_state->authority_readiness) != CLUSTER_AUTHORITY_OFF) { LWLockRelease(&cluster_phase_state->lwlock); return false; } pg_atomic_write_u32(&cluster_phase_state->authority_managed, 1); - pg_atomic_write_u32(&cluster_phase_state->authority_readiness, - CLUSTER_AUTHORITY_STARTING); + pg_atomic_write_u32(&cluster_phase_state->authority_readiness, CLUSTER_AUTHORITY_STARTING); cluster_phase_state->authority_origin_thread = origin_thread; cluster_phase_state->authority_boot_incarnation = boot_incarnation; cluster_phase_state->authority_lms_generation = 0; @@ -546,13 +504,11 @@ cluster_authority_readiness_bind_recovery_generation(uint64 lms_generation) return false; } if (pg_atomic_read_u32(&cluster_phase_state->authority_managed) == 0 - || (ClusterAuthorityReadiness)pg_atomic_read_u32( - &cluster_phase_state->authority_readiness) + || (ClusterAuthorityReadiness)pg_atomic_read_u32(&cluster_phase_state->authority_readiness) != CLUSTER_AUTHORITY_STARTING || !cluster_authority_setup_phase_current() || (cluster_phase_state->authority_lms_generation != 0 - && cluster_phase_state->authority_lms_generation - != lms_generation)) { + && cluster_phase_state->authority_lms_generation != lms_generation)) { LWLockRelease(&cluster_phase_state->lwlock); return false; } @@ -563,7 +519,7 @@ cluster_authority_readiness_bind_recovery_generation(uint64 lms_generation) return false; } valid = binding.state == CLUSTER_AUTHORITY_STARTING - && cluster_authority_binding_preseal_current(&binding); + && cluster_authority_binding_preseal_current(&binding); if (!valid && cluster_authority_binding_copy(&binding)) { cluster_authority_clear_matching(&binding, "bind_preseal_fail"); } @@ -581,8 +537,7 @@ cluster_authority_readiness_publish_recovery(uint64 lms_generation) if (!cluster_phase_state_lock_acquire(LW_EXCLUSIVE)) return false; if (pg_atomic_read_u32(&cluster_phase_state->authority_managed) == 0 - || (ClusterAuthorityReadiness)pg_atomic_read_u32( - &cluster_phase_state->authority_readiness) + || (ClusterAuthorityReadiness)pg_atomic_read_u32(&cluster_phase_state->authority_readiness) != CLUSTER_AUTHORITY_STARTING || !cluster_authority_setup_phase_current()) { LWLockRelease(&cluster_phase_state->lwlock); @@ -598,29 +553,25 @@ cluster_authority_readiness_publish_recovery(uint64 lms_generation) * below instead of the steady recovery predicate. */ if (!cluster_authority_binding_copy(&binding)) return false; - valid = binding.state == CLUSTER_AUTHORITY_STARTING - && cluster_authority_setup_phase_current() - && cluster_cssd_get_status() == CLUSTER_CSSD_READY - && cluster_qvotec_get_status() == CLUSTER_QVOTEC_READY - && cluster_qvotec_in_quorum() - && cluster_qvotec_get_self_incarnation() == binding.boot_incarnation - && cluster_membership_get_last_admitted_incarnation(cluster_node_id) - == binding.boot_incarnation - && cluster_lms_get_lms_restart_generation() == lms_generation - && cluster_lms_is_recovery_ready() - && cluster_formation_classification_revalidate_nowait( - binding.origin_thread, &binding.authority, - &binding.formation) == CLUSTER_FORMATION_WITNESS_READY - && cluster_grd_recovery_authority_is_current( - binding.boot_incarnation, lms_generation); + valid = binding.state == CLUSTER_AUTHORITY_STARTING && cluster_authority_setup_phase_current() + && cluster_cssd_get_status() == CLUSTER_CSSD_READY + && cluster_qvotec_get_status() == CLUSTER_QVOTEC_READY && cluster_qvotec_in_quorum() + && cluster_qvotec_get_self_incarnation() == binding.boot_incarnation + && cluster_membership_get_last_admitted_incarnation(cluster_node_id) + == binding.boot_incarnation + && cluster_lms_get_lms_restart_generation() == lms_generation + && cluster_lms_is_recovery_ready() + && cluster_formation_classification_revalidate_nowait( + binding.origin_thread, &binding.authority, &binding.formation) + == CLUSTER_FORMATION_WITNESS_READY + && cluster_grd_recovery_authority_is_current(binding.boot_incarnation, lms_generation); if (!valid) { cluster_authority_clear_matching(&binding, "publish_recovery_fail"); return false; } if (!cluster_phase_state_lock_acquire(LW_EXCLUSIVE)) return false; - if ((ClusterAuthorityReadiness)pg_atomic_read_u32( - &cluster_phase_state->authority_readiness) + if ((ClusterAuthorityReadiness)pg_atomic_read_u32(&cluster_phase_state->authority_readiness) == CLUSTER_AUTHORITY_STARTING && cluster_phase_state->authority_lms_generation == lms_generation) pg_atomic_write_u32(&cluster_phase_state->authority_readiness, @@ -662,10 +613,8 @@ cluster_recovery_transport_is_current(void) * bound generation that drifted from the live formation is * genuinely stale. */ - if (cluster_authority_setup_phase_current() - && binding.lms_generation != 0) - cluster_authority_clear_matching(&binding, - "recovery_transport_stale"); + if (cluster_authority_setup_phase_current() && binding.lms_generation != 0) + cluster_authority_clear_matching(&binding, "recovery_transport_stale"); } return current; } @@ -723,24 +672,18 @@ cluster_recovery_transport_components_current(void) bool boot_ok = binding.boot_incarnation != 0; bool lmsgen_ok = binding.lms_generation != 0; bool cssd_ok = cluster_cssd_get_status() == CLUSTER_CSSD_READY; - bool qvotec_ok = cluster_qvotec_get_status() - == CLUSTER_QVOTEC_READY; + bool qvotec_ok = cluster_qvotec_get_status() == CLUSTER_QVOTEC_READY; bool quorum_ok = cluster_qvotec_in_quorum(); - bool inc_ok = cluster_qvotec_get_self_incarnation() - == binding.boot_incarnation; - bool admitted_ok - = cluster_membership_get_last_admitted_incarnation( - cluster_node_id) - == binding.boot_incarnation; - bool lms_match_ok = cluster_lms_get_lms_restart_generation() - == binding.lms_generation; + bool inc_ok = cluster_qvotec_get_self_incarnation() == binding.boot_incarnation; + bool admitted_ok = cluster_membership_get_last_admitted_incarnation(cluster_node_id) + == binding.boot_incarnation; + bool lms_match_ok = cluster_lms_get_lms_restart_generation() == binding.lms_generation; bool lms_rcv_ok = cluster_lms_is_recovery_ready(); bool member_ok = cluster_membership_is_member(cluster_node_id) - || cluster_reconfig_self_join_admitted(); + || cluster_reconfig_self_join_admitted(); - return boot_ok && lmsgen_ok && cssd_ok && qvotec_ok && quorum_ok - && inc_ok && admitted_ok && lms_match_ok && lms_rcv_ok - && member_ok; + return boot_ok && lmsgen_ok && cssd_ok && qvotec_ok && quorum_ok && inc_ok && admitted_ok + && lms_match_ok && lms_rcv_ok && member_ok; } return false; } @@ -766,8 +709,7 @@ cluster_recovery_authority_is_current(void) * (begin() is phase-3 gated), guaranteeing the phase4 * serving-publication timeout. */ if (!cluster_authority_binding_components_current(&binding, false)) - cluster_authority_clear_matching(&binding, - "recovery_authority_stale"); + cluster_authority_clear_matching(&binding, "recovery_authority_stale"); } return current; } @@ -796,43 +738,38 @@ cluster_authority_readiness_publish_serving(void) qvotec_ready = cluster_qvotec_get_status() == CLUSTER_QVOTEC_READY; in_quorum = cluster_qvotec_in_quorum(); self_incarnation = cluster_qvotec_get_self_incarnation(); - admitted_incarnation - = cluster_membership_get_last_admitted_incarnation(cluster_node_id); + admitted_incarnation = cluster_membership_get_last_admitted_incarnation(cluster_node_id); lms_generation = cluster_lms_get_lms_restart_generation(); lms_ready = cluster_lms_is_ready(); formation_result = cluster_formation_classification_revalidate_nowait( binding.origin_thread, &binding.authority, &binding.formation); - grd_current = cluster_grd_recovery_authority_is_current( - binding.boot_incarnation, binding.lms_generation); - valid = cssd_ready && qvotec_ready && in_quorum - && self_incarnation == binding.boot_incarnation - && admitted_incarnation == binding.boot_incarnation - && lms_generation == binding.lms_generation && lms_ready - && formation_result == CLUSTER_FORMATION_WITNESS_READY - && grd_current && cluster_reconfig_self_join_admitted(); + grd_current = cluster_grd_recovery_authority_is_current(binding.boot_incarnation, + binding.lms_generation); + valid = cssd_ready && qvotec_ready && in_quorum && self_incarnation == binding.boot_incarnation + && admitted_incarnation == binding.boot_incarnation + && lms_generation == binding.lms_generation && lms_ready + && formation_result == CLUSTER_FORMATION_WITNESS_READY && grd_current + && cluster_reconfig_self_join_admitted(); if (!valid) { - ereport(LOG, - (errmsg("cluster phase 4: serving authority diagnostic"), - errdetail("cssd_ready=%d qvotec_ready=%d in_quorum=%d " - "self_incarnation=%llu/%llu admitted_incarnation=%llu " - "lms_generation=%llu/%llu lms_ready=%d formation_result=%d " - "grd_current=%d", - cssd_ready, qvotec_ready, in_quorum, - (unsigned long long)self_incarnation, - (unsigned long long)binding.boot_incarnation, - (unsigned long long)admitted_incarnation, - (unsigned long long)lms_generation, - (unsigned long long)binding.lms_generation, - lms_ready, (int)formation_result, grd_current))); + ereport( + LOG, + (errmsg("cluster phase 4: serving authority diagnostic"), + errdetail("cssd_ready=%d qvotec_ready=%d in_quorum=%d " + "self_incarnation=%llu/%llu admitted_incarnation=%llu " + "lms_generation=%llu/%llu lms_ready=%d formation_result=%d " + "grd_current=%d", + cssd_ready, qvotec_ready, in_quorum, (unsigned long long)self_incarnation, + (unsigned long long)binding.boot_incarnation, + (unsigned long long)admitted_incarnation, (unsigned long long)lms_generation, + (unsigned long long)binding.lms_generation, lms_ready, (int)formation_result, + grd_current))); cluster_authority_clear_matching(&binding, "publish_serving_stale"); return false; } LWLockAcquire(&cluster_phase_state->lwlock, LW_EXCLUSIVE); - if ((ClusterAuthorityReadiness)pg_atomic_read_u32( - &cluster_phase_state->authority_readiness) + if ((ClusterAuthorityReadiness)pg_atomic_read_u32(&cluster_phase_state->authority_readiness) == CLUSTER_AUTHORITY_RECOVERY_READY - && cluster_phase_state->authority_lms_generation - == binding.lms_generation) + && cluster_phase_state->authority_lms_generation == binding.lms_generation) pg_atomic_write_u32(&cluster_phase_state->authority_readiness, CLUSTER_AUTHORITY_SERVING_READY); else @@ -885,37 +822,30 @@ cluster_authority_serving_rebind_lmon(void) if (ext_cur) return true; gen_cur = cluster_serving_generation_current(&binding); - capture_ok = cluster_reconfig_capture_formation_snapshot_v1( - binding.origin_thread, ¤t); - moved = capture_ok - && !cluster_formation_snapshot_matches_v1( - &binding.formation, ¤t); + capture_ok = cluster_reconfig_capture_formation_snapshot_v1(binding.origin_thread, ¤t); + moved = capture_ok && !cluster_formation_snapshot_matches_v1(&binding.formation, ¤t); if (!gen_cur || !capture_ok || !moved) return false; /* The GRD helper accepts only the exact event already closed by the ordinary * LMON P0-P7 recovery driver; it does not start a second barrier. */ - grd_rebind_ok = cluster_grd_serving_authority_rebind_lmon( - ¤t, binding.boot_incarnation, binding.lms_generation); - verify_ok = cluster_reconfig_capture_formation_snapshot_v1( - binding.origin_thread, &verify) - && memcmp(¤t, &verify, sizeof(current)) == 0; + grd_rebind_ok = cluster_grd_serving_authority_rebind_lmon(¤t, binding.boot_incarnation, + binding.lms_generation); + verify_ok = cluster_reconfig_capture_formation_snapshot_v1(binding.origin_thread, &verify) + && memcmp(¤t, &verify, sizeof(current)) == 0; if (!grd_rebind_ok || !verify_ok) return false; if (!cluster_phase_state_lock_acquire(LW_EXCLUSIVE)) return false; - if ((ClusterAuthorityReadiness)pg_atomic_read_u32( - &cluster_phase_state->authority_readiness) + if ((ClusterAuthorityReadiness)pg_atomic_read_u32(&cluster_phase_state->authority_readiness) == CLUSTER_AUTHORITY_SERVING_READY - && cluster_phase_state->authority_origin_thread - == binding.origin_thread - && cluster_phase_state->authority_boot_incarnation - == binding.boot_incarnation - && cluster_phase_state->authority_lms_generation - == binding.lms_generation - && memcmp(&cluster_phase_state->authority_formation, - &binding.formation, sizeof(binding.formation)) == 0) { + && cluster_phase_state->authority_origin_thread == binding.origin_thread + && cluster_phase_state->authority_boot_incarnation == binding.boot_incarnation + && cluster_phase_state->authority_lms_generation == binding.lms_generation + && memcmp(&cluster_phase_state->authority_formation, &binding.formation, + sizeof(binding.formation)) + == 0) { cluster_phase_state->authority_formation = current; rebound = true; } @@ -949,36 +879,30 @@ cluster_authority_serving_rebind_leaver(void) if (cluster_authority_binding_external_current(&binding, true)) return true; if (!cluster_serving_generation_current(&binding) - || !cluster_reconfig_capture_formation_snapshot_v1( - binding.origin_thread, ¤t) - || cluster_formation_snapshot_matches_v1( - &binding.formation, ¤t)) { + || !cluster_reconfig_capture_formation_snapshot_v1(binding.origin_thread, ¤t) + || cluster_formation_snapshot_matches_v1(&binding.formation, ¤t)) { return false; } /* Only the committed leaver re-binds this way (the GRD helper re-checks * the applied CLEAN_LEAVE evidence + all fail-closed components). */ - if (!cluster_grd_serving_authority_rebind_leaver( - ¤t, binding.boot_incarnation, binding.lms_generation) - || !cluster_reconfig_capture_formation_snapshot_v1( - binding.origin_thread, &verify) + if (!cluster_grd_serving_authority_rebind_leaver(¤t, binding.boot_incarnation, + binding.lms_generation) + || !cluster_reconfig_capture_formation_snapshot_v1(binding.origin_thread, &verify) || memcmp(¤t, &verify, sizeof(current)) != 0) { return false; } if (!cluster_phase_state_lock_acquire(LW_EXCLUSIVE)) return false; - if ((ClusterAuthorityReadiness)pg_atomic_read_u32( - &cluster_phase_state->authority_readiness) + if ((ClusterAuthorityReadiness)pg_atomic_read_u32(&cluster_phase_state->authority_readiness) == CLUSTER_AUTHORITY_SERVING_READY - && cluster_phase_state->authority_origin_thread - == binding.origin_thread - && cluster_phase_state->authority_boot_incarnation - == binding.boot_incarnation - && cluster_phase_state->authority_lms_generation - == binding.lms_generation - && memcmp(&cluster_phase_state->authority_formation, - &binding.formation, sizeof(binding.formation)) == 0) { + && cluster_phase_state->authority_origin_thread == binding.origin_thread + && cluster_phase_state->authority_boot_incarnation == binding.boot_incarnation + && cluster_phase_state->authority_lms_generation == binding.lms_generation + && memcmp(&cluster_phase_state->authority_formation, &binding.formation, + sizeof(binding.formation)) + == 0) { cluster_phase_state->authority_formation = current; rebound = true; } @@ -988,26 +912,23 @@ cluster_authority_serving_rebind_leaver(void) } bool -cluster_recovery_authority_resid_mode_allowed(const ClusterResId *resid, - LOCKMODE mode) +cluster_recovery_authority_resid_mode_allowed(const ClusterResId *resid, LOCKMODE mode) { if (resid == NULL) return false; if (resid->type == CLUSTER_CF_RESID_TYPE) - return mode == ShareLock && resid->field1 == 0 && resid->field2 == 0 - && resid->field3 == 0 && resid->field4 == 0 - && resid->lockmethodid == DEFAULT_LOCKMETHOD; + return mode == ShareLock && resid->field1 == 0 && resid->field2 == 0 && resid->field3 == 0 + && resid->field4 == 0 && resid->lockmethodid == DEFAULT_LOCKMETHOD; if (resid->type == CLUSTER_WAL_RETENTION_RESID_TYPE) return mode == ExclusiveLock && resid->field1 > 0 - && resid->field1 <= CLUSTER_WAL_RETENTION_MAX_THREADS - && resid->field2 == 0 && resid->field3 == 0 && resid->field4 == 0 - && resid->lockmethodid == DEFAULT_LOCKMETHOD; + && resid->field1 <= CLUSTER_WAL_RETENTION_MAX_THREADS && resid->field2 == 0 + && resid->field3 == 0 && resid->field4 == 0 + && resid->lockmethodid == DEFAULT_LOCKMETHOD; return false; } bool -cluster_recovery_authority_request_allowed(const ClusterResId *resid, - LOCKMODE mode, +cluster_recovery_authority_request_allowed(const ClusterResId *resid, LOCKMODE mode, bool startup_process) { /* @@ -1034,11 +955,10 @@ cluster_recovery_authority_request_allowed(const ClusterResId *resid, */ if (cluster_hw_remaster_worker_active()) return cluster_recovery_authority_resid_mode_allowed(resid, mode); - return startup_process - && cluster_current_phase() == CLUSTER_PHASE_3_RECOVERY - && (cluster_recovery_transport_components_current() - || cluster_recovery_authority_is_current()) - && cluster_recovery_authority_resid_mode_allowed(resid, mode); + return startup_process && cluster_current_phase() == CLUSTER_PHASE_3_RECOVERY + && (cluster_recovery_transport_components_current() + || cluster_recovery_authority_is_current()) + && cluster_recovery_authority_resid_mode_allowed(resid, mode); } @@ -1071,8 +991,7 @@ cluster_phase_elapsed_seconds(void) return 0; LWLockAcquire(&cluster_phase_state->lwlock, LW_SHARED); - phase = (ClusterStartupPhase)pg_atomic_read_u32( - &cluster_phase_state->current_phase); + phase = (ClusterStartupPhase)pg_atomic_read_u32(&cluster_phase_state->current_phase); started = cluster_phase_state->phase_start_times[(int)phase]; LWLockRelease(&cluster_phase_state->lwlock); @@ -1170,11 +1089,9 @@ cluster_phase_shmem_init(void) */ memset(cluster_phase_state, 0, sizeof(*cluster_phase_state)); LWLockInitialize(&cluster_phase_state->lwlock, LWTRANCHE_CLUSTER_STARTUP_PHASE); - pg_atomic_init_u32(&cluster_phase_state->authority_readiness, - CLUSTER_AUTHORITY_OFF); + pg_atomic_init_u32(&cluster_phase_state->authority_readiness, CLUSTER_AUTHORITY_OFF); pg_atomic_init_u32(&cluster_phase_state->authority_managed, 0); - pg_atomic_init_u32(&cluster_phase_state->current_phase, - CLUSTER_PHASE_PRE_INIT); + pg_atomic_init_u32(&cluster_phase_state->current_phase, CLUSTER_PHASE_PRE_INIT); } } @@ -1233,8 +1150,7 @@ cluster_advance_phase(ClusterStartupPhase target) errhint("cluster_phase_shmem_init() must run during " "CreateSharedMemoryAndSemaphores()."))); - prev = (ClusterStartupPhase)pg_atomic_read_u32( - &cluster_phase_state->current_phase); + prev = (ClusterStartupPhase)pg_atomic_read_u32(&cluster_phase_state->current_phase); /* * Strict transition rules. The only legitimate transitions are: @@ -1379,52 +1295,40 @@ static TimestampTz phase3_recovery_deadline = 0; * neither owns admission nor creates or refreshes a deadline. */ static bool -cluster_phase3_try_pre_publish_join_readonly_pivot(TimestampTz deadline, - uint64 lms_generation) +cluster_phase3_try_pre_publish_join_readonly_pivot(TimestampTz deadline, uint64 lms_generation) { ClusterAuthorityBindingLocal binding; uint64 predecessor_floor; - if (phase3_join_readonly_deferred || deadline == 0 - || lms_generation == 0 || GetCurrentTimestamp() >= deadline - || !cluster_cf_phase2_peer_verified() + if (phase3_join_readonly_deferred || deadline == 0 || lms_generation == 0 + || GetCurrentTimestamp() >= deadline || !cluster_cf_phase2_peer_verified() || cluster_reconfig_self_join_admitted() || !cluster_reconfig_epoch0_late_founder_evidence_current() - || !cluster_authority_binding_copy(&binding) - || binding.state != CLUSTER_AUTHORITY_STARTING + || !cluster_authority_binding_copy(&binding) || binding.state != CLUSTER_AUTHORITY_STARTING || binding.lms_generation != lms_generation - || cluster_lms_get_lms_restart_generation() - != binding.lms_generation + || cluster_lms_get_lms_restart_generation() != binding.lms_generation || binding.boot_incarnation == 0 - || cluster_qvotec_get_self_incarnation() - != binding.boot_incarnation) + || cluster_qvotec_get_self_incarnation() != binding.boot_incarnation) return false; - predecessor_floor - = cluster_membership_get_last_admitted_incarnation(cluster_node_id); - if (predecessor_floor != 0 - && predecessor_floor >= binding.boot_incarnation) + predecessor_floor = cluster_membership_get_last_admitted_incarnation(cluster_node_id); + if (predecessor_floor != 0 && predecessor_floor >= binding.boot_incarnation) return false; if (!cluster_authority_clear_matching_for_handoff(&binding) || cluster_authority_readiness_get() != CLUSTER_AUTHORITY_OFF || !cluster_authority_readiness_managed() - || cluster_lms_get_lms_restart_generation() - != binding.lms_generation - || cluster_qvotec_get_self_incarnation() - != binding.boot_incarnation - || cluster_membership_get_last_admitted_incarnation(cluster_node_id) - != predecessor_floor - || GetCurrentTimestamp() >= deadline - || !cluster_cf_phase2_peer_verified() + || cluster_lms_get_lms_restart_generation() != binding.lms_generation + || cluster_qvotec_get_self_incarnation() != binding.boot_incarnation + || cluster_membership_get_last_admitted_incarnation(cluster_node_id) != predecessor_floor + || GetCurrentTimestamp() >= deadline || !cluster_cf_phase2_peer_verified() || cluster_reconfig_self_join_admitted() || !cluster_reconfig_epoch0_late_founder_evidence_current() - || !cluster_reconfig_stage_pre_publish_join_handoff( - binding.boot_incarnation, predecessor_floor)) + || !cluster_reconfig_stage_pre_publish_join_handoff(binding.boot_incarnation, + predecessor_floor)) return false; phase3_join_readonly_deferred = true; - elog(LOG, - "cluster phase 3: exact pre-publish recovery binding pivoted to JOIN_READONLY"); + elog(LOG, "cluster phase 3: exact pre-publish recovery binding pivoted to JOIN_READONLY"); return true; } @@ -1532,8 +1436,7 @@ phase_2_handler(PhaseRunFailContext *fail_ctx) static bool -cluster_phase3_wait_for_live_formation(TimestampTz deadline, - bool allow_join_readonly, +cluster_phase3_wait_for_live_formation(TimestampTz deadline, bool allow_join_readonly, ClusterFormationWitnessResult *out_result, uint16 *out_origin_thread, ClusterFenceAuthorityProof *out_authority, @@ -1572,11 +1475,11 @@ cluster_phase3_wait_for_live_formation(TimestampTz deadline, attempt_ms = cluster_phase_remaining_budget_ms(deadline, 5000); if (attempt_ms > 100) attempt_ms = 100; - result = cluster_formation_witness_build_recovery_control_wait( - thread_id, attempt_ms, &witness); + result = cluster_formation_witness_build_recovery_control_wait(thread_id, attempt_ms, + &witness); if (result == CLUSTER_FORMATION_WITNESS_READY) { - if (!cluster_formation_witness_copy_classification_v1( - witness, out_origin_thread, out_authority, out_snapshot)) + if (!cluster_formation_witness_copy_classification_v1(witness, out_origin_thread, + out_authority, out_snapshot)) result = CLUSTER_FORMATION_WITNESS_CORRUPT; else result = cluster_formation_witness_revalidate_nowait(witness); @@ -1632,27 +1535,21 @@ cluster_phase4_refresh_serving_formation(int timeout_ms) || !cluster_reconfig_self_join_admitted()) return CLUSTER_FORMATION_WITNESS_CAPABILITY_UNAVAILABLE; - result = cluster_formation_witness_build_live_wait( - binding.origin_thread, timeout_ms, &witness); + result = cluster_formation_witness_build_live_wait(binding.origin_thread, timeout_ms, &witness); if (result == CLUSTER_FORMATION_WITNESS_READY) { - if (!cluster_formation_witness_copy_classification_v1( - witness, &fresh_origin_thread, &fresh_authority, - &fresh_formation)) + if (!cluster_formation_witness_copy_classification_v1(witness, &fresh_origin_thread, + &fresh_authority, &fresh_formation)) result = CLUSTER_FORMATION_WITNESS_CORRUPT; else if (fresh_origin_thread != binding.origin_thread - || fresh_authority.agree_disk_count - != binding.authority.agree_disk_count - || fresh_authority.total_disk_count - != binding.authority.total_disk_count - || !cluster_fence_marker_semantic_equal( - &fresh_authority.marker, &binding.authority.marker) - || !cluster_formation_snapshot_matches_v1( - &binding.formation, &fresh_formation)) + || fresh_authority.agree_disk_count != binding.authority.agree_disk_count + || fresh_authority.total_disk_count != binding.authority.total_disk_count + || !cluster_fence_marker_semantic_equal(&fresh_authority.marker, + &binding.authority.marker) + || !cluster_formation_snapshot_matches_v1(&binding.formation, &fresh_formation)) result = CLUSTER_FORMATION_WITNESS_UNSTABLE; else result = cluster_formation_classification_revalidate_nowait( - binding.origin_thread, &binding.authority, - &binding.formation); + binding.origin_thread, &binding.authority, &binding.formation); } cluster_formation_witness_destroy(&witness); return result; @@ -1686,13 +1583,10 @@ phase_3_handler(PhaseRunFailContext *fail_ctx) * children. Its authority-only budget is created after ordinary admission; * it cannot respawn a child or establish authority before that edge. */ if (resume_join_readonly) { - if (phase3_recovery_deadline == 0 - || GetCurrentTimestamp() >= phase3_recovery_deadline + if (phase3_recovery_deadline == 0 || GetCurrentTimestamp() >= phase3_recovery_deadline || cluster_cssd_get_status() != CLUSTER_CSSD_READY - || cluster_qvotec_get_status() != CLUSTER_QVOTEC_READY - || !cluster_qvotec_in_quorum() - || !cluster_cf_phase2_peer_verified() - || !cluster_reconfig_self_join_admitted()) { + || cluster_qvotec_get_status() != CLUSTER_QVOTEC_READY || !cluster_qvotec_in_quorum() + || !cluster_cf_phase2_peer_verified() || !cluster_reconfig_self_join_admitted()) { fail_ctx->errcode = ERRCODE_CLUSTER_WAL_RETENTION_BLOCKED; fail_ctx->errmsg = "cluster phase 3: JOIN_READONLY admission is not current"; fail_ctx->errhint = "The fresh peer proof, quorum, original phase-3 deadline, " @@ -1725,8 +1619,7 @@ phase_3_handler(PhaseRunFailContext *fail_ctx) * waits and the configured multi-node quorum cut. */ phase3_recovery_deadline = TimestampTzPlusMilliseconds( - GetCurrentTimestamp(), - cluster_phase_timeout_for(CLUSTER_PHASE_3_RECOVERY) * 1000); + GetCurrentTimestamp(), cluster_phase_timeout_for(CLUSTER_PHASE_3_RECOVERY) * 1000); phase3_cssd_pid = cluster_cssd_start(); if (phase3_cssd_pid <= 0) { @@ -1775,13 +1668,11 @@ phase_3_handler(PhaseRunFailContext *fail_ctx) establish_recovery_authority: if (cluster_phase4_wal_state_configured() - && !cluster_phase3_wait_for_live_formation( - phase3_recovery_deadline, !resume_join_readonly, - &formation_result, &formation_origin_thread, - &formation_authority, &formation_snapshot)) { - ereport(LOG, - (errmsg("cluster phase 3: live formation wait failed with witness result %u", - (uint32) formation_result))); + && !cluster_phase3_wait_for_live_formation(phase3_recovery_deadline, !resume_join_readonly, + &formation_result, &formation_origin_thread, + &formation_authority, &formation_snapshot)) { + ereport(LOG, (errmsg("cluster phase 3: live formation wait failed with witness result %u", + (uint32)formation_result))); fail_ctx->errcode = ERRCODE_CLUSTER_WAL_RETENTION_BLOCKED; fail_ctx->errmsg = "cluster phase 3: live formation did not become ready before recovery"; fail_ctx->errhint = "Verify exact self MEMBER admission, the current QVOTEC " @@ -1790,7 +1681,8 @@ phase_3_handler(PhaseRunFailContext *fail_ctx) return PHASE_RUN_FATAL; } if (!resume_join_readonly && phase3_join_readonly_deferred) { - elog(LOG, "cluster phase 3: deferring recovery authority for exact JOIN_READONLY StartupXLOG"); + elog(LOG, + "cluster phase 3: deferring recovery authority for exact JOIN_READONLY StartupXLOG"); /* The ordinary stripe/JCMK state machine owns admission timing. The * pre-StartupXLOG phase budget must not become, or be mistaken for, a * second admission deadline. */ @@ -1806,9 +1698,8 @@ phase_3_handler(PhaseRunFailContext *fail_ctx) "no PG-native recovery-authority fallback."; return PHASE_RUN_FATAL; } - if (!cluster_authority_readiness_begin( - formation_origin_thread, &formation_authority, - &formation_snapshot)) { + if (!cluster_authority_readiness_begin(formation_origin_thread, &formation_authority, + &formation_snapshot)) { fail_ctx->errcode = ERRCODE_CLUSTER_WAL_RETENTION_BLOCKED; fail_ctx->errmsg = "cluster phase 3: live formation could not bind this boot"; fail_ctx->errhint = "Verify the current QVOTEC incarnation equals the admitted " @@ -1824,8 +1715,7 @@ phase_3_handler(PhaseRunFailContext *fail_ctx) fail_ctx->errhint = "Check postmaster log and OS process limits."; return PHASE_RUN_FATAL; } - lms_remaining_ms = cluster_phase_remaining_budget_ms( - phase3_recovery_deadline, 5000); + lms_remaining_ms = cluster_phase_remaining_budget_ms(phase3_recovery_deadline, 5000); if (!cluster_lms_wait_for_recovery_ready(lms_remaining_ms)) { cluster_authority_readiness_clear(); fail_ctx->errcode = ERRCODE_CLUSTER_LMS_UNAVAILABLE; @@ -1850,8 +1740,7 @@ phase_3_handler(PhaseRunFailContext *fail_ctx) */ bind_failed = false; barrier_failed = false; - for (;;) - { + for (;;) { lms_generation = cluster_lms_get_lms_restart_generation(); /* * The clean-reopen mainline (STOP-01 frozen THREAD_OPEN) is @@ -1871,22 +1760,18 @@ phase_3_handler(PhaseRunFailContext *fail_ctx) * probe response on the heartbeat cadence). */ if (cluster_phase4_wal_state_configured()) { - (void)cluster_authority_readiness_bind_recovery_generation( - lms_generation); + (void)cluster_authority_readiness_bind_recovery_generation(lms_generation); } - if (!cluster_authority_readiness_bind_recovery_generation( - lms_generation)) { + if (!cluster_authority_readiness_bind_recovery_generation(lms_generation)) { /* begin() only accepts OFF, so drop any stale STARTING * binding before reacquiring the exact live formation. */ cluster_authority_readiness_clear(); if (GetCurrentTimestamp() >= phase3_recovery_deadline || !cluster_phase3_wait_for_live_formation( phase3_recovery_deadline, false, &formation_result, - &formation_origin_thread, &formation_authority, - &formation_snapshot) + &formation_origin_thread, &formation_authority, &formation_snapshot) || !cluster_authority_readiness_begin( - formation_origin_thread, &formation_authority, - &formation_snapshot)) { + formation_origin_thread, &formation_authority, &formation_snapshot)) { bind_failed = true; break; } @@ -1894,16 +1779,13 @@ phase_3_handler(PhaseRunFailContext *fail_ctx) continue; } boot_incarnation = cluster_qvotec_get_self_incarnation(); - lms_remaining_ms = cluster_phase_remaining_budget_ms( - phase3_recovery_deadline, 5000); - if (cluster_grd_recovery_authority_barrier_wait( - &formation_snapshot, boot_incarnation, lms_generation, - lms_remaining_ms)) { - if (cluster_authority_readiness_publish_recovery( - lms_generation)) + lms_remaining_ms = cluster_phase_remaining_budget_ms(phase3_recovery_deadline, 5000); + if (cluster_grd_recovery_authority_barrier_wait(&formation_snapshot, boot_incarnation, + lms_generation, lms_remaining_ms)) { + if (cluster_authority_readiness_publish_recovery(lms_generation)) break; - } else if (cluster_phase3_try_pre_publish_join_readonly_pivot( - phase3_recovery_deadline, lms_generation)) { + } else if (cluster_phase3_try_pre_publish_join_readonly_pivot(phase3_recovery_deadline, + lms_generation)) { return PHASE_RUN_OK; } if (GetCurrentTimestamp() >= phase3_recovery_deadline) { @@ -1914,13 +1796,11 @@ phase_3_handler(PhaseRunFailContext *fail_ctx) * barrier attempt; begin() only accepts OFF, so drop the * stale binding first. */ cluster_authority_readiness_clear(); - if (!cluster_phase3_wait_for_live_formation( - phase3_recovery_deadline, false, &formation_result, - &formation_origin_thread, &formation_authority, - &formation_snapshot) - || !cluster_authority_readiness_begin( - formation_origin_thread, &formation_authority, - &formation_snapshot)) { + if (!cluster_phase3_wait_for_live_formation(phase3_recovery_deadline, false, + &formation_result, &formation_origin_thread, + &formation_authority, &formation_snapshot) + || !cluster_authority_readiness_begin(formation_origin_thread, &formation_authority, + &formation_snapshot)) { bind_failed = true; break; } @@ -1932,15 +1812,14 @@ phase_3_handler(PhaseRunFailContext *fail_ctx) } if (bind_failed || barrier_failed - || cluster_authority_readiness_get() - != CLUSTER_AUTHORITY_RECOVERY_READY) - { + || cluster_authority_readiness_get() != CLUSTER_AUTHORITY_RECOVERY_READY) { cluster_authority_readiness_clear(); fail_ctx->errcode = ERRCODE_CLUSTER_LMS_UNAVAILABLE; if (barrier_failed) { fail_ctx->errmsg = "cluster phase 3: authoritative recovery GRD is unavailable"; - fail_ctx->errhint = "Recovery requires an explicit current-generation holder " - "authority seal; an empty or uninitialized GRD is insufficient."; + fail_ctx->errhint + = "Recovery requires an explicit current-generation holder " + "authority seal; an empty or uninitialized GRD is insufficient."; } else { fail_ctx->errmsg = "cluster phase 3: recovery LMS generation could not be bound"; fail_ctx->errhint = "The LMS recovery generation, live formation, and admitted " @@ -1965,8 +1844,8 @@ phase_3_handler(PhaseRunFailContext *fail_ctx) * unchanged: OFF -> STARTING -> RECOVERY_READY, followed by the existing * phase-4 RECOVERY_READY -> SERVING_READY transition. */ static PhaseRunResult -cluster_phase4_establish_join_readonly_authority( - TimestampTz deadline, PhaseRunFailContext *fail_ctx) +cluster_phase4_establish_join_readonly_authority(TimestampTz deadline, + PhaseRunFailContext *fail_ctx) { ClusterFenceAuthorityProof formation_authority; ClusterFormationSnapshotV1 formation_snapshot; @@ -1978,19 +1857,17 @@ cluster_phase4_establish_join_readonly_authority( bool bind_failed = false; bool barrier_failed = false; - if (!phase3_join_readonly_deferred - || cluster_current_phase() != CLUSTER_PHASE_4_NORMAL - || !cluster_cf_phase2_peer_verified() - || !cluster_reconfig_self_join_admitted()) { + if (!phase3_join_readonly_deferred || cluster_current_phase() != CLUSTER_PHASE_4_NORMAL + || !cluster_cf_phase2_peer_verified() || !cluster_reconfig_self_join_admitted()) { fail_ctx->errcode = ERRCODE_CLUSTER_WAL_RETENTION_BLOCKED; fail_ctx->errmsg = "cluster phase 4: JOIN_READONLY admission is not current"; fail_ctx->errhint = "The fresh peer proof and exact stripe/JOIN-WAL/JCMK " "admission must remain current before authority publication."; return PHASE_RUN_FATAL; } - if (!cluster_phase3_wait_for_live_formation( - deadline, false, &formation_result, &formation_origin_thread, - &formation_authority, &formation_snapshot)) { + if (!cluster_phase3_wait_for_live_formation(deadline, false, &formation_result, + &formation_origin_thread, &formation_authority, + &formation_snapshot)) { fail_ctx->errcode = ERRCODE_CLUSTER_WAL_RETENTION_BLOCKED; fail_ctx->errmsg = "cluster phase 4: admitted JOIN_READONLY formation is unavailable"; fail_ctx->errhint = "The current admitted formation and durable voting " @@ -2003,9 +1880,8 @@ cluster_phase4_establish_join_readonly_authority( fail_ctx->errhint = "Set cluster.lms_enabled=on; no native serving fallback exists."; return PHASE_RUN_FATAL; } - if (!cluster_authority_readiness_begin( - formation_origin_thread, &formation_authority, - &formation_snapshot)) { + if (!cluster_authority_readiness_begin(formation_origin_thread, &formation_authority, + &formation_snapshot)) { fail_ctx->errcode = ERRCODE_CLUSTER_WAL_RETENTION_BLOCKED; fail_ctx->errmsg = "cluster phase 4: admitted JOIN_READONLY formation could not bind"; fail_ctx->errhint = "The admission incarnation and formation must remain exact."; @@ -2032,17 +1908,14 @@ cluster_phase4_establish_join_readonly_authority( for (;;) { lms_generation = cluster_lms_get_lms_restart_generation(); - if (!cluster_authority_readiness_bind_recovery_generation( - lms_generation)) { + if (!cluster_authority_readiness_bind_recovery_generation(lms_generation)) { cluster_authority_readiness_clear(); if (GetCurrentTimestamp() >= deadline || !cluster_phase3_wait_for_live_formation( - deadline, false, &formation_result, - &formation_origin_thread, &formation_authority, - &formation_snapshot) - || !cluster_authority_readiness_begin( - formation_origin_thread, &formation_authority, - &formation_snapshot)) { + deadline, false, &formation_result, &formation_origin_thread, + &formation_authority, &formation_snapshot) + || !cluster_authority_readiness_begin(formation_origin_thread, &formation_authority, + &formation_snapshot)) { bind_failed = true; break; } @@ -2052,24 +1925,20 @@ cluster_phase4_establish_join_readonly_authority( boot_incarnation = cluster_qvotec_get_self_incarnation(); lms_remaining_ms = cluster_phase_remaining_budget_ms(deadline, 5000); - if (cluster_grd_recovery_authority_barrier_wait( - &formation_snapshot, boot_incarnation, lms_generation, - lms_remaining_ms) - && cluster_authority_readiness_publish_recovery( - lms_generation)) + if (cluster_grd_recovery_authority_barrier_wait(&formation_snapshot, boot_incarnation, + lms_generation, lms_remaining_ms) + && cluster_authority_readiness_publish_recovery(lms_generation)) break; if (GetCurrentTimestamp() >= deadline) { barrier_failed = true; break; } cluster_authority_readiness_clear(); - if (!cluster_phase3_wait_for_live_formation( - deadline, false, &formation_result, - &formation_origin_thread, &formation_authority, - &formation_snapshot) - || !cluster_authority_readiness_begin( - formation_origin_thread, &formation_authority, - &formation_snapshot)) { + if (!cluster_phase3_wait_for_live_formation(deadline, false, &formation_result, + &formation_origin_thread, &formation_authority, + &formation_snapshot) + || !cluster_authority_readiness_begin(formation_origin_thread, &formation_authority, + &formation_snapshot)) { bind_failed = true; break; } @@ -2077,13 +1946,13 @@ cluster_phase4_establish_join_readonly_authority( } if (bind_failed || barrier_failed - || cluster_authority_readiness_get() - != CLUSTER_AUTHORITY_RECOVERY_READY) { + || cluster_authority_readiness_get() != CLUSTER_AUTHORITY_RECOVERY_READY) { cluster_authority_readiness_clear(); fail_ctx->errcode = ERRCODE_CLUSTER_LMS_UNAVAILABLE; - fail_ctx->errmsg = barrier_failed - ? "cluster phase 4: admitted JOIN_READONLY GRD barrier is unavailable" - : "cluster phase 4: admitted JOIN_READONLY LMS generation could not bind"; + fail_ctx->errmsg + = barrier_failed + ? "cluster phase 4: admitted JOIN_READONLY GRD barrier is unavailable" + : "cluster phase 4: admitted JOIN_READONLY LMS generation could not bind"; fail_ctx->errhint = "Formation, admission, LMS generation, and GRD seal " "must remain exact within the phase-4 deadline."; return PHASE_RUN_FATAL; @@ -2126,8 +1995,7 @@ cluster_phase_remaining_budget_ms(TimestampTz deadline, int driver_buffer_ms) static bool cluster_phase4_wal_state_configured(void) { - return cluster_enabled && cluster_wal_threads_dir != NULL - && cluster_wal_threads_dir[0] != '\0'; + return cluster_enabled && cluster_wal_threads_dir != NULL && cluster_wal_threads_dir[0] != '\0'; } @@ -2148,32 +2016,29 @@ static void cluster_validate_running_configuration(void) { if (cluster_phase4_wal_state_configured() && !cluster_controlfile_shared_authority) - ereport(FATAL, - (errcode(ERRCODE_CLUSTER_CONTROLFILE_AUTHORITY_UNAVAILABLE), - errmsg("formed WAL registry requires shared control-file authority"), - errhint("Set cluster.controlfile_shared_authority=on and restart all " - "members on the same RF A1 binary."))); + ereport(FATAL, (errcode(ERRCODE_CLUSTER_CONTROLFILE_AUTHORITY_UNAVAILABLE), + errmsg("formed WAL registry requires shared control-file authority"), + errhint("Set cluster.controlfile_shared_authority=on and restart all " + "members on the same RF A1 binary."))); if (cluster_enabled && !SCN_NODE_ID_VALID(cluster_node_id)) { if (cluster_allow_single_node) { - ereport(WARNING, - (errcode(ERRCODE_WARNING), - errmsg("cluster.node_id (%d) is outside the valid range 0..%d; " - "cluster SCN advance will silently skip", - cluster_node_id, SCN_MAX_VALID_NODE_ID), - errhint("Set cluster.node_id in postgresql.conf to an integer 0..127 " - "to enable SCN advance, or set cluster.enabled = off for " - "vanilla PG behaviour. Currently running in single-node " - "compatibility mode (cluster.allow_single_node = on). Set " - "cluster.allow_single_node = off to enforce strict mode."))); + ereport(WARNING, (errcode(ERRCODE_WARNING), + errmsg("cluster.node_id (%d) is outside the valid range 0..%d; " + "cluster SCN advance will silently skip", + cluster_node_id, SCN_MAX_VALID_NODE_ID), + errhint("Set cluster.node_id in postgresql.conf to an integer 0..127 " + "to enable SCN advance, or set cluster.enabled = off for " + "vanilla PG behaviour. Currently running in single-node " + "compatibility mode (cluster.allow_single_node = on). Set " + "cluster.allow_single_node = off to enforce strict mode."))); } else { - ereport(FATAL, - (errcode(ERRCODE_INVALID_PARAMETER_VALUE), - errmsg("cluster.node_id (%d) is outside the valid range 0..%d", - cluster_node_id, SCN_MAX_VALID_NODE_ID), - errhint("Set cluster.node_id in postgresql.conf to an integer 0..127, " - "or set cluster.allow_single_node = on for single-node " - "compatibility mode."))); + ereport(FATAL, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), + errmsg("cluster.node_id (%d) is outside the valid range 0..%d", + cluster_node_id, SCN_MAX_VALID_NODE_ID), + errhint("Set cluster.node_id in postgresql.conf to an integer 0..127, " + "or set cluster.allow_single_node = on for single-node " + "compatibility mode."))); } } @@ -2210,8 +2075,7 @@ cluster_validate_running_configuration(void) static PhaseRunResult -cluster_phase4_start_stats(PhaseRunFailContext *fail_ctx, TimestampTz deadline, - int *stats_pid) +cluster_phase4_start_stats(PhaseRunFailContext *fail_ctx, TimestampTz deadline, int *stats_pid) { int remaining_ms; @@ -2322,8 +2186,8 @@ phase_4_handler(PhaseRunFailContext *fail_ctx) * build that authority here under this same phase-4 absolute deadline; * the ordinary phase-3 path and all already-admitted boots are unchanged. */ if (registry_configured && phase3_join_readonly_deferred - && cluster_phase4_establish_join_readonly_authority( - phase4_deadline, fail_ctx) == PHASE_RUN_FATAL) + && cluster_phase4_establish_join_readonly_authority(phase4_deadline, fail_ctx) + == PHASE_RUN_FATAL) return PHASE_RUN_FATAL; /* ---------- @@ -2352,8 +2216,7 @@ phase_4_handler(PhaseRunFailContext *fail_ctx) /* A flat/unconfigured registry keeps the pre-RF child order unchanged. */ if (!registry_configured - && cluster_phase4_start_stats(fail_ctx, phase4_deadline, &stats_pid) - == PHASE_RUN_FATAL) + && cluster_phase4_start_stats(fail_ctx, phase4_deadline, &stats_pid) == PHASE_RUN_FATAL) return PHASE_RUN_FATAL; /* @@ -2371,8 +2234,7 @@ phase_4_handler(PhaseRunFailContext *fail_ctx) } lms_pid = phase3_lms_pid; - if (lms_pid <= 0) - { + if (lms_pid <= 0) { fail_ctx->errcode = ERRCODE_CLUSTER_LMS_UNAVAILABLE; fail_ctx->errmsg = "cluster phase 4: recovery LMS authority is unavailable"; fail_ctx->errhint = "Restart after the phase-3 LMS generation and authority " @@ -2387,13 +2249,10 @@ phase_4_handler(PhaseRunFailContext *fail_ctx) * and the contract requires retrying inside the existing phase4 * deadline instead of treating one miss as terminal. */ - for (;;) - { - if (cluster_authority_readiness_get() - == CLUSTER_AUTHORITY_RECOVERY_READY) + for (;;) { + if (cluster_authority_readiness_get() == CLUSTER_AUTHORITY_RECOVERY_READY) break; - if (GetCurrentTimestamp() >= phase4_deadline) - { + if (GetCurrentTimestamp() >= phase4_deadline) { fail_ctx->errcode = ERRCODE_CLUSTER_LMS_UNAVAILABLE; fail_ctx->errmsg = "cluster phase 4: recovery LMS authority is unavailable"; fail_ctx->errhint = "Restart after the phase-3 LMS generation and authority " @@ -2406,16 +2265,14 @@ phase_4_handler(PhaseRunFailContext *fail_ctx) * never for ordinary service. LMON keeps retrying the original * stripe join gate after recovery; wait for that exact admission byte * before issuing the existing LMS SERVING request. */ - for (;;) - { + for (;;) { if (cluster_reconfig_self_join_admitted()) break; - if (GetCurrentTimestamp() >= phase4_deadline) - { + if (GetCurrentTimestamp() >= phase4_deadline) { fail_ctx->errcode = ERRCODE_CLUSTER_LMS_UNAVAILABLE; fail_ctx->errmsg = "cluster phase 4: xid stripe admission is unavailable"; fail_ctx->errhint = "Recovery control authority cannot publish ordinary " - "service until the post-recovery xid stripe floor is durable."; + "service until the post-recovery xid stripe floor is durable."; return PHASE_RUN_FATAL; } pg_usleep(20000L); @@ -2425,31 +2282,26 @@ phase_4_handler(PhaseRunFailContext *fail_ctx) * authority only after the exact stripe gate opens, and accept it only * when it is the same immutable marker/formation already bound to this * recovery generation. */ - for (;;) - { + for (;;) { ClusterFormationWitnessResult refresh_result; - int refresh_ms = cluster_phase_remaining_budget_ms( - phase4_deadline, 5000); + int refresh_ms = cluster_phase_remaining_budget_ms(phase4_deadline, 5000); if (refresh_ms > 100) refresh_ms = 100; - refresh_result = cluster_phase4_refresh_serving_formation( - refresh_ms); + refresh_result = cluster_phase4_refresh_serving_formation(refresh_ms); if (refresh_result == CLUSTER_FORMATION_WITNESS_READY) break; if ((refresh_result != CLUSTER_FORMATION_WITNESS_OWNER_MISMATCH && refresh_result != CLUSTER_FORMATION_WITNESS_UNSTABLE && refresh_result != CLUSTER_FORMATION_WITNESS_MARKER_UNPROVEN && refresh_result != CLUSTER_FORMATION_WITNESS_IO_FAILED - && refresh_result - != CLUSTER_FORMATION_WITNESS_CAPABILITY_UNAVAILABLE) - || GetCurrentTimestamp() >= phase4_deadline) - { + && refresh_result != CLUSTER_FORMATION_WITNESS_CAPABILITY_UNAVAILABLE) + || GetCurrentTimestamp() >= phase4_deadline) { cluster_authority_readiness_clear(); fail_ctx->errcode = ERRCODE_CLUSTER_LMS_UNAVAILABLE; fail_ctx->errmsg = "cluster phase 4: serving formation proof is unavailable"; fail_ctx->errhint = "The post-recovery durable marker and exact admitted " - "formation must still match the phase-3 authority binding."; + "formation must still match the phase-3 authority binding."; return PHASE_RUN_FATAL; } pg_usleep(20000L); @@ -2476,12 +2328,10 @@ phase_4_handler(PhaseRunFailContext *fail_ctx) * closed only when the budget is exhausted or the authoritative * predicate itself reports stale. */ - for (;;) - { + for (;;) { if (cluster_authority_readiness_publish_serving()) break; - if (GetCurrentTimestamp() >= phase4_deadline) - { + if (GetCurrentTimestamp() >= phase4_deadline) { cluster_authority_readiness_clear(); fail_ctx->errcode = ERRCODE_CLUSTER_LMS_UNAVAILABLE; fail_ctx->errmsg = "cluster phase 4: serving authority publication failed"; @@ -2500,8 +2350,7 @@ phase_4_handler(PhaseRunFailContext *fail_ctx) * and publishes READY only after ACTIVE post-read and checkpoint return. */ if (registry_configured - && cluster_phase4_start_stats(fail_ctx, phase4_deadline, &stats_pid) - == PHASE_RUN_FATAL) + && cluster_phase4_start_stats(fail_ctx, phase4_deadline, &stats_pid) == PHASE_RUN_FATAL) return PHASE_RUN_FATAL; if (registry_configured) @@ -2831,11 +2680,9 @@ cluster_run_phase4_sequence(void) * admission budget, and LMON remains the sole join-timeout owner. */ if (phase3_join_readonly_deferred) { while (!cluster_reconfig_self_join_admitted()) { - ClusterMembershipState self_state - = cluster_membership_get_state(cluster_node_id); + ClusterMembershipState self_state = cluster_membership_get_state(cluster_node_id); - if (self_state == CLUSTER_MEMBER_REJECTED - || self_state == CLUSTER_MEMBER_REMOVED) + if (self_state == CLUSTER_MEMBER_REJECTED || self_state == CLUSTER_MEMBER_REMOVED) break; pg_usleep(20000L); } @@ -2845,7 +2692,7 @@ cluster_run_phase4_sequence(void) errmsg("cluster startup phase %s failed: JOIN_READONLY admission rejected", cluster_startup_phase_to_string(CLUSTER_PHASE_4_NORMAL)), errhint("The ordinary stripe/JOIN-WAL/JCMK owner reached its " - "existing fail-closed terminal before phase 4."))); + "existing fail-closed terminal before phase 4."))); } Assert(!IsUnderPostmaster); diff --git a/src/backend/cluster/cluster_stats.c b/src/backend/cluster/cluster_stats.c index 692e383378e..1cf5ebe1a38 100644 --- a/src/backend/cluster/cluster_stats.c +++ b/src/backend/cluster/cluster_stats.c @@ -423,8 +423,7 @@ stats_advance_liveness_tick(void) static bool stats_wal_state_configured(void) { - return cluster_enabled && cluster_wal_threads_dir != NULL - && cluster_wal_threads_dir[0] != '\0'; + return cluster_enabled && cluster_wal_threads_dir != NULL && cluster_wal_threads_dir[0] != '\0'; } @@ -489,8 +488,7 @@ stats_prepare_incarnation(void) started_at = (int64)cluster_stats_state->spawned_at; LWLockRelease(&cluster_stats_state->lwlock); stats_fill_wal_state_update(CLUSTER_WAL_STATE_UPDATE_ACTIVE, started_at, &update); - result = cluster_wal_state_update_own( - &update, CLUSTER_WAL_STATE_CF_ACQUIRE_X, NULL); + result = cluster_wal_state_update_own(&update, CLUSTER_WAL_STATE_CF_ACQUIRE_X, NULL); /* * RF-ROOT A1 retry discipline: the clusterwide CF(X) can be held by * the coordinator's formation/serving critical sections (or by this @@ -503,26 +501,22 @@ stats_prepare_incarnation(void) for (w2_retry = 0; w2_retry < 3; w2_retry++) { pg_usleep(1000000L); /* 1 s */ - result = cluster_wal_state_update_own( - &update, CLUSTER_WAL_STATE_CF_ACQUIRE_X, NULL); - if (result == CLUSTER_WAL_STATE_UPDATE_OK - || result == CLUSTER_WAL_STATE_UPDATE_NOOP + result + = cluster_wal_state_update_own(&update, CLUSTER_WAL_STATE_CF_ACQUIRE_X, NULL); + if (result == CLUSTER_WAL_STATE_UPDATE_OK || result == CLUSTER_WAL_STATE_UPDATE_NOOP || result != CLUSTER_WAL_STATE_UPDATE_CF_UNAVAILABLE) break; } } - if (result != CLUSTER_WAL_STATE_UPDATE_OK - && result != CLUSTER_WAL_STATE_UPDATE_NOOP) - ereport(FATAL, - (errcode(ERRCODE_CLUSTER_WAL_STATE_IO_FAILURE), - errmsg("could not publish ACTIVE to the WAL state registry"), - errdetail("The verified-CF update returned result %d.", (int)result), - errhint("The node remains outside RUNNING admission; preserve and " - "inspect the registry evidence before retrying."))); - - ereport(LOG, - (errmsg("pgrac WAL thread %u published ACTIVE in the WAL state registry", - (unsigned)cluster_wal_thread_id()))); + if (result != CLUSTER_WAL_STATE_UPDATE_OK && result != CLUSTER_WAL_STATE_UPDATE_NOOP) + ereport(FATAL, (errcode(ERRCODE_CLUSTER_WAL_STATE_IO_FAILURE), + errmsg("could not publish ACTIVE to the WAL state registry"), + errdetail("The verified-CF update returned result %d.", (int)result), + errhint("The node remains outside RUNNING admission; preserve and " + "inspect the registry evidence before retrying."))); + + ereport(LOG, (errmsg("pgrac WAL thread %u published ACTIVE in the WAL state registry", + (unsigned)cluster_wal_thread_id()))); RequestCheckpoint(CHECKPOINT_IMMEDIATE | CHECKPOINT_FORCE | CHECKPOINT_WAIT); return false; } @@ -575,12 +569,11 @@ stats_refresh_wal_state(void) return; if (cluster_wal_thread_refresh_fail_fetch_add() == 0) - ereport(LOG, - (errcode(ERRCODE_CLUSTER_WAL_STATE_IO_FAILURE), - errmsg("could not refresh the WAL state registry slot"), - errdetail("The verified-CF update returned result %d.", (int)result), - errhint("Further refresh failures are counted, not logged " - "(cluster.wal_thread.wal_state_refresh_fail_count)."))); + ereport(LOG, (errcode(ERRCODE_CLUSTER_WAL_STATE_IO_FAILURE), + errmsg("could not refresh the WAL state registry slot"), + errdetail("The verified-CF update returned result %d.", (int)result), + errhint("Further refresh failures are counted, not logged " + "(cluster.wal_thread.wal_state_refresh_fail_count)."))); } diff --git a/src/backend/cluster/cluster_subtrans.c b/src/backend/cluster/cluster_subtrans.c index 504855bec34..67d8a1d1bab 100644 --- a/src/backend/cluster/cluster_subtrans.c +++ b/src/backend/cluster/cluster_subtrans.c @@ -240,7 +240,7 @@ cluster_subtrans_emit_subcommit(TransactionId child_xid, TransactionId parent_xi tt_request.key = &child_key; tt_request.parent_key = &parent_key; if (cluster_tt_status_source_dispatch(CLUSTER_TT_SOURCE_INSTALL_SUBCOMMITTED, &tt_request, - &tt_result) + &tt_result) != CLUSTER_SEMANTIC_ADMISSION_OK || !tt_result.bool_value) return false; @@ -249,7 +249,7 @@ cluster_subtrans_emit_subcommit(TransactionId child_xid, TransactionId parent_xi hint_request.key = &child_key; hint_request.parent_key = &parent_key; (void)cluster_tt_status_hint_source_dispatch(CLUSTER_TT_HINT_SOURCE_EMIT_SUBCOMMITTED, - &hint_request); + &hint_request); /* spec-3.15 D7: track the link for a potential PREPARE. */ { @@ -342,7 +342,7 @@ cluster_subtrans_lookup_parent(const ClusterTTStatusResult *child_result, int de memset(&source_request, 0, sizeof(source_request)); source_request.key = &next_key; if (cluster_tt_status_source_dispatch(CLUSTER_TT_SOURCE_LOOKUP, &source_request, - &source_result) + &source_result) != CLUSTER_SEMANTIC_ADMISSION_OK || !source_result.bool_value) { /* @@ -358,7 +358,7 @@ cluster_subtrans_lookup_parent(const ClusterTTStatusResult *child_result, int de memset(&bump_request, 0, sizeof(bump_request)); (void)cluster_tt_status_source_dispatch(CLUSTER_TT_SOURCE_BUMP_PARENT_CHAIN_FOLLOW, - &bump_request, &bump_result); + &bump_request, &bump_result); if (parent_res.status != CLUSTER_TT_STATUS_SUBCOMMITTED) return parent_res; diff --git a/src/backend/cluster/cluster_thread_recovery_authority.c b/src/backend/cluster/cluster_thread_recovery_authority.c index 2ea7c727f3e..e23b1479fa3 100644 --- a/src/backend/cluster/cluster_thread_recovery_authority.c +++ b/src/backend/cluster/cluster_thread_recovery_authority.c @@ -12,47 +12,43 @@ static bool root_owner_exact(uint16 dead_tid, const ClusterRecoveryDutyKey *duty, - const ClusterControlRootSnapshot *root, - const ClusterControlRootReadToken *token) + const ClusterControlRootSnapshot *root, const ClusterControlRootReadToken *token) { - return dead_tid != 0 && duty != NULL && root != NULL && token != NULL && - dead_tid == duty->origin_thread_id && - memcmp(&root->identity, duty, sizeof(*duty)) == 0 && - root->lifecycle == CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_REQUIRED && - (root->root_flags & (CLUSTER_CONTROL_ROOT_FLAG_CHECKPOINT_VALID | - CLUSTER_CONTROL_ROOT_FLAG_TAIL_VALID)) == - (CLUSTER_CONTROL_ROOT_FLAG_CHECKPOINT_VALID | - CLUSTER_CONTROL_ROOT_FLAG_TAIL_VALID) && - token->origin_thread_id == dead_tid && - token->lifecycle == CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_REQUIRED && - token->root_lineage_seq == duty->root_lineage_seq && - memcmp(token->authority_uuid, duty->authority_uuid, 16) == 0 && - token->root_flags == root->root_flags && token->reserved20 == 0 && - token->reserved32 == 0; + return dead_tid != 0 && duty != NULL && root != NULL && token != NULL + && dead_tid == duty->origin_thread_id + && memcmp(&root->identity, duty, sizeof(*duty)) == 0 + && root->lifecycle == CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_REQUIRED + && (root->root_flags + & (CLUSTER_CONTROL_ROOT_FLAG_CHECKPOINT_VALID + | CLUSTER_CONTROL_ROOT_FLAG_TAIL_VALID)) + == (CLUSTER_CONTROL_ROOT_FLAG_CHECKPOINT_VALID + | CLUSTER_CONTROL_ROOT_FLAG_TAIL_VALID) + && token->origin_thread_id == dead_tid + && token->lifecycle == CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_REQUIRED + && token->root_lineage_seq == duty->root_lineage_seq + && memcmp(token->authority_uuid, duty->authority_uuid, 16) == 0 + && token->root_flags == root->root_flags && token->reserved20 == 0 + && token->reserved32 == 0; } bool cluster_thread_recovery_pin_request_build_v1( uint16 dead_tid, const ClusterRecoveryDutyKey *duty, - const ClusterControlRootSnapshot *root_snapshot, - const ClusterControlRootReadToken *root_token, - const ClusterFormationWitnessV1 *formation, - const PgracExternalFenceNeedSetV1 *fence_need_set, + const ClusterControlRootSnapshot *root_snapshot, const ClusterControlRootReadToken *root_token, + const ClusterFormationWitnessV1 *formation, const PgracExternalFenceNeedSetV1 *fence_need_set, const PgracExternalFenceAdmissionSetV1 *fence_admission_set, - ClusterWalRetentionInterval *out_interval, - ClusterWalRetentionPinThreadRequest *out_request) + ClusterWalRetentionInterval *out_interval, ClusterWalRetentionPinThreadRequest *out_request) { if (out_interval == NULL || out_request == NULL) return false; memset(out_interval, 0, sizeof(*out_interval)); memset(out_request, 0, sizeof(*out_request)); - if (!root_owner_exact(dead_tid, duty, root_snapshot, root_token) || - formation == NULL || fence_need_set == NULL || - fence_admission_set == NULL || root_snapshot->checkpoint_tli == 0 || - root_snapshot->checkpoint_tli != root_snapshot->tail_tli || - root_snapshot->checkpoint_lower_lsn == InvalidXLogRecPtr || - root_snapshot->validated_tail_lsn_exclusive <= - root_snapshot->checkpoint_lower_lsn) + if (!root_owner_exact(dead_tid, duty, root_snapshot, root_token) || formation == NULL + || fence_need_set == NULL || fence_admission_set == NULL + || root_snapshot->checkpoint_tli == 0 + || root_snapshot->checkpoint_tli != root_snapshot->tail_tli + || root_snapshot->checkpoint_lower_lsn == InvalidXLogRecPtr + || root_snapshot->validated_tail_lsn_exclusive <= root_snapshot->checkpoint_lower_lsn) return false; out_interval->thread_id = dead_tid; out_interval->tli = root_snapshot->checkpoint_tli; @@ -73,108 +69,95 @@ cluster_thread_recovery_authority_revalidate_nowait_v1( const ClusterThreadRecoveryAuthorityV1 *authority) { ClusterRecoverySerialGuard *serial; - PgracExternalFenceDenyReason reason = - PGRAC_EXTERNAL_FENCE_DENY_BAD_ARGUMENT; + PgracExternalFenceDenyReason reason = PGRAC_EXTERNAL_FENCE_DENY_BAD_ARGUMENT; - if (authority == NULL || authority->duty == NULL || - authority->root_snapshot == NULL || authority->root_token == NULL || - authority->formation == NULL || authority->fence_need_set == NULL || - authority->fence_admission_set == NULL || - authority->retention_pin == NULL || authority->serial_guard == NULL) + if (authority == NULL || authority->duty == NULL || authority->root_snapshot == NULL + || authority->root_token == NULL || authority->formation == NULL + || authority->fence_need_set == NULL || authority->fence_admission_set == NULL + || authority->retention_pin == NULL || authority->serial_guard == NULL) return CLUSTER_THREAD_AUTHORITY_INVALID; serial = authority->serial_guard; - if (!root_owner_exact(authority->duty->origin_thread_id, - authority->duty, authority->root_snapshot, authority->root_token) || - memcmp(&serial->duty, authority->duty, - sizeof(serial->duty)) != 0 || - memcmp(&serial->root_read_token, authority->root_token, - sizeof(serial->root_read_token)) != 0) + if (!root_owner_exact(authority->duty->origin_thread_id, authority->duty, + authority->root_snapshot, authority->root_token) + || memcmp(&serial->duty, authority->duty, sizeof(serial->duty)) != 0 + || memcmp(&serial->root_read_token, authority->root_token, sizeof(serial->root_read_token)) + != 0) return CLUSTER_THREAD_AUTHORITY_ROOT_STALE; - if (!serial->held || serial->formation != authority->formation || - serial->fence_need_set != authority->fence_need_set || - serial->fence_admission_set != authority->fence_admission_set || - cluster_recovery_serial_revalidate(serial) != - CLUSTER_RECOVERY_SERIAL_CURRENT) + if (!serial->held || serial->formation != authority->formation + || serial->fence_need_set != authority->fence_need_set + || serial->fence_admission_set != authority->fence_admission_set + || cluster_recovery_serial_revalidate(serial) != CLUSTER_RECOVERY_SERIAL_CURRENT) return CLUSTER_THREAD_AUTHORITY_SERIAL_STALE; - if (cluster_formation_witness_revalidate_nowait(authority->formation) != - CLUSTER_FORMATION_WITNESS_READY || - !cluster_external_fence_need_set_revalidate_nowait( - authority->fence_need_set, authority->formation, &reason) || - !cluster_external_fence_revalidate_set_nowait( - authority->fence_admission_set, authority->fence_need_set, - authority->formation, &reason)) + if (cluster_formation_witness_revalidate_nowait(authority->formation) + != CLUSTER_FORMATION_WITNESS_READY + || !cluster_external_fence_need_set_revalidate_nowait(authority->fence_need_set, + authority->formation, &reason) + || !cluster_external_fence_revalidate_set_nowait(authority->fence_admission_set, + authority->fence_need_set, + authority->formation, &reason)) return CLUSTER_THREAD_AUTHORITY_FENCE_STALE; - if (cluster_wal_retention_pin_revalidate(authority->retention_pin) != - CLUSTER_WAL_PIN_OK) + if (cluster_wal_retention_pin_revalidate(authority->retention_pin) != CLUSTER_WAL_PIN_OK) return CLUSTER_THREAD_AUTHORITY_PIN_STALE; return CLUSTER_THREAD_AUTHORITY_OK; } bool cluster_thread_recovery_authority_covers_window_v1( - const ClusterThreadRecoveryAuthorityV1 *authority, uint16 dead_tid, - XLogRecPtr scan_lower, XLogRecPtr scan_upper) + const ClusterThreadRecoveryAuthorityV1 *authority, uint16 dead_tid, XLogRecPtr scan_lower, + XLogRecPtr scan_upper) { - if (authority == NULL || authority->duty == NULL || - authority->root_snapshot == NULL || authority->root_token == NULL || - authority->retention_pin == NULL || authority->serial_guard == NULL || - !root_owner_exact(dead_tid, authority->duty, - authority->root_snapshot, authority->root_token) || - scan_lower == InvalidXLogRecPtr || scan_upper <= scan_lower) + if (authority == NULL || authority->duty == NULL || authority->root_snapshot == NULL + || authority->root_token == NULL || authority->retention_pin == NULL + || authority->serial_guard == NULL + || !root_owner_exact(dead_tid, authority->duty, authority->root_snapshot, + authority->root_token) + || scan_lower == InvalidXLogRecPtr || scan_upper <= scan_lower) return false; - return scan_lower >= authority->root_snapshot->checkpoint_lower_lsn && - scan_upper <= - authority->root_snapshot->validated_tail_lsn_exclusive; + return scan_lower >= authority->root_snapshot->checkpoint_lower_lsn + && scan_upper <= authority->root_snapshot->validated_tail_lsn_exclusive; } bool cluster_thread_recovery_root_complete_patch_build_v1( - const ClusterThreadRecoveryAuthorityV1 *authority, - XLogRecPtr recovered_through, ClusterControlRootPatch *out_patch) + const ClusterThreadRecoveryAuthorityV1 *authority, XLogRecPtr recovered_through, + ClusterControlRootPatch *out_patch) { const ClusterControlRootSnapshot *root; - const uint32 required_flags = - CLUSTER_CONTROL_ROOT_FLAG_CLAIM_VALID | - CLUSTER_CONTROL_ROOT_FLAG_CHECKPOINT_VALID | - CLUSTER_CONTROL_ROOT_FLAG_TAIL_VALID | - CLUSTER_CONTROL_ROOT_FLAG_TAIL_LAST_RECORD_VALID; + const uint32 required_flags + = CLUSTER_CONTROL_ROOT_FLAG_CLAIM_VALID | CLUSTER_CONTROL_ROOT_FLAG_CHECKPOINT_VALID + | CLUSTER_CONTROL_ROOT_FLAG_TAIL_VALID | CLUSTER_CONTROL_ROOT_FLAG_TAIL_LAST_RECORD_VALID; if (out_patch == NULL) return false; memset(out_patch, 0, sizeof(*out_patch)); - if (authority == NULL || authority->duty == NULL || - authority->root_snapshot == NULL || authority->root_token == NULL || - authority->retention_pin == NULL || authority->serial_guard == NULL || - !authority->serial_guard->held || - memcmp(&authority->serial_guard->duty, authority->duty, - sizeof(*authority->duty)) != 0 || - memcmp(&authority->serial_guard->root_read_token, - authority->root_token, sizeof(*authority->root_token)) != 0) + if (authority == NULL || authority->duty == NULL || authority->root_snapshot == NULL + || authority->root_token == NULL || authority->retention_pin == NULL + || authority->serial_guard == NULL || !authority->serial_guard->held + || memcmp(&authority->serial_guard->duty, authority->duty, sizeof(*authority->duty)) != 0 + || memcmp(&authority->serial_guard->root_read_token, authority->root_token, + sizeof(*authority->root_token)) + != 0) return false; root = authority->root_snapshot; - if (!root_owner_exact(authority->duty->origin_thread_id, - authority->duty, root, authority->root_token) || - (root->root_flags & required_flags) != required_flags || - root->tail_tli == 0 || root->tail_last_record_lsn == 0 || - root->tail_last_record_lsn >= root->validated_tail_lsn_exclusive || - root->tail_last_record_crc32c == 0 || - recovered_through != root->validated_tail_lsn_exclusive) + if (!root_owner_exact(authority->duty->origin_thread_id, authority->duty, root, + authority->root_token) + || (root->root_flags & required_flags) != required_flags || root->tail_tli == 0 + || root->tail_last_record_lsn == 0 + || root->tail_last_record_lsn >= root->validated_tail_lsn_exclusive + || root->tail_last_record_crc32c == 0 + || recovered_through != root->validated_tail_lsn_exclusive) return false; - out_patch->mask = CLUSTER_CONTROL_ROOT_PATCH_LIFECYCLE | - CLUSTER_CONTROL_ROOT_PATCH_RECOVERY_PROGRESS; - out_patch->expected_lifecycle = - CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_REQUIRED; + out_patch->mask + = CLUSTER_CONTROL_ROOT_PATCH_LIFECYCLE | CLUSTER_CONTROL_ROOT_PATCH_RECOVERY_PROGRESS; + out_patch->expected_lifecycle = CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_REQUIRED; out_patch->expected_flags_mask = required_flags; out_patch->expected_flags_value = required_flags; - out_patch->desired.lifecycle = - CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_COMPLETE; - out_patch->desired.root_flags = root->root_flags | - CLUSTER_CONTROL_ROOT_FLAG_RECOVERED_VALID | - CLUSTER_CONTROL_ROOT_FLAG_RECOVERED_LAST_RECORD_VALID; + out_patch->desired.lifecycle = CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_COMPLETE; + out_patch->desired.root_flags = root->root_flags | CLUSTER_CONTROL_ROOT_FLAG_RECOVERED_VALID + | CLUSTER_CONTROL_ROOT_FLAG_RECOVERED_LAST_RECORD_VALID; out_patch->desired.recovered_tli = root->tail_tli; out_patch->desired.recovered_through_lsn_exclusive = recovered_through; out_patch->desired.recovered_last_record_lsn = root->tail_last_record_lsn; - out_patch->desired.recovered_last_record_crc32c = - root->tail_last_record_crc32c; + out_patch->desired.recovered_last_record_crc32c = root->tail_last_record_crc32c; return true; } diff --git a/src/backend/cluster/cluster_thread_recovery_fabric_apply.c b/src/backend/cluster/cluster_thread_recovery_fabric_apply.c index a8c92f930e6..be66dcc11e8 100644 --- a/src/backend/cluster/cluster_thread_recovery_fabric_apply.c +++ b/src/backend/cluster/cluster_thread_recovery_fabric_apply.c @@ -21,15 +21,14 @@ #define fabric_apply_free(pointer_) pfree(pointer_) #endif -typedef struct ClusterThreadRecoveryFabricApplyStateV1 -{ +typedef struct ClusterThreadRecoveryFabricApplyStateV1 { RfPageOnlineTargetViewV1 *views; RfPageStorageInstallComponentV1 *components; RfPageAuthorityTargetV1 *authority_targets; RfPageStableBaseProofV1 **proofs; - uint32 *chain_indices; - char *prepared_pages; - char *io_pages; + uint32 *chain_indices; + char *prepared_pages; + char *io_pages; RfPageAuthorityPreflightV1 *page_preflight; RfPageSmgrPreopenV1 *smgr_preopen; } ClusterThreadRecoveryFabricApplyStateV1; @@ -37,63 +36,61 @@ typedef struct ClusterThreadRecoveryFabricApplyStateV1 static bool fabric_apply_authority_fresh(void *arg) { - const ClusterThreadRecoveryAuthorityV1 *authority = - (const ClusterThreadRecoveryAuthorityV1 *) arg; + const ClusterThreadRecoveryAuthorityV1 *authority + = (const ClusterThreadRecoveryAuthorityV1 *)arg; - return cluster_thread_recovery_authority_revalidate_nowait_v1(authority) == - CLUSTER_THREAD_AUTHORITY_OK; + return cluster_thread_recovery_authority_revalidate_nowait_v1(authority) + == CLUSTER_THREAD_AUTHORITY_OK; } static RfPageProofDetailV1 fabric_apply_map_authority(RfPageAuthorityVerdictV1 verdict) { - switch (verdict) - { - case RF_PAGE_AUTHORITY_OK: - return RF_PAGE_PROOF_DETAIL_OK; - case RF_PAGE_AUTHORITY_INVALID_ARGUMENT: - return RF_PAGE_PROOF_DETAIL_INVALID_ARGUMENT; - case RF_PAGE_AUTHORITY_ROOT_STALE: - case RF_PAGE_AUTHORITY_GENERATION_STALE: - return RF_PAGE_PROOF_DETAIL_ROOT_STALE; - case RF_PAGE_AUTHORITY_FENCE_STALE: - case RF_PAGE_AUTHORITY_SERIAL_NOT_HELD: - return RF_PAGE_PROOF_DETAIL_FENCE_STALE; - case RF_PAGE_AUTHORITY_RETENTION_STALE: - return RF_PAGE_PROOF_DETAIL_RETENTION_STALE; - case RF_PAGE_AUTHORITY_SOURCE_GAP: - return RF_PAGE_PROOF_DETAIL_SOURCE_GAP; - case RF_PAGE_AUTHORITY_NO_STABLE_BASE: - return RF_PAGE_PROOF_DETAIL_ANCHOR_MISSING; - case RF_PAGE_AUTHORITY_CLASS_UNKNOWN: - return RF_PAGE_PROOF_DETAIL_CLASS_UNKNOWN; - case RF_PAGE_AUTHORITY_IDENTITY_MISMATCH: - return RF_PAGE_PROOF_DETAIL_IDENTITY_MISMATCH; - case RF_PAGE_AUTHORITY_INCARNATION_MISMATCH: - return RF_PAGE_PROOF_DETAIL_INCARNATION_MISMATCH; - case RF_PAGE_AUTHORITY_VERSION_RULE_MISSING: - return RF_PAGE_PROOF_DETAIL_VERSION_MISMATCH; - case RF_PAGE_AUTHORITY_CONTRIBUTOR_INCOMPLETE: - return RF_PAGE_PROOF_DETAIL_COMPONENT_INCOMPLETE; - case RF_PAGE_AUTHORITY_SIDE_INCOMPLETE: - return RF_PAGE_PROOF_DETAIL_SIDE_INCOMPLETE; - case RF_PAGE_AUTHORITY_WOULD_BLOCK: - return RF_PAGE_PROOF_DETAIL_WOULD_BLOCK; - case RF_PAGE_AUTHORITY_CANCELLED: - return RF_PAGE_PROOF_DETAIL_CANCELLED; - case RF_PAGE_AUTHORITY_OOM: - return RF_PAGE_PROOF_DETAIL_OOM; - case RF_PAGE_AUTHORITY_INTERNAL: - default: - return RF_PAGE_PROOF_DETAIL_INTERNAL; + switch (verdict) { + case RF_PAGE_AUTHORITY_OK: + return RF_PAGE_PROOF_DETAIL_OK; + case RF_PAGE_AUTHORITY_INVALID_ARGUMENT: + return RF_PAGE_PROOF_DETAIL_INVALID_ARGUMENT; + case RF_PAGE_AUTHORITY_ROOT_STALE: + case RF_PAGE_AUTHORITY_GENERATION_STALE: + return RF_PAGE_PROOF_DETAIL_ROOT_STALE; + case RF_PAGE_AUTHORITY_FENCE_STALE: + case RF_PAGE_AUTHORITY_SERIAL_NOT_HELD: + return RF_PAGE_PROOF_DETAIL_FENCE_STALE; + case RF_PAGE_AUTHORITY_RETENTION_STALE: + return RF_PAGE_PROOF_DETAIL_RETENTION_STALE; + case RF_PAGE_AUTHORITY_SOURCE_GAP: + return RF_PAGE_PROOF_DETAIL_SOURCE_GAP; + case RF_PAGE_AUTHORITY_NO_STABLE_BASE: + return RF_PAGE_PROOF_DETAIL_ANCHOR_MISSING; + case RF_PAGE_AUTHORITY_CLASS_UNKNOWN: + return RF_PAGE_PROOF_DETAIL_CLASS_UNKNOWN; + case RF_PAGE_AUTHORITY_IDENTITY_MISMATCH: + return RF_PAGE_PROOF_DETAIL_IDENTITY_MISMATCH; + case RF_PAGE_AUTHORITY_INCARNATION_MISMATCH: + return RF_PAGE_PROOF_DETAIL_INCARNATION_MISMATCH; + case RF_PAGE_AUTHORITY_VERSION_RULE_MISSING: + return RF_PAGE_PROOF_DETAIL_VERSION_MISMATCH; + case RF_PAGE_AUTHORITY_CONTRIBUTOR_INCOMPLETE: + return RF_PAGE_PROOF_DETAIL_COMPONENT_INCOMPLETE; + case RF_PAGE_AUTHORITY_SIDE_INCOMPLETE: + return RF_PAGE_PROOF_DETAIL_SIDE_INCOMPLETE; + case RF_PAGE_AUTHORITY_WOULD_BLOCK: + return RF_PAGE_PROOF_DETAIL_WOULD_BLOCK; + case RF_PAGE_AUTHORITY_CANCELLED: + return RF_PAGE_PROOF_DETAIL_CANCELLED; + case RF_PAGE_AUTHORITY_OOM: + return RF_PAGE_PROOF_DETAIL_OOM; + case RF_PAGE_AUTHORITY_INTERNAL: + default: + return RF_PAGE_PROOF_DETAIL_INTERNAL; } } static void -fabric_apply_state_free(ClusterThreadRecoveryFabricApplyStateV1 *state, - uint32 target_count) +fabric_apply_state_free(ClusterThreadRecoveryFabricApplyStateV1 *state, uint32 target_count) { - uint32 i; + uint32 i; if (state->smgr_preopen != NULL) rf_page_storage_smgr_preopen_destroy_v1(&state->smgr_preopen); @@ -120,10 +117,9 @@ fabric_apply_state_free(ClusterThreadRecoveryFabricApplyStateV1 *state, } RfPageProofDetailV1 -cluster_thread_recovery_fabric_apply_v1( - const ClusterThreadRecoveryFabricPlanV1 *plan, - const ClusterThreadRecoveryAuthorityV1 *authority, - ClusterThreadRecoveryFabricApplyResultV1 *result) +cluster_thread_recovery_fabric_apply_v1(const ClusterThreadRecoveryFabricPlanV1 *plan, + const ClusterThreadRecoveryAuthorityV1 *authority, + ClusterThreadRecoveryFabricApplyResultV1 *result) { const RfPageOnlinePlanV1 *page_plan; const RfSideOnlinePlanV1 *side_plan; @@ -136,53 +132,44 @@ cluster_thread_recovery_fabric_apply_v1( RfPageAuthorityBatchRequestV1 authority_request; RfContributorStreamCutV1 cut; RfPageProofDetailV1 detail = RF_PAGE_PROOF_DETAIL_INTERNAL; - uint64 current_epoch; - uint32 participant_count; - uint32 target_count; - uint32 max_chain_count = 0; - uint32 i; - bool retained_source_current = false; + uint64 current_epoch; + uint32 participant_count; + uint32 target_count; + uint32 max_chain_count = 0; + uint32 i; + bool retained_source_current = false; if (result == NULL) return RF_PAGE_PROOF_DETAIL_INVALID_ARGUMENT; memset(result, 0, sizeof(*result)); page_plan = cluster_thread_recovery_fabric_page_plan_v1(plan); side_plan = cluster_thread_recovery_fabric_side_plan_v1(plan); - if (page_plan == NULL || side_plan == NULL || authority == NULL || - !fabric_apply_authority_fresh((void *) authority)) + if (page_plan == NULL || side_plan == NULL || authority == NULL + || !fabric_apply_authority_fresh((void *)authority)) return RF_PAGE_PROOF_DETAIL_ROOT_STALE; - participant_count = - cluster_thread_recovery_fabric_participant_count_v1(plan); + participant_count = cluster_thread_recovery_fabric_participant_count_v1(plan); if (participant_count != 1) return RF_PAGE_PROOF_DETAIL_COMPONENT_INCOMPLETE; - if (authority->duty == NULL || authority->root_snapshot == NULL || - !cluster_thread_recovery_fabric_identity_matches_v1(plan, - authority->duty->system_identifier, - authority->duty->storage_uuid) || - !cluster_thread_recovery_fabric_identity_matches_v1(plan, - authority->root_snapshot->identity.system_identifier, + if (authority->duty == NULL || authority->root_snapshot == NULL + || !cluster_thread_recovery_fabric_identity_matches_v1( + plan, authority->duty->system_identifier, authority->duty->storage_uuid) + || !cluster_thread_recovery_fabric_identity_matches_v1( + plan, authority->root_snapshot->identity.system_identifier, authority->root_snapshot->identity.storage_uuid)) return RF_PAGE_PROOF_DETAIL_IDENTITY_MISMATCH; if (!cluster_thread_recovery_fabric_cut_v1(plan, 0, &cut)) return RF_PAGE_PROOF_DETAIL_SOURCE_GAP; - if (cut.failed_thread == 0 || - cut.failed_thread != authority->duty->origin_thread_id || - cut.failed_thread != - authority->root_snapshot->identity.origin_thread_id || - cut.timeline_id == 0 || - cut.timeline_id != authority->root_snapshot->checkpoint_tli || - cut.timeline_id != authority->root_snapshot->tail_tli || - cut.flags != RF_CONTRIBUTOR_CUT_COMPLETE || - cut.scan_begin_inclusive == InvalidXLogRecPtr || - cut.scan_end_exclusive <= cut.scan_begin_inclusive || - cut.scan_begin_inclusive != - authority->root_snapshot->checkpoint_lower_lsn || - cut.scan_end_exclusive != - authority->root_snapshot->validated_tail_lsn_exclusive) + if (cut.failed_thread == 0 || cut.failed_thread != authority->duty->origin_thread_id + || cut.failed_thread != authority->root_snapshot->identity.origin_thread_id + || cut.timeline_id == 0 || cut.timeline_id != authority->root_snapshot->checkpoint_tli + || cut.timeline_id != authority->root_snapshot->tail_tli + || cut.flags != RF_CONTRIBUTOR_CUT_COMPLETE || cut.scan_begin_inclusive == InvalidXLogRecPtr + || cut.scan_end_exclusive <= cut.scan_begin_inclusive + || cut.scan_begin_inclusive != authority->root_snapshot->checkpoint_lower_lsn + || cut.scan_end_exclusive != authority->root_snapshot->validated_tail_lsn_exclusive) return RF_PAGE_PROOF_DETAIL_SOURCE_GAP; - if (!cluster_thread_recovery_authority_covers_window_v1(authority, - cut.failed_thread, cut.scan_begin_inclusive, - cut.scan_end_exclusive)) + if (!cluster_thread_recovery_authority_covers_window_v1( + authority, cut.failed_thread, cut.scan_begin_inclusive, cut.scan_end_exclusive)) return RF_PAGE_PROOF_DETAIL_RETENTION_STALE; retained_source_current = true; current_epoch = cluster_epoch_get_current(); @@ -194,56 +181,43 @@ cluster_thread_recovery_fabric_apply_v1( memset(&state, 0, sizeof(state)); memset(&completed, 0, sizeof(completed)); completed.page_target_count = target_count; - completed.side_operation_count = - rf_side_online_plan_operation_count_v1(side_plan); + completed.side_operation_count = rf_side_online_plan_operation_count_v1(side_plan); - if (target_count > 0) - { - Size page_bytes = (Size) target_count * BLCKSZ; + if (target_count > 0) { + Size page_bytes = (Size)target_count * BLCKSZ; - state.views = (RfPageOnlineTargetViewV1 *) fabric_apply_alloc0( - (Size) target_count * sizeof(*state.views)); - state.components = (RfPageStorageInstallComponentV1 *) - fabric_apply_alloc0((Size) target_count * - sizeof(*state.components)); - state.authority_targets = (RfPageAuthorityTargetV1 *) - fabric_apply_alloc0((Size) target_count * - sizeof(*state.authority_targets)); - state.proofs = (RfPageStableBaseProofV1 **) fabric_apply_alloc0( - (Size) target_count * sizeof(*state.proofs)); - state.prepared_pages = (char *) fabric_apply_alloc0(page_bytes); - state.io_pages = (char *) fabric_apply_alloc0(page_bytes); - if (state.views == NULL || state.components == NULL || - state.authority_targets == NULL || state.proofs == NULL || - state.prepared_pages == NULL || state.io_pages == NULL) - { + state.views = (RfPageOnlineTargetViewV1 *)fabric_apply_alloc0((Size)target_count + * sizeof(*state.views)); + state.components = (RfPageStorageInstallComponentV1 *)fabric_apply_alloc0( + (Size)target_count * sizeof(*state.components)); + state.authority_targets = (RfPageAuthorityTargetV1 *)fabric_apply_alloc0( + (Size)target_count * sizeof(*state.authority_targets)); + state.proofs = (RfPageStableBaseProofV1 **)fabric_apply_alloc0((Size)target_count + * sizeof(*state.proofs)); + state.prepared_pages = (char *)fabric_apply_alloc0(page_bytes); + state.io_pages = (char *)fabric_apply_alloc0(page_bytes); + if (state.views == NULL || state.components == NULL || state.authority_targets == NULL + || state.proofs == NULL || state.prepared_pages == NULL || state.io_pages == NULL) { detail = RF_PAGE_PROOF_DETAIL_OOM; goto done; } - for (i = 0; i < target_count; i++) - { - if (!rf_page_online_plan_target_v1(page_plan, i, - &state.views[i]) || state.views[i].source == NULL || - state.views[i].contributors == NULL || - state.views[i].graph == NULL || - state.views[i].canonical_page == NULL || - state.views[i].contributors->edge_count == 0) - { + for (i = 0; i < target_count; i++) { + if (!rf_page_online_plan_target_v1(page_plan, i, &state.views[i]) + || state.views[i].source == NULL || state.views[i].contributors == NULL + || state.views[i].graph == NULL || state.views[i].canonical_page == NULL + || state.views[i].contributors->edge_count == 0) { detail = RF_PAGE_PROOF_DETAIL_COMPONENT_INCOMPLETE; goto done; } - max_chain_count = Max(max_chain_count, - state.views[i].contributors->edge_count); + max_chain_count = Max(max_chain_count, state.views[i].contributors->edge_count); } - state.chain_indices = (uint32 *) fabric_apply_alloc0( - (Size) max_chain_count * sizeof(*state.chain_indices)); - if (state.chain_indices == NULL) - { + state.chain_indices + = (uint32 *)fabric_apply_alloc0((Size)max_chain_count * sizeof(*state.chain_indices)); + if (state.chain_indices == NULL) { detail = RF_PAGE_PROOF_DETAIL_OOM; goto done; } - for (i = 0; i < target_count; i++) - { + for (i = 0; i < target_count; i++) { RfPageStableBaseProofRequestV1 proof_request; memset(&proof_request, 0, sizeof(proof_request)); @@ -252,49 +226,39 @@ cluster_thread_recovery_fabric_apply_v1( proof_request.root_tokens = authority->root_token; proof_request.formation = authority->formation; proof_request.fence_need_set = authority->fence_need_set; - proof_request.fence_admission_set = - authority->fence_admission_set; + proof_request.fence_admission_set = authority->fence_admission_set; proof_request.retention_pin = authority->retention_pin; - detail = rf_page_stable_base_proof_build_bound_v1(&proof_request, - state.chain_indices, max_chain_count, &state.proofs[i]); + detail = rf_page_stable_base_proof_build_bound_v1(&proof_request, state.chain_indices, + max_chain_count, &state.proofs[i]); if (detail != RF_PAGE_PROOF_DETAIL_OK) goto done; - state.authority_targets[i].page_identity = - state.views[i].page_identity; - state.authority_targets[i].expected_result = - state.views[i].expected_result; + state.authority_targets[i].page_identity = state.views[i].page_identity; + state.authority_targets[i].expected_result = state.views[i].expected_result; state.authority_targets[i].stable_base = state.proofs[i]; state.authority_targets[i].source = state.views[i].source; - state.authority_targets[i].contributors = - state.views[i].contributors; + state.authority_targets[i].contributors = state.views[i].contributors; state.components[i].page_identity = state.views[i].page_identity; state.components[i].before_kind = state.views[i].before_kind; - state.components[i].expected_before = - state.views[i].expected_before; - state.components[i].expected_result = - state.views[i].expected_result; - state.components[i].canonical_page = - state.views[i].canonical_page; + state.components[i].expected_before = state.views[i].expected_before; + state.components[i].expected_result = state.views[i].expected_result; + state.components[i].canonical_page = state.views[i].canonical_page; } memset(&authority_request, 0, sizeof(authority_request)); authority_request.targets = state.authority_targets; authority_request.target_count = target_count; authority_request.formation = authority->formation; authority_request.fence_need_set = authority->fence_need_set; - authority_request.fence_admission_set = - authority->fence_admission_set; + authority_request.fence_admission_set = authority->fence_admission_set; authority_request.retention_pin = authority->retention_pin; authority_request.duties = authority->duty; authority_request.root_tokens = authority->root_token; authority_request.participant_count = participant_count; - detail = fabric_apply_map_authority( - rf_page_authority_batch_preflight_wait_v1(&authority_request, - 1000, &state.page_preflight)); + detail = fabric_apply_map_authority(rf_page_authority_batch_preflight_wait_v1( + &authority_request, 1000, &state.page_preflight)); if (detail != RF_PAGE_PROOF_DETAIL_OK) goto done; if (!rf_page_install_authority_adapter_init_v1(state.page_preflight, - authority->serial_guard, &page_adapter)) - { + authority->serial_guard, &page_adapter)) { detail = RF_PAGE_PROOF_DETAIL_INTERNAL; goto done; } @@ -307,39 +271,32 @@ cluster_thread_recovery_fabric_apply_v1( install_request.io_capacity = page_bytes; install_request.authority = &page_adapter.ops; install_request.global_preflight_ok = true; - detail = rf_page_storage_smgr_preopen_v1(&install_request, - &state.smgr_preopen); + detail = rf_page_storage_smgr_preopen_v1(&install_request, &state.smgr_preopen); if (detail != RF_PAGE_PROOF_DETAIL_OK) goto done; } - if (!rf_side_online_production_owner_init_v1(&side_owner, - (void *) authority, fabric_apply_authority_fresh, - (uint32) current_epoch, retained_source_current)) - { + if (!rf_side_online_production_owner_init_v1(&side_owner, (void *)authority, + fabric_apply_authority_fresh, + (uint32)current_epoch, retained_source_current)) { detail = RF_PAGE_PROOF_DETAIL_ROOT_STALE; goto done; } detail = rf_side_online_production_preflight_v1(side_plan, &side_owner); if (detail != RF_PAGE_PROOF_DETAIL_OK) goto done; - if (target_count > 0) - { + if (target_count > 0) { memset(&install_proof, 0, sizeof(install_proof)); - detail = rf_page_storage_install_smgr_preopened_v1(&install_request, - state.smgr_preopen, &install_proof); + detail = rf_page_storage_install_smgr_preopened_v1(&install_request, state.smgr_preopen, + &install_proof); if (detail != RF_PAGE_PROOF_DETAIL_OK) goto done; completed.page_write_count = install_proof.write_count; completed.page_result_skip_count = install_proof.result_skip_count; - completed.page_durability_complete = - install_proof.durability_complete; + completed.page_durability_complete = install_proof.durability_complete; completed.page_postread_complete = install_proof.postread_complete; - if (!install_proof.proof_published || - !install_proof.authority_released || - !completed.page_durability_complete || - !completed.page_postread_complete) - { + if (!install_proof.proof_published || !install_proof.authority_released + || !completed.page_durability_complete || !completed.page_postread_complete) { detail = RF_PAGE_PROOF_DETAIL_POSTREAD_FAILED; goto done; } @@ -348,8 +305,7 @@ cluster_thread_recovery_fabric_apply_v1( if (detail != RF_PAGE_PROOF_DETAIL_OK) goto done; completed.side_apply_complete = true; - if (!fabric_apply_authority_fresh((void *) authority)) - { + if (!fabric_apply_authority_fresh((void *)authority)) { detail = RF_PAGE_PROOF_DETAIL_ROOT_STALE; goto done; } diff --git a/src/backend/cluster/cluster_thread_recovery_fabric_execute.c b/src/backend/cluster/cluster_thread_recovery_fabric_execute.c index dc4ba1d49b7..bebb1d6b7a3 100644 --- a/src/backend/cluster/cluster_thread_recovery_fabric_execute.c +++ b/src/backend/cluster/cluster_thread_recovery_fabric_execute.c @@ -11,31 +11,28 @@ RfPageProofDetailV1 cluster_thread_recovery_fabric_execute_root_v1( - uint16 dead_thread, XLogRecPtr scan_begin_inclusive, - XLogRecPtr scan_end_exclusive, - const struct ClusterThreadRecoveryAuthorityV1 *authority, - bool space_active, ClusterThreadRecoveryFabricApplyResultV1 *result, - uint64 *out_record_count) + uint16 dead_thread, XLogRecPtr scan_begin_inclusive, XLogRecPtr scan_end_exclusive, + const struct ClusterThreadRecoveryAuthorityV1 *authority, bool space_active, + ClusterThreadRecoveryFabricApplyResultV1 *result, uint64 *out_record_count) { ClusterThreadRecoveryFabricPlanV1 *plan = NULL; ClusterThreadRecoveryFabricApplyResultV1 completed; RfPageProofDetailV1 detail; - uint64 record_count = 0; + uint64 record_count = 0; if (result == NULL || out_record_count == NULL) return RF_PAGE_PROOF_DETAIL_INVALID_ARGUMENT; memset(result, 0, sizeof(*result)); *out_record_count = 0; memset(&completed, 0, sizeof(completed)); - detail = cluster_thread_recovery_fabric_scan_root_v1(dead_thread, - scan_begin_inclusive, scan_end_exclusive, authority, space_active, - &plan, &record_count); + detail = cluster_thread_recovery_fabric_scan_root_v1(dead_thread, scan_begin_inclusive, + scan_end_exclusive, authority, + space_active, &plan, &record_count); if (detail != RF_PAGE_PROOF_DETAIL_OK) return detail; if (plan == NULL) return RF_PAGE_PROOF_DETAIL_INTERNAL; - detail = cluster_thread_recovery_fabric_apply_v1(plan, authority, - &completed); + detail = cluster_thread_recovery_fabric_apply_v1(plan, authority, &completed); cluster_thread_recovery_fabric_plan_destroy_v1(&plan); if (detail != RF_PAGE_PROOF_DETAIL_OK) return detail; diff --git a/src/backend/cluster/cluster_thread_recovery_fabric_plan.c b/src/backend/cluster/cluster_thread_recovery_fabric_plan.c index 4f73f7a9330..e4173b00aa9 100644 --- a/src/backend/cluster/cluster_thread_recovery_fabric_plan.c +++ b/src/backend/cluster/cluster_thread_recovery_fabric_plan.c @@ -19,17 +19,16 @@ #define CLUSTER_THREAD_RECOVERY_FABRIC_PLAN_MAGIC UINT32_C(0x52465031) -struct ClusterThreadRecoveryFabricPlanV1 -{ - uint32 magic; - bool sealed; - bool failed; - bool space_active; - uint8 reserved1; - uint64 system_identifier; - uint8 storage_uuid[16]; - uint32 participant_count; - uint32 record_count; +struct ClusterThreadRecoveryFabricPlanV1 { + uint32 magic; + bool sealed; + bool failed; + bool space_active; + uint8 reserved1; + uint64 system_identifier; + uint8 storage_uuid[16]; + uint32 participant_count; + uint32 record_count; RfContributorStreamCutV1 *physical_cuts; RfPageOnlinePlanV1 *page_plan; RfSideOnlinePlanV1 *side_plan; @@ -37,39 +36,41 @@ struct ClusterThreadRecoveryFabricPlanV1 static RfPageProofDetailV1 fabric_preflight_side_record(void *arg, const RfOpcodeRouteV1 *route, - const RfPageVersionEdgeEntryV1 *edge, const DecodedBkpBlock *block) + const RfPageVersionEdgeEntryV1 *edge, const DecodedBkpBlock *block) { - (void) arg; - return route != NULL && - (route->record_owner == RF_ROUTE_OWNER_SIDE_TYPED || - route->record_owner == RF_ROUTE_OWNER_LOGICAL_NOOP) && - edge == NULL && block == NULL ? RF_PAGE_PROOF_DETAIL_OK : - RF_PAGE_PROOF_DETAIL_SIDE_INCOMPLETE; + (void)arg; + return route != NULL + && (route->record_owner == RF_ROUTE_OWNER_SIDE_TYPED + || route->record_owner == RF_ROUTE_OWNER_LOGICAL_NOOP) + && edge == NULL && block == NULL + ? RF_PAGE_PROOF_DETAIL_OK + : RF_PAGE_PROOF_DETAIL_SIDE_INCOMPLETE; } static RfPageProofDetailV1 fabric_preflight_side_component(void *arg, const RfOpcodeRouteV1 *route, - const RfPageVersionEdgeEntryV1 *edge, const DecodedBkpBlock *block) + const RfPageVersionEdgeEntryV1 *edge, const DecodedBkpBlock *block) { - (void) arg; - return route != NULL && route->record_owner == RF_ROUTE_OWNER_PAGE_CODEC && - edge != NULL && block != NULL && - (edge->page_class == RF_PAGE_CLASS_ROUTED_HEADER || - edge->page_class == RF_PAGE_CLASS_ROUTED_SIDE || - edge->page_class == RF_PAGE_CLASS_ROUTED_SPACE) ? - RF_PAGE_PROOF_DETAIL_OK : RF_PAGE_PROOF_DETAIL_SIDE_INCOMPLETE; + (void)arg; + return route != NULL && route->record_owner == RF_ROUTE_OWNER_PAGE_CODEC && edge != NULL + && block != NULL + && (edge->page_class == RF_PAGE_CLASS_ROUTED_HEADER + || edge->page_class == RF_PAGE_CLASS_ROUTED_SIDE + || edge->page_class == RF_PAGE_CLASS_ROUTED_SPACE) + ? RF_PAGE_PROOF_DETAIL_OK + : RF_PAGE_PROOF_DETAIL_SIDE_INCOMPLETE; } static RfPageProofDetailV1 -fabric_preflight_rebuildable_component(void *arg, - const RfOpcodeRouteV1 *route, const RfPageVersionEdgeEntryV1 *edge, - const DecodedBkpBlock *block) +fabric_preflight_rebuildable_component(void *arg, const RfOpcodeRouteV1 *route, + const RfPageVersionEdgeEntryV1 *edge, + const DecodedBkpBlock *block) { - (void) arg; - return route != NULL && route->record_owner == RF_ROUTE_OWNER_PAGE_CODEC && - edge != NULL && block != NULL && - edge->page_class == RF_PAGE_CLASS_REBUILDABLE_FSM ? - RF_PAGE_PROOF_DETAIL_OK : RF_PAGE_PROOF_DETAIL_CLASS_UNKNOWN; + (void)arg; + return route != NULL && route->record_owner == RF_ROUTE_OWNER_PAGE_CODEC && edge != NULL + && block != NULL && edge->page_class == RF_PAGE_CLASS_REBUILDABLE_FSM + ? RF_PAGE_PROOF_DETAIL_OK + : RF_PAGE_PROOF_DETAIL_CLASS_UNKNOWN; } static void @@ -100,24 +101,21 @@ cluster_thread_recovery_fabric_plan_create_v1( if (out_plan == NULL) return RF_PAGE_PROOF_DETAIL_INVALID_ARGUMENT; *out_plan = NULL; - if (request == NULL || request->physical_cuts == NULL || - request->participant_count == 0 || - request->participant_count > RF_PAGE_STABLE_MAX_PARTICIPANTS || - memcmp(request->reserved_zero, zero_reserved, sizeof(zero_reserved)) != 0) + if (request == NULL || request->physical_cuts == NULL || request->participant_count == 0 + || request->participant_count > RF_PAGE_STABLE_MAX_PARTICIPANTS + || memcmp(request->reserved_zero, zero_reserved, sizeof(zero_reserved)) != 0) return RF_PAGE_PROOF_DETAIL_INVALID_ARGUMENT; - plan = (ClusterThreadRecoveryFabricPlanV1 *) - fabric_alloc0(sizeof(*plan)); + plan = (ClusterThreadRecoveryFabricPlanV1 *)fabric_alloc0(sizeof(*plan)); if (plan == NULL) return RF_PAGE_PROOF_DETAIL_OOM; - plan->physical_cuts = (RfContributorStreamCutV1 *) fabric_alloc0( - (Size) request->participant_count * sizeof(*plan->physical_cuts)); - if (plan->physical_cuts == NULL) - { + plan->physical_cuts = (RfContributorStreamCutV1 *)fabric_alloc0((Size)request->participant_count + * sizeof(*plan->physical_cuts)); + if (plan->physical_cuts == NULL) { fabric_plan_free(plan); return RF_PAGE_PROOF_DETAIL_OOM; } memcpy(plan->physical_cuts, request->physical_cuts, - (Size) request->participant_count * sizeof(*plan->physical_cuts)); + (Size)request->participant_count * sizeof(*plan->physical_cuts)); memset(&page_request, 0, sizeof(page_request)); page_request.system_identifier = request->system_identifier; memcpy(page_request.storage_uuid, request->storage_uuid, 16); @@ -126,8 +124,7 @@ cluster_thread_recovery_fabric_plan_create_v1( page_request.retention_binding_cookie = request->retention_binding_cookie; page_request.memory_budget = request->page_memory_budget; detail = rf_page_online_plan_create_v1(&page_request, &plan->page_plan); - if (detail != RF_PAGE_PROOF_DETAIL_OK) - { + if (detail != RF_PAGE_PROOF_DETAIL_OK) { fabric_plan_free(plan); return detail; } @@ -138,8 +135,7 @@ cluster_thread_recovery_fabric_plan_create_v1( side_request.participant_count = request->participant_count; side_request.memory_budget = request->side_memory_budget; detail = rf_side_online_plan_create_v1(&side_request, &plan->side_plan); - if (detail != RF_PAGE_PROOF_DETAIL_OK) - { + if (detail != RF_PAGE_PROOF_DETAIL_OK) { fabric_plan_free(plan); return detail; } @@ -153,9 +149,9 @@ cluster_thread_recovery_fabric_plan_create_v1( } RfPageProofDetailV1 -cluster_thread_recovery_fabric_plan_feed_record_v1( - ClusterThreadRecoveryFabricPlanV1 *plan, XLogReaderState *record, - uint16 participant_index) +cluster_thread_recovery_fabric_plan_feed_record_v1(ClusterThreadRecoveryFabricPlanV1 *plan, + XLogReaderState *record, + uint16 participant_index) { RfDetachedOwnerOpsV1 owner_ops; RfDetachedRecordPlanV1 record_plan; @@ -163,42 +159,35 @@ cluster_thread_recovery_fabric_plan_feed_record_v1( RfPageProofDetailV1 detail; DecodedXLogRecord *decoded; - if (plan == NULL || plan->magic != - CLUSTER_THREAD_RECOVERY_FABRIC_PLAN_MAGIC || plan->sealed || - plan->failed || record == NULL || record->record == NULL || - participant_index >= plan->participant_count) + if (plan == NULL || plan->magic != CLUSTER_THREAD_RECOVERY_FABRIC_PLAN_MAGIC || plan->sealed + || plan->failed || record == NULL || record->record == NULL + || participant_index >= plan->participant_count) return RF_PAGE_PROOF_DETAIL_INVALID_ARGUMENT; decoded = record->record; memset(&owner_ops, 0, sizeof(owner_ops)); owner_ops.arg = plan; owner_ops.preflight_side_record = fabric_preflight_side_record; owner_ops.preflight_side_component = fabric_preflight_side_component; - owner_ops.preflight_rebuildable_component = - fabric_preflight_rebuildable_component; + owner_ops.preflight_rebuildable_component = fabric_preflight_rebuildable_component; memset(&record_plan, 0, sizeof(record_plan)); - detail = rf_page_detached_preflight_v1(record, plan->space_active, - &owner_ops, &record_plan); + detail = rf_page_detached_preflight_v1(record, plan->space_active, &owner_ops, &record_plan); if (detail != RF_PAGE_PROOF_DETAIL_OK) goto fail; memset(&identity, 0, sizeof(identity)); identity.record.system_identifier = plan->system_identifier; memcpy(identity.record.storage_uuid, plan->storage_uuid, 16); - identity.record.origin_thread = - plan->physical_cuts[participant_index].failed_thread; - identity.record.timeline_id = - plan->physical_cuts[participant_index].timeline_id; + identity.record.origin_thread = plan->physical_cuts[participant_index].failed_thread; + identity.record.timeline_id = plan->physical_cuts[participant_index].timeline_id; identity.record.read_rec_ptr = record->ReadRecPtr; identity.record.end_rec_ptr = record->EndRecPtr; - identity.record.record_crc = (uint32) decoded->header.xl_crc; + identity.record.record_crc = (uint32)decoded->header.xl_crc; identity.record.rmid = decoded->header.xl_rmid; identity.record.info = decoded->header.xl_info; identity.participant_index = participant_index; - detail = rf_page_online_plan_feed_record_v1(plan->page_plan, - &record_plan, &identity); + detail = rf_page_online_plan_feed_record_v1(plan->page_plan, &record_plan, &identity); if (detail != RF_PAGE_PROOF_DETAIL_OK) goto fail; - detail = rf_side_online_plan_feed_record_v1(plan->side_plan, - &record_plan, &identity); + detail = rf_side_online_plan_feed_record_v1(plan->side_plan, &record_plan, &identity); if (detail != RF_PAGE_PROOF_DETAIL_OK) goto fail; plan->record_count++; @@ -210,25 +199,21 @@ cluster_thread_recovery_fabric_plan_feed_record_v1( } RfPageProofDetailV1 -cluster_thread_recovery_fabric_plan_seal_v1( - ClusterThreadRecoveryFabricPlanV1 *plan) +cluster_thread_recovery_fabric_plan_seal_v1(ClusterThreadRecoveryFabricPlanV1 *plan) { RfPageProofDetailV1 detail; - if (plan == NULL || plan->magic != - CLUSTER_THREAD_RECOVERY_FABRIC_PLAN_MAGIC || plan->sealed) + if (plan == NULL || plan->magic != CLUSTER_THREAD_RECOVERY_FABRIC_PLAN_MAGIC || plan->sealed) return RF_PAGE_PROOF_DETAIL_INVALID_ARGUMENT; if (plan->failed) return RF_PAGE_PROOF_DETAIL_COMPONENT_INCOMPLETE; detail = rf_page_online_plan_seal_v1(plan->page_plan); - if (detail != RF_PAGE_PROOF_DETAIL_OK) - { + if (detail != RF_PAGE_PROOF_DETAIL_OK) { plan->failed = true; return detail; } detail = rf_side_online_plan_seal_v1(plan->side_plan); - if (detail != RF_PAGE_PROOF_DETAIL_OK) - { + if (detail != RF_PAGE_PROOF_DETAIL_OK) { plan->failed = true; return detail; } @@ -237,59 +222,56 @@ cluster_thread_recovery_fabric_plan_seal_v1( } const RfPageOnlinePlanV1 * -cluster_thread_recovery_fabric_page_plan_v1( - const ClusterThreadRecoveryFabricPlanV1 *plan) +cluster_thread_recovery_fabric_page_plan_v1(const ClusterThreadRecoveryFabricPlanV1 *plan) { - return plan != NULL && plan->magic == - CLUSTER_THREAD_RECOVERY_FABRIC_PLAN_MAGIC && plan->sealed && - !plan->failed ? plan->page_plan : NULL; + return plan != NULL && plan->magic == CLUSTER_THREAD_RECOVERY_FABRIC_PLAN_MAGIC && plan->sealed + && !plan->failed + ? plan->page_plan + : NULL; } const RfSideOnlinePlanV1 * -cluster_thread_recovery_fabric_side_plan_v1( - const ClusterThreadRecoveryFabricPlanV1 *plan) +cluster_thread_recovery_fabric_side_plan_v1(const ClusterThreadRecoveryFabricPlanV1 *plan) { - return plan != NULL && plan->magic == - CLUSTER_THREAD_RECOVERY_FABRIC_PLAN_MAGIC && plan->sealed && - !plan->failed ? plan->side_plan : NULL; + return plan != NULL && plan->magic == CLUSTER_THREAD_RECOVERY_FABRIC_PLAN_MAGIC && plan->sealed + && !plan->failed + ? plan->side_plan + : NULL; } uint32 -cluster_thread_recovery_fabric_participant_count_v1( - const ClusterThreadRecoveryFabricPlanV1 *plan) +cluster_thread_recovery_fabric_participant_count_v1(const ClusterThreadRecoveryFabricPlanV1 *plan) { - return plan != NULL && plan->magic == - CLUSTER_THREAD_RECOVERY_FABRIC_PLAN_MAGIC && plan->sealed && - !plan->failed ? plan->participant_count : 0; + return plan != NULL && plan->magic == CLUSTER_THREAD_RECOVERY_FABRIC_PLAN_MAGIC && plan->sealed + && !plan->failed + ? plan->participant_count + : 0; } bool -cluster_thread_recovery_fabric_identity_matches_v1( - const ClusterThreadRecoveryFabricPlanV1 *plan, uint64 system_identifier, - const uint8 storage_uuid[16]) +cluster_thread_recovery_fabric_identity_matches_v1(const ClusterThreadRecoveryFabricPlanV1 *plan, + uint64 system_identifier, + const uint8 storage_uuid[16]) { - return storage_uuid != NULL && plan != NULL && plan->magic == - CLUSTER_THREAD_RECOVERY_FABRIC_PLAN_MAGIC && plan->sealed && - !plan->failed && plan->system_identifier == system_identifier && - memcmp(plan->storage_uuid, storage_uuid, 16) == 0; + return storage_uuid != NULL && plan != NULL + && plan->magic == CLUSTER_THREAD_RECOVERY_FABRIC_PLAN_MAGIC && plan->sealed + && !plan->failed && plan->system_identifier == system_identifier + && memcmp(plan->storage_uuid, storage_uuid, 16) == 0; } bool -cluster_thread_recovery_fabric_cut_v1( - const ClusterThreadRecoveryFabricPlanV1 *plan, uint32 index, - RfContributorStreamCutV1 *out_cut) +cluster_thread_recovery_fabric_cut_v1(const ClusterThreadRecoveryFabricPlanV1 *plan, uint32 index, + RfContributorStreamCutV1 *out_cut) { - if (out_cut == NULL || plan == NULL || plan->magic != - CLUSTER_THREAD_RECOVERY_FABRIC_PLAN_MAGIC || !plan->sealed || - plan->failed || index >= plan->participant_count) + if (out_cut == NULL || plan == NULL || plan->magic != CLUSTER_THREAD_RECOVERY_FABRIC_PLAN_MAGIC + || !plan->sealed || plan->failed || index >= plan->participant_count) return false; *out_cut = plan->physical_cuts[index]; return true; } void -cluster_thread_recovery_fabric_plan_destroy_v1( - ClusterThreadRecoveryFabricPlanV1 **plan_address) +cluster_thread_recovery_fabric_plan_destroy_v1(ClusterThreadRecoveryFabricPlanV1 **plan_address) { ClusterThreadRecoveryFabricPlanV1 *plan; diff --git a/src/backend/cluster/cluster_thread_recovery_fabric_scan.c b/src/backend/cluster/cluster_thread_recovery_fabric_scan.c index e8858e82d38..2014961e00b 100644 --- a/src/backend/cluster/cluster_thread_recovery_fabric_scan.c +++ b/src/backend/cluster/cluster_thread_recovery_fabric_scan.c @@ -13,55 +13,53 @@ #include "cluster/cluster_thread_recovery_fabric.h" static bool -fabric_scan_root_exact(uint16 dead_thread, XLogRecPtr scan_begin, - XLogRecPtr scan_end, const ClusterThreadRecoveryAuthorityV1 *authority) +fabric_scan_root_exact(uint16 dead_thread, XLogRecPtr scan_begin, XLogRecPtr scan_end, + const ClusterThreadRecoveryAuthorityV1 *authority) { const ClusterControlRootSnapshot *root; - if (authority == NULL || authority->duty == NULL || - authority->root_snapshot == NULL || authority->retention_pin == NULL) + if (authority == NULL || authority->duty == NULL || authority->root_snapshot == NULL + || authority->retention_pin == NULL) return false; root = authority->root_snapshot; - return dead_thread != 0 && dead_thread == authority->duty->origin_thread_id && - dead_thread == root->identity.origin_thread_id && - memcmp(&root->identity, authority->duty, - sizeof(*authority->duty)) == 0 && - root->checkpoint_tli != 0 && - root->checkpoint_tli == root->tail_tli && - scan_begin != InvalidXLogRecPtr && scan_end > scan_begin && - scan_begin == root->checkpoint_lower_lsn && - scan_end == root->validated_tail_lsn_exclusive; + return dead_thread != 0 && dead_thread == authority->duty->origin_thread_id + && dead_thread == root->identity.origin_thread_id + && memcmp(&root->identity, authority->duty, sizeof(*authority->duty)) == 0 + && root->checkpoint_tli != 0 && root->checkpoint_tli == root->tail_tli + && scan_begin != InvalidXLogRecPtr && scan_end > scan_begin + && scan_begin == root->checkpoint_lower_lsn + && scan_end == root->validated_tail_lsn_exclusive; } RfPageProofDetailV1 -cluster_thread_recovery_fabric_scan_root_v1( - uint16 dead_thread, XLogRecPtr scan_begin_inclusive, - XLogRecPtr scan_end_exclusive, - const ClusterThreadRecoveryAuthorityV1 *authority, - bool space_active, ClusterThreadRecoveryFabricPlanV1 **out_plan, - uint64 *out_record_count) +cluster_thread_recovery_fabric_scan_root_v1(uint16 dead_thread, XLogRecPtr scan_begin_inclusive, + XLogRecPtr scan_end_exclusive, + const ClusterThreadRecoveryAuthorityV1 *authority, + bool space_active, + ClusterThreadRecoveryFabricPlanV1 **out_plan, + uint64 *out_record_count) { ClusterThreadRecoveryFabricPlanRequestV1 request; ClusterThreadRecoveryFabricPlanV1 *plan = NULL; RfContributorStreamCutV1 cut; RfPageProofDetailV1 detail; XLogReaderState *reader = NULL; - void *reader_private = NULL; - char *error_message = NULL; - uint64 record_count = 0; - bool reached_upper = false; + void *reader_private = NULL; + char *error_message = NULL; + uint64 record_count = 0; + bool reached_upper = false; if (out_plan == NULL || out_record_count == NULL) return RF_PAGE_PROOF_DETAIL_INVALID_ARGUMENT; *out_plan = NULL; *out_record_count = 0; - if (cluster_thread_recovery_authority_revalidate_nowait_v1(authority) != - CLUSTER_THREAD_AUTHORITY_OK || - !fabric_scan_root_exact(dead_thread, scan_begin_inclusive, - scan_end_exclusive, authority)) + if (cluster_thread_recovery_authority_revalidate_nowait_v1(authority) + != CLUSTER_THREAD_AUTHORITY_OK + || !fabric_scan_root_exact(dead_thread, scan_begin_inclusive, scan_end_exclusive, + authority)) return RF_PAGE_PROOF_DETAIL_ROOT_STALE; - if (!cluster_thread_recovery_authority_covers_window_v1(authority, - dead_thread, scan_begin_inclusive, scan_end_exclusive)) + if (!cluster_thread_recovery_authority_covers_window_v1( + authority, dead_thread, scan_begin_inclusive, scan_end_exclusive)) return RF_PAGE_PROOF_DETAIL_RETENTION_STALE; memset(&cut, 0, sizeof(cut)); @@ -75,62 +73,51 @@ cluster_thread_recovery_fabric_scan_root_v1( memcpy(request.storage_uuid, authority->duty->storage_uuid, 16); request.physical_cuts = &cut; request.participant_count = 1; - request.retention_binding_cookie = - (uint64) (uintptr_t) authority->retention_pin; + request.retention_binding_cookie = (uint64)(uintptr_t)authority->retention_pin; request.space_active = space_active; detail = cluster_thread_recovery_fabric_plan_create_v1(&request, &plan); if (detail != RF_PAGE_PROOF_DETAIL_OK) return detail; reader = cluster_thread_wal_reader_make(dead_thread, &reader_private); - if (reader == NULL || reader_private == NULL) - { + if (reader == NULL || reader_private == NULL) { detail = RF_PAGE_PROOF_DETAIL_SOURCE_GAP; goto done; } reader->seg.ws_tli = cut.timeline_id; XLogBeginRead(reader, scan_begin_inclusive); - for (;;) - { + for (;;) { XLogRecord *record = XLogReadRecord(reader, &error_message); - if (record == NULL) - { + if (record == NULL) { detail = RF_PAGE_PROOF_DETAIL_SOURCE_GAP; break; } - if ((record_count == 0 && - reader->ReadRecPtr != scan_begin_inclusive) || - reader->ReadRecPtr < scan_begin_inclusive || - reader->EndRecPtr <= reader->ReadRecPtr || - reader->EndRecPtr > scan_end_exclusive) - { + if ((record_count == 0 && reader->ReadRecPtr != scan_begin_inclusive) + || reader->ReadRecPtr < scan_begin_inclusive || reader->EndRecPtr <= reader->ReadRecPtr + || reader->EndRecPtr > scan_end_exclusive) { detail = RF_PAGE_PROOF_DETAIL_SOURCE_GAP; break; } - detail = cluster_thread_recovery_fabric_plan_feed_record_v1(plan, - reader, 0); + detail = cluster_thread_recovery_fabric_plan_feed_record_v1(plan, reader, 0); if (detail != RF_PAGE_PROOF_DETAIL_OK) break; - if (record_count == UINT64_MAX) - { + if (record_count == UINT64_MAX) { detail = RF_PAGE_PROOF_DETAIL_CAPACITY; break; } record_count++; - if (reader->EndRecPtr == scan_end_exclusive) - { + if (reader->EndRecPtr == scan_end_exclusive) { reached_upper = true; break; } } if (!reached_upper) goto done; - if (cluster_thread_recovery_authority_revalidate_nowait_v1(authority) != - CLUSTER_THREAD_AUTHORITY_OK || - !cluster_thread_recovery_authority_covers_window_v1(authority, - dead_thread, scan_begin_inclusive, scan_end_exclusive)) - { + if (cluster_thread_recovery_authority_revalidate_nowait_v1(authority) + != CLUSTER_THREAD_AUTHORITY_OK + || !cluster_thread_recovery_authority_covers_window_v1( + authority, dead_thread, scan_begin_inclusive, scan_end_exclusive)) { detail = RF_PAGE_PROOF_DETAIL_RETENTION_STALE; goto done; } diff --git a/src/backend/cluster/cluster_thread_recovery_finalize.c b/src/backend/cluster/cluster_thread_recovery_finalize.c index 434acd98616..7a671a9322d 100644 --- a/src/backend/cluster/cluster_thread_recovery_finalize.c +++ b/src/backend/cluster/cluster_thread_recovery_finalize.c @@ -17,45 +17,38 @@ root_token_matches_snapshot(const ClusterControlRootReadToken *token, const ClusterControlRootSnapshot *snapshot, const ClusterRecoveryDutyKey *duty) { - return token != NULL && snapshot != NULL && duty != NULL && - memcmp(&snapshot->identity, duty, sizeof(*duty)) == 0 && - memcmp(token->authority_uuid, duty->authority_uuid, 16) == 0 && - token->origin_thread_id == duty->origin_thread_id && - token->source != 0 && token->lifecycle == snapshot->lifecycle && - token->root_lineage_seq == duty->root_lineage_seq && - token->reserved20 == 0 && token->reserved32 == 0 && - token->file_txn_seq != 0 && token->root_publish_seq != 0 && - token->record_crc32c != 0 && token->root_flags == snapshot->root_flags; + return token != NULL && snapshot != NULL && duty != NULL + && memcmp(&snapshot->identity, duty, sizeof(*duty)) == 0 + && memcmp(token->authority_uuid, duty->authority_uuid, 16) == 0 + && token->origin_thread_id == duty->origin_thread_id && token->source != 0 + && token->lifecycle == snapshot->lifecycle + && token->root_lineage_seq == duty->root_lineage_seq && token->reserved20 == 0 + && token->reserved32 == 0 && token->file_txn_seq != 0 && token->root_publish_seq != 0 + && token->record_crc32c != 0 && token->root_flags == snapshot->root_flags; } static bool root_complete_matches(const ClusterControlRootSnapshot *snapshot, - const ClusterControlRootReadToken *token, - const ClusterRecoveryDutyKey *duty, + const ClusterControlRootReadToken *token, const ClusterRecoveryDutyKey *duty, const ClusterControlRootPatch *patch) { - const uint32 recovered_flags = - CLUSTER_CONTROL_ROOT_FLAG_RECOVERED_VALID | - CLUSTER_CONTROL_ROOT_FLAG_RECOVERED_LAST_RECORD_VALID; + const uint32 recovered_flags = CLUSTER_CONTROL_ROOT_FLAG_RECOVERED_VALID + | CLUSTER_CONTROL_ROOT_FLAG_RECOVERED_LAST_RECORD_VALID; - return root_token_matches_snapshot(token, snapshot, duty) && - snapshot->lifecycle == - CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_COMPLETE && - (snapshot->root_flags & recovered_flags) == recovered_flags && - snapshot->recovered_tli == patch->desired.recovered_tli && - snapshot->recovered_through_lsn_exclusive == - patch->desired.recovered_through_lsn_exclusive && - snapshot->recovered_last_record_lsn == - patch->desired.recovered_last_record_lsn && - snapshot->recovered_last_record_crc32c == - patch->desired.recovered_last_record_crc32c; + return root_token_matches_snapshot(token, snapshot, duty) + && snapshot->lifecycle == CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_COMPLETE + && (snapshot->root_flags & recovered_flags) == recovered_flags + && snapshot->recovered_tli == patch->desired.recovered_tli + && snapshot->recovered_through_lsn_exclusive + == patch->desired.recovered_through_lsn_exclusive + && snapshot->recovered_last_record_lsn == patch->desired.recovered_last_record_lsn + && snapshot->recovered_last_record_crc32c == patch->desired.recovered_last_record_crc32c; } ClusterThreadRecoveryRootFinalizeResultV1 -cluster_thread_recovery_root_finalize_after_ir_v1( - const ClusterThreadRecoveryAuthorityV1 *authority, - const ClusterControlRootPatch *patch, - ClusterControlRootSnapshot *out_snapshot) +cluster_thread_recovery_root_finalize_after_ir_v1(const ClusterThreadRecoveryAuthorityV1 *authority, + const ClusterControlRootPatch *patch, + ClusterControlRootSnapshot *out_snapshot) { ClusterControlRootSnapshot current_snapshot; ClusterControlRootReadToken current_token; @@ -64,84 +57,73 @@ cluster_thread_recovery_root_finalize_after_ir_v1( if (out_snapshot == NULL) return CLUSTER_THREAD_ROOT_FINALIZE_INVALID; memset(out_snapshot, 0, sizeof(*out_snapshot)); - if (authority == NULL || authority->duty == NULL || - authority->root_snapshot == NULL || authority->root_token == NULL || - authority->retention_pin == NULL || authority->serial_guard == NULL || - authority->serial_guard->held || - authority->serial_guard->release_uncertain || patch == NULL || - patch->mask != (CLUSTER_CONTROL_ROOT_PATCH_LIFECYCLE | - CLUSTER_CONTROL_ROOT_PATCH_RECOVERY_PROGRESS) || - patch->expected_lifecycle != - CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_REQUIRED || - patch->desired.lifecycle != - CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_COMPLETE || - !root_token_matches_snapshot(authority->root_token, - authority->root_snapshot, authority->duty)) + if (authority == NULL || authority->duty == NULL || authority->root_snapshot == NULL + || authority->root_token == NULL || authority->retention_pin == NULL + || authority->serial_guard == NULL || authority->serial_guard->held + || authority->serial_guard->release_uncertain || patch == NULL + || patch->mask + != (CLUSTER_CONTROL_ROOT_PATCH_LIFECYCLE + | CLUSTER_CONTROL_ROOT_PATCH_RECOVERY_PROGRESS) + || patch->expected_lifecycle != CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_REQUIRED + || patch->desired.lifecycle != CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_COMPLETE + || !root_token_matches_snapshot(authority->root_token, authority->root_snapshot, + authority->duty)) return CLUSTER_THREAD_ROOT_FINALIZE_INVALID; current_snapshot = *authority->root_snapshot; current_token = *authority->root_token; - for (attempt = 0; attempt < CLUSTER_THREAD_ROOT_FINALIZE_MAX_CAS_ATTEMPTS; - attempt++) - { + for (attempt = 0; attempt < CLUSTER_THREAD_ROOT_FINALIZE_MAX_CAS_ATTEMPTS; attempt++) { ClusterControlRootSnapshot published; ClusterControlRootReadToken published_token; ClusterControlRootResult result; - result = cluster_control_root_recovery_complete_publish_v1( - ¤t_token, patch, &published, &published_token); - if (result == CLUSTER_CONTROL_ROOT_OK_PRIMARY) - { - if (!root_complete_matches(&published, &published_token, - authority->duty, patch)) + result = cluster_control_root_recovery_complete_publish_v1(¤t_token, patch, + &published, &published_token); + if (result == CLUSTER_CONTROL_ROOT_OK_PRIMARY) { + if (!root_complete_matches(&published, &published_token, authority->duty, patch)) return CLUSTER_THREAD_ROOT_FINALIZE_BLOCKED; *out_snapshot = published; return CLUSTER_THREAD_ROOT_FINALIZE_OK; } if (result == CLUSTER_CONTROL_ROOT_RELEASE_UNCERTAIN) return CLUSTER_THREAD_ROOT_FINALIZE_CLEANUP_UNCERTAIN; - if (result != CLUSTER_CONTROL_ROOT_STALE_TOKEN && - result != CLUSTER_CONTROL_ROOT_CAS_CONFLICT) + if (result != CLUSTER_CONTROL_ROOT_STALE_TOKEN + && result != CLUSTER_CONTROL_ROOT_CAS_CONFLICT) return result == CLUSTER_CONTROL_ROOT_LOCK_UNAVAILABLE - ? CLUSTER_THREAD_ROOT_FINALIZE_RETRY : - (result == CLUSTER_CONTROL_ROOT_INVALID_ARGUMENT - ? CLUSTER_THREAD_ROOT_FINALIZE_INVALID - : CLUSTER_THREAD_ROOT_FINALIZE_BLOCKED); + ? CLUSTER_THREAD_ROOT_FINALIZE_RETRY + : (result == CLUSTER_CONTROL_ROOT_INVALID_ARGUMENT + ? CLUSTER_THREAD_ROOT_FINALIZE_INVALID + : CLUSTER_THREAD_ROOT_FINALIZE_BLOCKED); result = cluster_control_root_read_canonical( - authority->duty->origin_thread_id, authority->duty, - CLUSTER_CONTROL_ROOT_READ_STRONG, &published, &published_token); + authority->duty->origin_thread_id, authority->duty, CLUSTER_CONTROL_ROOT_READ_STRONG, + &published, &published_token); if (result == CLUSTER_CONTROL_ROOT_RELEASE_UNCERTAIN) return CLUSTER_THREAD_ROOT_FINALIZE_CLEANUP_UNCERTAIN; - if (result != CLUSTER_CONTROL_ROOT_OK_PRIMARY && - result != CLUSTER_CONTROL_ROOT_OK_PRIMARY_DEGRADED) + if (result != CLUSTER_CONTROL_ROOT_OK_PRIMARY + && result != CLUSTER_CONTROL_ROOT_OK_PRIMARY_DEGRADED) return result == CLUSTER_CONTROL_ROOT_LOCK_UNAVAILABLE - ? CLUSTER_THREAD_ROOT_FINALIZE_RETRY : - CLUSTER_THREAD_ROOT_FINALIZE_BLOCKED; - switch (cluster_wal_retention_pin_adopt_root_readback_v1( - authority->retention_pin, ¤t_snapshot, ¤t_token, - &published, &published_token)) - { - case CLUSTER_WAL_PIN_OK: - break; - case CLUSTER_WAL_PIN_RELEASE_UNCERTAIN: - return CLUSTER_THREAD_ROOT_FINALIZE_CLEANUP_UNCERTAIN; - case CLUSTER_WAL_PIN_STALE: - return CLUSTER_THREAD_ROOT_FINALIZE_RETRY; - default: - return CLUSTER_THREAD_ROOT_FINALIZE_BLOCKED; + ? CLUSTER_THREAD_ROOT_FINALIZE_RETRY + : CLUSTER_THREAD_ROOT_FINALIZE_BLOCKED; + switch (cluster_wal_retention_pin_adopt_root_readback_v1(authority->retention_pin, + ¤t_snapshot, ¤t_token, + &published, &published_token)) { + case CLUSTER_WAL_PIN_OK: + break; + case CLUSTER_WAL_PIN_RELEASE_UNCERTAIN: + return CLUSTER_THREAD_ROOT_FINALIZE_CLEANUP_UNCERTAIN; + case CLUSTER_WAL_PIN_STALE: + return CLUSTER_THREAD_ROOT_FINALIZE_RETRY; + default: + return CLUSTER_THREAD_ROOT_FINALIZE_BLOCKED; } - if (published.lifecycle == - CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_COMPLETE) - { - if (!root_complete_matches(&published, &published_token, - authority->duty, patch)) + if (published.lifecycle == CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_COMPLETE) { + if (!root_complete_matches(&published, &published_token, authority->duty, patch)) return CLUSTER_THREAD_ROOT_FINALIZE_RETRY; *out_snapshot = published; return CLUSTER_THREAD_ROOT_FINALIZE_ALREADY_COMPLETE; } - if (published.lifecycle != - CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_REQUIRED) + if (published.lifecycle != CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_REQUIRED) return CLUSTER_THREAD_ROOT_FINALIZE_RETRY; current_snapshot = published; current_token = published_token; diff --git a/src/backend/cluster/cluster_thread_recovery_orchestrator.c b/src/backend/cluster/cluster_thread_recovery_orchestrator.c index e0d6fc0bdd9..271c477d52f 100644 --- a/src/backend/cluster/cluster_thread_recovery_orchestrator.c +++ b/src/backend/cluster/cluster_thread_recovery_orchestrator.c @@ -62,14 +62,14 @@ #include "port/atomics.h" /* replay-slot atomics + barriers (3b-4b) */ #include "portability/instr_time.h" /* PGRAC: spec-4.13 D5 LOG-only latency */ -#include "cluster/cluster_conf.h" /* node_count / has_peers (scope gate) */ -#include "cluster/cluster_elog.h" /* ERRCODE_CLUSTER_THREAD_RECOVERY_BLOCKED */ -#include "cluster/cluster_guc.h" /* GUCs: online flag + shared backend + policy */ -#include "cluster/cluster_ir.h" /* STOP03 held serial guard */ -#include "cluster/cluster_recovery_merge.h" /* node-local authority publish (online) */ -#include "cluster/cluster_recovery_plan.h" /* ClusterThreadReplaySlot + slot accessor */ +#include "cluster/cluster_conf.h" /* node_count / has_peers (scope gate) */ +#include "cluster/cluster_elog.h" /* ERRCODE_CLUSTER_THREAD_RECOVERY_BLOCKED */ +#include "cluster/cluster_guc.h" /* GUCs: online flag + shared backend + policy */ +#include "cluster/cluster_ir.h" /* STOP03 held serial guard */ +#include "cluster/cluster_recovery_merge.h" /* node-local authority publish (online) */ +#include "cluster/cluster_recovery_plan.h" /* ClusterThreadReplaySlot + slot accessor */ #include "cluster/cluster_semantic_activation.h" /* bit22 cutover latch (contract §B) */ -#include "cluster/cluster_thread_recovery.h" /* engine / driver / pure gates */ +#include "cluster/cluster_thread_recovery.h" /* engine / driver / pure gates */ #include "cluster/cluster_thread_recovery_authority.h" #include "cluster/cluster_thread_recovery_fabric.h" #include "cluster/cluster_wal_state.h" /* replay-window slot read */ @@ -98,23 +98,20 @@ cluster_thread_recovery_replay_mark_replaying(uint16 dead_tid, uint64 episode_ep } ClusterThreadReplayMatchResult -cluster_thread_recovery_replay_transition_if_match( - uint16 dead_tid, uint64 attempt_stamp, - ClusterThreadRecReplayState expected, - ClusterThreadRecReplayState target) +cluster_thread_recovery_replay_transition_if_match(uint16 dead_tid, uint64 attempt_stamp, + ClusterThreadRecReplayState expected, + ClusterThreadRecReplayState target) { ClusterThreadReplaySlot *slot = cluster_thread_recovery_replay_slot(dead_tid); uint32 expected_state; if (slot == NULL || attempt_stamp == 0 - || !cluster_thread_recovery_replay_transition_shape_valid(expected, - target)) + || !cluster_thread_recovery_replay_transition_shape_valid(expected, target)) return CLUSTER_THREADREC_MATCH_INVALID; if (pg_atomic_read_u64(&slot->episode_epoch) != attempt_stamp) return CLUSTER_THREADREC_MATCH_STAMP_MISMATCH; expected_state = (uint32)expected; - if (!pg_atomic_compare_exchange_u32(&slot->state, &expected_state, - (uint32)target)) + if (!pg_atomic_compare_exchange_u32(&slot->state, &expected_state, (uint32)target)) return CLUSTER_THREADREC_MATCH_STATE_MISMATCH; return CLUSTER_THREADREC_MATCH_CHANGED; } @@ -276,58 +273,48 @@ cluster_thread_recovery_capability_gate(ClusterThreadRecScope scope) } static ClusterThreadRecResult -cluster_thread_recovery_drive_fabric(uint16 dead_tid, - XLogRecPtr scan_lower, XLogRecPtr scan_upper, - const ClusterThreadRecoveryAuthorityV1 *authority, - ClusterThreadReplayStats *stats) +cluster_thread_recovery_drive_fabric(uint16 dead_tid, XLogRecPtr scan_lower, XLogRecPtr scan_upper, + const ClusterThreadRecoveryAuthorityV1 *authority, + ClusterThreadReplayStats *stats) { volatile RfPageProofDetailV1 detail = RF_PAGE_PROOF_DETAIL_INTERNAL; ClusterThreadRecoveryFabricApplyResultV1 apply_result; - uint64 record_count = 0; + uint64 record_count = 0; MemoryContext caller_ctx = CurrentMemoryContext; memset(&apply_result, 0, sizeof(apply_result)); PG_TRY(); { - detail = cluster_thread_recovery_fabric_execute_root_v1(dead_tid, - scan_lower, scan_upper, authority, false, &apply_result, - &record_count); + detail = cluster_thread_recovery_fabric_execute_root_v1( + dead_tid, scan_lower, scan_upper, authority, false, &apply_result, &record_count); } PG_CATCH(); { - ErrorData *edata; + ErrorData *edata; MemoryContextSwitchTo(caller_ctx); edata = CopyErrorData(); - if (cluster_thread_recovery_should_rethrow(edata->elevel)) - { + if (cluster_thread_recovery_should_rethrow(edata->elevel)) { FreeErrorData(edata); PG_RE_THROW(); } - ereport(LOG, - (errmsg("cluster thread recovery: immutable fabric execution " - "blocked for dead thread %u: %s", - dead_tid, edata->message != NULL ? edata->message : - "unknown"))); + ereport(LOG, (errmsg("cluster thread recovery: immutable fabric execution " + "blocked for dead thread %u: %s", + dead_tid, edata->message != NULL ? edata->message : "unknown"))); FlushErrorState(); FreeErrorData(edata); detail = RF_PAGE_PROOF_DETAIL_INTERNAL; } PG_END_TRY(); - if (detail != RF_PAGE_PROOF_DETAIL_OK || record_count == 0 || - !apply_result.side_apply_complete || - apply_result.page_write_count + - apply_result.page_result_skip_count != - apply_result.page_target_count || - (apply_result.page_target_count > 0 && - (!apply_result.page_durability_complete || - !apply_result.page_postread_complete))) - { - ereport(LOG, - (errmsg("cluster thread recovery: immutable fabric did not close " - "for dead thread %u (detail %d)", dead_tid, - (int) detail))); + if (detail != RF_PAGE_PROOF_DETAIL_OK || record_count == 0 || !apply_result.side_apply_complete + || apply_result.page_write_count + apply_result.page_result_skip_count + != apply_result.page_target_count + || (apply_result.page_target_count > 0 + && (!apply_result.page_durability_complete || !apply_result.page_postread_complete))) { + ereport(LOG, (errmsg("cluster thread recovery: immutable fabric did not close " + "for dead thread %u (detail %d)", + dead_tid, (int)detail))); memset(stats, 0, sizeof(*stats)); return CLUSTER_THREADREC_BLOCKED; } @@ -375,8 +362,8 @@ cluster_thread_recovery_replay_one_window(uint16 dead_tid, XLogRecPtr scan_lower /* dead_tid must name a real thread slot (origin in range). */ if (dead_tid < 1 || dead_tid > CLUSTER_WAL_STATE_SLOT_COUNT) return CLUSTER_THREADREC_BLOCKED; - if (cluster_thread_recovery_authority_revalidate_nowait_v1(authority) != - CLUSTER_THREAD_AUTHORITY_OK) { + if (cluster_thread_recovery_authority_revalidate_nowait_v1(authority) + != CLUSTER_THREAD_AUTHORITY_OK) { cluster_write_fence_note_external_mutation_gate_blocked(); return CLUSTER_THREADREC_BLOCKED; } @@ -393,8 +380,8 @@ cluster_thread_recovery_replay_one_window(uint16 dead_tid, XLogRecPtr scan_lower */ INSTR_TIME_SET_CURRENT(tr_start); /* PGRAC: spec-4.13 D5 replay-phase start */ pgstat_report_wait_start(WAIT_EVENT_CLUSTER_THREAD_RECOVERY); - drive_res = cluster_thread_recovery_drive_fabric(dead_tid, scan_lower, - scan_upper, authority, stats); + drive_res + = cluster_thread_recovery_drive_fabric(dead_tid, scan_lower, scan_upper, authority, stats); pgstat_report_wait_end(); INSTR_TIME_SET_CURRENT(tr_replay_end); /* PGRAC: spec-4.13 D5 replay/visibility done */ @@ -444,11 +431,13 @@ cluster_thread_recovery_replay_one_window(uint16 dead_tid, XLogRecPtr scan_lower /* STOP04 publish gate: the same held IR/formation/NeedSet/ * AdmissionSet must still be current after fabric durability and * immediately before reader authority becomes visible. */ - if (cluster_thread_recovery_authority_revalidate_nowait_v1(authority) != - CLUSTER_THREAD_AUTHORITY_OK) { + if (cluster_thread_recovery_authority_revalidate_nowait_v1(authority) + != CLUSTER_THREAD_AUTHORITY_OK) { cluster_write_fence_note_external_publish_gate_blocked(); - ereport(ERROR, - (errmsg("thread recovery root/fence/pin authority became stale before publish"))); + ereport( + ERROR, + (errmsg( + "thread recovery root/fence/pin authority became stale before publish"))); } /* @@ -565,9 +554,8 @@ cluster_thread_recovery_replay_one(uint16 dead_tid, uint64 episode_epoch, bool shared_fs; int survivors; - if (cluster_thread_recovery_authority_revalidate_nowait_v1(authority) != - CLUSTER_THREAD_AUTHORITY_OK) - { + if (cluster_thread_recovery_authority_revalidate_nowait_v1(authority) + != CLUSTER_THREAD_AUTHORITY_OK) { cluster_write_fence_note_external_mutation_gate_blocked(); return CLUSTER_THREADREC_BLOCKED; } @@ -612,28 +600,23 @@ cluster_thread_recovery_replay_one(uint16 dead_tid, uint64 episode_epoch, uint32 pin_checkpoint_tli; if (!cluster_thread_recovery_projection_current( - dead_tid, episode_epoch, &pin_token, &pin_validated_tail, - &pin_checkpoint_lower, &pin_lifecycle, &pin_tail_tli, - &pin_checkpoint_tli)) { + dead_tid, episode_epoch, &pin_token, &pin_validated_tail, &pin_checkpoint_lower, + &pin_lifecycle, &pin_tail_tli, &pin_checkpoint_tli)) { ereport(LOG, (errmsg("cluster thread recovery: dead thread %u canonical projection " "unavailable -> BLOCKED (kept frozen)", dead_tid))); cluster_thread_recovery_count_blocked(); return CLUSTER_THREADREC_BLOCKED; } - if (memcmp(&pin_token, authority->root_token, sizeof(pin_token)) != 0 || - pin_lifecycle != authority->root_snapshot->lifecycle || - pin_tail_tli != authority->root_snapshot->tail_tli || - pin_checkpoint_tli != authority->root_snapshot->checkpoint_tli || - pin_checkpoint_lower != - authority->root_snapshot->checkpoint_lower_lsn || - pin_validated_tail != - authority->root_snapshot->validated_tail_lsn_exclusive) - { - ereport(LOG, - (errmsg("cluster thread recovery: dead thread %u canonical projection " - "does not match the held root owner -> BLOCKED (kept frozen)", - dead_tid))); + if (memcmp(&pin_token, authority->root_token, sizeof(pin_token)) != 0 + || pin_lifecycle != authority->root_snapshot->lifecycle + || pin_tail_tli != authority->root_snapshot->tail_tli + || pin_checkpoint_tli != authority->root_snapshot->checkpoint_tli + || pin_checkpoint_lower != authority->root_snapshot->checkpoint_lower_lsn + || pin_validated_tail != authority->root_snapshot->validated_tail_lsn_exclusive) { + ereport(LOG, (errmsg("cluster thread recovery: dead thread %u canonical projection " + "does not match the held root owner -> BLOCKED (kept frozen)", + dead_tid))); cluster_thread_recovery_count_blocked(); return CLUSTER_THREADREC_BLOCKED; } @@ -642,23 +625,23 @@ cluster_thread_recovery_replay_one(uint16 dead_tid, uint64 episode_epoch, ereport(LOG, (errmsg("cluster thread recovery: dead thread %u canonical projection " "unusable (checkpoint_lower %X/%X, validated_tail %X/%X) " "-> BLOCKED (kept frozen)", - dead_tid, - LSN_FORMAT_ARGS((XLogRecPtr) pin_checkpoint_lower), - LSN_FORMAT_ARGS((XLogRecPtr) pin_validated_tail)))); + dead_tid, LSN_FORMAT_ARGS((XLogRecPtr)pin_checkpoint_lower), + LSN_FORMAT_ARGS((XLogRecPtr)pin_validated_tail)))); cluster_thread_recovery_count_blocked(); return CLUSTER_THREADREC_BLOCKED; } - lower = (XLogRecPtr) pin_checkpoint_lower; - validated_min = (XLogRecPtr) pin_validated_tail; + lower = (XLogRecPtr)pin_checkpoint_lower; + validated_min = (XLogRecPtr)pin_validated_tail; } else { ClusterWalStateSlot slot; /* Pre-bit22 (frozen §17.8): the wal-state registry is the selected * authority — the restored pre-migration shape (bb7fda782e^). */ if (cluster_wal_state_read_slot(dead_tid, &slot) != CLUSTER_WAL_SLOT_OK) { - ereport(LOG, (errmsg("cluster thread recovery: dead thread %u wal-state slot unreadable " - "-> BLOCKED (kept frozen)", - dead_tid))); + ereport(LOG, + (errmsg("cluster thread recovery: dead thread %u wal-state slot unreadable " + "-> BLOCKED (kept frozen)", + dead_tid))); cluster_thread_recovery_count_blocked(); return CLUSTER_THREADREC_BLOCKED; } @@ -667,14 +650,13 @@ cluster_thread_recovery_replay_one(uint16 dead_tid, uint64 episode_epoch, ereport(LOG, (errmsg("cluster thread recovery: dead thread %u wal-state slot unusable " "(checkpoint_redo %X/%X, highest %X/%X) " "-> BLOCKED (kept frozen)", - dead_tid, - LSN_FORMAT_ARGS((XLogRecPtr) slot.checkpoint_redo_lsn), - LSN_FORMAT_ARGS((XLogRecPtr) slot.highest_lsn)))); + dead_tid, LSN_FORMAT_ARGS((XLogRecPtr)slot.checkpoint_redo_lsn), + LSN_FORMAT_ARGS((XLogRecPtr)slot.highest_lsn)))); cluster_thread_recovery_count_blocked(); return CLUSTER_THREADREC_BLOCKED; } - lower = (XLogRecPtr) slot.checkpoint_redo_lsn; - validated_min = (XLogRecPtr) slot.highest_lsn; + lower = (XLogRecPtr)slot.checkpoint_redo_lsn; + validated_min = (XLogRecPtr)slot.highest_lsn; } /* @@ -693,22 +675,20 @@ cluster_thread_recovery_replay_one(uint16 dead_tid, uint64 episode_epoch, cluster_thread_recovery_count_blocked(); return CLUSTER_THREADREC_BLOCKED; } - if (cluster_thread_recovery_authority_revalidate_nowait_v1(authority) != - CLUSTER_THREAD_AUTHORITY_OK || - !cluster_thread_recovery_authority_covers_window_v1( - authority, dead_tid, lower, scan_upper)) - { - ereport(LOG, - (errmsg("cluster thread recovery: dead thread %u validated window " - "is outside the held WAL retention authority -> BLOCKED (kept frozen)", - dead_tid))); + if (cluster_thread_recovery_authority_revalidate_nowait_v1(authority) + != CLUSTER_THREAD_AUTHORITY_OK + || !cluster_thread_recovery_authority_covers_window_v1(authority, dead_tid, lower, + scan_upper)) { + ereport(LOG, (errmsg("cluster thread recovery: dead thread %u validated window " + "is outside the held WAL retention authority -> BLOCKED (kept frozen)", + dead_tid))); cluster_write_fence_note_external_mutation_gate_blocked(); cluster_thread_recovery_count_blocked(); return CLUSTER_THREADREC_BLOCKED; } - return cluster_thread_recovery_replay_one_window( - dead_tid, lower, scan_upper, episode_epoch, authority, NULL); + return cluster_thread_recovery_replay_one_window(dead_tid, lower, scan_upper, episode_epoch, + authority, NULL); } /* diff --git a/src/backend/cluster/cluster_thread_recovery_orchestrator_srf.c b/src/backend/cluster/cluster_thread_recovery_orchestrator_srf.c index 4fb681c3bbb..6f899e4ad02 100644 --- a/src/backend/cluster/cluster_thread_recovery_orchestrator_srf.c +++ b/src/backend/cluster/cluster_thread_recovery_orchestrator_srf.c @@ -167,7 +167,7 @@ cluster_thread_capability_gate_test(PG_FUNCTION_ARGS) else if (scope_arg > (int32)CLUSTER_THREADREC_SCOPE_NO_SHARED_BACKEND) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("scope %d out of range [0, %d]", scope_arg, - (int)CLUSTER_THREADREC_SCOPE_NO_SHARED_BACKEND))); + (int)CLUSTER_THREADREC_SCOPE_NO_SHARED_BACKEND))); else scope = (ClusterThreadRecScope)scope_arg; diff --git a/src/backend/cluster/cluster_thread_recovery_replay.c b/src/backend/cluster/cluster_thread_recovery_replay.c index 88755300d21..d712f0f30e3 100644 --- a/src/backend/cluster/cluster_thread_recovery_replay.c +++ b/src/backend/cluster/cluster_thread_recovery_replay.c @@ -88,7 +88,7 @@ #include "cluster/cluster_page_version.h" #include "cluster/cluster_side_recovery.h" #include "cluster/cluster_side_route.h" -#include "cluster/cluster_side_prepared.h" /* D-SIDE-03 production judge (队列 ④) */ +#include "cluster/cluster_side_prepared.h" /* D-SIDE-03 production judge (队列 ④) */ #include "cluster/cluster_side_projection.h" /* D-SIDE-04 production judge (队列 ④) */ #include "cluster/cluster_side_stats.h" #include "cluster/storage/cluster_smgr.h" @@ -147,8 +147,7 @@ touched_add(ClusterThreadTouchedRels *touched, const RelFileLocator *rl, ForkNum * (the production post-read/authority wiring is RED), so the outcome is * the honest deny — the failed-origin interval stays retained. */ -static void -cluster_thread_recovery_retention_judge(const ClusterThreadTouchedRels *touched); +static void cluster_thread_recovery_retention_judge(const ClusterThreadTouchedRels *touched); void cluster_thread_recovery_touched_sync_all(const ClusterThreadTouchedRels *touched) @@ -204,13 +203,13 @@ cluster_thread_recovery_retention_judge(const ClusterThreadTouchedRels *touched) memset(&proof, 0, sizeof(proof)); memset(&handoff, 0, sizeof(handoff)); - handoff.proof = &proof; /* incomplete proof: FND-10 denies */ - (void) cluster_page_handoff_ready(&handoff); + handoff.proof = &proof; /* incomplete proof: FND-10 denies */ + (void)cluster_page_handoff_ready(&handoff); memset(&retention, 0, sizeof(retention)); - retention.failed_origin_thread = - (touched != NULL ? touched->origin_thread_id : 0); /* real dead_tid */ - retention.affected_count = (uint32) (touched != NULL ? touched->n : 0); + retention.failed_origin_thread + = (touched != NULL ? touched->origin_thread_id : 0); /* real dead_tid */ + retention.affected_count = (uint32)(touched != NULL ? touched->n : 0); retention.all_bytes_durable = true; /* smgrimmedsync just ran */ retention.all_post_read_ok = false; /* post-read wiring RED */ retention.consumers_zero = false; /* consumers wiring RED */ @@ -375,9 +374,9 @@ cluster_thread_recovery_page_judge(XLogReaderState *reader, uint8 block_id, ClusterSideReadinessInput ready; ClusterPageClass cls; ClusterPageApplyVerdict verdict; - uint8 rmid; - uint16 opcode; - bool decoded_ok; + uint8 rmid; + uint16 opcode; + bool decoded_ok; if (!stats_inited) { cluster_page_stats_init(&page_stats); @@ -394,11 +393,10 @@ cluster_thread_recovery_page_judge(XLogReaderState *reader, uint8 block_id, cin.opcode = opcode; cin.forknum = forknum; cin.has_full_page_image = XLogRecHasBlockRef(reader, block_id) - && XLogRecHasBlockImage(reader, block_id) - && XLogRecBlockImageApply(reader, block_id); + && XLogRecHasBlockImage(reader, block_id) + && XLogRecBlockImageApply(reader, block_id); cls = cluster_page_classify(&cin); - if (cls == CLUSTER_PAGE_CLASS_UNKNOWN - || cls == CLUSTER_PAGE_CLASS_UNCLASSIFIED) + if (cls == CLUSTER_PAGE_CLASS_UNKNOWN || cls == CLUSTER_PAGE_CLASS_UNCLASSIFIED) cluster_page_stats_unknown_class_blocked(&page_stats); /* 2. §3.1 decode (census-gated identity + hints). */ @@ -407,7 +405,7 @@ cluster_thread_recovery_page_judge(XLogReaderState *reader, uint8 block_id, if (!decoded_ok) { cluster_page_stats_source_missing(&page_stats); cluster_side_stats_blocked(&side_stats, true); - return; /* no identity: the chain fails closed */ + return; /* no identity: the chain fails closed */ } /* 3. §3.2 admission — the VersionToken producer contract is RED, so @@ -422,13 +420,13 @@ cluster_thread_recovery_page_judge(XLogReaderState *reader, uint8 block_id, consume.identity = &decoded.identity; consume.page_class = decoded.page_class; consume.expected_before = NULL; /* no producer yet: fails closed */ - (void) cluster_side_page_consumer_ready(&consume); + (void)cluster_side_page_consumer_ready(&consume); memset(&ready, 0, sizeof(ready)); - ready.resource_id = (uint16) blocknum; - (void) cluster_side_resource_readiness(&ready); + ready.resource_id = (uint16)blocknum; + (void)cluster_side_resource_readiness(&ready); cluster_side_stats_domain(&side_stats, CLUSTER_SIDE_ROUTE_TT_UNDO); cluster_side_stats_durability(&side_stats); - (void) rl; + (void)rl; } /* @@ -457,8 +455,7 @@ cluster_thread_recovery_prepared_judge(XLogReaderState *reader, uint8 info) uint8 opmask = info & XLOG_XACT_OPMASK; uint32 data_len; - if (opmask != XLOG_XACT_PREPARE - && opmask != XLOG_XACT_COMMIT_PREPARED + if (opmask != XLOG_XACT_PREPARE && opmask != XLOG_XACT_COMMIT_PREPARED && opmask != XLOG_XACT_ABORT_PREPARED) return; if (reader == NULL) @@ -470,7 +467,7 @@ cluster_thread_recovery_prepared_judge(XLogReaderState *reader, uint8 info) if (opmask == XLOG_XACT_PREPARE) { ClusterSidePreparedInput in; - xl_xact_prepare *xlrec = (xl_xact_prepare *) XLogRecGetData(reader); + xl_xact_prepare *xlrec = (xl_xact_prepare *)XLogRecGetData(reader); data_len = XLogRecGetDataLen(reader); memset(&in, 0, sizeof(in)); @@ -478,11 +475,10 @@ cluster_thread_recovery_prepared_judge(XLogReaderState *reader, uint8 info) * it); the GID leg requires a well-formed non-empty GID that fits * inside the record payload. */ in.prepare_redo_ok = true; - in.gid_identity_match = xlrec != NULL - && data_len >= sizeof(xl_xact_prepare) - && cluster_side_prepared_gid_identity_ok( - (const char *) xlrec + sizeof(xl_xact_prepare), - xlrec->gidlen, data_len - (uint32) sizeof(xl_xact_prepare)); + in.gid_identity_match = xlrec != NULL && data_len >= sizeof(xl_xact_prepare) + && cluster_side_prepared_gid_identity_ok( + (const char *)xlrec + sizeof(xl_xact_prepare), xlrec->gidlen, + data_len - (uint32)sizeof(xl_xact_prepare)); /* G3 gap: no durable database-scoped pending store, no TT/undo * match producer — the honest fail-closed legs. */ in.pending_durable_ok = false; @@ -492,17 +488,17 @@ cluster_thread_recovery_prepared_judge(XLogReaderState *reader, uint8 info) ClusterSidePreparedResolveInput r; memset(&r, 0, sizeof(r)); - r.terminal_redo_ok = true; /* we are replaying the terminal */ - r.pending_match = false; /* G3 gap: no pending store */ + r.terminal_redo_ok = true; /* we are replaying the terminal */ + r.pending_match = false; /* G3 gap: no pending store */ r.tt_undo_complete = false; - (void) cluster_side_prepared_resolve_ready(&r); + (void)cluster_side_prepared_resolve_ready(&r); verdict = CLUSTER_SIDE_PREPARED_BLOCKED; } if (verdict == CLUSTER_SIDE_PREPARED_IN_DOUBT) cluster_side_stats_domain(&side_stats, CLUSTER_SIDE_ROUTE_TT_UNDO); else cluster_side_stats_blocked(&side_stats, false); - (void) verdict; + (void)verdict; } /* @@ -543,8 +539,8 @@ cluster_thread_recovery_projection_judge(XLogReaderState *reader) /* canonical_truth_ok / coverage / integrity / producer / retention: * all RED in production — verification and rebuildability both fail * closed and the lookup refuses (no projection is ever served). */ - (void) cluster_side_projection_lookup(false); - (void) cluster_side_projection_rebuildable(kind, false, false); + (void)cluster_side_projection_lookup(false); + (void)cluster_side_projection_rebuildable(kind, false, false); /* D-SIDE-04 real exporter: this IS the projection route (CLOG / * MULTIXACT / COMMIT_TS redo in the replay stream), so the domain * counter must land in the projection bucket — never the TT/undo diff --git a/src/backend/cluster/cluster_thread_recovery_worker.c b/src/backend/cluster/cluster_thread_recovery_worker.c index b8f875e00a6..4c3648a00c7 100644 --- a/src/backend/cluster/cluster_thread_recovery_worker.c +++ b/src/backend/cluster/cluster_thread_recovery_worker.c @@ -56,15 +56,15 @@ #include "utils/timestamp.h" #include "utils/wait_event.h" -#include "cluster/cluster_conf.h" /* node_count / has_peers / CLUSTER_MAX_NODES */ -#include "cluster/cluster_external_fence.h" /* STOP04 NeedSet/AdmissionSet */ -#include "cluster/cluster_grd.h" /* live recovery episode epoch (L235) */ -#include "cluster/cluster_guc.h" /* cluster_online_thread_recovery (scope) */ -#include "cluster/cluster_ir.h" /* spec-5.7 D8 — IR(X) recovery-owner gate */ +#include "cluster/cluster_conf.h" /* node_count / has_peers / CLUSTER_MAX_NODES */ +#include "cluster/cluster_external_fence.h" /* STOP04 NeedSet/AdmissionSet */ +#include "cluster/cluster_grd.h" /* live recovery episode epoch (L235) */ +#include "cluster/cluster_guc.h" /* cluster_online_thread_recovery (scope) */ +#include "cluster/cluster_ir.h" /* spec-5.7 D8 — IR(X) recovery-owner gate */ #include "cluster/cluster_recovery_duty.h" -#include "cluster/cluster_recovery_plan.h" /* RF-ROOT P7 G1b: pinned projection API */ +#include "cluster/cluster_recovery_plan.h" /* RF-ROOT P7 G1b: pinned projection API */ #include "cluster/cluster_semantic_activation.h" /* bit22 cutover latch (contract §B) */ -#include "cluster/cluster_thread_recovery.h" /* slot helpers + replay_one + gates */ +#include "cluster/cluster_thread_recovery.h" /* slot helpers + replay_one + gates */ #include "cluster/cluster_thread_recovery_authority.h" #include "cluster/storage/cluster_shared_fs.h" /* shared backend (scope) */ @@ -75,8 +75,7 @@ * publishes nothing, and leaves the slot for the live episode (keep frozen). */ static ClusterThreadRecResult -thread_recovery_worker_run( - const ClusterThreadRecLaunchEligibility *eligibility) +thread_recovery_worker_run(const ClusterThreadRecLaunchEligibility *eligibility) { ClusterFormationWitnessV1 *formation = NULL; PgracExternalFenceNeedSetV1 *needs = NULL; @@ -112,10 +111,9 @@ thread_recovery_worker_run( /* The launch must have marked the slot REPLAYING; anything else means this * spawn raced a reset or a newer launch -> moot (do not touch the slot). */ - slot_read = cluster_thread_recovery_replay_read(dead_tid, &state, - &launch_epoch); - if (!cluster_thread_recovery_worker_start_valid( - eligibility, dead_tid, slot_read, state, launch_epoch)) + slot_read = cluster_thread_recovery_replay_read(dead_tid, &state, &launch_epoch); + if (!cluster_thread_recovery_worker_start_valid(eligibility, dead_tid, slot_read, state, + launch_epoch)) return CLUSTER_THREADREC_DEFERRED; /* L235 BEFORE: a stale launch epoch means the reconfig episode advanced past @@ -128,39 +126,34 @@ thread_recovery_worker_run( /* All waitable evidence is obtained before IR. The current provider-0 * package deterministically stops at NeedSet/admit with BLOCKED and performs * zero GES/replay/publish; a future certified provider uses this same order. */ - formation_result = cluster_formation_witness_build_wait( - dead_tid, false, fence_timeout_ms, - &formation); + formation_result + = cluster_formation_witness_build_wait(dead_tid, false, fence_timeout_ms, &formation); if (formation_result != CLUSTER_FORMATION_WITNESS_READY) - return formation_result == CLUSTER_FORMATION_WITNESS_UNSTABLE || - formation_result == CLUSTER_FORMATION_WITNESS_MARKER_UNPROVEN || - formation_result == CLUSTER_FORMATION_WITNESS_IO_FAILED - ? CLUSTER_THREADREC_DEFERRED : CLUSTER_THREADREC_BLOCKED; - - need_result = cluster_external_fence_need_set_build( - &eligibility->duty, formation, &needs); - if (need_result != PGRAC_EXTERNAL_FENCE_NEED_SET_OK) - { + return formation_result == CLUSTER_FORMATION_WITNESS_UNSTABLE + || formation_result == CLUSTER_FORMATION_WITNESS_MARKER_UNPROVEN + || formation_result == CLUSTER_FORMATION_WITNESS_IO_FAILED + ? CLUSTER_THREADREC_DEFERRED + : CLUSTER_THREADREC_BLOCKED; + + need_result = cluster_external_fence_need_set_build(&eligibility->duty, formation, &needs); + if (need_result != PGRAC_EXTERNAL_FENCE_NEED_SET_OK) { cluster_formation_witness_destroy(&formation); - return need_result == PGRAC_EXTERNAL_FENCE_NEED_SET_MEMBERSHIP_UNSTABLE || - need_result == PGRAC_EXTERNAL_FENCE_NEED_SET_FENCE_AUTHORITY_UNAVAILABLE - ? CLUSTER_THREADREC_DEFERRED : CLUSTER_THREADREC_BLOCKED; + return need_result == PGRAC_EXTERNAL_FENCE_NEED_SET_MEMBERSHIP_UNSTABLE + || need_result == PGRAC_EXTERNAL_FENCE_NEED_SET_FENCE_AUTHORITY_UNAVAILABLE + ? CLUSTER_THREADREC_DEFERRED + : CLUSTER_THREADREC_BLOCKED; } - fence_verdict = cluster_external_fence_admit_set_wait( - needs, formation, fence_timeout_ms, - &admissions); - if (fence_verdict != PGRAC_EXTERNAL_FENCE_WRITE_EXCLUDED) - { + fence_verdict + = cluster_external_fence_admit_set_wait(needs, formation, fence_timeout_ms, &admissions); + if (fence_verdict != PGRAC_EXTERNAL_FENCE_WRITE_EXCLUDED) { cluster_external_fence_admission_set_release(&admissions); cluster_external_fence_need_set_release(&needs); cluster_formation_witness_destroy(&formation); return CLUSTER_THREADREC_BLOCKED; } - if (!cluster_external_fence_need_set_revalidate_nowait( - needs, formation, &deny_reason) || - !cluster_external_fence_revalidate_set_nowait( - admissions, needs, formation, &deny_reason)) - { + if (!cluster_external_fence_need_set_revalidate_nowait(needs, formation, &deny_reason) + || !cluster_external_fence_revalidate_set_nowait(admissions, needs, formation, + &deny_reason)) { cluster_external_fence_admission_set_release(&admissions); cluster_external_fence_need_set_release(&needs); cluster_formation_witness_destroy(&formation); @@ -168,33 +161,27 @@ thread_recovery_worker_run( } root_result = cluster_control_root_read_canonical( - eligibility->duty.origin_thread_id, &eligibility->duty, - CLUSTER_CONTROL_ROOT_READ_STRONG, &root_snapshot, &root_token); - if ((root_result != CLUSTER_CONTROL_ROOT_OK_PRIMARY && - root_result != CLUSTER_CONTROL_ROOT_OK_PRIMARY_DEGRADED) || - root_snapshot.lifecycle != - CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_REQUIRED || - memcmp(&root_snapshot.identity, &eligibility->duty, - sizeof(eligibility->duty)) != 0) - { + eligibility->duty.origin_thread_id, &eligibility->duty, CLUSTER_CONTROL_ROOT_READ_STRONG, + &root_snapshot, &root_token); + if ((root_result != CLUSTER_CONTROL_ROOT_OK_PRIMARY + && root_result != CLUSTER_CONTROL_ROOT_OK_PRIMARY_DEGRADED) + || root_snapshot.lifecycle != CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_REQUIRED + || memcmp(&root_snapshot.identity, &eligibility->duty, sizeof(eligibility->duty)) != 0) { cluster_external_fence_admission_set_release(&admissions); cluster_external_fence_need_set_release(&needs); cluster_formation_witness_destroy(&formation); return CLUSTER_THREADREC_DEFERRED; } - if (!cluster_thread_recovery_pin_request_build_v1( - dead_tid, &eligibility->duty, &root_snapshot, &root_token, - formation, needs, admissions, &pin_interval, &pin_request)) - { + if (!cluster_thread_recovery_pin_request_build_v1(dead_tid, &eligibility->duty, &root_snapshot, + &root_token, formation, needs, admissions, + &pin_interval, &pin_request)) { cluster_external_fence_admission_set_release(&admissions); cluster_external_fence_need_set_release(&needs); cluster_formation_witness_destroy(&formation); return CLUSTER_THREADREC_DEFERRED; } - pin_result = cluster_wal_retention_pin_acquire( - &pin_request, 1, &retention_pin); - if (pin_result != CLUSTER_WAL_PIN_OK) - { + pin_result = cluster_wal_retention_pin_acquire(&pin_request, 1, &retention_pin); + if (pin_result != CLUSTER_WAL_PIN_OK) { /* A non-NULL failed acquisition is release-uncertain. Its ResourceOwner * callback must retain the borrowed fence owners until process exit. */ if (retention_pin != NULL) @@ -202,9 +189,9 @@ thread_recovery_worker_run( cluster_external_fence_admission_set_release(&admissions); cluster_external_fence_need_set_release(&needs); cluster_formation_witness_destroy(&formation); - return pin_result == CLUSTER_WAL_PIN_UNAVAILABLE || - pin_result == CLUSTER_WAL_PIN_STALE - ? CLUSTER_THREADREC_DEFERRED : CLUSTER_THREADREC_BLOCKED; + return pin_result == CLUSTER_WAL_PIN_UNAVAILABLE || pin_result == CLUSTER_WAL_PIN_STALE + ? CLUSTER_THREADREC_DEFERRED + : CLUSTER_THREADREC_BLOCKED; } memset(&serial_request, 0, sizeof(serial_request)); serial_request.mode = CLUSTER_RECOVERY_SERIAL_ONLINE; @@ -215,10 +202,8 @@ thread_recovery_worker_run( serial_request.fence_admission_set = admissions; serial_request.acquire_timeout_ms = fence_timeout_ms; serial_request.release_timeout_ms = fence_timeout_ms; - serial_result = cluster_recovery_serial_acquire( - &serial_request, &serial_guard); - if (serial_result != CLUSTER_RECOVERY_SERIAL_GRANTED) - { + serial_result = cluster_recovery_serial_acquire(&serial_request, &serial_guard); + if (serial_result != CLUSTER_RECOVERY_SERIAL_GRANTED) { walr_release_result = cluster_wal_retention_pin_release(&retention_pin); if (walr_release_result != CLUSTER_WALR_RELEASE_CONFIRMED) return CLUSTER_THREADREC_BLOCKED; @@ -226,22 +211,21 @@ thread_recovery_worker_run( cluster_external_fence_need_set_release(&needs); cluster_formation_witness_destroy(&formation); return serial_result == CLUSTER_RECOVERY_SERIAL_INTERNAL_FAILURE - ? CLUSTER_THREADREC_BLOCKED : CLUSTER_THREADREC_DEFERRED; + ? CLUSTER_THREADREC_BLOCKED + : CLUSTER_THREADREC_DEFERRED; } - pin_result = cluster_wal_retention_pin_bind_one( - retention_pin, &serial_guard); - if (pin_result != CLUSTER_WAL_PIN_OK) - { + pin_result = cluster_wal_retention_pin_bind_one(retention_pin, &serial_guard); + if (pin_result != CLUSTER_WAL_PIN_OK) { release_result = cluster_recovery_serial_release(&serial_guard); walr_release_result = cluster_wal_retention_pin_release(&retention_pin); - if (release_result != CLUSTER_RECOVERY_SERIAL_RELEASE_CONFIRMED || - walr_release_result != CLUSTER_WALR_RELEASE_CONFIRMED) + if (release_result != CLUSTER_RECOVERY_SERIAL_RELEASE_CONFIRMED + || walr_release_result != CLUSTER_WALR_RELEASE_CONFIRMED) return CLUSTER_THREADREC_BLOCKED; cluster_external_fence_admission_set_release(&admissions); cluster_external_fence_need_set_release(&needs); cluster_formation_witness_destroy(&formation); - return pin_result == CLUSTER_WAL_PIN_STALE - ? CLUSTER_THREADREC_DEFERRED : CLUSTER_THREADREC_BLOCKED; + return pin_result == CLUSTER_WAL_PIN_STALE ? CLUSTER_THREADREC_DEFERRED + : CLUSTER_THREADREC_BLOCKED; } memset(&authority, 0, sizeof(authority)); authority.duty = &eligibility->duty; @@ -252,27 +236,21 @@ thread_recovery_worker_run( authority.fence_admission_set = admissions; authority.retention_pin = retention_pin; authority.serial_guard = &serial_guard; - if (cluster_thread_recovery_authority_revalidate_nowait_v1(&authority) != - CLUSTER_THREAD_AUTHORITY_OK) - { + if (cluster_thread_recovery_authority_revalidate_nowait_v1(&authority) + != CLUSTER_THREAD_AUTHORITY_OK) { cluster_write_fence_note_external_mutation_gate_blocked(); result = CLUSTER_THREADREC_DEFERRED; - } - else - { + } else { PG_TRY(); { - result = cluster_thread_recovery_replay_one( - dead_tid, launch_epoch, &authority); + result = cluster_thread_recovery_replay_one(dead_tid, launch_epoch, &authority); } PG_CATCH(); { release_result = cluster_recovery_serial_release(&serial_guard); - walr_release_result = - cluster_wal_retention_pin_release(&retention_pin); - if (release_result == CLUSTER_RECOVERY_SERIAL_RELEASE_CONFIRMED && - walr_release_result == CLUSTER_WALR_RELEASE_CONFIRMED) - { + walr_release_result = cluster_wal_retention_pin_release(&retention_pin); + if (release_result == CLUSTER_RECOVERY_SERIAL_RELEASE_CONFIRMED + && walr_release_result == CLUSTER_WALR_RELEASE_CONFIRMED) { cluster_external_fence_admission_set_release(&admissions); cluster_external_fence_need_set_release(&needs); cluster_formation_witness_destroy(&formation); @@ -284,13 +262,13 @@ thread_recovery_worker_run( /* IR and WAL retention stay held through replay_one's publish. A stale * final bundle forbids DONE even if replay completed. */ - if (cluster_thread_recovery_authority_revalidate_nowait_v1(&authority) != - CLUSTER_THREAD_AUTHORITY_OK) + if (cluster_thread_recovery_authority_revalidate_nowait_v1(&authority) + != CLUSTER_THREAD_AUTHORITY_OK) result = CLUSTER_THREADREC_BLOCKED; release_result = cluster_recovery_serial_release(&serial_guard); walr_release_result = cluster_wal_retention_pin_release(&retention_pin); - if (release_result != CLUSTER_RECOVERY_SERIAL_RELEASE_CONFIRMED || - walr_release_result != CLUSTER_WALR_RELEASE_CONFIRMED) + if (release_result != CLUSTER_RECOVERY_SERIAL_RELEASE_CONFIRMED + || walr_release_result != CLUSTER_WALR_RELEASE_CONFIRMED) return CLUSTER_THREADREC_BLOCKED; cluster_external_fence_admission_set_release(&admissions); cluster_external_fence_need_set_release(&needs); @@ -325,10 +303,9 @@ cluster_thread_recovery_worker_main(Datum main_arg) if (MyBgworkerEntry == NULL) return; memcpy(&eligibility, MyBgworkerEntry->bgw_extra, sizeof(eligibility)); - slot_read = cluster_thread_recovery_replay_read( - (uint16)dead_tid, &state, &launch_epoch); - if (!cluster_thread_recovery_worker_start_valid( - &eligibility, (uint16)dead_tid, slot_read, state, launch_epoch)) + slot_read = cluster_thread_recovery_replay_read((uint16)dead_tid, &state, &launch_epoch); + if (!cluster_thread_recovery_worker_start_valid(&eligibility, (uint16)dead_tid, slot_read, + state, launch_epoch)) return; /* Cleanup authority on every controlled exit; scheduler state is reaped only @@ -344,27 +321,27 @@ cluster_thread_recovery_worker_main(Datum main_arg) res = thread_recovery_worker_run(&eligibility); if (cluster_thread_recovery_worker_terminal_state(res, &terminal_state)) { match_result = cluster_thread_recovery_replay_transition_if_match( - (uint16)dead_tid, eligibility.attempt_stamp, - CLUSTER_THREADREC_REPLAY_REPLAYING, terminal_state); + (uint16)dead_tid, eligibility.attempt_stamp, CLUSTER_THREADREC_REPLAY_REPLAYING, + terminal_state); if (match_result != CLUSTER_THREADREC_MATCH_CHANGED) - ereport(PANIC, - (errmsg("online thread-recovery terminal slot transition failed"), - errdetail("thread=%u stamp=" UINT64_FORMAT - " result=%d match=%d", - (unsigned)dead_tid, eligibility.attempt_stamp, - (int)res, (int)match_result))); + ereport(PANIC, (errmsg("online thread-recovery terminal slot transition failed"), + errdetail("thread=%u stamp=" UINT64_FORMAT " result=%d match=%d", + (unsigned)dead_tid, eligibility.attempt_stamp, (int)res, + (int)match_result))); } - ereport(LOG, (errmsg("online thread recovery: dead thread %d -> %s", dead_tid, - res == CLUSTER_THREADREC_DONE - ? "done" - : (res == CLUSTER_THREADREC_BLOCKED ? "blocked (kept frozen)" - : (res == CLUSTER_THREADREC_DEFERRED ? "deferred" - : "not applicable"))), - res == CLUSTER_THREADREC_BLOCKED - ? errhint("The dead thread's resources stay frozen; check the shared WAL " - "storage and cluster.thread_recovery_on_unrecoverable.") - : 0)); + ereport( + LOG, + (errmsg("online thread recovery: dead thread %d -> %s", dead_tid, + res == CLUSTER_THREADREC_DONE + ? "done" + : (res == CLUSTER_THREADREC_BLOCKED + ? "blocked (kept frozen)" + : (res == CLUSTER_THREADREC_DEFERRED ? "deferred" : "not applicable"))), + res == CLUSTER_THREADREC_BLOCKED + ? errhint("The dead thread's resources stay frozen; check the shared WAL " + "storage and cluster.thread_recovery_on_unrecoverable.") + : 0)); } typedef struct ClusterThreadRecOwnedWorker { @@ -373,21 +350,18 @@ typedef struct ClusterThreadRecOwnedWorker { bool terminate_sent; } ClusterThreadRecOwnedWorker; -static ClusterThreadRecOwnedWorker - thread_recovery_owned[CLUSTER_WAL_THREAD_MAX + 1]; +static ClusterThreadRecOwnedWorker thread_recovery_owned[CLUSTER_WAL_THREAD_MAX + 1]; StaticAssertDecl(sizeof(ClusterThreadRecLaunchEligibility) <= BGW_EXTRALEN, "thread recovery eligibility must fit bgw_extra"); static bool -thread_recovery_eligibility_valid( - const ClusterThreadRecLaunchEligibility *eligibility) +thread_recovery_eligibility_valid(const ClusterThreadRecLaunchEligibility *eligibility) { return eligibility != NULL - && cluster_thread_recovery_worker_start_valid( - eligibility, eligibility->origin_thread, true, - CLUSTER_THREADREC_REPLAY_REPLAYING, - eligibility->attempt_stamp); + && cluster_thread_recovery_worker_start_valid(eligibility, eligibility->origin_thread, + true, CLUSTER_THREADREC_REPLAY_REPLAYING, + eligibility->attempt_stamp); } static bool @@ -440,44 +414,38 @@ thread_recovery_reap_one(uint16 dead_tid, bool *retained_out) return; status = GetBackgroundWorkerPid(owned->handle, &pid); if (status == BGWH_STOPPED) - slot_read = cluster_thread_recovery_replay_read(dead_tid, &state, - &slot_stamp); - decision = cluster_thread_recovery_reap_decide( - status, slot_read, owned->attempt_stamp, state, slot_stamp); + slot_read = cluster_thread_recovery_replay_read(dead_tid, &state, &slot_stamp); + decision = cluster_thread_recovery_reap_decide(status, slot_read, owned->attempt_stamp, state, + slot_stamp); if (decision == CLUSTER_THREADREC_REAP_RETAIN) { if (retained_out != NULL) *retained_out = true; return; } if (decision == CLUSTER_THREADREC_REAP_INVALID) - ereport(FATAL, - (errmsg("invalid online thread-recovery worker/slot relation"), - errdetail("thread=%u owned_stamp=" UINT64_FORMAT - " status=%d slot_read=%s slot_state=%d slot_stamp=" UINT64_FORMAT, - (unsigned)dead_tid, owned->attempt_stamp, (int)status, - slot_read ? "true" : "false", (int)state, - slot_stamp))); + ereport(FATAL, (errmsg("invalid online thread-recovery worker/slot relation"), + errdetail("thread=%u owned_stamp=" UINT64_FORMAT + " status=%d slot_read=%s slot_state=%d slot_stamp=" UINT64_FORMAT, + (unsigned)dead_tid, owned->attempt_stamp, (int)status, + slot_read ? "true" : "false", (int)state, slot_stamp))); if (decision == CLUSTER_THREADREC_REAP_RESET_IDLE) { ClusterThreadReplayMatchResult match_result - = cluster_thread_recovery_replay_transition_if_match( - dead_tid, owned->attempt_stamp, - CLUSTER_THREADREC_REPLAY_REPLAYING, - CLUSTER_THREADREC_REPLAY_IDLE); + = cluster_thread_recovery_replay_transition_if_match(dead_tid, owned->attempt_stamp, + CLUSTER_THREADREC_REPLAY_REPLAYING, + CLUSTER_THREADREC_REPLAY_IDLE); if (match_result != CLUSTER_THREADREC_MATCH_CHANGED) ereport(FATAL, (errmsg("online thread-recovery STOPPED reap could not reset slot"), - errdetail("thread=%u stamp=" UINT64_FORMAT " match=%d", - (unsigned)dead_tid, owned->attempt_stamp, - (int)match_result))); + errdetail("thread=%u stamp=" UINT64_FORMAT " match=%d", (unsigned)dead_tid, + owned->attempt_stamp, (int)match_result))); } pfree(owned->handle); memset(owned, 0, sizeof(*owned)); } static void -thread_recovery_launch_one( - const ClusterThreadRecLaunchEligibility *eligibility) +thread_recovery_launch_one(const ClusterThreadRecLaunchEligibility *eligibility) { ClusterThreadRecOwnedWorker *owned; ClusterThreadRecReplayState state; @@ -490,15 +458,12 @@ thread_recovery_launch_one( return; if (!cluster_thread_recovery_replay_read(dead_tid, &state, &slot_stamp) || state != CLUSTER_THREADREC_REPLAY_IDLE) - ereport(FATAL, - (errmsg("invalid online thread-recovery launch slot"), - errdetail("thread=%u state=%d stamp=" UINT64_FORMAT, - (unsigned)dead_tid, (int)state, slot_stamp))); - if (!cluster_thread_recovery_replay_mark_replaying( - dead_tid, eligibility->attempt_stamp)) - ereport(FATAL, - (errmsg("could not stamp online thread-recovery slot for dead thread %u", - (unsigned)dead_tid))); + ereport(FATAL, (errmsg("invalid online thread-recovery launch slot"), + errdetail("thread=%u state=%d stamp=" UINT64_FORMAT, (unsigned)dead_tid, + (int)state, slot_stamp))); + if (!cluster_thread_recovery_replay_mark_replaying(dead_tid, eligibility->attempt_stamp)) + ereport(FATAL, (errmsg("could not stamp online thread-recovery slot for dead thread %u", + (unsigned)dead_tid))); /* * RF-ROOT P7 (contract §B): pin the canonical-root projection BEFORE * the worker spawns — post-bit22 only (pre-bit22 replay_one derives @@ -512,8 +477,7 @@ thread_recovery_launch_one( * the worker fails closed (window derivation BLOCKED). */ if (cluster_r4_bit22_cutover_active()) { - (void) cluster_thread_recovery_pin_projection( - dead_tid, eligibility->attempt_stamp); + (void)cluster_thread_recovery_pin_projection(dead_tid, eligibility->attempt_stamp); } if (register_one_worker(eligibility, &owned->handle)) { owned->attempt_stamp = eligibility->attempt_stamp; @@ -522,20 +486,16 @@ thread_recovery_launch_one( } match_result = cluster_thread_recovery_replay_transition_if_match( - dead_tid, eligibility->attempt_stamp, - CLUSTER_THREADREC_REPLAY_REPLAYING, + dead_tid, eligibility->attempt_stamp, CLUSTER_THREADREC_REPLAY_REPLAYING, CLUSTER_THREADREC_REPLAY_IDLE); if (match_result != CLUSTER_THREADREC_MATCH_CHANGED) - ereport(FATAL, - (errmsg("could not reset failed online thread-recovery launch"), - errdetail("thread=%u stamp=" UINT64_FORMAT " match=%d", - (unsigned)dead_tid, eligibility->attempt_stamp, - (int)match_result))); - ereport(WARNING, - (errmsg("could not register online thread-recovery worker for dead thread %u", - (unsigned)dead_tid), - errhint("Background worker slots are exhausted (max_worker_processes); the " - "dead thread stays frozen until recovery can run."))); + ereport(FATAL, (errmsg("could not reset failed online thread-recovery launch"), + errdetail("thread=%u stamp=" UINT64_FORMAT " match=%d", (unsigned)dead_tid, + eligibility->attempt_stamp, (int)match_result))); + ereport(WARNING, (errmsg("could not register online thread-recovery worker for dead thread %u", + (unsigned)dead_tid), + errhint("Background worker slots are exhausted (max_worker_processes); the " + "dead thread stays frozen until recovery can run."))); } void @@ -546,40 +506,31 @@ cluster_thread_recovery_lmon_tick(void) int survivors; uint16 dead_tid; - for (dead_tid = XLP_THREAD_ID_FIRST_REAL; - dead_tid <= CLUSTER_WAL_THREAD_MAX; dead_tid++) + for (dead_tid = XLP_THREAD_ID_FIRST_REAL; dead_tid <= CLUSTER_WAL_THREAD_MAX; dead_tid++) thread_recovery_reap_one(dead_tid, NULL); - shared_fs = (cluster_shared_storage_backend - == CLUSTER_SHARED_FS_BACKEND_CLUSTER_FS); + shared_fs = (cluster_shared_storage_backend == CLUSTER_SHARED_FS_BACKEND_CLUSTER_FS); survivors = cluster_conf_node_count() - 1; - scope = cluster_thread_recovery_decide_scope( - cluster_online_thread_recovery, cluster_conf_has_peers(), shared_fs, - survivors); + scope = cluster_thread_recovery_decide_scope(cluster_online_thread_recovery, + cluster_conf_has_peers(), shared_fs, survivors); if (scope != CLUSTER_THREADREC_SCOPE_APPLICABLE) return; - for (dead_tid = XLP_THREAD_ID_FIRST_REAL; - dead_tid <= CLUSTER_WAL_THREAD_MAX; dead_tid++) { + for (dead_tid = XLP_THREAD_ID_FIRST_REAL; dead_tid <= CLUSTER_WAL_THREAD_MAX; dead_tid++) { ClusterThreadRecLaunchEligibility eligibility; - ClusterThreadRecOwnedWorker *owned - = &thread_recovery_owned[dead_tid]; + ClusterThreadRecOwnedWorker *owned = &thread_recovery_owned[dead_tid]; memset(&eligibility, 0, sizeof(eligibility)); - if (!cluster_reconfig_thread_recovery_eligibility_consume( - dead_tid, &eligibility)) + if (!cluster_reconfig_thread_recovery_eligibility_consume(dead_tid, &eligibility)) continue; if (!thread_recovery_eligibility_valid(&eligibility) || eligibility.origin_thread != dead_tid) - ereport(FATAL, - (errmsg("invalid online thread-recovery launch eligibility"), - errdetail("requested_thread=%u carrier_thread=%u stamp=" UINT64_FORMAT, - (unsigned)dead_tid, - (unsigned)eligibility.origin_thread, - eligibility.attempt_stamp))); + ereport(FATAL, (errmsg("invalid online thread-recovery launch eligibility"), + errdetail("requested_thread=%u carrier_thread=%u stamp=" UINT64_FORMAT, + (unsigned)dead_tid, (unsigned)eligibility.origin_thread, + eligibility.attempt_stamp))); if (owned->handle != NULL) { - if (owned->attempt_stamp != eligibility.attempt_stamp - && !owned->terminate_sent) { + if (owned->attempt_stamp != eligibility.attempt_stamp && !owned->terminate_sent) { TerminateBackgroundWorker(owned->handle); owned->terminate_sent = true; } @@ -592,14 +543,11 @@ cluster_thread_recovery_lmon_tick(void) void cluster_thread_recovery_lmon_shutdown(void) { - TimestampTz deadline - = TimestampTzPlusMilliseconds(GetCurrentTimestamp(), 5000); + TimestampTz deadline = TimestampTzPlusMilliseconds(GetCurrentTimestamp(), 5000); uint16 dead_tid; - for (dead_tid = XLP_THREAD_ID_FIRST_REAL; - dead_tid <= CLUSTER_WAL_THREAD_MAX; dead_tid++) { - ClusterThreadRecOwnedWorker *owned - = &thread_recovery_owned[dead_tid]; + for (dead_tid = XLP_THREAD_ID_FIRST_REAL; dead_tid <= CLUSTER_WAL_THREAD_MAX; dead_tid++) { + ClusterThreadRecOwnedWorker *owned = &thread_recovery_owned[dead_tid]; if (owned->handle != NULL && !owned->terminate_sent) { TerminateBackgroundWorker(owned->handle); @@ -612,23 +560,22 @@ cluster_thread_recovery_lmon_shutdown(void) long wait_ms; int rc; - for (dead_tid = XLP_THREAD_ID_FIRST_REAL; - dead_tid <= CLUSTER_WAL_THREAD_MAX; dead_tid++) + for (dead_tid = XLP_THREAD_ID_FIRST_REAL; dead_tid <= CLUSTER_WAL_THREAD_MAX; dead_tid++) thread_recovery_reap_one(dead_tid, &retained); if (!retained) return; now = GetCurrentTimestamp(); if (now >= deadline) - ereport(FATAL, - (errmsg("timed out reaping online thread-recovery workers during LMON shutdown"))); + ereport( + FATAL, + (errmsg("timed out reaping online thread-recovery workers during LMON shutdown"))); wait_ms = (long)((deadline - now + INT64CONST(999)) / INT64CONST(1000)); if (wait_ms > 50) wait_ms = 50; if (wait_ms < 1) wait_ms = 1; - rc = WaitLatch(MyLatch, - WL_LATCH_SET | WL_TIMEOUT | WL_EXIT_ON_PM_DEATH, - wait_ms, WAIT_EVENT_CLUSTER_BGPROC_LMON_MAIN_LOOP); + rc = WaitLatch(MyLatch, WL_LATCH_SET | WL_TIMEOUT | WL_EXIT_ON_PM_DEATH, wait_ms, + WAIT_EVENT_CLUSTER_BGPROC_LMON_MAIN_LOOP); if (rc & WL_LATCH_SET) ResetLatch(MyLatch); } diff --git a/src/backend/cluster/cluster_tt_2pc.c b/src/backend/cluster/cluster_tt_2pc.c index 05d000376ab..d8c1d74667e 100644 --- a/src/backend/cluster/cluster_tt_2pc.c +++ b/src/backend/cluster/cluster_tt_2pc.c @@ -41,7 +41,7 @@ #include "cluster/cluster_itl_touch.h" /* PostPrepare touch-list drop (V-2) */ #include "cluster/cluster_reconfig.h" #include "cluster/cluster_semantic_activation.h" -#include "cluster/cluster_subtrans.h" /* sub-link export/reset (D7) */ +#include "cluster/cluster_subtrans.h" /* sub-link export/reset (D7) */ #include "cluster/cluster_tt_2pc.h" #include "cluster/cluster_tt_local.h" /* binding export/reset */ #include "cluster/cluster_tt_slot.h" /* protected-slot map (D6/V-4) */ @@ -225,7 +225,7 @@ cluster_tt_twophase_recover(TransactionId xid, uint16 info, void *recdata, uint3 source_request.key = &l->child_key; source_request.parent_key = &l->parent_key; if (cluster_tt_status_source_dispatch(CLUSTER_TT_SOURCE_INSTALL_SUBCOMMITTED, - &source_request, &source_result) + &source_request, &source_result) != CLUSTER_SEMANTIC_ADMISSION_OK || !source_result.bool_value) ereport(ERROR, (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), @@ -326,7 +326,7 @@ cluster_tt_twophase_standby_recover(TransactionId xid, uint16 info, void *recdat source_request.status = CLUSTER_TT_STATUS_IN_PROGRESS; source_request.commit_scn = InvalidScn; if (cluster_tt_status_source_dispatch(CLUSTER_TT_SOURCE_INSTALL_LOCAL, &source_request, - &source_result) + &source_result) != CLUSTER_SEMANTIC_ADMISSION_OK || !source_result.bool_value) { /* capacity / shmem unavailable: degrade, do NOT PANIC the @@ -349,7 +349,7 @@ cluster_tt_twophase_standby_recover(TransactionId xid, uint16 info, void *recdat source_request.key = &l->child_key; source_request.parent_key = &l->parent_key; if (cluster_tt_status_source_dispatch(CLUSTER_TT_SOURCE_INSTALL_SUBCOMMITTED, - &source_request, &source_result) + &source_request, &source_result) != CLUSTER_SEMANTIC_ADMISSION_OK || !source_result.bool_value) { /* capacity / shmem unavailable: degrade, do NOT PANIC the @@ -379,7 +379,7 @@ cluster_tt_twophase_standby_commit_prepared(TransactionId xid, SCN commit_scn) source_request.xid = xid; source_request.commit_scn = commit_scn; if (cluster_tt_status_source_dispatch(CLUSTER_TT_SOURCE_RESOLVE_PREPARED_COMMIT, - &source_request, &source_result) + &source_request, &source_result) != CLUSTER_SEMANTIC_ADMISSION_OK) return 0; return source_result.int_value; @@ -392,10 +392,11 @@ cluster_tt_twophase_writable_admission(void) ClusterJoinGateVerdict verdict = cluster_reconfig_self_join_gate_verdict(); if (verdict == CLUSTER_JOIN_GATE_BLOCK_53R61) - ereport(FATAL, - (errcode(ERRCODE_CLUSTER_JOIN_REJECTED_STALE), - errmsg("cannot finish a prepared transaction: this node's cluster join was rejected"), - errhint("Restart this node so it presents a fresh cluster incarnation."))); + ereport( + FATAL, + (errcode(ERRCODE_CLUSTER_JOIN_REJECTED_STALE), + errmsg("cannot finish a prepared transaction: this node's cluster join was rejected"), + errhint("Restart this node so it presents a fresh cluster incarnation."))); return verdict == CLUSTER_JOIN_GATE_ALLOW; } @@ -403,13 +404,14 @@ cluster_tt_twophase_writable_admission(void) static void cluster_tt_twophase_modifier_recheck_or_error(const ClusterSemanticAdmissionToken *token) { - if (!cluster_semantic_activation_modifier_recheck( - token, cluster_tt_twophase_writable_admission())) - ereport(ERROR, - (errcode(ERRCODE_CLUSTER_RECONFIG_IN_PROGRESS), - errmsg("cannot finish a prepared transaction: cluster reconfiguration in progress"), - errhint("The prepared transaction remains retryable; retry after cluster admission " - "converges."))); + if (!cluster_semantic_activation_modifier_recheck(token, + cluster_tt_twophase_writable_admission())) + ereport( + ERROR, + (errcode(ERRCODE_CLUSTER_RECONFIG_IN_PROGRESS), + errmsg("cannot finish a prepared transaction: cluster reconfiguration in progress"), + errhint("The prepared transaction remains retryable; retry after cluster admission " + "converges."))); } @@ -446,14 +448,15 @@ cluster_tt_twophase_prefinish(TransactionId xid, SCN final_scn, bool is_commit, Assert(cluster_node_id >= 0); - admission = cluster_semantic_activation_modifier_enter( - cluster_tt_twophase_writable_admission(), &modifier_token); + admission = cluster_semantic_activation_modifier_enter(cluster_tt_twophase_writable_admission(), + &modifier_token); if (admission != CLUSTER_SEMANTIC_ADMISSION_OK) - ereport(ERROR, - (errcode(ERRCODE_CLUSTER_RECONFIG_IN_PROGRESS), - errmsg("cannot finish a prepared transaction: cluster reconfiguration in progress"), - errhint("The prepared transaction remains retryable; retry after cluster admission " - "converges."))); + ereport( + ERROR, + (errcode(ERRCODE_CLUSTER_RECONFIG_IN_PROGRESS), + errmsg("cannot finish a prepared transaction: cluster reconfiguration in progress"), + errhint("The prepared transaction remains retryable; retry after cluster admission " + "converges."))); PG_TRY(); { @@ -473,10 +476,9 @@ cluster_tt_twophase_prefinish(TransactionId xid, SCN final_scn, bool is_commit, uint16 origin_node_id; if (!cluster_tt_2pc_binding_origin_node(b, &origin_node_id)) - ereport(ERROR, - (errcode(ERRCODE_DATA_CORRUPTED), - errmsg("invalid TT binding segment %u for prepared transaction %u", - b->undo_segment_id, xid))); + ereport(ERROR, (errcode(ERRCODE_DATA_CORRUPTED), + errmsg("invalid TT binding segment %u for prepared transaction %u", + b->undo_segment_id, xid))); memset(&key, 0, sizeof(key)); key.origin_node_id = origin_node_id; key.undo_segment_id = (uint16)b->undo_segment_id; @@ -489,19 +491,19 @@ cluster_tt_twophase_prefinish(TransactionId xid, SCN final_scn, bool is_commit, cluster_tt_slot_durable_commit(b->undo_segment_id, b->slot_offset, b->xid, b->wrap, final_scn); cluster_tt_slot_mark_committed(b->undo_segment_id, b->slot_offset, b->xid, - final_scn); + final_scn); memset(&source_request, 0, sizeof(source_request)); source_request.key = &key; source_request.status = CLUSTER_TT_STATUS_COMMITTED; source_request.commit_scn = final_scn; (void)cluster_tt_status_source_dispatch(CLUSTER_TT_SOURCE_INSTALL_LOCAL, - &source_request, &source_result); + &source_request, &source_result); memset(&hint_request, 0, sizeof(hint_request)); hint_request.key = &key; hint_request.status = CLUSTER_TT_STATUS_COMMITTED; hint_request.commit_scn = final_scn; (void)cluster_tt_status_hint_source_dispatch(CLUSTER_TT_HINT_SOURCE_EMIT, - &hint_request); + &hint_request); } else { cluster_tt_twophase_modifier_recheck_or_error(&modifier_token); cluster_tt_slot_durable_abort(b->undo_segment_id, b->slot_offset, b->xid, b->wrap); @@ -517,7 +519,7 @@ cluster_tt_twophase_prefinish(TransactionId xid, SCN final_scn, bool is_commit, if (p.heads != NULL && !UBA_is_invalid(p.heads[i])) { cluster_tt_twophase_modifier_recheck_or_error(&modifier_token); cluster_tt_slot_durable_set_head(b->undo_segment_id, b->slot_offset, b->xid, - b->wrap, p.heads[i]); + b->wrap, p.heads[i]); } cluster_tt_slot_mark_aborted(b->undo_segment_id, b->slot_offset, b->xid); memset(&source_request, 0, sizeof(source_request)); @@ -525,13 +527,13 @@ cluster_tt_twophase_prefinish(TransactionId xid, SCN final_scn, bool is_commit, source_request.status = CLUSTER_TT_STATUS_ABORTED; source_request.commit_scn = InvalidScn; (void)cluster_tt_status_source_dispatch(CLUSTER_TT_SOURCE_INSTALL_LOCAL, - &source_request, &source_result); + &source_request, &source_result); memset(&hint_request, 0, sizeof(hint_request)); hint_request.key = &key; hint_request.status = CLUSTER_TT_STATUS_ABORTED; hint_request.commit_scn = InvalidScn; (void)cluster_tt_status_hint_source_dispatch(CLUSTER_TT_HINT_SOURCE_EMIT, - &hint_request); + &hint_request); } } } diff --git a/src/backend/cluster/cluster_tt_durable.c b/src/backend/cluster/cluster_tt_durable.c index ee3890d2028..8b1292a2e7a 100644 --- a/src/backend/cluster/cluster_tt_durable.c +++ b/src/backend/cluster/cluster_tt_durable.c @@ -39,22 +39,22 @@ #include "utils/elog.h" #include "utils/timestamp.h" -#include "cluster/cluster_guc.h" /* cluster_node_id */ +#include "cluster/cluster_guc.h" /* cluster_node_id */ #include "cluster/cluster_epoch.h" #include "cluster/cluster_ges.h" #include "cluster/cluster_qvotec.h" -#include "cluster/cluster_scn.h" /* SCN, SCN_VALID, InvalidScn */ +#include "cluster/cluster_scn.h" /* SCN, SCN_VALID, InvalidScn */ #include "cluster/cluster_semantic_activation.h" #include "cluster/cluster_terminal_ref_census.h" #include "cluster/cluster_undo_cleaner.h" /* spec-3.13 D2-B scan-only pass */ #include "cluster/cluster_tt_durable.h" -#include "cluster/cluster_tt_slot.h" /* TTSlot, TT_SLOT_COMMITTED, TT_SLOTS_PER_SEGMENT */ +#include "cluster/cluster_tt_slot.h" /* TTSlot, TT_SLOT_COMMITTED, TT_SLOTS_PER_SEGMENT */ #include "cluster/cluster_tt_status.h" -#include "cluster/cluster_undo_segment.h" /* UndoSegmentHeaderData */ -#include "cluster/cluster_undo_smgr.h" /* header-bytes + block I/O */ +#include "cluster/cluster_undo_segment.h" /* UndoSegmentHeaderData */ +#include "cluster/cluster_undo_smgr.h" /* header-bytes + block I/O */ #include "cluster/storage/cluster_undo_alloc.h" /* CLUSTER_UNDO_SEGS_PER_INSTANCE */ #include "cluster/storage/cluster_undo_block0_current.h" -#include "cluster/storage/cluster_undo_xlog.h" /* cluster_undo_emit_tt_slot_commit */ +#include "cluster/storage/cluster_undo_xlog.h" /* cluster_undo_emit_tt_slot_commit */ /* Absolute byte offset of TTSlot[slot_offset] within segment header block 0. */ @@ -110,17 +110,14 @@ cluster_tt_durable_redo_decide(uint8 slot_status, TransactionId slot_xid, uint16 } ClusterTTActiveTransitionDecision -cluster_tt_active_transition_decide(const TTSlot *predecessor, - uint32 disk_generation, - uint32 expected_generation, - TransactionId xid, uint16 wrap, +cluster_tt_active_transition_decide(const TTSlot *predecessor, uint32 disk_generation, + uint32 expected_generation, TransactionId xid, uint16 wrap, bool identity_authorized) { TTSlot zero_slot; bool terminal_shape; - if (predecessor == NULL || !TransactionIdIsNormal(xid) - || wrap == TT_WRAP_INVALID) + if (predecessor == NULL || !TransactionIdIsNormal(xid) || wrap == TT_WRAP_INVALID) return CLUSTER_TT_ACTIVE_CORRUPT; if (disk_generation > expected_generation) return CLUSTER_TT_ACTIVE_STALE; @@ -131,12 +128,11 @@ cluster_tt_active_transition_decide(const TTSlot *predecessor, memset(&zero_slot, 0, sizeof(zero_slot)); if (predecessor->status == TT_SLOT_UNUSED) - return memcmp(predecessor, &zero_slot, sizeof(zero_slot)) == 0 - ? CLUSTER_TT_ACTIVE_APPLY : CLUSTER_TT_ACTIVE_CORRUPT; + return memcmp(predecessor, &zero_slot, sizeof(zero_slot)) == 0 ? CLUSTER_TT_ACTIVE_APPLY + : CLUSTER_TT_ACTIVE_CORRUPT; if (predecessor->status == TT_SLOT_ACTIVE) { - if (predecessor->flags != TT_FLAGS_RESERVED - || SCN_VALID(predecessor->commit_scn) + if (predecessor->flags != TT_FLAGS_RESERVED || SCN_VALID(predecessor->commit_scn) || !UBA_is_invalid(predecessor->first_undo_block)) return CLUSTER_TT_ACTIVE_CORRUPT; if (predecessor->wrap > wrap) @@ -148,36 +144,31 @@ cluster_tt_active_transition_decide(const TTSlot *predecessor, terminal_shape = (predecessor->flags & ~TT_SLOT_FLAGS_KNOWN) == 0 - && UBA_is_invalid(predecessor->first_undo_block) - && ((predecessor->status == TT_SLOT_COMMITTED - && SCN_VALID(predecessor->commit_scn)) - || ((predecessor->status == TT_SLOT_ABORTED - || predecessor->status == TT_SLOT_RECYCLABLE) - && !SCN_VALID(predecessor->commit_scn))); + && UBA_is_invalid(predecessor->first_undo_block) + && ((predecessor->status == TT_SLOT_COMMITTED && SCN_VALID(predecessor->commit_scn)) + || ((predecessor->status == TT_SLOT_ABORTED + || predecessor->status == TT_SLOT_RECYCLABLE) + && !SCN_VALID(predecessor->commit_scn))); if (!terminal_shape) return CLUSTER_TT_ACTIVE_CORRUPT; if (predecessor->wrap > wrap) return CLUSTER_TT_ACTIVE_STALE; - if (predecessor->wrap >= TT_WRAP_MAX - || wrap != (uint16)(predecessor->wrap + 1)) + if (predecessor->wrap >= TT_WRAP_MAX || wrap != (uint16)(predecessor->wrap + 1)) return CLUSTER_TT_ACTIVE_CONFLICT; return CLUSTER_TT_ACTIVE_APPLY; } ClusterTTTerminalTransitionDecision -cluster_tt_terminal_transition_decide(const TTSlot *predecessor, - uint32 disk_generation, - uint32 expected_generation, - TransactionId xid, uint16 wrap, - uint8 terminal_status, SCN commit_scn) +cluster_tt_terminal_transition_decide(const TTSlot *predecessor, uint32 disk_generation, + uint32 expected_generation, TransactionId xid, uint16 wrap, + uint8 terminal_status, SCN commit_scn) { bool terminal_shape; if (predecessor == NULL || expected_generation == UINT32_MAX - || disk_generation < expected_generation - || !TransactionIdIsNormal(xid) || wrap == TT_WRAP_INVALID - || (terminal_status != TT_SLOT_COMMITTED - && terminal_status != TT_SLOT_ABORTED) + || disk_generation < expected_generation || !TransactionIdIsNormal(xid) + || wrap == TT_WRAP_INVALID + || (terminal_status != TT_SLOT_COMMITTED && terminal_status != TT_SLOT_ABORTED) || (terminal_status == TT_SLOT_COMMITTED) != SCN_VALID(commit_scn)) return CLUSTER_TT_TERMINAL_CORRUPT; if (disk_generation > expected_generation) @@ -189,46 +180,38 @@ cluster_tt_terminal_transition_decide(const TTSlot *predecessor, return CLUSTER_TT_TERMINAL_CONFLICT; if (predecessor->status == TT_SLOT_ACTIVE) { - if (predecessor->flags != TT_FLAGS_RESERVED - || SCN_VALID(predecessor->commit_scn) + if (predecessor->flags != TT_FLAGS_RESERVED || SCN_VALID(predecessor->commit_scn) || !UBA_is_invalid(predecessor->first_undo_block)) return CLUSTER_TT_TERMINAL_CORRUPT; return CLUSTER_TT_TERMINAL_APPLY; } - terminal_shape = (predecessor->flags & ~TT_SLOT_FLAGS_KNOWN) == 0 - && UBA_is_invalid(predecessor->first_undo_block) - && ((predecessor->status == TT_SLOT_COMMITTED - && SCN_VALID(predecessor->commit_scn)) - || (predecessor->status == TT_SLOT_ABORTED - && !SCN_VALID(predecessor->commit_scn))); + terminal_shape + = (predecessor->flags & ~TT_SLOT_FLAGS_KNOWN) == 0 + && UBA_is_invalid(predecessor->first_undo_block) + && ((predecessor->status == TT_SLOT_COMMITTED && SCN_VALID(predecessor->commit_scn)) + || (predecessor->status == TT_SLOT_ABORTED && !SCN_VALID(predecessor->commit_scn))); if (!terminal_shape) - return predecessor->status == TT_SLOT_UNUSED - ? CLUSTER_TT_TERMINAL_CONFLICT - : CLUSTER_TT_TERMINAL_CORRUPT; + return predecessor->status == TT_SLOT_UNUSED ? CLUSTER_TT_TERMINAL_CONFLICT + : CLUSTER_TT_TERMINAL_CORRUPT; if (predecessor->status != terminal_status) return CLUSTER_TT_TERMINAL_CONFLICT; - if (terminal_status == TT_SLOT_COMMITTED - && predecessor->commit_scn != commit_scn) + if (terminal_status == TT_SLOT_COMMITTED && predecessor->commit_scn != commit_scn) return CLUSTER_TT_TERMINAL_CONFLICT; return (predecessor->flags & TT_SLOT_FLAG_CTRC_RELEASE_PROVEN) != 0 - ? CLUSTER_TT_TERMINAL_APPLY - : CLUSTER_TT_TERMINAL_IDEMPOTENT; + ? CLUSTER_TT_TERMINAL_APPLY + : CLUSTER_TT_TERMINAL_IDEMPOTENT; } static bool tt_active_owner_matches(const ClusterTTSlotCurrentOwner *expected, const ClusterTTSlotCurrentOwner *observed) { - return expected != NULL && observed != NULL - && expected->segment_id == observed->segment_id - && expected->xid == observed->xid - && expected->commit_scn == observed->commit_scn - && expected->slot_offset == observed->slot_offset - && expected->wrap == observed->wrap - && expected->status == observed->status - && memcmp(expected->reserved8, observed->reserved8, - sizeof(expected->reserved8)) == 0; + return expected != NULL && observed != NULL && expected->segment_id == observed->segment_id + && expected->xid == observed->xid && expected->commit_scn == observed->commit_scn + && expected->slot_offset == observed->slot_offset && expected->wrap == observed->wrap + && expected->status == observed->status + && memcmp(expected->reserved8, observed->reserved8, sizeof(expected->reserved8)) == 0; } /* @@ -265,8 +248,7 @@ tt_allocator_classify_owner(const ClusterTTSlotCurrentOwner *expected) return TT_ALLOCATOR_OWNER_ROLLED_AWAY; memset(&observed, 0, sizeof(observed)); - if (cluster_tt_slot_current_owner_by_xid( - cluster_node_id, expected->xid, &observed) + if (cluster_tt_slot_current_owner_by_xid(cluster_node_id, expected->xid, &observed) && tt_active_owner_matches(expected, &observed)) return TT_ALLOCATOR_OWNER_MATCH; @@ -283,17 +265,16 @@ tt_allocator_corroborates_or_rolled_away(const ClusterTTSlotCurrentOwner *expect } XLogRecPtr -cluster_tt_slot_durable_publish_active( - const ClusterTTSlotCurrentOwner *expected_owner, - const ClusterSemanticAdmissionToken *admission, - uint32 *segment_generation_out, TTSlot *successor_out) +cluster_tt_slot_durable_publish_active(const ClusterTTSlotCurrentOwner *expected_owner, + const ClusterSemanticAdmissionToken *admission, + uint32 *segment_generation_out, TTSlot *successor_out) { TTAllocatorOwnerObservation allocator_observation; ClusterUndoBlock0LogicalKey key; ClusterUndoBlock0ResolvedRoot root; ClusterUndoBlock0ResolvedRoot final_root; - ClusterUndoBlock0Generation generation = {false, 0}; - ClusterUndoBlock0CurrentGuard guard = {0}; + ClusterUndoBlock0Generation generation = { false, 0 }; + ClusterUndoBlock0CurrentGuard guard = { 0 }; ClusterUndoBlock0Pin pin; ClusterCtrcTxnKeyV1 ctrc_key; ClusterCtrcOriginReservation ctrc_reservation; @@ -339,9 +320,8 @@ cluster_tt_slot_durable_publish_active( || expected_owner->status != CTS_ACTIVE || expected_owner->commit_scn != InvalidScn || expected_owner->reserved8[0] != 0 || expected_owner->reserved8[1] != 0 || expected_owner->reserved8[2] != 0) - ereport(ERROR, - (errcode(ERRCODE_CLUSTER_RECONFIG_IN_PROGRESS), - errmsg("cannot publish canonical ACTIVE without an exact local TT owner"))); + ereport(ERROR, (errcode(ERRCODE_CLUSTER_RECONFIG_IN_PROGRESS), + errmsg("cannot publish canonical ACTIVE without an exact local TT owner"))); *segment_generation_out = UINT32_MAX; memset(successor_out, 0, sizeof(*successor_out)); @@ -370,31 +350,28 @@ cluster_tt_slot_durable_publish_active( target_side = admission->side == CLUSTER_SEMANTIC_TARGET_SIDE; ctrc_reserve_perpetual = cluster_ges_request_timeout_ms == -1; if (!ctrc_reserve_perpetual) - ctrc_reserve_deadline = TimestampTzPlusMilliseconds( - GetCurrentTimestamp(), cluster_ges_request_timeout_ms); + ctrc_reserve_deadline + = TimestampTzPlusMilliseconds(GetCurrentTimestamp(), cluster_ges_request_timeout_ms); PG_TRY(); { retry_active_snapshot: MemSet(&root, 0, sizeof(root)); MemSet(&generation, 0, sizeof(generation)); - root_available = target_side - ? cluster_semantic_activation_resolve_shared_undo_root( - admission, CLUSTER_UNDO_PATH_RUNTIME_SHARED, owner, - expected_owner->segment_id, &root) - : cluster_semantic_activation_resolve_shared_undo_root_live_owner_source( - admission, CLUSTER_UNDO_PATH_RUNTIME_SHARED, owner, - expected_owner->segment_id, &root); + root_available + = target_side ? cluster_semantic_activation_resolve_shared_undo_root( + admission, CLUSTER_UNDO_PATH_RUNTIME_SHARED, owner, + expected_owner->segment_id, &root) + : cluster_semantic_activation_resolve_shared_undo_root_live_owner_source( + admission, CLUSTER_UNDO_PATH_RUNTIME_SHARED, owner, + expected_owner->segment_id, &root); step = target_side - ? cluster_undo_block0_current_acquire_begin_live_owner_target( - &key, cluster_ges_request_timeout_ms, admission, &guard, - ¤t_failure) - : cluster_undo_block0_current_acquire_begin_live_owner_source( - &key, cluster_ges_request_timeout_ms, admission, &guard, - ¤t_failure); - if (step == CLUSTER_UNDO_BLOCK0_CURRENT_FAILED) - { + ? cluster_undo_block0_current_acquire_begin_live_owner_target( + &key, cluster_ges_request_timeout_ms, admission, &guard, ¤t_failure) + : cluster_undo_block0_current_acquire_begin_live_owner_source( + &key, cluster_ges_request_timeout_ms, admission, &guard, ¤t_failure); + if (step == CLUSTER_UNDO_BLOCK0_CURRENT_FAILED) { /* A failed begin retains no guard under the current API. A known * obsolete local candidate need not restore its old readiness before * returning the still-unpublished reservation to its caller. */ @@ -415,8 +392,7 @@ cluster_tt_slot_durable_publish_active( while (step == CLUSTER_UNDO_BLOCK0_CURRENT_PENDING) { CHECK_FOR_INTERRUPTS(); - step = cluster_undo_block0_current_acquire_poll(&guard, - ¤t_failure); + step = cluster_undo_block0_current_acquire_poll(&guard, ¤t_failure); if (step == CLUSTER_UNDO_BLOCK0_CURRENT_PENDING && !cluster_undo_block0_current_wait_reply( &guard, CLUSTER_UNDO_BLOCK0_WAIT_TT_ACTIVE_ACQUIRE)) @@ -427,8 +403,7 @@ cluster_tt_slot_durable_publish_active( allocator_observation = tt_allocator_classify_owner(expected_owner); if (allocator_observation == TT_ALLOCATOR_OWNER_ROLLED_AWAY) goto active_publication_done; - if (step != CLUSTER_UNDO_BLOCK0_CURRENT_HELD || !root_available) - { + if (step != CLUSTER_UNDO_BLOCK0_CURRENT_HELD || !root_available) { ges_failure = cluster_ges_timeout_detail_get(); ereport(ERROR, (errcode(ERRCODE_CLUSTER_RECONFIG_IN_PROGRESS), @@ -458,10 +433,9 @@ cluster_tt_slot_durable_publish_active( expected_owner->slot_offset, expected_owner->wrap, cluster_tt_slot_current_segment(cluster_node_id)))); - result = cluster_undo_block0_current_sample_generation_exclusive( - &guard, &root, &generation); - if (result != CLUSTER_UNDO_BLOCK0_OK || !generation.known - || generation.value == UINT32_MAX) + result + = cluster_undo_block0_current_sample_generation_exclusive(&guard, &root, &generation); + if (result != CLUSTER_UNDO_BLOCK0_OK || !generation.known || generation.value == UINT32_MAX) ereport(ERROR, (errcode(ERRCODE_CLUSTER_RECONFIG_IN_PROGRESS), errmsg("canonical ACTIVE block-zero generation is unavailable"), @@ -469,8 +443,8 @@ cluster_tt_slot_durable_publish_active( "PGRAC_NODE=%d PGRAC_ATTEMPT=0 ", cluster_node_id))); - result = cluster_undo_block0_current_pin_exclusive( - &guard, &root, &generation, &pin, (char **)&resident_header); + result = cluster_undo_block0_current_pin_exclusive(&guard, &root, &generation, &pin, + (char **)&resident_header); if (result != CLUSTER_UNDO_BLOCK0_OK || resident_header == NULL) ereport(ERROR, (errcode(ERRCODE_CLUSTER_RECONFIG_IN_PROGRESS), @@ -481,12 +455,11 @@ cluster_tt_slot_durable_publish_active( pin_held = true; cluster_tt_durable_io_wait_start(); - if (!cluster_undo_smgr_read_block(root.intent, - expected_owner->segment_id, owner, 0, disk_block.data)) { + if (!cluster_undo_smgr_read_block(root.intent, expected_owner->segment_id, owner, 0, + disk_block.data)) { cluster_tt_durable_io_wait_end(); - ereport(ERROR, - (errcode(ERRCODE_DATA_CORRUPTED), - errmsg("cannot read canonical TT block zero for ACTIVE publication"))); + ereport(ERROR, (errcode(ERRCODE_DATA_CORRUPTED), + errmsg("cannot read canonical TT block zero for ACTIVE publication"))); } cluster_tt_durable_io_wait_end(); @@ -499,8 +472,8 @@ cluster_tt_slot_durable_publish_active( || resident_header->tt_slots_count != disk_header->tt_slots_count || resident_header->wrap_count != disk_header->wrap_count || memcmp(&resident_header->tt_slots[expected_owner->slot_offset], - &disk_header->tt_slots[expected_owner->slot_offset], - sizeof(TTSlot)) != 0) + &disk_header->tt_slots[expected_owner->slot_offset], sizeof(TTSlot)) + != 0) ereport( ERROR, (errcode(ERRCODE_DATA_CORRUPTED), @@ -525,27 +498,23 @@ cluster_tt_slot_durable_publish_active( resident_header->tt_slots[expected_owner->slot_offset].status))); publication_epoch = cluster_epoch_get_current(); - publication_boot_incarnation - = cluster_qvotec_get_self_incarnation(); - if (publication_epoch > UINT32_MAX - || publication_boot_incarnation == 0 - || admission->record_generation == 0 - || root.root_id == 0 || root.root_generation == 0 + publication_boot_incarnation = cluster_qvotec_get_self_incarnation(); + if (publication_epoch > UINT32_MAX || publication_boot_incarnation == 0 + || admission->record_generation == 0 || root.root_id == 0 || root.root_generation == 0 || GetSystemIdentifier() == 0) - ereport(ERROR, - (errcode(ERRCODE_CLUSTER_RECONFIG_IN_PROGRESS), - errmsg("canonical ACTIVE CTRC identity is unavailable"), - errdetail("epoch=%llu boot_incarnation=%llu " - "record_generation=%llu formation_epoch=%llu " - "root_id=%llu root_generation=%llu " - "system_identifier=%llu", - (unsigned long long)publication_epoch, - (unsigned long long)publication_boot_incarnation, - (unsigned long long)admission->record_generation, - (unsigned long long)admission->formation_epoch, - (unsigned long long)root.root_id, - (unsigned long long)root.root_generation, - (unsigned long long)GetSystemIdentifier()))); + ereport(ERROR, (errcode(ERRCODE_CLUSTER_RECONFIG_IN_PROGRESS), + errmsg("canonical ACTIVE CTRC identity is unavailable"), + errdetail("epoch=%llu boot_incarnation=%llu " + "record_generation=%llu formation_epoch=%llu " + "root_id=%llu root_generation=%llu " + "system_identifier=%llu", + (unsigned long long)publication_epoch, + (unsigned long long)publication_boot_incarnation, + (unsigned long long)admission->record_generation, + (unsigned long long)admission->formation_epoch, + (unsigned long long)root.root_id, + (unsigned long long)root.root_generation, + (unsigned long long)GetSystemIdentifier()))); MemSet(&ctrc_key, 0, sizeof(ctrc_key)); ctrc_key.format_version = CLUSTER_CTRC_FORMAT_VERSION; ctrc_key.owner_instance = owner; @@ -563,84 +532,62 @@ cluster_tt_slot_durable_publish_active( ctrc_key.root_descriptor_incarnation = root.root_generation; ctrc_key.root_id = root.root_id; ctrc_key.root_generation = root.root_generation; - ctrc_reserve_result = cluster_ctrc_origin_reserve_active( - &ctrc_key, &ctrc_reservation); - if (ctrc_reserve_result - == CLUSTER_CTRC_ORIGIN_RESERVE_RETRY_RELEASED) - { + ctrc_reserve_result = cluster_ctrc_origin_reserve_active(&ctrc_key, &ctrc_reservation); + if (ctrc_reserve_result == CLUSTER_CTRC_ORIGIN_RESERVE_RETRY_RELEASED) { /* The old row needs cleaner progress before it can be reclaimed. * Never retain block-0 current or its content pin across that * asynchronous wait: the cleaner can require the same authority * before it reaches certificate notification. The next attempt * reacquires and rebuilds the complete canonical snapshot. */ - if (pin_held) - { + if (pin_held) { cluster_undo_block0_unpin(&pin); pin_held = false; } - if (current_active) - { + if (current_active) { cluster_undo_block0_current_cancel(&guard); - current_active = false; - MemSet(&guard, 0, sizeof(guard)); - } + current_active = false; + MemSet(&guard, 0, sizeof(guard)); + } /* Terminal publication already woke the first cleaner pass. Re-arm * explicitly for an overlap observed between passes, then poll only * the CTRC row. Reacquiring block-0 XCUR while the released row is * unchanged creates no new evidence and can starve the cleaner/GES * path that must deliver the notification. */ cluster_undo_cleaner_wakeup(); - while (cluster_ctrc_origin_release_overlap_pending(&ctrc_key)) - { - if (!ctrc_reserve_perpetual - && GetCurrentTimestamp() >= ctrc_reserve_deadline) + while (cluster_ctrc_origin_release_overlap_pending(&ctrc_key)) { + if (!ctrc_reserve_perpetual && GetCurrentTimestamp() >= ctrc_reserve_deadline) break; CHECK_FOR_INTERRUPTS(); pg_usleep(1000L); } - if (ctrc_reserve_perpetual - || GetCurrentTimestamp() < ctrc_reserve_deadline) - { + if (ctrc_reserve_perpetual || GetCurrentTimestamp() < ctrc_reserve_deadline) { CHECK_FOR_INTERRUPTS(); goto retry_active_snapshot; } } if (ctrc_reserve_result == CLUSTER_CTRC_ORIGIN_RESERVE_REFUSED) - ereport(ERROR, - (errcode(ERRCODE_CLUSTER_RECONFIG_IN_PROGRESS), - errmsg("canonical ACTIVE CTRC origin reservation is unavailable"), - errdetail("ready=%s owner=%u origin=%u segment=%u " - "generation=%u slot=%u wrap=%u xid=%u", - cluster_ctrc_shmem_ready() ? "true" : "false", - ctrc_key.owner_instance, - ctrc_key.origin_node_id, - ctrc_key.segment_id, - ctrc_key.segment_generation, - ctrc_key.slot_offset, - ctrc_key.slot_wrap, - ctrc_key.xid))); - if (ctrc_reserve_result - == CLUSTER_CTRC_ORIGIN_RESERVE_RETRY_RELEASED) - ereport(ERROR, - (errcode(ERRCODE_CLUSTER_RECONFIG_IN_PROGRESS), - errmsg("canonical ACTIVE CTRC origin release notification timed out"), - errdetail("owner=%u origin=%u segment=%u generation=%u " - "slot=%u wrap=%u xid=%u timeout_ms=%d", - ctrc_key.owner_instance, - ctrc_key.origin_node_id, - ctrc_key.segment_id, - ctrc_key.segment_generation, - ctrc_key.slot_offset, - ctrc_key.slot_wrap, - ctrc_key.xid, - cluster_ges_request_timeout_ms))); - ctrc_pre_bind_cancel_armed - = ctrc_reserve_result == CLUSTER_CTRC_ORIGIN_RESERVED_PENDING; + ereport(ERROR, (errcode(ERRCODE_CLUSTER_RECONFIG_IN_PROGRESS), + errmsg("canonical ACTIVE CTRC origin reservation is unavailable"), + errdetail("ready=%s owner=%u origin=%u segment=%u " + "generation=%u slot=%u wrap=%u xid=%u", + cluster_ctrc_shmem_ready() ? "true" : "false", + ctrc_key.owner_instance, ctrc_key.origin_node_id, + ctrc_key.segment_id, ctrc_key.segment_generation, + ctrc_key.slot_offset, ctrc_key.slot_wrap, ctrc_key.xid))); + if (ctrc_reserve_result == CLUSTER_CTRC_ORIGIN_RESERVE_RETRY_RELEASED) + ereport(ERROR, (errcode(ERRCODE_CLUSTER_RECONFIG_IN_PROGRESS), + errmsg("canonical ACTIVE CTRC origin release notification timed out"), + errdetail("owner=%u origin=%u segment=%u generation=%u " + "slot=%u wrap=%u xid=%u timeout_ms=%d", + ctrc_key.owner_instance, ctrc_key.origin_node_id, + ctrc_key.segment_id, ctrc_key.segment_generation, + ctrc_key.slot_offset, ctrc_key.slot_wrap, ctrc_key.xid, + cluster_ges_request_timeout_ms))); + ctrc_pre_bind_cancel_armed = ctrc_reserve_result == CLUSTER_CTRC_ORIGIN_RESERVED_PENDING; switch (cluster_tt_active_transition_decide( - &disk_header->tt_slots[expected_owner->slot_offset], - disk_header->wrap_count, generation.value, - expected_owner->xid, expected_owner->wrap, true)) { + &disk_header->tt_slots[expected_owner->slot_offset], disk_header->wrap_count, + generation.value, expected_owner->xid, expected_owner->wrap, true)) { case CLUSTER_TT_ACTIVE_APPLY: memset(&successor, 0, sizeof(successor)); successor.xid = expected_owner->xid; @@ -657,68 +604,60 @@ cluster_tt_slot_durable_publish_active( case CLUSTER_TT_ACTIVE_CORRUPT: default: ereport(ERROR, - (errcode(ERRCODE_DATA_CORRUPTED), - errmsg("canonical ACTIVE predecessor is not an exact legal transition"))); + (errcode(ERRCODE_DATA_CORRUPTED), + errmsg("canonical ACTIVE predecessor is not an exact legal transition"))); } - bind_lsn = cluster_undo_emit_tt_slot_bind( - owner, expected_owner->segment_id, generation.value, - expected_owner->slot_offset, expected_owner->wrap, - expected_owner->xid); + bind_lsn = cluster_undo_emit_tt_slot_bind(owner, expected_owner->segment_id, + generation.value, expected_owner->slot_offset, + expected_owner->wrap, expected_owner->xid); if (XLogRecPtrIsInvalid(bind_lsn)) - ereport(ERROR, - (errcode(ERRCODE_DATA_CORRUPTED), - errmsg("canonical ACTIVE BIND WAL was not inserted"))); - if (ctrc_pre_bind_cancel_armed) - { + ereport(ERROR, (errcode(ERRCODE_DATA_CORRUPTED), + errmsg("canonical ACTIVE BIND WAL was not inserted"))); + if (ctrc_pre_bind_cancel_armed) { ctrc_pre_bind_cancel_armed = false; ctrc_post_bind_block_armed = true; } - if (memcmp(&disk_header->tt_slots[expected_owner->slot_offset], - &successor, sizeof(successor)) != 0) { + if (memcmp(&disk_header->tt_slots[expected_owner->slot_offset], &successor, + sizeof(successor)) + != 0) { cluster_tt_durable_io_wait_start(); if (!cluster_undo_smgr_write_header_bytes( root.intent, expected_owner->segment_id, owner, - tt_slot_file_offset(expected_owner->slot_offset), - (const char *)&successor, sizeof(successor))) { + tt_slot_file_offset(expected_owner->slot_offset), (const char *)&successor, + sizeof(successor))) { cluster_tt_durable_io_wait_end(); - ereport(ERROR, - (errcode(ERRCODE_DATA_CORRUPTED), - errmsg("cannot write canonical ACTIVE TT slot"))); + ereport(ERROR, (errcode(ERRCODE_DATA_CORRUPTED), + errmsg("cannot write canonical ACTIVE TT slot"))); } cluster_tt_durable_io_wait_end(); - memcpy(&resident_header->tt_slots[expected_owner->slot_offset], - &successor, sizeof(successor)); + memcpy(&resident_header->tt_slots[expected_owner->slot_offset], &successor, + sizeof(successor)); } - if (!(target_side - ? cluster_semantic_activation_resolve_shared_undo_root( - admission, CLUSTER_UNDO_PATH_RUNTIME_SHARED, owner, - expected_owner->segment_id, &final_root) - : cluster_semantic_activation_resolve_shared_undo_root_live_owner_source( - admission, CLUSTER_UNDO_PATH_RUNTIME_SHARED, owner, - expected_owner->segment_id, &final_root)) + if (!(target_side ? cluster_semantic_activation_resolve_shared_undo_root( + admission, CLUSTER_UNDO_PATH_RUNTIME_SHARED, owner, + expected_owner->segment_id, &final_root) + : cluster_semantic_activation_resolve_shared_undo_root_live_owner_source( + admission, CLUSTER_UNDO_PATH_RUNTIME_SHARED, owner, + expected_owner->segment_id, &final_root)) || !cluster_undo_block0_root_matches(&root, &final_root) || !cluster_semantic_activation_modifier_recheck(admission, true) || cluster_epoch_get_current() != publication_epoch - || cluster_qvotec_get_self_incarnation() - != publication_boot_incarnation - || cluster_undo_block0_current_recheck_exclusive(&guard) - != CLUSTER_UNDO_BLOCK0_OK + || cluster_qvotec_get_self_incarnation() != publication_boot_incarnation + || cluster_undo_block0_current_recheck_exclusive(&guard) != CLUSTER_UNDO_BLOCK0_OK || resident_header->wrap_count != generation.value - || memcmp(&resident_header->tt_slots[expected_owner->slot_offset], - &successor, sizeof(successor)) != 0 + || memcmp(&resident_header->tt_slots[expected_owner->slot_offset], &successor, + sizeof(successor)) + != 0 || !tt_allocator_corroborates_or_rolled_away(expected_owner)) - ereport(ERROR, - (errcode(ERRCODE_CLUSTER_RECONFIG_IN_PROGRESS), - errmsg("canonical ACTIVE authority drifted during publication"))); - if (!cluster_ctrc_origin_open_reserved( - &ctrc_reservation, &ctrc_grant_generation) + ereport(ERROR, (errcode(ERRCODE_CLUSTER_RECONFIG_IN_PROGRESS), + errmsg("canonical ACTIVE authority drifted during publication"))); + if (!cluster_ctrc_origin_open_reserved(&ctrc_reservation, &ctrc_grant_generation) || ctrc_grant_generation == 0) - ereport(ERROR, - (errcode(ERRCODE_CLUSTER_RECONFIG_IN_PROGRESS), - errmsg("canonical ACTIVE CTRC origin grant is unavailable"))); + ereport(ERROR, (errcode(ERRCODE_CLUSTER_RECONFIG_IN_PROGRESS), + errmsg("canonical ACTIVE CTRC origin grant is unavailable"))); ctrc_post_bind_block_armed = false; *segment_generation_out = generation.value; @@ -727,13 +666,10 @@ cluster_tt_slot_durable_publish_active( } PG_FINALLY(); { - if (ctrc_pre_bind_cancel_armed) - { + if (ctrc_pre_bind_cancel_armed) { (void)cluster_ctrc_origin_cancel_pre_bind(&ctrc_reservation); ctrc_pre_bind_cancel_armed = false; - } - else if (ctrc_post_bind_block_armed) - { + } else if (ctrc_post_bind_block_armed) { (void)cluster_ctrc_origin_block_post_bind(&ctrc_reservation); ctrc_post_bind_block_armed = false; } @@ -753,20 +689,16 @@ cluster_tt_slot_durable_publish_active( ClusterTTActiveTransitionDecision cluster_tt_durable_bind_preflight_exact(uint8 instance, uint32 segment_id, - uint32 segment_generation, - uint16 slot_offset, uint16 wrap, + uint32 segment_generation, uint16 slot_offset, uint16 wrap, TransactionId xid) { PGAlignedBlock first; PGAlignedBlock second; - const UndoSegmentHeaderData *first_header - = (const UndoSegmentHeaderData *)first.data; - const UndoSegmentHeaderData *second_header - = (const UndoSegmentHeaderData *)second.data; + const UndoSegmentHeaderData *first_header = (const UndoSegmentHeaderData *)first.data; + const UndoSegmentHeaderData *second_header = (const UndoSegmentHeaderData *)second.data; uint8 expected_instance; - if (instance == 0 || segment_id == 0 - || slot_offset >= TT_SLOTS_PER_SEGMENT + if (instance == 0 || segment_id == 0 || slot_offset >= TT_SLOTS_PER_SEGMENT || !TransactionIdIsNormal(xid) || wrap == TT_WRAP_INVALID) return CLUSTER_TT_ACTIVE_CORRUPT; expected_instance = tt_owner_instance_for_segment(segment_id); @@ -774,99 +706,89 @@ cluster_tt_durable_bind_preflight_exact(uint8 instance, uint32 segment_id, return CLUSTER_TT_ACTIVE_CORRUPT; cluster_tt_durable_io_wait_start(); - if (!cluster_undo_smgr_read_block(cluster_undo_intent_for_owner(instance), - segment_id, instance, 0, first.data) - || !cluster_undo_smgr_read_block(cluster_undo_intent_for_owner(instance), - segment_id, instance, 0, second.data)) { + if (!cluster_undo_smgr_read_block(cluster_undo_intent_for_owner(instance), segment_id, instance, + 0, first.data) + || !cluster_undo_smgr_read_block(cluster_undo_intent_for_owner(instance), segment_id, + instance, 0, second.data)) { cluster_tt_durable_io_wait_end(); return CLUSTER_TT_ACTIVE_CONFLICT; } cluster_tt_durable_io_wait_end(); - if (first_header->segment_id != segment_id - || first_header->owner_instance != instance + if (first_header->segment_id != segment_id || first_header->owner_instance != instance || first_header->tt_slots_count != TT_SLOTS_PER_SEGMENT || second_header->segment_id != first_header->segment_id || second_header->owner_instance != first_header->owner_instance || second_header->tt_slots_count != first_header->tt_slots_count) return CLUSTER_TT_ACTIVE_CORRUPT; if (second_header->wrap_count != first_header->wrap_count - || memcmp(&second_header->tt_slots[slot_offset], - &first_header->tt_slots[slot_offset], sizeof(TTSlot)) != 0) + || memcmp(&second_header->tt_slots[slot_offset], &first_header->tt_slots[slot_offset], + sizeof(TTSlot)) + != 0) return CLUSTER_TT_ACTIVE_CONFLICT; - return cluster_tt_active_transition_decide( - &first_header->tt_slots[slot_offset], first_header->wrap_count, - segment_generation, xid, wrap, true); + return cluster_tt_active_transition_decide(&first_header->tt_slots[slot_offset], + first_header->wrap_count, segment_generation, xid, + wrap, true); } ClusterTTTerminalTransitionDecision cluster_tt_durable_abort_preflight_exact(uint8 instance, uint32 segment_id, - uint32 segment_generation, - uint16 slot_offset, uint16 wrap, + uint32 segment_generation, uint16 slot_offset, uint16 wrap, TransactionId xid) { PGAlignedBlock first; PGAlignedBlock second; - const UndoSegmentHeaderData *first_header - = (const UndoSegmentHeaderData *)first.data; - const UndoSegmentHeaderData *second_header - = (const UndoSegmentHeaderData *)second.data; + const UndoSegmentHeaderData *first_header = (const UndoSegmentHeaderData *)first.data; + const UndoSegmentHeaderData *second_header = (const UndoSegmentHeaderData *)second.data; - if (instance == 0 || segment_id == 0 - || segment_generation == UINT32_MAX - || slot_offset >= TT_SLOTS_PER_SEGMENT - || !TransactionIdIsNormal(xid) || wrap == TT_WRAP_INVALID - || instance != tt_owner_instance_for_segment(segment_id)) + if (instance == 0 || segment_id == 0 || segment_generation == UINT32_MAX + || slot_offset >= TT_SLOTS_PER_SEGMENT || !TransactionIdIsNormal(xid) + || wrap == TT_WRAP_INVALID || instance != tt_owner_instance_for_segment(segment_id)) return CLUSTER_TT_TERMINAL_CORRUPT; cluster_tt_durable_io_wait_start(); - if (!cluster_undo_smgr_read_block(cluster_undo_intent_for_owner(instance), - segment_id, instance, 0, first.data) - || !cluster_undo_smgr_read_block(cluster_undo_intent_for_owner(instance), - segment_id, instance, 0, second.data)) { + if (!cluster_undo_smgr_read_block(cluster_undo_intent_for_owner(instance), segment_id, instance, + 0, first.data) + || !cluster_undo_smgr_read_block(cluster_undo_intent_for_owner(instance), segment_id, + instance, 0, second.data)) { cluster_tt_durable_io_wait_end(); return CLUSTER_TT_TERMINAL_CONFLICT; } cluster_tt_durable_io_wait_end(); - if (first_header->segment_id != segment_id - || first_header->owner_instance != instance + if (first_header->segment_id != segment_id || first_header->owner_instance != instance || first_header->tt_slots_count != TT_SLOTS_PER_SEGMENT || second_header->segment_id != first_header->segment_id || second_header->owner_instance != first_header->owner_instance || second_header->tt_slots_count != first_header->tt_slots_count) return CLUSTER_TT_TERMINAL_CORRUPT; if (second_header->wrap_count != first_header->wrap_count - || memcmp(&second_header->tt_slots[slot_offset], - &first_header->tt_slots[slot_offset], sizeof(TTSlot)) != 0) + || memcmp(&second_header->tt_slots[slot_offset], &first_header->tt_slots[slot_offset], + sizeof(TTSlot)) + != 0) return CLUSTER_TT_TERMINAL_CONFLICT; - return cluster_tt_terminal_transition_decide( - &first_header->tt_slots[slot_offset], first_header->wrap_count, - segment_generation, xid, wrap, TT_SLOT_ABORTED, InvalidScn); + return cluster_tt_terminal_transition_decide(&first_header->tt_slots[slot_offset], + first_header->wrap_count, segment_generation, xid, + wrap, TT_SLOT_ABORTED, InvalidScn); } ClusterUndoTtCtrcReleaseRedoDecision -cluster_tt_durable_ctrc_release_preflight_exact( - const xl_undo_tt_slot_ctrc_release_v1 *record) +cluster_tt_durable_ctrc_release_preflight_exact(const xl_undo_tt_slot_ctrc_release_v1 *record) { PGAlignedBlock first; PGAlignedBlock second; - const UndoSegmentHeaderData *first_header - = (const UndoSegmentHeaderData *)first.data; - const UndoSegmentHeaderData *second_header - = (const UndoSegmentHeaderData *)second.data; + const UndoSegmentHeaderData *first_header = (const UndoSegmentHeaderData *)first.data; + const UndoSegmentHeaderData *second_header = (const UndoSegmentHeaderData *)second.data; ClusterUndoPathIntent intent; if (!cluster_undo_tt_ctrc_release_valid(record) - || record->owner_instance - != tt_owner_instance_for_segment(record->segment_id)) + || record->owner_instance != tt_owner_instance_for_segment(record->segment_id)) return CLUSTER_UNDO_TT_CTRC_RELEASE_REDO_CONFLICT; intent = cluster_undo_intent_for_owner(record->owner_instance); cluster_tt_durable_io_wait_start(); - if (!cluster_undo_smgr_read_block(intent, record->segment_id, - record->owner_instance, 0, first.data) - || !cluster_undo_smgr_read_block(intent, record->segment_id, - record->owner_instance, 0, second.data)) - { + if (!cluster_undo_smgr_read_block(intent, record->segment_id, record->owner_instance, 0, + first.data) + || !cluster_undo_smgr_read_block(intent, record->segment_id, record->owner_instance, 0, + second.data)) { cluster_tt_durable_io_wait_end(); return CLUSTER_UNDO_TT_CTRC_RELEASE_REDO_CONFLICT; } @@ -879,16 +801,15 @@ cluster_tt_durable_ctrc_release_preflight_exact( || second_header->tt_slots_count != first_header->tt_slots_count || second_header->wrap_count != first_header->wrap_count || memcmp(&second_header->tt_slots[record->slot_offset], - &first_header->tt_slots[record->slot_offset], sizeof(TTSlot)) != 0) + &first_header->tt_slots[record->slot_offset], sizeof(TTSlot)) + != 0) return CLUSTER_UNDO_TT_CTRC_RELEASE_REDO_CONFLICT; return cluster_undo_tt_ctrc_release_redo_decide( - first_header->wrap_count, - &first_header->tt_slots[record->slot_offset], record); + first_header->wrap_count, &first_header->tt_slots[record->slot_offset], record); } void -cluster_tt_durable_redo_ctrc_release_slot_exact( - const xl_undo_tt_slot_ctrc_release_v1 *record) +cluster_tt_durable_redo_ctrc_release_slot_exact(const xl_undo_tt_slot_ctrc_release_v1 *record) { ClusterUndoPathIntent intent; PGAlignedBlock block; @@ -897,69 +818,54 @@ cluster_tt_durable_redo_ctrc_release_slot_exact( TTSlot *slot; if (!cluster_undo_tt_ctrc_release_valid(record) - || record->owner_instance - != tt_owner_instance_for_segment(record->segment_id)) - ereport(PANIC, - (errcode(ERRCODE_DATA_CORRUPTED), - errmsg("invalid exact TT CTRC release identity"))); + || record->owner_instance != tt_owner_instance_for_segment(record->segment_id)) + ereport(PANIC, (errcode(ERRCODE_DATA_CORRUPTED), + errmsg("invalid exact TT CTRC release identity"))); intent = cluster_undo_intent_for_owner(record->owner_instance); cluster_tt_durable_io_wait_start(); - if (!cluster_undo_smgr_read_block(intent, record->segment_id, - record->owner_instance, 0, block.data)) - { + if (!cluster_undo_smgr_read_block(intent, record->segment_id, record->owner_instance, 0, + block.data)) { cluster_tt_durable_io_wait_end(); ereport(PANIC, (errcode(ERRCODE_DATA_CORRUPTED), - errmsg("cannot read undo segment %u for CTRC release redo", - record->segment_id))); + errmsg("cannot read undo segment %u for CTRC release redo", record->segment_id))); } - if (header->segment_id != record->segment_id - || header->owner_instance != record->owner_instance - || header->tt_slots_count != TT_SLOTS_PER_SEGMENT) - { + if (header->segment_id != record->segment_id || header->owner_instance != record->owner_instance + || header->tt_slots_count != TT_SLOTS_PER_SEGMENT) { cluster_tt_durable_io_wait_end(); - ereport(PANIC, - (errcode(ERRCODE_DATA_CORRUPTED), - errmsg("conflicting undo segment header for CTRC release redo"))); + ereport(PANIC, (errcode(ERRCODE_DATA_CORRUPTED), + errmsg("conflicting undo segment header for CTRC release redo"))); } slot = &header->tt_slots[record->slot_offset]; - decision = cluster_undo_tt_ctrc_release_redo_decide( - header->wrap_count, slot, record); - if (decision == CLUSTER_UNDO_TT_CTRC_RELEASE_REDO_SKIP_STALE) - { + decision = cluster_undo_tt_ctrc_release_redo_decide(header->wrap_count, slot, record); + if (decision == CLUSTER_UNDO_TT_CTRC_RELEASE_REDO_SKIP_STALE) { cluster_tt_durable_io_wait_end(); cluster_vis_bump_recovery_undo_redo_skips(); return; } - if (decision == CLUSTER_UNDO_TT_CTRC_RELEASE_REDO_IDEMPOTENT) - { + if (decision == CLUSTER_UNDO_TT_CTRC_RELEASE_REDO_IDEMPOTENT) { cluster_tt_durable_io_wait_end(); return; } - if (decision != CLUSTER_UNDO_TT_CTRC_RELEASE_REDO_APPLY) - { + if (decision != CLUSTER_UNDO_TT_CTRC_RELEASE_REDO_APPLY) { cluster_tt_durable_io_wait_end(); - ereport(PANIC, - (errcode(ERRCODE_DATA_CORRUPTED), - errmsg("conflicting terminal predecessor for CTRC release redo"), - errdetail("segment_generation=%u disk_generation=%u slot=%u wrap=%u xid=%u", - record->segment_generation, header->wrap_count, - record->slot_offset, record->slot_wrap, record->xid))); + ereport(PANIC, (errcode(ERRCODE_DATA_CORRUPTED), + errmsg("conflicting terminal predecessor for CTRC release redo"), + errdetail("segment_generation=%u disk_generation=%u slot=%u wrap=%u xid=%u", + record->segment_generation, header->wrap_count, + record->slot_offset, record->slot_wrap, record->xid))); } slot->flags = TT_SLOT_FLAG_CTRC_RELEASE_PROVEN; - if (!cluster_undo_smgr_write_header_bytes(intent, record->segment_id, - record->owner_instance, - (uint32)offsetof(UndoSegmentHeaderData, tt_slots) - + (uint32)record->slot_offset * (uint32)sizeof(TTSlot), - (const char *)slot, sizeof(*slot)) - || !cluster_undo_smgr_fsync_segment_file(record->segment_id, - record->owner_instance)) - { + if (!cluster_undo_smgr_write_header_bytes(intent, record->segment_id, record->owner_instance, + (uint32)offsetof(UndoSegmentHeaderData, tt_slots) + + (uint32)record->slot_offset + * (uint32)sizeof(TTSlot), + (const char *)slot, sizeof(*slot)) + || !cluster_undo_smgr_fsync_segment_file(record->segment_id, record->owner_instance)) { cluster_tt_durable_io_wait_end(); - ereport(PANIC, - (errcode(ERRCODE_DATA_CORRUPTED), - errmsg("cannot durably write CTRC release bit for undo segment %u slot %u", - record->segment_id, record->slot_offset))); + ereport(PANIC, (errcode(ERRCODE_DATA_CORRUPTED), + errmsg("cannot durably write CTRC release bit for undo segment %u slot %u", + record->segment_id, record->slot_offset))); } cluster_tt_durable_io_wait_end(); cluster_vis_bump_recovery_undo_redo_applies(); @@ -1106,9 +1012,8 @@ cluster_tt_slot_durable_commit(uint32 segment_id, uint16 slot_offset, Transactio } static uint8 -tt_slot_durable_terminal_exact(uint32 segment_id, uint32 segment_generation, - uint16 slot_offset, TransactionId xid, - uint16 wrap, uint8 terminal_status, +tt_slot_durable_terminal_exact(uint32 segment_id, uint32 segment_generation, uint16 slot_offset, + TransactionId xid, uint16 wrap, uint8 terminal_status, SCN terminal_scn, bool apply_transition, const ClusterSemanticAdmissionToken *admission, TTSlot *successor_out) @@ -1141,8 +1046,7 @@ tt_slot_durable_terminal_exact(uint32 segment_id, uint32 segment_generation, Assert((terminal_status == TT_SLOT_COMMITTED) == SCN_VALID(terminal_scn)); if (admission == NULL || successor_out == NULL || !admission->entered || segment_generation == UINT32_MAX - || (terminal_status != TT_SLOT_COMMITTED - && terminal_status != TT_SLOT_ABORTED) + || (terminal_status != TT_SLOT_COMMITTED && terminal_status != TT_SLOT_ABORTED) || (admission->side != CLUSTER_SEMANTIC_SOURCE_SIDE && admission->side != CLUSTER_SEMANTIC_TARGET_SIDE) || cluster_node_id < 0 || owner != (uint8)(cluster_node_id + 1)) @@ -1164,23 +1068,20 @@ tt_slot_durable_terminal_exact(uint32 segment_id, uint32 segment_generation, memset(&pin, 0, sizeof(pin)); pin.slot = -1; target_side = admission->side == CLUSTER_SEMANTIC_TARGET_SIDE; - root_available = target_side - ? cluster_semantic_activation_resolve_shared_undo_root( - admission, CLUSTER_UNDO_PATH_RUNTIME_SHARED, owner, segment_id, &root) - : cluster_semantic_activation_resolve_shared_undo_root_live_owner_source( - admission, CLUSTER_UNDO_PATH_RUNTIME_SHARED, owner, segment_id, &root); + root_available + = target_side ? cluster_semantic_activation_resolve_shared_undo_root( + admission, CLUSTER_UNDO_PATH_RUNTIME_SHARED, owner, segment_id, &root) + : cluster_semantic_activation_resolve_shared_undo_root_live_owner_source( + admission, CLUSTER_UNDO_PATH_RUNTIME_SHARED, owner, segment_id, &root); if (!tt_allocator_corroborates_or_rolled_away(&expected_owner)) - ereport(ERROR, - (errcode(ERRCODE_CLUSTER_RECONFIG_IN_PROGRESS), - errmsg("cannot commit a transaction: allocator identity is not exact"))); + ereport(ERROR, (errcode(ERRCODE_CLUSTER_RECONFIG_IN_PROGRESS), + errmsg("cannot commit a transaction: allocator identity is not exact"))); step = target_side - ? cluster_undo_block0_current_acquire_begin_live_owner_target( - &key, cluster_ges_request_timeout_ms, admission, &guard, - ¤t_failure) - : cluster_undo_block0_current_acquire_begin_live_owner_source( - &key, cluster_ges_request_timeout_ms, admission, &guard, - ¤t_failure); + ? cluster_undo_block0_current_acquire_begin_live_owner_target( + &key, cluster_ges_request_timeout_ms, admission, &guard, ¤t_failure) + : cluster_undo_block0_current_acquire_begin_live_owner_source( + &key, cluster_ges_request_timeout_ms, admission, &guard, ¤t_failure); if (step == CLUSTER_UNDO_BLOCK0_CURRENT_FAILED) { ges_failure = cluster_ges_timeout_detail_get(); ereport( @@ -1227,75 +1128,67 @@ tt_slot_durable_terminal_exact(uint32 segment_id, uint32 segment_generation, "segment=%u result=%d", cluster_node_id, segment_id, (int)current_failure))); - result = cluster_undo_block0_current_sample_generation_exclusive( - &guard, &root, &generation); + result + = cluster_undo_block0_current_sample_generation_exclusive(&guard, &root, &generation); if (result != CLUSTER_UNDO_BLOCK0_OK || !generation.known || generation.value != segment_generation) - ereport(ERROR, - (errcode(ERRCODE_CLUSTER_RECONFIG_IN_PROGRESS), - errmsg("cannot commit a transaction: canonical generation changed"))); - result = cluster_undo_block0_current_pin_exclusive( - &guard, &root, &generation, &pin, (char **)&resident_header); + ereport(ERROR, (errcode(ERRCODE_CLUSTER_RECONFIG_IN_PROGRESS), + errmsg("cannot commit a transaction: canonical generation changed"))); + result = cluster_undo_block0_current_pin_exclusive(&guard, &root, &generation, &pin, + (char **)&resident_header); if (result != CLUSTER_UNDO_BLOCK0_OK || resident_header == NULL) - ereport(ERROR, - (errcode(ERRCODE_CLUSTER_RECONFIG_IN_PROGRESS), - errmsg("cannot commit a transaction: canonical block-zero content is unavailable"))); + ereport( + ERROR, + (errcode(ERRCODE_CLUSTER_RECONFIG_IN_PROGRESS), + errmsg( + "cannot commit a transaction: canonical block-zero content is unavailable"))); pin_held = true; cluster_tt_durable_io_wait_start(); - if (!cluster_undo_smgr_read_block(root.intent, segment_id, owner, 0, - disk_block.data)) { + if (!cluster_undo_smgr_read_block(root.intent, segment_id, owner, 0, disk_block.data)) { cluster_tt_durable_io_wait_end(); - ereport(ERROR, - (errcode(ERRCODE_DATA_CORRUPTED), - errmsg("cannot read canonical TT block zero for commit"))); + ereport(ERROR, (errcode(ERRCODE_DATA_CORRUPTED), + errmsg("cannot read canonical TT block zero for commit"))); } cluster_tt_durable_io_wait_end(); - if (disk_header->segment_id != segment_id - || disk_header->owner_instance != owner + if (disk_header->segment_id != segment_id || disk_header->owner_instance != owner || disk_header->tt_slots_count != TT_SLOTS_PER_SEGMENT || disk_header->wrap_count != segment_generation || resident_header->segment_id != disk_header->segment_id || resident_header->owner_instance != disk_header->owner_instance || resident_header->tt_slots_count != disk_header->tt_slots_count || resident_header->wrap_count != disk_header->wrap_count - || memcmp(&resident_header->tt_slots[slot_offset], - &disk_header->tt_slots[slot_offset], sizeof(TTSlot)) != 0) - ereport(ERROR, - (errcode(ERRCODE_DATA_CORRUPTED), - errmsg("canonical TT commit identity or generation mismatch"))); + || memcmp(&resident_header->tt_slots[slot_offset], &disk_header->tt_slots[slot_offset], + sizeof(TTSlot)) + != 0) + ereport(ERROR, (errcode(ERRCODE_DATA_CORRUPTED), + errmsg("canonical TT commit identity or generation mismatch"))); decision = cluster_tt_terminal_transition_decide( - &disk_header->tt_slots[slot_offset], disk_header->wrap_count, - segment_generation, xid, wrap, terminal_status, terminal_scn); - if (decision != CLUSTER_TT_TERMINAL_APPLY - && decision != CLUSTER_TT_TERMINAL_IDEMPOTENT) - ereport(ERROR, - (errcode(ERRCODE_DATA_CORRUPTED), - errmsg("canonical TT commit predecessor is not exact"))); + &disk_header->tt_slots[slot_offset], disk_header->wrap_count, segment_generation, xid, + wrap, terminal_status, terminal_scn); + if (decision != CLUSTER_TT_TERMINAL_APPLY && decision != CLUSTER_TT_TERMINAL_IDEMPOTENT) + ereport(ERROR, (errcode(ERRCODE_DATA_CORRUPTED), + errmsg("canonical TT commit predecessor is not exact"))); successor = disk_header->tt_slots[slot_offset]; successor.status = terminal_status; successor.flags = TT_FLAGS_RESERVED; successor.commit_scn = terminal_scn; successor.first_undo_block = InvalidUbaVal; - final_expected = apply_transition ? successor - : disk_header->tt_slots[slot_offset]; + final_expected = apply_transition ? successor : disk_header->tt_slots[slot_offset]; memset(&final_root, 0, sizeof(final_root)); if (!(target_side ? cluster_semantic_activation_resolve_shared_undo_root( - admission, CLUSTER_UNDO_PATH_RUNTIME_SHARED, owner, - segment_id, &final_root) + admission, CLUSTER_UNDO_PATH_RUNTIME_SHARED, owner, segment_id, &final_root) : cluster_semantic_activation_resolve_shared_undo_root_live_owner_source( - admission, CLUSTER_UNDO_PATH_RUNTIME_SHARED, owner, - segment_id, &final_root)) + admission, CLUSTER_UNDO_PATH_RUNTIME_SHARED, owner, segment_id, + &final_root)) || !cluster_undo_block0_root_matches(&root, &final_root) || !cluster_semantic_activation_modifier_recheck(admission, true) - || cluster_undo_block0_current_recheck_exclusive(&guard) - != CLUSTER_UNDO_BLOCK0_OK) - ereport(ERROR, - (errcode(ERRCODE_CLUSTER_RECONFIG_IN_PROGRESS), - errmsg("canonical TT commit authority drifted before transition"))); + || cluster_undo_block0_current_recheck_exclusive(&guard) != CLUSTER_UNDO_BLOCK0_OK) + ereport(ERROR, (errcode(ERRCODE_CLUSTER_RECONFIG_IN_PROGRESS), + errmsg("canonical TT commit authority drifted before transition"))); if (apply_transition && decision == CLUSTER_TT_TERMINAL_APPLY) { cluster_tt_durable_io_wait_start(); @@ -1303,34 +1196,29 @@ tt_slot_durable_terminal_exact(uint32 segment_id, uint32 segment_generation, root.intent, segment_id, owner, tt_slot_file_offset(slot_offset), (const char *)&successor, sizeof(successor))) { cluster_tt_durable_io_wait_end(); - ereport(ERROR, - (errcode(ERRCODE_DATA_CORRUPTED), - errmsg("cannot write canonical terminal TT slot"))); + ereport(ERROR, (errcode(ERRCODE_DATA_CORRUPTED), + errmsg("cannot write canonical terminal TT slot"))); } cluster_tt_durable_io_wait_end(); - memcpy(&resident_header->tt_slots[slot_offset], &successor, - sizeof(successor)); + memcpy(&resident_header->tt_slots[slot_offset], &successor, sizeof(successor)); } memset(&final_root, 0, sizeof(final_root)); if (!(target_side ? cluster_semantic_activation_resolve_shared_undo_root( - admission, CLUSTER_UNDO_PATH_RUNTIME_SHARED, owner, - segment_id, &final_root) + admission, CLUSTER_UNDO_PATH_RUNTIME_SHARED, owner, segment_id, &final_root) : cluster_semantic_activation_resolve_shared_undo_root_live_owner_source( - admission, CLUSTER_UNDO_PATH_RUNTIME_SHARED, owner, - segment_id, &final_root)) + admission, CLUSTER_UNDO_PATH_RUNTIME_SHARED, owner, segment_id, + &final_root)) || !cluster_undo_block0_root_matches(&root, &final_root) || !cluster_semantic_activation_modifier_recheck(admission, true) - || cluster_undo_block0_current_recheck_exclusive(&guard) - != CLUSTER_UNDO_BLOCK0_OK + || cluster_undo_block0_current_recheck_exclusive(&guard) != CLUSTER_UNDO_BLOCK0_OK || resident_header->wrap_count != segment_generation - || memcmp(&resident_header->tt_slots[slot_offset], &final_expected, - sizeof(successor)) != 0 + || memcmp(&resident_header->tt_slots[slot_offset], &final_expected, sizeof(successor)) + != 0 || !tt_allocator_corroborates_or_rolled_away(&expected_owner)) - ereport(ERROR, - (errcode(ERRCODE_CLUSTER_RECONFIG_IN_PROGRESS), - errmsg("canonical TT commit authority drifted after transition"))); + ereport(ERROR, (errcode(ERRCODE_CLUSTER_RECONFIG_IN_PROGRESS), + errmsg("canonical TT commit authority drifted after transition"))); *successor_out = successor; } @@ -1354,43 +1242,40 @@ tt_slot_durable_terminal_exact(uint32 segment_id, uint32 segment_generation, } uint8 -cluster_tt_slot_durable_commit_writeonly(uint32 segment_id, - uint32 segment_generation, - uint16 slot_offset, TransactionId xid, - uint16 wrap, SCN commit_scn, +cluster_tt_slot_durable_commit_writeonly(uint32 segment_id, uint32 segment_generation, + uint16 slot_offset, TransactionId xid, uint16 wrap, + SCN commit_scn, const ClusterSemanticAdmissionToken *admission, TTSlot *successor_out) { uint8 owner; - owner = tt_slot_durable_terminal_exact(segment_id, segment_generation, - slot_offset, xid, wrap, TT_SLOT_COMMITTED, commit_scn, true, - admission, successor_out); + owner = tt_slot_durable_terminal_exact(segment_id, segment_generation, slot_offset, xid, wrap, + TT_SLOT_COMMITTED, commit_scn, true, admission, + successor_out); cluster_tt_durable_count_commit(); return owner; } XLogRecPtr -cluster_tt_slot_durable_abort_exact(uint32 segment_id, - uint32 segment_generation, - uint16 slot_offset, TransactionId xid, - uint16 wrap, - const ClusterSemanticAdmissionToken *admission, - TTSlot *successor_out) +cluster_tt_slot_durable_abort_exact(uint32 segment_id, uint32 segment_generation, + uint16 slot_offset, TransactionId xid, uint16 wrap, + const ClusterSemanticAdmissionToken *admission, + TTSlot *successor_out) { TTSlot prepared_successor; XLogRecPtr abort_lsn; uint8 owner; - owner = tt_slot_durable_terminal_exact(segment_id, segment_generation, - slot_offset, xid, wrap, TT_SLOT_ABORTED, InvalidScn, false, - admission, &prepared_successor); - abort_lsn = cluster_undo_emit_tt_slot_abort_exact(owner, segment_id, - segment_generation, slot_offset, wrap, xid); + owner = tt_slot_durable_terminal_exact(segment_id, segment_generation, slot_offset, xid, wrap, + TT_SLOT_ABORTED, InvalidScn, false, admission, + &prepared_successor); + abort_lsn = cluster_undo_emit_tt_slot_abort_exact(owner, segment_id, segment_generation, + slot_offset, wrap, xid); XLogFlush(abort_lsn); - (void)tt_slot_durable_terminal_exact(segment_id, segment_generation, - slot_offset, xid, wrap, TT_SLOT_ABORTED, InvalidScn, true, - admission, successor_out); + (void)tt_slot_durable_terminal_exact(segment_id, segment_generation, slot_offset, xid, wrap, + TT_SLOT_ABORTED, InvalidScn, true, admission, + successor_out); return abort_lsn; } @@ -1595,9 +1480,8 @@ cluster_tt_slot_durable_lookup_committed_stable(uint32 segment_id, uint16 slot_o } bool -cluster_tt_slot_durable_read_exact_stable(uint32 segment_id, uint16 slot_offset, - TransactionId xid, uint16 expected_wrap, - TTSlot *slot_out) +cluster_tt_slot_durable_read_exact_stable(uint32 segment_id, uint16 slot_offset, TransactionId xid, + uint16 expected_wrap, TTSlot *slot_out) { uint8 owner; uint32 off; @@ -1609,8 +1493,7 @@ cluster_tt_slot_durable_read_exact_stable(uint32 segment_id, uint16 slot_offset, memset(slot_out, 0, sizeof(*slot_out)); if (segment_id == 0 - || segment_id - > ((uint32)SCN_MAX_VALID_NODE_ID + 1) * CLUSTER_UNDO_SEGS_PER_INSTANCE + || segment_id > ((uint32)SCN_MAX_VALID_NODE_ID + 1) * CLUSTER_UNDO_SEGS_PER_INSTANCE || slot_offset >= TT_SLOTS_PER_SEGMENT || !TransactionIdIsNormal(xid) || expected_wrap == TT_WRAP_INVALID) return false; @@ -1627,8 +1510,7 @@ cluster_tt_slot_durable_read_exact_stable(uint32 segment_id, uint16 slot_offset, } cluster_tt_durable_io_wait_end(); - if (first.status > (uint8)TT_SLOT_RECYCLABLE || first.xid != xid - || first.wrap != expected_wrap) + if (first.status > (uint8)TT_SLOT_RECYCLABLE || first.xid != xid || first.wrap != expected_wrap) return false; cluster_tt_durable_io_wait_start(); @@ -1639,9 +1521,8 @@ cluster_tt_slot_durable_read_exact_stable(uint32 segment_id, uint16 slot_offset, } cluster_tt_durable_io_wait_end(); - if (memcmp(&first, &second, sizeof(first)) != 0 - || second.status > (uint8)TT_SLOT_RECYCLABLE || second.xid != xid - || second.wrap != expected_wrap) + if (memcmp(&first, &second, sizeof(first)) != 0 || second.status > (uint8)TT_SLOT_RECYCLABLE + || second.xid != xid || second.wrap != expected_wrap) return false; *slot_out = second; @@ -1650,44 +1531,34 @@ cluster_tt_slot_durable_read_exact_stable(uint32 segment_id, uint16 slot_offset, void -cluster_tt_durable_redo_abort_slot(uint8 instance, uint32 segment_id, - uint16 slot_offset, uint16 wrap, - TransactionId xid) +cluster_tt_durable_redo_abort_slot(uint8 instance, uint32 segment_id, uint16 slot_offset, + uint16 wrap, TransactionId xid) { - uint32 off; - TTSlot slot; + uint32 off; + TTSlot slot; ClusterTTRedoDecision decision; - if (instance == 0 || segment_id == 0 || - instance != tt_owner_instance_for_segment(segment_id) || - slot_offset >= TT_SLOTS_PER_SEGMENT || !TransactionIdIsNormal(xid) || - wrap == TT_WRAP_INVALID) + if (instance == 0 || segment_id == 0 || instance != tt_owner_instance_for_segment(segment_id) + || slot_offset >= TT_SLOTS_PER_SEGMENT || !TransactionIdIsNormal(xid) + || wrap == TT_WRAP_INVALID) ereport(PANIC, - (errcode(ERRCODE_DATA_CORRUPTED), - errmsg("invalid typed TT abort redo identity"))); + (errcode(ERRCODE_DATA_CORRUPTED), errmsg("invalid typed TT abort redo identity"))); off = tt_slot_file_offset(slot_offset); cluster_tt_durable_io_wait_start(); - if (!cluster_undo_smgr_read_header_bytes( - cluster_undo_intent_for_owner(instance), segment_id, instance, off, - (char *) &slot, sizeof(slot))) - { + if (!cluster_undo_smgr_read_header_bytes(cluster_undo_intent_for_owner(instance), segment_id, + instance, off, (char *)&slot, sizeof(slot))) { cluster_tt_durable_io_wait_end(); - ereport(PANIC, - (errcode(ERRCODE_DATA_CORRUPTED), - errmsg("cannot read TT slot %u of undo segment %u for abort redo", - slot_offset, segment_id))); + ereport(PANIC, (errcode(ERRCODE_DATA_CORRUPTED), + errmsg("cannot read TT slot %u of undo segment %u for abort redo", + slot_offset, segment_id))); } - decision = cluster_tt_durable_redo_decide(slot.status, slot.xid, - slot.wrap, xid, wrap); - if (decision == CLUSTER_TT_REDO_BADSTATUS) - { + decision = cluster_tt_durable_redo_decide(slot.status, slot.xid, slot.wrap, xid, wrap); + if (decision == CLUSTER_TT_REDO_BADSTATUS) { cluster_tt_durable_io_wait_end(); - ereport(PANIC, - (errcode(ERRCODE_DATA_CORRUPTED), - errmsg("invalid TT status %u in typed abort redo", slot.status))); + ereport(PANIC, (errcode(ERRCODE_DATA_CORRUPTED), + errmsg("invalid TT status %u in typed abort redo", slot.status))); } - if (decision == CLUSTER_TT_REDO_SKIP) - { + if (decision == CLUSTER_TT_REDO_SKIP) { cluster_tt_durable_io_wait_end(); cluster_vis_bump_recovery_undo_redo_skips(); return; @@ -1698,16 +1569,13 @@ cluster_tt_durable_redo_abort_slot(uint8 instance, uint32 segment_id, slot.flags = TT_FLAGS_RESERVED; slot.commit_scn = InvalidScn; slot.first_undo_block = InvalidUbaVal; - if (!cluster_undo_smgr_write_header_bytes( - cluster_undo_intent_for_owner(instance), segment_id, instance, off, - (const char *) &slot, sizeof(slot)) || - !cluster_undo_smgr_fsync_segment_file(segment_id, instance)) - { + if (!cluster_undo_smgr_write_header_bytes(cluster_undo_intent_for_owner(instance), segment_id, + instance, off, (const char *)&slot, sizeof(slot)) + || !cluster_undo_smgr_fsync_segment_file(segment_id, instance)) { cluster_tt_durable_io_wait_end(); - ereport(PANIC, - (errcode(ERRCODE_DATA_CORRUPTED), - errmsg("cannot durably write TT slot %u of undo segment %u for abort redo", - slot_offset, segment_id))); + ereport(PANIC, (errcode(ERRCODE_DATA_CORRUPTED), + errmsg("cannot durably write TT slot %u of undo segment %u for abort redo", + slot_offset, segment_id))); } cluster_tt_durable_io_wait_end(); cluster_vis_bump_recovery_undo_redo_applies(); @@ -1715,8 +1583,7 @@ cluster_tt_durable_redo_abort_slot(uint8 instance, uint32 segment_id, void cluster_tt_durable_redo_abort_slot_exact(uint8 instance, uint32 segment_id, - uint32 segment_generation, - uint16 slot_offset, uint16 wrap, + uint32 segment_generation, uint16 slot_offset, uint16 wrap, TransactionId xid) { PGAlignedBlock block; @@ -1724,34 +1591,28 @@ cluster_tt_durable_redo_abort_slot_exact(uint8 instance, uint32 segment_id, TTSlot successor; ClusterTTTerminalTransitionDecision decision; - if (instance == 0 || segment_id == 0 - || segment_generation == UINT32_MAX + if (instance == 0 || segment_id == 0 || segment_generation == UINT32_MAX || instance != tt_owner_instance_for_segment(segment_id) - || slot_offset >= TT_SLOTS_PER_SEGMENT - || !TransactionIdIsNormal(xid) || wrap == TT_WRAP_INVALID) + || slot_offset >= TT_SLOTS_PER_SEGMENT || !TransactionIdIsNormal(xid) + || wrap == TT_WRAP_INVALID) ereport(PANIC, - (errcode(ERRCODE_DATA_CORRUPTED), - errmsg("invalid exact TT abort redo identity"))); + (errcode(ERRCODE_DATA_CORRUPTED), errmsg("invalid exact TT abort redo identity"))); cluster_tt_durable_io_wait_start(); - if (!cluster_undo_smgr_read_block(cluster_undo_intent_for_owner(instance), - segment_id, instance, 0, block.data)) { + if (!cluster_undo_smgr_read_block(cluster_undo_intent_for_owner(instance), segment_id, instance, + 0, block.data)) { cluster_tt_durable_io_wait_end(); - ereport(PANIC, - (errcode(ERRCODE_DATA_CORRUPTED), - errmsg("cannot read undo segment %u for exact abort redo", - segment_id))); + ereport(PANIC, (errcode(ERRCODE_DATA_CORRUPTED), + errmsg("cannot read undo segment %u for exact abort redo", segment_id))); } - if (header->segment_id != segment_id - || header->owner_instance != instance + if (header->segment_id != segment_id || header->owner_instance != instance || header->tt_slots_count != TT_SLOTS_PER_SEGMENT) { cluster_tt_durable_io_wait_end(); - ereport(PANIC, - (errcode(ERRCODE_DATA_CORRUPTED), - errmsg("conflicting undo segment header for exact abort redo"))); + ereport(PANIC, (errcode(ERRCODE_DATA_CORRUPTED), + errmsg("conflicting undo segment header for exact abort redo"))); } - decision = cluster_tt_terminal_transition_decide( - &header->tt_slots[slot_offset], header->wrap_count, - segment_generation, xid, wrap, TT_SLOT_ABORTED, InvalidScn); + decision = cluster_tt_terminal_transition_decide(&header->tt_slots[slot_offset], + header->wrap_count, segment_generation, xid, + wrap, TT_SLOT_ABORTED, InvalidScn); if (decision == CLUSTER_TT_TERMINAL_STALE) { cluster_tt_durable_io_wait_end(); cluster_vis_bump_recovery_undo_redo_skips(); @@ -1763,24 +1624,21 @@ cluster_tt_durable_redo_abort_slot_exact(uint8 instance, uint32 segment_id, } if (decision != CLUSTER_TT_TERMINAL_APPLY) { cluster_tt_durable_io_wait_end(); - ereport(PANIC, - (errcode(ERRCODE_DATA_CORRUPTED), - errmsg("conflicting canonical ACTIVE predecessor for exact abort redo"))); + ereport(PANIC, (errcode(ERRCODE_DATA_CORRUPTED), + errmsg("conflicting canonical ACTIVE predecessor for exact abort redo"))); } successor = header->tt_slots[slot_offset]; successor.status = TT_SLOT_ABORTED; successor.flags = TT_FLAGS_RESERVED; successor.commit_scn = InvalidScn; successor.first_undo_block = InvalidUbaVal; - if (!cluster_undo_smgr_write_header_bytes( - cluster_undo_intent_for_owner(instance), segment_id, instance, - tt_slot_file_offset(slot_offset), (const char *)&successor, - sizeof(successor)) + if (!cluster_undo_smgr_write_header_bytes(cluster_undo_intent_for_owner(instance), segment_id, + instance, tt_slot_file_offset(slot_offset), + (const char *)&successor, sizeof(successor)) || !cluster_undo_smgr_fsync_segment_file(segment_id, instance)) { cluster_tt_durable_io_wait_end(); - ereport(PANIC, - (errcode(ERRCODE_DATA_CORRUPTED), - errmsg("cannot durably write exact ABORTED TT slot"))); + ereport(PANIC, (errcode(ERRCODE_DATA_CORRUPTED), + errmsg("cannot durably write exact ABORTED TT slot"))); } cluster_tt_durable_io_wait_end(); cluster_vis_bump_recovery_undo_redo_applies(); @@ -1788,51 +1646,40 @@ cluster_tt_durable_redo_abort_slot_exact(uint8 instance, uint32 segment_id, void -cluster_tt_durable_redo_set_head_slot(uint8 instance, uint32 segment_id, - uint16 slot_offset, uint16 wrap, - TransactionId xid, - UBA first_undo_block) +cluster_tt_durable_redo_set_head_slot(uint8 instance, uint32 segment_id, uint16 slot_offset, + uint16 wrap, TransactionId xid, UBA first_undo_block) { - uint32 off; - TTSlot slot; + uint32 off; + TTSlot slot; - if (instance == 0 || segment_id == 0 || - instance != tt_owner_instance_for_segment(segment_id) || - slot_offset >= TT_SLOTS_PER_SEGMENT || !TransactionIdIsNormal(xid) || - wrap == TT_WRAP_INVALID || UBA_is_invalid(first_undo_block)) - ereport(PANIC, - (errcode(ERRCODE_DATA_CORRUPTED), - errmsg("invalid typed TT set-head redo identity"))); + if (instance == 0 || segment_id == 0 || instance != tt_owner_instance_for_segment(segment_id) + || slot_offset >= TT_SLOTS_PER_SEGMENT || !TransactionIdIsNormal(xid) + || wrap == TT_WRAP_INVALID || UBA_is_invalid(first_undo_block)) + ereport(PANIC, (errcode(ERRCODE_DATA_CORRUPTED), + errmsg("invalid typed TT set-head redo identity"))); off = tt_slot_file_offset(slot_offset); cluster_tt_durable_io_wait_start(); - if (!cluster_undo_smgr_read_header_bytes( - cluster_undo_intent_for_owner(instance), segment_id, instance, off, - (char *) &slot, sizeof(slot))) - { + if (!cluster_undo_smgr_read_header_bytes(cluster_undo_intent_for_owner(instance), segment_id, + instance, off, (char *)&slot, sizeof(slot))) { cluster_tt_durable_io_wait_end(); - ereport(PANIC, - (errcode(ERRCODE_DATA_CORRUPTED), - errmsg("cannot read TT slot %u of undo segment %u for set-head redo", - slot_offset, segment_id))); + ereport(PANIC, (errcode(ERRCODE_DATA_CORRUPTED), + errmsg("cannot read TT slot %u of undo segment %u for set-head redo", + slot_offset, segment_id))); } - if (slot.status != TT_SLOT_ABORTED || slot.xid != xid || - slot.wrap != wrap) - { + if (slot.status != TT_SLOT_ABORTED || slot.xid != xid || slot.wrap != wrap) { cluster_tt_durable_io_wait_end(); cluster_vis_bump_recovery_undo_redo_skips(); return; } slot.first_undo_block = first_undo_block; - if (!cluster_undo_smgr_write_header_bytes( - cluster_undo_intent_for_owner(instance), segment_id, instance, off, - (const char *) &slot, sizeof(slot)) || - !cluster_undo_smgr_fsync_segment_file(segment_id, instance)) - { + if (!cluster_undo_smgr_write_header_bytes(cluster_undo_intent_for_owner(instance), segment_id, + instance, off, (const char *)&slot, sizeof(slot)) + || !cluster_undo_smgr_fsync_segment_file(segment_id, instance)) { cluster_tt_durable_io_wait_end(); ereport(PANIC, (errcode(ERRCODE_DATA_CORRUPTED), errmsg("cannot durably write TT slot %u of undo segment %u for set-head redo", - slot_offset, segment_id))); + slot_offset, segment_id))); } cluster_tt_durable_io_wait_end(); cluster_vis_bump_recovery_undo_redo_applies(); @@ -2112,48 +1959,45 @@ cluster_tt_slot_durable_resolve_by_xid_origin(int origin_node, TransactionId xid } ClusterTTDurableLocate -cluster_tt_slot_durable_locate_any_by_xid_origin(int origin_node, - TransactionId xid, uint16 *out_seg, uint16 *out_slot, - uint16 *out_wrap, uint8 *out_status) +cluster_tt_slot_durable_locate_any_by_xid_origin(int origin_node, TransactionId xid, + uint16 *out_seg, uint16 *out_slot, + uint16 *out_wrap, uint8 *out_status) { - uint8 owner; - uint32 seg_lo; - uint32 seg_hi; - uint32 segment_id; + uint8 owner; + uint32 seg_lo; + uint32 seg_hi; + uint32 segment_id; PGAlignedBlock blockbuf; - uint32 matches = 0; - bool scan_complete = true; - uint16 matched_seg = 0; - uint16 matched_slot = 0; - uint16 matched_wrap = 0; - uint8 matched_status = TT_SLOT_INVALID; + uint32 matches = 0; + bool scan_complete = true; + uint16 matched_seg = 0; + uint16 matched_slot = 0; + uint16 matched_wrap = 0; + uint8 matched_status = TT_SLOT_INVALID; if (origin_node < 0 || !TransactionIdIsNormal(xid)) return CLUSTER_TT_DURABLE_LOCATE_SCAN_UNAVAILABLE; - owner = (uint8) (origin_node + 1); - seg_lo = (uint32) origin_node * CLUSTER_UNDO_SEGS_PER_INSTANCE + 1; + owner = (uint8)(origin_node + 1); + seg_lo = (uint32)origin_node * CLUSTER_UNDO_SEGS_PER_INSTANCE + 1; seg_hi = seg_lo + CLUSTER_UNDO_SEGS_PER_INSTANCE - 1; cluster_tt_durable_count_by_xid_scan(); cluster_tt_durable_io_wait_start(); - for (segment_id = seg_lo; segment_id <= seg_hi; segment_id++) - { + for (segment_id = seg_lo; segment_id <= seg_hi; segment_id++) { const UndoSegmentHeaderData *header; uint16 i; if (!durable_scan_read_header(owner, segment_id, blockbuf.data, &scan_complete)) continue; - header = (const UndoSegmentHeaderData *) blockbuf.data; - for (i = 0; i < TT_SLOTS_PER_SEGMENT; i++) - { + header = (const UndoSegmentHeaderData *)blockbuf.data; + for (i = 0; i < TT_SLOTS_PER_SEGMENT; i++) { const TTSlot *slot = &header->tt_slots[i]; - if (slot->xid != xid || - (slot->status != TT_SLOT_ACTIVE && - slot->status != TT_SLOT_COMMITTED && - slot->status != TT_SLOT_ABORTED)) + if (slot->xid != xid + || (slot->status != TT_SLOT_ACTIVE && slot->status != TT_SLOT_COMMITTED + && slot->status != TT_SLOT_ABORTED)) continue; matches++; - matched_seg = (uint16) segment_id; + matched_seg = (uint16)segment_id; matched_slot = i; matched_wrap = slot->wrap; matched_status = slot->status; diff --git a/src/backend/cluster/cluster_tt_local.c b/src/backend/cluster/cluster_tt_local.c index 315f6433247..d2e50f9fc97 100644 --- a/src/backend/cluster/cluster_tt_local.c +++ b/src/backend/cluster/cluster_tt_local.c @@ -291,8 +291,7 @@ cluster_tt_local_reserve_binding(TransactionId top_xid, uint32 *out_segment_id, retained_pressure = true; } else off = cluster_tt_slot_alloc_current_exact( - cluster_node_id, seg, top_xid, &retained_pressure, - ¤t_drift, &wrap); + cluster_node_id, seg, top_xid, &retained_pressure, ¤t_drift, &wrap); if (current_drift) continue; if (off != INVALID_TT_SLOT_OFFSET) @@ -376,7 +375,6 @@ cluster_tt_local_reserve_binding(TransactionId top_xid, uint32 *out_segment_id, errhint("A long-running reader is retaining committed undo; end it, " "or raise cluster.undo_segments_max_per_instance."))); } - } } @@ -412,8 +410,7 @@ cluster_tt_local_peek_binding(TransactionId top_xid, uint32 *out_segment_id, idx = cluster_tt_local_find_binding(top_xid); if (idx < 0 || !TransactionIdIsValid(top_xid) - || cluster_tt_local_bindings[idx].publish_state - != CLUSTER_CANONICAL_TXN_PUBLISHED) + || cluster_tt_local_bindings[idx].publish_state != CLUSTER_CANONICAL_TXN_PUBLISHED) return false; b = &cluster_tt_local_bindings[idx]; @@ -502,16 +499,14 @@ cluster_tt_local_finish_bindings(bool committed, SCN commit_scn) if (!TransactionIdIsValid(b->top_xid)) continue; - if (committed - && b->publish_state == CLUSTER_CANONICAL_TXN_PUBLISHED + if (committed && b->publish_state == CLUSTER_CANONICAL_TXN_PUBLISHED && b->terminal_state == CLUSTER_TT_LOCAL_TERMINAL_COMMIT_STAGED) cluster_tt_slot_mark_committed(b->segment_id, b->slot_offset, b->top_xid, commit_scn); else if (!committed && ((b->publish_state == CLUSTER_CANONICAL_TXN_RESERVED && b->terminal_state == CLUSTER_TT_LOCAL_TERMINAL_NONE) || (b->publish_state == CLUSTER_CANONICAL_TXN_PUBLISHED - && b->terminal_state - == CLUSTER_TT_LOCAL_TERMINAL_ABORT_DURABLE))) + && b->terminal_state == CLUSTER_TT_LOCAL_TERMINAL_ABORT_DURABLE))) cluster_tt_slot_mark_aborted(b->segment_id, b->slot_offset, b->top_xid); } @@ -561,9 +556,9 @@ install_key(const ClusterTTStatusKey *key, ClusterTTStatus status, SCN commit_sc source_request.status = status; source_request.commit_scn = commit_scn; installed = cluster_tt_status_source_dispatch(CLUSTER_TT_SOURCE_INSTALL_LOCAL, &source_request, - &source_result) - == CLUSTER_SEMANTIC_ADMISSION_OK - && source_result.bool_value; + &source_result) + == CLUSTER_SEMANTIC_ADMISSION_OK + && source_result.bool_value; if (!installed) return; @@ -580,9 +575,9 @@ install_key(const ClusterTTStatusKey *key, ClusterTTStatus status, SCN commit_sc memset(&lookup_request, 0, sizeof(lookup_request)); lookup_request.key = key; hit = cluster_tt_status_source_dispatch(CLUSTER_TT_SOURCE_LOOKUP, &lookup_request, - &lookup_result) - == CLUSTER_SEMANTIC_ADMISSION_OK - && lookup_result.bool_value; + &lookup_result) + == CLUSTER_SEMANTIC_ADMISSION_OK + && lookup_result.bool_value; res = lookup_result.lookup; epoch_stable = ((uint32)cluster_epoch_get_current() == key->cluster_epoch); } @@ -683,8 +678,7 @@ cluster_tt_local_writable_admission(void) static void cluster_tt_local_modifier_recheck_or_error(const ClusterSemanticAdmissionToken *token) { - if (!cluster_semantic_activation_modifier_recheck(token, - cluster_tt_local_writable_admission())) + if (!cluster_semantic_activation_modifier_recheck(token, cluster_tt_local_writable_admission())) ereport(ERROR, (errcode(ERRCODE_CLUSTER_RECONFIG_IN_PROGRESS), errmsg("cannot commit a transaction: cluster reconfiguration in progress"), @@ -695,16 +689,12 @@ static bool cluster_tt_local_copy_published(const ClusterTTLocalBinding *binding, ClusterCanonicalTxnBinding *out) { - if (binding == NULL || out == NULL - || binding->publish_state != CLUSTER_CANONICAL_TXN_PUBLISHED - || !TransactionIdIsNormal(binding->top_xid) - || binding->segment_id == 0 - || binding->segment_generation == UINT32_MAX - || binding->slot_offset >= TT_SLOTS_PER_SEGMENT - || binding->wrap == TT_WRAP_INVALID - || XLogRecPtrIsInvalid(binding->active_lsn) - || binding->terminal_state != CLUSTER_TT_LOCAL_TERMINAL_NONE - || binding->reserved8[0] != 0 || binding->reserved8[1] != 0) + if (binding == NULL || out == NULL || binding->publish_state != CLUSTER_CANONICAL_TXN_PUBLISHED + || !TransactionIdIsNormal(binding->top_xid) || binding->segment_id == 0 + || binding->segment_generation == UINT32_MAX || binding->slot_offset >= TT_SLOTS_PER_SEGMENT + || binding->wrap == TT_WRAP_INVALID || XLogRecPtrIsInvalid(binding->active_lsn) + || binding->terminal_state != CLUSTER_TT_LOCAL_TERMINAL_NONE || binding->reserved8[0] != 0 + || binding->reserved8[1] != 0) return false; memset(out, 0, sizeof(*out)); @@ -728,13 +718,11 @@ cluster_tt_local_get_published_binding(TransactionId top_xid, if (binding_out == NULL) return false; memset(binding_out, 0, sizeof(*binding_out)); - if (!cluster_enabled || cluster_node_id < 0 - || !TransactionIdIsNormal(top_xid)) + if (!cluster_enabled || cluster_node_id < 0 || !TransactionIdIsNormal(top_xid)) return false; idx = cluster_tt_local_find_binding(top_xid); return idx >= 0 - && cluster_tt_local_copy_published(&cluster_tt_local_bindings[idx], - binding_out); + && cluster_tt_local_copy_published(&cluster_tt_local_bindings[idx], binding_out); } /* Only called after the publisher's normal, zero-side-effect retry result. @@ -764,15 +752,14 @@ cluster_tt_local_forget_unpublished_reservation(TransactionId top_xid) bool cluster_tt_local_prepare_canonical_active(TransactionId top_xid, - ClusterCanonicalTxnBinding *binding_out) + ClusterCanonicalTxnBinding *binding_out) { uint64 retry_count = 0; if (binding_out == NULL) return false; memset(binding_out, 0, sizeof(*binding_out)); - if (!cluster_enabled || cluster_node_id < 0 - || !TransactionIdIsNormal(top_xid)) + if (!cluster_enabled || cluster_node_id < 0 || !TransactionIdIsNormal(top_xid)) return false; for (;;) { @@ -898,10 +885,8 @@ cluster_tt_local_prepare_canonical_active(TransactionId top_xid, /* Legacy shape retained for non-heap callers, but it is now strictly * read-only and can never reserve or publish while a caller holds page locks. */ bool -cluster_tt_local_get_or_create_binding(TransactionId top_xid, - uint32 *out_segment_id, - uint16 *out_slot_offset, - uint32 *out_tt_slot_id) +cluster_tt_local_get_or_create_binding(TransactionId top_xid, uint32 *out_segment_id, + uint16 *out_slot_offset, uint32 *out_tt_slot_id) { ClusterCanonicalTxnBinding binding; @@ -950,16 +935,15 @@ cluster_tt_local_precommit_durable_finish(TransactionId xid, SCN commit_scn, return false; idx = cluster_tt_local_find_binding(xid); if (idx < 0) - ereport(ERROR, - (errcode(ERRCODE_DATA_CORRUPTED), - errmsg("canonical ACTIVE binding disappeared before commit"))); + ereport(ERROR, (errcode(ERRCODE_DATA_CORRUPTED), + errmsg("canonical ACTIVE binding disappeared before commit"))); segment_id = binding.segment_id; segment_generation = binding.segment_generation; slot_offset = binding.slot_offset; wrap = binding.slot_wrap; - admission = cluster_semantic_activation_modifier_enter( - cluster_tt_local_writable_admission(), &modifier_token); + admission = cluster_semantic_activation_modifier_enter(cluster_tt_local_writable_admission(), + &modifier_token); if (admission != CLUSTER_SEMANTIC_ADMISSION_OK) ereport(ERROR, (errcode(ERRCODE_CLUSTER_RECONFIG_IN_PROGRESS), @@ -976,10 +960,9 @@ cluster_tt_local_precommit_durable_finish(TransactionId xid, SCN commit_scn, * the whole xact, so its wrap cannot have changed. */ cluster_tt_local_modifier_recheck_or_error(&modifier_token); - owner = cluster_tt_slot_durable_commit_writeonly( - segment_id, segment_generation, slot_offset, xid, wrap, commit_scn, - &modifier_token, - &successor); + owner = cluster_tt_slot_durable_commit_writeonly(segment_id, segment_generation, + slot_offset, xid, wrap, commit_scn, + &modifier_token, &successor); /* * Build the fold delta (mirrors xl_undo_tt_slot_commit fields). xid is the @@ -996,8 +979,7 @@ cluster_tt_local_precommit_durable_finish(TransactionId xid, SCN commit_scn, out_fold->flags = 0; out_fold->reserved = 0; out_fold->commit_scn = successor.commit_scn; - cluster_tt_local_bindings[idx].terminal_state - = CLUSTER_TT_LOCAL_TERMINAL_COMMIT_STAGED; + cluster_tt_local_bindings[idx].terminal_state = CLUSTER_TT_LOCAL_TERMINAL_COMMIT_STAGED; } PG_FINALLY(); { @@ -1037,30 +1019,25 @@ cluster_tt_local_preabort_durable_finish(TransactionId xid) errdetail("xid=%u publication=%u terminal=%u", xid, binding->publish_state, binding->terminal_state))); - admission = cluster_semantic_activation_modifier_enter( - cluster_tt_local_writable_admission(), &modifier_token); + admission = cluster_semantic_activation_modifier_enter(cluster_tt_local_writable_admission(), + &modifier_token); if (admission != CLUSTER_SEMANTIC_ADMISSION_OK) - ereport(ERROR, - (errcode(ERRCODE_CLUSTER_RECONFIG_IN_PROGRESS), - errmsg("cannot make canonical transaction abort durable during cluster reconfiguration"))); + ereport(ERROR, (errcode(ERRCODE_CLUSTER_RECONFIG_IN_PROGRESS), + errmsg("cannot make canonical transaction abort durable during cluster " + "reconfiguration"))); PG_TRY(); { cluster_tt_local_modifier_recheck_or_error(&modifier_token); abort_lsn = cluster_tt_slot_durable_abort_exact( - binding->segment_id, binding->segment_generation, - binding->slot_offset, binding->top_xid, binding->wrap, - &modifier_token, &successor); + binding->segment_id, binding->segment_generation, binding->slot_offset, + binding->top_xid, binding->wrap, &modifier_token, &successor); cluster_tt_local_modifier_recheck_or_error(&modifier_token); - if (XLogRecPtrIsInvalid(abort_lsn) - || successor.status != TT_SLOT_ABORTED - || successor.xid != binding->top_xid - || successor.wrap != binding->wrap - || successor.flags != TT_FLAGS_RESERVED - || SCN_VALID(successor.commit_scn) + if (XLogRecPtrIsInvalid(abort_lsn) || successor.status != TT_SLOT_ABORTED + || successor.xid != binding->top_xid || successor.wrap != binding->wrap + || successor.flags != TT_FLAGS_RESERVED || SCN_VALID(successor.commit_scn) || !UBA_is_invalid(successor.first_undo_block)) - ereport(ERROR, - (errcode(ERRCODE_DATA_CORRUPTED), - errmsg("canonical abort publisher returned an invalid successor"))); + ereport(ERROR, (errcode(ERRCODE_DATA_CORRUPTED), + errmsg("canonical abort publisher returned an invalid successor"))); binding->terminal_state = CLUSTER_TT_LOCAL_TERMINAL_ABORT_DURABLE; } PG_FINALLY(); @@ -1077,8 +1054,7 @@ cluster_tt_local_record_commit(TransactionId xid, SCN commit_scn) int idx = cluster_tt_local_find_binding(xid); if (idx >= 0 - && cluster_tt_local_bindings[idx].terminal_state - == CLUSTER_TT_LOCAL_TERMINAL_COMMIT_STAGED) + && cluster_tt_local_bindings[idx].terminal_state == CLUSTER_TT_LOCAL_TERMINAL_COMMIT_STAGED) install_status(xid, CLUSTER_TT_STATUS_COMMITTED, commit_scn); /* * spec-3.12 D2: retain the binding's TT slot as COMMITTED + commit_scn @@ -1118,8 +1094,7 @@ cluster_tt_local_record_abort(TransactionId xid) } if (idx >= 0 - && cluster_tt_local_bindings[idx].terminal_state - == CLUSTER_TT_LOCAL_TERMINAL_ABORT_DURABLE) + && cluster_tt_local_bindings[idx].terminal_state == CLUSTER_TT_LOCAL_TERMINAL_ABORT_DURABLE) install_status(xid, CLUSTER_TT_STATUS_ABORTED, InvalidScn); /* spec-3.12 D2 / C7: aborted slots are immediately recyclable. */ cluster_tt_local_finish_bindings(false /* aborted */, InvalidScn); @@ -1283,7 +1258,7 @@ cluster_tt_local_get_or_create_binding(TransactionId top_xid, uint32 *out_segmen bool cluster_tt_local_prepare_canonical_active(TransactionId top_xid, - ClusterCanonicalTxnBinding *binding_out) + ClusterCanonicalTxnBinding *binding_out) { (void)top_xid; if (binding_out != NULL) diff --git a/src/backend/cluster/cluster_tt_recovery.c b/src/backend/cluster/cluster_tt_recovery.c index b549bf982cf..c4b9b95320c 100644 --- a/src/backend/cluster/cluster_tt_recovery.c +++ b/src/backend/cluster/cluster_tt_recovery.c @@ -307,7 +307,7 @@ typedef struct TTRevertExpect { */ static int PGRAC_PCM_X_FENCE_DOMINATED(cluster_bufmgr_pcm_x_ordinary_content_write_permitted) -revert_one_delete_record(const UndoRecordHeader *hdr, const TTRevertExpect *exp) + revert_one_delete_record(const UndoRecordHeader *hdr, const TTRevertExpect *exp) { Buffer buf; BufferDesc *desc; diff --git a/src/backend/cluster/cluster_tt_slot.c b/src/backend/cluster/cluster_tt_slot.c index b3ce1086cc0..a7e11f68cb7 100644 --- a/src/backend/cluster/cluster_tt_slot.c +++ b/src/backend/cluster/cluster_tt_slot.c @@ -46,10 +46,10 @@ #include "access/transam.h" #include "cluster/cluster_clean_leave.h" -#include "cluster/cluster_guc.h" /* cluster_undo_retention_horizon_enabled */ -#include "cluster/cluster_mode.h" /* cluster_peer_mode_enabled */ -#include "cluster/cluster_scn.h" /* SCN_MAX_VALID_NODE_ID */ -#include "cluster/cluster_shmem.h" /* ClusterShmemRegion */ +#include "cluster/cluster_guc.h" /* cluster_undo_retention_horizon_enabled */ +#include "cluster/cluster_mode.h" /* cluster_peer_mode_enabled */ +#include "cluster/cluster_scn.h" /* SCN_MAX_VALID_NODE_ID */ +#include "cluster/cluster_shmem.h" /* ClusterShmemRegion */ #include "cluster/cluster_terminal_ref_census.h" /* L11/L12 release sample */ #include "cluster/cluster_tt_slot.h" #include "cluster/cluster_undo_retention.h" /* horizon + recyclable predicate */ @@ -490,8 +490,8 @@ tt_slot_entry_recycle_locked(ClusterTTSlotAllocEntry *e, TransactionId new_owner */ static uint16 cluster_tt_slot_alloc_locked(ClusterTTSlotAllocPerSegment *seg, uint32 segment_id, - TransactionId top_xid, bool gate_enabled, bool peer_mode, - SCN horizon, bool *out_retained_pressure, uint16 *out_wrap) + TransactionId top_xid, bool gate_enabled, bool peer_mode, SCN horizon, + bool *out_retained_pressure, uint16 *out_wrap) { int reusable_idx = -1; int free_idx = -1; @@ -516,8 +516,7 @@ cluster_tt_slot_alloc_locked(ClusterTTSlotAllocPerSegment *seg, uint32 segment_i /* A local ProcArray horizon cannot authorize destruction of evidence * still needed by a peer snapshot or current-MX canonical proof. */ bool recyclable - = (peer_mode - && (e->status == CTS_COMMITTED || e->status == CTS_ABORTED)) + = (peer_mode && (e->status == CTS_COMMITTED || e->status == CTS_ABORTED)) ? false : (gate_enabled ? cluster_tt_slot_recyclable(e->status, e->commit_scn, horizon) @@ -530,8 +529,7 @@ cluster_tt_slot_alloc_locked(ClusterTTSlotAllocPerSegment *seg, uint32 segment_i } if (recyclable) { - if (reusable_idx < 0 - && !cluster_tt_slot_is_protected(segment_id, (uint16)i)) + if (reusable_idx < 0 && !cluster_tt_slot_is_protected(segment_id, (uint16)i)) reusable_idx = i; } else { retained_pressure = true; @@ -541,8 +539,7 @@ cluster_tt_slot_alloc_locked(ClusterTTSlotAllocPerSegment *seg, uint32 segment_i } if (retain_skip_seen > 0 && ClusterTTSlotShm != NULL) - pg_atomic_fetch_add_u64(&ClusterTTSlotShm->tt_slot_retain_skip_count, - retain_skip_seen); + pg_atomic_fetch_add_u64(&ClusterTTSlotShm->tt_slot_retain_skip_count, retain_skip_seen); /* Pass 2: prefer FREE over a retention-eligible recyclable slot. */ if (free_idx >= 0) { @@ -641,8 +638,8 @@ cluster_tt_slot_alloc_ext(uint32 segment_id, TransactionId top_xid, bool *out_re seg = cluster_tt_slot_get_or_init(segment_id); LWLockAcquire(&seg->lock, LW_EXCLUSIVE); - result = cluster_tt_slot_alloc_locked(seg, segment_id, top_xid, gate_enabled, - peer_mode, horizon, out_retained_pressure, NULL); + result = cluster_tt_slot_alloc_locked(seg, segment_id, top_xid, gate_enabled, peer_mode, + horizon, out_retained_pressure, NULL); LWLockRelease(&seg->lock); return result; } @@ -657,9 +654,9 @@ cluster_tt_slot_alloc_ext(uint32 segment_id, TransactionId top_xid, bool *out_re * segment unexpectedly. */ uint16 -cluster_tt_slot_alloc_current_exact(int node_id, uint32 expected_segment_id, - TransactionId top_xid, bool *out_retained_pressure, - bool *out_current_drift, uint16 *out_wrap) +cluster_tt_slot_alloc_current_exact(int node_id, uint32 expected_segment_id, TransactionId top_xid, + bool *out_retained_pressure, bool *out_current_drift, + uint16 *out_wrap) { ClusterTTSlotAllocPerSegment *seg; bool gate_enabled; @@ -677,11 +674,12 @@ cluster_tt_slot_alloc_current_exact(int node_id, uint32 expected_segment_id, if (ClusterTTSlotShm == NULL) ereport(ERROR, (errcode(ERRCODE_INTERNAL_ERROR), errmsg("cluster TT slot allocator shmem not initialised"))); - if (node_id < 0 || node_id >= CLUSTER_TT_SLOT_MAX_NODES - || expected_segment_id == 0 || expected_segment_id > UINT16_MAX + if (node_id < 0 || node_id >= CLUSTER_TT_SLOT_MAX_NODES || expected_segment_id == 0 + || expected_segment_id > UINT16_MAX || cluster_tt_slot_segment_to_node(expected_segment_id) != node_id) - ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), - errmsg("cluster_tt_slot_alloc_current_exact: invalid node/segment identity"))); + ereport(ERROR, + (errcode(ERRCODE_INVALID_PARAMETER_VALUE), + errmsg("cluster_tt_slot_alloc_current_exact: invalid node/segment identity"))); if (!TransactionIdIsValid(top_xid)) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("cluster_tt_slot_alloc_current_exact: top_xid must be valid"))); @@ -704,9 +702,8 @@ cluster_tt_slot_alloc_current_exact(int node_id, uint32 expected_segment_id, return INVALID_TT_SLOT_OFFSET; } - result = cluster_tt_slot_alloc_locked(seg, expected_segment_id, top_xid, - gate_enabled, peer_mode, horizon, - out_retained_pressure, out_wrap); + result = cluster_tt_slot_alloc_locked(seg, expected_segment_id, top_xid, gate_enabled, + peer_mode, horizon, out_retained_pressure, out_wrap); LWLockRelease(&seg->lock); return result; } @@ -772,8 +769,7 @@ cluster_tt_slot_gc_current_pass(SCN horizon, uint64 expected_epoch, binding_generation = seg->binding_generation; LWLockRelease(&seg->lock); - if (candidate.status != CTS_COMMITTED - && candidate.status != CTS_ABORTED) + if (candidate.status != CTS_COMMITTED && candidate.status != CTS_ABORTED) continue; if (tt_slot_entry_wrap_retired(&candidate)) { tt_slot_count_wrap_retired(); @@ -786,20 +782,18 @@ cluster_tt_slot_gc_current_pass(SCN horizon, uint64 expected_epoch, * 8.4D floor is inclusive; ABORTED has no invented SCN horizon. */ if (peer_mode) { recyclable = candidate.status == CTS_ABORTED - ? candidate.commit_scn == InvalidScn - : SCN_VALID(candidate.commit_scn) - && SCN_VALID(horizon) - && scn_time_cmp(candidate.commit_scn, horizon) <= 0; - terminal_status = candidate.status == CTS_COMMITTED - ? (uint8)TT_SLOT_COMMITTED : (uint8)TT_SLOT_ABORTED; + ? candidate.commit_scn == InvalidScn + : SCN_VALID(candidate.commit_scn) && SCN_VALID(horizon) + && scn_time_cmp(candidate.commit_scn, horizon) <= 0; + terminal_status = candidate.status == CTS_COMMITTED ? (uint8)TT_SLOT_COMMITTED + : (uint8)TT_SLOT_ABORTED; if (recyclable) recyclable = cluster_ctrc_terminal_release_sample_exact( - segment_id, (uint16)i, candidate.xid, - candidate.wrap, terminal_status, candidate.commit_scn, - expected_epoch); + segment_id, (uint16)i, candidate.xid, candidate.wrap, terminal_status, + candidate.commit_scn, expected_epoch); } else - recyclable = cluster_tt_slot_recyclable(candidate.status, - candidate.commit_scn, horizon); + recyclable + = cluster_tt_slot_recyclable(candidate.status, candidate.commit_scn, horizon); if (!recyclable) continue; @@ -817,8 +811,7 @@ cluster_tt_slot_gc_current_pass(SCN horizon, uint64 expected_epoch, * binding generation. This is the mutation point and therefore the * final folded-epoch fence is repeated while the candidate is owned. */ LWLockAcquire(&seg->lock, LW_EXCLUSIVE); - if (seg->segment_id != segment_id - || seg->binding_generation != binding_generation + if (seg->segment_id != segment_id || seg->binding_generation != binding_generation || memcmp(&seg->slots[i], &candidate, sizeof(candidate)) != 0) { LWLockRelease(&seg->lock); continue; @@ -947,7 +940,7 @@ cluster_tt_slot_mark_committed(uint32 segment_id, uint16 slot_offset, Transactio SCN commit_scn) { ClusterTTSlotAllocPerSegment *seg; - bool transitioned = false; + bool transitioned = false; if (slot_offset >= TT_SLOTS_PER_SEGMENT) ereport(ERROR, @@ -993,7 +986,7 @@ void cluster_tt_slot_mark_aborted(uint32 segment_id, uint16 slot_offset, TransactionId xid) { ClusterTTSlotAllocPerSegment *seg; - bool transitioned = false; + bool transitioned = false; if (slot_offset >= TT_SLOTS_PER_SEGMENT) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), @@ -1054,8 +1047,7 @@ cluster_tt_slot_current_segment(int node_id) * canonical owner and therefore fails closed with a zeroed result. */ bool -cluster_tt_slot_current_owner_by_xid(int node_id, TransactionId xid, - ClusterTTSlotCurrentOwner *out) +cluster_tt_slot_current_owner_by_xid(int node_id, TransactionId xid, ClusterTTSlotCurrentOwner *out) { ClusterTTSlotAllocPerSegment *seg; ClusterTTSlotCurrentOwner found; @@ -1066,8 +1058,7 @@ cluster_tt_slot_current_owner_by_xid(int node_id, TransactionId xid, if (out == NULL) return false; memset(out, 0, sizeof(*out)); - if (ClusterTTSlotShm == NULL || node_id < 0 - || node_id >= CLUSTER_TT_SLOT_MAX_NODES + if (ClusterTTSlotShm == NULL || node_id < 0 || node_id >= CLUSTER_TT_SLOT_MAX_NODES || !TransactionIdIsNormal(xid)) return false; @@ -1088,12 +1079,10 @@ cluster_tt_slot_current_owner_by_xid(int node_id, TransactionId xid, valid = false; break; } - if ((entry->status == CTS_COMMITTED - && !SCN_VALID(entry->commit_scn)) + if ((entry->status == CTS_COMMITTED && !SCN_VALID(entry->commit_scn)) || ((entry->status == CTS_ACTIVE || entry->status == CTS_ABORTED) && entry->commit_scn != InvalidScn) - || (entry->status != CTS_ACTIVE - && entry->status != CTS_COMMITTED + || (entry->status != CTS_ACTIVE && entry->status != CTS_COMMITTED && entry->status != CTS_ABORTED)) { valid = false; break; @@ -1163,10 +1152,9 @@ cluster_tt_slot_rollover(int node_id, uint32 new_segment_id, bool *out_old_had_a LWLockAcquire(&seg->lock, LW_EXCLUSIVE); if (seg->binding_generation == UINT64_MAX) { LWLockRelease(&seg->lock); - ereport(ERROR, - (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), - errmsg("cluster_tt_slot_rollover: binding generation exhausted for node %d", - node_id))); + ereport(ERROR, (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), + errmsg("cluster_tt_slot_rollover: binding generation exhausted for node %d", + node_id))); } for (i = 0; i < TT_SLOTS_PER_SEGMENT; i++) { if (seg->slots[i].status == CTS_ACTIVE) { diff --git a/src/backend/cluster/cluster_tt_status.c b/src/backend/cluster/cluster_tt_status.c index 9453cc8feb0..c6b3deb3afc 100644 --- a/src/backend/cluster/cluster_tt_status.c +++ b/src/backend/cluster/cluster_tt_status.c @@ -671,21 +671,18 @@ static bool cluster_tt_status_current_entries_agree(const ClusterTTOverlayEntry *a, const ClusterTTOverlayEntry *b) { - return a->status == b->status - && a->commit_scn == b->commit_scn && a->status_epoch == b->status_epoch - && a->has_parent_key == b->has_parent_key + return a->status == b->status && a->commit_scn == b->commit_scn + && a->status_epoch == b->status_epoch && a->has_parent_key == b->has_parent_key && memcmp(&a->parent_key, &b->parent_key, sizeof(a->parent_key)) == 0; } static bool -cluster_tt_status_current_entry_matches(const ClusterTTOverlayEntry *entry, - TransactionId xid, uint32 epoch, - TimestampTz now) +cluster_tt_status_current_entry_matches(const ClusterTTOverlayEntry *entry, TransactionId xid, + uint32 epoch, TimestampTz now) { - return entry->key.origin_node_id == (uint16)cluster_node_id - && entry->key.local_xid == xid && entry->key.cluster_epoch == epoch - && entry->key.undo_segment_id != 0 && entry->key.tt_slot_id != 0 - && entry->key._reserved == 0 && entry->key._reserved2 == 0 + return entry->key.origin_node_id == (uint16)cluster_node_id && entry->key.local_xid == xid + && entry->key.cluster_epoch == epoch && entry->key.undo_segment_id != 0 + && entry->key.tt_slot_id != 0 && entry->key._reserved == 0 && entry->key._reserved2 == 0 && entry->status_epoch == epoch && is_entry_fresh(entry, now); } @@ -695,10 +692,10 @@ cluster_tt_status_current_entry_matches(const ClusterTTOverlayEntry *entry, * cluster_tt_local. This helper classifies their status agreement; it never * chooses which physical key is canonical. */ static bool -cluster_tt_status_current_group_locked( - TransactionId xid, uint32 epoch, TimestampTz now, - const ClusterTTStatusKey *candidate, ClusterTTOverlayEntry *sample, - uint32 *match_count, bool *candidate_found) +cluster_tt_status_current_group_locked(TransactionId xid, uint32 epoch, TimestampTz now, + const ClusterTTStatusKey *candidate, + ClusterTTOverlayEntry *sample, uint32 *match_count, + bool *candidate_found) { HASH_SEQ_STATUS seq; ClusterTTOverlayEntry *entry; @@ -710,8 +707,7 @@ cluster_tt_status_current_group_locked( while ((entry = (ClusterTTOverlayEntry *)hash_seq_search(&seq)) != NULL) { if (!cluster_tt_status_current_entry_matches(entry, xid, epoch, now)) continue; - if (candidate != NULL - && memcmp(&entry->key, candidate, sizeof(*candidate)) == 0) + if (candidate != NULL && memcmp(&entry->key, candidate, sizeof(*candidate)) == 0) *candidate_found = true; if (*match_count == 0) *sample = *entry; @@ -725,24 +721,20 @@ cluster_tt_status_current_group_locked( } static bool -cluster_tt_status_overlay_matches_current_owner( - const ClusterTTOverlayEntry *entry, - const ClusterTTSlotCurrentOwner *owner) +cluster_tt_status_overlay_matches_current_owner(const ClusterTTOverlayEntry *entry, + const ClusterTTSlotCurrentOwner *owner) { switch (owner->status) { case CTS_ACTIVE: return (entry->status == CLUSTER_TT_STATUS_IN_PROGRESS || entry->status == CLUSTER_TT_STATUS_SUBCOMMITTED) - && entry->commit_scn == InvalidScn - && owner->commit_scn == InvalidScn; + && entry->commit_scn == InvalidScn && owner->commit_scn == InvalidScn; case CTS_COMMITTED: return (entry->status == CLUSTER_TT_STATUS_COMMITTED || entry->status == CLUSTER_TT_STATUS_CLEANED_OUT) - && SCN_VALID(entry->commit_scn) - && entry->commit_scn == owner->commit_scn; + && SCN_VALID(entry->commit_scn) && entry->commit_scn == owner->commit_scn; case CTS_ABORTED: - return entry->status == CLUSTER_TT_STATUS_ABORTED - && entry->commit_scn == InvalidScn + return entry->status == CLUSTER_TT_STATUS_ABORTED && entry->commit_scn == InvalidScn && owner->commit_scn == InvalidScn; default: return false; @@ -750,9 +742,11 @@ cluster_tt_status_overlay_matches_current_owner( } static bool -cluster_tt_status_lookup_current_own_xid_internal( - TransactionId xid, const ClusterTTStatusKey *candidate, ClusterTTStatusKey *key, - ClusterTTStatusResult *result, ClusterTTCurrentKeyVerdict *candidate_verdict) +cluster_tt_status_lookup_current_own_xid_internal(TransactionId xid, + const ClusterTTStatusKey *candidate, + ClusterTTStatusKey *key, + ClusterTTStatusResult *result, + ClusterTTCurrentKeyVerdict *candidate_verdict) { ClusterTTOverlayEntry *entry; ClusterTTOverlayEntry selected; @@ -781,22 +775,20 @@ cluster_tt_status_lookup_current_own_xid_internal( if (epoch > UINT32_MAX) return false; if (candidate != NULL - && (candidate->origin_node_id != (uint16)cluster_node_id - || candidate->local_xid != xid || candidate->cluster_epoch != (uint32)epoch - || candidate->undo_segment_id == 0 || candidate->tt_slot_id == 0 - || candidate->_reserved != 0 || candidate->_reserved2 != 0)) + && (candidate->origin_node_id != (uint16)cluster_node_id || candidate->local_xid != xid + || candidate->cluster_epoch != (uint32)epoch || candidate->undo_segment_id == 0 + || candidate->tt_slot_id == 0 || candidate->_reserved != 0 + || candidate->_reserved2 != 0)) return false; now = GetCurrentTimestamp(); LWLockAcquire(ClusterTTStatusLock, LW_SHARED); group_agrees = cluster_tt_status_current_group_locked( - xid, (uint32)epoch, now, candidate, &selected, &match_count, - &candidate_found); + xid, (uint32)epoch, now, candidate, &selected, &match_count, &candidate_found); LWLockRelease(ClusterTTStatusLock); if (!group_agrees) { if (match_count != 0) - pg_atomic_fetch_add_u64( - &ClusterTTStatusState->ambiguous_raw_xid_reject_count, 1); + pg_atomic_fetch_add_u64(&ClusterTTStatusState->ambiguous_raw_xid_reject_count, 1); return false; } @@ -813,56 +805,45 @@ cluster_tt_status_lookup_current_own_xid_internal( * canonical binding for the active happy path. Snapshot it outside the * overlay lock, recheck the complete overlay group, then snapshot it * again after releasing that lock to close the rollover/reuse window. */ - if (!cluster_tt_slot_current_owner_by_xid( - cluster_node_id, xid, &owner) + if (!cluster_tt_slot_current_owner_by_xid(cluster_node_id, xid, &owner) || owner.segment_id == 0 || owner.xid != xid - || owner.slot_offset >= TT_SLOTS_PER_SEGMENT - || owner.reserved8[0] != 0 || owner.reserved8[1] != 0 - || owner.reserved8[2] != 0) { + || owner.slot_offset >= TT_SLOTS_PER_SEGMENT || owner.reserved8[0] != 0 + || owner.reserved8[1] != 0 || owner.reserved8[2] != 0) { pg_atomic_fetch_add_u64(&ClusterTTStatusState->ambiguous_raw_xid_reject_count, 1); return false; } memset(&canonical_key, 0, sizeof(canonical_key)); canonical_key.origin_node_id = (uint16)cluster_node_id; canonical_key.undo_segment_id = owner.segment_id; - canonical_key.tt_slot_id = - cluster_tt_slot_offset_to_id(owner.slot_offset); + canonical_key.tt_slot_id = cluster_tt_slot_offset_to_id(owner.slot_offset); canonical_key.cluster_epoch = (uint32)epoch; canonical_key.local_xid = xid; now = GetCurrentTimestamp(); LWLockAcquire(ClusterTTStatusLock, LW_SHARED); - entry = (ClusterTTOverlayEntry *)hash_search( - ClusterTTStatusHTAB, &canonical_key, HASH_FIND, NULL); + entry = (ClusterTTOverlayEntry *)hash_search(ClusterTTStatusHTAB, &canonical_key, HASH_FIND, + NULL); if (entry == NULL - || !cluster_tt_status_current_entry_matches( - entry, xid, (uint32)epoch, now)) { + || !cluster_tt_status_current_entry_matches(entry, xid, (uint32)epoch, now)) { LWLockRelease(ClusterTTStatusLock); - pg_atomic_fetch_add_u64( - &ClusterTTStatusState->ambiguous_raw_xid_reject_count, 1); + pg_atomic_fetch_add_u64(&ClusterTTStatusState->ambiguous_raw_xid_reject_count, 1); return false; } canonical_entry = *entry; - if (!cluster_tt_status_current_group_locked( - xid, (uint32)epoch, now, candidate, &selected, &check_count, - &check_candidate_found) + if (!cluster_tt_status_current_group_locked(xid, (uint32)epoch, now, candidate, &selected, + &check_count, &check_candidate_found) || check_count < 2 - || !cluster_tt_status_current_entries_agree( - &canonical_entry, &selected) - || !cluster_tt_status_overlay_matches_current_owner( - &canonical_entry, &owner)) { + || !cluster_tt_status_current_entries_agree(&canonical_entry, &selected) + || !cluster_tt_status_overlay_matches_current_owner(&canonical_entry, &owner)) { LWLockRelease(ClusterTTStatusLock); - pg_atomic_fetch_add_u64( - &ClusterTTStatusState->ambiguous_raw_xid_reject_count, 1); + pg_atomic_fetch_add_u64(&ClusterTTStatusState->ambiguous_raw_xid_reject_count, 1); return false; } LWLockRelease(ClusterTTStatusLock); - if (!cluster_tt_slot_current_owner_by_xid( - cluster_node_id, xid, &owner_check) + if (!cluster_tt_slot_current_owner_by_xid(cluster_node_id, xid, &owner_check) || memcmp(&owner, &owner_check, sizeof(owner)) != 0) { - pg_atomic_fetch_add_u64( - &ClusterTTStatusState->ambiguous_raw_xid_reject_count, 1); + pg_atomic_fetch_add_u64(&ClusterTTStatusState->ambiguous_raw_xid_reject_count, 1); return false; } selected = canonical_entry; @@ -1309,9 +1290,11 @@ cluster_tt_status_lookup_exact(const ClusterTTStatusKey *key, ClusterTTStatusRes } static bool -cluster_tt_status_lookup_current_own_xid_internal( - TransactionId xid, const ClusterTTStatusKey *candidate, ClusterTTStatusKey *key, - ClusterTTStatusResult *result, ClusterTTCurrentKeyVerdict *candidate_verdict) +cluster_tt_status_lookup_current_own_xid_internal(TransactionId xid, + const ClusterTTStatusKey *candidate, + ClusterTTStatusKey *key, + ClusterTTStatusResult *result, + ClusterTTCurrentKeyVerdict *candidate_verdict) { (void)xid; (void)candidate; @@ -1508,20 +1491,17 @@ cluster_tt_status_source_dispatch(ClusterTTStatusSourceOp op, if (request == NULL) admission = CLUSTER_SEMANTIC_ADMISSION_CLOSED; else - local_result.bool_value - = cluster_tt_status_lookup_current_own_xid_internal( - request->xid, NULL, &local_result.current_key, - &local_result.lookup, NULL); + local_result.bool_value = cluster_tt_status_lookup_current_own_xid_internal( + request->xid, NULL, &local_result.current_key, &local_result.lookup, NULL); break; case CLUSTER_TT_SOURCE_LOOKUP_CURRENT_OWN_XID_CANDIDATE: local_result.current_key_verdict = CLUSTER_TT_CURRENT_KEY_UNKNOWN; if (request == NULL || request->key == NULL) admission = CLUSTER_SEMANTIC_ADMISSION_CLOSED; else - local_result.bool_value - = cluster_tt_status_lookup_current_own_xid_internal( - request->xid, request->key, &local_result.current_key, - &local_result.lookup, &local_result.current_key_verdict); + local_result.bool_value = cluster_tt_status_lookup_current_own_xid_internal( + request->xid, request->key, &local_result.current_key, &local_result.lookup, + &local_result.current_key_verdict); break; default: admission = CLUSTER_SEMANTIC_ADMISSION_CLOSED; diff --git a/src/backend/cluster/cluster_tt_status_hint.c b/src/backend/cluster/cluster_tt_status_hint.c index 84f4c0f1655..1745b29565e 100644 --- a/src/backend/cluster/cluster_tt_status_hint.c +++ b/src/backend/cluster/cluster_tt_status_hint.c @@ -746,7 +746,7 @@ cluster_tt_status_hint_handle_envelope_raw(const ClusterICEnvelope *env, const v multi_request.member_count = v4_member_count; multi_request.members = v4_members; if (cluster_multixact_source_dispatch(CLUSTER_MULTI_SOURCE_OVERLAY_INSTALL, &multi_request, - &multi_result) + &multi_result) != CLUSTER_SEMANTIC_ADMISSION_OK) return; @@ -878,18 +878,17 @@ cluster_tt_status_hint_handle_envelope_raw(const ClusterICEnvelope *env, const v if (is_v3_subcommitted) { tt_request.parent_key = &parent_key_local; tt_admission = cluster_tt_status_source_dispatch(CLUSTER_TT_SOURCE_INSTALL_SUBCOMMITTED, - &tt_request, &tt_result); + &tt_request, &tt_result); } else { tt_request.status = (ClusterTTStatus)status_raw; tt_request.commit_scn = commit_scn; - tt_admission = cluster_tt_status_source_dispatch(CLUSTER_TT_SOURCE_INSTALL_LOCAL, &tt_request, - &tt_result); + tt_admission = cluster_tt_status_source_dispatch(CLUSTER_TT_SOURCE_INSTALL_LOCAL, + &tt_request, &tt_result); } if (tt_admission != CLUSTER_SEMANTIC_ADMISSION_OK || !tt_result.bool_value) return; if (!is_v3_subcommitted) { - /* * spec-5.2 D6: a remote holder just became terminal on this node's * TT cache — wake any backend blocked in cluster_tx_enqueue_wait on diff --git a/src/backend/cluster/cluster_tx_enqueue.c b/src/backend/cluster/cluster_tx_enqueue.c index a0d51159c37..3cab38a8bd4 100644 --- a/src/backend/cluster/cluster_tx_enqueue.c +++ b/src/backend/cluster/cluster_tx_enqueue.c @@ -80,12 +80,10 @@ typedef struct ClusterTxwWaitSlot { StaticAssertDecl(sizeof(ClusterTxwIdentity) == 24, "R4 D9 waiter identity must remain exactly 24 bytes"); -StaticAssertDecl(__alignof__(ClusterTxwIdentity) == 4, - "R4 D9 waiter identity must remain align-4"); +StaticAssertDecl(__alignof__(ClusterTxwIdentity) == 4, "R4 D9 waiter identity must remain align-4"); StaticAssertDecl(sizeof(ClusterTxwWaitSlot) == 28, "R4 D9 waiter slot must remain exactly 28 bytes"); -StaticAssertDecl(__alignof__(ClusterTxwWaitSlot) == 4, - "R4 D9 waiter slot must remain align-4"); +StaticAssertDecl(__alignof__(ClusterTxwWaitSlot) == 4, "R4 D9 waiter slot must remain align-4"); #define CLUSTER_TXW_SLOT_FREE 0 #define CLUSTER_TXW_SLOT_SOURCE 1 @@ -205,12 +203,11 @@ cluster_tx_enqueue_shmem_register(void) * ============================================================ */ static bool -txw_slot_set(int procno, const ClusterTTStatusKey *holder_key, - bool current_mx_wait) +txw_slot_set(int procno, const ClusterTTStatusKey *holder_key, bool current_mx_wait) { bool registered = false; - uint32 slot_kind = current_mx_wait ? CLUSTER_TXW_SLOT_SOURCE_CURRENT_MX - : CLUSTER_TXW_SLOT_SOURCE; + uint32 slot_kind + = current_mx_wait ? CLUSTER_TXW_SLOT_SOURCE_CURRENT_MX : CLUSTER_TXW_SLOT_SOURCE; LWLockAcquire(&ClusterTxw->lock, LW_EXCLUSIVE); if (ClusterTxw->slots[procno].waiting == CLUSTER_TXW_SLOT_FREE) { @@ -257,14 +254,12 @@ txw_slot_clear(int procno, uint32 expected_kind) } if (current_kind != expected_kind) { LWLockRelease(&ClusterTxw->lock); - ereport(PANIC, - (errmsg("cluster TX waiter slot ownership changed during cleanup"))); + ereport(PANIC, (errmsg("cluster TX waiter slot ownership changed during cleanup"))); } active = pg_atomic_read_u32(&ClusterTxw->active_waiters); if (active == 0) { LWLockRelease(&ClusterTxw->lock); - ereport(PANIC, - (errmsg("cluster TX active waiter counter underflow during cleanup"))); + ereport(PANIC, (errmsg("cluster TX active waiter counter underflow during cleanup"))); } ClusterTxw->slots[procno].waiting = CLUSTER_TXW_SLOT_FREE; pg_atomic_fetch_sub_u32(&ClusterTxw->active_waiters, 1); @@ -315,8 +310,7 @@ txw_exact_wfg_cancel(const ClusterLmdVertex *waiter) remove_result = cluster_lmd_graph_remove_edge_by_waiter_exact_result(waiter); if (remove_result != CLUSTER_LMD_GRAPH_REMOVE_REMOVED && remove_result != CLUSTER_LMD_GRAPH_REMOVE_ABSENT) - ereport(PANIC, - (errmsg("cluster TX exact waiter identity became stale during cleanup"))); + ereport(PANIC, (errmsg("cluster TX exact waiter identity became stale during cleanup"))); } static void @@ -333,10 +327,8 @@ txw_exact_waiter_vertex(ClusterLmdVertex *waiter, int procno, uint64 formation_e } static void -txw_exact_cleanup(int procno, uint32 slot_kind, bool slot_registered, - bool wait_state_published, - bool wfg_registered, uint64 formation_epoch, TransactionId xid, - uint64 wait_seq) +txw_exact_cleanup(int procno, uint32 slot_kind, bool slot_registered, bool wait_state_published, + bool wfg_registered, uint64 formation_epoch, TransactionId xid, uint64 wait_seq) { if (wfg_registered) { ClusterLmdVertex waiter; @@ -364,7 +356,7 @@ txw_exact_cleanup(int procno, uint32 slot_kind, bool slot_registered, */ void cluster_tx_enqueue_cleanup_on_backend_exit_callback(int code pg_attribute_unused(), - Datum arg pg_attribute_unused()) + Datum arg pg_attribute_unused()) { ClusterLmdWaitStateSnapshot wait_state; ClusterLmdWaitStateReadResult read_result; @@ -380,11 +372,10 @@ cluster_tx_enqueue_cleanup_on_backend_exit_callback(int code pg_attribute_unused slot_kind = txw_slot_kind(procno); if (slot_kind == CLUSTER_TXW_SLOT_FREE) return; - if (slot_kind != CLUSTER_TXW_SLOT_SOURCE - && slot_kind != CLUSTER_TXW_SLOT_SOURCE_CURRENT_MX + if (slot_kind != CLUSTER_TXW_SLOT_SOURCE && slot_kind != CLUSTER_TXW_SLOT_SOURCE_CURRENT_MX && slot_kind != CLUSTER_TXW_SLOT_TARGET) - ereport(PANIC, - (errmsg("cluster TX waiter slot has invalid ownership discriminator during backend-exit cleanup"))); + ereport(PANIC, (errmsg("cluster TX waiter slot has invalid ownership discriminator during " + "backend-exit cleanup"))); memset(&wait_state, 0, sizeof(wait_state)); read_result = cluster_lmd_wait_state_read_exact(&MyProc->cluster_lmd_wait, &wait_state); @@ -396,18 +387,19 @@ cluster_tx_enqueue_cleanup_on_backend_exit_callback(int code pg_attribute_unused || wait_state.request_id != 0 || wait_state.wait_seq == 0) ereport(PANIC, (errmsg("cluster TX waiter state is malformed during backend-exit cleanup"))); - } - else if (read_result != CLUSTER_LMD_WAIT_STATE_READ_INACTIVE) - ereport(PANIC, - (errmsg("cluster TX waiter state has unknown read result during backend-exit cleanup"))); + } else if (read_result != CLUSTER_LMD_WAIT_STATE_READ_INACTIVE) + ereport( + PANIC, + (errmsg( + "cluster TX waiter state has unknown read result during backend-exit cleanup"))); txw_exit_slot_prevalidate(procno, slot_kind); /* ACTIVE cleanup order is exact WFG edge, proc wait state, owned slot. */ if (read_result == CLUSTER_LMD_WAIT_STATE_READ_ACTIVE) { ClusterLmdVertex waiter; - txw_exact_waiter_vertex(&waiter, procno, wait_state.cluster_epoch, - wait_state.xid, wait_state.wait_seq); + txw_exact_waiter_vertex(&waiter, procno, wait_state.cluster_epoch, wait_state.xid, + wait_state.wait_seq); txw_exact_wfg_cancel(&waiter); cluster_lmd_wait_state_clear(&MyProc->cluster_lmd_wait); } @@ -415,18 +407,16 @@ cluster_tx_enqueue_cleanup_on_backend_exit_callback(int code pg_attribute_unused } static ClusterTxwResult -cluster_tx_enqueue_wait_internal(const ClusterTTStatusKey *holder_key, - int effective_timeout_ms, - bool current_mx_wait, - uint64 current_mx_deadline_mono_us) +cluster_tx_enqueue_wait_internal(const ClusterTTStatusKey *holder_key, int effective_timeout_ms, + bool current_mx_wait, uint64 current_mx_deadline_mono_us) { int procno; TimestampTz source_deadline = 0; ClusterTxwResult result = CLUSTER_TXW_TIMEOUT; ClusterLmdVertex tx_wfg_waiter; bool tx_wfg_registered = false; - uint32 slot_kind = current_mx_wait ? CLUSTER_TXW_SLOT_SOURCE_CURRENT_MX - : CLUSTER_TXW_SLOT_SOURCE; + uint32 slot_kind + = current_mx_wait ? CLUSTER_TXW_SLOT_SOURCE_CURRENT_MX : CLUSTER_TXW_SLOT_SOURCE; Assert(holder_key != NULL); @@ -451,8 +441,7 @@ cluster_tx_enqueue_wait_internal(const ClusterTTStatusKey *holder_key, if (current_mx_deadline_mono_us == 0) return CLUSTER_TXW_UNPROVABLE; } else - source_deadline = GetCurrentTimestamp() - + (TimestampTz)effective_timeout_ms * 1000; + source_deadline = GetCurrentTimestamp() + (TimestampTz)effective_timeout_ms * 1000; if (!txw_slot_set(procno, holder_key, current_mx_wait)) return CLUSTER_TXW_UNPROVABLE; @@ -513,94 +502,92 @@ cluster_tx_enqueue_wait_internal(const ClusterTTStatusKey *holder_key, PG_TRY(); { for (;;) { - long wait_ms; + long wait_ms; - ResetLatch(MyLatch); + ResetLatch(MyLatch); - /* + /* * Consume only a token that still matches the live TX wait * published above. Do not ereport or return from inside * PG_TRY: the shared cleanup envelope below must clear the * waiter slot, wait-state, and WFG edge first. */ - if (cluster_cancel_token_consume()) { - result = CLUSTER_TXW_DEADLOCK; - break; - } + if (cluster_cancel_token_consume()) { + result = CLUSTER_TXW_DEADLOCK; + break; + } - /* + /* * Active R4 current-MX has no SOURCE authority to consult. Keep * the exact TX/WFG registration for one bounded native wake/poll * slice, clean it below, and require the heap caller to restart * from tuple capture + DESCRIBE. The operation-owned absolute * deadline survives that restart and prevents budget refresh. */ - if (current_mx_wait) { - uint64 now_us = txw_monotonic_us(); - uint64 remaining_us; - - if (now_us >= current_mx_deadline_mono_us) { - result = CLUSTER_TXW_TIMEOUT; - pg_atomic_fetch_add_u64(&ClusterTxw->timeout_count, 1); - break; - } - remaining_us = current_mx_deadline_mono_us - now_us; - if (remaining_us >= (uint64)CLUSTER_TXW_TICK_MS * UINT64_C(1000)) - wait_ms = CLUSTER_TXW_TICK_MS; - else { - wait_ms = (long)(remaining_us / UINT64_C(1000)); - if (remaining_us % UINT64_C(1000) != 0) - wait_ms++; - if (wait_ms <= 0) - wait_ms = 1; - } - (void)WaitLatch(MyLatch, - WL_LATCH_SET | WL_TIMEOUT | WL_EXIT_ON_PM_DEATH, - wait_ms, WAIT_EVENT_GES_TX_ENQUEUE_WAIT); - CHECK_FOR_INTERRUPTS(); - result = CLUSTER_TXW_RETRY; + if (current_mx_wait) { + uint64 now_us = txw_monotonic_us(); + uint64 remaining_us; + + if (now_us >= current_mx_deadline_mono_us) { + result = CLUSTER_TXW_TIMEOUT; + pg_atomic_fetch_add_u64(&ClusterTxw->timeout_count, 1); break; } + remaining_us = current_mx_deadline_mono_us - now_us; + if (remaining_us >= (uint64)CLUSTER_TXW_TICK_MS * UINT64_C(1000)) + wait_ms = CLUSTER_TXW_TICK_MS; + else { + wait_ms = (long)(remaining_us / UINT64_C(1000)); + if (remaining_us % UINT64_C(1000) != 0) + wait_ms++; + if (wait_ms <= 0) + wait_ms = 1; + } + (void)WaitLatch(MyLatch, WL_LATCH_SET | WL_TIMEOUT | WL_EXIT_ON_PM_DEATH, wait_ms, + WAIT_EVENT_GES_TX_ENQUEUE_WAIT); + CHECK_FOR_INTERRUPTS(); + result = CLUSTER_TXW_RETRY; + break; + } - /* Re-check the holder's TT status (closes the register/wake race: + /* Re-check the holder's TT status (closes the register/wake race: * a terminal status published before we slept is seen here). */ - { - ClusterTTStatusResult cres; - ClusterTTStatusSourceRequest source_request; - ClusterTTStatusSourceResult source_result; - bool found; - TimestampTz now; - - memset(&source_request, 0, sizeof(source_request)); - source_request.key = holder_key; - found = cluster_tt_status_source_dispatch( - CLUSTER_TT_SOURCE_LOOKUP, &source_request, &source_result) - == CLUSTER_SEMANTIC_ADMISSION_OK + { + ClusterTTStatusResult cres; + ClusterTTStatusSourceRequest source_request; + ClusterTTStatusSourceResult source_result; + bool found; + TimestampTz now; + + memset(&source_request, 0, sizeof(source_request)); + source_request.key = holder_key; + found = cluster_tt_status_source_dispatch(CLUSTER_TT_SOURCE_LOOKUP, &source_request, + &source_result) + == CLUSTER_SEMANTIC_ADMISSION_OK && source_result.bool_value; - cres = source_result.lookup; - if (found && cres.authoritative - && txw_status_is_terminal(cres.status)) { - result = CLUSTER_TXW_RESOLVED; - break; - } - - now = GetCurrentTimestamp(); - if (now >= source_deadline) { - result = CLUSTER_TXW_TIMEOUT; - pg_atomic_fetch_add_u64(&ClusterTxw->timeout_count, 1); - break; - } - - wait_ms = (long)((source_deadline - now) / 1000); + cres = source_result.lookup; + if (found && cres.authoritative && txw_status_is_terminal(cres.status)) { + result = CLUSTER_TXW_RESOLVED; + break; } - if (wait_ms <= 0) - wait_ms = 1; - if (wait_ms > CLUSTER_TXW_TICK_MS) - wait_ms = CLUSTER_TXW_TICK_MS; - (void)WaitLatch(MyLatch, WL_LATCH_SET | WL_TIMEOUT | WL_EXIT_ON_PM_DEATH, wait_ms, - WAIT_EVENT_GES_TX_ENQUEUE_WAIT); - CHECK_FOR_INTERRUPTS(); + now = GetCurrentTimestamp(); + if (now >= source_deadline) { + result = CLUSTER_TXW_TIMEOUT; + pg_atomic_fetch_add_u64(&ClusterTxw->timeout_count, 1); + break; + } + + wait_ms = (long)((source_deadline - now) / 1000); + } + if (wait_ms <= 0) + wait_ms = 1; + if (wait_ms > CLUSTER_TXW_TICK_MS) + wait_ms = CLUSTER_TXW_TICK_MS; + + (void)WaitLatch(MyLatch, WL_LATCH_SET | WL_TIMEOUT | WL_EXIT_ON_PM_DEATH, wait_ms, + WAIT_EVENT_GES_TX_ENQUEUE_WAIT); + CHECK_FOR_INTERRUPTS(); } } PG_CATCH(); @@ -622,7 +609,7 @@ cluster_tx_enqueue_wait_internal(const ClusterTTStatusKey *holder_key, ClusterTxwResult cluster_tx_enqueue_wait_exact(const ClusterTxLocator *locator, int effective_timeout_ms, - ClusterTxResolveReason *reason_out) + ClusterTxResolveReason *reason_out) { ClusterTxResolution resolution; ClusterTxResolveReason initial_reason = CLUSTER_TX_RESOLVE_TARGET_DISABLED; @@ -648,11 +635,10 @@ cluster_tx_enqueue_wait_exact(const ClusterTxLocator *locator, int effective_tim * run before this layer inspects a possibly malformed locator or shmem. */ memset(&resolution, 0, sizeof(resolution)); initial_outcome = cluster_tx_resolve_exact(locator, CLUSTER_TX_RESOLVE_ROW_WAIT, &resolution, - &initial_reason); + &initial_reason); if (initial_outcome == CLUSTER_TX_UNKNOWN) { - final_reason = initial_reason == CLUSTER_TX_RESOLVE_NONE - ? CLUSTER_TX_RESOLVE_PROTOCOL - : initial_reason; + final_reason = initial_reason == CLUSTER_TX_RESOLVE_NONE ? CLUSTER_TX_RESOLVE_PROTOCOL + : initial_reason; goto done; } /* The exact resolver publishes a non-UNKNOWN outcome only with NONE. */ @@ -714,8 +700,8 @@ cluster_tx_enqueue_wait_exact(const ClusterTxLocator *locator, int effective_tim final_reason = CLUSTER_TX_RESOLVE_RF_DEFERRED; break; } - wait_seq = cluster_lmd_wait_state_publish(&MyProc->cluster_lmd_wait, - CLUSTER_LMD_WAIT_TX, 0, formation_epoch, my_xid); + wait_seq = cluster_lmd_wait_state_publish( + &MyProc->cluster_lmd_wait, CLUSTER_LMD_WAIT_TX, 0, formation_epoch, my_xid); wait_state_published = true; if (cluster_epoch_get_current() != formation_epoch) { final_reason = CLUSTER_TX_RESOLVE_RF_DEFERRED; @@ -768,8 +754,8 @@ cluster_tx_enqueue_wait_exact(const ClusterTxLocator *locator, int effective_tim } if (current_outcome == CLUSTER_TX_UNKNOWN) { final_reason = current_reason == CLUSTER_TX_RESOLVE_NONE - ? CLUSTER_TX_RESOLVE_PROTOCOL - : current_reason; + ? CLUSTER_TX_RESOLVE_PROTOCOL + : current_reason; break; } if ((current_outcome != CLUSTER_TX_IN_PROGRESS @@ -795,8 +781,8 @@ cluster_tx_enqueue_wait_exact(const ClusterTxLocator *locator, int effective_tim wait_ms = 1; if (wait_ms > CLUSTER_TXW_TICK_MS) wait_ms = CLUSTER_TXW_TICK_MS; - (void)WaitLatch(MyLatch, WL_LATCH_SET | WL_TIMEOUT | WL_EXIT_ON_PM_DEATH, - wait_ms, WAIT_EVENT_GES_TX_ENQUEUE_WAIT); + (void)WaitLatch(MyLatch, WL_LATCH_SET | WL_TIMEOUT | WL_EXIT_ON_PM_DEATH, wait_ms, + WAIT_EVENT_GES_TX_ENQUEUE_WAIT); CHECK_FOR_INTERRUPTS(); } } while (false); @@ -804,8 +790,8 @@ cluster_tx_enqueue_wait_exact(const ClusterTxLocator *locator, int effective_tim PG_FINALLY(); { txw_exact_cleanup(procno, CLUSTER_TXW_SLOT_TARGET, (bool)slot_registered, - (bool)wait_state_published, - (bool)wfg_registered, formation_epoch, my_xid, (uint64)wait_seq); + (bool)wait_state_published, (bool)wfg_registered, formation_epoch, my_xid, + (uint64)wait_seq); } PG_END_TRY(); @@ -816,16 +802,13 @@ cluster_tx_enqueue_wait_exact(const ClusterTxLocator *locator, int effective_tim } ClusterTxwResult -cluster_tx_enqueue_wait(const ClusterTTStatusKey *holder_key, - int effective_timeout_ms) +cluster_tx_enqueue_wait(const ClusterTTStatusKey *holder_key, int effective_timeout_ms) { - return cluster_tx_enqueue_wait_internal(holder_key, effective_timeout_ms, - false, 0); + return cluster_tx_enqueue_wait_internal(holder_key, effective_timeout_ms, false, 0); } ClusterTxwResult -cluster_tx_enqueue_wait_current_mx(const ClusterTTStatusKey *holder_key, - int effective_timeout_ms, +cluster_tx_enqueue_wait_current_mx(const ClusterTTStatusKey *holder_key, int effective_timeout_ms, uint64 *absolute_deadline_mono_us) { uint64 now_us; @@ -838,12 +821,12 @@ cluster_tx_enqueue_wait_current_mx(const ClusterTTStatusKey *holder_key, if (*absolute_deadline_mono_us == 0) { now_us = txw_monotonic_us(); timeout_us = (uint64)effective_timeout_ms > UINT64_MAX / UINT64_C(1000) - ? UINT64_MAX - : (uint64)effective_timeout_ms * UINT64_C(1000); + ? UINT64_MAX + : (uint64)effective_timeout_ms * UINT64_C(1000); *absolute_deadline_mono_us = txw_saturating_add_us(now_us, timeout_us); } - return cluster_tx_enqueue_wait_internal(holder_key, effective_timeout_ms, - true, *absolute_deadline_mono_us); + return cluster_tx_enqueue_wait_internal(holder_key, effective_timeout_ms, true, + *absolute_deadline_mono_us); } void diff --git a/src/backend/cluster/cluster_tx_resolve.c b/src/backend/cluster/cluster_tx_resolve.c index b99e599884a..95308292054 100644 --- a/src/backend/cluster/cluster_tx_resolve.c +++ b/src/backend/cluster/cluster_tx_resolve.c @@ -26,8 +26,7 @@ #include "cluster/cluster_tx_resolve.h" static bool -cluster_tx_locator_is_well_formed(const ClusterTxLocator *locator, - bool allow_partial_wrap, +cluster_tx_locator_is_well_formed(const ClusterTxLocator *locator, bool allow_partial_wrap, ClusterTxResolveReason *reason_out) { uint32 segment_id; @@ -41,8 +40,7 @@ cluster_tx_locator_is_well_formed(const ClusterTxLocator *locator, if (locator == NULL) return false; - data_kind = locator->itl_kind == ITL_FLAG_ACTIVE - || locator->itl_kind == ITL_FLAG_COMMITTED + data_kind = locator->itl_kind == ITL_FLAG_ACTIVE || locator->itl_kind == ITL_FLAG_COMMITTED || locator->itl_kind == ITL_FLAG_ABORTED || locator->itl_kind == ITL_FLAG_NEEDS_CLEANOUT; if (locator->itl_slot_index >= CLUSTER_ITL_INITRANS_DEFAULT @@ -77,31 +75,25 @@ cluster_tx_resolve_reason_is_known(ClusterTxResolveReason reason) } static bool -cluster_tx_zero_epoch_terminal_census_is_admissible( - const ClusterTxLocator *locator, - const ClusterSemanticAdmissionToken *admission, - bool caller_owned_terminal_census) +cluster_tx_zero_epoch_terminal_census_is_admissible(const ClusterTxLocator *locator, + const ClusterSemanticAdmissionToken *admission, + bool caller_owned_terminal_census) { NodeId origin = uba_origin_node_id(locator->uba); int node_count = cluster_conf_node_count(); bool generation_admissible; bool topology_admissible; - topology_admissible - = (node_count == 1 && origin == (NodeId)cluster_node_id) - || (node_count == 4 && origin != InvalidNodeId); + topology_admissible = (node_count == 1 && origin == (NodeId)cluster_node_id) + || (node_count == 4 && origin != InvalidNodeId); /* The single-node sentinel exists only before the first PGSA record. * The approved homogeneous four-node clean-formation path instead binds * whatever record generation the caller-owned admission currently holds; * its exact-current check below is the freshness proof. */ generation_admissible - = (node_count == 1 && admission->record_generation == 0) - || node_count == 4; - return caller_owned_terminal_census - && generation_admissible - && cluster_storage_mode_enabled() - && topology_admissible - && !cluster_recmerge_window_active + = (node_count == 1 && admission->record_generation == 0) || node_count == 4; + return caller_owned_terminal_census && generation_admissible && cluster_storage_mode_enabled() + && topology_admissible && !cluster_recmerge_window_active && cluster_epoch_get_current() == 0 && cluster_semantic_activation_recheck_r4_terminal_census(admission); } @@ -112,17 +104,13 @@ cluster_tx_zero_epoch_terminal_census_is_admissible( * and is admitted only for the homogeneous four-node clean formation. */ static bool cluster_tx_zero_epoch_partial_visibility_is_admissible( - const ClusterTxLocator *locator, - const ClusterSemanticAdmissionToken *admission) + const ClusterTxLocator *locator, const ClusterSemanticAdmissionToken *admission) { NodeId origin = uba_origin_node_id(locator->uba); - return cluster_conf_node_count() == 4 - && origin != InvalidNodeId - && admission->record_generation != 0 - && cluster_storage_mode_enabled() - && !cluster_recmerge_window_active - && cluster_epoch_get_current() == 0 + return cluster_conf_node_count() == 4 && origin != InvalidNodeId + && admission->record_generation != 0 && cluster_storage_mode_enabled() + && !cluster_recmerge_window_active && cluster_epoch_get_current() == 0 && cluster_semantic_activation_recheck(admission); } @@ -149,10 +137,8 @@ cluster_tx_resolution_is_publishable(const ClusterTxLocator *locator, ClusterTxR /* Hint cleanout and bounded terminal census may publish only an * irreversible terminal result. */ - if ((mode == CLUSTER_TX_RESOLVE_CLEANOUT_HINT - || mode == CLUSTER_TX_RESOLVE_TERMINAL_CENSUS) - && resolution->outcome != CLUSTER_TX_COMMITTED - && resolution->outcome != CLUSTER_TX_ABORTED) + if ((mode == CLUSTER_TX_RESOLVE_CLEANOUT_HINT || mode == CLUSTER_TX_RESOLVE_TERMINAL_CENSUS) + && resolution->outcome != CLUSTER_TX_COMMITTED && resolution->outcome != CLUSTER_TX_ABORTED) return false; return true; @@ -216,9 +202,8 @@ cluster_tx_locator_from_itl(Page page, uint8 slot_index, ClusterTxLocator *out, } bool -cluster_tx_locator_from_itl_terminal_census( - Page page, uint8 slot_index, ClusterTxLocator *out, - ClusterTxResolveReason *reason_out) +cluster_tx_locator_from_itl_terminal_census(Page page, uint8 slot_index, ClusterTxLocator *out, + ClusterTxResolveReason *reason_out) { if (!cluster_tx_locator_from_itl(page, slot_index, out, reason_out)) return false; @@ -230,11 +215,11 @@ cluster_tx_locator_from_itl_terminal_census( } static ClusterTxOutcome -cluster_tx_resolve_exact_with_admission( - const ClusterTxLocator *locator, ClusterTxResolveMode mode, - const ClusterSemanticAdmissionToken *admission, ClusterTxResolution *out, - ClusterTxResolveReason *reason_out, bool caller_owned_terminal_census, - SCN retained_commit_scn) +cluster_tx_resolve_exact_with_admission(const ClusterTxLocator *locator, ClusterTxResolveMode mode, + const ClusterSemanticAdmissionToken *admission, + ClusterTxResolution *out, + ClusterTxResolveReason *reason_out, + bool caller_owned_terminal_census, SCN retained_commit_scn) { ClusterTxResolution candidate; ClusterTxResolveReason reason = CLUSTER_TX_RESOLVE_PROTOCOL; @@ -242,9 +227,8 @@ cluster_tx_resolve_exact_with_admission( ClusterTxOutcome outcome = CLUSTER_TX_UNKNOWN; uint64 formation_epoch; bool terminal_census = mode == CLUSTER_TX_RESOLVE_TERMINAL_CENSUS; - bool partial_visibility - = mode == CLUSTER_TX_RESOLVE_VISIBILITY - && locator != NULL && locator->tt_wrap == TT_WRAP_INVALID; + bool partial_visibility = mode == CLUSTER_TX_RESOLVE_VISIBILITY && locator != NULL + && locator->tt_wrap == TT_WRAP_INVALID; bool clean_formation_row_wait = false; if (out != NULL) @@ -256,11 +240,9 @@ cluster_tx_resolve_exact_with_admission( if (admission == NULL || !admission->entered || admission->feature_bit != CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1 || admission->side != CLUSTER_SEMANTIC_TARGET_SIDE || out == NULL - || (unsigned int)mode - > (unsigned int)CLUSTER_TX_RESOLVE_TERMINAL_CENSUS) + || (unsigned int)mode > (unsigned int)CLUSTER_TX_RESOLVE_TERMINAL_CENSUS) goto done; - if (!cluster_tx_locator_is_well_formed( - locator, terminal_census || partial_visibility, &reason)) + if (!cluster_tx_locator_is_well_formed(locator, terminal_census || partial_visibility, &reason)) goto done; formation_epoch = admission->formation_epoch; @@ -295,36 +277,31 @@ cluster_tx_resolve_exact_with_admission( outcome = cluster_runtime_visibility_resolve_exact_origin_admitted( locator, mode, admission, &candidate, &provider_reason); else - outcome = cluster_runtime_visibility_resolve_exact_origin( - locator, mode, formation_epoch, &candidate, &provider_reason); + outcome = cluster_runtime_visibility_resolve_exact_origin(locator, mode, formation_epoch, + &candidate, &provider_reason); if (outcome == CLUSTER_TX_UNKNOWN && terminal_census - && locator->itl_kind == ITL_FLAG_NEEDS_CLEANOUT - && SCN_VALID(retained_commit_scn)) - { + && locator->itl_kind == ITL_FLAG_NEEDS_CLEANOUT && SCN_VALID(retained_commit_scn)) { memset(&candidate, 0, sizeof(candidate)); provider_reason = CLUSTER_TX_RESOLVE_AUTHORITY_UNAVAILABLE; - outcome - = cluster_runtime_visibility_resolve_terminal_census_retained_exact( - locator, retained_commit_scn, admission, &candidate, - &provider_reason); + outcome = cluster_runtime_visibility_resolve_terminal_census_retained_exact( + locator, retained_commit_scn, admission, &candidate, &provider_reason); } if (outcome == CLUSTER_TX_UNKNOWN) { reason = provider_reason == CLUSTER_TX_RESOLVE_NONE - || !cluster_tx_resolve_reason_is_known(provider_reason) - ? CLUSTER_TX_RESOLVE_PROTOCOL - : provider_reason; + || !cluster_tx_resolve_reason_is_known(provider_reason) + ? CLUSTER_TX_RESOLVE_PROTOCOL + : provider_reason; goto done; } - if (!cluster_tx_resolution_is_publishable(locator, mode, formation_epoch, - outcome, &candidate, provider_reason)) { + if (!cluster_tx_resolution_is_publishable(locator, mode, formation_epoch, outcome, &candidate, + provider_reason)) { outcome = CLUSTER_TX_UNKNOWN; reason = CLUSTER_TX_RESOLVE_PROTOCOL; goto done; } if (cluster_epoch_get_current() != formation_epoch - || (terminal_census - ? !cluster_semantic_activation_recheck_r4_terminal_census(admission) - : !cluster_semantic_activation_recheck(admission))) { + || (terminal_census ? !cluster_semantic_activation_recheck_r4_terminal_census(admission) + : !cluster_semantic_activation_recheck(admission))) { outcome = CLUSTER_TX_UNKNOWN; reason = CLUSTER_TX_RESOLVE_RF_DEFERRED; goto done; @@ -335,26 +312,21 @@ cluster_tx_resolve_exact_with_admission( done: switch (outcome) { - case CLUSTER_TX_UNKNOWN: - cluster_r4_observe(CLUSTER_R4_EVENT_TX_UNKNOWN, reason, - CLUSTER_CR_BUILD_NONE); - break; - case CLUSTER_TX_IN_PROGRESS: - cluster_r4_observe(CLUSTER_R4_EVENT_TX_IN_PROGRESS, reason, - CLUSTER_CR_BUILD_NONE); - break; - case CLUSTER_TX_PREPARED: - cluster_r4_observe(CLUSTER_R4_EVENT_TX_PREPARED, reason, - CLUSTER_CR_BUILD_NONE); - break; - case CLUSTER_TX_COMMITTED: - cluster_r4_observe(CLUSTER_R4_EVENT_TX_COMMITTED, reason, - CLUSTER_CR_BUILD_NONE); - break; - case CLUSTER_TX_ABORTED: - cluster_r4_observe(CLUSTER_R4_EVENT_TX_ABORTED, reason, - CLUSTER_CR_BUILD_NONE); - break; + case CLUSTER_TX_UNKNOWN: + cluster_r4_observe(CLUSTER_R4_EVENT_TX_UNKNOWN, reason, CLUSTER_CR_BUILD_NONE); + break; + case CLUSTER_TX_IN_PROGRESS: + cluster_r4_observe(CLUSTER_R4_EVENT_TX_IN_PROGRESS, reason, CLUSTER_CR_BUILD_NONE); + break; + case CLUSTER_TX_PREPARED: + cluster_r4_observe(CLUSTER_R4_EVENT_TX_PREPARED, reason, CLUSTER_CR_BUILD_NONE); + break; + case CLUSTER_TX_COMMITTED: + cluster_r4_observe(CLUSTER_R4_EVENT_TX_COMMITTED, reason, CLUSTER_CR_BUILD_NONE); + break; + case CLUSTER_TX_ABORTED: + cluster_r4_observe(CLUSTER_R4_EVENT_TX_ABORTED, reason, CLUSTER_CR_BUILD_NONE); + break; } if (reason_out != NULL) *reason_out = reason; @@ -362,10 +334,9 @@ cluster_tx_resolve_exact_with_admission( } ClusterTxOutcome -cluster_tx_resolve_exact_admitted( - const ClusterTxLocator *locator, ClusterTxResolveMode mode, - const ClusterSemanticAdmissionToken *admission, ClusterTxResolution *out, - ClusterTxResolveReason *reason_out) +cluster_tx_resolve_exact_admitted(const ClusterTxLocator *locator, ClusterTxResolveMode mode, + const ClusterSemanticAdmissionToken *admission, + ClusterTxResolution *out, ClusterTxResolveReason *reason_out) { if (mode != CLUSTER_TX_RESOLVE_TERMINAL_CENSUS) { if (out != NULL) @@ -374,27 +345,27 @@ cluster_tx_resolve_exact_admitted( *reason_out = CLUSTER_TX_RESOLVE_PROTOCOL; return CLUSTER_TX_UNKNOWN; } - return cluster_tx_resolve_exact_with_admission( - locator, mode, admission, out, reason_out, true, InvalidScn); + return cluster_tx_resolve_exact_with_admission(locator, mode, admission, out, reason_out, true, + InvalidScn); } ClusterTxOutcome -cluster_tx_resolve_terminal_census_retained_admitted( - const ClusterTxLocator *locator, SCN retained_commit_scn, - const ClusterSemanticAdmissionToken *admission, ClusterTxResolution *out, - ClusterTxResolveReason *reason_out) +cluster_tx_resolve_terminal_census_retained_admitted(const ClusterTxLocator *locator, + SCN retained_commit_scn, + const ClusterSemanticAdmissionToken *admission, + ClusterTxResolution *out, + ClusterTxResolveReason *reason_out) { - if (!SCN_VALID(retained_commit_scn)) - { + if (!SCN_VALID(retained_commit_scn)) { if (out != NULL) memset(out, 0, sizeof(*out)); if (reason_out != NULL) *reason_out = CLUSTER_TX_RESOLVE_PROTOCOL; return CLUSTER_TX_UNKNOWN; } - return cluster_tx_resolve_exact_with_admission( - locator, CLUSTER_TX_RESOLVE_TERMINAL_CENSUS, admission, out, - reason_out, true, retained_commit_scn); + return cluster_tx_resolve_exact_with_admission(locator, CLUSTER_TX_RESOLVE_TERMINAL_CENSUS, + admission, out, reason_out, true, + retained_commit_scn); } void @@ -405,8 +376,7 @@ cluster_tx_resolve_terminal_census_batch_preflight(void) ClusterTxOutcome cluster_tx_resolve_exact(const ClusterTxLocator *locator, ClusterTxResolveMode mode, - ClusterTxResolution *out, - ClusterTxResolveReason *reason_out) + ClusterTxResolution *out, ClusterTxResolveReason *reason_out) { ClusterSemanticAdmissionToken admission; ClusterSemanticAdmissionResult admission_result; @@ -420,23 +390,21 @@ cluster_tx_resolve_exact(const ClusterTxLocator *locator, ClusterTxResolveMode m *reason_out = CLUSTER_TX_RESOLVE_TARGET_DISABLED; memset(&admission, 0, sizeof(admission)); if (terminal_census) - admission_result - = cluster_semantic_activation_enter_r4_terminal_census(&admission); + admission_result = cluster_semantic_activation_enter_r4_terminal_census(&admission); else admission_result = cluster_semantic_activation_enter( - CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, - CLUSTER_SEMANTIC_TARGET_SIDE, &admission); + CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, CLUSTER_SEMANTIC_TARGET_SIDE, &admission); if (admission_result != CLUSTER_SEMANTIC_ADMISSION_OK) { reason = admission_result == CLUSTER_SEMANTIC_ADMISSION_TARGET_DISABLED - ? CLUSTER_TX_RESOLVE_TARGET_DISABLED - : CLUSTER_TX_RESOLVE_RF_DEFERRED; + ? CLUSTER_TX_RESOLVE_TARGET_DISABLED + : CLUSTER_TX_RESOLVE_RF_DEFERRED; goto done; } PG_TRY(); { - outcome = cluster_tx_resolve_exact_with_admission( - locator, mode, &admission, out, &reason, false, InvalidScn); + outcome = cluster_tx_resolve_exact_with_admission(locator, mode, &admission, out, &reason, + false, InvalidScn); } PG_FINALLY(); { @@ -465,12 +433,12 @@ cluster_tx_resolve_multixact(MultiXactId mxid, ClusterMultiResolution *out, *reason_out = CLUSTER_TX_RESOLVE_TARGET_DISABLED; memset(&admission, 0, sizeof(admission)); - admission_result = cluster_semantic_activation_enter( - CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, CLUSTER_SEMANTIC_TARGET_SIDE, &admission); + admission_result = cluster_semantic_activation_enter(CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, + CLUSTER_SEMANTIC_TARGET_SIDE, &admission); if (admission_result != CLUSTER_SEMANTIC_ADMISSION_OK) { reason = admission_result == CLUSTER_SEMANTIC_ADMISSION_TARGET_DISABLED - ? CLUSTER_TX_RESOLVE_TARGET_DISABLED - : CLUSTER_TX_RESOLVE_RF_DEFERRED; + ? CLUSTER_TX_RESOLVE_TARGET_DISABLED + : CLUSTER_TX_RESOLVE_RF_DEFERRED; goto done; } @@ -497,10 +465,9 @@ cluster_tx_resolve_multixact(MultiXactId mxid, ClusterMultiResolution *out, bool stable; int i; - first_count = GetMultiXactIdMembersWithOffset(mxid, &first, false, false, - &first_start); - second_count = GetMultiXactIdMembersWithOffset(mxid, &second, false, false, - &second_start); + first_count = GetMultiXactIdMembersWithOffset(mxid, &first, false, false, &first_start); + second_count + = GetMultiXactIdMembersWithOffset(mxid, &second, false, false, &second_start); first_valid = first_start != 0 && first_count >= 2 && first_count <= CLUSTER_R4_MAX_MULTI_MEMBERS && first != NULL; @@ -528,8 +495,8 @@ cluster_tx_resolve_multixact(MultiXactId mxid, ClusterMultiResolution *out, } stable = first_valid && second_valid - && cluster_multixact_native_snapshot_equal( - first_start, first_count, first, second_start, second_count, second); + && cluster_multixact_native_snapshot_equal(first_start, first_count, first, + second_start, second_count, second); if (first != NULL) pfree(first); if (second != NULL) @@ -546,8 +513,7 @@ cluster_tx_resolve_multixact(MultiXactId mxid, ClusterMultiResolution *out, reason = CLUSTER_TX_RESOLVE_COMPOSITION_CHANGED; } -admitted_done: - ; + admitted_done:; } PG_FINALLY(); { diff --git a/src/backend/cluster/cluster_undo_horizon_ic.c b/src/backend/cluster/cluster_undo_horizon_ic.c index b10878b05b2..46515177c0d 100644 --- a/src/backend/cluster/cluster_undo_horizon_ic.c +++ b/src/backend/cluster/cluster_undo_horizon_ic.c @@ -553,26 +553,24 @@ cluster_undo_horizon_read_admission_enforce(SCN read_scn) refuse_reason = "no active snapshot"; else if (snap->read_epoch < admitted - 1) refuse_reason = "snapshot epoch predates self admission epoch"; - else if (SCN_VALID(read_scn) && SCN_VALID(snap->read_scn) - && snap->read_scn != read_scn) + else if (SCN_VALID(read_scn) && SCN_VALID(snap->read_scn) && snap->read_scn != read_scn) refuse_reason = "resolver read SCN does not match the active snapshot"; if (refuse_reason != NULL) { if (UndoHorizonShmem != NULL) pg_atomic_fetch_add_u64(&UndoHorizonShmem->admission_refuse_count, 1); - ereport(ERROR, (errcode(ERRCODE_CLUSTER_RECONFIG_IN_PROGRESS), - errmsg("cross-node undo access refused: snapshot predates this node's " - "cluster admission"), - errdetail("reason=%s admitted_epoch=" UINT64_FORMAT - " snapshot_epoch=" UINT64_FORMAT " current_epoch=" UINT64_FORMAT - " resolver_read_scn=" UINT64_FORMAT - " snapshot_read_scn=" UINT64_FORMAT, - refuse_reason, admitted == 0 ? 0 : admitted - 1, - snap == NULL ? 0 : snap->read_epoch, - cluster_epoch_get_current(), (uint64)read_scn, - snap == NULL ? 0 : (uint64)snap->read_scn), - errhint("Take a new snapshot (new statement or transaction) after the " - "join completed and retry."))); + ereport(ERROR, + (errcode(ERRCODE_CLUSTER_RECONFIG_IN_PROGRESS), + errmsg("cross-node undo access refused: snapshot predates this node's " + "cluster admission"), + errdetail("reason=%s admitted_epoch=" UINT64_FORMAT + " snapshot_epoch=" UINT64_FORMAT " current_epoch=" UINT64_FORMAT + " resolver_read_scn=" UINT64_FORMAT " snapshot_read_scn=" UINT64_FORMAT, + refuse_reason, admitted == 0 ? 0 : admitted - 1, + snap == NULL ? 0 : snap->read_epoch, cluster_epoch_get_current(), + (uint64)read_scn, snap == NULL ? 0 : (uint64)snap->read_scn), + errhint("Take a new snapshot (new statement or transaction) after the " + "join completed and retry."))); } /* diff --git a/src/backend/cluster/cluster_undo_record.c b/src/backend/cluster/cluster_undo_record.c index c2c6001ffe5..b274c63e02c 100644 --- a/src/backend/cluster/cluster_undo_record.c +++ b/src/backend/cluster/cluster_undo_record.c @@ -1391,8 +1391,9 @@ claim_undo_extent(ClusterUndoExtent *ext, uint8 owner_instance, uint32 ensured_s PG_CATCH(); { pgstat_report_wait_end(); - LWLockRelease(&UndoRecordShared->lifecycle_lock.lock); - LWLockRelease(&UndoRecordShared->cursor_lock.lock); + /* ERROR resets InterruptHoldoffCount. The outer transaction + * handler releases LWLocks with LWLockReleaseAll, not retail + * LWLockRelease calls from this rethrow-only handler. */ PG_RE_THROW(); } PG_END_TRY(); @@ -1425,7 +1426,6 @@ claim_undo_extent(ClusterUndoExtent *ext, uint8 owner_instance, uint32 ensured_s PG_CATCH(); { pgstat_report_wait_end(); - LWLockRelease(&UndoRecordShared->cursor_lock.lock); PG_RE_THROW(); } PG_END_TRY(); @@ -1474,7 +1474,6 @@ claim_undo_extent(ClusterUndoExtent *ext, uint8 owner_instance, uint32 ensured_s } PG_CATCH(); { - LWLockRelease(&UndoRecordShared->cursor_lock.lock); PG_RE_THROW(); } PG_END_TRY(); @@ -1524,7 +1523,6 @@ claim_undo_extent(ClusterUndoExtent *ext, uint8 owner_instance, uint32 ensured_s } PG_CATCH(); { - LWLockRelease(&UndoRecordShared->cursor_lock.lock); PG_RE_THROW(); } PG_END_TRY(); @@ -3512,6 +3510,11 @@ cluster_undo_autoextend_count(void) * cluster_tt_slot_current_segment / cluster_tt_slot_rollover) -- never the * reverse. The retention horizon (ProcArrayLock) is computed by the caller * BEFORE this call and is not held across it. + * + * On ERROR, the transaction error handler owns LWLockReleaseAll. ERROR has + * already reset InterruptHoldoffCount, so rethrow handlers must not call + * LWLockRelease on the allocator locks. Normal return paths still release + * their exact locks below. */ uint32 cluster_undo_tt_rollover_locked(int node_id, uint32 old_segment_id, bool *out_at_hard_cap) @@ -3551,8 +3554,6 @@ cluster_undo_tt_rollover_locked(int node_id, uint32 old_segment_id, bool *out_at } PG_CATCH(); { - LWLockRelease(&UndoRecordShared->lifecycle_lock.lock); - LWLockRelease(&UndoRecordShared->cursor_lock.lock); PG_RE_THROW(); } PG_END_TRY(); @@ -3587,7 +3588,6 @@ cluster_undo_tt_rollover_locked(int node_id, uint32 old_segment_id, bool *out_at } PG_CATCH(); { - LWLockRelease(&UndoRecordShared->cursor_lock.lock); PG_RE_THROW(); } PG_END_TRY(); @@ -3630,7 +3630,6 @@ cluster_undo_tt_rollover_locked(int node_id, uint32 old_segment_id, bool *out_at } PG_CATCH(); { - LWLockRelease(&UndoRecordShared->cursor_lock.lock); PG_RE_THROW(); } PG_END_TRY(); @@ -3669,7 +3668,6 @@ cluster_undo_tt_rollover_locked(int node_id, uint32 old_segment_id, bool *out_at } PG_CATCH(); { - LWLockRelease(&UndoRecordShared->cursor_lock.lock); PG_RE_THROW(); } PG_END_TRY(); @@ -3740,7 +3738,6 @@ cluster_undo_tt_rollover_locked(int node_id, uint32 old_segment_id, bool *out_at } PG_CATCH(); { - LWLockRelease(&UndoRecordShared->cursor_lock.lock); PG_RE_THROW(); } PG_END_TRY(); diff --git a/src/backend/cluster/cluster_undo_root_descriptor.c b/src/backend/cluster/cluster_undo_root_descriptor.c index e3eab007e2b..a5467285c30 100644 --- a/src/backend/cluster/cluster_undo_root_descriptor.c +++ b/src/backend/cluster/cluster_undo_root_descriptor.c @@ -37,16 +37,14 @@ pgrd_get_le16(const uint8 *in) static uint32 pgrd_get_le32(const uint8 *in) { - return (uint32)in[0] | ((uint32)in[1] << 8) - | ((uint32)in[2] << 16) | ((uint32)in[3] << 24); + return (uint32)in[0] | ((uint32)in[1] << 8) | ((uint32)in[2] << 16) | ((uint32)in[3] << 24); } static uint64 pgrd_get_le64(const uint8 *in) { - return (uint64)pgrd_get_le32(in) - | ((uint64)pgrd_get_le32(in + 4) << 32); + return (uint64)pgrd_get_le32(in) | ((uint64)pgrd_get_le32(in + 4) << 32); } @@ -102,8 +100,8 @@ pgrd_crc32c(const uint8 bytes[CLUSTER_UNDO_ROOT_DESCRIPTOR_BYTES]) bool -cluster_undo_root_namespace_id(uint64 descriptor_incarnation, - uint32 root_ordinal, uint64 *namespace_id) +cluster_undo_root_namespace_id(uint64 descriptor_incarnation, uint32 root_ordinal, + uint64 *namespace_id) { uint64 ordinal = (uint64)root_ordinal + 1; uint64 incarnation_index; @@ -113,9 +111,7 @@ cluster_undo_root_namespace_id(uint64 descriptor_incarnation, || root_ordinal >= CLUSTER_UNDO_ROOT_COUNT) return false; incarnation_index = descriptor_incarnation - 1; - if (incarnation_index - > (CLUSTER_UNDO_ROOT_MAX_NAMESPACE - ordinal) - / CLUSTER_UNDO_ROOT_COUNT) + if (incarnation_index > (CLUSTER_UNDO_ROOT_MAX_NAMESPACE - ordinal) / CLUSTER_UNDO_ROOT_COUNT) return false; value = incarnation_index * CLUSTER_UNDO_ROOT_COUNT + ordinal; if (value == 0 || value > CLUSTER_UNDO_ROOT_MAX_NAMESPACE) @@ -126,11 +122,10 @@ cluster_undo_root_namespace_id(uint64 descriptor_incarnation, bool -cluster_undo_root_file_slot(uint32 owner_instance, uint32 segment_slot, - uint32 *file_slot) +cluster_undo_root_file_slot(uint32 owner_instance, uint32 segment_slot, uint32 *file_slot) { - if (file_slot == NULL || owner_instance == 0 - || owner_instance > CLUSTER_MAX_NODES || segment_slot >= 256) + if (file_slot == NULL || owner_instance == 0 || owner_instance > CLUSTER_MAX_NODES + || segment_slot >= 256) return false; *file_slot = (owner_instance - 1) * 256 + segment_slot; return true; @@ -140,8 +135,7 @@ cluster_undo_root_file_slot(uint32 owner_instance, uint32 segment_slot, bool cluster_undo_root_id(uint64 namespace_id, uint32 file_slot, uint64 *root_id) { - if (root_id == NULL || namespace_id == 0 - || namespace_id > CLUSTER_UNDO_ROOT_MAX_NAMESPACE + if (root_id == NULL || namespace_id == 0 || namespace_id > CLUSTER_UNDO_ROOT_MAX_NAMESPACE || file_slot >= CLUSTER_UNDO_ROOT_FILE_SLOTS) return false; *root_id = (namespace_id << 15) | file_slot; @@ -156,66 +150,52 @@ pgrd_descriptor_valid(const ClusterUndoRootDescriptorV1 *descriptor) if (descriptor == NULL || descriptor->descriptor_incarnation == 0 || descriptor->system_identifier == 0 - || pgrd_bytes_zero(descriptor->root_uuid, - CLUSTER_UNDO_ROOT_UUID_BYTES)) + || pgrd_bytes_zero(descriptor->root_uuid, CLUSTER_UNDO_ROOT_UUID_BYTES)) return false; if (descriptor->root_kind == CLUSTER_UNDO_ROOT_KIND_SHARED) { if (descriptor->owner_node != -1 || descriptor->root_ordinal != 0) return false; } else if (descriptor->root_kind == CLUSTER_UNDO_ROOT_KIND_LOCAL) { - if (descriptor->owner_node < 0 - || descriptor->owner_node >= CLUSTER_MAX_NODES - || descriptor->root_ordinal - != (uint32)descriptor->owner_node + 1) + if (descriptor->owner_node < 0 || descriptor->owner_node >= CLUSTER_MAX_NODES + || descriptor->root_ordinal != (uint32)descriptor->owner_node + 1) return false; } else return false; - return cluster_undo_root_namespace_id( - descriptor->descriptor_incarnation, descriptor->root_ordinal, - &expected_namespace) + return cluster_undo_root_namespace_id(descriptor->descriptor_incarnation, + descriptor->root_ordinal, &expected_namespace) && descriptor->namespace_id == expected_namespace; } bool -cluster_undo_root_descriptor_encode( - const ClusterUndoRootDescriptorV1 *descriptor, - uint8 out[CLUSTER_UNDO_ROOT_DESCRIPTOR_BYTES]) +cluster_undo_root_descriptor_encode(const ClusterUndoRootDescriptorV1 *descriptor, + uint8 out[CLUSTER_UNDO_ROOT_DESCRIPTOR_BYTES]) { uint8 image[CLUSTER_UNDO_ROOT_DESCRIPTOR_BYTES]; if (out == NULL || !pgrd_descriptor_valid(descriptor)) return false; memset(image, 0, sizeof(image)); - pgrd_put_le32(image + PGRD_OFF_MAGIC, - CLUSTER_UNDO_ROOT_DESCRIPTOR_MAGIC); - pgrd_put_le16(image + PGRD_OFF_VERSION, - CLUSTER_UNDO_ROOT_DESCRIPTOR_VERSION); - pgrd_put_le16(image + PGRD_OFF_HEADER_LEN, - CLUSTER_UNDO_ROOT_DESCRIPTOR_HEADER_LEN); - pgrd_put_le64(image + PGRD_OFF_INCARNATION, - descriptor->descriptor_incarnation); + pgrd_put_le32(image + PGRD_OFF_MAGIC, CLUSTER_UNDO_ROOT_DESCRIPTOR_MAGIC); + pgrd_put_le16(image + PGRD_OFF_VERSION, CLUSTER_UNDO_ROOT_DESCRIPTOR_VERSION); + pgrd_put_le16(image + PGRD_OFF_HEADER_LEN, CLUSTER_UNDO_ROOT_DESCRIPTOR_HEADER_LEN); + pgrd_put_le64(image + PGRD_OFF_INCARNATION, descriptor->descriptor_incarnation); image[PGRD_OFF_ROOT_KIND] = descriptor->root_kind; - pgrd_put_le32(image + PGRD_OFF_OWNER_NODE, - (uint32)descriptor->owner_node); - pgrd_put_le32(image + PGRD_OFF_ROOT_ORDINAL, - descriptor->root_ordinal); - memcpy(image + PGRD_OFF_ROOT_UUID, descriptor->root_uuid, - CLUSTER_UNDO_ROOT_UUID_BYTES); + pgrd_put_le32(image + PGRD_OFF_OWNER_NODE, (uint32)descriptor->owner_node); + pgrd_put_le32(image + PGRD_OFF_ROOT_ORDINAL, descriptor->root_ordinal); + memcpy(image + PGRD_OFF_ROOT_UUID, descriptor->root_uuid, CLUSTER_UNDO_ROOT_UUID_BYTES); pgrd_put_le64(image + PGRD_OFF_NAMESPACE_ID, descriptor->namespace_id); - pgrd_put_le64(image + PGRD_OFF_SYSTEM_IDENTIFIER, - descriptor->system_identifier); - pgrd_put_le32(image + CLUSTER_UNDO_ROOT_DESCRIPTOR_CRC_OFFSET, - pgrd_crc32c(image)); + pgrd_put_le64(image + PGRD_OFF_SYSTEM_IDENTIFIER, descriptor->system_identifier); + pgrd_put_le32(image + CLUSTER_UNDO_ROOT_DESCRIPTOR_CRC_OFFSET, pgrd_crc32c(image)); memcpy(out, image, sizeof(image)); return true; } ClusterUndoRootDescriptorState -cluster_undo_root_descriptor_decode( - const uint8 bytes[CLUSTER_UNDO_ROOT_DESCRIPTOR_BYTES], - uint64 expected_system_identifier, ClusterUndoRootDescriptorV1 *out) +cluster_undo_root_descriptor_decode(const uint8 bytes[CLUSTER_UNDO_ROOT_DESCRIPTOR_BYTES], + uint64 expected_system_identifier, + ClusterUndoRootDescriptorV1 *out) { ClusterUndoRootDescriptorV1 decoded; @@ -223,34 +203,25 @@ cluster_undo_root_descriptor_decode( return CLUSTER_UNDO_ROOT_DESCRIPTOR_HOLD; if (pgrd_bytes_zero(bytes, CLUSTER_UNDO_ROOT_DESCRIPTOR_BYTES)) return CLUSTER_UNDO_ROOT_DESCRIPTOR_UNPROVISIONED; - if (pgrd_get_le32(bytes + PGRD_OFF_MAGIC) - != CLUSTER_UNDO_ROOT_DESCRIPTOR_MAGIC - || pgrd_get_le16(bytes + PGRD_OFF_VERSION) - != CLUSTER_UNDO_ROOT_DESCRIPTOR_VERSION - || pgrd_get_le16(bytes + PGRD_OFF_HEADER_LEN) - != CLUSTER_UNDO_ROOT_DESCRIPTOR_HEADER_LEN + if (pgrd_get_le32(bytes + PGRD_OFF_MAGIC) != CLUSTER_UNDO_ROOT_DESCRIPTOR_MAGIC + || pgrd_get_le16(bytes + PGRD_OFF_VERSION) != CLUSTER_UNDO_ROOT_DESCRIPTOR_VERSION + || pgrd_get_le16(bytes + PGRD_OFF_HEADER_LEN) != CLUSTER_UNDO_ROOT_DESCRIPTOR_HEADER_LEN || !pgrd_bytes_zero(bytes + PGRD_OFF_RESERVED0, 3) || pgrd_get_le32(bytes + PGRD_OFF_RESERVED1) != 0 || !pgrd_bytes_zero(bytes + PGRD_OFF_RESERVED2, - CLUSTER_UNDO_ROOT_DESCRIPTOR_CRC_OFFSET - - PGRD_OFF_RESERVED2) - || pgrd_get_le32(bytes + CLUSTER_UNDO_ROOT_DESCRIPTOR_CRC_OFFSET) - != pgrd_crc32c(bytes)) + CLUSTER_UNDO_ROOT_DESCRIPTOR_CRC_OFFSET - PGRD_OFF_RESERVED2) + || pgrd_get_le32(bytes + CLUSTER_UNDO_ROOT_DESCRIPTOR_CRC_OFFSET) != pgrd_crc32c(bytes)) return CLUSTER_UNDO_ROOT_DESCRIPTOR_HOLD; memset(&decoded, 0, sizeof(decoded)); - decoded.descriptor_incarnation - = pgrd_get_le64(bytes + PGRD_OFF_INCARNATION); + decoded.descriptor_incarnation = pgrd_get_le64(bytes + PGRD_OFF_INCARNATION); decoded.root_kind = bytes[PGRD_OFF_ROOT_KIND]; decoded.owner_node = (int32)pgrd_get_le32(bytes + PGRD_OFF_OWNER_NODE); decoded.root_ordinal = pgrd_get_le32(bytes + PGRD_OFF_ROOT_ORDINAL); - memcpy(decoded.root_uuid, bytes + PGRD_OFF_ROOT_UUID, - CLUSTER_UNDO_ROOT_UUID_BYTES); + memcpy(decoded.root_uuid, bytes + PGRD_OFF_ROOT_UUID, CLUSTER_UNDO_ROOT_UUID_BYTES); decoded.namespace_id = pgrd_get_le64(bytes + PGRD_OFF_NAMESPACE_ID); - decoded.system_identifier - = pgrd_get_le64(bytes + PGRD_OFF_SYSTEM_IDENTIFIER); - if (!pgrd_descriptor_valid(&decoded) - || decoded.system_identifier != expected_system_identifier) + decoded.system_identifier = pgrd_get_le64(bytes + PGRD_OFF_SYSTEM_IDENTIFIER); + if (!pgrd_descriptor_valid(&decoded) || decoded.system_identifier != expected_system_identifier) return CLUSTER_UNDO_ROOT_DESCRIPTOR_HOLD; *out = decoded; return CLUSTER_UNDO_ROOT_DESCRIPTOR_VALID; @@ -258,18 +229,17 @@ cluster_undo_root_descriptor_decode( bool -cluster_undo_root_descriptor_resolve( - const ClusterUndoRootDescriptorV1 *descriptor, - ClusterUndoPathIntent intent, uint32 owner_instance, uint32 segment_id, - ClusterUndoBlock0ResolvedRoot *out) +cluster_undo_root_descriptor_resolve(const ClusterUndoRootDescriptorV1 *descriptor, + ClusterUndoPathIntent intent, uint32 owner_instance, + uint32 segment_id, ClusterUndoBlock0ResolvedRoot *out) { ClusterUndoBlock0ResolvedRoot resolved; uint32 file_slot; uint32 first_segment; uint32 segment_slot; - if (out == NULL || !pgrd_descriptor_valid(descriptor) - || owner_instance == 0 || owner_instance > CLUSTER_MAX_NODES) + if (out == NULL || !pgrd_descriptor_valid(descriptor) || owner_instance == 0 + || owner_instance > CLUSTER_MAX_NODES) return false; if (descriptor->root_kind == CLUSTER_UNDO_ROOT_KIND_SHARED) { if (intent != CLUSTER_UNDO_PATH_RUNTIME_SHARED @@ -286,8 +256,7 @@ cluster_undo_root_descriptor_resolve( return false; segment_slot = segment_id - first_segment; if (!cluster_undo_root_file_slot(owner_instance, segment_slot, &file_slot) - || !cluster_undo_root_id(descriptor->namespace_id, file_slot, - &resolved.root_id)) + || !cluster_undo_root_id(descriptor->namespace_id, file_slot, &resolved.root_id)) return false; resolved.intent = intent; diff --git a/src/backend/cluster/cluster_views.c b/src/backend/cluster/cluster_views.c index 80d665b6740..b423042af6c 100644 --- a/src/backend/cluster/cluster_views.c +++ b/src/backend/cluster/cluster_views.c @@ -53,6 +53,19 @@ #include "cluster/cluster_inject.h" /* CLUSTER_INJECTION_POINT (stage 0.30 sweep) */ #include "cluster/cluster_views.h" +#ifndef USE_PGRAC_CLUSTER +/* pg_proc keeps this entry in both builds; no cutover exists without cluster. */ +PG_FUNCTION_INFO_V1(pgrac_r4_bit22_cutover_begin); + +Datum +pgrac_r4_bit22_cutover_begin(PG_FUNCTION_ARGS) +{ + ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("cluster support is not enabled in this build"))); + PG_RETURN_NULL(); +} +#endif + #ifdef USE_PGRAC_CLUSTER #include "cluster/cluster_apply_master_election.h" #include "cluster/cluster_conf.h" /* cluster_conf_lookup_node, role helpers */ diff --git a/src/backend/cluster/cluster_visibility_inject.c b/src/backend/cluster/cluster_visibility_inject.c index aa692c6c401..91a887a3889 100644 --- a/src/backend/cluster/cluster_visibility_inject.c +++ b/src/backend/cluster/cluster_visibility_inject.c @@ -262,7 +262,7 @@ cluster_test_inject_visibility_tt_ref(PG_FUNCTION_ARGS) source_request.status = install_status; source_request.commit_scn = commit_scn; install_admission = cluster_tt_status_source_dispatch(CLUSTER_TT_SOURCE_INSTALL_LOCAL, - &source_request, &source_result); + &source_request, &source_result); install_value = source_result.bool_value; installed = install_admission == CLUSTER_SEMANTIC_ADMISSION_OK && install_value; @@ -277,25 +277,24 @@ cluster_test_inject_visibility_tt_ref(PG_FUNCTION_ARGS) memset(&source_request, 0, sizeof(source_request)); source_request.key = &key; lookup_admission = cluster_tt_status_source_dispatch(CLUSTER_TT_SOURCE_LOOKUP, &source_request, - &source_result); + &source_result); lookup_value = source_result.bool_value; looked_up = lookup_admission == CLUSTER_SEMANTIC_ADMISSION_OK && lookup_value; res = source_result.lookup; - if (!installed || !looked_up || res.status != install_status - || res.commit_scn != commit_scn) - ereport(ERROR, (errcode(ERRCODE_CONFIGURATION_LIMIT_EXCEEDED), - errmsg("cluster TT status overlay install verification failed"), - errdetail("install admission=%d result=%s; lookup admission=%d result=%s; " - "key epoch=%u current epoch=" UINT64_FORMAT "; " - "requested status=%d observed status=%d; " - "requested commit SCN=" UINT64_FORMAT - " observed commit SCN=" UINT64_FORMAT ".", - (int)install_admission, install_value ? "true" : "false", - (int)lookup_admission, lookup_value ? "true" : "false", - key.cluster_epoch, cluster_epoch_get_current(), - (int)install_status, (int)res.status, - (uint64)commit_scn, (uint64)res.commit_scn), - errhint("Raise cluster.tt_status_overlay_max_entries or lower TTL."))); + if (!installed || !looked_up || res.status != install_status || res.commit_scn != commit_scn) + ereport(ERROR, + (errcode(ERRCODE_CONFIGURATION_LIMIT_EXCEEDED), + errmsg("cluster TT status overlay install verification failed"), + errdetail("install admission=%d result=%s; lookup admission=%d result=%s; " + "key epoch=%u current epoch=" UINT64_FORMAT "; " + "requested status=%d observed status=%d; " + "requested commit SCN=" UINT64_FORMAT + " observed commit SCN=" UINT64_FORMAT ".", + (int)install_admission, install_value ? "true" : "false", + (int)lookup_admission, lookup_value ? "true" : "false", + key.cluster_epoch, cluster_epoch_get_current(), (int)install_status, + (int)res.status, (uint64)commit_scn, (uint64)res.commit_scn), + errhint("Raise cluster.tt_status_overlay_max_entries or lower TTL."))); PG_RETURN_BOOL(true); } @@ -339,7 +338,7 @@ cluster_test_clear_visibility_injects(PG_FUNCTION_ARGS) memset(&source_request, 0, sizeof(source_request)); source_request.key = &key; (void)cluster_tt_status_source_dispatch(CLUSTER_TT_SOURCE_DELETE_EXACT, &source_request, - &source_result); + &source_result); hash_search(ClusterVisibilityInjectHTAB, &e->xid, HASH_REMOVE, NULL); removed++; diff --git a/src/backend/cluster/cluster_visibility_resolve.c b/src/backend/cluster/cluster_visibility_resolve.c index 468d70f66b0..11fbe018165 100644 --- a/src/backend/cluster/cluster_visibility_resolve.c +++ b/src/backend/cluster/cluster_visibility_resolve.c @@ -53,7 +53,7 @@ #include "cluster/cluster_tt_durable.h" /* spec-4.8 D2 remote_active_failclosed counter */ #include "cluster/cluster_tt_status.h" /* lookup_exact / Key / Result */ #include "cluster/cluster_touched_peers.h" /* spec-5.14 D2 class 4 */ -#include "cluster/cluster_tx_resolve.h" /* exact DATA->canonical TT fallback */ +#include "cluster/cluster_tx_resolve.h" /* exact DATA->canonical TT fallback */ #include "cluster/cluster_visibility_resolve.h" #include "cluster/cluster_wal_state.h" /* CLUSTER_WAL_STATE_SLOT_COUNT */ #include "cluster/cluster_xid_authority.h" /* GCS-race round-2 RC-E: native-prehistory gate */ @@ -120,9 +120,8 @@ vis_origin_materialized(int origin) static int cluster_vis_resolve_depth = 0; static bool -cluster_vis_from_exact_tx_resolution( - ClusterTxOutcome outcome, const ClusterTxResolution *resolution, - ClusterVisResolve *out) +cluster_vis_from_exact_tx_resolution(ClusterTxOutcome outcome, + const ClusterTxResolution *resolution, ClusterVisResolve *out) { if (resolution == NULL || out == NULL || outcome != resolution->outcome) return false; @@ -306,11 +305,9 @@ resolve_from_remote_ref(TransactionId raw_xid, const ClusterUndoTTSlotRef *ref, * route; eligibility is rechecked immediately before the exact request. */ defer_slotless_origin_pull = cluster_vis_freshref_c1b_pair_request_eligible( - raw_xid, ref->local_xid, ref->has_cached_status, - ref->cached_commit_scn, ref->cluster_epoch, - cluster_epoch_get_current(), (int32)ref->origin_node_id, - cluster_node_id, (uint32)ref->undo_segment_id, - (uint32)ref->tt_slot_id); + raw_xid, ref->local_xid, ref->has_cached_status, ref->cached_commit_scn, ref->cluster_epoch, + cluster_epoch_get_current(), (int32)ref->origin_node_id, cluster_node_id, + (uint32)ref->undo_segment_id, (uint32)ref->tt_slot_id); memset(&source_request, 0, sizeof(source_request)); source_request.key = &key; @@ -383,11 +380,11 @@ resolve_from_remote_ref(TransactionId raw_xid, const ClusterUndoTTSlotRef *ref, } static void -cluster_vis_log_freshref_unproven( - TransactionId raw_xid, const ClusterUndoTTSlotRef *ref, - bool freshref_pair, ClusterUndoVerdictResult v, - const ClusterTxLocator *exact_locator, ClusterTxOutcome exact_outcome, - ClusterTxResolveReason exact_reason) +cluster_vis_log_freshref_unproven(TransactionId raw_xid, const ClusterUndoTTSlotRef *ref, + bool freshref_pair, ClusterUndoVerdictResult v, + const ClusterTxLocator *exact_locator, + ClusterTxOutcome exact_outcome, + ClusterTxResolveReason exact_reason) { if (vis_freshref_first_unproven_logged || ref == NULL) return; @@ -397,12 +394,10 @@ cluster_vis_log_freshref_unproven( "ref_epoch=%u cached=%d cached_scn=" UINT64_FORMAT " freshref_pair=%d undo_verdict=%d exact_locator=%d " "exact_outcome=%d exact_reason=%s", - raw_xid, (unsigned)ref->origin_node_id, - (unsigned)ref->undo_segment_id, (unsigned)ref->tt_slot_id, - ref->cluster_epoch, ref->has_cached_status, - (uint64)ref->cached_commit_scn, freshref_pair, (int)v.kind, - exact_locator != NULL, (int)exact_outcome, - cluster_tx_resolve_reason_name(exact_reason)); + raw_xid, (unsigned)ref->origin_node_id, (unsigned)ref->undo_segment_id, + (unsigned)ref->tt_slot_id, ref->cluster_epoch, ref->has_cached_status, + (uint64)ref->cached_commit_scn, freshref_pair, (int)v.kind, exact_locator != NULL, + (int)exact_outcome, cluster_tx_resolve_reason_name(exact_reason)); } @@ -421,8 +416,7 @@ cluster_vis_log_freshref_unproven( */ static void classify_ref_guts(TransactionId raw_xid, const ClusterUndoTTSlotRef *ref, XLogRecPtr anchor_lsn, - SCN read_scn, const ClusterTxLocator *exact_locator, - ClusterVisResolve *out) + SCN read_scn, const ClusterTxLocator *exact_locator, ClusterVisResolve *out) { if (out == NULL || ref == NULL) return; @@ -805,11 +799,9 @@ classify_ref_guts(TransactionId raw_xid, const ClusterUndoTTSlotRef *ref, XLogRe * the dedicated fresh-ref counter is the ONLY extra bump here -- an * explicit rtvis_resolve_note here would double-count. */ bool freshref_pair = cluster_vis_freshref_c1b_pair_request_eligible( - raw_xid, ref->local_xid, ref->has_cached_status, - ref->cached_commit_scn, ref->cluster_epoch, - cluster_epoch_get_current(), (int32)ref->origin_node_id, - cluster_node_id, (uint32)ref->undo_segment_id, - (uint32)ref->tt_slot_id); + raw_xid, ref->local_xid, ref->has_cached_status, ref->cached_commit_scn, + ref->cluster_epoch, cluster_epoch_get_current(), (int32)ref->origin_node_id, + cluster_node_id, (uint32)ref->undo_segment_id, (uint32)ref->tt_slot_id); ClusterUndoVerdictResult v; cluster_vis_evidence_note(CLUSTER_VIS_METRIC_ORIGIN_ASK); @@ -829,8 +821,7 @@ classify_ref_guts(TransactionId raw_xid, const ClusterUndoTTSlotRef *ref, XLogRe /* O2: an origin-proven exact terminal is immutable and may use * the existing backend-local, lxid-bound memo. A bound or live * result remains request/snapshot relative and is never installed. */ - if ((v.kind == CLUSTER_UNDO_VERDICT_COMMITTED_EXACT - && SCN_VALID(v.commit_scn)) + if ((v.kind == CLUSTER_UNDO_VERDICT_COMMITTED_EXACT && SCN_VALID(v.commit_scn)) || v.kind == CLUSTER_UNDO_VERDICT_ABORTED) { ClusterTTStatusKey memo_key; @@ -845,9 +836,7 @@ classify_ref_guts(TransactionId raw_xid, const ClusterUndoTTSlotRef *ref, XLogRe v.kind == CLUSTER_UNDO_VERDICT_COMMITTED_EXACT ? (uint8)CLUSTER_TT_STATUS_COMMITTED : (uint8)CLUSTER_TT_STATUS_ABORTED, - v.kind == CLUSTER_UNDO_VERDICT_COMMITTED_EXACT - ? v.commit_scn - : InvalidScn); + v.kind == CLUSTER_UNDO_VERDICT_COMMITTED_EXACT ? v.commit_scn : InvalidScn); } cluster_vis_freshref_verdict_note_resolved(); return; @@ -862,13 +851,12 @@ classify_ref_guts(TransactionId raw_xid, const ClusterUndoTTSlotRef *ref, XLogRe exact_reason = CLUSTER_TX_RESOLVE_PROTOCOL; if (exact_locator != NULL) cluster_vis_evidence_note(CLUSTER_VIS_METRIC_ORIGIN_ASK); - exact_outcome = exact_locator == NULL - ? CLUSTER_TX_UNKNOWN - : cluster_tx_resolve_exact( - exact_locator, CLUSTER_TX_RESOLVE_VISIBILITY, - &exact_resolution, &exact_reason); - if (cluster_vis_from_exact_tx_resolution( - exact_outcome, &exact_resolution, out)) { + exact_outcome + = exact_locator == NULL + ? CLUSTER_TX_UNKNOWN + : cluster_tx_resolve_exact(exact_locator, CLUSTER_TX_RESOLVE_VISIBILITY, + &exact_resolution, &exact_reason); + if (cluster_vis_from_exact_tx_resolution(exact_outcome, &exact_resolution, out)) { cluster_vis_evidence_note(CLUSTER_VIS_METRIC_ROUTE_BYPASS); cluster_vis_evidence_note(CLUSTER_VIS_METRIC_DURABLE_ROUTE_GAP); cluster_vis_evidence_note(exact_outcome == CLUSTER_TX_IN_PROGRESS @@ -879,9 +867,8 @@ classify_ref_guts(TransactionId raw_xid, const ClusterUndoTTSlotRef *ref, XLogRe } /* Both reduced-key verdicts and the exact DATA->TT resolver are * unproven. The latter never returns BOUND or installs a memo. */ - cluster_vis_log_freshref_unproven( - raw_xid, ref, freshref_pair, v, exact_locator, - exact_outcome, exact_reason); + cluster_vis_log_freshref_unproven(raw_xid, ref, freshref_pair, v, exact_locator, + exact_outcome, exact_reason); if (exact_locator != NULL) { if (exact_reason == CLUSTER_TX_RESOLVE_TIMEOUT) { out->diagnostic_reason = "AUTHORITY_DEADLINE_EXPIRED"; @@ -956,8 +943,7 @@ cluster_vis_exact_locators_for_ref(Page page, uint8 slot_index, ClusterVisXidKin */ static void classify_ref(TransactionId raw_xid, const ClusterUndoTTSlotRef *ref, XLogRecPtr anchor_lsn, - SCN read_scn, const ClusterTxLocator *exact_locator, - ClusterVisResolve *out) + SCN read_scn, const ClusterTxLocator *exact_locator, ClusterVisResolve *out) { cluster_vis_resolve_depth++; classify_ref_guts(raw_xid, ref, anchor_lsn, read_scn, exact_locator, out); diff --git a/src/backend/cluster/cluster_visibility_verdict.c b/src/backend/cluster/cluster_visibility_verdict.c index e7829661a62..f3494350389 100644 --- a/src/backend/cluster/cluster_visibility_verdict.c +++ b/src/backend/cluster/cluster_visibility_verdict.c @@ -164,8 +164,7 @@ cluster_vis_update_lock_only_xmax_verdict(ClusterTTStatus status) * through local CLOG. lock_only dominates the command-id comparison. */ ClusterVisNativeSelfUpdateVerdict -cluster_vis_update_native_self_verdict(bool lock_only, - bool cmax_at_or_after_curcid) +cluster_vis_update_native_self_verdict(bool lock_only, bool cmax_at_or_after_curcid) { if (lock_only) return CLUSTER_VIS_NATIVE_SELF_BEING_MODIFIED; @@ -253,8 +252,7 @@ bool cluster_vis_dirty_remote_xmax_waitable(ClusterTTStatus status, bool is_xmax, bool exact_locator_valid) { - return status == CLUSTER_TT_STATUS_IN_PROGRESS - && is_xmax && exact_locator_valid; + return status == CLUSTER_TT_STATUS_IN_PROGRESS && is_xmax && exact_locator_valid; } /* ============================================================ diff --git a/src/backend/cluster/cluster_voting_disk_io.c b/src/backend/cluster/cluster_voting_disk_io.c index 8d9f64b25c1..5cb26e6850f 100644 --- a/src/backend/cluster/cluster_voting_disk_io.c +++ b/src/backend/cluster/cluster_voting_disk_io.c @@ -595,9 +595,8 @@ cluster_voting_disk_write_formation_slot(int fd, uint32 node_id, const void *in_ memcpy(aligned, in_slot512, CLUSTER_VOTING_SLOT_BYTES); voting_disk_io_arm_timeout(); - nwritten - = pwrite(fd, aligned, CLUSTER_VOTING_SLOT_BYTES, - CLUSTER_VOTING_FORMATION_SLOT_OFFSET(node_id)); + nwritten = pwrite(fd, aligned, CLUSTER_VOTING_SLOT_BYTES, + CLUSTER_VOTING_FORMATION_SLOT_OFFSET(node_id)); if (nwritten != CLUSTER_VOTING_SLOT_BYTES) { voting_disk_io_disarm_timeout(); return CLUSTER_VOTING_DISK_IO_FAILED; @@ -873,8 +872,7 @@ cluster_voting_disk_read_raw_slot_at(int fd, off_t offset, void *out_slot512) if (fd < 0) return CLUSTER_VOTING_DISK_RAW_READ_NOT_TRIED; - if (out_slot512 == NULL || offset < 0 - || offset % CLUSTER_VOTING_SLOT_BYTES != 0) + if (out_slot512 == NULL || offset < 0 || offset % CLUSTER_VOTING_SLOT_BYTES != 0) return CLUSTER_VOTING_DISK_RAW_READ_IO_FAILED; memset(aligned, 0, sizeof(aligned)); @@ -894,16 +892,14 @@ cluster_voting_disk_read_raw_slot_at(int fd, off_t offset, void *out_slot512) ClusterVotingDiskIoState -cluster_voting_disk_write_raw_slot_at(int fd, off_t offset, - const void *in_slot512) +cluster_voting_disk_write_raw_slot_at(int fd, off_t offset, const void *in_slot512) { char aligned[CLUSTER_VOTING_SLOT_BYTES] __attribute__((aligned(512))); ssize_t nwritten; if (fd < 0) return CLUSTER_VOTING_DISK_IO_NOT_TRIED; - if (in_slot512 == NULL || offset < 0 - || offset % CLUSTER_VOTING_SLOT_BYTES != 0) + if (in_slot512 == NULL || offset < 0 || offset % CLUSTER_VOTING_SLOT_BYTES != 0) return CLUSTER_VOTING_DISK_IO_FAILED; memcpy(aligned, in_slot512, CLUSTER_VOTING_SLOT_BYTES); @@ -948,8 +944,7 @@ cluster_voting_disk_read_epoch_ballot_slot(int fd, uint32 proposer_node_id, void } ClusterVotingDiskIoState -cluster_voting_disk_write_epoch_ballot_slot(int fd, uint32 proposer_node_id, - const void *in_slot512) +cluster_voting_disk_write_epoch_ballot_slot(int fd, uint32 proposer_node_id, const void *in_slot512) { char aligned[CLUSTER_VOTING_SLOT_BYTES] __attribute__((aligned(512))); ssize_t nwritten; @@ -961,7 +956,7 @@ cluster_voting_disk_write_epoch_ballot_slot(int fd, uint32 proposer_node_id, memcpy(aligned, in_slot512, CLUSTER_VOTING_SLOT_BYTES); nwritten = pwrite(fd, aligned, CLUSTER_VOTING_SLOT_BYTES, - CLUSTER_VOTING_EPOCH_BALLOT_SLOT_OFFSET(proposer_node_id)); + CLUSTER_VOTING_EPOCH_BALLOT_SLOT_OFFSET(proposer_node_id)); if (nwritten != CLUSTER_VOTING_SLOT_BYTES) return CLUSTER_VOTING_DISK_IO_FAILED; if (fdatasync(fd) != 0) @@ -989,8 +984,7 @@ voting_disk_raw_authority_attest(int fd, uint64 required_capacity) return false; if (ioctl(fd, BLKGETSIZE64, &capacity) != 0) return false; - return capacity >= required_capacity - && (capacity % CLUSTER_VOTING_SLOT_BYTES) == 0; + return capacity >= required_capacity && (capacity % CLUSTER_VOTING_SLOT_BYTES) == 0; #else (void)fd; (void)required_capacity; @@ -1001,15 +995,13 @@ voting_disk_raw_authority_attest(int fd, uint64 required_capacity) bool cluster_voting_disk_epoch_ballot_authority_attest(int fd) { - return voting_disk_raw_authority_attest( - fd, (uint64)CLUSTER_VOTING_FILE_BYTES_MIN); + return voting_disk_raw_authority_attest(fd, (uint64)CLUSTER_VOTING_FILE_BYTES_MIN); } bool cluster_voting_disk_pgrd_authority_attest(int fd) { - if (voting_disk_raw_authority_attest( - fd, (uint64)CLUSTER_VOTING_PGRD_FILE_BYTES_MIN)) + if (voting_disk_raw_authority_attest(fd, (uint64)CLUSTER_VOTING_PGRD_FILE_BYTES_MIN)) return true; #ifndef __linux__ { diff --git a/src/backend/cluster/cluster_wal_retention.c b/src/backend/cluster/cluster_wal_retention.c index 0cf4c42491f..89a2b448546 100644 --- a/src/backend/cluster/cluster_wal_retention.c +++ b/src/backend/cluster/cluster_wal_retention.c @@ -91,8 +91,8 @@ static ClusterWalRetentionE1Context *active_e1_context; static ClusterWalRetentionE1Context *active_action_context; static bool walr_resource_callback_registered; -static void walr_resource_release_callback(ResourceReleasePhase phase, - bool isCommit, bool isTopLevel, void *arg); +static void walr_resource_release_callback(ResourceReleasePhase phase, bool isCommit, + bool isTopLevel, void *arg); static void wal_reuse_guard_close_handles(ClusterWalReuseActionGuard *guard) @@ -130,7 +130,7 @@ static bool control_root_read_ready(ClusterControlRootResult result) { return result == CLUSTER_CONTROL_ROOT_OK_PRIMARY - || result == CLUSTER_CONTROL_ROOT_OK_PRIMARY_DEGRADED; + || result == CLUSTER_CONTROL_ROOT_OK_PRIMARY_DEGRADED; } bool @@ -161,16 +161,13 @@ cluster_wal_thread_directory_parse(const char *basename, uint16 *out_thread_id) } bool -cluster_wal_file_identity_valid(const ClusterWalFileIdentity *identity, - int wal_segsz_bytes) +cluster_wal_file_identity_valid(const ClusterWalFileIdentity *identity, int wal_segsz_bytes) { uint64 segments_per_id; - if (identity == NULL || !IsValidWalSegSize(wal_segsz_bytes) - || identity->thread_id == 0 + if (identity == NULL || !IsValidWalSegSize(wal_segsz_bytes) || identity->thread_id == 0 || identity->thread_id > CLUSTER_WAL_RETENTION_MAX_THREADS - || (identity->kind != CLUSTER_WAL_FILE_NORMAL - && identity->kind != CLUSTER_WAL_FILE_PARTIAL) + || (identity->kind != CLUSTER_WAL_FILE_NORMAL && identity->kind != CLUSTER_WAL_FILE_PARTIAL) || identity->reserved_zero != 0 || identity->tli == 0) return false; segments_per_id = XLogSegmentsPerXLogId(wal_segsz_bytes); @@ -178,8 +175,7 @@ cluster_wal_file_identity_valid(const ClusterWalFileIdentity *identity, } bool -cluster_wal_file_identity_parse(const char *basename, uint16 thread_id, - int wal_segsz_bytes, +cluster_wal_file_identity_parse(const char *basename, uint16 thread_id, int wal_segsz_bytes, ClusterWalFileIdentity *out_identity) { ClusterWalFileIdentity identity; @@ -194,8 +190,8 @@ cluster_wal_file_identity_parse(const char *basename, uint16 thread_id, if (out_identity == NULL) return false; memset(out_identity, 0, sizeof(*out_identity)); - if (basename == NULL || !IsValidWalSegSize(wal_segsz_bytes) - || thread_id == 0 || thread_id > CLUSTER_WAL_RETENTION_MAX_THREADS) + if (basename == NULL || !IsValidWalSegSize(wal_segsz_bytes) || thread_id == 0 + || thread_id > CLUSTER_WAL_RETENTION_MAX_THREADS) return false; partial = IsPartialXLogFileName(basename); if (!partial && !IsXLogFileName(basename)) @@ -223,42 +219,37 @@ cluster_wal_file_identity_parse(const char *basename, uint16 thread_id, bool cluster_wal_file_long_header_matches(const ClusterWalFileIdentity *identity, - const XLogLongPageHeaderData *header, - uint64 system_identifier, + const XLogLongPageHeaderData *header, uint64 system_identifier, int wal_segsz_bytes) { XLogRecPtr expected_pageaddr; - if (!cluster_wal_file_identity_valid(identity, wal_segsz_bytes) - || header == NULL || system_identifier == 0) + if (!cluster_wal_file_identity_valid(identity, wal_segsz_bytes) || header == NULL + || system_identifier == 0) return false; expected_pageaddr = (XLogRecPtr)(identity->segno * (uint64)wal_segsz_bytes); - return header->std.xlp_magic == XLOG_PAGE_MAGIC - && (header->std.xlp_info & ~XLP_ALL_FLAGS) == 0 - && (header->std.xlp_info & XLP_LONG_HEADER) != 0 - && header->std.xlp_tli == identity->tli - && header->std.xlp_pageaddr == expected_pageaddr - && header->std.xlp_thread_id == identity->thread_id - && header->std.xlp_cluster_flags == XLP_CLUSTER_FLAGS_RESERVED - && header->xlp_sysid == system_identifier - && header->xlp_seg_size == (uint32)wal_segsz_bytes - && header->xlp_xlog_blcksz == XLOG_BLCKSZ; + return header->std.xlp_magic == XLOG_PAGE_MAGIC && (header->std.xlp_info & ~XLP_ALL_FLAGS) == 0 + && (header->std.xlp_info & XLP_LONG_HEADER) != 0 && header->std.xlp_tli == identity->tli + && header->std.xlp_pageaddr == expected_pageaddr + && header->std.xlp_thread_id == identity->thread_id + && header->std.xlp_cluster_flags == XLP_CLUSTER_FLAGS_RESERVED + && header->xlp_sysid == system_identifier + && header->xlp_seg_size == (uint32)wal_segsz_bytes + && header->xlp_xlog_blcksz == XLOG_BLCKSZ; } bool -cluster_wal_retention_interval_segment_bounds( - const ClusterWalRetentionInterval *interval, int wal_segsz_bytes, - XLogSegNo *out_first, XLogSegNo *out_last) +cluster_wal_retention_interval_segment_bounds(const ClusterWalRetentionInterval *interval, + int wal_segsz_bytes, XLogSegNo *out_first, + XLogSegNo *out_last) { if (out_first == NULL || out_last == NULL) return false; *out_first = 0; *out_last = 0; - if (interval == NULL || !IsValidWalSegSize(wal_segsz_bytes) - || interval->thread_id == 0 - || interval->thread_id > CLUSTER_WAL_RETENTION_MAX_THREADS - || interval->reserved_zero != 0 || interval->tli == 0 - || interval->start_lsn == InvalidXLogRecPtr + if (interval == NULL || !IsValidWalSegSize(wal_segsz_bytes) || interval->thread_id == 0 + || interval->thread_id > CLUSTER_WAL_RETENTION_MAX_THREADS || interval->reserved_zero != 0 + || interval->tli == 0 || interval->start_lsn == InvalidXLogRecPtr || interval->end_lsn <= interval->start_lsn) return false; *out_first = interval->start_lsn / (uint64)wal_segsz_bytes; @@ -267,20 +258,18 @@ cluster_wal_retention_interval_segment_bounds( } bool -cluster_wal_retention_interval_intersects_file( - const ClusterWalRetentionInterval *interval, - const ClusterWalFileIdentity *identity, int wal_segsz_bytes) +cluster_wal_retention_interval_intersects_file(const ClusterWalRetentionInterval *interval, + const ClusterWalFileIdentity *identity, + int wal_segsz_bytes) { XLogSegNo first; XLogSegNo last; if (!cluster_wal_file_identity_valid(identity, wal_segsz_bytes) - || !cluster_wal_retention_interval_segment_bounds( - interval, wal_segsz_bytes, &first, &last)) + || !cluster_wal_retention_interval_segment_bounds(interval, wal_segsz_bytes, &first, &last)) return false; - return interval->thread_id == identity->thread_id - && interval->tli == identity->tli && identity->segno >= first - && identity->segno <= last; + return interval->thread_id == identity->thread_id && interval->tli == identity->tli + && identity->segno >= first && identity->segno <= last; } bool @@ -319,20 +308,18 @@ static bool walr_request_has_native_lock(const ClusterLockAcquireRequest *request) { return request->locktag.locktag_field1 == CLUSTER_WALR_NATIVE_TAG_MAGIC - && request->locktag.locktag_field2 == request->resid.field1 - && request->locktag.locktag_field3 - == CLUSTER_WAL_RETENTION_RESID_TYPE - && request->locktag.locktag_field4 == 0 - && request->locktag.locktag_type == LOCKTAG_USERLOCK - && request->locktag.locktag_lockmethodid == DEFAULT_LOCKMETHOD; + && request->locktag.locktag_field2 == request->resid.field1 + && request->locktag.locktag_field3 == CLUSTER_WAL_RETENTION_RESID_TYPE + && request->locktag.locktag_field4 == 0 + && request->locktag.locktag_type == LOCKTAG_USERLOCK + && request->locktag.locktag_lockmethodid == DEFAULT_LOCKMETHOD; } static void walr_native_lock_release_or_fatal(const ClusterLockAcquireRequest *request) { if (walr_request_has_native_lock(request) - && !LockRelease(&request->locktag, request->lockmode, - request->sessionLock)) + && !LockRelease(&request->locktag, request->lockmode, request->sessionLock)) elog(FATAL, "could not release WALR PG-native lock"); } @@ -348,10 +335,9 @@ walr_request_acquire_actual(ClusterLockAcquireRequest *request) if (result == CLUSTER_LOCK_ACQUIRE_NEED_PG_NATIVE_LOCK) { LockAcquireResult native_result; - walr_native_locktag_init((uint16)request->resid.field1, - &request->locktag); - native_result = LockAcquire(&request->locktag, request->lockmode, - request->sessionLock, request->dontwait); + walr_native_locktag_init((uint16)request->resid.field1, &request->locktag); + native_result = LockAcquire(&request->locktag, request->lockmode, request->sessionLock, + request->dontwait); if (native_result != LOCKACQUIRE_OK) { if (native_result == LOCKACQUIRE_ALREADY_CLEAR || native_result == LOCKACQUIRE_ALREADY_HELD) @@ -371,8 +357,7 @@ walr_request_acquire_actual(ClusterLockAcquireRequest *request) * preserve_request_id is used by X->S: keeping the confirmed X holder key * makes cleanup exact whether the downgrade reply is received or lost. */ static ClusterLockAcquireResult -walr_request_convert_actual(ClusterLockAcquireRequest *request, - uint64 preserve_request_id, +walr_request_convert_actual(ClusterLockAcquireRequest *request, uint64 preserve_request_id, bool *out_cleanup_required) { ClusterLockAcquireResult result; @@ -388,18 +373,16 @@ walr_request_convert_actual(ClusterLockAcquireRequest *request, request->holder.request_id = preserve_request_id; } walr_native_locktag_init((uint16)request->resid.field1, &request->locktag); - native_result = LockAcquire(&request->locktag, request->lockmode, - request->sessionLock, request->dontwait); - if (native_result != LOCKACQUIRE_OK - && native_result != LOCKACQUIRE_ALREADY_HELD) { + native_result = LockAcquire(&request->locktag, request->lockmode, request->sessionLock, + request->dontwait); + if (native_result != LOCKACQUIRE_OK && native_result != LOCKACQUIRE_ALREADY_HELD) { if (native_result == LOCKACQUIRE_ALREADY_CLEAR) walr_native_lock_release_or_fatal(request); return CLUSTER_LOCK_ACQUIRE_NOT_AVAIL; } result = cluster_lock_acquire_s5_promote(request); if (result != CLUSTER_LOCK_ACQUIRE_OK_CONVERTED) { - if (request->lockmode == ExclusiveLock - && result != CLUSTER_LOCK_ACQUIRE_NOT_AVAIL) { + if (request->lockmode == ExclusiveLock && result != CLUSTER_LOCK_ACQUIRE_NOT_AVAIL) { if (out_cleanup_required != NULL) *out_cleanup_required = true; } else @@ -425,51 +408,43 @@ static bool root_token_matches_identity(const ClusterControlRootReadToken *token, const ClusterRecoveryDutyKey *duty) { - uint32 required_flags = CLUSTER_CONTROL_ROOT_FLAG_CLAIM_VALID - | CLUSTER_CONTROL_ROOT_FLAG_CHECKPOINT_VALID; + uint32 required_flags + = CLUSTER_CONTROL_ROOT_FLAG_CLAIM_VALID | CLUSTER_CONTROL_ROOT_FLAG_CHECKPOINT_VALID; - return token != NULL && duty != NULL - && token->origin_thread_id == duty->origin_thread_id - && token->root_lineage_seq == duty->root_lineage_seq - && memcmp(token->authority_uuid, duty->authority_uuid, - sizeof(token->authority_uuid)) == 0 - && token->source != 0 - && token->lifecycle >= CLUSTER_CONTROL_ROOT_LIFECYCLE_OPEN - && token->lifecycle <= CLUSTER_CONTROL_ROOT_LIFECYCLE_RETIRED - && token->reserved20 == 0 && token->reserved32 == 0 - && token->file_txn_seq != 0 && token->root_publish_seq != 0 - && token->record_crc32c != 0 - && (token->root_flags & required_flags) == required_flags - && (token->root_flags & ~CLUSTER_CONTROL_ROOT_FLAGS_V1) == 0; + return token != NULL && duty != NULL && token->origin_thread_id == duty->origin_thread_id + && token->root_lineage_seq == duty->root_lineage_seq + && memcmp(token->authority_uuid, duty->authority_uuid, sizeof(token->authority_uuid)) + == 0 + && token->source != 0 && token->lifecycle >= CLUSTER_CONTROL_ROOT_LIFECYCLE_OPEN + && token->lifecycle <= CLUSTER_CONTROL_ROOT_LIFECYCLE_RETIRED && token->reserved20 == 0 + && token->reserved32 == 0 && token->file_txn_seq != 0 && token->root_publish_seq != 0 + && token->record_crc32c != 0 && (token->root_flags & required_flags) == required_flags + && (token->root_flags & ~CLUSTER_CONTROL_ROOT_FLAGS_V1) == 0; } static bool root_token_matches_recovery_duty(const ClusterControlRootReadToken *token, const ClusterRecoveryDutyKey *duty) { - uint32 required_flags = CLUSTER_CONTROL_ROOT_FLAG_TAIL_VALID - | CLUSTER_CONTROL_ROOT_FLAG_RECOVERED_VALID; + uint32 required_flags + = CLUSTER_CONTROL_ROOT_FLAG_TAIL_VALID | CLUSTER_CONTROL_ROOT_FLAG_RECOVERED_VALID; return root_token_matches_identity(token, duty) - && token->lifecycle - == CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_REQUIRED - && (token->root_flags & required_flags) == required_flags; + && token->lifecycle == CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_REQUIRED + && (token->root_flags & required_flags) == required_flags; } static bool -pin_request_valid(const ClusterWalRetentionPinThreadRequest *request, - int wal_segsz_bytes, Size *total_bytes) +pin_request_valid(const ClusterWalRetentionPinThreadRequest *request, int wal_segsz_bytes, + Size *total_bytes) { uint32 i; Size interval_bytes; - if (request == NULL || request->intervals == NULL - || request->nintervals == 0 + if (request == NULL || request->intervals == NULL || request->nintervals == 0 || !cluster_recovery_duty_key_valid_v1(&request->duty) - || !root_token_matches_recovery_duty( - &request->root_read, &request->duty) - || request->formation == NULL || request->needs == NULL - || request->admissions == NULL + || !root_token_matches_recovery_duty(&request->root_read, &request->duty) + || request->formation == NULL || request->needs == NULL || request->admissions == NULL || request->nintervals > MaxAllocSize / sizeof(*request->intervals)) return false; interval_bytes = (Size)request->nintervals * sizeof(*request->intervals); @@ -483,16 +458,14 @@ pin_request_valid(const ClusterWalRetentionPinThreadRequest *request, XLogSegNo last; if (interval->thread_id != request->duty.origin_thread_id - || !cluster_wal_retention_interval_segment_bounds( - interval, wal_segsz_bytes, &first, &last)) + || !cluster_wal_retention_interval_segment_bounds(interval, wal_segsz_bytes, &first, + &last)) return false; if (i > 0) { - const ClusterWalRetentionInterval *previous = - &request->intervals[i - 1]; + const ClusterWalRetentionInterval *previous = &request->intervals[i - 1]; if (previous->tli > interval->tli - || (previous->tli == interval->tli - && previous->end_lsn >= interval->start_lsn)) + || (previous->tli == interval->tli && previous->end_lsn >= interval->start_lsn)) return false; } } @@ -503,12 +476,10 @@ static bool pin_valid(const ClusterWalRetentionPin *pin) { return pin != NULL && pin == active_pin && pin->magic == CLUSTER_WAL_PIN_MAGIC - && pin->owner_pid == MyProcPid && pin->owner == CurrentResourceOwner - && pin->nthreads > 0 - && pin->nthreads <= CLUSTER_WAL_RETENTION_MAX_THREADS - && pin->threads != NULL - && pin->state >= CLUSTER_WAL_PIN_STATE_ACQUIRED_UNBOUND - && pin->state <= CLUSTER_WAL_PIN_STATE_SEALED; + && pin->owner_pid == MyProcPid && pin->owner == CurrentResourceOwner && pin->nthreads > 0 + && pin->nthreads <= CLUSTER_WAL_RETENTION_MAX_THREADS && pin->threads != NULL + && pin->state >= CLUSTER_WAL_PIN_STATE_ACQUIRED_UNBOUND + && pin->state <= CLUSTER_WAL_PIN_STATE_SEALED; } static void @@ -550,8 +521,7 @@ pin_release_locks(ClusterWalRetentionPin *pin) unconfirmed = true; } } - return unconfirmed ? CLUSTER_WALR_RELEASE_UNCONFIRMED - : CLUSTER_WALR_RELEASE_CONFIRMED; + return unconfirmed ? CLUSTER_WALR_RELEASE_UNCONFIRMED : CLUSTER_WALR_RELEASE_CONFIRMED; } static ClusterWalPinResult @@ -577,40 +547,34 @@ pin_current_after_grants(ClusterWalRetentionPin *pin) ClusterWalPinThread *thread = &pin->threads[i]; ClusterControlRootSnapshot snapshot; ClusterControlRootResult result; - PgracExternalFenceDenyReason reason = - PGRAC_EXTERNAL_FENCE_DENY_NONE; + PgracExternalFenceDenyReason reason = PGRAC_EXTERNAL_FENCE_DENY_NONE; - result = cluster_control_root_revalidate( - &thread->root_read, &thread->duty, &snapshot); + result = cluster_control_root_revalidate(&thread->root_read, &thread->duty, &snapshot); if (!control_root_read_ready(result) - || memcmp(&snapshot.identity, &thread->duty, - sizeof(thread->duty)) != 0 - || snapshot.lifecycle - != CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_REQUIRED + || memcmp(&snapshot.identity, &thread->duty, sizeof(thread->duty)) != 0 + || snapshot.lifecycle != CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_REQUIRED || snapshot.root_flags != thread->root_read.root_flags || cluster_formation_witness_revalidate_nowait(thread->formation) - != CLUSTER_FORMATION_WITNESS_READY - || !cluster_external_fence_need_set_revalidate_nowait( - thread->needs, thread->formation, &reason) - || !cluster_external_fence_revalidate_set_nowait( - thread->admissions, thread->needs, thread->formation, &reason)) + != CLUSTER_FORMATION_WITNESS_READY + || !cluster_external_fence_need_set_revalidate_nowait(thread->needs, thread->formation, + &reason) + || !cluster_external_fence_revalidate_set_nowait(thread->admissions, thread->needs, + thread->formation, &reason)) return CLUSTER_WAL_PIN_STALE; } return CLUSTER_WAL_PIN_OK; } ClusterWalPinResult -cluster_wal_retention_pin_acquire( - const ClusterWalRetentionPinThreadRequest *requests, uint16 nthreads, - ClusterWalRetentionPin **out_pin) +cluster_wal_retention_pin_acquire(const ClusterWalRetentionPinThreadRequest *requests, + uint16 nthreads, ClusterWalRetentionPin **out_pin) { ClusterWalRetentionPin *pin; Size total_bytes; uint16 i; - if (out_pin == NULL || *out_pin != NULL || requests == NULL - || CurrentResourceOwner == NULL || nthreads == 0 - || nthreads > CLUSTER_WAL_RETENTION_MAX_THREADS) + if (out_pin == NULL || *out_pin != NULL || requests == NULL || CurrentResourceOwner == NULL + || nthreads == 0 || nthreads > CLUSTER_WAL_RETENTION_MAX_THREADS) return CLUSTER_WAL_PIN_INVALID; if (active_pin != NULL) return CLUSTER_WAL_PIN_CAPACITY; @@ -621,8 +585,7 @@ cluster_wal_retention_pin_acquire( for (i = 0; i < nthreads; i++) { if (!pin_request_valid(&requests[i], wal_segment_size, &total_bytes) || (i > 0 - && requests[i - 1].duty.origin_thread_id - >= requests[i].duty.origin_thread_id)) + && requests[i - 1].duty.origin_thread_id >= requests[i].duty.origin_thread_id)) return CLUSTER_WAL_PIN_INVALID; } walr_resource_ensure_callback(); @@ -636,8 +599,7 @@ cluster_wal_retention_pin_acquire( pin->state = CLUSTER_WAL_PIN_STATE_ACQUIRED_UNBOUND; for (i = 0; i < nthreads; i++) { ClusterWalPinThread *thread = &pin->threads[i]; - Size bytes = (Size)requests[i].nintervals - * sizeof(*thread->intervals); + Size bytes = (Size)requests[i].nintervals * sizeof(*thread->intervals); thread->intervals = palloc0(bytes); memcpy(thread->intervals, requests[i].intervals, bytes); @@ -655,9 +617,8 @@ cluster_wal_retention_pin_acquire( ClusterLockAcquireResult result; memset(&walr->request, 0, sizeof(walr->request)); - if (!cluster_wal_retention_resid_encode( - pin->threads[i].duty.origin_thread_id, - &walr->request.resid)) + if (!cluster_wal_retention_resid_encode(pin->threads[i].duty.origin_thread_id, + &walr->request.resid)) return pin_fail_after_locks(pin, CLUSTER_WAL_PIN_INVALID, out_pin); walr->request.lockmode = ShareLock; walr->request.op = CLUSTER_LOCK_OP_REQUEST; @@ -665,14 +626,12 @@ cluster_wal_retention_pin_acquire( walr->request.lockmethod_id = DEFAULT_LOCKMETHOD; walr->request.dontwait = true; walr->request.sessionLock = false; - walr->request.caller_local_start_ts_ms = - (uint64)(GetCurrentTimestamp() / 1000); + walr->request.caller_local_start_ts_ms = (uint64)(GetCurrentTimestamp() / 1000); walr->request.timeout_ms = 1; walr->request.wait_event = WAIT_EVENT_CLUSTER_GES_REPLY_WAIT; result = walr_request_acquire_actual(&walr->request); if (result != CLUSTER_LOCK_ACQUIRE_OK_GRANTED) - return pin_fail_after_locks(pin, CLUSTER_WAL_PIN_UNAVAILABLE, - out_pin); + return pin_fail_after_locks(pin, CLUSTER_WAL_PIN_UNAVAILABLE, out_pin); walr->held = true; } if (pin_current_after_grants(pin) != CLUSTER_WAL_PIN_OK) @@ -682,18 +641,14 @@ cluster_wal_retention_pin_acquire( } static bool -serial_matches_thread(ClusterRecoverySerialGuard *serial, - const ClusterWalPinThread *thread) +serial_matches_thread(ClusterRecoverySerialGuard *serial, const ClusterWalPinThread *thread) { return serial != NULL && serial->held && !serial->release_uncertain - && memcmp(&serial->duty, &thread->duty, sizeof(thread->duty)) == 0 - && memcmp(&serial->root_read_token, &thread->root_read, - sizeof(thread->root_read)) == 0 - && serial->formation == thread->formation - && serial->fence_need_set == thread->needs - && serial->fence_admission_set == thread->admissions - && cluster_recovery_serial_revalidate(serial) - == CLUSTER_RECOVERY_SERIAL_CURRENT; + && memcmp(&serial->duty, &thread->duty, sizeof(thread->duty)) == 0 + && memcmp(&serial->root_read_token, &thread->root_read, sizeof(thread->root_read)) == 0 + && serial->formation == thread->formation && serial->fence_need_set == thread->needs + && serial->fence_admission_set == thread->admissions + && cluster_recovery_serial_revalidate(serial) == CLUSTER_RECOVERY_SERIAL_CURRENT; } static ClusterWalPinThread * @@ -717,8 +672,7 @@ cluster_wal_retention_pin_bind_one(ClusterWalRetentionPin *pin, return CLUSTER_WAL_PIN_INVALID; if (pin->poisoned) return CLUSTER_WAL_PIN_RELEASE_UNCERTAIN; - if (pin->state != CLUSTER_WAL_PIN_STATE_ACQUIRED_UNBOUND - || pin->nthreads != 1) + if (pin->state != CLUSTER_WAL_PIN_STATE_ACQUIRED_UNBOUND || pin->nthreads != 1) return CLUSTER_WAL_PIN_INVALID; if (!serial_matches_thread(held_serial, &pin->threads[0])) return CLUSTER_WAL_PIN_STALE; @@ -737,9 +691,8 @@ cluster_wal_retention_pin_bind_set(ClusterWalRetentionPin *pin, return CLUSTER_WAL_PIN_INVALID; if (pin->poisoned) return CLUSTER_WAL_PIN_RELEASE_UNCERTAIN; - if (pin->state != CLUSTER_WAL_PIN_STATE_ACQUIRED_UNBOUND - || pin->nthreads <= 1 || held_set == NULL - || held_set->count != pin->nthreads) + if (pin->state != CLUSTER_WAL_PIN_STATE_ACQUIRED_UNBOUND || pin->nthreads <= 1 + || held_set == NULL || held_set->count != pin->nthreads) return CLUSTER_WAL_PIN_INVALID; for (i = 0; i < pin->nthreads; i++) if (!serial_matches_thread(&held_set->guards[i], &pin->threads[i])) @@ -768,13 +721,11 @@ pin_revalidate_bound(ClusterWalRetentionPin *pin) } ClusterWalPinResult -cluster_wal_retention_pin_preflight_revalidate_wait_v1( - ClusterWalRetentionPin *pin) +cluster_wal_retention_pin_preflight_revalidate_wait_v1(ClusterWalRetentionPin *pin) { ClusterWalPinResult result; - if (!pin_valid(pin) || pin->state != - CLUSTER_WAL_PIN_STATE_ACQUIRED_UNBOUND) + if (!pin_valid(pin) || pin->state != CLUSTER_WAL_PIN_STATE_ACQUIRED_UNBOUND) return CLUSTER_WAL_PIN_INVALID; if (pin->poisoned) return CLUSTER_WAL_PIN_STALE; @@ -815,40 +766,36 @@ pin_root_token_matches_snapshot(const ClusterControlRootReadToken *token, const ClusterControlRootSnapshot *snapshot, const ClusterRecoveryDutyKey *duty) { - return token != NULL && snapshot != NULL && duty != NULL && - memcmp(&snapshot->identity, duty, sizeof(*duty)) == 0 && - memcmp(token->authority_uuid, duty->authority_uuid, 16) == 0 && - token->origin_thread_id == duty->origin_thread_id && - token->source != 0 && token->lifecycle == snapshot->lifecycle && - token->root_lineage_seq == duty->root_lineage_seq && - token->reserved20 == 0 && token->reserved32 == 0 && - token->file_txn_seq != 0 && token->root_publish_seq != 0 && - token->record_crc32c != 0 && token->root_flags == snapshot->root_flags && - (token->root_flags & ~CLUSTER_CONTROL_ROOT_FLAGS_V1) == 0; + return token != NULL && snapshot != NULL && duty != NULL + && memcmp(&snapshot->identity, duty, sizeof(*duty)) == 0 + && memcmp(token->authority_uuid, duty->authority_uuid, 16) == 0 + && token->origin_thread_id == duty->origin_thread_id && token->source != 0 + && token->lifecycle == snapshot->lifecycle + && token->root_lineage_seq == duty->root_lineage_seq && token->reserved20 == 0 + && token->reserved32 == 0 && token->file_txn_seq != 0 && token->root_publish_seq != 0 + && token->record_crc32c != 0 && token->root_flags == snapshot->root_flags + && (token->root_flags & ~CLUSTER_CONTROL_ROOT_FLAGS_V1) == 0; } static bool pin_root_immutable_tuple_equal(const ClusterControlRootSnapshot *left, const ClusterControlRootSnapshot *right) { - return memcmp(&left->identity, &right->identity, - sizeof(left->identity)) == 0 && - left->checkpoint_tli == right->checkpoint_tli && - left->checkpoint_source_kind == right->checkpoint_source_kind && - left->checkpoint_lower_lsn == right->checkpoint_lower_lsn && - left->checkpoint_record_crc32c == right->checkpoint_record_crc32c && - left->tail_tli == right->tail_tli && - left->tail_validation_kind == right->tail_validation_kind && - left->validated_tail_lsn_exclusive == - right->validated_tail_lsn_exclusive && - left->tail_last_record_lsn == right->tail_last_record_lsn && - left->tail_last_record_crc32c == right->tail_last_record_crc32c; + return memcmp(&left->identity, &right->identity, sizeof(left->identity)) == 0 + && left->checkpoint_tli == right->checkpoint_tli + && left->checkpoint_source_kind == right->checkpoint_source_kind + && left->checkpoint_lower_lsn == right->checkpoint_lower_lsn + && left->checkpoint_record_crc32c == right->checkpoint_record_crc32c + && left->tail_tli == right->tail_tli + && left->tail_validation_kind == right->tail_validation_kind + && left->validated_tail_lsn_exclusive == right->validated_tail_lsn_exclusive + && left->tail_last_record_lsn == right->tail_last_record_lsn + && left->tail_last_record_crc32c == right->tail_last_record_crc32c; } ClusterWalPinResult cluster_wal_retention_pin_adopt_root_readback_v1( - ClusterWalRetentionPin *pin, - const ClusterControlRootSnapshot *expected_snapshot, + ClusterWalRetentionPin *pin, const ClusterControlRootSnapshot *expected_snapshot, const ClusterControlRootReadToken *expected_token, const ClusterControlRootSnapshot *observed_snapshot, const ClusterControlRootReadToken *observed_token) @@ -856,37 +803,30 @@ cluster_wal_retention_pin_adopt_root_readback_v1( ClusterWalPinThread *thread; const ClusterWalRetentionInterval *interval; - if (!pin_valid(pin) || expected_snapshot == NULL || expected_token == NULL || - observed_snapshot == NULL || observed_token == NULL) + if (!pin_valid(pin) || expected_snapshot == NULL || expected_token == NULL + || observed_snapshot == NULL || observed_token == NULL) return CLUSTER_WAL_PIN_INVALID; if (pin->poisoned || pin->state != CLUSTER_WAL_PIN_STATE_SEALED) return CLUSTER_WAL_PIN_STALE; thread = pin_find_thread(pin, expected_token->origin_thread_id); - if (thread == NULL || thread->serial == NULL || thread->serial->held || - thread->serial->release_uncertain || thread->nintervals != 1 || - memcmp(&thread->root_read, expected_token, - sizeof(*expected_token)) != 0 || - !pin_root_token_matches_snapshot(expected_token, expected_snapshot, - &thread->duty) || - !pin_root_token_matches_snapshot(observed_token, observed_snapshot, - &thread->duty)) + if (thread == NULL || thread->serial == NULL || thread->serial->held + || thread->serial->release_uncertain || thread->nintervals != 1 + || memcmp(&thread->root_read, expected_token, sizeof(*expected_token)) != 0 + || !pin_root_token_matches_snapshot(expected_token, expected_snapshot, &thread->duty) + || !pin_root_token_matches_snapshot(observed_token, observed_snapshot, &thread->duty)) return CLUSTER_WAL_PIN_STALE; interval = &thread->intervals[0]; - if (expected_snapshot->lifecycle != - CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_REQUIRED || - (observed_snapshot->lifecycle != - CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_REQUIRED && - observed_snapshot->lifecycle != - CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_COMPLETE) || - interval->thread_id != thread->duty.origin_thread_id || - interval->tli != expected_snapshot->checkpoint_tli || - interval->tli != expected_snapshot->tail_tli || - interval->start_lsn != expected_snapshot->checkpoint_lower_lsn || - interval->end_lsn != - expected_snapshot->validated_tail_lsn_exclusive || - !pin_root_immutable_tuple_equal(expected_snapshot, observed_snapshot) || - observed_token->file_txn_seq < expected_token->file_txn_seq || - observed_token->root_publish_seq < expected_token->root_publish_seq) + if (expected_snapshot->lifecycle != CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_REQUIRED + || (observed_snapshot->lifecycle != CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_REQUIRED + && observed_snapshot->lifecycle != CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_COMPLETE) + || interval->thread_id != thread->duty.origin_thread_id + || interval->tli != expected_snapshot->checkpoint_tli + || interval->tli != expected_snapshot->tail_tli + || interval->start_lsn != expected_snapshot->checkpoint_lower_lsn + || interval->end_lsn != expected_snapshot->validated_tail_lsn_exclusive + || !pin_root_immutable_tuple_equal(expected_snapshot, observed_snapshot) + || observed_token->file_txn_seq < expected_token->file_txn_seq + || observed_token->root_publish_seq < expected_token->root_publish_seq) return CLUSTER_WAL_PIN_STALE; thread->root_read = *observed_token; return CLUSTER_WAL_PIN_OK; @@ -929,34 +869,30 @@ walr_share_request_init(uint16 thread_id, ClusterLockAcquireRequest *request) request->lockmethod_id = DEFAULT_LOCKMETHOD; request->dontwait = true; request->sessionLock = false; - request->caller_local_start_ts_ms = - (uint64)(GetCurrentTimestamp() / 1000); + request->caller_local_start_ts_ms = (uint64)(GetCurrentTimestamp() / 1000); request->timeout_ms = 1; request->wait_event = WAIT_EVENT_CLUSTER_GES_REPLY_WAIT; return true; } ClusterWalPinResult -cluster_wal_retention_root_publish_begin_exact( - const ClusterControlRootReadToken *expected_root, bool require_sealed_pin, - ClusterWalRootPublishGuard **out_guard) +cluster_wal_retention_root_publish_begin_exact(const ClusterControlRootReadToken *expected_root, + bool require_sealed_pin, + ClusterWalRootPublishGuard **out_guard) { ClusterWalRootPublishGuard *guard; uint16 thread_id; uint16 i; if (out_guard == NULL || *out_guard != NULL || expected_root == NULL - || CurrentResourceOwner == NULL - || expected_root->origin_thread_id == 0 + || CurrentResourceOwner == NULL || expected_root->origin_thread_id == 0 || expected_root->origin_thread_id > CLUSTER_WAL_RETENTION_MAX_THREADS || expected_root->source == 0 || expected_root->lifecycle < CLUSTER_CONTROL_ROOT_LIFECYCLE_OPEN || expected_root->lifecycle > CLUSTER_CONTROL_ROOT_LIFECYCLE_RETIRED || expected_root->reserved20 != 0 || expected_root->reserved32 != 0 - || expected_root->root_lineage_seq == 0 - || expected_root->file_txn_seq == 0 - || expected_root->root_publish_seq == 0 - || expected_root->record_crc32c == 0 + || expected_root->root_lineage_seq == 0 || expected_root->file_txn_seq == 0 + || expected_root->root_publish_seq == 0 || expected_root->record_crc32c == 0 || (expected_root->root_flags & ~CLUSTER_CONTROL_ROOT_FLAGS_V1) != 0) return CLUSTER_WAL_PIN_INVALID; thread_id = expected_root->origin_thread_id; @@ -979,10 +915,8 @@ cluster_wal_retention_root_publish_begin_exact( if (active_pin->threads[i].duty.origin_thread_id == thread_id) break; if (i == active_pin->nthreads - || memcmp(&active_pin->threads[i].root_read, expected_root, - sizeof(*expected_root)) != 0 - || !active_pin->threads[i].walr.held - || active_pin->threads[i].walr.release_uncertain) { + || memcmp(&active_pin->threads[i].root_read, expected_root, sizeof(*expected_root)) != 0 + || !active_pin->threads[i].walr.held || active_pin->threads[i].walr.release_uncertain) { pfree(guard); return CLUSTER_WAL_PIN_STALE; } @@ -1019,10 +953,8 @@ cluster_wal_retention_root_publish_end(ClusterWalRootPublishGuard **guard) return CLUSTER_WALR_RELEASE_INVALID; if (*guard == NULL) return CLUSTER_WALR_RELEASE_NOT_HELD; - if (*guard != active_root_publish_guard - || (*guard)->magic != CLUSTER_WAL_ROOT_PUBLISH_MAGIC - || (*guard)->owner_pid != MyProcPid - || (*guard)->owner != CurrentResourceOwner) + if (*guard != active_root_publish_guard || (*guard)->magic != CLUSTER_WAL_ROOT_PUBLISH_MAGIC + || (*guard)->owner_pid != MyProcPid || (*guard)->owner != CurrentResourceOwner) return CLUSTER_WALR_RELEASE_INVALID; if (!(*guard)->borrowed_from_pin) { ClusterLockAcquireResult lock_result; @@ -1044,8 +976,8 @@ cluster_wal_retention_root_publish_end(ClusterWalRootPublishGuard **guard) } static void -walr_resource_release_callback(ResourceReleasePhase phase, - bool isCommit, bool isTopLevel, void *arg) +walr_resource_release_callback(ResourceReleasePhase phase, bool isCommit, bool isTopLevel, + void *arg) { (void)isCommit; (void)isTopLevel; @@ -1053,22 +985,19 @@ walr_resource_release_callback(ResourceReleasePhase phase, if (phase != RESOURCE_RELEASE_BEFORE_LOCKS) return; - if (active_reuse_guard != NULL - && active_reuse_guard->owner == CurrentResourceOwner) { + if (active_reuse_guard != NULL && active_reuse_guard->owner == CurrentResourceOwner) { ClusterLockAcquireResult lock_result; ClusterWalPinThread *pin_thread = NULL; if (active_reuse_guard->walr.converted_from_pin) { - pin_thread = pin_find_thread( - active_reuse_guard->pin_or_null, - active_reuse_guard->duty.origin_thread_id); + pin_thread = pin_find_thread(active_reuse_guard->pin_or_null, + active_reuse_guard->duty.origin_thread_id); if (pin_thread == NULL || !pin_thread->walr.held || pin_thread->serial != active_reuse_guard->serial_or_null) elog(FATAL, "lost WALR retained-source holder during action cleanup"); } - lock_result = walr_request_release_actual( - &active_reuse_guard->walr.acquire_request); + lock_result = walr_request_release_actual(&active_reuse_guard->walr.acquire_request); if (lock_result != CLUSTER_LOCK_ACQUIRE_OK_GRANTED) elog(FATAL, "could not confirm WALR action-guard cleanup"); active_reuse_guard->walr.held = false; @@ -1084,12 +1013,10 @@ walr_resource_release_callback(ResourceReleasePhase phase, wal_reuse_guard_close_handles(active_reuse_guard); active_reuse_guard = NULL; } - if (active_e1_context != NULL - && active_e1_context->owner == CurrentResourceOwner) { + if (active_e1_context != NULL && active_e1_context->owner == CurrentResourceOwner) { ClusterLockAcquireResult lock_result; - lock_result = walr_request_release_actual( - &active_e1_context->coarse_walr.acquire_request); + lock_result = walr_request_release_actual(&active_e1_context->coarse_walr.acquire_request); if (lock_result != CLUSTER_LOCK_ACQUIRE_OK_GRANTED) elog(FATAL, "could not confirm coarse WAL-retention cleanup"); active_e1_context->coarse_walr.held = false; @@ -1097,8 +1024,7 @@ walr_resource_release_callback(ResourceReleasePhase phase, explicit_bzero(active_e1_context, sizeof(*active_e1_context)); active_e1_context = NULL; } - if (active_action_context != NULL - && active_action_context->owner == CurrentResourceOwner) { + if (active_action_context != NULL && active_action_context->owner == CurrentResourceOwner) { cluster_formation_witness_destroy(&active_action_context->formation); explicit_bzero(active_action_context, sizeof(*active_action_context)); active_action_context = NULL; @@ -1107,8 +1033,7 @@ walr_resource_release_callback(ResourceReleasePhase phase, && active_root_publish_guard->owner == CurrentResourceOwner) { ClusterWalRootPublishGuard *guard = active_root_publish_guard; - if (cluster_wal_retention_root_publish_end(&guard) - != CLUSTER_WALR_RELEASE_CONFIRMED) + if (cluster_wal_retention_root_publish_end(&guard) != CLUSTER_WALR_RELEASE_CONFIRMED) elog(FATAL, "could not confirm WALR root-publisher cleanup"); } if (active_pin != NULL && active_pin->owner == CurrentResourceOwner) { @@ -1125,18 +1050,15 @@ static bool wal_reuse_guard_valid(const ClusterWalReuseActionGuard *guard) { return guard != NULL && guard->magic == CLUSTER_WAL_REUSE_GUARD_MAGIC - && guard->version == CLUSTER_WAL_REUSE_GUARD_VERSION - && guard->owner_pid == MyProcPid - && guard->self_address == (uintptr_t)guard - && guard->owner == CurrentResourceOwner - && CurrentResourceOwner != NULL - && guard->state <= CLUSTER_WAL_GUARD_BOOKKEPT - && (guard->flags & ~CLUSTER_WAL_GUARD_F_KNOWN_MASK) == 0; + && guard->version == CLUSTER_WAL_REUSE_GUARD_VERSION && guard->owner_pid == MyProcPid + && guard->self_address == (uintptr_t)guard && guard->owner == CurrentResourceOwner + && CurrentResourceOwner != NULL && guard->state <= CLUSTER_WAL_GUARD_BOOKKEPT + && (guard->flags & ~CLUSTER_WAL_GUARD_F_KNOWN_MASK) == 0; } ClusterWalReuseGuardResult cluster_wal_reuse_guard_init(ClusterWalReuseActionGuard *guard, - ClusterWalReuseDenyReason *out_reason) + ClusterWalReuseDenyReason *out_reason) { static const ClusterWalReuseActionGuard zero_guard; @@ -1166,10 +1088,10 @@ wal_reuse_request_has_no_source(const ClusterWalReuseGuardRequest *request) static const ClusterWalFileIdentity zero_file; return request->source_kind == CLUSTER_WAL_INSTALL_SOURCE_NONE - && memcmp(&request->source_carrier, &zero_file, sizeof(zero_file)) == 0 - && request->fork_lsn == InvalidXLogRecPtr - && request->source_coverage_start == InvalidXLogRecPtr - && request->source_coverage_end == InvalidXLogRecPtr; + && memcmp(&request->source_carrier, &zero_file, sizeof(zero_file)) == 0 + && request->fork_lsn == InvalidXLogRecPtr + && request->source_coverage_start == InvalidXLogRecPtr + && request->source_coverage_end == InvalidXLogRecPtr; } static bool @@ -1185,25 +1107,21 @@ wal_reuse_request_source_valid(const ClusterWalReuseGuardRequest *request) return false; segment_end = segment_start + (uint64)wal_segment_size; if (request->entry == CLUSTER_WAL_REUSE_E3_ARCHIVE_END) - return request->source_kind - == CLUSTER_WAL_INSTALL_SOURCE_FORK_COPY_TEMP - && cluster_wal_file_identity_valid(&request->source_carrier, - wal_segment_size) - && request->source_carrier.kind == CLUSTER_WAL_FILE_NORMAL - && request->source_carrier.segno == request->file.segno - && request->source_carrier.tli != request->file.tli - && request->fork_lsn > segment_start - && request->fork_lsn < segment_end - && request->source_coverage_start == segment_start - && request->source_coverage_end == request->fork_lsn; + return request->source_kind == CLUSTER_WAL_INSTALL_SOURCE_FORK_COPY_TEMP + && cluster_wal_file_identity_valid(&request->source_carrier, wal_segment_size) + && request->source_carrier.kind == CLUSTER_WAL_FILE_NORMAL + && request->source_carrier.segno == request->file.segno + && request->source_carrier.tli != request->file.tli + && request->fork_lsn > segment_start && request->fork_lsn < segment_end + && request->source_coverage_start == segment_start + && request->source_coverage_end == request->fork_lsn; if (request->entry == CLUSTER_WAL_REUSE_E6_ARCHIVE_KEEP) return request->source_kind == CLUSTER_WAL_INSTALL_SOURCE_ARCHIVE_STAGE - && memcmp(&request->source_carrier, &request->file, - sizeof(request->file)) == 0 - && request->fork_lsn == InvalidXLogRecPtr - && request->source_coverage_start >= segment_start - && request->source_coverage_start < request->source_coverage_end - && request->source_coverage_end <= segment_end; + && memcmp(&request->source_carrier, &request->file, sizeof(request->file)) == 0 + && request->fork_lsn == InvalidXLogRecPtr + && request->source_coverage_start >= segment_start + && request->source_coverage_start < request->source_coverage_end + && request->source_coverage_end <= segment_end; return false; } @@ -1212,38 +1130,32 @@ wal_reuse_request_shape_valid(const ClusterWalReuseGuardRequest *request) { bool no_source; - if (request == NULL - || !cluster_wal_file_identity_valid(&request->file, wal_segment_size) + if (request == NULL || !cluster_wal_file_identity_valid(&request->file, wal_segment_size) || !cluster_recovery_duty_key_valid_v1(&request->duty) || !root_token_matches_identity(&request->root_read, &request->duty) - || request->file.thread_id != request->duty.origin_thread_id - || request->formation == NULL) + || request->file.thread_id != request->duty.origin_thread_id || request->formation == NULL) return false; no_source = wal_reuse_request_has_no_source(request); switch (request->entry) { - case CLUSTER_WAL_REUSE_E1_CHECKPOINT_RESTARTPOINT: - case CLUSTER_WAL_REUSE_E2_APPLY_TIMELINE_SWITCH: - return request->action - == CLUSTER_WAL_ACTION_RETIRE_RECYCLE_OR_REMOVE - && no_source; - case CLUSTER_WAL_REUSE_E3_ARCHIVE_END: - if (request->action - == CLUSTER_WAL_ACTION_RETIRE_RECYCLE_OR_REMOVE) - return no_source; - return (request->action == CLUSTER_WAL_ACTION_FORCE_REPLACE - || request->action == CLUSTER_WAL_ACTION_CREATE_ABSENT) - && wal_reuse_request_source_valid(request); - case CLUSTER_WAL_REUSE_E4_PARTIAL_RENAME: - return request->action == CLUSTER_WAL_ACTION_RENAME_PARTIAL - && no_source; - case CLUSTER_WAL_REUSE_E6_ARCHIVE_KEEP: - return (request->action == CLUSTER_WAL_ACTION_ARCHIVE_REPLACE - || request->action == CLUSTER_WAL_ACTION_CREATE_ABSENT) - && wal_reuse_request_source_valid(request); - case CLUSTER_WAL_REUSE_E5_RESTORE_STAGING: - case CLUSTER_WAL_REUSE_E7_EXTERNAL_CLEANUP: - default: - return false; + case CLUSTER_WAL_REUSE_E1_CHECKPOINT_RESTARTPOINT: + case CLUSTER_WAL_REUSE_E2_APPLY_TIMELINE_SWITCH: + return request->action == CLUSTER_WAL_ACTION_RETIRE_RECYCLE_OR_REMOVE && no_source; + case CLUSTER_WAL_REUSE_E3_ARCHIVE_END: + if (request->action == CLUSTER_WAL_ACTION_RETIRE_RECYCLE_OR_REMOVE) + return no_source; + return (request->action == CLUSTER_WAL_ACTION_FORCE_REPLACE + || request->action == CLUSTER_WAL_ACTION_CREATE_ABSENT) + && wal_reuse_request_source_valid(request); + case CLUSTER_WAL_REUSE_E4_PARTIAL_RENAME: + return request->action == CLUSTER_WAL_ACTION_RENAME_PARTIAL && no_source; + case CLUSTER_WAL_REUSE_E6_ARCHIVE_KEEP: + return (request->action == CLUSTER_WAL_ACTION_ARCHIVE_REPLACE + || request->action == CLUSTER_WAL_ACTION_CREATE_ABSENT) + && wal_reuse_request_source_valid(request); + case CLUSTER_WAL_REUSE_E5_RESTORE_STAGING: + case CLUSTER_WAL_REUSE_E7_EXTERNAL_CLEANUP: + default: + return false; } } @@ -1252,11 +1164,9 @@ static int64 wal_reuse_stat_mtime_ns(const struct stat *st) { #ifdef __APPLE__ - return (int64)st->st_mtimespec.tv_sec * INT64_C(1000000000) - + st->st_mtimespec.tv_nsec; + return (int64)st->st_mtimespec.tv_sec * INT64_C(1000000000) + st->st_mtimespec.tv_nsec; #else - return (int64)st->st_mtim.tv_sec * INT64_C(1000000000) - + st->st_mtim.tv_nsec; + return (int64)st->st_mtim.tv_sec * INT64_C(1000000000) + st->st_mtim.tv_nsec; #endif } @@ -1264,11 +1174,9 @@ static int64 wal_reuse_stat_ctime_ns(const struct stat *st) { #ifdef __APPLE__ - return (int64)st->st_ctimespec.tv_sec * INT64_C(1000000000) - + st->st_ctimespec.tv_nsec; + return (int64)st->st_ctimespec.tv_sec * INT64_C(1000000000) + st->st_ctimespec.tv_nsec; #else - return (int64)st->st_ctim.tv_sec * INT64_C(1000000000) - + st->st_ctim.tv_nsec; + return (int64)st->st_ctim.tv_sec * INT64_C(1000000000) + st->st_ctim.tv_nsec; #endif } @@ -1276,15 +1184,14 @@ static bool wal_reuse_same_leaf_stat(const struct stat *left, const struct stat *right) { return left->st_dev == right->st_dev && left->st_ino == right->st_ino - && left->st_mode == right->st_mode && left->st_size == right->st_size - && wal_reuse_stat_mtime_ns(left) == wal_reuse_stat_mtime_ns(right) - && wal_reuse_stat_ctime_ns(left) == wal_reuse_stat_ctime_ns(right); + && left->st_mode == right->st_mode && left->st_size == right->st_size + && wal_reuse_stat_mtime_ns(left) == wal_reuse_stat_mtime_ns(right) + && wal_reuse_stat_ctime_ns(left) == wal_reuse_stat_ctime_ns(right); } #endif static bool -wal_reuse_target_basename(const ClusterWalFileIdentity *file, - char *basename, Size basename_size) +wal_reuse_target_basename(const ClusterWalFileIdentity *file, char *basename, Size basename_size) { char normal[XLOG_FNAME_LEN + 1]; int written; @@ -1298,9 +1205,8 @@ wal_reuse_target_basename(const ClusterWalFileIdentity *file, } static bool -wal_reuse_stamp_held_target(const ClusterWalFileIdentity *file, - uint64 system_identifier, int dirfd, int fd, - ClusterWalFileObjectStamp *out_stamp) +wal_reuse_stamp_held_target(const ClusterWalFileIdentity *file, uint64 system_identifier, int dirfd, + int fd, ClusterWalFileObjectStamp *out_stamp) { #ifndef WIN32 char basename[MAXFNAMELEN]; @@ -1320,27 +1226,22 @@ wal_reuse_stamp_held_target(const ClusterWalFileIdentity *file, #else return false; #endif - if (dirfd < 0 || fd < 0 - || !wal_reuse_target_basename(file, basename, sizeof(basename)) - || fstat(dirfd, &dir_stat) != 0 || !S_ISDIR(dir_stat.st_mode) - || fstat(fd, &before) != 0 || !S_ISREG(before.st_mode) - || before.st_size < (off_t)SizeOfXLogLongPHD + if (dirfd < 0 || fd < 0 || !wal_reuse_target_basename(file, basename, sizeof(basename)) + || fstat(dirfd, &dir_stat) != 0 || !S_ISDIR(dir_stat.st_mode) || fstat(fd, &before) != 0 + || !S_ISREG(before.st_mode) || before.st_size < (off_t)SizeOfXLogLongPHD || fstatat(dirfd, basename, &named_before, at_flags) != 0 || !wal_reuse_same_leaf_stat(&before, &named_before) - || pread(fd, header_bytes, sizeof(header_bytes), 0) - != (ssize_t)sizeof(header_bytes) - || fstat(fd, &after) != 0 - || fstatat(dirfd, basename, &named_after, at_flags) != 0 + || pread(fd, header_bytes, sizeof(header_bytes), 0) != (ssize_t)sizeof(header_bytes) + || fstat(fd, &after) != 0 || fstatat(dirfd, basename, &named_after, at_flags) != 0 || !wal_reuse_same_leaf_stat(&before, &after) || !wal_reuse_same_leaf_stat(&after, &named_after) - || !cluster_wal_file_identity_parse(basename, file->thread_id, - wal_segment_size, &parsed) + || !cluster_wal_file_identity_parse(basename, file->thread_id, wal_segment_size, &parsed) || memcmp(&parsed, file, sizeof(parsed)) != 0) return false; memset(&header, 0, sizeof(header)); memcpy(&header, header_bytes, Min(sizeof(header), sizeof(header_bytes))); - if (!cluster_wal_file_long_header_matches( - &parsed, &header, system_identifier, wal_segment_size)) + if (!cluster_wal_file_long_header_matches(&parsed, &header, system_identifier, + wal_segment_size)) return false; out_stamp->platform = CLUSTER_WAL_OBJECT_POSIX; out_stamp->directory_device = (uint64)dir_stat.st_dev; @@ -1365,10 +1266,9 @@ wal_reuse_stamp_held_target(const ClusterWalFileIdentity *file, } static bool -wal_reuse_open_target(const ClusterWalFileIdentity *file, - uint64 system_identifier, - ClusterWalFileObjectStamp *out_stamp, - intptr_t *out_dir_handle, intptr_t *out_handle) +wal_reuse_open_target(const ClusterWalFileIdentity *file, uint64 system_identifier, + ClusterWalFileObjectStamp *out_stamp, intptr_t *out_dir_handle, + intptr_t *out_handle) { #ifndef WIN32 char dirname[32]; @@ -1385,8 +1285,8 @@ wal_reuse_open_target(const ClusterWalFileIdentity *file, return false; cluster_wal_thread_dir_name(file->thread_id, dirname, sizeof(dirname)); if (dirname[0] == '\0' - || snprintf(dirpath, sizeof(dirpath), "%s/%s", cluster_wal_threads_dir, - dirname) >= (int)sizeof(dirpath) + || snprintf(dirpath, sizeof(dirpath), "%s/%s", cluster_wal_threads_dir, dirname) + >= (int)sizeof(dirpath) || !wal_reuse_target_basename(file, basename, sizeof(basename))) return false; #ifdef O_DIRECTORY @@ -1403,8 +1303,7 @@ wal_reuse_open_target(const ClusterWalFileIdentity *file, if (dirfd < 0) return false; fd = openat(dirfd, basename, open_flags); - if (fd < 0 || !wal_reuse_stamp_held_target( - file, system_identifier, dirfd, fd, out_stamp)) { + if (fd < 0 || !wal_reuse_stamp_held_target(file, system_identifier, dirfd, fd, out_stamp)) { if (fd >= 0) close(fd); close(dirfd); @@ -1424,8 +1323,7 @@ wal_reuse_open_target(const ClusterWalFileIdentity *file, } static ClusterWalReuseGuardResult -wal_reuse_preflight_roots(const ClusterWalReuseGuardRequest *request, - ClusterWalRootFold *fold, +wal_reuse_preflight_roots(const ClusterWalReuseGuardRequest *request, ClusterWalRootFold *fold, ClusterControlRootSnapshot *target_root, ClusterWalReuseDenyReason *out_reason) { @@ -1438,17 +1336,17 @@ wal_reuse_preflight_roots(const ClusterWalReuseGuardRequest *request, memset(&formation_snapshot, 0, sizeof(formation_snapshot)); memset(&authority, 0, sizeof(authority)); memset(inputs, 0, sizeof(inputs)); - if (!cluster_formation_witness_copy_classification_v1( - request->formation, &witness_thread, &authority, &formation_snapshot) + if (!cluster_formation_witness_copy_classification_v1(request->formation, &witness_thread, + &authority, &formation_snapshot) || witness_thread != request->duty.origin_thread_id || cluster_formation_witness_revalidate_nowait(request->formation) - != CLUSTER_FORMATION_WITNESS_READY) { + != CLUSTER_FORMATION_WITNESS_READY) { *out_reason = CLUSTER_WAL_DENY_FORMATION_STALE; return CLUSTER_WAL_GUARD_BLOCKED; } for (i = 0; i < CLUSTER_WAL_RETENTION_MAX_THREADS; i++) { - ClusterMembershipState state = - (ClusterMembershipState)formation_snapshot.membership.membership_state[i]; + ClusterMembershipState state + = (ClusterMembershipState)formation_snapshot.membership.membership_state[i]; ClusterControlRootIdentity discovered_identity; ClusterControlRootReadToken token; ClusterControlRootResult result; @@ -1462,23 +1360,22 @@ wal_reuse_preflight_roots(const ClusterWalReuseGuardRequest *request, inputs[i].configured = true; memset(&token, 0, sizeof(token)); if (i + 1 == request->duty.origin_thread_id) { - result = cluster_control_root_read_canonical( - i + 1, &request->duty, CLUSTER_CONTROL_ROOT_READ_STRONG, - &inputs[i].snapshot, &token); + result = cluster_control_root_read_canonical(i + 1, &request->duty, + CLUSTER_CONTROL_ROOT_READ_STRONG, + &inputs[i].snapshot, &token); } else { ClusterControlRootSnapshot bootstrap; result = cluster_control_root_read_canonical( - i + 1, NULL, CLUSTER_CONTROL_ROOT_READ_BOOTSTRAP_VALIDATE, - &bootstrap, NULL); + i + 1, NULL, CLUSTER_CONTROL_ROOT_READ_BOOTSTRAP_VALIDATE, &bootstrap, NULL); if (!control_root_read_ready(result)) { inputs[i].read_result = result; continue; } discovered_identity = bootstrap.identity; - result = cluster_control_root_read_canonical( - i + 1, &discovered_identity, CLUSTER_CONTROL_ROOT_READ_STRONG, - &inputs[i].snapshot, &token); + result = cluster_control_root_read_canonical(i + 1, &discovered_identity, + CLUSTER_CONTROL_ROOT_READ_STRONG, + &inputs[i].snapshot, &token); } inputs[i].read_result = result; if (i + 1 == request->duty.origin_thread_id) { @@ -1498,8 +1395,8 @@ wal_reuse_preflight_roots(const ClusterWalReuseGuardRequest *request, *out_reason = CLUSTER_WAL_DENY_FORMATION_STALE; return CLUSTER_WAL_GUARD_BLOCKED; } - if (!cluster_wal_retention_fold_validated_roots( - inputs, CLUSTER_WAL_RETENTION_MAX_THREADS, wal_segment_size, fold) + if (!cluster_wal_retention_fold_validated_roots(inputs, CLUSTER_WAL_RETENTION_MAX_THREADS, + wal_segment_size, fold) || fold->result == CLUSTER_WAL_FOLD_UNKNOWN) { *out_reason = CLUSTER_WAL_DENY_ROOT_REQUIRED; return CLUSTER_WAL_GUARD_BLOCKED; @@ -1508,26 +1405,23 @@ wal_reuse_preflight_roots(const ClusterWalReuseGuardRequest *request, } ClusterWalReuseGuardResult -cluster_wal_reuse_guard_preflight( - ClusterWalReuseActionGuard *guard, - const ClusterWalReuseGuardRequest *request, - PgracExternalFenceNeedSetV1 **out_needs, - ClusterWalReuseDenyReason *out_reason) +cluster_wal_reuse_guard_preflight(ClusterWalReuseActionGuard *guard, + const ClusterWalReuseGuardRequest *request, + PgracExternalFenceNeedSetV1 **out_needs, + ClusterWalReuseDenyReason *out_reason) { ClusterWalFileObjectStamp target_stamp; ClusterWalRootFold fold; ClusterControlRootSnapshot target_root; PgracExternalFenceNeedSetV1 *needs = NULL; ClusterWalReuseGuardResult result; - PgracExternalFenceDenyReason fence_reason = - PGRAC_EXTERNAL_FENCE_DENY_NONE; + PgracExternalFenceDenyReason fence_reason = PGRAC_EXTERNAL_FENCE_DENY_NONE; uint32 i; if (out_reason == NULL) return CLUSTER_WAL_GUARD_INVALID; *out_reason = CLUSTER_WAL_DENY_NONE; - if (!wal_reuse_guard_valid(guard) - || guard->state != CLUSTER_WAL_GUARD_EMPTY + if (!wal_reuse_guard_valid(guard) || guard->state != CLUSTER_WAL_GUARD_EMPTY || out_needs == NULL || *out_needs != NULL) { *out_reason = CLUSTER_WAL_DENY_GUARD_STATE; return CLUSTER_WAL_GUARD_INVALID; @@ -1540,9 +1434,8 @@ cluster_wal_reuse_guard_preflight( *out_reason = CLUSTER_WAL_DENY_INSTALL_SOURCE_UNPROVEN; return CLUSTER_WAL_GUARD_BLOCKED; } - if (!wal_reuse_open_target( - &request->file, request->duty.system_identifier, &target_stamp, - &guard->source_dir_handle, &guard->source_handle)) { + if (!wal_reuse_open_target(&request->file, request->duty.system_identifier, &target_stamp, + &guard->source_dir_handle, &guard->source_handle)) { *out_reason = CLUSTER_WAL_DENY_OBJECT_STALE; return CLUSTER_WAL_GUARD_BLOCKED; } @@ -1552,22 +1445,19 @@ cluster_wal_reuse_guard_preflight( if (result != CLUSTER_WAL_GUARD_OK) return result; for (i = 0; i < fold.nintervals; i++) - if (cluster_wal_retention_interval_intersects_file( - &fold.intervals[i], &request->file, wal_segment_size)) { + if (cluster_wal_retention_interval_intersects_file(&fold.intervals[i], &request->file, + wal_segment_size)) { *out_reason = CLUSTER_WAL_DENY_ROOT_REQUIRED; return CLUSTER_WAL_GUARD_BLOCKED; } - if (target_root.lifecycle - == CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_REQUIRED) { - if (cluster_external_fence_need_set_build( - &request->duty, request->formation, &needs) - != PGRAC_EXTERNAL_FENCE_NEED_SET_OK - || needs == NULL - || cluster_external_fence_need_set_count(needs) == 0 + if (target_root.lifecycle == CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_REQUIRED) { + if (cluster_external_fence_need_set_build(&request->duty, request->formation, &needs) + != PGRAC_EXTERNAL_FENCE_NEED_SET_OK + || needs == NULL || cluster_external_fence_need_set_count(needs) == 0 || cluster_external_fence_need_set_count(needs) > CLUSTER_MAX_NODES || cluster_external_fence_need_set_digest(needs) == NULL - || !cluster_external_fence_need_set_revalidate_nowait( - needs, request->formation, &fence_reason)) { + || !cluster_external_fence_need_set_revalidate_nowait(needs, request->formation, + &fence_reason)) { if (needs != NULL) cluster_external_fence_need_set_release(&needs); *out_reason = CLUSTER_WAL_DENY_FENCE_UNAVAILABLE; @@ -1593,12 +1483,12 @@ cluster_wal_reuse_guard_preflight( } ClusterWalReuseGuardResult -cluster_wal_reuse_guard_preflight_active_recovery( - ClusterWalReuseActionGuard *guard, - const ClusterWalFileIdentity *file, ClusterWalReuseEntry entry, - ClusterRecoverySerialGuard **out_serial, - ClusterWalRetentionPin **out_pin, - ClusterWalReuseDenyReason *out_reason) +cluster_wal_reuse_guard_preflight_active_recovery(ClusterWalReuseActionGuard *guard, + const ClusterWalFileIdentity *file, + ClusterWalReuseEntry entry, + ClusterRecoverySerialGuard **out_serial, + ClusterWalRetentionPin **out_pin, + ClusterWalReuseDenyReason *out_reason) { ClusterWalPinThread *thread; ClusterWalFileObjectStamp target_stamp; @@ -1607,40 +1497,33 @@ cluster_wal_reuse_guard_preflight_active_recovery( if (out_reason == NULL) return CLUSTER_WAL_GUARD_INVALID; *out_reason = CLUSTER_WAL_DENY_NONE; - if (out_serial == NULL || out_pin == NULL - || *out_serial != NULL || *out_pin != NULL - || !wal_reuse_guard_valid(guard) - || guard->state != CLUSTER_WAL_GUARD_EMPTY - || file == NULL + if (out_serial == NULL || out_pin == NULL || *out_serial != NULL || *out_pin != NULL + || !wal_reuse_guard_valid(guard) || guard->state != CLUSTER_WAL_GUARD_EMPTY || file == NULL || !cluster_wal_file_identity_valid(file, wal_segment_size) - || entry != CLUSTER_WAL_REUSE_E2_APPLY_TIMELINE_SWITCH - || !pin_valid(active_pin) || active_pin->poisoned + || entry != CLUSTER_WAL_REUSE_E2_APPLY_TIMELINE_SWITCH || !pin_valid(active_pin) + || active_pin->poisoned || (active_pin->state != CLUSTER_WAL_PIN_STATE_BOUND_ONE && active_pin->state != CLUSTER_WAL_PIN_STATE_BOUND_SET)) { *out_reason = CLUSTER_WAL_DENY_GUARD_STATE; return CLUSTER_WAL_GUARD_INVALID; } thread = pin_find_thread(active_pin, file->thread_id); - if (thread == NULL || thread->serial == NULL - || thread->formation == NULL || thread->needs == NULL - || thread->admissions == NULL || !thread->walr.held + if (thread == NULL || thread->serial == NULL || thread->formation == NULL + || thread->needs == NULL || thread->admissions == NULL || !thread->walr.held || thread->walr.release_uncertain - || !root_token_matches_recovery_duty( - &thread->root_read, &thread->duty) - || cluster_wal_retention_pin_revalidate(active_pin) - != CLUSTER_WAL_PIN_OK) { + || !root_token_matches_recovery_duty(&thread->root_read, &thread->duty) + || cluster_wal_retention_pin_revalidate(active_pin) != CLUSTER_WAL_PIN_OK) { *out_reason = CLUSTER_WAL_DENY_SERIAL_STALE; return CLUSTER_WAL_GUARD_BLOCKED; } for (i = 0; i < thread->nintervals; i++) - if (cluster_wal_retention_interval_intersects_file( - &thread->intervals[i], file, wal_segment_size)) { + if (cluster_wal_retention_interval_intersects_file(&thread->intervals[i], file, + wal_segment_size)) { *out_reason = CLUSTER_WAL_DENY_ROOT_REQUIRED; return CLUSTER_WAL_GUARD_BLOCKED; } - if (!wal_reuse_open_target( - file, thread->duty.system_identifier, &target_stamp, - &guard->source_dir_handle, &guard->source_handle)) { + if (!wal_reuse_open_target(file, thread->duty.system_identifier, &target_stamp, + &guard->source_dir_handle, &guard->source_handle)) { *out_reason = CLUSTER_WAL_DENY_OBJECT_STALE; return CLUSTER_WAL_GUARD_BLOCKED; } @@ -1662,22 +1545,19 @@ cluster_wal_reuse_guard_preflight_active_recovery( ClusterWalReuseGuardResult cluster_wal_reuse_guard_fence_admitted_nowait( - ClusterWalReuseActionGuard *guard, - const PgracExternalFenceAdmissionSetV1 *admissions_or_null, + ClusterWalReuseActionGuard *guard, const PgracExternalFenceAdmissionSetV1 *admissions_or_null, ClusterWalReuseDenyReason *out_reason) { const PgracExternalFenceWriterSetDigest *need_digest; const PgracExternalFenceWriterSetDigest *admission_digest; - PgracExternalFenceDenyReason fence_reason = - PGRAC_EXTERNAL_FENCE_DENY_NONE; + PgracExternalFenceDenyReason fence_reason = PGRAC_EXTERNAL_FENCE_DENY_NONE; uint32 need_count; uint32 admission_count; if (out_reason == NULL) return CLUSTER_WAL_GUARD_INVALID; *out_reason = CLUSTER_WAL_DENY_NONE; - if (!wal_reuse_guard_valid(guard) - || guard->state != CLUSTER_WAL_GUARD_PREFLIGHTED + if (!wal_reuse_guard_valid(guard) || guard->state != CLUSTER_WAL_GUARD_PREFLIGHTED || guard->formation == NULL) { *out_reason = CLUSTER_WAL_DENY_GUARD_STATE; return CLUSTER_WAL_GUARD_INVALID; @@ -1700,24 +1580,19 @@ cluster_wal_reuse_guard_fence_admitted_nowait( return CLUSTER_WAL_GUARD_BLOCKED; } need_count = cluster_external_fence_need_set_count(guard->needs_or_null); - admission_count = - cluster_external_fence_admission_set_count(admissions_or_null); - need_digest = - cluster_external_fence_need_set_digest(guard->needs_or_null); - admission_digest = - cluster_external_fence_admission_set_digest(admissions_or_null); - if (need_count == 0 || need_count > CLUSTER_MAX_NODES - || admission_count != need_count || need_digest == NULL - || admission_digest == NULL + admission_count = cluster_external_fence_admission_set_count(admissions_or_null); + need_digest = cluster_external_fence_need_set_digest(guard->needs_or_null); + admission_digest = cluster_external_fence_admission_set_digest(admissions_or_null); + if (need_count == 0 || need_count > CLUSTER_MAX_NODES || admission_count != need_count + || need_digest == NULL || admission_digest == NULL || memcmp(need_digest, admission_digest, sizeof(*need_digest)) != 0) { *out_reason = CLUSTER_WAL_DENY_FENCE_UNAVAILABLE; return CLUSTER_WAL_GUARD_BLOCKED; } - if (!cluster_external_fence_need_set_revalidate_nowait( - guard->needs_or_null, guard->formation, &fence_reason) - || !cluster_external_fence_revalidate_set_nowait( - admissions_or_null, guard->needs_or_null, guard->formation, - &fence_reason)) { + if (!cluster_external_fence_need_set_revalidate_nowait(guard->needs_or_null, guard->formation, + &fence_reason) + || !cluster_external_fence_revalidate_set_nowait(admissions_or_null, guard->needs_or_null, + guard->formation, &fence_reason)) { *out_reason = CLUSTER_WAL_DENY_FENCE_STALE; return CLUSTER_WAL_GUARD_BLOCKED; } @@ -1741,36 +1616,31 @@ static bool wal_retention_e1_context_valid(const ClusterWalRetentionE1Context *context) { return context != NULL && context->magic == CLUSTER_WAL_E1_CONTEXT_MAGIC - && context->thread_id > 0 - && context->thread_id <= CLUSTER_WAL_RETENTION_MAX_THREADS - && context->reserved == 0 && context->owner_pid == MyProcPid - && context->owner == CurrentResourceOwner - && context->formation != NULL; + && context->thread_id > 0 && context->thread_id <= CLUSTER_WAL_RETENTION_MAX_THREADS + && context->reserved == 0 && context->owner_pid == MyProcPid + && context->owner == CurrentResourceOwner && context->formation != NULL; } static bool -wal_retention_e1_read_root(ClusterWalRetentionE1Context *context, - bool discover_identity, - ClusterControlRootSnapshot *out_snapshot, - ClusterControlRootReadToken *out_token) +wal_retention_e1_read_root(ClusterWalRetentionE1Context *context, bool discover_identity, + ClusterControlRootSnapshot *out_snapshot, + ClusterControlRootReadToken *out_token) { ClusterControlRootIdentity identity; ClusterControlRootSnapshot bootstrap; ClusterControlRootResult result; if (discover_identity) { - result = cluster_control_root_read_canonical( - context->thread_id, NULL, - CLUSTER_CONTROL_ROOT_READ_BOOTSTRAP_VALIDATE, - &bootstrap, NULL); + result = cluster_control_root_read_canonical(context->thread_id, NULL, + CLUSTER_CONTROL_ROOT_READ_BOOTSTRAP_VALIDATE, + &bootstrap, NULL); if (!control_root_read_ready(result)) return false; identity = bootstrap.identity; } else identity = context->duty; result = cluster_control_root_read_canonical( - context->thread_id, &identity, CLUSTER_CONTROL_ROOT_READ_STRONG, - out_snapshot, out_token); + context->thread_id, &identity, CLUSTER_CONTROL_ROOT_READ_STRONG, out_snapshot, out_token); if (!control_root_read_ready(result) || memcmp(&out_snapshot->identity, &identity, sizeof(identity)) != 0 || !root_token_matches_identity(out_token, &identity)) @@ -1781,10 +1651,10 @@ wal_retention_e1_read_root(ClusterWalRetentionE1Context *context, } ClusterWalReuseGuardResult -cluster_wal_retention_e1_coarse_begin( - ClusterWalRetentionE1Context *context, uint16 thread_id, - ClusterWalRootFoldResult *out_fold_result, XLogSegNo *out_floor_segno, - ClusterWalReuseDenyReason *out_reason) +cluster_wal_retention_e1_coarse_begin(ClusterWalRetentionE1Context *context, uint16 thread_id, + ClusterWalRootFoldResult *out_fold_result, + XLogSegNo *out_floor_segno, + ClusterWalReuseDenyReason *out_reason) { static const ClusterWalRetentionE1Context zero_context; ClusterWalReuseGuardRequest request; @@ -1808,10 +1678,9 @@ cluster_wal_retention_e1_coarse_begin( if (context == NULL || out_fold_result == NULL || out_floor_segno == NULL || CurrentResourceOwner == NULL || thread_id == 0 || thread_id > CLUSTER_WAL_RETENTION_MAX_THREADS - || memcmp(context, &zero_context, sizeof(*context)) != 0 - || active_e1_context != NULL || active_action_context != NULL - || active_reuse_guard != NULL - || active_pin != NULL || active_root_publish_guard != NULL) { + || memcmp(context, &zero_context, sizeof(*context)) != 0 || active_e1_context != NULL + || active_action_context != NULL || active_reuse_guard != NULL || active_pin != NULL + || active_root_publish_guard != NULL) { *out_reason = CLUSTER_WAL_DENY_GUARD_STATE; return CLUSTER_WAL_GUARD_INVALID; } @@ -1828,8 +1697,7 @@ cluster_wal_retention_e1_coarse_begin( } memset(&own_root, 0, sizeof(own_root)); memset(&own_token, 0, sizeof(own_token)); - if (!wal_retention_e1_read_root( - context, true, &own_root, &own_token)) { + if (!wal_retention_e1_read_root(context, true, &own_root, &own_token)) { cluster_formation_witness_destroy(&context->formation); explicit_bzero(context, sizeof(*context)); *out_reason = CLUSTER_WAL_DENY_ROOT_UNAVAILABLE; @@ -1849,8 +1717,7 @@ cluster_wal_retention_e1_coarse_begin( lock_request.lockmethod_id = DEFAULT_LOCKMETHOD; lock_request.dontwait = true; lock_request.sessionLock = false; - lock_request.caller_local_start_ts_ms = - (uint64)(GetCurrentTimestamp() / 1000); + lock_request.caller_local_start_ts_ms = (uint64)(GetCurrentTimestamp() / 1000); lock_request.timeout_ms = 1; lock_request.wait_event = WAIT_EVENT_CLUSTER_GES_REPLY_WAIT; walr_resource_ensure_callback(); @@ -1876,10 +1743,8 @@ cluster_wal_retention_e1_coarse_begin( request.formation = context->formation; memset(&fold, 0, sizeof(fold)); memset(&target_root, 0, sizeof(target_root)); - result = wal_reuse_preflight_roots( - &request, &fold, &target_root, out_reason); - if (result == CLUSTER_WAL_GUARD_OK - && fold.result == CLUSTER_WAL_FOLD_BOUNDED + result = wal_reuse_preflight_roots(&request, &fold, &target_root, out_reason); + if (result == CLUSTER_WAL_GUARD_OK && fold.result == CLUSTER_WAL_FOLD_BOUNDED && fold.floor_by_thread[thread_id - 1] == 0) { *out_reason = CLUSTER_WAL_DENY_ROOT_REQUIRED; result = CLUSTER_WAL_GUARD_BLOCKED; @@ -1902,9 +1767,8 @@ cluster_wal_retention_e1_coarse_begin( } ClusterWalrReleaseResult -cluster_wal_retention_e1_coarse_release( - ClusterWalRetentionE1Context *context, - ClusterWalReuseDenyReason *out_reason) +cluster_wal_retention_e1_coarse_release(ClusterWalRetentionE1Context *context, + ClusterWalReuseDenyReason *out_reason) { ClusterLockAcquireResult lock_result; uint64 now_us; @@ -1913,13 +1777,12 @@ cluster_wal_retention_e1_coarse_release( return CLUSTER_WALR_RELEASE_INVALID; *out_reason = CLUSTER_WAL_DENY_NONE; if (!wal_retention_e1_context_valid(context) - || context->state != CLUSTER_WAL_E1_STATE_COARSE_HELD - || active_e1_context != context || !context->coarse_walr.held) { + || context->state != CLUSTER_WAL_E1_STATE_COARSE_HELD || active_e1_context != context + || !context->coarse_walr.held) { *out_reason = CLUSTER_WAL_DENY_GUARD_STATE; return CLUSTER_WALR_RELEASE_INVALID; } - lock_result = walr_request_release_actual( - &context->coarse_walr.acquire_request); + lock_result = walr_request_release_actual(&context->coarse_walr.acquire_request); if (lock_result != CLUSTER_LOCK_ACQUIRE_OK_GRANTED) { context->coarse_walr.release_uncertain = true; *out_reason = CLUSTER_WAL_DENY_RELEASE_UNCERTAIN; @@ -1928,19 +1791,17 @@ cluster_wal_retention_e1_coarse_release( context->coarse_walr.held = false; context->coarse_walr.coordinated = false; context->coarse_walr.mode = NoLock; - memset(&context->coarse_walr.acquire_request, 0, - sizeof(context->coarse_walr.acquire_request)); + memset(&context->coarse_walr.acquire_request, 0, sizeof(context->coarse_walr.acquire_request)); active_e1_context = NULL; context->state = CLUSTER_WAL_E1_STATE_FILES; now_us = wal_retention_monotonic_us(); if (now_us == 0 - || now_us > UINT64_MAX - - (uint64)CLUSTER_WAL_REUSE_FENCE_TIMEOUT_MS * UINT64_C(1000)) { + || now_us > UINT64_MAX - (uint64)CLUSTER_WAL_REUSE_FENCE_TIMEOUT_MS * UINT64_C(1000)) { *out_reason = CLUSTER_WAL_DENY_FENCE_UNAVAILABLE; return CLUSTER_WALR_RELEASE_INVALID; } - context->provider_deadline_us = now_us - + (uint64)CLUSTER_WAL_REUSE_FENCE_TIMEOUT_MS * UINT64_C(1000); + context->provider_deadline_us + = now_us + (uint64)CLUSTER_WAL_REUSE_FENCE_TIMEOUT_MS * UINT64_C(1000); return CLUSTER_WALR_RELEASE_CONFIRMED; } @@ -1951,9 +1812,8 @@ cluster_wal_retention_active_pin_present(void) } ClusterWalReuseGuardResult -cluster_wal_retention_action_begin( - ClusterWalRetentionE1Context *context, uint16 thread_id, - ClusterWalReuseDenyReason *out_reason) +cluster_wal_retention_action_begin(ClusterWalRetentionE1Context *context, uint16 thread_id, + ClusterWalReuseDenyReason *out_reason) { static const ClusterWalRetentionE1Context zero_context; ClusterControlRootSnapshot own_root; @@ -1966,9 +1826,8 @@ cluster_wal_retention_action_begin( *out_reason = CLUSTER_WAL_DENY_NONE; if (context == NULL || CurrentResourceOwner == NULL || thread_id == 0 || thread_id > CLUSTER_WAL_RETENTION_MAX_THREADS - || memcmp(context, &zero_context, sizeof(*context)) != 0 - || active_action_context != NULL || active_e1_context != NULL - || active_reuse_guard != NULL || active_pin != NULL + || memcmp(context, &zero_context, sizeof(*context)) != 0 || active_action_context != NULL + || active_e1_context != NULL || active_reuse_guard != NULL || active_pin != NULL || active_root_publish_guard != NULL) { *out_reason = CLUSTER_WAL_DENY_GUARD_STATE; return CLUSTER_WAL_GUARD_INVALID; @@ -1995,27 +1854,26 @@ cluster_wal_retention_action_begin( } now_us = wal_retention_monotonic_us(); if (now_us == 0 - || now_us > UINT64_MAX - - (uint64)CLUSTER_WAL_REUSE_FENCE_TIMEOUT_MS * UINT64_C(1000)) { + || now_us > UINT64_MAX - (uint64)CLUSTER_WAL_REUSE_FENCE_TIMEOUT_MS * UINT64_C(1000)) { cluster_formation_witness_destroy(&context->formation); explicit_bzero(context, sizeof(*context)); *out_reason = CLUSTER_WAL_DENY_FENCE_UNAVAILABLE; return CLUSTER_WAL_GUARD_BLOCKED; } - context->provider_deadline_us = now_us - + (uint64)CLUSTER_WAL_REUSE_FENCE_TIMEOUT_MS * UINT64_C(1000); + context->provider_deadline_us + = now_us + (uint64)CLUSTER_WAL_REUSE_FENCE_TIMEOUT_MS * UINT64_C(1000); walr_resource_ensure_callback(); active_action_context = context; return CLUSTER_WAL_GUARD_OK; } ClusterWalReuseGuardResult -cluster_wal_retention_action_preflight( - ClusterWalRetentionE1Context *context, - const ClusterWalFileIdentity *file, ClusterWalReuseEntry entry, - ClusterWalReuseActionGuard *guard, - PgracExternalFenceNeedSetV1 **out_needs, - ClusterWalReuseDenyReason *out_reason) +cluster_wal_retention_action_preflight(ClusterWalRetentionE1Context *context, + const ClusterWalFileIdentity *file, + ClusterWalReuseEntry entry, + ClusterWalReuseActionGuard *guard, + PgracExternalFenceNeedSetV1 **out_needs, + ClusterWalReuseDenyReason *out_reason) { ClusterControlRootSnapshot own_root; ClusterControlRootReadToken own_token; @@ -2024,19 +1882,16 @@ cluster_wal_retention_action_preflight( if (out_reason == NULL) return CLUSTER_WAL_GUARD_INVALID; *out_reason = CLUSTER_WAL_DENY_NONE; - if (!wal_retention_e1_context_valid(context) - || active_action_context != context - || context->state != CLUSTER_WAL_E1_STATE_FILES - || context->coarse_walr.held || file == NULL || guard == NULL - || entry != CLUSTER_WAL_REUSE_E2_APPLY_TIMELINE_SWITCH - || out_needs == NULL || *out_needs != NULL) { + if (!wal_retention_e1_context_valid(context) || active_action_context != context + || context->state != CLUSTER_WAL_E1_STATE_FILES || context->coarse_walr.held || file == NULL + || guard == NULL || entry != CLUSTER_WAL_REUSE_E2_APPLY_TIMELINE_SWITCH || out_needs == NULL + || *out_needs != NULL) { *out_reason = CLUSTER_WAL_DENY_GUARD_STATE; return CLUSTER_WAL_GUARD_INVALID; } memset(&own_root, 0, sizeof(own_root)); memset(&own_token, 0, sizeof(own_token)); - if (!wal_retention_e1_read_root( - context, false, &own_root, &own_token)) { + if (!wal_retention_e1_read_root(context, false, &own_root, &own_token)) { *out_reason = CLUSTER_WAL_DENY_ROOT_STALE; return CLUSTER_WAL_GUARD_BLOCKED; } @@ -2048,8 +1903,7 @@ cluster_wal_retention_action_preflight( request.duty = context->duty; request.root_read = context->root_read; request.formation = context->formation; - return cluster_wal_reuse_guard_preflight( - guard, &request, out_needs, out_reason); + return cluster_wal_reuse_guard_preflight(guard, &request, out_needs, out_reason); } void @@ -2057,8 +1911,8 @@ cluster_wal_retention_action_finish(ClusterWalRetentionE1Context *context) { if (context == NULL || context->magic == 0) return; - if (!wal_retention_e1_context_valid(context) - || active_action_context != context || context->coarse_walr.held) + if (!wal_retention_e1_context_valid(context) || active_action_context != context + || context->coarse_walr.held) return; cluster_formation_witness_destroy(&context->formation); explicit_bzero(context, sizeof(*context)); @@ -2066,11 +1920,11 @@ cluster_wal_retention_action_finish(ClusterWalRetentionE1Context *context) } ClusterWalReuseGuardResult -cluster_wal_retention_e1_preflight( - ClusterWalRetentionE1Context *context, - const ClusterWalFileIdentity *file, ClusterWalReuseActionGuard *guard, - PgracExternalFenceNeedSetV1 **out_needs, - ClusterWalReuseDenyReason *out_reason) +cluster_wal_retention_e1_preflight(ClusterWalRetentionE1Context *context, + const ClusterWalFileIdentity *file, + ClusterWalReuseActionGuard *guard, + PgracExternalFenceNeedSetV1 **out_needs, + ClusterWalReuseDenyReason *out_reason) { ClusterControlRootSnapshot own_root; ClusterControlRootReadToken own_token; @@ -2079,17 +1933,15 @@ cluster_wal_retention_e1_preflight( if (out_reason == NULL) return CLUSTER_WAL_GUARD_INVALID; *out_reason = CLUSTER_WAL_DENY_NONE; - if (!wal_retention_e1_context_valid(context) - || context->state != CLUSTER_WAL_E1_STATE_FILES - || context->coarse_walr.held || file == NULL || guard == NULL - || out_needs == NULL || *out_needs != NULL) { + if (!wal_retention_e1_context_valid(context) || context->state != CLUSTER_WAL_E1_STATE_FILES + || context->coarse_walr.held || file == NULL || guard == NULL || out_needs == NULL + || *out_needs != NULL) { *out_reason = CLUSTER_WAL_DENY_GUARD_STATE; return CLUSTER_WAL_GUARD_INVALID; } memset(&own_root, 0, sizeof(own_root)); memset(&own_token, 0, sizeof(own_token)); - if (!wal_retention_e1_read_root( - context, false, &own_root, &own_token)) { + if (!wal_retention_e1_read_root(context, false, &own_root, &own_token)) { *out_reason = CLUSTER_WAL_DENY_ROOT_STALE; return CLUSTER_WAL_GUARD_BLOCKED; } @@ -2101,16 +1953,15 @@ cluster_wal_retention_e1_preflight( request.duty = context->duty; request.root_read = context->root_read; request.formation = context->formation; - return cluster_wal_reuse_guard_preflight( - guard, &request, out_needs, out_reason); + return cluster_wal_reuse_guard_preflight(guard, &request, out_needs, out_reason); } ClusterWalReuseGuardResult -cluster_wal_retention_e1_fence_wait( - ClusterWalRetentionE1Context *context, ClusterWalReuseActionGuard *guard, - PgracExternalFenceNeedSetV1 *needs, - PgracExternalFenceAdmissionSetV1 **out_admissions, - ClusterWalReuseDenyReason *out_reason) +cluster_wal_retention_e1_fence_wait(ClusterWalRetentionE1Context *context, + ClusterWalReuseActionGuard *guard, + PgracExternalFenceNeedSetV1 *needs, + PgracExternalFenceAdmissionSetV1 **out_admissions, + ClusterWalReuseDenyReason *out_reason) { PgracExternalFenceVerdict verdict; uint64 now_us; @@ -2120,16 +1971,14 @@ cluster_wal_retention_e1_fence_wait( if (out_reason == NULL) return CLUSTER_WAL_GUARD_INVALID; *out_reason = CLUSTER_WAL_DENY_NONE; - if (!wal_retention_e1_context_valid(context) - || context->state != CLUSTER_WAL_E1_STATE_FILES - || guard == NULL || out_admissions == NULL - || *out_admissions != NULL || guard->needs_or_null != needs) { + if (!wal_retention_e1_context_valid(context) || context->state != CLUSTER_WAL_E1_STATE_FILES + || guard == NULL || out_admissions == NULL || *out_admissions != NULL + || guard->needs_or_null != needs) { *out_reason = CLUSTER_WAL_DENY_GUARD_STATE; return CLUSTER_WAL_GUARD_INVALID; } if (needs == NULL) - return cluster_wal_reuse_guard_fence_admitted_nowait( - guard, NULL, out_reason); + return cluster_wal_reuse_guard_fence_admitted_nowait(guard, NULL, out_reason); now_us = wal_retention_monotonic_us(); if (now_us == 0 || now_us >= context->provider_deadline_us) { *out_reason = CLUSTER_WAL_DENY_FENCE_UNAVAILABLE; @@ -2137,18 +1986,16 @@ cluster_wal_retention_e1_fence_wait( } remaining_us = context->provider_deadline_us - now_us; timeout_ms = (int)Min((remaining_us + UINT64_C(999)) / UINT64_C(1000), - (uint64)CLUSTER_WAL_REUSE_FENCE_TIMEOUT_MS); + (uint64)CLUSTER_WAL_REUSE_FENCE_TIMEOUT_MS); if (timeout_ms < 1) timeout_ms = 1; - verdict = cluster_external_fence_admit_set_wait( - needs, context->formation, timeout_ms, out_admissions); - if (verdict != PGRAC_EXTERNAL_FENCE_WRITE_EXCLUDED - || *out_admissions == NULL) { + verdict = cluster_external_fence_admit_set_wait(needs, context->formation, timeout_ms, + out_admissions); + if (verdict != PGRAC_EXTERNAL_FENCE_WRITE_EXCLUDED || *out_admissions == NULL) { *out_reason = CLUSTER_WAL_DENY_FENCE_UNAVAILABLE; return CLUSTER_WAL_GUARD_BLOCKED; } - return cluster_wal_reuse_guard_fence_admitted_nowait( - guard, *out_admissions, out_reason); + return cluster_wal_reuse_guard_fence_admitted_nowait(guard, *out_admissions, out_reason); } void @@ -2162,7 +2009,7 @@ cluster_wal_retention_e1_finish(ClusterWalRetentionE1Context *context) return; if (context->coarse_walr.held && cluster_wal_retention_e1_coarse_release(context, &reason) - != CLUSTER_WALR_RELEASE_CONFIRMED) + != CLUSTER_WALR_RELEASE_CONFIRMED) elog(FATAL, "could not confirm coarse WAL-retention release"); cluster_formation_witness_destroy(&context->formation); explicit_bzero(context, sizeof(*context)); @@ -2174,8 +2021,7 @@ wal_reuse_guard_fence_current(const ClusterWalReuseActionGuard *guard, { const PgracExternalFenceWriterSetDigest *need_digest; const PgracExternalFenceWriterSetDigest *admission_digest; - PgracExternalFenceDenyReason fence_reason = - PGRAC_EXTERNAL_FENCE_DENY_NONE; + PgracExternalFenceDenyReason fence_reason = PGRAC_EXTERNAL_FENCE_DENY_NONE; uint32 need_count; uint32 admission_count; @@ -2196,23 +2042,19 @@ wal_reuse_guard_fence_current(const ClusterWalReuseActionGuard *guard, return false; } need_count = cluster_external_fence_need_set_count(guard->needs_or_null); - admission_count = cluster_external_fence_admission_set_count( - guard->admissions_or_null); + admission_count = cluster_external_fence_admission_set_count(guard->admissions_or_null); need_digest = cluster_external_fence_need_set_digest(guard->needs_or_null); - admission_digest = cluster_external_fence_admission_set_digest( - guard->admissions_or_null); - if (need_count == 0 || need_count > CLUSTER_MAX_NODES - || admission_count != need_count || need_digest == NULL - || admission_digest == NULL + admission_digest = cluster_external_fence_admission_set_digest(guard->admissions_or_null); + if (need_count == 0 || need_count > CLUSTER_MAX_NODES || admission_count != need_count + || need_digest == NULL || admission_digest == NULL || memcmp(need_digest, admission_digest, sizeof(*need_digest)) != 0) { *out_reason = CLUSTER_WAL_DENY_FENCE_UNAVAILABLE; return false; } - if (!cluster_external_fence_need_set_revalidate_nowait( - guard->needs_or_null, guard->formation, &fence_reason) + if (!cluster_external_fence_need_set_revalidate_nowait(guard->needs_or_null, guard->formation, + &fence_reason) || !cluster_external_fence_revalidate_set_nowait( - guard->admissions_or_null, guard->needs_or_null, guard->formation, - &fence_reason)) { + guard->admissions_or_null, guard->needs_or_null, guard->formation, &fence_reason)) { *out_reason = CLUSTER_WAL_DENY_FENCE_STALE; return false; } @@ -2220,10 +2062,8 @@ wal_reuse_guard_fence_current(const ClusterWalReuseActionGuard *guard, } static ClusterWalReuseGuardResult -wal_reuse_guard_rollback_x(ClusterWalReuseActionGuard *guard, - ClusterWalReuseGuardResult result, - ClusterWalReuseDenyReason reason, - ClusterWalReuseDenyReason *out_reason) +wal_reuse_guard_rollback_x(ClusterWalReuseActionGuard *guard, ClusterWalReuseGuardResult result, + ClusterWalReuseDenyReason reason, ClusterWalReuseDenyReason *out_reason) { ClusterLockAcquireResult lock_result; @@ -2235,8 +2075,7 @@ wal_reuse_guard_rollback_x(ClusterWalReuseActionGuard *guard, } guard->walr.held = false; guard->walr.coordinated = false; - memset(&guard->walr.acquire_request, 0, - sizeof(guard->walr.acquire_request)); + memset(&guard->walr.acquire_request, 0, sizeof(guard->walr.acquire_request)); memset(&guard->walr.resid, 0, sizeof(guard->walr.resid)); guard->walr.mode = NoLock; guard->state = CLUSTER_WAL_GUARD_FENCE_ADMITTED_OR_NA; @@ -2246,11 +2085,10 @@ wal_reuse_guard_rollback_x(ClusterWalReuseActionGuard *guard, } ClusterWalReuseGuardResult -cluster_wal_reuse_guard_arm( - ClusterWalReuseActionGuard *guard, - ClusterRecoverySerialGuard *held_serial_or_null, - ClusterWalRetentionPin *held_pin_or_null, - ClusterWalReuseDenyReason *out_reason) +cluster_wal_reuse_guard_arm(ClusterWalReuseActionGuard *guard, + ClusterRecoverySerialGuard *held_serial_or_null, + ClusterWalRetentionPin *held_pin_or_null, + ClusterWalReuseDenyReason *out_reason) { ClusterWalReuseGuardRequest request; ClusterWalFileObjectStamp current_stamp; @@ -2264,8 +2102,7 @@ cluster_wal_reuse_guard_arm( if (out_reason == NULL) return CLUSTER_WAL_GUARD_INVALID; *out_reason = CLUSTER_WAL_DENY_NONE; - if (!wal_reuse_guard_valid(guard) - || guard->state != CLUSTER_WAL_GUARD_FENCE_ADMITTED_OR_NA + if (!wal_reuse_guard_valid(guard) || guard->state != CLUSTER_WAL_GUARD_FENCE_ADMITTED_OR_NA || active_reuse_guard != NULL) { *out_reason = CLUSTER_WAL_DENY_GUARD_STATE; return CLUSTER_WAL_GUARD_INVALID; @@ -2279,31 +2116,23 @@ cluster_wal_reuse_guard_arm( ClusterResId expected_resid; bool cleanup_required = false; - thread = pin_find_thread(held_pin_or_null, - guard->duty.origin_thread_id); + thread = pin_find_thread(held_pin_or_null, guard->duty.origin_thread_id); if (thread == NULL || held_pin_or_null->poisoned || (held_pin_or_null->state != CLUSTER_WAL_PIN_STATE_BOUND_ONE && held_pin_or_null->state != CLUSTER_WAL_PIN_STATE_BOUND_SET) - || active_root_publish_guard != NULL - || thread->serial != held_serial_or_null + || active_root_publish_guard != NULL || thread->serial != held_serial_or_null || memcmp(&thread->duty, &guard->duty, sizeof(guard->duty)) != 0 - || memcmp(&thread->root_read, &guard->root_read, - sizeof(guard->root_read)) != 0 - || thread->formation != guard->formation - || thread->needs != guard->needs_or_null + || memcmp(&thread->root_read, &guard->root_read, sizeof(guard->root_read)) != 0 + || thread->formation != guard->formation || thread->needs != guard->needs_or_null || thread->admissions != guard->admissions_or_null || !serial_matches_thread(held_serial_or_null, thread) - || cluster_wal_retention_pin_revalidate(held_pin_or_null) - != CLUSTER_WAL_PIN_OK + || cluster_wal_retention_pin_revalidate(held_pin_or_null) != CLUSTER_WAL_PIN_OK || !thread->walr.held || thread->walr.release_uncertain || thread->walr.request.lockmode != ShareLock - || thread->walr.request.holder.request_id - != thread->walr.request.request_id + || thread->walr.request.holder.request_id != thread->walr.request.request_id || !walr_request_has_native_lock(&thread->walr.request) - || !cluster_wal_retention_resid_encode( - guard->duty.origin_thread_id, &expected_resid) - || memcmp(&thread->walr.request.resid, &expected_resid, - sizeof(expected_resid)) != 0) { + || !cluster_wal_retention_resid_encode(guard->duty.origin_thread_id, &expected_resid) + || memcmp(&thread->walr.request.resid, &expected_resid, sizeof(expected_resid)) != 0) { *out_reason = CLUSTER_WAL_DENY_INVALID_IDENTITY; return CLUSTER_WAL_GUARD_BLOCKED; } @@ -2317,8 +2146,7 @@ cluster_wal_reuse_guard_arm( lock_request.timeout_ms = 1; lock_request.wait_event = WAIT_EVENT_CLUSTER_GES_REPLY_WAIT; walr_resource_ensure_callback(); - lock_result = walr_request_convert_actual( - &lock_request, 0, &cleanup_required); + lock_result = walr_request_convert_actual(&lock_request, 0, &cleanup_required); if (lock_result != CLUSTER_LOCK_ACQUIRE_OK_CONVERTED) { if (cleanup_required) { guard->serial_or_null = held_serial_or_null; @@ -2361,8 +2189,7 @@ cluster_wal_reuse_guard_arm( return CLUSTER_WAL_GUARD_BLOCKED; } memset(&lock_request, 0, sizeof(lock_request)); - if (!cluster_wal_retention_resid_encode( - guard->file.thread_id, &lock_request.resid)) { + if (!cluster_wal_retention_resid_encode(guard->file.thread_id, &lock_request.resid)) { *out_reason = CLUSTER_WAL_DENY_INVALID_IDENTITY; return CLUSTER_WAL_GUARD_INVALID; } @@ -2372,8 +2199,7 @@ cluster_wal_reuse_guard_arm( lock_request.lockmethod_id = DEFAULT_LOCKMETHOD; lock_request.dontwait = true; lock_request.sessionLock = false; - lock_request.caller_local_start_ts_ms = - (uint64)(GetCurrentTimestamp() / 1000); + lock_request.caller_local_start_ts_ms = (uint64)(GetCurrentTimestamp() / 1000); lock_request.timeout_ms = 1; lock_request.wait_event = WAIT_EVENT_CLUSTER_GES_REPLY_WAIT; walr_resource_ensure_callback(); @@ -2391,15 +2217,12 @@ cluster_wal_reuse_guard_arm( guard->state = CLUSTER_WAL_GUARD_WALR_X_HELD; active_reuse_guard = guard; - if (!wal_reuse_stamp_held_target( - &guard->file, guard->duty.system_identifier, - (int)guard->source_dir_handle, (int)guard->source_handle, - ¤t_stamp) - || memcmp(¤t_stamp, &guard->pre_action_stamp, - sizeof(current_stamp)) != 0) - return wal_reuse_guard_rollback_x( - guard, CLUSTER_WAL_GUARD_BLOCKED, CLUSTER_WAL_DENY_OBJECT_STALE, - out_reason); + if (!wal_reuse_stamp_held_target(&guard->file, guard->duty.system_identifier, + (int)guard->source_dir_handle, (int)guard->source_handle, + ¤t_stamp) + || memcmp(¤t_stamp, &guard->pre_action_stamp, sizeof(current_stamp)) != 0) + return wal_reuse_guard_rollback_x(guard, CLUSTER_WAL_GUARD_BLOCKED, + CLUSTER_WAL_DENY_OBJECT_STALE, out_reason); memset(&request, 0, sizeof(request)); request.file = guard->file; request.entry = guard->entry; @@ -2416,45 +2239,42 @@ cluster_wal_reuse_guard_arm( memset(&target_root, 0, sizeof(target_root)); result = wal_reuse_preflight_roots(&request, &fold, &target_root, out_reason); if (result != CLUSTER_WAL_GUARD_OK) - return wal_reuse_guard_rollback_x( - guard, result, *out_reason, out_reason); + return wal_reuse_guard_rollback_x(guard, result, *out_reason, out_reason); for (i = 0; i < fold.nintervals; i++) - if (cluster_wal_retention_interval_intersects_file( - &fold.intervals[i], &guard->file, wal_segment_size)) - return wal_reuse_guard_rollback_x( - guard, CLUSTER_WAL_GUARD_BLOCKED, - CLUSTER_WAL_DENY_ROOT_REQUIRED, out_reason); + if (cluster_wal_retention_interval_intersects_file(&fold.intervals[i], &guard->file, + wal_segment_size)) + return wal_reuse_guard_rollback_x(guard, CLUSTER_WAL_GUARD_BLOCKED, + CLUSTER_WAL_DENY_ROOT_REQUIRED, out_reason); if (!wal_reuse_guard_fence_current(guard, out_reason)) - return wal_reuse_guard_rollback_x( - guard, CLUSTER_WAL_GUARD_BLOCKED, *out_reason, out_reason); + return wal_reuse_guard_rollback_x(guard, CLUSTER_WAL_GUARD_BLOCKED, *out_reason, + out_reason); guard->state = CLUSTER_WAL_GUARD_ARMED; return CLUSTER_WAL_GUARD_OK; } static bool wal_reuse_primary_physical_legal(const ClusterWalReuseActionGuard *guard, - ClusterWalReusePhysicalAction physical) + ClusterWalReusePhysicalAction physical) { switch (guard->action) { - case CLUSTER_WAL_ACTION_RETIRE_RECYCLE_OR_REMOVE: - return physical == CLUSTER_WAL_PHYSICAL_RECYCLE - || physical == CLUSTER_WAL_PHYSICAL_REMOVE; - case CLUSTER_WAL_ACTION_FORCE_REPLACE: - case CLUSTER_WAL_ACTION_ARCHIVE_REPLACE: - return physical == CLUSTER_WAL_PHYSICAL_REPLACE; - case CLUSTER_WAL_ACTION_RENAME_PARTIAL: - return physical == CLUSTER_WAL_PHYSICAL_RENAME_PARTIAL; - case CLUSTER_WAL_ACTION_CREATE_ABSENT: - return physical == CLUSTER_WAL_PHYSICAL_CREATE_ABSENT; - default: - return false; + case CLUSTER_WAL_ACTION_RETIRE_RECYCLE_OR_REMOVE: + return physical == CLUSTER_WAL_PHYSICAL_RECYCLE || physical == CLUSTER_WAL_PHYSICAL_REMOVE; + case CLUSTER_WAL_ACTION_FORCE_REPLACE: + case CLUSTER_WAL_ACTION_ARCHIVE_REPLACE: + return physical == CLUSTER_WAL_PHYSICAL_REPLACE; + case CLUSTER_WAL_ACTION_RENAME_PARTIAL: + return physical == CLUSTER_WAL_PHYSICAL_RENAME_PARTIAL; + case CLUSTER_WAL_ACTION_CREATE_ABSENT: + return physical == CLUSTER_WAL_PHYSICAL_CREATE_ABSENT; + default: + return false; } } ClusterWalReuseGuardResult -cluster_wal_reuse_guard_l3_begin( - ClusterWalReuseActionGuard *guard, ClusterWalReusePhysicalAction physical, - ClusterWalReuseDenyReason *out_reason) +cluster_wal_reuse_guard_l3_begin(ClusterWalReuseActionGuard *guard, + ClusterWalReusePhysicalAction physical, + ClusterWalReuseDenyReason *out_reason) { ClusterWalFileObjectStamp current_stamp; ClusterWalPinThread *pin_thread; @@ -2463,35 +2283,26 @@ cluster_wal_reuse_guard_l3_begin( if (out_reason == NULL) return CLUSTER_WAL_GUARD_INVALID; *out_reason = CLUSTER_WAL_DENY_NONE; - if (!wal_reuse_guard_valid(guard) - || guard->state != CLUSTER_WAL_GUARD_ARMED - || active_reuse_guard != guard || !guard->walr.held - || !guard->walr.coordinated || guard->walr.mode != ExclusiveLock - || guard->walr.release_uncertain + if (!wal_reuse_guard_valid(guard) || guard->state != CLUSTER_WAL_GUARD_ARMED + || active_reuse_guard != guard || !guard->walr.held || !guard->walr.coordinated + || guard->walr.mode != ExclusiveLock || guard->walr.release_uncertain || !root_token_matches_identity(&guard->root_read, &guard->duty)) { *out_reason = CLUSTER_WAL_DENY_GUARD_STATE; return CLUSTER_WAL_GUARD_INVALID; } if (guard->walr.converted_from_pin) { - pin_thread = pin_find_thread(guard->pin_or_null, - guard->duty.origin_thread_id); + pin_thread = pin_find_thread(guard->pin_or_null, guard->duty.origin_thread_id); if (pin_thread == NULL - || (guard->pin_or_null->state - != CLUSTER_WAL_PIN_STATE_BOUND_ONE - && guard->pin_or_null->state - != CLUSTER_WAL_PIN_STATE_BOUND_SET) + || (guard->pin_or_null->state != CLUSTER_WAL_PIN_STATE_BOUND_ONE + && guard->pin_or_null->state != CLUSTER_WAL_PIN_STATE_BOUND_SET) || pin_thread->serial != guard->serial_or_null - || memcmp(&pin_thread->duty, &guard->duty, - sizeof(guard->duty)) != 0 - || memcmp(&pin_thread->root_read, &guard->root_read, - sizeof(guard->root_read)) != 0 + || memcmp(&pin_thread->duty, &guard->duty, sizeof(guard->duty)) != 0 + || memcmp(&pin_thread->root_read, &guard->root_read, sizeof(guard->root_read)) != 0 || pin_thread->formation != guard->formation || pin_thread->needs != guard->needs_or_null - || pin_thread->admissions != guard->admissions_or_null - || !pin_thread->walr.held + || pin_thread->admissions != guard->admissions_or_null || !pin_thread->walr.held || pin_thread->walr.release_uncertain - || cluster_wal_retention_pin_revalidate(guard->pin_or_null) - != CLUSTER_WAL_PIN_OK + || cluster_wal_retention_pin_revalidate(guard->pin_or_null) != CLUSTER_WAL_PIN_OK || !serial_matches_thread(guard->serial_or_null, pin_thread)) { *out_reason = CLUSTER_WAL_DENY_SERIAL_STALE; return CLUSTER_WAL_GUARD_BLOCKED; @@ -2503,25 +2314,21 @@ cluster_wal_reuse_guard_l3_begin( *out_reason = CLUSTER_WAL_DENY_INVALID_IDENTITY; return CLUSTER_WAL_GUARD_INVALID; } - } else if (guard->action - != CLUSTER_WAL_ACTION_RETIRE_RECYCLE_OR_REMOVE - || physical != CLUSTER_WAL_PHYSICAL_REMOVE - || (guard->flags & (CLUSTER_WAL_GUARD_F_PRIMARY_RECYCLE - | CLUSTER_WAL_GUARD_F_PRIMARY_ZERO)) - != (CLUSTER_WAL_GUARD_F_PRIMARY_RECYCLE - | CLUSTER_WAL_GUARD_F_PRIMARY_ZERO) - || (guard->flags & CLUSTER_WAL_GUARD_F_FALLBACK_L3) != 0) { + } else if (guard->action != CLUSTER_WAL_ACTION_RETIRE_RECYCLE_OR_REMOVE + || physical != CLUSTER_WAL_PHYSICAL_REMOVE + || (guard->flags + & (CLUSTER_WAL_GUARD_F_PRIMARY_RECYCLE | CLUSTER_WAL_GUARD_F_PRIMARY_ZERO)) + != (CLUSTER_WAL_GUARD_F_PRIMARY_RECYCLE | CLUSTER_WAL_GUARD_F_PRIMARY_ZERO) + || (guard->flags & CLUSTER_WAL_GUARD_F_FALLBACK_L3) != 0) { *out_reason = CLUSTER_WAL_DENY_GUARD_STATE; return CLUSTER_WAL_GUARD_INVALID; } if (!wal_reuse_guard_fence_current(guard, out_reason)) return CLUSTER_WAL_GUARD_BLOCKED; - if (!wal_reuse_stamp_held_target( - &guard->file, guard->duty.system_identifier, - (int)guard->source_dir_handle, (int)guard->source_handle, - ¤t_stamp) - || memcmp(¤t_stamp, &guard->pre_action_stamp, - sizeof(current_stamp)) != 0) { + if (!wal_reuse_stamp_held_target(&guard->file, guard->duty.system_identifier, + (int)guard->source_dir_handle, (int)guard->source_handle, + ¤t_stamp) + || memcmp(¤t_stamp, &guard->pre_action_stamp, sizeof(current_stamp)) != 0) { *out_reason = CLUSTER_WAL_DENY_OBJECT_STALE; return CLUSTER_WAL_GUARD_BLOCKED; } @@ -2537,25 +2344,26 @@ cluster_wal_reuse_guard_l3_begin( static bool wal_reuse_guard_primary_physical(const ClusterWalReuseActionGuard *guard, - ClusterWalReusePhysicalAction *physical) + ClusterWalReusePhysicalAction *physical) { switch (guard->action) { - case CLUSTER_WAL_ACTION_RETIRE_RECYCLE_OR_REMOVE: - *physical = (guard->flags & CLUSTER_WAL_GUARD_F_PRIMARY_RECYCLE) != 0 - ? CLUSTER_WAL_PHYSICAL_RECYCLE : CLUSTER_WAL_PHYSICAL_REMOVE; - return true; - case CLUSTER_WAL_ACTION_FORCE_REPLACE: - case CLUSTER_WAL_ACTION_ARCHIVE_REPLACE: - *physical = CLUSTER_WAL_PHYSICAL_REPLACE; - return true; - case CLUSTER_WAL_ACTION_RENAME_PARTIAL: - *physical = CLUSTER_WAL_PHYSICAL_RENAME_PARTIAL; - return true; - case CLUSTER_WAL_ACTION_CREATE_ABSENT: - *physical = CLUSTER_WAL_PHYSICAL_CREATE_ABSENT; - return true; - default: - return false; + case CLUSTER_WAL_ACTION_RETIRE_RECYCLE_OR_REMOVE: + *physical = (guard->flags & CLUSTER_WAL_GUARD_F_PRIMARY_RECYCLE) != 0 + ? CLUSTER_WAL_PHYSICAL_RECYCLE + : CLUSTER_WAL_PHYSICAL_REMOVE; + return true; + case CLUSTER_WAL_ACTION_FORCE_REPLACE: + case CLUSTER_WAL_ACTION_ARCHIVE_REPLACE: + *physical = CLUSTER_WAL_PHYSICAL_REPLACE; + return true; + case CLUSTER_WAL_ACTION_RENAME_PARTIAL: + *physical = CLUSTER_WAL_PHYSICAL_RENAME_PARTIAL; + return true; + case CLUSTER_WAL_ACTION_CREATE_ABSENT: + *physical = CLUSTER_WAL_PHYSICAL_CREATE_ABSENT; + return true; + default: + return false; } } @@ -2563,25 +2371,25 @@ static ClusterWalTerminalOutcome wal_reuse_terminal_for_physical(ClusterWalReusePhysicalAction physical) { switch (physical) { - case CLUSTER_WAL_PHYSICAL_REMOVE: - return CLUSTER_WAL_TERMINAL_REMOVED; - case CLUSTER_WAL_PHYSICAL_RECYCLE: - return CLUSTER_WAL_TERMINAL_RECYCLED; - case CLUSTER_WAL_PHYSICAL_REPLACE: - return CLUSTER_WAL_TERMINAL_REPLACED; - case CLUSTER_WAL_PHYSICAL_RENAME_PARTIAL: - return CLUSTER_WAL_TERMINAL_RENAMED_PARTIAL; - case CLUSTER_WAL_PHYSICAL_CREATE_ABSENT: - return CLUSTER_WAL_TERMINAL_CREATED; - default: - return CLUSTER_WAL_TERMINAL_UNCHANGED; + case CLUSTER_WAL_PHYSICAL_REMOVE: + return CLUSTER_WAL_TERMINAL_REMOVED; + case CLUSTER_WAL_PHYSICAL_RECYCLE: + return CLUSTER_WAL_TERMINAL_RECYCLED; + case CLUSTER_WAL_PHYSICAL_REPLACE: + return CLUSTER_WAL_TERMINAL_REPLACED; + case CLUSTER_WAL_PHYSICAL_RENAME_PARTIAL: + return CLUSTER_WAL_TERMINAL_RENAMED_PARTIAL; + case CLUSTER_WAL_PHYSICAL_CREATE_ABSENT: + return CLUSTER_WAL_TERMINAL_CREATED; + default: + return CLUSTER_WAL_TERMINAL_UNCHANGED; } } ClusterWalReuseGuardResult -cluster_wal_reuse_guard_confirm_zero_mutation( - ClusterWalReuseActionGuard *guard, ClusterWalReusePhysicalAction physical, - ClusterWalReuseDenyReason *out_reason) +cluster_wal_reuse_guard_confirm_zero_mutation(ClusterWalReuseActionGuard *guard, + ClusterWalReusePhysicalAction physical, + ClusterWalReuseDenyReason *out_reason) { ClusterWalFileObjectStamp current_stamp; ClusterWalPinThread *pin_thread; @@ -2589,34 +2397,26 @@ cluster_wal_reuse_guard_confirm_zero_mutation( if (out_reason == NULL) return CLUSTER_WAL_GUARD_INVALID; *out_reason = CLUSTER_WAL_DENY_NONE; - if (!wal_reuse_guard_valid(guard) - || guard->state != CLUSTER_WAL_GUARD_ARMED - || active_reuse_guard != guard || !guard->walr.held - || !guard->walr.coordinated || guard->walr.mode != ExclusiveLock - || guard->walr.release_uncertain + if (!wal_reuse_guard_valid(guard) || guard->state != CLUSTER_WAL_GUARD_ARMED + || active_reuse_guard != guard || !guard->walr.held || !guard->walr.coordinated + || guard->walr.mode != ExclusiveLock || guard->walr.release_uncertain || !root_token_matches_identity(&guard->root_read, &guard->duty)) { *out_reason = CLUSTER_WAL_DENY_GUARD_STATE; return CLUSTER_WAL_GUARD_INVALID; } if (guard->walr.converted_from_pin) { - pin_thread = pin_find_thread(guard->pin_or_null, - guard->duty.origin_thread_id); + pin_thread = pin_find_thread(guard->pin_or_null, guard->duty.origin_thread_id); if (pin_thread == NULL - || (guard->pin_or_null->state - != CLUSTER_WAL_PIN_STATE_BOUND_ONE - && guard->pin_or_null->state - != CLUSTER_WAL_PIN_STATE_BOUND_SET) + || (guard->pin_or_null->state != CLUSTER_WAL_PIN_STATE_BOUND_ONE + && guard->pin_or_null->state != CLUSTER_WAL_PIN_STATE_BOUND_SET) || pin_thread->serial != guard->serial_or_null - || memcmp(&pin_thread->duty, &guard->duty, - sizeof(guard->duty)) != 0 - || memcmp(&pin_thread->root_read, &guard->root_read, - sizeof(guard->root_read)) != 0 + || memcmp(&pin_thread->duty, &guard->duty, sizeof(guard->duty)) != 0 + || memcmp(&pin_thread->root_read, &guard->root_read, sizeof(guard->root_read)) != 0 || pin_thread->formation != guard->formation || pin_thread->needs != guard->needs_or_null - || pin_thread->admissions != guard->admissions_or_null - || !pin_thread->walr.held || pin_thread->walr.release_uncertain - || cluster_wal_retention_pin_revalidate(guard->pin_or_null) - != CLUSTER_WAL_PIN_OK + || pin_thread->admissions != guard->admissions_or_null || !pin_thread->walr.held + || pin_thread->walr.release_uncertain + || cluster_wal_retention_pin_revalidate(guard->pin_or_null) != CLUSTER_WAL_PIN_OK || !serial_matches_thread(guard->serial_or_null, pin_thread)) { *out_reason = CLUSTER_WAL_DENY_SERIAL_STALE; return CLUSTER_WAL_GUARD_BLOCKED; @@ -2624,41 +2424,36 @@ cluster_wal_reuse_guard_confirm_zero_mutation( } if (!wal_reuse_guard_fence_current(guard, out_reason)) return CLUSTER_WAL_GUARD_BLOCKED; - if (!wal_reuse_stamp_held_target( - &guard->file, guard->duty.system_identifier, - (int)guard->source_dir_handle, (int)guard->source_handle, - ¤t_stamp) - || memcmp(¤t_stamp, &guard->pre_action_stamp, - sizeof(current_stamp)) != 0) { + if (!wal_reuse_stamp_held_target(&guard->file, guard->duty.system_identifier, + (int)guard->source_dir_handle, (int)guard->source_handle, + ¤t_stamp) + || memcmp(¤t_stamp, &guard->pre_action_stamp, sizeof(current_stamp)) != 0) { *out_reason = CLUSTER_WAL_DENY_OBJECT_STALE; return CLUSTER_WAL_GUARD_BLOCKED; } - return cluster_wal_reuse_guard_note_zero_mutation( - guard, physical, out_reason); + return cluster_wal_reuse_guard_note_zero_mutation(guard, physical, out_reason); } ClusterWalReuseGuardResult -cluster_wal_reuse_guard_note_zero_mutation( - ClusterWalReuseActionGuard *guard, ClusterWalReusePhysicalAction physical, - ClusterWalReuseDenyReason *out_reason) +cluster_wal_reuse_guard_note_zero_mutation(ClusterWalReuseActionGuard *guard, + ClusterWalReusePhysicalAction physical, + ClusterWalReuseDenyReason *out_reason) { ClusterWalReusePhysicalAction expected; if (out_reason == NULL) return CLUSTER_WAL_GUARD_INVALID; *out_reason = CLUSTER_WAL_DENY_NONE; - if (!wal_reuse_guard_valid(guard) - || guard->state != CLUSTER_WAL_GUARD_ARMED + if (!wal_reuse_guard_valid(guard) || guard->state != CLUSTER_WAL_GUARD_ARMED || (guard->flags & CLUSTER_WAL_GUARD_F_PRIMARY_L3) == 0) { *out_reason = CLUSTER_WAL_DENY_GUARD_STATE; return CLUSTER_WAL_GUARD_INVALID; } if ((guard->flags & CLUSTER_WAL_GUARD_F_FALLBACK_L3) != 0) { if (physical != CLUSTER_WAL_PHYSICAL_REMOVE - || (guard->flags & (CLUSTER_WAL_GUARD_F_PRIMARY_RECYCLE - | CLUSTER_WAL_GUARD_F_PRIMARY_ZERO)) - != (CLUSTER_WAL_GUARD_F_PRIMARY_RECYCLE - | CLUSTER_WAL_GUARD_F_PRIMARY_ZERO) + || (guard->flags + & (CLUSTER_WAL_GUARD_F_PRIMARY_RECYCLE | CLUSTER_WAL_GUARD_F_PRIMARY_ZERO)) + != (CLUSTER_WAL_GUARD_F_PRIMARY_RECYCLE | CLUSTER_WAL_GUARD_F_PRIMARY_ZERO) || (guard->flags & CLUSTER_WAL_GUARD_F_FALLBACK_ZERO) != 0) { *out_reason = CLUSTER_WAL_DENY_GUARD_STATE; return CLUSTER_WAL_GUARD_INVALID; @@ -2667,8 +2462,7 @@ cluster_wal_reuse_guard_note_zero_mutation( return CLUSTER_WAL_GUARD_OK; } if ((guard->flags & CLUSTER_WAL_GUARD_F_PRIMARY_ZERO) != 0 - || !wal_reuse_guard_primary_physical(guard, &expected) - || physical != expected) { + || !wal_reuse_guard_primary_physical(guard, &expected) || physical != expected) { *out_reason = CLUSTER_WAL_DENY_GUARD_STATE; return CLUSTER_WAL_GUARD_INVALID; } @@ -2677,9 +2471,9 @@ cluster_wal_reuse_guard_note_zero_mutation( } ClusterWalReuseGuardResult -cluster_wal_reuse_guard_terminal_durable( - ClusterWalReuseActionGuard *guard, ClusterWalTerminalOutcome outcome, - ClusterWalReuseDenyReason *out_reason) +cluster_wal_reuse_guard_terminal_durable(ClusterWalReuseActionGuard *guard, + ClusterWalTerminalOutcome outcome, + ClusterWalReuseDenyReason *out_reason) { ClusterWalReusePhysicalAction physical; ClusterWalTerminalOutcome expected; @@ -2687,8 +2481,7 @@ cluster_wal_reuse_guard_terminal_durable( if (out_reason == NULL) return CLUSTER_WAL_GUARD_INVALID; *out_reason = CLUSTER_WAL_DENY_NONE; - if (!wal_reuse_guard_valid(guard) - || guard->state != CLUSTER_WAL_GUARD_ARMED + if (!wal_reuse_guard_valid(guard) || guard->state != CLUSTER_WAL_GUARD_ARMED || (guard->flags & CLUSTER_WAL_GUARD_F_PRIMARY_L3) == 0) { *out_reason = CLUSTER_WAL_DENY_GUARD_STATE; return CLUSTER_WAL_GUARD_INVALID; @@ -2732,10 +2525,8 @@ cluster_wal_reuse_guard_remove(ClusterWalReuseActionGuard *guard, if (out_reason == NULL) return CLUSTER_WAL_GUARD_INVALID; *out_reason = CLUSTER_WAL_DENY_NONE; - if (!wal_reuse_guard_valid(guard) - || guard->state != CLUSTER_WAL_GUARD_ARMED - || active_reuse_guard != guard || !guard->walr.held - || guard->walr.release_uncertain + if (!wal_reuse_guard_valid(guard) || guard->state != CLUSTER_WAL_GUARD_ARMED + || active_reuse_guard != guard || !guard->walr.held || guard->walr.release_uncertain || (guard->flags & CLUSTER_WAL_GUARD_F_PRIMARY_L3) == 0 /* STOP-05 §15.5: the single recycle-to-remove fallback is the one * legal shape where PRIMARY_ZERO may be set -- the recycle attempt @@ -2756,8 +2547,7 @@ cluster_wal_reuse_guard_remove(ClusterWalReuseActionGuard *guard, return CLUSTER_WAL_GUARD_INVALID; } if (physical != CLUSTER_WAL_PHYSICAL_REMOVE - || !wal_reuse_target_basename( - &guard->file, basename, sizeof(basename))) { + || !wal_reuse_target_basename(&guard->file, basename, sizeof(basename))) { *out_reason = CLUSTER_WAL_DENY_GUARD_STATE; return CLUSTER_WAL_GUARD_INVALID; } @@ -2770,43 +2560,38 @@ cluster_wal_reuse_guard_remove(ClusterWalReuseActionGuard *guard, #endif /* This is the mutation-adjacent identity check. It deliberately uses * the exact preflight handles and performs no pathname reconstruction. */ - if (!wal_reuse_stamp_held_target( - &guard->file, guard->duty.system_identifier, dirfd, - (int)guard->source_handle, ¤t_stamp) - || memcmp(¤t_stamp, &guard->pre_action_stamp, - sizeof(current_stamp)) != 0) { + if (!wal_reuse_stamp_held_target(&guard->file, guard->duty.system_identifier, dirfd, + (int)guard->source_handle, ¤t_stamp) + || memcmp(¤t_stamp, &guard->pre_action_stamp, sizeof(current_stamp)) != 0) { *out_reason = CLUSTER_WAL_DENY_OBJECT_STALE; return CLUSTER_WAL_GUARD_BLOCKED; } if (unlinkat(dirfd, basename, 0) != 0) { - result = cluster_wal_reuse_guard_confirm_zero_mutation( - guard, CLUSTER_WAL_PHYSICAL_REMOVE, out_reason); + result = cluster_wal_reuse_guard_confirm_zero_mutation(guard, CLUSTER_WAL_PHYSICAL_REMOVE, + out_reason); if (result != CLUSTER_WAL_GUARD_OK) return result; *out_reason = CLUSTER_WAL_DENY_OBJECT_STALE; return CLUSTER_WAL_GUARD_BLOCKED; } - if (fsync(dirfd) != 0 - || fstatat(dirfd, basename, &post_action, at_flags) == 0 + if (fsync(dirfd) != 0 || fstatat(dirfd, basename, &post_action, at_flags) == 0 || errno != ENOENT) { *out_reason = CLUSTER_WAL_DENY_RELEASE_UNCERTAIN; return CLUSTER_WAL_GUARD_RELEASE_UNCERTAIN; } - return cluster_wal_reuse_guard_terminal_durable( - guard, CLUSTER_WAL_TERMINAL_REMOVED, out_reason); + return cluster_wal_reuse_guard_terminal_durable(guard, CLUSTER_WAL_TERMINAL_REMOVED, + out_reason); #else if (out_reason != NULL) *out_reason = CLUSTER_WAL_DENY_OBJECT_STALE; - return out_reason == NULL ? CLUSTER_WAL_GUARD_INVALID - : CLUSTER_WAL_GUARD_BLOCKED; + return out_reason == NULL ? CLUSTER_WAL_GUARD_INVALID : CLUSTER_WAL_GUARD_BLOCKED; #endif } ClusterWalReuseGuardResult -cluster_wal_reuse_guard_recycle( - ClusterWalReuseActionGuard *guard, - const ClusterWalFileIdentity *destination, - ClusterWalReuseDenyReason *out_reason) +cluster_wal_reuse_guard_recycle(ClusterWalReuseActionGuard *guard, + const ClusterWalFileIdentity *destination, + ClusterWalReuseDenyReason *out_reason) { #ifndef WIN32 ClusterWalFileObjectStamp current_stamp; @@ -2823,26 +2608,22 @@ cluster_wal_reuse_guard_recycle( if (out_reason == NULL) return CLUSTER_WAL_GUARD_INVALID; *out_reason = CLUSTER_WAL_DENY_NONE; - if (!wal_reuse_guard_valid(guard) - || guard->state != CLUSTER_WAL_GUARD_ARMED - || active_reuse_guard != guard || !guard->walr.held - || guard->walr.release_uncertain + if (!wal_reuse_guard_valid(guard) || guard->state != CLUSTER_WAL_GUARD_ARMED + || active_reuse_guard != guard || !guard->walr.held || guard->walr.release_uncertain || (guard->flags & CLUSTER_WAL_GUARD_F_PRIMARY_L3) == 0 - || (guard->flags & (CLUSTER_WAL_GUARD_F_PRIMARY_ZERO - | CLUSTER_WAL_GUARD_F_FALLBACK_L3 - | CLUSTER_WAL_GUARD_F_FALLBACK_ZERO)) != 0 + || (guard->flags + & (CLUSTER_WAL_GUARD_F_PRIMARY_ZERO | CLUSTER_WAL_GUARD_F_FALLBACK_L3 + | CLUSTER_WAL_GUARD_F_FALLBACK_ZERO)) + != 0 || !wal_reuse_guard_primary_physical(guard, &physical) - || physical != CLUSTER_WAL_PHYSICAL_RECYCLE - || destination == NULL + || physical != CLUSTER_WAL_PHYSICAL_RECYCLE || destination == NULL || !cluster_wal_file_identity_valid(destination, wal_segment_size) || destination->kind != CLUSTER_WAL_FILE_NORMAL || destination->thread_id != guard->file.thread_id || memcmp(destination, &guard->file, sizeof(*destination)) == 0 - || !wal_reuse_target_basename( - &guard->file, source_basename, sizeof(source_basename)) - || !wal_reuse_target_basename( - destination, destination_basename, - sizeof(destination_basename))) { + || !wal_reuse_target_basename(&guard->file, source_basename, sizeof(source_basename)) + || !wal_reuse_target_basename(destination, destination_basename, + sizeof(destination_basename))) { *out_reason = CLUSTER_WAL_DENY_GUARD_STATE; return CLUSTER_WAL_GUARD_INVALID; } @@ -2853,62 +2634,54 @@ cluster_wal_reuse_guard_recycle( *out_reason = CLUSTER_WAL_DENY_OBJECT_STALE; return CLUSTER_WAL_GUARD_BLOCKED; #endif - if (!wal_reuse_stamp_held_target( - &guard->file, guard->duty.system_identifier, dirfd, - (int)guard->source_handle, ¤t_stamp) - || memcmp(¤t_stamp, &guard->pre_action_stamp, - sizeof(current_stamp)) != 0) { + if (!wal_reuse_stamp_held_target(&guard->file, guard->duty.system_identifier, dirfd, + (int)guard->source_handle, ¤t_stamp) + || memcmp(¤t_stamp, &guard->pre_action_stamp, sizeof(current_stamp)) != 0) { *out_reason = CLUSTER_WAL_DENY_OBJECT_STALE; return CLUSTER_WAL_GUARD_BLOCKED; } - stat_result = fstatat( - dirfd, destination_basename, &destination_after, at_flags); + stat_result = fstatat(dirfd, destination_basename, &destination_after, at_flags); if (stat_result == 0 || errno != ENOENT) { - result = cluster_wal_reuse_guard_note_zero_mutation( - guard, CLUSTER_WAL_PHYSICAL_RECYCLE, out_reason); + result = cluster_wal_reuse_guard_note_zero_mutation(guard, CLUSTER_WAL_PHYSICAL_RECYCLE, + out_reason); if (result != CLUSTER_WAL_GUARD_OK) return result; *out_reason = CLUSTER_WAL_DENY_OBJECT_STALE; return CLUSTER_WAL_GUARD_BLOCKED; } if (renameat(dirfd, source_basename, dirfd, destination_basename) != 0) { - result = cluster_wal_reuse_guard_confirm_zero_mutation( - guard, CLUSTER_WAL_PHYSICAL_RECYCLE, out_reason); + result = cluster_wal_reuse_guard_confirm_zero_mutation(guard, CLUSTER_WAL_PHYSICAL_RECYCLE, + out_reason); if (result != CLUSTER_WAL_GUARD_OK) return result; *out_reason = CLUSTER_WAL_DENY_OBJECT_STALE; return CLUSTER_WAL_GUARD_BLOCKED; } - if (fsync(dirfd) != 0 - || fstatat(dirfd, source_basename, &source_after, at_flags) == 0 - || errno != ENOENT - || fstat((int)guard->source_handle, &source_after) != 0 - || fstatat(dirfd, destination_basename, - &destination_after, at_flags) != 0 + if (fsync(dirfd) != 0 || fstatat(dirfd, source_basename, &source_after, at_flags) == 0 + || errno != ENOENT || fstat((int)guard->source_handle, &source_after) != 0 + || fstatat(dirfd, destination_basename, &destination_after, at_flags) != 0 || !wal_reuse_same_leaf_stat(&source_after, &destination_after)) { *out_reason = CLUSTER_WAL_DENY_RELEASE_UNCERTAIN; return CLUSTER_WAL_GUARD_RELEASE_UNCERTAIN; } - return cluster_wal_reuse_guard_terminal_durable( - guard, CLUSTER_WAL_TERMINAL_RECYCLED, out_reason); + return cluster_wal_reuse_guard_terminal_durable(guard, CLUSTER_WAL_TERMINAL_RECYCLED, + out_reason); #else (void)destination; if (out_reason != NULL) *out_reason = CLUSTER_WAL_DENY_OBJECT_STALE; - return out_reason == NULL ? CLUSTER_WAL_GUARD_INVALID - : CLUSTER_WAL_GUARD_BLOCKED; + return out_reason == NULL ? CLUSTER_WAL_GUARD_INVALID : CLUSTER_WAL_GUARD_BLOCKED; #endif } ClusterWalReuseGuardResult cluster_wal_reuse_guard_bookkeep(ClusterWalReuseActionGuard *guard, - ClusterWalReuseDenyReason *out_reason) + ClusterWalReuseDenyReason *out_reason) { if (out_reason == NULL) return CLUSTER_WAL_GUARD_INVALID; *out_reason = CLUSTER_WAL_DENY_NONE; - if (!wal_reuse_guard_valid(guard) - || guard->state != CLUSTER_WAL_GUARD_TERMINAL_DURABLE + if (!wal_reuse_guard_valid(guard) || guard->state != CLUSTER_WAL_GUARD_TERMINAL_DURABLE || guard->outcome == CLUSTER_WAL_TERMINAL_UNCHANGED) { *out_reason = CLUSTER_WAL_DENY_GUARD_STATE; return CLUSTER_WAL_GUARD_INVALID; @@ -2919,8 +2692,8 @@ cluster_wal_reuse_guard_bookkeep(ClusterWalReuseActionGuard *guard, ClusterWalrReleaseResult cluster_wal_reuse_guard_finish(ClusterWalReuseActionGuard *guard, - ClusterWalTerminalOutcome *out_outcome, - ClusterWalReuseDenyReason *out_reason) + ClusterWalTerminalOutcome *out_outcome, + ClusterWalReuseDenyReason *out_reason) { if (out_outcome != NULL) *out_outcome = CLUSTER_WAL_TERMINAL_UNCHANGED; @@ -2968,10 +2741,8 @@ cluster_wal_reuse_guard_finish(ClusterWalReuseActionGuard *guard, ClusterLockAcquireRequest downgrade; bool cleanup_required = false; - thread = pin_find_thread(guard->pin_or_null, - guard->duty.origin_thread_id); - if (thread == NULL || !thread->walr.held - || thread->serial != guard->serial_or_null + thread = pin_find_thread(guard->pin_or_null, guard->duty.origin_thread_id); + if (thread == NULL || !thread->walr.held || thread->serial != guard->serial_or_null || guard->walr.acquire_request.lockmode != ExclusiveLock || guard->walr.mode != ExclusiveLock) { *out_reason = CLUSTER_WAL_DENY_GUARD_STATE; @@ -2984,8 +2755,7 @@ cluster_wal_reuse_guard_finish(ClusterWalReuseActionGuard *guard, downgrade.convert_old_request_id = 0; downgrade.dontwait = true; lock_result = walr_request_convert_actual( - &downgrade, guard->walr.acquire_request.request_id, - &cleanup_required); + &downgrade, guard->walr.acquire_request.request_id, &cleanup_required); if (lock_result != CLUSTER_LOCK_ACQUIRE_OK_CONVERTED) { guard->walr.release_uncertain = true; guard->pin_or_null->poisoned = true; @@ -2996,8 +2766,7 @@ cluster_wal_reuse_guard_finish(ClusterWalReuseActionGuard *guard, /* Drop only the temporary native X and extra S conversion refs; * the pin's original native S remains. The master holder keeps * the confirmed converted request id, now in ShareLock mode. */ - walr_native_lock_release_or_fatal( - &guard->walr.acquire_request); + walr_native_lock_release_or_fatal(&guard->walr.acquire_request); walr_native_lock_release_or_fatal(&downgrade); thread->walr.request = downgrade; thread->walr.held = true; @@ -3008,8 +2777,7 @@ cluster_wal_reuse_guard_finish(ClusterWalReuseActionGuard *guard, explicit_bzero(guard, sizeof(*guard)); return CLUSTER_WALR_RELEASE_CONFIRMED; } - lock_result = walr_request_release_actual( - &guard->walr.acquire_request); + lock_result = walr_request_release_actual(&guard->walr.acquire_request); if (lock_result != CLUSTER_LOCK_ACQUIRE_OK_GRANTED) { guard->walr.release_uncertain = true; *out_reason = CLUSTER_WAL_DENY_RELEASE_UNCERTAIN; @@ -3027,17 +2795,15 @@ cluster_wal_reuse_guard_finish(ClusterWalReuseActionGuard *guard, } bool -cluster_wal_retention_fold_validated_roots(const ClusterWalRootFoldInput *inputs, - uint16 nslots, int wal_segsz_bytes, - ClusterWalRootFold *out_fold) +cluster_wal_retention_fold_validated_roots(const ClusterWalRootFoldInput *inputs, uint16 nslots, + int wal_segsz_bytes, ClusterWalRootFold *out_fold) { uint16 i; if (out_fold == NULL) return false; fold_unknown(out_fold); - if (inputs == NULL || nslots == 0 - || nslots > CLUSTER_WAL_RETENTION_MAX_THREADS + if (inputs == NULL || nslots == 0 || nslots > CLUSTER_WAL_RETENTION_MAX_THREADS || !IsValidWalSegSize(wal_segsz_bytes)) return false; @@ -3050,10 +2816,8 @@ cluster_wal_retention_fold_validated_roots(const ClusterWalRootFoldInput *inputs if (!input->configured) continue; - if (!control_root_read_ready(input->read_result) - || root->identity.origin_thread_id != i + 1 - || root->identity.system_identifier == 0 - || root->identity.root_lineage_seq == 0 + if (!control_root_read_ready(input->read_result) || root->identity.origin_thread_id != i + 1 + || root->identity.system_identifier == 0 || root->identity.root_lineage_seq == 0 || (root->root_flags & ~CLUSTER_CONTROL_ROOT_FLAGS_V1) != 0 || (root->root_flags & CLUSTER_CONTROL_ROOT_FLAG_CLAIM_VALID) == 0) { fold_unknown(out_fold); @@ -3061,47 +2825,43 @@ cluster_wal_retention_fold_validated_roots(const ClusterWalRootFoldInput *inputs } switch (root->lifecycle) { - case CLUSTER_CONTROL_ROOT_LIFECYCLE_OPEN: - case CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_REQUIRED: - if ((root->root_flags & CLUSTER_CONTROL_ROOT_FLAG_CHECKPOINT_VALID) == 0 - || (root->root_flags & CLUSTER_CONTROL_ROOT_FLAG_TAIL_VALID) == 0 - || root->checkpoint_tli == 0 - || root->checkpoint_tli != root->tail_tli - || root->checkpoint_lower_lsn == InvalidXLogRecPtr - || root->validated_tail_lsn_exclusive - < root->checkpoint_lower_lsn) { - fold_unknown(out_fold); - return true; - } - if (root->validated_tail_lsn_exclusive - == root->checkpoint_lower_lsn) - continue; - memset(&interval, 0, sizeof(interval)); - interval.thread_id = i + 1; - interval.tli = root->checkpoint_tli; - interval.start_lsn = root->checkpoint_lower_lsn; - interval.end_lsn = root->validated_tail_lsn_exclusive; - if (!cluster_wal_retention_interval_segment_bounds( - &interval, wal_segsz_bytes, &first, &last) - || out_fold->nintervals - >= CLUSTER_WAL_RETENTION_MAX_THREADS) { - fold_unknown(out_fold); - return true; - } - out_fold->intervals[out_fold->nintervals++] = interval; - out_fold->floor_by_thread[i] = first; - break; - case CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_COMPLETE: - case CLUSTER_CONTROL_ROOT_LIFECYCLE_CLOSED: - case CLUSTER_CONTROL_ROOT_LIFECYCLE_RETIRED: - break; - case CLUSTER_CONTROL_ROOT_LIFECYCLE_UNUSED: - default: + case CLUSTER_CONTROL_ROOT_LIFECYCLE_OPEN: + case CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_REQUIRED: + if ((root->root_flags & CLUSTER_CONTROL_ROOT_FLAG_CHECKPOINT_VALID) == 0 + || (root->root_flags & CLUSTER_CONTROL_ROOT_FLAG_TAIL_VALID) == 0 + || root->checkpoint_tli == 0 || root->checkpoint_tli != root->tail_tli + || root->checkpoint_lower_lsn == InvalidXLogRecPtr + || root->validated_tail_lsn_exclusive < root->checkpoint_lower_lsn) { fold_unknown(out_fold); return true; + } + if (root->validated_tail_lsn_exclusive == root->checkpoint_lower_lsn) + continue; + memset(&interval, 0, sizeof(interval)); + interval.thread_id = i + 1; + interval.tli = root->checkpoint_tli; + interval.start_lsn = root->checkpoint_lower_lsn; + interval.end_lsn = root->validated_tail_lsn_exclusive; + if (!cluster_wal_retention_interval_segment_bounds(&interval, wal_segsz_bytes, &first, + &last) + || out_fold->nintervals >= CLUSTER_WAL_RETENTION_MAX_THREADS) { + fold_unknown(out_fold); + return true; + } + out_fold->intervals[out_fold->nintervals++] = interval; + out_fold->floor_by_thread[i] = first; + break; + case CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_COMPLETE: + case CLUSTER_CONTROL_ROOT_LIFECYCLE_CLOSED: + case CLUSTER_CONTROL_ROOT_LIFECYCLE_RETIRED: + break; + case CLUSTER_CONTROL_ROOT_LIFECYCLE_UNUSED: + default: + fold_unknown(out_fold); + return true; } } - out_fold->result = out_fold->nintervals > 0 ? CLUSTER_WAL_FOLD_BOUNDED - : CLUSTER_WAL_FOLD_UNCONSTRAINED; + out_fold->result + = out_fold->nintervals > 0 ? CLUSTER_WAL_FOLD_BOUNDED : CLUSTER_WAL_FOLD_UNCONSTRAINED; return true; } diff --git a/src/backend/cluster/cluster_wal_state.c b/src/backend/cluster/cluster_wal_state.c index e500c5f0fd3..e0333c95ae5 100644 --- a/src/backend/cluster/cluster_wal_state.c +++ b/src/backend/cluster/cluster_wal_state.c @@ -169,8 +169,8 @@ wal_state_cf_prerequisites_ready(void) { ClusterResId cf_resid; - if (!cluster_controlfile_shared_authority || !cluster_lms_enabled - || !cluster_lms_is_ready() || MyProc == NULL) + if (!cluster_controlfile_shared_authority || !cluster_lms_enabled || !cluster_lms_is_ready() + || MyProc == NULL) return false; cluster_cf_resid_encode(&cf_resid); return cluster_grd_lookup_master(&cf_resid) >= 0; @@ -202,8 +202,7 @@ cluster_wal_state_update_own(const ClusterWalStateUpdate *update, ClusterWalStat ssize_t nbytes; if (update == NULL - || (cf_mode != CLUSTER_WAL_STATE_CF_ACQUIRE_X - && cf_mode != CLUSTER_WAL_STATE_CF_BORROW_X)) + || (cf_mode != CLUSTER_WAL_STATE_CF_ACQUIRE_X && cf_mode != CLUSTER_WAL_STATE_CF_BORROW_X)) return CLUSTER_WAL_STATE_UPDATE_INVALID; if (!cluster_enabled || !registry_configured()) return CLUSTER_WAL_STATE_UPDATE_DISABLED; @@ -275,8 +274,8 @@ cluster_wal_state_update_own(const ClusterWalStateUpdate *update, ClusterWalStat goto out; } - result = cluster_wal_state_slot_prepare_update( - &fresh_before, thread_id, cluster_node_id, update, &expected_after); + result = cluster_wal_state_slot_prepare_update(&fresh_before, thread_id, cluster_node_id, + update, &expected_after); if (result == CLUSTER_WAL_STATE_UPDATE_NOOP) { if (published_slot != NULL) memcpy(published_slot, &fresh_before, sizeof(*published_slot)); @@ -318,8 +317,8 @@ cluster_wal_state_update_own(const ClusterWalStateUpdate *update, ClusterWalStat result = CLUSTER_WAL_STATE_UPDATE_IO_ERROR; goto out; } - result = cluster_wal_state_slot_verify_postread( - &expected_after, &fresh_observed, thread_id, cluster_node_id); + result = cluster_wal_state_slot_verify_postread(&expected_after, &fresh_observed, thread_id, + cluster_node_id); if (result == CLUSTER_WAL_STATE_UPDATE_OK && published_slot != NULL) memcpy(published_slot, &fresh_observed, sizeof(*published_slot)); @@ -337,8 +336,7 @@ cluster_wal_state_update_own(const ClusterWalStateUpdate *update, ClusterWalStat * RELEASE_UNCERTAIN — fail-closed (the caller must not re-acquire * or re-publish on the same token; the slot deliberately stays * held and the next acquire drains it — never a double grant). */ - if (cluster_cf_unlock_confirmed(ExclusiveLock) - == CLUSTER_CF_RELEASE_UNCONFIRMED) + if (cluster_cf_unlock_confirmed(ExclusiveLock) == CLUSTER_CF_RELEASE_UNCONFIRMED) return CLUSTER_WAL_STATE_UPDATE_RELEASE_UNCERTAIN; } return result; @@ -389,20 +387,20 @@ cluster_wal_state_ensure(void) long long actual_size = (long long)st.st_size; (void)close(fd); - ereport(FATAL, (errcode(ERRCODE_CLUSTER_WAL_STATE_IO_FAILURE), - errmsg("WAL state registry \"%s\" is not a regular exact-size file " - "(size %lld, expected %d)", - path, actual_size, CLUSTER_WAL_STATE_FILE_SIZE), - errhint("Restore a known-valid registry while the cluster is fully offline; " - "runtime startup preserves the invalid evidence."))); + ereport(FATAL, + (errcode(ERRCODE_CLUSTER_WAL_STATE_IO_FAILURE), + errmsg("WAL state registry \"%s\" is not a regular exact-size file " + "(size %lld, expected %d)", + path, actual_size, CLUSTER_WAL_STATE_FILE_SIZE), + errhint("Restore a known-valid registry while the cluster is fully offline; " + "runtime startup preserves the invalid evidence."))); } image = palloc0(CLUSTER_WAL_STATE_FILE_SIZE); pgstat_report_wait_start(WAIT_EVENT_CLUSTER_WAL_STATE_READ); for (block = 0; block <= CLUSTER_WAL_STATE_SLOT_COUNT; block++) { off_t offset = (off_t)block * CLUSTER_WAL_STATE_SLOT_SIZE; - ssize_t nread - = pg_pread(fd, image + offset, CLUSTER_WAL_STATE_SLOT_SIZE, offset); + ssize_t nread = pg_pread(fd, image + offset, CLUSTER_WAL_STATE_SLOT_SIZE, offset); if (nread != CLUSTER_WAL_STATE_SLOT_SIZE) { int save_errno = nread < 0 ? errno : EIO; @@ -436,41 +434,39 @@ cluster_wal_state_ensure(void) errdetail("Header validation failed: %s.", reason != NULL ? reason : "unknown"), errhint("Restore a known-valid registry while the cluster is fully " - "offline; runtime startup never deletes, truncates or " - "rebuilds it."))); + "offline; runtime startup never deletes, truncates or " + "rebuilds it."))); else ereport(FATAL, (errcode(ERRCODE_CLUSTER_WAL_STATE_IO_FAILURE), errmsg("WAL state registry \"%s\" failed validation", path), errdetail("Slot %u validation failed: %s.", (unsigned)bad_thread, reason != NULL ? reason : "unknown"), errhint("Restore a known-valid registry while the cluster is fully " - "offline; runtime startup never deletes, truncates or " - "rebuilds it."))); + "offline; runtime startup never deletes, truncates or " + "rebuilds it."))); } own_thread = cluster_wal_thread_id(); memcpy(&own_slot, image + CLUSTER_WAL_STATE_SLOT_OFFSET(own_thread), sizeof(own_slot)); - own_verdict - = cluster_wal_state_slot_classify(&own_slot, own_thread, cluster_node_id, &reason); + own_verdict = cluster_wal_state_slot_classify(&own_slot, own_thread, cluster_node_id, &reason); if (own_verdict != CLUSTER_WAL_SLOT_EMPTY && own_verdict != CLUSTER_WAL_SLOT_OK) { pfree(image); if (own_verdict == CLUSTER_WAL_SLOT_FOREIGN) - ereport(FATAL, - (errcode(ERRCODE_CLUSTER_WAL_STATE_IO_FAILURE), - errmsg("WAL state registry \"%s\" own slot %u failed validation", path, - (unsigned)own_thread), - errdetail("Own-slot validation failed: node_id mismatch " - "(expected %d, found %d).", - cluster_node_id, (int)own_slot.node_id), - errhint("Restore the correct known-valid registry while the cluster is " - "fully offline; foreign ownership evidence is preserved."))); - ereport(FATAL, (errcode(ERRCODE_CLUSTER_WAL_STATE_IO_FAILURE), - errmsg("WAL state registry \"%s\" own slot %u failed validation", path, - (unsigned)own_thread), - errdetail("Own-slot validation failed: %s.", - reason != NULL ? reason : "unknown"), - errhint("Restore the correct known-valid registry while the cluster is " - "fully offline; foreign ownership evidence is preserved."))); + ereport(FATAL, (errcode(ERRCODE_CLUSTER_WAL_STATE_IO_FAILURE), + errmsg("WAL state registry \"%s\" own slot %u failed validation", path, + (unsigned)own_thread), + errdetail("Own-slot validation failed: node_id mismatch " + "(expected %d, found %d).", + cluster_node_id, (int)own_slot.node_id), + errhint("Restore the correct known-valid registry while the cluster is " + "fully offline; foreign ownership evidence is preserved."))); + ereport(FATAL, + (errcode(ERRCODE_CLUSTER_WAL_STATE_IO_FAILURE), + errmsg("WAL state registry \"%s\" own slot %u failed validation", path, + (unsigned)own_thread), + errdetail("Own-slot validation failed: %s.", reason != NULL ? reason : "unknown"), + errhint("Restore the correct known-valid registry while the cluster is " + "fully offline; foreign ownership evidence is preserved."))); } pfree(image); return true; @@ -640,10 +636,8 @@ cluster_wal_state_publish_stopped(void) update.last_updated = (int64)GetCurrentTimestamp(); update.highest_lsn = (uint64)write_ptr; update.highest_scn = (uint64)cluster_scn_current(); - result = cluster_wal_state_update_own( - &update, CLUSTER_WAL_STATE_CF_ACQUIRE_X, NULL); - if (result != CLUSTER_WAL_STATE_UPDATE_OK - && result != CLUSTER_WAL_STATE_UPDATE_NOOP + result = cluster_wal_state_update_own(&update, CLUSTER_WAL_STATE_CF_ACQUIRE_X, NULL); + if (result != CLUSTER_WAL_STATE_UPDATE_OK && result != CLUSTER_WAL_STATE_UPDATE_NOOP && result != CLUSTER_WAL_STATE_UPDATE_DISABLED) ereport(WARNING, (errcode(ERRCODE_CLUSTER_WAL_STATE_IO_FAILURE), errmsg("could not publish STOPPED to the WAL state registry " @@ -651,8 +645,7 @@ cluster_wal_state_publish_stopped(void) (int)result), errhint("The slot stays ACTIVE; recovery readers treat it " "conservatively."))); - return result == CLUSTER_WAL_STATE_UPDATE_OK - || result == CLUSTER_WAL_STATE_UPDATE_NOOP; + return result == CLUSTER_WAL_STATE_UPDATE_OK || result == CLUSTER_WAL_STATE_UPDATE_NOOP; } /* @@ -853,9 +846,7 @@ cluster_wal_state_refresh_fail_count(void) * lockstep anchor for any future ungated site (a regression re-lists it * here + in the script and turns the latch apply self-check RED). */ -static const char *const cluster_wal_state_census_deferred_sites[] = { - NULL -}; +static const char *const cluster_wal_state_census_deferred_sites[] = { NULL }; bool cluster_wal_state_correctness_census_ok(void) diff --git a/src/backend/cluster/cluster_write_fence.c b/src/backend/cluster/cluster_write_fence.c index 08df9b64273..f7ed7991eae 100644 --- a/src/backend/cluster/cluster_write_fence.c +++ b/src/backend/cluster/cluster_write_fence.c @@ -40,13 +40,13 @@ #include "utils/timestamp.h" #include "utils/wait_event.h" /* D4 marker-write + D6 verify wait events */ -#include "cluster/cluster_epoch.h" /* cluster_epoch_get_current */ +#include "cluster/cluster_epoch.h" /* cluster_epoch_get_current */ #include "cluster/cluster_clean_leave.h" -#include "cluster/cluster_guc.h" /* cluster_node_id, cluster_voting_disks */ -#include "cluster/cluster_lmon.h" /* cluster_lmon_marker_complete_wakeup */ -#include "cluster/cluster_qvotec.h" /* ClusterVotingSlot (marker layout asserts) */ -#include "cluster/cluster_shmem.h" /* cluster_shmem_register_region */ -#include "cluster/cluster_write_fence.h" /* region + judge + wrapper + marker */ +#include "cluster/cluster_guc.h" /* cluster_node_id, cluster_voting_disks */ +#include "cluster/cluster_lmon.h" /* cluster_lmon_marker_complete_wakeup */ +#include "cluster/cluster_qvotec.h" /* ClusterVotingSlot (marker layout asserts) */ +#include "cluster/cluster_shmem.h" /* cluster_shmem_register_region */ +#include "cluster/cluster_write_fence.h" /* region + judge + wrapper + marker */ /* * spec-4.12 D1: pin the fence-marker on-disk layout against the voting slot, so a @@ -230,19 +230,17 @@ cluster_write_fence_shmem_register(void) * This generation check prevents a pre-change proof from being published * after the state-changing invalidation that made it stale. */ static bool -cluster_write_fence_cache_write_begin_if_unchanged(uint64 expected_sequence, - uint64 *odd_seq) +cluster_write_fence_cache_write_begin_if_unchanged(uint64 expected_sequence, uint64 *odd_seq) { uint64 expected; if (cluster_write_fence_shmem == NULL || odd_seq == NULL) return false; - if ((expected_sequence & UINT64_C(1)) != 0 - || expected_sequence >= UINT64_MAX - 1) + if ((expected_sequence & UINT64_C(1)) != 0 || expected_sequence >= UINT64_MAX - 1) return false; expected = expected_sequence; - if (!pg_atomic_compare_exchange_u64(&cluster_write_fence_shmem->authority_cache_seq, - &expected, expected_sequence + 1)) + if (!pg_atomic_compare_exchange_u64(&cluster_write_fence_shmem->authority_cache_seq, &expected, + expected_sequence + 1)) return false; *odd_seq = expected_sequence + 1; return true; @@ -296,8 +294,8 @@ cluster_write_fence_authority_cache_sequence(void) bool cluster_write_fence_authority_cache_publish_if_unchanged(const ClusterFenceMarker *marker, - uint64 published_at_us, - uint64 expected_sequence) + uint64 published_at_us, + uint64 expected_sequence) { uint64 odd_seq; @@ -393,9 +391,9 @@ cluster_write_fence_revalidate_cached_nowait(const ClusterFenceMarker *expected, pg_read_barrier(); seq_after = pg_atomic_read_u64(&cluster_write_fence_shmem->authority_cache_seq); if (seq_before == seq_after && (seq_after & UINT64_C(1)) == 0) - return cluster_fence_authority_cache_decide_v1( - expected, seq_before, seq_after, valid, &observed, published_at_us, expiry_us, - now_us); + return cluster_fence_authority_cache_decide_v1(expected, seq_before, seq_after, valid, + &observed, published_at_us, expiry_us, + now_us); } return CLUSTER_FENCE_CACHE_UNAVAILABLE; } @@ -957,8 +955,7 @@ cluster_write_fence_atomic_max(pg_atomic_uint64 *value, uint64 candidate) { uint64 old = pg_atomic_read_u64(value); - while (candidate > old && - !pg_atomic_compare_exchange_u64(value, &old, candidate)) + while (candidate > old && !pg_atomic_compare_exchange_u64(value, &old, candidate)) ; } @@ -970,25 +967,22 @@ cluster_write_fence_note_external_admit_requested(void) } void -cluster_write_fence_note_external_write_excluded(uint64 journal_seq, - uint64 verified_mono_ns) +cluster_write_fence_note_external_write_excluded(uint64 journal_seq, uint64 verified_mono_ns) { if (cluster_write_fence_shmem == NULL) return; pg_atomic_fetch_add_u64(&cluster_write_fence_shmem->external_write_excluded, 1); cluster_write_fence_atomic_max(&cluster_write_fence_shmem->external_last_journal_seq, - journal_seq); - cluster_write_fence_atomic_max( - &cluster_write_fence_shmem->external_last_verified_mono_ns, - verified_mono_ns); + journal_seq); + cluster_write_fence_atomic_max(&cluster_write_fence_shmem->external_last_verified_mono_ns, + verified_mono_ns); } -#define DEFINE_EXTERNAL_COUNTER_NOTE(name) \ - void cluster_write_fence_note_external_##name(void) \ - { \ - if (cluster_write_fence_shmem != NULL) \ - pg_atomic_fetch_add_u64( \ - &cluster_write_fence_shmem->external_##name, 1); \ +#define DEFINE_EXTERNAL_COUNTER_NOTE(name) \ + void cluster_write_fence_note_external_##name(void) \ + { \ + if (cluster_write_fence_shmem != NULL) \ + pg_atomic_fetch_add_u64(&cluster_write_fence_shmem->external_##name, 1); \ } DEFINE_EXTERNAL_COUNTER_NOTE(rejected) @@ -1002,11 +996,12 @@ DEFINE_EXTERNAL_COUNTER_NOTE(publish_gate_blocked) #undef DEFINE_EXTERNAL_COUNTER_NOTE -#define DEFINE_EXTERNAL_COUNTER_GETTER(name) \ - uint64 cluster_write_fence_get_external_##name(void) \ - { \ - return cluster_write_fence_shmem == NULL ? 0 : \ - pg_atomic_read_u64(&cluster_write_fence_shmem->external_##name); \ +#define DEFINE_EXTERNAL_COUNTER_GETTER(name) \ + uint64 cluster_write_fence_get_external_##name(void) \ + { \ + return cluster_write_fence_shmem == NULL \ + ? 0 \ + : pg_atomic_read_u64(&cluster_write_fence_shmem->external_##name); \ } DEFINE_EXTERNAL_COUNTER_GETTER(admit_requested) @@ -1035,12 +1030,10 @@ cluster_write_fence_get_external_last_proof_age_ms(uint64 *age_ms) *age_ms = 0; if (cluster_write_fence_shmem == NULL) return false; - sample = pg_atomic_read_u64( - &cluster_write_fence_shmem->external_last_verified_mono_ns); + sample = pg_atomic_read_u64(&cluster_write_fence_shmem->external_last_verified_mono_ns); if (sample == 0 || clock_gettime(CLOCK_MONOTONIC, &now) != 0) return false; - now_ns = (uint64) now.tv_sec * UINT64_C(1000000000) + - (uint64) now.tv_nsec; + now_ns = (uint64)now.tv_sec * UINT64_C(1000000000) + (uint64)now.tv_nsec; if (now_ns < sample) return false; *age_ms = (now_ns - sample) / UINT64_C(1000000); diff --git a/src/backend/cluster/cluster_xid_stripe_boot.c b/src/backend/cluster/cluster_xid_stripe_boot.c index 9d945904215..37a62df3187 100644 --- a/src/backend/cluster/cluster_xid_stripe_boot.c +++ b/src/backend/cluster/cluster_xid_stripe_boot.c @@ -243,8 +243,7 @@ stripe_read_activation_one(int fd, ClusterXidStripeActivationRecord *out, uint32 /* EOF on a file that has not grown past region 4 yet is the * lazily-materialised empty state, not an I/O failure. */ - if (fstat(fd, &st) == 0 - && (off_t)st.st_size < CLUSTER_VOTING_PGSA_SLOT_OFFSET) + if (fstat(fd, &st) == 0 && (off_t)st.st_size < CLUSTER_VOTING_PGSA_SLOT_OFFSET) return STRIPE_READ_ABSENT; return STRIPE_READ_UNREADABLE; } @@ -988,8 +987,7 @@ cluster_xid_stripe_join_progress(bool self_may_seed) op = StripeBootShmem->op; target = StripeBootShmem->op_target_node; LWLockRelease(&StripeBootShmem->lock); - if (req > done && op == STRIPE_OP_CLAIM - && target == cluster_node_id) + if (req > done && op == STRIPE_OP_CLAIM && target == cluster_node_id) return STRIPE_JOIN_CLAIM_OWNED; return STRIPE_JOIN_WAIT_EVIDENCE; } diff --git a/src/backend/cluster/storage/cluster_shared_fs.c b/src/backend/cluster/storage/cluster_shared_fs.c index 9b780c81a8a..da3b45ff91c 100644 --- a/src/backend/cluster/storage/cluster_shared_fs.c +++ b/src/backend/cluster/storage/cluster_shared_fs.c @@ -98,22 +98,20 @@ protected_set_uuid_parse(const char *text, uint8 out[16]) if (text == NULL || strlen(text) != 32) return false; - for (i = 0; i < 16; i++) - { - int high = protected_set_hex_nibble((unsigned char) text[i * 2]); - int low = protected_set_hex_nibble((unsigned char) text[i * 2 + 1]); + for (i = 0; i < 16; i++) { + int high = protected_set_hex_nibble((unsigned char)text[i * 2]); + int low = protected_set_hex_nibble((unsigned char)text[i * 2 + 1]); if (high < 0 || low < 0) return false; - out[i] = (uint8) ((high << 4) | low); + out[i] = (uint8)((high << 4) | low); nonzero = nonzero || out[i] != 0; } return nonzero; } bool -cluster_shared_fs_get_protected_set_identity( - ClusterProtectedSetIdentityV1 *out) +cluster_shared_fs_get_protected_set_identity(ClusterProtectedSetIdentityV1 *out) { char uuid[CLUSTER_SHARED_UUID_LEN]; bool available = false; @@ -122,25 +120,22 @@ cluster_shared_fs_get_protected_set_identity( return false; memset(out, 0, sizeof(*out)); memset(uuid, 0, sizeof(uuid)); - switch (cluster_shared_storage_backend) - { - case CLUSTER_SHARED_FS_BACKEND_BLOCK_DEVICE: - available = cluster_shared_fs_block_device_get_storage_uuid( - uuid, sizeof(uuid)); - break; - case CLUSTER_SHARED_FS_BACKEND_CLUSTER_FS: - cluster_shared_fs_get_storage_uuid(uuid, sizeof(uuid)); - available = uuid[0] != '\0'; - break; - default: - return false; + switch (cluster_shared_storage_backend) { + case CLUSTER_SHARED_FS_BACKEND_BLOCK_DEVICE: + available = cluster_shared_fs_block_device_get_storage_uuid(uuid, sizeof(uuid)); + break; + case CLUSTER_SHARED_FS_BACKEND_CLUSTER_FS: + cluster_shared_fs_get_storage_uuid(uuid, sizeof(uuid)); + available = uuid[0] != '\0'; + break; + default: + return false; } - if (!available || !protected_set_uuid_parse(uuid, out->storage_uuid)) - { + if (!available || !protected_set_uuid_parse(uuid, out->storage_uuid)) { memset(out, 0, sizeof(*out)); return false; } - out->backend_id = (uint32) cluster_shared_storage_backend; + out->backend_id = (uint32)cluster_shared_storage_backend; return true; } diff --git a/src/backend/cluster/storage/cluster_shared_fs_block_device.c b/src/backend/cluster/storage/cluster_shared_fs_block_device.c index 0df872a8380..2b8cb9781dc 100644 --- a/src/backend/cluster/storage/cluster_shared_fs_block_device.c +++ b/src/backend/cluster/storage/cluster_shared_fs_block_device.c @@ -856,8 +856,7 @@ raw_ensure_layout(void) (errcode(ERRCODE_CONFIGURATION_LIMIT_EXCEEDED), errmsg("raw block device capacity exceeds the supported offset range"), errdetail("BLKGETSIZE64 reported " UINT64_FORMAT - " bytes; the maximum supported capacity is " INT64_FORMAT - " bytes.", + " bytes; the maximum supported capacity is " INT64_FORMAT " bytes.", reported_capacity, (int64)PG_INT64_MAX), errhint("Use a block device no larger than the reported maximum."))); if (size_failure == RAW_DEVICE_SIZE_FAILURE_SECTOR_ALIGNMENT) @@ -870,11 +869,10 @@ raw_ensure_layout(void) errhint("Verify that the block-device mapping exposes a whole number of " "512-byte sectors."))); if (size_failure == RAW_DEVICE_SIZE_FAILURE_UNSUPPORTED) - ereport(FATAL, - (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), - errmsg("could not query raw block device capacity on this platform"), - errhint("Use a Linux block device that supports BLKGETSIZE64, or a " - "regular-file image for development tests."))); + ereport(FATAL, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), + errmsg("could not query raw block device capacity on this platform"), + errhint("Use a Linux block device that supports BLKGETSIZE64, or a " + "regular-file image for development tests."))); errno = saved_errno; if (size_failure == RAW_DEVICE_SIZE_FAILURE_BLOCK_QUERY) ereport(FATAL, @@ -1488,19 +1486,16 @@ cluster_shared_fs_block_device_init(void) bool exact = true; int i; - memset(cluster_raw_protected_storage_uuid, 0, - sizeof(cluster_raw_protected_storage_uuid)); + memset(cluster_raw_protected_storage_uuid, 0, sizeof(cluster_raw_protected_storage_uuid)); raw_load_super(&super, &valid, &all_zero); - if (!valid || all_zero || super.storage_uuid[32] != '\0' || - cluster_shared_storage_uuid == NULL || - strlen(cluster_shared_storage_uuid) != 32) + if (!valid || all_zero || super.storage_uuid[32] != '\0' + || cluster_shared_storage_uuid == NULL || strlen(cluster_shared_storage_uuid) != 32) exact = false; - for (i = 0; exact && i < 32; i++) - { - unsigned char ch = (unsigned char) super.storage_uuid[i]; + for (i = 0; exact && i < 32; i++) { + unsigned char ch = (unsigned char)super.storage_uuid[i]; - if (!((ch >= '0' && ch <= '9') || (ch >= 'a' && ch <= 'f')) || - ch != (unsigned char) cluster_shared_storage_uuid[i]) + if (!((ch >= '0' && ch <= '9') || (ch >= 'a' && ch <= 'f')) + || ch != (unsigned char)cluster_shared_storage_uuid[i]) exact = false; } if (exact) @@ -1520,8 +1515,7 @@ cluster_shared_fs_block_device_shutdown(void) } cluster_raw_fence_capability = CLUSTER_FENCE_CAP_NONE; cluster_shared_fs_block_device_caps.supports_scsi3_pr = false; - memset(cluster_raw_protected_storage_uuid, 0, - sizeof(cluster_raw_protected_storage_uuid)); + memset(cluster_raw_protected_storage_uuid, 0, sizeof(cluster_raw_protected_storage_uuid)); } bool @@ -1532,8 +1526,7 @@ cluster_shared_fs_block_device_get_storage_uuid(char *out, size_t outlen) out[0] = '\0'; if (cluster_raw_protected_storage_uuid[0] == '\0') return false; - memcpy(out, cluster_raw_protected_storage_uuid, - sizeof(cluster_raw_protected_storage_uuid)); + memcpy(out, cluster_raw_protected_storage_uuid, sizeof(cluster_raw_protected_storage_uuid)); return true; } diff --git a/src/backend/cluster/storage/cluster_shared_fs_sharedfs.c b/src/backend/cluster/storage/cluster_shared_fs_sharedfs.c index 9a86f429538..fdbafa8c3db 100644 --- a/src/backend/cluster/storage/cluster_shared_fs_sharedfs.c +++ b/src/backend/cluster/storage/cluster_shared_fs_sharedfs.c @@ -376,9 +376,7 @@ cluster_shared_fs_sharedfs_nblocks(ClusterSharedFsHandle *handle) * cluster-wide corruption verdict. Re-sample for one short fixed budget; * aligned observations remain the only values ever returned. */ - for (recheck = 0; recheck < CLUSTER_SHAREDFS_EOF_RECHECK_ATTEMPTS; - recheck++) - { + for (recheck = 0; recheck < CLUSTER_SHAREDFS_EOF_RECHECK_ATTEMPTS; recheck++) { size = FileSize(handle->vfd); if (size < 0) ereport(ERROR, (errcode_for_file_access(), diff --git a/src/backend/cluster/storage/cluster_undo_alloc.c b/src/backend/cluster/storage/cluster_undo_alloc.c index 13d172071c6..309bde89978 100644 --- a/src/backend/cluster/storage/cluster_undo_alloc.c +++ b/src/backend/cluster/storage/cluster_undo_alloc.c @@ -352,8 +352,8 @@ cluster_undo_active_segment_for_node_or_create(int node_id) if (cached_node_id == node_id && cached_segment_id == segment_id) { if (!cached_block0_resident - && cluster_undo_block0_current_live_owner_ensure_resident( - &logical, 10000) == CLUSTER_UNDO_BLOCK0_OK) + && cluster_undo_block0_current_live_owner_ensure_resident(&logical, 10000) + == CLUSTER_UNDO_BLOCK0_OK) cached_block0_resident = true; return cached_segment_id; } @@ -414,8 +414,7 @@ read_segment_header_via_smgr(uint32 segment_id, uint8 owner_instance, char *bloc } -typedef enum ClusterUndoLifecycleMutationKind -{ +typedef enum ClusterUndoLifecycleMutationKind { CLUSTER_UNDO_LIFECYCLE_MARK_ACTIVE = 1, CLUSTER_UNDO_LIFECYCLE_MARK_COMMITTED, CLUSTER_UNDO_LIFECYCLE_MARK_FULL, @@ -428,9 +427,9 @@ typedef enum ClusterUndoLifecycleMutationKind * block-zero current/content-X owner compare and publish it. This function * may wait for 0xFB and therefore must run without lifecycle/content locks. */ static bool -cluster_undo_block0_current_live_owner_lifecycle_exact( - uint32 segment_id, uint8 owner_instance, - ClusterUndoLifecycleMutationKind kind, uint32 arg1, uint32 arg2) +cluster_undo_block0_current_live_owner_lifecycle_exact(uint32 segment_id, uint8 owner_instance, + ClusterUndoLifecycleMutationKind kind, + uint32 arg1, uint32 arg2) { PGAlignedBlock predecessor; PGAlignedBlock successor; @@ -441,10 +440,8 @@ cluster_undo_block0_current_live_owner_lifecycle_exact( uint64 last; uint32 block; - if (!read_segment_header_via_smgr(segment_id, owner_instance, - predecessor.data, &before) - || !cluster_undo_segment_header_identity_ok(predecessor.data, - segment_id, owner_instance) + if (!read_segment_header_via_smgr(segment_id, owner_instance, predecessor.data, &before) + || !cluster_undo_segment_header_identity_ok(predecessor.data, segment_id, owner_instance) || before->wrap_count == UINT32_MAX) return false; memcpy(successor.data, predecessor.data, BLCKSZ); @@ -457,8 +454,7 @@ cluster_undo_block0_current_live_owner_lifecycle_exact( after->segment_state = SEGMENT_ACTIVE; break; case CLUSTER_UNDO_LIFECYCLE_MARK_COMMITTED: - if (before->segment_state != SEGMENT_ACTIVE - && before->segment_state != SEGMENT_COMMITTED) + if (before->segment_state != SEGMENT_ACTIVE && before->segment_state != SEGMENT_COMMITTED) return false; after->segment_state = SEGMENT_COMMITTED; break; @@ -474,15 +470,14 @@ cluster_undo_block0_current_live_owner_lifecycle_exact( after->tail_block = arg1; break; case CLUSTER_UNDO_LIFECYCLE_MARK_BLOCK: - if (before->segment_state != SEGMENT_ACTIVE - || arg1 >= UNDO_BLOCKS_PER_SEGMENT) + if (before->segment_state != SEGMENT_ACTIVE || arg1 >= UNDO_BLOCKS_PER_SEGMENT) return false; (void)UndoSegmentBitmap_mark_used(after->free_block_bitmap, arg1); break; case CLUSTER_UNDO_LIFECYCLE_CLAIM_RANGE: last = (uint64)arg1 + arg2; - if (before->segment_state != SEGMENT_ACTIVE || arg1 < 1 - || arg2 == 0 || last > UNDO_BLOCKS_PER_SEGMENT) + if (before->segment_state != SEGMENT_ACTIVE || arg1 < 1 || arg2 == 0 + || last > UNDO_BLOCKS_PER_SEGMENT) return false; /* An extent claim is intentionally not idempotent: accepting an * already-used bit could hand the same extent to two local writers. */ @@ -493,8 +488,8 @@ cluster_undo_block0_current_live_owner_lifecycle_exact( if ((before->free_block_bitmap[byte_idx] & bit_mask) != 0) return false; } - if (!UndoSegmentBitmap_mark_range_used(after->free_block_bitmap, - arg1, arg2, UNDO_BLOCKS_PER_SEGMENT)) + if (!UndoSegmentBitmap_mark_range_used(after->free_block_bitmap, arg1, arg2, + UNDO_BLOCKS_PER_SEGMENT)) return false; break; default: @@ -505,12 +500,12 @@ cluster_undo_block0_current_live_owner_lifecycle_exact( key.owner_instance = owner_instance; expected.known = true; expected.value = before->wrap_count; - if (cluster_undo_block0_current_live_owner_ensure_resident( - &key, 10000) != CLUSTER_UNDO_BLOCK0_OK) + if (cluster_undo_block0_current_live_owner_ensure_resident(&key, 10000) + != CLUSTER_UNDO_BLOCK0_OK) return false; - return cluster_undo_block0_current_live_owner_mutate_exact( - &key, &expected, predecessor.data, successor.data, 10000) - == CLUSTER_UNDO_BLOCK0_OK; + return cluster_undo_block0_current_live_owner_mutate_exact(&key, &expected, predecessor.data, + successor.data, 10000) + == CLUSTER_UNDO_BLOCK0_OK; } @@ -525,8 +520,7 @@ bool cluster_undo_segment_mark_active(uint32 segment_id, uint8 owner_instance) { return cluster_undo_block0_current_live_owner_lifecycle_exact( - segment_id, owner_instance, CLUSTER_UNDO_LIFECYCLE_MARK_ACTIVE, - 0, 0); + segment_id, owner_instance, CLUSTER_UNDO_LIFECYCLE_MARK_ACTIVE, 0, 0); } @@ -546,8 +540,7 @@ bool cluster_undo_segment_mark_committed(uint32 segment_id, uint8 owner_instance) { return cluster_undo_block0_current_live_owner_lifecycle_exact( - segment_id, owner_instance, CLUSTER_UNDO_LIFECYCLE_MARK_COMMITTED, - 0, 0); + segment_id, owner_instance, CLUSTER_UNDO_LIFECYCLE_MARK_COMMITTED, 0, 0); } @@ -559,21 +552,19 @@ cluster_undo_segment_mark_committed(uint32 segment_id, uint8 owner_instance) * caller's expected epoch; no lifecycle/content lock may be held here. */ ClusterUndoSegTryRecycle -cluster_undo_segment_try_mark_recyclable(uint32 segment_id, - uint8 owner_instance, SCN horizon, uint64 expected_epoch) +cluster_undo_segment_try_mark_recyclable(uint32 segment_id, uint8 owner_instance, SCN horizon, + uint64 expected_epoch) { ClusterUndoBlock0LogicalKey key; ClusterUndoBlock0RecycleResult result; - if (segment_id == 0 || owner_instance < 1 - || owner_instance > UNDO_OWNER_INSTANCE_MAX - || !SCN_VALID(horizon) - || (expected_epoch == 0 && cluster_conf_node_count() != 4)) + if (segment_id == 0 || owner_instance < 1 || owner_instance > UNDO_OWNER_INSTANCE_MAX + || !SCN_VALID(horizon) || (expected_epoch == 0 && cluster_conf_node_count() != 4)) return CLUSTER_SEG_RECYCLE_READ_FAIL; key.owner_instance = owner_instance; key.segment_id = segment_id; - result = cluster_undo_block0_current_live_owner_recycle_exact( - &key, horizon, expected_epoch, 10000); + result = cluster_undo_block0_current_live_owner_recycle_exact(&key, horizon, expected_epoch, + 10000); switch (result) { case CLUSTER_UNDO_BLOCK0_RECYCLE_ADVANCED: return CLUSTER_SEG_RECYCLE_ADVANCED; @@ -611,8 +602,8 @@ cluster_undo_segment_reuse_in_place(uint32 segment_id, uint8 owner_instance, uin ClusterUndoBlock0Generation expected; ClusterUndoBlock0Result result; - if (segment_id == 0 || old_generation == UINT32_MAX - || owner_instance < 1 || owner_instance > UNDO_OWNER_INSTANCE_MAX) + if (segment_id == 0 || old_generation == UINT32_MAX || owner_instance < 1 + || owner_instance > UNDO_OWNER_INSTANCE_MAX) return 0; cluster_undo_segment_make_header_bytes(segment_id, owner_instance, page.data); @@ -622,8 +613,7 @@ cluster_undo_segment_reuse_in_place(uint32 segment_id, uint8 owner_instance, uin key.segment_id = segment_id; expected.known = true; expected.value = old_generation; - result = cluster_undo_block0_current_live_owner_reuse_exact( - &key, &expected, page.data, 10000); + result = cluster_undo_block0_current_live_owner_reuse_exact(&key, &expected, page.data, 10000); if (result != CLUSTER_UNDO_BLOCK0_OK) return 0; @@ -674,8 +664,7 @@ bool cluster_undo_segment_mark_full(uint32 segment_id, uint8 owner_instance) { return cluster_undo_block0_current_live_owner_lifecycle_exact( - segment_id, owner_instance, CLUSTER_UNDO_LIFECYCLE_MARK_FULL, - 0, 0); + segment_id, owner_instance, CLUSTER_UNDO_LIFECYCLE_MARK_FULL, 0, 0); } @@ -693,8 +682,7 @@ cluster_undo_segment_tail_block_init(uint32 segment_id, uint8 owner_instance, BlockNumber initial_tail) { return cluster_undo_block0_current_live_owner_lifecycle_exact( - segment_id, owner_instance, CLUSTER_UNDO_LIFECYCLE_INIT_TAIL, - initial_tail, 0); + segment_id, owner_instance, CLUSTER_UNDO_LIFECYCLE_INIT_TAIL, initial_tail, 0); } @@ -713,8 +701,7 @@ bool cluster_undo_segment_mark_block_used(uint32 segment_id, uint8 owner_instance, uint32 block_no) { return cluster_undo_block0_current_live_owner_lifecycle_exact( - segment_id, owner_instance, CLUSTER_UNDO_LIFECYCLE_MARK_BLOCK, - block_no, 0); + segment_id, owner_instance, CLUSTER_UNDO_LIFECYCLE_MARK_BLOCK, block_no, 0); } @@ -731,8 +718,7 @@ cluster_undo_segment_mark_block_range_used(uint32 segment_id, uint8 owner_instan uint32 first_block, uint32 nblocks) { return cluster_undo_block0_current_live_owner_lifecycle_exact( - segment_id, owner_instance, CLUSTER_UNDO_LIFECYCLE_CLAIM_RANGE, - first_block, nblocks); + segment_id, owner_instance, CLUSTER_UNDO_LIFECYCLE_CLAIM_RANGE, first_block, nblocks); } @@ -813,8 +799,7 @@ cluster_undo_segment_read_state(uint32 segment_id, uint8 owner_instance) * ============================================================ */ bool -cluster_undo_segment_extend_or_create( - uint8 owner_instance, ClusterUndoSegmentExtendPlan *plan) +cluster_undo_segment_extend_or_create(uint8 owner_instance, ClusterUndoSegmentExtendPlan *plan) { uint32 slot; uint32 base_segment_id; @@ -919,10 +904,9 @@ cluster_undo_segment_extend_or_create( close(fd); if (rb == BLCKSZ - && cluster_undo_segment_header_identity_ok(peek.data, - new_segment_id, owner_instance)) { - UndoSegmentHeaderData *header - = (UndoSegmentHeaderData *)peek.data; + && cluster_undo_segment_header_identity_ok(peek.data, new_segment_id, + owner_instance)) { + UndoSegmentHeaderData *header = (UndoSegmentHeaderData *)peek.data; if (header->segment_state == SEGMENT_RECYCLABLE) { plan->segment_id = new_segment_id; @@ -931,7 +915,7 @@ cluster_undo_segment_extend_or_create( return true; } if (header->segment_state == SEGMENT_ALLOCATED) { - TTSlot empty_slots[TT_SLOTS_PER_SEGMENT] = {{0}}; + TTSlot empty_slots[TT_SLOTS_PER_SEGMENT] = { { 0 } }; /* The state byte alone cannot authorize FREE/wrap0. A * previous incarnation may have bound a TT before its first diff --git a/src/backend/cluster/storage/cluster_undo_block0.c b/src/backend/cluster/storage/cluster_undo_block0.c index 37f08a876f4..6c1a980c784 100644 --- a/src/backend/cluster/storage/cluster_undo_block0.c +++ b/src/backend/cluster/storage/cluster_undo_block0.c @@ -189,8 +189,7 @@ cluster_undo_block0_r4_publish_ready(const ClusterR4PrerequisiteSnapshot *expect * current lane. Callers cannot manufacture an empty affected-set proof. */ ClusterR4StartupCompletionResultV1 -cluster_undo_block0_r4_startup_begin( - int timeout_ms, ClusterR4StartupCompletionContextV1 **out) +cluster_undo_block0_r4_startup_begin(int timeout_ms, ClusterR4StartupCompletionContextV1 **out) { if (out == NULL) return CLUSTER_R4_STARTUP_COMPLETION_INVALID; @@ -201,12 +200,11 @@ cluster_undo_block0_r4_startup_begin( } ClusterR4StartupCompletionResultV1 -cluster_undo_block0_r4_startup_close_next( - ClusterR4StartupCompletionContextV1 *context, - const RfRootResourceAdmissionV1 *root, - const RfRecordClosureProofV1 *record, - const RfPageResourceProofV1 *page, - const RfSideResourceProofSetV1 *side) +cluster_undo_block0_r4_startup_close_next(ClusterR4StartupCompletionContextV1 *context, + const RfRootResourceAdmissionV1 *root, + const RfRecordClosureProofV1 *record, + const RfPageResourceProofV1 *page, + const RfSideResourceProofSetV1 *side) { (void)root; (void)record; @@ -217,8 +215,7 @@ cluster_undo_block0_r4_startup_close_next( } ClusterR4StartupCompletionResultV1 -cluster_undo_block0_r4_startup_finalize( - ClusterR4StartupCompletionContextV1 **context) +cluster_undo_block0_r4_startup_finalize(ClusterR4StartupCompletionContextV1 **context) { if (context == NULL || *context == NULL) return CLUSTER_R4_STARTUP_COMPLETION_INVALID; @@ -226,8 +223,7 @@ cluster_undo_block0_r4_startup_finalize( } void -cluster_undo_block0_r4_startup_abort( - ClusterR4StartupCompletionContextV1 **context) +cluster_undo_block0_r4_startup_abort(ClusterR4StartupCompletionContextV1 **context) { if (context != NULL) *context = NULL; diff --git a/src/backend/cluster/storage/cluster_undo_block0_current.c b/src/backend/cluster/storage/cluster_undo_block0_current.c index df9fa3d7c77..1512551a1e5 100644 --- a/src/backend/cluster/storage/cluster_undo_block0_current.c +++ b/src/backend/cluster/storage/cluster_undo_block0_current.c @@ -1637,7 +1637,7 @@ cluster_undo_block0_current_pin_exclusive(ClusterUndoBlock0CurrentGuard *guard, { ClusterUndoBlock0CurrentGuardData *data; ClusterUndoBlock0AuthorityProof proof; - ClusterUndoBlock0Pin original_pin; + unsigned char original_pin[sizeof(*pin)]; volatile ClusterUndoBlock0CurrentPinCleanup cleanup; ClusterUndoBlock0Result result; char *private_page = NULL; @@ -1649,7 +1649,8 @@ cluster_undo_block0_current_pin_exclusive(ClusterUndoBlock0CurrentGuard *guard, if (result != CLUSTER_UNDO_BLOCK0_OK) return result; - original_pin = *pin; + /* Refusal preserves the caller's complete representation, including padding. */ + memcpy(original_pin, pin, sizeof(original_pin)); cleanup.guard = guard; cleanup.pin = pin; cleanup.local_pin_held = false; @@ -1670,7 +1671,7 @@ cluster_undo_block0_current_pin_exclusive(ClusterUndoBlock0CurrentGuard *guard, PG_END_ENSURE_ERROR_CLEANUP(current_pin_error_cleanup, PointerGetDatum((ClusterUndoBlock0CurrentPinCleanup *)&cleanup)); if (result != CLUSTER_UNDO_BLOCK0_OK) { - *pin = original_pin; + memcpy(pin, original_pin, sizeof(original_pin)); return result; } *page = private_page; diff --git a/src/backend/cluster/storage/cluster_undo_block0_resident.c b/src/backend/cluster/storage/cluster_undo_block0_resident.c index 4f6b308dd64..15c3d294fa8 100644 --- a/src/backend/cluster/storage/cluster_undo_block0_resident.c +++ b/src/backend/cluster/storage/cluster_undo_block0_resident.c @@ -104,23 +104,22 @@ static bool Block0ResourceCallbackRegistered = false; #define BLOCK0_FRAME_DATA(i) (Block0Frames + ((Size)(i)) * BLCKSZ) static bool block0_authority_proof_valid(const ClusterUndoBlock0LogicalKey *logical, - const ClusterUndoBlock0AuthorityProof *proof); + const ClusterUndoBlock0AuthorityProof *proof); static bool block0_authority_proof_matches(const ClusterUndoBlock0AuthorityProof *observed, - const ClusterUndoBlock0AuthorityProof *expected); + const ClusterUndoBlock0AuthorityProof *expected); static bool block0_page_identity(const char *page, const ClusterUndoBlock0LogicalKey *logical, ClusterUndoBlock0Generation *generation); static void block0_pin_clear(ClusterUndoBlock0Pin *pin); -static void block0_drop_reservation(ClusterUndoBlock0SlotData *meta, - ClusterUndoBlock0Pin *pin); +static void block0_drop_reservation(ClusterUndoBlock0SlotData *meta, ClusterUndoBlock0Pin *pin); static void block0_abort_pin(ClusterUndoBlock0Pin *pin); static void block0_recovery_guard_clear(ClusterUndoBlock0RecoveryGuard *guard); static void block0_resource_release_callback(ResourceReleasePhase phase, bool isCommit, - bool isTopLevel, void *arg); + bool isTopLevel, void *arg); static ClusterUndoBlock0OwnedResource *block0_resource_prepare(const void *handle, - ClusterUndoBlock0OwnedKind kind); + ClusterUndoBlock0OwnedKind kind); static void block0_resource_link(ClusterUndoBlock0OwnedResource *resource); -static ClusterUndoBlock0OwnedResource *block0_resource_find( - const void *handle, ClusterUndoBlock0OwnedKind kind); +static ClusterUndoBlock0OwnedResource *block0_resource_find(const void *handle, + ClusterUndoBlock0OwnedKind kind); static void block0_resource_free(ClusterUndoBlock0OwnedResource *resource); static void block0_resource_forget(ClusterUndoBlock0OwnedResource *resource); @@ -213,8 +212,8 @@ block0_resource_return_frame(uint32 frame_index) static void -block0_resource_release_callback(ResourceReleasePhase phase, bool isCommit, - bool isTopLevel, void *arg) +block0_resource_release_callback(ResourceReleasePhase phase, bool isCommit, bool isTopLevel, + void *arg) { dlist_mutable_iter iter; @@ -273,13 +272,11 @@ block0_resource_release_callback(ResourceReleasePhase phase, bool isCommit, (void)cluster_undo_smgr_provision_temp_cleanup( meta->resolved_root.intent, meta->logical.segment_id, meta->logical.owner_instance, resource->temp_path); - if (pg_atomic_read_u32(&meta->state) - == CLUSTER_UNDO_BLOCK0_SLOT_FILLING + if (pg_atomic_read_u32(&meta->state) == CLUSTER_UNDO_BLOCK0_SLOT_FILLING && meta->frame_index == resource->frame_index) { meta->frame_index = CLUSTER_UNDO_BLOCK0_FRAME_INVALID; pg_atomic_write_u32(&meta->pincount, 0); - pg_atomic_write_u32(&meta->state, - CLUSTER_UNDO_BLOCK0_SLOT_EMPTY); + pg_atomic_write_u32(&meta->state, CLUSTER_UNDO_BLOCK0_SLOT_EMPTY); return_frame = true; } LWLockRelease(&meta->content_lock); @@ -304,7 +301,7 @@ cluster_undo_block0_shmem_size(uint32 frame_count) sz = MAXALIGN(sizeof(ClusterUndoBlock0Ctl)); sz = add_size(sz, MAXALIGN(mul_size((Size)CLUSTER_UNDO_BLOCK0_SLOT_COUNT, - sizeof(ClusterUndoBlock0Slot)))); + sizeof(ClusterUndoBlock0Slot)))); sz = add_size(sz, MAXALIGN(mul_size((Size)frame_count, sizeof(uint32)))); sz = add_size(sz, mul_size((Size)frame_count, (Size)BLCKSZ)); return sz; @@ -330,8 +327,8 @@ cluster_undo_block0_shmem_init_region(void *address, Size size, uint32 frame_cou Block0Ctl = (ClusterUndoBlock0Ctl *)cursor; cursor += MAXALIGN(sizeof(ClusterUndoBlock0Ctl)); Block0Slots = (ClusterUndoBlock0Slot *)cursor; - cursor += MAXALIGN(mul_size((Size)CLUSTER_UNDO_BLOCK0_SLOT_COUNT, - sizeof(ClusterUndoBlock0Slot))); + cursor + += MAXALIGN(mul_size((Size)CLUSTER_UNDO_BLOCK0_SLOT_COUNT, sizeof(ClusterUndoBlock0Slot))); Block0FreeFrames = (uint32 *)cursor; cursor += MAXALIGN(mul_size((Size)frame_count, sizeof(uint32))); Block0Frames = cursor; @@ -438,8 +435,8 @@ cluster_undo_block0_frame_release(ClusterUndoBlock0FrameToken *token) if (token == NULL || !token->owned) return; owned = block0_resource_find(token, CLUSTER_UNDO_BLOCK0_OWNED_FRAME); - if (Block0Ctl == NULL || token->frame_index >= Block0Ctl->frame_count - || owned == NULL || owned->frame_index != token->frame_index) { + if (Block0Ctl == NULL || token->frame_index >= Block0Ctl->frame_count || owned == NULL + || owned->frame_index != token->frame_index) { token->frame_index = CLUSTER_UNDO_BLOCK0_FRAME_INVALID; token->owned = false; if (Block0Ctl == NULL) @@ -494,8 +491,7 @@ block0_page_identity(const char *page, const ClusterUndoBlock0LogicalKey *logica return false; ph = (PageHeader)page; hdr = (const UndoSegmentHeaderData *)page; - if ((ph->pd_flags & PD_UNDO_SEG_HEADER) == 0 - || PageGetPageSize((Page)page) != BLCKSZ + if ((ph->pd_flags & PD_UNDO_SEG_HEADER) == 0 || PageGetPageSize((Page)page) != BLCKSZ || PageGetPageLayoutVersion((Page)page) != PG_PAGE_LAYOUT_VERSION || hdr->segment_id != logical->segment_id || hdr->segment_size_bytes != UNDO_SEGMENT_SIZE_BYTES @@ -636,10 +632,10 @@ block0_normal_start_read(ClusterUndoBlock0SlotData *meta, ClusterUndoBlock0Result cluster_undo_block0_admit_runtime(const ClusterUndoBlock0LogicalKey *logical, - const ClusterUndoBlock0ResolvedRoot *root, - const ClusterUndoBlock0AuthorityProof *proof, - ClusterUndoBlock0FrameToken *token, ClusterUndoBlock0Pin *pin, - char **page) + const ClusterUndoBlock0ResolvedRoot *root, + const ClusterUndoBlock0AuthorityProof *proof, + ClusterUndoBlock0FrameToken *token, ClusterUndoBlock0Pin *pin, + char **page) { ClusterUndoBlock0SlotData *meta; ClusterUndoBlock0Generation generation; @@ -744,8 +740,8 @@ cluster_undo_block0_admit_runtime(const ClusterUndoBlock0LogicalKey *logical, static void block0_provision_restore_token(ClusterUndoBlock0SlotData *meta, - ClusterUndoBlock0OwnedResource *owned, - ClusterUndoBlock0FrameToken *token) + ClusterUndoBlock0OwnedResource *owned, + ClusterUndoBlock0FrameToken *token) { meta->frame_index = CLUSTER_UNDO_BLOCK0_FRAME_INVALID; pg_atomic_write_u32(&meta->pincount, 0); @@ -767,9 +763,8 @@ ClusterUndoBlock0Result cluster_undo_block0_provision_begin(const ClusterUndoBlock0LogicalKey *logical, const ClusterUndoBlock0ResolvedRoot *target_root, const ClusterUndoBlock0AuthorityProof *proof, - ClusterUndoBlock0FrameToken *token, - ClusterUndoBlock0Pin *pin, char **unpublished_page, - bool *creator) + ClusterUndoBlock0FrameToken *token, ClusterUndoBlock0Pin *pin, + char **unpublished_page, bool *creator) { ClusterUndoBlock0SlotData *meta; ClusterUndoBlock0Generation generation; @@ -783,8 +778,8 @@ cluster_undo_block0_provision_begin(const ClusterUndoBlock0LogicalKey *logical, *unpublished_page = NULL; if (creator != NULL) *creator = false; - if (Block0Ctl == NULL || target_root == NULL || token == NULL || !token->owned - || pin == NULL || unpublished_page == NULL || creator == NULL + if (Block0Ctl == NULL || target_root == NULL || token == NULL || !token->owned || pin == NULL + || unpublished_page == NULL || creator == NULL || token->frame_index >= Block0Ctl->frame_count) return CLUSTER_UNDO_BLOCK0_CAPACITY_UNAVAILABLE; if (cluster_undo_block0_logical_slot(logical, &slotno) != CLUSTER_UNDO_BLOCK0_OK @@ -821,7 +816,7 @@ cluster_undo_block0_provision_begin(const ClusterUndoBlock0LogicalKey *logical, Assert(owned->temp_path == NULL); final_state = cluster_undo_smgr_probe_segment(target_root->intent, logical->segment_id, - logical->owner_instance, frame); + logical->owner_instance, frame); if (final_state != CLUSTER_UNDO_SMGR_FINAL_ABSENT && final_state != CLUSTER_UNDO_SMGR_FINAL_EXACT && final_state != CLUSTER_UNDO_SMGR_FINAL_INVALID @@ -840,8 +835,8 @@ cluster_undo_block0_provision_begin(const ClusterUndoBlock0LogicalKey *logical, if (final_state == CLUSTER_UNDO_SMGR_FINAL_ABSENT) { owned->temp_path = MemoryContextAlloc(TopMemoryContext, MAXPGPATH); owned->temp_path[0] = '\0'; - if (!cluster_undo_smgr_provision_temp_create(target_root->intent, - logical->segment_id, logical->owner_instance, owned->temp_path)) { + if (!cluster_undo_smgr_provision_temp_create(target_root->intent, logical->segment_id, + logical->owner_instance, owned->temp_path)) { block0_provision_restore_token(meta, owned, token); return CLUSTER_UNDO_BLOCK0_IO_ERROR; } @@ -865,8 +860,8 @@ cluster_undo_block0_provision_begin(const ClusterUndoBlock0LogicalKey *logical, pin->logical = *logical; pin->resolved_root = *target_root; pin->observed_generation = final_state == CLUSTER_UNDO_SMGR_FINAL_EXACT - ? generation - : (ClusterUndoBlock0Generation){ .known = false, .value = 0 }; + ? generation + : (ClusterUndoBlock0Generation){ .known = false, .value = 0 }; pin->mode = CLUSTER_UNDO_BLOCK0_EXCLUSIVE; pin->proof = *proof; *unpublished_page = frame; @@ -900,8 +895,7 @@ cluster_undo_block0_provision_publish(ClusterUndoBlock0Pin *pin, XLogRecPtr init || meta->frame_index != owned->frame_index) ereport(ERROR, (errmsg("undo block-zero provision publisher lost filling authority"))); frame = BLOCK0_FRAME_DATA(meta->frame_index); - if (!block0_page_identity(frame, &meta->logical, &generation) - || generation.value == UINT32_MAX) + if (!block0_page_identity(frame, &meta->logical, &generation) || generation.value == UINT32_MAX) ereport(ERROR, (errmsg("invalid undo block-zero provision image"))); XLogFlush(init_lsn); @@ -909,9 +903,9 @@ cluster_undo_block0_provision_publish(ClusterUndoBlock0Pin *pin, XLogRecPtr init meta->resolved_root.intent, meta->logical.segment_id, meta->logical.owner_instance, owned->temp_path, frame); if (publish_result == CLUSTER_UNDO_SMGR_PUBLISH_EXISTS) { - if (cluster_undo_smgr_probe_segment(meta->resolved_root.intent, - meta->logical.segment_id, meta->logical.owner_instance, frame) - != CLUSTER_UNDO_SMGR_FINAL_EXACT + if (cluster_undo_smgr_probe_segment(meta->resolved_root.intent, meta->logical.segment_id, + meta->logical.owner_instance, frame) + != CLUSTER_UNDO_SMGR_FINAL_EXACT || !block0_page_identity(frame, &meta->logical, &generation) || generation.value == UINT32_MAX) ereport(ERROR, (errmsg("undo block-zero provision winner is not exact"))); @@ -945,8 +939,9 @@ cluster_undo_block0_provision_abort(ClusterUndoBlock0Pin *pin) meta = &Block0Slots[pin->slot].data; frame_index = owned->frame_index; if (owned->temp_path != NULL && owned->temp_path[0] != '\0') - (void)cluster_undo_smgr_provision_temp_cleanup(meta->resolved_root.intent, - meta->logical.segment_id, meta->logical.owner_instance, owned->temp_path); + (void)cluster_undo_smgr_provision_temp_cleanup( + meta->resolved_root.intent, meta->logical.segment_id, meta->logical.owner_instance, + owned->temp_path); if (pg_atomic_read_u32(&meta->state) == CLUSTER_UNDO_BLOCK0_SLOT_FILLING && meta->frame_index == frame_index) { meta->frame_index = CLUSTER_UNDO_BLOCK0_FRAME_INVALID; @@ -963,8 +958,7 @@ cluster_undo_block0_provision_abort(ClusterUndoBlock0Pin *pin) ClusterUndoBlock0Result cluster_undo_block0_reserve(const ClusterUndoBlock0LogicalKey *logical, const ClusterUndoBlock0ResolvedRoot *expected_root, - const ClusterUndoBlock0AuthorityProof *proof, - ClusterUndoBlock0Pin *pin) + const ClusterUndoBlock0AuthorityProof *proof, ClusterUndoBlock0Pin *pin) { ClusterUndoBlock0SlotData *meta; ClusterUndoBlock0OwnedResource *owned; @@ -990,9 +984,8 @@ cluster_undo_block0_reserve(const ClusterUndoBlock0LogicalKey *logical, LWLockRelease(&meta->content_lock); if (owned != NULL) pfree(owned); - return state == CLUSTER_UNDO_BLOCK0_SLOT_RETIRING - ? CLUSTER_UNDO_BLOCK0_GENERATION_MISMATCH - : CLUSTER_UNDO_BLOCK0_NOT_PUBLISHED; + return state == CLUSTER_UNDO_BLOCK0_SLOT_RETIRING ? CLUSTER_UNDO_BLOCK0_GENERATION_MISMATCH + : CLUSTER_UNDO_BLOCK0_NOT_PUBLISHED; } if (meta->logical.segment_id != logical->segment_id || meta->logical.owner_instance != logical->owner_instance @@ -1056,8 +1049,8 @@ cluster_undo_block0_lock_content(ClusterUndoBlock0Pin *pin, ? CLUSTER_UNDO_BLOCK0_GENERATION_MISMATCH : CLUSTER_UNDO_BLOCK0_NOT_PUBLISHED; else if (meta->logical.segment_id != pin->logical.segment_id - || meta->logical.owner_instance != pin->logical.owner_instance - || !cluster_undo_block0_root_matches(&meta->resolved_root, &pin->resolved_root)) + || meta->logical.owner_instance != pin->logical.owner_instance + || !cluster_undo_block0_root_matches(&meta->resolved_root, &pin->resolved_root)) result = CLUSTER_UNDO_BLOCK0_IDENTITY_MISMATCH; else if (!block0_authority_proof_matches(&meta->proof, &pin->proof)) result = CLUSTER_UNDO_BLOCK0_AUTHORITY_DENIED; @@ -1123,7 +1116,7 @@ cluster_undo_block0_copy_resident(const ClusterUndoBlock0LogicalKey *logical, if (private_page == NULL) return CLUSTER_UNDO_BLOCK0_IDENTITY_MISMATCH; result = cluster_undo_block0_pin(logical, expected_root, expected, CLUSTER_UNDO_BLOCK0_SHARED, - proof, &pin, &page); + proof, &pin, &page); if (result != CLUSTER_UNDO_BLOCK0_OK) return result; memcpy(private_page, page, BLCKSZ); @@ -1196,11 +1189,10 @@ cluster_undo_block0_copy_readonly(const ClusterUndoBlock0LogicalKey *logical, ClusterUndoBlock0Result -cluster_undo_block0_sample_resident_generation( - const ClusterUndoBlock0LogicalKey *logical, - const ClusterUndoBlock0ResolvedRoot *expected_root, - const ClusterUndoBlock0AuthorityProof *proof, - ClusterUndoBlock0Generation *observed_generation) +cluster_undo_block0_sample_resident_generation(const ClusterUndoBlock0LogicalKey *logical, + const ClusterUndoBlock0ResolvedRoot *expected_root, + const ClusterUndoBlock0AuthorityProof *proof, + ClusterUndoBlock0Generation *observed_generation) { ClusterUndoBlock0Pin pin; ClusterUndoBlock0Result result; @@ -1209,7 +1201,7 @@ cluster_undo_block0_sample_resident_generation( if (observed_generation == NULL) return CLUSTER_UNDO_BLOCK0_IDENTITY_MISMATCH; result = cluster_undo_block0_pin(logical, expected_root, NULL, CLUSTER_UNDO_BLOCK0_SHARED, - proof, &pin, &page); + proof, &pin, &page); if (result != CLUSTER_UNDO_BLOCK0_OK) return result; *observed_generation = pin.observed_generation; @@ -1220,10 +1212,8 @@ cluster_undo_block0_sample_resident_generation( ClusterUndoBlock0Result cluster_undo_block0_sample_resident_generation_conditional( - const ClusterUndoBlock0LogicalKey *logical, - const ClusterUndoBlock0ResolvedRoot *expected_root, - const ClusterUndoBlock0AuthorityProof *proof, - ClusterUndoBlock0Generation *observed_generation) + const ClusterUndoBlock0LogicalKey *logical, const ClusterUndoBlock0ResolvedRoot *expected_root, + const ClusterUndoBlock0AuthorityProof *proof, ClusterUndoBlock0Generation *observed_generation) { ClusterUndoBlock0SlotData *meta; ClusterUndoBlock0Result result = CLUSTER_UNDO_BLOCK0_OK; @@ -1234,8 +1224,7 @@ cluster_undo_block0_sample_resident_generation_conditional( return CLUSTER_UNDO_BLOCK0_IDENTITY_MISMATCH; memset(observed_generation, 0, sizeof(*observed_generation)); if (Block0Ctl == NULL - || cluster_undo_block0_logical_slot(logical, &slotno) - != CLUSTER_UNDO_BLOCK0_OK + || cluster_undo_block0_logical_slot(logical, &slotno) != CLUSTER_UNDO_BLOCK0_OK || !cluster_undo_block0_root_valid(expected_root) || !block0_authority_proof_valid(logical, proof)) return CLUSTER_UNDO_BLOCK0_IDENTITY_MISMATCH; @@ -1247,12 +1236,11 @@ cluster_undo_block0_sample_resident_generation_conditional( if (state != CLUSTER_UNDO_BLOCK0_SLOT_VALID_CLEAN && state != CLUSTER_UNDO_BLOCK0_SLOT_VALID_DIRTY) result = state == CLUSTER_UNDO_BLOCK0_SLOT_RETIRING - ? CLUSTER_UNDO_BLOCK0_GENERATION_MISMATCH - : CLUSTER_UNDO_BLOCK0_NOT_PUBLISHED; + ? CLUSTER_UNDO_BLOCK0_GENERATION_MISMATCH + : CLUSTER_UNDO_BLOCK0_NOT_PUBLISHED; else if (meta->logical.segment_id != logical->segment_id - || meta->logical.owner_instance != logical->owner_instance - || !cluster_undo_block0_root_matches( - &meta->resolved_root, expected_root)) + || meta->logical.owner_instance != logical->owner_instance + || !cluster_undo_block0_root_matches(&meta->resolved_root, expected_root)) result = CLUSTER_UNDO_BLOCK0_IDENTITY_MISMATCH; else if (!block0_authority_proof_matches(&meta->proof, proof)) result = CLUSTER_UNDO_BLOCK0_AUTHORITY_DENIED; @@ -1264,20 +1252,17 @@ cluster_undo_block0_sample_resident_generation_conditional( ClusterUndoBlock0Result -cluster_undo_block0_prove_strict_empty( - const ClusterUndoBlock0LogicalKey *logical, - const ClusterUndoBlock0AuthorityProof *proof) +cluster_undo_block0_prove_strict_empty(const ClusterUndoBlock0LogicalKey *logical, + const ClusterUndoBlock0AuthorityProof *proof) { ClusterUndoBlock0SlotData *meta; ClusterUndoBlock0Result result; uint32 slotno; - if (cluster_undo_block0_logical_slot(logical, &slotno) - != CLUSTER_UNDO_BLOCK0_OK) + if (cluster_undo_block0_logical_slot(logical, &slotno) != CLUSTER_UNDO_BLOCK0_OK) return CLUSTER_UNDO_BLOCK0_IDENTITY_MISMATCH; if (!block0_authority_proof_valid(logical, proof) - || proof->kind != CLUSTER_UNDO_BLOCK0_LIVE_OWNER - || proof->recovery_generation != 0) + || proof->kind != CLUSTER_UNDO_BLOCK0_LIVE_OWNER || proof->recovery_generation != 0) return CLUSTER_UNDO_BLOCK0_AUTHORITY_DENIED; if (Block0Ctl == NULL) return CLUSTER_UNDO_BLOCK0_AUTHORITY_DENIED; @@ -1298,14 +1283,11 @@ cluster_undo_block0_prove_strict_empty( ClusterUndoBlock0Result -cluster_undo_block0_recovery_private_begin( - const ClusterUndoBlock0LogicalKey *logical, - const ClusterUndoBlock0ResolvedRoot *redo_root, - const ClusterUndoBlock0AuthorityProof *proof, - bool allow_absent, - ClusterUndoBlock0RecoveryGuard *guard, - char private_page[BLCKSZ], - bool *exists) +cluster_undo_block0_recovery_private_begin(const ClusterUndoBlock0LogicalKey *logical, + const ClusterUndoBlock0ResolvedRoot *redo_root, + const ClusterUndoBlock0AuthorityProof *proof, + bool allow_absent, ClusterUndoBlock0RecoveryGuard *guard, + char private_page[BLCKSZ], bool *exists) { ClusterUndoBlock0SlotData *meta; ClusterUndoBlock0Generation generation; @@ -1333,14 +1315,12 @@ cluster_undo_block0_recovery_private_begin( meta = &Block0Slots[slotno].data; LWLockAcquire(&meta->content_lock, LW_EXCLUSIVE); state = pg_atomic_read_u32(&meta->state); - if (state != CLUSTER_UNDO_BLOCK0_SLOT_EMPTY - || pg_atomic_read_u32(&meta->pincount) != 0) { + if (state != CLUSTER_UNDO_BLOCK0_SLOT_EMPTY || pg_atomic_read_u32(&meta->pincount) != 0) { LWLockRelease(&meta->content_lock); if (owned != NULL) pfree(owned); - return state == CLUSTER_UNDO_BLOCK0_SLOT_RETIRING - ? CLUSTER_UNDO_BLOCK0_GENERATION_MISMATCH - : CLUSTER_UNDO_BLOCK0_NOT_PUBLISHED; + return state == CLUSTER_UNDO_BLOCK0_SLOT_RETIRING ? CLUSTER_UNDO_BLOCK0_GENERATION_MISMATCH + : CLUSTER_UNDO_BLOCK0_NOT_PUBLISHED; } if (owned != NULL) { owned->slot = slotno; @@ -1378,10 +1358,8 @@ cluster_undo_block0_recovery_private_begin( void cluster_undo_block0_recovery_private_finish(ClusterUndoBlock0RecoveryGuard *guard, - const char *successor_page, - XLogRecPtr replay_lsn, - bool write_image, - bool fsync_parent) + const char *successor_page, XLogRecPtr replay_lsn, + bool write_image, bool fsync_parent) { ClusterUndoBlock0SlotData *meta; ClusterUndoBlock0Generation successor_generation; @@ -1389,12 +1367,9 @@ cluster_undo_block0_recovery_private_finish(ClusterUndoBlock0RecoveryGuard *guar uint32 slotno; if (Block0Ctl == NULL || guard == NULL || !guard->content_x_held || guard->slot < 0 - || guard->slot >= CLUSTER_UNDO_BLOCK0_SLOT_COUNT - || XLogRecPtrIsInvalid(replay_lsn) - || cluster_undo_block0_logical_slot(&guard->logical, &slotno) - != CLUSTER_UNDO_BLOCK0_OK - || slotno != (uint32)guard->slot - || !cluster_undo_block0_root_valid(&guard->resolved_root) + || guard->slot >= CLUSTER_UNDO_BLOCK0_SLOT_COUNT || XLogRecPtrIsInvalid(replay_lsn) + || cluster_undo_block0_logical_slot(&guard->logical, &slotno) != CLUSTER_UNDO_BLOCK0_OK + || slotno != (uint32)guard->slot || !cluster_undo_block0_root_valid(&guard->resolved_root) || !block0_authority_proof_valid(&guard->logical, &guard->proof) || (guard->proof.kind != CLUSTER_UNDO_BLOCK0_RECOVERY_OWNER && guard->proof.kind != CLUSTER_UNDO_BLOCK0_STARTUP_REDO) @@ -1405,22 +1380,17 @@ cluster_undo_block0_recovery_private_finish(ClusterUndoBlock0RecoveryGuard *guar owned = block0_resource_find(guard, CLUSTER_UNDO_BLOCK0_OWNED_RECOVERY); if (pg_atomic_read_u32(&meta->state) != CLUSTER_UNDO_BLOCK0_SLOT_EMPTY || pg_atomic_read_u32(&meta->pincount) != 0) - ereport(PANIC, - (errmsg("undo block-zero recovery-private finish found resident state"))); + ereport(PANIC, (errmsg("undo block-zero recovery-private finish found resident state"))); if (write_image) { if (successor_page == NULL - || !block0_page_identity(successor_page, &guard->logical, - &successor_generation)) - ereport(PANIC, - (errmsg("invalid undo block-zero recovery-private successor image"))); + || !block0_page_identity(successor_page, &guard->logical, &successor_generation)) + ereport(PANIC, (errmsg("invalid undo block-zero recovery-private successor image"))); if (fsync_parent) ereport(PANIC, (errmsg("undo block-zero recovery parent-directory fsync is unavailable"))); - if (!cluster_undo_smgr_write_block(guard->resolved_root.intent, - guard->logical.segment_id, - guard->logical.owner_instance, 0, - successor_page, true)) + if (!cluster_undo_smgr_write_block(guard->resolved_root.intent, guard->logical.segment_id, + guard->logical.owner_instance, 0, successor_page, true)) ereport(PANIC, (errmsg("could not durably apply recovery-private block zero"))); } @@ -1454,14 +1424,13 @@ cluster_undo_block0_recovery_private_abort(ClusterUndoBlock0RecoveryGuard *guard * closure remain separate READY prerequisites. */ bool -cluster_undo_block0_verify_clean_census( - const ClusterUndoBlock0ResidentCensusItem *items, uint32 count) +cluster_undo_block0_verify_clean_census(const ClusterUndoBlock0ResidentCensusItem *items, + uint32 count) { uint32 item_index = 0; uint32 slotno; - if (Block0Ctl == NULL || (count > 0 && items == NULL) - || count > CLUSTER_UNDO_BLOCK0_SLOT_COUNT) + if (Block0Ctl == NULL || (count > 0 && items == NULL) || count > CLUSTER_UNDO_BLOCK0_SLOT_COUNT) return false; for (slotno = 0; slotno < CLUSTER_UNDO_BLOCK0_SLOT_COUNT; slotno++) { @@ -1472,23 +1441,19 @@ cluster_undo_block0_verify_clean_census( LWLockAcquire(&meta->content_lock, LW_SHARED); state = pg_atomic_read_u32(&meta->state); if (item_index < count) { - const ClusterUndoBlock0ResidentCensusItem *item - = &items[item_index]; + const ClusterUndoBlock0ResidentCensusItem *item = &items[item_index]; uint32 expected_slot; if (cluster_undo_block0_logical_slot(&item->logical, &expected_slot) == CLUSTER_UNDO_BLOCK0_OK - && expected_slot == slotno - && state == CLUSTER_UNDO_BLOCK0_SLOT_VALID_CLEAN + && expected_slot == slotno && state == CLUSTER_UNDO_BLOCK0_SLOT_VALID_CLEAN && pg_atomic_read_u32(&meta->pincount) == 0 && meta->frame_index < Block0Ctl->frame_count && XLogRecPtrIsInvalid(meta->last_wal_lsn) && meta->logical.segment_id == item->logical.segment_id && meta->logical.owner_instance == item->logical.owner_instance - && cluster_undo_block0_root_matches( - &meta->resolved_root, &item->resolved_root) - && cluster_undo_block0_generation_matches( - &meta->generation, &item->generation) + && cluster_undo_block0_root_matches(&meta->resolved_root, &item->resolved_root) + && cluster_undo_block0_generation_matches(&meta->generation, &item->generation) && item->generation.known && block0_authority_proof_matches(&meta->proof, &item->proof)) matched = true; @@ -1775,8 +1740,7 @@ cluster_undo_block0_mark_wal_dirty(ClusterUndoBlock0Pin *pin, XLogRecPtr wal_lsn uint32 state; Assert(Block0Ctl != NULL); - Assert(pin != NULL && pin->slot >= 0 - && pin->slot < CLUSTER_UNDO_BLOCK0_SLOT_COUNT); + Assert(pin != NULL && pin->slot >= 0 && pin->slot < CLUSTER_UNDO_BLOCK0_SLOT_COUNT); Assert(pin->mode == CLUSTER_UNDO_BLOCK0_EXCLUSIVE); Assert(!XLogRecPtrIsInvalid(wal_lsn)); meta = &Block0Slots[pin->slot].data; @@ -1791,7 +1755,7 @@ cluster_undo_block0_mark_wal_dirty(ClusterUndoBlock0Pin *pin, XLogRecPtr wal_lsn void cluster_undo_block0_flush_sync(ClusterUndoBlock0Pin *pin, const char *successor_page, - XLogRecPtr required_wal_lsn, bool fsync_parent) + XLogRecPtr required_wal_lsn, bool fsync_parent) { ClusterUndoBlock0SlotData *meta; ClusterUndoBlock0Generation successor_generation; @@ -1799,23 +1763,20 @@ cluster_undo_block0_flush_sync(ClusterUndoBlock0Pin *pin, const char *successor_ uint32 state; if (Block0Ctl == NULL || pin == NULL || pin->slot < 0 - || pin->slot >= CLUSTER_UNDO_BLOCK0_SLOT_COUNT - || pin->mode != CLUSTER_UNDO_BLOCK0_EXCLUSIVE || successor_page == NULL) + || pin->slot >= CLUSTER_UNDO_BLOCK0_SLOT_COUNT || pin->mode != CLUSTER_UNDO_BLOCK0_EXCLUSIVE + || successor_page == NULL) ereport(ERROR, (errmsg("invalid undo block-zero synchronous flush owner"))); if (fsync_parent) ereport(ERROR, (errmsg("undo block-zero parent-directory fsync is unavailable"))); meta = &Block0Slots[pin->slot].data; - if (!block0_page_identity(successor_page, &meta->logical, - &successor_generation)) - ereport(ERROR, - (errmsg("invalid undo block-zero synchronous flush successor image"))); + if (!block0_page_identity(successor_page, &meta->logical, &successor_generation)) + ereport(ERROR, (errmsg("invalid undo block-zero synchronous flush successor image"))); state = pg_atomic_read_u32(&meta->state); if (state != CLUSTER_UNDO_BLOCK0_SLOT_VALID_CLEAN && state != CLUSTER_UNDO_BLOCK0_SLOT_VALID_DIRTY) ereport(ERROR, (errmsg("undo block-zero synchronous flush found invalid resident state"))); - if (XLogRecPtrIsInvalid(required_wal_lsn) - && state == CLUSTER_UNDO_BLOCK0_SLOT_VALID_DIRTY) + if (XLogRecPtrIsInvalid(required_wal_lsn) && state == CLUSTER_UNDO_BLOCK0_SLOT_VALID_DIRTY) ereport(ERROR, (errmsg("undo block-zero dirty flush requires a valid WAL LSN"))); flush_lsn = required_wal_lsn; @@ -1825,7 +1786,7 @@ cluster_undo_block0_flush_sync(ClusterUndoBlock0Pin *pin, const char *successor_ if (!XLogRecPtrIsInvalid(flush_lsn)) XLogFlush(flush_lsn); if (!cluster_undo_smgr_write_block(meta->resolved_root.intent, meta->logical.segment_id, - meta->logical.owner_instance, 0, successor_page, true)) + meta->logical.owner_instance, 0, successor_page, true)) ereport(ERROR, (errmsg("could not flush undo block zero"))); memcpy(BLOCK0_FRAME_DATA(meta->frame_index), successor_page, BLCKSZ); diff --git a/src/backend/cluster/storage/cluster_undo_buf.c b/src/backend/cluster/storage/cluster_undo_buf.c index 10eeca65d6e..75d590cceeb 100644 --- a/src/backend/cluster/storage/cluster_undo_buf.c +++ b/src/backend/cluster/storage/cluster_undo_buf.c @@ -328,7 +328,7 @@ cluster_undo_buf_shmem_init(void) data_region_sz = add_size(data_region_sz, mul_size((Size)BLCKSZ, n)); block0_sz = cluster_undo_block0_shmem_size((uint32)n); if (!cluster_undo_block0_shmem_init_region(((char *)UndoBufPool) + data_region_sz, block0_sz, - (uint32)n, found)) + (uint32)n, found)) ereport(PANIC, (errmsg("could not initialize cluster undo block-zero resident region"))); if (found) @@ -869,27 +869,21 @@ cluster_undo_buf_unref_slot(int slot) bool -cluster_undo_buf_lock_ref_conditional(int slot, uint32 segment_id, - uint8 owner, uint32 block_no) +cluster_undo_buf_lock_ref_conditional(int slot, uint32 segment_id, uint8 owner, uint32 block_no) { UndoBufSlot *s; bool exact; - if (UndoBufPool == NULL || UndoBufSlots == NULL - || slot < 0 || slot >= UndoBufPool->nslots) + if (UndoBufPool == NULL || UndoBufSlots == NULL || slot < 0 || slot >= UndoBufPool->nslots) return false; s = &UndoBufSlots[slot]; - if (!s->valid || s->io_in_progress - || s->segment_id != segment_id || s->owner != owner - || s->block_no != block_no - || pg_atomic_read_u32(&s->pincount) == 0) + if (!s->valid || s->io_in_progress || s->segment_id != segment_id || s->owner != owner + || s->block_no != block_no || pg_atomic_read_u32(&s->pincount) == 0) return false; if (!LWLockConditionalAcquire(&s->content_lock, LW_EXCLUSIVE)) return false; - exact = s->valid && !s->io_in_progress - && s->segment_id == segment_id && s->owner == owner - && s->block_no == block_no - && pg_atomic_read_u32(&s->pincount) > 0; + exact = s->valid && !s->io_in_progress && s->segment_id == segment_id && s->owner == owner + && s->block_no == block_no && pg_atomic_read_u32(&s->pincount) > 0; if (!exact) LWLockRelease(&s->content_lock); return exact; @@ -897,26 +891,21 @@ cluster_undo_buf_lock_ref_conditional(int slot, uint32 segment_id, void -cluster_undo_buf_install_ref_locked(int slot, uint32 segment_id, - uint8 owner, uint32 block_no, - const char image[BLCKSZ]) +cluster_undo_buf_install_ref_locked(int slot, uint32 segment_id, uint8 owner, uint32 block_no, + const char image[BLCKSZ]) { UndoBufSlot *s; - if (UndoBufPool == NULL || UndoBufSlots == NULL || image == NULL - || slot < 0 || slot >= UndoBufPool->nslots) - ereport(PANIC, - (errmsg("cluster undo prepared consume lost its buffer slot"))); + if (UndoBufPool == NULL || UndoBufSlots == NULL || image == NULL || slot < 0 + || slot >= UndoBufPool->nslots) + ereport(PANIC, (errmsg("cluster undo prepared consume lost its buffer slot"))); s = &UndoBufSlots[slot]; - if (!LWLockHeldByMe(&s->content_lock) - || !s->valid || s->io_in_progress - || s->segment_id != segment_id || s->owner != owner - || s->block_no != block_no + if (!LWLockHeldByMe(&s->content_lock) || !s->valid || s->io_in_progress + || s->segment_id != segment_id || s->owner != owner || s->block_no != block_no || pg_atomic_read_u32(&s->pincount) == 0) - ereport(PANIC, - (errmsg("cluster undo prepared consume lost exact resident authority " - "seg=%u owner=%u block=%u slot=%d", - segment_id, (unsigned int) owner, block_no, slot))); + ereport(PANIC, (errmsg("cluster undo prepared consume lost exact resident authority " + "seg=%u owner=%u block=%u slot=%d", + segment_id, (unsigned int)owner, block_no, slot))); memcpy(SLOT_DATA(slot), image, BLCKSZ); } @@ -926,15 +915,12 @@ cluster_undo_buf_unlock_ref(int slot) { UndoBufSlot *s; - if (UndoBufPool == NULL || UndoBufSlots == NULL - || slot < 0 || slot >= UndoBufPool->nslots) - ereport(PANIC, - (errmsg("cluster undo prepared consume cannot unlock its buffer slot"))); + if (UndoBufPool == NULL || UndoBufSlots == NULL || slot < 0 || slot >= UndoBufPool->nslots) + ereport(PANIC, (errmsg("cluster undo prepared consume cannot unlock its buffer slot"))); s = &UndoBufSlots[slot]; if (!LWLockHeldByMe(&s->content_lock)) ereport(PANIC, - (errmsg("cluster undo prepared consume does not hold buffer slot %d", - slot))); + (errmsg("cluster undo prepared consume does not hold buffer slot %d", slot))); LWLockRelease(&s->content_lock); } diff --git a/src/backend/cluster/storage/cluster_undo_smgr.c b/src/backend/cluster/storage/cluster_undo_smgr.c index 71f6b2de51c..eee54a26e97 100644 --- a/src/backend/cluster/storage/cluster_undo_smgr.c +++ b/src/backend/cluster/storage/cluster_undo_smgr.c @@ -130,11 +130,9 @@ provision_temp_name_class(const char *name, uint8 owner_instance) if (strncmp(name, "seg_", 4) != 0) return PROVISION_TEMP_NAME_MALFORMED; p = name + 4; - if (!provision_decimal_token(&p, &segment_id) - || segment_id == 0 || segment_id > UINT16_MAX + if (!provision_decimal_token(&p, &segment_id) || segment_id == 0 || segment_id > UINT16_MAX || strncmp(p, marker, sizeof(marker) - 1) != 0 - || ((segment_id - 1) / CLUSTER_UNDO_SEGS_PER_INSTANCE) + 1 - != (uint64)owner_instance) + || ((segment_id - 1) / CLUSTER_UNDO_SEGS_PER_INSTANCE) + 1 != (uint64)owner_instance) return PROVISION_TEMP_NAME_MALFORMED; p += sizeof(marker) - 1; start_begin = p; @@ -144,15 +142,13 @@ provision_temp_name_class(const char *name, uint8 owner_instance) if (!provision_decimal_token(&p, &ignored)) return PROVISION_TEMP_NAME_MALFORMED; pid_end = p; - if (*p++ != '.' - || !provision_decimal_token(&p, &ignored) || ignored == 0 || *p != '\0') + if (*p++ != '.' || !provision_decimal_token(&p, &ignored) || ignored == 0 || *p != '\0') return PROVISION_TEMP_NAME_MALFORMED; - start_len = snprintf(current_start, sizeof(current_start), "%lld", - (long long)MyStartTimestamp); + start_len = snprintf(current_start, sizeof(current_start), "%lld", (long long)MyStartTimestamp); pid_len = snprintf(current_pid, sizeof(current_pid), "%d", MyProcPid); - if (start_len < 0 || start_len >= (int)sizeof(current_start) - || pid_len < 0 || pid_len >= (int)sizeof(current_pid)) + if (start_len < 0 || start_len >= (int)sizeof(current_start) || pid_len < 0 + || pid_len >= (int)sizeof(current_pid)) return PROVISION_TEMP_NAME_MALFORMED; if ((size_t)start_len == (size_t)((pid_begin - 1) - start_begin) && memcmp(start_begin, current_start, (size_t)start_len) == 0 @@ -358,8 +354,7 @@ cluster_undo_smgr_probe_segment(ClusterUndoPathIntent intent, uint32 segment_id, return CLUSTER_UNDO_SMGR_FINAL_IO_ERROR; fd = BasicOpenFile(path, O_RDONLY | PG_BINARY); if (fd < 0) - return errno == ENOENT ? CLUSTER_UNDO_SMGR_FINAL_ABSENT - : CLUSTER_UNDO_SMGR_FINAL_IO_ERROR; + return errno == ENOENT ? CLUSTER_UNDO_SMGR_FINAL_ABSENT : CLUSTER_UNDO_SMGR_FINAL_IO_ERROR; if (fstat(fd, &st) != 0) { save_errno = errno; (void)close(fd); @@ -382,8 +377,7 @@ cluster_undo_smgr_probe_segment(ClusterUndoPathIntent intent, uint32 segment_id, if (close(fd) != 0) return CLUSTER_UNDO_SMGR_FINAL_IO_ERROR; if (nread != BLCKSZ - || !cluster_undo_segment_header_identity_ok(private_block.data, segment_id, - owner_instance)) + || !cluster_undo_segment_header_identity_ok(private_block.data, segment_id, owner_instance)) return CLUSTER_UNDO_SMGR_FINAL_INVALID; if (!provision_fsync_parent(path)) return CLUSTER_UNDO_SMGR_FINAL_IO_ERROR; @@ -431,8 +425,7 @@ provision_temp_owned(ClusterUndoPathIntent intent, uint32 segment_id, uint8 owne bool cluster_undo_smgr_provision_temp_create(ClusterUndoPathIntent intent, uint32 segment_id, - uint8 owner_instance, - char temp_path[MAXPGPATH]) + uint8 owner_instance, char temp_path[MAXPGPATH]) { char final_path[MAXPGPATH]; char prefix[MAXPGPATH]; @@ -479,8 +472,7 @@ cluster_undo_smgr_provision_temp_cleanup(ClusterUndoPathIntent intent, uint32 se bool -cluster_undo_smgr_cleanup_boot_foreign_temps(ClusterUndoPathIntent intent, - uint8 owner_instance) +cluster_undo_smgr_cleanup_boot_foreign_temps(ClusterUndoPathIntent intent, uint8 owner_instance) { char final_path[MAXPGPATH]; char directory[MAXPGPATH]; @@ -494,8 +486,9 @@ cluster_undo_smgr_cleanup_boot_foreign_temps(ClusterUndoPathIntent intent, if (owner_instance < 1 || owner_instance > UNDO_OWNER_INSTANCE_MAX) return false; first_segment = ((uint32)owner_instance - 1) * CLUSTER_UNDO_SEGS_PER_INSTANCE + 1; - if (cluster_undo_path_resolve(intent, owner_instance, first_segment, - final_path, sizeof(final_path)) != 0) + if (cluster_undo_path_resolve(intent, owner_instance, first_segment, final_path, + sizeof(final_path)) + != 0) return false; strlcpy(directory, final_path, sizeof(directory)); get_parent_directory(directory); @@ -518,9 +511,8 @@ cluster_undo_smgr_cleanup_boot_foreign_temps(ClusterUndoPathIntent intent, break; } ret = snprintf(candidate, sizeof(candidate), "%s/%s", directory, entry->d_name); - if (ret < 0 || ret >= (int)sizeof(candidate) - || lstat(candidate, &st) != 0 || !S_ISREG(st.st_mode) - || unlink(candidate) != 0) { + if (ret < 0 || ret >= (int)sizeof(candidate) || lstat(candidate, &st) != 0 + || !S_ISREG(st.st_mode) || unlink(candidate) != 0) { ok = false; break; } @@ -544,17 +536,15 @@ root_descriptor_path(const char *root_directory, char final_path[MAXPGPATH]) if (root_directory == NULL || root_directory[0] == '\0') return false; - ret = snprintf(final_path, MAXPGPATH, "%s/%s", root_directory, - PGRD_MIRROR_NAME); + ret = snprintf(final_path, MAXPGPATH, "%s/%s", root_directory, PGRD_MIRROR_NAME); return ret >= 0 && ret < MAXPGPATH; } static ClusterUndoSmgrRootMirrorState -root_descriptor_read( - const char *root_directory, - const uint8 expected[CLUSTER_UNDO_ROOT_DESCRIPTOR_BYTES], - uint8 observed[CLUSTER_UNDO_ROOT_DESCRIPTOR_BYTES]) +root_descriptor_read(const char *root_directory, + const uint8 expected[CLUSTER_UNDO_ROOT_DESCRIPTOR_BYTES], + uint8 observed[CLUSTER_UNDO_ROOT_DESCRIPTOR_BYTES]) { char final_path[MAXPGPATH]; uint8 image[CLUSTER_UNDO_ROOT_DESCRIPTOR_BYTES]; @@ -565,14 +555,12 @@ root_descriptor_read( int open_flags = O_RDONLY | PG_BINARY; int fd; - if (observed == NULL - || !root_descriptor_path(root_directory, final_path)) + if (observed == NULL || !root_descriptor_path(root_directory, final_path)) return CLUSTER_UNDO_SMGR_ROOT_MIRROR_IO_ERROR; if (lstat(final_path, &path_st) != 0) return errno == ENOENT ? CLUSTER_UNDO_SMGR_ROOT_MIRROR_ABSENT : CLUSTER_UNDO_SMGR_ROOT_MIRROR_IO_ERROR; - if (!S_ISREG(path_st.st_mode) - || path_st.st_size != CLUSTER_UNDO_ROOT_DESCRIPTOR_BYTES) + if (!S_ISREG(path_st.st_mode) || path_st.st_size != CLUSTER_UNDO_ROOT_DESCRIPTOR_BYTES) return CLUSTER_UNDO_SMGR_ROOT_MIRROR_HOLD; #ifdef O_NOFOLLOW @@ -592,10 +580,8 @@ root_descriptor_read( errno = save_errno; return CLUSTER_UNDO_SMGR_ROOT_MIRROR_IO_ERROR; } - if (!S_ISREG(fd_st.st_mode) - || fd_st.st_size != CLUSTER_UNDO_ROOT_DESCRIPTOR_BYTES - || fd_st.st_dev != path_st.st_dev - || fd_st.st_ino != path_st.st_ino) { + if (!S_ISREG(fd_st.st_mode) || fd_st.st_size != CLUSTER_UNDO_ROOT_DESCRIPTOR_BYTES + || fd_st.st_dev != path_st.st_dev || fd_st.st_ino != path_st.st_ino) { if (close(fd) != 0) return CLUSTER_UNDO_SMGR_ROOT_MIRROR_IO_ERROR; return CLUSTER_UNDO_SMGR_ROOT_MIRROR_HOLD; @@ -609,8 +595,7 @@ root_descriptor_read( } if (close(fd) != 0) return CLUSTER_UNDO_SMGR_ROOT_MIRROR_IO_ERROR; - if (nread != sizeof(image) - || (expected != NULL && memcmp(image, expected, sizeof(image)) != 0)) + if (nread != sizeof(image) || (expected != NULL && memcmp(image, expected, sizeof(image)) != 0)) return CLUSTER_UNDO_SMGR_ROOT_MIRROR_HOLD; if (!provision_fsync_parent(final_path)) return CLUSTER_UNDO_SMGR_ROOT_MIRROR_IO_ERROR; @@ -620,10 +605,9 @@ root_descriptor_read( ClusterUndoSmgrRootMirrorState -cluster_undo_smgr_root_descriptor_probe( - const char *root_directory, - const uint8 expected[CLUSTER_UNDO_ROOT_DESCRIPTOR_BYTES], - uint8 observed[CLUSTER_UNDO_ROOT_DESCRIPTOR_BYTES]) +cluster_undo_smgr_root_descriptor_probe(const char *root_directory, + const uint8 expected[CLUSTER_UNDO_ROOT_DESCRIPTOR_BYTES], + uint8 observed[CLUSTER_UNDO_ROOT_DESCRIPTOR_BYTES]) { if (expected == NULL) return CLUSTER_UNDO_SMGR_ROOT_MIRROR_IO_ERROR; @@ -632,18 +616,16 @@ cluster_undo_smgr_root_descriptor_probe( ClusterUndoSmgrRootMirrorState -cluster_undo_smgr_root_descriptor_read_candidate( - const char *root_directory, - uint8 observed[CLUSTER_UNDO_ROOT_DESCRIPTOR_BYTES]) +cluster_undo_smgr_root_descriptor_read_candidate(const char *root_directory, + uint8 observed[CLUSTER_UNDO_ROOT_DESCRIPTOR_BYTES]) { return root_descriptor_read(root_directory, NULL, observed); } ClusterUndoSmgrRootMirrorState -cluster_undo_smgr_root_descriptor_publish( - const char *root_directory, - const uint8 image[CLUSTER_UNDO_ROOT_DESCRIPTOR_BYTES]) +cluster_undo_smgr_root_descriptor_publish(const char *root_directory, + const uint8 image[CLUSTER_UNDO_ROOT_DESCRIPTOR_BYTES]) { char final_path[MAXPGPATH]; char temp_path[MAXPGPATH]; @@ -660,9 +642,8 @@ cluster_undo_smgr_root_descriptor_publish( counter = ++provision_temp_counter; if (counter == 0) return CLUSTER_UNDO_SMGR_ROOT_MIRROR_IO_ERROR; - ret = snprintf(temp_path, sizeof(temp_path), "%s%s%lld.%d." UINT64_FORMAT, - final_path, PGRD_MIRROR_TEMP_MARKER, - (long long)MyStartTimestamp, MyProcPid, counter); + ret = snprintf(temp_path, sizeof(temp_path), "%s%s%lld.%d." UINT64_FORMAT, final_path, + PGRD_MIRROR_TEMP_MARKER, (long long)MyStartTimestamp, MyProcPid, counter); if (ret < 0 || ret >= (int)sizeof(temp_path)) return CLUSTER_UNDO_SMGR_ROOT_MIRROR_IO_ERROR; fd = BasicOpenFile(temp_path, O_RDWR | O_CREAT | O_EXCL | PG_BINARY); @@ -684,9 +665,8 @@ cluster_undo_smgr_root_descriptor_publish( bool parent_ok = provision_fsync_parent(final_path); bool cleanup_ok = unlink(temp_path) == 0; - return parent_ok && cleanup_ok - ? CLUSTER_UNDO_SMGR_ROOT_MIRROR_PUBLISHED - : CLUSTER_UNDO_SMGR_ROOT_MIRROR_IO_ERROR; + return parent_ok && cleanup_ok ? CLUSTER_UNDO_SMGR_ROOT_MIRROR_PUBLISHED + : CLUSTER_UNDO_SMGR_ROOT_MIRROR_IO_ERROR; } if (errno != EEXIST) { (void)unlink(temp_path); @@ -694,8 +674,7 @@ cluster_undo_smgr_root_descriptor_publish( } if (unlink(temp_path) != 0) return CLUSTER_UNDO_SMGR_ROOT_MIRROR_IO_ERROR; - state = cluster_undo_smgr_root_descriptor_probe(root_directory, image, - observed); + state = cluster_undo_smgr_root_descriptor_probe(root_directory, image, observed); if (state == CLUSTER_UNDO_SMGR_ROOT_MIRROR_EXACT) return state; if (state == CLUSTER_UNDO_SMGR_ROOT_MIRROR_HOLD) @@ -748,7 +727,7 @@ cluster_undo_smgr_provision_temp_publish(ClusterUndoPathIntent intent, uint32 se (void)close(fd); errno = save_errno; (void)cluster_undo_smgr_provision_temp_cleanup(intent, segment_id, owner_instance, - temp_path); + temp_path); return CLUSTER_UNDO_SMGR_PUBLISH_IO_ERROR; } nwritten = pg_pwrite(fd, block0, BLCKSZ, 0); @@ -761,7 +740,7 @@ cluster_undo_smgr_provision_temp_publish(ClusterUndoPathIntent intent, uint32 se temp_ok = false; if (!temp_ok) { (void)cluster_undo_smgr_provision_temp_cleanup(intent, segment_id, owner_instance, - temp_path); + temp_path); return CLUSTER_UNDO_SMGR_PUBLISH_IO_ERROR; } @@ -772,26 +751,26 @@ cluster_undo_smgr_provision_temp_publish(ClusterUndoPathIntent intent, uint32 se * private name available for a retry: rewriting it would rewrite * the already-visible final file and defeat no-replace publication. */ - (void)cluster_undo_smgr_provision_temp_cleanup(intent, segment_id, - owner_instance, temp_path); + (void)cluster_undo_smgr_provision_temp_cleanup(intent, segment_id, owner_instance, + temp_path); return CLUSTER_UNDO_SMGR_PUBLISH_IO_ERROR; } if (!cluster_undo_smgr_provision_temp_cleanup(intent, segment_id, owner_instance, - temp_path)) + temp_path)) return CLUSTER_UNDO_SMGR_PUBLISH_IO_ERROR; return CLUSTER_UNDO_SMGR_PUBLISH_PUBLISHED; } if (errno != EEXIST) { (void)cluster_undo_smgr_provision_temp_cleanup(intent, segment_id, owner_instance, - temp_path); + temp_path); return CLUSTER_UNDO_SMGR_PUBLISH_IO_ERROR; } - final_state = cluster_undo_smgr_probe_segment(intent, segment_id, owner_instance, - observed.data); + final_state + = cluster_undo_smgr_probe_segment(intent, segment_id, owner_instance, observed.data); if (final_state == CLUSTER_UNDO_SMGR_FINAL_EXACT) { if (!cluster_undo_smgr_provision_temp_cleanup(intent, segment_id, owner_instance, - temp_path)) + temp_path)) return CLUSTER_UNDO_SMGR_PUBLISH_IO_ERROR; return CLUSTER_UNDO_SMGR_PUBLISH_EXISTS; } diff --git a/src/backend/cluster/storage/cluster_undo_xlog.c b/src/backend/cluster/storage/cluster_undo_xlog.c index 2eb1850eb1d..7277afaf487 100644 --- a/src/backend/cluster/storage/cluster_undo_xlog.c +++ b/src/backend/cluster/storage/cluster_undo_xlog.c @@ -223,9 +223,8 @@ cluster_undo_emit_segment_init(uint8 instance, uint32 segment_id, const char *pa * flush is required: the first dependent undo/heap WAL record follows it. */ XLogRecPtr -cluster_undo_emit_tt_slot_bind(uint8 instance, uint32 segment_id, - uint32 segment_generation, uint16 slot_offset, - uint16 wrap, TransactionId xid) +cluster_undo_emit_tt_slot_bind(uint8 instance, uint32 segment_id, uint32 segment_generation, + uint16 slot_offset, uint16 wrap, TransactionId xid) { xl_undo_tt_slot_bind rec; @@ -376,10 +375,8 @@ cluster_undo_emit_tt_slot_abort(uint8 instance, uint32 segment_id, uint16 slot_o } XLogRecPtr -cluster_undo_emit_tt_slot_abort_exact(uint8 instance, uint32 segment_id, - uint32 segment_generation, - uint16 slot_offset, uint16 wrap, - TransactionId xid) +cluster_undo_emit_tt_slot_abort_exact(uint8 instance, uint32 segment_id, uint32 segment_generation, + uint16 slot_offset, uint16 wrap, TransactionId xid) { xl_undo_tt_slot_abort_exact rec; XLogRecPtr lsn; @@ -440,38 +437,39 @@ cluster_undo_emit_tt_slot_set_head(uint8 instance, uint32 segment_id, uint16 slo * caller owns block-0 X-current and flushes this LSN before publishing the * exact TT release bit. */ XLogRecPtr -cluster_undo_xlog_insert_tt_ctrc_release( - const xl_undo_tt_slot_ctrc_release_v1 *record) +cluster_undo_xlog_insert_tt_ctrc_release(const xl_undo_tt_slot_ctrc_release_v1 *record) { uint8 bytes[CLUSTER_UNDO_TT_CTRC_RELEASE_BYTES]; if (!cluster_undo_tt_ctrc_release_encode(record, bytes)) - ereport(ERROR, - (errcode(ERRCODE_DATA_CORRUPTED), - errmsg("invalid canonical TT CTRC release certificate"), - errdetail("segment_id=%u segment_generation=%u xid=%u cluster_epoch=%u root_id=" UINT64_FORMAT " root_generation=" UINT64_FORMAT " formation_epoch=" UINT64_FORMAT " admission_generation=" UINT64_FORMAT " seal_generation=" UINT64_FORMAT " touched_low=" UINT64_FORMAT " touched_high=" UINT64_FORMAT " slot_offset=%u slot_wrap=%u owner_instance=%u terminal_status=%u format_version=%u flags=%u", - record != NULL ? record->segment_id : 0, - record != NULL ? record->segment_generation : 0, - record != NULL ? record->xid : 0, - record != NULL ? record->cluster_epoch : 0, - (uint64)(record != NULL ? record->root_id : 0), - (uint64)(record != NULL ? record->root_generation : 0), - (uint64)(record != NULL ? record->formation_epoch : 0), - (uint64)(record != NULL - ? record->admission_record_generation : 0), - (uint64)(record != NULL ? record->seal_generation : 0), - (uint64)(record != NULL ? record->touched_nodes_low : 0), - (uint64)(record != NULL ? record->touched_nodes_high : 0), - record != NULL ? record->slot_offset : 0, - record != NULL ? record->slot_wrap : 0, - record != NULL ? record->owner_instance : 0, - record != NULL ? record->terminal_status : 0, - record != NULL ? record->format_version : 0, - record != NULL ? record->flags : 0))); + ereport( + ERROR, + (errcode(ERRCODE_DATA_CORRUPTED), + errmsg("invalid canonical TT CTRC release certificate"), + errdetail( + "segment_id=%u segment_generation=%u xid=%u cluster_epoch=%u " + "root_id=" UINT64_FORMAT " root_generation=" UINT64_FORMAT + " formation_epoch=" UINT64_FORMAT " admission_generation=" UINT64_FORMAT + " seal_generation=" UINT64_FORMAT " touched_low=" UINT64_FORMAT + " touched_high=" UINT64_FORMAT " slot_offset=%u slot_wrap=%u owner_instance=%u " + "terminal_status=%u format_version=%u flags=%u", + record != NULL ? record->segment_id : 0, + record != NULL ? record->segment_generation : 0, record != NULL ? record->xid : 0, + record != NULL ? record->cluster_epoch : 0, + (uint64)(record != NULL ? record->root_id : 0), + (uint64)(record != NULL ? record->root_generation : 0), + (uint64)(record != NULL ? record->formation_epoch : 0), + (uint64)(record != NULL ? record->admission_record_generation : 0), + (uint64)(record != NULL ? record->seal_generation : 0), + (uint64)(record != NULL ? record->touched_nodes_low : 0), + (uint64)(record != NULL ? record->touched_nodes_high : 0), + record != NULL ? record->slot_offset : 0, record != NULL ? record->slot_wrap : 0, + record != NULL ? record->owner_instance : 0, + record != NULL ? record->terminal_status : 0, + record != NULL ? record->format_version : 0, record != NULL ? record->flags : 0))); XLogBeginInsert(); XLogRegisterData((char *)bytes, sizeof(bytes)); - return XLogInsert(RM_CLUSTER_UNDO_ID, - XLOG_UNDO_TT_SLOT_CTRC_RELEASE); + return XLogInsert(RM_CLUSTER_UNDO_ID, XLOG_UNDO_TT_SLOT_CTRC_RELEASE); } @@ -843,10 +841,8 @@ static const UBA InvalidUbaVal = InvalidUba_init; * is either an exact idempotent ACTIVE or recovery corruption. */ void -cluster_tt_durable_redo_bind_slot(uint8 instance, uint32 segment_id, - uint32 segment_generation, - uint16 slot_offset, uint16 wrap, - TransactionId xid) +cluster_tt_durable_redo_bind_slot(uint8 instance, uint32 segment_id, uint32 segment_generation, + uint16 slot_offset, uint16 wrap, TransactionId xid) { char path[MAXPGPATH]; int fd; @@ -858,27 +854,24 @@ cluster_tt_durable_redo_bind_slot(uint8 instance, uint32 segment_id, uint32 offset; ssize_t nread; - if (instance == 0 || instance > UNDO_OWNER_INSTANCE_MAX - || segment_id == 0 || slot_offset >= TT_SLOTS_PER_SEGMENT - || !TransactionIdIsNormal(xid) || wrap == TT_WRAP_INVALID - || (uint8)(((segment_id - 1) / CLUSTER_UNDO_SEGS_PER_INSTANCE) + 1) - != instance) - ereport(PANIC, - (errcode(ERRCODE_DATA_CORRUPTED), - errmsg("invalid canonical TT ACTIVE identity during redo"))); - if (build_undo_segment_path(cluster_undo_intent_for_owner(instance), - instance, segment_id, path, sizeof(path)) != 0) - ereport(PANIC, - (errmsg("undo segment path too long for TT ACTIVE redo: instance=%u seg=%u", - instance, segment_id))); + if (instance == 0 || instance > UNDO_OWNER_INSTANCE_MAX || segment_id == 0 + || slot_offset >= TT_SLOTS_PER_SEGMENT || !TransactionIdIsNormal(xid) + || wrap == TT_WRAP_INVALID + || (uint8)(((segment_id - 1) / CLUSTER_UNDO_SEGS_PER_INSTANCE) + 1) != instance) + ereport(PANIC, (errcode(ERRCODE_DATA_CORRUPTED), + errmsg("invalid canonical TT ACTIVE identity during redo"))); + if (build_undo_segment_path(cluster_undo_intent_for_owner(instance), instance, segment_id, path, + sizeof(path)) + != 0) + ereport(PANIC, (errmsg("undo segment path too long for TT ACTIVE redo: instance=%u seg=%u", + instance, segment_id))); /* A BIND delta cannot reconstruct a missing segment header/generation. */ fd = cluster_undo_redo_open_segment(instance, segment_id, path, false); if (fd < 0) ereport(PANIC, (errcode_for_file_access(), - errmsg("could not open undo segment file \"%s\" for TT ACTIVE redo: %m", - path))); + errmsg("could not open undo segment file \"%s\" for TT ACTIVE redo: %m", path))); nread = pg_pread(fd, blockbuf.data, BLCKSZ, 0); if (nread != BLCKSZ) { int save_errno = errno; @@ -886,22 +879,21 @@ cluster_tt_durable_redo_bind_slot(uint8 instance, uint32 segment_id, close(fd); errno = save_errno; ereport(PANIC, - (errcode_for_file_access(), - errmsg("could not read undo segment header \"%s\" for TT ACTIVE redo: read %zd of %d bytes", - path, nread, BLCKSZ))); + (errcode_for_file_access(), errmsg("could not read undo segment header \"%s\" for " + "TT ACTIVE redo: read %zd of %d bytes", + path, nread, BLCKSZ))); } if (header->segment_id != segment_id || header->owner_instance != instance || header->tt_slots_count != TT_SLOTS_PER_SEGMENT) { close(fd); ereport(PANIC, (errcode(ERRCODE_DATA_CORRUPTED), - errmsg("undo segment \"%s\" identity mismatch during TT ACTIVE redo", - path))); + errmsg("undo segment \"%s\" identity mismatch during TT ACTIVE redo", path))); } predecessor = &header->tt_slots[slot_offset]; - decision = cluster_tt_active_transition_decide( - predecessor, header->wrap_count, segment_generation, xid, wrap, true); + decision = cluster_tt_active_transition_decide(predecessor, header->wrap_count, + segment_generation, xid, wrap, true); switch (decision) { case CLUSTER_TT_ACTIVE_STALE: cluster_vis_bump_recovery_undo_redo_skips(); @@ -916,17 +908,15 @@ cluster_tt_durable_redo_bind_slot(uint8 instance, uint32 segment_id, successor.commit_scn = InvalidScn; successor.first_undo_block = InvalidUbaVal; offset = (uint32)offsetof(UndoSegmentHeaderData, tt_slots) - + (uint32)slot_offset * (uint32)sizeof(TTSlot); - if (pg_pwrite(fd, &successor, sizeof(successor), (off_t)offset) - != sizeof(successor)) { + + (uint32)slot_offset * (uint32)sizeof(TTSlot); + if (pg_pwrite(fd, &successor, sizeof(successor), (off_t)offset) != sizeof(successor)) { int save_errno = errno; close(fd); errno = save_errno; ereport(PANIC, (errcode_for_file_access(), - errmsg("could not write undo segment \"%s\" TT ACTIVE slot: %m", - path))); + errmsg("could not write undo segment \"%s\" TT ACTIVE slot: %m", path))); } if (pg_fsync(fd) != 0) { int save_errno = errno; @@ -935,8 +925,7 @@ cluster_tt_durable_redo_bind_slot(uint8 instance, uint32 segment_id, errno = save_errno; ereport(PANIC, (errcode_for_file_access(), - errmsg("could not fsync undo segment \"%s\" after TT ACTIVE redo: %m", - path))); + errmsg("could not fsync undo segment \"%s\" after TT ACTIVE redo: %m", path))); } cluster_vis_bump_recovery_undo_redo_applies(); break; @@ -944,19 +933,18 @@ cluster_tt_durable_redo_bind_slot(uint8 instance, uint32 segment_id, case CLUSTER_TT_ACTIVE_CORRUPT: default: close(fd); - ereport(PANIC, - (errcode(ERRCODE_DATA_CORRUPTED), - errmsg("undo segment \"%s\" has conflicting TT ACTIVE predecessor", - path), - errdetail("segment_generation=%u disk_generation=%u slot=%u wrap=%u xid=%u decision=%d", - segment_generation, header->wrap_count, slot_offset, - wrap, xid, (int)decision))); + ereport( + PANIC, + (errcode(ERRCODE_DATA_CORRUPTED), + errmsg("undo segment \"%s\" has conflicting TT ACTIVE predecessor", path), + errdetail( + "segment_generation=%u disk_generation=%u slot=%u wrap=%u xid=%u decision=%d", + segment_generation, header->wrap_count, slot_offset, wrap, xid, (int)decision))); } if (close(fd) != 0) - ereport(PANIC, - (errcode_for_file_access(), - errmsg("could not close undo segment file \"%s\": %m", path))); + ereport(PANIC, (errcode_for_file_access(), + errmsg("could not close undo segment file \"%s\": %m", path))); } /* @@ -1092,8 +1080,7 @@ cluster_tt_durable_redo_stamp_slot(uint8 instance, uint32 segment_id, uint16 slo void cluster_tt_durable_redo_stamp_slot_exact(uint8 instance, uint32 segment_id, - uint32 segment_generation, - uint16 slot_offset, uint16 wrap, + uint32 segment_generation, uint16 slot_offset, uint16 wrap, TransactionId xid, SCN commit_scn) { char path[MAXPGPATH]; @@ -1104,51 +1091,44 @@ cluster_tt_durable_redo_stamp_slot_exact(uint8 instance, uint32 segment_id, ClusterTTTerminalTransitionDecision decision; ssize_t nread; - if (instance == 0 || segment_id == 0 - || segment_generation == UINT32_MAX - || slot_offset >= TT_SLOTS_PER_SEGMENT - || wrap == TT_WRAP_INVALID || !TransactionIdIsNormal(xid) - || !SCN_VALID(commit_scn)) - ereport(PANIC, - (errcode(ERRCODE_DATA_CORRUPTED), - errmsg("invalid exact canonical TT commit redo identity"))); - if (build_undo_segment_path(cluster_undo_intent_for_owner(instance), - instance, segment_id, path, sizeof(path)) != 0) + if (instance == 0 || segment_id == 0 || segment_generation == UINT32_MAX + || slot_offset >= TT_SLOTS_PER_SEGMENT || wrap == TT_WRAP_INVALID + || !TransactionIdIsNormal(xid) || !SCN_VALID(commit_scn)) + ereport(PANIC, (errcode(ERRCODE_DATA_CORRUPTED), + errmsg("invalid exact canonical TT commit redo identity"))); + if (build_undo_segment_path(cluster_undo_intent_for_owner(instance), instance, segment_id, path, + sizeof(path)) + != 0) ereport(PANIC, - (errmsg("undo segment path too long: instance=%u seg=%u", - instance, segment_id))); + (errmsg("undo segment path too long: instance=%u seg=%u", instance, segment_id))); fd = cluster_undo_redo_open_segment(instance, segment_id, path, false); if (fd < 0) - ereport(PANIC, - (errcode_for_file_access(), - errmsg("could not open undo segment file \"%s\" for exact TT commit redo: %m", - path))); + ereport( + PANIC, + (errcode_for_file_access(), + errmsg("could not open undo segment file \"%s\" for exact TT commit redo: %m", path))); nread = pg_pread(fd, blockbuf.data, BLCKSZ, 0); if (nread != BLCKSZ) { int save_errno = errno; close(fd); errno = save_errno; - ereport(PANIC, - (errcode_for_file_access(), - errmsg("could not read undo segment header \"%s\": read %zd of %d bytes", - path, nread, BLCKSZ))); + ereport(PANIC, (errcode_for_file_access(), + errmsg("could not read undo segment header \"%s\": read %zd of %d bytes", + path, nread, BLCKSZ))); } header = (UndoSegmentHeaderData *)blockbuf.data; - if (header->segment_id != segment_id - || header->owner_instance != instance + if (header->segment_id != segment_id || header->owner_instance != instance || header->tt_slots_count != TT_SLOTS_PER_SEGMENT) { close(fd); ereport(PANIC, (errcode(ERRCODE_DATA_CORRUPTED), - errmsg("undo segment \"%s\" has conflicting exact TT commit header", - path))); + errmsg("undo segment \"%s\" has conflicting exact TT commit header", path))); } slot = &header->tt_slots[slot_offset]; - decision = cluster_tt_terminal_transition_decide( - slot, header->wrap_count, segment_generation, xid, wrap, - TT_SLOT_COMMITTED, commit_scn); + decision = cluster_tt_terminal_transition_decide(slot, header->wrap_count, segment_generation, + xid, wrap, TT_SLOT_COMMITTED, commit_scn); if (decision == CLUSTER_TT_TERMINAL_STALE) { cluster_vis_bump_recovery_undo_redo_skips(); } else if (decision == CLUSTER_TT_TERMINAL_IDEMPOTENT) { @@ -1166,10 +1146,12 @@ cluster_tt_durable_redo_stamp_slot_exact(uint8 instance, uint32 segment_id, close(fd); errno = save_errno; - ereport(PANIC, - (errcode_for_file_access(), - errmsg("could not write undo segment \"%s\" exact TT commit: wrote %zd of %d bytes", - path, written, BLCKSZ))); + ereport( + PANIC, + (errcode_for_file_access(), + errmsg( + "could not write undo segment \"%s\" exact TT commit: wrote %zd of %d bytes", + path, written, BLCKSZ))); } if (pg_fsync(fd) != 0) { int save_errno = errno; @@ -1187,16 +1169,14 @@ cluster_tt_durable_redo_stamp_slot_exact(uint8 instance, uint32 segment_id, close(fd); ereport(PANIC, (errcode(ERRCODE_DATA_CORRUPTED), - errmsg("undo segment \"%s\" has conflicting exact TT commit predecessor", - path), + errmsg("undo segment \"%s\" has conflicting exact TT commit predecessor", path), errdetail("generation=%u disk_generation=%u slot=%u wrap=%u xid=%u decision=%d", - segment_generation, header->wrap_count, slot_offset, - wrap, xid, (int)decision))); + segment_generation, header->wrap_count, slot_offset, wrap, xid, + (int)decision))); } if (close(fd) != 0) - ereport(PANIC, - (errcode_for_file_access(), - errmsg("could not close undo segment file \"%s\": %m", path))); + ereport(PANIC, (errcode_for_file_access(), + errmsg("could not close undo segment file \"%s\": %m", path))); } /* @@ -1207,9 +1187,8 @@ cluster_tt_durable_redo_stamp_slot_exact(uint8 instance, uint32 segment_id, static void cluster_undo_redo_tt_slot_commit(const ClusterUndoDecoded *decoded) { - cluster_tt_durable_redo_stamp_slot(decoded->instance, decoded->segment_id, - decoded->slot_offset, decoded->wrap, decoded->xid, - decoded->commit_scn); + cluster_tt_durable_redo_stamp_slot(decoded->instance, decoded->segment_id, decoded->slot_offset, + decoded->wrap, decoded->xid, decoded->commit_scn); } @@ -1223,15 +1202,14 @@ cluster_undo_redo_tt_slot_commit(const ClusterUndoDecoded *decoded) static void cluster_undo_redo_tt_slot_abort(const ClusterUndoDecoded *decoded) { - if (decoded->format_version == CLUSTER_UNDO_TT_ABORT_EXACT_VERSION) - { - cluster_tt_durable_redo_abort_slot_exact(decoded->instance, - decoded->segment_id, decoded->expected_generation, - decoded->slot_offset, decoded->wrap, decoded->xid); + if (decoded->format_version == CLUSTER_UNDO_TT_ABORT_EXACT_VERSION) { + cluster_tt_durable_redo_abort_slot_exact(decoded->instance, decoded->segment_id, + decoded->expected_generation, decoded->slot_offset, + decoded->wrap, decoded->xid); return; } - cluster_tt_durable_redo_abort_slot(decoded->instance, decoded->segment_id, - decoded->slot_offset, decoded->wrap, decoded->xid); + cluster_tt_durable_redo_abort_slot(decoded->instance, decoded->segment_id, decoded->slot_offset, + decoded->wrap, decoded->xid); } @@ -1249,9 +1227,9 @@ cluster_undo_redo_tt_slot_abort(const ClusterUndoDecoded *decoded) static void cluster_undo_redo_tt_slot_set_head(const ClusterUndoDecoded *decoded) { - cluster_tt_durable_redo_set_head_slot(decoded->instance, - decoded->segment_id, decoded->slot_offset, decoded->wrap, - decoded->xid, decoded->first_undo_block); + cluster_tt_durable_redo_set_head_slot(decoded->instance, decoded->segment_id, + decoded->slot_offset, decoded->wrap, decoded->xid, + decoded->first_undo_block); } /* Replay the exact CTRC release certificate without consulting live @@ -1271,13 +1249,11 @@ cluster_undo_redo_tt_ctrc_release(const ClusterUndoDecoded *decoded) record.root_id = decoded->root_id; record.root_generation = decoded->root_generation; record.formation_epoch = decoded->formation_epoch; - record.admission_record_generation - = decoded->admission_record_generation; + record.admission_record_generation = decoded->admission_record_generation; record.seal_generation = decoded->seal_generation; record.touched_nodes_low = decoded->touched_nodes_low; record.touched_nodes_high = decoded->touched_nodes_high; - memcpy(record.ack_set_digest, decoded->ack_set_digest, - sizeof(record.ack_set_digest)); + memcpy(record.ack_set_digest, decoded->ack_set_digest, sizeof(record.ack_set_digest)); record.slot_offset = decoded->slot_offset; record.slot_wrap = decoded->wrap; record.owner_instance = decoded->instance; @@ -1285,9 +1261,8 @@ cluster_undo_redo_tt_ctrc_release(const ClusterUndoDecoded *decoded) record.format_version = decoded->format_version; record.flags = decoded->flags; if (!cluster_undo_tt_ctrc_release_valid(&record)) - ereport(PANIC, - (errcode(ERRCODE_DATA_CORRUPTED), - errmsg("invalid decoded TT CTRC release certificate"))); + ereport(PANIC, (errcode(ERRCODE_DATA_CORRUPTED), + errmsg("invalid decoded TT CTRC release certificate"))); cluster_tt_durable_redo_ctrc_release_slot_exact(&record); } @@ -1826,21 +1801,20 @@ cluster_undo_redo(XLogReaderState *record) * the separate canonical shared SPACE ABI is approved. */ memset(&decoded, 0, sizeof(decoded)); - if (!cluster_undo_decode(record, &decoded) || - decoded.opcode != info || !cluster_undo_preflight(&decoded)) + if (!cluster_undo_decode(record, &decoded) || decoded.opcode != info + || !cluster_undo_preflight(&decoded)) ereport(PANIC, (errcode(ERRCODE_DATA_CORRUPTED), - errmsg("invalid cluster undo record %u during shared decode preflight", - info))); + errmsg("invalid cluster undo record %u during shared decode preflight", info))); switch (info) { case XLOG_UNDO_SEGMENT_INIT: cluster_undo_redo_segment_init(record); break; case XLOG_UNDO_TT_SLOT_BIND: - cluster_tt_durable_redo_bind_slot(decoded.instance, - decoded.segment_id, decoded.expected_generation, - decoded.slot_offset, decoded.wrap, decoded.xid); + cluster_tt_durable_redo_bind_slot(decoded.instance, decoded.segment_id, + decoded.expected_generation, decoded.slot_offset, + decoded.wrap, decoded.xid); break; case XLOG_UNDO_TT_SLOT_COMMIT: cluster_undo_redo_tt_slot_commit(&decoded); diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c index 4f75191b782..cf640c68703 100644 --- a/src/bin/initdb/initdb.c +++ b/src/bin/initdb/initdb.c @@ -3611,7 +3611,7 @@ pgrac_wal_state_validate_handoff(char *thread_name, size_t thread_name_size) char *resolved_root; char *resolved_xlog; char xlog_parent[MAXPGPATH]; - char *separator; + const char *separator; unsigned int thread_id; char extra; @@ -3660,7 +3660,7 @@ static void pgrac_wal_state_check_root_entries(const char *thread_name, bool allow_registry) { DIR *dir; - struct dirent *entry; + const struct dirent *entry; char unexpected[MAXPGPATH] = ""; dir = opendir(pgrac_wal_state_root); diff --git a/src/common/Makefile b/src/common/Makefile index aeff996dae0..90a718b1386 100644 --- a/src/common/Makefile +++ b/src/common/Makefile @@ -118,6 +118,17 @@ OBJS_FRONTEND = \ OBJS_SHLIB = $(OBJS_FRONTEND_SHLIB:%.o=%_shlib.o) OBJS_SRV = $(OBJS_COMMON:%.o=%_srv.o) +# PGRAC: CTRC certificates use the allocation-free, stack-based SHA-256 +# implementation while holding shared-state locks. OpenSSL remains the +# provider for pg_cryptohash; keep the existing certificate implementation +# available in the cluster server archive as well. The non-SSL branch above +# already includes sha2.o, and disable-cluster keeps the upstream object set. +ifeq ($(enable_pgrac_cluster),yes) +ifeq ($(with_ssl),openssl) +OBJS_SRV += sha2_srv.o +endif +endif + # where to find gen_keywordlist.pl and subsidiary files TOOLSDIR = $(top_srcdir)/src/tools GEN_KEYWORDLIST = $(PERL) -I $(TOOLSDIR) $(TOOLSDIR)/gen_keywordlist.pl diff --git a/src/include/cluster/cluster_cf_phase2.h b/src/include/cluster/cluster_cf_phase2.h index 96477333c22..1c37ea77bee 100644 --- a/src/include/cluster/cluster_cf_phase2.h +++ b/src/include/cluster/cluster_cf_phase2.h @@ -61,9 +61,9 @@ typedef struct ClusterCfPhase2RecordV2 { uint8 kind; uint8 reserved; int32 probe_owner_node; - int32 responder_node; /* CLUSTER_CF_P2_PROBE uses -1 */ + int32 responder_node; /* CLUSTER_CF_P2_PROBE uses -1 */ uint64 probe_nonce; - pg_crc32c crc; /* over [0, offsetof(crc)) */ + pg_crc32c crc; /* over [0, offsetof(crc)) */ } ClusterCfPhase2RecordV2; /* @@ -76,11 +76,10 @@ extern bool cluster_cf_phase2_write_probe(const char *shared_dir, int probe_owne uint64 probe_nonce); extern bool cluster_cf_phase2_read_probe(const char *shared_dir, int probe_owner, ClusterCfPhase2RecordV2 *out); -extern bool cluster_cf_phase2_write_ack(const char *shared_dir, int probe_owner, - int responder, uint64 probe_nonce); +extern bool cluster_cf_phase2_write_ack(const char *shared_dir, int probe_owner, int responder, + uint64 probe_nonce); extern bool cluster_cf_phase2_read_exact_ack(const char *shared_dir, int probe_owner, - int expected_responder, - uint64 expected_nonce); + int expected_responder, uint64 expected_nonce); /* * Steady-state probe responder (spec-5.6a): acks any configured peer's diff --git a/src/include/cluster/cluster_control_root.h b/src/include/cluster/cluster_control_root.h index e665b860eef..05a53f6d780 100644 --- a/src/include/cluster/cluster_control_root.h +++ b/src/include/cluster/cluster_control_root.h @@ -52,14 +52,14 @@ /* Bit 0 is the already-frozen R4 synchronous-CR semantic feature. Keep the * complete root-v1 known set public so every reader rejects the same unknown * bits; inclusion here is understanding, not activation. */ -#define PGRAC_CONTROL_ROOT_FEATURE_KNOWN_MASK_V1 \ - ((UINT64_C(1) << 0) | PGRAC_CONTROL_ROOT_FEATURE_WAL_REUSE_V1 | \ - PGRAC_CONTROL_ROOT_FEATURE_PAGE_STABLE_BASE_V1 | \ - PGRAC_CONTROL_ROOT_FEATURE_SPACE_METADATA_V1 | \ - PGRAC_CONTROL_ROOT_FEATURE_CONSERVATIVE_COMMIT_SCN_V1 | \ - PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1 | \ - PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_SERIAL_V1 | \ - PGRAC_CONTROL_ROOT_FEATURE_EXTERNAL_FENCE_V1) +#define PGRAC_CONTROL_ROOT_FEATURE_KNOWN_MASK_V1 \ + ((UINT64_C(1) << 0) | PGRAC_CONTROL_ROOT_FEATURE_WAL_REUSE_V1 \ + | PGRAC_CONTROL_ROOT_FEATURE_PAGE_STABLE_BASE_V1 \ + | PGRAC_CONTROL_ROOT_FEATURE_SPACE_METADATA_V1 \ + | PGRAC_CONTROL_ROOT_FEATURE_CONSERVATIVE_COMMIT_SCN_V1 \ + | PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1 \ + | PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_SERIAL_V1 \ + | PGRAC_CONTROL_ROOT_FEATURE_EXTERNAL_FENCE_V1) typedef enum ClusterControlRootLifecycle { CLUSTER_CONTROL_ROOT_LIFECYCLE_UNUSED = 0, @@ -248,8 +248,7 @@ typedef struct ClusterControlRootFileToken { uint8 image_sha256[32]; } ClusterControlRootFileToken; -StaticAssertDecl(sizeof(ClusterControlRootIdentity) == 80, - "ClusterControlRootIdentity ABI"); +StaticAssertDecl(sizeof(ClusterControlRootIdentity) == 80, "ClusterControlRootIdentity ABI"); StaticAssertDecl(offsetof(ClusterControlRootIdentity, system_identifier) == 0, "control-root system identifier offset"); StaticAssertDecl(offsetof(ClusterControlRootIdentity, storage_uuid) == 8, @@ -272,8 +271,7 @@ StaticAssertDecl(offsetof(ClusterControlRootIdentity, origin_owner_incarnation) "control-root owner offset"); StaticAssertDecl(offsetof(ClusterControlRootIdentity, root_lineage_seq) == 72, "control-root lineage offset"); -StaticAssertDecl(sizeof(ClusterControlRootSnapshot) == 216, - "ClusterControlRootSnapshot ABI"); +StaticAssertDecl(sizeof(ClusterControlRootSnapshot) == 216, "ClusterControlRootSnapshot ABI"); StaticAssertDecl(offsetof(ClusterControlRootSnapshot, lifecycle) == 80, "control-root lifecycle offset"); StaticAssertDecl(offsetof(ClusterControlRootSnapshot, root_flags) == 84, @@ -324,8 +322,7 @@ StaticAssertDecl(offsetof(ClusterControlRootSnapshot, lifecycle_reason) == 204, "control-root lifecycle reason offset"); StaticAssertDecl(offsetof(ClusterControlRootSnapshot, reserved208) == 208, "control-root reserved208 offset"); -StaticAssertDecl(sizeof(ClusterControlRootReadToken) == 64, - "ClusterControlRootReadToken ABI"); +StaticAssertDecl(sizeof(ClusterControlRootReadToken) == 64, "ClusterControlRootReadToken ABI"); StaticAssertDecl(offsetof(ClusterControlRootReadToken, authority_uuid) == 0, "control-root token authority offset"); StaticAssertDecl(offsetof(ClusterControlRootReadToken, origin_thread_id) == 16, @@ -348,10 +345,8 @@ StaticAssertDecl(offsetof(ClusterControlRootReadToken, record_crc32c) == 56, "control-root token CRC offset"); StaticAssertDecl(offsetof(ClusterControlRootReadToken, root_flags) == 60, "control-root token flags offset"); -StaticAssertDecl(sizeof(ClusterControlRootPatch) == 248, - "ClusterControlRootPatch ABI"); -StaticAssertDecl(offsetof(ClusterControlRootPatch, mask) == 0, - "control-root patch mask offset"); +StaticAssertDecl(sizeof(ClusterControlRootPatch) == 248, "ClusterControlRootPatch ABI"); +StaticAssertDecl(offsetof(ClusterControlRootPatch, mask) == 0, "control-root patch mask offset"); StaticAssertDecl(offsetof(ClusterControlRootPatch, expected_lifecycle) == 8, "control-root patch lifecycle offset"); StaticAssertDecl(offsetof(ClusterControlRootPatch, expected_flags_mask) == 12, @@ -402,8 +397,7 @@ StaticAssertDecl(offsetof(ClusterControlRootMigrationRoundV1, coordinator_node_i "control-root round coordinator node offset"); StaticAssertDecl(offsetof(ClusterControlRootMigrationRoundV1, reserved76) == 76, "control-root round reserved offset"); -StaticAssertDecl(sizeof(ClusterControlRootFileToken) == 80, - "ClusterControlRootFileToken ABI"); +StaticAssertDecl(sizeof(ClusterControlRootFileToken) == 80, "ClusterControlRootFileToken ABI"); StaticAssertDecl(offsetof(ClusterControlRootFileToken, authority_uuid) == 0, "control-root file token authority offset"); StaticAssertDecl(offsetof(ClusterControlRootFileToken, file_txn_seq) == 16, @@ -432,10 +426,8 @@ extern ClusterControlRootResult cluster_control_root_read_canonical( /* RF-ROOT P9 verification (implementation): verify the canonical root is ACTIVE and * bound to exactly this cutover round (full canonical validation, read-only * proof; returns a file token for the caller's freshness binding). */ -extern ClusterControlRootResult -cluster_control_root_bootstrap_validate_active_round( - const ClusterControlRootMigrationRoundV1 *round, - ClusterControlRootFileToken *token); +extern ClusterControlRootResult cluster_control_root_bootstrap_validate_active_round( + const ClusterControlRootMigrationRoundV1 *round, ClusterControlRootFileToken *token); /* RF-ROOT P9 verification (cold-formation): member-side field binding — * ACTIVE root bound to the round identity a member holds (epoch / @@ -443,19 +435,19 @@ cluster_control_root_bootstrap_validate_active_round( * full round + its sha are coordinator-local (seam shmem), so members * cannot recompute round_sha256; the identity fields + the root's own * CRC/dual-copy validation bind the round. */ -extern ClusterControlRootResult -cluster_control_root_bootstrap_validate_active_round_fields( - uint64 transition_epoch, uint64 prepare_generation, - uint64 source_feature_bitmap, uint64 target_feature_bitmap); +extern ClusterControlRootResult cluster_control_root_bootstrap_validate_active_round_fields( + uint64 transition_epoch, uint64 prepare_generation, uint64 source_feature_bitmap, + uint64 target_feature_bitmap); /* RF-ROOT P9 verification (contract): re-arm the bit22 cutover latch from a * durable ACTIVE root across a postmaster restart. Returns whether the * dual-path gate reads as post-bit22 afterwards. */ extern bool cluster_control_root_restore_bit22_latch_if_active(void); -extern ClusterControlRootResult cluster_control_root_read_canonical_discovered( - uint16 origin_thread_id, ClusterControlRootSnapshot *out_snapshot, - ClusterControlRootReadToken *out_token); +extern ClusterControlRootResult +cluster_control_root_read_canonical_discovered(uint16 origin_thread_id, + ClusterControlRootSnapshot *out_snapshot, + ClusterControlRootReadToken *out_token); /* Stage 8 contract (verified implementation): lock-free canonical read for a DEAD * origin's thread — no live writer exists (the only publisher was the dead * postmaster) and the GRD recovery adopts each shard to exactly one @@ -463,41 +455,39 @@ extern ClusterControlRootResult cluster_control_root_read_canonical_discovered( * Used by the post-bit22 hw-remaster path while the GRD recovery holds the * CF shard FROZEN (CF(S) itself unavailable), breaking the remaster -> * unfreeze -> CF-shard-NORMAL deadlock. */ -extern ClusterControlRootResult cluster_control_root_read_canonical_dead_origin( - uint16 origin_thread_id, ClusterControlRootSnapshot *out_snapshot); +extern ClusterControlRootResult +cluster_control_root_read_canonical_dead_origin(uint16 origin_thread_id, + ClusterControlRootSnapshot *out_snapshot); extern ClusterControlRootResult cluster_control_root_lookup_owner_by_node_runtime( int32 old_node_id, ClusterControlRootIdentity *out_identity, ClusterControlRootSnapshot *out_snapshot, ClusterControlRootReadToken *out_token); extern ClusterControlRootResult cluster_control_root_compare_and_publish( - const ClusterControlRootReadToken *expected_token, - const ClusterControlRootPatch *patch, ClusterControlRootPublishReason reason, - ClusterControlRootSnapshot *out_snapshot, ClusterControlRootReadToken *out_token); -extern ClusterControlRootResult cluster_control_root_revalidate( - const ClusterControlRootReadToken *token, - const ClusterControlRootIdentity *expected_identity, - ClusterControlRootSnapshot *out_snapshot); + const ClusterControlRootReadToken *expected_token, const ClusterControlRootPatch *patch, + ClusterControlRootPublishReason reason, ClusterControlRootSnapshot *out_snapshot, + ClusterControlRootReadToken *out_token); +extern ClusterControlRootResult +cluster_control_root_revalidate(const ClusterControlRootReadToken *token, + const ClusterControlRootIdentity *expected_identity, + ClusterControlRootSnapshot *out_snapshot); extern bool cluster_control_root_identity_equal(const ClusterControlRootIdentity *left, - const ClusterControlRootIdentity *right); + const ClusterControlRootIdentity *right); extern bool cluster_control_root_feature_bitmap_is_known(uint64 active_feature_bitmap); -extern ClusterControlRootResult cluster_control_root_create_prepared( - const ClusterControlRootMigrationImage *image, - const ClusterControlRootMigrationRoundV1 *round, - ClusterControlRootFileToken *out_token); +extern ClusterControlRootResult +cluster_control_root_create_prepared(const ClusterControlRootMigrationImage *image, + const ClusterControlRootMigrationRoundV1 *round, + ClusterControlRootFileToken *out_token); extern ClusterControlRootResult cluster_control_root_activate_prepared( - const ClusterControlRootFileToken *expected_token, - const uint8 expected_round_sha256[32], - const ClusterControlRootMigrationRoundV1 *round, - ClusterControlRootFileToken *out_token); -extern bool cluster_control_root_round_sha256( - const ClusterControlRootMigrationRoundV1 *round, - uint8 out_sha[PG_SHA256_DIGEST_LENGTH]); + const ClusterControlRootFileToken *expected_token, const uint8 expected_round_sha256[32], + const ClusterControlRootMigrationRoundV1 *round, ClusterControlRootFileToken *out_token); +extern bool cluster_control_root_round_sha256(const ClusterControlRootMigrationRoundV1 *round, + uint8 out_sha[PG_SHA256_DIGEST_LENGTH]); /* contract step ④d: construct the create_prepared migration image from the * live registry + claims + membership (coordinator side). */ -extern ClusterControlRootResult cluster_control_root_build_migration_image( - const ClusterControlRootMigrationRoundV1 *round, - ClusterControlRootMigrationImage *out); -extern ClusterControlRootResult cluster_control_root_discard_inactive( - const ClusterControlRootFileToken *expected_token, - const uint8 expected_round_sha256[32]); +extern ClusterControlRootResult +cluster_control_root_build_migration_image(const ClusterControlRootMigrationRoundV1 *round, + ClusterControlRootMigrationImage *out); +extern ClusterControlRootResult +cluster_control_root_discard_inactive(const ClusterControlRootFileToken *expected_token, + const uint8 expected_round_sha256[32]); #endif /* CLUSTER_CONTROL_ROOT_H */ diff --git a/src/include/cluster/cluster_cr.h b/src/include/cluster/cluster_cr.h index 70fb8e658c7..44e4b408691 100644 --- a/src/include/cluster/cluster_cr.h +++ b/src/include/cluster/cluster_cr.h @@ -86,10 +86,11 @@ cluster_cr_r4_dependency_request_id(uint32 slot_index, uint64 slot_generation, u return (slot_generation << 18) | ((uint64)(build_steps - 1) << 2) | slot_index; } -extern ClusterR4CrBuildStepResult cluster_cr_build_on_holder_step( - uint32 slot_index, uint64 slot_generation, bool foreign_undo_ready, - ClusterR4CrSlotExtension *extension, char result_page[BLCKSZ], - const char foreign_undo_page[BLCKSZ], ClusterCrBuildReason *reason_out); +extern ClusterR4CrBuildStepResult +cluster_cr_build_on_holder_step(uint32 slot_index, uint64 slot_generation, bool foreign_undo_ready, + ClusterR4CrSlotExtension *extension, char result_page[BLCKSZ], + const char foreign_undo_page[BLCKSZ], + ClusterCrBuildReason *reason_out); /* * Extract one exact transaction member from an already-resident private DATA * block. This helper performs no I/O and touches no shared state. On success @@ -97,12 +98,13 @@ extern ClusterR4CrBuildStepResult cluster_cr_build_on_holder_step( * TT_WRAP_INVALID may be upgraded once from record.tt_wrap_plus1. On failure * every output is left byte-for-byte unchanged. */ -extern bool cluster_cr_r4_extract_resident_record( - const char resident_undo_page[BLCKSZ], - const ClusterTxLocator *request_locator, char record_out[BLCKSZ], - size_t *record_length_out, ClusterTxLocator *canonical_locator_out); -extern bool cluster_cr_build_on_holder_pending_locator( - uint32 slot_index, uint64 slot_generation, ClusterTxLocator *locator_out); +extern bool cluster_cr_r4_extract_resident_record(const char resident_undo_page[BLCKSZ], + const ClusterTxLocator *request_locator, + char record_out[BLCKSZ], + size_t *record_length_out, + ClusterTxLocator *canonical_locator_out); +extern bool cluster_cr_build_on_holder_pending_locator(uint32 slot_index, uint64 slot_generation, + ClusterTxLocator *locator_out); extern void cluster_cr_build_on_holder_forget(uint32 slot_index, uint64 slot_generation); #endif diff --git a/src/include/cluster/cluster_cr_server.h b/src/include/cluster/cluster_cr_server.h index 01dffccf1e8..622b4978709 100644 --- a/src/include/cluster/cluster_cr_server.h +++ b/src/include/cluster/cluster_cr_server.h @@ -62,7 +62,7 @@ #include "cluster/cluster_multixact_current.h" #include "cluster/cluster_runtime_visibility.h" /* ClusterLiveAuthority (spec-6.12i) */ #include "cluster/cluster_semantic_activation.h" -#include "cluster/cluster_tt_durable.h" /* ClusterTTDurableResolve */ +#include "cluster/cluster_tt_durable.h" /* ClusterTTDurableResolve */ #include "cluster/cluster_undo_verdict.h" /* ClusterUndoVerdictResult (spec-5.22d D4-6) */ /* Split verdict for the server-side construction (see banner). */ @@ -126,34 +126,35 @@ extern bool cluster_cr_server_live_binding_exact(bool xid_is_mine, uint32 expect * carrier/window doubt remain UNKNOWN_FAIL_CLOSED. */ extern ClusterUndoVerdictKind cluster_cr_server_c0_zero_match_verdict( - bool authoritative, bool xid_is_mine, uint32 expected_segment_id, - uint32 expected_tt_slot_id, bool no_raw_reuse_window, bool clog_is_committed, - bool clog_is_aborted, bool clog_is_in_progress, bool xid_is_in_progress); + bool authoritative, bool xid_is_mine, uint32 expected_segment_id, uint32 expected_tt_slot_id, + bool no_raw_reuse_window, bool clog_is_committed, bool clog_is_aborted, + bool clog_is_in_progress, bool xid_is_in_progress); /* S8-815PRE-FRESHREF-C1B-01: pure exact-pair conjunction. This classifier * can return only COMMITTED_EXACT or UNKNOWN_FAIL_CLOSED; the existing * COMMITTED_BOUND contract is intentionally unreachable here. */ extern ClusterUndoVerdictKind cluster_cr_server_freshref_c1b_pair_verdict( - bool pair_request, bool xid_is_mine, uint32 expected_segment_id, - uint32 expected_tt_slot_id, bool no_raw_reuse_window, int raw_clog_status, - ClusterTTDurableResolve resolve, uint16 matched_segment, uint16 matched_slot, - SCN resolved_scn, SCN proposed_scn, bool retention_ok, SCN horizon_scn); + bool pair_request, bool xid_is_mine, uint32 expected_segment_id, uint32 expected_tt_slot_id, + bool no_raw_reuse_window, int raw_clog_status, ClusterTTDurableResolve resolve, + uint16 matched_segment, uint16 matched_slot, SCN resolved_scn, SCN proposed_scn, + bool retention_ok, SCN horizon_scn); extern bool cluster_cr_server_freshref_c1b_pair_request_decode( - const GcsBlockForwardPayload *fwd, int32 authenticated_source_node, - int32 local_node, uint64 current_epoch, int max_backends, - uint32 *segment_id, TransactionId *xid, uint32 *expected_tt_slot_id, - SCN *proposed_scn); -extern bool cluster_cr_server_local_freshref_c1b_pair_exact( - TransactionId xid, uint32 expected_segment_id, - uint32 expected_tt_slot_id, SCN proposed_scn, uint16 *out_wrap); + const GcsBlockForwardPayload *fwd, int32 authenticated_source_node, int32 local_node, + uint64 current_epoch, int max_backends, uint32 *segment_id, TransactionId *xid, + uint32 *expected_tt_slot_id, SCN *proposed_scn); +extern bool cluster_cr_server_local_freshref_c1b_pair_exact(TransactionId xid, + uint32 expected_segment_id, + uint32 expected_tt_slot_id, + SCN proposed_scn, uint16 *out_wrap); #ifdef USE_CLUSTER_UNIT -extern ClusterUndoVerdictKind cluster_cr_server_test_own_xid_verdict( - TransactionId xid, uint32 expected_segment_id, uint32 expected_tt_slot_id, - bool authoritative); -extern ClusterUndoVerdictResult cluster_cr_server_test_own_xid_pair_verdict( - TransactionId xid, uint32 expected_segment_id, uint32 expected_tt_slot_id, - SCN proposed_scn); +extern ClusterUndoVerdictKind cluster_cr_server_test_own_xid_verdict(TransactionId xid, + uint32 expected_segment_id, + uint32 expected_tt_slot_id, + bool authoritative); +extern ClusterUndoVerdictResult +cluster_cr_server_test_own_xid_pair_verdict(TransactionId xid, uint32 expected_segment_id, + uint32 expected_tt_slot_id, SCN proposed_scn); #endif /* @@ -197,9 +198,9 @@ typedef enum ClusterLmsCrSlotState { /* Work-slot request kind (spec-6.12i extends the wave-b CR-only table). */ typedef enum ClusterLmsCrSlotKind { - CLUSTER_LMS_SLOT_KIND_CR = 0, /* spec-6.12b CR construction */ - CLUSTER_LMS_SLOT_KIND_UNDO_FETCH = 1, /* spec-6.12i undo-TT block fetch */ - CLUSTER_LMS_SLOT_KIND_UNDO_VERDICT = 2, /* spec-6.12i D-i4 complete-scan verdict */ + CLUSTER_LMS_SLOT_KIND_CR = 0, /* spec-6.12b CR construction */ + CLUSTER_LMS_SLOT_KIND_UNDO_FETCH = 1, /* spec-6.12i undo-TT block fetch */ + CLUSTER_LMS_SLOT_KIND_UNDO_VERDICT = 2, /* spec-6.12i D-i4 complete-scan verdict */ CLUSTER_LMS_SLOT_KIND_UNDO_MULTI_VERDICT = 3, /* spec-7.1 D3-b multi member verdict */ CLUSTER_LMS_SLOT_KIND_R4_CR_BUILD = 4 } ClusterLmsCrSlotKind; @@ -243,18 +244,15 @@ StaticAssertDecl(offsetof(ClusterR4CrOwnerStamp, edge_owner_incarnation) == 0, "R4 owner edge-incarnation offset"); StaticAssertDecl(offsetof(ClusterR4CrOwnerStamp, builder_incarnation) == 8, "R4 owner builder-incarnation offset"); -StaticAssertDecl(offsetof(ClusterR4CrOwnerStamp, edge_owner_pid) == 16, - "R4 owner edge-pid offset"); -StaticAssertDecl(offsetof(ClusterR4CrOwnerStamp, builder_pid) == 20, - "R4 owner builder-pid offset"); +StaticAssertDecl(offsetof(ClusterR4CrOwnerStamp, edge_owner_pid) == 16, "R4 owner edge-pid offset"); +StaticAssertDecl(offsetof(ClusterR4CrOwnerStamp, builder_pid) == 20, "R4 owner builder-pid offset"); StaticAssertDecl(offsetof(ClusterR4CrOwnerStamp, edge_owner_worker_id) == 24, "R4 owner edge-worker offset"); StaticAssertDecl(offsetof(ClusterR4CrOwnerStamp, builder_worker_id) == 25, "R4 owner builder-worker offset"); StaticAssertDecl(offsetof(ClusterR4CrOwnerStamp, edge_owner_role) == 26, "R4 owner edge-role offset"); -StaticAssertDecl(offsetof(ClusterR4CrOwnerStamp, reserved) == 27, - "R4 owner reserved offset"); +StaticAssertDecl(offsetof(ClusterR4CrOwnerStamp, reserved) == 27, "R4 owner reserved offset"); StaticAssertDecl(sizeof(ClusterR4CrOwnerStamp) == 32, "R4 owner stamp must remain exactly 32 bytes"); @@ -287,8 +285,7 @@ typedef struct ClusterR4CrSlotExtension { StaticAssertDecl(offsetof(ClusterR4CrSlotExtension, route_proof) == 0, "R4 slot route-proof offset"); -StaticAssertDecl(offsetof(ClusterR4CrSlotExtension, owner) == 80, - "R4 slot owner-stamp offset"); +StaticAssertDecl(offsetof(ClusterR4CrSlotExtension, owner) == 80, "R4 slot owner-stamp offset"); StaticAssertDecl(offsetof(ClusterR4CrSlotExtension, slot_generation) == 112, "R4 slot generation offset"); StaticAssertDecl(offsetof(ClusterR4CrSlotExtension, foreign_request_id) == 120, @@ -329,16 +326,13 @@ StaticAssertDecl(offsetof(ClusterR4CrSlotExtension, foreign_row_offset) == 226, "R4 slot foreign-row offset"); StaticAssertDecl(offsetof(ClusterR4CrSlotExtension, terminal_reason) == 228, "R4 slot terminal-reason offset"); -StaticAssertDecl(offsetof(ClusterR4CrSlotExtension, flags) == 229, - "R4 slot flags offset"); -StaticAssertDecl(offsetof(ClusterR4CrSlotExtension, reserved) == 230, - "R4 slot reserved offset"); +StaticAssertDecl(offsetof(ClusterR4CrSlotExtension, flags) == 229, "R4 slot flags offset"); +StaticAssertDecl(offsetof(ClusterR4CrSlotExtension, reserved) == 230, "R4 slot reserved offset"); StaticAssertDecl(sizeof(ClusterR4CrSlotExtension) == 256, "R4 slot extension must remain exactly 256 bytes"); StaticAssertDecl(MAXALIGN(sizeof(ClusterR4CrSlotExtension)) == 256, "R4 slot extension must add no alignment padding"); -StaticAssertDecl(MAXALIGN(BLCKSZ) == BLCKSZ, - "R4 foreign page must add no alignment padding"); +StaticAssertDecl(MAXALIGN(BLCKSZ) == BLCKSZ, "R4 foreign page must add no alignment padding"); typedef struct ClusterLmsCrSlot { pg_atomic_uint32 state; /* ClusterLmsCrSlotState */ @@ -389,14 +383,12 @@ typedef struct ClusterLmsCrSlot { StaticAssertDecl(sizeof(((ClusterLmsCrSlot *)0)->result_page) == BLCKSZ, "legacy result_page must remain one block"); -StaticAssertDecl(offsetof(ClusterLmsCrSlot, r4) - == offsetof(ClusterLmsCrSlot, result_page) + BLCKSZ, +StaticAssertDecl(offsetof(ClusterLmsCrSlot, r4) == offsetof(ClusterLmsCrSlot, result_page) + BLCKSZ, "R4 metadata must immediately follow legacy result_page"); StaticAssertDecl(offsetof(ClusterLmsCrSlot, foreign_undo_page) == offsetof(ClusterLmsCrSlot, r4) + 256, "R4 foreign scratch must immediately follow metadata"); -StaticAssertDecl(sizeof(ClusterLmsCrSlot) - == offsetof(ClusterLmsCrSlot, r4) + 256 + BLCKSZ, +StaticAssertDecl(sizeof(ClusterLmsCrSlot) == offsetof(ClusterLmsCrSlot, r4) + 256 + BLCKSZ, "R4 slot increment must remain exactly 8448 bytes"); StaticAssertDecl(sizeof(ClusterR4CrSlotExtension) + BLCKSZ == 8448, "R4 per-slot increment must remain exactly 8448 bytes"); @@ -426,15 +418,15 @@ extern void cluster_cr_server_stat_bump(ClusterCrServerStat which); extern void cluster_cr_construct_page_for_server(const char *cur_page, SCN read_scn, BufferTag tag, char *dst_page, bool *out_partial); extern ClusterCrBuildResult cluster_cr_build_on_holder(const BufferTag *tag, SCN read_scn, - char dst[BLCKSZ], - ClusterCrBuildReason *reason_out); + char dst[BLCKSZ], + ClusterCrBuildReason *reason_out); /* TARGET-only requester CR entry. SOURCE retains its private historical * bool/PARTIAL path; this ABI exposes the closed R4 result/reason domains and * copies a page to dst only after a positive final TARGET recheck. */ -extern ClusterCrBuildResult cluster_gcs_block_cr_fetch_and_wait( - BufferTag tag, SCN read_scn, char dst[BLCKSZ], - ClusterCrBuildReason *reason_out); +extern ClusterCrBuildResult cluster_gcs_block_cr_fetch_and_wait(BufferTag tag, SCN read_scn, + char dst[BLCKSZ], + ClusterCrBuildReason *reason_out); /* Shmem region registration (cluster_shmem.c registry). */ extern void cluster_cr_server_shmem_register(void); @@ -454,19 +446,19 @@ extern bool cluster_lms_cr_submit(const GcsBlockForwardPayload *fwd); * copy, clear, transfer or leave it. FULL/NONE means the immutable holder * work was published, not that a finished CR page already exists. */ -extern ClusterCrBuildResult cluster_lms_cr_submit_r4( - const ClusterR4CrForwardPayload *forward, - const ClusterSemanticAdmissionToken *receive_admission, - uint32 requester_capability_generation, - uint32 master_capability_generation, - ClusterCrBuildReason *reason_out); +extern ClusterCrBuildResult +cluster_lms_cr_submit_r4(const ClusterR4CrForwardPayload *forward, + const ClusterSemanticAdmissionToken *receive_admission, + uint32 requester_capability_generation, + uint32 master_capability_generation, ClusterCrBuildReason *reason_out); /* Worker-0 endpoint for one already authenticated status-24 foreign undo * response. The caller retains every input; true means the exact correlated * R4 slot release-published UNDO_READY. */ -extern bool cluster_cr_server_r4_land_foreign_undo( - const ClusterICEnvelope *env, const GcsBlockReplyHeader *header, - const char undo_page[BLCKSZ], const ClusterGcsUndoAuthTrailer *undo_auth); +extern bool cluster_cr_server_r4_land_foreign_undo(const ClusterICEnvelope *env, + const GcsBlockReplyHeader *header, + const char undo_page[BLCKSZ], + const ClusterGcsUndoAuthTrailer *undo_auth); /* Worker-0 process-local half of the D4 close proof: every retained build * context is canonical empty and no terminal/SHIPPING positive edge remains. @@ -474,22 +466,22 @@ extern bool cluster_cr_server_r4_land_foreign_undo( extern bool cluster_cr_server_r4_worker0_drained(void); /* LMON-only recovery after the exact current worker0 drain ACK. */ -extern bool cluster_cr_server_r4_lmon_reclaim_closed(uint64 worker_incarnation, - uint64 generation); +extern bool cluster_cr_server_r4_lmon_reclaim_closed(uint64 worker_incarnation, uint64 generation); #ifdef USE_CLUSTER_UNIT extern bool cluster_cr_server_test_reserve_legacy_slot(ClusterLmsCrSlot *slot, - uint32 reserved_state); + uint32 reserved_state); extern bool cluster_cr_server_test_r4_claim_queued(uint32 slot_index); extern bool cluster_cr_server_test_r4_build_step(uint32 slot_index); extern bool cluster_cr_server_test_r4_send_foreign_undo(uint32 slot_index); -extern bool cluster_cr_server_test_r4_freeze_foreign_generation( - uint32 slot_index, uint32 physical_generation); +extern bool cluster_cr_server_test_r4_freeze_foreign_generation(uint32 slot_index, + uint32 physical_generation); extern bool cluster_cr_server_test_r4_ship_terminal(uint32 slot_index); extern void cluster_cr_server_test_r4_reset_contexts(void); -extern bool cluster_cr_server_test_r4_context_matches( - uint32 slot_index, bool expect_present, uint64 slot_generation, - uint64 builder_incarnation, const ClusterSemanticAdmissionToken *admission); +extern bool +cluster_cr_server_test_r4_context_matches(uint32 slot_index, bool expect_present, + uint64 slot_generation, uint64 builder_incarnation, + const ClusterSemanticAdmissionToken *admission); #endif /* LMON dispatch side (spec-6.12i D-i1): park a validated undo-TT fetch @@ -544,27 +536,24 @@ extern void cluster_lms_cr_ship_ready(void); * ships exactly one reply, so the caller does not itself reply on refusal. */ extern void cluster_gcs_block_forward_serve_inline(const GcsBlockForwardPayload *fwd, - ClusterLmsCrSlotKind kind); + ClusterLmsCrSlotKind kind); extern ClusterMxDescribeResult cluster_gcs_current_mx_describe_fetch_and_wait( int32 origin_node, const ClusterCurrentMxKey *key, ClusterCurrentMxMemberDesc *members, uint16 members_cap, uint16 *members_count, uint32 *reported_total_members); -extern void cluster_gcs_current_mx_describe_serve_inline( - const struct ClusterICEnvelope *env, const void *payload); +extern void cluster_gcs_current_mx_describe_serve_inline(const struct ClusterICEnvelope *env, + const void *payload); struct ClusterCurrentMxProofForwardV2; -extern void cluster_gcs_current_mx_member_proof_serve_inline( - const struct ClusterICEnvelope *env, const void *payload); +extern void cluster_gcs_current_mx_member_proof_serve_inline(const struct ClusterICEnvelope *env, + const void *payload); struct ClusterCurrentMxProofReplyPage; extern ClusterMxResolveResult cluster_cr_server_current_mx_build_proof_page( - uint16 source_node_id, - const struct ClusterCurrentMxProofForwardV2 *request, + uint16 source_node_id, const struct ClusterCurrentMxProofForwardV2 *request, ClusterMxResolveResult result, uint32 requester_capability_generation, - const ClusterCurrentMemberProof *proofs, - uint16 proof_count, const ClusterCurrentUpdaterProof *updater_proof, - struct ClusterCurrentMxProofReplyPage *page); + const ClusterCurrentMemberProof *proofs, uint16 proof_count, + const ClusterCurrentUpdaterProof *updater_proof, struct ClusterCurrentMxProofReplyPage *page); #ifdef USE_CLUSTER_UNIT struct ClusterCurrentMxDescribeReplyPage; -extern ClusterMxDescribeResult -cluster_cr_server_test_current_mx_build_describe_page( +extern ClusterMxDescribeResult cluster_cr_server_test_current_mx_build_describe_page( uint16 source_node_id, uint64 request_id, const ClusterCurrentMxKey *key, const MultiXactMember *native_members, int native_count, struct ClusterCurrentMxDescribeReplyPage *page); @@ -572,17 +561,14 @@ cluster_cr_server_test_current_mx_build_describe_page( extern ClusterMxResolveResult cluster_gcs_current_mx_member_proof_fetch_and_wait( int32 origin_node, struct ClusterCurrentMxProofForwardV2 *request, ClusterCurrentMemberProof *proofs, uint16 proofs_cap, uint16 *proof_count, - ClusterCurrentUpdaterProof *updater_proof, - uint32 *requester_capability_generation_out, TimestampTz deadline); + ClusterCurrentUpdaterProof *updater_proof, uint32 *requester_capability_generation_out, + TimestampTz deadline); #ifdef USE_CLUSTER_UNIT -extern ClusterMxResolveResult -cluster_cr_server_test_current_mx_build_proof_page( - uint16 source_node_id, - const struct ClusterCurrentMxProofForwardV2 *request, +extern ClusterMxResolveResult cluster_cr_server_test_current_mx_build_proof_page( + uint16 source_node_id, const struct ClusterCurrentMxProofForwardV2 *request, ClusterMxResolveResult result, uint32 requester_capability_generation, - const ClusterCurrentMemberProof *proofs, - uint16 proof_count, const ClusterCurrentUpdaterProof *updater_proof, - struct ClusterCurrentMxProofReplyPage *page); + const ClusterCurrentMemberProof *proofs, uint16 proof_count, + const ClusterCurrentUpdaterProof *updater_proof, struct ClusterCurrentMxProofReplyPage *page); #endif typedef enum ClusterR4SourceCrOp { CLUSTER_R4_SOURCE_CR_FETCH = 0 } ClusterR4SourceCrOp; @@ -632,9 +618,9 @@ extern bool cluster_gcs_block_undo_verdict_fetch_and_wait(int32 origin_node, uin ClusterGcsUndoVerdictPage *verdict_out, ClusterLiveAuthority *auth_out); extern bool cluster_gcs_block_undo_freshref_c1b_pair_fetch_and_wait( - int32 origin_node, uint32 segment_id, uint32 expected_tt_slot_id, - TransactionId xid, uint32 ref_epoch, SCN proposed_scn, - ClusterGcsUndoVerdictPage *verdict_out, ClusterLiveAuthority *auth_out); + int32 origin_node, uint32 segment_id, uint32 expected_tt_slot_id, TransactionId xid, + uint32 ref_epoch, SCN proposed_scn, ClusterGcsUndoVerdictPage *verdict_out, + ClusterLiveAuthority *auth_out); /* Requester side (backend, spec-5.22d D4-6): ask the elected serve AUTHORITY * (a live survivor — NOT the dead owner) for a block0-proven verdict on the diff --git a/src/include/cluster/cluster_epoch_ballot.h b/src/include/cluster/cluster_epoch_ballot.h index 058cf51cea2..177f7df4dab 100644 --- a/src/include/cluster/cluster_epoch_ballot.h +++ b/src/include/cluster/cluster_epoch_ballot.h @@ -24,8 +24,7 @@ #define CLUSTER_EPOCH_BALLOT_LANE_BYTES 512 #define CLUSTER_EPOCH_BALLOT_BITMAP_BYTES 16 #define CLUSTER_EPOCH_BALLOT_DIGEST_BYTES 16 -#define CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT \ - UINT64_C(0x8e0dae5b428905e4) +#define CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT UINT64_C(0x8e0dae5b428905e4) typedef enum ClusterEpochBallotPhase { CLUSTER_EPOCH_BALLOT_PHASE_EMPTY = 0, @@ -55,51 +54,51 @@ typedef enum ClusterEpochEventKind { #define CLUSTER_EPOCH_AUTHORITY_VALUE_VERSION UINT16_C(1) typedef struct ClusterEpochBallotId { - uint64 counter; /* 0 */ - int32 proposer_node_id; /* 8 */ - uint32 reserved; /* 12: zero */ - uint64 proposer_admitted_incarnation; /* 16 */ - uint64 nonce; /* 24 */ + uint64 counter; /* 0 */ + int32 proposer_node_id; /* 8 */ + uint32 reserved; /* 12: zero */ + uint64 proposer_admitted_incarnation; /* 16 */ + uint64 nonce; /* 24 */ } ClusterEpochBallotId; typedef struct ClusterEpochAuthorityValue { - uint16 value_version; /* 0 */ - uint8 transition; /* 2 */ - uint8 event_kind; /* 3 */ - int32 request_origin_node; /* 4 */ - int32 target_node_id; /* 8 */ - uint32 reserved0; /* 12: zero */ - uint64 authority_generation; /* 16 */ - uint64 baseline_epoch; /* 24 */ - uint64 reserved_epoch; /* 32 */ - uint64 old_incarnation; /* 40 */ - uint64 fresh_incarnation; /* 48 */ - uint64 request_nonce; /* 56 */ + uint16 value_version; /* 0 */ + uint8 transition; /* 2 */ + uint8 event_kind; /* 3 */ + int32 request_origin_node; /* 4 */ + int32 target_node_id; /* 8 */ + uint32 reserved0; /* 12: zero */ + uint64 authority_generation; /* 16 */ + uint64 baseline_epoch; /* 24 */ + uint64 reserved_epoch; /* 32 */ + uint64 old_incarnation; /* 40 */ + uint64 fresh_incarnation; /* 48 */ + uint64 request_nonce; /* 56 */ uint8 authority_member_bitmap[CLUSTER_EPOCH_BALLOT_BITMAP_BYTES]; /* 64 */ - uint8 event_subject_bitmap[CLUSTER_EPOCH_BALLOT_BITMAP_BYTES]; /* 80 */ - uint64 grammar_fingerprint; /* 96 */ - uint8 predecessor_digest[CLUSTER_EPOCH_BALLOT_DIGEST_BYTES]; /* 104 */ - uint8 reserved1[8]; /* 120: zero */ + uint8 event_subject_bitmap[CLUSTER_EPOCH_BALLOT_BITMAP_BYTES]; /* 80 */ + uint64 grammar_fingerprint; /* 96 */ + uint8 predecessor_digest[CLUSTER_EPOCH_BALLOT_DIGEST_BYTES]; /* 104 */ + uint8 reserved1[8]; /* 120: zero */ } ClusterEpochAuthorityValue; typedef struct ClusterEpochBallotLane { - uint32 magic; /* 0 */ - uint16 version; /* 4 */ - uint8 last_write_phase; /* 6 */ - uint8 flags; /* 7: zero */ - int32 proposer_node_id; /* 8 */ - uint32 configured_disk_count; /* 12 */ - uint64 proposer_admitted_incarnation; /* 16 */ - uint64 lane_generation; /* 24 */ - uint64 system_identifier; /* 32 */ - uint64 grammar_fingerprint; /* 40 */ - ClusterEpochBallotId promised_ballot; /* 48 */ - ClusterEpochBallotId accepted_ballot; /* 80 */ + uint32 magic; /* 0 */ + uint16 version; /* 4 */ + uint8 last_write_phase; /* 6 */ + uint8 flags; /* 7: zero */ + int32 proposer_node_id; /* 8 */ + uint32 configured_disk_count; /* 12 */ + uint64 proposer_admitted_incarnation; /* 16 */ + uint64 lane_generation; /* 24 */ + uint64 system_identifier; /* 32 */ + uint64 grammar_fingerprint; /* 40 */ + ClusterEpochBallotId promised_ballot; /* 48 */ + ClusterEpochBallotId accepted_ballot; /* 80 */ ClusterEpochAuthorityValue accepted_value; /* 112 */ - ClusterEpochBallotId settled_ballot; /* 240 */ - ClusterEpochAuthorityValue settled_value; /* 272 */ - uint8 reserved[108]; /* 400: zero */ - uint32 crc32c; /* 508 */ + ClusterEpochBallotId settled_ballot; /* 240 */ + ClusterEpochAuthorityValue settled_value; /* 272 */ + uint8 reserved[108]; /* 400: zero */ + uint32 crc32c; /* 508 */ } ClusterEpochBallotLane; StaticAssertDecl(sizeof(ClusterEpochBallotId) == CLUSTER_EPOCH_BALLOT_ID_BYTES, @@ -115,8 +114,7 @@ StaticAssertDecl(offsetof(ClusterEpochBallotId, proposer_admitted_incarnation) = StaticAssertDecl(offsetof(ClusterEpochBallotId, nonce) == 24, "epoch ballot nonce offset must remain 24"); -StaticAssertDecl(sizeof(ClusterEpochAuthorityValue) - == CLUSTER_EPOCH_AUTHORITY_VALUE_BYTES, +StaticAssertDecl(sizeof(ClusterEpochAuthorityValue) == CLUSTER_EPOCH_AUTHORITY_VALUE_BYTES, "epoch authority value must remain 128 bytes"); StaticAssertDecl(offsetof(ClusterEpochAuthorityValue, value_version) == 0, "authority value version offset must remain 0"); @@ -191,41 +189,43 @@ StaticAssertDecl(offsetof(ClusterEpochBallotLane, crc32c) == 508, "epoch ballot lane crc offset must remain 508"); extern bool cluster_epoch_ballot_id_is_valid(const ClusterEpochBallotId *ballot); -extern bool cluster_epoch_ballot_id_encode( - const ClusterEpochBallotId *ballot, - uint8 out[CLUSTER_EPOCH_BALLOT_ID_BYTES]); -extern bool cluster_epoch_ballot_id_decode( - const uint8 bytes[CLUSTER_EPOCH_BALLOT_ID_BYTES], - ClusterEpochBallotId *out); +extern bool cluster_epoch_ballot_id_encode(const ClusterEpochBallotId *ballot, + uint8 out[CLUSTER_EPOCH_BALLOT_ID_BYTES]); +extern bool cluster_epoch_ballot_id_decode(const uint8 bytes[CLUSTER_EPOCH_BALLOT_ID_BYTES], + ClusterEpochBallotId *out); extern int cluster_epoch_ballot_id_compare(const ClusterEpochBallotId *a, - const ClusterEpochBallotId *b); + const ClusterEpochBallotId *b); extern bool cluster_epoch_ballot_next_counter(uint64 current, uint64 *next); -extern bool cluster_epoch_authority_value_is_valid( - const ClusterEpochAuthorityValue *value, uint64 expected_grammar_fingerprint); -extern bool cluster_epoch_authority_value_encode( - const ClusterEpochAuthorityValue *value, uint64 expected_grammar_fingerprint, - uint8 out[CLUSTER_EPOCH_AUTHORITY_VALUE_BYTES]); -extern bool cluster_epoch_authority_value_decode( - const uint8 bytes[CLUSTER_EPOCH_AUTHORITY_VALUE_BYTES], - uint64 expected_grammar_fingerprint, ClusterEpochAuthorityValue *out); - -extern bool cluster_epoch_ballot_lane_is_valid( - const ClusterEpochBallotLane *lane, int32 expected_proposer_node_id, - uint32 expected_configured_disk_count, - uint64 expected_proposer_admitted_incarnation, - uint64 expected_system_identifier, uint64 expected_grammar_fingerprint); -extern bool cluster_epoch_ballot_lane_encode( - const ClusterEpochBallotLane *lane, int32 expected_proposer_node_id, - uint32 expected_configured_disk_count, - uint64 expected_proposer_admitted_incarnation, - uint64 expected_system_identifier, uint64 expected_grammar_fingerprint, - uint8 out[CLUSTER_EPOCH_BALLOT_LANE_BYTES]); -extern bool cluster_epoch_ballot_lane_decode( - const uint8 bytes[CLUSTER_EPOCH_BALLOT_LANE_BYTES], - int32 expected_proposer_node_id, uint32 expected_configured_disk_count, - uint64 expected_proposer_admitted_incarnation, - uint64 expected_system_identifier, uint64 expected_grammar_fingerprint, - ClusterEpochBallotLane *out); +extern bool cluster_epoch_authority_value_is_valid(const ClusterEpochAuthorityValue *value, + uint64 expected_grammar_fingerprint); +extern bool cluster_epoch_authority_value_encode(const ClusterEpochAuthorityValue *value, + uint64 expected_grammar_fingerprint, + uint8 out[CLUSTER_EPOCH_AUTHORITY_VALUE_BYTES]); +extern bool +cluster_epoch_authority_value_decode(const uint8 bytes[CLUSTER_EPOCH_AUTHORITY_VALUE_BYTES], + uint64 expected_grammar_fingerprint, + ClusterEpochAuthorityValue *out); + +extern bool cluster_epoch_ballot_lane_is_valid(const ClusterEpochBallotLane *lane, + int32 expected_proposer_node_id, + uint32 expected_configured_disk_count, + uint64 expected_proposer_admitted_incarnation, + uint64 expected_system_identifier, + uint64 expected_grammar_fingerprint); +extern bool cluster_epoch_ballot_lane_encode(const ClusterEpochBallotLane *lane, + int32 expected_proposer_node_id, + uint32 expected_configured_disk_count, + uint64 expected_proposer_admitted_incarnation, + uint64 expected_system_identifier, + uint64 expected_grammar_fingerprint, + uint8 out[CLUSTER_EPOCH_BALLOT_LANE_BYTES]); +extern bool cluster_epoch_ballot_lane_decode(const uint8 bytes[CLUSTER_EPOCH_BALLOT_LANE_BYTES], + int32 expected_proposer_node_id, + uint32 expected_configured_disk_count, + uint64 expected_proposer_admitted_incarnation, + uint64 expected_system_identifier, + uint64 expected_grammar_fingerprint, + ClusterEpochBallotLane *out); #endif /* CLUSTER_EPOCH_BALLOT_H */ diff --git a/src/include/cluster/cluster_external_fence.h b/src/include/cluster/cluster_external_fence.h index 71d90feea44..953add22f01 100644 --- a/src/include/cluster/cluster_external_fence.h +++ b/src/include/cluster/cluster_external_fence.h @@ -30,11 +30,9 @@ #define PGRAC_EXTERNAL_FENCE_REJOIN_FRAME_V1_BYTES UINT32_C(256) #define PGRAC_EXTERNAL_FENCE_ACQUIRE_TIMEOUT_DEFAULT_MS 120000 -StaticAssertDecl(PGRAC_IC_HELLO_CAP_CONTROL_ROOT_V1 - == UINT32_C(0x00080000), +StaticAssertDecl(PGRAC_IC_HELLO_CAP_CONTROL_ROOT_V1 == UINT32_C(0x00080000), "unexpected control-root v1 HELLO capability"); -StaticAssertDecl(PGRAC_CONTROL_ROOT_FEATURE_EXTERNAL_FENCE_V1 - == (UINT64_C(1) << 24), +StaticAssertDecl(PGRAC_CONTROL_ROOT_FEATURE_EXTERNAL_FENCE_V1 == (UINT64_C(1) << 24), "unexpected external-fence root feature bit"); typedef enum PgracExternalFenceVerdict { @@ -212,8 +210,7 @@ StaticAssertDecl(sizeof(ClusterRecoveryDutyDigest) == 32, "recovery duty digest must remain 32 bytes"); StaticAssertDecl(sizeof(PgracExternalFenceWriterV1) == 16, "external fence writer v1 must remain 16 bytes"); -StaticAssertDecl(offsetof(PgracExternalFenceWriterV1, node_id) == 0, - "writer node offset changed"); +StaticAssertDecl(offsetof(PgracExternalFenceWriterV1, node_id) == 0, "writer node offset changed"); StaticAssertDecl(offsetof(PgracExternalFenceWriterV1, reserved0) == 4, "writer reserved offset changed"); StaticAssertDecl(offsetof(PgracExternalFenceWriterV1, incarnation) == 8, @@ -224,8 +221,7 @@ StaticAssertDecl(sizeof(PgracExternalFenceNeedV1) == 96, "external fence need v1 must remain 96 bytes"); StaticAssertDecl(offsetof(PgracExternalFenceNeedV1, system_identifier) == 0, "need system identifier offset changed"); -StaticAssertDecl(offsetof(PgracExternalFenceNeedV1, - canonical_duty_digest) == 8, +StaticAssertDecl(offsetof(PgracExternalFenceNeedV1, canonical_duty_digest) == 8, "need duty digest offset changed"); StaticAssertDecl(offsetof(PgracExternalFenceNeedV1, victim_node_id) == 40, "need victim node offset changed"); @@ -233,8 +229,7 @@ StaticAssertDecl(offsetof(PgracExternalFenceNeedV1, reserved0) == 44, "need reserved offset changed"); StaticAssertDecl(offsetof(PgracExternalFenceNeedV1, victim_incarnation) == 48, "need victim incarnation offset changed"); -StaticAssertDecl(offsetof(PgracExternalFenceNeedV1, - protected_set_digest) == 56, +StaticAssertDecl(offsetof(PgracExternalFenceNeedV1, protected_set_digest) == 56, "need protected-set digest offset changed"); StaticAssertDecl(offsetof(PgracExternalFenceNeedV1, predicate_id) == 88, "need predicate id offset changed"); @@ -244,26 +239,21 @@ StaticAssertDecl(sizeof(PgracExternalFenceBindingV1) == 104, "external fence binding v1 must remain 104 bytes"); StaticAssertDecl(offsetof(PgracExternalFenceBindingV1, system_identifier) == 0, "binding system identifier offset changed"); -StaticAssertDecl(offsetof(PgracExternalFenceBindingV1, - canonical_duty_digest) == 8, +StaticAssertDecl(offsetof(PgracExternalFenceBindingV1, canonical_duty_digest) == 8, "binding duty digest offset changed"); StaticAssertDecl(offsetof(PgracExternalFenceBindingV1, victim_node_id) == 40, "binding victim node offset changed"); StaticAssertDecl(offsetof(PgracExternalFenceBindingV1, reserved0) == 44, "binding reserved offset changed"); -StaticAssertDecl(offsetof(PgracExternalFenceBindingV1, - victim_incarnation) == 48, +StaticAssertDecl(offsetof(PgracExternalFenceBindingV1, victim_incarnation) == 48, "binding victim incarnation offset changed"); -StaticAssertDecl(offsetof(PgracExternalFenceBindingV1, - target_mapping_generation) == 56, +StaticAssertDecl(offsetof(PgracExternalFenceBindingV1, target_mapping_generation) == 56, "binding mapping generation offset changed"); -StaticAssertDecl(offsetof(PgracExternalFenceBindingV1, - protected_set_digest) == 64, +StaticAssertDecl(offsetof(PgracExternalFenceBindingV1, protected_set_digest) == 64, "binding protected-set digest offset changed"); StaticAssertDecl(offsetof(PgracExternalFenceBindingV1, predicate_id) == 96, "binding predicate id offset changed"); -StaticAssertDecl(offsetof(PgracExternalFenceBindingV1, - predicate_version) == 100, +StaticAssertDecl(offsetof(PgracExternalFenceBindingV1, predicate_version) == 100, "binding predicate version offset changed"); StaticAssertDecl(sizeof(PgracExternalFenceRejoinOfferV1) == 40, "external fence rejoin offer v1 must remain 40 bytes"); @@ -273,162 +263,124 @@ StaticAssertDecl(offsetof(PgracExternalFenceRejoinOfferV1, old_node_id) == 16, "rejoin offer node offset changed"); StaticAssertDecl(offsetof(PgracExternalFenceRejoinOfferV1, reserved20) == 20, "rejoin offer reserved offset changed"); -StaticAssertDecl(offsetof(PgracExternalFenceRejoinOfferV1, - old_incarnation) == 24, +StaticAssertDecl(offsetof(PgracExternalFenceRejoinOfferV1, old_incarnation) == 24, "rejoin offer old incarnation offset changed"); -StaticAssertDecl(offsetof(PgracExternalFenceRejoinOfferV1, - candidate_incarnation) == 32, +StaticAssertDecl(offsetof(PgracExternalFenceRejoinOfferV1, candidate_incarnation) == 32, "rejoin offer candidate incarnation offset changed"); StaticAssertDecl(sizeof(PgracExternalFenceRejoinNeedV1) == 104, "external fence rejoin need v1 must remain 104 bytes"); -StaticAssertDecl(offsetof(PgracExternalFenceRejoinNeedV1, - system_identifier) == 0, +StaticAssertDecl(offsetof(PgracExternalFenceRejoinNeedV1, system_identifier) == 0, "rejoin need system identifier offset changed"); -StaticAssertDecl(offsetof(PgracExternalFenceRejoinNeedV1, - rejoin_gate_digest) == 8, +StaticAssertDecl(offsetof(PgracExternalFenceRejoinNeedV1, rejoin_gate_digest) == 8, "rejoin need gate digest offset changed"); StaticAssertDecl(offsetof(PgracExternalFenceRejoinNeedV1, old_node_id) == 40, "rejoin need node offset changed"); StaticAssertDecl(offsetof(PgracExternalFenceRejoinNeedV1, reserved44) == 44, "rejoin need reserved offset changed"); -StaticAssertDecl(offsetof(PgracExternalFenceRejoinNeedV1, - old_incarnation) == 48, +StaticAssertDecl(offsetof(PgracExternalFenceRejoinNeedV1, old_incarnation) == 48, "rejoin need old incarnation offset changed"); -StaticAssertDecl(offsetof(PgracExternalFenceRejoinNeedV1, - candidate_incarnation) == 56, +StaticAssertDecl(offsetof(PgracExternalFenceRejoinNeedV1, candidate_incarnation) == 56, "rejoin need candidate incarnation offset changed"); -StaticAssertDecl(offsetof(PgracExternalFenceRejoinNeedV1, - protected_set_digest) == 64, +StaticAssertDecl(offsetof(PgracExternalFenceRejoinNeedV1, protected_set_digest) == 64, "rejoin need protected-set offset changed"); StaticAssertDecl(offsetof(PgracExternalFenceRejoinNeedV1, predicate_id) == 96, "rejoin need predicate offset changed"); -StaticAssertDecl(offsetof(PgracExternalFenceRejoinNeedV1, - predicate_version) == 100, +StaticAssertDecl(offsetof(PgracExternalFenceRejoinNeedV1, predicate_version) == 100, "rejoin need predicate version offset changed"); StaticAssertDecl(sizeof(PgracExternalFenceRejoinBindingV1) == 112, "external fence rejoin binding v1 must remain 112 bytes"); -StaticAssertDecl(offsetof(PgracExternalFenceRejoinBindingV1, - system_identifier) == 0, +StaticAssertDecl(offsetof(PgracExternalFenceRejoinBindingV1, system_identifier) == 0, "rejoin binding system identifier offset changed"); -StaticAssertDecl(offsetof(PgracExternalFenceRejoinBindingV1, - rejoin_gate_digest) == 8, +StaticAssertDecl(offsetof(PgracExternalFenceRejoinBindingV1, rejoin_gate_digest) == 8, "rejoin binding gate digest offset changed"); -StaticAssertDecl(offsetof(PgracExternalFenceRejoinBindingV1, - old_node_id) == 40, +StaticAssertDecl(offsetof(PgracExternalFenceRejoinBindingV1, old_node_id) == 40, "rejoin binding node offset changed"); -StaticAssertDecl(offsetof(PgracExternalFenceRejoinBindingV1, - reserved44) == 44, +StaticAssertDecl(offsetof(PgracExternalFenceRejoinBindingV1, reserved44) == 44, "rejoin binding reserved offset changed"); -StaticAssertDecl(offsetof(PgracExternalFenceRejoinBindingV1, - old_incarnation) == 48, +StaticAssertDecl(offsetof(PgracExternalFenceRejoinBindingV1, old_incarnation) == 48, "rejoin binding old incarnation offset changed"); -StaticAssertDecl(offsetof(PgracExternalFenceRejoinBindingV1, - candidate_incarnation) == 56, +StaticAssertDecl(offsetof(PgracExternalFenceRejoinBindingV1, candidate_incarnation) == 56, "rejoin binding candidate incarnation offset changed"); -StaticAssertDecl(offsetof(PgracExternalFenceRejoinBindingV1, - target_mapping_generation) == 64, +StaticAssertDecl(offsetof(PgracExternalFenceRejoinBindingV1, target_mapping_generation) == 64, "rejoin binding mapping offset changed"); -StaticAssertDecl(offsetof(PgracExternalFenceRejoinBindingV1, - protected_set_digest) == 72, +StaticAssertDecl(offsetof(PgracExternalFenceRejoinBindingV1, protected_set_digest) == 72, "rejoin binding protected-set offset changed"); -StaticAssertDecl(offsetof(PgracExternalFenceRejoinBindingV1, - predicate_id) == 104, +StaticAssertDecl(offsetof(PgracExternalFenceRejoinBindingV1, predicate_id) == 104, "rejoin binding predicate offset changed"); -StaticAssertDecl(offsetof(PgracExternalFenceRejoinBindingV1, - predicate_version) == 108, +StaticAssertDecl(offsetof(PgracExternalFenceRejoinBindingV1, predicate_version) == 108, "rejoin binding predicate version offset changed"); StaticAssertDecl(sizeof(ClusterReconfigRejoinFailureSnapshotV1) == 80, "rejoin failure snapshot v1 size changed"); -StaticAssertDecl(offsetof(ClusterReconfigRejoinFailureSnapshotV1, - old_incarnation) == 72, +StaticAssertDecl(offsetof(ClusterReconfigRejoinFailureSnapshotV1, old_incarnation) == 72, "rejoin failure old incarnation offset changed"); StaticAssertDecl(sizeof(ClusterGrdRejoinClearSnapshotV1) == 32, "rejoin GRD clear snapshot v1 size changed"); -StaticAssertDecl(offsetof(ClusterGrdRejoinClearSnapshotV1, - survivor_bitmap) == 16, +StaticAssertDecl(offsetof(ClusterGrdRejoinClearSnapshotV1, survivor_bitmap) == 16, "rejoin GRD clear survivor offset changed"); StaticAssertDecl(sizeof(ClusterReconfigRejoinPendingSnapshotV1) == 96, "rejoin pending snapshot v1 size changed"); -StaticAssertDecl(offsetof(ClusterReconfigRejoinPendingSnapshotV1, - observed_slot_generation) == 88, +StaticAssertDecl(offsetof(ClusterReconfigRejoinPendingSnapshotV1, observed_slot_generation) == 88, "rejoin pending observed generation offset changed"); typedef struct PgracExternalFenceAdmissionV1 PgracExternalFenceAdmissionV1; typedef struct PgracExternalFenceNeedSetV1 PgracExternalFenceNeedSetV1; -typedef struct PgracExternalFenceAdmissionSetV1 - PgracExternalFenceAdmissionSetV1; +typedef struct PgracExternalFenceAdmissionSetV1 PgracExternalFenceAdmissionSetV1; typedef struct PgracExternalFenceRejoinOpV1 PgracExternalFenceRejoinOpV1; -typedef struct PgracExternalFenceRejoinAuthorityClearV1 - PgracExternalFenceRejoinAuthorityClearV1; +typedef struct PgracExternalFenceRejoinAuthorityClearV1 PgracExternalFenceRejoinAuthorityClearV1; -extern bool cluster_reconfig_get_observed_slot_coherent( - int32 node_id, uint64 *out_incarnation, uint64 *out_generation); -extern bool cluster_reconfig_rejoin_failure_snapshot( - int32 old_node_id, uint64 old_incarnation, - ClusterReconfigRejoinFailureSnapshotV1 *out_failure); -extern bool cluster_grd_rejoin_clear_snapshot( - const ClusterReconfigRejoinFailureSnapshotV1 *failure, - ClusterGrdRejoinClearSnapshotV1 *out_clear); -extern bool cluster_reconfig_rejoin_pending_snapshot( - const ClusterReconfigRejoinFailureSnapshotV1 *failure, - uint64 candidate_incarnation, - ClusterReconfigRejoinPendingSnapshotV1 *out_pending); -extern bool cluster_reconfig_rejoin_pending_ready( - const ClusterReconfigRejoinPendingSnapshotV1 *pending); +extern bool cluster_reconfig_get_observed_slot_coherent(int32 node_id, uint64 *out_incarnation, + uint64 *out_generation); +extern bool +cluster_reconfig_rejoin_failure_snapshot(int32 old_node_id, uint64 old_incarnation, + ClusterReconfigRejoinFailureSnapshotV1 *out_failure); +extern bool cluster_grd_rejoin_clear_snapshot(const ClusterReconfigRejoinFailureSnapshotV1 *failure, + ClusterGrdRejoinClearSnapshotV1 *out_clear); +extern bool +cluster_reconfig_rejoin_pending_snapshot(const ClusterReconfigRejoinFailureSnapshotV1 *failure, + uint64 candidate_incarnation, + ClusterReconfigRejoinPendingSnapshotV1 *out_pending); +extern bool +cluster_reconfig_rejoin_pending_ready(const ClusterReconfigRejoinPendingSnapshotV1 *pending); /* STOP04 §11.7 current-package policy. This remains false until a later * explicit provider selection and deployment certification authorizes bit24. * Keeping the check as a production callsite leaves the approved LMON handoff * dormant without weakening ordinary online join. */ extern bool cluster_external_fence_runtime_active(void); -extern bool cluster_external_fence_rejoin_protected_set_digest( - uint8 out[PGRAC_EXTERNAL_FENCE_DIGEST_BYTES]); +extern bool +cluster_external_fence_rejoin_protected_set_digest(uint8 out[PGRAC_EXTERNAL_FENCE_DIGEST_BYTES]); extern PgracExternalFenceRejoinStatus -cluster_external_fence_rejoin_start_async( - int timeout_ms, PgracExternalFenceRejoinOpV1 **out_op); +cluster_external_fence_rejoin_start_async(int timeout_ms, PgracExternalFenceRejoinOpV1 **out_op); extern PgracExternalFenceRejoinStatus -cluster_external_fence_rejoin_poll_nowait( - PgracExternalFenceRejoinOpV1 *op, - PgracExternalFenceDenyReason *reason); +cluster_external_fence_rejoin_poll_nowait(PgracExternalFenceRejoinOpV1 *op, + PgracExternalFenceDenyReason *reason); extern const PgracExternalFenceRejoinOfferV1 * -cluster_external_fence_rejoin_offer( - const PgracExternalFenceRejoinOpV1 *op); -extern PgracExternalFenceRejoinStatus -cluster_external_fence_rejoin_authority_clear_build( +cluster_external_fence_rejoin_offer(const PgracExternalFenceRejoinOpV1 *op); +extern PgracExternalFenceRejoinStatus cluster_external_fence_rejoin_authority_clear_build( const PgracExternalFenceRejoinOpV1 *offered_op, const ClusterReconfigRejoinFailureSnapshotV1 *failure, const ClusterGrdRejoinClearSnapshotV1 *grd_clear, - PgracExternalFenceRejoinAuthorityClearV1 **out_clear, - PgracExternalFenceDenyReason *reason); -extern PgracExternalFenceRejoinStatus -cluster_external_fence_rejoin_authorize_on_async( - PgracExternalFenceRejoinOpV1 *op, - PgracExternalFenceRejoinAuthorityClearV1 **authority_clear, + PgracExternalFenceRejoinAuthorityClearV1 **out_clear, PgracExternalFenceDenyReason *reason); +extern PgracExternalFenceRejoinStatus cluster_external_fence_rejoin_authorize_on_async( + PgracExternalFenceRejoinOpV1 *op, PgracExternalFenceRejoinAuthorityClearV1 **authority_clear, const ClusterControlRootIdentity *old_identity, const ClusterControlRootSnapshot *complete_snapshot, - const ClusterControlRootReadToken *complete_token, - const uint8 protected_set_digest[32], + const ClusterControlRootReadToken *complete_token, const uint8 protected_set_digest[32], PgracExternalFenceDenyReason *reason); -extern PgracExternalFenceRejoinStatus -cluster_external_fence_rejoin_refresh_on_async( - PgracExternalFenceRejoinOpV1 *op, - const ClusterReconfigRejoinPendingSnapshotV1 *pending, - PgracExternalFenceDenyReason *reason); -extern bool cluster_external_fence_rejoin_revalidate_root( - PgracExternalFenceRejoinOpV1 *op, - ClusterControlRootSnapshot *out_fresh_snapshot, +extern PgracExternalFenceRejoinStatus cluster_external_fence_rejoin_refresh_on_async( + PgracExternalFenceRejoinOpV1 *op, const ClusterReconfigRejoinPendingSnapshotV1 *pending, PgracExternalFenceDenyReason *reason); +extern bool +cluster_external_fence_rejoin_revalidate_root(PgracExternalFenceRejoinOpV1 *op, + ClusterControlRootSnapshot *out_fresh_snapshot, + PgracExternalFenceDenyReason *reason); extern bool cluster_external_fence_rejoin_consume_nowait( - PgracExternalFenceRejoinOpV1 *op, - const ClusterReconfigRejoinPendingSnapshotV1 *current_pending, - const ClusterJoinCommitMarker *committed_candidate, - PgracExternalFenceDenyReason *reason); + PgracExternalFenceRejoinOpV1 *op, const ClusterReconfigRejoinPendingSnapshotV1 *current_pending, + const ClusterJoinCommitMarker *committed_candidate, PgracExternalFenceDenyReason *reason); extern const PgracExternalFenceRejoinBindingV1 * -cluster_external_fence_rejoin_binding( - const PgracExternalFenceRejoinOpV1 *op); -extern void cluster_external_fence_rejoin_release( - PgracExternalFenceRejoinOpV1 **op); +cluster_external_fence_rejoin_binding(const PgracExternalFenceRejoinOpV1 *op); +extern void cluster_external_fence_rejoin_release(PgracExternalFenceRejoinOpV1 **op); extern void cluster_external_fence_rejoin_authority_clear_release( PgracExternalFenceRejoinAuthorityClearV1 **authority_clear); @@ -436,60 +388,48 @@ extern void cluster_external_fence_rejoin_authority_clear_release( * one formation object from build through final no-wait revalidation. There is * no scalar generation argument or hidden root/formation fetch. */ extern PgracExternalFenceNeedSetResult -cluster_external_fence_need_set_build( - const ClusterRecoveryDutyKey *duty, - const ClusterFormationWitnessV1 *formation, - PgracExternalFenceNeedSetV1 **out); -extern bool cluster_external_fence_need_set_revalidate_nowait( - const PgracExternalFenceNeedSetV1 *needs, - const ClusterFormationWitnessV1 *formation, - PgracExternalFenceDenyReason *reason); -extern PgracExternalFenceVerdict cluster_external_fence_admit_set_wait( - const PgracExternalFenceNeedSetV1 *needs, - const ClusterFormationWitnessV1 *formation, int timeout_ms, - PgracExternalFenceAdmissionSetV1 **out); +cluster_external_fence_need_set_build(const ClusterRecoveryDutyKey *duty, + const ClusterFormationWitnessV1 *formation, + PgracExternalFenceNeedSetV1 **out); +extern bool +cluster_external_fence_need_set_revalidate_nowait(const PgracExternalFenceNeedSetV1 *needs, + const ClusterFormationWitnessV1 *formation, + PgracExternalFenceDenyReason *reason); +extern PgracExternalFenceVerdict +cluster_external_fence_admit_set_wait(const PgracExternalFenceNeedSetV1 *needs, + const ClusterFormationWitnessV1 *formation, int timeout_ms, + PgracExternalFenceAdmissionSetV1 **out); extern bool cluster_external_fence_revalidate_set_nowait( - const PgracExternalFenceAdmissionSetV1 *admissions, - const PgracExternalFenceNeedSetV1 *needs, - const ClusterFormationWitnessV1 *formation, - PgracExternalFenceDenyReason *reason); + const PgracExternalFenceAdmissionSetV1 *admissions, const PgracExternalFenceNeedSetV1 *needs, + const ClusterFormationWitnessV1 *formation, PgracExternalFenceDenyReason *reason); -extern PgracExternalFenceVerdict cluster_external_fence_admit_wait( - const PgracExternalFenceNeedV1 *need, int timeout_ms, - PgracExternalFenceAdmissionV1 **out); -extern bool cluster_external_fence_revalidate_nowait( - const PgracExternalFenceAdmissionV1 *admission, - const PgracExternalFenceNeedV1 *current, - PgracExternalFenceDenyReason *reason); +extern PgracExternalFenceVerdict +cluster_external_fence_admit_wait(const PgracExternalFenceNeedV1 *need, int timeout_ms, + PgracExternalFenceAdmissionV1 **out); +extern bool cluster_external_fence_revalidate_nowait(const PgracExternalFenceAdmissionV1 *admission, + const PgracExternalFenceNeedV1 *current, + PgracExternalFenceDenyReason *reason); extern const PgracExternalFenceBindingV1 * -cluster_external_fence_admission_binding( - const PgracExternalFenceAdmissionV1 *admission); -extern void cluster_external_fence_admission_release( - PgracExternalFenceAdmissionV1 *admission); +cluster_external_fence_admission_binding(const PgracExternalFenceAdmissionV1 *admission); +extern void cluster_external_fence_admission_release(PgracExternalFenceAdmissionV1 *admission); -extern uint32 cluster_external_fence_need_set_count( - const PgracExternalFenceNeedSetV1 *set); -extern const PgracExternalFenceNeedV1 *cluster_external_fence_need_set_at( - const PgracExternalFenceNeedSetV1 *set, uint32 index); +extern uint32 cluster_external_fence_need_set_count(const PgracExternalFenceNeedSetV1 *set); +extern const PgracExternalFenceNeedV1 * +cluster_external_fence_need_set_at(const PgracExternalFenceNeedSetV1 *set, uint32 index); extern const PgracExternalFenceWriterSetDigest * -cluster_external_fence_need_set_digest( - const PgracExternalFenceNeedSetV1 *set); -extern void cluster_external_fence_need_set_release( - PgracExternalFenceNeedSetV1 **set); +cluster_external_fence_need_set_digest(const PgracExternalFenceNeedSetV1 *set); +extern void cluster_external_fence_need_set_release(PgracExternalFenceNeedSetV1 **set); -extern uint32 cluster_external_fence_admission_set_count( - const PgracExternalFenceAdmissionSetV1 *set); +extern uint32 +cluster_external_fence_admission_set_count(const PgracExternalFenceAdmissionSetV1 *set); extern const PgracExternalFenceBindingV1 * -cluster_external_fence_admission_set_binding_at( - const PgracExternalFenceAdmissionSetV1 *set, uint32 index); +cluster_external_fence_admission_set_binding_at(const PgracExternalFenceAdmissionSetV1 *set, + uint32 index); extern const PgracExternalFenceWriterSetDigest * -cluster_external_fence_admission_set_digest( - const PgracExternalFenceAdmissionSetV1 *set); -extern void cluster_external_fence_admission_set_release( - PgracExternalFenceAdmissionSetV1 **set); +cluster_external_fence_admission_set_digest(const PgracExternalFenceAdmissionSetV1 *set); +extern void cluster_external_fence_admission_set_release(PgracExternalFenceAdmissionSetV1 **set); /* Diagnostic only; never authority. */ -extern PgracExternalFenceDenyReason -cluster_external_fence_last_deny_reason(void); +extern PgracExternalFenceDenyReason cluster_external_fence_last_deny_reason(void); #endif /* CLUSTER_EXTERNAL_FENCE_H */ diff --git a/src/include/cluster/cluster_formation_marker.h b/src/include/cluster/cluster_formation_marker.h index 00ce9ce6f85..2f07aad6fda 100644 --- a/src/include/cluster/cluster_formation_marker.h +++ b/src/include/cluster/cluster_formation_marker.h @@ -41,7 +41,7 @@ #define CLUSTER_FORMATION_MARKER_H #include "c.h" -#include "cluster/cluster_voting_disk_io.h" /* CLUSTER_VOTING_SLOT_BYTES */ +#include "cluster/cluster_voting_disk_io.h" /* CLUSTER_VOTING_SLOT_BYTES */ /* 16 bytes — mirrors CLUSTER_RECONFIG_DEAD_BITMAP_BYTES (cluster_reconfig.h * cannot be included here: it includes this header for the mailbox type). */ @@ -65,15 +65,14 @@ /* Header bytes up to (and including) crc32c); entries follow at 72. */ #define CLUSTER_FORMATION_MARKER_HEADER_BYTES 72 /* Max co-boot members that fit the 512-byte slot. */ -#define CLUSTER_FORMATION_MARKER_MAX_MEMBERS \ - ((CLUSTER_VOTING_SLOT_BYTES - CLUSTER_FORMATION_MARKER_HEADER_BYTES) \ +#define CLUSTER_FORMATION_MARKER_MAX_MEMBERS \ + ((CLUSTER_VOTING_SLOT_BYTES - CLUSTER_FORMATION_MARKER_HEADER_BYTES) \ / CLUSTER_FORMATION_MARKER_ENTRY_BYTES) -typedef struct ClusterFormationCommitMarker -{ - uint32 magic; /* CLUSTER_FORMATION_MARKER_MAGIC */ - uint16 version; /* CLUSTER_FORMATION_MARKER_VERSION */ - uint8 phase; /* CLUSTER_FORMATION_MARKER_PHASE_COMMITTED */ +typedef struct ClusterFormationCommitMarker { + uint32 magic; /* CLUSTER_FORMATION_MARKER_MAGIC */ + uint16 version; /* CLUSTER_FORMATION_MARKER_VERSION */ + uint8 phase; /* CLUSTER_FORMATION_MARKER_PHASE_COMMITTED */ uint8 _pad1; uint64 formation_generation; /* monotonic; takeover raises it */ uint64 formation_epoch; /* the (possibly recovered) cluster epoch */ @@ -81,28 +80,26 @@ typedef struct ClusterFormationCommitMarker uint64 arbiter_incarnation; /* arbiter's CURRENT boot incarnation */ uint64 commit_nonce; /* per-formation-attempt identity */ uint8 admitted_nodes[CLUSTER_FORMATION_MARKER_BITMAP_BYTES]; /* co-boot bitmap */ - uint16 n_admitted; /* = popcount(admitted_nodes) */ + uint16 n_admitted; /* = popcount(admitted_nodes) */ uint16 _pad2; - uint32 crc32c; /* CRC32C over [magic .. _pad2] */ - /* followed by n_admitted compact entries: uint8 node_id + uint64 incarnation */ + uint32 crc32c; /* CRC32C over [magic .. _pad2] */ + /* followed by n_admitted compact entries: uint8 node_id + uint64 incarnation */ } ClusterFormationCommitMarker; -extern void cluster_formation_marker_compute_crc( - ClusterFormationCommitMarker *marker); -extern bool cluster_formation_marker_encode( - const ClusterFormationCommitMarker *marker, - const uint64 *incarnation_by_node /* CLUSTER_MAX_NODES */, - uint8 slot_bytes[CLUSTER_VOTING_SLOT_BYTES]); -extern bool cluster_formation_marker_decode( - const uint8 slot_bytes[CLUSTER_VOTING_SLOT_BYTES], - ClusterFormationCommitMarker *marker, - uint64 *incarnation_by_node /* CLUSTER_MAX_NODES, optional */); -extern bool cluster_formation_marker_validate( - const uint8 slot_bytes[CLUSTER_VOTING_SLOT_BYTES], - ClusterFormationCommitMarker *out_decoded, - uint64 *out_incarnations); -extern uint64 cluster_formation_marker_incarnation_for( - const uint64 *incarnation_by_node, int32 node_id); +extern void cluster_formation_marker_compute_crc(ClusterFormationCommitMarker *marker); +extern bool +cluster_formation_marker_encode(const ClusterFormationCommitMarker *marker, + const uint64 *incarnation_by_node /* CLUSTER_MAX_NODES */, + uint8 slot_bytes[CLUSTER_VOTING_SLOT_BYTES]); +extern bool +cluster_formation_marker_decode(const uint8 slot_bytes[CLUSTER_VOTING_SLOT_BYTES], + ClusterFormationCommitMarker *marker, + uint64 *incarnation_by_node /* CLUSTER_MAX_NODES, optional */); +extern bool cluster_formation_marker_validate(const uint8 slot_bytes[CLUSTER_VOTING_SLOT_BYTES], + ClusterFormationCommitMarker *out_decoded, + uint64 *out_incarnations); +extern uint64 cluster_formation_marker_incarnation_for(const uint64 *incarnation_by_node, + int32 node_id); /* * qvotec formation-marker mailbox (mirrors the join-marker submit pattern): @@ -113,14 +110,13 @@ extern uint64 cluster_formation_marker_incarnation_for( * majority of disks carries the EXACT image (majority readback). A marker * that cannot reach majority on every target member fails closed. */ -typedef struct ClusterFormationMarkerSubmitRequest -{ +typedef struct ClusterFormationMarkerSubmitRequest { bool active; uint64 request_seq; uint64 completion_seq; - uint32 result; /* bool success */ + uint32 result; /* bool success */ uint8 marker_bytes[CLUSTER_VOTING_SLOT_BYTES]; uint8 target_members[CLUSTER_FORMATION_MARKER_BITMAP_BYTES]; } ClusterFormationMarkerSubmitRequest; -#endif /* CLUSTER_FORMATION_MARKER_H */ +#endif /* CLUSTER_FORMATION_MARKER_H */ diff --git a/src/include/cluster/cluster_gcs.h b/src/include/cluster/cluster_gcs.h index 39f618b152d..59ac929b847 100644 --- a/src/include/cluster/cluster_gcs.h +++ b/src/include/cluster/cluster_gcs.h @@ -148,8 +148,7 @@ cluster_gcs_reply_matches_outstanding(const GcsReplyPayload *reply, uint64 expec uint8 expected_transition_id, int32 expected_master_node, uint32 authenticated_source_node) { - return reply != NULL && expected_request_id != 0 - && reply->request_id == expected_request_id + return reply != NULL && expected_request_id != 0 && reply->request_id == expected_request_id && reply->transition_id == expected_transition_id && reply->status <= GCS_REPLY_DENIED_EPOCH_STALE && reply->reserved_0[0] == 0 && reply->reserved_0[1] == 0 && expected_master_node >= 0 diff --git a/src/include/cluster/cluster_gcs_block.h b/src/include/cluster/cluster_gcs_block.h index 1d9d6259381..cf5592d781f 100644 --- a/src/include/cluster/cluster_gcs_block.h +++ b/src/include/cluster/cluster_gcs_block.h @@ -76,8 +76,8 @@ #include "cluster/cluster_sf_dep.h" /* ClusterSfDepVec / max origins */ #include "cluster/cluster_terminal_ref_census.h" #include "cluster/cluster_tx_resolve.h" -#include "storage/block.h" /* BLCKSZ */ -#include "storage/buf_internals.h" /* BufferTag, BufferDesc */ +#include "storage/block.h" /* BLCKSZ */ +#include "storage/buf_internals.h" /* BufferTag, BufferDesc */ #ifdef USE_PGRAC_CLUSTER @@ -127,56 +127,37 @@ typedef struct ResourceXRemoteSFailureDecision { * lock domains before returning the terminal reference. */ static inline bool cluster_gcs_resource_x_target_terminal_resample_exact( - ClusterPcmOwnResult candidate_result, - const ClusterPcmOwnSnapshot *before_n, - const ClusterPcmOwnSnapshot *live_x, - ResourceXApplyResult round_snapshot_result, + ClusterPcmOwnResult candidate_result, const ClusterPcmOwnSnapshot *before_n, + const ClusterPcmOwnSnapshot *live_x, ResourceXApplyResult round_snapshot_result, const ResourceXBootstrapRoundFailureSnapshot *round) { - if (candidate_result != CLUSTER_PCM_OWN_STALE - || before_n == NULL || live_x == NULL || round == NULL - || round_snapshot_result != RESOURCE_X_APPLY_APPLIED + if (candidate_result != CLUSTER_PCM_OWN_STALE || before_n == NULL || live_x == NULL + || round == NULL || round_snapshot_result != RESOURCE_X_APPLY_APPLIED || round->terminal != 1) return false; if (!BufferTagsEqual(&before_n->tag, &live_x->tag) - || !BufferTagsEqual(&live_x->tag, - &round->ref.assertion.resource) - || before_n->pcm_state != (uint8) PCM_STATE_N - || before_n->flags != 0 - || before_n->generation == UINT64_MAX - || before_n->reservation_token == UINT64_MAX - || before_n->writer_activation_token != 0 - || before_n->resource_x_activation_generation != 0 - || live_x->pcm_state != (uint8) PCM_STATE_X - || live_x->flags != 0 - || live_x->generation == 0 - || live_x->generation == UINT64_MAX - || live_x->generation == before_n->generation - || live_x->reservation_token == 0 - || live_x->reservation_token == UINT64_MAX - || live_x->writer_activation_token != 0 - || live_x->resource_x_activation_generation != 0) + || !BufferTagsEqual(&live_x->tag, &round->ref.assertion.resource) + || before_n->pcm_state != (uint8)PCM_STATE_N || before_n->flags != 0 + || before_n->generation == UINT64_MAX || before_n->reservation_token == UINT64_MAX + || before_n->writer_activation_token != 0 || before_n->resource_x_activation_generation != 0 + || live_x->pcm_state != (uint8)PCM_STATE_X || live_x->flags != 0 || live_x->generation == 0 + || live_x->generation == UINT64_MAX || live_x->generation == before_n->generation + || live_x->reservation_token == 0 || live_x->reservation_token == UINT64_MAX + || live_x->writer_activation_token != 0 || live_x->resource_x_activation_generation != 0) return false; return round->buffer_ownership_generation == live_x->generation - && round->ref.assertion.requester_node >= 0 - && round->ref.formation != 0 - && round->ref.formation != UINT64_MAX - && round->ref.acquisition_generation != 0 - && round->ref.acquisition_generation != UINT64_MAX - && round->base_authority_generation != 0 - && round->base_authority_generation != UINT64_MAX - && round->authority_generation - > round->base_authority_generation - && round->authority_generation != UINT64_MAX - && round->r4_record_generation != 0 - && round->r4_record_generation != UINT64_MAX - && round->master_session_incarnation != 0 - && round->master_session_incarnation != UINT64_MAX - && round->absolute_deadline_us != 0 - && round->absolute_deadline_us != UINT64_MAX - && round->retired_acquisition_generation - == round->ref.acquisition_generation - && round->progress_flags == 0; + && round->ref.assertion.requester_node >= 0 && round->ref.formation != 0 + && round->ref.formation != UINT64_MAX && round->ref.acquisition_generation != 0 + && round->ref.acquisition_generation != UINT64_MAX + && round->base_authority_generation != 0 + && round->base_authority_generation != UINT64_MAX + && round->authority_generation > round->base_authority_generation + && round->authority_generation != UINT64_MAX && round->r4_record_generation != 0 + && round->r4_record_generation != UINT64_MAX && round->master_session_incarnation != 0 + && round->master_session_incarnation != UINT64_MAX && round->absolute_deadline_us != 0 + && round->absolute_deadline_us != UINT64_MAX + && round->retired_acquisition_generation == round->ref.acquisition_generation + && round->progress_flags == 0; } /* The same-node T1 executor can finish its exact N+GRANT_PENDING install and @@ -217,10 +198,8 @@ cluster_gcs_resource_x_target_terminal_resample_exact( * mask is the exact stable cover that permits a fresh driver iteration. */ static inline uint64 cluster_gcs_resource_x_pending_terminal_resample_mismatch( - const ClusterPcmOwnSnapshot *before_pending, - const ClusterPcmOwnSnapshot *live_x, - ResourceXApplyResult round_snapshot_result, - const ResourceXBootstrapRoundFailureSnapshot *round) + const ClusterPcmOwnSnapshot *before_pending, const ClusterPcmOwnSnapshot *live_x, + ResourceXApplyResult round_snapshot_result, const ResourceXBootstrapRoundFailureSnapshot *round) { uint64 mismatch = RESOURCE_X_PENDING_TERMINAL_MISMATCH_NONE; @@ -233,19 +212,18 @@ cluster_gcs_resource_x_pending_terminal_resample_mismatch( if (!BufferTagsEqual(&before_pending->tag, &live_x->tag) || !BufferTagsEqual(&live_x->tag, &round->ref.assertion.resource)) mismatch |= RESOURCE_X_PENDING_TERMINAL_MISMATCH_TAG; - if (before_pending->pcm_state != (uint8) PCM_STATE_N) + if (before_pending->pcm_state != (uint8)PCM_STATE_N) mismatch |= RESOURCE_X_PENDING_TERMINAL_MISMATCH_BEFORE_STATE; if (before_pending->flags != PCM_OWN_FLAG_GRANT_PENDING) mismatch |= RESOURCE_X_PENDING_TERMINAL_MISMATCH_BEFORE_FLAGS; if (before_pending->generation >= UINT64_MAX - 1) mismatch |= RESOURCE_X_PENDING_TERMINAL_MISMATCH_BEFORE_GENERATION; - if (before_pending->reservation_token == 0 - || before_pending->reservation_token == UINT64_MAX) + if (before_pending->reservation_token == 0 || before_pending->reservation_token == UINT64_MAX) mismatch |= RESOURCE_X_PENDING_TERMINAL_MISMATCH_BEFORE_TOKEN; if (before_pending->writer_activation_token != 0 || before_pending->resource_x_activation_generation != 0) mismatch |= RESOURCE_X_PENDING_TERMINAL_MISMATCH_BEFORE_ACTIVATION; - if (live_x->pcm_state != (uint8) PCM_STATE_X) + if (live_x->pcm_state != (uint8)PCM_STATE_X) mismatch |= RESOURCE_X_PENDING_TERMINAL_MISMATCH_LIVE_STATE; if (live_x->flags != 0) mismatch |= RESOURCE_X_PENDING_TERMINAL_MISMATCH_LIVE_FLAGS; @@ -254,8 +232,7 @@ cluster_gcs_resource_x_pending_terminal_resample_mismatch( mismatch |= RESOURCE_X_PENDING_TERMINAL_MISMATCH_LIVE_GENERATION; if (live_x->reservation_token != before_pending->reservation_token) mismatch |= RESOURCE_X_PENDING_TERMINAL_MISMATCH_LIVE_TOKEN; - if (live_x->writer_activation_token != 0 - || live_x->resource_x_activation_generation != 0) + if (live_x->writer_activation_token != 0 || live_x->resource_x_activation_generation != 0) mismatch |= RESOURCE_X_PENDING_TERMINAL_MISMATCH_LIVE_ACTIVATION; if (round->buffer_ownership_generation != live_x->generation) mismatch |= RESOURCE_X_PENDING_TERMINAL_MISMATCH_ROUND_BUFFER_GENERATION; @@ -263,26 +240,20 @@ cluster_gcs_resource_x_pending_terminal_resample_mismatch( mismatch |= RESOURCE_X_PENDING_TERMINAL_MISMATCH_ROUND_REQUESTER; if (round->ref.formation == 0 || round->ref.formation == UINT64_MAX) mismatch |= RESOURCE_X_PENDING_TERMINAL_MISMATCH_ROUND_FORMATION; - if (round->ref.acquisition_generation == 0 - || round->ref.acquisition_generation == UINT64_MAX) + if (round->ref.acquisition_generation == 0 || round->ref.acquisition_generation == UINT64_MAX) mismatch |= RESOURCE_X_PENDING_TERMINAL_MISMATCH_ROUND_ACQUISITION; - if (round->base_authority_generation == 0 - || round->base_authority_generation == UINT64_MAX) + if (round->base_authority_generation == 0 || round->base_authority_generation == UINT64_MAX) mismatch |= RESOURCE_X_PENDING_TERMINAL_MISMATCH_ROUND_BASE_AUTHORITY; if (round->authority_generation <= round->base_authority_generation || round->authority_generation == UINT64_MAX) mismatch |= RESOURCE_X_PENDING_TERMINAL_MISMATCH_ROUND_AUTHORITY; - if (round->r4_record_generation == 0 - || round->r4_record_generation == UINT64_MAX) + if (round->r4_record_generation == 0 || round->r4_record_generation == UINT64_MAX) mismatch |= RESOURCE_X_PENDING_TERMINAL_MISMATCH_ROUND_R4; - if (round->master_session_incarnation == 0 - || round->master_session_incarnation == UINT64_MAX) + if (round->master_session_incarnation == 0 || round->master_session_incarnation == UINT64_MAX) mismatch |= RESOURCE_X_PENDING_TERMINAL_MISMATCH_ROUND_SESSION; - if (round->absolute_deadline_us == 0 - || round->absolute_deadline_us == UINT64_MAX) + if (round->absolute_deadline_us == 0 || round->absolute_deadline_us == UINT64_MAX) mismatch |= RESOURCE_X_PENDING_TERMINAL_MISMATCH_ROUND_DEADLINE; - if (round->retired_acquisition_generation - != round->ref.acquisition_generation) + if (round->retired_acquisition_generation != round->ref.acquisition_generation) mismatch |= RESOURCE_X_PENDING_TERMINAL_MISMATCH_ROUND_RETIRED; if (round->progress_flags != 0) mismatch |= RESOURCE_X_PENDING_TERMINAL_MISMATCH_ROUND_PROGRESS; @@ -291,14 +262,12 @@ cluster_gcs_resource_x_pending_terminal_resample_mismatch( static inline bool cluster_gcs_resource_x_target_pending_terminal_resample_exact( - const ClusterPcmOwnSnapshot *before_pending, - const ClusterPcmOwnSnapshot *live_x, - ResourceXApplyResult round_snapshot_result, - const ResourceXBootstrapRoundFailureSnapshot *round) + const ClusterPcmOwnSnapshot *before_pending, const ClusterPcmOwnSnapshot *live_x, + ResourceXApplyResult round_snapshot_result, const ResourceXBootstrapRoundFailureSnapshot *round) { - return cluster_gcs_resource_x_pending_terminal_resample_mismatch( - before_pending, live_x, round_snapshot_result, round) - == RESOURCE_X_PENDING_TERMINAL_MISMATCH_NONE; + return cluster_gcs_resource_x_pending_terminal_resample_mismatch(before_pending, live_x, + round_snapshot_result, round) + == RESOURCE_X_PENDING_TERMINAL_MISMATCH_NONE; } /* A legacy local acquire and the target-only Resource-X driver serialize @@ -310,11 +279,11 @@ cluster_gcs_resource_x_target_pending_terminal_resample_exact( * bounded sleep/reprobe with the original diagnostic timestamp. The next * iteration validates the successor through its canonical predicate. */ static inline bool -cluster_gcs_resource_x_target_local_n_reservation_retry_exact( - const ClusterPcmOwnSnapshot *before, - ClusterPcmOwnResult live_result, - const ClusterPcmOwnSnapshot *live, - uint64 now_us, uint64 absolute_deadline_us) +cluster_gcs_resource_x_target_local_n_reservation_retry_exact(const ClusterPcmOwnSnapshot *before, + ClusterPcmOwnResult live_result, + const ClusterPcmOwnSnapshot *live, + uint64 now_us, + uint64 absolute_deadline_us) { bool before_pending; @@ -323,28 +292,22 @@ cluster_gcs_resource_x_target_local_n_reservation_retry_exact( return false; before_pending = before->flags == PCM_OWN_FLAG_GRANT_PENDING; if ((!before_pending && before->flags != 0) - || live_result != (before_pending - ? CLUSTER_PCM_OWN_OK : CLUSTER_PCM_OWN_STALE) - || !BufferTagsEqual(&before->tag, &live->tag) - || before->pcm_state != (uint8) PCM_STATE_N - || live->pcm_state != (uint8) PCM_STATE_N - || (live->flags != 0 - && live->flags != PCM_OWN_FLAG_GRANT_PENDING) - || before->generation == UINT64_MAX - || live->generation != before->generation - || before->reservation_token == UINT64_MAX - || live->reservation_token == UINT64_MAX - || before->writer_activation_token != 0 - || live->writer_activation_token != 0 + || live_result != (before_pending ? CLUSTER_PCM_OWN_OK : CLUSTER_PCM_OWN_STALE) + || !BufferTagsEqual(&before->tag, &live->tag) || before->pcm_state != (uint8)PCM_STATE_N + || live->pcm_state != (uint8)PCM_STATE_N + || (live->flags != 0 && live->flags != PCM_OWN_FLAG_GRANT_PENDING) + || before->generation == UINT64_MAX || live->generation != before->generation + || before->reservation_token == UINT64_MAX || live->reservation_token == UINT64_MAX + || before->writer_activation_token != 0 || live->writer_activation_token != 0 || before->resource_x_activation_generation != 0 || live->resource_x_activation_generation != 0) return false; if (before_pending) return before->reservation_token != 0 - && live->reservation_token >= before->reservation_token - && (live->flags == 0 || live->reservation_token != 0); + && live->reservation_token >= before->reservation_token + && (live->flags == 0 || live->reservation_token != 0); return live->reservation_token > before->reservation_token - && (live->flags == 0 || live->reservation_token != 0); + && (live->flags == 0 || live->reservation_token != 0); } /* An ordinary pre-assert observation is not a reservation or authority. @@ -378,16 +341,14 @@ cluster_gcs_resource_x_target_preassert_resample_exact( * already-joined remote carrier only for VM/FSM, whose exact retained image * is installed by the existing Resource-X target path before X commit. */ static inline bool -GcsBlockResourceXDirectInitProofAllowedExact( - const BufferTag *tag, bool durable_proof, bool remote_proof) +GcsBlockResourceXDirectInitProofAllowedExact(const BufferTag *tag, bool durable_proof, + bool remote_proof) { if (tag == NULL || durable_proof == remote_proof) return false; if (durable_proof) return true; - return remote_proof - && (tag->forkNum == VISIBILITYMAP_FORKNUM - || tag->forkNum == FSM_FORKNUM); + return remote_proof && (tag->forkNum == VISIBILITYMAP_FORKNUM || tag->forkNum == FSM_FORKNUM); } /* A clean cached X observation can race one complete type-17 X-to-N @@ -411,22 +372,15 @@ cluster_gcs_resource_x_target_empty_round_drift_retry_exact( || now_us == 0 || now_us == UINT64_MAX || absolute_deadline_us == 0 || absolute_deadline_us == UINT64_MAX) return false; - if (!BufferTagsEqual(&before_x->tag, &live_n->tag) - || before_x->pcm_state != (uint8) PCM_STATE_X - || before_x->flags != 0 - || before_x->generation == 0 - || before_x->generation >= UINT64_MAX - 1 - || before_x->reservation_token == 0 - || before_x->reservation_token >= UINT64_MAX - 1 - || before_x->writer_activation_token != 0 + if (!BufferTagsEqual(&before_x->tag, &live_n->tag) || before_x->pcm_state != (uint8)PCM_STATE_X + || before_x->flags != 0 || before_x->generation == 0 + || before_x->generation >= UINT64_MAX - 1 || before_x->reservation_token == 0 + || before_x->reservation_token >= UINT64_MAX - 1 || before_x->writer_activation_token != 0 || before_x->resource_x_activation_generation != 0 - || live_n->pcm_state != (uint8) PCM_STATE_N - || live_n->flags != 0 + || live_n->pcm_state != (uint8)PCM_STATE_N || live_n->flags != 0 || live_n->generation != before_x->generation + 1 - || live_n->reservation_token - != before_x->reservation_token + 1 - || live_n->writer_activation_token != 0 - || live_n->resource_x_activation_generation != 0) + || live_n->reservation_token != before_x->reservation_token + 1 + || live_n->writer_activation_token != 0 || live_n->resource_x_activation_generation != 0) return false; return true; } @@ -448,24 +402,17 @@ cluster_gcs_resource_x_target_retained_predecessor_retry_exact( || now_us == 0 || now_us == UINT64_MAX || absolute_deadline_us == 0 || absolute_deadline_us == UINT64_MAX) return false; - if (!BufferTagsEqual(&before_x->tag, &live_n->tag) - || before_x->pcm_state != (uint8) PCM_STATE_X - || before_x->flags != 0 - || before_x->generation == 0 - || before_x->generation >= UINT64_MAX - 1 - || before_x->reservation_token == 0 - || before_x->reservation_token == UINT64_MAX - || before_x->writer_activation_token != 0 + if (!BufferTagsEqual(&before_x->tag, &live_n->tag) || before_x->pcm_state != (uint8)PCM_STATE_X + || before_x->flags != 0 || before_x->generation == 0 + || before_x->generation >= UINT64_MAX - 1 || before_x->reservation_token == 0 + || before_x->reservation_token == UINT64_MAX || before_x->writer_activation_token != 0 || before_x->resource_x_activation_generation != 0 - || live_n->pcm_state != (uint8) PCM_STATE_N - || (live_n->flags != PCM_OWN_FLAG_REVOKING - && live_n->flags != 0) - || live_n->generation != before_x->generation + 1 - || live_n->reservation_token == 0 + || live_n->pcm_state != (uint8)PCM_STATE_N + || (live_n->flags != PCM_OWN_FLAG_REVOKING && live_n->flags != 0) + || live_n->generation != before_x->generation + 1 || live_n->reservation_token == 0 || live_n->reservation_token == UINT64_MAX || live_n->reservation_token <= before_x->reservation_token - || live_n->writer_activation_token != 0 - || live_n->resource_x_activation_generation != 0) + || live_n->writer_activation_token != 0 || live_n->resource_x_activation_generation != 0) return false; return true; } @@ -479,18 +426,13 @@ cluster_gcs_resource_x_target_retained_predecessor_retry_exact( static inline bool cluster_gcs_resource_x_target_undrained_current_predecessor_exact( bool retained_pair_exact, bool retained_buffer_exact, - ClusterPcmOwnResult current_candidate_result, - const ClusterPcmOwnSnapshot *current_n) + ClusterPcmOwnResult current_candidate_result, const ClusterPcmOwnSnapshot *current_n) { if (!retained_pair_exact || retained_buffer_exact - || current_candidate_result != CLUSTER_PCM_OWN_OK - || current_n == NULL - || current_n->pcm_state != (uint8) PCM_STATE_N - || current_n->flags != 0 - || current_n->generation == 0 - || current_n->generation == UINT64_MAX - || current_n->reservation_token == 0 - || current_n->reservation_token == UINT64_MAX + || current_candidate_result != CLUSTER_PCM_OWN_OK || current_n == NULL + || current_n->pcm_state != (uint8)PCM_STATE_N || current_n->flags != 0 + || current_n->generation == 0 || current_n->generation == UINT64_MAX + || current_n->reservation_token == 0 || current_n->reservation_token == UINT64_MAX || current_n->writer_activation_token != 0 || current_n->resource_x_activation_generation != 0) return false; @@ -522,12 +464,9 @@ cluster_gcs_resource_x_event_owner_identity(int32 procno, int32 process_pid) static inline uint32 cluster_gcs_resource_x_dispatch_recheck_failure_mask( - bool admission_current, bool gate_session_current, - bool requester_sampled, bool master_sampled, - uint32 expected_requester_generation, - uint32 expected_master_generation, - uint32 observed_requester_generation, - uint32 observed_master_generation) + bool admission_current, bool gate_session_current, bool requester_sampled, bool master_sampled, + uint32 expected_requester_generation, uint32 expected_master_generation, + uint32 observed_requester_generation, uint32 observed_master_generation) { uint32 mask = RESOURCE_X_DISPATCH_RECHECK_OK; @@ -553,10 +492,10 @@ cluster_gcs_resource_x_dispatch_recheck_failure_mask( * publication failure is ambiguous. This helper owns no state and grants no * authority. */ static inline ResourceXRemoteSFailureDecision -cluster_gcs_resource_x_remote_s_failure_decide( - ResourceXRemoteSStage stage, ResourceXFailureDomain cause_domain, - bool cancel_attempted, bool cancel_ok, - bool abort_attempted, bool abort_ok) +cluster_gcs_resource_x_remote_s_failure_decide(ResourceXRemoteSStage stage, + ResourceXFailureDomain cause_domain, + bool cancel_attempted, bool cancel_ok, + bool abort_attempted, bool abort_ok) { ResourceXRemoteSFailureDecision decision; @@ -564,8 +503,7 @@ cluster_gcs_resource_x_remote_s_failure_decide( decision.global_fail_closed = true; decision.discard_old_round = false; decision.rollback_complete = false; - if (cause_domain <= RESOURCE_X_FAIL_NONE - || cause_domain > RESOURCE_X_FAIL_INTERNAL_CORRUPTION) + if (cause_domain <= RESOURCE_X_FAIL_NONE || cause_domain > RESOURCE_X_FAIL_INTERNAL_CORRUPTION) return decision; switch (stage) { @@ -579,8 +517,7 @@ cluster_gcs_resource_x_remote_s_failure_decide( if (cancel_attempted || !abort_attempted) return decision; if (!abort_ok) { - decision.domain - = RESOURCE_X_FAIL_POST_MUTATION_AMBIGUITY; + decision.domain = RESOURCE_X_FAIL_POST_MUTATION_AMBIGUITY; return decision; } decision.rollback_complete = true; @@ -589,8 +526,7 @@ cluster_gcs_resource_x_remote_s_failure_decide( if (!cancel_attempted || !abort_attempted) return decision; if (!cancel_ok || !abort_ok) { - decision.domain - = RESOURCE_X_FAIL_POST_MUTATION_AMBIGUITY; + decision.domain = RESOURCE_X_FAIL_POST_MUTATION_AMBIGUITY; return decision; } decision.rollback_complete = true; @@ -607,11 +543,9 @@ cluster_gcs_resource_x_remote_s_failure_decide( } decision.domain = cause_domain; - decision.global_fail_closed - = cause_domain == RESOURCE_X_FAIL_POST_MUTATION_AMBIGUITY - || cause_domain == RESOURCE_X_FAIL_INTERNAL_CORRUPTION; - decision.discard_old_round - = cause_domain == RESOURCE_X_FAIL_AUTHORITY_DRIFT; + decision.global_fail_closed = cause_domain == RESOURCE_X_FAIL_POST_MUTATION_AMBIGUITY + || cause_domain == RESOURCE_X_FAIL_INTERNAL_CORRUPTION; + decision.discard_old_round = cause_domain == RESOURCE_X_FAIL_AUTHORITY_DRIFT; return decision; } @@ -688,7 +622,7 @@ static inline bool cluster_gcs_pcm_x_auth_result_retryable(PcmXSessionAuthResult result) { return result >= PCM_X_SESSION_AUTH_CONNECTION_NOT_READY - && result <= PCM_X_SESSION_AUTH_CONNECTION_TORN; + && result <= PCM_X_SESSION_AUTH_CONNECTION_TORN; } /* ============================================================ @@ -1027,12 +961,9 @@ StaticAssertDecl(GCS_BLOCK_REPLY_UNDO_VERDICT_RESULT == GCS_BLOCK_REPLY_UNDO_TT_ StaticAssertDecl(GCS_BLOCK_REPLY_UNDO_MULTI_VERDICT_RESULT == GCS_BLOCK_REPLY_UNDO_VERDICT_RESULT + 1, "spec-7.1 D3-b undo-multi-verdict status must follow undo-verdict"); -StaticAssertDecl(GCS_BLOCK_REPLY_R4_CR_FULL == 21, - "R4 reply status ABI must begin at 21"); -StaticAssertDecl(GCS_BLOCK_REPLY_R4_DENIED == 26, - "R4 reply status ABI must end at 26"); -StaticAssertDecl(GCS_BLOCK_REPLY_CURRENT_MX_DESCRIBE_RESULT - == GCS_BLOCK_REPLY_R4_DENIED + 1, +StaticAssertDecl(GCS_BLOCK_REPLY_R4_CR_FULL == 21, "R4 reply status ABI must begin at 21"); +StaticAssertDecl(GCS_BLOCK_REPLY_R4_DENIED == 26, "R4 reply status ABI must end at 26"); +StaticAssertDecl(GCS_BLOCK_REPLY_CURRENT_MX_DESCRIBE_RESULT == GCS_BLOCK_REPLY_R4_DENIED + 1, "current MX describe result must follow the closed R4 domain"); StaticAssertDecl(GCS_BLOCK_REPLY_CURRENT_MX_MEMBER_PROOF_RESULT == GCS_BLOCK_REPLY_CURRENT_MX_DESCRIBE_RESULT + 1, @@ -1050,8 +981,7 @@ StaticAssertDecl(GCS_BLOCK_REPLY_CURRENT_MX_CTRC_SEAL_RESULT static inline bool GcsBlockReplyStatusIsLegacy(GcsBlockReplyStatus status) { - return status >= GCS_BLOCK_REPLY_GRANTED - && status <= GCS_BLOCK_REPLY_UNDO_MULTI_VERDICT_RESULT; + return status >= GCS_BLOCK_REPLY_GRANTED && status <= GCS_BLOCK_REPLY_UNDO_MULTI_VERDICT_RESULT; } static inline bool @@ -1577,14 +1507,13 @@ StaticAssertDecl(sizeof(GcsBlockReplyHeader) == 48, "spec-2.33 D1 + spec-2.35 HC109 GcsBlockReplyHeader wire ABI 48B " "(request_id 8 + page_lsn 8 + epoch 8 + checksum 4 + " "sender_node 4 + requester_backend_id 4 + transition_id 1 + " - "status 1 + forwarding_master_node_bytes 4 + reserved 6)"); + "status 1 + forwarding_master_node_bytes 4 + reserved 6)"); /* Status 24 alone reuses the six-byte reply tail as * {physical_generation:u32_le, reserved:u16=0}. Generation zero is valid; * UINT32_MAX is exhausted and cannot be published. */ static inline bool -GcsBlockReplyHeaderSetR4UndoGeneration(GcsBlockReplyHeader *header, - uint32 physical_generation) +GcsBlockReplyHeaderSetR4UndoGeneration(GcsBlockReplyHeader *header, uint32 physical_generation) { if (header != NULL) memset(header->reserved_0, 0, sizeof(header->reserved_0)); @@ -1605,13 +1534,11 @@ GcsBlockReplyHeaderGetR4UndoGeneration(const GcsBlockReplyHeader *header, if (physical_generation_out != NULL) *physical_generation_out = 0; - if (header == NULL || physical_generation_out == NULL - || header->reserved_0[4] != 0 || header->reserved_0[5] != 0) + if (header == NULL || physical_generation_out == NULL || header->reserved_0[4] != 0 + || header->reserved_0[5] != 0) return false; - generation = (uint32)header->reserved_0[0] - | ((uint32)header->reserved_0[1] << 8) - | ((uint32)header->reserved_0[2] << 16) - | ((uint32)header->reserved_0[3] << 24); + generation = (uint32)header->reserved_0[0] | ((uint32)header->reserved_0[1] << 8) + | ((uint32)header->reserved_0[2] << 16) | ((uint32)header->reserved_0[3] << 24); if (generation == UINT32_MAX) return false; *physical_generation_out = generation; @@ -1837,13 +1764,12 @@ GcsBlockForwardPayloadGetExpectedPiWatermarkScn(const GcsBlockForwardPayload *p) #define GCS_BLOCK_FORWARD_KIND_CURRENT_MX_MEMBER_PROOF ((uint8)7) #define GCS_BLOCK_FORWARD_KIND_CURRENT_MX_STATS ((uint8)8) #define GCS_BLOCK_FORWARD_KIND_CURRENT_MX_DESCRIBE ((uint8)9) -#define CLUSTER_GCS_BLOCK_R4_INTERNAL_ENDPOINT ((int32)-2) +#define CLUSTER_GCS_BLOCK_R4_INTERNAL_ENDPOINT ((int32) - 2) -StaticAssertDecl(CLUSTER_R4_FORWARD_EXTENDED - < GCS_BLOCK_FORWARD_KIND_CURRENT_MX_MEMBER_PROOF, +StaticAssertDecl(CLUSTER_R4_FORWARD_EXTENDED < GCS_BLOCK_FORWARD_KIND_CURRENT_MX_MEMBER_PROOF, "current MX request domain must follow the closed R4 kind"); StaticAssertDecl(GCS_BLOCK_FORWARD_KIND_CURRENT_MX_STATS - == GCS_BLOCK_FORWARD_KIND_CURRENT_MX_MEMBER_PROOF + 1 + == GCS_BLOCK_FORWARD_KIND_CURRENT_MX_MEMBER_PROOF + 1 && GCS_BLOCK_FORWARD_KIND_CURRENT_MX_DESCRIBE == GCS_BLOCK_FORWARD_KIND_CURRENT_MX_STATS + 1, "current MX request kind allocation changed"); @@ -1858,8 +1784,7 @@ GcsBlockForwardPayloadIsCurrentMxMemberProof(const GcsBlockForwardPayload *paylo static inline bool GcsBlockForwardPayloadIsCurrentMxDescribe(const GcsBlockForwardPayload *payload) { - return payload != NULL - && payload->reserved_0[6] == GCS_BLOCK_FORWARD_KIND_CURRENT_MX_DESCRIBE; + return payload != NULL && payload->reserved_0[6] == GCS_BLOCK_FORWARD_KIND_CURRENT_MX_DESCRIBE; } static inline bool @@ -1872,8 +1797,7 @@ GcsBlockForwardPayloadIsCurrentMxRuntime(const GcsBlockForwardPayload *payload) /* Current-MX overlays the old BufferTag. DATA sharding therefore uses only * the preserved request identity; this synthetic tag is never authority. */ static inline BufferTag -GcsBlockCurrentMxRouteTagMake(uint64 request_id, uint64 epoch, - int32 requester_node, +GcsBlockCurrentMxRouteTagMake(uint64 request_id, uint64 epoch, int32 requester_node, int32 requester_backend_id) { BufferTag tag; @@ -1923,27 +1847,27 @@ static inline ClusterCrBuildResult cluster_cr_build_result_for_reason(ClusterCrBuildReason reason) { switch (reason) { - case CLUSTER_CR_BUILD_NONE: - return CLUSTER_CR_BUILD_FULL; - case CLUSTER_CR_BUILD_TARGET_DISABLED: - case CLUSTER_CR_BUILD_RF_DEFERRED: - case CLUSTER_CR_BUILD_WRONG_MASTER: - case CLUSTER_CR_BUILD_NO_HOLDER: - case CLUSTER_CR_BUILD_HOLDER_AMBIGUOUS: - case CLUSTER_CR_BUILD_HOLDER_MOVED: - case CLUSTER_CR_BUILD_RECOVERING: - case CLUSTER_CR_BUILD_GENERATION_MISMATCH: - case CLUSTER_CR_BUILD_CAPACITY: - case CLUSTER_CR_BUILD_EPOCH_MISMATCH: - return CLUSTER_CR_BUILD_RETRYABLE; - case CLUSTER_CR_BUILD_BAD_LOCATOR: - case CLUSTER_CR_BUILD_BAD_UNDO: - case CLUSTER_CR_BUILD_CHAIN_LIMIT: - case CLUSTER_CR_BUILD_SNAPSHOT_TOO_OLD: - case CLUSTER_CR_BUILD_CANCELLED: - case CLUSTER_CR_BUILD_IO_ERROR: - case CLUSTER_CR_BUILD_PROTOCOL: - return CLUSTER_CR_BUILD_FAIL_CLOSED; + case CLUSTER_CR_BUILD_NONE: + return CLUSTER_CR_BUILD_FULL; + case CLUSTER_CR_BUILD_TARGET_DISABLED: + case CLUSTER_CR_BUILD_RF_DEFERRED: + case CLUSTER_CR_BUILD_WRONG_MASTER: + case CLUSTER_CR_BUILD_NO_HOLDER: + case CLUSTER_CR_BUILD_HOLDER_AMBIGUOUS: + case CLUSTER_CR_BUILD_HOLDER_MOVED: + case CLUSTER_CR_BUILD_RECOVERING: + case CLUSTER_CR_BUILD_GENERATION_MISMATCH: + case CLUSTER_CR_BUILD_CAPACITY: + case CLUSTER_CR_BUILD_EPOCH_MISMATCH: + return CLUSTER_CR_BUILD_RETRYABLE; + case CLUSTER_CR_BUILD_BAD_LOCATOR: + case CLUSTER_CR_BUILD_BAD_UNDO: + case CLUSTER_CR_BUILD_CHAIN_LIMIT: + case CLUSTER_CR_BUILD_SNAPSHOT_TOO_OLD: + case CLUSTER_CR_BUILD_CANCELLED: + case CLUSTER_CR_BUILD_IO_ERROR: + case CLUSTER_CR_BUILD_PROTOCOL: + return CLUSTER_CR_BUILD_FAIL_CLOSED; } return CLUSTER_CR_BUILD_FAIL_CLOSED; } @@ -1960,8 +1884,7 @@ typedef struct ClusterR4CrRouteProof { int32 selected_holder_node; } ClusterR4CrRouteProof; -StaticAssertDecl(sizeof(ClusterR4CrRouteProof) == 80, - "R4 CR route proof must remain 80 bytes"); +StaticAssertDecl(sizeof(ClusterR4CrRouteProof) == 80, "R4 CR route proof must remain 80 bytes"); /* * R4 D3 master-side policy over one coherent PCM snapshot. NONE means one @@ -1971,8 +1894,7 @@ StaticAssertDecl(sizeof(ClusterR4CrRouteProof) == 80, */ static inline ClusterCrBuildReason cluster_r4_route_policy_classify(const PcmAuthoritySnapshot *authority, uint64 current_epoch, - uint64 master_authority_generation, - int32 *selected_holder_out) + uint64 master_authority_generation, int32 *selected_holder_out) { uint32 master_node; @@ -1997,8 +1919,7 @@ cluster_r4_route_policy_classify(const PcmAuthoritySnapshot *authority, uint64 c if (authority->state == PCM_STATE_X) { if (authority->x_holder_node < 0 || authority->x_holder_node >= RESOURCE_X_PROTOCOL_NODE_LIMIT - || authority->s_holders_bitmap != 0 - || master_node != (uint32)authority->x_holder_node) + || authority->s_holders_bitmap != 0 || master_node != (uint32)authority->x_holder_node) return CLUSTER_CR_BUILD_HOLDER_AMBIGUOUS; *selected_holder_out = authority->x_holder_node; } else if (authority->state == PCM_STATE_S) { @@ -2023,10 +1944,8 @@ cluster_r4_route_policy_classify(const PcmAuthoritySnapshot *authority, uint64 c * the selected canonical holder remain exact. */ static inline bool cluster_r4_route_proof_matches(const ClusterR4CrRouteProof *armed, uint64 formation_epoch, - uint64 master_authority_generation, - int32 selected_holder_node, - uint64 master_resource_transition_count, - SCN expected_page_scn) + uint64 master_authority_generation, int32 selected_holder_node, + uint64 master_resource_transition_count, SCN expected_page_scn) { return armed != NULL && selected_holder_node >= 0 && selected_holder_node < RESOURCE_X_PROTOCOL_NODE_LIMIT @@ -2112,252 +2031,258 @@ typedef struct ClusterR4TransitionCell { const char *spec_action; } ClusterR4TransitionCell; -#define CLUSTER_R4_ROUTE_OWNERS \ - (CLUSTER_R4_OWNER_REQUESTER | CLUSTER_R4_OWNER_REAL_MASTER) -#define CLUSTER_R4_FORWARD_OWNERS \ - (CLUSTER_R4_OWNER_REAL_MASTER | CLUSTER_R4_OWNER_HOLDER_LMON) -#define CLUSTER_R4_UNDO_OWNERS \ +#define CLUSTER_R4_ROUTE_OWNERS (CLUSTER_R4_OWNER_REQUESTER | CLUSTER_R4_OWNER_REAL_MASTER) +#define CLUSTER_R4_FORWARD_OWNERS (CLUSTER_R4_OWNER_REAL_MASTER | CLUSTER_R4_OWNER_HOLDER_LMON) +#define CLUSTER_R4_UNDO_OWNERS \ (CLUSTER_R4_OWNER_HOLDER_LMON | CLUSTER_R4_OWNER_HOLDER_LMS | CLUSTER_R4_OWNER_ORIGIN) -#define CLUSTER_R4_CELL(next, alternate, owner, action, text) \ - { (next), (alternate), (owner), (action), (text) } +#define CLUSTER_R4_CELL(next, alternate, owner, action, text) \ + { \ + (next), (alternate), (owner), (action), (text) \ + } static inline const ClusterR4TransitionCell * cluster_r4_transition_lookup(ClusterR4OperationState state, ClusterR4OperationEvent event) { - static const ClusterR4TransitionCell - cluster_r4_transition_manifest[CLUSTER_R4_STATE_COUNT][CLUSTER_R4_EVENT_COUNT] = { - { - CLUSTER_R4_CELL(CLUSTER_R4_STATE_ROUTING, CLUSTER_R4_STATE_INVALID, - CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_ARM_BEFORE_SEND, - "R/arm-before-send"), - CLUSTER_R4_CELL(CLUSTER_R4_STATE_EMPTY, CLUSTER_R4_STATE_INVALID, - CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_DROP, "E/drop"), - CLUSTER_R4_CELL(CLUSTER_R4_STATE_EMPTY, CLUSTER_R4_STATE_INVALID, - CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_DROP, "E/drop"), - CLUSTER_R4_CELL(CLUSTER_R4_STATE_EMPTY, CLUSTER_R4_STATE_INVALID, - CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_DROP, "E/drop"), - CLUSTER_R4_CELL(CLUSTER_R4_STATE_CANCELLED, CLUSTER_R4_STATE_INVALID, - CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_NO_SEND, "K/no-send"), - CLUSTER_R4_CELL(CLUSTER_R4_STATE_EMPTY, CLUSTER_R4_STATE_INVALID, - CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_DROP, "E/drop"), - CLUSTER_R4_CELL(CLUSTER_R4_STATE_EMPTY, CLUSTER_R4_STATE_INVALID, - CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_DROP, "E/drop"), - CLUSTER_R4_CELL(CLUSTER_R4_STATE_RETRYABLE, CLUSTER_R4_STATE_INVALID, - CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_RETRY, "T/retry"), - CLUSTER_R4_CELL(CLUSTER_R4_STATE_FAIL_CLOSED, CLUSTER_R4_STATE_INVALID, - CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_FAIL_PROTOCOL, - "X/FC(protocol)"), - }, - { - CLUSTER_R4_CELL(CLUSTER_R4_STATE_FORWARDED, CLUSTER_R4_STATE_INVALID, - CLUSTER_R4_ROUTE_OWNERS, CLUSTER_R4_ACTION_MASTER_FORWARD, - "F/master selects+forwards"), - CLUSTER_R4_CELL(CLUSTER_R4_STATE_ROUTING, CLUSTER_R4_STATE_INVALID, - CLUSTER_R4_ROUTE_OWNERS, CLUSTER_R4_ACTION_REPLAY_ROUTE, - "R/replay same route"), - CLUSTER_R4_CELL(CLUSTER_R4_STATE_RETRYABLE, CLUSTER_R4_STATE_INVALID, - CLUSTER_R4_ROUTE_OWNERS, CLUSTER_R4_ACTION_RETRY, "T/retry"), - CLUSTER_R4_CELL(CLUSTER_R4_STATE_RETRYABLE, CLUSTER_R4_STATE_INVALID, - CLUSTER_R4_ROUTE_OWNERS, CLUSTER_R4_ACTION_CLOSE_ATTEMPT, - "T/close attempt"), - CLUSTER_R4_CELL(CLUSTER_R4_STATE_CANCELLED, CLUSTER_R4_STATE_INVALID, - CLUSTER_R4_ROUTE_OWNERS, CLUSTER_R4_ACTION_CANCEL_ROUTE, - "K/cancel route"), - CLUSTER_R4_CELL(CLUSTER_R4_STATE_RETRYABLE, CLUSTER_R4_STATE_INVALID, - CLUSTER_R4_ROUTE_OWNERS, CLUSTER_R4_ACTION_RETRY, "T/retry"), - CLUSTER_R4_CELL(CLUSTER_R4_STATE_RETRYABLE, CLUSTER_R4_STATE_INVALID, - CLUSTER_R4_ROUTE_OWNERS, CLUSTER_R4_ACTION_STALE_ROUTE, - "T/stale route"), - CLUSTER_R4_CELL(CLUSTER_R4_STATE_RETRYABLE, CLUSTER_R4_STATE_INVALID, - CLUSTER_R4_ROUTE_OWNERS, CLUSTER_R4_ACTION_RETRY, "T/retry"), - CLUSTER_R4_CELL(CLUSTER_R4_STATE_FAIL_CLOSED, CLUSTER_R4_STATE_INVALID, - CLUSTER_R4_ROUTE_OWNERS, CLUSTER_R4_ACTION_FAIL_PROTOCOL, - "X/FC(protocol)"), - }, - { - CLUSTER_R4_CELL(CLUSTER_R4_STATE_BUILDING, CLUSTER_R4_STATE_INVALID, - CLUSTER_R4_FORWARD_OWNERS, CLUSTER_R4_ACTION_HOLDER_STABLE_COPY, - "B/holder stable copy"), - CLUSTER_R4_CELL(CLUSTER_R4_STATE_FORWARDED, CLUSTER_R4_STATE_INVALID, - CLUSTER_R4_FORWARD_OWNERS, CLUSTER_R4_ACTION_DROP_OR_REPLAY, - "F/drop or replay"), - CLUSTER_R4_CELL(CLUSTER_R4_STATE_RETRYABLE, CLUSTER_R4_STATE_INVALID, - CLUSTER_R4_FORWARD_OWNERS, CLUSTER_R4_ACTION_RETRY, "T/retry"), - CLUSTER_R4_CELL(CLUSTER_R4_STATE_RETRYABLE, CLUSTER_R4_STATE_INVALID, - CLUSTER_R4_FORWARD_OWNERS, CLUSTER_R4_ACTION_CLOSE_ATTEMPT, - "T/close attempt"), - CLUSTER_R4_CELL(CLUSTER_R4_STATE_CANCELLED, CLUSTER_R4_STATE_INVALID, - CLUSTER_R4_FORWARD_OWNERS, CLUSTER_R4_ACTION_CANCEL_SLOT, - "K/cancel slot"), - CLUSTER_R4_CELL(CLUSTER_R4_STATE_RETRYABLE, CLUSTER_R4_STATE_INVALID, - CLUSTER_R4_FORWARD_OWNERS, CLUSTER_R4_ACTION_RETRY, "T/retry"), - CLUSTER_R4_CELL(CLUSTER_R4_STATE_RETRYABLE, CLUSTER_R4_STATE_INVALID, - CLUSTER_R4_FORWARD_OWNERS, CLUSTER_R4_ACTION_STALE_SLOT, - "T/stale slot"), - CLUSTER_R4_CELL(CLUSTER_R4_STATE_RETRYABLE, CLUSTER_R4_STATE_INVALID, - CLUSTER_R4_FORWARD_OWNERS, CLUSTER_R4_ACTION_RETRY, "T/retry"), - CLUSTER_R4_CELL(CLUSTER_R4_STATE_FAIL_CLOSED, CLUSTER_R4_STATE_INVALID, - CLUSTER_R4_FORWARD_OWNERS, CLUSTER_R4_ACTION_FAIL_PROTOCOL, - "X/FC(protocol)"), - }, - { - CLUSTER_R4_CELL(CLUSTER_R4_STATE_WAIT_UNDO, CLUSTER_R4_STATE_REPLIED, - CLUSTER_R4_OWNER_HOLDER_LMS, CLUSTER_R4_ACTION_REQUEST_UNDO_OR_PUBLISH, - "U/request foreign undo or P/publish result"), - CLUSTER_R4_CELL(CLUSTER_R4_STATE_BUILDING, CLUSTER_R4_STATE_INVALID, - CLUSTER_R4_OWNER_HOLDER_LMS, CLUSTER_R4_ACTION_DROP, "B/drop"), - CLUSTER_R4_CELL(CLUSTER_R4_STATE_RETRYABLE, CLUSTER_R4_STATE_INVALID, - CLUSTER_R4_OWNER_HOLDER_LMS, CLUSTER_R4_ACTION_RETRY, "T/retry"), - CLUSTER_R4_CELL(CLUSTER_R4_STATE_RETRYABLE, CLUSTER_R4_STATE_INVALID, - CLUSTER_R4_OWNER_HOLDER_LMS, CLUSTER_R4_ACTION_ABORT_SCRATCH, - "T/abort scratch"), - CLUSTER_R4_CELL(CLUSTER_R4_STATE_CANCELLED, CLUSTER_R4_STATE_INVALID, - CLUSTER_R4_OWNER_HOLDER_LMS, CLUSTER_R4_ACTION_ABORT_SCRATCH, - "K/abort scratch"), - CLUSTER_R4_CELL(CLUSTER_R4_STATE_RETRYABLE, CLUSTER_R4_STATE_INVALID, - CLUSTER_R4_OWNER_HOLDER_LMS, CLUSTER_R4_ACTION_RETRY, "T/retry"), - CLUSTER_R4_CELL(CLUSTER_R4_STATE_RETRYABLE, CLUSTER_R4_STATE_INVALID, - CLUSTER_R4_OWNER_HOLDER_LMS, CLUSTER_R4_ACTION_ABORT_SCRATCH, - "T/abort scratch"), - CLUSTER_R4_CELL(CLUSTER_R4_STATE_RETRYABLE, CLUSTER_R4_STATE_INVALID, - CLUSTER_R4_OWNER_HOLDER_LMS, CLUSTER_R4_ACTION_RETRY, "T/retry"), - CLUSTER_R4_CELL(CLUSTER_R4_STATE_FAIL_CLOSED, CLUSTER_R4_STATE_INVALID, - CLUSTER_R4_OWNER_HOLDER_LMS, CLUSTER_R4_ACTION_FAIL_DATA_PROTOCOL, - "X/FC(data/protocol)"), - }, - { - CLUSTER_R4_CELL(CLUSTER_R4_STATE_BUILDING, CLUSTER_R4_STATE_INVALID, - CLUSTER_R4_UNDO_OWNERS, CLUSTER_R4_ACTION_EXACT_UNDO_REPLY, - "B/exact undo reply"), - CLUSTER_R4_CELL(CLUSTER_R4_STATE_WAIT_UNDO, CLUSTER_R4_STATE_INVALID, - CLUSTER_R4_UNDO_OWNERS, CLUSTER_R4_ACTION_DROP, "U/drop"), - CLUSTER_R4_CELL(CLUSTER_R4_STATE_RETRYABLE, CLUSTER_R4_STATE_INVALID, - CLUSTER_R4_UNDO_OWNERS, CLUSTER_R4_ACTION_RETRY, "T/retry"), - CLUSTER_R4_CELL(CLUSTER_R4_STATE_RETRYABLE, CLUSTER_R4_STATE_INVALID, - CLUSTER_R4_UNDO_OWNERS, CLUSTER_R4_ACTION_ABORT_SCRATCH, - "T/abort scratch"), - CLUSTER_R4_CELL(CLUSTER_R4_STATE_CANCELLED, CLUSTER_R4_STATE_INVALID, - CLUSTER_R4_UNDO_OWNERS, CLUSTER_R4_ACTION_ABORT_SCRATCH, - "K/abort scratch"), - CLUSTER_R4_CELL(CLUSTER_R4_STATE_RETRYABLE, CLUSTER_R4_STATE_INVALID, - CLUSTER_R4_UNDO_OWNERS, CLUSTER_R4_ACTION_RETRY, "T/retry"), - CLUSTER_R4_CELL(CLUSTER_R4_STATE_RETRYABLE, CLUSTER_R4_STATE_INVALID, - CLUSTER_R4_UNDO_OWNERS, CLUSTER_R4_ACTION_ABORT_SCRATCH, - "T/abort scratch"), - CLUSTER_R4_CELL(CLUSTER_R4_STATE_RETRYABLE, CLUSTER_R4_STATE_INVALID, - CLUSTER_R4_UNDO_OWNERS, CLUSTER_R4_ACTION_RETRY, "T/retry"), - CLUSTER_R4_CELL(CLUSTER_R4_STATE_FAIL_CLOSED, CLUSTER_R4_STATE_INVALID, - CLUSTER_R4_UNDO_OWNERS, CLUSTER_R4_ACTION_FAIL_DATA_PROTOCOL, - "X/FC(data/protocol)"), - }, - { - CLUSTER_R4_CELL(CLUSTER_R4_STATE_CONSUMED, CLUSTER_R4_STATE_INVALID, - CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_CONSUMER_CAS, - "C/exact consumer CAS"), - CLUSTER_R4_CELL(CLUSTER_R4_STATE_REPLIED, CLUSTER_R4_STATE_INVALID, - CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_DROP, "P/drop"), - CLUSTER_R4_CELL(CLUSTER_R4_STATE_REPLIED, CLUSTER_R4_STATE_INVALID, - CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_DROP, "P/drop"), - CLUSTER_R4_CELL(CLUSTER_R4_STATE_REPLIED, CLUSTER_R4_STATE_INVALID, - CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_DROP, "P/drop"), - CLUSTER_R4_CELL(CLUSTER_R4_STATE_CANCELLED, CLUSTER_R4_STATE_INVALID, - CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_DROP_RESULT, - "K/drop result"), - CLUSTER_R4_CELL(CLUSTER_R4_STATE_REPLIED, CLUSTER_R4_STATE_INVALID, - CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_DROP, "P/drop"), - CLUSTER_R4_CELL(CLUSTER_R4_STATE_REPLIED, CLUSTER_R4_STATE_INVALID, - CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_DROP, "P/drop"), - CLUSTER_R4_CELL(CLUSTER_R4_STATE_REPLIED, CLUSTER_R4_STATE_INVALID, - CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_DROP, "P/drop"), - CLUSTER_R4_CELL(CLUSTER_R4_STATE_REPLIED, CLUSTER_R4_STATE_INVALID, - CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_DROP, "P/drop"), - }, - { - CLUSTER_R4_CELL(CLUSTER_R4_STATE_CONSUMED, CLUSTER_R4_STATE_INVALID, - CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_DROP, "C/drop"), - CLUSTER_R4_CELL(CLUSTER_R4_STATE_CONSUMED, CLUSTER_R4_STATE_INVALID, - CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_DROP, "C/drop"), - CLUSTER_R4_CELL(CLUSTER_R4_STATE_CONSUMED, CLUSTER_R4_STATE_INVALID, - CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_DROP, "C/drop"), - CLUSTER_R4_CELL(CLUSTER_R4_STATE_CONSUMED, CLUSTER_R4_STATE_INVALID, - CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_DROP, "C/drop"), - CLUSTER_R4_CELL(CLUSTER_R4_STATE_CONSUMED, CLUSTER_R4_STATE_INVALID, - CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_DROP, "C/drop"), - CLUSTER_R4_CELL(CLUSTER_R4_STATE_CONSUMED, CLUSTER_R4_STATE_INVALID, - CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_DROP, "C/drop"), - CLUSTER_R4_CELL(CLUSTER_R4_STATE_CONSUMED, CLUSTER_R4_STATE_INVALID, - CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_DROP, "C/drop"), - CLUSTER_R4_CELL(CLUSTER_R4_STATE_CONSUMED, CLUSTER_R4_STATE_INVALID, - CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_DROP, "C/drop"), - CLUSTER_R4_CELL(CLUSTER_R4_STATE_CONSUMED, CLUSTER_R4_STATE_INVALID, - CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_DROP, "C/drop"), - }, - { - CLUSTER_R4_CELL(CLUSTER_R4_STATE_ROUTING, CLUSTER_R4_STATE_INVALID, - CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_NEW_REQUEST, - "R/new request id after typed close"), - CLUSTER_R4_CELL(CLUSTER_R4_STATE_RETRYABLE, CLUSTER_R4_STATE_INVALID, - CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_DROP, "T/drop"), - CLUSTER_R4_CELL(CLUSTER_R4_STATE_RETRYABLE, CLUSTER_R4_STATE_INVALID, - CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_DROP, "T/drop"), - CLUSTER_R4_CELL(CLUSTER_R4_STATE_FAIL_CLOSED, CLUSTER_R4_STATE_INVALID, - CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_OVERALL_DEADLINE, - "X/overall deadline"), - CLUSTER_R4_CELL(CLUSTER_R4_STATE_CANCELLED, CLUSTER_R4_STATE_INVALID, - CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_CLEANUP, "K/cleanup"), - CLUSTER_R4_CELL(CLUSTER_R4_STATE_RETRYABLE, CLUSTER_R4_STATE_INVALID, - CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_WAIT_TOPOLOGY, - "T/wait topology"), - CLUSTER_R4_CELL(CLUSTER_R4_STATE_RETRYABLE, CLUSTER_R4_STATE_INVALID, - CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_WAIT_ADMISSION, - "T/wait admission"), - CLUSTER_R4_CELL(CLUSTER_R4_STATE_RETRYABLE, CLUSTER_R4_STATE_INVALID, - CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_BACKOFF, "T/backoff"), - CLUSTER_R4_CELL(CLUSTER_R4_STATE_FAIL_CLOSED, CLUSTER_R4_STATE_INVALID, - CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_FAIL_PROTOCOL, - "X/FC(protocol)"), - }, - { - CLUSTER_R4_CELL(CLUSTER_R4_STATE_FAIL_CLOSED, CLUSTER_R4_STATE_INVALID, - CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_DROP, "X/drop"), - CLUSTER_R4_CELL(CLUSTER_R4_STATE_FAIL_CLOSED, CLUSTER_R4_STATE_INVALID, - CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_DROP, "X/drop"), - CLUSTER_R4_CELL(CLUSTER_R4_STATE_FAIL_CLOSED, CLUSTER_R4_STATE_INVALID, - CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_DROP, "X/drop"), - CLUSTER_R4_CELL(CLUSTER_R4_STATE_FAIL_CLOSED, CLUSTER_R4_STATE_INVALID, - CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_DROP, "X/drop"), - CLUSTER_R4_CELL(CLUSTER_R4_STATE_FAIL_CLOSED, CLUSTER_R4_STATE_INVALID, - CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_CLEANUP, "X/cleanup"), - CLUSTER_R4_CELL(CLUSTER_R4_STATE_FAIL_CLOSED, CLUSTER_R4_STATE_INVALID, - CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_DROP, "X/drop"), - CLUSTER_R4_CELL(CLUSTER_R4_STATE_FAIL_CLOSED, CLUSTER_R4_STATE_INVALID, - CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_DROP, "X/drop"), - CLUSTER_R4_CELL(CLUSTER_R4_STATE_FAIL_CLOSED, CLUSTER_R4_STATE_INVALID, - CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_DROP, "X/drop"), - CLUSTER_R4_CELL(CLUSTER_R4_STATE_FAIL_CLOSED, CLUSTER_R4_STATE_INVALID, - CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_DROP, "X/drop"), - }, - { - CLUSTER_R4_CELL(CLUSTER_R4_STATE_CANCELLED, CLUSTER_R4_STATE_INVALID, - CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_DROP, "K/drop"), - CLUSTER_R4_CELL(CLUSTER_R4_STATE_CANCELLED, CLUSTER_R4_STATE_INVALID, - CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_DROP, "K/drop"), - CLUSTER_R4_CELL(CLUSTER_R4_STATE_CANCELLED, CLUSTER_R4_STATE_INVALID, - CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_DROP, "K/drop"), - CLUSTER_R4_CELL(CLUSTER_R4_STATE_CANCELLED, CLUSTER_R4_STATE_INVALID, - CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_DROP, "K/drop"), - CLUSTER_R4_CELL(CLUSTER_R4_STATE_CANCELLED, CLUSTER_R4_STATE_INVALID, - CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_DROP, "K/drop"), - CLUSTER_R4_CELL(CLUSTER_R4_STATE_CANCELLED, CLUSTER_R4_STATE_INVALID, - CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_DROP, "K/drop"), - CLUSTER_R4_CELL(CLUSTER_R4_STATE_CANCELLED, CLUSTER_R4_STATE_INVALID, - CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_DROP, "K/drop"), - CLUSTER_R4_CELL(CLUSTER_R4_STATE_CANCELLED, CLUSTER_R4_STATE_INVALID, - CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_DROP, "K/drop"), - CLUSTER_R4_CELL(CLUSTER_R4_STATE_CANCELLED, CLUSTER_R4_STATE_INVALID, - CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_DROP, "K/drop"), - }, - }; + static const ClusterR4TransitionCell cluster_r4_transition_manifest[CLUSTER_R4_STATE_COUNT] + [CLUSTER_R4_EVENT_COUNT] + = { + { + CLUSTER_R4_CELL(CLUSTER_R4_STATE_ROUTING, CLUSTER_R4_STATE_INVALID, + CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_ARM_BEFORE_SEND, + "R/arm-before-send"), + CLUSTER_R4_CELL(CLUSTER_R4_STATE_EMPTY, CLUSTER_R4_STATE_INVALID, + CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_DROP, "E/drop"), + CLUSTER_R4_CELL(CLUSTER_R4_STATE_EMPTY, CLUSTER_R4_STATE_INVALID, + CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_DROP, "E/drop"), + CLUSTER_R4_CELL(CLUSTER_R4_STATE_EMPTY, CLUSTER_R4_STATE_INVALID, + CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_DROP, "E/drop"), + CLUSTER_R4_CELL(CLUSTER_R4_STATE_CANCELLED, CLUSTER_R4_STATE_INVALID, + CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_NO_SEND, + "K/no-send"), + CLUSTER_R4_CELL(CLUSTER_R4_STATE_EMPTY, CLUSTER_R4_STATE_INVALID, + CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_DROP, "E/drop"), + CLUSTER_R4_CELL(CLUSTER_R4_STATE_EMPTY, CLUSTER_R4_STATE_INVALID, + CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_DROP, "E/drop"), + CLUSTER_R4_CELL(CLUSTER_R4_STATE_RETRYABLE, CLUSTER_R4_STATE_INVALID, + CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_RETRY, "T/retry"), + CLUSTER_R4_CELL(CLUSTER_R4_STATE_FAIL_CLOSED, CLUSTER_R4_STATE_INVALID, + CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_FAIL_PROTOCOL, + "X/FC(protocol)"), + }, + { + CLUSTER_R4_CELL(CLUSTER_R4_STATE_FORWARDED, CLUSTER_R4_STATE_INVALID, + CLUSTER_R4_ROUTE_OWNERS, CLUSTER_R4_ACTION_MASTER_FORWARD, + "F/master selects+forwards"), + CLUSTER_R4_CELL(CLUSTER_R4_STATE_ROUTING, CLUSTER_R4_STATE_INVALID, + CLUSTER_R4_ROUTE_OWNERS, CLUSTER_R4_ACTION_REPLAY_ROUTE, + "R/replay same route"), + CLUSTER_R4_CELL(CLUSTER_R4_STATE_RETRYABLE, CLUSTER_R4_STATE_INVALID, + CLUSTER_R4_ROUTE_OWNERS, CLUSTER_R4_ACTION_RETRY, "T/retry"), + CLUSTER_R4_CELL(CLUSTER_R4_STATE_RETRYABLE, CLUSTER_R4_STATE_INVALID, + CLUSTER_R4_ROUTE_OWNERS, CLUSTER_R4_ACTION_CLOSE_ATTEMPT, + "T/close attempt"), + CLUSTER_R4_CELL(CLUSTER_R4_STATE_CANCELLED, CLUSTER_R4_STATE_INVALID, + CLUSTER_R4_ROUTE_OWNERS, CLUSTER_R4_ACTION_CANCEL_ROUTE, + "K/cancel route"), + CLUSTER_R4_CELL(CLUSTER_R4_STATE_RETRYABLE, CLUSTER_R4_STATE_INVALID, + CLUSTER_R4_ROUTE_OWNERS, CLUSTER_R4_ACTION_RETRY, "T/retry"), + CLUSTER_R4_CELL(CLUSTER_R4_STATE_RETRYABLE, CLUSTER_R4_STATE_INVALID, + CLUSTER_R4_ROUTE_OWNERS, CLUSTER_R4_ACTION_STALE_ROUTE, + "T/stale route"), + CLUSTER_R4_CELL(CLUSTER_R4_STATE_RETRYABLE, CLUSTER_R4_STATE_INVALID, + CLUSTER_R4_ROUTE_OWNERS, CLUSTER_R4_ACTION_RETRY, "T/retry"), + CLUSTER_R4_CELL(CLUSTER_R4_STATE_FAIL_CLOSED, CLUSTER_R4_STATE_INVALID, + CLUSTER_R4_ROUTE_OWNERS, CLUSTER_R4_ACTION_FAIL_PROTOCOL, + "X/FC(protocol)"), + }, + { + CLUSTER_R4_CELL(CLUSTER_R4_STATE_BUILDING, CLUSTER_R4_STATE_INVALID, + CLUSTER_R4_FORWARD_OWNERS, CLUSTER_R4_ACTION_HOLDER_STABLE_COPY, + "B/holder stable copy"), + CLUSTER_R4_CELL(CLUSTER_R4_STATE_FORWARDED, CLUSTER_R4_STATE_INVALID, + CLUSTER_R4_FORWARD_OWNERS, CLUSTER_R4_ACTION_DROP_OR_REPLAY, + "F/drop or replay"), + CLUSTER_R4_CELL(CLUSTER_R4_STATE_RETRYABLE, CLUSTER_R4_STATE_INVALID, + CLUSTER_R4_FORWARD_OWNERS, CLUSTER_R4_ACTION_RETRY, "T/retry"), + CLUSTER_R4_CELL(CLUSTER_R4_STATE_RETRYABLE, CLUSTER_R4_STATE_INVALID, + CLUSTER_R4_FORWARD_OWNERS, CLUSTER_R4_ACTION_CLOSE_ATTEMPT, + "T/close attempt"), + CLUSTER_R4_CELL(CLUSTER_R4_STATE_CANCELLED, CLUSTER_R4_STATE_INVALID, + CLUSTER_R4_FORWARD_OWNERS, CLUSTER_R4_ACTION_CANCEL_SLOT, + "K/cancel slot"), + CLUSTER_R4_CELL(CLUSTER_R4_STATE_RETRYABLE, CLUSTER_R4_STATE_INVALID, + CLUSTER_R4_FORWARD_OWNERS, CLUSTER_R4_ACTION_RETRY, "T/retry"), + CLUSTER_R4_CELL(CLUSTER_R4_STATE_RETRYABLE, CLUSTER_R4_STATE_INVALID, + CLUSTER_R4_FORWARD_OWNERS, CLUSTER_R4_ACTION_STALE_SLOT, + "T/stale slot"), + CLUSTER_R4_CELL(CLUSTER_R4_STATE_RETRYABLE, CLUSTER_R4_STATE_INVALID, + CLUSTER_R4_FORWARD_OWNERS, CLUSTER_R4_ACTION_RETRY, "T/retry"), + CLUSTER_R4_CELL(CLUSTER_R4_STATE_FAIL_CLOSED, CLUSTER_R4_STATE_INVALID, + CLUSTER_R4_FORWARD_OWNERS, CLUSTER_R4_ACTION_FAIL_PROTOCOL, + "X/FC(protocol)"), + }, + { + CLUSTER_R4_CELL(CLUSTER_R4_STATE_WAIT_UNDO, CLUSTER_R4_STATE_REPLIED, + CLUSTER_R4_OWNER_HOLDER_LMS, + CLUSTER_R4_ACTION_REQUEST_UNDO_OR_PUBLISH, + "U/request foreign undo or P/publish result"), + CLUSTER_R4_CELL(CLUSTER_R4_STATE_BUILDING, CLUSTER_R4_STATE_INVALID, + CLUSTER_R4_OWNER_HOLDER_LMS, CLUSTER_R4_ACTION_DROP, "B/drop"), + CLUSTER_R4_CELL(CLUSTER_R4_STATE_RETRYABLE, CLUSTER_R4_STATE_INVALID, + CLUSTER_R4_OWNER_HOLDER_LMS, CLUSTER_R4_ACTION_RETRY, "T/retry"), + CLUSTER_R4_CELL(CLUSTER_R4_STATE_RETRYABLE, CLUSTER_R4_STATE_INVALID, + CLUSTER_R4_OWNER_HOLDER_LMS, CLUSTER_R4_ACTION_ABORT_SCRATCH, + "T/abort scratch"), + CLUSTER_R4_CELL(CLUSTER_R4_STATE_CANCELLED, CLUSTER_R4_STATE_INVALID, + CLUSTER_R4_OWNER_HOLDER_LMS, CLUSTER_R4_ACTION_ABORT_SCRATCH, + "K/abort scratch"), + CLUSTER_R4_CELL(CLUSTER_R4_STATE_RETRYABLE, CLUSTER_R4_STATE_INVALID, + CLUSTER_R4_OWNER_HOLDER_LMS, CLUSTER_R4_ACTION_RETRY, "T/retry"), + CLUSTER_R4_CELL(CLUSTER_R4_STATE_RETRYABLE, CLUSTER_R4_STATE_INVALID, + CLUSTER_R4_OWNER_HOLDER_LMS, CLUSTER_R4_ACTION_ABORT_SCRATCH, + "T/abort scratch"), + CLUSTER_R4_CELL(CLUSTER_R4_STATE_RETRYABLE, CLUSTER_R4_STATE_INVALID, + CLUSTER_R4_OWNER_HOLDER_LMS, CLUSTER_R4_ACTION_RETRY, "T/retry"), + CLUSTER_R4_CELL(CLUSTER_R4_STATE_FAIL_CLOSED, CLUSTER_R4_STATE_INVALID, + CLUSTER_R4_OWNER_HOLDER_LMS, CLUSTER_R4_ACTION_FAIL_DATA_PROTOCOL, + "X/FC(data/protocol)"), + }, + { + CLUSTER_R4_CELL(CLUSTER_R4_STATE_BUILDING, CLUSTER_R4_STATE_INVALID, + CLUSTER_R4_UNDO_OWNERS, CLUSTER_R4_ACTION_EXACT_UNDO_REPLY, + "B/exact undo reply"), + CLUSTER_R4_CELL(CLUSTER_R4_STATE_WAIT_UNDO, CLUSTER_R4_STATE_INVALID, + CLUSTER_R4_UNDO_OWNERS, CLUSTER_R4_ACTION_DROP, "U/drop"), + CLUSTER_R4_CELL(CLUSTER_R4_STATE_RETRYABLE, CLUSTER_R4_STATE_INVALID, + CLUSTER_R4_UNDO_OWNERS, CLUSTER_R4_ACTION_RETRY, "T/retry"), + CLUSTER_R4_CELL(CLUSTER_R4_STATE_RETRYABLE, CLUSTER_R4_STATE_INVALID, + CLUSTER_R4_UNDO_OWNERS, CLUSTER_R4_ACTION_ABORT_SCRATCH, + "T/abort scratch"), + CLUSTER_R4_CELL(CLUSTER_R4_STATE_CANCELLED, CLUSTER_R4_STATE_INVALID, + CLUSTER_R4_UNDO_OWNERS, CLUSTER_R4_ACTION_ABORT_SCRATCH, + "K/abort scratch"), + CLUSTER_R4_CELL(CLUSTER_R4_STATE_RETRYABLE, CLUSTER_R4_STATE_INVALID, + CLUSTER_R4_UNDO_OWNERS, CLUSTER_R4_ACTION_RETRY, "T/retry"), + CLUSTER_R4_CELL(CLUSTER_R4_STATE_RETRYABLE, CLUSTER_R4_STATE_INVALID, + CLUSTER_R4_UNDO_OWNERS, CLUSTER_R4_ACTION_ABORT_SCRATCH, + "T/abort scratch"), + CLUSTER_R4_CELL(CLUSTER_R4_STATE_RETRYABLE, CLUSTER_R4_STATE_INVALID, + CLUSTER_R4_UNDO_OWNERS, CLUSTER_R4_ACTION_RETRY, "T/retry"), + CLUSTER_R4_CELL(CLUSTER_R4_STATE_FAIL_CLOSED, CLUSTER_R4_STATE_INVALID, + CLUSTER_R4_UNDO_OWNERS, CLUSTER_R4_ACTION_FAIL_DATA_PROTOCOL, + "X/FC(data/protocol)"), + }, + { + CLUSTER_R4_CELL(CLUSTER_R4_STATE_CONSUMED, CLUSTER_R4_STATE_INVALID, + CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_CONSUMER_CAS, + "C/exact consumer CAS"), + CLUSTER_R4_CELL(CLUSTER_R4_STATE_REPLIED, CLUSTER_R4_STATE_INVALID, + CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_DROP, "P/drop"), + CLUSTER_R4_CELL(CLUSTER_R4_STATE_REPLIED, CLUSTER_R4_STATE_INVALID, + CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_DROP, "P/drop"), + CLUSTER_R4_CELL(CLUSTER_R4_STATE_REPLIED, CLUSTER_R4_STATE_INVALID, + CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_DROP, "P/drop"), + CLUSTER_R4_CELL(CLUSTER_R4_STATE_CANCELLED, CLUSTER_R4_STATE_INVALID, + CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_DROP_RESULT, + "K/drop result"), + CLUSTER_R4_CELL(CLUSTER_R4_STATE_REPLIED, CLUSTER_R4_STATE_INVALID, + CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_DROP, "P/drop"), + CLUSTER_R4_CELL(CLUSTER_R4_STATE_REPLIED, CLUSTER_R4_STATE_INVALID, + CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_DROP, "P/drop"), + CLUSTER_R4_CELL(CLUSTER_R4_STATE_REPLIED, CLUSTER_R4_STATE_INVALID, + CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_DROP, "P/drop"), + CLUSTER_R4_CELL(CLUSTER_R4_STATE_REPLIED, CLUSTER_R4_STATE_INVALID, + CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_DROP, "P/drop"), + }, + { + CLUSTER_R4_CELL(CLUSTER_R4_STATE_CONSUMED, CLUSTER_R4_STATE_INVALID, + CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_DROP, "C/drop"), + CLUSTER_R4_CELL(CLUSTER_R4_STATE_CONSUMED, CLUSTER_R4_STATE_INVALID, + CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_DROP, "C/drop"), + CLUSTER_R4_CELL(CLUSTER_R4_STATE_CONSUMED, CLUSTER_R4_STATE_INVALID, + CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_DROP, "C/drop"), + CLUSTER_R4_CELL(CLUSTER_R4_STATE_CONSUMED, CLUSTER_R4_STATE_INVALID, + CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_DROP, "C/drop"), + CLUSTER_R4_CELL(CLUSTER_R4_STATE_CONSUMED, CLUSTER_R4_STATE_INVALID, + CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_DROP, "C/drop"), + CLUSTER_R4_CELL(CLUSTER_R4_STATE_CONSUMED, CLUSTER_R4_STATE_INVALID, + CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_DROP, "C/drop"), + CLUSTER_R4_CELL(CLUSTER_R4_STATE_CONSUMED, CLUSTER_R4_STATE_INVALID, + CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_DROP, "C/drop"), + CLUSTER_R4_CELL(CLUSTER_R4_STATE_CONSUMED, CLUSTER_R4_STATE_INVALID, + CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_DROP, "C/drop"), + CLUSTER_R4_CELL(CLUSTER_R4_STATE_CONSUMED, CLUSTER_R4_STATE_INVALID, + CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_DROP, "C/drop"), + }, + { + CLUSTER_R4_CELL(CLUSTER_R4_STATE_ROUTING, CLUSTER_R4_STATE_INVALID, + CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_NEW_REQUEST, + "R/new request id after typed close"), + CLUSTER_R4_CELL(CLUSTER_R4_STATE_RETRYABLE, CLUSTER_R4_STATE_INVALID, + CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_DROP, "T/drop"), + CLUSTER_R4_CELL(CLUSTER_R4_STATE_RETRYABLE, CLUSTER_R4_STATE_INVALID, + CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_DROP, "T/drop"), + CLUSTER_R4_CELL(CLUSTER_R4_STATE_FAIL_CLOSED, CLUSTER_R4_STATE_INVALID, + CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_OVERALL_DEADLINE, + "X/overall deadline"), + CLUSTER_R4_CELL(CLUSTER_R4_STATE_CANCELLED, CLUSTER_R4_STATE_INVALID, + CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_CLEANUP, + "K/cleanup"), + CLUSTER_R4_CELL(CLUSTER_R4_STATE_RETRYABLE, CLUSTER_R4_STATE_INVALID, + CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_WAIT_TOPOLOGY, + "T/wait topology"), + CLUSTER_R4_CELL(CLUSTER_R4_STATE_RETRYABLE, CLUSTER_R4_STATE_INVALID, + CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_WAIT_ADMISSION, + "T/wait admission"), + CLUSTER_R4_CELL(CLUSTER_R4_STATE_RETRYABLE, CLUSTER_R4_STATE_INVALID, + CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_BACKOFF, + "T/backoff"), + CLUSTER_R4_CELL(CLUSTER_R4_STATE_FAIL_CLOSED, CLUSTER_R4_STATE_INVALID, + CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_FAIL_PROTOCOL, + "X/FC(protocol)"), + }, + { + CLUSTER_R4_CELL(CLUSTER_R4_STATE_FAIL_CLOSED, CLUSTER_R4_STATE_INVALID, + CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_DROP, "X/drop"), + CLUSTER_R4_CELL(CLUSTER_R4_STATE_FAIL_CLOSED, CLUSTER_R4_STATE_INVALID, + CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_DROP, "X/drop"), + CLUSTER_R4_CELL(CLUSTER_R4_STATE_FAIL_CLOSED, CLUSTER_R4_STATE_INVALID, + CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_DROP, "X/drop"), + CLUSTER_R4_CELL(CLUSTER_R4_STATE_FAIL_CLOSED, CLUSTER_R4_STATE_INVALID, + CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_DROP, "X/drop"), + CLUSTER_R4_CELL(CLUSTER_R4_STATE_FAIL_CLOSED, CLUSTER_R4_STATE_INVALID, + CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_CLEANUP, + "X/cleanup"), + CLUSTER_R4_CELL(CLUSTER_R4_STATE_FAIL_CLOSED, CLUSTER_R4_STATE_INVALID, + CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_DROP, "X/drop"), + CLUSTER_R4_CELL(CLUSTER_R4_STATE_FAIL_CLOSED, CLUSTER_R4_STATE_INVALID, + CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_DROP, "X/drop"), + CLUSTER_R4_CELL(CLUSTER_R4_STATE_FAIL_CLOSED, CLUSTER_R4_STATE_INVALID, + CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_DROP, "X/drop"), + CLUSTER_R4_CELL(CLUSTER_R4_STATE_FAIL_CLOSED, CLUSTER_R4_STATE_INVALID, + CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_DROP, "X/drop"), + }, + { + CLUSTER_R4_CELL(CLUSTER_R4_STATE_CANCELLED, CLUSTER_R4_STATE_INVALID, + CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_DROP, "K/drop"), + CLUSTER_R4_CELL(CLUSTER_R4_STATE_CANCELLED, CLUSTER_R4_STATE_INVALID, + CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_DROP, "K/drop"), + CLUSTER_R4_CELL(CLUSTER_R4_STATE_CANCELLED, CLUSTER_R4_STATE_INVALID, + CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_DROP, "K/drop"), + CLUSTER_R4_CELL(CLUSTER_R4_STATE_CANCELLED, CLUSTER_R4_STATE_INVALID, + CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_DROP, "K/drop"), + CLUSTER_R4_CELL(CLUSTER_R4_STATE_CANCELLED, CLUSTER_R4_STATE_INVALID, + CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_DROP, "K/drop"), + CLUSTER_R4_CELL(CLUSTER_R4_STATE_CANCELLED, CLUSTER_R4_STATE_INVALID, + CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_DROP, "K/drop"), + CLUSTER_R4_CELL(CLUSTER_R4_STATE_CANCELLED, CLUSTER_R4_STATE_INVALID, + CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_DROP, "K/drop"), + CLUSTER_R4_CELL(CLUSTER_R4_STATE_CANCELLED, CLUSTER_R4_STATE_INVALID, + CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_DROP, "K/drop"), + CLUSTER_R4_CELL(CLUSTER_R4_STATE_CANCELLED, CLUSTER_R4_STATE_INVALID, + CLUSTER_R4_OWNER_REQUESTER, CLUSTER_R4_ACTION_DROP, "K/drop"), + }, + }; if (state < CLUSTER_R4_STATE_EMPTY || state >= CLUSTER_R4_STATE_COUNT || event < CLUSTER_R4_EVENT_VALID || event >= CLUSTER_R4_EVENT_COUNT) @@ -2410,8 +2335,7 @@ StaticAssertDecl(sizeof(ClusterR4ForwardKindUnion) == 24, "R4 forward kind union must remain 24 bytes"); StaticAssertDecl(sizeof(ClusterR4ForwardExtension) == 32, "R4 forward extension must remain 32 bytes"); -StaticAssertDecl(offsetof(ClusterR4ForwardExtension, - kind.cr.master_resource_transition_count_le) +StaticAssertDecl(offsetof(ClusterR4ForwardExtension, kind.cr.master_resource_transition_count_le) == 12, "R4 FORWARD96 transition count must occupy absolute bytes 76..83"); @@ -2431,74 +2355,69 @@ StaticAssertDecl(sizeof(ClusterR4CrForwardPayload) == 96, "R4 CR forward payload must remain 96 bytes"); struct ClusterICEnvelope; -extern ClusterCrBuildResult cluster_gcs_block_r4_route_cr( - const struct ClusterICEnvelope *env, const ClusterR4CrRequestPayload *request, - ClusterCrBuildReason *reason_out); +extern ClusterCrBuildResult cluster_gcs_block_r4_route_cr(const struct ClusterICEnvelope *env, + const ClusterR4CrRequestPayload *request, + ClusterCrBuildReason *reason_out); /* LMON close census: live requester slots in the exact R4_CR domain. */ extern uint64 cluster_gcs_block_r4_requester_count(void); extern ClusterTxOutcome cluster_gcs_block_r4_tx_resolve_fetch_and_wait( - int32 origin_node, const ClusterTxLocator *locator, - uint32 expected_physical_generation, uint64 formation_epoch, - ClusterTxResolution *out, ClusterTxResolveReason *reason_out); + int32 origin_node, const ClusterTxLocator *locator, uint32 expected_physical_generation, + uint64 formation_epoch, ClusterTxResolution *out, ClusterTxResolveReason *reason_out); extern void cluster_gcs_block_r4_tx_resolve_drain(void); extern bool cluster_gcs_block_r4_tx_resolve_active(void); /* Process-local diagnostic snapshot; never supplies authority or advances work. */ extern int cluster_gcs_block_r4_tx_resolve_pending_detail(char *out, Size capacity); #define CLUSTER_GCS_BLOCK_R4_TX_ORIGIN_PENDING_WAIT_MS 1 static inline long -cluster_gcs_block_r4_tx_resolve_wait_timeout_for_count(long idle_timeout_ms, - int active_contexts) +cluster_gcs_block_r4_tx_resolve_wait_timeout_for_count(long idle_timeout_ms, int active_contexts) { if (idle_timeout_ms <= 0 || active_contexts <= 0) return idle_timeout_ms; return idle_timeout_ms < CLUSTER_GCS_BLOCK_R4_TX_ORIGIN_PENDING_WAIT_MS - ? idle_timeout_ms - : CLUSTER_GCS_BLOCK_R4_TX_ORIGIN_PENDING_WAIT_MS; + ? idle_timeout_ms + : CLUSTER_GCS_BLOCK_R4_TX_ORIGIN_PENDING_WAIT_MS; } extern long cluster_gcs_block_r4_tx_resolve_wait_timeout(long idle_timeout_ms); #ifdef USE_CLUSTER_UNIT extern bool cluster_gcs_block_test_r4_request80(const struct ClusterICEnvelope *env, - const void *payload); + const void *payload); extern bool cluster_gcs_block_test_r4_forward96(const struct ClusterICEnvelope *env, - const void *payload); + const void *payload); extern int cluster_gcs_block_test_r4_tx_origin_context_count(void); extern void cluster_gcs_block_test_r4_tx_origin_drain(void); -extern bool cluster_gcs_block_test_current_mx_forward128( - const struct ClusterICEnvelope *env, const void *payload); +extern bool cluster_gcs_block_test_current_mx_forward128(const struct ClusterICEnvelope *env, + const void *payload); extern bool cluster_gcs_block_test_r4_refusal_status(ClusterCrBuildResult result, - ClusterCrBuildReason reason, - bool admitted_forward, - GcsBlockReplyStatus *status_out); + ClusterCrBuildReason reason, + bool admitted_forward, + GcsBlockReplyStatus *status_out); extern bool cluster_gcs_block_test_decode_r4_reply( const struct ClusterICEnvelope *env, const void *payload, uint64 expected_request_id, uint64 expected_epoch, int32 expected_requester_backend_id, uint8 expected_transition_id, - int32 expected_sender_node, int32 expected_forwarding_master_node, - uint8 expected_reply_domain); -extern bool cluster_gcs_block_test_arm_r4_reply_slot(uint64 request_id, - uint64 request_epoch, - int32 requester_backend_id, - uint8 transition_id, - int32 expected_master_node); -extern bool cluster_gcs_block_test_arm_legacy_reply_slot(uint64 request_id, - uint64 request_epoch, + int32 expected_sender_node, int32 expected_forwarding_master_node, uint8 expected_reply_domain); +extern bool cluster_gcs_block_test_arm_r4_reply_slot(uint64 request_id, uint64 request_epoch, int32 requester_backend_id, uint8 transition_id, int32 expected_master_node); -extern bool cluster_gcs_block_test_snapshot_r4_reply_slot( - GcsBlockReplyHeader *header_out, char block_out[GCS_BLOCK_DATA_SIZE], - bool *reply_received_out, uint64 *stale_drop_count_out); -extern bool cluster_gcs_block_test_r4_requester_arm( - BufferTag tag, uint64 request_epoch, int32 expected_master_node, - uint64 next_sequence, uint64 *request_id_out); +extern bool cluster_gcs_block_test_arm_legacy_reply_slot(uint64 request_id, uint64 request_epoch, + int32 requester_backend_id, + uint8 transition_id, + int32 expected_master_node); +extern bool cluster_gcs_block_test_snapshot_r4_reply_slot(GcsBlockReplyHeader *header_out, + char block_out[GCS_BLOCK_DATA_SIZE], + bool *reply_received_out, + uint64 *stale_drop_count_out); +extern bool cluster_gcs_block_test_r4_requester_arm(BufferTag tag, uint64 request_epoch, + int32 expected_master_node, + uint64 next_sequence, uint64 *request_id_out); extern bool cluster_gcs_block_test_snapshot_r4_requester_slot( - bool *in_use_out, uint8 *reply_domain_out, uint64 *request_id_out, - uint8 *transition_id_out, BufferTag *tag_out, uint64 *request_epoch_out, - int32 *expected_master_node_out, ClusterGcsBlockDirectState *direct_state_out, - bool *direct_target_prepared_out); + bool *in_use_out, uint8 *reply_domain_out, uint64 *request_id_out, uint8 *transition_id_out, + BufferTag *tag_out, uint64 *request_epoch_out, int32 *expected_master_node_out, + ClusterGcsBlockDirectState *direct_state_out, bool *direct_target_prepared_out); extern bool cluster_gcs_block_test_release_r4_requester_slot(void); -extern bool cluster_gcs_block_test_r4_fetch_and_wait( - BufferTag tag, SCN read_scn, int32 real_master_node, - char dst_page[GCS_BLOCK_DATA_SIZE]); +extern bool cluster_gcs_block_test_r4_fetch_and_wait(BufferTag tag, SCN read_scn, + int32 real_master_node, + char dst_page[GCS_BLOCK_DATA_SIZE]); #endif static inline void @@ -2594,8 +2513,7 @@ ClusterR4RequestExtensionGetCr(const ClusterR4RequestExtension *extension, SCN * static inline void ClusterR4ForwardExtensionSetCrProof(ClusterR4ForwardExtension *extension, uint64 master_authority_generation, - uint64 master_resource_transition_count, - SCN expected_page_scn) + uint64 master_resource_transition_count, SCN expected_page_scn) { if (extension == NULL) return; @@ -2606,14 +2524,12 @@ ClusterR4ForwardExtensionSetCrProof(ClusterR4ForwardExtension *extension, master_authority_generation); ClusterR4WireWriteU64(extension->kind.cr.master_resource_transition_count_le, master_resource_transition_count); - ClusterR4WireWriteU64(extension->kind.cr.expected_page_scn_le, - (uint64)expected_page_scn); + ClusterR4WireWriteU64(extension->kind.cr.expected_page_scn_le, (uint64)expected_page_scn); } static inline bool ClusterR4ForwardExtensionGetCrProof(const ClusterR4ForwardExtension *extension, - uint64 formation_epoch, - uint64 *master_authority_generation_out, + uint64 formation_epoch, uint64 *master_authority_generation_out, uint64 *master_resource_transition_count_out, SCN *expected_page_scn_out) { @@ -2636,32 +2552,27 @@ ClusterR4ForwardExtensionGetCrProof(const ClusterR4ForwardExtension *extension, || memcmp(extension->subject_id_le, zero_subject, sizeof(zero_subject)) != 0) return false; - master_generation - = ClusterR4WireReadU64(extension->kind.cr.master_authority_generation_le); - transition_count - = ClusterR4WireReadU64(extension->kind.cr.master_resource_transition_count_le); + master_generation = ClusterR4WireReadU64(extension->kind.cr.master_authority_generation_le); + transition_count = ClusterR4WireReadU64(extension->kind.cr.master_resource_transition_count_le); if ((uint32)master_generation == 0 - || (uint32)(master_generation >> 32) != (uint32)formation_epoch - || transition_count == 0 || transition_count == UINT64_MAX) + || (uint32)(master_generation >> 32) != (uint32)formation_epoch || transition_count == 0 + || transition_count == UINT64_MAX) return false; *master_authority_generation_out = master_generation; *master_resource_transition_count_out = transition_count; - *expected_page_scn_out - = (SCN)ClusterR4WireReadU64(extension->kind.cr.expected_page_scn_le); + *expected_page_scn_out = (SCN)ClusterR4WireReadU64(extension->kind.cr.expected_page_scn_le); return true; } static inline bool -ClusterR4ForwardExtensionSetLocator(ClusterR4ForwardExtension *extension, - ClusterR4WireKind kind, +ClusterR4ForwardExtensionSetLocator(ClusterR4ForwardExtension *extension, ClusterR4WireKind kind, const ClusterTxLocator *locator) { if (extension != NULL) memset(extension, 0, sizeof(*extension)); if (extension == NULL || locator == NULL - || (kind != CLUSTER_R4_WIRE_TX_RESOLVE - && kind != CLUSTER_R4_WIRE_UNDO_DATA_FETCH)) + || (kind != CLUSTER_R4_WIRE_TX_RESOLVE && kind != CLUSTER_R4_WIRE_UNDO_DATA_FETCH)) return false; extension->r4_version = CLUSTER_R4_WIRE_VERSION; @@ -2680,9 +2591,9 @@ ClusterR4ForwardExtensionSetLocator(ClusterR4ForwardExtension *extension, * guard; it is never a positive DATA generation. Zero is a known first one. */ static inline bool ClusterR4ForwardExtensionSetLocatorGeneration(ClusterR4ForwardExtension *extension, - ClusterR4WireKind kind, - const ClusterTxLocator *locator, - uint32 physical_generation) + ClusterR4WireKind kind, + const ClusterTxLocator *locator, + uint32 physical_generation) { if (extension != NULL) memset(extension, 0, sizeof(*extension)); @@ -2695,8 +2606,7 @@ ClusterR4ForwardExtensionSetLocatorGeneration(ClusterR4ForwardExtension *extensi static inline bool ClusterR4ForwardExtensionGetLocator(const ClusterR4ForwardExtension *extension, - ClusterR4WireKind expected_kind, - ClusterTxLocator *locator_out) + ClusterR4WireKind expected_kind, ClusterTxLocator *locator_out) { static const uint8 zero_flags[2] = { 0, 0 }; static const uint8 zero_subject[4] = { 0, 0, 0, 0 }; @@ -2726,9 +2636,9 @@ ClusterR4ForwardExtensionGetLocator(const ClusterR4ForwardExtension *extension, static inline bool ClusterR4ForwardExtensionGetLocatorGeneration(const ClusterR4ForwardExtension *extension, - ClusterR4WireKind expected_kind, - ClusterTxLocator *locator_out, - uint32 *physical_generation_out) + ClusterR4WireKind expected_kind, + ClusterTxLocator *locator_out, + uint32 *physical_generation_out) { uint32 generation; ClusterR4ForwardExtension copy; @@ -2799,8 +2709,8 @@ ClusterR4TxVerdictPageDecode(const uint8 page[BLCKSZ], const ClusterTxLocator *e if (page == NULL || expected_locator == NULL || resolution_out == NULL || ClusterR4WireReadU32(&page[0]) != CLUSTER_R4_TX_VERDICT_MAGIC || ClusterR4WireReadU16(&page[4]) != CLUSTER_R4_TX_VERDICT_VERSION - || ClusterR4WireReadU16(&page[6]) != CLUSTER_R4_TX_VERDICT_HEADER_LEN - || page[10] != 0 || page[11] != 0 + || ClusterR4WireReadU16(&page[6]) != CLUSTER_R4_TX_VERDICT_HEADER_LEN || page[10] != 0 + || page[11] != 0 || memcmp(&page[CLUSTER_R4_TX_VERDICT_HEADER_LEN], zero_tail, sizeof(zero_tail)) != 0) return false; @@ -2816,8 +2726,7 @@ ClusterR4TxVerdictPageDecode(const uint8 page[BLCKSZ], const ClusterTxLocator *e decoded.locator_echo.tt_wrap = ClusterR4WireReadU16(&page[32]); decoded.locator_echo.itl_kind = page[34]; decoded.locator_echo.itl_slot_index = page[35]; - if (!cluster_tx_locator_reply_matches(expected_locator, - &decoded.locator_echo)) + if (!cluster_tx_locator_reply_matches(expected_locator, &decoded.locator_echo)) return false; decoded.top_xid = (TransactionId)ClusterR4WireReadU32(&page[36]); @@ -3221,8 +3130,7 @@ GcsBlockForwardPayloadIsUndoVerdictRequest(const GcsBlockForwardPayload *p) static inline bool GcsBlockForwardPayloadIsUndoVerdictAuthoritative(const GcsBlockForwardPayload *p) { - return p->reserved_0[6] == (uint8)5 - || GcsBlockForwardPayloadIsUndoFreshRefC1bPairRequest(p); + return p->reserved_0[6] == (uint8)5 || GcsBlockForwardPayloadIsUndoFreshRefC1bPairRequest(p); } /* PGRAC: spec-5.22d D4-6 — reserved_0[6] VALUE 4 = dead-owner AUTHORITY @@ -3364,8 +3272,7 @@ GcsBlockUndoAuthorityFetchTagDecodeOwner(BufferTag tag, int32 *owner_node) * there while dbOid and blockNum retain the exact segment and 1-based TT slot. * The discriminator is validated separately before this decoder is called. */ static inline BufferTag -GcsBlockUndoFreshRefC1bTagMake(uint32 segment_id, TransactionId xid, - uint32 expected_tt_slot_id) +GcsBlockUndoFreshRefC1bTagMake(uint32 segment_id, TransactionId xid, uint32 expected_tt_slot_id) { BufferTag tag = GcsBlockUndoFetchTagMake(segment_id, expected_tt_slot_id); @@ -3374,8 +3281,8 @@ GcsBlockUndoFreshRefC1bTagMake(uint32 segment_id, TransactionId xid, } static inline bool -GcsBlockUndoFreshRefC1bTagDecode(BufferTag tag, uint32 *segment_id, - TransactionId *xid, uint32 *expected_tt_slot_id) +GcsBlockUndoFreshRefC1bTagDecode(BufferTag tag, uint32 *segment_id, TransactionId *xid, + uint32 *expected_tt_slot_id) { TransactionId decoded_xid = (TransactionId)tag.relNumber; @@ -3612,7 +3519,7 @@ typedef enum GcsXheldReadShipDecision { static inline GcsXheldReadShipDecision gcs_block_xheld_read_ship_decision(uint8 transition_id, int pre_state, int32 holder_node, - int32 requester_node, int32 master_node, bool master_resident) + int32 requester_node, int32 master_node, bool master_resident) { /* Only plain cross-node reads (N→S) on an X-held block are in scope. */ if (transition_id != (uint8)PCM_TRANS_N_TO_S || pre_state != (int)PCM_LOCK_MODE_X) @@ -3644,22 +3551,19 @@ gcs_block_xheld_read_ship_decision(uint8 transition_id, int pre_state, int32 hol * widened into an X->S downgrade or S registration. */ static inline bool gcs_block_xheld_read_barrier_bypass_exact(const PcmAuthoritySnapshot *before, - const PcmAuthoritySnapshot *after, - int32 requester_node) + const PcmAuthoritySnapshot *after, int32 requester_node) { int32 holder_node; if (before == NULL || after == NULL || requester_node < 0 || requester_node >= RESOURCE_X_PROTOCOL_NODE_LIMIT - || memcmp(before, after, sizeof(*before)) != 0 - || before->reserved[0] != 0 || before->reserved[1] != 0 - || before->state != PCM_STATE_X || before->transition_count == 0 + || memcmp(before, after, sizeof(*before)) != 0 || before->reserved[0] != 0 + || before->reserved[1] != 0 || before->state != PCM_STATE_X || before->transition_count == 0 || before->transition_count == UINT64_MAX || before->s_holders_bitmap != 0) return false; holder_node = before->x_holder_node; return holder_node >= 0 && holder_node < RESOURCE_X_PROTOCOL_NODE_LIMIT - && holder_node != requester_node - && before->master_holder.node_id == (uint32)holder_node; + && holder_node != requester_node && before->master_holder.node_id == (uint32)holder_node; } typedef enum GcsBlockSBarrierReadAction { @@ -3669,8 +3573,8 @@ typedef enum GcsBlockSBarrierReadAction { } GcsBlockSBarrierReadAction; static inline GcsBlockSBarrierReadAction -gcs_block_s_barrier_read_action_exact(bool queue_before, bool queue_after, - bool resource_x_before, bool resource_x_after, +gcs_block_s_barrier_read_action_exact(bool queue_before, bool queue_after, bool resource_x_before, + bool resource_x_after, const PcmAuthoritySnapshot *authority_before, bool authority_before_valid, const PcmAuthoritySnapshot *authority_after, @@ -3681,10 +3585,10 @@ gcs_block_s_barrier_read_action_exact(bool queue_before, bool queue_after, if (queue_before || queue_after || (!resource_x_before && !resource_x_after) || !authority_before_valid || !authority_after_valid) return GCS_BLOCK_S_BARRIER_DENY; - return gcs_block_xheld_read_barrier_bypass_exact( - authority_before, authority_after, requester_node) - ? GCS_BLOCK_S_BARRIER_IMAGE_ONLY - : GCS_BLOCK_S_BARRIER_DENY; + return gcs_block_xheld_read_barrier_bypass_exact(authority_before, authority_after, + requester_node) + ? GCS_BLOCK_S_BARRIER_IMAGE_ONLY + : GCS_BLOCK_S_BARRIER_DENY; } /* A FORWARDED_IN_FLIGHT dedup record caches routing, never authority. Reuse @@ -3694,9 +3598,8 @@ gcs_block_s_barrier_read_action_exact(bool queue_before, bool queue_after, * a committed Resource-X handoff invalidates it through the holder fields. * No PI bitmap participates in this decision. */ static inline bool -gcs_block_forward_replay_authority_exact(GcsBlockReplyStatus cached_status, - uint8 transition_id, int32 cached_holder_node, - int32 requester_node, +gcs_block_forward_replay_authority_exact(GcsBlockReplyStatus cached_status, uint8 transition_id, + int32 cached_holder_node, int32 requester_node, const PcmAuthoritySnapshot *authority) { uint32 holder_bit; @@ -3710,25 +3613,19 @@ gcs_block_forward_replay_authority_exact(GcsBlockReplyStatus cached_status, switch (cached_status) { case GCS_BLOCK_REPLY_READ_IMAGE_FROM_XHOLDER: - return transition_id == (uint8)PCM_TRANS_N_TO_S - && authority->state == PCM_STATE_X - && authority->x_holder_node == cached_holder_node - && authority->s_holders_bitmap == 0 + return transition_id == (uint8)PCM_TRANS_N_TO_S && authority->state == PCM_STATE_X + && authority->x_holder_node == cached_holder_node && authority->s_holders_bitmap == 0 && authority->master_holder.node_id == (uint32)cached_holder_node - && authority->pending_x_requester_node == -1 - && authority->pending_x_since_lsn == 0; + && authority->pending_x_requester_node == -1 && authority->pending_x_since_lsn == 0; case GCS_BLOCK_REPLY_GRANTED_FROM_HOLDER: - return transition_id == (uint8)PCM_TRANS_N_TO_S - && authority->state == PCM_STATE_S && authority->x_holder_node == -1 - && (authority->s_holders_bitmap & holder_bit) != 0 + return transition_id == (uint8)PCM_TRANS_N_TO_S && authority->state == PCM_STATE_S + && authority->x_holder_node == -1 && (authority->s_holders_bitmap & holder_bit) != 0 && authority->master_holder.node_id == (uint32)cached_holder_node - && authority->pending_x_requester_node == -1 - && authority->pending_x_since_lsn == 0; + && authority->pending_x_requester_node == -1 && authority->pending_x_since_lsn == 0; case GCS_BLOCK_REPLY_X_GRANTED_FROM_HOLDER: return (transition_id == (uint8)PCM_TRANS_N_TO_X || transition_id == (uint8)PCM_TRANS_S_TO_X_UPGRADE) - && authority->state == PCM_STATE_X - && authority->x_holder_node == cached_holder_node + && authority->state == PCM_STATE_X && authority->x_holder_node == cached_holder_node && authority->s_holders_bitmap == 0 && authority->master_holder.node_id == (uint32)cached_holder_node && authority->pending_x_requester_node == requester_node @@ -3744,8 +3641,7 @@ gcs_block_forward_replay_authority_exact(GcsBlockReplyStatus cached_status, * immediately following cleanup response is retryable. No direct refusal * can start a retry round by itself. */ static inline bool -gcs_block_holder_refusal_retry_exact(int32 forwarding_master, - bool *awaiting_master_cleanup, +gcs_block_holder_refusal_retry_exact(int32 forwarding_master, bool *awaiting_master_cleanup, int retry_attempt, int max_retries) { if (awaiting_master_cleanup == NULL || retry_attempt >= max_retries) { @@ -3770,13 +3666,12 @@ gcs_block_holder_refusal_retry_exact(int32 forwarding_master, * a fresh request identity. Direct master denials and writer transitions do * not qualify. */ static inline bool -gcs_block_forwarded_s_refusal_requires_fresh_retry( - GcsBlockReplyStatus status, uint8 transition_id, - int32 forwarding_master) +gcs_block_forwarded_s_refusal_requires_fresh_retry(GcsBlockReplyStatus status, uint8 transition_id, + int32 forwarding_master) { return status == GCS_BLOCK_REPLY_DENIED_MASTER_NOT_HOLDER - && transition_id == (uint8)PCM_TRANS_N_TO_S - && forwarding_master >= 0 && forwarding_master < 32; + && transition_id == (uint8)PCM_TRANS_N_TO_S && forwarding_master >= 0 + && forwarding_master < 32; } /* PGRAC: spec-5.2a D3 — pure master-side decision for an eligible clean-page @@ -3877,11 +3772,11 @@ GcsBlockMasterDirectCopyRefusalStatus(ClusterBufmgrGcsCopyRefusal refusal) extern const char *cluster_bufmgr_gcs_copy_refusal_name(ClusterBufmgrGcsCopyRefusal refusal); extern bool cluster_bufmgr_copy_block_for_gcs(BufferTag tag, XLogRecPtr *out_page_lsn, char *dst, - ClusterBufmgrGcsCopyRefusal *out_refusal); + ClusterBufmgrGcsCopyRefusal *out_refusal); extern bool cluster_bufmgr_copy_block_for_r4_cr(BufferTag tag, SCN expected_page_scn, - XLogRecPtr *page_lsn_out, SCN *page_scn_out, - char *dst, - ClusterBufmgrGcsCopyRefusal *refusal_out); + XLogRecPtr *page_lsn_out, SCN *page_scn_out, + char *dst, + ClusterBufmgrGcsCopyRefusal *refusal_out); extern bool cluster_bufmgr_borrow_block_for_gcs_live_sge(BufferTag tag, XLogRecPtr *out_page_lsn, void **out_page_addr, BufferDesc **out_buf); @@ -3948,11 +3843,9 @@ typedef enum ClusterItlStampSkipReason { * for the exact expected tag while recovery merge is inactive. Returns the * captured generation, acquisition epoch and PCM state; creates no authority * or lifecycle state. */ -extern bool cluster_bufmgr_terminal_stamp_authority(Buffer buffer, - const BufferTag *expected_tag, - uint64 *own_generation, - uint64 *acquisition_epoch, - uint8 *pcm_state); +extern bool cluster_bufmgr_terminal_stamp_authority(Buffer buffer, const BufferTag *expected_tag, + uint64 *own_generation, + uint64 *acquisition_epoch, uint8 *pcm_state); /* PGRAC: spec-8.3 — no-fetch exact-proof acquire for the commit-time ITL * stamp. Replaces the residency-only semantic: under mapping authority, @@ -4189,9 +4082,9 @@ extern bool cluster_gcs_send_block_request_and_wait(BufferDesc *buf, * bufmgr aborts/rearms GRANT_PENDING and selects a fresh holder identity. */ extern bool cluster_gcs_local_master_read_image_and_wait(BufferDesc *buf, - const PcmAuthoritySnapshot *expected, - bool force_one_shot, - bool *out_retry_denied); + const PcmAuthoritySnapshot *expected, + bool force_one_shot, + bool *out_retry_denied); /* * R10/A' PGRAC adaptation: a master-local legacy N->S acquisition bypasses * the data-plane dedup table, so consult the existing exact PCM-X active-head @@ -4437,9 +4330,9 @@ extern uint64 cluster_gcs_get_block_dedup_done_marked_count(void); /* RC-F DON extern uint64 cluster_gcs_get_block_dedup_done_mismatch_count(void); /* RC-F DONE */ extern uint64 cluster_gcs_get_block_dedup_hint_violation_count(void); /* review F5 */ extern uint64 cluster_gcs_get_block_dedup_legacy_pin_count(void); /* review F5 */ -extern uint64 cluster_gcs_get_fallback_scn_verify_pass_count(void); /* round-4c FUNC-1 */ -extern uint64 cluster_gcs_get_fallback_scn_refresh_count(void); /* round-4c FUNC-1 */ -extern uint64 cluster_gcs_get_fallback_scn_failclosed_count(void); /* round-4c FUNC-1 */ +extern uint64 cluster_gcs_get_fallback_scn_verify_pass_count(void); /* round-4c FUNC-1 */ +extern uint64 cluster_gcs_get_fallback_scn_refresh_count(void); /* round-4c FUNC-1 */ +extern uint64 cluster_gcs_get_fallback_scn_failclosed_count(void); /* round-4c FUNC-1 */ /* * PGRAC: spec-2.35 D12 — 7 NEW reliability/lifecycle counter accessors @@ -4587,7 +4480,7 @@ typedef struct ResourceXWriterUseContext { } ResourceXWriterUseContext; StaticAssertDecl(sizeof(ResourceXWriterUseContext) == 72, - "ResourceXWriterUseContext layout must remain 72 bytes"); + "ResourceXWriterUseContext layout must remain 72 bytes"); /* Process-local TARGET cached-X eviction plan. It is never serialized or * stored in shared memory: PREPARE freezes the exact existing kind-4 bytes @@ -4632,16 +4525,14 @@ extern const char *cluster_gcs_resource_x_take_acquire_failure_reason(int buffer ResourceXApplyResult result, uint64 *attempt_out); -extern ResourceXApplyResult cluster_gcs_resource_x_target_acquire_exact( - BufferDesc *buf, uint64 r4_record_generation, - ResourceXAcquisitionRef *ref_out); +extern ResourceXApplyResult +cluster_gcs_resource_x_target_acquire_exact(BufferDesc *buf, uint64 r4_record_generation, + ResourceXAcquisitionRef *ref_out); /* Stack-only retry variant for the bufmgr pre-use handoff. A zero input * freezes the ordinary R7 absolute deadline; subsequent calls must present * the same nonzero value and can never refresh it. */ -extern ResourceXApplyResult -cluster_gcs_resource_x_target_acquire_until_exact( - BufferDesc *buf, const BufferTag *expected_resource, - uint64 r4_record_generation, +extern ResourceXApplyResult cluster_gcs_resource_x_target_acquire_until_exact( + BufferDesc *buf, const BufferTag *expected_resource, uint64 r4_record_generation, uint64 *absolute_deadline_us_io, ResourceXAcquisitionRef *ref_out); /* Only a deliberate, unpinned VM/FSM handoff owner may opt into this entry. @@ -4650,17 +4541,14 @@ cluster_gcs_resource_x_target_acquire_until_exact( extern ResourceXApplyResult cluster_gcs_resource_x_target_acquire_reobserve_exact( BufferDesc *buf, const BufferTag *expected_resource, uint64 r4_record_generation, ResourceXAuxiliaryAcquireContext *context, ResourceXAcquisitionRef *ref_out); -extern ResourceXApplyResult -cluster_gcs_resource_x_target_evict_prepare_exact( - const BufferTag *tag, const ClusterPcmOwnSnapshot *exact_x, - uint64 r4_record_generation, uint64 reservation_token, - ResourceXTargetEvictionPlan *plan_out); +extern ResourceXApplyResult cluster_gcs_resource_x_target_evict_prepare_exact( + const BufferTag *tag, const ClusterPcmOwnSnapshot *exact_x, uint64 r4_record_generation, + uint64 reservation_token, ResourceXTargetEvictionPlan *plan_out); extern ResourceXApplyResult cluster_gcs_resource_x_target_evict_publish_exact(ResourceXTargetEvictionPlan *plan, bool *retry_pending_out); extern ResourceXApplyResult -cluster_gcs_resource_x_target_evict_abort_exact( - ResourceXTargetEvictionPlan *plan); +cluster_gcs_resource_x_target_evict_abort_exact(ResourceXTargetEvictionPlan *plan); /* Optional process-local disposition, not authority: only NOT_FOUND plus * creation_reobserve_out=true proves a consumed auxiliary creation may be * relooked up by its original unpinned caller. Bare NOT_FOUND is an error. */ @@ -4668,31 +4556,25 @@ extern ResourceXApplyResult cluster_gcs_resource_x_target_direct_init_acquire_ex BufferDesc *buf, const BufferTag *expected_resource, uint64 r4_record_generation, uint64 direct_init_ownership_generation, uint64 direct_init_reservation_token, bool *creation_reobserve_out, ResourceXAcquisitionRef *ref_out); -extern ResourceXApplyResult -cluster_gcs_resource_x_target_direct_init_join_exact( - BufferDesc *buf, const BufferTag *expected_resource, - uint64 direct_init_ownership_generation, - uint64 direct_init_reservation_token, - ResourceXAcquisitionRef *ref_out); -extern bool cluster_gcs_resource_x_target_context_recheck_exact( - const ResourceXWriterUseContext *context); +extern ResourceXApplyResult cluster_gcs_resource_x_target_direct_init_join_exact( + BufferDesc *buf, const BufferTag *expected_resource, uint64 direct_init_ownership_generation, + uint64 direct_init_reservation_token, ResourceXAcquisitionRef *ref_out); +extern bool +cluster_gcs_resource_x_target_context_recheck_exact(const ResourceXWriterUseContext *context); /* Local proof check only: BAD_STATE means recognized unavailable observation, * never permission. Callers must revalidate their physical proof after wait. */ extern ResourceXApplyResult cluster_gcs_resource_x_target_context_recheck_result_exact( const ResourceXWriterUseContext *context); extern ResourceXApplyResult -cluster_gcs_resource_x_target_itl_recycle_begin_exact( - const ResourceXWriterUseContext *context, - const ClusterPcmOwnSnapshot *observed, - ResourceXLocalOwnerHandle *handle_out); +cluster_gcs_resource_x_target_itl_recycle_begin_exact(const ResourceXWriterUseContext *context, + const ClusterPcmOwnSnapshot *observed, + ResourceXLocalOwnerHandle *handle_out); extern ResourceXApplyResult -cluster_gcs_resource_x_target_itl_recycle_finish_exact( - const ResourceXWriterUseContext *context, - const ClusterPcmOwnSnapshot *observed, - const ResourceXLocalOwnerHandle *handle); +cluster_gcs_resource_x_target_itl_recycle_finish_exact(const ResourceXWriterUseContext *context, + const ClusterPcmOwnSnapshot *observed, + const ResourceXLocalOwnerHandle *handle); extern ResourceXApplyResult -cluster_gcs_resource_x_target_itl_recycle_cancel_exact( - const ResourceXLocalOwnerHandle *handle); +cluster_gcs_resource_x_target_itl_recycle_cancel_exact(const ResourceXLocalOwnerHandle *handle); /* ============================================================ * spec-2.34 D4 — eager wake on epoch advance. * @@ -4707,11 +4589,9 @@ cluster_gcs_resource_x_target_itl_recycle_cancel_exact( * reply timeout safety net. * ============================================================ */ extern void cluster_gcs_block_on_epoch_advance(uint64 new_epoch); -extern void cluster_gcs_block_on_epoch_advance_exact( - uint64 new_epoch, const uint8 *dead_bitmap); +extern void cluster_gcs_block_on_epoch_advance_exact(uint64 new_epoch, const uint8 *dead_bitmap); extern bool cluster_gcs_block_resource_x_cutover_tick(void); -extern bool cluster_gcs_ctrc_dispatch_close( - const ClusterCtrcCloseDispatch *dispatch); +extern bool cluster_gcs_ctrc_dispatch_close(const ClusterCtrcCloseDispatch *dispatch); extern void cluster_gcs_ctrc_dispatch_batch(const ClusterCtrcCloseDispatch *dispatches, Size count); diff --git a/src/include/cluster/cluster_gcs_block_dedup.h b/src/include/cluster/cluster_gcs_block_dedup.h index f9448e76a78..4c87582fa02 100644 --- a/src/include/cluster/cluster_gcs_block_dedup.h +++ b/src/include/cluster/cluster_gcs_block_dedup.h @@ -191,8 +191,7 @@ typedef enum GcsBlockR4RouteSendResult { StaticAssertDecl(sizeof(GcsBlockR4RouteIdentity) == 64, "R4 CR route identity must remain 64 bytes"); -StaticAssertDecl(sizeof(GcsBlockR4RouteRecord) == 128, - "R4 CR route record must remain 128 bytes"); +StaticAssertDecl(sizeof(GcsBlockR4RouteRecord) == 128, "R4 CR route record must remain 128 bytes"); typedef union GcsBlockDedupPayloadMeta { ClusterSfDepVec sf_dep_vec; diff --git a/src/include/cluster/cluster_ges_reply_wait.h b/src/include/cluster/cluster_ges_reply_wait.h index 66bf1c3b546..374dbb1e044 100644 --- a/src/include/cluster/cluster_ges_reply_wait.h +++ b/src/include/cluster/cluster_ges_reply_wait.h @@ -205,17 +205,16 @@ extern GesReplyDeliverResult cluster_ges_reply_wait_deliver(const GesReplyWaitKe * * No HTAB entry pointer escapes this API and it never waits on a CV. */ -extern GesReplyWaitPollResult -cluster_ges_reply_wait_poll_consume(const GesReplyWaitKey *key, - GesReplyWaitVerdict *verdict_out); +extern GesReplyWaitPollResult cluster_ges_reply_wait_poll_consume(const GesReplyWaitKey *key, + GesReplyWaitVerdict *verdict_out); /* * Arm and perform one bounded sleep on the exact live reply entry without * consuming or changing its verdict. Returns false when the key has no live * waitable entry, so cooperative callers can retain their polling fallback. */ -extern bool cluster_ges_reply_wait_sleep_exact(const GesReplyWaitKey *key, - long timeout_ms, uint32 wait_event); +extern bool cluster_ges_reply_wait_sleep_exact(const GesReplyWaitKey *key, long timeout_ms, + uint32 wait_event); /* * spec-5.16 — abandon a wait entry at the bounded GES timeout instead of deleting diff --git a/src/include/cluster/cluster_grd.h b/src/include/cluster/cluster_grd.h index 98d73029bcc..1e46397d079 100644 --- a/src/include/cluster/cluster_grd.h +++ b/src/include/cluster/cluster_grd.h @@ -182,7 +182,7 @@ typedef struct ClusterGrdShared { /* spec-4.6 D1/D4 — per-shard recovery phase (ClusterGrdShardPhase). */ pg_atomic_uint32 shard_phase[PGRAC_GRD_SHARD_COUNT]; - pg_atomic_uint32 master_map_initialized; /* 0 until LMON init */ + pg_atomic_uint32 master_map_initialized; /* 0 until LMON init */ /* Scheme A recovery-authority barrier. The existing REDECLARE_DONE * epoch/hash wire converges holder truth across the exact formation. * A1 keeps every blocking step in LMON: Postmaster publishes the request @@ -559,22 +559,22 @@ extern uint32 cluster_grd_shard_lookup(const ClusterResId *resid); */ extern int32 cluster_grd_shard_master(uint32 shard_id); extern bool cluster_grd_is_local_master(uint32 shard_id); -extern bool cluster_grd_recovery_authority_barrier_wait( - const ClusterFormationSnapshotV1 *formation, uint64 boot_incarnation, - uint64 lms_generation, int timeout_ms); +extern bool cluster_grd_recovery_authority_barrier_wait(const ClusterFormationSnapshotV1 *formation, + uint64 boot_incarnation, + uint64 lms_generation, int timeout_ms); extern void cluster_grd_recovery_authority_lmon_tick(void); -extern bool cluster_grd_recovery_authority_is_current( - uint64 boot_incarnation, uint64 lms_generation); -extern bool cluster_grd_serving_authority_rebind_lmon( - const ClusterFormationSnapshotV1 *formation, uint64 boot_incarnation, - uint64 lms_generation); +extern bool cluster_grd_recovery_authority_is_current(uint64 boot_incarnation, + uint64 lms_generation); +extern bool cluster_grd_serving_authority_rebind_lmon(const ClusterFormationSnapshotV1 *formation, + uint64 boot_incarnation, + uint64 lms_generation); /* RF-ROOT P6 (L5 shutdown handoff): the committed LEAVER's serving rebind — * no episode gates (the departed node never arms one for its own departure; * its drain was cooperative and complete), re-stamped from its own applied * CLEAN_LEAVE evidence. */ -extern bool cluster_grd_serving_authority_rebind_leaver( - const ClusterFormationSnapshotV1 *formation, uint64 boot_incarnation, - uint64 lms_generation); +extern bool cluster_grd_serving_authority_rebind_leaver(const ClusterFormationSnapshotV1 *formation, + uint64 boot_incarnation, + uint64 lms_generation); /* * spec-4.6 D2 — failure-driven remaster (NOT affinity/DRM, NOT @@ -1126,8 +1126,7 @@ extern ClusterGrdEntryResult cluster_grd_revalidate_and_promote(const ClusterRes * mirror. Only the exact reservation identity is consumed; sibling * reservations are neither authority nor a reason to reject the grant. */ extern ClusterGrdEntryResult -cluster_grd_promote_remote_grant_exact(const ClusterResId *resid, - const ClusterGrdHolderId *holder); +cluster_grd_promote_remote_grant_exact(const ClusterResId *resid, const ClusterGrdHolderId *holder); extern ClusterGrdEntryResult cluster_grd_promote_remote_grant_mode_exact(const ClusterResId *resid, const ClusterGrdHolderId *holder, LOCKMODE mode); @@ -1136,12 +1135,11 @@ extern ClusterGrdEntryResult cluster_grd_confirm_local_grant_exact(const Cluster LOCKMODE mode); extern ClusterGrdEntryResult cluster_grd_release_holder_by_id(const ClusterResId *resid, - const ClusterGrdHolderId *holder); + const ClusterGrdHolderId *holder); /* Lookup an exact full-identity holder without creating an entry. Used by * recovery-mode release gates to prove the allowlisted mode before mutation. */ extern bool cluster_grd_holder_mode_by_id(const ClusterResId *resid, - const ClusterGrdHolderId *holder, - LOCKMODE *out_mode); + const ClusterGrdHolderId *holder, LOCKMODE *out_mode); extern ClusterGrdEntryResult cluster_grd_cancel_reservation_by_id(const ClusterResId *resid, const ClusterGrdHolderId *holder); @@ -1455,8 +1453,9 @@ extern ClusterGrdConvertResult cluster_grd_entry_request_convert(ClusterGrdEntry /* RF-ROOT P6 S05-3H -- return a conflicting UPGRADE immediately without * inserting it into converts[]. */ -extern ClusterGrdConvertResult cluster_grd_entry_request_convert_nowait( - ClusterGrdEntry *entry, const ClusterGrdConvert *req, bool *out_drain_hint); +extern ClusterGrdConvertResult +cluster_grd_entry_request_convert_nowait(ClusterGrdEntry *entry, const ClusterGrdConvert *req, + bool *out_drain_hint); /* * D5 — convert-priority drain (caller holds entry->lock). Grants every @@ -1532,10 +1531,11 @@ extern ClusterGrdConvertResult cluster_grd_convert_or_enqueue_meta( ClusterGrdConflictHolder *conflict_holders_out, int *n_conflict_out); /* RF-ROOT P6 S05-3H -- master-side non-enqueuing same-holder conversion. */ -extern ClusterGrdConvertResult cluster_grd_convert_nowait( - const ClusterResId *resid, int32 node_id, uint32 procno, uint64 cluster_epoch, - LOCKMODE current_mode, LOCKMODE requested_mode, uint64 convert_request_id, - uint64 old_request_id, int32 source_node_id, uint64 shard_master_generation); +extern ClusterGrdConvertResult +cluster_grd_convert_nowait(const ClusterResId *resid, int32 node_id, uint32 procno, + uint64 cluster_epoch, LOCKMODE current_mode, LOCKMODE requested_mode, + uint64 convert_request_id, uint64 old_request_id, int32 source_node_id, + uint64 shard_master_generation); /* * spec-5.3 §3.5 native-probe clear path: commit a convert located by the diff --git a/src/include/cluster/cluster_guc.h b/src/include/cluster/cluster_guc.h index 99a48c9228a..6aeb9196aa8 100644 --- a/src/include/cluster/cluster_guc.h +++ b/src/include/cluster/cluster_guc.h @@ -253,11 +253,9 @@ extern char *cluster_injection_points; #ifdef ENABLE_INJECTION extern char *cluster_pcm_x_retain_flush_error_target; -extern bool cluster_pcm_x_retain_flush_error_target_matches(uint32 spc_oid, - uint32 db_oid, - uint32 rel_number, - int fork_number, - uint32 block_number); +extern bool cluster_pcm_x_retain_flush_error_target_matches(uint32 spc_oid, uint32 db_oid, + uint32 rel_number, int fork_number, + uint32 block_number); #endif diff --git a/src/include/cluster/cluster_ic.h b/src/include/cluster/cluster_ic.h index 5b3a8652985..3e31677396d 100644 --- a/src/include/cluster/cluster_ic.h +++ b/src/include/cluster/cluster_ic.h @@ -413,65 +413,58 @@ typedef enum ClusterICPlane { * iff no separately named single-bit allocation collides. Keep the two * intentionally reserved holes (0x00004000 and 0x00040000) outside the mask. */ #define PGRAC_IC_HELLO_CAP_DEFINED_COUNT 21 -#define PGRAC_IC_HELLO_CAP_DEFINED_MASK \ - (PGRAC_IC_HELLO_CAP_SMART_FUSION_REPLY_V2 \ - | PGRAC_IC_HELLO_CAP_UNDO_AUTHORITY_SERVE_V1 \ - | PGRAC_IC_HELLO_CAP_UNDO_HORIZON_V1 | PGRAC_IC_HELLO_CAP_CAPS_REPLY_V1 \ - | PGRAC_IC_HELLO_CAP_GCS_DONE_V1 | PGRAC_IC_HELLO_CAP_XID_NATIVE_DISABLE_V1 \ - | PGRAC_IC_HELLO_CAP_XID_AUTHORITY_FLOCK_V2 | PGRAC_IC_HELLO_CAP_GCS_INVAL_BUSY_V1 \ - | PGRAC_IC_HELLO_CAP_UNDO_HORIZON_IDLE_V1 | PGRAC_IC_HELLO_CAP_PCM_X_CONVERT_V1 \ - | PGRAC_IC_HELLO_CAP_PCM_X_REBASE_V1 | PGRAC_IC_HELLO_CAP_PCM_X_SOURCE_FLOOR_V1 \ - | PGRAC_IC_HELLO_CAP_SEMANTIC_ACTIVATION_V1 | PGRAC_IC_HELLO_CAP_R4_SYNC_CR_V1 \ - | PGRAC_IC_HELLO_CAP_SEMANTIC_ACTIVATION_ACK_V1 \ - | PGRAC_IC_HELLO_CAP_MULTIXACT_CURRENT_V1 \ - | PGRAC_IC_HELLO_CAP_GCS_RESOURCE_X_CONVERT_V1 \ - | PGRAC_IC_HELLO_CAP_CONTROL_ROOT_V1 \ - | PGRAC_IC_HELLO_CAP_CANDIDATE2_CORRECTED_A1_V1 \ - | PGRAC_IC_HELLO_CAP_UNDO_ROOT_DESCRIPTOR_V1 \ +#define PGRAC_IC_HELLO_CAP_DEFINED_MASK \ + (PGRAC_IC_HELLO_CAP_SMART_FUSION_REPLY_V2 | PGRAC_IC_HELLO_CAP_UNDO_AUTHORITY_SERVE_V1 \ + | PGRAC_IC_HELLO_CAP_UNDO_HORIZON_V1 | PGRAC_IC_HELLO_CAP_CAPS_REPLY_V1 \ + | PGRAC_IC_HELLO_CAP_GCS_DONE_V1 | PGRAC_IC_HELLO_CAP_XID_NATIVE_DISABLE_V1 \ + | PGRAC_IC_HELLO_CAP_XID_AUTHORITY_FLOCK_V2 | PGRAC_IC_HELLO_CAP_GCS_INVAL_BUSY_V1 \ + | PGRAC_IC_HELLO_CAP_UNDO_HORIZON_IDLE_V1 | PGRAC_IC_HELLO_CAP_PCM_X_CONVERT_V1 \ + | PGRAC_IC_HELLO_CAP_PCM_X_REBASE_V1 | PGRAC_IC_HELLO_CAP_PCM_X_SOURCE_FLOOR_V1 \ + | PGRAC_IC_HELLO_CAP_SEMANTIC_ACTIVATION_V1 | PGRAC_IC_HELLO_CAP_R4_SYNC_CR_V1 \ + | PGRAC_IC_HELLO_CAP_SEMANTIC_ACTIVATION_ACK_V1 | PGRAC_IC_HELLO_CAP_MULTIXACT_CURRENT_V1 \ + | PGRAC_IC_HELLO_CAP_GCS_RESOURCE_X_CONVERT_V1 | PGRAC_IC_HELLO_CAP_CONTROL_ROOT_V1 \ + | PGRAC_IC_HELLO_CAP_CANDIDATE2_CORRECTED_A1_V1 | PGRAC_IC_HELLO_CAP_UNDO_ROOT_DESCRIPTOR_V1 \ | PGRAC_IC_HELLO_CAP_MULTIXACT_CTRC_V1) -#define PGRAC_IC_HELLO_CAP_DEFINED_SUM \ - (PGRAC_IC_HELLO_CAP_SMART_FUSION_REPLY_V2 \ - + PGRAC_IC_HELLO_CAP_UNDO_AUTHORITY_SERVE_V1 \ - + PGRAC_IC_HELLO_CAP_UNDO_HORIZON_V1 + PGRAC_IC_HELLO_CAP_CAPS_REPLY_V1 \ - + PGRAC_IC_HELLO_CAP_GCS_DONE_V1 + PGRAC_IC_HELLO_CAP_XID_NATIVE_DISABLE_V1 \ - + PGRAC_IC_HELLO_CAP_XID_AUTHORITY_FLOCK_V2 + PGRAC_IC_HELLO_CAP_GCS_INVAL_BUSY_V1 \ - + PGRAC_IC_HELLO_CAP_UNDO_HORIZON_IDLE_V1 + PGRAC_IC_HELLO_CAP_PCM_X_CONVERT_V1 \ - + PGRAC_IC_HELLO_CAP_PCM_X_REBASE_V1 + PGRAC_IC_HELLO_CAP_PCM_X_SOURCE_FLOOR_V1 \ - + PGRAC_IC_HELLO_CAP_SEMANTIC_ACTIVATION_V1 + PGRAC_IC_HELLO_CAP_R4_SYNC_CR_V1 \ - + PGRAC_IC_HELLO_CAP_SEMANTIC_ACTIVATION_ACK_V1 \ - + PGRAC_IC_HELLO_CAP_MULTIXACT_CURRENT_V1 \ - + PGRAC_IC_HELLO_CAP_GCS_RESOURCE_X_CONVERT_V1 \ - + PGRAC_IC_HELLO_CAP_CONTROL_ROOT_V1 \ - + PGRAC_IC_HELLO_CAP_CANDIDATE2_CORRECTED_A1_V1 \ - + PGRAC_IC_HELLO_CAP_UNDO_ROOT_DESCRIPTOR_V1 \ +#define PGRAC_IC_HELLO_CAP_DEFINED_SUM \ + (PGRAC_IC_HELLO_CAP_SMART_FUSION_REPLY_V2 + PGRAC_IC_HELLO_CAP_UNDO_AUTHORITY_SERVE_V1 \ + + PGRAC_IC_HELLO_CAP_UNDO_HORIZON_V1 + PGRAC_IC_HELLO_CAP_CAPS_REPLY_V1 \ + + PGRAC_IC_HELLO_CAP_GCS_DONE_V1 + PGRAC_IC_HELLO_CAP_XID_NATIVE_DISABLE_V1 \ + + PGRAC_IC_HELLO_CAP_XID_AUTHORITY_FLOCK_V2 + PGRAC_IC_HELLO_CAP_GCS_INVAL_BUSY_V1 \ + + PGRAC_IC_HELLO_CAP_UNDO_HORIZON_IDLE_V1 + PGRAC_IC_HELLO_CAP_PCM_X_CONVERT_V1 \ + + PGRAC_IC_HELLO_CAP_PCM_X_REBASE_V1 + PGRAC_IC_HELLO_CAP_PCM_X_SOURCE_FLOOR_V1 \ + + PGRAC_IC_HELLO_CAP_SEMANTIC_ACTIVATION_V1 + PGRAC_IC_HELLO_CAP_R4_SYNC_CR_V1 \ + + PGRAC_IC_HELLO_CAP_SEMANTIC_ACTIVATION_ACK_V1 + PGRAC_IC_HELLO_CAP_MULTIXACT_CURRENT_V1 \ + + PGRAC_IC_HELLO_CAP_GCS_RESOURCE_X_CONVERT_V1 + PGRAC_IC_HELLO_CAP_CONTROL_ROOT_V1 \ + + PGRAC_IC_HELLO_CAP_CANDIDATE2_CORRECTED_A1_V1 + PGRAC_IC_HELLO_CAP_UNDO_ROOT_DESCRIPTOR_V1 \ + PGRAC_IC_HELLO_CAP_MULTIXACT_CTRC_V1) #define PGRAC_IC_HELLO_CAP_IS_SINGLE_BIT(cap) ((cap) != 0 && (((cap) & ((cap) - 1)) == 0)) StaticAssertDecl(PGRAC_IC_HELLO_CAP_DEFINED_SUM == PGRAC_IC_HELLO_CAP_DEFINED_MASK, "PGRAC HELLO capability allocations collide"); StaticAssertDecl((PGRAC_IC_HELLO_CAP_DEFINED_MASK & UINT32_C(0x00044000)) == 0, "PGRAC HELLO reserved capability holes were allocated"); -StaticAssertDecl(PGRAC_IC_HELLO_CAP_IS_SINGLE_BIT(PGRAC_IC_HELLO_CAP_SMART_FUSION_REPLY_V2) - && PGRAC_IC_HELLO_CAP_IS_SINGLE_BIT(PGRAC_IC_HELLO_CAP_UNDO_AUTHORITY_SERVE_V1) - && PGRAC_IC_HELLO_CAP_IS_SINGLE_BIT(PGRAC_IC_HELLO_CAP_UNDO_HORIZON_V1) - && PGRAC_IC_HELLO_CAP_IS_SINGLE_BIT(PGRAC_IC_HELLO_CAP_CAPS_REPLY_V1) - && PGRAC_IC_HELLO_CAP_IS_SINGLE_BIT(PGRAC_IC_HELLO_CAP_GCS_DONE_V1) - && PGRAC_IC_HELLO_CAP_IS_SINGLE_BIT(PGRAC_IC_HELLO_CAP_XID_NATIVE_DISABLE_V1) - && PGRAC_IC_HELLO_CAP_IS_SINGLE_BIT(PGRAC_IC_HELLO_CAP_XID_AUTHORITY_FLOCK_V2) - && PGRAC_IC_HELLO_CAP_IS_SINGLE_BIT(PGRAC_IC_HELLO_CAP_GCS_INVAL_BUSY_V1) - && PGRAC_IC_HELLO_CAP_IS_SINGLE_BIT(PGRAC_IC_HELLO_CAP_UNDO_HORIZON_IDLE_V1) - && PGRAC_IC_HELLO_CAP_IS_SINGLE_BIT(PGRAC_IC_HELLO_CAP_PCM_X_CONVERT_V1) - && PGRAC_IC_HELLO_CAP_IS_SINGLE_BIT(PGRAC_IC_HELLO_CAP_PCM_X_REBASE_V1) - && PGRAC_IC_HELLO_CAP_IS_SINGLE_BIT(PGRAC_IC_HELLO_CAP_PCM_X_SOURCE_FLOOR_V1) - && PGRAC_IC_HELLO_CAP_IS_SINGLE_BIT(PGRAC_IC_HELLO_CAP_SEMANTIC_ACTIVATION_V1) - && PGRAC_IC_HELLO_CAP_IS_SINGLE_BIT(PGRAC_IC_HELLO_CAP_R4_SYNC_CR_V1) - && PGRAC_IC_HELLO_CAP_IS_SINGLE_BIT(PGRAC_IC_HELLO_CAP_SEMANTIC_ACTIVATION_ACK_V1) - && PGRAC_IC_HELLO_CAP_IS_SINGLE_BIT(PGRAC_IC_HELLO_CAP_MULTIXACT_CURRENT_V1) - && PGRAC_IC_HELLO_CAP_IS_SINGLE_BIT(PGRAC_IC_HELLO_CAP_GCS_RESOURCE_X_CONVERT_V1) - && PGRAC_IC_HELLO_CAP_IS_SINGLE_BIT(PGRAC_IC_HELLO_CAP_CONTROL_ROOT_V1) - && PGRAC_IC_HELLO_CAP_IS_SINGLE_BIT(PGRAC_IC_HELLO_CAP_CANDIDATE2_CORRECTED_A1_V1) - && PGRAC_IC_HELLO_CAP_IS_SINGLE_BIT(PGRAC_IC_HELLO_CAP_UNDO_ROOT_DESCRIPTOR_V1) - && PGRAC_IC_HELLO_CAP_IS_SINGLE_BIT(PGRAC_IC_HELLO_CAP_MULTIXACT_CTRC_V1), - "PGRAC HELLO capabilities must each allocate one bit"); +StaticAssertDecl( + PGRAC_IC_HELLO_CAP_IS_SINGLE_BIT(PGRAC_IC_HELLO_CAP_SMART_FUSION_REPLY_V2) + && PGRAC_IC_HELLO_CAP_IS_SINGLE_BIT(PGRAC_IC_HELLO_CAP_UNDO_AUTHORITY_SERVE_V1) + && PGRAC_IC_HELLO_CAP_IS_SINGLE_BIT(PGRAC_IC_HELLO_CAP_UNDO_HORIZON_V1) + && PGRAC_IC_HELLO_CAP_IS_SINGLE_BIT(PGRAC_IC_HELLO_CAP_CAPS_REPLY_V1) + && PGRAC_IC_HELLO_CAP_IS_SINGLE_BIT(PGRAC_IC_HELLO_CAP_GCS_DONE_V1) + && PGRAC_IC_HELLO_CAP_IS_SINGLE_BIT(PGRAC_IC_HELLO_CAP_XID_NATIVE_DISABLE_V1) + && PGRAC_IC_HELLO_CAP_IS_SINGLE_BIT(PGRAC_IC_HELLO_CAP_XID_AUTHORITY_FLOCK_V2) + && PGRAC_IC_HELLO_CAP_IS_SINGLE_BIT(PGRAC_IC_HELLO_CAP_GCS_INVAL_BUSY_V1) + && PGRAC_IC_HELLO_CAP_IS_SINGLE_BIT(PGRAC_IC_HELLO_CAP_UNDO_HORIZON_IDLE_V1) + && PGRAC_IC_HELLO_CAP_IS_SINGLE_BIT(PGRAC_IC_HELLO_CAP_PCM_X_CONVERT_V1) + && PGRAC_IC_HELLO_CAP_IS_SINGLE_BIT(PGRAC_IC_HELLO_CAP_PCM_X_REBASE_V1) + && PGRAC_IC_HELLO_CAP_IS_SINGLE_BIT(PGRAC_IC_HELLO_CAP_PCM_X_SOURCE_FLOOR_V1) + && PGRAC_IC_HELLO_CAP_IS_SINGLE_BIT(PGRAC_IC_HELLO_CAP_SEMANTIC_ACTIVATION_V1) + && PGRAC_IC_HELLO_CAP_IS_SINGLE_BIT(PGRAC_IC_HELLO_CAP_R4_SYNC_CR_V1) + && PGRAC_IC_HELLO_CAP_IS_SINGLE_BIT(PGRAC_IC_HELLO_CAP_SEMANTIC_ACTIVATION_ACK_V1) + && PGRAC_IC_HELLO_CAP_IS_SINGLE_BIT(PGRAC_IC_HELLO_CAP_MULTIXACT_CURRENT_V1) + && PGRAC_IC_HELLO_CAP_IS_SINGLE_BIT(PGRAC_IC_HELLO_CAP_GCS_RESOURCE_X_CONVERT_V1) + && PGRAC_IC_HELLO_CAP_IS_SINGLE_BIT(PGRAC_IC_HELLO_CAP_CONTROL_ROOT_V1) + && PGRAC_IC_HELLO_CAP_IS_SINGLE_BIT(PGRAC_IC_HELLO_CAP_CANDIDATE2_CORRECTED_A1_V1) + && PGRAC_IC_HELLO_CAP_IS_SINGLE_BIT(PGRAC_IC_HELLO_CAP_UNDO_ROOT_DESCRIPTOR_V1) + && PGRAC_IC_HELLO_CAP_IS_SINGLE_BIT(PGRAC_IC_HELLO_CAP_MULTIXACT_CTRC_V1), + "PGRAC HELLO capabilities must each allocate one bit"); #undef PGRAC_IC_HELLO_CAP_IS_SINGLE_BIT /* * PGRAC: spec-7.2 D2 — plane + connection-epoch ride the documented-zero diff --git a/src/include/cluster/cluster_ir.h b/src/include/cluster/cluster_ir.h index ef6a32a2c91..32d03837e86 100644 --- a/src/include/cluster/cluster_ir.h +++ b/src/include/cluster/cluster_ir.h @@ -35,11 +35,11 @@ #define CLUSTER_IR_H #include "cluster/cluster_control_root.h" /* ClusterRecoveryDutyKey */ -#include "cluster/cluster_grd.h" /* ClusterResId */ -#include "cluster/cluster_hw.h" /* CLUSTER_HW_RESID_TYPE (collision check) */ -#include "cluster/cluster_dl.h" /* CLUSTER_DL_RESID_TYPE (collision check) */ -#include "cluster/cluster_xlog.h" /* CLUSTER_WAL_THREAD_MAX */ -#include "storage/lock.h" /* LOCKTAG_LAST_TYPE */ +#include "cluster/cluster_grd.h" /* ClusterResId */ +#include "cluster/cluster_hw.h" /* CLUSTER_HW_RESID_TYPE (collision check) */ +#include "cluster/cluster_dl.h" /* CLUSTER_DL_RESID_TYPE (collision check) */ +#include "cluster/cluster_xlog.h" /* CLUSTER_WAL_THREAD_MAX */ +#include "storage/lock.h" /* LOCKTAG_LAST_TYPE */ /* * CLUSTER_IR_RESID_TYPE -- IR resource-id namespace marker. Above every PG @@ -60,8 +60,8 @@ StaticAssertDecl(CLUSTER_IR_RESID_TYPE != CLUSTER_DL_RESID_TYPE, /* RF-ROOT P3 / STOP03 §17.2: compact IR(X) key derived only from a valid * full recovery-duty identity. Invalid input preserves *out. */ -extern bool cluster_recovery_serial_resid_encode( - const ClusterRecoveryDutyKey *duty, ClusterResId *out); +extern bool cluster_recovery_serial_resid_encode(const ClusterRecoveryDutyKey *duty, + ClusterResId *out); #ifndef FRONTEND @@ -69,8 +69,7 @@ extern bool cluster_recovery_serial_resid_encode( typedef struct ClusterFormationWitnessV1 ClusterFormationWitnessV1; typedef struct PgracExternalFenceNeedSetV1 PgracExternalFenceNeedSetV1; -typedef struct PgracExternalFenceAdmissionSetV1 - PgracExternalFenceAdmissionSetV1; +typedef struct PgracExternalFenceAdmissionSetV1 PgracExternalFenceAdmissionSetV1; typedef enum ClusterRecoverySerialMode { CLUSTER_RECOVERY_SERIAL_ONLINE = 1, @@ -138,19 +137,19 @@ typedef struct ClusterRecoverySerialGuardSet { ClusterRecoverySerialGuard guards[CLUSTER_RECOVERY_SERIAL_SET_MAX]; } ClusterRecoverySerialGuardSet; -extern ClusterRecoverySerialAcquireResult cluster_recovery_serial_acquire( - const ClusterRecoverySerialRequest *request, - ClusterRecoverySerialGuard *guard); -extern ClusterRecoverySerialRevalidateResult cluster_recovery_serial_revalidate( - ClusterRecoverySerialGuard *guard); -extern ClusterRecoverySerialReleaseResult cluster_recovery_serial_release( - ClusterRecoverySerialGuard *guard); -extern ClusterRecoverySerialAcquireResult cluster_recovery_serial_acquire_set( - const ClusterRecoverySerialRequest *requests, uint16 count, - int overall_acquire_timeout_ms, ClusterRecoverySerialGuardSet *set, - uint16 *failed_index); -extern ClusterRecoverySerialReleaseResult cluster_recovery_serial_release_set( - ClusterRecoverySerialGuardSet *set); +extern ClusterRecoverySerialAcquireResult +cluster_recovery_serial_acquire(const ClusterRecoverySerialRequest *request, + ClusterRecoverySerialGuard *guard); +extern ClusterRecoverySerialRevalidateResult +cluster_recovery_serial_revalidate(ClusterRecoverySerialGuard *guard); +extern ClusterRecoverySerialReleaseResult +cluster_recovery_serial_release(ClusterRecoverySerialGuard *guard); +extern ClusterRecoverySerialAcquireResult +cluster_recovery_serial_acquire_set(const ClusterRecoverySerialRequest *requests, uint16 count, + int overall_acquire_timeout_ms, + ClusterRecoverySerialGuardSet *set, uint16 *failed_index); +extern ClusterRecoverySerialReleaseResult +cluster_recovery_serial_release_set(ClusterRecoverySerialGuardSet *set); /* Minimal shmem region for the ten STOP03 §10.3 volatile counters. */ extern Size cluster_ir_shmem_size(void); diff --git a/src/include/cluster/cluster_itl_touch.h b/src/include/cluster/cluster_itl_touch.h index 37e808a8e44..9aaded662e5 100644 --- a/src/include/cluster/cluster_itl_touch.h +++ b/src/include/cluster/cluster_itl_touch.h @@ -61,8 +61,8 @@ #include "storage/itemptr.h" /* OffsetNumber */ #include "storage/relfilelocator.h" #include "cluster/cluster_buffer_desc.h" /* PCM_STATE_N / PCM_STATE_X */ -#include "cluster/cluster_itl_slot.h" /* CLUSTER_ITL_INITRANS_DEFAULT (spec-3.4c D14) */ -#include "cluster/cluster_scn.h" /* SCN */ +#include "cluster/cluster_itl_slot.h" /* CLUSTER_ITL_INITRANS_DEFAULT (spec-3.4c D14) */ +#include "cluster/cluster_scn.h" /* SCN */ #include "cluster/cluster_terminal_ref_census.h" /* @@ -140,13 +140,12 @@ typedef struct ClusterItlTerminalProof { */ static inline bool cluster_itl_terminal_stamp_authority_admissible(bool storage_mode, int local_node_id, - int node_count, bool recovery_merge_active, - uint8 pcm_state, uint32 own_flags, - uint64 writer_activation_token) + int node_count, bool recovery_merge_active, + uint8 pcm_state, uint32 own_flags, + uint64 writer_activation_token) { - if (!storage_mode || node_count <= 0 || local_node_id < 0 - || local_node_id >= node_count || recovery_merge_active || own_flags != 0 - || writer_activation_token != 0) + if (!storage_mode || node_count <= 0 || local_node_id < 0 || local_node_id >= node_count + || recovery_merge_active || own_flags != 0 || writer_activation_token != 0) return false; if (node_count == 1) @@ -156,29 +155,26 @@ cluster_itl_terminal_stamp_authority_admissible(bool storage_mode, int local_nod /* Exact local-owner and slot checks used by terminal hinting. */ static inline bool -cluster_itl_terminal_proof_owner_exact(const ClusterItlTerminalProof *proof, - uint64 own_generation, uint64 acquisition_epoch, - uint8 pcm_state, bool authority_admissible, - uint32 own_flags, +cluster_itl_terminal_proof_owner_exact(const ClusterItlTerminalProof *proof, uint64 own_generation, + uint64 acquisition_epoch, uint8 pcm_state, + bool authority_admissible, uint32 own_flags, uint64 writer_activation_token) { - return proof != NULL && proof->valid && authority_admissible - && pcm_state == proof->pcm_state && own_flags == 0 - && writer_activation_token == 0 && own_generation == proof->own_generation - && acquisition_epoch == proof->acquisition_epoch; + return proof != NULL && proof->valid && authority_admissible && pcm_state == proof->pcm_state + && own_flags == 0 && writer_activation_token == 0 + && own_generation == proof->own_generation + && acquisition_epoch == proof->acquisition_epoch; } static inline bool -cluster_itl_terminal_proof_slot_exact(const ClusterItlTerminalProof *proof, - TransactionId xid, uint16 slot_wrap, - uint8 slot_class, +cluster_itl_terminal_proof_slot_exact(const ClusterItlTerminalProof *proof, TransactionId xid, + uint16 slot_wrap, uint8 slot_class, const UBA *undo_segment_head) { - return proof != NULL && proof->valid && xid == proof->xid - && slot_wrap == proof->slot_wrap && slot_class == proof->slot_class - && undo_segment_head != NULL - && undo_segment_head->raw[0] == proof->undo_segment_head.raw[0] - && undo_segment_head->raw[1] == proof->undo_segment_head.raw[1]; + return proof != NULL && proof->valid && xid == proof->xid && slot_wrap == proof->slot_wrap + && slot_class == proof->slot_class && undo_segment_head != NULL + && undo_segment_head->raw[0] == proof->undo_segment_head.raw[0] + && undo_segment_head->raw[1] == proof->undo_segment_head.raw[1]; } /* @@ -240,17 +236,17 @@ extern void cluster_itl_touch_register_exact(const ClusterItlTouchHandle *handle /* Receipt-bearing twin for an ordinary heap path that already crossed exact * APPLY. The receipt handle is copied only into the private touch record; * ClusterItlTouchHandle remains the frozen 24-byte public ABI. */ -extern void cluster_itl_touch_register_exact_ctrc( - const ClusterItlTouchHandle *handle, Buffer buffer, TransactionId xid, - const ClusterCtrcReceiptHandle *ctrc_handle); +extern void cluster_itl_touch_register_exact_ctrc(const ClusterItlTouchHandle *handle, + Buffer buffer, TransactionId xid, + const ClusterCtrcReceiptHandle *ctrc_handle); /* Lookup-only accelerator for same-transaction, same-ITL receipt reuse. * The caller holds the page content lock EXCLUSIVE. A hit requires the * current slot bytes and local X-owner proof to match the newest capture in * the current subtransaction range; a miss changes no shared state. */ -extern bool cluster_itl_touch_lookup_reusable_ctrc( - const ClusterItlTouchHandle *handle, Buffer buffer, TransactionId xid, - ClusterCtrcReceiptHandle *ctrc_handle_out); +extern bool cluster_itl_touch_lookup_reusable_ctrc(const ClusterItlTouchHandle *handle, + Buffer buffer, TransactionId xid, + ClusterCtrcReceiptHandle *ctrc_handle_out); /* * spec-3.5 hardening: subxact range ownership for touched ITL slots. diff --git a/src/include/cluster/cluster_lmon.h b/src/include/cluster/cluster_lmon.h index ddf24f82e13..cb8d86efb4e 100644 --- a/src/include/cluster/cluster_lmon.h +++ b/src/include/cluster/cluster_lmon.h @@ -142,7 +142,7 @@ typedef struct ClusterLmonSharedState { uint64 last_iter_us; /* most recent main-loop iteration wall time */ uint64 max_iter_us; /* high-water iteration wall time */ uint64 slow_iter_count; /* iterations over cluster.lmon_slow_iteration_warn_ms */ - uint64 timed_duty_sample_count; /* completed samples paired with total_iter_us */ + uint64 timed_duty_sample_count; /* completed samples paired with total_iter_us */ uint64 total_iter_us; /* same-incarnation cumulative duty time */ struct Latch *lmon_latch; /* qvotec completion wake target; LMON owns lifecycle */ bool shutdown_requested; /* postmaster sets; LMON main loop polls + exits */ diff --git a/src/include/cluster/cluster_lms.h b/src/include/cluster/cluster_lms.h index bc4e64c0a5e..ddb257a547b 100644 --- a/src/include/cluster/cluster_lms.h +++ b/src/include/cluster/cluster_lms.h @@ -399,24 +399,20 @@ extern void LmsMain(void) pg_attribute_noreturn(); extern void LmsWorkerMain(int worker_id) pg_attribute_noreturn(); /* D4-B LMON/worker0 close handshake over the existing 80-byte control tail. */ -extern bool cluster_lms_r4_drain_request(ClusterLmsSharedState *state, - uint64 generation, - uint64 *worker_incarnation); +extern bool cluster_lms_r4_drain_request(ClusterLmsSharedState *state, uint64 generation, + uint64 *worker_incarnation); #ifdef USE_CLUSTER_UNIT extern uint64 cluster_lms_test_publish_r4_worker_incarnation(ClusterLmsSharedState *state, - int worker_id); -extern bool cluster_lms_test_r4_drain_request(ClusterLmsSharedState *state, - uint64 generation, - uint64 *worker_incarnation); -extern bool cluster_lms_test_r4_drain_ack(ClusterLmsSharedState *state, - uint64 worker_incarnation, - uint64 generation); + int worker_id); +extern bool cluster_lms_test_r4_drain_request(ClusterLmsSharedState *state, uint64 generation, + uint64 *worker_incarnation); +extern bool cluster_lms_test_r4_drain_ack(ClusterLmsSharedState *state, uint64 worker_incarnation, + uint64 generation); extern bool cluster_lms_test_r4_drain_ack_matches(ClusterLmsSharedState *state, - uint64 worker_incarnation, - uint64 generation); + uint64 worker_incarnation, uint64 generation); extern bool cluster_lms_test_r4_drain_ack_tick(ClusterLmsSharedState *state, - uint64 worker_incarnation); + uint64 worker_incarnation); #endif /* @@ -440,12 +436,10 @@ extern void cluster_lms_data_plane_tick(long timeout_ms); extern void cluster_lms_data_plane_shutdown(void); #ifdef USE_CLUSTER_UNIT -extern void cluster_lms_data_plane_test_seed_peer(int32 peer_id, int fd, - bool connected, bool enabled, - bool wes_dirty); -extern bool cluster_lms_data_plane_test_peer_snapshot(int32 peer_id, - int *fd_out, bool *down_out, - bool *wes_dirty_out); +extern void cluster_lms_data_plane_test_seed_peer(int32 peer_id, int fd, bool connected, + bool enabled, bool wes_dirty); +extern bool cluster_lms_data_plane_test_peer_snapshot(int32 peer_id, int *fd_out, bool *down_out, + bool *wes_dirty_out); #endif /* @@ -462,14 +456,15 @@ extern void cluster_lms_outbound_request_lwlocks(void); extern bool cluster_lms_outbound_enqueue(int worker_id, uint8 msg_type, uint32 dest_node_id, const void *payload, uint16 payload_len); extern bool cluster_lms_outbound_enqueue_cap_bound(int worker_id, uint8 msg_type, - uint32 dest_node_id, const void *payload, - uint16 payload_len, uint32 required_capability, - uint32 connection_generation); + uint32 dest_node_id, const void *payload, + uint16 payload_len, uint32 required_capability, + uint32 connection_generation); struct ResourceXIntentSlot; struct ClusterPcmOwnSnapshot; -extern bool cluster_lms_outbound_enqueue_resource_x_intent( - int worker_id, const struct ResourceXIntentSlot *intent, - uint32 connection_generation, uint64 deadline_us); +extern bool cluster_lms_outbound_enqueue_resource_x_intent(int worker_id, + const struct ResourceXIntentSlot *intent, + uint32 connection_generation, + uint64 deadline_us); /* Process-local handle for the current-slice remote-S holder adaptation. * It names one exact PENDING slot in the existing LMS DATA ring; none of @@ -483,23 +478,19 @@ typedef struct ClusterLmsRemoteSStatusHandle { uint64 reservation_token; } ClusterLmsRemoteSStatusHandle; -extern ClusterPcmOwnResult -cluster_lms_outbound_stage_resource_x_remote_s_status_exact( - int worker_id, uint32 dest_node_id, const void *payload, - uint16 payload_len, const struct ClusterPcmOwnSnapshot *expected_revoking, +extern ClusterPcmOwnResult cluster_lms_outbound_stage_resource_x_remote_s_status_exact( + int worker_id, uint32 dest_node_id, const void *payload, uint16 payload_len, + const struct ClusterPcmOwnSnapshot *expected_revoking, ClusterLmsRemoteSStatusHandle *handle_out); -extern ClusterPcmOwnResult -cluster_lms_outbound_publish_resource_x_remote_s_status_exact( - const ClusterLmsRemoteSStatusHandle *handle, - const struct ClusterPcmOwnSnapshot *released_n); -extern ClusterPcmOwnResult -cluster_lms_outbound_cancel_resource_x_remote_s_status_exact( +extern ClusterPcmOwnResult cluster_lms_outbound_publish_resource_x_remote_s_status_exact( + const ClusterLmsRemoteSStatusHandle *handle, const struct ClusterPcmOwnSnapshot *released_n); +extern ClusterPcmOwnResult cluster_lms_outbound_cancel_resource_x_remote_s_status_exact( const ClusterLmsRemoteSStatusHandle *handle); extern int cluster_lms_outbound_resource_x_intent_pump(void); struct GcsBlockReplyHeader; extern bool cluster_lms_outbound_enqueue_zero_block_reply(int worker_id, uint32 dest_node_id, - const struct GcsBlockReplyHeader *header, - bool direct_land); + const struct GcsBlockReplyHeader *header, + bool direct_land); extern bool cluster_lms_outbound_enqueue_zero_block_reply_cap_bound( int worker_id, uint32 dest_node_id, const struct GcsBlockReplyHeader *header, uint32 required_capability, uint32 connection_generation); @@ -516,8 +507,8 @@ typedef struct ClusterLmsResourceXTransportSnapshot { StaticAssertDecl(sizeof(ClusterLmsResourceXTransportSnapshot) == 16, "Resource-X transport snapshot layout must remain 16 bytes"); -extern bool cluster_lms_outbound_resource_x_transport_snapshot( - ClusterLmsResourceXTransportSnapshot *out); +extern bool +cluster_lms_outbound_resource_x_transport_snapshot(ClusterLmsResourceXTransportSnapshot *out); extern uint64 cluster_lms_outbound_resource_x_staged_count(void); /* diff --git a/src/include/cluster/cluster_membership.h b/src/include/cluster/cluster_membership.h index f60f324700c..a00646a28c5 100644 --- a/src/include/cluster/cluster_membership.h +++ b/src/include/cluster/cluster_membership.h @@ -213,22 +213,22 @@ typedef struct ClusterReplacementCommitMarkerV3 { uint32 crc32c; } ClusterReplacementCommitMarkerV3; -extern bool cluster_replacement_marker_v3_encode( - const ClusterReplacementCommitMarkerV3 *marker, - uint8 out[CLUSTER_JCMK_REPLACEMENT_BYTES]); -extern bool cluster_replacement_marker_v3_decode( - const uint8 bytes[CLUSTER_JCMK_REPLACEMENT_BYTES], int32 expected_target_node, - ClusterReplacementCommitMarkerV3 *out); +extern bool cluster_replacement_marker_v3_encode(const ClusterReplacementCommitMarkerV3 *marker, + uint8 out[CLUSTER_JCMK_REPLACEMENT_BYTES]); +extern bool cluster_replacement_marker_v3_decode(const uint8 bytes[CLUSTER_JCMK_REPLACEMENT_BYTES], + int32 expected_target_node, + ClusterReplacementCommitMarkerV3 *out); /* Pure v3 identity, strict-majority and phase-basis decisions. */ -extern bool cluster_replacement_marker_v3_same_image( - const ClusterReplacementCommitMarkerV3 *a, const ClusterReplacementCommitMarkerV3 *b); +extern bool cluster_replacement_marker_v3_same_image(const ClusterReplacementCommitMarkerV3 *a, + const ClusterReplacementCommitMarkerV3 *b); extern int cluster_replacement_marker_v3_select_majority( const uint8 images[][CLUSTER_JCMK_REPLACEMENT_BYTES], int n, uint32 majority, int32 expected_target_node, ClusterReplacementCommitMarkerV3 *out_marker, uint32 *out_agree); -extern bool cluster_replacement_marker_v3_floor_basis( - const uint8 bytes[CLUSTER_JCMK_REPLACEMENT_BYTES], int32 expected_target_node, - uint64 *out_incarnation_floor); +extern bool +cluster_replacement_marker_v3_floor_basis(const uint8 bytes[CLUSTER_JCMK_REPLACEMENT_BYTES], + int32 expected_target_node, + uint64 *out_incarnation_floor); extern bool cluster_replacement_marker_v3_is_committed_closed_basis( const uint8 bytes[CLUSTER_JCMK_REPLACEMENT_BYTES], int32 expected_target_node, uint64 *out_incarnation_floor); diff --git a/src/include/cluster/cluster_multixact.h b/src/include/cluster/cluster_multixact.h index f9feb7624c3..2cd4a4ee82b 100644 --- a/src/include/cluster/cluster_multixact.h +++ b/src/include/cluster/cluster_multixact.h @@ -135,15 +135,14 @@ cluster_multixact_native_snapshot_equal(MultiXactOffset first_generation, int fi { int i; - if (first_generation == 0 || second_generation == 0 - || first_generation != second_generation || first_count != second_count - || first_count < 2 || first_count > 256 || first == NULL || second == NULL) + if (first_generation == 0 || second_generation == 0 || first_generation != second_generation + || first_count != second_count || first_count < 2 || first_count > 256 || first == NULL + || second == NULL) return false; for (i = 0; i < first_count; i++) { if (!TransactionIdIsNormal(first[i].xid) || !TransactionIdIsNormal(second[i].xid) - || first[i].status < MultiXactStatusForKeyShare - || first[i].status > MaxMultiXactStatus + || first[i].status < MultiXactStatusForKeyShare || first[i].status > MaxMultiXactStatus || second[i].status < MultiXactStatusForKeyShare || second[i].status > MaxMultiXactStatus || first[i].xid != second[i].xid || first[i].status != second[i].status) @@ -214,9 +213,10 @@ typedef struct ClusterMultiXactSourceResult { * Callers may consume overlay_out only when the return value is OK and * the operation's fixed success field is positive. */ -extern ClusterSemanticAdmissionResult cluster_multixact_source_dispatch( - ClusterMultiXactSourceOp op, const ClusterMultiXactSourceRequest *request, - ClusterMultiXactSourceResult *result); +extern ClusterSemanticAdmissionResult +cluster_multixact_source_dispatch(ClusterMultiXactSourceOp op, + const ClusterMultiXactSourceRequest *request, + ClusterMultiXactSourceResult *result); /* * Resolve the frozen D3-b snapshot-visibility contract under the semantic @@ -227,25 +227,22 @@ extern ClusterSemanticAdmissionResult cluster_multixact_source_dispatch( * unchanged. */ extern ClusterSemanticAdmissionResult -cluster_multixact_remote_xmax_visibility_dispatch( - const ClusterMultiXactSourceRequest *request, - ClusterMultiXactSourceResult *result); +cluster_multixact_remote_xmax_visibility_dispatch(const ClusterMultiXactSourceRequest *request, + ClusterMultiXactSourceResult *result); struct ClusterSideProjectionOperationV1; /* RF-SIDE retained-redo rebuild path. These callback-shaped APIs bypass the * R4 semantic-serving gate only to mutate/verify non-authoritative projection * metadata; they never grant terminal state, readiness or OPEN. */ -extern bool cluster_multixact_recovery_projection_apply(void *arg, - int origin_slot, uint32 cluster_epoch, - const struct ClusterSideProjectionOperationV1 *operation, - const uint8 *owned_payload, uint32 owned_payload_length, - XLogRecPtr source_lsn, XLogRecPtr source_end_lsn); -extern bool cluster_multixact_recovery_projection_verify(void *arg, - int origin_slot, uint32 cluster_epoch, - const struct ClusterSideProjectionOperationV1 *operation, - const uint8 *owned_payload, uint32 owned_payload_length, - XLogRecPtr source_lsn, XLogRecPtr source_end_lsn); +extern bool cluster_multixact_recovery_projection_apply( + void *arg, int origin_slot, uint32 cluster_epoch, + const struct ClusterSideProjectionOperationV1 *operation, const uint8 *owned_payload, + uint32 owned_payload_length, XLogRecPtr source_lsn, XLogRecPtr source_end_lsn); +extern bool cluster_multixact_recovery_projection_verify( + void *arg, int origin_slot, uint32 cluster_epoch, + const struct ClusterSideProjectionOperationV1 *operation, const uint8 *owned_payload, + uint32 owned_payload_length, XLogRecPtr source_lsn, XLogRecPtr source_end_lsn); /* * spec-7.1 D3-b: one multixact member's origin-SERVED terminal verdict. diff --git a/src/include/cluster/cluster_multixact_current.h b/src/include/cluster/cluster_multixact_current.h index 6c35be188a1..edcf8129596 100644 --- a/src/include/cluster/cluster_multixact_current.h +++ b/src/include/cluster/cluster_multixact_current.h @@ -101,8 +101,7 @@ typedef struct ClusterCurrentMemberProof { static inline void -ClusterCurrentMemberProofSetCtrcBinding(ClusterCurrentMemberProof *proof, - uint32 segment_generation, +ClusterCurrentMemberProofSetCtrcBinding(ClusterCurrentMemberProof *proof, uint32 segment_generation, uint16 slot_wrap) { proof->key.segment_generation = segment_generation; @@ -113,17 +112,13 @@ ClusterCurrentMemberProofSetCtrcBinding(ClusterCurrentMemberProof *proof, static inline bool ClusterCurrentMemberProofGetStatusKey(const ClusterCurrentMemberProof *proof, - ClusterTTStatusKey *status_key, - uint32 *segment_generation, + ClusterTTStatusKey *status_key, uint32 *segment_generation, uint16 *slot_wrap) { - if (proof == NULL || status_key == NULL || segment_generation == NULL - || slot_wrap == NULL + if (proof == NULL || status_key == NULL || segment_generation == NULL || slot_wrap == NULL || (proof->state != CCM_ACTIVE && proof->state != CCM_SELF) - || proof->key.binding_version - != CLUSTER_CURRENT_MEMBER_PROOF_BINDING_VERSION - || proof->key.segment_generation == UINT32_MAX - || proof->key.slot_wrap == UINT16_MAX) + || proof->key.binding_version != CLUSTER_CURRENT_MEMBER_PROOF_BINDING_VERSION + || proof->key.segment_generation == UINT32_MAX || proof->key.slot_wrap == UINT16_MAX) return false; memset(status_key, 0, sizeof(*status_key)); status_key->origin_node_id = proof->key.origin_node_id; @@ -138,8 +133,7 @@ ClusterCurrentMemberProofGetStatusKey(const ClusterCurrentMemberProof *proof, static inline void -ClusterCurrentMemberProofSetCtrcGrant(ClusterCurrentMemberProof *proof, - uint32 grant_generation) +ClusterCurrentMemberProofSetCtrcGrant(ClusterCurrentMemberProof *proof, uint32 grant_generation) { proof->reserved8[0] = (uint8)(grant_generation & UINT32_C(0xff)); proof->reserved8[1] = (uint8)((grant_generation >> 8) & UINT32_C(0xff)); @@ -151,10 +145,8 @@ ClusterCurrentMemberProofSetCtrcGrant(ClusterCurrentMemberProof *proof, static inline uint32 ClusterCurrentMemberProofGetCtrcGrant(const ClusterCurrentMemberProof *proof) { - return (uint32)proof->reserved8[0] - | ((uint32)proof->reserved8[1] << 8) - | ((uint32)proof->reserved8[2] << 16) - | ((uint32)proof->reserved8[3] << 24); + return (uint32)proof->reserved8[0] | ((uint32)proof->reserved8[1] << 8) + | ((uint32)proof->reserved8[2] << 16) | ((uint32)proof->reserved8[3] << 24); } @@ -313,7 +305,7 @@ typedef struct ClusterCurrentProofChunkView { typedef bool (*ClusterCurrentMxExactLookupFn)(const ClusterTTStatusKey *key, - ClusterTTStatusResult *result, void *arg); + ClusterTTStatusResult *result, void *arg); /* @@ -409,22 +401,20 @@ extern ClusterMxResolveResult cluster_multixact_current_validate_proof_set( const ClusterCurrentProofChunkView *chunks, uint16 nchunks, ClusterCurrentMemberProof *ordered_proofs); extern bool cluster_multixact_current_resolve_origin_member_proof( - TransactionId member_xid, uint8 member_status, uint16 member_ordinal, - uint16 member_origin_node, uint32 current_epoch, bool requester_self, - const ClusterTTStatusKey *initial_key, const ClusterTTStatusResult *initial_result, - ClusterCurrentMxExactLookupFn exact_lookup, void *exact_lookup_arg, - ClusterCurrentMemberProof *proof); -extern bool cluster_multixact_current_member_proof_bind_ctrc( - ClusterCurrentMemberProof *proof, - const struct ClusterCtrcTxnKeyV1 *ctrc_key); + TransactionId member_xid, uint8 member_status, uint16 member_ordinal, uint16 member_origin_node, + uint32 current_epoch, bool requester_self, const ClusterTTStatusKey *initial_key, + const ClusterTTStatusResult *initial_result, ClusterCurrentMxExactLookupFn exact_lookup, + void *exact_lookup_arg, ClusterCurrentMemberProof *proof); +extern bool +cluster_multixact_current_member_proof_bind_ctrc(ClusterCurrentMemberProof *proof, + const struct ClusterCtrcTxnKeyV1 *ctrc_key); extern ClusterUpdaterCandidateVerdict cluster_multixact_current_updater_candidate_verdict( - const ClusterTTStatusKey *candidate, TransactionId updater_xid, - uint16 updater_origin_node, uint32 current_epoch, ClusterTTStatusKey *current_binding, + const ClusterTTStatusKey *candidate, TransactionId updater_xid, uint16 updater_origin_node, + uint32 current_epoch, ClusterTTStatusKey *current_binding, ClusterTTStatusResult *current_result); extern bool cluster_multixact_current_successor_provenance_well_formed( - const ClusterCurrentMxSuccessorAlias *alias, - const ClusterTxLocator *locator, TransactionId updater_xid, - uint16 updater_origin_node, uint32 current_epoch); + const ClusterCurrentMxSuccessorAlias *alias, const ClusterTxLocator *locator, + TransactionId updater_xid, uint16 updater_origin_node, uint32 current_epoch); extern bool cluster_multixact_current_validate_updater_proof( const ClusterCurrentMxKey *key, const ClusterCurrentMxMemberDesc *members, const ClusterCurrentMemberProof *proofs, uint16 nmembers, @@ -462,12 +452,12 @@ extern ClusterMxRecomposeResult cluster_multixact_current_recompose( const ClusterCurrentMxMemberDesc *members, const ClusterCurrentMemberProof *proofs, uint16 nmembers, TransactionId requester_xid, MultiXactStatus requester_status, MultiXactMember *normalized_members, uint16 normalized_cap, uint16 *normalized_count); -extern bool cluster_multixact_current_plan_heap_header( - const void *base_header, Size header_size, - const ClusterCurrentMxHeapHeaderPlan *plan, void *planned_header); -extern bool cluster_multixact_current_heap_publish_transition( - ClusterCurrentMxHeapPublishStage stage, - ClusterCurrentMxHeapPublishEvent event, - ClusterCurrentMxHeapPublishStage *next_stage); +extern bool cluster_multixact_current_plan_heap_header(const void *base_header, Size header_size, + const ClusterCurrentMxHeapHeaderPlan *plan, + void *planned_header); +extern bool +cluster_multixact_current_heap_publish_transition(ClusterCurrentMxHeapPublishStage stage, + ClusterCurrentMxHeapPublishEvent event, + ClusterCurrentMxHeapPublishStage *next_stage); #endif /* CLUSTER_MULTIXACT_CURRENT_H */ diff --git a/src/include/cluster/cluster_multixact_current_stats.h b/src/include/cluster/cluster_multixact_current_stats.h index 4eb54525e98..4546de80ca6 100644 --- a/src/include/cluster/cluster_multixact_current_stats.h +++ b/src/include/cluster/cluster_multixact_current_stats.h @@ -66,13 +66,12 @@ typedef enum ClusterCurrentMxStatId { CMX_STAT_COUNT } ClusterCurrentMxStatId; -typedef struct ClusterCurrentMxStatsSnapshot -{ - uint32 node_id; - uint32 reserved32; - uint64 cluster_epoch; +typedef struct ClusterCurrentMxStatsSnapshot { + uint32 node_id; + uint32 reserved32; + uint64 cluster_epoch; TimestampTz stats_since; - uint64 counters[CMX_STAT_COUNT]; + uint64 counters[CMX_STAT_COUNT]; } ClusterCurrentMxStatsSnapshot; extern Size cluster_multixact_current_stats_shmem_size(void); @@ -84,9 +83,8 @@ extern TimestampTz cluster_multixact_current_stats_since(void); extern ClusterCurrentMxStatId cluster_multixact_current_restart_bucket(uint32 restarts); extern void cluster_multixact_current_stats_record_restarts(uint32 restarts); extern void cluster_multixact_current_stats_alert_sample(void); -extern bool cluster_multixact_current_stats_snapshot( - uint32 node_id, uint64 cluster_epoch, - ClusterCurrentMxStatsSnapshot *snapshot); +extern bool cluster_multixact_current_stats_snapshot(uint32 node_id, uint64 cluster_epoch, + ClusterCurrentMxStatsSnapshot *snapshot); #endif /* USE_PGRAC_CLUSTER */ diff --git a/src/include/cluster/cluster_multixact_current_wire.h b/src/include/cluster/cluster_multixact_current_wire.h index ffddd181da4..3cd3b46d878 100644 --- a/src/include/cluster/cluster_multixact_current_wire.h +++ b/src/include/cluster/cluster_multixact_current_wire.h @@ -138,8 +138,8 @@ typedef struct ClusterCurrentMxDescribeReplyHeader { uint32 reserved32; } ClusterCurrentMxDescribeReplyHeader; -#define CLUSTER_CURRENT_MX_DESCRIBE_REPLY_RESERVED_SIZE \ - (BLCKSZ - sizeof(ClusterCurrentMxDescribeReplyHeader) \ +#define CLUSTER_CURRENT_MX_DESCRIBE_REPLY_RESERVED_SIZE \ + (BLCKSZ - sizeof(ClusterCurrentMxDescribeReplyHeader) \ - CLUSTER_CURRENT_MX_MAX_MEMBERS * sizeof(ClusterCurrentMxMemberDesc)) typedef struct ClusterCurrentMxDescribeReplyPage { @@ -170,22 +170,18 @@ typedef struct ClusterCurrentMxProofReplyHeader { typedef struct ClusterCurrentMxUpdaterProofReplyBodyWire { ClusterCurrentMemberProof member_proof; ClusterCurrentUpdaterProof updater_proof; - uint8 reserved[CLUSTER_CURRENT_MX_MAX_PROOF_ASKS_PER_FRAME - * sizeof(ClusterCurrentMemberProof) - - sizeof(ClusterCurrentMemberProof) - - sizeof(ClusterCurrentUpdaterProof)]; + uint8 reserved[CLUSTER_CURRENT_MX_MAX_PROOF_ASKS_PER_FRAME * sizeof(ClusterCurrentMemberProof) + - sizeof(ClusterCurrentMemberProof) - sizeof(ClusterCurrentUpdaterProof)]; } ClusterCurrentMxUpdaterProofReplyBodyWire; typedef union ClusterCurrentMxProofReplyBodyWire { ClusterCurrentMemberProof proofs[CLUSTER_CURRENT_MX_MAX_PROOF_ASKS_PER_FRAME]; ClusterCurrentMxUpdaterProofReplyBodyWire updater; - uint8 raw[CLUSTER_CURRENT_MX_MAX_PROOF_ASKS_PER_FRAME - * sizeof(ClusterCurrentMemberProof)]; + uint8 raw[CLUSTER_CURRENT_MX_MAX_PROOF_ASKS_PER_FRAME * sizeof(ClusterCurrentMemberProof)]; } ClusterCurrentMxProofReplyBodyWire; -#define CLUSTER_CURRENT_MX_PROOF_REPLY_RESERVED_SIZE \ - (BLCKSZ - sizeof(ClusterCurrentMxProofReplyHeader) \ - - sizeof(ClusterCurrentMxProofReplyBodyWire)) +#define CLUSTER_CURRENT_MX_PROOF_REPLY_RESERVED_SIZE \ + (BLCKSZ - sizeof(ClusterCurrentMxProofReplyHeader) - sizeof(ClusterCurrentMxProofReplyBodyWire)) typedef struct ClusterCurrentMxProofReplyPage { ClusterCurrentMxProofReplyHeader header; @@ -196,7 +192,7 @@ typedef struct ClusterCurrentMxProofReplyPage { StaticAssertDecl(sizeof(ClusterCurrentMxDescribePrefixWire) == sizeof(GcsBlockForwardPayload), "current MX describe prefix must preserve the shipped 64-byte frame"); StaticAssertDecl(offsetof(ClusterCurrentMxDescribePrefixWire, request_id) - == offsetof(GcsBlockForwardPayload, request_id) + == offsetof(GcsBlockForwardPayload, request_id) && offsetof(ClusterCurrentMxDescribePrefixWire, epoch) == offsetof(GcsBlockForwardPayload, epoch) && offsetof(ClusterCurrentMxDescribePrefixWire, original_requester_node) @@ -253,8 +249,7 @@ StaticAssertDecl(sizeof(ClusterCurrentMxDescribeReplyPage) == BLCKSZ, "current MX describe reply must fill one GCS page"); StaticAssertDecl(sizeof(ClusterCurrentMxProofReplyHeader) == 64, "current MX proof reply header must remain 64 bytes"); -StaticAssertDecl(offsetof(ClusterCurrentMxProofReplyHeader, - requester_capability_generation) == 60, +StaticAssertDecl(offsetof(ClusterCurrentMxProofReplyHeader, requester_capability_generation) == 60, "current MX requester capability carrier offset must remain 60"); StaticAssertDecl(sizeof(ClusterCurrentMxUpdaterProofReplyBodyWire) == CLUSTER_CURRENT_MX_MAX_PROOF_ASKS_PER_FRAME @@ -317,15 +312,13 @@ extern ClusterMxResolveResult cluster_multixact_current_wire_build_proof_request uint16 plans_cap, uint16 *plan_count); extern ClusterMxResolveResult cluster_multixact_current_wire_validate_proof_reply( const void *payload, uint32 payload_length, int32 expected_source, uint64 current_epoch, - const ClusterCurrentMxProofForwardV2 *expected_request, - ClusterCurrentMemberProof *proofs, uint16 proofs_cap, uint16 *proof_count, - ClusterCurrentUpdaterProof *updater_proof, + const ClusterCurrentMxProofForwardV2 *expected_request, ClusterCurrentMemberProof *proofs, + uint16 proofs_cap, uint16 *proof_count, ClusterCurrentUpdaterProof *updater_proof, uint32 *requester_capability_generation_out); extern bool cluster_multixact_current_wire_validate_proof_reply_frame( const void *payload, uint32 payload_length, int32 expected_source, uint64 current_epoch, const ClusterCurrentMxProofForwardV2 *expected_request, ClusterMxResolveResult *result, ClusterCurrentMemberProof *proofs, uint16 proofs_cap, uint16 *proof_count, - ClusterCurrentUpdaterProof *updater_proof, - uint32 *requester_capability_generation_out); + ClusterCurrentUpdaterProof *updater_proof, uint32 *requester_capability_generation_out); #endif /* CLUSTER_MULTIXACT_CURRENT_WIRE_H */ diff --git a/src/include/cluster/cluster_node_remove.h b/src/include/cluster/cluster_node_remove.h index 7c0d8c9b401..691954bf623 100644 --- a/src/include/cluster/cluster_node_remove.h +++ b/src/include/cluster/cluster_node_remove.h @@ -311,8 +311,7 @@ extern const char *cluster_node_remove_phase_str(int phase); /* canonical text for a request result (operator UDF return). */ extern const char *cluster_node_remove_request_result_str(ClusterRemoveRequestResult r); -extern bool cluster_node_remove_startup_serving_allows(bool authority_managed, - bool serving_ready); +extern bool cluster_node_remove_startup_serving_allows(bool authority_managed, bool serving_ready); /* * Precheck verdict (U10 / §3.2) — pure mapping of the live facts to a request diff --git a/src/include/cluster/cluster_page_anchor_cache.h b/src/include/cluster/cluster_page_anchor_cache.h index 5bc442629b4..33f422ad2f1 100644 --- a/src/include/cluster/cluster_page_anchor_cache.h +++ b/src/include/cluster/cluster_page_anchor_cache.h @@ -13,37 +13,32 @@ #define CLUSTER_PAGE_ANCHOR_CACHE_INTERFACE_V1 1 #define RF_PAGE_ANCHOR_CACHE_CAPACITY 256 -typedef struct RfPageAnchorCacheKeyV1 -{ +typedef struct RfPageAnchorCacheKeyV1 { RfPageIdentityV1 page_identity; - uint8 segment_incarnation[16]; - uint8 root_lineage[16]; - uint64 checkpoint_epoch; - uint64 fpw_epoch; + uint8 segment_incarnation[16]; + uint8 root_lineage[16]; + uint64 checkpoint_epoch; + uint64 fpw_epoch; } RfPageAnchorCacheKeyV1; /* true means the caller must add REGBUF_FORCE_IMAGE. */ -extern bool rf_page_anchor_cache_key_valid_v1( - const RfPageAnchorCacheKeyV1 *key); -extern bool rf_page_anchor_cache_block_matches_v1( - const RfPageAnchorCacheKeyV1 *key, const RelFileLocator *locator, - ForkNumber forknum, BlockNumber blockno); -extern bool rf_page_anchor_cache_incarnation_matches_v1( - const RfPageAnchorCacheKeyV1 *key, - const uint8 result_incarnation[16]); -extern bool rf_page_anchor_cache_should_force_v1( - const RfPageAnchorCacheKeyV1 *key); -extern uint8 rf_page_anchor_cache_registration_flags_v1( - const RfPageAnchorCacheKeyV1 *key, uint8 caller_flags); +extern bool rf_page_anchor_cache_key_valid_v1(const RfPageAnchorCacheKeyV1 *key); +extern bool rf_page_anchor_cache_block_matches_v1(const RfPageAnchorCacheKeyV1 *key, + const RelFileLocator *locator, ForkNumber forknum, + BlockNumber blockno); +extern bool rf_page_anchor_cache_incarnation_matches_v1(const RfPageAnchorCacheKeyV1 *key, + const uint8 result_incarnation[16]); +extern bool rf_page_anchor_cache_should_force_v1(const RfPageAnchorCacheKeyV1 *key); +extern uint8 rf_page_anchor_cache_registration_flags_v1(const RfPageAnchorCacheKeyV1 *key, + uint8 caller_flags); /* * Cache credit is granted only after a successful WAL insertion that * actually emitted an APPLY image. A full cache returns false and safely * leaves this key as a miss. */ -extern bool rf_page_anchor_cache_record_v1( - const RfPageAnchorCacheKeyV1 *key, bool insert_succeeded, - bool apply_image_emitted); +extern bool rf_page_anchor_cache_record_v1(const RfPageAnchorCacheKeyV1 *key, bool insert_succeeded, + bool apply_image_emitted); extern void rf_page_anchor_cache_forget_all_v1(void); -#endif /* CLUSTER_PAGE_ANCHOR_CACHE_H */ +#endif /* CLUSTER_PAGE_ANCHOR_CACHE_H */ diff --git a/src/include/cluster/cluster_page_apply.h b/src/include/cluster/cluster_page_apply.h index a160abd86c2..5fc2beb51e1 100644 --- a/src/include/cluster/cluster_page_apply.h +++ b/src/include/cluster/cluster_page_apply.h @@ -50,20 +50,18 @@ * any false the caller performs NO page mutation and never converts a * temporary failure into a skip (spec §7.1). */ -typedef struct ClusterPageMutationAdmission -{ - bool duty_root_ok; /* exact duty/control root current */ - bool recoverer_active_ok; /* active recoverer + failure generation */ - bool fence_ok; /* four-layer fence armed */ - bool serialization_ok; /* exact resource serialization held */ - bool source_proof_fresh; /* selected §5 proof re-validated */ - bool working_version_exact; /* current == expected-before (exact) */ - bool retention_covers; /* retention pin covers ALL contributors */ +typedef struct ClusterPageMutationAdmission { + bool duty_root_ok; /* exact duty/control root current */ + bool recoverer_active_ok; /* active recoverer + failure generation */ + bool fence_ok; /* four-layer fence armed */ + bool serialization_ok; /* exact resource serialization held */ + bool source_proof_fresh; /* selected §5 proof re-validated */ + bool working_version_exact; /* current == expected-before (exact) */ + bool retention_covers; /* retention pin covers ALL contributors */ } ClusterPageMutationAdmission; /* true iff every §7.1 fact holds. */ -extern bool cluster_page_mutation_admission( - const ClusterPageMutationAdmission *admission); +extern bool cluster_page_mutation_admission(const ClusterPageMutationAdmission *admission); /* * §7.2 sequence step judgement. The caller executes each native step @@ -83,18 +81,17 @@ extern bool cluster_page_mutation_admission( * relation-fsync-counter/logical-DONE/pre-write-checksum are never * substitutes (spec §7.2 last paragraph). */ -typedef struct ClusterPageSequenceResult -{ +typedef struct ClusterPageSequenceResult { ClusterPageRecoveryState state; /* advanced state (unchanged on failure) */ ClusterPageRecoveryOutcome outcome; } ClusterPageSequenceResult; -extern ClusterPageSequenceResult cluster_page_apply_step_durability( - ClusterPageRecoveryState state, bool durable_ok); -extern ClusterPageSequenceResult cluster_page_apply_step_post_read( - ClusterPageRecoveryState state, bool post_read_ok); -extern ClusterPageSequenceResult cluster_page_apply_step_authority( - ClusterPageRecoveryState state, bool authority_ok); +extern ClusterPageSequenceResult cluster_page_apply_step_durability(ClusterPageRecoveryState state, + bool durable_ok); +extern ClusterPageSequenceResult cluster_page_apply_step_post_read(ClusterPageRecoveryState state, + bool post_read_ok); +extern ClusterPageSequenceResult cluster_page_apply_step_authority(ClusterPageRecoveryState state, + bool authority_ok); /* * §7.3 typed page proof exported to RF-ROOT/SIDE (logical export only — @@ -102,16 +99,15 @@ extern ClusterPageSequenceResult cluster_page_apply_step_authority( * FND-10 conjunction; RF-SIDE consumes only page dependencies; it is * never an all-domain barrier (spec §7.3). */ -typedef struct ClusterPageProof -{ - uint16 failed_origin_thread; +typedef struct ClusterPageProof { + uint16 failed_origin_thread; ClusterPageIdentity identity; ClusterPageClass page_class; ClusterPageVersion post_read_version; /* canonical post-read result */ - bool contributor_coverage; /* source-to-terminal chain closed */ - bool durability_barrier_ok; /* durable ordering completed */ - bool post_read_ok; /* canonical bytes verified */ - bool authority_revalidated; /* RF-ROOT revalidation passed */ + bool contributor_coverage; /* source-to-terminal chain closed */ + bool durability_barrier_ok; /* durable ordering completed */ + bool post_read_ok; /* canonical bytes verified */ + bool authority_revalidated; /* RF-ROOT revalidation passed */ } ClusterPageProof; /* @@ -130,8 +126,7 @@ extern ClusterPageRecoveryOutcome cluster_page_apply_midwrite_cut(void); * rebuild, a fresh post-read or the stable-base STOP). Every row maps * to exactly one outcome; unknown cuts fail closed. */ -typedef enum ClusterPageCrashCut -{ +typedef enum ClusterPageCrashCut { CLUSTER_PAGE_CUT_BEFORE_SOURCE_PROOF = 0, CLUSTER_PAGE_CUT_AFTER_SOURCE_PROOF, CLUSTER_PAGE_CUT_DURING_TARGET_WRITE, @@ -141,7 +136,6 @@ typedef enum ClusterPageCrashCut CLUSTER_PAGE_CUT_AFTER_RELEASE } ClusterPageCrashCut; -extern ClusterPageRecoveryOutcome cluster_page_crash_matrix_verdict( - ClusterPageCrashCut cut); +extern ClusterPageRecoveryOutcome cluster_page_crash_matrix_verdict(ClusterPageCrashCut cut); -#endif /* CLUSTER_PAGE_APPLY_H */ +#endif /* CLUSTER_PAGE_APPLY_H */ diff --git a/src/include/cluster/cluster_page_authority.h b/src/include/cluster/cluster_page_authority.h index 2e7719bc41f..d815646d13c 100644 --- a/src/include/cluster/cluster_page_authority.h +++ b/src/include/cluster/cluster_page_authority.h @@ -16,8 +16,7 @@ #define CLUSTER_PAGE_AUTHORITY_INTERFACE_V1 1 -typedef enum RfPageAuthorityVerdictV1 -{ +typedef enum RfPageAuthorityVerdictV1 { RF_PAGE_AUTHORITY_OK = 0, RF_PAGE_AUTHORITY_INVALID_ARGUMENT = 1, RF_PAGE_AUTHORITY_ROOT_STALE = 2, @@ -39,8 +38,7 @@ typedef enum RfPageAuthorityVerdictV1 RF_PAGE_AUTHORITY_INTERNAL = 18 } RfPageAuthorityVerdictV1; -typedef struct RfPageAuthorityTargetV1 -{ +typedef struct RfPageAuthorityTargetV1 { RfPageIdentityV1 page_identity; RfPageVersionV1 expected_result; const RfPageStableBaseProofV1 *stable_base; @@ -48,52 +46,49 @@ typedef struct RfPageAuthorityTargetV1 const RfContributorVectorV1 *contributors; } RfPageAuthorityTargetV1; -typedef struct RfPageAuthorityBatchRequestV1 -{ +typedef struct RfPageAuthorityBatchRequestV1 { const RfPageAuthorityTargetV1 *targets; - uint32 target_count; + uint32 target_count; const ClusterFormationWitnessV1 *formation; const PgracExternalFenceNeedSetV1 *fence_need_set; const PgracExternalFenceAdmissionSetV1 *fence_admission_set; ClusterWalRetentionPin *retention_pin; const ClusterRecoveryDutyKey *duties; const ClusterControlRootReadToken *root_tokens; - uint32 participant_count; - uint32 flags; + uint32 participant_count; + uint32 flags; } RfPageAuthorityBatchRequestV1; typedef struct RfPageAuthorityPreflightV1 RfPageAuthorityPreflightV1; typedef struct RfPageAuthorityGuardV1 RfPageAuthorityGuardV1; -typedef struct RfPageInstallAuthorityAdapterV1 -{ +typedef struct RfPageInstallAuthorityAdapterV1 { RfPageInstallAuthorityOpsV1 ops; RfPageAuthorityPreflightV1 *preflight; ClusterRecoverySerialGuard *serial_guard; RfPageAuthorityGuardV1 *guard; - bool proof_published; + bool proof_published; } RfPageInstallAuthorityAdapterV1; -extern RfPageAuthorityVerdictV1 rf_page_authority_batch_preflight_wait_v1( - const RfPageAuthorityBatchRequestV1 *request, int timeout_ms, - RfPageAuthorityPreflightV1 **out_preflight); -extern RfPageAuthorityVerdictV1 rf_page_authority_batch_promote_nowait_v1( - RfPageAuthorityPreflightV1 *preflight, - ClusterRecoverySerialGuard *serial_guard, - RfPageAuthorityGuardV1 **out_guard); -extern RfPageAuthorityVerdictV1 rf_page_authority_batch_revalidate_nowait_v1( - const RfPageAuthorityGuardV1 *guard, - ClusterRecoverySerialGuard *serial_guard); -extern bool rf_page_authority_preflight_matches_target_v1( - const RfPageAuthorityPreflightV1 *preflight, - const RfPageIdentityV1 *identity, const uint8 incarnation[16]); -extern void rf_page_authority_preflight_destroy_v1( - RfPageAuthorityPreflightV1 **preflight); -extern void rf_page_authority_guard_release_v1( - RfPageAuthorityGuardV1 **guard); -extern bool rf_page_install_authority_adapter_init_v1( - RfPageAuthorityPreflightV1 *preflight, - ClusterRecoverySerialGuard *serial_guard, - RfPageInstallAuthorityAdapterV1 *adapter); +extern RfPageAuthorityVerdictV1 +rf_page_authority_batch_preflight_wait_v1(const RfPageAuthorityBatchRequestV1 *request, + int timeout_ms, + RfPageAuthorityPreflightV1 **out_preflight); +extern RfPageAuthorityVerdictV1 +rf_page_authority_batch_promote_nowait_v1(RfPageAuthorityPreflightV1 *preflight, + ClusterRecoverySerialGuard *serial_guard, + RfPageAuthorityGuardV1 **out_guard); +extern RfPageAuthorityVerdictV1 +rf_page_authority_batch_revalidate_nowait_v1(const RfPageAuthorityGuardV1 *guard, + ClusterRecoverySerialGuard *serial_guard); +extern bool +rf_page_authority_preflight_matches_target_v1(const RfPageAuthorityPreflightV1 *preflight, + const RfPageIdentityV1 *identity, + const uint8 incarnation[16]); +extern void rf_page_authority_preflight_destroy_v1(RfPageAuthorityPreflightV1 **preflight); +extern void rf_page_authority_guard_release_v1(RfPageAuthorityGuardV1 **guard); +extern bool rf_page_install_authority_adapter_init_v1(RfPageAuthorityPreflightV1 *preflight, + ClusterRecoverySerialGuard *serial_guard, + RfPageInstallAuthorityAdapterV1 *adapter); -#endif /* CLUSTER_PAGE_AUTHORITY_H */ +#endif /* CLUSTER_PAGE_AUTHORITY_H */ diff --git a/src/include/cluster/cluster_page_detached.h b/src/include/cluster/cluster_page_detached.h index 4dfdc485bc6..bf2259cb12f 100644 --- a/src/include/cluster/cluster_page_detached.h +++ b/src/include/cluster/cluster_page_detached.h @@ -14,47 +14,42 @@ #define CLUSTER_PAGE_DETACHED_INTERFACE_V1 1 -typedef enum RfDetachedComponentOwnerV1 -{ +typedef enum RfDetachedComponentOwnerV1 { RF_DETACHED_COMPONENT_INVALID = 0, RF_DETACHED_COMPONENT_PAGE_CODEC = 1, RF_DETACHED_COMPONENT_REBUILDABLE = 2, RF_DETACHED_COMPONENT_SIDE_TYPED = 3 } RfDetachedComponentOwnerV1; -typedef struct RfDetachedComponentPlanV1 -{ - uint8 block_id; - uint8 page_class; - uint8 owner; - uint8 codec_id; - uint16 component_ordinal; - uint16 edge_flags; - uint8 before_kind; - uint8 result_kind; - uint8 reserved_zero[6]; +typedef struct RfDetachedComponentPlanV1 { + uint8 block_id; + uint8 page_class; + uint8 owner; + uint8 codec_id; + uint16 component_ordinal; + uint16 edge_flags; + uint8 before_kind; + uint8 result_kind; + uint8 reserved_zero[6]; RfPageVersionV1 before; RfPageVersionV1 result; } RfDetachedComponentPlanV1; -typedef struct RfDetachedRecordPlanV1 -{ +typedef struct RfDetachedRecordPlanV1 { XLogReaderState *source_record; RfOpcodeRouteV1 route; - uint64 result_token; - uint32 component_count; + uint64 result_token; + uint32 component_count; RfDetachedComponentPlanV1 components[RF_PAGE_STABLE_MAX_COMPONENTS]; - bool preflight_complete; + bool preflight_complete; } RfDetachedRecordPlanV1; -typedef RfPageProofDetailV1 (*RfDetachedOwnerPreflightV1) (void *arg, - const RfOpcodeRouteV1 *route, - const RfPageVersionEdgeEntryV1 *edge, - const DecodedBkpBlock *block); +typedef RfPageProofDetailV1 (*RfDetachedOwnerPreflightV1)(void *arg, const RfOpcodeRouteV1 *route, + const RfPageVersionEdgeEntryV1 *edge, + const DecodedBkpBlock *block); -typedef struct RfDetachedOwnerOpsV1 -{ - void *arg; +typedef struct RfDetachedOwnerOpsV1 { + void *arg; RfDetachedOwnerPreflightV1 preflight_side_record; RfDetachedOwnerPreflightV1 preflight_side_component; RfDetachedOwnerPreflightV1 preflight_rebuildable_component; @@ -62,33 +57,31 @@ typedef struct RfDetachedOwnerOpsV1 struct RfDetachedPageCodecV1; -typedef RfPageProofDetailV1 (*RfDetachedCodecPreflightV1) ( - const struct RfDetachedPageCodecV1 *codec, - const RfOpcodeRouteV1 *route, - const RfPageVersionEdgeEntryV1 *edge, - const DecodedBkpBlock *block); +typedef RfPageProofDetailV1 (*RfDetachedCodecPreflightV1)(const struct RfDetachedPageCodecV1 *codec, + const RfOpcodeRouteV1 *route, + const RfPageVersionEdgeEntryV1 *edge, + const DecodedBkpBlock *block); -typedef RfPageProofDetailV1 (*RfDetachedCodecApplyV1) ( - XLogReaderState *record, uint8 block_id, uint64 result_token, - const char old_page[BLCKSZ], char new_page[BLCKSZ]); +typedef RfPageProofDetailV1 (*RfDetachedCodecApplyV1)(XLogReaderState *record, uint8 block_id, + uint64 result_token, + const char old_page[BLCKSZ], + char new_page[BLCKSZ]); -typedef struct RfDetachedPageCodecV1 -{ - uint8 codec_id; - uint8 rmid; - uint16 abi_version; +typedef struct RfDetachedPageCodecV1 { + uint8 codec_id; + uint8 rmid; + uint16 abi_version; RfDetachedCodecPreflightV1 preflight; RfDetachedCodecApplyV1 apply; } RfDetachedPageCodecV1; -extern const RfDetachedPageCodecV1 *rf_page_detached_codec_lookup_v1( - uint8 codec_id); -extern RfPageProofDetailV1 rf_page_detached_preflight_v1( - XLogReaderState *record, bool space_active, - const RfDetachedOwnerOpsV1 *owner_ops, - RfDetachedRecordPlanV1 *plan); -extern RfPageProofDetailV1 rf_page_detached_apply_v1( - const RfDetachedRecordPlanV1 *plan, uint32 component_index, - const char old_page[BLCKSZ], char new_page[BLCKSZ]); +extern const RfDetachedPageCodecV1 *rf_page_detached_codec_lookup_v1(uint8 codec_id); +extern RfPageProofDetailV1 rf_page_detached_preflight_v1(XLogReaderState *record, bool space_active, + const RfDetachedOwnerOpsV1 *owner_ops, + RfDetachedRecordPlanV1 *plan); +extern RfPageProofDetailV1 rf_page_detached_apply_v1(const RfDetachedRecordPlanV1 *plan, + uint32 component_index, + const char old_page[BLCKSZ], + char new_page[BLCKSZ]); -#endif /* CLUSTER_PAGE_DETACHED_H */ +#endif /* CLUSTER_PAGE_DETACHED_H */ diff --git a/src/include/cluster/cluster_page_guard.h b/src/include/cluster/cluster_page_guard.h index 20db49fe971..960242027da 100644 --- a/src/include/cluster/cluster_page_guard.h +++ b/src/include/cluster/cluster_page_guard.h @@ -13,43 +13,40 @@ #define CLUSTER_PAGE_GUARD_INTERFACE_V1 1 #define RF_PAGE_GUARD_PARTITIONS 256 -typedef enum RfPageGuardStateV1 -{ +typedef enum RfPageGuardStateV1 { RF_PAGE_GUARD_EMPTY = 0, RF_PAGE_GUARD_PREFLIGHTED = 1, RF_PAGE_GUARD_PROMOTED = 2, RF_PAGE_GUARD_RELEASED = 3 } RfPageGuardStateV1; -typedef struct RfPageGuardPreflightV1 -{ +typedef struct RfPageGuardPreflightV1 { RfPageIdentityV1 page_identity; - uint64 identity_fingerprint; - uint32 partition; - uint8 state; - uint8 reserved_zero[3]; + uint64 identity_fingerprint; + uint32 partition; + uint8 state; + uint8 reserved_zero[3]; } RfPageGuardPreflightV1; -typedef struct RfPageGuardV1 -{ +typedef struct RfPageGuardV1 { RfPageIdentityV1 page_identity; - uint64 identity_fingerprint; - uint32 partition; - int32 owner_pid; - uint8 state; - uint8 reserved_zero[7]; + uint64 identity_fingerprint; + uint32 partition; + int32 owner_pid; + uint8 state; + uint8 reserved_zero[7]; } RfPageGuardV1; extern void rf_page_guard_request_lwlocks_v1(void); extern void rf_page_guard_shmem_init_v1(void); extern bool rf_page_guard_preflight_v1(const RfPageIdentityV1 *identity, - RfPageGuardPreflightV1 *preflight); -extern bool rf_page_guard_promote_nowait_v1( - const RfPageGuardPreflightV1 *preflight, RfPageGuardV1 *guard); -extern bool rf_page_guard_revalidate_nowait_v1( - const RfPageGuardV1 *guard, const RfPageIdentityV1 *identity); -extern bool rf_page_guard_covers_nowait_v1( - const RfPageGuardV1 *guard, const RfPageIdentityV1 *identity); + RfPageGuardPreflightV1 *preflight); +extern bool rf_page_guard_promote_nowait_v1(const RfPageGuardPreflightV1 *preflight, + RfPageGuardV1 *guard); +extern bool rf_page_guard_revalidate_nowait_v1(const RfPageGuardV1 *guard, + const RfPageIdentityV1 *identity); +extern bool rf_page_guard_covers_nowait_v1(const RfPageGuardV1 *guard, + const RfPageIdentityV1 *identity); extern void rf_page_guard_release_v1(RfPageGuardV1 *guard); -#endif /* CLUSTER_PAGE_GUARD_H */ +#endif /* CLUSTER_PAGE_GUARD_H */ diff --git a/src/include/cluster/cluster_page_handoff.h b/src/include/cluster/cluster_page_handoff.h index dfbedd205ed..672696d7c42 100644 --- a/src/include/cluster/cluster_page_handoff.h +++ b/src/include/cluster/cluster_page_handoff.h @@ -49,12 +49,11 @@ * contributors is still retained; `consumers_zero` says no consumer * remains for this resource. */ -typedef struct ClusterPageHandoffInput -{ +typedef struct ClusterPageHandoffInput { const ClusterPageProof *proof; - bool side_proof_ok; - bool retention_pinned; - bool consumers_zero; + bool side_proof_ok; + bool retention_pinned; + bool consumers_zero; } ClusterPageHandoffInput; /* @@ -74,4 +73,4 @@ extern bool cluster_page_handoff_ready(const ClusterPageHandoffInput *in); */ extern bool cluster_page_handoff_retention_denied(const ClusterPageHandoffInput *in); -#endif /* CLUSTER_PAGE_HANDOFF_H */ +#endif /* CLUSTER_PAGE_HANDOFF_H */ diff --git a/src/include/cluster/cluster_page_install.h b/src/include/cluster/cluster_page_install.h index 1f0ec82feee..9ceebee6db7 100644 --- a/src/include/cluster/cluster_page_install.h +++ b/src/include/cluster/cluster_page_install.h @@ -12,84 +12,73 @@ #define CLUSTER_PAGE_INSTALL_INTERFACE_V1 1 -typedef struct RfPageStorageInstallComponentV1 -{ +typedef struct RfPageStorageInstallComponentV1 { RfPageIdentityV1 page_identity; - uint8 before_kind; - uint8 reserved_zero[7]; + uint8 before_kind; + uint8 reserved_zero[7]; RfPageVersionV1 expected_before; RfPageVersionV1 expected_result; const char *canonical_page; } RfPageStorageInstallComponentV1; -typedef struct RfPageInstallStorageOpsV1 -{ - void *arg; - bool checksums_enabled; - bool (*read) (void *arg, uint32 index, - const RfPageIdentityV1 *identity, char page[BLCKSZ], - bool *exists); - bool (*write) (void *arg, uint32 index, - const RfPageIdentityV1 *identity, - const char page[BLCKSZ], bool extend); - bool (*sync) (void *arg, uint32 index, - const RfPageIdentityV1 *identity); - uint16 (*checksum) (void *arg, const char page[BLCKSZ], - BlockNumber blockno); +typedef struct RfPageInstallStorageOpsV1 { + void *arg; + bool checksums_enabled; + bool (*read)(void *arg, uint32 index, const RfPageIdentityV1 *identity, char page[BLCKSZ], + bool *exists); + bool (*write)(void *arg, uint32 index, const RfPageIdentityV1 *identity, + const char page[BLCKSZ], bool extend); + bool (*sync)(void *arg, uint32 index, const RfPageIdentityV1 *identity); + uint16 (*checksum)(void *arg, const char page[BLCKSZ], BlockNumber blockno); } RfPageInstallStorageOpsV1; -typedef struct RfPageInstallAuthorityOpsV1 -{ - void *arg; - bool (*validate_identity) (void *arg, - const RfPageIdentityV1 *identity, +typedef struct RfPageInstallAuthorityOpsV1 { + void *arg; + bool (*validate_identity)(void *arg, const RfPageIdentityV1 *identity, const uint8 incarnation[16]); - bool (*promote) (void *arg); - bool (*publish) (void *arg); - bool (*release) (void *arg); + bool (*promote)(void *arg); + bool (*publish)(void *arg); + bool (*release)(void *arg); } RfPageInstallAuthorityOpsV1; -typedef struct RfPageStorageInstallRequestV1 -{ +typedef struct RfPageStorageInstallRequestV1 { const RfPageStorageInstallComponentV1 *components; - uint32 component_count; - char *prepared_pages; - Size prepared_capacity; - char *io_pages; - Size io_capacity; + uint32 component_count; + char *prepared_pages; + Size prepared_capacity; + char *io_pages; + Size io_capacity; const RfPageInstallStorageOpsV1 *storage; const RfPageInstallAuthorityOpsV1 *authority; - bool global_preflight_ok; + bool global_preflight_ok; } RfPageStorageInstallRequestV1; -typedef struct RfPageStorageInstallProofV1 -{ - uint32 component_count; - uint32 write_count; - uint32 result_skip_count; - bool durability_complete; - bool postread_complete; - bool proof_published; - bool authority_released; +typedef struct RfPageStorageInstallProofV1 { + uint32 component_count; + uint32 write_count; + uint32 result_skip_count; + bool durability_complete; + bool postread_complete; + bool proof_published; + bool authority_released; } RfPageStorageInstallProofV1; -extern RfPageProofDetailV1 rf_page_storage_install_execute_v1( - const RfPageStorageInstallRequestV1 *request, - RfPageStorageInstallProofV1 *proof); +extern RfPageProofDetailV1 +rf_page_storage_install_execute_v1(const RfPageStorageInstallRequestV1 *request, + RfPageStorageInstallProofV1 *proof); typedef struct RfPageSmgrPreopenV1 RfPageSmgrPreopenV1; -extern RfPageProofDetailV1 rf_page_storage_smgr_preopen_v1( - const RfPageStorageInstallRequestV1 *request, - RfPageSmgrPreopenV1 **out_preopen); -extern RfPageProofDetailV1 rf_page_storage_install_smgr_preopened_v1( - const RfPageStorageInstallRequestV1 *request, - RfPageSmgrPreopenV1 *preopen, - RfPageStorageInstallProofV1 *proof); -extern void rf_page_storage_smgr_preopen_destroy_v1( - RfPageSmgrPreopenV1 **preopen); -extern RfPageProofDetailV1 rf_page_storage_install_smgr_v1( - const RfPageStorageInstallRequestV1 *request, - RfPageStorageInstallProofV1 *proof); +extern RfPageProofDetailV1 +rf_page_storage_smgr_preopen_v1(const RfPageStorageInstallRequestV1 *request, + RfPageSmgrPreopenV1 **out_preopen); +extern RfPageProofDetailV1 +rf_page_storage_install_smgr_preopened_v1(const RfPageStorageInstallRequestV1 *request, + RfPageSmgrPreopenV1 *preopen, + RfPageStorageInstallProofV1 *proof); +extern void rf_page_storage_smgr_preopen_destroy_v1(RfPageSmgrPreopenV1 **preopen); +extern RfPageProofDetailV1 +rf_page_storage_install_smgr_v1(const RfPageStorageInstallRequestV1 *request, + RfPageStorageInstallProofV1 *proof); -#endif /* CLUSTER_PAGE_INSTALL_H */ +#endif /* CLUSTER_PAGE_INSTALL_H */ diff --git a/src/include/cluster/cluster_page_online_plan.h b/src/include/cluster/cluster_page_online_plan.h index 71f74f2829b..dbb07701e1f 100644 --- a/src/include/cluster/cluster_page_online_plan.h +++ b/src/include/cluster/cluster_page_online_plan.h @@ -15,28 +15,25 @@ typedef struct RfPageOnlinePlanV1 RfPageOnlinePlanV1; -typedef struct RfPageOnlinePlanRequestV1 -{ - uint64 system_identifier; - uint8 storage_uuid[16]; +typedef struct RfPageOnlinePlanRequestV1 { + uint64 system_identifier; + uint8 storage_uuid[16]; const RfContributorStreamCutV1 *physical_cuts; - uint32 participant_count; - uint64 retention_binding_cookie; - Size memory_budget; + uint32 participant_count; + uint64 retention_binding_cookie; + Size memory_budget; } RfPageOnlinePlanRequestV1; -typedef struct RfPageOnlineRecordIdentityV1 -{ +typedef struct RfPageOnlineRecordIdentityV1 { RfPageReplayRecordIdentityV1 record; - uint16 participant_index; - uint16 reserved_zero; + uint16 participant_index; + uint16 reserved_zero; } RfPageOnlineRecordIdentityV1; -typedef struct RfPageOnlineTargetViewV1 -{ +typedef struct RfPageOnlineTargetViewV1 { RfPageIdentityV1 page_identity; - uint8 before_kind; - uint8 reserved_zero[7]; + uint8 before_kind; + uint8 reserved_zero[7]; RfPageVersionV1 expected_before; RfPageVersionV1 expected_result; const char *canonical_page; @@ -45,20 +42,16 @@ typedef struct RfPageOnlineTargetViewV1 const RfPageStableGraphRequestV1 *graph; } RfPageOnlineTargetViewV1; -extern RfPageProofDetailV1 rf_page_online_plan_create_v1( - const RfPageOnlinePlanRequestV1 *request, - RfPageOnlinePlanV1 **out_plan); -extern RfPageProofDetailV1 rf_page_online_plan_feed_record_v1( - RfPageOnlinePlanV1 *plan, - const RfDetachedRecordPlanV1 *record_plan, - const RfPageOnlineRecordIdentityV1 *identity); -extern RfPageProofDetailV1 rf_page_online_plan_seal_v1( - RfPageOnlinePlanV1 *plan); -extern uint32 rf_page_online_plan_target_count_v1( - const RfPageOnlinePlanV1 *plan); -extern bool rf_page_online_plan_target_v1( - const RfPageOnlinePlanV1 *plan, uint32 index, - RfPageOnlineTargetViewV1 *out_target); +extern RfPageProofDetailV1 rf_page_online_plan_create_v1(const RfPageOnlinePlanRequestV1 *request, + RfPageOnlinePlanV1 **out_plan); +extern RfPageProofDetailV1 +rf_page_online_plan_feed_record_v1(RfPageOnlinePlanV1 *plan, + const RfDetachedRecordPlanV1 *record_plan, + const RfPageOnlineRecordIdentityV1 *identity); +extern RfPageProofDetailV1 rf_page_online_plan_seal_v1(RfPageOnlinePlanV1 *plan); +extern uint32 rf_page_online_plan_target_count_v1(const RfPageOnlinePlanV1 *plan); +extern bool rf_page_online_plan_target_v1(const RfPageOnlinePlanV1 *plan, uint32 index, + RfPageOnlineTargetViewV1 *out_target); extern void rf_page_online_plan_destroy_v1(RfPageOnlinePlanV1 **plan); -#endif /* CLUSTER_PAGE_ONLINE_PLAN_H */ +#endif /* CLUSTER_PAGE_ONLINE_PLAN_H */ diff --git a/src/include/cluster/cluster_page_producer.h b/src/include/cluster/cluster_page_producer.h index a13879f3a07..daf9b1f6406 100644 --- a/src/include/cluster/cluster_page_producer.h +++ b/src/include/cluster/cluster_page_producer.h @@ -14,16 +14,15 @@ #define CLUSTER_PAGE_PRODUCER_INTERFACE_V1 1 #define RF_PAGE_PRODUCER_MAX_COMPONENTS XLR_PAGE_VERSION_EDGE_MAX_ENTRIES -typedef struct RfPageProducerComponentV1 -{ - uint8 block_id; - uint8 page_class; - uint8 before_kind; - uint8 reserved_zero; - uint16 component_ordinal; - uint16 reserved_zero2; - uint8 segment_incarnation[16]; - Page page; +typedef struct RfPageProducerComponentV1 { + uint8 block_id; + uint8 page_class; + uint8 before_kind; + uint8 reserved_zero; + uint16 component_ordinal; + uint16 reserved_zero2; + uint8 segment_incarnation[16]; + Page page; } RfPageProducerComponentV1; /* @@ -32,24 +31,21 @@ typedef struct RfPageProducerComponentV1 * first revalidates every ordinary page, then installs that token on all of * them before any WAL image/copy may be formed. */ -typedef struct RfPageProducerBatchV1 -{ - uint64 result_token; - uint8 entry_count; - bool prepared; - bool stamped; - Page ordinary_pages[RF_PAGE_PRODUCER_MAX_COMPONENTS]; +typedef struct RfPageProducerBatchV1 { + uint64 result_token; + uint8 entry_count; + bool prepared; + bool stamped; + Page ordinary_pages[RF_PAGE_PRODUCER_MAX_COMPONENTS]; RfPageVersionEdgeEntryV1 entries[RF_PAGE_PRODUCER_MAX_COMPONENTS]; } RfPageProducerBatchV1; extern uint64 rf_page_mutation_token_next(void); extern void rf_page_mutation_token_observe(uint64 token); -extern bool rf_page_producer_prepare_v1( - const RfPageProducerComponentV1 *components, uint8 component_count, - RfPageProducerBatchV1 *batch); +extern bool rf_page_producer_prepare_v1(const RfPageProducerComponentV1 *components, + uint8 component_count, RfPageProducerBatchV1 *batch); extern bool rf_page_producer_stamp_v1(RfPageProducerBatchV1 *batch); -extern bool rf_page_producer_register_wal_v1( - const RfPageProducerBatchV1 *batch); +extern bool rf_page_producer_register_wal_v1(const RfPageProducerBatchV1 *batch); -#endif /* CLUSTER_PAGE_PRODUCER_H */ +#endif /* CLUSTER_PAGE_PRODUCER_H */ diff --git a/src/include/cluster/cluster_page_recovery.h b/src/include/cluster/cluster_page_recovery.h index 3fd3eeaf2da..7f0643d9ca3 100644 --- a/src/include/cluster/cluster_page_recovery.h +++ b/src/include/cluster/cluster_page_recovery.h @@ -52,16 +52,15 @@ * proof requirements which the apply layer (PGDEL-06) must satisfy before * acting — the action table itself never guesses. */ -typedef enum ClusterPageRecoveryAction -{ +typedef enum ClusterPageRecoveryAction { CLUSTER_PAGE_ACTION_APPLY = 0, /* NORMAL/CLEANOUT: versioned delta apply */ - CLUSTER_PAGE_ACTION_INIT, /* NEW: init only under a full-init rule */ - CLUSTER_PAGE_ACTION_INCARNATE, /* INCARNATION: close old set, open new */ - CLUSTER_PAGE_ACTION_DISCARD, /* TEMP: discard/recreate with owner proof */ - CLUSTER_PAGE_ACTION_REBUILD, /* REBUILDABLE/NONLOGGED: rebuild/route */ - CLUSTER_PAGE_ACTION_ROUTE, /* HEADER: route to the typed owner */ - CLUSTER_PAGE_ACTION_IMAGE, /* FULLIMAGE: image payload under provenance */ - CLUSTER_PAGE_ACTION_BLOCKED /* WILLINIT (no rule) / UNKNOWN: mutation=0 */ + CLUSTER_PAGE_ACTION_INIT, /* NEW: init only under a full-init rule */ + CLUSTER_PAGE_ACTION_INCARNATE, /* INCARNATION: close old set, open new */ + CLUSTER_PAGE_ACTION_DISCARD, /* TEMP: discard/recreate with owner proof */ + CLUSTER_PAGE_ACTION_REBUILD, /* REBUILDABLE/NONLOGGED: rebuild/route */ + CLUSTER_PAGE_ACTION_ROUTE, /* HEADER: route to the typed owner */ + CLUSTER_PAGE_ACTION_IMAGE, /* FULLIMAGE: image payload under provenance */ + CLUSTER_PAGE_ACTION_BLOCKED /* WILLINIT (no rule) / UNKNOWN: mutation=0 */ } ClusterPageRecoveryAction; /* @@ -71,8 +70,7 @@ typedef enum ClusterPageRecoveryAction * produced by the PGDEL-04..06 layers that own those proofs (the enum is * defined here once so every layer shares one outcome vocabulary). */ -typedef enum ClusterPageRecoveryOutcome -{ +typedef enum ClusterPageRecoveryOutcome { CLUSTER_PAGE_OUTCOME_APPLY = 0, CLUSTER_PAGE_OUTCOME_SKIP, CLUSTER_PAGE_OUTCOME_BLOCKED_SOURCE, @@ -89,8 +87,7 @@ typedef enum ClusterPageRecoveryOutcome * successor re-enters UNCLASSIFIED (D3′ — predecessor-private progress is * never read as correctness). */ -typedef enum ClusterPageRecoveryState -{ +typedef enum ClusterPageRecoveryState { CLUSTER_PAGE_STATE_UNCLASSIFIED = 0, CLUSTER_PAGE_STATE_CLASSIFIED, CLUSTER_PAGE_STATE_SOURCE_PROVEN, @@ -108,8 +105,7 @@ typedef enum ClusterPageRecoveryState * §4.1 recovery-action column: the closed class -> action table. * UNKNOWN -> BLOCKED (spec: "unknown default 必须 BLOCKED"). */ -extern ClusterPageRecoveryAction cluster_page_class_recovery_action( - ClusterPageClass page_class); +extern ClusterPageRecoveryAction cluster_page_class_recovery_action(ClusterPageClass page_class); /* * §3.5 state machine: advance exactly one adjacent step. Returns true @@ -124,7 +120,7 @@ extern bool cluster_page_state_advance(ClusterPageRecoveryState *state, * The class layer's blocked branch is BLOCKED_CLASS; the finer * subdivisions are the PGDEL-04..06 layers' to emit. */ -extern ClusterPageRecoveryOutcome cluster_page_dispatcher_verdict( - ClusterPageClass page_class, ClusterPageApplyVerdict verdict); +extern ClusterPageRecoveryOutcome cluster_page_dispatcher_verdict(ClusterPageClass page_class, + ClusterPageApplyVerdict verdict); -#endif /* CLUSTER_PAGE_RECOVERY_H */ +#endif /* CLUSTER_PAGE_RECOVERY_H */ diff --git a/src/include/cluster/cluster_page_replay_batch.h b/src/include/cluster/cluster_page_replay_batch.h index 34da1b7e523..9a1cb4c5c24 100644 --- a/src/include/cluster/cluster_page_replay_batch.h +++ b/src/include/cluster/cluster_page_replay_batch.h @@ -13,71 +13,65 @@ #define CLUSTER_PAGE_REPLAY_BATCH_INTERFACE_V1 1 -typedef struct RfPageReplayStepV1 -{ - uint32 record_index; - uint32 component_index; +typedef struct RfPageReplayStepV1 { + uint32 record_index; + uint32 component_index; } RfPageReplayStepV1; -typedef struct RfPageReplayRecordV1 -{ +typedef struct RfPageReplayRecordV1 { const RfDetachedRecordPlanV1 *record_plan; RfPageReplayRecordIdentityV1 identity; - uint16 participant_index; - uint16 reserved_zero; + uint16 participant_index; + uint16 reserved_zero; } RfPageReplayRecordV1; -typedef struct RfPageReplayTargetV1 -{ +typedef struct RfPageReplayTargetV1 { RfPageIdentityV1 page_identity; - uint8 before_kind; - uint8 reserved_zero[7]; + uint8 before_kind; + uint8 reserved_zero[7]; RfPageVersionV1 expected_before; RfPageVersionV1 expected_result; const char *base_page; const RfPageReplayStepV1 *steps; - uint32 step_count; + uint32 step_count; } RfPageReplayTargetV1; -typedef struct RfPageReplayBatchRequestV1 -{ - uint64 system_identifier; - uint8 storage_uuid[16]; +typedef struct RfPageReplayBatchRequestV1 { + uint64 system_identifier; + uint8 storage_uuid[16]; const RfContributorStreamCutV1 *participants; - uint32 participant_count; + uint32 participant_count; const RfPageReplayRecordV1 *records; - uint32 record_count; + uint32 record_count; const RfPageReplayTargetV1 *targets; - uint32 target_count; - uint8 *record_component_seen; - Size record_component_seen_capacity; - char *canonical_pages; - Size canonical_capacity; - char *install_prepared_pages; - Size install_prepared_capacity; - char *install_io_pages; - Size install_io_capacity; + uint32 target_count; + uint8 *record_component_seen; + Size record_component_seen_capacity; + char *canonical_pages; + Size canonical_capacity; + char *install_prepared_pages; + Size install_prepared_capacity; + char *install_io_pages; + Size install_io_capacity; const RfPageInstallStorageOpsV1 *storage; const RfPageInstallAuthorityOpsV1 *authority; - bool global_preflight_ok; + bool global_preflight_ok; } RfPageReplayBatchRequestV1; -typedef struct RfPageReplayBatchProofV1 -{ - uint32 target_count; - uint32 step_count; - bool detached_apply_complete; +typedef struct RfPageReplayBatchProofV1 { + uint32 target_count; + uint32 step_count; + bool detached_apply_complete; RfPageStorageInstallProofV1 install; } RfPageReplayBatchProofV1; -extern RfPageProofDetailV1 rf_page_replay_batch_execute_v1( - const RfPageReplayBatchRequestV1 *request, - RfPageReplayBatchProofV1 *proof); +extern RfPageProofDetailV1 +rf_page_replay_batch_execute_v1(const RfPageReplayBatchRequestV1 *request, + RfPageReplayBatchProofV1 *proof); #ifndef USE_CLUSTER_UNIT -extern RfPageProofDetailV1 rf_page_replay_batch_smgr_v1( - const RfPageReplayBatchRequestV1 *request, - RfPageReplayBatchProofV1 *proof); +extern RfPageProofDetailV1 rf_page_replay_batch_smgr_v1(const RfPageReplayBatchRequestV1 *request, + RfPageReplayBatchProofV1 *proof); #endif -#endif /* CLUSTER_PAGE_REPLAY_BATCH_H */ +#endif /* CLUSTER_PAGE_REPLAY_BATCH_H */ diff --git a/src/include/cluster/cluster_page_rmgr.h b/src/include/cluster/cluster_page_rmgr.h index 4a1242d6c69..1d64f8364be 100644 --- a/src/include/cluster/cluster_page_rmgr.h +++ b/src/include/cluster/cluster_page_rmgr.h @@ -73,16 +73,15 @@ * mutation declaration + VersionToken producer contract * land with the apply chain (PGDEL-03/06). */ -typedef struct ClusterPageRmgrCensusEntry -{ - uint8 rmid; - uint16 opcode; - uint16 opcode_mask; +typedef struct ClusterPageRmgrCensusEntry { + uint8 rmid; + uint16 opcode; + uint16 opcode_mask; ClusterPageClass page_class; - bool affects_page; - bool known_delta; - bool will_init; - bool decoder_registered; + bool affects_page; + bool known_delta; + bool will_init; + bool decoder_registered; } ClusterPageRmgrCensusEntry; /* @@ -111,21 +110,19 @@ extern void cluster_page_rmgr_populate_known_set(void); * expected-before -> result-version edge topology is the apply chain's * contract (PGDEL-03/06). */ -typedef struct ClusterPageRedoHints -{ - SCN record_scn; /* xl_scn from the record header */ - XLogRecPtr record_lsn; /* record EndRecPtr */ - SCN page_scn; /* pd_block_scn of the working page (caller) */ - XLogRecPtr page_lsn; /* pd_lsn of the working page (caller) */ +typedef struct ClusterPageRedoHints { + SCN record_scn; /* xl_scn from the record header */ + XLogRecPtr record_lsn; /* record EndRecPtr */ + SCN page_scn; /* pd_block_scn of the working page (caller) */ + XLogRecPtr page_lsn; /* pd_lsn of the working page (caller) */ } ClusterPageRedoHints; -typedef struct ClusterPageRedoDecoded -{ - ClusterPageClass page_class; /* census row assignment */ +typedef struct ClusterPageRedoDecoded { + ClusterPageClass page_class; /* census row assignment */ ClusterPageIdentity identity; /* from the record block reference */ ClusterPageRedoHints hints; - bool full_image; /* XLR block image present AND applies */ - bool will_init; /* BKPBLOCK_WILL_INIT attribute */ + bool full_image; /* XLR block image present AND applies */ + bool will_init; /* BKPBLOCK_WILL_INIT attribute */ } ClusterPageRedoDecoded; /* @@ -138,4 +135,4 @@ typedef struct ClusterPageRedoDecoded extern bool cluster_page_redo_decode(XLogReaderState *record, uint8 block_id, ClusterPageRedoDecoded *out); -#endif /* CLUSTER_PAGE_RMGR_H */ +#endif /* CLUSTER_PAGE_RMGR_H */ diff --git a/src/include/cluster/cluster_page_set.h b/src/include/cluster/cluster_page_set.h index c15fa808a44..bc8d2206982 100644 --- a/src/include/cluster/cluster_page_set.h +++ b/src/include/cluster/cluster_page_set.h @@ -51,29 +51,27 @@ * exact-equality record identity; `failed_origin_thread` names the * failed-origin duty this change belongs to. */ -typedef struct ClusterPageRedoChange -{ +typedef struct ClusterPageRedoChange { ClusterPageIdentity identity; ClusterPageClass page_class; ClusterPageVersion expected_before; ClusterPageVersion result_version; - uint64 change_identity; /* opaque exact-equality */ - uint16 failed_origin_thread; + uint64 change_identity; /* opaque exact-equality */ + uint16 failed_origin_thread; } ClusterPageRedoChange; /* * §6.1 BlockRecoverySet — the in-memory rebuildable plan for ONE block. */ -typedef struct ClusterBlockRecoverySet -{ - uint16 failed_origin_thread; +typedef struct ClusterBlockRecoverySet { + uint16 failed_origin_thread; ClusterPageIdentity identity; ClusterPageClass page_class; - ClusterPageSourceKind source_kind; /* selected source (PGDEL-04) */ - ClusterPageVersion source_version; /* selected source's version */ - ClusterPageVersion terminal_version; /* required terminal version */ + ClusterPageSourceKind source_kind; /* selected source (PGDEL-04) */ + ClusterPageVersion source_version; /* selected source's version */ + ClusterPageVersion terminal_version; /* required terminal version */ const ClusterPageRedoChange *contributors; /* ordered same-block chain */ - int n_contributors; + int n_contributors; } ClusterBlockRecoverySet; /* @@ -89,13 +87,12 @@ typedef struct ClusterBlockRecoverySet * construction — the closure FAILS on any mismatch instead of * guessing which terminal is right). */ -typedef enum ClusterPageClosureResult -{ +typedef enum ClusterPageClosureResult { CLUSTER_PAGE_CLOSURE_OK = 0, - CLUSTER_PAGE_CLOSURE_GAP, /* missing/unknown/invalid version join */ - CLUSTER_PAGE_CLOSURE_UNKNOWN_CLASS, /* a contributor class is UNKNOWN */ + CLUSTER_PAGE_CLOSURE_GAP, /* missing/unknown/invalid version join */ + CLUSTER_PAGE_CLOSURE_UNKNOWN_CLASS, /* a contributor class is UNKNOWN */ CLUSTER_PAGE_CLOSURE_INCARNATION_CROSS, /* incarnation boundary crossed */ - CLUSTER_PAGE_CLOSURE_THREAD_MISMATCH, /* contributor of another origin */ + CLUSTER_PAGE_CLOSURE_THREAD_MISMATCH, /* contributor of another origin */ CLUSTER_PAGE_CLOSURE_TERMINAL_MISMATCH, /* chain end != terminal */ CLUSTER_PAGE_CLOSURE_INVALID_INPUT } ClusterPageClosureResult; @@ -105,8 +102,8 @@ typedef enum ClusterPageClosureResult * deterministic: the same canonical inputs always produce the same * result (rerun determinism). No mutation, no I/O. */ -extern ClusterPageClosureResult cluster_page_contributor_closure( - const ClusterBlockRecoverySet *set); +extern ClusterPageClosureResult +cluster_page_contributor_closure(const ClusterBlockRecoverySet *set); /* * §3.3 shape-2 trusted skip: true when a contributor chain is closed @@ -115,7 +112,7 @@ extern ClusterPageClosureResult cluster_page_contributor_closure( * an empty chain) is already covered by the closed chain. Only a * closed chain proves coverage: a numeric high-water never does (§3.3). */ -extern bool cluster_page_contributor_chain_covers( - const ClusterBlockRecoverySet *set, const ClusterPageVersion *from_version); +extern bool cluster_page_contributor_chain_covers(const ClusterBlockRecoverySet *set, + const ClusterPageVersion *from_version); -#endif /* CLUSTER_PAGE_SET_H */ +#endif /* CLUSTER_PAGE_SET_H */ diff --git a/src/include/cluster/cluster_page_source.h b/src/include/cluster/cluster_page_source.h index 22e0ab0310c..ffa3854b6f9 100644 --- a/src/include/cluster/cluster_page_source.h +++ b/src/include/cluster/cluster_page_source.h @@ -49,11 +49,10 @@ #include "cluster/cluster_page_version.h" -typedef enum ClusterPageSourceKind -{ +typedef enum ClusterPageSourceKind { CLUSTER_PAGE_SOURCE_CURRENT = 0, /* §5.2 survivor GCS holder */ - CLUSTER_PAGE_SOURCE_PI, /* §5.3 past image */ - CLUSTER_PAGE_SOURCE_STORAGE /* §5.4 checkpointed shared storage */ + CLUSTER_PAGE_SOURCE_PI, /* §5.3 past image */ + CLUSTER_PAGE_SOURCE_STORAGE /* §5.4 checkpointed shared storage */ } ClusterPageSourceKind; /* @@ -63,19 +62,18 @@ typedef enum ClusterPageSourceKind * resource. The boolean facts are exactly what the named production * owner declares; this layer never infers them. */ -typedef struct ClusterPageSourceValidateInput -{ - const ClusterPageIdentity *identity; /* exact expected resource */ +typedef struct ClusterPageSourceValidateInput { + const ClusterPageIdentity *identity; /* exact expected resource */ const ClusterPageVersion *source_version; /* the source's PageVersion */ - bool integrity_ok; /* page-class integrity verifier passed */ - bool stability_ok; /* CURRENT: GCS stability witness; PI: holder stable */ - bool lineage_ok; /* control-root / failure-generation lineage current */ - bool owner_ok; /* source owner present & authoritative */ - bool ship_boundary_ok; /* PI: ship/boundary SCN proof (spec §5.3) */ - bool anchored_ok; /* STORAGE: version anchored to durable checkpoint/root */ - bool coverage_ok; /* STORAGE: FPI/init/FPW + rmgr exceptions handled */ - bool fresh_ok; /* STORAGE: re-verified before mutation (§5.4-7) */ - bool contributors_closed; /* STORAGE: §5.4-5, owned by PGDEL-05 */ + bool integrity_ok; /* page-class integrity verifier passed */ + bool stability_ok; /* CURRENT: GCS stability witness; PI: holder stable */ + bool lineage_ok; /* control-root / failure-generation lineage current */ + bool owner_ok; /* source owner present & authoritative */ + bool ship_boundary_ok; /* PI: ship/boundary SCN proof (spec §5.3) */ + bool anchored_ok; /* STORAGE: version anchored to durable checkpoint/root */ + bool coverage_ok; /* STORAGE: FPI/init/FPW + rmgr exceptions handled */ + bool fresh_ok; /* STORAGE: re-verified before mutation (§5.4-7) */ + bool contributors_closed; /* STORAGE: §5.4-5, owned by PGDEL-05 */ } ClusterPageSourceValidateInput; /* @@ -85,8 +83,7 @@ typedef struct ClusterPageSourceValidateInput * "empty replay set" conclusion needs the §5.2-6 per-block chain, which * is PGDEL-05's — validation here only admits the source. */ -extern bool cluster_page_source_validate_current( - const ClusterPageSourceValidateInput *in); +extern bool cluster_page_source_validate_current(const ClusterPageSourceValidateInput *in); /* * §5.3 PI conjunction: exact identity + valid version + integrity + @@ -94,8 +91,7 @@ extern bool cluster_page_source_validate_current( * failure the PI is discarded: its bytes must never be smuggled into the * STORAGE branch, and a PI miss is never written as "page recovered". */ -extern bool cluster_page_source_validate_pi( - const ClusterPageSourceValidateInput *in); +extern bool cluster_page_source_validate_pi(const ClusterPageSourceValidateInput *in); /* * §5.4 STORAGE conjunction: exact identity + valid version + integrity + @@ -105,8 +101,7 @@ extern bool cluster_page_source_validate_pi( * honestly closed, and retained failed-origin redo is never a base * (spec §5.4 last paragraph). */ -extern bool cluster_page_source_validate_storage( - const ClusterPageSourceValidateInput *in); +extern bool cluster_page_source_validate_storage(const ClusterPageSourceValidateInput *in); /* * §5.5/§6.2 selection: returns the chosen input index, or -1 (BLOCKED). @@ -119,7 +114,6 @@ extern bool cluster_page_source_validate_storage( * `kinds` array (inputs do not carry their own kind). */ extern int cluster_page_source_select(const ClusterPageSourceKind *kinds, - const ClusterPageSourceValidateInput *inputs, - int n); + const ClusterPageSourceValidateInput *inputs, int n); -#endif /* CLUSTER_PAGE_SOURCE_H */ +#endif /* CLUSTER_PAGE_SOURCE_H */ diff --git a/src/include/cluster/cluster_page_stable_base.h b/src/include/cluster/cluster_page_stable_base.h index 5d6022d3871..99c7dbfc105 100644 --- a/src/include/cluster/cluster_page_stable_base.h +++ b/src/include/cluster/cluster_page_stable_base.h @@ -18,67 +18,58 @@ #define RF_PAGE_STABLE_MAX_EDGES 65536 #define RF_PAGE_STABLE_MAX_COMPONENTS 33 -typedef struct RfPageIdentityV1 -{ - uint64 system_identifier; - uint8 storage_uuid[16]; +typedef struct RfPageIdentityV1 { + uint64 system_identifier; + uint8 storage_uuid[16]; RelFileLocator locator; - uint32 forknum; + uint32 forknum; BlockNumber blockno; - uint32 reserved_zero; + uint32 reserved_zero; } RfPageIdentityV1; -StaticAssertDecl(sizeof(RfPageIdentityV1) == 48, - "RfPageIdentityV1 ABI drift"); +StaticAssertDecl(sizeof(RfPageIdentityV1) == 48, "RfPageIdentityV1 ABI drift"); StaticAssertDecl(offsetof(RfPageIdentityV1, storage_uuid) == 8, "RfPageIdentityV1 storage UUID offset drift"); StaticAssertDecl(offsetof(RfPageIdentityV1, locator) == 24, "RfPageIdentityV1 locator offset drift"); -StaticAssertDecl(offsetof(RfPageIdentityV1, forknum) == 36, - "RfPageIdentityV1 fork offset drift"); -StaticAssertDecl(offsetof(RfPageIdentityV1, blockno) == 40, - "RfPageIdentityV1 block offset drift"); +StaticAssertDecl(offsetof(RfPageIdentityV1, forknum) == 36, "RfPageIdentityV1 fork offset drift"); +StaticAssertDecl(offsetof(RfPageIdentityV1, blockno) == 40, "RfPageIdentityV1 block offset drift"); #define RF_CONTRIBUTOR_CUT_COMPLETE UINT16_C(0x0001) #define RF_CONTRIBUTOR_CUT_EXPLICIT_EMPTY UINT16_C(0x0002) #define RF_CONTRIBUTOR_CUT_KNOWN_MASK UINT16_C(0x0003) -typedef struct RfContributorStreamCutV1 -{ - uint16 failed_thread; - uint16 flags; +typedef struct RfContributorStreamCutV1 { + uint16 failed_thread; + uint16 flags; TimeLineID timeline_id; XLogRecPtr scan_begin_inclusive; XLogRecPtr scan_end_exclusive; - uint32 contributor_count; - uint32 component_count; + uint32 contributor_count; + uint32 component_count; } RfContributorStreamCutV1; -StaticAssertDecl(sizeof(RfContributorStreamCutV1) == 32, - "RfContributorStreamCutV1 ABI drift"); +StaticAssertDecl(sizeof(RfContributorStreamCutV1) == 32, "RfContributorStreamCutV1 ABI drift"); StaticAssertDecl(offsetof(RfContributorStreamCutV1, timeline_id) == 4, "RfContributorStreamCutV1 timeline offset drift"); -StaticAssertDecl(offsetof(RfContributorStreamCutV1, - scan_begin_inclusive) == 8, +StaticAssertDecl(offsetof(RfContributorStreamCutV1, scan_begin_inclusive) == 8, "RfContributorStreamCutV1 begin offset drift"); -StaticAssertDecl(offsetof(RfContributorStreamCutV1, - contributor_count) == 24, +StaticAssertDecl(offsetof(RfContributorStreamCutV1, contributor_count) == 24, "RfContributorStreamCutV1 count offset drift"); /* Exact immutable identity of one decoded foreign WAL record. */ -typedef struct RfPageReplayRecordIdentityV1 -{ - uint64 system_identifier; - uint8 storage_uuid[16]; - uint16 origin_thread; - uint16 reserved_zero; +typedef struct RfPageReplayRecordIdentityV1 { + uint64 system_identifier; + uint8 storage_uuid[16]; + uint16 origin_thread; + uint16 reserved_zero; TimeLineID timeline_id; XLogRecPtr read_rec_ptr; XLogRecPtr end_rec_ptr; - uint32 record_crc; - uint8 rmid; - uint8 info; - uint16 reserved_zero2; + uint32 record_crc; + uint8 rmid; + uint8 info; + uint16 reserved_zero2; } RfPageReplayRecordIdentityV1; StaticAssertDecl(sizeof(RfPageReplayRecordIdentityV1) == 56, @@ -90,8 +81,7 @@ StaticAssertDecl(offsetof(RfPageReplayRecordIdentityV1, read_rec_ptr) == 32, StaticAssertDecl(offsetof(RfPageReplayRecordIdentityV1, record_crc) == 48, "RfPageReplayRecordIdentityV1 CRC offset drift"); -typedef enum RfPageProofDetailV1 -{ +typedef enum RfPageProofDetailV1 { RF_PAGE_PROOF_DETAIL_OK = 0, RF_PAGE_PROOF_DETAIL_INVALID_ARGUMENT = 1, RF_PAGE_PROOF_DETAIL_ROOT_STALE = 2, @@ -125,75 +115,68 @@ typedef enum RfPageProofDetailV1 } RfPageProofDetailV1; /* Immutable decoder output projected onto one ordinary target page. */ -typedef struct RfPageStableEdgeInputV1 -{ +typedef struct RfPageStableEdgeInputV1 { RfPageIdentityV1 page_identity; RfPageVersionEdgeEntryV1 edge; - uint64 result_token; + uint64 result_token; RfPageReplayRecordIdentityV1 record_identity; - uint16 participant_index; - uint16 component_count; - uint8 anchor_digest[32]; - bool record_complete; - bool opcode_supported; - bool side_complete; - bool image_integrity_ok; + uint16 participant_index; + uint16 component_count; + uint8 anchor_digest[32]; + bool record_complete; + bool opcode_supported; + bool side_complete; + bool image_integrity_ok; } RfPageStableEdgeInputV1; /* Caller-owned RF-SIDE view. It owns neither WAL nor authority. */ -typedef struct RfContributorVectorV1 -{ - uint64 system_identifier; - uint8 storage_uuid[16]; - uint32 participant_count; - uint32 edge_count; +typedef struct RfContributorVectorV1 { + uint64 system_identifier; + uint8 storage_uuid[16]; + uint32 participant_count; + uint32 edge_count; const RfContributorStreamCutV1 *cuts; const RfPageStableEdgeInputV1 *edges; } RfContributorVectorV1; -typedef struct RfPagePinnedSourceV1 -{ +typedef struct RfPagePinnedSourceV1 { RfPageIdentityV1 page_identity; RfPageVersionV1 source_version; - uint64 binding_cookie; - uint64 current_binding_cookie; - bool identity_verified; - bool integrity_verified; + uint64 binding_cookie; + uint64 current_binding_cookie; + bool identity_verified; + bool integrity_verified; } RfPagePinnedSourceV1; -typedef struct RfPageStableGraphRequestV1 -{ +typedef struct RfPageStableGraphRequestV1 { RfPageIdentityV1 page_identity; RfPageVersionV1 expected_result; const RfContributorVectorV1 *contributors; const RfPagePinnedSourceV1 *source; - uint32 participant_count; - uint32 flags; - uint64 retention_binding_cookie; - uint64 current_retention_binding_cookie; - bool root_current; - bool duty_current; - bool fence_current; - bool retention_current; + uint32 participant_count; + uint32 flags; + uint64 retention_binding_cookie; + uint64 current_retention_binding_cookie; + bool root_current; + bool duty_current; + bool fence_current; + bool retention_current; } RfPageStableGraphRequestV1; -typedef struct RfPageStableSelectionV1 -{ +typedef struct RfPageStableSelectionV1 { RfPageVersionV1 terminal_version; - uint32 anchor_edge_index; - uint32 chain_length; - bool result_already_present; + uint32 anchor_edge_index; + uint32 chain_length; + bool result_already_present; } RfPageStableSelectionV1; -typedef struct PgracExternalFenceAdmissionSetV1 - PgracExternalFenceAdmissionSetV1; +typedef struct PgracExternalFenceAdmissionSetV1 PgracExternalFenceAdmissionSetV1; typedef struct PgracExternalFenceNeedSetV1 PgracExternalFenceNeedSetV1; typedef struct ClusterFormationWitnessV1 ClusterFormationWitnessV1; typedef struct ClusterWalRetentionPin ClusterWalRetentionPin; typedef struct RfPageStableBaseProofV1 RfPageStableBaseProofV1; -typedef struct RfPageStableBaseProofRequestV1 -{ +typedef struct RfPageStableBaseProofRequestV1 { const RfPageStableGraphRequestV1 *graph; const ClusterRecoveryDutyKey *duties; const ClusterControlRootReadToken *root_tokens; @@ -201,12 +184,11 @@ typedef struct RfPageStableBaseProofRequestV1 const PgracExternalFenceNeedSetV1 *fence_need_set; const PgracExternalFenceAdmissionSetV1 *fence_admission_set; ClusterWalRetentionPin *retention_pin; - uint32 flags; + uint32 flags; } RfPageStableBaseProofRequestV1; extern bool rf_page_identity_valid_v1(const RfPageIdentityV1 *identity); -extern bool rf_page_identity_equal_v1(const RfPageIdentityV1 *left, - const RfPageIdentityV1 *right); +extern bool rf_page_identity_equal_v1(const RfPageIdentityV1 *left, const RfPageIdentityV1 *right); extern bool rf_page_version_present_v1(const RfPageVersionV1 *version); /* @@ -214,94 +196,82 @@ extern bool rf_page_version_present_v1(const RfPageVersionV1 *version); * caller-owned workspace and receives anchor-to-terminal edge indices only on * success. Every failure leaves both output objects untouched. */ -extern RfPageProofDetailV1 rf_page_stable_base_select_v1( - const RfPageStableGraphRequestV1 *request, - uint32 *chain_indices, uint32 chain_capacity, - RfPageStableSelectionV1 *selection); -extern RfPageProofDetailV1 rf_page_stable_base_proof_build_wait_v1( - const RfPageStableBaseProofRequestV1 *request, - uint32 *chain_indices, uint32 chain_capacity, int timeout_ms, - RfPageStableBaseProofV1 **out_proof); -extern RfPageProofDetailV1 rf_page_stable_base_proof_build_bound_v1( - const RfPageStableBaseProofRequestV1 *request, - uint32 *chain_indices, uint32 chain_capacity, - RfPageStableBaseProofV1 **out_proof); +extern RfPageProofDetailV1 rf_page_stable_base_select_v1(const RfPageStableGraphRequestV1 *request, + uint32 *chain_indices, + uint32 chain_capacity, + RfPageStableSelectionV1 *selection); +extern RfPageProofDetailV1 +rf_page_stable_base_proof_build_wait_v1(const RfPageStableBaseProofRequestV1 *request, + uint32 *chain_indices, uint32 chain_capacity, + int timeout_ms, RfPageStableBaseProofV1 **out_proof); +extern RfPageProofDetailV1 +rf_page_stable_base_proof_build_bound_v1(const RfPageStableBaseProofRequestV1 *request, + uint32 *chain_indices, uint32 chain_capacity, + RfPageStableBaseProofV1 **out_proof); extern bool rf_page_stable_base_proof_matches_v1( - const RfPageStableBaseProofV1 *proof, - const RfPageIdentityV1 *page_identity, - const RfPageVersionV1 *expected_result, - const ClusterRecoveryDutyKey *duties, - const ClusterControlRootReadToken *root_tokens, - const ClusterFormationWitnessV1 *formation, + const RfPageStableBaseProofV1 *proof, const RfPageIdentityV1 *page_identity, + const RfPageVersionV1 *expected_result, const ClusterRecoveryDutyKey *duties, + const ClusterControlRootReadToken *root_tokens, const ClusterFormationWitnessV1 *formation, const PgracExternalFenceNeedSetV1 *fence_need_set, const PgracExternalFenceAdmissionSetV1 *fence_admission_set, - ClusterWalRetentionPin *retention_pin, - const RfPagePinnedSourceV1 *source, - const RfContributorVectorV1 *contributors, - uint32 participant_count); -extern void rf_page_stable_base_proof_destroy_v1( - RfPageStableBaseProofV1 **proof); + ClusterWalRetentionPin *retention_pin, const RfPagePinnedSourceV1 *source, + const RfContributorVectorV1 *contributors, uint32 participant_count); +extern void rf_page_stable_base_proof_destroy_v1(RfPageStableBaseProofV1 **proof); #ifdef USE_CLUSTER_UNIT -typedef enum RfPageInstallTargetStateV1 -{ +typedef enum RfPageInstallTargetStateV1 { RF_PAGE_INSTALL_TARGET_EXPECTED = 1, RF_PAGE_INSTALL_TARGET_RESULT = 2, RF_PAGE_INSTALL_TARGET_TORN = 3, RF_PAGE_INSTALL_TARGET_UNRELATED = 4 } RfPageInstallTargetStateV1; -typedef struct RfPageInstallComponentV1 -{ +typedef struct RfPageInstallComponentV1 { RfPageIdentityV1 page_identity; RfPageVersionV1 expected_before; RfPageVersionV1 expected_result; const char *canonical_page; - uint8 target_state; - bool route_preflight_ok; - bool side_preflight_ok; - bool scratch_ready; - bool identity_authority_ok; - bool canonical_layout_ok; - bool checksums_enabled; + uint8 target_state; + bool route_preflight_ok; + bool side_preflight_ok; + bool scratch_ready; + bool identity_authority_ok; + bool canonical_layout_ok; + bool checksums_enabled; } RfPageInstallComponentV1; -typedef struct RfPageInstallOpsV1 -{ - void *arg; - bool (*canonicalize) (void *arg, uint32 index, - bool checksums_enabled, char page[BLCKSZ]); - bool (*promote) (void *arg); - bool (*write) (void *arg, uint32 index, const char page[BLCKSZ]); - bool (*sync) (void *arg, uint32 index); - bool (*postread) (void *arg, uint32 index, char page[BLCKSZ]); - bool (*publish) (void *arg); - bool (*release) (void *arg); +typedef struct RfPageInstallOpsV1 { + void *arg; + bool (*canonicalize)(void *arg, uint32 index, bool checksums_enabled, char page[BLCKSZ]); + bool (*promote)(void *arg); + bool (*write)(void *arg, uint32 index, const char page[BLCKSZ]); + bool (*sync)(void *arg, uint32 index); + bool (*postread)(void *arg, uint32 index, char page[BLCKSZ]); + bool (*publish)(void *arg); + bool (*release)(void *arg); } RfPageInstallOpsV1; -typedef struct RfPageInstallRequestV1 -{ +typedef struct RfPageInstallRequestV1 { const RfPageInstallComponentV1 *components; - uint32 component_count; - char *prepared_pages; - Size prepared_capacity; + uint32 component_count; + char *prepared_pages; + Size prepared_capacity; const RfPageInstallOpsV1 *ops; - bool global_preflight_ok; + bool global_preflight_ok; } RfPageInstallRequestV1; -typedef struct RfPageInstallProofV1 -{ - uint32 component_count; - bool durability_complete; - bool postread_complete; - bool proof_published; - bool authority_released; +typedef struct RfPageInstallProofV1 { + uint32 component_count; + bool durability_complete; + bool postread_complete; + bool proof_published; + bool authority_released; } RfPageInstallProofV1; -extern RfPageProofDetailV1 rf_page_stable_install_test_v1( - const RfPageInstallRequestV1 *request, RfPageInstallProofV1 *proof); +extern RfPageProofDetailV1 rf_page_stable_install_test_v1(const RfPageInstallRequestV1 *request, + RfPageInstallProofV1 *proof); -#endif /* USE_CLUSTER_UNIT */ +#endif /* USE_CLUSTER_UNIT */ -#endif /* CLUSTER_PAGE_STABLE_BASE_H */ +#endif /* CLUSTER_PAGE_STABLE_BASE_H */ diff --git a/src/include/cluster/cluster_page_stats.h b/src/include/cluster/cluster_page_stats.h index 374076b8b1f..9969a0a09da 100644 --- a/src/include/cluster/cluster_page_stats.h +++ b/src/include/cluster/cluster_page_stats.h @@ -41,11 +41,10 @@ #include "port/atomics.h" #include "cluster/cluster_page_apply.h" -typedef enum ClusterPageStatKind -{ - CLUSTER_PAGE_STAT_EVENT = 0, /* 一次发生(计数) */ - CLUSTER_PAGE_STAT_GAUGE, /* 当前值(可设可读) */ - CLUSTER_PAGE_STAT_TIMESTAMP /* 最近一次发生时刻(uint64 us) */ +typedef enum ClusterPageStatKind { + CLUSTER_PAGE_STAT_EVENT = 0, /* 一次发生(计数) */ + CLUSTER_PAGE_STAT_GAUGE, /* 当前值(可设可读) */ + CLUSTER_PAGE_STAT_TIMESTAMP /* 最近一次发生时刻(uint64 us) */ } ClusterPageStatKind; /* @@ -53,34 +52,33 @@ typedef enum ClusterPageStatKind * producer function below (G4′). Timestamps use GetCurrentTimestamp() * microsecond values; latency measurement is the consumer's subtraction. */ -typedef struct ClusterPageRecoveryStats -{ +typedef struct ClusterPageRecoveryStats { /* ---- EVENTS ---- */ - pg_atomic_uint64 source_selected_current; /* §9.1-1 CURRENT */ - pg_atomic_uint64 source_selected_pi; /* §9.1-1 PI */ - pg_atomic_uint64 source_selected_storage; /* §9.1-1 STORAGE */ - pg_atomic_uint64 source_invalid; /* §9.1-2 invalid by reason */ - pg_atomic_uint64 source_missing; /* §9.1-2 missing */ - pg_atomic_uint64 source_conflict; /* §9.1-2 conflict */ - pg_atomic_uint64 result_skip; /* §9.1-3 */ - pg_atomic_uint64 apply_count; /* §9.1-4 expected-before apply */ - pg_atomic_uint64 version_mismatch; /* §9.1-4 mismatch */ - pg_atomic_uint64 unknown_class_blocked; /* §9.1-5 */ - pg_atomic_uint64 authority_stale_rejected; /* §9.1-8 */ - pg_atomic_uint64 resource_early_release; /* §9.1-9 (bug signal) */ - pg_atomic_uint64 retire_denied; /* §9.1-10 PL-12 */ - pg_atomic_uint64 d3_rebuild; /* §9.1-11 */ - pg_atomic_uint64 d3_optimization_hit; /* §9.1-11 */ - pg_atomic_uint64 stable_base_unresolved; /* §9.1-12 */ + pg_atomic_uint64 source_selected_current; /* §9.1-1 CURRENT */ + pg_atomic_uint64 source_selected_pi; /* §9.1-1 PI */ + pg_atomic_uint64 source_selected_storage; /* §9.1-1 STORAGE */ + pg_atomic_uint64 source_invalid; /* §9.1-2 invalid by reason */ + pg_atomic_uint64 source_missing; /* §9.1-2 missing */ + pg_atomic_uint64 source_conflict; /* §9.1-2 conflict */ + pg_atomic_uint64 result_skip; /* §9.1-3 */ + pg_atomic_uint64 apply_count; /* §9.1-4 expected-before apply */ + pg_atomic_uint64 version_mismatch; /* §9.1-4 mismatch */ + pg_atomic_uint64 unknown_class_blocked; /* §9.1-5 */ + pg_atomic_uint64 authority_stale_rejected; /* §9.1-8 */ + pg_atomic_uint64 resource_early_release; /* §9.1-9 (bug signal) */ + pg_atomic_uint64 retire_denied; /* §9.1-10 PL-12 */ + pg_atomic_uint64 d3_rebuild; /* §9.1-11 */ + pg_atomic_uint64 d3_optimization_hit; /* §9.1-11 */ + pg_atomic_uint64 stable_base_unresolved; /* §9.1-12 */ /* ---- GAUGES ---- */ - pg_atomic_uint64 contributor_records; /* §9.1-6 */ - pg_atomic_uint64 contributor_threads; /* §9.1-6 */ - pg_atomic_uint64 contributor_gaps; /* §9.1-6 */ - pg_atomic_uint64 retained_pinned_bytes; /* §9.1-10 */ + pg_atomic_uint64 contributor_records; /* §9.1-6 */ + pg_atomic_uint64 contributor_threads; /* §9.1-6 */ + pg_atomic_uint64 contributor_gaps; /* §9.1-6 */ + pg_atomic_uint64 retained_pinned_bytes; /* §9.1-10 */ /* ---- TIMESTAMPS (last occurrence, us) ---- */ - pg_atomic_uint64 last_page_write_ts; /* §9.1-7 */ - pg_atomic_uint64 last_durability_barrier_ts; /* §9.1-7 */ - pg_atomic_uint64 last_post_read_ts; /* §9.1-7 */ + pg_atomic_uint64 last_page_write_ts; /* §9.1-7 */ + pg_atomic_uint64 last_durability_barrier_ts; /* §9.1-7 */ + pg_atomic_uint64 last_post_read_ts; /* §9.1-7 */ } ClusterPageRecoveryStats; extern void cluster_page_stats_init(ClusterPageRecoveryStats *stats); @@ -98,16 +96,13 @@ extern void cluster_page_stats_unknown_class_blocked(ClusterPageRecoveryStats *s extern void cluster_page_stats_authority_stale(ClusterPageRecoveryStats *stats); extern void cluster_page_stats_early_release(ClusterPageRecoveryStats *stats); extern void cluster_page_stats_retire_denied(ClusterPageRecoveryStats *stats); -extern void cluster_page_stats_d3_rebuild(ClusterPageRecoveryStats *stats, - bool optimization_hit); +extern void cluster_page_stats_d3_rebuild(ClusterPageRecoveryStats *stats, bool optimization_hit); extern void cluster_page_stats_stable_base_unresolved(ClusterPageRecoveryStats *stats); /* GAUGE producers. */ -extern void cluster_page_stats_contributors(ClusterPageRecoveryStats *stats, - uint64 records, uint64 threads, - uint64 gaps); -extern void cluster_page_stats_pinned_bytes(ClusterPageRecoveryStats *stats, - uint64 bytes); +extern void cluster_page_stats_contributors(ClusterPageRecoveryStats *stats, uint64 records, + uint64 threads, uint64 gaps); +extern void cluster_page_stats_pinned_bytes(ClusterPageRecoveryStats *stats, uint64 bytes); /* TIMESTAMP producers. */ extern void cluster_page_stats_note_page_write(ClusterPageRecoveryStats *stats); @@ -129,27 +124,25 @@ extern bool cluster_page_stats_describe(const char *name, ClusterPageStatKind *k * returns the number of chars that WOULD have been written (snprintf * semantics) so the caller can size the buffer. */ -typedef struct ClusterPageAttemptDump -{ - uint16 failed_origin_thread; - uint64 failure_generation; +typedef struct ClusterPageAttemptDump { + uint16 failed_origin_thread; + uint64 failure_generation; ClusterPageIdentity identity; ClusterPageClass page_class; ClusterPageSourceKind source_kind; ClusterPageVersion source_version; ClusterPageVersion terminal_version; - uint64 contributor_count; - uint64 contributor_thread_set; - bool applied; /* apply 或 skip 结论 */ - bool version_mismatch; - bool durability_ok; - bool post_read_ok; - bool authority_revalidated; - bool released; - const char *stop_reason; /* NULL = no STOP */ + uint64 contributor_count; + uint64 contributor_thread_set; + bool applied; /* apply 或 skip 结论 */ + bool version_mismatch; + bool durability_ok; + bool post_read_ok; + bool authority_revalidated; + bool released; + const char *stop_reason; /* NULL = no STOP */ } ClusterPageAttemptDump; -extern int cluster_page_attempt_dump(const ClusterPageAttemptDump *dump, - char *buf, Size buflen); +extern int cluster_page_attempt_dump(const ClusterPageAttemptDump *dump, char *buf, Size buflen); -#endif /* CLUSTER_PAGE_STATS_H */ +#endif /* CLUSTER_PAGE_STATS_H */ diff --git a/src/include/cluster/cluster_page_version.h b/src/include/cluster/cluster_page_version.h index 5b20fd90a9e..5ef71e223e2 100644 --- a/src/include/cluster/cluster_page_version.h +++ b/src/include/cluster/cluster_page_version.h @@ -62,15 +62,13 @@ typedef uint64 ClusterPageIncarnation; typedef uint64 ClusterVersionToken; /* exact shared-storage database identity + physical relation/fork/block. */ -typedef struct ClusterPageIdentity -{ +typedef struct ClusterPageIdentity { RelFileLocator rlocator; - ForkNumber forknum; + ForkNumber forknum; BlockNumber blocknum; } ClusterPageIdentity; -typedef struct ClusterPageVersion -{ +typedef struct ClusterPageVersion { ClusterPageIdentity identity; ClusterPageIncarnation incarnation; /* 0 = invalid */ ClusterVersionToken token; /* 0 = invalid */ @@ -79,8 +77,7 @@ typedef struct ClusterPageVersion /* §3.4: expected_before is "PageVersion-or-explicit-class-state". The one * explicit class state defined here is UNFORMATTED (PC-NEW before-state): * typed, never a numeric sentinel (spec §3.1, §4.3). */ -typedef struct ClusterPageBeforeState -{ +typedef struct ClusterPageBeforeState { ClusterPageIdentity identity; ClusterPageIncarnation new_incarnation; /* 0 = invalid */ } ClusterPageBeforeState; @@ -92,11 +89,10 @@ typedef struct ClusterPageBeforeState * Any invalid input fails closed to BLOCKED — InvalidScn containment is * BLOCKED, never a version success (spec §10.1 PU-01). */ -typedef enum ClusterPageApplyVerdict -{ - CLUSTER_PAGE_APPLY_APPLY = 0, /* current == expected_before, result valid */ - CLUSTER_PAGE_APPLY_SKIP, /* trusted source == result (shape 1) */ - CLUSTER_PAGE_APPLY_BLOCKED /* anything else: fail closed */ +typedef enum ClusterPageApplyVerdict { + CLUSTER_PAGE_APPLY_APPLY = 0, /* current == expected_before, result valid */ + CLUSTER_PAGE_APPLY_SKIP, /* trusted source == result (shape 1) */ + CLUSTER_PAGE_APPLY_BLOCKED /* anything else: fail closed */ } ClusterPageApplyVerdict; /* @@ -105,8 +101,7 @@ typedef enum ClusterPageApplyVerdict * unknown fork-header / ambiguous lifecycle classify UNKNOWN (BLOCKED). * Class names track the spec table rows (PC-NORMAL .. PC-UNKNOWN). */ -typedef enum ClusterPageClass -{ +typedef enum ClusterPageClass { CLUSTER_PAGE_CLASS_UNCLASSIFIED = 0, /* state-machine start (spec §3.5) */ CLUSTER_PAGE_CLASS_NORMAL, /* PC-NORMAL */ CLUSTER_PAGE_CLASS_NEW, /* PC-NEW */ @@ -124,11 +119,10 @@ typedef enum ClusterPageClass /* §4.5: header pages route to an exact typed owner. NONE means the caller * declares no typed owner — a header-class page without an owner is never * auto-inferred (that would be a guess, and guesses are UNKNOWN). */ -typedef enum ClusterPageHeaderOwner -{ +typedef enum ClusterPageHeaderOwner { CLUSTER_PAGE_HEADER_OWNER_NONE = 0, - CLUSTER_PAGE_HEADER_OWNER_ROOT, /* RF-ROOT typed owner */ - CLUSTER_PAGE_HEADER_OWNER_SIDE, /* RF-SIDE typed owner */ + CLUSTER_PAGE_HEADER_OWNER_ROOT, /* RF-ROOT typed owner */ + CLUSTER_PAGE_HEADER_OWNER_SIDE, /* RF-SIDE typed owner */ CLUSTER_PAGE_HEADER_OWNER_PG_CORE /* PG core typed owner */ } ClusterPageHeaderOwner; @@ -139,18 +133,17 @@ typedef enum ClusterPageHeaderOwner * exact caller-declared facts — the classifier never infers them from * names, paths, counters or digests (spec §5.1). */ -typedef struct ClusterPageClassifyInput -{ - uint8 rmid; - uint16 opcode; - bool has_full_page_image; /* XLR_FULL_PAGE_WRITE / FPI payload */ - bool has_will_init; /* WILL_INIT record attribute */ - ForkNumber forknum; - bool relation_is_temp; /* temp/session-local relation scope */ - bool relation_is_unlogged; /* nonlogged relation (no WAL coverage) */ - bool page_absent; /* relation/file absent or block beyond EOF */ - bool page_is_new; /* PageIsNew: all-zero/uninitialized page */ - bool is_cleanout; /* delayed cleanout metadata normalization */ +typedef struct ClusterPageClassifyInput { + uint8 rmid; + uint16 opcode; + bool has_full_page_image; /* XLR_FULL_PAGE_WRITE / FPI payload */ + bool has_will_init; /* WILL_INIT record attribute */ + ForkNumber forknum; + bool relation_is_temp; /* temp/session-local relation scope */ + bool relation_is_unlogged; /* nonlogged relation (no WAL coverage) */ + bool page_absent; /* relation/file absent or block beyond EOF */ + bool page_is_new; /* PageIsNew: all-zero/uninitialized page */ + bool is_cleanout; /* delayed cleanout metadata normalization */ ClusterPageHeaderOwner header_owner; /* typed owner declaration */ } ClusterPageClassifyInput; @@ -158,11 +151,9 @@ typedef struct ClusterPageClassifyInput * Identity / version helpers. */ extern bool cluster_page_identity_valid(const ClusterPageIdentity *identity); -extern bool cluster_page_identity_equal(const ClusterPageIdentity *a, - const ClusterPageIdentity *b); +extern bool cluster_page_identity_equal(const ClusterPageIdentity *a, const ClusterPageIdentity *b); extern bool cluster_page_version_valid(const ClusterPageVersion *version); -extern bool cluster_page_version_equal(const ClusterPageVersion *a, - const ClusterPageVersion *b); +extern bool cluster_page_version_equal(const ClusterPageVersion *a, const ClusterPageVersion *b); extern bool cluster_page_before_state_valid(const ClusterPageBeforeState *state); extern bool cluster_page_before_state_equal(const ClusterPageBeforeState *a, const ClusterPageBeforeState *b); @@ -176,10 +167,8 @@ extern bool cluster_page_before_state_equal(const ClusterPageBeforeState *a, * §3.3 shape-2 contributor-chain skip belongs to PGDEL-05). */ extern ClusterPageApplyVerdict cluster_page_version_decide( - const ClusterPageVersion *current_working, - const ClusterPageVersion *expected_before, - const ClusterPageVersion *result_version, - const ClusterPageVersion *trusted_source_version); + const ClusterPageVersion *current_working, const ClusterPageVersion *expected_before, + const ClusterPageVersion *result_version, const ClusterPageVersion *trusted_source_version); /* * §4.1 closed classifier. Returns exactly one class; UNKNOWN means the @@ -200,4 +189,4 @@ extern ClusterPageClass cluster_page_classify(const ClusterPageClassifyInput *in extern bool cluster_page_class_register_known_opcode(uint8 rmid, uint16 opcode); extern bool cluster_page_class_is_known_opcode(uint8 rmid, uint16 opcode); -#endif /* CLUSTER_PAGE_VERSION_H */ +#endif /* CLUSTER_PAGE_VERSION_H */ diff --git a/src/include/cluster/cluster_pcm_direct_init.h b/src/include/cluster/cluster_pcm_direct_init.h index 8399a672f67..8ee0f5f8983 100644 --- a/src/include/cluster/cluster_pcm_direct_init.h +++ b/src/include/cluster/cluster_pcm_direct_init.h @@ -57,18 +57,15 @@ cluster_pcm_direct_init_proof_consume(ClusterPcmDirectInitKind kind, const ClusterPcmDirectInitSnapshot *snapshot, ClusterPcmDirectInitProof *proof); extern ClusterPcmOwnResult -cluster_pcm_direct_init_aux_pending_observer_validate( - ClusterPcmDirectInitKind kind, - const ClusterPcmDirectInitSnapshot *snapshot); +cluster_pcm_direct_init_aux_pending_observer_validate(ClusterPcmDirectInitKind kind, + const ClusterPcmDirectInitSnapshot *snapshot); extern ClusterPcmOwnResult -cluster_pcm_direct_init_target_pending_validate( - ClusterPcmDirectInitKind kind, - const ClusterPcmDirectInitSnapshot *pending, - const ClusterPcmDirectInitProof *consumed_proof); +cluster_pcm_direct_init_target_pending_validate(ClusterPcmDirectInitKind kind, + const ClusterPcmDirectInitSnapshot *pending, + const ClusterPcmDirectInitProof *consumed_proof); extern ClusterPcmOwnResult -cluster_pcm_direct_init_target_commit_validate( - ClusterPcmDirectInitKind kind, - const ClusterPcmDirectInitSnapshot *committed, - const ClusterPcmDirectInitProof *consumed_proof); +cluster_pcm_direct_init_target_commit_validate(ClusterPcmDirectInitKind kind, + const ClusterPcmDirectInitSnapshot *committed, + const ClusterPcmDirectInitProof *consumed_proof); #endif /* CLUSTER_PCM_DIRECT_INIT_H */ diff --git a/src/include/cluster/cluster_pcm_lock.h b/src/include/cluster/cluster_pcm_lock.h index d6884f283df..962284441dc 100644 --- a/src/include/cluster/cluster_pcm_lock.h +++ b/src/include/cluster/cluster_pcm_lock.h @@ -56,8 +56,8 @@ #include "cluster/cluster_grd.h" /* ClusterGrdHolderId */ #include "cluster/cluster_resource_x_identity.h" #include "cluster/cluster_resource_x_node_wire.h" -#include "cluster/cluster_scn.h" /* spec-2.41 D2 — SCN dual watermark */ -#include "storage/buf_internals.h" /* BufferTag */ +#include "cluster/cluster_scn.h" /* spec-2.41 D2 — SCN dual watermark */ +#include "storage/buf_internals.h" /* BufferTag */ #ifdef USE_PGRAC_CLUSTER @@ -192,8 +192,7 @@ typedef struct PcmReclaimBatch { uint8 reserved[7]; } PcmReclaimBatch; -StaticAssertDecl(sizeof(PcmReclaimBatch) == 24, - "PcmReclaimBatch layout must remain 24 bytes"); +StaticAssertDecl(sizeof(PcmReclaimBatch) == 24, "PcmReclaimBatch layout must remain 24 bytes"); /* Read-only D5 lifecycle observability. Every value is sourced from the * native PCM directory/reclaim owner; none aliases the removed PCM-X ticket @@ -412,8 +411,7 @@ extern void cluster_pcm_vm_clear_note(const BufferTag *tag, BlockNumber heap_blo extern void cluster_pcm_vm_latency_note(const BufferTag *tag, bool remote, uint64 elapsed_us); extern bool cluster_pcm_vm_stats_snapshot(PcmVmStats *out); -StaticAssertDecl(sizeof(PcmGrdLifecycleStats) - == (9 + PCM_RETIRE_REFUSAL_N) * sizeof(uint64), +StaticAssertDecl(sizeof(PcmGrdLifecycleStats) == (9 + PCM_RETIRE_REFUSAL_N) * sizeof(uint64), "PcmGrdLifecycleStats must remain a fixed native counter cohort"); /* Read-only current gauges for protocol debt which must drain before a @@ -442,8 +440,7 @@ typedef struct PcmEntryRef { uint8 reserved[3]; } PcmEntryRef; -StaticAssertDecl(sizeof(PcmEntryRef) == 48, - "PcmEntryRef layout must remain 48 bytes"); +StaticAssertDecl(sizeof(PcmEntryRef) == 48, "PcmEntryRef layout must remain 48 bytes"); /* A staged transport may outlive the lookup pin that created it. This * exact identity keeps the binding non-retirable without granting PCM or @@ -460,23 +457,20 @@ typedef struct PcmEntryTransportRef { StaticAssertDecl(sizeof(PcmEntryTransportRef) == 48, "PcmEntryTransportRef layout must remain 48 bytes"); -extern bool pcm_entry_ref_acquire(const BufferTag *tag, bool create, - PcmEntryRef *out, PcmEntryAcquireResult *result); +extern bool pcm_entry_ref_acquire(const BufferTag *tag, bool create, PcmEntryRef *out, + PcmEntryAcquireResult *result); extern void pcm_entry_ref_release(PcmEntryRef *ref); extern bool pcm_entry_transport_ref_begin(const PcmEntryRef *entry_ref, - PcmEntryTransportRef *transport_ref); + PcmEntryTransportRef *transport_ref); extern void pcm_entry_transport_ref_end(PcmEntryTransportRef *transport_ref); -extern bool pcm_entry_retire_classify_exact(const BufferTag *tag, - uint64 expected_generation, PcmRetireRefusal *why); -extern bool pcm_entry_try_retire_exact(const BufferTag *tag, - uint64 binding_generation, PcmRetireReason reason); -extern bool cluster_pcm_lock_reclaim_bounded(uint32 probe_budget, - PcmReclaimBatch *out); +extern bool pcm_entry_retire_classify_exact(const BufferTag *tag, uint64 expected_generation, + PcmRetireRefusal *why); +extern bool pcm_entry_try_retire_exact(const BufferTag *tag, uint64 binding_generation, + PcmRetireReason reason); +extern bool cluster_pcm_lock_reclaim_bounded(uint32 probe_budget, PcmReclaimBatch *out); extern void cluster_pcm_lock_lmon_reclaim_tick(void); -extern void cluster_pcm_grd_lifecycle_stats_snapshot( - PcmGrdLifecycleStats *out); -extern void cluster_pcm_grd_protocol_debt_snapshot( - PcmGrdProtocolDebtStats *out); +extern void cluster_pcm_grd_lifecycle_stats_snapshot(PcmGrdLifecycleStats *out); +extern void cluster_pcm_grd_protocol_debt_snapshot(PcmGrdProtocolDebtStats *out); /* Stage 8 R9: one logical Resource-X acquisition is the already-frozen D6 * assertion plus exact formation and acquisition generation. Transport @@ -976,15 +970,15 @@ extern bool cluster_pcm_lock_resource_x_trace_begin(const BufferTag *tag, uint64 extern bool cluster_pcm_lock_resource_x_trace_seal(uint64 epoch); extern bool cluster_pcm_lock_resource_x_trace_snapshot(ResourceXTraceStats *out); extern uint32 cluster_pcm_lock_resource_x_trace_read(uint64 epoch, uint64 first, - ResourceXTraceEvent *out, uint32 limit); + ResourceXTraceEvent *out, uint32 limit); extern bool cluster_pcm_lock_resource_x_trace_release(uint64 epoch); extern void cluster_pcm_lock_resource_x_trace_note(const ResourceXTraceEvent *event); -extern void cluster_pcm_lock_resource_x_trace_ref(uint16 kind, - const ResourceXAcquisitionRef *ref, uint64 value); -extern void cluster_pcm_lock_resource_x_trace_frame(uint16 kind, - const ResourceXDecodedFrame *frame, int32 peer, int32 result); -extern void cluster_pcm_lock_resource_x_trace_wire(uint8 msg_type, int32 peer, - const void *payload, uint32 length, int32 result); +extern void cluster_pcm_lock_resource_x_trace_ref(uint16 kind, const ResourceXAcquisitionRef *ref, + uint64 value); +extern void cluster_pcm_lock_resource_x_trace_frame(uint16 kind, const ResourceXDecodedFrame *frame, + int32 peer, int32 result); +extern void cluster_pcm_lock_resource_x_trace_wire(uint8 msg_type, int32 peer, const void *payload, + uint32 length, int32 result); /* Exact, process-local D2 result retained for the R8 sweep owner. This is * deliberately not a wire structure and carries both the removed queue @@ -1036,8 +1030,7 @@ typedef struct ResourceXReconfigToken { uint32 reserved; } ResourceXReconfigToken; -#define RESOURCE_X_RECONFIG_RECLAIM_WITNESS_MAX \ - (4 * RESOURCE_X_PROTOCOL_NODE_LIMIT) +#define RESOURCE_X_RECONFIG_RECLAIM_WITNESS_MAX (4 * RESOURCE_X_PROTOCOL_NODE_LIMIT) typedef struct ResourceXReconfigBatch { uint32 examined_count; @@ -1054,8 +1047,7 @@ typedef struct ResourceXReconfigBatch { uint32 reclaim_orphan_count; uint64 next_state_index; uint64 residual_count; - ResourceXReclaimWitness - reclaim_witnesses[RESOURCE_X_RECONFIG_RECLAIM_WITNESS_MAX]; + ResourceXReclaimWitness reclaim_witnesses[RESOURCE_X_RECONFIG_RECLAIM_WITNESS_MAX]; } ResourceXReconfigBatch; typedef struct ResourceXReconfigStats { @@ -1422,52 +1414,42 @@ extern PcmLockMode cluster_pcm_lock_query(BufferTag tag); extern int cluster_pcm_grd_capacity(void); extern bool cluster_pcm_lock_authority_snapshot(BufferTag tag, PcmAuthoritySnapshot *out); extern bool cluster_pcm_lock_r4_route_snapshot(BufferTag tag, PcmAuthoritySnapshot *authority_out, - uint64 *master_authority_generation_out, - SCN *expected_page_scn_out); + uint64 *master_authority_generation_out, + SCN *expected_page_scn_out); extern bool cluster_pcm_lock_authority_matches(BufferTag tag, const PcmAuthoritySnapshot *expected); extern ResourceXApplyResult cluster_pcm_lock_resource_x_t1_grant_exact(const ResourceXAcquisitionRef *ref); /* Temporary R10 production adapter handoff. The caller must already have * selected the exact PCM-X master ticket, then pass a complete legacy * authority snapshot taken without either domain lock. */ -extern ResourceXApplyResult -cluster_pcm_lock_resource_x_adapter_base_bind_exact( - const ResourceXAssertion *assertion, uint64 formation, - uint64 base_authority_generation, +extern ResourceXApplyResult cluster_pcm_lock_resource_x_adapter_base_bind_exact( + const ResourceXAssertion *assertion, uint64 formation, uint64 base_authority_generation, const PcmAuthoritySnapshot *legacy_authority); -extern ResourceXApplyResult -cluster_pcm_lock_resource_x_adapter_head_rebind_exact( - const ResourceXAssertion *assertion, uint64 assertion_sequence, - uint64 ticket_id, uint64 formation, - uint64 base_authority_generation, +extern ResourceXApplyResult cluster_pcm_lock_resource_x_adapter_head_rebind_exact( + const ResourceXAssertion *assertion, uint64 assertion_sequence, uint64 ticket_id, + uint64 formation, uint64 base_authority_generation, const PcmAuthoritySnapshot *legacy_authority); -extern ResourceXApplyResult -cluster_pcm_lock_resource_x_adapter_successor_base_exact( +extern ResourceXApplyResult cluster_pcm_lock_resource_x_adapter_successor_base_exact( const ResourceXAssertion *assertion, uint64 formation, - const PcmAuthoritySnapshot *legacy_authority, - uint64 *base_authority_generation_out); -extern ResourceXApplyResult cluster_pcm_lock_resource_x_assert_exact( - const ResourceXDecodedFrame *assertion, int32 authenticated_source_node, - ResourceXMasterSnapshot *out); + const PcmAuthoritySnapshot *legacy_authority, uint64 *base_authority_generation_out); +extern ResourceXApplyResult +cluster_pcm_lock_resource_x_assert_exact(const ResourceXDecodedFrame *assertion, + int32 authenticated_source_node, + ResourceXMasterSnapshot *out); /* PGRAC adaptation: kind-9 is a non-authority pre-ASSERT receipt. The * caller passes independently authenticated/current connection, R4, and * master-session values; the exact ASSERT consumes the receipt under the * same resource entry lock that creates the canonical master request. */ -extern ResourceXApplyResult -cluster_pcm_lock_resource_x_bootstrap_request_exact( +extern ResourceXApplyResult cluster_pcm_lock_resource_x_bootstrap_request_exact( const ResourceXDecodedFrame *request, int32 authenticated_source_node, - uint32 authenticated_ingress_connection_generation, - uint64 r4_record_generation, uint64 current_master_session_incarnation, - uint32 master_sender_connection_generation, + uint32 authenticated_ingress_connection_generation, uint64 r4_record_generation, + uint64 current_master_session_incarnation, uint32 master_sender_connection_generation, ResourceXDecodedFrame *ack_out); -extern bool cluster_pcm_lock_resource_x_s_barrier_active( - const BufferTag *tag); -extern ResourceXApplyResult -cluster_pcm_lock_resource_x_assert_bootstrapped_exact( +extern bool cluster_pcm_lock_resource_x_s_barrier_active(const BufferTag *tag); +extern ResourceXApplyResult cluster_pcm_lock_resource_x_assert_bootstrapped_exact( const ResourceXDecodedFrame *assertion, int32 authenticated_source_node, - uint32 authenticated_ingress_connection_generation, - uint64 r4_record_generation, uint64 current_master_session_incarnation, - uint32 current_master_sender_connection_generation, + uint32 authenticated_ingress_connection_generation, uint64 r4_record_generation, + uint64 current_master_session_incarnation, uint32 current_master_sender_connection_generation, ResourceXMasterSnapshot *out); /* Process-local membership in one node head. This is not authority and is * never copied to another caller. A failed witness cannot be reset by a @@ -1619,11 +1601,8 @@ cluster_pcm_lock_resource_x_bootstrap_round_step_direct_init_exact( ResourceXDecodedFrame *dispatch_out, ResourceXAcquisitionRef *terminal_ref_out); extern ResourceXApplyResult cluster_pcm_lock_resource_x_bootstrap_round_direct_init_join_budget_exact( - const ResourceXAssertion *assertion, - uint64 direct_init_ownership_generation, - uint64 direct_init_reservation_token, - uint64 now_us, - uint64 *r4_record_generation_out, + const ResourceXAssertion *assertion, uint64 direct_init_ownership_generation, + uint64 direct_init_reservation_token, uint64 now_us, uint64 *r4_record_generation_out, uint64 *absolute_deadline_us_out); extern ResourceXBootstrapRoundAction cluster_pcm_lock_resource_x_bootstrap_round_step_direct_init_join_exact( @@ -1634,17 +1613,14 @@ cluster_pcm_lock_resource_x_bootstrap_round_step_direct_init_join_exact( uint64 retry_slice_us, uint64 direct_init_ownership_generation, uint64 direct_init_reservation_token, bool cached_local_x, uint64 cached_ownership_generation, ResourceXDecodedFrame *dispatch_out, ResourceXAcquisitionRef *terminal_ref_out); -extern ResourceXBootstrapRoundAction -cluster_pcm_lock_resource_x_bootstrap_round_accept_ack_exact( +extern ResourceXBootstrapRoundAction cluster_pcm_lock_resource_x_bootstrap_round_accept_ack_exact( const ResourceXDecodedFrame *ack, int32 authenticated_master_node, - uint32 authenticated_ingress_connection_generation, - uint64 r4_record_generation, uint64 now_us, + uint32 authenticated_ingress_connection_generation, uint64 r4_record_generation, uint64 now_us, ResourceXDecodedFrame *assertion_out); extern ResourceXApplyResult cluster_pcm_lock_resource_x_bootstrap_round_discard_pre_assert_authority_drift_exact( const ResourceXDecodedFrame *request, int32 expected_master_node, - uint64 expected_r4_record_generation, - uint32 expected_master_ingress_connection_generation, + uint64 expected_r4_record_generation, uint32 expected_master_ingress_connection_generation, uint64 expected_retry_slice_us, uint64 expected_absolute_deadline_us, uint64 expected_direct_init_ownership_generation, uint64 expected_direct_init_reservation_token); @@ -1673,54 +1649,39 @@ extern ResourceXApplyResult cluster_pcm_lock_resource_x_predecessor_wait_exact( uint64 current_formation, uint64 expected_carrier_generation, uint64 caller_absolute_deadline_us, uint64 requested_sleep_slice_us); struct ClusterPcmOwnSnapshot; -extern bool -cluster_pcm_lock_resource_x_bootstrap_round_direct_init_inflight_exact( - const ResourceXAssertion *assertion, int32 current_master_node, - uint64 resource_formation, uint64 master_session_incarnation, - uint64 r4_record_generation, - uint32 requester_sender_connection_generation, - uint32 master_ingress_connection_generation, - uint64 retry_slice_us, - uint64 direct_init_ownership_generation, - uint64 direct_init_reservation_token, - const struct ClusterPcmOwnSnapshot *observed); +extern bool cluster_pcm_lock_resource_x_bootstrap_round_direct_init_inflight_exact( + const ResourceXAssertion *assertion, int32 current_master_node, uint64 resource_formation, + uint64 master_session_incarnation, uint64 r4_record_generation, + uint32 requester_sender_connection_generation, uint32 master_ingress_connection_generation, + uint64 retry_slice_us, uint64 direct_init_ownership_generation, + uint64 direct_init_reservation_token, const struct ClusterPcmOwnSnapshot *observed); /* An ordinary TARGET follower may observe the exact R9 executor's closed * N-reservation through T2-before-T3 interval. This predicate grants no * authority: it only joins that BufferDesc observation to the same * ASSERT-dispatched requester round and active T1/T2 acquisition so the * caller may wait and re-probe instead of treating the closed fence as * corruption. */ -extern bool -cluster_pcm_lock_resource_x_bootstrap_round_target_install_inflight_exact( - const ResourceXAssertion *assertion, int32 current_master_node, - uint64 resource_formation, uint64 master_session_incarnation, - uint64 r4_record_generation, - uint32 requester_sender_connection_generation, - uint32 master_ingress_connection_generation, - uint64 retry_slice_us, - const struct ClusterPcmOwnSnapshot *observed); +extern bool cluster_pcm_lock_resource_x_bootstrap_round_target_install_inflight_exact( + const ResourceXAssertion *assertion, int32 current_master_node, uint64 resource_formation, + uint64 master_session_incarnation, uint64 r4_record_generation, + uint32 requester_sender_connection_generation, uint32 master_ingress_connection_generation, + uint64 retry_slice_us, const struct ClusterPcmOwnSnapshot *observed); extern ResourceXTargetInstallFollowState cluster_pcm_lock_resource_x_bootstrap_round_target_install_capture_exact( - const ResourceXAssertion *assertion, int32 current_master_node, - uint64 resource_formation, uint64 master_session_incarnation, - uint64 r4_record_generation, - uint32 requester_sender_connection_generation, - uint32 master_ingress_connection_generation, + const ResourceXAssertion *assertion, int32 current_master_node, uint64 resource_formation, + uint64 master_session_incarnation, uint64 r4_record_generation, + uint32 requester_sender_connection_generation, uint32 master_ingress_connection_generation, uint64 retry_slice_us, uint64 caller_absolute_deadline_us, const struct ClusterPcmOwnSnapshot *observed, ResourceXTargetInstallContinuation *continuation_out); extern ResourceXTargetInstallFollowState cluster_pcm_lock_resource_x_bootstrap_round_target_install_classify_exact( const ResourceXTargetInstallContinuation *continuation, - const struct ClusterPcmOwnSnapshot *observed, - ResourceXAcquisitionRef *terminal_ref_out); -extern ResourceXApplyResult -cluster_pcm_lock_resource_x_bootstrap_round_target_install_wait_exact( + const struct ClusterPcmOwnSnapshot *observed, ResourceXAcquisitionRef *terminal_ref_out); +extern ResourceXApplyResult cluster_pcm_lock_resource_x_bootstrap_round_target_install_wait_exact( const ResourceXTargetInstallContinuation *continuation, - ResourceXTargetInstallFollowState expected_follow_state, - long timeout_ms); -extern ResourceXApplyResult -cluster_pcm_lock_resource_x_bootstrap_round_publish_terminal_exact( + ResourceXTargetInstallFollowState expected_follow_state, long timeout_ms); +extern ResourceXApplyResult cluster_pcm_lock_resource_x_bootstrap_round_publish_terminal_exact( const ResourceXAcquisitionRef *ref, uint64 master_session_incarnation, uint64 r4_record_generation, uint64 cached_ownership_generation, uint64 terminal_authority_generation, uint64 now_us); @@ -1728,78 +1689,54 @@ cluster_pcm_lock_resource_x_bootstrap_round_publish_terminal_exact( * EVICTING owner and freezes kind-4 while the BufferDesc is still exact * X+REVOKING. ABORT is pre-mutation only; COMMIT is called only after local * apply or reliable transport admission and clears cover+owner together. */ -extern ResourceXApplyResult -cluster_pcm_lock_resource_x_target_evict_prepare_exact( - const BufferTag *tag, int32 current_master_node, - uint64 resource_formation, uint64 master_session_incarnation, - uint64 r4_record_generation, uint64 cached_ownership_generation, - uint64 reservation_token, uint32 sender_connection_generation, - int32 owner_procno, ResourceXDecodedFrame *release_out, +extern ResourceXApplyResult cluster_pcm_lock_resource_x_target_evict_prepare_exact( + const BufferTag *tag, int32 current_master_node, uint64 resource_formation, + uint64 master_session_incarnation, uint64 r4_record_generation, + uint64 cached_ownership_generation, uint64 reservation_token, + uint32 sender_connection_generation, int32 owner_procno, ResourceXDecodedFrame *release_out, ResourceXLocalOwnerHandle *handle_out); extern ResourceXApplyResult -cluster_pcm_lock_resource_x_target_evict_abort_exact( - const ResourceXLocalOwnerHandle *handle); -extern ResourceXApplyResult -cluster_pcm_lock_resource_x_target_evict_commit_exact( - const ResourceXDecodedFrame *release, int32 current_master_node, - uint64 r4_record_generation, uint64 cached_ownership_generation, - const ResourceXLocalOwnerHandle *handle); -extern bool -cluster_pcm_lock_resource_x_bootstrap_round_direct_init_matches_exact( - const ResourceXAcquisitionRef *ref, - uint64 direct_init_ownership_generation, +cluster_pcm_lock_resource_x_target_evict_abort_exact(const ResourceXLocalOwnerHandle *handle); +extern ResourceXApplyResult cluster_pcm_lock_resource_x_target_evict_commit_exact( + const ResourceXDecodedFrame *release, int32 current_master_node, uint64 r4_record_generation, + uint64 cached_ownership_generation, const ResourceXLocalOwnerHandle *handle); +extern bool cluster_pcm_lock_resource_x_bootstrap_round_direct_init_matches_exact( + const ResourceXAcquisitionRef *ref, uint64 direct_init_ownership_generation, uint64 direct_init_reservation_token); -extern bool -cluster_pcm_lock_resource_x_bootstrap_round_direct_init_terminal_holder_exact( - const ResourceXDecodedFrame *successor_block, - int32 authenticated_master_node, uint64 r4_record_generation, - uint64 cached_ownership_generation, +extern bool cluster_pcm_lock_resource_x_bootstrap_round_direct_init_terminal_holder_exact( + const ResourceXDecodedFrame *successor_block, int32 authenticated_master_node, + uint64 r4_record_generation, uint64 cached_ownership_generation, ResourceXTerminalXLineage *lineage_out); -extern bool -cluster_pcm_lock_resource_x_bootstrap_round_terminal_holder_exact( - const ResourceXDecodedFrame *successor_block, - int32 authenticated_master_node, uint64 r4_record_generation, - uint64 cached_ownership_generation, +extern bool cluster_pcm_lock_resource_x_bootstrap_round_terminal_holder_exact( + const ResourceXDecodedFrame *successor_block, int32 authenticated_master_node, + uint64 r4_record_generation, uint64 cached_ownership_generation, ResourceXTerminalXLineage *lineage_out); +extern ResourceXApplyResult cluster_pcm_lock_resource_x_itl_recycle_begin_exact( + const ResourceXAcquisitionRef *ref, uint64 master_session_incarnation, + uint64 r4_record_generation, uint64 cached_ownership_generation, uint64 reservation_token, + int32 owner_procno, uint64 now_us, ResourceXLocalOwnerHandle *handle_out); extern ResourceXApplyResult -cluster_pcm_lock_resource_x_itl_recycle_begin_exact( - const ResourceXAcquisitionRef *ref, - uint64 master_session_incarnation, uint64 r4_record_generation, - uint64 cached_ownership_generation, uint64 reservation_token, - int32 owner_procno, uint64 now_us, - ResourceXLocalOwnerHandle *handle_out); -extern ResourceXApplyResult -cluster_pcm_lock_resource_x_itl_recycle_finish_exact( - const ResourceXLocalOwnerHandle *handle, uint64 now_us); -extern ResourceXApplyResult -cluster_pcm_lock_resource_x_itl_recycle_cancel_exact( - const ResourceXLocalOwnerHandle *handle); +cluster_pcm_lock_resource_x_itl_recycle_finish_exact(const ResourceXLocalOwnerHandle *handle, + uint64 now_us); extern ResourceXApplyResult -cluster_pcm_lock_resource_x_terminal_x_revoke_claim_exact( - const ResourceXDecodedFrame *successor_block, - int32 authenticated_master_node, uint64 r4_record_generation, - uint64 cached_ownership_generation, uint64 reservation_token, - int32 owner_procno, uint64 now_us, - ResourceXTerminalXLineage *lineage_out, +cluster_pcm_lock_resource_x_itl_recycle_cancel_exact(const ResourceXLocalOwnerHandle *handle); +extern ResourceXApplyResult cluster_pcm_lock_resource_x_terminal_x_revoke_claim_exact( + const ResourceXDecodedFrame *successor_block, int32 authenticated_master_node, + uint64 r4_record_generation, uint64 cached_ownership_generation, uint64 reservation_token, + int32 owner_procno, uint64 now_us, ResourceXTerminalXLineage *lineage_out, ResourceXLocalOwnerHandle *handle_out); -extern ResourceXApplyResult -cluster_pcm_lock_resource_x_terminal_x_revoke_replay_exact( - const ResourceXDecodedFrame *successor_block, - int32 authenticated_master_node, uint64 r4_record_generation, - uint64 cached_ownership_generation, uint64 now_us, - ResourceXTerminalXLineage *lineage_out); -extern bool -cluster_pcm_lock_resource_x_terminal_x_revoke_revalidate_held_exact( - const ResourceXDecodedFrame *successor_block, - int32 authenticated_master_node, uint64 r4_record_generation, - uint64 cached_ownership_generation, - const ResourceXLocalOwnerHandle *handle, +extern ResourceXApplyResult cluster_pcm_lock_resource_x_terminal_x_revoke_replay_exact( + const ResourceXDecodedFrame *successor_block, int32 authenticated_master_node, + uint64 r4_record_generation, uint64 cached_ownership_generation, uint64 now_us, ResourceXTerminalXLineage *lineage_out); +extern bool cluster_pcm_lock_resource_x_terminal_x_revoke_revalidate_held_exact( + const ResourceXDecodedFrame *successor_block, int32 authenticated_master_node, + uint64 r4_record_generation, uint64 cached_ownership_generation, + const ResourceXLocalOwnerHandle *handle, ResourceXTerminalXLineage *lineage_out); extern ResourceXApplyResult -cluster_pcm_lock_resource_x_terminal_x_revoke_yield_exact( - const ResourceXLocalOwnerHandle *handle, uint64 now_us); -extern ResourceXApplyResult -cluster_pcm_lock_resource_x_terminal_x_revoke_release_exact( +cluster_pcm_lock_resource_x_terminal_x_revoke_yield_exact(const ResourceXLocalOwnerHandle *handle, + uint64 now_us); +extern ResourceXApplyResult cluster_pcm_lock_resource_x_terminal_x_revoke_release_exact( const ResourceXLocalOwnerHandle *handle); extern ResourceXApplyResult cluster_pcm_lock_resource_x_source_finish_defer_exact( const ResourceXDecodedFrame *block, int32 master_node, @@ -1811,79 +1748,56 @@ extern ResourceXApplyResult cluster_pcm_lock_resource_x_terminal_x_revoke_finish const ResourceXDecodedFrame *successor_block, int32 authenticated_master_node, uint64 r4_record_generation, const struct ClusterPcmOwnSnapshot *revoking, const struct ClusterPcmOwnSnapshot *dropped, const ResourceXLocalOwnerHandle *handle); -extern bool -cluster_pcm_lock_resource_x_bootstrap_round_direct_init_snapshot_exact( - const ResourceXAcquisitionRef *ref, - uint64 *direct_init_ownership_generation_out, +extern bool cluster_pcm_lock_resource_x_bootstrap_round_direct_init_snapshot_exact( + const ResourceXAcquisitionRef *ref, uint64 *direct_init_ownership_generation_out, uint64 *direct_init_reservation_token_out); -extern ResourceXApplyResult -cluster_pcm_lock_resource_x_bootstrap_round_failure_snapshot_exact( - const ResourceXAssertion *assertion, int32 current_master_node, - uint64 resource_formation, uint64 master_session_incarnation, - uint64 r4_record_generation, - uint32 requester_sender_connection_generation, - uint32 master_ingress_connection_generation, uint64 retry_slice_us, - ResourceXBootstrapRoundFailureSnapshot *out); -extern bool -cluster_pcm_lock_resource_x_bootstrap_round_cover_matches_exact( +extern ResourceXApplyResult cluster_pcm_lock_resource_x_bootstrap_round_failure_snapshot_exact( + const ResourceXAssertion *assertion, int32 current_master_node, uint64 resource_formation, + uint64 master_session_incarnation, uint64 r4_record_generation, + uint32 requester_sender_connection_generation, uint32 master_ingress_connection_generation, + uint64 retry_slice_us, ResourceXBootstrapRoundFailureSnapshot *out); +extern bool cluster_pcm_lock_resource_x_bootstrap_round_cover_matches_exact( const ResourceXAcquisitionRef *ref, uint64 master_session_incarnation, uint64 r4_record_generation, uint64 cached_ownership_generation); extern ResourceXApplyResult cluster_pcm_lock_resource_x_bootstrap_round_invalidate_ownership_loss_exact( - const ResourceXAssertion *assertion, int32 current_master_node, - uint64 resource_formation, uint64 master_session_incarnation, - uint64 r4_record_generation, - uint32 requester_sender_connection_generation, - uint32 master_ingress_connection_generation, uint64 retry_slice_us, - const struct ClusterPcmOwnSnapshot *observed); -extern ResourceXApplyResult -cluster_pcm_lock_resource_x_bootstrap_round_x_to_s_preflight_exact( + const ResourceXAssertion *assertion, int32 current_master_node, uint64 resource_formation, + uint64 master_session_incarnation, uint64 r4_record_generation, + uint32 requester_sender_connection_generation, uint32 master_ingress_connection_generation, + uint64 retry_slice_us, const struct ClusterPcmOwnSnapshot *observed); +extern ResourceXApplyResult cluster_pcm_lock_resource_x_bootstrap_round_x_to_s_preflight_exact( const struct ClusterPcmOwnSnapshot *current); +extern ResourceXApplyResult cluster_pcm_lock_resource_x_bootstrap_round_note_x_to_s_exact( + const struct ClusterPcmOwnSnapshot *revoking, const struct ClusterPcmOwnSnapshot *shared); extern ResourceXApplyResult -cluster_pcm_lock_resource_x_bootstrap_round_note_x_to_s_exact( - const struct ClusterPcmOwnSnapshot *revoking, - const struct ClusterPcmOwnSnapshot *shared); -extern ResourceXApplyResult cluster_pcm_lock_resource_x_block_to_n_exact( - const ResourceXDecodedFrame *block, int32 authenticated_master_node); -extern ResourceXApplyResult -cluster_pcm_lock_resource_x_block_to_n_source_exact( +cluster_pcm_lock_resource_x_block_to_n_exact(const ResourceXDecodedFrame *block, + int32 authenticated_master_node); +extern ResourceXApplyResult cluster_pcm_lock_resource_x_block_to_n_source_exact( const ResourceXDecodedFrame *block, int32 authenticated_master_node, - const ResourceXDecodedFrame *blocked_status, - const ResourceXDecodedFrame *image_envelope); -extern ResourceXApplyResult -cluster_pcm_lock_resource_x_block_to_n_drop_x_source_exact( + const ResourceXDecodedFrame *blocked_status, const ResourceXDecodedFrame *image_envelope); +extern ResourceXApplyResult cluster_pcm_lock_resource_x_block_to_n_drop_x_source_exact( const ResourceXDecodedFrame *block, int32 authenticated_master_node, - const ResourceXDecodedFrame *blocked_status, - const ResourceXDecodedFrame *image_envelope, - const struct ClusterPcmOwnSnapshot *revoking, - const ResourceXLocalOwnerHandle *owner); -extern ResourceXApplyResult -cluster_pcm_lock_resource_x_block_to_n_prepared_x_source_exact( + const ResourceXDecodedFrame *blocked_status, const ResourceXDecodedFrame *image_envelope, + const struct ClusterPcmOwnSnapshot *revoking, const ResourceXLocalOwnerHandle *owner); +extern ResourceXApplyResult cluster_pcm_lock_resource_x_block_to_n_prepared_x_source_exact( const ResourceXDecodedFrame *block, int32 authenticated_master_node, - const ResourceXDecodedFrame *blocked_status, - const ResourceXDecodedFrame *image_envelope, - const struct ClusterPcmOwnSnapshot *revoking, - const ResourceXLocalOwnerHandle *owner); -extern ResourceXApplyResult -cluster_pcm_lock_resource_x_block_to_n_prepared_s_source_exact( + const ResourceXDecodedFrame *blocked_status, const ResourceXDecodedFrame *image_envelope, + const struct ClusterPcmOwnSnapshot *revoking, const ResourceXLocalOwnerHandle *owner); +extern ResourceXApplyResult cluster_pcm_lock_resource_x_block_to_n_prepared_s_source_exact( const ResourceXDecodedFrame *block, int32 authenticated_master_node, - const ResourceXDecodedFrame *blocked_status, - const ResourceXDecodedFrame *image_envelope, - const struct ClusterPcmOwnSnapshot *prepared_source, - XLogRecPtr prepared_page_lsn, uint64 prepared_page_scn, - uint32 prepared_page_checksum); + const ResourceXDecodedFrame *blocked_status, const ResourceXDecodedFrame *image_envelope, + const struct ClusterPcmOwnSnapshot *prepared_source, XLogRecPtr prepared_page_lsn, + uint64 prepared_page_scn, uint32 prepared_page_checksum); /* Retention is PENDING and transport-invisible. Publish the indivisible pair * only after the caller completed the exact physical source revoke. The * query returns NOT_FOUND when only an exact older same-domain attempt is * retained; replacement remains gated by its separate DRAIN contract. */ -extern ResourceXApplyResult -cluster_pcm_lock_resource_x_holder_pair_publish_needed_exact( - const ResourceXAssertion *assertion, uint64 assertion_sequence, - int32 authenticated_master_node, uint64 authenticated_master_session); -extern ResourceXApplyResult -cluster_pcm_lock_resource_x_holder_pair_publish_exact( - const ResourceXAssertion *assertion, uint64 assertion_sequence, - int32 authenticated_master_node, uint64 authenticated_master_session); +extern ResourceXApplyResult cluster_pcm_lock_resource_x_holder_pair_publish_needed_exact( + const ResourceXAssertion *assertion, uint64 assertion_sequence, int32 authenticated_master_node, + uint64 authenticated_master_session); +extern ResourceXApplyResult cluster_pcm_lock_resource_x_holder_pair_publish_exact( + const ResourceXAssertion *assertion, uint64 assertion_sequence, int32 authenticated_master_node, + uint64 authenticated_master_session); /* Replay only a published, undrained immutable pair. Occupied physical slots * are validated and left untouched; an empty pair is rearmed atomically. */ extern ResourceXApplyResult cluster_pcm_lock_resource_x_holder_pair_replay_exact( @@ -1893,76 +1807,73 @@ extern ResourceXApplyResult cluster_pcm_lock_resource_x_holder_pair_replay_exact * physical generation to the exact still-undrained PENDING/PUBLISHED pair * under the resource entry lock; callers must separately revalidate * BufferDesc. */ -extern bool -cluster_pcm_lock_resource_x_holder_pair_retained_fence_exact( - const BufferTag *tag, int32 current_master_node, - uint64 current_master_session, uint64 current_formation, - uint64 retained_generation); -extern ResourceXApplyResult cluster_pcm_lock_resource_x_holder_status_exact( - const ResourceXAssertion *assertion, ResourceXDecodedFrame *out); -extern ResourceXApplyResult cluster_pcm_lock_resource_x_holder_image_exact( - const ResourceXAssertion *assertion, ResourceXDecodedFrame *out); +extern bool cluster_pcm_lock_resource_x_holder_pair_retained_fence_exact( + const BufferTag *tag, int32 current_master_node, uint64 current_master_session, + uint64 current_formation, uint64 retained_generation); +extern ResourceXApplyResult +cluster_pcm_lock_resource_x_holder_status_exact(const ResourceXAssertion *assertion, + ResourceXDecodedFrame *out); +extern ResourceXApplyResult +cluster_pcm_lock_resource_x_holder_image_exact(const ResourceXAssertion *assertion, + ResourceXDecodedFrame *out); /* Classify one old type-17 as superseded only when the current retained * status+image pair is atomically exact and has a strictly newer sequence. */ -extern ResourceXApplyResult -cluster_pcm_lock_resource_x_holder_pair_supersedes_exact( - const ResourceXAssertion *assertion, uint64 assertion_sequence, - int32 authenticated_master_node, uint64 authenticated_master_session); +extern ResourceXApplyResult cluster_pcm_lock_resource_x_holder_pair_supersedes_exact( + const ResourceXAssertion *assertion, uint64 assertion_sequence, int32 authenticated_master_node, + uint64 authenticated_master_session); /* Validate and retire only the exact type-18/type-15 retained carrier pair * selected by one authenticated post-settlement DRAIN. The prepare/commit * split keeps the GRD entry lock out of the BufferContent critical section. */ +extern ResourceXApplyResult cluster_pcm_lock_resource_x_holder_pair_drain_prepare_exact( + const ResourceXAssertion *assertion, uint64 assertion_sequence, int32 authenticated_master_node, + uint64 authenticated_master_session, uint64 *source_generation_out); +extern ResourceXApplyResult cluster_pcm_lock_resource_x_holder_pair_drain_commit_exact( + const ResourceXAssertion *assertion, uint64 assertion_sequence, int32 authenticated_master_node, + uint64 authenticated_master_session, uint64 source_generation); extern ResourceXApplyResult -cluster_pcm_lock_resource_x_holder_pair_drain_prepare_exact( - const ResourceXAssertion *assertion, uint64 assertion_sequence, - int32 authenticated_master_node, uint64 authenticated_master_session, - uint64 *source_generation_out); +cluster_pcm_lock_resource_x_blocked_to_n_exact(const ResourceXDecodedFrame *blocked, + int32 authenticated_source_node, + ResourceXMasterSnapshot *out); extern ResourceXApplyResult -cluster_pcm_lock_resource_x_holder_pair_drain_commit_exact( - const ResourceXAssertion *assertion, uint64 assertion_sequence, - int32 authenticated_master_node, uint64 authenticated_master_session, - uint64 source_generation); -extern ResourceXApplyResult cluster_pcm_lock_resource_x_blocked_to_n_exact( - const ResourceXDecodedFrame *blocked, int32 authenticated_source_node, - ResourceXMasterSnapshot *out); -extern ResourceXApplyResult cluster_pcm_lock_resource_x_local_proof_exact( - const ResourceXDecodedFrame *local_proof, int32 authenticated_source_node, - ResourceXMasterSnapshot *out); -extern ResourceXApplyResult cluster_pcm_lock_resource_x_durable_proof_exact( - const ResourceXDurableProof *durable_proof, ResourceXMasterSnapshot *out); -extern ResourceXApplyResult cluster_pcm_lock_resource_x_master_snapshot_exact( - const ResourceXAssertion *assertion, ResourceXMasterSnapshot *out); -extern bool cluster_pcm_lock_resource_x_s_barrier_active_exact( - const BufferTag *tag); +cluster_pcm_lock_resource_x_local_proof_exact(const ResourceXDecodedFrame *local_proof, + int32 authenticated_source_node, + ResourceXMasterSnapshot *out); +extern ResourceXApplyResult +cluster_pcm_lock_resource_x_durable_proof_exact(const ResourceXDurableProof *durable_proof, + ResourceXMasterSnapshot *out); +extern ResourceXApplyResult +cluster_pcm_lock_resource_x_master_snapshot_exact(const ResourceXAssertion *assertion, + ResourceXMasterSnapshot *out); +extern bool cluster_pcm_lock_resource_x_s_barrier_active_exact(const BufferTag *tag); /* Requester-node projection of an in-flight bootstrap round. This is a * retry-only local S-admission barrier; terminal cached X remains eligible * for the normal BufferDesc covering-grant path. */ -extern bool -cluster_pcm_lock_resource_x_requester_s_barrier_active_exact( - const BufferTag *tag); +extern bool cluster_pcm_lock_resource_x_requester_s_barrier_active_exact(const BufferTag *tag); extern ResourceXApplyResult -cluster_pcm_lock_resource_x_current_x_successor_exact( - const BufferTag *tag, int32 holder_node, bool *preserve_current_x_out); -extern ResourceXApplyResult cluster_pcm_lock_resource_x_authority_grant_exact( - const ResourceXAssertion *assertion, ResourceXDecodedFrame *out); -extern ResourceXApplyResult cluster_pcm_lock_resource_x_requester_join_exact( - const ResourceXDecodedFrame *frame, int32 authenticated_source_node, - ResourceXRequesterJoinSnapshot *out); +cluster_pcm_lock_resource_x_current_x_successor_exact(const BufferTag *tag, int32 holder_node, + bool *preserve_current_x_out); +extern ResourceXApplyResult +cluster_pcm_lock_resource_x_authority_grant_exact(const ResourceXAssertion *assertion, + ResourceXDecodedFrame *out); +extern ResourceXApplyResult +cluster_pcm_lock_resource_x_requester_join_exact(const ResourceXDecodedFrame *frame, + int32 authenticated_source_node, + ResourceXRequesterJoinSnapshot *out); extern ResourceXApplyResult cluster_pcm_lock_resource_x_requester_join_current_exact( const ResourceXDecodedFrame *frame, int32 authenticated_source_node, uint32 authenticated_source_ingress_generation, int32 current_master_node, uint32 current_master_ingress_generation, uint64 r4_record_generation, ResourceXRequesterJoinSnapshot *out); -extern ResourceXApplyResult -cluster_pcm_lock_resource_x_requester_join_frames_exact( +extern ResourceXApplyResult cluster_pcm_lock_resource_x_requester_join_frames_exact( const ResourceXAssertion *assertion, ResourceXDecodedFrame *grant_out, ResourceXDecodedFrame *image_out, ResourceXRequesterJoinSnapshot *out); -extern ResourceXApplyResult cluster_pcm_lock_resource_x_install_settlement_exact( - const ResourceXDecodedFrame *settlement, int32 authenticated_source_node, - ResourceXMasterSnapshot *out); extern ResourceXApplyResult -cluster_pcm_lock_resource_x_source_settlement_intent_snapshot_exact( - const ResourceXAssertion *assertion, ResourceXIntentSlot *slot_out, - void *payload_out, uint16 payload_capacity); +cluster_pcm_lock_resource_x_install_settlement_exact(const ResourceXDecodedFrame *settlement, + int32 authenticated_source_node, + ResourceXMasterSnapshot *out); +extern ResourceXApplyResult cluster_pcm_lock_resource_x_source_settlement_intent_snapshot_exact( + const ResourceXAssertion *assertion, ResourceXIntentSlot *slot_out, void *payload_out, + uint16 payload_capacity); /* Process-local freshness evidence for one SourceSettlement ingress. The * plan is never serialized or retained and grants no Resource-X authority. */ @@ -1995,8 +1906,7 @@ typedef struct ResourceXSourceSettlementPlan { bool valid; } ResourceXSourceSettlementPlan; -extern ResourceXApplyResult -cluster_pcm_lock_resource_x_source_settlement_prepare_exact( +extern ResourceXApplyResult cluster_pcm_lock_resource_x_source_settlement_prepare_exact( const ResourceXDecodedFrame *settlement, int32 authenticated_master_node, ResourceXSourceSettlementPlan *plan_out); @@ -2055,92 +1965,84 @@ typedef struct ResourceXSourceSettlementCommitObservation { } ResourceXSourceSettlementCommitObservation; StaticAssertDecl(sizeof(ResourceXSourceSettlementCommitObservation) == 96, - "ResourceXSourceSettlementCommitObservation layout must remain 96 bytes"); + "ResourceXSourceSettlementCommitObservation layout must remain 96 bytes"); -extern ResourceXApplyResult -cluster_pcm_lock_resource_x_source_settlement_prepare_observed_exact( +extern ResourceXApplyResult cluster_pcm_lock_resource_x_source_settlement_prepare_observed_exact( const ResourceXDecodedFrame *settlement, int32 authenticated_master_node, ResourceXSourceSettlementPlan *plan_out, ResourceXSourceSettlementCommitObservation *observation_out); -extern ResourceXApplyResult -cluster_pcm_lock_resource_x_source_settlement_commit_exact( +extern ResourceXApplyResult cluster_pcm_lock_resource_x_source_settlement_commit_exact( const ResourceXDecodedFrame *settlement, int32 authenticated_master_node, const ResourceXSourceSettlementPlan *plan, ResourceXSourceSettlementCommitObservation *observation_out); +extern ResourceXApplyResult cluster_pcm_lock_resource_x_source_settlement_ack_build_exact( + const ResourceXDecodedFrame *settlement, uint32 sender_connection_generation, + ResourceXDecodedFrame *ack_out); extern ResourceXApplyResult -cluster_pcm_lock_resource_x_source_settlement_ack_build_exact( - const ResourceXDecodedFrame *settlement, - uint32 sender_connection_generation, ResourceXDecodedFrame *ack_out); +cluster_pcm_lock_resource_x_source_settlement_ack_exact(const ResourceXDecodedFrame *ack, + int32 authenticated_source_node, + ResourceXMasterSnapshot *out); extern ResourceXApplyResult -cluster_pcm_lock_resource_x_source_settlement_ack_exact( - const ResourceXDecodedFrame *ack, int32 authenticated_source_node, - ResourceXMasterSnapshot *out); +cluster_pcm_lock_resource_x_settled_retire_exact(const ResourceXAssertion *assertion, + uint64 assertion_sequence, + const ResourceXMasterSnapshot *settled); extern ResourceXApplyResult -cluster_pcm_lock_resource_x_settled_retire_exact( - const ResourceXAssertion *assertion, uint64 assertion_sequence, - const ResourceXMasterSnapshot *settled); -extern ResourceXApplyResult cluster_pcm_lock_resource_x_release_x_exact( - const ResourceXDecodedFrame *release, int32 authenticated_source_node, - ResourceXMasterSnapshot *out); +cluster_pcm_lock_resource_x_release_x_exact(const ResourceXDecodedFrame *release, + int32 authenticated_source_node, + ResourceXMasterSnapshot *out); extern ResourceXReclaimResult cluster_pcm_lock_resource_x_reclaim_requester_exact( - const BufferTag *tag, int32 dead_node, uint64 dead_formation, - ResourceXReclaimWitness *out); + const BufferTag *tag, int32 dead_node, uint64 dead_formation, ResourceXReclaimWitness *out); extern bool cluster_pcm_lock_resource_x_intent_arm_exact( - ResourceXIntentSlot *slot, const ResourceXIntentBodyHandle *body, - uint64 logical_generation, uint64 authority_generation, - uint64 now_us, uint32 destination_node, uint16 payload_bytes, + ResourceXIntentSlot *slot, const ResourceXIntentBodyHandle *body, uint64 logical_generation, + uint64 authority_generation, uint64 now_us, uint32 destination_node, uint16 payload_bytes, ResourceXWireKind kind); extern ResourceXIntentResult cluster_pcm_lock_resource_x_intent_not_admitted_exact( - ResourceXIntentSlot *slot, const ResourceXIntentSlot *expected, - uint64 now_us); -extern ResourceXIntentResult cluster_pcm_lock_resource_x_intent_stage_exact( - ResourceXIntentSlot *slot, const ResourceXIntentSlot *expected, - uint64 now_us); + ResourceXIntentSlot *slot, const ResourceXIntentSlot *expected, uint64 now_us); +extern ResourceXIntentResult +cluster_pcm_lock_resource_x_intent_stage_exact(ResourceXIntentSlot *slot, + const ResourceXIntentSlot *expected, uint64 now_us); extern ResourceXIntentResult cluster_pcm_lock_resource_x_intent_hard_rearm_exact( - ResourceXIntentSlot *slot, const ResourceXIntentSlot *expected, - uint64 now_us); -extern bool cluster_pcm_lock_resource_x_intent_complete_exact( - ResourceXIntentSlot *slot, const ResourceXIntentSlot *expected); + ResourceXIntentSlot *slot, const ResourceXIntentSlot *expected, uint64 now_us); +extern bool cluster_pcm_lock_resource_x_intent_complete_exact(ResourceXIntentSlot *slot, + const ResourceXIntentSlot *expected); extern ResourceXApplyResult cluster_pcm_lock_resource_x_block_intent_snapshot_exact( - const ResourceXAssertion *assertion, int32 holder_node, - ResourceXIntentSlot *slot_out, void *payload_out, - uint16 payload_capacity); -extern ResourceXApplyResult -cluster_pcm_lock_resource_x_holder_status_intent_snapshot_exact( - const ResourceXAssertion *assertion, ResourceXIntentSlot *slot_out, + const ResourceXAssertion *assertion, int32 holder_node, ResourceXIntentSlot *slot_out, void *payload_out, uint16 payload_capacity); +extern ResourceXApplyResult cluster_pcm_lock_resource_x_holder_status_intent_snapshot_exact( + const ResourceXAssertion *assertion, ResourceXIntentSlot *slot_out, void *payload_out, + uint16 payload_capacity); +extern ResourceXApplyResult cluster_pcm_lock_resource_x_holder_image_intent_snapshot_exact( + const ResourceXAssertion *assertion, ResourceXIntentSlot *slot_out, void *payload_out, + uint16 payload_capacity); extern ResourceXApplyResult -cluster_pcm_lock_resource_x_holder_image_intent_snapshot_exact( - const ResourceXAssertion *assertion, ResourceXIntentSlot *slot_out, - void *payload_out, uint16 payload_capacity); -extern ResourceXApplyResult cluster_pcm_lock_resource_x_grant_intent_snapshot_exact( - const ResourceXAssertion *assertion, ResourceXIntentSlot *slot_out, - void *payload_out, uint16 payload_capacity); +cluster_pcm_lock_resource_x_grant_intent_snapshot_exact(const ResourceXAssertion *assertion, + ResourceXIntentSlot *slot_out, + void *payload_out, uint16 payload_capacity); extern ResourceXIntentResult -cluster_pcm_lock_resource_x_grant_intent_not_admitted_exact( - const ResourceXIntentSlot *expected, uint64 now_us); -extern ResourceXIntentResult cluster_pcm_lock_resource_x_grant_intent_stage_exact( - const ResourceXIntentSlot *expected, uint64 now_us); +cluster_pcm_lock_resource_x_grant_intent_not_admitted_exact(const ResourceXIntentSlot *expected, + uint64 now_us); extern ResourceXIntentResult -cluster_pcm_lock_resource_x_grant_intent_hard_rearm_exact( - const ResourceXIntentSlot *expected, uint64 now_us); -extern bool cluster_pcm_lock_resource_x_grant_intent_complete_exact( - const ResourceXIntentSlot *expected); -extern ResourceXApplyResult -cluster_pcm_lock_resource_x_outbound_intent_snapshot_exact( - const ResourceXIntentSlot *expected, ResourceXIntentSlot *slot_out, - void *payload_out, uint16 payload_capacity); +cluster_pcm_lock_resource_x_grant_intent_stage_exact(const ResourceXIntentSlot *expected, + uint64 now_us); +extern ResourceXIntentResult +cluster_pcm_lock_resource_x_grant_intent_hard_rearm_exact(const ResourceXIntentSlot *expected, + uint64 now_us); +extern bool +cluster_pcm_lock_resource_x_grant_intent_complete_exact(const ResourceXIntentSlot *expected); +extern ResourceXApplyResult cluster_pcm_lock_resource_x_outbound_intent_snapshot_exact( + const ResourceXIntentSlot *expected, ResourceXIntentSlot *slot_out, void *payload_out, + uint16 payload_capacity); extern ResourceXIntentResult -cluster_pcm_lock_resource_x_outbound_intent_not_admitted_exact( - const ResourceXIntentSlot *expected, uint64 now_us); +cluster_pcm_lock_resource_x_outbound_intent_not_admitted_exact(const ResourceXIntentSlot *expected, + uint64 now_us); extern ResourceXIntentResult -cluster_pcm_lock_resource_x_outbound_intent_stage_exact( - const ResourceXIntentSlot *expected, uint64 now_us); +cluster_pcm_lock_resource_x_outbound_intent_stage_exact(const ResourceXIntentSlot *expected, + uint64 now_us); extern ResourceXIntentResult -cluster_pcm_lock_resource_x_outbound_intent_hard_rearm_exact( - const ResourceXIntentSlot *expected, uint64 now_us); -extern bool cluster_pcm_lock_resource_x_outbound_intent_complete_exact( - const ResourceXIntentSlot *expected); +cluster_pcm_lock_resource_x_outbound_intent_hard_rearm_exact(const ResourceXIntentSlot *expected, + uint64 now_us); +extern bool +cluster_pcm_lock_resource_x_outbound_intent_complete_exact(const ResourceXIntentSlot *expected); extern ResourceXIntentProbeResult cluster_pcm_lock_resource_x_ready_intent_probe_exact(const BufferTag *tag, uint32 *owner_cursor, ResourceXIntentSlot *slot_out); @@ -2150,64 +2052,57 @@ extern ResourceXIntentProbeResult cluster_pcm_lock_resource_x_outbound_intent_pr extern ResourceXIntentProbeResult cluster_pcm_lock_resource_x_outbound_work_probe_exact( uint32 probe_budget, ResourceXIntentSlot *slot_out, void *payload_out, uint16 payload_capacity, uint32 *examined_out, ResourceXAcquisitionRef *delivery_out); +extern ResourceXApplyResult cluster_pcm_lock_resource_x_gate_bind_formation_exact(uint64 formation); +extern bool +cluster_pcm_lock_resource_x_cutover_gate_snapshot_exact(ResourceXGateSnapshot *snapshot_out); +extern bool cluster_pcm_lock_resource_x_gate_snapshot(ResourceXGateSnapshot *snapshot_out); extern ResourceXApplyResult -cluster_pcm_lock_resource_x_gate_bind_formation_exact(uint64 formation); -extern bool cluster_pcm_lock_resource_x_cutover_gate_snapshot_exact( - ResourceXGateSnapshot *snapshot_out); -extern bool cluster_pcm_lock_resource_x_gate_snapshot( - ResourceXGateSnapshot *snapshot_out); -extern ResourceXApplyResult -cluster_pcm_lock_resource_x_gate_fail_closed_exact( - const ResourceXGateSnapshot *expected); +cluster_pcm_lock_resource_x_gate_fail_closed_exact(const ResourceXGateSnapshot *expected); extern bool cluster_pcm_lock_resource_x_gate_open_exact(uint64 formation); -extern bool cluster_pcm_lock_resource_x_executor_enter( - const ResourceXAcquisitionRef *ref, ResourceXActivationGateToken *out_gate); -extern void -cluster_pcm_lock_resource_x_executor_leave(ResourceXActivationGateToken *gate); +extern bool cluster_pcm_lock_resource_x_executor_enter(const ResourceXAcquisitionRef *ref, + ResourceXActivationGateToken *out_gate); +extern void cluster_pcm_lock_resource_x_executor_leave(ResourceXActivationGateToken *gate); extern uint64 cluster_pcm_lock_resource_x_activation_inflight_count(void); extern bool cluster_resource_x_reconfig_freeze_pending(uint64 old_formation, - ResourceXReconfigToken *out); -extern bool cluster_resource_x_reconfig_freeze_pending_exact( - uint64 old_formation, uint32 dead_requester_bitmap, - ResourceXReconfigToken *out); -extern bool cluster_resource_x_reconfig_bind_new_formation_exact( - ResourceXReconfigToken *token, uint64 new_formation); + ResourceXReconfigToken *out); +extern bool cluster_resource_x_reconfig_freeze_pending_exact(uint64 old_formation, + uint32 dead_requester_bitmap, + ResourceXReconfigToken *out); +extern bool cluster_resource_x_reconfig_bind_new_formation_exact(ResourceXReconfigToken *token, + uint64 new_formation); extern bool cluster_resource_x_reconfig_freeze(uint64 old_formation, uint64 new_formation, ResourceXReconfigToken *out); -extern bool cluster_resource_x_reconfig_freeze_exact( - uint64 old_formation, uint64 new_formation, uint32 dead_requester_bitmap, - ResourceXReconfigToken *out); +extern bool cluster_resource_x_reconfig_freeze_exact(uint64 old_formation, uint64 new_formation, + uint32 dead_requester_bitmap, + ResourceXReconfigToken *out); /* Source-removal cutover enters the R8 owner without supplying a formation * value. The Resource-X gate retains the exact current value and allocates * its own checked successor after the pending full sweep. */ -extern bool cluster_resource_x_reconfig_cutover_begin_native_exact( - ResourceXReconfigToken *out); -extern bool cluster_resource_x_reconfig_cutover_bind_native_successor_exact( - ResourceXReconfigToken *token); -extern ResourceXReconfigResult cluster_resource_x_reconfig_sweep( - const ResourceXReconfigToken *token, uint32 probe_budget, ResourceXReconfigBatch *out); -extern bool cluster_resource_x_reconfig_zero_proof_exact( - const ResourceXReconfigToken *token, ResourceXZeroResidualProof *out); +extern bool cluster_resource_x_reconfig_cutover_begin_native_exact(ResourceXReconfigToken *out); +extern bool +cluster_resource_x_reconfig_cutover_bind_native_successor_exact(ResourceXReconfigToken *token); +extern ResourceXReconfigResult +cluster_resource_x_reconfig_sweep(const ResourceXReconfigToken *token, uint32 probe_budget, + ResourceXReconfigBatch *out); +extern bool cluster_resource_x_reconfig_zero_proof_exact(const ResourceXReconfigToken *token, + ResourceXZeroResidualProof *out); extern bool cluster_pcm_lock_resource_x_clean_completion_prove_exact( - const ResourceXReconfigToken *token, - const ResourceXZeroResidualProof *zero_proof, + const ResourceXReconfigToken *token, const ResourceXZeroResidualProof *zero_proof, ResourceXCleanCompletionProof *out); extern bool cluster_pcm_lock_resource_x_clean_completion_proof_exact( - const ResourceXReconfigToken *token, - const ResourceXZeroResidualProof *zero_proof, + const ResourceXReconfigToken *token, const ResourceXZeroResidualProof *zero_proof, ResourceXCleanCompletionProof *out); /* Read-only R11 prerequisite view of the current frozen R8/R10 pair. The * owning proof validators remain authoritative; this accessor only returns * exact copies after both live checks succeed for one token. */ -extern bool cluster_pcm_lock_resource_x_cutover_proofs_exact( - ResourceXReconfigToken *token_out, - ResourceXZeroResidualProof *zero_proof_out, - ResourceXCleanCompletionProof *clean_proof_out); +extern bool +cluster_pcm_lock_resource_x_cutover_proofs_exact(ResourceXReconfigToken *token_out, + ResourceXZeroResidualProof *zero_proof_out, + ResourceXCleanCompletionProof *clean_proof_out); /* Read-only post-thaw view of the same retained pair. The frozen accessor * above deliberately remains false after thaw. */ extern bool cluster_pcm_lock_resource_x_cutover_thawed_proofs_exact( - ResourceXReconfigToken *token_out, - ResourceXZeroResidualProof *zero_proof_out, + ResourceXReconfigToken *token_out, ResourceXZeroResidualProof *zero_proof_out, ResourceXCleanCompletionProof *clean_proof_out); /* Read the exact current R8/R10 pair and a local digest without accepting an * external formation coordinate. The returned token remains the only @@ -2216,19 +2111,24 @@ extern bool cluster_pcm_lock_resource_x_cutover_current_proof_digest_exact( bool thawed, ResourceXReconfigToken *token_out, uint64 *digest_out); extern bool cluster_resource_x_reconfig_thaw_exact(const ResourceXReconfigToken *token); extern void cluster_resource_x_reconfig_stats_snapshot(ResourceXReconfigStats *out); -extern ResourceXExecutorProbeResult cluster_pcm_lock_resource_x_executor_probe_exact( - const ResourceXAcquisitionRef *ref, ResourceXExecutorSnapshot *out_snapshot); -extern ResourceXApplyResult cluster_pcm_lock_resource_x_executor_wait_exact( - const ResourceXAcquisitionRef *ref, long timeout_ms); -extern ResourceXApplyResult cluster_pcm_lock_resource_x_executor_rearm_exact( - const ResourceXAcquisitionRef *ref); -extern ResourceXApplyResult cluster_pcm_lock_resource_x_requester_apply_exact( - const ResourceXAcquisitionRef *ref, const ResourceXBufferInstallProof *proof); -extern ResourceXApplyResult cluster_pcm_lock_resource_x_requester_activate_exact( - const ResourceXAcquisitionRef *ref, const ResourceXBufferActivationProof *proof); +extern ResourceXExecutorProbeResult +cluster_pcm_lock_resource_x_executor_probe_exact(const ResourceXAcquisitionRef *ref, + ResourceXExecutorSnapshot *out_snapshot); +extern ResourceXApplyResult +cluster_pcm_lock_resource_x_executor_wait_exact(const ResourceXAcquisitionRef *ref, + long timeout_ms); +extern ResourceXApplyResult +cluster_pcm_lock_resource_x_executor_rearm_exact(const ResourceXAcquisitionRef *ref); +extern ResourceXApplyResult +cluster_pcm_lock_resource_x_requester_apply_exact(const ResourceXAcquisitionRef *ref, + const ResourceXBufferInstallProof *proof); +extern ResourceXApplyResult +cluster_pcm_lock_resource_x_requester_activate_exact(const ResourceXAcquisitionRef *ref, + const ResourceXBufferActivationProof *proof); extern void cluster_pcm_lock_resource_x_o1_stats_snapshot(ResourceXO1Stats *out); -extern void cluster_pcm_lock_resource_x_publish_no_progress_exact( - const ResourceXAcquisitionRef *ref, ResourceXNoProgressReason reason); +extern void +cluster_pcm_lock_resource_x_publish_no_progress_exact(const ResourceXAcquisitionRef *ref, + ResourceXNoProgressReason reason); extern int cluster_pcm_grd_count(void); extern void cluster_pcm_grd_get_summary(int *n_count, int *s_count, int *x_count, int *pi_holders_total, int *convert_queue_active); diff --git a/src/include/cluster/cluster_pcm_own.h b/src/include/cluster/cluster_pcm_own.h index 914fdeda097..6372da4b912 100644 --- a/src/include/cluster/cluster_pcm_own.h +++ b/src/include/cluster/cluster_pcm_own.h @@ -65,9 +65,9 @@ typedef struct ClusterPcmOwnEntry { pg_atomic_uint64 reservation_token; /* monotone; active iff a transient flag is set */ pg_atomic_uint64 writer_activation_token; /* committed X not yet activated under content X */ pg_atomic_uint64 resource_x_activation_generation; /* target T2 bound, T3 not yet open */ - pg_atomic_uint32 flags; /* PCM_OWN_FLAG_* */ - uint32 _pad; /* keep naturally aligned */ - pg_atomic_uint64 delivery_attempt; /* non-authoritative target residency hold */ + pg_atomic_uint32 flags; /* PCM_OWN_FLAG_* */ + uint32 _pad; /* keep naturally aligned */ + pg_atomic_uint64 delivery_attempt; /* non-authoritative target residency hold */ } ClusterPcmOwnEntry; StaticAssertDecl(sizeof(ClusterPcmOwnEntry) == 48, "ClusterPcmOwnEntry must remain 48 bytes"); @@ -147,24 +147,27 @@ cluster_pcm_own_writer_grant_commit_exact(int buf_id, uint64 expected_generation /* Clear only the exact committed generation/token after content-EXCLUSIVE * activation proof or after exact queue-claim cleanup. */ extern ClusterPcmOwnResult cluster_pcm_own_writer_activation_clear_exact(int buf_id, - uint64 expected_generation, - uint64 reservation_token); + uint64 expected_generation, + uint64 reservation_token); /* Resource-X T2 binds its acquisition generation only while the exact writer * fence is closed. Normal T3 clears the generation first and the writer * token second. Generic legacy clear is forbidden while this binding lives. */ -extern ClusterPcmOwnResult cluster_pcm_own_resource_x_activation_bind_exact( - int buf_id, uint64 expected_generation, uint64 reservation_token, - uint64 acquisition_generation); -extern ClusterPcmOwnResult cluster_pcm_own_resource_x_activation_clear_exact( - int buf_id, uint64 expected_generation, uint64 reservation_token, - uint64 acquisition_generation); +extern ClusterPcmOwnResult +cluster_pcm_own_resource_x_activation_bind_exact(int buf_id, uint64 expected_generation, + uint64 reservation_token, + uint64 acquisition_generation); +extern ClusterPcmOwnResult +cluster_pcm_own_resource_x_activation_clear_exact(int buf_id, uint64 expected_generation, + uint64 reservation_token, + uint64 acquisition_generation); /* R8 recovery-owner clear: unlike normal T3, this advances the descriptor * ownership generation while clearing both activation fields. The bufmgr * caller changes the descriptor to a non-writable N+PI shape under the same * header-lock hold. */ -extern ClusterPcmOwnResult cluster_pcm_own_resource_x_neutralize_exact( - int buf_id, uint64 expected_generation, uint64 reservation_token, - uint64 acquisition_generation, uint64 *out_neutral_generation); +extern ClusterPcmOwnResult +cluster_pcm_own_resource_x_neutralize_exact(int buf_id, uint64 expected_generation, + uint64 reservation_token, uint64 acquisition_generation, + uint64 *out_neutral_generation); /* PCM-X retained-image revoke: commit advances the ownership generation but * deliberately leaves the exact REVOKING token live until DRAIN proves the * immutable image record is no longer needed. Release clears only that diff --git a/src/include/cluster/cluster_qvotec.h b/src/include/cluster/cluster_qvotec.h index b21070e49fa..b83692615f0 100644 --- a/src/include/cluster/cluster_qvotec.h +++ b/src/include/cluster/cluster_qvotec.h @@ -112,7 +112,7 @@ #include "port/atomics.h" #include "storage/lwlock.h" -#include "cluster/cluster_conf.h" /* CLUSTER_MAX_NODES */ +#include "cluster/cluster_conf.h" /* CLUSTER_MAX_NODES */ #include "cluster/cluster_semantic_activation.h" /* record types */ @@ -221,12 +221,10 @@ typedef struct ClusterQvotecMailboxCompletion { } ClusterQvotecMailboxCompletion; #ifdef USE_PGRAC_CLUSTER -StaticAssertDecl(CLUSTER_QVOTEC_MAILBOX_NONE == 0 - && CLUSTER_QVOTEC_MAILBOX_RECOVER_HEAD == 1 +StaticAssertDecl(CLUSTER_QVOTEC_MAILBOX_NONE == 0 && CLUSTER_QVOTEC_MAILBOX_RECOVER_HEAD == 1 && CLUSTER_QVOTEC_MAILBOX_PROPOSE_VALUE == 2, "ClusterQvotecMailbox request opcode values are frozen"); -StaticAssertDecl(CLUSTER_QVOTEC_MAILBOX_RESULT_NONE == 0 - && CLUSTER_QVOTEC_MAILBOX_CHOSEN == 1 +StaticAssertDecl(CLUSTER_QVOTEC_MAILBOX_RESULT_NONE == 0 && CLUSTER_QVOTEC_MAILBOX_CHOSEN == 1 && CLUSTER_QVOTEC_MAILBOX_ADOPTED_OTHER == 2 && CLUSTER_QVOTEC_MAILBOX_HOLD == 3, "ClusterQvotecMailbox completion result values are frozen"); @@ -430,23 +428,24 @@ extern void cluster_qvotec_observe(ClusterQvotecObservation *out); * are volatile and carry no authority across a process restart. */ extern void cluster_qvotec_mailbox_restart_reset(ClusterQvotecMailbox *mailbox); -extern ClusterQvotecMailboxSubmitStatus cluster_qvotec_mailbox_lmon_submit( - ClusterQvotecMailbox *mailbox, ClusterQvotecMailboxOpcode opcode, - const uint8 request_value[CLUSTER_QVOTEC_AUTHORITY_VALUE_BYTES], uint64 *request_seq_out); +extern ClusterQvotecMailboxSubmitStatus +cluster_qvotec_mailbox_lmon_submit(ClusterQvotecMailbox *mailbox, ClusterQvotecMailboxOpcode opcode, + const uint8 request_value[CLUSTER_QVOTEC_AUTHORITY_VALUE_BYTES], + uint64 *request_seq_out); extern bool cluster_qvotec_mailbox_qvotec_poll(ClusterQvotecMailbox *mailbox, - ClusterQvotecMailboxRequest *request_out); -extern bool cluster_qvotec_mailbox_qvotec_complete( - ClusterQvotecMailbox *mailbox, uint8 configured_disk_bitmap, - const ClusterQvotecMailboxCompletion *completion); -extern bool cluster_qvotec_mailbox_lmon_poll_completion( - ClusterQvotecMailbox *mailbox, uint64 request_seq, - ClusterQvotecMailboxCompletion *completion_out); + ClusterQvotecMailboxRequest *request_out); +extern bool +cluster_qvotec_mailbox_qvotec_complete(ClusterQvotecMailbox *mailbox, uint8 configured_disk_bitmap, + const ClusterQvotecMailboxCompletion *completion); +extern bool +cluster_qvotec_mailbox_lmon_poll_completion(ClusterQvotecMailbox *mailbox, uint64 request_seq, + ClusterQvotecMailboxCompletion *completion_out); extern ClusterQvotecMailboxSubmitStatus cluster_qvotec_authority_lmon_submit( ClusterQvotecMailboxOpcode opcode, - const uint8 request_value[CLUSTER_QVOTEC_AUTHORITY_VALUE_BYTES], - uint64 *request_seq_out); -extern bool cluster_qvotec_authority_lmon_poll_completion( - uint64 request_seq, ClusterQvotecMailboxCompletion *completion_out); + const uint8 request_value[CLUSTER_QVOTEC_AUTHORITY_VALUE_BYTES], uint64 *request_seq_out); +extern bool +cluster_qvotec_authority_lmon_poll_completion(uint64 request_seq, + ClusterQvotecMailboxCompletion *completion_out); /* ---------- @@ -550,10 +549,8 @@ extern pid_t cluster_postmaster_start_qvotec(void); /* RF-ROOT P9 verification (implementation): read-only startup read of the R4 * semantic-activation record tail (strict majority; zero writes). */ -extern ClusterSemanticActivationResult -cluster_qvotec_bootstrap_read_semantic_activation( - uint8 selected[CLUSTER_SEMANTIC_ACTIVATION_RECORD_BYTES], - bool *implicit_open); +extern ClusterSemanticActivationResult cluster_qvotec_bootstrap_read_semantic_activation( + uint8 selected[CLUSTER_SEMANTIC_ACTIVATION_RECORD_BYTES], bool *implicit_open); /* Startup-only read of the shared PGRD through the existing strict selector. * No provision/CAS and no use of QVOTEC's process-private descriptors. */ diff --git a/src/include/cluster/cluster_r4_observe.h b/src/include/cluster/cluster_r4_observe.h index 3b3d188b77a..dcf467c0eef 100644 --- a/src/include/cluster/cluster_r4_observe.h +++ b/src/include/cluster/cluster_r4_observe.h @@ -49,7 +49,7 @@ typedef enum ClusterR4RefusalStage { + CLUSTER_R4_REFUSAL_STAGE_COUNT * CLUSTER_R4_REFUSAL_REASON_COUNT) extern void cluster_r4_observe(ClusterR4Event event, ClusterTxResolveReason tx_reason, - ClusterCrBuildReason cr_reason); + ClusterCrBuildReason cr_reason); extern const char *cluster_r4_refusal_stage_name(ClusterR4RefusalStage stage); extern void cluster_r4_observe_refusal(ClusterR4RefusalStage stage, ClusterCrBuildReason reason, const BufferTag *tag, uint64 request_id, uint64 epoch, diff --git a/src/include/cluster/cluster_reconfig.h b/src/include/cluster/cluster_reconfig.h index 308228653cf..ceae194972c 100644 --- a/src/include/cluster/cluster_reconfig.h +++ b/src/include/cluster/cluster_reconfig.h @@ -541,8 +541,8 @@ extern void cluster_reconfig_get_last_event(ReconfigEvent *out); * reconfig event -- the GRD recovery IDLE tick must hold its baseline instead * of re-capturing the post-bump epoch (else WAIT_EPOCH wedges). */ extern bool cluster_reconfig_has_pending_prebump_stage(void); -extern bool cluster_reconfig_capture_formation_snapshot_v1( - uint16 origin_thread, struct ClusterFormationSnapshotV1 *out); +extern bool cluster_reconfig_capture_formation_snapshot_v1(uint16 origin_thread, + struct ClusterFormationSnapshotV1 *out); /* ============================================================ @@ -636,53 +636,45 @@ extern uint64 cluster_reconfig_compute_event_id_v2( /* Build, but do not publish or apply, the exact node-local kind-6 observer * assertion. Durable JCMK/ballot recovery remains the caller's prerequisite. */ -extern bool cluster_reconfig_build_replacement_committed_event( - const ClusterReplacementEpisode *episode, int32 observer_role, - TimestampTz applied_at, ReconfigEvent *out_event); +extern bool +cluster_reconfig_build_replacement_committed_event(const ClusterReplacementEpisode *episode, + int32 observer_role, TimestampTz applied_at, + ReconfigEvent *out_event); /* Pure replacement-GRD basis gate. The caller supplies a locally published * kind-6 assertion and a majority-recovered COMMITTED_CLOSED marker; success * exposes only the immutable durable survivor set and committed epoch. */ extern bool cluster_reconfig_replacement_grd_basis_authorized( const ReconfigEvent *event, const ClusterReplacementEpisode *episode, - const ClusterReplacementCommitMarkerV3 *committed_marker, - int32 local_node_id, - uint8 out_survivors[CLUSTER_RECONFIG_DEAD_BITMAP_BYTES], - uint64 *out_epoch); + const ClusterReplacementCommitMarkerV3 *committed_marker, int32 local_node_id, + uint8 out_survivors[CLUSTER_RECONFIG_DEAD_BITMAP_BYTES], uint64 *out_epoch); extern bool cluster_reconfig_lmon_snapshot_replacement_grd_basis( - uint8 out_survivors[CLUSTER_RECONFIG_DEAD_BITMAP_BYTES], - uint64 *out_epoch); + uint8 out_survivors[CLUSTER_RECONFIG_DEAD_BITMAP_BYTES], uint64 *out_epoch); /* Phase-1 opcode-18 pre-mutation gate. This only validates the already- * recovered RESERVE/ballot, durable PREPARE and node-local episode; it neither * publishes the target fence nor performs purge/ACK work. */ extern bool cluster_reconfig_replacement_purge_request_authorized( - const ClusterReplacementWireMessage *request, - int32 authenticated_source_node_id, int32 local_receiver_node_id, - const ClusterEpochAuthorityValue *settled_reserve, + const ClusterReplacementWireMessage *request, int32 authenticated_source_node_id, + int32 local_receiver_node_id, const ClusterEpochAuthorityValue *settled_reserve, const ClusterEpochBallotId *settled_ballot, const ClusterReplacementCommitMarkerV3 *durable_prepare); extern bool cluster_reconfig_replacement_purge_request_ingress_authorized( const ClusterICEnvelope *env, const void *payload, uint32 payload_length, int32 authenticated_source_node_id, int32 local_receiver_node_id, - const ClusterEpochAuthorityValue *settled_reserve, - const ClusterEpochBallotId *settled_ballot, + const ClusterEpochAuthorityValue *settled_reserve, const ClusterEpochBallotId *settled_ballot, const ClusterReplacementCommitMarkerV3 *durable_prepare, ClusterReplacementWireMessage *out_request); extern bool cluster_reconfig_replacement_purge_ack_authorized( - const ClusterReplacementWireMessage *ack, - int32 authenticated_source_node_id, int32 local_receiver_node_id, - const ClusterEpochAuthorityValue *settled_reserve, + const ClusterReplacementWireMessage *ack, int32 authenticated_source_node_id, + int32 local_receiver_node_id, const ClusterEpochAuthorityValue *settled_reserve, const ClusterEpochBallotId *settled_ballot, - const ClusterReplacementCommitMarkerV3 *durable_prepare, - int32 *out_ack_node_id); + const ClusterReplacementCommitMarkerV3 *durable_prepare, int32 *out_ack_node_id); extern bool cluster_reconfig_replacement_purge_ack_ingress_authorized( const ClusterICEnvelope *env, const void *payload, uint32 payload_length, int32 authenticated_source_node_id, int32 local_receiver_node_id, - const ClusterEpochAuthorityValue *settled_reserve, - const ClusterEpochBallotId *settled_ballot, - const ClusterReplacementCommitMarkerV3 *durable_prepare, - int32 *out_ack_node_id); + const ClusterEpochAuthorityValue *settled_reserve, const ClusterEpochBallotId *settled_ballot, + const ClusterReplacementCommitMarkerV3 *durable_prepare, int32 *out_ack_node_id); /* * spec-5.15 D1/D4 — qvotec publishes the freshest observed voting-slot @@ -726,8 +718,7 @@ extern bool cluster_reconfig_get_observed_fresh_alive(int32 node_id); extern void cluster_reconfig_bootstrap_publish_begin(void); extern void cluster_reconfig_bootstrap_publish_in_quorum(bool in_quorum); extern void cluster_reconfig_bootstrap_publish_end(void); -extern bool cluster_reconfig_bootstrap_proof_node(int32 node_id, - uint64 *out_incarnation); +extern bool cluster_reconfig_bootstrap_proof_node(int32 node_id, uint64 *out_incarnation); /* * spec-5.15 Hardening v1.1 (HF-1 / INV-J9): true iff a majority of the current @@ -787,25 +778,25 @@ cluster_reconfig_submit_join_marker(int32 target_node, const ClusterJoinCommitMa extern bool cluster_reconfig_submit_join_marker_async(ClusterMarkerAsync *a, int32 target_node, const ClusterJoinCommitMarker *m, ClusterMarkerAsyncKind kind, TimestampTz now); -extern bool cluster_reconfig_submit_replacement_marker_v3_async( - ClusterMarkerAsync *a, int32 target_node, - const ClusterReplacementCommitMarkerV3 *marker, - ClusterMarkerAsyncKind kind, TimestampTz now); -extern bool cluster_reconfig_verify_replacement_committed_closed_async( - ClusterMarkerAsync *a, int32 target_node, TimestampTz now); +extern bool +cluster_reconfig_submit_replacement_marker_v3_async(ClusterMarkerAsync *a, int32 target_node, + const ClusterReplacementCommitMarkerV3 *marker, + ClusterMarkerAsyncKind kind, TimestampTz now); +extern bool cluster_reconfig_verify_replacement_committed_closed_async(ClusterMarkerAsync *a, + int32 target_node, + TimestampTz now); extern ClusterMarkerPollResult cluster_reconfig_poll_join_marker_async(ClusterMarkerAsync *a, - TimestampTz now, - uint32 *out_result, - uint64 *out_elapsed_us); -extern bool cluster_reconfig_join_qvotec_poll_pending( - ClusterJoinMarkerMailboxOperationV1 *operation_out, - int32 *target_node_out, void *write_slot512_out); -extern void cluster_reconfig_join_qvotec_complete( - ClusterJoinMarkerMailboxOperationV1 operation, bool acked, - const uint8 *verified_image96); -extern bool cluster_reconfig_qvotec_lifecycle_transition( - ClusterQvotecMailbox *authority_mailbox, - pg_atomic_uint32 *qvotec_status, ClusterQvotecStatus next_status); + TimestampTz now, + uint32 *out_result, + uint64 *out_elapsed_us); +extern bool +cluster_reconfig_join_qvotec_poll_pending(ClusterJoinMarkerMailboxOperationV1 *operation_out, + int32 *target_node_out, void *write_slot512_out); +extern void cluster_reconfig_join_qvotec_complete(ClusterJoinMarkerMailboxOperationV1 operation, + bool acked, const uint8 *verified_image96); +extern bool cluster_reconfig_qvotec_lifecycle_transition(ClusterQvotecMailbox *authority_mailbox, + pg_atomic_uint32 *qvotec_status, + ClusterQvotecStatus next_status); extern void cluster_reconfig_publish_join_qvotec_latch(struct Latch *latch); /* RF-ROOT P9 verification / cold-formation cold-formation ruling — @@ -813,14 +804,13 @@ extern void cluster_reconfig_publish_join_qvotec_latch(struct Latch *latch); * LMON submits a COMMITTED marker + target co-boot member set; qvotec * writes it to every target member's slot on every disk and completes only * on a majority write + majority exact readback. */ -extern bool cluster_reconfig_formation_qvotec_poll_pending( - ClusterFormationMarkerSubmitRequest *out); +extern bool +cluster_reconfig_formation_qvotec_poll_pending(ClusterFormationMarkerSubmitRequest *out); extern void cluster_reconfig_formation_qvotec_complete(bool success); -extern void cluster_reconfig_formation_qvotec_note_max_generation( - uint64 generation); -extern void cluster_reconfig_formation_qvotec_publish_observed( - const ClusterFormationCommitMarker *marker, - const uint64 *incarnation_by_node); +extern void cluster_reconfig_formation_qvotec_note_max_generation(uint64 generation); +extern void +cluster_reconfig_formation_qvotec_publish_observed(const ClusterFormationCommitMarker *marker, + const uint64 *incarnation_by_node); extern void cluster_reconfig_formation_qvotec_clear_observed(void); extern void cluster_reconfig_publish_formation_qvotec_latch(struct Latch *latch); extern void cluster_reconfig_cold_formation_tick(void); @@ -878,8 +868,8 @@ extern bool cluster_reconfig_self_join_admitted(void); /* RF-ROOT P6 */ * current QVOTEC peer identity, exact admitted membership, and the already- * published stripe face. It grants neither membership nor xid authority. */ extern bool cluster_reconfig_epoch0_late_founder_evidence_current(void); -extern bool cluster_reconfig_stage_pre_publish_join_handoff( - uint64 expected_self_incarnation, uint64 expected_predecessor_floor); +extern bool cluster_reconfig_stage_pre_publish_join_handoff(uint64 expected_self_incarnation, + uint64 expected_predecessor_floor); extern bool cluster_reconfig_pre_publish_join_handoff_current(void); /* spec-5.15A closed replacement admission. A canonical local ADMITTED @@ -887,29 +877,29 @@ extern bool cluster_reconfig_pre_publish_join_handoff_current(void); * closed. The later uniform-OPEN seam is declared separately below. */ extern bool cluster_reconfig_publish_replacement_member_closed( const ClusterReplacementEpisode *admitted_episode); -extern bool cluster_reconfig_qvotec_observe_replacement_admitted( - const int *fds, int n_disks, uint64 live_incarnation); +extern bool cluster_reconfig_qvotec_observe_replacement_admitted(const int *fds, int n_disks, + uint64 live_incarnation); /* Called only by the uniform-OPEN owner after the cluster-wide OPEN/ACK gate. * The local gate opens only when the caller's full episode and explicit * generation are byte-identical to the stored ADMITTED MEMBER episode. */ -extern bool cluster_reconfig_open_replacement_admission( - const ClusterReplacementEpisode *expected_episode, - uint32 expected_state_generation); +extern bool +cluster_reconfig_open_replacement_admission(const ClusterReplacementEpisode *expected_episode, + uint32 expected_state_generation); /* Formation-LMON-only phase-3 observer. The authenticated handoff alone can * never write JCMK, publish MEMBER, or open admission. */ -extern bool cluster_reconfig_lmon_observe_replacement_ready( - const ClusterReplacementPhase3HandoffItem *item); -extern bool cluster_reconfig_lmon_build_replacement_admitted( - const ClusterEpochAuthorityValue *terminal_head, - ClusterReplacementCommitMarkerV3 *out_marker); +extern bool +cluster_reconfig_lmon_observe_replacement_ready(const ClusterReplacementPhase3HandoffItem *item); +extern bool +cluster_reconfig_lmon_build_replacement_admitted(const ClusterEpochAuthorityValue *terminal_head, + ClusterReplacementCommitMarkerV3 *out_marker); extern bool cluster_reconfig_lmon_finalize_replacement_admitted( const ClusterEpochAuthorityValue *terminal_head, const ClusterReplacementCommitMarkerV3 *admitted_marker); -extern bool cluster_reconfig_lmon_snapshot_replacement_admitted( - ClusterReplacementEpisode *out_episode, - ClusterReplacementCommitMarkerV3 *out_marker); +extern bool +cluster_reconfig_lmon_snapshot_replacement_admitted(ClusterReplacementEpisode *out_episode, + ClusterReplacementCommitMarkerV3 *out_marker); /* D13 initial-clean formation basis. This stack-only image is not a new * authority: it exposes the exact current four-node identity only while every @@ -938,14 +928,13 @@ typedef struct ClusterR4MembershipSnapshot { uint64 local_self_boot_incarnation; } ClusterR4MembershipSnapshot; -extern bool cluster_reconfig_snapshot_initial_clean_formation( - ClusterInitialCleanFormationSnapshot *out); -extern bool cluster_reconfig_lmon_snapshot_r4_membership( - ClusterR4MembershipSnapshot *out); +extern bool +cluster_reconfig_snapshot_initial_clean_formation(ClusterInitialCleanFormationSnapshot *out); +extern bool cluster_reconfig_lmon_snapshot_r4_membership(ClusterR4MembershipSnapshot *out); /* Formation-LMON-only coherent MEMBER/epoch sample for PGSA reconstruction. */ -extern bool cluster_reconfig_lmon_snapshot_admitted_membership( - uint64 *out_members_lo, uint64 *out_members_hi, - uint64 *out_formation_epoch); +extern bool cluster_reconfig_lmon_snapshot_admitted_membership(uint64 *out_members_lo, + uint64 *out_members_hi, + uint64 *out_formation_epoch); /* Existing exact terminal receipt proof may replace remote online liveness * only for normal-stop observation. No new admission or mutable authority. */ extern bool cluster_reconfig_normal_stop_snapshot_admitted_membership( @@ -958,15 +947,13 @@ extern void cluster_reconfig_lmon_replacement_ready_tick(void); extern void cluster_reconfig_lmon_replacement_admit_tick(void); extern void cluster_reconfig_lmon_replacement_closed_tick(void); extern ClusterReplacementCommittedClosedPublishResultV1 -cluster_reconfig_lmon_publish_replacement_committed_closed( - uint64 authority_request_seq, uint64 marker_request_seq); +cluster_reconfig_lmon_publish_replacement_committed_closed(uint64 authority_request_seq, + uint64 marker_request_seq); /* Reconfiguration is the sole owner of the replacement episode/JCMK * co-sample behind the public R4A prerequisite facade. */ -extern ClusterR4PrerequisiteSnapshot -cluster_reconfig_r4_prerequisite_snapshot(void); -extern bool cluster_reconfig_r4_publish_ready( - const ClusterR4PrerequisiteSnapshot *expected); +extern ClusterR4PrerequisiteSnapshot cluster_reconfig_r4_prerequisite_snapshot(void); +extern bool cluster_reconfig_r4_publish_ready(const ClusterR4PrerequisiteSnapshot *expected); /* ============================================================ diff --git a/src/include/cluster/cluster_recovery_duty.h b/src/include/cluster/cluster_recovery_duty.h index 84140a6e9e8..c93261edb37 100644 --- a/src/include/cluster/cluster_recovery_duty.h +++ b/src/include/cluster/cluster_recovery_duty.h @@ -81,8 +81,7 @@ typedef struct ClusterFormationSnapshotV1 { * this local tag. It authorizes no serving or write operation. */ #define CLUSTER_FORMATION_SNAPSHOT_RECOVERY_CONTROL UINT8_C(1) -StaticAssertDecl(sizeof(ClusterRecoveryDutyDigest) == 32, - "ClusterRecoveryDutyDigest ABI"); +StaticAssertDecl(sizeof(ClusterRecoveryDutyDigest) == 32, "ClusterRecoveryDutyDigest ABI"); /* Shared pure validity predicate for every consumer of the exact duty key. * Keeping this beside the canonical encoder prevents compact resource ids @@ -103,75 +102,70 @@ cluster_recovery_duty_key_valid_v1(const ClusterRecoveryDutyKey *key) } if (!storage_nonzero || !authority_nonzero || (key->authority_uuid[6] & UINT8_C(0xf0)) != UINT8_C(0x40) - || (key->authority_uuid[8] & UINT8_C(0xc0)) != UINT8_C(0x80) - || key->origin_thread_id == 0 - || key->origin_thread_id > CLUSTER_CONTROL_ROOT_RECORD_COUNT - || key->origin_node_id < 0 + || (key->authority_uuid[8] & UINT8_C(0xc0)) != UINT8_C(0x80) || key->origin_thread_id == 0 + || key->origin_thread_id > CLUSTER_CONTROL_ROOT_RECORD_COUNT || key->origin_node_id < 0 || key->origin_node_id >= CLUSTER_CONTROL_ROOT_RECORD_COUNT - || key->origin_thread_id != (uint16)(key->origin_node_id + 1) - || key->reserved42 != 0 || key->thread_claim_created_at == 0 - || key->thread_claim_crc32c == 0 || key->reserved60 != 0 - || key->origin_owner_incarnation == 0 || key->root_lineage_seq == 0) + || key->origin_thread_id != (uint16)(key->origin_node_id + 1) || key->reserved42 != 0 + || key->thread_claim_created_at == 0 || key->thread_claim_crc32c == 0 + || key->reserved60 != 0 || key->origin_owner_incarnation == 0 || key->root_lineage_seq == 0) return false; - cluster_wal_thread_claim_fill(&claim, key->origin_thread_id, - key->origin_node_id, - key->thread_claim_created_at); + cluster_wal_thread_claim_fill(&claim, key->origin_thread_id, key->origin_node_id, + key->thread_claim_created_at); return key->thread_claim_crc32c == claim.crc; } -extern bool cluster_recovery_duty_key_encode_v1( - const ClusterRecoveryDutyKey *key, - uint8 out[CLUSTER_RECOVERY_DUTY_KEY_V1_BYTES]); -extern ClusterRecoveryDutyCompare cluster_recovery_duty_key_compare( - const ClusterRecoveryDutyKey *expected, const ClusterRecoveryDutyKey *observed); +extern bool cluster_recovery_duty_key_encode_v1(const ClusterRecoveryDutyKey *key, + uint8 out[CLUSTER_RECOVERY_DUTY_KEY_V1_BYTES]); +extern ClusterRecoveryDutyCompare +cluster_recovery_duty_key_compare(const ClusterRecoveryDutyKey *expected, + const ClusterRecoveryDutyKey *observed); extern bool cluster_recovery_duty_digest_v1(const ClusterRecoveryDutyKey *key, - ClusterRecoveryDutyDigest *out); + ClusterRecoveryDutyDigest *out); extern ClusterRecoveryOwnerImportResult cluster_recovery_owner_import_select_v1( - int32 node_id, const ClusterWalThreadClaim *immutable_claim, - uint64 frozen_admitted_bitmap_low, uint64 frozen_admitted_bitmap_high, - const ClusterRecoveryOwnerDiskSampleV1 *samples, int total_disk_count, - uint64 *out_incarnation); -extern ClusterRecoveryOwnerImportResult cluster_recovery_owner_import_read_v1( - int32 node_id, const ClusterWalThreadClaim *immutable_claim, - uint64 frozen_admitted_bitmap_low, uint64 frozen_admitted_bitmap_high, - uint64 *out_incarnation); -extern bool cluster_recovery_owner_rejoin_v1(int32 node_id, - uint64 admitted_incarnation); + int32 node_id, const ClusterWalThreadClaim *immutable_claim, uint64 frozen_admitted_bitmap_low, + uint64 frozen_admitted_bitmap_high, const ClusterRecoveryOwnerDiskSampleV1 *samples, + int total_disk_count, uint64 *out_incarnation); +extern ClusterRecoveryOwnerImportResult +cluster_recovery_owner_import_read_v1(int32 node_id, const ClusterWalThreadClaim *immutable_claim, + uint64 frozen_admitted_bitmap_low, + uint64 frozen_admitted_bitmap_high, uint64 *out_incarnation); +extern bool cluster_recovery_owner_rejoin_v1(int32 node_id, uint64 admitted_incarnation); extern bool cluster_control_root_thread_clean_close_publish(void); /* RF-ROOT P6 */ -extern bool cluster_control_root_thread_clean_close_publish_retry(void); /* RF-ROOT P7 recovery path */ -extern bool cluster_control_root_thread_open_publish( - uint64 boot_incarnation); /* RF-ROOT P6 */ +extern bool +cluster_control_root_thread_clean_close_publish_retry(void); /* RF-ROOT P7 recovery path */ +extern bool cluster_control_root_thread_open_publish(uint64 boot_incarnation); /* RF-ROOT P6 */ extern bool cluster_control_root_checkpoint_advance_publish( - XLogRecPtr redo, TimeLineID tli, XLogRecPtr ckpt_record_start, - XLogRecPtr ckpt_record_end, uint32 record_crc32c); /* RF-ROOT P7 G1a */ + XLogRecPtr redo, TimeLineID tli, XLogRecPtr ckpt_record_start, XLogRecPtr ckpt_record_end, + uint32 record_crc32c); /* RF-ROOT P7 G1a */ extern bool cluster_control_root_fpw_sticky_publish(void); /* RF-ROOT P7 G1a-2 */ extern ClusterFormationWitnessResult cluster_formation_witness_decide_v1( const ClusterFormationSnapshotV1 *f1, const ClusterFenceAuthorityProof *authority, const ClusterFormationSnapshotV1 *f2, uint16 origin_thread, bool opening_new_duty); -extern ClusterFormationWitnessResult cluster_formation_witness_build_wait( - uint16 origin_thread, bool opening_new_duty, int timeout_ms, - ClusterFormationWitnessV1 **out); -extern ClusterFormationWitnessResult cluster_formation_witness_build_live_wait( - uint16 origin_thread, int timeout_ms, ClusterFormationWitnessV1 **out); extern ClusterFormationWitnessResult -cluster_formation_witness_build_recovery_control_wait( - uint16 origin_thread, int timeout_ms, ClusterFormationWitnessV1 **out); -extern ClusterFormationWitnessResult cluster_formation_witness_revalidate_nowait( - const ClusterFormationWitnessV1 *witness); -extern ClusterFormationWitnessResult cluster_formation_classification_revalidate_nowait( - uint16 origin_thread, const ClusterFenceAuthorityProof *authority, - const ClusterFormationSnapshotV1 *snapshot); -extern bool cluster_formation_snapshot_matches_v1( - const ClusterFormationSnapshotV1 *expected, - const ClusterFormationSnapshotV1 *observed); +cluster_formation_witness_build_wait(uint16 origin_thread, bool opening_new_duty, int timeout_ms, + ClusterFormationWitnessV1 **out); +extern ClusterFormationWitnessResult +cluster_formation_witness_build_live_wait(uint16 origin_thread, int timeout_ms, + ClusterFormationWitnessV1 **out); +extern ClusterFormationWitnessResult +cluster_formation_witness_build_recovery_control_wait(uint16 origin_thread, int timeout_ms, + ClusterFormationWitnessV1 **out); +extern ClusterFormationWitnessResult +cluster_formation_witness_revalidate_nowait(const ClusterFormationWitnessV1 *witness); +extern ClusterFormationWitnessResult +cluster_formation_classification_revalidate_nowait(uint16 origin_thread, + const ClusterFenceAuthorityProof *authority, + const ClusterFormationSnapshotV1 *snapshot); +extern bool cluster_formation_snapshot_matches_v1(const ClusterFormationSnapshotV1 *expected, + const ClusterFormationSnapshotV1 *observed); /* Copy the immutable classification already owned by an admitted witness. * This performs no current-state read; callers must separately revalidate the * same opaque witness before consuming the copy. */ extern bool cluster_formation_witness_copy_classification_v1( const ClusterFormationWitnessV1 *witness, uint16 *origin_thread, ClusterFenceAuthorityProof *authority, ClusterFormationSnapshotV1 *snapshot); -extern const ClusterFenceAuthorityProof *cluster_formation_witness_authority( - const ClusterFormationWitnessV1 *witness); +extern const ClusterFenceAuthorityProof * +cluster_formation_witness_authority(const ClusterFormationWitnessV1 *witness); extern void cluster_formation_witness_destroy(ClusterFormationWitnessV1 **witness); #endif /* CLUSTER_RECOVERY_DUTY_H */ diff --git a/src/include/cluster/cluster_recovery_merge.h b/src/include/cluster/cluster_recovery_merge.h index b1ee3e5a3d7..03554d0b956 100644 --- a/src/include/cluster/cluster_recovery_merge.h +++ b/src/include/cluster/cluster_recovery_merge.h @@ -352,10 +352,8 @@ typedef enum ClusterMergeClaimVerdict { * minus the one own-thread bit, and the ascending vector must name every * foreign bit exactly once. */ static inline bool -cluster_recovery_fence_plan_shape_valid(uint16 own_thread, - const uint64 replay[2], - const uint64 foreign[2], - const uint16 *origin_threads, +cluster_recovery_fence_plan_shape_valid(uint16 own_thread, const uint64 replay[2], + const uint64 foreign[2], const uint16 *origin_threads, uint16 origin_count) { uint64 expected_foreign[2]; @@ -363,37 +361,28 @@ cluster_recovery_fence_plan_shape_valid(uint16 own_thread, uint16 previous = 0; uint16 i; - if (own_thread == 0 || own_thread > CLUSTER_WAL_STATE_SLOT_COUNT || - replay == NULL || foreign == NULL || - origin_count > CLUSTER_WAL_STATE_SLOT_COUNT || - (origin_count > 0 && origin_threads == NULL)) + if (own_thread == 0 || own_thread > CLUSTER_WAL_STATE_SLOT_COUNT || replay == NULL + || foreign == NULL || origin_count > CLUSTER_WAL_STATE_SLOT_COUNT + || (origin_count > 0 && origin_threads == NULL)) return false; expected_foreign[0] = replay[0]; expected_foreign[1] = replay[1]; - if ((expected_foreign[(own_thread - 1) / 64] & - (UINT64_C(1) << ((own_thread - 1) % 64))) == 0) + if ((expected_foreign[(own_thread - 1) / 64] & (UINT64_C(1) << ((own_thread - 1) % 64))) == 0) return false; - expected_foreign[(own_thread - 1) / 64] &= - ~(UINT64_C(1) << ((own_thread - 1) % 64)); - if (expected_foreign[0] != foreign[0] || - expected_foreign[1] != foreign[1]) + expected_foreign[(own_thread - 1) / 64] &= ~(UINT64_C(1) << ((own_thread - 1) % 64)); + if (expected_foreign[0] != foreign[0] || expected_foreign[1] != foreign[1]) return false; - for (i = 0; i < origin_count; i++) - { + for (i = 0; i < origin_count; i++) { uint16 tid = origin_threads[i]; - if (tid == 0 || tid > CLUSTER_WAL_STATE_SLOT_COUNT || - tid == own_thread || tid <= previous || - (foreign[(tid - 1) / 64] & - (UINT64_C(1) << ((tid - 1) % 64))) == 0) + if (tid == 0 || tid > CLUSTER_WAL_STATE_SLOT_COUNT || tid == own_thread || tid <= previous + || (foreign[(tid - 1) / 64] & (UINT64_C(1) << ((tid - 1) % 64))) == 0) return false; previous = tid; } - for (i = 1; i <= CLUSTER_WAL_STATE_SLOT_COUNT; i++) - { - if ((foreign[(i - 1) / 64] & - (UINT64_C(1) << ((i - 1) % 64))) != 0) + for (i = 1; i <= CLUSTER_WAL_STATE_SLOT_COUNT; i++) { + if ((foreign[(i - 1) / 64] & (UINT64_C(1) << ((i - 1) % 64))) != 0) counted++; } return counted == origin_count; @@ -403,22 +392,18 @@ cluster_recovery_fence_plan_shape_valid(uint16 own_thread, * than the chosen replay owner is therefore a foreign destructive restore * and must hit the 58R17 negative gate before merged replay. */ static inline bool -cluster_recovery_restore_first_foreign(const uint64 bitmap[2], - uint16 own_thread, +cluster_recovery_restore_first_foreign(const uint64 bitmap[2], uint16 own_thread, uint16 *foreign_thread) { uint16 tid; - if (bitmap == NULL || own_thread == 0 || - own_thread > CLUSTER_WAL_STATE_SLOT_COUNT || foreign_thread == NULL) + if (bitmap == NULL || own_thread == 0 || own_thread > CLUSTER_WAL_STATE_SLOT_COUNT + || foreign_thread == NULL) return true; *foreign_thread = 0; - for (tid = 1; tid <= CLUSTER_WAL_STATE_SLOT_COUNT; tid++) - { - if (tid != own_thread && - (bitmap[(tid - 1) / 64] & - (UINT64_C(1) << ((tid - 1) % 64))) != 0) - { + for (tid = 1; tid <= CLUSTER_WAL_STATE_SLOT_COUNT; tid++) { + if (tid != own_thread + && (bitmap[(tid - 1) / 64] & (UINT64_C(1) << ((tid - 1) % 64))) != 0) { *foreign_thread = tid; return true; } @@ -427,13 +412,11 @@ cluster_recovery_restore_first_foreign(const uint64 bitmap[2], } static inline bool -cluster_recovery_restore_has_foreign(const uint64 bitmap[2], - uint16 own_thread) +cluster_recovery_restore_has_foreign(const uint64 bitmap[2], uint16 own_thread) { uint16 foreign_thread; - return cluster_recovery_restore_first_foreign( - bitmap, own_thread, &foreign_thread); + return cluster_recovery_restore_first_foreign(bitmap, own_thread, &foreign_thread); } static inline void @@ -504,21 +487,17 @@ typedef enum ClusterMergeEngage { * AdmissionSet. The caller obtains the merge claim only after this returns * ENGAGE, then acquires the STOP03 guard set and commits the unchanged plan * before copying its replay inputs. */ -extern ClusterMergeEngage cluster_recovery_merge_preflight_readonly( - uint16 own_thread, XLogRecPtr own_redo, ClusterRecoveryFencePlan **out_plan); -extern bool cluster_recovery_merge_fence_plan_acquire_serial( - ClusterRecoveryFencePlan *plan); -extern bool cluster_recovery_merge_commit_plan_nowait( - ClusterRecoveryFencePlan *plan); -extern bool cluster_recovery_merge_fence_plan_copy_replay( - const ClusterRecoveryFencePlan *plan, uint64 out_bitmap[2], - XLogRecPtr *out_start); -extern bool cluster_recovery_merge_fence_plan_revalidate_nowait( - ClusterRecoveryFencePlan *plan); -extern bool cluster_recovery_merge_fence_plan_release_serial( - ClusterRecoveryFencePlan *plan); -extern void cluster_recovery_merge_fence_plan_destroy( - ClusterRecoveryFencePlan **plan); +extern ClusterMergeEngage +cluster_recovery_merge_preflight_readonly(uint16 own_thread, XLogRecPtr own_redo, + ClusterRecoveryFencePlan **out_plan); +extern bool cluster_recovery_merge_fence_plan_acquire_serial(ClusterRecoveryFencePlan *plan); +extern bool cluster_recovery_merge_commit_plan_nowait(ClusterRecoveryFencePlan *plan); +extern bool cluster_recovery_merge_fence_plan_copy_replay(const ClusterRecoveryFencePlan *plan, + uint64 out_bitmap[2], + XLogRecPtr *out_start); +extern bool cluster_recovery_merge_fence_plan_revalidate_nowait(ClusterRecoveryFencePlan *plan); +extern bool cluster_recovery_merge_fence_plan_release_serial(ClusterRecoveryFencePlan *plan); +extern void cluster_recovery_merge_fence_plan_destroy(ClusterRecoveryFencePlan **plan); /* Sole-merger claim lifecycle (spec-6.14 D9 amend; see the pure core * above). acquire_blocking runs in PerformWalRecovery BEFORE the engage diff --git a/src/include/cluster/cluster_recovery_plan.h b/src/include/cluster/cluster_recovery_plan.h index 12e48588df4..2eb7c7294f6 100644 --- a/src/include/cluster/cluster_recovery_plan.h +++ b/src/include/cluster/cluster_recovery_plan.h @@ -147,9 +147,8 @@ cluster_recovery_classify_slot(ClusterWalSlotVerdict v, const ClusterWalStateSlo */ static inline ClusterRecoveryThreadVerdict cluster_recovery_classify_root_slot(ClusterControlRootResult root_result, - const ClusterControlRootSnapshot *snapshot, - uint16 own_thread, uint16 tid, int64 now_us, - int checkpoint_timeout_sec) + const ClusterControlRootSnapshot *snapshot, uint16 own_thread, + uint16 tid, int64 now_us, int checkpoint_timeout_sec) { int64 threshold_us; int64 age_us; @@ -160,13 +159,13 @@ cluster_recovery_classify_root_slot(ClusterControlRootResult root_result, return CLUSTER_RECOVERY_THREAD_EMPTY; if ((root_result != CLUSTER_CONTROL_ROOT_OK_PRIMARY && root_result != CLUSTER_CONTROL_ROOT_OK_PRIMARY_DEGRADED) - || snapshot->identity.origin_node_id != (int32) tid - 1) + || snapshot->identity.origin_node_id != (int32)tid - 1) return CLUSTER_RECOVERY_THREAD_UNKNOWN; if (snapshot->lifecycle == CLUSTER_CONTROL_ROOT_LIFECYCLE_CLOSED) return CLUSTER_RECOVERY_THREAD_CLEAN; if (snapshot->lifecycle != CLUSTER_CONTROL_ROOT_LIFECYCLE_OPEN) return CLUSTER_RECOVERY_THREAD_UNKNOWN; - threshold_us = (int64) Max(checkpoint_timeout_sec * 2, 60) * INT64CONST(1000000); + threshold_us = (int64)Max(checkpoint_timeout_sec * 2, 60) * INT64CONST(1000000); age_us = now_us - snapshot->published_at_usec; /* Boundary included in the alive side (mirrors the registry * classifier's <= stale window; ALIVE-biased per follow-up). */ @@ -308,14 +307,11 @@ cluster_thread_recovery_pin_fill(ClusterThreadReplaySlot *slot, static inline bool cluster_thread_recovery_projection_read(ClusterThreadReplaySlot *slot, uint64 episode_epoch, ClusterControlRootReadToken *token_out, - uint64 *validated_tail_out, - uint64 *checkpoint_lower_out, - uint64 *lifecycle_out, - uint32 *tail_tli_out, + uint64 *validated_tail_out, uint64 *checkpoint_lower_out, + uint64 *lifecycle_out, uint32 *tail_tli_out, uint32 *checkpoint_tli_out) { - if (slot == NULL - || pg_atomic_read_u64(&slot->episode_epoch) != episode_epoch) + if (slot == NULL || pg_atomic_read_u64(&slot->episode_epoch) != episode_epoch) return false; pg_read_barrier(); if (token_out != NULL) @@ -344,8 +340,7 @@ extern bool cluster_thread_recovery_projection_current(uint16 dead_tid, uint64 e ClusterControlRootReadToken *token_out, uint64 *validated_tail_out, uint64 *checkpoint_lower_out, - uint64 *lifecycle_out, - uint32 *tail_tli_out, + uint64 *lifecycle_out, uint32 *tail_tli_out, uint32 *checkpoint_tli_out); #endif /* !FRONTEND */ diff --git a/src/include/cluster/cluster_recovery_worker.h b/src/include/cluster/cluster_recovery_worker.h index afab3a2fe9f..5667870e853 100644 --- a/src/include/cluster/cluster_recovery_worker.h +++ b/src/include/cluster/cluster_recovery_worker.h @@ -197,9 +197,8 @@ cluster_recovery_worker_target_page(uint64 highest_lsn, int wal_segsz_bytes, uin static inline bool cluster_recovery_worker_root_anchor_valid(const ClusterControlRootSnapshot *snapshot) { - return snapshot != NULL - && snapshot->validated_tail_lsn_exclusive != 0 - && snapshot->tail_tli != 0; + return snapshot != NULL && snapshot->validated_tail_lsn_exclusive != 0 + && snapshot->tail_tli != 0; } #ifndef FRONTEND diff --git a/src/include/cluster/cluster_remote_xact.h b/src/include/cluster/cluster_remote_xact.h index e7149aa6ca1..3198d39e51c 100644 --- a/src/include/cluster/cluster_remote_xact.h +++ b/src/include/cluster/cluster_remote_xact.h @@ -214,40 +214,35 @@ typedef enum ClusterRemoteXactOutcome { #define CLUSTER_REMOTE_XACT_ENTRY_FLAG_WRAP_VALID UINT8_C(0x01) #define CLUSTER_REMOTE_XACT_RESET_MAX_ENTRIES UINT32_C(32768) -typedef enum ClusterRemoteXactStoredStateV2 -{ +typedef enum ClusterRemoteXactStoredStateV2 { CLUSTER_REMOTE_XACT_STORED_EMPTY = 0, CLUSTER_REMOTE_XACT_STORED_COMMITTED = 1, CLUSTER_REMOTE_XACT_STORED_ABORTED = 2, CLUSTER_REMOTE_XACT_STORED_PREPARED = 3 } ClusterRemoteXactStoredStateV2; -typedef struct ClusterRemoteXactEntryV2 -{ - uint8 payload[CLUSTER_REMOTE_XACT_ENTRY_PAYLOAD_BYTES]; - uint8 status; - uint8 format_version; - uint8 flags; - uint8 reserved_zero; +typedef struct ClusterRemoteXactEntryV2 { + uint8 payload[CLUSTER_REMOTE_XACT_ENTRY_PAYLOAD_BYTES]; + uint8 status; + uint8 format_version; + uint8 flags; + uint8 reserved_zero; } ClusterRemoteXactEntryV2; -StaticAssertDecl(sizeof(ClusterRemoteXactEntryV2) == - CLUSTER_REMOTE_XACT_ENTRY_BYTES, +StaticAssertDecl(sizeof(ClusterRemoteXactEntryV2) == CLUSTER_REMOTE_XACT_ENTRY_BYTES, "remote-xact v2 entry must be 32 bytes"); -typedef struct ClusterRemoteXactEntryDecodedV2 -{ +typedef struct ClusterRemoteXactEntryDecodedV2 { ClusterRemoteXactOutcome outcome; - SCN commit_scn; - int64 commit_timestamp; - uint16 wrap; - bool wrap_valid; + SCN commit_scn; + int64 commit_timestamp; + uint16 wrap; + bool wrap_valid; } ClusterRemoteXactEntryDecodedV2; static inline bool cluster_remote_xact_entry_encode_pending_v2( - ClusterRemoteXactEntryV2 *entry, - const uint8 digest[CLUSTER_REMOTE_XACT_PREPARE_DIGEST_BYTES]) + ClusterRemoteXactEntryV2 *entry, const uint8 digest[CLUSTER_REMOTE_XACT_PREPARE_DIGEST_BYTES]) { if (entry == NULL || digest == NULL) return false; @@ -263,115 +258,92 @@ cluster_remote_xact_entry_pending_matches_v2( const ClusterRemoteXactEntryV2 *entry, const uint8 digest[CLUSTER_REMOTE_XACT_PREPARE_DIGEST_BYTES]) { - if (entry == NULL || digest == NULL || - entry->status != CLUSTER_REMOTE_XACT_STORED_PREPARED || - entry->format_version != CLUSTER_REMOTE_XACT_ENTRY_FORMAT_V2 || - entry->flags != 0 || entry->reserved_zero != 0) + if (entry == NULL || digest == NULL || entry->status != CLUSTER_REMOTE_XACT_STORED_PREPARED + || entry->format_version != CLUSTER_REMOTE_XACT_ENTRY_FORMAT_V2 || entry->flags != 0 + || entry->reserved_zero != 0) return false; - return memcmp(entry->payload, digest, - CLUSTER_REMOTE_XACT_PREPARE_DIGEST_BYTES) == 0; + return memcmp(entry->payload, digest, CLUSTER_REMOTE_XACT_PREPARE_DIGEST_BYTES) == 0; } static inline bool -cluster_remote_xact_entry_encode_terminal_v2( - ClusterRemoteXactEntryV2 *entry, ClusterRemoteXactOutcome outcome, - SCN commit_scn, int64 commit_timestamp, bool wrap_valid, uint16 wrap) +cluster_remote_xact_entry_encode_terminal_v2(ClusterRemoteXactEntryV2 *entry, + ClusterRemoteXactOutcome outcome, SCN commit_scn, + int64 commit_timestamp, bool wrap_valid, uint16 wrap) { - if (entry == NULL || - (outcome != CLUSTER_REMOTE_XACT_COMMITTED && - outcome != CLUSTER_REMOTE_XACT_ABORTED)) + if (entry == NULL + || (outcome != CLUSTER_REMOTE_XACT_COMMITTED && outcome != CLUSTER_REMOTE_XACT_ABORTED)) return false; - if ((outcome == CLUSTER_REMOTE_XACT_COMMITTED && - (commit_scn == InvalidScn || commit_scn == 0 || - commit_timestamp == 0 || (wrap_valid && wrap == 0))) || - (outcome == CLUSTER_REMOTE_XACT_ABORTED && - (commit_scn != InvalidScn || commit_timestamp != 0 || - wrap_valid || wrap != 0))) + if ((outcome == CLUSTER_REMOTE_XACT_COMMITTED + && (commit_scn == InvalidScn || commit_timestamp == 0 || (wrap_valid && wrap == 0))) + || (outcome == CLUSTER_REMOTE_XACT_ABORTED + && (commit_scn != InvalidScn || commit_timestamp != 0 || wrap_valid || wrap != 0))) return false; memset(entry, 0, sizeof(*entry)); - if (outcome == CLUSTER_REMOTE_XACT_COMMITTED) - { + if (outcome == CLUSTER_REMOTE_XACT_COMMITTED) { memcpy(entry->payload, &commit_scn, sizeof(commit_scn)); - memcpy(entry->payload + 8, &commit_timestamp, - sizeof(commit_timestamp)); + memcpy(entry->payload + 8, &commit_timestamp, sizeof(commit_timestamp)); memcpy(entry->payload + 16, &wrap, sizeof(wrap)); entry->status = CLUSTER_REMOTE_XACT_STORED_COMMITTED; if (wrap_valid) entry->flags = CLUSTER_REMOTE_XACT_ENTRY_FLAG_WRAP_VALID; - } - else + } else entry->status = CLUSTER_REMOTE_XACT_STORED_ABORTED; entry->format_version = CLUSTER_REMOTE_XACT_ENTRY_FORMAT_V2; return true; } static inline bool -cluster_remote_xact_entry_decode_terminal_v2( - const ClusterRemoteXactEntryV2 *entry, - ClusterRemoteXactEntryDecodedV2 *decoded) +cluster_remote_xact_entry_decode_terminal_v2(const ClusterRemoteXactEntryV2 *entry, + ClusterRemoteXactEntryDecodedV2 *decoded) { ClusterRemoteXactEntryDecodedV2 candidate; - uint8 reserved = 0; - int i; - - if (entry == NULL || decoded == NULL || - entry->format_version != CLUSTER_REMOTE_XACT_ENTRY_FORMAT_V2 || - entry->reserved_zero != 0 || - (entry->flags & ~CLUSTER_REMOTE_XACT_ENTRY_FLAG_WRAP_VALID) != 0 || - (entry->status != CLUSTER_REMOTE_XACT_STORED_COMMITTED && - entry->status != CLUSTER_REMOTE_XACT_STORED_ABORTED)) + uint8 reserved = 0; + int i; + + if (entry == NULL || decoded == NULL + || entry->format_version != CLUSTER_REMOTE_XACT_ENTRY_FORMAT_V2 || entry->reserved_zero != 0 + || (entry->flags & ~CLUSTER_REMOTE_XACT_ENTRY_FLAG_WRAP_VALID) != 0 + || (entry->status != CLUSTER_REMOTE_XACT_STORED_COMMITTED + && entry->status != CLUSTER_REMOTE_XACT_STORED_ABORTED)) return false; for (i = 18; i < CLUSTER_REMOTE_XACT_ENTRY_PAYLOAD_BYTES; i++) reserved |= entry->payload[i]; if (reserved != 0) return false; memset(&candidate, 0, sizeof(candidate)); - if (entry->status == CLUSTER_REMOTE_XACT_STORED_COMMITTED) - { + if (entry->status == CLUSTER_REMOTE_XACT_STORED_COMMITTED) { candidate.outcome = CLUSTER_REMOTE_XACT_COMMITTED; - memcpy(&candidate.commit_scn, entry->payload, - sizeof(candidate.commit_scn)); - memcpy(&candidate.commit_timestamp, entry->payload + 8, - sizeof(candidate.commit_timestamp)); - memcpy(&candidate.wrap, entry->payload + 16, - sizeof(candidate.wrap)); - candidate.wrap_valid = (entry->flags & - CLUSTER_REMOTE_XACT_ENTRY_FLAG_WRAP_VALID) != 0; - if (candidate.commit_scn == InvalidScn || candidate.commit_scn == 0 || - candidate.commit_timestamp == 0 || - (candidate.wrap_valid && candidate.wrap == 0) || - (!candidate.wrap_valid && candidate.wrap != 0)) + memcpy(&candidate.commit_scn, entry->payload, sizeof(candidate.commit_scn)); + memcpy(&candidate.commit_timestamp, entry->payload + 8, sizeof(candidate.commit_timestamp)); + memcpy(&candidate.wrap, entry->payload + 16, sizeof(candidate.wrap)); + candidate.wrap_valid = (entry->flags & CLUSTER_REMOTE_XACT_ENTRY_FLAG_WRAP_VALID) != 0; + if (candidate.commit_scn == InvalidScn || candidate.commit_timestamp == 0 + || (candidate.wrap_valid && candidate.wrap == 0) + || (!candidate.wrap_valid && candidate.wrap != 0)) return false; - } - else - { + } else { candidate.outcome = CLUSTER_REMOTE_XACT_ABORTED; - if (entry->flags != 0 || entry->payload[0] != 0 || - entry->payload[1] != 0 || entry->payload[2] != 0 || - entry->payload[3] != 0 || entry->payload[4] != 0 || - entry->payload[5] != 0 || entry->payload[6] != 0 || - entry->payload[7] != 0 || entry->payload[8] != 0 || - entry->payload[9] != 0 || entry->payload[10] != 0 || - entry->payload[11] != 0 || entry->payload[12] != 0 || - entry->payload[13] != 0 || entry->payload[14] != 0 || - entry->payload[15] != 0 || entry->payload[16] != 0 || - entry->payload[17] != 0) + if (entry->flags != 0 || entry->payload[0] != 0 || entry->payload[1] != 0 + || entry->payload[2] != 0 || entry->payload[3] != 0 || entry->payload[4] != 0 + || entry->payload[5] != 0 || entry->payload[6] != 0 || entry->payload[7] != 0 + || entry->payload[8] != 0 || entry->payload[9] != 0 || entry->payload[10] != 0 + || entry->payload[11] != 0 || entry->payload[12] != 0 || entry->payload[13] != 0 + || entry->payload[14] != 0 || entry->payload[15] != 0 || entry->payload[16] != 0 + || entry->payload[17] != 0) return false; } *decoded = candidate; return true; } -typedef enum ClusterRemoteXactEntryTransitionV2 -{ +typedef enum ClusterRemoteXactEntryTransitionV2 { CLUSTER_REMOTE_XACT_ENTRY_WRITE = 0, CLUSTER_REMOTE_XACT_ENTRY_NOOP = 1, CLUSTER_REMOTE_XACT_ENTRY_CONFLICT = 2, CLUSTER_REMOTE_XACT_ENTRY_INVALID = 3 } ClusterRemoteXactEntryTransitionV2; -typedef enum ClusterRemoteXactMutationV2 -{ +typedef enum ClusterRemoteXactMutationV2 { CLUSTER_REMOTE_XACT_MUTATION_STORED = 0, CLUSTER_REMOTE_XACT_MUTATION_UNCHANGED = 1, CLUSTER_REMOTE_XACT_MUTATION_CONFLICT = 2, @@ -381,9 +353,9 @@ typedef enum ClusterRemoteXactMutationV2 static inline bool cluster_remote_xact_entry_is_empty_v2(const ClusterRemoteXactEntryV2 *entry) { - const uint8 *bytes = (const uint8 *) entry; - uint8 seen = 0; - Size i; + const uint8 *bytes = (const uint8 *)entry; + uint8 seen = 0; + Size i; if (entry == NULL) return false; @@ -395,24 +367,21 @@ cluster_remote_xact_entry_is_empty_v2(const ClusterRemoteXactEntryV2 *entry) static inline ClusterRemoteXactEntryTransitionV2 cluster_remote_xact_entry_prepare_transition_v2( const ClusterRemoteXactEntryV2 *current, - const uint8 digest[CLUSTER_REMOTE_XACT_PREPARE_DIGEST_BYTES], - ClusterRemoteXactEntryV2 *next) + const uint8 digest[CLUSTER_REMOTE_XACT_PREPARE_DIGEST_BYTES], ClusterRemoteXactEntryV2 *next) { if (current == NULL || digest == NULL || next == NULL) return CLUSTER_REMOTE_XACT_ENTRY_INVALID; - if (cluster_remote_xact_entry_is_empty_v2(current)) - { + if (cluster_remote_xact_entry_is_empty_v2(current)) { if (!cluster_remote_xact_entry_encode_pending_v2(next, digest)) return CLUSTER_REMOTE_XACT_ENTRY_INVALID; return CLUSTER_REMOTE_XACT_ENTRY_WRITE; } - if (cluster_remote_xact_entry_pending_matches_v2(current, digest)) - { + if (cluster_remote_xact_entry_pending_matches_v2(current, digest)) { *next = *current; return CLUSTER_REMOTE_XACT_ENTRY_NOOP; } - if (current->format_version != CLUSTER_REMOTE_XACT_ENTRY_FORMAT_V2 || - current->reserved_zero != 0) + if (current->format_version != CLUSTER_REMOTE_XACT_ENTRY_FORMAT_V2 + || current->reserved_zero != 0) return CLUSTER_REMOTE_XACT_ENTRY_INVALID; return CLUSTER_REMOTE_XACT_ENTRY_CONFLICT; } @@ -421,64 +390,57 @@ static inline ClusterRemoteXactEntryTransitionV2 cluster_remote_xact_entry_terminal_transition_v2( const ClusterRemoteXactEntryV2 *current, bool require_prepared, const uint8 expected_prepare_digest[CLUSTER_REMOTE_XACT_PREPARE_DIGEST_BYTES], - ClusterRemoteXactOutcome outcome, SCN commit_scn, - int64 commit_timestamp, bool wrap_valid, uint16 wrap, - ClusterRemoteXactEntryV2 *next) + ClusterRemoteXactOutcome outcome, SCN commit_scn, int64 commit_timestamp, bool wrap_valid, + uint16 wrap, ClusterRemoteXactEntryV2 *next) { ClusterRemoteXactEntryV2 candidate; ClusterRemoteXactEntryDecodedV2 decoded; - if (current == NULL || next == NULL || - (require_prepared && expected_prepare_digest == NULL) || - !cluster_remote_xact_entry_encode_terminal_v2(&candidate, outcome, - commit_scn, commit_timestamp, wrap_valid, wrap)) + if (current == NULL || next == NULL || (require_prepared && expected_prepare_digest == NULL) + || !cluster_remote_xact_entry_encode_terminal_v2(&candidate, outcome, commit_scn, + commit_timestamp, wrap_valid, wrap)) return CLUSTER_REMOTE_XACT_ENTRY_INVALID; - if (cluster_remote_xact_entry_is_empty_v2(current)) - { + if (cluster_remote_xact_entry_is_empty_v2(current)) { if (require_prepared) return CLUSTER_REMOTE_XACT_ENTRY_CONFLICT; *next = candidate; return CLUSTER_REMOTE_XACT_ENTRY_WRITE; } - if (memcmp(current, &candidate, sizeof(candidate)) == 0 && - cluster_remote_xact_entry_decode_terminal_v2(current, &decoded)) - { + if (memcmp(current, &candidate, sizeof(candidate)) == 0 + && cluster_remote_xact_entry_decode_terminal_v2(current, &decoded)) { *next = *current; return CLUSTER_REMOTE_XACT_ENTRY_NOOP; } - if (require_prepared && - cluster_remote_xact_entry_pending_matches_v2( - current, expected_prepare_digest)) - { + if (require_prepared + && cluster_remote_xact_entry_pending_matches_v2(current, expected_prepare_digest)) { *next = candidate; return CLUSTER_REMOTE_XACT_ENTRY_WRITE; } - if (current->format_version != CLUSTER_REMOTE_XACT_ENTRY_FORMAT_V2 || - current->reserved_zero != 0) + if (current->format_version != CLUSTER_REMOTE_XACT_ENTRY_FORMAT_V2 + || current->reserved_zero != 0) return CLUSTER_REMOTE_XACT_ENTRY_INVALID; return CLUSTER_REMOTE_XACT_ENTRY_CONFLICT; } static inline ClusterRemoteXactEntryTransitionV2 -cluster_remote_xact_entry_reset_transition_v2( - const ClusterRemoteXactEntryV2 *current, ClusterRemoteXactEntryV2 *next) +cluster_remote_xact_entry_reset_transition_v2(const ClusterRemoteXactEntryV2 *current, + ClusterRemoteXactEntryV2 *next) { if (current == NULL || next == NULL) return CLUSTER_REMOTE_XACT_ENTRY_INVALID; memset(next, 0, sizeof(*next)); /* Reset invalidates a projection scope. Corrupt or old bytes are safe to * erase because they are never canonical transaction truth. */ - return cluster_remote_xact_entry_is_empty_v2(current) - ? CLUSTER_REMOTE_XACT_ENTRY_NOOP : CLUSTER_REMOTE_XACT_ENTRY_WRITE; + return cluster_remote_xact_entry_is_empty_v2(current) ? CLUSTER_REMOTE_XACT_ENTRY_NOOP + : CLUSTER_REMOTE_XACT_ENTRY_WRITE; } static inline bool -cluster_remote_xact_reset_range_valid_v2(int origin_node, - TransactionId first_xid, uint32 count) +cluster_remote_xact_reset_range_valid_v2(int origin_node, TransactionId first_xid, uint32 count) { - return origin_node >= 0 && origin_node < (1 << 7) && count > 0 && - count <= CLUSTER_REMOTE_XACT_RESET_MAX_ENTRIES && - (uint64) first_xid + (uint64) count - 1 <= UINT32_MAX; + return origin_node >= 0 && origin_node < (1 << 7) && count > 0 + && count <= CLUSTER_REMOTE_XACT_RESET_MAX_ENTRIES + && (uint64)first_xid + (uint64)count - 1 <= UINT32_MAX; } /* shmem request/init plumbing (cluster_shmem.c / ipci path). */ @@ -512,27 +474,26 @@ extern void cluster_remote_xact_apply(int origin_node, struct XLogReaderState *r * must supply the digest frozen by the immutable SIDE plan; * missing/different projected state fails closed. */ -extern bool cluster_remote_xact_prepare_digest_v2( - uint64 system_identifier, int origin_node, TransactionId xid, - Oid database, const char *gid, - uint8 digest[CLUSTER_REMOTE_XACT_PREPARE_DIGEST_BYTES]); -extern ClusterRemoteXactMutationV2 cluster_remote_xact_store_prepared_v2( - int origin_node, TransactionId xid, - const uint8 digest[CLUSTER_REMOTE_XACT_PREPARE_DIGEST_BYTES]); +extern bool +cluster_remote_xact_prepare_digest_v2(uint64 system_identifier, int origin_node, TransactionId xid, + Oid database, const char *gid, + uint8 digest[CLUSTER_REMOTE_XACT_PREPARE_DIGEST_BYTES]); +extern ClusterRemoteXactMutationV2 +cluster_remote_xact_store_prepared_v2(int origin_node, TransactionId xid, + const uint8 digest[CLUSTER_REMOTE_XACT_PREPARE_DIGEST_BYTES]); extern ClusterRemoteXactMutationV2 cluster_remote_xact_store_terminal_v2( int origin_node, TransactionId xid, bool require_prepared, const uint8 expected_prepare_digest[CLUSTER_REMOTE_XACT_PREPARE_DIGEST_BYTES], - ClusterRemoteXactOutcome outcome, SCN commit_scn, - TimestampTz commit_timestamp, bool wrap_valid, uint16 wrap); + ClusterRemoteXactOutcome outcome, SCN commit_scn, TimestampTz commit_timestamp, bool wrap_valid, + uint16 wrap); extern bool cluster_remote_xact_pending_matches_v2( int origin_node, TransactionId xid, const uint8 digest[CLUSTER_REMOTE_XACT_PREPARE_DIGEST_BYTES]); -extern bool cluster_remote_xact_reset_range_v2(int origin_node, - TransactionId first_xid, uint32 count); -extern bool cluster_remote_xact_range_empty_v2(int origin_node, - TransactionId first_xid, uint32 count); -extern bool cluster_remote_xact_truncate_before_v2(int origin_node, - TransactionId oldest_xid); +extern bool cluster_remote_xact_reset_range_v2(int origin_node, TransactionId first_xid, + uint32 count); +extern bool cluster_remote_xact_range_empty_v2(int origin_node, TransactionId first_xid, + uint32 count); +extern bool cluster_remote_xact_truncate_before_v2(int origin_node, TransactionId oldest_xid); /* Flush any residual dirty SLRU pages (normal v2 mutations fsync inline). */ extern void cluster_remote_xact_flush(void); @@ -562,9 +523,9 @@ extern ClusterRemoteXactOutcome cluster_remote_outcome_terminal_authorized( extern ClusterRemoteXactOutcome cluster_remote_outcome_durable_checked(int origin_node, TransactionId xid, SCN *out_scn); extern ClusterRemoteXactOutcome cluster_remote_commit_outcome(int origin_node, TransactionId xid, - SCN *commit_scn); + SCN *commit_scn); extern bool cluster_remote_commit_timestamp(int origin_node, TransactionId xid, - TimestampTz *commit_timestamp); + TimestampTz *commit_timestamp); /* Observation counters (D11 dump). */ extern uint64 cluster_remote_xact_diverted_commit_count(void); diff --git a/src/include/cluster/cluster_replacement_episode.h b/src/include/cluster/cluster_replacement_episode.h index a716903257d..5359ff502ff 100644 --- a/src/include/cluster/cluster_replacement_episode.h +++ b/src/include/cluster/cluster_replacement_episode.h @@ -25,9 +25,9 @@ #define CLUSTER_REPLACEMENT_EPISODE_R4A_TARGET_READY UINT8_C(0x01) #define CLUSTER_REPLACEMENT_EPISODE_GRD_POSTEPOCH_READY UINT8_C(0x02) #define CLUSTER_REPLACEMENT_EPISODE_INTENT_CLEARED UINT8_C(0x08) -#define CLUSTER_REPLACEMENT_EPISODE_READINESS_MASK \ - (CLUSTER_REPLACEMENT_EPISODE_R4A_TARGET_READY \ - | CLUSTER_REPLACEMENT_EPISODE_GRD_POSTEPOCH_READY \ +#define CLUSTER_REPLACEMENT_EPISODE_READINESS_MASK \ + (CLUSTER_REPLACEMENT_EPISODE_R4A_TARGET_READY \ + | CLUSTER_REPLACEMENT_EPISODE_GRD_POSTEPOCH_READY \ | CLUSTER_REPLACEMENT_EPISODE_INTENT_CLEARED) typedef enum ClusterReplacementEpisodePhase { @@ -42,20 +42,20 @@ typedef enum ClusterReplacementEpisodePhase { } ClusterReplacementEpisodePhase; typedef struct ClusterReplacementEpisode { - uint64 request_nonce; /* 0 */ - uint64 baseline_epoch; /* 8 */ - uint64 reserved_or_committed_epoch; /* 16: exact baseline+1 */ - uint64 old_admitted_incarnation; /* 24 */ - uint64 fresh_incarnation; /* 32 */ - uint64 grammar_fingerprint; /* 40 */ + uint64 request_nonce; /* 0 */ + uint64 baseline_epoch; /* 8 */ + uint64 reserved_or_committed_epoch; /* 16: exact baseline+1 */ + uint64 old_admitted_incarnation; /* 24 */ + uint64 fresh_incarnation; /* 32 */ + uint64 grammar_fingerprint; /* 40 */ uint8 expected_survivors[CLUSTER_REPLACEMENT_EPISODE_BITMAP_BYTES]; /* 48 */ - uint8 acknowledgements[CLUSTER_REPLACEMENT_EPISODE_BITMAP_BYTES]; /* 64 */ - int32 target_node_id; /* 80 */ - int32 coordinator_node_id; /* 84 */ - uint32 state_generation; /* 88; zero means empty */ - uint8 phase; /* 92 */ - uint8 readiness_flags; /* 93 */ - uint8 reserved[2]; /* 94: zero */ + uint8 acknowledgements[CLUSTER_REPLACEMENT_EPISODE_BITMAP_BYTES]; /* 64 */ + int32 target_node_id; /* 80 */ + int32 coordinator_node_id; /* 84 */ + uint32 state_generation; /* 88; zero means empty */ + uint8 phase; /* 92 */ + uint8 readiness_flags; /* 93 */ + uint8 reserved[2]; /* 94: zero */ } ClusterReplacementEpisode; StaticAssertDecl(sizeof(ClusterReplacementEpisode) == CLUSTER_REPLACEMENT_EPISODE_BYTES, diff --git a/src/include/cluster/cluster_replacement_request.h b/src/include/cluster/cluster_replacement_request.h index 834d8c2c7dc..758418af69e 100644 --- a/src/include/cluster/cluster_replacement_request.h +++ b/src/include/cluster/cluster_replacement_request.h @@ -43,40 +43,34 @@ typedef enum ClusterReplacementRequestSlotState { CLUSTER_REPLACEMENT_REQUEST_SLOT_HOLD = 2 } ClusterReplacementRequestSlotState; -StaticAssertDecl(sizeof(ClusterReplacementRequestMarker) - == CLUSTER_REPLACEMENT_MARKER_BYTES, +StaticAssertDecl(sizeof(ClusterReplacementRequestMarker) == CLUSTER_REPLACEMENT_MARKER_BYTES, "replacement request marker host shape must remain 64 bytes"); -StaticAssertDecl(CLUSTER_REPLACEMENT_MARKER_RESERVED1_OFFSET - + CLUSTER_REPLACEMENT_MARKER_BYTES +StaticAssertDecl(CLUSTER_REPLACEMENT_MARKER_RESERVED1_OFFSET + CLUSTER_REPLACEMENT_MARKER_BYTES <= CLUSTER_REPLACEMENT_REQUEST_RESERVED1_BYTES, "replacement request marker must fit the voting-slot reserved1"); -extern bool cluster_replacement_request_encode( - const ClusterReplacementRequestMarker *marker, - uint8 out[CLUSTER_REPLACEMENT_MARKER_BYTES]); -extern bool cluster_replacement_request_decode( - const uint8 bytes[CLUSTER_REPLACEMENT_MARKER_BYTES], - int32 expected_target_node, ClusterReplacementRequestMarker *out); -extern bool cluster_replacement_request_pack( - uint8 reserved1[CLUSTER_REPLACEMENT_REQUEST_RESERVED1_BYTES], - const ClusterReplacementRequestMarker *marker); +extern bool cluster_replacement_request_encode(const ClusterReplacementRequestMarker *marker, + uint8 out[CLUSTER_REPLACEMENT_MARKER_BYTES]); +extern bool cluster_replacement_request_decode(const uint8 bytes[CLUSTER_REPLACEMENT_MARKER_BYTES], + int32 expected_target_node, + ClusterReplacementRequestMarker *out); +extern bool +cluster_replacement_request_pack(uint8 reserved1[CLUSTER_REPLACEMENT_REQUEST_RESERVED1_BYTES], + const ClusterReplacementRequestMarker *marker); extern bool cluster_replacement_request_unpack( - const uint8 reserved1[CLUSTER_REPLACEMENT_REQUEST_RESERVED1_BYTES], - int32 expected_target_node, ClusterReplacementRequestMarker *out); -extern void cluster_replacement_request_clear( - uint8 reserved1[CLUSTER_REPLACEMENT_REQUEST_RESERVED1_BYTES]); + const uint8 reserved1[CLUSTER_REPLACEMENT_REQUEST_RESERVED1_BYTES], int32 expected_target_node, + ClusterReplacementRequestMarker *out); +extern void +cluster_replacement_request_clear(uint8 reserved1[CLUSTER_REPLACEMENT_REQUEST_RESERVED1_BYTES]); extern bool cluster_replacement_request_is_clear( const uint8 reserved1[CLUSTER_REPLACEMENT_REQUEST_RESERVED1_BYTES]); extern ClusterReplacementRequestSlotState cluster_replacement_request_slot_state( - uint64 flags, - const uint8 reserved1[CLUSTER_REPLACEMENT_REQUEST_RESERVED1_BYTES], + uint64 flags, const uint8 reserved1[CLUSTER_REPLACEMENT_REQUEST_RESERVED1_BYTES], int32 expected_target_node, uint64 expected_slot_incarnation, ClusterReplacementRequestMarker *out); extern ClusterReplacementRequestSlotState cluster_replacement_request_preserve_per_disk( - uint64 prior_flags, - const uint8 prior_reserved1[CLUSTER_REPLACEMENT_REQUEST_RESERVED1_BYTES], - int32 expected_target_node, uint64 expected_slot_incarnation, - uint64 *new_flags, + uint64 prior_flags, const uint8 prior_reserved1[CLUSTER_REPLACEMENT_REQUEST_RESERVED1_BYTES], + int32 expected_target_node, uint64 expected_slot_incarnation, uint64 *new_flags, uint8 new_reserved1[CLUSTER_REPLACEMENT_REQUEST_RESERVED1_BYTES]); #endif /* CLUSTER_REPLACEMENT_REQUEST_H */ diff --git a/src/include/cluster/cluster_replacement_wire.h b/src/include/cluster/cluster_replacement_wire.h index 37b5bbd26b1..55d8dbde4d4 100644 --- a/src/include/cluster/cluster_replacement_wire.h +++ b/src/include/cluster/cluster_replacement_wire.h @@ -23,8 +23,7 @@ #define CLUSTER_REPLACEMENT_WIRE_BYTES 72 #define CLUSTER_REPLACEMENT_WIRE_BITMAP_BYTES 16 #define CLUSTER_REPLACEMENT_PHASE3_HANDOFF_CAPACITY 8 -#define CANDIDATE2_CORRECTED_A1_GRAMMAR_FINGERPRINT \ - UINT64_C(0x8e0dae5b428905e4) +#define CANDIDATE2_CORRECTED_A1_GRAMMAR_FINGERPRINT UINT64_C(0x8e0dae5b428905e4) typedef struct ClusterReplacementWirePhase3 { @@ -70,8 +69,7 @@ typedef struct ClusterReplacementPhase3HandoffItem { typedef struct ClusterReplacementPhase3Handoff { uint64 producer_seq; uint64 consumer_seq; - ClusterReplacementPhase3HandoffItem - items[CLUSTER_REPLACEMENT_PHASE3_HANDOFF_CAPACITY]; + ClusterReplacementPhase3HandoffItem items[CLUSTER_REPLACEMENT_PHASE3_HANDOFF_CAPACITY]; } ClusterReplacementPhase3Handoff; typedef enum ClusterReplacementPhase3IngressResult { @@ -81,38 +79,30 @@ typedef enum ClusterReplacementPhase3IngressResult { } ClusterReplacementPhase3IngressResult; -extern bool cluster_replacement_wire_encode( - const ClusterReplacementWireMessage *message, - uint8 out[CLUSTER_REPLACEMENT_WIRE_BYTES]); -extern bool cluster_replacement_wire_encode_phase3_snapshot( - const ClusterR4PrerequisiteSnapshot *snapshot, - uint8 out[CLUSTER_REPLACEMENT_WIRE_BYTES]); -extern bool cluster_replacement_wire_decode( - const uint8 bytes[CLUSTER_REPLACEMENT_WIRE_BYTES], - ClusterReplacementWireMessage *out); -extern void cluster_replacement_phase3_handoff_init( - ClusterReplacementPhase3Handoff *handoff); -extern uint32 cluster_replacement_phase3_handoff_pending( - const ClusterReplacementPhase3Handoff *handoff); -extern bool cluster_replacement_phase3_handoff_poll( - ClusterReplacementPhase3Handoff *handoff, - ClusterReplacementPhase3HandoffItem *out); -extern ClusterReplacementPhase3IngressResult -cluster_replacement_wire_phase3_ingress( - ClusterReplacementPhase3Handoff *handoff, const ClusterICEnvelope *env, - const void *payload, uint32 payload_length, int32 authenticated_source_node_id, - int32 local_receiver_node_id, uint64 current_epoch, - uint32 control_connection_generation); +extern bool cluster_replacement_wire_encode(const ClusterReplacementWireMessage *message, + uint8 out[CLUSTER_REPLACEMENT_WIRE_BYTES]); +extern bool +cluster_replacement_wire_encode_phase3_snapshot(const ClusterR4PrerequisiteSnapshot *snapshot, + uint8 out[CLUSTER_REPLACEMENT_WIRE_BYTES]); +extern bool cluster_replacement_wire_decode(const uint8 bytes[CLUSTER_REPLACEMENT_WIRE_BYTES], + ClusterReplacementWireMessage *out); +extern void cluster_replacement_phase3_handoff_init(ClusterReplacementPhase3Handoff *handoff); +extern uint32 +cluster_replacement_phase3_handoff_pending(const ClusterReplacementPhase3Handoff *handoff); +extern bool cluster_replacement_phase3_handoff_poll(ClusterReplacementPhase3Handoff *handoff, + ClusterReplacementPhase3HandoffItem *out); +extern ClusterReplacementPhase3IngressResult cluster_replacement_wire_phase3_ingress( + ClusterReplacementPhase3Handoff *handoff, const ClusterICEnvelope *env, const void *payload, + uint32 payload_length, int32 authenticated_source_node_id, int32 local_receiver_node_id, + uint64 current_epoch, uint32 control_connection_generation); /* Process-local ingress mailbox. GES CONTROL dispatch is its sole producer; * the formation LMON tick is its sole consumer. */ -extern ClusterReplacementPhase3IngressResult -cluster_replacement_wire_phase3_ingress_local( +extern ClusterReplacementPhase3IngressResult cluster_replacement_wire_phase3_ingress_local( const ClusterICEnvelope *env, const void *payload, uint32 payload_length, - int32 authenticated_source_node_id, int32 local_receiver_node_id, - uint64 current_epoch, uint32 control_connection_generation); -extern bool cluster_replacement_phase3_handoff_poll_local( - ClusterReplacementPhase3HandoffItem *out); + int32 authenticated_source_node_id, int32 local_receiver_node_id, uint64 current_epoch, + uint32 control_connection_generation); +extern bool cluster_replacement_phase3_handoff_poll_local(ClusterReplacementPhase3HandoffItem *out); extern uint32 cluster_replacement_phase3_handoff_pending_local(void); /* Raw owner observation, not authority: > capacity (including NULL) is * invalid, never empty. The caller must establish the owning LMON context. */ diff --git a/src/include/cluster/cluster_resource_x_identity.h b/src/include/cluster/cluster_resource_x_identity.h index 5fdb5c8217c..482e815746d 100644 --- a/src/include/cluster/cluster_resource_x_identity.h +++ b/src/include/cluster/cluster_resource_x_identity.h @@ -18,31 +18,27 @@ #define RESOURCE_X_PROOF_READINESS_UNAVAILABLE "UNAVAILABLE_PROOF_KIND" #define RESOURCE_X_PROOF_READINESS_AVAILABLE "AVAILABLE_PROOF_KIND" -typedef struct ResourceXAssertion -{ - BufferTag resource; - int32 requester_node; +typedef struct ResourceXAssertion { + BufferTag resource; + int32 requester_node; } ResourceXAssertion; -typedef struct ResourceXAttemptWitness -{ +typedef struct ResourceXAttemptWitness { ResourceXAssertion assertion; - uint64 base_authority_generation; + uint64 base_authority_generation; } ResourceXAttemptWitness; -typedef struct ResourceXTransportWitness -{ - uint64 cluster_epoch; - uint64 peer_session_incarnation; - uint32 connection_generation; - uint16 lane_id; - uint16 flags; +typedef struct ResourceXTransportWitness { + uint64 cluster_epoch; + uint64 peer_session_incarnation; + uint32 connection_generation; + uint16 lane_id; + uint16 flags; } ResourceXTransportWitness; /* Process-local D6-03 outcome. These values are never persisted or sent on * the legacy 41--64 wire family. */ -typedef enum ResourceXLocalJoinResult -{ +typedef enum ResourceXLocalJoinResult { RESOURCE_X_LOCAL_JOIN_NONE = 0, RESOURCE_X_LOCAL_LEADER_MUST_SUBMIT, RESOURCE_X_LOCAL_JOINED_LOCAL_ASSERTION, @@ -70,16 +66,14 @@ StaticAssertDecl(offsetof(ResourceXTransportWitness, cluster_epoch) == 0 && offsetof(ResourceXTransportWitness, flags) == 22, "Resource-X transport witness offsets changed"); -extern bool resource_x_assertion_init(const BufferTag *tag, - int32 requester_node, +extern bool resource_x_assertion_init(const BufferTag *tag, int32 requester_node, ResourceXAssertion *out); extern bool resource_x_assertion_valid(const ResourceXAssertion *assertion); extern bool resource_x_assertion_equal(const ResourceXAssertion *left, const ResourceXAssertion *right); extern uint32 resource_x_assertion_hash(const ResourceXAssertion *assertion); extern bool resource_x_attempt_init(const ResourceXAssertion *assertion, - uint64 base_authority_generation, - ResourceXAttemptWitness *out); + uint64 base_authority_generation, ResourceXAttemptWitness *out); extern bool resource_x_attempt_matches(const ResourceXAttemptWitness *left, const ResourceXAttemptWitness *right); /* R6 readiness only: no proof enum, proof value, producer, or proof-bearing key. */ diff --git a/src/include/cluster/cluster_resource_x_node_wire.h b/src/include/cluster/cluster_resource_x_node_wire.h index df071e3001a..54ed6864094 100644 --- a/src/include/cluster/cluster_resource_x_node_wire.h +++ b/src/include/cluster/cluster_resource_x_node_wire.h @@ -34,8 +34,7 @@ #define RESOURCE_X_MSG_BLOCKED_TO_N PGRAC_IC_MSG_GCS_BLOCK_INVALIDATE_ACK #define RESOURCE_X_MSG_SETTLEMENT_OR_RELEASE PGRAC_IC_MSG_GCS_BLOCK_DONE -typedef enum ResourceXWireKind -{ +typedef enum ResourceXWireKind { RESOURCE_X_WIRE_ASSERT_X = 1, RESOURCE_X_WIRE_BLOCK_TO_N = 2, RESOURCE_X_WIRE_BLOCKED_TO_N = 3, @@ -52,8 +51,7 @@ typedef enum ResourceXWireKind #define RESOURCE_X_WIRE_KIND_MIN RESOURCE_X_WIRE_ASSERT_X #define RESOURCE_X_WIRE_KIND_MAX RESOURCE_X_WIRE_SOURCE_SETTLEMENT_ACK_V2 -typedef enum ResourceXSourceProofKind -{ +typedef enum ResourceXSourceProofKind { RESOURCE_X_PROOF_REMOTE_CARRIER = 1, RESOURCE_X_PROOF_LOCAL_IMAGE = 2, RESOURCE_X_PROOF_DURABLE_STORAGE = 3 @@ -70,8 +68,7 @@ typedef enum ResourceXSourceProofKind /* Only a zero-base type14/kind9 request may permit remote-source admission. */ #define RESOURCE_X_COMMON_FLAG_REMOTE_ADMISSION UINT8_C(0x08) -typedef enum ResourceXWireOutcome -{ +typedef enum ResourceXWireOutcome { RESOURCE_X_OUTCOME_NONE = 0, RESOURCE_X_OUTCOME_OK = 1, RESOURCE_X_OUTCOME_DUPLICATE = 2, @@ -86,26 +83,22 @@ typedef enum ResourceXWireOutcome RESOURCE_X_OUTCOME_CORRUPT = 11 } ResourceXWireOutcome; -typedef enum ResourceXSourceDisposition -{ +typedef enum ResourceXSourceDisposition { RESOURCE_X_DISPOSITION_REMOTE_NONWRITABLE = 1, RESOURCE_X_DISPOSITION_LOCAL_IMAGE = 2, RESOURCE_X_DISPOSITION_DURABLE_STORAGE = 3 } ResourceXSourceDisposition; -typedef enum ResourceXRequesterRole -{ +typedef enum ResourceXRequesterRole { RESOURCE_X_REQUESTER_ROLE_ACQUIRER = 1 } ResourceXRequesterRole; -typedef enum ResourceXSettlementTerminalState -{ +typedef enum ResourceXSettlementTerminalState { RESOURCE_X_SETTLEMENT_TERMINAL_INSTALLED = 1, RESOURCE_X_SETTLEMENT_TERMINAL_EXCLUDED = 2 } ResourceXSettlementTerminalState; -typedef enum ResourceXWireReject -{ +typedef enum ResourceXWireReject { RESOURCE_X_WIRE_REJECT_NONE = 0, RESOURCE_X_WIRE_REJECT_BAD_ARGUMENT, RESOURCE_X_WIRE_REJECT_LEGACY_LENGTH, @@ -122,233 +115,219 @@ typedef enum ResourceXWireReject RESOURCE_X_WIRE_REJECT_BODY } ResourceXWireReject; -typedef struct ResourceXWireCommonV1 -{ - uint8 wire_version; - uint8 kind; - uint8 header_bytes[2]; - uint8 semantic_crc32c[4]; - uint8 logical_assertion[24]; - uint8 base_authority_generation[8]; - uint8 resource_formation[8]; - uint8 master_session_incarnation[8]; - uint8 assertion_sequence[8]; - uint8 ordered_lane[4]; - uint8 action_node[4]; - uint8 observed_mode; - uint8 target_mode; - uint8 source_candidate; - uint8 retain_pi_if_dirty; - uint8 sender_connection_generation[4]; - uint8 outcome; - uint8 flags; - uint8 zero_reserved[6]; - uint8 authority_generation[8]; +typedef struct ResourceXWireCommonV1 { + uint8 wire_version; + uint8 kind; + uint8 header_bytes[2]; + uint8 semantic_crc32c[4]; + uint8 logical_assertion[24]; + uint8 base_authority_generation[8]; + uint8 resource_formation[8]; + uint8 master_session_incarnation[8]; + uint8 assertion_sequence[8]; + uint8 ordered_lane[4]; + uint8 action_node[4]; + uint8 observed_mode; + uint8 target_mode; + uint8 source_candidate; + uint8 retain_pi_if_dirty; + uint8 sender_connection_generation[4]; + uint8 outcome; + uint8 flags; + uint8 zero_reserved[6]; + uint8 authority_generation[8]; } ResourceXWireCommonV1; typedef ResourceXWireCommonV1 ResourceXControlV1; -typedef struct ResourceXLocalProofDeclarationV1 -{ +typedef struct ResourceXLocalProofDeclarationV1 { ResourceXWireCommonV1 common; - uint8 local_holder_authority_generation[8]; - uint8 requester_target_generation[8]; - uint8 page_scn_lsn[8]; - uint8 dependency_count[2]; - uint8 zero_reserved[2]; - uint8 dependency_vector_crc32c[4]; - uint8 page_checksum[4]; - uint8 local_image_proof_crc32c[4]; - uint8 requester_connection_generation[8]; - uint8 local_proof_generation[8]; + uint8 local_holder_authority_generation[8]; + uint8 requester_target_generation[8]; + uint8 page_scn_lsn[8]; + uint8 dependency_count[2]; + uint8 zero_reserved[2]; + uint8 dependency_vector_crc32c[4]; + uint8 page_checksum[4]; + uint8 local_image_proof_crc32c[4]; + uint8 requester_connection_generation[8]; + uint8 local_proof_generation[8]; } ResourceXLocalProofDeclarationV1; -typedef struct ResourceXBlockedToNProofV1 -{ +typedef struct ResourceXBlockedToNProofV1 { ResourceXWireCommonV1 common; - uint8 source_fence[RESOURCE_X_SOURCE_FENCE_BYTES]; - uint8 source_carrier_generation[8]; - uint8 requester_target_generation[8]; - uint8 page_scn_lsn[8]; - uint8 dependency_count[2]; - uint8 dependencies[RESOURCE_X_DEPENDENCY_VECTOR_BYTES]; - uint8 source_proof_crc32c[4]; - uint8 page_checksum[4]; - uint8 source_disposition; - uint8 proof_kind; - uint8 proof_flags[2]; - uint8 holder_connection_generation[8]; - uint8 acting_formation[8]; + uint8 source_fence[RESOURCE_X_SOURCE_FENCE_BYTES]; + uint8 source_carrier_generation[8]; + uint8 requester_target_generation[8]; + uint8 page_scn_lsn[8]; + uint8 dependency_count[2]; + uint8 dependencies[RESOURCE_X_DEPENDENCY_VECTOR_BYTES]; + uint8 source_proof_crc32c[4]; + uint8 page_checksum[4]; + uint8 source_disposition; + uint8 proof_kind; + uint8 proof_flags[2]; + uint8 holder_connection_generation[8]; + uint8 acting_formation[8]; } ResourceXBlockedToNProofV1; -typedef struct ResourceXAuthorityGrantV1 -{ +typedef struct ResourceXAuthorityGrantV1 { ResourceXWireCommonV1 common; - uint8 source_fence[RESOURCE_X_SOURCE_FENCE_BYTES]; - uint8 final_authority_generation[8]; - uint8 source_carrier_generation[8]; - uint8 requester_target_generation[8]; - uint8 page_scn_lsn[8]; - uint8 dependency_count[2]; - uint8 dependencies[RESOURCE_X_DEPENDENCY_VECTOR_BYTES]; - uint8 source_proof_crc32c[4]; - uint8 page_checksum[4]; - uint8 proof_kind; - uint8 source_disposition; - uint8 grant_flags[2]; - uint8 requester_connection_generation[8]; + uint8 source_fence[RESOURCE_X_SOURCE_FENCE_BYTES]; + uint8 final_authority_generation[8]; + uint8 source_carrier_generation[8]; + uint8 requester_target_generation[8]; + uint8 page_scn_lsn[8]; + uint8 dependency_count[2]; + uint8 dependencies[RESOURCE_X_DEPENDENCY_VECTOR_BYTES]; + uint8 source_proof_crc32c[4]; + uint8 page_checksum[4]; + uint8 proof_kind; + uint8 source_disposition; + uint8 grant_flags[2]; + uint8 requester_connection_generation[8]; } ResourceXAuthorityGrantV1; -typedef struct ResourceXImageEnvelopeV1 -{ +typedef struct ResourceXImageEnvelopeV1 { ResourceXWireCommonV1 common; - uint8 request_tail[RESOURCE_X_REQUEST_TAIL_BYTES]; - uint8 conversion_base_generation[8]; - uint8 source_fence[RESOURCE_X_SOURCE_FENCE_BYTES]; - uint8 source_carrier_generation[8]; - uint8 requester_target_generation[8]; - uint8 page_scn_lsn[8]; - uint8 dependency_count[2]; - uint8 dependencies[RESOURCE_X_DEPENDENCY_VECTOR_BYTES]; - uint8 dependency_vector_crc32c[4]; - uint8 page_checksum[4]; - uint8 image_length[4]; - uint8 source_disposition; - uint8 proof_kind; - uint8 image_flags[2]; - uint8 page_bytes[RESOURCE_X_PAGE_BYTES]; + uint8 request_tail[RESOURCE_X_REQUEST_TAIL_BYTES]; + uint8 conversion_base_generation[8]; + uint8 source_fence[RESOURCE_X_SOURCE_FENCE_BYTES]; + uint8 source_carrier_generation[8]; + uint8 requester_target_generation[8]; + uint8 page_scn_lsn[8]; + uint8 dependency_count[2]; + uint8 dependencies[RESOURCE_X_DEPENDENCY_VECTOR_BYTES]; + uint8 dependency_vector_crc32c[4]; + uint8 page_checksum[4]; + uint8 image_length[4]; + uint8 source_disposition; + uint8 proof_kind; + uint8 image_flags[2]; + uint8 page_bytes[RESOURCE_X_PAGE_BYTES]; } ResourceXImageEnvelopeV1; -typedef struct ResourceXInstallSettlementV1 -{ +typedef struct ResourceXInstallSettlementV1 { ResourceXWireCommonV1 common; - uint8 conversion_base_generation[8]; - uint8 final_authority_generation[8]; - uint8 requester_connection_generation[8]; - uint8 requester_target_generation[8]; - uint8 page_scn_lsn[8]; - uint8 page_checksum[4]; - uint8 source_proof_crc32c[4]; - uint8 installed_mode; - uint8 requester_role; - uint8 terminal_outcome; - uint8 terminal_state; - uint8 settlement_flags[4]; + uint8 conversion_base_generation[8]; + uint8 final_authority_generation[8]; + uint8 requester_connection_generation[8]; + uint8 requester_target_generation[8]; + uint8 page_scn_lsn[8]; + uint8 page_checksum[4]; + uint8 source_proof_crc32c[4]; + uint8 installed_mode; + uint8 requester_role; + uint8 terminal_outcome; + uint8 terminal_state; + uint8 settlement_flags[4]; } ResourceXInstallSettlementV1; /* Host-order values. These are never copied directly to the wire. */ -typedef struct ResourceXDecodedCommon -{ +typedef struct ResourceXDecodedCommon { ResourceXAssertion logical_assertion; - uint64 base_authority_generation; - uint64 resource_formation; - uint64 master_session_incarnation; - uint64 assertion_sequence; - uint32 ordered_lane; - int32 action_node; - uint8 observed_mode; - uint8 target_mode; - uint8 source_candidate; - uint8 retain_pi_if_dirty; - uint32 sender_connection_generation; - uint8 outcome; - uint8 flags; - uint64 authority_generation; + uint64 base_authority_generation; + uint64 resource_formation; + uint64 master_session_incarnation; + uint64 assertion_sequence; + uint32 ordered_lane; + int32 action_node; + uint8 observed_mode; + uint8 target_mode; + uint8 source_candidate; + uint8 retain_pi_if_dirty; + uint32 sender_connection_generation; + uint8 outcome; + uint8 flags; + uint64 authority_generation; /* Decoder-verified CRC from wire bytes. The encoder computes this field; * callers do not provide it as input. */ - uint32 semantic_crc32c; + uint32 semantic_crc32c; } ResourceXDecodedCommon; -typedef struct ResourceXDecodedLocalProof -{ - uint64 local_holder_authority_generation; - uint64 requester_target_generation; - uint64 page_scn_lsn; - uint16 dependency_count; - uint32 dependency_vector_crc32c; - uint32 page_checksum; - uint32 local_image_proof_crc32c; - uint64 requester_connection_generation; - uint64 local_proof_generation; +typedef struct ResourceXDecodedLocalProof { + uint64 local_holder_authority_generation; + uint64 requester_target_generation; + uint64 page_scn_lsn; + uint16 dependency_count; + uint32 dependency_vector_crc32c; + uint32 page_checksum; + uint32 local_image_proof_crc32c; + uint64 requester_connection_generation; + uint64 local_proof_generation; } ResourceXDecodedLocalProof; -typedef struct ResourceXDecodedBlockedToN -{ - uint8 source_fence[RESOURCE_X_SOURCE_FENCE_BYTES]; - uint64 source_carrier_generation; - uint64 requester_target_generation; - uint64 page_scn_lsn; - uint16 dependency_count; - uint64 dependencies[RESOURCE_X_DEPENDENCY_MAX]; - uint32 source_proof_crc32c; - uint32 page_checksum; - uint8 source_disposition; - uint8 proof_kind; - uint16 proof_flags; - uint64 holder_connection_generation; - uint64 acting_formation; +typedef struct ResourceXDecodedBlockedToN { + uint8 source_fence[RESOURCE_X_SOURCE_FENCE_BYTES]; + uint64 source_carrier_generation; + uint64 requester_target_generation; + uint64 page_scn_lsn; + uint16 dependency_count; + uint64 dependencies[RESOURCE_X_DEPENDENCY_MAX]; + uint32 source_proof_crc32c; + uint32 page_checksum; + uint8 source_disposition; + uint8 proof_kind; + uint16 proof_flags; + uint64 holder_connection_generation; + uint64 acting_formation; } ResourceXDecodedBlockedToN; -typedef struct ResourceXDecodedAuthorityGrant -{ - uint8 source_fence[RESOURCE_X_SOURCE_FENCE_BYTES]; - uint64 final_authority_generation; - uint64 source_carrier_generation; - uint64 requester_target_generation; - uint64 page_scn_lsn; - uint16 dependency_count; - uint64 dependencies[RESOURCE_X_DEPENDENCY_MAX]; - uint32 source_proof_crc32c; - uint32 page_checksum; - uint8 proof_kind; - uint8 source_disposition; - uint16 grant_flags; - uint64 requester_connection_generation; +typedef struct ResourceXDecodedAuthorityGrant { + uint8 source_fence[RESOURCE_X_SOURCE_FENCE_BYTES]; + uint64 final_authority_generation; + uint64 source_carrier_generation; + uint64 requester_target_generation; + uint64 page_scn_lsn; + uint16 dependency_count; + uint64 dependencies[RESOURCE_X_DEPENDENCY_MAX]; + uint32 source_proof_crc32c; + uint32 page_checksum; + uint8 proof_kind; + uint8 source_disposition; + uint16 grant_flags; + uint64 requester_connection_generation; } ResourceXDecodedAuthorityGrant; -typedef struct ResourceXDecodedImageEnvelope -{ - uint8 request_tail[RESOURCE_X_REQUEST_TAIL_BYTES]; - uint64 conversion_base_generation; - uint8 source_fence[RESOURCE_X_SOURCE_FENCE_BYTES]; - uint64 source_carrier_generation; - uint64 requester_target_generation; - uint64 page_scn_lsn; - uint16 dependency_count; - uint64 dependencies[RESOURCE_X_DEPENDENCY_MAX]; - uint32 dependency_vector_crc32c; - uint32 page_checksum; - uint32 image_length; - uint8 source_disposition; - uint8 proof_kind; - uint16 image_flags; - uint8 page_bytes[RESOURCE_X_PAGE_BYTES]; +typedef struct ResourceXDecodedImageEnvelope { + uint8 request_tail[RESOURCE_X_REQUEST_TAIL_BYTES]; + uint64 conversion_base_generation; + uint8 source_fence[RESOURCE_X_SOURCE_FENCE_BYTES]; + uint64 source_carrier_generation; + uint64 requester_target_generation; + uint64 page_scn_lsn; + uint16 dependency_count; + uint64 dependencies[RESOURCE_X_DEPENDENCY_MAX]; + uint32 dependency_vector_crc32c; + uint32 page_checksum; + uint32 image_length; + uint8 source_disposition; + uint8 proof_kind; + uint16 image_flags; + uint8 page_bytes[RESOURCE_X_PAGE_BYTES]; } ResourceXDecodedImageEnvelope; -typedef struct ResourceXDecodedInstallSettlement -{ - uint64 conversion_base_generation; - uint64 final_authority_generation; - uint64 requester_connection_generation; - uint64 requester_target_generation; - uint64 page_scn_lsn; - uint32 page_checksum; - uint32 source_proof_crc32c; - uint8 installed_mode; - uint8 requester_role; - uint8 terminal_outcome; - uint8 terminal_state; - uint32 settlement_flags; +typedef struct ResourceXDecodedInstallSettlement { + uint64 conversion_base_generation; + uint64 final_authority_generation; + uint64 requester_connection_generation; + uint64 requester_target_generation; + uint64 page_scn_lsn; + uint32 page_checksum; + uint32 source_proof_crc32c; + uint8 installed_mode; + uint8 requester_role; + uint8 terminal_outcome; + uint8 terminal_state; + uint32 settlement_flags; } ResourceXDecodedInstallSettlement; -typedef struct ResourceXDecodedFrame -{ +typedef struct ResourceXDecodedFrame { ResourceXWireKind kind; - uint16 payload_bytes; - bool blocked_has_remote_proof; + uint16 payload_bytes; + bool blocked_has_remote_proof; ResourceXDecodedCommon common; - union - { + union { ResourceXDecodedLocalProof local_proof; ResourceXDecodedBlockedToN blocked_to_n; ResourceXDecodedAuthorityGrant authority_grant; @@ -366,10 +345,8 @@ StaticAssertDecl(offsetof(ResourceXWireCommonV1, logical_assertion) == 8 "Resource-X common V1 offsets changed"); StaticAssertDecl(sizeof(ResourceXLocalProofDeclarationV1) == RESOURCE_X_SHORT_V1_BYTES, "Resource-X local proof V1 wire size changed"); -StaticAssertDecl(offsetof(ResourceXLocalProofDeclarationV1, - local_holder_authority_generation) == 96 - && offsetof(ResourceXLocalProofDeclarationV1, - local_proof_generation) == 144, +StaticAssertDecl(offsetof(ResourceXLocalProofDeclarationV1, local_holder_authority_generation) == 96 + && offsetof(ResourceXLocalProofDeclarationV1, local_proof_generation) == 144, "Resource-X local proof V1 offsets changed"); StaticAssertDecl(sizeof(ResourceXBlockedToNProofV1) == RESOURCE_X_PROOF_V1_BYTES, "Resource-X blocked-to-N V1 wire size changed"); @@ -379,8 +356,7 @@ StaticAssertDecl(offsetof(ResourceXBlockedToNProofV1, source_fence) == 96 StaticAssertDecl(sizeof(ResourceXAuthorityGrantV1) == RESOURCE_X_PROOF_V1_BYTES, "Resource-X authority-grant V1 wire size changed"); StaticAssertDecl(offsetof(ResourceXAuthorityGrantV1, source_fence) == 96 - && offsetof(ResourceXAuthorityGrantV1, - requester_connection_generation) == 304, + && offsetof(ResourceXAuthorityGrantV1, requester_connection_generation) == 304, "Resource-X authority-grant V1 offsets changed"); StaticAssertDecl(sizeof(ResourceXImageEnvelopeV1) == RESOURCE_X_IMAGE_V1_BYTES, "Resource-X image-envelope V1 wire size changed"); @@ -389,19 +365,18 @@ StaticAssertDecl(offsetof(ResourceXImageEnvelopeV1, request_tail) == 96 "Resource-X image-envelope V1 offsets changed"); StaticAssertDecl(sizeof(ResourceXInstallSettlementV1) == RESOURCE_X_SHORT_V1_BYTES, "Resource-X install-settlement V1 wire size changed"); -StaticAssertDecl(offsetof(ResourceXInstallSettlementV1, - conversion_base_generation) == 96 +StaticAssertDecl(offsetof(ResourceXInstallSettlementV1, conversion_base_generation) == 96 && offsetof(ResourceXInstallSettlementV1, settlement_flags) == 148, "Resource-X install-settlement V1 offsets changed"); -extern bool cluster_resource_x_wire_encode(uint8 msg_type, - const ResourceXDecodedFrame *frame, void *payload, uint16 payload_capacity, - uint16 *payload_len_out, ResourceXWireReject *reject); -extern bool cluster_resource_x_wire_decode(uint8 msg_type, const void *payload, - uint16 payload_len, ResourceXDecodedFrame *out, - ResourceXWireReject *reject); -extern bool cluster_resource_x_wire_rebind_sender_generation(uint8 msg_type, - void *payload, uint16 payload_len, uint32 sender_connection_generation, - ResourceXWireReject *reject); +extern bool cluster_resource_x_wire_encode(uint8 msg_type, const ResourceXDecodedFrame *frame, + void *payload, uint16 payload_capacity, + uint16 *payload_len_out, ResourceXWireReject *reject); +extern bool cluster_resource_x_wire_decode(uint8 msg_type, const void *payload, uint16 payload_len, + ResourceXDecodedFrame *out, ResourceXWireReject *reject); +extern bool cluster_resource_x_wire_rebind_sender_generation(uint8 msg_type, void *payload, + uint16 payload_len, + uint32 sender_connection_generation, + ResourceXWireReject *reject); #endif /* CLUSTER_RESOURCE_X_NODE_WIRE_H */ diff --git a/src/include/cluster/cluster_resource_x_retry.h b/src/include/cluster/cluster_resource_x_retry.h index ed9f7c26a9a..4b46f611e0e 100644 --- a/src/include/cluster/cluster_resource_x_retry.h +++ b/src/include/cluster/cluster_resource_x_retry.h @@ -78,10 +78,8 @@ typedef struct ResourceXTerminalRecordV1 { ResourceXRetryStateV1 state; } ResourceXTerminalRecordV1; -StaticAssertDecl(sizeof(ResourceXRetryStateV1) == 72, - "Resource-X retry state ABI"); -StaticAssertDecl(offsetof(ResourceXRetryStateV1, attempt) == 0, - "Resource-X retry attempt offset"); +StaticAssertDecl(sizeof(ResourceXRetryStateV1) == 72, "Resource-X retry state ABI"); +StaticAssertDecl(offsetof(ResourceXRetryStateV1, attempt) == 0, "Resource-X retry attempt offset"); StaticAssertDecl(offsetof(ResourceXRetryStateV1, first_submit_mono_us) == 32 && offsetof(ResourceXRetryStateV1, next_retry_due_mono_us) == 40 && offsetof(ResourceXRetryStateV1, terminal_deadline_mono_us) == 48, @@ -93,22 +91,18 @@ StaticAssertDecl(offsetof(ResourceXRetryStateV1, last_phase) == 64 && offsetof(ResourceXRetryStateV1, flags) == 66 && offsetof(ResourceXRetryStateV1, state_generation) == 68, "Resource-X retry lifecycle offsets"); -StaticAssertDecl(sizeof(ResourceXRetryAction) == 64, - "Resource-X retry action ABI"); +StaticAssertDecl(sizeof(ResourceXRetryAction) == 64, "Resource-X retry action ABI"); StaticAssertDecl(offsetof(ResourceXRetryAction, attempt) == 0 && offsetof(ResourceXRetryAction, transport) == 32 && offsetof(ResourceXRetryAction, expected_state_generation) == 56 && offsetof(ResourceXRetryAction, expected_retry_count) == 60, "Resource-X retry action offsets"); -StaticAssertDecl(sizeof(ResourceXTerminalRecordV1) == 72, - "Resource-X terminal record ABI"); +StaticAssertDecl(sizeof(ResourceXTerminalRecordV1) == 72, "Resource-X terminal record ABI"); extern bool resource_x_retry_state_init(const ResourceXAttemptWitness *attempt, uint64 first_submit_mono_us, - uint64 terminal_deadline_mono_us, - uint32 max_retries, - uint32 initial_backoff_ms, - uint32 state_generation, + uint64 terminal_deadline_mono_us, uint32 max_retries, + uint32 initial_backoff_ms, uint32 state_generation, ResourceXRetryStateV1 *out); extern void resource_x_retry_state_clear(ResourceXRetryStateV1 *state); extern bool resource_x_retry_state_is_clear(const ResourceXRetryStateV1 *state); @@ -116,24 +110,23 @@ extern ResourceXTerminalReason resource_x_terminal_reason_decode(uint32 reason); extern void resource_x_terminal_record_clear(ResourceXTerminalRecordV1 *record); extern bool resource_x_terminal_record_is_clear(const ResourceXTerminalRecordV1 *record); extern bool resource_x_terminal_record_publish(const ResourceXRetryStateV1 *terminal, - ResourceXTerminalRecordV1 *record_out); + ResourceXTerminalRecordV1 *record_out); extern bool resource_x_terminal_record_replay(const ResourceXTerminalRecordV1 *record, - const ResourceXAttemptWitness *attempt, ResourceXRetryStateV1 *state_out); + const ResourceXAttemptWitness *attempt, + ResourceXRetryStateV1 *state_out); extern bool resource_x_retry_policy_exact(const ResourceXRetryStateV1 *state, - uint32 *max_retries_out, uint32 *initial_backoff_ms_out); + uint32 *max_retries_out, uint32 *initial_backoff_ms_out); extern bool resource_x_retry_next_due_exact(const ResourceXRetryStateV1 *state, - uint64 last_admitted_mono_us, uint32 admitted_retry_count, - uint64 *next_due_out); -extern ResourceXRetryApplyResult resource_x_retry_terminalize_exact( - const ResourceXRetryStateV1 *current, - const ResourceXRetryStateV1 *expected, - uint32 terminal_errcode, uint64 terminal_at_mono_us, - ResourceXRetryStateV1 *terminal_out); -extern ResourceXRetryDecision resource_x_retry_classify_exact( - const ResourceXRetryStateV1 *state, - const ResourceXAttemptWitness *current_attempt, - const ResourceXTransportWitness *fresh_transport, - uint64 now_mono_us, - ResourceXRetryAction *out); + uint64 last_admitted_mono_us, + uint32 admitted_retry_count, uint64 *next_due_out); +extern ResourceXRetryApplyResult +resource_x_retry_terminalize_exact(const ResourceXRetryStateV1 *current, + const ResourceXRetryStateV1 *expected, uint32 terminal_errcode, + uint64 terminal_at_mono_us, ResourceXRetryStateV1 *terminal_out); +extern ResourceXRetryDecision +resource_x_retry_classify_exact(const ResourceXRetryStateV1 *state, + const ResourceXAttemptWitness *current_attempt, + const ResourceXTransportWitness *fresh_transport, + uint64 now_mono_us, ResourceXRetryAction *out); #endif /* CLUSTER_RESOURCE_X_RETRY_H */ diff --git a/src/include/cluster/cluster_rf_route.h b/src/include/cluster/cluster_rf_route.h index b03b832ad27..00847aca7bc 100644 --- a/src/include/cluster/cluster_rf_route.h +++ b/src/include/cluster/cluster_rf_route.h @@ -12,23 +12,20 @@ #define CLUSTER_RF_ROUTE_INTERFACE_V1 1 -typedef enum RfRecordRouteOwnerV1 -{ +typedef enum RfRecordRouteOwnerV1 { RF_ROUTE_OWNER_INVALID = 0, RF_ROUTE_OWNER_PAGE_CODEC = 1, RF_ROUTE_OWNER_SIDE_TYPED = 2, RF_ROUTE_OWNER_LOGICAL_NOOP = 3 } RfRecordRouteOwnerV1; -typedef enum RfRouteBlockPolicyV1 -{ +typedef enum RfRouteBlockPolicyV1 { RF_ROUTE_BLOCKS_FORBIDDEN = 0, RF_ROUTE_BLOCKS_REQUIRED = 1, RF_ROUTE_BLOCKS_OPTIONAL_TYPED = 2 } RfRouteBlockPolicyV1; -typedef enum RfRouteCodecV1 -{ +typedef enum RfRouteCodecV1 { RF_ROUTE_CODEC_NONE = 0, RF_ROUTE_CODEC_XLOG_FPI = 1, RF_ROUTE_CODEC_HEAP2 = 2, @@ -49,22 +46,19 @@ typedef enum RfRouteCodecV1 RF_ROUTE_CODEC_SIDE_XID_STRIPE_SHMEM = 17 } RfRouteCodecV1; -typedef struct RfOpcodeRouteV1 -{ - uint8 rmid; - uint8 normalized_info; - uint8 legal_info_flags; - uint8 record_owner; - uint8 block_policy; - uint8 codec_id; - uint16 reserved_zero; +typedef struct RfOpcodeRouteV1 { + uint8 rmid; + uint8 normalized_info; + uint8 legal_info_flags; + uint8 record_owner; + uint8 block_policy; + uint8 codec_id; + uint16 reserved_zero; } RfOpcodeRouteV1; -StaticAssertDecl(sizeof(RfOpcodeRouteV1) == 8, - "RfOpcodeRouteV1 must remain an 8-byte ABI"); +StaticAssertDecl(sizeof(RfOpcodeRouteV1) == 8, "RfOpcodeRouteV1 must remain an 8-byte ABI"); -typedef enum RfOpcodeRouteLookupResultV1 -{ +typedef enum RfOpcodeRouteLookupResultV1 { RF_OPCODE_ROUTE_OK = 0, RF_OPCODE_ROUTE_RMID_UNSUPPORTED = 1, RF_OPCODE_ROUTE_OPCODE_UNSUPPORTED = 2, @@ -76,13 +70,9 @@ typedef enum RfOpcodeRouteLookupResultV1 extern size_t rf_opcode_route_manifest_count_v1(void); extern size_t rf_opcode_route_manifest_live_count_v1(void); -extern bool rf_opcode_route_manifest_entry_v1(size_t index, - RfOpcodeRouteV1 *route, - bool *active); -extern RfOpcodeRouteLookupResultV1 rf_opcode_route_lookup_v1(uint8 rmid, - uint8 raw_info, - bool has_blocks, - bool space_active, +extern bool rf_opcode_route_manifest_entry_v1(size_t index, RfOpcodeRouteV1 *route, bool *active); +extern RfOpcodeRouteLookupResultV1 rf_opcode_route_lookup_v1(uint8 rmid, uint8 raw_info, + bool has_blocks, bool space_active, RfOpcodeRouteV1 *route); -#endif /* CLUSTER_RF_ROUTE_H */ +#endif /* CLUSTER_RF_ROUTE_H */ diff --git a/src/include/cluster/cluster_runtime_visibility.h b/src/include/cluster/cluster_runtime_visibility.h index a1ba500d0d8..a8f39ab8bfc 100644 --- a/src/include/cluster/cluster_runtime_visibility.h +++ b/src/include/cluster/cluster_runtime_visibility.h @@ -148,8 +148,8 @@ typedef struct ClusterRuntimeVisibilityCanonicalDiagnostic { } ClusterRuntimeVisibilityCanonicalDiagnostic; extern void cluster_runtime_visibility_ensure_exit_hooks(void); -extern bool cluster_runtime_visibility_zero_epoch_pair_admission_enter( - ClusterSemanticAdmissionToken *token); +extern bool +cluster_runtime_visibility_zero_epoch_pair_admission_enter(ClusterSemanticAdmissionToken *token); extern ClusterTxOutcome cluster_runtime_visibility_resolve_exact_origin( const ClusterTxLocator *locator, ClusterTxResolveMode mode, uint64 formation_epoch, ClusterTxResolution *out, ClusterTxResolveReason *reason_out); @@ -157,44 +157,35 @@ extern ClusterTxOutcome cluster_runtime_visibility_resolve_exact_origin_admitted const ClusterTxLocator *locator, ClusterTxResolveMode mode, const ClusterSemanticAdmissionToken *admission, ClusterTxResolution *out, ClusterTxResolveReason *reason_out); -extern ClusterTxOutcome -cluster_runtime_visibility_resolve_terminal_census_retained_exact( +extern ClusterTxOutcome cluster_runtime_visibility_resolve_terminal_census_retained_exact( const ClusterTxLocator *locator, SCN retained_commit_scn, const ClusterSemanticAdmissionToken *admission, ClusterTxResolution *out, ClusterTxResolveReason *reason_out); -extern ClusterTxOutcome -cluster_runtime_visibility_resolve_terminal_census_retained_local_exact( +extern ClusterTxOutcome cluster_runtime_visibility_resolve_terminal_census_retained_local_exact( const ClusterTxLocator *locator, SCN retained_commit_scn, const ClusterSemanticAdmissionToken *admission, ClusterTxResolution *out, ClusterTxResolveReason *reason_out); extern ClusterTxOutcome cluster_runtime_visibility_resolve_exact_origin_held( const ClusterTxLocator *locator, ClusterTxResolveMode mode, const ClusterSemanticAdmissionToken *admission, - const ClusterUndoBlock0Generation *expected_generation, - ClusterUndoBlock0CurrentGuard *guard, + const ClusterUndoBlock0Generation *expected_generation, ClusterUndoBlock0CurrentGuard *guard, const ClusterUndoBlock0ResolvedRoot *root, ClusterTxResolution *out, ClusterTxResolveReason *reason_out); -extern ClusterRuntimeVisibilityOriginStep -cluster_runtime_visibility_origin_plan_freeze_data_held( +extern ClusterRuntimeVisibilityOriginStep cluster_runtime_visibility_origin_plan_freeze_data_held( const ClusterTxLocator *locator, ClusterTxResolveMode mode, const ClusterSemanticAdmissionToken *admission, - const ClusterUndoBlock0Generation *expected_generation, - ClusterUndoBlock0CurrentGuard *guard, - const ClusterUndoBlock0ResolvedRoot *root, - ClusterRuntimeVisibilityOriginPlan *plan, ClusterTxResolution *out, - ClusterTxResolveReason *reason_out); + const ClusterUndoBlock0Generation *expected_generation, ClusterUndoBlock0CurrentGuard *guard, + const ClusterUndoBlock0ResolvedRoot *root, ClusterRuntimeVisibilityOriginPlan *plan, + ClusterTxResolution *out, ClusterTxResolveReason *reason_out); extern bool cluster_runtime_visibility_origin_plan_canonical_logical( - const ClusterRuntimeVisibilityOriginPlan *plan, - ClusterUndoBlock0LogicalKey *logical_out); + const ClusterRuntimeVisibilityOriginPlan *plan, ClusterUndoBlock0LogicalKey *logical_out); extern bool cluster_runtime_visibility_origin_plan_canonical_physical( - const ClusterRuntimeVisibilityOriginPlan *plan, - ClusterTTSlotPhysicalLocator *locator_out, bool *same_segment_out); + const ClusterRuntimeVisibilityOriginPlan *plan, ClusterTTSlotPhysicalLocator *locator_out, + bool *same_segment_out); extern bool cluster_runtime_visibility_origin_plan_sample_canonical_held( ClusterRuntimeVisibilityOriginPlan *plan, ClusterTxResolveMode mode, - const ClusterSemanticAdmissionToken *admission, - ClusterUndoBlock0CurrentGuard *guard, - const ClusterUndoBlock0ResolvedRoot *root, - ClusterTxResolveReason *reason_out); + const ClusterSemanticAdmissionToken *admission, ClusterUndoBlock0CurrentGuard *guard, + const ClusterUndoBlock0ResolvedRoot *root, ClusterTxResolveReason *reason_out); extern bool cluster_runtime_visibility_origin_plan_canonical_diagnostic( const ClusterRuntimeVisibilityOriginPlan *plan, ClusterRuntimeVisibilityCanonicalDiagnostic *out); @@ -204,55 +195,41 @@ extern bool cluster_runtime_visibility_origin_plan_canonical_diagnostic( * Neither can create an ACTIVE or terminal result from nonmatching bytes. */ extern bool cluster_runtime_visibility_current_owner_sample_held( TransactionId xid, const ClusterTTSlotCurrentOwner *expected_owner, - const ClusterSemanticAdmissionToken *admission, - ClusterUndoBlock0CurrentGuard *guard, - const ClusterUndoBlock0ResolvedRoot *root, - ClusterTTStatusKey *key_out, ClusterTTStatusResult *result_out, - bool *ctrc_physical_active_out); + const ClusterSemanticAdmissionToken *admission, ClusterUndoBlock0CurrentGuard *guard, + const ClusterUndoBlock0ResolvedRoot *root, ClusterTTStatusKey *key_out, + ClusterTTStatusResult *result_out, bool *ctrc_physical_active_out); extern bool cluster_runtime_visibility_physical_locator_sample_held( - const ClusterTTSlotPhysicalLocator *locator, - const ClusterSemanticAdmissionToken *admission, - ClusterUndoBlock0CurrentGuard *guard, - const ClusterUndoBlock0ResolvedRoot *root, - ClusterTTStatusKey *key_out, ClusterTTStatusResult *result_out, - bool *ctrc_physical_active_out); + const ClusterTTSlotPhysicalLocator *locator, const ClusterSemanticAdmissionToken *admission, + ClusterUndoBlock0CurrentGuard *guard, const ClusterUndoBlock0ResolvedRoot *root, + ClusterTTStatusKey *key_out, ClusterTTStatusResult *result_out, bool *ctrc_physical_active_out); extern bool cluster_runtime_visibility_current_owner_lookup_exact( - TransactionId xid, ClusterTTStatusKey *key_out, - ClusterTTStatusResult *result_out); + TransactionId xid, ClusterTTStatusKey *key_out, ClusterTTStatusResult *result_out); extern bool cluster_runtime_visibility_current_owner_lookup_exact_ctrc( - TransactionId xid, ClusterTTStatusKey *key_out, - ClusterTTStatusResult *result_out, uint32 *ctrc_grant_out); + TransactionId xid, ClusterTTStatusKey *key_out, ClusterTTStatusResult *result_out, + uint32 *ctrc_grant_out); extern bool cluster_runtime_visibility_current_owner_lookup_exact_ctrc_full( - TransactionId xid, ClusterTTStatusKey *key_out, - ClusterTTStatusResult *result_out, uint32 *ctrc_grant_out, - ClusterCtrcTxnKeyV1 *ctrc_key_out, + TransactionId xid, ClusterTTStatusKey *key_out, ClusterTTStatusResult *result_out, + uint32 *ctrc_grant_out, ClusterCtrcTxnKeyV1 *ctrc_key_out, ClusterCtrcParticipantIdentity *participant_out); /* Local current-MX terminal proof path. It samples the exact current or * rolled physical slot and never creates a CTRC touch/grant/participant. */ extern bool cluster_runtime_visibility_local_terminal_lookup_exact( - TransactionId xid, ClusterTTStatusKey *key_out, - ClusterTTStatusResult *result_out); + TransactionId xid, ClusterTTStatusKey *key_out, ClusterTTStatusResult *result_out); /* Resolve an updater from its exact page-derived DATA locator. The function * executes the same DATA -> canonical TT -> DATA proof used by the remote * origin adapter and never substitutes a by-xid locator. */ extern bool cluster_runtime_visibility_current_mx_updater_provenance_exact( - const ClusterTxLocator *locator, TimestampTz deadline, - ClusterTTStatusKey *key_out, ClusterTTStatusResult *result_out, - uint32 *ctrc_grant_out, - uint32 *participant_capability_generation_out, - ClusterCtrcTxnKeyV1 *ctrc_key_out, - ClusterTxLocator *canonical_locator_out, - bool *cross_segment_out); + const ClusterTxLocator *locator, TimestampTz deadline, ClusterTTStatusKey *key_out, + ClusterTTStatusResult *result_out, uint32 *ctrc_grant_out, + uint32 *participant_capability_generation_out, ClusterCtrcTxnKeyV1 *ctrc_key_out, + ClusterTxLocator *canonical_locator_out, bool *cross_segment_out); extern bool cluster_runtime_visibility_active_proof_ctrc_identity_exact( const ClusterCurrentMemberProofKey *proof_key, uint32 ctrc_grant, - uint32 requester_capability_generation, - ClusterCtrcTxnKeyV1 *ctrc_key_out, + uint32 requester_capability_generation, ClusterCtrcTxnKeyV1 *ctrc_key_out, ClusterCtrcParticipantIdentity *participant_out); -extern ClusterTxOutcome -cluster_runtime_visibility_origin_plan_recheck_data_held( +extern ClusterTxOutcome cluster_runtime_visibility_origin_plan_recheck_data_held( ClusterRuntimeVisibilityOriginPlan *plan, ClusterTxResolveMode mode, - const ClusterSemanticAdmissionToken *admission, - ClusterUndoBlock0CurrentGuard *guard, + const ClusterSemanticAdmissionToken *admission, ClusterUndoBlock0CurrentGuard *guard, const ClusterUndoBlock0ResolvedRoot *root, ClusterTxResolution *out, ClusterTxResolveReason *reason_out); /* Export the exact revalidated resident DATA image under the final guard. @@ -315,7 +292,8 @@ extern bool cluster_vis_live_authority_covers_policy(SCN demand_scn, ClusterLive /* * S3-P0-03: pure admission for a COMMITTED_BELOW_HORIZON proof. A valid - * snapshot may consume the bound only when horizon_scn <= read_scn. The + * snapshot may consume the bound only when scn_time_cmp(horizon_scn, read_scn) + * is nonpositive. The * plain visibility resolver passes InvalidScn for terminal-state-only * consumers (Update/Self/Dirty/Toast/writer-chain); those consumers may use * the origin+CLOG-proven COMMITTED fact, but must preserve the bound marker @@ -328,9 +306,8 @@ extern bool cluster_vis_committed_bound_admissible(SCN horizon_scn, SCN read_scn * exact retained-page pairing. Pure and fail-closed; no authority/state is * created by a true result. */ extern bool cluster_vis_freshref_c1b_pair_request_eligible( - TransactionId raw_xid, TransactionId ref_xid, bool has_cached_status, - SCN cached_commit_scn, uint32 ref_epoch, uint64 current_epoch, - int32 origin_node, int32 local_node, uint32 segment_id, + TransactionId raw_xid, TransactionId ref_xid, bool has_cached_status, SCN cached_commit_scn, + uint32 ref_epoch, uint64 current_epoch, int32 origin_node, int32 local_node, uint32 segment_id, uint32 expected_tt_slot_id); /* diff --git a/src/include/cluster/cluster_semantic_activation.h b/src/include/cluster/cluster_semantic_activation.h index 22f1d6cd3ae..eeda980c137 100644 --- a/src/include/cluster/cluster_semantic_activation.h +++ b/src/include/cluster/cluster_semantic_activation.h @@ -13,7 +13,7 @@ #define CLUSTER_SEMANTIC_ACTIVATION_H #include "c.h" -#include "common/sha2.h" /* PG_SHA256_DIGEST_LENGTH (contract seam) */ +#include "common/sha2.h" /* PG_SHA256_DIGEST_LENGTH (contract seam) */ #include "cluster/cluster_control_root.h" /* file token + round (contract seam) */ #include "cluster/cluster_ic.h" #include "cluster/cluster_undo_root_descriptor.h" @@ -302,8 +302,7 @@ typedef struct ClusterSemanticActivationDescriptor { extern ClusterSemanticAdmissionResult cluster_semantic_activation_enter(uint64 feature_bit, ClusterSemanticAdmissionSide side, ClusterSemanticAdmissionToken *token); -extern ResourceXWriterPath -cluster_resource_x_writer_path_snapshot(uint64 *r4_generation_out); +extern ResourceXWriterPath cluster_resource_x_writer_path_snapshot(uint64 *r4_generation_out); extern bool cluster_semantic_activation_phase1_pristine(void); /* Postmaster lifecycle hint only: atomics, no locks/I/O/identity copy. * True includes unknown state; it never authorizes a shutdown or OPEN. */ @@ -342,41 +341,36 @@ cluster_semantic_activation_r11_cutover_snapshot(ClusterSemanticR11CutoverSnapsh extern bool cluster_semantic_activation_recheck(const ClusterSemanticAdmissionToken *token); extern ClusterSemanticAdmissionResult cluster_semantic_activation_enter_r4_terminal_census(ClusterSemanticAdmissionToken *token); -extern bool cluster_semantic_activation_recheck_r4_terminal_census( - const ClusterSemanticAdmissionToken *token); -extern bool cluster_semantic_activation_resolve_shared_undo_root( - const ClusterSemanticAdmissionToken *token, ClusterUndoPathIntent intent, - uint32 owner_instance, uint32 segment_id, - ClusterUndoBlock0ResolvedRoot *out); -extern bool -cluster_semantic_activation_resolve_shared_undo_root_r4_terminal_census( - const ClusterSemanticAdmissionToken *token, ClusterUndoPathIntent intent, - uint32 owner_instance, uint32 segment_id, - ClusterUndoBlock0ResolvedRoot *out); extern bool -cluster_semantic_activation_resolve_shared_undo_root_live_owner_source( - const ClusterSemanticAdmissionToken *token, ClusterUndoPathIntent intent, - uint32 owner_instance, uint32 segment_id, - ClusterUndoBlock0ResolvedRoot *out); +cluster_semantic_activation_recheck_r4_terminal_census(const ClusterSemanticAdmissionToken *token); +extern bool cluster_semantic_activation_resolve_shared_undo_root( + const ClusterSemanticAdmissionToken *token, ClusterUndoPathIntent intent, uint32 owner_instance, + uint32 segment_id, ClusterUndoBlock0ResolvedRoot *out); +extern bool cluster_semantic_activation_resolve_shared_undo_root_r4_terminal_census( + const ClusterSemanticAdmissionToken *token, ClusterUndoPathIntent intent, uint32 owner_instance, + uint32 segment_id, ClusterUndoBlock0ResolvedRoot *out); +extern bool cluster_semantic_activation_resolve_shared_undo_root_live_owner_source( + const ClusterSemanticAdmissionToken *token, ClusterUndoPathIntent intent, uint32 owner_instance, + uint32 segment_id, ClusterUndoBlock0ResolvedRoot *out); extern bool cluster_semantic_activation_peer_open_matches( const ClusterSemanticAdmissionToken *token, int32 authenticated_peer_node_id, uint32 required_hello_caps, uint32 sampled_capability_generation); -extern bool cluster_semantic_activation_resource_x_peer_open_matches( - const ClusterSemanticAdmissionToken *token, int32 authenticated_peer_node_id, - uint32 sampled_capability_generation); +extern bool +cluster_semantic_activation_resource_x_peer_open_matches(const ClusterSemanticAdmissionToken *token, + int32 authenticated_peer_node_id, + uint32 sampled_capability_generation); extern ClusterSemanticResourceXPeerOpenResult -cluster_semantic_activation_resource_x_peer_open_check( - const ClusterSemanticAdmissionToken *token, int32 authenticated_peer_node_id, - uint32 sampled_capability_generation); +cluster_semantic_activation_resource_x_peer_open_check(const ClusterSemanticAdmissionToken *token, + int32 authenticated_peer_node_id, + uint32 sampled_capability_generation); extern bool cluster_semantic_activation_restore_open_proof_if_active(void); extern void cluster_semantic_activation_leave(ClusterSemanticAdmissionToken *token); extern bool cluster_semantic_activation_backend_has_admission(void); extern ClusterSemanticAdmissionResult cluster_semantic_activation_modifier_enter(bool writable_admission, - ClusterSemanticAdmissionToken *token); -extern bool -cluster_semantic_activation_modifier_recheck(const ClusterSemanticAdmissionToken *token, - bool writable_admission); + ClusterSemanticAdmissionToken *token); +extern bool cluster_semantic_activation_modifier_recheck(const ClusterSemanticAdmissionToken *token, + bool writable_admission); extern Size cluster_semantic_activation_shmem_size(void); extern void cluster_semantic_activation_shmem_init(void); /* RF-ROOT P7 (contract §B): the bit22 cutover reader latch — the dual-path @@ -391,35 +385,31 @@ extern bool cluster_r4_bit22_cutover_verified(void); * first-open round (wal-state registry writer gate). */ extern bool cluster_r4_bit22_source_writer_enter(void); extern void cluster_r4_bit22_source_writer_leave(void); -extern bool cluster_r4_bit22_source_close_begin(uint64 transition_epoch, - uint64 prepare_generation); +extern bool cluster_r4_bit22_source_close_begin(uint64 transition_epoch, uint64 prepare_generation); extern bool cluster_r4_bit22_source_close_current(uint64 transition_epoch, uint64 prepare_generation); extern bool cluster_r4_bit22_cutover_latch_verify(void); -extern bool cluster_r4_bit22_cutover_latch_apply(uint64 transition_epoch, - uint64 round_generation); +extern bool cluster_r4_bit22_cutover_latch_apply(uint64 transition_epoch, uint64 round_generation); /* contract: the round driver stages the PREPARED token/sha/round here after * create_prepared; the coordinator LMON consumes it at the OPEN_APPLIED * advance (step ②). */ -extern bool cluster_r4_bit22_cutover_seam_store( - const ClusterControlRootFileToken *file_token, - const uint8 round_sha[PG_SHA256_DIGEST_LENGTH], - const ClusterControlRootMigrationRoundV1 *round); +extern bool cluster_r4_bit22_cutover_seam_store(const ClusterControlRootFileToken *file_token, + const uint8 round_sha[PG_SHA256_DIGEST_LENGTH], + const ClusterControlRootMigrationRoundV1 *round); /* contract step ④c: the round driver entry — coordinator backend, with the * constructed migration image + round. */ -extern bool cluster_r4_bit22_cutover_begin( - const ClusterControlRootMigrationImage *image, - const ClusterControlRootMigrationRoundV1 *round); +extern bool cluster_r4_bit22_cutover_begin(const ClusterControlRootMigrationImage *image, + const ClusterControlRootMigrationRoundV1 *round); extern void cluster_semantic_activation_register(const ClusterSemanticActivationDescriptor *descriptor); extern const ClusterSemanticActivationDescriptor * cluster_semantic_activation_descriptor(uint64 feature_bit); extern uint64 cluster_semantic_activation_compiled_feature_bitmap(void); extern bool cluster_semantic_activation_record_encode(const ClusterSemanticActivationRecord *record, - uint8 bytes[512]); + uint8 bytes[512]); extern bool cluster_semantic_activation_record_decode(const uint8 bytes[512], - ClusterSemanticActivationRecord *record, - ClusterSemanticActivationRefusal *refusal); + ClusterSemanticActivationRecord *record, + ClusterSemanticActivationRefusal *refusal); extern bool cluster_semantic_activation_ack_wire_encode( const ClusterSemanticActivationAckWireV1 *message, uint8 bytes[CLUSTER_SEMANTIC_ACTIVATION_ACK_WIRE_BYTES]); @@ -432,34 +422,30 @@ extern bool cluster_semantic_activation_qvotec_poll_record_cas(ClusterSemanticActivationCasRequest *out); extern bool cluster_semantic_activation_qvotec_complete_record_cas(uint64 request_seq, - ClusterSemanticActivationResult result); -extern bool cluster_semantic_activation_qvotec_poll_record_read( - ClusterSemanticActivationReadRequest *out); + ClusterSemanticActivationResult result); +extern bool +cluster_semantic_activation_qvotec_poll_record_read(ClusterSemanticActivationReadRequest *out); extern bool cluster_semantic_activation_qvotec_complete_record_read( - uint64 request_seq, ClusterSemanticActivationResult result, - bool implicit_open, + uint64 request_seq, ClusterSemanticActivationResult result, bool implicit_open, const uint8 selected_bytes[CLUSTER_SEMANTIC_ACTIVATION_RECORD_BYTES]); extern bool cluster_semantic_activation_undo_root_descriptor_mailbox_submit( - const ClusterSemanticFormationBinding *formation, - uint64 system_identifier, - const uint8 desired_bytes[CLUSTER_SEMANTIC_ACTIVATION_RECORD_BYTES], - uint64 *out_request_seq); + const ClusterSemanticFormationBinding *formation, uint64 system_identifier, + const uint8 desired_bytes[CLUSTER_SEMANTIC_ACTIVATION_RECORD_BYTES], uint64 *out_request_seq); extern bool cluster_semantic_activation_qvotec_pgrd_formation_matches( const ClusterSemanticFormationBinding *formation); -extern bool cluster_semantic_activation_qvotec_poll_undo_root_descriptor( - ClusterUndoRootDescriptorRequest *out); +extern bool +cluster_semantic_activation_qvotec_poll_undo_root_descriptor(ClusterUndoRootDescriptorRequest *out); extern bool cluster_semantic_activation_qvotec_complete_undo_root_descriptor( uint64 request_seq, ClusterSemanticActivationResult result); -extern bool -cluster_semantic_activation_undo_root_descriptor_mailbox_poll_completion( +extern bool cluster_semantic_activation_undo_root_descriptor_mailbox_poll_completion( uint64 request_seq, ClusterSemanticActivationResult *out_result); extern bool cluster_semantic_activation_qvotec_poll_undo_root_descriptor_read( ClusterUndoRootDescriptorReadRequest *out); extern bool cluster_semantic_activation_qvotec_complete_undo_root_descriptor_read( uint64 request_seq, ClusterUndoRootDescriptorState state, const uint8 selected_bytes[CLUSTER_UNDO_ROOT_DESCRIPTOR_BYTES]); -extern void cluster_semantic_activation_ack_handler( - const ClusterICEnvelope *env, const void *payload); +extern void cluster_semantic_activation_ack_handler(const ClusterICEnvelope *env, + const void *payload); extern void cluster_semantic_activation_lmon_tick(void); /* RF-ROOT P7 G3: the R4 cutover coordinator proof reads the ACK table's * COMPLETE state bound to the exact round identity (transition epoch, @@ -469,11 +455,9 @@ extern void cluster_semantic_activation_lmon_tick(void); * table stands at (or beyond) minimum_stage — SAMPLE for the create proof, * PREPARED for the activate proof (the W6 clause 3 CLOSED binding). */ extern bool cluster_semantic_activation_ack_complete_matches( - uint64 transition_epoch, uint64 record_generation, - uint64 expected_members_lo, uint64 expected_members_hi, - uint64 source_feature_bitmap, uint64 target_feature_bitmap, - uint64 capability_sample_digest, - ClusterSemanticActivationAckStage minimum_stage); + uint64 transition_epoch, uint64 record_generation, uint64 expected_members_lo, + uint64 expected_members_hi, uint64 source_feature_bitmap, uint64 target_feature_bitmap, + uint64 capability_sample_digest, ClusterSemanticActivationAckStage minimum_stage); extern ClusterSemanticActivationResult cluster_semantic_activation_submit(ClusterSemanticActivationAction action, ClusterSemanticActivationRefusal *refusal); diff --git a/src/include/cluster/cluster_sf_dep.h b/src/include/cluster/cluster_sf_dep.h index 88812773252..2655c12f27f 100644 --- a/src/include/cluster/cluster_sf_dep.h +++ b/src/include/cluster/cluster_sf_dep.h @@ -281,16 +281,17 @@ extern bool cluster_sf_peer_supports_gcs_inval_busy(int32 peer_id); extern bool cluster_sf_peer_supports_pcm_x_convert(int32 peer_id); extern bool cluster_sf_peer_supports_pcm_x_rebase(int32 peer_id); extern bool cluster_sf_peer_supports_pcm_x_source_floor(int32 peer_id); -extern bool cluster_sf_peer_multixact_current_capability_generation( - int32 peer_id, uint32 *generation_out); +extern bool cluster_sf_peer_multixact_current_capability_generation(int32 peer_id, + uint32 *generation_out); extern bool cluster_sf_peer_pcm_x_source_floor_sample(int32 peer_id, bool *source_floor_out, - uint32 *generation_out); -extern bool cluster_sf_peer_capability_family_sample( - int32 peer_id, uint32 required_capabilities, uint32 optional_capabilities, - bool *optional_supported_out, uint32 *generation_out); -extern bool cluster_sf_peer_capability_word_sample( - int32 peer_id, uint32 required_capabilities, - uint32 *capability_word_out, uint32 *generation_out); + uint32 *generation_out); +extern bool cluster_sf_peer_capability_family_sample(int32 peer_id, uint32 required_capabilities, + uint32 optional_capabilities, + bool *optional_supported_out, + uint32 *generation_out); +extern bool cluster_sf_peer_capability_word_sample(int32 peer_id, uint32 required_capabilities, + uint32 *capability_word_out, + uint32 *generation_out); extern bool cluster_sf_peer_capability_generation_matches(int32 peer_id, uint32 required_capabilities, uint32 expected_generation); diff --git a/src/include/cluster/cluster_side_online_owner.h b/src/include/cluster/cluster_side_online_owner.h index b741d19685f..f129bc2200a 100644 --- a/src/include/cluster/cluster_side_online_owner.h +++ b/src/include/cluster/cluster_side_online_owner.h @@ -12,23 +12,23 @@ typedef bool (*RfSideOnlineFreshAuthorityV1)(void *arg); -typedef struct RfSideOnlineProductionOwnerV1 -{ - void *authority_arg; +typedef struct RfSideOnlineProductionOwnerV1 { + void *authority_arg; RfSideOnlineFreshAuthorityV1 revalidate_authority; RfSideOnlineProjectionOwnerV1 projection; - bool protected_set_active; - bool protected_set_complete; - uint8 reserved2[6]; + bool protected_set_active; + bool protected_set_complete; + uint8 reserved2[6]; } RfSideOnlineProductionOwnerV1; -extern bool rf_side_online_production_owner_init_v1( - RfSideOnlineProductionOwnerV1 *owner, void *authority_arg, - RfSideOnlineFreshAuthorityV1 revalidate_authority, uint32 cluster_epoch, - bool failed_origin_redo_retained); -extern RfPageProofDetailV1 rf_side_online_production_preflight_v1( - const RfSideOnlinePlanV1 *plan, RfSideOnlineProductionOwnerV1 *owner); -extern RfPageProofDetailV1 rf_side_online_production_apply_v1( - const RfSideOnlinePlanV1 *plan, RfSideOnlineProductionOwnerV1 *owner); +extern bool +rf_side_online_production_owner_init_v1(RfSideOnlineProductionOwnerV1 *owner, void *authority_arg, + RfSideOnlineFreshAuthorityV1 revalidate_authority, + uint32 cluster_epoch, bool failed_origin_redo_retained); +extern RfPageProofDetailV1 +rf_side_online_production_preflight_v1(const RfSideOnlinePlanV1 *plan, + RfSideOnlineProductionOwnerV1 *owner); +extern RfPageProofDetailV1 rf_side_online_production_apply_v1(const RfSideOnlinePlanV1 *plan, + RfSideOnlineProductionOwnerV1 *owner); #endif diff --git a/src/include/cluster/cluster_side_online_plan.h b/src/include/cluster/cluster_side_online_plan.h index c6b4609d79d..812f75a3184 100644 --- a/src/include/cluster/cluster_side_online_plan.h +++ b/src/include/cluster/cluster_side_online_plan.h @@ -16,53 +16,44 @@ typedef struct RfSideOnlinePlanV1 RfSideOnlinePlanV1; -typedef enum RfSideOnlineOperationKindV1 -{ +typedef enum RfSideOnlineOperationKindV1 { RF_SIDE_ONLINE_OPERATION_INVALID = 0, RF_SIDE_ONLINE_OPERATION_XACT = 1, RF_SIDE_ONLINE_OPERATION_UNDO = 2, RF_SIDE_ONLINE_OPERATION_PROJECTION = 3 } RfSideOnlineOperationKindV1; -typedef struct RfSideOnlinePlanRequestV1 -{ - uint64 system_identifier; - uint8 storage_uuid[16]; +typedef struct RfSideOnlinePlanRequestV1 { + uint64 system_identifier; + uint8 storage_uuid[16]; const RfContributorStreamCutV1 *physical_cuts; - uint32 participant_count; - Size memory_budget; + uint32 participant_count; + Size memory_budget; } RfSideOnlinePlanRequestV1; -typedef struct RfSideOnlineOperationV1 -{ +typedef struct RfSideOnlineOperationV1 { RfPageOnlineRecordIdentityV1 identity; RfOpcodeRouteV1 route; RfSideOnlineOperationKindV1 kind; - uint32 owned_payload_offset; - uint32 owned_payload_length; + uint32 owned_payload_offset; + uint32 owned_payload_length; const uint8 *owned_payload; RfSideXactOperationV1 xact; ClusterUndoDecoded undo; ClusterSideProjectionOperationV1 projection; } RfSideOnlineOperationV1; -typedef bool (*RfSideOnlineApplyXactV1)(void *arg, - const RfSideOnlineOperationV1 *operation); -typedef bool (*RfSideOnlineApplyUndoV1)(void *arg, - const RfSideOnlineOperationV1 *operation); -typedef bool (*RfSideOnlineApplyProjectionV1)(void *arg, - const RfSideOnlineOperationV1 *operation); -typedef bool (*RfSideOnlinePreflightXactV1)(void *arg, - const RfSideOnlineOperationV1 *operation); -typedef bool (*RfSideOnlinePreflightUndoV1)(void *arg, - const RfSideOnlineOperationV1 *operation); +typedef bool (*RfSideOnlineApplyXactV1)(void *arg, const RfSideOnlineOperationV1 *operation); +typedef bool (*RfSideOnlineApplyUndoV1)(void *arg, const RfSideOnlineOperationV1 *operation); +typedef bool (*RfSideOnlineApplyProjectionV1)(void *arg, const RfSideOnlineOperationV1 *operation); +typedef bool (*RfSideOnlinePreflightXactV1)(void *arg, const RfSideOnlineOperationV1 *operation); +typedef bool (*RfSideOnlinePreflightUndoV1)(void *arg, const RfSideOnlineOperationV1 *operation); typedef bool (*RfSideOnlinePreflightProjectionV1)(void *arg, - const RfSideOnlineOperationV1 *operation); + const RfSideOnlineOperationV1 *operation); typedef bool (*RfSideOnlineBeginProtectedSetV1)(void *arg); typedef void (*RfSideOnlineEndProtectedSetV1)(void *arg, bool complete); -typedef struct RfSideOnlineApplyOpsV1 -{ +typedef struct RfSideOnlineApplyOpsV1 { void *arg; RfSideOnlineBeginProtectedSetV1 begin_protected_set; RfSideOnlineEndProtectedSetV1 end_protected_set; @@ -79,36 +70,34 @@ typedef struct RfSideOnlineApplyOpsV1 * retained-source certificate belongs to the immutable failed-origin replay * cut; projection bytes themselves never establish PREPARED, terminal truth, * readiness, or OPEN. */ -typedef struct RfSideOnlineProjectionOwnerV1 -{ - uint32 cluster_epoch; - bool failed_origin_redo_retained; - uint8 reserved5[3]; +typedef struct RfSideOnlineProjectionOwnerV1 { + uint32 cluster_epoch; + bool failed_origin_redo_retained; + uint8 reserved5[3]; ClusterSideProjectionApplyOpsV1 projection_ops; } RfSideOnlineProjectionOwnerV1; -extern RfPageProofDetailV1 rf_side_online_plan_create_v1( - const RfSideOnlinePlanRequestV1 *request, RfSideOnlinePlanV1 **out_plan); -extern RfPageProofDetailV1 rf_side_online_plan_feed_record_v1( - RfSideOnlinePlanV1 *plan, const RfDetachedRecordPlanV1 *record_plan, - const RfPageOnlineRecordIdentityV1 *identity); -extern RfPageProofDetailV1 rf_side_online_plan_seal_v1( - RfSideOnlinePlanV1 *plan); -extern uint32 rf_side_online_plan_operation_count_v1( - const RfSideOnlinePlanV1 *plan); -extern bool rf_side_online_plan_operation_v1(const RfSideOnlinePlanV1 *plan, - uint32 index, RfSideOnlineOperationV1 *out_operation); -extern RfPageProofDetailV1 rf_side_online_plan_preflight_v1( - const RfSideOnlinePlanV1 *plan, const RfSideOnlineApplyOpsV1 *ops); -extern RfPageProofDetailV1 rf_side_online_plan_apply_v1( - const RfSideOnlinePlanV1 *plan, const RfSideOnlineApplyOpsV1 *ops); -extern bool rf_side_online_projection_owner_init_v1( - RfSideOnlineProjectionOwnerV1 *owner, uint32 cluster_epoch, - bool failed_origin_redo_retained); +extern RfPageProofDetailV1 rf_side_online_plan_create_v1(const RfSideOnlinePlanRequestV1 *request, + RfSideOnlinePlanV1 **out_plan); +extern RfPageProofDetailV1 +rf_side_online_plan_feed_record_v1(RfSideOnlinePlanV1 *plan, + const RfDetachedRecordPlanV1 *record_plan, + const RfPageOnlineRecordIdentityV1 *identity); +extern RfPageProofDetailV1 rf_side_online_plan_seal_v1(RfSideOnlinePlanV1 *plan); +extern uint32 rf_side_online_plan_operation_count_v1(const RfSideOnlinePlanV1 *plan); +extern bool rf_side_online_plan_operation_v1(const RfSideOnlinePlanV1 *plan, uint32 index, + RfSideOnlineOperationV1 *out_operation); +extern RfPageProofDetailV1 rf_side_online_plan_preflight_v1(const RfSideOnlinePlanV1 *plan, + const RfSideOnlineApplyOpsV1 *ops); +extern RfPageProofDetailV1 rf_side_online_plan_apply_v1(const RfSideOnlinePlanV1 *plan, + const RfSideOnlineApplyOpsV1 *ops); +extern bool rf_side_online_projection_owner_init_v1(RfSideOnlineProjectionOwnerV1 *owner, + uint32 cluster_epoch, + bool failed_origin_redo_retained); extern bool rf_side_online_projection_preflight_owned_v1(void *arg, - const RfSideOnlineOperationV1 *operation); + const RfSideOnlineOperationV1 *operation); extern bool rf_side_online_projection_apply_owned_v1(void *arg, - const RfSideOnlineOperationV1 *operation); + const RfSideOnlineOperationV1 *operation); extern void rf_side_online_plan_destroy_v1(RfSideOnlinePlanV1 **plan); #endif diff --git a/src/include/cluster/cluster_side_prepared.h b/src/include/cluster/cluster_side_prepared.h index 9427dbb574a..2101228377d 100644 --- a/src/include/cluster/cluster_side_prepared.h +++ b/src/include/cluster/cluster_side_prepared.h @@ -41,10 +41,9 @@ #ifndef CLUSTER_SIDE_PREPARED_H #define CLUSTER_SIDE_PREPARED_H -typedef enum ClusterSidePreparedVerdict -{ +typedef enum ClusterSidePreparedVerdict { CLUSTER_SIDE_PREPARED_IN_DOUBT = 0, /* prepare + pending + TT/undo all match */ - CLUSTER_SIDE_PREPARED_BLOCKED /* any fact missing/conflicting */ + CLUSTER_SIDE_PREPARED_BLOCKED /* any fact missing/conflicting */ } ClusterSidePreparedVerdict; /* @@ -52,12 +51,11 @@ typedef enum ClusterSidePreparedVerdict * (the production 2PC/TT wiring supplies them); this layer judges the * conjunction only. */ -typedef struct ClusterSidePreparedInput -{ - bool prepare_redo_ok; /* exact prepare terminal redo seen */ - bool pending_durable_ok; /* database-scoped durable pending entry */ - bool tt_undo_match; /* matching shared TT/undo identity */ - bool gid_identity_match; /* same transaction, exact GID/identity */ +typedef struct ClusterSidePreparedInput { + bool prepare_redo_ok; /* exact prepare terminal redo seen */ + bool pending_durable_ok; /* database-scoped durable pending entry */ + bool tt_undo_match; /* matching shared TT/undo identity */ + bool gid_identity_match; /* same transaction, exact GID/identity */ } ClusterSidePreparedInput; /* @@ -66,8 +64,7 @@ typedef struct ClusterSidePreparedInput * origin-local file or recoverer-local cache standing in for the * database-scoped pending entry. */ -extern ClusterSidePreparedVerdict cluster_side_prepared_verdict( - const ClusterSidePreparedInput *in); +extern ClusterSidePreparedVerdict cluster_side_prepared_verdict(const ClusterSidePreparedInput *in); /* * RECO-style resolution (COMMIT_PREPARED / ABORT_PREPARED terminal): @@ -79,15 +76,13 @@ extern ClusterSidePreparedVerdict cluster_side_prepared_verdict( * released only after the matching resolution is durable verified * (§2.3 last bullet; §4 PREPARED rows). */ -typedef struct ClusterSidePreparedResolveInput -{ - bool terminal_redo_ok; /* commit-prepared / rollback-prepared redo */ - bool pending_match; /* exact pending/prepare identity match */ - bool tt_undo_complete; /* COMMIT: TT match; ROLLBACK: undo done */ +typedef struct ClusterSidePreparedResolveInput { + bool terminal_redo_ok; /* commit-prepared / rollback-prepared redo */ + bool pending_match; /* exact pending/prepare identity match */ + bool tt_undo_complete; /* COMMIT: TT match; ROLLBACK: undo done */ } ClusterSidePreparedResolveInput; -extern bool cluster_side_prepared_resolve_ready( - const ClusterSidePreparedResolveInput *in); +extern bool cluster_side_prepared_resolve_ready(const ClusterSidePreparedResolveInput *in); /* * cluster_side_prepared_gid_identity_ok -- the GID identity leg of the @@ -96,8 +91,7 @@ extern bool cluster_side_prepared_resolve_ready( * wire/2PC path uses, and fully inside the available payload bytes. * Pure predicate; no state, no locks. */ -extern bool cluster_side_prepared_gid_identity_ok(const char *gid, - uint16 gidlen, +extern bool cluster_side_prepared_gid_identity_ok(const char *gid, uint16 gidlen, uint32 available_bytes); -#endif /* CLUSTER_SIDE_PREPARED_H */ +#endif /* CLUSTER_SIDE_PREPARED_H */ diff --git a/src/include/cluster/cluster_side_projection.h b/src/include/cluster/cluster_side_projection.h index 88c3b30f117..660df11fd53 100644 --- a/src/include/cluster/cluster_side_projection.h +++ b/src/include/cluster/cluster_side_projection.h @@ -45,15 +45,13 @@ #include "access/transam.h" #include "access/xlogdefs.h" -typedef enum ClusterSideProjectionKind -{ +typedef enum ClusterSideProjectionKind { CLUSTER_SIDE_PROJECTION_CLOG = 0, CLUSTER_SIDE_PROJECTION_MULTIXACT, CLUSTER_SIDE_PROJECTION_COMMIT_TS } ClusterSideProjectionKind; -typedef enum ClusterSideProjectionActionV1 -{ +typedef enum ClusterSideProjectionActionV1 { CLUSTER_SIDE_PROJECTION_ACTION_INVALID = 0, CLUSTER_SIDE_PROJECTION_ACTION_ZERO_PAGE, CLUSTER_SIDE_PROJECTION_ACTION_CREATE, @@ -65,58 +63,53 @@ typedef enum ClusterSideProjectionActionV1 * MULTIXACT CREATE members remain caller-owned bytes in the enclosing SIDE * plan; member_count/member_offset describe their exact native identity. */ -typedef struct ClusterSideProjectionOperationV1 -{ +typedef struct ClusterSideProjectionOperationV1 { ClusterSideProjectionKind kind; ClusterSideProjectionActionV1 action; - uint8 normalized_info; - uint8 reserved9[3]; - int32 page_number; - Oid oldest_database; + uint8 normalized_info; + uint8 reserved9[3]; + int32 page_number; + Oid oldest_database; TransactionId oldest_xid; MultiXactId multixact_id; MultiXactOffset member_offset; - uint32 member_count; + uint32 member_count; MultiXactId truncate_start_multixact; MultiXactId truncate_end_multixact; MultiXactOffset truncate_start_member; MultiXactOffset truncate_end_member; } ClusterSideProjectionOperationV1; -typedef enum ClusterSideProjectionApplyResultV1 -{ +typedef enum ClusterSideProjectionApplyResultV1 { CLUSTER_SIDE_PROJECTION_APPLY_OK = 0, CLUSTER_SIDE_PROJECTION_APPLY_BLOCKED, CLUSTER_SIDE_PROJECTION_APPLY_POST_READ_FAILED } ClusterSideProjectionApplyResultV1; -typedef struct ClusterSideProjectionApplyInputV1 -{ +typedef struct ClusterSideProjectionApplyInputV1 { const ClusterSideProjectionOperationV1 *operation; const uint8 *owned_payload; - uint32 owned_payload_length; - uint16 origin_thread; - bool source_retained; - uint8 reserved19; - uint32 cluster_epoch; + uint32 owned_payload_length; + uint16 origin_thread; + bool source_retained; + uint8 reserved19; + uint32 cluster_epoch; XLogRecPtr source_lsn; XLogRecPtr source_end_lsn; } ClusterSideProjectionApplyInputV1; -typedef bool (*ClusterSideProjectionResetRangeV1)(void *arg, - int origin_slot, TransactionId first_xid, uint32 xid_count); -typedef bool (*ClusterSideProjectionRangeEmptyV1)(void *arg, - int origin_slot, TransactionId first_xid, uint32 xid_count); -typedef bool (*ClusterSideProjectionTruncateBeforeV1)(void *arg, - int origin_slot, TransactionId oldest_xid); -typedef bool (*ClusterSideProjectionMultiOperationV1)(void *arg, - int origin_slot, uint32 cluster_epoch, - const ClusterSideProjectionOperationV1 *operation, - const uint8 *owned_payload, uint32 owned_payload_length, - XLogRecPtr source_lsn, XLogRecPtr source_end_lsn); +typedef bool (*ClusterSideProjectionResetRangeV1)(void *arg, int origin_slot, + TransactionId first_xid, uint32 xid_count); +typedef bool (*ClusterSideProjectionRangeEmptyV1)(void *arg, int origin_slot, + TransactionId first_xid, uint32 xid_count); +typedef bool (*ClusterSideProjectionTruncateBeforeV1)(void *arg, int origin_slot, + TransactionId oldest_xid); +typedef bool (*ClusterSideProjectionMultiOperationV1)( + void *arg, int origin_slot, uint32 cluster_epoch, + const ClusterSideProjectionOperationV1 *operation, const uint8 *owned_payload, + uint32 owned_payload_length, XLogRecPtr source_lsn, XLogRecPtr source_end_lsn); -typedef struct ClusterSideProjectionApplyOpsV1 -{ +typedef struct ClusterSideProjectionApplyOpsV1 { void *arg; ClusterSideProjectionResetRangeV1 reset_remote_xact_range; ClusterSideProjectionRangeEmptyV1 remote_xact_range_empty; @@ -126,22 +119,19 @@ typedef struct ClusterSideProjectionApplyOpsV1 } ClusterSideProjectionApplyOpsV1; extern ClusterSideProjectionApplyResultV1 -cluster_side_projection_target_preflight_v1( - const ClusterSideProjectionApplyInputV1 *input); +cluster_side_projection_target_preflight_v1(const ClusterSideProjectionApplyInputV1 *input); extern ClusterSideProjectionApplyResultV1 -cluster_side_projection_apply_owned_v1( - const ClusterSideProjectionApplyInputV1 *input, - const ClusterSideProjectionApplyOpsV1 *ops); +cluster_side_projection_apply_owned_v1(const ClusterSideProjectionApplyInputV1 *input, + const ClusterSideProjectionApplyOpsV1 *ops); /* * §2.4 verifier facts for one projection scope. */ -typedef struct ClusterSideProjectionVerifyInput -{ - bool canonical_truth_ok; /* canonical producer (TT/undo + matching +typedef struct ClusterSideProjectionVerifyInput { + bool canonical_truth_ok; /* canonical producer (TT/undo + matching * terminal redo) bidirectional match */ - bool coverage_ok; /* xid/origin/wrap/terminal coverage exact */ - bool integrity_ok; /* checksum/coverage mismatch detector passed */ + bool coverage_ok; /* xid/origin/wrap/terminal coverage exact */ + bool integrity_ok; /* checksum/coverage mismatch detector passed */ } ClusterSideProjectionVerifyInput; /* @@ -165,20 +155,18 @@ extern bool cluster_side_projection_verified(ClusterSideProjectionKind kind, * check for the rebuild source. */ extern bool cluster_side_projection_rebuildable(ClusterSideProjectionKind kind, - bool source_retained, - bool canonical_producer_ok); + bool source_retained, bool canonical_producer_ok); /* * §2.4 lookup verdict: a VERIFIED projection answers; anything else is * FAIL_CLOSED (scope closed until rebuild; no synchronous network or * durable I/O is added by this judgement — it is a pure function). */ -typedef enum ClusterSideProjectionLookup -{ +typedef enum ClusterSideProjectionLookup { CLUSTER_SIDE_PROJECTION_LOOKUP_OK = 0, CLUSTER_SIDE_PROJECTION_LOOKUP_FAIL_CLOSED } ClusterSideProjectionLookup; extern ClusterSideProjectionLookup cluster_side_projection_lookup(bool verified); -#endif /* CLUSTER_SIDE_PROJECTION_H */ +#endif /* CLUSTER_SIDE_PROJECTION_H */ diff --git a/src/include/cluster/cluster_side_recovery.h b/src/include/cluster/cluster_side_recovery.h index d9271a81612..088335ad734 100644 --- a/src/include/cluster/cluster_side_recovery.h +++ b/src/include/cluster/cluster_side_recovery.h @@ -51,15 +51,14 @@ * version this domain must bind; the consumer never re-parses the page * (spec §1.2 D-SIDE-06: 不复制 page parser). */ -typedef struct ClusterSidePageConsumeInput -{ +typedef struct ClusterSidePageConsumeInput { const ClusterPageIdentity *identity; - ClusterPageClass page_class; /* UNKNOWN/UNCLASSIFIED fails */ + ClusterPageClass page_class; /* UNKNOWN/UNCLASSIFIED fails */ const ClusterPageVersion *expected_before; /* must be valid */ - bool contributor_coverage; /* RF-PAGE chain closed */ - bool durability_barrier_ok; /* RF-PAGE durability done */ - bool post_read_ok; /* RF-PAGE canonical post-read done */ - bool authority_revalidated; /* RF-PAGE ROOT revalidation done */ + bool contributor_coverage; /* RF-PAGE chain closed */ + bool durability_barrier_ok; /* RF-PAGE durability done */ + bool post_read_ok; /* RF-PAGE canonical post-read done */ + bool authority_revalidated; /* RF-PAGE ROOT revalidation done */ } ClusterSidePageConsumeInput; /* @@ -77,12 +76,11 @@ extern bool cluster_side_page_consumer_ready(const ClusterSidePageConsumeInput * * and no whole-instance barrier exists (§4 row "resource A verified、 * resource B blocked -> A 可 open,B 保持 fenced"). */ -typedef struct ClusterSideReadinessInput -{ - uint16 resource_id; /* exact resource/thread identity */ - bool page_proof_ok; /* D-SIDE-06 verdict for the resource */ - bool side_proof_ok; /* this domain's truth proof (TT/undo/pending) */ - bool authority_fresh; /* RF-ROOT authority fresh */ +typedef struct ClusterSideReadinessInput { + uint16 resource_id; /* exact resource/thread identity */ + bool page_proof_ok; /* D-SIDE-06 verdict for the resource */ + bool side_proof_ok; /* this domain's truth proof (TT/undo/pending) */ + bool authority_fresh; /* RF-ROOT authority fresh */ } ClusterSideReadinessInput; extern bool cluster_side_resource_readiness(const ClusterSideReadinessInput *in); @@ -96,25 +94,23 @@ extern bool cluster_side_resource_readiness(const ClusterSideReadinessInput *in) * denial reason (spec §1.2 D-SIDE-08, §2.2, §4 row "all affected * TT/undo/space bytes durable 但 post-read 缺一项 -> deny retire"). */ -typedef enum ClusterSideRetentionVerdict -{ - CLUSTER_SIDE_RETENTION_READY = 0, /* FND-10 SIDE side holds */ - CLUSTER_SIDE_RETENTION_DENY_NOT_DURABLE, /* some affected bytes not durable */ - CLUSTER_SIDE_RETENTION_DENY_NO_POST_READ, /* some affected post-read missing */ - CLUSTER_SIDE_RETENTION_DENY_CONSUMER, /* an exact consumer remains */ - CLUSTER_SIDE_RETENTION_DENY_INVALID /* bad input / empty set */ +typedef enum ClusterSideRetentionVerdict { + CLUSTER_SIDE_RETENTION_READY = 0, /* FND-10 SIDE side holds */ + CLUSTER_SIDE_RETENTION_DENY_NOT_DURABLE, /* some affected bytes not durable */ + CLUSTER_SIDE_RETENTION_DENY_NO_POST_READ, /* some affected post-read missing */ + CLUSTER_SIDE_RETENTION_DENY_CONSUMER, /* an exact consumer remains */ + CLUSTER_SIDE_RETENTION_DENY_INVALID /* bad input / empty set */ } ClusterSideRetentionVerdict; -typedef struct ClusterSideRetentionProof -{ - uint16 failed_origin_thread; - uint32 affected_count; /* affected TT/undo/pending/space resources */ - bool all_bytes_durable; /* every affected byte durable */ - bool all_post_read_ok; /* every affected canonical post-read done */ - bool consumers_zero; /* no exact resource/thread consumer remains */ +typedef struct ClusterSideRetentionProof { + uint16 failed_origin_thread; + uint32 affected_count; /* affected TT/undo/pending/space resources */ + bool all_bytes_durable; /* every affected byte durable */ + bool all_post_read_ok; /* every affected canonical post-read done */ + bool consumers_zero; /* no exact resource/thread consumer remains */ } ClusterSideRetentionProof; -extern ClusterSideRetentionVerdict cluster_side_retention_proof_ready( - const ClusterSideRetentionProof *proof); +extern ClusterSideRetentionVerdict +cluster_side_retention_proof_ready(const ClusterSideRetentionProof *proof); -#endif /* CLUSTER_SIDE_RECOVERY_H */ +#endif /* CLUSTER_SIDE_RECOVERY_H */ diff --git a/src/include/cluster/cluster_side_route.h b/src/include/cluster/cluster_side_route.h index 4ab41e9a597..b5be6f44e6e 100644 --- a/src/include/cluster/cluster_side_route.h +++ b/src/include/cluster/cluster_side_route.h @@ -50,30 +50,27 @@ * everything without an exact route is BLOCKED (the matrix's * "unknown/failure direction" is always BLOCKED). */ -typedef enum ClusterSideRouteKind -{ +typedef enum ClusterSideRouteKind { CLUSTER_SIDE_ROUTE_PAGE = 0, /* RF-PAGE owns the mutation */ - CLUSTER_SIDE_ROUTE_TT_UNDO, /* transaction/undo truth primitive */ - CLUSTER_SIDE_ROUTE_PROJECTION, /* CLOG/MULTIXACT/COMMIT_TS projection */ - CLUSTER_SIDE_ROUTE_STORAGE, /* canonical storage lifecycle */ + CLUSTER_SIDE_ROUTE_TT_UNDO, /* transaction/undo truth primitive */ + CLUSTER_SIDE_ROUTE_PROJECTION, /* CLOG/MULTIXACT/COMMIT_TS projection */ + CLUSTER_SIDE_ROUTE_STORAGE, /* canonical storage lifecycle */ CLUSTER_SIDE_ROUTE_PROVED_NOOP, /* positive no-mutation proof */ - CLUSTER_SIDE_ROUTE_BLOCKED /* mutation=0, resource never released */ + CLUSTER_SIDE_ROUTE_BLOCKED /* mutation=0, resource never released */ } ClusterSideRouteKind; -typedef struct ClusterSideRouteRow -{ - uint8 rmid; - uint16 opcode; /* 0 with opcode_mask==0 = whole rmgr */ - uint16 opcode_mask; /* 0 = exact opcode match */ +typedef struct ClusterSideRouteRow { + uint8 rmid; + uint16 opcode; /* 0 with opcode_mask==0 = whole rmgr */ + uint16 opcode_mask; /* 0 = exact opcode match */ ClusterSideRouteKind kind; - const char *noop_reason; /* PROVED_NOOP proof kind (else NULL) */ + const char *noop_reason; /* PROVED_NOOP proof kind (else NULL) */ } ClusterSideRouteRow; /* * §2.1 verdicts. */ -typedef enum ClusterSideRouteVerdict -{ +typedef enum ClusterSideRouteVerdict { CLUSTER_SIDE_ROUTE_VERDICT_APPLY = 0, CLUSTER_SIDE_ROUTE_VERDICT_PROVED_NOOP, CLUSTER_SIDE_ROUTE_VERDICT_BLOCKED @@ -83,15 +80,13 @@ typedef enum ClusterSideRouteVerdict * Total-registry lookup: exactly one row per (rmid, opcode), or false * for an unknown rmgr/opcode (the caller must treat it as BLOCKED). */ -extern bool cluster_side_route_lookup(uint8 rmid, uint16 opcode, - ClusterSideRouteRow *out); +extern bool cluster_side_route_lookup(uint8 rmid, uint16 opcode, ClusterSideRouteRow *out); /* * §2.1 verdict — pure function of the row (cold/online identical, * U-SIDE-02). A PROVED_NOOP row carries its proof kind; anything * without a positive no-mutation proof is BLOCKED. */ -extern ClusterSideRouteVerdict cluster_side_route_verdict( - const ClusterSideRouteRow *row); +extern ClusterSideRouteVerdict cluster_side_route_verdict(const ClusterSideRouteRow *row); -#endif /* CLUSTER_SIDE_ROUTE_H */ +#endif /* CLUSTER_SIDE_ROUTE_H */ diff --git a/src/include/cluster/cluster_side_space.h b/src/include/cluster/cluster_side_space.h index 615f695dda5..7fce4519541 100644 --- a/src/include/cluster/cluster_side_space.h +++ b/src/include/cluster/cluster_side_space.h @@ -44,8 +44,7 @@ #include "cluster/cluster_page_version.h" -typedef enum ClusterSideSpaceKind -{ +typedef enum ClusterSideSpaceKind { CLUSTER_SIDE_SPACE_HWM = 0, CLUSTER_SIDE_SPACE_EXTENT, CLUSTER_SIDE_SPACE_BITMAP @@ -70,8 +69,7 @@ extern bool cluster_side_space_metadata_mutation_allowed(ClusterSideSpaceKind ki */ extern ClusterPageApplyVerdict cluster_side_space_metadata_page_verdict( ClusterSideSpaceKind kind, const ClusterPageVersion *current_working, - const ClusterPageVersion *expected_before, - const ClusterPageVersion *result_version, + const ClusterPageVersion *expected_before, const ClusterPageVersion *result_version, const ClusterPageVersion *trusted_source_version); -#endif /* CLUSTER_SIDE_SPACE_H */ +#endif /* CLUSTER_SIDE_SPACE_H */ diff --git a/src/include/cluster/cluster_side_stats.h b/src/include/cluster/cluster_side_stats.h index 7ffc7bf906a..a7597221b2a 100644 --- a/src/include/cluster/cluster_side_stats.h +++ b/src/include/cluster/cluster_side_stats.h @@ -40,8 +40,7 @@ #include "port/atomics.h" -typedef struct ClusterSideStats -{ +typedef struct ClusterSideStats { /* route events (D-SIDE-01 verdicts observed) */ pg_atomic_uint64 route_applies; pg_atomic_uint64 route_noops; @@ -74,4 +73,4 @@ extern void cluster_side_stats_durability(ClusterSideStats *stats); */ extern bool cluster_side_stats_describe(const char *name, int *kind); -#endif /* CLUSTER_SIDE_STATS_H */ +#endif /* CLUSTER_SIDE_STATS_H */ diff --git a/src/include/cluster/cluster_side_undo.h b/src/include/cluster/cluster_side_undo.h index c729a5f6d40..d5773319948 100644 --- a/src/include/cluster/cluster_side_undo.h +++ b/src/include/cluster/cluster_side_undo.h @@ -41,12 +41,11 @@ #define CLUSTER_SIDE_UNDO_H #include "access/xlogreader.h" -#include "cluster/cluster_scn.h" /* SCN */ +#include "cluster/cluster_scn.h" /* SCN */ #include "cluster/cluster_itl_slot.h" /* UBA */ -#include "storage/itemptr.h" /* TransactionId */ +#include "storage/itemptr.h" /* TransactionId */ -typedef enum ClusterUndoDecodedKind -{ +typedef enum ClusterUndoDecodedKind { CLUSTER_UNDO_KIND_SEGMENT_INIT = 0, CLUSTER_UNDO_KIND_TT_BIND, CLUSTER_UNDO_KIND_TT_COMMIT, @@ -57,7 +56,7 @@ typedef enum ClusterUndoDecodedKind CLUSTER_UNDO_KIND_SEGMENT_REUSE, CLUSTER_UNDO_KIND_BLOCK_WRITE, CLUSTER_UNDO_KIND_BLOCK_WRITE_MULTI, - CLUSTER_UNDO_KIND_HW_RESERVE, /* BLOCKED: STOP-RF-SIDE-SPACE-ABI */ + CLUSTER_UNDO_KIND_HW_RESERVE, /* BLOCKED: STOP-RF-SIDE-SPACE-ABI */ CLUSTER_UNDO_KIND_UNKNOWN } ClusterUndoDecodedKind; @@ -67,43 +66,42 @@ typedef enum ClusterUndoDecodedKind * re-derived; the per-kind fields are filled only for the kinds that * carry them (0 otherwise). */ -typedef struct ClusterUndoDecoded -{ +typedef struct ClusterUndoDecoded { ClusterUndoDecodedKind kind; - uint16 opcode; /* rmgr info after XLR_INFO_MASK */ - uint8 instance; /* owner instance (1..128) */ - uint32 segment_id; - uint16 slot_offset; /* TT slot offset */ - uint16 wrap; /* TT reuse generation */ - TransactionId xid; /* TT slot owner */ - SCN commit_scn; /* TT commit SCN */ - uint32 block_no; /* BLOCK_WRITE target block */ - bool has_payload; /* BLOCK_WRITE carries a payload image */ - bool has_fpi; /* BLOCK_WRITE payload is a full page */ - uint16 rec_off; - uint16 rec_len; - uint16 slot_off; - uint16 slot_len; - uint32 payload_offset; /* immutable-copy range in record main data */ - uint32 payload_length; - uint32 expected_generation; - uint32 new_generation; - uint32 cluster_epoch; - uint64 root_id; - uint64 root_generation; - uint64 formation_epoch; - uint64 admission_record_generation; - uint64 seal_generation; - uint64 touched_nodes_low; - uint64 touched_nodes_high; - uint8 ack_set_digest[16]; - uint8 format_version; - uint8 flags; - uint8 terminal_status; - uint8 old_state; - uint8 new_state; - uint8 reserved_zero[1]; - UBA first_undo_block; + uint16 opcode; /* rmgr info after XLR_INFO_MASK */ + uint8 instance; /* owner instance (1..128) */ + uint32 segment_id; + uint16 slot_offset; /* TT slot offset */ + uint16 wrap; /* TT reuse generation */ + TransactionId xid; /* TT slot owner */ + SCN commit_scn; /* TT commit SCN */ + uint32 block_no; /* BLOCK_WRITE target block */ + bool has_payload; /* BLOCK_WRITE carries a payload image */ + bool has_fpi; /* BLOCK_WRITE payload is a full page */ + uint16 rec_off; + uint16 rec_len; + uint16 slot_off; + uint16 slot_len; + uint32 payload_offset; /* immutable-copy range in record main data */ + uint32 payload_length; + uint32 expected_generation; + uint32 new_generation; + uint32 cluster_epoch; + uint64 root_id; + uint64 root_generation; + uint64 formation_epoch; + uint64 admission_record_generation; + uint64 seal_generation; + uint64 touched_nodes_low; + uint64 touched_nodes_high; + uint8 ack_set_digest[16]; + uint8 format_version; + uint8 flags; + uint8 terminal_status; + uint8 old_state; + uint8 new_state; + uint8 reserved_zero[1]; + UBA first_undo_block; } ClusterUndoDecoded; /* @@ -121,26 +119,23 @@ extern bool cluster_undo_decode(XLogReaderState *record, ClusterUndoDecoded *out */ extern bool cluster_undo_preflight(const ClusterUndoDecoded *decoded); -typedef enum ClusterUndoApplyResultV1 -{ +typedef enum ClusterUndoApplyResultV1 { CLUSTER_UNDO_APPLY_OK = 0, CLUSTER_UNDO_APPLY_BLOCKED = 1, CLUSTER_UNDO_APPLY_POST_READ_FAILED = 2 } ClusterUndoApplyResultV1; -typedef enum ClusterUndoTargetPreflightV1 -{ +typedef enum ClusterUndoTargetPreflightV1 { CLUSTER_UNDO_TARGET_APPLY = 0, CLUSTER_UNDO_TARGET_PROVED_NOOP = 1, CLUSTER_UNDO_TARGET_BLOCKED = 2 } ClusterUndoTargetPreflightV1; /* Classify the exact durable TT target without mutating it. */ -extern ClusterUndoTargetPreflightV1 cluster_undo_preflight_tt_target_v1( - const ClusterUndoDecoded *decoded); +extern ClusterUndoTargetPreflightV1 +cluster_undo_preflight_tt_target_v1(const ClusterUndoDecoded *decoded); /* Apply one already-decoded TT operation and verify the exact durable slot. */ -extern ClusterUndoApplyResultV1 cluster_undo_apply_tt_v1( - const ClusterUndoDecoded *decoded); +extern ClusterUndoApplyResultV1 cluster_undo_apply_tt_v1(const ClusterUndoDecoded *decoded); -#endif /* CLUSTER_SIDE_UNDO_H */ +#endif /* CLUSTER_SIDE_UNDO_H */ diff --git a/src/include/cluster/cluster_side_xact.h b/src/include/cluster/cluster_side_xact.h index b3c7cadaa56..b359bdb2e9b 100644 --- a/src/include/cluster/cluster_side_xact.h +++ b/src/include/cluster/cluster_side_xact.h @@ -16,8 +16,7 @@ #define CLUSTER_SIDE_XACT_INTERFACE_V1 1 -typedef enum RfSideXactKindV1 -{ +typedef enum RfSideXactKindV1 { RF_SIDE_XACT_INVALID = 0, RF_SIDE_XACT_COMMIT = 1, RF_SIDE_XACT_ABORT = 2, @@ -26,100 +25,89 @@ typedef enum RfSideXactKindV1 RF_SIDE_XACT_ABORT_PREPARED = 5 } RfSideXactKindV1; -typedef struct RfSideXactOperationV1 -{ - uint64 system_identifier; +typedef struct RfSideXactOperationV1 { + uint64 system_identifier; RfSideXactKindV1 kind; - uint16 origin_thread; - uint16 reserved_zero; + uint16 origin_thread; + uint16 reserved_zero; TransactionId xid; - Oid database; - Oid prepared_owner; - uint32 xinfo; - uint32 prepare_payload_length; + Oid database; + Oid prepared_owner; + uint32 xinfo; + uint32 prepare_payload_length; TimestampTz prepared_at; - SCN terminal_scn; + SCN terminal_scn; TimestampTz terminal_timestamp; - bool has_tt_delta; - uint8 reserved49[7]; + bool has_tt_delta; + uint8 reserved49[7]; xl_xact_tt_commit tt_delta; - uint8 prepare_binding[CLUSTER_REMOTE_XACT_PREPARE_DIGEST_BYTES]; - char prepare_gid[GIDSIZE]; - uint16 prepared_record_version; - uint16 prepared_binding_count; - uint32 prepared_sublink_count; + uint8 prepare_binding[CLUSTER_REMOTE_XACT_PREPARE_DIGEST_BYTES]; + char prepare_gid[GIDSIZE]; + uint16 prepared_record_version; + uint16 prepared_binding_count; + uint32 prepared_sublink_count; ClusterTT2PCBinding prepared_bindings[CLUSTER_TT_2PC_MAX_BINDINGS]; ClusterTT2PCSubLink prepared_sublinks[CLUSTER_TT_2PC_MAX_SUBLINKS]; - UBA prepared_heads[CLUSTER_TT_2PC_MAX_BINDINGS]; + UBA prepared_heads[CLUSTER_TT_2PC_MAX_BINDINGS]; } RfSideXactOperationV1; -extern bool rf_side_xact_decode_v1(XLogReaderState *record, - uint64 system_identifier, uint16 origin_thread, - RfSideXactOperationV1 *out); -extern bool rf_side_xact_structural_preflight_v1( - const RfSideXactOperationV1 *operation); +extern bool rf_side_xact_decode_v1(XLogReaderState *record, uint64 system_identifier, + uint16 origin_thread, RfSideXactOperationV1 *out); +extern bool rf_side_xact_structural_preflight_v1(const RfSideXactOperationV1 *operation); -typedef enum RfSideXactApplyResultV1 -{ +typedef enum RfSideXactApplyResultV1 { RF_SIDE_XACT_APPLY_OK = 0, RF_SIDE_XACT_APPLY_BLOCKED = 1, RF_SIDE_XACT_APPLY_CONFLICT = 2, RF_SIDE_XACT_APPLY_POST_READ_FAILED = 3 } RfSideXactApplyResultV1; -typedef struct RfSideXactTTCommitRequirementV1 -{ - uint8 instance; - bool requires_apply; - uint16 slot_offset; - uint16 wrap; - uint16 reserved_zero; - uint32 segment_id; +typedef struct RfSideXactTTCommitRequirementV1 { + uint8 instance; + bool requires_apply; + uint16 slot_offset; + uint16 wrap; + uint16 reserved_zero; + uint32 segment_id; TransactionId xid; - SCN commit_scn; + SCN commit_scn; } RfSideXactTTCommitRequirementV1; -typedef struct RfSideXactCommitPreparedRequirementsV1 -{ - uint16 count; - uint16 reserved_zero; +typedef struct RfSideXactCommitPreparedRequirementsV1 { + uint16 count; + uint16 reserved_zero; RfSideXactTTCommitRequirementV1 bindings[CLUSTER_TT_2PC_MAX_BINDINGS]; } RfSideXactCommitPreparedRequirementsV1; -typedef struct RfSideXactTTAbortRequirementV1 -{ - uint8 instance; - bool requires_apply; - uint16 reserved_zero; - uint32 segment_id; - uint16 slot_offset; - uint16 wrap; +typedef struct RfSideXactTTAbortRequirementV1 { + uint8 instance; + bool requires_apply; + uint16 reserved_zero; + uint32 segment_id; + uint16 slot_offset; + uint16 wrap; TransactionId xid; } RfSideXactTTAbortRequirementV1; -typedef struct RfSideXactAbortPreparedRequirementsV1 -{ - uint16 count; - uint16 reserved_zero; +typedef struct RfSideXactAbortPreparedRequirementsV1 { + uint16 count; + uint16 reserved_zero; RfSideXactTTAbortRequirementV1 bindings[CLUSTER_TT_2PC_MAX_BINDINGS]; } RfSideXactAbortPreparedRequirementsV1; /* Apply one already-decoded operation. This function never reads WAL. */ -extern RfSideXactApplyResultV1 rf_side_xact_apply_v1( - const RfSideXactOperationV1 *operation); -extern RfSideXactApplyResultV1 rf_side_xact_target_preflight_owned_v1( - const RfSideXactOperationV1 *operation, const uint8 *owned_payload, - uint32 owned_payload_length); +extern RfSideXactApplyResultV1 rf_side_xact_apply_v1(const RfSideXactOperationV1 *operation); extern RfSideXactApplyResultV1 -rf_side_xact_commit_prepared_requirements_v1( +rf_side_xact_target_preflight_owned_v1(const RfSideXactOperationV1 *operation, + const uint8 *owned_payload, uint32 owned_payload_length); +extern RfSideXactApplyResultV1 rf_side_xact_commit_prepared_requirements_v1( const RfSideXactOperationV1 *operation, RfSideXactCommitPreparedRequirementsV1 *out_requirements); -extern RfSideXactApplyResultV1 -rf_side_xact_abort_prepared_requirements_v1( +extern RfSideXactApplyResultV1 rf_side_xact_abort_prepared_requirements_v1( const RfSideXactOperationV1 *operation, RfSideXactAbortPreparedRequirementsV1 *out_requirements); -extern RfSideXactApplyResultV1 rf_side_xact_apply_owned_v1( - const RfSideXactOperationV1 *operation, const uint8 *owned_payload, - uint32 owned_payload_length); +extern RfSideXactApplyResultV1 rf_side_xact_apply_owned_v1(const RfSideXactOperationV1 *operation, + const uint8 *owned_payload, + uint32 owned_payload_length); #endif diff --git a/src/include/cluster/cluster_startup_phase.h b/src/include/cluster/cluster_startup_phase.h index c59b8fabc90..00bc0b93b27 100644 --- a/src/include/cluster/cluster_startup_phase.h +++ b/src/include/cluster/cluster_startup_phase.h @@ -269,7 +269,7 @@ typedef enum ClusterAuthorityReadiness { } ClusterAuthorityReadiness; typedef struct ClusterPhaseSharedState { - LWLock lwlock; /* LWTRANCHE_CLUSTER_STARTUP_PHASE */ + LWLock lwlock; /* LWTRANCHE_CLUSTER_STARTUP_PHASE */ pg_atomic_uint32 current_phase; /* AD-023 A1: lock-free reads */ TimestampTz phase_start_times[CLUSTER_PHASE_LAST + 1]; PhaseHistoryEntry phase_history[CLUSTER_PHASE_HISTORY_RING_SIZE]; @@ -309,13 +309,12 @@ extern void cluster_phase_shmem_register(void); * transitions; every consumer gets a generation-revalidated predicate. */ extern ClusterAuthorityReadiness cluster_authority_readiness_get(void); extern bool cluster_authority_readiness_managed(void); -extern bool cluster_authority_handoff_identity_current( - uint64 expected_self_incarnation, uint64 expected_predecessor_floor); -extern bool cluster_authority_readiness_begin( - uint16 origin_thread, const ClusterFenceAuthorityProof *authority, - const ClusterFormationSnapshotV1 *formation); -extern bool cluster_authority_readiness_bind_recovery_generation( - uint64 lms_generation); +extern bool cluster_authority_handoff_identity_current(uint64 expected_self_incarnation, + uint64 expected_predecessor_floor); +extern bool cluster_authority_readiness_begin(uint16 origin_thread, + const ClusterFenceAuthorityProof *authority, + const ClusterFormationSnapshotV1 *formation); +extern bool cluster_authority_readiness_bind_recovery_generation(uint64 lms_generation); extern bool cluster_authority_readiness_publish_recovery(uint64 lms_generation); extern bool cluster_authority_readiness_publish_serving(void); extern void cluster_authority_readiness_clear(void); @@ -328,10 +327,9 @@ extern bool cluster_authority_serving_rebind_lmon(void); * (no local episode closes for its own departure; re-stamps from its own * applied CLEAN_LEAVE evidence). */ extern bool cluster_authority_serving_rebind_leaver(void); -extern bool cluster_recovery_authority_resid_mode_allowed( - const ClusterResId *resid, LOCKMODE mode); -extern bool cluster_recovery_authority_request_allowed( - const ClusterResId *resid, LOCKMODE mode, bool startup_process); +extern bool cluster_recovery_authority_resid_mode_allowed(const ClusterResId *resid, LOCKMODE mode); +extern bool cluster_recovery_authority_request_allowed(const ClusterResId *resid, LOCKMODE mode, + bool startup_process); /* ---------- diff --git a/src/include/cluster/cluster_terminal_ref_census.h b/src/include/cluster/cluster_terminal_ref_census.h index 28722768ce0..5ed12baea44 100644 --- a/src/include/cluster/cluster_terminal_ref_census.h +++ b/src/include/cluster/cluster_terminal_ref_census.h @@ -48,21 +48,19 @@ #define CLUSTER_CTRC_WIRE_VERSION UINT16_C(2) #define CLUSTER_CTRC_SELECTOR_VERSION UINT8_C(1) #define CLUSTER_CTRC_FORWARD_KIND UINT8_C(11) -#define CLUSTER_CTRC_INTERNAL_ENDPOINT ((int32)-2) +#define CLUSTER_CTRC_INTERNAL_ENDPOINT ((int32) - 2) #define CLUSTER_CTRC_MAX_PARTICIPANTS CLUSTER_SF_DEP_MAX_ORIGINS #define CLUSTER_CTRC_PAGE_LSN_ORIGIN_INVALID UINT16_MAX #define CTRC_ACK_FLAG_ZERO_RANGE UINT16_C(0x0001) #define CTRC_ACK_FLAG_ALL_DURABLE UINT16_C(0x0002) -typedef enum ClusterCtrcSealSuboperation -{ +typedef enum ClusterCtrcSealSuboperation { CTRC_SEAL_CLOSE_AND_CLEAN = 1, CTRC_SEAL_CERTIFICATE_COMMITTED = 2 } ClusterCtrcSealSuboperation; -typedef enum ClusterCtrcSealReplyResult -{ +typedef enum ClusterCtrcSealReplyResult { CTRC_SEAL_REPLY_DENIED = 0, CTRC_SEAL_REPLY_LOCAL_RELEASE_ACK = 1, CTRC_SEAL_REPLY_PENDING_DRAIN = 2, @@ -70,8 +68,7 @@ typedef enum ClusterCtrcSealReplyResult CTRC_SEAL_REPLY_CERTIFICATE_RECLAIMED = 4 } ClusterCtrcSealReplyResult; -typedef enum ClusterCtrcSealReason -{ +typedef enum ClusterCtrcSealReason { CTRC_SEAL_REASON_MALFORMED = 1, CTRC_SEAL_REASON_IDENTITY = 2, CTRC_SEAL_REASON_PREPARED = 3, @@ -114,8 +111,7 @@ typedef enum ClusterCtrcStatId { CTRC_STAT_COUNT } ClusterCtrcStatId; -typedef enum ClusterCtrcCleanerReason -{ +typedef enum ClusterCtrcCleanerReason { CTRC_CLEANER_REASON_NONE = 0, CTRC_CLEANER_REASON_PREPARED_DRAIN, CTRC_CLEANER_REASON_RESOURCE_X, @@ -142,8 +138,7 @@ typedef struct ClusterCtrcCleanerWorkerObservation { /* A single shared scheduling seam. The phase value selects a safe point; * the seam never changes proof, receipt, ACK, certificate or verdict bytes. */ -typedef enum ClusterCtrcTestBarrierPhase -{ +typedef enum ClusterCtrcTestBarrierPhase { CTRC_TEST_BARRIER_NONE = 0, CTRC_TEST_BARRIER_ACTIVE_PROOF_READY = 1, CTRC_TEST_BARRIER_ACK_DURABLE = 2, @@ -152,8 +147,7 @@ typedef enum ClusterCtrcTestBarrierPhase CTRC_TEST_BARRIER_COUNT } ClusterCtrcTestBarrierPhase; -typedef enum ClusterCtrcReferenceKind -{ +typedef enum ClusterCtrcReferenceKind { CTRC_REF_HEAP_ITL_UBA = 1, CTRC_REF_CURRENT_MX_LOCKER = 2, CTRC_REF_CURRENT_MX_UPDATER = 3, @@ -161,16 +155,14 @@ typedef enum ClusterCtrcReferenceKind CTRC_REF_HOT_FOLLOW_EDGE = 5 } ClusterCtrcReferenceKind; -typedef enum ClusterCtrcTargetKind -{ +typedef enum ClusterCtrcTargetKind { CTRC_TARGET_EXACT_ITL_SLOT = 1, CTRC_TARGET_EXACT_TID = 2, CTRC_TARGET_PAGE_PENDING_ITL_SLOT = 3, CTRC_TARGET_PAGE_PENDING_OFFNUM = 4 } ClusterCtrcTargetKind; -typedef enum ClusterCtrcProofClass -{ +typedef enum ClusterCtrcProofClass { CTRC_PROOF_UNKNOWN = 0, CTRC_PROOF_SELF = 1, CTRC_PROOF_ACTIVE = 2, @@ -178,8 +170,7 @@ typedef enum ClusterCtrcProofClass CTRC_PROOF_ABORTED = 4 } ClusterCtrcProofClass; -typedef enum ClusterCtrcReceiptState -{ +typedef enum ClusterCtrcReceiptState { CTRC_RECEIPT_FREE = 0, CTRC_RECEIPT_PREPARED, CTRC_RECEIPT_APPLIED, @@ -195,15 +186,13 @@ typedef enum ClusterCtrcReceiptState /* Parallel open-addressing metadata for the bounded receipt array. This is * volatile shared-memory state, not wire, WAL, or persistent ABI. */ -typedef enum ClusterCtrcReceiptProbeState -{ +typedef enum ClusterCtrcReceiptProbeState { CTRC_RECEIPT_PROBE_EMPTY = 0, CTRC_RECEIPT_PROBE_OCCUPIED, CTRC_RECEIPT_PROBE_TOMBSTONE } ClusterCtrcReceiptProbeState; -typedef enum ClusterCtrcReleaseDisposition -{ +typedef enum ClusterCtrcReleaseDisposition { CTRC_RELEASE_NONE = 0, CTRC_RELEASE_CANCELLED_PREMUTATION = 1, CTRC_RELEASE_CLEANED_ABSENT = 2, @@ -211,8 +200,7 @@ typedef enum ClusterCtrcReleaseDisposition CTRC_RELEASE_CLEANED_SUCCESSOR_REPLACED = 4 } ClusterCtrcReleaseDisposition; -typedef enum ClusterCtrcParticipantState -{ +typedef enum ClusterCtrcParticipantState { CTRC_PARTICIPANT_EMPTY = 0, CTRC_PARTICIPANT_OPEN, CTRC_PARTICIPANT_CLOSED_DRAINING, @@ -221,8 +209,7 @@ typedef enum ClusterCtrcParticipantState CTRC_PARTICIPANT_BLOCKED } ClusterCtrcParticipantState; -typedef enum ClusterCtrcOriginState -{ +typedef enum ClusterCtrcOriginState { CTRC_ORIGIN_EMPTY = 0, CTRC_ORIGIN_OPEN, CTRC_ORIGIN_SEALING, @@ -233,8 +220,7 @@ typedef enum ClusterCtrcOriginState CTRC_ORIGIN_BLOCKED } ClusterCtrcOriginState; -typedef struct ClusterCtrcTxnKeyV1 -{ +typedef struct ClusterCtrcTxnKeyV1 { uint8 format_version; uint8 owner_instance; uint16 origin_node_id; @@ -254,8 +240,7 @@ typedef struct ClusterCtrcTxnKeyV1 uint8 reserved[16]; } ClusterCtrcTxnKeyV1; -typedef struct ClusterCtrcPublicationIdV1 -{ +typedef struct ClusterCtrcPublicationIdV1 { uint16 requester_node_id; uint64 requester_boot_incarnation; uint32 capability_record_generation; @@ -275,8 +260,7 @@ typedef struct ClusterCtrcPublicationIdV1 uint32 grant_generation; } ClusterCtrcPublicationIdV1; -typedef struct ClusterCtrcTargetV1 -{ +typedef struct ClusterCtrcTargetV1 { uint8 kind; uint8 relation_persistence; uint8 needs_wal; @@ -314,8 +298,7 @@ typedef struct ClusterCtrcTargetV1 uint64 intended_descriptor_hash; } ClusterCtrcTargetV1; -typedef enum ClusterCtrcPageVersionOrder -{ +typedef enum ClusterCtrcPageVersionOrder { CTRC_PAGE_VERSION_CURRENT = 0, CTRC_PAGE_VERSION_REGRESSED, CTRC_PAGE_VERSION_UNKNOWN @@ -326,13 +309,12 @@ typedef enum ClusterCtrcPageVersionOrder extern bool cluster_ctrc_pending_itl_target_recheck(const ClusterCtrcTargetV1 *stored, const ClusterCtrcTargetV1 *observed); -extern ClusterCtrcPageVersionOrder cluster_ctrc_page_version_order( - uint16 predecessor_origin, XLogRecPtr predecessor_lsn, - SCN predecessor_scn, uint16 current_origin, XLogRecPtr current_lsn, - SCN current_scn); +extern ClusterCtrcPageVersionOrder +cluster_ctrc_page_version_order(uint16 predecessor_origin, XLogRecPtr predecessor_lsn, + SCN predecessor_scn, uint16 current_origin, XLogRecPtr current_lsn, + SCN current_scn); -typedef struct ClusterCtrcParticipantIdentity -{ +typedef struct ClusterCtrcParticipantIdentity { uint16 node_id; uint16 reserved16; uint32 capability_record_generation; @@ -344,8 +326,7 @@ typedef struct ClusterCtrcParticipantIdentity /* Stack-only close work item owned by the existing undo cleaner. It is not * shared-memory or wire ABI; the 136-byte encoder remains the sole wire * representation. */ -typedef struct ClusterCtrcCloseDispatch -{ +typedef struct ClusterCtrcCloseDispatch { ClusterCtrcTxnKeyV1 key; ClusterCtrcParticipantIdentity participant; uint64 request_id; @@ -356,8 +337,7 @@ typedef struct ClusterCtrcCloseDispatch uint32 reserved32; } ClusterCtrcCloseDispatch; -typedef struct ClusterCtrcOriginEntry -{ +typedef struct ClusterCtrcOriginEntry { ClusterCtrcTxnKeyV1 key; uint64 reservation_generation; uint32 grant_generation; @@ -373,16 +353,14 @@ typedef struct ClusterCtrcOriginEntry uint64 close_request_id[CLUSTER_CTRC_MAX_PARTICIPANTS]; } ClusterCtrcOriginEntry; -typedef enum ClusterCtrcOriginReservationKind -{ +typedef enum ClusterCtrcOriginReservationKind { CTRC_ORIGIN_RESERVATION_INVALID = 0, CTRC_ORIGIN_RESERVATION_PENDING_OWNED = 1, CTRC_ORIGIN_RESERVATION_EXISTING_OPEN = 2 } ClusterCtrcOriginReservationKind; /* Stack-only handle for the EMPTY-reserved -> OPEN origin transition. */ -typedef struct ClusterCtrcOriginReservation -{ +typedef struct ClusterCtrcOriginReservation { ClusterCtrcTxnKeyV1 key; uint64 origin_index; uint64 reservation_generation; @@ -391,8 +369,7 @@ typedef struct ClusterCtrcOriginReservation uint8 reserved8[6]; } ClusterCtrcOriginReservation; -typedef struct ClusterCtrcParticipantEntry -{ +typedef struct ClusterCtrcParticipantEntry { ClusterCtrcTxnKeyV1 key; ClusterCtrcParticipantIdentity identity; uint32 grant_generation; @@ -409,8 +386,7 @@ typedef struct ClusterCtrcParticipantEntry uint64 ack_frozen_count; } ClusterCtrcParticipantEntry; -typedef struct ClusterCtrcReceipt -{ +typedef struct ClusterCtrcReceipt { ClusterCtrcTxnKeyV1 key; ClusterCtrcPublicationIdV1 publication; ClusterCtrcTargetV1 target; @@ -421,8 +397,7 @@ typedef struct ClusterCtrcReceipt XLogRecPtr required_lsn[CLUSTER_SF_DEP_MAX_ORIGINS]; } ClusterCtrcReceipt; -typedef struct ClusterCtrcApplyToken -{ +typedef struct ClusterCtrcApplyToken { bool valid; uint8 reserved8[7]; uint64 journal_sequence; @@ -432,8 +407,7 @@ typedef struct ClusterCtrcApplyToken /* Backend-local ownership handle for one bounded shared receipt slot. This * is not a second receipt, wire object, shared ABI or transaction authority. */ -typedef struct ClusterCtrcReceiptHandle -{ +typedef struct ClusterCtrcReceiptHandle { ClusterCtrcParticipantEntry *participant; ClusterCtrcReceipt *receipt; ClusterCtrcTxnKeyV1 key; @@ -444,8 +418,7 @@ typedef struct ClusterCtrcReceiptHandle uint8 reserved8[7]; } ClusterCtrcReceiptHandle; -typedef struct ClusterCtrcDurability -{ +typedef struct ClusterCtrcDurability { XLogRecPtr highest_local_lsn; XLogRecPtr local_flush_lsn; XLogRecPtr required_lsn[CLUSTER_SF_DEP_MAX_ORIGINS]; @@ -457,8 +430,7 @@ typedef struct ClusterCtrcDurability * wire nor shared-memory ABI: the shared wrapper compares every field while * holding the receipt-table locks, so a stale/recycled handle cannot clean a * different ITL reference. */ -typedef struct ClusterCtrcItlTargetIdentity -{ +typedef struct ClusterCtrcItlTargetIdentity { uint32 spc_oid; uint32 db_oid; uint32 rel_number; @@ -473,8 +445,7 @@ typedef struct ClusterCtrcItlTargetIdentity uint8 uba[16]; } ClusterCtrcItlTargetIdentity; -typedef struct ClusterCtrcLocalReleaseAckV1 -{ +typedef struct ClusterCtrcLocalReleaseAckV1 { ClusterCtrcTxnKeyV1 transaction_key; uint32 grant_generation; uint8 result; @@ -504,8 +475,7 @@ typedef struct ClusterCtrcLocalReleaseAckV1 uint32 crc32c; } ClusterCtrcLocalReleaseAckV1; -typedef struct ClusterCtrcSealRequestV1 -{ +typedef struct ClusterCtrcSealRequestV1 { uint64 request_id; uint64 cluster_epoch; uint8 tt_status_key_0_19[20]; @@ -534,8 +504,7 @@ typedef struct ClusterCtrcSealRequestV1 uint32 reserved_tail; } ClusterCtrcSealRequestV1; -typedef struct ClusterCtrcSealReplyHeaderV1 -{ +typedef struct ClusterCtrcSealReplyHeaderV1 { uint32 magic; uint16 wire_version; uint16 header_length; @@ -554,86 +523,72 @@ typedef struct ClusterCtrcSealReplyHeaderV1 uint32 header_crc32c; } ClusterCtrcSealReplyHeaderV1; -typedef enum ClusterCtrcOriginOpenResult -{ +typedef enum ClusterCtrcOriginOpenResult { CLUSTER_CTRC_ORIGIN_REFUSED = 0, CLUSTER_CTRC_ORIGIN_OPENED = 1, CLUSTER_CTRC_ORIGIN_DUPLICATE = 2 } ClusterCtrcOriginOpenResult; -typedef enum ClusterCtrcOriginReserveResult -{ +typedef enum ClusterCtrcOriginReserveResult { CLUSTER_CTRC_ORIGIN_RESERVE_REFUSED = 0, CLUSTER_CTRC_ORIGIN_RESERVED_PENDING = 1, CLUSTER_CTRC_ORIGIN_RESERVED_EXISTING_OPEN = 2, CLUSTER_CTRC_ORIGIN_RESERVE_RETRY_RELEASED = 3 } ClusterCtrcOriginReserveResult; -typedef enum ClusterCtrcTouchResult -{ +typedef enum ClusterCtrcTouchResult { CLUSTER_CTRC_TOUCH_REFUSED = 0, CLUSTER_CTRC_TOUCH_RECORDED = 1, CLUSTER_CTRC_TOUCH_DUPLICATE = 2, CLUSTER_CTRC_TOUCH_TERMINAL_NO_GRANT = 3 } ClusterCtrcTouchResult; -typedef enum ClusterCtrcParticipantOpenResult -{ +typedef enum ClusterCtrcParticipantOpenResult { CLUSTER_CTRC_PARTICIPANT_REFUSED = 0, CLUSTER_CTRC_PARTICIPANT_OPENED = 1, CLUSTER_CTRC_PARTICIPANT_DUPLICATE = 2 } ClusterCtrcParticipantOpenResult; -typedef enum ClusterCtrcPrepareResult -{ +typedef enum ClusterCtrcPrepareResult { CLUSTER_CTRC_PREPARE_REFUSED = 0, CLUSTER_CTRC_PREPARE_READY = 1, CLUSTER_CTRC_PREPARE_DUPLICATE = 2, CLUSTER_CTRC_PREPARE_CAPACITY = 3 } ClusterCtrcPrepareResult; -typedef enum ClusterCtrcApplyResult -{ +typedef enum ClusterCtrcApplyResult { CLUSTER_CTRC_APPLY_FAIL_CLOSED = 0, CLUSTER_CTRC_APPLY_APPLIED = 1, CLUSTER_CTRC_APPLY_RETRY_REQUIRED = 2 } ClusterCtrcApplyResult; -typedef enum ClusterCtrcItlProjection -{ +typedef enum ClusterCtrcItlProjection { CTRC_ITL_NEEDS_CLEANOUT = 0, CTRC_ITL_HINT_SKIPPED, CTRC_ITL_TERMINAL_INDEPENDENT, CTRC_ITL_TARGET_ABSENT } ClusterCtrcItlProjection; -typedef enum ClusterCtrcDischargeResult -{ +typedef enum ClusterCtrcDischargeResult { CLUSTER_CTRC_DISCHARGE_RETAIN = 0, CLUSTER_CTRC_DISCHARGE_CLEANED = 1 } ClusterCtrcDischargeResult; -typedef enum ClusterCtrcItlCleanoutApplyResult -{ +typedef enum ClusterCtrcItlCleanoutApplyResult { CLUSTER_CTRC_ITL_CLEANOUT_RETAIN = 0, CLUSTER_CTRC_ITL_CLEANOUT_ALREADY_TERMINAL = 1, CLUSTER_CTRC_ITL_CLEANOUT_REWRITTEN = 2 } ClusterCtrcItlCleanoutApplyResult; -typedef enum ClusterCtrcCloseResult -{ +typedef enum ClusterCtrcCloseResult { CLUSTER_CTRC_CLOSE_BLOCKED_RETAIN = 0, CLUSTER_CTRC_CLOSE_PENDING_DRAIN = 1, CLUSTER_CTRC_CLOSE_ACK_READY = 2 } ClusterCtrcCloseResult; -typedef enum ClusterCtrcLossResult -{ - CLUSTER_CTRC_LOSS_BLOCKED = 0 -} ClusterCtrcLossResult; +typedef enum ClusterCtrcLossResult { CLUSTER_CTRC_LOSS_BLOCKED = 0 } ClusterCtrcLossResult; -typedef enum ClusterCtrcTargetState -{ +typedef enum ClusterCtrcTargetState { CTRC_TARGET_ABSENT = 0, CTRC_TARGET_AMBIGUOUS, CTRC_TARGET_TERMINAL_LOCK_ONLY, @@ -642,8 +597,7 @@ typedef enum ClusterCtrcTargetState CTRC_TARGET_ACTIVE_SURVIVOR } ClusterCtrcTargetState; -typedef struct ClusterCtrcCleanReferenceInput -{ +typedef struct ClusterCtrcCleanReferenceInput { uint8 target_state; bool source_transition_censused; bool page_authority_exact; @@ -652,16 +606,14 @@ typedef struct ClusterCtrcCleanReferenceInput uint16 unknown_companions; } ClusterCtrcCleanReferenceInput; -typedef enum ClusterCtrcCleanResult -{ +typedef enum ClusterCtrcCleanResult { CTRC_CLEAN_RETAIN = 0, CTRC_CLEANED_ABSENT = 1, CTRC_CLEANED_TERMINAL_REWRITE = 2, CTRC_CLEANED_SUCCESSOR_REPLACED = 3 } ClusterCtrcCleanResult; -typedef enum ClusterCtrcCurrentMxRewriteKind -{ +typedef enum ClusterCtrcCurrentMxRewriteKind { CTRC_CURRENT_MX_REWRITE_RETAIN = 0, CTRC_CURRENT_MX_REWRITE_INVALIDATE, CTRC_CURRENT_MX_REWRITE_COMMITTED_UPDATER, @@ -670,8 +622,7 @@ typedef enum ClusterCtrcCurrentMxRewriteKind /* Pure descriptor-level plan. It contains no shared-memory pointer and is * produced before allocating a successor descriptor or touching a page. */ -typedef struct ClusterCtrcCurrentMxRewritePlan -{ +typedef struct ClusterCtrcCurrentMxRewritePlan { uint8 kind; uint8 clean_result; uint16 survivor_count; @@ -680,31 +631,27 @@ typedef struct ClusterCtrcCurrentMxRewritePlan MultiXactMember survivors[CLUSTER_CURRENT_MX_MAX_MEMBERS]; } ClusterCtrcCurrentMxRewritePlan; -typedef struct ClusterCtrcTransferState -{ +typedef struct ClusterCtrcTransferState { uint16 active_survivor_count; uint16 successor_receipt_count; bool descriptor_durable; bool predecessor_removed; } ClusterCtrcTransferState; -typedef enum ClusterCtrcTransferResult -{ +typedef enum ClusterCtrcTransferResult { CLUSTER_CTRC_TRANSFER_REFUSED = 0, CLUSTER_CTRC_TRANSFER_PENDING_DESCRIPTOR = 1, CLUSTER_CTRC_TRANSFER_READY = 2, CLUSTER_CTRC_TRANSFER_REMOVED = 3 } ClusterCtrcTransferResult; -typedef enum ClusterCtrcAckResult -{ +typedef enum ClusterCtrcAckResult { CLUSTER_CTRC_ACK_DENIED = 0, CLUSTER_CTRC_ACK_RELEASED = 1, CTRC_ACK_RELEASED = CLUSTER_CTRC_ACK_RELEASED } ClusterCtrcAckResult; -typedef struct ClusterCtrcCertificateInput -{ +typedef struct ClusterCtrcCertificateInput { const ClusterCtrcLocalReleaseAckV1 *acks; uint16 ack_count; uint16 reserved16; @@ -716,8 +663,7 @@ typedef struct ClusterCtrcCertificateInput /* Stack-only immutable copy used across the no-CTRC-lock block-0 certificate * phase. It is neither shared-memory nor wire ABI. */ -typedef struct ClusterCtrcOriginCertificateSnapshot -{ +typedef struct ClusterCtrcOriginCertificateSnapshot { uint64 origin_index; ClusterCtrcOriginEntry origin; ClusterCtrcLocalReleaseAckV1 acks[CLUSTER_CTRC_MAX_PARTICIPANTS]; @@ -725,21 +671,18 @@ typedef struct ClusterCtrcOriginCertificateSnapshot uint8 reserved[6]; } ClusterCtrcOriginCertificateSnapshot; -typedef enum ClusterCtrcCertificateResult -{ +typedef enum ClusterCtrcCertificateResult { CLUSTER_CTRC_CERTIFICATE_RETAIN = 0, CLUSTER_CTRC_CERTIFICATE_READY = 1 } ClusterCtrcCertificateResult; -typedef enum ClusterCtrcTerminalStatus -{ +typedef enum ClusterCtrcTerminalStatus { CTRC_TERMINAL_UNKNOWN = 0, CTRC_TERMINAL_COMMITTED = 1, CTRC_TERMINAL_ABORTED = 2 } ClusterCtrcTerminalStatus; -typedef struct ClusterCtrcRecycleInput -{ +typedef struct ClusterCtrcRecycleInput { uint8 status; bool release_proven; bool durable_aborted; @@ -748,8 +691,7 @@ typedef struct ClusterCtrcRecycleInput uint64 horizon_scn; } ClusterCtrcRecycleInput; -typedef enum ClusterCtrcCrashCut -{ +typedef enum ClusterCtrcCrashCut { CTRC_CRASH_BEFORE_TOUCH = 1, CTRC_CRASH_AFTER_TOUCH_BEFORE_PROOF, CTRC_CRASH_PREPARED_BEFORE_APPLIED, @@ -761,14 +703,12 @@ typedef enum ClusterCtrcCrashCut CTRC_CRASH_ORIGIN_PRECERT_LOSS } ClusterCtrcCrashCut; -typedef enum ClusterCtrcCrashDisposition -{ +typedef enum ClusterCtrcCrashDisposition { CLUSTER_CTRC_CRASH_RETAIN = 0, CLUSTER_CTRC_CRASH_RELEASE_PROVEN = 1 } ClusterCtrcCrashDisposition; -typedef struct ClusterCtrcCapacity -{ +typedef struct ClusterCtrcCapacity { uint64 origin_key_entries; uint64 participant_key_entries; uint64 receipt_entries; @@ -777,8 +717,7 @@ typedef struct ClusterCtrcCapacity Size total_bytes; } ClusterCtrcCapacity; -typedef struct ClusterCtrcDebugSnapshot -{ +typedef struct ClusterCtrcDebugSnapshot { uint64 origin_open; uint64 origin_sealing; uint64 origin_release_proven; @@ -800,8 +739,7 @@ typedef struct ClusterCtrcDebugSnapshot uint32 cleaner_reason; } ClusterCtrcDebugSnapshot; -typedef enum ClusterCtrcCapacityDisposition -{ +typedef enum ClusterCtrcCapacityDisposition { CLUSTER_CTRC_CAPACITY_REFUSE_BEFORE_MUTATION = 0 } ClusterCtrcCapacityDisposition; @@ -819,43 +757,39 @@ StaticAssertDecl(offsetof(ClusterCtrcLocalReleaseAckV1, crc32c) == 412, "CTRC ACK CRC offset must remain 412"); extern const uint8 cluster_ctrc_empty_sha256[32]; -extern bool cluster_ctrc_sha256_exact(const void *bytes, Size length, - uint8 digest[32]); -extern bool cluster_ctrc_seal_request_encode( - const ClusterCtrcTxnKeyV1 *key, uint64 request_id, - uint32 grant_generation, uint64 seal_generation, - uint32 participant_capability_record_generation, - ClusterCtrcSealSuboperation suboperation, - uint8 *bytes, Size length); -extern bool cluster_ctrc_seal_request_decode( - const uint8 *bytes, Size length, uint64 authenticated_system_identifier, - int32 envelope_source_node, int32 local_node, uint64 current_epoch, - ClusterCtrcSealRequestV1 *request_out, ClusterCtrcTxnKeyV1 *key_out); -extern bool cluster_ctrc_local_release_ack_encode( - const ClusterCtrcLocalReleaseAckV1 *ack, - uint8 bytes[CLUSTER_CTRC_LOCAL_ACK_BYTES]); -extern bool cluster_ctrc_local_release_ack_decode( - const uint8 bytes[CLUSTER_CTRC_LOCAL_ACK_BYTES], - ClusterCtrcLocalReleaseAckV1 *ack_out); -extern bool cluster_ctrc_seal_reply_encode( - const uint8 *request_bytes, Size request_length, - int32 source_node, int32 destination_node, - ClusterCtrcSealReplyResult result, uint16 first_reason, - const ClusterCtrcLocalReleaseAckV1 *ack, - uint8 *page, Size page_length); -extern bool cluster_ctrc_seal_reply_decode( - const uint8 *page, Size page_length, - const uint8 *request_bytes, Size request_length, - int32 expected_source_node, int32 expected_destination_node, - ClusterCtrcSealReplyHeaderV1 *header_out, - ClusterCtrcLocalReleaseAckV1 *ack_out); - -extern bool cluster_ctrc_capacity_compute(Size n_buffers, int max_backends, - int declared_nodes, +extern bool cluster_ctrc_sha256_exact(const void *bytes, Size length, uint8 digest[32]); +extern bool cluster_ctrc_seal_request_encode(const ClusterCtrcTxnKeyV1 *key, uint64 request_id, + uint32 grant_generation, uint64 seal_generation, + uint32 participant_capability_record_generation, + ClusterCtrcSealSuboperation suboperation, uint8 *bytes, + Size length); +extern bool cluster_ctrc_seal_request_decode(const uint8 *bytes, Size length, + uint64 authenticated_system_identifier, + int32 envelope_source_node, int32 local_node, + uint64 current_epoch, + ClusterCtrcSealRequestV1 *request_out, + ClusterCtrcTxnKeyV1 *key_out); +extern bool cluster_ctrc_local_release_ack_encode(const ClusterCtrcLocalReleaseAckV1 *ack, + uint8 bytes[CLUSTER_CTRC_LOCAL_ACK_BYTES]); +extern bool cluster_ctrc_local_release_ack_decode(const uint8 bytes[CLUSTER_CTRC_LOCAL_ACK_BYTES], + ClusterCtrcLocalReleaseAckV1 *ack_out); +extern bool cluster_ctrc_seal_reply_encode(const uint8 *request_bytes, Size request_length, + int32 source_node, int32 destination_node, + ClusterCtrcSealReplyResult result, uint16 first_reason, + const ClusterCtrcLocalReleaseAckV1 *ack, uint8 *page, + Size page_length); +extern bool cluster_ctrc_seal_reply_decode(const uint8 *page, Size page_length, + const uint8 *request_bytes, Size request_length, + int32 expected_source_node, + int32 expected_destination_node, + ClusterCtrcSealReplyHeaderV1 *header_out, + ClusterCtrcLocalReleaseAckV1 *ack_out); + +extern bool cluster_ctrc_capacity_compute(Size n_buffers, int max_backends, int declared_nodes, ClusterCtrcCapacity *capacity); -extern bool cluster_ctrc_participant_index_compute( - uint64 origin_index, uint64 origin_entries, uint64 participant_entries, - uint16 participant_node_id, uint64 *index_out); +extern bool cluster_ctrc_participant_index_compute(uint64 origin_index, uint64 origin_entries, + uint64 participant_entries, + uint16 participant_node_id, uint64 *index_out); extern ClusterCtrcCapacityDisposition cluster_ctrc_runtime_full_disposition(void); extern Size cluster_ctrc_shmem_size(void); extern void cluster_ctrc_shmem_init(void); @@ -864,8 +798,7 @@ extern bool cluster_ctrc_shmem_ready(void); extern const char *cluster_ctrc_stat_name(ClusterCtrcStatId stat); extern uint64 cluster_ctrc_stat_get(ClusterCtrcStatId stat); extern void cluster_ctrc_stat_bump(ClusterCtrcStatId stat); -extern const char *cluster_ctrc_cleaner_reason_name( - ClusterCtrcCleanerReason reason); +extern const char *cluster_ctrc_cleaner_reason_name(ClusterCtrcCleanerReason reason); extern ClusterCtrcCleanerReason cluster_ctrc_cleaner_reason_get(void); extern void cluster_ctrc_cleaner_reason_set(ClusterCtrcCleanerReason reason); extern bool cluster_ctrc_cleaner_bind_worker(unsigned worker_id); @@ -875,103 +808,91 @@ extern ClusterCtrcCleanerReason cluster_ctrc_cleaner_worker_reason(unsigned work extern bool cluster_ctrc_cleaner_worker_observation(unsigned worker_id, ClusterCtrcCleanerWorkerObservation *out); extern bool cluster_ctrc_debug_snapshot(ClusterCtrcDebugSnapshot *snapshot); -extern bool cluster_ctrc_test_barrier_control( - ClusterCtrcTestBarrierPhase phase, bool armed); +extern bool cluster_ctrc_test_barrier_control(ClusterCtrcTestBarrierPhase phase, bool armed); extern void cluster_ctrc_test_barrier_wait(ClusterCtrcTestBarrierPhase phase); -extern void cluster_ctrc_note_publication_after_apply( - const ClusterCtrcReceiptHandle *handle, bool current_mx); +extern void cluster_ctrc_note_publication_after_apply(const ClusterCtrcReceiptHandle *handle, + bool current_mx); extern bool cluster_ctrc_origin_grant_publishable_entry( const ClusterCtrcOriginEntry *origin, const ClusterCtrcTxnKeyV1 *key, - const ClusterCtrcParticipantIdentity *participant, - uint32 grant_generation); -extern bool cluster_ctrc_origin_grant_publishable( - const ClusterCtrcTxnKeyV1 *key, - const ClusterCtrcParticipantIdentity *participant, - uint32 grant_generation); - -extern ClusterCtrcOriginReserveResult cluster_ctrc_origin_reserve_active( - const ClusterCtrcTxnKeyV1 *key, - ClusterCtrcOriginReservation *reservation); -extern bool cluster_ctrc_origin_release_overlap_pending( - const ClusterCtrcTxnKeyV1 *key); -extern ClusterCtrcOriginReserveResult cluster_ctrc_origin_reserve_entry( - ClusterCtrcOriginEntry *origin, const ClusterCtrcTxnKeyV1 *key, - uint64 origin_index, uint64 reservation_generation, - ClusterCtrcOriginReservation *reservation); -extern bool cluster_ctrc_origin_cancel_pre_bind_entry( - ClusterCtrcOriginEntry *origin, uint64 origin_index, - const ClusterCtrcOriginReservation *reservation); -extern bool cluster_ctrc_origin_block_post_bind_entry( - ClusterCtrcOriginEntry *origin, uint64 origin_index, - const ClusterCtrcOriginReservation *reservation); -extern bool cluster_ctrc_origin_cancel_pre_bind( - const ClusterCtrcOriginReservation *reservation); -extern bool cluster_ctrc_origin_block_post_bind( - const ClusterCtrcOriginReservation *reservation); -extern bool cluster_ctrc_origin_open_reserved( - const ClusterCtrcOriginReservation *reservation, - uint32 *grant_generation); -extern ClusterCtrcTouchResult cluster_ctrc_origin_touch_exact( - const ClusterCtrcTxnKeyV1 *key, - const ClusterCtrcParticipantIdentity *participant, - ClusterCtrcProofClass proof_class, uint32 *grant_out); - -extern ClusterCtrcOriginOpenResult cluster_ctrc_origin_open_active( - ClusterCtrcOriginEntry *origin, const ClusterCtrcTxnKeyV1 *key, - uint32 grant_generation); -extern ClusterCtrcTouchResult cluster_ctrc_origin_record_touched( - ClusterCtrcOriginEntry *origin, - const ClusterCtrcParticipantIdentity *participant, - ClusterCtrcProofClass proof_class, uint32 *grant_out); -extern bool cluster_ctrc_origin_has_exact_touch( - const ClusterCtrcOriginEntry *origin, - const ClusterCtrcParticipantIdentity *participant); -extern bool cluster_ctrc_origin_begin_seal_entry( - ClusterCtrcOriginEntry *origin, uint64 seal_generation); -extern bool cluster_ctrc_origin_arm_close_entry( - ClusterCtrcOriginEntry *origin, uint16 participant_node_id, - uint64 request_id); -extern bool cluster_ctrc_origin_note_close_reply_entry( - ClusterCtrcOriginEntry *origin, uint16 participant_node_id, - uint64 request_id, ClusterCtrcSealReplyResult result); -extern bool cluster_ctrc_origin_arm_certificate_entry( - ClusterCtrcOriginEntry *origin, uint16 participant_node_id, - uint64 request_id); -extern bool cluster_ctrc_origin_note_certificate_reply_entry( - ClusterCtrcOriginEntry *origin, uint16 participant_node_id, - uint64 request_id, ClusterCtrcSealReplyResult result); -extern bool cluster_ctrc_origin_begin_cleaning_entry( - ClusterCtrcOriginEntry *origin); + const ClusterCtrcParticipantIdentity *participant, uint32 grant_generation); +extern bool cluster_ctrc_origin_grant_publishable(const ClusterCtrcTxnKeyV1 *key, + const ClusterCtrcParticipantIdentity *participant, + uint32 grant_generation); + +extern ClusterCtrcOriginReserveResult +cluster_ctrc_origin_reserve_active(const ClusterCtrcTxnKeyV1 *key, + ClusterCtrcOriginReservation *reservation); +extern bool cluster_ctrc_origin_release_overlap_pending(const ClusterCtrcTxnKeyV1 *key); +extern ClusterCtrcOriginReserveResult +cluster_ctrc_origin_reserve_entry(ClusterCtrcOriginEntry *origin, const ClusterCtrcTxnKeyV1 *key, + uint64 origin_index, uint64 reservation_generation, + ClusterCtrcOriginReservation *reservation); +extern bool +cluster_ctrc_origin_cancel_pre_bind_entry(ClusterCtrcOriginEntry *origin, uint64 origin_index, + const ClusterCtrcOriginReservation *reservation); +extern bool +cluster_ctrc_origin_block_post_bind_entry(ClusterCtrcOriginEntry *origin, uint64 origin_index, + const ClusterCtrcOriginReservation *reservation); +extern bool cluster_ctrc_origin_cancel_pre_bind(const ClusterCtrcOriginReservation *reservation); +extern bool cluster_ctrc_origin_block_post_bind(const ClusterCtrcOriginReservation *reservation); +extern bool cluster_ctrc_origin_open_reserved(const ClusterCtrcOriginReservation *reservation, + uint32 *grant_generation); +extern ClusterCtrcTouchResult +cluster_ctrc_origin_touch_exact(const ClusterCtrcTxnKeyV1 *key, + const ClusterCtrcParticipantIdentity *participant, + ClusterCtrcProofClass proof_class, uint32 *grant_out); + +extern ClusterCtrcOriginOpenResult cluster_ctrc_origin_open_active(ClusterCtrcOriginEntry *origin, + const ClusterCtrcTxnKeyV1 *key, + uint32 grant_generation); +extern ClusterCtrcTouchResult +cluster_ctrc_origin_record_touched(ClusterCtrcOriginEntry *origin, + const ClusterCtrcParticipantIdentity *participant, + ClusterCtrcProofClass proof_class, uint32 *grant_out); +extern bool cluster_ctrc_origin_has_exact_touch(const ClusterCtrcOriginEntry *origin, + const ClusterCtrcParticipantIdentity *participant); +extern bool cluster_ctrc_origin_begin_seal_entry(ClusterCtrcOriginEntry *origin, + uint64 seal_generation); +extern bool cluster_ctrc_origin_arm_close_entry(ClusterCtrcOriginEntry *origin, + uint16 participant_node_id, uint64 request_id); +extern bool cluster_ctrc_origin_note_close_reply_entry(ClusterCtrcOriginEntry *origin, + uint16 participant_node_id, + uint64 request_id, + ClusterCtrcSealReplyResult result); +extern bool cluster_ctrc_origin_arm_certificate_entry(ClusterCtrcOriginEntry *origin, + uint16 participant_node_id, + uint64 request_id); +extern bool cluster_ctrc_origin_note_certificate_reply_entry(ClusterCtrcOriginEntry *origin, + uint16 participant_node_id, + uint64 request_id, + ClusterCtrcSealReplyResult result); +extern bool cluster_ctrc_origin_begin_cleaning_entry(ClusterCtrcOriginEntry *origin); extern bool cluster_ctrc_origin_request_snapshot_shared( - uint64 request_id, uint16 participant_node_id, - ClusterCtrcTxnKeyV1 *key_out, - ClusterCtrcParticipantIdentity *identity_out, - uint32 *grant_generation_out, uint64 *seal_generation_out, - ClusterCtrcSealSuboperation *suboperation_out); + uint64 request_id, uint16 participant_node_id, ClusterCtrcTxnKeyV1 *key_out, + ClusterCtrcParticipantIdentity *identity_out, uint32 *grant_generation_out, + uint64 *seal_generation_out, ClusterCtrcSealSuboperation *suboperation_out); extern bool cluster_ctrc_origin_close_request_snapshot_shared( - uint64 request_id, uint16 participant_node_id, - ClusterCtrcTxnKeyV1 *key_out, - ClusterCtrcParticipantIdentity *identity_out, - uint32 *grant_generation_out, uint64 *seal_generation_out); -extern bool cluster_ctrc_origin_note_close_reply_shared( - uint64 request_id, uint16 participant_node_id, - ClusterCtrcSealReplyResult result); -extern bool cluster_ctrc_origin_note_certificate_reply_shared( - uint64 request_id, uint16 participant_node_id, - ClusterCtrcSealReplyResult result); + uint64 request_id, uint16 participant_node_id, ClusterCtrcTxnKeyV1 *key_out, + ClusterCtrcParticipantIdentity *identity_out, uint32 *grant_generation_out, + uint64 *seal_generation_out); +extern bool cluster_ctrc_origin_note_close_reply_shared(uint64 request_id, + uint16 participant_node_id, + ClusterCtrcSealReplyResult result); +extern bool cluster_ctrc_origin_note_certificate_reply_shared(uint64 request_id, + uint16 participant_node_id, + ClusterCtrcSealReplyResult result); /* False means unsupported batch shape, without mutation; true is consumption, * not collective release proof. Caller retains each rechecked admission. */ -extern bool cluster_ctrc_origin_note_local_certificate_batch_shared( - const ClusterCtrcCloseDispatch *dispatches, - const ClusterCtrcSealReplyResult *results, Size count); +extern bool +cluster_ctrc_origin_note_local_certificate_batch_shared(const ClusterCtrcCloseDispatch *dispatches, + const ClusterCtrcSealReplyResult *results, + Size count); extern bool cluster_ctrc_origin_note_local_close_batch_shared( const ClusterCtrcCloseDispatch *dispatches, const ClusterCtrcSealReplyResult *results, const ClusterCtrcLocalReleaseAckV1 *acks, Size count); extern bool cluster_ctrc_origin_next_open_shared(ClusterCtrcTxnKeyV1 *key_out); -extern bool cluster_ctrc_origin_begin_seal_shared( - const ClusterCtrcTxnKeyV1 *key); -extern bool cluster_ctrc_origin_next_close_dispatch_shared( - ClusterCtrcCloseDispatch *dispatch_out); +extern bool cluster_ctrc_origin_begin_seal_shared(const ClusterCtrcTxnKeyV1 *key); +extern bool cluster_ctrc_origin_next_close_dispatch_shared(ClusterCtrcCloseDispatch *dispatch_out); extern bool cluster_ctrc_cleaner_run_pass(void); typedef enum ClusterCtrcNormalStopDomain { @@ -1027,33 +948,28 @@ cluster_ctrc_capacity_probe_current(uint32 segment_id, SCN horizon, uint64 epoch * invalid slot sentinel checks all physical origins in the header. */ extern bool cluster_ctrc_reuse_handoff_complete(const struct UndoSegmentHeaderData *header, uint16 slot_offset); -extern bool cluster_ctrc_terminal_release_sample_exact( - uint32 segment_id, uint16 slot_offset, TransactionId xid, - uint16 slot_wrap, uint8 terminal_status, SCN terminal_scn, - uint64 expected_epoch); -extern ClusterCtrcParticipantOpenResult cluster_ctrc_participant_open( - ClusterCtrcParticipantEntry *participant, const ClusterCtrcTxnKeyV1 *key, - uint32 grant_generation, - const ClusterCtrcParticipantIdentity *identity); -extern ClusterCtrcPrepareResult cluster_ctrc_receipt_prepare( - ClusterCtrcParticipantEntry *participant, - const ClusterCtrcPublicationIdV1 *publication, - const ClusterCtrcTargetV1 *target, ClusterCtrcReceipt *receipt); +extern bool cluster_ctrc_terminal_release_sample_exact(uint32 segment_id, uint16 slot_offset, + TransactionId xid, uint16 slot_wrap, + uint8 terminal_status, SCN terminal_scn, + uint64 expected_epoch); +extern ClusterCtrcParticipantOpenResult +cluster_ctrc_participant_open(ClusterCtrcParticipantEntry *participant, + const ClusterCtrcTxnKeyV1 *key, uint32 grant_generation, + const ClusterCtrcParticipantIdentity *identity); +extern ClusterCtrcPrepareResult +cluster_ctrc_receipt_prepare(ClusterCtrcParticipantEntry *participant, + const ClusterCtrcPublicationIdV1 *publication, + const ClusterCtrcTargetV1 *target, ClusterCtrcReceipt *receipt); /* Caller holds the participant and receipt table locks. */ extern ClusterCtrcPrepareResult cluster_ctrc_receipt_prepare_table_locked( - ClusterCtrcParticipantEntry *participant, - const ClusterCtrcTxnKeyV1 *key, - const ClusterCtrcParticipantIdentity *identity, - uint32 grant_generation, - const ClusterCtrcPublicationIdV1 *publication, - const ClusterCtrcTargetV1 *target, - ClusterCtrcReceipt *receipts, uint8 *probe_states, Size receipt_count, - uint64 journal_sequence, uint64 *receipt_index_out, - Size *probe_count_out); + ClusterCtrcParticipantEntry *participant, const ClusterCtrcTxnKeyV1 *key, + const ClusterCtrcParticipantIdentity *identity, uint32 grant_generation, + const ClusterCtrcPublicationIdV1 *publication, const ClusterCtrcTargetV1 *target, + ClusterCtrcReceipt *receipts, uint8 *probe_states, Size receipt_count, uint64 journal_sequence, + uint64 *receipt_index_out, Size *probe_count_out); extern bool cluster_ctrc_receipt_reclaim_frozen_table_locked( - const ClusterCtrcTxnKeyV1 *key, uint64 expected_receipt_count, - ClusterCtrcReceipt *receipts, uint8 *probe_states, Size receipt_count, - Size *reclaimed_count_out); + const ClusterCtrcTxnKeyV1 *key, uint64 expected_receipt_count, ClusterCtrcReceipt *receipts, + uint8 *probe_states, Size receipt_count, Size *reclaimed_count_out); #define CLUSTER_CTRC_RECLAIM_BATCH_MAX 64 /* Call-local work only; not a shared, durable, or wire authority record. */ typedef struct ClusterCtrcReclaimWork { @@ -1071,141 +987,119 @@ extern bool cluster_ctrc_participant_certificate_batch_shared(const ClusterCtrcCloseDispatch *dispatches, Size count, ClusterCtrcSealReplyResult *results); extern ClusterCtrcPrepareResult cluster_ctrc_receipt_prepare_shared( - const ClusterCtrcTxnKeyV1 *key, - const ClusterCtrcParticipantIdentity *identity, - uint32 grant_generation, - const ClusterCtrcPublicationIdV1 *publication, - const ClusterCtrcTargetV1 *target, - ClusterCtrcReceiptHandle *handle); + const ClusterCtrcTxnKeyV1 *key, const ClusterCtrcParticipantIdentity *identity, + uint32 grant_generation, const ClusterCtrcPublicationIdV1 *publication, + const ClusterCtrcTargetV1 *target, ClusterCtrcReceiptHandle *handle); extern ClusterCtrcApplyResult cluster_ctrc_receipt_apply_prepared( ClusterCtrcParticipantEntry *participant, ClusterCtrcReceipt *receipt, const ClusterCtrcTargetV1 *final_target, ClusterCtrcApplyToken *token); -extern ClusterCtrcApplyResult cluster_ctrc_receipt_apply_shared( - const ClusterCtrcReceiptHandle *handle, - const ClusterCtrcTargetV1 *final_target, ClusterCtrcApplyToken *token); +extern ClusterCtrcApplyResult +cluster_ctrc_receipt_apply_shared(const ClusterCtrcReceiptHandle *handle, + const ClusterCtrcTargetV1 *final_target, + ClusterCtrcApplyToken *token); extern ClusterCtrcApplyResult cluster_ctrc_receipt_retarget_itl( ClusterCtrcParticipantEntry *participant, ClusterCtrcReceipt *receipt, - const ClusterCtrcTargetV1 *pending_target, - const ClusterCtrcTargetV1 *final_target, ClusterCtrcApplyToken *token); + const ClusterCtrcTargetV1 *pending_target, const ClusterCtrcTargetV1 *final_target, + ClusterCtrcApplyToken *token); extern ClusterCtrcApplyResult cluster_ctrc_receipt_retarget_itl_shared( - const ClusterCtrcReceiptHandle *handle, - const ClusterCtrcTargetV1 *pending_target, + const ClusterCtrcReceiptHandle *handle, const ClusterCtrcTargetV1 *pending_target, const ClusterCtrcTargetV1 *final_target, ClusterCtrcApplyToken *token); extern bool cluster_ctrc_receipt_itl_reuse_candidate_shared( - const ClusterCtrcReceiptHandle *handle, - const ClusterCtrcTargetV1 *pending_target, - const ClusterCtrcItlTargetIdentity *current_target, - const uint8 current_slot_sha256[32]); -extern bool cluster_ctrc_receipt_cancel_prepared( - ClusterCtrcParticipantEntry *participant, ClusterCtrcReceipt *receipt); -extern bool cluster_ctrc_receipt_cancel_shared( - const ClusterCtrcReceiptHandle *handle); -extern ClusterCtrcDischargeResult cluster_ctrc_receipt_discharge_itl( - ClusterCtrcParticipantEntry *participant, ClusterCtrcReceipt *receipt, - ClusterCtrcItlProjection projection, - const ClusterCtrcDurability *durability); -extern bool cluster_ctrc_itl_target_identity_matches( - const ClusterCtrcTargetV1 *target, - const ClusterCtrcItlTargetIdentity *expected); + const ClusterCtrcReceiptHandle *handle, const ClusterCtrcTargetV1 *pending_target, + const ClusterCtrcItlTargetIdentity *current_target, const uint8 current_slot_sha256[32]); +extern bool cluster_ctrc_receipt_cancel_prepared(ClusterCtrcParticipantEntry *participant, + ClusterCtrcReceipt *receipt); +extern bool cluster_ctrc_receipt_cancel_shared(const ClusterCtrcReceiptHandle *handle); +extern ClusterCtrcDischargeResult +cluster_ctrc_receipt_discharge_itl(ClusterCtrcParticipantEntry *participant, + ClusterCtrcReceipt *receipt, ClusterCtrcItlProjection projection, + const ClusterCtrcDurability *durability); +extern bool cluster_ctrc_itl_target_identity_matches(const ClusterCtrcTargetV1 *target, + const ClusterCtrcItlTargetIdentity *expected); extern ClusterCtrcDischargeResult cluster_ctrc_receipt_discharge_itl_shared( - const ClusterCtrcReceiptHandle *handle, - const ClusterCtrcItlTargetIdentity *expected_target, - ClusterCtrcItlProjection projection, - const ClusterCtrcDurability *durability); + const ClusterCtrcReceiptHandle *handle, const ClusterCtrcItlTargetIdentity *expected_target, + ClusterCtrcItlProjection projection, const ClusterCtrcDurability *durability); extern ClusterCtrcDischargeResult cluster_ctrc_receipt_discharge_current_mx( ClusterCtrcParticipantEntry *participant, ClusterCtrcReceipt *receipt, - const ClusterCtrcTargetV1 *expected_target, - ClusterCtrcCleanResult clean_result, - const ClusterCtrcDurability *durability); -extern ClusterCtrcDischargeResult -cluster_ctrc_receipt_discharge_current_mx_shared( - const ClusterCtrcReceiptHandle *handle, - const ClusterCtrcTargetV1 *expected_target, - ClusterCtrcCleanResult clean_result, + const ClusterCtrcTargetV1 *expected_target, ClusterCtrcCleanResult clean_result, const ClusterCtrcDurability *durability); -extern ClusterCtrcItlCleanoutApplyResult cluster_ctrc_itl_cleanout_slot( - const ClusterCtrcTxnKeyV1 *key, const ClusterCtrcTargetV1 *target, - ClusterCtrcTerminalStatus terminal_status, SCN commit_scn, - ClusterItlSlotData *slot); -extern ClusterCtrcCloseResult cluster_ctrc_participant_close( - ClusterCtrcParticipantEntry *participant, - const ClusterCtrcParticipantIdentity *identity, uint32 grant_generation, - uint64 seal_generation); -extern ClusterCtrcCloseResult cluster_ctrc_participant_close_or_tombstone( - ClusterCtrcParticipantEntry *participant, const ClusterCtrcTxnKeyV1 *key, - const ClusterCtrcParticipantIdentity *identity, uint32 grant_generation, - uint64 seal_generation); +extern ClusterCtrcDischargeResult cluster_ctrc_receipt_discharge_current_mx_shared( + const ClusterCtrcReceiptHandle *handle, const ClusterCtrcTargetV1 *expected_target, + ClusterCtrcCleanResult clean_result, const ClusterCtrcDurability *durability); +extern ClusterCtrcItlCleanoutApplyResult +cluster_ctrc_itl_cleanout_slot(const ClusterCtrcTxnKeyV1 *key, const ClusterCtrcTargetV1 *target, + ClusterCtrcTerminalStatus terminal_status, SCN commit_scn, + ClusterItlSlotData *slot); +extern ClusterCtrcCloseResult +cluster_ctrc_participant_close(ClusterCtrcParticipantEntry *participant, + const ClusterCtrcParticipantIdentity *identity, + uint32 grant_generation, uint64 seal_generation); +extern ClusterCtrcCloseResult +cluster_ctrc_participant_close_or_tombstone(ClusterCtrcParticipantEntry *participant, + const ClusterCtrcTxnKeyV1 *key, + const ClusterCtrcParticipantIdentity *identity, + uint32 grant_generation, uint64 seal_generation); extern ClusterCtrcSealReplyResult cluster_ctrc_participant_request_apply( - ClusterCtrcParticipantEntry *participant, - ClusterCtrcLocalReleaseAckV1 *ack_summary, - const ClusterCtrcTxnKeyV1 *key, - const ClusterCtrcParticipantIdentity *identity, uint32 grant_generation, - uint64 seal_generation, ClusterCtrcSealSuboperation suboperation, + ClusterCtrcParticipantEntry *participant, ClusterCtrcLocalReleaseAckV1 *ack_summary, + const ClusterCtrcTxnKeyV1 *key, const ClusterCtrcParticipantIdentity *identity, + uint32 grant_generation, uint64 seal_generation, ClusterCtrcSealSuboperation suboperation, uint16 *first_reason, ClusterCtrcLocalReleaseAckV1 *ack_out); extern ClusterCtrcSealReplyResult cluster_ctrc_participant_request_shared( - const ClusterCtrcTxnKeyV1 *key, - const ClusterCtrcParticipantIdentity *identity, uint32 grant_generation, - uint64 seal_generation, ClusterCtrcSealSuboperation suboperation, + const ClusterCtrcTxnKeyV1 *key, const ClusterCtrcParticipantIdentity *identity, + uint32 grant_generation, uint64 seal_generation, ClusterCtrcSealSuboperation suboperation, uint16 *first_reason, ClusterCtrcLocalReleaseAckV1 *ack_out); -extern bool cluster_ctrc_origin_ack_land_entry( - ClusterCtrcOriginEntry *origin, uint64 request_id, - const ClusterCtrcLocalReleaseAckV1 *ack, - ClusterCtrcLocalReleaseAckV1 *ack_slot); -extern bool cluster_ctrc_origin_ack_land_shared( - uint64 request_id, const ClusterCtrcLocalReleaseAckV1 *ack); -extern ClusterCtrcLossResult cluster_ctrc_participant_note_owner_loss( - ClusterCtrcParticipantEntry *participant, ClusterCtrcReceipt *receipt); -extern ClusterCtrcCleanResult cluster_ctrc_clean_reference( - const ClusterCtrcCleanReferenceInput *input); +extern bool cluster_ctrc_origin_ack_land_entry(ClusterCtrcOriginEntry *origin, uint64 request_id, + const ClusterCtrcLocalReleaseAckV1 *ack, + ClusterCtrcLocalReleaseAckV1 *ack_slot); +extern bool cluster_ctrc_origin_ack_land_shared(uint64 request_id, + const ClusterCtrcLocalReleaseAckV1 *ack); +extern ClusterCtrcLossResult +cluster_ctrc_participant_note_owner_loss(ClusterCtrcParticipantEntry *participant, + ClusterCtrcReceipt *receipt); +extern ClusterCtrcCleanResult +cluster_ctrc_clean_reference(const ClusterCtrcCleanReferenceInput *input); extern bool cluster_ctrc_current_mx_terminal_proof_exact( - const ClusterCtrcTxnKeyV1 *key, - const ClusterCurrentMxKey *descriptor_key, - const ClusterCtrcPublicationIdV1 *publication, - const ClusterCurrentMxMemberDesc *members, + const ClusterCtrcTxnKeyV1 *key, const ClusterCurrentMxKey *descriptor_key, + const ClusterCtrcPublicationIdV1 *publication, const ClusterCurrentMxMemberDesc *members, const ClusterCurrentMemberProof *proofs, uint16 nmembers, ClusterCtrcTerminalStatus *terminal_status_out, SCN *commit_scn_out); -extern bool cluster_ctrc_current_mx_rewrite_plan( - const ClusterCtrcTxnKeyV1 *key, - const ClusterCtrcPublicationIdV1 *publication, - const ClusterCurrentMxMemberDesc *members, - const ClusterCurrentMemberProof *proofs, uint16 nmembers, - ClusterCtrcCurrentMxRewritePlan *plan); -extern bool cluster_ctrc_native_current_mx_mutation_allowed( - bool peer_mode, int mx_origin_slot); -extern bool cluster_ctrc_relation_removal_ready_from_snapshot( - const ClusterCtrcReceipt *receipts, Size receipt_count, - uint32 spc_oid, uint32 db_oid, uint32 rel_number); -extern bool cluster_ctrc_relation_removal_ready_shared( - uint32 spc_oid, uint32 db_oid, uint32 rel_number); -extern ClusterCtrcTransferResult cluster_ctrc_transfer_note_successor_receipt( - ClusterCtrcTransferState *transfer); -extern ClusterCtrcTransferResult cluster_ctrc_transfer_note_descriptor_durable( - ClusterCtrcTransferState *transfer); -extern ClusterCtrcTransferResult cluster_ctrc_transfer_remove_predecessor( - ClusterCtrcTransferState *transfer); -extern ClusterCtrcAckResult cluster_ctrc_participant_build_ack( - ClusterCtrcParticipantEntry *participant, - const ClusterCtrcDurability *durability, - ClusterCtrcLocalReleaseAckV1 *ack); +extern bool cluster_ctrc_current_mx_rewrite_plan(const ClusterCtrcTxnKeyV1 *key, + const ClusterCtrcPublicationIdV1 *publication, + const ClusterCurrentMxMemberDesc *members, + const ClusterCurrentMemberProof *proofs, + uint16 nmembers, + ClusterCtrcCurrentMxRewritePlan *plan); +extern bool cluster_ctrc_native_current_mx_mutation_allowed(bool peer_mode, int mx_origin_slot); +extern bool cluster_ctrc_relation_removal_ready_from_snapshot(const ClusterCtrcReceipt *receipts, + Size receipt_count, uint32 spc_oid, + uint32 db_oid, uint32 rel_number); +extern bool cluster_ctrc_relation_removal_ready_shared(uint32 spc_oid, uint32 db_oid, + uint32 rel_number); +extern ClusterCtrcTransferResult +cluster_ctrc_transfer_note_successor_receipt(ClusterCtrcTransferState *transfer); +extern ClusterCtrcTransferResult +cluster_ctrc_transfer_note_descriptor_durable(ClusterCtrcTransferState *transfer); +extern ClusterCtrcTransferResult +cluster_ctrc_transfer_remove_predecessor(ClusterCtrcTransferState *transfer); +extern ClusterCtrcAckResult +cluster_ctrc_participant_build_ack(ClusterCtrcParticipantEntry *participant, + const ClusterCtrcDurability *durability, + ClusterCtrcLocalReleaseAckV1 *ack); extern ClusterCtrcAckResult cluster_ctrc_participant_ack_from_snapshot( - const ClusterCtrcParticipantEntry *participant, - ClusterCtrcReceipt *receipts, Size receipt_count, - const ClusterCtrcDurability *durability, - ClusterCtrcLocalReleaseAckV1 *ack); -extern ClusterCtrcCertificateResult cluster_ctrc_origin_certificate_validate( - const ClusterCtrcCertificateInput *input); -extern bool cluster_ctrc_origin_certificate_digest( - const ClusterCtrcCertificateInput *input, uint8 digest[32]); + const ClusterCtrcParticipantEntry *participant, ClusterCtrcReceipt *receipts, + Size receipt_count, const ClusterCtrcDurability *durability, ClusterCtrcLocalReleaseAckV1 *ack); +extern ClusterCtrcCertificateResult +cluster_ctrc_origin_certificate_validate(const ClusterCtrcCertificateInput *input); +extern bool cluster_ctrc_origin_certificate_digest(const ClusterCtrcCertificateInput *input, + uint8 digest[32]); extern bool cluster_ctrc_origin_certificate_snapshot_entry( const ClusterCtrcOriginEntry *origin, const ClusterCtrcLocalReleaseAckV1 ack_slots[CLUSTER_CTRC_MAX_PARTICIPANTS], uint64 origin_index, ClusterCtrcOriginCertificateSnapshot *snapshot); -extern bool cluster_ctrc_origin_certificate_commit_entry( - ClusterCtrcOriginEntry *origin, - const ClusterCtrcOriginCertificateSnapshot *snapshot); -extern bool cluster_ctrc_terminal_recyclable( - const ClusterCtrcRecycleInput *input); -extern ClusterCtrcCrashDisposition cluster_ctrc_crash_cut_disposition( - ClusterCtrcCrashCut cut); +extern bool +cluster_ctrc_origin_certificate_commit_entry(ClusterCtrcOriginEntry *origin, + const ClusterCtrcOriginCertificateSnapshot *snapshot); +extern bool cluster_ctrc_terminal_recyclable(const ClusterCtrcRecycleInput *input); +extern ClusterCtrcCrashDisposition cluster_ctrc_crash_cut_disposition(ClusterCtrcCrashCut cut); #endif /* CLUSTER_TERMINAL_REF_CENSUS_H */ diff --git a/src/include/cluster/cluster_thread_recovery.h b/src/include/cluster/cluster_thread_recovery.h index 7ba0c88e027..fdc9066f7b9 100644 --- a/src/include/cluster/cluster_thread_recovery.h +++ b/src/include/cluster/cluster_thread_recovery.h @@ -43,8 +43,7 @@ struct XLogReaderState; typedef struct ClusterRecoverySerialGuard ClusterRecoverySerialGuard; -typedef struct ClusterThreadRecoveryAuthorityV1 - ClusterThreadRecoveryAuthorityV1; +typedef struct ClusterThreadRecoveryAuthorityV1 ClusterThreadRecoveryAuthorityV1; /* * Result of attempting to online-recover one dead thread (spec-4.11 §2.2). @@ -53,10 +52,10 @@ typedef struct ClusterThreadRecoveryAuthorityV1 * (result-returning, not FATAL -- R13). */ typedef enum ClusterThreadRecResult { - CLUSTER_THREADREC_DONE = 0, /* recovered_through_local published */ - CLUSTER_THREADREC_BLOCKED = 1, /* verified semantic failure (53RA4) */ + CLUSTER_THREADREC_DONE = 0, /* recovered_through_local published */ + CLUSTER_THREADREC_BLOCKED = 1, /* verified semantic failure (53RA4) */ CLUSTER_THREADREC_NOT_APPLICABLE = 2, /* no online recovery attempt */ - CLUSTER_THREADREC_DEFERRED = 3, /* transient; keep REPLAYING for reap */ + CLUSTER_THREADREC_DEFERRED = 3, /* transient; keep REPLAYING for reap */ } ClusterThreadRecResult; /* @@ -90,14 +89,12 @@ typedef enum ClusterThreadReplayMatchResult { } ClusterThreadReplayMatchResult; static inline bool -cluster_thread_recovery_replay_transition_shape_valid( - ClusterThreadRecReplayState expected, - ClusterThreadRecReplayState target) +cluster_thread_recovery_replay_transition_shape_valid(ClusterThreadRecReplayState expected, + ClusterThreadRecReplayState target) { return expected == CLUSTER_THREADREC_REPLAY_REPLAYING - && (target == CLUSTER_THREADREC_REPLAY_IDLE - || target == CLUSTER_THREADREC_REPLAY_DONE - || target == CLUSTER_THREADREC_REPLAY_BLOCKED); + && (target == CLUSTER_THREADREC_REPLAY_IDLE || target == CLUSTER_THREADREC_REPLAY_DONE + || target == CLUSTER_THREADREC_REPLAY_BLOCKED); } /* @@ -259,12 +256,11 @@ typedef enum ClusterThreadRecReapDecision { } ClusterThreadRecReapDecision; static inline ClusterThreadRecReapDecision -cluster_thread_recovery_reap_decide( - BgwHandleStatus handle_status, bool slot_read, uint64 owned_stamp, - ClusterThreadRecReplayState slot_state, uint64 slot_stamp) +cluster_thread_recovery_reap_decide(BgwHandleStatus handle_status, bool slot_read, + uint64 owned_stamp, ClusterThreadRecReplayState slot_state, + uint64 slot_stamp) { - if (handle_status == BGWH_STARTED - || handle_status == BGWH_NOT_YET_STARTED + if (handle_status == BGWH_STARTED || handle_status == BGWH_NOT_YET_STARTED || handle_status == BGWH_POSTMASTER_DIED) return CLUSTER_THREADREC_REAP_RETAIN; if (handle_status != BGWH_STOPPED || !slot_read || owned_stamp == 0 @@ -288,24 +284,23 @@ typedef struct ClusterThreadRecLaunchEligibility { * acquire any authority it must match the exact main argument and the live * REPLAYING slot/stamp, and it must still carry a valid full duty identity. */ static inline bool -cluster_thread_recovery_worker_start_valid( - const ClusterThreadRecLaunchEligibility *eligibility, uint16 main_thread, - bool slot_read, ClusterThreadRecReplayState slot_state, - uint64 slot_stamp) +cluster_thread_recovery_worker_start_valid(const ClusterThreadRecLaunchEligibility *eligibility, + uint16 main_thread, bool slot_read, + ClusterThreadRecReplayState slot_state, + uint64 slot_stamp) { - return eligibility != NULL - && main_thread >= XLP_THREAD_ID_FIRST_REAL - && main_thread <= CLUSTER_WAL_THREAD_MAX - && eligibility->origin_thread == main_thread - && eligibility->attempt_stamp != 0 && slot_read - && slot_state == CLUSTER_THREADREC_REPLAY_REPLAYING - && slot_stamp == eligibility->attempt_stamp - && cluster_recovery_duty_key_valid_v1(&eligibility->duty) - && eligibility->duty.origin_thread_id == main_thread; + return eligibility != NULL && main_thread >= XLP_THREAD_ID_FIRST_REAL + && main_thread <= CLUSTER_WAL_THREAD_MAX && eligibility->origin_thread == main_thread + && eligibility->attempt_stamp != 0 && slot_read + && slot_state == CLUSTER_THREADREC_REPLAY_REPLAYING + && slot_stamp == eligibility->attempt_stamp + && cluster_recovery_duty_key_valid_v1(&eligibility->duty) + && eligibility->duty.origin_thread_id == main_thread; } -extern bool cluster_reconfig_thread_recovery_eligibility_consume( - uint16 origin_thread, ClusterThreadRecLaunchEligibility *out); +extern bool +cluster_reconfig_thread_recovery_eligibility_consume(uint16 origin_thread, + ClusterThreadRecLaunchEligibility *out); extern void cluster_thread_recovery_lmon_tick(void); extern void cluster_thread_recovery_lmon_shutdown(void); @@ -390,7 +385,7 @@ typedef struct ClusterThreadTouchedRels { * touched set was recovered for. Set by the orchestrator from the * real dead_tid so the retention proof's failed_origin_thread is a * true identity, not a placeholder. 0 = unset (fail-closed). */ - uint16 origin_thread_id; + uint16 origin_thread_id; } ClusterThreadTouchedRels; /* @@ -486,7 +481,7 @@ cluster_thread_recovery_replay_epoch_aborts(uint64 slot_epoch, uint64 current_ep */ static inline bool cluster_thread_recovery_worker_terminal_state(ClusterThreadRecResult res, - ClusterThreadRecReplayState *state) + ClusterThreadRecReplayState *state) { if (state == NULL) return false; @@ -507,9 +502,9 @@ cluster_thread_recovery_worker_terminal_state(ClusterThreadRecResult res, * later increment (the Q10-B apply matrix); declared here for the * reconfig FSM driver call site. */ -extern ClusterThreadRecResult cluster_thread_recovery_replay_one(uint16 dead_tid, - uint64 episode_epoch, - const ClusterThreadRecoveryAuthorityV1 *authority); +extern ClusterThreadRecResult +cluster_thread_recovery_replay_one(uint16 dead_tid, uint64 episode_epoch, + const ClusterThreadRecoveryAuthorityV1 *authority); /* * Unfreeze precondition (spec-4.11 D3, 3b-3): has dead_tid been fully @@ -553,10 +548,9 @@ extern bool cluster_thread_recovery_gate_unfreeze(const uint64 *dead_bitmap, int */ extern bool cluster_thread_recovery_replay_mark_replaying(uint16 dead_tid, uint64 episode_epoch); extern ClusterThreadReplayMatchResult -cluster_thread_recovery_replay_transition_if_match( - uint16 dead_tid, uint64 attempt_stamp, - ClusterThreadRecReplayState expected, - ClusterThreadRecReplayState target); +cluster_thread_recovery_replay_transition_if_match(uint16 dead_tid, uint64 attempt_stamp, + ClusterThreadRecReplayState expected, + ClusterThreadRecReplayState target); extern bool cluster_thread_recovery_replay_read(uint16 dead_tid, ClusterThreadRecReplayState *state_out, uint64 *epoch_out); @@ -699,11 +693,9 @@ extern ClusterThreadRecResult cluster_thread_recovery_validated_end(uint16 dead_ * Real validated-boundary derivation for replay_one(dead_tid, epoch) is D4 * (3b-4); 3b-2 derives only a basic window. */ -extern ClusterThreadRecResult -cluster_thread_recovery_replay_one_window(uint16 dead_tid, XLogRecPtr scan_lower, - XLogRecPtr scan_upper, uint64 episode_epoch, - const ClusterThreadRecoveryAuthorityV1 *authority, - ClusterThreadReplayStats *stats); +extern ClusterThreadRecResult cluster_thread_recovery_replay_one_window( + uint16 dead_tid, XLogRecPtr scan_lower, XLogRecPtr scan_upper, uint64 episode_epoch, + const ClusterThreadRecoveryAuthorityV1 *authority, ClusterThreadReplayStats *stats); /* * PGRAC: spec-6.12h D-h3b -- per-thread WAL reader factory, exported for the diff --git a/src/include/cluster/cluster_thread_recovery_authority.h b/src/include/cluster/cluster_thread_recovery_authority.h index 47821735982..d50f5d16cb7 100644 --- a/src/include/cluster/cluster_thread_recovery_authority.h +++ b/src/include/cluster/cluster_thread_recovery_authority.h @@ -12,8 +12,7 @@ #include "cluster/cluster_ir.h" #include "cluster/cluster_wal_retention.h" -typedef enum ClusterThreadRecoveryAuthorityResultV1 -{ +typedef enum ClusterThreadRecoveryAuthorityResultV1 { CLUSTER_THREAD_AUTHORITY_OK = 0, CLUSTER_THREAD_AUTHORITY_INVALID = 1, CLUSTER_THREAD_AUTHORITY_ROOT_STALE = 2, @@ -22,8 +21,7 @@ typedef enum ClusterThreadRecoveryAuthorityResultV1 CLUSTER_THREAD_AUTHORITY_PIN_STALE = 5 } ClusterThreadRecoveryAuthorityResultV1; -typedef enum ClusterThreadRecoveryRootFinalizeResultV1 -{ +typedef enum ClusterThreadRecoveryRootFinalizeResultV1 { CLUSTER_THREAD_ROOT_FINALIZE_OK = 0, CLUSTER_THREAD_ROOT_FINALIZE_ALREADY_COMPLETE = 1, CLUSTER_THREAD_ROOT_FINALIZE_RETRY = 2, @@ -32,8 +30,7 @@ typedef enum ClusterThreadRecoveryRootFinalizeResultV1 CLUSTER_THREAD_ROOT_FINALIZE_INVALID = 5 } ClusterThreadRecoveryRootFinalizeResultV1; -typedef struct ClusterThreadRecoveryAuthorityV1 -{ +typedef struct ClusterThreadRecoveryAuthorityV1 { const ClusterRecoveryDutyKey *duty; const ClusterControlRootSnapshot *root_snapshot; const ClusterControlRootReadToken *root_token; @@ -46,26 +43,22 @@ typedef struct ClusterThreadRecoveryAuthorityV1 extern bool cluster_thread_recovery_pin_request_build_v1( uint16 dead_tid, const ClusterRecoveryDutyKey *duty, - const ClusterControlRootSnapshot *root_snapshot, - const ClusterControlRootReadToken *root_token, - const ClusterFormationWitnessV1 *formation, - const PgracExternalFenceNeedSetV1 *fence_need_set, + const ClusterControlRootSnapshot *root_snapshot, const ClusterControlRootReadToken *root_token, + const ClusterFormationWitnessV1 *formation, const PgracExternalFenceNeedSetV1 *fence_need_set, const PgracExternalFenceAdmissionSetV1 *fence_admission_set, - ClusterWalRetentionInterval *out_interval, - ClusterWalRetentionPinThreadRequest *out_request); + ClusterWalRetentionInterval *out_interval, ClusterWalRetentionPinThreadRequest *out_request); extern ClusterThreadRecoveryAuthorityResultV1 cluster_thread_recovery_authority_revalidate_nowait_v1( const ClusterThreadRecoveryAuthorityV1 *authority); extern bool cluster_thread_recovery_authority_covers_window_v1( - const ClusterThreadRecoveryAuthorityV1 *authority, uint16 dead_tid, - XLogRecPtr scan_lower, XLogRecPtr scan_upper); + const ClusterThreadRecoveryAuthorityV1 *authority, uint16 dead_tid, XLogRecPtr scan_lower, + XLogRecPtr scan_upper); extern bool cluster_thread_recovery_root_complete_patch_build_v1( - const ClusterThreadRecoveryAuthorityV1 *authority, - XLogRecPtr recovered_through, ClusterControlRootPatch *out_patch); + const ClusterThreadRecoveryAuthorityV1 *authority, XLogRecPtr recovered_through, + ClusterControlRootPatch *out_patch); extern ClusterThreadRecoveryRootFinalizeResultV1 -cluster_thread_recovery_root_finalize_after_ir_v1( - const ClusterThreadRecoveryAuthorityV1 *authority, - const ClusterControlRootPatch *patch, - ClusterControlRootSnapshot *out_snapshot); +cluster_thread_recovery_root_finalize_after_ir_v1(const ClusterThreadRecoveryAuthorityV1 *authority, + const ClusterControlRootPatch *patch, + ClusterControlRootSnapshot *out_snapshot); -#endif /* CLUSTER_THREAD_RECOVERY_AUTHORITY_H */ +#endif /* CLUSTER_THREAD_RECOVERY_AUTHORITY_H */ diff --git a/src/include/cluster/cluster_thread_recovery_fabric.h b/src/include/cluster/cluster_thread_recovery_fabric.h index 95df25e3eed..2a18e3756b4 100644 --- a/src/include/cluster/cluster_thread_recovery_fabric.h +++ b/src/include/cluster/cluster_thread_recovery_fabric.h @@ -10,32 +10,29 @@ #define CLUSTER_THREAD_RECOVERY_FABRIC_INTERFACE_V1 1 -typedef struct ClusterThreadRecoveryFabricPlanV1 - ClusterThreadRecoveryFabricPlanV1; +typedef struct ClusterThreadRecoveryFabricPlanV1 ClusterThreadRecoveryFabricPlanV1; -typedef struct ClusterThreadRecoveryFabricPlanRequestV1 -{ - uint64 system_identifier; - uint8 storage_uuid[16]; +typedef struct ClusterThreadRecoveryFabricPlanRequestV1 { + uint64 system_identifier; + uint8 storage_uuid[16]; const RfContributorStreamCutV1 *physical_cuts; - uint32 participant_count; - uint64 retention_binding_cookie; - Size page_memory_budget; - Size side_memory_budget; - bool space_active; - uint8 reserved_zero[7]; + uint32 participant_count; + uint64 retention_binding_cookie; + Size page_memory_budget; + Size side_memory_budget; + bool space_active; + uint8 reserved_zero[7]; } ClusterThreadRecoveryFabricPlanRequestV1; -typedef struct ClusterThreadRecoveryFabricApplyResultV1 -{ - uint32 page_target_count; - uint32 side_operation_count; - uint32 page_write_count; - uint32 page_result_skip_count; - bool page_durability_complete; - bool page_postread_complete; - bool side_apply_complete; - uint8 reserved_zero[5]; +typedef struct ClusterThreadRecoveryFabricApplyResultV1 { + uint32 page_target_count; + uint32 side_operation_count; + uint32 page_write_count; + uint32 page_result_skip_count; + bool page_durability_complete; + bool page_postread_complete; + bool side_apply_complete; + uint8 reserved_zero[5]; } ClusterThreadRecoveryFabricApplyResultV1; struct ClusterThreadRecoveryAuthorityV1; @@ -44,39 +41,34 @@ extern RfPageProofDetailV1 cluster_thread_recovery_fabric_plan_create_v1( const ClusterThreadRecoveryFabricPlanRequestV1 *request, ClusterThreadRecoveryFabricPlanV1 **out_plan); extern RfPageProofDetailV1 cluster_thread_recovery_fabric_plan_feed_record_v1( - ClusterThreadRecoveryFabricPlanV1 *plan, XLogReaderState *record, - uint16 participant_index); -extern RfPageProofDetailV1 cluster_thread_recovery_fabric_plan_seal_v1( - ClusterThreadRecoveryFabricPlanV1 *plan); -extern const RfPageOnlinePlanV1 *cluster_thread_recovery_fabric_page_plan_v1( - const ClusterThreadRecoveryFabricPlanV1 *plan); -extern const RfSideOnlinePlanV1 *cluster_thread_recovery_fabric_side_plan_v1( - const ClusterThreadRecoveryFabricPlanV1 *plan); -extern uint32 cluster_thread_recovery_fabric_participant_count_v1( - const ClusterThreadRecoveryFabricPlanV1 *plan); -extern bool cluster_thread_recovery_fabric_identity_matches_v1( - const ClusterThreadRecoveryFabricPlanV1 *plan, uint64 system_identifier, - const uint8 storage_uuid[16]); -extern bool cluster_thread_recovery_fabric_cut_v1( - const ClusterThreadRecoveryFabricPlanV1 *plan, uint32 index, - RfContributorStreamCutV1 *out_cut); + ClusterThreadRecoveryFabricPlanV1 *plan, XLogReaderState *record, uint16 participant_index); +extern RfPageProofDetailV1 +cluster_thread_recovery_fabric_plan_seal_v1(ClusterThreadRecoveryFabricPlanV1 *plan); +extern const RfPageOnlinePlanV1 * +cluster_thread_recovery_fabric_page_plan_v1(const ClusterThreadRecoveryFabricPlanV1 *plan); +extern const RfSideOnlinePlanV1 * +cluster_thread_recovery_fabric_side_plan_v1(const ClusterThreadRecoveryFabricPlanV1 *plan); +extern uint32 +cluster_thread_recovery_fabric_participant_count_v1(const ClusterThreadRecoveryFabricPlanV1 *plan); +extern bool +cluster_thread_recovery_fabric_identity_matches_v1(const ClusterThreadRecoveryFabricPlanV1 *plan, + uint64 system_identifier, + const uint8 storage_uuid[16]); +extern bool cluster_thread_recovery_fabric_cut_v1(const ClusterThreadRecoveryFabricPlanV1 *plan, + uint32 index, RfContributorStreamCutV1 *out_cut); extern RfPageProofDetailV1 cluster_thread_recovery_fabric_scan_root_v1( - uint16 dead_thread, XLogRecPtr scan_begin_inclusive, - XLogRecPtr scan_end_exclusive, - const struct ClusterThreadRecoveryAuthorityV1 *authority, - bool space_active, ClusterThreadRecoveryFabricPlanV1 **out_plan, - uint64 *out_record_count); -extern RfPageProofDetailV1 cluster_thread_recovery_fabric_apply_v1( - const ClusterThreadRecoveryFabricPlanV1 *plan, - const struct ClusterThreadRecoveryAuthorityV1 *authority, - ClusterThreadRecoveryFabricApplyResultV1 *result); + uint16 dead_thread, XLogRecPtr scan_begin_inclusive, XLogRecPtr scan_end_exclusive, + const struct ClusterThreadRecoveryAuthorityV1 *authority, bool space_active, + ClusterThreadRecoveryFabricPlanV1 **out_plan, uint64 *out_record_count); +extern RfPageProofDetailV1 +cluster_thread_recovery_fabric_apply_v1(const ClusterThreadRecoveryFabricPlanV1 *plan, + const struct ClusterThreadRecoveryAuthorityV1 *authority, + ClusterThreadRecoveryFabricApplyResultV1 *result); extern RfPageProofDetailV1 cluster_thread_recovery_fabric_execute_root_v1( - uint16 dead_thread, XLogRecPtr scan_begin_inclusive, - XLogRecPtr scan_end_exclusive, - const struct ClusterThreadRecoveryAuthorityV1 *authority, - bool space_active, ClusterThreadRecoveryFabricApplyResultV1 *result, - uint64 *out_record_count); -extern void cluster_thread_recovery_fabric_plan_destroy_v1( - ClusterThreadRecoveryFabricPlanV1 **plan); + uint16 dead_thread, XLogRecPtr scan_begin_inclusive, XLogRecPtr scan_end_exclusive, + const struct ClusterThreadRecoveryAuthorityV1 *authority, bool space_active, + ClusterThreadRecoveryFabricApplyResultV1 *result, uint64 *out_record_count); +extern void +cluster_thread_recovery_fabric_plan_destroy_v1(ClusterThreadRecoveryFabricPlanV1 **plan); #endif diff --git a/src/include/cluster/cluster_tt_durable.h b/src/include/cluster/cluster_tt_durable.h index 32491b827f6..6ce25bd0211 100644 --- a/src/include/cluster/cluster_tt_durable.h +++ b/src/include/cluster/cluster_tt_durable.h @@ -38,7 +38,7 @@ #include "cluster/cluster_itl_slot.h" /* UBA (spec-4.8 D7-A set_head) */ #include "cluster/cluster_scn.h" /* SCN */ -#include "cluster/cluster_tt_slot.h" /* TTSlot */ +#include "cluster/cluster_tt_slot.h" /* TTSlot */ typedef struct ClusterSemanticAdmissionToken ClusterSemanticAdmissionToken; @@ -63,10 +63,10 @@ typedef enum ClusterTTActiveTransitionDecision { CLUSTER_TT_ACTIVE_CORRUPT } ClusterTTActiveTransitionDecision; -extern ClusterTTActiveTransitionDecision cluster_tt_active_transition_decide( - const TTSlot *predecessor, uint32 disk_generation, - uint32 expected_generation, TransactionId xid, uint16 wrap, - bool identity_authorized); +extern ClusterTTActiveTransitionDecision +cluster_tt_active_transition_decide(const TTSlot *predecessor, uint32 disk_generation, + uint32 expected_generation, TransactionId xid, uint16 wrap, + bool identity_authorized); /* Exact ACTIVE-to-terminal compare-before-transition result. */ typedef enum ClusterTTTerminalTransitionDecision { @@ -77,10 +77,10 @@ typedef enum ClusterTTTerminalTransitionDecision { CLUSTER_TT_TERMINAL_CORRUPT } ClusterTTTerminalTransitionDecision; -extern ClusterTTTerminalTransitionDecision cluster_tt_terminal_transition_decide( - const TTSlot *predecessor, uint32 disk_generation, - uint32 expected_generation, TransactionId xid, uint16 wrap, - uint8 terminal_status, SCN commit_scn); +extern ClusterTTTerminalTransitionDecision +cluster_tt_terminal_transition_decide(const TTSlot *predecessor, uint32 disk_generation, + uint32 expected_generation, TransactionId xid, uint16 wrap, + uint8 terminal_status, SCN commit_scn); /* * Publish the canonical physical ACTIVE predecessor for one exact current @@ -93,23 +93,23 @@ extern ClusterTTTerminalTransitionDecision cluster_tt_terminal_transition_decide * Every other failure raises ERROR. In particular a BIND emitter failure * never returns this retry result, and zero outputs after ERROR prove nothing. */ -extern XLogRecPtr cluster_tt_slot_durable_publish_active( - const ClusterTTSlotCurrentOwner *expected_owner, - const ClusterSemanticAdmissionToken *admission, - uint32 *segment_generation_out, TTSlot *successor_out); +extern XLogRecPtr +cluster_tt_slot_durable_publish_active(const ClusterTTSlotCurrentOwner *expected_owner, + const ClusterSemanticAdmissionToken *admission, + uint32 *segment_generation_out, TTSlot *successor_out); /* Recovery/online-replay exact BIND predecessor classification and apply. */ extern ClusterTTActiveTransitionDecision cluster_tt_durable_bind_preflight_exact(uint8 instance, uint32 segment_id, - uint32 segment_generation, uint16 slot_offset, uint16 wrap, - TransactionId xid); + uint32 segment_generation, uint16 slot_offset, uint16 wrap, + TransactionId xid); extern ClusterTTTerminalTransitionDecision cluster_tt_durable_abort_preflight_exact(uint8 instance, uint32 segment_id, - uint32 segment_generation, uint16 slot_offset, uint16 wrap, - TransactionId xid); -extern void cluster_tt_durable_redo_bind_slot(uint8 instance, - uint32 segment_id, uint32 segment_generation, uint16 slot_offset, - uint16 wrap, TransactionId xid); + uint32 segment_generation, uint16 slot_offset, uint16 wrap, + TransactionId xid); +extern void cluster_tt_durable_redo_bind_slot(uint8 instance, uint32 segment_id, + uint32 segment_generation, uint16 slot_offset, + uint16 wrap, TransactionId xid); /* * cluster_tt_durable_redo_decide -- decide what an XLOG_UNDO_TT_SLOT_COMMIT @@ -206,19 +206,16 @@ extern void cluster_tt_slot_durable_commit(uint32 segment_id, uint16 slot_offset * cluster_tt_durable_redo_stamp_slot() (cluster_undo_xlog.c), driven by * xact_redo_commit instead of the 0x30 redo. */ -extern uint8 cluster_tt_slot_durable_commit_writeonly(uint32 segment_id, - uint32 segment_generation, - uint16 slot_offset, TransactionId xid, uint16 wrap, - SCN commit_scn, - const ClusterSemanticAdmissionToken *admission, - TTSlot *successor_out); +extern uint8 cluster_tt_slot_durable_commit_writeonly( + uint32 segment_id, uint32 segment_generation, uint16 slot_offset, TransactionId xid, + uint16 wrap, SCN commit_scn, const ClusterSemanticAdmissionToken *admission, + TTSlot *successor_out); /* Ordinary abort: verify exact ACTIVE, emit+flush exact 0x60, then * apply the identical ABORTED successor before allocator reuse. */ -extern XLogRecPtr cluster_tt_slot_durable_abort_exact(uint32 segment_id, - uint32 segment_generation, uint16 slot_offset, TransactionId xid, - uint16 wrap, const ClusterSemanticAdmissionToken *admission, - TTSlot *successor_out); +extern XLogRecPtr cluster_tt_slot_durable_abort_exact( + uint32 segment_id, uint32 segment_generation, uint16 slot_offset, TransactionId xid, + uint16 wrap, const ClusterSemanticAdmissionToken *admission, TTSlot *successor_out); /* * cluster_tt_slot_durable_abort -- spec-3.15 D5 (ROLLBACK PREPARED). @@ -273,8 +270,8 @@ extern bool cluster_tt_slot_durable_lookup_committed_stable( * a non-NULL slot_out remains canonical zero. */ extern bool cluster_tt_slot_durable_read_exact_stable(uint32 segment_id, uint16 slot_offset, - TransactionId xid, uint16 expected_wrap, - TTSlot *slot_out); + TransactionId xid, uint16 expected_wrap, + TTSlot *slot_out); /* * Recovery-only typed TT mutations. Unlike the normal transaction helpers, @@ -283,22 +280,21 @@ extern bool cluster_tt_slot_durable_read_exact_stable(uint32 segment_id, uint16 * exact undo segment before returning; a stale/newer identity is a no-op and * must be detected by the caller's exact post-read. */ -extern void cluster_tt_durable_redo_abort_slot(uint8 instance, - uint32 segment_id, uint16 slot_offset, uint16 wrap, TransactionId xid); -extern void cluster_tt_durable_redo_abort_slot_exact(uint8 instance, - uint32 segment_id, uint32 segment_generation, uint16 slot_offset, - uint16 wrap, TransactionId xid); -extern void cluster_tt_durable_redo_set_head_slot(uint8 instance, - uint32 segment_id, uint16 slot_offset, uint16 wrap, TransactionId xid, - UBA first_undo_block); +extern void cluster_tt_durable_redo_abort_slot(uint8 instance, uint32 segment_id, + uint16 slot_offset, uint16 wrap, TransactionId xid); +extern void cluster_tt_durable_redo_abort_slot_exact(uint8 instance, uint32 segment_id, + uint32 segment_generation, uint16 slot_offset, + uint16 wrap, TransactionId xid); +extern void cluster_tt_durable_redo_set_head_slot(uint8 instance, uint32 segment_id, + uint16 slot_offset, uint16 wrap, + TransactionId xid, UBA first_undo_block); extern ClusterTTDurableResolve cluster_tt_slot_durable_resolve_by_xid_origin(int origin_node, TransactionId xid, uint32 expected_wrap, SCN *commit_scn, uint16 *out_seg, uint16 *out_slot, uint16 *out_wrap); -typedef enum ClusterTTDurableLocate -{ +typedef enum ClusterTTDurableLocate { CLUSTER_TT_DURABLE_LOCATE_FOUND = 0, CLUSTER_TT_DURABLE_LOCATE_MISSING, CLUSTER_TT_DURABLE_LOCATE_AMBIGUOUS, @@ -308,9 +304,9 @@ typedef enum ClusterTTDurableLocate /* Recovery projection locator: find exactly one durable ACTIVE/COMMITTED/ * ABORTED owner without interpreting that state as terminal authority. */ extern ClusterTTDurableLocate -cluster_tt_slot_durable_locate_any_by_xid_origin(int origin_node, - TransactionId xid, uint16 *out_seg, uint16 *out_slot, - uint16 *out_wrap, uint8 *out_status); +cluster_tt_slot_durable_locate_any_by_xid_origin(int origin_node, TransactionId xid, + uint16 *out_seg, uint16 *out_slot, + uint16 *out_wrap, uint8 *out_status); /* * cluster_tt_slot_durable_lookup_by_xid -- scan the local node's undo segment diff --git a/src/include/cluster/cluster_tt_local.h b/src/include/cluster/cluster_tt_local.h index 8c91139b898..d17666ada9f 100644 --- a/src/include/cluster/cluster_tt_local.h +++ b/src/include/cluster/cluster_tt_local.h @@ -72,10 +72,10 @@ typedef struct ClusterCanonicalTxnBinding { StaticAssertDecl(sizeof(ClusterCanonicalTxnBinding) == 32, "canonical transaction binding must remain stack-only 32 bytes"); -extern bool cluster_tt_local_prepare_canonical_active( - TransactionId top_xid, ClusterCanonicalTxnBinding *binding_out); -extern bool cluster_tt_local_get_published_binding( - TransactionId top_xid, ClusterCanonicalTxnBinding *binding_out); +extern bool cluster_tt_local_prepare_canonical_active(TransactionId top_xid, + ClusterCanonicalTxnBinding *binding_out); +extern bool cluster_tt_local_get_published_binding(TransactionId top_xid, + ClusterCanonicalTxnBinding *binding_out); /* * cluster_tt_local_record_commit -- install COMMITTED status for a @@ -106,7 +106,7 @@ extern void cluster_tt_local_record_commit(TransactionId xid, SCN commit_scn); * must NOT do durable I/O). */ extern bool cluster_tt_local_precommit_durable_finish(TransactionId xid, SCN commit_scn, - struct xl_xact_tt_commit *out_fold); + struct xl_xact_tt_commit *out_fold); extern bool cluster_tt_local_preabort_durable_finish(TransactionId xid); /* diff --git a/src/include/cluster/cluster_tt_slot.h b/src/include/cluster/cluster_tt_slot.h index e83a9aa24f8..feaf16db645 100644 --- a/src/include/cluster/cluster_tt_slot.h +++ b/src/include/cluster/cluster_tt_slot.h @@ -356,9 +356,10 @@ extern uint16 cluster_tt_slot_alloc(uint32 segment_id, TransactionId top_xid); */ extern uint16 cluster_tt_slot_alloc_ext(uint32 segment_id, TransactionId top_xid, bool *out_retained_pressure); -extern uint16 cluster_tt_slot_alloc_current_exact( - int node_id, uint32 expected_segment_id, TransactionId top_xid, - bool *out_retained_pressure, bool *out_current_drift, uint16 *out_wrap); +extern uint16 cluster_tt_slot_alloc_current_exact(int node_id, uint32 expected_segment_id, + TransactionId top_xid, + bool *out_retained_pressure, + bool *out_current_drift, uint16 *out_wrap); extern void cluster_tt_slot_free(uint32 segment_id, uint16 slot_offset); extern uint16 cluster_tt_slot_get_wrap(uint32 segment_id, uint16 slot_offset); @@ -399,8 +400,8 @@ extern void cluster_tt_slot_mark_aborted(uint32 segment_id, uint16 slot_offset, * the SEGMENT_ACTIVE -> SEGMENT_COMMITTED transition. */ extern uint32 cluster_tt_slot_current_segment(int node_id); -extern bool cluster_tt_slot_current_owner_by_xid( - int node_id, TransactionId xid, ClusterTTSlotCurrentOwner *out); +extern bool cluster_tt_slot_current_owner_by_xid(int node_id, TransactionId xid, + ClusterTTSlotCurrentOwner *out); extern void cluster_tt_slot_rollover(int node_id, uint32 new_segment_id, bool *out_old_had_active); diff --git a/src/include/cluster/cluster_tx_enqueue.h b/src/include/cluster/cluster_tx_enqueue.h index 765b912ad45..129264c6744 100644 --- a/src/include/cluster/cluster_tx_enqueue.h +++ b/src/include/cluster/cluster_tx_enqueue.h @@ -80,8 +80,8 @@ extern ClusterTxwResult cluster_tx_enqueue_wait(const ClusterTTStatusKey *holder /* R4 D9 exact TARGET wait. The caller owns locator capture and mandatory * post-wait page/tuple requalification; this layer never returns visibility. */ extern ClusterTxwResult cluster_tx_enqueue_wait_exact(const ClusterTxLocator *locator, - int effective_timeout_ms, - ClusterTxResolveReason *reason_out); + int effective_timeout_ms, + ClusterTxResolveReason *reason_out); /* Idempotent R4 D9 SOURCE/TARGET-wait cleanup for proc_exit/FATAL paths. */ extern void cluster_tx_enqueue_cleanup_on_backend_exit_callback(int code, Datum arg); @@ -93,9 +93,9 @@ extern void cluster_tx_enqueue_cleanup_on_backend_exit_callback(int code, Datum * the heap caller re-DESCRIBE exact TARGET authority. The caller retains the * in/out monotonic deadline across those retries; zero initializes it once. */ -extern ClusterTxwResult cluster_tx_enqueue_wait_current_mx( - const ClusterTTStatusKey *holder_key, int effective_timeout_ms, - uint64 *absolute_deadline_mono_us); +extern ClusterTxwResult cluster_tx_enqueue_wait_current_mx(const ClusterTTStatusKey *holder_key, + int effective_timeout_ms, + uint64 *absolute_deadline_mono_us); /* * cluster_txw_wake_waiters — wake every backend waiting on holder_key. diff --git a/src/include/cluster/cluster_tx_resolve.h b/src/include/cluster/cluster_tx_resolve.h index 359a1c82db5..679e515c26f 100644 --- a/src/include/cluster/cluster_tx_resolve.h +++ b/src/include/cluster/cluster_tx_resolve.h @@ -95,28 +95,23 @@ cluster_tx_outcome_proof_is_valid(ClusterTxOutcome outcome, ClusterTxProofKind p { static const uint8 valid_proofs[5] = { [CLUSTER_TX_UNKNOWN] - = (uint8)((1U << CLUSTER_TX_PROOF_NONE) - | (1U << CLUSTER_TX_PROOF_RECYCLED_BELOW_HORIZON)), - [CLUSTER_TX_IN_PROGRESS] - = (uint8)((1U << CLUSTER_TX_PROOF_ORIGIN_DURABLE_TT_CLOG) - | (1U << CLUSTER_TX_PROOF_ORIGIN_SUBTRANS_TOP) - | (1U << CLUSTER_TX_PROOF_ORIGIN_MULTIXACT)), - [CLUSTER_TX_PREPARED] - = (uint8)((1U << CLUSTER_TX_PROOF_ORIGIN_SUBTRANS_TOP) - | (1U << CLUSTER_TX_PROOF_ORIGIN_TWOPHASE) - | (1U << CLUSTER_TX_PROOF_ORIGIN_MULTIXACT)), - [CLUSTER_TX_COMMITTED] - = (uint8)((1U << CLUSTER_TX_PROOF_ITL_CLEANOUT) - | (1U << CLUSTER_TX_PROOF_ORIGIN_DURABLE_TT_CLOG) - | (1U << CLUSTER_TX_PROOF_ORIGIN_SUBTRANS_TOP) - | (1U << CLUSTER_TX_PROOF_ORIGIN_MULTIXACT) - | (1U << CLUSTER_TX_PROOF_RECOVERY_MATERIALIZED)), - [CLUSTER_TX_ABORTED] - = (uint8)((1U << CLUSTER_TX_PROOF_ITL_CLEANOUT) - | (1U << CLUSTER_TX_PROOF_ORIGIN_DURABLE_TT_CLOG) - | (1U << CLUSTER_TX_PROOF_ORIGIN_SUBTRANS_TOP) - | (1U << CLUSTER_TX_PROOF_ORIGIN_MULTIXACT) - | (1U << CLUSTER_TX_PROOF_RECOVERY_MATERIALIZED)), + = (uint8)((1U << CLUSTER_TX_PROOF_NONE) | (1U << CLUSTER_TX_PROOF_RECYCLED_BELOW_HORIZON)), + [CLUSTER_TX_IN_PROGRESS] = (uint8)((1U << CLUSTER_TX_PROOF_ORIGIN_DURABLE_TT_CLOG) + | (1U << CLUSTER_TX_PROOF_ORIGIN_SUBTRANS_TOP) + | (1U << CLUSTER_TX_PROOF_ORIGIN_MULTIXACT)), + [CLUSTER_TX_PREPARED] = (uint8)((1U << CLUSTER_TX_PROOF_ORIGIN_SUBTRANS_TOP) + | (1U << CLUSTER_TX_PROOF_ORIGIN_TWOPHASE) + | (1U << CLUSTER_TX_PROOF_ORIGIN_MULTIXACT)), + [CLUSTER_TX_COMMITTED] = (uint8)((1U << CLUSTER_TX_PROOF_ITL_CLEANOUT) + | (1U << CLUSTER_TX_PROOF_ORIGIN_DURABLE_TT_CLOG) + | (1U << CLUSTER_TX_PROOF_ORIGIN_SUBTRANS_TOP) + | (1U << CLUSTER_TX_PROOF_ORIGIN_MULTIXACT) + | (1U << CLUSTER_TX_PROOF_RECOVERY_MATERIALIZED)), + [CLUSTER_TX_ABORTED] = (uint8)((1U << CLUSTER_TX_PROOF_ITL_CLEANOUT) + | (1U << CLUSTER_TX_PROOF_ORIGIN_DURABLE_TT_CLOG) + | (1U << CLUSTER_TX_PROOF_ORIGIN_SUBTRANS_TOP) + | (1U << CLUSTER_TX_PROOF_ORIGIN_MULTIXACT) + | (1U << CLUSTER_TX_PROOF_RECOVERY_MATERIALIZED)), }; if ((unsigned int)outcome >= lengthof(valid_proofs) @@ -150,15 +145,11 @@ typedef struct ClusterTxResolution { * exact undo record under Candidate-2 SCUR. Every other identity byte is * immutable; a canonical request never permits a wrap substitution. */ static inline bool -cluster_tx_locator_reply_matches(const ClusterTxLocator *request, - const ClusterTxLocator *reply) +cluster_tx_locator_reply_matches(const ClusterTxLocator *request, const ClusterTxLocator *reply) { - if (request == NULL || reply == NULL - || request->uba.raw[0] != reply->uba.raw[0] - || request->uba.raw[1] != reply->uba.raw[1] - || request->xid != reply->xid - || request->itl_kind != reply->itl_kind - || request->itl_slot_index != reply->itl_slot_index) + if (request == NULL || reply == NULL || request->uba.raw[0] != reply->uba.raw[0] + || request->uba.raw[1] != reply->uba.raw[1] || request->xid != reply->xid + || request->itl_kind != reply->itl_kind || request->itl_slot_index != reply->itl_slot_index) return false; if (request->tt_wrap == TT_WRAP_INVALID) return reply->tt_wrap <= TT_WRAP_MAX; @@ -192,17 +183,17 @@ typedef struct ClusterMultiResolution { extern bool cluster_tx_locator_from_itl(Page page, uint8 slot_index, ClusterTxLocator *out, ClusterTxResolveReason *reason_out); -extern bool cluster_tx_locator_from_itl_terminal_census( - Page page, uint8 slot_index, ClusterTxLocator *out, - ClusterTxResolveReason *reason_out); +extern bool cluster_tx_locator_from_itl_terminal_census(Page page, uint8 slot_index, + ClusterTxLocator *out, + ClusterTxResolveReason *reason_out); extern ClusterTxOutcome cluster_tx_resolve_exact(const ClusterTxLocator *locator, ClusterTxResolveMode mode, ClusterTxResolution *out, ClusterTxResolveReason *reason_out); -extern ClusterTxOutcome cluster_tx_resolve_exact_admitted( - const ClusterTxLocator *locator, ClusterTxResolveMode mode, - const ClusterSemanticAdmissionToken *admission, ClusterTxResolution *out, - ClusterTxResolveReason *reason_out); +extern ClusterTxOutcome +cluster_tx_resolve_exact_admitted(const ClusterTxLocator *locator, ClusterTxResolveMode mode, + const ClusterSemanticAdmissionToken *admission, + ClusterTxResolution *out, ClusterTxResolveReason *reason_out); extern ClusterTxOutcome cluster_tx_resolve_terminal_census_retained_admitted( const ClusterTxLocator *locator, SCN retained_commit_scn, const ClusterSemanticAdmissionToken *admission, ClusterTxResolution *out, diff --git a/src/include/cluster/cluster_uba.h b/src/include/cluster/cluster_uba.h index e98fb87f1fc..54af87ea5b4 100644 --- a/src/include/cluster/cluster_uba.h +++ b/src/include/cluster/cluster_uba.h @@ -72,9 +72,9 @@ #define CLUSTER_UBA_H #include "c.h" -#include "cluster/cluster_scn.h" /* NodeId, SCN_MAX_VALID_NODE_ID */ -#include "cluster/cluster_tt_slot.h" /* TT_SLOTS_PER_SEGMENT + UBA typedef chain */ -#include "cluster/cluster_undo_segment.h" /* UNDO_BLOCKS_PER_SEGMENT */ +#include "cluster/cluster_scn.h" /* NodeId, SCN_MAX_VALID_NODE_ID */ +#include "cluster/cluster_tt_slot.h" /* TT_SLOTS_PER_SEGMENT + UBA typedef chain */ +#include "cluster/cluster_undo_segment.h" /* UNDO_BLOCKS_PER_SEGMENT */ #include "cluster/storage/cluster_undo_alloc.h" /* logical segment-range constants */ @@ -163,18 +163,16 @@ uba_decode(UBA u, uint32 *segment_id, uint32 *block_no, uint16 *tt_slot_offset, * only after every record-specific predicate succeeds. */ static inline bool -uba_decode_record(UBA u, uint32 *segment_id, uint32 *block_no, - uint16 *tt_slot_offset, uint16 *row_offset) +uba_decode_record(UBA u, uint32 *segment_id, uint32 *block_no, uint16 *tt_slot_offset, + uint16 *row_offset) { uint32 decoded_segment; uint32 decoded_block; uint16 decoded_slot; uint16 decoded_row; - const uint32 max_segment - = (uint32)UNDO_OWNER_INSTANCE_MAX * CLUSTER_UNDO_SEGS_PER_INSTANCE; + const uint32 max_segment = (uint32)UNDO_OWNER_INSTANCE_MAX * CLUSTER_UNDO_SEGS_PER_INSTANCE; - if (segment_id == NULL || block_no == NULL || tt_slot_offset == NULL - || row_offset == NULL) + if (segment_id == NULL || block_no == NULL || tt_slot_offset == NULL || row_offset == NULL) return false; if (!uba_decode(u, &decoded_segment, &decoded_block, &decoded_slot, &decoded_row)) return false; diff --git a/src/include/cluster/cluster_undo_format.h b/src/include/cluster/cluster_undo_format.h index 90f9283f4e8..0d0c11c6695 100644 --- a/src/include/cluster/cluster_undo_format.h +++ b/src/include/cluster/cluster_undo_format.h @@ -174,8 +174,8 @@ cluster_undo_record_slot_index_valid(uint16 slot_count, uint16 row_offset) static inline bool -cluster_undo_record_slot_range_valid(uint16 slot_count, uint16 row_offset, - uint32 record_offset, uint16 record_length) +cluster_undo_record_slot_range_valid(uint16 slot_count, uint16 row_offset, uint32 record_offset, + uint16 record_length) { uint64 directory_bytes = (uint64)slot_count * sizeof(UndoSlotDirEntry); uint64 record_end = (uint64)record_offset + (uint64)record_length; diff --git a/src/include/cluster/cluster_undo_record.h b/src/include/cluster/cluster_undo_record.h index d1ec01243ee..e34a4d0729b 100644 --- a/src/include/cluster/cluster_undo_record.h +++ b/src/include/cluster/cluster_undo_record.h @@ -429,7 +429,6 @@ cluster_undo_record_decode_payload(const UndoRecordHeader *record, const void *p uint8 expected_kind = ITL_FLAG_ACTIVE; size_t body_length; bool has_history; - unsigned i; if (body_length_out != NULL) *body_length_out = 0; @@ -519,6 +518,7 @@ cluster_undo_record_decode_payload(const UndoRecordHeader *record, const void *p uint32 block; uint16 tt; uint16 row; + unsigned i; if (record->target_block == InvalidBlockNumber || !OffsetNumberIsValid(record->target_offset) diff --git a/src/include/cluster/cluster_undo_retention.h b/src/include/cluster/cluster_undo_retention.h index 09fc13801e8..b55bd0b1c25 100644 --- a/src/include/cluster/cluster_undo_retention.h +++ b/src/include/cluster/cluster_undo_retention.h @@ -97,8 +97,8 @@ struct UndoSegmentHeaderData; extern bool cluster_tt_slot_recyclable(uint8 cts_status, SCN commit_scn, SCN horizon); extern bool cluster_undo_segment_recyclable(const struct UndoSegmentHeaderData *hdr, SCN horizon); -extern bool cluster_undo_segment_recyclable_for_mode( - const struct UndoSegmentHeaderData *hdr, SCN horizon, bool peer_mode); +extern bool cluster_undo_segment_recyclable_for_mode(const struct UndoSegmentHeaderData *hdr, + SCN horizon, bool peer_mode); /* diff --git a/src/include/cluster/cluster_undo_root_descriptor.h b/src/include/cluster/cluster_undo_root_descriptor.h index f2ede05e274..d45543f7860 100644 --- a/src/include/cluster/cluster_undo_root_descriptor.h +++ b/src/include/cluster/cluster_undo_root_descriptor.h @@ -23,24 +23,19 @@ #define CLUSTER_UNDO_ROOT_COUNT 129 #define CLUSTER_UNDO_ROOT_FILE_SLOTS 32768 #define CLUSTER_UNDO_ROOT_MAX_NAMESPACE (UINT64_MAX >> 15) -#define CLUSTER_UNDO_ROOT_DESCRIPTOR_SHARED_SLOT \ - (6 * CLUSTER_MAX_NODES + 2) -#define CLUSTER_UNDO_ROOT_DESCRIPTOR_LOCAL_SLOT(node_id) \ - (6 * CLUSTER_MAX_NODES + 3 + (node_id)) -#define CLUSTER_UNDO_ROOT_DESCRIPTOR_SHARED_OFFSET \ - ((off_t)CLUSTER_UNDO_ROOT_DESCRIPTOR_SHARED_SLOT \ - * CLUSTER_UNDO_ROOT_DESCRIPTOR_BYTES) -#define CLUSTER_UNDO_ROOT_DESCRIPTOR_LOCAL_OFFSET(node_id) \ - ((off_t)CLUSTER_UNDO_ROOT_DESCRIPTOR_LOCAL_SLOT(node_id) \ - * CLUSTER_UNDO_ROOT_DESCRIPTOR_BYTES) +#define CLUSTER_UNDO_ROOT_DESCRIPTOR_SHARED_SLOT (6 * CLUSTER_MAX_NODES + 2) +#define CLUSTER_UNDO_ROOT_DESCRIPTOR_LOCAL_SLOT(node_id) (6 * CLUSTER_MAX_NODES + 3 + (node_id)) +#define CLUSTER_UNDO_ROOT_DESCRIPTOR_SHARED_OFFSET \ + ((off_t)CLUSTER_UNDO_ROOT_DESCRIPTOR_SHARED_SLOT * CLUSTER_UNDO_ROOT_DESCRIPTOR_BYTES) +#define CLUSTER_UNDO_ROOT_DESCRIPTOR_LOCAL_OFFSET(node_id) \ + ((off_t)CLUSTER_UNDO_ROOT_DESCRIPTOR_LOCAL_SLOT(node_id) * CLUSTER_UNDO_ROOT_DESCRIPTOR_BYTES) /* * B′ P0 fix: keep in lockstep with CLUSTER_VOTING_PGRD_FILE_BYTES_MIN — * the attested capacity now also covers region 7 (cold-formation marker * slots [7N+3, 7N+3+N)) which follows the undo descriptors. */ -#define CLUSTER_UNDO_ROOT_DESCRIPTOR_FILE_BYTES_MIN \ - ((off_t)(8 * CLUSTER_MAX_NODES + 3) \ - * CLUSTER_UNDO_ROOT_DESCRIPTOR_BYTES) +#define CLUSTER_UNDO_ROOT_DESCRIPTOR_FILE_BYTES_MIN \ + ((off_t)(8 * CLUSTER_MAX_NODES + 3) * CLUSTER_UNDO_ROOT_DESCRIPTOR_BYTES) typedef enum ClusterUndoRootKind { CLUSTER_UNDO_ROOT_KIND_SHARED = 1, @@ -63,23 +58,20 @@ typedef struct ClusterUndoRootDescriptorV1 { uint64 system_identifier; } ClusterUndoRootDescriptorV1; -extern bool cluster_undo_root_namespace_id(uint64 descriptor_incarnation, - uint32 root_ordinal, - uint64 *namespace_id); -extern bool cluster_undo_root_file_slot(uint32 owner_instance, - uint32 segment_slot, - uint32 *file_slot); -extern bool cluster_undo_root_id(uint64 namespace_id, uint32 file_slot, - uint64 *root_id); -extern bool cluster_undo_root_descriptor_encode( - const ClusterUndoRootDescriptorV1 *descriptor, - uint8 out[CLUSTER_UNDO_ROOT_DESCRIPTOR_BYTES]); -extern ClusterUndoRootDescriptorState cluster_undo_root_descriptor_decode( - const uint8 bytes[CLUSTER_UNDO_ROOT_DESCRIPTOR_BYTES], - uint64 expected_system_identifier, ClusterUndoRootDescriptorV1 *out); -extern bool cluster_undo_root_descriptor_resolve( - const ClusterUndoRootDescriptorV1 *descriptor, - ClusterUndoPathIntent intent, uint32 owner_instance, uint32 segment_id, - ClusterUndoBlock0ResolvedRoot *out); +extern bool cluster_undo_root_namespace_id(uint64 descriptor_incarnation, uint32 root_ordinal, + uint64 *namespace_id); +extern bool cluster_undo_root_file_slot(uint32 owner_instance, uint32 segment_slot, + uint32 *file_slot); +extern bool cluster_undo_root_id(uint64 namespace_id, uint32 file_slot, uint64 *root_id); +extern bool cluster_undo_root_descriptor_encode(const ClusterUndoRootDescriptorV1 *descriptor, + uint8 out[CLUSTER_UNDO_ROOT_DESCRIPTOR_BYTES]); +extern ClusterUndoRootDescriptorState +cluster_undo_root_descriptor_decode(const uint8 bytes[CLUSTER_UNDO_ROOT_DESCRIPTOR_BYTES], + uint64 expected_system_identifier, + ClusterUndoRootDescriptorV1 *out); +extern bool cluster_undo_root_descriptor_resolve(const ClusterUndoRootDescriptorV1 *descriptor, + ClusterUndoPathIntent intent, + uint32 owner_instance, uint32 segment_id, + ClusterUndoBlock0ResolvedRoot *out); #endif /* CLUSTER_UNDO_ROOT_DESCRIPTOR_H */ diff --git a/src/include/cluster/cluster_undo_smgr.h b/src/include/cluster/cluster_undo_smgr.h index 0eda9c6d12a..06b45d51802 100644 --- a/src/include/cluster/cluster_undo_smgr.h +++ b/src/include/cluster/cluster_undo_smgr.h @@ -132,20 +132,22 @@ typedef enum ClusterUndoSmgrPublishResult { CLUSTER_UNDO_SMGR_PUBLISH_IO_ERROR } ClusterUndoSmgrPublishResult; -extern ClusterUndoSmgrFinalState cluster_undo_smgr_probe_segment( - ClusterUndoPathIntent intent, uint32 segment_id, uint8 owner_instance, - char block0[BLCKSZ]); -extern bool cluster_undo_smgr_provision_temp_create( - ClusterUndoPathIntent intent, uint32 segment_id, uint8 owner_instance, - char temp_path[MAXPGPATH]); -extern ClusterUndoSmgrPublishResult cluster_undo_smgr_provision_temp_publish( - ClusterUndoPathIntent intent, uint32 segment_id, uint8 owner_instance, - const char *temp_path, const char block0[BLCKSZ]); -extern bool cluster_undo_smgr_provision_temp_cleanup( - ClusterUndoPathIntent intent, uint32 segment_id, uint8 owner_instance, - const char *temp_path); -extern bool cluster_undo_smgr_cleanup_boot_foreign_temps( - ClusterUndoPathIntent intent, uint8 owner_instance); +extern ClusterUndoSmgrFinalState cluster_undo_smgr_probe_segment(ClusterUndoPathIntent intent, + uint32 segment_id, + uint8 owner_instance, + char block0[BLCKSZ]); +extern bool cluster_undo_smgr_provision_temp_create(ClusterUndoPathIntent intent, uint32 segment_id, + uint8 owner_instance, + char temp_path[MAXPGPATH]); +extern ClusterUndoSmgrPublishResult +cluster_undo_smgr_provision_temp_publish(ClusterUndoPathIntent intent, uint32 segment_id, + uint8 owner_instance, const char *temp_path, + const char block0[BLCKSZ]); +extern bool cluster_undo_smgr_provision_temp_cleanup(ClusterUndoPathIntent intent, + uint32 segment_id, uint8 owner_instance, + const char *temp_path); +extern bool cluster_undo_smgr_cleanup_boot_foreign_temps(ClusterUndoPathIntent intent, + uint8 owner_instance); /* * A-prime immutable root-descriptor applicability mirror. root_directory is @@ -160,16 +162,15 @@ typedef enum ClusterUndoSmgrRootMirrorState { CLUSTER_UNDO_SMGR_ROOT_MIRROR_IO_ERROR } ClusterUndoSmgrRootMirrorState; -extern ClusterUndoSmgrRootMirrorState cluster_undo_smgr_root_descriptor_probe( - const char *root_directory, - const uint8 expected[CLUSTER_UNDO_ROOT_DESCRIPTOR_BYTES], - uint8 observed[CLUSTER_UNDO_ROOT_DESCRIPTOR_BYTES]); +extern ClusterUndoSmgrRootMirrorState +cluster_undo_smgr_root_descriptor_probe(const char *root_directory, + const uint8 expected[CLUSTER_UNDO_ROOT_DESCRIPTOR_BYTES], + uint8 observed[CLUSTER_UNDO_ROOT_DESCRIPTOR_BYTES]); extern ClusterUndoSmgrRootMirrorState cluster_undo_smgr_root_descriptor_read_candidate( - const char *root_directory, - uint8 observed[CLUSTER_UNDO_ROOT_DESCRIPTOR_BYTES]); -extern ClusterUndoSmgrRootMirrorState cluster_undo_smgr_root_descriptor_publish( - const char *root_directory, - const uint8 image[CLUSTER_UNDO_ROOT_DESCRIPTOR_BYTES]); + const char *root_directory, uint8 observed[CLUSTER_UNDO_ROOT_DESCRIPTOR_BYTES]); +extern ClusterUndoSmgrRootMirrorState +cluster_undo_smgr_root_descriptor_publish(const char *root_directory, + const uint8 image[CLUSTER_UNDO_ROOT_DESCRIPTOR_BYTES]); /* diff --git a/src/include/cluster/cluster_undo_verdict.h b/src/include/cluster/cluster_undo_verdict.h index e0e09a1777a..7945d29e270 100644 --- a/src/include/cluster/cluster_undo_verdict.h +++ b/src/include/cluster/cluster_undo_verdict.h @@ -144,18 +144,15 @@ extern ClusterUndoVerdictResult cluster_undo_verdict_from_resolve(bool ok, bool * 6.12i P0); the positive-proof gates are unchanged. Derived (recycled) callers * pass false to keep cluster_xid_is_mine. Compiled only in --enable-cluster builds. */ -extern ClusterUndoVerdictResult cluster_undo_verdict_resolve(int origin_node, - uint32 undo_segment_id, - TransactionId raw_xid, - uint32 expected_tt_slot_id, SCN read_scn, - bool authoritative); +extern ClusterUndoVerdictResult +cluster_undo_verdict_resolve(int origin_node, uint32 undo_segment_id, TransactionId raw_xid, + uint32 expected_tt_slot_id, SCN read_scn, bool authoritative); /* S8-815PRE-FRESHREF-C1B-01: exact retained-page pairing entry. It is * remote/live-origin only and can return COMMITTED_EXACT only when the * current ref tuple, origin C1b and native no-reuse fence all agree. */ extern ClusterUndoVerdictResult cluster_undo_verdict_resolve_freshref_c1b_pair( - int origin_node, uint32 undo_segment_id, TransactionId raw_xid, - TransactionId ref_xid, uint32 expected_tt_slot_id, uint32 ref_epoch, - SCN cached_commit_scn, SCN read_scn); + int origin_node, uint32 undo_segment_id, TransactionId raw_xid, TransactionId ref_xid, + uint32 expected_tt_slot_id, uint32 ref_epoch, SCN cached_commit_scn, SCN read_scn); #endif /* CLUSTER_UNDO_VERDICT_H */ diff --git a/src/include/cluster/cluster_visibility_resolve.h b/src/include/cluster/cluster_visibility_resolve.h index fca85dacc6e..25308402a54 100644 --- a/src/include/cluster/cluster_visibility_resolve.h +++ b/src/include/cluster/cluster_visibility_resolve.h @@ -57,7 +57,7 @@ #include "cluster/cluster_scn.h" /* SCN */ #include "cluster/cluster_tt_slot.h" /* ClusterUndoTTSlotRef */ #include "cluster/cluster_tt_status.h" /* ClusterTTStatus */ -#include "cluster/cluster_tx_resolve.h" /* ClusterTxLocator */ +#include "cluster/cluster_tx_resolve.h" /* ClusterTxLocator */ #include "cluster/cluster_undo_verdict.h" /* ClusterUndoVerdictResult (spec-5.22f D6) */ @@ -94,9 +94,9 @@ typedef enum ClusterVisEvidence { typedef struct ClusterVisResolve { ClusterVisEvidence evidence; - ClusterTTStatus status; /* valid when evidence == REMOTE */ - SCN commit_scn; /* valid for COMMITTED / CLEANED_OUT */ - bool commit_scn_is_bound; /* spec-6.12i CP5: commit_scn is a HORIZON + ClusterTTStatus status; /* valid when evidence == REMOTE */ + SCN commit_scn; /* valid for COMMITTED / CLEANED_OUT */ + bool commit_scn_is_bound; /* spec-6.12i CP5: commit_scn is a HORIZON * BOUND from a below-horizon verdict, not * the exact commit_scn. It decides * correctly against the read_scn this @@ -105,14 +105,14 @@ typedef struct ClusterVisResolve { * exact scn (a later smaller read_scn * would read it as committed-after -> * false-invisible, Rule 8.A). */ - ClusterUndoTTSlotRef ref; /* copied exact ref (REMOTE/LOCAL/STALE) */ + ClusterUndoTTSlotRef ref; /* copied exact ref (REMOTE/LOCAL/STALE) */ /* Stage-8 PRE adjustment 23: a wait consumer may use only the exact * page-derived DATA locator captured under the same content lock as the * verdict. The ref/raw xid is never promoted into a remote wait key. */ bool row_wait_locator_valid; ClusterTxLocator row_wait_locator; - uint16 multi_marker_origin; /* XMAX_MULTI: origin node of marker, else 0 */ - bool multi_marker_is_remote; /* XMAX_MULTI: marker hit + origin != self */ + uint16 multi_marker_origin; /* XMAX_MULTI: origin node of marker, else 0 */ + bool multi_marker_is_remote; /* XMAX_MULTI: marker hit + origin != self */ const char *diagnostic_reason; /* static diagnostic text, not proof or wire */ } ClusterVisResolve; @@ -220,8 +220,7 @@ typedef enum ClusterVisNativeSelfUpdateVerdict { } ClusterVisNativeSelfUpdateVerdict; extern ClusterVisNativeSelfUpdateVerdict -cluster_vis_update_native_self_verdict(bool lock_only, - bool cmax_at_or_after_curcid); +cluster_vis_update_native_self_verdict(bool lock_only, bool cmax_at_or_after_curcid); /* * spec-3.21 §2.3: CR image xmax-side MVCC visibility verdict. @@ -253,9 +252,8 @@ extern ClusterVisVerdict cluster_vis_dirty_verdict(ClusterTTStatus status, bool /* The base OBS-3 verdict remains fail-closed. Only the typed unique-index * owner may turn an exact remote IN_PROGRESS xmax into an unlocked wait. */ -extern bool cluster_vis_dirty_remote_xmax_waitable(ClusterTTStatus status, - bool is_xmax, - bool exact_locator_valid); +extern bool cluster_vis_dirty_remote_xmax_waitable(ClusterTTStatus status, bool is_xmax, + bool exact_locator_valid); /* diff --git a/src/include/cluster/cluster_voting_disk_io.h b/src/include/cluster/cluster_voting_disk_io.h index 93e1a784f83..18c960a218a 100644 --- a/src/include/cluster/cluster_voting_disk_io.h +++ b/src/include/cluster/cluster_voting_disk_io.h @@ -147,7 +147,8 @@ * (JCMK coordinator-write pattern). Payload = ClusterFormationCommitMarker * (magic "PGFM"); this layer is payload-agnostic aligned raw slot I/O. */ -#define CLUSTER_VOTING_FORMATION_SLOT_OFFSET(node_id) ((off_t) (7 * CLUSTER_MAX_NODES + 3 + (node_id)) * CLUSTER_VOTING_SLOT_BYTES) +#define CLUSTER_VOTING_FORMATION_SLOT_OFFSET(node_id) \ + ((off_t)(7 * CLUSTER_MAX_NODES + 3 + (node_id)) * CLUSTER_VOTING_SLOT_BYTES) /* * spec-8.4 / spec-5.15A — PGSA occupies fixed slot 5N+1. One 512-byte @@ -319,12 +320,10 @@ extern ClusterVotingDiskIoState cluster_voting_disk_write_join_slot(int fd, uint * magic/version/CRC. Same per-I/O timeout discipline and fail-closed * empty semantics as the join-slot path. */ -extern ClusterVotingDiskIoState cluster_voting_disk_read_formation_slot(int fd, - uint32 node_id, - void *out_slot512); -extern ClusterVotingDiskIoState cluster_voting_disk_write_formation_slot(int fd, - uint32 node_id, - const void *in_slot512); +extern ClusterVotingDiskIoState cluster_voting_disk_read_formation_slot(int fd, uint32 node_id, + void *out_slot512); +extern ClusterVotingDiskIoState cluster_voting_disk_write_formation_slot(int fd, uint32 node_id, + const void *in_slot512); /* * spec-6.4 D7 — raw 512-byte ADG apply-master lease slot R/W in region 4. @@ -365,20 +364,19 @@ extern ClusterVotingDiskIoState cluster_voting_disk_write_stripe_activation(int * Fixed PGSA slot. The offset is deliberately not a caller parameter. A * full all-zero page remains FULL; payload policy belongs to the caller. */ -extern ClusterVotingDiskRawReadState -cluster_voting_disk_read_raw_tail_slot(int fd, void *out_slot512); -extern ClusterVotingDiskIoState -cluster_voting_disk_write_raw_tail_slot(int fd, const void *in_slot512); +extern ClusterVotingDiskRawReadState cluster_voting_disk_read_raw_tail_slot(int fd, + void *out_slot512); +extern ClusterVotingDiskIoState cluster_voting_disk_write_raw_tail_slot(int fd, + const void *in_slot512); /* Payload-neutral aligned raw-sector I/O at a caller-selected frozen offset. * The offset must be nonnegative and exactly 512-byte aligned. Payload * validation, fixed-slot ownership, readback comparison and quorum counting * remain with the authority layer. */ -extern ClusterVotingDiskRawReadState -cluster_voting_disk_read_raw_slot_at(int fd, off_t offset, void *out_slot512); -extern ClusterVotingDiskIoState -cluster_voting_disk_write_raw_slot_at(int fd, off_t offset, - const void *in_slot512); +extern ClusterVotingDiskRawReadState cluster_voting_disk_read_raw_slot_at(int fd, off_t offset, + void *out_slot512); +extern ClusterVotingDiskIoState cluster_voting_disk_write_raw_slot_at(int fd, off_t offset, + const void *in_slot512); /* * Raw node-indexed epoch-ballot lane I/O. This is a dedicated synchronous @@ -388,9 +386,9 @@ cluster_voting_disk_write_raw_slot_at(int fd, off_t offset, */ extern ClusterVotingDiskIoState cluster_voting_disk_read_epoch_ballot_slot(int fd, uint32 proposer_node_id, void *out_slot512); -extern ClusterVotingDiskIoState -cluster_voting_disk_write_epoch_ballot_slot(int fd, uint32 proposer_node_id, - const void *in_slot512); +extern ClusterVotingDiskIoState cluster_voting_disk_write_epoch_ballot_slot(int fd, + uint32 proposer_node_id, + const void *in_slot512); /* Positive common-epoch ballot authority is Linux raw-block only. Regular * files remain valid codec/I/O fixtures but can never pass this attestation. */ diff --git a/src/include/cluster/cluster_wal_retention.h b/src/include/cluster/cluster_wal_retention.h index b42d407e2fe..6e7693fc030 100644 --- a/src/include/cluster/cluster_wal_retention.h +++ b/src/include/cluster/cluster_wal_retention.h @@ -288,16 +288,13 @@ typedef struct ClusterWalReuseGuardRequest { const ClusterFormationWitnessV1 *formation; } ClusterWalReuseGuardRequest; -StaticAssertDecl(sizeof(ClusterWalFileIdentity) == 16, - "ClusterWalFileIdentity must be 16 bytes"); +StaticAssertDecl(sizeof(ClusterWalFileIdentity) == 16, "ClusterWalFileIdentity must be 16 bytes"); StaticAssertDecl(offsetof(ClusterWalFileIdentity, thread_id) == 0, "ClusterWalFileIdentity thread offset"); -StaticAssertDecl(offsetof(ClusterWalFileIdentity, kind) == 2, - "ClusterWalFileIdentity kind offset"); +StaticAssertDecl(offsetof(ClusterWalFileIdentity, kind) == 2, "ClusterWalFileIdentity kind offset"); StaticAssertDecl(offsetof(ClusterWalFileIdentity, reserved_zero) == 3, "ClusterWalFileIdentity reserved offset"); -StaticAssertDecl(offsetof(ClusterWalFileIdentity, tli) == 4, - "ClusterWalFileIdentity TLI offset"); +StaticAssertDecl(offsetof(ClusterWalFileIdentity, tli) == 4, "ClusterWalFileIdentity TLI offset"); StaticAssertDecl(offsetof(ClusterWalFileIdentity, segno) == 8, "ClusterWalFileIdentity segment offset"); StaticAssertDecl(sizeof(ClusterWalRetentionInterval) == 24, @@ -311,131 +308,124 @@ StaticAssertDecl(offsetof(ClusterWalRetentionInterval, start_lsn) == 8, StaticAssertDecl(offsetof(ClusterWalRetentionInterval, end_lsn) == 16, "ClusterWalRetentionInterval end offset"); -extern bool cluster_wal_thread_directory_parse(const char *basename, - uint16 *out_thread_id); -extern bool cluster_wal_file_identity_parse(const char *basename, - uint16 thread_id, int wal_segsz_bytes, - ClusterWalFileIdentity *out_identity); +extern bool cluster_wal_thread_directory_parse(const char *basename, uint16 *out_thread_id); +extern bool cluster_wal_file_identity_parse(const char *basename, uint16 thread_id, + int wal_segsz_bytes, + ClusterWalFileIdentity *out_identity); extern bool cluster_wal_file_identity_valid(const ClusterWalFileIdentity *identity, - int wal_segsz_bytes); -extern bool cluster_wal_file_long_header_matches( - const ClusterWalFileIdentity *identity, const XLogLongPageHeaderData *header, - uint64 system_identifier, int wal_segsz_bytes); -extern bool cluster_wal_retention_interval_segment_bounds( - const ClusterWalRetentionInterval *interval, int wal_segsz_bytes, - XLogSegNo *out_first, XLogSegNo *out_last); -extern bool cluster_wal_retention_interval_intersects_file( - const ClusterWalRetentionInterval *interval, - const ClusterWalFileIdentity *identity, int wal_segsz_bytes); -extern bool cluster_wal_retention_resid_encode(uint16 thread_id, - ClusterResId *out_resid); -extern ClusterWalPinResult cluster_wal_retention_pin_acquire( - const ClusterWalRetentionPinThreadRequest *requests, uint16 nthreads, - ClusterWalRetentionPin **out_pin); -extern ClusterWalPinResult cluster_wal_retention_pin_bind_one( - ClusterWalRetentionPin *pin, ClusterRecoverySerialGuard *held_serial); -extern ClusterWalPinResult cluster_wal_retention_pin_bind_set( - ClusterWalRetentionPin *pin, ClusterRecoverySerialGuardSet *held_set); + int wal_segsz_bytes); +extern bool cluster_wal_file_long_header_matches(const ClusterWalFileIdentity *identity, + const XLogLongPageHeaderData *header, + uint64 system_identifier, int wal_segsz_bytes); +extern bool +cluster_wal_retention_interval_segment_bounds(const ClusterWalRetentionInterval *interval, + int wal_segsz_bytes, XLogSegNo *out_first, + XLogSegNo *out_last); +extern bool +cluster_wal_retention_interval_intersects_file(const ClusterWalRetentionInterval *interval, + const ClusterWalFileIdentity *identity, + int wal_segsz_bytes); +extern bool cluster_wal_retention_resid_encode(uint16 thread_id, ClusterResId *out_resid); extern ClusterWalPinResult -cluster_wal_retention_pin_preflight_revalidate_wait_v1( - ClusterWalRetentionPin *pin); -extern ClusterWalPinResult cluster_wal_retention_pin_revalidate( - ClusterWalRetentionPin *pin); -extern ClusterWalPinResult cluster_wal_retention_pin_seal_for_root_publish( - ClusterWalRetentionPin *pin); +cluster_wal_retention_pin_acquire(const ClusterWalRetentionPinThreadRequest *requests, + uint16 nthreads, ClusterWalRetentionPin **out_pin); +extern ClusterWalPinResult +cluster_wal_retention_pin_bind_one(ClusterWalRetentionPin *pin, + ClusterRecoverySerialGuard *held_serial); +extern ClusterWalPinResult +cluster_wal_retention_pin_bind_set(ClusterWalRetentionPin *pin, + ClusterRecoverySerialGuardSet *held_set); +extern ClusterWalPinResult +cluster_wal_retention_pin_preflight_revalidate_wait_v1(ClusterWalRetentionPin *pin); +extern ClusterWalPinResult cluster_wal_retention_pin_revalidate(ClusterWalRetentionPin *pin); +extern ClusterWalPinResult +cluster_wal_retention_pin_seal_for_root_publish(ClusterWalRetentionPin *pin); extern ClusterWalPinResult cluster_wal_retention_pin_adopt_root_readback_v1( - ClusterWalRetentionPin *pin, - const ClusterControlRootSnapshot *expected_snapshot, + ClusterWalRetentionPin *pin, const ClusterControlRootSnapshot *expected_snapshot, const ClusterControlRootReadToken *expected_token, const ClusterControlRootSnapshot *observed_snapshot, const ClusterControlRootReadToken *observed_token); -extern ClusterWalrReleaseResult cluster_wal_retention_pin_release( - ClusterWalRetentionPin **pin); -extern ClusterWalPinResult cluster_wal_retention_root_publish_begin_exact( - const ClusterControlRootReadToken *expected_root, bool require_sealed_pin, - ClusterWalRootPublishGuard **out_guard); -extern ClusterWalrReleaseResult cluster_wal_retention_root_publish_end( - ClusterWalRootPublishGuard **guard); -extern ClusterWalReuseGuardResult cluster_wal_retention_e1_coarse_begin( - ClusterWalRetentionE1Context *context, uint16 thread_id, - ClusterWalRootFoldResult *out_fold_result, XLogSegNo *out_floor_segno, - ClusterWalReuseDenyReason *out_reason); -extern ClusterWalrReleaseResult cluster_wal_retention_e1_coarse_release( - ClusterWalRetentionE1Context *context, - ClusterWalReuseDenyReason *out_reason); +extern ClusterWalrReleaseResult cluster_wal_retention_pin_release(ClusterWalRetentionPin **pin); +extern ClusterWalPinResult +cluster_wal_retention_root_publish_begin_exact(const ClusterControlRootReadToken *expected_root, + bool require_sealed_pin, + ClusterWalRootPublishGuard **out_guard); +extern ClusterWalrReleaseResult +cluster_wal_retention_root_publish_end(ClusterWalRootPublishGuard **guard); +extern ClusterWalReuseGuardResult +cluster_wal_retention_e1_coarse_begin(ClusterWalRetentionE1Context *context, uint16 thread_id, + ClusterWalRootFoldResult *out_fold_result, + XLogSegNo *out_floor_segno, + ClusterWalReuseDenyReason *out_reason); +extern ClusterWalrReleaseResult +cluster_wal_retention_e1_coarse_release(ClusterWalRetentionE1Context *context, + ClusterWalReuseDenyReason *out_reason); extern ClusterWalReuseGuardResult cluster_wal_retention_e1_preflight( - ClusterWalRetentionE1Context *context, - const ClusterWalFileIdentity *file, ClusterWalReuseActionGuard *guard, - PgracExternalFenceNeedSetV1 **out_needs, + ClusterWalRetentionE1Context *context, const ClusterWalFileIdentity *file, + ClusterWalReuseActionGuard *guard, PgracExternalFenceNeedSetV1 **out_needs, ClusterWalReuseDenyReason *out_reason); extern bool cluster_wal_retention_active_pin_present(void); -extern ClusterWalReuseGuardResult cluster_wal_retention_action_begin( - ClusterWalRetentionE1Context *context, uint16 thread_id, - ClusterWalReuseDenyReason *out_reason); +extern ClusterWalReuseGuardResult +cluster_wal_retention_action_begin(ClusterWalRetentionE1Context *context, uint16 thread_id, + ClusterWalReuseDenyReason *out_reason); extern ClusterWalReuseGuardResult cluster_wal_retention_action_preflight( - ClusterWalRetentionE1Context *context, - const ClusterWalFileIdentity *file, ClusterWalReuseEntry entry, - ClusterWalReuseActionGuard *guard, - PgracExternalFenceNeedSetV1 **out_needs, - ClusterWalReuseDenyReason *out_reason); -extern void cluster_wal_retention_action_finish( - ClusterWalRetentionE1Context *context); + ClusterWalRetentionE1Context *context, const ClusterWalFileIdentity *file, + ClusterWalReuseEntry entry, ClusterWalReuseActionGuard *guard, + PgracExternalFenceNeedSetV1 **out_needs, ClusterWalReuseDenyReason *out_reason); +extern void cluster_wal_retention_action_finish(ClusterWalRetentionE1Context *context); extern ClusterWalReuseGuardResult cluster_wal_retention_e1_fence_wait( ClusterWalRetentionE1Context *context, ClusterWalReuseActionGuard *guard, - PgracExternalFenceNeedSetV1 *needs, - PgracExternalFenceAdmissionSetV1 **out_admissions, - ClusterWalReuseDenyReason *out_reason); -extern void cluster_wal_retention_e1_finish( - ClusterWalRetentionE1Context *context); -extern ClusterWalReuseGuardResult cluster_wal_reuse_guard_init( - ClusterWalReuseActionGuard *guard, ClusterWalReuseDenyReason *out_reason); -extern ClusterWalReuseGuardResult cluster_wal_reuse_guard_preflight( - ClusterWalReuseActionGuard *guard, - const ClusterWalReuseGuardRequest *request, - PgracExternalFenceNeedSetV1 **out_needs, + PgracExternalFenceNeedSetV1 *needs, PgracExternalFenceAdmissionSetV1 **out_admissions, ClusterWalReuseDenyReason *out_reason); +extern void cluster_wal_retention_e1_finish(ClusterWalRetentionE1Context *context); extern ClusterWalReuseGuardResult -cluster_wal_reuse_guard_preflight_active_recovery( - ClusterWalReuseActionGuard *guard, - const ClusterWalFileIdentity *file, ClusterWalReuseEntry entry, - ClusterRecoverySerialGuard **out_serial, - ClusterWalRetentionPin **out_pin, - ClusterWalReuseDenyReason *out_reason); +cluster_wal_reuse_guard_init(ClusterWalReuseActionGuard *guard, + ClusterWalReuseDenyReason *out_reason); +extern ClusterWalReuseGuardResult cluster_wal_reuse_guard_preflight( + ClusterWalReuseActionGuard *guard, const ClusterWalReuseGuardRequest *request, + PgracExternalFenceNeedSetV1 **out_needs, ClusterWalReuseDenyReason *out_reason); +extern ClusterWalReuseGuardResult cluster_wal_reuse_guard_preflight_active_recovery( + ClusterWalReuseActionGuard *guard, const ClusterWalFileIdentity *file, + ClusterWalReuseEntry entry, ClusterRecoverySerialGuard **out_serial, + ClusterWalRetentionPin **out_pin, ClusterWalReuseDenyReason *out_reason); extern ClusterWalReuseGuardResult cluster_wal_reuse_guard_fence_admitted_nowait( - ClusterWalReuseActionGuard *guard, - const PgracExternalFenceAdmissionSetV1 *admissions_or_null, + ClusterWalReuseActionGuard *guard, const PgracExternalFenceAdmissionSetV1 *admissions_or_null, ClusterWalReuseDenyReason *out_reason); extern ClusterWalReuseGuardResult cluster_wal_reuse_guard_arm( - ClusterWalReuseActionGuard *guard, - ClusterRecoverySerialGuard *held_serial_or_null, - ClusterWalRetentionPin *held_pin_or_null, - ClusterWalReuseDenyReason *out_reason); -extern ClusterWalReuseGuardResult cluster_wal_reuse_guard_l3_begin( - ClusterWalReuseActionGuard *guard, ClusterWalReusePhysicalAction physical, - ClusterWalReuseDenyReason *out_reason); -extern ClusterWalReuseGuardResult cluster_wal_reuse_guard_note_zero_mutation( - ClusterWalReuseActionGuard *guard, ClusterWalReusePhysicalAction physical, - ClusterWalReuseDenyReason *out_reason); -extern ClusterWalReuseGuardResult cluster_wal_reuse_guard_confirm_zero_mutation( - ClusterWalReuseActionGuard *guard, ClusterWalReusePhysicalAction physical, - ClusterWalReuseDenyReason *out_reason); -extern ClusterWalReuseGuardResult cluster_wal_reuse_guard_terminal_durable( - ClusterWalReuseActionGuard *guard, ClusterWalTerminalOutcome outcome, - ClusterWalReuseDenyReason *out_reason); -extern ClusterWalReuseGuardResult cluster_wal_reuse_guard_remove( - ClusterWalReuseActionGuard *guard, - ClusterWalReuseDenyReason *out_reason); -extern ClusterWalReuseGuardResult cluster_wal_reuse_guard_recycle( - ClusterWalReuseActionGuard *guard, - const ClusterWalFileIdentity *destination, - ClusterWalReuseDenyReason *out_reason); -extern ClusterWalReuseGuardResult cluster_wal_reuse_guard_bookkeep( - ClusterWalReuseActionGuard *guard, ClusterWalReuseDenyReason *out_reason); -extern ClusterWalrReleaseResult cluster_wal_reuse_guard_finish( - ClusterWalReuseActionGuard *guard, ClusterWalTerminalOutcome *out_outcome, - ClusterWalReuseDenyReason *out_reason); -extern bool cluster_wal_retention_fold_validated_roots( - const ClusterWalRootFoldInput *inputs, uint16 nslots, int wal_segsz_bytes, - ClusterWalRootFold *out_fold); + ClusterWalReuseActionGuard *guard, ClusterRecoverySerialGuard *held_serial_or_null, + ClusterWalRetentionPin *held_pin_or_null, ClusterWalReuseDenyReason *out_reason); +extern ClusterWalReuseGuardResult +cluster_wal_reuse_guard_l3_begin(ClusterWalReuseActionGuard *guard, + ClusterWalReusePhysicalAction physical, + ClusterWalReuseDenyReason *out_reason); +extern ClusterWalReuseGuardResult +cluster_wal_reuse_guard_note_zero_mutation(ClusterWalReuseActionGuard *guard, + ClusterWalReusePhysicalAction physical, + ClusterWalReuseDenyReason *out_reason); +extern ClusterWalReuseGuardResult +cluster_wal_reuse_guard_confirm_zero_mutation(ClusterWalReuseActionGuard *guard, + ClusterWalReusePhysicalAction physical, + ClusterWalReuseDenyReason *out_reason); +extern ClusterWalReuseGuardResult +cluster_wal_reuse_guard_terminal_durable(ClusterWalReuseActionGuard *guard, + ClusterWalTerminalOutcome outcome, + ClusterWalReuseDenyReason *out_reason); +extern ClusterWalReuseGuardResult +cluster_wal_reuse_guard_remove(ClusterWalReuseActionGuard *guard, + ClusterWalReuseDenyReason *out_reason); +extern ClusterWalReuseGuardResult +cluster_wal_reuse_guard_recycle(ClusterWalReuseActionGuard *guard, + const ClusterWalFileIdentity *destination, + ClusterWalReuseDenyReason *out_reason); +extern ClusterWalReuseGuardResult +cluster_wal_reuse_guard_bookkeep(ClusterWalReuseActionGuard *guard, + ClusterWalReuseDenyReason *out_reason); +extern ClusterWalrReleaseResult +cluster_wal_reuse_guard_finish(ClusterWalReuseActionGuard *guard, + ClusterWalTerminalOutcome *out_outcome, + ClusterWalReuseDenyReason *out_reason); +extern bool cluster_wal_retention_fold_validated_roots(const ClusterWalRootFoldInput *inputs, + uint16 nslots, int wal_segsz_bytes, + ClusterWalRootFold *out_fold); #endif /* CLUSTER_WAL_RETENTION_H */ diff --git a/src/include/cluster/cluster_wal_state.h b/src/include/cluster/cluster_wal_state.h index 565560f6d9b..da16232325d 100644 --- a/src/include/cluster/cluster_wal_state.h +++ b/src/include/cluster/cluster_wal_state.h @@ -355,8 +355,7 @@ cluster_wal_state_image_validate(const void *image, size_t image_size, uint16 *b const char *slot_reason = NULL; memcpy(&slot, bytes + CLUSTER_WAL_STATE_SLOT_SIZE * (i + 1), sizeof(slot)); - verdict = cluster_wal_state_slot_classify(&slot, (uint16)(i + 1), -1, - &slot_reason); + verdict = cluster_wal_state_slot_classify(&slot, (uint16)(i + 1), -1, &slot_reason); if (verdict != CLUSTER_WAL_SLOT_EMPTY && verdict != CLUSTER_WAL_SLOT_OK) { bad_thread = (uint16)(i + 1); reason = slot_reason != NULL ? slot_reason : "invalid slot"; @@ -401,9 +400,8 @@ cluster_wal_state_slot_verdict_to_update_result(ClusterWalSlotVerdict verdict) * Other updates require ACTIVE; STOPPED is idempotent. */ static inline ClusterWalStateUpdateResult -cluster_wal_state_slot_prepare_update(const ClusterWalStateSlot *fresh_before, - uint16 expect_thread, int32 expect_node, - const ClusterWalStateUpdate *update, +cluster_wal_state_slot_prepare_update(const ClusterWalStateSlot *fresh_before, uint16 expect_thread, + int32 expect_node, const ClusterWalStateUpdate *update, ClusterWalStateSlot *expected_after) { ClusterWalSlotVerdict verdict; @@ -413,15 +411,13 @@ cluster_wal_state_slot_prepare_update(const ClusterWalStateSlot *fresh_before, || expect_node < 0) return CLUSTER_WAL_STATE_UPDATE_INVALID; - verdict - = cluster_wal_state_slot_classify(fresh_before, expect_thread, expect_node, NULL); + verdict = cluster_wal_state_slot_classify(fresh_before, expect_thread, expect_node, NULL); if (verdict == CLUSTER_WAL_SLOT_EMPTY) { if (update->kind != CLUSTER_WAL_STATE_UPDATE_ACTIVE) return CLUSTER_WAL_STATE_UPDATE_EMPTY; cluster_wal_state_slot_fill(expected_after, expect_thread, expect_node, - CLUSTER_WAL_SLOT_STATE_ACTIVE, update->tli, - update->started_at, update->last_updated, - update->highest_lsn, update->highest_scn); + CLUSTER_WAL_SLOT_STATE_ACTIVE, update->tli, update->started_at, + update->last_updated, update->highest_lsn, update->highest_scn); expected_after->refresh_interval_ms = update->refresh_interval_ms; expected_after->merge_recovered_lsn = 0; expected_after->crc = cluster_wal_state_block_crc(expected_after); @@ -532,9 +528,9 @@ extern void cluster_wal_state_mark_fpw_off(void); extern void cluster_wal_state_refresh_own_slot(void); /* RF A1 sole formed-registry mutation engine. */ -extern ClusterWalStateUpdateResult cluster_wal_state_update_own( - const ClusterWalStateUpdate *update, ClusterWalStateCfMode cf_mode, - ClusterWalStateSlot *published_slot); +extern ClusterWalStateUpdateResult +cluster_wal_state_update_own(const ClusterWalStateUpdate *update, ClusterWalStateCfMode cf_mode, + ClusterWalStateSlot *published_slot); /* Reader: pread + classify slot `thread_id` (1..128). Returns the * verdict; on OK fills *slot_out. */ diff --git a/src/include/cluster/cluster_write_fence.h b/src/include/cluster/cluster_write_fence.h index 1273fa03b26..23e18ecb79e 100644 --- a/src/include/cluster/cluster_write_fence.h +++ b/src/include/cluster/cluster_write_fence.h @@ -191,8 +191,7 @@ typedef struct ClusterFenceAuthorityProof { uint32 total_disk_count; } ClusterFenceAuthorityProof; -StaticAssertDecl(sizeof(ClusterFenceAuthorityProof) == 72, - "ClusterFenceAuthorityProof ABI"); +StaticAssertDecl(sizeof(ClusterFenceAuthorityProof) == 72, "ClusterFenceAuthorityProof ABI"); /* Internal one-vote-per-physical-disk input to the pure total selector. */ typedef enum ClusterFenceDiskVoteState { @@ -282,14 +281,12 @@ cluster_fence_marker_valid_v1(const ClusterFenceMarker *m) return m->fence_event_id == 0 && m->fence_generation == 0; return m->issuer_node_id >= 0 && m->issuer_node_id < CLUSTER_FENCE_MARKER_DEAD_BITMAP_BYTES * 8 - && !cluster_fence_marker_node_is_fenced(m->fenced_dead_bitmap, - m->issuer_node_id); + && !cluster_fence_marker_node_is_fenced(m->fenced_dead_bitmap, m->issuer_node_id); } return bitmap_nonempty && m->issuer_node_id >= 0 && m->issuer_node_id < CLUSTER_FENCE_MARKER_DEAD_BITMAP_BYTES * 8 - && !cluster_fence_marker_node_is_fenced(m->fenced_dead_bitmap, - m->issuer_node_id); + && !cluster_fence_marker_node_is_fenced(m->fenced_dead_bitmap, m->issuer_node_id); } /* @@ -326,8 +323,7 @@ cluster_fence_marker_order_compare(const ClusterFenceMarker *a, const ClusterFen */ static inline ClusterFenceDiskVoteState cluster_fence_disk_vote_select_v1(const ClusterFenceMarker *slot_markers, - const bool *outer_crc_valid, int n_slots, - ClusterFenceMarker *out) + const bool *outer_crc_valid, int n_slots, ClusterFenceMarker *out) { ClusterFenceMarker best; bool found = false; @@ -373,8 +369,8 @@ cluster_fence_disk_vote_select_v1(const ClusterFenceMarker *slot_markers, */ static inline ClusterFenceAuthorityReadResult cluster_fence_authority_prove_v1(const ClusterFenceMarker *disk_markers, - const ClusterFenceDiskVoteState *disk_states, - int n_disks, ClusterFenceAuthorityProof *out) + const ClusterFenceDiskVoteState *disk_states, int n_disks, + ClusterFenceAuthorityProof *out) { ClusterFenceAuthorityProof proof; bool unreadable = false; @@ -391,22 +387,22 @@ cluster_fence_authority_prove_v1(const ClusterFenceMarker *disk_markers, majority = n_disks / 2 + 1; for (i = 0; i < n_disks; i++) { switch (disk_states[i]) { - case CLUSTER_FENCE_DISK_VOTE_EMPTY: - break; - case CLUSTER_FENCE_DISK_VOTE_VALID: - if (!cluster_fence_marker_valid_v1(&disk_markers[i])) - corrupt = true; - break; - case CLUSTER_FENCE_DISK_VOTE_UNREADABLE: - unreadable = true; - break; - case CLUSTER_FENCE_DISK_VOTE_MIXED_VERSION: - mixed_version = true; - break; - case CLUSTER_FENCE_DISK_VOTE_CORRUPT: - default: + case CLUSTER_FENCE_DISK_VOTE_EMPTY: + break; + case CLUSTER_FENCE_DISK_VOTE_VALID: + if (!cluster_fence_marker_valid_v1(&disk_markers[i])) corrupt = true; - break; + break; + case CLUSTER_FENCE_DISK_VOTE_UNREADABLE: + unreadable = true; + break; + case CLUSTER_FENCE_DISK_VOTE_MIXED_VERSION: + mixed_version = true; + break; + case CLUSTER_FENCE_DISK_VOTE_CORRUPT: + default: + corrupt = true; + break; } } if (corrupt) @@ -468,9 +464,8 @@ cluster_fence_marker_semantic_equal(const ClusterFenceMarker *a, const ClusterFe static inline ClusterFenceAuthorityCacheResult cluster_fence_authority_cache_decide_v1(const ClusterFenceMarker *expected, uint64 seq_before, uint64 seq_after, bool valid, - const ClusterFenceMarker *observed, - uint64 published_at_us, uint64 expiry_us, - uint64 now_us) + const ClusterFenceMarker *observed, uint64 published_at_us, + uint64 expiry_us, uint64 now_us) { if (!valid) return CLUSTER_FENCE_CACHE_INVALID; @@ -624,9 +619,8 @@ cluster_write_fence_authority_advances(uint64 new_epoch, const uint8 *new_dead, * can only reject locally. This is the author-side half of 4.12b D5. */ static inline bool -cluster_fence_baseline_author_permitted_v1( - const ClusterFenceMarker *baseline, bool have_durable, - const ClusterFenceMarker *durable) +cluster_fence_baseline_author_permitted_v1(const ClusterFenceMarker *baseline, bool have_durable, + const ClusterFenceMarker *durable) { int order; @@ -636,12 +630,11 @@ cluster_fence_baseline_author_permitted_v1( return true; if (!cluster_fence_marker_valid_v1(durable) || !cluster_write_fence_authority_advances( - baseline->fence_epoch, baseline->fenced_dead_bitmap, - durable->fence_epoch, durable->fenced_dead_bitmap)) + baseline->fence_epoch, baseline->fenced_dead_bitmap, durable->fence_epoch, + durable->fenced_dead_bitmap)) return false; order = cluster_fence_marker_order_compare(baseline, durable); - return order > 0 - || (order == 0 && cluster_fence_marker_tuple_equal(baseline, durable)); + return order > 0 || (order == 0 && cluster_fence_marker_tuple_equal(baseline, durable)); } /* @@ -865,8 +858,8 @@ extern bool cluster_write_fence_enforcing(void); /* STOP-02 \u00a717.5 direct, total, distinct-disk durable authority proof. */ extern ClusterFenceAuthorityReadResult cluster_write_fence_read_durable_authority(ClusterFenceAuthorityProof *out); -extern ClusterFenceAuthorityCacheResult cluster_write_fence_revalidate_cached_nowait( - const ClusterFenceMarker *expected, uint64 now_us); +extern ClusterFenceAuthorityCacheResult +cluster_write_fence_revalidate_cached_nowait(const ClusterFenceMarker *expected, uint64 now_us); extern void cluster_write_fence_authority_cache_invalidate(void); extern uint64 cluster_write_fence_authority_cache_mutation_begin(void); extern void cluster_write_fence_authority_cache_mutation_end(uint64 odd_sequence); @@ -958,7 +951,7 @@ extern void cluster_write_fence_note_baseline_published(bool is_leader, bool pub /* STOP-04 \u00a73.13 external-fence producers and L110-safe readers. */ extern void cluster_write_fence_note_external_admit_requested(void); extern void cluster_write_fence_note_external_write_excluded(uint64 journal_seq, - uint64 verified_mono_ns); + uint64 verified_mono_ns); extern void cluster_write_fence_note_external_rejected(void); extern void cluster_write_fence_note_external_unknown(void); extern void cluster_write_fence_note_external_unavailable(void); diff --git a/src/include/cluster/storage/cluster_shared_fs.h b/src/include/cluster/storage/cluster_shared_fs.h index 9c1b69fb481..1c6b9c6687b 100644 --- a/src/include/cluster/storage/cluster_shared_fs.h +++ b/src/include/cluster/storage/cluster_shared_fs.h @@ -387,14 +387,12 @@ extern const ClusterSharedFsOps cluster_shared_fs_sharedfs_ops; extern void cluster_shared_fs_sentinel_attach(void); extern bool cluster_shared_fs_sentinel_has_participant(int node_id); extern void cluster_shared_fs_get_storage_uuid(char *out, size_t outlen); -extern bool cluster_shared_fs_get_protected_set_identity( - ClusterProtectedSetIdentityV1 *out); +extern bool cluster_shared_fs_get_protected_set_identity(ClusterProtectedSetIdentityV1 *out); /* Backend-private identity source used by the provider-neutral dispatcher. * It returns only a strict configured UUID already matched to the CRC-valid * raw superblock; the legacy "raw-block-device" fallback returns false. */ -extern bool cluster_shared_fs_block_device_get_storage_uuid( - char *out, size_t outlen); +extern bool cluster_shared_fs_block_device_get_storage_uuid(char *out, size_t outlen); #endif /* CLUSTER_SHARED_FS_H */ diff --git a/src/include/cluster/storage/cluster_undo_alloc.h b/src/include/cluster/storage/cluster_undo_alloc.h index 7fa09465bec..1673ac2a383 100644 --- a/src/include/cluster/storage/cluster_undo_alloc.h +++ b/src/include/cluster/storage/cluster_undo_alloc.h @@ -242,8 +242,8 @@ StaticAssertDecl(sizeof(ClusterUndoSegmentExtendPlan) == 16, * ownership but release lifecycle_lock before first provision or reuse * through current authority, then revalidate the selected image. */ -extern bool cluster_undo_segment_extend_or_create( - uint8 owner_instance, ClusterUndoSegmentExtendPlan *plan); +extern bool cluster_undo_segment_extend_or_create(uint8 owner_instance, + ClusterUndoSegmentExtendPlan *plan); /* @@ -295,20 +295,21 @@ typedef enum ClusterUndoSegTryRecycle { } ClusterUndoSegTryRecycle; /* Caller holds no lifecycle/content lock; expected_epoch binds the folded floor. */ -extern ClusterUndoSegTryRecycle -cluster_undo_segment_try_mark_recyclable(uint32 segment_id, - uint8 owner_instance, SCN horizon, uint64 expected_epoch); +extern ClusterUndoSegTryRecycle cluster_undo_segment_try_mark_recyclable(uint32 segment_id, + uint8 owner_instance, + SCN horizon, + uint64 expected_epoch); /* spec-3.13 D4: exact in-place rebirth; caller holds no lifecycle/content lock. */ extern uint32 cluster_undo_segment_reuse_in_place(uint32 segment_id, uint8 owner_instance, - uint32 old_generation); + uint32 old_generation); /* spec-3.13 D4: durable segment generation (== header wrap_count; 0 = unknown). */ extern uint32 cluster_undo_segment_generation(uint32 segment_id, uint8 owner_instance); /* spec-3.13: identity check exported for redo + reuse peek (L212 surface). */ extern bool cluster_undo_segment_header_identity_ok(const char *blockbuf, uint32 segment_id, - uint8 owner_instance); + uint8 owner_instance); typedef enum ClusterUndoPoolObservationResult { CLUSTER_UNDO_POOL_OBS_OK = 0, diff --git a/src/include/cluster/storage/cluster_undo_block0.h b/src/include/cluster/storage/cluster_undo_block0.h index 2c6f22c4de8..9b0e38296dc 100644 --- a/src/include/cluster/storage/cluster_undo_block0.h +++ b/src/include/cluster/storage/cluster_undo_block0.h @@ -161,7 +161,7 @@ extern bool cluster_undo_block0_generation_matches(const ClusterUndoBlock0Genera extern bool cluster_undo_block0_generation_advance(const ClusterUndoBlock0Generation *current, ClusterUndoBlock0Generation *next); extern bool cluster_undo_block0_state_transition_allowed(ClusterUndoBlock0SlotState from, - ClusterUndoBlock0SlotState to); + ClusterUndoBlock0SlotState to); /* Separate block0 subregion embedded after the ordinary undo DATA bank. */ extern Size cluster_undo_block0_shmem_size(uint32 frame_count); @@ -173,114 +173,78 @@ extern ClusterUndoBlock0Result cluster_undo_block0_frame_reserve_batch(uint32 count, ClusterUndoBlock0FrameToken *tokens); extern void cluster_undo_block0_frame_release(ClusterUndoBlock0FrameToken *token); -extern ClusterUndoBlock0Result -cluster_undo_block0_admit_runtime(const ClusterUndoBlock0LogicalKey *logical, - const ClusterUndoBlock0ResolvedRoot *root, - const ClusterUndoBlock0AuthorityProof *proof, - ClusterUndoBlock0FrameToken *token, ClusterUndoBlock0Pin *pin, - char **page); -extern ClusterUndoBlock0Result -cluster_undo_block0_reserve(const ClusterUndoBlock0LogicalKey *logical, - const ClusterUndoBlock0ResolvedRoot *expected_root, - const ClusterUndoBlock0AuthorityProof *proof, - ClusterUndoBlock0Pin *pin); +extern ClusterUndoBlock0Result cluster_undo_block0_admit_runtime( + const ClusterUndoBlock0LogicalKey *logical, const ClusterUndoBlock0ResolvedRoot *root, + const ClusterUndoBlock0AuthorityProof *proof, ClusterUndoBlock0FrameToken *token, + ClusterUndoBlock0Pin *pin, char **page); +extern ClusterUndoBlock0Result cluster_undo_block0_reserve( + const ClusterUndoBlock0LogicalKey *logical, const ClusterUndoBlock0ResolvedRoot *expected_root, + const ClusterUndoBlock0AuthorityProof *proof, ClusterUndoBlock0Pin *pin); extern ClusterUndoBlock0Result cluster_undo_block0_lock_content(ClusterUndoBlock0Pin *pin, const ClusterUndoBlock0Generation *expected, ClusterUndoBlock0Mode mode, char **page); -extern ClusterUndoBlock0Result -cluster_undo_block0_pin(const ClusterUndoBlock0LogicalKey *logical, - const ClusterUndoBlock0ResolvedRoot *expected_root, - const ClusterUndoBlock0Generation *expected, ClusterUndoBlock0Mode mode, - const ClusterUndoBlock0AuthorityProof *proof, ClusterUndoBlock0Pin *pin, - char **page); -extern ClusterUndoBlock0Result -cluster_undo_block0_copy_resident(const ClusterUndoBlock0LogicalKey *logical, - const ClusterUndoBlock0ResolvedRoot *expected_root, - const ClusterUndoBlock0Generation *expected, - const ClusterUndoBlock0AuthorityProof *proof, - char private_page[BLCKSZ], - ClusterUndoBlock0Generation *observed_generation); -extern ClusterUndoBlock0Result -cluster_undo_block0_copy_readonly(const ClusterUndoBlock0LogicalKey *logical, - const ClusterUndoBlock0ResolvedRoot *read_root, - const ClusterUndoBlock0Generation *expected, - const ClusterUndoBlock0AuthorityProof *proof, - char private_page[BLCKSZ]); -extern ClusterUndoBlock0Result -cluster_undo_block0_sample_resident_generation( - const ClusterUndoBlock0LogicalKey *logical, - const ClusterUndoBlock0ResolvedRoot *expected_root, - const ClusterUndoBlock0AuthorityProof *proof, - ClusterUndoBlock0Generation *observed_generation); +extern ClusterUndoBlock0Result cluster_undo_block0_pin( + const ClusterUndoBlock0LogicalKey *logical, const ClusterUndoBlock0ResolvedRoot *expected_root, + const ClusterUndoBlock0Generation *expected, ClusterUndoBlock0Mode mode, + const ClusterUndoBlock0AuthorityProof *proof, ClusterUndoBlock0Pin *pin, char **page); +extern ClusterUndoBlock0Result cluster_undo_block0_copy_resident( + const ClusterUndoBlock0LogicalKey *logical, const ClusterUndoBlock0ResolvedRoot *expected_root, + const ClusterUndoBlock0Generation *expected, const ClusterUndoBlock0AuthorityProof *proof, + char private_page[BLCKSZ], ClusterUndoBlock0Generation *observed_generation); +extern ClusterUndoBlock0Result cluster_undo_block0_copy_readonly( + const ClusterUndoBlock0LogicalKey *logical, const ClusterUndoBlock0ResolvedRoot *read_root, + const ClusterUndoBlock0Generation *expected, const ClusterUndoBlock0AuthorityProof *proof, + char private_page[BLCKSZ]); +extern ClusterUndoBlock0Result cluster_undo_block0_sample_resident_generation( + const ClusterUndoBlock0LogicalKey *logical, const ClusterUndoBlock0ResolvedRoot *expected_root, + const ClusterUndoBlock0AuthorityProof *proof, ClusterUndoBlock0Generation *observed_generation); /* Same exact sample, but never queues behind the resident content lock and * never fills a missing slot. CAPACITY_UNAVAILABLE means the caller must * drop its later-ranked lock and retry from its original deadline. */ +extern ClusterUndoBlock0Result cluster_undo_block0_sample_resident_generation_conditional( + const ClusterUndoBlock0LogicalKey *logical, const ClusterUndoBlock0ResolvedRoot *expected_root, + const ClusterUndoBlock0AuthorityProof *proof, ClusterUndoBlock0Generation *observed_generation); extern ClusterUndoBlock0Result -cluster_undo_block0_sample_resident_generation_conditional( - const ClusterUndoBlock0LogicalKey *logical, - const ClusterUndoBlock0ResolvedRoot *expected_root, - const ClusterUndoBlock0AuthorityProof *proof, - ClusterUndoBlock0Generation *observed_generation); -extern ClusterUndoBlock0Result -cluster_undo_block0_prove_strict_empty( - const ClusterUndoBlock0LogicalKey *logical, - const ClusterUndoBlock0AuthorityProof *proof); -extern ClusterUndoBlock0Result -cluster_undo_block0_recovery_private_begin( - const ClusterUndoBlock0LogicalKey *logical, - const ClusterUndoBlock0ResolvedRoot *redo_root, - const ClusterUndoBlock0AuthorityProof *proof, - bool allow_absent, - ClusterUndoBlock0RecoveryGuard *guard, - char private_page[BLCKSZ], - bool *exists); -extern void -cluster_undo_block0_recovery_private_finish(ClusterUndoBlock0RecoveryGuard *guard, - const char *successor_page, - XLogRecPtr replay_lsn, - bool write_image, - bool fsync_parent); -extern void -cluster_undo_block0_recovery_private_abort(ClusterUndoBlock0RecoveryGuard *guard); +cluster_undo_block0_prove_strict_empty(const ClusterUndoBlock0LogicalKey *logical, + const ClusterUndoBlock0AuthorityProof *proof); +extern ClusterUndoBlock0Result cluster_undo_block0_recovery_private_begin( + const ClusterUndoBlock0LogicalKey *logical, const ClusterUndoBlock0ResolvedRoot *redo_root, + const ClusterUndoBlock0AuthorityProof *proof, bool allow_absent, + ClusterUndoBlock0RecoveryGuard *guard, char private_page[BLCKSZ], bool *exists); +extern void cluster_undo_block0_recovery_private_finish(ClusterUndoBlock0RecoveryGuard *guard, + const char *successor_page, + XLogRecPtr replay_lsn, bool write_image, + bool fsync_parent); +extern void cluster_undo_block0_recovery_private_abort(ClusterUndoBlock0RecoveryGuard *guard); extern ClusterUndoBlock0Result cluster_undo_block0_provision_begin( - const ClusterUndoBlock0LogicalKey *logical, - const ClusterUndoBlock0ResolvedRoot *target_root, - const ClusterUndoBlock0AuthorityProof *proof, - ClusterUndoBlock0FrameToken *token, - ClusterUndoBlock0Pin *pin, - char **unpublished_page, - bool *creator); -extern void cluster_undo_block0_provision_publish(ClusterUndoBlock0Pin *pin, - XLogRecPtr init_lsn); + const ClusterUndoBlock0LogicalKey *logical, const ClusterUndoBlock0ResolvedRoot *target_root, + const ClusterUndoBlock0AuthorityProof *proof, ClusterUndoBlock0FrameToken *token, + ClusterUndoBlock0Pin *pin, char **unpublished_page, bool *creator); +extern void cluster_undo_block0_provision_publish(ClusterUndoBlock0Pin *pin, XLogRecPtr init_lsn); extern void cluster_undo_block0_provision_abort(ClusterUndoBlock0Pin *pin); -extern bool cluster_undo_block0_verify_clean_census( - const ClusterUndoBlock0ResidentCensusItem *items, uint32 count); +extern bool +cluster_undo_block0_verify_clean_census(const ClusterUndoBlock0ResidentCensusItem *items, + uint32 count); /* Normal Startup's closed pass only: never an online eviction interface. */ extern bool cluster_undo_block0_normal_start_empty(void); extern bool cluster_undo_block0_normal_start_discard(const ClusterUndoBlock0ResidentCensusItem *item, uint32 frame_index); -extern void cluster_undo_block0_mark_wal_dirty(ClusterUndoBlock0Pin *pin, - XLogRecPtr wal_lsn); -extern void cluster_undo_block0_flush_sync(ClusterUndoBlock0Pin *pin, - const char *successor_page, - XLogRecPtr required_wal_lsn, - bool fsync_parent); +extern void cluster_undo_block0_mark_wal_dirty(ClusterUndoBlock0Pin *pin, XLogRecPtr wal_lsn); +extern void cluster_undo_block0_flush_sync(ClusterUndoBlock0Pin *pin, const char *successor_page, + XLogRecPtr required_wal_lsn, bool fsync_parent); extern void cluster_undo_block0_unpin(ClusterUndoBlock0Pin *pin); extern ClusterR4PrerequisiteSnapshot cluster_undo_block0_r4_prerequisite_snapshot(void); -extern bool -cluster_undo_block0_r4_publish_ready(const ClusterR4PrerequisiteSnapshot *expected); +extern bool cluster_undo_block0_r4_publish_ready(const ClusterR4PrerequisiteSnapshot *expected); -typedef struct ClusterR4StartupCompletionContextV1 - ClusterR4StartupCompletionContextV1; +typedef struct ClusterR4StartupCompletionContextV1 ClusterR4StartupCompletionContextV1; typedef struct RfRootResourceAdmissionV1 RfRootResourceAdmissionV1; typedef struct RfRecordClosureProofV1 RfRecordClosureProofV1; typedef struct RfPageResourceProofV1 RfPageResourceProofV1; typedef struct RfSideResourceProofSetV1 RfSideResourceProofSetV1; -typedef enum ClusterR4StartupCompletionResultV1 -{ +typedef enum ClusterR4StartupCompletionResultV1 { CLUSTER_R4_STARTUP_COMPLETION_OK = 0, CLUSTER_R4_STARTUP_COMPLETION_RETRY = 1, CLUSTER_R4_STARTUP_COMPLETION_BLOCKED_LINEAGE = 2, @@ -296,19 +260,13 @@ typedef enum ClusterR4StartupCompletionResultV1 } ClusterR4StartupCompletionResultV1; extern ClusterR4StartupCompletionResultV1 -cluster_undo_block0_r4_startup_begin( - int timeout_ms, ClusterR4StartupCompletionContextV1 **out); -extern ClusterR4StartupCompletionResultV1 -cluster_undo_block0_r4_startup_close_next( - ClusterR4StartupCompletionContextV1 *context, - const RfRootResourceAdmissionV1 *root, - const RfRecordClosureProofV1 *record, - const RfPageResourceProofV1 *page, +cluster_undo_block0_r4_startup_begin(int timeout_ms, ClusterR4StartupCompletionContextV1 **out); +extern ClusterR4StartupCompletionResultV1 cluster_undo_block0_r4_startup_close_next( + ClusterR4StartupCompletionContextV1 *context, const RfRootResourceAdmissionV1 *root, + const RfRecordClosureProofV1 *record, const RfPageResourceProofV1 *page, const RfSideResourceProofSetV1 *side); extern ClusterR4StartupCompletionResultV1 -cluster_undo_block0_r4_startup_finalize( - ClusterR4StartupCompletionContextV1 **context); -extern void cluster_undo_block0_r4_startup_abort( - ClusterR4StartupCompletionContextV1 **context); +cluster_undo_block0_r4_startup_finalize(ClusterR4StartupCompletionContextV1 **context); +extern void cluster_undo_block0_r4_startup_abort(ClusterR4StartupCompletionContextV1 **context); #endif /* CLUSTER_UNDO_BLOCK0_H */ diff --git a/src/include/cluster/storage/cluster_undo_block0_current.h b/src/include/cluster/storage/cluster_undo_block0_current.h index 10b8f9952ce..b4b0b06c64f 100644 --- a/src/include/cluster/storage/cluster_undo_block0_current.h +++ b/src/include/cluster/storage/cluster_undo_block0_current.h @@ -112,93 +112,79 @@ extern void cluster_undo_block0_current_ensure_exit_hooks(void); extern ClusterUndoBlock0CurrentStep cluster_undo_block0_current_acquire_begin( const ClusterUndoBlock0LogicalKey *key, ClusterUndoBlock0CurrentMode mode, int timeout_ms, ClusterUndoBlock0CurrentGuard *guard, ClusterUndoBlock0Result *failure); -extern ClusterUndoBlock0CurrentStep -cluster_undo_block0_current_acquire_begin_admitted( - const ClusterUndoBlock0LogicalKey *key, ClusterUndoBlock0CurrentMode mode, - int timeout_ms, const ClusterSemanticAdmissionToken *admission, - ClusterUndoBlock0CurrentGuard *guard, ClusterUndoBlock0Result *failure); -extern ClusterUndoBlock0CurrentStep -cluster_undo_block0_current_acquire_begin_ctrc_release( +extern ClusterUndoBlock0CurrentStep cluster_undo_block0_current_acquire_begin_admitted( + const ClusterUndoBlock0LogicalKey *key, ClusterUndoBlock0CurrentMode mode, int timeout_ms, + const ClusterSemanticAdmissionToken *admission, ClusterUndoBlock0CurrentGuard *guard, + ClusterUndoBlock0Result *failure); +extern ClusterUndoBlock0CurrentStep cluster_undo_block0_current_acquire_begin_ctrc_release( const ClusterUndoBlock0LogicalKey *key, int timeout_ms, - const ClusterSemanticAdmissionToken *admission, - ClusterUndoBlock0CurrentGuard *guard, ClusterUndoBlock0Result *failure); -extern ClusterUndoBlock0CurrentStep -cluster_undo_block0_current_acquire_begin_live_owner_source( + const ClusterSemanticAdmissionToken *admission, ClusterUndoBlock0CurrentGuard *guard, + ClusterUndoBlock0Result *failure); +extern ClusterUndoBlock0CurrentStep cluster_undo_block0_current_acquire_begin_live_owner_source( const ClusterUndoBlock0LogicalKey *key, int timeout_ms, - const ClusterSemanticAdmissionToken *admission, - ClusterUndoBlock0CurrentGuard *guard, ClusterUndoBlock0Result *failure); -extern ClusterUndoBlock0CurrentStep -cluster_undo_block0_current_acquire_begin_live_owner_target( + const ClusterSemanticAdmissionToken *admission, ClusterUndoBlock0CurrentGuard *guard, + ClusterUndoBlock0Result *failure); +extern ClusterUndoBlock0CurrentStep cluster_undo_block0_current_acquire_begin_live_owner_target( const ClusterUndoBlock0LogicalKey *key, int timeout_ms, - const ClusterSemanticAdmissionToken *admission, - ClusterUndoBlock0CurrentGuard *guard, ClusterUndoBlock0Result *failure); + const ClusterSemanticAdmissionToken *admission, ClusterUndoBlock0CurrentGuard *guard, + ClusterUndoBlock0Result *failure); extern ClusterUndoBlock0CurrentStep cluster_undo_block0_current_acquire_poll(ClusterUndoBlock0CurrentGuard *guard, - ClusterUndoBlock0Result *failure); + ClusterUndoBlock0Result *failure); extern bool cluster_undo_block0_current_wait_reply(ClusterUndoBlock0CurrentGuard *guard, ClusterUndoBlock0ReplyWaitSite site); extern void cluster_undo_block0_current_cancel(ClusterUndoBlock0CurrentGuard *guard); extern ClusterUndoBlock0CurrentStep cluster_undo_block0_current_release_begin(ClusterUndoBlock0CurrentGuard *guard, - ClusterUndoBlock0Result *failure); + ClusterUndoBlock0Result *failure); extern ClusterUndoBlock0CurrentStep cluster_undo_block0_current_release_poll(ClusterUndoBlock0CurrentGuard *guard, - ClusterUndoBlock0Result *failure); + ClusterUndoBlock0Result *failure); -extern ClusterUndoBlock0Result cluster_undo_block0_current_sample_generation( - ClusterUndoBlock0CurrentGuard *guard, const ClusterUndoBlock0ResolvedRoot *root, - ClusterUndoBlock0Generation *observed); -extern ClusterUndoBlock0Result cluster_undo_block0_current_sample_generation_exclusive( - ClusterUndoBlock0CurrentGuard *guard, const ClusterUndoBlock0ResolvedRoot *root, - ClusterUndoBlock0Generation *observed); extern ClusterUndoBlock0Result -cluster_undo_block0_current_prove_strict_empty_exclusive( - ClusterUndoBlock0CurrentGuard *guard); +cluster_undo_block0_current_sample_generation(ClusterUndoBlock0CurrentGuard *guard, + const ClusterUndoBlock0ResolvedRoot *root, + ClusterUndoBlock0Generation *observed); +extern ClusterUndoBlock0Result +cluster_undo_block0_current_sample_generation_exclusive(ClusterUndoBlock0CurrentGuard *guard, + const ClusterUndoBlock0ResolvedRoot *root, + ClusterUndoBlock0Generation *observed); +extern ClusterUndoBlock0Result +cluster_undo_block0_current_prove_strict_empty_exclusive(ClusterUndoBlock0CurrentGuard *guard); extern ClusterUndoBlock0Result cluster_undo_block0_current_copy_resident( ClusterUndoBlock0CurrentGuard *guard, const ClusterUndoBlock0ResolvedRoot *root, const ClusterUndoBlock0Generation *expected, char private_page[BLCKSZ]); extern ClusterUndoBlock0Result cluster_undo_block0_current_pin_exclusive( ClusterUndoBlock0CurrentGuard *guard, const ClusterUndoBlock0ResolvedRoot *root, const ClusterUndoBlock0Generation *expected, ClusterUndoBlock0Pin *pin, char **page); -extern ClusterUndoBlock0Result cluster_undo_block0_current_recheck_exclusive( - ClusterUndoBlock0CurrentGuard *guard); +extern ClusterUndoBlock0Result +cluster_undo_block0_current_recheck_exclusive(ClusterUndoBlock0CurrentGuard *guard); extern ClusterUndoBlock0Result cluster_undo_block0_current_live_owner_provision(const ClusterUndoBlock0LogicalKey *key, int timeout_ms); extern ClusterUndoBlock0Result cluster_undo_block0_current_live_owner_ensure_resident(const ClusterUndoBlock0LogicalKey *key, int timeout_ms); -extern ClusterUndoBlock0Result -cluster_undo_block0_current_live_owner_ensure_resident_exact( +extern ClusterUndoBlock0Result cluster_undo_block0_current_live_owner_ensure_resident_exact( const ClusterUndoBlock0LogicalKey *key, int timeout_ms, ClusterUndoBlock0LiveOwnerPublication *publication); -extern ClusterUndoBlock0Result -cluster_undo_block0_current_live_owner_reuse_exact( - const ClusterUndoBlock0LogicalKey *key, - const ClusterUndoBlock0Generation *expected, - const char successor_page[BLCKSZ], int timeout_ms); -extern ClusterUndoBlock0Result -cluster_undo_block0_current_live_owner_mutate_exact( - const ClusterUndoBlock0LogicalKey *key, - const ClusterUndoBlock0Generation *expected, - const char predecessor_page[BLCKSZ], +extern ClusterUndoBlock0Result cluster_undo_block0_current_live_owner_reuse_exact( + const ClusterUndoBlock0LogicalKey *key, const ClusterUndoBlock0Generation *expected, const char successor_page[BLCKSZ], int timeout_ms); -extern ClusterUndoBlock0RecycleResult -cluster_undo_block0_current_live_owner_recycle_exact( - const ClusterUndoBlock0LogicalKey *key, SCN horizon, - uint64 expected_epoch, int timeout_ms); +extern ClusterUndoBlock0Result cluster_undo_block0_current_live_owner_mutate_exact( + const ClusterUndoBlock0LogicalKey *key, const ClusterUndoBlock0Generation *expected, + const char predecessor_page[BLCKSZ], const char successor_page[BLCKSZ], int timeout_ms); +extern ClusterUndoBlock0RecycleResult cluster_undo_block0_current_live_owner_recycle_exact( + const ClusterUndoBlock0LogicalKey *key, SCN horizon, uint64 expected_epoch, int timeout_ms); extern bool cluster_undo_block0_current_live_owner_publication_recheck( const ClusterUndoBlock0LiveOwnerPublication *publication); -extern bool -cluster_undo_block0_current_live_owner_publication_recheck_conditional( +extern bool cluster_undo_block0_current_live_owner_publication_recheck_conditional( const ClusterUndoBlock0LiveOwnerPublication *publication); /* Target Startup's sole no-live-GES lane. READY publication additionally * revalidates this process-local ownership through the query below. */ -extern bool cluster_undo_block0_current_startup_fenced_begin( - ClusterUndoBlock0CurrentGuard *guard); -extern bool cluster_undo_block0_current_startup_fenced_end( - ClusterUndoBlock0CurrentGuard *guard); +extern bool cluster_undo_block0_current_startup_fenced_begin(ClusterUndoBlock0CurrentGuard *guard); +extern bool cluster_undo_block0_current_startup_fenced_end(ClusterUndoBlock0CurrentGuard *guard); extern bool cluster_undo_block0_current_startup_fenced_owned(void); #endif /* CLUSTER_UNDO_BLOCK0_CURRENT_H */ diff --git a/src/include/cluster/storage/cluster_undo_buf.h b/src/include/cluster/storage/cluster_undo_buf.h index b0e036d52e4..e87fde2847a 100644 --- a/src/include/cluster/storage/cluster_undo_buf.h +++ b/src/include/cluster/storage/cluster_undo_buf.h @@ -96,7 +96,7 @@ extern char *cluster_undo_buf_pin(uint32 segment_id, uint8 owner, uint32 block_n * disabled pool returns false without disk I/O and leaves dst unchanged. */ extern bool cluster_undo_buf_copy_resident(uint32 segment_id, uint8 owner, uint32 block_no, - char dst[BLCKSZ]); + char dst[BLCKSZ]); /* * cluster_undo_buf_mark_dirty -- the EXCLUSIVE-pinned block was modified, @@ -119,11 +119,10 @@ extern void cluster_undo_buf_unref_slot(int slot); * retry edge. Once locked, the exact referenced slot cannot be evicted or * rebound; install is therefore infallible and is followed by explicit * unlock after the prepared image is copied. */ -extern bool cluster_undo_buf_lock_ref_conditional(int slot, uint32 segment_id, - uint8 owner, uint32 block_no); -extern void cluster_undo_buf_install_ref_locked(int slot, uint32 segment_id, - uint8 owner, uint32 block_no, - const char image[BLCKSZ]); +extern bool cluster_undo_buf_lock_ref_conditional(int slot, uint32 segment_id, uint8 owner, + uint32 block_no); +extern void cluster_undo_buf_install_ref_locked(int slot, uint32 segment_id, uint8 owner, + uint32 block_no, const char image[BLCKSZ]); extern void cluster_undo_buf_unlock_ref(int slot); /* checkpoint / shutdown flush hook. is_checkpoint=true on checkpoint. */ diff --git a/src/include/cluster/storage/cluster_undo_xlog.h b/src/include/cluster/storage/cluster_undo_xlog.h index aa74102a7d2..175a23384a0 100644 --- a/src/include/cluster/storage/cluster_undo_xlog.h +++ b/src/include/cluster/storage/cluster_undo_xlog.h @@ -44,7 +44,7 @@ #include "cluster/cluster_itl_slot.h" /* UBA (spec-4.8 D7-A xl_undo_tt_slot_set_head) */ #include "cluster/cluster_scn.h" /* SCN typedef (spec-3.11 D3 xl_undo_tt_slot_commit) */ -#include "cluster/cluster_tt_slot.h" /* TTSlot + CTRC release flag */ +#include "cluster/cluster_tt_slot.h" /* TTSlot + CTRC release flag */ #include "cluster/cluster_undo_format.h" /* UndoBlockHeader/UndoSlotDirEntry (spec-3.18 D2 block_write) */ @@ -159,8 +159,7 @@ StaticAssertDecl(sizeof(xl_undo_tt_slot_bind) == 24, "xl_undo_tt_slot_bind must be exactly 24 bytes"); StaticAssertDecl(offsetof(xl_undo_tt_slot_bind, segment_generation) == 4, "bind segment generation offset must remain fixed"); -StaticAssertDecl(offsetof(xl_undo_tt_slot_bind, xid) == 8, - "bind xid offset must remain fixed"); +StaticAssertDecl(offsetof(xl_undo_tt_slot_bind, xid) == 8, "bind xid offset must remain fixed"); StaticAssertDecl(offsetof(xl_undo_tt_slot_bind, instance) == 16, "bind identity trailer offset must remain fixed"); @@ -291,8 +290,7 @@ StaticAssertDecl(sizeof(xl_undo_tt_slot_set_head) == 32, #define CLUSTER_UNDO_TT_CTRC_RELEASE_ALL_TOUCHED_ACKED UINT8_C(0x01) #define CLUSTER_UNDO_TT_CTRC_RELEASE_BYTES 96 -typedef struct xl_undo_tt_slot_ctrc_release_v1 -{ +typedef struct xl_undo_tt_slot_ctrc_release_v1 { uint32 segment_id; uint32 segment_generation; TransactionId xid; @@ -313,14 +311,11 @@ typedef struct xl_undo_tt_slot_ctrc_release_v1 uint8 flags; } xl_undo_tt_slot_ctrc_release_v1; -StaticAssertDecl(sizeof(xl_undo_tt_slot_ctrc_release_v1) - == CLUSTER_UNDO_TT_CTRC_RELEASE_BYTES, +StaticAssertDecl(sizeof(xl_undo_tt_slot_ctrc_release_v1) == CLUSTER_UNDO_TT_CTRC_RELEASE_BYTES, "CTRC release WAL payload must remain exactly 96 bytes"); -StaticAssertDecl(offsetof(xl_undo_tt_slot_ctrc_release_v1, - ack_set_digest) == 72, +StaticAssertDecl(offsetof(xl_undo_tt_slot_ctrc_release_v1, ack_set_digest) == 72, "CTRC release digest offset must remain fixed"); -StaticAssertDecl(offsetof(xl_undo_tt_slot_ctrc_release_v1, - slot_offset) == 88, +StaticAssertDecl(offsetof(xl_undo_tt_slot_ctrc_release_v1, slot_offset) == 88, "CTRC release identity trailer offset must remain fixed"); static inline void @@ -357,8 +352,8 @@ cluster_undo_tt_ctrc_get_u16_le(const uint8 *bytes) static inline uint32 cluster_undo_tt_ctrc_get_u32_le(const uint8 *bytes) { - return (uint32)bytes[0] | ((uint32)bytes[1] << 8) - | ((uint32)bytes[2] << 16) | ((uint32)bytes[3] << 24); + return (uint32)bytes[0] | ((uint32)bytes[1] << 8) | ((uint32)bytes[2] << 16) + | ((uint32)bytes[3] << 24); } static inline uint64 @@ -373,51 +368,41 @@ cluster_undo_tt_ctrc_get_u64_le(const uint8 *bytes) } static inline bool -cluster_undo_tt_ctrc_release_valid( - const xl_undo_tt_slot_ctrc_release_v1 *record) +cluster_undo_tt_ctrc_release_valid(const xl_undo_tt_slot_ctrc_release_v1 *record) { - return record != NULL && record->segment_id != 0 - && TransactionIdIsNormal(record->xid) - && record->root_id != 0 && record->root_generation != 0 - && record->admission_record_generation != 0 - && record->seal_generation != 0 - && record->touched_nodes_high == 0 - && (record->touched_nodes_low & ~UINT64_C(0xffff)) == 0 - && record->slot_offset < TT_SLOTS_PER_SEGMENT - && record->slot_wrap != TT_WRAP_INVALID - && record->owner_instance != 0 && record->owner_instance <= 128 - && (record->terminal_status == TT_SLOT_COMMITTED - || record->terminal_status == TT_SLOT_ABORTED) - && record->format_version - == CLUSTER_UNDO_TT_CTRC_RELEASE_VERSION - && record->flags - == CLUSTER_UNDO_TT_CTRC_RELEASE_ALL_TOUCHED_ACKED; + return record != NULL && record->segment_id != 0 && TransactionIdIsNormal(record->xid) + && record->root_id != 0 && record->root_generation != 0 + && record->admission_record_generation != 0 && record->seal_generation != 0 + && record->touched_nodes_high == 0 + && (record->touched_nodes_low & ~UINT64_C(0xffff)) == 0 + && record->slot_offset < TT_SLOTS_PER_SEGMENT && record->slot_wrap != TT_WRAP_INVALID + && record->owner_instance != 0 && record->owner_instance <= 128 + && (record->terminal_status == TT_SLOT_COMMITTED + || record->terminal_status == TT_SLOT_ABORTED) + && record->format_version == CLUSTER_UNDO_TT_CTRC_RELEASE_VERSION + && record->flags == CLUSTER_UNDO_TT_CTRC_RELEASE_ALL_TOUCHED_ACKED; } static inline bool -cluster_undo_tt_ctrc_release_encode( - const xl_undo_tt_slot_ctrc_release_v1 *record, - uint8 bytes[CLUSTER_UNDO_TT_CTRC_RELEASE_BYTES]) +cluster_undo_tt_ctrc_release_encode(const xl_undo_tt_slot_ctrc_release_v1 *record, + uint8 bytes[CLUSTER_UNDO_TT_CTRC_RELEASE_BYTES]) { if (bytes != NULL) memset(bytes, 0, CLUSTER_UNDO_TT_CTRC_RELEASE_BYTES); if (bytes == NULL || !cluster_undo_tt_ctrc_release_valid(record)) return false; cluster_undo_tt_ctrc_put_u32_le(bytes + 0, record->segment_id); - cluster_undo_tt_ctrc_put_u32_le(bytes + 4, - record->segment_generation); + cluster_undo_tt_ctrc_put_u32_le(bytes + 4, record->segment_generation); cluster_undo_tt_ctrc_put_u32_le(bytes + 8, record->xid); cluster_undo_tt_ctrc_put_u32_le(bytes + 12, record->cluster_epoch); cluster_undo_tt_ctrc_put_u64_le(bytes + 16, record->root_id); cluster_undo_tt_ctrc_put_u64_le(bytes + 24, record->root_generation); cluster_undo_tt_ctrc_put_u64_le(bytes + 32, record->formation_epoch); - cluster_undo_tt_ctrc_put_u64_le(bytes + 40, - record->admission_record_generation); + cluster_undo_tt_ctrc_put_u64_le(bytes + 40, record->admission_record_generation); cluster_undo_tt_ctrc_put_u64_le(bytes + 48, record->seal_generation); cluster_undo_tt_ctrc_put_u64_le(bytes + 56, record->touched_nodes_low); cluster_undo_tt_ctrc_put_u64_le(bytes + 64, record->touched_nodes_high); - memcpy(bytes + 72, record->ack_set_digest, - sizeof(record->ack_set_digest)); + memcpy(bytes + 72, record->ack_set_digest, sizeof(record->ack_set_digest)); cluster_undo_tt_ctrc_put_u16_le(bytes + 88, record->slot_offset); cluster_undo_tt_ctrc_put_u16_le(bytes + 90, record->slot_wrap); bytes[92] = record->owner_instance; @@ -428,9 +413,8 @@ cluster_undo_tt_ctrc_release_encode( } static inline bool -cluster_undo_tt_ctrc_release_decode( - const uint8 bytes[CLUSTER_UNDO_TT_CTRC_RELEASE_BYTES], - xl_undo_tt_slot_ctrc_release_v1 *record_out) +cluster_undo_tt_ctrc_release_decode(const uint8 bytes[CLUSTER_UNDO_TT_CTRC_RELEASE_BYTES], + xl_undo_tt_slot_ctrc_release_v1 *record_out) { xl_undo_tt_slot_ctrc_release_v1 record; @@ -440,20 +424,17 @@ cluster_undo_tt_ctrc_release_decode( return false; memset(&record, 0, sizeof(record)); record.segment_id = cluster_undo_tt_ctrc_get_u32_le(bytes + 0); - record.segment_generation - = cluster_undo_tt_ctrc_get_u32_le(bytes + 4); + record.segment_generation = cluster_undo_tt_ctrc_get_u32_le(bytes + 4); record.xid = cluster_undo_tt_ctrc_get_u32_le(bytes + 8); record.cluster_epoch = cluster_undo_tt_ctrc_get_u32_le(bytes + 12); record.root_id = cluster_undo_tt_ctrc_get_u64_le(bytes + 16); record.root_generation = cluster_undo_tt_ctrc_get_u64_le(bytes + 24); record.formation_epoch = cluster_undo_tt_ctrc_get_u64_le(bytes + 32); - record.admission_record_generation - = cluster_undo_tt_ctrc_get_u64_le(bytes + 40); + record.admission_record_generation = cluster_undo_tt_ctrc_get_u64_le(bytes + 40); record.seal_generation = cluster_undo_tt_ctrc_get_u64_le(bytes + 48); record.touched_nodes_low = cluster_undo_tt_ctrc_get_u64_le(bytes + 56); record.touched_nodes_high = cluster_undo_tt_ctrc_get_u64_le(bytes + 64); - memcpy(record.ack_set_digest, bytes + 72, - sizeof(record.ack_set_digest)); + memcpy(record.ack_set_digest, bytes + 72, sizeof(record.ack_set_digest)); record.slot_offset = cluster_undo_tt_ctrc_get_u16_le(bytes + 88); record.slot_wrap = cluster_undo_tt_ctrc_get_u16_le(bytes + 90); record.owner_instance = bytes[92]; @@ -466,8 +447,7 @@ cluster_undo_tt_ctrc_release_decode( return true; } -typedef enum ClusterUndoTtCtrcReleaseRedoDecision -{ +typedef enum ClusterUndoTtCtrcReleaseRedoDecision { CLUSTER_UNDO_TT_CTRC_RELEASE_REDO_APPLY = 0, CLUSTER_UNDO_TT_CTRC_RELEASE_REDO_IDEMPOTENT, CLUSTER_UNDO_TT_CTRC_RELEASE_REDO_SKIP_STALE, @@ -475,8 +455,8 @@ typedef enum ClusterUndoTtCtrcReleaseRedoDecision } ClusterUndoTtCtrcReleaseRedoDecision; static inline ClusterUndoTtCtrcReleaseRedoDecision -cluster_undo_tt_ctrc_release_redo_decide(uint32 disk_generation, - const TTSlot *slot, const xl_undo_tt_slot_ctrc_release_v1 *record) +cluster_undo_tt_ctrc_release_redo_decide(uint32 disk_generation, const TTSlot *slot, + const xl_undo_tt_slot_ctrc_release_v1 *record) { if (slot == NULL || !cluster_undo_tt_ctrc_release_valid(record)) return CLUSTER_UNDO_TT_CTRC_RELEASE_REDO_CONFLICT; @@ -487,21 +467,19 @@ cluster_undo_tt_ctrc_release_redo_decide(uint32 disk_generation, if (slot->wrap > record->slot_wrap) return CLUSTER_UNDO_TT_CTRC_RELEASE_REDO_SKIP_STALE; if (slot->wrap < record->slot_wrap || slot->xid != record->xid - || slot->status != record->terminal_status - || (slot->flags & ~TT_SLOT_FLAGS_KNOWN) != 0 + || slot->status != record->terminal_status || (slot->flags & ~TT_SLOT_FLAGS_KNOWN) != 0 || (slot->status == TT_SLOT_COMMITTED) != SCN_VALID(slot->commit_scn)) return CLUSTER_UNDO_TT_CTRC_RELEASE_REDO_CONFLICT; return (slot->flags & TT_SLOT_FLAG_CTRC_RELEASE_PROVEN) != 0 - ? CLUSTER_UNDO_TT_CTRC_RELEASE_REDO_IDEMPOTENT - : CLUSTER_UNDO_TT_CTRC_RELEASE_REDO_APPLY; + ? CLUSTER_UNDO_TT_CTRC_RELEASE_REDO_IDEMPOTENT + : CLUSTER_UNDO_TT_CTRC_RELEASE_REDO_APPLY; } /* Shared cold/online exact block-0 primitive for the decoded 0xA0 record. */ extern ClusterUndoTtCtrcReleaseRedoDecision -cluster_tt_durable_ctrc_release_preflight_exact( - const xl_undo_tt_slot_ctrc_release_v1 *record); -extern void cluster_tt_durable_redo_ctrc_release_slot_exact( - const xl_undo_tt_slot_ctrc_release_v1 *record); +cluster_tt_durable_ctrc_release_preflight_exact(const xl_undo_tt_slot_ctrc_release_v1 *record); +extern void +cluster_tt_durable_redo_ctrc_release_slot_exact(const xl_undo_tt_slot_ctrc_release_v1 *record); /* * On-disk WAL payload for XLOG_UNDO_SEGMENT_RECYCLE (spec-3.13 D3). @@ -761,9 +739,8 @@ extern XLogRecPtr cluster_undo_emit_segment_init(uint8 instance, uint32 segment_ /* Publish one exact canonical ACTIVE transaction-table identity. */ extern XLogRecPtr cluster_undo_emit_tt_slot_bind(uint8 instance, uint32 segment_id, - uint32 segment_generation, - uint16 slot_offset, uint16 wrap, - TransactionId xid); + uint32 segment_generation, uint16 slot_offset, + uint16 wrap, TransactionId xid); /* * cluster_undo_emit_tt_slot_commit (spec-3.11 D3) @@ -787,27 +764,29 @@ extern XLogRecPtr cluster_undo_emit_tt_slot_commit(uint8 instance, uint32 segmen extern void cluster_tt_durable_redo_stamp_slot(uint8 instance, uint32 segment_id, uint16 slot_offset, uint16 wrap, TransactionId xid, SCN commit_scn); -extern void cluster_tt_durable_redo_stamp_slot_exact(uint8 instance, - uint32 segment_id, uint32 segment_generation, uint16 slot_offset, - uint16 wrap, TransactionId xid, SCN commit_scn); +extern void cluster_tt_durable_redo_stamp_slot_exact(uint8 instance, uint32 segment_id, + uint32 segment_generation, uint16 slot_offset, + uint16 wrap, TransactionId xid, + SCN commit_scn); /* spec-3.15 D5: emit XLOG_UNDO_TT_SLOT_ABORT (prepared rollback). */ extern XLogRecPtr cluster_undo_emit_tt_slot_abort(uint8 instance, uint32 segment_id, uint16 slot_offset, uint16 wrap, TransactionId xid); -extern XLogRecPtr cluster_undo_emit_tt_slot_abort_exact(uint8 instance, - uint32 segment_id, uint32 segment_generation, uint16 slot_offset, - uint16 wrap, TransactionId xid); +extern XLogRecPtr cluster_undo_emit_tt_slot_abort_exact(uint8 instance, uint32 segment_id, + uint32 segment_generation, + uint16 slot_offset, uint16 wrap, + TransactionId xid); /* spec-4.8 D7-A: emit XLOG_UNDO_TT_SLOT_SET_HEAD (durable undo-chain head). */ extern XLogRecPtr cluster_undo_emit_tt_slot_set_head(uint8 instance, uint32 segment_id, - uint16 slot_offset, uint16 wrap, - TransactionId xid, UBA first_undo_block); + uint16 slot_offset, uint16 wrap, + TransactionId xid, UBA first_undo_block); /* Spec 8.4D: insert the exact 96-byte CTRC release certificate. The caller * must flush the returned LSN before publishing the release bit. */ -extern XLogRecPtr cluster_undo_xlog_insert_tt_ctrc_release( - const xl_undo_tt_slot_ctrc_release_v1 *record); +extern XLogRecPtr +cluster_undo_xlog_insert_tt_ctrc_release(const xl_undo_tt_slot_ctrc_release_v1 *record); /* spec-3.13 D3: emit XLOG_UNDO_SEGMENT_RECYCLE (caller XLogFlush + pwrite + fsync). */ extern XLogRecPtr cluster_undo_emit_segment_recycle(uint8 instance, uint32 segment_id, diff --git a/src/test/cluster_regress/expected/quorum_voting_smoke.out b/src/test/cluster_regress/expected/quorum_voting_smoke.out index 3636409f190..8795c7b920a 100644 --- a/src/test/cluster_regress/expected/quorum_voting_smoke.out +++ b/src/test/cluster_regress/expected/quorum_voting_smoke.out @@ -27,7 +27,7 @@ SELECT name, vartype, context 'cluster.quorum_poll_interval_ms', 'cluster.voting_disk_io_timeout_ms', 'cluster.voting_disk_size_bytes') - ORDER BY name; + ORDER BY name COLLATE "C"; name | vartype | context -----------------------------------+---------+------------ cluster.quorum_poll_interval_ms | integer | postmaster diff --git a/src/test/cluster_regress/sql/quorum_voting_smoke.sql b/src/test/cluster_regress/sql/quorum_voting_smoke.sql index e3b5358555e..9e92c588650 100644 --- a/src/test/cluster_regress/sql/quorum_voting_smoke.sql +++ b/src/test/cluster_regress/sql/quorum_voting_smoke.sql @@ -27,7 +27,7 @@ SELECT name, vartype, context 'cluster.quorum_poll_interval_ms', 'cluster.voting_disk_io_timeout_ms', 'cluster.voting_disk_size_bytes') - ORDER BY name; + ORDER BY name COLLATE "C"; -- ---------- -- Block 2: pg_cluster_quorum_state view exists with 7 columns. diff --git a/src/test/cluster_tap/t/030_acceptance.pl b/src/test/cluster_tap/t/030_acceptance.pl index cade4d0ab19..c5355f37134 100644 --- a/src/test/cluster_tap/t/030_acceptance.pl +++ b/src/test/cluster_tap/t/030_acceptance.pl @@ -393,10 +393,20 @@ 'SELECT count(*) >= 30 FROM pg_cluster_state') eq 't', 'O1 pg_cluster_state returns >= 30 rows (20 inject + others)'); +my @state_categories = (qw( + advisory block_format buffer_format catalog cf cluster_cssd cluster_stats + conf cr cr_coord cr_pool ctrc diag dl gcs gcs_recovery ges grd grd_recovery + guc hang hw ic inject ir ko lck lmd lmon lms multixact_current normal_start + pcm pgstat phase r4 reconfig reconfig_join reconfig_touched recovery + resolver_cache scn sequence shared_fs shmem sinval smart_fusion ts tt_2pc + tt_recovery tt_status tt_status_hint undo undo_cleaner visibility wal_thread + write_fence xid_stripe xnode_lever xnode_profile +), map { "undo.cleaner.worker.$_" } 0 .. 7); is($node->safe_psql('postgres', - q{SELECT string_agg(DISTINCT category, ',' ORDER BY category) FROM pg_cluster_state}), - 'advisory,block_format,buffer_format,catalog,cf,cluster_cssd,cluster_stats,conf,cr,cr_coord,cr_pool,diag,dl,gcs,gcs_recovery,ges,grd,grd_recovery,guc,hang,hw,ic,inject,ir,ko,lck,lmd,lmon,lms,multixact_current,pcm,pgstat,phase,r4,reconfig,reconfig_join,reconfig_touched,recovery,resolver_cache,scn,sequence,shared_fs,shmem,sinval,smart_fusion,ts,tt_2pc,tt_recovery,tt_status,tt_status_hint,undo,undo_cleaner,visibility,wal_thread,write_fence,xid_stripe,xnode_lever,xnode_profile', - 'O2 pg_cluster_state has all 58 categories (Stage 8 R4 adds observation events)'); + q{SELECT string_agg(DISTINCT category COLLATE "C", ',' + ORDER BY category COLLATE "C") FROM pg_cluster_state}), + join(',', sort @state_categories), + 'O2 pg_cluster_state has all 68 categories, including normal start and cleaner workers'); is($node->safe_psql('postgres', q{SELECT count(*) FROM pg_cluster_state WHERE value IS NULL}), diff --git a/src/test/cluster_tap/t/031_undo_publication_refusal.pl b/src/test/cluster_tap/t/031_undo_publication_refusal.pl new file mode 100644 index 00000000000..c9ed8fe71e8 --- /dev/null +++ b/src/test/cluster_tap/t/031_undo_publication_refusal.pl @@ -0,0 +1,53 @@ +#------------------------------------------------------------------------- +# +# 031_undo_publication_refusal.pl +# PGRAC: an unadmitted undo publication must remain a SQL error, not a +# backend assertion failure. Exercise real ERROR recovery twice so a +# leaked allocator LWLock cannot hide behind the first refusal. +# +# IDENTIFICATION +# src/test/cluster_tap/t/031_undo_publication_refusal.pl +# +# Author: SqlRush +# Portions Copyright (c) 2026, pgrac contributors +# +#------------------------------------------------------------------------- + +use strict; +use warnings; + +use PostgreSQL::Test::Cluster; +use PostgreSQL::Test::Utils; +use Test::More; + +my $node = PostgreSQL::Test::Cluster->new('undo_refusal'); +$node->init; +$node->append_conf('postgresql.conf', + "cluster.enabled = on\n" + . "cluster.node_id = 0\n" + . "cluster.allow_single_node = on\n" + . "autovacuum = off\n"); +$node->start; +$node->safe_psql('postgres', 'CREATE TABLE undo_refusal (id int)'); +my $started = $node->safe_psql('postgres', 'SELECT pg_postmaster_start_time()'); + +# No voting-backed undo root is installed: authority rejection is required. +for my $attempt (1 .. 2) +{ + my ($out, $err); + my $rc = $node->psql('postgres', 'INSERT INTO undo_refusal VALUES (1)', + stdout => \$out, stderr => \$err, + extra_params => [ '-v', 'VERBOSITY=verbose' ], timeout => 15); + is($rc, 3, "attempt $attempt returns an ordinary SQL error"); + like($err, qr/55000: undo segment first publication refused:/, + "attempt $attempt preserves the authority refusal"); + is($node->safe_psql('postgres', 'SELECT pg_postmaster_start_time()'), + $started, "attempt $attempt does not restart the server"); + is($node->safe_psql('postgres', 'SELECT count(*) FROM undo_refusal'), + '0', "attempt $attempt publishes no row"); +} + +unlike(slurp_file($node->logfile), qr/TRAP:|PANIC:|terminated by signal/, + 'error cleanup does not crash a backend'); +$node->stop('fast'); +done_testing(); diff --git a/src/test/cluster_unit/Makefile b/src/test/cluster_unit/Makefile index 0f89e63aa2c..3b584551b38 100644 --- a/src/test/cluster_unit/Makefile +++ b/src/test/cluster_unit/Makefile @@ -30,8 +30,23 @@ else R4_RUNTIME_VIS_TEST_DEAD_STRIP = -Wl,--gc-sections endif +# The backend CRC dispatcher logs its hardware selection on some platforms. +# Retain that real dispatcher; supply a fail-stop standalone logging boundary. +CLUSTER_UNIT_PORT_LIBS = $(top_builddir)/src/port/libpgport_srv.a cluster_unit_port_stubs.o +CLUSTER_UNIT_CLANG ?= $(if $(strip $(CLANG)),$(CLANG),clang) + +# Standalone fixtures have no ResourceOwner. Use PostgreSQL's actual frontend +# hash provider with the same configured algorithm, not a fake digest or the +# full frontend archive (which would override the fixture's memory allocator). +ifeq ($(with_ssl),openssl) +CLUSTER_UNIT_CRYPTOHASH_O = $(top_builddir)/src/common/cryptohash_openssl.o +else +CLUSTER_UNIT_CRYPTOHASH_O = $(top_builddir)/src/common/cryptohash.o +endif + # Test source files (each becomes a standalone executable) -TESTS = test_cluster_basic test_cluster_version test_cluster_backend_types \ +TESTS = test_cluster_basic test_cluster_version test_cluster_backend_types test_cluster_port_runtime \ + test_cluster_heap_prepare_diagnostic \ test_cluster_r4_production_reachability test_cluster_heap_update_temp_lock test_cluster_heap_dml_lifetime \ test_cluster_gcs_reqid test_cluster_ctrc_cleaner test_cluster_ctrc_dispatch test_cluster_heap_receipt \ test_cluster_ctrc_capacity test_cluster_undo_cleaner_capacity test_cluster_ctrc_itl_reuse test_cluster_normal_stop test_cluster_ic_chunk_stop test_cluster_gcs_stop test_cluster_sinval_stop test_cluster_ko_stop test_cluster_rdma_stop test_cluster_rdma_stop_disabled test_cluster_ic_stop \ @@ -65,7 +80,7 @@ TESTS = test_cluster_basic test_cluster_version test_cluster_backend_types \ test_cluster_retention test_cluster_undo_cleaner test_cluster_visibility_variants test_cluster_writer_chain test_cluster_tt_2pc \ test_cluster_stage3_acceptance test_cluster_undo_buf test_cluster_undo_extent \ test_cluster_wal_thread test_cluster_wal_state test_cluster_wal_state_rmw test_cluster_recovery_plan \ - test_cluster_backup \ + test_cluster_backup test_cluster_retained_remote \ test_cluster_recovery_worker test_cluster_recovery_merge test_cluster_remote_xact \ test_cluster_block_apply test_cluster_thread_apply test_cluster_thread_replay \ test_cluster_thread_driver test_cluster_thread_orchestrator \ @@ -152,6 +167,10 @@ TESTS = test_cluster_basic test_cluster_version test_cluster_backend_types \ # Path to the cluster_version object (no PG deps, safe to link standalone). TESTS += test_cluster_tt_abort_owner test_cluster_tt_active_owner TESTS += test_cluster_cr_native_origin test_cluster_cr_mvcc_origin +# Keep registration before all expands its prerequisite list. +TESTS += test_cluster_pcm_aux_consumer test_cluster_pcm_aux_reobserve test_cluster_resource_x_terminal_ingress +TESTS += test_cluster_pcm_aux_mutation test_cluster_heap_extend_current +TESTS += test_cluster_cr_inline_stop CLUSTER_VERSION_O = $(top_builddir)/src/backend/cluster/cluster_version.o @@ -170,6 +189,9 @@ override CPPFLAGS := -I. -I$(top_srcdir)/src/include $(CPPFLAGS) # ---------- all: $(TESTS) check_resource_x_send_c1 +cluster_unit_port_stubs.o: cluster_unit_port_stubs.c + + CLUSTER_SHMEM_O = $(top_builddir)/src/backend/cluster/cluster_shmem.o CLUSTER_SIGNAL_O = $(top_builddir)/src/backend/cluster/cluster_signal.o CLUSTER_VIEWS_O = $(top_builddir)/src/backend/cluster/cluster_views.o @@ -236,24 +258,24 @@ test_cluster_resource_x_identity: test_cluster_resource_x_identity.c \ cluster_resource_x_wire_f076.h unit_test.h \ $(CLUSTER_RESOURCE_X_IDENTITY_O) $(CC) $(CFLAGS) $(CPPFLAGS) $< $(CLUSTER_RESOURCE_X_IDENTITY_O) \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ test_cluster_resource_x_node_wire: test_cluster_resource_x_node_wire.c unit_test.h \ $(CLUSTER_RESOURCE_X_IDENTITY_O) $(CLUSTER_RESOURCE_X_NODE_WIRE_O) $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_RESOURCE_X_IDENTITY_O) $(CLUSTER_RESOURCE_X_NODE_WIRE_O) \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ test_cluster_resource_x_retry: test_cluster_resource_x_retry.c unit_test.h \ $(CLUSTER_RESOURCE_X_IDENTITY_O) $(CLUSTER_RESOURCE_X_RETRY_O) $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_RESOURCE_X_IDENTITY_O) $(CLUSTER_RESOURCE_X_RETRY_O) \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ test_cluster_resource_x_handoff: test_cluster_resource_x_handoff.c unit_test.h \ $(CLUSTER_RESOURCE_X_IDENTITY_O) $(CC) $(CFLAGS) $(CPPFLAGS) $< $(CLUSTER_RESOURCE_X_IDENTITY_O) \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-5.15 D9: test_cluster_membership links cluster_membership.o (pure layer: # monotonic-incarnation vet + membership-state decision table). The pure layer @@ -264,7 +286,7 @@ test_cluster_membership: test_cluster_membership.c unit_test.h $(CLUSTER_VERSION $(CLUSTER_MEMBERSHIP_O) $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_VERSION_O) $(CLUSTER_MEMBERSHIP_O) \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-7.3 D1: test_cluster_lms_shard links cluster_lms_shard.o (pure layer: # BufferTag -> worker shard map). Links libpgcommon_srv.a for @@ -276,7 +298,7 @@ test_cluster_lms_shard: test_cluster_lms_shard.c unit_test.h $(CLUSTER_VERSION_O $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_VERSION_O) $(CLUSTER_LMS_SHARD_O) $(CLUSTER_LMS_LIFECYCLE_O) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-7.3 D5: test_cluster_gcs_block_dedup links cluster_gcs_block_dedup.o # (real per-worker sharded lookup/install/GC/counter paths) + cluster_lms_shard.o, @@ -288,7 +310,7 @@ test_cluster_gcs_block_dedup: test_cluster_gcs_block_dedup.c unit_test.h $(CLUST $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_VERSION_O) $(CLUSTER_GCS_BLOCK_DEDUP_O) $(CLUSTER_LMS_SHARD_O) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-7.3 D9: test_cluster_gcs_block_shard links cluster_gcs_block_shard.o # (the REAL staging-path payload -> worker router, extracted as a pure file) @@ -302,7 +324,7 @@ test_cluster_gcs_block_shard: test_cluster_gcs_block_shard.c unit_test.h $(CLUST $(CLUSTER_VERSION_O) $(CLUSTER_GCS_BLOCK_SHARD_O) $(CLUSTER_LMS_SHARD_O) \ $(CLUSTER_RESOURCE_X_IDENTITY_O) $(CLUSTER_RESOURCE_X_NODE_WIRE_O) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-6.5 D0/D1: test_cluster_backup links only the dependency-light # manifest/PITR helper object. Runtime SQL/shmem code stays in @@ -312,11 +334,8 @@ test_cluster_backup: test_cluster_backup.c unit_test.h $(CLUSTER_VERSION_O) \ $(CLUSTER_BACKUP_MANIFEST_O) $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_VERSION_O) $(CLUSTER_BACKUP_MANIFEST_O) \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ -TESTS += test_cluster_pcm_aux_consumer test_cluster_pcm_aux_reobserve test_cluster_resource_x_terminal_ingress -TESTS += test_cluster_pcm_aux_mutation test_cluster_heap_extend_current -TESTS += test_cluster_cr_inline_stop # Most tests link only cluster_version.o. test_cluster_guc / # test_cluster_shmem / test_cluster_signal / test_cluster_views / @@ -331,7 +350,7 @@ SIMPLE_TESTS := $(filter-out test_cluster_cr_native_origin test_cluster_cr_mvcc_ test_cluster_resource_x_identity test_cluster_resource_x_node_wire \ test_cluster_resource_x_terminal_ingress \ test_cluster_resource_x_retry \ - test_cluster_resource_x_handoff \ + test_cluster_resource_x_handoff test_cluster_retained_remote \ test_cluster_r4_d10_hint_source test_cluster_r4_d10_tt_source \ test_cluster_r4_d10_multi_source test_cluster_sf_dep test_cluster_wal_state_rmw \ test_cluster_ges_reply_wait \ @@ -359,7 +378,8 @@ SIMPLE_TESTS := $(filter-out test_pgrac_fenced_config test_pgrac_fenced_core \ test_pgrac_fenced_coordinator \ test_pgrac_fenced_ipmi test_pgrac_fenced_ipmi_exec \ test_pgrac_fenced_ctl,$(SIMPLE_TESTS)) -SIMPLE_TESTS := $(filter-out test_cluster_page_edge,$(SIMPLE_TESTS)) +SIMPLE_TESTS := $(filter-out test_cluster_page_edge test_cluster_port_runtime,$(SIMPLE_TESTS)) +SIMPLE_TESTS := $(filter-out test_cluster_heap_prepare_diagnostic,$(SIMPLE_TESTS)) SIMPLE_TESTS := $(filter-out test_cluster_hw_handoff,$(SIMPLE_TESTS)) SIMPLE_TESTS := $(filter-out test_cluster_page_edge_reader,$(SIMPLE_TESTS)) SIMPLE_TESTS := $(filter-out test_cluster_heap_epq_wait,$(SIMPLE_TESTS)) @@ -390,7 +410,7 @@ test_cluster_epoch: test_cluster_epoch.c unit_test.h $(CLUSTER_VERSION_O) \ $(CLUSTER_EPOCH_O) $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_VERSION_O) $(CLUSTER_EPOCH_O) \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-5.1a D6: test_cluster_ges_mode links cluster_ges_mode.o (pure layer: # const matrix + compat / convert-class / DLM-alias / PG-name helpers). @@ -400,7 +420,7 @@ test_cluster_ges_mode: test_cluster_ges_mode.c unit_test.h $(CLUSTER_VERSION_O) $(CLUSTER_GES_MODE_O) $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_VERSION_O) $(CLUSTER_GES_MODE_O) \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-5.4 D11: test_cluster_sequence links cluster_sequence.o (pure layer: # SQ resid encoding + direction-aware batch allocator + instance-cache @@ -411,7 +431,7 @@ test_cluster_sequence: test_cluster_sequence.c unit_test.h $(CLUSTER_VERSION_O) $(CLUSTER_SEQUENCE_O) $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_VERSION_O) $(CLUSTER_SEQUENCE_O) \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-5.7a D1: test_cluster_hw links cluster_hw.o (pure layer: HW resid # encoding + three-state extend classifier + master-side batch allocator @@ -422,7 +442,7 @@ test_cluster_hw: test_cluster_hw.c unit_test.h $(CLUSTER_VERSION_O) \ $(CLUSTER_HW_O) $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_VERSION_O) $(CLUSTER_HW_O) \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-5.7 D4: test_cluster_dl links cluster_dl.o (pure DL resid encoder) + # cluster_hw.o (cluster_hw_resid_encode, for the DL-vs-HW distinctness test). @@ -431,7 +451,7 @@ test_cluster_dl: test_cluster_dl.c unit_test.h $(CLUSTER_VERSION_O) \ $(CLUSTER_DL_O) $(CLUSTER_HW_O) $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_VERSION_O) $(CLUSTER_DL_O) $(CLUSTER_HW_O) \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-5.7 §3.1d (v1.5 amend): test_cluster_extend_gate links cluster_extend_gate.o # (pure liveness engage classifier + wrapper). The wrapper's six runtime @@ -445,7 +465,7 @@ test_cluster_extend_gate: test_cluster_extend_gate.c unit_test.h $(CLUSTER_VERSI $(CLUSTER_EXTEND_GATE_O) $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_VERSION_O) $(CLUSTER_EXTEND_GATE_O) \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-5.7 D8 / RF-ROOT P3: test_cluster_recovery_serial links the pure IR # encoder plus the typed acquire/release backend. The test supplies bounded @@ -458,7 +478,7 @@ test_cluster_recovery_serial: test_cluster_recovery_serial.c unit_test.h $(CLUST $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_VERSION_O) $(CLUSTER_IR_O) $(CLUSTER_IR_LOCK_O) \ $(CLUSTER_DL_O) $(CLUSTER_HW_O) \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ CLUSTER_EXTERNAL_FENCE_O = test_cluster_external_fence_product.o PGRAC_EXTERNAL_FENCE_PROTOCOL_O = \ @@ -476,7 +496,7 @@ test_cluster_external_fence: test_cluster_external_fence.c unit_test.h \ $(CC) $(CFLAGS) $(CPPFLAGS) $< $(CLUSTER_EXTERNAL_FENCE_O) \ $(PGRAC_EXTERNAL_FENCE_PROTOCOL_O) \ $(top_builddir)/src/common/libpgcommon.a \ - $(top_builddir)/src/port/libpgport_srv.a $(LDFLAGS) -lssl -lcrypto -o $@ + $(CLUSTER_UNIT_PORT_LIBS) $(LDFLAGS) -lssl -lcrypto -o $@ # spec-5.7 D5: test_cluster_ts links cluster_ts.o (pure TT resid encoders) + # cluster_ir.o/cluster_dl.o/cluster_hw.o (resid encoders, for the TT-vs-others @@ -487,7 +507,7 @@ test_cluster_ts: test_cluster_ts.c unit_test.h $(CLUSTER_VERSION_O) \ $(CLUSTER_TS_O) $(CLUSTER_IR_O) $(CLUSTER_DL_O) $(CLUSTER_HW_O) $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_VERSION_O) $(CLUSTER_TS_O) $(CLUSTER_IR_O) $(CLUSTER_DL_O) $(CLUSTER_HW_O) \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-5.7 D6: test_cluster_ko links cluster_ko.o (pure KO resid encoder) + # cluster_dl.o/cluster_ir.o/cluster_hw.o (resid encoders, for the KO-vs-others @@ -498,7 +518,7 @@ test_cluster_ko: test_cluster_ko.c unit_test.h $(CLUSTER_VERSION_O) \ $(CLUSTER_KO_O) $(CLUSTER_DL_O) $(CLUSTER_IR_O) $(CLUSTER_HW_O) $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_VERSION_O) $(CLUSTER_KO_O) $(CLUSTER_DL_O) $(CLUSTER_IR_O) $(CLUSTER_HW_O) \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-5.11 D9: test_cluster_hang links cluster_hang_policy.o (the pure Hang # Manager decision/policy layer: threshold / wait-source tag / exclusion / @@ -510,7 +530,7 @@ test_cluster_hang: test_cluster_hang.c unit_test.h $(CLUSTER_VERSION_O) \ $(CLUSTER_HANG_POLICY_O) $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_VERSION_O) $(CLUSTER_HANG_POLICY_O) \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-5.12 D9: test_cluster_hang_resolve links cluster_hang_resolve_policy.o # (the pure Hang Manager disposition decision layer: victim score + comparator, @@ -524,7 +544,7 @@ test_cluster_hang_resolve: test_cluster_hang_resolve.c unit_test.h $(CLUSTER_VER $(CLUSTER_HANG_RESOLVE_POLICY_O) $(CLUSTER_HANG_POLICY_O) $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_VERSION_O) $(CLUSTER_HANG_RESOLVE_POLICY_O) $(CLUSTER_HANG_POLICY_O) \ - $(top_builddir)/src/port/libpgport_srv.a -lm -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -lm -o $@ # spec-5.20 D8: test_cluster_hang_acceptance links the same two pure Hang # Manager policy objects as the 5.11/5.12 unit tests — cluster_hang_resolve_policy.o @@ -536,7 +556,7 @@ test_cluster_hang_acceptance: test_cluster_hang_acceptance.c unit_test.h $(CLUST $(CLUSTER_HANG_RESOLVE_POLICY_O) $(CLUSTER_HANG_POLICY_O) $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_VERSION_O) $(CLUSTER_HANG_RESOLVE_POLICY_O) $(CLUSTER_HANG_POLICY_O) \ - $(top_builddir)/src/port/libpgport_srv.a -lm -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -lm -o $@ # spec-6.12b: test_cluster_cr_server_policy links cluster_cr_server_policy.o # (the pure FULL/PARTIAL/DENY split over write_scn-DESC chain origins). No @@ -555,7 +575,7 @@ test_cluster_cr_server_policy: test_cluster_cr_server_policy.c unit_test.h $(CLU $(CLUSTER_VERSION_O) $(CLUSTER_CR_SERVER_POLICY_O) $(CLUSTER_CR_SERVER_C0_TEST_O) \ $(top_builddir)/src/backend/cluster/cluster_undo_retention.o \ $(R4_RUNTIME_VIS_TEST_DEAD_STRIP) \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-6.12i: test_cluster_runtime_visibility links cluster_runtime_visibility_policy.o # (the pure D-i2 live-authority window gate: epoch match + hwm >= anchor_lsn, @@ -565,7 +585,7 @@ test_cluster_runtime_visibility: test_cluster_runtime_visibility.c unit_test.h $ $(CLUSTER_RUNTIME_VIS_POLICY_O) $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_VERSION_O) $(CLUSTER_RUNTIME_VIS_POLICY_O) \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-5.14 D1: test_cluster_touched_peers links cluster_touched_peers.o (the # pure per-tx touched bitmap: stamp / poison / intersect / reset / DSM merge). @@ -577,7 +597,7 @@ test_cluster_touched_peers: test_cluster_touched_peers.c unit_test.h $(CLUSTER_V $(CLUSTER_TOUCHED_PEERS_O) $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_VERSION_O) $(CLUSTER_TOUCHED_PEERS_O) \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-5.13 D15: test_cluster_clean_leave links cluster_clean_leave_policy.o (the # pure clean-leave decision layer: phase-FSM transition validity, writable-only @@ -684,7 +704,7 @@ test_cluster_normal_stop: test_cluster_normal_stop.c test_cluster_normal_stop_cl $(CC) $(CFLAGS) $(CPPFLAGS) -ffunction-sections -fdata-sections $< \ $(CLUSTER_CLEAN_LEAVE_POLICY_O) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a \ + $(CLUSTER_UNIT_PORT_LIBS) \ $(CLUSTER_UNDO_TEST_GC_SECTIONS) -o $@ test_cluster_clean_leave: test_cluster_clean_leave.c unit_test.h $(CLUSTER_VERSION_O) \ @@ -712,15 +732,15 @@ test_cluster_mrp_stop: test_cluster_mrp_stop.c unit_test.h \ $(top_srcdir)/src/include/cluster/cluster_clean_leave.h $(CC) $(CFLAGS) $(CPPFLAGS) -ffunction-sections -fdata-sections $< \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a $(CLUSTER_UNDO_TEST_GC_SECTIONS) -o $@ + $(CLUSTER_UNIT_PORT_LIBS) $(CLUSTER_UNDO_TEST_GC_SECTIONS) -o $@ -test_cluster_backup_stop: test_cluster_backup_stop.c unit_test.h \ +test_cluster_backup_stop: test_cluster_backup_stop.c unit_test.h test_cluster_normal_cold_scn.inc \ $(top_srcdir)/src/backend/cluster/cluster_backup.c \ $(top_srcdir)/src/include/cluster/cluster_clean_leave.h $(CLUSTER_BACKUP_MANIFEST_O) $(CC) $(CFLAGS) $(CPPFLAGS) -ffunction-sections -fdata-sections $< \ $(CLUSTER_BACKUP_MANIFEST_O) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a $(CLUSTER_UNDO_TEST_GC_SECTIONS) -o $@ + $(CLUSTER_UNIT_PORT_LIBS) $(CLUSTER_UNDO_TEST_GC_SECTIONS) -o $@ test_cluster_recovery_stop: test_cluster_recovery_stop.c unit_test.h \ $(top_srcdir)/src/backend/cluster/cluster_recovery_plan.c \ @@ -728,28 +748,28 @@ test_cluster_recovery_stop: test_cluster_recovery_stop.c unit_test.h \ $(top_srcdir)/src/include/cluster/cluster_clean_leave.h $(CC) $(CFLAGS) $(CPPFLAGS) -ffunction-sections -fdata-sections $< \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a $(CLUSTER_UNDO_TEST_GC_SECTIONS) -o $@ + $(CLUSTER_UNIT_PORT_LIBS) $(CLUSTER_UNDO_TEST_GC_SECTIONS) -o $@ CLUSTER_NODE_REMOVE_POLICY_O = $(top_builddir)/src/backend/cluster/cluster_node_remove_policy.o test_cluster_node_remove_stop: test_cluster_node_remove_stop.c unit_test.h \ $(top_srcdir)/src/backend/cluster/cluster_node_remove.c \ $(top_srcdir)/src/include/cluster/cluster_clean_leave.h $(CLUSTER_NODE_REMOVE_POLICY_O) $(CC) $(CFLAGS) $(CPPFLAGS) -ffunction-sections -fdata-sections $< \ - $(CLUSTER_NODE_REMOVE_POLICY_O) $(top_builddir)/src/port/libpgport_srv.a \ + $(CLUSTER_NODE_REMOVE_POLICY_O) $(CLUSTER_UNIT_PORT_LIBS) \ $(CLUSTER_UNDO_TEST_GC_SECTIONS) -o $@ test_cluster_node_remove: test_cluster_node_remove.c unit_test.h $(CLUSTER_VERSION_O) \ $(CLUSTER_NODE_REMOVE_POLICY_O) $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_VERSION_O) $(CLUSTER_NODE_REMOVE_POLICY_O) \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-5.15A §2.4: exact 96-byte replacement episode local mirror and # dependency-free structural/identity/generation validation. test_cluster_epoch_ballot_codec: test_cluster_epoch_ballot_codec.c unit_test.h \ $(CLUSTER_EPOCH_BALLOT_O) $(CC) $(CFLAGS) $(CPPFLAGS) $< $(CLUSTER_EPOCH_BALLOT_O) \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ test_cluster_replacement_episode: test_cluster_replacement_episode.c unit_test.h \ $(CLUSTER_REPLACEMENT_EPISODE_O) @@ -759,7 +779,7 @@ test_cluster_replacement_episode: test_cluster_replacement_episode.c unit_test.h test_cluster_replacement_request: test_cluster_replacement_request.c unit_test.h \ $(CLUSTER_REPLACEMENT_REQUEST_O) $(CC) $(CFLAGS) $(CPPFLAGS) $< $(CLUSTER_REPLACEMENT_REQUEST_O) \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-5.15A §2.3: dependency-free opcode-18 exact 72-byte LE codec. test_cluster_replacement_wire: test_cluster_replacement_wire.c unit_test.h \ @@ -771,7 +791,7 @@ test_cluster_replacement_wire: test_cluster_replacement_wire.c unit_test.h \ test_cluster_undo_root_descriptor: test_cluster_undo_root_descriptor.c unit_test.h \ $(CLUSTER_UNDO_ROOT_DESCRIPTOR_O) $(CC) $(CFLAGS) $(CPPFLAGS) $< $(CLUSTER_UNDO_ROOT_DESCRIPTOR_O) \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # RF-ROOT P9 verification (cold-formation cold-formation ruling): pure # 512-byte formation-commit-marker codec (encode/decode + wire CRC over @@ -782,7 +802,7 @@ CLUSTER_FORMATION_MARKER_O = $(top_builddir)/src/backend/cluster/cluster_formati test_cluster_formation_marker: test_cluster_formation_marker.c unit_test.h \ $(CLUSTER_FORMATION_MARKER_O) $(CC) $(CFLAGS) $(CPPFLAGS) $< $(CLUSTER_FORMATION_MARKER_O) \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # RF-PAGE PGDEL-01: PageVersion semantic type (valid/exact-equality), # §3.2 expected-before -> result-version admission decision with the §3.3 @@ -805,7 +825,7 @@ test_cluster_page_edge_reader: test_cluster_page_edge_reader.c unit_test.h \ xlogreader_fs.o $(XLOG_PAGE_EDGE_ENCODER_O) $(CC) $(CFLAGS) $(CPPFLAGS) $< xlogreader_fs.o \ $(XLOG_PAGE_EDGE_ENCODER_O) $(top_builddir)/src/common/libpgcommon.a \ - $(top_builddir)/src/port/libpgport_srv.a $(LDFLAGS) \ + $(CLUSTER_UNIT_PORT_LIBS) $(LDFLAGS) \ -lssl -lcrypto -llz4 -lzstd -o $@ CLUSTER_RF_ROUTE_O = $(top_builddir)/src/backend/cluster/cluster_rf_route.o @@ -819,7 +839,7 @@ test_cluster_rf_route: test_cluster_rf_route.c unit_test.h \ $(CLUSTER_RF_ROUTE_O) $(CC) $(CFLAGS) $(CPPFLAGS) $< $(CLUSTER_RF_ROUTE_O) \ $(top_builddir)/src/common/libpgcommon.a \ - $(top_builddir)/src/port/libpgport_srv.a $(LDFLAGS) \ + $(CLUSTER_UNIT_PORT_LIBS) $(LDFLAGS) \ -lssl -lcrypto -o $@ CLUSTER_PAGE_DETACHED_O = \ @@ -833,7 +853,7 @@ test_cluster_page_detached: test_cluster_page_detached.c unit_test.h \ $(CC) $(CFLAGS) $(CPPFLAGS) $< $(CLUSTER_PAGE_DETACHED_O) \ $(CLUSTER_RF_ROUTE_O) $(CLUSTER_BLOCK_APPLY_O) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ CLUSTER_PAGE_REPLAY_BATCH_O = cluster_page_replay_batch_test.o @@ -848,7 +868,7 @@ test_cluster_page_guard: test_cluster_page_guard.c unit_test.h \ $(CLUSTER_PAGE_GUARD_O) $(CC) $(CFLAGS) $(CPPFLAGS) $< $(CLUSTER_PAGE_GUARD_O) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ CLUSTER_PAGE_AUTHORITY_O = cluster_page_authority_test.o @@ -862,7 +882,7 @@ test_cluster_page_authority: test_cluster_page_authority.c unit_test.h \ $(CC) $(CFLAGS) $(CPPFLAGS) -DUSE_CLUSTER_UNIT $< $(CLUSTER_PAGE_AUTHORITY_O) \ $(CLUSTER_PAGE_GUARD_O) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ CLUSTER_THREAD_RECOVERY_AUTHORITY_O = \ cluster_thread_recovery_authority_test.o \ @@ -884,7 +904,7 @@ test_cluster_thread_recovery_authority: \ $(CC) $(CFLAGS) $(CPPFLAGS) -DUSE_CLUSTER_UNIT $< \ $(CLUSTER_THREAD_RECOVERY_AUTHORITY_O) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ CLUSTER_THREAD_RECOVERY_FABRIC_PLAN_O = \ cluster_thread_recovery_fabric_plan_test.o @@ -900,7 +920,7 @@ test_cluster_thread_recovery_fabric_plan: \ $(CC) $(CFLAGS) $(CPPFLAGS) -DUSE_CLUSTER_UNIT $< \ $(CLUSTER_THREAD_RECOVERY_FABRIC_PLAN_O) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ CLUSTER_THREAD_RECOVERY_FABRIC_APPLY_O = \ cluster_thread_recovery_fabric_apply_test.o @@ -916,7 +936,7 @@ test_cluster_thread_recovery_fabric_apply: \ $(CC) $(CFLAGS) $(CPPFLAGS) -DUSE_CLUSTER_UNIT $< \ $(CLUSTER_THREAD_RECOVERY_FABRIC_APPLY_O) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ CLUSTER_THREAD_RECOVERY_FABRIC_SCAN_O = \ cluster_thread_recovery_fabric_scan_test.o @@ -932,7 +952,7 @@ test_cluster_thread_recovery_fabric_scan: \ $(CC) $(CFLAGS) $(CPPFLAGS) -DUSE_CLUSTER_UNIT $< \ $(CLUSTER_THREAD_RECOVERY_FABRIC_SCAN_O) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ CLUSTER_THREAD_RECOVERY_FABRIC_EXECUTE_O = \ cluster_thread_recovery_fabric_execute_test.o @@ -948,7 +968,7 @@ test_cluster_thread_recovery_fabric_execute: \ $(CC) $(CFLAGS) $(CPPFLAGS) -DUSE_CLUSTER_UNIT $< \ $(CLUSTER_THREAD_RECOVERY_FABRIC_EXECUTE_O) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ CLUSTER_PAGE_ONLINE_PLAN_O = cluster_page_online_plan_test.o @@ -962,7 +982,7 @@ test_cluster_page_online_plan: test_cluster_page_online_plan.c unit_test.h \ $(CC) $(CFLAGS) $(CPPFLAGS) -DUSE_CLUSTER_UNIT $< \ $(CLUSTER_PAGE_ONLINE_PLAN_O) \ $(top_builddir)/src/common/libpgcommon.a \ - $(top_builddir)/src/port/libpgport_srv.a $(LDFLAGS) \ + $(CLUSTER_UNIT_PORT_LIBS) $(LDFLAGS) \ -lssl -lcrypto -o $@ $(CLUSTER_PAGE_REPLAY_BATCH_O): \ @@ -975,7 +995,7 @@ test_cluster_page_replay_batch: test_cluster_page_replay_batch.c unit_test.h \ $(CC) $(CFLAGS) $(CPPFLAGS) $< $(CLUSTER_PAGE_REPLAY_BATCH_O) \ $(CLUSTER_PAGE_INSTALL_O) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ $(CLUSTER_PAGE_INSTALL_O): \ $(top_srcdir)/src/backend/cluster/cluster_page_install.c \ @@ -986,7 +1006,7 @@ test_cluster_page_install: test_cluster_page_install.c unit_test.h \ $(CLUSTER_PAGE_INSTALL_O) $(CC) $(CFLAGS) $(CPPFLAGS) $< $(CLUSTER_PAGE_INSTALL_O) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ CLUSTER_PAGE_PRODUCER_O = cluster_page_producer_test.o @@ -999,7 +1019,7 @@ test_cluster_page_producer: test_cluster_page_producer.c unit_test.h \ $(CLUSTER_PAGE_PRODUCER_O) $(CC) $(CFLAGS) $(CPPFLAGS) -DUSE_CLUSTER_UNIT $< \ $(CLUSTER_PAGE_PRODUCER_O) \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ CLUSTER_PAGE_ANCHOR_CACHE_O = \ $(top_builddir)/src/backend/cluster/cluster_page_anchor_cache.o @@ -1016,7 +1036,7 @@ test_cluster_page_anchor_cache: test_cluster_page_anchor_cache.c unit_test.h \ $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_PAGE_ANCHOR_CACHE_O) $(CLUSTER_PAGE_STABLE_BASE_O) \ xlogreader_fs.o $(top_builddir)/src/common/libpgcommon.a \ - $(top_builddir)/src/port/libpgport_srv.a $(LDFLAGS) \ + $(CLUSTER_UNIT_PORT_LIBS) $(LDFLAGS) \ -lssl -lcrypto -llz4 -lzstd -o $@ $(CLUSTER_PAGE_STABLE_BASE_O): \ $(top_srcdir)/src/backend/cluster/cluster_page_stable_base.c \ @@ -1028,14 +1048,14 @@ test_cluster_page_stable_base: test_cluster_page_stable_base.c unit_test.h \ $(CC) $(CFLAGS) $(CPPFLAGS) -DUSE_CLUSTER_UNIT $< \ $(CLUSTER_PAGE_STABLE_BASE_O) xlogreader_fs.o \ $(top_builddir)/src/common/libpgcommon.a \ - $(top_builddir)/src/port/libpgport_srv.a $(LDFLAGS) \ + $(CLUSTER_UNIT_PORT_LIBS) $(LDFLAGS) \ -lssl -lcrypto -llz4 -lzstd -o $@ CLUSTER_PAGE_VERSION_O = $(top_builddir)/src/backend/cluster/cluster_page_version.o test_cluster_page_version: test_cluster_page_version.c unit_test.h \ $(CLUSTER_PAGE_VERSION_O) $(CC) $(CFLAGS) $(CPPFLAGS) $< $(CLUSTER_PAGE_VERSION_O) \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # RF-PAGE PGDEL-02: rmgr census (closed-table row assignment + t/256 # differential-evidence state), census -> classifier wiring, and the @@ -1046,7 +1066,7 @@ CLUSTER_PAGE_RMGR_O = $(top_builddir)/src/backend/cluster/cluster_page_rmgr.o test_cluster_page_rmgr: test_cluster_page_rmgr.c unit_test.h \ $(CLUSTER_PAGE_RMGR_O) $(CLUSTER_PAGE_VERSION_O) $(CC) $(CFLAGS) $(CPPFLAGS) $< $(CLUSTER_PAGE_RMGR_O) $(CLUSTER_PAGE_VERSION_O) \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # RF-PAGE PGDEL-03: §4.1 recovery-action table, §3.5 per-block state # machine (adjacent advance only) and §8.1 dispatcher verdict. Pure @@ -1055,7 +1075,7 @@ CLUSTER_PAGE_RECOVERY_O = $(top_builddir)/src/backend/cluster/cluster_page_recov test_cluster_page_recovery: test_cluster_page_recovery.c unit_test.h \ $(CLUSTER_PAGE_RECOVERY_O) $(CC) $(CFLAGS) $(CPPFLAGS) $< $(CLUSTER_PAGE_RECOVERY_O) \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # RF-PAGE PGDEL-04: CURRENT/PI/STORAGE provenance validators (§5.2/5.3/ # 5.4 conjunctions) + §5.5/§6.2 source selection. Pure judgement over @@ -1064,7 +1084,7 @@ CLUSTER_PAGE_SOURCE_O = $(top_builddir)/src/backend/cluster/cluster_page_source. test_cluster_page_source: test_cluster_page_source.c unit_test.h \ $(CLUSTER_PAGE_SOURCE_O) $(CLUSTER_PAGE_VERSION_O) $(CC) $(CFLAGS) $(CPPFLAGS) $< $(CLUSTER_PAGE_SOURCE_O) $(CLUSTER_PAGE_VERSION_O) \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # RF-PAGE PGDEL-05: in-memory per-block recovery set + §6.3 contributor # closure + §3.3 shape-2 chain skip. Pure judgement over the ordered @@ -1073,7 +1093,7 @@ CLUSTER_PAGE_SET_O = $(top_builddir)/src/backend/cluster/cluster_page_set.o test_cluster_page_set: test_cluster_page_set.c unit_test.h \ $(CLUSTER_PAGE_SET_O) $(CLUSTER_PAGE_VERSION_O) $(CC) $(CFLAGS) $(CPPFLAGS) $< $(CLUSTER_PAGE_SET_O) $(CLUSTER_PAGE_VERSION_O) \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # RF-PAGE PGDEL-06: §7.1 mutation admission, §7.2 sequence-step gates, # §7.6 stable-base STOP (permanent RED) and §7.7 crash-matrix verdicts. @@ -1082,7 +1102,7 @@ CLUSTER_PAGE_APPLY_O = $(top_builddir)/src/backend/cluster/cluster_page_apply.o test_cluster_page_apply: test_cluster_page_apply.c unit_test.h \ $(CLUSTER_PAGE_APPLY_O) $(CLUSTER_PAGE_RECOVERY_O) $(CC) $(CFLAGS) $(CPPFLAGS) $< $(CLUSTER_PAGE_APPLY_O) $(CLUSTER_PAGE_RECOVERY_O) \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # RF-PAGE PGDEL-07: §7.4 FND-10 per-resource handoff judgement + PL-12 # retention denial. Judgement-only; links the apply layer for the @@ -1092,7 +1112,7 @@ test_cluster_page_handoff: test_cluster_page_handoff.c unit_test.h \ $(CLUSTER_PAGE_HANDOFF_O) $(CLUSTER_PAGE_APPLY_O) $(CLUSTER_PAGE_RECOVERY_O) $(CC) $(CFLAGS) $(CPPFLAGS) $< $(CLUSTER_PAGE_HANDOFF_O) $(CLUSTER_PAGE_APPLY_O) \ $(CLUSTER_PAGE_RECOVERY_O) \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # RF-PAGE PGDEL-08: §9.1 recovery-only counters (G2-classified), # vocabulary table and §9.3 attempt dump. GetCurrentTimestamp comes @@ -1101,7 +1121,7 @@ CLUSTER_PAGE_STATS_O = $(top_builddir)/src/backend/cluster/cluster_page_stats.o test_cluster_page_stats: test_cluster_page_stats.c unit_test.h \ $(CLUSTER_PAGE_STATS_O) $(CLUSTER_PAGE_VERSION_O) $(CC) $(CFLAGS) $(CPPFLAGS) $< $(CLUSTER_PAGE_STATS_O) $(CLUSTER_PAGE_VERSION_O) \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # RF-PAGE PGDEL-09: PU matrix + unit-level PL face over the delivered # semantic layers (classifier/decide/closure/source/handoff/crash matrix). @@ -1111,13 +1131,13 @@ CLUSTER_PAGE_MATRIX_LIBS = $(CLUSTER_PAGE_APPLY_O) $(CLUSTER_PAGE_HANDOFF_O) \ test_cluster_page_recovery_matrix: test_cluster_page_recovery_matrix.c unit_test.h \ $(CLUSTER_PAGE_MATRIX_LIBS) $(CC) $(CFLAGS) $(CPPFLAGS) $< $(CLUSTER_PAGE_MATRIX_LIBS) \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # RF-PAGE PGDEL-10: ABI-baseline guards (page header / WAL record header / # buffer tag / relfilelocator sizes frozen at the PGRAC HEAD baseline). test_cluster_page_abi: test_cluster_page_abi.c unit_test.h $(CC) $(CFLAGS) $(CPPFLAGS) $< \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # RF-SIDE D-SIDE-06/07/08: RF-PAGE integration verdict, per-resource # readiness, retention proof exporter. Links the page version layer. @@ -1125,14 +1145,14 @@ CLUSTER_SIDE_RECOVERY_O = $(top_builddir)/src/backend/cluster/cluster_side_recov test_cluster_side_recovery: test_cluster_side_recovery.c unit_test.h \ $(CLUSTER_SIDE_RECOVERY_O) $(CLUSTER_PAGE_VERSION_O) $(CC) $(CFLAGS) $(CPPFLAGS) $< $(CLUSTER_SIDE_RECOVERY_O) $(CLUSTER_PAGE_VERSION_O) \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # RF-SIDE D-SIDE-01: total route registry (§3.2 matrix) + §2.1 verdicts. CLUSTER_SIDE_ROUTE_O = $(top_builddir)/src/backend/cluster/cluster_side_route.o test_cluster_side_route: test_cluster_side_route.c unit_test.h \ $(CLUSTER_SIDE_ROUTE_O) $(CLUSTER_RF_ROUTE_O) $(CC) $(CFLAGS) $(CPPFLAGS) $< $(CLUSTER_SIDE_ROUTE_O) $(CLUSTER_RF_ROUTE_O) \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # RF-SIDE D-SIDE-02: TT/undo decode + preflight primitives (single # parser; malformed/unknown -> BLOCKED pre-mutation). @@ -1141,7 +1161,7 @@ test_cluster_side_undo: test_cluster_side_undo.c unit_test.h \ $(CLUSTER_SIDE_UNDO_O) $(CLUSTER_SIDE_ROUTE_O) $(CLUSTER_RF_ROUTE_O) $(CC) $(CFLAGS) $(CPPFLAGS) $< $(CLUSTER_SIDE_UNDO_O) $(CLUSTER_SIDE_ROUTE_O) \ $(CLUSTER_RF_ROUTE_O) \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ CLUSTER_SIDE_XACT_O = test_cluster_side_xact_product.o CLUSTER_REMOTE_XACT_IDENTITY_O = \ @@ -1161,18 +1181,21 @@ SIDE_XACT_XACTDESC_O = test_cluster_side_xact_xactdesc.o $(SIDE_XACT_XACTDESC_O): $(top_srcdir)/src/backend/access/rmgrdesc/xactdesc.c $(CC) $(CFLAGS) $(CPPFLAGS) -ffunction-sections -fdata-sections -c $< -o $@ SIDE_XACT_TT_2PC_RECORD_O = $(top_builddir)/src/backend/cluster/cluster_tt_2pc_record.o +test_cluster_side_xact_undo_product.o: $(top_srcdir)/src/backend/cluster/cluster_side_undo.c + $(CC) $(CFLAGS) $(CPPFLAGS) -ffunction-sections -fdata-sections -c $< -o $@ + test_cluster_side_xact: test_cluster_side_xact.c unit_test.h \ $(CLUSTER_SIDE_XACT_O) $(CLUSTER_SIDE_ONLINE_PLAN_TEST_O) \ $(CLUSTER_REMOTE_XACT_IDENTITY_O) \ $(SIDE_XACT_XACTDESC_O) $(SIDE_XACT_TT_2PC_RECORD_O) \ - $(CLUSTER_SIDE_UNDO_O) $(CLUSTER_SIDE_ROUTE_O) $(CLUSTER_RF_ROUTE_O) + test_cluster_side_xact_undo_product.o $(CLUSTER_SIDE_ROUTE_O) $(CLUSTER_RF_ROUTE_O) $(CC) $(CFLAGS) $(CPPFLAGS) $< $(CLUSTER_SIDE_XACT_O) \ $(CLUSTER_SIDE_ONLINE_PLAN_TEST_O) $(SIDE_XACT_XACTDESC_O) \ $(CLUSTER_REMOTE_XACT_IDENTITY_O) \ - $(SIDE_XACT_TT_2PC_RECORD_O) $(CLUSTER_SIDE_UNDO_O) \ + $(SIDE_XACT_TT_2PC_RECORD_O) test_cluster_side_xact_undo_product.o \ $(CLUSTER_SIDE_ROUTE_O) $(CLUSTER_RF_ROUTE_O) \ $(top_builddir)/src/common/libpgcommon.a \ - $(top_builddir)/src/port/libpgport_srv.a \ + $(CLUSTER_UNIT_PORT_LIBS) \ $(R4_RUNTIME_VIS_TEST_DEAD_STRIP) $(LDFLAGS) -lssl -lcrypto -o $@ CLUSTER_SIDE_ONLINE_OWNER_O = \ @@ -1180,7 +1203,7 @@ CLUSTER_SIDE_ONLINE_OWNER_O = \ test_cluster_side_online_owner: test_cluster_side_online_owner.c unit_test.h \ $(CLUSTER_SIDE_ONLINE_OWNER_O) $(CC) $(CFLAGS) $(CPPFLAGS) $< $(CLUSTER_SIDE_ONLINE_OWNER_O) \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # RF-SIDE D-SIDE-03: PREPARED/in-doubt binding + RECO-style resolution # judgements. @@ -1188,7 +1211,7 @@ CLUSTER_SIDE_PREPARED_O = $(top_builddir)/src/backend/cluster/cluster_side_prepa test_cluster_side_prepared: test_cluster_side_prepared.c unit_test.h \ $(CLUSTER_SIDE_PREPARED_O) $(CC) $(CFLAGS) $(CPPFLAGS) $< $(CLUSTER_SIDE_PREPARED_O) \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # RF-SIDE D-SIDE-04: CLOG/MULTIXACT/COMMIT_TS derived-projection # judgements (verified / rebuildable / fail-closed lookup). @@ -1196,7 +1219,7 @@ CLUSTER_SIDE_PROJECTION_O = $(top_builddir)/src/backend/cluster/cluster_side_pro test_cluster_side_projection: test_cluster_side_projection.c unit_test.h \ $(CLUSTER_SIDE_PROJECTION_O) $(CC) $(CFLAGS) $(CPPFLAGS) $< $(CLUSTER_SIDE_PROJECTION_O) \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # RF-SIDE D-SIDE-05: canonical space metadata gates (HWM/extent/bitmap) # under STOP-RF-SIDE-SPACE-ABI. @@ -1204,7 +1227,7 @@ CLUSTER_SIDE_SPACE_O = $(top_builddir)/src/backend/cluster/cluster_side_space.o test_cluster_side_space: test_cluster_side_space.c unit_test.h \ $(CLUSTER_SIDE_SPACE_O) $(CLUSTER_PAGE_VERSION_O) $(CC) $(CFLAGS) $(CPPFLAGS) $< $(CLUSTER_SIDE_SPACE_O) $(CLUSTER_PAGE_VERSION_O) \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # RF-SIDE D-SIDE-10: observability counters (observational only — # U-SIDE-16: counters can never change a verdict). @@ -1215,7 +1238,7 @@ test_cluster_side_stats: test_cluster_side_stats.c unit_test.h \ $(CLUSTER_PAGE_VERSION_O) $(CC) $(CFLAGS) $(CPPFLAGS) $< $(CLUSTER_SIDE_STATS_O) $(CLUSTER_SIDE_ROUTE_O) \ $(CLUSTER_RF_ROUTE_O) $(CLUSTER_SIDE_RECOVERY_O) $(CLUSTER_PAGE_VERSION_O) \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # RF-SIDE D-SIDE-09: fault corpus judgement face — U-SIDE-17 + L1..L20 # legs over the delivered judgement layers. @@ -1228,7 +1251,7 @@ CLUSTER_SIDE_CORPUS_LIBS = $(CLUSTER_PAGE_APPLY_O) $(CLUSTER_PAGE_SET_O) \ test_cluster_side_corpus: test_cluster_side_corpus.c unit_test.h \ $(CLUSTER_SIDE_CORPUS_LIBS) $(CC) $(CFLAGS) $(CPPFLAGS) $< $(CLUSTER_SIDE_CORPUS_LIBS) \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-5.7 D3 S1: test_cluster_hw_snapshot links cluster_hw_snapshot.o (the HW # authority durable-snapshot envelope: serialize / deserialize+validate / @@ -1237,10 +1260,11 @@ test_cluster_side_corpus: test_cluster_side_corpus.c unit_test.h \ # Assert ExceptionalCondition hook. The durable file round trip (temp + # durable_rename) is added to this binary with D3 S3. CLUSTER_HW_SNAPSHOT_O = $(top_builddir)/src/backend/cluster/cluster_hw_snapshot.o -test_cluster_hw_snapshot_io.o: $(top_srcdir)/src/backend/cluster/cluster_hw_snapshot.c \ +test_cluster_hw_snapshot_io.o: test_cluster_hw_snapshot_io.c \ + $(top_srcdir)/src/backend/cluster/cluster_hw_snapshot.c \ $(top_srcdir)/src/include/cluster/cluster_hw_snapshot.h \ $(top_srcdir)/src/include/common/cluster_hw_snapshot_codec.h - $(CC) $(CFLAGS) $(CPPFLAGS) -Dread=hw_snapshot_test_read -c $< -o $@ + $(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@ test_cluster_hw_snapshot_codec_backend.o: $(top_srcdir)/src/common/cluster_hw_snapshot_codec.c \ $(top_srcdir)/src/include/common/cluster_hw_snapshot_codec.h @@ -1260,7 +1284,7 @@ test_cluster_hw_snapshot: test_cluster_hw_snapshot.c unit_test.h $(CLUSTER_VERSI $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_VERSION_O) test_cluster_hw_snapshot_io.o \ test_cluster_hw_snapshot_codec_backend.o test_cluster_hw_snapshot_codec_frontend.o \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-5.6 Da1: test_cluster_cf_authority links cluster_cf_authority.o and # exercises the pure classify/decide logic plus a real durable_rename read/ @@ -1272,7 +1296,7 @@ test_cluster_cf_authority: test_cluster_cf_authority.c unit_test.h \ $(CLUSTER_CF_AUTHORITY_O) $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_CF_AUTHORITY_O) \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ CLUSTER_CONTROL_ROOT_O = $(top_builddir)/src/backend/cluster/cluster_control_root.o # migration_wal_scan (contract) drives a real XLogReader over the thread @@ -1284,7 +1308,7 @@ test_cluster_control_root: test_cluster_control_root.c unit_test.h \ $(CC) $(CFLAGS) $(CPPFLAGS) $< $(CLUSTER_CONTROL_ROOT_O) \ xlogreader_fs.o \ $(top_builddir)/src/common/libpgcommon.a \ - $(top_builddir)/src/port/libpgport_srv.a $(LDFLAGS) \ + $(CLUSTER_UNIT_PORT_LIBS) $(LDFLAGS) \ -lssl -lcrypto -llz4 -lzstd -o $@ xlogreader_fs.o: $(top_srcdir)/src/backend/access/transam/xlogreader.c @@ -1294,20 +1318,20 @@ CLUSTER_WAL_RETENTION_O = $(top_builddir)/src/backend/cluster/cluster_wal_retent test_cluster_wal_retention: test_cluster_wal_retention.c unit_test.h \ $(CLUSTER_WAL_RETENTION_O) $(CC) $(CFLAGS) $(CPPFLAGS) $< $(CLUSTER_WAL_RETENTION_O) \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ CLUSTER_RECOVERY_DUTY_O = $(top_builddir)/src/backend/cluster/cluster_recovery_duty.o test_cluster_recovery_duty: test_cluster_recovery_duty.c unit_test.h \ $(CLUSTER_RECOVERY_DUTY_O) $(CC) $(CFLAGS) $(CPPFLAGS) $< $(CLUSTER_RECOVERY_DUTY_O) \ $(top_builddir)/src/common/libpgcommon.a \ - $(top_builddir)/src/port/libpgport_srv.a $(LDFLAGS) -lssl -lcrypto -o $@ + $(CLUSTER_UNIT_PORT_LIBS) $(LDFLAGS) -lssl -lcrypto -o $@ test_cluster_formation_witness: test_cluster_formation_witness.c unit_test.h \ $(CLUSTER_RECOVERY_DUTY_O) $(CC) $(CFLAGS) $(CPPFLAGS) $< $(CLUSTER_RECOVERY_DUTY_O) \ $(top_builddir)/src/common/libpgcommon.a \ - $(top_builddir)/src/port/libpgport_srv.a $(LDFLAGS) -lssl -lcrypto -o $@ + $(CLUSTER_UNIT_PORT_LIBS) $(LDFLAGS) -lssl -lcrypto -o $@ test_pgrac_external_fence_protocol: \ test_pgrac_external_fence_protocol.c unit_test.h \ @@ -1315,7 +1339,7 @@ test_pgrac_external_fence_protocol: \ $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(PGRAC_EXTERNAL_FENCE_PROTOCOL_O) \ $(top_builddir)/src/common/libpgcommon.a \ - $(top_builddir)/src/port/libpgport_srv.a $(LDFLAGS) -lssl -lcrypto -o $@ + $(CLUSTER_UNIT_PORT_LIBS) $(LDFLAGS) -lssl -lcrypto -o $@ PGRAC_FENCED_CONFIG_O = \ $(top_builddir)/src/bin/pgrac_fenced/pgrac_fenced_config.o @@ -1502,14 +1526,14 @@ test_pgrac_fenced_ctl: test_pgrac_fenced_ctl.c unit_test.h \ $(PGRAC_FENCED_CTL_O) $(PGRAC_FENCED_JOURNAL_O) \ $(PGRAC_EXTERNAL_FENCE_PROTOCOL_O) \ $(top_builddir)/src/common/libpgcommon.a \ - $(top_builddir)/src/port/libpgport_srv.a $(LDFLAGS) -lssl -lcrypto -o $@ + $(CLUSTER_UNIT_PORT_LIBS) $(LDFLAGS) -lssl -lcrypto -o $@ CLUSTER_FENCE_AUTHORITY_O = $(top_builddir)/src/backend/cluster/cluster_fence_authority.o test_cluster_write_fence_durable: test_cluster_write_fence_durable.c unit_test.h \ $(CLUSTER_FENCE_AUTHORITY_O) $(CC) $(CFLAGS) $(CPPFLAGS) $< $(CLUSTER_FENCE_AUTHORITY_O) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ CLUSTER_WRITE_FENCE_O = $(top_builddir)/src/backend/cluster/cluster_write_fence.o test_cluster_write_fence_cache: test_cluster_write_fence_cache.c unit_test.h \ @@ -1517,7 +1541,7 @@ test_cluster_write_fence_cache: test_cluster_write_fence_cache.c unit_test.h \ $(CC) $(CFLAGS) $(CPPFLAGS) $< $(CLUSTER_WRITE_FENCE_O) $(CLUSTER_MEMBERSHIP_O) \ $(CLUSTER_EPOCH_O) -lpthread \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-5.6a D1: test_cluster_recovery_anchor links cluster_recovery_anchor.o # and exercises the pure image classification plus a real torn-safe read/ @@ -1529,13 +1553,13 @@ test_cluster_recovery_anchor: test_cluster_recovery_anchor.c unit_test.h \ $(CLUSTER_RECOVERY_ANCHOR_O) $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_RECOVERY_ANCHOR_O) \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-6.14a D1: test_cluster_gcs_reqid exercises the pure request-id domain # helpers (cluster_gcs_reqid.h, c.h-only); links libpgport for pg_printf. test_cluster_gcs_reqid: test_cluster_gcs_reqid.c unit_test.h $(CC) $(CFLAGS) $(CPPFLAGS) $< \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-6.14 D1: test_cluster_shared_catalog links cluster_shared_catalog.o # (the pure vet predicate + "non-temp = shared" routing criterion). The @@ -1546,7 +1570,7 @@ test_cluster_shared_catalog: test_cluster_shared_catalog.c unit_test.h \ $(CLUSTER_SHARED_CATALOG_O) $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_SHARED_CATALOG_O) \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-6.14 D6: test_cluster_oid_lease links cluster_oid_lease.o (the pure # lease math + torn-safe authority file I/O). fd.c openers, pg_fsync, @@ -1558,7 +1582,7 @@ test_cluster_oid_lease: test_cluster_oid_lease.c unit_test.h \ $(CLUSTER_OID_LEASE_O) $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_OID_LEASE_O) \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-6.15b D1/D2: test_cluster_xid_authority links cluster_xid_authority.o # (the shared XID authority + native-era prehistory: torn-safe file I/O, @@ -1576,7 +1600,7 @@ test_cluster_xid_authority: test_cluster_xid_authority.c unit_test.h \ $(CLUSTER_XID_AUTHORITY_O) $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_XID_AUTHORITY_O) \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-6.14 D5: test_cluster_relmap_authority links cluster_relmap_authority.o @@ -1588,7 +1612,7 @@ test_cluster_relmap_authority: test_cluster_relmap_authority.c unit_test.h \ $(CLUSTER_RELMAP_AUTHORITY_O) $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_RELMAP_AUTHORITY_O) \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-5.6 Da2: test_cluster_cf_storage links cluster_cf_storage.o (migration # + symlink + storage rename-contract) plus cluster_cf_authority.o (the @@ -1599,7 +1623,7 @@ test_cluster_cf_storage: test_cluster_cf_storage.c unit_test.h \ $(CLUSTER_CF_STORAGE_O) $(CLUSTER_CF_AUTHORITY_O) $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_CF_STORAGE_O) $(CLUSTER_CF_AUTHORITY_O) \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-5.6 Db1: test_cluster_cf_enqueue links cluster_cf_enqueue.o (the pure # resid encoder). No PG backend deps beyond the Assert hook. @@ -1608,7 +1632,7 @@ test_cluster_cf_enqueue: test_cluster_cf_enqueue.c unit_test.h \ $(CLUSTER_CF_ENQUEUE_O) $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_CF_ENQUEUE_O) \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-5.6 Dc4: test_cluster_cf_stats links cluster_cf_stats.o (the CF # observability counters); ShmemInitStruct + region register stubbed locally. @@ -1617,7 +1641,7 @@ test_cluster_cf_stats: test_cluster_cf_stats.c unit_test.h \ $(CLUSTER_CF_STATS_O) $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_CF_STATS_O) \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-5.6 increment (iii): test_cluster_cf_phase2 links cluster_cf_phase2.o # (the cross-node rename-contract rendezvous). The probe/ack file I/O and the @@ -1629,7 +1653,7 @@ test_cluster_cf_phase2: test_cluster_cf_phase2.c unit_test.h \ $(CLUSTER_CF_PHASE2_O) $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_CF_PHASE2_O) \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-6.2 D0: test_cluster_terminal_authority links the pure Smart Fusion # terminal-authority decision layer. It has no backend dependencies beyond the @@ -1640,7 +1664,7 @@ test_cluster_terminal_authority: test_cluster_terminal_authority.c unit_test.h \ $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_TERMINAL_AUTHORITY_O) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-3.12 D6: test_cluster_retention links cluster_undo_retention.o (the two # pure retention predicates) standalone. cluster_undo_retention.c references @@ -1662,12 +1686,12 @@ test_cluster_tt_2pc: test_cluster_tt_2pc.c unit_test.h \ -DTWOPHASE_SOURCE_PATH='"$(abspath $(top_srcdir))/src/backend/access/transam/twophase.c"' \ $< \ $(CLUSTER_TT_2PC_RECORD_O) \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ test_cluster_visibility_variants: test_cluster_visibility_variants.c unit_test.h \ $(CLUSTER_VIS_VERDICT_O) $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_VIS_VERDICT_O) \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-5.22f D6-1: test_cluster_vis_undo_verdict_map links the same pure # verdict object (cluster_visibility_verdict.o) for the two D6 fresh-ref @@ -1678,7 +1702,7 @@ test_cluster_vis_undo_verdict_map: test_cluster_vis_undo_verdict_map.c unit_test $(CLUSTER_VIS_VERDICT_O) $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_VIS_VERDICT_O) \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-7.1a D0/U0: test_cluster_writer_chain links the pure terminal-writer # outcome -> TM_Result mapping standalone (no buffer / no page / no backend). @@ -1687,13 +1711,13 @@ test_cluster_writer_chain: test_cluster_writer_chain.c unit_test.h \ $(CLUSTER_WRITER_CHAIN_O) $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_WRITER_CHAIN_O) \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ test_cluster_retention: test_cluster_retention.c unit_test.h \ $(CLUSTER_UNDO_RETENTION_O) $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_UNDO_RETENTION_O) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-3.17 D6: test_cluster_stage3_acceptance — 8 static contract tests # (L1-L8) pinning the Stage 3 MVCC final surface (catversion / undo opcodes @@ -1706,7 +1730,7 @@ test_cluster_stage3_acceptance: test_cluster_stage3_acceptance.c unit_test.h ../ $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_UNDO_RETENTION_O) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-4.14 D6: test_cluster_stage4_acceptance — 10 static contract tests # (L1-L10) pinning the Stage 4 WAL + recovery + fence final surface @@ -1720,7 +1744,7 @@ test_cluster_stage4_acceptance: test_cluster_stage4_acceptance.c unit_test.h ../ ../../../src/include/cluster/cluster_thread_recovery.h $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-5.19 D8: test_cluster_stage5_integrated_acceptance — 6 static contract # tests (L1-L6) pinning the Stage 5 (through 5.19) integrated-acceptance @@ -1733,7 +1757,7 @@ test_cluster_stage5_integrated_acceptance: test_cluster_stage5_integrated_accept ../../../src/include/access/heapam_xlog.h $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-5.21 D3: test_cluster_stage5_beta_acceptance — 6 static contract tests # (L1-L6) pinning the Stage 5 (through 5.21) beta close-out release surface @@ -1747,7 +1771,7 @@ test_cluster_stage5_beta_acceptance: test_cluster_stage5_beta_acceptance.c unit_ ../../../src/include/cluster/cluster_gcs_block.h $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-5.58 D8: test_cluster_stage5_5_cr_acceptance — 6 static contract tests # (L1-L6) pinning the Stage 5.5 CR read-path band (5.51-5.57) final surface @@ -1761,21 +1785,23 @@ test_cluster_stage5_5_cr_acceptance: test_cluster_stage5_5_cr_acceptance.c unit_ ../../../src/include/cluster/cluster_cr_coordinator_stat.h $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-3.18 D1: test_cluster_undo_buf links the real undo buffer pool object # and stubs ShmemInitStruct / LWLock* / cluster_undo_smgr_{read,write}_block # locally (single-threaded pool-logic test). CLUSTER_UNDO_BUF_O = $(top_builddir)/src/backend/cluster/storage/cluster_undo_buf.o test_cluster_undo_buf: test_cluster_undo_buf.c unit_test.h $(CLUSTER_UNDO_BUF_O) \ + $(CLUSTER_UNDO_ROOT_DESCRIPTOR_O) \ $(top_builddir)/src/backend/cluster/storage/cluster_undo_block0.o \ $(top_builddir)/src/backend/cluster/storage/cluster_undo_block0_resident.o $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_UNDO_BUF_O) \ + $(CLUSTER_UNDO_ROOT_DESCRIPTOR_O) \ $(top_builddir)/src/backend/cluster/storage/cluster_undo_block0.o \ $(top_builddir)/src/backend/cluster/storage/cluster_undo_block0_resident.o \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-4.10 D3a: test_cluster_block_apply links the real single-block # redo-apply framework object and stubs RestoreBlockImage + the @@ -1790,7 +1816,7 @@ test_cluster_block_apply: test_cluster_block_apply.c unit_test.h $(CLUSTER_BLOCK $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_BLOCK_APPLY_O) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-4.11 D1: test_cluster_thread_apply links the real online thread-recovery # apply wrapper object and stubs cluster_block_apply_one (its byte-for-byte @@ -1805,7 +1831,7 @@ test_cluster_thread_apply: test_cluster_thread_apply.c unit_test.h $(CLUSTER_THR $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_THREAD_APPLY_O) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-4.11 D1 contract: test_cluster_thread_replay exercises the PURE # block-classification gate (cluster_thread_replay_classify_block, a header @@ -1816,7 +1842,7 @@ test_cluster_thread_apply: test_cluster_thread_apply.c unit_test.h $(CLUSTER_THR test_cluster_thread_replay: test_cluster_thread_replay.c unit_test.h $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-4.11 D1 contract: test_cluster_thread_driver exercises the driver's # PURE decision helpers -- cluster_thread_recovery_should_rethrow (the R13 elevel @@ -1828,7 +1854,7 @@ test_cluster_thread_replay: test_cluster_thread_replay.c unit_test.h test_cluster_thread_driver: test_cluster_thread_driver.c unit_test.h $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-4.11 D1 contract: test_cluster_thread_orchestrator exercises the # orchestrator's PURE on_unrecoverable escalation gate @@ -1839,7 +1865,7 @@ test_cluster_thread_driver: test_cluster_thread_driver.c unit_test.h test_cluster_thread_orchestrator: test_cluster_thread_orchestrator.c unit_test.h $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-4.12 D3: test_cluster_write_fence exercises the PURE cooperative write-fence # judge cluster_write_fence_decide (a header inline -- no cluster object needed; @@ -1848,9 +1874,9 @@ test_cluster_thread_orchestrator: test_cluster_thread_orchestrator.c unit_test.h test_cluster_write_fence: test_cluster_write_fence.c unit_test.h $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ -$(filter-out test_cluster_lms_native_probe test_cluster_bufmgr_stop,$(SIMPLE_TESTS)): %: %.c unit_test.h $(CLUSTER_VERSION_O) +$(filter-out test_cluster_lms_native_probe test_cluster_bufmgr_stop test_cluster_r4_itl_capacity test_cluster_ctrc_itl_reuse,$(SIMPLE_TESTS)): %: %.c unit_test.h $(CLUSTER_VERSION_O) $(CC) $(CFLAGS) $(CPPFLAGS) $< $(CLUSTER_VERSION_O) -o $@ # The wire behavior is inline; an updated decoder must rebuild this binary. @@ -1928,7 +1954,7 @@ test_cluster_ic_envelope: test_cluster_ic_envelope.c unit_test.h \ $(CLUSTER_VERSION_O) $(CLUSTER_IC_ENVELOPE_O) $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_VERSION_O) $(CLUSTER_IC_ENVELOPE_O) \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-2.3 D4: test_cluster_ic_router links cluster_ic_router.o + # cluster_ic_envelope.o (envelope_build called inside send_envelope) + @@ -1941,7 +1967,7 @@ test_cluster_ic_router: test_cluster_ic_router.c unit_test.h \ $(CLUSTER_VERSION_O) $(CLUSTER_IC_ROUTER_O) $(CLUSTER_IC_ENVELOPE_O) $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_VERSION_O) $(CLUSTER_IC_ROUTER_O) $(CLUSTER_IC_ENVELOPE_O) \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # test_cluster_conf links cluster_conf.o standalone. cluster_conf.c # references ereport / ShmemInitStruct / AllocateFile / FreeFile / @@ -1951,7 +1977,7 @@ test_cluster_ic_router: test_cluster_ic_router.c unit_test.h \ test_cluster_conf: test_cluster_conf.c unit_test.h $(CLUSTER_VERSION_O) \ $(CLUSTER_CONF_O) $(CC) $(CFLAGS) $(CPPFLAGS) $< \ - $(CLUSTER_VERSION_O) $(CLUSTER_CONF_O) -o $@ + $(CLUSTER_VERSION_O) $(CLUSTER_CONF_O) $(CLUSTER_UNIT_PORT_LIBS) -o $@ # test_cluster_ic_mock links cluster_ic.o standalone (same as # test_cluster_ic but exercises the mock vtable additions and the four @@ -2000,7 +2026,7 @@ test_cluster_debug: test_cluster_debug.c unit_test.h $(CLUSTER_VERSION_O) \ $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_VERSION_O) $(CLUSTER_DEBUG_O) $(CLUSTER_STARTUP_PHASE_O) \ $(CLUSTER_RESOURCE_X_IDENTITY_O) \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # test_cluster_xnode_profile links cluster_xnode_profile.o standalone (spec-5.59 # D10). The test defines the GUC variable itself (cluster_guc.o is not @@ -2057,7 +2083,7 @@ test_cluster_ges_handoff: test_cluster_ges_handoff.c unit_test.h \ $(CLUSTER_GES_HANDOFF_POLICY_O) $(CLUSTER_GES_MODE_O) $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_GES_HANDOFF_POLICY_O) $(CLUSTER_GES_MODE_O) \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # test_cluster_shared_fs links the three storage/ objects standalone: # cluster_shared_fs.o (registry + dispatch), cluster_shared_fs_stub.o @@ -2075,7 +2101,7 @@ test_cluster_shared_fs: test_cluster_shared_fs.c unit_test.h \ $(CLUSTER_VERSION_O) $(CLUSTER_SHARED_FS_O) \ $(CLUSTER_SHARED_FS_STUB_O) $(CLUSTER_SHARED_FS_LOCAL_O) \ $(CLUSTER_SHARED_FS_SHAREDFS_O) $(CLUSTER_SHARED_CATALOG_O) \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-4.5a D12: runtime unit for the shared_fs backend + shared-root # sentinel. Links ONLY cluster_shared_fs_sharedfs.o with functional @@ -2084,7 +2110,7 @@ test_cluster_shared_fs_sharedfs: test_cluster_shared_fs_sharedfs.c unit_test.h \ $(CLUSTER_VERSION_O) $(CLUSTER_SHARED_FS_SHAREDFS_O) $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_VERSION_O) $(CLUSTER_SHARED_FS_SHAREDFS_O) \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-6.0a: runtime unit for the raw block_device backend over a # temporary regular file that stands in for a block device. Links only @@ -2092,7 +2118,7 @@ test_cluster_shared_fs_sharedfs: test_cluster_shared_fs_sharedfs.c unit_test.h \ test_cluster_shared_fs_block_device: test_cluster_shared_fs_block_device.c unit_test.h \ $(CLUSTER_SHARED_FS_BLOCK_DEVICE_O) $(CLUSTER_PR_SCSI_O) $(CC) $(CFLAGS) $(CPPFLAGS) $< \ - $(CLUSTER_SHARED_FS_BLOCK_DEVICE_O) $(CLUSTER_PR_SCSI_O) -o $@ + $(CLUSTER_SHARED_FS_BLOCK_DEVICE_O) $(CLUSTER_PR_SCSI_O) $(CLUSTER_UNIT_PORT_LIBS) -o $@ # M5: compile the production capacity path into one focused syscall-boundary # unit. Dead stripping keeps unrelated provider/backend duties out. @@ -2119,7 +2145,7 @@ test_cluster_smgr: test_cluster_smgr.c unit_test.h \ $(CLUSTER_VERSION_O) $(CLUSTER_SMGR_O) $(CLUSTER_SHARED_CATALOG_O) \ $(CLUSTER_SHARED_FS_O) $(CLUSTER_SHARED_FS_STUB_O) \ $(CLUSTER_SHARED_FS_LOCAL_O) \ - $(CLUSTER_SHARED_FS_SHAREDFS_O) -o $@ + $(CLUSTER_SHARED_FS_SHAREDFS_O) $(CLUSTER_UNIT_PORT_LIBS) -o $@ # test_cluster_startup_phase links cluster_startup_phase.o standalone. # cluster_startup_phase.c references ereport / GetCurrentTimestamp / @@ -2132,6 +2158,7 @@ test_cluster_smgr: test_cluster_smgr.c unit_test.h \ test_cluster_startup_phase: test_cluster_startup_phase.c unit_test.h \ $(CLUSTER_VERSION_O) $(CLUSTER_STARTUP_PHASE_O) $(CC) $(CFLAGS) $(CPPFLAGS) $< \ + -DSTARTUP_PHASE_SOURCE_PATH='"$(abspath $(top_srcdir))/src/backend/cluster/cluster_startup_phase.c"' \ $(CLUSTER_VERSION_O) $(CLUSTER_STARTUP_PHASE_O) -o $@ # test_cluster_lmon links cluster_lmon.o standalone (spec-1.11 Sprint A). @@ -2202,13 +2229,15 @@ check_pcm_x_write_gate_coverage: PYTHONDONTWRITEBYTECODE=1 python3 \ $(top_srcdir)/src/tools/check_pcm_x_write_gate_ast.py \ --source-root "$(top_srcdir)" --compile-directory "$(CURDIR)" \ - --clang "$(CC)" --cflags '$(CFLAGS)' --cppflags '$(CPPFLAGS)' + --clang "$(CLUSTER_UNIT_CLANG)" --cflags '$(CFLAGS)' --cppflags '$(CPPFLAGS)' check_resource_x_send_c1_unit: PYTHONDONTWRITEBYTECODE=1 python3 \ $(top_srcdir)/src/test/cluster_unit/test_resource_x_send_c1.py -check_resource_x_send_c1: +# This gate executes and mutates these binaries. Listing it beside TESTS in +# all does not impose an order, especially in a clean parallel build. +check_resource_x_send_c1: test_cluster_pcm_lock test_cluster_lms_outbound test_cluster_gcs_block PYTHONDONTWRITEBYTECODE=1 python3 \ $(top_srcdir)/src/tools/check_resource_x_send_c1.py \ --source-root "$(top_srcdir)" \ @@ -2365,14 +2394,20 @@ cluster_qvotec_io_test.o: $(top_srcdir)/src/backend/cluster/cluster_voting_disk_ $(CC) $(CFLAGS) $(CPPFLAGS) -Dfdatasync=cluster_qvotec_test_fdatasync \ -Dpwrite=cluster_qvotec_test_pwrite -c $< -o $@ +# Retain the actual functions reached by the voting fixture, not unrelated +# startup-directory and postmaster entry points from the same source file. +test_cluster_qvotec_activation_product.o: $(top_srcdir)/src/backend/cluster/cluster_semantic_activation.c + $(CC) $(CFLAGS) $(CPPFLAGS) -ffunction-sections -fdata-sections -c $< -o $@ + test_cluster_qvotec: test_cluster_qvotec.c test_cluster_qvotec_startup.inc unit_test.h \ + cluster_unit_no_normal_stop.h \ $(CLUSTER_VERSION_O) $(CLUSTER_QVOTEC_PGSA_TEST_O) \ $(CLUSTER_NODE_REMOVE_POLICY_O) \ $(CLUSTER_EPOCH_BALLOT_O) $(CLUSTER_REPLACEMENT_REQUEST_O) \ $(CLUSTER_MEMBERSHIP_O) \ cluster_qvotec_io_test.o $(CLUSTER_UNDO_BLOCK0_O) \ $(CLUSTER_UNDO_ROOT_DESCRIPTOR_O) \ - $(top_builddir)/src/backend/cluster/cluster_semantic_activation.o + test_cluster_qvotec_activation_product.o $(CC) $(CFLAGS) $(CPPFLAGS) -DCLUSTER_QVOTEC_PGSA_UNIT_TEST \ -DQVOTEC_SOURCE_PATH='"$(abspath $(top_srcdir))/src/backend/cluster/cluster_qvotec.c"' \ -DLMON_SOURCE_PATH='"$(abspath $(top_srcdir))/src/backend/cluster/cluster_lmon.c"' \ @@ -2386,9 +2421,9 @@ test_cluster_qvotec: test_cluster_qvotec.c test_cluster_qvotec_startup.inc unit_ $(CLUSTER_MEMBERSHIP_O) \ cluster_qvotec_io_test.o $(CLUSTER_UNDO_BLOCK0_O) \ $(CLUSTER_UNDO_ROOT_DESCRIPTOR_O) \ - $(top_builddir)/src/backend/cluster/cluster_semantic_activation.o \ + test_cluster_qvotec_activation_product.o $(R4_RUNTIME_VIS_TEST_DEAD_STRIP) \ $(top_builddir)/src/common/libpgcommon.a \ - $(top_builddir)/src/port/libpgport_srv.a $(LDFLAGS) -lssl -lcrypto -o $@ + $(CLUSTER_UNIT_PORT_LIBS) $(LDFLAGS) -lssl -lcrypto -o $@ # spec-2.28 Sprint A Step 1 — cluster_fence.o standalone link. Stubs all # PG runtime deps (shmem / lwlock / timestamp / errlog). T-fence-1 verifies @@ -2421,7 +2456,7 @@ test_cluster_reconfig: test_cluster_reconfig.c unit_test.h \ $(CLUSTER_REPLACEMENT_EPISODE_O) $(CLUSTER_REPLACEMENT_WIRE_O) \ $(CLUSTER_FORMATION_MARKER_O) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-2.6 Sprint A Step 2 D3: cluster_voting_disk_io.o standalone test. # Real syscalls (open / pread / pwrite / fdatasync) on a temp file — @@ -2434,7 +2469,7 @@ test_cluster_voting_disk_io: test_cluster_voting_disk_io.c unit_test.h \ $(CLUSTER_VERSION_O) $(CLUSTER_VOTING_DISK_IO_O) $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_VERSION_O) $(CLUSTER_VOTING_DISK_IO_O) \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-2.6 Sprint A Step 2 D4: cluster_quorum_decision.o standalone test. # Pure logic — no shmem, no I/O, no logging. Synthetic slot matrix @@ -2471,7 +2506,7 @@ test_cluster_adg: test_cluster_adg.c unit_test.h \ $(CLUSTER_VERSION_O) $(CLUSTER_ADG_O) $(CLUSTER_LNS_O) $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_VERSION_O) $(CLUSTER_ADG_O) $(CLUSTER_LNS_O) \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-2.13 D6: test_cluster_ges links cluster_ges.o standalone. # cluster_ges.c references ShmemInitStruct + cluster_shmem_register_region @@ -2487,7 +2522,7 @@ test_cluster_ges: test_cluster_ges.c unit_test.h \ $(CLUSTER_VERSION_O) $(CLUSTER_GES_O) $(CLUSTER_GES_MODE_O) \ $(CLUSTER_REPLACEMENT_WIRE_O) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # Spec 8.4A D1: exact-key cooperative poll snapshots and consumes a # delivered reply under the reply-table lock without waiting on the CV. @@ -2495,7 +2530,7 @@ test_cluster_ges_reply_wait: test_cluster_ges_reply_wait.c unit_test.h \ $(CLUSTER_GES_REPLY_WAIT_O) $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_GES_REPLY_WAIT_O) \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # P0#3: fixed-capacity, no-overwrite GES cleanup deferred-retry queue. test_cluster_grd_outbound: test_cluster_grd_outbound.c unit_test.h \ @@ -2504,7 +2539,7 @@ test_cluster_grd_outbound: test_cluster_grd_outbound.c unit_test.h \ $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_VERSION_O) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-2.14 D11: test_cluster_grd links cluster_grd.o standalone. # cluster_grd.c references ShmemInitStruct + cluster_shmem_register_region @@ -2523,7 +2558,7 @@ test_cluster_grd: test_cluster_grd.c unit_test.h test_cluster_grd_stop_types.inc $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_VERSION_O) $(CLUSTER_GRD_O) $(CLUSTER_GES_MODE_O) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-5.10 D9: test_cluster_grd_starvation links cluster_grd.o standalone # (same stub surface as test_cluster_grd; the spec-5.8 LMD wait-edge API is @@ -2533,7 +2568,7 @@ test_cluster_grd_starvation: test_cluster_grd_starvation.c unit_test.h \ $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_VERSION_O) $(CLUSTER_GRD_O) $(CLUSTER_GES_MODE_O) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-2.19 D13: test_cluster_lmd links cluster_lmd.o standalone. # cluster_lmd.c references ShmemInitStruct + cluster_shmem_register_region @@ -2559,7 +2594,7 @@ test_cluster_lmd: test_cluster_lmd.c test_cluster_lmd_pending.inc test_cluster_l $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_VERSION_O) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-5.8 D1a: test_cluster_lmd_graph links cluster_lmd_graph.o standalone. # cluster_lmd_graph.c references ShmemInitStruct + ShmemInitHash + hash_search @@ -2572,7 +2607,7 @@ test_cluster_lmd_graph: test_cluster_lmd_graph.c unit_test.h \ $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_VERSION_O) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-5.8 D1d: test_cluster_lmd_wait_state links cluster_lmd_wait_state.o # standalone. The wait-state object depends only on pg_atomic (libpgport); @@ -2586,7 +2621,7 @@ test_cluster_lmd_wait_state: test_cluster_lmd_wait_state.c unit_test.h \ $(CC) $(CFLAGS) $(PTHREAD_CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_VERSION_O) $(CLUSTER_LMD_WAIT_STATE_O) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a $(PTHREAD_LIBS) -o $@ + $(CLUSTER_UNIT_PORT_LIBS) $(PTHREAD_LIBS) -o $@ # spec-5.9 D3: test_cluster_cancel_token links cluster_cancel_token.o # standalone. The match logic (consume_against) only needs the spinlock + @@ -2597,7 +2632,7 @@ test_cluster_cancel_token: test_cluster_cancel_token.c unit_test.h \ $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_VERSION_O) $(CLUSTER_CANCEL_TOKEN_O) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # The collector test includes the real source to exercise private malformed # state without a duplicated layout. The ordinary product object is built @@ -2610,7 +2645,7 @@ test_cluster_lmd_probe_collector: test_cluster_lmd_probe_collector.c unit_test.h $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_VERSION_O) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-2.20 D13: test_cluster_lock_acquire links cluster_lock_acquire.o # standalone. cluster_lock_acquire.c references cluster_lms_is_ready / @@ -2622,7 +2657,7 @@ test_cluster_lock_acquire: test_cluster_lock_acquire.c unit_test.h \ $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_VERSION_O) $(CLUSTER_LOCK_ACQUIRE_O) $(CLUSTER_GES_MODE_O) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # HW handoff uses production objects in two independent address spaces. # Section splitting removes unrelated backend entry points, not tested code. @@ -2638,7 +2673,7 @@ test_cluster_hw_handoff: test_cluster_hw_handoff.c test_cluster_grd.c unit_test. $(CC) $(CFLAGS) $(CPPFLAGS) -ffunction-sections -fdata-sections $< \ $(HW_HANDOFF_OBJECTS) $(R4_RUNTIME_VIS_TEST_DEAD_STRIP) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-5.5 D3/D8: test_cluster_advisory links cluster_advisory.o standalone. # cluster_advisory.c references ShmemInitStruct + cluster_shmem_register_region @@ -2651,7 +2686,7 @@ test_cluster_advisory: test_cluster_advisory.c unit_test.h \ $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_VERSION_O) $(CLUSTER_ADVISORY_O) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-2.30 D9: test_cluster_pcm_lock links cluster_pcm_lock.o standalone. # cluster_pcm_lock.c references 20 PG-runtime symbols (ShmemInit* / LWLock* / @@ -2690,7 +2725,7 @@ test_cluster_pcm_source_replay.inc: $(top_srcdir)/src/backend/cluster/cluster_gc END { if (found != 1 || emit) exit 1 }' $< > $@ test_cluster_pcm_source_replay_consumer.inc: $(top_srcdir)/src/backend/cluster/cluster_gcs_block.c Makefile - awk '/^\t\t\t\treplay_result$$/ { emit=1; begin++ } \ + awk '/^\t\t\t\treplay_result([[:space:]]*=|$$)/ { emit=1; begin++ } \ emit && /^\t\t\t}/ { emit=0; end++ } \ emit { print } \ END { if (begin != 1 || end != 1 || emit) exit 1 }' $< > $@.tmp @@ -2727,7 +2762,7 @@ test_cluster_pcm_lock: test_cluster_pcm_lock.c unit_test.h test_cluster_pcm_wait $(CLUSTER_VERSION_O) test_cluster_pcm_lock_clock_product.o $(CLUSTER_RESOURCE_X_IDENTITY_O) \ $(CLUSTER_RESOURCE_X_NODE_WIRE_O) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-2.36a C1/D5a: the real cluster_pcm_own object is linked against a # fake shmem region. The test also reads the production bufmgr source through @@ -2885,7 +2920,7 @@ test_cluster_bufmgr_stop_owner.inc: $(top_srcdir)/src/backend/storage/buffer/buf test_cluster_bufmgr_stop: test_cluster_bufmgr_stop.c unit_test.h \ test_cluster_pcm_snapshot_owner.inc test_cluster_bufmgr_stop_owner.inc $(CLUSTER_PCM_OWN_O) $(CC) $(CFLAGS) $(CPPFLAGS) $< $(CLUSTER_PCM_OWN_O) \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ test_cluster_pcm_own: test_cluster_pcm_own.c unit_test.h \ test_cluster_pcm_snapshot_owner.inc test_cluster_pcm_transition_owner.inc \ @@ -2900,7 +2935,7 @@ test_cluster_pcm_own: test_cluster_pcm_own.c unit_test.h \ $(CC) $(CFLAGS) $(CPPFLAGS) \ -DBUFMGR_SOURCE_PATH='"$(top_srcdir)/src/backend/storage/buffer/bufmgr.c"' \ $< $(CLUSTER_PCM_OWN_O) \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # S3-core direct-init proof is a dependency-light, process-local decision # layer. The real bufmgr captures/revalidates the snapshots under its header @@ -2913,9 +2948,10 @@ test_cluster_pcm_direct_init: test_cluster_pcm_direct_init.c unit_test.h \ -DFSM_SOURCE_PATH='"$(top_srcdir)/src/backend/storage/freespace/freespace.c"' \ -DHEAPAM_SOURCE_PATH='"$(top_srcdir)/src/backend/access/heap/heapam.c"' \ -DHIO_SOURCE_PATH='"$(top_srcdir)/src/backend/access/heap/hio.c"' \ + -DPROBES_SOURCE_PATH='"$(top_srcdir)/src/backend/utils/probes.d"' \ $< \ $(CLUSTER_PCM_DIRECT_INIT_O) \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ test_cluster_pcm_aux_handoff.inc: $(top_srcdir)/src/backend/storage/buffer/bufmgr.c Makefile awk '/^typedef struct ClusterBufmgrPcmAuxPinHandoff/ { emit=1; type++ } \ @@ -2937,7 +2973,7 @@ test_cluster_pcm_aux_reobserve: test_cluster_pcm_aux_reobserve.c unit_test.h \ test_cluster_pcm_aux_reobserve_owner.inc test_cluster_pcm_aux_reobserve_context.inc \ test_cluster_pcm_aux_prepare.inc test_cluster_heap_vm_lock_entry.inc $(CC) $(CFLAGS) $(CPPFLAGS) $< \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ test_cluster_pcm_aux_reobserve_owner.inc: $(top_srcdir)/src/backend/storage/buffer/bufmgr.c Makefile awk '/^typedef (enum ClusterPcmXWriterLedgerPhase|struct ClusterPcmXWriterLedgerEntry)/ { emit=1; types++ } \ @@ -3050,7 +3086,7 @@ test_cluster_pcm_aux_mutation: test_cluster_pcm_aux_mutation.c unit_test.h \ test_cluster_pcm_aux_fsm_mutation.inc test_cluster_pcm_aux_mutation_consumer.inc \ test_cluster_pcm_aux_page_space.inc $(CC) $(CFLAGS) $(CPPFLAGS) $< \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # Execute the real heap extension consumer and real page initialization. # Only allocation/transport, lock, pin and FSM boundaries are controlled. @@ -3071,7 +3107,7 @@ test_cluster_heap_extend_page.inc: $(top_srcdir)/src/backend/storage/page/bufpag test_cluster_heap_extend_current: test_cluster_heap_extend_current.c unit_test.h \ test_cluster_heap_extend_current.inc test_cluster_heap_extend_page.inc $(CC) $(CFLAGS) $(CPPFLAGS) $< \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ test_cluster_heap_hio_vm.inc: $(top_srcdir)/src/backend/access/heap/hio.c Makefile awk '/^cluster_hio_lock_buffer_pair\(/ { print "static void"; emit=1; pair++ } \ @@ -3118,7 +3154,7 @@ test_cluster_pcm_aux_consumer: test_cluster_pcm_aux_consumer.c unit_test.h \ $(CLUSTER_PCM_DIRECT_INIT_O) $(CLUSTER_RESOURCE_X_IDENTITY_O) $(CC) $(CFLAGS) $(CPPFLAGS) $< $(CLUSTER_PCM_DIRECT_INIT_O) \ $(CLUSTER_RESOURCE_X_IDENTITY_O) \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-8.4 W0: source-path-only static/model RED. Prospective R4 files are # passed as strings (not prerequisites), so their absence is observed as @@ -3161,12 +3197,23 @@ test_cluster_r4_tx_locator: test_cluster_r4_tx_locator.c unit_test.h \ $(CLUSTER_TX_RESOLVE_O) $(CLUSTER_R4_TX_LOCATOR_UBA_O) $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_TX_RESOLVE_O) $(CLUSTER_R4_TX_LOCATOR_UBA_O) \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-8.4 B1/D5: compile the real runtime-visibility provider into a # function-sectioned test object. Dead stripping keeps this existing R4 # target focused on the exact-origin provider without stubbing unrelated # legacy runtime-visibility services from the same production source file. +test_cluster_retained_remote.inc: $(top_srcdir)/src/backend/cluster/cluster_runtime_visibility.c Makefile + awk '/^cluster_runtime_visibility_resolve_terminal_census_retained_remote_exact\(/ { print "static ClusterTxOutcome"; emit=1; found++ } \ + emit { print } emit && /^}/ { emit=0 } \ + END { if (found != 1 || emit) exit 1 }' $< > $@.tmp + mv $@.tmp $@ + +test_cluster_retained_remote: test_cluster_retained_remote.c test_cluster_retained_remote.inc unit_test.h \ + $(top_builddir)/src/backend/cluster/cluster_uba.o + $(CC) $(CFLAGS) $(CPPFLAGS) $< $(top_builddir)/src/backend/cluster/cluster_uba.o \ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ + CLUSTER_R4_RUNTIME_VIS_TEST_O = test_cluster_r4_runtime_visibility_exact.o CLUSTER_R4_RUNTIME_VIS_UBA_O = $(top_builddir)/src/backend/cluster/cluster_uba.o $(CLUSTER_R4_RUNTIME_VIS_TEST_O): $(top_srcdir)/src/backend/cluster/cluster_runtime_visibility.c @@ -3180,7 +3227,7 @@ test_cluster_r4_tx_outcome: test_cluster_r4_tx_outcome.c unit_test.h \ $(CLUSTER_CR_SERVER_POLICY_O) $(CLUSTER_RUNTIME_VIS_POLICY_O) \ $(R4_RUNTIME_VIS_TEST_DEAD_STRIP) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # Real CR shared predicate plus real stripe derivation, with only the # process/lock/nextXid boundaries supplied by the fixture. @@ -3192,7 +3239,7 @@ test_cluster_cr_native_origin: test_cluster_cr_native_origin.c unit_test.h \ $< $(top_builddir)/src/backend/cluster/cluster_xid_stripe.o \ $(R4_RUNTIME_VIS_TEST_DEAD_STRIP) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # Stage 8 R4 D3: compile the real capability store with function sections so # this focused target executes its shared-lock sampler and existing generation @@ -3206,7 +3253,7 @@ test_cluster_sf_dep: test_cluster_sf_dep.c unit_test.h $(top_srcdir)/src/backend $(CC) $(CFLAGS) $(CPPFLAGS) -ffunction-sections -fdata-sections $< \ $(R4_RUNTIME_VIS_TEST_DEAD_STRIP) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # Stage 8 R4 D3: exact REQUEST80/FORWARD96 production decoder seam. The # USE_CLUSTER_UNIT symbols call the same static branches as the registered @@ -3241,7 +3288,7 @@ test_cluster_r4_route_policy: test_cluster_r4_route_policy.c unit_test.h \ $(CLUSTER_VERSION_O) $(CLUSTER_R4_GCS_BLOCK_TEST_O) $(CLUSTER_PCM_OWN_O) \ $(R4_RUNTIME_VIS_TEST_DEAD_STRIP) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # Stage 8 R4 D4-B: compile the real LMS source with function sections so the # focused test seam executes the incarnation publication used by both DATA @@ -3256,7 +3303,7 @@ test_cluster_lms_native_probe: test_cluster_lms_native_probe.c unit_test.h \ -DGES_DEDUP_SOURCE_PATH='"$(abspath $(top_srcdir))/src/backend/cluster/cluster_ges_dedup.c"' \ $< $(R4_RUNTIME_VIS_TEST_DEAD_STRIP) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ $(CLUSTER_R4_LMS_CONTROLS_TEST_O): $(top_srcdir)/src/backend/cluster/cluster_lms.c \ $(top_srcdir)/src/include/cluster/cluster_lms.h @@ -3283,7 +3330,7 @@ test_cluster_cr_inline_stop.inc: $(top_srcdir)/src/backend/cluster/cluster_cr_se test_cluster_cr_inline_stop: test_cluster_cr_inline_stop.c test_cluster_cr_inline_stop.inc unit_test.h $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ $(CLUSTER_R4_SLOT_RESERVATION_TEST_O): $(top_srcdir)/src/backend/cluster/cluster_cr_server.c \ $(top_srcdir)/src/include/cluster/cluster_cr_server.h @@ -3321,7 +3368,7 @@ test_cluster_r4_slot_reservation: test_cluster_r4_slot_reservation.c unit_test.h test_cluster_r4_multi_resolve_product.o $(CLUSTER_CR_APPLY_O) $(CLUSTER_R4_CONTINUATION_PAGE_O) \ $(R4_RUNTIME_VIS_TEST_DEAD_STRIP) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # Stage 8 R4 D11: exercise the thin observation adapter and the real holder # result seam. The fixture supplies only the existing CR-copy/constructor, @@ -3371,7 +3418,7 @@ test_cluster_r4_cr_walk: test_cluster_r4_cr_walk.c unit_test.h \ $(CLUSTER_R4_CR_WALK_TEST_O) $(CLUSTER_R4_MULTI_RESOLVE_TEST_O) \ $(R4_RUNTIME_VIS_TEST_DEAD_STRIP) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # Actual HW startup and file/authority consumer composition. test_cluster_hw_initdb_sync_tail.inc: $(top_srcdir)/src/bin/initdb/initdb.c Makefile @@ -3410,7 +3457,7 @@ test_cluster_hw_cold: test_cluster_hw_cold.c test_cluster_allocation_stop.c unit $(CC) $(CFLAGS) $(CPPFLAGS) -ffunction-sections -fdata-sections $< \ $(CLUSTER_HW_SNAPSHOT_O) $(R4_RUNTIME_VIS_TEST_DEAD_STRIP) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # Actual OID/SQ/HW original allocation owners. test_cluster_allocation_stop: test_cluster_allocation_stop.c unit_test.h \ @@ -3424,14 +3471,14 @@ test_cluster_allocation_stop: test_cluster_allocation_stop.c unit_test.h \ $(CC) $(CFLAGS) $(CPPFLAGS) -ffunction-sections -fdata-sections $< \ $(R4_RUNTIME_VIS_TEST_DEAD_STRIP) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ test_cluster_ic_stop: test_cluster_ic_stop.c unit_test.h \ $(top_srcdir)/src/backend/cluster/cluster_ic_mux.c $(CC) $(CFLAGS) $(CPPFLAGS) -ffunction-sections -fdata-sections $< \ $(R4_RUNTIME_VIS_TEST_DEAD_STRIP) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ test_cluster_rdma_stop.inc: $(top_srcdir)/src/backend/cluster/cluster_ic_rdma.c Makefile awk '/^#define CLUSTER_IC_RDMA_MAX_SGE / { print } \ @@ -3454,14 +3501,14 @@ test_cluster_ko_stop: test_cluster_ko_stop.c unit_test.h \ $(CC) $(CFLAGS) $(CPPFLAGS) -ffunction-sections -fdata-sections $< \ $(R4_RUNTIME_VIS_TEST_DEAD_STRIP) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ test_cluster_sinval_stop: test_cluster_sinval_stop.c unit_test.h \ $(top_srcdir)/src/backend/cluster/cluster_sinval.c $(CC) $(CFLAGS) $(CPPFLAGS) -ffunction-sections -fdata-sections $< \ $(R4_RUNTIME_VIS_TEST_DEAD_STRIP) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ test_cluster_gcs_stop_invalidate.inc: $(top_srcdir)/src/backend/cluster/cluster_gcs_block.c Makefile awk '/^cluster_gcs_handle_block_invalidate_envelope\(/ { print "static void"; emit=1; handlers++ } \ @@ -3485,7 +3532,7 @@ test_cluster_gcs_stop: test_cluster_gcs_stop.c test_cluster_gcs_stop_invalidate. $(CC) $(CFLAGS) $(CPPFLAGS) -ffunction-sections -fdata-sections $< \ $(R4_RUNTIME_VIS_TEST_DEAD_STRIP) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # Actual chunk ownership through final dispatch, with the real envelope codec. test_cluster_ic_chunk_stop: test_cluster_ic_chunk_stop.c unit_test.h \ @@ -3494,7 +3541,7 @@ test_cluster_ic_chunk_stop: test_cluster_ic_chunk_stop.c unit_test.h \ $(CC) $(CFLAGS) $(CPPFLAGS) -ffunction-sections -fdata-sections $< \ $(R4_RUNTIME_VIS_TEST_DEAD_STRIP) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # GCS-race round-4c tier1-partial-IO: test_cluster_ic_tier1_partial links # cluster_ic_tier1.o standalone and drives the PRODUCTION outbound-tail @@ -3509,7 +3556,7 @@ test_cluster_ic_tier1_partial: test_cluster_ic_tier1_partial.c unit_test.h \ $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_VERSION_O) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # GCS serve-stall round-5: test_cluster_lms_outbound links # cluster_lms_outbound.o standalone and pins the drain's four-state send @@ -3525,7 +3572,7 @@ test_cluster_lms_outbound: test_cluster_lms_outbound.c unit_test.h \ $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_VERSION_O) cluster_lms_outbound_test.o \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-2.31 D9 v0.5: test_cluster_bufmgr_pcm_hook verifies the bufmgr # LockBuffer/LockBufferForCleanup PCM hook layer in isolation by using a @@ -3539,7 +3586,7 @@ test_cluster_bufmgr_pcm_hook: test_cluster_bufmgr_pcm_hook.c unit_test.h \ $(CLUSTER_VERSION_O) $(CLUSTER_PCM_LOCK_O) $(CLUSTER_RESOURCE_X_IDENTITY_O) \ $(CLUSTER_RESOURCE_X_NODE_WIRE_O) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-2.32 D9: test_cluster_gcs_dispatch verifies GCS request protocol # skeleton invariants (msg_type enum 12/13, payload ABI lock, dispatch @@ -3550,7 +3597,7 @@ test_cluster_gcs_dispatch: test_cluster_gcs_dispatch.c unit_test.h \ $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_VERSION_O) $(CLUSTER_GCS_O) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # Compile the actual terminal ingress verbatim. Dependencies are explicit # fixture doubles; the master/source decision and call sequence are product C. @@ -3576,7 +3623,7 @@ test_cluster_resource_x_terminal_owner.inc: $(top_srcdir)/src/backend/cluster/cl mv $@.tmp $@ test_cluster_resource_x_terminal_gate_consumer.inc: $(top_srcdir)/src/backend/cluster/cluster_gcs_block.c Makefile - awk '/^[[:space:]]*terminal_admission_current$$/ { emit=1; begin++ } \ + awk '/^[[:space:]]*terminal_admission_current([[:space:]]*=|$$)/ { emit=1; begin++ } \ emit && /memset\(&target_install_follow, 0,/ { emit=0; end++ } \ emit { print } \ END { if (begin != 1 || end != 1 || emit) exit 1 }' $< > $@.tmp @@ -3678,7 +3725,7 @@ test_cluster_resource_x_terminal_ingress: test_cluster_resource_x_terminal_ingre $(top_srcdir)/src/include/cluster/cluster_semantic_activation.h \ $(top_srcdir)/src/include/cluster/cluster_resource_x_node_wire.h $(CC) $(CFLAGS) $(CPPFLAGS) $< $(CLUSTER_RESOURCE_X_IDENTITY_O) \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-2.33 D13: test_cluster_gcs_block verifies GCS block-shipping # substrate compile-time invariants (msg_type 14/15, payload ABI sizes, @@ -3697,13 +3744,14 @@ test_cluster_gcs_block: test_cluster_gcs_block.c unit_test.h \ -DBUFMGR_SOURCE_PATH='"$(top_srcdir)/src/backend/storage/buffer/bufmgr.c"' \ -DLMS_SOURCE_PATH='"$(top_srcdir)/src/backend/cluster/cluster_lms.c"' \ -DLMS_OUTBOUND_SOURCE_PATH='"$(top_srcdir)/src/backend/cluster/cluster_lms_outbound.c"' \ + -DLMON_SOURCE_PATH='"$(top_srcdir)/src/backend/cluster/cluster_lmon.c"' \ -DT400_SOURCE_PATH='"$(top_srcdir)/src/test/cluster_tap/t/400_pcm_x_queue_4node_liveness.pl"' \ -DT406_SOURCE_PATH='"$(top_srcdir)/src/test/cluster_tap/t/406_resource_x_finish_flush_failclosed_4node.pl"' \ $< \ $(CLUSTER_VERSION_O) $(CLUSTER_RESOURCE_X_IDENTITY_O) \ $(CLUSTER_RESOURCE_X_RETRY_O) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a $(PTHREAD_LIBS) -o $@ + $(CLUSTER_UNIT_PORT_LIBS) $(PTHREAD_LIBS) -o $@ # spec-2.34 D13: test_cluster_gcs_block_retransmit verifies reliability # hardening compile-time invariants (status enum 7→8, dedup entry 8312B @@ -3715,7 +3763,7 @@ test_cluster_gcs_block_retransmit: test_cluster_gcs_block_retransmit.c unit_test $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_VERSION_O) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-7.2a: test_cluster_gcs_block_dedup_reclaim verifies the eager-reclaim # safety decision primitives (review r1): in-window reclaim whitelist @@ -3729,7 +3777,7 @@ test_cluster_gcs_block_dedup_reclaim: test_cluster_gcs_block_dedup_reclaim.c uni $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_VERSION_O) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-7.2a review F4: test_cluster_gcs_block_dedup_htab links the REAL # cluster_gcs_block_dedup.o and drives lookup_or_register to cap against a @@ -3743,7 +3791,7 @@ test_cluster_gcs_block_dedup_htab: test_cluster_gcs_block_dedup_htab.c unit_test $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_VERSION_O) $(CLUSTER_GCS_BLOCK_DEDUP_O) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # Stage 8 R4 D3 P1-B: compile the real dedup source into a target-local object # whose instr_time clock_gettime call is redirected to the independent fixture @@ -3761,7 +3809,7 @@ test_cluster_gcs_block_dedup_r4_route: test_cluster_gcs_block_dedup_r4_route.c u $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_R4_ROUTE_DEDUP_TEST_O) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-2.35 D17: test_cluster_gcs_block_2way verifies CF 2-way protocol # compile-time invariants (msg_type 16, status 8, GcsBlockForwardPayload @@ -3773,7 +3821,7 @@ test_cluster_gcs_block_2way: test_cluster_gcs_block_2way.c unit_test.h \ $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_VERSION_O) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-2.36 D11/D12: test_cluster_gcs_block_3way verifies CF 3-way # protocol compile-time invariants (msg_type 17/18, reply status 9/10/11, @@ -3786,7 +3834,7 @@ test_cluster_gcs_block_3way: test_cluster_gcs_block_3way.c unit_test.h \ $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_VERSION_O) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-2.37 D13: test_cluster_gcs_block_lost_write verifies PI watermark # + lost-write detection MVP compile-time invariants (reply status 12, @@ -3798,7 +3846,7 @@ test_cluster_gcs_block_lost_write: test_cluster_gcs_block_lost_write.c unit_test $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_VERSION_O) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-2.38 D11/D12: test_cluster_sinval verifies SI Broadcaster skeleton # compile-time invariants (msg_type 7, LMON-mediated SINVAL fanout @@ -3813,7 +3861,7 @@ test_cluster_sinval: test_cluster_sinval.c unit_test.h \ $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_VERSION_O) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-2.39 D15: test_cluster_sinval_ack verifies the ack/barrier wire # ABI + flag encoding + enum invariants (msg_type 19 not colliding with @@ -3827,7 +3875,7 @@ test_cluster_sinval_ack: test_cluster_sinval_ack.c unit_test.h \ $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_VERSION_O) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-2.40 D8: test_cluster_stage2_acceptance — 8 static contract # tests verifying Stage 2 final surface snapshot (catversion >= 202605460, @@ -3841,7 +3889,7 @@ test_cluster_stage2_acceptance: test_cluster_stage2_acceptance.c unit_test.h ../ $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_VERSION_O) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-3.1 D9: test_cluster_tt_status — 22 真 C 单测 verifying the Undo # TT status foundation static contract (24B ClusterTTStatusKey with @@ -3855,7 +3903,7 @@ test_cluster_tt_status: test_cluster_tt_status.c unit_test.h \ $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_VERSION_O) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-3.2 D9: test_cluster_tt_status_hint — 18 static contract tests # verifying cross-node TT status hint wire ABI (32B with embedded @@ -3869,7 +3917,7 @@ test_cluster_tt_status_hint: test_cluster_tt_status_hint.c unit_test.h \ $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_VERSION_O) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-3.2 D10: test_cluster_visibility_fork — 12 static contract tests # verifying HeapTupleSatisfiesMVCC cluster fork inputs (ClusterUndoTTSlotRef @@ -3891,7 +3939,7 @@ test_cluster_visibility_fork: test_cluster_visibility_fork.c unit_test.h \ $< \ $(CLUSTER_VERSION_O) $(CLUSTER_VIS_VERDICT_O) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-3.3 D11: test_cluster_visibility_decide_scn — 22 static + # behavioral mock tests verifying cluster_visibility_decide_by_scn() and @@ -3907,7 +3955,7 @@ test_cluster_visibility_decide_scn: test_cluster_visibility_decide_scn.c unit_te $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_VERSION_O) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-3.3 D12: test_cluster_snapshot_source — 18 static + ABI tests # verifying SnapshotData explicit 24B cluster tail (D1), the SnapshotSource @@ -3918,7 +3966,7 @@ test_cluster_snapshot_source: test_cluster_snapshot_source.c unit_test.h \ $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_VERSION_O) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-3.4a D11: test_cluster_itl_touch — 23 static + ABI tests # verifying ClusterItlTouchHandle 24B layout, writer API symbols @@ -3932,7 +3980,7 @@ test_cluster_itl_touch: test_cluster_itl_touch.c unit_test.h \ $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_VERSION_O) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-8.3 D11: test_cluster_active_itl_transfer pins the active-ITL # current-block transfer contracts. Header-inline policy checks cover the @@ -3945,7 +3993,7 @@ test_cluster_active_itl_transfer: test_cluster_active_itl_transfer.c unit_test.h $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_VERSION_O) $(CLUSTER_ITL_TOUCH_REAL_O) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-3.4a D12: test_cluster_itl_wal — 18 static ABI tests for the # heap WAL ITL delta block-local array layout (xl_heap_itl_delta 24B @@ -3957,7 +4005,7 @@ test_cluster_itl_wal: test_cluster_itl_wal.c unit_test.h \ $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_VERSION_O) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-3.4b D10: test_cluster_uba — 24 static + inline-helper tests # covering the UBA encode/decode helpers + offset/id sentinel separation @@ -3968,7 +4016,7 @@ test_cluster_uba: test_cluster_uba.c unit_test.h \ $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_VERSION_O) $(CLUSTER_UBA_O) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-3.4b D11: test_cluster_tt_slot_allocator — 30 tests linking the # real cluster_tt_slot.o + mocked ShmemInitStruct / LWLock / ereport so @@ -3985,7 +4033,7 @@ test_cluster_tt_durable: test_cluster_tt_durable.c unit_test.h \ $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_TT_DURABLE_O) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # Includes the real local consumer to seed otherwise unreachable partial # publication states; dead stripping removes unrelated local entry points. @@ -3994,7 +4042,7 @@ test_cluster_tt_abort_owner: test_cluster_tt_abort_owner.c test_cluster_tt_durab $(CC) $(CFLAGS) $(CPPFLAGS) -ffunction-sections -fdata-sections $< \ $(CLUSTER_TT_DURABLE_O) $(R4_RUNTIME_VIS_TEST_DEAD_STRIP) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ test_cluster_tt_active_owner: test_cluster_tt_active_owner.c test_cluster_tt_durable.c unit_test.h \ $(top_srcdir)/src/backend/cluster/cluster_tt_local.c \ @@ -4002,14 +4050,14 @@ test_cluster_tt_active_owner: test_cluster_tt_active_owner.c test_cluster_tt_dur $(CC) $(CFLAGS) $(CPPFLAGS) -ffunction-sections -fdata-sections $< \ $(CLUSTER_TT_DURABLE_O) $(R4_RUNTIME_VIS_TEST_DEAD_STRIP) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ test_cluster_tt_slot_allocator: test_cluster_tt_slot_allocator.c unit_test.h \ $(CLUSTER_VERSION_O) $(CLUSTER_TT_SLOT_O) $(CLUSTER_UNDO_RETENTION_O) $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_VERSION_O) $(CLUSTER_TT_SLOT_O) $(CLUSTER_UNDO_RETENTION_O) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-3.4b D12: test_cluster_itl_reader_real_triple — 18 tests for # the 3-branch reader (FREE / UBA_is_invalid legacy / real decode) on @@ -4030,7 +4078,7 @@ test_cluster_itl_reader_real_triple: test_cluster_itl_reader_real_triple.c unit_ test_cluster_itl_inverse_product.o $(R4_RUNTIME_VIS_TEST_DEAD_STRIP) \ $(CLUSTER_VERSION_O) $(CLUSTER_ITL_O) $(CLUSTER_UBA_O) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-3.4c D10: test_cluster_itl_cleanout — 20 tests covering the # lazy cleanout helper symbol surface + can_stamp() pure-data @@ -4045,7 +4093,7 @@ test_cluster_itl_cleanout: test_cluster_itl_cleanout.c unit_test.h \ $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_VERSION_O) $(CLUSTER_ITL_CLEANOUT_O) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-3.4c D11: test_cluster_visibility_inject — 16 tests covering # the D5b inject UDF surface + A1 install_local + F4 delete_exact @@ -4057,7 +4105,7 @@ test_cluster_visibility_inject: test_cluster_visibility_inject.c unit_test.h \ $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_VERSION_O) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-3.4c D13: test_cluster_itl_cleanout_perf — 8 tests covering # the D14 per-page aggregate layout (ClusterItlPagedHandle @@ -4070,7 +4118,7 @@ test_cluster_itl_cleanout_perf: test_cluster_itl_cleanout_perf.c unit_test.h \ $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_VERSION_O) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-3.4d D13: test_cluster_heap_lock_tuple — 19 tests covering the # spec-3.4d ABI / lock-only ITL enum / SQLSTATE / WAL flag / counter @@ -4082,7 +4130,7 @@ test_cluster_heap_lock_tuple: test_cluster_heap_lock_tuple.c unit_test.h \ $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_VERSION_O) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-3.4e D5: test_cluster_perf_gates — 10 pure ABI / threshold / # symbol-link tests for 5-tier × 4 workload class perf gate contract. @@ -4092,7 +4140,7 @@ test_cluster_perf_gates: test_cluster_perf_gates.c unit_test.h \ $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_VERSION_O) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-3.5 D12: test_cluster_subtrans — 12 pure ABI / offsetof / sizeof / # enum / SQLSTATE / symbol-link tests for SUBTRANS cross-node visibility @@ -4103,7 +4151,7 @@ test_cluster_subtrans: test_cluster_subtrans.c unit_test.h \ $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_VERSION_O) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-3.6 D10: test_cluster_multixact — 16 pure ABI / offsetof / sizeof / # enum / SQLSTATE / symbol-link tests for MULTIXACT reader/member-resolution @@ -4115,7 +4163,7 @@ test_cluster_multixact: test_cluster_multixact.c unit_test.h \ $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_VERSION_O) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-3.6b D1: pure current-DML descriptor/proof validators and compositor. CLUSTER_MULTIXACT_CURRENT_O = $(top_builddir)/src/backend/cluster/cluster_multixact_current.o @@ -4179,7 +4227,7 @@ test_cluster_undo_format: test_cluster_undo_format.c unit_test.h \ $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_VERSION_O) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-3.7 D12 + spec-8.1 O4: encode/decode tests plus the real read-only # pool observer and once-per-postmaster publication lifecycle. Build the two @@ -4225,7 +4273,7 @@ test_cluster_undo_block0: test_cluster_undo_block0.c unit_test.h \ $(CLUSTER_VERSION_O) $(CLUSTER_UNDO_BLOCK0_O) $(CLUSTER_UNDO_BLOCK0_RESIDENT_O) \ $(CLUSTER_UNDO_ROOT_DESCRIPTOR_O) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a $(PTHREAD_LIBS) -o $@ + $(CLUSTER_UNIT_PORT_LIBS) $(PTHREAD_LIBS) -o $@ # Spec 8.4A Candidate-2: the fixture includes the exact current owner source # so it can pin private key/phase invariants without exporting test-only ABI. @@ -4237,7 +4285,7 @@ test_cluster_undo_block0_current: test_cluster_undo_block0_current.c unit_test.h $(CLUSTER_UNDO_BLOCK0_RESIDENT_O) $(CLUSTER_GES_REPLY_WAIT_O) $(CLUSTER_GES_O) $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # Spec 8.4A P3 first publication: the fixture includes the real smgr source # and runs typed final-path/no-replace behavior against a private temp dir. @@ -4247,7 +4295,7 @@ test_cluster_undo_smgr_publication: test_cluster_undo_smgr_publication.c unit_te $(CC) $(CFLAGS) $(CPPFLAGS) -ffunction-sections -fdata-sections $< \ $(CLUSTER_UNDO_TEST_GC_SECTIONS) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-8.4 D13: these activation policy targets include the real # dependency-light product source so static codec/FSM/lock-policy helpers are @@ -4257,15 +4305,16 @@ CLUSTER_SEMANTIC_ACTIVATION_C = $(top_srcdir)/src/backend/cluster/cluster_semant CLUSTER_SEMANTIC_ACTIVATION_H = $(top_srcdir)/src/include/cluster/cluster_semantic_activation.h test_cluster_r4_activation_record: test_cluster_r4_activation_record.c unit_test.h \ + cluster_unit_no_normal_stop.h \ cluster_r4_activation_test_stubs.h \ $(CLUSTER_SEMANTIC_ACTIVATION_C) $(CLUSTER_SEMANTIC_ACTIVATION_H) \ $(CLUSTER_VERSION_O) $(CLUSTER_UNDO_BLOCK0_O) \ $(CLUSTER_UNDO_ROOT_DESCRIPTOR_O) - $(CC) $(CFLAGS) $(CPPFLAGS) $< \ + $(CC) $(CFLAGS) $(CPPFLAGS) -ffunction-sections -fdata-sections $< \ $(CLUSTER_VERSION_O) $(CLUSTER_UNDO_BLOCK0_O) \ $(CLUSTER_UNDO_ROOT_DESCRIPTOR_O) \ $(top_builddir)/src/common/libpgcommon.a \ - $(top_builddir)/src/port/libpgport_srv.a $(LDFLAGS) -lssl -lcrypto -o $@ + $(CLUSTER_UNIT_PORT_LIBS) $(R4_RUNTIME_VIS_TEST_DEAD_STRIP) $(LDFLAGS) -lssl -lcrypto -o $@ CLUSTER_R4_OPEN_ROUTE_TEST_O = test_cluster_r4_open_route_product.o $(CLUSTER_R4_OPEN_ROUTE_TEST_O): $(top_srcdir)/src/backend/cluster/cluster_gcs_block.c \ @@ -4313,8 +4362,8 @@ test_cluster_r4_activation_fsm: test_cluster_r4_activation_fsm.c unit_test.h tes $(CLUSTER_UNDO_ROOT_DESCRIPTOR_O) $(CLUSTER_R4_OPEN_ROUTE_TEST_O) \ $(CLUSTER_UNDO_BLOCK0_RESIDENT_O) \ $(R4_RUNTIME_VIS_TEST_DEAD_STRIP) \ - $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a $(LDFLAGS) -lssl -lcrypto -o $@ + $(CLUSTER_UNIT_CRYPTOHASH_O) $(top_builddir)/src/common/libpgcommon_srv.a \ + $(CLUSTER_UNIT_PORT_LIBS) $(LDFLAGS) -lssl -lcrypto -o $@ # Stage 8 R4 D6 lifecycle/store RED tranche: link the real heap HOT lifecycle, # index-handler ownership switch, executor buffer-slot implementation and heap @@ -4378,7 +4427,7 @@ test_cluster_heap_inplace_lock.inc: $(top_srcdir)/src/backend/access/heap/heapam test_cluster_heap_inplace: test_cluster_heap_inplace.c unit_test.h test_cluster_heap_inplace_consumer.inc test_cluster_heap_inplace_lock.inc $(CLUSTER_HOT_BUFPAGE_TEST_O) $(CC) $(CFLAGS) $(CPPFLAGS) -ffunction-sections -fdata-sections $< \ $(CLUSTER_HOT_BUFPAGE_TEST_O) $(R4_RUNTIME_VIS_TEST_DEAD_STRIP) \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ test_cluster_heap_epq_consumer.inc: $(top_srcdir)/src/backend/access/heap/heapam_handler.c Makefile awk '/^heapam_tuple_lock\(/ { print "static TM_Result"; emit=1; found++ } \ @@ -4492,7 +4541,7 @@ test_cluster_index_exhaustion.inc: $(top_srcdir)/src/backend/access/index/indexa test_cluster_heap_epq_wait: test_cluster_heap_epq_wait.c unit_test.h test_cluster_heap_epq_consumer.inc test_cluster_heap_fetch_consumer.inc test_cluster_heap_lock_dispatch.inc test_cluster_heap_lock_output.inc test_cluster_heap_lock_reacquire.inc test_cluster_heap_lock_rebind.inc test_cluster_heap_lock_self.inc test_cluster_heap_lock_strength.inc test_cluster_heap_scan_lifetime.inc test_cluster_heap_scan_consumers.inc test_cluster_heap_snapshot_consumer.inc test_cluster_heap_index_recheck.inc test_cluster_heap_index_recapture.inc test_cluster_heap_copy_entry.inc test_cluster_heap_copy_exit.inc test_cluster_index_exhaustion.inc $(CLUSTER_HOT_BUFPAGE_TEST_O) $(CC) $(CFLAGS) $(CPPFLAGS) -ffunction-sections -fdata-sections $< \ $(CLUSTER_HOT_BUFPAGE_TEST_O) $(R4_RUNTIME_VIS_TEST_DEAD_STRIP) \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # Compile the actual backend branch, not the unit-only reachability seam. test_cluster_r4_hot_reachability.inc: $(top_srcdir)/src/backend/access/heap/heapam.c Makefile @@ -4578,7 +4627,23 @@ test_cluster_heap_dml_lifetime: test_cluster_heap_dml_lifetime.c unit_test.h \ $(CC) $(CFLAGS) $(CPPFLAGS) -ffunction-sections -fdata-sections $< \ $(CLUSTER_HOT_BUFPAGE_TEST_O) $(CLUSTER_R4_HEAPTUPLE_TEST_O) $(R4_RUNTIME_VIS_TEST_DEAD_STRIP) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ + +# PGRAC: execute the actual prepare decision body; services are fixture seams. +test_cluster_heap_prepare_diagnostic.inc: $(top_srcdir)/src/backend/access/heap/heapam.c Makefile + awk '/^typedef enum ClusterHeapPreparedUndoResult/ { emit=1 } \ + /^cluster_heap_itl_prepare_prepared_undo\(/ { print "static ClusterHeapPreparedUndoResult"; emit=1; found++ } \ + emit { print } emit && /^} ClusterHeapPreparedUndoResult;/ { emit=0 } \ + emit && /const char \*\*refusal_reason/ { diagnostic=1 } \ + emit && /uint64 \*capacity_wait_deadline_us/ { capacity_wait=1 } \ + emit && /^}/ { emit=0; done++ } \ + END { if (found != 1 || done != 1) exit 1; \ + if (diagnostic) print "#define PREPARE_HAS_DIAGNOSTIC 1"; \ + if (capacity_wait) print "#define PREPARE_HAS_CAPACITY_WAIT 1" }' $< > $@.tmp + mv $@.tmp $@ + +test_cluster_heap_prepare_diagnostic: test_cluster_heap_prepare_diagnostic.c unit_test.h test_cluster_heap_prepare_diagnostic.inc + $(CC) $(CFLAGS) $(CPPFLAGS) $< -o $@ test_cluster_heap_update_temp_lock: test_cluster_heap_update_temp_lock.c unit_test.h test_cluster_heap_update_temp_lock.inc test_cluster_heap_update_temp_consumer.inc test_cluster_heap_lock_return_receipt.inc test_cluster_heap_update_successor_header.inc $(CC) $(CFLAGS) $(CPPFLAGS) $< -o $@ @@ -4600,8 +4665,8 @@ test_cluster_r4_lock_order: test_cluster_r4_lock_order.c unit_test.h \ $(CLUSTER_R4_HEAPTUPLE_TEST_O) $(CLUSTER_WRITER_CHAIN_O) $(CLUSTER_VIS_VERDICT_O) \ $(CLUSTER_HOT_PRUNE_TEST_O) $(CLUSTER_HOT_BUFPAGE_TEST_O) $(CLUSTER_HOT_HORIZON_O) \ $(R4_RUNTIME_VIS_TEST_DEAD_STRIP) \ - $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_CRYPTOHASH_O) $(top_builddir)/src/common/libpgcommon_srv.a \ + $(CLUSTER_UNIT_PORT_LIBS) $(LDFLAGS) $(filter -lssl -lcrypto,$(LIBS)) -o $@ # PGRAC: keep the real terminal-only resolver in the ITL capacity consumer # test. Origin responses and TX wakeups are controlled by the fixture. @@ -4617,8 +4682,8 @@ test_cluster_r4_itl_capacity: test_cluster_r4_itl_capacity.c test_cluster_r4_loc $(CLUSTER_HOT_BUFPAGE_TEST_O) $(CLUSTER_UNDO_ROOT_DESCRIPTOR_O) \ $(CLUSTER_VERSION_O) $(CLUSTER_UNDO_BLOCK0_O) $(CLUSTER_CR_APPLY_O) \ $(CLUSTER_VIS_VERDICT_O) $(R4_RUNTIME_VIS_TEST_DEAD_STRIP) \ - $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_CRYPTOHASH_O) $(top_builddir)/src/common/libpgcommon_srv.a \ + $(CLUSTER_UNIT_PORT_LIBS) $(LDFLAGS) $(filter -lssl -lcrypto,$(LIBS)) -o $@ # Unit37 final receipt: execute the real exact-ref resolver body on its # peer-origin memo-hit path. All overlay, wire, native-CLOG and durable @@ -4641,7 +4706,7 @@ test_cluster_cr_mvcc_origin: test_cluster_cr_mvcc_origin.c test_cluster_cr_mvcc_ $(CLUSTER_R4_SCRATCH_RESOLVER_TEST_O) $(CLUSTER_VIS_VERDICT_O) \ $(CLUSTER_R4_HOT_VIS_TEST_O) $(R4_RUNTIME_VIS_TEST_DEAD_STRIP) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ $(CLUSTER_R4_SCRATCH_RESOLVER_TEST_O): \ $(top_srcdir)/src/backend/cluster/cluster_visibility_resolve.c @@ -4657,7 +4722,7 @@ test_cluster_r4_scratch_resolver: test_cluster_r4_scratch_resolver.c unit_test.h $(CLUSTER_R4_HOT_VIS_TEST_O) \ $(R4_RUNTIME_VIS_TEST_DEAD_STRIP) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-3.7 D12: test_cluster_undo_record — 12 encode/decode round-trip # tests for UndoRecordHeader + 4 payloads + slot dir addressing. @@ -4688,7 +4753,7 @@ test_cluster_undo_record: test_cluster_undo_record.c unit_test.h \ $< test_cluster_undo_ctrc_product.o $(CLUSTER_UBA_O) \ $(CLUSTER_VERSION_O) $(CLUSTER_UNDO_ALLOC_TEST_O) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a $(CLUSTER_UNDO_TEST_GC_SECTIONS) -o $@ + $(CLUSTER_UNIT_PORT_LIBS) $(CLUSTER_UNDO_TEST_GC_SECTIONS) -o $@ # Link the actual heap final planner, not the USE_CLUSTER_UNIT boundary mocks. test_cluster_heap_receipt_product.o: test_cluster_heap_receipt_product.c \ @@ -4714,7 +4779,7 @@ test_cluster_heap_receipt: test_cluster_heap_receipt.c test_cluster_undo_record. $< test_cluster_heap_receipt_product.o $(CLUSTER_HOT_BUFPAGE_TEST_O) $(CLUSTER_UBA_O) \ test_cluster_undo_ctrc_product.o $(CLUSTER_VERSION_O) $(CLUSTER_UNDO_ALLOC_TEST_O) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a $(CLUSTER_UNDO_TEST_GC_SECTIONS) -o $@ + $(CLUSTER_UNIT_PORT_LIBS) $(CLUSTER_UNDO_TEST_GC_SECTIONS) -o $@ # CTRC focused contract: compile the real dependency-light state engine with # section GC. The test supplies only PostgreSQL runtime boundary stubs; all @@ -4743,7 +4808,7 @@ test_cluster_undo_cleaner_capacity: test_cluster_undo_cleaner_capacity.c test_cl $(top_srcdir)/src/include/miscadmin.h unit_test.h $(CC) $(CFLAGS) $(CPPFLAGS) -ffunction-sections -fdata-sections $< \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a \ + $(CLUSTER_UNIT_PORT_LIBS) \ $(CLUSTER_UNDO_TEST_GC_SECTIONS) -o $@ test_cluster_ctrc_run_pass.inc: $(top_srcdir)/src/backend/cluster/cluster_terminal_ref_census.c Makefile awk '/^cluster_ctrc_cleaner_run_pass\(/ { print "bool"; emit=1; count++ } \ @@ -4755,7 +4820,7 @@ test_cluster_ctrc_capacity: test_cluster_ctrc_capacity.c test_cluster_ctrc_clean $(top_srcdir)/src/include/cluster/cluster_terminal_ref_census.h unit_test.h $(CC) $(CFLAGS) $(CPPFLAGS) -ffunction-sections -fdata-sections $< \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a \ + $(CLUSTER_UNIT_PORT_LIBS) \ $(CLUSTER_UNDO_TEST_GC_SECTIONS) -o $@ test_cluster_undo_cleaner: $(top_srcdir)/src/include/cluster/cluster_undo_cleaner.h \ $(top_srcdir)/src/include/miscadmin.h @@ -4765,7 +4830,7 @@ test_cluster_ctrc_cleaner: test_cluster_ctrc_cleaner.c test_cluster_ctrc_run_pas $(top_srcdir)/src/include/cluster/cluster_terminal_ref_census.h $(CC) $(CFLAGS) $(CPPFLAGS) -ffunction-sections -fdata-sections $< \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a \ + $(CLUSTER_UNIT_PORT_LIBS) \ $(CLUSTER_UNDO_TEST_GC_SECTIONS) -o $@ # Whole production cleaner and exact-page guard, not a reconstructed predicate. @@ -4791,7 +4856,7 @@ test_cluster_ctrc_itl_reuse: test_cluster_ctrc_itl_reuse.c test_cluster_ctrc_cle $(CC) $(CFLAGS) $(CPPFLAGS) -ffunction-sections -fdata-sections $< \ test_cluster_ctrc_itl_roles_product.o test_cluster_ctrc_transam_product.o \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a \ + $(CLUSTER_UNIT_PORT_LIBS) \ $(CLUSTER_UNDO_TEST_GC_SECTIONS) -o $@ # Verbatim actual dispatcher bodies, with the same fail-if-missing extraction @@ -4814,7 +4879,7 @@ test_cluster_ctrc_dispatch: test_cluster_ctrc_dispatch.c test_cluster_ctrc_clean $(top_srcdir)/src/include/cluster/cluster_gcs_block.h $(CC) $(CFLAGS) $(CPPFLAGS) -ffunction-sections -fdata-sections $< \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a \ + $(CLUSTER_UNIT_PORT_LIBS) \ $(CLUSTER_UNDO_TEST_GC_SECTIONS) -o $@ .PHONY: check_ctrc_source_census @@ -4847,7 +4912,7 @@ test_cluster_terminal_ref_census: test_cluster_terminal_ref_census.c test_cluste -DPGRAC_SOURCE_ROOT_PATH='"$(abspath $(top_srcdir))"' \ $< $(CLUSTER_CTRC_TEST_O) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a \ + $(CLUSTER_UNIT_PORT_LIBS) \ $(CLUSTER_UNDO_TEST_GC_SECTIONS) -o $@ @@ -4863,7 +4928,7 @@ test_cluster_wal_state: test_cluster_wal_state.c unit_test.h \ $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_VERSION_O) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ CLUSTER_WAL_STATE_O = $(top_builddir)/src/backend/cluster/cluster_wal_state.o @@ -4874,7 +4939,7 @@ test_cluster_wal_state_rmw: test_cluster_wal_state_rmw.c unit_test.h \ $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_VERSION_O) $(CLUSTER_WAL_STATE_O) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-4.5 D11: test_cluster_recovery_merge — 20 pure tests (k-way # heap ordering scn->lsn->node, G/S/L/U class matrix, xl_scn layout). @@ -4886,7 +4951,7 @@ test_cluster_recovery_merge: test_cluster_recovery_merge.c unit_test.h \ $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_VERSION_O) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-4.4 D7: test_cluster_recovery_worker — 15 pure-helper tests # (round-robin striping conservation, page-header check incl. the P0 @@ -4898,7 +4963,7 @@ test_cluster_recovery_worker: test_cluster_recovery_worker.c unit_test.h \ $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_VERSION_O) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-4.3 D6: test_cluster_recovery_plan — 16 pure-classifier tests # for the recovery plan (§3.2 truth table 1:1: own-priority family, @@ -4912,7 +4977,7 @@ test_cluster_recovery_plan: test_cluster_recovery_plan.c unit_test.h \ $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_VERSION_O) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-4.1 D8: test_cluster_wal_thread — 12 pure-helper tests for the # per-thread WAL routing surface (identity mapping / dir name / page @@ -4925,7 +4990,7 @@ test_cluster_wal_thread: test_cluster_wal_thread.c unit_test.h \ $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_VERSION_O) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-3.8 D12: test_cluster_undo_lifecycle — 10 pure ABI / enum / # SQLSTATE / sizeof / offsetof tests for Undo Segment Lifecycle MVP + @@ -4936,7 +5001,7 @@ test_cluster_undo_lifecycle: test_cluster_undo_lifecycle.c unit_test.h \ $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_VERSION_O) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-3.9 D10: test_cluster_cr — ABI / SQLSTATE + the 4 inverse-apply # helpers (cluster_cr_apply.o) on a synthetic ITL page. Chain walker / @@ -4947,7 +5012,7 @@ test_cluster_cr: test_cluster_cr.c unit_test.h \ $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_CR_APPLY_O) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-3.10 D8: test_cluster_cr_cache — backend-local clock CR cache # (cluster_cr_cache.o) with malloc-backed MemoryContext stubs. @@ -4957,7 +5022,7 @@ test_cluster_cr_cache: test_cluster_cr_cache.c unit_test.h \ $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_CR_CACHE_O) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-5.53 D7: test_cluster_cr_key — CR cache key identity contract # (cluster_cr_cache_key_equal): per-field necessity, joint sufficiency, @@ -4967,7 +5032,7 @@ test_cluster_cr_key: test_cluster_cr_key.c unit_test.h \ $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_CR_CACHE_O) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-5.51: test_cluster_cr_pool — shared CR buffer pool substrate # (cluster_cr_pool.o + cluster_cr_cache.o for canonical key_equal) with @@ -4978,7 +5043,7 @@ test_cluster_cr_pool: test_cluster_cr_pool.c unit_test.h \ $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_CR_POOL_O) $(CLUSTER_CR_CACHE_O) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-5.56: test_cluster_cr_lifecycle — CR pool lifecycle / invalidation contract # (C1-C4) + per-relation generation table (composite fence, INV-G1/G2/G3, overflow, @@ -4988,7 +5053,7 @@ test_cluster_cr_lifecycle: test_cluster_cr_lifecycle.c unit_test.h \ $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_CR_POOL_O) $(CLUSTER_CR_CACHE_O) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-5.52: test_cluster_cr_admit — backend-local admission predicate + # scan-kind marker lifecycle + page-identity churn detector + per-backend @@ -5001,7 +5066,7 @@ test_cluster_cr_admit: test_cluster_cr_admit.c unit_test.h \ $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_CR_ADMIT_O) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-5.55: test_cluster_resolver_cache — shared resolver cache module # (cluster_resolver_cache.o) with malloc-backed ShmemInitStruct + no-op LWLock @@ -5013,7 +5078,7 @@ test_cluster_resolver_cache: test_cluster_resolver_cache.c unit_test.h \ $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_RESOLVER_CACHE_O) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-5.52 D9: test_cluster_cr_admit_stat — independent admission reason # counter shmem region (cluster_cr_admit_stat.o) with malloc-backed @@ -5024,7 +5089,7 @@ test_cluster_cr_admit_stat: test_cluster_cr_admit_stat.c unit_test.h \ $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_CR_ADMIT_STAT_O) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-5.54 D5: test_cluster_cr_tuple_stat — independent tuple-level CR fast-path # outcome counter shmem region (cluster_cr_tuple_stat.o) with malloc-backed @@ -5035,7 +5100,7 @@ test_cluster_cr_tuple_stat: test_cluster_cr_tuple_stat.c unit_test.h \ $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_CR_TUPLE_STAT_O) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-5.54 D7: test_cluster_cr_tuple — D1 static eligibility predicate + D2 # TargetTupleCrState per-record transitions on a synthetic ITL page. Links @@ -5047,7 +5112,7 @@ test_cluster_cr_tuple: test_cluster_cr_tuple.c unit_test.h \ $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_CR_TUPLE_O) $(CLUSTER_CR_APPLY_O) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-5.57 D9: test_cluster_cr_coordinator — cross-instance CR/current read-path # coordinator boundary module (cluster_cr_coordinator_stat.o): independent @@ -5061,7 +5126,7 @@ test_cluster_cr_coordinator: test_cluster_cr_coordinator.c unit_test.h \ $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_CR_COORDINATOR_STAT_O) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-6.15 D2: test_cluster_xid_stripe — U1 truth tables for the xid # stripe pure derivation layer (widen signed window / origin_slot floor @@ -5075,7 +5140,7 @@ test_cluster_xid_stripe: test_cluster_xid_stripe.c unit_test.h \ $(CLUSTER_XID_STRIPE_O) $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_XID_STRIPE_O) \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-5.22a D1: test_cluster_undo_resid — shared-undo block resource # identity pure layer (undo resid class byte + encode/decode + @@ -5088,7 +5153,7 @@ test_cluster_undo_resid: test_cluster_undo_resid.c unit_test.h \ $(CLUSTER_VERSION_O) $(CLUSTER_UNDO_RESID_O) $(CLUSTER_HW_O) $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_VERSION_O) $(CLUSTER_UNDO_RESID_O) $(CLUSTER_HW_O) \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-5.22d D4-1: test_cluster_undo_authority — dead/absent-owner undo # serve-authority election pure layer (deterministic lowest-fresh-survivor + @@ -5102,7 +5167,7 @@ test_cluster_undo_authority: test_cluster_undo_authority.c unit_test.h \ $(CLUSTER_VERSION_O) $(CLUSTER_UNDO_AUTHORITY_O) $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_VERSION_O) $(CLUSTER_UNDO_AUTHORITY_O) \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-5.22e D5-1: test_cluster_undo_horizon — cluster-wide undo retention # horizon pure fold (required-MEMBER report views -> recycle floor, U1-U16 @@ -5123,7 +5188,7 @@ test_cluster_undo_horizon: test_cluster_undo_horizon.c unit_test.h test_cluster_ $(CLUSTER_VERSION_O) $(CLUSTER_UNDO_HORIZON_O) $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_VERSION_O) $(CLUSTER_UNDO_HORIZON_O) \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-5.22b D2-1/D2-3: test_cluster_undo_gcs — owner-as-master routing layer # (D2-1: cluster_undo_block_lookup_master / _master_is_self) + the pure reader @@ -5141,7 +5206,7 @@ test_cluster_undo_gcs: test_cluster_undo_gcs.c unit_test.h \ $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_VERSION_O) $(CLUSTER_UNDO_RESID_O) $(CLUSTER_UNDO_GCS_O) \ $(CLUSTER_RUNTIME_VIS_POLICY_O) \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-5.22c D3-1/D3-2: test_cluster_undo_verdict — cross-node xid->commit_scn # verdict taxonomy (five-value ClusterUndoVerdictKind) + the two pure mapping @@ -5161,7 +5226,7 @@ test_cluster_undo_verdict: test_cluster_undo_verdict.c unit_test.h \ $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_VERSION_O) $(CLUSTER_UNDO_RESID_O) $(CLUSTER_UNDO_GCS_O) \ $(CLUSTER_RUNTIME_VIS_POLICY_O) \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-7.1 D3-a: test_cluster_mxid_stripe — truth tables for the mxid # stripe pure derivation layer (half-space origin derivation / striped @@ -5175,7 +5240,7 @@ test_cluster_mxid_stripe: test_cluster_mxid_stripe.c unit_test.h \ $(CLUSTER_MXID_STRIPE_O) $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_MXID_STRIPE_O) \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # spec-7.1 D3-b (A1): test_cluster_multixact_served — visibility truth table # for the pure served-verdict combination resolver. Links @@ -5189,7 +5254,7 @@ test_cluster_multixact_served: test_cluster_multixact_served.c unit_test.h \ $(CLUSTER_MULTIXACT_SERVED_O) \ $(CLUSTER_VIS_VERDICT_O) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ # Executable U1-U12 refusal choreography. The test links the # dependency-light sequencer that bufmgr.c consumes; no production source is @@ -5200,7 +5265,7 @@ test_cluster_share_barrier: test_cluster_share_barrier.c unit_test.h \ $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_VERSION_O) $(BUFMGR_BARRIER_O) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ TABLEAM_BARRIER_O = $(top_builddir)/src/backend/access/table/tableam_barrier.o test_cluster_heap_barrier: test_cluster_heap_barrier.c unit_test.h \ @@ -5208,4 +5273,11 @@ test_cluster_heap_barrier: test_cluster_heap_barrier.c unit_test.h \ $(CC) $(CFLAGS) $(CPPFLAGS) $< \ $(CLUSTER_VERSION_O) $(TABLEAM_BARRIER_O) \ $(top_builddir)/src/common/libpgcommon_srv.a \ - $(top_builddir)/src/port/libpgport_srv.a -o $@ + $(CLUSTER_UNIT_PORT_LIBS) -o $@ + +test_cluster_port_runtime: test_cluster_port_runtime.c unit_test.h + $(CC) $(CFLAGS) $(CPPFLAGS) $< $(CLUSTER_UNIT_PORT_LIBS) -o $@ + +# Append after the source prerequisites so recipes using $< still compile +# their test source. Changes to the logging boundary must relink every test. +$(TESTS): cluster_unit_port_stubs.o diff --git a/src/test/cluster_unit/cluster_r4_activation_test_stubs.h b/src/test/cluster_unit/cluster_r4_activation_test_stubs.h index ffdfd6b26db..01d867c9085 100644 --- a/src/test/cluster_unit/cluster_r4_activation_test_stubs.h +++ b/src/test/cluster_unit/cluster_r4_activation_test_stubs.h @@ -41,12 +41,10 @@ char *cluster_shared_data_dir; static bool cluster_r4_activation_test_formation_valid; static int32 cluster_r4_activation_test_membership_node = -1; static uint64 cluster_r4_activation_test_membership_floor; -static ClusterMembershipState cluster_r4_activation_test_membership_state - = CLUSTER_MEMBER_MEMBER; +static ClusterMembershipState cluster_r4_activation_test_membership_state = CLUSTER_MEMBER_MEMBER; static int32 cluster_r4_activation_test_membership_node2 = -1; static uint64 cluster_r4_activation_test_membership_floor2; -static ClusterMembershipState cluster_r4_activation_test_membership_state2 - = CLUSTER_MEMBER_MEMBER; +static ClusterMembershipState cluster_r4_activation_test_membership_state2 = CLUSTER_MEMBER_MEMBER; static uint64 cluster_r4_activation_test_self_incarnation = 1; static uint64 cluster_r4_activation_test_current_epoch; static bool cluster_r4_activation_test_in_quorum = true; @@ -76,19 +74,16 @@ cluster_epoch_get_current(void) } bool -cluster_replacement_episode_is_valid( - const ClusterReplacementEpisode *episode) +cluster_replacement_episode_is_valid(const ClusterReplacementEpisode *episode) { return cluster_r4_activation_test_formation_valid && episode != NULL; } bool -cluster_reconfig_lmon_snapshot_replacement_admitted( - ClusterReplacementEpisode *out_episode, - ClusterReplacementCommitMarkerV3 *out_marker) +cluster_reconfig_lmon_snapshot_replacement_admitted(ClusterReplacementEpisode *out_episode, + ClusterReplacementCommitMarkerV3 *out_marker) { - if (!cluster_r4_activation_test_formation_valid || out_episode == NULL - || out_marker == NULL) + if (!cluster_r4_activation_test_formation_valid || out_episode == NULL || out_marker == NULL) return false; memset(out_episode, 0, sizeof(*out_episode)); @@ -182,10 +177,8 @@ cluster_undo_smgr_root_descriptor_publish( } bool -cluster_reconfig_lmon_snapshot_admitted_membership( - uint64 *out_members_lo, - uint64 *out_members_hi, - uint64 *out_formation_epoch) +cluster_reconfig_lmon_snapshot_admitted_membership(uint64 *out_members_lo, uint64 *out_members_hi, + uint64 *out_formation_epoch) { cluster_r4_activation_test_admitted_snapshot_calls++; if (out_members_lo != NULL) @@ -194,9 +187,8 @@ cluster_reconfig_lmon_snapshot_admitted_membership( *out_members_hi = 0; if (out_formation_epoch != NULL) *out_formation_epoch = 0; - if (!cluster_r4_activation_test_admitted_snapshot_valid - || out_members_lo == NULL || out_members_hi == NULL - || out_formation_epoch == NULL) + if (!cluster_r4_activation_test_admitted_snapshot_valid || out_members_lo == NULL + || out_members_hi == NULL || out_formation_epoch == NULL) return false; *out_members_lo = cluster_r4_activation_test_admitted_members_lo; *out_members_hi = cluster_r4_activation_test_admitted_members_hi; @@ -233,10 +225,9 @@ cluster_lms_shared_state(void) } bool -cluster_lms_r4_drain_request( - ClusterLmsSharedState *state pg_attribute_unused(), - uint64 generation pg_attribute_unused(), - uint64 *worker_incarnation pg_attribute_unused()) +cluster_lms_r4_drain_request(ClusterLmsSharedState *state pg_attribute_unused(), + uint64 generation pg_attribute_unused(), + uint64 *worker_incarnation pg_attribute_unused()) { return false; } @@ -246,9 +237,8 @@ cluster_lms_wakeup(int worker_id pg_attribute_unused()) {} bool -cluster_cr_server_r4_lmon_reclaim_closed( - uint64 worker_incarnation pg_attribute_unused(), - uint64 generation pg_attribute_unused()) +cluster_cr_server_r4_lmon_reclaim_closed(uint64 worker_incarnation pg_attribute_unused(), + uint64 generation pg_attribute_unused()) { return false; } @@ -272,26 +262,23 @@ cluster_gcs_block_r4_requester_count(void) } bool cluster_sf_peer_capability_generation_matches(int32 peer_id, uint32 required_capabilities, - uint32 expected_generation); + uint32 expected_generation); static bool cluster_r4_activation_test_capability_generation_matches; static int32 cluster_r4_activation_test_capability_peer = -1; static uint64 cluster_r4_activation_test_capability_peer_mask; static uint32 cluster_r4_activation_test_capability_required; static uint32 cluster_r4_activation_test_capability_expected_generation; bool -cluster_sf_peer_capability_generation_matches(int32 peer_id, - uint32 required_capabilities, - uint32 expected_generation) +cluster_sf_peer_capability_generation_matches(int32 peer_id, uint32 required_capabilities, + uint32 expected_generation) { return cluster_r4_activation_test_capability_generation_matches && (peer_id == cluster_r4_activation_test_capability_peer || (peer_id >= 0 && peer_id < 64 - && (cluster_r4_activation_test_capability_peer_mask - & (UINT64_C(1) << peer_id)) != 0)) - && required_capabilities - == cluster_r4_activation_test_capability_required - && expected_generation - == cluster_r4_activation_test_capability_expected_generation; + && (cluster_r4_activation_test_capability_peer_mask & (UINT64_C(1) << peer_id)) + != 0)) + && required_capabilities == cluster_r4_activation_test_capability_required + && expected_generation == cluster_r4_activation_test_capability_expected_generation; } static bool cluster_r4_activation_test_capability_word_sample_ok; @@ -299,11 +286,10 @@ static uint32 cluster_r4_activation_test_capability_word; static uint32 cluster_r4_activation_test_capability_generation; static uint32 cluster_r4_activation_test_capability_sample_calls[CLUSTER_MAX_NODES]; static uint32 cluster_r4_activation_test_local_capability_word; -static ClusterICSendResult - cluster_r4_activation_test_send_results[CLUSTER_MAX_NODES]; +static ClusterICSendResult cluster_r4_activation_test_send_results[CLUSTER_MAX_NODES]; static uint32 cluster_r4_activation_test_send_calls[CLUSTER_MAX_NODES]; static uint8 cluster_r4_activation_test_send_payloads[CLUSTER_MAX_NODES] - [CLUSTER_SEMANTIC_ACTIVATION_ACK_WIRE_BYTES]; + [CLUSTER_SEMANTIC_ACTIVATION_ACK_WIRE_BYTES]; static uint32 cluster_r4_activation_test_send_payload_lengths[CLUSTER_MAX_NODES]; static uint8 cluster_r4_activation_test_send_msg_types[CLUSTER_MAX_NODES]; static uint32 cluster_r4_activation_test_close_calls[CLUSTER_MAX_NODES]; @@ -326,8 +312,7 @@ cluster_sf_peer_capability_record_snapshot(int32 peer_id, ClusterSfPeerCap *out) bool cluster_sf_peer_capability_word_sample(int32 peer_id, uint32 required_capabilities, - uint32 *capability_word_out, - uint32 *generation_out) + uint32 *capability_word_out, uint32 *generation_out) { if (capability_word_out != NULL) *capability_word_out = 0; @@ -335,9 +320,8 @@ cluster_sf_peer_capability_word_sample(int32 peer_id, uint32 required_capabiliti *generation_out = 0; if (peer_id >= 0 && peer_id < CLUSTER_MAX_NODES) cluster_r4_activation_test_capability_sample_calls[peer_id]++; - if (!cluster_r4_activation_test_capability_word_sample_ok - || peer_id < 0 || peer_id >= CLUSTER_MAX_NODES - || required_capabilities == 0 + if (!cluster_r4_activation_test_capability_word_sample_ok || peer_id < 0 + || peer_id >= CLUSTER_MAX_NODES || required_capabilities == 0 || (cluster_r4_activation_test_capability_word & required_capabilities) != required_capabilities) return false; @@ -355,18 +339,16 @@ cluster_ic_local_capability_word(void) } ClusterICSendResult -cluster_ic_send_envelope(uint8 msg_type, int32 dest_node_id, - const void *payload, uint32 payload_len) +cluster_ic_send_envelope(uint8 msg_type, int32 dest_node_id, const void *payload, + uint32 payload_len) { - if (dest_node_id < 0 || dest_node_id >= CLUSTER_MAX_NODES - || payload == NULL + if (dest_node_id < 0 || dest_node_id >= CLUSTER_MAX_NODES || payload == NULL || payload_len != CLUSTER_SEMANTIC_ACTIVATION_ACK_WIRE_BYTES) return CLUSTER_IC_SEND_HARD_ERROR; cluster_r4_activation_test_send_calls[dest_node_id]++; cluster_r4_activation_test_send_msg_types[dest_node_id] = msg_type; cluster_r4_activation_test_send_payload_lengths[dest_node_id] = payload_len; - memcpy(cluster_r4_activation_test_send_payloads[dest_node_id], payload, - payload_len); + memcpy(cluster_r4_activation_test_send_payloads[dest_node_id], payload, payload_len); return cluster_r4_activation_test_send_results[dest_node_id]; } diff --git a/src/test/cluster_unit/cluster_resource_x_wire_f076.h b/src/test/cluster_unit/cluster_resource_x_wire_f076.h index 53b43ebd44f..3af3aa3645e 100644 --- a/src/test/cluster_unit/cluster_resource_x_wire_f076.h +++ b/src/test/cluster_unit/cluster_resource_x_wire_f076.h @@ -14,32 +14,12 @@ typedef struct ResourceXWireF076MessageAbi { uint16 alternate_len; } ResourceXWireF076MessageAbi; -static const ResourceXWireF076MessageAbi resource_x_wire_f076_message_abi[] = { - {41, 80, 0}, - {42, 112, 0}, - {43, 96, 0}, - {44, 96, 0}, - {45, 104, 0}, - {46, 128, 0}, - {47, 104, 0}, - {48, 96, 0}, - {49, 96, 104}, - {50, 128, 0}, - {51, 128, 0}, - {52, 104, 112}, - {53, 96, 0}, - {54, 104, 0}, - {55, 96, 0}, - {56, 96, 0}, - {57, 80, 0}, - {58, 112, 0}, - {59, 96, 0}, - {60, 96, 0}, - {61, 96, 0}, - {62, 96, 0}, - {63, 32, 0}, - {64, 32, 0} -}; +static const ResourceXWireF076MessageAbi resource_x_wire_f076_message_abi[] + = { { 41, 80, 0 }, { 42, 112, 0 }, { 43, 96, 0 }, { 44, 96, 0 }, { 45, 104, 0 }, + { 46, 128, 0 }, { 47, 104, 0 }, { 48, 96, 0 }, { 49, 96, 104 }, { 50, 128, 0 }, + { 51, 128, 0 }, { 52, 104, 112 }, { 53, 96, 0 }, { 54, 104, 0 }, { 55, 96, 0 }, + { 56, 96, 0 }, { 57, 80, 0 }, { 58, 112, 0 }, { 59, 96, 0 }, { 60, 96, 0 }, + { 61, 96, 0 }, { 62, 96, 0 }, { 63, 32, 0 }, { 64, 32, 0 } }; enum ResourceXWireF076Layout { F076_BUFFER_TAG_LEN = 20, diff --git a/src/test/cluster_unit/cluster_unit_no_normal_stop.h b/src/test/cluster_unit/cluster_unit_no_normal_stop.h new file mode 100644 index 00000000000..fbe5c1cdb1e --- /dev/null +++ b/src/test/cluster_unit/cluster_unit_no_normal_stop.h @@ -0,0 +1,42 @@ +/*------------------------------------------------------------------------- + * cluster_unit_no_normal_stop.h + * Fail-stop boundaries for fixtures that do not execute normal shutdown. + * + * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2026, pgrac contributors + * + * Author: SqlRush + * + * IDENTIFICATION + * src/test/cluster_unit/cluster_unit_no_normal_stop.h + * + * NOTES + * A new path into shutdown must fail the fixture, never grant authority. + *------------------------------------------------------------------------- + */ +#ifndef CLUSTER_UNIT_NO_NORMAL_STOP_H +#define CLUSTER_UNIT_NO_NORMAL_STOP_H + +#include "cluster/cluster_clean_leave.h" +#include "cluster/cluster_reconfig.h" + +bool +cluster_reconfig_normal_stop_snapshot_admitted_membership( + const ClusterSemanticActivationRecord *open_record pg_attribute_unused(), + const uint8 *root_descriptor pg_attribute_unused(), + uint64 *out_members_lo pg_attribute_unused(), uint64 *out_members_hi pg_attribute_unused(), + uint64 *out_formation_epoch pg_attribute_unused()) +{ + abort(); +} + +bool +cluster_normal_stop_peer_receipt_tail( + const ClusterSemanticActivationRecord *open_record pg_attribute_unused(), + const uint8 root_descriptor[CLUSTER_UNDO_ROOT_DESCRIPTOR_BYTES] pg_attribute_unused(), + int peer pg_attribute_unused(), uint64 admitted_incarnation pg_attribute_unused()) +{ + abort(); +} +#endif diff --git a/src/test/cluster_unit/cluster_unit_port_stubs.c b/src/test/cluster_unit/cluster_unit_port_stubs.c new file mode 100644 index 00000000000..c87136d3fab --- /dev/null +++ b/src/test/cluster_unit/cluster_unit_port_stubs.c @@ -0,0 +1,42 @@ +/*------------------------------------------------------------------------- + * cluster_unit_port_stubs.c + * Standalone error boundary for the real backend portability library. + * + * Author: SqlRush + * Portions Copyright (c) 2026, pgrac contributors + * + * ARM's runtime CRC selector logs its chosen implementation. Tests that + * otherwise need no backend error machinery still link the real selector. + * Existing per-fixture error handlers take precedence over these weak + * defaults. Only the selector's DEBUG1 message is ignored; any unexpected + * severity aborts the test, never becoming a successful operation. + *------------------------------------------------------------------------- + */ +#include "postgres.h" + +bool __attribute__((weak)) +errstart(int elevel, const char *domain pg_attribute_unused()) +{ + if (elevel != DEBUG1) + abort(); + return false; +} + +bool __attribute__((weak)) +errstart_cold(int elevel, const char *domain) +{ + return errstart(elevel, domain); +} + +int __attribute__((weak)) +errmsg_internal(const char *fmt pg_attribute_unused(), ...) +{ + abort(); +} + +void __attribute__((weak)) +errfinish(const char *filename pg_attribute_unused(), int lineno pg_attribute_unused(), + const char *funcname pg_attribute_unused()) +{ + abort(); +} diff --git a/src/test/cluster_unit/data/r11-source-removal-census-v1.json b/src/test/cluster_unit/data/r11-source-removal-census-v1.json index 7bcbbbb99aa..a44eafbe1d0 100644 --- a/src/test/cluster_unit/data/r11-source-removal-census-v1.json +++ b/src/test/cluster_unit/data/r11-source-removal-census-v1.json @@ -15,8 +15,8 @@ }, "current_product_snapshot": { "algorithm": "sha256-canonical-path-blob-v1", - "path_count": 2224, - "sha256": "b257e233d68a37edfbd238891077e28248d64fa8f1743cba1cdaf18a3c2680c2" + "path_count": 2225, + "sha256": "526de2a0572d0c41dccfe05c6c01f1779646383a15a54db61f91e7cb3dde4d4a" }, "gates": { "L1": { @@ -131,7 +131,7 @@ }, { "path": "src/backend/cluster/cluster_lms_outbound.c", - "symbol": "cluster_pcm_lock_resource_x_outbound_intent_probe_exact" + "symbol": "cluster_pcm_lock_resource_x_outbound_work_probe_exact" } ] }, diff --git a/src/test/cluster_unit/data/resource-x-send-c1.tsv b/src/test/cluster_unit/data/resource-x-send-c1.tsv index 51c96b01766..02cb7c31ff9 100644 --- a/src/test/cluster_unit/data/resource-x-send-c1.tsv +++ b/src/test/cluster_unit/data/resource-x-send-c1.tsv @@ -1,12 +1,12 @@ id name root producer_chain consumer_chain observable positive_witness negative_witness forbidden_symbol mutation_edge mutation_witness mutation_result positive_assertion negative_assertion -C1-1 authority-grant-builder cluster_pcm_lock_resource_x_blocked_to_n_exact cluster_pcm_lock_resource_x_blocked_to_n_exact>pcm_resource_x_apply_blocked_holder_locked>pcm_resource_x_commit_grant_locked>pcm_resource_x_build_authority_grant_locked cluster_pcm_lock_resource_x_blocked_to_n_exact>pcm_resource_x_apply_blocked_holder_locked>pcm_resource_x_commit_grant_locked>cluster_pcm_lock_resource_x_intent_arm_exact cluster_pcm_lock_resource_x_grant_intent_snapshot_exact src/test/cluster_unit/test_cluster_pcm_lock.c::test_resource_x_master_remote_proof_is_retained_not_inferred src/test/cluster_unit/test_cluster_pcm_lock.c::test_resource_x_master_local_and_durable_proofs_are_exact_and_closed - pcm_resource_x_commit_grant_locked>pcm_resource_x_build_authority_grant_locked positive RESOURCE_X_APPLY_INVALID RESOURCE_X_MASTER_GRANT_COMMITTED RESOURCE_X_MASTER_WAIT_PROOF -C1-2 block-to-n-producer cluster_pcm_lock_resource_x_assert_bootstrapped_exact cluster_pcm_lock_resource_x_assert_bootstrapped_exact>pcm_resource_x_assert_exact_internal>pcm_resource_x_arm_block_intents_locked cluster_pcm_lock_resource_x_assert_bootstrapped_exact>pcm_resource_x_assert_exact_internal>pcm_resource_x_arm_block_intents_locked>cluster_pcm_lock_resource_x_intent_arm_exact cluster_pcm_lock_resource_x_block_intent_snapshot_exact src/test/cluster_unit/test_cluster_pcm_lock.c::test_resource_x_master_arms_exact_block_to_n_intent_per_holder src/test/cluster_unit/test_cluster_pcm_lock.c::test_resource_x_intent_retains_logical_owner_across_physical_scarcity - pcm_resource_x_arm_block_intents_locked>cluster_pcm_lock_resource_x_intent_arm_exact positive false RESOURCE_X_WIRE_BLOCK_TO_N RESOURCE_X_INTENT_NOT_ADMITTED +C1-1 authority-grant-builder cluster_pcm_lock_resource_x_local_proof_exact cluster_pcm_lock_resource_x_local_proof_exact>pcm_resource_x_commit_grant_locked>pcm_resource_x_build_authority_grant_locked cluster_pcm_lock_resource_x_local_proof_exact>pcm_resource_x_commit_grant_locked>cluster_pcm_lock_resource_x_intent_arm_exact cluster_pcm_lock_resource_x_grant_intent_snapshot_exact src/test/cluster_unit/test_cluster_pcm_lock.c::test_resource_x_master_local_and_durable_proofs_are_exact_and_closed src/test/cluster_unit/test_cluster_pcm_lock.c::test_resource_x_master_remote_proof_is_retained_not_inferred - pcm_resource_x_commit_grant_locked>pcm_resource_x_build_authority_grant_locked positive RESOURCE_X_APPLY_INVALID RESOURCE_X_MASTER_GRANT_COMMITTED RESOURCE_X_APPLY_BAD_STATE +C1-2 block-to-n-producer cluster_pcm_lock_resource_x_assert_bootstrapped_exact cluster_pcm_lock_resource_x_assert_bootstrapped_exact>pcm_resource_x_assert_exact_internal>pcm_resource_x_assert_locked>pcm_resource_x_arm_block_intents_locked cluster_pcm_lock_resource_x_assert_bootstrapped_exact>pcm_resource_x_assert_exact_internal>pcm_resource_x_assert_locked>pcm_resource_x_arm_block_intents_locked>cluster_pcm_lock_resource_x_intent_arm_exact cluster_pcm_lock_resource_x_block_intent_snapshot_exact src/test/cluster_unit/test_cluster_pcm_lock.c::test_resource_x_master_arms_exact_block_to_n_intent_per_holder src/test/cluster_unit/test_cluster_pcm_lock.c::test_resource_x_intent_retains_logical_owner_across_physical_scarcity - pcm_resource_x_arm_block_intents_locked>cluster_pcm_lock_resource_x_intent_arm_exact positive false RESOURCE_X_WIRE_BLOCK_TO_N RESOURCE_X_INTENT_NOT_ADMITTED C1-3 blocker-exact-apply gcs_block_try_resource_x_frame gcs_block_try_resource_x_frame>cluster_resource_x_wire_decode gcs_block_try_resource_x_frame>cluster_pcm_lock_resource_x_blocked_to_n_exact>pcm_resource_x_apply_blocked_holder_locked blocked_holders_bitmap src/test/cluster_unit/test_cluster_pcm_lock.c::test_resource_x_master_remote_proof_is_retained_not_inferred src/test/cluster_unit/test_cluster_pcm_lock.c::test_resource_x_blocked_to_n_exact_clear_rejects_generation_drift - cluster_pcm_lock_resource_x_blocked_to_n_exact>pcm_resource_x_apply_blocked_holder_locked negative RESOURCE_X_APPLY_INVALID RESOURCE_X_MASTER_GRANT_COMMITTED RESOURCE_X_APPLY_STALE C1-4 grant-exact-completion cluster_lms_outbound_drain_send cluster_lms_outbound_drain_send>cluster_pcm_lock_resource_x_outbound_intent_snapshot_exact cluster_lms_outbound_drain_send>cluster_pcm_lock_resource_x_outbound_intent_complete_exact cluster_pcm_lock_resource_x_outbound_intent_snapshot_exact src/test/cluster_unit/test_cluster_lms_outbound.c::test_resource_x_intent_admission_stages_and_completion_clears_owner src/test/cluster_unit/test_cluster_lms_outbound.c::test_resource_x_intent_transport_refusal_rearms_without_ring_copy - cluster_lms_outbound_drain_send>cluster_pcm_lock_resource_x_outbound_intent_complete_exact positive false ut_resource_x_complete_count ut_resource_x_complete_count C1-5 hard-drift-rebuild cluster_lms_outbound_drain_send cluster_lms_outbound_drain_send>cluster_pcm_lock_resource_x_outbound_intent_hard_rearm_exact>cluster_pcm_lock_resource_x_intent_hard_rearm_exact cluster_lms_outbound_drain_send>cluster_pcm_lock_resource_x_outbound_intent_hard_rearm_exact>pcm_resource_x_intent_mark_dirty resource_x_intent_arm_generation src/test/cluster_unit/test_cluster_lms_outbound.c::test_resource_x_intent_capability_drift_rearms_before_send src/test/cluster_unit/test_cluster_lms_outbound.c::test_resource_x_intent_transport_refusal_rearms_without_ring_copy - cluster_lms_outbound_drain_send>cluster_pcm_lock_resource_x_outbound_intent_hard_rearm_exact positive RESOURCE_X_INTENT_STALE ut_resource_x_rearm_count ut_resource_x_rearm_count C1-6 not-admitted-preserves-owner cluster_lms_outbound_resource_x_intent_pump cluster_lms_outbound_resource_x_intent_pump>cluster_pcm_lock_resource_x_outbound_intent_not_admitted_exact>cluster_pcm_lock_resource_x_intent_not_admitted_exact cluster_lms_outbound_resource_x_intent_pump>cluster_pcm_lock_resource_x_outbound_intent_not_admitted_exact>pcm_resource_x_intent_mark_dirty resource_x_intent_arm_generation src/test/cluster_unit/test_cluster_lms_outbound.c::test_resource_x_intent_pump_not_admitted_preserves_owner src/test/cluster_unit/test_cluster_lms_outbound.c::test_resource_x_intent_admission_stages_and_completion_clears_owner - cluster_lms_outbound_resource_x_intent_pump>cluster_pcm_lock_resource_x_outbound_intent_not_admitted_exact positive RESOURCE_X_INTENT_STALE ut_resource_x_owner_slot.state ut_resource_x_complete_count C1-7 physical-deadline-lifecycle cluster_lms_outbound_drain_send cluster_lms_outbound_drain_send>cluster_pcm_lock_resource_x_outbound_intent_snapshot_exact cluster_lms_outbound_drain_send>cluster_pcm_lock_resource_x_outbound_intent_hard_rearm_exact>pcm_resource_x_intent_mark_dirty deadline_us src/test/cluster_unit/test_cluster_lms_outbound.c::test_resource_x_intent_physical_deadline_rearms_before_send src/test/cluster_unit/test_cluster_lms_outbound.c::test_resource_x_intent_capability_drift_rearms_before_send - cluster_lms_outbound_drain_send>cluster_pcm_lock_resource_x_outbound_intent_hard_rearm_exact positive RESOURCE_X_INTENT_STALE ut_resource_x_rearm_count ut_resource_x_rearm_count -C1-8 type17-holder-ingress cluster_gcs_handle_block_invalidate_envelope cluster_gcs_handle_block_invalidate_envelope>gcs_block_try_resource_x_frame>gcs_block_resource_x_type17_ingress>gcs_block_pcm_x_resource_x_source_block_to_n>gcs_block_pcm_x_resource_x_build_source_frames cluster_gcs_handle_block_invalidate_envelope>gcs_block_try_resource_x_frame>gcs_block_resource_x_type17_ingress>gcs_block_pcm_x_resource_x_source_block_to_n>cluster_pcm_lock_resource_x_holder_pair_publish_exact>pcm_resource_x_rearm_holder_source_locked holder_status_intent src/test/cluster_unit/test_cluster_pcm_lock.c::test_resource_x_x_source_defers_self_master_grd_transition_to_ingress src/test/cluster_unit/test_cluster_pcm_lock.c::test_resource_x_holder_retains_status_before_s_to_n - cluster_pcm_lock_resource_x_holder_pair_publish_exact>pcm_resource_x_rearm_holder_source_locked positive false RESOURCE_X_WIRE_IMAGE_ENVELOPE RESOURCE_X_WIRE_BLOCKED_TO_N +C1-8 type17-holder-ingress cluster_gcs_handle_block_invalidate_envelope cluster_gcs_handle_block_invalidate_envelope>gcs_block_try_resource_x_frame>gcs_block_resource_x_type17_ingress>gcs_block_pcm_x_resource_x_source_block_to_n>gcs_block_pcm_x_resource_x_build_source_frames cluster_gcs_handle_block_invalidate_envelope>gcs_block_try_resource_x_frame>gcs_block_resource_x_type17_ingress>gcs_block_pcm_x_resource_x_source_block_to_n>cluster_pcm_lock_resource_x_holder_pair_publish_exact>pcm_resource_x_holder_pair_publish_internal>pcm_resource_x_rearm_holder_source_locked holder_status_intent src/test/cluster_unit/test_cluster_pcm_lock.c::test_resource_x_x_source_defers_self_master_grd_transition_to_ingress src/test/cluster_unit/test_cluster_pcm_lock.c::test_resource_x_holder_retains_status_before_s_to_n - pcm_resource_x_holder_pair_publish_internal>pcm_resource_x_rearm_holder_source_locked positive false RESOURCE_X_WIRE_IMAGE_ENVELOPE RESOURCE_X_WIRE_BLOCKED_TO_N C1-9 type18-master-ingress cluster_gcs_handle_block_invalidate_ack_envelope cluster_gcs_handle_block_invalidate_ack_envelope>gcs_block_try_resource_x_frame>cluster_resource_x_wire_decode cluster_gcs_handle_block_invalidate_ack_envelope>gcs_block_try_resource_x_frame>cluster_pcm_lock_resource_x_blocked_to_n_exact>pcm_resource_x_apply_blocked_holder_locked>pcm_resource_x_commit_grant_locked blocked_holders_bitmap src/test/cluster_unit/test_cluster_pcm_lock.c::test_resource_x_type18_wire_decode_drives_master_exact_apply src/test/cluster_unit/test_cluster_pcm_lock.c::test_resource_x_master_remote_proof_is_retained_not_inferred - pcm_resource_x_apply_blocked_holder_locked>pcm_resource_x_commit_grant_locked positive RESOURCE_X_APPLY_INVALID RESOURCE_X_MASTER_GRANT_COMMITTED RESOURCE_X_APPLY_BAD_STATE -C1-10 bound-only-wrapper-absent cluster_lms_outbound_resource_x_intent_pump cluster_lms_outbound_resource_x_intent_pump>cluster_pcm_lock_resource_x_outbound_intent_probe_exact>pcm_resource_x_outbound_owner_at cluster_lms_outbound_resource_x_intent_pump>cluster_pcm_lock_resource_x_outbound_intent_probe_exact>pcm_resource_x_outbound_owner_valid resource_x_intent_next_owner_index src/test/cluster_unit/test_cluster_pcm_lock.c::test_resource_x_intent_sparse_probe_rediscovers_exact_rearm src/test/cluster_unit/test_cluster_lms_outbound.c::test_resource_x_intent_pump_is_bounded_to_sixteen_four_probes cluster_pcm_lock_resource_x_grant_intent_probe_exact cluster_lms_outbound_resource_x_intent_pump>cluster_pcm_lock_resource_x_outbound_intent_probe_exact negative RESOURCE_X_INTENT_PROBE_IDLE RESOURCE_X_INTENT_PROBE_COMPLETE ut_resource_x_probe_call_count -C1-11 combined-claim-dirty-pass cluster_lms_outbound_resource_x_intent_pump cluster_lms_outbound_resource_x_intent_pump>cluster_pcm_lock_resource_x_outbound_intent_probe_exact>pcm_resource_x_outbound_owner_at cluster_lms_outbound_resource_x_intent_pump>cluster_pcm_lock_resource_x_outbound_intent_probe_exact>pcm_resource_x_outbound_owner_valid resource_x_intent_completed_generation src/test/cluster_unit/test_cluster_pcm_lock.c::test_resource_x_intent_sparse_probe_rediscovers_exact_rearm src/test/cluster_unit/test_cluster_pcm_lock.c::test_resource_x_master_arms_exact_block_to_n_intent_per_holder - cluster_pcm_lock_resource_x_outbound_intent_probe_exact>pcm_resource_x_outbound_owner_valid positive false RESOURCE_X_INTENT_PROBE_FOUND RESOURCE_X_INTENT_PROBE_FOUND +C1-10 bound-only-wrapper-absent cluster_lms_outbound_resource_x_intent_pump cluster_lms_outbound_resource_x_intent_pump>cluster_pcm_lock_resource_x_outbound_work_probe_exact>pcm_resource_x_outbound_owner_at cluster_lms_outbound_resource_x_intent_pump>cluster_pcm_lock_resource_x_outbound_work_probe_exact>pcm_resource_x_outbound_owner_valid resource_x_intent_next_owner_index src/test/cluster_unit/test_cluster_pcm_lock.c::test_resource_x_intent_sparse_probe_rediscovers_exact_rearm src/test/cluster_unit/test_cluster_lms_outbound.c::test_resource_x_intent_pump_is_bounded_to_sixteen_four_probes cluster_pcm_lock_resource_x_grant_intent_probe_exact cluster_lms_outbound_resource_x_intent_pump>cluster_pcm_lock_resource_x_outbound_work_probe_exact negative RESOURCE_X_INTENT_PROBE_IDLE RESOURCE_X_INTENT_PROBE_COMPLETE ut_resource_x_probe_call_count +C1-11 combined-claim-dirty-pass cluster_lms_outbound_resource_x_intent_pump cluster_lms_outbound_resource_x_intent_pump>cluster_pcm_lock_resource_x_outbound_work_probe_exact>pcm_resource_x_outbound_owner_at cluster_lms_outbound_resource_x_intent_pump>cluster_pcm_lock_resource_x_outbound_work_probe_exact>pcm_resource_x_outbound_owner_valid resource_x_intent_completed_generation src/test/cluster_unit/test_cluster_pcm_lock.c::test_resource_x_intent_sparse_probe_rediscovers_exact_rearm src/test/cluster_unit/test_cluster_pcm_lock.c::test_resource_x_master_arms_exact_block_to_n_intent_per_holder - cluster_pcm_lock_resource_x_outbound_work_probe_exact>pcm_resource_x_outbound_owner_valid positive false RESOURCE_X_INTENT_PROBE_FOUND RESOURCE_X_INTENT_PROBE_FOUND diff --git a/src/test/cluster_unit/data/send-c1-9-plus-2.json b/src/test/cluster_unit/data/send-c1-9-plus-2.json index 951d9055ce9..10106af85e7 100644 --- a/src/test/cluster_unit/data/send-c1-9-plus-2.json +++ b/src/test/cluster_unit/data/send-c1-9-plus-2.json @@ -1 +1 @@ -{"evidence_sha256":"cba9f8c71d372dff1ab01b9714c84edd5caf07bee92885e736b9d170f0c7e7f2","gate":"SEND-C1-9+2","manifest_sha256":"9497504705fc5abacadf68c90079898793a63a381e42ad9481732c5cf6a1042f","row_count":11,"rows":[{"consumer_chain":["cluster_pcm_lock_resource_x_blocked_to_n_exact","pcm_resource_x_apply_blocked_holder_locked","pcm_resource_x_commit_grant_locked","cluster_pcm_lock_resource_x_intent_arm_exact"],"evidence_sha256":"d3dd849f2a62920f46b797ad766e0ab4d663731be87e4c2e8d03181687ec169a","forbidden_symbol":null,"id":"C1-1","mutation_edge":["pcm_resource_x_commit_grant_locked","pcm_resource_x_build_authority_grant_locked"],"mutation_result":"RESOURCE_X_APPLY_INVALID","mutation_sha256":"bd4f7bdf748c07fda686efbfa78874d8c27fbdc93be4b1ebc367879c51b58206","mutation_witness":"positive","name":"authority-grant-builder","negative_assertion":"RESOURCE_X_MASTER_WAIT_PROOF","negative_witness":"src/test/cluster_unit/test_cluster_pcm_lock.c::test_resource_x_master_local_and_durable_proofs_are_exact_and_closed","observable":"cluster_pcm_lock_resource_x_grant_intent_snapshot_exact","positive_assertion":"RESOURCE_X_MASTER_GRANT_COMMITTED","positive_witness":"src/test/cluster_unit/test_cluster_pcm_lock.c::test_resource_x_master_remote_proof_is_retained_not_inferred","producer_chain":["cluster_pcm_lock_resource_x_blocked_to_n_exact","pcm_resource_x_apply_blocked_holder_locked","pcm_resource_x_commit_grant_locked","pcm_resource_x_build_authority_grant_locked"],"root":"cluster_pcm_lock_resource_x_blocked_to_n_exact"},{"consumer_chain":["cluster_pcm_lock_resource_x_assert_bootstrapped_exact","pcm_resource_x_assert_exact_internal","pcm_resource_x_arm_block_intents_locked","cluster_pcm_lock_resource_x_intent_arm_exact"],"evidence_sha256":"8fee90d2cacd874b4139fa7c1f2d89350670b618d6fc618737398bad64a98c79","forbidden_symbol":null,"id":"C1-2","mutation_edge":["pcm_resource_x_arm_block_intents_locked","cluster_pcm_lock_resource_x_intent_arm_exact"],"mutation_result":"false","mutation_sha256":"f2496c4da9611a2fe5d1e6042663ba9bc9be0de61ddfa856609845c189288a13","mutation_witness":"positive","name":"block-to-n-producer","negative_assertion":"RESOURCE_X_INTENT_NOT_ADMITTED","negative_witness":"src/test/cluster_unit/test_cluster_pcm_lock.c::test_resource_x_intent_retains_logical_owner_across_physical_scarcity","observable":"cluster_pcm_lock_resource_x_block_intent_snapshot_exact","positive_assertion":"RESOURCE_X_WIRE_BLOCK_TO_N","positive_witness":"src/test/cluster_unit/test_cluster_pcm_lock.c::test_resource_x_master_arms_exact_block_to_n_intent_per_holder","producer_chain":["cluster_pcm_lock_resource_x_assert_bootstrapped_exact","pcm_resource_x_assert_exact_internal","pcm_resource_x_arm_block_intents_locked"],"root":"cluster_pcm_lock_resource_x_assert_bootstrapped_exact"},{"consumer_chain":["gcs_block_try_resource_x_frame","cluster_pcm_lock_resource_x_blocked_to_n_exact","pcm_resource_x_apply_blocked_holder_locked"],"evidence_sha256":"66fc2d601dacd397b631edabc9c44a9289d27750cbaf660cdaf93cd807092169","forbidden_symbol":null,"id":"C1-3","mutation_edge":["cluster_pcm_lock_resource_x_blocked_to_n_exact","pcm_resource_x_apply_blocked_holder_locked"],"mutation_result":"RESOURCE_X_APPLY_INVALID","mutation_sha256":"9701a578021b39364b89c0e2934b5f9ccf0d0f261653cadcca2c0930f200bd46","mutation_witness":"negative","name":"blocker-exact-apply","negative_assertion":"RESOURCE_X_APPLY_STALE","negative_witness":"src/test/cluster_unit/test_cluster_pcm_lock.c::test_resource_x_blocked_to_n_exact_clear_rejects_generation_drift","observable":"blocked_holders_bitmap","positive_assertion":"RESOURCE_X_MASTER_GRANT_COMMITTED","positive_witness":"src/test/cluster_unit/test_cluster_pcm_lock.c::test_resource_x_master_remote_proof_is_retained_not_inferred","producer_chain":["gcs_block_try_resource_x_frame","cluster_resource_x_wire_decode"],"root":"gcs_block_try_resource_x_frame"},{"consumer_chain":["cluster_lms_outbound_drain_send","cluster_pcm_lock_resource_x_outbound_intent_complete_exact"],"evidence_sha256":"3e90b5ed06936dd7e9fa9976653cfd09025a8e05546af520e0ae0130dbd5a6c2","forbidden_symbol":null,"id":"C1-4","mutation_edge":["cluster_lms_outbound_drain_send","cluster_pcm_lock_resource_x_outbound_intent_complete_exact"],"mutation_result":"false","mutation_sha256":"34c83ebab9a30149e954f0b4aac726e0d102f7da69323069a795dd3d93274c4c","mutation_witness":"positive","name":"grant-exact-completion","negative_assertion":"ut_resource_x_complete_count","negative_witness":"src/test/cluster_unit/test_cluster_lms_outbound.c::test_resource_x_intent_transport_refusal_rearms_without_ring_copy","observable":"cluster_pcm_lock_resource_x_outbound_intent_snapshot_exact","positive_assertion":"ut_resource_x_complete_count","positive_witness":"src/test/cluster_unit/test_cluster_lms_outbound.c::test_resource_x_intent_admission_stages_and_completion_clears_owner","producer_chain":["cluster_lms_outbound_drain_send","cluster_pcm_lock_resource_x_outbound_intent_snapshot_exact"],"root":"cluster_lms_outbound_drain_send"},{"consumer_chain":["cluster_lms_outbound_drain_send","cluster_pcm_lock_resource_x_outbound_intent_hard_rearm_exact","pcm_resource_x_intent_mark_dirty"],"evidence_sha256":"4e67dcf093309b720e2f43607ade6651a5534dace316a2e499f2e13cd6c9cf1e","forbidden_symbol":null,"id":"C1-5","mutation_edge":["cluster_lms_outbound_drain_send","cluster_pcm_lock_resource_x_outbound_intent_hard_rearm_exact"],"mutation_result":"RESOURCE_X_INTENT_STALE","mutation_sha256":"221faec45fc2d110593f47f0947fcf31fc2f0f9605aa76559f1656e5781df18b","mutation_witness":"positive","name":"hard-drift-rebuild","negative_assertion":"ut_resource_x_rearm_count","negative_witness":"src/test/cluster_unit/test_cluster_lms_outbound.c::test_resource_x_intent_transport_refusal_rearms_without_ring_copy","observable":"resource_x_intent_arm_generation","positive_assertion":"ut_resource_x_rearm_count","positive_witness":"src/test/cluster_unit/test_cluster_lms_outbound.c::test_resource_x_intent_capability_drift_rearms_before_send","producer_chain":["cluster_lms_outbound_drain_send","cluster_pcm_lock_resource_x_outbound_intent_hard_rearm_exact","cluster_pcm_lock_resource_x_intent_hard_rearm_exact"],"root":"cluster_lms_outbound_drain_send"},{"consumer_chain":["cluster_lms_outbound_resource_x_intent_pump","cluster_pcm_lock_resource_x_outbound_intent_not_admitted_exact","pcm_resource_x_intent_mark_dirty"],"evidence_sha256":"ce9d88f16b9f588535703c81385d7b03fccca772ea0b23cdfa85b468b47967d6","forbidden_symbol":null,"id":"C1-6","mutation_edge":["cluster_lms_outbound_resource_x_intent_pump","cluster_pcm_lock_resource_x_outbound_intent_not_admitted_exact"],"mutation_result":"RESOURCE_X_INTENT_STALE","mutation_sha256":"169591458d3d8b7aa48b3b4405bace85641deee15a702566e09addcac8c46e50","mutation_witness":"positive","name":"not-admitted-preserves-owner","negative_assertion":"ut_resource_x_complete_count","negative_witness":"src/test/cluster_unit/test_cluster_lms_outbound.c::test_resource_x_intent_admission_stages_and_completion_clears_owner","observable":"resource_x_intent_arm_generation","positive_assertion":"ut_resource_x_owner_slot.state","positive_witness":"src/test/cluster_unit/test_cluster_lms_outbound.c::test_resource_x_intent_pump_not_admitted_preserves_owner","producer_chain":["cluster_lms_outbound_resource_x_intent_pump","cluster_pcm_lock_resource_x_outbound_intent_not_admitted_exact","cluster_pcm_lock_resource_x_intent_not_admitted_exact"],"root":"cluster_lms_outbound_resource_x_intent_pump"},{"consumer_chain":["cluster_lms_outbound_drain_send","cluster_pcm_lock_resource_x_outbound_intent_hard_rearm_exact","pcm_resource_x_intent_mark_dirty"],"evidence_sha256":"b3dbd8f0dbfdda926be41ee44784488e33820d5af378e77c138c3304e7996999","forbidden_symbol":null,"id":"C1-7","mutation_edge":["cluster_lms_outbound_drain_send","cluster_pcm_lock_resource_x_outbound_intent_hard_rearm_exact"],"mutation_result":"RESOURCE_X_INTENT_STALE","mutation_sha256":"221faec45fc2d110593f47f0947fcf31fc2f0f9605aa76559f1656e5781df18b","mutation_witness":"positive","name":"physical-deadline-lifecycle","negative_assertion":"ut_resource_x_rearm_count","negative_witness":"src/test/cluster_unit/test_cluster_lms_outbound.c::test_resource_x_intent_capability_drift_rearms_before_send","observable":"deadline_us","positive_assertion":"ut_resource_x_rearm_count","positive_witness":"src/test/cluster_unit/test_cluster_lms_outbound.c::test_resource_x_intent_physical_deadline_rearms_before_send","producer_chain":["cluster_lms_outbound_drain_send","cluster_pcm_lock_resource_x_outbound_intent_snapshot_exact"],"root":"cluster_lms_outbound_drain_send"},{"consumer_chain":["cluster_gcs_handle_block_invalidate_envelope","gcs_block_try_resource_x_frame","gcs_block_resource_x_type17_ingress","gcs_block_pcm_x_resource_x_source_block_to_n","cluster_pcm_lock_resource_x_holder_pair_publish_exact","pcm_resource_x_rearm_holder_source_locked"],"evidence_sha256":"7a7ea23988864f4662db0ff3fa8d0c777277cf1bb4a002dd3fe87f08c094c23e","forbidden_symbol":null,"id":"C1-8","mutation_edge":["cluster_pcm_lock_resource_x_holder_pair_publish_exact","pcm_resource_x_rearm_holder_source_locked"],"mutation_result":"false","mutation_sha256":"b0d2d13a0c30f489884256952f555165a292bede4a5bbea3922d67271eecbe4d","mutation_witness":"positive","name":"type17-holder-ingress","negative_assertion":"RESOURCE_X_WIRE_BLOCKED_TO_N","negative_witness":"src/test/cluster_unit/test_cluster_pcm_lock.c::test_resource_x_holder_retains_status_before_s_to_n","observable":"holder_status_intent","positive_assertion":"RESOURCE_X_WIRE_IMAGE_ENVELOPE","positive_witness":"src/test/cluster_unit/test_cluster_pcm_lock.c::test_resource_x_x_source_defers_self_master_grd_transition_to_ingress","producer_chain":["cluster_gcs_handle_block_invalidate_envelope","gcs_block_try_resource_x_frame","gcs_block_resource_x_type17_ingress","gcs_block_pcm_x_resource_x_source_block_to_n","gcs_block_pcm_x_resource_x_build_source_frames"],"root":"cluster_gcs_handle_block_invalidate_envelope"},{"consumer_chain":["cluster_gcs_handle_block_invalidate_ack_envelope","gcs_block_try_resource_x_frame","cluster_pcm_lock_resource_x_blocked_to_n_exact","pcm_resource_x_apply_blocked_holder_locked","pcm_resource_x_commit_grant_locked"],"evidence_sha256":"0b929f4a474eef61a124769d90164f125b2c8b15f0e65d900a5d76c27d633452","forbidden_symbol":null,"id":"C1-9","mutation_edge":["pcm_resource_x_apply_blocked_holder_locked","pcm_resource_x_commit_grant_locked"],"mutation_result":"RESOURCE_X_APPLY_INVALID","mutation_sha256":"d9371a145653bf6dfcef0e07851ee42fbf6709d75319f5f539291c206fbd6092","mutation_witness":"positive","name":"type18-master-ingress","negative_assertion":"RESOURCE_X_APPLY_BAD_STATE","negative_witness":"src/test/cluster_unit/test_cluster_pcm_lock.c::test_resource_x_master_remote_proof_is_retained_not_inferred","observable":"blocked_holders_bitmap","positive_assertion":"RESOURCE_X_MASTER_GRANT_COMMITTED","positive_witness":"src/test/cluster_unit/test_cluster_pcm_lock.c::test_resource_x_type18_wire_decode_drives_master_exact_apply","producer_chain":["cluster_gcs_handle_block_invalidate_ack_envelope","gcs_block_try_resource_x_frame","cluster_resource_x_wire_decode"],"root":"cluster_gcs_handle_block_invalidate_ack_envelope"},{"consumer_chain":["cluster_lms_outbound_resource_x_intent_pump","cluster_pcm_lock_resource_x_outbound_intent_probe_exact","pcm_resource_x_outbound_owner_valid"],"evidence_sha256":"f090cfcb65ff52906b14b7c0c233aea8f9da9a5be549dc5247535e23de2fc95b","forbidden_symbol":"cluster_pcm_lock_resource_x_grant_intent_probe_exact","id":"C1-10","mutation_edge":["cluster_lms_outbound_resource_x_intent_pump","cluster_pcm_lock_resource_x_outbound_intent_probe_exact"],"mutation_result":"RESOURCE_X_INTENT_PROBE_IDLE","mutation_sha256":"04e151bd3b68a04cb8a7028725b69fbba899ac67b886785813703ce6d8c6a80f","mutation_witness":"negative","name":"bound-only-wrapper-absent","negative_assertion":"ut_resource_x_probe_call_count","negative_witness":"src/test/cluster_unit/test_cluster_lms_outbound.c::test_resource_x_intent_pump_is_bounded_to_sixteen_four_probes","observable":"resource_x_intent_next_owner_index","positive_assertion":"RESOURCE_X_INTENT_PROBE_COMPLETE","positive_witness":"src/test/cluster_unit/test_cluster_pcm_lock.c::test_resource_x_intent_sparse_probe_rediscovers_exact_rearm","producer_chain":["cluster_lms_outbound_resource_x_intent_pump","cluster_pcm_lock_resource_x_outbound_intent_probe_exact","pcm_resource_x_outbound_owner_at"],"root":"cluster_lms_outbound_resource_x_intent_pump"},{"consumer_chain":["cluster_lms_outbound_resource_x_intent_pump","cluster_pcm_lock_resource_x_outbound_intent_probe_exact","pcm_resource_x_outbound_owner_valid"],"evidence_sha256":"942c7823073d7b3ab374af00795d6d161076f3299a7ab1885ba24e0f48c93ff5","forbidden_symbol":null,"id":"C1-11","mutation_edge":["cluster_pcm_lock_resource_x_outbound_intent_probe_exact","pcm_resource_x_outbound_owner_valid"],"mutation_result":"false","mutation_sha256":"751bb301391b0b0fe310b2e3cebcdd2255081da982e6a88a9b17fb02467e5e23","mutation_witness":"positive","name":"combined-claim-dirty-pass","negative_assertion":"RESOURCE_X_INTENT_PROBE_FOUND","negative_witness":"src/test/cluster_unit/test_cluster_pcm_lock.c::test_resource_x_master_arms_exact_block_to_n_intent_per_holder","observable":"resource_x_intent_completed_generation","positive_assertion":"RESOURCE_X_INTENT_PROBE_FOUND","positive_witness":"src/test/cluster_unit/test_cluster_pcm_lock.c::test_resource_x_intent_sparse_probe_rediscovers_exact_rearm","producer_chain":["cluster_lms_outbound_resource_x_intent_pump","cluster_pcm_lock_resource_x_outbound_intent_probe_exact","pcm_resource_x_outbound_owner_at"],"root":"cluster_lms_outbound_resource_x_intent_pump"}],"schema":"pgrac-resource-x-send-c1-v1"} +{"evidence_sha256":"093394c8455c7259a259a4170964fa549da96e619086b5c404c45e254f3ddc5a","gate":"SEND-C1-9+2","manifest_sha256":"8de76c5e2253c75d2a0a3deb3fe4d3a9b896174a0ab502d8a9dd8571ad59eeef","row_count":11,"rows":[{"consumer_chain":["cluster_pcm_lock_resource_x_local_proof_exact","pcm_resource_x_commit_grant_locked","cluster_pcm_lock_resource_x_intent_arm_exact"],"evidence_sha256":"5cbe7ddeee8f41b6e1668ffd1777766ccc8c191ff5e35ecc958207c690be730b","forbidden_symbol":null,"id":"C1-1","mutation_edge":["pcm_resource_x_commit_grant_locked","pcm_resource_x_build_authority_grant_locked"],"mutation_result":"RESOURCE_X_APPLY_INVALID","mutation_sha256":"eda7f7c6e0bf3a1430e48733d90315396802712374e9b0f6369340dbef477bb4","mutation_witness":"positive","name":"authority-grant-builder","negative_assertion":"RESOURCE_X_APPLY_BAD_STATE","negative_witness":"src/test/cluster_unit/test_cluster_pcm_lock.c::test_resource_x_master_remote_proof_is_retained_not_inferred","observable":"cluster_pcm_lock_resource_x_grant_intent_snapshot_exact","positive_assertion":"RESOURCE_X_MASTER_GRANT_COMMITTED","positive_witness":"src/test/cluster_unit/test_cluster_pcm_lock.c::test_resource_x_master_local_and_durable_proofs_are_exact_and_closed","producer_chain":["cluster_pcm_lock_resource_x_local_proof_exact","pcm_resource_x_commit_grant_locked","pcm_resource_x_build_authority_grant_locked"],"root":"cluster_pcm_lock_resource_x_local_proof_exact"},{"consumer_chain":["cluster_pcm_lock_resource_x_assert_bootstrapped_exact","pcm_resource_x_assert_exact_internal","pcm_resource_x_assert_locked","pcm_resource_x_arm_block_intents_locked","cluster_pcm_lock_resource_x_intent_arm_exact"],"evidence_sha256":"a6e3537e6f9131e0f84a0c5610f88141e7ed2f7c1212551387341c30bb3578e5","forbidden_symbol":null,"id":"C1-2","mutation_edge":["pcm_resource_x_arm_block_intents_locked","cluster_pcm_lock_resource_x_intent_arm_exact"],"mutation_result":"false","mutation_sha256":"93b58fb8f49250fcd2d247d7c98419b87e9d99c825c9be447f7cbfe554597203","mutation_witness":"positive","name":"block-to-n-producer","negative_assertion":"RESOURCE_X_INTENT_NOT_ADMITTED","negative_witness":"src/test/cluster_unit/test_cluster_pcm_lock.c::test_resource_x_intent_retains_logical_owner_across_physical_scarcity","observable":"cluster_pcm_lock_resource_x_block_intent_snapshot_exact","positive_assertion":"RESOURCE_X_WIRE_BLOCK_TO_N","positive_witness":"src/test/cluster_unit/test_cluster_pcm_lock.c::test_resource_x_master_arms_exact_block_to_n_intent_per_holder","producer_chain":["cluster_pcm_lock_resource_x_assert_bootstrapped_exact","pcm_resource_x_assert_exact_internal","pcm_resource_x_assert_locked","pcm_resource_x_arm_block_intents_locked"],"root":"cluster_pcm_lock_resource_x_assert_bootstrapped_exact"},{"consumer_chain":["gcs_block_try_resource_x_frame","cluster_pcm_lock_resource_x_blocked_to_n_exact","pcm_resource_x_apply_blocked_holder_locked"],"evidence_sha256":"7d3df9fee37248308702dfd98f7a752200e716a258eaa44e60a863676fa4ca23","forbidden_symbol":null,"id":"C1-3","mutation_edge":["cluster_pcm_lock_resource_x_blocked_to_n_exact","pcm_resource_x_apply_blocked_holder_locked"],"mutation_result":"RESOURCE_X_APPLY_INVALID","mutation_sha256":"e47458cae910960578963a7581494e9adfd67f866f99a0e88ce87509e6907dec","mutation_witness":"negative","name":"blocker-exact-apply","negative_assertion":"RESOURCE_X_APPLY_STALE","negative_witness":"src/test/cluster_unit/test_cluster_pcm_lock.c::test_resource_x_blocked_to_n_exact_clear_rejects_generation_drift","observable":"blocked_holders_bitmap","positive_assertion":"RESOURCE_X_MASTER_GRANT_COMMITTED","positive_witness":"src/test/cluster_unit/test_cluster_pcm_lock.c::test_resource_x_master_remote_proof_is_retained_not_inferred","producer_chain":["gcs_block_try_resource_x_frame","cluster_resource_x_wire_decode"],"root":"gcs_block_try_resource_x_frame"},{"consumer_chain":["cluster_lms_outbound_drain_send","cluster_pcm_lock_resource_x_outbound_intent_complete_exact"],"evidence_sha256":"57444858c63a4ce403da29431dd85f9f2ba2ce4037df122b126edad0839a1f13","forbidden_symbol":null,"id":"C1-4","mutation_edge":["cluster_lms_outbound_drain_send","cluster_pcm_lock_resource_x_outbound_intent_complete_exact"],"mutation_result":"false","mutation_sha256":"8b88b2477d2b5133c74f56da011853030843db8037684e30231833ebe9953bfb","mutation_witness":"positive","name":"grant-exact-completion","negative_assertion":"ut_resource_x_complete_count","negative_witness":"src/test/cluster_unit/test_cluster_lms_outbound.c::test_resource_x_intent_transport_refusal_rearms_without_ring_copy","observable":"cluster_pcm_lock_resource_x_outbound_intent_snapshot_exact","positive_assertion":"ut_resource_x_complete_count","positive_witness":"src/test/cluster_unit/test_cluster_lms_outbound.c::test_resource_x_intent_admission_stages_and_completion_clears_owner","producer_chain":["cluster_lms_outbound_drain_send","cluster_pcm_lock_resource_x_outbound_intent_snapshot_exact"],"root":"cluster_lms_outbound_drain_send"},{"consumer_chain":["cluster_lms_outbound_drain_send","cluster_pcm_lock_resource_x_outbound_intent_hard_rearm_exact","pcm_resource_x_intent_mark_dirty"],"evidence_sha256":"a7095440662a4d1796a42925a76377262fc2ae7c9888588376098d45623002e4","forbidden_symbol":null,"id":"C1-5","mutation_edge":["cluster_lms_outbound_drain_send","cluster_pcm_lock_resource_x_outbound_intent_hard_rearm_exact"],"mutation_result":"RESOURCE_X_INTENT_STALE","mutation_sha256":"b369071fe6f81eb4ef4832528c6effe7800c5b7c5f8db2b14a37f6d66c8ae642","mutation_witness":"positive","name":"hard-drift-rebuild","negative_assertion":"ut_resource_x_rearm_count","negative_witness":"src/test/cluster_unit/test_cluster_lms_outbound.c::test_resource_x_intent_transport_refusal_rearms_without_ring_copy","observable":"resource_x_intent_arm_generation","positive_assertion":"ut_resource_x_rearm_count","positive_witness":"src/test/cluster_unit/test_cluster_lms_outbound.c::test_resource_x_intent_capability_drift_rearms_before_send","producer_chain":["cluster_lms_outbound_drain_send","cluster_pcm_lock_resource_x_outbound_intent_hard_rearm_exact","cluster_pcm_lock_resource_x_intent_hard_rearm_exact"],"root":"cluster_lms_outbound_drain_send"},{"consumer_chain":["cluster_lms_outbound_resource_x_intent_pump","cluster_pcm_lock_resource_x_outbound_intent_not_admitted_exact","pcm_resource_x_intent_mark_dirty"],"evidence_sha256":"5a5e9cfd8f502a4769a5259e26965b4735fe5dd108ce6091e3a5770cd4deb5c5","forbidden_symbol":null,"id":"C1-6","mutation_edge":["cluster_lms_outbound_resource_x_intent_pump","cluster_pcm_lock_resource_x_outbound_intent_not_admitted_exact"],"mutation_result":"RESOURCE_X_INTENT_STALE","mutation_sha256":"eadc14d5ea5610ad1fb7dbda27a7025109e303749ef5f95dd5b19a99f84dc73c","mutation_witness":"positive","name":"not-admitted-preserves-owner","negative_assertion":"ut_resource_x_complete_count","negative_witness":"src/test/cluster_unit/test_cluster_lms_outbound.c::test_resource_x_intent_admission_stages_and_completion_clears_owner","observable":"resource_x_intent_arm_generation","positive_assertion":"ut_resource_x_owner_slot.state","positive_witness":"src/test/cluster_unit/test_cluster_lms_outbound.c::test_resource_x_intent_pump_not_admitted_preserves_owner","producer_chain":["cluster_lms_outbound_resource_x_intent_pump","cluster_pcm_lock_resource_x_outbound_intent_not_admitted_exact","cluster_pcm_lock_resource_x_intent_not_admitted_exact"],"root":"cluster_lms_outbound_resource_x_intent_pump"},{"consumer_chain":["cluster_lms_outbound_drain_send","cluster_pcm_lock_resource_x_outbound_intent_hard_rearm_exact","pcm_resource_x_intent_mark_dirty"],"evidence_sha256":"2f750a91ae9399e09013c30e85498529aae3f7595a1cb2edf5a8e1daae7c2b60","forbidden_symbol":null,"id":"C1-7","mutation_edge":["cluster_lms_outbound_drain_send","cluster_pcm_lock_resource_x_outbound_intent_hard_rearm_exact"],"mutation_result":"RESOURCE_X_INTENT_STALE","mutation_sha256":"b369071fe6f81eb4ef4832528c6effe7800c5b7c5f8db2b14a37f6d66c8ae642","mutation_witness":"positive","name":"physical-deadline-lifecycle","negative_assertion":"ut_resource_x_rearm_count","negative_witness":"src/test/cluster_unit/test_cluster_lms_outbound.c::test_resource_x_intent_capability_drift_rearms_before_send","observable":"deadline_us","positive_assertion":"ut_resource_x_rearm_count","positive_witness":"src/test/cluster_unit/test_cluster_lms_outbound.c::test_resource_x_intent_physical_deadline_rearms_before_send","producer_chain":["cluster_lms_outbound_drain_send","cluster_pcm_lock_resource_x_outbound_intent_snapshot_exact"],"root":"cluster_lms_outbound_drain_send"},{"consumer_chain":["cluster_gcs_handle_block_invalidate_envelope","gcs_block_try_resource_x_frame","gcs_block_resource_x_type17_ingress","gcs_block_pcm_x_resource_x_source_block_to_n","cluster_pcm_lock_resource_x_holder_pair_publish_exact","pcm_resource_x_holder_pair_publish_internal","pcm_resource_x_rearm_holder_source_locked"],"evidence_sha256":"113ded3875b7bd94482a3be03ee8b9b5cd26b744facdc9fc5ecdacff7fc3e150","forbidden_symbol":null,"id":"C1-8","mutation_edge":["pcm_resource_x_holder_pair_publish_internal","pcm_resource_x_rearm_holder_source_locked"],"mutation_result":"false","mutation_sha256":"e0463eac4849997088920f50a7863cb856d2c8175ccef946ee3149d45b4afa28","mutation_witness":"positive","name":"type17-holder-ingress","negative_assertion":"RESOURCE_X_WIRE_BLOCKED_TO_N","negative_witness":"src/test/cluster_unit/test_cluster_pcm_lock.c::test_resource_x_holder_retains_status_before_s_to_n","observable":"holder_status_intent","positive_assertion":"RESOURCE_X_WIRE_IMAGE_ENVELOPE","positive_witness":"src/test/cluster_unit/test_cluster_pcm_lock.c::test_resource_x_x_source_defers_self_master_grd_transition_to_ingress","producer_chain":["cluster_gcs_handle_block_invalidate_envelope","gcs_block_try_resource_x_frame","gcs_block_resource_x_type17_ingress","gcs_block_pcm_x_resource_x_source_block_to_n","gcs_block_pcm_x_resource_x_build_source_frames"],"root":"cluster_gcs_handle_block_invalidate_envelope"},{"consumer_chain":["cluster_gcs_handle_block_invalidate_ack_envelope","gcs_block_try_resource_x_frame","cluster_pcm_lock_resource_x_blocked_to_n_exact","pcm_resource_x_apply_blocked_holder_locked","pcm_resource_x_commit_grant_locked"],"evidence_sha256":"954d7e54b8385ac4570be605773c83181dcb3dad32503e772f28d6193e597779","forbidden_symbol":null,"id":"C1-9","mutation_edge":["pcm_resource_x_apply_blocked_holder_locked","pcm_resource_x_commit_grant_locked"],"mutation_result":"RESOURCE_X_APPLY_INVALID","mutation_sha256":"5236df7e25ea94828a461c1cf8d98588fd895e5866996b82baa7d6be176af54f","mutation_witness":"positive","name":"type18-master-ingress","negative_assertion":"RESOURCE_X_APPLY_BAD_STATE","negative_witness":"src/test/cluster_unit/test_cluster_pcm_lock.c::test_resource_x_master_remote_proof_is_retained_not_inferred","observable":"blocked_holders_bitmap","positive_assertion":"RESOURCE_X_MASTER_GRANT_COMMITTED","positive_witness":"src/test/cluster_unit/test_cluster_pcm_lock.c::test_resource_x_type18_wire_decode_drives_master_exact_apply","producer_chain":["cluster_gcs_handle_block_invalidate_ack_envelope","gcs_block_try_resource_x_frame","cluster_resource_x_wire_decode"],"root":"cluster_gcs_handle_block_invalidate_ack_envelope"},{"consumer_chain":["cluster_lms_outbound_resource_x_intent_pump","cluster_pcm_lock_resource_x_outbound_work_probe_exact","pcm_resource_x_outbound_owner_valid"],"evidence_sha256":"913fc408d8d6f22ed719c9434b2f1d1b88555c73ce2625a5a6c78c4774919c85","forbidden_symbol":"cluster_pcm_lock_resource_x_grant_intent_probe_exact","id":"C1-10","mutation_edge":["cluster_lms_outbound_resource_x_intent_pump","cluster_pcm_lock_resource_x_outbound_work_probe_exact"],"mutation_result":"RESOURCE_X_INTENT_PROBE_IDLE","mutation_sha256":"7e975b43e2151d87fe7a8920a5c52602ab98650e8ece90f52362220ecc9e752b","mutation_witness":"negative","name":"bound-only-wrapper-absent","negative_assertion":"ut_resource_x_probe_call_count","negative_witness":"src/test/cluster_unit/test_cluster_lms_outbound.c::test_resource_x_intent_pump_is_bounded_to_sixteen_four_probes","observable":"resource_x_intent_next_owner_index","positive_assertion":"RESOURCE_X_INTENT_PROBE_COMPLETE","positive_witness":"src/test/cluster_unit/test_cluster_pcm_lock.c::test_resource_x_intent_sparse_probe_rediscovers_exact_rearm","producer_chain":["cluster_lms_outbound_resource_x_intent_pump","cluster_pcm_lock_resource_x_outbound_work_probe_exact","pcm_resource_x_outbound_owner_at"],"root":"cluster_lms_outbound_resource_x_intent_pump"},{"consumer_chain":["cluster_lms_outbound_resource_x_intent_pump","cluster_pcm_lock_resource_x_outbound_work_probe_exact","pcm_resource_x_outbound_owner_valid"],"evidence_sha256":"bec29d1b5cb6d258d2df597ad7cbd28f8bd36f25e5f28778260a42b4cf11190d","forbidden_symbol":null,"id":"C1-11","mutation_edge":["cluster_pcm_lock_resource_x_outbound_work_probe_exact","pcm_resource_x_outbound_owner_valid"],"mutation_result":"false","mutation_sha256":"ec03a004bafcae8444565ea83e55c2ddc14150956ade46b114df797784679bfd","mutation_witness":"positive","name":"combined-claim-dirty-pass","negative_assertion":"RESOURCE_X_INTENT_PROBE_FOUND","negative_witness":"src/test/cluster_unit/test_cluster_pcm_lock.c::test_resource_x_master_arms_exact_block_to_n_intent_per_holder","observable":"resource_x_intent_completed_generation","positive_assertion":"RESOURCE_X_INTENT_PROBE_FOUND","positive_witness":"src/test/cluster_unit/test_cluster_pcm_lock.c::test_resource_x_intent_sparse_probe_rediscovers_exact_rearm","producer_chain":["cluster_lms_outbound_resource_x_intent_pump","cluster_pcm_lock_resource_x_outbound_work_probe_exact","pcm_resource_x_outbound_owner_at"],"root":"cluster_lms_outbound_resource_x_intent_pump"}],"schema":"pgrac-resource-x-send-c1-v1"} diff --git a/src/test/cluster_unit/pgrac_fenced_live_rejoin_client.c b/src/test/cluster_unit/pgrac_fenced_live_rejoin_client.c index 5bdd7762291..6eaba8bc7ae 100644 --- a/src/test/cluster_unit/pgrac_fenced_live_rejoin_client.c +++ b/src/test/cluster_unit/pgrac_fenced_live_rejoin_client.c @@ -20,13 +20,11 @@ write_exact(int fd, const uint8 *bytes, size_t len) { size_t used = 0; - while (used < len) - { + while (used < len) { ssize_t written = write(fd, bytes + used, len - used); - if (written > 0) - { - used += (size_t) written; + if (written > 0) { + used += (size_t)written; continue; } if (written < 0 && errno == EINTR) @@ -41,13 +39,11 @@ read_exact(int fd, uint8 *bytes, size_t len) { size_t used = 0; - while (used < len) - { + while (used < len) { ssize_t got = read(fd, bytes + used, len - used); - if (got > 0) - { - used += (size_t) got; + if (got > 0) { + used += (size_t)got; continue; } if (got < 0 && errno == EINTR) @@ -59,18 +55,19 @@ read_exact(int fd, uint8 *bytes, size_t len) static bool exchange(int fd, const PgracExternalFenceProtocolRejoinFrameV1 *request, - PgracExternalFenceProtocolRejoinFrameV1 *response) + PgracExternalFenceProtocolRejoinFrameV1 *response) { uint8 request_frame[PGRAC_EXTERNAL_FENCE_REJOIN_V1_BYTES]; uint8 response_frame[PGRAC_EXTERNAL_FENCE_REJOIN_V1_BYTES]; - return pgrac_external_fence_rejoin_v1_encode(request, request_frame) && - write_exact(fd, request_frame, sizeof(request_frame)) && - read_exact(fd, response_frame, sizeof(response_frame)) && - pgrac_external_fence_rejoin_v1_decode(response_frame, - sizeof(response_frame), response) && - memcmp(request->transport_nonce, response->transport_nonce, - sizeof(request->transport_nonce)) == 0; + return pgrac_external_fence_rejoin_v1_encode(request, request_frame) + && write_exact(fd, request_frame, sizeof(request_frame)) + && read_exact(fd, response_frame, sizeof(response_frame)) + && pgrac_external_fence_rejoin_v1_decode(response_frame, sizeof(response_frame), + response) + && memcmp(request->transport_nonce, response->transport_nonce, + sizeof(request->transport_nonce)) + == 0; } static bool @@ -81,29 +78,22 @@ proof_fresh_exact(const PgracExternalFenceProtocolRejoinFrameV1 *response) if (clock_gettime(CLOCK_MONOTONIC, &now) != 0 || now.tv_sec < 0) return false; - now_ns = (uint64) now.tv_sec * UINT64_C(1000000000) + - (uint64) now.tv_nsec; - return response->verified_mono_ns < response->fresh_until_mono_ns && - response->fresh_until_mono_ns - response->verified_mono_ns == - UINT64_C(5000000000) && - now_ns < response->fresh_until_mono_ns; + now_ns = (uint64)now.tv_sec * UINT64_C(1000000000) + (uint64)now.tv_nsec; + return response->verified_mono_ns < response->fresh_until_mono_ns + && response->fresh_until_mono_ns - response->verified_mono_ns == UINT64_C(5000000000) + && now_ns < response->fresh_until_mono_ns; } static void -bound_request(uint16 opcode, - const PgracExternalFenceProtocolRejoinFrameV1 *source, - uint8 nonce, - PgracExternalFenceProtocolRejoinFrameV1 *request) +bound_request(uint16 opcode, const PgracExternalFenceProtocolRejoinFrameV1 *source, uint8 nonce, + PgracExternalFenceProtocolRejoinFrameV1 *request) { memset(request, 0, sizeof(*request)); request->opcode = opcode; - memset(request->transport_nonce, nonce, - sizeof(request->transport_nonce)); - memcpy(request->operation_id, source->operation_id, - sizeof(request->operation_id)); + memset(request->transport_nonce, nonce, sizeof(request->transport_nonce)); + memcpy(request->operation_id, source->operation_id, sizeof(request->operation_id)); request->system_identifier = source->system_identifier; - memset(request->rejoin_gate_digest, 0x91, - sizeof(request->rejoin_gate_digest)); + memset(request->rejoin_gate_digest, 0x91, sizeof(request->rejoin_gate_digest)); memcpy(request->protected_set_digest, source->protected_set_digest, sizeof(request->protected_set_digest)); request->old_node_id = source->old_node_id; @@ -127,77 +117,58 @@ main(void) return 1; memset(&address, 0, sizeof(address)); address.sun_family = AF_UNIX; - if (strlcpy(address.sun_path, PGRAC_FENCED_DB_SOCKET_PATH, - sizeof(address.sun_path)) >= sizeof(address.sun_path) || - connect(fd, (struct sockaddr *) &address, sizeof(address)) != 0) + if (strlcpy(address.sun_path, PGRAC_FENCED_DB_SOCKET_PATH, sizeof(address.sun_path)) + >= sizeof(address.sun_path) + || connect(fd, (struct sockaddr *)&address, sizeof(address)) != 0) return 2; memset(&request, 0, sizeof(request)); request.opcode = PGRAC_EXTERNAL_FENCE_REJOIN_LMON_CLAIM_NEXT; - memset(request.transport_nonce, 0x61, - sizeof(request.transport_nonce)); - if (!exchange(fd, &request, &offer)) - { + memset(request.transport_nonce, 0x61, sizeof(request.transport_nonce)); + if (!exchange(fd, &request, &offer)) { fprintf(stderr, "CLAIM exchange failed: %s\n", strerror(errno)); return 3; } - if ( - offer.opcode != PGRAC_EXTERNAL_FENCE_REJOIN_LMON_OFFER || - offer.status != PGRAC_FENCED_REJOIN_STATUS_OFFERED || - !proof_fresh_exact(&offer)) - { + if (offer.opcode != PGRAC_EXTERNAL_FENCE_REJOIN_LMON_OFFER + || offer.status != PGRAC_FENCED_REJOIN_STATUS_OFFERED || !proof_fresh_exact(&offer)) { fprintf(stderr, - "CLAIM response rejected: opcode=%u status=%u reason=%u " - "provider=%u/%u verified=%llu fresh_until=%llu generation=%llu\n", - (unsigned) offer.opcode, (unsigned) offer.status, - (unsigned) offer.deny_reason, (unsigned) offer.provider_id, - (unsigned) offer.provider_abi_version, - (unsigned long long) offer.verified_mono_ns, - (unsigned long long) offer.fresh_until_mono_ns, - (unsigned long long) offer.proof_generation); + "CLAIM response rejected: opcode=%u status=%u reason=%u " + "provider=%u/%u verified=%llu fresh_until=%llu generation=%llu\n", + (unsigned)offer.opcode, (unsigned)offer.status, (unsigned)offer.deny_reason, + (unsigned)offer.provider_id, (unsigned)offer.provider_abi_version, + (unsigned long long)offer.verified_mono_ns, + (unsigned long long)offer.fresh_until_mono_ns, + (unsigned long long)offer.proof_generation); return 3; } - bound_request(PGRAC_EXTERNAL_FENCE_REJOIN_LMON_AUTHORIZE_ON, - &offer, 0x62, &request); - if (!exchange(fd, &request, &on_result)) - { + bound_request(PGRAC_EXTERNAL_FENCE_REJOIN_LMON_AUTHORIZE_ON, &offer, 0x62, &request); + if (!exchange(fd, &request, &on_result)) { fprintf(stderr, "AUTHORIZE exchange failed: %s\n", strerror(errno)); return 4; } - if ( - on_result.opcode != PGRAC_EXTERNAL_FENCE_REJOIN_LMON_ON_RESULT || - on_result.status != PGRAC_FENCED_REJOIN_STATUS_WAITING_JOINER || - !proof_fresh_exact(&on_result) || - on_result.proof_generation <= offer.proof_generation) - { - fprintf(stderr, - "AUTHORIZE response rejected: opcode=%u status=%u generation=%llu\n", - (unsigned) on_result.opcode, (unsigned) on_result.status, - (unsigned long long) on_result.proof_generation); + if (on_result.opcode != PGRAC_EXTERNAL_FENCE_REJOIN_LMON_ON_RESULT + || on_result.status != PGRAC_FENCED_REJOIN_STATUS_WAITING_JOINER + || !proof_fresh_exact(&on_result) || on_result.proof_generation <= offer.proof_generation) { + fprintf(stderr, "AUTHORIZE response rejected: opcode=%u status=%u generation=%llu\n", + (unsigned)on_result.opcode, (unsigned)on_result.status, + (unsigned long long)on_result.proof_generation); return 4; } - bound_request(PGRAC_EXTERNAL_FENCE_REJOIN_LMON_REFRESH_ON, - &on_result, 0x63, &request); - if (!exchange(fd, &request, &ready)) - { + bound_request(PGRAC_EXTERNAL_FENCE_REJOIN_LMON_REFRESH_ON, &on_result, 0x63, &request); + if (!exchange(fd, &request, &ready)) { fprintf(stderr, "REFRESH exchange failed: %s\n", strerror(errno)); return 5; } - if ( - ready.opcode != PGRAC_EXTERNAL_FENCE_REJOIN_LMON_REFRESH_RESULT || - ready.status != PGRAC_FENCED_REJOIN_STATUS_READY || - !proof_fresh_exact(&ready) || - ready.proof_generation <= on_result.proof_generation) - { - fprintf(stderr, - "REFRESH response rejected: opcode=%u status=%u generation=%llu\n", - (unsigned) ready.opcode, (unsigned) ready.status, - (unsigned long long) ready.proof_generation); + if (ready.opcode != PGRAC_EXTERNAL_FENCE_REJOIN_LMON_REFRESH_RESULT + || ready.status != PGRAC_FENCED_REJOIN_STATUS_READY || !proof_fresh_exact(&ready) + || ready.proof_generation <= on_result.proof_generation) { + fprintf(stderr, "REFRESH response rejected: opcode=%u status=%u generation=%llu\n", + (unsigned)ready.opcode, (unsigned)ready.status, + (unsigned long long)ready.proof_generation); return 5; } - printf("offer=%llu on=%llu ready=%llu\n", - (unsigned long long) offer.proof_generation, - (unsigned long long) on_result.proof_generation, - (unsigned long long) ready.proof_generation); - (void) close(fd); + printf("offer=%llu on=%llu ready=%llu\n", (unsigned long long)offer.proof_generation, + (unsigned long long)on_result.proof_generation, + (unsigned long long)ready.proof_generation); + (void)close(fd); return 0; } diff --git a/src/test/cluster_unit/test_cluster_active_itl_transfer.c b/src/test/cluster_unit/test_cluster_active_itl_transfer.c index fcb81d2df75..ec0166f3783 100644 --- a/src/test/cluster_unit/test_cluster_active_itl_transfer.c +++ b/src/test/cluster_unit/test_cluster_active_itl_transfer.c @@ -108,17 +108,15 @@ repalloc(void *pointer, Size size) bool cluster_bufmgr_terminal_stamp_authority(Buffer buffer, const BufferTag *expected_tag, - uint64 *own_generation, - uint64 *acquisition_epoch, + uint64 *own_generation, uint64 *acquisition_epoch, uint8 *pcm_state) { UT_ASSERT_EQ(buffer, 1); if (!test_capture_authority || expected_tag == NULL || !BufferTagsEqual(expected_tag, &test_live_tag) || !cluster_itl_terminal_stamp_authority_admissible( - cluster_enabled, cluster_node_id, test_node_count, - test_recovery_merge_active, test_pcm_state, test_own_flags, - test_writer_activation_token)) + cluster_enabled, cluster_node_id, test_node_count, test_recovery_merge_active, + test_pcm_state, test_own_flags, test_writer_activation_token)) return false; *own_generation = test_own_generation; *acquisition_epoch = test_acquisition_epoch; @@ -128,24 +126,22 @@ cluster_bufmgr_terminal_stamp_authority(Buffer buffer, const BufferTag *expected Buffer cluster_bufmgr_lock_resident_for_exact_itl_stamp(const ClusterItlTouchRecord *record, - ClusterItlStampSkipReason *out_reason) + ClusterItlStampSkipReason *out_reason) { test_stamp_lock_calls++; test_stamp_lock_saw_valid_proof = record->proof.valid; if (!record->proof.valid - || !BufferTagsEqual(&test_live_tag, - &(BufferTag){ .spcOid = record->key.rloc.spcOid, - .dbOid = record->key.rloc.dbOid, - .relNumber = record->key.rloc.relNumber, - .forkNum = record->key.forknum, - .blockNum = record->key.block }) + || !BufferTagsEqual(&test_live_tag, &(BufferTag){ .spcOid = record->key.rloc.spcOid, + .dbOid = record->key.rloc.dbOid, + .relNumber = record->key.rloc.relNumber, + .forkNum = record->key.forknum, + .blockNum = record->key.block }) || !cluster_itl_terminal_stamp_authority_admissible( - cluster_enabled, cluster_node_id, test_node_count, - test_recovery_merge_active, test_pcm_state, test_own_flags, - test_writer_activation_token) - || !cluster_itl_terminal_proof_owner_exact( - &record->proof, test_own_generation, test_acquisition_epoch, - test_pcm_state, true, test_own_flags, test_writer_activation_token)) { + cluster_enabled, cluster_node_id, test_node_count, test_recovery_merge_active, + test_pcm_state, test_own_flags, test_writer_activation_token) + || !cluster_itl_terminal_proof_owner_exact(&record->proof, test_own_generation, + test_acquisition_epoch, test_pcm_state, true, + test_own_flags, test_writer_activation_token)) { *out_reason = CLUSTER_ITL_STAMP_SKIP_INVALID_PROOF; return InvalidBuffer; } @@ -229,11 +225,10 @@ cluster_sf_observed_origin_durable_lsn(int32 origin) } ClusterCtrcDischargeResult -cluster_ctrc_receipt_discharge_itl_shared( - const ClusterCtrcReceiptHandle *handle, - const ClusterCtrcItlTargetIdentity *expected_target, - ClusterCtrcItlProjection projection, - const ClusterCtrcDurability *durability) +cluster_ctrc_receipt_discharge_itl_shared(const ClusterCtrcReceiptHandle *handle, + const ClusterCtrcItlTargetIdentity *expected_target, + ClusterCtrcItlProjection projection, + const ClusterCtrcDurability *durability) { UT_ASSERT(handle != NULL && handle->valid); UT_ASSERT(expected_target != NULL); @@ -248,9 +243,9 @@ cluster_ctrc_receipt_discharge_itl_shared( } void -cluster_ctrc_note_publication_after_apply( - const ClusterCtrcReceiptHandle *handle pg_attribute_unused(), - bool current_mx pg_attribute_unused()) +cluster_ctrc_note_publication_after_apply(const ClusterCtrcReceiptHandle *handle + pg_attribute_unused(), + bool current_mx pg_attribute_unused()) {} static ClusterItlSlotData * @@ -356,10 +351,8 @@ registration_ctrc_handle(int receipt_index, const ClusterItlTouchHandle *touch, receipt->target.itl_slot_wrap = slot->wrap; receipt->target.itl_xid = slot->xid; receipt->target.itl_class = slot->flags == ITL_FLAG_LOCK_ONLY_ACTIVE ? 2 : 1; - receipt->target.needs_wal - = (touch->flags & CLUSTER_ITL_TOUCH_FLAG_NEEDS_WAL) != 0; - memcpy(receipt->target.uba, &slot->undo_segment_head, - sizeof(slot->undo_segment_head)); + receipt->target.needs_wal = (touch->flags & CLUSTER_ITL_TOUCH_FLAG_NEEDS_WAL) != 0; + memcpy(receipt->target.uba, &slot->undo_segment_head, sizeof(slot->undo_segment_head)); return handle; } @@ -386,8 +379,7 @@ UT_TEST(u13_exact_owner_proof_matches) { ClusterItlTerminalProof proof = valid_proof(); - UT_ASSERT(cluster_itl_terminal_proof_owner_exact( - &proof, 41, 17, PCM_STATE_X, true, 0, 0)); + UT_ASSERT(cluster_itl_terminal_proof_owner_exact(&proof, 41, 17, PCM_STATE_X, true, 0, 0)); } UT_TEST(u14_missing_owner_proof_is_rejected) @@ -395,42 +387,36 @@ UT_TEST(u14_missing_owner_proof_is_rejected) ClusterItlTerminalProof proof = valid_proof(); proof.valid = false; - UT_ASSERT(!cluster_itl_terminal_proof_owner_exact( - &proof, 41, 17, PCM_STATE_X, true, 0, 0)); + UT_ASSERT(!cluster_itl_terminal_proof_owner_exact(&proof, 41, 17, PCM_STATE_X, true, 0, 0)); } UT_TEST(u15_later_x_generation_is_rejected) { ClusterItlTerminalProof proof = valid_proof(); - UT_ASSERT(!cluster_itl_terminal_proof_owner_exact( - &proof, 42, 17, PCM_STATE_X, true, 0, 0)); + UT_ASSERT(!cluster_itl_terminal_proof_owner_exact(&proof, 42, 17, PCM_STATE_X, true, 0, 0)); } UT_TEST(u16_scope_change_is_rejected) { ClusterItlTerminalProof proof = valid_proof(); - UT_ASSERT(!cluster_itl_terminal_proof_owner_exact( - &proof, 41, 18, PCM_STATE_X, true, 0, 0)); + UT_ASSERT(!cluster_itl_terminal_proof_owner_exact(&proof, 41, 18, PCM_STATE_X, true, 0, 0)); } UT_TEST(u17_non_x_owner_is_rejected) { ClusterItlTerminalProof proof = valid_proof(); - UT_ASSERT(!cluster_itl_terminal_proof_owner_exact( - &proof, 41, 17, PCM_STATE_N, true, 0, 0)); + UT_ASSERT(!cluster_itl_terminal_proof_owner_exact(&proof, 41, 17, PCM_STATE_N, true, 0, 0)); } UT_TEST(u18_busy_owner_is_rejected) { ClusterItlTerminalProof proof = valid_proof(); - UT_ASSERT(!cluster_itl_terminal_proof_owner_exact( - &proof, 41, 17, PCM_STATE_X, true, 1, 0)); - UT_ASSERT(!cluster_itl_terminal_proof_owner_exact( - &proof, 41, 17, PCM_STATE_X, true, 0, 99)); + UT_ASSERT(!cluster_itl_terminal_proof_owner_exact(&proof, 41, 17, PCM_STATE_X, true, 1, 0)); + UT_ASSERT(!cluster_itl_terminal_proof_owner_exact(&proof, 41, 17, PCM_STATE_X, true, 0, 99)); } UT_TEST(u19_exact_slot_proof_matches) @@ -438,8 +424,7 @@ UT_TEST(u19_exact_slot_proof_matches) ClusterItlTerminalProof proof = valid_proof(); UBA uba = proof.undo_segment_head; - UT_ASSERT(cluster_itl_terminal_proof_slot_exact(&proof, 700, 3, - ITL_FLAG_ACTIVE, &uba)); + UT_ASSERT(cluster_itl_terminal_proof_slot_exact(&proof, 700, 3, ITL_FLAG_ACTIVE, &uba)); } UT_TEST(u20_slot_aba_or_class_change_is_rejected) @@ -447,15 +432,12 @@ UT_TEST(u20_slot_aba_or_class_change_is_rejected) ClusterItlTerminalProof proof = valid_proof(); UBA uba = proof.undo_segment_head; - UT_ASSERT(!cluster_itl_terminal_proof_slot_exact(&proof, 701, 3, - ITL_FLAG_ACTIVE, &uba)); - UT_ASSERT(!cluster_itl_terminal_proof_slot_exact(&proof, 700, 4, - ITL_FLAG_ACTIVE, &uba)); - UT_ASSERT(!cluster_itl_terminal_proof_slot_exact(&proof, 700, 3, - ITL_FLAG_LOCK_ONLY_ACTIVE, &uba)); + UT_ASSERT(!cluster_itl_terminal_proof_slot_exact(&proof, 701, 3, ITL_FLAG_ACTIVE, &uba)); + UT_ASSERT(!cluster_itl_terminal_proof_slot_exact(&proof, 700, 4, ITL_FLAG_ACTIVE, &uba)); + UT_ASSERT( + !cluster_itl_terminal_proof_slot_exact(&proof, 700, 3, ITL_FLAG_LOCK_ONLY_ACTIVE, &uba)); uba.raw[1]++; - UT_ASSERT(!cluster_itl_terminal_proof_slot_exact(&proof, 700, 3, - ITL_FLAG_ACTIVE, &uba)); + UT_ASSERT(!cluster_itl_terminal_proof_slot_exact(&proof, 700, 3, ITL_FLAG_ACTIVE, &uba)); } UT_TEST(u35_uba_drift_preserves_active_slot) @@ -504,8 +486,7 @@ UT_TEST(u36_abort_discharge_waits_for_terminal_wal_and_dependency_frontier) UT_ASSERT_EQ(test_discharge_target.itl_xid, xid); UT_ASSERT_EQ(test_discharge_target.itl_slot_wrap, slot->wrap); UT_ASSERT_EQ(test_discharge_target.itl_class, 1); - UT_ASSERT_EQ(test_discharge_target.uba[15], - ((const uint8 *)&slot->undo_segment_head)[15]); + UT_ASSERT_EQ(test_discharge_target.uba[15], ((const uint8 *)&slot->undo_segment_head)[15]); UT_ASSERT_EQ(test_discharge_durability.highest_local_lsn, 300); UT_ASSERT_EQ(test_discharge_durability.local_flush_lsn, 300); UT_ASSERT_EQ(test_discharge_durability.required_lsn[4], 400); @@ -625,8 +606,7 @@ UT_TEST(u39_same_slot_recapture_replaces_only_the_eager_receipt_handle) UT_ASSERT_EQ(test_discharge_calls, 1); UT_ASSERT(test_discharged_receipt == &test_ctrc_receipts[1]); - UT_ASSERT_EQ(test_discharge_target.uba[0], - ((const uint8 *)&slot->undo_segment_head)[0]); + UT_ASSERT_EQ(test_discharge_target.uba[0], ((const uint8 *)&slot->undo_segment_head)[0]); } UT_TEST(u40_reuse_lookup_returns_only_the_exact_live_itl_receipt) @@ -644,21 +624,17 @@ UT_TEST(u40_reuse_lookup_returns_only_the_exact_live_itl_receipt) cluster_itl_touch_register_exact_ctrc(&touch, 1, xid, ®istered); MemSet(&found, 0, sizeof(found)); - UT_ASSERT(cluster_itl_touch_lookup_reusable_ctrc( - &touch, 1, xid, &found)); + UT_ASSERT(cluster_itl_touch_lookup_reusable_ctrc(&touch, 1, xid, &found)); UT_ASSERT(found.valid); UT_ASSERT(found.receipt == registered.receipt); - UT_ASSERT_EQ(found.journal_slot_generation, - registered.journal_slot_generation); + UT_ASSERT_EQ(found.journal_slot_generation, registered.journal_slot_generation); slot->undo_segment_head.raw[1]++; - UT_ASSERT(!cluster_itl_touch_lookup_reusable_ctrc( - &touch, 1, xid, &found)); + UT_ASSERT(!cluster_itl_touch_lookup_reusable_ctrc(&touch, 1, xid, &found)); UT_ASSERT(!found.valid); slot->undo_segment_head.raw[1]--; test_own_generation++; - UT_ASSERT(!cluster_itl_touch_lookup_reusable_ctrc( - &touch, 1, xid, &found)); + UT_ASSERT(!cluster_itl_touch_lookup_reusable_ctrc(&touch, 1, xid, &found)); UT_ASSERT(!found.valid); } diff --git a/src/test/cluster_unit/test_cluster_allocation_stop.c b/src/test/cluster_unit/test_cluster_allocation_stop.c index 81de7bc0ca6..0908e641721 100644 --- a/src/test/cluster_unit/test_cluster_allocation_stop.c +++ b/src/test/cluster_unit/test_cluster_allocation_stop.c @@ -30,7 +30,11 @@ int cluster_oid_lease_size = 8; int cluster_node_id = 0; char *cluster_shared_data_dir; static int fixture_node_count = 4; -int cluster_conf_node_count(void) { return fixture_node_count; } +int +cluster_conf_node_count(void) +{ + return fixture_node_count; +} PGPROC *MyProc; PROC_HDR *ProcGlobal; Latch *MyLatch; @@ -59,7 +63,11 @@ cluster_normal_stop_service_new_work(bool modifies_data) stop_new_modifier_calls++; return stop_new_modifier_allowed; } -uint32 cluster_grd_shard_for_resource(const ClusterResId *resid) { return 0; } +uint32 +cluster_grd_shard_for_resource(const ClusterResId *resid) +{ + return 0; +} static uint32 fixture_hw_master_generation; static ClusterGrdShardPhase fixture_hw_shard_phase = GRD_SHARD_NORMAL; uint32 @@ -609,8 +617,8 @@ UT_TEST(lmon_post_send_observes_original_shared_owners) UT_TEST(hw_remote_seal_precedes_original_advance_wal_and_reply) { - HwAllocRequest req = {0}; - ClusterICEnvelope env = {0}; + HwAllocRequest req = { 0 }; + ClusterICEnvelope env = { 0 }; HwAllocReply accepted; ClusterResId resid; bool found; @@ -633,7 +641,7 @@ UT_TEST(hw_remote_seal_precedes_original_advance_wal_and_reply) env.source_node_id = 1; env.dest_node_id = 0; env.payload_length = sizeof(req); - cluster_hw_resid_encode((RelFileLocator){1663, 5, 16384}, MAIN_FORKNUM, &resid); + cluster_hw_resid_encode((RelFileLocator){ 1663, 5, 16384 }, MAIN_FORKNUM, &resid); stop_new_modifier_allowed = false; cluster_hw_alloc_request_handler(&env, &req); UT_ASSERT_EQ(stop_new_modifier_calls, 1); @@ -662,9 +670,9 @@ UT_TEST(hw_remote_seal_precedes_original_advance_wal_and_reply) UT_TEST(hw_local_backend_and_existing_reply_keep_original_paths) { - HwAllocRequest req = {0}; + HwAllocRequest req = { 0 }; HwAllocReply reply, received; - ClusterICEnvelope env = {0}; + ClusterICEnvelope env = { 0 }; reset_fixture(); cluster_shared_data_dir = "allocation-fixture"; diff --git a/src/test/cluster_unit/test_cluster_backup_stop.c b/src/test/cluster_unit/test_cluster_backup_stop.c index 15983a18032..e9d016c81e7 100644 --- a/src/test/cluster_unit/test_cluster_backup_stop.c +++ b/src/test/cluster_unit/test_cluster_backup_stop.c @@ -3,6 +3,7 @@ #include "postgres.h" #include "miscadmin.h" #include "cluster/cluster_clean_leave.h" +#include "test_cluster_normal_cold_scn.inc" #include "../../backend/cluster/cluster_backup.c" #undef printf #undef fprintf diff --git a/src/test/cluster_unit/test_cluster_block_format.c b/src/test/cluster_unit/test_cluster_block_format.c index 9eb8dc76a24..224b2ded6ea 100644 --- a/src/test/cluster_unit/test_cluster_block_format.c +++ b/src/test/cluster_unit/test_cluster_block_format.c @@ -170,7 +170,7 @@ UT_TEST(test_page_lsn_origin_roundtrip_preserves_other_flags) UT_ASSERT(PageGetLSNOrigin((Page)&ph, &origin)); UT_ASSERT_EQ(origin, 0); UT_ASSERT_EQ(ph.pd_flags & (PD_HAS_ITL | PD_CLUSTER_FORCE_FPI), - PD_HAS_ITL | PD_CLUSTER_FORCE_FPI); + PD_HAS_ITL | PD_CLUSTER_FORCE_FPI); PageSetLSNOrigin((Page)&ph, PGRAC_PAGE_LSN_ORIGIN_MAX); UT_ASSERT(PageGetLSNOrigin((Page)&ph, &origin)); UT_ASSERT_EQ(origin, PGRAC_PAGE_LSN_ORIGIN_MAX); diff --git a/src/test/cluster_unit/test_cluster_bufmgr_pcm_hook.c b/src/test/cluster_unit/test_cluster_bufmgr_pcm_hook.c index 15fccfb4b05..73028f10c54 100644 --- a/src/test/cluster_unit/test_cluster_bufmgr_pcm_hook.c +++ b/src/test/cluster_unit/test_cluster_bufmgr_pcm_hook.c @@ -40,7 +40,9 @@ *------------------------------------------------------------------------- */ #include "postgres.h" +#include "miscadmin.h" +#include "cluster/cluster_clean_leave.h" #include "cluster/cluster_buffer_desc.h" #include "cluster/cluster_gcs_block.h" /* spec-4.7 D1 — ClusterGcsBlockPhase + phase_for_tag proto */ #include "cluster/cluster_inject.h" @@ -75,6 +77,31 @@ int NBuffers = 0; int cluster_injection_armed_count = 0; int cluster_gcs_reply_timeout_ms = 1; bool cluster_enabled = true; /* PGRAC: spec-2.31 D2 helper depends on this */ +bool IsUnderPostmaster = false; +BackendType MyBackendType = B_BACKEND; +AuxProcType MyAuxProcType = NotAnAuxProcess; + +bool +cluster_normal_stop_service_new_work(bool modifies_data pg_attribute_unused()) +{ + /* The fixture models an open service, never a normal-stop episode. */ + return true; +} + +bool +cluster_normal_stop_pi_retirement_allowed(void) +{ + return false; +} + +int +s_lock(volatile slock_t *lock, const char *file pg_attribute_unused(), + int line pg_attribute_unused(), const char *func pg_attribute_unused()) +{ + while (TAS_SPIN(lock)) + ; + return 0; +} uint64 cluster_lms_get_shard_master_generation(void) @@ -87,8 +114,7 @@ cluster_lms_wakeup(int worker_id pg_attribute_unused()) {} bool -cluster_lms_outbound_resource_x_transport_snapshot( - ClusterLmsResourceXTransportSnapshot *out) +cluster_lms_outbound_resource_x_transport_snapshot(ClusterLmsResourceXTransportSnapshot *out) { if (out != NULL) memset(out, 0, sizeof(*out)); @@ -96,10 +122,9 @@ cluster_lms_outbound_resource_x_transport_snapshot( } ResourceXSidecarNeutralizeResult -cluster_bufmgr_resource_x_neutralize_exact( - const BufferTag *tag pg_attribute_unused(), - uint64 old_formation pg_attribute_unused(), - uint64 acquisition_generation pg_attribute_unused()) +cluster_bufmgr_resource_x_neutralize_exact(const BufferTag *tag pg_attribute_unused(), + uint64 old_formation pg_attribute_unused(), + uint64 acquisition_generation pg_attribute_unused()) { return RESOURCE_X_SIDECAR_NEUTRALIZED; } @@ -170,7 +195,6 @@ static uint32 ut_wait_event_info_storage = 0; uint32 *my_wait_event_info = &ut_wait_event_info_storage; #define FAKE_PCM_MAX_ENTRIES 8 -#define FAKE_PCM_ENTRY_BYTES 1032 static union { uint64 force_align; @@ -180,10 +204,8 @@ static union { char data[1048576]; } fake_pcm_header; -static union { - uint64 force_align; - char data[FAKE_PCM_MAX_ENTRIES][FAKE_PCM_ENTRY_BYTES]; -} fake_pcm_entries; +/* malloc alignment and the production HASHCTL size, without a stale ABI copy. */ +static void *fake_pcm_entries[FAKE_PCM_MAX_ENTRIES]; static char fake_pcm_htab_token; static bool fake_pcm_header_found = false; @@ -255,13 +277,18 @@ ShmemInitHash(const char *name pg_attribute_unused(), long init_size pg_attribut long max_size, HASHCTL *infoP, int hash_flags pg_attribute_unused()) { Assert((hash_flags & HASH_ELEM) != 0); - Assert(infoP->entrysize <= FAKE_PCM_ENTRY_BYTES); + Assert(infoP->entrysize >= infoP->keysize); Assert(max_size <= FAKE_PCM_MAX_ENTRIES); fake_pcm_keysize = infoP->keysize; fake_pcm_entrysize = infoP->entrysize; fake_pcm_entry_max = max_size; fake_pcm_entry_count = 0; - memset(&fake_pcm_entries, 0, sizeof(fake_pcm_entries)); + for (long i = 0; i < FAKE_PCM_MAX_ENTRIES; i++) { + free(fake_pcm_entries[i]); + fake_pcm_entries[i] = i < max_size ? calloc(1, infoP->entrysize) : NULL; + if (i < max_size && fake_pcm_entries[i] == NULL) + abort(); + } return (HTAB *)&fake_pcm_htab_token; } @@ -274,7 +301,7 @@ hash_search(HTAB *hashp pg_attribute_unused(), const void *keyPtr, HASHACTION ac Assert(fake_pcm_keysize > 0); for (i = 0; i < fake_pcm_entry_count; i++) { - char *entry = fake_pcm_entries.data[i]; + char *entry = fake_pcm_entries[i]; if (memcmp(entry, keyPtr, fake_pcm_keysize) == 0) { if (foundPtr != NULL) @@ -298,10 +325,10 @@ hash_search(HTAB *hashp pg_attribute_unused(), const void *keyPtr, HASHACTION ac Assert(false); } - memcpy(fake_pcm_entries.data[fake_pcm_entry_count], keyPtr, fake_pcm_keysize); + memcpy(fake_pcm_entries[fake_pcm_entry_count], keyPtr, fake_pcm_keysize); if (foundPtr != NULL) *foundPtr = false; - return fake_pcm_entries.data[fake_pcm_entry_count++]; + return fake_pcm_entries[fake_pcm_entry_count++]; } long @@ -322,7 +349,7 @@ hash_seq_search(HASH_SEQ_STATUS *status) { if (status->curBucket >= (uint32)fake_pcm_entry_count) return NULL; - return fake_pcm_entries.data[status->curBucket++]; + return fake_pcm_entries[status->curBucket++]; } void @@ -360,6 +387,13 @@ LWLockHeldByMeInMode(LWLock *lock, LWLockMode mode) return fake_lwlock_held == lock && fake_lwlock_mode == mode; } +void +ForEachLWLockHeldByMe(void (*callback)(LWLock *, LWLockMode, void *), void *context) +{ + if (fake_lwlock_held != NULL) + callback(fake_lwlock_held, fake_lwlock_mode, context); +} + TimestampTz GetCurrentTimestamp(void) { @@ -404,8 +438,8 @@ cluster_gcs_send_transition_and_wait(BufferTag tag pg_attribute_unused(), bool cluster_gcs_try_send_transition_and_wait(BufferTag tag pg_attribute_unused(), - PcmLockTransition trans pg_attribute_unused(), - int master_node pg_attribute_unused()) + PcmLockTransition trans pg_attribute_unused(), + int master_node pg_attribute_unused()) { abort(); } @@ -429,11 +463,10 @@ cluster_gcs_send_block_request_and_wait(struct BufferDesc *buf pg_attribute_unus /* spec-5.2 D2 sub-case B stub: local-master read-image forward unreachable. */ bool -cluster_gcs_local_master_read_image_and_wait(struct BufferDesc *buf pg_attribute_unused(), - const PcmAuthoritySnapshot *expected - pg_attribute_unused(), - bool force_one_shot pg_attribute_unused(), - bool *out_retry_denied pg_attribute_unused()) +cluster_gcs_local_master_read_image_and_wait( + struct BufferDesc *buf pg_attribute_unused(), + const PcmAuthoritySnapshot *expected pg_attribute_unused(), + bool force_one_shot pg_attribute_unused(), bool *out_retry_denied pg_attribute_unused()) { abort(); } @@ -658,7 +691,6 @@ static void reset_fixture(void) { memset(&fake_pcm_header, 0, sizeof(fake_pcm_header)); - memset(&fake_pcm_entries, 0, sizeof(fake_pcm_entries)); fake_pcm_header_found = false; fake_pcm_entry_count = 0; fake_pcm_entry_max = 0; @@ -875,37 +907,35 @@ UT_TEST(test_L10_read_image_is_neither_cached_cover_nor_write_authority) before = live; UT_ASSERT_EQ(CLUSTER_PCM_GRANT_WAIT_READ_IMAGE_BRACKET, 2); - UT_ASSERT_EQ(cluster_pcm_x_read_image_begin_disposition( - &live, BM_VALID, (uint8)BUF_TYPE_CURRENT, &reason), - CLUSTER_PCM_OWN_BUSY); + UT_ASSERT_EQ(cluster_pcm_x_read_image_begin_disposition(&live, BM_VALID, + (uint8)BUF_TYPE_CURRENT, &reason), + CLUSTER_PCM_OWN_BUSY); UT_ASSERT_EQ(reason, CLUSTER_PCM_GRANT_WAIT_READ_IMAGE_BRACKET); UT_ASSERT_EQ(memcmp(&live, &before, sizeof(live)), 0); UT_ASSERT(!cluster_pcm_x_cached_cover_reverify_accepts( - (uint8)PCM_LOCK_MODE_S, live.generation, live.generation, - live.pcm_state, live.flags, live.writer_activation_token, - live.resource_x_activation_generation)); - UT_ASSERT(!cluster_pcm_x_ordinary_mutation_allowed( - true, true, false, live.pcm_state, live.flags, - live.writer_activation_token, - live.resource_x_activation_generation)); + (uint8)PCM_LOCK_MODE_S, live.generation, live.generation, live.pcm_state, live.flags, + live.writer_activation_token, live.resource_x_activation_generation)); + UT_ASSERT(!cluster_pcm_x_ordinary_mutation_allowed(true, true, false, live.pcm_state, + live.flags, live.writer_activation_token, + live.resource_x_activation_generation)); live.flags = PCM_OWN_FLAG_GRANT_PENDING; reason = CLUSTER_PCM_GRANT_WAIT_READ_IMAGE_BRACKET; - UT_ASSERT_EQ(cluster_pcm_x_read_image_begin_disposition( - &live, BM_VALID, (uint8)BUF_TYPE_CURRENT, &reason), - CLUSTER_PCM_OWN_CORRUPT); + UT_ASSERT_EQ(cluster_pcm_x_read_image_begin_disposition(&live, BM_VALID, + (uint8)BUF_TYPE_CURRENT, &reason), + CLUSTER_PCM_OWN_CORRUPT); UT_ASSERT_EQ(reason, CLUSTER_PCM_GRANT_WAIT_NONE); live = before; live.generation = UINT64_MAX; - UT_ASSERT_EQ(cluster_pcm_x_read_image_begin_disposition( - &live, BM_VALID, (uint8)BUF_TYPE_CURRENT, &reason), - CLUSTER_PCM_OWN_EXHAUSTED); + UT_ASSERT_EQ(cluster_pcm_x_read_image_begin_disposition(&live, BM_VALID, + (uint8)BUF_TYPE_CURRENT, &reason), + CLUSTER_PCM_OWN_EXHAUSTED); live = before; - UT_ASSERT_EQ(cluster_pcm_x_read_image_begin_disposition( - &live, BM_VALID | BM_IO_IN_PROGRESS, - (uint8)BUF_TYPE_CURRENT, &reason), CLUSTER_PCM_OWN_CORRUPT); - UT_ASSERT_EQ(cluster_pcm_x_read_image_begin_disposition( - &live, BM_VALID, (uint8)BUF_TYPE_PI, &reason), + UT_ASSERT_EQ(cluster_pcm_x_read_image_begin_disposition(&live, BM_VALID | BM_IO_IN_PROGRESS, + (uint8)BUF_TYPE_CURRENT, &reason), + CLUSTER_PCM_OWN_CORRUPT); + UT_ASSERT_EQ( + cluster_pcm_x_read_image_begin_disposition(&live, BM_VALID, (uint8)BUF_TYPE_PI, &reason), CLUSTER_PCM_OWN_CORRUPT); } diff --git a/src/test/cluster_unit/test_cluster_cf_enqueue.c b/src/test/cluster_unit/test_cluster_cf_enqueue.c index 21fce0c7528..d5a8027b5af 100644 --- a/src/test/cluster_unit/test_cluster_cf_enqueue.c +++ b/src/test/cluster_unit/test_cluster_cf_enqueue.c @@ -234,8 +234,7 @@ cluster_cf_owner_eor_phase_install(void) bool cluster_cf_owner_eor_phase_activate(void) { - if (!AmCheckpointerProcess() - || g_owner_eor_phase != CLUSTER_CF_OWNER_EOR_INSTALLED) + if (!AmCheckpointerProcess() || g_owner_eor_phase != CLUSTER_CF_OWNER_EOR_INSTALLED) return false; g_owner_eor_phase = CLUSTER_CF_OWNER_EOR_ACTIVE; return true; @@ -435,9 +434,9 @@ UT_TEST(test_owner_eor_disabled_seed_uses_exact_declared_node) UT_ASSERT(fd >= 0); f = fdopen(fd, "w"); UT_ASSERT(f != NULL); - UT_ASSERT(fprintf(f, - "[cluster]\nname = pgrac\n\n[node.0]\n" - "interconnect_addr = 127.0.0.1:6433\n") > 0); + UT_ASSERT(fprintf(f, "[cluster]\nname = pgrac\n\n[node.0]\n" + "interconnect_addr = 127.0.0.1:6433\n") + > 0); UT_ASSERT_EQ(fclose(f), 0); g_node_count = 0; @@ -500,21 +499,18 @@ UT_TEST(test_confirmed_release_requires_clusterwide_s6_success) UT_ASSERT(cluster_cf_lock(ExclusiveLock)); UT_ASSERT(cluster_cf_held_is_clusterwide(ExclusiveLock)); - UT_ASSERT_EQ(cluster_cf_unlock_confirmed(ExclusiveLock), - CLUSTER_CF_RELEASE_CONFIRMED); + UT_ASSERT_EQ(cluster_cf_unlock_confirmed(ExclusiveLock), CLUSTER_CF_RELEASE_CONFIRMED); UT_ASSERT(!cluster_cf_held(ExclusiveLock)); UT_ASSERT_EQ(g_s6_count, 1); UT_ASSERT(cluster_cf_lock(ExclusiveLock)); g_s6_result = CLUSTER_LOCK_ACQUIRE_FAIL_TIMEOUT; - UT_ASSERT_EQ(cluster_cf_unlock_confirmed(ExclusiveLock), - CLUSTER_CF_RELEASE_UNCONFIRMED); + UT_ASSERT_EQ(cluster_cf_unlock_confirmed(ExclusiveLock), CLUSTER_CF_RELEASE_UNCONFIRMED); UT_ASSERT(cluster_cf_held(ExclusiveLock)); UT_ASSERT(cluster_cf_held_is_clusterwide(ExclusiveLock)); g_s6_result = CLUSTER_LOCK_ACQUIRE_OK_GRANTED; - UT_ASSERT_EQ(cluster_cf_unlock_confirmed(ExclusiveLock), - CLUSTER_CF_RELEASE_CONFIRMED); + UT_ASSERT_EQ(cluster_cf_unlock_confirmed(ExclusiveLock), CLUSTER_CF_RELEASE_CONFIRMED); UT_ASSERT(!cluster_cf_held(ExclusiveLock)); } @@ -526,8 +522,7 @@ UT_TEST(test_native_hold_never_becomes_clusterwide_authority) UT_ASSERT(cluster_cf_lock(ShareLock)); UT_ASSERT(cluster_cf_held(ShareLock)); UT_ASSERT(!cluster_cf_held_is_clusterwide(ShareLock)); - UT_ASSERT_EQ(cluster_cf_unlock_confirmed(ShareLock), - CLUSTER_CF_RELEASE_NOT_HELD); + UT_ASSERT_EQ(cluster_cf_unlock_confirmed(ShareLock), CLUSTER_CF_RELEASE_NOT_HELD); UT_ASSERT(!cluster_cf_held(ShareLock)); UT_ASSERT_EQ(g_s6_count, 0); } diff --git a/src/test/cluster_unit/test_cluster_cf_phase2.c b/src/test/cluster_unit/test_cluster_cf_phase2.c index 80949fc07ec..f2e1010c33f 100644 --- a/src/test/cluster_unit/test_cluster_cf_phase2.c +++ b/src/test/cluster_unit/test_cluster_cf_phase2.c @@ -201,8 +201,7 @@ cluster_conf_lookup_node(int32 id) { static const ClusterNodeInfo marker; - return (id >= 0 && id < CLUSTER_MAX_NODES && stub_configured_nodes[id]) - ? &marker : NULL; + return (id >= 0 && id < CLUSTER_MAX_NODES && stub_configured_nodes[id]) ? &marker : NULL; } int cluster_conf_node_count(void) @@ -236,8 +235,8 @@ configure_nodes(int count) static void ack_path(char path[MAXPGPATH], int probe_owner, int responder, uint64 nonce) { - snprintf(path, MAXPGPATH, "%s/%s/ack.%d.%d.%016" INT64_MODIFIER "x", - shared_root, CLUSTER_CF_PHASE2_DIR, probe_owner, responder, nonce); + snprintf(path, MAXPGPATH, "%s/%s/ack.%d.%d.%016" INT64_MODIFIER "x", shared_root, + CLUSTER_CF_PHASE2_DIR, probe_owner, responder, nonce); } static void @@ -255,8 +254,7 @@ static void restamp_v2(ClusterCfPhase2RecordV2 *record) { INIT_CRC32C(record->crc); - COMP_CRC32C(record->crc, record, - offsetof(ClusterCfPhase2RecordV2, crc)); + COMP_CRC32C(record->crc, record, offsetof(ClusterCfPhase2RecordV2, crc)); FIN_CRC32C(record->crc); } @@ -340,11 +338,9 @@ UT_TEST(test_four_responders_publish_distinct_exact_acks) configure_nodes(4); UT_ASSERT(cluster_cf_phase2_write_probe(shared_root, 0, nonce)); for (responder = 1; responder <= 3; responder++) - UT_ASSERT(cluster_cf_phase2_write_ack( - shared_root, 0, responder, nonce)); + UT_ASSERT(cluster_cf_phase2_write_ack(shared_root, 0, responder, nonce)); for (responder = 1; responder <= 3; responder++) - UT_ASSERT(cluster_cf_phase2_read_exact_ack( - shared_root, 0, responder, nonce)); + UT_ASSERT(cluster_cf_phase2_read_exact_ack(shared_root, 0, responder, nonce)); } UT_TEST(test_nonselected_responder_cannot_complete_rendezvous) @@ -355,8 +351,7 @@ UT_TEST(test_nonselected_responder_cannot_complete_rendezvous) configure_nodes(4); UT_ASSERT(cluster_cf_phase2_write_probe(shared_root, 0, nonce)); UT_ASSERT(cluster_cf_phase2_write_ack(shared_root, 0, 2, nonce)); - UT_ASSERT(!cluster_cf_phase2_rendezvous( - shared_root, 0, 1, nonce, 0)); + UT_ASSERT(!cluster_cf_phase2_rendezvous(shared_root, 0, 1, nonce, 0)); } UT_TEST(test_delayed_old_nonce_writer_cannot_replace_current_ack) @@ -371,8 +366,7 @@ UT_TEST(test_delayed_old_nonce_writer_cannot_replace_current_ack) UT_ASSERT(cluster_cf_phase2_write_probe(shared_root, 0, new_nonce)); UT_ASSERT(cluster_cf_phase2_write_ack(shared_root, 0, 1, new_nonce)); UT_ASSERT(!cluster_cf_phase2_write_ack(shared_root, 0, 1, old_nonce)); - UT_ASSERT(cluster_cf_phase2_read_exact_ack( - shared_root, 0, 1, new_nonce)); + UT_ASSERT(cluster_cf_phase2_read_exact_ack(shared_root, 0, 1, new_nonce)); } UT_TEST(test_duplicate_exact_ack_is_idempotent) @@ -384,8 +378,7 @@ UT_TEST(test_duplicate_exact_ack_is_idempotent) UT_ASSERT(cluster_cf_phase2_write_probe(shared_root, 0, nonce)); UT_ASSERT(cluster_cf_phase2_write_ack(shared_root, 0, 1, nonce)); UT_ASSERT(cluster_cf_phase2_write_ack(shared_root, 0, 1, nonce)); - UT_ASSERT(cluster_cf_phase2_read_exact_ack( - shared_root, 0, 1, nonce)); + UT_ASSERT(cluster_cf_phase2_read_exact_ack(shared_root, 0, 1, nonce)); } UT_TEST(test_v2_crc_and_path_tuple_validation) @@ -394,6 +387,8 @@ UT_TEST(test_v2_crc_and_path_tuple_validation) uint32 magic; uint32 version; uint64 nonce; + /* The fixture writes the complete old wire record, including CRC. */ + /* cppcheck-suppress unusedStructMember */ pg_crc32c crc; } ClusterCfPhase2RecordV1; ClusterCfPhase2RecordV1 v1; @@ -407,10 +402,8 @@ UT_TEST(test_v2_crc_and_path_tuple_validation) configure_nodes(4); UT_ASSERT(cluster_cf_phase2_write_probe(shared_root, 0, nonce)); UT_ASSERT(cluster_cf_phase2_write_ack(shared_root, 0, 1, nonce)); - UT_ASSERT(!cluster_cf_phase2_read_exact_ack( - shared_root, 0, 2, nonce)); - UT_ASSERT(!cluster_cf_phase2_read_exact_ack( - shared_root, 0, 1, nonce + 1)); + UT_ASSERT(!cluster_cf_phase2_read_exact_ack(shared_root, 0, 2, nonce)); + UT_ASSERT(!cluster_cf_phase2_read_exact_ack(shared_root, 0, 1, nonce + 1)); ack_path(path, 0, 1, nonce); fd = open(path, O_RDONLY); @@ -419,8 +412,7 @@ UT_TEST(test_v2_crc_and_path_tuple_validation) close(fd); record.crc ^= 1; write_test_bytes(path, &record, sizeof(record)); - UT_ASSERT(!cluster_cf_phase2_read_exact_ack( - shared_root, 0, 1, nonce)); + UT_ASSERT(!cluster_cf_phase2_read_exact_ack(shared_root, 0, 1, nonce)); UT_ASSERT(cluster_cf_phase2_write_probe(shared_root, 0, nonce + 1)); UT_ASSERT(cluster_cf_phase2_write_ack(shared_root, 0, 1, nonce + 1)); @@ -432,15 +424,12 @@ UT_TEST(test_v2_crc_and_path_tuple_validation) record.responder_node = 2; restamp_v2(&record); write_test_bytes(path, &record, sizeof(record)); - UT_ASSERT(!cluster_cf_phase2_read_exact_ack( - shared_root, 0, 1, nonce + 1)); + UT_ASSERT(!cluster_cf_phase2_read_exact_ack(shared_root, 0, 1, nonce + 1)); /* A valid V2 body moved under another probe-owner path is foreign. */ UT_ASSERT(cluster_cf_phase2_write_probe(shared_root, 0, nonce + 2)); - snprintf(from, sizeof(from), "%s/%s/probe.0", - shared_root, CLUSTER_CF_PHASE2_DIR); - snprintf(path, sizeof(path), "%s/%s/probe.1", - shared_root, CLUSTER_CF_PHASE2_DIR); + snprintf(from, sizeof(from), "%s/%s/probe.0", shared_root, CLUSTER_CF_PHASE2_DIR); + snprintf(path, sizeof(path), "%s/%s/probe.1", shared_root, CLUSTER_CF_PHASE2_DIR); UT_ASSERT_EQ(rename(from, path), 0); UT_ASSERT(!cluster_cf_phase2_read_probe(shared_root, 1, &record)); @@ -451,8 +440,7 @@ UT_TEST(test_v2_crc_and_path_tuple_validation) v1.nonce = nonce + 3; ack_path(path, 0, 1, nonce + 3); write_test_bytes(path, &v1, sizeof(v1)); - UT_ASSERT(!cluster_cf_phase2_read_exact_ack( - shared_root, 0, 1, nonce + 3)); + UT_ASSERT(!cluster_cf_phase2_read_exact_ack(shared_root, 0, 1, nonce + 3)); } UT_TEST(test_ack_cleanup_is_scoped_to_exact_responder_pair) @@ -477,13 +465,12 @@ UT_TEST(test_ack_cleanup_is_scoped_to_exact_responder_pair) ack_path(old_same_pair, 0, 1, old_nonce); ack_path(old_other_responder, 0, 2, old_nonce); ack_path(old_other_owner, 1, 2, foreign_nonce); - snprintf(malformed, sizeof(malformed), "%s/%s/ack.0.1.foreign", - shared_root, CLUSTER_CF_PHASE2_DIR); + snprintf(malformed, sizeof(malformed), "%s/%s/ack.0.1.foreign", shared_root, + CLUSTER_CF_PHASE2_DIR); write_test_bytes(malformed, &marker, sizeof(marker)); UT_ASSERT(cluster_cf_phase2_write_probe(shared_root, 0, current_nonce)); - UT_ASSERT(cluster_cf_phase2_write_ack( - shared_root, 0, 1, current_nonce)); + UT_ASSERT(cluster_cf_phase2_write_ack(shared_root, 0, 1, current_nonce)); ack_path(current, 0, 1, current_nonce); UT_ASSERT(access(old_same_pair, F_OK) != 0); UT_ASSERT(access(current, F_OK) == 0); @@ -520,8 +507,7 @@ UT_TEST(test_delayed_old_cleanup_cannot_delete_later_current_ack) UT_ASSERT_EQ(kill(child, SIGCONT), 0); UT_ASSERT_EQ(waitpid(child, &status, 0), child); UT_ASSERT(WIFEXITED(status)); - UT_ASSERT(cluster_cf_phase2_read_exact_ack( - shared_root, 0, 1, new_nonce)); + UT_ASSERT(cluster_cf_phase2_read_exact_ack(shared_root, 0, 1, new_nonce)); } /* ====================================================================== @@ -540,8 +526,7 @@ UT_TEST(test_rendezvous_success) */ UT_ASSERT(cluster_cf_phase2_write_probe(shared_root, 1, UINT64CONST(0xAAAA0001BBBB0002))); UT_ASSERT(cluster_cf_phase2_write_probe(shared_root, 0, UINT64CONST(0xCCCC0003DDDD0004))); - UT_ASSERT(cluster_cf_phase2_write_ack( - shared_root, 0, 1, UINT64CONST(0xCCCC0003DDDD0004))); + UT_ASSERT(cluster_cf_phase2_write_ack(shared_root, 0, 1, UINT64CONST(0xCCCC0003DDDD0004))); UT_ASSERT( cluster_cf_phase2_rendezvous(shared_root, 0, 1, UINT64CONST(0xCCCC0003DDDD0004), 60000)); @@ -552,8 +537,8 @@ UT_TEST(test_rendezvous_success) UT_ASSERT(cluster_cf_phase2_read_probe(shared_root, 0, &probe)); UT_ASSERT_EQ(probe.probe_nonce, UINT64CONST(0xCCCC0003DDDD0004)); - UT_ASSERT(cluster_cf_phase2_read_exact_ack( - shared_root, 1, 0, UINT64CONST(0xAAAA0001BBBB0002))); + UT_ASSERT( + cluster_cf_phase2_read_exact_ack(shared_root, 1, 0, UINT64CONST(0xAAAA0001BBBB0002))); } } diff --git a/src/test/cluster_unit/test_cluster_clean_leave.c b/src/test/cluster_unit/test_cluster_clean_leave.c index 857a84aae5e..018a62571c3 100644 --- a/src/test/cluster_unit/test_cluster_clean_leave.c +++ b/src/test/cluster_unit/test_cluster_clean_leave.c @@ -451,30 +451,22 @@ UT_TEST(test_phase1_full_stop_probe_policy) plan.member_incarnations[3] = 104; UT_ASSERT(cluster_clean_leave_phase1_full_stop_plan_valid(&plan)); - UT_ASSERT(cluster_clean_leave_phase1_full_stop_probe_accepts( - CLUSTER_LEAVE_PRODUCER_SHUTDOWN, true, 2, 2, 0, 0, 51, - true, true)); + UT_ASSERT(cluster_clean_leave_phase1_full_stop_probe_accepts(CLUSTER_LEAVE_PRODUCER_SHUTDOWN, + true, 2, 2, 0, 0, 51, true, true)); UT_ASSERT(!cluster_clean_leave_phase1_full_stop_probe_accepts( - CLUSTER_LEAVE_PRODUCER_OPERATOR, true, 2, 2, 0, 0, 51, - true, true)); + CLUSTER_LEAVE_PRODUCER_OPERATOR, true, 2, 2, 0, 0, 51, true, true)); UT_ASSERT(!cluster_clean_leave_phase1_full_stop_probe_accepts( - CLUSTER_LEAVE_PRODUCER_SHUTDOWN, false, 2, 2, 0, 0, 51, - true, true)); + CLUSTER_LEAVE_PRODUCER_SHUTDOWN, false, 2, 2, 0, 0, 51, true, true)); UT_ASSERT(!cluster_clean_leave_phase1_full_stop_probe_accepts( - CLUSTER_LEAVE_PRODUCER_SHUTDOWN, true, 1, 2, 0, 0, 51, - true, true)); + CLUSTER_LEAVE_PRODUCER_SHUTDOWN, true, 1, 2, 0, 0, 51, true, true)); UT_ASSERT(!cluster_clean_leave_phase1_full_stop_probe_accepts( - CLUSTER_LEAVE_PRODUCER_SHUTDOWN, true, 2, 2, 0, 1, 51, - true, true)); - UT_ASSERT(!cluster_clean_leave_phase1_full_stop_probe_accepts( - CLUSTER_LEAVE_PRODUCER_SHUTDOWN, true, 2, 2, 0, 0, 0, - true, true)); + CLUSTER_LEAVE_PRODUCER_SHUTDOWN, true, 2, 2, 0, 1, 51, true, true)); + UT_ASSERT(!cluster_clean_leave_phase1_full_stop_probe_accepts(CLUSTER_LEAVE_PRODUCER_SHUTDOWN, + true, 2, 2, 0, 0, 0, true, true)); UT_ASSERT(!cluster_clean_leave_phase1_full_stop_probe_accepts( - CLUSTER_LEAVE_PRODUCER_SHUTDOWN, true, 2, 2, 0, 0, 51, - false, true)); + CLUSTER_LEAVE_PRODUCER_SHUTDOWN, true, 2, 2, 0, 0, 51, false, true)); UT_ASSERT(!cluster_clean_leave_phase1_full_stop_probe_accepts( - CLUSTER_LEAVE_PRODUCER_SHUTDOWN, true, 2, 2, 0, 0, 51, - true, false)); + CLUSTER_LEAVE_PRODUCER_SHUTDOWN, true, 2, 2, 0, 0, 51, true, false)); } UT_TEST(test_phase1_full_stop_probe_phase_policy) @@ -482,24 +474,16 @@ UT_TEST(test_phase1_full_stop_probe_phase_policy) /* The authenticated sender's existing WAL evidence distinguishes the two * same-wire rounds. A peer already in the post-STOPPED round must never * receive an ACK from a receiver which is still ACTIVE. */ - UT_ASSERT(cluster_clean_leave_phase1_full_stop_probe_phase_accepts( - true, false, true, false)); - UT_ASSERT(cluster_clean_leave_phase1_full_stop_probe_phase_accepts( - true, false, false, true)); - UT_ASSERT(!cluster_clean_leave_phase1_full_stop_probe_phase_accepts( - false, true, true, false)); - UT_ASSERT(cluster_clean_leave_phase1_full_stop_probe_phase_accepts( - false, true, false, true)); + UT_ASSERT(cluster_clean_leave_phase1_full_stop_probe_phase_accepts(true, false, true, false)); + UT_ASSERT(cluster_clean_leave_phase1_full_stop_probe_phase_accepts(true, false, false, true)); + UT_ASSERT(!cluster_clean_leave_phase1_full_stop_probe_phase_accepts(false, true, true, false)); + UT_ASSERT(cluster_clean_leave_phase1_full_stop_probe_phase_accepts(false, true, false, true)); /* Missing or contradictory source/local evidence is fail-closed. */ - UT_ASSERT(!cluster_clean_leave_phase1_full_stop_probe_phase_accepts( - false, false, true, false)); - UT_ASSERT(!cluster_clean_leave_phase1_full_stop_probe_phase_accepts( - true, true, true, false)); - UT_ASSERT(!cluster_clean_leave_phase1_full_stop_probe_phase_accepts( - true, false, false, false)); - UT_ASSERT(!cluster_clean_leave_phase1_full_stop_probe_phase_accepts( - true, false, true, true)); + UT_ASSERT(!cluster_clean_leave_phase1_full_stop_probe_phase_accepts(false, false, true, false)); + UT_ASSERT(!cluster_clean_leave_phase1_full_stop_probe_phase_accepts(true, true, true, false)); + UT_ASSERT(!cluster_clean_leave_phase1_full_stop_probe_phase_accepts(true, false, false, false)); + UT_ASSERT(!cluster_clean_leave_phase1_full_stop_probe_phase_accepts(true, false, true, true)); } UT_TEST(test_phase1_full_stop_post_stopped_request_ahead_consumption_policy) @@ -508,54 +492,44 @@ UT_TEST(test_phase1_full_stop_post_stopped_request_ahead_consumption_policy) * lifecycle edges. A peer request arriving in that narrow interval must * stay bound to the predecessor local nonce and become consumable after the * one legal nonce transition. */ - UT_ASSERT(cluster_clean_leave_phase1_full_stop_request_ahead_uses_predecessor_nonce( - true, false, false)); - UT_ASSERT(cluster_clean_leave_phase1_full_stop_request_ahead_uses_predecessor_nonce( - false, true, false)); + UT_ASSERT(cluster_clean_leave_phase1_full_stop_request_ahead_uses_predecessor_nonce(true, false, + false)); + UT_ASSERT(cluster_clean_leave_phase1_full_stop_request_ahead_uses_predecessor_nonce(false, true, + false)); UT_ASSERT(!cluster_clean_leave_phase1_full_stop_request_ahead_uses_predecessor_nonce( false, true, true)); UT_ASSERT(!cluster_clean_leave_phase1_full_stop_request_ahead_uses_predecessor_nonce( false, false, false)); - UT_ASSERT(!cluster_clean_leave_phase1_full_stop_request_ahead_uses_predecessor_nonce( - true, true, false)); + UT_ASSERT(!cluster_clean_leave_phase1_full_stop_request_ahead_uses_predecessor_nonce(true, true, + false)); /* A transport-consumed request which arrived while this receiver was still * ACTIVE remains owned by the receiver. It becomes consumable exactly once * after the same local attempt advances to STOPPED, dispatches its own peer * requests, and retains the original absolute deadline. */ UT_ASSERT(cluster_clean_leave_phase1_full_stop_request_ahead_can_consume( - true, true, 101, 9000, 102, 9000, - true, true, true, true)); + true, true, 101, 9000, 102, 9000, true, true, true, true)); /* A request retained after local STOPPED but before dispatch keeps the same * local round nonce rather than accepting another transition. */ UT_ASSERT(cluster_clean_leave_phase1_full_stop_request_ahead_can_consume( - true, false, 102, 9000, 102, 9000, - true, true, true, true)); + true, false, 102, 9000, 102, 9000, true, true, true, true)); UT_ASSERT(!cluster_clean_leave_phase1_full_stop_request_ahead_can_consume( - false, true, 101, 9000, 102, 9000, - true, true, true, true)); + false, true, 101, 9000, 102, 9000, true, true, true, true)); UT_ASSERT(!cluster_clean_leave_phase1_full_stop_request_ahead_can_consume( - true, true, 101, 9000, 101, 9000, - true, true, true, true)); + true, true, 101, 9000, 101, 9000, true, true, true, true)); UT_ASSERT(!cluster_clean_leave_phase1_full_stop_request_ahead_can_consume( - true, false, 102, 9000, 103, 9000, - true, true, true, true)); + true, false, 102, 9000, 103, 9000, true, true, true, true)); UT_ASSERT(!cluster_clean_leave_phase1_full_stop_request_ahead_can_consume( - true, true, 101, 9000, 102, 9001, - true, true, true, true)); + true, true, 101, 9000, 102, 9001, true, true, true, true)); UT_ASSERT(!cluster_clean_leave_phase1_full_stop_request_ahead_can_consume( - true, true, 101, 9000, 102, 9000, - false, true, true, true)); + true, true, 101, 9000, 102, 9000, false, true, true, true)); UT_ASSERT(!cluster_clean_leave_phase1_full_stop_request_ahead_can_consume( - true, true, 101, 9000, 102, 9000, - true, false, true, true)); + true, true, 101, 9000, 102, 9000, true, false, true, true)); UT_ASSERT(!cluster_clean_leave_phase1_full_stop_request_ahead_can_consume( - true, true, 101, 9000, 102, 9000, - true, true, false, true)); + true, true, 101, 9000, 102, 9000, true, true, false, true)); UT_ASSERT(!cluster_clean_leave_phase1_full_stop_request_ahead_can_consume( - true, true, 101, 9000, 102, 9000, - true, true, true, false)); + true, true, 101, 9000, 102, 9000, true, true, true, false)); } UT_TEST(test_phase1_full_stop_post_stopped_request_retains_per_peer_transport_ownership) @@ -572,31 +546,26 @@ UT_TEST(test_phase1_full_stop_post_stopped_request_retains_per_peer_transport_ow * exact local ownership bit until the current transport consumes the frame; * NOT_ADMITTED therefore leaves only that peer pending for an event-loop * retry under the original absolute deadline. */ - UT_ASSERT_NOT_NULL(strstr(clean_leave, - "phase1_post_stopped_request_sent")); - tick = strstr(clean_leave, - "\ncl_phase1_full_stop_post_stopped_request_lmon_tick("); + UT_ASSERT_NOT_NULL(strstr(clean_leave, "phase1_post_stopped_request_sent")); + tick = strstr(clean_leave, "\ncl_phase1_full_stop_post_stopped_request_lmon_tick("); UT_ASSERT_NOT_NULL(tick); if (tick == NULL) goto out; - tick_end = strstr(tick, - "\n}\n\nstatic void\ncl_phase1_full_stop_post_stopped_reply_lmon_tick("); + tick_end + = strstr(tick, "\n}\n\nstatic void\ncl_phase1_full_stop_post_stopped_reply_lmon_tick("); UT_ASSERT_NOT_NULL(tick_end); if (tick_end == NULL) goto out; - UT_ASSERT_NOT_NULL(find_in_order(tick, tick_end, - "phase1_post_stopped_request_sent")); - UT_ASSERT_NOT_NULL(find_in_order(tick, tick_end, - "cl_phase1_full_stop_capture_barrier_identity(")); - UT_ASSERT_NOT_NULL(find_in_order(tick, tick_end, - "local_wal_state != CLUSTER_WAL_SLOT_STATE_STOPPED")); - UT_ASSERT_NOT_NULL(find_in_order(tick, tick_end, - "cl_phase1_full_stop_send_post_stopped_request(")); - UT_ASSERT_NOT_NULL(find_in_order(tick, tick_end, - "CLUSTER_IC_SEND_NOT_ADMITTED")); + UT_ASSERT_NOT_NULL(find_in_order(tick, tick_end, "phase1_post_stopped_request_sent")); + UT_ASSERT_NOT_NULL( + find_in_order(tick, tick_end, "cl_phase1_full_stop_capture_barrier_identity(")); + UT_ASSERT_NOT_NULL( + find_in_order(tick, tick_end, "local_wal_state != CLUSTER_WAL_SLOT_STATE_STOPPED")); + UT_ASSERT_NOT_NULL( + find_in_order(tick, tick_end, "cl_phase1_full_stop_send_post_stopped_request(")); + UT_ASSERT_NOT_NULL(find_in_order(tick, tick_end, "CLUSTER_IC_SEND_NOT_ADMITTED")); UT_ASSERT(strstr(tick, "cluster_clean_leave_ic_broadcast_announce(") == NULL - || strstr(tick, "cluster_clean_leave_ic_broadcast_announce(") - >= tick_end); + || strstr(tick, "cluster_clean_leave_ic_broadcast_announce(") >= tick_end); out: free(clean_leave); } @@ -626,43 +595,44 @@ UT_TEST(test_phase1_full_stop_early_receiver_retains_semantic_ownership) /* DONE/WOULD_BLOCK has transferred the frame to this LMON. A valid peer * STOPPED request which is one stage ahead must enter the bounded exact * receiver slot; the handler may not silently return and discard it. */ - UT_ASSERT_NOT_NULL(find_in_order(handler, handler_end, - "cl_phase1_full_stop_retain_request_ahead_locked(")); - UT_ASSERT(strstr(handler, - "cl_phase1_member_bit_clear(\n\t\t\t\t\t\tcl_phase1_post_stopped_request_sent") == NULL - || strstr(handler, - "cl_phase1_member_bit_clear(\n\t\t\t\t\t\tcl_phase1_post_stopped_request_sent") - >= handler_end); - - consume = strstr(clean_leave, - "\ncl_phase1_full_stop_consume_request_ahead_lmon_tick("); + UT_ASSERT_NOT_NULL( + find_in_order(handler, handler_end, "cl_phase1_full_stop_retain_request_ahead_locked(")); + UT_ASSERT( + strstr(handler, + "cl_phase1_member_bit_clear(\n\t\t\t\t\t\tcl_phase1_post_stopped_request_sent") + == NULL + || strstr(handler, + "cl_phase1_member_bit_clear(\n\t\t\t\t\t\tcl_phase1_post_stopped_request_sent") + >= handler_end); + + consume = strstr(clean_leave, "\ncl_phase1_full_stop_consume_request_ahead_lmon_tick("); UT_ASSERT_NOT_NULL(consume); if (consume == NULL) goto out; - consume_end = strstr(consume, - "\n}\n\nstatic void\ncl_phase1_full_stop_post_stopped_reply_lmon_tick("); + consume_end + = strstr(consume, "\n}\n\nstatic void\ncl_phase1_full_stop_post_stopped_reply_lmon_tick("); UT_ASSERT_NOT_NULL(consume_end); if (consume_end == NULL) goto out; - UT_ASSERT_NOT_NULL(find_in_order(consume, consume_end, - "cl_phase1_full_stop_consume_request_ahead_locked(")); + UT_ASSERT_NOT_NULL( + find_in_order(consume, consume_end, "cl_phase1_full_stop_consume_request_ahead_locked(")); - consume_locked = strstr(clean_leave, - "\ncl_phase1_full_stop_consume_request_ahead_locked("); + consume_locked = strstr(clean_leave, "\ncl_phase1_full_stop_consume_request_ahead_locked("); UT_ASSERT_NOT_NULL(consume_locked); if (consume_locked == NULL) goto out; - consume_locked_end = strstr(consume_locked, - "\n}\n\n\nstatic void\ncl_phase1_full_stop_release("); + consume_locked_end + = strstr(consume_locked, "\n}\n\n\nstatic void\ncl_phase1_full_stop_release("); UT_ASSERT_NOT_NULL(consume_locked_end); if (consume_locked_end == NULL) goto out; - UT_ASSERT_NOT_NULL(find_in_order(consume_locked, consume_locked_end, - "cluster_clean_leave_phase1_full_stop_request_ahead_can_consume(")); - UT_ASSERT_NOT_NULL(find_in_order(consume_locked, consume_locked_end, - "phase1_post_stopped_reply_pending")); - UT_ASSERT_NOT_NULL(find_in_order(consume_locked, consume_locked_end, - "memset(ahead, 0, sizeof(*ahead))")); + UT_ASSERT_NOT_NULL( + find_in_order(consume_locked, consume_locked_end, + "cluster_clean_leave_phase1_full_stop_request_ahead_can_consume(")); + UT_ASSERT_NOT_NULL( + find_in_order(consume_locked, consume_locked_end, "phase1_post_stopped_reply_pending")); + UT_ASSERT_NOT_NULL( + find_in_order(consume_locked, consume_locked_end, "memset(ahead, 0, sizeof(*ahead))")); out: free(clean_leave); } @@ -675,52 +645,45 @@ UT_TEST(test_phase1_full_stop_post_stopped_receiver_requires_confirmed_local_rou * the existing post-STOPPED round. Once that round completes locally, the * exact receive window remains open through the bounded release phase so a * slower peer's same-round replay cannot be discarded. */ - UT_ASSERT(cluster_clean_leave_phase1_full_stop_post_stopped_receiver_ready( - true, true, true, true, true, false)); - UT_ASSERT(cluster_clean_leave_phase1_full_stop_post_stopped_receiver_ready( - true, true, true, false, true, true)); + UT_ASSERT(cluster_clean_leave_phase1_full_stop_post_stopped_receiver_ready(true, true, true, + true, true, false)); + UT_ASSERT(cluster_clean_leave_phase1_full_stop_post_stopped_receiver_ready(true, true, true, + false, true, true)); UT_ASSERT(!cluster_clean_leave_phase1_full_stop_post_stopped_receiver_ready( true, true, true, false, true, false)); UT_ASSERT(!cluster_clean_leave_phase1_full_stop_post_stopped_receiver_ready( true, true, true, true, false, false)); - UT_ASSERT(!cluster_clean_leave_phase1_full_stop_post_stopped_receiver_ready( - false, true, true, true, true, false)); - UT_ASSERT(!cluster_clean_leave_phase1_full_stop_post_stopped_receiver_ready( - true, false, true, true, true, false)); - UT_ASSERT(!cluster_clean_leave_phase1_full_stop_post_stopped_receiver_ready( - true, true, false, true, true, false)); + UT_ASSERT(!cluster_clean_leave_phase1_full_stop_post_stopped_receiver_ready(false, true, true, + true, true, false)); + UT_ASSERT(!cluster_clean_leave_phase1_full_stop_post_stopped_receiver_ready(true, false, true, + true, true, false)); + UT_ASSERT(!cluster_clean_leave_phase1_full_stop_post_stopped_receiver_ready(true, true, false, + true, true, false)); } UT_TEST(test_phase1_full_stop_release_probe_is_exact_and_phase1_only) { UT_ASSERT(cluster_clean_leave_phase1_full_stop_release_probe_accepts( - CLUSTER_LEAVE_PRODUCER_SHUTDOWN, - CLUSTER_PHASE1_FULL_STOP_WIRE_RELEASE, - 2, 2, 0, 0, 91, true, true, true)); + CLUSTER_LEAVE_PRODUCER_SHUTDOWN, CLUSTER_PHASE1_FULL_STOP_WIRE_RELEASE, 2, 2, 0, 0, 91, + true, true, true)); UT_ASSERT(!cluster_clean_leave_phase1_full_stop_release_probe_accepts( - CLUSTER_LEAVE_PRODUCER_OPERATOR, - CLUSTER_PHASE1_FULL_STOP_WIRE_RELEASE, - 2, 2, 0, 0, 91, true, true, true)); + CLUSTER_LEAVE_PRODUCER_OPERATOR, CLUSTER_PHASE1_FULL_STOP_WIRE_RELEASE, 2, 2, 0, 0, 91, + true, true, true)); UT_ASSERT(!cluster_clean_leave_phase1_full_stop_release_probe_accepts( - CLUSTER_LEAVE_PRODUCER_SHUTDOWN, - CLUSTER_PHASE1_FULL_STOP_WIRE_BARRIER, - 2, 2, 0, 0, 91, true, true, true)); + CLUSTER_LEAVE_PRODUCER_SHUTDOWN, CLUSTER_PHASE1_FULL_STOP_WIRE_BARRIER, 2, 2, 0, 0, 91, + true, true, true)); UT_ASSERT(!cluster_clean_leave_phase1_full_stop_release_probe_accepts( - CLUSTER_LEAVE_PRODUCER_SHUTDOWN, - CLUSTER_PHASE1_FULL_STOP_WIRE_RELEASE, - 1, 2, 0, 0, 91, true, true, true)); + CLUSTER_LEAVE_PRODUCER_SHUTDOWN, CLUSTER_PHASE1_FULL_STOP_WIRE_RELEASE, 1, 2, 0, 0, 91, + true, true, true)); UT_ASSERT(!cluster_clean_leave_phase1_full_stop_release_probe_accepts( - CLUSTER_LEAVE_PRODUCER_SHUTDOWN, - CLUSTER_PHASE1_FULL_STOP_WIRE_RELEASE, - 2, 2, 1, 0, 91, true, true, true)); + CLUSTER_LEAVE_PRODUCER_SHUTDOWN, CLUSTER_PHASE1_FULL_STOP_WIRE_RELEASE, 2, 2, 1, 0, 91, + true, true, true)); UT_ASSERT(!cluster_clean_leave_phase1_full_stop_release_probe_accepts( - CLUSTER_LEAVE_PRODUCER_SHUTDOWN, - CLUSTER_PHASE1_FULL_STOP_WIRE_RELEASE, - 2, 2, 0, 0, 0, true, true, true)); + CLUSTER_LEAVE_PRODUCER_SHUTDOWN, CLUSTER_PHASE1_FULL_STOP_WIRE_RELEASE, 2, 2, 0, 0, 0, true, + true, true)); UT_ASSERT(!cluster_clean_leave_phase1_full_stop_release_probe_accepts( - CLUSTER_LEAVE_PRODUCER_SHUTDOWN, - CLUSTER_PHASE1_FULL_STOP_WIRE_RELEASE, - 2, 2, 0, 0, 91, false, true, true)); + CLUSTER_LEAVE_PRODUCER_SHUTDOWN, CLUSTER_PHASE1_FULL_STOP_WIRE_RELEASE, 2, 2, 0, 0, 91, + false, true, true)); } UT_TEST(test_phase1_full_stop_exact_receipt_may_precede_local_reply_publication) @@ -729,33 +692,25 @@ UT_TEST(test_phase1_full_stop_exact_receipt_may_precede_local_reply_publication) * sender's local reply_sent publication may lag that cross-process fact; * final completion still checks reply_sent independently. */ UT_ASSERT(cluster_clean_leave_phase1_full_stop_receipt_accepts( - CLUSTER_LEAVE_PRODUCER_SHUTDOWN, - CLUSTER_PHASE1_FULL_STOP_WIRE_RECEIPT, - true, 91, 91, true)); + CLUSTER_LEAVE_PRODUCER_SHUTDOWN, CLUSTER_PHASE1_FULL_STOP_WIRE_RECEIPT, true, 91, 91, + true)); UT_ASSERT(!cluster_clean_leave_phase1_full_stop_receipt_accepts( - CLUSTER_LEAVE_PRODUCER_OPERATOR, - CLUSTER_PHASE1_FULL_STOP_WIRE_RECEIPT, - true, 91, 91, true)); + CLUSTER_LEAVE_PRODUCER_OPERATOR, CLUSTER_PHASE1_FULL_STOP_WIRE_RECEIPT, true, 91, 91, + true)); UT_ASSERT(!cluster_clean_leave_phase1_full_stop_receipt_accepts( - CLUSTER_LEAVE_PRODUCER_SHUTDOWN, - CLUSTER_PHASE1_FULL_STOP_WIRE_RELEASE, - true, 91, 91, true)); + CLUSTER_LEAVE_PRODUCER_SHUTDOWN, CLUSTER_PHASE1_FULL_STOP_WIRE_RELEASE, true, 91, 91, + true)); UT_ASSERT(!cluster_clean_leave_phase1_full_stop_receipt_accepts( - CLUSTER_LEAVE_PRODUCER_SHUTDOWN, - CLUSTER_PHASE1_FULL_STOP_WIRE_RECEIPT, - false, 91, 91, true)); + CLUSTER_LEAVE_PRODUCER_SHUTDOWN, CLUSTER_PHASE1_FULL_STOP_WIRE_RECEIPT, false, 91, 91, + true)); UT_ASSERT(!cluster_clean_leave_phase1_full_stop_receipt_accepts( - CLUSTER_LEAVE_PRODUCER_SHUTDOWN, - CLUSTER_PHASE1_FULL_STOP_WIRE_RECEIPT, - true, 0, 91, true)); + CLUSTER_LEAVE_PRODUCER_SHUTDOWN, CLUSTER_PHASE1_FULL_STOP_WIRE_RECEIPT, true, 0, 91, true)); UT_ASSERT(!cluster_clean_leave_phase1_full_stop_receipt_accepts( - CLUSTER_LEAVE_PRODUCER_SHUTDOWN, - CLUSTER_PHASE1_FULL_STOP_WIRE_RECEIPT, - true, 90, 91, true)); + CLUSTER_LEAVE_PRODUCER_SHUTDOWN, CLUSTER_PHASE1_FULL_STOP_WIRE_RECEIPT, true, 90, 91, + true)); UT_ASSERT(!cluster_clean_leave_phase1_full_stop_receipt_accepts( - CLUSTER_LEAVE_PRODUCER_SHUTDOWN, - CLUSTER_PHASE1_FULL_STOP_WIRE_RECEIPT, - true, 91, 91, false)); + CLUSTER_LEAVE_PRODUCER_SHUTDOWN, CLUSTER_PHASE1_FULL_STOP_WIRE_RECEIPT, true, 91, 91, + false)); } UT_TEST(test_phase1_full_stop_release_completion_requires_four_way_delivery) @@ -778,32 +733,32 @@ UT_TEST(test_phase1_full_stop_release_completion_requires_four_way_delivery) plan.member_incarnations[1] = 102; plan.member_incarnations[2] = 103; plan.member_incarnations[3] = 104; - request_sent[0] = request_seen[0] = reply_sent[0] = reply_seen[0] - = receipt_sent[0] = receipt_seen[0] = 0x0e; + request_sent[0] = request_seen[0] = reply_sent[0] = reply_seen[0] = receipt_sent[0] + = receipt_seen[0] = 0x0e; UT_ASSERT(cluster_clean_leave_phase1_full_stop_release_complete( - &plan, 0, request_sent, request_seen, reply_sent, reply_seen, - receipt_sent, receipt_seen, sizeof(request_sent), true)); + &plan, 0, request_sent, request_seen, reply_sent, reply_seen, receipt_sent, receipt_seen, + sizeof(request_sent), true)); request_seen[0] = 0x06; UT_ASSERT(!cluster_clean_leave_phase1_full_stop_release_complete( - &plan, 0, request_sent, request_seen, reply_sent, reply_seen, - receipt_sent, receipt_seen, sizeof(request_sent), true)); + &plan, 0, request_sent, request_seen, reply_sent, reply_seen, receipt_sent, receipt_seen, + sizeof(request_sent), true)); request_seen[0] = 0x0e; reply_sent[0] = 0x06; UT_ASSERT(!cluster_clean_leave_phase1_full_stop_release_complete( - &plan, 0, request_sent, request_seen, reply_sent, reply_seen, - receipt_sent, receipt_seen, sizeof(request_sent), true)); + &plan, 0, request_sent, request_seen, reply_sent, reply_seen, receipt_sent, receipt_seen, + sizeof(request_sent), true)); reply_sent[0] = 0x0e; receipt_seen[0] = 0x06; /* Local egress drain is not evidence that every peer consumed our final * release reply. Exact per-peer receipts are mandatory. */ UT_ASSERT(!cluster_clean_leave_phase1_full_stop_release_complete( - &plan, 0, request_sent, request_seen, reply_sent, reply_seen, - receipt_sent, receipt_seen, sizeof(request_sent), true)); + &plan, 0, request_sent, request_seen, reply_sent, reply_seen, receipt_sent, receipt_seen, + sizeof(request_sent), true)); receipt_seen[0] = 0x0e; UT_ASSERT(!cluster_clean_leave_phase1_full_stop_release_complete( - &plan, 0, request_sent, request_seen, reply_sent, reply_seen, - receipt_sent, receipt_seen, sizeof(request_sent), false)); + &plan, 0, request_sent, request_seen, reply_sent, reply_seen, receipt_sent, receipt_seen, + sizeof(request_sent), false)); } UT_TEST(test_phase1_full_stop_exact_ack_barrier) @@ -822,24 +777,20 @@ UT_TEST(test_phase1_full_stop_exact_ack_barrier) plan.member_incarnations[2] = 103; plan.member_incarnations[3] = 104; - UT_ASSERT(cluster_clean_leave_phase1_full_stop_ack_matches( - &plan, 0, 2, 2, 0, 0, 61, 103)); - UT_ASSERT(!cluster_clean_leave_phase1_full_stop_ack_matches( - &plan, 0, 1, 2, 0, 0, 61, 103)); - UT_ASSERT(!cluster_clean_leave_phase1_full_stop_ack_matches( - &plan, 0, 2, 2, 0, 0, 60, 103)); - UT_ASSERT(!cluster_clean_leave_phase1_full_stop_ack_matches( - &plan, 0, 2, 2, 0, 0, 61, 999)); + UT_ASSERT(cluster_clean_leave_phase1_full_stop_ack_matches(&plan, 0, 2, 2, 0, 0, 61, 103)); + UT_ASSERT(!cluster_clean_leave_phase1_full_stop_ack_matches(&plan, 0, 1, 2, 0, 0, 61, 103)); + UT_ASSERT(!cluster_clean_leave_phase1_full_stop_ack_matches(&plan, 0, 2, 2, 0, 0, 60, 103)); + UT_ASSERT(!cluster_clean_leave_phase1_full_stop_ack_matches(&plan, 0, 2, 2, 0, 0, 61, 999)); ack_bitmap[0] = 0x0e; /* exact peers 1,2,3 for self node 0 */ - UT_ASSERT(cluster_clean_leave_phase1_full_stop_ack_complete( - &plan, 0, ack_bitmap, sizeof(ack_bitmap))); + UT_ASSERT(cluster_clean_leave_phase1_full_stop_ack_complete(&plan, 0, ack_bitmap, + sizeof(ack_bitmap))); ack_bitmap[0] = 0x06; - UT_ASSERT(!cluster_clean_leave_phase1_full_stop_ack_complete( - &plan, 0, ack_bitmap, sizeof(ack_bitmap))); + UT_ASSERT(!cluster_clean_leave_phase1_full_stop_ack_complete(&plan, 0, ack_bitmap, + sizeof(ack_bitmap))); ack_bitmap[0] = 0x1e; /* an out-of-contract fifth member/ACK is a drift */ - UT_ASSERT(!cluster_clean_leave_phase1_full_stop_ack_complete( - &plan, 0, ack_bitmap, sizeof(ack_bitmap))); + UT_ASSERT(!cluster_clean_leave_phase1_full_stop_ack_complete(&plan, 0, ack_bitmap, + sizeof(ack_bitmap))); } UT_TEST(test_phase1_full_stop_barrier_waits_for_local_positive_ack_fanout) @@ -851,15 +802,15 @@ UT_TEST(test_phase1_full_stop_barrier_waits_for_local_positive_ack_fanout) UT_ASSERT_NOT_NULL(clean_leave); if (clean_leave == NULL) return; - barrier = strstr(clean_leave, - "\ncl_phase1_full_stop_post_stopped_barrier("); + barrier = strstr(clean_leave, "\ncl_phase1_full_stop_post_stopped_barrier("); UT_ASSERT_NOT_NULL(barrier); - barrier_end = barrier == NULL ? NULL : strstr(barrier, - "\n}\n\nstatic bool\ncl_phase1_full_stop_release_completion("); + barrier_end + = barrier == NULL + ? NULL + : strstr(barrier, "\n}\n\nstatic bool\ncl_phase1_full_stop_release_completion("); UT_ASSERT_NOT_NULL(barrier_end); if (barrier != NULL && barrier_end != NULL) - UT_ASSERT_NOT_NULL(find_in_order(barrier, barrier_end, - "phase1_post_stopped_reply_sent")); + UT_ASSERT_NOT_NULL(find_in_order(barrier, barrier_end, "phase1_post_stopped_reply_sent")); free(clean_leave); } @@ -868,29 +819,27 @@ UT_TEST(test_phase1_full_stop_post_stopped_nonce_is_fresh) UT_ASSERT(cluster_clean_leave_phase1_full_stop_nonce_fresh(61, 62)); UT_ASSERT(!cluster_clean_leave_phase1_full_stop_nonce_fresh(61, 61)); UT_ASSERT(!cluster_clean_leave_phase1_full_stop_nonce_fresh(61, 0)); - UT_ASSERT(!cluster_clean_leave_phase1_full_stop_nonce_fresh( - 61, UINT64_MAX)); + UT_ASSERT(!cluster_clean_leave_phase1_full_stop_nonce_fresh(61, UINT64_MAX)); UT_ASSERT(!cluster_clean_leave_phase1_full_stop_nonce_fresh(0, 62)); - UT_ASSERT(!cluster_clean_leave_phase1_full_stop_nonce_fresh( - UINT64_MAX, 62)); + UT_ASSERT(!cluster_clean_leave_phase1_full_stop_nonce_fresh(UINT64_MAX, 62)); } UT_TEST(test_phase1_full_stop_two_round_nonce_lineage_is_closed) { - UT_ASSERT_EQ(cluster_clean_leave_phase1_full_stop_probe_nonce_decide( - 11, 0, 11), CLUSTER_PHASE1_PROBE_NONCE_STALE_ACTIVE); - UT_ASSERT_EQ(cluster_clean_leave_phase1_full_stop_probe_nonce_decide( - 11, 0, 12), CLUSTER_PHASE1_PROBE_NONCE_ACCEPT_STOPPED); - UT_ASSERT_EQ(cluster_clean_leave_phase1_full_stop_probe_nonce_decide( - 11, 12, 12), CLUSTER_PHASE1_PROBE_NONCE_DUPLICATE_STOPPED); - UT_ASSERT_EQ(cluster_clean_leave_phase1_full_stop_probe_nonce_decide( - 11, 12, 11), CLUSTER_PHASE1_PROBE_NONCE_STALE_ACTIVE); - UT_ASSERT_EQ(cluster_clean_leave_phase1_full_stop_probe_nonce_decide( - 11, 12, 13), CLUSTER_PHASE1_PROBE_NONCE_CONFLICT); - UT_ASSERT_EQ(cluster_clean_leave_phase1_full_stop_probe_nonce_decide( - 0, 0, 12), CLUSTER_PHASE1_PROBE_NONCE_CONFLICT); - UT_ASSERT_EQ(cluster_clean_leave_phase1_full_stop_probe_nonce_decide( - 11, 0, UINT64_MAX), CLUSTER_PHASE1_PROBE_NONCE_CONFLICT); + UT_ASSERT_EQ(cluster_clean_leave_phase1_full_stop_probe_nonce_decide(11, 0, 11), + CLUSTER_PHASE1_PROBE_NONCE_STALE_ACTIVE); + UT_ASSERT_EQ(cluster_clean_leave_phase1_full_stop_probe_nonce_decide(11, 0, 12), + CLUSTER_PHASE1_PROBE_NONCE_ACCEPT_STOPPED); + UT_ASSERT_EQ(cluster_clean_leave_phase1_full_stop_probe_nonce_decide(11, 12, 12), + CLUSTER_PHASE1_PROBE_NONCE_DUPLICATE_STOPPED); + UT_ASSERT_EQ(cluster_clean_leave_phase1_full_stop_probe_nonce_decide(11, 12, 11), + CLUSTER_PHASE1_PROBE_NONCE_STALE_ACTIVE); + UT_ASSERT_EQ(cluster_clean_leave_phase1_full_stop_probe_nonce_decide(11, 12, 13), + CLUSTER_PHASE1_PROBE_NONCE_CONFLICT); + UT_ASSERT_EQ(cluster_clean_leave_phase1_full_stop_probe_nonce_decide(0, 0, 12), + CLUSTER_PHASE1_PROBE_NONCE_CONFLICT); + UT_ASSERT_EQ(cluster_clean_leave_phase1_full_stop_probe_nonce_decide(11, 0, UINT64_MAX), + CLUSTER_PHASE1_PROBE_NONCE_CONFLICT); } UT_TEST(test_phase1_full_stop_prepare_disposition_is_closed) @@ -922,8 +871,8 @@ UT_TEST(test_phase1_full_stop_pgstat_follower_uses_existing_aux_hook) UT_ASSERT_NOT_NULL(aux_hook_end); if (aux_hook == NULL || aux_hook_end == NULL) goto out; - UT_ASSERT(find_in_order(aux_hook, aux_hook_end, - "pgstat_prepare_for_server_shutdown_follower()") != NULL); + UT_ASSERT(find_in_order(aux_hook, aux_hook_end, "pgstat_prepare_for_server_shutdown_follower()") + != NULL); pgstat_hook = strstr(pgstat, "\npgstat_shutdown_hook("); pgstat_hook_end = pgstat_hook == NULL ? NULL : strstr(pgstat_hook, "\n}"); @@ -931,15 +880,12 @@ UT_TEST(test_phase1_full_stop_pgstat_follower_uses_existing_aux_hook) UT_ASSERT_NOT_NULL(pgstat_hook_end); if (pgstat_hook == NULL || pgstat_hook_end == NULL) goto out; - follower = find_in_order(pgstat_hook, pgstat_hook_end, - "pgstat_server_shutdown_follower"); - report = find_in_order(pgstat_hook, pgstat_hook_end, - "pgstat_report_stat(true)"); + follower = find_in_order(pgstat_hook, pgstat_hook_end, "pgstat_server_shutdown_follower"); + report = find_in_order(pgstat_hook, pgstat_hook_end, "pgstat_report_stat(true)"); UT_ASSERT_NOT_NULL(follower); UT_ASSERT_NOT_NULL(report); UT_ASSERT(follower != NULL && report != NULL && follower < report); - UT_ASSERT_NOT_NULL(strstr(pgstat, - "pgstat_prepare_for_server_shutdown_follower(void)")); + UT_ASSERT_NOT_NULL(strstr(pgstat, "pgstat_prepare_for_server_shutdown_follower(void)")); out: free(auxprocess); free(pgstat); @@ -983,14 +929,14 @@ UT_TEST(test_phase1_full_stop_runtime_order_and_no_polling) if (shutdown == NULL || shutdown_end == NULL) goto out; prepare = find_in_order(shutdown, shutdown_end, - "cluster_clean_leave_phase1_full_stop_prepare_exact("); + "cluster_clean_leave_phase1_full_stop_prepare_exact("); if (prepare == NULL) goto out; prepare = find_in_order(prepare, shutdown_end, "&phase1_full_stop_plan"); if (prepare == NULL) goto out; - prepare_failed = find_in_order(prepare, shutdown_end, - "CLUSTER_PHASE1_FULL_STOP_ATTEMPT_FAILED"); + prepare_failed + = find_in_order(prepare, shutdown_end, "CLUSTER_PHASE1_FULL_STOP_ATTEMPT_FAILED"); if (prepare_failed == NULL) goto out; fail_closed = find_in_order(prepare_failed, shutdown_end, "ereport(PANIC"); @@ -1000,129 +946,110 @@ UT_TEST(test_phase1_full_stop_runtime_order_and_no_polling) if (prepare == NULL) goto out; stopped = find_in_order(prepare, shutdown_end, - "wal_stopped_ok = cluster_wal_state_publish_stopped()"); + "wal_stopped_ok = cluster_wal_state_publish_stopped()"); if (stopped == NULL) goto out; - stopped_failure = find_in_order(stopped, shutdown_end, - "if (!wal_stopped_ok"); + stopped_failure = find_in_order(stopped, shutdown_end, "if (!wal_stopped_ok"); if (stopped_failure == NULL) goto out; - stopped_failure = find_in_order(stopped_failure, shutdown_end, - "ereport(PANIC"); + stopped_failure = find_in_order(stopped_failure, shutdown_end, "ereport(PANIC"); if (stopped_failure == NULL) goto out; - stopped_failure = find_in_order(stopped_failure, shutdown_end, - "WAL STOPPED publication failed"); + stopped_failure + = find_in_order(stopped_failure, shutdown_end, "WAL STOPPED publication failed"); if (stopped_failure == NULL) goto out; - stopped_success = find_in_order(stopped, shutdown_end, - "WAL STOPPED published"); + stopped_success = find_in_order(stopped, shutdown_end, "WAL STOPPED published"); if (stopped_success == NULL) goto out; close = find_in_order(stopped_success, shutdown_end, - "cluster_clean_leave_phase1_full_stop_close_exact("); + "cluster_clean_leave_phase1_full_stop_close_exact("); if (close == NULL) goto out; close = find_in_order(close, shutdown_end, "&phase1_full_stop_plan"); if (close == NULL) goto out; - close_failure = find_in_order(close, shutdown_end, - "if (!clean_handoff_ok"); + close_failure = find_in_order(close, shutdown_end, "if (!clean_handoff_ok"); if (close_failure == NULL) goto out; - close_failure = find_in_order(close_failure, shutdown_end, - "ereport(PANIC"); + close_failure = find_in_order(close_failure, shutdown_end, "ereport(PANIC"); if (close_failure == NULL) goto out; - close_failure = find_in_order(close_failure, shutdown_end, - "post-STOPPED ACK barrier failed"); + close_failure = find_in_order(close_failure, shutdown_end, "post-STOPPED ACK barrier failed"); if (close_failure == NULL) goto out; - close_success = find_in_order(close, shutdown_end, - "exact four-member ACK barrier complete"); + close_success = find_in_order(close, shutdown_end, "exact four-member ACK barrier complete"); if (close_success == NULL) goto out; - release_success = find_in_order(close_success, shutdown_end, - "release/completion complete"); + release_success = find_in_order(close_success, shutdown_end, "release/completion complete"); UT_ASSERT_NOT_NULL(release_success); - post_stopped = strstr(clean_leave, - "\ncl_phase1_full_stop_post_stopped_barrier("); + post_stopped = strstr(clean_leave, "\ncl_phase1_full_stop_post_stopped_barrier("); UT_ASSERT_NOT_NULL(post_stopped); if (post_stopped == NULL) goto out; - post_stopped_end = strstr(post_stopped, - "\n}\n\nbool\ncluster_clean_leave_phase1_full_stop_close_exact("); + post_stopped_end + = strstr(post_stopped, "\n}\n\nbool\ncluster_clean_leave_phase1_full_stop_close_exact("); UT_ASSERT_NOT_NULL(post_stopped_end); if (post_stopped_end == NULL) goto out; UT_ASSERT_NOT_NULL(strstr(post_stopped, "CLUSTER_WAL_SLOT_STATE_STOPPED")); - UT_ASSERT_NOT_NULL(strstr(post_stopped, - "cl_phase1_full_stop_identity_matches(")); + UT_ASSERT_NOT_NULL(strstr(post_stopped, "cl_phase1_full_stop_identity_matches(")); UT_ASSERT_NOT_NULL(strstr(post_stopped, "plan->absolute_deadline_us")); UT_ASSERT_NOT_NULL(strstr(post_stopped, "WaitLatch(")); - UT_ASSERT_NOT_NULL(strstr(post_stopped, - "failure-domain stage=post-STOPPED")); + UT_ASSERT_NOT_NULL(strstr(post_stopped, "failure-domain stage=post-STOPPED")); UT_ASSERT(strstr(post_stopped, "pg_usleep(") == NULL || strstr(post_stopped, "pg_usleep(") >= post_stopped_end); - UT_ASSERT_NOT_NULL(strstr(clean_leave, - "cl_phase1_full_stop_retain_request_ahead_locked(")); - UT_ASSERT_NOT_NULL(strstr(clean_leave, - "cl_phase1_full_stop_consume_request_ahead_lmon_tick(")); - UT_ASSERT_NOT_NULL(strstr(clean_leave, - "cluster_clean_leave_phase1_full_stop_post_stopped_receiver_ready(")); - UT_ASSERT_NOT_NULL(strstr(clean_leave, - "phase1_post_stopped_reply_pending")); - UT_ASSERT_NOT_NULL(strstr(clean_leave, - "cl_phase1_full_stop_send_post_stopped_reply(")); - UT_ASSERT_NOT_NULL(strstr(clean_leave, - "CLUSTER_IC_SEND_NOT_ADMITTED")); - release_completion = strstr(clean_leave, - "\ncl_phase1_full_stop_release_completion("); - release_completion_end = release_completion == NULL ? NULL - : strstr(release_completion, - "\n}\n\nbool\ncluster_clean_leave_phase1_full_stop_close_exact("); + UT_ASSERT_NOT_NULL(strstr(clean_leave, "cl_phase1_full_stop_retain_request_ahead_locked(")); + UT_ASSERT_NOT_NULL(strstr(clean_leave, "cl_phase1_full_stop_consume_request_ahead_lmon_tick(")); + UT_ASSERT_NOT_NULL( + strstr(clean_leave, "cluster_clean_leave_phase1_full_stop_post_stopped_receiver_ready(")); + UT_ASSERT_NOT_NULL(strstr(clean_leave, "phase1_post_stopped_reply_pending")); + UT_ASSERT_NOT_NULL(strstr(clean_leave, "cl_phase1_full_stop_send_post_stopped_reply(")); + UT_ASSERT_NOT_NULL(strstr(clean_leave, "CLUSTER_IC_SEND_NOT_ADMITTED")); + release_completion = strstr(clean_leave, "\ncl_phase1_full_stop_release_completion("); + release_completion_end + = release_completion == NULL + ? NULL + : strstr(release_completion, + "\n}\n\nbool\ncluster_clean_leave_phase1_full_stop_close_exact("); UT_ASSERT_NOT_NULL(release_completion); UT_ASSERT_NOT_NULL(release_completion_end); if (release_completion != NULL && release_completion_end != NULL) { - UT_ASSERT_NOT_NULL(strstr(release_completion, - "plan->absolute_deadline_us")); - UT_ASSERT_NOT_NULL(strstr(release_completion, - "phase1_release_receipt_seen")); - UT_ASSERT_NOT_NULL(strstr(release_completion, - "failure-domain stage=release-completion")); + UT_ASSERT_NOT_NULL(strstr(release_completion, "plan->absolute_deadline_us")); + UT_ASSERT_NOT_NULL(strstr(release_completion, "phase1_release_receipt_seen")); + UT_ASSERT_NOT_NULL(strstr(release_completion, "failure-domain stage=release-completion")); UT_ASSERT_NOT_NULL(strstr(release_completion, "WaitLatch(")); UT_ASSERT(strstr(release_completion, "pg_usleep(") == NULL - || strstr(release_completion, "pg_usleep(") - >= release_completion_end); + || strstr(release_completion, "pg_usleep(") >= release_completion_end); } - close_body = strstr(clean_leave, - "\ncluster_clean_leave_phase1_full_stop_close_exact("); - close_end = close_body == NULL ? NULL : strstr(close_body, - "\n}\n\n/*\n * cluster_clean_leave_drive_drain"); + close_body = strstr(clean_leave, "\ncluster_clean_leave_phase1_full_stop_close_exact("); + close_end = close_body == NULL + ? NULL + : strstr(close_body, "\n}\n\n/*\n * cluster_clean_leave_drive_drain"); UT_ASSERT_NOT_NULL(close_body); UT_ASSERT_NOT_NULL(close_end); if (close_body == NULL || close_end == NULL) goto out; - UT_ASSERT(strstr(close_body, - "cluster_control_root_thread_clean_close_publish(") == NULL - || strstr(close_body, - "cluster_control_root_thread_clean_close_publish(") >= close_end); - post_stopped = find_in_order(close_body, close_end, - "cl_phase1_full_stop_post_stopped_barrier(plan)"); + UT_ASSERT(strstr(close_body, "cluster_control_root_thread_clean_close_publish(") == NULL + || strstr(close_body, "cluster_control_root_thread_clean_close_publish(") + >= close_end); + post_stopped + = find_in_order(close_body, close_end, "cl_phase1_full_stop_post_stopped_barrier(plan)"); UT_ASSERT_NOT_NULL(post_stopped); - release_completion = post_stopped == NULL ? NULL - : find_in_order(post_stopped, close_end, - "cl_phase1_full_stop_release_completion(plan)"); + release_completion = post_stopped == NULL + ? NULL + : find_in_order(post_stopped, close_end, + "cl_phase1_full_stop_release_completion(plan)"); UT_ASSERT_NOT_NULL(release_completion); - UT_ASSERT_NOT_NULL(strstr(clean_leave, - "CLUSTER_PHASE1_FULL_STOP_WIRE_RECEIPT")); + UT_ASSERT_NOT_NULL(strstr(clean_leave, "CLUSTER_PHASE1_FULL_STOP_WIRE_RECEIPT")); legacy = find_in_order(close, shutdown_end, "cluster_clean_leave_shutdown_drain()"); UT_ASSERT_NOT_NULL(legacy); - prepare_body = strstr(clean_leave, - "\ncluster_clean_leave_phase1_full_stop_prepare_exact("); - prepare_end = prepare_body == NULL ? NULL : strstr(prepare_body, - "\n}\n\nbool\ncluster_clean_leave_phase1_full_stop_close_exact("); + prepare_body = strstr(clean_leave, "\ncluster_clean_leave_phase1_full_stop_prepare_exact("); + prepare_end = prepare_body == NULL + ? NULL + : strstr(prepare_body, + "\n}\n\nbool\ncluster_clean_leave_phase1_full_stop_close_exact("); UT_ASSERT_NOT_NULL(prepare_body); UT_ASSERT_NOT_NULL(prepare_end); if (prepare_body == NULL || prepare_end == NULL) @@ -1157,20 +1084,16 @@ UT_TEST(test_phase1_full_stop_retains_coordination_without_r4_admission) return; shutdown = strstr(postmaster, "if (pmState == PM_STOP_BACKENDS)"); - shutdown_end = shutdown == NULL ? NULL - : strstr(shutdown, "pmState = PM_WAIT_BACKENDS;"); + shutdown_end = shutdown == NULL ? NULL : strstr(shutdown, "pmState = PM_WAIT_BACKENDS;"); UT_ASSERT_NOT_NULL(shutdown); UT_ASSERT_NOT_NULL(shutdown_end); if (shutdown == NULL || shutdown_end == NULL) goto out; - rf_admission = find_in_order(shutdown, shutdown_end, - "cluster_registry_holds_admission()"); + rf_admission = find_in_order(shutdown, shutdown_end, "cluster_registry_holds_admission()"); phase1_candidate = find_in_order(rf_admission, shutdown_end, - "cluster_clean_leave_phase1_full_stop_candidate()"); - combined = find_in_order(phase1_candidate, shutdown_end, - "retain_shutdown_coordination"); - stop_coordination = find_in_order(combined, shutdown_end, - "if (!retain_shutdown_coordination)"); + "cluster_clean_leave_phase1_full_stop_candidate()"); + combined = find_in_order(phase1_candidate, shutdown_end, "retain_shutdown_coordination"); + stop_coordination = find_in_order(combined, shutdown_end, "if (!retain_shutdown_coordination)"); suppress = find_in_order(stop_coordination, shutdown_end, "if (!retain_normal_stop && retain_shutdown_coordination && LmonPID != 0)"); @@ -1180,14 +1103,14 @@ UT_TEST(test_phase1_full_stop_retains_coordination_without_r4_admission) * exercised in test_cluster_postmaster_stop, not inferred from text. */ wait_backends = strstr(shutdown_end, "if (pmState == PM_WAIT_BACKENDS)"); - wait_backends_end = wait_backends == NULL ? NULL - : strstr(wait_backends, "if (pmState == PM_SHUTDOWN_2)"); + wait_backends_end + = wait_backends == NULL ? NULL : strstr(wait_backends, "if (pmState == PM_SHUTDOWN_2)"); UT_ASSERT_NOT_NULL(wait_backends); UT_ASSERT_NOT_NULL(wait_backends_end); if (wait_backends == NULL || wait_backends_end == NULL) goto out; - UT_ASSERT_NOT_NULL(find_in_order(wait_backends, wait_backends_end, - "cluster_lmon_reconfig_suppressed()")); + UT_ASSERT_NOT_NULL( + find_in_order(wait_backends, wait_backends_end, "cluster_lmon_reconfig_suppressed()")); out: free(postmaster); } diff --git a/src/test/cluster_unit/test_cluster_control_root.c b/src/test/cluster_unit/test_cluster_control_root.c index 48770773e1f..4fd902dccf9 100644 --- a/src/test/cluster_unit/test_cluster_control_root.c +++ b/src/test/cluster_unit/test_cluster_control_root.c @@ -46,7 +46,7 @@ * fixture uses the default 16MiB segment size (segment 1 covers * [0x1000000, 0x2000000) — the build_source_wal_state fixture's * checkpoint LSN 0x1000000 therefore lives in segment 1). */ -int wal_segment_size = XLOG_BLCKSZ * 2048; +int wal_segment_size = XLOG_BLCKSZ * 2048; UT_DEFINE_GLOBALS(); @@ -61,8 +61,7 @@ int cluster_node_id = 0; static char test_root[MAXPGPATH]; static char test_wal_root[MAXPGPATH]; static uint64 test_system_identifier = TEST_SYSID; -static char test_storage_uuid_text[33] = - "00112233445566778899aabbccddeeff"; +static char test_storage_uuid_text[33] = "00112233445566778899aabbccddeeff"; static ClusterCfContractState test_contract = CLUSTER_CF_CONTRACT_CROSSNODE_VERIFIED; static int test_node_count = 4; static bool test_local_probe = true; @@ -92,8 +91,7 @@ static int test_qvotec_bootstrap_calls; static bool test_activate_authorized = true; static bool test_publish_authorized = true; static ClusterWalPinResult test_walr_begin_result = CLUSTER_WAL_PIN_OK; -static ClusterWalrReleaseResult test_walr_end_result = - CLUSTER_WALR_RELEASE_CONFIRMED; +static ClusterWalrReleaseResult test_walr_end_result = CLUSTER_WALR_RELEASE_CONFIRMED; static int test_walr_begin_calls = 0; static int test_walr_end_calls = 0; static uint16 test_walr_thread = 0; @@ -106,11 +104,12 @@ static TimestampTz test_now = INT64_C(1700000000000000); typedef struct ClusterWalRootPublishGuard ClusterWalRootPublishGuard; -extern ClusterWalPinResult cluster_wal_retention_root_publish_begin_exact( - const ClusterControlRootReadToken *expected_root, bool require_sealed_pin, - ClusterWalRootPublishGuard **out_guard); -extern ClusterWalrReleaseResult cluster_wal_retention_root_publish_end( - ClusterWalRootPublishGuard **guard); +extern ClusterWalPinResult +cluster_wal_retention_root_publish_begin_exact(const ClusterControlRootReadToken *expected_root, + bool require_sealed_pin, + ClusterWalRootPublishGuard **out_guard); +extern ClusterWalrReleaseResult +cluster_wal_retention_root_publish_end(ClusterWalRootPublishGuard **guard); void ExceptionalCondition(const char *conditionName, const char *fileName, int lineNumber) @@ -160,8 +159,7 @@ errstart_cold(int elevel pg_attribute_unused(), const char *domain pg_attribute_ void errfinish(const char *filename pg_attribute_unused(), int lineno pg_attribute_unused(), const char *funcname pg_attribute_unused()) -{ -} +{} int BasicOpenFilePerm(const char *fileName, int fileFlags, mode_t fileMode) @@ -186,8 +184,7 @@ durable_rename(const char *oldfile, const char *newfile, int elevel pg_attribute { test_durable_rename_calls++; test_last_rename_order = ++test_order_seq; - if (test_fail_primary_rename - && strstr(newfile, CLUSTER_CONTROL_ROOT_REL_PATH) != NULL + if (test_fail_primary_rename && strstr(newfile, CLUSTER_CONTROL_ROOT_REL_PATH) != NULL && strstr(newfile, ".bak") == NULL) { errno = EIO; return -1; @@ -218,7 +215,7 @@ static uint64 test_membership_incarnation = UINT64_C(0x1020304050607080); uint64 cluster_membership_get_last_admitted_incarnation(int32 node_id) { - (void) node_id; + (void)node_id; return test_membership_incarnation; } @@ -242,8 +239,7 @@ cluster_r4_bit22_source_writer_enter(void) void cluster_r4_bit22_source_writer_leave(void) -{ -} +{} bool cluster_r4_bit22_source_close_begin(uint64 transition_epoch pg_attribute_unused(), @@ -262,8 +258,7 @@ cluster_r4_bit22_source_close_current(uint64 transition_epoch pg_attribute_unuse } bool -cluster_r4_bit22_cutover_latch_apply(uint64 transition_epoch, - uint64 round_generation) +cluster_r4_bit22_cutover_latch_apply(uint64 transition_epoch, uint64 round_generation) { test_bit22_latch_apply_calls++; if (!test_bit22_latch_apply_ok) @@ -276,8 +271,7 @@ cluster_r4_bit22_cutover_latch_apply(uint64 transition_epoch, ClusterSemanticActivationResult cluster_qvotec_bootstrap_read_semantic_activation( - uint8 selected[CLUSTER_SEMANTIC_ACTIVATION_RECORD_BYTES], - bool *implicit_open) + uint8 selected[CLUSTER_SEMANTIC_ACTIVATION_RECORD_BYTES], bool *implicit_open) { test_qvotec_bootstrap_calls++; if (selected != NULL) @@ -371,10 +365,9 @@ cluster_cf_unlock_confirmed(LOCKMODE mode pg_attribute_unused()) } ClusterWalPinResult -cluster_wal_retention_root_publish_begin_exact( - const ClusterControlRootReadToken *expected_root, - bool require_sealed_pin pg_attribute_unused(), - ClusterWalRootPublishGuard **out_guard) +cluster_wal_retention_root_publish_begin_exact(const ClusterControlRootReadToken *expected_root, + bool require_sealed_pin pg_attribute_unused(), + ClusterWalRootPublishGuard **out_guard) { test_walr_begin_calls++; test_walr_thread = expected_root->origin_thread_id; @@ -464,16 +457,14 @@ sha256_bytes(const uint8 *bytes, size_t len, uint8 out[PG_SHA256_DIGEST_LENGTH]) { pg_cryptohash_ctx *ctx = pg_cryptohash_create(PG_SHA256); - if (ctx == NULL || pg_cryptohash_init(ctx) < 0 - || pg_cryptohash_update(ctx, bytes, len) < 0 + if (ctx == NULL || pg_cryptohash_init(ctx) < 0 || pg_cryptohash_update(ctx, bytes, len) < 0 || pg_cryptohash_final(ctx, out, PG_SHA256_DIGEST_LENGTH) < 0) abort(); pg_cryptohash_free(ctx); } static void -round_sha256(const ClusterControlRootMigrationRoundV1 *round, - uint8 out[PG_SHA256_DIGEST_LENGTH]) +round_sha256(const ClusterControlRootMigrationRoundV1 *round, uint8 out[PG_SHA256_DIGEST_LENGTH]) { uint8 bytes[80]; @@ -610,7 +601,7 @@ write_minimal_checkpoint_segment(const char *thread_dir) * The record reader parses these headers, so zeros alone would be * misread as block ids. */ page[off] = XLR_BLOCK_ID_DATA_SHORT; - page[off + 1] = (uint8) sizeof(CheckPoint); + page[off + 1] = (uint8)sizeof(CheckPoint); memset(page + off + 2, 0, sizeof(CheckPoint)); memset(&rec, 0, sizeof(rec)); @@ -623,13 +614,12 @@ write_minimal_checkpoint_segment(const char *thread_dir) * including) xl_crc. */ INIT_CRC32C(crc); COMP_CRC32C(crc, page + off, 2 + sizeof(CheckPoint)); - COMP_CRC32C(crc, (uint8 *) &rec, offsetof(XLogRecord, xl_crc)); + COMP_CRC32C(crc, (uint8 *)&rec, offsetof(XLogRecord, xl_crc)); FIN_CRC32C(crc); - rec.xl_crc = (uint32) crc; + rec.xl_crc = (uint32)crc; memcpy(page + SizeOfXLogLongPHD, &rec, sizeof(rec)); - snprintf(path, sizeof(path), "%s/%s", thread_dir, - "000000010000000000000001"); + snprintf(path, sizeof(path), "%s/%s", thread_dir, "000000010000000000000001"); write_all_or_abort(path, page, sizeof(page)); } @@ -647,8 +637,8 @@ build_source_wal_state(void) cluster_wal_state_header_fill(&header, INT64_C(1699999999000000)); memcpy(bytes, &header, sizeof(header)); cluster_wal_state_slot_fill(&slot, 1, 0, CLUSTER_WAL_SLOT_STATE_STOPPED, 1, - INT64_C(1699999999000001), - INT64_C(1699999999000002), UINT64_C(0x1000000), 1); + INT64_C(1699999999000001), INT64_C(1699999999000002), + UINT64_C(0x1000000), 1); slot.checkpoint_redo_lsn = UINT64_C(0x1000000); slot.crc = cluster_wal_state_block_crc(&slot); memcpy(bytes + CLUSTER_WAL_STATE_SLOT_OFFSET(1), &slot, sizeof(slot)); @@ -658,8 +648,7 @@ build_source_wal_state(void) snprintf(thread_dir, sizeof(thread_dir), "%s/thread_1", test_wal_root); if (mkdir(thread_dir, 0700) != 0 && errno != EEXIST) abort(); - snprintf(path, sizeof(path), "%s/%s", thread_dir, - CLUSTER_WAL_THREAD_CLAIM_FILENAME); + snprintf(path, sizeof(path), "%s/%s", thread_dir, CLUSTER_WAL_THREAD_CLAIM_FILENAME); write_all_or_abort(path, &claim, sizeof(claim)); write_minimal_checkpoint_segment(thread_dir); } @@ -688,8 +677,7 @@ fill_identity(ClusterControlRootIdentity *identity) } static void -build_migration(ClusterControlRootMigrationImage *image, - ClusterControlRootMigrationRoundV1 *round) +build_migration(ClusterControlRootMigrationImage *image, ClusterControlRootMigrationRoundV1 *round) { ClusterControlRootSnapshot *record; @@ -702,10 +690,9 @@ build_migration(ClusterControlRootMigrationImage *image, image->assigned_record_count = 1; record = &image->records[0]; record->lifecycle = CLUSTER_CONTROL_ROOT_LIFECYCLE_CLOSED; - record->root_flags = CLUSTER_CONTROL_ROOT_FLAG_CLAIM_VALID - | CLUSTER_CONTROL_ROOT_FLAG_CHECKPOINT_VALID - | CLUSTER_CONTROL_ROOT_FLAG_TAIL_VALID - | CLUSTER_CONTROL_ROOT_FLAG_RECOVERED_VALID; + record->root_flags + = CLUSTER_CONTROL_ROOT_FLAG_CLAIM_VALID | CLUSTER_CONTROL_ROOT_FLAG_CHECKPOINT_VALID + | CLUSTER_CONTROL_ROOT_FLAG_TAIL_VALID | CLUSTER_CONTROL_ROOT_FLAG_RECOVERED_VALID; record->root_publish_seq = 1; record->checkpoint_tli = 1; record->tail_tli = 1; @@ -838,19 +825,16 @@ fixture_seed_source(uint32 tli, uint64 checkpoint_lsn, uint64 tail_lsn, char thread_dir[MAXPGPATH]; int64 claim_created_at = INT64_C(1700000000000001); - if (snprintf(path, sizeof(path), "%s/%s", test_wal_root, - CLUSTER_WAL_STATE_FILENAME) <= 0 + if (snprintf(path, sizeof(path), "%s/%s", test_wal_root, CLUSTER_WAL_STATE_FILENAME) <= 0 || !read_exact_file(path, bytes, sizeof(bytes)) - || !cluster_wal_state_image_validate(bytes, sizeof(bytes), &bad_thread, - &reason)) + || !cluster_wal_state_image_validate(bytes, sizeof(bytes), &bad_thread, &reason)) return false; if (!cluster_wal_state_slot_is_zero( (ClusterWalStateSlot *)(bytes + CLUSTER_WAL_STATE_SLOT_OFFSET(1)))) return false; - cluster_wal_state_slot_fill(&slot, 1, 0, CLUSTER_WAL_SLOT_STATE_STOPPED, - tli, claim_created_at, claim_created_at + 1, - tail_lsn, 1); + cluster_wal_state_slot_fill(&slot, 1, 0, CLUSTER_WAL_SLOT_STATE_STOPPED, tli, claim_created_at, + claim_created_at + 1, tail_lsn, 1); slot.checkpoint_redo_lsn = checkpoint_lsn; slot.crc = cluster_wal_state_block_crc(&slot); memcpy(bytes + CLUSTER_WAL_STATE_SLOT_OFFSET(1), &slot, sizeof(slot)); @@ -862,8 +846,7 @@ fixture_seed_source(uint32 tli, uint64 checkpoint_lsn, uint64 tail_lsn, return false; if (mkdir(thread_dir, 0700) != 0 && errno != EEXIST) return false; - if (snprintf(path, sizeof(path), "%s/%s", thread_dir, - CLUSTER_WAL_THREAD_CLAIM_FILENAME) <= 0 + if (snprintf(path, sizeof(path), "%s/%s", thread_dir, CLUSTER_WAL_THREAD_CLAIM_FILENAME) <= 0 || !write_exact_durable(path, out_claim, sizeof(*out_claim))) return false; return true; @@ -888,14 +871,11 @@ fixture_root_main(int argc, char **argv) uint32 lifecycle; int i; - if (argc != 10 || strcmp(argv[1], "--fixture-root") != 0 - || !parse_u64_arg(argv[4], &sysid) || sysid == 0 - || !parse_u64_arg(argv[7], &tli64) || tli64 == 0 - || tli64 > UINT32_MAX + if (argc != 10 || strcmp(argv[1], "--fixture-root") != 0 || !parse_u64_arg(argv[4], &sysid) + || sysid == 0 || !parse_u64_arg(argv[7], &tli64) || tli64 == 0 || tli64 > UINT32_MAX || !parse_u64_arg(argv[8], &checkpoint_lsn) || checkpoint_lsn == 0 || !parse_u64_arg(argv[9], &tail_lsn) || tail_lsn < checkpoint_lsn - || strlen(argv[2]) >= sizeof(test_root) - || strlen(argv[3]) >= sizeof(test_wal_root) + || strlen(argv[2]) >= sizeof(test_root) || strlen(argv[3]) >= sizeof(test_wal_root) || strlen(argv[5]) != 32) { fprintf(stderr, "invalid --fixture-root arguments\n"); return 2; @@ -938,7 +918,7 @@ fixture_root_main(int argc, char **argv) image.created_at_usec = INT64_C(1700000000000002); image.assigned_record_count = 1; - snapshot = (ClusterControlRootSnapshot){0}; + snapshot = (ClusterControlRootSnapshot){ 0 }; snapshot.identity.system_identifier = sysid; memcpy(snapshot.identity.storage_uuid, image.storage_uuid, 16); memcpy(snapshot.identity.authority_uuid, image.authority_uuid, 16); @@ -980,9 +960,8 @@ fixture_root_main(int argc, char **argv) round.bytes = sizeof(round); round.prepare_generation = 1; round.transition_epoch = 1; - round.target_feature_bitmap = - PGRAC_CONTROL_ROOT_FEATURE_WAL_REUSE_V1 - | PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1; + round.target_feature_bitmap = PGRAC_CONTROL_ROOT_FEATURE_WAL_REUSE_V1 + | PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1; round.admitted_bitmap_low = 1; round.capability_sample_digest = UINT64_C(0x8877665544332211); round.coordinator_incarnation = UINT64_C(0x7766554433221100); @@ -996,15 +975,14 @@ fixture_root_main(int argc, char **argv) } round_sha256(&round, round_sha); if (cluster_control_root_activate_prepared(&prepared, round_sha, &round, &active) - != CLUSTER_CONTROL_ROOT_OK_PRIMARY + != CLUSTER_CONTROL_ROOT_OK_PRIMARY || active.activation_state != CLUSTER_CONTROL_ROOT_ACTIVATION_ACTIVE) { fprintf(stderr, "control-root activation verification failed\n"); return 1; } expected_identity = snapshot.identity; - if (cluster_control_root_read_canonical(1, &expected_identity, - CLUSTER_CONTROL_ROOT_READ_STRONG, - &snapshot, &read_token) + if (cluster_control_root_read_canonical(1, &expected_identity, CLUSTER_CONTROL_ROOT_READ_STRONG, + &snapshot, &read_token) != CLUSTER_CONTROL_ROOT_OK_PRIMARY) { fprintf(stderr, "control-root activation verification failed\n"); return 1; @@ -1028,9 +1006,8 @@ fixture_root_main(int argc, char **argv) * */ static bool -fixture_cast_load_thread(uint16 thread_id, int32 node_id, uint32 *out_tli, - uint64 *out_ckpt, uint64 *out_tail, - ClusterWalThreadClaim *out_claim) +fixture_cast_load_thread(uint16 thread_id, int32 node_id, uint32 *out_tli, uint64 *out_ckpt, + uint64 *out_tail, ClusterWalThreadClaim *out_claim) { uint8 bytes[CLUSTER_WAL_STATE_FILE_SIZE]; ClusterWalStateSlot slot; @@ -1041,38 +1018,25 @@ fixture_cast_load_thread(uint16 thread_id, int32 node_id, uint32 *out_tli, char path[MAXPGPATH]; char thread_dir[MAXPGPATH]; - if (snprintf(path, sizeof(path), "%s/%s", test_wal_root, - CLUSTER_WAL_STATE_FILENAME) <= 0 + if (snprintf(path, sizeof(path), "%s/%s", test_wal_root, CLUSTER_WAL_STATE_FILENAME) <= 0 || !read_exact_file(path, bytes, sizeof(bytes)) - || !cluster_wal_state_image_validate(bytes, sizeof(bytes), &bad_thread, - &reason)) + || !cluster_wal_state_image_validate(bytes, sizeof(bytes), &bad_thread, &reason)) return false; memcpy(&slot, bytes + CLUSTER_WAL_STATE_SLOT_OFFSET(thread_id), sizeof(slot)); - if (cluster_wal_state_slot_classify(&slot, thread_id, -1, NULL) - != CLUSTER_WAL_SLOT_OK - || slot.state != CLUSTER_WAL_SLOT_STATE_STOPPED - || slot.node_id != node_id - || slot.tli == 0 - || slot.checkpoint_redo_lsn == 0 - || slot.highest_lsn == 0 - || slot.highest_lsn < slot.checkpoint_redo_lsn - || slot.merge_recovered_lsn != 0) + if (cluster_wal_state_slot_classify(&slot, thread_id, -1, NULL) != CLUSTER_WAL_SLOT_OK + || slot.state != CLUSTER_WAL_SLOT_STATE_STOPPED || slot.node_id != node_id || slot.tli == 0 + || slot.checkpoint_redo_lsn == 0 || slot.highest_lsn == 0 + || slot.highest_lsn < slot.checkpoint_redo_lsn || slot.merge_recovered_lsn != 0) return false; - if (snprintf(thread_dir, sizeof(thread_dir), "%s/thread_%u", test_wal_root, - thread_id) <= 0 - || snprintf(path, sizeof(path), "%s/%s", thread_dir, - CLUSTER_WAL_THREAD_CLAIM_FILENAME) <= 0 + if (snprintf(thread_dir, sizeof(thread_dir), "%s/thread_%u", test_wal_root, thread_id) <= 0 + || snprintf(path, sizeof(path), "%s/%s", thread_dir, CLUSTER_WAL_THREAD_CLAIM_FILENAME) <= 0 || !read_exact_file(path, (uint8 *)&disk_claim, sizeof(disk_claim))) return false; - cluster_wal_thread_claim_fill(&expected_claim, thread_id, node_id, - disk_claim.created_at); - if (disk_claim.magic != expected_claim.magic - || disk_claim.version != expected_claim.version - || disk_claim.thread_id != thread_id - || disk_claim.node_id != node_id - || disk_claim.created_at == 0 - || disk_claim.crc != expected_claim.crc) + cluster_wal_thread_claim_fill(&expected_claim, thread_id, node_id, disk_claim.created_at); + if (disk_claim.magic != expected_claim.magic || disk_claim.version != expected_claim.version + || disk_claim.thread_id != thread_id || disk_claim.node_id != node_id + || disk_claim.created_at == 0 || disk_claim.crc != expected_claim.crc) return false; *out_tli = slot.tli; @@ -1084,13 +1048,12 @@ fixture_cast_load_thread(uint16 thread_id, int32 node_id, uint32 *out_tli, static void fixture_cast_fill_record(ClusterControlRootSnapshot *snapshot, uint64 sysid, - const uint8 storage_uuid[16], - const uint8 authority_uuid[16], uint16 thread_id, - int32 node_id, const ClusterWalThreadClaim *claim, - uint32 lifecycle, uint64 owner_incarnation, uint32 tli, - uint64 ckpt, uint64 tail) + const uint8 storage_uuid[16], const uint8 authority_uuid[16], + uint16 thread_id, int32 node_id, const ClusterWalThreadClaim *claim, + uint32 lifecycle, uint64 owner_incarnation, uint32 tli, uint64 ckpt, + uint64 tail) { - *snapshot = (ClusterControlRootSnapshot){0}; + *snapshot = (ClusterControlRootSnapshot){ 0 }; snapshot->identity.system_identifier = sysid; memcpy(snapshot->identity.storage_uuid, storage_uuid, 16); memcpy(snapshot->identity.authority_uuid, authority_uuid, 16); @@ -1148,16 +1111,12 @@ fixture_cast_main(int argc, char **argv) uint8 storage_uuid[16]; uint8 authority_uuid[16]; - if (argc != 11 || strcmp(argv[1], "--fixture-root-cast") != 0 - || !parse_u64_arg(argv[4], &sysid) || sysid == 0 - || strlen(argv[2]) >= sizeof(test_root) - || strlen(argv[3]) >= sizeof(test_wal_root) - || strlen(argv[5]) != 32 || strlen(argv[6]) != 32 - || !parse_uuid_hex(argv[5], storage_uuid) - || !parse_uuid_hex(argv[6], authority_uuid) - || (authority_uuid[6] & 0xf0) != 0x40 - || (authority_uuid[8] & 0xc0) != 0x80 - || !parse_u64_arg(argv[8], &inc2) || inc2 == 0 + if (argc != 11 || strcmp(argv[1], "--fixture-root-cast") != 0 || !parse_u64_arg(argv[4], &sysid) + || sysid == 0 || strlen(argv[2]) >= sizeof(test_root) + || strlen(argv[3]) >= sizeof(test_wal_root) || strlen(argv[5]) != 32 + || strlen(argv[6]) != 32 || !parse_uuid_hex(argv[5], storage_uuid) + || !parse_uuid_hex(argv[6], authority_uuid) || (authority_uuid[6] & 0xf0) != 0x40 + || (authority_uuid[8] & 0xc0) != 0x80 || !parse_u64_arg(argv[8], &inc2) || inc2 == 0 || !parse_u64_arg(argv[10], &inc1) || inc1 == 0) { fprintf(stderr, "invalid --fixture-root-cast arguments\n"); return 2; @@ -1206,12 +1165,10 @@ fixture_cast_main(int argc, char **argv) memcpy(image.authority_uuid, authority_uuid, 16); image.created_at_usec = INT64_C(1700000000000002); image.assigned_record_count = 2; - fixture_cast_fill_record(&image.records[0], sysid, storage_uuid, - authority_uuid, 1, 0, &claim1, lifecycle1, inc1, - tli1, ckpt1, tail1); - fixture_cast_fill_record(&image.records[1], sysid, storage_uuid, - authority_uuid, 2, 1, &claim2, lifecycle2, inc2, - tli2, ckpt2, tail2); + fixture_cast_fill_record(&image.records[0], sysid, storage_uuid, authority_uuid, 1, 0, &claim1, + lifecycle1, inc1, tli1, ckpt1, tail1); + fixture_cast_fill_record(&image.records[1], sysid, storage_uuid, authority_uuid, 2, 1, &claim2, + lifecycle2, inc2, tli2, ckpt2, tail2); memset(&round, 0, sizeof(round)); memcpy(round.magic, "PCRM", 4); @@ -1219,41 +1176,36 @@ fixture_cast_main(int argc, char **argv) round.bytes = sizeof(round); round.prepare_generation = 1; round.transition_epoch = 1; - round.target_feature_bitmap = - PGRAC_CONTROL_ROOT_FEATURE_WAL_REUSE_V1 - | PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1; + round.target_feature_bitmap = PGRAC_CONTROL_ROOT_FEATURE_WAL_REUSE_V1 + | PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1; round.admitted_bitmap_low = 3; round.capability_sample_digest = UINT64_C(0x8877665544332211); round.coordinator_incarnation = UINT64_C(0x7766554433221100); round.coordinator_node_id = 0; wipe_root_files(); - result_cast_prepare = cluster_control_root_create_prepared(&image, &round, - &prepared); + result_cast_prepare = cluster_control_root_create_prepared(&image, &round, &prepared); if (result_cast_prepare != CLUSTER_CONTROL_ROOT_OK_PRIMARY) { - fprintf(stderr, "control-root cast prepare failed (result %d)\n", - (int)result_cast_prepare); + fprintf(stderr, "control-root cast prepare failed (result %d)\n", (int)result_cast_prepare); return 1; } round_sha256(&round, round_sha); if (cluster_control_root_activate_prepared(&prepared, round_sha, &round, &active) - != CLUSTER_CONTROL_ROOT_OK_PRIMARY + != CLUSTER_CONTROL_ROOT_OK_PRIMARY || active.activation_state != CLUSTER_CONTROL_ROOT_ACTIVATION_ACTIVE) { fprintf(stderr, "control-root cast activation failed\n"); return 1; } expected_identity = image.records[0].identity; - if (cluster_control_root_read_canonical(1, &expected_identity, - CLUSTER_CONTROL_ROOT_READ_STRONG, - &snapshot, &read_token) + if (cluster_control_root_read_canonical(1, &expected_identity, CLUSTER_CONTROL_ROOT_READ_STRONG, + &snapshot, &read_token) != CLUSTER_CONTROL_ROOT_OK_PRIMARY) { fprintf(stderr, "control-root cast thread-1 readback failed\n"); return 1; } expected_identity = image.records[1].identity; - if (cluster_control_root_read_canonical(2, &expected_identity, - CLUSTER_CONTROL_ROOT_READ_STRONG, - &snapshot, &read_token) + if (cluster_control_root_read_canonical(2, &expected_identity, CLUSTER_CONTROL_ROOT_READ_STRONG, + &snapshot, &read_token) != CLUSTER_CONTROL_ROOT_OK_PRIMARY) { fprintf(stderr, "control-root cast thread-2 readback failed\n"); return 1; @@ -1262,8 +1214,7 @@ fixture_cast_main(int argc, char **argv) } static ClusterControlRootResult -create_prepared(ClusterControlRootMigrationImage *image, - ClusterControlRootMigrationRoundV1 *round, +create_prepared(ClusterControlRootMigrationImage *image, ClusterControlRootMigrationRoundV1 *round, ClusterControlRootFileToken *token) { build_migration(image, round); @@ -1283,18 +1234,16 @@ force_first_record_lineage(uint64 lineage) read_all_or_abort(primary, bytes, sizeof(bytes)); put_u64_le(record + 24, lineage); put_u32_le(record + 504, image_crc(record, 504)); - put_u32_le(bytes + 96, - image_crc(bytes + CLUSTER_CONTROL_ROOT_HEADER_BYTES, - sizeof(bytes) - CLUSTER_CONTROL_ROOT_HEADER_BYTES)); + put_u32_le(bytes + 96, image_crc(bytes + CLUSTER_CONTROL_ROOT_HEADER_BYTES, + sizeof(bytes) - CLUSTER_CONTROL_ROOT_HEADER_BYTES)); put_u32_le(bytes + 504, image_crc(bytes, 504)); write_all_or_abort(primary, bytes, sizeof(bytes)); write_all_or_abort(bak, bytes, sizeof(bytes)); } static void -build_owner_rejoin_patch(const ClusterControlRootSnapshot *snapshot, - uint64 new_incarnation, uint64 new_lineage, - ClusterControlRootPatch *patch) +build_owner_rejoin_patch(const ClusterControlRootSnapshot *snapshot, uint64 new_incarnation, + uint64 new_lineage, ClusterControlRootPatch *patch) { memset(patch, 0, sizeof(*patch)); patch->mask = UINT64_C(0x3b); @@ -1313,8 +1262,7 @@ build_owner_rejoin_patch(const ClusterControlRootSnapshot *snapshot, patch->desired.tail_last_record_lsn = snapshot->tail_last_record_lsn; patch->desired.tail_last_record_crc32c = snapshot->tail_last_record_crc32c; patch->desired.recovered_tli = snapshot->recovered_tli; - patch->desired.recovered_through_lsn_exclusive = - snapshot->recovered_through_lsn_exclusive; + patch->desired.recovered_through_lsn_exclusive = snapshot->recovered_through_lsn_exclusive; patch->desired.recovered_last_record_lsn = snapshot->recovered_last_record_lsn; patch->desired.recovered_last_record_crc32c = snapshot->recovered_last_record_crc32c; } @@ -1346,8 +1294,7 @@ UT_TEST(test_abi_identity_and_features) { ClusterControlRootIdentity left; ClusterControlRootIdentity right; - uint64 known = (UINT64_C(1) << 0) - | PGRAC_CONTROL_ROOT_FEATURE_WAL_REUSE_V1 + uint64 known = (UINT64_C(1) << 0) | PGRAC_CONTROL_ROOT_FEATURE_WAL_REUSE_V1 | PGRAC_CONTROL_ROOT_FEATURE_PAGE_STABLE_BASE_V1 | PGRAC_CONTROL_ROOT_FEATURE_SPACE_METADATA_V1 | PGRAC_CONTROL_ROOT_FEATURE_CONSERVATIVE_COMMIT_SCN_V1 @@ -1359,14 +1306,10 @@ UT_TEST(test_abi_identity_and_features) UT_ASSERT_EQ(CLUSTER_CONTROL_ROOT_FORMAT_FLAGS_V1, UINT64_C(0x0d)); UT_ASSERT_EQ(CLUSTER_CONTROL_ROOT_FLAGS_V1, UINT32_C(0x1fd)); UT_ASSERT_EQ(CLUSTER_CONTROL_ROOT_PATCH_ALL_V1, UINT64_C(0xfb)); - UT_ASSERT_EQ(PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1, - UINT64_C(0x00400000)); - UT_ASSERT_EQ(PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_SERIAL_V1, - UINT64_C(0x00800000)); - UT_ASSERT_EQ(PGRAC_CONTROL_ROOT_FEATURE_EXTERNAL_FENCE_V1, - UINT64_C(0x01000000)); - UT_ASSERT_EQ(PGRAC_CONTROL_ROOT_FEATURE_KNOWN_MASK_V1, - UINT64_C(0x01ee0001)); + UT_ASSERT_EQ(PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1, UINT64_C(0x00400000)); + UT_ASSERT_EQ(PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_SERIAL_V1, UINT64_C(0x00800000)); + UT_ASSERT_EQ(PGRAC_CONTROL_ROOT_FEATURE_EXTERNAL_FENCE_V1, UINT64_C(0x01000000)); + UT_ASSERT_EQ(PGRAC_CONTROL_ROOT_FEATURE_KNOWN_MASK_V1, UINT64_C(0x01ee0001)); UT_ASSERT_EQ(known, PGRAC_CONTROL_ROOT_FEATURE_KNOWN_MASK_V1); fill_identity(&left); right = left; @@ -1401,9 +1344,8 @@ UT_TEST(test_external_fence_bit24_activation_is_forbidden_without_provider) wipe_root_files(); build_migration(&image, &round); - round.target_feature_bitmap |= - PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_SERIAL_V1 | - PGRAC_CONTROL_ROOT_FEATURE_EXTERNAL_FENCE_V1; + round.target_feature_bitmap |= PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_SERIAL_V1 + | PGRAC_CONTROL_ROOT_FEATURE_EXTERNAL_FENCE_V1; memset(&token, 0xee, sizeof(token)); UT_ASSERT_EQ(cluster_control_root_create_prepared(&image, &round, &token), CLUSTER_CONTROL_ROOT_INVALID_ARGUMENT); @@ -1433,17 +1375,16 @@ UT_TEST(test_create_and_read_primary) read_all_or_abort(bak_path, bak, sizeof(bak)); UT_ASSERT(memcmp(primary, bak, sizeof(primary)) == 0); UT_ASSERT_EQ(image_crc(primary + CLUSTER_CONTROL_ROOT_HEADER_BYTES, - sizeof(primary) - CLUSTER_CONTROL_ROOT_HEADER_BYTES), + sizeof(primary) - CLUSTER_CONTROL_ROOT_HEADER_BYTES), file_token.body_crc32c); memset(&snapshot, 0xee, sizeof(snapshot)); memset(&read_token, 0xee, sizeof(read_token)); UT_ASSERT_EQ(cluster_control_root_read_canonical(1, &image.records[0].identity, - CLUSTER_CONTROL_ROOT_READ_STRONG, - &snapshot, &read_token), + CLUSTER_CONTROL_ROOT_READ_STRONG, &snapshot, + &read_token), CLUSTER_CONTROL_ROOT_OK_PRIMARY); - UT_ASSERT(cluster_control_root_identity_equal(&snapshot.identity, - &image.records[0].identity)); + UT_ASSERT(cluster_control_root_identity_equal(&snapshot.identity, &image.records[0].identity)); UT_ASSERT_EQ(read_token.file_txn_seq, 1); UT_ASSERT_EQ(read_token.origin_thread_id, 1); } @@ -1460,9 +1401,8 @@ UT_TEST(test_bootstrap_read_never_returns_authority_token) UT_ASSERT_EQ(create_prepared(&image, &round, &file_token), CLUSTER_CONTROL_ROOT_OK_PRIMARY); test_cf_lock_calls = 0; memset(&read_token, 0xee, sizeof(read_token)); - UT_ASSERT_EQ(cluster_control_root_read_canonical(1, NULL, - CLUSTER_CONTROL_ROOT_READ_BOOTSTRAP_VALIDATE, - &snapshot, &read_token), + UT_ASSERT_EQ(cluster_control_root_read_canonical( + 1, NULL, CLUSTER_CONTROL_ROOT_READ_BOOTSTRAP_VALIDATE, &snapshot, &read_token), CLUSTER_CONTROL_ROOT_OK_PRIMARY); UT_ASSERT_EQ(test_cf_lock_calls, 0); UT_ASSERT_EQ(read_token.file_txn_seq, 0); @@ -1487,8 +1427,7 @@ UT_TEST(test_round_sha256_is_deterministic_and_matches_create) UT_ASSERT(memcmp(sha_a, sha_b, sizeof(sha_a)) == 0); /* create_prepared must succeed with the same round (its header stores * the same wire-encoded sha). */ - UT_ASSERT_EQ(create_prepared(&image, &round, &token), - CLUSTER_CONTROL_ROOT_OK_PRIMARY); + UT_ASSERT_EQ(create_prepared(&image, &round, &token), CLUSTER_CONTROL_ROOT_OK_PRIMARY); } UT_TEST(test_build_migration_image_maps_registry_and_claims) @@ -1505,20 +1444,13 @@ UT_TEST(test_build_migration_image_maps_registry_and_claims) UT_ASSERT(image.records[0].checkpoint_record_crc32c != 0); UT_ASSERT_EQ(image.records[0].identity.origin_thread_id, 1); UT_ASSERT_EQ(image.records[0].identity.origin_node_id, 0); - UT_ASSERT_EQ(image.records[0].identity.origin_owner_incarnation, - UINT64_C(0x1020304050607080)); - UT_ASSERT_EQ(image.records[0].identity.thread_claim_created_at, - INT64_C(1699999999000001)); - UT_ASSERT_EQ(image.records[0].lifecycle, - CLUSTER_CONTROL_ROOT_LIFECYCLE_CLOSED); - UT_ASSERT_EQ(image.records[0].checkpoint_lower_lsn, - UINT64_C(0x1000000)); - UT_ASSERT_EQ(image.records[0].validated_tail_lsn_exclusive, - UINT64_C(0x1000000)); - UT_ASSERT((image.records[0].root_flags - & CLUSTER_CONTROL_ROOT_FLAG_CLAIM_VALID) != 0); - UT_ASSERT(memcmp(image.storage_uuid, image.records[0].identity.storage_uuid, - 16) == 0); + UT_ASSERT_EQ(image.records[0].identity.origin_owner_incarnation, UINT64_C(0x1020304050607080)); + UT_ASSERT_EQ(image.records[0].identity.thread_claim_created_at, INT64_C(1699999999000001)); + UT_ASSERT_EQ(image.records[0].lifecycle, CLUSTER_CONTROL_ROOT_LIFECYCLE_CLOSED); + UT_ASSERT_EQ(image.records[0].checkpoint_lower_lsn, UINT64_C(0x1000000)); + UT_ASSERT_EQ(image.records[0].validated_tail_lsn_exclusive, UINT64_C(0x1000000)); + UT_ASSERT((image.records[0].root_flags & CLUSTER_CONTROL_ROOT_FLAG_CLAIM_VALID) != 0); + UT_ASSERT(memcmp(image.storage_uuid, image.records[0].identity.storage_uuid, 16) == 0); build_source_wal_state(); /* restore the shared fixture for later tests */ } @@ -1534,12 +1466,9 @@ UT_TEST(test_build_migration_image_accepts_frozen_active_slot) wipe_root_files(); memset(bytes, 0, sizeof(bytes)); - cluster_wal_state_header_fill((ClusterWalStateHeader *) bytes, - INT64_C(1699999999000000)); - cluster_wal_state_slot_fill(&slot, 1, 0, - CLUSTER_WAL_SLOT_STATE_ACTIVE, 1, - INT64_C(1699999999000001), - INT64_C(1699999999000002), + cluster_wal_state_header_fill((ClusterWalStateHeader *)bytes, INT64_C(1699999999000000)); + cluster_wal_state_slot_fill(&slot, 1, 0, CLUSTER_WAL_SLOT_STATE_ACTIVE, 1, + INT64_C(1699999999000001), INT64_C(1699999999000002), UINT64_C(0x1000000), 1); slot.checkpoint_redo_lsn = UINT64_C(0x1000000); slot.crc = cluster_wal_state_block_crc(&slot); @@ -1547,8 +1476,7 @@ UT_TEST(test_build_migration_image_accepts_frozen_active_slot) { char path[MAXPGPATH]; - snprintf(path, sizeof(path), "%s/%s", test_wal_root, - CLUSTER_WAL_STATE_FILENAME); + snprintf(path, sizeof(path), "%s/%s", test_wal_root, CLUSTER_WAL_STATE_FILENAME); write_all_or_abort(path, bytes, sizeof(bytes)); } /* claim + minimal WAL segment for the scan */ @@ -1557,14 +1485,11 @@ UT_TEST(test_build_migration_image_accepts_frozen_active_slot) char path[MAXPGPATH]; ClusterWalThreadClaim claim; - snprintf(thread_dir, sizeof(thread_dir), "%s/thread_1", - test_wal_root); + snprintf(thread_dir, sizeof(thread_dir), "%s/thread_1", test_wal_root); if (mkdir(thread_dir, 0700) != 0 && errno != EEXIST) abort(); - cluster_wal_thread_claim_fill(&claim, 1, 0, - INT64_C(1699999999000001)); - snprintf(path, sizeof(path), "%s/%s", thread_dir, - CLUSTER_WAL_THREAD_CLAIM_FILENAME); + cluster_wal_thread_claim_fill(&claim, 1, 0, INT64_C(1699999999000001)); + snprintf(path, sizeof(path), "%s/%s", thread_dir, CLUSTER_WAL_THREAD_CLAIM_FILENAME); write_all_or_abort(path, &claim, sizeof(claim)); write_minimal_checkpoint_segment(thread_dir); } @@ -1599,21 +1524,18 @@ UT_TEST(test_build_migration_image_rejects_non_stopped_slot) build_source_wal_state(); /* flip slot 1 to ACTIVE — the W6 CLOSED precondition is violated */ path_for(path, sizeof(path), ""); /* reuse: write into the wal root */ - snprintf(path, sizeof(path), "%s/%s", test_wal_root, - CLUSTER_WAL_STATE_FILENAME); + snprintf(path, sizeof(path), "%s/%s", test_wal_root, CLUSTER_WAL_STATE_FILENAME); fd = open(path, O_RDWR); UT_ASSERT(fd >= 0); memcpy(&slot, (void *)0, 0); /* noop to keep compiler quiet */ { ClusterWalStateSlot s; - if (pread(fd, &s, sizeof(s), CLUSTER_WAL_STATE_SLOT_OFFSET(1)) - != (ssize_t) sizeof(s)) + if (pread(fd, &s, sizeof(s), CLUSTER_WAL_STATE_SLOT_OFFSET(1)) != (ssize_t)sizeof(s)) abort(); s.state = CLUSTER_WAL_SLOT_STATE_ACTIVE; s.crc = cluster_wal_state_block_crc(&s); - if (pwrite(fd, &s, sizeof(s), CLUSTER_WAL_STATE_SLOT_OFFSET(1)) - != (ssize_t) sizeof(s)) + if (pwrite(fd, &s, sizeof(s), CLUSTER_WAL_STATE_SLOT_OFFSET(1)) != (ssize_t)sizeof(s)) abort(); } close(fd); @@ -1634,9 +1556,8 @@ UT_TEST(test_strong_read_null_identity_stays_invalid_argument) UT_ASSERT_EQ(create_prepared(&image, &round, &file_token), CLUSTER_CONTROL_ROOT_OK_PRIMARY); memset(&snapshot, 0xee, sizeof(snapshot)); memset(&read_token, 0xee, sizeof(read_token)); - UT_ASSERT_EQ(cluster_control_root_read_canonical(1, NULL, - CLUSTER_CONTROL_ROOT_READ_STRONG, - &snapshot, &read_token), + UT_ASSERT_EQ(cluster_control_root_read_canonical(1, NULL, CLUSTER_CONTROL_ROOT_READ_STRONG, + &snapshot, &read_token), CLUSTER_CONTROL_ROOT_INVALID_ARGUMENT); UT_ASSERT_EQ(snapshot.identity.system_identifier, 0); UT_ASSERT_EQ(read_token.file_txn_seq, 0); @@ -1656,8 +1577,7 @@ UT_TEST(test_discovered_read_binds_identity_and_mints_token) memset(&read_token, 0xee, sizeof(read_token)); UT_ASSERT_EQ(cluster_control_root_read_canonical_discovered(1, &snapshot, &read_token), CLUSTER_CONTROL_ROOT_OK_PRIMARY); - UT_ASSERT(cluster_control_root_identity_equal(&snapshot.identity, - &image.records[0].identity)); + UT_ASSERT(cluster_control_root_identity_equal(&snapshot.identity, &image.records[0].identity)); UT_ASSERT_EQ(snapshot.checkpoint_lower_lsn, UINT64_C(0x1000000)); /* The STRONG step mints the authority token (BOOTSTRAP never does). */ UT_ASSERT_EQ(read_token.file_txn_seq, 1); @@ -1706,8 +1626,8 @@ UT_TEST(test_valid_bak_blocks_corrupt_primary) memset(&snapshot, 0xee, sizeof(snapshot)); memset(&read_token, 0xee, sizeof(read_token)); UT_ASSERT_EQ(cluster_control_root_read_canonical(1, &image.records[0].identity, - CLUSTER_CONTROL_ROOT_READ_STRONG, - &snapshot, &read_token), + CLUSTER_CONTROL_ROOT_READ_STRONG, &snapshot, + &read_token), CLUSTER_CONTROL_ROOT_OK_BAK_BLOCKED); UT_ASSERT_EQ(snapshot.identity.system_identifier, 0); UT_ASSERT_EQ(read_token.file_txn_seq, 0); @@ -1798,8 +1718,7 @@ UT_TEST(test_restore_bit22_latch_from_active_root) UT_ASSERT_EQ(test_bit22_latch_apply_calls, 0); /* PREPARED root (create only) -> no restore (not ACTIVE). */ - UT_ASSERT_EQ(create_prepared(&image, &round, &prepared), - CLUSTER_CONTROL_ROOT_OK_PRIMARY); + UT_ASSERT_EQ(create_prepared(&image, &round, &prepared), CLUSTER_CONTROL_ROOT_OK_PRIMARY); test_bit22_latch_apply_calls = 0; UT_ASSERT(!cluster_control_root_restore_bit22_latch_if_active()); UT_ASSERT_EQ(test_bit22_latch_apply_calls, 0); @@ -1807,13 +1726,11 @@ UT_TEST(test_restore_bit22_latch_from_active_root) /* ACTIVE root but the OPEN record does not cross-match the round * identity -> no restore. */ round_sha256(&round, round_sha); - UT_ASSERT_EQ(cluster_control_root_activate_prepared(&prepared, round_sha, - &round, &active), + UT_ASSERT_EQ(cluster_control_root_activate_prepared(&prepared, round_sha, &round, &active), CLUSTER_CONTROL_ROOT_OK_PRIMARY); UT_ASSERT_EQ(active.activation_state, CLUSTER_CONTROL_ROOT_ACTIVATION_ACTIVE); test_decoded_open.transition_epoch = round.transition_epoch + 1; - test_decoded_open.record_generation - = round.prepare_generation + 2; /* epoch mismatch */ + test_decoded_open.record_generation = round.prepare_generation + 2; /* epoch mismatch */ test_bit22_latch_apply_calls = 0; UT_ASSERT(!cluster_control_root_restore_bit22_latch_if_active()); UT_ASSERT_EQ(test_bit22_latch_apply_calls, 0); @@ -1822,14 +1739,12 @@ UT_TEST(test_restore_bit22_latch_from_active_root) /* ACTIVE root + exact cross-match -> restored with the OPEN record's * round identity (TARGET_BOOTSTRAP). */ test_decoded_open.transition_epoch = round.transition_epoch; - test_decoded_open.record_generation - = round.prepare_generation + 2; + test_decoded_open.record_generation = round.prepare_generation + 2; test_bit22_latch_apply_calls = 0; UT_ASSERT(cluster_control_root_restore_bit22_latch_if_active()); UT_ASSERT_EQ(test_bit22_latch_apply_calls, 1); UT_ASSERT_EQ(test_bit22_latch_apply_epoch, round.transition_epoch); - UT_ASSERT_EQ(test_bit22_latch_apply_generation, - round.prepare_generation + 2); + UT_ASSERT_EQ(test_bit22_latch_apply_generation, round.prepare_generation + 2); UT_ASSERT(test_bit22_latch_active); /* Already armed -> no second apply. */ @@ -1839,15 +1754,12 @@ UT_TEST(test_restore_bit22_latch_from_active_root) /* Refused apply (census RED stand-in) -> fail-closed, gate stays off. */ wipe_root_files(); - UT_ASSERT_EQ(create_prepared(&image, &round, &prepared), - CLUSTER_CONTROL_ROOT_OK_PRIMARY); + UT_ASSERT_EQ(create_prepared(&image, &round, &prepared), CLUSTER_CONTROL_ROOT_OK_PRIMARY); round_sha256(&round, round_sha); - UT_ASSERT_EQ(cluster_control_root_activate_prepared(&prepared, round_sha, - &round, &active), + UT_ASSERT_EQ(cluster_control_root_activate_prepared(&prepared, round_sha, &round, &active), CLUSTER_CONTROL_ROOT_OK_PRIMARY); test_decoded_open.transition_epoch = round.transition_epoch; - test_decoded_open.record_generation - = round.prepare_generation + 2; + test_decoded_open.record_generation = round.prepare_generation + 2; test_bit22_latch_active = false; test_bit22_latch_apply_ok = false; test_bit22_latch_apply_calls = 0; @@ -1885,8 +1797,7 @@ UT_TEST(test_unbound_cutover_mutators_fail_before_cf_and_preserve_prepared_root) rename_calls_before = test_durable_rename_calls; memset(&active, 0xee, sizeof(active)); test_activate_authorized = false; - UT_ASSERT_EQ(cluster_control_root_activate_prepared( - &prepared, round_sha, &round, &active), + UT_ASSERT_EQ(cluster_control_root_activate_prepared(&prepared, round_sha, &round, &active), CLUSTER_CONTROL_ROOT_INVALID_ARGUMENT); UT_ASSERT_EQ(test_cf_lock_calls, lock_calls_before); UT_ASSERT_EQ(test_durable_rename_calls, rename_calls_before); @@ -1894,8 +1805,7 @@ UT_TEST(test_unbound_cutover_mutators_fail_before_cf_and_preserve_prepared_root) /* The refused attempt cannot consume or mutate the PREPARED image. */ test_activate_authorized = true; - UT_ASSERT_EQ(cluster_control_root_activate_prepared( - &prepared, round_sha, &round, &active), + UT_ASSERT_EQ(cluster_control_root_activate_prepared(&prepared, round_sha, &round, &active), CLUSTER_CONTROL_ROOT_OK_PRIMARY); UT_ASSERT_EQ(active.activation_state, CLUSTER_CONTROL_ROOT_ACTIVATION_ACTIVE); UT_ASSERT_EQ(active.file_txn_seq, prepared.file_txn_seq + 1); @@ -1915,8 +1825,8 @@ UT_TEST(test_native_cf_hold_cannot_authorize_strong_read) memset(&snapshot, 0xee, sizeof(snapshot)); memset(&token, 0xee, sizeof(token)); UT_ASSERT_EQ(cluster_control_root_read_canonical(1, &image.records[0].identity, - CLUSTER_CONTROL_ROOT_READ_STRONG, - &snapshot, &token), + CLUSTER_CONTROL_ROOT_READ_STRONG, &snapshot, + &token), CLUSTER_CONTROL_ROOT_LOCK_UNAVAILABLE); UT_ASSERT_EQ(snapshot.identity.system_identifier, 0); UT_ASSERT_EQ(token.file_txn_seq, 0); @@ -1989,8 +1899,8 @@ UT_TEST(test_forbidden_patch_rejected_before_cf_and_file_io) patch.expected_lifecycle = CLUSTER_CONTROL_ROOT_LIFECYCLE_CLOSED; test_cf_lock_calls = 0; UT_ASSERT_EQ(cluster_control_root_compare_and_publish( - &token, &patch, CLUSTER_CONTROL_ROOT_PUBLISH_THREAD_RETIRE, - &snapshot, NULL), CLUSTER_CONTROL_ROOT_INVALID_ARGUMENT); + &token, &patch, CLUSTER_CONTROL_ROOT_PUBLISH_THREAD_RETIRE, &snapshot, NULL), + CLUSTER_CONTROL_ROOT_INVALID_ARGUMENT); UT_ASSERT_EQ(test_cf_lock_calls, 0); } @@ -2007,14 +1917,14 @@ UT_TEST(test_lookup_and_revalidate_use_exact_primary_identity) wipe_root_files(); UT_ASSERT_EQ(create_prepared(&image, &round, &file_token), CLUSTER_CONTROL_ROOT_OK_PRIMARY); UT_ASSERT_EQ(cluster_control_root_read_canonical(1, &image.records[0].identity, - CLUSTER_CONTROL_ROOT_READ_STRONG, - &snapshot, &token), + CLUSTER_CONTROL_ROOT_READ_STRONG, &snapshot, + &token), CLUSTER_CONTROL_ROOT_OK_PRIMARY); - UT_ASSERT_EQ(cluster_control_root_revalidate(&token, &image.records[0].identity, - &snapshot), + UT_ASSERT_EQ(cluster_control_root_revalidate(&token, &image.records[0].identity, &snapshot), CLUSTER_CONTROL_ROOT_OK_PRIMARY); - UT_ASSERT_EQ(cluster_control_root_lookup_owner_by_node_runtime( - 0, &identity, &snapshot, &lookup_token), CLUSTER_CONTROL_ROOT_OK_PRIMARY); + UT_ASSERT_EQ( + cluster_control_root_lookup_owner_by_node_runtime(0, &identity, &snapshot, &lookup_token), + CLUSTER_CONTROL_ROOT_OK_PRIMARY); UT_ASSERT(cluster_control_root_identity_equal(&identity, &image.records[0].identity)); UT_ASSERT_EQ(lookup_token.file_txn_seq, token.file_txn_seq); } @@ -2033,22 +1943,24 @@ UT_TEST(test_lifecycle_publish_exact_token_cas) wipe_root_files(); UT_ASSERT_EQ(create_prepared(&image, &round, &file_token), CLUSTER_CONTROL_ROOT_OK_PRIMARY); UT_ASSERT_EQ(cluster_control_root_read_canonical(1, &image.records[0].identity, - CLUSTER_CONTROL_ROOT_READ_STRONG, - &snapshot, &read_token), + CLUSTER_CONTROL_ROOT_READ_STRONG, &snapshot, + &read_token), CLUSTER_CONTROL_ROOT_OK_PRIMARY); memset(&patch, 0, sizeof(patch)); patch.mask = CLUSTER_CONTROL_ROOT_PATCH_LIFECYCLE; patch.expected_lifecycle = CLUSTER_CONTROL_ROOT_LIFECYCLE_CLOSED; patch.desired.lifecycle = CLUSTER_CONTROL_ROOT_LIFECYCLE_RETIRED; UT_ASSERT_EQ(cluster_control_root_compare_and_publish( - &read_token, &patch, CLUSTER_CONTROL_ROOT_PUBLISH_THREAD_RETIRE, - &published, &new_token), CLUSTER_CONTROL_ROOT_OK_PRIMARY); + &read_token, &patch, CLUSTER_CONTROL_ROOT_PUBLISH_THREAD_RETIRE, &published, + &new_token), + CLUSTER_CONTROL_ROOT_OK_PRIMARY); UT_ASSERT_EQ(published.lifecycle, CLUSTER_CONTROL_ROOT_LIFECYCLE_RETIRED); UT_ASSERT_EQ(published.root_publish_seq, snapshot.root_publish_seq + 1); UT_ASSERT_EQ(new_token.file_txn_seq, read_token.file_txn_seq + 1); UT_ASSERT_EQ(cluster_control_root_compare_and_publish( - &read_token, &patch, CLUSTER_CONTROL_ROOT_PUBLISH_THREAD_RETIRE, - &published, &new_token), CLUSTER_CONTROL_ROOT_STALE_TOKEN); + &read_token, &patch, CLUSTER_CONTROL_ROOT_PUBLISH_THREAD_RETIRE, &published, + &new_token), + CLUSTER_CONTROL_ROOT_STALE_TOKEN); UT_ASSERT_EQ(test_walr_begin_calls, 0); UT_ASSERT_EQ(test_walr_end_calls, 0); } @@ -2066,25 +1978,24 @@ UT_TEST(test_retention_expanding_publish_refuses_before_cf_without_walr) wipe_root_files(); build_migration(&image, &round); - image.records[0].lifecycle = - CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_COMPLETE; + image.records[0].lifecycle = CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_COMPLETE; UT_ASSERT_EQ(cluster_control_root_create_prepared(&image, &round, &file_token), CLUSTER_CONTROL_ROOT_OK_PRIMARY); - UT_ASSERT_EQ(cluster_control_root_read_canonical( - 1, &image.records[0].identity, - CLUSTER_CONTROL_ROOT_READ_STRONG, &snapshot, &read_token), + UT_ASSERT_EQ(cluster_control_root_read_canonical(1, &image.records[0].identity, + CLUSTER_CONTROL_ROOT_READ_STRONG, &snapshot, + &read_token), CLUSTER_CONTROL_ROOT_OK_PRIMARY); - build_owner_rejoin_patch(&snapshot, - snapshot.identity.origin_owner_incarnation + 1, - snapshot.identity.root_lineage_seq + 1, &patch); + build_owner_rejoin_patch(&snapshot, snapshot.identity.origin_owner_incarnation + 1, + snapshot.identity.root_lineage_seq + 1, &patch); test_cf_lock_calls = 0; test_durable_rename_calls = 0; test_walr_begin_result = CLUSTER_WAL_PIN_UNAVAILABLE; memset(&published, 0xee, sizeof(published)); memset(&new_token, 0xee, sizeof(new_token)); - UT_ASSERT_EQ(cluster_control_root_compare_and_publish( - &read_token, &patch, CLUSTER_CONTROL_ROOT_PUBLISH_OWNER_REJOIN, - &published, &new_token), CLUSTER_CONTROL_ROOT_LOCK_UNAVAILABLE); + UT_ASSERT_EQ(cluster_control_root_compare_and_publish(&read_token, &patch, + CLUSTER_CONTROL_ROOT_PUBLISH_OWNER_REJOIN, + &published, &new_token), + CLUSTER_CONTROL_ROOT_LOCK_UNAVAILABLE); UT_ASSERT_EQ(test_walr_begin_calls, 1); UT_ASSERT_EQ(test_walr_thread, 1); UT_ASSERT_EQ(test_walr_end_calls, 0); @@ -2107,25 +2018,24 @@ UT_TEST(test_retention_expanding_publish_holds_walr_around_cf_and_readback) wipe_root_files(); build_migration(&image, &round); - image.records[0].lifecycle = - CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_COMPLETE; + image.records[0].lifecycle = CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_COMPLETE; UT_ASSERT_EQ(cluster_control_root_create_prepared(&image, &round, &file_token), CLUSTER_CONTROL_ROOT_OK_PRIMARY); - UT_ASSERT_EQ(cluster_control_root_read_canonical( - 1, &image.records[0].identity, - CLUSTER_CONTROL_ROOT_READ_STRONG, &snapshot, &read_token), + UT_ASSERT_EQ(cluster_control_root_read_canonical(1, &image.records[0].identity, + CLUSTER_CONTROL_ROOT_READ_STRONG, &snapshot, + &read_token), CLUSTER_CONTROL_ROOT_OK_PRIMARY); - build_owner_rejoin_patch(&snapshot, - snapshot.identity.origin_owner_incarnation + 1, - snapshot.identity.root_lineage_seq + 1, &patch); + build_owner_rejoin_patch(&snapshot, snapshot.identity.origin_owner_incarnation + 1, + snapshot.identity.root_lineage_seq + 1, &patch); test_order_seq = 0; test_walr_begin_order = 0; test_cf_acquire_order = 0; test_cf_release_order = 0; test_last_rename_order = 0; - UT_ASSERT_EQ(cluster_control_root_compare_and_publish( - &read_token, &patch, CLUSTER_CONTROL_ROOT_PUBLISH_OWNER_REJOIN, - &published, &new_token), CLUSTER_CONTROL_ROOT_OK_PRIMARY); + UT_ASSERT_EQ(cluster_control_root_compare_and_publish(&read_token, &patch, + CLUSTER_CONTROL_ROOT_PUBLISH_OWNER_REJOIN, + &published, &new_token), + CLUSTER_CONTROL_ROOT_OK_PRIMARY); UT_ASSERT_EQ(test_walr_begin_calls, 1); UT_ASSERT_EQ(test_walr_end_calls, 1); UT_ASSERT(test_walr_begin_order < test_cf_acquire_order); @@ -2150,11 +2060,10 @@ UT_TEST(test_unbound_publisher_fails_before_cf_and_preserves_root) wipe_root_files(); test_publish_authorized = true; - UT_ASSERT_EQ(create_prepared(&image, &round, &file_token), - CLUSTER_CONTROL_ROOT_OK_PRIMARY); - UT_ASSERT_EQ(cluster_control_root_read_canonical( - 1, &image.records[0].identity, - CLUSTER_CONTROL_ROOT_READ_STRONG, &before, &before_token), + UT_ASSERT_EQ(create_prepared(&image, &round, &file_token), CLUSTER_CONTROL_ROOT_OK_PRIMARY); + UT_ASSERT_EQ(cluster_control_root_read_canonical(1, &image.records[0].identity, + CLUSTER_CONTROL_ROOT_READ_STRONG, &before, + &before_token), CLUSTER_CONTROL_ROOT_OK_PRIMARY); memset(&patch, 0, sizeof(patch)); patch.mask = CLUSTER_CONTROL_ROOT_PATCH_LIFECYCLE; @@ -2165,18 +2074,17 @@ UT_TEST(test_unbound_publisher_fails_before_cf_and_preserves_root) lock_calls_before_publish = test_cf_lock_calls; test_publish_authorized = false; UT_ASSERT_EQ(cluster_control_root_compare_and_publish( - &before_token, &patch, - CLUSTER_CONTROL_ROOT_PUBLISH_THREAD_RETIRE, - &published, &published_token), + &before_token, &patch, CLUSTER_CONTROL_ROOT_PUBLISH_THREAD_RETIRE, &published, + &published_token), CLUSTER_CONTROL_ROOT_INVALID_ARGUMENT); UT_ASSERT_EQ(test_cf_lock_calls, lock_calls_before_publish); UT_ASSERT_EQ(published.identity.system_identifier, 0); UT_ASSERT_EQ(published_token.file_txn_seq, 0); test_publish_authorized = true; - UT_ASSERT_EQ(cluster_control_root_read_canonical( - 1, &image.records[0].identity, - CLUSTER_CONTROL_ROOT_READ_STRONG, &after, &after_token), + UT_ASSERT_EQ(cluster_control_root_read_canonical(1, &image.records[0].identity, + CLUSTER_CONTROL_ROOT_READ_STRONG, &after, + &after_token), CLUSTER_CONTROL_ROOT_OK_PRIMARY); UT_ASSERT_EQ(after.lifecycle, before.lifecycle); UT_ASSERT_EQ(after.root_publish_seq, before.root_publish_seq); @@ -2200,18 +2108,17 @@ UT_TEST(test_owner_rejoin_rejects_non_new_incarnation) UT_ASSERT_EQ(cluster_control_root_create_prepared(&image, &round, &file_token), CLUSTER_CONTROL_ROOT_OK_PRIMARY); UT_ASSERT_EQ(cluster_control_root_read_canonical(1, &image.records[0].identity, - CLUSTER_CONTROL_ROOT_READ_STRONG, - &snapshot, &read_token), + CLUSTER_CONTROL_ROOT_READ_STRONG, &snapshot, + &read_token), CLUSTER_CONTROL_ROOT_OK_PRIMARY); memset(&patch, 0, sizeof(patch)); patch.mask = UINT64_C(0x3b); patch.expected_lifecycle = CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_COMPLETE; patch.desired.lifecycle = CLUSTER_CONTROL_ROOT_LIFECYCLE_OPEN; - patch.desired.identity.origin_owner_incarnation = - snapshot.identity.origin_owner_incarnation; + patch.desired.identity.origin_owner_incarnation = snapshot.identity.origin_owner_incarnation; patch.desired.identity.root_lineage_seq = snapshot.identity.root_lineage_seq + 1; - patch.desired.root_flags = CLUSTER_CONTROL_ROOT_FLAG_CLAIM_VALID - | CLUSTER_CONTROL_ROOT_FLAG_CHECKPOINT_VALID; + patch.desired.root_flags + = CLUSTER_CONTROL_ROOT_FLAG_CLAIM_VALID | CLUSTER_CONTROL_ROOT_FLAG_CHECKPOINT_VALID; patch.desired.checkpoint_tli = snapshot.checkpoint_tli; patch.desired.checkpoint_source_kind = snapshot.checkpoint_source_kind; patch.desired.checkpoint_lower_lsn = snapshot.checkpoint_lower_lsn; @@ -2219,9 +2126,10 @@ UT_TEST(test_owner_rejoin_rejects_non_new_incarnation) patch.desired.recovered_through_lsn_exclusive = snapshot.checkpoint_lower_lsn; memset(&published, 0xee, sizeof(published)); memset(&new_token, 0xee, sizeof(new_token)); - UT_ASSERT_EQ(cluster_control_root_compare_and_publish( - &read_token, &patch, CLUSTER_CONTROL_ROOT_PUBLISH_OWNER_REJOIN, - &published, &new_token), CLUSTER_CONTROL_ROOT_CAS_CONFLICT); + UT_ASSERT_EQ(cluster_control_root_compare_and_publish(&read_token, &patch, + CLUSTER_CONTROL_ROOT_PUBLISH_OWNER_REJOIN, + &published, &new_token), + CLUSTER_CONTROL_ROOT_CAS_CONFLICT); UT_ASSERT_EQ(published.identity.system_identifier, 0); UT_ASSERT_EQ(new_token.file_txn_seq, 0); } @@ -2244,15 +2152,16 @@ UT_TEST(test_owner_rejoin_advances_exact_lineage_and_exhausts_at_max) image.records[0].lifecycle = CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_COMPLETE; UT_ASSERT_EQ(cluster_control_root_create_prepared(&image, &round, &file_token), CLUSTER_CONTROL_ROOT_OK_PRIMARY); - UT_ASSERT_EQ(cluster_control_root_lookup_owner_by_node_runtime( - 0, &identity, &snapshot, &read_token), - CLUSTER_CONTROL_ROOT_OK_PRIMARY); + UT_ASSERT_EQ( + cluster_control_root_lookup_owner_by_node_runtime(0, &identity, &snapshot, &read_token), + CLUSTER_CONTROL_ROOT_OK_PRIMARY); new_incarnation = snapshot.identity.origin_owner_incarnation + 1; - build_owner_rejoin_patch(&snapshot, new_incarnation, - snapshot.identity.root_lineage_seq + 1, &patch); - UT_ASSERT_EQ(cluster_control_root_compare_and_publish( - &read_token, &patch, CLUSTER_CONTROL_ROOT_PUBLISH_OWNER_REJOIN, - &published, &new_token), CLUSTER_CONTROL_ROOT_OK_PRIMARY); + build_owner_rejoin_patch(&snapshot, new_incarnation, snapshot.identity.root_lineage_seq + 1, + &patch); + UT_ASSERT_EQ(cluster_control_root_compare_and_publish(&read_token, &patch, + CLUSTER_CONTROL_ROOT_PUBLISH_OWNER_REJOIN, + &published, &new_token), + CLUSTER_CONTROL_ROOT_OK_PRIMARY); UT_ASSERT_EQ(published.lifecycle, CLUSTER_CONTROL_ROOT_LIFECYCLE_OPEN); UT_ASSERT_EQ(published.identity.origin_owner_incarnation, new_incarnation); UT_ASSERT_EQ(published.identity.root_lineage_seq, 2); @@ -2265,18 +2174,18 @@ UT_TEST(test_owner_rejoin_advances_exact_lineage_and_exhausts_at_max) UT_ASSERT_EQ(cluster_control_root_create_prepared(&image, &round, &file_token), CLUSTER_CONTROL_ROOT_OK_PRIMARY); force_first_record_lineage(UINT64_MAX); - UT_ASSERT_EQ(cluster_control_root_lookup_owner_by_node_runtime( - 0, &identity, &snapshot, &read_token), - CLUSTER_CONTROL_ROOT_OK_PRIMARY); + UT_ASSERT_EQ( + cluster_control_root_lookup_owner_by_node_runtime(0, &identity, &snapshot, &read_token), + CLUSTER_CONTROL_ROOT_OK_PRIMARY); UT_ASSERT_EQ(snapshot.identity.root_lineage_seq, UINT64_MAX); - build_owner_rejoin_patch(&snapshot, - snapshot.identity.origin_owner_incarnation + 1, - UINT64_C(1), &patch); + build_owner_rejoin_patch(&snapshot, snapshot.identity.origin_owner_incarnation + 1, UINT64_C(1), + &patch); memset(&published, 0xee, sizeof(published)); memset(&new_token, 0xee, sizeof(new_token)); - UT_ASSERT_EQ(cluster_control_root_compare_and_publish( - &read_token, &patch, CLUSTER_CONTROL_ROOT_PUBLISH_OWNER_REJOIN, - &published, &new_token), CLUSTER_CONTROL_ROOT_CAS_CONFLICT); + UT_ASSERT_EQ(cluster_control_root_compare_and_publish(&read_token, &patch, + CLUSTER_CONTROL_ROOT_PUBLISH_OWNER_REJOIN, + &published, &new_token), + CLUSTER_CONTROL_ROOT_CAS_CONFLICT); UT_ASSERT_EQ(published.identity.system_identifier, 0); UT_ASSERT_EQ(new_token.file_txn_seq, 0); } @@ -2301,21 +2210,21 @@ UT_TEST(test_lifecycle_frozen_shape_matrix) image.records[0].lifecycle = CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_COMPLETE; UT_ASSERT_EQ(cluster_control_root_create_prepared(&image, &round, &file_token), CLUSTER_CONTROL_ROOT_OK_PRIMARY); - UT_ASSERT_EQ(cluster_control_root_lookup_owner_by_node_runtime( - 0, &identity, &snapshot, &read_token), - CLUSTER_CONTROL_ROOT_OK_PRIMARY); + UT_ASSERT_EQ( + cluster_control_root_lookup_owner_by_node_runtime(0, &identity, &snapshot, &read_token), + CLUSTER_CONTROL_ROOT_OK_PRIMARY); new_incarnation = snapshot.identity.origin_owner_incarnation + 1; - build_owner_rejoin_patch(&snapshot, new_incarnation, - snapshot.identity.root_lineage_seq + 1, &patch); + build_owner_rejoin_patch(&snapshot, new_incarnation, snapshot.identity.root_lineage_seq + 1, + &patch); memset(&published, 0xee, sizeof(published)); memset(&new_token, 0xee, sizeof(new_token)); - UT_ASSERT_EQ(cluster_control_root_compare_and_publish( - &read_token, &patch, CLUSTER_CONTROL_ROOT_PUBLISH_OWNER_REJOIN, - &published, &new_token), CLUSTER_CONTROL_ROOT_OK_PRIMARY); + UT_ASSERT_EQ(cluster_control_root_compare_and_publish(&read_token, &patch, + CLUSTER_CONTROL_ROOT_PUBLISH_OWNER_REJOIN, + &published, &new_token), + CLUSTER_CONTROL_ROOT_OK_PRIMARY); UT_ASSERT_EQ(published.lifecycle, CLUSTER_CONTROL_ROOT_LIFECYCLE_OPEN); UT_ASSERT_EQ(published.identity.origin_owner_incarnation, new_incarnation); - UT_ASSERT_EQ(published.identity.root_lineage_seq, - snapshot.identity.root_lineage_seq + 1); + UT_ASSERT_EQ(published.identity.root_lineage_seq, snapshot.identity.root_lineage_seq + 1); /* ② OWNER_REJOIN from OPEN is rejected by patch_shape_valid BEFORE any * CF / file I/O (STOP-02 §17.4: pre-lifecycle must be @@ -2325,20 +2234,20 @@ UT_TEST(test_lifecycle_frozen_shape_matrix) image.records[0].lifecycle = CLUSTER_CONTROL_ROOT_LIFECYCLE_OPEN; UT_ASSERT_EQ(cluster_control_root_create_prepared(&image, &round, &file_token), CLUSTER_CONTROL_ROOT_OK_PRIMARY); - UT_ASSERT_EQ(cluster_control_root_lookup_owner_by_node_runtime( - 0, &identity, &snapshot, &read_token), - CLUSTER_CONTROL_ROOT_OK_PRIMARY); - build_owner_rejoin_patch(&snapshot, - snapshot.identity.origin_owner_incarnation + 1, - snapshot.identity.root_lineage_seq + 1, &patch); + UT_ASSERT_EQ( + cluster_control_root_lookup_owner_by_node_runtime(0, &identity, &snapshot, &read_token), + CLUSTER_CONTROL_ROOT_OK_PRIMARY); + build_owner_rejoin_patch(&snapshot, snapshot.identity.origin_owner_incarnation + 1, + snapshot.identity.root_lineage_seq + 1, &patch); patch.expected_lifecycle = CLUSTER_CONTROL_ROOT_LIFECYCLE_OPEN; test_cf_lock_calls = 0; test_durable_rename_calls = 0; memset(&published, 0xee, sizeof(published)); memset(&new_token, 0xee, sizeof(new_token)); - UT_ASSERT_EQ(cluster_control_root_compare_and_publish( - &read_token, &patch, CLUSTER_CONTROL_ROOT_PUBLISH_OWNER_REJOIN, - &published, &new_token), CLUSTER_CONTROL_ROOT_INVALID_ARGUMENT); + UT_ASSERT_EQ(cluster_control_root_compare_and_publish(&read_token, &patch, + CLUSTER_CONTROL_ROOT_PUBLISH_OWNER_REJOIN, + &published, &new_token), + CLUSTER_CONTROL_ROOT_INVALID_ARGUMENT); UT_ASSERT_EQ(published.identity.system_identifier, 0); UT_ASSERT_EQ(new_token.file_txn_seq, 0); UT_ASSERT_EQ(test_cf_lock_calls, 0); @@ -2352,20 +2261,20 @@ UT_TEST(test_lifecycle_frozen_shape_matrix) image.records[0].lifecycle = CLUSTER_CONTROL_ROOT_LIFECYCLE_CLOSED; UT_ASSERT_EQ(cluster_control_root_create_prepared(&image, &round, &file_token), CLUSTER_CONTROL_ROOT_OK_PRIMARY); - UT_ASSERT_EQ(cluster_control_root_lookup_owner_by_node_runtime( - 0, &identity, &snapshot, &read_token), - CLUSTER_CONTROL_ROOT_OK_PRIMARY); - build_owner_rejoin_patch(&snapshot, - snapshot.identity.origin_owner_incarnation + 1, - snapshot.identity.root_lineage_seq + 1, &patch); + UT_ASSERT_EQ( + cluster_control_root_lookup_owner_by_node_runtime(0, &identity, &snapshot, &read_token), + CLUSTER_CONTROL_ROOT_OK_PRIMARY); + build_owner_rejoin_patch(&snapshot, snapshot.identity.origin_owner_incarnation + 1, + snapshot.identity.root_lineage_seq + 1, &patch); patch.expected_lifecycle = CLUSTER_CONTROL_ROOT_LIFECYCLE_CLOSED; test_cf_lock_calls = 0; test_durable_rename_calls = 0; memset(&published, 0xee, sizeof(published)); memset(&new_token, 0xee, sizeof(new_token)); - UT_ASSERT_EQ(cluster_control_root_compare_and_publish( - &read_token, &patch, CLUSTER_CONTROL_ROOT_PUBLISH_OWNER_REJOIN, - &published, &new_token), CLUSTER_CONTROL_ROOT_INVALID_ARGUMENT); + UT_ASSERT_EQ(cluster_control_root_compare_and_publish(&read_token, &patch, + CLUSTER_CONTROL_ROOT_PUBLISH_OWNER_REJOIN, + &published, &new_token), + CLUSTER_CONTROL_ROOT_INVALID_ARGUMENT); UT_ASSERT_EQ(published.identity.system_identifier, 0); UT_ASSERT_EQ(new_token.file_txn_seq, 0); UT_ASSERT_EQ(test_cf_lock_calls, 0); @@ -2378,17 +2287,16 @@ UT_TEST(test_lifecycle_frozen_shape_matrix) image.records[0].lifecycle = CLUSTER_CONTROL_ROOT_LIFECYCLE_CLOSED; UT_ASSERT_EQ(cluster_control_root_create_prepared(&image, &round, &file_token), CLUSTER_CONTROL_ROOT_OK_PRIMARY); - UT_ASSERT_EQ(cluster_control_root_lookup_owner_by_node_runtime( - 0, &identity, &snapshot, &read_token), - CLUSTER_CONTROL_ROOT_OK_PRIMARY); + UT_ASSERT_EQ( + cluster_control_root_lookup_owner_by_node_runtime(0, &identity, &snapshot, &read_token), + CLUSTER_CONTROL_ROOT_OK_PRIMARY); new_incarnation = snapshot.identity.origin_owner_incarnation + 1; memset(&patch, 0, sizeof(patch)); patch.mask = UINT64_C(0x3b); patch.expected_lifecycle = CLUSTER_CONTROL_ROOT_LIFECYCLE_CLOSED; patch.desired.lifecycle = CLUSTER_CONTROL_ROOT_LIFECYCLE_OPEN; patch.desired.identity.origin_owner_incarnation = new_incarnation; - patch.desired.identity.root_lineage_seq = - snapshot.identity.root_lineage_seq + 1; + patch.desired.identity.root_lineage_seq = snapshot.identity.root_lineage_seq + 1; patch.desired.root_flags = snapshot.root_flags; patch.desired.checkpoint_tli = snapshot.checkpoint_tli; patch.desired.checkpoint_source_kind = snapshot.checkpoint_source_kind; @@ -2396,25 +2304,22 @@ UT_TEST(test_lifecycle_frozen_shape_matrix) patch.desired.checkpoint_record_crc32c = snapshot.checkpoint_record_crc32c; patch.desired.tail_tli = snapshot.tail_tli; patch.desired.tail_validation_kind = snapshot.tail_validation_kind; - patch.desired.validated_tail_lsn_exclusive = - snapshot.validated_tail_lsn_exclusive; + patch.desired.validated_tail_lsn_exclusive = snapshot.validated_tail_lsn_exclusive; patch.desired.tail_last_record_lsn = snapshot.tail_last_record_lsn; patch.desired.tail_last_record_crc32c = snapshot.tail_last_record_crc32c; patch.desired.recovered_tli = snapshot.recovered_tli; - patch.desired.recovered_through_lsn_exclusive = - snapshot.recovered_through_lsn_exclusive; + patch.desired.recovered_through_lsn_exclusive = snapshot.recovered_through_lsn_exclusive; patch.desired.recovered_last_record_lsn = snapshot.recovered_last_record_lsn; - patch.desired.recovered_last_record_crc32c = - snapshot.recovered_last_record_crc32c; + patch.desired.recovered_last_record_crc32c = snapshot.recovered_last_record_crc32c; memset(&published, 0xee, sizeof(published)); memset(&new_token, 0xee, sizeof(new_token)); - UT_ASSERT_EQ(cluster_control_root_compare_and_publish( - &read_token, &patch, CLUSTER_CONTROL_ROOT_PUBLISH_THREAD_OPEN, - &published, &new_token), CLUSTER_CONTROL_ROOT_OK_PRIMARY); + UT_ASSERT_EQ(cluster_control_root_compare_and_publish(&read_token, &patch, + CLUSTER_CONTROL_ROOT_PUBLISH_THREAD_OPEN, + &published, &new_token), + CLUSTER_CONTROL_ROOT_OK_PRIMARY); UT_ASSERT_EQ(published.lifecycle, CLUSTER_CONTROL_ROOT_LIFECYCLE_OPEN); UT_ASSERT_EQ(published.identity.origin_owner_incarnation, new_incarnation); - UT_ASSERT_EQ(published.identity.root_lineage_seq, - snapshot.identity.root_lineage_seq + 1); + UT_ASSERT_EQ(published.identity.root_lineage_seq, snapshot.identity.root_lineage_seq + 1); } UT_TEST(test_initial_migration_requires_lineage_one) @@ -2446,8 +2351,8 @@ UT_TEST(test_unconfirmed_release_returns_no_authority) memset(&snapshot, 0xee, sizeof(snapshot)); memset(&token, 0xee, sizeof(token)); UT_ASSERT_EQ(cluster_control_root_read_canonical(1, &image.records[0].identity, - CLUSTER_CONTROL_ROOT_READ_STRONG, - &snapshot, &token), + CLUSTER_CONTROL_ROOT_READ_STRONG, &snapshot, + &token), CLUSTER_CONTROL_ROOT_RELEASE_UNCERTAIN); UT_ASSERT_EQ(snapshot.identity.system_identifier, 0); UT_ASSERT_EQ(token.file_txn_seq, 0); @@ -2490,8 +2395,8 @@ UT_TEST(test_reserved_bytes_and_symlink_fail_closed) write_all_or_abort(primary, bytes, sizeof(bytes)); unlink(bak); UT_ASSERT_EQ(cluster_control_root_read_canonical(1, &image.records[0].identity, - CLUSTER_CONTROL_ROOT_READ_STRONG, - &snapshot, NULL), + CLUSTER_CONTROL_ROOT_READ_STRONG, &snapshot, + NULL), CLUSTER_CONTROL_ROOT_BAD_RESERVED); wipe_root_files(); diff --git a/src/test/cluster_unit/test_cluster_cr_server_policy.c b/src/test/cluster_unit/test_cluster_cr_server_policy.c index 88f2c6b5e8a..bd07bf6ae56 100644 --- a/src/test/cluster_unit/test_cluster_cr_server_policy.c +++ b/src/test/cluster_unit/test_cluster_cr_server_policy.c @@ -68,15 +68,12 @@ VariableCache ShmemVariableCache = &c0_variable_cache; * origin CLOG abort is positive ABORTED authority, while "not committed" by * itself remains UNKNOWN_FAIL_CLOSED. */ -extern ClusterUndoVerdictKind -cluster_cr_server_resolved_scn_verdict(bool clog_did_commit, bool clog_did_abort, - bool xid_is_in_progress); -extern bool cluster_cr_server_live_binding_exact(bool xid_is_mine, - uint32 expected_segment_id, - uint32 expected_tt_slot_id, - uint16 matched_segment, - uint16 matched_slot, - bool xid_is_in_progress, +extern ClusterUndoVerdictKind cluster_cr_server_resolved_scn_verdict(bool clog_did_commit, + bool clog_did_abort, + bool xid_is_in_progress); +extern bool cluster_cr_server_live_binding_exact(bool xid_is_mine, uint32 expected_segment_id, + uint32 expected_tt_slot_id, uint16 matched_segment, + uint16 matched_slot, bool xid_is_in_progress, bool durable_binding_stable); /* @@ -87,19 +84,20 @@ extern bool cluster_cr_server_live_binding_exact(bool xid_is_mine, * product header before the RED receipt is captured. */ extern ClusterUndoVerdictKind cluster_cr_server_c0_zero_match_verdict( - bool authoritative, bool xid_is_mine, uint32 expected_segment_id, - uint32 expected_tt_slot_id, bool no_raw_reuse_window, bool clog_is_committed, - bool clog_is_aborted, bool clog_is_in_progress, bool xid_is_in_progress); -extern ClusterUndoVerdictKind cluster_cr_server_test_own_xid_verdict( - TransactionId xid, uint32 expected_segment_id, uint32 expected_tt_slot_id, - bool authoritative); + bool authoritative, bool xid_is_mine, uint32 expected_segment_id, uint32 expected_tt_slot_id, + bool no_raw_reuse_window, bool clog_is_committed, bool clog_is_aborted, + bool clog_is_in_progress, bool xid_is_in_progress); +extern ClusterUndoVerdictKind cluster_cr_server_test_own_xid_verdict(TransactionId xid, + uint32 expected_segment_id, + uint32 expected_tt_slot_id, + bool authoritative); extern bool cluster_cr_server_test_undo_verdict_serve(ClusterLmsCrSlot *slot); extern bool cluster_cr_server_test_multi_verdict_serve(ClusterLmsCrSlot *slot); extern const char *cluster_cr_server_test_ordinary_reason(TransactionId xid, uint32 segment_hint, ClusterUndoVerdictKind *kind); -extern ClusterUndoVerdictResult cluster_cr_server_test_own_xid_pair_verdict( - TransactionId xid, uint32 expected_segment_id, uint32 expected_tt_slot_id, - SCN proposed_scn); +extern ClusterUndoVerdictResult +cluster_cr_server_test_own_xid_pair_verdict(TransactionId xid, uint32 expected_segment_id, + uint32 expected_tt_slot_id, SCN proposed_scn); extern const char *cluster_cr_server_test_own_xid_pair_reason(TransactionId xid, uint32 expected_segment_id, uint32 expected_tt_slot_id, @@ -107,15 +105,14 @@ extern const char *cluster_cr_server_test_own_xid_pair_reason(TransactionId xid, ClusterUndoVerdictResult *out); extern bool cluster_cr_server_test_pair_detail_admit(uint32 *emitted); extern bool cluster_cr_server_freshref_c1b_pair_request_decode( - const GcsBlockForwardPayload *fwd, int32 authenticated_source_node, - int32 local_node, uint64 current_epoch, int max_backends, - uint32 *segment_id, TransactionId *xid, uint32 *expected_tt_slot_id, - SCN *proposed_scn); + const GcsBlockForwardPayload *fwd, int32 authenticated_source_node, int32 local_node, + uint64 current_epoch, int max_backends, uint32 *segment_id, TransactionId *xid, + uint32 *expected_tt_slot_id, SCN *proposed_scn); extern ClusterUndoVerdictKind cluster_cr_server_freshref_c1b_pair_verdict( - bool pair_request, bool xid_is_mine, uint32 expected_segment_id, - uint32 expected_tt_slot_id, bool no_raw_reuse_window, XidStatus raw_status, - ClusterTTDurableResolve resolve, uint16 matched_segment, uint16 matched_slot, - SCN resolved_scn, SCN proposed_scn, bool retention_ok, SCN horizon_scn); + bool pair_request, bool xid_is_mine, uint32 expected_segment_id, uint32 expected_tt_slot_id, + bool no_raw_reuse_window, XidStatus raw_status, ClusterTTDurableResolve resolve, + uint16 matched_segment, uint16 matched_slot, SCN resolved_scn, SCN proposed_scn, + bool retention_ok, SCN horizon_scn); typedef enum C0TestEvent { C0_EV_SCAN = 1, @@ -283,8 +280,7 @@ TransactionIdDidAbort(TransactionId xid pg_attribute_unused()) bool TransactionIdIsInProgress(TransactionId xid pg_attribute_unused()) { - UT_ASSERT_EQ(c0_native_lock_depth, - c0_expect_procarray_under_native_lock ? 1 : 0); + UT_ASSERT_EQ(c0_native_lock_depth, c0_expect_procarray_under_native_lock ? 1 : 0); UT_ASSERT_EQ(c0_xact_lock_depth, 0); c0_procarray_calls++; c0_note(C0_EV_PROCARRAY); @@ -539,8 +535,8 @@ scn_time_cmp(SCN a, SCN b) bool cluster_xid_native_prehistory_provable_full(uint64 next_full_xid pg_attribute_unused(), - uint64 covered_hw_full pg_attribute_unused(), - TransactionId xid pg_attribute_unused()) + uint64 covered_hw_full pg_attribute_unused(), + TransactionId xid pg_attribute_unused()) { c0_native_provable_calls++; return false; @@ -779,16 +775,14 @@ UT_TEST(test_resolved_scn_explicit_abort_after_stamp_is_positive) = source != NULL ? strstr(source, "case CLUSTER_TT_DURABLE_RESOLVED_SCN:") : NULL; const char *resolved_end = resolved != NULL ? strstr(resolved, "if (cluster_cr_accept_resolved_scn(scn))") : NULL; - const char *exact_gate - = resolved != NULL ? strstr(resolved, "if (exact_binding)") : NULL; + const char *exact_gate = resolved != NULL ? strstr(resolved, "if (exact_binding)") : NULL; const char *did_abort = exact_gate != NULL ? strstr(exact_gate, "TransactionIdDidAbort(xid)") : NULL; const char *abort_verdict = did_abort != NULL ? strstr(did_abort, "CLUSTER_UNDO_VERDICT_ABORTED") : NULL; - const char *unknown - = abort_verdict != NULL - ? strstr(abort_verdict, "CLUSTER_UNDO_VERDICT_UNKNOWN_FAIL_CLOSED") - : NULL; + const char *unknown = abort_verdict != NULL + ? strstr(abort_verdict, "CLUSTER_UNDO_VERDICT_UNKNOWN_FAIL_CLOSED") + : NULL; UT_ASSERT_EQ((int)cluster_cr_server_resolved_scn_verdict(false, true, false), (int)CLUSTER_UNDO_VERDICT_ABORTED); @@ -865,45 +859,45 @@ UT_TEST(test_resolved_scn_commit_between_clog_and_procarray_rechecks_exact_bindi */ UT_TEST(test_c0_zero_match_positive_proof_table) { - UT_ASSERT_EQ((int)cluster_cr_server_c0_zero_match_verdict( - true, true, 1, 1, true, false, true, false, false), + UT_ASSERT_EQ((int)cluster_cr_server_c0_zero_match_verdict(true, true, 1, 1, true, false, true, + false, false), (int)CLUSTER_UNDO_VERDICT_ABORTED); - UT_ASSERT_EQ((int)cluster_cr_server_c0_zero_match_verdict( - true, true, 1, 1, true, false, false, true, true), + UT_ASSERT_EQ((int)cluster_cr_server_c0_zero_match_verdict(true, true, 1, 1, true, false, false, + true, true), (int)CLUSTER_UNDO_VERDICT_IN_PROGRESS); /* Commit-without-SCN, SUB_COMMITTED/unknown and contradictory samples. */ - UT_ASSERT_EQ((int)cluster_cr_server_c0_zero_match_verdict( - true, true, 1, 1, true, true, false, false, false), + UT_ASSERT_EQ((int)cluster_cr_server_c0_zero_match_verdict(true, true, 1, 1, true, true, false, + false, false), (int)CLUSTER_UNDO_VERDICT_UNKNOWN_FAIL_CLOSED); - UT_ASSERT_EQ((int)cluster_cr_server_c0_zero_match_verdict( - true, true, 1, 1, true, false, false, false, false), + UT_ASSERT_EQ((int)cluster_cr_server_c0_zero_match_verdict(true, true, 1, 1, true, false, false, + false, false), (int)CLUSTER_UNDO_VERDICT_UNKNOWN_FAIL_CLOSED); - UT_ASSERT_EQ((int)cluster_cr_server_c0_zero_match_verdict( - true, true, 1, 1, true, false, true, false, true), + UT_ASSERT_EQ((int)cluster_cr_server_c0_zero_match_verdict(true, true, 1, 1, true, false, true, + false, true), (int)CLUSTER_UNDO_VERDICT_UNKNOWN_FAIL_CLOSED); /* Every carrier/no-reuse gate is fail-closed. */ - UT_ASSERT_EQ((int)cluster_cr_server_c0_zero_match_verdict( - false, true, 1, 1, true, false, true, false, false), + UT_ASSERT_EQ((int)cluster_cr_server_c0_zero_match_verdict(false, true, 1, 1, true, false, true, + false, false), (int)CLUSTER_UNDO_VERDICT_UNKNOWN_FAIL_CLOSED); - UT_ASSERT_EQ((int)cluster_cr_server_c0_zero_match_verdict( - true, false, 1, 1, true, false, true, false, false), + UT_ASSERT_EQ((int)cluster_cr_server_c0_zero_match_verdict(true, false, 1, 1, true, false, true, + false, false), (int)CLUSTER_UNDO_VERDICT_UNKNOWN_FAIL_CLOSED); - UT_ASSERT_EQ((int)cluster_cr_server_c0_zero_match_verdict( - true, true, 0, 1, true, false, true, false, false), + UT_ASSERT_EQ((int)cluster_cr_server_c0_zero_match_verdict(true, true, 0, 1, true, false, true, + false, false), (int)CLUSTER_UNDO_VERDICT_UNKNOWN_FAIL_CLOSED); - UT_ASSERT_EQ((int)cluster_cr_server_c0_zero_match_verdict( - true, true, UINT32_C(65536), 1, true, false, true, false, false), + UT_ASSERT_EQ((int)cluster_cr_server_c0_zero_match_verdict(true, true, UINT32_C(65536), 1, true, + false, true, false, false), (int)CLUSTER_UNDO_VERDICT_UNKNOWN_FAIL_CLOSED); - UT_ASSERT_EQ((int)cluster_cr_server_c0_zero_match_verdict( - true, true, 1, 0, true, false, true, false, false), + UT_ASSERT_EQ((int)cluster_cr_server_c0_zero_match_verdict(true, true, 1, 0, true, false, true, + false, false), (int)CLUSTER_UNDO_VERDICT_UNKNOWN_FAIL_CLOSED); - UT_ASSERT_EQ((int)cluster_cr_server_c0_zero_match_verdict( - true, true, 1, 49, true, false, true, false, false), + UT_ASSERT_EQ((int)cluster_cr_server_c0_zero_match_verdict(true, true, 1, 49, true, false, true, + false, false), (int)CLUSTER_UNDO_VERDICT_UNKNOWN_FAIL_CLOSED); - UT_ASSERT_EQ((int)cluster_cr_server_c0_zero_match_verdict( - true, true, 1, 1, false, false, true, false, false), + UT_ASSERT_EQ((int)cluster_cr_server_c0_zero_match_verdict(true, true, 1, 1, false, false, true, + false, false), (int)CLUSTER_UNDO_VERDICT_UNKNOWN_FAIL_CLOSED); } @@ -913,69 +907,65 @@ UT_TEST(test_c0_zero_match_positive_proof_table) * COMMITTED_BOUND. */ UT_TEST(test_freshref_c1b_pair_exact_truth_table) { - const SCN proposed = (SCN) 10498; + const SCN proposed = (SCN)10498; - UT_ASSERT_EQ((int) cluster_cr_server_freshref_c1b_pair_verdict( - true, true, 7, 1, true, TRANSACTION_STATUS_COMMITTED, - CLUSTER_TT_DURABLE_RESOLVED_SCN, 7, 0, proposed, proposed, - false, InvalidScn), - (int) CLUSTER_UNDO_VERDICT_COMMITTED_EXACT); - UT_ASSERT_EQ((int) cluster_cr_server_freshref_c1b_pair_verdict( - true, true, 7, 1, true, TRANSACTION_STATUS_COMMITTED, - CLUSTER_TT_DURABLE_RECYCLED_ZERO_MATCH, 0, 0, InvalidScn, - proposed, true, proposed), - (int) CLUSTER_UNDO_VERDICT_COMMITTED_EXACT); + UT_ASSERT_EQ((int)cluster_cr_server_freshref_c1b_pair_verdict( + true, true, 7, 1, true, TRANSACTION_STATUS_COMMITTED, + CLUSTER_TT_DURABLE_RESOLVED_SCN, 7, 0, proposed, proposed, false, InvalidScn), + (int)CLUSTER_UNDO_VERDICT_COMMITTED_EXACT); + UT_ASSERT_EQ((int)cluster_cr_server_freshref_c1b_pair_verdict( + true, true, 7, 1, true, TRANSACTION_STATUS_COMMITTED, + CLUSTER_TT_DURABLE_RECYCLED_ZERO_MATCH, 0, 0, InvalidScn, proposed, true, + proposed), + (int)CLUSTER_UNDO_VERDICT_COMMITTED_EXACT); /* Pair identity, no-reuse and literal origin CLOG are all mandatory. */ - UT_ASSERT_EQ((int) cluster_cr_server_freshref_c1b_pair_verdict( - false, true, 7, 1, true, TRANSACTION_STATUS_COMMITTED, - CLUSTER_TT_DURABLE_RECYCLED_ZERO_MATCH, 0, 0, InvalidScn, - proposed, true, proposed), - (int) CLUSTER_UNDO_VERDICT_UNKNOWN_FAIL_CLOSED); - UT_ASSERT_EQ((int) cluster_cr_server_freshref_c1b_pair_verdict( - true, true, 7, 1, false, TRANSACTION_STATUS_COMMITTED, - CLUSTER_TT_DURABLE_RECYCLED_ZERO_MATCH, 0, 0, InvalidScn, - proposed, true, proposed), - (int) CLUSTER_UNDO_VERDICT_UNKNOWN_FAIL_CLOSED); - UT_ASSERT_EQ((int) cluster_cr_server_freshref_c1b_pair_verdict( - true, true, 7, 1, true, TRANSACTION_STATUS_ABORTED, - CLUSTER_TT_DURABLE_RECYCLED_ZERO_MATCH, 0, 0, InvalidScn, - proposed, true, proposed), - (int) CLUSTER_UNDO_VERDICT_UNKNOWN_FAIL_CLOSED); + UT_ASSERT_EQ((int)cluster_cr_server_freshref_c1b_pair_verdict( + false, true, 7, 1, true, TRANSACTION_STATUS_COMMITTED, + CLUSTER_TT_DURABLE_RECYCLED_ZERO_MATCH, 0, 0, InvalidScn, proposed, true, + proposed), + (int)CLUSTER_UNDO_VERDICT_UNKNOWN_FAIL_CLOSED); + UT_ASSERT_EQ((int)cluster_cr_server_freshref_c1b_pair_verdict( + true, true, 7, 1, false, TRANSACTION_STATUS_COMMITTED, + CLUSTER_TT_DURABLE_RECYCLED_ZERO_MATCH, 0, 0, InvalidScn, proposed, true, + proposed), + (int)CLUSTER_UNDO_VERDICT_UNKNOWN_FAIL_CLOSED); + UT_ASSERT_EQ((int)cluster_cr_server_freshref_c1b_pair_verdict( + true, true, 7, 1, true, TRANSACTION_STATUS_ABORTED, + CLUSTER_TT_DURABLE_RECYCLED_ZERO_MATCH, 0, 0, InvalidScn, proposed, true, + proposed), + (int)CLUSTER_UNDO_VERDICT_UNKNOWN_FAIL_CLOSED); /* Live match requires exact segment, 1-based slot and SCN. */ - UT_ASSERT_EQ((int) cluster_cr_server_freshref_c1b_pair_verdict( - true, true, 7, 1, true, TRANSACTION_STATUS_COMMITTED, - CLUSTER_TT_DURABLE_RESOLVED_SCN, 8, 0, proposed, proposed, - false, InvalidScn), - (int) CLUSTER_UNDO_VERDICT_UNKNOWN_FAIL_CLOSED); - UT_ASSERT_EQ((int) cluster_cr_server_freshref_c1b_pair_verdict( - true, true, 7, 1, true, TRANSACTION_STATUS_COMMITTED, - CLUSTER_TT_DURABLE_RESOLVED_SCN, 7, 1, proposed, proposed, - false, InvalidScn), - (int) CLUSTER_UNDO_VERDICT_UNKNOWN_FAIL_CLOSED); - UT_ASSERT_EQ((int) cluster_cr_server_freshref_c1b_pair_verdict( - true, true, 7, 1, true, TRANSACTION_STATUS_COMMITTED, - CLUSTER_TT_DURABLE_RESOLVED_SCN, 7, 0, proposed + 1, proposed, - false, InvalidScn), - (int) CLUSTER_UNDO_VERDICT_UNKNOWN_FAIL_CLOSED); + UT_ASSERT_EQ((int)cluster_cr_server_freshref_c1b_pair_verdict( + true, true, 7, 1, true, TRANSACTION_STATUS_COMMITTED, + CLUSTER_TT_DURABLE_RESOLVED_SCN, 8, 0, proposed, proposed, false, InvalidScn), + (int)CLUSTER_UNDO_VERDICT_UNKNOWN_FAIL_CLOSED); + UT_ASSERT_EQ((int)cluster_cr_server_freshref_c1b_pair_verdict( + true, true, 7, 1, true, TRANSACTION_STATUS_COMMITTED, + CLUSTER_TT_DURABLE_RESOLVED_SCN, 7, 1, proposed, proposed, false, InvalidScn), + (int)CLUSTER_UNDO_VERDICT_UNKNOWN_FAIL_CLOSED); + UT_ASSERT_EQ((int)cluster_cr_server_freshref_c1b_pair_verdict( + true, true, 7, 1, true, TRANSACTION_STATUS_COMMITTED, + CLUSTER_TT_DURABLE_RESOLVED_SCN, 7, 0, proposed + 1, proposed, false, + InvalidScn), + (int)CLUSTER_UNDO_VERDICT_UNKNOWN_FAIL_CLOSED); /* Recycled zero-match requires retention and proposed <= frozen horizon. */ - UT_ASSERT_EQ((int) cluster_cr_server_freshref_c1b_pair_verdict( - true, true, 7, 1, true, TRANSACTION_STATUS_COMMITTED, - CLUSTER_TT_DURABLE_RECYCLED_ZERO_MATCH, 0, 0, InvalidScn, - proposed, false, proposed), - (int) CLUSTER_UNDO_VERDICT_UNKNOWN_FAIL_CLOSED); - UT_ASSERT_EQ((int) cluster_cr_server_freshref_c1b_pair_verdict( - true, true, 7, 1, true, TRANSACTION_STATUS_COMMITTED, - CLUSTER_TT_DURABLE_RECYCLED_ZERO_MATCH, 0, 0, InvalidScn, - proposed, true, proposed - 1), - (int) CLUSTER_UNDO_VERDICT_UNKNOWN_FAIL_CLOSED); - UT_ASSERT_EQ((int) cluster_cr_server_freshref_c1b_pair_verdict( - true, true, 7, 1, true, TRANSACTION_STATUS_COMMITTED, - CLUSTER_TT_DURABLE_AMBIGUOUS_WRAP, 0, 0, InvalidScn, - proposed, true, proposed), - (int) CLUSTER_UNDO_VERDICT_UNKNOWN_FAIL_CLOSED); + UT_ASSERT_EQ((int)cluster_cr_server_freshref_c1b_pair_verdict( + true, true, 7, 1, true, TRANSACTION_STATUS_COMMITTED, + CLUSTER_TT_DURABLE_RECYCLED_ZERO_MATCH, 0, 0, InvalidScn, proposed, false, + proposed), + (int)CLUSTER_UNDO_VERDICT_UNKNOWN_FAIL_CLOSED); + UT_ASSERT_EQ((int)cluster_cr_server_freshref_c1b_pair_verdict( + true, true, 7, 1, true, TRANSACTION_STATUS_COMMITTED, + CLUSTER_TT_DURABLE_RECYCLED_ZERO_MATCH, 0, 0, InvalidScn, proposed, true, + proposed - 1), + (int)CLUSTER_UNDO_VERDICT_UNKNOWN_FAIL_CLOSED); + UT_ASSERT_EQ((int)cluster_cr_server_freshref_c1b_pair_verdict( + true, true, 7, 1, true, TRANSACTION_STATUS_COMMITTED, + CLUSTER_TT_DURABLE_AMBIGUOUS_WRAP, 0, 0, InvalidScn, proposed, true, proposed), + (int)CLUSTER_UNDO_VERDICT_UNKNOWN_FAIL_CLOSED); } UT_TEST(test_freshref_c1b_pair_real_resolver_holds_no_reuse_through_c1b) @@ -1022,10 +1012,8 @@ UT_TEST(test_freshref_c1b_pair_real_resolver_holds_no_reuse_through_c1b) c0_retention_ok = true; c0_horizon_scn = proposed + 2; c0_raw_status = TRANSACTION_STATUS_COMMITTED; - result = cluster_cr_server_test_own_xid_pair_verdict( - 4195136, 7, 1, proposed); - UT_ASSERT_EQ((int)result.kind, - (int)CLUSTER_UNDO_VERDICT_COMMITTED_EXACT); + result = cluster_cr_server_test_own_xid_pair_verdict(4195136, 7, 1, proposed); + UT_ASSERT_EQ((int)result.kind, (int)CLUSTER_UNDO_VERDICT_COMMITTED_EXACT); UT_ASSERT_EQ((uint64)result.commit_scn, (uint64)proposed); UT_ASSERT_EQ(c0_raw_clog_calls, 1); UT_ASSERT_EQ(c0_retention_calls, 0); @@ -1041,8 +1029,7 @@ UT_TEST(test_freshref_c1b_pair_real_resolver_holds_no_reuse_through_c1b) c0_raw_status = TRANSACTION_STATUS_COMMITTED; c0_disable_before_native_recheck = true; result = cluster_cr_server_test_own_xid_pair_verdict(4195136, 7, 1, proposed); - UT_ASSERT_EQ((int)result.kind, - (int)CLUSTER_UNDO_VERDICT_UNKNOWN_FAIL_CLOSED); + UT_ASSERT_EQ((int)result.kind, (int)CLUSTER_UNDO_VERDICT_UNKNOWN_FAIL_CLOSED); UT_ASSERT_EQ(c0_raw_clog_calls, 0); UT_ASSERT_EQ(c0_retention_calls, 0); UT_ASSERT_EQ(c0_native_lock_depth, 0); @@ -1067,8 +1054,8 @@ UT_TEST(test_freshref_c1b_pair_request_canonical_decode) GcsBlockForwardPayloadSetExpectedPiWatermarkScn(&fwd, (SCN)10498); GcsBlockForwardPayloadSetUndoFreshRefC1bPairRequest(&fwd); - UT_ASSERT(cluster_cr_server_freshref_c1b_pair_request_decode( - &fwd, 1, 0, 11, 8, &segment, &xid, &slot, &proposed)); + UT_ASSERT(cluster_cr_server_freshref_c1b_pair_request_decode(&fwd, 1, 0, 11, 8, &segment, &xid, + &slot, &proposed)); UT_ASSERT_EQ(segment, 7); UT_ASSERT_EQ(xid, (TransactionId)4195136); UT_ASSERT_EQ(slot, 1); @@ -1078,36 +1065,36 @@ UT_TEST(test_freshref_c1b_pair_request_canonical_decode) * the runtime requester/origin pair gate must additionally hold a current * homogeneous R4 TARGET admission before it can send or consume it. */ fwd.epoch = 0; - UT_ASSERT(cluster_cr_server_freshref_c1b_pair_request_decode( - &fwd, 1, 0, 0, 8, NULL, NULL, NULL, NULL)); + UT_ASSERT(cluster_cr_server_freshref_c1b_pair_request_decode(&fwd, 1, 0, 0, 8, NULL, NULL, NULL, + NULL)); fwd.epoch = 11; /* Every transport/canonical identity axis independently fails closed. */ fwd.epoch = 12; - UT_ASSERT(!cluster_cr_server_freshref_c1b_pair_request_decode( - &fwd, 1, 0, 11, 8, NULL, NULL, NULL, NULL)); + UT_ASSERT(!cluster_cr_server_freshref_c1b_pair_request_decode(&fwd, 1, 0, 11, 8, NULL, NULL, + NULL, NULL)); fwd.epoch = 11; - UT_ASSERT(!cluster_cr_server_freshref_c1b_pair_request_decode( - &fwd, 2, 0, 11, 8, NULL, NULL, NULL, NULL)); + UT_ASSERT(!cluster_cr_server_freshref_c1b_pair_request_decode(&fwd, 2, 0, 11, 8, NULL, NULL, + NULL, NULL)); fwd.master_node = 2; - UT_ASSERT(!cluster_cr_server_freshref_c1b_pair_request_decode( - &fwd, 1, 0, 11, 8, NULL, NULL, NULL, NULL)); + UT_ASSERT(!cluster_cr_server_freshref_c1b_pair_request_decode(&fwd, 1, 0, 11, 8, NULL, NULL, + NULL, NULL)); fwd.master_node = 1; fwd.requester_backend_id = 9; - UT_ASSERT(!cluster_cr_server_freshref_c1b_pair_request_decode( - &fwd, 1, 0, 11, 8, NULL, NULL, NULL, NULL)); + UT_ASSERT(!cluster_cr_server_freshref_c1b_pair_request_decode(&fwd, 1, 0, 11, 8, NULL, NULL, + NULL, NULL)); fwd.requester_backend_id = 4; fwd.reserved_0[0] = 1; - UT_ASSERT(!cluster_cr_server_freshref_c1b_pair_request_decode( - &fwd, 1, 0, 11, 8, NULL, NULL, NULL, NULL)); + UT_ASSERT(!cluster_cr_server_freshref_c1b_pair_request_decode(&fwd, 1, 0, 11, 8, NULL, NULL, + NULL, NULL)); fwd.reserved_0[0] = 0; GcsBlockForwardPayloadSetExpectedPiWatermarkScn(&fwd, InvalidScn); - UT_ASSERT(!cluster_cr_server_freshref_c1b_pair_request_decode( - &fwd, 1, 0, 11, 8, NULL, NULL, NULL, NULL)); + UT_ASSERT(!cluster_cr_server_freshref_c1b_pair_request_decode(&fwd, 1, 0, 11, 8, NULL, NULL, + NULL, NULL)); GcsBlockForwardPayloadSetExpectedPiWatermarkScn(&fwd, (SCN)10498); GcsBlockForwardPayloadSetUndoVerdictRequest(&fwd, true); - UT_ASSERT(!cluster_cr_server_freshref_c1b_pair_request_decode( - &fwd, 1, 0, 11, 8, NULL, NULL, NULL, NULL)); + UT_ASSERT(!cluster_cr_server_freshref_c1b_pair_request_decode(&fwd, 1, 0, 11, 8, NULL, NULL, + NULL, NULL)); } /* Observe the actual resolver, without promoting an old refusal to success. */ @@ -1604,15 +1591,12 @@ UT_TEST(test_r4_cr_build_inline_entry_is_denied_without_serve) = source != NULL ? strstr(source, "\ncluster_gcs_block_forward_serve_inline(") : NULL; const char *function_end = function != NULL ? strstr(function, "\n}\n\n#endif") : NULL; const char *kind_switch = function != NULL ? strstr(function, "\tswitch (kind) {") : NULL; - const char *r4_case - = kind_switch != NULL - ? strstr(kind_switch, "case CLUSTER_LMS_SLOT_KIND_R4_CR_BUILD:") - : NULL; - const char *deny_jump - = r4_case != NULL ? strstr(r4_case, "goto inline_deny_no_serve;") : NULL; + const char *r4_case = kind_switch != NULL + ? strstr(kind_switch, "case CLUSTER_LMS_SLOT_KIND_R4_CR_BUILD:") + : NULL; + const char *deny_jump = r4_case != NULL ? strstr(r4_case, "goto inline_deny_no_serve;") : NULL; const char *serve = kind_switch != NULL ? strstr(kind_switch, "cr_serve_slot(&slot);") : NULL; - const char *deny_label - = serve != NULL ? strstr(serve, "\ninline_deny_no_serve:") : NULL; + const char *deny_label = serve != NULL ? strstr(serve, "\ninline_deny_no_serve:") : NULL; const char *reply = deny_label != NULL ? strstr(deny_label, "cr_build_and_send_reply(&slot);") : NULL; @@ -1624,12 +1608,10 @@ UT_TEST(test_r4_cr_build_inline_entry_is_denied_without_serve) UT_ASSERT_NOT_NULL(serve); UT_ASSERT_NOT_NULL(deny_label); UT_ASSERT_NOT_NULL(reply); - if (function != NULL && function_end != NULL && kind_switch != NULL - && r4_case != NULL && deny_jump != NULL && serve != NULL - && deny_label != NULL && reply != NULL) - UT_ASSERT(function < kind_switch && kind_switch < r4_case - && r4_case < deny_jump && deny_jump < serve - && serve < deny_label && deny_label < reply + if (function != NULL && function_end != NULL && kind_switch != NULL && r4_case != NULL + && deny_jump != NULL && serve != NULL && deny_label != NULL && reply != NULL) + UT_ASSERT(function < kind_switch && kind_switch < r4_case && r4_case < deny_jump + && deny_jump < serve && serve < deny_label && deny_label < reply && reply < function_end); free(source); } @@ -1646,32 +1628,21 @@ UT_TEST(test_r4_cr_build_inline_entry_is_denied_without_serve) UT_TEST(test_lms_exact_status22_preempts_legacy_tt_scan_convoy) { char *source = read_cr_server_source(); - const char *function - = source != NULL ? strstr(source, "\ncluster_lms_cr_drain(") : NULL; + const char *function = source != NULL ? strstr(source, "\ncluster_lms_cr_drain(") : NULL; const char *function_end - = function != NULL - ? strstr(function, "\n}\n\n/*\n * cluster_lms_cr_ship_ready") - : NULL; + = function != NULL ? strstr(function, "\n}\n\n/*\n * cluster_lms_cr_ship_ready") : NULL; const char *exact_drain - = function != NULL - ? strstr(function, "cluster_gcs_block_r4_tx_resolve_drain();") - : NULL; - const char *exact_active - = exact_drain != NULL - ? strstr(exact_drain, "cluster_gcs_block_r4_tx_resolve_active()") - : NULL; + = function != NULL ? strstr(function, "cluster_gcs_block_r4_tx_resolve_drain();") : NULL; + const char *exact_active = exact_drain != NULL + ? strstr(exact_drain, "cluster_gcs_block_r4_tx_resolve_active()") + : NULL; const char *cursor - = exact_active != NULL - ? strstr(exact_active, "cluster_lms_cr_legacy_drain_cursor") - : NULL; - const char *single_serve - = cursor != NULL ? strstr(cursor, "cr_serve_slot(slot);") : NULL; - const char *advance - = single_serve != NULL - ? strstr(single_serve, "cluster_lms_cr_legacy_drain_cursor =") - : NULL; - const char *bounded_break - = advance != NULL ? strstr(advance, "break;") : NULL; + = exact_active != NULL ? strstr(exact_active, "cluster_lms_cr_legacy_drain_cursor") : NULL; + const char *single_serve = cursor != NULL ? strstr(cursor, "cr_serve_slot(slot);") : NULL; + const char *advance = single_serve != NULL + ? strstr(single_serve, "cluster_lms_cr_legacy_drain_cursor =") + : NULL; + const char *bounded_break = advance != NULL ? strstr(advance, "break;") : NULL; UT_ASSERT_NOT_NULL(function); UT_ASSERT_NOT_NULL(function_end); @@ -1681,12 +1652,10 @@ UT_TEST(test_lms_exact_status22_preempts_legacy_tt_scan_convoy) UT_ASSERT_NOT_NULL(single_serve); UT_ASSERT_NOT_NULL(advance); UT_ASSERT_NOT_NULL(bounded_break); - if (function != NULL && function_end != NULL && exact_drain != NULL - && exact_active != NULL && cursor != NULL && single_serve != NULL - && advance != NULL && bounded_break != NULL) - UT_ASSERT(function < exact_drain && exact_drain < exact_active - && exact_active < cursor && cursor < single_serve - && single_serve < advance && advance < bounded_break + if (function != NULL && function_end != NULL && exact_drain != NULL && exact_active != NULL + && cursor != NULL && single_serve != NULL && advance != NULL && bounded_break != NULL) + UT_ASSERT(function < exact_drain && exact_drain < exact_active && exact_active < cursor + && cursor < single_serve && single_serve < advance && advance < bounded_break && bounded_break < function_end); free(source); } diff --git a/src/test/cluster_unit/test_cluster_cssd.c b/src/test/cluster_unit/test_cluster_cssd.c index fc1eb2259d2..d0b71fbd0bc 100644 --- a/src/test/cluster_unit/test_cluster_cssd.c +++ b/src/test/cluster_unit/test_cluster_cssd.c @@ -156,8 +156,7 @@ LWLockAcquire(LWLock *lock pg_attribute_unused(), LWLockMode mode pg_attribute_u return true; } bool -LWLockConditionalAcquire(LWLock *lock pg_attribute_unused(), - LWLockMode mode pg_attribute_unused()) +LWLockConditionalAcquire(LWLock *lock pg_attribute_unused(), LWLockMode mode pg_attribute_unused()) { ut_lwlock_conditional_calls++; return ut_lwlock_conditional_result; @@ -595,8 +594,7 @@ UT_TEST(test_t12_no_pgproc_status_reads_never_block) ut_lwlock_blocking_calls = 0; ut_lwlock_conditional_calls = 0; - UT_ASSERT_EQ((int)cluster_cssd_get_status(), - (int)CLUSTER_CSSD_STARTING); + UT_ASSERT_EQ((int)cluster_cssd_get_status(), (int)CLUSTER_CSSD_STARTING); UT_ASSERT(!cluster_cssd_wait_for_ready(250)); UT_ASSERT_EQ(ut_lwlock_blocking_calls, 0); UT_ASSERT(ut_lwlock_conditional_calls >= 2); @@ -604,8 +602,7 @@ UT_TEST(test_t12_no_pgproc_status_reads_never_block) ut_lwlock_conditional_result = true; ut_lwlock_blocking_calls = 0; ut_lwlock_conditional_calls = 0; - UT_ASSERT_EQ((int)cluster_cssd_get_status(), - (int)CLUSTER_CSSD_STARTING); + UT_ASSERT_EQ((int)cluster_cssd_get_status(), (int)CLUSTER_CSSD_STARTING); UT_ASSERT_EQ(ut_lwlock_blocking_calls, 0); UT_ASSERT_EQ(ut_lwlock_conditional_calls, 1); @@ -613,8 +610,7 @@ UT_TEST(test_t12_no_pgproc_status_reads_never_block) MyProc = &fake_proc; ut_lwlock_blocking_calls = 0; ut_lwlock_conditional_calls = 0; - UT_ASSERT_EQ((int)cluster_cssd_get_status(), - (int)CLUSTER_CSSD_STARTING); + UT_ASSERT_EQ((int)cluster_cssd_get_status(), (int)CLUSTER_CSSD_STARTING); UT_ASSERT_EQ(ut_lwlock_blocking_calls, 1); UT_ASSERT_EQ(ut_lwlock_conditional_calls, 0); MyProc = NULL; diff --git a/src/test/cluster_unit/test_cluster_ctrc_itl_reuse.c b/src/test/cluster_unit/test_cluster_ctrc_itl_reuse.c index 147507ac302..3be11727780 100644 --- a/src/test/cluster_unit/test_cluster_ctrc_itl_reuse.c +++ b/src/test/cluster_unit/test_cluster_ctrc_itl_reuse.c @@ -1240,7 +1240,7 @@ UT_TEST(test_effective_old_lock_is_not_logical_data_history) reuse_tuple()->t_infomask = lock_shape == 0 ? HEAP_XMAX_LOCK_ONLY : lock_shape == 1 ? HEAP_XMAX_LOCK_ONLY | HEAP_XMAX_EXCL_LOCK - : HEAP_XMAX_EXCL_LOCK; + : HEAP_XMAX_EXCL_LOCK; HeapTupleHeaderSetXmax(reuse_tuple(), reuse_receipt.key.xid); reuse_expect_retained(); } diff --git a/src/test/cluster_unit/test_cluster_debug.c b/src/test/cluster_unit/test_cluster_debug.c index 12a7375f377..4e3652afc13 100644 --- a/src/test/cluster_unit/test_cluster_debug.c +++ b/src/test/cluster_unit/test_cluster_debug.c @@ -51,7 +51,7 @@ #include "cluster/cluster_hang.h" /* spec-5.11: ClusterHangDumpData for dump_hang stubs */ #include "cluster/cluster_hang_resolve.h" /* spec-5.12: ClusterHangResolveCounters for dump stubs */ #include "cluster/cluster_lmd.h" -#include "cluster/cluster_reconfig.h" /* spec-5.14 D6 touched getter stubs */ +#include "cluster/cluster_reconfig.h" /* spec-5.14 D6 touched getter stubs */ #include "cluster/cluster_semantic_activation.h" /* R4 writer snapshot stub */ #include "cluster/cluster_hw_snapshot.h" #include "cluster/cluster_r4_observe.h" @@ -849,30 +849,23 @@ cluster_dl_release_count(void) } /* STOP03 §10.3 dump_ir stubs (cluster_ir_lock.c is not linked here). */ -#define DEFINE_RECOVERY_SERIAL_COUNTER_STUB(name) \ - uint64 name(void); \ - uint64 name(void) \ - { \ - return 0; \ +#define DEFINE_RECOVERY_SERIAL_COUNTER_STUB(name) \ + uint64 name(void); \ + uint64 name(void) \ + { \ + return 0; \ } DEFINE_RECOVERY_SERIAL_COUNTER_STUB(cluster_recovery_serial_grant_count) DEFINE_RECOVERY_SERIAL_COUNTER_STUB(cluster_recovery_serial_busy_count) DEFINE_RECOVERY_SERIAL_COUNTER_STUB(cluster_recovery_serial_retry_count) -DEFINE_RECOVERY_SERIAL_COUNTER_STUB( - cluster_recovery_serial_revalidate_reject_count) -DEFINE_RECOVERY_SERIAL_COUNTER_STUB( - cluster_recovery_serial_node_cleanup_wait_count) -DEFINE_RECOVERY_SERIAL_COUNTER_STUB( - cluster_recovery_serial_release_confirmed_count) -DEFINE_RECOVERY_SERIAL_COUNTER_STUB( - cluster_recovery_serial_release_unconfirmed_count) -DEFINE_RECOVERY_SERIAL_COUNTER_STUB( - cluster_recovery_serial_cold_set_grant_count) -DEFINE_RECOVERY_SERIAL_COUNTER_STUB( - cluster_recovery_serial_capability_denied_count) -DEFINE_RECOVERY_SERIAL_COUNTER_STUB( - cluster_recovery_serial_native_result_rejected_count) +DEFINE_RECOVERY_SERIAL_COUNTER_STUB(cluster_recovery_serial_revalidate_reject_count) +DEFINE_RECOVERY_SERIAL_COUNTER_STUB(cluster_recovery_serial_node_cleanup_wait_count) +DEFINE_RECOVERY_SERIAL_COUNTER_STUB(cluster_recovery_serial_release_confirmed_count) +DEFINE_RECOVERY_SERIAL_COUNTER_STUB(cluster_recovery_serial_release_unconfirmed_count) +DEFINE_RECOVERY_SERIAL_COUNTER_STUB(cluster_recovery_serial_cold_set_grant_count) +DEFINE_RECOVERY_SERIAL_COUNTER_STUB(cluster_recovery_serial_capability_denied_count) +DEFINE_RECOVERY_SERIAL_COUNTER_STUB(cluster_recovery_serial_native_result_rejected_count) #undef DEFINE_RECOVERY_SERIAL_COUNTER_STUB @@ -986,10 +979,10 @@ cluster_write_fence_get_baseline_authority_age_us(void) { return 0; } -#define DEFINE_EXTERNAL_FENCE_COUNTER_STUB(name) \ - uint64 cluster_write_fence_get_external_##name(void) \ - { \ - return 0; \ +#define DEFINE_EXTERNAL_FENCE_COUNTER_STUB(name) \ + uint64 cluster_write_fence_get_external_##name(void) \ + { \ + return 0; \ } DEFINE_EXTERNAL_FENCE_COUNTER_STUB(admit_requested) DEFINE_EXTERNAL_FENCE_COUNTER_STUB(write_excluded) @@ -3578,8 +3571,7 @@ LWLockAcquire(LWLock *lock pg_attribute_unused(), LWLockMode mode pg_attribute_u * LWLock reads; the debug unit never runs those paths, so the stub simply * reports acquire success and never blocks. */ bool -LWLockConditionalAcquire(LWLock *lock pg_attribute_unused(), - LWLockMode mode pg_attribute_unused()) +LWLockConditionalAcquire(LWLock *lock pg_attribute_unused(), LWLockMode mode pg_attribute_unused()) { return true; } @@ -3633,17 +3625,17 @@ cluster_wal_thread_id(void) ClusterFormationWitnessResult cluster_formation_witness_build_live_wait(uint16 origin_thread pg_attribute_unused(), - int timeout_ms pg_attribute_unused(), - ClusterFormationWitnessV1 **out) + int timeout_ms pg_attribute_unused(), + ClusterFormationWitnessV1 **out) { *out = NULL; return CLUSTER_FORMATION_WITNESS_CAPABILITY_UNAVAILABLE; } ClusterFormationWitnessResult -cluster_formation_witness_build_recovery_control_wait( - uint16 origin_thread pg_attribute_unused(), - int timeout_ms pg_attribute_unused(), ClusterFormationWitnessV1 **out) +cluster_formation_witness_build_recovery_control_wait(uint16 origin_thread pg_attribute_unused(), + int timeout_ms pg_attribute_unused(), + ClusterFormationWitnessV1 **out) { *out = NULL; return CLUSTER_FORMATION_WITNESS_CAPABILITY_UNAVAILABLE; @@ -3657,9 +3649,8 @@ cluster_formation_witness_destroy(ClusterFormationWitnessV1 **witness) bool cluster_formation_witness_copy_classification_v1( - const ClusterFormationWitnessV1 *witness pg_attribute_unused(), - uint16 *origin_thread, ClusterFenceAuthorityProof *authority, - ClusterFormationSnapshotV1 *snapshot) + const ClusterFormationWitnessV1 *witness pg_attribute_unused(), uint16 *origin_thread, + ClusterFenceAuthorityProof *authority, ClusterFormationSnapshotV1 *snapshot) { memset(authority, 0, sizeof(*authority)); memset(snapshot, 0, sizeof(*snapshot)); @@ -3692,9 +3683,8 @@ cluster_formation_snapshot_matches_v1( } bool -cluster_reconfig_capture_formation_snapshot_v1( - uint16 origin_thread pg_attribute_unused(), - ClusterFormationSnapshotV1 *snapshot) +cluster_reconfig_capture_formation_snapshot_v1(uint16 origin_thread pg_attribute_unused(), + ClusterFormationSnapshotV1 *snapshot) { memset(snapshot, 0, sizeof(*snapshot)); return false; @@ -3721,17 +3711,15 @@ cluster_membership_get_last_admitted_incarnation(int32 node_id pg_attribute_unus bool cluster_grd_recovery_authority_barrier_wait( const ClusterFormationSnapshotV1 *formation pg_attribute_unused(), - uint64 boot_incarnation pg_attribute_unused(), - uint64 lms_generation pg_attribute_unused(), + uint64 boot_incarnation pg_attribute_unused(), uint64 lms_generation pg_attribute_unused(), int timeout_ms pg_attribute_unused()) { return false; } bool -cluster_grd_recovery_authority_is_current( - uint64 boot_incarnation pg_attribute_unused(), - uint64 lms_generation pg_attribute_unused()) +cluster_grd_recovery_authority_is_current(uint64 boot_incarnation pg_attribute_unused(), + uint64 lms_generation pg_attribute_unused()) { return false; } @@ -3739,8 +3727,7 @@ cluster_grd_recovery_authority_is_current( bool cluster_grd_serving_authority_rebind_lmon( const ClusterFormationSnapshotV1 *formation pg_attribute_unused(), - uint64 boot_incarnation pg_attribute_unused(), - uint64 lms_generation pg_attribute_unused()) + uint64 boot_incarnation pg_attribute_unused(), uint64 lms_generation pg_attribute_unused()) { return false; } @@ -3751,8 +3738,7 @@ cluster_grd_serving_authority_rebind_lmon( bool cluster_grd_serving_authority_rebind_leaver( const ClusterFormationSnapshotV1 *formation pg_attribute_unused(), - uint64 boot_incarnation pg_attribute_unused(), - uint64 lms_generation pg_attribute_unused()) + uint64 boot_incarnation pg_attribute_unused(), uint64 lms_generation pg_attribute_unused()) { return false; } @@ -3806,8 +3792,7 @@ cluster_reconfig_stage_pre_publish_join_handoff( void cluster_cf_phase2_verify_or_fail(const char *pgdata pg_attribute_unused()) -{ -} +{} bool cluster_cf_phase2_peer_verified(void) @@ -5127,8 +5112,8 @@ UT_TEST(test_debug_dump_exposes_native_pcm_grd_lifecycle_stats) UT_ASSERT_STR_EQ(captured_dump_value("pcm", "pcm_grd_capacity_retry_count"), "6"); UT_ASSERT_STR_EQ(captured_dump_value("pcm", "pcm_grd_capacity_fail_count"), "7"); UT_ASSERT_STR_EQ(captured_dump_value("pcm", "pcm_grd_peak_live_entries"), "12"); - UT_ASSERT_STR_EQ(captured_dump_value("pcm", - "pcm_grd_reclaim_refused_pcm_mode_not_n_count"), "9"); + UT_ASSERT_STR_EQ(captured_dump_value("pcm", "pcm_grd_reclaim_refused_pcm_mode_not_n_count"), + "9"); UT_ASSERT_EQ(captured_dump_count("pcm", "pcm_x_runtime_state"), 0); } @@ -5339,8 +5324,7 @@ UT_TEST(test_debug_dump_exposes_closed_ctrc_observability) (void)cluster_dump_state(fcinfo); for (i = 0; i < CTRC_STAT_COUNT; i++) - UT_ASSERT_EQ(captured_dump_count("ctrc", - cluster_ctrc_stat_name((ClusterCtrcStatId)i)), 1); + UT_ASSERT_EQ(captured_dump_count("ctrc", cluster_ctrc_stat_name((ClusterCtrcStatId)i)), 1); UT_ASSERT_STR_EQ(captured_dump_value("ctrc", "cleaner_reason"), "NONE"); UT_ASSERT_EQ(captured_dump_count("ctrc", "test_barrier_phase"), 1); UT_ASSERT_EQ(captured_dump_count("ctrc", "test_barrier_hit_count"), 1); diff --git a/src/test/cluster_unit/test_cluster_epoch.c b/src/test/cluster_unit/test_cluster_epoch.c index 87327768952..da1c550d886 100644 --- a/src/test/cluster_unit/test_cluster_epoch.c +++ b/src/test/cluster_unit/test_cluster_epoch.c @@ -92,8 +92,7 @@ cluster_write_fence_authority_cache_mutation_begin(void) } void -cluster_write_fence_authority_cache_mutation_end( - uint64 odd_sequence pg_attribute_unused()) +cluster_write_fence_authority_cache_mutation_end(uint64 odd_sequence pg_attribute_unused()) {} /* diff --git a/src/test/cluster_unit/test_cluster_epoch_ballot_codec.c b/src/test/cluster_unit/test_cluster_epoch_ballot_codec.c index 0d7836a3e3b..a41942ba199 100644 --- a/src/test/cluster_unit/test_cluster_epoch_ballot_codec.c +++ b/src/test/cluster_unit/test_cluster_epoch_ballot_codec.c @@ -20,11 +20,9 @@ UT_DEFINE_GLOBALS(); void -ExceptionalCondition(const char *conditionName, const char *fileName, - int lineNumber) +ExceptionalCondition(const char *conditionName, const char *fileName, int lineNumber) { - printf("# Assert failed: %s at %s:%d\n", conditionName, fileName, - lineNumber); + printf("# Assert failed: %s at %s:%d\n", conditionName, fileName, lineNumber); abort(); } @@ -98,10 +96,9 @@ static void expected_ballot_bytes(uint8 out[CLUSTER_EPOCH_BALLOT_ID_BYTES]) { static const uint8 bytes[CLUSTER_EPOCH_BALLOT_ID_BYTES] = { - 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, - 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x18, 0x17, 0x16, 0x15, 0x14, 0x13, 0x12, 0x11, - 0x28, 0x27, 0x26, 0x25, 0x24, 0x23, 0x22, 0x21, + 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x07, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x17, 0x16, 0x15, 0x14, 0x13, + 0x12, 0x11, 0x28, 0x27, 0x26, 0x25, 0x24, 0x23, 0x22, 0x21, }; memcpy(out, bytes, sizeof(bytes)); @@ -112,21 +109,14 @@ static void expected_value_bytes(uint8 out[CLUSTER_EPOCH_AUTHORITY_VALUE_BYTES]) { static const uint8 bytes[CLUSTER_EPOCH_AUTHORITY_VALUE_BYTES] = { - 0x01, 0x00, 0x02, 0x05, 0x02, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x38, 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x31, - 0x48, 0x47, 0x46, 0x45, 0x44, 0x43, 0x42, 0x41, - 0x49, 0x47, 0x46, 0x45, 0x44, 0x43, 0x42, 0x41, - 0x58, 0x57, 0x56, 0x55, 0x54, 0x53, 0x52, 0x51, - 0x68, 0x67, 0x66, 0x65, 0x64, 0x63, 0x62, 0x61, - 0x78, 0x77, 0x76, 0x75, 0x74, 0x73, 0x72, 0x71, - 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xe4, 0x05, 0x89, 0x42, 0x5b, 0xae, 0x0d, 0x8e, - 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, - 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, + 0x01, 0x00, 0x02, 0x05, 0x02, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x38, 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x31, 0x48, 0x47, 0x46, 0x45, 0x44, 0x43, + 0x42, 0x41, 0x49, 0x47, 0x46, 0x45, 0x44, 0x43, 0x42, 0x41, 0x58, 0x57, 0x56, 0x55, 0x54, + 0x53, 0x52, 0x51, 0x68, 0x67, 0x66, 0x65, 0x64, 0x63, 0x62, 0x61, 0x78, 0x77, 0x76, 0x75, + 0x74, 0x73, 0x72, 0x71, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe4, 0x05, 0x89, 0x42, 0x5b, 0xae, 0x0d, 0x8e, 0x80, + 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, }; @@ -138,12 +128,10 @@ static void expected_lane_bytes(uint8 out[CLUSTER_EPOCH_BALLOT_LANE_BYTES]) { static const uint8 header[48] = { - 0x45, 0x50, 0x42, 0x4c, 0x01, 0x00, 0x03, 0x00, - 0x07, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, - 0x18, 0x17, 0x16, 0x15, 0x14, 0x13, 0x12, 0x11, - 0x11, 0x10, 0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a, - 0x38, 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x31, - 0xe4, 0x05, 0x89, 0x42, 0x5b, 0xae, 0x0d, 0x8e, + 0x45, 0x50, 0x42, 0x4c, 0x01, 0x00, 0x03, 0x00, 0x07, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x18, 0x17, 0x16, 0x15, 0x14, 0x13, 0x12, 0x11, + 0x11, 0x10, 0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a, 0x38, 0x37, 0x36, 0x35, + 0x34, 0x33, 0x32, 0x31, 0xe4, 0x05, 0x89, 0x42, 0x5b, 0xae, 0x0d, 0x8e, }; uint8 ballot[CLUSTER_EPOCH_BALLOT_ID_BYTES]; uint8 value[CLUSTER_EPOCH_AUTHORITY_VALUE_BYTES]; @@ -182,20 +170,18 @@ test_lane_recrc(uint8 bytes[CLUSTER_EPOCH_BALLOT_LANE_BYTES]) static bool encode_lane(const ClusterEpochBallotLane *lane, uint8 out[CLUSTER_EPOCH_BALLOT_LANE_BYTES]) { - return cluster_epoch_ballot_lane_encode( - lane, 7, 3, UINT64_C(0x1112131415161718), - UINT64_C(0x3132333435363738), - CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT, out); + return cluster_epoch_ballot_lane_encode(lane, 7, 3, UINT64_C(0x1112131415161718), + UINT64_C(0x3132333435363738), + CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT, out); } static bool decode_lane(const uint8 bytes[CLUSTER_EPOCH_BALLOT_LANE_BYTES], ClusterEpochBallotLane *out) { - return cluster_epoch_ballot_lane_decode( - bytes, 7, 3, UINT64_C(0x1112131415161718), - UINT64_C(0x3132333435363738), - CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT, out); + return cluster_epoch_ballot_lane_decode(bytes, 7, 3, UINT64_C(0x1112131415161718), + UINT64_C(0x3132333435363738), + CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT, out); } @@ -295,8 +281,8 @@ UT_TEST(test_authority_value_exact_little_endian_golden_and_roundtrip) uint8 actual[CLUSTER_EPOCH_AUTHORITY_VALUE_BYTES]; expected_value_bytes(expected); - UT_ASSERT(cluster_epoch_authority_value_encode( - &value, CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT, actual)); + UT_ASSERT(cluster_epoch_authority_value_encode(&value, CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT, + actual)); UT_ASSERT_EQ(memcmp(actual, expected, sizeof(actual)), 0); memset(&decoded, 0, sizeof(decoded)); UT_ASSERT(cluster_epoch_authority_value_decode( @@ -309,68 +295,67 @@ UT_TEST(test_authority_value_rejects_identity_phase_and_reserved_drift) { ClusterEpochAuthorityValue value = make_value(); - UT_ASSERT(cluster_epoch_authority_value_is_valid( - &value, CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT)); + UT_ASSERT( + cluster_epoch_authority_value_is_valid(&value, CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT)); value.value_version++; - UT_ASSERT(!cluster_epoch_authority_value_is_valid( - &value, CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT)); + UT_ASSERT( + !cluster_epoch_authority_value_is_valid(&value, CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT)); value = make_value(); value.transition = 0; - UT_ASSERT(!cluster_epoch_authority_value_is_valid( - &value, CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT)); + UT_ASSERT( + !cluster_epoch_authority_value_is_valid(&value, CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT)); value = make_value(); value.event_kind = 6; - UT_ASSERT(!cluster_epoch_authority_value_is_valid( - &value, CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT)); + UT_ASSERT( + !cluster_epoch_authority_value_is_valid(&value, CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT)); value = make_value(); value.request_origin_node = -1; - UT_ASSERT(!cluster_epoch_authority_value_is_valid( - &value, CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT)); + UT_ASSERT( + !cluster_epoch_authority_value_is_valid(&value, CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT)); value = make_value(); value.target_node_id = -1; - UT_ASSERT(!cluster_epoch_authority_value_is_valid( - &value, CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT)); + UT_ASSERT( + !cluster_epoch_authority_value_is_valid(&value, CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT)); value = make_value(); value.event_subject_bitmap[0] = UINT8_C(0x0c); - UT_ASSERT(!cluster_epoch_authority_value_is_valid( - &value, CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT)); + UT_ASSERT( + !cluster_epoch_authority_value_is_valid(&value, CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT)); value.target_node_id = -1; - UT_ASSERT(cluster_epoch_authority_value_is_valid( - &value, CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT)); + UT_ASSERT( + cluster_epoch_authority_value_is_valid(&value, CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT)); value = make_value(); value.reserved0 = 1; - UT_ASSERT(!cluster_epoch_authority_value_is_valid( - &value, CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT)); + UT_ASSERT( + !cluster_epoch_authority_value_is_valid(&value, CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT)); value = make_value(); value.authority_generation = 0; - UT_ASSERT(!cluster_epoch_authority_value_is_valid( - &value, CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT)); + UT_ASSERT( + !cluster_epoch_authority_value_is_valid(&value, CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT)); value = make_value(); value.reserved_epoch++; - UT_ASSERT(!cluster_epoch_authority_value_is_valid( - &value, CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT)); + UT_ASSERT( + !cluster_epoch_authority_value_is_valid(&value, CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT)); value = make_value(); value.baseline_epoch = UINT64_MAX; value.reserved_epoch = 0; - UT_ASSERT(!cluster_epoch_authority_value_is_valid( - &value, CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT)); + UT_ASSERT( + !cluster_epoch_authority_value_is_valid(&value, CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT)); value = make_value(); value.request_nonce = 0; - UT_ASSERT(!cluster_epoch_authority_value_is_valid( - &value, CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT)); + UT_ASSERT( + !cluster_epoch_authority_value_is_valid(&value, CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT)); value = make_value(); - memset(value.authority_member_bitmap, 0, - sizeof(value.authority_member_bitmap)); - UT_ASSERT(!cluster_epoch_authority_value_is_valid( - &value, CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT)); + memset(value.authority_member_bitmap, 0, sizeof(value.authority_member_bitmap)); + UT_ASSERT( + !cluster_epoch_authority_value_is_valid(&value, CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT)); value = make_value(); value.grammar_fingerprint ^= UINT64_C(1); - UT_ASSERT(!cluster_epoch_authority_value_is_valid( - &value, CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT)); + UT_ASSERT( + !cluster_epoch_authority_value_is_valid(&value, CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT)); value = make_value(); value.reserved1[3] = 1; - UT_ASSERT(!cluster_epoch_authority_value_is_valid( - &value, CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT)); + UT_ASSERT( + !cluster_epoch_authority_value_is_valid(&value, CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT)); } @@ -388,20 +373,20 @@ UT_TEST(test_authority_genesis_has_the_exact_zero_polarity) value.request_nonce = 0; memset(value.event_subject_bitmap, 0, sizeof(value.event_subject_bitmap)); memset(value.predecessor_digest, 0, sizeof(value.predecessor_digest)); - UT_ASSERT(cluster_epoch_authority_value_is_valid( - &value, CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT)); + UT_ASSERT( + cluster_epoch_authority_value_is_valid(&value, CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT)); value.authority_generation = 2; - UT_ASSERT(!cluster_epoch_authority_value_is_valid( - &value, CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT)); + UT_ASSERT( + !cluster_epoch_authority_value_is_valid(&value, CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT)); value.authority_generation = 1; value.request_nonce = 1; - UT_ASSERT(!cluster_epoch_authority_value_is_valid( - &value, CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT)); + UT_ASSERT( + !cluster_epoch_authority_value_is_valid(&value, CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT)); value = make_value(); value.event_kind = CLUSTER_EPOCH_EVENT_GENESIS; - UT_ASSERT(!cluster_epoch_authority_value_is_valid( - &value, CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT)); + UT_ASSERT( + !cluster_epoch_authority_value_is_valid(&value, CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT)); } diff --git a/src/test/cluster_unit/test_cluster_external_fence.c b/src/test/cluster_unit/test_cluster_external_fence.c index c79b219115b..c2a12316bd9 100644 --- a/src/test/cluster_unit/test_cluster_external_fence.c +++ b/src/test/cluster_unit/test_cluster_external_fence.c @@ -59,19 +59,18 @@ static bool stub_protected_set_identity_available; static ClusterProtectedSetIdentityV1 stub_protected_set_identity; extern bool cluster_external_fence_runtime_active(void); -extern bool cluster_external_fence_rejoin_protected_set_digest( - uint8 out[PGRAC_EXTERNAL_FENCE_DIGEST_BYTES]); +extern bool +cluster_external_fence_rejoin_protected_set_digest(uint8 out[PGRAC_EXTERNAL_FENCE_DIGEST_BYTES]); extern bool cluster_external_fence_test_runtime_active(void); extern int cluster_external_fence_test_connect_root_daemon(int timeout_ms); extern bool cluster_external_fence_test_root_peer_authenticated(int fd); -extern int cluster_external_fence_test_admission_lease_ms( - const PgracExternalFenceAdmissionV1 *admission); +extern int +cluster_external_fence_test_admission_lease_ms(const PgracExternalFenceAdmissionV1 *admission); extern bool cluster_formation_witness_copy_classification_v1( const ClusterFormationWitnessV1 *witness, uint16 *origin_thread, ClusterFenceAuthorityProof *authority, ClusterFormationSnapshotV1 *snapshot); -char *cluster_external_fence_socket_path = - "/var/run/pgrac/pgrac-fenced.sock"; +char *cluster_external_fence_socket_path = "/var/run/pgrac/pgrac-fenced.sock"; int cluster_write_fence_lease_ms = 6000; bool @@ -85,9 +84,8 @@ cluster_external_fence_test_connect_root_daemon(int timeout_ms) { int fd; - (void) timeout_ms; - if (stub_root_transport_index < stub_root_transport_count) - { + (void)timeout_ms; + if (stub_root_transport_index < stub_root_transport_count) { fd = stub_root_transport_fds[stub_root_transport_index]; stub_root_transport_fds[stub_root_transport_index] = -1; stub_root_transport_index++; @@ -103,13 +101,12 @@ cluster_external_fence_test_connect_root_daemon(int timeout_ms) bool cluster_external_fence_test_root_peer_authenticated(int fd) { - (void) fd; + (void)fd; return stub_root_peer_authenticated; } bool -cluster_shared_fs_get_protected_set_identity( - ClusterProtectedSetIdentityV1 *out) +cluster_shared_fs_get_protected_set_identity(ClusterProtectedSetIdentityV1 *out) { if (out != NULL) memset(out, 0, sizeof(*out)); @@ -132,19 +129,28 @@ cluster_write_fence_note_external_unavailable(void) } void -cluster_write_fence_note_external_write_excluded(uint64 journal_seq, - uint64 verified_mono_ns) +cluster_write_fence_note_external_write_excluded(uint64 journal_seq, uint64 verified_mono_ns) { - (void) journal_seq; - (void) verified_mono_ns; + (void)journal_seq; + (void)verified_mono_ns; stub_external_write_excluded++; } -void cluster_write_fence_note_external_rejected(void) {} -void cluster_write_fence_note_external_unknown(void) {} -void cluster_write_fence_note_external_identity_mismatch(void) {} -void cluster_write_fence_note_external_expired(void) {} -void cluster_write_fence_note_external_daemon_disconnect(void) {} +void +cluster_write_fence_note_external_rejected(void) +{} +void +cluster_write_fence_note_external_unknown(void) +{} +void +cluster_write_fence_note_external_identity_mismatch(void) +{} +void +cluster_write_fence_note_external_expired(void) +{} +void +cluster_write_fence_note_external_daemon_disconnect(void) +{} void pfree(void *pointer) @@ -165,11 +171,9 @@ palloc(Size size) } void -ExceptionalCondition(const char *condition_name, const char *file_name, - int line_number) +ExceptionalCondition(const char *condition_name, const char *file_name, int line_number) { - printf("# Assert failed: %s at %s:%d\n", condition_name, file_name, - line_number); + printf("# Assert failed: %s at %s:%d\n", condition_name, file_name, line_number); abort(); } @@ -180,20 +184,19 @@ cluster_ic_local_capability_word(void) } ClusterFormationWitnessResult -cluster_formation_witness_revalidate_nowait( - const ClusterFormationWitnessV1 *witness) +cluster_formation_witness_revalidate_nowait(const ClusterFormationWitnessV1 *witness) { - (void) witness; + (void)witness; return stub_formation_result; } bool -cluster_formation_witness_copy_classification_v1( - const ClusterFormationWitnessV1 *witness, uint16 *origin_thread, - ClusterFenceAuthorityProof *authority, ClusterFormationSnapshotV1 *snapshot) +cluster_formation_witness_copy_classification_v1(const ClusterFormationWitnessV1 *witness, + uint16 *origin_thread, + ClusterFenceAuthorityProof *authority, + ClusterFormationSnapshotV1 *snapshot) { - if (witness == NULL || origin_thread == NULL || authority == NULL || - snapshot == NULL) + if (witness == NULL || origin_thread == NULL || authority == NULL || snapshot == NULL) return false; *origin_thread = stub_formation_origin_thread; *authority = stub_formation_authority; @@ -202,8 +205,7 @@ cluster_formation_witness_copy_classification_v1( } bool -cluster_recovery_duty_digest_v1(const ClusterRecoveryDutyKey *key, - ClusterRecoveryDutyDigest *out) +cluster_recovery_duty_digest_v1(const ClusterRecoveryDutyKey *key, ClusterRecoveryDutyDigest *out) { if (!cluster_recovery_duty_key_valid_v1(key) || out == NULL) return false; @@ -212,67 +214,61 @@ cluster_recovery_duty_digest_v1(const ClusterRecoveryDutyKey *key, } bool -cluster_reconfig_rejoin_failure_snapshot( - int32 old_node_id, uint64 old_incarnation, - ClusterReconfigRejoinFailureSnapshotV1 *out_failure) +cluster_reconfig_rejoin_failure_snapshot(int32 old_node_id, uint64 old_incarnation, + ClusterReconfigRejoinFailureSnapshotV1 *out_failure) { if (out_failure != NULL) memset(out_failure, 0, sizeof(*out_failure)); - if (!stub_rejoin_failure_current || out_failure == NULL || - old_node_id != stub_rejoin_failure.old_node_id || - old_incarnation != stub_rejoin_failure.old_incarnation) + if (!stub_rejoin_failure_current || out_failure == NULL + || old_node_id != stub_rejoin_failure.old_node_id + || old_incarnation != stub_rejoin_failure.old_incarnation) return false; *out_failure = stub_rejoin_failure; return true; } bool -cluster_grd_rejoin_clear_snapshot( - const ClusterReconfigRejoinFailureSnapshotV1 *failure, - ClusterGrdRejoinClearSnapshotV1 *out_clear) +cluster_grd_rejoin_clear_snapshot(const ClusterReconfigRejoinFailureSnapshotV1 *failure, + ClusterGrdRejoinClearSnapshotV1 *out_clear) { if (out_clear != NULL) memset(out_clear, 0, sizeof(*out_clear)); - if (!stub_rejoin_grd_current || failure == NULL || out_clear == NULL || - memcmp(failure, &stub_rejoin_failure, sizeof(*failure)) != 0) + if (!stub_rejoin_grd_current || failure == NULL || out_clear == NULL + || memcmp(failure, &stub_rejoin_failure, sizeof(*failure)) != 0) return false; *out_clear = stub_rejoin_grd; return true; } bool -cluster_reconfig_rejoin_pending_snapshot( - const ClusterReconfigRejoinFailureSnapshotV1 *failure, - uint64 candidate_incarnation, - ClusterReconfigRejoinPendingSnapshotV1 *out_pending) +cluster_reconfig_rejoin_pending_snapshot(const ClusterReconfigRejoinFailureSnapshotV1 *failure, + uint64 candidate_incarnation, + ClusterReconfigRejoinPendingSnapshotV1 *out_pending) { if (out_pending != NULL) memset(out_pending, 0, sizeof(*out_pending)); - if (!stub_rejoin_pending_current || failure == NULL || - out_pending == NULL || - memcmp(failure, &stub_rejoin_failure, sizeof(*failure)) != 0 || - candidate_incarnation != stub_rejoin_pending.candidate_incarnation) + if (!stub_rejoin_pending_current || failure == NULL || out_pending == NULL + || memcmp(failure, &stub_rejoin_failure, sizeof(*failure)) != 0 + || candidate_incarnation != stub_rejoin_pending.candidate_incarnation) return false; *out_pending = stub_rejoin_pending; return true; } bool -cluster_reconfig_rejoin_pending_ready( - const ClusterReconfigRejoinPendingSnapshotV1 *pending) +cluster_reconfig_rejoin_pending_ready(const ClusterReconfigRejoinPendingSnapshotV1 *pending) { - return stub_rejoin_pending_is_ready && pending != NULL && - memcmp(pending, &stub_rejoin_pending, sizeof(*pending)) == 0; + return stub_rejoin_pending_is_ready && pending != NULL + && memcmp(pending, &stub_rejoin_pending, sizeof(*pending)) == 0; } ClusterControlRootResult -cluster_control_root_revalidate( - const ClusterControlRootReadToken *token, - const ClusterControlRootIdentity *expected_identity, - ClusterControlRootSnapshot *out_snapshot) +cluster_control_root_revalidate(const ClusterControlRootReadToken *token, + const ClusterControlRootIdentity *expected_identity, + ClusterControlRootSnapshot *out_snapshot) { - (void) token; - (void) expected_identity; + (void)token; + (void)expected_identity; if (out_snapshot != NULL) *out_snapshot = stub_root_revalidate_snapshot; return stub_root_revalidate_result; @@ -284,21 +280,18 @@ cluster_join_marker_compute_crc(ClusterJoinCommitMarker *marker) pg_crc32c crc; INIT_CRC32C(crc); - COMP_CRC32C(crc, marker, - offsetof(ClusterJoinCommitMarker, crc32c)); + COMP_CRC32C(crc, marker, offsetof(ClusterJoinCommitMarker, crc32c)); FIN_CRC32C(crc); - marker->crc32c = (uint32) crc; + marker->crc32c = (uint32)crc; } bool -cluster_join_marker_struct_valid( - const ClusterJoinCommitMarker *marker, int32 expected_node) +cluster_join_marker_struct_valid(const ClusterJoinCommitMarker *marker, int32 expected_node) { ClusterJoinCommitMarker copy; - if (marker == NULL || marker->magic != CLUSTER_JCMK_MAGIC || - marker->version != CLUSTER_JCMK_VERSION || - marker->node_id != expected_node) + if (marker == NULL || marker->magic != CLUSTER_JCMK_MAGIC + || marker->version != CLUSTER_JCMK_VERSION || marker->node_id != expected_node) return false; copy = *marker; cluster_join_marker_compute_crc(©); @@ -308,14 +301,14 @@ cluster_join_marker_struct_valid( ClusterMembershipState cluster_membership_get_state(int32 node_id) { - (void) node_id; + (void)node_id; return stub_membership_state; } uint64 cluster_membership_get_last_admitted_incarnation(int32 node_id) { - (void) node_id; + (void)node_id; return stub_admitted_floor; } @@ -333,19 +326,17 @@ fill_valid_duty(ClusterRecoveryDutyKey *duty) memset(duty, 0, sizeof(*duty)); duty->system_identifier = UINT64_C(0x0123456789abcdef); - for (i = 0; i < 16; i++) - { - duty->storage_uuid[i] = (uint8) (i + 1); - duty->authority_uuid[i] = (uint8) (0xa0 + i); + for (i = 0; i < 16; i++) { + duty->storage_uuid[i] = (uint8)(i + 1); + duty->authority_uuid[i] = (uint8)(0xa0 + i); } duty->authority_uuid[6] = 0x4a; duty->authority_uuid[8] = 0x8b; duty->origin_thread_id = 1; duty->origin_node_id = 0; duty->thread_claim_created_at = 123456; - cluster_wal_thread_claim_fill(&claim, duty->origin_thread_id, - duty->origin_node_id, - duty->thread_claim_created_at); + cluster_wal_thread_claim_fill(&claim, duty->origin_thread_id, duty->origin_node_id, + duty->thread_claim_created_at); duty->thread_claim_crc32c = claim.crc; duty->origin_owner_incarnation = UINT64_C(0x100000001); duty->root_lineage_seq = 7; @@ -367,25 +358,20 @@ prepare_two_writer_formation(const ClusterRecoveryDutyKey *duty) stub_formation_authority.marker.fence_generation = UINT64_C(7); stub_formation_authority.marker.issuer_node_id = 3; stub_formation_authority.marker.fenced_dead_bitmap[0] = UINT8_C(0x05); - stub_formation_authority.marker.marker_kind = - CLUSTER_FENCE_MARKER_KIND_FENCE; + stub_formation_authority.marker.marker_kind = CLUSTER_FENCE_MARKER_KIND_FENCE; stub_formation_snapshot.excluded_bitmap[0] = UINT8_C(0x05); - stub_formation_snapshot.membership.membership_state[0] = - CLUSTER_MEMBER_DEAD; - stub_formation_snapshot.membership.membership_state[2] = - CLUSTER_MEMBER_REMOVED; - stub_formation_snapshot.membership.last_admitted_incarnation[0] = - duty->origin_owner_incarnation; - stub_formation_snapshot.membership.last_admitted_incarnation[2] = - UINT64_C(0x300000003); + stub_formation_snapshot.membership.membership_state[0] = CLUSTER_MEMBER_DEAD; + stub_formation_snapshot.membership.membership_state[2] = CLUSTER_MEMBER_REMOVED; + stub_formation_snapshot.membership.last_admitted_incarnation[0] + = duty->origin_owner_incarnation; + stub_formation_snapshot.membership.last_admitted_incarnation[2] = UINT64_C(0x300000003); stub_formation_snapshot.local_epoch = UINT64_C(4); stub_local_capabilities = PGRAC_IC_HELLO_CAP_CONTROL_ROOT_V1; stub_runtime_active = true; stub_protected_set_identity_available = true; - stub_protected_set_identity.backend_id = - CLUSTER_SHARED_FS_BACKEND_BLOCK_DEVICE; + stub_protected_set_identity.backend_id = CLUSTER_SHARED_FS_BACKEND_BLOCK_DEVICE; memcpy(stub_protected_set_identity.storage_uuid, duty->storage_uuid, - sizeof(stub_protected_set_identity.storage_uuid)); + sizeof(stub_protected_set_identity.storage_uuid)); } static bool @@ -393,13 +379,12 @@ test_read_all(int fd, uint8 *bytes, size_t len) { size_t used = 0; - while (used < len) - { + while (used < len) { ssize_t got = read(fd, bytes + used, len - used); if (got <= 0) return false; - used += (size_t) got; + used += (size_t)got; } return true; } @@ -409,21 +394,19 @@ test_write_all(int fd, const uint8 *bytes, size_t len) { size_t used = 0; - while (used < len) - { + while (used < len) { ssize_t written = write(fd, bytes + used, len - used); if (written <= 0) return false; - used += (size_t) written; + used += (size_t)written; } return true; } static int -test_only_affirmative_provider_child_timed(int fd, - uint64 mapping_generation, uint64 freshness_ns, int delay_ms, - int close_control_fd) +test_only_affirmative_provider_child_timed(int fd, uint64 mapping_generation, uint64 freshness_ns, + int delay_ms, int close_control_fd) { PgracExternalFenceProtocolRequestV1 request; PgracExternalFenceProtocolResponseV1 response; @@ -432,12 +415,10 @@ test_only_affirmative_provider_child_timed(int fd, uint8 response_frame[PGRAC_EXTERNAL_FENCE_RESPONSE_V1_BYTES]; uint8 closed_byte; - if (!test_read_all(fd, request_frame, sizeof(request_frame)) || - !pgrac_external_fence_request_v1_decode(request_frame, - sizeof(request_frame), &request)) + if (!test_read_all(fd, request_frame, sizeof(request_frame)) + || !pgrac_external_fence_request_v1_decode(request_frame, sizeof(request_frame), &request)) return 1; - if (delay_ms > 0) - { + if (delay_ms > 0) { struct timespec delay; delay.tv_sec = delay_ms / 1000; @@ -447,28 +428,24 @@ test_only_affirmative_provider_child_timed(int fd, } memset(&response, 0, sizeof(response)); response.verdict = PGRAC_EXTERNAL_FENCE_WRITE_EXCLUDED; - memcpy(response.request_nonce, request.request_nonce, - sizeof(response.request_nonce)); - if (!pgrac_external_fence_binding_from_request_v1(&request.need, - mapping_generation, &response.binding)) + memcpy(response.request_nonce, request.request_nonce, sizeof(response.request_nonce)); + if (!pgrac_external_fence_binding_from_request_v1(&request.need, mapping_generation, + &response.binding)) return 2; - memset(response.daemon_boot_id, 0x91, - sizeof(response.daemon_boot_id)); + memset(response.daemon_boot_id, 0x91, sizeof(response.daemon_boot_id)); response.journal_seq = UINT64_C(10); if (clock_gettime(CLOCK_MONOTONIC, &now) != 0) return 3; - response.verified_mono_ns = - (uint64) now.tv_sec * UINT64_C(1000000000) + (uint64) now.tv_nsec; + response.verified_mono_ns = (uint64)now.tv_sec * UINT64_C(1000000000) + (uint64)now.tv_nsec; response.fresh_until_mono_ns = response.verified_mono_ns + freshness_ns; response.proof_generation = UINT64_C(11); response.provider_id = UINT16_C(1); response.provider_abi_version = UINT16_C(1); response.provider_result = UINT32_C(0); - memset(response.target_state_digest, 0x92, - sizeof(response.target_state_digest)); + memset(response.target_state_digest, 0x92, sizeof(response.target_state_digest)); response.deny_reason = PGRAC_EXTERNAL_FENCE_DENY_NONE; - if (!pgrac_external_fence_response_v1_encode(&response, response_frame) || - !test_write_all(fd, response_frame, sizeof(response_frame))) + if (!pgrac_external_fence_response_v1_encode(&response, response_frame) + || !test_write_all(fd, response_frame, sizeof(response_frame))) return 4; if (close_control_fd >= 0) return read(close_control_fd, &closed_byte, 1) == 1 ? 0 : 5; @@ -479,8 +456,7 @@ test_only_affirmative_provider_child_timed(int fd, static int test_only_affirmative_provider_child(int fd) { - return test_only_affirmative_provider_child_timed(fd, - UINT64_C(9), UINT64_C(1000000000), 0, -1); + return test_only_affirmative_provider_child_timed(fd, UINT64_C(9), UINT64_C(1000000000), 0, -1); } static int @@ -491,20 +467,18 @@ test_only_negative_provider_child(int fd) uint8 request_frame[PGRAC_EXTERNAL_FENCE_REQUEST_V1_BYTES]; uint8 response_frame[PGRAC_EXTERNAL_FENCE_RESPONSE_V1_BYTES]; - if (!test_read_all(fd, request_frame, sizeof(request_frame)) || - !pgrac_external_fence_request_v1_decode(request_frame, - sizeof(request_frame), &request)) + if (!test_read_all(fd, request_frame, sizeof(request_frame)) + || !pgrac_external_fence_request_v1_decode(request_frame, sizeof(request_frame), &request)) return 1; memset(&response, 0, sizeof(response)); response.verdict = PGRAC_EXTERNAL_FENCE_UNKNOWN; - memcpy(response.request_nonce, request.request_nonce, - sizeof(response.request_nonce)); + memcpy(response.request_nonce, request.request_nonce, sizeof(response.request_nonce)); response.provider_id = UINT16_C(1); response.provider_abi_version = UINT16_C(1); response.provider_result = UINT32_C(3); response.deny_reason = PGRAC_EXTERNAL_FENCE_DENY_PROVIDER_UNKNOWN; - if (!pgrac_external_fence_response_v1_encode(&response, response_frame) || - !test_write_all(fd, response_frame, sizeof(response_frame))) + if (!pgrac_external_fence_response_v1_encode(&response, response_frame) + || !test_write_all(fd, response_frame, sizeof(response_frame))) return 2; return 0; } @@ -514,12 +488,10 @@ fill_valid_scalar_need(PgracExternalFenceNeedV1 *need) { memset(need, 0, sizeof(*need)); need->system_identifier = UINT64_C(0x0123456789abcdef); - memset(need->canonical_duty_digest.bytes, 0xa5, - sizeof(need->canonical_duty_digest.bytes)); + memset(need->canonical_duty_digest.bytes, 0xa5, sizeof(need->canonical_duty_digest.bytes)); need->victim_node_id = 1; need->victim_incarnation = UINT64_C(0x100000001); - memset(need->protected_set_digest, 0x5a, - sizeof(need->protected_set_digest)); + memset(need->protected_set_digest, 0x5a, sizeof(need->protected_set_digest)); need->predicate_id = PGRAC_EXTERNAL_FENCE_PREDICATE_WRITE_EXCLUDED; need->predicate_version = PGRAC_EXTERNAL_FENCE_PREDICATE_VERSION_V1; } @@ -558,19 +530,15 @@ UT_TEST(test_external_fence_recovery_layouts) UT_ASSERT_EQ(offsetof(PgracExternalFenceWriterV1, incarnation), 8); UT_ASSERT_EQ(sizeof(PgracExternalFenceWriterSetDigest), 32); UT_ASSERT_EQ(sizeof(PgracExternalFenceNeedV1), 96); - UT_ASSERT_EQ(offsetof(PgracExternalFenceNeedV1, - canonical_duty_digest), 8); + UT_ASSERT_EQ(offsetof(PgracExternalFenceNeedV1, canonical_duty_digest), 8); UT_ASSERT_EQ(offsetof(PgracExternalFenceNeedV1, victim_node_id), 40); UT_ASSERT_EQ(offsetof(PgracExternalFenceNeedV1, victim_incarnation), 48); UT_ASSERT_EQ(offsetof(PgracExternalFenceNeedV1, protected_set_digest), 56); UT_ASSERT_EQ(offsetof(PgracExternalFenceNeedV1, predicate_version), 92); UT_ASSERT_EQ(sizeof(PgracExternalFenceBindingV1), 104); - UT_ASSERT_EQ(offsetof(PgracExternalFenceBindingV1, - canonical_duty_digest), 8); - UT_ASSERT_EQ(offsetof(PgracExternalFenceBindingV1, - target_mapping_generation), 56); - UT_ASSERT_EQ(offsetof(PgracExternalFenceBindingV1, - protected_set_digest), 64); + UT_ASSERT_EQ(offsetof(PgracExternalFenceBindingV1, canonical_duty_digest), 8); + UT_ASSERT_EQ(offsetof(PgracExternalFenceBindingV1, target_mapping_generation), 56); + UT_ASSERT_EQ(offsetof(PgracExternalFenceBindingV1, protected_set_digest), 64); UT_ASSERT_EQ(offsetof(PgracExternalFenceBindingV1, predicate_version), 100); } @@ -578,108 +546,81 @@ UT_TEST(test_external_fence_rejoin_layouts) { UT_ASSERT_EQ(sizeof(PgracExternalFenceRejoinOfferV1), 40); UT_ASSERT_EQ(offsetof(PgracExternalFenceRejoinOfferV1, old_node_id), 16); - UT_ASSERT_EQ(offsetof(PgracExternalFenceRejoinOfferV1, - candidate_incarnation), 32); + UT_ASSERT_EQ(offsetof(PgracExternalFenceRejoinOfferV1, candidate_incarnation), 32); UT_ASSERT_EQ(sizeof(PgracExternalFenceRejoinNeedV1), 104); - UT_ASSERT_EQ(offsetof(PgracExternalFenceRejoinNeedV1, - protected_set_digest), 64); + UT_ASSERT_EQ(offsetof(PgracExternalFenceRejoinNeedV1, protected_set_digest), 64); UT_ASSERT_EQ(offsetof(PgracExternalFenceRejoinNeedV1, predicate_id), 96); UT_ASSERT_EQ(sizeof(PgracExternalFenceRejoinBindingV1), 112); - UT_ASSERT_EQ(offsetof(PgracExternalFenceRejoinBindingV1, - target_mapping_generation), 64); - UT_ASSERT_EQ(offsetof(PgracExternalFenceRejoinBindingV1, - protected_set_digest), 72); - UT_ASSERT_EQ(offsetof(PgracExternalFenceRejoinBindingV1, - predicate_version), 108); + UT_ASSERT_EQ(offsetof(PgracExternalFenceRejoinBindingV1, target_mapping_generation), 64); + UT_ASSERT_EQ(offsetof(PgracExternalFenceRejoinBindingV1, protected_set_digest), 72); + UT_ASSERT_EQ(offsetof(PgracExternalFenceRejoinBindingV1, predicate_version), 108); } UT_TEST(test_external_fence_rejoin_snapshot_layouts) { UT_ASSERT_EQ(sizeof(ClusterReconfigRejoinFailureSnapshotV1), 80); - UT_ASSERT_EQ(offsetof(ClusterReconfigRejoinFailureSnapshotV1, - reconfig_kind), 0); - UT_ASSERT_EQ(offsetof(ClusterReconfigRejoinFailureSnapshotV1, - event_id), 8); - UT_ASSERT_EQ(offsetof(ClusterReconfigRejoinFailureSnapshotV1, - dead_bitmap), 32); - UT_ASSERT_EQ(offsetof(ClusterReconfigRejoinFailureSnapshotV1, - survivor_bitmap), 48); - UT_ASSERT_EQ(offsetof(ClusterReconfigRejoinFailureSnapshotV1, - old_node_id), 64); - UT_ASSERT_EQ(offsetof(ClusterReconfigRejoinFailureSnapshotV1, - old_incarnation), 72); + UT_ASSERT_EQ(offsetof(ClusterReconfigRejoinFailureSnapshotV1, reconfig_kind), 0); + UT_ASSERT_EQ(offsetof(ClusterReconfigRejoinFailureSnapshotV1, event_id), 8); + UT_ASSERT_EQ(offsetof(ClusterReconfigRejoinFailureSnapshotV1, dead_bitmap), 32); + UT_ASSERT_EQ(offsetof(ClusterReconfigRejoinFailureSnapshotV1, survivor_bitmap), 48); + UT_ASSERT_EQ(offsetof(ClusterReconfigRejoinFailureSnapshotV1, old_node_id), 64); + UT_ASSERT_EQ(offsetof(ClusterReconfigRejoinFailureSnapshotV1, old_incarnation), 72); UT_ASSERT_EQ(sizeof(ClusterGrdRejoinClearSnapshotV1), 32); - UT_ASSERT_EQ(offsetof(ClusterGrdRejoinClearSnapshotV1, - dead_bitmap_hash), 8); - UT_ASSERT_EQ(offsetof(ClusterGrdRejoinClearSnapshotV1, - survivor_bitmap), 16); + UT_ASSERT_EQ(offsetof(ClusterGrdRejoinClearSnapshotV1, dead_bitmap_hash), 8); + UT_ASSERT_EQ(offsetof(ClusterGrdRejoinClearSnapshotV1, survivor_bitmap), 16); UT_ASSERT_EQ(sizeof(ClusterReconfigRejoinPendingSnapshotV1), 96); - UT_ASSERT_EQ(offsetof(ClusterReconfigRejoinPendingSnapshotV1, - old_epoch), 16); - UT_ASSERT_EQ(offsetof(ClusterReconfigRejoinPendingSnapshotV1, - dead_bitmap), 40); - UT_ASSERT_EQ(offsetof(ClusterReconfigRejoinPendingSnapshotV1, - join_bitmap), 56); - UT_ASSERT_EQ(offsetof(ClusterReconfigRejoinPendingSnapshotV1, - node_id), 72); - UT_ASSERT_EQ(offsetof(ClusterReconfigRejoinPendingSnapshotV1, - candidate_incarnation), 80); - UT_ASSERT_EQ(offsetof(ClusterReconfigRejoinPendingSnapshotV1, - observed_slot_generation), 88); + UT_ASSERT_EQ(offsetof(ClusterReconfigRejoinPendingSnapshotV1, old_epoch), 16); + UT_ASSERT_EQ(offsetof(ClusterReconfigRejoinPendingSnapshotV1, dead_bitmap), 40); + UT_ASSERT_EQ(offsetof(ClusterReconfigRejoinPendingSnapshotV1, join_bitmap), 56); + UT_ASSERT_EQ(offsetof(ClusterReconfigRejoinPendingSnapshotV1, node_id), 72); + UT_ASSERT_EQ(offsetof(ClusterReconfigRejoinPendingSnapshotV1, candidate_incarnation), 80); + UT_ASSERT_EQ(offsetof(ClusterReconfigRejoinPendingSnapshotV1, observed_slot_generation), 88); } UT_TEST(test_external_fence_no_generation_set_api) { - typedef PgracExternalFenceNeedSetResult (*BuildFn)( - const ClusterRecoveryDutyKey *, const ClusterFormationWitnessV1 *, - PgracExternalFenceNeedSetV1 **); - typedef bool (*NeedRevalidateFn)( - const PgracExternalFenceNeedSetV1 *, - const ClusterFormationWitnessV1 *, PgracExternalFenceDenyReason *); - typedef PgracExternalFenceVerdict (*AdmitFn)( - const PgracExternalFenceNeedSetV1 *, - const ClusterFormationWitnessV1 *, int, - PgracExternalFenceAdmissionSetV1 **); + typedef PgracExternalFenceNeedSetResult (*BuildFn)(const ClusterRecoveryDutyKey *, + const ClusterFormationWitnessV1 *, + PgracExternalFenceNeedSetV1 **); + typedef bool (*NeedRevalidateFn)(const PgracExternalFenceNeedSetV1 *, + const ClusterFormationWitnessV1 *, + PgracExternalFenceDenyReason *); + typedef PgracExternalFenceVerdict (*AdmitFn)(const PgracExternalFenceNeedSetV1 *, + const ClusterFormationWitnessV1 *, int, + PgracExternalFenceAdmissionSetV1 **); typedef bool (*AdmissionRevalidateFn)( - const PgracExternalFenceAdmissionSetV1 *, - const PgracExternalFenceNeedSetV1 *, + const PgracExternalFenceAdmissionSetV1 *, const PgracExternalFenceNeedSetV1 *, const ClusterFormationWitnessV1 *, PgracExternalFenceDenyReason *); + UT_ASSERT( + __builtin_types_compatible_p(__typeof__(&cluster_external_fence_need_set_build), BuildFn)); UT_ASSERT(__builtin_types_compatible_p( - __typeof__(&cluster_external_fence_need_set_build), BuildFn)); - UT_ASSERT(__builtin_types_compatible_p( - __typeof__(&cluster_external_fence_need_set_revalidate_nowait), - NeedRevalidateFn)); + __typeof__(&cluster_external_fence_need_set_revalidate_nowait), NeedRevalidateFn)); + UT_ASSERT( + __builtin_types_compatible_p(__typeof__(&cluster_external_fence_admit_set_wait), AdmitFn)); UT_ASSERT(__builtin_types_compatible_p( - __typeof__(&cluster_external_fence_admit_set_wait), AdmitFn)); - UT_ASSERT(__builtin_types_compatible_p( - __typeof__(&cluster_external_fence_revalidate_set_nowait), - AdmissionRevalidateFn)); + __typeof__(&cluster_external_fence_revalidate_set_nowait), AdmissionRevalidateFn)); } UT_TEST(test_external_fence_inactive_capability_builds_no_need_set) { ClusterRecoveryDutyKey duty; - const ClusterFormationWitnessV1 *formation = - (const ClusterFormationWitnessV1 *) (uintptr_t) 1; + const ClusterFormationWitnessV1 *formation = (const ClusterFormationWitnessV1 *)(uintptr_t)1; PgracExternalFenceNeedSetV1 *needs = NULL; fill_valid_duty(&duty); stub_formation_result = CLUSTER_FORMATION_WITNESS_READY; stub_local_capabilities = 0; - UT_ASSERT_EQ(cluster_external_fence_need_set_build( - &duty, formation, &needs), - PGRAC_EXTERNAL_FENCE_NEED_SET_CAPABILITY_UNAVAILABLE); + UT_ASSERT_EQ(cluster_external_fence_need_set_build(&duty, formation, &needs), + PGRAC_EXTERNAL_FENCE_NEED_SET_CAPABILITY_UNAVAILABLE); UT_ASSERT(needs == NULL); } UT_TEST(test_external_fence_need_set_builds_complete_sorted_writers) { ClusterRecoveryDutyKey duty; - const ClusterFormationWitnessV1 *formation = - (const ClusterFormationWitnessV1 *) (uintptr_t) 1; - const ClusterFormationWitnessV1 *replacement = - (const ClusterFormationWitnessV1 *) (uintptr_t) 2; + const ClusterFormationWitnessV1 *formation = (const ClusterFormationWitnessV1 *)(uintptr_t)1; + const ClusterFormationWitnessV1 *replacement = (const ClusterFormationWitnessV1 *)(uintptr_t)2; PgracExternalFenceNeedSetV1 *needs = NULL; PgracExternalFenceDenyReason reason = PGRAC_EXTERNAL_FENCE_DENY_NONE; const PgracExternalFenceNeedV1 *first; @@ -699,52 +640,40 @@ UT_TEST(test_external_fence_need_set_builds_complete_sorted_writers) stub_formation_authority.marker.fence_generation = UINT64_C(7); stub_formation_authority.marker.issuer_node_id = 3; stub_formation_authority.marker.fenced_dead_bitmap[0] = UINT8_C(0x05); - stub_formation_authority.marker.marker_kind = - CLUSTER_FENCE_MARKER_KIND_FENCE; + stub_formation_authority.marker.marker_kind = CLUSTER_FENCE_MARKER_KIND_FENCE; stub_formation_snapshot.excluded_bitmap[0] = UINT8_C(0x05); - stub_formation_snapshot.membership.membership_state[0] = - CLUSTER_MEMBER_DEAD; - stub_formation_snapshot.membership.membership_state[2] = - CLUSTER_MEMBER_REMOVED; - stub_formation_snapshot.membership.last_admitted_incarnation[0] = - duty.origin_owner_incarnation; - stub_formation_snapshot.membership.last_admitted_incarnation[2] = - UINT64_C(0x300000003); + stub_formation_snapshot.membership.membership_state[0] = CLUSTER_MEMBER_DEAD; + stub_formation_snapshot.membership.membership_state[2] = CLUSTER_MEMBER_REMOVED; + stub_formation_snapshot.membership.last_admitted_incarnation[0] = duty.origin_owner_incarnation; + stub_formation_snapshot.membership.last_admitted_incarnation[2] = UINT64_C(0x300000003); stub_formation_snapshot.local_epoch = UINT64_C(4); stub_local_capabilities = PGRAC_IC_HELLO_CAP_CONTROL_ROOT_V1; stub_runtime_active = true; stub_protected_set_identity_available = true; - stub_protected_set_identity.backend_id = - CLUSTER_SHARED_FS_BACKEND_BLOCK_DEVICE; + stub_protected_set_identity.backend_id = CLUSTER_SHARED_FS_BACKEND_BLOCK_DEVICE; memcpy(stub_protected_set_identity.storage_uuid, duty.storage_uuid, - sizeof(stub_protected_set_identity.storage_uuid)); + sizeof(stub_protected_set_identity.storage_uuid)); - UT_ASSERT_EQ(cluster_external_fence_need_set_build( - &duty, formation, &needs), PGRAC_EXTERNAL_FENCE_NEED_SET_OK); + UT_ASSERT_EQ(cluster_external_fence_need_set_build(&duty, formation, &needs), + PGRAC_EXTERNAL_FENCE_NEED_SET_OK); UT_ASSERT(needs != NULL); UT_ASSERT_EQ(cluster_external_fence_need_set_count(needs), 2); first = cluster_external_fence_need_set_at(needs, 0); second = cluster_external_fence_need_set_at(needs, 1); UT_ASSERT(first != NULL); UT_ASSERT(second != NULL); - if (first != NULL) - { + if (first != NULL) { UT_ASSERT_EQ(first->victim_node_id, 0); - UT_ASSERT_EQ(first->victim_incarnation, - duty.origin_owner_incarnation); + UT_ASSERT_EQ(first->victim_incarnation, duty.origin_owner_incarnation); } - if (second != NULL) - { + if (second != NULL) { UT_ASSERT_EQ(second->victim_node_id, 2); - UT_ASSERT_EQ(second->victim_incarnation, - UINT64_C(0x300000003)); + UT_ASSERT_EQ(second->victim_incarnation, UINT64_C(0x300000003)); } UT_ASSERT(cluster_external_fence_need_set_digest(needs) != NULL); - UT_ASSERT(cluster_external_fence_need_set_revalidate_nowait( - needs, formation, &reason)); + UT_ASSERT(cluster_external_fence_need_set_revalidate_nowait(needs, formation, &reason)); UT_ASSERT_EQ(reason, PGRAC_EXTERNAL_FENCE_DENY_NONE); - UT_ASSERT(!cluster_external_fence_need_set_revalidate_nowait( - needs, replacement, &reason)); + UT_ASSERT(!cluster_external_fence_need_set_revalidate_nowait(needs, replacement, &reason)); UT_ASSERT_EQ(reason, PGRAC_EXTERNAL_FENCE_DENY_WRITER_SET_STALE); cluster_external_fence_need_set_release(&needs); UT_ASSERT(needs == NULL); @@ -755,55 +684,46 @@ UT_TEST(test_external_fence_need_set_builds_complete_sorted_writers) UT_TEST(test_external_fence_need_set_rejects_incomplete_authority) { ClusterRecoveryDutyKey duty; - const ClusterFormationWitnessV1 *formation = - (const ClusterFormationWitnessV1 *) (uintptr_t) 1; + const ClusterFormationWitnessV1 *formation = (const ClusterFormationWitnessV1 *)(uintptr_t)1; PgracExternalFenceNeedSetV1 *needs = NULL; fill_valid_duty(&duty); prepare_two_writer_formation(&duty); memset(stub_formation_authority.marker.fenced_dead_bitmap, 0, - sizeof(stub_formation_authority.marker.fenced_dead_bitmap)); - stub_formation_authority.marker.marker_kind = - CLUSTER_FENCE_MARKER_KIND_BASELINE; - stub_formation_authority.marker.issuer_node_id = - CLUSTER_FENCE_BASELINE_INITIAL_ISSUER; + sizeof(stub_formation_authority.marker.fenced_dead_bitmap)); + stub_formation_authority.marker.marker_kind = CLUSTER_FENCE_MARKER_KIND_BASELINE; + stub_formation_authority.marker.issuer_node_id = CLUSTER_FENCE_BASELINE_INITIAL_ISSUER; stub_formation_authority.marker.fence_event_id = 0; stub_formation_authority.marker.fence_generation = 0; memset(stub_formation_snapshot.excluded_bitmap, 0, - sizeof(stub_formation_snapshot.excluded_bitmap)); - UT_ASSERT_EQ(cluster_external_fence_need_set_build( - &duty, formation, &needs), - PGRAC_EXTERNAL_FENCE_NEED_SET_WRITER_COUNT_INVALID); + sizeof(stub_formation_snapshot.excluded_bitmap)); + UT_ASSERT_EQ(cluster_external_fence_need_set_build(&duty, formation, &needs), + PGRAC_EXTERNAL_FENCE_NEED_SET_WRITER_COUNT_INVALID); UT_ASSERT(needs == NULL); prepare_two_writer_formation(&duty); stub_formation_authority.marker.fenced_dead_bitmap[0] = UINT8_C(0x04); stub_formation_snapshot.excluded_bitmap[0] = UINT8_C(0x04); - UT_ASSERT_EQ(cluster_external_fence_need_set_build( - &duty, formation, &needs), - PGRAC_EXTERNAL_FENCE_NEED_SET_ORIGINAL_OWNER_MISSING); + UT_ASSERT_EQ(cluster_external_fence_need_set_build(&duty, formation, &needs), + PGRAC_EXTERNAL_FENCE_NEED_SET_ORIGINAL_OWNER_MISSING); UT_ASSERT(needs == NULL); prepare_two_writer_formation(&duty); stub_formation_snapshot.membership.last_admitted_incarnation[2] = 0; - UT_ASSERT_EQ(cluster_external_fence_need_set_build( - &duty, formation, &needs), - PGRAC_EXTERNAL_FENCE_NEED_SET_WRITER_INCAR_UNPROVEN); + UT_ASSERT_EQ(cluster_external_fence_need_set_build(&duty, formation, &needs), + PGRAC_EXTERNAL_FENCE_NEED_SET_WRITER_INCAR_UNPROVEN); UT_ASSERT(needs == NULL); prepare_two_writer_formation(&duty); - stub_formation_snapshot.membership.membership_state[2] = - CLUSTER_MEMBER_JOINING; - UT_ASSERT_EQ(cluster_external_fence_need_set_build( - &duty, formation, &needs), - PGRAC_EXTERNAL_FENCE_NEED_SET_MEMBERSHIP_UNSTABLE); + stub_formation_snapshot.membership.membership_state[2] = CLUSTER_MEMBER_JOINING; + UT_ASSERT_EQ(cluster_external_fence_need_set_build(&duty, formation, &needs), + PGRAC_EXTERNAL_FENCE_NEED_SET_MEMBERSHIP_UNSTABLE); UT_ASSERT(needs == NULL); prepare_two_writer_formation(&duty); stub_protected_set_identity.storage_uuid[0] ^= UINT8_C(0xff); - UT_ASSERT_EQ(cluster_external_fence_need_set_build( - &duty, formation, &needs), - PGRAC_EXTERNAL_FENCE_NEED_SET_STORAGE_UNAVAILABLE); + UT_ASSERT_EQ(cluster_external_fence_need_set_build(&duty, formation, &needs), + PGRAC_EXTERNAL_FENCE_NEED_SET_STORAGE_UNAVAILABLE); UT_ASSERT(needs == NULL); stub_runtime_active = false; stub_protected_set_identity_available = false; @@ -816,12 +736,10 @@ UT_TEST(test_external_fence_provider_zero_is_unavailable_without_admission) memset(&need, 0, sizeof(need)); need.system_identifier = 1; - memset(need.canonical_duty_digest.bytes, 0xa5, - sizeof(need.canonical_duty_digest.bytes)); + memset(need.canonical_duty_digest.bytes, 0xa5, sizeof(need.canonical_duty_digest.bytes)); need.victim_node_id = 1; need.victim_incarnation = 1; - memset(need.protected_set_digest, 0x5a, - sizeof(need.protected_set_digest)); + memset(need.protected_set_digest, 0x5a, sizeof(need.protected_set_digest)); need.predicate_id = PGRAC_EXTERNAL_FENCE_PREDICATE_WRITE_EXCLUDED; need.predicate_version = PGRAC_EXTERNAL_FENCE_PREDICATE_VERSION_V1; stub_external_admit_requested = 0; @@ -837,22 +755,17 @@ UT_TEST(test_external_fence_provider_zero_is_unavailable_without_admission) UT_TEST(test_external_fence_nonproof_signals_never_admit) { - static const char *const standalone_observations[] = { - "ping_loss", - "membership_dead", - "victim_process_exit" - }; + static const char *const standalone_observations[] + = { "ping_loss", "membership_dead", "victim_process_exit" }; PgracExternalFenceNeedV1 need; uint32 i; memset(&need, 0, sizeof(need)); need.system_identifier = UINT64_C(0x0123456789abcdef); - memset(need.canonical_duty_digest.bytes, 0xa5, - sizeof(need.canonical_duty_digest.bytes)); + memset(need.canonical_duty_digest.bytes, 0xa5, sizeof(need.canonical_duty_digest.bytes)); need.victim_node_id = 1; need.victim_incarnation = UINT64_C(0x100000001); - memset(need.protected_set_digest, 0x5a, - sizeof(need.protected_set_digest)); + memset(need.protected_set_digest, 0x5a, sizeof(need.protected_set_digest)); need.predicate_id = PGRAC_EXTERNAL_FENCE_PREDICATE_WRITE_EXCLUDED; need.predicate_version = PGRAC_EXTERNAL_FENCE_PREDICATE_VERSION_V1; stub_runtime_active = false; @@ -863,16 +776,15 @@ UT_TEST(test_external_fence_nonproof_signals_never_admit) * API. Exercise each one as an isolated trigger and prove that, without * the authenticated daemon readback path, no opaque admission exists. */ - for (i = 0; i < lengthof(standalone_observations); i++) - { + for (i = 0; i < lengthof(standalone_observations); i++) { PgracExternalFenceAdmissionV1 *admission = NULL; UT_ASSERT_NOT_NULL(standalone_observations[i]); - UT_ASSERT_EQ(cluster_external_fence_admit_wait( - &need, 1000, &admission), PGRAC_EXTERNAL_FENCE_UNAVAILABLE); + UT_ASSERT_EQ(cluster_external_fence_admit_wait(&need, 1000, &admission), + PGRAC_EXTERNAL_FENCE_UNAVAILABLE); UT_ASSERT(admission == NULL); UT_ASSERT_EQ(cluster_external_fence_last_deny_reason(), - PGRAC_EXTERNAL_FENCE_DENY_DAEMON_UNAVAILABLE); + PGRAC_EXTERNAL_FENCE_DENY_DAEMON_UNAVAILABLE); } } @@ -889,50 +801,43 @@ UT_TEST(test_external_fence_test_only_exact_response_creates_live_admission) UT_ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, sockets), 0); child = fork(); UT_ASSERT(child >= 0); - if (child == 0) - { + if (child == 0) { int child_rc; - (void) close(sockets[0]); + (void)close(sockets[0]); child_rc = test_only_affirmative_provider_child(sockets[1]); - (void) close(sockets[1]); + (void)close(sockets[1]); _exit(child_rc); } - (void) close(sockets[1]); + (void)close(sockets[1]); stub_root_transport_fd = sockets[0]; stub_runtime_active = true; stub_external_write_excluded = 0; memset(&need, 0, sizeof(need)); need.system_identifier = UINT64_C(0x0123456789abcdef); - memset(need.canonical_duty_digest.bytes, 0xa5, - sizeof(need.canonical_duty_digest.bytes)); + memset(need.canonical_duty_digest.bytes, 0xa5, sizeof(need.canonical_duty_digest.bytes)); need.victim_node_id = 1; need.victim_incarnation = UINT64_C(0x100000001); - memset(need.protected_set_digest, 0x5a, - sizeof(need.protected_set_digest)); + memset(need.protected_set_digest, 0x5a, sizeof(need.protected_set_digest)); need.predicate_id = PGRAC_EXTERNAL_FENCE_PREDICATE_WRITE_EXCLUDED; need.predicate_version = PGRAC_EXTERNAL_FENCE_PREDICATE_VERSION_V1; UT_ASSERT_EQ(cluster_external_fence_admit_wait(&need, 5000, &admission), - PGRAC_EXTERNAL_FENCE_WRITE_EXCLUDED); + PGRAC_EXTERNAL_FENCE_WRITE_EXCLUDED); UT_ASSERT(admission != NULL); binding = cluster_external_fence_admission_binding(admission); UT_ASSERT(binding != NULL); - if (binding != NULL) - { - UT_ASSERT_EQ(binding->victim_incarnation, - UINT64_C(0x100000001)); + if (binding != NULL) { + UT_ASSERT_EQ(binding->victim_incarnation, UINT64_C(0x100000001)); UT_ASSERT_EQ(binding->target_mapping_generation, UINT64_C(9)); } - UT_ASSERT(cluster_external_fence_revalidate_nowait(admission, &need, - &reason)); + UT_ASSERT(cluster_external_fence_revalidate_nowait(admission, &need, &reason)); UT_ASSERT_EQ(reason, PGRAC_EXTERNAL_FENCE_DENY_NONE); UT_ASSERT_EQ(stub_external_write_excluded, 1); cluster_external_fence_admission_release(admission); admission = NULL; - if (stub_root_transport_fd >= 0) - { - (void) close(stub_root_transport_fd); + if (stub_root_transport_fd >= 0) { + (void)close(stub_root_transport_fd); stub_root_transport_fd = -1; } UT_ASSERT_EQ(waitpid(child, &status, 0), child); @@ -949,17 +854,14 @@ UT_TEST(test_external_fence_admission_pins_call_entry_lease_snapshot) memset(&need, 0, sizeof(need)); need.system_identifier = UINT64_C(0x0123456789abcdef); - memset(need.canonical_duty_digest.bytes, 0xa5, - sizeof(need.canonical_duty_digest.bytes)); + memset(need.canonical_duty_digest.bytes, 0xa5, sizeof(need.canonical_duty_digest.bytes)); need.victim_node_id = 1; need.victim_incarnation = UINT64_C(0x100000001); - memset(need.protected_set_digest, 0x5a, - sizeof(need.protected_set_digest)); + memset(need.protected_set_digest, 0x5a, sizeof(need.protected_set_digest)); need.predicate_id = PGRAC_EXTERNAL_FENCE_PREDICATE_WRITE_EXCLUDED; need.predicate_version = PGRAC_EXTERNAL_FENCE_PREDICATE_VERSION_V1; stub_runtime_active = true; - for (i = 0; i < (int) lengthof(entry_values); i++) - { + for (i = 0; i < (int)lengthof(entry_values); i++) { PgracExternalFenceAdmissionV1 *admission = NULL; int sockets[2]; int status; @@ -968,24 +870,22 @@ UT_TEST(test_external_fence_admission_pins_call_entry_lease_snapshot) UT_ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, sockets), 0); child = fork(); UT_ASSERT(child >= 0); - if (child == 0) - { + if (child == 0) { int child_rc; - (void) close(sockets[0]); + (void)close(sockets[0]); child_rc = test_only_affirmative_provider_child(sockets[1]); - (void) close(sockets[1]); + (void)close(sockets[1]); _exit(child_rc); } - (void) close(sockets[1]); + (void)close(sockets[1]); stub_root_transport_fd = sockets[0]; cluster_write_fence_lease_ms = entry_values[i]; stub_connect_lease_ms = entry_values[(i + 1) % lengthof(entry_values)]; - UT_ASSERT_EQ(cluster_external_fence_admit_wait(&need, 5000, - &admission), PGRAC_EXTERNAL_FENCE_WRITE_EXCLUDED); + UT_ASSERT_EQ(cluster_external_fence_admit_wait(&need, 5000, &admission), + PGRAC_EXTERNAL_FENCE_WRITE_EXCLUDED); UT_ASSERT(admission != NULL); - UT_ASSERT_EQ(cluster_external_fence_test_admission_lease_ms(admission), - entry_values[i]); + UT_ASSERT_EQ(cluster_external_fence_test_admission_lease_ms(admission), entry_values[i]); cluster_external_fence_admission_release(admission); UT_ASSERT_EQ(waitpid(child, &status, 0), child); UT_ASSERT(WIFEXITED(status)); @@ -1010,42 +910,38 @@ UT_TEST(test_external_fence_live_admission_detects_daemon_close) UT_ASSERT_EQ(pipe(control), 0); child = fork(); UT_ASSERT(child >= 0); - if (child == 0) - { + if (child == 0) { int child_rc; - (void) close(sockets[0]); - (void) close(control[1]); - child_rc = test_only_affirmative_provider_child_timed(sockets[1], - UINT64_C(9), UINT64_C(1000000000), 0, control[0]); - (void) close(control[0]); - (void) close(sockets[1]); + (void)close(sockets[0]); + (void)close(control[1]); + child_rc = test_only_affirmative_provider_child_timed(sockets[1], UINT64_C(9), + UINT64_C(1000000000), 0, control[0]); + (void)close(control[0]); + (void)close(sockets[1]); _exit(child_rc); } - (void) close(sockets[1]); - (void) close(control[0]); + (void)close(sockets[1]); + (void)close(control[0]); stub_root_transport_fd = sockets[0]; stub_runtime_active = true; memset(&need, 0, sizeof(need)); need.system_identifier = UINT64_C(0x0123456789abcdef); - memset(need.canonical_duty_digest.bytes, 0xa5, - sizeof(need.canonical_duty_digest.bytes)); + memset(need.canonical_duty_digest.bytes, 0xa5, sizeof(need.canonical_duty_digest.bytes)); need.victim_node_id = 1; need.victim_incarnation = UINT64_C(0x100000001); - memset(need.protected_set_digest, 0x5a, - sizeof(need.protected_set_digest)); + memset(need.protected_set_digest, 0x5a, sizeof(need.protected_set_digest)); need.predicate_id = PGRAC_EXTERNAL_FENCE_PREDICATE_WRITE_EXCLUDED; need.predicate_version = PGRAC_EXTERNAL_FENCE_PREDICATE_VERSION_V1; UT_ASSERT_EQ(cluster_external_fence_admit_wait(&need, 5000, &admission), - PGRAC_EXTERNAL_FENCE_WRITE_EXCLUDED); + PGRAC_EXTERNAL_FENCE_WRITE_EXCLUDED); UT_ASSERT(admission != NULL); UT_ASSERT_EQ(write(control[1], "x", 1), 1); - (void) close(control[1]); + (void)close(control[1]); UT_ASSERT_EQ(waitpid(child, &status, 0), child); UT_ASSERT(WIFEXITED(status)); UT_ASSERT_EQ(WEXITSTATUS(status), 0); - UT_ASSERT(!cluster_external_fence_revalidate_nowait(admission, &need, - &reason)); + UT_ASSERT(!cluster_external_fence_revalidate_nowait(admission, &need, &reason)); UT_ASSERT_EQ(reason, PGRAC_EXTERNAL_FENCE_DENY_CONNECTION_CLOSED); cluster_external_fence_admission_release(admission); stub_runtime_active = false; @@ -1066,64 +962,59 @@ UT_TEST(test_external_fence_e1_child_owns_independent_admission) UT_ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, parent_sockets), 0); parent_provider = fork(); UT_ASSERT(parent_provider >= 0); - if (parent_provider == 0) - { + if (parent_provider == 0) { int child_rc; - (void) close(parent_sockets[0]); + (void)close(parent_sockets[0]); child_rc = test_only_affirmative_provider_child(parent_sockets[1]); - (void) close(parent_sockets[1]); + (void)close(parent_sockets[1]); _exit(child_rc); } - (void) close(parent_sockets[1]); + (void)close(parent_sockets[1]); stub_root_transport_fd = parent_sockets[0]; stub_runtime_active = true; - UT_ASSERT_EQ(cluster_external_fence_admit_wait( - &need, 5000, &parent_admission), - PGRAC_EXTERNAL_FENCE_WRITE_EXCLUDED); + UT_ASSERT_EQ(cluster_external_fence_admit_wait(&need, 5000, &parent_admission), + PGRAC_EXTERNAL_FENCE_WRITE_EXCLUDED); UT_ASSERT(parent_admission != NULL); UT_ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, child_sockets), 0); child_provider = fork(); UT_ASSERT(child_provider >= 0); - if (child_provider == 0) - { + if (child_provider == 0) { int child_rc; - (void) close(child_sockets[0]); + (void)close(child_sockets[0]); child_rc = test_only_affirmative_provider_child(child_sockets[1]); - (void) close(child_sockets[1]); + (void)close(child_sockets[1]); _exit(child_rc); } - (void) close(child_sockets[1]); + (void)close(child_sockets[1]); e1_child = fork(); UT_ASSERT(e1_child >= 0); - if (e1_child == 0) - { + if (e1_child == 0) { PgracExternalFenceAdmissionV1 *own_admission = NULL; PgracExternalFenceDenyReason reason = PGRAC_EXTERNAL_FENCE_DENY_NONE; int child_rc = 0; /* A checkpointer/restartpointer must reject an inherited pointer. */ - if (cluster_external_fence_revalidate_nowait( - parent_admission, &need, &reason) || - reason != PGRAC_EXTERNAL_FENCE_DENY_BAD_ARGUMENT) + if (cluster_external_fence_revalidate_nowait(parent_admission, &need, &reason) + || reason != PGRAC_EXTERNAL_FENCE_DENY_BAD_ARGUMENT) child_rc = 1; stub_root_transport_fd = child_sockets[0]; stub_root_transport_count = 0; stub_root_transport_index = 0; - if (child_rc == 0 && cluster_external_fence_admit_wait( - &need, 5000, &own_admission) != - PGRAC_EXTERNAL_FENCE_WRITE_EXCLUDED) + if (child_rc == 0 + && cluster_external_fence_admit_wait(&need, 5000, &own_admission) + != PGRAC_EXTERNAL_FENCE_WRITE_EXCLUDED) child_rc = 2; - if (child_rc == 0 && (own_admission == NULL || - !cluster_external_fence_revalidate_nowait( - own_admission, &need, &reason))) + if (child_rc == 0 + && (own_admission == NULL + || !cluster_external_fence_revalidate_nowait(own_admission, &need, &reason))) child_rc = 3; cluster_external_fence_admission_release(own_admission); _exit(child_rc); } - (void) close(child_sockets[0]); + (void)close(child_sockets[0]); UT_ASSERT_EQ(waitpid(e1_child, &status, 0), e1_child); UT_ASSERT(WIFEXITED(status)); UT_ASSERT_EQ(WEXITSTATUS(status), 0); @@ -1157,26 +1048,23 @@ UT_TEST(test_external_fence_mapping_reload_closes_old_and_fresh_admits) UT_ASSERT_EQ(pipe(old_control), 0); old_provider = fork(); UT_ASSERT(old_provider >= 0); - if (old_provider == 0) - { + if (old_provider == 0) { int child_rc; - (void) close(old_sockets[0]); - (void) close(old_control[1]); + (void)close(old_sockets[0]); + (void)close(old_control[1]); child_rc = test_only_affirmative_provider_child_timed( - old_sockets[1], UINT64_C(9), UINT64_C(1000000000), 0, - old_control[0]); - (void) close(old_control[0]); - (void) close(old_sockets[1]); + old_sockets[1], UINT64_C(9), UINT64_C(1000000000), 0, old_control[0]); + (void)close(old_control[0]); + (void)close(old_sockets[1]); _exit(child_rc); } - (void) close(old_sockets[1]); - (void) close(old_control[0]); + (void)close(old_sockets[1]); + (void)close(old_control[0]); stub_root_transport_fd = old_sockets[0]; stub_runtime_active = true; - UT_ASSERT_EQ(cluster_external_fence_admit_wait( - &need, 5000, &old_admission), - PGRAC_EXTERNAL_FENCE_WRITE_EXCLUDED); + UT_ASSERT_EQ(cluster_external_fence_admit_wait(&need, 5000, &old_admission), + PGRAC_EXTERNAL_FENCE_WRITE_EXCLUDED); binding = cluster_external_fence_admission_binding(old_admission); UT_ASSERT(binding != NULL); if (binding != NULL) @@ -1184,39 +1072,35 @@ UT_TEST(test_external_fence_mapping_reload_closes_old_and_fresh_admits) /* The daemon closes old live admissions before enabling generation 10. */ UT_ASSERT_EQ(write(old_control[1], "x", 1), 1); - (void) close(old_control[1]); + (void)close(old_control[1]); UT_ASSERT_EQ(waitpid(old_provider, &status, 0), old_provider); UT_ASSERT(WIFEXITED(status)); UT_ASSERT_EQ(WEXITSTATUS(status), 0); - UT_ASSERT(!cluster_external_fence_revalidate_nowait( - old_admission, &need, &reason)); + UT_ASSERT(!cluster_external_fence_revalidate_nowait(old_admission, &need, &reason)); UT_ASSERT_EQ(reason, PGRAC_EXTERNAL_FENCE_DENY_CONNECTION_CLOSED); cluster_external_fence_admission_release(old_admission); UT_ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, new_sockets), 0); new_provider = fork(); UT_ASSERT(new_provider >= 0); - if (new_provider == 0) - { + if (new_provider == 0) { int child_rc; - (void) close(new_sockets[0]); - child_rc = test_only_affirmative_provider_child_timed( - new_sockets[1], UINT64_C(10), UINT64_C(1000000000), 0, -1); - (void) close(new_sockets[1]); + (void)close(new_sockets[0]); + child_rc = test_only_affirmative_provider_child_timed(new_sockets[1], UINT64_C(10), + UINT64_C(1000000000), 0, -1); + (void)close(new_sockets[1]); _exit(child_rc); } - (void) close(new_sockets[1]); + (void)close(new_sockets[1]); stub_root_transport_fd = new_sockets[0]; - UT_ASSERT_EQ(cluster_external_fence_admit_wait( - &need, 5000, &new_admission), - PGRAC_EXTERNAL_FENCE_WRITE_EXCLUDED); + UT_ASSERT_EQ(cluster_external_fence_admit_wait(&need, 5000, &new_admission), + PGRAC_EXTERNAL_FENCE_WRITE_EXCLUDED); binding = cluster_external_fence_admission_binding(new_admission); UT_ASSERT(binding != NULL); if (binding != NULL) UT_ASSERT_EQ(binding->target_mapping_generation, UINT64_C(10)); - UT_ASSERT(cluster_external_fence_revalidate_nowait( - new_admission, &need, &reason)); + UT_ASSERT(cluster_external_fence_revalidate_nowait(new_admission, &need, &reason)); cluster_external_fence_admission_release(new_admission); UT_ASSERT_EQ(waitpid(new_provider, &status, 0), new_provider); UT_ASSERT(WIFEXITED(status)); @@ -1227,10 +1111,8 @@ UT_TEST(test_external_fence_mapping_reload_closes_old_and_fresh_admits) UT_TEST(test_external_fence_admit_set_ands_all_sorted_writers) { ClusterRecoveryDutyKey duty; - const ClusterFormationWitnessV1 *formation = - (const ClusterFormationWitnessV1 *) (uintptr_t) 1; - const ClusterFormationWitnessV1 *replacement = - (const ClusterFormationWitnessV1 *) (uintptr_t) 2; + const ClusterFormationWitnessV1 *formation = (const ClusterFormationWitnessV1 *)(uintptr_t)1; + const ClusterFormationWitnessV1 *replacement = (const ClusterFormationWitnessV1 *)(uintptr_t)2; PgracExternalFenceNeedSetV1 *needs = NULL; PgracExternalFenceAdmissionSetV1 *admissions = NULL; PgracExternalFenceDenyReason reason = PGRAC_EXTERNAL_FENCE_DENY_NONE; @@ -1254,54 +1136,46 @@ UT_TEST(test_external_fence_admit_set_ands_all_sorted_writers) stub_formation_authority.marker.fence_generation = UINT64_C(7); stub_formation_authority.marker.issuer_node_id = 3; stub_formation_authority.marker.fenced_dead_bitmap[0] = UINT8_C(0x05); - stub_formation_authority.marker.marker_kind = - CLUSTER_FENCE_MARKER_KIND_FENCE; + stub_formation_authority.marker.marker_kind = CLUSTER_FENCE_MARKER_KIND_FENCE; stub_formation_snapshot.excluded_bitmap[0] = UINT8_C(0x05); - stub_formation_snapshot.membership.membership_state[0] = - CLUSTER_MEMBER_DEAD; - stub_formation_snapshot.membership.membership_state[2] = - CLUSTER_MEMBER_REMOVED; - stub_formation_snapshot.membership.last_admitted_incarnation[0] = - duty.origin_owner_incarnation; - stub_formation_snapshot.membership.last_admitted_incarnation[2] = - UINT64_C(0x300000003); + stub_formation_snapshot.membership.membership_state[0] = CLUSTER_MEMBER_DEAD; + stub_formation_snapshot.membership.membership_state[2] = CLUSTER_MEMBER_REMOVED; + stub_formation_snapshot.membership.last_admitted_incarnation[0] = duty.origin_owner_incarnation; + stub_formation_snapshot.membership.last_admitted_incarnation[2] = UINT64_C(0x300000003); stub_formation_snapshot.local_epoch = UINT64_C(4); stub_local_capabilities = PGRAC_IC_HELLO_CAP_CONTROL_ROOT_V1; stub_runtime_active = true; stub_protected_set_identity_available = true; - stub_protected_set_identity.backend_id = - CLUSTER_SHARED_FS_BACKEND_BLOCK_DEVICE; + stub_protected_set_identity.backend_id = CLUSTER_SHARED_FS_BACKEND_BLOCK_DEVICE; memcpy(stub_protected_set_identity.storage_uuid, duty.storage_uuid, - sizeof(stub_protected_set_identity.storage_uuid)); - UT_ASSERT_EQ(cluster_external_fence_need_set_build( - &duty, formation, &needs), PGRAC_EXTERNAL_FENCE_NEED_SET_OK); + sizeof(stub_protected_set_identity.storage_uuid)); + UT_ASSERT_EQ(cluster_external_fence_need_set_build(&duty, formation, &needs), + PGRAC_EXTERNAL_FENCE_NEED_SET_OK); UT_ASSERT(needs != NULL); stub_root_transport_count = 2; stub_root_transport_index = 0; stub_external_admit_requested = 0; - for (i = 0; i < 2; i++) - { + for (i = 0; i < 2; i++) { UT_ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, sockets[i]), 0); children[i] = fork(); UT_ASSERT(children[i] >= 0); - if (children[i] == 0) - { + if (children[i] == 0) { int child_rc; int prior; for (prior = 0; prior < i; prior++) - (void) close(sockets[prior][0]); - (void) close(sockets[i][0]); + (void)close(sockets[prior][0]); + (void)close(sockets[i][0]); child_rc = test_only_affirmative_provider_child(sockets[i][1]); - (void) close(sockets[i][1]); + (void)close(sockets[i][1]); _exit(child_rc); } - (void) close(sockets[i][1]); + (void)close(sockets[i][1]); stub_root_transport_fds[i] = sockets[i][0]; } - UT_ASSERT_EQ(cluster_external_fence_admit_set_wait(needs, formation, - 5000, &admissions), PGRAC_EXTERNAL_FENCE_WRITE_EXCLUDED); + UT_ASSERT_EQ(cluster_external_fence_admit_set_wait(needs, formation, 5000, &admissions), + PGRAC_EXTERNAL_FENCE_WRITE_EXCLUDED); UT_ASSERT(admissions != NULL); UT_ASSERT_EQ(cluster_external_fence_admission_set_count(admissions), 2); binding = cluster_external_fence_admission_set_binding_at(admissions, 0); @@ -1312,20 +1186,17 @@ UT_TEST(test_external_fence_admit_set_ands_all_sorted_writers) UT_ASSERT(binding != NULL); if (binding != NULL) UT_ASSERT_EQ(binding->victim_node_id, 2); - UT_ASSERT(cluster_external_fence_revalidate_set_nowait( - admissions, needs, formation, &reason)); + UT_ASSERT(cluster_external_fence_revalidate_set_nowait(admissions, needs, formation, &reason)); UT_ASSERT_EQ(reason, PGRAC_EXTERNAL_FENCE_DENY_NONE); - UT_ASSERT(!cluster_external_fence_revalidate_set_nowait( - admissions, needs, replacement, &reason)); + UT_ASSERT( + !cluster_external_fence_revalidate_set_nowait(admissions, needs, replacement, &reason)); UT_ASSERT_EQ(reason, PGRAC_EXTERNAL_FENCE_DENY_WRITER_SET_STALE); UT_ASSERT_EQ(stub_external_admit_requested, 2); cluster_external_fence_admission_set_release(&admissions); UT_ASSERT(admissions == NULL); - for (i = 0; i < 2; i++) - { - if (stub_root_transport_fds[i] >= 0) - { - (void) close(stub_root_transport_fds[i]); + for (i = 0; i < 2; i++) { + if (stub_root_transport_fds[i] >= 0) { + (void)close(stub_root_transport_fds[i]); stub_root_transport_fds[i] = -1; } UT_ASSERT_EQ(waitpid(children[i], &status, 0), children[i]); @@ -1342,8 +1213,7 @@ UT_TEST(test_external_fence_admit_set_ands_all_sorted_writers) UT_TEST(test_external_fence_admit_set_reverses_partial_success) { ClusterRecoveryDutyKey duty; - const ClusterFormationWitnessV1 *formation = - (const ClusterFormationWitnessV1 *) (uintptr_t) 1; + const ClusterFormationWitnessV1 *formation = (const ClusterFormationWitnessV1 *)(uintptr_t)1; PgracExternalFenceNeedSetV1 *needs = NULL; PgracExternalFenceAdmissionSetV1 *admissions = NULL; int sockets[2][2]; @@ -1353,48 +1223,42 @@ UT_TEST(test_external_fence_admit_set_reverses_partial_success) fill_valid_duty(&duty); prepare_two_writer_formation(&duty); - UT_ASSERT_EQ(cluster_external_fence_need_set_build( - &duty, formation, &needs), PGRAC_EXTERNAL_FENCE_NEED_SET_OK); + UT_ASSERT_EQ(cluster_external_fence_need_set_build(&duty, formation, &needs), + PGRAC_EXTERNAL_FENCE_NEED_SET_OK); for (i = 0; i < 2; i++) UT_ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, sockets[i]), 0); - for (i = 0; i < 2; i++) - { + for (i = 0; i < 2; i++) { children[i] = fork(); UT_ASSERT(children[i] >= 0); - if (children[i] == 0) - { + if (children[i] == 0) { int child_rc; int j; - for (j = 0; j < 2; j++) - { - (void) close(sockets[j][0]); + for (j = 0; j < 2; j++) { + (void)close(sockets[j][0]); if (j != i) - (void) close(sockets[j][1]); + (void)close(sockets[j][1]); } - child_rc = i == 0 ? - test_only_affirmative_provider_child(sockets[i][1]) : - test_only_negative_provider_child(sockets[i][1]); - (void) close(sockets[i][1]); + child_rc = i == 0 ? test_only_affirmative_provider_child(sockets[i][1]) + : test_only_negative_provider_child(sockets[i][1]); + (void)close(sockets[i][1]); _exit(child_rc); } } stub_root_transport_count = 2; stub_root_transport_index = 0; stub_external_admit_requested = 0; - for (i = 0; i < 2; i++) - { - (void) close(sockets[i][1]); + for (i = 0; i < 2; i++) { + (void)close(sockets[i][1]); stub_root_transport_fds[i] = sockets[i][0]; } - UT_ASSERT_EQ(cluster_external_fence_admit_set_wait(needs, formation, - 5000, &admissions), PGRAC_EXTERNAL_FENCE_UNKNOWN); + UT_ASSERT_EQ(cluster_external_fence_admit_set_wait(needs, formation, 5000, &admissions), + PGRAC_EXTERNAL_FENCE_UNKNOWN); UT_ASSERT(admissions == NULL); UT_ASSERT_EQ(cluster_external_fence_last_deny_reason(), - PGRAC_EXTERNAL_FENCE_DENY_PROVIDER_UNKNOWN); + PGRAC_EXTERNAL_FENCE_DENY_PROVIDER_UNKNOWN); UT_ASSERT_EQ(stub_external_admit_requested, 2); - for (i = 0; i < 2; i++) - { + for (i = 0; i < 2; i++) { UT_ASSERT_EQ(waitpid(children[i], &status, 0), children[i]); UT_ASSERT(WIFEXITED(status)); UT_ASSERT_EQ(WEXITSTATUS(status), 0); @@ -1409,8 +1273,7 @@ UT_TEST(test_external_fence_admit_set_reverses_partial_success) UT_TEST(test_external_fence_admit_set_final_expiry_clears_whole_output) { ClusterRecoveryDutyKey duty; - const ClusterFormationWitnessV1 *formation = - (const ClusterFormationWitnessV1 *) (uintptr_t) 1; + const ClusterFormationWitnessV1 *formation = (const ClusterFormationWitnessV1 *)(uintptr_t)1; PgracExternalFenceNeedSetV1 *needs = NULL; PgracExternalFenceAdmissionSetV1 *admissions = NULL; int sockets[2][2]; @@ -1420,47 +1283,40 @@ UT_TEST(test_external_fence_admit_set_final_expiry_clears_whole_output) fill_valid_duty(&duty); prepare_two_writer_formation(&duty); - UT_ASSERT_EQ(cluster_external_fence_need_set_build( - &duty, formation, &needs), PGRAC_EXTERNAL_FENCE_NEED_SET_OK); + UT_ASSERT_EQ(cluster_external_fence_need_set_build(&duty, formation, &needs), + PGRAC_EXTERNAL_FENCE_NEED_SET_OK); for (i = 0; i < 2; i++) UT_ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, sockets[i]), 0); - for (i = 0; i < 2; i++) - { + for (i = 0; i < 2; i++) { children[i] = fork(); UT_ASSERT(children[i] >= 0); - if (children[i] == 0) - { + if (children[i] == 0) { int child_rc; int j; - for (j = 0; j < 2; j++) - { - (void) close(sockets[j][0]); + for (j = 0; j < 2; j++) { + (void)close(sockets[j][0]); if (j != i) - (void) close(sockets[j][1]); + (void)close(sockets[j][1]); } child_rc = test_only_affirmative_provider_child_timed( - sockets[i][1], UINT64_C(9), - i == 0 ? UINT64_C(30000000) : - UINT64_C(1000000000), i == 0 ? 0 : 100, -1); - (void) close(sockets[i][1]); + sockets[i][1], UINT64_C(9), i == 0 ? UINT64_C(30000000) : UINT64_C(1000000000), + i == 0 ? 0 : 100, -1); + (void)close(sockets[i][1]); _exit(child_rc); } } stub_root_transport_count = 2; stub_root_transport_index = 0; - for (i = 0; i < 2; i++) - { - (void) close(sockets[i][1]); + for (i = 0; i < 2; i++) { + (void)close(sockets[i][1]); stub_root_transport_fds[i] = sockets[i][0]; } - UT_ASSERT_EQ(cluster_external_fence_admit_set_wait(needs, formation, - 5000, &admissions), PGRAC_EXTERNAL_FENCE_UNAVAILABLE); + UT_ASSERT_EQ(cluster_external_fence_admit_set_wait(needs, formation, 5000, &admissions), + PGRAC_EXTERNAL_FENCE_UNAVAILABLE); UT_ASSERT(admissions == NULL); - UT_ASSERT_EQ(cluster_external_fence_last_deny_reason(), - PGRAC_EXTERNAL_FENCE_DENY_EXPIRED); - for (i = 0; i < 2; i++) - { + UT_ASSERT_EQ(cluster_external_fence_last_deny_reason(), PGRAC_EXTERNAL_FENCE_DENY_EXPIRED); + for (i = 0; i < 2; i++) { UT_ASSERT_EQ(waitpid(children[i], &status, 0), children[i]); UT_ASSERT(WIFEXITED(status)); UT_ASSERT_EQ(WEXITSTATUS(status), 0); @@ -1475,8 +1331,7 @@ UT_TEST(test_external_fence_admit_set_final_expiry_clears_whole_output) UT_TEST(test_external_rejoin_races_invalidate_sets_and_held_guard) { ClusterRecoveryDutyKey duty; - const ClusterFormationWitnessV1 *formation = - (const ClusterFormationWitnessV1 *) (uintptr_t) 1; + const ClusterFormationWitnessV1 *formation = (const ClusterFormationWitnessV1 *)(uintptr_t)1; PgracExternalFenceNeedSetV1 *needs = NULL; PgracExternalFenceAdmissionSetV1 *admissions = NULL; PgracExternalFenceDenyReason reason = PGRAC_EXTERNAL_FENCE_DENY_NONE; @@ -1488,81 +1343,70 @@ UT_TEST(test_external_rejoin_races_invalidate_sets_and_held_guard) fill_valid_duty(&duty); prepare_two_writer_formation(&duty); - UT_ASSERT_EQ(cluster_external_fence_need_set_build( - &duty, formation, &needs), PGRAC_EXTERNAL_FENCE_NEED_SET_OK); + UT_ASSERT_EQ(cluster_external_fence_need_set_build(&duty, formation, &needs), + PGRAC_EXTERNAL_FENCE_NEED_SET_OK); UT_ASSERT(needs != NULL); /* A rejoin/new-configuration cut before the first connect is zero-I/O. */ stub_root_transport_count = 0; stub_root_transport_index = 0; stub_formation_result = CLUSTER_FORMATION_WITNESS_UNSTABLE; - UT_ASSERT_EQ(cluster_external_fence_admit_set_wait( - needs, formation, 5000, &admissions), - PGRAC_EXTERNAL_FENCE_UNAVAILABLE); + UT_ASSERT_EQ(cluster_external_fence_admit_set_wait(needs, formation, 5000, &admissions), + PGRAC_EXTERNAL_FENCE_UNAVAILABLE); UT_ASSERT(admissions == NULL); UT_ASSERT_EQ(cluster_external_fence_last_deny_reason(), - PGRAC_EXTERNAL_FENCE_DENY_WRITER_SET_STALE); + PGRAC_EXTERNAL_FENCE_DENY_WRITER_SET_STALE); UT_ASSERT_EQ(stub_root_transport_index, 0); stub_formation_result = CLUSTER_FORMATION_WITNESS_READY; - for (i = 0; i < 2; i++) - { + for (i = 0; i < 2; i++) { UT_ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, sockets[i]), 0); UT_ASSERT_EQ(pipe(controls[i]), 0); } - for (i = 0; i < 2; i++) - { + for (i = 0; i < 2; i++) { children[i] = fork(); UT_ASSERT(children[i] >= 0); - if (children[i] == 0) - { + if (children[i] == 0) { int child_rc; int j; - for (j = 0; j < 2; j++) - { - (void) close(sockets[j][0]); - (void) close(controls[j][1]); - if (j != i) - { - (void) close(sockets[j][1]); - (void) close(controls[j][0]); + for (j = 0; j < 2; j++) { + (void)close(sockets[j][0]); + (void)close(controls[j][1]); + if (j != i) { + (void)close(sockets[j][1]); + (void)close(controls[j][0]); } } child_rc = test_only_affirmative_provider_child_timed( - sockets[i][1], UINT64_C(9), UINT64_C(1000000000), 0, - controls[i][0]); - (void) close(controls[i][0]); - (void) close(sockets[i][1]); + sockets[i][1], UINT64_C(9), UINT64_C(1000000000), 0, controls[i][0]); + (void)close(controls[i][0]); + (void)close(sockets[i][1]); _exit(child_rc); } } stub_root_transport_count = 2; stub_root_transport_index = 0; - for (i = 0; i < 2; i++) - { - (void) close(sockets[i][1]); - (void) close(controls[i][0]); + for (i = 0; i < 2; i++) { + (void)close(sockets[i][1]); + (void)close(controls[i][0]); stub_root_transport_fds[i] = sockets[i][0]; } - UT_ASSERT_EQ(cluster_external_fence_admit_set_wait( - needs, formation, 5000, &admissions), - PGRAC_EXTERNAL_FENCE_WRITE_EXCLUDED); + UT_ASSERT_EQ(cluster_external_fence_admit_set_wait(needs, formation, 5000, &admissions), + PGRAC_EXTERNAL_FENCE_WRITE_EXCLUDED); UT_ASSERT(admissions != NULL); /* AUTHORIZE closes every old fd; P/new epoch makes the set stale. */ stub_formation_snapshot.local_epoch++; stub_formation_result = CLUSTER_FORMATION_WITNESS_UNSTABLE; - for (i = 0; i < 2; i++) - { + for (i = 0; i < 2; i++) { UT_ASSERT_EQ(write(controls[i][1], "x", 1), 1); - (void) close(controls[i][1]); + (void)close(controls[i][1]); UT_ASSERT_EQ(waitpid(children[i], &status, 0), children[i]); UT_ASSERT(WIFEXITED(status)); UT_ASSERT_EQ(WEXITSTATUS(status), 0); } - UT_ASSERT(!cluster_external_fence_revalidate_set_nowait( - admissions, needs, formation, &reason)); + UT_ASSERT(!cluster_external_fence_revalidate_set_nowait(admissions, needs, formation, &reason)); UT_ASSERT_EQ(reason, PGRAC_EXTERNAL_FENCE_DENY_WRITER_SET_STALE); cluster_external_fence_admission_set_release(&admissions); @@ -1577,36 +1421,30 @@ UT_TEST(test_external_rejoin_races_invalidate_sets_and_held_guard) UT_TEST(test_external_fence_entry_and_nowait_fail_closed) { PgracExternalFenceNeedV1 need; - PgracExternalFenceAdmissionV1 *admission = - (PgracExternalFenceAdmissionV1 *) (uintptr_t) 1; - PgracExternalFenceAdmissionSetV1 *admissions = - (PgracExternalFenceAdmissionSetV1 *) (uintptr_t) 1; + PgracExternalFenceAdmissionV1 *admission = (PgracExternalFenceAdmissionV1 *)(uintptr_t)1; + PgracExternalFenceAdmissionSetV1 *admissions = (PgracExternalFenceAdmissionSetV1 *)(uintptr_t)1; PgracExternalFenceDenyReason reason = PGRAC_EXTERNAL_FENCE_DENY_NONE; memset(&need, 0, sizeof(need)); UT_ASSERT_EQ(cluster_external_fence_admit_wait(&need, 0, &admission), PGRAC_EXTERNAL_FENCE_UNAVAILABLE); UT_ASSERT(admission == NULL); - UT_ASSERT_EQ(cluster_external_fence_last_deny_reason(), - PGRAC_EXTERNAL_FENCE_DENY_BAD_ARGUMENT); + UT_ASSERT_EQ(cluster_external_fence_last_deny_reason(), PGRAC_EXTERNAL_FENCE_DENY_BAD_ARGUMENT); UT_ASSERT(!cluster_external_fence_revalidate_nowait(NULL, &need, &reason)); UT_ASSERT_EQ(reason, PGRAC_EXTERNAL_FENCE_DENY_BAD_ARGUMENT); - UT_ASSERT_EQ(cluster_external_fence_admit_set_wait(NULL, NULL, 0, - &admissions), + UT_ASSERT_EQ(cluster_external_fence_admit_set_wait(NULL, NULL, 0, &admissions), PGRAC_EXTERNAL_FENCE_UNAVAILABLE); UT_ASSERT(admissions == NULL); - UT_ASSERT_EQ(cluster_external_fence_last_deny_reason(), - PGRAC_EXTERNAL_FENCE_DENY_BAD_ARGUMENT); + UT_ASSERT_EQ(cluster_external_fence_last_deny_reason(), PGRAC_EXTERNAL_FENCE_DENY_BAD_ARGUMENT); cluster_external_fence_admission_release(NULL); cluster_external_fence_admission_set_release(NULL); } UT_TEST(test_external_fence_rejoin_api_provider_zero_fails_closed) { - PgracExternalFenceRejoinOpV1 *op = - (PgracExternalFenceRejoinOpV1 *) (uintptr_t) 1; - PgracExternalFenceRejoinAuthorityClearV1 *clear = - (PgracExternalFenceRejoinAuthorityClearV1 *) (uintptr_t) 1; + PgracExternalFenceRejoinOpV1 *op = (PgracExternalFenceRejoinOpV1 *)(uintptr_t)1; + PgracExternalFenceRejoinAuthorityClearV1 *clear + = (PgracExternalFenceRejoinAuthorityClearV1 *)(uintptr_t)1; PgracExternalFenceDenyReason reason = PGRAC_EXTERNAL_FENCE_DENY_NONE; ClusterControlRootSnapshot snapshot; ClusterReconfigRejoinPendingSnapshotV1 pending; @@ -1624,26 +1462,22 @@ UT_TEST(test_external_fence_rejoin_api_provider_zero_fails_closed) PGRAC_EXTERNAL_FENCE_REJOIN_UNAVAILABLE); UT_ASSERT_EQ(reason, PGRAC_EXTERNAL_FENCE_DENY_BAD_ARGUMENT); UT_ASSERT(cluster_external_fence_rejoin_offer(NULL) == NULL); - UT_ASSERT_EQ(cluster_external_fence_rejoin_authority_clear_build( - NULL, NULL, NULL, &clear, &reason), + UT_ASSERT_EQ( + cluster_external_fence_rejoin_authority_clear_build(NULL, NULL, NULL, &clear, &reason), PGRAC_EXTERNAL_FENCE_REJOIN_UNAVAILABLE); UT_ASSERT(clear == NULL); UT_ASSERT_EQ(reason, PGRAC_EXTERNAL_FENCE_DENY_BAD_ARGUMENT); - UT_ASSERT_EQ(cluster_external_fence_rejoin_authorize_on_async( - NULL, &clear, NULL, NULL, NULL, NULL, &reason), - PGRAC_EXTERNAL_FENCE_REJOIN_UNAVAILABLE); + UT_ASSERT_EQ(cluster_external_fence_rejoin_authorize_on_async(NULL, &clear, NULL, NULL, NULL, + NULL, &reason), + PGRAC_EXTERNAL_FENCE_REJOIN_UNAVAILABLE); UT_ASSERT_EQ(reason, PGRAC_EXTERNAL_FENCE_DENY_BAD_ARGUMENT); - UT_ASSERT_EQ(cluster_external_fence_rejoin_refresh_on_async( - NULL, &pending, &reason), - PGRAC_EXTERNAL_FENCE_REJOIN_UNAVAILABLE); + UT_ASSERT_EQ(cluster_external_fence_rejoin_refresh_on_async(NULL, &pending, &reason), + PGRAC_EXTERNAL_FENCE_REJOIN_UNAVAILABLE); UT_ASSERT_EQ(reason, PGRAC_EXTERNAL_FENCE_DENY_BAD_ARGUMENT); - UT_ASSERT(!cluster_external_fence_rejoin_revalidate_root( - NULL, &snapshot, &reason)); + UT_ASSERT(!cluster_external_fence_rejoin_revalidate_root(NULL, &snapshot, &reason)); UT_ASSERT_EQ(reason, PGRAC_EXTERNAL_FENCE_DENY_BAD_ARGUMENT); - UT_ASSERT(memcmp(&snapshot, &(ClusterControlRootSnapshot){ 0 }, - sizeof(snapshot)) == 0); - UT_ASSERT(!cluster_external_fence_rejoin_consume_nowait( - NULL, &pending, &marker, &reason)); + UT_ASSERT(memcmp(&snapshot, &(ClusterControlRootSnapshot){ 0 }, sizeof(snapshot)) == 0); + UT_ASSERT(!cluster_external_fence_rejoin_consume_nowait(NULL, &pending, &marker, &reason)); UT_ASSERT_EQ(reason, PGRAC_EXTERNAL_FENCE_DENY_BAD_ARGUMENT); UT_ASSERT(cluster_external_fence_rejoin_binding(NULL) == NULL); cluster_external_fence_rejoin_release(NULL); @@ -1663,17 +1497,16 @@ UT_TEST(test_external_fence_current_package_forbids_activation_but_binds_storage stub_protected_set_identity_available = false; memset(digest, 0xa5, sizeof(digest)); UT_ASSERT(!cluster_external_fence_rejoin_protected_set_digest(digest)); - UT_ASSERT(memcmp(digest, (uint8[32]) { 0 }, sizeof(digest)) == 0); + UT_ASSERT(memcmp(digest, (uint8[32]){ 0 }, sizeof(digest)) == 0); - memset(&stub_protected_set_identity, 0, - sizeof(stub_protected_set_identity)); + memset(&stub_protected_set_identity, 0, sizeof(stub_protected_set_identity)); stub_protected_set_identity.backend_id = 2; memset(stub_protected_set_identity.storage_uuid, 0x5a, sizeof(stub_protected_set_identity.storage_uuid)); stub_protected_set_identity_available = true; - UT_ASSERT(pgrac_external_fence_protected_set_digest_v1( - stub_protected_set_identity.backend_id, - stub_protected_set_identity.storage_uuid, expected)); + UT_ASSERT(pgrac_external_fence_protected_set_digest_v1(stub_protected_set_identity.backend_id, + stub_protected_set_identity.storage_uuid, + expected)); UT_ASSERT(cluster_external_fence_rejoin_protected_set_digest(digest)); UT_ASSERT(memcmp(digest, expected, sizeof(digest)) == 0); } @@ -1691,33 +1524,30 @@ UT_TEST(test_external_fence_rejoin_rejects_unauthenticated_root_peer) UT_ASSERT(listen_fd >= 0); if (listen_fd < 0) return; - snprintf(socket_path, sizeof(socket_path), - "/tmp/pgrac-rejoin-auth-%ld.sock", (long) getpid()); - (void) unlink(socket_path); + snprintf(socket_path, sizeof(socket_path), "/tmp/pgrac-rejoin-auth-%ld.sock", (long)getpid()); + (void)unlink(socket_path); memset(&address, 0, sizeof(address)); address.sun_family = AF_UNIX; strlcpy(address.sun_path, socket_path, sizeof(address.sun_path)); - UT_ASSERT_EQ(bind(listen_fd, (struct sockaddr *) &address, - sizeof(address)), 0); + UT_ASSERT_EQ(bind(listen_fd, (struct sockaddr *)&address, sizeof(address)), 0); UT_ASSERT_EQ(listen(listen_fd, 1), 0); cluster_external_fence_socket_path = socket_path; stub_root_peer_authenticated = false; UT_ASSERT_EQ(cluster_external_fence_rejoin_start_async(5000, &op), - PGRAC_EXTERNAL_FENCE_REJOIN_PENDING); + PGRAC_EXTERNAL_FENCE_REJOIN_PENDING); UT_ASSERT(op != NULL); peer_fd = accept(listen_fd, NULL, NULL); UT_ASSERT(peer_fd >= 0); UT_ASSERT_EQ(cluster_external_fence_rejoin_poll_nowait(op, &reason), - PGRAC_EXTERNAL_FENCE_REJOIN_UNAVAILABLE); + PGRAC_EXTERNAL_FENCE_REJOIN_UNAVAILABLE); UT_ASSERT_EQ(reason, PGRAC_EXTERNAL_FENCE_DENY_PEER_AUTH); cluster_external_fence_rejoin_release(&op); UT_ASSERT(op == NULL); if (peer_fd >= 0) - (void) close(peer_fd); - (void) close(listen_fd); - (void) unlink(socket_path); - cluster_external_fence_socket_path = - "/var/run/pgrac/pgrac-fenced.sock"; + (void)close(peer_fd); + (void)close(listen_fd); + (void)unlink(socket_path); + cluster_external_fence_socket_path = "/var/run/pgrac/pgrac-fenced.sock"; } UT_TEST(test_external_fence_rejoin_claim_receives_exact_offer) @@ -1753,14 +1583,12 @@ UT_TEST(test_external_fence_rejoin_claim_receives_exact_offer) UT_ASSERT(listen_fd >= 0); if (listen_fd < 0) return; - snprintf(socket_path, sizeof(socket_path), - "/tmp/pgrac-rejoin-%ld.sock", (long) getpid()); - (void) unlink(socket_path); + snprintf(socket_path, sizeof(socket_path), "/tmp/pgrac-rejoin-%ld.sock", (long)getpid()); + (void)unlink(socket_path); memset(&address, 0, sizeof(address)); address.sun_family = AF_UNIX; strlcpy(address.sun_path, socket_path, sizeof(address.sun_path)); - UT_ASSERT(bind(listen_fd, (struct sockaddr *) &address, - sizeof(address)) == 0); + UT_ASSERT(bind(listen_fd, (struct sockaddr *)&address, sizeof(address)) == 0); UT_ASSERT(listen(listen_fd, 1) == 0); cluster_external_fence_socket_path = socket_path; stub_root_peer_authenticated = true; @@ -1777,36 +1605,28 @@ UT_TEST(test_external_fence_rejoin_claim_receives_exact_offer) UT_ASSERT_EQ(reason, PGRAC_EXTERNAL_FENCE_DENY_NONE); io_count = read(peer_fd, frame, sizeof(frame)); UT_ASSERT_EQ(io_count, sizeof(frame)); - UT_ASSERT(pgrac_external_fence_rejoin_v1_decode( - frame, sizeof(frame), &claim)); - UT_ASSERT_EQ(claim.opcode, - PGRAC_EXTERNAL_FENCE_REJOIN_LMON_CLAIM_NEXT); + UT_ASSERT(pgrac_external_fence_rejoin_v1_decode(frame, sizeof(frame), &claim)); + UT_ASSERT_EQ(claim.opcode, PGRAC_EXTERNAL_FENCE_REJOIN_LMON_CLAIM_NEXT); memset(&response, 0, sizeof(response)); response.opcode = PGRAC_EXTERNAL_FENCE_REJOIN_LMON_OFFER; - memcpy(response.transport_nonce, claim.transport_nonce, - sizeof(response.transport_nonce)); + memcpy(response.transport_nonce, claim.transport_nonce, sizeof(response.transport_nonce)); memset(response.operation_id, 0x11, sizeof(response.operation_id)); response.system_identifier = UINT64_C(0x0123456789abcdef); - memset(response.protected_set_digest, 0x22, - sizeof(response.protected_set_digest)); + memset(response.protected_set_digest, 0x22, sizeof(response.protected_set_digest)); response.old_node_id = 1; response.old_incarnation = UINT64_C(70); response.candidate_incarnation = UINT64_C(77); response.provider_id = 1; response.provider_abi_version = 1; response.target_mapping_generation = UINT64_C(3); - memset(response.daemon_boot_id, 0x33, - sizeof(response.daemon_boot_id)); + memset(response.daemon_boot_id, 0x33, sizeof(response.daemon_boot_id)); response.journal_seq = UINT64_C(4); UT_ASSERT(clock_gettime(CLOCK_MONOTONIC, &now) == 0); - response.verified_mono_ns = (uint64) now.tv_sec * UINT64_C(1000000000) - + (uint64) now.tv_nsec; - response.fresh_until_mono_ns = response.verified_mono_ns + - UINT64_C(5000000000); + response.verified_mono_ns = (uint64)now.tv_sec * UINT64_C(1000000000) + (uint64)now.tv_nsec; + response.fresh_until_mono_ns = response.verified_mono_ns + UINT64_C(5000000000); response.proof_generation = UINT64_C(5); - memset(response.target_state_digest, 0x44, - sizeof(response.target_state_digest)); + memset(response.target_state_digest, 0x44, sizeof(response.target_state_digest)); response.status = PGRAC_EXTERNAL_FENCE_REJOIN_OFFERED; response.deny_reason = PGRAC_EXTERNAL_FENCE_DENY_NONE; UT_ASSERT(pgrac_external_fence_rejoin_v1_encode(&response, frame)); @@ -1821,8 +1641,7 @@ UT_TEST(test_external_fence_rejoin_claim_receives_exact_offer) UT_ASSERT_EQ(offer->old_node_id, 1); UT_ASSERT_EQ(offer->old_incarnation, UINT64_C(70)); UT_ASSERT_EQ(offer->candidate_incarnation, UINT64_C(77)); - UT_ASSERT(memcmp(offer->operation_id, response.operation_id, - sizeof(offer->operation_id)) == 0); + UT_ASSERT(memcmp(offer->operation_id, response.operation_id, sizeof(offer->operation_id)) == 0); memset(&failure, 0, sizeof(failure)); failure.reconfig_kind = RECONFIG_KIND_FAIL_STOP; @@ -1836,23 +1655,22 @@ UT_TEST(test_external_fence_rejoin_claim_receives_exact_offer) memset(&grd_clear, 0, sizeof(grd_clear)); grd_clear.episode_epoch = failure.new_epoch; grd_clear.dead_bitmap_hash = UINT64_C(11); - memcpy(grd_clear.survivor_bitmap, failure.survivor_bitmap, - sizeof(grd_clear.survivor_bitmap)); + memcpy(grd_clear.survivor_bitmap, failure.survivor_bitmap, sizeof(grd_clear.survivor_bitmap)); stub_rejoin_failure_current = true; stub_rejoin_grd_current = true; stub_rejoin_failure = failure; stub_rejoin_grd = grd_clear; grd_clear.survivor_bitmap[0] = UINT8_C(4); - UT_ASSERT_EQ(cluster_external_fence_rejoin_authority_clear_build( - op, &failure, &grd_clear, &authority_clear, &reason), - PGRAC_EXTERNAL_FENCE_REJOIN_PENDING); + UT_ASSERT_EQ(cluster_external_fence_rejoin_authority_clear_build(op, &failure, &grd_clear, + &authority_clear, &reason), + PGRAC_EXTERNAL_FENCE_REJOIN_PENDING); UT_ASSERT(authority_clear == NULL); UT_ASSERT_EQ(reason, PGRAC_EXTERNAL_FENCE_DENY_GRD_NOT_CLEAR); grd_clear = stub_rejoin_grd; - UT_ASSERT_EQ(cluster_external_fence_rejoin_authority_clear_build( - op, &failure, &grd_clear, &authority_clear, &reason), - PGRAC_EXTERNAL_FENCE_REJOIN_WAITING_ROOT); + UT_ASSERT_EQ(cluster_external_fence_rejoin_authority_clear_build(op, &failure, &grd_clear, + &authority_clear, &reason), + PGRAC_EXTERNAL_FENCE_REJOIN_WAITING_ROOT); UT_ASSERT(authority_clear != NULL); UT_ASSERT_EQ(reason, PGRAC_EXTERNAL_FENCE_DENY_NONE); @@ -1860,14 +1678,13 @@ UT_TEST(test_external_fence_rejoin_claim_receives_exact_offer) old_identity.origin_thread_id = 2; old_identity.origin_node_id = 1; old_identity.origin_owner_incarnation = UINT64_C(70); - cluster_wal_thread_claim_fill(&claim_record, - old_identity.origin_thread_id, old_identity.origin_node_id, - old_identity.thread_claim_created_at); + cluster_wal_thread_claim_fill(&claim_record, old_identity.origin_thread_id, + old_identity.origin_node_id, + old_identity.thread_claim_created_at); old_identity.thread_claim_crc32c = claim_record.crc; memset(&complete_snapshot, 0, sizeof(complete_snapshot)); complete_snapshot.identity = old_identity; - complete_snapshot.lifecycle = - CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_COMPLETE; + complete_snapshot.lifecycle = CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_COMPLETE; complete_snapshot.root_flags = CLUSTER_CONTROL_ROOT_FLAG_CLAIM_VALID; complete_snapshot.root_publish_seq = UINT64_C(12); memset(&complete_token, 0, sizeof(complete_token)); @@ -1875,36 +1692,31 @@ UT_TEST(test_external_fence_rejoin_claim_receives_exact_offer) sizeof(complete_token.authority_uuid)); complete_token.origin_thread_id = old_identity.origin_thread_id; complete_token.source = UINT8_C(1); - complete_token.lifecycle = - CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_COMPLETE; + complete_token.lifecycle = CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_COMPLETE; complete_token.root_lineage_seq = old_identity.root_lineage_seq; complete_token.file_txn_seq = UINT64_C(13); complete_token.root_publish_seq = complete_snapshot.root_publish_seq; complete_token.record_crc32c = UINT32_C(14); complete_token.root_flags = complete_snapshot.root_flags; authorize_status = cluster_external_fence_rejoin_authorize_on_async( - op, &authority_clear, &old_identity, &complete_snapshot, - &complete_token, response.protected_set_digest, &reason); + op, &authority_clear, &old_identity, &complete_snapshot, &complete_token, + response.protected_set_digest, &reason); UT_ASSERT_EQ(authorize_status, PGRAC_EXTERNAL_FENCE_REJOIN_PENDING); UT_ASSERT(authority_clear == NULL); UT_ASSERT_EQ(reason, PGRAC_EXTERNAL_FENCE_DENY_NONE); - if (authorize_status != PGRAC_EXTERNAL_FENCE_REJOIN_PENDING || - authority_clear != NULL) + if (authorize_status != PGRAC_EXTERNAL_FENCE_REJOIN_PENDING || authority_clear != NULL) goto cleanup; io_count = read(peer_fd, frame, sizeof(frame)); UT_ASSERT_EQ(io_count, sizeof(frame)); - UT_ASSERT(pgrac_external_fence_rejoin_v1_decode( - frame, sizeof(frame), &claim)); - UT_ASSERT_EQ(claim.opcode, - PGRAC_EXTERNAL_FENCE_REJOIN_LMON_AUTHORIZE_ON); - UT_ASSERT(memcmp(claim.operation_id, response.operation_id, - sizeof(claim.operation_id)) == 0); + UT_ASSERT(pgrac_external_fence_rejoin_v1_decode(frame, sizeof(frame), &claim)); + UT_ASSERT_EQ(claim.opcode, PGRAC_EXTERNAL_FENCE_REJOIN_LMON_AUTHORIZE_ON); + UT_ASSERT(memcmp(claim.operation_id, response.operation_id, sizeof(claim.operation_id)) == 0); UT_ASSERT_EQ(claim.system_identifier, old_identity.system_identifier); - UT_ASSERT(memcmp(claim.rejoin_gate_digest, (uint8[32]) { 0 }, - sizeof(claim.rejoin_gate_digest)) != 0); - UT_ASSERT(memcmp(claim.protected_set_digest, - response.protected_set_digest, - sizeof(claim.protected_set_digest)) == 0); + UT_ASSERT(memcmp(claim.rejoin_gate_digest, (uint8[32]){ 0 }, sizeof(claim.rejoin_gate_digest)) + != 0); + UT_ASSERT(memcmp(claim.protected_set_digest, response.protected_set_digest, + sizeof(claim.protected_set_digest)) + == 0); UT_ASSERT_EQ(claim.old_node_id, 1); UT_ASSERT_EQ(claim.old_incarnation, UINT64_C(70)); UT_ASSERT_EQ(claim.candidate_incarnation, UINT64_C(77)); @@ -1912,10 +1724,8 @@ UT_TEST(test_external_fence_rejoin_claim_receives_exact_offer) memset(&response, 0, sizeof(response)); response.opcode = PGRAC_EXTERNAL_FENCE_REJOIN_LMON_ON_RESULT; - memcpy(response.transport_nonce, claim.transport_nonce, - sizeof(response.transport_nonce)); - memcpy(response.operation_id, claim.operation_id, - sizeof(response.operation_id)); + memcpy(response.transport_nonce, claim.transport_nonce, sizeof(response.transport_nonce)); + memcpy(response.operation_id, claim.operation_id, sizeof(response.operation_id)); response.system_identifier = claim.system_identifier; memcpy(response.rejoin_gate_digest, claim.rejoin_gate_digest, sizeof(response.rejoin_gate_digest)); @@ -1927,17 +1737,13 @@ UT_TEST(test_external_fence_rejoin_claim_receives_exact_offer) response.provider_id = 1; response.provider_abi_version = 1; response.target_mapping_generation = UINT64_C(3); - memset(response.daemon_boot_id, 0x33, - sizeof(response.daemon_boot_id)); + memset(response.daemon_boot_id, 0x33, sizeof(response.daemon_boot_id)); response.journal_seq = UINT64_C(6); UT_ASSERT(clock_gettime(CLOCK_MONOTONIC, &now) == 0); - response.verified_mono_ns = (uint64) now.tv_sec * UINT64_C(1000000000) - + (uint64) now.tv_nsec; - response.fresh_until_mono_ns = response.verified_mono_ns + - UINT64_C(5000000000); + response.verified_mono_ns = (uint64)now.tv_sec * UINT64_C(1000000000) + (uint64)now.tv_nsec; + response.fresh_until_mono_ns = response.verified_mono_ns + UINT64_C(5000000000); response.proof_generation = UINT64_C(6); - memset(response.target_state_digest, 0x55, - sizeof(response.target_state_digest)); + memset(response.target_state_digest, 0x55, sizeof(response.target_state_digest)); response.status = PGRAC_EXTERNAL_FENCE_REJOIN_WAITING_JOINER; response.deny_reason = PGRAC_EXTERNAL_FENCE_DENY_NONE; UT_ASSERT(pgrac_external_fence_rejoin_v1_encode(&response, frame)); @@ -1959,32 +1765,28 @@ UT_TEST(test_external_fence_rejoin_claim_receives_exact_offer) stub_rejoin_pending = pending; stub_rejoin_pending_current = true; stub_rejoin_pending_is_ready = true; - refresh_status = cluster_external_fence_rejoin_refresh_on_async( - op, &pending, &reason); + refresh_status = cluster_external_fence_rejoin_refresh_on_async(op, &pending, &reason); UT_ASSERT_EQ(refresh_status, PGRAC_EXTERNAL_FENCE_REJOIN_PENDING); UT_ASSERT_EQ(reason, PGRAC_EXTERNAL_FENCE_DENY_NONE); if (refresh_status != PGRAC_EXTERNAL_FENCE_REJOIN_PENDING) goto cleanup; io_count = read(peer_fd, frame, sizeof(frame)); UT_ASSERT_EQ(io_count, sizeof(frame)); - UT_ASSERT(pgrac_external_fence_rejoin_v1_decode( - frame, sizeof(frame), &response)); - UT_ASSERT_EQ(response.opcode, - PGRAC_EXTERNAL_FENCE_REJOIN_LMON_REFRESH_ON); - UT_ASSERT(memcmp(response.operation_id, claim.operation_id, - sizeof(response.operation_id)) == 0); - UT_ASSERT(memcmp(response.transport_nonce, claim.transport_nonce, - sizeof(response.transport_nonce)) != 0); - UT_ASSERT(memcmp(response.rejoin_gate_digest, - claim.rejoin_gate_digest, - sizeof(response.rejoin_gate_digest)) == 0); + UT_ASSERT(pgrac_external_fence_rejoin_v1_decode(frame, sizeof(frame), &response)); + UT_ASSERT_EQ(response.opcode, PGRAC_EXTERNAL_FENCE_REJOIN_LMON_REFRESH_ON); + UT_ASSERT(memcmp(response.operation_id, claim.operation_id, sizeof(response.operation_id)) + == 0); + UT_ASSERT( + memcmp(response.transport_nonce, claim.transport_nonce, sizeof(response.transport_nonce)) + != 0); + UT_ASSERT(memcmp(response.rejoin_gate_digest, claim.rejoin_gate_digest, + sizeof(response.rejoin_gate_digest)) + == 0); claim = response; memset(&response, 0, sizeof(response)); response.opcode = PGRAC_EXTERNAL_FENCE_REJOIN_LMON_REFRESH_RESULT; - memcpy(response.transport_nonce, claim.transport_nonce, - sizeof(response.transport_nonce)); - memcpy(response.operation_id, claim.operation_id, - sizeof(response.operation_id)); + memcpy(response.transport_nonce, claim.transport_nonce, sizeof(response.transport_nonce)); + memcpy(response.operation_id, claim.operation_id, sizeof(response.operation_id)); response.system_identifier = claim.system_identifier; memcpy(response.rejoin_gate_digest, claim.rejoin_gate_digest, sizeof(response.rejoin_gate_digest)); @@ -1996,17 +1798,13 @@ UT_TEST(test_external_fence_rejoin_claim_receives_exact_offer) response.provider_id = 1; response.provider_abi_version = 1; response.target_mapping_generation = UINT64_C(3); - memset(response.daemon_boot_id, 0x33, - sizeof(response.daemon_boot_id)); + memset(response.daemon_boot_id, 0x33, sizeof(response.daemon_boot_id)); response.journal_seq = UINT64_C(7); UT_ASSERT(clock_gettime(CLOCK_MONOTONIC, &now) == 0); - response.verified_mono_ns = (uint64) now.tv_sec * UINT64_C(1000000000) - + (uint64) now.tv_nsec; - response.fresh_until_mono_ns = response.verified_mono_ns + - UINT64_C(5000000000); + response.verified_mono_ns = (uint64)now.tv_sec * UINT64_C(1000000000) + (uint64)now.tv_nsec; + response.fresh_until_mono_ns = response.verified_mono_ns + UINT64_C(5000000000); response.proof_generation = UINT64_C(7); - memset(response.target_state_digest, 0x66, - sizeof(response.target_state_digest)); + memset(response.target_state_digest, 0x66, sizeof(response.target_state_digest)); response.status = PGRAC_EXTERNAL_FENCE_REJOIN_READY; response.deny_reason = PGRAC_EXTERNAL_FENCE_DENY_NONE; UT_ASSERT(pgrac_external_fence_rejoin_v1_encode(&response, frame)); @@ -2016,19 +1814,16 @@ UT_TEST(test_external_fence_rejoin_claim_receives_exact_offer) UT_ASSERT_EQ(reason, PGRAC_EXTERNAL_FENCE_DENY_NONE); binding = cluster_external_fence_rejoin_binding(op); UT_ASSERT(binding != NULL); - if (binding != NULL) - { + if (binding != NULL) { UT_ASSERT_EQ(binding->old_node_id, 1); UT_ASSERT_EQ(binding->candidate_incarnation, UINT64_C(77)); } stub_root_revalidate_result = CLUSTER_CONTROL_ROOT_OK_PRIMARY; stub_root_revalidate_snapshot = complete_snapshot; memset(&fresh_snapshot, 0xa5, sizeof(fresh_snapshot)); - UT_ASSERT(cluster_external_fence_rejoin_revalidate_root( - op, &fresh_snapshot, &reason)); + UT_ASSERT(cluster_external_fence_rejoin_revalidate_root(op, &fresh_snapshot, &reason)); UT_ASSERT_EQ(reason, PGRAC_EXTERNAL_FENCE_DENY_NONE); - UT_ASSERT(memcmp(&fresh_snapshot, &complete_snapshot, - sizeof(fresh_snapshot)) == 0); + UT_ASSERT(memcmp(&fresh_snapshot, &complete_snapshot, sizeof(fresh_snapshot)) == 0); memset(&committed_candidate, 0, sizeof(committed_candidate)); committed_candidate.magic = CLUSTER_JCMK_MAGIC; committed_candidate.version = CLUSTER_JCMK_VERSION; @@ -2042,11 +1837,11 @@ UT_TEST(test_external_fence_rejoin_claim_receives_exact_offer) stub_membership_state = CLUSTER_MEMBER_JOINING; stub_admitted_floor = failure.old_incarnation; stub_cluster_epoch = pending.new_epoch; - UT_ASSERT(cluster_external_fence_rejoin_consume_nowait( - op, &pending, &committed_candidate, &reason)); + UT_ASSERT( + cluster_external_fence_rejoin_consume_nowait(op, &pending, &committed_candidate, &reason)); UT_ASSERT_EQ(reason, PGRAC_EXTERNAL_FENCE_DENY_NONE); - UT_ASSERT(!cluster_external_fence_rejoin_consume_nowait( - op, &pending, &committed_candidate, &reason)); + UT_ASSERT( + !cluster_external_fence_rejoin_consume_nowait(op, &pending, &committed_candidate, &reason)); UT_ASSERT_EQ(reason, PGRAC_EXTERNAL_FENCE_DENY_REJOIN_CONSUMED); cleanup: @@ -2054,11 +1849,10 @@ UT_TEST(test_external_fence_rejoin_claim_receives_exact_offer) cluster_external_fence_rejoin_release(&op); UT_ASSERT(op == NULL); if (peer_fd >= 0) - (void) close(peer_fd); - (void) close(listen_fd); - (void) unlink(socket_path); - cluster_external_fence_socket_path = - "/var/run/pgrac/pgrac-fenced.sock"; + (void)close(peer_fd); + (void)close(listen_fd); + (void)unlink(socket_path); + cluster_external_fence_socket_path = "/var/run/pgrac/pgrac-fenced.sock"; stub_root_peer_authenticated = false; } diff --git a/src/test/cluster_unit/test_cluster_formation_marker.c b/src/test/cluster_unit/test_cluster_formation_marker.c index 14202ec7806..7206ca72628 100644 --- a/src/test/cluster_unit/test_cluster_formation_marker.c +++ b/src/test/cluster_unit/test_cluster_formation_marker.c @@ -50,8 +50,7 @@ errmsg_internal(const char *fmt pg_attribute_unused(), ...) } void -errfinish(const char *filename pg_attribute_unused(), - int lineno pg_attribute_unused(), +errfinish(const char *filename pg_attribute_unused(), int lineno pg_attribute_unused(), const char *funcname pg_attribute_unused()) {} @@ -59,14 +58,14 @@ errfinish(const char *filename pg_attribute_unused(), static int failures = 0; -#define EXPECT_TRUE(cond, msg) \ - do { \ - if (!(cond)) { \ - fprintf(stderr, "FAIL: %s (%s:%d)\n", msg, __FILE__, __LINE__); \ - failures++; \ - } else { \ - printf("ok: %s\n", msg); \ - } \ +#define EXPECT_TRUE(cond, msg) \ + do { \ + if (!(cond)) { \ + fprintf(stderr, "FAIL: %s (%s:%d)\n", msg, __FILE__, __LINE__); \ + failures++; \ + } else { \ + printf("ok: %s\n", msg); \ + } \ } while (0) static void @@ -74,9 +73,9 @@ test_roundtrip(void) { ClusterFormationCommitMarker m; ClusterFormationCommitMarker out; - uint64 inc_by_node[CLUSTER_MAX_NODES]; - uint64 out_inc[CLUSTER_MAX_NODES]; - uint8 slot[CLUSTER_VOTING_SLOT_BYTES]; + uint64 inc_by_node[CLUSTER_MAX_NODES]; + uint64 out_inc[CLUSTER_MAX_NODES]; + uint8 slot[CLUSTER_VOTING_SLOT_BYTES]; memset(&m, 0, sizeof(m)); m.magic = CLUSTER_FORMATION_MARKER_MAGIC; @@ -87,7 +86,7 @@ test_roundtrip(void) m.arbiter_node = 0; m.arbiter_incarnation = 1001; m.commit_nonce = 0xdeadbeef; - m.admitted_nodes[0] = 0x03; /* members 0 and 1 */ + m.admitted_nodes[0] = 0x03; /* members 0 and 1 */ m.n_admitted = 2; cluster_formation_marker_compute_crc(&m); @@ -95,29 +94,23 @@ test_roundtrip(void) inc_by_node[0] = 1001; inc_by_node[1] = 2002; - EXPECT_TRUE(cluster_formation_marker_encode(&m, inc_by_node, slot), - "encode two-member marker"); + EXPECT_TRUE(cluster_formation_marker_encode(&m, inc_by_node, slot), "encode two-member marker"); memset(&out, 0, sizeof(out)); memset(out_inc, 0, sizeof(out_inc)); - EXPECT_TRUE(cluster_formation_marker_decode(slot, &out, out_inc), - "decode round-trip"); - EXPECT_TRUE(out.formation_generation == 1 - && out.formation_epoch == 7 - && out.arbiter_node == 0 - && out.arbiter_incarnation == 1001 - && out.commit_nonce == 0xdeadbeef - && out.n_admitted == 2, + EXPECT_TRUE(cluster_formation_marker_decode(slot, &out, out_inc), "decode round-trip"); + EXPECT_TRUE(out.formation_generation == 1 && out.formation_epoch == 7 && out.arbiter_node == 0 + && out.arbiter_incarnation == 1001 && out.commit_nonce == 0xdeadbeef + && out.n_admitted == 2, "decoded header fields match"); - EXPECT_TRUE(out_inc[0] == 1001 && out_inc[1] == 2002, - "decoded incarnation table matches"); + EXPECT_TRUE(out_inc[0] == 1001 && out_inc[1] == 2002, "decoded incarnation table matches"); } static void test_wire_crc_covers_table(void) { ClusterFormationCommitMarker m; - uint64 inc_by_node[CLUSTER_MAX_NODES]; - uint8 slot[CLUSTER_VOTING_SLOT_BYTES]; + uint64 inc_by_node[CLUSTER_MAX_NODES]; + uint8 slot[CLUSTER_VOTING_SLOT_BYTES]; memset(&m, 0, sizeof(m)); m.magic = CLUSTER_FORMATION_MARKER_MAGIC; @@ -133,15 +126,14 @@ test_wire_crc_covers_table(void) memset(inc_by_node, 0, sizeof(inc_by_node)); inc_by_node[0] = 55; inc_by_node[1] = 66; - EXPECT_TRUE(cluster_formation_marker_encode(&m, inc_by_node, slot), - "encode for tamper test"); + EXPECT_TRUE(cluster_formation_marker_encode(&m, inc_by_node, slot), "encode for tamper test"); /* Flip one byte INSIDE the compact table (entry 1's incarnation at * 72 + 9 = 81). A CRC that covers the table must reject it. */ slot[81] ^= 0xFF; { ClusterFormationCommitMarker out; - uint64 out_inc[CLUSTER_MAX_NODES]; + uint64 out_inc[CLUSTER_MAX_NODES]; EXPECT_TRUE(!cluster_formation_marker_decode(slot, &out, out_inc), "table tamper rejected by wire CRC"); @@ -152,8 +144,8 @@ static void test_capacity_clamp(void) { ClusterFormationCommitMarker m; - uint64 inc_by_node[CLUSTER_MAX_NODES]; - uint8 slot[CLUSTER_VOTING_SLOT_BYTES]; + uint64 inc_by_node[CLUSTER_MAX_NODES]; + uint8 slot[CLUSTER_VOTING_SLOT_BYTES]; memset(&m, 0, sizeof(m)); m.magic = CLUSTER_FORMATION_MARKER_MAGIC; @@ -167,7 +159,7 @@ test_capacity_clamp(void) /* member index beyond MAX_MEMBERS (48) — the 128-bit bitmap allows it * but the compact table cannot hold it: must be rejected. */ m.admitted_nodes[CLUSTER_FORMATION_MARKER_MAX_MEMBERS / 8] - = (uint8) (1u << (CLUSTER_FORMATION_MARKER_MAX_MEMBERS % 8)); + = (uint8)(1u << (CLUSTER_FORMATION_MARKER_MAX_MEMBERS % 8)); m.n_admitted = 1; memset(inc_by_node, 0, sizeof(inc_by_node)); inc_by_node[CLUSTER_FORMATION_MARKER_MAX_MEMBERS] = 9; @@ -179,8 +171,8 @@ static void test_corrupt_n_admitted_oob(void) { ClusterFormationCommitMarker m; - uint64 inc_by_node[CLUSTER_MAX_NODES]; - uint8 slot[CLUSTER_VOTING_SLOT_BYTES]; + uint64 inc_by_node[CLUSTER_MAX_NODES]; + uint8 slot[CLUSTER_VOTING_SLOT_BYTES]; memset(&m, 0, sizeof(m)); m.magic = CLUSTER_FORMATION_MARKER_MAGIC; @@ -204,7 +196,7 @@ test_corrupt_n_admitted_oob(void) slot[65] = 0xFF; { ClusterFormationCommitMarker out; - uint64 out_inc[CLUSTER_MAX_NODES]; + uint64 out_inc[CLUSTER_MAX_NODES]; EXPECT_TRUE(!cluster_formation_marker_decode(slot, &out, out_inc), "corrupt n_admitted rejected"); @@ -215,8 +207,8 @@ static void test_zero_members_rejected(void) { ClusterFormationCommitMarker m; - uint64 inc_by_node[CLUSTER_MAX_NODES]; - uint8 slot[CLUSTER_VOTING_SLOT_BYTES]; + uint64 inc_by_node[CLUSTER_MAX_NODES]; + uint8 slot[CLUSTER_VOTING_SLOT_BYTES]; memset(&m, 0, sizeof(m)); m.magic = CLUSTER_FORMATION_MARKER_MAGIC; @@ -227,7 +219,7 @@ test_zero_members_rejected(void) m.arbiter_node = 0; m.arbiter_incarnation = 1; m.commit_nonce = 3; - m.n_admitted = 0; /* no members — structural violation */ + m.n_admitted = 0; /* no members — structural violation */ memset(inc_by_node, 0, sizeof(inc_by_node)); EXPECT_TRUE(!cluster_formation_marker_encode(&m, inc_by_node, slot), "zero-member marker rejected"); diff --git a/src/test/cluster_unit/test_cluster_formation_witness.c b/src/test/cluster_unit/test_cluster_formation_witness.c index edd0253e6d4..2b604f15b66 100644 --- a/src/test/cluster_unit/test_cluster_formation_witness.c +++ b/src/test/cluster_unit/test_cluster_formation_witness.c @@ -8,7 +8,7 @@ #include "cluster/cluster_recovery_duty.h" #include "cluster/cluster_semantic_activation.h" /* ACK stage enum (G3 stub) */ -#include "storage/latch.h" /* recovery path retry stubs (MyLatch/WaitLatch) */ +#include "storage/latch.h" /* recovery path retry stubs (MyLatch/WaitLatch) */ #undef printf #undef fprintf @@ -35,11 +35,19 @@ static uint64 cache_sequence; /* Added to the product header by the GREEN; keep the RED link-exact rather * than relying on an implicit declaration. */ extern ClusterFormationWitnessResult -cluster_formation_witness_build_recovery_control_wait( - uint16 origin_thread, int timeout_ms, ClusterFormationWitnessV1 **out); +cluster_formation_witness_build_recovery_control_wait(uint16 origin_thread, int timeout_ms, + ClusterFormationWitnessV1 **out); -void *palloc(Size size) { return malloc(size); } -void pfree(void *pointer) { free(pointer); } +void * +palloc(Size size) +{ + return malloc(size); +} +void +pfree(void *pointer) +{ + free(pointer); +} void ExceptionalCondition(const char *conditionName, const char *fileName, int lineNumber) { @@ -55,7 +63,7 @@ pg_usleep(long microsec) bool cluster_reconfig_capture_formation_snapshot_v1(uint16 origin_thread, - ClusterFormationSnapshotV1 *out) + ClusterFormationSnapshotV1 *out) { (void)origin_thread; if (!snapshot_available) @@ -75,8 +83,8 @@ cluster_write_fence_read_durable_authority(ClusterFenceAuthorityProof *out) bool cluster_write_fence_authority_cache_publish_if_unchanged(const ClusterFenceMarker *marker, - uint64 published_at_us, - uint64 expected_sequence) + uint64 published_at_us, + uint64 expected_sequence) { (void)marker; (void)published_at_us; @@ -94,9 +102,10 @@ cluster_write_fence_authority_cache_sequence(void) * product object also owns the runtime owner-rejoin path; keep those unused * dependencies fail-closed without widening this unit's link boundary. */ ClusterControlRootResult -cluster_control_root_lookup_owner_by_node_runtime( - int32 old_node_id, ClusterControlRootIdentity *out_identity, - ClusterControlRootSnapshot *out_snapshot, ClusterControlRootReadToken *out_token) +cluster_control_root_lookup_owner_by_node_runtime(int32 old_node_id, + ClusterControlRootIdentity *out_identity, + ClusterControlRootSnapshot *out_snapshot, + ClusterControlRootReadToken *out_token) { (void)old_node_id; (void)out_identity; @@ -110,8 +119,7 @@ cluster_control_root_lookup_owner_by_node_runtime( * formation-witness entry points, so keep the proofs fail-closed. */ bool cluster_semantic_activation_ack_complete_matches( - uint64 transition_epoch pg_attribute_unused(), - uint64 record_generation pg_attribute_unused(), + uint64 transition_epoch pg_attribute_unused(), uint64 record_generation pg_attribute_unused(), uint64 expected_members_lo pg_attribute_unused(), uint64 expected_members_hi pg_attribute_unused(), uint64 source_feature_bitmap pg_attribute_unused(), @@ -135,10 +143,9 @@ cluster_wal_state_correctness_census_ok(void) } ClusterRecoveryOwnerImportResult -cluster_recovery_owner_import_read_v1( - int32 node_id, const ClusterWalThreadClaim *immutable_claim, - uint64 frozen_admitted_bitmap_low, uint64 frozen_admitted_bitmap_high, - uint64 *out_incarnation) +cluster_recovery_owner_import_read_v1(int32 node_id, const ClusterWalThreadClaim *immutable_claim, + uint64 frozen_admitted_bitmap_low, + uint64 frozen_admitted_bitmap_high, uint64 *out_incarnation) { (void)node_id; (void)immutable_claim; @@ -149,10 +156,11 @@ cluster_recovery_owner_import_read_v1( } ClusterControlRootResult -cluster_control_root_compare_and_publish( - const ClusterControlRootReadToken *expected_token, - const ClusterControlRootPatch *patch, ClusterControlRootPublishReason reason, - ClusterControlRootSnapshot *out_snapshot, ClusterControlRootReadToken *out_token) +cluster_control_root_compare_and_publish(const ClusterControlRootReadToken *expected_token, + const ClusterControlRootPatch *patch, + ClusterControlRootPublishReason reason, + ClusterControlRootSnapshot *out_snapshot, + ClusterControlRootReadToken *out_token) { (void)expected_token; (void)patch; @@ -231,31 +239,30 @@ GetCurrentTimestamp(void) TimestampTz TimestampTzPlusMilliseconds(TimestampTz t, int64 ms) { - return t + (TimestampTz) ms * 1000; + return t + (TimestampTz)ms * 1000; } int WaitLatch(Latch *latch, int wakeEvents, long timeout, uint32 wait_event_info) { - (void) latch; - (void) wakeEvents; - (void) timeout; - (void) wait_event_info; + (void)latch; + (void)wakeEvents; + (void)timeout; + (void)wait_event_info; return WL_TIMEOUT; } void ResetLatch(Latch *latch) { - (void) latch; + (void)latch; } volatile sig_atomic_t InterruptPending = 0; void ProcessInterrupts(void) -{ -} +{} /* recovery path: the retry rebinds the leaver's serving authority on the success * path; this fixture never reaches it. */ @@ -455,17 +462,17 @@ UT_TEST(test_recovery_control_witness_is_initial_only_and_survives_gate_open) snapshots[0].local_epoch = 1; snapshots[1] = snapshots[0]; snapshot_call = 0; - UT_ASSERT_EQ(cluster_formation_witness_build_recovery_control_wait( - 1, 1, &witness), CLUSTER_FORMATION_WITNESS_UNSTABLE); + UT_ASSERT_EQ(cluster_formation_witness_build_recovery_control_wait(1, 1, &witness), + CLUSTER_FORMATION_WITNESS_UNSTABLE); UT_ASSERT_NULL(witness); snapshots[0].local_epoch = UINT64_C(0); snapshots[1] = snapshots[0]; snapshot_call = 0; - UT_ASSERT_EQ(cluster_formation_witness_build_recovery_control_wait( - 1, 10, &witness), CLUSTER_FORMATION_WITNESS_READY); + UT_ASSERT_EQ(cluster_formation_witness_build_recovery_control_wait(1, 10, &witness), + CLUSTER_FORMATION_WITNESS_READY); UT_ASSERT_NOT_NULL(witness); - UT_ASSERT(cluster_formation_witness_copy_classification_v1( - witness, &origin_thread, &authority, &classification)); + UT_ASSERT(cluster_formation_witness_copy_classification_v1(witness, &origin_thread, &authority, + &classification)); UT_ASSERT_EQ(origin_thread, 1); /* StartupXLOG later opens the exact same formation's write gate. That one @@ -473,14 +480,14 @@ UT_TEST(test_recovery_control_witness_is_initial_only_and_survives_gate_open) snapshots[0].self_join_admitted = 1; snapshots[1].self_join_admitted = 1; snapshot_call = 0; - UT_ASSERT_EQ(cluster_formation_classification_revalidate_nowait( - origin_thread, &authority, &classification), + UT_ASSERT_EQ(cluster_formation_classification_revalidate_nowait(origin_thread, &authority, + &classification), CLUSTER_FORMATION_WITNESS_READY); snapshots[0].membership.last_admitted_incarnation[0]++; snapshots[1] = snapshots[0]; snapshot_call = 0; - UT_ASSERT_EQ(cluster_formation_classification_revalidate_nowait( - origin_thread, &authority, &classification), + UT_ASSERT_EQ(cluster_formation_classification_revalidate_nowait(origin_thread, &authority, + &classification), CLUSTER_FORMATION_WITNESS_UNSTABLE); cluster_formation_witness_destroy(&witness); } diff --git a/src/test/cluster_unit/test_cluster_gcs_block.c b/src/test/cluster_unit/test_cluster_gcs_block.c index 0416c407879..5e4d8c2ab2a 100644 --- a/src/test/cluster_unit/test_cluster_gcs_block.c +++ b/src/test/cluster_unit/test_cluster_gcs_block.c @@ -313,8 +313,10 @@ assert_ordered_in_function(const char *source, const char *function_start, const for (i = 0; i < needle_count; i++) { cursor = strstr(cursor, needles[i]); UT_ASSERT_NOT_NULL(cursor); - if (cursor == NULL) + if (cursor == NULL) { + printf("# Missing ordered source token %d in %s: %s\n", i, function_start, needles[i]); return; + } UT_ASSERT(cursor < end); if (cursor >= end) return; @@ -516,24 +518,15 @@ UT_TEST(test_pcm_x_session_auth_sample_classifies_epoch_zero_and_torn_reads) /* Before any Resource-X round or holder mutation exists, every complete * NOT_READY/TORN sample is bounded backpressure under the caller's first * R7 deadline. INVALID and OK are not retry dispositions. */ - UT_ASSERT(!cluster_gcs_pcm_x_auth_result_retryable( - PCM_X_SESSION_AUTH_INVALID)); - UT_ASSERT(!cluster_gcs_pcm_x_auth_result_retryable( - PCM_X_SESSION_AUTH_OK)); - UT_ASSERT(cluster_gcs_pcm_x_auth_result_retryable( - PCM_X_SESSION_AUTH_CONNECTION_NOT_READY)); - UT_ASSERT(cluster_gcs_pcm_x_auth_result_retryable( - PCM_X_SESSION_AUTH_SLOT_NOT_READY)); - UT_ASSERT(cluster_gcs_pcm_x_auth_result_retryable( - PCM_X_SESSION_AUTH_EPOCH_NOT_READY)); - UT_ASSERT(cluster_gcs_pcm_x_auth_result_retryable( - PCM_X_SESSION_AUTH_FRESH_NOT_READY)); - UT_ASSERT(cluster_gcs_pcm_x_auth_result_retryable( - PCM_X_SESSION_AUTH_SLOT_TORN)); - UT_ASSERT(cluster_gcs_pcm_x_auth_result_retryable( - PCM_X_SESSION_AUTH_EPOCH_TORN)); - UT_ASSERT(cluster_gcs_pcm_x_auth_result_retryable( - PCM_X_SESSION_AUTH_CONNECTION_TORN)); + UT_ASSERT(!cluster_gcs_pcm_x_auth_result_retryable(PCM_X_SESSION_AUTH_INVALID)); + UT_ASSERT(!cluster_gcs_pcm_x_auth_result_retryable(PCM_X_SESSION_AUTH_OK)); + UT_ASSERT(cluster_gcs_pcm_x_auth_result_retryable(PCM_X_SESSION_AUTH_CONNECTION_NOT_READY)); + UT_ASSERT(cluster_gcs_pcm_x_auth_result_retryable(PCM_X_SESSION_AUTH_SLOT_NOT_READY)); + UT_ASSERT(cluster_gcs_pcm_x_auth_result_retryable(PCM_X_SESSION_AUTH_EPOCH_NOT_READY)); + UT_ASSERT(cluster_gcs_pcm_x_auth_result_retryable(PCM_X_SESSION_AUTH_FRESH_NOT_READY)); + UT_ASSERT(cluster_gcs_pcm_x_auth_result_retryable(PCM_X_SESSION_AUTH_SLOT_TORN)); + UT_ASSERT(cluster_gcs_pcm_x_auth_result_retryable(PCM_X_SESSION_AUTH_EPOCH_TORN)); + UT_ASSERT(cluster_gcs_pcm_x_auth_result_retryable(PCM_X_SESSION_AUTH_CONNECTION_TORN)); } @@ -541,12 +534,11 @@ UT_TEST(test_resource_x_dispatch_recheck_failure_mask_names_each_exact_predicate { uint32 mask; - mask = cluster_gcs_resource_x_dispatch_recheck_failure_mask( - true, true, true, true, 7, 7, 7, 7); + mask = cluster_gcs_resource_x_dispatch_recheck_failure_mask(true, true, true, true, 7, 7, 7, 7); UT_ASSERT_EQ(mask, RESOURCE_X_DISPATCH_RECHECK_OK); - mask = cluster_gcs_resource_x_dispatch_recheck_failure_mask( - false, false, false, false, 7, 7, 8, 9); + mask = cluster_gcs_resource_x_dispatch_recheck_failure_mask(false, false, false, false, 7, 7, 8, + 9); UT_ASSERT((mask & RESOURCE_X_DISPATCH_RECHECK_ADMISSION) != 0); UT_ASSERT((mask & RESOURCE_X_DISPATCH_RECHECK_GATE_SESSION) != 0); UT_ASSERT((mask & RESOURCE_X_DISPATCH_RECHECK_REQUESTER_SAMPLE) != 0); @@ -554,11 +546,9 @@ UT_TEST(test_resource_x_dispatch_recheck_failure_mask_names_each_exact_predicate UT_ASSERT((mask & RESOURCE_X_DISPATCH_RECHECK_REQUESTER_GENERATION) != 0); UT_ASSERT((mask & RESOURCE_X_DISPATCH_RECHECK_MASTER_GENERATION) != 0); - mask = cluster_gcs_resource_x_dispatch_recheck_failure_mask( - true, true, true, true, 7, 7, 8, 7); + mask = cluster_gcs_resource_x_dispatch_recheck_failure_mask(true, true, true, true, 7, 7, 8, 7); UT_ASSERT_EQ(mask, RESOURCE_X_DISPATCH_RECHECK_REQUESTER_GENERATION); - mask = cluster_gcs_resource_x_dispatch_recheck_failure_mask( - true, true, true, true, 7, 7, 7, 8); + mask = cluster_gcs_resource_x_dispatch_recheck_failure_mask(true, true, true, true, 7, 7, 7, 8); UT_ASSERT_EQ(mask, RESOURCE_X_DISPATCH_RECHECK_MASTER_GENERATION); } @@ -577,19 +567,15 @@ UT_TEST(test_resource_x_type17_event_owner_identity_supports_no_pgproc_lms) UT_ASSERT_NOT_NULL(source); if (source == NULL) return; - helper = strstr(source, - "\ngcs_block_pcm_x_resource_x_source_block_to_n("); - helper_end = helper != NULL - ? strstr(helper, "\n\n/* Install the exact retained remote carrier") - : NULL; + helper = strstr(source, "\ngcs_block_pcm_x_resource_x_source_block_to_n("); + helper_end = helper != NULL ? strstr(helper, "\n\n/* Install the exact retained remote carrier") + : NULL; UT_ASSERT_NOT_NULL(helper); UT_ASSERT_NOT_NULL(helper_end); if (helper != NULL && helper_end != NULL) { - UT_ASSERT_NOT_NULL(strstr(helper, - "cluster_gcs_resource_x_event_owner_identity(")); - UT_ASSERT_NOT_NULL(strstr(helper, - "MyProc != NULL ? (int32)MyProc->pgprocno : -1,\n" - "\t\t\t\t\t(int32)getpid())")); + UT_ASSERT_NOT_NULL(strstr(helper, "cluster_gcs_resource_x_event_owner_identity(")); + UT_ASSERT_NOT_NULL(strstr(helper, "MyProc != NULL ? (int32)MyProc->pgprocno : -1, " + "(int32)getpid())")); blocking_guard = strstr(helper, "if (MyProc == NULL)"); UT_ASSERT(blocking_guard == NULL || blocking_guard >= helper_end); } @@ -721,26 +707,25 @@ UT_TEST(test_xheld_read_image_bypasses_only_exact_stable_s_barrier) before.pending_x_requester_node = -1; after = before; - UT_ASSERT(gcs_block_xheld_read_barrier_bypass_exact(&before, &after, - 2 /* requester */)); - UT_ASSERT_EQ(gcs_block_s_barrier_read_action_exact( - false, false, false, false, &before, true, &after, true, 2), - GCS_BLOCK_S_BARRIER_NONE); - UT_ASSERT_EQ(gcs_block_s_barrier_read_action_exact( - true, false, true, true, &before, true, &after, true, 2), - GCS_BLOCK_S_BARRIER_DENY); - UT_ASSERT_EQ(gcs_block_s_barrier_read_action_exact( - false, false, true, true, &before, true, &after, true, 2), - GCS_BLOCK_S_BARRIER_IMAGE_ONLY); - UT_ASSERT_EQ(gcs_block_s_barrier_read_action_exact( - false, false, true, true, &before, false, &after, true, 2), - GCS_BLOCK_S_BARRIER_DENY); + UT_ASSERT(gcs_block_xheld_read_barrier_bypass_exact(&before, &after, 2 /* requester */)); + UT_ASSERT_EQ(gcs_block_s_barrier_read_action_exact(false, false, false, false, &before, true, + &after, true, 2), + GCS_BLOCK_S_BARRIER_NONE); + UT_ASSERT_EQ(gcs_block_s_barrier_read_action_exact(true, false, true, true, &before, true, + &after, true, 2), + GCS_BLOCK_S_BARRIER_DENY); + UT_ASSERT_EQ(gcs_block_s_barrier_read_action_exact(false, false, true, true, &before, true, + &after, true, 2), + GCS_BLOCK_S_BARRIER_IMAGE_ONLY); + UT_ASSERT_EQ(gcs_block_s_barrier_read_action_exact(false, false, true, true, &before, false, + &after, true, 2), + GCS_BLOCK_S_BARRIER_DENY); after.transition_count++; UT_ASSERT(!gcs_block_xheld_read_barrier_bypass_exact(&before, &after, 2)); - UT_ASSERT_EQ(gcs_block_s_barrier_read_action_exact( - false, false, true, true, &before, true, &after, true, 2), - GCS_BLOCK_S_BARRIER_DENY); + UT_ASSERT_EQ(gcs_block_s_barrier_read_action_exact(false, false, true, true, &before, true, + &after, true, 2), + GCS_BLOCK_S_BARRIER_DENY); after = before; after.master_holder.request_id++; UT_ASSERT(!gcs_block_xheld_read_barrier_bypass_exact(&before, &after, 2)); @@ -751,10 +736,10 @@ UT_TEST(test_xheld_read_image_bypasses_only_exact_stable_s_barrier) after.s_holders_bitmap = UINT32_C(1) << 3; UT_ASSERT(!gcs_block_xheld_read_barrier_bypass_exact(&before, &after, 2)); + UT_ASSERT( + !gcs_block_xheld_read_barrier_bypass_exact(&before, &before, 1 /* requester is holder */)); UT_ASSERT(!gcs_block_xheld_read_barrier_bypass_exact(&before, &before, - 1 /* requester is holder */)); - UT_ASSERT(!gcs_block_xheld_read_barrier_bypass_exact(&before, &before, - RESOURCE_X_PROTOCOL_NODE_LIMIT)); + RESOURCE_X_PROTOCOL_NODE_LIMIT)); after = before; after.state = PCM_STATE_S; @@ -790,8 +775,8 @@ UT_TEST(test_forward_replay_requires_current_exact_authority) authority.pending_x_requester_node = -1; UT_ASSERT(gcs_block_forward_replay_authority_exact( - GCS_BLOCK_REPLY_READ_IMAGE_FROM_XHOLDER, (uint8)PCM_TRANS_N_TO_S, - 0 /* cached holder */, 2 /* requester */, &authority)); + GCS_BLOCK_REPLY_READ_IMAGE_FROM_XHOLDER, (uint8)PCM_TRANS_N_TO_S, 0 /* cached holder */, + 2 /* requester */, &authority)); /* Resource-X committed a new current X holder while this request was in * flight. Replaying the old holder marker must now fail closed. */ @@ -807,9 +792,8 @@ UT_TEST(test_forward_replay_requires_current_exact_authority) authority.master_holder.node_id = 0; authority.pending_x_requester_node = 1; authority.pending_x_since_lsn = 9; - UT_ASSERT(!gcs_block_forward_replay_authority_exact( - GCS_BLOCK_REPLY_READ_IMAGE_FROM_XHOLDER, (uint8)PCM_TRANS_N_TO_S, - 0, 2, &authority)); + UT_ASSERT(!gcs_block_forward_replay_authority_exact(GCS_BLOCK_REPLY_READ_IMAGE_FROM_XHOLDER, + (uint8)PCM_TRANS_N_TO_S, 0, 2, &authority)); /* A normal S forward remains reusable only for the exact canonical S * holder and with no newer writer barrier. */ @@ -819,13 +803,11 @@ UT_TEST(test_forward_replay_requires_current_exact_authority) authority.master_holder.node_id = 0; authority.pending_x_requester_node = -1; authority.pending_x_since_lsn = 0; - UT_ASSERT(gcs_block_forward_replay_authority_exact( - GCS_BLOCK_REPLY_GRANTED_FROM_HOLDER, (uint8)PCM_TRANS_N_TO_S, 0, 2, - &authority)); + UT_ASSERT(gcs_block_forward_replay_authority_exact(GCS_BLOCK_REPLY_GRANTED_FROM_HOLDER, + (uint8)PCM_TRANS_N_TO_S, 0, 2, &authority)); authority.master_holder.node_id = 1; - UT_ASSERT(!gcs_block_forward_replay_authority_exact( - GCS_BLOCK_REPLY_GRANTED_FROM_HOLDER, (uint8)PCM_TRANS_N_TO_S, 0, 2, - &authority)); + UT_ASSERT(!gcs_block_forward_replay_authority_exact(GCS_BLOCK_REPLY_GRANTED_FROM_HOLDER, + (uint8)PCM_TRANS_N_TO_S, 0, 2, &authority)); /* Writer transfer replay is exact to the old X holder and this requester's * pending-X episode. */ @@ -835,13 +817,11 @@ UT_TEST(test_forward_replay_requires_current_exact_authority) authority.master_holder.node_id = 0; authority.pending_x_requester_node = 2; authority.pending_x_since_lsn = 11; - UT_ASSERT(gcs_block_forward_replay_authority_exact( - GCS_BLOCK_REPLY_X_GRANTED_FROM_HOLDER, (uint8)PCM_TRANS_N_TO_X, 0, 2, - &authority)); + UT_ASSERT(gcs_block_forward_replay_authority_exact(GCS_BLOCK_REPLY_X_GRANTED_FROM_HOLDER, + (uint8)PCM_TRANS_N_TO_X, 0, 2, &authority)); authority.pending_x_requester_node = 3; - UT_ASSERT(!gcs_block_forward_replay_authority_exact( - GCS_BLOCK_REPLY_X_GRANTED_FROM_HOLDER, (uint8)PCM_TRANS_N_TO_X, 0, 2, - &authority)); + UT_ASSERT(!gcs_block_forward_replay_authority_exact(GCS_BLOCK_REPLY_X_GRANTED_FROM_HOLDER, + (uint8)PCM_TRANS_N_TO_X, 0, 2, &authority)); } @@ -1027,37 +1007,29 @@ UT_TEST(test_forwarded_holder_refusal_allows_one_master_cleanup_retry) { bool awaiting_master_cleanup = false; - UT_ASSERT(gcs_block_holder_refusal_retry_exact( - 1, &awaiting_master_cleanup, 0, 8)); + UT_ASSERT(gcs_block_holder_refusal_retry_exact(1, &awaiting_master_cleanup, 0, 8)); UT_ASSERT(awaiting_master_cleanup); - UT_ASSERT(gcs_block_holder_refusal_retry_exact( - GCS_BLOCK_REPLY_NO_FORWARDING_MASTER, - &awaiting_master_cleanup, 1, 8)); + UT_ASSERT(gcs_block_holder_refusal_retry_exact(GCS_BLOCK_REPLY_NO_FORWARDING_MASTER, + &awaiting_master_cleanup, 1, 8)); UT_ASSERT(!awaiting_master_cleanup); - UT_ASSERT(!gcs_block_holder_refusal_retry_exact( - GCS_BLOCK_REPLY_NO_FORWARDING_MASTER, - &awaiting_master_cleanup, 2, 8)); + UT_ASSERT(!gcs_block_holder_refusal_retry_exact(GCS_BLOCK_REPLY_NO_FORWARDING_MASTER, + &awaiting_master_cleanup, 2, 8)); - UT_ASSERT(!gcs_block_holder_refusal_retry_exact( - 1, &awaiting_master_cleanup, 8, 8)); + UT_ASSERT(!gcs_block_holder_refusal_retry_exact(1, &awaiting_master_cleanup, 8, 8)); UT_ASSERT(!awaiting_master_cleanup); } UT_TEST(test_forwarded_n_to_s_holder_refusal_requires_fresh_outer_retry) { UT_ASSERT(gcs_block_forwarded_s_refusal_requires_fresh_retry( - GCS_BLOCK_REPLY_DENIED_MASTER_NOT_HOLDER, - (uint8)PCM_TRANS_N_TO_S, 1)); + GCS_BLOCK_REPLY_DENIED_MASTER_NOT_HOLDER, (uint8)PCM_TRANS_N_TO_S, 1)); UT_ASSERT(!gcs_block_forwarded_s_refusal_requires_fresh_retry( - GCS_BLOCK_REPLY_DENIED_MASTER_NOT_HOLDER, - (uint8)PCM_TRANS_N_TO_S, + GCS_BLOCK_REPLY_DENIED_MASTER_NOT_HOLDER, (uint8)PCM_TRANS_N_TO_S, GCS_BLOCK_REPLY_NO_FORWARDING_MASTER)); UT_ASSERT(!gcs_block_forwarded_s_refusal_requires_fresh_retry( - GCS_BLOCK_REPLY_DENIED_MASTER_NOT_HOLDER, - (uint8)PCM_TRANS_N_TO_X, 1)); - UT_ASSERT(!gcs_block_forwarded_s_refusal_requires_fresh_retry( - GCS_BLOCK_REPLY_DENIED_PENDING_X, - (uint8)PCM_TRANS_N_TO_S, 1)); + GCS_BLOCK_REPLY_DENIED_MASTER_NOT_HOLDER, (uint8)PCM_TRANS_N_TO_X, 1)); + UT_ASSERT(!gcs_block_forwarded_s_refusal_requires_fresh_retry(GCS_BLOCK_REPLY_DENIED_PENDING_X, + (uint8)PCM_TRANS_N_TO_S, 1)); } @@ -1151,14 +1123,14 @@ UT_TEST(test_forward_payload_freshref_c1b_pair_kind10_routes_as_single_verdict) GcsBlockForwardPayload fwd; memset(&fwd, 0, sizeof(fwd)); - fwd.reserved_0[6] = (uint8) 10; + fwd.reserved_0[6] = (uint8)10; UT_ASSERT_EQ(GcsBlockForwardPayloadIsUndoVerdictRequest(&fwd) ? 1 : 0, 1); UT_ASSERT_EQ(GcsBlockForwardPayloadIsUndoVerdictAuthoritative(&fwd) ? 1 : 0, 1); UT_ASSERT_EQ(GcsBlockForwardPayloadIsUndoMultiVerdictRequest(&fwd) ? 1 : 0, 0); UT_ASSERT_EQ(GcsBlockForwardPayloadIsUndoAuthorityVerdictRequest(&fwd) ? 1 : 0, 0); UT_ASSERT_EQ(GcsBlockForwardPayloadIsUndoTtFetchRequest(&fwd) ? 1 : 0, 0); - UT_ASSERT_EQ((int) sizeof(GcsBlockForwardPayload), 64); + UT_ASSERT_EQ((int)sizeof(GcsBlockForwardPayload), 64); } @@ -1166,22 +1138,21 @@ UT_TEST(test_forward_payload_freshref_c1b_pair_kind10_routes_as_single_verdict) * {segment, raw xid, exact 1-based TT slot}. */ UT_TEST(test_freshref_c1b_pair_tag_roundtrip_and_malformed_rejection) { - BufferTag tag = GcsBlockUndoFreshRefC1bTagMake(7, (TransactionId) 4202576, 48); + BufferTag tag = GcsBlockUndoFreshRefC1bTagMake(7, (TransactionId)4202576, 48); uint32 segment = 0; uint32 slot = 0; TransactionId xid = InvalidTransactionId; UT_ASSERT(GcsBlockUndoFreshRefC1bTagDecode(tag, &segment, &xid, &slot)); UT_ASSERT_EQ(segment, 7); - UT_ASSERT_EQ(xid, (TransactionId) 4202576); + UT_ASSERT_EQ(xid, (TransactionId)4202576); UT_ASSERT_EQ(slot, 48); - tag.dbOid = (Oid) 0; + tag.dbOid = (Oid)0; UT_ASSERT(!GcsBlockUndoFreshRefC1bTagDecode(tag, NULL, NULL, NULL)); - tag = GcsBlockUndoFreshRefC1bTagMake(7, (TransactionId) 4202576, 0); + tag = GcsBlockUndoFreshRefC1bTagMake(7, (TransactionId)4202576, 0); UT_ASSERT(!GcsBlockUndoFreshRefC1bTagDecode(tag, NULL, NULL, NULL)); - tag = GcsBlockUndoFreshRefC1bTagMake(7, (TransactionId) 4202576, - TT_SLOTS_PER_SEGMENT + 1); + tag = GcsBlockUndoFreshRefC1bTagMake(7, (TransactionId)4202576, TT_SLOTS_PER_SEGMENT + 1); UT_ASSERT(!GcsBlockUndoFreshRefC1bTagDecode(tag, NULL, NULL, NULL)); tag = GcsBlockUndoFreshRefC1bTagMake(7, InvalidTransactionId, 1); UT_ASSERT(!GcsBlockUndoFreshRefC1bTagDecode(tag, NULL, NULL, NULL)); @@ -1411,8 +1382,8 @@ UT_TEST(test_local_master_read_image_pending_x_denial_rearms_at_outer_boundary) release = retry_break != NULL ? strstr(retry_break, "gcs_block_release_slot(slot)") : NULL; retry_return = release != NULL ? strstr(release, "if (*out_retry_denied)") : NULL; terminal_error = retry_return != NULL - ? strstr(retry_return, "could not obtain read image from X holder") - : NULL; + ? strstr(retry_return, "could not obtain read image from X holder") + : NULL; UT_ASSERT_NOT_NULL(pending_x); UT_ASSERT_NOT_NULL(retry_flag); @@ -1458,34 +1429,31 @@ UT_TEST(test_t400_positive_fixture_scopes_finish_flush_injection_to_exact_l2f_ta UT_ASSERT(strstr(t400, "pcm_xq_flush_error") == NULL); UT_ASSERT(strstr(t400, "wait_for_resource_x_protocol_quiescence") == NULL); UT_ASSERT(strstr(t400, "L5F") == NULL); - catalog_helper = strstr(t400, - "\nsub pcm_xq_dirty_retain_block0_tag\n"); - catalog_helper_end = catalog_helper != NULL - ? strstr(catalog_helper, "\n}\n") : NULL; - legacy_relation_size = catalog_helper != NULL - ? strstr(catalog_helper, "pg_relation_size(") : NULL; - relation_path = catalog_helper != NULL - ? strstr(catalog_helper, "pg_relation_filepath(c.oid)") : NULL; - shared_physical_path = relation_path != NULL - ? strstr(relation_path, "$shared_root/$relation_path") : NULL; + catalog_helper = strstr(t400, "\nsub pcm_xq_dirty_retain_block0_tag\n"); + catalog_helper_end = catalog_helper != NULL ? strstr(catalog_helper, "\n}\n") : NULL; + legacy_relation_size + = catalog_helper != NULL ? strstr(catalog_helper, "pg_relation_size(") : NULL; + relation_path + = catalog_helper != NULL ? strstr(catalog_helper, "pg_relation_filepath(c.oid)") : NULL; + shared_physical_path + = relation_path != NULL ? strstr(relation_path, "$shared_root/$relation_path") : NULL; UT_ASSERT_NOT_NULL(catalog_helper); UT_ASSERT_NOT_NULL(catalog_helper_end); UT_ASSERT(legacy_relation_size == NULL || catalog_helper_end == NULL || legacy_relation_size > catalog_helper_end); UT_ASSERT_NOT_NULL(relation_path); UT_ASSERT_NOT_NULL(shared_physical_path); - if (catalog_helper_end != NULL && relation_path != NULL - && shared_physical_path != NULL) + if (catalog_helper_end != NULL && relation_path != NULL && shared_physical_path != NULL) UT_ASSERT(relation_path < shared_physical_path && shared_physical_path < catalog_helper_end); reload = strstr(t400, "\nsub wait_for_lms_finish_flush_reload\n"); reload_end = reload != NULL ? strstr(reload, "\n}\n") : NULL; expected_target = reload != NULL ? strstr(reload, "$expected_target") : NULL; - target_capture = expected_target != NULL - ? strstr(expected_target, "target=\"([^\"]*)\"") : NULL; - target_match = target_capture != NULL - ? strstr(target_capture, "$target eq $expected_target") : NULL; + target_capture + = expected_target != NULL ? strstr(expected_target, "target=\"([^\"]*)\"") : NULL; + target_match + = target_capture != NULL ? strstr(target_capture, "$target eq $expected_target") : NULL; UT_ASSERT_NOT_NULL(reload); UT_ASSERT_NOT_NULL(reload_end); UT_ASSERT_NOT_NULL(expected_target); @@ -1494,19 +1462,18 @@ UT_TEST(test_t400_positive_fixture_scopes_finish_flush_injection_to_exact_l2f_ta if (reload_end != NULL && target_match != NULL) UT_ASSERT(target_match < reload_end); - catalog_tag = strstr(t400, - "COALESCE(NULLIF(c.reltablespace, 0), d.dattablespace)"); + catalog_tag = strstr(t400, "COALESCE(NULLIF(c.reltablespace, 0), d.dattablespace)"); target_guc = catalog_tag != NULL - ? strstr(catalog_tag, "cluster.pcm_x_retain_flush_error_target") : NULL; - warning_arm = target_guc != NULL - ? strstr(target_guc, - "cluster-pcm-x-retain-flush-error';") : NULL; + ? strstr(catalog_tag, "cluster.pcm_x_retain_flush_error_target") + : NULL; + warning_arm + = target_guc != NULL ? strstr(target_guc, "cluster-pcm-x-retain-flush-error';") : NULL; explicit_disarm = warning_arm != NULL - ? strstr(warning_arm, - "cluster-pcm-x-retain-flush-error:none:0") : NULL; + ? strstr(warning_arm, "cluster-pcm-x-retain-flush-error:none:0") + : NULL; target_clear = explicit_disarm != NULL - ? strstr(explicit_disarm, - "cluster.pcm_x_retain_flush_error_target = ''") : NULL; + ? strstr(explicit_disarm, "cluster.pcm_x_retain_flush_error_target = ''") + : NULL; UT_ASSERT_NOT_NULL(catalog_tag); UT_ASSERT_NOT_NULL(target_guc); UT_ASSERT_NOT_NULL(warning_arm); @@ -1549,8 +1516,7 @@ UT_TEST(test_t406_isolated_fixture_owns_exact_target_finish_flush_failure) UT_ASSERT_NOT_NULL(quad_name); UT_ASSERT_NOT_NULL(quad_name_end); if (quad_name != NULL && quad_name_end != NULL) - UT_ASSERT((size_t)(quad_name_end - quad_name) - < PGRAC_IC_CLUSTER_NAME_MAX); + UT_ASSERT((size_t)(quad_name_end - quad_name) < PGRAC_IC_CLUSTER_NAME_MAX); UT_ASSERT_NOT_NULL(strstr(t406, "quorum_voting_disks => 3")); UT_ASSERT_NOT_NULL(strstr(t406, "shared_data => 1")); UT_ASSERT_NOT_NULL(strstr(t406, "shared_system_identifier => 1")); @@ -1558,68 +1524,61 @@ UT_TEST(test_t406_isolated_fixture_owns_exact_target_finish_flush_failure) UT_ASSERT_NOT_NULL(strstr(t406, "my $quad_started = 0;")); UT_ASSERT_NOT_NULL(strstr(t406, "my $quad_stopped = 0;")); UT_ASSERT_NOT_NULL(strstr(t406, "\nEND\n")); - UT_ASSERT_NOT_NULL(strstr(t406, - "SHOW cluster.pcm_x_retain_flush_error_target")); + UT_ASSERT_NOT_NULL(strstr(t406, "SHOW cluster.pcm_x_retain_flush_error_target")); UT_ASSERT_NOT_NULL(strstr(t406, "RF_DEFERRED")); UT_ASSERT_NOT_NULL(strstr(t406, "'R4 bit0'")); UT_ASSERT_NOT_NULL(strstr(t406, "'Resource-X bit10'")); UT_ASSERT_NOT_NULL(strstr(t406, "resource_x_gate_phase")); UT_ASSERT_NOT_NULL(strstr(t406, "pcm_x_flush_decoy")); UT_ASSERT_NOT_NULL(strstr(t406, "pcm_x_flush_target")); - UT_ASSERT_NOT_NULL(strstr(t406, - "COALESCE(NULLIF(c.reltablespace, 0), d.dattablespace)")); + UT_ASSERT_NOT_NULL(strstr(t406, "COALESCE(NULLIF(c.reltablespace, 0), d.dattablespace)")); catalog_helper = strstr(t406, "\nsub exact_finish_flush_tags\n"); - catalog_helper_end = catalog_helper != NULL - ? strstr(catalog_helper, "\n}\n") : NULL; - legacy_relation_size = catalog_helper != NULL - ? strstr(catalog_helper, "pg_relation_size(") : NULL; - relation_path = catalog_helper != NULL - ? strstr(catalog_helper, "pg_relation_filepath(c.oid)") : NULL; - shared_physical_path = relation_path != NULL - ? strstr(relation_path, "$shared_root/$relation_path") : NULL; + catalog_helper_end = catalog_helper != NULL ? strstr(catalog_helper, "\n}\n") : NULL; + legacy_relation_size + = catalog_helper != NULL ? strstr(catalog_helper, "pg_relation_size(") : NULL; + relation_path + = catalog_helper != NULL ? strstr(catalog_helper, "pg_relation_filepath(c.oid)") : NULL; + shared_physical_path + = relation_path != NULL ? strstr(relation_path, "$shared_root/$relation_path") : NULL; UT_ASSERT_NOT_NULL(catalog_helper); UT_ASSERT_NOT_NULL(catalog_helper_end); UT_ASSERT(legacy_relation_size == NULL || catalog_helper_end == NULL || legacy_relation_size > catalog_helper_end); UT_ASSERT_NOT_NULL(relation_path); UT_ASSERT_NOT_NULL(shared_physical_path); - if (catalog_helper_end != NULL && relation_path != NULL - && shared_physical_path != NULL) + if (catalog_helper_end != NULL && relation_path != NULL && shared_physical_path != NULL) UT_ASSERT(relation_path < shared_physical_path && shared_physical_path < catalog_helper_end); UT_ASSERT_NOT_NULL(strstr(t406, "$decoy_tag ne $target_tag")); - UT_ASSERT_NOT_NULL(strstr(t406, - "wait_for_lms_finish_flush_reload")); + UT_ASSERT_NOT_NULL(strstr(t406, "wait_for_lms_finish_flush_reload")); UT_ASSERT(strstr(t406, "wait_for_resource_x_protocol_quiescence") == NULL); UT_ASSERT(strstr(t406, "source=0 requester=1") == NULL); UT_ASSERT_NOT_NULL(strstr(t406, "source=[0-3] requester=1")); - UT_ASSERT_NOT_NULL(strstr(t406, - "while (time() < $decoy_deadline)")); - UT_ASSERT_NOT_NULL(strstr(t406, - "while (time() < $target_deadline)")); + UT_ASSERT_NOT_NULL(strstr(t406, "while (time() < $decoy_deadline)")); + UT_ASSERT_NOT_NULL(strstr(t406, "while (time() < $target_deadline)")); UT_ASSERT(strstr(t406, "\ndo\n{") == NULL); - target_config = strstr(t406, - "ALTER SYSTEM SET cluster.pcm_x_retain_flush_error_target"); + target_config = strstr(t406, "ALTER SYSTEM SET cluster.pcm_x_retain_flush_error_target"); fault_arm = target_config != NULL - ? strstr(target_config, - "cluster-pcm-x-retain-flush-error:skipn:1") : NULL; - decoy_update = fault_arm != NULL - ? strstr(fault_arm, "UPDATE pcm_x_flush_decoy SET v = 1") : NULL; + ? strstr(target_config, "cluster-pcm-x-retain-flush-error:skipn:1") + : NULL; + decoy_update + = fault_arm != NULL ? strstr(fault_arm, "UPDATE pcm_x_flush_decoy SET v = 1") : NULL; decoy_insert = decoy_update != NULL - ? strstr(decoy_update, - "INSERT INTO pcm_x_flush_decoy(id, v) VALUES (2, 1)") : NULL; - target_update = decoy_insert != NULL - ? strstr(decoy_insert, "UPDATE pcm_x_flush_target SET v = 1") : NULL; - target_insert = target_update != NULL - ? strstr(target_update, - "INSERT INTO pcm_x_flush_target(id, v) VALUES (2, 1)") : NULL; + ? strstr(decoy_update, "INSERT INTO pcm_x_flush_decoy(id, v) VALUES (2, 1)") + : NULL; + target_update + = decoy_insert != NULL ? strstr(decoy_insert, "UPDATE pcm_x_flush_target SET v = 1") : NULL; + target_insert + = target_update != NULL + ? strstr(target_update, "INSERT INTO pcm_x_flush_target(id, v) VALUES (2, 1)") + : NULL; explicit_disarm = target_insert != NULL - ? strstr(target_insert, - "cluster-pcm-x-retain-flush-error:none:0") : NULL; + ? strstr(target_insert, "cluster-pcm-x-retain-flush-error:none:0") + : NULL; target_clear = explicit_disarm != NULL - ? strstr(explicit_disarm, - "cluster.pcm_x_retain_flush_error_target = ''") : NULL; + ? strstr(explicit_disarm, "cluster.pcm_x_retain_flush_error_target = ''") + : NULL; stop = target_clear != NULL ? strstr(target_clear, "$quad->stop_quad") : NULL; UT_ASSERT_NOT_NULL(target_config); UT_ASSERT_NOT_NULL(fault_arm); @@ -1632,26 +1591,21 @@ UT_TEST(test_t406_isolated_fixture_owns_exact_target_finish_flush_failure) UT_ASSERT_NOT_NULL(stop); if (target_config != NULL && fault_arm != NULL) UT_ASSERT(target_config < fault_arm); - if (decoy_update != NULL && decoy_insert != NULL && - target_update != NULL && target_insert != NULL) - UT_ASSERT(decoy_update < decoy_insert && decoy_insert < target_update && - target_update < target_insert); + if (decoy_update != NULL && decoy_insert != NULL && target_update != NULL + && target_insert != NULL) + UT_ASSERT(decoy_update < decoy_insert && decoy_insert < target_update + && target_update < target_insert); if (explicit_disarm != NULL && target_clear != NULL && stop != NULL) UT_ASSERT(explicit_disarm < target_clear && target_clear < stop); - UT_ASSERT_NOT_NULL(strstr(t406, - "cluster PCM-X retained-image finish fault skipped non-target")); - UT_ASSERT_NOT_NULL(strstr(t406, - "injected PCM-X retained-image FlushBuffer failure")); - UT_ASSERT_NOT_NULL(strstr(t406, - "Resource-X source settlement ACK diagnostic")); + UT_ASSERT_NOT_NULL( + strstr(t406, "cluster PCM-X retained-image finish fault skipped non-target")); + UT_ASSERT_NOT_NULL(strstr(t406, "injected PCM-X retained-image FlushBuffer failure")); + UT_ASSERT_NOT_NULL(strstr(t406, "Resource-X source settlement ACK diagnostic")); UT_ASSERT_NOT_NULL(strstr(t406, "$target_assertion_sequence")); - UT_ASSERT_NOT_NULL(strstr(t406, - "attempt=\\Q$target_assertion_sequence\\E")); - UT_ASSERT(strstr(t406, - "qr/Resource-X source settlement ACK diagnostic/,") == NULL); - UT_ASSERT_NOT_NULL(strstr(t406, - "cluster PCM-X runtime fail-closed (recovery blocked)")); + UT_ASSERT_NOT_NULL(strstr(t406, "attempt=\\Q$target_assertion_sequence\\E")); + UT_ASSERT(strstr(t406, "qr/Resource-X source settlement ACK diagnostic/,") == NULL); + UT_ASSERT_NOT_NULL(strstr(t406, "cluster PCM-X runtime fail-closed (recovery blocked)")); UT_ASSERT_NOT_NULL(strstr(t406, "lost track of buffer IO")); free(t406); } @@ -1790,7 +1744,7 @@ UT_TEST(test_local_master_x_transfer_revalidates_exact_authority_and_retries_sta UT_TEST(test_remote_downgrade_prepares_exact_image_before_notify_and_reply) { char *gcs_source = read_gcs_block_source(); - char *bufmgr_source = read_source_path("../../backend/storage/buffer/bufmgr.c"); + char *bufmgr_source = read_source_path(BUFMGR_SOURCE_PATH); const char *forward = gcs_source != NULL ? strstr(gcs_source, "\ncluster_gcs_handle_block_forward_envelope(") : NULL; @@ -1825,14 +1779,16 @@ UT_TEST(test_remote_downgrade_prepares_exact_image_before_notify_and_reply) const char *commit = notify != NULL ? strstr(notify, "cluster_bufmgr_pcm_own_finish_x_to_s_downgrade(") : NULL; const char *cover_close - = commit != NULL ? strstr(commit, - "cluster_pcm_lock_resource_x_bootstrap_round_note_x_to_s_exact(") : NULL; + = commit != NULL + ? strstr(commit, "cluster_pcm_lock_resource_x_bootstrap_round_note_x_to_s_exact(") + : NULL; const char *cover_close_after_unlock - = commit != NULL ? strstr(commit, - "LWLockRelease(content_lock);\n\tcover_result\n\t\t= cluster_pcm_lock_resource_x_bootstrap_round_note_x_to_s_exact(") : NULL; + = commit != NULL + ? strstr(commit, "LWLockRelease(content_lock);\n\tcover_result\n\t\t= " + "cluster_pcm_lock_resource_x_bootstrap_round_note_x_to_s_exact(") + : NULL; const char *unpin_after_cover - = cover_close != NULL ? strstr(cover_close, - "cluster_bufmgr_unpin_for_gcs(buf);") : NULL; + = cover_close != NULL ? strstr(cover_close, "cluster_bufmgr_unpin_for_gcs(buf);") : NULL; const char *abort = helper != NULL ? strstr(helper, "cluster_bufmgr_pcm_own_abort_x_revoke(") : NULL; const char *local_helper @@ -1851,14 +1807,20 @@ UT_TEST(test_remote_downgrade_prepares_exact_image_before_notify_and_reply) ? strstr(local_master, "cluster_bufmgr_pcm_own_finish_x_to_s_downgrade(") : NULL; const char *local_cover_close - = local_commit != NULL ? strstr(local_commit, - "cluster_pcm_lock_resource_x_bootstrap_round_note_x_to_s_exact(") : NULL; + = local_commit != NULL + ? strstr(local_commit, + "cluster_pcm_lock_resource_x_bootstrap_round_note_x_to_s_exact(") + : NULL; const char *local_cover_close_after_unlock - = local_commit != NULL ? strstr(local_commit, - "LWLockRelease(content_lock);\n\tcover_result\n\t\t= cluster_pcm_lock_resource_x_bootstrap_round_note_x_to_s_exact(") : NULL; + = local_commit != NULL + ? strstr(local_commit, + "LWLockRelease(content_lock);\n\tcover_result\n\t\t= " + "cluster_pcm_lock_resource_x_bootstrap_round_note_x_to_s_exact(") + : NULL; const char *local_unpin_after_cover - = local_cover_close != NULL ? strstr(local_cover_close, - "cluster_bufmgr_unpin_for_gcs(buf);") : NULL; + = local_cover_close != NULL + ? strstr(local_cover_close, "cluster_bufmgr_unpin_for_gcs(buf);") + : NULL; const char *local_call = gcs_source != NULL ? strstr(gcs_source, "cluster_bufmgr_downgrade_x_to_s_for_gcs_prepare_image(") @@ -1907,12 +1869,11 @@ UT_TEST(test_remote_downgrade_prepares_exact_image_before_notify_and_reply) UT_ASSERT_NOT_NULL(cover_close_after_unlock); UT_ASSERT_NOT_NULL(unpin_after_cover); UT_ASSERT_NOT_NULL(abort); - if (helper_end != NULL && reserve != NULL && precopy != NULL && notify != NULL - && commit != NULL && cover_close != NULL && cover_close_after_unlock != NULL - && unpin_after_cover != NULL) + if (helper_end != NULL && reserve != NULL && precopy != NULL && notify != NULL && commit != NULL + && cover_close != NULL && cover_close_after_unlock != NULL && unpin_after_cover != NULL) UT_ASSERT(reserve < precopy && precopy < notify && notify < commit - && commit < cover_close_after_unlock && cover_close_after_unlock <= cover_close - && cover_close < unpin_after_cover && unpin_after_cover < helper_end); + && commit < cover_close_after_unlock && cover_close_after_unlock <= cover_close + && cover_close < unpin_after_cover && unpin_after_cover < helper_end); if (helper_end != NULL && abort != NULL) UT_ASSERT(abort < notify && abort < helper_end); UT_ASSERT_NOT_NULL(local_helper); @@ -1925,12 +1886,10 @@ UT_TEST(test_remote_downgrade_prepares_exact_image_before_notify_and_reply) UT_ASSERT_NOT_NULL(local_cover_close_after_unlock); UT_ASSERT_NOT_NULL(local_unpin_after_cover); if (local_helper_end != NULL && local_reserve != NULL && local_copy != NULL - && local_master != NULL && local_commit != NULL - && local_cover_close != NULL && local_cover_close_after_unlock != NULL - && local_unpin_after_cover != NULL) + && local_master != NULL && local_commit != NULL && local_cover_close != NULL + && local_cover_close_after_unlock != NULL && local_unpin_after_cover != NULL) UT_ASSERT(local_reserve < local_copy && local_copy < local_master - && local_master < local_commit - && local_commit < local_cover_close_after_unlock + && local_master < local_commit && local_commit < local_cover_close_after_unlock && local_cover_close_after_unlock <= local_cover_close && local_cover_close < local_unpin_after_cover && local_unpin_after_cover < local_helper_end); @@ -1955,10 +1914,9 @@ UT_TEST(test_preprepared_image_accepts_exact_zero_lsn_and_rejects_mismatch) const char *prepared = produce != NULL ? strstr(produce, "if (!preprepared_image)") : NULL; const char *nonzero_assert = prepared != NULL ? strstr(prepared, "*out_page_lsn != InvalidXLogRecPtr") : NULL; - const char *lsn_match - = prepared != NULL - ? strstr(prepared, "PageGetLSN((Page)block_buf) != *out_page_lsn") - : NULL; + const char *lsn_match = prepared != NULL + ? strstr(prepared, "PageGetLSN((Page)block_buf) != *out_page_lsn") + : NULL; const char *payload_match = prepared != NULL ? strstr(prepared, "*out_block_payload != block_buf") : NULL; const char *fail_closed @@ -2172,14 +2130,12 @@ UT_TEST(test_master_direct_copy_busy_uses_only_fresh_identity_retry_boundary) UT_TEST(test_holder_forward_copy_busy_uses_same_fresh_identity_retry_boundary) { char *source = read_gcs_block_source(); - const char *forward_refusal - = source != NULL ? strstr(source, "/* HC105 evict race */") : NULL; + const char *forward_refusal = source != NULL ? strstr(source, "/* HC105 evict race */") : NULL; const char *forward_refusal_end = forward_refusal != NULL ? strstr(forward_refusal, "send_sf_dep =") : NULL; const char *mapping = forward_refusal != NULL - ? strstr(forward_refusal, - "GcsBlockMasterDirectCopyRefusalStatus(copy_refusal)") + ? strstr(forward_refusal, "GcsBlockMasterDirectCopyRefusalStatus(copy_refusal)") : NULL; const char *terminal_literal = forward_refusal != NULL @@ -2227,13 +2183,11 @@ UT_TEST(test_master_not_holder_producers_log_one_coherent_authority_snapshot) "authority.transition_count", }; static const char *const required_reasons[] = { - "direct-land-nonsendable", "direct-land-forward-rearm", - "produce-no-resident-authority", - "produce-copy-refused", "clean-third-party-master", - "live-x-other-holder", "pending-x-reserve-failed", - "x-forward-send-failed", "x-state-holder-unroutable", - "holder-immediate-deny", "holder-drop-pinned", - "holder-drop-stale", "holder-copy-refused", + "direct-land-nonsendable", "direct-land-forward-rearm", "produce-no-resident-authority", + "produce-copy-refused", "clean-third-party-master", "live-x-other-holder", + "pending-x-reserve-failed", "x-forward-send-failed", "x-state-holder-unroutable", + "holder-immediate-deny", "holder-drop-pinned", "holder-drop-stale", + "holder-copy-refused", }; size_t i; @@ -2397,11 +2351,10 @@ UT_TEST(test_resource_x_target_executor_orders_t1_t2_t3_before_writable_return) "cluster_pcm_lock_resource_x_executor_leave(" }; char *source = read_gcs_block_source(); - assert_ordered_in_function( - source, "\ngcs_block_pcm_x_resource_x_join_terminal_try(", - "\nstatic ResourceXApplyResult\n" - "gcs_block_pcm_x_resource_x_master_durable_try(", - executor_contract, lengthof(executor_contract)); + assert_ordered_in_function(source, "\ngcs_block_pcm_x_resource_x_join_terminal_try(", + "\nstatic ResourceXApplyResult\n" + "gcs_block_pcm_x_resource_x_master_durable_try(", + executor_contract, lengthof(executor_contract)); free(source); } @@ -2410,12 +2363,9 @@ UT_TEST(test_resource_x_writer_completion_does_not_own_acquisition_retirement) char *source = read_gcs_block_source(); UT_ASSERT_NOT_NULL(source); - UT_ASSERT(strstr(source, - "cluster_pcm_lock_resource_x_executor_release_capture_exact") == NULL); - UT_ASSERT(strstr(source, - "cluster_pcm_lock_resource_x_executor_release_exact") == NULL); - UT_ASSERT(strstr(source, - "gcs_block_pcm_x_resource_x_writer_complete_release_exact") == NULL); + UT_ASSERT(strstr(source, "cluster_pcm_lock_resource_x_executor_release_capture_exact") == NULL); + UT_ASSERT(strstr(source, "cluster_pcm_lock_resource_x_executor_release_exact") == NULL); + UT_ASSERT(strstr(source, "gcs_block_pcm_x_resource_x_writer_complete_release_exact") == NULL); free(source); } @@ -2446,7 +2396,8 @@ UT_TEST(test_resource_x_epoch_hook_freezes_sweeps_and_thaws_before_existing_wake "cluster_resource_x_reconfig_freeze_pending_exact(", "token.new_formation == 0", "gcs_block_resource_x_fail_closed_current()", - "cluster_resource_x_reconfig_sweep(", "CHECK_FOR_INTERRUPTS()", + "cluster_resource_x_reconfig_sweep(", + "CHECK_FOR_INTERRUPTS()", "cluster_resource_x_reconfig_zero_proof_exact(", "cluster_pcm_lock_resource_x_clean_completion_prove_exact(", "cluster_pcm_lock_resource_x_cutover_proofs_exact(", @@ -2462,32 +2413,33 @@ UT_TEST(test_resource_x_epoch_hook_freezes_sweeps_and_thaws_before_existing_wake assert_ordered_in_function( source, "\ngcs_block_resource_x_reconfig_epoch(", - "\n\n/* ============================================================\n * PGRAC: spec-2.34 D4", + "\n\n/* ============================================================\n * PGRAC: spec-2.34 " + "D4", actor_contract, lengthof(actor_contract)); assert_ordered_in_function( source, "\ncluster_gcs_block_on_epoch_advance_exact(", - "\n\n/* ============================================================\n * PGRAC MODIFICATIONS by SqlRush — spec-5.13 D5", + "\n\n/* ============================================================\n * PGRAC " + "MODIFICATIONS by SqlRush — spec-5.13 D5", hook_contract, lengthof(hook_contract)); free(source); } UT_TEST(test_resource_x_r11_cutover_tick_is_native_bounded_and_lmon_owned) { - static const char *const cutover_contract[] = { - "cluster_semantic_activation_r11_cutover_snapshot(", - "cluster_pcm_lock_resource_x_gate_snapshot(", - "cluster_resource_x_reconfig_cutover_begin_native_exact(", - "cluster_resource_x_reconfig_sweep(", - "cluster_resource_x_reconfig_cutover_bind_native_successor_exact(", - "cluster_resource_x_reconfig_sweep(", - "cluster_resource_x_reconfig_zero_proof_exact(", - "cluster_pcm_lock_resource_x_clean_completion_prove_exact(", - "cluster_pcm_lock_resource_x_cutover_proofs_exact(", - "cluster_resource_x_reconfig_thaw_exact(", - "cluster_pcm_lock_resource_x_cutover_thawed_proofs_exact(" - }; + static const char *const cutover_contract[] + = { "cluster_semantic_activation_r11_cutover_snapshot(", + "cluster_pcm_lock_resource_x_gate_snapshot(", + "cluster_resource_x_reconfig_cutover_begin_native_exact(", + "cluster_resource_x_reconfig_sweep(", + "cluster_resource_x_reconfig_cutover_bind_native_successor_exact(", + "cluster_resource_x_reconfig_sweep(", + "cluster_resource_x_reconfig_zero_proof_exact(", + "cluster_pcm_lock_resource_x_clean_completion_prove_exact(", + "cluster_pcm_lock_resource_x_cutover_proofs_exact(", + "cluster_resource_x_reconfig_thaw_exact(", + "cluster_pcm_lock_resource_x_cutover_thawed_proofs_exact(" }; char *source = read_gcs_block_source(); - char *lmon = read_source_path("../../../src/backend/cluster/cluster_lmon.c"); + char *lmon = read_source_path(LMON_SOURCE_PATH); const char *first_semantic; const char *cutover_start; const char *cutover_end; @@ -2504,53 +2456,55 @@ UT_TEST(test_resource_x_r11_cutover_tick_is_native_bounded_and_lmon_owned) assert_ordered_in_function( source, "\ncluster_gcs_block_resource_x_cutover_tick(", - "\n\n/* ============================================================", - cutover_contract, lengthof(cutover_contract)); - cutover_start = strstr(source, - "\ncluster_gcs_block_resource_x_cutover_tick("); - cutover_end = cutover_start != NULL - ? strstr(cutover_start, - "\n\n/* ============================================================") : NULL; - forbidden_bind = cutover_start != NULL - ? strstr(cutover_start, - "cluster_pcm_lock_resource_x_gate_bind_formation_exact(") : NULL; - forbidden_external_successor = cutover_start != NULL - ? strstr(cutover_start, - "cluster_resource_x_reconfig_bind_new_formation_exact(") : NULL; + "\n\n/* ============================================================", cutover_contract, + lengthof(cutover_contract)); + cutover_start = strstr(source, "\ncluster_gcs_block_resource_x_cutover_tick("); + cutover_end + = cutover_start != NULL + ? strstr(cutover_start, + "\n\n/* ============================================================") + : NULL; + forbidden_bind + = cutover_start != NULL + ? strstr(cutover_start, "cluster_pcm_lock_resource_x_gate_bind_formation_exact(") + : NULL; + forbidden_external_successor + = cutover_start != NULL + ? strstr(cutover_start, "cluster_resource_x_reconfig_bind_new_formation_exact(") + : NULL; forbidden_r4_arithmetic = cutover_start != NULL - ? strstr(cutover_start, - "cutover.resource_x_old_formation + 1") : NULL; + ? strstr(cutover_start, "cutover.resource_x_old_formation + 1") + : NULL; UT_ASSERT_NOT_NULL(cutover_start); UT_ASSERT_NOT_NULL(cutover_end); UT_ASSERT(forbidden_bind == NULL || forbidden_bind >= cutover_end); - UT_ASSERT(forbidden_external_successor == NULL - || forbidden_external_successor >= cutover_end); - UT_ASSERT(forbidden_r4_arithmetic == NULL - || forbidden_r4_arithmetic >= cutover_end); + UT_ASSERT(forbidden_external_successor == NULL || forbidden_external_successor >= cutover_end); + UT_ASSERT(forbidden_r4_arithmetic == NULL || forbidden_r4_arithmetic >= cutover_end); UT_ASSERT_NULL(strstr(source, "cluster_gcs_block_pcm_x_formation_tick")); UT_ASSERT_NULL(strstr(source, "cluster_pcm_x_runtime_snapshot")); - UT_ASSERT_NOT_NULL(strstr(source, - "return result == RESOURCE_X_RECONFIG_MORE\n" - "\t\t\t\t&& batch.examined_count != 0;")); + UT_ASSERT_NOT_NULL(strstr(source, "return result == RESOURCE_X_RECONFIG_MORE " + "&& batch.examined_count != 0;")); first_semantic = strstr(lmon, "cluster_semantic_activation_lmon_tick();"); first_recovery = first_semantic != NULL - ? strstr(first_semantic, "cluster_grd_recovery_lmon_tick();") : NULL; + ? strstr(first_semantic, "cluster_grd_recovery_lmon_tick();") + : NULL; first_cutover = first_recovery != NULL - ? strstr(first_recovery, - "if (cluster_gcs_block_resource_x_cutover_tick())") : NULL; - first_reschedule = first_cutover != NULL - ? strstr(first_cutover, "SetLatch(MyLatch);") : NULL; + ? strstr(first_recovery, "if (cluster_gcs_block_resource_x_cutover_tick())") + : NULL; + first_reschedule = first_cutover != NULL ? strstr(first_cutover, "SetLatch(MyLatch);") : NULL; second_semantic = first_reschedule != NULL - ? strstr(first_reschedule + 1, - "cluster_semantic_activation_lmon_tick();") : NULL; + ? strstr(first_reschedule + 1, "cluster_semantic_activation_lmon_tick();") + : NULL; second_recovery = second_semantic != NULL - ? strstr(second_semantic, "cluster_grd_recovery_lmon_tick();") : NULL; - second_cutover = second_recovery != NULL - ? strstr(second_recovery, - "if (cluster_gcs_block_resource_x_cutover_tick())") : NULL; - second_reschedule = second_cutover != NULL - ? strstr(second_cutover, "SetLatch(MyLatch);") : NULL; + ? strstr(second_semantic, "cluster_grd_recovery_lmon_tick();") + : NULL; + second_cutover + = second_recovery != NULL + ? strstr(second_recovery, "if (cluster_gcs_block_resource_x_cutover_tick())") + : NULL; + second_reschedule + = second_cutover != NULL ? strstr(second_cutover, "SetLatch(MyLatch);") : NULL; UT_ASSERT_NOT_NULL(first_semantic); UT_ASSERT_NOT_NULL(first_recovery); UT_ASSERT_NOT_NULL(first_cutover); @@ -2565,20 +2519,17 @@ UT_TEST(test_resource_x_r11_cutover_tick_is_native_bounded_and_lmon_owned) UT_TEST(test_resource_x_reused_type_ingress_precedes_every_legacy_path) { - static const char *const handler_names[] = { - "\ncluster_gcs_handle_block_request_envelope(", - "\ncluster_gcs_handle_block_reply_envelope(", - "\ncluster_gcs_handle_block_done_envelope(", - "\ncluster_gcs_handle_block_invalidate_envelope(", - "\ncluster_gcs_handle_block_invalidate_ack_envelope(" - }; - static const char *const legacy_boundaries[] = { - "gcs_block_try_r4_request80(env, payload)", - "gcs_block_try_land_current_mx_reply(env, payload)", - "sizeof(GcsBlockDonePayload)", - "CLUSTER_INJECTION_POINT(\"cluster-gcs-block-invalidate-stall-ack\")", - "if (ClusterGcsBlock == NULL)" - }; + static const char *const handler_names[] + = { "\ncluster_gcs_handle_block_request_envelope(", + "\ncluster_gcs_handle_block_reply_envelope(", + "\ncluster_gcs_handle_block_done_envelope(", + "\ncluster_gcs_handle_block_invalidate_envelope(", + "\ncluster_gcs_handle_block_invalidate_ack_envelope(" }; + static const char *const legacy_boundaries[] + = { "gcs_block_try_r4_request80(env, payload)", + "gcs_block_try_land_current_mx_reply(env, payload)", "sizeof(GcsBlockDonePayload)", + "CLUSTER_INJECTION_POINT(\"cluster-gcs-block-invalidate-stall-ack\")", + "if (ClusterGcsBlock == NULL)" }; char *source = read_gcs_block_source(); const char *helper; int i; @@ -2591,28 +2542,20 @@ UT_TEST(test_resource_x_reused_type_ingress_precedes_every_legacy_path) if (helper != NULL) { UT_ASSERT_NOT_NULL(strstr(helper, "gcs_block_resource_x_payload_candidate(")); UT_ASSERT_NOT_NULL(strstr(helper, "cluster_resource_x_wire_decode(")); - UT_ASSERT_NOT_NULL(strstr(helper, - "PGRAC_IC_HELLO_CAP_GCS_RESOURCE_X_CONVERT_V1")); + UT_ASSERT_NOT_NULL(strstr(helper, "PGRAC_IC_HELLO_CAP_GCS_RESOURCE_X_CONVERT_V1")); UT_ASSERT_NOT_NULL(strstr(helper, "cluster_sf_peer_capability_word_sample(")); - UT_ASSERT_NOT_NULL(strstr(helper, - "authenticated_capability_generation = connection_generation")); - UT_ASSERT_NULL(strstr(helper, - "frame.common.sender_connection_generation != connection_generation")); - UT_ASSERT_NOT_NULL(strstr(helper, - "gcs_block_resource_x_bootstrapped_assert_ingress(")); - UT_ASSERT_NOT_NULL(strstr(helper, - "cluster_pcm_lock_resource_x_local_proof_exact(")); - UT_ASSERT_NOT_NULL(strstr(helper, - "gcs_block_resource_x_type17_ingress(")); - UT_ASSERT_NOT_NULL(strstr(helper, - "cluster_pcm_lock_resource_x_blocked_to_n_exact(")); - UT_ASSERT_NOT_NULL(strstr(helper, - "cluster_pcm_lock_resource_x_install_settlement_exact(")); - UT_ASSERT_NOT_NULL(strstr(helper, - "cluster_pcm_lock_resource_x_release_x_exact(")); + UT_ASSERT_NOT_NULL( + strstr(helper, "authenticated_capability_generation = connection_generation")); + UT_ASSERT_NULL( + strstr(helper, "frame.common.sender_connection_generation != connection_generation")); + UT_ASSERT_NOT_NULL(strstr(helper, "gcs_block_resource_x_bootstrapped_assert_ingress(")); + UT_ASSERT_NOT_NULL(strstr(helper, "cluster_pcm_lock_resource_x_local_proof_exact(")); + UT_ASSERT_NOT_NULL(strstr(helper, "gcs_block_resource_x_type17_ingress(")); + UT_ASSERT_NOT_NULL(strstr(helper, "cluster_pcm_lock_resource_x_blocked_to_n_exact(")); + UT_ASSERT_NOT_NULL(strstr(helper, "cluster_pcm_lock_resource_x_install_settlement_exact(")); + UT_ASSERT_NOT_NULL(strstr(helper, "cluster_pcm_lock_resource_x_release_x_exact(")); } - UT_ASSERT_NOT_NULL(strstr(source, - "cluster_pcm_lock_resource_x_assert_bootstrapped_exact(")); + UT_ASSERT_NOT_NULL(strstr(source, "cluster_pcm_lock_resource_x_assert_bootstrapped_exact(")); for (i = 0; i < (int)lengthof(handler_names); i++) { const char *handler = strstr(source, handler_names[i]); const char *intercept; @@ -2633,16 +2576,15 @@ UT_TEST(test_resource_x_reused_type_ingress_precedes_every_legacy_path) UT_TEST(test_retired_pcm_x_ingress_drops_only_authenticated_current_target_peer) { - static const char *const stale_contract[] = { - "cluster_semantic_activation_enter(", - "admission_result != CLUSTER_SEMANTIC_ADMISSION_OK", - "gcs_block_legacy_pcm_x_fail_closed(source_node)", - "cluster_sf_peer_capability_word_sample(", - "gcs_block_resource_x_target_peer_matches_exact(", - "cluster_semantic_activation_recheck(&admission)", - "cluster_semantic_activation_leave(&admission)", - "gcs_block_legacy_pcm_x_fail_closed(source_node)" - }; + static const char *const stale_contract[] + = { "cluster_semantic_activation_enter(", + "admission_result != CLUSTER_SEMANTIC_ADMISSION_OK", + "gcs_block_legacy_pcm_x_fail_closed(source_node)", + "cluster_sf_peer_capability_word_sample(", + "gcs_block_resource_x_target_peer_matches_exact(", + "cluster_semantic_activation_recheck(&admission)", + "cluster_semantic_activation_leave(&admission)", + "gcs_block_legacy_pcm_x_fail_closed(source_node)" }; char *source = read_gcs_block_source(); const char *helper; @@ -2652,31 +2594,29 @@ UT_TEST(test_retired_pcm_x_ingress_drops_only_authenticated_current_target_peer) helper = strstr(source, "\ngcs_block_legacy_pcm_x_stale_ingress("); UT_ASSERT_NOT_NULL(helper); if (helper != NULL) { - assert_ordered_in_function( - source, "\ngcs_block_legacy_pcm_x_stale_ingress(", - "\n\n#define LEGACY_PCM_X_STALE_INFO", stale_contract, - lengthof(stale_contract)); - UT_ASSERT_NOT_NULL(strstr(helper, - "if (!peer_sampled || !peer_exact || !admission_current)")); + assert_ordered_in_function(source, "\ngcs_block_legacy_pcm_x_stale_ingress(", + "\n\n#define LEGACY_PCM_X_STALE_INFO", stale_contract, + lengthof(stale_contract)); + UT_ASSERT_NOT_NULL( + strstr(helper, "if (!peer_sampled || !peer_exact || !admission_current)")); } free(source); } UT_TEST(test_resource_x_kind9_ingress_is_target_native_and_no_fallback) { - static const char *const native_local_proof_contract[] = { - "cluster_bufmgr_pcm_own_snapshot_by_tag(", - "before.pcm_state != (uint8)PCM_STATE_S", - "before.pcm_state != (uint8)PCM_STATE_X", - "cluster_bufmgr_copy_block_for_r4_cr(", - "cluster_bufmgr_pcm_own_snapshot_by_tag(", - "memcmp(&before, &after, sizeof(before)) != 0", - "local_proof.kind = RESOURCE_X_WIRE_LOCAL_PROOF_DECLARATION", - "local_proof.body.local_proof.local_holder_authority_generation", - "local_proof.body.local_proof.requester_target_generation", - "gcs_block_pcm_x_resource_x_dependency_crc(zero_dependencies)", - "gcs_block_resource_x_assert_stage_exact(" - }; + static const char *const native_local_proof_contract[] + = { "cluster_bufmgr_pcm_own_snapshot_by_tag(", + "before.pcm_state != (uint8)PCM_STATE_S", + "before.pcm_state != (uint8)PCM_STATE_X", + "cluster_bufmgr_copy_block_for_r4_cr(", + "cluster_bufmgr_pcm_own_snapshot_by_tag(", + "memcmp(&before, &after, sizeof(before)) != 0", + "local_proof.kind = RESOURCE_X_WIRE_LOCAL_PROOF_DECLARATION", + "local_proof.body.local_proof.local_holder_authority_generation", + "local_proof.body.local_proof.requester_target_generation", + "gcs_block_pcm_x_resource_x_dependency_crc(zero_dependencies)", + "gcs_block_resource_x_assert_stage_exact(" }; char *source = read_gcs_block_source(); const char *candidate; const char *ingress; @@ -2687,45 +2627,32 @@ UT_TEST(test_resource_x_kind9_ingress_is_target_native_and_no_fallback) return; candidate = strstr(source, "\ngcs_block_resource_x_payload_candidate("); ingress = strstr(source, "\ngcs_block_resource_x_kind9_ingress("); - ack_stage = strstr(source, - "\ngcs_block_resource_x_bootstrap_ack_stage_exact("); + ack_stage = strstr(source, "\ngcs_block_resource_x_bootstrap_ack_stage_exact("); UT_ASSERT_NOT_NULL(candidate); UT_ASSERT_NOT_NULL(ingress); UT_ASSERT_NOT_NULL(ack_stage); if (candidate != NULL) { - UT_ASSERT_NOT_NULL(strstr(candidate, - "msg_type == RESOURCE_X_MSG_IMAGE_OR_GRANT")); - UT_ASSERT_NOT_NULL(strstr(candidate, - "payload_length == RESOURCE_X_CONTROL_V1_BYTES")); + UT_ASSERT_NOT_NULL(strstr(candidate, "msg_type == RESOURCE_X_MSG_IMAGE_OR_GRANT")); + UT_ASSERT_NOT_NULL(strstr(candidate, "payload_length == RESOURCE_X_CONTROL_V1_BYTES")); } if (ingress != NULL) { - UT_ASSERT_NOT_NULL(strstr(ingress, - "CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1")); - UT_ASSERT_NOT_NULL(strstr(ingress, - "cluster_semantic_activation_enter(")); - UT_ASSERT_NOT_NULL(strstr(ingress, - "cluster_pcm_lock_resource_x_bootstrap_request_exact(")); - UT_ASSERT_NOT_NULL(strstr(ingress, - "cluster_pcm_lock_resource_x_bootstrap_round_accept_ack_exact(")); - UT_ASSERT_NOT_NULL(strstr(ingress, - "cluster_semantic_activation_recheck(")); - UT_ASSERT_NOT_NULL(strstr(ingress, - "gcs_block_resource_x_bootstrap_ack_stage_exact(")); - UT_ASSERT_NOT_NULL(strstr(ingress, - "gcs_block_resource_x_native_assert_stage_exact(")); + UT_ASSERT_NOT_NULL( + strstr(ingress, "CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1")); + UT_ASSERT_NOT_NULL(strstr(ingress, "cluster_semantic_activation_enter(")); + UT_ASSERT_NOT_NULL(strstr(ingress, "cluster_pcm_lock_resource_x_bootstrap_request_exact(")); + UT_ASSERT_NOT_NULL( + strstr(ingress, "cluster_pcm_lock_resource_x_bootstrap_round_accept_ack_exact(")); + UT_ASSERT_NOT_NULL(strstr(ingress, "cluster_semantic_activation_recheck(")); + UT_ASSERT_NOT_NULL(strstr(ingress, "gcs_block_resource_x_bootstrap_ack_stage_exact(")); + UT_ASSERT_NOT_NULL(strstr(ingress, "gcs_block_resource_x_native_assert_stage_exact(")); } - assert_ordered_in_function( - source, "\ngcs_block_resource_x_native_assert_stage_exact(", - "\n/* PGRAC adaptation: requester round extraction", - native_local_proof_contract, - lengthof(native_local_proof_contract)); - UT_ASSERT_NOT_NULL(strstr(source, - "cluster_pcm_lock_resource_x_assert_bootstrapped_exact(")); + assert_ordered_in_function(source, "\ngcs_block_resource_x_native_assert_stage_exact(", + "\n/* PGRAC adaptation: requester round extraction", + native_local_proof_contract, lengthof(native_local_proof_contract)); + UT_ASSERT_NOT_NULL(strstr(source, "cluster_pcm_lock_resource_x_assert_bootstrapped_exact(")); if (ack_stage != NULL) { - const char *encode = strstr(ack_stage, - "cluster_resource_x_wire_encode("); - const char *enqueue = strstr(ack_stage, - "cluster_grd_outbound_enqueue_backend_msg("); + const char *encode = strstr(ack_stage, "cluster_resource_x_wire_encode("); + const char *enqueue = strstr(ack_stage, "cluster_grd_outbound_enqueue_backend_msg("); UT_ASSERT_NOT_NULL(encode); UT_ASSERT_NOT_NULL(enqueue); @@ -2777,8 +2704,7 @@ UT_TEST(test_resource_x_native_target_driver_uses_round_and_no_ticket_family) UT_ASSERT_NOT_NULL(source); if (source == NULL) return; - driver = strstr(source, - "\ngcs_block_resource_x_target_acquire_internal("); + driver = strstr(source, "\ngcs_block_resource_x_target_acquire_internal("); driver_end = driver != NULL ? strstr(driver, "\n}\n") : NULL; UT_ASSERT_NOT_NULL(driver); UT_ASSERT_NOT_NULL(driver_end); @@ -2796,17 +2722,15 @@ UT_TEST(test_resource_x_native_target_driver_uses_round_and_no_ticket_family) UT_ASSERT(site == NULL || site >= driver_end); } } - gate_helper = strstr(source, - "\ngcs_block_resource_x_gate_session_snapshot_result("); - gate_helper_end = gate_helper != NULL - ? strstr(gate_helper, "\n}\n") : NULL; + gate_helper = strstr(source, "\ngcs_block_resource_x_gate_session_snapshot_result("); + gate_helper_end = gate_helper != NULL ? strstr(gate_helper, "\n}\n") : NULL; UT_ASSERT_NOT_NULL(gate_helper); UT_ASSERT_NOT_NULL(gate_helper_end); if (gate_helper != NULL && gate_helper_end != NULL) { - const char *gate_snapshot = strstr(gate_helper, - "cluster_pcm_lock_resource_x_gate_snapshot("); - const char *session_snapshot = strstr(gate_helper, - "gcs_block_pcm_x_authenticated_session_result("); + const char *gate_snapshot + = strstr(gate_helper, "cluster_pcm_lock_resource_x_gate_snapshot("); + const char *session_snapshot + = strstr(gate_helper, "gcs_block_pcm_x_authenticated_session_result("); UT_ASSERT_NOT_NULL(gate_snapshot); UT_ASSERT_NOT_NULL(session_snapshot); @@ -2819,22 +2743,18 @@ UT_TEST(test_resource_x_native_target_driver_uses_round_and_no_ticket_family) /* TARGET derives its local base directly from BufferDesc. The deleted * source adapter and its local attempt/grant projections must not reappear * anywhere in the retained terminal executor. */ - terminal = strstr(source, - "\ngcs_block_pcm_x_resource_x_join_terminal_try("); + terminal = strstr(source, "\ngcs_block_pcm_x_resource_x_join_terminal_try("); terminal_end = terminal != NULL - ? strstr(terminal, "\nstatic ResourceXApplyResult\n" - "gcs_block_pcm_x_resource_x_master_durable_try(") - : NULL; + ? strstr(terminal, "\nstatic ResourceXApplyResult\n" + "gcs_block_pcm_x_resource_x_master_durable_try(") + : NULL; UT_ASSERT_NOT_NULL(terminal); UT_ASSERT_NOT_NULL(terminal_end); if (terminal != NULL && terminal_end != NULL) { - const char *target_snapshot = strstr(terminal, - "cluster_bufmgr_pcm_own_snapshot_by_tag("); + const char *target_snapshot = strstr(terminal, "cluster_bufmgr_pcm_own_snapshot_by_tag("); UT_ASSERT_NOT_NULL(target_snapshot); - UT_ASSERT(strstr(terminal, - "cluster_pcm_x_local_resource_x_attempt_exact(") == NULL); - UT_ASSERT(strstr(terminal, - "cluster_pcm_x_local_resource_x_grant_publish_exact(") == NULL); + UT_ASSERT(strstr(terminal, "cluster_pcm_x_local_resource_x_attempt_exact(") == NULL); + UT_ASSERT(strstr(terminal, "cluster_pcm_x_local_resource_x_grant_publish_exact(") == NULL); } free(source); } @@ -2860,20 +2780,16 @@ UT_TEST(test_resource_x_type15_exact_join_is_the_only_new_r9_entry) char *source = read_gcs_block_source(); const char *executor; - assert_ordered_in_function( - source, "\ngcs_block_try_resource_x_frame(", - "\n/*\n * cluster_gcs_handle_block_request_envelope", ingress_contract, - lengthof(ingress_contract)); - assert_ordered_in_function( - source, "\ngcs_block_pcm_x_resource_x_join_terminal_try(", - "\nstatic ResourceXApplyResult\n" - "gcs_block_pcm_x_resource_x_master_durable_try(", executor_contract, - lengthof(executor_contract)); - executor = strstr(source, - "\ngcs_block_pcm_x_resource_x_join_terminal_try("); + assert_ordered_in_function(source, "\ngcs_block_try_resource_x_frame(", + "\n/*\n * cluster_gcs_handle_block_request_envelope", + ingress_contract, lengthof(ingress_contract)); + assert_ordered_in_function(source, "\ngcs_block_pcm_x_resource_x_join_terminal_try(", + "\nstatic ResourceXApplyResult\n" + "gcs_block_pcm_x_resource_x_master_durable_try(", + executor_contract, lengthof(executor_contract)); + executor = strstr(source, "\ngcs_block_pcm_x_resource_x_join_terminal_try("); if (executor != NULL) - UT_ASSERT_NULL(strstr(executor, - "&ref, join.base_authority_generation")); + UT_ASSERT_NULL(strstr(executor, "&ref, join.base_authority_generation")); free(source); } @@ -2895,24 +2811,20 @@ UT_TEST(test_resource_x_duplicate_type15_tick_rearms_only_exact_buffer_busy) if (source == NULL) return; try_frame = strstr(source, "\ngcs_block_try_resource_x_frame("); - ingress = try_frame != NULL - ? strstr(try_frame, "case RESOURCE_X_WIRE_IMAGE_ENVELOPE:") : NULL; + ingress = try_frame != NULL ? strstr(try_frame, "case RESOURCE_X_WIRE_IMAGE_ENVELOPE:") : NULL; ingress_end = ingress != NULL ? strstr(ingress, "\n\t}\n\tif (") : NULL; - terminal = strstr(source, - "\ngcs_block_pcm_x_resource_x_join_terminal_try("); + terminal = strstr(source, "\ngcs_block_pcm_x_resource_x_join_terminal_try("); terminal_end = terminal != NULL - ? strstr(terminal, "\nstatic ResourceXApplyResult\n" - "gcs_block_pcm_x_resource_x_master_durable_try(") - : NULL; + ? strstr(terminal, "\nstatic ResourceXApplyResult\n" + "gcs_block_pcm_x_resource_x_master_durable_try(") + : NULL; UT_ASSERT_NOT_NULL(ingress); UT_ASSERT_NOT_NULL(ingress_end); UT_ASSERT_NOT_NULL(terminal); UT_ASSERT_NOT_NULL(terminal_end); if (ingress != NULL && ingress_end != NULL) { - const char *retry_arg = strstr(ingress, - "result == RESOURCE_X_APPLY_DUPLICATE"); - const char *terminal_try = strstr(ingress, - "gcs_block_resource_x_requester_terminal_try("); + const char *retry_arg = strstr(ingress, "result == RESOURCE_X_APPLY_DUPLICATE"); + const char *terminal_try = strstr(ingress, "gcs_block_resource_x_requester_terminal_try("); UT_ASSERT_NOT_NULL(retry_arg); UT_ASSERT_NOT_NULL(terminal_try); @@ -2930,18 +2842,22 @@ UT_TEST(test_resource_x_duplicate_type15_tick_rearms_only_exact_buffer_busy) * may clear only the same-generation, retryable content-lock BUSY * observation and make one new probe/attempt; no local loop or new timer * is allowed. */ - blocked = strstr(terminal, - "probe_result == RESOURCE_X_EXECUTOR_BLOCKED"); - exact_generation = blocked != NULL ? strstr(blocked, - "executor_snapshot.no_progress_generation == ref.acquisition_generation") - : NULL; - busy_reason = exact_generation != NULL ? strstr(exact_generation, - "executor_snapshot.no_progress_reason == RESOURCE_X_NO_PROGRESS_BUFFER_BUSY") - : NULL; - rearm = busy_reason != NULL ? strstr(busy_reason, - "cluster_pcm_lock_resource_x_executor_rearm_exact(&ref)") : NULL; - reprobe = rearm != NULL ? strstr(rearm, - "cluster_pcm_lock_resource_x_executor_probe_exact(") : NULL; + blocked = strstr(terminal, "probe_result == RESOURCE_X_EXECUTOR_BLOCKED"); + exact_generation + = blocked != NULL + ? strstr(blocked, + "executor_snapshot.no_progress_generation == ref.acquisition_generation") + : NULL; + busy_reason + = exact_generation != NULL + ? strstr(exact_generation, + "executor_snapshot.no_progress_reason == RESOURCE_X_NO_PROGRESS_BUFFER_BUSY") + : NULL; + rearm = busy_reason != NULL + ? strstr(busy_reason, "cluster_pcm_lock_resource_x_executor_rearm_exact(&ref)") + : NULL; + reprobe + = rearm != NULL ? strstr(rearm, "cluster_pcm_lock_resource_x_executor_probe_exact(") : NULL; UT_ASSERT_NOT_NULL(strstr(terminal, "bool scheduled_retry")); UT_ASSERT_NOT_NULL(blocked); UT_ASSERT_NOT_NULL(exact_generation); @@ -2955,31 +2871,29 @@ UT_TEST(test_resource_x_duplicate_type15_tick_rearms_only_exact_buffer_busy) UT_TEST(test_resource_x_direct_n_uses_exact_durable_storage_proof) { - static const char *const master_proof_contract[] = { - "captured->incompatible_holders_bitmap != captured->blocked_holders_bitmap", - "cluster_bufmgr_read_storage_image_for_resource_x(", - "gcs_block_pcm_x_resource_x_durable_proof_crc(", - "cluster_pcm_lock_resource_x_durable_proof_exact(" - }; + static const char *const master_proof_contract[] + = { "captured->incompatible_holders_bitmap != captured->blocked_holders_bitmap", + "cluster_bufmgr_read_storage_image_for_resource_x(", + "gcs_block_pcm_x_resource_x_durable_proof_crc(", + "cluster_pcm_lock_resource_x_durable_proof_exact(" }; static const char *const requester_join_contract[] = { "cluster_pcm_lock_resource_x_t1_grant_delivery_exact(", "cluster_bufmgr_read_storage_image_for_resource_x(", "gcs_block_pcm_x_resource_x_durable_proof_crc(", "gcs_block_pcm_x_resource_x_prepare_target_x(", "cluster_bufmgr_pcm_own_activate_x_by_tag(" }; - static const char *const target_direct_init_contract[] = { - "cluster_pcm_lock_resource_x_bootstrap_round_direct_init_snapshot_exact(", - "cluster_bufmgr_pcm_own_direct_init_snapshot_by_tag_exact(", - "cluster_pcm_lock_resource_x_bootstrap_round_direct_init_matches_exact(", - "current.flags == PCM_OWN_FLAG_GRANT_PENDING", - "if (target_native)", - "if (!direct_init_bound", - "(!require_clean_n", - "&& !direct_init_remote_install)", - "cluster_bufmgr_pcm_own_n_direct_init_candidate_exact(", - "cluster_pcm_lock_resource_x_bootstrap_round_direct_init_matches_exact(", - "cluster_bufmgr_pcm_own_finish_x_commit(" - }; + static const char *const target_direct_init_contract[] + = { "cluster_pcm_lock_resource_x_bootstrap_round_direct_init_snapshot_exact(", + "cluster_bufmgr_pcm_own_direct_init_snapshot_by_tag_exact(", + "cluster_pcm_lock_resource_x_bootstrap_round_direct_init_matches_exact(", + "current.flags == PCM_OWN_FLAG_GRANT_PENDING", + "if (target_native)", + "if (!direct_init_bound", + "(!require_clean_n", + "&& !direct_init_remote_install)", + "cluster_bufmgr_pcm_own_n_direct_init_candidate_exact(", + "cluster_pcm_lock_resource_x_bootstrap_round_direct_init_matches_exact(", + "cluster_bufmgr_pcm_own_finish_x_commit(" }; static const char *const target_direct_init_terminal_contract[] = { "gcs_block_pcm_x_resource_x_prepare_target_x(", "cluster_bufmgr_pcm_own_direct_init_bind_x_by_tag_exact(", @@ -2987,36 +2901,32 @@ UT_TEST(test_resource_x_direct_n_uses_exact_durable_storage_proof) "cluster_bufmgr_pcm_own_direct_init_clear_x_by_tag_exact(" }; char *source = read_gcs_block_source(); - assert_ordered_in_function( - source, "\ngcs_block_pcm_x_resource_x_master_durable_try(", - "\nstatic ResourceXApplyResult\n" - "gcs_block_pcm_x_resource_x_remote_s_own_result(", master_proof_contract, - lengthof(master_proof_contract)); - assert_ordered_in_function( - source, "\ngcs_block_pcm_x_resource_x_join_terminal_try(", - "\nstatic ResourceXApplyResult\n" - "gcs_block_pcm_x_resource_x_master_durable_try(", requester_join_contract, - lengthof(requester_join_contract)); + assert_ordered_in_function(source, "\ngcs_block_pcm_x_resource_x_master_durable_try(", + "\nstatic ResourceXApplyResult\n" + "gcs_block_pcm_x_resource_x_remote_s_own_result(", + master_proof_contract, lengthof(master_proof_contract)); + assert_ordered_in_function(source, "\ngcs_block_pcm_x_resource_x_join_terminal_try(", + "\nstatic ResourceXApplyResult\n" + "gcs_block_pcm_x_resource_x_master_durable_try(", + requester_join_contract, lengthof(requester_join_contract)); assert_ordered_in_function(source, "gcs_block_pcm_x_resource_x_prepare_target_x(", "\n/* Consume one complete retained type-15 join", target_direct_init_contract, lengthof(target_direct_init_contract)); - assert_ordered_in_function( - source, "\ngcs_block_pcm_x_resource_x_join_terminal_try(", - "\nstatic bool\ngcs_block_try_resource_x_frame(", - target_direct_init_terminal_contract, - lengthof(target_direct_init_terminal_contract)); + assert_ordered_in_function(source, "\ngcs_block_pcm_x_resource_x_join_terminal_try(", + "\nstatic bool\ngcs_block_try_resource_x_frame(", + target_direct_init_terminal_contract, + lengthof(target_direct_init_terminal_contract)); free(source); } UT_TEST(test_resource_x_target_x_freezes_exact_committed_generation_before_replay) { - static const char *const generation_contract[] = { - "expected_local_generation >= UINT64_MAX - 1", - "expected_committed_generation = expected_local_generation + 1;", - "cluster_pcm_x_resource_x_t2_snapshot_exact(ref, ¤t)", - "current.generation != expected_committed_generation", - "committed_generation != expected_committed_generation" - }; + static const char *const generation_contract[] + = { "expected_local_generation >= UINT64_MAX - 1", + "expected_committed_generation = expected_local_generation + 1;", + "cluster_pcm_x_resource_x_t2_snapshot_exact(ref, ¤t)", + "current.generation != expected_committed_generation", + "committed_generation != expected_committed_generation" }; char *source = read_gcs_block_source(); assert_ordered_in_function(source, "gcs_block_pcm_x_resource_x_prepare_target_x(", @@ -3035,42 +2945,35 @@ UT_TEST(test_resource_x_target_undrained_current_predecessor_shape) current.tag.relNumber = 16384; current.tag.forkNum = VISIBILITYMAP_FORKNUM; current.tag.blockNum = 0; - current.pcm_state = (uint8) PCM_STATE_N; + current.pcm_state = (uint8)PCM_STATE_N; current.generation = 2; current.reservation_token = 2; /* An exact undrained predecessor plus an independently revalidated clean * N+CURRENT descriptor grants no authority. It only permits the normal * empty-round step to return PREDECESSOR_WAIT under its original deadline. */ - UT_ASSERT( - cluster_gcs_resource_x_target_undrained_current_predecessor_exact( - true, false, CLUSTER_PCM_OWN_OK, ¤t)); + UT_ASSERT(cluster_gcs_resource_x_target_undrained_current_predecessor_exact( + true, false, CLUSTER_PCM_OWN_OK, ¤t)); /* N+PI stays on SourceSettlement's retained-release wait. Missing pair, * non-exact candidate, active flags, and malformed identity remain closed. */ - UT_ASSERT(! - cluster_gcs_resource_x_target_undrained_current_predecessor_exact( - true, true, CLUSTER_PCM_OWN_OK, ¤t)); - UT_ASSERT(! - cluster_gcs_resource_x_target_undrained_current_predecessor_exact( - false, false, CLUSTER_PCM_OWN_OK, ¤t)); - UT_ASSERT(! - cluster_gcs_resource_x_target_undrained_current_predecessor_exact( - true, false, CLUSTER_PCM_OWN_STALE, ¤t)); + UT_ASSERT(!cluster_gcs_resource_x_target_undrained_current_predecessor_exact( + true, true, CLUSTER_PCM_OWN_OK, ¤t)); + UT_ASSERT(!cluster_gcs_resource_x_target_undrained_current_predecessor_exact( + false, false, CLUSTER_PCM_OWN_OK, ¤t)); + UT_ASSERT(!cluster_gcs_resource_x_target_undrained_current_predecessor_exact( + true, false, CLUSTER_PCM_OWN_STALE, ¤t)); current.flags = PCM_OWN_FLAG_REVOKING; - UT_ASSERT(! - cluster_gcs_resource_x_target_undrained_current_predecessor_exact( - true, false, CLUSTER_PCM_OWN_OK, ¤t)); + UT_ASSERT(!cluster_gcs_resource_x_target_undrained_current_predecessor_exact( + true, false, CLUSTER_PCM_OWN_OK, ¤t)); current.flags = 0; current.generation = 0; - UT_ASSERT(! - cluster_gcs_resource_x_target_undrained_current_predecessor_exact( - true, false, CLUSTER_PCM_OWN_OK, ¤t)); + UT_ASSERT(!cluster_gcs_resource_x_target_undrained_current_predecessor_exact( + true, false, CLUSTER_PCM_OWN_OK, ¤t)); current.generation = 2; current.reservation_token = UINT64_MAX; - UT_ASSERT(! - cluster_gcs_resource_x_target_undrained_current_predecessor_exact( - true, false, CLUSTER_PCM_OWN_OK, ¤t)); + UT_ASSERT(!cluster_gcs_resource_x_target_undrained_current_predecessor_exact( + true, false, CLUSTER_PCM_OWN_OK, ¤t)); } UT_TEST(test_resource_x_native_target_accepts_only_exact_clean_n_before_bootstrap) @@ -3114,51 +3017,51 @@ UT_TEST(test_resource_x_native_target_accepts_only_exact_clean_n_before_bootstra * authority or bytes: the existing exact BM_VALID/no-IO N predicate must * pass before kind-9 bootstrap, and DURABLE_STORAGE remains master-selected. */ target = strstr(source, "\ngcs_block_resource_x_target_acquire_internal("); - target_end = target != NULL - ? strstr(target, "\nResourceXApplyResult\n" - "cluster_gcs_resource_x_target_acquire_exact(") - : NULL; - snapshot = target != NULL - ? strstr(target, "cluster_bufmgr_pcm_own_snapshot(buf, &own)") : NULL; - continuation_valid = snapshot != NULL - ? strstr(snapshot, "if (target_install_follow.valid)") - : NULL; - continuation_classify = continuation_valid != NULL - ? strstr(continuation_valid, - "gcs_block_resource_x_target_install_classify_coherent(") - : NULL; - continuation_wait = continuation_classify != NULL - ? strstr(continuation_classify, - "cluster_pcm_lock_resource_x_bootstrap_round_target_install_wait_exact(") - : NULL; - continuation_capture = continuation_wait != NULL - ? strstr(continuation_wait, - "gcs_block_resource_x_target_install_capture_coherent(") - : NULL; + target_end = target != NULL ? strstr(target, "\nResourceXApplyResult\n" + "cluster_gcs_resource_x_target_acquire_exact(") + : NULL; + snapshot = target != NULL ? strstr(target, "cluster_bufmgr_pcm_own_snapshot(buf, &own)") : NULL; + continuation_valid + = snapshot != NULL ? strstr(snapshot, "if (target_install_follow.valid)") : NULL; + continuation_classify + = continuation_valid != NULL + ? strstr(continuation_valid, "gcs_block_resource_x_target_install_classify_coherent(") + : NULL; + continuation_wait + = continuation_classify != NULL + ? strstr(continuation_classify, + "cluster_pcm_lock_resource_x_bootstrap_round_target_install_wait_exact(") + : NULL; + continuation_capture + = continuation_wait != NULL + ? strstr(continuation_wait, "gcs_block_resource_x_target_install_capture_coherent(") + : NULL; /* Anchor the ordinary TARGET N branch after receipt capture; direct-init * has an earlier, separate N shape. */ n_branch = continuation_capture != NULL - ? strstr(continuation_capture, - "} else {\n\t\t\t\t\tif (own.pcm_state == (uint8)PCM_STATE_N") - : NULL; - retained_pair_helper = n_branch != NULL - ? strstr(n_branch, - "cluster_pcm_lock_resource_x_holder_pair_retained_fence_exact(") - : NULL; + ? strstr(continuation_capture, + "} else {\n\t\t\t\t\tif (own.pcm_state == (uint8)PCM_STATE_N") + : NULL; + retained_pair_helper + = n_branch != NULL + ? strstr(n_branch, "cluster_pcm_lock_resource_x_holder_pair_retained_fence_exact(") + : NULL; retained_buffer_helper = retained_pair_helper != NULL ? strstr(retained_pair_helper, "cluster_bufmgr_pcm_own_n_predecessor_observe_exact(") : NULL; - undrained_current_helper = retained_buffer_helper != NULL - ? strstr(retained_buffer_helper, - "cluster_gcs_resource_x_target_undrained_current_predecessor_exact(") - : NULL; + undrained_current_helper + = retained_buffer_helper != NULL + ? strstr(retained_buffer_helper, + "cluster_gcs_resource_x_target_undrained_current_predecessor_exact(") + : NULL; retained_wait = retained_buffer_helper != NULL - ? strstr(retained_buffer_helper, - "if (target_retained_release_inflight)") : NULL; - retained_admission_recheck = retained_wait != NULL - ? strstr(retained_wait, - "cluster_semantic_activation_recheck(&admission)") : NULL; + ? strstr(retained_buffer_helper, "if (target_retained_release_inflight)") + : NULL; + retained_admission_recheck + = retained_wait != NULL + ? strstr(retained_wait, "cluster_semantic_activation_recheck(&admission)") + : NULL; retained_gate_recheck = retained_wait != NULL ? strstr(retained_wait, "gcs_block_resource_x_gate_session_recheck_result(") @@ -3170,33 +3073,29 @@ UT_TEST(test_resource_x_native_target_accepts_only_exact_clean_n_before_bootstra = retained_wait != NULL ? strstr(retained_wait, "cluster_pcm_lock_resource_x_predecessor_wait_exact(") : NULL; - retained_continue = retained_sleep != NULL - ? strstr(retained_sleep, "continue;") : NULL; + retained_continue = retained_sleep != NULL ? strstr(retained_sleep, "continue;") : NULL; n_candidate = n_branch != NULL - ? strstr(n_branch, - "cluster_bufmgr_pcm_own_n_assertion_candidate_exact(") - : NULL; + ? strstr(n_branch, "cluster_bufmgr_pcm_own_n_assertion_candidate_exact(") + : NULL; step = n_candidate != NULL ? strstr(n_candidate, "cluster_pcm_lock_resource_x_bootstrap_round_step_observed_exact(") : NULL; - predecessor_wait = step != NULL - ? strstr(step, - "RESOURCE_X_BOOTSTRAP_ROUND_PREDECESSOR_WAIT") : NULL; + predecessor_wait + = step != NULL ? strstr(step, "RESOURCE_X_BOOTSTRAP_ROUND_PREDECESSOR_WAIT") : NULL; predecessor_deadline = predecessor_wait != NULL ? strstr(predecessor_wait, "CHECK_FOR_INTERRUPTS()") : NULL; predecessor_sleep = predecessor_deadline != NULL ? strstr(predecessor_deadline, "cluster_pcm_lock_resource_x_predecessor_wait_exact(") : NULL; - predecessor_continue = predecessor_sleep != NULL - ? strstr(predecessor_sleep, "continue;") : NULL; + predecessor_continue + = predecessor_sleep != NULL ? strstr(predecessor_sleep, "continue;") : NULL; round_wait = predecessor_continue != NULL ? strstr(predecessor_continue, "cluster_pcm_lock_resource_x_bootstrap_round_wait_caller_exact(") : NULL; - generation_zero_reject = snapshot != NULL - ? strstr(snapshot, "if (own.generation == 0)") : NULL; + generation_zero_reject = snapshot != NULL ? strstr(snapshot, "if (own.generation == 0)") : NULL; readonly_wait = step != NULL ? strstr(step, "if (action != RESOURCE_X_BOOTSTRAP_ROUND_WAIT)") : NULL; @@ -3274,31 +3173,32 @@ UT_TEST(test_resource_x_native_target_accepts_only_exact_clean_n_before_bootstra /* The same cold-N shape must be revalidated at type-15 terminal before * T1/T2/T3. Rejecting generation zero before the exact N predicate would * invalidate the round that this function admitted above. */ - terminal = strstr(source, - "\ngcs_block_pcm_x_resource_x_join_terminal_try("); + terminal = strstr(source, "\ngcs_block_pcm_x_resource_x_join_terminal_try("); terminal_end = terminal != NULL - ? strstr(terminal, "\nstatic ResourceXApplyResult\n" - "gcs_block_pcm_x_resource_x_master_durable_try(") - : NULL; - terminal_snapshot = terminal != NULL - ? strstr(terminal, "cluster_bufmgr_pcm_own_snapshot_by_tag(") : NULL; - terminal_n_branch = terminal_snapshot != NULL - ? strstr(terminal_snapshot, - "target_base.pcm_state == (uint8)PCM_STATE_N") : NULL; - terminal_n_candidate = terminal_n_branch != NULL - ? strstr(terminal_n_branch, - "cluster_bufmgr_pcm_own_n_assertion_candidate_exact(") : NULL; + ? strstr(terminal, "\nstatic ResourceXApplyResult\n" + "gcs_block_pcm_x_resource_x_master_durable_try(") + : NULL; + terminal_snapshot + = terminal != NULL ? strstr(terminal, "cluster_bufmgr_pcm_own_snapshot_by_tag(") : NULL; + terminal_n_branch + = terminal_snapshot != NULL + ? strstr(terminal_snapshot, "target_base.pcm_state == (uint8)PCM_STATE_N") + : NULL; + terminal_n_candidate + = terminal_n_branch != NULL + ? strstr(terminal_n_branch, "cluster_bufmgr_pcm_own_n_assertion_candidate_exact(") + : NULL; terminal_generation_zero_reject = terminal_snapshot != NULL - ? strstr(terminal_snapshot, "target_base.generation == 0") : NULL; + ? strstr(terminal_snapshot, "target_base.generation == 0") + : NULL; UT_ASSERT_NOT_NULL(terminal); UT_ASSERT_NOT_NULL(terminal_end); UT_ASSERT_NOT_NULL(terminal_snapshot); UT_ASSERT_NOT_NULL(terminal_n_branch); UT_ASSERT_NOT_NULL(terminal_n_candidate); UT_ASSERT_NOT_NULL(terminal_generation_zero_reject); - if (terminal_end != NULL && terminal_snapshot != NULL - && terminal_n_branch != NULL && terminal_n_candidate != NULL - && terminal_generation_zero_reject != NULL) { + if (terminal_end != NULL && terminal_snapshot != NULL && terminal_n_branch != NULL + && terminal_n_candidate != NULL && terminal_generation_zero_reject != NULL) { UT_ASSERT(terminal_snapshot < terminal_n_branch); UT_ASSERT(terminal_n_branch < terminal_n_candidate); UT_ASSERT(terminal_n_candidate < terminal_generation_zero_reject); @@ -3331,49 +3231,40 @@ UT_TEST(test_resource_x_target_preflight_waits_under_one_r7_deadline) * Resource-X round exists this is pre-mutation backpressure: keep the exact * admission/gate/transport checks, wait only under the first R7 absolute * deadline, and do not create or reuse a round while the proof is absent. */ - target = source != NULL - ? strstr(source, "\ngcs_block_resource_x_target_acquire_internal(") - : NULL; - target_end = target != NULL - ? strstr(target, "\nResourceXApplyResult\n" - "cluster_gcs_resource_x_target_acquire_exact(") - : NULL; + target + = source != NULL ? strstr(source, "\ngcs_block_resource_x_target_acquire_internal(") : NULL; + target_end = target != NULL ? strstr(target, "\nResourceXApplyResult\n" + "cluster_gcs_resource_x_target_acquire_exact(") + : NULL; deadline = target != NULL - ? strstr(target, "absolute_deadline_us = gcs_block_pcm_x_saturating_add_us(") - : NULL; - preflight_loop = deadline != NULL - ? strstr(deadline, "diagnostic_stage = \"preflight-membership\"") - : NULL; + ? strstr(target, + "absolute_deadline_us\n\t\t\t\t\t= gcs_block_pcm_x_saturating_add_us(") + : NULL; + preflight_loop + = deadline != NULL ? strstr(deadline, "diagnostic_stage = \"preflight-membership\"") : NULL; gate = preflight_loop != NULL - ? strstr(preflight_loop, - "gcs_block_resource_x_gate_session_snapshot_result(") - : NULL; - admission_recheck = gate != NULL - ? strstr(gate, "cluster_semantic_activation_recheck(&admission)") - : NULL; - cross_namespace_formation_compare = preflight_loop != NULL - ? strstr(preflight_loop, - "gate.formation != admission.formation_epoch") - : NULL; + ? strstr(preflight_loop, "gcs_block_resource_x_gate_session_snapshot_result(") + : NULL; + admission_recheck + = gate != NULL ? strstr(gate, "cluster_semantic_activation_recheck(&admission)") : NULL; + cross_namespace_formation_compare + = preflight_loop != NULL + ? strstr(preflight_loop, "gate.formation != admission.formation_epoch") + : NULL; peer_ready = admission_recheck != NULL - ? strstr(admission_recheck, - "gcs_block_pcm_x_resource_x_peer_ready_exact(") - : NULL; + ? strstr(admission_recheck, "gcs_block_pcm_x_resource_x_peer_ready_exact(") + : NULL; peer_open = peer_ready != NULL - ? strstr(peer_ready, - "gcs_block_resource_x_target_peer_matches_exact(") - : NULL; + ? strstr(peer_ready, "gcs_block_resource_x_target_peer_matches_exact(") + : NULL; wait_stage = peer_open != NULL - ? strstr(peer_open, - "diagnostic_stage = \"preflight-membership-wait\"") - : NULL; + ? strstr(peer_open, "diagnostic_stage = \"preflight-membership-wait\"") + : NULL; deadline_check = wait_stage != NULL ? strstr(wait_stage, "now_us == 0 || now_us == UINT64_MAX") : NULL; - sleep = deadline_check != NULL - ? strstr(deadline_check, "pg_usleep(timeout_ms * 1000L)") : NULL; + sleep = deadline_check != NULL ? strstr(deadline_check, "pg_usleep(timeout_ms * 1000L)") : NULL; retry = sleep != NULL ? strstr(sleep, "continue;") : NULL; - round_loop = retry != NULL - ? strstr(retry, "diagnostic_stage = \"round-loop\"") : NULL; + round_loop = retry != NULL ? strstr(retry, "diagnostic_stage = \"round-loop\"") : NULL; round_step = round_loop != NULL ? strstr(round_loop, "cluster_pcm_lock_resource_x_bootstrap_round_step_observed_exact(") @@ -3384,10 +3275,8 @@ UT_TEST(test_resource_x_target_preflight_waits_under_one_r7_deadline) UT_ASSERT_NOT_NULL(deadline); UT_ASSERT_NOT_NULL(preflight_loop); UT_ASSERT_NOT_NULL(gate); - UT_ASSERT_NOT_NULL(strstr(preflight_loop, - "cluster_gcs_pcm_x_auth_result_retryable(")); - UT_ASSERT_NOT_NULL(strstr(preflight_loop, - "preflight_session_check=%d")); + UT_ASSERT_NOT_NULL(strstr(preflight_loop, "cluster_gcs_pcm_x_auth_result_retryable(")); + UT_ASSERT_NOT_NULL(strstr(preflight_loop, "preflight_session_check=%d")); UT_ASSERT_NOT_NULL(admission_recheck); /* ResourceXGateSnapshot.formation is a per-resource generation, while * admission.formation_epoch is the cluster membership epoch. Comparing @@ -3401,11 +3290,10 @@ UT_TEST(test_resource_x_target_preflight_waits_under_one_r7_deadline) UT_ASSERT_NOT_NULL(retry); UT_ASSERT_NOT_NULL(round_loop); UT_ASSERT_NOT_NULL(round_step); - if (target_end != NULL && deadline != NULL && preflight_loop != NULL - && gate != NULL && admission_recheck != NULL && peer_ready != NULL - && peer_open != NULL && wait_stage != NULL && deadline_check != NULL - && sleep != NULL && retry != NULL && round_loop != NULL - && round_step != NULL) { + if (target_end != NULL && deadline != NULL && preflight_loop != NULL && gate != NULL + && admission_recheck != NULL && peer_ready != NULL && peer_open != NULL + && wait_stage != NULL && deadline_check != NULL && sleep != NULL && retry != NULL + && round_loop != NULL && round_step != NULL) { UT_ASSERT(target < deadline && deadline < preflight_loop); UT_ASSERT(preflight_loop < gate && gate < admission_recheck); UT_ASSERT(admission_recheck < peer_ready && peer_ready < peer_open); @@ -3419,11 +3307,10 @@ UT_TEST(test_resource_x_target_preflight_waits_under_one_r7_deadline) UT_TEST(test_resource_x_passive_pi_waits_for_exact_remote_image_before_x) { - static const char *const target_contract[] = { - "cluster_bufmgr_pcm_own_begin_x_reservation(", - "gcs_block_pcm_x_resource_x_install_target_image_exact(", - "cluster_bufmgr_pcm_own_finish_x_commit(" - }; + static const char *const target_contract[] + = { "cluster_bufmgr_pcm_own_begin_x_reservation(", + "gcs_block_pcm_x_resource_x_install_target_image_exact(", + "cluster_bufmgr_pcm_own_finish_x_commit(" }; char *source = read_gcs_block_source(); const char *join; const char *remote_image; @@ -3437,10 +3324,9 @@ UT_TEST(test_resource_x_passive_pi_waits_for_exact_remote_image_before_x) "\n/* Consume one complete retained type-15 join", target_contract, lengthof(target_contract)); join = strstr(source, "\ngcs_block_pcm_x_resource_x_join_terminal_try("); - remote_image = join != NULL - ? strstr(join, "image_frame.body.image_envelope.page_bytes") : NULL; - prepare_target = join != NULL - ? strstr(join, "gcs_block_pcm_x_resource_x_prepare_target_x(") : NULL; + remote_image = join != NULL ? strstr(join, "image_frame.body.image_envelope.page_bytes") : NULL; + prepare_target + = join != NULL ? strstr(join, "gcs_block_pcm_x_resource_x_prepare_target_x(") : NULL; UT_ASSERT_NOT_NULL(remote_image); UT_ASSERT_NOT_NULL(prepare_target); UT_ASSERT(remote_image < prepare_target); @@ -3467,14 +3353,13 @@ UT_TEST(test_resource_x_direct_init_remote_carrier_is_aux_only_exact_r9_install) "if (direct_init_bound && !remote_proof)", "cluster_bufmgr_pcm_own_direct_init_clear_x_by_tag_exact(", "cluster_bufmgr_pcm_own_writer_activation_clear_by_tag_exact(" }; - static const char *const install_contract[] = { - "direct_init_remote_install", - "GcsBlockResourceXDirectInitProofAllowedExact(", - "cluster_pcm_lock_resource_x_bootstrap_round_direct_init_matches_exact(", - "cluster_bufmgr_pcm_own_n_direct_init_candidate_exact(", - "gcs_block_pcm_x_resource_x_install_target_image_exact(", - "cluster_bufmgr_pcm_own_finish_x_commit(" - }; + static const char *const install_contract[] + = { "direct_init_remote_install", + "GcsBlockResourceXDirectInitProofAllowedExact(", + "cluster_pcm_lock_resource_x_bootstrap_round_direct_init_matches_exact(", + "cluster_bufmgr_pcm_own_n_direct_init_candidate_exact(", + "gcs_block_pcm_x_resource_x_install_target_image_exact(", + "cluster_bufmgr_pcm_own_finish_x_commit(" }; char *source = read_gcs_block_source(); BufferTag tag; @@ -3485,25 +3370,17 @@ UT_TEST(test_resource_x_direct_init_remote_carrier_is_aux_only_exact_r9_install) * outside this user-approved seam. */ memset(&tag, 0, sizeof(tag)); tag.forkNum = VISIBILITYMAP_FORKNUM; - UT_ASSERT(GcsBlockResourceXDirectInitProofAllowedExact( - &tag, false, true)); + UT_ASSERT(GcsBlockResourceXDirectInitProofAllowedExact(&tag, false, true)); tag.forkNum = FSM_FORKNUM; - UT_ASSERT(GcsBlockResourceXDirectInitProofAllowedExact( - &tag, false, true)); + UT_ASSERT(GcsBlockResourceXDirectInitProofAllowedExact(&tag, false, true)); tag.forkNum = MAIN_FORKNUM; - UT_ASSERT(!GcsBlockResourceXDirectInitProofAllowedExact( - &tag, false, true)); + UT_ASSERT(!GcsBlockResourceXDirectInitProofAllowedExact(&tag, false, true)); tag.forkNum = INIT_FORKNUM; - UT_ASSERT(!GcsBlockResourceXDirectInitProofAllowedExact( - &tag, false, true)); - UT_ASSERT(GcsBlockResourceXDirectInitProofAllowedExact( - &tag, true, false)); - UT_ASSERT(!GcsBlockResourceXDirectInitProofAllowedExact( - &tag, false, false)); - UT_ASSERT(!GcsBlockResourceXDirectInitProofAllowedExact( - &tag, true, true)); - UT_ASSERT(!GcsBlockResourceXDirectInitProofAllowedExact( - NULL, false, true)); + UT_ASSERT(!GcsBlockResourceXDirectInitProofAllowedExact(&tag, false, true)); + UT_ASSERT(GcsBlockResourceXDirectInitProofAllowedExact(&tag, true, false)); + UT_ASSERT(!GcsBlockResourceXDirectInitProofAllowedExact(&tag, false, false)); + UT_ASSERT(!GcsBlockResourceXDirectInitProofAllowedExact(&tag, true, true)); + UT_ASSERT(!GcsBlockResourceXDirectInitProofAllowedExact(NULL, false, true)); UT_ASSERT_NOT_NULL(source); if (source == NULL) return; @@ -3519,22 +3396,19 @@ UT_TEST(test_resource_x_direct_init_remote_carrier_is_aux_only_exact_r9_install) UT_TEST(test_resource_x_settlement_removes_exact_wfg_before_locator_completion) { - static const char *const completion_contract[] = { - "cluster_pcm_lock_resource_x_install_settlement_exact(", - "snapshot.phase == RESOURCE_X_MASTER_SETTLED", - "cluster_pcm_lock_resource_x_settled_retire_exact(" - }; + static const char *const completion_contract[] + = { "cluster_pcm_lock_resource_x_install_settlement_exact(", + "snapshot.phase == RESOURCE_X_MASTER_SETTLED", + "cluster_pcm_lock_resource_x_settled_retire_exact(" }; char *source = read_gcs_block_source(); /* Source-removed TARGET has no legacy WFG/locator completion. An exact * settlement reaches the canonical master entry and then retires that same * assertion generation; failures remain fail closed. */ - assert_ordered_in_function( - source, "\ngcs_block_try_resource_x_frame(", - "\n/*\n * cluster_gcs_handle_block_request_envelope", - completion_contract, lengthof(completion_contract)); - UT_ASSERT(strstr(source, - "gcs_block_pcm_x_resource_x_complete_and_remove_wfg_exact(") == NULL); + assert_ordered_in_function(source, "\ngcs_block_try_resource_x_frame(", + "\n/*\n * cluster_gcs_handle_block_request_envelope", + completion_contract, lengthof(completion_contract)); + UT_ASSERT(strstr(source, "gcs_block_pcm_x_resource_x_complete_and_remove_wfg_exact(") == NULL); UT_ASSERT(strstr(source, "cluster_gcs_pcm_x_vertex_from_identity(") == NULL); free(source); } @@ -3556,10 +3430,9 @@ UT_TEST(test_resource_x_native_settlement_has_no_legacy_locator_cleanup) UT_ASSERT_NOT_NULL(ingress); UT_ASSERT_NOT_NULL(ingress_end); if (ingress != NULL && ingress_end != NULL) { - legacy_cleanup = strstr(ingress, - "gcs_block_pcm_x_resource_x_complete_and_remove_wfg_exact("); - resource_x_retire = strstr(ingress, - "cluster_pcm_lock_resource_x_settled_retire_exact("); + legacy_cleanup + = strstr(ingress, "gcs_block_pcm_x_resource_x_complete_and_remove_wfg_exact("); + resource_x_retire = strstr(ingress, "cluster_pcm_lock_resource_x_settled_retire_exact("); UT_ASSERT_NULL(legacy_cleanup); UT_ASSERT_NOT_NULL(resource_x_retire); /* The common tail also retires when proof is the second leg. */ @@ -3573,36 +3446,35 @@ UT_TEST(test_resource_x_native_settlement_has_no_legacy_locator_cleanup) UT_TEST(test_resource_x_source_settlement_uses_exact_typed_debt_and_ack) { - static const char *const source_apply_contract[] = { - "ResourceXSourceSettlementPlan plan", - "ResourceXSourceSettlementCommitObservation prepare_observation", - "cluster_pcm_lock_resource_x_source_settlement_prepare_observed_exact(", - "&prepare_observation", - "if (result == RESOURCE_X_APPLY_APPLIED && plan.valid)", - "cluster_pcm_x_revoke_finish_mode(&plan.assertion.resource, 0)", - "settlement_finish_mode == CLUSTER_PCM_X_REVOKE_FINISH_RETAIN", - "cluster_bufmgr_pcm_own_release_retained_fence_preserve_pi(", - "&plan.assertion.resource", - "plan.source_generation", - "&carrier_release_complete", - "gcs_block_resource_x_source_settlement_failure_record(", - "RESOURCE_X_SOURCE_SETTLEMENT_STAGE_LOCAL_RELEASE", - "cluster_pcm_lock_resource_x_source_settlement_commit_exact(", - "&plan", - "&commit_observation", - "gcs_block_resource_x_source_settlement_failure_record(", - "&commit_observation", - "RESOURCE_X_SOURCE_SETTLEMENT_STAGE_COMMIT", - "gcs_block_resource_x_source_settlement_failure_record(", - "RESOURCE_X_SOURCE_SETTLEMENT_STAGE_PREPARE", - "cluster_pcm_lock_resource_x_source_settlement_ack_build_exact(", - "gcs_block_resource_x_source_settlement_failure_record(", - "RESOURCE_X_SOURCE_SETTLEMENT_STAGE_ACK_BUILD", - "cluster_resource_x_wire_encode(", - "gcs_block_resource_x_source_settlement_failure_record(", - "RESOURCE_X_SOURCE_SETTLEMENT_STAGE_ACK_ENCODE", - "cluster_grd_outbound_enqueue_backend_msg(" - }; + static const char *const source_apply_contract[] + = { "ResourceXSourceSettlementPlan plan", + "ResourceXSourceSettlementCommitObservation prepare_observation", + "cluster_pcm_lock_resource_x_source_settlement_prepare_observed_exact(", + "&prepare_observation", + "if (result == RESOURCE_X_APPLY_APPLIED && plan.valid)", + "cluster_pcm_x_revoke_finish_mode(&plan.assertion.resource, 0)", + "settlement_finish_mode == CLUSTER_PCM_X_REVOKE_FINISH_RETAIN", + "cluster_bufmgr_pcm_own_release_retained_fence_preserve_pi(", + "&plan.assertion.resource", + "plan.source_generation", + "&carrier_release_complete", + "gcs_block_resource_x_source_settlement_failure_record(", + "RESOURCE_X_SOURCE_SETTLEMENT_STAGE_LOCAL_RELEASE", + "cluster_pcm_lock_resource_x_source_settlement_commit_exact(", + "&plan", + "&commit_observation", + "gcs_block_resource_x_source_settlement_failure_record(", + "&commit_observation", + "RESOURCE_X_SOURCE_SETTLEMENT_STAGE_COMMIT", + "gcs_block_resource_x_source_settlement_failure_record(", + "RESOURCE_X_SOURCE_SETTLEMENT_STAGE_PREPARE", + "cluster_pcm_lock_resource_x_source_settlement_ack_build_exact(", + "gcs_block_resource_x_source_settlement_failure_record(", + "RESOURCE_X_SOURCE_SETTLEMENT_STAGE_ACK_BUILD", + "cluster_resource_x_wire_encode(", + "gcs_block_resource_x_source_settlement_failure_record(", + "RESOURCE_X_SOURCE_SETTLEMENT_STAGE_ACK_ENCODE", + "cluster_grd_outbound_enqueue_backend_msg(" }; char *source = read_gcs_block_source(); const char *candidate; const char *candidate_end; @@ -3614,11 +3486,10 @@ UT_TEST(test_resource_x_source_settlement_uses_exact_typed_debt_and_ack) UT_ASSERT_NOT_NULL(source); if (source == NULL) return; - candidate = strstr(source, - "if (msg_type == RESOURCE_X_MSG_BLOCK_TO_N)"); + candidate = strstr(source, "if (msg_type == RESOURCE_X_MSG_BLOCK_TO_N)"); candidate_end = candidate != NULL - ? strstr(candidate, - "if (msg_type == RESOURCE_X_MSG_BLOCKED_TO_N)") : NULL; + ? strstr(candidate, "if (msg_type == RESOURCE_X_MSG_BLOCKED_TO_N)") + : NULL; UT_ASSERT_NOT_NULL(candidate); UT_ASSERT_NOT_NULL(candidate_end); if (candidate != NULL && candidate_end != NULL) { @@ -3628,24 +3499,24 @@ UT_TEST(test_resource_x_source_settlement_uses_exact_typed_debt_and_ack) if (proof != NULL) UT_ASSERT(proof < candidate_end); } - assert_ordered_in_function( - source, "\ngcs_block_resource_x_source_settlement_ingress(", - "\n\nstatic", source_apply_contract, - lengthof(source_apply_contract)); - handler = strstr(source, - "\ngcs_block_resource_x_source_settlement_ingress("); + assert_ordered_in_function(source, "\ngcs_block_resource_x_source_settlement_ingress(", + "\n\nstatic", source_apply_contract, + lengthof(source_apply_contract)); + handler = strstr(source, "\ngcs_block_resource_x_source_settlement_ingress("); handler_end = handler != NULL ? strstr(handler, "\n\nstatic") : NULL; UT_ASSERT_NOT_NULL(handler); UT_ASSERT_NOT_NULL(handler_end); if (handler != NULL && handler_end != NULL) { - const char *guard = strstr(handler, - "if (result == RESOURCE_X_APPLY_APPLIED && plan.valid)"); - const char *release = guard != NULL ? strstr(guard, - "cluster_bufmgr_pcm_own_release_retained_fence_preserve_pi(") - : NULL; - const char *second_release = release != NULL ? strstr(release + 1, - "cluster_bufmgr_pcm_own_release_retained_fence_preserve_pi(") - : NULL; + const char *guard + = strstr(handler, "if (result == RESOURCE_X_APPLY_APPLIED && plan.valid)"); + const char *release + = guard != NULL + ? strstr(guard, "cluster_bufmgr_pcm_own_release_retained_fence_preserve_pi(") + : NULL; + const char *second_release + = release != NULL ? strstr(release + 1, + "cluster_bufmgr_pcm_own_release_retained_fence_preserve_pi(") + : NULL; UT_ASSERT_NOT_NULL(guard); UT_ASSERT_NOT_NULL(release); @@ -3653,41 +3524,28 @@ UT_TEST(test_resource_x_source_settlement_uses_exact_typed_debt_and_ack) UT_ASSERT(guard < release && release < handler_end); UT_ASSERT(second_release == NULL || second_release >= handler_end); } - UT_ASSERT_NOT_NULL(strstr(source, - "ResourceXSourceSettlementStage source_settlement_stage")); + UT_ASSERT_NOT_NULL(strstr(source, "ResourceXSourceSettlementStage source_settlement_stage")); UT_ASSERT_NOT_NULL(strstr(source, "source_settlement_stage=%u")); - UT_ASSERT_NOT_NULL(strstr(source, - "source_settlement_commit_stage=%u")); - UT_ASSERT_NOT_NULL(strstr(source, - "source_settlement_commit_mismatch=0x%08x")); - UT_ASSERT_NOT_NULL(strstr(source, - "source_settlement_current_formation=%llu")); - UT_ASSERT_NOT_NULL(strstr(source, - "source_settlement_current_terminal_authority=%llu")); - UT_ASSERT_NOT_NULL(strstr(source, - "source_settlement_current_cached_generation=%llu")); - UT_ASSERT_NOT_NULL(strstr(source, - "source_settlement_current_round_phase=%u")); - UT_ASSERT_NOT_NULL(strstr(source, - "source_settlement_current_owner_state=%u")); - UT_ASSERT_NOT_NULL(strstr(source, - "source_settlement_pair_observed_mode=%u")); - UT_ASSERT_NOT_NULL(strstr(source, - "first_failure.holder_mutation_started = release_applied")); + UT_ASSERT_NOT_NULL(strstr(source, "source_settlement_commit_stage=%u")); + UT_ASSERT_NOT_NULL(strstr(source, "source_settlement_commit_mismatch=0x%08x")); + UT_ASSERT_NOT_NULL(strstr(source, "source_settlement_current_formation=%llu")); + UT_ASSERT_NOT_NULL(strstr(source, "source_settlement_current_terminal_authority=%llu")); + UT_ASSERT_NOT_NULL(strstr(source, "source_settlement_current_cached_generation=%llu")); + UT_ASSERT_NOT_NULL(strstr(source, "source_settlement_current_round_phase=%u")); + UT_ASSERT_NOT_NULL(strstr(source, "source_settlement_current_owner_state=%u")); + UT_ASSERT_NOT_NULL(strstr(source, "source_settlement_pair_observed_mode=%u")); + UT_ASSERT_NOT_NULL(strstr(source, "first_failure.holder_mutation_started = release_applied")); ingress = strstr(source, "case RESOURCE_X_WIRE_SOURCE_SETTLEMENT_V2:"); - ingress_end = ingress != NULL - ? strstr(ingress, "case RESOURCE_X_WIRE_RELEASE_X:") : NULL; + ingress_end = ingress != NULL ? strstr(ingress, "case RESOURCE_X_WIRE_RELEASE_X:") : NULL; UT_ASSERT_NOT_NULL(ingress); UT_ASSERT_NOT_NULL(ingress_end); if (ingress != NULL && ingress_end != NULL) { - const char *apply = strstr(ingress, - "gcs_block_resource_x_source_settlement_ingress("); - const char *ack_case = strstr(ingress, - "case RESOURCE_X_WIRE_SOURCE_SETTLEMENT_ACK_V2:"); - const char *ack_apply = ack_case != NULL - ? strstr(ack_case, - "cluster_pcm_lock_resource_x_source_settlement_ack_exact(") - : NULL; + const char *apply = strstr(ingress, "gcs_block_resource_x_source_settlement_ingress("); + const char *ack_case = strstr(ingress, "case RESOURCE_X_WIRE_SOURCE_SETTLEMENT_ACK_V2:"); + const char *ack_apply + = ack_case != NULL + ? strstr(ack_case, "cluster_pcm_lock_resource_x_source_settlement_ack_exact(") + : NULL; UT_ASSERT_NOT_NULL(apply); UT_ASSERT_NOT_NULL(ack_case); @@ -3717,8 +3575,7 @@ UT_TEST(test_resource_x_source_settlement_distinguishes_retained_and_dropped_car UT_ASSERT_NOT_NULL(source); if (source == NULL) return; - handler = strstr(source, - "\ngcs_block_resource_x_source_settlement_ingress("); + handler = strstr(source, "\ngcs_block_resource_x_source_settlement_ingress("); handler_end = handler != NULL ? strstr(handler, "\n\nstatic") : NULL; UT_ASSERT_NOT_NULL(handler); UT_ASSERT_NOT_NULL(handler_end); @@ -3731,25 +3588,29 @@ UT_TEST(test_resource_x_source_settlement_distinguishes_retained_and_dropped_car * already completed their exact unpinned DROP before the pair can become * PUBLISHED, so settlement must not look up a descriptor that no longer * exists. Any unclassified fork remains fail closed. */ - classify = strstr(handler, - "cluster_pcm_x_revoke_finish_mode(&plan.assertion.resource, 0)"); - retain_branch = classify != NULL ? strstr(classify, - "settlement_finish_mode == CLUSTER_PCM_X_REVOKE_FINISH_RETAIN") - : NULL; - release = retain_branch != NULL ? strstr(retain_branch, - "cluster_bufmgr_pcm_own_release_retained_fence_preserve_pi(") - : NULL; - drop_branch = release != NULL ? strstr(release, - "settlement_finish_mode == CLUSTER_PCM_X_REVOKE_FINISH_DROP") - : NULL; - drop_complete = drop_branch != NULL ? strstr(drop_branch, - "carrier_release_complete = true") : NULL; + classify = strstr(handler, "cluster_pcm_x_revoke_finish_mode(&plan.assertion.resource, 0)"); + retain_branch + = classify != NULL + ? strstr(classify, "settlement_finish_mode == CLUSTER_PCM_X_REVOKE_FINISH_RETAIN") + : NULL; + release + = retain_branch != NULL + ? strstr(retain_branch, "cluster_bufmgr_pcm_own_release_retained_fence_preserve_pi(") + : NULL; + drop_branch + = release != NULL + ? strstr(release, "settlement_finish_mode == CLUSTER_PCM_X_REVOKE_FINISH_DROP") + : NULL; + drop_complete + = drop_branch != NULL ? strstr(drop_branch, "carrier_release_complete = true") : NULL; invalid_branch = drop_complete != NULL ? strstr(drop_complete, "else {") : NULL; - fail_closed = invalid_branch != NULL ? strstr(invalid_branch, - "gcs_block_resource_x_fail_closed_current()") : NULL; - commit = fail_closed != NULL ? strstr(fail_closed, - "cluster_pcm_lock_resource_x_source_settlement_commit_exact(") - : NULL; + fail_closed = invalid_branch != NULL + ? strstr(invalid_branch, "gcs_block_resource_x_fail_closed_current()") + : NULL; + commit + = fail_closed != NULL + ? strstr(fail_closed, "cluster_pcm_lock_resource_x_source_settlement_commit_exact(") + : NULL; UT_ASSERT_NOT_NULL(classify); UT_ASSERT_NOT_NULL(retain_branch); @@ -3759,17 +3620,11 @@ UT_TEST(test_resource_x_source_settlement_distinguishes_retained_and_dropped_car UT_ASSERT_NOT_NULL(invalid_branch); UT_ASSERT_NOT_NULL(fail_closed); UT_ASSERT_NOT_NULL(commit); - if (classify != NULL && retain_branch != NULL && release != NULL - && drop_branch != NULL && drop_complete != NULL - && invalid_branch != NULL && fail_closed != NULL && commit != NULL) - UT_ASSERT(classify < retain_branch - && retain_branch < release - && release < drop_branch - && drop_branch < drop_complete - && drop_complete < invalid_branch - && invalid_branch < fail_closed - && fail_closed < commit - && commit < handler_end); + if (classify != NULL && retain_branch != NULL && release != NULL && drop_branch != NULL + && drop_complete != NULL && invalid_branch != NULL && fail_closed != NULL && commit != NULL) + UT_ASSERT(classify < retain_branch && retain_branch < release && release < drop_branch + && drop_branch < drop_complete && drop_complete < invalid_branch + && invalid_branch < fail_closed && fail_closed < commit && commit < handler_end); free(source); } @@ -3827,23 +3682,18 @@ UT_TEST(test_resource_x_type17_x_source_fences_before_retained_release) source, "\ngcs_block_resource_x_source_finish_owned(", "\nstatic ResourceXApplyResult\ngcs_block_pcm_x_resource_x_source_block_to_n(", finish_contract, lengthof(finish_contract)); - helper = strstr(source, - "\ngcs_block_pcm_x_resource_x_source_block_to_n("); + helper = strstr(source, "\ngcs_block_pcm_x_resource_x_source_block_to_n("); UT_ASSERT_NOT_NULL(helper); if (helper != NULL) - assert_ordered_in_function( - source, "\ngcs_block_pcm_x_resource_x_source_block_to_n(", - "\n\n/* Consume the exact Resource-X subdomain", source_contract, - lengthof(source_contract)); + assert_ordered_in_function(source, "\ngcs_block_pcm_x_resource_x_source_block_to_n(", + "\n\n/* Consume the exact Resource-X subdomain", source_contract, + lengthof(source_contract)); if (helper != NULL) - UT_ASSERT_NOT_NULL(strstr(helper, - "status_result != RESOURCE_X_APPLY_NOT_FOUND\n" - "\t\t&& status_result != RESOURCE_X_APPLY_STALE")); + UT_ASSERT_NOT_NULL(strstr(helper, "status_result != RESOURCE_X_APPLY_NOT_FOUND\n" + "\t\t\t && status_result != RESOURCE_X_APPLY_STALE")); if (helper != NULL) { - const char *helper_end = strstr( - helper, "\n\n/* Consume the exact Resource-X subdomain"); - const char *legacy_fence = strstr( - helper, "cluster_pcm_x_local_writer_revoke_fence_"); + const char *helper_end = strstr(helper, "\n\n/* Consume the exact Resource-X subdomain"); + const char *legacy_fence = strstr(helper, "cluster_pcm_x_local_writer_revoke_fence_"); UT_ASSERT_NOT_NULL(helper_end); UT_ASSERT(legacy_fence == NULL || legacy_fence >= helper_end); @@ -3852,12 +3702,11 @@ UT_TEST(test_resource_x_type17_x_source_fences_before_retained_release) UT_ASSERT_NOT_NULL(strstr(source, "pair_retained")); } ingress = strstr(source, "\ngcs_block_resource_x_type17_ingress("); - source_call = ingress != NULL - ? strstr(ingress, "gcs_block_pcm_x_resource_x_source_block_to_n(") - : NULL; + source_call + = ingress != NULL ? strstr(ingress, "gcs_block_pcm_x_resource_x_source_block_to_n(") : NULL; s_consumer = source_call != NULL - ? strstr(source_call, "cluster_pcm_lock_resource_x_block_to_n_exact(") - : NULL; + ? strstr(source_call, "cluster_pcm_lock_resource_x_block_to_n_exact(") + : NULL; UT_ASSERT_NOT_NULL(ingress); UT_ASSERT_NOT_NULL(source_call); UT_ASSERT_NOT_NULL(s_consumer); @@ -3866,18 +3715,16 @@ UT_TEST(test_resource_x_type17_x_source_fences_before_retained_release) builder = strstr(source, "\ngcs_block_pcm_x_resource_x_build_source_frames("); UT_ASSERT_NOT_NULL(builder); if (builder != NULL) { - UT_ASSERT_NOT_NULL(strstr(builder, - "requester_target_generation = block->common.assertion_sequence")); - UT_ASSERT_NOT_NULL(strstr(builder, - "source_proof_crc32c = image->common.semantic_crc32c")); + UT_ASSERT_NOT_NULL( + strstr(builder, "requester_target_generation = block->common.assertion_sequence")); + UT_ASSERT_NOT_NULL(strstr(builder, "source_proof_crc32c = image->common.semantic_crc32c")); } abort = strstr(source, "\ngcs_block_pcm_x_resource_x_abort_pre_arm("); arm = strstr(source, "cluster_pcm_lock_resource_x_block_to_n_source_exact("); UT_ASSERT_NOT_NULL(abort); UT_ASSERT_NOT_NULL(arm); if (abort != NULL) - UT_ASSERT_NOT_NULL(strstr(abort, - "cluster_bufmgr_pcm_own_abort_x_revoke(")); + UT_ASSERT_NOT_NULL(strstr(abort, "cluster_bufmgr_pcm_own_abort_x_revoke(")); free(source); } @@ -3892,48 +3739,38 @@ UT_TEST(test_resource_x_type17_early_stale_records_exact_failure_stage) UT_ASSERT_NOT_NULL(source); if (source == NULL) return; - helper = strstr(source, - "\ngcs_block_pcm_x_resource_x_source_block_to_n("); - helper_end = helper != NULL - ? strstr(helper, "\n\n/* Consume the exact Resource-X subdomain") - : NULL; + helper = strstr(source, "\ngcs_block_pcm_x_resource_x_source_block_to_n("); + helper_end + = helper != NULL ? strstr(helper, "\n\n/* Consume the exact Resource-X subdomain") : NULL; UT_ASSERT_NOT_NULL(helper); UT_ASSERT_NOT_NULL(helper_end); if (helper != NULL && helper_end != NULL) { - UT_ASSERT_NOT_NULL(strstr(helper, - "failure_stage = \"gate-session\";")); - UT_ASSERT_NOT_NULL(strstr(helper, - "failure_stage = \"retained-image\";")); - UT_ASSERT_NOT_NULL(strstr(helper, - "failure_stage = \"retained-pair-domain\";")); - UT_ASSERT_NOT_NULL(strstr(helper, - "failure_stage = \"writer-path\";")); - UT_ASSERT_NULL(strstr(helper, - "return image_result == RESOURCE_X_APPLY_NOT_FOUND")); + UT_ASSERT_NOT_NULL(strstr(helper, "failure_stage = \"gate-session\";")); + UT_ASSERT_NOT_NULL(strstr(helper, "failure_stage = \"retained-image\";")); + UT_ASSERT_NOT_NULL(strstr(helper, "failure_stage = \"retained-pair-domain\";")); + UT_ASSERT_NOT_NULL(strstr(helper, "failure_stage = \"writer-path\";")); + UT_ASSERT_NULL(strstr(helper, "return image_result == RESOURCE_X_APPLY_NOT_FOUND")); } ingress = strstr(source, "\ngcs_block_resource_x_type17_ingress("); - ingress_end = ingress != NULL - ? strstr(ingress, "\n\n/* PGRAC adaptation: kind-9") : NULL; + ingress_end = ingress != NULL ? strstr(ingress, "\n\n/* PGRAC adaptation: kind-9") : NULL; UT_ASSERT_NOT_NULL(ingress); UT_ASSERT_NOT_NULL(ingress_end); if (ingress != NULL && ingress_end != NULL) { UT_ASSERT_NOT_NULL(strstr(ingress, "peer_exact =")); - UT_ASSERT_NOT_NULL(strstr(ingress, - "peer_check = cluster_semantic_activation_resource_x_peer_open_check(")); + UT_ASSERT_NOT_NULL(strstr( + ingress, "peer_check = cluster_semantic_activation_resource_x_peer_open_check(")); UT_ASSERT_NOT_NULL(strstr(ingress, "gate_exact =")); UT_ASSERT_NOT_NULL(strstr(ingress, "master_exact =")); UT_ASSERT_NOT_NULL(strstr(ingress, "formation_exact =")); UT_ASSERT_NOT_NULL(strstr(ingress, "session_exact =")); UT_ASSERT_NOT_NULL(strstr(ingress, "admission_exact =")); - UT_ASSERT_NOT_NULL(strstr(ingress, - "Resource-X type-17 ingress predicate diagnostic")); + UT_ASSERT_NOT_NULL(strstr(ingress, "Resource-X type-17 ingress predicate diagnostic")); UT_ASSERT_NOT_NULL(strstr(ingress, "peer_check=%d")); UT_ASSERT_NOT_NULL(strstr(ingress, "gate_snapshot=%s")); UT_ASSERT_NOT_NULL(strstr(ingress, "gate_phase=%u")); UT_ASSERT_NOT_NULL(strstr(ingress, "lookup_master=%d")); UT_ASSERT_NOT_NULL(strstr(ingress, "session_check=%d")); - UT_ASSERT_NOT_NULL(strstr(ingress, - "gcs_block_pcm_x_authenticated_session_result(")); + UT_ASSERT_NOT_NULL(strstr(ingress, "gcs_block_pcm_x_authenticated_session_result(")); } free(source); } @@ -3958,20 +3795,16 @@ UT_TEST(test_resource_x_type17_x_source_separates_wire_and_local_fence_formation UT_ASSERT_NOT_NULL(source); if (source == NULL) return; - assert_ordered_in_function( - source, "\ngcs_block_pcm_x_resource_x_source_block_to_n(", - "\n\n/* Install the exact retained remote carrier", dual_domain_contract, - lengthof(dual_domain_contract)); - helper = strstr(source, - "\ngcs_block_pcm_x_resource_x_source_block_to_n("); - helper_end = helper != NULL - ? strstr(helper, "\n\n/* Install the exact retained remote carrier") - : NULL; + assert_ordered_in_function(source, "\ngcs_block_pcm_x_resource_x_source_block_to_n(", + "\n\n/* Install the exact retained remote carrier", + dual_domain_contract, lengthof(dual_domain_contract)); + helper = strstr(source, "\ngcs_block_pcm_x_resource_x_source_block_to_n("); + helper_end = helper != NULL ? strstr(helper, "\n\n/* Install the exact retained remote carrier") + : NULL; UT_ASSERT_NOT_NULL(helper); UT_ASSERT_NOT_NULL(helper_end); if (helper != NULL && helper_end != NULL) { - const char *legacy_fence = strstr(helper, - "cluster_pcm_x_local_writer_revoke_fence_"); + const char *legacy_fence = strstr(helper, "cluster_pcm_x_local_writer_revoke_fence_"); UT_ASSERT(legacy_fence == NULL || legacy_fence >= helper_end); } @@ -4005,41 +3838,43 @@ UT_TEST(test_resource_x_type17_target_x_after_l3_uses_no_legacy_shell) UT_ASSERT_NOT_NULL(source); if (source == NULL) return; - assert_ordered_in_function( - source, "\ngcs_block_pcm_x_resource_x_source_block_to_n(", - "\n\n/* Install the exact retained remote carrier", tagless_contract, - lengthof(tagless_contract)); - helper = strstr(source, - "\ngcs_block_pcm_x_resource_x_source_block_to_n("); - helper_end = helper != NULL - ? strstr(helper, "\n\n/* Install the exact retained remote carrier") - : NULL; - legacy_shell = helper != NULL - ? strstr(helper, "pcm_x_allocator_reserve_locked(") : NULL; + assert_ordered_in_function(source, "\ngcs_block_pcm_x_resource_x_source_block_to_n(", + "\n\n/* Install the exact retained remote carrier", tagless_contract, + lengthof(tagless_contract)); + helper = strstr(source, "\ngcs_block_pcm_x_resource_x_source_block_to_n("); + helper_end = helper != NULL ? strstr(helper, "\n\n/* Install the exact retained remote carrier") + : NULL; + legacy_shell = helper != NULL ? strstr(helper, "pcm_x_allocator_reserve_locked(") : NULL; UT_ASSERT_NOT_NULL(helper); UT_ASSERT_NOT_NULL(helper_end); - lineage_first = helper != NULL ? strstr(helper, - "cluster_pcm_lock_resource_x_bootstrap_round_terminal_holder_exact(") - : NULL; - lineage_second = lineage_first != NULL ? strstr(lineage_first + 1, - "cluster_pcm_lock_resource_x_terminal_x_revoke_revalidate_held_exact(") - : NULL; - lineage_third = lineage_second != NULL ? strstr(lineage_second + 1, - "cluster_pcm_lock_resource_x_terminal_x_revoke_revalidate_held_exact(") - : NULL; - lineage_fourth = lineage_third != NULL ? strstr(lineage_third + 1, - "cluster_pcm_lock_resource_x_terminal_x_revoke_revalidate_held_exact(") - : NULL; + lineage_first + = helper != NULL + ? strstr(helper, "cluster_pcm_lock_resource_x_bootstrap_round_terminal_holder_exact(") + : NULL; + lineage_second + = lineage_first != NULL + ? strstr(lineage_first + 1, + "cluster_pcm_lock_resource_x_terminal_x_revoke_revalidate_held_exact(") + : NULL; + lineage_third + = lineage_second != NULL + ? strstr(lineage_second + 1, + "cluster_pcm_lock_resource_x_terminal_x_revoke_revalidate_held_exact(") + : NULL; + lineage_fourth + = lineage_third != NULL + ? strstr(lineage_third + 1, + "cluster_pcm_lock_resource_x_terminal_x_revoke_revalidate_held_exact(") + : NULL; UT_ASSERT_NOT_NULL(lineage_first); UT_ASSERT_NOT_NULL(lineage_second); if (lineage_second != NULL && helper_end != NULL) UT_ASSERT(lineage_second < helper_end); UT_ASSERT(lineage_third == NULL || lineage_third >= helper_end); UT_ASSERT(lineage_fourth == NULL || lineage_fourth >= helper_end); - UT_ASSERT_NOT_NULL(strstr(helper, - "cluster_bufmgr_pcm_own_abort_held_x_revoke(")); - UT_ASSERT_NOT_NULL(strstr(helper, - "cluster_bufmgr_pcm_own_abandon_held_x_revoke_after_fail_closed(")); + UT_ASSERT_NOT_NULL(strstr(helper, "cluster_bufmgr_pcm_own_abort_held_x_revoke(")); + UT_ASSERT_NOT_NULL( + strstr(helper, "cluster_bufmgr_pcm_own_abandon_held_x_revoke_after_fail_closed(")); if (legacy_shell != NULL && helper_end != NULL) UT_ASSERT(legacy_shell >= helper_end); free(source); @@ -4061,27 +3896,25 @@ UT_TEST(test_resource_x_type17_target_x_uses_fork_exact_revoke_finish) UT_ASSERT_NOT_NULL(source); if (source == NULL) return; - helper = strstr(source, - "\ngcs_block_pcm_x_resource_x_source_block_to_n("); - helper_end = helper != NULL - ? strstr(helper, "\n\n/* Install the exact retained remote carrier") - : NULL; - finish_mode = helper != NULL - ? strstr(helper, "target_x_finish_mode =\n\t\t\tcluster_pcm_x_revoke_finish_mode(") - : NULL; - retain_branch = finish_mode != NULL - ? strstr(finish_mode, "if (target_x_retain) {") : NULL; + helper = strstr(source, "\ngcs_block_pcm_x_resource_x_source_block_to_n("); + helper_end = helper != NULL ? strstr(helper, "\n\n/* Install the exact retained remote carrier") + : NULL; + finish_mode + = helper != NULL + ? strstr(helper, "target_x_finish_mode\n\t\t\t= cluster_pcm_x_revoke_finish_mode(") + : NULL; + retain_branch = finish_mode != NULL ? strstr(finish_mode, "if (target_x_retain) {") : NULL; held_begin = retain_branch != NULL - ? strstr(retain_branch, - "cluster_bufmgr_pcm_own_begin_x_revoke_held_by_tag(") : NULL; - drop_branch = held_begin != NULL - ? strstr(held_begin, "else if (target_x_drop)") : NULL; + ? strstr(retain_branch, "cluster_bufmgr_pcm_own_begin_x_revoke_held_by_tag(") + : NULL; + drop_branch = held_begin != NULL ? strstr(held_begin, "else if (target_x_drop)") : NULL; ordinary_begin = drop_branch != NULL - ? strstr(drop_branch, "cluster_bufmgr_pcm_own_begin_x_revoke(") : NULL; + ? strstr(drop_branch, "cluster_bufmgr_pcm_own_begin_x_revoke(") + : NULL; content_drain = ordinary_begin != NULL - ? strstr(ordinary_begin, - "if (tagless_target_x && target_x_retain && !semantic_retained)") - : NULL; + ? strstr(ordinary_begin, + "if (tagless_target_x && target_x_retain && !semantic_retained)") + : NULL; generic_finish = content_drain != NULL ? strstr(content_drain, "return gcs_block_resource_x_source_finish_owned(") : NULL; @@ -4095,13 +3928,13 @@ UT_TEST(test_resource_x_type17_target_x_uses_fork_exact_revoke_finish) UT_ASSERT_NOT_NULL(ordinary_begin); UT_ASSERT_NOT_NULL(content_drain); UT_ASSERT_NOT_NULL(generic_finish); - if (helper_end != NULL && finish_mode != NULL && retain_branch != NULL - && held_begin != NULL && drop_branch != NULL && ordinary_begin != NULL - && content_drain != NULL && generic_finish != NULL) { - UT_ASSERT(helper < finish_mode && finish_mode < retain_branch - && retain_branch < held_begin && held_begin < drop_branch - && drop_branch < ordinary_begin && ordinary_begin < content_drain - && content_drain < generic_finish && generic_finish < helper_end); + if (helper_end != NULL && finish_mode != NULL && retain_branch != NULL && held_begin != NULL + && drop_branch != NULL && ordinary_begin != NULL && content_drain != NULL + && generic_finish != NULL) { + UT_ASSERT(helper < finish_mode && finish_mode < retain_branch && retain_branch < held_begin + && held_begin < drop_branch && drop_branch < ordinary_begin + && ordinary_begin < content_drain && content_drain < generic_finish + && generic_finish < helper_end); } free(source); } @@ -4126,30 +3959,21 @@ UT_TEST(test_resource_x_type17_target_drains_before_semantic_retention) UT_ASSERT_NOT_NULL(source); if (source == NULL) return; - helper = strstr(source, - "\ngcs_block_pcm_x_resource_x_source_block_to_n("); - helper_end = helper != NULL - ? strstr(helper, "\n\n/* Install the exact retained remote carrier") - : NULL; - preflight = helper != NULL - ? strstr(helper, "cluster_bufmgr_pcm_own_try_drain_held_x_revoke(") - : NULL; - busy = preflight != NULL - ? strstr(preflight, "own_result == CLUSTER_PCM_OWN_BUSY") : NULL; - abort = busy != NULL - ? strstr(busy, "cluster_bufmgr_pcm_own_abort_held_x_revoke(") : NULL; + helper = strstr(source, "\ngcs_block_pcm_x_resource_x_source_block_to_n("); + helper_end = helper != NULL ? strstr(helper, "\n\n/* Install the exact retained remote carrier") + : NULL; + preflight + = helper != NULL ? strstr(helper, "cluster_bufmgr_pcm_own_try_drain_held_x_revoke(") : NULL; + busy = preflight != NULL ? strstr(preflight, "own_result == CLUSTER_PCM_OWN_BUSY") : NULL; + abort = busy != NULL ? strstr(busy, "cluster_bufmgr_pcm_own_abort_held_x_revoke(") : NULL; yield = abort != NULL - ? strstr(abort, - "cluster_pcm_lock_resource_x_terminal_x_revoke_yield_exact(") - : NULL; - retry_return = yield != NULL - ? strstr(yield, "return RESOURCE_X_APPLY_BAD_STATE;") : NULL; - copy = retry_return != NULL - ? strstr(retry_return, "cluster_bufmgr_copy_block_for_gcs(") : NULL; + ? strstr(abort, "cluster_pcm_lock_resource_x_terminal_x_revoke_yield_exact(") + : NULL; + retry_return = yield != NULL ? strstr(yield, "return RESOURCE_X_APPLY_BAD_STATE;") : NULL; + copy = retry_return != NULL ? strstr(retry_return, "cluster_bufmgr_copy_block_for_gcs(") : NULL; retain = copy != NULL - ? strstr(copy, - "cluster_pcm_lock_resource_x_block_to_n_prepared_x_source_exact(") - : NULL; + ? strstr(copy, "cluster_pcm_lock_resource_x_block_to_n_prepared_x_source_exact(") + : NULL; finish = retain != NULL ? strstr(retain, "return gcs_block_resource_x_source_finish_owned(") : NULL; @@ -4163,34 +3987,29 @@ UT_TEST(test_resource_x_type17_target_drains_before_semantic_retention) UT_ASSERT_NOT_NULL(copy); UT_ASSERT_NOT_NULL(retain); UT_ASSERT_NOT_NULL(finish); - if (helper_end != NULL && preflight != NULL && busy != NULL - && abort != NULL && yield != NULL && retry_return != NULL - && copy != NULL && retain != NULL && finish != NULL) { - UT_ASSERT(helper < preflight && preflight < busy && busy < abort - && abort < yield && yield < retry_return && retry_return < copy - && copy < retain && retain < finish && finish < helper_end); + if (helper_end != NULL && preflight != NULL && busy != NULL && abort != NULL && yield != NULL + && retry_return != NULL && copy != NULL && retain != NULL && finish != NULL) { + UT_ASSERT(helper < preflight && preflight < busy && busy < abort && abort < yield + && yield < retry_return && retry_return < copy && copy < retain && retain < finish + && finish < helper_end); UT_ASSERT(strstr(preflight, "pg_usleep(") == NULL - || strstr(preflight, "pg_usleep(") >= helper_end); - UT_ASSERT(strstr(preflight, - "GCS_RESOURCE_X_TERMINAL_FINISH_ATTEMPTS") == NULL - || strstr(preflight, - "GCS_RESOURCE_X_TERMINAL_FINISH_ATTEMPTS") >= helper_end); + || strstr(preflight, "pg_usleep(") >= helper_end); + UT_ASSERT(strstr(preflight, "GCS_RESOURCE_X_TERMINAL_FINISH_ATTEMPTS") == NULL + || strstr(preflight, "GCS_RESOURCE_X_TERMINAL_FINISH_ATTEMPTS") >= helper_end); forbidden = strstr(preflight, "LWLockAcquire("); UT_ASSERT(forbidden == NULL || forbidden >= helper_end); forbidden = strstr(preflight, "LWLockAcquireOrWait("); UT_ASSERT(forbidden == NULL || forbidden >= helper_end); - forbidden = strstr(busy, - "cluster_pcm_lock_resource_x_block_to_n_prepared_x_source_exact("); + forbidden = strstr(busy, "cluster_pcm_lock_resource_x_block_to_n_prepared_x_source_exact("); UT_ASSERT(forbidden == NULL || forbidden >= retry_return); - forbidden = strstr(busy, - "cluster_pcm_lock_resource_x_holder_pair_publish_exact("); + forbidden = strstr(busy, "cluster_pcm_lock_resource_x_holder_pair_publish_exact("); UT_ASSERT(forbidden == NULL || forbidden >= retry_return); - second_yield = strstr(yield + 1, - "cluster_pcm_lock_resource_x_terminal_x_revoke_yield_exact("); + second_yield + = strstr(yield + 1, "cluster_pcm_lock_resource_x_terminal_x_revoke_yield_exact("); third_yield = second_yield != NULL - ? strstr(second_yield + 1, - "cluster_pcm_lock_resource_x_terminal_x_revoke_yield_exact(") - : NULL; + ? strstr(second_yield + 1, + "cluster_pcm_lock_resource_x_terminal_x_revoke_yield_exact(") + : NULL; UT_ASSERT_NOT_NULL(second_yield); UT_ASSERT(second_yield == NULL || second_yield < helper_end); UT_ASSERT(third_yield == NULL || third_yield >= helper_end); @@ -4218,42 +4037,34 @@ UT_TEST(test_resource_x_type17_aux_drop_drains_passive_pins_before_pair) UT_ASSERT_NOT_NULL(source); if (source == NULL) return; - helper = strstr(source, - "\ngcs_block_pcm_x_resource_x_source_block_to_n("); - helper_end = helper != NULL - ? strstr(helper, "\n\n/* Install the exact retained remote carrier") - : NULL; - drop_begin = helper != NULL - ? strstr(helper, "else if (target_x_drop)") : NULL; + helper = strstr(source, "\ngcs_block_pcm_x_resource_x_source_block_to_n("); + helper_end = helper != NULL ? strstr(helper, "\n\n/* Install the exact retained remote carrier") + : NULL; + drop_begin = helper != NULL ? strstr(helper, "else if (target_x_drop)") : NULL; drop_drain = drop_begin != NULL - ? strstr(drop_begin, - "cluster_bufmgr_pcm_own_try_drain_drop_x_revoke(") : NULL; - busy = drop_drain != NULL - ? strstr(drop_drain, "own_result == CLUSTER_PCM_OWN_BUSY") : NULL; - abort = busy != NULL - ? strstr(busy, "cluster_bufmgr_pcm_own_abort_x_revoke(") : NULL; + ? strstr(drop_begin, "cluster_bufmgr_pcm_own_try_drain_drop_x_revoke(") + : NULL; + busy = drop_drain != NULL ? strstr(drop_drain, "own_result == CLUSTER_PCM_OWN_BUSY") : NULL; + abort = busy != NULL ? strstr(busy, "cluster_bufmgr_pcm_own_abort_x_revoke(") : NULL; yield = abort != NULL - ? strstr(abort, - "cluster_pcm_lock_resource_x_terminal_x_revoke_yield_exact(") - : NULL; - retry_return = yield != NULL - ? strstr(yield, "return RESOURCE_X_APPLY_BAD_STATE;") : NULL; + ? strstr(abort, "cluster_pcm_lock_resource_x_terminal_x_revoke_yield_exact(") + : NULL; + retry_return = yield != NULL ? strstr(yield, "return RESOURCE_X_APPLY_BAD_STATE;") : NULL; pair = retry_return != NULL - ? strstr(retry_return, - "cluster_pcm_lock_resource_x_block_to_n_drop_x_source_exact(") - : NULL; + ? strstr(retry_return, "cluster_pcm_lock_resource_x_block_to_n_drop_x_source_exact(") + : NULL; finish = pair != NULL ? strstr(pair, "return gcs_block_resource_x_source_finish_owned(") : NULL; drop_close_branch = finish != NULL ? strstr(strstr(source, "\ngcs_block_resource_x_source_finish_owned("), "if (target_x_drop) {") : NULL; close_cover = drop_close_branch != NULL - ? strstr(drop_close_branch, - "cluster_pcm_lock_resource_x_terminal_x_revoke_finish_drop_exact(") - : NULL; + ? strstr(drop_close_branch, + "cluster_pcm_lock_resource_x_terminal_x_revoke_finish_drop_exact(") + : NULL; publish = close_cover != NULL - ? strstr(close_cover, - "cluster_pcm_lock_resource_x_holder_pair_publish_exact(") : NULL; + ? strstr(close_cover, "cluster_pcm_lock_resource_x_holder_pair_publish_exact(") + : NULL; UT_ASSERT_NOT_NULL(helper); UT_ASSERT_NOT_NULL(helper_end); @@ -4268,19 +4079,17 @@ UT_TEST(test_resource_x_type17_aux_drop_drains_passive_pins_before_pair) UT_ASSERT_NOT_NULL(drop_close_branch); UT_ASSERT_NOT_NULL(close_cover); UT_ASSERT_NOT_NULL(publish); - if (helper_end != NULL && drop_begin != NULL && drop_drain != NULL - && busy != NULL && abort != NULL && yield != NULL - && retry_return != NULL && pair != NULL && finish != NULL - && drop_close_branch != NULL && close_cover != NULL - && publish != NULL) { + if (helper_end != NULL && drop_begin != NULL && drop_drain != NULL && busy != NULL + && abort != NULL && yield != NULL && retry_return != NULL && pair != NULL && finish != NULL + && drop_close_branch != NULL && close_cover != NULL && publish != NULL) { UT_ASSERT(drop_begin < drop_drain && drop_drain < busy && busy < abort && abort < yield && yield < retry_return && retry_return < pair && pair < finish && finish < helper_end && drop_close_branch < close_cover && close_cover < publish && publish < helper); UT_ASSERT(strstr(drop_drain, "LWLockAcquire(") == NULL - || strstr(drop_drain, "LWLockAcquire(") >= retry_return); + || strstr(drop_drain, "LWLockAcquire(") >= retry_return); UT_ASSERT(strstr(drop_drain, "pg_usleep(") == NULL - || strstr(drop_drain, "pg_usleep(") >= retry_return); + || strstr(drop_drain, "pg_usleep(") >= retry_return); } free(source); } @@ -4305,57 +4114,47 @@ UT_TEST(test_resource_x_type17_selected_s_source_reuses_fenced_pair_core) const char *source_dispatch; const char *status_dispatch; - assert_ordered_in_function( - source, "\ngcs_block_pcm_x_resource_x_source_block_to_n(", - "\n\n/* Install the exact retained remote carrier", source_contract, - lengthof(source_contract)); + assert_ordered_in_function(source, "\ngcs_block_pcm_x_resource_x_source_block_to_n(", + "\n\n/* Install the exact retained remote carrier", source_contract, + lengthof(source_contract)); if (source != NULL) { - const char *helper = strstr( - source, "\ngcs_block_pcm_x_resource_x_source_block_to_n("); - const char *helper_end = helper != NULL - ? strstr(helper, "\n\n/* Install the exact retained remote carrier") - : NULL; - const char *legacy_fence = helper != NULL - ? strstr(helper, "cluster_pcm_x_local_writer_revoke_fence_") - : NULL; + const char *helper = strstr(source, "\ngcs_block_pcm_x_resource_x_source_block_to_n("); + const char *helper_end + = helper != NULL ? strstr(helper, "\n\n/* Install the exact retained remote carrier") + : NULL; + const char *legacy_fence + = helper != NULL ? strstr(helper, "cluster_pcm_x_local_writer_revoke_fence_") : NULL; UT_ASSERT_NOT_NULL(helper); UT_ASSERT_NOT_NULL(helper_end); UT_ASSERT(legacy_fence == NULL || legacy_fence >= helper_end); } - builder = strstr(source, - "\ngcs_block_pcm_x_resource_x_build_source_frames("); + builder = strstr(source, "\ngcs_block_pcm_x_resource_x_build_source_frames("); UT_ASSERT_NOT_NULL(builder); if (builder != NULL) { - UT_ASSERT_NOT_NULL(strstr(builder, - "revoking->pcm_state != source_mode")); - UT_ASSERT_NOT_NULL(strstr(builder, - "image->common.observed_mode = source_mode")); - UT_ASSERT_NOT_NULL(strstr(builder, - "image_body->source_fence[28] = source_mode")); + UT_ASSERT_NOT_NULL(strstr(builder, "revoking->pcm_state != source_mode")); + UT_ASSERT_NOT_NULL(strstr(builder, "image->common.observed_mode = source_mode")); + UT_ASSERT_NOT_NULL(strstr(builder, "image_body->source_fence[28] = source_mode")); } abort = strstr(source, "\ngcs_block_pcm_x_resource_x_abort_pre_arm("); UT_ASSERT_NOT_NULL(abort); if (abort != NULL) { - UT_ASSERT_NOT_NULL(strstr(abort, - "cluster_bufmgr_pcm_own_abort_s_revoke(")); - UT_ASSERT_NOT_NULL(strstr(abort, - "cluster_bufmgr_pcm_own_abort_x_revoke(")); + UT_ASSERT_NOT_NULL(strstr(abort, "cluster_bufmgr_pcm_own_abort_s_revoke(")); + UT_ASSERT_NOT_NULL(strstr(abort, "cluster_bufmgr_pcm_own_abort_x_revoke(")); } ingress = strstr(source, "\ngcs_block_try_resource_x_frame("); - type17_ingress = strstr(source, - "\ngcs_block_resource_x_type17_ingress("); + type17_ingress = strstr(source, "\ngcs_block_resource_x_type17_ingress("); UT_ASSERT_NOT_NULL(ingress); UT_ASSERT_NOT_NULL(type17_ingress); if (ingress != NULL) - UT_ASSERT_NOT_NULL(strstr(ingress, - "gcs_block_resource_x_type17_ingress(")); + UT_ASSERT_NOT_NULL(strstr(ingress, "gcs_block_resource_x_type17_ingress(")); source_dispatch = type17_ingress != NULL - ? strstr(type17_ingress, - "gcs_block_pcm_x_resource_x_source_block_to_n(") : NULL; - status_dispatch = type17_ingress != NULL - ? strstr(type17_ingress, - "gcs_block_pcm_x_resource_x_remote_s_holder_block_to_n(") : NULL; + ? strstr(type17_ingress, "gcs_block_pcm_x_resource_x_source_block_to_n(") + : NULL; + status_dispatch + = type17_ingress != NULL + ? strstr(type17_ingress, "gcs_block_pcm_x_resource_x_remote_s_holder_block_to_n(") + : NULL; UT_ASSERT_NOT_NULL(source_dispatch); UT_ASSERT_NOT_NULL(status_dispatch); if (source_dispatch != NULL && status_dispatch != NULL) @@ -4387,61 +4186,49 @@ UT_TEST(test_resource_x_type17_remote_s_holder_uses_exact_buffer_evidence) const char *remote_call; const char *master_entry_call; - assert_ordered_in_function( - source, "\ngcs_block_pcm_x_resource_x_remote_s_holder_block_to_n(", - "\n\nstatic bool\ngcs_block_resource_x_target_peer_matches_exact(", - holder_contract, - lengthof(holder_contract)); - helper = strstr(source, - "\ngcs_block_pcm_x_resource_x_remote_s_holder_block_to_n("); - helper_end = helper != NULL - ? strstr(helper, - "\n\nstatic bool\ngcs_block_resource_x_target_peer_matches_exact(") - : NULL; + assert_ordered_in_function(source, "\ngcs_block_pcm_x_resource_x_remote_s_holder_block_to_n(", + "\n\nstatic bool\ngcs_block_resource_x_target_peer_matches_exact(", + holder_contract, lengthof(holder_contract)); + helper = strstr(source, "\ngcs_block_pcm_x_resource_x_remote_s_holder_block_to_n("); + helper_end + = helper != NULL + ? strstr(helper, "\n\nstatic bool\ngcs_block_resource_x_target_peer_matches_exact(") + : NULL; UT_ASSERT_NOT_NULL(helper); UT_ASSERT_NOT_NULL(helper_end); if (helper != NULL && helper_end != NULL) { forbidden = strstr(helper, "pcm_get_or_create_entry("); UT_ASSERT(forbidden == NULL || forbidden >= helper_end); - forbidden = strstr(helper, - "cluster_pcm_lock_resource_x_block_to_n_exact("); + forbidden = strstr(helper, "cluster_pcm_lock_resource_x_block_to_n_exact("); UT_ASSERT(forbidden == NULL || forbidden >= helper_end); - forbidden = strstr(helper, - "cluster_lms_outbound_enqueue_resource_x_remote_s_status_exact("); + forbidden + = strstr(helper, "cluster_lms_outbound_enqueue_resource_x_remote_s_status_exact("); UT_ASSERT(forbidden == NULL || forbidden >= helper_end); - UT_ASSERT_NOT_NULL(strstr(helper, - "cluster_lms_outbound_cancel_resource_x_remote_s_status_exact(")); - UT_ASSERT_NOT_NULL(strstr(helper, - "cluster_bufmgr_pcm_own_abort_s_revoke(")); + UT_ASSERT_NOT_NULL( + strstr(helper, "cluster_lms_outbound_cancel_resource_x_remote_s_status_exact(")); + UT_ASSERT_NOT_NULL(strstr(helper, "cluster_bufmgr_pcm_own_abort_s_revoke(")); } ingress = strstr(source, "\ngcs_block_try_resource_x_frame("); - type17_ingress = strstr(source, - "\ngcs_block_resource_x_type17_ingress("); + type17_ingress = strstr(source, "\ngcs_block_resource_x_type17_ingress("); UT_ASSERT_NOT_NULL(ingress); UT_ASSERT_NOT_NULL(type17_ingress); if (ingress != NULL) - UT_ASSERT_NOT_NULL(strstr(ingress, - "gcs_block_resource_x_type17_ingress(")); + UT_ASSERT_NOT_NULL(strstr(ingress, "gcs_block_resource_x_type17_ingress(")); if (type17_ingress != NULL) { - UT_ASSERT_NOT_NULL(strstr(type17_ingress, - "cluster_semantic_activation_enter(")); - UT_ASSERT_NOT_NULL(strstr(type17_ingress, - "gcs_block_resource_x_target_peer_matches_exact(")); - UT_ASSERT_NOT_NULL(strstr(type17_ingress, - "gcs_block_resource_x_gate_session_snapshot(")); - UT_ASSERT_NOT_NULL(strstr(type17_ingress, - "admission.record_generation")); - UT_ASSERT_NOT_NULL(strstr(type17_ingress, - "cluster_semantic_activation_leave(")); + UT_ASSERT_NOT_NULL(strstr(type17_ingress, "cluster_semantic_activation_enter(")); + UT_ASSERT_NOT_NULL( + strstr(type17_ingress, "gcs_block_resource_x_target_peer_matches_exact(")); + UT_ASSERT_NOT_NULL(strstr(type17_ingress, "gcs_block_resource_x_gate_session_snapshot(")); + UT_ASSERT_NOT_NULL(strstr(type17_ingress, "admission.record_generation")); + UT_ASSERT_NOT_NULL(strstr(type17_ingress, "cluster_semantic_activation_leave(")); } - remote_call = type17_ingress != NULL - ? strstr(type17_ingress, - "gcs_block_pcm_x_resource_x_remote_s_holder_block_to_n(") - : NULL; + remote_call + = type17_ingress != NULL + ? strstr(type17_ingress, "gcs_block_pcm_x_resource_x_remote_s_holder_block_to_n(") + : NULL; master_entry_call = remote_call != NULL - ? strstr(remote_call, - "cluster_pcm_lock_resource_x_block_to_n_exact(") - : NULL; + ? strstr(remote_call, "cluster_pcm_lock_resource_x_block_to_n_exact(") + : NULL; UT_ASSERT_NOT_NULL(remote_call); UT_ASSERT_NOT_NULL(master_entry_call); if (remote_call != NULL && master_entry_call != NULL) @@ -4462,21 +4249,20 @@ UT_TEST(test_resource_x_type17_stable_n_replay_is_zero_mutation_and_revalidated) "cluster_sf_peer_capability_record_snapshot(", "capability.generation != expected_connection" }; char *source = read_gcs_block_source(); - const char *holder = strstr(source, - "\ngcs_block_pcm_x_resource_x_remote_s_holder_block_to_n("); - const char *holder_end = holder != NULL - ? strstr(holder, - "\n\nstatic bool\ngcs_block_resource_x_target_peer_matches_exact(") - : NULL; - const char *stable_n = holder != NULL - ? strstr(holder, - "cluster_pcm_x_remote_s_holder_stable_n_result(") : NULL; - const char *n_candidate = stable_n != NULL - ? strstr(stable_n, - "cluster_bufmgr_pcm_own_n_assertion_candidate_exact(") : NULL; - const char *snapshot_failure = n_candidate != NULL - ? strstr(n_candidate, - "first_failure.buffer_own_result = (int32)own_result;") : NULL; + const char *holder = strstr(source, "\ngcs_block_pcm_x_resource_x_remote_s_holder_block_to_n("); + const char *holder_end + = holder != NULL + ? strstr(holder, "\n\nstatic bool\ngcs_block_resource_x_target_peer_matches_exact(") + : NULL; + const char *stable_n + = holder != NULL ? strstr(holder, "cluster_pcm_x_remote_s_holder_stable_n_result(") : NULL; + const char *n_candidate + = stable_n != NULL ? strstr(stable_n, "cluster_bufmgr_pcm_own_n_assertion_candidate_exact(") + : NULL; + const char *snapshot_failure + = n_candidate != NULL + ? strstr(n_candidate, "first_failure.buffer_own_result = (int32)own_result;") + : NULL; const char *authority_recheck = n_candidate != NULL ? strstr(n_candidate, "gcs_block_resource_x_remote_s_authority_result_exact(") @@ -4485,23 +4271,24 @@ UT_TEST(test_resource_x_type17_stable_n_replay_is_zero_mutation_and_revalidated) = authority_recheck != NULL ? strstr(authority_recheck, "gcs_block_pcm_x_resource_x_peer_ready_exact(") : NULL; - const char *sender_rebind = outbound_sample != NULL - ? strstr(outbound_sample, - "status.common.sender_connection_generation") : NULL; - const char *status_encode = sender_rebind != NULL - ? strstr(sender_rebind, "cluster_resource_x_wire_encode(") : NULL; - const char *status_enqueue = status_encode != NULL - ? strstr(status_encode, - "cluster_lms_outbound_enqueue_cap_bound(") : NULL; - const char *backpressure = status_enqueue != NULL - ? strstr(status_enqueue, "RESOURCE_X_APPLY_BAD_STATE") : NULL; - const char *applied = backpressure != NULL - ? strstr(backpressure, "return RESOURCE_X_APPLY_APPLIED;") : NULL; - const char *s_candidate = holder != NULL - ? strstr(holder, - "cluster_bufmgr_pcm_own_s_holder_candidate_exact(") : NULL; - const char *begin_revoke = holder != NULL - ? strstr(holder, "cluster_bufmgr_pcm_own_begin_s_revoke(") : NULL; + const char *sender_rebind + = outbound_sample != NULL + ? strstr(outbound_sample, "status.common.sender_connection_generation") + : NULL; + const char *status_encode + = sender_rebind != NULL ? strstr(sender_rebind, "cluster_resource_x_wire_encode(") : NULL; + const char *status_enqueue + = status_encode != NULL ? strstr(status_encode, "cluster_lms_outbound_enqueue_cap_bound(") + : NULL; + const char *backpressure + = status_enqueue != NULL ? strstr(status_enqueue, "RESOURCE_X_APPLY_BAD_STATE") : NULL; + const char *applied + = backpressure != NULL ? strstr(backpressure, "return RESOURCE_X_APPLY_APPLIED;") : NULL; + const char *s_candidate + = holder != NULL ? strstr(holder, "cluster_bufmgr_pcm_own_s_holder_candidate_exact(") + : NULL; + const char *begin_revoke + = holder != NULL ? strstr(holder, "cluster_bufmgr_pcm_own_begin_s_revoke(") : NULL; UT_ASSERT_NOT_NULL(holder); UT_ASSERT_NOT_NULL(holder_end); @@ -4550,98 +4337,83 @@ UT_TEST(test_resource_x_type17_stable_n_replay_is_zero_mutation_and_revalidated) UT_TEST(test_pcm_x_local_s_barrier_covers_active_and_exact_late_bind_head) { - static const char *const barrier_contract[] = { - "cluster_pcm_lock_resource_x_s_barrier_active(&tag)", - "return false", - "starvation_denied_pending_x_count" - }; + static const char *const barrier_contract[] + = { "cluster_pcm_lock_resource_x_s_barrier_active(&tag)", "return false", + "starvation_denied_pending_x_count" }; char *source = read_gcs_block_source(); - assert_ordered_in_function( - source, "\ncluster_gcs_block_resource_x_local_s_barrier_active(", - "\n\nstatic bool\ngcs_block_resource_x_payload_candidate(", - barrier_contract, lengthof(barrier_contract)); + assert_ordered_in_function(source, "\ncluster_gcs_block_resource_x_local_s_barrier_active(", + "\n\nstatic bool\ngcs_block_resource_x_payload_candidate(", + barrier_contract, lengthof(barrier_contract)); free(source); } UT_TEST(test_resource_x_s_barrier_closes_remote_registration_race) { - static const char *const ingress_contract[] = { - "resource_x_s_barrier_before =", - "cluster_gcs_block_resource_x_local_s_barrier_active(req->tag)", - "cluster_gcs_block_dedup_lookup_or_register(", - "resource_x_s_barrier_after =", - "cluster_gcs_block_resource_x_local_s_barrier_active(req->tag)", - "gcs_block_s_barrier_read_action_exact(", - "resource_x_s_barrier_before, resource_x_s_barrier_after", - "cluster_gcs_block_dedup_pending_x_deny_exact(" - }; + static const char *const ingress_contract[] + = { "resource_x_s_barrier_before =", + "cluster_gcs_block_resource_x_local_s_barrier_active(req->tag)", + "cluster_gcs_block_dedup_lookup_or_register(", + "resource_x_s_barrier_after =", + "cluster_gcs_block_resource_x_local_s_barrier_active(req->tag)", + "gcs_block_s_barrier_read_action_exact(", + "resource_x_s_barrier_before,\n\t\t\tresource_x_s_barrier_after", + "cluster_gcs_block_dedup_pending_x_deny_exact(" }; char *source = read_gcs_block_source(); - assert_ordered_in_function( - source, "\ncluster_gcs_handle_block_request_envelope(", - "\ncluster_gcs_handle_block_reply_envelope(", - ingress_contract, lengthof(ingress_contract)); + assert_ordered_in_function(source, "\ncluster_gcs_handle_block_request_envelope(", + "\ncluster_gcs_handle_block_reply_envelope(", ingress_contract, + lengthof(ingress_contract)); free(source); } UT_TEST(test_r4_tx_origin_epoch_zero_is_four_node_and_session_generation_exact) { - static const char *const accept_contract[] = { - "forward->base.epoch != env->epoch", - "forward->base.epoch != cluster_epoch_get_current()", - "forward->base.epoch == 0 && cluster_conf_node_count() != 4", - "cluster_sf_peer_capability_family_sample(", - "capability_generation == 0", - "cluster_semantic_activation_enter_r4_terminal_census(", - "cluster_semantic_activation_resolve_shared_undo_root_r4_terminal_census(", - "cluster_semantic_activation_recheck_r4_terminal_census(" - }; - static const char *const send_contract[] = { - "context->current_mx_request.prefix.original_requester_node", - "context->forward.base.original_requester_node", - "capability_current", - "cluster_epoch_get_current() != request_epoch", - "context->requester_capability_generation", - "gcs_block_r4_tx_origin_admission_current(context)" - }; - static const char *const drain_contract[] = { - "for (step_budget = 0;", - "phase_before = context->phase", - "gcs_block_r4_tx_origin_step(context)", - "!context->in_use || context->phase == phase_before" - }; + static const char *const accept_contract[] + = { "forward->base.epoch != env->epoch", + "forward->base.epoch != cluster_epoch_get_current()", + "forward->base.epoch == 0 && cluster_conf_node_count() != 4", + "cluster_sf_peer_capability_family_sample(", + "capability_generation == 0", + "cluster_semantic_activation_enter_r4_terminal_census(", + "cluster_semantic_activation_resolve_shared_undo_root_r4_terminal_census(", + "cluster_semantic_activation_recheck_r4_terminal_census(" }; + static const char *const send_contract[] + = { "context->current_mx_request.prefix.original_requester_node", + "context->forward.base.original_requester_node", + "capability_current", + "cluster_epoch_get_current() != request_epoch", + "context->requester_capability_generation", + "gcs_block_r4_tx_origin_admission_current(context)" }; + static const char *const drain_contract[] + = { "for (step_budget = 0;", "phase_before = context->phase", + "gcs_block_r4_tx_origin_step(context)", + "!context->in_use || context->phase == phase_before" }; char *source = read_gcs_block_source(); - assert_ordered_in_function( - source, "\ngcs_block_r4_tx_origin_try_accept(", - "\nstatic bool\ngcs_block_r4_tx_origin_resolution_valid(", - accept_contract, lengthof(accept_contract)); - UT_ASSERT_NULL(strstr(source, - "forward->base.epoch == 0 && admission.record_generation != 0")); - assert_ordered_in_function( - source, "\ngcs_block_r4_tx_origin_step(", - "\nvoid\ncluster_gcs_block_r4_tx_resolve_drain(", - send_contract, lengthof(send_contract)); - assert_ordered_in_function( - source, "\ncluster_gcs_block_r4_tx_resolve_drain(", - "\nstatic void\ngcs_block_send_reply(", - drain_contract, lengthof(drain_contract)); + assert_ordered_in_function(source, "\ngcs_block_r4_tx_origin_try_accept(", + "\nstatic bool\ngcs_block_r4_tx_origin_resolution_valid(", + accept_contract, lengthof(accept_contract)); + UT_ASSERT_NULL(strstr(source, "forward->base.epoch == 0 && admission.record_generation != 0")); + assert_ordered_in_function(source, "\ngcs_block_r4_tx_origin_step(", + "\nvoid\ncluster_gcs_block_r4_tx_resolve_drain(", send_contract, + lengthof(send_contract)); + assert_ordered_in_function(source, "\ncluster_gcs_block_r4_tx_resolve_drain(", + "\nstatic void\ngcs_block_send_reply(", drain_contract, + lengthof(drain_contract)); free(source); } UT_TEST(test_r4_tx_origin_pending_work_uses_bounded_lms_poll_slice) { - static const char *const lms_contract[] = { - "cluster_lms_cr_drain()", - "cluster_gcs_block_r4_tx_resolve_wait_timeout(LMS_IDLE_TIMEOUT_MS)", - "cluster_lms_data_plane_tick(lms_wait_timeout_ms)" - }; - static const char *const data_worker_contract[] = { - "cluster_gcs_block_r4_tx_resolve_drain()", - "cluster_gcs_block_r4_tx_resolve_wait_timeout(LMS_IDLE_TIMEOUT_MS)", - "cluster_lms_data_plane_tick(lms_wait_timeout_ms)" - }; + static const char *const lms_contract[] + = { "cluster_lms_cr_drain()", + "cluster_gcs_block_r4_tx_resolve_wait_timeout(LMS_IDLE_TIMEOUT_MS)", + "cluster_lms_data_plane_tick(lms_wait_timeout_ms)" }; + static const char *const data_worker_contract[] + = { "cluster_gcs_block_r4_tx_resolve_drain()", + "cluster_gcs_block_r4_tx_resolve_wait_timeout(LMS_IDLE_TIMEOUT_MS)", + "cluster_lms_data_plane_tick(lms_wait_timeout_ms)" }; char *source = read_source_path(LMS_SOURCE_PATH); const char *worker_start; const char *worker_end; @@ -4654,162 +4426,138 @@ UT_TEST(test_r4_tx_origin_pending_work_uses_bounded_lms_poll_slice) UT_ASSERT_EQ(cluster_gcs_block_r4_tx_resolve_wait_timeout_for_count(100, 1), 1); UT_ASSERT_EQ(cluster_gcs_block_r4_tx_resolve_wait_timeout_for_count(100, 4), 1); assert_ordered_in_function( - source, "\nLmsMain(", "\n\n/* ============================================================", - lms_contract, lengthof(lms_contract)); + source, "\nLmsMain(", + "\n\n/* ============================================================", lms_contract, + lengthof(lms_contract)); /* Current-MX proof requests are sharded across every DATA worker. Each * process owns its own nonblocking origin contexts and must drive them. */ worker_start = strstr(source, "\nLmsWorkerMain("); UT_ASSERT_NOT_NULL(worker_start); worker_end = worker_start != NULL - ? strstr(worker_start, "\n\npid_t\ncluster_lms_get_worker_pid(") : NULL; + ? strstr(worker_start, "\n\npid_t\ncluster_lms_get_worker_pid(") + : NULL; UT_ASSERT_NOT_NULL(worker_end); - worker_drain = worker_start != NULL - ? strstr(worker_start, data_worker_contract[0]) : NULL; + worker_drain = worker_start != NULL ? strstr(worker_start, data_worker_contract[0]) : NULL; UT_ASSERT_NOT_NULL(worker_drain); - if (worker_drain != NULL && worker_end != NULL) - { + if (worker_drain != NULL && worker_end != NULL) { UT_ASSERT(worker_drain < worker_end); - assert_ordered_in_function( - source, "\nLmsWorkerMain(", - "\n\npid_t\ncluster_lms_get_worker_pid(", - data_worker_contract, lengthof(data_worker_contract)); + assert_ordered_in_function(source, "\nLmsWorkerMain(", + "\n\npid_t\ncluster_lms_get_worker_pid(", data_worker_contract, + lengthof(data_worker_contract)); } free(source); } UT_TEST(test_pcm_x_finish_flush_reload_ack_is_target_exact_after_sighup) { - static const char *const reload_contract[] = { - "static bool initialized = false", - "static char *was_value = NULL", - "static char *was_target = NULL", - "value = cluster_injection_points != NULL", - "target = cluster_pcm_x_retain_flush_error_target != NULL", - "strcmp(value, was_value) == 0", - "strcmp(target, was_target) == 0", - "injection config: pid=%d armed=%s value=", - "target=", - "MemoryContextStrdup(TopMemoryContext, value)", - "MemoryContextStrdup(TopMemoryContext, target)", - "was_armed = armed", - "initialized = true" - }; - static const char *const apply_contract[] = { - "ProcessConfigFile(PGC_SIGHUP)", - "lms_note_pcm_x_finish_flush_injection_reload(0)" - }; - static const char *const worker_apply_contract[] = { - "ProcessConfigFile(PGC_SIGHUP)", - "lms_note_pcm_x_finish_flush_injection_reload(worker_id)" - }; + static const char *const reload_contract[] + = { "static bool initialized = false", + "static char *was_value = NULL", + "static char *was_target = NULL", + "value = cluster_injection_points != NULL", + "target = cluster_pcm_x_retain_flush_error_target != NULL", + "strcmp(value, was_value) == 0", + "strcmp(target, was_target) == 0", + "injection config: pid=%d armed=%s value=", + "target=", + "MemoryContextStrdup(TopMemoryContext, value)", + "MemoryContextStrdup(TopMemoryContext, target)", + "was_armed = armed", + "initialized = true" }; + static const char *const apply_contract[] + = { "ProcessConfigFile(PGC_SIGHUP)", "lms_note_pcm_x_finish_flush_injection_reload(0)" }; + static const char *const worker_apply_contract[] + = { "ProcessConfigFile(PGC_SIGHUP)", + "lms_note_pcm_x_finish_flush_injection_reload(worker_id)" }; char *source = read_source_path(LMS_SOURCE_PATH); /* The acknowledgement is evidence that this process applied both the * injection list and exact target. A repeated armed bit with a different * target/value must emit again, and both DATA-worker loops can acknowledge * only after their SIGHUP configuration load returns. */ + assert_ordered_in_function(source, "\nlms_note_pcm_x_finish_flush_injection_reload(", + "\n\nvoid\nLmsMain(", reload_contract, lengthof(reload_contract)); assert_ordered_in_function( - source, "\nlms_note_pcm_x_finish_flush_injection_reload(", - "\n\nvoid\nLmsMain(", reload_contract, lengthof(reload_contract)); - assert_ordered_in_function( - source, "\nLmsMain(", "\n\n/* ============================================================", - apply_contract, lengthof(apply_contract)); - assert_ordered_in_function( - source, "\nLmsWorkerMain(", "\n\npid_t\ncluster_lms_get_worker_pid(", - worker_apply_contract, lengthof(worker_apply_contract)); + source, "\nLmsMain(", + "\n\n/* ============================================================", apply_contract, + lengthof(apply_contract)); + assert_ordered_in_function(source, "\nLmsWorkerMain(", "\n\npid_t\ncluster_lms_get_worker_pid(", + worker_apply_contract, lengthof(worker_apply_contract)); free(source); } UT_TEST(test_current_mx_member_proof_reuses_nonblocking_target_origin_context) { - static const char *const demux_contract[] = { - "GcsBlockForwardPayloadIsCurrentMxMemberProof(routing)", - "gcs_block_current_mx_origin_try_accept(env, payload)", - "cluster_gcs_current_mx_member_proof_serve_inline(env, payload)" - }; - static const char *const accept_contract[] = { - "cluster_multixact_current_wire_validate_proof_forward(", - "cluster_semantic_activation_enter(", - "CLUSTER_SEMANTIC_TARGET_SIDE", - "gcs_block_current_mx_origin_locate_physical(", - "GCS_BLOCK_R4_TX_ORIGIN_TT_ACQUIRE_BEGIN" - }; - static const char *const locator_contract[] = { - "cluster_tt_slot_current_owner_by_xid(", - "cluster_tt_slot_durable_locate_any_by_xid_origin(" - }; - static const char *const step_contract[] = { - "cluster_undo_block0_current_acquire_begin_admitted(", - "cluster_undo_block0_current_acquire_poll(", - "gcs_block_current_mx_origin_sample_held(context)", - "cluster_undo_block0_current_release_begin(", - "cluster_undo_block0_current_release_poll(" - }; - static const char *const sample_contract[] = { - "context->current_mx_sampled_bitmap", - "context->current_mx_locators[i].segment_id", - "context->tt_logical.segment_id", - "cluster_runtime_visibility_physical_locator_sample_held(", - "cluster_multixact_current_resolve_origin_member_proof(", - "cluster_ctrc_origin_touch_exact(", - "&context->current_mx_requester_identity", - "ClusterCurrentMemberProofSetCtrcGrant(" - }; - static const char *const advance_contract[] = { - "context->current_mx_sampled_bitmap", - "context->current_mx_locators[i].segment_id", - "gcs_block_r4_tx_origin_resolve_root_current(", - "context->current_mx_result = CMX_RESOLVE_OK" - }; - static const char *const capability_carrier_contract[] = { - "gcs_block_current_mx_requester_identity_current(context)", - "context->current_mx_requester_identity.capability_record_generation", - "cluster_cr_server_current_mx_build_proof_page(" - }; - static const char *const send_worker_contract[] = { - "gcs_block_r4_tx_origin_worker_current(context)", - "gcs_block_current_mx_origin_prepare_reply(context)", - "gcs_block_send_envelope_or_loopback(" - }; + static const char *const demux_contract[] + = { "GcsBlockForwardPayloadIsCurrentMxMemberProof(routing)", + "gcs_block_current_mx_origin_try_accept(env, payload)", + "cluster_gcs_current_mx_member_proof_serve_inline(env, payload)" }; + static const char *const accept_contract[] + = { "cluster_multixact_current_wire_validate_proof_forward(", + "cluster_semantic_activation_enter(", "CLUSTER_SEMANTIC_TARGET_SIDE", + "gcs_block_current_mx_origin_locate_physical(", + "GCS_BLOCK_R4_TX_ORIGIN_TT_ACQUIRE_BEGIN" }; + static const char *const locator_contract[] + = { "cluster_tt_slot_current_owner_by_xid(", + "cluster_tt_slot_durable_locate_any_by_xid_origin(" }; + static const char *const step_contract[] + = { "cluster_undo_block0_current_acquire_begin_admitted(", + "cluster_undo_block0_current_acquire_poll(", + "gcs_block_current_mx_origin_sample_held(context)", + "cluster_undo_block0_current_release_begin(", + "cluster_undo_block0_current_release_poll(" }; + static const char *const sample_contract[] + = { "context->current_mx_sampled_bitmap", + "context->current_mx_locators[i].segment_id", + "context->tt_logical.segment_id", + "cluster_runtime_visibility_physical_locator_sample_held(", + "cluster_multixact_current_resolve_origin_member_proof(", + "cluster_ctrc_origin_touch_exact(", + "&context->current_mx_requester_identity", + "ClusterCurrentMemberProofSetCtrcGrant(" }; + static const char *const advance_contract[] + = { "context->current_mx_sampled_bitmap", "context->current_mx_locators[i].segment_id", + "gcs_block_r4_tx_origin_resolve_root_current(", + "context->current_mx_result = CMX_RESOLVE_OK" }; + static const char *const capability_carrier_contract[] + = { "gcs_block_current_mx_requester_identity_current(context)", + "context->current_mx_requester_identity.capability_record_generation", + "cluster_cr_server_current_mx_build_proof_page(" }; + static const char *const send_worker_contract[] + = { "gcs_block_r4_tx_origin_worker_current(context)", + "gcs_block_current_mx_origin_prepare_reply(context)", + "gcs_block_send_envelope_or_loopback(" }; char *source = read_gcs_block_source(); assert_ordered_in_function( source, "\ngcs_block_try_current_mx_forward128(", "\n#ifdef USE_CLUSTER_UNIT\nbool\ncluster_gcs_block_test_current_mx_forward128(", demux_contract, lengthof(demux_contract)); - assert_ordered_in_function( - source, "\ngcs_block_current_mx_origin_try_accept(", - "\nstatic bool\ngcs_block_r4_tx_origin_resolution_valid(", - accept_contract, lengthof(accept_contract)); - assert_ordered_in_function( - source, "\ngcs_block_current_mx_origin_locate_physical(", - "\nstatic bool\ngcs_block_current_mx_origin_try_accept(", - locator_contract, lengthof(locator_contract)); - assert_ordered_in_function( - source, "\ngcs_block_r4_tx_origin_step(", - "\nvoid\ncluster_gcs_block_r4_tx_resolve_drain(", - step_contract, lengthof(step_contract)); - assert_ordered_in_function( - source, "\ngcs_block_current_mx_origin_sample_held(", - "\ntypedef enum GcsBlockCurrentMxAdvance", - sample_contract, lengthof(sample_contract)); + assert_ordered_in_function(source, "\ngcs_block_current_mx_origin_try_accept(", + "\nstatic bool\ngcs_block_r4_tx_origin_resolution_valid(", + accept_contract, lengthof(accept_contract)); + assert_ordered_in_function(source, "\ngcs_block_current_mx_origin_locate_physical(", + "\nstatic bool\ngcs_block_current_mx_origin_try_accept(", + locator_contract, lengthof(locator_contract)); + assert_ordered_in_function(source, "\ngcs_block_r4_tx_origin_step(", + "\nvoid\ncluster_gcs_block_r4_tx_resolve_drain(", step_contract, + lengthof(step_contract)); + assert_ordered_in_function(source, "\ngcs_block_current_mx_origin_sample_held(", + "\ntypedef enum GcsBlockCurrentMxAdvance", sample_contract, + lengthof(sample_contract)); assert_ordered_in_function( source, "\ngcs_block_current_mx_origin_advance(", "\nstatic GcsBlockR4TxOriginPhase\ngcs_block_current_mx_origin_after_release(", advance_contract, lengthof(advance_contract)); - assert_ordered_in_function( - source, "\ngcs_block_current_mx_origin_prepare_reply(", - "\nstatic bool\ngcs_block_current_mx_origin_sample_held(", - capability_carrier_contract, - lengthof(capability_carrier_contract)); - assert_ordered_in_function( - source, "\ngcs_block_r4_tx_origin_step(", - "\nvoid\ncluster_gcs_block_r4_tx_resolve_drain(", - send_worker_contract, lengthof(send_worker_contract)); - UT_ASSERT_NULL(strstr(source, - "owner->segment_id != segment_id")); - UT_ASSERT_NULL(strstr(source, - "gcs_block_current_mx_origin_try_accept(env, payload)\n\t\t&& cluster_runtime_visibility_current_owner_lookup_exact")); + assert_ordered_in_function(source, "\ngcs_block_current_mx_origin_prepare_reply(", + "\nstatic bool\ngcs_block_current_mx_origin_sample_held(", + capability_carrier_contract, lengthof(capability_carrier_contract)); + assert_ordered_in_function(source, "\ngcs_block_r4_tx_origin_step(", + "\nvoid\ncluster_gcs_block_r4_tx_resolve_drain(", + send_worker_contract, lengthof(send_worker_contract)); + UT_ASSERT_NULL(strstr(source, "owner->segment_id != segment_id")); + UT_ASSERT_NULL(strstr(source, "gcs_block_current_mx_origin_try_accept(env, payload)\n\t\t&& " + "cluster_runtime_visibility_current_owner_lookup_exact")); free(source); } @@ -4836,22 +4584,19 @@ UT_TEST(test_ctrc_forward_and_reply_use_closed_internal_gcs_domain) "PG_FINALLY()", "cluster_semantic_activation_leave(", "pfree(" }; - static const char *const forward_contract[] = { - "cluster_ctrc_seal_request_decode(", - "cluster_semantic_activation_enter_r4_terminal_census(", - "cluster_semantic_activation_resolve_shared_undo_root_r4_terminal_census(", - "cluster_ctrc_participant_request_shared(", - "cluster_ctrc_seal_reply_encode(", - "GCS_BLOCK_REPLY_CURRENT_MX_CTRC_SEAL_RESULT", - "cluster_ic_send_envelope(" - }; - static const char *const reply_contract[] = { - "cluster_ctrc_origin_request_snapshot_shared(", - "cluster_ctrc_seal_reply_decode(", - "cluster_ctrc_origin_note_certificate_reply_shared(", - "cluster_ctrc_origin_ack_land_shared(", - "cluster_ctrc_origin_note_close_reply_shared(" - }; + static const char *const forward_contract[] + = { "cluster_ctrc_seal_request_decode(", + "cluster_semantic_activation_enter_r4_terminal_census(", + "cluster_semantic_activation_resolve_shared_undo_root_r4_terminal_census(", + "cluster_ctrc_participant_request_shared(", + "cluster_ctrc_seal_reply_encode(", + "GCS_BLOCK_REPLY_CURRENT_MX_CTRC_SEAL_RESULT", + "cluster_ic_send_envelope(" }; + static const char *const reply_contract[] + = { "cluster_ctrc_origin_request_snapshot_shared(", "cluster_ctrc_seal_reply_decode(", + "cluster_ctrc_origin_note_certificate_reply_shared(", + "cluster_ctrc_origin_ack_land_shared(", + "cluster_ctrc_origin_note_close_reply_shared(" }; char *source = read_gcs_block_source(); const char *forward_handler; const char *ctrc_forward_call; @@ -4866,43 +4611,40 @@ UT_TEST(test_ctrc_forward_and_reply_use_closed_internal_gcs_domain) assert_ordered_in_function(source, "\ngcs_ctrc_dispatch_prepare(", "\nbool\ncluster_gcs_ctrc_dispatch_close(", prepare_contract, lengthof(prepare_contract)); - assert_ordered_in_function( - source, "\ncluster_gcs_ctrc_dispatch_close(", - "\nstatic bool\ngcs_block_try_land_ctrc_reply(", - dispatch_contract, lengthof(dispatch_contract)); + assert_ordered_in_function(source, "\ncluster_gcs_ctrc_dispatch_close(", + "\nstatic bool\ngcs_block_try_land_ctrc_reply(", dispatch_contract, + lengthof(dispatch_contract)); assert_ordered_in_function(source, "\ngcs_ctrc_dispatch_local_certificates(", "\nvoid\ncluster_gcs_ctrc_dispatch_batch(", batch_contract, lengthof(batch_contract)); - assert_ordered_in_function( - source, "\ngcs_block_try_ctrc_forward136(", - "\nstatic bool\ngcs_block_try_current_mx_forward128(", - forward_contract, lengthof(forward_contract)); - assert_ordered_in_function( - source, "\ngcs_block_try_land_ctrc_reply(", - "\n/* Current-MX statuses 27/28", - reply_contract, lengthof(reply_contract)); - - forward_handler = strstr(source, - "\ncluster_gcs_handle_block_forward_envelope("); + assert_ordered_in_function(source, "\ngcs_block_try_ctrc_forward136(", + "\nstatic bool\ngcs_block_try_current_mx_forward128(", + forward_contract, lengthof(forward_contract)); + assert_ordered_in_function(source, "\ngcs_block_try_land_ctrc_reply(", + "\n/* Current-MX statuses 27/28", reply_contract, + lengthof(reply_contract)); + + forward_handler = strstr(source, "\ncluster_gcs_handle_block_forward_envelope("); ctrc_forward_call = forward_handler != NULL - ? strstr(forward_handler, - "gcs_block_try_ctrc_forward136(env, payload)") : NULL; - current_mx_call = ctrc_forward_call != NULL - ? strstr(ctrc_forward_call, - "gcs_block_try_current_mx_forward128(env, payload)") : NULL; + ? strstr(forward_handler, "gcs_block_try_ctrc_forward136(env, payload)") + : NULL; + current_mx_call + = ctrc_forward_call != NULL + ? strstr(ctrc_forward_call, "gcs_block_try_current_mx_forward128(env, payload)") + : NULL; UT_ASSERT_NOT_NULL(ctrc_forward_call); UT_ASSERT_NOT_NULL(current_mx_call); if (ctrc_forward_call != NULL && current_mx_call != NULL) UT_ASSERT(ctrc_forward_call < current_mx_call); - reply_handler = strstr(source, - "\ncluster_gcs_handle_block_reply_envelope("); + reply_handler = strstr(source, "\ncluster_gcs_handle_block_reply_envelope("); ctrc_reply_call = reply_handler != NULL - ? strstr(reply_handler, - "gcs_block_try_land_ctrc_reply(env, payload)") : NULL; - current_mx_reply_call = ctrc_reply_call != NULL - ? strstr(ctrc_reply_call, - "gcs_block_try_land_current_mx_reply(env, payload)") : NULL; + ? strstr(reply_handler, "gcs_block_try_land_ctrc_reply(env, payload)") + : NULL; + current_mx_reply_call + = ctrc_reply_call != NULL + ? strstr(ctrc_reply_call, "gcs_block_try_land_current_mx_reply(env, payload)") + : NULL; UT_ASSERT_NOT_NULL(ctrc_reply_call); UT_ASSERT_NOT_NULL(current_mx_reply_call); if (ctrc_reply_call != NULL && current_mx_reply_call != NULL) @@ -4915,106 +4657,92 @@ UT_TEST(test_ctrc_forward_and_reply_use_closed_internal_gcs_domain) * that read result without turning it into a touch or a nonzero ACTIVE grant. */ UT_TEST(test_current_mx_ctrc_grant_requires_same_sample_physical_active) { - static const char *const local_contract[] = { - "bool ctrc_physical_active = false", - "cluster_tt_local_get_published_binding(", - "expected_binding = &local_binding", - "cluster_runtime_visibility_current_owner_sample_held_internal(", - "&ctrc_physical_active", - "ctrc_required && !ctrc_physical_active", - "cluster_ctrc_origin_touch_exact(" - }; - static const char *const remote_contract[] = { - "bool ctrc_physical_active = false", - "cluster_runtime_visibility_physical_locator_sample_held(", - "&ctrc_physical_active", - "!ctrc_physical_active", - "cluster_ctrc_origin_touch_exact(" - }; + static const char *const local_contract[] + = { "bool ctrc_physical_active = false", + "cluster_tt_local_get_published_binding(", + "expected_binding = &local_binding", + "cluster_runtime_visibility_current_owner_sample_held_internal(", + "&ctrc_physical_active", + "ctrc_required && !ctrc_physical_active", + "cluster_ctrc_origin_touch_exact(" }; + static const char *const remote_contract[] + = { "bool ctrc_physical_active = false", + "cluster_runtime_visibility_physical_locator_sample_held(", "&ctrc_physical_active", + "!ctrc_physical_active", "cluster_ctrc_origin_touch_exact(" }; char *runtime_source = read_source_path(RUNTIME_VISIBILITY_SOURCE_PATH); char *gcs_source = read_gcs_block_source(); - assert_ordered_in_function( - runtime_source, - "\ncluster_runtime_visibility_current_owner_lookup_internal(", - "\nbool\ncluster_runtime_visibility_current_owner_lookup_exact(", - local_contract, lengthof(local_contract)); - assert_ordered_in_function( - gcs_source, "\ngcs_block_current_mx_origin_sample_held(", - "\ntypedef enum GcsBlockCurrentMxAdvance", - remote_contract, lengthof(remote_contract)); + assert_ordered_in_function(runtime_source, + "\ncluster_runtime_visibility_current_owner_lookup_internal(", + "\nbool\ncluster_runtime_visibility_current_owner_lookup_exact(", + local_contract, lengthof(local_contract)); + assert_ordered_in_function(gcs_source, "\ngcs_block_current_mx_origin_sample_held(", + "\ntypedef enum GcsBlockCurrentMxAdvance", remote_contract, + lengthof(remote_contract)); free(runtime_source); free(gcs_source); } UT_TEST(test_current_mx_origin_unknown_records_first_exact_failure_stage) { - static const char *const accept_contract[] = { - "GCS_BLOCK_CURRENT_MX_ORIGIN_FAILURE_CONTEXT_FULL", - "GCS_BLOCK_CURRENT_MX_ORIGIN_FAILURE_ADMISSION", - "GCS_BLOCK_CURRENT_MX_ORIGIN_FAILURE_LOCATOR", - "current_mx_failure_xid = xid", - "current_mx_current_owner_found", - "= current_owner_found", - "current_mx_durable_locate_result", - "= durable_locate_result", - "GCS_BLOCK_CURRENT_MX_ORIGIN_FAILURE_ROOT" - }; - static const char *const reply_contract[] = { - "context->current_mx_result == CMX_RESOLVE_UNKNOWN", - "gcs_block_current_mx_origin_log_first_unknown(context)" - }; + static const char *const accept_contract[] + = { "GCS_BLOCK_CURRENT_MX_ORIGIN_FAILURE_CONTEXT_FULL", + "GCS_BLOCK_CURRENT_MX_ORIGIN_FAILURE_ADMISSION", + "GCS_BLOCK_CURRENT_MX_ORIGIN_FAILURE_LOCATOR", + "current_mx_failure_xid = xid", + "current_mx_current_owner_found", + "= current_owner_found", + "current_mx_durable_locate_result", + "= durable_locate_result", + "GCS_BLOCK_CURRENT_MX_ORIGIN_FAILURE_ROOT" }; + static const char *const reply_contract[] + = { "context->current_mx_result == CMX_RESOLVE_UNKNOWN", + "gcs_block_current_mx_origin_log_first_unknown(context)" }; char *source = read_gcs_block_source(); /* A fail-closed UNKNOWN is valid only when its first exact TARGET-side * predicate remains visible. The diagnostic is process-local and must * not add a wire field, shared counter, retry, or positive authority. */ - assert_ordered_in_function( - source, "\ngcs_block_current_mx_origin_try_accept(", - "\nstatic bool\ngcs_block_r4_tx_origin_resolution_valid(", - accept_contract, lengthof(accept_contract)); - assert_ordered_in_function( - source, "\ngcs_block_current_mx_origin_prepare_reply(", - "\nstatic bool\ngcs_block_current_mx_origin_sample_held(", - reply_contract, lengthof(reply_contract)); - UT_ASSERT_NOT_NULL(strstr(source, - "current_owner_found=%d durable_locate=%d")); + assert_ordered_in_function(source, "\ngcs_block_current_mx_origin_try_accept(", + "\nstatic bool\ngcs_block_r4_tx_origin_resolution_valid(", + accept_contract, lengthof(accept_contract)); + assert_ordered_in_function(source, "\ngcs_block_current_mx_origin_prepare_reply(", + "\nstatic bool\ngcs_block_current_mx_origin_sample_held(", + reply_contract, lengthof(reply_contract)); + UT_ASSERT_NOT_NULL(strstr(source, "current_owner_found=%d durable_locate=%d")); UT_ASSERT_NULL(strstr(source, "current_mx_failure_retry")); free(source); } UT_TEST(test_r4_tx_origin_cross_segment_resolution_is_cooperative) { - static const char *const phase_contract[] = { - "GCS_BLOCK_R4_TX_ORIGIN_DATA_FREEZE", - "cluster_runtime_visibility_origin_plan_freeze_data_held(", - "GCS_BLOCK_R4_TX_ORIGIN_DATA_RELEASE_BEGIN", - "GCS_BLOCK_R4_TX_ORIGIN_TT_ACQUIRE_BEGIN", - "cluster_runtime_visibility_origin_plan_sample_canonical_held(", - "GCS_BLOCK_R4_TX_ORIGIN_TT_RELEASE_BEGIN", - "GCS_BLOCK_R4_TX_ORIGIN_DATA_RECHECK_ACQUIRE_BEGIN", - "cluster_runtime_visibility_origin_plan_recheck_data_held(", - "GCS_BLOCK_R4_TX_ORIGIN_FINAL_RELEASE_BEGIN", - "GCS_BLOCK_R4_TX_ORIGIN_SEND" - }; + static const char *const phase_contract[] + = { "GCS_BLOCK_R4_TX_ORIGIN_DATA_FREEZE", + "cluster_runtime_visibility_origin_plan_freeze_data_held(", + "GCS_BLOCK_R4_TX_ORIGIN_DATA_RELEASE_BEGIN", + "GCS_BLOCK_R4_TX_ORIGIN_TT_ACQUIRE_BEGIN", + "cluster_runtime_visibility_origin_plan_sample_canonical_held(", + "GCS_BLOCK_R4_TX_ORIGIN_TT_RELEASE_BEGIN", + "GCS_BLOCK_R4_TX_ORIGIN_DATA_RECHECK_ACQUIRE_BEGIN", + "cluster_runtime_visibility_origin_plan_recheck_data_held(", + "GCS_BLOCK_R4_TX_ORIGIN_FINAL_RELEASE_BEGIN", + "GCS_BLOCK_R4_TX_ORIGIN_SEND" }; char *source = read_gcs_block_source(); - const char *step = source != NULL - ? strstr(source, "\ngcs_block_r4_tx_origin_step(") : NULL; - const char *step_end = step != NULL - ? strstr(step, "\nvoid\ncluster_gcs_block_r4_tx_resolve_drain(") : NULL; - const char *blocking_resolver = step != NULL - ? strstr(step, "cluster_runtime_visibility_resolve_exact_origin_held(") - : NULL; + const char *step = source != NULL ? strstr(source, "\ngcs_block_r4_tx_origin_step(") : NULL; + const char *step_end + = step != NULL ? strstr(step, "\nvoid\ncluster_gcs_block_r4_tx_resolve_drain(") : NULL; + const char *blocking_resolver + = step != NULL ? strstr(step, "cluster_runtime_visibility_resolve_exact_origin_held(") + : NULL; const char *sleep = step != NULL ? strstr(step, "pg_usleep(") : NULL; /* The status-22 origin runs on the LMS DATA event loop. A cross-segment * DATA -> canonical TT -> DATA proof must therefore yield at each current * acquire/release instead of waiting for replies that the same loop must * process. The proof remains one resolver with at most one SCUR held. */ - assert_ordered_in_function( - source, "\ngcs_block_r4_tx_origin_step(", - "\nvoid\ncluster_gcs_block_r4_tx_resolve_drain(", - phase_contract, lengthof(phase_contract)); + assert_ordered_in_function(source, "\ngcs_block_r4_tx_origin_step(", + "\nvoid\ncluster_gcs_block_r4_tx_resolve_drain(", phase_contract, + lengthof(phase_contract)); UT_ASSERT_NOT_NULL(step); UT_ASSERT_NOT_NULL(step_end); if (step_end != NULL) { @@ -5026,27 +4754,22 @@ UT_TEST(test_r4_tx_origin_cross_segment_resolution_is_cooperative) UT_TEST(test_r4_tx_origin_serializes_existing_scur_owner_before_all_acquires) { - static const char *const scheduler_contract[] = { - "GCS_BLOCK_R4_TX_ORIGIN_ACQUIRE_BEGIN", - "gcs_block_r4_tx_origin_scur_available(context)", - "cluster_undo_block0_current_acquire_begin_admitted(", - "GCS_BLOCK_R4_TX_ORIGIN_TT_ACQUIRE_BEGIN", - "gcs_block_r4_tx_origin_scur_available(context)", - "cluster_undo_block0_current_acquire_begin_admitted(", - "GCS_BLOCK_R4_TX_ORIGIN_DATA_RECHECK_ACQUIRE_BEGIN", - "gcs_block_r4_tx_origin_scur_available(context)", - "cluster_undo_block0_current_acquire_begin_admitted(" - }; + static const char *const scheduler_contract[] + = { "GCS_BLOCK_R4_TX_ORIGIN_ACQUIRE_BEGIN", + "gcs_block_r4_tx_origin_scur_available(context)", + "cluster_undo_block0_current_acquire_begin_admitted(", + "GCS_BLOCK_R4_TX_ORIGIN_TT_ACQUIRE_BEGIN", + "gcs_block_r4_tx_origin_scur_available(context)", + "cluster_undo_block0_current_acquire_begin_admitted(", + "GCS_BLOCK_R4_TX_ORIGIN_DATA_RECHECK_ACQUIRE_BEGIN", + "gcs_block_r4_tx_origin_scur_available(context)", + "cluster_undo_block0_current_acquire_begin_admitted(" }; char *source = read_gcs_block_source(); const char *helper - = source != NULL - ? strstr(source, "\ngcs_block_r4_tx_origin_scur_available(") - : NULL; + = source != NULL ? strstr(source, "\ngcs_block_r4_tx_origin_scur_available(") : NULL; const char *helper_end - = helper != NULL - ? strstr(helper, - "\n}\n\nstatic void\ngcs_block_r4_tx_origin_step(") - : NULL; + = helper != NULL ? strstr(helper, "\n}\n\nstatic void\ngcs_block_r4_tx_origin_step(") + : NULL; /* A burst of status-22 requests can name the same DATA segment. The * existing process-local resolver must yield while any other context owns @@ -5058,10 +4781,9 @@ UT_TEST(test_r4_tx_origin_serializes_existing_scur_owner_before_all_acquires) UT_ASSERT_NOT_NULL(strstr(helper, "other->in_use")); UT_ASSERT_NOT_NULL(strstr(helper, "other->guard_active")); } - assert_ordered_in_function( - source, "\ngcs_block_r4_tx_origin_step(", - "\nvoid\ncluster_gcs_block_r4_tx_resolve_drain(", - scheduler_contract, lengthof(scheduler_contract)); + assert_ordered_in_function(source, "\ngcs_block_r4_tx_origin_step(", + "\nvoid\ncluster_gcs_block_r4_tx_resolve_drain(", scheduler_contract, + lengthof(scheduler_contract)); free(source); } @@ -5069,22 +4791,16 @@ UT_TEST(test_r4_tx_origin_status22_allows_exact_live_but_not_prepared) { char *source = read_gcs_block_source(); const char *validator - = source != NULL - ? strstr(source, "\ngcs_block_r4_tx_origin_resolution_valid(") - : NULL; + = source != NULL ? strstr(source, "\ngcs_block_r4_tx_origin_resolution_valid(") : NULL; const char *validator_end = validator != NULL - ? strstr(validator, - "\n}\n\nstatic void\ngcs_block_r4_tx_origin_prepare_reply(") - : NULL; - const char *live - = validator != NULL - ? strstr(validator, "context->outcome != CLUSTER_TX_IN_PROGRESS") + ? strstr(validator, "\n}\n\nstatic void\ngcs_block_r4_tx_origin_prepare_reply(") : NULL; + const char *live = validator != NULL + ? strstr(validator, "context->outcome != CLUSTER_TX_IN_PROGRESS") + : NULL; const char *prepared - = validator != NULL - ? strstr(validator, "context->outcome == CLUSTER_TX_PREPARED") - : NULL; + = validator != NULL ? strstr(validator, "context->outcome == CLUSTER_TX_PREPARED") : NULL; UT_ASSERT_NOT_NULL(validator); UT_ASSERT_NOT_NULL(validator_end); @@ -5097,28 +4813,25 @@ UT_TEST(test_r4_tx_origin_status22_allows_exact_live_but_not_prepared) UT_TEST(test_r4_tx_origin_mode_free_status22_uses_open_visibility_then_terminal_fallback) { - static const char *const accept_contract[] = { - "cluster_semantic_activation_enter(", - "CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1", - "CLUSTER_SEMANTIC_TARGET_SIDE", - "resolve_mode = CLUSTER_TX_RESOLVE_VISIBILITY", - "cluster_semantic_activation_resolve_shared_undo_root(", - "cluster_semantic_activation_recheck(&admission)", - "admission_result != CLUSTER_SEMANTIC_ADMISSION_TARGET_DISABLED", - "cluster_semantic_activation_enter_r4_terminal_census(", - "resolve_mode = CLUSTER_TX_RESOLVE_TERMINAL_CENSUS", - "cluster_semantic_activation_resolve_shared_undo_root_r4_terminal_census(", - "cluster_semantic_activation_recheck_r4_terminal_census(&admission)", - "free_context->resolve_mode = resolve_mode" - }; - static const char *const resolve_contract[] = { - "&context->locator, context->resolve_mode", - "&context->admission, &context->expected_generation" - }; - static const char *const send_contract[] = { - "gcs_block_r4_tx_origin_admission_current(context)", - "gcs_block_r4_tx_origin_prepare_reply(context)" - }; + static const char *const accept_contract[] + = { "cluster_semantic_activation_enter(", + "CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1", + "CLUSTER_SEMANTIC_TARGET_SIDE", + "resolve_mode = CLUSTER_TX_RESOLVE_VISIBILITY", + "cluster_semantic_activation_resolve_shared_undo_root(", + "cluster_semantic_activation_recheck(&admission)", + "admission_result != CLUSTER_SEMANTIC_ADMISSION_TARGET_DISABLED", + "cluster_semantic_activation_enter_r4_terminal_census(", + "resolve_mode = CLUSTER_TX_RESOLVE_TERMINAL_CENSUS", + "cluster_semantic_activation_resolve_shared_undo_root_r4_terminal_census(", + "cluster_semantic_activation_recheck_r4_terminal_census(&admission)", + "free_context->resolve_mode = resolve_mode" }; + static const char *const resolve_contract[] + = { "&context->locator, context->resolve_mode", + "&context->admission,\n\t\t\t&context->expected_generation" }; + static const char *const send_contract[] + = { "gcs_block_r4_tx_origin_admission_current(context)", + "gcs_block_r4_tx_origin_prepare_reply(context)" }; char *source = read_gcs_block_source(); /* Freshref §3.1 deliberately keeps kind-2 mode-free on the wire. An @@ -5126,48 +4839,38 @@ UT_TEST(test_r4_tx_origin_mode_free_status22_uses_open_visibility_then_terminal_ * ordinary admission, while the pre-OPEN terminal exception remains the * only fallback. The requester retains the original mode and rejects a * live reply for terminal census. */ - assert_ordered_in_function( - source, "\ngcs_block_r4_tx_origin_try_accept(", - "\nstatic bool\ngcs_block_r4_tx_origin_resolution_valid(", - accept_contract, lengthof(accept_contract)); - assert_ordered_in_function( - source, "\ngcs_block_r4_tx_origin_step(", - "\nvoid\ncluster_gcs_block_r4_tx_resolve_drain(", - resolve_contract, lengthof(resolve_contract)); - assert_ordered_in_function( - source, "\ngcs_block_r4_tx_origin_step(", - "\nvoid\ncluster_gcs_block_r4_tx_resolve_drain(", - send_contract, lengthof(send_contract)); + assert_ordered_in_function(source, "\ngcs_block_r4_tx_origin_try_accept(", + "\nstatic bool\ngcs_block_r4_tx_origin_resolution_valid(", + accept_contract, lengthof(accept_contract)); + assert_ordered_in_function(source, "\ngcs_block_r4_tx_origin_step(", + "\nvoid\ncluster_gcs_block_r4_tx_resolve_drain(", resolve_contract, + lengthof(resolve_contract)); + assert_ordered_in_function(source, "\ngcs_block_r4_tx_origin_step(", + "\nvoid\ncluster_gcs_block_r4_tx_resolve_drain(", send_contract, + lengthof(send_contract)); free(source); } UT_TEST(test_r4_tx_origin_first_denial_records_exact_local_phase) { - static const char *const drain_contract[] = { - "phase_before = context->phase", - "gcs_block_r4_tx_origin_step(context)", - "context->failure_phase == 0", - "context->failure_phase = phase_before" - }; - static const char *const reply_contract[] = { - "gcs_block_r4_tx_origin_resolution_valid(context)", - "gcs_block_r4_tx_origin_log_first_denied(context)", - "header->status = (uint8)GCS_BLOCK_REPLY_R4_DENIED" - }; + static const char *const drain_contract[] + = { "phase_before = context->phase", "gcs_block_r4_tx_origin_step(context)", + "context->failure_phase == 0", "context->failure_phase = phase_before" }; + static const char *const reply_contract[] + = { "gcs_block_r4_tx_origin_resolution_valid(context)", + "gcs_block_r4_tx_origin_log_first_denied(context)", + "header->status = (uint8)GCS_BLOCK_REPLY_R4_DENIED" }; char *source = read_gcs_block_source(); /* Observability only: retain the first process-local failure phase and * emit one bounded origin diagnostic before the unchanged DENIED reply. */ - UT_ASSERT_NOT_NULL(strstr(source, - "GcsBlockR4TxOriginPhase failure_phase;")); - assert_ordered_in_function( - source, "\ncluster_gcs_block_r4_tx_resolve_drain(", - "\nbool\ncluster_gcs_block_r4_tx_resolve_active(", - drain_contract, lengthof(drain_contract)); - assert_ordered_in_function( - source, "\ngcs_block_r4_tx_origin_prepare_reply(", - "\nstatic void\ngcs_block_r4_tx_origin_step(", - reply_contract, lengthof(reply_contract)); + UT_ASSERT_NOT_NULL(strstr(source, "GcsBlockR4TxOriginPhase failure_phase;")); + assert_ordered_in_function(source, "\ncluster_gcs_block_r4_tx_resolve_drain(", + "\nbool\ncluster_gcs_block_r4_tx_resolve_active(", drain_contract, + lengthof(drain_contract)); + assert_ordered_in_function(source, "\ngcs_block_r4_tx_origin_prepare_reply(", + "\nstatic void\ngcs_block_r4_tx_origin_step(", reply_contract, + lengthof(reply_contract)); UT_ASSERT_NOT_NULL(strstr(source, "context->canonical_sampled")); UT_ASSERT_NOT_NULL(strstr(source, "context->expected_generation.value")); UT_ASSERT_NOT_NULL(strstr(source, "current_failure=%d")); @@ -5177,23 +4880,19 @@ UT_TEST(test_r4_tx_origin_first_denial_records_exact_local_phase) UT_TEST(test_resource_x_d1_records_exact_first_failure_before_policy_change) { - static const char *const target_contract[] = { - "n_candidate_result != CLUSTER_PCM_OWN_OK", - "gcs_block_pcm_x_resource_x_remote_s_own_result(", - "cluster_pcm_lock_resource_x_bootstrap_round_failure_snapshot_exact(", - "gcs_block_resource_x_first_failure_record(", - "break;", - "result != RESOURCE_X_APPLY_APPLIED && !first_failure_recorded", - "cluster_pcm_lock_resource_x_bootstrap_round_failure_snapshot_exact(", - "gcs_block_resource_x_first_failure_record(" - }; - static const char *const holder_contract[] = { - "ResourceXRemoteSStage remote_s_stage", - "ResourceXFailureDomain failure_domain", - "rollback_cancel_ok", - "rollback_abort_ok", - "gcs_block_resource_x_first_failure_record(" - }; + static const char *const target_contract[] + = { "n_candidate_result != CLUSTER_PCM_OWN_OK", + "gcs_block_pcm_x_resource_x_remote_s_own_result(", + "cluster_pcm_lock_resource_x_bootstrap_round_failure_snapshot_exact(", + "gcs_block_resource_x_first_failure_record(", + "break;", + "result != RESOURCE_X_APPLY_APPLIED && !first_failure_recorded", + "cluster_pcm_lock_resource_x_bootstrap_round_failure_snapshot_exact(", + "gcs_block_resource_x_first_failure_record(" }; + static const char *const holder_contract[] + = { "ResourceXRemoteSStage remote_s_stage", "ResourceXFailureDomain failure_domain", + "rollback_cancel_ok", "rollback_abort_ok", + "gcs_block_resource_x_first_failure_record(" }; char *source = read_gcs_block_source(); const char *target; const char *target_end; @@ -5204,20 +4903,15 @@ UT_TEST(test_resource_x_d1_records_exact_first_failure_before_policy_change) * exits; the holder records rollback outcomes after the rollback attempt. */ assert_ordered_in_function( source, "\ngcs_block_resource_x_target_acquire_internal(", - "\nResourceXApplyResult\ncluster_gcs_resource_x_target_acquire_exact(", - target_contract, lengthof(target_contract)); - assert_ordered_in_function( - source, "\ngcs_block_pcm_x_resource_x_remote_s_holder_block_to_n(", - "\nstatic bool\ngcs_block_resource_x_target_peer_matches_exact(", - holder_contract, lengthof(holder_contract)); - UT_ASSERT_NOT_NULL(strstr(source, - "resource_x_pre_mutation_backpressure_count")); - UT_ASSERT_NOT_NULL(strstr(source, - "resource_x_authority_drift_count")); - UT_ASSERT_NOT_NULL(strstr(source, - "resource_x_post_mutation_ambiguity_count")); - UT_ASSERT_NOT_NULL(strstr(source, - "resource_x_internal_corruption_count")); + "\nResourceXApplyResult\ncluster_gcs_resource_x_target_acquire_exact(", target_contract, + lengthof(target_contract)); + assert_ordered_in_function(source, "\ngcs_block_pcm_x_resource_x_remote_s_holder_block_to_n(", + "\nstatic bool\ngcs_block_resource_x_target_peer_matches_exact(", + holder_contract, lengthof(holder_contract)); + UT_ASSERT_NOT_NULL(strstr(source, "resource_x_pre_mutation_backpressure_count")); + UT_ASSERT_NOT_NULL(strstr(source, "resource_x_authority_drift_count")); + UT_ASSERT_NOT_NULL(strstr(source, "resource_x_post_mutation_ambiguity_count")); + UT_ASSERT_NOT_NULL(strstr(source, "resource_x_internal_corruption_count")); UT_ASSERT_NOT_NULL(strstr(source, "remote_s_stage=%u")); UT_ASSERT_NOT_NULL(strstr(source, "failure_domain=%u")); UT_ASSERT_NOT_NULL(strstr(source, "request_sequence=%llu")); @@ -5240,34 +4934,31 @@ UT_TEST(test_resource_x_d1_records_exact_first_failure_before_policy_change) UT_ASSERT_NOT_NULL(strstr(source, "status_published=%s")); UT_ASSERT_NOT_NULL(strstr(source, "proof_staged=%s")); UT_ASSERT_NOT_NULL(strstr(source, "proof_published=%s")); - UT_ASSERT_NOT_NULL(strstr(source, - "gcs_block_resource_x_first_failure_should_log(")); - UT_ASSERT_NOT_NULL(strstr(source, - "RESOURCE_X_FIRST_FAILURE_LOG_RATE_LIMIT")); + UT_ASSERT_NOT_NULL(strstr(source, "gcs_block_resource_x_first_failure_should_log(")); + UT_ASSERT_NOT_NULL(strstr(source, "RESOURCE_X_FIRST_FAILURE_LOG_RATE_LIMIT")); UT_ASSERT_NOT_NULL(strstr(source, "cluster_pcm_grd_capacity()")); - UT_ASSERT_NOT_NULL(strstr(source, - "cluster_pcm_grd_lifecycle_stats_snapshot(&lifecycle)")); + UT_ASSERT_NOT_NULL(strstr(source, "cluster_pcm_grd_lifecycle_stats_snapshot(&lifecycle)")); UT_ASSERT_NOT_NULL(strstr(source, "reclaim_attempts=%llu")); UT_ASSERT_NOT_NULL(strstr(source, "reclaim_successes=%llu")); UT_ASSERT_NOT_NULL(strstr(source, "refused_pcm_mode=%llu")); UT_ASSERT_NOT_NULL(strstr(source, "refused_resource_x=%llu")); UT_ASSERT_NOT_NULL(strstr(source, "refused_sidecar=%llu")); - UT_ASSERT_NOT_NULL(strstr(source, - "cluster_bufmgr_pcm_own_n_assertion_candidate_exact(\n" - "\t\t\t\t\t\t\t\t\tbuf, &own, &failure_live)")); + UT_ASSERT_NOT_NULL(strstr(source, "cluster_bufmgr_pcm_own_n_assertion_candidate_exact(\n" + "\t\t\t\t\t\t\t\tbuf, &own, &failure_live)")); /* A requester-side BufferDesc/terminal-round observation is not a * remote-S holder transition. D1 may report the exact terminal round, * but it must not invent remote-S stages or holder/status/proof facts. */ - target = strstr(source, - "\ngcs_block_resource_x_target_acquire_internal("); - target_end = target == NULL ? NULL : strstr(target, - "\nResourceXApplyResult\ncluster_gcs_resource_x_target_acquire_exact("); + target = strstr(source, "\ngcs_block_resource_x_target_acquire_internal("); + target_end + = target == NULL + ? NULL + : strstr(target, + "\nResourceXApplyResult\ncluster_gcs_resource_x_target_acquire_exact("); UT_ASSERT_NOT_NULL(target); UT_ASSERT_NOT_NULL(target_end); if (target != NULL && target_end != NULL) { - const char *none_stage = strstr(target, - "= RESOURCE_X_REMOTE_S_STAGE_NONE;"); + const char *none_stage = strstr(target, "= RESOURCE_X_REMOTE_S_STAGE_NONE;"); UT_ASSERT_NOT_NULL(none_stage); if (none_stage != NULL) @@ -5288,18 +4979,14 @@ UT_TEST(test_resource_x_d1_records_exact_first_failure_before_policy_change) UT_TEST(test_resource_x_terminal_failure_distinguishes_final_authority_observations) { - static const char *const terminal_recheck_contract[] = { - "action == RESOURCE_X_BOOTSTRAP_ROUND_TERMINAL", - "diagnostic_stage = \"terminal-recheck\"", - "terminal_admission_current\n", - "= cluster_semantic_activation_recheck(&admission)", - "terminal_session_check\n", - "= gcs_block_resource_x_gate_session_snapshot_result(", - "terminal_gate_session_current", - "if (!terminal_admission_current\n", - "|| !terminal_gate_session_current)", - "result = RESOURCE_X_APPLY_STALE" - }; + static const char *const terminal_recheck_contract[] + = { "action == RESOURCE_X_BOOTSTRAP_ROUND_TERMINAL", + "diagnostic_stage = \"terminal-recheck\"", + "terminal_admission_current = cluster_semantic_activation_recheck(&admission)", + "terminal_session_check = gcs_block_resource_x_gate_session_snapshot_result(", + "terminal_gate_session_current", + "if (!terminal_admission_current || !terminal_gate_session_current)", + "result = RESOURCE_X_APPLY_STALE" }; char *source = read_gcs_block_source(); /* A terminal round is already exact retained authority, so a final @@ -5328,76 +5015,61 @@ UT_TEST(test_resource_x_d6_remote_s_failure_decision_matrix) /* No holder mutation: pressure stays local and never fences. */ decision = cluster_gcs_resource_x_remote_s_failure_decide( - RESOURCE_X_REMOTE_S_STAGE_SNAPSHOT, - RESOURCE_X_FAIL_PRE_MUTATION_BACKPRESSURE, - false, false, false, false); - UT_ASSERT_EQ(decision.domain, - RESOURCE_X_FAIL_PRE_MUTATION_BACKPRESSURE); + RESOURCE_X_REMOTE_S_STAGE_SNAPSHOT, RESOURCE_X_FAIL_PRE_MUTATION_BACKPRESSURE, false, false, + false, false); + UT_ASSERT_EQ(decision.domain, RESOURCE_X_FAIL_PRE_MUTATION_BACKPRESSURE); UT_ASSERT(!decision.global_fail_closed); UT_ASSERT(!decision.discard_old_round); UT_ASSERT(decision.rollback_complete); /* REVOKE_HELD is reversible only after the exact abort succeeds. */ decision = cluster_gcs_resource_x_remote_s_failure_decide( - RESOURCE_X_REMOTE_S_STAGE_REVOKE_HELD, - RESOURCE_X_FAIL_PRE_MUTATION_BACKPRESSURE, - false, false, true, true); - UT_ASSERT_EQ(decision.domain, - RESOURCE_X_FAIL_PRE_MUTATION_BACKPRESSURE); + RESOURCE_X_REMOTE_S_STAGE_REVOKE_HELD, RESOURCE_X_FAIL_PRE_MUTATION_BACKPRESSURE, false, + false, true, true); + UT_ASSERT_EQ(decision.domain, RESOURCE_X_FAIL_PRE_MUTATION_BACKPRESSURE); UT_ASSERT(!decision.global_fail_closed); UT_ASSERT(decision.rollback_complete); decision = cluster_gcs_resource_x_remote_s_failure_decide( - RESOURCE_X_REMOTE_S_STAGE_REVOKE_HELD, - RESOURCE_X_FAIL_PRE_MUTATION_BACKPRESSURE, - false, false, true, false); - UT_ASSERT_EQ(decision.domain, - RESOURCE_X_FAIL_POST_MUTATION_AMBIGUITY); + RESOURCE_X_REMOTE_S_STAGE_REVOKE_HELD, RESOURCE_X_FAIL_PRE_MUTATION_BACKPRESSURE, false, + false, true, false); + UT_ASSERT_EQ(decision.domain, RESOURCE_X_FAIL_POST_MUTATION_AMBIGUITY); UT_ASSERT(decision.global_fail_closed); UT_ASSERT(!decision.rollback_complete); /* PENDING_STAGED needs both exact cancellation and revoke abort. */ decision = cluster_gcs_resource_x_remote_s_failure_decide( - RESOURCE_X_REMOTE_S_STAGE_PENDING_STAGED, - RESOURCE_X_FAIL_AUTHORITY_DRIFT, - true, true, true, true); + RESOURCE_X_REMOTE_S_STAGE_PENDING_STAGED, RESOURCE_X_FAIL_AUTHORITY_DRIFT, true, true, true, + true); UT_ASSERT_EQ(decision.domain, RESOURCE_X_FAIL_AUTHORITY_DRIFT); UT_ASSERT(!decision.global_fail_closed); UT_ASSERT(decision.discard_old_round); UT_ASSERT(decision.rollback_complete); decision = cluster_gcs_resource_x_remote_s_failure_decide( - RESOURCE_X_REMOTE_S_STAGE_PENDING_STAGED, - RESOURCE_X_FAIL_AUTHORITY_DRIFT, - true, false, true, true); - UT_ASSERT_EQ(decision.domain, - RESOURCE_X_FAIL_POST_MUTATION_AMBIGUITY); + RESOURCE_X_REMOTE_S_STAGE_PENDING_STAGED, RESOURCE_X_FAIL_AUTHORITY_DRIFT, true, false, + true, true); + UT_ASSERT_EQ(decision.domain, RESOURCE_X_FAIL_POST_MUTATION_AMBIGUITY); UT_ASSERT(decision.global_fail_closed); UT_ASSERT(!decision.rollback_complete); decision = cluster_gcs_resource_x_remote_s_failure_decide( - RESOURCE_X_REMOTE_S_STAGE_PENDING_STAGED, - RESOURCE_X_FAIL_PRE_MUTATION_BACKPRESSURE, - true, true, true, false); - UT_ASSERT_EQ(decision.domain, - RESOURCE_X_FAIL_POST_MUTATION_AMBIGUITY); + RESOURCE_X_REMOTE_S_STAGE_PENDING_STAGED, RESOURCE_X_FAIL_PRE_MUTATION_BACKPRESSURE, true, + true, true, false); + UT_ASSERT_EQ(decision.domain, RESOURCE_X_FAIL_POST_MUTATION_AMBIGUITY); UT_ASSERT(decision.global_fail_closed); UT_ASSERT(!decision.rollback_complete); /* S is already N: READY publication uncertainty is never retry-local. */ decision = cluster_gcs_resource_x_remote_s_failure_decide( - RESOURCE_X_REMOTE_S_STAGE_COMMITTED_N, - RESOURCE_X_FAIL_POST_MUTATION_AMBIGUITY, - false, false, false, false); - UT_ASSERT_EQ(decision.domain, - RESOURCE_X_FAIL_POST_MUTATION_AMBIGUITY); + RESOURCE_X_REMOTE_S_STAGE_COMMITTED_N, RESOURCE_X_FAIL_POST_MUTATION_AMBIGUITY, false, + false, false, false); + UT_ASSERT_EQ(decision.domain, RESOURCE_X_FAIL_POST_MUTATION_AMBIGUITY); UT_ASSERT(decision.global_fail_closed); UT_ASSERT(!decision.rollback_complete); /* Illegal stage/rollback combinations are corruption, never BUSY. */ decision = cluster_gcs_resource_x_remote_s_failure_decide( - RESOURCE_X_REMOTE_S_STAGE_SNAPSHOT, - RESOURCE_X_FAIL_PRE_MUTATION_BACKPRESSURE, - true, true, false, false); - UT_ASSERT_EQ(decision.domain, - RESOURCE_X_FAIL_INTERNAL_CORRUPTION); + RESOURCE_X_REMOTE_S_STAGE_SNAPSHOT, RESOURCE_X_FAIL_PRE_MUTATION_BACKPRESSURE, true, true, + false, false); + UT_ASSERT_EQ(decision.domain, RESOURCE_X_FAIL_INTERNAL_CORRUPTION); UT_ASSERT(decision.global_fail_closed); UT_ASSERT(!decision.rollback_complete); @@ -5405,19 +5077,17 @@ UT_TEST(test_resource_x_d6_remote_s_failure_decision_matrix) * Direct fencing inside an individual failure branch would silently * re-couple a wire result to global policy. */ source = read_gcs_block_source(); - holder = strstr(source, - "\ngcs_block_pcm_x_resource_x_remote_s_holder_block_to_n("); - holder_end = holder == NULL ? NULL : strstr(holder, - "\n\nstatic bool\ngcs_block_resource_x_target_peer_matches_exact("); + holder = strstr(source, "\ngcs_block_pcm_x_resource_x_remote_s_holder_block_to_n("); + holder_end + = holder == NULL + ? NULL + : strstr(holder, "\n\nstatic bool\ngcs_block_resource_x_target_peer_matches_exact("); UT_ASSERT_NOT_NULL(holder); UT_ASSERT_NOT_NULL(holder_end); if (holder != NULL && holder_end != NULL) { - UT_ASSERT_NOT_NULL(strstr(holder, - "cluster_gcs_resource_x_remote_s_failure_decide(")); - UT_ASSERT_NOT_NULL(strstr(holder, - "gcs_block_resource_x_failure_decision_apply(")); - direct_fence = strstr(holder, - "gcs_block_resource_x_fail_closed_current("); + UT_ASSERT_NOT_NULL(strstr(holder, "cluster_gcs_resource_x_remote_s_failure_decide(")); + UT_ASSERT_NOT_NULL(strstr(holder, "gcs_block_resource_x_failure_decision_apply(")); + direct_fence = strstr(holder, "gcs_block_resource_x_fail_closed_current("); UT_ASSERT(direct_fence == NULL || direct_fence >= holder_end); } free(source); @@ -5460,8 +5130,8 @@ UT_TEST(test_resource_x_target_install_coherent_adjudicator_is_result_complete) for (i = 0; i < lengthof(raw_states); i++) { ref = seeded_ref; continuation = seeded_continuation; - state = cluster_pcm_x_target_install_follow_adjudicate_exact( - &before, &after, raw_states[i], &ref, &continuation); + state = cluster_pcm_x_target_install_follow_adjudicate_exact(&before, &after, raw_states[i], + &ref, &continuation); UT_ASSERT_EQ(state, raw_states[i]); if (raw_states[i] == RESOURCE_X_TARGET_INSTALL_TERMINAL) UT_ASSERT_EQ(memcmp(&ref, &seeded_ref, sizeof(ref)), 0); @@ -5470,87 +5140,77 @@ UT_TEST(test_resource_x_target_install_coherent_adjudicator_is_result_complete) if (raw_states[i] == RESOURCE_X_TARGET_INSTALL_INFLIGHT || raw_states[i] == RESOURCE_X_TARGET_INSTALL_TERMINAL || raw_states[i] == RESOURCE_X_TARGET_INSTALL_PREUSE_RETRY) - UT_ASSERT_EQ(memcmp(&continuation, &seeded_continuation, - sizeof(continuation)), 0); + UT_ASSERT_EQ(memcmp(&continuation, &seeded_continuation, sizeof(continuation)), 0); else - UT_ASSERT_EQ(memcmp(&continuation, &zero_continuation, - sizeof(continuation)), 0); + UT_ASSERT_EQ(memcmp(&continuation, &zero_continuation, sizeof(continuation)), 0); } after.generation++; for (i = 0; i < lengthof(raw_states); i++) { ref = seeded_ref; continuation = seeded_continuation; - state = cluster_pcm_x_target_install_follow_adjudicate_exact( - &before, &after, raw_states[i], &ref, &continuation); + state = cluster_pcm_x_target_install_follow_adjudicate_exact(&before, &after, raw_states[i], + &ref, &continuation); UT_ASSERT_EQ(state, RESOURCE_X_TARGET_INSTALL_RESAMPLE); UT_ASSERT_EQ(memcmp(&ref, &zero_ref, sizeof(ref)), 0); - UT_ASSERT_EQ(memcmp(&continuation, &zero_continuation, - sizeof(continuation)), 0); + UT_ASSERT_EQ(memcmp(&continuation, &zero_continuation, sizeof(continuation)), 0); } after = before; ref = seeded_ref; continuation = seeded_continuation; state = cluster_pcm_x_target_install_follow_adjudicate_exact( - &before, &after, (ResourceXTargetInstallFollowState)UINT8_MAX, - &ref, &continuation); + &before, &after, (ResourceXTargetInstallFollowState)UINT8_MAX, &ref, &continuation); UT_ASSERT_EQ(state, RESOURCE_X_TARGET_INSTALL_INVALID); UT_ASSERT_EQ(memcmp(&ref, &zero_ref, sizeof(ref)), 0); - UT_ASSERT_EQ(memcmp(&continuation, &zero_continuation, - sizeof(continuation)), 0); + UT_ASSERT_EQ(memcmp(&continuation, &zero_continuation, sizeof(continuation)), 0); } UT_TEST(test_resource_x_target_install_driver_has_no_unbracketed_entry_observer) { - static const char *const capture_order[] = { - "cluster_pcm_lock_resource_x_bootstrap_round_target_install_capture_exact(", - "cluster_bufmgr_pcm_own_snapshot(", - "cluster_pcm_x_target_install_follow_adjudicate_exact(" - }; - static const char *const classify_order[] = { - "cluster_pcm_lock_resource_x_bootstrap_round_target_install_classify_exact(", - "cluster_bufmgr_pcm_own_snapshot(", - "cluster_pcm_x_target_install_follow_adjudicate_exact(" - }; + static const char *const capture_order[] + = { "cluster_pcm_lock_resource_x_bootstrap_round_target_install_capture_exact(", + "cluster_bufmgr_pcm_own_snapshot(", + "cluster_pcm_x_target_install_follow_adjudicate_exact(" }; + static const char *const classify_order[] + = { "cluster_pcm_lock_resource_x_bootstrap_round_target_install_classify_exact(", + "cluster_bufmgr_pcm_own_snapshot(", + "cluster_pcm_x_target_install_follow_adjudicate_exact(" }; char *source = read_gcs_block_source(); const char *driver; const char *driver_end; - assert_ordered_in_function(source, - "\ngcs_block_resource_x_target_install_capture_coherent(", - "\nstatic ResourceXApplyResult\n" - "gcs_block_resource_x_target_install_classify_coherent(", - capture_order, lengthof(capture_order)); - assert_ordered_in_function(source, - "\ngcs_block_resource_x_target_install_classify_coherent(", - "\nstatic ResourceXApplyResult\n" - "gcs_block_resource_x_target_acquire_internal(", - classify_order, lengthof(classify_order)); - UT_ASSERT_EQ(count_source_occurrences(source, - "cluster_pcm_lock_resource_x_bootstrap_round_target_install_capture_exact("), + assert_ordered_in_function(source, "\ngcs_block_resource_x_target_install_capture_coherent(", + "\nstatic ResourceXApplyResult\n" + "gcs_block_resource_x_target_install_classify_coherent(", + capture_order, lengthof(capture_order)); + assert_ordered_in_function(source, "\ngcs_block_resource_x_target_install_classify_coherent(", + "\nstatic ResourceXApplyResult\n" + "gcs_block_resource_x_target_acquire_internal(", + classify_order, lengthof(classify_order)); + UT_ASSERT_EQ( + count_source_occurrences( + source, "cluster_pcm_lock_resource_x_bootstrap_round_target_install_capture_exact("), 1); - UT_ASSERT_EQ(count_source_occurrences(source, - "cluster_pcm_lock_resource_x_bootstrap_round_target_install_classify_exact("), + UT_ASSERT_EQ( + count_source_occurrences( + source, "cluster_pcm_lock_resource_x_bootstrap_round_target_install_classify_exact("), 1); - driver = source != NULL - ? strstr(source, "\ngcs_block_resource_x_target_acquire_internal(") - : NULL; - driver_end = driver != NULL - ? strstr(driver, - "\nResourceXApplyResult\ncluster_gcs_resource_x_target_acquire_exact(") - : NULL; + driver + = source != NULL ? strstr(source, "\ngcs_block_resource_x_target_acquire_internal(") : NULL; + driver_end + = driver != NULL + ? strstr(driver, + "\nResourceXApplyResult\ncluster_gcs_resource_x_target_acquire_exact(") + : NULL; UT_ASSERT_NOT_NULL(driver); UT_ASSERT_NOT_NULL(driver_end); if (driver != NULL && driver_end != NULL) { - UT_ASSERT_NOT_NULL(strstr(driver, - "gcs_block_resource_x_target_install_capture_coherent(")); - UT_ASSERT_NOT_NULL(strstr(driver, - "gcs_block_resource_x_target_install_classify_coherent(")); - UT_ASSERT_NOT_NULL(strstr(driver, - "RESOURCE_X_TARGET_INSTALL_RESAMPLE")); - UT_ASSERT_NULL(strstr(driver, - "&target_install_follow, &own, timeout_ms")); + UT_ASSERT_NOT_NULL(strstr(driver, "gcs_block_resource_x_target_install_capture_coherent(")); + UT_ASSERT_NOT_NULL( + strstr(driver, "gcs_block_resource_x_target_install_classify_coherent(")); + UT_ASSERT_NOT_NULL(strstr(driver, "RESOURCE_X_TARGET_INSTALL_RESAMPLE")); + UT_ASSERT_NULL(strstr(driver, "&target_install_follow, &own, timeout_ms")); } free(source); } @@ -5560,9 +5220,9 @@ UT_TEST(test_resource_x_target_install_driver_has_no_unbracketed_entry_observer) * generated product proves that every cross-axis result is either discarded * on B change or preserves exactly the already classified stable result. */ static ResourceXTargetInstallFollowState -resource_x_target_install_generated_stable_state( - size_t buffer_phase, size_t entry_phase, size_t owner_state, - size_t identity_state, size_t lineage_state) +resource_x_target_install_generated_stable_state(size_t buffer_phase, size_t entry_phase, + size_t owner_state, size_t identity_state, + size_t lineage_state) { /* entry: T1, T2, terminal, failed, stale, unknown */ if (entry_phase == 3 || entry_phase == 5) @@ -5573,19 +5233,17 @@ resource_x_target_install_generated_stable_state( if (owner_state == 5 || buffer_phase >= 6) return RESOURCE_X_TARGET_INSTALL_RECOVERY_BLOCKED; if (entry_phase == 0) - return owner_state == 0 && buffer_phase <= 3 - ? RESOURCE_X_TARGET_INSTALL_INFLIGHT - : RESOURCE_X_TARGET_INSTALL_RECOVERY_BLOCKED; + return owner_state == 0 && buffer_phase <= 3 ? RESOURCE_X_TARGET_INSTALL_INFLIGHT + : RESOURCE_X_TARGET_INSTALL_RECOVERY_BLOCKED; if (entry_phase == 1) return owner_state == 0 && buffer_phase >= 1 && buffer_phase <= 3 - ? RESOURCE_X_TARGET_INSTALL_INFLIGHT - : RESOURCE_X_TARGET_INSTALL_RECOVERY_BLOCKED; + ? RESOURCE_X_TARGET_INSTALL_INFLIGHT + : RESOURCE_X_TARGET_INSTALL_RECOVERY_BLOCKED; /* Terminal: I3 + empty is the sole authority-bearing cell. Exact * terminal pre-use owners and RX/RN successors can only requalify. */ if (owner_state == 0 && buffer_phase == 3) return RESOURCE_X_TARGET_INSTALL_TERMINAL; - if ((buffer_phase == 3 || buffer_phase == 4 || buffer_phase == 5) - && owner_state < 5) + if ((buffer_phase == 3 || buffer_phase == 4 || buffer_phase == 5) && owner_state < 5) return RESOURCE_X_TARGET_INSTALL_PREUSE_RETRY; return RESOURCE_X_TARGET_INSTALL_RECOVERY_BLOCKED; } @@ -5628,14 +5286,11 @@ UT_TEST(test_resource_x_target_install_generated_cross_axis_matrix) if (buffer_phase == 0) { before.pcm_state = (uint8)PCM_STATE_N; before.flags = PCM_OWN_FLAG_GRANT_PENDING; - } else if (buffer_phase == 1 || buffer_phase == 2 - || buffer_phase == 3) { + } else if (buffer_phase == 1 || buffer_phase == 2 || buffer_phase == 3) { before.pcm_state = (uint8)PCM_STATE_X; before.generation = 11; - before.writer_activation_token - = buffer_phase == 3 ? 0 : UINT64_C(17); - before.resource_x_activation_generation - = buffer_phase == 2 ? UINT64_C(23) : 0; + before.writer_activation_token = buffer_phase == 3 ? 0 : UINT64_C(17); + before.resource_x_activation_generation = buffer_phase == 2 ? UINT64_C(23) : 0; } else if (buffer_phase == 4) { before.pcm_state = (uint8)PCM_STATE_X; before.flags = PCM_OWN_FLAG_REVOKING; @@ -5655,61 +5310,64 @@ UT_TEST(test_resource_x_target_install_generated_cross_axis_matrix) before.flags = UINT32_C(0xffffffff); } for (entry_phase = 0; entry_phase < 6; entry_phase++) - for (owner_state = 0; owner_state < 6; owner_state++) - for (identity_state = 0; identity_state < 5; identity_state++) - for (observation = 0; observation < 2; observation++) - for (lineage_state = 0; lineage_state < 3; lineage_state++) - for (deadline_state = 0; deadline_state < 3; deadline_state++) { - raw_state = resource_x_target_install_generated_stable_state( - buffer_phase, entry_phase, owner_state, - identity_state, lineage_state); - after = before; - if (observation != 0) - /* The complete snapshot now reserves two bytes, not three. */ - after._reserved[1] ^= UINT8_C(1); - before_saved = before; - after_saved = after; - memset(&seeded_ref, 0x5a, sizeof(seeded_ref)); - memset(&seeded_continuation, 0xa5, - sizeof(seeded_continuation)); - seeded_continuation.capture_flags = (uint8)owner_state; - seeded_continuation.requester_node = (int32)identity_state; - seeded_continuation.observed_claim_pending_generation - = lineage_state == 0 ? 0 : UINT64_C(10); - seeded_continuation.observed_claim_reservation_token = lineage_state == 0 ? 0 - : lineage_state == 1 - ? UINT64_C(17) - : UINT64_C(18); - seeded_continuation.observed_head_change_generation = UINT64_C(1000); - seeded_continuation.caller_absolute_deadline_us - = deadline_state == 0 ? UINT64_C(1001) - : deadline_state == 1 ? UINT64_C(1000) : UINT64_C(999); - seeded_continuation.valid = true; - ref = seeded_ref; - continuation = seeded_continuation; - state = cluster_pcm_x_target_install_follow_adjudicate_exact( - &before, &after, raw_state, &ref, &continuation); - expected = observation != 0 - ? RESOURCE_X_TARGET_INSTALL_RESAMPLE : raw_state; - UT_ASSERT_EQ(state, expected); - UT_ASSERT_EQ(memcmp(&before, &before_saved, sizeof(before)), 0); - UT_ASSERT_EQ(memcmp(&after, &after_saved, sizeof(after)), 0); - if (expected == RESOURCE_X_TARGET_INSTALL_TERMINAL) - UT_ASSERT_EQ(memcmp(&ref, &seeded_ref, sizeof(ref)), 0); - else - UT_ASSERT_EQ(memcmp(&ref, &zero_ref, sizeof(ref)), 0); - if (expected == RESOURCE_X_TARGET_INSTALL_INFLIGHT - || expected == RESOURCE_X_TARGET_INSTALL_TERMINAL - || expected == RESOURCE_X_TARGET_INSTALL_PREUSE_RETRY) { - UT_ASSERT_EQ(memcmp(&continuation, &seeded_continuation, - sizeof(continuation)), 0); - UT_ASSERT(continuation.caller_absolute_deadline_us - <= seeded_continuation.caller_absolute_deadline_us); - } else - UT_ASSERT_EQ(memcmp(&continuation, &zero_continuation, - sizeof(continuation)), 0); - cases++; - } + for (owner_state = 0; owner_state < 6; owner_state++) + for (identity_state = 0; identity_state < 5; identity_state++) + for (observation = 0; observation < 2; observation++) + for (lineage_state = 0; lineage_state < 3; lineage_state++) + for (deadline_state = 0; deadline_state < 3; deadline_state++) { + raw_state = resource_x_target_install_generated_stable_state( + buffer_phase, entry_phase, owner_state, identity_state, + lineage_state); + after = before; + if (observation != 0) + /* The complete snapshot now reserves two bytes, not three. */ + after._reserved[1] ^= UINT8_C(1); + before_saved = before; + after_saved = after; + memset(&seeded_ref, 0x5a, sizeof(seeded_ref)); + memset(&seeded_continuation, 0xa5, sizeof(seeded_continuation)); + seeded_continuation.capture_flags = (uint8)owner_state; + seeded_continuation.requester_node = (int32)identity_state; + seeded_continuation.observed_claim_pending_generation + = lineage_state == 0 ? 0 : UINT64_C(10); + seeded_continuation.observed_claim_reservation_token + = lineage_state == 0 ? 0 + : lineage_state == 1 ? UINT64_C(17) + : UINT64_C(18); + seeded_continuation.observed_head_change_generation + = UINT64_C(1000); + seeded_continuation.caller_absolute_deadline_us + = deadline_state == 0 ? UINT64_C(1001) + : deadline_state == 1 ? UINT64_C(1000) + : UINT64_C(999); + seeded_continuation.valid = true; + ref = seeded_ref; + continuation = seeded_continuation; + state = cluster_pcm_x_target_install_follow_adjudicate_exact( + &before, &after, raw_state, &ref, &continuation); + expected = observation != 0 ? RESOURCE_X_TARGET_INSTALL_RESAMPLE + : raw_state; + UT_ASSERT_EQ(state, expected); + UT_ASSERT_EQ(memcmp(&before, &before_saved, sizeof(before)), 0); + UT_ASSERT_EQ(memcmp(&after, &after_saved, sizeof(after)), 0); + if (expected == RESOURCE_X_TARGET_INSTALL_TERMINAL) + UT_ASSERT_EQ(memcmp(&ref, &seeded_ref, sizeof(ref)), 0); + else + UT_ASSERT_EQ(memcmp(&ref, &zero_ref, sizeof(ref)), 0); + if (expected == RESOURCE_X_TARGET_INSTALL_INFLIGHT + || expected == RESOURCE_X_TARGET_INSTALL_TERMINAL + || expected == RESOURCE_X_TARGET_INSTALL_PREUSE_RETRY) { + UT_ASSERT_EQ(memcmp(&continuation, &seeded_continuation, + sizeof(continuation)), + 0); + UT_ASSERT(continuation.caller_absolute_deadline_us + <= seeded_continuation.caller_absolute_deadline_us); + } else + UT_ASSERT_EQ(memcmp(&continuation, &zero_continuation, + sizeof(continuation)), + 0); + cases++; + } } UT_ASSERT_EQ(cases, UINT64_C(29160)); } @@ -5753,16 +5411,13 @@ UT_TEST(test_resource_x_target_install_resample_loop_checks_fixed_deadline_first const char *deadline_result; const char *first_snapshot; - driver = source != NULL - ? strstr(source, "\ngcs_block_resource_x_target_acquire_internal(") - : NULL; - round_loop = driver != NULL - ? strstr(driver, "diagnostic_stage = \"round-loop\"") : NULL; + driver + = source != NULL ? strstr(source, "\ngcs_block_resource_x_target_acquire_internal(") : NULL; + round_loop = driver != NULL ? strstr(driver, "diagnostic_stage = \"round-loop\"") : NULL; loop = round_loop != NULL ? strstr(round_loop, "for (;;) {") : NULL; - first_snapshot = loop != NULL - ? strstr(loop, "diagnostic_stage = \"own-snapshot\"") : NULL; - deadline_sample = loop != NULL - ? strstr(loop, "now_us = gcs_block_pcm_x_monotonic_us();") : NULL; + first_snapshot = loop != NULL ? strstr(loop, "diagnostic_stage = \"own-snapshot\"") : NULL; + deadline_sample + = loop != NULL ? strstr(loop, "now_us = gcs_block_pcm_x_monotonic_us();") : NULL; deadline_guard = deadline_sample != NULL ? strstr(deadline_sample, "if (wait_diagnostic.state.started_us != 0)") : NULL; @@ -5776,8 +5431,8 @@ UT_TEST(test_resource_x_target_install_resample_loop_checks_fixed_deadline_first UT_ASSERT_NOT_NULL(deadline_sample); UT_ASSERT_NOT_NULL(deadline_guard); UT_ASSERT_NOT_NULL(deadline_result); - if (first_snapshot != NULL && deadline_sample != NULL - && deadline_guard != NULL && deadline_result != NULL) { + if (first_snapshot != NULL && deadline_sample != NULL && deadline_guard != NULL + && deadline_result != NULL) { UT_ASSERT(loop < deadline_sample); UT_ASSERT(deadline_sample < deadline_guard); UT_ASSERT(deadline_guard < deadline_result); @@ -5788,23 +5443,22 @@ UT_TEST(test_resource_x_target_install_resample_loop_checks_fixed_deadline_first UT_TEST(test_resource_x_target_rebinds_exact_same_round_install_after_snapshot_drift) { - static const char *const drift_contract[] = { - "n_candidate_result != CLUSTER_PCM_OWN_OK", - "n_candidate_result == CLUSTER_PCM_OWN_STALE", - "gcs_block_resource_x_target_install_capture_coherent(", - "retry_slice_us,", - "absolute_deadline_us,", - "&failure_live,", - "&target_install_follow_state,", - "&target_install_follow)", - "RESOURCE_X_TARGET_INSTALL_RESAMPLE", - "RESOURCE_X_TARGET_INSTALL_INFLIGHT", - "RESOURCE_X_TARGET_INSTALL_TERMINAL", - "continue;", - "gcs_block_pcm_x_resource_x_remote_s_own_result(", - "gcs_block_resource_x_first_failure_record(", - "break;" - }; + static const char *const drift_contract[] + = { "n_candidate_result != CLUSTER_PCM_OWN_OK", + "n_candidate_result == CLUSTER_PCM_OWN_STALE", + "gcs_block_resource_x_target_install_capture_coherent(", + "retry_slice_us,", + "absolute_deadline_us,", + "&failure_live,", + "&target_install_follow_state,", + "&target_install_follow)", + "RESOURCE_X_TARGET_INSTALL_RESAMPLE", + "RESOURCE_X_TARGET_INSTALL_INFLIGHT", + "RESOURCE_X_TARGET_INSTALL_TERMINAL", + "continue;", + "gcs_block_pcm_x_resource_x_remote_s_own_result(", + "gcs_block_resource_x_first_failure_record(", + "break;" }; char *source = read_gcs_block_source(); /* The observed t/400 first cause is a clean N snapshot whose exact @@ -5815,28 +5469,27 @@ UT_TEST(test_resource_x_target_rebinds_exact_same_round_install_after_snapshot_d * recomputed nor refreshed here. */ assert_ordered_in_function( source, "\ngcs_block_resource_x_target_acquire_internal(", - "\nResourceXApplyResult\ncluster_gcs_resource_x_target_acquire_exact(", - drift_contract, lengthof(drift_contract)); + "\nResourceXApplyResult\ncluster_gcs_resource_x_target_acquire_exact(", drift_contract, + lengthof(drift_contract)); free(source); } UT_TEST(test_resource_x_target_resamples_only_exact_terminal_install) { - static const char *const resample_contract[] = { - "n_candidate_result != CLUSTER_PCM_OWN_OK", - "n_candidate_result == CLUSTER_PCM_OWN_STALE", - "gcs_block_resource_x_target_install_capture_coherent(", - "&failure_live,", - "&target_install_follow_state,", - "&target_install_follow)", - "RESOURCE_X_TARGET_INSTALL_RESAMPLE", - "RESOURCE_X_TARGET_INSTALL_TERMINAL", - "continue;", - "gcs_block_pcm_x_resource_x_remote_s_own_result(", - "cluster_pcm_lock_resource_x_bootstrap_round_failure_snapshot_exact(", - "gcs_block_resource_x_first_failure_record(", - "break;" - }; + static const char *const resample_contract[] + = { "n_candidate_result != CLUSTER_PCM_OWN_OK", + "n_candidate_result == CLUSTER_PCM_OWN_STALE", + "gcs_block_resource_x_target_install_capture_coherent(", + "&failure_live,", + "&target_install_follow_state,", + "&target_install_follow)", + "RESOURCE_X_TARGET_INSTALL_RESAMPLE", + "RESOURCE_X_TARGET_INSTALL_TERMINAL", + "continue;", + "gcs_block_pcm_x_resource_x_remote_s_own_result(", + "cluster_pcm_lock_resource_x_bootstrap_round_failure_snapshot_exact(", + "gcs_block_resource_x_first_failure_record(", + "break;" }; ClusterPcmOwnSnapshot before; ClusterPcmOwnSnapshot live; ResourceXBootstrapRoundFailureSnapshot round; @@ -5850,11 +5503,11 @@ UT_TEST(test_resource_x_target_resamples_only_exact_terminal_install) before.tag.relNumber = 16384; before.tag.forkNum = MAIN_FORKNUM; before.tag.blockNum = 222; - before.pcm_state = (uint8) PCM_STATE_N; + before.pcm_state = (uint8)PCM_STATE_N; before.generation = 64; before.reservation_token = 178; live = before; - live.pcm_state = (uint8) PCM_STATE_X; + live.pcm_state = (uint8)PCM_STATE_X; live.generation = 65; live.reservation_token = 179; round.ref.assertion.resource = before.tag; @@ -5877,36 +5530,30 @@ UT_TEST(test_resource_x_target_resamples_only_exact_terminal_install) * must capture the exact attempt/token receipt and the next iteration must * revalidate BufferDesc and entry before returning the terminal ref. */ UT_ASSERT(cluster_gcs_resource_x_target_terminal_resample_exact( - CLUSTER_PCM_OWN_STALE, &before, &live, - RESOURCE_X_APPLY_APPLIED, &round)); + CLUSTER_PCM_OWN_STALE, &before, &live, RESOURCE_X_APPLY_APPLIED, &round)); round.terminal = 0; UT_ASSERT(!cluster_gcs_resource_x_target_terminal_resample_exact( - CLUSTER_PCM_OWN_STALE, &before, &live, - RESOURCE_X_APPLY_APPLIED, &round)); + CLUSTER_PCM_OWN_STALE, &before, &live, RESOURCE_X_APPLY_APPLIED, &round)); round.terminal = 1; round.buffer_ownership_generation = 66; UT_ASSERT(!cluster_gcs_resource_x_target_terminal_resample_exact( - CLUSTER_PCM_OWN_STALE, &before, &live, - RESOURCE_X_APPLY_APPLIED, &round)); + CLUSTER_PCM_OWN_STALE, &before, &live, RESOURCE_X_APPLY_APPLIED, &round)); round.buffer_ownership_generation = 65; live.flags = PCM_OWN_FLAG_REVOKING; UT_ASSERT(!cluster_gcs_resource_x_target_terminal_resample_exact( - CLUSTER_PCM_OWN_STALE, &before, &live, - RESOURCE_X_APPLY_APPLIED, &round)); + CLUSTER_PCM_OWN_STALE, &before, &live, RESOURCE_X_APPLY_APPLIED, &round)); live.flags = 0; UT_ASSERT(!cluster_gcs_resource_x_target_terminal_resample_exact( - CLUSTER_PCM_OWN_OK, &before, &live, - RESOURCE_X_APPLY_APPLIED, &round)); + CLUSTER_PCM_OWN_OK, &before, &live, RESOURCE_X_APPLY_APPLIED, &round)); UT_ASSERT(!cluster_gcs_resource_x_target_terminal_resample_exact( - CLUSTER_PCM_OWN_STALE, &before, &live, - RESOURCE_X_APPLY_STALE, &round)); + CLUSTER_PCM_OWN_STALE, &before, &live, RESOURCE_X_APPLY_STALE, &round)); source = read_gcs_block_source(); assert_ordered_in_function( source, "\ngcs_block_resource_x_target_acquire_internal(", - "\nResourceXApplyResult\ncluster_gcs_resource_x_target_acquire_exact(", - resample_contract, lengthof(resample_contract)); + "\nResourceXApplyResult\ncluster_gcs_resource_x_target_acquire_exact(", resample_contract, + lengthof(resample_contract)); free(source); } @@ -5929,12 +5576,12 @@ UT_TEST(test_resource_x_target_resamples_exact_pending_install_after_terminal_pu pending.tag.relNumber = 16384; pending.tag.forkNum = MAIN_FORKNUM; pending.tag.blockNum = 223; - pending.pcm_state = (uint8) PCM_STATE_N; + pending.pcm_state = (uint8)PCM_STATE_N; pending.generation = 0; pending.reservation_token = 8; pending.flags = PCM_OWN_FLAG_GRANT_PENDING; live = pending; - live.pcm_state = (uint8) PCM_STATE_X; + live.pcm_state = (uint8)PCM_STATE_X; live.generation = 1; live.flags = 0; round.ref.assertion.resource = pending.tag; @@ -5990,28 +5637,26 @@ UT_TEST(test_resource_x_target_resamples_exact_pending_install_after_terminal_pu /* Production must close this race before the generic clean-N candidate * rejects the stale pending preimage as INVALID. */ source = read_gcs_block_source(); - driver = source != NULL - ? strstr(source, "\ngcs_block_resource_x_target_acquire_internal(") - : NULL; - resample_stage = driver != NULL - ? strstr(driver, "diagnostic_stage = \"pending-install-terminal-resample\"") - : NULL; - receipt_capture = resample_stage != NULL - ? strstr(resample_stage, - "gcs_block_resource_x_target_install_capture_coherent(") - : NULL; - generic_candidate = receipt_capture != NULL - ? strstr(receipt_capture, - "cluster_bufmgr_pcm_own_n_assertion_candidate_exact(") - : NULL; + driver + = source != NULL ? strstr(source, "\ngcs_block_resource_x_target_acquire_internal(") : NULL; + resample_stage + = driver != NULL + ? strstr(driver, "diagnostic_stage = \"pending-install-terminal-resample\"") + : NULL; + receipt_capture + = resample_stage != NULL + ? strstr(resample_stage, "gcs_block_resource_x_target_install_capture_coherent(") + : NULL; + generic_candidate + = receipt_capture != NULL + ? strstr(receipt_capture, "cluster_bufmgr_pcm_own_n_assertion_candidate_exact(") + : NULL; UT_ASSERT_NOT_NULL(driver); UT_ASSERT_NOT_NULL(resample_stage); UT_ASSERT_NOT_NULL(receipt_capture); UT_ASSERT_NOT_NULL(generic_candidate); - if (resample_stage != NULL && receipt_capture != NULL - && generic_candidate != NULL) - UT_ASSERT(resample_stage < receipt_capture - && receipt_capture < generic_candidate); + if (resample_stage != NULL && receipt_capture != NULL && generic_candidate != NULL) + UT_ASSERT(resample_stage < receipt_capture && receipt_capture < generic_candidate); free(source); } @@ -6030,12 +5675,12 @@ UT_TEST(test_resource_x_pending_terminal_resample_diagnostic_names_exact_mismatc pending.tag.relNumber = 16384; pending.tag.forkNum = MAIN_FORKNUM; pending.tag.blockNum = 223; - pending.pcm_state = (uint8) PCM_STATE_N; + pending.pcm_state = (uint8)PCM_STATE_N; pending.generation = 14; pending.reservation_token = 8; pending.flags = PCM_OWN_FLAG_GRANT_PENDING; live = pending; - live.pcm_state = (uint8) PCM_STATE_X; + live.pcm_state = (uint8)PCM_STATE_X; live.generation = 15; live.flags = 0; round.ref.assertion.resource = pending.tag; @@ -6058,35 +5703,30 @@ UT_TEST(test_resource_x_pending_terminal_resample_diagnostic_names_exact_mismatc round.buffer_ownership_generation++; mismatch = cluster_gcs_resource_x_pending_terminal_resample_mismatch( &pending, &live, RESOURCE_X_APPLY_APPLIED, &round); - UT_ASSERT_EQ(mismatch, - RESOURCE_X_PENDING_TERMINAL_MISMATCH_ROUND_BUFFER_GENERATION); + UT_ASSERT_EQ(mismatch, RESOURCE_X_PENDING_TERMINAL_MISMATCH_ROUND_BUFFER_GENERATION); round.buffer_ownership_generation--; round.retired_acquisition_generation++; mismatch = cluster_gcs_resource_x_pending_terminal_resample_mismatch( &pending, &live, RESOURCE_X_APPLY_APPLIED, &round); - UT_ASSERT_EQ(mismatch, - RESOURCE_X_PENDING_TERMINAL_MISMATCH_ROUND_RETIRED); + UT_ASSERT_EQ(mismatch, RESOURCE_X_PENDING_TERMINAL_MISMATCH_ROUND_RETIRED); round.retired_acquisition_generation--; round.ref.formation = 0; mismatch = cluster_gcs_resource_x_pending_terminal_resample_mismatch( &pending, &live, RESOURCE_X_APPLY_APPLIED, &round); - UT_ASSERT_EQ(mismatch, - RESOURCE_X_PENDING_TERMINAL_MISMATCH_ROUND_FORMATION); + UT_ASSERT_EQ(mismatch, RESOURCE_X_PENDING_TERMINAL_MISMATCH_ROUND_FORMATION); round.ref.formation = 2; round.progress_flags = 1; mismatch = cluster_gcs_resource_x_pending_terminal_resample_mismatch( &pending, &live, RESOURCE_X_APPLY_APPLIED, &round); - UT_ASSERT_EQ(mismatch, - RESOURCE_X_PENDING_TERMINAL_MISMATCH_ROUND_PROGRESS); + UT_ASSERT_EQ(mismatch, RESOURCE_X_PENDING_TERMINAL_MISMATCH_ROUND_PROGRESS); round.progress_flags = 0; mismatch = cluster_gcs_resource_x_pending_terminal_resample_mismatch( &pending, &live, RESOURCE_X_APPLY_STALE, &round); - UT_ASSERT_EQ(mismatch, - RESOURCE_X_PENDING_TERMINAL_MISMATCH_ROUND_RESULT); + UT_ASSERT_EQ(mismatch, RESOURCE_X_PENDING_TERMINAL_MISMATCH_ROUND_RESULT); } UT_TEST(test_resource_x_target_resamples_exact_pending_install_after_wait_wakeup) @@ -6107,37 +5747,35 @@ UT_TEST(test_resource_x_target_resamples_exact_pending_install_after_wait_wakeup * terminal race, but it can no longer authorize a retry. The receipt wait * lives earlier in the driver and returns to the same immutable continuation; * this block records the r115 mismatch mask and propagates its typed result. */ - driver = source != NULL - ? strstr(source, "\ngcs_block_resource_x_target_acquire_internal(") - : NULL; + driver + = source != NULL ? strstr(source, "\ngcs_block_resource_x_target_acquire_internal(") : NULL; wait_stage = driver != NULL ? strstr(driver, "diagnostic_stage = \"round-wait\"") : NULL; wait_failure = wait_stage != NULL - ? strstr(wait_stage, "if (wait_result != RESOURCE_X_APPLY_APPLIED") - : NULL; - duplicate_guard = wait_failure == NULL ? NULL - : strstr(wait_failure, "&& wait_result != RESOURCE_X_APPLY_DUPLICATE)"); + ? strstr(wait_stage, "if (wait_result != RESOURCE_X_APPLY_APPLIED") + : NULL; + duplicate_guard = wait_failure == NULL + ? NULL + : strstr(wait_failure, "&& wait_result != RESOURCE_X_APPLY_DUPLICATE)"); resample_stage = wait_failure != NULL - ? strstr(wait_failure, - "diagnostic_stage = \"wait-terminal-resample\"") - : NULL; + ? strstr(wait_failure, "diagnostic_stage = \"wait-terminal-resample\"") + : NULL; live_snapshot = resample_stage != NULL - ? strstr(resample_stage, "cluster_bufmgr_pcm_own_snapshot(") - : NULL; - round_snapshot = live_snapshot != NULL - ? strstr(live_snapshot, - "cluster_pcm_lock_resource_x_bootstrap_round_failure_snapshot_exact(") - : NULL; - mismatch = round_snapshot != NULL - ? strstr(round_snapshot, - "cluster_gcs_resource_x_pending_terminal_resample_mismatch(") - : NULL; - return_result = mismatch != NULL - ? strstr(mismatch, "result = wait_result;") - : NULL; - legacy_retry = mismatch != NULL - ? strstr(mismatch, - "cluster_gcs_resource_x_target_pending_terminal_resample_exact(") - : NULL; + ? strstr(resample_stage, "cluster_bufmgr_pcm_own_snapshot(") + : NULL; + round_snapshot + = live_snapshot != NULL + ? strstr(live_snapshot, + "cluster_pcm_lock_resource_x_bootstrap_round_failure_snapshot_exact(") + : NULL; + mismatch + = round_snapshot != NULL + ? strstr(round_snapshot, "cluster_gcs_resource_x_pending_terminal_resample_mismatch(") + : NULL; + return_result = mismatch != NULL ? strstr(mismatch, "result = wait_result;") : NULL; + legacy_retry + = mismatch != NULL + ? strstr(mismatch, "cluster_gcs_resource_x_target_pending_terminal_resample_exact(") + : NULL; UT_ASSERT_NOT_NULL(driver); UT_ASSERT_NOT_NULL(wait_stage); UT_ASSERT_NOT_NULL(wait_failure); @@ -6149,13 +5787,10 @@ UT_TEST(test_resource_x_target_resamples_exact_pending_install_after_wait_wakeup UT_ASSERT_NOT_NULL(round_snapshot); UT_ASSERT_NOT_NULL(mismatch); UT_ASSERT_NOT_NULL(return_result); - if (resample_stage != NULL && live_snapshot != NULL - && round_snapshot != NULL && mismatch != NULL - && return_result != NULL) { - UT_ASSERT(resample_stage < live_snapshot - && live_snapshot < round_snapshot - && round_snapshot < mismatch - && mismatch < return_result); + if (resample_stage != NULL && live_snapshot != NULL && round_snapshot != NULL + && mismatch != NULL && return_result != NULL) { + UT_ASSERT(resample_stage < live_snapshot && live_snapshot < round_snapshot + && round_snapshot < mismatch && mismatch < return_result); UT_ASSERT(legacy_retry == NULL || legacy_retry >= return_result); } free(source); @@ -6163,32 +5798,31 @@ UT_TEST(test_resource_x_target_resamples_exact_pending_install_after_wait_wakeup UT_TEST(test_resource_x_target_retains_one_install_receipt_until_terminal_gate) { - static const char *const continuation_contract[] = { - "ResourceXTargetInstallContinuation target_install_follow", - "memset(&target_install_follow, 0, sizeof(target_install_follow))", - "if (target_install_follow.valid)", - "gcs_block_resource_x_target_install_classify_coherent(", - "buf, &target_install_follow, &own,", - "&target_install_follow_state, &terminal_ref)", - "RESOURCE_X_TARGET_INSTALL_RESAMPLE", - "RESOURCE_X_TARGET_INSTALL_TERMINAL", - "goto target_install_terminal_recheck", - "RESOURCE_X_TARGET_INSTALL_INFLIGHT", - "cluster_pcm_lock_resource_x_bootstrap_round_target_install_wait_exact(", - "&target_install_follow,", - "RESOURCE_X_TARGET_INSTALL_INFLIGHT,", - "timeout_ms)", - "continue;", - "gcs_block_resource_x_target_install_capture_coherent(", - "retry_slice_us,", - "absolute_deadline_us, &own,", - "&target_install_follow_state,", - "&target_install_follow)", - "target_install_terminal_recheck:", - "terminal_admission_current", - "terminal_gate_session_current", - "*ref_out = terminal_ref" - }; + static const char *const continuation_contract[] + = { "ResourceXTargetInstallContinuation target_install_follow", + "memset(&target_install_follow, 0, sizeof(target_install_follow))", + "if (target_install_follow.valid)", + "gcs_block_resource_x_target_install_classify_coherent(", + "buf, &target_install_follow, &own,", + "&target_install_follow_state,\n\t\t\t\t\t\t\t&terminal_ref)", + "RESOURCE_X_TARGET_INSTALL_RESAMPLE", + "RESOURCE_X_TARGET_INSTALL_TERMINAL", + "goto target_install_terminal_recheck", + "RESOURCE_X_TARGET_INSTALL_INFLIGHT", + "cluster_pcm_lock_resource_x_bootstrap_round_target_install_wait_exact(", + "&target_install_follow,", + "RESOURCE_X_TARGET_INSTALL_INFLIGHT,", + "timeout_ms)", + "continue;", + "gcs_block_resource_x_target_install_capture_coherent(", + "retry_slice_us,", + "absolute_deadline_us, &own,", + "&target_install_follow_state,", + "&target_install_follow)", + "target_install_terminal_recheck:", + "terminal_admission_current", + "terminal_gate_session_current", + "*ref_out = terminal_ref" }; char *source = read_gcs_block_source(); const char *driver; const char *driver_end; @@ -6206,27 +5840,25 @@ UT_TEST(test_resource_x_target_retains_one_install_receipt_until_terminal_gate) source, "\ngcs_block_resource_x_target_acquire_internal(", "\nResourceXApplyResult\ncluster_gcs_resource_x_target_acquire_exact(", continuation_contract, lengthof(continuation_contract)); - driver = source != NULL - ? strstr(source, "\ngcs_block_resource_x_target_acquire_internal(") - : NULL; - driver_end = driver != NULL - ? strstr(driver, - "\nResourceXApplyResult\ncluster_gcs_resource_x_target_acquire_exact(") - : NULL; - valid_branch = driver != NULL - ? strstr(driver, "if (target_install_follow.valid)") - : NULL; - first_capture = valid_branch != NULL - ? strstr(valid_branch, - "gcs_block_resource_x_target_install_capture_coherent(") - : NULL; + driver + = source != NULL ? strstr(source, "\ngcs_block_resource_x_target_acquire_internal(") : NULL; + driver_end + = driver != NULL + ? strstr(driver, + "\nResourceXApplyResult\ncluster_gcs_resource_x_target_acquire_exact(") + : NULL; + valid_branch = driver != NULL ? strstr(driver, "if (target_install_follow.valid)") : NULL; + first_capture + = valid_branch != NULL + ? strstr(valid_branch, "gcs_block_resource_x_target_install_capture_coherent(") + : NULL; UT_ASSERT_NOT_NULL(driver); UT_ASSERT_NOT_NULL(driver_end); UT_ASSERT_NOT_NULL(valid_branch); UT_ASSERT_NOT_NULL(first_capture); if (driver != NULL && driver_end != NULL) { - old_boolean = strstr(driver, - "cluster_pcm_lock_resource_x_bootstrap_round_target_install_inflight_exact("); + old_boolean = strstr( + driver, "cluster_pcm_lock_resource_x_bootstrap_round_target_install_inflight_exact("); UT_ASSERT(old_boolean == NULL || old_boolean >= driver_end); } if (valid_branch != NULL && first_capture != NULL) { @@ -6238,17 +5870,16 @@ UT_TEST(test_resource_x_target_retains_one_install_receipt_until_terminal_gate) UT_TEST(test_resource_x_target_preuse_successor_discards_only_local_receipt) { - static const char *const preuse_contract[] = { - "bool target_install_preuse_retry_seen = false", - "RESOURCE_X_TARGET_INSTALL_PREUSE_RETRY", - "target_install_preuse_retry_seen = true", - "cluster_pcm_lock_resource_x_bootstrap_round_target_install_wait_exact(", - "if (wait_result == RESOURCE_X_APPLY_DUPLICATE)", - "memset(&target_install_follow, 0,", - "sizeof(target_install_follow))", - "target_install_preuse_retry_seen = false", - "continue;" - }; + static const char *const preuse_contract[] + = { "bool target_install_preuse_retry_seen = false", + "RESOURCE_X_TARGET_INSTALL_PREUSE_RETRY", + "target_install_preuse_retry_seen = true", + "cluster_pcm_lock_resource_x_bootstrap_round_target_install_wait_exact(", + "if (wait_result == RESOURCE_X_APPLY_DUPLICATE)", + "memset(&target_install_follow, 0,", + "sizeof(target_install_follow))", + "target_install_preuse_retry_seen = false", + "continue;" }; char *source = read_gcs_block_source(); const char *driver; const char *driver_end; @@ -6262,24 +5893,18 @@ UT_TEST(test_resource_x_target_preuse_successor_discards_only_local_receipt) * successor, clear shared state, or mint a new caller deadline. */ assert_ordered_in_function( source, "\ngcs_block_resource_x_target_acquire_internal(", - "\nResourceXApplyResult\ncluster_gcs_resource_x_target_acquire_exact(", - preuse_contract, lengthof(preuse_contract)); - driver = source != NULL - ? strstr(source, "\ngcs_block_resource_x_target_acquire_internal(") - : NULL; - driver_end = driver != NULL - ? strstr(driver, - "\nResourceXApplyResult\ncluster_gcs_resource_x_target_acquire_exact(") - : NULL; - preuse = driver != NULL - ? strstr(driver, "RESOURCE_X_TARGET_INSTALL_PREUSE_RETRY") - : NULL; - preuse_end = preuse != NULL - ? strstr(preuse, "RESOURCE_X_TARGET_INSTALL_INFLIGHT") - : NULL; - terminal_jump = preuse != NULL - ? strstr(preuse, "goto target_install_terminal_recheck") - : NULL; + "\nResourceXApplyResult\ncluster_gcs_resource_x_target_acquire_exact(", preuse_contract, + lengthof(preuse_contract)); + driver + = source != NULL ? strstr(source, "\ngcs_block_resource_x_target_acquire_internal(") : NULL; + driver_end + = driver != NULL + ? strstr(driver, + "\nResourceXApplyResult\ncluster_gcs_resource_x_target_acquire_exact(") + : NULL; + preuse = driver != NULL ? strstr(driver, "RESOURCE_X_TARGET_INSTALL_PREUSE_RETRY") : NULL; + preuse_end = preuse != NULL ? strstr(preuse, "RESOURCE_X_TARGET_INSTALL_INFLIGHT") : NULL; + terminal_jump = preuse != NULL ? strstr(preuse, "goto target_install_terminal_recheck") : NULL; UT_ASSERT_NOT_NULL(driver); UT_ASSERT_NOT_NULL(driver_end); UT_ASSERT_NOT_NULL(preuse); @@ -6287,8 +5912,8 @@ UT_TEST(test_resource_x_target_preuse_successor_discards_only_local_receipt) if (preuse != NULL && preuse_end != NULL) UT_ASSERT(terminal_jump == NULL || terminal_jump >= preuse_end); if (driver != NULL && driver_end != NULL) { - const char *deadline_reset = strstr(preuse, - "absolute_deadline_us = gcs_block_pcm_x_saturating_add_us("); + const char *deadline_reset = strstr( + preuse, "absolute_deadline_us\n\t\t\t\t\t= gcs_block_pcm_x_saturating_add_us("); UT_ASSERT(deadline_reset == NULL || deadline_reset >= driver_end); } @@ -6312,7 +5937,7 @@ UT_TEST(test_resource_x_target_waits_out_unrelated_local_pending_reservation) pending.tag.relNumber = 16384; pending.tag.forkNum = MAIN_FORKNUM; pending.tag.blockNum = 224; - pending.pcm_state = (uint8) PCM_STATE_N; + pending.pcm_state = (uint8)PCM_STATE_N; pending.generation = 6; pending.reservation_token = 77; pending.flags = PCM_OWN_FLAG_GRANT_PENDING; @@ -6322,70 +5947,60 @@ UT_TEST(test_resource_x_target_waits_out_unrelated_local_pending_reservation) * may overlap an unrelated Resource-X requester round, so it is bounded * local contention rather than a reason to fence the cluster-wide gate. */ UT_ASSERT(cluster_gcs_resource_x_target_local_n_reservation_retry_exact( - &pending, CLUSTER_PCM_OWN_OK, &live, - UINT64_C(100), UINT64_C(200))); + &pending, CLUSTER_PCM_OWN_OK, &live, UINT64_C(100), UINT64_C(200))); live.reservation_token++; UT_ASSERT(cluster_gcs_resource_x_target_local_n_reservation_retry_exact( - &pending, CLUSTER_PCM_OWN_OK, &live, - UINT64_C(100), UINT64_C(200))); + &pending, CLUSTER_PCM_OWN_OK, &live, UINT64_C(100), UINT64_C(200))); live.flags = 0; UT_ASSERT(cluster_gcs_resource_x_target_local_n_reservation_retry_exact( - &pending, CLUSTER_PCM_OWN_OK, &live, - UINT64_C(100), UINT64_C(200))); + &pending, CLUSTER_PCM_OWN_OK, &live, UINT64_C(100), UINT64_C(200))); /* Invalid reservation shapes, descriptor drift, failed snapshots, and an * exhausted caller deadline never acquire or extend authority. */ pending.reservation_token = 0; UT_ASSERT(!cluster_gcs_resource_x_target_local_n_reservation_retry_exact( - &pending, CLUSTER_PCM_OWN_OK, &live, - UINT64_C(100), UINT64_C(200))); + &pending, CLUSTER_PCM_OWN_OK, &live, UINT64_C(100), UINT64_C(200))); pending.reservation_token = 77; pending.writer_activation_token = 77; UT_ASSERT(!cluster_gcs_resource_x_target_local_n_reservation_retry_exact( - &pending, CLUSTER_PCM_OWN_OK, &live, - UINT64_C(100), UINT64_C(200))); + &pending, CLUSTER_PCM_OWN_OK, &live, UINT64_C(100), UINT64_C(200))); pending.writer_activation_token = 0; live.tag.blockNum++; UT_ASSERT(!cluster_gcs_resource_x_target_local_n_reservation_retry_exact( - &pending, CLUSTER_PCM_OWN_OK, &live, - UINT64_C(100), UINT64_C(200))); + &pending, CLUSTER_PCM_OWN_OK, &live, UINT64_C(100), UINT64_C(200))); live.tag = pending.tag; UT_ASSERT(!cluster_gcs_resource_x_target_local_n_reservation_retry_exact( - &pending, CLUSTER_PCM_OWN_STALE, &live, - UINT64_C(100), UINT64_C(200))); + &pending, CLUSTER_PCM_OWN_STALE, &live, UINT64_C(100), UINT64_C(200))); UT_ASSERT(cluster_gcs_resource_x_target_local_n_reservation_retry_exact( &pending, CLUSTER_PCM_OWN_OK, &live, UINT64_C(200), UINT64_C(200))); /* Production must consume this transient before the clean-N assertion * predicate sees GRANT_PENDING and maps its INVALID result to recovery. */ source = read_gcs_block_source(); - driver = source != NULL - ? strstr(source, "\ngcs_block_resource_x_target_acquire_internal(") - : NULL; - pending_branch = driver != NULL - ? strstr(driver, "own.flags == PCM_OWN_FLAG_GRANT_PENDING") - : NULL; + driver + = source != NULL ? strstr(source, "\ngcs_block_resource_x_target_acquire_internal(") : NULL; + pending_branch + = driver != NULL ? strstr(driver, "own.flags == PCM_OWN_FLAG_GRANT_PENDING") : NULL; retry_exact = pending_branch != NULL - ? strstr(pending_branch, - "cluster_gcs_resource_x_target_local_n_reservation_retry_exact(") - : NULL; + ? strstr(pending_branch, + "cluster_gcs_resource_x_target_local_n_reservation_retry_exact(") + : NULL; retry_wait = retry_exact != NULL - ? strstr(retry_exact, "diagnostic_stage = \"local-pending-reservation-wait\"") - : NULL; - generic_candidate = retry_wait != NULL - ? strstr(retry_wait, - "cluster_bufmgr_pcm_own_n_assertion_candidate_exact(") - : NULL; + ? strstr(retry_exact, "diagnostic_stage = \"local-pending-reservation-wait\"") + : NULL; + generic_candidate + = retry_wait != NULL + ? strstr(retry_wait, "cluster_bufmgr_pcm_own_n_assertion_candidate_exact(") + : NULL; UT_ASSERT_NOT_NULL(driver); UT_ASSERT_NOT_NULL(pending_branch); UT_ASSERT_NOT_NULL(retry_exact); UT_ASSERT_NOT_NULL(retry_wait); UT_ASSERT_NOT_NULL(generic_candidate); - if (pending_branch != NULL && retry_exact != NULL - && retry_wait != NULL && generic_candidate != NULL) - UT_ASSERT(pending_branch < retry_exact - && retry_exact < retry_wait - && retry_wait < generic_candidate); + if (pending_branch != NULL && retry_exact != NULL && retry_wait != NULL + && generic_candidate != NULL) + UT_ASSERT(pending_branch < retry_exact && retry_exact < retry_wait + && retry_wait < generic_candidate); free(source); } @@ -6405,7 +6020,7 @@ UT_TEST(test_resource_x_target_retries_clean_n_reservation_token_churn) before.tag.relNumber = 16384; before.tag.forkNum = MAIN_FORKNUM; before.tag.blockNum = 224; - before.pcm_state = (uint8) PCM_STATE_N; + before.pcm_state = (uint8)PCM_STATE_N; before.generation = 6; before.reservation_token = 29; live = before; @@ -6416,47 +6031,38 @@ UT_TEST(test_resource_x_target_retries_clean_n_reservation_token_churn) * generation and ownership fields prove that only the monotone reservation * token advanced; retrying under the original deadline grants no authority. */ UT_ASSERT(cluster_gcs_resource_x_target_local_n_reservation_retry_exact( - &before, CLUSTER_PCM_OWN_STALE, &live, - UINT64_C(100), UINT64_C(200))); + &before, CLUSTER_PCM_OWN_STALE, &live, UINT64_C(100), UINT64_C(200))); before.reservation_token = 0; UT_ASSERT(cluster_gcs_resource_x_target_local_n_reservation_retry_exact( - &before, CLUSTER_PCM_OWN_STALE, &live, - UINT64_C(100), UINT64_C(200))); + &before, CLUSTER_PCM_OWN_STALE, &live, UINT64_C(100), UINT64_C(200))); /* State, generation, ownership or non-monotone token drift is not the * completed pre-mutation reservation episode handled by this retry. */ before.reservation_token = 29; live.reservation_token = before.reservation_token; UT_ASSERT(!cluster_gcs_resource_x_target_local_n_reservation_retry_exact( - &before, CLUSTER_PCM_OWN_STALE, &live, - UINT64_C(100), UINT64_C(200))); + &before, CLUSTER_PCM_OWN_STALE, &live, UINT64_C(100), UINT64_C(200))); live.reservation_token = 28; UT_ASSERT(!cluster_gcs_resource_x_target_local_n_reservation_retry_exact( - &before, CLUSTER_PCM_OWN_STALE, &live, - UINT64_C(100), UINT64_C(200))); + &before, CLUSTER_PCM_OWN_STALE, &live, UINT64_C(100), UINT64_C(200))); live.reservation_token = 30; live.generation++; UT_ASSERT(!cluster_gcs_resource_x_target_local_n_reservation_retry_exact( - &before, CLUSTER_PCM_OWN_STALE, &live, - UINT64_C(100), UINT64_C(200))); + &before, CLUSTER_PCM_OWN_STALE, &live, UINT64_C(100), UINT64_C(200))); live.generation = before.generation; live.flags = PCM_OWN_FLAG_GRANT_PENDING; UT_ASSERT(cluster_gcs_resource_x_target_local_n_reservation_retry_exact( - &before, CLUSTER_PCM_OWN_STALE, &live, - UINT64_C(100), UINT64_C(200))); + &before, CLUSTER_PCM_OWN_STALE, &live, UINT64_C(100), UINT64_C(200))); live.flags = PCM_OWN_FLAG_GRANT_PENDING | PCM_OWN_FLAG_REVOKING; UT_ASSERT(!cluster_gcs_resource_x_target_local_n_reservation_retry_exact( - &before, CLUSTER_PCM_OWN_STALE, &live, - UINT64_C(100), UINT64_C(200))); + &before, CLUSTER_PCM_OWN_STALE, &live, UINT64_C(100), UINT64_C(200))); live.flags = 0; live.writer_activation_token = 1; UT_ASSERT(!cluster_gcs_resource_x_target_local_n_reservation_retry_exact( - &before, CLUSTER_PCM_OWN_STALE, &live, - UINT64_C(100), UINT64_C(200))); + &before, CLUSTER_PCM_OWN_STALE, &live, UINT64_C(100), UINT64_C(200))); live.writer_activation_token = 0; UT_ASSERT(!cluster_gcs_resource_x_target_local_n_reservation_retry_exact( - &before, CLUSTER_PCM_OWN_OK, &live, - UINT64_C(100), UINT64_C(200))); + &before, CLUSTER_PCM_OWN_OK, &live, UINT64_C(100), UINT64_C(200))); UT_ASSERT(cluster_gcs_resource_x_target_local_n_reservation_retry_exact( &before, CLUSTER_PCM_OWN_STALE, &live, UINT64_C(200), UINT64_C(200))); @@ -6464,20 +6070,17 @@ UT_TEST(test_resource_x_target_retries_clean_n_reservation_token_churn) * its read-only resampling boundary, after STALE and before first failure. * The narrower helper above still serves the pending-N reservation path. */ source = read_gcs_block_source(); - driver = source != NULL - ? strstr(source, "\ngcs_block_resource_x_target_acquire_internal(") - : NULL; + driver + = source != NULL ? strstr(source, "\ngcs_block_resource_x_target_acquire_internal(") : NULL; candidate = driver != NULL - ? strstr(driver, - "cluster_bufmgr_pcm_own_n_assertion_candidate_exact(") - : NULL; + ? strstr(driver, "cluster_bufmgr_pcm_own_n_assertion_candidate_exact(") + : NULL; retry_exact = candidate != NULL ? strstr(candidate, "cluster_gcs_resource_x_target_preassert_resample_exact(") : NULL; failure_record = retry_exact != NULL - ? strstr(retry_exact, - "gcs_block_resource_x_first_failure_record(") - : NULL; + ? strstr(retry_exact, "gcs_block_resource_x_first_failure_record(") + : NULL; UT_ASSERT_NOT_NULL(driver); UT_ASSERT_NOT_NULL(candidate); UT_ASSERT_NOT_NULL(retry_exact); @@ -6489,15 +6092,14 @@ UT_TEST(test_resource_x_target_retries_clean_n_reservation_token_churn) UT_TEST(test_resource_x_target_retries_only_exact_empty_round_x_to_n_drift) { - static const char *const retry_contract[] = { - "if (action == RESOURCE_X_BOOTSTRAP_ROUND_FAIL_CLOSED) {", - "cluster_bufmgr_pcm_own_snapshot(buf, &failure_live)", - "cluster_pcm_lock_resource_x_bootstrap_round_failure_snapshot_exact(", - "cluster_gcs_resource_x_dispatch_recheck_failure_mask(", - "cluster_gcs_resource_x_target_empty_round_drift_retry_exact(", - "continue;", - "diagnostic_stage = \"round-fail-closed\"" - }; + static const char *const retry_contract[] + = { "if (action == RESOURCE_X_BOOTSTRAP_ROUND_FAIL_CLOSED) {", + "cluster_bufmgr_pcm_own_snapshot(buf, &failure_live)", + "cluster_pcm_lock_resource_x_bootstrap_round_failure_snapshot_exact(", + "cluster_gcs_resource_x_dispatch_recheck_failure_mask(", + "cluster_gcs_resource_x_target_empty_round_drift_retry_exact(", + "continue;", + "diagnostic_stage = \"round-fail-closed\"" }; ClusterPcmOwnSnapshot before; ClusterPcmOwnSnapshot live; char *source; @@ -6508,11 +6110,11 @@ UT_TEST(test_resource_x_target_retries_only_exact_empty_round_x_to_n_drift) before.tag.relNumber = 16384; before.tag.forkNum = MAIN_FORKNUM; before.tag.blockNum = 222; - before.pcm_state = (uint8) PCM_STATE_X; + before.pcm_state = (uint8)PCM_STATE_X; before.generation = 57; before.reservation_token = 149; live = before; - live.pcm_state = (uint8) PCM_STATE_N; + live.pcm_state = (uint8)PCM_STATE_N; live.generation = 58; live.reservation_token = 150; @@ -6521,77 +6123,60 @@ UT_TEST(test_resource_x_target_retries_only_exact_empty_round_x_to_n_drift) * discarded only when the current descriptor is the exact one-step clean N * successor, no round exists, and the first R7 deadline is still live. */ UT_ASSERT(cluster_gcs_resource_x_target_empty_round_drift_retry_exact( - RESOURCE_X_BOOTSTRAP_ROUND_FAIL_CLOSED, false, false, - &before, CLUSTER_PCM_OWN_OK, &live, - RESOURCE_X_APPLY_NOT_FOUND, true, - UINT64_C(900), UINT64_C(1000))); + RESOURCE_X_BOOTSTRAP_ROUND_FAIL_CLOSED, false, false, &before, CLUSTER_PCM_OWN_OK, &live, + RESOURCE_X_APPLY_NOT_FOUND, true, UINT64_C(900), UINT64_C(1000))); /* Any wider drift, live round, expired deadline, or special acquisition * path remains fail closed. */ live.generation = 59; UT_ASSERT(!cluster_gcs_resource_x_target_empty_round_drift_retry_exact( - RESOURCE_X_BOOTSTRAP_ROUND_FAIL_CLOSED, false, false, - &before, CLUSTER_PCM_OWN_OK, &live, - RESOURCE_X_APPLY_NOT_FOUND, true, - UINT64_C(900), UINT64_C(1000))); + RESOURCE_X_BOOTSTRAP_ROUND_FAIL_CLOSED, false, false, &before, CLUSTER_PCM_OWN_OK, &live, + RESOURCE_X_APPLY_NOT_FOUND, true, UINT64_C(900), UINT64_C(1000))); live.generation = 58; live.reservation_token = 151; UT_ASSERT(!cluster_gcs_resource_x_target_empty_round_drift_retry_exact( - RESOURCE_X_BOOTSTRAP_ROUND_FAIL_CLOSED, false, false, - &before, CLUSTER_PCM_OWN_OK, &live, - RESOURCE_X_APPLY_NOT_FOUND, true, - UINT64_C(900), UINT64_C(1000))); + RESOURCE_X_BOOTSTRAP_ROUND_FAIL_CLOSED, false, false, &before, CLUSTER_PCM_OWN_OK, &live, + RESOURCE_X_APPLY_NOT_FOUND, true, UINT64_C(900), UINT64_C(1000))); live.reservation_token = 150; UT_ASSERT(!cluster_gcs_resource_x_target_empty_round_drift_retry_exact( - RESOURCE_X_BOOTSTRAP_ROUND_FAIL_CLOSED, false, false, - &before, CLUSTER_PCM_OWN_OK, &live, - RESOURCE_X_APPLY_APPLIED, true, - UINT64_C(900), UINT64_C(1000))); + RESOURCE_X_BOOTSTRAP_ROUND_FAIL_CLOSED, false, false, &before, CLUSTER_PCM_OWN_OK, &live, + RESOURCE_X_APPLY_APPLIED, true, UINT64_C(900), UINT64_C(1000))); UT_ASSERT(cluster_gcs_resource_x_target_empty_round_drift_retry_exact( RESOURCE_X_BOOTSTRAP_ROUND_FAIL_CLOSED, false, false, &before, CLUSTER_PCM_OWN_OK, &live, RESOURCE_X_APPLY_NOT_FOUND, true, UINT64_C(1000), UINT64_C(1000))); UT_ASSERT(!cluster_gcs_resource_x_target_empty_round_drift_retry_exact( - RESOURCE_X_BOOTSTRAP_ROUND_FAIL_CLOSED, true, false, - &before, CLUSTER_PCM_OWN_OK, &live, - RESOURCE_X_APPLY_NOT_FOUND, true, - UINT64_C(900), UINT64_C(1000))); + RESOURCE_X_BOOTSTRAP_ROUND_FAIL_CLOSED, true, false, &before, CLUSTER_PCM_OWN_OK, &live, + RESOURCE_X_APPLY_NOT_FOUND, true, UINT64_C(900), UINT64_C(1000))); UT_ASSERT(!cluster_gcs_resource_x_target_empty_round_drift_retry_exact( - RESOURCE_X_BOOTSTRAP_ROUND_FAIL_CLOSED, false, true, - &before, CLUSTER_PCM_OWN_OK, &live, - RESOURCE_X_APPLY_NOT_FOUND, true, - UINT64_C(900), UINT64_C(1000))); + RESOURCE_X_BOOTSTRAP_ROUND_FAIL_CLOSED, false, true, &before, CLUSTER_PCM_OWN_OK, &live, + RESOURCE_X_APPLY_NOT_FOUND, true, UINT64_C(900), UINT64_C(1000))); UT_ASSERT(!cluster_gcs_resource_x_target_empty_round_drift_retry_exact( - RESOURCE_X_BOOTSTRAP_ROUND_FAIL_CLOSED, false, false, - &before, CLUSTER_PCM_OWN_OK, &live, - RESOURCE_X_APPLY_NOT_FOUND, false, - UINT64_C(900), UINT64_C(1000))); - live.pcm_state = (uint8) PCM_STATE_S; + RESOURCE_X_BOOTSTRAP_ROUND_FAIL_CLOSED, false, false, &before, CLUSTER_PCM_OWN_OK, &live, + RESOURCE_X_APPLY_NOT_FOUND, false, UINT64_C(900), UINT64_C(1000))); + live.pcm_state = (uint8)PCM_STATE_S; UT_ASSERT(!cluster_gcs_resource_x_target_empty_round_drift_retry_exact( - RESOURCE_X_BOOTSTRAP_ROUND_FAIL_CLOSED, false, false, - &before, CLUSTER_PCM_OWN_OK, &live, - RESOURCE_X_APPLY_NOT_FOUND, true, - UINT64_C(900), UINT64_C(1000))); + RESOURCE_X_BOOTSTRAP_ROUND_FAIL_CLOSED, false, false, &before, CLUSTER_PCM_OWN_OK, &live, + RESOURCE_X_APPLY_NOT_FOUND, true, UINT64_C(900), UINT64_C(1000))); source = read_gcs_block_source(); assert_ordered_in_function( source, "\ngcs_block_resource_x_target_acquire_internal(", - "\nResourceXApplyResult\ncluster_gcs_resource_x_target_acquire_exact(", - retry_contract, lengthof(retry_contract)); + "\nResourceXApplyResult\ncluster_gcs_resource_x_target_acquire_exact(", retry_contract, + lengthof(retry_contract)); free(source); } UT_TEST(test_resource_x_target_waits_only_exact_retained_predecessor_after_cached_x_drift) { - static const char *const retry_contract[] = { - "if (action == RESOURCE_X_BOOTSTRAP_ROUND_FAIL_CLOSED) {", - "cluster_bufmgr_pcm_own_snapshot(buf, &failure_live)", - "cluster_gcs_resource_x_dispatch_recheck_failure_mask(", - "cluster_pcm_lock_resource_x_holder_pair_retained_fence_exact(", - "cluster_bufmgr_pcm_own_n_retained_release_inflight_exact(", - "cluster_gcs_resource_x_target_retained_predecessor_retry_exact(", - "continue;", - "diagnostic_stage = \"round-fail-closed\"" - }; + static const char *const retry_contract[] + = { "if (action == RESOURCE_X_BOOTSTRAP_ROUND_FAIL_CLOSED) {", + "cluster_bufmgr_pcm_own_snapshot(buf, &failure_live)", + "cluster_gcs_resource_x_dispatch_recheck_failure_mask(", + "cluster_pcm_lock_resource_x_holder_pair_retained_fence_exact(", + "cluster_bufmgr_pcm_own_n_retained_release_inflight_exact(", + "cluster_gcs_resource_x_target_retained_predecessor_retry_exact(", + "continue;", + "diagnostic_stage = \"round-fail-closed\"" }; ClusterPcmOwnSnapshot before; ClusterPcmOwnSnapshot live; char *source; @@ -6602,11 +6187,11 @@ UT_TEST(test_resource_x_target_waits_only_exact_retained_predecessor_after_cache before.tag.relNumber = 16384; before.tag.forkNum = MAIN_FORKNUM; before.tag.blockNum = 222; - before.pcm_state = (uint8) PCM_STATE_X; + before.pcm_state = (uint8)PCM_STATE_X; before.generation = 63; before.reservation_token = 177; live = before; - live.pcm_state = (uint8) PCM_STATE_N; + live.pcm_state = (uint8)PCM_STATE_N; live.flags = PCM_OWN_FLAG_REVOKING; live.generation = 64; live.reservation_token = 178; @@ -6615,40 +6200,33 @@ UT_TEST(test_resource_x_target_waits_only_exact_retained_predecessor_after_cache * the independently revalidated retained pair and physical N+PI carrier bind * the exact one-generation successor under the original live deadline. */ UT_ASSERT(cluster_gcs_resource_x_target_retained_predecessor_retry_exact( - RESOURCE_X_BOOTSTRAP_ROUND_FAIL_CLOSED, false, false, - &before, CLUSTER_PCM_OWN_OK, &live, true, true, true, - UINT64_C(900), UINT64_C(1000))); + RESOURCE_X_BOOTSTRAP_ROUND_FAIL_CLOSED, false, false, &before, CLUSTER_PCM_OWN_OK, &live, + true, true, true, UINT64_C(900), UINT64_C(1000))); /* Every missing half, widened generation, non-monotonic token, authority * drift, special acquisition path, or exhausted deadline stays fail closed. */ UT_ASSERT(!cluster_gcs_resource_x_target_retained_predecessor_retry_exact( - RESOURCE_X_BOOTSTRAP_ROUND_FAIL_CLOSED, false, false, - &before, CLUSTER_PCM_OWN_OK, &live, false, true, true, - UINT64_C(900), UINT64_C(1000))); + RESOURCE_X_BOOTSTRAP_ROUND_FAIL_CLOSED, false, false, &before, CLUSTER_PCM_OWN_OK, &live, + false, true, true, UINT64_C(900), UINT64_C(1000))); UT_ASSERT(!cluster_gcs_resource_x_target_retained_predecessor_retry_exact( - RESOURCE_X_BOOTSTRAP_ROUND_FAIL_CLOSED, false, false, - &before, CLUSTER_PCM_OWN_OK, &live, true, false, true, - UINT64_C(900), UINT64_C(1000))); + RESOURCE_X_BOOTSTRAP_ROUND_FAIL_CLOSED, false, false, &before, CLUSTER_PCM_OWN_OK, &live, + true, false, true, UINT64_C(900), UINT64_C(1000))); live.generation = 65; UT_ASSERT(!cluster_gcs_resource_x_target_retained_predecessor_retry_exact( - RESOURCE_X_BOOTSTRAP_ROUND_FAIL_CLOSED, false, false, - &before, CLUSTER_PCM_OWN_OK, &live, true, true, true, - UINT64_C(900), UINT64_C(1000))); + RESOURCE_X_BOOTSTRAP_ROUND_FAIL_CLOSED, false, false, &before, CLUSTER_PCM_OWN_OK, &live, + true, true, true, UINT64_C(900), UINT64_C(1000))); live.generation = 64; live.reservation_token = before.reservation_token; UT_ASSERT(!cluster_gcs_resource_x_target_retained_predecessor_retry_exact( - RESOURCE_X_BOOTSTRAP_ROUND_FAIL_CLOSED, false, false, - &before, CLUSTER_PCM_OWN_OK, &live, true, true, true, - UINT64_C(900), UINT64_C(1000))); + RESOURCE_X_BOOTSTRAP_ROUND_FAIL_CLOSED, false, false, &before, CLUSTER_PCM_OWN_OK, &live, + true, true, true, UINT64_C(900), UINT64_C(1000))); live.reservation_token = 178; UT_ASSERT(!cluster_gcs_resource_x_target_retained_predecessor_retry_exact( - RESOURCE_X_BOOTSTRAP_ROUND_FAIL_CLOSED, false, false, - &before, CLUSTER_PCM_OWN_OK, &live, true, true, false, - UINT64_C(900), UINT64_C(1000))); + RESOURCE_X_BOOTSTRAP_ROUND_FAIL_CLOSED, false, false, &before, CLUSTER_PCM_OWN_OK, &live, + true, true, false, UINT64_C(900), UINT64_C(1000))); UT_ASSERT(!cluster_gcs_resource_x_target_retained_predecessor_retry_exact( - RESOURCE_X_BOOTSTRAP_ROUND_FAIL_CLOSED, true, false, - &before, CLUSTER_PCM_OWN_OK, &live, true, true, true, - UINT64_C(900), UINT64_C(1000))); + RESOURCE_X_BOOTSTRAP_ROUND_FAIL_CLOSED, true, false, &before, CLUSTER_PCM_OWN_OK, &live, + true, true, true, UINT64_C(900), UINT64_C(1000))); UT_ASSERT(cluster_gcs_resource_x_target_retained_predecessor_retry_exact( RESOURCE_X_BOOTSTRAP_ROUND_FAIL_CLOSED, false, false, &before, CLUSTER_PCM_OWN_OK, &live, true, true, true, UINT64_C(1000), UINT64_C(1000))); @@ -6656,8 +6234,8 @@ UT_TEST(test_resource_x_target_waits_only_exact_retained_predecessor_after_cache source = read_gcs_block_source(); assert_ordered_in_function( source, "\ngcs_block_resource_x_target_acquire_internal(", - "\nResourceXApplyResult\ncluster_gcs_resource_x_target_acquire_exact(", - retry_contract, lengthof(retry_contract)); + "\nResourceXApplyResult\ncluster_gcs_resource_x_target_acquire_exact(", retry_contract, + lengthof(retry_contract)); free(source); } @@ -6742,16 +6320,16 @@ UT_TEST(test_resource_x_direct_init_reprobes_exact_same_round_after_candidate_dr * deadline is reused. */ assert_ordered_in_function( source, "\ngcs_block_resource_x_target_acquire_internal(", - "\nResourceXApplyResult\ncluster_gcs_resource_x_target_acquire_exact(", - drift_contract, lengthof(drift_contract)); + "\nResourceXApplyResult\ncluster_gcs_resource_x_target_acquire_exact(", drift_contract, + lengthof(drift_contract)); candidate = strstr(source, "if (direct_init_pending_n)"); - receipt_capture = candidate != NULL - ? strstr(candidate, - "gcs_block_resource_x_target_install_capture_coherent(") - : NULL; + receipt_capture + = candidate != NULL + ? strstr(candidate, "gcs_block_resource_x_target_install_capture_coherent(") + : NULL; accept_receipt = receipt_capture != NULL - ? strstr(receipt_capture, "RESOURCE_X_TARGET_INSTALL_INFLIGHT") - : NULL; + ? strstr(receipt_capture, "RESOURCE_X_TARGET_INSTALL_INFLIGHT") + : NULL; UT_ASSERT(candidate != NULL); UT_ASSERT(receipt_capture != NULL); UT_ASSERT(accept_receipt != NULL); @@ -6761,21 +6339,20 @@ UT_TEST(test_resource_x_direct_init_reprobes_exact_same_round_after_candidate_dr UT_TEST(test_resource_x_pre_dispatch_drift_recaptures_current_authority_under_same_deadline) { - static const char *const rebind_contract[] = { - "dispatch_recheck_failure_mask", - "!= RESOURCE_X_DISPATCH_RECHECK_OK", - "== RESOURCE_X_BOOTSTRAP_ROUND_DISPATCH_REQUEST", - "!join_only", - "gcs_block_resource_x_gate_session_snapshot_result(", - "cluster_gcs_pcm_x_auth_result_retryable(", - "cluster_pcm_lock_resource_x_bootstrap_round_discard_pre_assert_authority_drift_exact(", - "absolute_deadline_us", - "gate = rebound_gate", - "master_session = rebound_master_session", - "requester_sender_connection_generation", - "master_ingress_connection_generation", - "continue;" - }; + static const char *const rebind_contract[] + = { "dispatch_recheck_failure_mask", + "!= RESOURCE_X_DISPATCH_RECHECK_OK", + "== RESOURCE_X_BOOTSTRAP_ROUND_DISPATCH_REQUEST", + "!join_only", + "gcs_block_resource_x_gate_session_snapshot_result(", + "cluster_gcs_pcm_x_auth_result_retryable(", + "cluster_pcm_lock_resource_x_bootstrap_round_discard_pre_assert_authority_drift_exact(", + "absolute_deadline_us", + "gate = rebound_gate", + "master_session = rebound_master_session", + "requester_sender_connection_generation", + "master_ingress_connection_generation", + "continue;" }; char *source = read_gcs_block_source(); /* D1 AUTHORITY_DRIFT: before kind-9 transport/ASSERT authority exists, @@ -6784,8 +6361,8 @@ UT_TEST(test_resource_x_pre_dispatch_drift_recaptures_current_authority_under_sa * ASSERT/post-mutation shapes and join-only followers remain refusals. */ assert_ordered_in_function( source, "\ngcs_block_resource_x_target_acquire_internal(", - "\nResourceXApplyResult\ncluster_gcs_resource_x_target_acquire_exact(", - rebind_contract, lengthof(rebind_contract)); + "\nResourceXApplyResult\ncluster_gcs_resource_x_target_acquire_exact(", rebind_contract, + lengthof(rebind_contract)); free(source); } @@ -6827,12 +6404,9 @@ UT_TEST(test_resource_x_target_eviction_freezes_before_local_n_and_publishes_sam "plan->release_admitted = true", "cluster_pcm_lock_resource_x_target_evict_commit_exact(", "cluster_semantic_activation_leave(&admission)" }; - static const char *const abort_contract[] = { - "!plan->prepared", - "plan->local_n_committed || plan->release_admitted", - "cluster_pcm_lock_resource_x_target_evict_abort_exact(", - "plan->prepared = false" - }; + static const char *const abort_contract[] + = { "!plan->prepared", "plan->local_n_committed || plan->release_admitted", + "cluster_pcm_lock_resource_x_target_evict_abort_exact(", "plan->prepared = false" }; char *source = read_gcs_block_source(); const char *publish; const char *publish_end; @@ -6851,12 +6425,14 @@ UT_TEST(test_resource_x_target_eviction_freezes_before_local_n_and_publishes_sam publish_contract, lengthof(publish_contract)); assert_ordered_in_function( source, "\ncluster_gcs_resource_x_target_evict_abort_exact(", - "\nResourceXApplyResult\ncluster_gcs_resource_x_target_acquire_exact(", - abort_contract, lengthof(abort_contract)); - publish = strstr(source, - "\ncluster_gcs_resource_x_target_evict_publish_exact("); - publish_end = publish == NULL ? NULL : strstr(publish, - "\nResourceXApplyResult\ncluster_gcs_resource_x_target_evict_abort_exact("); + "\nResourceXApplyResult\ncluster_gcs_resource_x_target_acquire_exact(", abort_contract, + lengthof(abort_contract)); + publish = strstr(source, "\ncluster_gcs_resource_x_target_evict_publish_exact("); + publish_end + = publish == NULL + ? NULL + : strstr(publish, + "\nResourceXApplyResult\ncluster_gcs_resource_x_target_evict_abort_exact("); UT_ASSERT_NOT_NULL(publish); UT_ASSERT_NOT_NULL(publish_end); if (publish != NULL && publish_end != NULL) { @@ -6864,8 +6440,7 @@ UT_TEST(test_resource_x_target_eviction_freezes_before_local_n_and_publishes_sam UT_ASSERT(encode == NULL || encode >= publish_end); } - UT_ASSERT_NULL(strstr(source, - "cluster_gcs_resource_x_target_evict_release_exact(")); + UT_ASSERT_NULL(strstr(source, "cluster_gcs_resource_x_target_evict_release_exact(")); free(source); } @@ -6885,38 +6460,33 @@ UT_TEST(test_resource_x_target_waits_for_exact_post_release_settlement_window) const char *deadline_fail_closed; const char *new_round; - driver = source != NULL - ? strstr(source, "\ngcs_block_resource_x_target_acquire_internal(") - : NULL; - driver_end = driver != NULL - ? strstr(driver, "\nResourceXApplyResult\n" - "cluster_gcs_resource_x_target_acquire_exact(") - : NULL; + driver + = source != NULL ? strstr(source, "\ngcs_block_resource_x_target_acquire_internal(") : NULL; + driver_end = driver != NULL ? strstr(driver, "\nResourceXApplyResult\n" + "cluster_gcs_resource_x_target_acquire_exact(") + : NULL; post_mutation_state = driver != NULL - ? strstr(driver, "bool target_retained_release_post_mutation = false") - : NULL; - pair_check = driver != NULL - ? strstr(driver, - "cluster_pcm_lock_resource_x_holder_pair_retained_fence_exact(") - : NULL; + ? strstr(driver, "bool target_retained_release_post_mutation = false") + : NULL; + pair_check + = driver != NULL + ? strstr(driver, "cluster_pcm_lock_resource_x_holder_pair_retained_fence_exact(") + : NULL; buffer_check = pair_check != NULL ? strstr(pair_check, "cluster_bufmgr_pcm_own_n_predecessor_observe_exact(") : NULL; post_mutation_classify = buffer_check != NULL - ? strstr(buffer_check, - "target_retained_release_post_mutation") - : NULL; + ? strstr(buffer_check, "target_retained_release_post_mutation") + : NULL; wait_branch = post_mutation_classify != NULL - ? strstr(post_mutation_classify, - "if (target_retained_release_inflight)") - : NULL; + ? strstr(post_mutation_classify, "if (target_retained_release_inflight)") + : NULL; drift_guard = wait_branch != NULL - ? strstr(wait_branch, - "if (!cluster_semantic_activation_recheck(&admission)") - : NULL; + ? strstr(wait_branch, "if (!cluster_semantic_activation_recheck(&admission)") + : NULL; drift_fail_closed = drift_guard != NULL - ? strstr(drift_guard, "gcs_block_resource_x_fail_closed_current()") - : NULL; + ? strstr(drift_guard, "gcs_block_resource_x_fail_closed_current()") + : NULL; deadline_guard = drift_fail_closed != NULL ? strstr(drift_fail_closed, "CHECK_FOR_INTERRUPTS()") : NULL; deadline_fail_closed @@ -6924,8 +6494,8 @@ UT_TEST(test_resource_x_target_waits_for_exact_post_release_settlement_window) ? strstr(deadline_guard, "cluster_pcm_lock_resource_x_predecessor_wait_exact(") : NULL; new_round = deadline_fail_closed != NULL - ? strstr(deadline_fail_closed, "diagnostic_stage = \"round-step\"") - : NULL; + ? strstr(deadline_fail_closed, "diagnostic_stage = \"round-step\"") + : NULL; UT_ASSERT_NOT_NULL(driver); UT_ASSERT_NOT_NULL(driver_end); @@ -6939,22 +6509,15 @@ UT_TEST(test_resource_x_target_waits_for_exact_post_release_settlement_window) UT_ASSERT_NOT_NULL(deadline_guard); UT_ASSERT_NOT_NULL(deadline_fail_closed); UT_ASSERT_NOT_NULL(new_round); - if (driver_end != NULL && post_mutation_state != NULL - && pair_check != NULL && buffer_check != NULL - && post_mutation_classify != NULL && wait_branch != NULL - && drift_guard != NULL && drift_fail_closed != NULL - && deadline_guard != NULL && deadline_fail_closed != NULL - && new_round != NULL) - UT_ASSERT(post_mutation_state < pair_check - && pair_check < buffer_check - && buffer_check < post_mutation_classify - && post_mutation_classify < wait_branch - && wait_branch < drift_guard - && drift_guard < drift_fail_closed - && drift_fail_closed < deadline_guard - && deadline_guard < deadline_fail_closed - && deadline_fail_closed < new_round - && new_round < driver_end); + if (driver_end != NULL && post_mutation_state != NULL && pair_check != NULL + && buffer_check != NULL && post_mutation_classify != NULL && wait_branch != NULL + && drift_guard != NULL && drift_fail_closed != NULL && deadline_guard != NULL + && deadline_fail_closed != NULL && new_round != NULL) + UT_ASSERT(post_mutation_state < pair_check && pair_check < buffer_check + && buffer_check < post_mutation_classify && post_mutation_classify < wait_branch + && wait_branch < drift_guard && drift_guard < drift_fail_closed + && drift_fail_closed < deadline_guard && deadline_guard < deadline_fail_closed + && deadline_fail_closed < new_round && new_round < driver_end); free(source); } @@ -6968,30 +6531,24 @@ UT_TEST(test_recovering_denial_records_exact_master_gate_predicates) if (source == NULL) return; handler = strstr(source, "\ncluster_gcs_handle_block_request_envelope("); - handler_end = handler != NULL - ? strstr(handler, "\ncluster_gcs_handle_block_reply_envelope(") - : NULL; + handler_end + = handler != NULL ? strstr(handler, "\ncluster_gcs_handle_block_reply_envelope(") : NULL; UT_ASSERT_NOT_NULL(handler); UT_ASSERT_NOT_NULL(handler_end); - if (handler != NULL && handler_end != NULL) - { - const char *master_gate = strstr(handler, - "GCS block recovering master-gate diagnostic"); - const char *phase_gate = strstr(handler, - "GCS block recovering phase-gate diagnostic"); + if (handler != NULL && handler_end != NULL) { + const char *master_gate = strstr(handler, "GCS block recovering master-gate diagnostic"); + const char *phase_gate = strstr(handler, "GCS block recovering phase-gate diagnostic"); UT_ASSERT_NOT_NULL(master_gate); UT_ASSERT_NOT_NULL(phase_gate); - if (master_gate != NULL) - { + if (master_gate != NULL) { UT_ASSERT_NOT_NULL(strstr(master_gate, "in_quorum=%d")); UT_ASSERT_NOT_NULL(strstr(master_gate, "member=%d")); UT_ASSERT_NOT_NULL(strstr(master_gate, "join_active=%d")); UT_ASSERT_NOT_NULL(strstr(master_gate, "join_rebuilt=%d")); UT_ASSERT(master_gate < handler_end); } - if (phase_gate != NULL) - { + if (phase_gate != NULL) { UT_ASSERT_NOT_NULL(strstr(phase_gate, "static_master=%d")); UT_ASSERT_NOT_NULL(strstr(phase_gate, "peer_state=%d")); UT_ASSERT_NOT_NULL(strstr(phase_gate, "recovery_in_progress=%d")); @@ -7003,14 +6560,13 @@ UT_TEST(test_recovering_denial_records_exact_master_gate_predicates) UT_TEST(test_resource_x_high_rate_diagnostics_are_time_sampled) { - static const char *const gcs_diagnostics[] = { - "Resource-X kind-9 request diagnostic", - "Resource-X kind-9 ACK diagnostic", - "Resource-X source settlement ACK diagnostic", - "Resource-X source settlement ACK ingress diagnostic", - "Resource-X install settlement diagnostic", - "Resource-X frame ingress diagnostic" - }; + static const char *const gcs_diagnostics[] + = { "Resource-X kind-9 request diagnostic", + "Resource-X kind-9 ACK diagnostic", + "Resource-X source settlement ACK diagnostic", + "Resource-X source settlement ACK ingress diagnostic", + "Resource-X install settlement diagnostic", + "Resource-X frame ingress diagnostic" }; char *gcs_source = read_gcs_block_source(); char *pcm_source = read_source_path(PCM_LOCK_SOURCE_PATH); int i; @@ -7021,31 +6577,24 @@ UT_TEST(test_resource_x_high_rate_diagnostics_are_time_sampled) * outcomes remain unsampled at their call sites. */ UT_ASSERT_NOT_NULL(gcs_source); UT_ASSERT_NOT_NULL(pcm_source); - if (gcs_source != NULL) - { - UT_ASSERT_NOT_NULL(strstr(gcs_source, - "GCS_BLOCK_RESOURCE_X_DIAGNOSTIC_INTERVAL_US UINT64_C(250000)")); - UT_ASSERT_NOT_NULL(strstr(gcs_source, - "gcs_block_resource_x_diagnostic_next_log_at")); - UT_ASSERT_NOT_NULL(strstr(gcs_source, - "gcs_block_resource_x_diagnostic_should_log(")); - UT_ASSERT_NOT_NULL(strstr(gcs_source, - "result != RESOURCE_X_APPLY_APPLIED\n" - "\t\t\t&& result != RESOURCE_X_APPLY_DUPLICATE")); + if (gcs_source != NULL) { + UT_ASSERT_NOT_NULL( + strstr(gcs_source, "GCS_BLOCK_RESOURCE_X_DIAGNOSTIC_INTERVAL_US UINT64_C(250000)")); + UT_ASSERT_NOT_NULL(strstr(gcs_source, "gcs_block_resource_x_diagnostic_next_log_at")); + UT_ASSERT_NOT_NULL(strstr(gcs_source, "gcs_block_resource_x_diagnostic_should_log(")); + UT_ASSERT_NOT_NULL(strstr(gcs_source, "result != RESOURCE_X_APPLY_APPLIED " + "&& result != RESOURCE_X_APPLY_DUPLICATE")); for (i = 0; i < lengthof(gcs_diagnostics); i++) UT_ASSERT_NOT_NULL(strstr(gcs_source, gcs_diagnostics[i])); } - if (pcm_source != NULL) - { - UT_ASSERT_NOT_NULL(strstr(pcm_source, - "PCM_RESOURCE_X_DISPATCH_DIAGNOSTIC_INTERVAL_US UINT64_C(250000)")); - UT_ASSERT_NOT_NULL(strstr(pcm_source, - "pcm_resource_x_dispatch_diagnostic_next_log_at")); - UT_ASSERT_NOT_NULL(strstr(pcm_source, - "pcm_resource_x_dispatch_diagnostic_should_log()")); + if (pcm_source != NULL) { + UT_ASSERT_NOT_NULL( + strstr(pcm_source, "PCM_RESOURCE_X_DISPATCH_DIAGNOSTIC_INTERVAL_US UINT64_C(250000)")); + UT_ASSERT_NOT_NULL(strstr(pcm_source, "pcm_resource_x_dispatch_diagnostic_next_log_at")); + UT_ASSERT_NOT_NULL(strstr(pcm_source, "pcm_resource_x_dispatch_diagnostic_should_log()")); UT_ASSERT_NOT_NULL(strstr(pcm_source, - "if (pcm_resource_x_dispatch_diagnostic_should_log())\n" - "\t\t\t\tereport(LOG,")); + "if (pcm_resource_x_dispatch_diagnostic_should_log())\n" + "\t\t\t\tereport(LOG,")); } free(gcs_source); free(pcm_source); @@ -7073,10 +6622,10 @@ UT_TEST(test_resource_x_client_reason_is_exact_and_not_guessed_from_bad_state) UT_ASSERT_NOT_NULL(strstr(gcs_source, "gcs_resource_x_acquire_diagnostic.valid = false;")); UT_ASSERT_NOT_NULL(strstr(gcs_source, "cluster_pcm_rx_last_step_head_failure()")); UT_ASSERT_NOT_NULL(strstr(gcs_source, "cluster_pcm_rx_take_wait_failure()")); - UT_ASSERT_NOT_NULL(strstr(gcs_source, - "diagnostic_wait_failure == PCM_RX_WAIT_CALLER_DEADLINE_EXPIRED")); - UT_ASSERT_NOT_NULL(strstr(gcs_source, - "diagnostic_wait_failure == PCM_RX_WAIT_HEAD_NO_PROGRESS_EXPIRED")); + UT_ASSERT_NOT_NULL( + strstr(gcs_source, "diagnostic_wait_failure == PCM_RX_WAIT_CALLER_DEADLINE_EXPIRED")); + UT_ASSERT_NOT_NULL( + strstr(gcs_source, "diagnostic_wait_failure == PCM_RX_WAIT_HEAD_NO_PROGRESS_EXPIRED")); } if (bufmgr_source != NULL) { UT_ASSERT_NOT_NULL(strstr(bufmgr_source, "PGRAC_FAMILY=RESOURCE_X PGRAC_REASON=%s")); @@ -7089,31 +6638,23 @@ UT_TEST(test_resource_x_client_reason_is_exact_and_not_guessed_from_bad_state) UT_TEST(test_read_image_shared_marker_has_one_bufmgr_product_publisher) { - static const char *const marker_assignment - = "buf->pcm_state = (uint8) PCM_STATE_READ_IMAGE;"; + static const char *const marker_assignment = "buf->pcm_state = (uint8) PCM_STATE_READ_IMAGE;"; char *gcs_source = read_gcs_block_source(); char *bufmgr_source = read_source_path(BUFMGR_SOURCE_PATH); const char *publisher; UT_ASSERT_NOT_NULL(gcs_source); UT_ASSERT_NOT_NULL(bufmgr_source); - if (gcs_source != NULL) - { - UT_ASSERT_NULL(strstr(gcs_source, - "buf->pcm_state = (uint8)PCM_STATE_READ_IMAGE;")); - UT_ASSERT_NULL(strstr(gcs_source, - "buf->pcm_state = (uint8) PCM_STATE_READ_IMAGE;")); + if (gcs_source != NULL) { + UT_ASSERT_NULL(strstr(gcs_source, "buf->pcm_state = (uint8)PCM_STATE_READ_IMAGE;")); + UT_ASSERT_NULL(strstr(gcs_source, "buf->pcm_state = (uint8) PCM_STATE_READ_IMAGE;")); } - if (bufmgr_source != NULL) - { + if (bufmgr_source != NULL) { publisher = strstr(bufmgr_source, marker_assignment); UT_ASSERT_NOT_NULL(publisher); - if (publisher != NULL) - { - UT_ASSERT_NULL(strstr(publisher + strlen(marker_assignment), - marker_assignment)); - UT_ASSERT_NOT_NULL(strstr( - bufmgr_source, "cluster_pcm_own_publish_read_image_exact(")); + if (publisher != NULL) { + UT_ASSERT_NULL(strstr(publisher + strlen(marker_assignment), marker_assignment)); + UT_ASSERT_NOT_NULL(strstr(bufmgr_source, "cluster_pcm_own_publish_read_image_exact(")); } } free(gcs_source); @@ -7138,27 +6679,23 @@ UT_TEST(test_current_mx_updater_provenance_origin_plan_races) UT_ASSERT_NOT_NULL(source); if (source == NULL) return; - advance = strstr(source, - "\ngcs_block_current_mx_origin_updater_provenance_advance("); - advance_end = advance != NULL - ? strstr(advance, "\nstatic GcsBlockCurrentMxAdvance\n" - "gcs_block_current_mx_origin_advance(") - : NULL; + advance = strstr(source, "\ngcs_block_current_mx_origin_updater_provenance_advance("); + advance_end = advance != NULL ? strstr(advance, "\nstatic GcsBlockCurrentMxAdvance\n" + "gcs_block_current_mx_origin_advance(") + : NULL; freeze = advance != NULL - ? strstr(advance, - "cluster_runtime_visibility_origin_plan_freeze_data_held(") - : NULL; - canonical = freeze != NULL - ? strstr(freeze, - "cluster_runtime_visibility_origin_plan_sample_canonical_held(") - : NULL; + ? strstr(advance, "cluster_runtime_visibility_origin_plan_freeze_data_held(") + : NULL; + canonical + = freeze != NULL + ? strstr(freeze, "cluster_runtime_visibility_origin_plan_sample_canonical_held(") + : NULL; recheck = canonical != NULL - ? strstr(canonical, - "cluster_runtime_visibility_origin_plan_recheck_data_held(") - : NULL; + ? strstr(canonical, "cluster_runtime_visibility_origin_plan_recheck_data_held(") + : NULL; deadline = advance != NULL - ? strstr(advance, "gcs_block_r4_tx_origin_remaining_timeout_ms(context)") - : NULL; + ? strstr(advance, "gcs_block_r4_tx_origin_remaining_timeout_ms(context)") + : NULL; cleanup = strstr(source, "\ngcs_block_r4_tx_origin_context_clear("); UT_ASSERT_NOT_NULL(advance); @@ -7168,22 +6705,18 @@ UT_TEST(test_current_mx_updater_provenance_origin_plan_races) UT_ASSERT_NOT_NULL(recheck); UT_ASSERT_NOT_NULL(deadline); UT_ASSERT_NOT_NULL(cleanup); - if (advance_end != NULL && freeze != NULL && canonical != NULL - && recheck != NULL && deadline != NULL) - { + if (advance_end != NULL && freeze != NULL && canonical != NULL && recheck != NULL + && deadline != NULL) { UT_ASSERT(freeze < canonical); UT_ASSERT(canonical < recheck); UT_ASSERT(recheck < advance_end); UT_ASSERT(deadline < advance_end); } - if (cleanup != NULL) - { - UT_ASSERT_NOT_NULL(strstr(cleanup, - "cluster_undo_block0_current_cancel(&context->guard)")); - UT_ASSERT_NOT_NULL(strstr(cleanup, - "cluster_semantic_activation_leave(&context->admission)")); - UT_ASSERT_NOT_NULL(strstr(cleanup, - "memset(context, 0, sizeof(*context))")); + if (cleanup != NULL) { + UT_ASSERT_NOT_NULL(strstr(cleanup, "cluster_undo_block0_current_cancel(&context->guard)")); + UT_ASSERT_NOT_NULL( + strstr(cleanup, "cluster_semantic_activation_leave(&context->admission)")); + UT_ASSERT_NOT_NULL(strstr(cleanup, "memset(context, 0, sizeof(*context))")); } free(source); } diff --git a/src/test/cluster_unit/test_cluster_gcs_block_dedup_r4_route.c b/src/test/cluster_unit/test_cluster_gcs_block_dedup_r4_route.c index f87b839aed2..b529ba3dac1 100644 --- a/src/test/cluster_unit/test_cluster_gcs_block_dedup_r4_route.c +++ b/src/test/cluster_unit/test_cluster_gcs_block_dedup_r4_route.c @@ -403,8 +403,7 @@ make_tag(uint32 blockno) } static GcsBlockR4RouteIdentity -make_identity(uint64 seq, uint64 epoch, uint32 blockno, SCN read_scn, - uint64 activation_generation) +make_identity(uint64 seq, uint64 epoch, uint32 blockno, SCN read_scn, uint64 activation_generation) { GcsBlockR4RouteIdentity identity; @@ -456,8 +455,8 @@ static GcsBlockR4RouteArmResult arm_route(const GcsBlockR4RouteIdentity *identity, const ClusterR4CrRouteProof *proof, GcsBlockR4RouteRecord *record_out) { - return cluster_gcs_block_dedup_r4_route_arm_or_match( - 0, identity, TEST_ROUTE_TRANSITION, proof, TEST_LIFETIME_HINT_MS, true, record_out); + return cluster_gcs_block_dedup_r4_route_arm_or_match(0, identity, TEST_ROUTE_TRANSITION, proof, + TEST_LIFETIME_HINT_MS, true, record_out); } /* ------------------------------------------------------------------------- @@ -612,14 +611,13 @@ UT_TEST(test_proof_drift_marks_retryable_without_overwriting_winner) drifted.selected_holder_node = 3; UT_ASSERT_EQ(GCS_BLOCK_R4_ROUTE_ARM_HOLDER_MOVED, arm_route(&identity, &drifted, &record)); UT_ASSERT_EQ(1, cluster_gcs_block_dedup_r4_route_count()); - UT_ASSERT_EQ(GCS_BLOCK_R4_ROUTE_ARM_RETRYABLE, - arm_route(&identity, &first_proof, &record)); + UT_ASSERT_EQ(GCS_BLOCK_R4_ROUTE_ARM_RETRYABLE, arm_route(&identity, &first_proof, &record)); UT_ASSERT_EQ(GCS_BLOCK_R4_ROUTE_SEND_COLLISION, - cluster_gcs_block_dedup_r4_route_finish_send( - 0, &identity, TEST_ROUTE_TRANSITION, &drifted, true)); + cluster_gcs_block_dedup_r4_route_finish_send(0, &identity, TEST_ROUTE_TRANSITION, + &drifted, true)); UT_ASSERT_EQ(GCS_BLOCK_R4_ROUTE_SEND_FORWARDED, - cluster_gcs_block_dedup_r4_route_finish_send( - 0, &identity, TEST_ROUTE_TRANSITION, &first_proof, true)); + cluster_gcs_block_dedup_r4_route_finish_send(0, &identity, TEST_ROUTE_TRANSITION, + &first_proof, true)); UT_ASSERT_EQ(GCS_BLOCK_R4_ROUTE_ARM_REPLAY, arm_route(&identity, &first_proof, &record)); UT_ASSERT_EQ(GCS_BLOCK_R4_ROUTE_FORWARDED, record.state); assert_proof_exact(&record.proof, &first_proof); @@ -634,13 +632,13 @@ UT_TEST(test_send_failure_then_late_admission_becomes_forwarded) fixture_reset(8); UT_ASSERT_EQ(GCS_BLOCK_R4_ROUTE_ARM_NEW, arm_route(&identity, &proof, &record)); UT_ASSERT_EQ(GCS_BLOCK_R4_ROUTE_SEND_RETRYABLE, - cluster_gcs_block_dedup_r4_route_finish_send( - 0, &identity, TEST_ROUTE_TRANSITION, &proof, false)); + cluster_gcs_block_dedup_r4_route_finish_send(0, &identity, TEST_ROUTE_TRANSITION, + &proof, false)); UT_ASSERT_EQ(GCS_BLOCK_R4_ROUTE_ARM_RETRYABLE, arm_route(&identity, &proof, &record)); UT_ASSERT_EQ(GCS_BLOCK_R4_ROUTE_SEND_FORWARDED, - cluster_gcs_block_dedup_r4_route_finish_send( - 0, &identity, TEST_ROUTE_TRANSITION, &proof, true)); + cluster_gcs_block_dedup_r4_route_finish_send(0, &identity, TEST_ROUTE_TRANSITION, + &proof, true)); UT_ASSERT_EQ(GCS_BLOCK_R4_ROUTE_ARM_REPLAY, arm_route(&identity, &proof, &record)); UT_ASSERT_EQ(GCS_BLOCK_R4_ROUTE_FORWARDED, record.state); } @@ -654,11 +652,11 @@ UT_TEST(test_send_failure_cannot_downgrade_forwarded) fixture_reset(8); UT_ASSERT_EQ(GCS_BLOCK_R4_ROUTE_ARM_NEW, arm_route(&identity, &proof, &record)); UT_ASSERT_EQ(GCS_BLOCK_R4_ROUTE_SEND_FORWARDED, - cluster_gcs_block_dedup_r4_route_finish_send( - 0, &identity, TEST_ROUTE_TRANSITION, &proof, true)); + cluster_gcs_block_dedup_r4_route_finish_send(0, &identity, TEST_ROUTE_TRANSITION, + &proof, true)); UT_ASSERT_EQ(GCS_BLOCK_R4_ROUTE_SEND_RETRYABLE, - cluster_gcs_block_dedup_r4_route_finish_send( - 0, &identity, TEST_ROUTE_TRANSITION, &proof, false)); + cluster_gcs_block_dedup_r4_route_finish_send(0, &identity, TEST_ROUTE_TRANSITION, + &proof, false)); UT_ASSERT_EQ(GCS_BLOCK_R4_ROUTE_ARM_REPLAY, arm_route(&identity, &proof, &record)); UT_ASSERT_EQ(GCS_BLOCK_R4_ROUTE_FORWARDED, record.state); } @@ -676,8 +674,8 @@ UT_TEST(test_duplicate_send_admission_does_not_extend_forwarded_ttl) first_completion_monotonic = fixture_monotonic_us(); UT_ASSERT_EQ(GCS_BLOCK_R4_ROUTE_ARM_NEW, arm_route(&identity, &proof, &record)); UT_ASSERT_EQ(GCS_BLOCK_R4_ROUTE_SEND_FORWARDED, - cluster_gcs_block_dedup_r4_route_finish_send( - 0, &identity, TEST_ROUTE_TRANSITION, &proof, true)); + cluster_gcs_block_dedup_r4_route_finish_send(0, &identity, TEST_ROUTE_TRANSITION, + &proof, true)); /* A duplicate accepted publication one microsecond later must not refresh * completed_at_ts. At the original strict TTL + 1 boundary the route @@ -685,8 +683,8 @@ UT_TEST(test_duplicate_send_admission_does_not_extend_forwarded_ttl) fake_now = first_completion_wall + 1; fixture_set_monotonic_us(first_completion_monotonic + 1); UT_ASSERT_EQ(GCS_BLOCK_R4_ROUTE_SEND_FORWARDED, - cluster_gcs_block_dedup_r4_route_finish_send( - 0, &identity, TEST_ROUTE_TRANSITION, &proof, true)); + cluster_gcs_block_dedup_r4_route_finish_send(0, &identity, TEST_ROUTE_TRANSITION, + &proof, true)); UT_ASSERT_EQ(1, cluster_gcs_block_dedup_r4_route_count()); fake_now = first_completion_wall + TEST_PINNED_LIFETIME_US + 1; @@ -706,8 +704,8 @@ UT_TEST(test_finish_send_after_epoch_cleanup_is_stale) UT_ASSERT_EQ(GCS_BLOCK_R4_ROUTE_ARM_NEW, arm_route(&identity, &proof, &record)); UT_ASSERT_EQ(1, cluster_gcs_block_dedup_r4_route_sweep_epoch(4)); UT_ASSERT_EQ(GCS_BLOCK_R4_ROUTE_SEND_STALE, - cluster_gcs_block_dedup_r4_route_finish_send( - 0, &identity, TEST_ROUTE_TRANSITION, &proof, true)); + cluster_gcs_block_dedup_r4_route_finish_send(0, &identity, TEST_ROUTE_TRANSITION, + &proof, true)); UT_ASSERT_EQ(0, cluster_gcs_block_dedup_r4_route_count()); } @@ -763,9 +761,9 @@ UT_TEST(test_wall_forward_monotonic_in_window_expires_generic_but_keeps_route) fixture_reset(8); generic_key.request_id = gcs_reqid_requester(1, 7, 23); UT_ASSERT_EQ(GCS_BLOCK_DEDUP_MISS_REGISTERED, - cluster_gcs_block_dedup_lookup_or_register( - 0, &generic_key, generic_tag, TEST_ROUTE_TRANSITION, - TEST_LIFETIME_HINT_MS, true, NULL)); + cluster_gcs_block_dedup_lookup_or_register(0, &generic_key, generic_tag, + TEST_ROUTE_TRANSITION, + TEST_LIFETIME_HINT_MS, true, NULL)); UT_ASSERT_EQ(GCS_BLOCK_R4_ROUTE_ARM_NEW, arm_route(&route, &proof, &record)); /* Generic remains wall-clock based, while the route is still only one @@ -831,8 +829,7 @@ UT_TEST(test_cap_one_wall_backward_monotonic_expired_reclaims_route) if (result != GCS_BLOCK_R4_ROUTE_ARM_NEW) return; UT_ASSERT_EQ(1, cluster_gcs_block_dedup_r4_route_count()); - UT_ASSERT_EQ(GCS_BLOCK_R4_ROUTE_ARM_REPLAY, - arm_route(&second, &second_proof, &record)); + UT_ASSERT_EQ(GCS_BLOCK_R4_ROUTE_ARM_REPLAY, arm_route(&second, &second_proof, &record)); } UT_TEST(test_epoch_zero_is_valid_and_only_stale_formation_is_swept) @@ -865,8 +862,7 @@ UT_TEST(test_backend_exit_removes_exact_requester_route) UT_ASSERT_EQ(GCS_BLOCK_R4_ROUTE_ARM_NEW, arm_route(&survivor, &survivor_proof, &record)); cluster_gcs_block_dedup_cleanup_on_backend_exit(1, 7); UT_ASSERT_EQ(1, cluster_gcs_block_dedup_r4_route_count()); - UT_ASSERT_EQ(GCS_BLOCK_R4_ROUTE_ARM_REPLAY, - arm_route(&survivor, &survivor_proof, &record)); + UT_ASSERT_EQ(GCS_BLOCK_R4_ROUTE_ARM_REPLAY, arm_route(&survivor, &survivor_proof, &record)); UT_ASSERT_EQ(GCS_BLOCK_R4_ROUTE_ARM_NEW, arm_route(&matching, &matching_proof, &record)); } @@ -895,18 +891,18 @@ UT_TEST(test_closed_purge_removes_routes_but_preserves_generic_entry) generic_key = route.legacy_key; generic_key.request_id = gcs_reqid_requester(1, 7, 15); UT_ASSERT_EQ(GCS_BLOCK_DEDUP_MISS_REGISTERED, - cluster_gcs_block_dedup_lookup_or_register( - 0, &generic_key, generic_tag, TEST_ROUTE_TRANSITION, - TEST_LIFETIME_HINT_MS, true, NULL)); + cluster_gcs_block_dedup_lookup_or_register(0, &generic_key, generic_tag, + TEST_ROUTE_TRANSITION, + TEST_LIFETIME_HINT_MS, true, NULL)); UT_ASSERT_EQ(GCS_BLOCK_R4_ROUTE_ARM_NEW, arm_route(&route, &proof, &record)); UT_ASSERT_EQ(1, cluster_gcs_block_dedup_r4_route_purge_closed()); UT_ASSERT_EQ(0, cluster_gcs_block_dedup_r4_route_count()); UT_ASSERT_EQ(1, fake_live_count()); UT_ASSERT_EQ(GCS_BLOCK_DEDUP_IN_FLIGHT_DUPLICATE, - cluster_gcs_block_dedup_lookup_or_register( - 0, &generic_key, generic_tag, TEST_ROUTE_TRANSITION, - TEST_LIFETIME_HINT_MS, true, NULL)); + cluster_gcs_block_dedup_lookup_or_register(0, &generic_key, generic_tag, + TEST_ROUTE_TRANSITION, + TEST_LIFETIME_HINT_MS, true, NULL)); } UT_TEST(test_generic_done_and_remove_ignore_route) @@ -919,15 +915,14 @@ UT_TEST(test_generic_done_and_remove_ignore_route) fixture_reset(8); UT_ASSERT_EQ(GCS_BLOCK_R4_ROUTE_ARM_NEW, arm_route(&identity, &proof, &record)); done_mismatch_before = cluster_gcs_block_dedup_get_done_mismatch_count(); - UT_ASSERT(!cluster_gcs_block_dedup_mark_done( - 0, &identity.legacy_key, &identity.tag, TEST_ROUTE_TRANSITION)); + UT_ASSERT(!cluster_gcs_block_dedup_mark_done(0, &identity.legacy_key, &identity.tag, + TEST_ROUTE_TRANSITION)); cluster_gcs_block_dedup_remove(0, &identity.legacy_key); UT_ASSERT_EQ(GCS_BLOCK_DEDUP_VALIDATION_FAIL, - cluster_gcs_block_dedup_lookup_or_register( - 0, &identity.legacy_key, identity.tag, TEST_ROUTE_TRANSITION, - TEST_LIFETIME_HINT_MS, true, NULL)); - UT_ASSERT_EQ(done_mismatch_before, - cluster_gcs_block_dedup_get_done_mismatch_count()); + cluster_gcs_block_dedup_lookup_or_register(0, &identity.legacy_key, identity.tag, + TEST_ROUTE_TRANSITION, + TEST_LIFETIME_HINT_MS, true, NULL)); + UT_ASSERT_EQ(done_mismatch_before, cluster_gcs_block_dedup_get_done_mismatch_count()); UT_ASSERT_EQ(1, cluster_gcs_block_dedup_r4_route_count()); UT_ASSERT_EQ(GCS_BLOCK_R4_ROUTE_ARM_REPLAY, arm_route(&identity, &proof, &record)); } diff --git a/src/test/cluster_unit/test_cluster_gcs_block_shard.c b/src/test/cluster_unit/test_cluster_gcs_block_shard.c index 3b45985f504..e278b52b17c 100644 --- a/src/test/cluster_unit/test_cluster_gcs_block_shard.c +++ b/src/test/cluster_unit/test_cluster_gcs_block_shard.c @@ -420,32 +420,32 @@ UT_TEST(test_r4_extended_route_exact_lengths_and_tag_affinity) UT_ASSERT_EQ(sizeof(legacy_req), GCS_BLOCK_LEGACY_ROUTE_LEN); UT_ASSERT_EQ(sizeof(legacy_fwd), GCS_BLOCK_LEGACY_ROUTE_LEN); UT_ASSERT_EQ(cluster_gcs_block_payload_shard(PGRAC_IC_MSG_GCS_BLOCK_REQUEST, &legacy_req, - sizeof(legacy_req), CLUSTER_LMS_MAX_WORKERS), + sizeof(legacy_req), CLUSTER_LMS_MAX_WORKERS), expected); UT_ASSERT_EQ(cluster_gcs_block_payload_shard(PGRAC_IC_MSG_GCS_BLOCK_FORWARD, &legacy_fwd, - sizeof(legacy_fwd), CLUSTER_LMS_MAX_WORKERS), + sizeof(legacy_fwd), CLUSTER_LMS_MAX_WORKERS), expected); make_r4_route_frame(req_a.bytes, GCS_BLOCK_R4_REQUEST_ROUTE_LEN, tag, 0x00); make_r4_route_frame(req_b.bytes, GCS_BLOCK_R4_REQUEST_ROUTE_LEN, tag, 0xA5); UT_ASSERT_EQ(cluster_gcs_block_payload_shard(PGRAC_IC_MSG_GCS_BLOCK_REQUEST, req_a.bytes, - GCS_BLOCK_R4_REQUEST_ROUTE_LEN, - CLUSTER_LMS_MAX_WORKERS), + GCS_BLOCK_R4_REQUEST_ROUTE_LEN, + CLUSTER_LMS_MAX_WORKERS), expected); UT_ASSERT_EQ(cluster_gcs_block_payload_shard(PGRAC_IC_MSG_GCS_BLOCK_REQUEST, req_b.bytes, - GCS_BLOCK_R4_REQUEST_ROUTE_LEN, - CLUSTER_LMS_MAX_WORKERS), + GCS_BLOCK_R4_REQUEST_ROUTE_LEN, + CLUSTER_LMS_MAX_WORKERS), expected); make_r4_route_frame(fwd_a.bytes, GCS_BLOCK_R4_FORWARD_ROUTE_LEN, tag, 0x00); make_r4_route_frame(fwd_b.bytes, GCS_BLOCK_R4_FORWARD_ROUTE_LEN, tag, 0x5A); UT_ASSERT_EQ(cluster_gcs_block_payload_shard(PGRAC_IC_MSG_GCS_BLOCK_FORWARD, fwd_a.bytes, - GCS_BLOCK_R4_FORWARD_ROUTE_LEN, - CLUSTER_LMS_MAX_WORKERS), + GCS_BLOCK_R4_FORWARD_ROUTE_LEN, + CLUSTER_LMS_MAX_WORKERS), expected); UT_ASSERT_EQ(cluster_gcs_block_payload_shard(PGRAC_IC_MSG_GCS_BLOCK_FORWARD, fwd_b.bytes, - GCS_BLOCK_R4_FORWARD_ROUTE_LEN, - CLUSTER_LMS_MAX_WORKERS), + GCS_BLOCK_R4_FORWARD_ROUTE_LEN, + CLUSTER_LMS_MAX_WORKERS), expected); } @@ -474,26 +474,24 @@ UT_TEST(test_r4_kind4_internal_endpoint_routes_only_to_data_worker0) forward.extension.r4_version = CLUSTER_R4_WIRE_VERSION; forward.extension.r4_kind = CLUSTER_R4_WIRE_UNDO_DATA_FETCH; UT_ASSERT_EQ(cluster_gcs_block_payload_shard(PGRAC_IC_MSG_GCS_BLOCK_FORWARD, &forward, - sizeof(forward), CLUSTER_LMS_MAX_WORKERS), + sizeof(forward), CLUSTER_LMS_MAX_WORKERS), 0); forward.base.requester_backend_id = 1; UT_ASSERT_EQ(cluster_gcs_block_payload_shard(PGRAC_IC_MSG_GCS_BLOCK_FORWARD, &forward, - sizeof(forward), CLUSTER_LMS_MAX_WORKERS), + sizeof(forward), CLUSTER_LMS_MAX_WORKERS), ordinary_shard); forward.base.requester_backend_id = CLUSTER_GCS_BLOCK_R4_INTERNAL_ENDPOINT; forward.extension.r4_kind = CLUSTER_R4_WIRE_CR_BUILD; UT_ASSERT_EQ(cluster_gcs_block_payload_shard(PGRAC_IC_MSG_GCS_BLOCK_FORWARD, &forward, - sizeof(forward), CLUSTER_LMS_MAX_WORKERS), + sizeof(forward), CLUSTER_LMS_MAX_WORKERS), ordinary_shard); forward.extension.r4_kind = CLUSTER_R4_WIRE_UNDO_DATA_FETCH; UT_ASSERT_EQ(cluster_gcs_block_payload_shard(PGRAC_IC_MSG_GCS_BLOCK_FORWARD, &forward, - sizeof(forward) - 1, - CLUSTER_LMS_MAX_WORKERS), + sizeof(forward) - 1, CLUSTER_LMS_MAX_WORKERS), -1); UT_ASSERT_EQ(cluster_gcs_block_payload_shard(PGRAC_IC_MSG_GCS_BLOCK_FORWARD, &forward, - sizeof(forward) + 1, - CLUSTER_LMS_MAX_WORKERS), + sizeof(forward) + 1, CLUSTER_LMS_MAX_WORKERS), -1); } @@ -509,10 +507,8 @@ UT_TEST(test_r4_kind2_terminal_census_routes_to_existing_data_worker0) int i; for (i = 1; i < 10000 && ordinary_shard == 0; i++) { - tag = make_tag(GCS_BLOCK_UNDO_FETCH_TAG_MAGIC, 5, 0, - MAIN_FORKNUM, (BlockNumber)i); - ordinary_shard - = cluster_lms_shard_for_tag(&tag, CLUSTER_LMS_MAX_WORKERS); + tag = make_tag(GCS_BLOCK_UNDO_FETCH_TAG_MAGIC, 5, 0, MAIN_FORKNUM, (BlockNumber)i); + ordinary_shard = cluster_lms_shard_for_tag(&tag, CLUSTER_LMS_MAX_WORKERS); } UT_ASSERT(ordinary_shard > 0); memset(&forward, 0, sizeof(forward)); @@ -520,22 +516,22 @@ UT_TEST(test_r4_kind2_terminal_census_routes_to_existing_data_worker0) forward.base.requester_backend_id = 1; forward.extension.r4_version = CLUSTER_R4_WIRE_VERSION; forward.extension.r4_kind = CLUSTER_R4_WIRE_TX_RESOLVE; - UT_ASSERT_EQ(cluster_gcs_block_payload_shard( - PGRAC_IC_MSG_GCS_BLOCK_FORWARD, &forward, sizeof(forward), - CLUSTER_LMS_MAX_WORKERS), 0); + UT_ASSERT_EQ(cluster_gcs_block_payload_shard(PGRAC_IC_MSG_GCS_BLOCK_FORWARD, &forward, + sizeof(forward), CLUSTER_LMS_MAX_WORKERS), + 0); forward.extension.r4_version = 0; - UT_ASSERT_EQ(cluster_gcs_block_payload_shard( - PGRAC_IC_MSG_GCS_BLOCK_FORWARD, &forward, sizeof(forward), - CLUSTER_LMS_MAX_WORKERS), ordinary_shard); + UT_ASSERT_EQ(cluster_gcs_block_payload_shard(PGRAC_IC_MSG_GCS_BLOCK_FORWARD, &forward, + sizeof(forward), CLUSTER_LMS_MAX_WORKERS), + ordinary_shard); forward.extension.r4_version = CLUSTER_R4_WIRE_VERSION; forward.extension.r4_kind = CLUSTER_R4_WIRE_CR_BUILD; - UT_ASSERT_EQ(cluster_gcs_block_payload_shard( - PGRAC_IC_MSG_GCS_BLOCK_FORWARD, &forward, sizeof(forward), - CLUSTER_LMS_MAX_WORKERS), ordinary_shard); - UT_ASSERT_EQ(cluster_gcs_block_payload_shard( - PGRAC_IC_MSG_GCS_BLOCK_FORWARD, &forward, sizeof(forward) - 1, - CLUSTER_LMS_MAX_WORKERS), -1); + UT_ASSERT_EQ(cluster_gcs_block_payload_shard(PGRAC_IC_MSG_GCS_BLOCK_FORWARD, &forward, + sizeof(forward), CLUSTER_LMS_MAX_WORKERS), + ordinary_shard); + UT_ASSERT_EQ(cluster_gcs_block_payload_shard(PGRAC_IC_MSG_GCS_BLOCK_FORWARD, &forward, + sizeof(forward) - 1, CLUSTER_LMS_MAX_WORKERS), + -1); } /* ====================================================================== @@ -556,14 +552,14 @@ UT_TEST(test_r4_extended_route_length_mismatch_refused) make_r4_route_frame(payload.bytes, sizeof(payload.bytes), tag, 0xC3); for (i = 0; i < lengthof(request_bad_lengths); i++) - UT_ASSERT_EQ(cluster_gcs_block_payload_shard(PGRAC_IC_MSG_GCS_BLOCK_REQUEST, - payload.bytes, request_bad_lengths[i], - CLUSTER_LMS_MAX_WORKERS), + UT_ASSERT_EQ(cluster_gcs_block_payload_shard(PGRAC_IC_MSG_GCS_BLOCK_REQUEST, payload.bytes, + request_bad_lengths[i], + CLUSTER_LMS_MAX_WORKERS), -1); for (i = 0; i < lengthof(forward_bad_lengths); i++) - UT_ASSERT_EQ(cluster_gcs_block_payload_shard(PGRAC_IC_MSG_GCS_BLOCK_FORWARD, - payload.bytes, forward_bad_lengths[i], - CLUSTER_LMS_MAX_WORKERS), + UT_ASSERT_EQ(cluster_gcs_block_payload_shard(PGRAC_IC_MSG_GCS_BLOCK_FORWARD, payload.bytes, + forward_bad_lengths[i], + CLUSTER_LMS_MAX_WORKERS), -1); } @@ -589,14 +585,13 @@ UT_TEST(test_current_mx_forward128_routes_by_request_identity) describe.trailer.magic = CLUSTER_CURRENT_MX_WIRE_MAGIC; describe.trailer.version = CLUSTER_CURRENT_MX_WIRE_VERSION; - route_tag = GcsBlockCurrentMxRouteTagMake( - describe.prefix.request_id, describe.prefix.epoch, - describe.prefix.original_requester_node, - describe.prefix.requester_backend_id); + route_tag = GcsBlockCurrentMxRouteTagMake(describe.prefix.request_id, describe.prefix.epoch, + describe.prefix.original_requester_node, + describe.prefix.requester_backend_id); expected = cluster_lms_shard_for_tag(&route_tag, CLUSTER_LMS_MAX_WORKERS); - UT_ASSERT_EQ(cluster_gcs_block_payload_shard( - PGRAC_IC_MSG_GCS_BLOCK_FORWARD, &describe, sizeof(describe), - CLUSTER_LMS_MAX_WORKERS), expected); + UT_ASSERT_EQ(cluster_gcs_block_payload_shard(PGRAC_IC_MSG_GCS_BLOCK_FORWARD, &describe, + sizeof(describe), CLUSTER_LMS_MAX_WORKERS), + expected); memset(&proof, 0, sizeof(proof)); proof.prefix.request_id = describe.prefix.request_id; @@ -606,20 +601,20 @@ UT_TEST(test_current_mx_forward128_routes_by_request_identity) proof.prefix.kind = GCS_BLOCK_FORWARD_KIND_CURRENT_MX_MEMBER_PROOF; proof.trailer.magic = CLUSTER_CURRENT_MX_WIRE_MAGIC; proof.trailer.version = CLUSTER_CURRENT_MX_WIRE_VERSION; - UT_ASSERT_EQ(cluster_gcs_block_payload_shard( - PGRAC_IC_MSG_GCS_BLOCK_FORWARD, &proof, sizeof(proof), - CLUSTER_LMS_MAX_WORKERS), expected); + UT_ASSERT_EQ(cluster_gcs_block_payload_shard(PGRAC_IC_MSG_GCS_BLOCK_FORWARD, &proof, + sizeof(proof), CLUSTER_LMS_MAX_WORKERS), + expected); describe.prefix.kind = GCS_BLOCK_FORWARD_KIND_CURRENT_MX_STATS; - UT_ASSERT_EQ(cluster_gcs_block_payload_shard( - PGRAC_IC_MSG_GCS_BLOCK_FORWARD, &describe, sizeof(describe), - CLUSTER_LMS_MAX_WORKERS), -1); - UT_ASSERT_EQ(cluster_gcs_block_payload_shard( - PGRAC_IC_MSG_GCS_BLOCK_FORWARD, &proof, sizeof(proof) - 1, - CLUSTER_LMS_MAX_WORKERS), -1); - UT_ASSERT_EQ(cluster_gcs_block_payload_shard( - PGRAC_IC_MSG_GCS_BLOCK_FORWARD, &proof, sizeof(proof) + 1, - CLUSTER_LMS_MAX_WORKERS), -1); + UT_ASSERT_EQ(cluster_gcs_block_payload_shard(PGRAC_IC_MSG_GCS_BLOCK_FORWARD, &describe, + sizeof(describe), CLUSTER_LMS_MAX_WORKERS), + -1); + UT_ASSERT_EQ(cluster_gcs_block_payload_shard(PGRAC_IC_MSG_GCS_BLOCK_FORWARD, &proof, + sizeof(proof) - 1, CLUSTER_LMS_MAX_WORKERS), + -1); + UT_ASSERT_EQ(cluster_gcs_block_payload_shard(PGRAC_IC_MSG_GCS_BLOCK_FORWARD, &proof, + sizeof(proof) + 1, CLUSTER_LMS_MAX_WORKERS), + -1); } /* MXA-T24: the 136-byte CTRC CLOSE/CERTIFICATE family must use the same @@ -648,37 +643,37 @@ UT_TEST(test_ctrc_forward136_routes_only_exact_wire_domain) request.wire_length = CLUSTER_CTRC_SEAL_REQUEST_BYTES; request.participant_capability_record_generation = 23; - route_tag = GcsBlockCurrentMxRouteTagMake( - request.request_id, request.cluster_epoch, - request.original_requester_node, request.requester_backend_id); + route_tag = GcsBlockCurrentMxRouteTagMake(request.request_id, request.cluster_epoch, + request.original_requester_node, + request.requester_backend_id); expected = cluster_lms_shard_for_tag(&route_tag, CLUSTER_LMS_MAX_WORKERS); - UT_ASSERT_EQ(cluster_gcs_block_payload_shard( - PGRAC_IC_MSG_GCS_BLOCK_FORWARD, &request, sizeof(request), - CLUSTER_LMS_MAX_WORKERS), expected); + UT_ASSERT_EQ(cluster_gcs_block_payload_shard(PGRAC_IC_MSG_GCS_BLOCK_FORWARD, &request, + sizeof(request), CLUSTER_LMS_MAX_WORKERS), + expected); request.forward_kind = GCS_BLOCK_FORWARD_KIND_UNDO_FRESHREF_C1B_PAIR; - UT_ASSERT_EQ(cluster_gcs_block_payload_shard( - PGRAC_IC_MSG_GCS_BLOCK_FORWARD, &request, sizeof(request), - CLUSTER_LMS_MAX_WORKERS), -1); + UT_ASSERT_EQ(cluster_gcs_block_payload_shard(PGRAC_IC_MSG_GCS_BLOCK_FORWARD, &request, + sizeof(request), CLUSTER_LMS_MAX_WORKERS), + -1); request.forward_kind = CLUSTER_CTRC_FORWARD_KIND; request.wire_version++; - UT_ASSERT_EQ(cluster_gcs_block_payload_shard( - PGRAC_IC_MSG_GCS_BLOCK_FORWARD, &request, sizeof(request), - CLUSTER_LMS_MAX_WORKERS), -1); + UT_ASSERT_EQ(cluster_gcs_block_payload_shard(PGRAC_IC_MSG_GCS_BLOCK_FORWARD, &request, + sizeof(request), CLUSTER_LMS_MAX_WORKERS), + -1); request.wire_version = CLUSTER_CTRC_WIRE_VERSION; request.reserved_tail = 1; - UT_ASSERT_EQ(cluster_gcs_block_payload_shard( - PGRAC_IC_MSG_GCS_BLOCK_FORWARD, &request, sizeof(request), - CLUSTER_LMS_MAX_WORKERS), -1); + UT_ASSERT_EQ(cluster_gcs_block_payload_shard(PGRAC_IC_MSG_GCS_BLOCK_FORWARD, &request, + sizeof(request), CLUSTER_LMS_MAX_WORKERS), + -1); request.reserved_tail = 0; request.participant_capability_record_generation = 0; - UT_ASSERT_EQ(cluster_gcs_block_payload_shard( - PGRAC_IC_MSG_GCS_BLOCK_FORWARD, &request, sizeof(request), - CLUSTER_LMS_MAX_WORKERS), -1); + UT_ASSERT_EQ(cluster_gcs_block_payload_shard(PGRAC_IC_MSG_GCS_BLOCK_FORWARD, &request, + sizeof(request), CLUSTER_LMS_MAX_WORKERS), + -1); request.participant_capability_record_generation = 23; - UT_ASSERT_EQ(cluster_gcs_block_payload_shard( - PGRAC_IC_MSG_GCS_BLOCK_FORWARD, &request, sizeof(request) - 1, - CLUSTER_LMS_MAX_WORKERS), -1); + UT_ASSERT_EQ(cluster_gcs_block_payload_shard(PGRAC_IC_MSG_GCS_BLOCK_FORWARD, &request, + sizeof(request) - 1, CLUSTER_LMS_MAX_WORKERS), + -1); } /* Every staged PCM-X frame is tag-affine. RETIRE/RETIRE_ACK are the only @@ -714,16 +709,15 @@ UT_TEST(test_pi_durable_note_routes_to_exact_tag_worker) * decoded assertion tag; raw offset-16 routing would accept the corrupted * companion frame below. */ static uint16 -make_resource_x_route_frame(ResourceXWireKind kind, uint8 msg_type, - BufferTag tag, uint8 *bytes, uint16 capacity) +make_resource_x_route_frame(ResourceXWireKind kind, uint8 msg_type, BufferTag tag, uint8 *bytes, + uint16 capacity) { ResourceXDecodedFrame frame; ResourceXWireReject reject = RESOURCE_X_WIRE_REJECT_BAD_ARGUMENT; uint16 payload_len = 0; memset(&frame, 0, sizeof(frame)); - UT_ASSERT(resource_x_assertion_init(&tag, 3, - &frame.common.logical_assertion)); + UT_ASSERT(resource_x_assertion_init(&tag, 3, &frame.common.logical_assertion)); frame.kind = kind; frame.common.base_authority_generation = 11; frame.common.resource_formation = 12; @@ -757,15 +751,11 @@ make_resource_x_route_frame(ResourceXWireKind kind, uint8 msg_type, frame.blocked_has_remote_proof = capacity == RESOURCE_X_PROOF_V1_BYTES; if (frame.blocked_has_remote_proof) { frame.body.blocked_to_n.source_carrier_generation = 18; - frame.body.blocked_to_n.requester_target_generation - = frame.common.assertion_sequence; - frame.body.blocked_to_n.source_disposition - = RESOURCE_X_DISPOSITION_REMOTE_NONWRITABLE; - frame.body.blocked_to_n.proof_kind - = RESOURCE_X_PROOF_REMOTE_CARRIER; + frame.body.blocked_to_n.requester_target_generation = frame.common.assertion_sequence; + frame.body.blocked_to_n.source_disposition = RESOURCE_X_DISPOSITION_REMOTE_NONWRITABLE; + frame.body.blocked_to_n.proof_kind = RESOURCE_X_PROOF_REMOTE_CARRIER; frame.body.blocked_to_n.holder_connection_generation = 20; - frame.body.blocked_to_n.acting_formation - = frame.common.resource_formation; + frame.body.blocked_to_n.acting_formation = frame.common.resource_formation; } } else if (kind == RESOURCE_X_WIRE_RELEASE_X) { frame.common.observed_mode = PCM_STATE_X; @@ -774,20 +764,15 @@ make_resource_x_route_frame(ResourceXWireKind kind, uint8 msg_type, } else if (kind == RESOURCE_X_WIRE_LOCAL_PROOF_DECLARATION) { frame.common.outcome = RESOURCE_X_OUTCOME_OK; frame.body.local_proof.local_holder_authority_generation = 21; - frame.body.local_proof.requester_target_generation - = frame.common.assertion_sequence; + frame.body.local_proof.requester_target_generation = frame.common.assertion_sequence; frame.body.local_proof.requester_connection_generation = 23; frame.body.local_proof.local_proof_generation = 24; } else if (kind == RESOURCE_X_WIRE_AUTHORITY_GRANT) { frame.common.outcome = RESOURCE_X_OUTCOME_OK; - frame.body.authority_grant.final_authority_generation - = frame.common.authority_generation; - frame.body.authority_grant.requester_target_generation - = frame.common.assertion_sequence; - frame.body.authority_grant.proof_kind - = RESOURCE_X_PROOF_DURABLE_STORAGE; - frame.body.authority_grant.source_disposition - = RESOURCE_X_DISPOSITION_DURABLE_STORAGE; + frame.body.authority_grant.final_authority_generation = frame.common.authority_generation; + frame.body.authority_grant.requester_target_generation = frame.common.assertion_sequence; + frame.body.authority_grant.proof_kind = RESOURCE_X_PROOF_DURABLE_STORAGE; + frame.body.authority_grant.source_disposition = RESOURCE_X_DISPOSITION_DURABLE_STORAGE; frame.body.authority_grant.requester_connection_generation = 26; } else if (kind == RESOURCE_X_WIRE_IMAGE_ENVELOPE) { frame.common.action_node = 7; @@ -795,13 +780,10 @@ make_resource_x_route_frame(ResourceXWireKind kind, uint8 msg_type, frame.body.image_envelope.conversion_base_generation = frame.common.base_authority_generation; frame.body.image_envelope.source_carrier_generation = 27; - frame.body.image_envelope.requester_target_generation - = frame.common.assertion_sequence; + frame.body.image_envelope.requester_target_generation = frame.common.assertion_sequence; frame.body.image_envelope.image_length = RESOURCE_X_PAGE_BYTES; - frame.body.image_envelope.source_disposition - = RESOURCE_X_DISPOSITION_REMOTE_NONWRITABLE; - frame.body.image_envelope.proof_kind - = RESOURCE_X_PROOF_REMOTE_CARRIER; + frame.body.image_envelope.source_disposition = RESOURCE_X_DISPOSITION_REMOTE_NONWRITABLE; + frame.body.image_envelope.proof_kind = RESOURCE_X_PROOF_REMOTE_CARRIER; } else if (kind == RESOURCE_X_WIRE_INSTALL_SETTLEMENT) { frame.common.outcome = RESOURCE_X_OUTCOME_OK; frame.body.install_settlement.conversion_base_generation @@ -809,18 +791,15 @@ make_resource_x_route_frame(ResourceXWireKind kind, uint8 msg_type, frame.body.install_settlement.final_authority_generation = frame.common.authority_generation; frame.body.install_settlement.requester_connection_generation = 29; - frame.body.install_settlement.requester_target_generation - = frame.common.assertion_sequence; + frame.body.install_settlement.requester_target_generation = frame.common.assertion_sequence; frame.body.install_settlement.installed_mode = PCM_STATE_X; - frame.body.install_settlement.requester_role - = RESOURCE_X_REQUESTER_ROLE_ACQUIRER; + frame.body.install_settlement.requester_role = RESOURCE_X_REQUESTER_ROLE_ACQUIRER; frame.body.install_settlement.terminal_outcome = RESOURCE_X_OUTCOME_OK; - frame.body.install_settlement.terminal_state - = RESOURCE_X_SETTLEMENT_TERMINAL_INSTALLED; + frame.body.install_settlement.terminal_state = RESOURCE_X_SETTLEMENT_TERMINAL_INSTALLED; } - UT_ASSERT(cluster_resource_x_wire_encode(msg_type, &frame, bytes, - capacity, &payload_len, &reject)); + UT_ASSERT( + cluster_resource_x_wire_encode(msg_type, &frame, bytes, capacity, &payload_len, &reject)); UT_ASSERT_EQ(reject, RESOURCE_X_WIRE_REJECT_NONE); return payload_len; } @@ -832,30 +811,24 @@ UT_TEST(test_resource_x_reused_types_route_only_after_strict_domain_decode) ResourceXWireKind kind; uint16 payload_len; } cases[] = { - { RESOURCE_X_MSG_ASSERT_X, - RESOURCE_X_WIRE_PREASSERT_BOOTSTRAP, - RESOURCE_X_CONTROL_V1_BYTES }, - { RESOURCE_X_MSG_ASSERT_X, RESOURCE_X_WIRE_ASSERT_X, + { RESOURCE_X_MSG_ASSERT_X, RESOURCE_X_WIRE_PREASSERT_BOOTSTRAP, RESOURCE_X_CONTROL_V1_BYTES }, + { RESOURCE_X_MSG_ASSERT_X, RESOURCE_X_WIRE_ASSERT_X, RESOURCE_X_CONTROL_V1_BYTES }, { RESOURCE_X_MSG_ASSERT_X, RESOURCE_X_WIRE_LOCAL_PROOF_DECLARATION, RESOURCE_X_SHORT_V1_BYTES }, - { RESOURCE_X_MSG_BLOCK_TO_N, RESOURCE_X_WIRE_BLOCK_TO_N, - RESOURCE_X_CONTROL_V1_BYTES }, - { RESOURCE_X_MSG_BLOCKED_TO_N, RESOURCE_X_WIRE_BLOCKED_TO_N, - RESOURCE_X_CONTROL_V1_BYTES }, - { RESOURCE_X_MSG_BLOCKED_TO_N, RESOURCE_X_WIRE_BLOCKED_TO_N, - RESOURCE_X_PROOF_V1_BYTES }, + { RESOURCE_X_MSG_BLOCK_TO_N, RESOURCE_X_WIRE_BLOCK_TO_N, RESOURCE_X_CONTROL_V1_BYTES }, + { RESOURCE_X_MSG_BLOCKED_TO_N, RESOURCE_X_WIRE_BLOCKED_TO_N, RESOURCE_X_CONTROL_V1_BYTES }, + { RESOURCE_X_MSG_BLOCKED_TO_N, RESOURCE_X_WIRE_BLOCKED_TO_N, RESOURCE_X_PROOF_V1_BYTES }, { RESOURCE_X_MSG_IMAGE_OR_GRANT, RESOURCE_X_WIRE_AUTHORITY_GRANT, RESOURCE_X_PROOF_V1_BYTES }, { RESOURCE_X_MSG_IMAGE_OR_GRANT, RESOURCE_X_WIRE_IMAGE_ENVELOPE, RESOURCE_X_IMAGE_V1_BYTES }, - { RESOURCE_X_MSG_IMAGE_OR_GRANT, - RESOURCE_X_WIRE_PREASSERT_BOOTSTRAP, + { RESOURCE_X_MSG_IMAGE_OR_GRANT, RESOURCE_X_WIRE_PREASSERT_BOOTSTRAP, RESOURCE_X_CONTROL_V1_BYTES }, { RESOURCE_X_MSG_SETTLEMENT_OR_RELEASE, RESOURCE_X_WIRE_RELEASE_X, RESOURCE_X_CONTROL_V1_BYTES }, - { RESOURCE_X_MSG_SETTLEMENT_OR_RELEASE, - RESOURCE_X_WIRE_INSTALL_SETTLEMENT, RESOURCE_X_SHORT_V1_BYTES } + { RESOURCE_X_MSG_SETTLEMENT_OR_RELEASE, RESOURCE_X_WIRE_INSTALL_SETTLEMENT, + RESOURCE_X_SHORT_V1_BYTES } }; BufferTag tag = make_tag(1663, 5, 37001, FSM_FORKNUM, 771); union { @@ -866,16 +839,18 @@ UT_TEST(test_resource_x_reused_types_route_only_after_strict_domain_decode) Size i; for (i = 0; i < lengthof(cases); i++) { - uint16 encoded_len = make_resource_x_route_frame(cases[i].kind, - cases[i].msg_type, tag, payload.bytes, cases[i].payload_len); + uint16 encoded_len = make_resource_x_route_frame(cases[i].kind, cases[i].msg_type, tag, + payload.bytes, cases[i].payload_len); UT_ASSERT_EQ(encoded_len, cases[i].payload_len); - UT_ASSERT_EQ(cluster_gcs_block_payload_shard(cases[i].msg_type, - payload.bytes, encoded_len, CLUSTER_LMS_MAX_WORKERS), expected); + UT_ASSERT_EQ(cluster_gcs_block_payload_shard(cases[i].msg_type, payload.bytes, encoded_len, + CLUSTER_LMS_MAX_WORKERS), + expected); payload.bytes[20] ^= UINT8_C(0x01); - UT_ASSERT_EQ(cluster_gcs_block_payload_shard(cases[i].msg_type, - payload.bytes, encoded_len, CLUSTER_LMS_MAX_WORKERS), -1); + UT_ASSERT_EQ(cluster_gcs_block_payload_shard(cases[i].msg_type, payload.bytes, encoded_len, + CLUSTER_LMS_MAX_WORKERS), + -1); payload.bytes[20] ^= UINT8_C(0x01); } } @@ -891,16 +866,21 @@ UT_TEST(test_resource_x_length_collisions_preserve_legacy_domains) int expected = cluster_lms_shard_for_tag(&tag, CLUSTER_LMS_MAX_WORKERS); ack.tag = tag; - UT_ASSERT_EQ(cluster_gcs_block_payload_shard(PGRAC_IC_MSG_GCS_BLOCK_REQUEST, - &request, sizeof(request), CLUSTER_LMS_MAX_WORKERS), expected); - UT_ASSERT_EQ(cluster_gcs_block_payload_shard(PGRAC_IC_MSG_GCS_BLOCK_INVALIDATE, - &invalidate, sizeof(invalidate), CLUSTER_LMS_MAX_WORKERS), expected); - UT_ASSERT_EQ(cluster_gcs_block_payload_shard(PGRAC_IC_MSG_GCS_BLOCK_INVALIDATE_ACK, - &ack, sizeof(ack), CLUSTER_LMS_MAX_WORKERS), expected); - UT_ASSERT_EQ(cluster_gcs_block_payload_shard(PGRAC_IC_MSG_GCS_BLOCK_DONE, - &done, sizeof(done), CLUSTER_LMS_MAX_WORKERS), expected); - UT_ASSERT_EQ(cluster_gcs_block_payload_shard(PGRAC_IC_MSG_GCS_BLOCK_REPLY, - legacy_reply, sizeof(legacy_reply), CLUSTER_LMS_MAX_WORKERS), -1); + UT_ASSERT_EQ(cluster_gcs_block_payload_shard(PGRAC_IC_MSG_GCS_BLOCK_REQUEST, &request, + sizeof(request), CLUSTER_LMS_MAX_WORKERS), + expected); + UT_ASSERT_EQ(cluster_gcs_block_payload_shard(PGRAC_IC_MSG_GCS_BLOCK_INVALIDATE, &invalidate, + sizeof(invalidate), CLUSTER_LMS_MAX_WORKERS), + expected); + UT_ASSERT_EQ(cluster_gcs_block_payload_shard(PGRAC_IC_MSG_GCS_BLOCK_INVALIDATE_ACK, &ack, + sizeof(ack), CLUSTER_LMS_MAX_WORKERS), + expected); + UT_ASSERT_EQ(cluster_gcs_block_payload_shard(PGRAC_IC_MSG_GCS_BLOCK_DONE, &done, sizeof(done), + CLUSTER_LMS_MAX_WORKERS), + expected); + UT_ASSERT_EQ(cluster_gcs_block_payload_shard(PGRAC_IC_MSG_GCS_BLOCK_REPLY, legacy_reply, + sizeof(legacy_reply), CLUSTER_LMS_MAX_WORKERS), + -1); } int diff --git a/src/test/cluster_unit/test_cluster_gcs_dispatch.c b/src/test/cluster_unit/test_cluster_gcs_dispatch.c index 5826becff69..4dda3e8c97e 100644 --- a/src/test/cluster_unit/test_cluster_gcs_dispatch.c +++ b/src/test/cluster_unit/test_cluster_gcs_dispatch.c @@ -703,34 +703,34 @@ UT_TEST(test_gcs_reply_identity_is_exact_across_backends) reply.epoch = 7; UT_ASSERT(cluster_gcs_reply_matches_outstanding(&reply, backend1_request, - PCM_TRANS_S_TO_N_RELEASE, 3, 3)); + PCM_TRANS_S_TO_N_RELEASE, 3, 3)); /* Same raw sequence in another backend domain is not this request. */ UT_ASSERT(!cluster_gcs_reply_matches_outstanding(&reply, backend0_request, - PCM_TRANS_S_TO_N_RELEASE, 3, 3)); + PCM_TRANS_S_TO_N_RELEASE, 3, 3)); /* A predecessor reply cannot complete the successor transition. */ reply.transition_id = PCM_TRANS_X_TO_S_DOWNGRADE; UT_ASSERT(!cluster_gcs_reply_matches_outstanding(&reply, backend1_request, - PCM_TRANS_S_TO_N_RELEASE, 3, 3)); + PCM_TRANS_S_TO_N_RELEASE, 3, 3)); reply.transition_id = PCM_TRANS_S_TO_N_RELEASE; /* Body sender and authenticated envelope source are both exact. */ reply.sender_node = 2; UT_ASSERT(!cluster_gcs_reply_matches_outstanding(&reply, backend1_request, - PCM_TRANS_S_TO_N_RELEASE, 3, 3)); + PCM_TRANS_S_TO_N_RELEASE, 3, 3)); reply.sender_node = 3; UT_ASSERT(!cluster_gcs_reply_matches_outstanding(&reply, backend1_request, - PCM_TRANS_S_TO_N_RELEASE, 3, 2)); + PCM_TRANS_S_TO_N_RELEASE, 3, 2)); /* Reserved bytes and status domain remain fail closed. */ reply.reserved_0[0] = 1; UT_ASSERT(!cluster_gcs_reply_matches_outstanding(&reply, backend1_request, - PCM_TRANS_S_TO_N_RELEASE, 3, 3)); + PCM_TRANS_S_TO_N_RELEASE, 3, 3)); reply.reserved_0[0] = 0; reply.status = (uint8)(GCS_REPLY_DENIED_EPOCH_STALE + 1); UT_ASSERT(!cluster_gcs_reply_matches_outstanding(&reply, backend1_request, - PCM_TRANS_S_TO_N_RELEASE, 3, 3)); + PCM_TRANS_S_TO_N_RELEASE, 3, 3)); } diff --git a/src/test/cluster_unit/test_cluster_ges_reply_wait.c b/src/test/cluster_unit/test_cluster_ges_reply_wait.c index 6de13a6bd6a..7e76beba0da 100644 --- a/src/test/cluster_unit/test_cluster_ges_reply_wait.c +++ b/src/test/cluster_unit/test_cluster_ges_reply_wait.c @@ -62,7 +62,8 @@ pg_re_throw(void) void ExceptionalCondition(const char *conditionName pg_attribute_unused(), - const char *fileName pg_attribute_unused(), int lineNumber pg_attribute_unused()) + const char *fileName pg_attribute_unused(), + int lineNumber pg_attribute_unused()) { abort(); } @@ -197,8 +198,7 @@ hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr) *foundPtr = false; if (action == HASH_FIND || action == HASH_REMOVE) return NULL; - if ((action == HASH_ENTER || action == HASH_ENTER_NULL) - && hash->count < FAKE_REPLY_WAIT_CAP) { + if ((action == HASH_ENTER || action == HASH_ENTER_NULL) && hash->count < FAKE_REPLY_WAIT_CAP) { char *entry = hash->entries[hash->count++]; memset(entry, 0, fake_entrysize); @@ -287,8 +287,7 @@ ConditionVariablePrepareToSleep(ConditionVariable *cv) } bool -ConditionVariableTimedSleep(ConditionVariable *cv, long timeout_ms, - uint32 wait_event) +ConditionVariableTimedSleep(ConditionVariable *cv, long timeout_ms, uint32 wait_event) { Assert(fake_lock_depth == 0); Assert(cv == fake_cv_target); @@ -444,8 +443,7 @@ UT_TEST(test_poll_missing_is_explicit_without_output_mutation) GesReplyWaitVerdict verdict = { 0xAAAAAAAAU, 0xBBBBBBBBU }; reset_reply_wait(); - UT_ASSERT_EQ(cluster_ges_reply_wait_poll_consume(&key, &verdict), - GES_REPLY_WAIT_POLL_MISSING); + UT_ASSERT_EQ(cluster_ges_reply_wait_poll_consume(&key, &verdict), GES_REPLY_WAIT_POLL_MISSING); UT_ASSERT_EQ(verdict.reply_opcode, 0xAAAAAAAAU); UT_ASSERT_EQ(verdict.reject_reason, 0xBBBBBBBBU); UT_ASSERT_EQ(cluster_ges_reply_wait_table_active_count(), 0); @@ -468,15 +466,14 @@ UT_TEST(test_poll_matches_all_five_key_fields) UT_ASSERT_NOT_NULL(cluster_ges_reply_wait_insert(&base, 9000)); for (i = 0; i < 5; i++) { UT_ASSERT_NOT_NULL(cluster_ges_reply_wait_insert(&variants[i], 9000)); - UT_ASSERT_EQ(cluster_ges_reply_wait_deliver(&variants[i], (uint32)(100 + i), - (uint32)(200 + i)), - GES_REPLY_DELIVER_WOKE); + UT_ASSERT_EQ( + cluster_ges_reply_wait_deliver(&variants[i], (uint32)(100 + i), (uint32)(200 + i)), + GES_REPLY_DELIVER_WOKE); } verdict.reply_opcode = 0xAAAAAAAAU; verdict.reject_reason = 0xBBBBBBBBU; - UT_ASSERT_EQ(cluster_ges_reply_wait_poll_consume(&base, &verdict), - GES_REPLY_WAIT_POLL_PENDING); + UT_ASSERT_EQ(cluster_ges_reply_wait_poll_consume(&base, &verdict), GES_REPLY_WAIT_POLL_PENDING); UT_ASSERT_EQ(verdict.reply_opcode, 0xAAAAAAAAU); UT_ASSERT_EQ(verdict.reject_reason, 0xBBBBBBBBU); @@ -505,8 +502,7 @@ UT_TEST(test_configured_cap_controls_shmem_and_live_admission) size_at_two = cluster_ges_reply_wait_shmem_size(); cluster_ges_reply_wait_max_entries = 5; size_at_five = cluster_ges_reply_wait_shmem_size(); - UT_ASSERT_EQ(size_at_five - size_at_two, - (Size)(3 * sizeof(GesReplyWaitEntry))); + UT_ASSERT_EQ(size_at_five - size_at_two, (Size)(3 * sizeof(GesReplyWaitEntry))); reset_reply_wait_with_cap(2); UT_ASSERT_EQ(fake_init_size, 2); @@ -529,8 +525,7 @@ UT_TEST(test_sleep_exact_waits_without_consuming_pending_entry) UT_ASSERT_EQ(fake_cv_cancel_calls, 1); UT_ASSERT_EQ(fake_cv_timeout_ms, 1); UT_ASSERT_EQ(fake_cv_wait_event, 0x1234U); - UT_ASSERT_EQ(cluster_ges_reply_wait_poll_consume(&key, &verdict), - GES_REPLY_WAIT_POLL_PENDING); + UT_ASSERT_EQ(cluster_ges_reply_wait_poll_consume(&key, &verdict), GES_REPLY_WAIT_POLL_PENDING); UT_ASSERT_EQ(verdict.reply_opcode, 0xAAAAAAAAU); UT_ASSERT_EQ(verdict.reject_reason, 0xBBBBBBBBU); UT_ASSERT_EQ(fake_lock_acquires, fake_lock_releases); diff --git a/src/test/cluster_unit/test_cluster_grd.c b/src/test/cluster_unit/test_cluster_grd.c index 9d2c6c10d3f..f2680f19a13 100644 --- a/src/test/cluster_unit/test_cluster_grd.c +++ b/src/test/cluster_unit/test_cluster_grd.c @@ -58,10 +58,10 @@ #include "access/transam.h" /* spec-5.8 D1c — InvalidTransactionId */ #include "cluster/cluster_grd.h" #include "cluster/cluster_external_fence.h" -#include "cluster/cluster_hw.h" /* spec-4.6a HW remaster watchdog stubs */ -#include "cluster/cluster_lmd.h" /* spec-5.8 D1b — WFG vertex + submit/cancel edge */ -#include "cluster/cluster_undo_resid.h" /* spec-5.22a D1-5 — undo-class hash-route guard */ -#include "cluster/cluster_reconfig.h" /* spec-4.6 D1 — ReconfigEvent stub type */ +#include "cluster/cluster_hw.h" /* spec-4.6a HW remaster watchdog stubs */ +#include "cluster/cluster_lmd.h" /* spec-5.8 D1b — WFG vertex + submit/cancel edge */ +#include "cluster/cluster_undo_resid.h" /* spec-5.22a D1-5 — undo-class hash-route guard */ +#include "cluster/cluster_reconfig.h" /* spec-4.6 D1 — ReconfigEvent stub type */ #include "cluster/cluster_recovery_duty.h" #include "cluster/cluster_thread_recovery.h" /* spec-4.11 D3 (L238) — gate_unfreeze proto */ #include "port/atomics.h" @@ -483,16 +483,14 @@ cluster_reconfig_get_last_event(ReconfigEvent *out) } bool -cluster_reconfig_rejoin_failure_snapshot( - int32 old_node_id, uint64 old_incarnation, - ClusterReconfigRejoinFailureSnapshotV1 *out_failure) +cluster_reconfig_rejoin_failure_snapshot(int32 old_node_id, uint64 old_incarnation, + ClusterReconfigRejoinFailureSnapshotV1 *out_failure) { if (out_failure != NULL) memset(out_failure, 0, sizeof(*out_failure)); - if (out_failure == NULL || - old_node_id != ut_mock_rejoin_failure.old_node_id || - old_incarnation != ut_mock_rejoin_failure.old_incarnation || - ut_mock_rejoin_failure.event_id == 0) + if (out_failure == NULL || old_node_id != ut_mock_rejoin_failure.old_node_id + || old_incarnation != ut_mock_rejoin_failure.old_incarnation + || ut_mock_rejoin_failure.event_id == 0) return false; *out_failure = ut_mock_rejoin_failure; return true; @@ -921,9 +919,8 @@ cluster_lmd_submit_wait_edge_real(const ClusterLmdVertex *waiter, const ClusterL ClusterGrdGrantIdentity granted[PGRAC_GRD_MAX_CONVERTS_PUBLIC + 1]; ut_wfg_release_holder_on_submit_once = false; - ut_wfg_release_granted - = cluster_grd_release_and_drain(&ut_wfg_release_resid, &ut_wfg_release_holder, - granted, lengthof(granted)); + ut_wfg_release_granted = cluster_grd_release_and_drain( + &ut_wfg_release_resid, &ut_wfg_release_holder, granted, lengthof(granted)); } if (ut_wfg_throw_on_submit_once) { @@ -1786,8 +1783,7 @@ UT_TEST(test_grd_remote_grant_promotes_exact_reservation_amid_siblings) UT_ASSERT_EQ((int)mode, (int)ExclusiveLock); UT_ASSERT(!cluster_grd_holder_mode_by_id(&resid, &sibling, &mode)); - UT_ASSERT_EQ((int)cluster_grd_release_holder_by_id(&resid, &first), - (int)CLUSTER_GRD_ENTRY_OK); + UT_ASSERT_EQ((int)cluster_grd_release_holder_by_id(&resid, &first), (int)CLUSTER_GRD_ENTRY_OK); UT_ASSERT_EQ((int)cluster_grd_promote_remote_grant_exact(&resid, &sibling), (int)CLUSTER_GRD_ENTRY_OK); UT_ASSERT(cluster_grd_holder_mode_by_id(&resid, &sibling, &mode)); @@ -2087,8 +2083,7 @@ UT_TEST(test_grd_release_and_drain_reclaims_empty_entry) cluster_grd_entry_release(entry); missing = h1; missing.request_id++; - UT_ASSERT_EQ(cluster_grd_release_and_drain(&resid, &missing, granted, - lengthof(granted)), -1); + UT_ASSERT_EQ(cluster_grd_release_and_drain(&resid, &missing, granted, lengthof(granted)), -1); UT_ASSERT_EQ(cluster_grd_entry_count(), 1); /* exact holder retained */ (void)cluster_grd_release_and_drain(&resid, &h1, granted, lengthof(granted)); UT_ASSERT_EQ(cluster_grd_entry_count(), 0); /* empty -> reclaimed */ @@ -2698,8 +2693,7 @@ UT_TEST(test_walr_convert_nowait_conflict_never_enqueues) other.node_id = 2; other.procno = 200; other.request_id = 22; - UT_ASSERT_EQ((int)cluster_grd_entry_release_holder(e, &other), - (int)CLUSTER_GRD_ENTRY_OK); + UT_ASSERT_EQ((int)cluster_grd_entry_release_holder(e, &other), (int)CLUSTER_GRD_ENTRY_OK); UT_ASSERT_EQ((int)cluster_grd_entry_request_convert_nowait(e, &req, &drain), (int)CLUSTER_GRD_CONVERT_GRANTED_INPLACE); UT_ASSERT_EQ(cluster_grd_entry_nconverts(e), 0); @@ -2782,7 +2776,7 @@ UT_TEST(test_convert_u6_multiple_self_holders_excluded) convert_reset(); e = convert_make_entry(2016); - convert_grant(e, 1, 100, 11, ShareLock); /* precise convert source */ + convert_grant(e, 1, 100, 11, ShareLock); /* precise convert source */ convert_grant(e, 1, 100, 12, AccessShareLock); /* additive self holder */ req = convert_req(1, 100, ShareLock, AccessExclusiveLock, 77); @@ -2796,8 +2790,7 @@ UT_TEST(test_convert_u6_multiple_self_holders_excluded) converted.node_id = 1; converted.procno = 100; converted.request_id = 77; - UT_ASSERT_EQ((int)cluster_grd_entry_release_holder(e, &converted), - (int)CLUSTER_GRD_ENTRY_OK); + UT_ASSERT_EQ((int)cluster_grd_entry_release_holder(e, &converted), (int)CLUSTER_GRD_ENTRY_OK); UT_ASSERT_EQ(cluster_grd_entry_ngranted(e), 1); convert_teardown(); } @@ -2880,9 +2873,9 @@ UT_TEST(test_convert_u8_drain_converts_before_waiters) * slot. This specifically exercises the queued drain predicate. */ convert_reset(); e = convert_make_entry(2017); - convert_grant(e, 1, 100, 11, ShareLock); /* precise convert source */ + convert_grant(e, 1, 100, 11, ShareLock); /* precise convert source */ convert_grant(e, 1, 100, 12, AccessShareLock); /* additive self holder */ - convert_grant(e, 2, 200, 22, ShareLock); /* real remote blocker */ + convert_grant(e, 2, 200, 22, ShareLock); /* real remote blocker */ req = convert_req(1, 100, ShareLock, AccessExclusiveLock, 79); UT_ASSERT_EQ((int)cluster_grd_entry_request_convert(e, &req, &drain), @@ -2909,8 +2902,7 @@ UT_TEST(test_convert_u8_drain_converts_before_waiters) converted.node_id = 1; converted.procno = 100; converted.request_id = 79; - UT_ASSERT_EQ((int)cluster_grd_entry_release_holder(e, &converted), - (int)CLUSTER_GRD_ENTRY_OK); + UT_ASSERT_EQ((int)cluster_grd_entry_release_holder(e, &converted), (int)CLUSTER_GRD_ENTRY_OK); UT_ASSERT_EQ(cluster_grd_entry_ngranted(e), 1); UT_ASSERT(cluster_grd_entry_holder_mode(e, 1, 100, &m)); UT_ASSERT_EQ((int)m, (int)AccessShareLock); @@ -3466,19 +3458,16 @@ UT_TEST(test_walr_convert_nowait_requires_exact_old_holder_id) bast_resid(5184, &resid); holder = bast_holder(1, 100, 41); UT_ASSERT_EQ((int)cluster_grd_entry_enqueue_or_grant_meta( - &resid, &holder, 1, 41, - (ClusterGrdWaiterMeta){ (TransactionId)0, 0 }, 0, + &resid, &holder, 1, 41, (ClusterGrdWaiterMeta){ (TransactionId)0, 0 }, 0, UT_GES_OPCODE_REQUEST, ShareLock, conflicts, &nconflict), (int)CLUSTER_GRD_GRANT_NOW); - UT_ASSERT_EQ((int)cluster_grd_convert_nowait( - &resid, 1, 100, 0, ShareLock, ExclusiveLock, 42, - 999, 1, 0), - (int)CLUSTER_GRD_CONVERT_ILLEGAL); - UT_ASSERT_EQ((int)cluster_grd_convert_nowait( - &resid, 1, 100, 0, ShareLock, ExclusiveLock, 42, - 41, 1, 0), - (int)CLUSTER_GRD_CONVERT_GRANTED_INPLACE); + UT_ASSERT_EQ( + (int)cluster_grd_convert_nowait(&resid, 1, 100, 0, ShareLock, ExclusiveLock, 42, 999, 1, 0), + (int)CLUSTER_GRD_CONVERT_ILLEGAL); + UT_ASSERT_EQ( + (int)cluster_grd_convert_nowait(&resid, 1, 100, 0, ShareLock, ExclusiveLock, 42, 41, 1, 0), + (int)CLUSTER_GRD_CONVERT_GRANTED_INPLACE); convert_teardown(); } @@ -4015,16 +4004,16 @@ UT_TEST(test_5_8_wfg_projection_retries_after_release_wins_snapshot_publish_race bast_resid(5805, &resid); h = bast_holder(3, 482, 305); - UT_ASSERT_EQ((int)cluster_grd_entry_enqueue_or_grant(&resid, &h, 3, 305, 0, - UT_GES_OPCODE_REQUEST, ExclusiveLock, conflicts, &nc), + UT_ASSERT_EQ((int)cluster_grd_entry_enqueue_or_grant( + &resid, &h, 3, 305, 0, UT_GES_OPCODE_REQUEST, ExclusiveLock, conflicts, &nc), (int)CLUSTER_GRD_GRANT_NOW); ut_wfg_release_resid = resid; ut_wfg_release_holder = h; ut_wfg_release_holder_on_submit_once = true; h = bast_holder(3, 543, 306); - UT_ASSERT_EQ((int)cluster_grd_entry_enqueue_or_grant(&resid, &h, 3, 306, 0, - UT_GES_OPCODE_REQUEST, ExclusiveLock, conflicts, &nc), + UT_ASSERT_EQ((int)cluster_grd_entry_enqueue_or_grant( + &resid, &h, 3, 306, 0, UT_GES_OPCODE_REQUEST, ExclusiveLock, conflicts, &nc), (int)CLUSTER_GRD_ENQUEUED_WAITER); UT_ASSERT(!ut_wfg_release_holder_on_submit_once); @@ -4575,8 +4564,7 @@ UT_TEST(test_recovery_idle_ignores_join_pending) cluster_grd_recovery_lmon_tick(); cluster_grd_recovery_lmon_tick(); /* persistent staging remains inert */ - UT_ASSERT_EQ(cluster_grd_recovery_state_value(), - (uint32)GRD_RECOVERY_IDLE); + UT_ASSERT_EQ(cluster_grd_recovery_state_value(), (uint32)GRD_RECOVERY_IDLE); UT_ASSERT_EQ(cluster_grd_recovery_last_event_id(), 0); cluster_grd_recovery_counters_snapshot(&counters); UT_ASSERT_EQ(counters.remaster_started, 0); @@ -5282,16 +5270,14 @@ UT_TEST(test_rejoin_clear_snapshot_requires_exact_all_survivor_done_cut) ut_mock_last_event.event_id = failure.event_id; ut_mock_last_event.old_epoch = UINT64_C(8); ut_mock_last_event.new_epoch = failure.new_epoch; - ut_mock_last_event.cssd_dead_generation = - failure.cssd_dead_generation; + ut_mock_last_event.cssd_dead_generation = failure.cssd_dead_generation; ut_mock_last_event.coordinator_node_id = 0; ut_mock_last_event.reconfig_kind = RECONFIG_KIND_FAIL_STOP; memcpy(ut_mock_last_event.dead_bitmap, failure.dead_bitmap, sizeof(ut_mock_last_event.dead_bitmap)); ut_mock_epoch = failure.new_epoch; cluster_grd_recovery_lmon_tick(); - UT_ASSERT_EQ(cluster_grd_recovery_episode_epoch_value(), - failure.new_epoch); + UT_ASSERT_EQ(cluster_grd_recovery_episode_epoch_value(), failure.new_epoch); dead_hash = cluster_grd_dead_bitmap_hash(failure.dead_bitmap); UT_ASSERT_EQ(cluster_grd_recovery_event_bitmap_hash_value(), dead_hash); @@ -5305,8 +5291,8 @@ UT_TEST(test_rejoin_clear_snapshot_requires_exact_all_survivor_done_cut) UT_ASSERT(cluster_grd_rejoin_clear_snapshot(&failure, &clear)); UT_ASSERT_EQ(clear.episode_epoch, failure.new_epoch); UT_ASSERT_EQ(clear.dead_bitmap_hash, dead_hash); - UT_ASSERT(memcmp(clear.survivor_bitmap, failure.survivor_bitmap, - sizeof(clear.survivor_bitmap)) == 0); + UT_ASSERT(memcmp(clear.survivor_bitmap, failure.survivor_bitmap, sizeof(clear.survivor_bitmap)) + == 0); failure.survivor_bitmap[0] = 0; memset(&clear, 0xa5, sizeof(clear)); @@ -5347,8 +5333,7 @@ setup_recovery_authority_fixture(ClusterFormationSnapshotV1 *formation) } static void -setup_recovery_authority_singleton_fixture( - ClusterFormationSnapshotV1 *formation) +setup_recovery_authority_singleton_fixture(ClusterFormationSnapshotV1 *formation) { const int32 nodes[] = { 0 }; @@ -5374,8 +5359,7 @@ setup_recovery_authority_singleton_fixture( } static void -setup_recovery_authority_four_node_fixture( - ClusterFormationSnapshotV1 *formation) +setup_recovery_authority_four_node_fixture(ClusterFormationSnapshotV1 *formation) { const int32 nodes[] = { 0, 1, 2, 3 }; int i; @@ -5416,36 +5400,30 @@ UT_TEST(test_recovery_authority_done_echo_is_bounded_per_requester) int dest; setup_recovery_authority_four_node_fixture(&formation); - bitmap_hash = cluster_grd_dead_bitmap_hash( - formation.applied.dead_bitmap); + bitmap_hash = cluster_grd_dead_bitmap_hash(formation.applied.dead_bitmap); UT_ASSERT(bitmap_hash != 0); /* Drive far enough to stamp our exact self-DONE, but withhold all three * peer DONEs so the authority request terminates fail-closed. */ ut_drive_authority_lmon_tick = true; cluster_enabled = true; - UT_ASSERT(!cluster_grd_recovery_authority_barrier_wait( - &formation, 11, 7, 20)); + UT_ASSERT(!cluster_grd_recovery_authority_barrier_wait(&formation, 11, 7, 20)); ut_drive_authority_lmon_tick = false; cluster_grd_recovery_authority_lmon_tick(); memset(ut_done_enqueue_count, 0, sizeof(ut_done_enqueue_count)); - cluster_grd_recovery_mark_peer_done(1, formation.local_epoch, - bitmap_hash); + cluster_grd_recovery_mark_peer_done(1, formation.local_epoch, bitmap_hash); for (dest = 1; dest < 4; dest++) UT_ASSERT_EQ(ut_done_enqueue_count[dest], 1); /* Exact duplicate from requester 1 is idempotent. */ - cluster_grd_recovery_mark_peer_done(1, formation.local_epoch, - bitmap_hash); + cluster_grd_recovery_mark_peer_done(1, formation.local_epoch, bitmap_hash); for (dest = 1; dest < 4; dest++) UT_ASSERT_EQ(ut_done_enqueue_count[dest], 1); /* Distinct late requesters at the same composite each re-arm one echo. */ - cluster_grd_recovery_mark_peer_done(2, formation.local_epoch, - bitmap_hash); - cluster_grd_recovery_mark_peer_done(3, formation.local_epoch, - bitmap_hash); + cluster_grd_recovery_mark_peer_done(2, formation.local_epoch, bitmap_hash); + cluster_grd_recovery_mark_peer_done(3, formation.local_epoch, bitmap_hash); for (dest = 1; dest < 4; dest++) UT_ASSERT_EQ(ut_done_enqueue_count[dest], 3); @@ -5463,8 +5441,7 @@ UT_TEST(test_recovery_authority_postmaster_cannot_execute_blocking_barrier) /* With no LMON tick, the coordinator may only publish and poll. It * must time out fail-closed without running shard cleanup itself. */ - UT_ASSERT(!cluster_grd_recovery_authority_barrier_wait( - &formation, 11, 7, 2)); + UT_ASSERT(!cluster_grd_recovery_authority_barrier_wait(&formation, 11, 7, 2)); UT_ASSERT_EQ(ut_grd_blocking_lwlock_calls, 0); UT_ASSERT(!cluster_grd_recovery_authority_is_current(11, 7)); @@ -5487,8 +5464,7 @@ UT_TEST(test_recovery_authority_lmon_tick_is_sole_blocking_executor) ut_drive_authority_lmon_tick = true; cluster_enabled = true; - UT_ASSERT(cluster_grd_recovery_authority_barrier_wait( - &formation, 11, 7, 10)); + UT_ASSERT(cluster_grd_recovery_authority_barrier_wait(&formation, 11, 7, 10)); ut_drive_authority_lmon_tick = false; cluster_enabled = false; @@ -5510,8 +5486,7 @@ UT_TEST(test_recovery_authority_initial_epoch_zero_is_valid) ut_drive_authority_lmon_tick = true; cluster_enabled = true; - UT_ASSERT(cluster_grd_recovery_authority_barrier_wait( - &formation, 11, 7, 10)); + UT_ASSERT(cluster_grd_recovery_authority_barrier_wait(&formation, 11, 7, 10)); ut_drive_authority_lmon_tick = false; cluster_enabled = false; @@ -5525,8 +5500,7 @@ UT_TEST(test_recovery_authority_rejects_missing_peer_or_unremastered_map) ClusterFormationSnapshotV1 formation; setup_recovery_authority_fixture(&formation); - UT_ASSERT(!cluster_grd_recovery_authority_barrier_wait( - &formation, 11, 7, 2)); + UT_ASSERT(!cluster_grd_recovery_authority_barrier_wait(&formation, 11, 7, 2)); UT_ASSERT(!cluster_grd_recovery_authority_is_current(11, 7)); /* A declared shard master outside the exact MEMBER formation is not @@ -5534,8 +5508,7 @@ UT_TEST(test_recovery_authority_rejects_missing_peer_or_unremastered_map) setup_recovery_authority_fixture(&formation); formation.membership.membership_state[1] = CLUSTER_MEMBER_ABSENT; ut_member_mask = 0x1; - UT_ASSERT(!cluster_grd_recovery_authority_barrier_wait( - &formation, 11, 7, 10)); + UT_ASSERT(!cluster_grd_recovery_authority_barrier_wait(&formation, 11, 7, 10)); UT_ASSERT(!cluster_grd_recovery_authority_is_current(11, 7)); } @@ -5559,14 +5532,12 @@ UT_TEST(test_recovery_authority_same_composite_repost_retains_done_slots) ut_drive_authority_lmon_tick = false; cluster_enabled = true; - bitmap_hash = cluster_grd_dead_bitmap_hash( - formation.applied.dead_bitmap); + bitmap_hash = cluster_grd_dead_bitmap_hash(formation.applied.dead_bitmap); UT_ASSERT(bitmap_hash != 0); /* gen=1: no LMON tick and no peer DONE -> timeout fail-closed (the * request is cancelled, the composite fields stay published). */ - UT_ASSERT(!cluster_grd_recovery_authority_barrier_wait( - &formation, 11, 7, 2)); + UT_ASSERT(!cluster_grd_recovery_authority_barrier_wait(&formation, 11, 7, 2)); /* Terminalize the cancelled request so a fresh generation may post * (request-pending gate). */ @@ -5575,14 +5546,12 @@ UT_TEST(test_recovery_authority_same_composite_repost_retains_done_slots) /* The peer completed its re-declare at the request composite while the * request fields were still published; its DONE stamps the authority * slot (the exact evidence a same-composite re-post needs). */ - cluster_grd_recovery_mark_peer_done(1, formation.local_epoch, - bitmap_hash); + cluster_grd_recovery_mark_peer_done(1, formation.local_epoch, bitmap_hash); /* gen=2 re-post of the IDENTICAL composite: with the peer slot retained, * the driven LMON tick converges without any fresh peer frame. */ ut_drive_authority_lmon_tick = true; - UT_ASSERT(cluster_grd_recovery_authority_barrier_wait( - &formation, 11, 7, 20)); + UT_ASSERT(cluster_grd_recovery_authority_barrier_wait(&formation, 11, 7, 20)); ut_drive_authority_lmon_tick = false; cluster_enabled = false; UT_ASSERT(cluster_grd_recovery_authority_is_current(11, 7)); @@ -5605,17 +5574,14 @@ UT_TEST(test_recovery_authority_composite_change_repost_requires_fresh_done) ut_drive_authority_lmon_tick = false; cluster_enabled = true; - bitmap_hash = cluster_grd_dead_bitmap_hash( - formation.applied.dead_bitmap); + bitmap_hash = cluster_grd_dead_bitmap_hash(formation.applied.dead_bitmap); UT_ASSERT(bitmap_hash != 0); /* Same prologue as the retention test: gen=1 cancelled, peer slot * stamped at (5, hash). */ - UT_ASSERT(!cluster_grd_recovery_authority_barrier_wait( - &formation, 11, 7, 2)); + UT_ASSERT(!cluster_grd_recovery_authority_barrier_wait(&formation, 11, 7, 2)); cluster_grd_recovery_authority_lmon_tick(); - cluster_grd_recovery_mark_peer_done(1, formation.local_epoch, - bitmap_hash); + cluster_grd_recovery_mark_peer_done(1, formation.local_epoch, bitmap_hash); /* The epoch advances (a new reconfig event): the re-post composite * CHANGES, so the old (5, hash) slots must not carry over. */ @@ -5626,19 +5592,16 @@ UT_TEST(test_recovery_authority_composite_change_repost_requires_fresh_done) /* gen=2 at (6, hash): the peer slot was zeroed by the composite change; * with no fresh (6, hash) DONE the barrier must fail closed. */ ut_drive_authority_lmon_tick = true; - UT_ASSERT(!cluster_grd_recovery_authority_barrier_wait( - &formation, 11, 7, 20)); + UT_ASSERT(!cluster_grd_recovery_authority_barrier_wait(&formation, 11, 7, 20)); /* Terminalize the cancelled gen=2 so a fresh generation may post, then * a fresh peer DONE at the new composite lets the next same-composite * retry converge. */ ut_drive_authority_lmon_tick = false; cluster_grd_recovery_authority_lmon_tick(); - cluster_grd_recovery_mark_peer_done(1, formation.local_epoch, - bitmap_hash); + cluster_grd_recovery_mark_peer_done(1, formation.local_epoch, bitmap_hash); ut_drive_authority_lmon_tick = true; - UT_ASSERT(cluster_grd_recovery_authority_barrier_wait( - &formation, 11, 7, 20)); + UT_ASSERT(cluster_grd_recovery_authority_barrier_wait(&formation, 11, 7, 20)); ut_drive_authority_lmon_tick = false; cluster_enabled = false; UT_ASSERT(cluster_grd_recovery_authority_is_current(11, 7)); diff --git a/src/test/cluster_unit/test_cluster_grd_starvation.c b/src/test/cluster_unit/test_cluster_grd_starvation.c index b9ab59e2a5b..f964500a90a 100644 --- a/src/test/cluster_unit/test_cluster_grd_starvation.c +++ b/src/test/cluster_unit/test_cluster_grd_starvation.c @@ -404,10 +404,9 @@ cluster_thread_recovery_launch_workers(const uint64 *dead pg_attribute_unused(), {} bool -cluster_reconfig_rejoin_failure_snapshot( - int32 old_node_id pg_attribute_unused(), - uint64 old_incarnation pg_attribute_unused(), - ClusterReconfigRejoinFailureSnapshotV1 *out_failure) +cluster_reconfig_rejoin_failure_snapshot(int32 old_node_id pg_attribute_unused(), + uint64 old_incarnation pg_attribute_unused(), + ClusterReconfigRejoinFailureSnapshotV1 *out_failure) { if (out_failure != NULL) memset(out_failure, 0, sizeof(*out_failure)); @@ -641,15 +640,34 @@ GetNamedLWLockTranche(const char *tranche_name pg_attribute_unused()) return dummy_locks; } +static LWLock *held_locks[8]; +static int held_lock_count; + bool -LWLockAcquire(LWLock *lock pg_attribute_unused(), LWLockMode mode pg_attribute_unused()) +LWLockAcquire(LWLock *lock, LWLockMode mode pg_attribute_unused()) { + if (held_lock_count >= lengthof(held_locks)) + abort(); + held_locks[held_lock_count++] = lock; return true; } void -LWLockRelease(LWLock *lock pg_attribute_unused()) -{} +LWLockRelease(LWLock *lock) +{ + if (held_lock_count <= 0 || held_locks[held_lock_count - 1] != lock) + abort(); + held_lock_count--; +} + +bool +LWLockHeldByMe(LWLock *lock) +{ + for (int i = 0; i < held_lock_count; i++) + if (held_locks[i] == lock) + return true; + return false; +} /* spec-2.23 D6 stub: PG exported DoLockModesConflict — cluster_grd.c * uses this in enqueue_or_grant / release_and_pop_compatible_waiter. @@ -939,8 +957,7 @@ cluster_clean_leave_node_refuses_writes(void) void cluster_lmon_wakeup(void) -{ -} +{} uint64 cluster_lms_get_lms_restart_generation(void) diff --git a/src/test/cluster_unit/test_cluster_guc.c b/src/test/cluster_unit/test_cluster_guc.c index 3d97089478c..e46ea60cbc4 100644 --- a/src/test/cluster_unit/test_cluster_guc.c +++ b/src/test/cluster_unit/test_cluster_guc.c @@ -117,31 +117,26 @@ static GucStringAssignHook pcm_x_retain_flush_error_target_assign_hook = NULL; * for the missing injection-only symbols instead of failing at link time. * The real cluster_guc object replaces both definitions once D3 lands. */ char *cluster_pcm_x_retain_flush_error_target __attribute__((weak)) = NULL; -extern bool cluster_pcm_x_retain_flush_error_target_matches(uint32 spc_oid, - uint32 db_oid, - uint32 rel_number, - int fork_number, - uint32 block_number) +extern bool cluster_pcm_x_retain_flush_error_target_matches(uint32 spc_oid, uint32 db_oid, + uint32 rel_number, int fork_number, + uint32 block_number) __attribute__((weak)); bool cluster_pcm_x_retain_flush_error_target_matches(uint32 spc_oid pg_attribute_unused(), - uint32 db_oid pg_attribute_unused(), - uint32 rel_number pg_attribute_unused(), - int fork_number pg_attribute_unused(), - uint32 block_number pg_attribute_unused()) + uint32 db_oid pg_attribute_unused(), + uint32 rel_number pg_attribute_unused(), + int fork_number pg_attribute_unused(), + uint32 block_number pg_attribute_unused()) { return false; } #endif void -DefineCustomIntVariable(const char *name, - const char *short_desc pg_attribute_unused(), - const char *long_desc, - int *valueAddr, int bootValue, - int minValue, int maxValue, - GucContext context, int flags pg_attribute_unused(), +DefineCustomIntVariable(const char *name, const char *short_desc pg_attribute_unused(), + const char *long_desc, int *valueAddr, int bootValue, int minValue, + int maxValue, GucContext context, int flags pg_attribute_unused(), GucIntCheckHook check_hook pg_attribute_unused(), GucIntAssignHook assign_hook pg_attribute_unused(), GucShowHook show_hook pg_attribute_unused()) @@ -154,8 +149,7 @@ DefineCustomIntVariable(const char *name, undo_buffers_max_value = maxValue; undo_buffers_context = context; undo_buffers_long_desc = long_desc; - } - else if (strcmp(name, "cluster.external_fence_acquire_timeout_ms") == 0) { + } else if (strcmp(name, "cluster.external_fence_acquire_timeout_ms") == 0) { external_fence_timeout_value_addr = valueAddr; external_fence_timeout_boot_value = bootValue; external_fence_timeout_min_value = minValue; @@ -195,13 +189,12 @@ DefineCustomRealVariable( } void -DefineCustomStringVariable( - const char *name, const char *short_desc pg_attribute_unused(), - const char *long_desc pg_attribute_unused(), char **valueAddr pg_attribute_unused(), - const char *bootValue, GucContext context, - int flags, GucStringCheckHook check_hook, - GucStringAssignHook assign_hook pg_attribute_unused(), - GucShowHook show_hook pg_attribute_unused()) +DefineCustomStringVariable(const char *name, const char *short_desc pg_attribute_unused(), + const char *long_desc pg_attribute_unused(), + char **valueAddr pg_attribute_unused(), const char *bootValue, + GucContext context, int flags, GucStringCheckHook check_hook, + GucStringAssignHook assign_hook pg_attribute_unused(), + GucShowHook show_hook pg_attribute_unused()) { if (strcmp(name, "cluster.external_fence_socket_path") == 0) { external_fence_socket_value_addr = valueAddr; @@ -547,8 +540,8 @@ UT_TEST(test_external_fence_guc_contract) external_fence_socket_check_hook = NULL; cluster_init_guc(); - UT_ASSERT_EQ(external_fence_timeout_value_addr == - &cluster_external_fence_acquire_timeout_ms, true); + UT_ASSERT_EQ(external_fence_timeout_value_addr == &cluster_external_fence_acquire_timeout_ms, + true); UT_ASSERT_EQ(cluster_external_fence_acquire_timeout_ms, 120000); UT_ASSERT_EQ(external_fence_timeout_boot_value, 120000); UT_ASSERT_EQ(external_fence_timeout_min_value, 1); @@ -556,26 +549,21 @@ UT_TEST(test_external_fence_guc_contract) UT_ASSERT_EQ(external_fence_timeout_context, PGC_SIGHUP); UT_ASSERT_EQ(external_fence_timeout_flags, GUC_UNIT_MS); - UT_ASSERT_EQ(external_fence_socket_value_addr == - &cluster_external_fence_socket_path, true); - UT_ASSERT_STR_EQ(external_fence_socket_boot_value, - "/var/run/pgrac/pgrac-fenced.sock"); + UT_ASSERT_EQ(external_fence_socket_value_addr == &cluster_external_fence_socket_path, true); + UT_ASSERT_STR_EQ(external_fence_socket_boot_value, "/var/run/pgrac/pgrac-fenced.sock"); UT_ASSERT_EQ(external_fence_socket_context, PGC_POSTMASTER); UT_ASSERT_EQ(external_fence_socket_flags, 0); UT_ASSERT_NOT_NULL(external_fence_socket_check_hook); if (external_fence_socket_check_hook != NULL) { UT_ASSERT(external_fence_socket_check_hook(&valid, &extra, PGC_S_TEST)); UT_ASSERT(!external_fence_socket_check_hook(&relative, &extra, PGC_S_TEST)); - UT_ASSERT(!external_fence_socket_check_hook(&parent_component, &extra, - PGC_S_TEST)); - UT_ASSERT(external_fence_socket_check_hook(&dotdot_name, &extra, - PGC_S_TEST)); + UT_ASSERT(!external_fence_socket_check_hook(&parent_component, &extra, PGC_S_TEST)); + UT_ASSERT(external_fence_socket_check_hook(&dotdot_name, &extra, PGC_S_TEST)); memset(too_long, 'a', sizeof(too_long)); too_long[0] = '/'; too_long[sizeof(too_long) - 1] = '\0'; - UT_ASSERT(!external_fence_socket_check_hook(&too_long_ptr, &extra, - PGC_S_TEST)); + UT_ASSERT(!external_fence_socket_check_hook(&too_long_ptr, &extra, PGC_S_TEST)); } } @@ -584,29 +572,14 @@ UT_TEST(test_external_fence_guc_contract) UT_TEST(test_pcm_x_retain_flush_error_target_guc_contract) { static const char *const invalid_targets[] - = { "0/5/12345/0/0", - "1663/0/12345/0/0", - "1663/5/0/0/0", - "1663/5/12345/0", - "1663//12345/0/0", - "1663/5//0/0", - "1663/5/12345//0", - "1663/5/12345/0/", - "1663/5/12345/0/0/1", - " 1663/5/12345/0/0", - "1663/5/12345/0/0 ", - "1663/ 5/12345/0/0", - "+1663/5/12345/0/0", - "-1663/5/12345/0/0", - "0x67f/5/12345/0/0", - "1663/5/12x45/0/0", - "1663/5/12345/0/0suffix", - "1663/5/12345/0/0\n", - "4294967296/5/12345/0/0", - "1663/4294967296/12345/0/0", - "1663/5/4294967296/0/0", - "1663/5/12345/4/0", - "1663/5/12345/0/4294967295" }; + = { "0/5/12345/0/0", "1663/0/12345/0/0", "1663/5/0/0/0", + "1663/5/12345/0", "1663//12345/0/0", "1663/5//0/0", + "1663/5/12345//0", "1663/5/12345/0/", "1663/5/12345/0/0/1", + " 1663/5/12345/0/0", "1663/5/12345/0/0 ", "1663/ 5/12345/0/0", + "+1663/5/12345/0/0", "-1663/5/12345/0/0", "0x67f/5/12345/0/0", + "1663/5/12x45/0/0", "1663/5/12345/0/0suffix", "1663/5/12345/0/0\n", + "4294967296/5/12345/0/0", "1663/4294967296/12345/0/0", "1663/5/4294967296/0/0", + "1663/5/12345/4/0", "1663/5/12345/0/4294967295" }; char *value; void *extra; int i; @@ -620,19 +593,20 @@ UT_TEST(test_pcm_x_retain_flush_error_target_guc_contract) cluster_init_guc(); UT_ASSERT_NOT_NULL(pcm_x_retain_flush_error_target_value_addr); - UT_ASSERT_NOT_NULL((void *) &cluster_pcm_x_retain_flush_error_target); + UT_ASSERT_NOT_NULL((void *)&cluster_pcm_x_retain_flush_error_target); if (&cluster_pcm_x_retain_flush_error_target != NULL) - UT_ASSERT_EQ(pcm_x_retain_flush_error_target_value_addr == - &cluster_pcm_x_retain_flush_error_target, true); + UT_ASSERT_EQ(pcm_x_retain_flush_error_target_value_addr + == &cluster_pcm_x_retain_flush_error_target, + true); UT_ASSERT_STR_EQ(pcm_x_retain_flush_error_target_boot_value, ""); UT_ASSERT_EQ(pcm_x_retain_flush_error_target_context, PGC_SUSET); UT_ASSERT_EQ(pcm_x_retain_flush_error_target_flags, GUC_NOT_IN_SAMPLE); UT_ASSERT_NOT_NULL(pcm_x_retain_flush_error_target_check_hook); UT_ASSERT_NOT_NULL(pcm_x_retain_flush_error_target_assign_hook); - UT_ASSERT_NOT_NULL((void *) cluster_pcm_x_retain_flush_error_target_matches); - if (pcm_x_retain_flush_error_target_check_hook == NULL || - pcm_x_retain_flush_error_target_assign_hook == NULL || - cluster_pcm_x_retain_flush_error_target_matches == NULL) + UT_ASSERT_NOT_NULL((void *)cluster_pcm_x_retain_flush_error_target_matches); + if (pcm_x_retain_flush_error_target_check_hook == NULL + || pcm_x_retain_flush_error_target_assign_hook == NULL + || cluster_pcm_x_retain_flush_error_target_matches == NULL) return; /* Empty is a valid assignment with a distinct match-none parse result. */ @@ -672,8 +646,8 @@ UT_TEST(test_pcm_x_retain_flush_error_target_guc_contract) pcm_x_retain_flush_error_target_assign_hook(value, extra); free(extra); } - UT_ASSERT(cluster_pcm_x_retain_flush_error_target_matches( - UINT32_MAX, UINT32_MAX, UINT32_MAX, MAX_FORKNUM, InvalidBlockNumber - 1)); + UT_ASSERT(cluster_pcm_x_retain_flush_error_target_matches(UINT32_MAX, UINT32_MAX, UINT32_MAX, + MAX_FORKNUM, InvalidBlockNumber - 1)); /* Restore the canonical value. Every rejected check leaves this assigned * parse untouched because the assign hook is never called. */ @@ -685,15 +659,14 @@ UT_TEST(test_pcm_x_retain_flush_error_target_guc_contract) free(extra); } for (i = 0; i < lengthof(invalid_targets); i++) { - value = (char *) invalid_targets[i]; + value = (char *)invalid_targets[i]; extra = NULL; last_guc_check_errcode = 0; UT_ASSERT(!pcm_x_retain_flush_error_target_check_hook(&value, &extra, PGC_S_TEST)); UT_ASSERT_EQ(last_guc_check_errcode, ERRCODE_INVALID_PARAMETER_VALUE); if (extra != NULL) free(extra); - UT_ASSERT(cluster_pcm_x_retain_flush_error_target_matches( - 1663, 5, 12345, 0, 0)); + UT_ASSERT(cluster_pcm_x_retain_flush_error_target_matches(1663, 5, 12345, 0, 0)); } } #endif diff --git a/src/test/cluster_unit/test_cluster_heap_barrier.c b/src/test/cluster_unit/test_cluster_heap_barrier.c index 1d7389d31eb..366f432b0c1 100644 --- a/src/test/cluster_unit/test_cluster_heap_barrier.c +++ b/src/test/cluster_unit/test_cluster_heap_barrier.c @@ -35,19 +35,18 @@ UT_DEFINE_GLOBALS(); -typedef struct FetchFixture -{ +typedef struct FetchFixture { TableIndexFetchTupleResult typed_result; - bool legacy_found; - bool mutate_tid; - bool set_all_dead; - bool slot_empty; - bool call_again_seen; - int tid; - int typed_calls; - int legacy_calls; - int cleanup_calls; - bool throw_error; + bool legacy_found; + bool mutate_tid; + bool set_all_dead; + bool slot_empty; + bool call_again_seen; + int tid; + int typed_calls; + int legacy_calls; + int cleanup_calls; + bool throw_error; } FetchFixture; static sigjmp_buf error_jump; @@ -100,11 +99,9 @@ fixture_cleanup(void *context) fixture->cleanup_calls++; } -static const TableIndexFetchBarrierOps fixture_ops = { - .typed_fetch = fixture_typed_fetch, - .legacy_fetch = fixture_legacy_fetch, - .cleanup = fixture_cleanup -}; +static const TableIndexFetchBarrierOps fixture_ops = { .typed_fetch = fixture_typed_fetch, + .legacy_fetch = fixture_legacy_fetch, + .cleanup = fixture_cleanup }; static FetchFixture fetch_fixture(void) @@ -120,10 +117,9 @@ fetch_fixture(void) UT_TEST(test_t1_legacy_false_maps_to_not_found) { FetchFixture fixture = fetch_fixture(); - bool all_dead = true; + bool all_dead = true; - UT_ASSERT_EQ(table_index_fetch_barrier_execute(&fixture_ops, &fixture, - false, &all_dead), + UT_ASSERT_EQ(table_index_fetch_barrier_execute(&fixture_ops, &fixture, false, &all_dead), TABLE_INDEX_FETCH_NOT_FOUND); UT_ASSERT_EQ(fixture.legacy_calls, 1); UT_ASSERT_EQ(fixture.typed_calls, 0); @@ -135,8 +131,7 @@ UT_TEST(test_t2_legacy_true_maps_to_found) FetchFixture fixture = fetch_fixture(); fixture.legacy_found = true; - UT_ASSERT_EQ(table_index_fetch_barrier_execute(&fixture_ops, &fixture, - false, NULL), + UT_ASSERT_EQ(table_index_fetch_barrier_execute(&fixture_ops, &fixture, false, NULL), TABLE_INDEX_FETCH_FOUND); UT_ASSERT(!fixture.slot_empty); UT_ASSERT_EQ(fixture.cleanup_calls, 1); @@ -145,11 +140,10 @@ UT_TEST(test_t2_legacy_true_maps_to_found) UT_TEST(test_t3_barrier_is_disjoint_and_mutates_no_visibility_state) { FetchFixture fixture = fetch_fixture(); - bool all_dead = true; + bool all_dead = true; fixture.typed_result = TABLE_INDEX_FETCH_BARRIER_CLOSED; - UT_ASSERT_EQ(table_index_fetch_barrier_execute(&fixture_ops, &fixture, - true, &all_dead), + UT_ASSERT_EQ(table_index_fetch_barrier_execute(&fixture_ops, &fixture, true, &all_dead), TABLE_INDEX_FETCH_BARRIER_CLOSED); UT_ASSERT_EQ(fixture.tid, 42); UT_ASSERT(!all_dead); @@ -162,8 +156,7 @@ UT_TEST(test_t4_typed_not_found_preserves_completed_scan_result) FetchFixture fixture = fetch_fixture(); fixture.typed_result = TABLE_INDEX_FETCH_NOT_FOUND; - UT_ASSERT_EQ(table_index_fetch_barrier_execute(&fixture_ops, &fixture, - true, NULL), + UT_ASSERT_EQ(table_index_fetch_barrier_execute(&fixture_ops, &fixture, true, NULL), TABLE_INDEX_FETCH_NOT_FOUND); UT_ASSERT_EQ(fixture.typed_calls, 1); UT_ASSERT(fixture.slot_empty); @@ -172,13 +165,12 @@ UT_TEST(test_t4_typed_not_found_preserves_completed_scan_result) UT_TEST(test_t5_typed_found_preserves_callback_outputs) { FetchFixture fixture = fetch_fixture(); - bool all_dead = false; + bool all_dead = false; fixture.typed_result = TABLE_INDEX_FETCH_FOUND; fixture.mutate_tid = true; fixture.set_all_dead = true; - UT_ASSERT_EQ(table_index_fetch_barrier_execute(&fixture_ops, &fixture, - true, &all_dead), + UT_ASSERT_EQ(table_index_fetch_barrier_execute(&fixture_ops, &fixture, true, &all_dead), TABLE_INDEX_FETCH_FOUND); UT_ASSERT_EQ(fixture.tid, 43); UT_ASSERT(all_dead); @@ -191,10 +183,8 @@ UT_TEST(test_t6_callback_error_propagates_without_false_result) FetchFixture fixture = fetch_fixture(); fixture.throw_error = true; - if (sigsetjmp(error_jump, 1) == 0) - { - (void) table_index_fetch_barrier_execute(&fixture_ops, &fixture, - true, NULL); + if (sigsetjmp(error_jump, 1) == 0) { + (void)table_index_fetch_barrier_execute(&fixture_ops, &fixture, true, NULL); UT_ASSERT(false); } UT_ASSERT_EQ(fixture.cleanup_calls, 0); @@ -205,12 +195,10 @@ UT_TEST(test_t7_cleanup_runs_once_for_each_normal_result) FetchFixture fixture = fetch_fixture(); TableIndexFetchTupleResult result; - for (result = TABLE_INDEX_FETCH_NOT_FOUND; - result <= TABLE_INDEX_FETCH_BARRIER_CLOSED; result++) - { + for (result = TABLE_INDEX_FETCH_NOT_FOUND; result <= TABLE_INDEX_FETCH_BARRIER_CLOSED; + result++) { fixture.typed_result = result; - UT_ASSERT_EQ(table_index_fetch_barrier_execute(&fixture_ops, &fixture, - true, NULL), result); + UT_ASSERT_EQ(table_index_fetch_barrier_execute(&fixture_ops, &fixture, true, NULL), result); } UT_ASSERT_EQ(fixture.cleanup_calls, 3); } diff --git a/src/test/cluster_unit/test_cluster_heap_prepare_diagnostic.c b/src/test/cluster_unit/test_cluster_heap_prepare_diagnostic.c new file mode 100644 index 00000000000..36ba1aba490 --- /dev/null +++ b/src/test/cluster_unit/test_cluster_heap_prepare_diagnostic.c @@ -0,0 +1,246 @@ +/*------------------------------------------------------------------------- + * test_cluster_heap_prepare_diagnostic.c + * Exact production prepare refusal attribution, without changing decisions. + * + * Portions Copyright (c) 2026, pgrac contributors + * Author: SqlRush + * + * The extracted production helper is the unit under test. Capacity/census, + * PCM and receipt services are explicit boundaries, not a live replay. + *------------------------------------------------------------------------- + */ +#include "postgres.h" +#include "access/heapam.h" +#include "cluster/cluster_undo_record_api.h" +#include "../../backend/access/heap/heapam_r4_private.h" + +#undef printf +#include "unit_test.h" +UT_DEFINE_GLOBALS(); + +/* Only passed to the controlled guard/target services by this helper. */ +typedef struct ClusterHeapDmlAuthorityGuard { + int unused; +} ClusterHeapDmlAuthorityGuard; +static int fault; +static bool capacity_requested; +static bool request_lock_only = true; +static int wait_calls; +static bool content_unlocked; +static ClusterTxwResult wait_result; +static jmp_buf wait_error_jump; +static bool wait_error; + +/* Error reporting is an explicit fixture boundary, not a new product policy. */ +#undef ereport +#define ereport(level, rest) \ + do { \ + wait_error = true; \ + longjmp(wait_error_jump, 1); \ + } while (0) + +static ClusterTxwResult +cluster_heap_itl_wait_capacity_after_census(Buffer old_buffer, Buffer new_buffer, + Buffer full_buffer, TransactionId xid, bool lock_only, + uint64 *deadline, const char **reason) +{ + wait_calls++; + UT_ASSERT_EQ(old_buffer, 1); + UT_ASSERT_EQ(new_buffer, old_buffer); + UT_ASSERT_EQ(full_buffer, old_buffer); + UT_ASSERT_EQ(xid, 700); + UT_ASSERT(lock_only); + UT_ASSERT_EQ(*deadline, 12345); + *reason = "CONTROLLED_WAIT_RESULT"; + return wait_result; +} + +void +ExceptionalCondition(const char *condition, const char *file, int line) +{ + abort(); +} + +static ClusterHeapItlCapacityResult +cluster_heap_itl_ensure_capacity_with_terminal_census(Buffer buffer, TransactionId xid, + bool lock_only) +{ + return fault == 1 ? CLUSTER_HEAP_ITL_CAPACITY_EXHAUSTED_OR_REFUSED + : fault == 2 ? CLUSTER_HEAP_ITL_CAPACITY_RETRY_REQUALIFY + : CLUSTER_HEAP_ITL_CAPACITY_READY; +} + +static bool +cluster_heap_dml_authority_guard_capture(Buffer buffer, HeapTuple tuple, + ClusterHeapDmlAuthorityGuard *guard) +{ + return fault != 3; +} + +bool +cluster_undo_record_prepared_recheck(const ClusterUndoRecordPrepareReceipt *receipt, + uint16 payload_len) +{ + return fault != 4; +} + +static bool +cluster_heap_ctrc_pending_itl_target(Relation relation, Buffer buffer, + const ClusterHeapDmlAuthorityGuard *guard, uint8 record_type, + ClusterCtrcTargetV1 *target) +{ + return fault != 5; +} + +bool +cluster_undo_record_ctrc_stage_pending(ClusterUndoRecordPrepareReceipt *receipt, uint8 ordinal, + const ClusterCtrcTargetV1 *target) +{ + if (fault == 6) + return false; + receipt->ctrc_pending_mask |= UINT8_C(1); + return true; +} + +bool +cluster_undo_record_ctrc_pending_recheck(const ClusterUndoRecordPrepareReceipt *receipt, + uint8 ordinal, const ClusterCtrcTargetV1 *target) +{ + return fault != 7; +} + +static bool +cluster_heap_ctrc_stage_reusable_itl_receipt(Relation relation, Buffer buffer, TransactionId xid, + bool lock_only, + ClusterUndoRecordPrepareReceipt *receipt, + uint8 ordinal, const ClusterCtrcTargetV1 *target) +{ + return fault != 8; +} + +bool +cluster_undo_record_ctrc_pending_matches(const ClusterUndoRecordPrepareReceipt *receipt, + uint8 ordinal, const ClusterCtrcTargetV1 *target) +{ + return fault != 9; +} + +#include "test_cluster_heap_prepare_diagnostic.inc" + +static void +check_prepare(int cause, bool applied, int expected, const char *reason) +{ + ClusterUndoRecordPrepareReceipt receipt = { 0 }; + const char *observed = NULL; + bool invalidated = false; + ClusterHeapPreparedUndoResult result; + uint64 capacity_deadline = 12345; + + fault = cause; + receipt.ctrc_applied_mask = applied ? 1 : 0; + if (cause == 7 || cause == 9) + receipt.ctrc_pending_mask = 1; + if (cause == 9) + receipt.ctrc_prepared_mask = 1; +#ifdef PREPARE_HAS_CAPACITY_WAIT + observed = "old cause must not leak"; + result = cluster_heap_itl_prepare_prepared_undo( + NULL, 1, NULL, 700, request_lock_only, &receipt, 64, &invalidated, &observed, + capacity_requested ? &capacity_deadline : NULL, &content_unlocked); +#elif defined(PREPARE_HAS_DIAGNOSTIC) + observed = "old cause must not leak"; + result = cluster_heap_itl_prepare_prepared_undo(NULL, 1, NULL, 700, true, &receipt, 64, + &invalidated, &observed); +#else + /* Baseline executes the same production decision but has no reason output. */ + result = cluster_heap_itl_prepare_prepared_undo(NULL, 1, NULL, 700, true, &receipt, 64, + &invalidated); +#endif + UT_ASSERT_EQ(result, expected); + UT_ASSERT_EQ(invalidated, + cause == 7 || cause == 9 + || (capacity_requested && request_lock_only && cause == 1 && !applied)); + UT_ASSERT_EQ(receipt.ctrc_applied_mask, applied ? 1 : 0); + if (reason != NULL) { + UT_ASSERT(observed != NULL); + if (observed != NULL) + UT_ASSERT_EQ(strcmp(observed, reason), 0); + } else + UT_ASSERT(observed == NULL); +} + +UT_TEST(full_lock_capacity_waits_then_requalifies_without_apply) +{ + capacity_requested = true; + for (int retry = 0; retry < 2; retry++) { + wait_calls = 0; + content_unlocked = false; + wait_result = retry ? CLUSTER_TXW_RETRY : CLUSTER_TXW_RESOLVED; + check_prepare(1, false, CLUSTER_HEAP_PREPARED_UNDO_RETRY_REQUIRED, NULL); + UT_ASSERT_EQ(wait_calls, 1); + UT_ASSERT(content_unlocked); + } + /* APPLY cannot be cancelled by this waiting branch. */ + wait_calls = 0; + content_unlocked = false; + check_prepare(1, true, CLUSTER_HEAP_PREPARED_UNDO_REFUSED, "ITL_CAPACITY_REFUSED"); + UT_ASSERT_EQ(wait_calls, 0); + UT_ASSERT(!content_unlocked); + request_lock_only = false; + check_prepare(1, false, CLUSTER_HEAP_PREPARED_UNDO_REFUSED, "ITL_CAPACITY_REFUSED"); + UT_ASSERT_EQ(wait_calls, 0); + UT_ASSERT(!content_unlocked); + request_lock_only = true; + capacity_requested = false; +} + +UT_TEST(unproved_or_failed_wait_is_not_a_retry_success) +{ + const ClusterTxwResult failures[] + = { CLUSTER_TXW_UNPROVABLE, CLUSTER_TXW_TIMEOUT, CLUSTER_TXW_DEADLOCK }; + capacity_requested = true; + for (unsigned i = 0; i < lengthof(failures); i++) { + wait_calls = 0; + wait_error = content_unlocked = false; + wait_result = failures[i]; + if (setjmp(wait_error_jump) == 0) + check_prepare(1, false, CLUSTER_HEAP_PREPARED_UNDO_REFUSED, NULL); + UT_ASSERT(wait_error); + UT_ASSERT(content_unlocked); + UT_ASSERT_EQ(wait_calls, 1); + } + capacity_requested = false; +} + +UT_TEST(refusals_have_unique_exact_causes) +{ + check_prepare(1, false, CLUSTER_HEAP_PREPARED_UNDO_REFUSED, "ITL_CAPACITY_REFUSED"); + check_prepare(4, true, CLUSTER_HEAP_PREPARED_UNDO_REFUSED, "POST_APPLY_PREPARED_RECHECK"); + check_prepare(5, false, CLUSTER_HEAP_PREPARED_UNDO_REFUSED, "PENDING_TARGET_INVALID"); + check_prepare(6, false, CLUSTER_HEAP_PREPARED_UNDO_REFUSED, "PENDING_STAGE_REFUSED"); + check_prepare(7, true, CLUSTER_HEAP_PREPARED_UNDO_REFUSED, "POST_APPLY_PENDING_RECHECK"); + check_prepare(9, true, CLUSTER_HEAP_PREPARED_UNDO_REFUSED, "POST_APPLY_PENDING_MISMATCH"); +} + +UT_TEST(success_and_preapply_retries_remain_unchanged) +{ + check_prepare(0, false, CLUSTER_HEAP_PREPARED_UNDO_READY, NULL); + check_prepare(2, false, CLUSTER_HEAP_PREPARED_UNDO_RETRY_REQUIRED, NULL); + check_prepare(3, false, CLUSTER_HEAP_PREPARED_UNDO_RETRY_REQUIRED, NULL); + check_prepare(4, false, CLUSTER_HEAP_PREPARED_UNDO_RETRY_REQUIRED, NULL); + check_prepare(7, false, CLUSTER_HEAP_PREPARED_UNDO_RETRY_REQUIRED, NULL); + check_prepare(8, false, CLUSTER_HEAP_PREPARED_UNDO_RETRY_REQUIRED, NULL); + check_prepare(9, false, CLUSTER_HEAP_PREPARED_UNDO_RETRY_REQUIRED, NULL); +} + +int +main(void) +{ + UT_PLAN(4); + UT_RUN(refusals_have_unique_exact_causes); + UT_RUN(success_and_preapply_retries_remain_unchanged); + UT_RUN(full_lock_capacity_waits_then_requalifies_without_apply); + UT_RUN(unproved_or_failed_wait_is_not_a_retry_success); + UT_DONE(); + return ut_failed_count == 0 ? 0 : 1; +} diff --git a/src/test/cluster_unit/test_cluster_hw_cold.c b/src/test/cluster_unit/test_cluster_hw_cold.c index 873c113724c..8835c81429a 100644 --- a/src/test/cluster_unit/test_cluster_hw_cold.c +++ b/src/test/cluster_unit/test_cluster_hw_cold.c @@ -13,10 +13,16 @@ int allocation_stop_fixture_main(void); /* This suite qualifies HW in isolation. Its actual Startup tail must leave * the separately tested normal-TT producer untouched in EXISTING_OTHER. */ -ClusterNormalStartState cluster_semantic_normal_start_state(void) -{ return CLUSTER_NORMAL_START_EXISTING_OTHER; } -bool cluster_semantic_normal_start_finish(const char **failure) -{ abort(); } +ClusterNormalStartState +cluster_semantic_normal_start_state(void) +{ + return CLUSTER_NORMAL_START_EXISTING_OTHER; +} +bool +cluster_semantic_normal_start_finish(const char **failure) +{ + abort(); +} AuxProcType MyAuxProcType = StartupProcess; static char cold_root[] = "/tmp/pgrac-hw-cold-XXXXXX"; diff --git a/src/test/cluster_unit/test_cluster_hw_initdb.c b/src/test/cluster_unit/test_cluster_hw_initdb.c index 0ba4d7b655e..89edeef04bf 100644 --- a/src/test/cluster_unit/test_cluster_hw_initdb.c +++ b/src/test/cluster_unit/test_cluster_hw_initdb.c @@ -235,7 +235,8 @@ run_case(enum Fault injected, bool want_success, const char *reason) { char template[] = "/tmp/pgrac-hw-create-XXXXXX"; char *base = mkdtemp(template); - char *root, *data, *snapshot, *log; + char *root, *snapshot, *log; + const char *data; pid_t pid; int status, fd; char bytes[4096] = { 0 }; diff --git a/src/test/cluster_unit/test_cluster_hw_snapshot_io.c b/src/test/cluster_unit/test_cluster_hw_snapshot_io.c new file mode 100644 index 00000000000..6d7cf5143a0 --- /dev/null +++ b/src/test/cluster_unit/test_cluster_hw_snapshot_io.c @@ -0,0 +1,27 @@ +/*------------------------------------------------------------------------- + * + * test_cluster_hw_snapshot_io.c + * Compile the production reader with an exact read-fault injection seam. + * + * Portions Copyright (c) 2026, pgrac contributors + * Author: SqlRush + * + * IDENTIFICATION + * src/test/cluster_unit/test_cluster_hw_snapshot_io.c + * + *------------------------------------------------------------------------- + */ +#include "postgres.h" + +#include + +extern ssize_t hw_snapshot_test_read(int fd, void *buf, size_t count); + +/* + * Define the seam after libc declarations. A command-line -Dread also renames + * fortified libc declarations whose assembler alias still calls real read(), + * silently bypassing the injected EINTR, short-read and I/O-error witnesses. + */ +#define read hw_snapshot_test_read +#include "../../backend/cluster/cluster_hw_snapshot.c" +#undef read diff --git a/src/test/cluster_unit/test_cluster_ic.c b/src/test/cluster_unit/test_cluster_ic.c index 0e1c8f3ec75..cfcbfd43cb0 100644 --- a/src/test/cluster_unit/test_cluster_ic.c +++ b/src/test/cluster_unit/test_cluster_ic.c @@ -653,14 +653,10 @@ UT_TEST(test_hello_r4_capabilities_preserve_v1_reference) UT_ASSERT(cluster_ic_parse_hello(wire, &parsed)); capabilities = cluster_ic_hello_capabilities(&parsed); - UT_ASSERT_EQ(PGRAC_IC_HELLO_CAP_CANDIDATE2_CORRECTED_A1_V1, - (uint32)0x00100000U); - UT_ASSERT_EQ(PGRAC_IC_HELLO_CAP_UNDO_ROOT_DESCRIPTOR_V1, - (uint32)0x00200000U); - UT_ASSERT_EQ(PGRAC_IC_HELLO_CAP_GCS_RESOURCE_X_CONVERT_V1, - (uint32)0x00020000U); - UT_ASSERT_EQ(PGRAC_IC_HELLO_CAP_MULTIXACT_CTRC_V1, - UINT32_C(0x00400000)); + UT_ASSERT_EQ(PGRAC_IC_HELLO_CAP_CANDIDATE2_CORRECTED_A1_V1, (uint32)0x00100000U); + UT_ASSERT_EQ(PGRAC_IC_HELLO_CAP_UNDO_ROOT_DESCRIPTOR_V1, (uint32)0x00200000U); + UT_ASSERT_EQ(PGRAC_IC_HELLO_CAP_GCS_RESOURCE_X_CONVERT_V1, (uint32)0x00020000U); + UT_ASSERT_EQ(PGRAC_IC_HELLO_CAP_MULTIXACT_CTRC_V1, UINT32_C(0x00400000)); UT_ASSERT_EQ(capabilities & PGRAC_IC_HELLO_CAP_GCS_RESOURCE_X_CONVERT_V1, PGRAC_IC_HELLO_CAP_GCS_RESOURCE_X_CONVERT_V1); UT_ASSERT_EQ(capabilities & UINT32_C(0x007B3000), UINT32_C(0x007B3000)); @@ -684,19 +680,16 @@ UT_TEST(test_local_capability_word_is_hello_authority_with_ack_advertisement) cluster_ic_suppress_caps_reply = false; cluster_ic_suppress_gcs_done_cap = false; cluster_ic_suppress_xid_flock_cap = false; - cluster_ic_build_hello(wire, PGRAC_IC_HELLO_VERSION_V1, - PGRAC_IC_ENVELOPE_VERSION_V1, 0, "four-node-happy-path", - CLUSTER_IC_PLANE_CONTROL, 0); + cluster_ic_build_hello(wire, PGRAC_IC_HELLO_VERSION_V1, PGRAC_IC_ENVELOPE_VERSION_V1, 0, + "four-node-happy-path", CLUSTER_IC_PLANE_CONTROL, 0); UT_ASSERT(cluster_ic_parse_hello(wire, &parsed)); - UT_ASSERT_EQ(cluster_ic_local_capability_word(), - cluster_ic_hello_capabilities(&parsed)); + UT_ASSERT_EQ(cluster_ic_local_capability_word(), cluster_ic_hello_capabilities(&parsed)); /* RF-ROOT P9 verification (2026-08-19): the ACK-v1 bit IS advertised — * tier-1 peers must learn the semantic-activation ACK semantics from * the HELLO before the first ACK exchange. */ - UT_ASSERT_EQ(cluster_ic_local_capability_word() - & PGRAC_IC_HELLO_CAP_SEMANTIC_ACTIVATION_ACK_V1, - PGRAC_IC_HELLO_CAP_SEMANTIC_ACTIVATION_ACK_V1); + UT_ASSERT_EQ(cluster_ic_local_capability_word() & PGRAC_IC_HELLO_CAP_SEMANTIC_ACTIVATION_ACK_V1, + PGRAC_IC_HELLO_CAP_SEMANTIC_ACTIVATION_ACK_V1); } UT_TEST(test_current_mx_capability_is_advertised_without_reserved_bit_alias) @@ -709,14 +702,12 @@ UT_TEST(test_current_mx_capability_is_advertised_without_reserved_bit_alias) cluster_ic_suppress_caps_reply = false; cluster_ic_suppress_gcs_done_cap = false; cluster_ic_suppress_xid_flock_cap = false; - cluster_ic_build_hello(wire, PGRAC_IC_HELLO_VERSION_V1, - PGRAC_IC_ENVELOPE_VERSION_V1, 0, "current-mx", - CLUSTER_IC_PLANE_CONTROL, 0); + cluster_ic_build_hello(wire, PGRAC_IC_HELLO_VERSION_V1, PGRAC_IC_ENVELOPE_VERSION_V1, 0, + "current-mx", CLUSTER_IC_PLANE_CONTROL, 0); UT_ASSERT(cluster_ic_parse_hello(wire, &parsed)); capabilities = cluster_ic_hello_capabilities(&parsed); - UT_ASSERT_EQ(capabilities & UINT32_C(0x00010000), - UINT32_C(0x00010000)); + UT_ASSERT_EQ(capabilities & UINT32_C(0x00010000), UINT32_C(0x00010000)); UT_ASSERT_EQ(capabilities & PGRAC_IC_HELLO_CAP_MULTIXACT_CTRC_V1, PGRAC_IC_HELLO_CAP_MULTIXACT_CTRC_V1); UT_ASSERT_EQ(capabilities & UINT32_C(0x00004000), 0); @@ -823,14 +814,10 @@ UT_TEST(test_hello_smart_fusion_capability_gate) | PGRAC_IC_HELLO_CAP_GCS_INVAL_BUSY_V1 | PGRAC_IC_HELLO_CAP_UNDO_HORIZON_IDLE_V1 | PGRAC_IC_HELLO_CAP_PCM_X_CONVERT_V1 | PGRAC_IC_HELLO_CAP_PCM_X_REBASE_V1 | PGRAC_IC_HELLO_CAP_PCM_X_SOURCE_FLOOR_V1 | PGRAC_IC_HELLO_CAP_SEMANTIC_ACTIVATION_V1 - | PGRAC_IC_HELLO_CAP_SEMANTIC_ACTIVATION_ACK_V1 - | PGRAC_IC_HELLO_CAP_R4_SYNC_CR_V1 - | PGRAC_IC_HELLO_CAP_GCS_RESOURCE_X_CONVERT_V1 - | UINT32_C(0x00010000) - | PGRAC_IC_HELLO_CAP_CONTROL_ROOT_V1 - | PGRAC_IC_HELLO_CAP_CANDIDATE2_CORRECTED_A1_V1 - | PGRAC_IC_HELLO_CAP_UNDO_ROOT_DESCRIPTOR_V1 - | PGRAC_IC_HELLO_CAP_MULTIXACT_CTRC_V1); + | PGRAC_IC_HELLO_CAP_SEMANTIC_ACTIVATION_ACK_V1 | PGRAC_IC_HELLO_CAP_R4_SYNC_CR_V1 + | PGRAC_IC_HELLO_CAP_GCS_RESOURCE_X_CONVERT_V1 | UINT32_C(0x00010000) + | PGRAC_IC_HELLO_CAP_CONTROL_ROOT_V1 | PGRAC_IC_HELLO_CAP_CANDIDATE2_CORRECTED_A1_V1 + | PGRAC_IC_HELLO_CAP_UNDO_ROOT_DESCRIPTOR_V1 | PGRAC_IC_HELLO_CAP_MULTIXACT_CTRC_V1); /* Keep the aggregate word byte-exact as well as symbolically composed: * parallel protocol lanes have collided while preserving the same symbolic * expectation, so the literal catches accidental bit reuse. */ @@ -850,14 +837,10 @@ UT_TEST(test_hello_smart_fusion_capability_gate) | PGRAC_IC_HELLO_CAP_GCS_INVAL_BUSY_V1 | PGRAC_IC_HELLO_CAP_UNDO_HORIZON_IDLE_V1 | PGRAC_IC_HELLO_CAP_PCM_X_CONVERT_V1 | PGRAC_IC_HELLO_CAP_PCM_X_REBASE_V1 | PGRAC_IC_HELLO_CAP_PCM_X_SOURCE_FLOOR_V1 | PGRAC_IC_HELLO_CAP_SEMANTIC_ACTIVATION_V1 - | PGRAC_IC_HELLO_CAP_SEMANTIC_ACTIVATION_ACK_V1 - | PGRAC_IC_HELLO_CAP_R4_SYNC_CR_V1 - | PGRAC_IC_HELLO_CAP_GCS_RESOURCE_X_CONVERT_V1 - | UINT32_C(0x00010000) - | PGRAC_IC_HELLO_CAP_CONTROL_ROOT_V1 - | PGRAC_IC_HELLO_CAP_CANDIDATE2_CORRECTED_A1_V1 - | PGRAC_IC_HELLO_CAP_UNDO_ROOT_DESCRIPTOR_V1 - | PGRAC_IC_HELLO_CAP_MULTIXACT_CTRC_V1); + | PGRAC_IC_HELLO_CAP_SEMANTIC_ACTIVATION_ACK_V1 | PGRAC_IC_HELLO_CAP_R4_SYNC_CR_V1 + | PGRAC_IC_HELLO_CAP_GCS_RESOURCE_X_CONVERT_V1 | UINT32_C(0x00010000) + | PGRAC_IC_HELLO_CAP_CONTROL_ROOT_V1 | PGRAC_IC_HELLO_CAP_CANDIDATE2_CORRECTED_A1_V1 + | PGRAC_IC_HELLO_CAP_UNDO_ROOT_DESCRIPTOR_V1 | PGRAC_IC_HELLO_CAP_MULTIXACT_CTRC_V1); cluster_smart_fusion = true; cluster_interconnect_tier = CLUSTER_IC_TIER_3; @@ -875,12 +858,9 @@ UT_TEST(test_hello_smart_fusion_capability_gate) | PGRAC_IC_HELLO_CAP_PCM_X_REBASE_V1 | PGRAC_IC_HELLO_CAP_PCM_X_SOURCE_FLOOR_V1 | PGRAC_IC_HELLO_CAP_SEMANTIC_ACTIVATION_V1 | PGRAC_IC_HELLO_CAP_SEMANTIC_ACTIVATION_ACK_V1 | PGRAC_IC_HELLO_CAP_R4_SYNC_CR_V1 - | PGRAC_IC_HELLO_CAP_GCS_RESOURCE_X_CONVERT_V1 - | UINT32_C(0x00010000) - | PGRAC_IC_HELLO_CAP_CONTROL_ROOT_V1 - | PGRAC_IC_HELLO_CAP_CANDIDATE2_CORRECTED_A1_V1 - | PGRAC_IC_HELLO_CAP_UNDO_ROOT_DESCRIPTOR_V1 - | PGRAC_IC_HELLO_CAP_MULTIXACT_CTRC_V1); + | PGRAC_IC_HELLO_CAP_GCS_RESOURCE_X_CONVERT_V1 | UINT32_C(0x00010000) + | PGRAC_IC_HELLO_CAP_CONTROL_ROOT_V1 | PGRAC_IC_HELLO_CAP_CANDIDATE2_CORRECTED_A1_V1 + | PGRAC_IC_HELLO_CAP_UNDO_ROOT_DESCRIPTOR_V1 | PGRAC_IC_HELLO_CAP_MULTIXACT_CTRC_V1); cluster_smart_fusion = false; cluster_interconnect_tier = CLUSTER_IC_TIER_STUB; diff --git a/src/test/cluster_unit/test_cluster_ic_envelope.c b/src/test/cluster_unit/test_cluster_ic_envelope.c index d9480cd47b1..6bcf1629a46 100644 --- a/src/test/cluster_unit/test_cluster_ic_envelope.c +++ b/src/test/cluster_unit/test_cluster_ic_envelope.c @@ -170,13 +170,15 @@ cluster_ic_tier1_bump_epoch_observe_advance(int32 peer_id pg_attribute_unused()) /* * ereport family stubs. envelope_verify step-7 epoch enforce uses * ereport(LOG, ...) on reject -- we want it to NOT abort but also - * not require a real backend. Minimal stub:errstart returns true - * (so errmsg etc. run);errfinish is a no-op. + * not require a real backend. Suppress DEBUG output, including the platform + * CRC dispatch diagnostic. Unexpected ERRORs still abort the fixture. */ bool -errstart(int elevel pg_attribute_unused(), const char *domain pg_attribute_unused()) +errstart(int elevel, const char *domain pg_attribute_unused()) { - return true; + if (elevel >= ERROR) + abort(); + return elevel >= LOG; } void errfinish(const char *filename pg_attribute_unused(), int lineno pg_attribute_unused(), diff --git a/src/test/cluster_unit/test_cluster_ic_tier1_partial.c b/src/test/cluster_unit/test_cluster_ic_tier1_partial.c index f2337b6b65a..b3e5a1d5401 100644 --- a/src/test/cluster_unit/test_cluster_ic_tier1_partial.c +++ b/src/test/cluster_unit/test_cluster_ic_tier1_partial.c @@ -7,6 +7,9 @@ * * Links cluster_ic_tier1.o standalone and drives the PRODUCTION * send/drain paths over a real localhost TCP pair: + * After real socket saturation, a test-only send boundary holds + * EAGAIN for that fd until explicit drain/close. Kernel ACK progress + * cannot silently remove the precondition. Resumed bytes use real TCP. * * T-1 connect_one registers the peer fd (production registration * path — no test seam into tier1_peer_fds). @@ -71,8 +74,12 @@ #include "utils/wait_event.h" #include "cluster/cluster_clean_leave.h" /* Include the unchanged production translation unit so malformed private - * owner shapes can be checked without adding a runtime mutation API. */ + * owner shapes can be checked without adding a runtime mutation API. + * Interpose only the syscall after libc declarations, not product logic. */ +static ssize_t ut_backpressured_send(int fd, const void *buf, size_t len, int flags); +#define send ut_backpressured_send #include "../../backend/cluster/cluster_ic_tier1.c" +#undef send /* Drop PG's port.h printf -> pg_printf override; unit_test.h uses * stdlib printf and we don't rely on pg_printf in this binary. */ @@ -82,6 +89,29 @@ UT_DEFINE_GLOBALS(); +static int ut_backpressure_fd = -1; +static unsigned int ut_backpressure_calls = 0; + +static ssize_t +ut_backpressured_send(int fd, const void *buf, size_t len, int flags) +{ + if (fd == ut_backpressure_fd) { + ut_backpressure_calls++; + errno = EAGAIN; + return -1; + } + return send(fd, buf, len, flags); +} + +static void +ut_release_backpressure(int fd) +{ + if (fd == ut_backpressure_fd) { + UT_ASSERT(ut_backpressure_calls > 0); + ut_backpressure_fd = -1; + } +} + /* ============================================================ * PG-runtime stubs. * ============================================================ */ @@ -409,20 +439,24 @@ ut_open_listener(int *out_port) return fd; } -/* Fill the peer's send path with junk until EAGAIN (both socket buffers - * full). Returns the number of junk bytes written. */ +/* Observe real EAGAIN, then hold that syscall result for the exact fd until + * the test starts draining or finishes closing it. EAGAIN by itself is not + * a promise about later writes or smaller frames. Returns real junk bytes. */ static long ut_fill_until_eagain(int fd) { char junk[4096]; long total = 0; + UT_ASSERT_EQ(ut_backpressure_fd, -1); memset(junk, 'J', sizeof(junk)); for (;;) { ssize_t n = send(fd, junk, sizeof(junk), 0); if (n < 0) { UT_ASSERT(errno == EAGAIN || errno == EWOULDBLOCK); + ut_backpressure_fd = fd; + ut_backpressure_calls = 0; break; } total += (long)n; @@ -431,6 +465,22 @@ ut_fill_until_eagain(int fd) return total; } +/* Real ACK/window progress without running the product's queued-tail drain. + * The test's held EAGAIN must survive even when the kernel becomes writable. */ +static void +ut_allow_socket_progress(int tx_fd, int rx_fd) +{ + char junk[65536]; + fd_set wfds; + struct timeval tv = { 5, 0 }; + + while (recv(rx_fd, junk, sizeof(junk), MSG_DONTWAIT) > 0) + ; + FD_ZERO(&wfds); + FD_SET(tx_fd, &wfds); + UT_ASSERT_EQ(select(tx_fd + 1, NULL, &wfds, NULL, &tv), 1); +} + /* Pump the production drain entry until DONE, receiving concurrently so * the kernel buffers empty. Collects the stream into acc and returns once * `expected` bytes arrived AND nothing is pending — a fixed byte target, @@ -442,6 +492,7 @@ ut_drain_and_collect(int rx_fd, char *acc, long acc_cap, long expected) long collected = 0; int idle_spins = 0; + ut_release_backpressure(cluster_ic_tier1_get_peer_fd(UT_PEER_ID)); UT_ASSERT(expected <= acc_cap); for (;;) { ssize_t n = recv(rx_fd, acc + collected, (size_t)(acc_cap - collected), MSG_DONTWAIT); @@ -480,6 +531,7 @@ ut_drain_all_and_sweep(int32 peer_id, int rx_fd, char *acc, long acc_cap) long collected = 0; int idle_spins = 0; + ut_release_backpressure(cluster_ic_tier1_get_peer_fd(peer_id)); for (;;) { ssize_t n = recv(rx_fd, acc + collected, (size_t)(acc_cap - collected), MSG_DONTWAIT); @@ -650,6 +702,9 @@ UT_TEST(test_close_peer_resets_queued_tail) memset(frame_c, 'C', sizeof(frame_c)); (void)ut_fill_until_eagain(ut_tx_fd); + /* Model socket room reopening between the fill probe and the smaller + * frame. A previous EAGAIN does not reserve backpressure for this send. */ + ut_allow_socket_progress(ut_tx_fd, ut_rx_fd); rc = ClusterICOps_Tier1.send_bytes(UT_PEER_ID, frame_c, sizeof(frame_c)); UT_ASSERT(rc == CLUSTER_IC_SEND_WOULD_BLOCK); UT_ASSERT(cluster_ic_tier1_pending_outbound(UT_PEER_ID)); @@ -658,6 +713,7 @@ UT_TEST(test_close_peer_resets_queued_tail) * so a reconnect can never start its stream with mid-frame bytes. */ cluster_ic_tier1_close_peer(UT_PEER_ID, "test close"); UT_ASSERT(!cluster_ic_tier1_pending_outbound(UT_PEER_ID)); + ut_release_backpressure(ut_tx_fd); } UT_TEST(test_drain_on_dead_peer_hard_errors) @@ -729,15 +785,14 @@ UT_TEST(test_recv_drain_yields_after_bounded_frames) int i; memset(frames, 0, sizeof(frames)); - for (i = 0; i < lengthof(frames); i++) - { + for (i = 0; i < lengthof(frames); i++) { frames[i].msg_type = PGRAC_IC_MSG_HEARTBEAT; frames[i].source_node_id = UT_PEER_ID; frames[i].dest_node_id = cluster_node_id; } sent = send(ut_rx_fd, frames, sizeof(frames), 0); - UT_ASSERT_EQ(sent, (ssize_t) sizeof(frames)); + UT_ASSERT_EQ(sent, (ssize_t)sizeof(frames)); { fd_set rfds; struct timeval tv; @@ -782,6 +837,10 @@ UT_TEST(test_second_frame_survives_backpressure) UT_ASSERT(rc == CLUSTER_IC_SEND_WOULD_BLOCK); UT_ASSERT(cluster_ic_tier1_pending_outbound(UT_PEER_ID)); + /* Let the kernel make room without calling the product drain. This + * reproduces the ACK/window progress that can happen before frame E. */ + ut_allow_socket_progress(ut_tx_fd, ut_rx_fd); + /* Frame E while D is pending: must be admitted (WOULD_BLOCK = the * transport owns a copy) — never silently dropped. */ rc = ClusterICOps_Tier1.send_bytes(UT_PEER_ID, frame_e, sizeof(frame_e)); @@ -1011,6 +1070,7 @@ UT_TEST(test_close_peer_clears_fifo) cluster_ic_tier1_close_peer(UT_PEER_ID, "test close (fifo)"); UT_ASSERT(!cluster_ic_tier1_pending_outbound(UT_PEER_ID)); + ut_release_backpressure(ut_tx_fd); UT_ASSERT_EQ( (long)(cluster_ic_tier1_get_fifo_dropped_close(CLUSTER_IC_PLANE_CONTROL) - dropped0), 2L); } diff --git a/src/test/cluster_unit/test_cluster_inject.c b/src/test/cluster_unit/test_cluster_inject.c index b1606c0999e..25517554991 100644 --- a/src/test/cluster_unit/test_cluster_inject.c +++ b/src/test/cluster_unit/test_cluster_inject.c @@ -79,9 +79,8 @@ char *cluster_injection_points = NULL; /* extern from cluster_guc.h */ bool -cluster_ctrc_test_barrier_control( - ClusterCtrcTestBarrierPhase phase pg_attribute_unused(), - bool armed pg_attribute_unused()) +cluster_ctrc_test_barrier_control(ClusterCtrcTestBarrierPhase phase pg_attribute_unused(), + bool armed pg_attribute_unused()) { return true; } diff --git a/src/test/cluster_unit/test_cluster_lmd.c b/src/test/cluster_unit/test_cluster_lmd.c index e07b3a4d50b..f9983274c87 100644 --- a/src/test/cluster_unit/test_cluster_lmd.c +++ b/src/test/cluster_unit/test_cluster_lmd.c @@ -1207,8 +1207,10 @@ UT_TEST(test_lmd_actual_probe_wait_suspends_active_but_never_signs_idle) pg_atomic_write_u32(&cl_normal_stop->requested, 1); pg_atomic_write_u32(&cl_normal_stop->identity_published, 1); pg_atomic_write_u32(&cl_normal_stop->frontends_gone, 1); - pg_atomic_write_u32(&cl_normal_stop->phase, CLUSTER_NORMAL_STOP_QUIESCE); + pg_atomic_write_u32(&cl_normal_stop->phase, CLUSTER_NORMAL_STOP_WAIT_DRAIN_ACK); cl_normal_stop->peer_requests_seen = 15; + cl_state->ack_bitmap[0] = UINT32_C(15) & ~(UINT32_C(1) << cluster_node_id); + cl_normal_stop->peer_reply_sent = cl_state->ack_bitmap[0]; pg_atomic_write_u32(&cl_normal_stop->cleaner_quiesce_requested, 1); pg_atomic_write_u32(&cl_normal_stop->cleaner_quiesced_mask, 255); pg_atomic_write_u32(&cl_normal_stop->service_idle_mask, 2047); diff --git a/src/test/cluster_unit/test_cluster_lmon.c b/src/test/cluster_unit/test_cluster_lmon.c index b3cc3916ea6..ec2428fa6f8 100644 --- a/src/test/cluster_unit/test_cluster_lmon.c +++ b/src/test/cluster_unit/test_cluster_lmon.c @@ -1557,7 +1557,9 @@ test_stop_wait(WaitEvent *events) return 0; /* original reply/handoff publication, not the observer */ } if (test_stop_case == 9) { - pg_atomic_write_u32(&cl_normal_stop->phase, CLUSTER_NORMAL_STOP_QUIESCE); + pg_atomic_write_u32(&cl_normal_stop->phase, CLUSTER_NORMAL_STOP_WAIT_DRAIN_ACK); + cl_state->ack_bitmap[0] = UINT32_C(15) & ~(UINT32_C(1) << cluster_node_id); + cl_normal_stop->peer_reply_sent = cl_state->ack_bitmap[0]; /* Other actual actors are an explicit controller boundary here. */ pg_atomic_write_u32(&cl_normal_stop->service_idle_mask, pg_atomic_read_u32(&cl_normal_stop->service_idle_mask) | 1538); @@ -1587,6 +1589,9 @@ test_stop_wait(WaitEvent *events) static void test_run_normal_stop_lmon(bool transport, int scenario) { + int saved_node_id = cluster_node_id; + + cluster_node_id = 0; if (!test_lmon_shmem_found) cluster_lmon_shmem_init(); memset(&test_stop_region, 0, sizeof(test_stop_region)); @@ -1669,6 +1674,7 @@ test_run_normal_stop_lmon(bool transport, int scenario) UT_ASSERT_EQ(test_stop_lock_depth, 0); UT_ASSERT_EQ(cl_normal_stop_service_depth, 0); IsUnderPostmaster = false; + cluster_node_id = saved_node_id; } UT_TEST(test_stop_real_lmon_both_modes_work_wait_exit) diff --git a/src/test/cluster_unit/test_cluster_lms_native_probe.c b/src/test/cluster_unit/test_cluster_lms_native_probe.c index b94aad85bce..d5bc8c39a3b 100644 --- a/src/test/cluster_unit/test_cluster_lms_native_probe.c +++ b/src/test/cluster_unit/test_cluster_lms_native_probe.c @@ -254,6 +254,8 @@ cluster_grd_outbound_enqueue_lms_native_probe(uint32 dest, const void *data, uin peak_active = Max(peak_active, active); } UT_ASSERT(sends < lengthof(wire_ids)); + if (sends >= lengthof(wire_ids)) + abort(); wire_ids[sends++] = p->probe_id; } void diff --git a/src/test/cluster_unit/test_cluster_lms_outbound.c b/src/test/cluster_unit/test_cluster_lms_outbound.c index 0f01f1ae248..60a3f41d7fb 100644 --- a/src/test/cluster_unit/test_cluster_lms_outbound.c +++ b/src/test/cluster_unit/test_cluster_lms_outbound.c @@ -92,24 +92,20 @@ errdetail(const char *fmt pg_attribute_unused(), ...) /* Desired R10 C-intent boundary. The standalone ring test supplies the * semantic-owner callbacks below and exercises the real ring/drain object. */ -extern bool cluster_lms_outbound_enqueue_resource_x_intent( - int worker_id, const ResourceXIntentSlot *intent, - uint32 connection_generation, uint64 deadline_us); +extern bool cluster_lms_outbound_enqueue_resource_x_intent(int worker_id, + const ResourceXIntentSlot *intent, + uint32 connection_generation, + uint64 deadline_us); extern int cluster_lms_outbound_resource_x_intent_pump(void); -extern ClusterPcmOwnResult -cluster_lms_outbound_stage_resource_x_remote_s_status_exact( - int worker_id, uint32 dest_node_id, const void *payload, - uint16 payload_len, const ClusterPcmOwnSnapshot *expected_revoking, - ClusterLmsRemoteSStatusHandle *handle_out); -extern ClusterPcmOwnResult -cluster_lms_outbound_publish_resource_x_remote_s_status_exact( - const ClusterLmsRemoteSStatusHandle *handle, - const ClusterPcmOwnSnapshot *released_n); -extern ClusterPcmOwnResult -cluster_lms_outbound_cancel_resource_x_remote_s_status_exact( +extern ClusterPcmOwnResult cluster_lms_outbound_stage_resource_x_remote_s_status_exact( + int worker_id, uint32 dest_node_id, const void *payload, uint16 payload_len, + const ClusterPcmOwnSnapshot *expected_revoking, ClusterLmsRemoteSStatusHandle *handle_out); +extern ClusterPcmOwnResult cluster_lms_outbound_publish_resource_x_remote_s_status_exact( + const ClusterLmsRemoteSStatusHandle *handle, const ClusterPcmOwnSnapshot *released_n); +extern ClusterPcmOwnResult cluster_lms_outbound_cancel_resource_x_remote_s_status_exact( const ClusterLmsRemoteSStatusHandle *handle); -extern bool cluster_lms_outbound_resource_x_transport_snapshot( - ClusterLmsResourceXTransportSnapshot *out); +extern bool +cluster_lms_outbound_resource_x_transport_snapshot(ClusterLmsResourceXTransportSnapshot *out); /* ============================================================ * PG-runtime stubs. @@ -127,8 +123,7 @@ static uint8 ut_resource_x_owner_payload[RESOURCE_X_IMAGE_V1_BYTES]; static int ut_resource_x_stage_count = 0; static int ut_resource_x_rearm_count = 0; static int ut_resource_x_complete_count = 0; -static ResourceXIntentProbeResult ut_resource_x_probe_mode - = RESOURCE_X_INTENT_PROBE_IDLE; +static ResourceXIntentProbeResult ut_resource_x_probe_mode = RESOURCE_X_INTENT_PROBE_IDLE; static int ut_resource_x_probe_call_count = 0; static int ut_resource_x_delivery_tick_count = 0; static int ut_resource_x_source_finish_tick_count = 0; @@ -150,9 +145,8 @@ cluster_pcm_lock_resource_x_trace_wire(uint8 type, int32 peer, const void *paylo } bool -cluster_resource_x_wire_decode( - uint8 msg_type, const void *payload, uint16 payload_len, - ResourceXDecodedFrame *out, ResourceXWireReject *reject) +cluster_resource_x_wire_decode(uint8 msg_type, const void *payload, uint16 payload_len, + ResourceXDecodedFrame *out, ResourceXWireReject *reject) { if (msg_type != RESOURCE_X_MSG_IMAGE_OR_GRANT || payload == NULL || payload_len != RESOURCE_X_IMAGE_V1_BYTES || out == NULL @@ -160,8 +154,7 @@ cluster_resource_x_wire_decode( return false; memset(out, 0, sizeof(*out)); out->kind = RESOURCE_X_WIRE_IMAGE_ENVELOPE; - out->common.sender_connection_generation - = ut_resource_x_decode_sender_generation; + out->common.sender_connection_generation = ut_resource_x_decode_sender_generation; ut_resource_x_decode_count++; if (reject != NULL) *reject = RESOURCE_X_WIRE_REJECT_NONE; @@ -169,9 +162,10 @@ cluster_resource_x_wire_decode( } bool -cluster_resource_x_wire_rebind_sender_generation( - uint8 msg_type pg_attribute_unused(), void *payload, uint16 payload_len, - uint32 sender_connection_generation, ResourceXWireReject *reject) +cluster_resource_x_wire_rebind_sender_generation(uint8 msg_type pg_attribute_unused(), + void *payload, uint16 payload_len, + uint32 sender_connection_generation, + ResourceXWireReject *reject) { if (payload == NULL || payload_len < RESOURCE_X_CONTROL_V1_BYTES || sender_connection_generation == 0) @@ -187,41 +181,35 @@ static bool ut_resource_x_intent_identity_equal(const ResourceXIntentSlot *left, const ResourceXIntentSlot *right) { - return left != NULL && right != NULL - && left->logical_generation == right->logical_generation - && left->authority_generation == right->authority_generation - && left->first_armed_us == right->first_armed_us - && left->destination_node == right->destination_node - && left->payload_bytes == right->payload_bytes - && left->kind == right->kind - && memcmp(&left->body, &right->body, sizeof(left->body)) == 0; + return left != NULL && right != NULL && left->logical_generation == right->logical_generation + && left->authority_generation == right->authority_generation + && left->first_armed_us == right->first_armed_us + && left->destination_node == right->destination_node + && left->payload_bytes == right->payload_bytes && left->kind == right->kind + && memcmp(&left->body, &right->body, sizeof(left->body)) == 0; } ResourceXApplyResult -cluster_pcm_lock_resource_x_grant_intent_snapshot_exact( - const ResourceXAssertion *assertion, ResourceXIntentSlot *slot_out, - void *payload_out, uint16 payload_capacity) +cluster_pcm_lock_resource_x_grant_intent_snapshot_exact(const ResourceXAssertion *assertion, + ResourceXIntentSlot *slot_out, + void *payload_out, uint16 payload_capacity) { if (assertion == NULL || slot_out == NULL || payload_out == NULL || payload_capacity < ut_resource_x_owner_slot.payload_bytes || ut_resource_x_owner_slot.state == RESOURCE_X_INTENT_SLOT_EMPTY) return RESOURCE_X_APPLY_NOT_FOUND; - if (memcmp(assertion, &ut_resource_x_owner_slot.body.assertion, - sizeof(*assertion)) != 0) + if (memcmp(assertion, &ut_resource_x_owner_slot.body.assertion, sizeof(*assertion)) != 0) return RESOURCE_X_APPLY_STALE; *slot_out = ut_resource_x_owner_slot; - memcpy(payload_out, ut_resource_x_owner_payload, - ut_resource_x_owner_slot.payload_bytes); + memcpy(payload_out, ut_resource_x_owner_payload, ut_resource_x_owner_slot.payload_bytes); return RESOURCE_X_APPLY_APPLIED; } ResourceXIntentResult -cluster_pcm_lock_resource_x_grant_intent_stage_exact( - const ResourceXIntentSlot *expected, uint64 now_us) +cluster_pcm_lock_resource_x_grant_intent_stage_exact(const ResourceXIntentSlot *expected, + uint64 now_us) { - if (now_us == 0 - || !ut_resource_x_intent_identity_equal( - expected, &ut_resource_x_owner_slot) + if (now_us == 0 || !ut_resource_x_intent_identity_equal(expected, &ut_resource_x_owner_slot) || ut_resource_x_owner_slot.state != RESOURCE_X_INTENT_SLOT_ARMED) return RESOURCE_X_INTENT_STALE; ut_resource_x_owner_slot.state = RESOURCE_X_INTENT_SLOT_STAGED; @@ -231,12 +219,10 @@ cluster_pcm_lock_resource_x_grant_intent_stage_exact( } ResourceXIntentResult -cluster_pcm_lock_resource_x_grant_intent_not_admitted_exact( - const ResourceXIntentSlot *expected, uint64 now_us) +cluster_pcm_lock_resource_x_grant_intent_not_admitted_exact(const ResourceXIntentSlot *expected, + uint64 now_us) { - if (now_us == 0 - || !ut_resource_x_intent_identity_equal( - expected, &ut_resource_x_owner_slot) + if (now_us == 0 || !ut_resource_x_intent_identity_equal(expected, &ut_resource_x_owner_slot) || ut_resource_x_owner_slot.state != RESOURCE_X_INTENT_SLOT_ARMED) return RESOURCE_X_INTENT_STALE; ut_resource_x_owner_slot.last_attempt_us = now_us; @@ -244,12 +230,10 @@ cluster_pcm_lock_resource_x_grant_intent_not_admitted_exact( } ResourceXIntentResult -cluster_pcm_lock_resource_x_grant_intent_hard_rearm_exact( - const ResourceXIntentSlot *expected, uint64 now_us) +cluster_pcm_lock_resource_x_grant_intent_hard_rearm_exact(const ResourceXIntentSlot *expected, + uint64 now_us) { - if (now_us == 0 - || !ut_resource_x_intent_identity_equal( - expected, &ut_resource_x_owner_slot) + if (now_us == 0 || !ut_resource_x_intent_identity_equal(expected, &ut_resource_x_owner_slot) || ut_resource_x_owner_slot.state != RESOURCE_X_INTENT_SLOT_STAGED) return RESOURCE_X_INTENT_STALE; ut_resource_x_owner_slot.state = RESOURCE_X_INTENT_SLOT_ARMED; @@ -259,23 +243,21 @@ cluster_pcm_lock_resource_x_grant_intent_hard_rearm_exact( } bool -cluster_pcm_lock_resource_x_grant_intent_complete_exact( - const ResourceXIntentSlot *expected) +cluster_pcm_lock_resource_x_grant_intent_complete_exact(const ResourceXIntentSlot *expected) { - if (!ut_resource_x_intent_identity_equal( - expected, &ut_resource_x_owner_slot) + if (!ut_resource_x_intent_identity_equal(expected, &ut_resource_x_owner_slot) || ut_resource_x_owner_slot.state != RESOURCE_X_INTENT_SLOT_STAGED) return false; - memset(&ut_resource_x_owner_slot, 0, - sizeof(ut_resource_x_owner_slot)); + memset(&ut_resource_x_owner_slot, 0, sizeof(ut_resource_x_owner_slot)); ut_resource_x_complete_count++; return true; } ResourceXIntentProbeResult -cluster_pcm_lock_resource_x_outbound_intent_probe_exact( - uint32 probe_budget, ResourceXIntentSlot *slot_out, void *payload_out, - uint16 payload_capacity, uint32 *examined_out) +cluster_pcm_lock_resource_x_outbound_intent_probe_exact(uint32 probe_budget, + ResourceXIntentSlot *slot_out, + void *payload_out, uint16 payload_capacity, + uint32 *examined_out) { ut_resource_x_probe_call_count++; if (probe_budget > ut_resource_x_probe_max_budget) @@ -289,8 +271,7 @@ cluster_pcm_lock_resource_x_outbound_intent_probe_exact( return RESOURCE_X_INTENT_PROBE_CORRUPT; if (ut_resource_x_probe_mode == RESOURCE_X_INTENT_PROBE_FOUND) { *slot_out = ut_resource_x_owner_slot; - memcpy(payload_out, ut_resource_x_owner_payload, - ut_resource_x_owner_slot.payload_bytes); + memcpy(payload_out, ut_resource_x_owner_payload, ut_resource_x_owner_slot.payload_bytes); *examined_out = 1; ut_resource_x_probe_mode = RESOURCE_X_INTENT_PROBE_COMPLETE; return RESOURCE_X_INTENT_PROBE_FOUND; @@ -338,45 +319,41 @@ cluster_gcs_block_resource_x_source_finish_tick(const ResourceXAcquisitionRef *r } ResourceXApplyResult -cluster_pcm_lock_resource_x_outbound_intent_snapshot_exact( - const ResourceXIntentSlot *expected, ResourceXIntentSlot *slot_out, - void *payload_out, uint16 payload_capacity) +cluster_pcm_lock_resource_x_outbound_intent_snapshot_exact(const ResourceXIntentSlot *expected, + ResourceXIntentSlot *slot_out, + void *payload_out, + uint16 payload_capacity) { if (expected == NULL - || !ut_resource_x_intent_identity_equal( - expected, &ut_resource_x_owner_slot)) + || !ut_resource_x_intent_identity_equal(expected, &ut_resource_x_owner_slot)) return RESOURCE_X_APPLY_STALE; return cluster_pcm_lock_resource_x_grant_intent_snapshot_exact( &expected->body.assertion, slot_out, payload_out, payload_capacity); } ResourceXIntentResult -cluster_pcm_lock_resource_x_outbound_intent_stage_exact( - const ResourceXIntentSlot *expected, uint64 now_us) +cluster_pcm_lock_resource_x_outbound_intent_stage_exact(const ResourceXIntentSlot *expected, + uint64 now_us) { - return cluster_pcm_lock_resource_x_grant_intent_stage_exact( - expected, now_us); + return cluster_pcm_lock_resource_x_grant_intent_stage_exact(expected, now_us); } ResourceXIntentResult -cluster_pcm_lock_resource_x_outbound_intent_not_admitted_exact( - const ResourceXIntentSlot *expected, uint64 now_us) +cluster_pcm_lock_resource_x_outbound_intent_not_admitted_exact(const ResourceXIntentSlot *expected, + uint64 now_us) { - return cluster_pcm_lock_resource_x_grant_intent_not_admitted_exact( - expected, now_us); + return cluster_pcm_lock_resource_x_grant_intent_not_admitted_exact(expected, now_us); } ResourceXIntentResult -cluster_pcm_lock_resource_x_outbound_intent_hard_rearm_exact( - const ResourceXIntentSlot *expected, uint64 now_us) +cluster_pcm_lock_resource_x_outbound_intent_hard_rearm_exact(const ResourceXIntentSlot *expected, + uint64 now_us) { - return cluster_pcm_lock_resource_x_grant_intent_hard_rearm_exact( - expected, now_us); + return cluster_pcm_lock_resource_x_grant_intent_hard_rearm_exact(expected, now_us); } bool -cluster_pcm_lock_resource_x_outbound_intent_complete_exact( - const ResourceXIntentSlot *expected) +cluster_pcm_lock_resource_x_outbound_intent_complete_exact(const ResourceXIntentSlot *expected) { return cluster_pcm_lock_resource_x_grant_intent_complete_exact(expected); } @@ -392,18 +369,15 @@ cluster_sf_peer_capability_generation_matches(int32 peer_id, uint32 required_cap } bool -cluster_sf_peer_capability_word_sample(int32 peer_id, - uint32 required_capabilities, uint32 *capability_word_out, - uint32 *generation_out) +cluster_sf_peer_capability_word_sample(int32 peer_id, uint32 required_capabilities, + uint32 *capability_word_out, uint32 *generation_out) { if (capability_word_out != NULL) *capability_word_out = 0; if (generation_out != NULL) *generation_out = 0; - if (peer_id < 0 || peer_id >= CLUSTER_MAX_NODES - || required_capabilities == 0 - || (ut_peer_capabilities[peer_id] & required_capabilities) - != required_capabilities) + if (peer_id < 0 || peer_id >= CLUSTER_MAX_NODES || required_capabilities == 0 + || (ut_peer_capabilities[peer_id] & required_capabilities) != required_capabilities) return false; if (capability_word_out != NULL) *capability_word_out = ut_peer_capabilities[peer_id]; @@ -616,7 +590,8 @@ cluster_ic_send_envelope(uint8 msg_type, int32 dest_node_id, const void *payload ut_sent_log[ut_sent_n].dest = dest_node_id; ut_sent_log[ut_sent_n].marker = payload_len > 0 ? *(const uint8 *)payload : 0; ut_sent_log[ut_sent_n].payload_len = payload_len; - if (msg_type == PGRAC_IC_MSG_GCS_BLOCK_REPLY && payload_len >= sizeof(GcsBlockReplyHeader)) { + if (msg_type == PGRAC_IC_MSG_GCS_BLOCK_REPLY + && payload_len >= sizeof(GcsBlockReplyHeader)) { const uint8 *block_data = ((const uint8 *)payload) + sizeof(GcsBlockReplyHeader); uint32 i; @@ -674,10 +649,8 @@ ut_reset_log(void) memset(ut_peer_capabilities, 0, sizeof(ut_peer_capabilities)); memset(ut_peer_cap_generation, 0, sizeof(ut_peer_cap_generation)); memset(ut_sent_log, 0, sizeof(ut_sent_log)); - memset(&ut_resource_x_owner_slot, 0, - sizeof(ut_resource_x_owner_slot)); - memset(ut_resource_x_owner_payload, 0, - sizeof(ut_resource_x_owner_payload)); + memset(&ut_resource_x_owner_slot, 0, sizeof(ut_resource_x_owner_slot)); + memset(ut_resource_x_owner_payload, 0, sizeof(ut_resource_x_owner_payload)); ut_resource_x_stage_count = 0; ut_resource_x_rearm_count = 0; ut_resource_x_complete_count = 0; @@ -1012,23 +985,19 @@ UT_TEST(test_direct_zero_block_reply_uses_data_owner_direct_lane) UT_TEST(test_r4_cap_bound_zero_reply_sends_only_on_exact_generation) { - const uint32 cap = PGRAC_IC_HELLO_CAP_SEMANTIC_ACTIVATION_V1 - | PGRAC_IC_HELLO_CAP_R4_SYNC_CR_V1; - GcsBlockReplyHeader hdr - = ut_r4_refusal_header(GCS_BLOCK_REPLY_R4_RETRYABLE_HOLDER_MOVED, 1); + const uint32 cap = PGRAC_IC_HELLO_CAP_SEMANTIC_ACTIVATION_V1 | PGRAC_IC_HELLO_CAP_R4_SYNC_CR_V1; + GcsBlockReplyHeader hdr = ut_r4_refusal_header(GCS_BLOCK_REPLY_R4_RETRYABLE_HOLDER_MOVED, 1); ut_reset_log(); ut_peer_capabilities[UT_PEER_X] = cap; ut_peer_cap_generation[UT_PEER_X] = 42; - UT_ASSERT(cluster_lms_outbound_enqueue_zero_block_reply_cap_bound( - 2, UT_PEER_X, &hdr, cap, 42)); + UT_ASSERT(cluster_lms_outbound_enqueue_zero_block_reply_cap_bound(2, UT_PEER_X, &hdr, cap, 42)); UT_ASSERT_EQ(cluster_lms_outbound_drain_send(2), 1); UT_ASSERT_EQ(ut_sent_n, 1); UT_ASSERT_EQ(ut_checksum_call_count, 1); UT_ASSERT_EQ(ut_sent_log[0].payload_len, GCS_BLOCK_REPLY_PAYLOAD_TOTAL_SIZE); UT_ASSERT(ut_sent_log[0].reply_block_zero); - UT_ASSERT_EQ(ut_sent_log[0].reply_header.status, - GCS_BLOCK_REPLY_R4_RETRYABLE_HOLDER_MOVED); + UT_ASSERT_EQ(ut_sent_log[0].reply_header.status, GCS_BLOCK_REPLY_R4_RETRYABLE_HOLDER_MOVED); UT_ASSERT_EQ(ut_sent_log[0].reply_header.page_lsn, 1); UT_ASSERT_EQ(ut_sent_log[0].reply_header.checksum, UINT32_C(0xA55A7E11)); UT_ASSERT_EQ(GcsBlockReplyHeaderGetForwardingMasterNode(&ut_sent_log[0].reply_header), @@ -1037,15 +1006,13 @@ UT_TEST(test_r4_cap_bound_zero_reply_sends_only_on_exact_generation) UT_TEST(test_r4_cap_bound_zero_reply_drops_drift_before_zero_expansion) { - const uint32 cap = PGRAC_IC_HELLO_CAP_SEMANTIC_ACTIVATION_V1 - | PGRAC_IC_HELLO_CAP_R4_SYNC_CR_V1; + const uint32 cap = PGRAC_IC_HELLO_CAP_SEMANTIC_ACTIVATION_V1 | PGRAC_IC_HELLO_CAP_R4_SYNC_CR_V1; GcsBlockReplyHeader hdr = ut_r4_refusal_header(GCS_BLOCK_REPLY_R4_DENIED, 0); ut_reset_log(); ut_peer_capabilities[UT_PEER_X] = cap; ut_peer_cap_generation[UT_PEER_X] = 43; - UT_ASSERT(cluster_lms_outbound_enqueue_zero_block_reply_cap_bound( - 2, UT_PEER_X, &hdr, cap, 42)); + UT_ASSERT(cluster_lms_outbound_enqueue_zero_block_reply_cap_bound(2, UT_PEER_X, &hdr, cap, 42)); UT_ASSERT_EQ(cluster_lms_outbound_drain_send(2), 0); UT_ASSERT_EQ(cluster_lms_outbound_depth(2), 0); UT_ASSERT_EQ(ut_sent_n, 0); @@ -1055,23 +1022,21 @@ UT_TEST(test_r4_cap_bound_zero_reply_drops_drift_before_zero_expansion) UT_TEST(test_zero_reply_wrappers_reject_the_other_status_domain) { - const uint32 cap = PGRAC_IC_HELLO_CAP_SEMANTIC_ACTIVATION_V1 - | PGRAC_IC_HELLO_CAP_R4_SYNC_CR_V1; - GcsBlockReplyHeader legacy - = ut_r4_refusal_header(GCS_BLOCK_REPLY_DENIED_PENDING_X, 0); + const uint32 cap = PGRAC_IC_HELLO_CAP_SEMANTIC_ACTIVATION_V1 | PGRAC_IC_HELLO_CAP_R4_SYNC_CR_V1; + GcsBlockReplyHeader legacy = ut_r4_refusal_header(GCS_BLOCK_REPLY_DENIED_PENDING_X, 0); GcsBlockReplyHeader retryable = ut_r4_refusal_header(GCS_BLOCK_REPLY_R4_RETRYABLE_HOLDER_MOVED, 0); GcsBlockReplyHeader denied = ut_r4_refusal_header(GCS_BLOCK_REPLY_R4_DENIED, 1); ut_reset_log(); UT_ASSERT(!cluster_lms_outbound_enqueue_zero_block_reply(0, UT_PEER_X, &retryable, false)); - UT_ASSERT(!cluster_lms_outbound_enqueue_zero_block_reply_cap_bound( - 0, UT_PEER_X, &legacy, cap, 42)); - UT_ASSERT(!cluster_lms_outbound_enqueue_zero_block_reply_cap_bound( - 0, UT_PEER_X, &denied, cap, 42)); + UT_ASSERT( + !cluster_lms_outbound_enqueue_zero_block_reply_cap_bound(0, UT_PEER_X, &legacy, cap, 42)); + UT_ASSERT( + !cluster_lms_outbound_enqueue_zero_block_reply_cap_bound(0, UT_PEER_X, &denied, cap, 42)); retryable.reserved_0[0] = 1; - UT_ASSERT(!cluster_lms_outbound_enqueue_zero_block_reply_cap_bound( - 0, UT_PEER_X, &retryable, cap, 42)); + UT_ASSERT(!cluster_lms_outbound_enqueue_zero_block_reply_cap_bound(0, UT_PEER_X, &retryable, + cap, 42)); UT_ASSERT_EQ(cluster_lms_outbound_depth(0), 0); } @@ -1081,8 +1046,7 @@ UT_TEST(test_zero_reply_wrappers_reject_the_other_status_domain) * note for the next tick instead of losing it. */ UT_TEST(test_full_worker_ring_refuses_without_overwrite) { - const uint32 cap = PGRAC_IC_HELLO_CAP_SEMANTIC_ACTIVATION_V1 - | PGRAC_IC_HELLO_CAP_R4_SYNC_CR_V1; + const uint32 cap = PGRAC_IC_HELLO_CAP_SEMANTIC_ACTIVATION_V1 | PGRAC_IC_HELLO_CAP_R4_SYNC_CR_V1; GcsBlockReplyHeader refusal = ut_r4_refusal_header(GCS_BLOCK_REPLY_R4_DENIED, 0); int accepted = 0; int sent = 0; @@ -1094,8 +1058,8 @@ UT_TEST(test_full_worker_ring_refuses_without_overwrite) UT_ASSERT(accepted < 1024); UT_ASSERT_EQ((int)cluster_lms_outbound_depth(1), accepted); UT_ASSERT(!ut_enqueue_marker(1, UT_PEER_X, 0xE3)); - UT_ASSERT(!cluster_lms_outbound_enqueue_zero_block_reply_cap_bound( - 1, UT_PEER_X, &refusal, cap, 42)); + UT_ASSERT( + !cluster_lms_outbound_enqueue_zero_block_reply_cap_bound(1, UT_PEER_X, &refusal, cap, 42)); UT_ASSERT_EQ((int)cluster_lms_outbound_depth(1), accepted); ut_peer_rc[UT_PEER_X] = CLUSTER_IC_SEND_DONE; @@ -1166,18 +1130,15 @@ UT_TEST(test_resource_x_intent_admission_stages_and_completion_clears_owner) intent = ut_resource_x_grant_intent(UT_PEER_X); ut_resource_x_owner_slot = intent; ut_resource_x_owner_payload[0] = 0xA6; - ut_peer_capabilities[UT_PEER_X] - = PGRAC_IC_HELLO_CAP_GCS_RESOURCE_X_CONVERT_V1; + ut_peer_capabilities[UT_PEER_X] = PGRAC_IC_HELLO_CAP_GCS_RESOURCE_X_CONVERT_V1; ut_peer_cap_generation[UT_PEER_X] = 77; ut_peer_rc[UT_PEER_X] = CLUSTER_IC_SEND_DONE; UT_ASSERT(cluster_lms_outbound_resource_x_transport_snapshot(&before)); UT_ASSERT_EQ(before.staged_count, 0); - UT_ASSERT(cluster_lms_outbound_enqueue_resource_x_intent( - 0, &intent, 77, UINT64_MAX)); + UT_ASSERT(cluster_lms_outbound_enqueue_resource_x_intent(0, &intent, 77, UINT64_MAX)); UT_ASSERT_EQ(ut_resource_x_stage_count, 1); - UT_ASSERT_EQ(ut_resource_x_owner_slot.state, - RESOURCE_X_INTENT_SLOT_STAGED); + UT_ASSERT_EQ(ut_resource_x_owner_slot.state, RESOURCE_X_INTENT_SLOT_STAGED); UT_ASSERT_EQ(cluster_lms_outbound_depth(0), 1); UT_ASSERT_EQ(cluster_lms_outbound_resource_x_staged_count(), 1); UT_ASSERT(cluster_lms_outbound_resource_x_transport_snapshot(&after)); @@ -1197,8 +1158,7 @@ UT_TEST(test_resource_x_intent_admission_stages_and_completion_clears_owner) UT_ASSERT_EQ(ut_resource_x_rebind_count, 1); UT_ASSERT_EQ(ut_resource_x_rebind_generation, 77); UT_ASSERT_EQ(ut_resource_x_complete_count, 1); - UT_ASSERT_EQ(ut_resource_x_owner_slot.state, - RESOURCE_X_INTENT_SLOT_EMPTY); + UT_ASSERT_EQ(ut_resource_x_owner_slot.state, RESOURCE_X_INTENT_SLOT_EMPTY); } UT_TEST(test_resource_x_block_intent_uses_type17_and_control_payload) @@ -1209,18 +1169,15 @@ UT_TEST(test_resource_x_block_intent_uses_type17_and_control_payload) intent = ut_resource_x_block_intent(UT_PEER_X); ut_resource_x_owner_slot = intent; ut_resource_x_owner_payload[0] = 0xA9; - ut_peer_capabilities[UT_PEER_X] - = PGRAC_IC_HELLO_CAP_GCS_RESOURCE_X_CONVERT_V1; + ut_peer_capabilities[UT_PEER_X] = PGRAC_IC_HELLO_CAP_GCS_RESOURCE_X_CONVERT_V1; ut_peer_cap_generation[UT_PEER_X] = 83; ut_peer_rc[UT_PEER_X] = CLUSTER_IC_SEND_DONE; - UT_ASSERT(cluster_lms_outbound_enqueue_resource_x_intent( - 0, &intent, 83, UINT64_MAX)); + UT_ASSERT(cluster_lms_outbound_enqueue_resource_x_intent(0, &intent, 83, UINT64_MAX)); UT_ASSERT_EQ(cluster_lms_outbound_drain_send(0), 1); UT_ASSERT_EQ(ut_sent_n, 1); UT_ASSERT_EQ(ut_sent_log[0].msg_type, RESOURCE_X_MSG_BLOCK_TO_N); - UT_ASSERT_EQ(ut_sent_log[0].payload_len, - RESOURCE_X_CONTROL_V1_BYTES); + UT_ASSERT_EQ(ut_sent_log[0].payload_len, RESOURCE_X_CONTROL_V1_BYTES); UT_ASSERT_EQ(ut_sent_log[0].marker, 0xA9); UT_ASSERT_EQ(ut_resource_x_rebind_count, 1); UT_ASSERT_EQ(ut_resource_x_rebind_generation, 83); @@ -1235,19 +1192,15 @@ UT_TEST(test_resource_x_settlement_intent_uses_type38_and_short_payload) intent = ut_resource_x_settlement_intent(UT_PEER_X); ut_resource_x_owner_slot = intent; ut_resource_x_owner_payload[0] = 0xAB; - ut_peer_capabilities[UT_PEER_X] - = PGRAC_IC_HELLO_CAP_GCS_RESOURCE_X_CONVERT_V1; + ut_peer_capabilities[UT_PEER_X] = PGRAC_IC_HELLO_CAP_GCS_RESOURCE_X_CONVERT_V1; ut_peer_cap_generation[UT_PEER_X] = 86; ut_peer_rc[UT_PEER_X] = CLUSTER_IC_SEND_DONE; - UT_ASSERT(cluster_lms_outbound_enqueue_resource_x_intent( - 0, &intent, 86, UINT64_MAX)); + UT_ASSERT(cluster_lms_outbound_enqueue_resource_x_intent(0, &intent, 86, UINT64_MAX)); UT_ASSERT_EQ(cluster_lms_outbound_drain_send(0), 1); UT_ASSERT_EQ(ut_sent_n, 1); - UT_ASSERT_EQ(ut_sent_log[0].msg_type, - RESOURCE_X_MSG_SETTLEMENT_OR_RELEASE); - UT_ASSERT_EQ(ut_sent_log[0].payload_len, - RESOURCE_X_SHORT_V1_BYTES); + UT_ASSERT_EQ(ut_sent_log[0].msg_type, RESOURCE_X_MSG_SETTLEMENT_OR_RELEASE); + UT_ASSERT_EQ(ut_sent_log[0].payload_len, RESOURCE_X_SHORT_V1_BYTES); UT_ASSERT_EQ(ut_sent_log[0].marker, 0xAB); UT_ASSERT_EQ(ut_resource_x_rebind_count, 1); UT_ASSERT_EQ(ut_resource_x_rebind_generation, 86); @@ -1262,23 +1215,19 @@ UT_TEST(test_resource_x_holder_release_transport_rearms_until_typed_ack) intent = ut_resource_x_holder_release_intent(UT_PEER_X); ut_resource_x_owner_slot = intent; ut_resource_x_owner_payload[0] = 0xAC; - ut_peer_capabilities[UT_PEER_X] - = PGRAC_IC_HELLO_CAP_GCS_RESOURCE_X_CONVERT_V1; + ut_peer_capabilities[UT_PEER_X] = PGRAC_IC_HELLO_CAP_GCS_RESOURCE_X_CONVERT_V1; ut_peer_cap_generation[UT_PEER_X] = 87; ut_peer_rc[UT_PEER_X] = CLUSTER_IC_SEND_DONE; - UT_ASSERT(cluster_lms_outbound_enqueue_resource_x_intent( - 0, &intent, 87, UINT64_MAX)); + UT_ASSERT(cluster_lms_outbound_enqueue_resource_x_intent(0, &intent, 87, UINT64_MAX)); UT_ASSERT_EQ(cluster_lms_outbound_drain_send(0), 1); UT_ASSERT_EQ(ut_sent_n, 1); UT_ASSERT_EQ(ut_sent_log[0].msg_type, RESOURCE_X_MSG_BLOCK_TO_N); - UT_ASSERT_EQ(ut_sent_log[0].payload_len, - RESOURCE_X_PROOF_V1_BYTES); + UT_ASSERT_EQ(ut_sent_log[0].payload_len, RESOURCE_X_PROOF_V1_BYTES); UT_ASSERT_EQ(ut_sent_log[0].marker, 0xAC); UT_ASSERT_EQ(ut_resource_x_rearm_count, 1); UT_ASSERT_EQ(ut_resource_x_complete_count, 0); - UT_ASSERT_EQ(ut_resource_x_owner_slot.state, - RESOURCE_X_INTENT_SLOT_ARMED); + UT_ASSERT_EQ(ut_resource_x_owner_slot.state, RESOURCE_X_INTENT_SLOT_ARMED); } UT_TEST(test_resource_x_source_settlement_ack_fits_ordinary_data_ring) @@ -1288,16 +1237,14 @@ UT_TEST(test_resource_x_source_settlement_ack_fits_ordinary_data_ring) ut_reset_log(); ut_peer_rc[UT_PEER_X] = CLUSTER_IC_SEND_DONE; - UT_ASSERT(cluster_lms_outbound_enqueue(0, - RESOURCE_X_MSG_BLOCKED_TO_N, UT_PEER_X, ack, sizeof(ack))); + UT_ASSERT( + cluster_lms_outbound_enqueue(0, RESOURCE_X_MSG_BLOCKED_TO_N, UT_PEER_X, ack, sizeof(ack))); UT_ASSERT_EQ(cluster_lms_outbound_depth(0), 1); UT_ASSERT_EQ(cluster_lms_outbound_drain_send(0), 1); UT_ASSERT_EQ(cluster_lms_outbound_depth(0), 0); UT_ASSERT_EQ(ut_sent_n, 1); - UT_ASSERT_EQ(ut_sent_log[0].msg_type, - RESOURCE_X_MSG_BLOCKED_TO_N); - UT_ASSERT_EQ(ut_sent_log[0].payload_len, - RESOURCE_X_PROOF_V1_BYTES); + UT_ASSERT_EQ(ut_sent_log[0].msg_type, RESOURCE_X_MSG_BLOCKED_TO_N); + UT_ASSERT_EQ(ut_sent_log[0].payload_len, RESOURCE_X_PROOF_V1_BYTES); UT_ASSERT_EQ(ut_sent_log[0].marker, 0xAD); } @@ -1310,13 +1257,11 @@ UT_TEST(test_resource_x_image_intent_rebinds_transport_generation) ut_resource_x_owner_slot = intent; ut_resource_x_owner_payload[0] = 0xAA; ut_resource_x_decode_sender_generation = 84; - ut_peer_capabilities[UT_PEER_X] - = PGRAC_IC_HELLO_CAP_GCS_RESOURCE_X_CONVERT_V1; + ut_peer_capabilities[UT_PEER_X] = PGRAC_IC_HELLO_CAP_GCS_RESOURCE_X_CONVERT_V1; ut_peer_cap_generation[UT_PEER_X] = 84; ut_peer_rc[UT_PEER_X] = CLUSTER_IC_SEND_DONE; - UT_ASSERT(cluster_lms_outbound_enqueue_resource_x_intent( - 0, &intent, 84, UINT64_MAX)); + UT_ASSERT(cluster_lms_outbound_enqueue_resource_x_intent(0, &intent, 84, UINT64_MAX)); UT_ASSERT_EQ(cluster_lms_outbound_drain_send(0), 1); UT_ASSERT_EQ(ut_sent_n, 1); UT_ASSERT_EQ(ut_sent_log[0].msg_type, RESOURCE_X_MSG_IMAGE_OR_GRANT); @@ -1331,11 +1276,9 @@ UT_TEST(test_resource_x_image_intent_rebinds_transport_generation) intent = ut_resource_x_image_intent(UT_PEER_X); ut_resource_x_owner_slot = intent; ut_resource_x_decode_sender_generation = 84; - ut_peer_capabilities[UT_PEER_X] - = PGRAC_IC_HELLO_CAP_GCS_RESOURCE_X_CONVERT_V1; + ut_peer_capabilities[UT_PEER_X] = PGRAC_IC_HELLO_CAP_GCS_RESOURCE_X_CONVERT_V1; ut_peer_cap_generation[UT_PEER_X] = 85; - UT_ASSERT(cluster_lms_outbound_enqueue_resource_x_intent( - 0, &intent, 85, UINT64_MAX)); + UT_ASSERT(cluster_lms_outbound_enqueue_resource_x_intent(0, &intent, 85, UINT64_MAX)); UT_ASSERT_EQ(cluster_lms_outbound_drain_send(0), 1); UT_ASSERT_EQ(ut_sent_n, 1); UT_ASSERT_EQ(ut_resource_x_decode_count, 0); @@ -1343,8 +1286,7 @@ UT_TEST(test_resource_x_image_intent_rebinds_transport_generation) UT_ASSERT_EQ(ut_resource_x_rebind_generation, 85); UT_ASSERT_EQ(ut_resource_x_rearm_count, 0); UT_ASSERT_EQ(ut_resource_x_complete_count, 1); - UT_ASSERT_EQ(ut_resource_x_owner_slot.state, - RESOURCE_X_INTENT_SLOT_EMPTY); + UT_ASSERT_EQ(ut_resource_x_owner_slot.state, RESOURCE_X_INTENT_SLOT_EMPTY); } UT_TEST(test_resource_x_intent_transport_refusal_rearms_without_ring_copy) @@ -1355,19 +1297,16 @@ UT_TEST(test_resource_x_intent_transport_refusal_rearms_without_ring_copy) intent = ut_resource_x_grant_intent(UT_PEER_X); ut_resource_x_owner_slot = intent; ut_resource_x_owner_payload[0] = 0xA7; - ut_peer_capabilities[UT_PEER_X] - = PGRAC_IC_HELLO_CAP_GCS_RESOURCE_X_CONVERT_V1; + ut_peer_capabilities[UT_PEER_X] = PGRAC_IC_HELLO_CAP_GCS_RESOURCE_X_CONVERT_V1; ut_peer_cap_generation[UT_PEER_X] = 78; ut_peer_rc[UT_PEER_X] = CLUSTER_IC_SEND_NOT_ADMITTED; - UT_ASSERT(cluster_lms_outbound_enqueue_resource_x_intent( - 0, &intent, 78, UINT64_MAX)); + UT_ASSERT(cluster_lms_outbound_enqueue_resource_x_intent(0, &intent, 78, UINT64_MAX)); UT_ASSERT_EQ(cluster_lms_outbound_drain_send(0), 0); UT_ASSERT_EQ(cluster_lms_outbound_depth(0), 0); UT_ASSERT_EQ(ut_sent_n, 1); UT_ASSERT_EQ(ut_resource_x_rearm_count, 1); - UT_ASSERT_EQ(ut_resource_x_owner_slot.state, - RESOURCE_X_INTENT_SLOT_ARMED); + UT_ASSERT_EQ(ut_resource_x_owner_slot.state, RESOURCE_X_INTENT_SLOT_ARMED); UT_ASSERT_EQ(ut_resource_x_complete_count, 0); } @@ -1378,19 +1317,16 @@ UT_TEST(test_resource_x_intent_capability_drift_rearms_before_send) ut_reset_log(); intent = ut_resource_x_grant_intent(UT_PEER_X); ut_resource_x_owner_slot = intent; - ut_peer_capabilities[UT_PEER_X] - = PGRAC_IC_HELLO_CAP_GCS_RESOURCE_X_CONVERT_V1; + ut_peer_capabilities[UT_PEER_X] = PGRAC_IC_HELLO_CAP_GCS_RESOURCE_X_CONVERT_V1; ut_peer_cap_generation[UT_PEER_X] = 79; - UT_ASSERT(cluster_lms_outbound_enqueue_resource_x_intent( - 0, &intent, 79, UINT64_MAX)); + UT_ASSERT(cluster_lms_outbound_enqueue_resource_x_intent(0, &intent, 79, UINT64_MAX)); ut_peer_cap_generation[UT_PEER_X] = 80; UT_ASSERT_EQ(cluster_lms_outbound_drain_send(0), 0); UT_ASSERT_EQ(cluster_lms_outbound_depth(0), 0); UT_ASSERT_EQ(ut_sent_n, 0); UT_ASSERT_EQ(ut_resource_x_rearm_count, 1); - UT_ASSERT_EQ(ut_resource_x_owner_slot.state, - RESOURCE_X_INTENT_SLOT_ARMED); + UT_ASSERT_EQ(ut_resource_x_owner_slot.state, RESOURCE_X_INTENT_SLOT_ARMED); } UT_TEST(test_resource_x_intent_physical_deadline_rearms_before_send) @@ -1400,18 +1336,15 @@ UT_TEST(test_resource_x_intent_physical_deadline_rearms_before_send) ut_reset_log(); intent = ut_resource_x_grant_intent(UT_PEER_X); ut_resource_x_owner_slot = intent; - ut_peer_capabilities[UT_PEER_X] - = PGRAC_IC_HELLO_CAP_GCS_RESOURCE_X_CONVERT_V1; + ut_peer_capabilities[UT_PEER_X] = PGRAC_IC_HELLO_CAP_GCS_RESOURCE_X_CONVERT_V1; ut_peer_cap_generation[UT_PEER_X] = 81; - UT_ASSERT(cluster_lms_outbound_enqueue_resource_x_intent( - 0, &intent, 81, 1)); + UT_ASSERT(cluster_lms_outbound_enqueue_resource_x_intent(0, &intent, 81, 1)); UT_ASSERT_EQ(cluster_lms_outbound_drain_send(0), 0); UT_ASSERT_EQ(cluster_lms_outbound_depth(0), 0); UT_ASSERT_EQ(ut_sent_n, 0); UT_ASSERT_EQ(ut_resource_x_rearm_count, 1); - UT_ASSERT_EQ(ut_resource_x_owner_slot.state, - RESOURCE_X_INTENT_SLOT_ARMED); + UT_ASSERT_EQ(ut_resource_x_owner_slot.state, RESOURCE_X_INTENT_SLOT_ARMED); } UT_TEST(test_resource_x_intent_pump_stages_found_owner_on_tag_shard) @@ -1424,12 +1357,10 @@ UT_TEST(test_resource_x_intent_pump_stages_found_owner_on_tag_shard) ut_resource_x_owner_slot = intent; ut_resource_x_owner_payload[0] = 0xA8; ut_resource_x_probe_mode = RESOURCE_X_INTENT_PROBE_FOUND; - ut_peer_capabilities[UT_PEER_X] - = PGRAC_IC_HELLO_CAP_GCS_RESOURCE_X_CONVERT_V1; + ut_peer_capabilities[UT_PEER_X] = PGRAC_IC_HELLO_CAP_GCS_RESOURCE_X_CONVERT_V1; ut_peer_cap_generation[UT_PEER_X] = 82; ut_peer_rc[UT_PEER_X] = CLUSTER_IC_SEND_DONE; - worker_id = cluster_lms_shard_for_tag( - &intent.body.assertion.resource, cluster_lms_workers); + worker_id = cluster_lms_shard_for_tag(&intent.body.assertion.resource, cluster_lms_workers); UT_ASSERT_EQ(cluster_lms_outbound_resource_x_intent_pump(), 1); UT_ASSERT_EQ(ut_resource_x_probe_call_count, 2); @@ -1456,8 +1387,7 @@ UT_TEST(test_resource_x_intent_pump_not_admitted_preserves_owner) UT_ASSERT_EQ(ut_resource_x_stage_count, 0); UT_ASSERT_EQ(cluster_lms_outbound_depth(0), 0); UT_ASSERT_EQ(ut_sent_n, 0); - UT_ASSERT_EQ(ut_resource_x_owner_slot.state, - RESOURCE_X_INTENT_SLOT_ARMED); + UT_ASSERT_EQ(ut_resource_x_owner_slot.state, RESOURCE_X_INTENT_SLOT_ARMED); UT_ASSERT(ut_resource_x_owner_slot.last_attempt_us != 0); UT_ASSERT_EQ(ut_resource_x_complete_count, 0); } @@ -1508,12 +1438,10 @@ UT_TEST(test_resource_x_type14_assert_and_local_proof_share_one_data_fifo) ut_reset_log(); ut_peer_rc[UT_PEER_X] = CLUSTER_IC_SEND_DONE; - UT_ASSERT(cluster_lms_outbound_enqueue( - worker_id, RESOURCE_X_MSG_ASSERT_X, UT_PEER_X, - assertion, sizeof(assertion))); - UT_ASSERT(cluster_lms_outbound_enqueue( - worker_id, RESOURCE_X_MSG_ASSERT_X, UT_PEER_X, - local_proof, sizeof(local_proof))); + UT_ASSERT(cluster_lms_outbound_enqueue(worker_id, RESOURCE_X_MSG_ASSERT_X, UT_PEER_X, assertion, + sizeof(assertion))); + UT_ASSERT(cluster_lms_outbound_enqueue(worker_id, RESOURCE_X_MSG_ASSERT_X, UT_PEER_X, + local_proof, sizeof(local_proof))); UT_ASSERT_EQ(cluster_lms_outbound_depth(worker_id), 2); UT_ASSERT_EQ(cluster_lms_outbound_resource_x_staged_count(), 0); UT_ASSERT_EQ(cluster_lms_outbound_drain_send(worker_id), 2); @@ -1552,11 +1480,9 @@ UT_TEST(test_resource_x_remote_s_status_is_pending_then_exact_ready) UT_ASSERT(cluster_lms_outbound_resource_x_transport_snapshot(&snapshot)); transport_sequence = snapshot.mutation_sequence; - UT_ASSERT_EQ( - cluster_lms_outbound_stage_resource_x_remote_s_status_exact( - worker_id, UT_PEER_X, status, sizeof(status), - &revoking, &handle), - CLUSTER_PCM_OWN_OK); + UT_ASSERT_EQ(cluster_lms_outbound_stage_resource_x_remote_s_status_exact( + worker_id, UT_PEER_X, status, sizeof(status), &revoking, &handle), + CLUSTER_PCM_OWN_OK); UT_ASSERT(handle.slot_cookie != 0); UT_ASSERT_EQ(cluster_lms_outbound_depth(worker_id), 1); UT_ASSERT_EQ(cluster_lms_outbound_resource_x_staged_count(), 1); @@ -1573,18 +1499,14 @@ UT_TEST(test_resource_x_remote_s_status_is_pending_then_exact_ready) released.generation += 2; released.flags = 0; released.pcm_state = (uint8)PCM_STATE_N; - UT_ASSERT_EQ( - cluster_lms_outbound_publish_resource_x_remote_s_status_exact( - &handle, &released), - CLUSTER_PCM_OWN_STALE); + UT_ASSERT_EQ(cluster_lms_outbound_publish_resource_x_remote_s_status_exact(&handle, &released), + CLUSTER_PCM_OWN_STALE); UT_ASSERT_EQ(cluster_lms_outbound_depth(worker_id), 1); UT_ASSERT_EQ(ut_sent_n, 0); released.generation = revoking.generation + 1; - UT_ASSERT_EQ( - cluster_lms_outbound_publish_resource_x_remote_s_status_exact( - &handle, &released), - CLUSTER_PCM_OWN_OK); + UT_ASSERT_EQ(cluster_lms_outbound_publish_resource_x_remote_s_status_exact(&handle, &released), + CLUSTER_PCM_OWN_OK); UT_ASSERT(cluster_lms_outbound_resource_x_transport_snapshot(&snapshot)); UT_ASSERT(snapshot.mutation_sequence > transport_sequence); transport_sequence = snapshot.mutation_sequence; @@ -1595,8 +1517,7 @@ UT_TEST(test_resource_x_remote_s_status_is_pending_then_exact_ready) UT_ASSERT_EQ(cluster_lms_outbound_depth(worker_id), 1); UT_ASSERT_EQ(ut_sent_n, 0); - ut_peer_capabilities[UT_PEER_X] - = PGRAC_IC_HELLO_CAP_GCS_RESOURCE_X_CONVERT_V1; + ut_peer_capabilities[UT_PEER_X] = PGRAC_IC_HELLO_CAP_GCS_RESOURCE_X_CONVERT_V1; ut_peer_cap_generation[UT_PEER_X] = 88; ut_peer_rc[UT_PEER_X] = CLUSTER_IC_SEND_HARD_ERROR; UT_ASSERT_EQ(cluster_lms_outbound_drain_send(worker_id), 0); @@ -1611,10 +1532,8 @@ UT_TEST(test_resource_x_remote_s_status_is_pending_then_exact_ready) UT_ASSERT(cluster_lms_outbound_resource_x_transport_snapshot(&snapshot)); UT_ASSERT(snapshot.mutation_sequence > transport_sequence); UT_ASSERT_EQ(ut_sent_n, 2); - UT_ASSERT_EQ(ut_sent_log[1].msg_type, - RESOURCE_X_MSG_BLOCKED_TO_N); - UT_ASSERT_EQ(ut_sent_log[1].payload_len, - RESOURCE_X_CONTROL_V1_BYTES); + UT_ASSERT_EQ(ut_sent_log[1].msg_type, RESOURCE_X_MSG_BLOCKED_TO_N); + UT_ASSERT_EQ(ut_sent_log[1].payload_len, RESOURCE_X_CONTROL_V1_BYTES); UT_ASSERT_EQ(ut_sent_log[1].marker, 0xB1); } @@ -1636,19 +1555,13 @@ UT_TEST(test_resource_x_remote_s_pending_can_cancel_without_send) revoking.flags = PCM_OWN_FLAG_REVOKING; revoking.pcm_state = (uint8)PCM_STATE_S; - UT_ASSERT_EQ( - cluster_lms_outbound_stage_resource_x_remote_s_status_exact( - worker_id, UT_PEER_X, status, sizeof(status), - &revoking, &handle), - CLUSTER_PCM_OWN_OK); - UT_ASSERT_EQ( - cluster_lms_outbound_cancel_resource_x_remote_s_status_exact( - &handle), - CLUSTER_PCM_OWN_OK); - UT_ASSERT_EQ( - cluster_lms_outbound_cancel_resource_x_remote_s_status_exact( - &handle), - CLUSTER_PCM_OWN_STALE); + UT_ASSERT_EQ(cluster_lms_outbound_stage_resource_x_remote_s_status_exact( + worker_id, UT_PEER_X, status, sizeof(status), &revoking, &handle), + CLUSTER_PCM_OWN_OK); + UT_ASSERT_EQ(cluster_lms_outbound_cancel_resource_x_remote_s_status_exact(&handle), + CLUSTER_PCM_OWN_OK); + UT_ASSERT_EQ(cluster_lms_outbound_cancel_resource_x_remote_s_status_exact(&handle), + CLUSTER_PCM_OWN_STALE); UT_ASSERT_EQ(cluster_lms_outbound_drain_send(worker_id), 0); UT_ASSERT_EQ(cluster_lms_outbound_depth(worker_id), 0); UT_ASSERT_EQ(ut_sent_n, 0); @@ -1675,8 +1588,7 @@ UT_TEST(test_resource_x_nonrequester_s_status_self_master_loopback_is_retained) UT_ASSERT_EQ( cluster_lms_outbound_stage_resource_x_remote_s_status_exact( - worker_id, (uint32)cluster_node_id, status, sizeof(status), - &revoking, &handle), + worker_id, (uint32)cluster_node_id, status, sizeof(status), &revoking, &handle), CLUSTER_PCM_OWN_OK); UT_ASSERT_EQ(cluster_lms_outbound_drain_send(worker_id), 0); UT_ASSERT_EQ(cluster_lms_outbound_depth(worker_id), 1); @@ -1686,10 +1598,8 @@ UT_TEST(test_resource_x_nonrequester_s_status_self_master_loopback_is_retained) released.generation++; released.flags = 0; released.pcm_state = (uint8)PCM_STATE_N; - UT_ASSERT_EQ( - cluster_lms_outbound_publish_resource_x_remote_s_status_exact( - &handle, &released), - CLUSTER_PCM_OWN_OK); + UT_ASSERT_EQ(cluster_lms_outbound_publish_resource_x_remote_s_status_exact(&handle, &released), + CLUSTER_PCM_OWN_OK); UT_ASSERT_EQ(cluster_lms_outbound_drain_send(worker_id), 1); UT_ASSERT_EQ(cluster_lms_outbound_depth(worker_id), 0); UT_ASSERT_EQ(ut_sent_n, 0); diff --git a/src/test/cluster_unit/test_cluster_lms_shard.c b/src/test/cluster_unit/test_cluster_lms_shard.c index ee3db144873..d8334360a87 100644 --- a/src/test/cluster_unit/test_cluster_lms_shard.c +++ b/src/test/cluster_unit/test_cluster_lms_shard.c @@ -361,14 +361,11 @@ UT_TEST(test_lms_child_exit_invalidates_shared_readiness) cluster_lms_shared_mark_child_exit(&state); - UT_ASSERT_EQ((int)pg_atomic_read_u32(&state.lms_state), - (int)CLUSTER_LMS_STOPPED); + UT_ASSERT_EQ((int)pg_atomic_read_u32(&state.lms_state), (int)CLUSTER_LMS_STOPPED); UT_ASSERT_EQ(state.pid, 0); UT_ASSERT_EQ(state.worker_pids[0], 0); - UT_ASSERT_EQ(pg_atomic_read_u64(&state.recovery_ready_generation), - UINT64_C(0)); - UT_ASSERT_EQ(pg_atomic_read_u64(&state.serving_requested_generation), - UINT64_C(0)); + UT_ASSERT_EQ(pg_atomic_read_u64(&state.recovery_ready_generation), UINT64_C(0)); + UT_ASSERT_EQ(pg_atomic_read_u64(&state.serving_requested_generation), UINT64_C(0)); } int diff --git a/src/test/cluster_unit/test_cluster_membership.c b/src/test/cluster_unit/test_cluster_membership.c index afb92dab142..5ef2b75c011 100644 --- a/src/test/cluster_unit/test_cluster_membership.c +++ b/src/test/cluster_unit/test_cluster_membership.c @@ -102,8 +102,7 @@ static ClusterMembershipTable seed_tab; static uint32 test_get_le32(const uint8 *p) { - return (uint32)p[0] | ((uint32)p[1] << 8) | ((uint32)p[2] << 16) - | ((uint32)p[3] << 24); + return (uint32)p[0] | ((uint32)p[1] << 8) | ((uint32)p[2] << 16) | ((uint32)p[3] << 24); } static uint64 @@ -535,14 +534,12 @@ UT_TEST(test_replacement_marker_v3_exact_codec) ClusterReplacementCommitMarkerV3 out; uint8 bytes[CLUSTER_JCMK_REPLACEMENT_BYTES]; - make_replacement_marker(&in, CLUSTER_JCMK_REPLACEMENT_PHASE_ADMITTED, - UINT32_C(0x71727374)); + make_replacement_marker(&in, CLUSTER_JCMK_REPLACEMENT_PHASE_ADMITTED, UINT32_C(0x71727374)); memset(bytes, 0xA5, sizeof(bytes)); UT_ASSERT(cluster_replacement_marker_v3_encode(&in, bytes)); UT_ASSERT_EQ((int)test_get_le32(bytes + 0), (int)CLUSTER_JCMK_MAGIC); - UT_ASSERT_EQ((int)test_get_le32(bytes + 4), - (int)CLUSTER_JCMK_REPLACEMENT_VERSION); + UT_ASSERT_EQ((int)test_get_le32(bytes + 4), (int)CLUSTER_JCMK_REPLACEMENT_VERSION); UT_ASSERT_EQ((int)test_get_le32(bytes + 8), 7); UT_ASSERT_EQ((int)bytes[12], CLUSTER_JCMK_REPLACEMENT_PHASE_ADMITTED); UT_ASSERT_EQ((int)bytes[13], 0); @@ -656,8 +653,7 @@ UT_TEST(test_replacement_marker_v3_same_image_majority) UT_ASSERT(cluster_replacement_marker_v3_encode(&b, images[2])); selected = before; agree = 77; - UT_ASSERT_EQ(cluster_replacement_marker_v3_select_majority(images, 3, 2, 7, &selected, - &agree), + UT_ASSERT_EQ(cluster_replacement_marker_v3_select_majority(images, 3, 2, 7, &selected, &agree), -1); UT_ASSERT(memcmp(&selected, &before, sizeof(selected)) == 0); UT_ASSERT_EQ((int)agree, 77); @@ -667,31 +663,24 @@ UT_TEST(test_replacement_marker_v3_same_image_majority) images[1][44] ^= 1; selected = before; agree = 77; - UT_ASSERT_EQ(cluster_replacement_marker_v3_select_majority(images, 3, 2, 7, &selected, - &agree), + UT_ASSERT_EQ(cluster_replacement_marker_v3_select_majority(images, 3, 2, 7, &selected, &agree), -1); UT_ASSERT(memcmp(&selected, &before, sizeof(selected)) == 0); UT_ASSERT_EQ((int)agree, 77); /* Invalid cardinalities and target mismatch preserve every output. */ - UT_ASSERT_EQ(cluster_replacement_marker_v3_select_majority(images, 3, 0, 7, &selected, - &agree), + UT_ASSERT_EQ(cluster_replacement_marker_v3_select_majority(images, 3, 0, 7, &selected, &agree), -1); - UT_ASSERT_EQ(cluster_replacement_marker_v3_select_majority(images, 3, 1, 7, &selected, - &agree), + UT_ASSERT_EQ(cluster_replacement_marker_v3_select_majority(images, 3, 1, 7, &selected, &agree), -1); - UT_ASSERT_EQ(cluster_replacement_marker_v3_select_majority(images, 2, 1, 7, &selected, - &agree), + UT_ASSERT_EQ(cluster_replacement_marker_v3_select_majority(images, 2, 1, 7, &selected, &agree), -1); - UT_ASSERT_EQ(cluster_replacement_marker_v3_select_majority(images, 0, 1, 7, &selected, - &agree), + UT_ASSERT_EQ(cluster_replacement_marker_v3_select_majority(images, 0, 1, 7, &selected, &agree), -1); - UT_ASSERT_EQ(cluster_replacement_marker_v3_select_majority(images, 3, 4, 7, &selected, - &agree), + UT_ASSERT_EQ(cluster_replacement_marker_v3_select_majority(images, 3, 4, 7, &selected, &agree), -1); memcpy(images[1], images[0], sizeof(images[1])); - UT_ASSERT_EQ(cluster_replacement_marker_v3_select_majority(images, 3, 2, 8, &selected, - &agree), + UT_ASSERT_EQ(cluster_replacement_marker_v3_select_majority(images, 3, 2, 8, &selected, &agree), -1); UT_ASSERT(memcmp(&selected, &before, sizeof(selected)) == 0); UT_ASSERT_EQ((int)agree, 77); @@ -731,8 +720,7 @@ UT_TEST(test_replacement_marker_v3_phase_bases_and_floors) UT_ASSERT(floor == m.fresh_incarnation); UT_ASSERT_EQ((int)ready, (int)UINT32_C(0xA5A5A5A5)); - make_replacement_marker(&m, CLUSTER_JCMK_REPLACEMENT_PHASE_ADMITTED, - UINT32_C(0x71727374)); + make_replacement_marker(&m, CLUSTER_JCMK_REPLACEMENT_PHASE_ADMITTED, UINT32_C(0x71727374)); UT_ASSERT(cluster_replacement_marker_v3_encode(&m, bytes)); UT_ASSERT(cluster_replacement_marker_v3_floor_basis(bytes, 7, &floor)); UT_ASSERT(floor == m.fresh_incarnation); diff --git a/src/test/cluster_unit/test_cluster_multixact.c b/src/test/cluster_unit/test_cluster_multixact.c index 6825b0fb1b0..d316b332f7b 100644 --- a/src/test/cluster_unit/test_cluster_multixact.c +++ b/src/test/cluster_unit/test_cluster_multixact.c @@ -69,7 +69,8 @@ ExceptionalCondition(const char *conditionName pg_attribute_unused(), ClusterSemanticAdmissionResult cluster_multixact_source_dispatch(ClusterMultiXactSourceOp op pg_attribute_unused(), - const ClusterMultiXactSourceRequest *request pg_attribute_unused(), + const ClusterMultiXactSourceRequest *request + pg_attribute_unused(), ClusterMultiXactSourceResult *result pg_attribute_unused()) { return CLUSTER_SEMANTIC_ADMISSION_CLOSED; @@ -106,9 +107,9 @@ cluster_multixact_get_resolve_visibility_count(void) } ClusterSemanticAdmissionResult -cluster_tt_status_hint_source_dispatch( - ClusterTTStatusHintSourceOp op pg_attribute_unused(), - const ClusterTTStatusHintSourceRequest *request pg_attribute_unused()) +cluster_tt_status_hint_source_dispatch(ClusterTTStatusHintSourceOp op pg_attribute_unused(), + const ClusterTTStatusHintSourceRequest *request + pg_attribute_unused()) { return CLUSTER_SEMANTIC_ADMISSION_CLOSED; } diff --git a/src/test/cluster_unit/test_cluster_multixact_current.c b/src/test/cluster_unit/test_cluster_multixact_current.c index 9bf889fc417..ed73e8de2cd 100644 --- a/src/test/cluster_unit/test_cluster_multixact_current.c +++ b/src/test/cluster_unit/test_cluster_multixact_current.c @@ -69,8 +69,7 @@ MemoryContext CurrentMemoryContext = (MemoryContext)&test_memory_context_storage sigjmp_buf *PG_exception_stack = NULL; ErrorContextCallback *error_context_stack = NULL; -pg_attribute_noreturn() void -pg_re_throw(void) +pg_attribute_noreturn() void pg_re_throw(void) { abort(); } @@ -116,8 +115,7 @@ errstart(int elevel, const char *domain pg_attribute_unused()) } bool -errstart_cold(int elevel, - const char *domain pg_attribute_unused()) +errstart_cold(int elevel, const char *domain pg_attribute_unused()) { return elevel >= ERROR; } @@ -136,7 +134,7 @@ errmsg(const char *fmt pg_attribute_unused(), ...) void errfinish(const char *filename pg_attribute_unused(), int lineno pg_attribute_unused(), - const char *funcname pg_attribute_unused()) + const char *funcname pg_attribute_unused()) { abort(); } @@ -179,8 +177,7 @@ static uint32 test_runtime_describe_payload_len; static int test_runtime_materialize_calls; static int test_runtime_materialize_nmembers; static MultiXactMember test_runtime_materialize_member; -static uint8 test_runtime_describe_payload[ - sizeof(GcsBlockReplyHeader) + GCS_BLOCK_DATA_SIZE]; +static uint8 test_runtime_describe_payload[sizeof(GcsBlockReplyHeader) + GCS_BLOCK_DATA_SIZE]; TimestampTz GetCurrentTimestamp(void) @@ -189,39 +186,35 @@ GetCurrentTimestamp(void) } static void test_member(ClusterCurrentMxMemberDesc *member, TransactionId xid, uint8 status); -static void test_proof(ClusterCurrentMemberProof *proof, - const ClusterCurrentMxMemberDesc *member, uint16 ordinal, - ClusterCurrentMemberState state, uint16 origin, uint32 slot); +static void test_proof(ClusterCurrentMemberProof *proof, const ClusterCurrentMxMemberDesc *member, + uint16 ordinal, ClusterCurrentMemberState state, uint16 origin, uint32 slot); -extern ClusterMxDescribeResult -cluster_cr_server_test_current_mx_build_describe_page( +extern ClusterMxDescribeResult cluster_cr_server_test_current_mx_build_describe_page( uint16 source_node_id, uint64 request_id, const ClusterCurrentMxKey *key, const MultiXactMember *native_members, int native_count, ClusterCurrentMxDescribeReplyPage *page); -extern ClusterMxResolveResult -cluster_cr_server_test_current_mx_build_proof_page( +extern ClusterMxResolveResult cluster_cr_server_test_current_mx_build_proof_page( uint16 source_node_id, const ClusterCurrentMxProofForwardV2 *request, ClusterMxResolveResult result, uint32 requester_capability_generation, - const ClusterCurrentMemberProof *proofs, - uint16 proof_count, const ClusterCurrentUpdaterProof *updater_proof, - ClusterCurrentMxProofReplyPage *page); -extern bool cluster_runtime_visibility_current_owner_lookup_exact( - TransactionId xid, ClusterTTStatusKey *key, ClusterTTStatusResult *result); + const ClusterCurrentMemberProof *proofs, uint16 proof_count, + const ClusterCurrentUpdaterProof *updater_proof, ClusterCurrentMxProofReplyPage *page); +extern bool cluster_runtime_visibility_current_owner_lookup_exact(TransactionId xid, + ClusterTTStatusKey *key, + ClusterTTStatusResult *result); extern bool cluster_runtime_visibility_current_owner_lookup_exact_ctrc( TransactionId xid, ClusterTTStatusKey *key, ClusterTTStatusResult *result, uint32 *ctrc_grant_out); -MultiXactId cluster_multixact_test_materialize_local_current( - int nmembers, MultiXactMember *members); +MultiXactId cluster_multixact_test_materialize_local_current(int nmembers, + MultiXactMember *members); MultiXactId -cluster_multixact_test_materialize_local_current(int nmembers, - MultiXactMember *members) +cluster_multixact_test_materialize_local_current(int nmembers, MultiXactMember *members) { test_runtime_materialize_calls++; test_runtime_materialize_nmembers = nmembers; if (nmembers == 1 && members != NULL) test_runtime_materialize_member = members[0]; - return (MultiXactId) 901; + return (MultiXactId)901; } void @@ -265,8 +258,8 @@ cluster_write_fence_allowed(void) } bool -cluster_sf_peer_multixact_current_capability_generation( - int32 peer_id pg_attribute_unused(), uint32 *generation_out) +cluster_sf_peer_multixact_current_capability_generation(int32 peer_id pg_attribute_unused(), + uint32 *generation_out) { test_runtime_describe_capability_calls++; if (generation_out != NULL) @@ -275,13 +268,12 @@ cluster_sf_peer_multixact_current_capability_generation( } bool -cluster_sf_peer_capability_generation_matches( - int32 peer_id pg_attribute_unused(), uint32 required_capabilities, - uint32 expected_generation) +cluster_sf_peer_capability_generation_matches(int32 peer_id pg_attribute_unused(), + uint32 required_capabilities, + uint32 expected_generation) { test_runtime_describe_generation_match_calls++; - return required_capabilities - == PGRAC_IC_HELLO_CAP_MULTIXACT_CURRENT_V1 + return required_capabilities == PGRAC_IC_HELLO_CAP_MULTIXACT_CURRENT_V1 && expected_generation == 61; } @@ -299,8 +291,8 @@ cluster_gcs_block_compute_checksum(const char *data) } ClusterICSendResult -cluster_ic_send_envelope(uint8 msg_type, int32 dest_node_id, - const void *payload, uint32 payload_len) +cluster_ic_send_envelope(uint8 msg_type, int32 dest_node_id, const void *payload, + uint32 payload_len) { test_runtime_describe_send_calls++; test_runtime_describe_dest = (uint32)dest_node_id; @@ -351,8 +343,7 @@ GetMultiXactIdMembers(MultiXactId multi pg_attribute_unused(), MultiXactMember * memset(out, 0, (size_t)count * sizeof(*out)); out[0].xid = 100; out[0].status = MultiXactStatusForShare; - if (count == 2) - { + if (count == 2) { out[1].xid = 101; out[1].status = MultiXactStatusNoKeyUpdate; } @@ -385,11 +376,9 @@ cluster_gcs_current_mx_describe_fetch_and_wait( ClusterMxResolveResult cluster_gcs_current_mx_member_proof_fetch_and_wait( - int32 origin_node, ClusterCurrentMxProofForwardV2 *request, - ClusterCurrentMemberProof *proofs, uint16 proofs_cap, uint16 *proof_count, - ClusterCurrentUpdaterProof *updater_proof, - uint32 *requester_capability_generation_out, - TimestampTz deadline pg_attribute_unused()) + int32 origin_node, ClusterCurrentMxProofForwardV2 *request, ClusterCurrentMemberProof *proofs, + uint16 proofs_cap, uint16 *proof_count, ClusterCurrentUpdaterProof *updater_proof, + uint32 *requester_capability_generation_out, TimestampTz deadline pg_attribute_unused()) { ClusterCurrentMxProofForwardV2 decoded; uint8 i; @@ -410,22 +399,18 @@ cluster_gcs_current_mx_member_proof_fetch_and_wait( return CMX_RESOLVE_UNKNOWN; if (decoded.prefix.body_kind == CLUSTER_CURRENT_MX_PROOF_BODY_MEMBER_ASKS) { - if (proofs == NULL || proof_count == NULL - || proofs_cap < decoded.prefix.entry_count) + if (proofs == NULL || proof_count == NULL || proofs_cap < decoded.prefix.entry_count) return CMX_RESOLVE_UNKNOWN; for (i = 0; i < decoded.prefix.entry_count; i++) { ClusterCurrentMxMemberDesc member; test_member(&member, decoded.trailer.body.asks[i].xid, decoded.trailer.body.asks[i].member_status); - test_proof(&proofs[i], &member, - decoded.trailer.body.asks[i].member_ordinal, - test_runtime_remote_member_state, - (uint16)origin_node, 20 + i); + test_proof(&proofs[i], &member, decoded.trailer.body.asks[i].member_ordinal, + test_runtime_remote_member_state, (uint16)origin_node, 20 + i); } *proof_count = decoded.prefix.entry_count; - *requester_capability_generation_out - = (uint32)(100 + origin_node); + *requester_capability_generation_out = (uint32)(100 + origin_node); return CMX_RESOLVE_OK; } @@ -436,9 +421,8 @@ cluster_gcs_current_mx_member_proof_fetch_and_wait( test_member(&member, decoded.trailer.body.updater.challenge.updater_xid, decoded.trailer.body.updater.challenge.member_status); - test_proof(&proofs[0], &member, - decoded.trailer.body.updater.challenge.member_ordinal, CCM_COMMITTED, - (uint16)origin_node, 20); + test_proof(&proofs[0], &member, decoded.trailer.body.updater.challenge.member_ordinal, + CCM_COMMITTED, (uint16)origin_node, 20); } *proof_count = 1; updater_proof->mxkey = decoded.prefix.mxkey; @@ -458,12 +442,12 @@ bool TransactionIdIsCurrentTransactionId(TransactionId xid) { return TransactionIdIsNormal(test_runtime_self_xid) - && TransactionIdEquals(xid, test_runtime_self_xid); + && TransactionIdEquals(xid, test_runtime_self_xid); } bool -cluster_runtime_visibility_current_owner_lookup_exact( - TransactionId xid, ClusterTTStatusKey *key, ClusterTTStatusResult *result) +cluster_runtime_visibility_current_owner_lookup_exact(TransactionId xid, ClusterTTStatusKey *key, + ClusterTTStatusResult *result) { test_runtime_target_owner_calls++; UT_ASSERT_NOT_NULL(key); @@ -490,25 +474,24 @@ cluster_runtime_visibility_current_owner_lookup_exact( } bool -cluster_runtime_visibility_current_owner_lookup_exact_ctrc( - TransactionId xid, ClusterTTStatusKey *key, ClusterTTStatusResult *result, - uint32 *ctrc_grant_out) +cluster_runtime_visibility_current_owner_lookup_exact_ctrc(TransactionId xid, + ClusterTTStatusKey *key, + ClusterTTStatusResult *result, + uint32 *ctrc_grant_out) { bool found; if (ctrc_grant_out != NULL) *ctrc_grant_out = 0; - found = cluster_runtime_visibility_current_owner_lookup_exact( - xid, key, result); - if (found && ctrc_grant_out != NULL - && result->status == CLUSTER_TT_STATUS_IN_PROGRESS) + found = cluster_runtime_visibility_current_owner_lookup_exact(xid, key, result); + if (found && ctrc_grant_out != NULL && result->status == CLUSTER_TT_STATUS_IN_PROGRESS) *ctrc_grant_out = 7; return found; } bool -cluster_runtime_visibility_local_terminal_lookup_exact( - TransactionId xid, ClusterTTStatusKey *key, ClusterTTStatusResult *result) +cluster_runtime_visibility_local_terminal_lookup_exact(TransactionId xid, ClusterTTStatusKey *key, + ClusterTTStatusResult *result) { test_runtime_local_terminal_calls++; UT_ASSERT_NOT_NULL(key); @@ -529,8 +512,9 @@ cluster_runtime_visibility_local_terminal_lookup_exact( key->local_xid = xid; result->status = test_runtime_local_terminal_status; result->status_epoch = (uint32)test_runtime_epoch; - result->commit_scn = test_runtime_local_terminal_status - == CLUSTER_TT_STATUS_COMMITTED ? UINT64_C(901) : InvalidScn; + result->commit_scn = test_runtime_local_terminal_status == CLUSTER_TT_STATUS_COMMITTED + ? UINT64_C(901) + : InvalidScn; result->authoritative = true; return true; } @@ -538,12 +522,9 @@ cluster_runtime_visibility_local_terminal_lookup_exact( bool cluster_runtime_visibility_current_mx_updater_provenance_exact( const ClusterTxLocator *locator, TimestampTz deadline pg_attribute_unused(), - ClusterTTStatusKey *key, ClusterTTStatusResult *result, - uint32 *ctrc_grant_out, - uint32 *participant_capability_generation_out, - ClusterCtrcTxnKeyV1 *ctrc_key_out, - ClusterTxLocator *canonical_locator_out, - bool *cross_segment_out) + ClusterTTStatusKey *key, ClusterTTStatusResult *result, uint32 *ctrc_grant_out, + uint32 *participant_capability_generation_out, ClusterCtrcTxnKeyV1 *ctrc_key_out, + ClusterTxLocator *canonical_locator_out, bool *cross_segment_out) { uint32 data_segment; uint32 block_no; @@ -562,16 +543,14 @@ cluster_runtime_visibility_current_mx_updater_provenance_exact( *canonical_locator_out = *locator; canonical_locator_out->tt_wrap = 3; *cross_segment_out = false; - if (!uba_decode(locator->uba, &data_segment, &block_no, - &tt_slot_offset, &row_offset)) + if (!uba_decode(locator->uba, &data_segment, &block_no, &tt_slot_offset, &row_offset)) return false; - if (cluster_runtime_visibility_local_terminal_lookup_exact( - locator->xid, key, result)) { + if (cluster_runtime_visibility_local_terminal_lookup_exact(locator->xid, key, result)) { *cross_segment_out = key->undo_segment_id != data_segment; return true; } - if (!cluster_runtime_visibility_current_owner_lookup_exact_ctrc( - locator->xid, key, result, ctrc_grant_out)) + if (!cluster_runtime_visibility_current_owner_lookup_exact_ctrc(locator->xid, key, result, + ctrc_grant_out)) return false; ctrc_key_out->format_version = CLUSTER_CTRC_FORMAT_VERSION; ctrc_key_out->owner_instance = (uint8)(key->origin_node_id + 1); @@ -599,17 +578,15 @@ cluster_runtime_visibility_current_owner_lookup_exact_ctrc_full( UT_ASSERT_NOT_NULL(participant_out); memset(ctrc_key_out, 0, sizeof(*ctrc_key_out)); memset(participant_out, 0, sizeof(*participant_out)); - found = cluster_runtime_visibility_current_owner_lookup_exact_ctrc( - xid, key, result, ctrc_grant_out); - if (found && ctrc_grant_out != NULL && *ctrc_grant_out != 0) - { + found = cluster_runtime_visibility_current_owner_lookup_exact_ctrc(xid, key, result, + ctrc_grant_out); + if (found && ctrc_grant_out != NULL && *ctrc_grant_out != 0) { ctrc_key_out->format_version = CLUSTER_CTRC_FORMAT_VERSION; ctrc_key_out->owner_instance = (uint8)(key->origin_node_id + 1); ctrc_key_out->origin_node_id = key->origin_node_id; ctrc_key_out->segment_id = key->undo_segment_id; ctrc_key_out->segment_generation = 17; - ctrc_key_out->slot_offset - = cluster_tt_slot_id_to_offset(key->tt_slot_id); + ctrc_key_out->slot_offset = cluster_tt_slot_id_to_offset(key->tt_slot_id); ctrc_key_out->slot_wrap = 3; ctrc_key_out->xid = key->local_xid; ctrc_key_out->cluster_epoch = key->cluster_epoch; @@ -623,10 +600,9 @@ cluster_runtime_visibility_current_owner_lookup_exact_ctrc_full( } bool -cluster_ctrc_origin_grant_publishable( - const ClusterCtrcTxnKeyV1 *key, - const ClusterCtrcParticipantIdentity *participant, - uint32 grant_generation) +cluster_ctrc_origin_grant_publishable(const ClusterCtrcTxnKeyV1 *key, + const ClusterCtrcParticipantIdentity *participant, + uint32 grant_generation) { UT_ASSERT_NOT_NULL(key); UT_ASSERT_NOT_NULL(participant); @@ -722,24 +698,21 @@ StaticAssertDecl(offsetof(ClusterCurrentMemberProof, reserved8) == 40, StaticAssertDecl(sizeof(ClusterCurrentMxSuccessorAlias) == 24, "current MX successor alias must remain 24 bytes"); StaticAssertDecl(offsetof(ClusterCurrentMxSuccessorAlias, origin_node_id) == 0 - && offsetof(ClusterCurrentMxSuccessorAlias, - undo_record_segment_id) == 2 - && offsetof(ClusterCurrentMxSuccessorAlias, tt_slot_id) == 4 - && offsetof(ClusterCurrentMxSuccessorAlias, cluster_epoch) == 8 - && offsetof(ClusterCurrentMxSuccessorAlias, local_xid) == 12 - && offsetof(ClusterCurrentMxSuccessorAlias, reserved32) == 16 - && offsetof(ClusterCurrentMxSuccessorAlias, reserved32_2) == 20, + && offsetof(ClusterCurrentMxSuccessorAlias, undo_record_segment_id) == 2 + && offsetof(ClusterCurrentMxSuccessorAlias, tt_slot_id) == 4 + && offsetof(ClusterCurrentMxSuccessorAlias, cluster_epoch) == 8 + && offsetof(ClusterCurrentMxSuccessorAlias, local_xid) == 12 + && offsetof(ClusterCurrentMxSuccessorAlias, reserved32) == 16 + && offsetof(ClusterCurrentMxSuccessorAlias, reserved32_2) == 20, "current MX successor alias offsets changed"); StaticAssertDecl(sizeof(ClusterCurrentUpdaterProof) == 72, "current MX updater proof must remain 72 bytes"); StaticAssertDecl(offsetof(ClusterCurrentUpdaterProof, mxkey) == 0, "current MX updater proof mxkey offset changed"); -StaticAssertDecl(offsetof(ClusterCurrentUpdaterProof, - candidate_next_xmin_alias) == 16, +StaticAssertDecl(offsetof(ClusterCurrentUpdaterProof, candidate_next_xmin_alias) == 16, "current MX updater proof alias offset changed"); -StaticAssertDecl(offsetof(ClusterCurrentUpdaterProof, - candidate_next_xmin_locator) == 40, +StaticAssertDecl(offsetof(ClusterCurrentUpdaterProof, candidate_next_xmin_locator) == 40, "current MX updater proof locator offset changed"); StaticAssertDecl(offsetof(ClusterCurrentUpdaterProof, updater_xid) == 64, "current MX updater proof xid offset changed"); @@ -752,11 +725,9 @@ StaticAssertDecl(offsetof(ClusterCurrentUpdaterProof, reserved8) == 71, StaticAssertDecl(sizeof(ClusterCurrentUpdaterChallenge) == 56, "current MX updater challenge must remain 56 bytes"); -StaticAssertDecl(offsetof(ClusterCurrentUpdaterChallenge, - candidate_next_xmin_alias) == 0, +StaticAssertDecl(offsetof(ClusterCurrentUpdaterChallenge, candidate_next_xmin_alias) == 0, "current MX updater challenge alias offset changed"); -StaticAssertDecl(offsetof(ClusterCurrentUpdaterChallenge, - candidate_next_xmin_locator) == 24, +StaticAssertDecl(offsetof(ClusterCurrentUpdaterChallenge, candidate_next_xmin_locator) == 24, "current MX updater challenge locator offset changed"); StaticAssertDecl(offsetof(ClusterCurrentUpdaterChallenge, updater_xid) == 48, "current MX updater challenge xid offset changed"); @@ -874,22 +845,19 @@ test_ttkey(uint16 origin, TransactionId xid, uint32 slot) } static void -test_updater_challenge(ClusterCurrentUpdaterChallenge *challenge, - uint16 origin, TransactionId xid, uint32 slot) +test_updater_challenge(ClusterCurrentUpdaterChallenge *challenge, uint16 origin, TransactionId xid, + uint32 slot) { - uint32 data_segment - = (uint32)origin * CLUSTER_UNDO_SEGS_PER_INSTANCE + 1; + uint32 data_segment = (uint32)origin * CLUSTER_UNDO_SEGS_PER_INSTANCE + 1; UT_ASSERT(slot > 0 && slot <= TT_SLOTS_PER_SEGMENT); memset(challenge, 0, sizeof(*challenge)); challenge->candidate_next_xmin_alias.origin_node_id = origin; - challenge->candidate_next_xmin_alias.undo_record_segment_id - = (uint16)data_segment; + challenge->candidate_next_xmin_alias.undo_record_segment_id = (uint16)data_segment; challenge->candidate_next_xmin_alias.tt_slot_id = slot; challenge->candidate_next_xmin_alias.cluster_epoch = 9; challenge->candidate_next_xmin_alias.local_xid = xid; - challenge->candidate_next_xmin_locator.uba - = uba_encode(data_segment, 2, (uint16)(slot - 1), 0); + challenge->candidate_next_xmin_locator.uba = uba_encode(data_segment, 2, (uint16)(slot - 1), 0); challenge->candidate_next_xmin_locator.xid = xid; challenge->candidate_next_xmin_locator.tt_wrap = TT_WRAP_INVALID; challenge->candidate_next_xmin_locator.itl_kind = ITL_FLAG_ACTIVE; @@ -923,8 +891,7 @@ test_proof_request(ClusterCurrentMxProofForwardV2 *request, uint8 body_kind, uin request->prefix.entry_count = entry_count; request->prefix.body_kind = body_kind; request->prefix.kind = GCS_BLOCK_FORWARD_KIND_CURRENT_MX_MEMBER_PROOF; - ClusterCurrentMxProofPrefixSetDescriptorHash(&request->prefix, - UINT64CONST(0x8877665544332211)); + ClusterCurrentMxProofPrefixSetDescriptorHash(&request->prefix, UINT64CONST(0x8877665544332211)); request->trailer.magic = CLUSTER_CURRENT_MX_WIRE_MAGIC; request->trailer.version = CLUSTER_CURRENT_MX_WIRE_VERSION; if (body_kind == CLUSTER_CURRENT_MX_PROOF_BODY_MEMBER_ASKS) { @@ -941,11 +908,9 @@ test_proof_request(ClusterCurrentMxProofForwardV2 *request, uint8 body_kind, uin = challenge.candidate_next_xmin_alias; request->trailer.body.updater.challenge.candidate_next_xmin_locator = challenge.candidate_next_xmin_locator; - request->trailer.body.updater.challenge.updater_xid - = challenge.updater_xid; + request->trailer.body.updater.challenge.updater_xid = challenge.updater_xid; request->trailer.body.updater.challenge.member_ordinal = 0; - request->trailer.body.updater.challenge.member_status - = MultiXactStatusNoKeyUpdate; + request->trailer.body.updater.challenge.member_status = MultiXactStatusNoKeyUpdate; } } @@ -1151,15 +1116,13 @@ UT_TEST(test_current_multixact_proof_binding_and_order) UT_ASSERT_EQ(ordered[2].member_xid, 102); memset(proof01[0].reserved8, 0, sizeof(proof01[0].reserved8)); - UT_ASSERT_EQ(cluster_multixact_current_validate_proof_set( - &key, members, member_origins, 3, 77, hash, chunks, 3, - ordered), + UT_ASSERT_EQ(cluster_multixact_current_validate_proof_set(&key, members, member_origins, 3, 77, + hash, chunks, 3, ordered), CMX_RESOLVE_UNKNOWN); proof01[0].reserved8[0] = 7; proof01[1].reserved8[0] = 7; - UT_ASSERT_EQ(cluster_multixact_current_validate_proof_set( - &key, members, member_origins, 3, 77, hash, chunks, 3, - ordered), + UT_ASSERT_EQ(cluster_multixact_current_validate_proof_set(&key, members, member_origins, 3, 77, + hash, chunks, 3, ordered), CMX_RESOLVE_UNKNOWN); proof01[1].reserved8[0] = 0; @@ -1186,8 +1149,7 @@ UT_TEST(test_current_multixact_proof_binding_and_order) limit_updater_proof.verdict = CUCP_MATCH; UT_ASSERT_EQ(cluster_multixact_current_members_resolve( &key, members, CLUSTER_CURRENT_MX_MAX_MEMBERS + 1, hash, NULL, - capped_output.proofs, &limit_updater_proof, - proof_capability_generations), + capped_output.proofs, &limit_updater_proof, proof_capability_generations), CMX_RESOLVE_SUPPORTED_LIMIT); UT_ASSERT_EQ(capped_output.canary, UINT64CONST(0x8877665544332211)); UT_ASSERT_EQ(limit_updater_proof.verdict, CUCP_UNKNOWN); @@ -1256,11 +1218,9 @@ UT_TEST(test_current_multixact_proof_binding_and_order) UT_ASSERT_EQ(ordered[2].state, CCM_UNKNOWN); memset(ordered, 0xff, sizeof(ordered)); - UT_ASSERT_EQ( - cluster_multixact_current_members_resolve( - &key, members, 3, hash, NULL, ordered, NULL, - proof_capability_generations), - CMX_RESOLVE_UNKNOWN); + UT_ASSERT_EQ(cluster_multixact_current_members_resolve(&key, members, 3, hash, NULL, ordered, + NULL, proof_capability_generations), + CMX_RESOLVE_UNKNOWN); UT_ASSERT_EQ(ordered[0].state, CCM_UNKNOWN); UT_ASSERT_EQ(ordered[1].state, CCM_UNKNOWN); UT_ASSERT_EQ(ordered[2].state, CCM_UNKNOWN); @@ -1355,34 +1315,34 @@ UT_TEST(test_current_multixact_updater_candidate_requires_current_exact_binding) test_runtime_target_owner_enabled = true; test_runtime_target_owner_calls = 0; test_runtime_origin_proof_source_calls = 0; - UT_ASSERT_EQ(cluster_multixact_current_updater_candidate_verdict( - &candidate, 100, 5, 9, &selected, &selected_result), + UT_ASSERT_EQ(cluster_multixact_current_updater_candidate_verdict(&candidate, 100, 5, 9, + &selected, &selected_result), CUCP_MATCH); UT_ASSERT_EQ(memcmp(&selected, ¤t, sizeof(current)), 0); UT_ASSERT_EQ(test_runtime_target_owner_calls, 1); UT_ASSERT_EQ(test_runtime_origin_proof_source_calls, 0); candidate.tt_slot_id++; - UT_ASSERT_EQ(cluster_multixact_current_updater_candidate_verdict( - &candidate, 100, 5, 9, &selected, &selected_result), + UT_ASSERT_EQ(cluster_multixact_current_updater_candidate_verdict(&candidate, 100, 5, 9, + &selected, &selected_result), CUCP_UNKNOWN); UT_ASSERT_EQ(selected_result.status, CLUSTER_TT_STATUS_UNKNOWN); candidate = current; test_runtime_target_owner_enabled = false; - UT_ASSERT_EQ(cluster_multixact_current_updater_candidate_verdict( - &candidate, 100, 5, 9, &selected, &selected_result), + UT_ASSERT_EQ(cluster_multixact_current_updater_candidate_verdict(&candidate, 100, 5, 9, + &selected, &selected_result), CUCP_UNKNOWN); test_runtime_target_owner_enabled = true; candidate.local_xid++; - UT_ASSERT_EQ(cluster_multixact_current_updater_candidate_verdict( - &candidate, 100, 5, 9, &selected, &selected_result), + UT_ASSERT_EQ(cluster_multixact_current_updater_candidate_verdict(&candidate, 100, 5, 9, + &selected, &selected_result), CUCP_UNKNOWN); candidate = current; candidate.cluster_epoch++; - UT_ASSERT_EQ(cluster_multixact_current_updater_candidate_verdict( - &candidate, 100, 5, 9, &selected, &selected_result), + UT_ASSERT_EQ(cluster_multixact_current_updater_candidate_verdict(&candidate, 100, 5, 9, + &selected, &selected_result), CUCP_UNKNOWN); cluster_node_id = -1; @@ -1406,8 +1366,8 @@ UT_TEST(test_current_mx_updater_provenance_alias_canonical_matrix) test_runtime_target_owner_active_xid = 100; candidate.undo_segment_id = 1; - UT_ASSERT_EQ(cluster_multixact_current_updater_candidate_verdict( - &candidate, 100, 5, 9, &selected, &selected_result), + UT_ASSERT_EQ(cluster_multixact_current_updater_candidate_verdict(&candidate, 100, 5, 9, + &selected, &selected_result), CUCP_UNKNOWN); UT_ASSERT_EQ(selected_result.status, CLUSTER_TT_STATUS_UNKNOWN); @@ -1423,16 +1383,16 @@ UT_TEST(test_current_multixact_proof_forward_wire_binding) ClusterCurrentMxProofForwardV2 decoded; test_proof_request(&request, CLUSTER_CURRENT_MX_PROOF_BODY_MEMBER_ASKS, 7); - UT_ASSERT_EQ(cluster_multixact_current_wire_validate_proof_forward( - &request, sizeof(request), 3, 5, 9, &decoded), + UT_ASSERT_EQ(cluster_multixact_current_wire_validate_proof_forward(&request, sizeof(request), 3, + 5, 9, &decoded), true); UT_ASSERT_EQ(decoded.prefix.entry_count, 7); UT_ASSERT_EQ(ClusterCurrentMxProofPrefixGetDescriptorHash(&decoded.prefix), UINT64CONST(0x8877665544332211)); request.prefix.epoch = 0; request.prefix.mxkey.cluster_epoch = 0; - UT_ASSERT_EQ(cluster_multixact_current_wire_validate_proof_forward( - &request, sizeof(request), 3, 5, 0, &decoded), + UT_ASSERT_EQ(cluster_multixact_current_wire_validate_proof_forward(&request, sizeof(request), 3, + 5, 0, &decoded), true); request.prefix.epoch = 9; request.prefix.mxkey.cluster_epoch = 9; @@ -1444,17 +1404,17 @@ UT_TEST(test_current_multixact_proof_forward_wire_binding) &request, sizeof(request) + 1, 3, 5, 9, &decoded), false); request.trailer.body.asks[6].xid = 101; - UT_ASSERT_EQ(cluster_multixact_current_wire_validate_proof_forward( - &request, sizeof(request), 3, 5, 9, &decoded), + UT_ASSERT_EQ(cluster_multixact_current_wire_validate_proof_forward(&request, sizeof(request), 3, + 5, 9, &decoded), false); test_proof_request(&request, CLUSTER_CURRENT_MX_PROOF_BODY_UPDATER_CHALLENGE, 1); - UT_ASSERT_EQ(cluster_multixact_current_wire_validate_proof_forward( - &request, sizeof(request), 3, 5, 9, &decoded), + UT_ASSERT_EQ(cluster_multixact_current_wire_validate_proof_forward(&request, sizeof(request), 3, + 5, 9, &decoded), true); request.trailer.body.updater.challenge.member_status = MultiXactStatusForShare; - UT_ASSERT_EQ(cluster_multixact_current_wire_validate_proof_forward( - &request, sizeof(request), 3, 5, 9, &decoded), + UT_ASSERT_EQ(cluster_multixact_current_wire_validate_proof_forward(&request, sizeof(request), 3, + 5, 9, &decoded), false); } @@ -1492,8 +1452,8 @@ UT_TEST(test_current_multixact_proof_reply_wire_binding) test_member(&member, request.trailer.body.asks[i].xid, request.trailer.body.asks[i].member_status); - test_proof(&page.body.proofs[i], &member, - request.trailer.body.asks[i].member_ordinal, CCM_ACTIVE, 5, 20 + i); + test_proof(&page.body.proofs[i], &member, request.trailer.body.asks[i].member_ordinal, + CCM_ACTIVE, 5, 20 + i); } UT_ASSERT_EQ(cluster_multixact_current_wire_validate_proof_reply( @@ -1507,8 +1467,7 @@ UT_TEST(test_current_multixact_proof_reply_wire_binding) page.header.source_node_id = 4; UT_ASSERT_EQ(cluster_multixact_current_wire_validate_proof_reply_frame( &page, sizeof(page), 5, 9, &request, &frame_result, out, lengthof(out), - &out_count, &updater_out, - &requester_capability_generation), + &out_count, &updater_out, &requester_capability_generation), false); UT_ASSERT_EQ(out_count, 0); UT_ASSERT_EQ(out[0].state, CCM_UNKNOWN); @@ -1531,17 +1490,16 @@ UT_TEST(test_current_multixact_members_resolve_all_or_nothing) test_member(&members[0], 100, MultiXactStatusForShare); test_member(&members[1], 101, MultiXactStatusNoKeyUpdate); test_member(&members[2], 102, MultiXactStatusForKeyShare); - test_updater_challenge( - &challenge, (uint16)cluster_xid_origin_slot(members[1].xid), - members[1].xid, 20); + test_updater_challenge(&challenge, (uint16)cluster_xid_origin_slot(members[1].xid), + members[1].xid, 20); challenge.member_ordinal = 1; hash = cluster_multixact_current_descriptor_hash(&key, members, lengthof(members)); test_runtime_proof_calls = 0; test_runtime_proof_fail_call = 0; - UT_ASSERT_EQ(cluster_multixact_current_members_resolve( - &key, members, lengthof(members), hash, &challenge, proofs, - &updater_proof, proof_capability_generations), + UT_ASSERT_EQ(cluster_multixact_current_members_resolve(&key, members, lengthof(members), hash, + &challenge, proofs, &updater_proof, + proof_capability_generations), CMX_RESOLVE_OK); UT_ASSERT_EQ(test_runtime_proof_calls, 3); UT_ASSERT_EQ(proofs[1].state, CCM_COMMITTED); @@ -1551,9 +1509,9 @@ UT_TEST(test_current_multixact_members_resolve_all_or_nothing) memset(&updater_proof, 0xa5, sizeof(updater_proof)); test_runtime_proof_calls = 0; test_runtime_proof_fail_call = 2; - UT_ASSERT_EQ(cluster_multixact_current_members_resolve( - &key, members, lengthof(members), hash, &challenge, proofs, - &updater_proof, proof_capability_generations), + UT_ASSERT_EQ(cluster_multixact_current_members_resolve(&key, members, lengthof(members), hash, + &challenge, proofs, &updater_proof, + proof_capability_generations), CMX_RESOLVE_UNKNOWN); for (i = 0; i < lengthof(proofs); i++) UT_ASSERT_EQ(proofs[i].state, CCM_UNKNOWN); @@ -1584,26 +1542,26 @@ UT_TEST(test_current_mx_updater_provenance_local_remote_parity) test_member(&members[0], 100, MultiXactStatusNoKeyUpdate); test_updater_challenge(&challenge, 5, 100, 5); challenge.member_ordinal = 0; - hash = cluster_multixact_current_descriptor_hash(&key, members, - lengthof(members)); + hash = cluster_multixact_current_descriptor_hash(&key, members, lengthof(members)); cluster_node_id = 5; test_runtime_target_owner_enabled = false; test_runtime_local_terminal_xid = 100; test_runtime_local_terminal_status = CLUSTER_TT_STATUS_COMMITTED; test_runtime_local_terminal_rolled = true; - UT_ASSERT_EQ(cluster_multixact_current_members_resolve( - &key, members, lengthof(members), hash, &challenge, local_proofs, - &local_updater, local_generations), CMX_RESOLVE_OK); + UT_ASSERT_EQ(cluster_multixact_current_members_resolve(&key, members, lengthof(members), hash, + &challenge, local_proofs, &local_updater, + local_generations), + CMX_RESOLVE_OK); cluster_node_id = 3; test_runtime_proof_calls = 0; test_runtime_proof_fail_call = 0; - UT_ASSERT_EQ(cluster_multixact_current_members_resolve( - &key, members, lengthof(members), hash, &challenge, remote_proofs, - &remote_updater, remote_generations), CMX_RESOLVE_OK); - UT_ASSERT_EQ(memcmp(&local_updater, &remote_updater, - sizeof(local_updater)), 0); + UT_ASSERT_EQ(cluster_multixact_current_members_resolve(&key, members, lengthof(members), hash, + &challenge, remote_proofs, + &remote_updater, remote_generations), + CMX_RESOLVE_OK); + UT_ASSERT_EQ(memcmp(&local_updater, &remote_updater, sizeof(local_updater)), 0); test_runtime_local_terminal_xid = InvalidTransactionId; test_runtime_local_terminal_status = CLUSTER_TT_STATUS_UNKNOWN; @@ -1627,17 +1585,17 @@ UT_TEST(test_current_multixact_local_member_uses_target_canonical_not_source) key.cluster_epoch = (uint32)test_runtime_epoch; test_member(&members[0], 102, MultiXactStatusForShare); test_member(&members[1], 105, MultiXactStatusForKeyShare); - hash = cluster_multixact_current_descriptor_hash( - &key, members, lengthof(members)); + hash = cluster_multixact_current_descriptor_hash(&key, members, lengthof(members)); test_runtime_origin_proof_source_calls = 0; test_runtime_target_owner_enabled = true; test_runtime_target_owner_calls = 0; memset(proofs, 0xa5, sizeof(proofs)); memset(&updater_proof, 0xa5, sizeof(updater_proof)); - UT_ASSERT_EQ(cluster_multixact_current_members_resolve( - &key, members, lengthof(members), hash, NULL, proofs, - &updater_proof, proof_capability_generations), CMX_RESOLVE_OK); + UT_ASSERT_EQ(cluster_multixact_current_members_resolve(&key, members, lengthof(members), hash, + NULL, proofs, &updater_proof, + proof_capability_generations), + CMX_RESOLVE_OK); UT_ASSERT_EQ(test_runtime_target_owner_calls, 2); UT_ASSERT_EQ(test_runtime_origin_proof_source_calls, 0); UT_ASSERT_EQ(proofs[0].state, CCM_ACTIVE); @@ -1654,24 +1612,22 @@ UT_TEST(test_current_multixact_local_member_uses_target_canonical_not_source) test_runtime_local_grant_publishable = false; memset(proofs, 0xa5, sizeof(proofs)); memset(&updater_proof, 0xa5, sizeof(updater_proof)); - memset(proof_capability_generations, 0xa5, - sizeof(proof_capability_generations)); + memset(proof_capability_generations, 0xa5, sizeof(proof_capability_generations)); UT_ASSERT_EQ(cluster_multixact_current_members_resolve_until( - &key, members, lengthof(members), hash, NULL, proofs, - &updater_proof, proof_capability_generations, &operation_deadline), - CMX_RESOLVE_RETRY); + &key, members, lengthof(members), hash, NULL, proofs, &updater_proof, + proof_capability_generations, &operation_deadline), + CMX_RESOLVE_RETRY); UT_ASSERT_EQ(operation_deadline, (TimestampTz)UINT64_C(2000000)); - for (i = 0; i < lengthof(proofs); i++) - { + for (i = 0; i < lengthof(proofs); i++) { UT_ASSERT_EQ(proofs[i].state, CCM_UNKNOWN); UT_ASSERT_EQ(proof_capability_generations[i], (uint32)0); } UT_ASSERT_EQ(updater_proof.verdict, CUCP_UNKNOWN); cluster_gcs_reply_timeout_ms = 5000; UT_ASSERT_EQ(cluster_multixact_current_members_resolve_until( - &key, members, lengthof(members), hash, NULL, proofs, - &updater_proof, proof_capability_generations, &operation_deadline), - CMX_RESOLVE_RETRY); + &key, members, lengthof(members), hash, NULL, proofs, &updater_proof, + proof_capability_generations, &operation_deadline), + CMX_RESOLVE_RETRY); UT_ASSERT_EQ(operation_deadline, (TimestampTz)UINT64_C(2000000)); cluster_gcs_reply_timeout_ms = 1000; test_runtime_local_grant_publishable = true; @@ -1700,33 +1656,30 @@ UT_TEST(test_current_multixact_local_terminal_uses_physical_current_or_rolled) key.cluster_epoch = (uint32)test_runtime_epoch; test_member(&members[0], 102, MultiXactStatusForShare); test_member(&members[1], 105, MultiXactStatusForKeyShare); - hash = cluster_multixact_current_descriptor_hash( - &key, members, lengthof(members)); + hash = cluster_multixact_current_descriptor_hash(&key, members, lengthof(members)); test_runtime_target_owner_enabled = true; test_runtime_target_owner_active_xid = members[0].xid; test_runtime_local_terminal_xid = members[1].xid; test_runtime_self_xid = members[0].xid; - for (pass = 0; pass < 2; pass++) - { - test_runtime_local_terminal_status = pass == 0 - ? CLUSTER_TT_STATUS_COMMITTED : CLUSTER_TT_STATUS_ABORTED; + for (pass = 0; pass < 2; pass++) { + test_runtime_local_terminal_status + = pass == 0 ? CLUSTER_TT_STATUS_COMMITTED : CLUSTER_TT_STATUS_ABORTED; test_runtime_local_terminal_rolled = pass != 0; test_runtime_target_owner_calls = 0; test_runtime_local_terminal_calls = 0; memset(proofs, 0xa5, sizeof(proofs)); - memset(proof_capability_generations, 0xa5, - sizeof(proof_capability_generations)); - UT_ASSERT_EQ(cluster_multixact_current_members_resolve( - &key, members, lengthof(members), hash, NULL, proofs, - &updater_proof, proof_capability_generations), CMX_RESOLVE_OK); + memset(proof_capability_generations, 0xa5, sizeof(proof_capability_generations)); + UT_ASSERT_EQ(cluster_multixact_current_members_resolve(&key, members, lengthof(members), + hash, NULL, proofs, &updater_proof, + proof_capability_generations), + CMX_RESOLVE_OK); UT_ASSERT_EQ(test_runtime_target_owner_calls, 2); UT_ASSERT_EQ(test_runtime_local_terminal_calls, 1); UT_ASSERT_EQ(proofs[0].state, CCM_SELF); UT_ASSERT_EQ(ClusterCurrentMemberProofGetCtrcGrant(&proofs[0]), 7); UT_ASSERT_EQ(proof_capability_generations[0], (uint32)55); - UT_ASSERT_EQ(proofs[1].state, - pass == 0 ? CCM_COMMITTED : CCM_ABORTED); + UT_ASSERT_EQ(proofs[1].state, pass == 0 ? CCM_COMMITTED : CCM_ABORTED); UT_ASSERT_EQ(ClusterCurrentMemberProofGetCtrcGrant(&proofs[1]), 0); UT_ASSERT_EQ(proof_capability_generations[1], (uint32)0); } @@ -1756,34 +1709,32 @@ UT_TEST(test_current_multixact_multi_origin_capability_generation_pairing) cluster_node_id = 3; test_runtime_epoch = 9; - test_member(&members[0], 100, MultiXactStatusForShare); /* origin 5 */ + test_member(&members[0], 100, MultiXactStatusForShare); /* origin 5 */ test_member(&members[1], 101, MultiXactStatusForKeyShare); /* origin 6 */ - test_member(&members[2], 102, MultiXactStatusForShare); /* origin 4 */ - hash = cluster_multixact_current_descriptor_hash( - &key, members, lengthof(members)); + test_member(&members[2], 102, MultiXactStatusForShare); /* origin 4 */ + hash = cluster_multixact_current_descriptor_hash(&key, members, lengthof(members)); test_runtime_remote_member_state = CCM_ACTIVE; test_runtime_proof_calls = 0; test_runtime_proof_fail_call = 0; - UT_ASSERT_EQ(cluster_multixact_current_members_resolve( - &key, members, lengthof(members), hash, NULL, proofs, - &updater_proof, proof_capability_generations), CMX_RESOLVE_OK); - for (i = 0; i < lengthof(members); i++) - { + UT_ASSERT_EQ(cluster_multixact_current_members_resolve(&key, members, lengthof(members), hash, + NULL, proofs, &updater_proof, + proof_capability_generations), + CMX_RESOLVE_OK); + for (i = 0; i < lengthof(members); i++) { UT_ASSERT_EQ(proofs[i].state, CCM_ACTIVE); UT_ASSERT_EQ(proof_capability_generations[i], - (uint32)(100 + cluster_xid_origin_slot(members[i].xid))); + (uint32)(100 + cluster_xid_origin_slot(members[i].xid))); } memset(proofs, 0xa5, sizeof(proofs)); - memset(proof_capability_generations, 0xa5, - sizeof(proof_capability_generations)); + memset(proof_capability_generations, 0xa5, sizeof(proof_capability_generations)); test_runtime_proof_calls = 0; test_runtime_proof_fail_call = 2; - UT_ASSERT_EQ(cluster_multixact_current_members_resolve( - &key, members, lengthof(members), hash, NULL, proofs, - &updater_proof, proof_capability_generations), CMX_RESOLVE_UNKNOWN); - for (i = 0; i < lengthof(members); i++) - { + UT_ASSERT_EQ(cluster_multixact_current_members_resolve(&key, members, lengthof(members), hash, + NULL, proofs, &updater_proof, + proof_capability_generations), + CMX_RESOLVE_UNKNOWN); + for (i = 0; i < lengthof(members); i++) { UT_ASSERT_EQ(proofs[i].state, CCM_UNKNOWN); UT_ASSERT_EQ(proof_capability_generations[i], (uint32)0); } @@ -1802,15 +1753,15 @@ UT_TEST(test_current_multixact_publication_requires_prepared_state) ClusterCurrentMxHeapPublishStage next_stage; UT_ASSERT_EQ(cluster_multixact_current_heap_publish_transition( - CMX_HEAP_STAGE_LOCAL_DESCRIPTOR, CMX_HEAP_EVENT_PREPARE, - &next_stage), true); + CMX_HEAP_STAGE_LOCAL_DESCRIPTOR, CMX_HEAP_EVENT_PREPARE, &next_stage), + true); UT_ASSERT_EQ(next_stage, CMX_HEAP_STAGE_RECEIPT_PREPARED); UT_ASSERT_EQ(cluster_multixact_current_heap_publish_transition( - CMX_HEAP_STAGE_LOCAL_DESCRIPTOR, CMX_HEAP_EVENT_APPLY, - &next_stage), false); + CMX_HEAP_STAGE_LOCAL_DESCRIPTOR, CMX_HEAP_EVENT_APPLY, &next_stage), + false); UT_ASSERT_EQ(cluster_multixact_current_heap_publish_transition( - CMX_HEAP_STAGE_LOCAL_DESCRIPTOR, CMX_HEAP_EVENT_PUBLISH, - &next_stage), false); + CMX_HEAP_STAGE_LOCAL_DESCRIPTOR, CMX_HEAP_EVENT_PUBLISH, &next_stage), + false); } @@ -1818,12 +1769,9 @@ UT_TEST(test_current_multixact_publication_requires_prepared_state) * cmax, ctid, moved/HOT cleanup and ITL slot, not predecessor bytes. */ UT_TEST(test_current_multixact_exact_target_uses_planned_successor_header) { - uint8 base[SizeofHeapTupleHeader] - pg_attribute_aligned(MAXIMUM_ALIGNOF); - uint8 actual[SizeofHeapTupleHeader] - pg_attribute_aligned(MAXIMUM_ALIGNOF); - uint8 planned[SizeofHeapTupleHeader] - pg_attribute_aligned(MAXIMUM_ALIGNOF); + uint8 base[SizeofHeapTupleHeader] pg_attribute_aligned(MAXIMUM_ALIGNOF); + uint8 actual[SizeofHeapTupleHeader] pg_attribute_aligned(MAXIMUM_ALIGNOF); + uint8 planned[SizeofHeapTupleHeader] pg_attribute_aligned(MAXIMUM_ALIGNOF); HeapTupleHeader actual_header = (HeapTupleHeader)actual; ClusterCurrentMxHeapHeaderPlan plan; @@ -1846,14 +1794,13 @@ UT_TEST(test_current_multixact_exact_target_uses_planned_successor_header) actual_header->t_infomask2 |= plan.infomask2; HeapTupleHeaderClearHotUpdated(actual_header); HeapTupleHeaderSetXmax(actual_header, plan.multixact_id); - HeapTupleHeaderSetCmax( - actual_header, plan.command_id, plan.command_is_combo); + HeapTupleHeaderSetCmax(actual_header, plan.command_id, plan.command_is_combo); actual_header->t_ctid = plan.self_tid; HeapTupleHeaderSetMovedPartitions(actual_header); actual_header->t_itl_slot_idx = plan.itl_slot_index; - UT_ASSERT_EQ(cluster_multixact_current_plan_heap_header( - base, sizeof(base), &plan, planned), true); + UT_ASSERT_EQ(cluster_multixact_current_plan_heap_header(base, sizeof(base), &plan, planned), + true); UT_ASSERT_EQ(memcmp(planned, actual, sizeof(planned)), 0); UT_ASSERT(memcmp(planned, base, sizeof(planned)) != 0); } @@ -1875,14 +1822,11 @@ UT_TEST(test_current_multixact_receipt_uses_canonical_descriptor_hash) reversed[1] = members[0]; hash = cluster_multixact_current_descriptor_hash(&key, members, 2); UT_ASSERT(hash != 0); - UT_ASSERT_EQ(hash, - cluster_multixact_current_descriptor_hash(&key, members, 2)); + UT_ASSERT_EQ(hash, cluster_multixact_current_descriptor_hash(&key, members, 2)); other_key = key; other_key.multixact_id++; - UT_ASSERT(hash != cluster_multixact_current_descriptor_hash( - &other_key, members, 2)); - UT_ASSERT(hash != cluster_multixact_current_descriptor_hash( - &key, reversed, 2)); + UT_ASSERT(hash != cluster_multixact_current_descriptor_hash(&other_key, members, 2)); + UT_ASSERT(hash != cluster_multixact_current_descriptor_hash(&key, reversed, 2)); } @@ -1903,9 +1847,9 @@ UT_TEST(test_current_multixact_local_descriptor_is_described_on_demand) test_runtime_native_describe_count = 1; test_runtime_remote_describe_calls = 0; key.origin_node_id = 0; - UT_ASSERT_EQ(cluster_multixact_current_describe( - &key, members, lengthof(members), &member_count, &reported_total), - CMX_DESC_OK); + UT_ASSERT_EQ(cluster_multixact_current_describe(&key, members, lengthof(members), &member_count, + &reported_total), + CMX_DESC_OK); UT_ASSERT_EQ(test_runtime_native_describe_calls, 1); UT_ASSERT_EQ(test_runtime_remote_describe_calls, 0); UT_ASSERT_EQ(member_count, 1); @@ -1928,9 +1872,9 @@ UT_TEST(test_current_multixact_one_member_descriptor_is_valid) ClusterCurrentMxMemberDesc member; test_member(&member, 101, MultiXactStatusForShare); - UT_ASSERT_EQ(cluster_multixact_current_validate_descriptor( - &key, key.origin_node_id, key.cluster_epoch, &member, 1, 1), - CMX_DESC_OK); + UT_ASSERT_EQ(cluster_multixact_current_validate_descriptor(&key, key.origin_node_id, + key.cluster_epoch, &member, 1, 1), + CMX_DESC_OK); } @@ -1944,10 +1888,9 @@ UT_TEST(test_current_multixact_one_member_local_materializer) member.status = MultiXactStatusForKeyShare; test_runtime_materialize_calls = 0; test_runtime_materialize_nmembers = 0; - MemSet(&test_runtime_materialize_member, 0, - sizeof(test_runtime_materialize_member)); + MemSet(&test_runtime_materialize_member, 0, sizeof(test_runtime_materialize_member)); multi = MultiXactIdCreateLocalCurrentMembers(1, &member); - UT_ASSERT_EQ(multi, (MultiXactId) 901); + UT_ASSERT_EQ(multi, (MultiXactId)901); UT_ASSERT_EQ(test_runtime_materialize_calls, 1); UT_ASSERT_EQ(test_runtime_materialize_nmembers, 1); UT_ASSERT_EQ(test_runtime_materialize_member.xid, member.xid); @@ -1969,12 +1912,12 @@ UT_TEST(test_current_multixact_one_member_remote_descriptor_round_trip) native_member.xid = 501; native_member.status = MultiXactStatusForShare; UT_ASSERT_EQ(cluster_cr_server_test_current_mx_build_describe_page( - key.origin_node_id, request_id, &key, &native_member, 1, &page), - CMX_DESC_OK); + key.origin_node_id, request_id, &key, &native_member, 1, &page), + CMX_DESC_OK); UT_ASSERT_EQ(cluster_multixact_current_wire_validate_describe_reply( - &page, sizeof(page), key.origin_node_id, key.cluster_epoch, - request_id, &key, decoded, lengthof(decoded), &decoded_count, - &reported_total), CMX_DESC_OK); + &page, sizeof(page), key.origin_node_id, key.cluster_epoch, request_id, &key, + decoded, lengthof(decoded), &decoded_count, &reported_total), + CMX_DESC_OK); UT_ASSERT_EQ(decoded_count, (uint16)1); UT_ASSERT_EQ(reported_total, (uint32)1); UT_ASSERT_EQ(decoded[0].xid, native_member.xid); @@ -1997,14 +1940,14 @@ UT_TEST(test_current_multixact_one_member_proof_resolves_on_demand) test_runtime_remote_member_state = CCM_ACTIVE; test_runtime_proof_calls = 0; test_runtime_proof_fail_call = 0; - UT_ASSERT_EQ(cluster_multixact_current_members_resolve( - &key, &member, 1, hash, NULL, &proof, &updater_proof, - &proof_capability_generation), CMX_RESOLVE_OK); + UT_ASSERT_EQ(cluster_multixact_current_members_resolve(&key, &member, 1, hash, NULL, &proof, + &updater_proof, + &proof_capability_generation), + CMX_RESOLVE_OK); UT_ASSERT_EQ(test_runtime_proof_calls, 1); UT_ASSERT_EQ(proof.state, CCM_ACTIVE); UT_ASSERT_EQ(proof.member_xid, member.xid); - UT_ASSERT_EQ(proof_capability_generation, - (uint32)(100 + cluster_xid_origin_slot(member.xid))); + UT_ASSERT_EQ(proof_capability_generation, (uint32)(100 + cluster_xid_origin_slot(member.xid))); test_runtime_remote_member_state = CCM_ABORTED; cluster_node_id = -1; @@ -2020,7 +1963,7 @@ typedef union TestCurrentMxFixedHeader { static void test_current_mx_fixed_header_init(TestCurrentMxFixedHeader *storage) { - HeapTupleHeader header = (HeapTupleHeader) storage->bytes; + HeapTupleHeader header = (HeapTupleHeader)storage->bytes; MemSet(storage, 0, sizeof(*storage)); HeapTupleHeaderSetXmin(header, 41); @@ -2036,7 +1979,7 @@ test_current_mx_fixed_header_init(TestCurrentMxFixedHeader *storage) static void test_current_mx_header_plan_init(ClusterCurrentMxHeapHeaderPlan *plan, - ClusterCurrentMxHeapPublishKind kind) + ClusterCurrentMxHeapPublishKind kind) { MemSet(plan, 0, sizeof(*plan)); plan->kind = kind; @@ -2066,7 +2009,7 @@ UT_TEST(test_current_multixact_delete_header_plan_matches_publication_bytes) test_current_mx_header_plan_init(&plan, CMX_HEAP_PUBLISH_DELETE); plan.command_is_combo = true; plan.changing_partition = true; - header = (HeapTupleHeader) expected.bytes; + header = (HeapTupleHeader)expected.bytes; header->t_itl_slot_idx = plan.itl_slot_index; header->t_infomask &= ~(HEAP_XMAX_BITS | HEAP_MOVED); header->t_infomask2 &= ~HEAP_KEYS_UPDATED; @@ -2078,8 +2021,8 @@ UT_TEST(test_current_multixact_delete_header_plan_matches_publication_bytes) header->t_ctid = plan.self_tid; HeapTupleHeaderSetMovedPartitions(header); - UT_ASSERT(cluster_multixact_current_plan_heap_header( - base.bytes, sizeof(base.bytes), &plan, planned.bytes)); + UT_ASSERT(cluster_multixact_current_plan_heap_header(base.bytes, sizeof(base.bytes), &plan, + planned.bytes)); UT_ASSERT_EQ(memcmp(planned.bytes, expected.bytes, sizeof(planned.bytes)), 0); } @@ -2099,7 +2042,7 @@ UT_TEST(test_current_multixact_update_headers_match_publication_bytes) test_current_mx_header_plan_init(&plan, CMX_HEAP_PUBLISH_UPDATE_OLD); plan.command_is_combo = true; plan.hot_update = true; - header = (HeapTupleHeader) expected.bytes; + header = (HeapTupleHeader)expected.bytes; header->t_itl_slot_idx = plan.itl_slot_index; HeapTupleHeaderSetHotUpdated(header); header->t_infomask &= ~(HEAP_XMAX_BITS | HEAP_MOVED); @@ -2109,14 +2052,14 @@ UT_TEST(test_current_multixact_update_headers_match_publication_bytes) HeapTupleHeaderSetXmax(header, plan.multixact_id); HeapTupleHeaderSetCmax(header, plan.command_id, plan.command_is_combo); header->t_ctid = plan.successor_tid; - UT_ASSERT(cluster_multixact_current_plan_heap_header( - base.bytes, sizeof(base.bytes), &plan, planned.bytes)); + UT_ASSERT(cluster_multixact_current_plan_heap_header(base.bytes, sizeof(base.bytes), &plan, + planned.bytes)); UT_ASSERT_EQ(memcmp(planned.bytes, expected.bytes, sizeof(planned.bytes)), 0); expected = base; test_current_mx_header_plan_init(&plan, CMX_HEAP_PUBLISH_UPDATE_NEW); plan.hot_update = true; - header = (HeapTupleHeader) expected.bytes; + header = (HeapTupleHeader)expected.bytes; header->t_infomask &= ~HEAP_XACT_MASK; header->t_infomask2 &= ~HEAP2_XACT_MASK; HeapTupleHeaderSetXmin(header, plan.xmin); @@ -2127,8 +2070,8 @@ UT_TEST(test_current_multixact_update_headers_match_publication_bytes) HeapTupleHeaderSetHeapOnly(header); header->t_itl_slot_idx = plan.itl_slot_index; header->t_ctid = plan.self_tid; - UT_ASSERT(cluster_multixact_current_plan_heap_header( - base.bytes, sizeof(base.bytes), &plan, planned.bytes)); + UT_ASSERT(cluster_multixact_current_plan_heap_header(base.bytes, sizeof(base.bytes), &plan, + planned.bytes)); UT_ASSERT_EQ(memcmp(planned.bytes, expected.bytes, sizeof(planned.bytes)), 0); } @@ -2145,7 +2088,7 @@ UT_TEST(test_current_multixact_temp_lock_header_plan_matches_publication_bytes) expected = base; test_current_mx_header_plan_init(&plan, CMX_HEAP_PUBLISH_TEMP_LOCK); plan.itl_slot_index = CLUSTER_ITL_SLOT_UNALLOCATED; - header = (HeapTupleHeader) expected.bytes; + header = (HeapTupleHeader)expected.bytes; header->t_infomask &= ~(HEAP_XMAX_BITS | HEAP_MOVED); header->t_infomask2 &= ~HEAP_KEYS_UPDATED; HeapTupleHeaderClearHotUpdated(header); @@ -2154,8 +2097,8 @@ UT_TEST(test_current_multixact_temp_lock_header_plan_matches_publication_bytes) header->t_infomask2 |= plan.infomask2; HeapTupleHeaderSetCmax(header, plan.command_id, plan.command_is_combo); header->t_ctid = plan.self_tid; - UT_ASSERT(cluster_multixact_current_plan_heap_header( - base.bytes, sizeof(base.bytes), &plan, planned.bytes)); + UT_ASSERT(cluster_multixact_current_plan_heap_header(base.bytes, sizeof(base.bytes), &plan, + planned.bytes)); UT_ASSERT_EQ(memcmp(planned.bytes, expected.bytes, sizeof(planned.bytes)), 0); } @@ -2171,10 +2114,9 @@ UT_TEST(test_current_multixact_tuple_lock_header_plan_matches_publication_bytes) test_current_mx_fixed_header_init(&base); expected = base; test_current_mx_header_plan_init(&plan, CMX_HEAP_PUBLISH_TUPLE_LOCK); - plan.infomask = HEAP_XMAX_IS_MULTI | HEAP_XMAX_LOCK_ONLY - | HEAP_XMAX_SHR_LOCK; + plan.infomask = HEAP_XMAX_IS_MULTI | HEAP_XMAX_LOCK_ONLY | HEAP_XMAX_SHR_LOCK; plan.infomask2 = 0; - header = (HeapTupleHeader) expected.bytes; + header = (HeapTupleHeader)expected.bytes; header->t_infomask &= ~HEAP_XMAX_BITS; header->t_infomask2 &= ~HEAP_KEYS_UPDATED; header->t_infomask |= plan.infomask; @@ -2183,8 +2125,8 @@ UT_TEST(test_current_multixact_tuple_lock_header_plan_matches_publication_bytes) HeapTupleHeaderSetXmax(header, plan.multixact_id); header->t_ctid = plan.self_tid; header->t_itl_slot_idx = plan.itl_slot_index; - UT_ASSERT(cluster_multixact_current_plan_heap_header( - base.bytes, sizeof(base.bytes), &plan, planned.bytes)); + UT_ASSERT(cluster_multixact_current_plan_heap_header(base.bytes, sizeof(base.bytes), &plan, + planned.bytes)); UT_ASSERT_EQ(memcmp(planned.bytes, expected.bytes, sizeof(planned.bytes)), 0); } @@ -2194,15 +2136,14 @@ UT_TEST(test_current_multixact_one_member_heap_plan_stays_multixact) TestCurrentMxFixedHeader base; TestCurrentMxFixedHeader planned; ClusterCurrentMxHeapHeaderPlan plan; - HeapTupleHeader header = (HeapTupleHeader) planned.bytes; + HeapTupleHeader header = (HeapTupleHeader)planned.bytes; test_current_mx_fixed_header_init(&base); test_current_mx_header_plan_init(&plan, CMX_HEAP_PUBLISH_TUPLE_LOCK); - plan.infomask = HEAP_XMAX_IS_MULTI | HEAP_XMAX_LOCK_ONLY - | HEAP_XMAX_KEYSHR_LOCK; + plan.infomask = HEAP_XMAX_IS_MULTI | HEAP_XMAX_LOCK_ONLY | HEAP_XMAX_KEYSHR_LOCK; plan.infomask2 = 0; - UT_ASSERT(cluster_multixact_current_plan_heap_header( - base.bytes, sizeof(base.bytes), &plan, planned.bytes)); + UT_ASSERT(cluster_multixact_current_plan_heap_header(base.bytes, sizeof(base.bytes), &plan, + planned.bytes)); UT_ASSERT((header->t_infomask & HEAP_XMAX_IS_MULTI) != 0); UT_ASSERT_EQ(HeapTupleHeaderGetRawXmax(header), plan.multixact_id); } @@ -2212,19 +2153,19 @@ UT_TEST(test_current_multixact_applied_stage_rejects_retry) { ClusterCurrentMxHeapPublishStage next; - UT_ASSERT(cluster_multixact_current_heap_publish_transition( - CMX_HEAP_STAGE_RECEIPT_PREPARED, CMX_HEAP_EVENT_RETRY, &next)); + UT_ASSERT(cluster_multixact_current_heap_publish_transition(CMX_HEAP_STAGE_RECEIPT_PREPARED, + CMX_HEAP_EVENT_RETRY, &next)); UT_ASSERT_EQ(next, CMX_HEAP_STAGE_CANCELLED); - UT_ASSERT(cluster_multixact_current_heap_publish_transition( - CMX_HEAP_STAGE_RECEIPT_PREPARED, CMX_HEAP_EVENT_ERROR, &next)); + UT_ASSERT(cluster_multixact_current_heap_publish_transition(CMX_HEAP_STAGE_RECEIPT_PREPARED, + CMX_HEAP_EVENT_ERROR, &next)); UT_ASSERT_EQ(next, CMX_HEAP_STAGE_CANCELLED); - UT_ASSERT(!cluster_multixact_current_heap_publish_transition( - CMX_HEAP_STAGE_RECEIPT_APPLIED, CMX_HEAP_EVENT_RETRY, &next)); - UT_ASSERT(cluster_multixact_current_heap_publish_transition( - CMX_HEAP_STAGE_RECEIPT_APPLIED, CMX_HEAP_EVENT_ERROR, &next)); + UT_ASSERT(!cluster_multixact_current_heap_publish_transition(CMX_HEAP_STAGE_RECEIPT_APPLIED, + CMX_HEAP_EVENT_RETRY, &next)); + UT_ASSERT(cluster_multixact_current_heap_publish_transition(CMX_HEAP_STAGE_RECEIPT_APPLIED, + CMX_HEAP_EVENT_ERROR, &next)); UT_ASSERT_EQ(next, CMX_HEAP_STAGE_RECEIPT_APPLIED); - UT_ASSERT(cluster_multixact_current_heap_publish_transition( - CMX_HEAP_STAGE_RECEIPT_APPLIED, CMX_HEAP_EVENT_PUBLISH, &next)); + UT_ASSERT(cluster_multixact_current_heap_publish_transition(CMX_HEAP_STAGE_RECEIPT_APPLIED, + CMX_HEAP_EVENT_PUBLISH, &next)); UT_ASSERT_EQ(next, CMX_HEAP_STAGE_REFERENCE_PUBLISHED); } @@ -2248,8 +2189,7 @@ UT_TEST(test_current_multixact_proof_request_batches_by_member_origin) origins[i] = (uint16)cluster_xid_origin_slot(members[i].xid); } members[5].member_status = MultiXactStatusNoKeyUpdate; - test_updater_challenge( - &challenge, origins[5], members[5].xid, 20); + test_updater_challenge(&challenge, origins[5], members[5].xid, 20); challenge.member_ordinal = 5; hash = cluster_multixact_current_descriptor_hash(&key, members, lengthof(members)); @@ -2318,22 +2258,20 @@ UT_TEST(test_current_multixact_aux_cleaner_local_proof_plan_stays_nonwire) hash = cluster_multixact_current_descriptor_hash(&key, &member, 1); UT_ASSERT_EQ(cluster_multixact_current_wire_build_proof_requests( - &key, &member, &origin, 1, hash, NULL, 804, 0, origin, - InvalidBackendId, plans, lengthof(plans), &plan_count), - CMX_RESOLVE_OK); + &key, &member, &origin, 1, hash, NULL, 804, 0, origin, InvalidBackendId, plans, + lengthof(plans), &plan_count), + CMX_RESOLVE_OK); UT_ASSERT_EQ(plan_count, (uint16)1); UT_ASSERT_EQ(plans[0].destination_node_id, origin); - UT_ASSERT_EQ(plans[0].request.prefix.requester_backend_id, - InvalidBackendId); + UT_ASSERT_EQ(plans[0].request.prefix.requester_backend_id, InvalidBackendId); UT_ASSERT(!cluster_multixact_current_wire_validate_proof_forward( - &plans[0].request, sizeof(plans[0].request), origin, origin, 0, - &decoded)); + &plans[0].request, sizeof(plans[0].request), origin, origin, 0, &decoded)); UT_ASSERT_EQ(cluster_multixact_current_wire_build_proof_requests( - &key, &member, &origin, 1, hash, NULL, 805, 0, - (uint16)((origin + 1) % CLUSTER_MAX_NODES), InvalidBackendId, - plans, lengthof(plans), &plan_count), - CMX_RESOLVE_UNKNOWN); + &key, &member, &origin, 1, hash, NULL, 805, 0, + (uint16)((origin + 1) % CLUSTER_MAX_NODES), InvalidBackendId, plans, + lengthof(plans), &plan_count), + CMX_RESOLVE_UNKNOWN); UT_ASSERT_EQ(plan_count, (uint16)0); } @@ -2357,27 +2295,27 @@ UT_TEST(test_current_multixact_describe_wire_binding) forward.prefix.kind = GCS_BLOCK_FORWARD_KIND_CURRENT_MX_DESCRIBE; forward.trailer.magic = CLUSTER_CURRENT_MX_WIRE_MAGIC; forward.trailer.version = CLUSTER_CURRENT_MX_WIRE_VERSION; - UT_ASSERT_EQ(cluster_multixact_current_wire_validate_describe_forward( - &forward, sizeof(forward), 1, 2, 9, &decoded), + UT_ASSERT_EQ(cluster_multixact_current_wire_validate_describe_forward(&forward, sizeof(forward), + 1, 2, 9, &decoded), true); UT_ASSERT_EQ(memcmp(&decoded, &forward, sizeof(decoded)), 0); forward.prefix.epoch = 0; forward.prefix.mxkey.cluster_epoch = 0; - UT_ASSERT_EQ(cluster_multixact_current_wire_validate_describe_forward( - &forward, sizeof(forward), 1, 2, 0, &decoded), + UT_ASSERT_EQ(cluster_multixact_current_wire_validate_describe_forward(&forward, sizeof(forward), + 1, 2, 0, &decoded), true); forward.prefix.epoch = 9; forward.prefix.mxkey.cluster_epoch = 9; forward.prefix.reserved_b[3] = 1; memset(&decoded, 0xa5, sizeof(decoded)); - UT_ASSERT_EQ(cluster_multixact_current_wire_validate_describe_forward( - &forward, sizeof(forward), 1, 2, 9, &decoded), + UT_ASSERT_EQ(cluster_multixact_current_wire_validate_describe_forward(&forward, sizeof(forward), + 1, 2, 9, &decoded), false); UT_ASSERT_EQ(decoded.prefix.request_id, 0); forward.prefix.reserved_b[3] = 0; - UT_ASSERT_EQ(cluster_multixact_current_wire_validate_describe_forward( - &forward, sizeof(forward), 3, 2, 9, &decoded), + UT_ASSERT_EQ(cluster_multixact_current_wire_validate_describe_forward(&forward, sizeof(forward), + 3, 2, 9, &decoded), false); memset(&page, 0, sizeof(page)); @@ -2393,21 +2331,20 @@ UT_TEST(test_current_multixact_describe_wire_binding) page.header.wire_length = sizeof(page.header) + 2 * sizeof(page.members[0]); test_member(&page.members[0], 100, MultiXactStatusForShare); test_member(&page.members[1], 101, MultiXactStatusNoKeyUpdate); - page.header.descriptor_hash - = cluster_multixact_current_descriptor_hash(&key, page.members, 2); - UT_ASSERT_EQ(cluster_multixact_current_wire_validate_describe_reply( - &page, sizeof(page), 2, 9, 501, &key, out, lengthof(out), &out_count, - &out_total), - CMX_DESC_OK); + page.header.descriptor_hash = cluster_multixact_current_descriptor_hash(&key, page.members, 2); + UT_ASSERT_EQ( + cluster_multixact_current_wire_validate_describe_reply( + &page, sizeof(page), 2, 9, 501, &key, out, lengthof(out), &out_count, &out_total), + CMX_DESC_OK); UT_ASSERT_EQ(out_count, 2); UT_ASSERT_EQ(out_total, 2); UT_ASSERT_EQ(out[1].xid, 101); page.header.descriptor_hash++; - UT_ASSERT_EQ(cluster_multixact_current_wire_validate_describe_reply( - &page, sizeof(page), 2, 9, 501, &key, out, lengthof(out), &out_count, - &out_total), - CMX_DESC_UNKNOWN); + UT_ASSERT_EQ( + cluster_multixact_current_wire_validate_describe_reply( + &page, sizeof(page), 2, 9, 501, &key, out, lengthof(out), &out_count, &out_total), + CMX_DESC_UNKNOWN); UT_ASSERT_EQ(out_count, 0); page.header.descriptor_hash--; @@ -2421,16 +2358,16 @@ UT_TEST(test_current_multixact_describe_wire_binding) page.header.mxkey = key; page.header.total_count = CLUSTER_CURRENT_MX_MAX_MEMBERS + 1; page.header.wire_length = sizeof(page.header); - UT_ASSERT_EQ(cluster_multixact_current_wire_validate_describe_reply( - &page, sizeof(page), 2, 9, 501, &key, out, lengthof(out), &out_count, - &out_total), - CMX_DESC_SUPPORTED_LIMIT); + UT_ASSERT_EQ( + cluster_multixact_current_wire_validate_describe_reply( + &page, sizeof(page), 2, 9, 501, &key, out, lengthof(out), &out_count, &out_total), + CMX_DESC_SUPPORTED_LIMIT); UT_ASSERT_EQ(out_total, CLUSTER_CURRENT_MX_MAX_MEMBERS + 1); page.reserved[0] = 1; - UT_ASSERT_EQ(cluster_multixact_current_wire_validate_describe_reply( - &page, sizeof(page), 2, 9, 501, &key, out, lengthof(out), &out_count, - &out_total), - CMX_DESC_UNKNOWN); + UT_ASSERT_EQ( + cluster_multixact_current_wire_validate_describe_reply( + &page, sizeof(page), 2, 9, 501, &key, out, lengthof(out), &out_count, &out_total), + CMX_DESC_UNKNOWN); } @@ -2452,7 +2389,7 @@ UT_TEST(test_current_multixact_describe_routes_by_mxid_authority) test_runtime_mxid_origin = 0; test_runtime_mxid_mine = true; UT_ASSERT_EQ(cluster_multixact_current_describe(&key, members, lengthof(members), - &members_count, &reported_total), + &members_count, &reported_total), CMX_DESC_OK); UT_ASSERT_EQ(test_runtime_native_describe_calls, 1); UT_ASSERT_EQ(test_runtime_remote_describe_calls, 0); @@ -2465,7 +2402,7 @@ UT_TEST(test_current_multixact_describe_routes_by_mxid_authority) test_runtime_mxid_mine = false; test_runtime_remote_describe_ok = true; UT_ASSERT_EQ(cluster_multixact_current_describe(&key, members, lengthof(members), - &members_count, &reported_total), + &members_count, &reported_total), CMX_DESC_OK); UT_ASSERT_EQ(test_runtime_native_describe_calls, 1); UT_ASSERT_EQ(test_runtime_remote_describe_calls, 1); @@ -2474,7 +2411,7 @@ UT_TEST(test_current_multixact_describe_routes_by_mxid_authority) /* Underivable/wrong-origin identity fails before either authority read. */ test_runtime_mxid_origin = -1; UT_ASSERT_EQ(cluster_multixact_current_describe(&key, members, lengthof(members), - &members_count, &reported_total), + &members_count, &reported_total), CMX_DESC_UNKNOWN); UT_ASSERT_EQ(test_runtime_native_describe_calls, 1); UT_ASSERT_EQ(test_runtime_remote_describe_calls, 1); @@ -2765,10 +2702,8 @@ UT_TEST(test_current_multixact_committed_updater_requires_exact_hot_proof) challenge.member_ordinal = 1; memset(&updater_proof, 0, sizeof(updater_proof)); updater_proof.mxkey = key; - updater_proof.candidate_next_xmin_alias - = challenge.candidate_next_xmin_alias; - updater_proof.candidate_next_xmin_locator - = challenge.candidate_next_xmin_locator; + updater_proof.candidate_next_xmin_alias = challenge.candidate_next_xmin_alias; + updater_proof.candidate_next_xmin_locator = challenge.candidate_next_xmin_locator; updater_proof.candidate_next_xmin_locator.tt_wrap = 3; updater_proof.updater_xid = 101; updater_proof.member_ordinal = 1; @@ -2855,41 +2790,35 @@ UT_TEST(test_current_mx_updater_provenance_bootstraps_canonical_tt_wrap) memset(&updater_proof, 0, sizeof(updater_proof)); updater_proof.mxkey = key; - updater_proof.candidate_next_xmin_alias - = challenge.candidate_next_xmin_alias; - updater_proof.candidate_next_xmin_locator - = challenge.candidate_next_xmin_locator; + updater_proof.candidate_next_xmin_alias = challenge.candidate_next_xmin_alias; + updater_proof.candidate_next_xmin_locator = challenge.candidate_next_xmin_locator; updater_proof.candidate_next_xmin_locator.tt_wrap = 4; updater_proof.updater_xid = 101; updater_proof.member_ordinal = 1; updater_proof.verdict = CUCP_MATCH; UT_ASSERT(cluster_multixact_current_successor_provenance_well_formed( - &challenge.candidate_next_xmin_alias, - &challenge.candidate_next_xmin_locator, 101, 3, key.cluster_epoch)); + &challenge.candidate_next_xmin_alias, &challenge.candidate_next_xmin_locator, 101, 3, + key.cluster_epoch)); UT_ASSERT(cluster_multixact_current_validate_updater_proof( - &key, members, proofs, lengthof(members), &challenge, &updater_proof, - 3)); + &key, members, proofs, lengthof(members), &challenge, &updater_proof, 3)); challenge.candidate_next_xmin_locator.tt_wrap = 0; UT_ASSERT(!cluster_multixact_current_successor_provenance_well_formed( - &challenge.candidate_next_xmin_alias, - &challenge.candidate_next_xmin_locator, 101, 3, key.cluster_epoch)); + &challenge.candidate_next_xmin_alias, &challenge.candidate_next_xmin_locator, 101, 3, + key.cluster_epoch)); UT_ASSERT(!cluster_multixact_current_validate_updater_proof( - &key, members, proofs, lengthof(members), &challenge, &updater_proof, - 3)); + &key, members, proofs, lengthof(members), &challenge, &updater_proof, 3)); challenge.candidate_next_xmin_locator.tt_wrap = TT_WRAP_INVALID; updater_proof.candidate_next_xmin_locator.tt_wrap = TT_WRAP_INVALID; UT_ASSERT(!cluster_multixact_current_validate_updater_proof( - &key, members, proofs, lengthof(members), &challenge, &updater_proof, - 3)); + &key, members, proofs, lengthof(members), &challenge, &updater_proof, 3)); updater_proof.candidate_next_xmin_locator.tt_wrap = 4; updater_proof.candidate_next_xmin_locator.itl_slot_index++; UT_ASSERT(!cluster_multixact_current_validate_updater_proof( - &key, members, proofs, lengthof(members), &challenge, &updater_proof, - 3)); + &key, members, proofs, lengthof(members), &challenge, &updater_proof, 3)); } @@ -2945,19 +2874,20 @@ UT_TEST(test_current_multixact_unknown_trace_names_exact_rejection) test_member(&members[1], 101, MultiXactStatusForShare); test_proof(&proofs[0], &members[0], 0, CCM_ABORTED, 2, 50); test_proof(&proofs[1], &members[1], 1, CCM_ABORTED, 3, 51); - test_context(&ctx, &key, CCM_ACTION_UPDATE, MultiXactStatusUpdate, - LockTupleExclusive); + test_context(&ctx, &key, CCM_ACTION_UPDATE, MultiXactStatusUpdate, LockTupleExclusive); ctx.tuple_shape = CCM_SHAPE_UPDATED; - UT_ASSERT_EQ(cluster_multixact_current_decide_observed( - members, proofs, 2, &ctx, NULL, NULL, NULL, &trace), CMDL_UNKNOWN); + UT_ASSERT_EQ(cluster_multixact_current_decide_observed(members, proofs, 2, &ctx, NULL, NULL, + NULL, &trace), + CMDL_UNKNOWN); UT_ASSERT_EQ(trace.unknown_reason, CMX_UNKNOWN_TUPLE_SHAPE); UT_ASSERT_EQ(trace.member_ordinal, -1); ctx.tuple_shape = CCM_SHAPE_LOCK_ONLY; proofs[1].member_xid++; - UT_ASSERT_EQ(cluster_multixact_current_decide_observed( - members, proofs, 2, &ctx, NULL, NULL, NULL, &trace), CMDL_UNKNOWN); + UT_ASSERT_EQ(cluster_multixact_current_decide_observed(members, proofs, 2, &ctx, NULL, NULL, + NULL, &trace), + CMDL_UNKNOWN); UT_ASSERT_EQ(trace.unknown_reason, CMX_UNKNOWN_PROOF_ENTRY); UT_ASSERT_EQ(trace.member_ordinal, 1); } @@ -2977,9 +2907,9 @@ UT_TEST(test_current_multixact_recompose_filters_terminal_members) test_proof(&proofs[1], &members[1], 1, CCM_ACTIVE, 2, 32); test_proof(&proofs[2], &members[2], 2, CCM_ABORTED, 2, 33); - UT_ASSERT_EQ(cluster_multixact_current_recompose( - members, proofs, 3, 504, MultiXactStatusForShare, normalized, - lengthof(normalized), &normalized_count), + UT_ASSERT_EQ(cluster_multixact_current_recompose(members, proofs, 3, 504, + MultiXactStatusForShare, normalized, + lengthof(normalized), &normalized_count), CMX_RECOMPOSE_OK); UT_ASSERT_EQ(normalized_count, 2); UT_ASSERT_EQ(normalized[0].xid, 502); @@ -2998,13 +2928,14 @@ UT_TEST(test_current_multixact_recompose_preserves_one_active_member) test_member(&member, 551, MultiXactStatusForKeyShare); test_proof(&proof, &member, 0, CCM_ACTIVE, 2, 35); - UT_ASSERT_EQ(cluster_multixact_current_recompose( - &member, &proof, 1, 552, MultiXactStatusForShare, normalized, - lengthof(normalized), &normalized_count), CMX_RECOMPOSE_OK); + UT_ASSERT_EQ(cluster_multixact_current_recompose(&member, &proof, 1, 552, + MultiXactStatusForShare, normalized, + lengthof(normalized), &normalized_count), + CMX_RECOMPOSE_OK); UT_ASSERT_EQ(normalized_count, 2); UT_ASSERT_EQ(normalized[0].xid, member.xid); UT_ASSERT_EQ(normalized[0].status, MultiXactStatusForKeyShare); - UT_ASSERT_EQ(normalized[1].xid, (TransactionId) 552); + UT_ASSERT_EQ(normalized[1].xid, (TransactionId)552); UT_ASSERT_EQ(normalized[1].status, MultiXactStatusForShare); } @@ -3021,9 +2952,9 @@ UT_TEST(test_current_multixact_recompose_upgrades_requester_member) test_proof(&proofs[0], &members[0], 0, CCM_SELF, 2, 41); test_proof(&proofs[1], &members[1], 1, CCM_ACTIVE, 2, 42); - UT_ASSERT_EQ(cluster_multixact_current_recompose( - members, proofs, 2, 601, MultiXactStatusForUpdate, normalized, - lengthof(normalized), &normalized_count), + UT_ASSERT_EQ(cluster_multixact_current_recompose(members, proofs, 2, 601, + MultiXactStatusForUpdate, normalized, + lengthof(normalized), &normalized_count), CMX_RECOMPOSE_OK); UT_ASSERT_EQ(normalized_count, 2); UT_ASSERT_EQ(normalized[0].xid, 601); @@ -3045,9 +2976,9 @@ UT_TEST(test_current_multixact_recompose_fails_closed_on_incomplete_proof) test_proof(&proofs[0], &members[0], 0, CCM_ACTIVE, 2, 51); test_proof(&proofs[1], &members[1], 1, CCM_UNKNOWN, 2, 52); - UT_ASSERT_EQ(cluster_multixact_current_recompose( - members, proofs, 2, 703, MultiXactStatusForShare, normalized, - lengthof(normalized), &normalized_count), + UT_ASSERT_EQ(cluster_multixact_current_recompose(members, proofs, 2, 703, + MultiXactStatusForShare, normalized, + lengthof(normalized), &normalized_count), CMX_RECOMPOSE_UNKNOWN); UT_ASSERT_EQ(normalized_count, 0); UT_ASSERT_EQ(normalized[0].xid, InvalidTransactionId); @@ -3055,9 +2986,9 @@ UT_TEST(test_current_multixact_recompose_fails_closed_on_incomplete_proof) test_proof(&proofs[1], &members[1], 1, CCM_COMMITTED, 2, 52); members[1].member_status = MultiXactStatusNoKeyUpdate; proofs[1].member_status = MultiXactStatusNoKeyUpdate; - UT_ASSERT_EQ(cluster_multixact_current_recompose( - members, proofs, 2, 703, MultiXactStatusForShare, normalized, - lengthof(normalized), &normalized_count), + UT_ASSERT_EQ(cluster_multixact_current_recompose(members, proofs, 2, 703, + MultiXactStatusForShare, normalized, + lengthof(normalized), &normalized_count), CMX_RECOMPOSE_DENIED); UT_ASSERT_EQ(normalized_count, 0); } @@ -3078,9 +3009,8 @@ UT_TEST(test_current_multixact_recompose_filters_before_cap_check) test_proof(&proofs[0], &members[0], 0, CCM_ACTIVE, 2, 100); UT_ASSERT_EQ(cluster_multixact_current_recompose( - members, proofs, CLUSTER_CURRENT_MX_MAX_MEMBERS, 5000, - MultiXactStatusForShare, normalized, lengthof(normalized), - &normalized_count), + members, proofs, CLUSTER_CURRENT_MX_MAX_MEMBERS, 5000, MultiXactStatusForShare, + normalized, lengthof(normalized), &normalized_count), CMX_RECOMPOSE_OK); UT_ASSERT_EQ(normalized_count, 2); UT_ASSERT_EQ(normalized[0].xid, 1000); @@ -3109,42 +3039,35 @@ UT_TEST(test_current_multixact_origin_builds_strict_describe_page) memset(&page, 0xa5, sizeof(page)); UT_ASSERT_EQ(cluster_cr_server_test_current_mx_build_describe_page( - 2, request_id, &key, native_members, - lengthof(native_members), &page), - CMX_DESC_OK); + 2, request_id, &key, native_members, lengthof(native_members), &page), + CMX_DESC_OK); UT_ASSERT_EQ(page.header.magic, CLUSTER_CURRENT_MX_WIRE_MAGIC); UT_ASSERT_EQ(page.header.version, CLUSTER_CURRENT_MX_WIRE_VERSION); - UT_ASSERT_EQ(page.header.kind, - GCS_BLOCK_FORWARD_KIND_CURRENT_MX_DESCRIBE); + UT_ASSERT_EQ(page.header.kind, GCS_BLOCK_FORWARD_KIND_CURRENT_MX_DESCRIBE); UT_ASSERT_EQ(page.header.result, CMX_DESC_OK); UT_ASSERT_EQ(page.header.source_node_id, (uint32)2); UT_ASSERT_EQ(page.header.request_id, request_id); UT_ASSERT_EQ(page.header.total_count, (uint32)2); UT_ASSERT_EQ(page.header.entry_count, (uint16)2); UT_ASSERT(page.header.descriptor_hash != 0); - UT_ASSERT_EQ(page.header.wire_length, - sizeof(page.header) + 2 * sizeof(page.members[0])); + UT_ASSERT_EQ(page.header.wire_length, sizeof(page.header) + 2 * sizeof(page.members[0])); UT_ASSERT_EQ(cluster_multixact_current_wire_validate_describe_reply( - &page, sizeof(page), 2, 17, request_id, &key, - decoded, lengthof(decoded), &decoded_count, - &reported_total), - CMX_DESC_OK); + &page, sizeof(page), 2, 17, request_id, &key, decoded, lengthof(decoded), + &decoded_count, &reported_total), + CMX_DESC_OK); UT_ASSERT_EQ(decoded_count, (uint16)2); UT_ASSERT_EQ(reported_total, (uint32)2); UT_ASSERT_EQ(decoded[0].xid, (TransactionId)501); UT_ASSERT_EQ(decoded[1].xid, (TransactionId)502); UT_ASSERT_EQ(cluster_cr_server_test_current_mx_build_describe_page( - 2, request_id, &key, NULL, - CLUSTER_CURRENT_MX_MAX_MEMBERS + 1, &page), - CMX_DESC_SUPPORTED_LIMIT); + 2, request_id, &key, NULL, CLUSTER_CURRENT_MX_MAX_MEMBERS + 1, &page), + CMX_DESC_SUPPORTED_LIMIT); UT_ASSERT_EQ(cluster_multixact_current_wire_validate_describe_reply( - &page, sizeof(page), 2, 17, request_id, &key, - decoded, lengthof(decoded), &decoded_count, - &reported_total), - CMX_DESC_SUPPORTED_LIMIT); - UT_ASSERT_EQ(reported_total, - (uint32)CLUSTER_CURRENT_MX_MAX_MEMBERS + 1); + &page, sizeof(page), 2, 17, request_id, &key, decoded, lengthof(decoded), + &decoded_count, &reported_total), + CMX_DESC_SUPPORTED_LIMIT); + UT_ASSERT_EQ(reported_total, (uint32)CLUSTER_CURRENT_MX_MAX_MEMBERS + 1); } UT_TEST(test_current_multixact_origin_serves_describe_on_capability_bound_reply) @@ -3163,8 +3086,7 @@ UT_TEST(test_current_multixact_origin_serves_describe_on_capability_bound_reply) test_runtime_describe_send_calls = 0; test_runtime_describe_capability_calls = 0; test_runtime_describe_generation_match_calls = 0; - memset(test_runtime_describe_payload, 0, - sizeof(test_runtime_describe_payload)); + memset(test_runtime_describe_payload, 0, sizeof(test_runtime_describe_payload)); memset(&request, 0, sizeof(request)); request.prefix.request_id = UINT64_C(0x0200000000000043); request.prefix.epoch = test_runtime_epoch; @@ -3208,22 +3130,19 @@ UT_TEST(test_current_multixact_origin_serves_describe_on_capability_bound_reply) UT_ASSERT_EQ(test_runtime_describe_payload_len, sizeof(GcsBlockReplyHeader) + GCS_BLOCK_DATA_SIZE); outer = (const GcsBlockReplyHeader *)test_runtime_describe_payload; - page = (const ClusterCurrentMxDescribeReplyPage *)( - test_runtime_describe_payload + sizeof(*outer)); - UT_ASSERT_EQ(outer->status, - GCS_BLOCK_REPLY_CURRENT_MX_DESCRIBE_RESULT); + page = (const ClusterCurrentMxDescribeReplyPage *)(test_runtime_describe_payload + + sizeof(*outer)); + UT_ASSERT_EQ(outer->status, GCS_BLOCK_REPLY_CURRENT_MX_DESCRIBE_RESULT); UT_ASSERT_EQ(outer->sender_node, 2); UT_ASSERT_EQ(outer->requester_backend_id, 7); UT_ASSERT_EQ(outer->request_id, request.prefix.request_id); UT_ASSERT_EQ(outer->epoch, test_runtime_epoch); - UT_ASSERT_EQ(outer->checksum, - cluster_gcs_block_compute_checksum((const char *)page)); + UT_ASSERT_EQ(outer->checksum, cluster_gcs_block_compute_checksum((const char *)page)); UT_ASSERT_EQ(cluster_multixact_current_wire_validate_describe_reply( - page, sizeof(*page), 2, test_runtime_epoch, - request.prefix.request_id, &request.prefix.mxkey, - decoded, lengthof(decoded), &decoded_count, + page, sizeof(*page), 2, test_runtime_epoch, request.prefix.request_id, + &request.prefix.mxkey, decoded, lengthof(decoded), &decoded_count, &reported_total), - CMX_DESC_OK); + CMX_DESC_OK); UT_ASSERT_EQ(decoded_count, (uint16)2); UT_ASSERT_EQ(decoded[0].xid, (TransactionId)100); UT_ASSERT_EQ(decoded[1].xid, (TransactionId)101); @@ -3249,8 +3168,7 @@ UT_TEST(test_current_multixact_origin_builds_strict_member_proof_page) request.prefix.original_requester_node = 3; request.prefix.requester_backend_id = 7; request.prefix.total_count = 2; - ClusterCurrentMxProofPrefixSetDescriptorHash( - &request.prefix, UINT64_C(0x12345678)); + ClusterCurrentMxProofPrefixSetDescriptorHash(&request.prefix, UINT64_C(0x12345678)); request.prefix.entry_count = 1; request.prefix.body_kind = CLUSTER_CURRENT_MX_PROOF_BODY_MEMBER_ASKS; request.prefix.kind = GCS_BLOCK_FORWARD_KIND_CURRENT_MX_MEMBER_PROOF; @@ -3266,26 +3184,21 @@ UT_TEST(test_current_multixact_origin_builds_strict_member_proof_page) proof.state = CCM_ABORTED; memset(&page, 0xa5, sizeof(page)); - UT_ASSERT_EQ(cluster_cr_server_test_current_mx_build_proof_page( - 4, &request, CMX_RESOLVE_OK, 313, &proof, 1, NULL, - &page), - CMX_RESOLVE_OK); + UT_ASSERT_EQ(cluster_cr_server_test_current_mx_build_proof_page(4, &request, CMX_RESOLVE_OK, + 313, &proof, 1, NULL, &page), + CMX_RESOLVE_OK); UT_ASSERT_EQ(page.header.magic, CLUSTER_CURRENT_MX_WIRE_MAGIC); UT_ASSERT_EQ(page.header.version, CLUSTER_CURRENT_MX_WIRE_VERSION); - UT_ASSERT_EQ(page.header.kind, - GCS_BLOCK_FORWARD_KIND_CURRENT_MX_MEMBER_PROOF); + UT_ASSERT_EQ(page.header.kind, GCS_BLOCK_FORWARD_KIND_CURRENT_MX_MEMBER_PROOF); UT_ASSERT_EQ(page.header.result, CMX_RESOLVE_OK); UT_ASSERT_EQ(page.header.source_node_id, (uint32)4); UT_ASSERT_EQ(page.header.request_id, request.prefix.request_id); UT_ASSERT_EQ(page.header.entry_count, (uint16)1); - UT_ASSERT_EQ(page.header.requester_capability_generation, - (uint32)313); - UT_ASSERT_EQ(page.header.wire_length, - sizeof(page.header) + sizeof(proof)); + UT_ASSERT_EQ(page.header.requester_capability_generation, (uint32)313); + UT_ASSERT_EQ(page.header.wire_length, sizeof(page.header) + sizeof(proof)); UT_ASSERT(cluster_multixact_current_wire_validate_proof_reply_frame( - &page, sizeof(page), 4, 17, &request, &decoded_result, - decoded, lengthof(decoded), &decoded_count, &updater, - &decoded_capability_generation)); + &page, sizeof(page), 4, 17, &request, &decoded_result, decoded, lengthof(decoded), + &decoded_count, &updater, &decoded_capability_generation)); UT_ASSERT_EQ(decoded_result, CMX_RESOLVE_OK); UT_ASSERT_EQ(decoded_capability_generation, (uint32)313); UT_ASSERT_EQ(decoded_count, (uint16)1); @@ -3297,17 +3210,15 @@ UT_TEST(test_current_multixact_origin_builds_strict_member_proof_page) decoded_capability_generation = 313; decoded_count = 1; UT_ASSERT(!cluster_multixact_current_wire_validate_proof_reply_frame( - &page, sizeof(page), 4, 17, &request, &decoded_result, - decoded, lengthof(decoded), &decoded_count, &updater, - &decoded_capability_generation)); + &page, sizeof(page), 4, 17, &request, &decoded_result, decoded, lengthof(decoded), + &decoded_count, &updater, &decoded_capability_generation)); UT_ASSERT_EQ(decoded_result, CMX_RESOLVE_UNKNOWN); UT_ASSERT_EQ(decoded_capability_generation, (uint32)0); UT_ASSERT_EQ(decoded_count, (uint16)0); - UT_ASSERT_EQ(cluster_cr_server_test_current_mx_build_proof_page( - 4, &request, CMX_RESOLVE_DENIED, 313, NULL, 0, - NULL, &page), - CMX_RESOLVE_UNKNOWN); + UT_ASSERT_EQ(cluster_cr_server_test_current_mx_build_proof_page(4, &request, CMX_RESOLVE_DENIED, + 313, NULL, 0, NULL, &page), + CMX_RESOLVE_UNKNOWN); /* Adjustment 21: final send-freshness loss is a typed, whole-batch, * zero-output result. It is not UNKNOWN and cannot carry a stale proof or @@ -3316,26 +3227,23 @@ UT_TEST(test_current_multixact_origin_builds_strict_member_proof_page) decoded_result = CMX_RESOLVE_UNKNOWN; decoded_capability_generation = 313; decoded_count = 1; - UT_ASSERT_EQ(cluster_cr_server_test_current_mx_build_proof_page( - 4, &request, CMX_RESOLVE_RETRY, 0, NULL, 0, - NULL, &page), - CMX_RESOLVE_RETRY); + UT_ASSERT_EQ(cluster_cr_server_test_current_mx_build_proof_page(4, &request, CMX_RESOLVE_RETRY, + 0, NULL, 0, NULL, &page), + CMX_RESOLVE_RETRY); UT_ASSERT_EQ(page.header.result, CMX_RESOLVE_RETRY); UT_ASSERT_EQ(page.header.entry_count, (uint16)0); UT_ASSERT_EQ(page.header.requester_capability_generation, (uint32)0); UT_ASSERT_EQ(page.header.wire_length, sizeof(page.header)); UT_ASSERT(cluster_multixact_current_wire_validate_proof_reply_frame( - &page, sizeof(page), 4, 17, &request, &decoded_result, - decoded, lengthof(decoded), &decoded_count, &updater, - &decoded_capability_generation)); + &page, sizeof(page), 4, 17, &request, &decoded_result, decoded, lengthof(decoded), + &decoded_count, &updater, &decoded_capability_generation)); UT_ASSERT_EQ(decoded_result, CMX_RESOLVE_RETRY); UT_ASSERT_EQ(decoded_capability_generation, (uint32)0); UT_ASSERT_EQ(decoded_count, (uint16)0); UT_ASSERT_EQ(decoded[0].state, CCM_UNKNOWN); - UT_ASSERT_EQ(cluster_cr_server_test_current_mx_build_proof_page( - 4, &request, CMX_RESOLVE_RETRY, 313, &proof, 1, - NULL, &page), - CMX_RESOLVE_UNKNOWN); + UT_ASSERT_EQ(cluster_cr_server_test_current_mx_build_proof_page(4, &request, CMX_RESOLVE_RETRY, + 313, &proof, 1, NULL, &page), + CMX_RESOLVE_UNKNOWN); } UT_TEST(test_current_multixact_origin_serves_member_proof_on_capability_bound_reply) @@ -3355,8 +3263,7 @@ UT_TEST(test_current_multixact_origin_serves_member_proof_on_capability_bound_re test_runtime_describe_send_calls = 0; test_runtime_describe_capability_calls = 0; test_runtime_describe_generation_match_calls = 0; - memset(test_runtime_describe_payload, 0, - sizeof(test_runtime_describe_payload)); + memset(test_runtime_describe_payload, 0, sizeof(test_runtime_describe_payload)); memset(&request, 0, sizeof(request)); request.prefix.request_id = UINT64_C(0x0400000000000045); request.prefix.epoch = test_runtime_epoch; @@ -3366,8 +3273,7 @@ UT_TEST(test_current_multixact_origin_serves_member_proof_on_capability_bound_re request.prefix.original_requester_node = 3; request.prefix.requester_backend_id = 7; request.prefix.total_count = 2; - ClusterCurrentMxProofPrefixSetDescriptorHash( - &request.prefix, UINT64_C(0x12345678)); + ClusterCurrentMxProofPrefixSetDescriptorHash(&request.prefix, UINT64_C(0x12345678)); request.prefix.entry_count = 1; request.prefix.body_kind = CLUSTER_CURRENT_MX_PROOF_BODY_MEMBER_ASKS; request.prefix.kind = GCS_BLOCK_FORWARD_KIND_CURRENT_MX_MEMBER_PROOF; @@ -3407,20 +3313,16 @@ UT_TEST(test_current_multixact_origin_serves_member_proof_on_capability_bound_re UT_ASSERT_EQ(test_runtime_describe_payload_len, sizeof(GcsBlockReplyHeader) + GCS_BLOCK_DATA_SIZE); outer = (const GcsBlockReplyHeader *)test_runtime_describe_payload; - page = (const ClusterCurrentMxProofReplyPage *)( - test_runtime_describe_payload + sizeof(*outer)); - UT_ASSERT_EQ(outer->status, - GCS_BLOCK_REPLY_CURRENT_MX_MEMBER_PROOF_RESULT); + page = (const ClusterCurrentMxProofReplyPage *)(test_runtime_describe_payload + sizeof(*outer)); + UT_ASSERT_EQ(outer->status, GCS_BLOCK_REPLY_CURRENT_MX_MEMBER_PROOF_RESULT); UT_ASSERT_EQ(outer->sender_node, 4); UT_ASSERT_EQ(outer->requester_backend_id, 7); UT_ASSERT_EQ(outer->request_id, request.prefix.request_id); UT_ASSERT_EQ(outer->epoch, test_runtime_epoch); - UT_ASSERT_EQ(outer->checksum, - cluster_gcs_block_compute_checksum((const char *)page)); + UT_ASSERT_EQ(outer->checksum, cluster_gcs_block_compute_checksum((const char *)page)); UT_ASSERT(cluster_multixact_current_wire_validate_proof_reply_frame( - page, sizeof(*page), 4, test_runtime_epoch, &request, - &decoded_result, decoded, lengthof(decoded), &decoded_count, - &updater, &decoded_capability_generation)); + page, sizeof(*page), 4, test_runtime_epoch, &request, &decoded_result, decoded, + lengthof(decoded), &decoded_count, &updater, &decoded_capability_generation)); UT_ASSERT_EQ(decoded_result, CMX_RESOLVE_UNKNOWN); UT_ASSERT_EQ(decoded_count, (uint16)0); } diff --git a/src/test/cluster_unit/test_cluster_multixact_current_stats.c b/src/test/cluster_unit/test_cluster_multixact_current_stats.c index 54e6da5f64f..67c00c20232 100644 --- a/src/test/cluster_unit/test_cluster_multixact_current_stats.c +++ b/src/test/cluster_unit/test_cluster_multixact_current_stats.c @@ -59,8 +59,7 @@ errstart(int elevel pg_attribute_unused(), const char *domain pg_attribute_unuse void errfinish(const char *filename pg_attribute_unused(), int lineno pg_attribute_unused(), const char *funcname pg_attribute_unused()) -{ -} +{} int errmsg_internal(const char *fmt pg_attribute_unused(), ...) @@ -78,6 +77,8 @@ void * ShmemInitStruct(const char *name, Size size, bool *found) { static union { + /* Enforces alignment of the byte-backed shared-memory fixture. */ + /* cppcheck-suppress unusedStructMember */ uint64 align; unsigned char bytes[4096]; } shmem; @@ -92,8 +93,7 @@ ShmemInitStruct(const char *name, Size size, bool *found) void cluster_shmem_register_region(const ClusterShmemRegion *region pg_attribute_unused()) -{ -} +{} UT_TEST(test_current_mx_stats_null_safe) { @@ -106,20 +106,13 @@ UT_TEST(test_current_mx_stats_null_safe) UT_TEST(test_current_mx_restart_bucket_boundaries) { - UT_ASSERT_EQ(cluster_multixact_current_restart_bucket(0), - CMX_STAT_RESTART_BUCKET_0); - UT_ASSERT_EQ(cluster_multixact_current_restart_bucket(1), - CMX_STAT_RESTART_BUCKET_1); - UT_ASSERT_EQ(cluster_multixact_current_restart_bucket(2), - CMX_STAT_RESTART_BUCKET_2_3); - UT_ASSERT_EQ(cluster_multixact_current_restart_bucket(3), - CMX_STAT_RESTART_BUCKET_2_3); - UT_ASSERT_EQ(cluster_multixact_current_restart_bucket(4), - CMX_STAT_RESTART_BUCKET_4_7); - UT_ASSERT_EQ(cluster_multixact_current_restart_bucket(7), - CMX_STAT_RESTART_BUCKET_4_7); - UT_ASSERT_EQ(cluster_multixact_current_restart_bucket(8), - CMX_STAT_RESTART_BUCKET_8_PLUS); + UT_ASSERT_EQ(cluster_multixact_current_restart_bucket(0), CMX_STAT_RESTART_BUCKET_0); + UT_ASSERT_EQ(cluster_multixact_current_restart_bucket(1), CMX_STAT_RESTART_BUCKET_1); + UT_ASSERT_EQ(cluster_multixact_current_restart_bucket(2), CMX_STAT_RESTART_BUCKET_2_3); + UT_ASSERT_EQ(cluster_multixact_current_restart_bucket(3), CMX_STAT_RESTART_BUCKET_2_3); + UT_ASSERT_EQ(cluster_multixact_current_restart_bucket(4), CMX_STAT_RESTART_BUCKET_4_7); + UT_ASSERT_EQ(cluster_multixact_current_restart_bucket(7), CMX_STAT_RESTART_BUCKET_4_7); + UT_ASSERT_EQ(cluster_multixact_current_restart_bucket(8), CMX_STAT_RESTART_BUCKET_8_PLUS); UT_ASSERT_EQ(cluster_multixact_current_restart_bucket(UINT32_MAX), CMX_STAT_RESTART_BUCKET_8_PLUS); } diff --git a/src/test/cluster_unit/test_cluster_node_remove.c b/src/test/cluster_unit/test_cluster_node_remove.c index 41a2904af29..d804e0a50e6 100644 --- a/src/test/cluster_unit/test_cluster_node_remove.c +++ b/src/test/cluster_unit/test_cluster_node_remove.c @@ -537,9 +537,8 @@ UT_TEST(test_ic_payload_removed_incarnation) UT_TEST(test_startup_serving_gate) { - UT_ASSERT_STR_EQ(cluster_node_remove_request_result_str( - CLUSTER_REMOVE_REQ_NOT_SERVING), - "rejected:not_serving"); + UT_ASSERT_STR_EQ(cluster_node_remove_request_result_str(CLUSTER_REMOVE_REQ_NOT_SERVING), + "rejected:not_serving"); UT_ASSERT(cluster_node_remove_startup_serving_allows(false, false)); UT_ASSERT(cluster_node_remove_startup_serving_allows(false, true)); UT_ASSERT(!cluster_node_remove_startup_serving_allows(true, false)); diff --git a/src/test/cluster_unit/test_cluster_page_abi.c b/src/test/cluster_unit/test_cluster_page_abi.c index 92b1a884ad6..140794b8fad 100644 --- a/src/test/cluster_unit/test_cluster_page_abi.c +++ b/src/test/cluster_unit/test_cluster_page_abi.c @@ -58,12 +58,9 @@ StaticAssertDecl(sizeof(PageHeaderData) == 32, "PageHeaderData ABI baseline (24-byte PG16 header + 8-byte pd_block_scn)"); StaticAssertDecl(sizeof(XLogRecord) == 32, "XLogRecord ABI baseline (24-byte PG16 header + 8-byte xl_scn)"); -StaticAssertDecl(sizeof(BufferTag) == 20, - "BufferTag ABI baseline"); -StaticAssertDecl(sizeof(RelFileLocator) == 12, - "RelFileLocator ABI baseline"); -StaticAssertDecl(offsetof(XLogRecord, xl_scn) == 16, - "spec-4.5 xl_scn at offset 16"); +StaticAssertDecl(sizeof(BufferTag) == 20, "BufferTag ABI baseline"); +StaticAssertDecl(sizeof(RelFileLocator) == 12, "RelFileLocator ABI baseline"); +StaticAssertDecl(offsetof(XLogRecord, xl_scn) == 16, "spec-4.5 xl_scn at offset 16"); UT_TEST(abi_baseline) { diff --git a/src/test/cluster_unit/test_cluster_page_anchor_cache.c b/src/test/cluster_unit/test_cluster_page_anchor_cache.c index 811b2c25d98..e4b0886fb38 100644 --- a/src/test/cluster_unit/test_cluster_page_anchor_cache.c +++ b/src/test/cluster_unit/test_cluster_page_anchor_cache.c @@ -24,21 +24,19 @@ UT_DEFINE_GLOBALS(); void -ExceptionalCondition(const char *condition_name, const char *file_name, - int line_number) +ExceptionalCondition(const char *condition_name, const char *file_name, int line_number) { - printf("# Assert failed: %s at %s:%d\n", condition_name, file_name, - line_number); + printf("# Assert failed: %s at %s:%d\n", condition_name, file_name, line_number); abort(); } /* This binary links stable-base only for shared key helpers. Keep every * external authority seam fail closed if its owner branch becomes reachable. */ ClusterControlRootResult -cluster_control_root_revalidate( - const ClusterControlRootReadToken *token pg_attribute_unused(), - const ClusterControlRootIdentity *expected_identity pg_attribute_unused(), - ClusterControlRootSnapshot *out_snapshot pg_attribute_unused()) +cluster_control_root_revalidate(const ClusterControlRootReadToken *token pg_attribute_unused(), + const ClusterControlRootIdentity *expected_identity + pg_attribute_unused(), + ClusterControlRootSnapshot *out_snapshot pg_attribute_unused()) { return CLUSTER_CONTROL_ROOT_STALE_TOKEN; } @@ -77,8 +75,7 @@ cluster_wal_retention_pin_preflight_revalidate_wait_v1( } ClusterWalPinResult -cluster_wal_retention_pin_revalidate( - ClusterWalRetentionPin *pin pg_attribute_unused()) +cluster_wal_retention_pin_revalidate(ClusterWalRetentionPin *pin pg_attribute_unused()) { return CLUSTER_WAL_PIN_STALE; } @@ -121,23 +118,20 @@ errmsg_internal(const char *fmt pg_attribute_unused(), ...) } bool -errstart_cold(int elevel pg_attribute_unused(), - const char *domain pg_attribute_unused()) +errstart_cold(int elevel pg_attribute_unused(), const char *domain pg_attribute_unused()) { return false; } void -errfinish(const char *filename pg_attribute_unused(), - int lineno pg_attribute_unused(), +errfinish(const char *filename pg_attribute_unused(), int lineno pg_attribute_unused(), const char *funcname pg_attribute_unused()) -{ -} +{} static void fill_bytes(uint8 bytes[16], uint8 seed) { - int i; + int i; for (i = 0; i < 16; i++) bytes[i] = seed + i; @@ -266,12 +260,11 @@ UT_TEST(test_explicit_cache_loss_is_safe_miss) UT_TEST(test_capacity_exhaustion_is_safe_miss) { RfPageAnchorCacheKeyV1 key; - int i; + int i; rf_page_anchor_cache_forget_all_v1(); - for (i = 0; i < RF_PAGE_ANCHOR_CACHE_CAPACITY; i++) - { - key = make_key((BlockNumber) i + 1); + for (i = 0; i < RF_PAGE_ANCHOR_CACHE_CAPACITY; i++) { + key = make_key((BlockNumber)i + 1); UT_ASSERT(rf_page_anchor_cache_record_v1(&key, true, true)); } key = make_key(999); @@ -295,11 +288,10 @@ UT_TEST(test_invalid_key_never_earns_credit) UT_TEST(test_cache_miss_adds_explicit_force_flag) { RfPageAnchorCacheKeyV1 key = make_key(1); - uint8 flags; + uint8 flags; rf_page_anchor_cache_forget_all_v1(); - flags = rf_page_anchor_cache_registration_flags_v1(&key, - REGBUF_WILL_INIT | REGBUF_STANDARD); + flags = rf_page_anchor_cache_registration_flags_v1(&key, REGBUF_WILL_INIT | REGBUF_STANDARD); UT_ASSERT((flags & REGBUF_FORCE_IMAGE) != 0); UT_ASSERT((flags & REGBUF_WILL_INIT) == REGBUF_WILL_INIT); } @@ -307,12 +299,11 @@ UT_TEST(test_cache_miss_adds_explicit_force_flag) UT_TEST(test_cache_hit_preserves_caller_flags) { RfPageAnchorCacheKeyV1 key = make_key(1); - uint8 flags = REGBUF_STANDARD; + uint8 flags = REGBUF_STANDARD; rf_page_anchor_cache_forget_all_v1(); UT_ASSERT(rf_page_anchor_cache_record_v1(&key, true, true)); - UT_ASSERT_EQ(rf_page_anchor_cache_registration_flags_v1(&key, flags), - flags); + UT_ASSERT_EQ(rf_page_anchor_cache_registration_flags_v1(&key, flags), flags); } UT_TEST(test_anchor_key_binds_exact_registered_block) @@ -320,29 +311,23 @@ UT_TEST(test_anchor_key_binds_exact_registered_block) RfPageAnchorCacheKeyV1 key = make_key(11); RelFileLocator locator = key.page_identity.locator; - UT_ASSERT(rf_page_anchor_cache_block_matches_v1(&key, &locator, - MAIN_FORKNUM, 11)); + UT_ASSERT(rf_page_anchor_cache_block_matches_v1(&key, &locator, MAIN_FORKNUM, 11)); locator.relNumber++; - UT_ASSERT(!rf_page_anchor_cache_block_matches_v1(&key, &locator, - MAIN_FORKNUM, 11)); + UT_ASSERT(!rf_page_anchor_cache_block_matches_v1(&key, &locator, MAIN_FORKNUM, 11)); locator = key.page_identity.locator; - UT_ASSERT(!rf_page_anchor_cache_block_matches_v1(&key, &locator, - FSM_FORKNUM, 11)); - UT_ASSERT(!rf_page_anchor_cache_block_matches_v1(&key, &locator, - MAIN_FORKNUM, 12)); + UT_ASSERT(!rf_page_anchor_cache_block_matches_v1(&key, &locator, FSM_FORKNUM, 11)); + UT_ASSERT(!rf_page_anchor_cache_block_matches_v1(&key, &locator, MAIN_FORKNUM, 12)); } UT_TEST(test_anchor_key_binds_exact_result_incarnation) { RfPageAnchorCacheKeyV1 key = make_key(11); - uint8 incarnation[16]; + uint8 incarnation[16]; memcpy(incarnation, key.segment_incarnation, 16); - UT_ASSERT(rf_page_anchor_cache_incarnation_matches_v1(&key, - incarnation)); + UT_ASSERT(rf_page_anchor_cache_incarnation_matches_v1(&key, incarnation)); incarnation[15] ^= 0x80; - UT_ASSERT(!rf_page_anchor_cache_incarnation_matches_v1(&key, - incarnation)); + UT_ASSERT(!rf_page_anchor_cache_incarnation_matches_v1(&key, incarnation)); UT_ASSERT(!rf_page_anchor_cache_incarnation_matches_v1(&key, NULL)); } diff --git a/src/test/cluster_unit/test_cluster_page_apply.c b/src/test/cluster_unit/test_cluster_page_apply.c index eb9952f7a19..8597f4414cd 100644 --- a/src/test/cluster_unit/test_cluster_page_apply.c +++ b/src/test/cluster_unit/test_cluster_page_apply.c @@ -90,45 +90,36 @@ UT_TEST(test_sequence_steps_advance_on_owning_proof) ClusterPageSequenceResult r; /* A step outside its owning state is rejected (state unchanged). */ - r = cluster_page_apply_step_durability(CLUSTER_PAGE_STATE_MUTATED_IN_MEMORY, - true); - UT_ASSERT_EQ((int) r.state, - (int) CLUSTER_PAGE_STATE_MUTATED_IN_MEMORY); - UT_ASSERT_EQ((int) r.outcome, (int) CLUSTER_PAGE_OUTCOME_BLOCKED_CONTRIBUTOR); + r = cluster_page_apply_step_durability(CLUSTER_PAGE_STATE_MUTATED_IN_MEMORY, true); + UT_ASSERT_EQ((int)r.state, (int)CLUSTER_PAGE_STATE_MUTATED_IN_MEMORY); + UT_ASSERT_EQ((int)r.outcome, (int)CLUSTER_PAGE_OUTCOME_BLOCKED_CONTRIBUTOR); /* durability gate: fail -> BLOCKED_SOURCE, state unchanged. */ - r = cluster_page_apply_step_durability( - CLUSTER_PAGE_STATE_WAL_BEFORE_DATA_SATISFIED, false); - UT_ASSERT_EQ((int) r.state, - (int) CLUSTER_PAGE_STATE_WAL_BEFORE_DATA_SATISFIED); - UT_ASSERT_EQ((int) r.outcome, (int) CLUSTER_PAGE_OUTCOME_BLOCKED_SOURCE); + r = cluster_page_apply_step_durability(CLUSTER_PAGE_STATE_WAL_BEFORE_DATA_SATISFIED, false); + UT_ASSERT_EQ((int)r.state, (int)CLUSTER_PAGE_STATE_WAL_BEFORE_DATA_SATISFIED); + UT_ASSERT_EQ((int)r.outcome, (int)CLUSTER_PAGE_OUTCOME_BLOCKED_SOURCE); /* durability ok -> PAGE_WRITE_DURABLE. */ - r = cluster_page_apply_step_durability( - CLUSTER_PAGE_STATE_WAL_BEFORE_DATA_SATISFIED, true); - UT_ASSERT_EQ((int) r.state, (int) CLUSTER_PAGE_STATE_PAGE_WRITE_DURABLE); + r = cluster_page_apply_step_durability(CLUSTER_PAGE_STATE_WAL_BEFORE_DATA_SATISFIED, true); + UT_ASSERT_EQ((int)r.state, (int)CLUSTER_PAGE_STATE_PAGE_WRITE_DURABLE); /* PU-30: post-read wrong version/checksum -> CORRUPTION_VERSION, no * proof/release. */ - r = cluster_page_apply_step_post_read(CLUSTER_PAGE_STATE_PAGE_WRITE_DURABLE, - false); - UT_ASSERT_EQ((int) r.state, (int) CLUSTER_PAGE_STATE_PAGE_WRITE_DURABLE); - UT_ASSERT_EQ((int) r.outcome, (int) CLUSTER_PAGE_OUTCOME_CORRUPTION_VERSION); + r = cluster_page_apply_step_post_read(CLUSTER_PAGE_STATE_PAGE_WRITE_DURABLE, false); + UT_ASSERT_EQ((int)r.state, (int)CLUSTER_PAGE_STATE_PAGE_WRITE_DURABLE); + UT_ASSERT_EQ((int)r.outcome, (int)CLUSTER_PAGE_OUTCOME_CORRUPTION_VERSION); - r = cluster_page_apply_step_post_read(CLUSTER_PAGE_STATE_PAGE_WRITE_DURABLE, - true); - UT_ASSERT_EQ((int) r.state, (int) CLUSTER_PAGE_STATE_POST_READ_VERIFIED); + r = cluster_page_apply_step_post_read(CLUSTER_PAGE_STATE_PAGE_WRITE_DURABLE, true); + UT_ASSERT_EQ((int)r.state, (int)CLUSTER_PAGE_STATE_POST_READ_VERIFIED); /* PU-29: stale authority before release -> STALE_AUTHORITY, no * release. */ - r = cluster_page_apply_step_authority(CLUSTER_PAGE_STATE_POST_READ_VERIFIED, - false); - UT_ASSERT_EQ((int) r.state, (int) CLUSTER_PAGE_STATE_POST_READ_VERIFIED); - UT_ASSERT_EQ((int) r.outcome, (int) CLUSTER_PAGE_OUTCOME_STALE_AUTHORITY); + r = cluster_page_apply_step_authority(CLUSTER_PAGE_STATE_POST_READ_VERIFIED, false); + UT_ASSERT_EQ((int)r.state, (int)CLUSTER_PAGE_STATE_POST_READ_VERIFIED); + UT_ASSERT_EQ((int)r.outcome, (int)CLUSTER_PAGE_OUTCOME_STALE_AUTHORITY); - r = cluster_page_apply_step_authority(CLUSTER_PAGE_STATE_POST_READ_VERIFIED, - true); - UT_ASSERT_EQ((int) r.state, (int) CLUSTER_PAGE_STATE_RESOURCE_RELEASED); + r = cluster_page_apply_step_authority(CLUSTER_PAGE_STATE_POST_READ_VERIFIED, true); + UT_ASSERT_EQ((int)r.state, (int)CLUSTER_PAGE_STATE_RESOURCE_RELEASED); } UT_TEST(test_midwrite_cut_is_permanent_stop) @@ -136,40 +127,35 @@ UT_TEST(test_midwrite_cut_is_permanent_stop) /* PL-03 / §7.6: the repeated-recoverer target-write cut is a * permanent RED/STOP — never SKIP, never an expected-failure green, * never a mock carrier. */ - UT_ASSERT_EQ((int) cluster_page_apply_midwrite_cut(), - (int) CLUSTER_PAGE_OUTCOME_STABLE_BASE_UNRESOLVED); - UT_ASSERT_EQ((int) cluster_page_apply_midwrite_cut(), - (int) CLUSTER_PAGE_OUTCOME_STABLE_BASE_UNRESOLVED); + UT_ASSERT_EQ((int)cluster_page_apply_midwrite_cut(), + (int)CLUSTER_PAGE_OUTCOME_STABLE_BASE_UNRESOLVED); + UT_ASSERT_EQ((int)cluster_page_apply_midwrite_cut(), + (int)CLUSTER_PAGE_OUTCOME_STABLE_BASE_UNRESOLVED); } UT_TEST(test_crash_matrix_rows) { /* §7.7: all seven rows, exactly one outcome each. */ - UT_ASSERT_EQ((int) cluster_page_crash_matrix_verdict( - CLUSTER_PAGE_CUT_BEFORE_SOURCE_PROOF), - (int) CLUSTER_PAGE_OUTCOME_BLOCKED_SOURCE); - UT_ASSERT_EQ((int) cluster_page_crash_matrix_verdict( - CLUSTER_PAGE_CUT_AFTER_SOURCE_PROOF), - (int) CLUSTER_PAGE_OUTCOME_BLOCKED_SOURCE); - UT_ASSERT_EQ((int) cluster_page_crash_matrix_verdict( - CLUSTER_PAGE_CUT_DURING_TARGET_WRITE), - (int) CLUSTER_PAGE_OUTCOME_STABLE_BASE_UNRESOLVED); - UT_ASSERT_EQ((int) cluster_page_crash_matrix_verdict( - CLUSTER_PAGE_CUT_AFTER_WRITE_BEFORE_DURABILITY), - (int) CLUSTER_PAGE_OUTCOME_BLOCKED_SOURCE); - UT_ASSERT_EQ((int) cluster_page_crash_matrix_verdict( - CLUSTER_PAGE_CUT_AFTER_DURABILITY_BEFORE_POST_READ), - (int) CLUSTER_PAGE_OUTCOME_BLOCKED_SOURCE); - UT_ASSERT_EQ((int) cluster_page_crash_matrix_verdict( - CLUSTER_PAGE_CUT_AFTER_POST_READ_BEFORE_RELEASE), - (int) CLUSTER_PAGE_OUTCOME_STALE_AUTHORITY); - UT_ASSERT_EQ((int) cluster_page_crash_matrix_verdict( - CLUSTER_PAGE_CUT_AFTER_RELEASE), - (int) CLUSTER_PAGE_OUTCOME_APPLY); + UT_ASSERT_EQ((int)cluster_page_crash_matrix_verdict(CLUSTER_PAGE_CUT_BEFORE_SOURCE_PROOF), + (int)CLUSTER_PAGE_OUTCOME_BLOCKED_SOURCE); + UT_ASSERT_EQ((int)cluster_page_crash_matrix_verdict(CLUSTER_PAGE_CUT_AFTER_SOURCE_PROOF), + (int)CLUSTER_PAGE_OUTCOME_BLOCKED_SOURCE); + UT_ASSERT_EQ((int)cluster_page_crash_matrix_verdict(CLUSTER_PAGE_CUT_DURING_TARGET_WRITE), + (int)CLUSTER_PAGE_OUTCOME_STABLE_BASE_UNRESOLVED); + UT_ASSERT_EQ( + (int)cluster_page_crash_matrix_verdict(CLUSTER_PAGE_CUT_AFTER_WRITE_BEFORE_DURABILITY), + (int)CLUSTER_PAGE_OUTCOME_BLOCKED_SOURCE); + UT_ASSERT_EQ( + (int)cluster_page_crash_matrix_verdict(CLUSTER_PAGE_CUT_AFTER_DURABILITY_BEFORE_POST_READ), + (int)CLUSTER_PAGE_OUTCOME_BLOCKED_SOURCE); + UT_ASSERT_EQ( + (int)cluster_page_crash_matrix_verdict(CLUSTER_PAGE_CUT_AFTER_POST_READ_BEFORE_RELEASE), + (int)CLUSTER_PAGE_OUTCOME_STALE_AUTHORITY); + UT_ASSERT_EQ((int)cluster_page_crash_matrix_verdict(CLUSTER_PAGE_CUT_AFTER_RELEASE), + (int)CLUSTER_PAGE_OUTCOME_APPLY); /* Unknown cut: fail closed. */ - UT_ASSERT_EQ((int) cluster_page_crash_matrix_verdict( - (ClusterPageCrashCut) 99), - (int) CLUSTER_PAGE_OUTCOME_BLOCKED_CLASS); + UT_ASSERT_EQ((int)cluster_page_crash_matrix_verdict((ClusterPageCrashCut)99), + (int)CLUSTER_PAGE_OUTCOME_BLOCKED_CLASS); } UT_TEST(test_proof_surface_fields) @@ -184,13 +170,13 @@ UT_TEST(test_proof_surface_fields) p.durability_barrier_ok = true; p.post_read_ok = true; p.authority_revalidated = true; - UT_ASSERT_EQ((int) p.failed_origin_thread, 2); - UT_ASSERT_EQ((int) p.page_class, (int) CLUSTER_PAGE_CLASS_NORMAL); - UT_ASSERT(p.contributor_coverage && p.durability_barrier_ok - && p.post_read_ok && p.authority_revalidated); + UT_ASSERT_EQ((int)p.failed_origin_thread, 2); + UT_ASSERT_EQ((int)p.page_class, (int)CLUSTER_PAGE_CLASS_NORMAL); + UT_ASSERT(p.contributor_coverage && p.durability_barrier_ok && p.post_read_ok + && p.authority_revalidated); /* A proof without the post-read result is not a proof: the caller * must fail to produce it (field-level contract, PU-30). */ - UT_ASSERT_EQ((unsigned long long) p.post_read_version.token, 0ULL); + UT_ASSERT_EQ((unsigned long long)p.post_read_version.token, 0ULL); } /* STOP-06 product TDD (implementation): the §7.2 mutation chain @@ -222,24 +208,23 @@ UT_TEST(test_mutation_chain_full_sequence) /* Full §7.2 chain: WAL-before-data -> durability barrier -> canonical * post-read -> fresh authority -> released. */ - r = cluster_page_apply_step_durability( - CLUSTER_PAGE_STATE_WAL_BEFORE_DATA_SATISFIED, true); - UT_ASSERT_EQ((int) r.state, (int) CLUSTER_PAGE_STATE_PAGE_WRITE_DURABLE); - UT_ASSERT_EQ((int) r.outcome, (int) CLUSTER_PAGE_OUTCOME_APPLY); + r = cluster_page_apply_step_durability(CLUSTER_PAGE_STATE_WAL_BEFORE_DATA_SATISFIED, true); + UT_ASSERT_EQ((int)r.state, (int)CLUSTER_PAGE_STATE_PAGE_WRITE_DURABLE); + UT_ASSERT_EQ((int)r.outcome, (int)CLUSTER_PAGE_OUTCOME_APPLY); r = cluster_page_apply_step_post_read(r.state, true); - UT_ASSERT_EQ((int) r.state, (int) CLUSTER_PAGE_STATE_POST_READ_VERIFIED); + UT_ASSERT_EQ((int)r.state, (int)CLUSTER_PAGE_STATE_POST_READ_VERIFIED); r = cluster_page_apply_step_authority(r.state, true); - UT_ASSERT_EQ((int) r.state, (int) CLUSTER_PAGE_STATE_RESOURCE_RELEASED); - UT_ASSERT_EQ((int) r.outcome, (int) CLUSTER_PAGE_OUTCOME_APPLY); + UT_ASSERT_EQ((int)r.state, (int)CLUSTER_PAGE_STATE_RESOURCE_RELEASED); + UT_ASSERT_EQ((int)r.outcome, (int)CLUSTER_PAGE_OUTCOME_APPLY); /* STOP gate at chain level (PL-03 / §7.6): the mid-write cut is a * permanent wedge — the chain outcome is STABLE_BASE_UNRESOLVED and * no step may be attempted past it (mutation = 0 while the STOP * holds; U-SIDE-18: no config/test override exists). */ - UT_ASSERT_EQ((int) cluster_page_apply_midwrite_cut(), - (int) CLUSTER_PAGE_OUTCOME_STABLE_BASE_UNRESOLVED); - UT_ASSERT_EQ((int) cluster_page_apply_midwrite_cut(), - (int) CLUSTER_PAGE_OUTCOME_STABLE_BASE_UNRESOLVED); + UT_ASSERT_EQ((int)cluster_page_apply_midwrite_cut(), + (int)CLUSTER_PAGE_OUTCOME_STABLE_BASE_UNRESOLVED); + UT_ASSERT_EQ((int)cluster_page_apply_midwrite_cut(), + (int)CLUSTER_PAGE_OUTCOME_STABLE_BASE_UNRESOLVED); } int diff --git a/src/test/cluster_unit/test_cluster_page_authority.c b/src/test/cluster_unit/test_cluster_page_authority.c index 8420965d984..6b7cc2b8bc3 100644 --- a/src/test/cluster_unit/test_cluster_page_authority.c +++ b/src/test/cluster_unit/test_cluster_page_authority.c @@ -21,11 +21,9 @@ UT_DEFINE_GLOBALS(); void -ExceptionalCondition(const char *condition_name, const char *file_name, - int line_number) +ExceptionalCondition(const char *condition_name, const char *file_name, int line_number) { - printf("# unexpected Assert: %s at %s:%d\n", condition_name, file_name, - line_number); + printf("# unexpected Assert: %s at %s:%d\n", condition_name, file_name, line_number); abort(); } @@ -65,39 +63,31 @@ static bool pin_current; static bool stable_proof_current; static ClusterRecoverySerialRevalidateResult serial_result; -#define FORMATION ((const ClusterFormationWitnessV1 *) &formation_object) -#define NEEDS ((const PgracExternalFenceNeedSetV1 *) &needs_object) -#define ADMISSIONS ((const PgracExternalFenceAdmissionSetV1 *) &admissions_object) -#define PIN ((ClusterWalRetentionPin *) &pin_object) +#define FORMATION ((const ClusterFormationWitnessV1 *)&formation_object) +#define NEEDS ((const PgracExternalFenceNeedSetV1 *)&needs_object) +#define ADMISSIONS ((const PgracExternalFenceAdmissionSetV1 *)&admissions_object) +#define PIN ((ClusterWalRetentionPin *)&pin_object) #define ROOT_TOKENS (root_tokens) #define DUTIES (duty_objects) bool rf_page_stable_base_proof_matches_v1( - const RfPageStableBaseProofV1 *proof, - const RfPageIdentityV1 *page_identity, - const RfPageVersionV1 *expected_result, - const ClusterRecoveryDutyKey *duties, - const ClusterControlRootReadToken *roots, - const ClusterFormationWitnessV1 *formation, + const RfPageStableBaseProofV1 *proof, const RfPageIdentityV1 *page_identity, + const RfPageVersionV1 *expected_result, const ClusterRecoveryDutyKey *duties, + const ClusterControlRootReadToken *roots, const ClusterFormationWitnessV1 *formation, const PgracExternalFenceNeedSetV1 *needs, - const PgracExternalFenceAdmissionSetV1 *fence_admissions, - ClusterWalRetentionPin *pin, - const RfPagePinnedSourceV1 *source, - const RfContributorVectorV1 *contributors, + const PgracExternalFenceAdmissionSetV1 *fence_admissions, ClusterWalRetentionPin *pin, + const RfPagePinnedSourceV1 *source, const RfContributorVectorV1 *contributors, uint32 participant_count) { int index = -1; int i; - if (!stable_proof_current || duties != DUTIES || roots != ROOT_TOKENS || - formation != FORMATION || needs != NEEDS || - fence_admissions != ADMISSIONS || pin != PIN || - participant_count != 1) + if (!stable_proof_current || duties != DUTIES || roots != ROOT_TOKENS || formation != FORMATION + || needs != NEEDS || fence_admissions != ADMISSIONS || pin != PIN || participant_count != 1) return false; for (i = 0; i < TEST_AUTHORITY_TARGETS; i++) - if (proof == (const RfPageStableBaseProofV1 *) &stable_proof_objects[i]) - { + if (proof == (const RfPageStableBaseProofV1 *)&stable_proof_objects[i]) { index = i; break; } @@ -105,24 +95,23 @@ rf_page_stable_base_proof_matches_v1( return false; if (contributors != &vector_objects[index]) return false; - return page_identity != NULL && page_identity->blockno == (uint32) index + 1 && - expected_result != NULL && expected_result->mutation_token == - (uint64) index + 101 && - memcmp(expected_result->segment_incarnation, - (const uint8[16]) {7, 7, 7, 7, 7, 7, 7, 7, - 7, 7, 7, 7, 7, 7, 7, 7}, 16) == 0 && - source == &source_objects[index]; + return page_identity != NULL && page_identity->blockno == (uint32)index + 1 + && expected_result != NULL && expected_result->mutation_token == (uint64)index + 101 + && memcmp(expected_result->segment_incarnation, + (const uint8[16]){ 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7 }, 16) + == 0 + && source == &source_objects[index]; } ClusterRecoveryDutyCompare cluster_recovery_duty_key_compare(const ClusterRecoveryDutyKey *expected, const ClusterRecoveryDutyKey *observed) { - return expected == &DUTIES[0] && observed != NULL && - observed->origin_thread_id == DUTIES[0].origin_thread_id && - observed->root_lineage_seq == DUTIES[0].root_lineage_seq ? - CLUSTER_RECOVERY_DUTY_COMPARE_EXACT : - CLUSTER_RECOVERY_DUTY_COMPARE_DIFFERENT; + return expected == &DUTIES[0] && observed != NULL + && observed->origin_thread_id == DUTIES[0].origin_thread_id + && observed->root_lineage_seq == DUTIES[0].root_lineage_seq + ? CLUSTER_RECOVERY_DUTY_COMPARE_EXACT + : CLUSTER_RECOVERY_DUTY_COMPARE_DIFFERENT; } ClusterRecoverySerialRevalidateResult @@ -132,36 +121,33 @@ cluster_recovery_serial_revalidate(ClusterRecoverySerialGuard *guard) } bool -cluster_external_fence_need_set_revalidate_nowait( - const PgracExternalFenceNeedSetV1 *needs, - const ClusterFormationWitnessV1 *formation, - PgracExternalFenceDenyReason *reason) +cluster_external_fence_need_set_revalidate_nowait(const PgracExternalFenceNeedSetV1 *needs, + const ClusterFormationWitnessV1 *formation, + PgracExternalFenceDenyReason *reason) { if (reason != NULL) - *reason = fence_need_current ? PGRAC_EXTERNAL_FENCE_DENY_NONE : - PGRAC_EXTERNAL_FENCE_DENY_BINDING_MISMATCH; + *reason = fence_need_current ? PGRAC_EXTERNAL_FENCE_DENY_NONE + : PGRAC_EXTERNAL_FENCE_DENY_BINDING_MISMATCH; return needs == NEEDS && formation == FORMATION && fence_need_current; } bool -cluster_external_fence_revalidate_set_nowait( - const PgracExternalFenceAdmissionSetV1 *admissions, - const PgracExternalFenceNeedSetV1 *needs, - const ClusterFormationWitnessV1 *formation, - PgracExternalFenceDenyReason *reason) +cluster_external_fence_revalidate_set_nowait(const PgracExternalFenceAdmissionSetV1 *admissions, + const PgracExternalFenceNeedSetV1 *needs, + const ClusterFormationWitnessV1 *formation, + PgracExternalFenceDenyReason *reason) { if (reason != NULL) - *reason = fence_admission_current ? PGRAC_EXTERNAL_FENCE_DENY_NONE : - PGRAC_EXTERNAL_FENCE_DENY_EXPIRED; - return admissions == ADMISSIONS && needs == NEEDS && - formation == FORMATION && fence_admission_current; + *reason = fence_admission_current ? PGRAC_EXTERNAL_FENCE_DENY_NONE + : PGRAC_EXTERNAL_FENCE_DENY_EXPIRED; + return admissions == ADMISSIONS && needs == NEEDS && formation == FORMATION + && fence_admission_current; } ClusterWalPinResult cluster_wal_retention_pin_revalidate(ClusterWalRetentionPin *pin) { - return pin == PIN && pin_current ? CLUSTER_WAL_PIN_OK : - CLUSTER_WAL_PIN_STALE; + return pin == PIN && pin_current ? CLUSTER_WAL_PIN_OK : CLUSTER_WAL_PIN_STALE; } static RfPageIdentityV1 @@ -181,8 +167,7 @@ identity(uint32 blockno) } static void -init_case(RfPageAuthorityBatchRequestV1 *request, - RfPageAuthorityTargetV1 targets[2], +init_case(RfPageAuthorityBatchRequestV1 *request, RfPageAuthorityTargetV1 targets[2], ClusterRecoverySerialGuard *serial) { memset(request, 0, sizeof(*request)); @@ -194,10 +179,8 @@ init_case(RfPageAuthorityBatchRequestV1 *request, memset(targets[1].expected_result.segment_incarnation, 7, 16); targets[0].expected_result.mutation_token = 101; targets[1].expected_result.mutation_token = 102; - targets[0].stable_base = - (const RfPageStableBaseProofV1 *) &stable_proof_objects[0]; - targets[1].stable_base = - (const RfPageStableBaseProofV1 *) &stable_proof_objects[1]; + targets[0].stable_base = (const RfPageStableBaseProofV1 *)&stable_proof_objects[0]; + targets[1].stable_base = (const RfPageStableBaseProofV1 *)&stable_proof_objects[1]; targets[0].source = &source_objects[0]; targets[1].source = &source_objects[1]; targets[0].contributors = &vector_objects[0]; @@ -219,8 +202,7 @@ init_case(RfPageAuthorityBatchRequestV1 *request, memset(ROOT_TOKENS, 0, sizeof(root_tokens)); DUTIES[0].origin_thread_id = 1; DUTIES[0].root_lineage_seq = 91; - memset(ROOT_TOKENS[0].authority_uuid, 0x31, - sizeof(ROOT_TOKENS[0].authority_uuid)); + memset(ROOT_TOKENS[0].authority_uuid, 0x31, sizeof(ROOT_TOKENS[0].authority_uuid)); ROOT_TOKENS[0].origin_thread_id = 1; ROOT_TOKENS[0].lifecycle = CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_REQUIRED; ROOT_TOKENS[0].root_lineage_seq = 91; @@ -246,12 +228,12 @@ UT_TEST(test_exact_owner_set_promotes_and_revalidates) RfPageAuthorityGuardV1 *guard = NULL; init_case(&request, targets, &serial); - UT_ASSERT_EQ(rf_page_authority_batch_preflight_wait_v1( - &request, 1000, &preflight), RF_PAGE_AUTHORITY_OK); - UT_ASSERT_EQ(rf_page_authority_batch_promote_nowait_v1( - preflight, &serial, &guard), RF_PAGE_AUTHORITY_OK); - UT_ASSERT_EQ(rf_page_authority_batch_revalidate_nowait_v1( - guard, &serial), RF_PAGE_AUTHORITY_OK); + UT_ASSERT_EQ(rf_page_authority_batch_preflight_wait_v1(&request, 1000, &preflight), + RF_PAGE_AUTHORITY_OK); + UT_ASSERT_EQ(rf_page_authority_batch_promote_nowait_v1(preflight, &serial, &guard), + RF_PAGE_AUTHORITY_OK); + UT_ASSERT_EQ(rf_page_authority_batch_revalidate_nowait_v1(guard, &serial), + RF_PAGE_AUTHORITY_OK); rf_page_authority_guard_release_v1(&guard); rf_page_authority_preflight_destroy_v1(&preflight); UT_ASSERT(guard == NULL && preflight == NULL); @@ -264,27 +246,25 @@ UT_TEST(test_batch_target_set_is_not_limited_by_record_components) ClusterRecoverySerialGuard serial; RfPageAuthorityPreflightV1 *preflight = NULL; RfPageAuthorityGuardV1 *guard = NULL; - uint32 i; + uint32 i; init_case(&request, targets, &serial); - for (i = 2; i < TEST_AUTHORITY_TARGETS; i++) - { + for (i = 2; i < TEST_AUTHORITY_TARGETS; i++) { targets[i].page_identity = identity(i + 1); memset(targets[i].expected_result.segment_incarnation, 7, 16); targets[i].expected_result.mutation_token = i + 101; - targets[i].stable_base = - (const RfPageStableBaseProofV1 *) &stable_proof_objects[i]; + targets[i].stable_base = (const RfPageStableBaseProofV1 *)&stable_proof_objects[i]; targets[i].source = &source_objects[i]; targets[i].contributors = &vector_objects[i]; } request.target_count = TEST_AUTHORITY_TARGETS; rf_page_guard_shmem_init_v1(); - UT_ASSERT_EQ(rf_page_authority_batch_preflight_wait_v1( - &request, 1000, &preflight), RF_PAGE_AUTHORITY_OK); - UT_ASSERT_EQ(rf_page_authority_batch_promote_nowait_v1( - preflight, &serial, &guard), RF_PAGE_AUTHORITY_OK); - UT_ASSERT_EQ(rf_page_authority_batch_revalidate_nowait_v1( - guard, &serial), RF_PAGE_AUTHORITY_OK); + UT_ASSERT_EQ(rf_page_authority_batch_preflight_wait_v1(&request, 1000, &preflight), + RF_PAGE_AUTHORITY_OK); + UT_ASSERT_EQ(rf_page_authority_batch_promote_nowait_v1(preflight, &serial, &guard), + RF_PAGE_AUTHORITY_OK); + UT_ASSERT_EQ(rf_page_authority_batch_revalidate_nowait_v1(guard, &serial), + RF_PAGE_AUTHORITY_OK); rf_page_authority_guard_release_v1(&guard); rf_page_authority_preflight_destroy_v1(&preflight); } @@ -298,8 +278,8 @@ UT_TEST(test_missing_live_stop04_object_is_invalid) init_case(&request, targets, &serial); request.fence_need_set = NULL; - UT_ASSERT_EQ(rf_page_authority_batch_preflight_wait_v1( - &request, 1000, &preflight), RF_PAGE_AUTHORITY_INVALID_ARGUMENT); + UT_ASSERT_EQ(rf_page_authority_batch_preflight_wait_v1(&request, 1000, &preflight), + RF_PAGE_AUTHORITY_INVALID_ARGUMENT); UT_ASSERT(preflight == NULL); } @@ -312,12 +292,11 @@ UT_TEST(test_serial_pointer_identity_mismatch_is_fence_stale) RfPageAuthorityGuardV1 *guard = NULL; init_case(&request, targets, &serial); - UT_ASSERT_EQ(rf_page_authority_batch_preflight_wait_v1( - &request, 1000, &preflight), RF_PAGE_AUTHORITY_OK); - serial.fence_admission_set = (const PgracExternalFenceAdmissionSetV1 *) - &pin_object; - UT_ASSERT_EQ(rf_page_authority_batch_promote_nowait_v1( - preflight, &serial, &guard), RF_PAGE_AUTHORITY_FENCE_STALE); + UT_ASSERT_EQ(rf_page_authority_batch_preflight_wait_v1(&request, 1000, &preflight), + RF_PAGE_AUTHORITY_OK); + serial.fence_admission_set = (const PgracExternalFenceAdmissionSetV1 *)&pin_object; + UT_ASSERT_EQ(rf_page_authority_batch_promote_nowait_v1(preflight, &serial, &guard), + RF_PAGE_AUTHORITY_FENCE_STALE); UT_ASSERT(guard == NULL); rf_page_authority_preflight_destroy_v1(&preflight); } @@ -331,15 +310,15 @@ UT_TEST(test_fence_stale_blocks_before_page_promote) RfPageAuthorityGuardV1 *guard = NULL; init_case(&request, targets, &serial); - UT_ASSERT_EQ(rf_page_authority_batch_preflight_wait_v1( - &request, 1000, &preflight), RF_PAGE_AUTHORITY_OK); + UT_ASSERT_EQ(rf_page_authority_batch_preflight_wait_v1(&request, 1000, &preflight), + RF_PAGE_AUTHORITY_OK); fence_admission_current = false; - UT_ASSERT_EQ(rf_page_authority_batch_promote_nowait_v1( - preflight, &serial, &guard), RF_PAGE_AUTHORITY_FENCE_STALE); + UT_ASSERT_EQ(rf_page_authority_batch_promote_nowait_v1(preflight, &serial, &guard), + RF_PAGE_AUTHORITY_FENCE_STALE); UT_ASSERT(guard == NULL); fence_admission_current = true; - UT_ASSERT_EQ(rf_page_authority_batch_promote_nowait_v1( - preflight, &serial, &guard), RF_PAGE_AUTHORITY_OK); + UT_ASSERT_EQ(rf_page_authority_batch_promote_nowait_v1(preflight, &serial, &guard), + RF_PAGE_AUTHORITY_OK); rf_page_authority_guard_release_v1(&guard); rf_page_authority_preflight_destroy_v1(&preflight); } @@ -358,17 +337,15 @@ UT_TEST(test_page_conflict_releases_already_promoted_partition) init_case(&request, targets, &serial); rf_page_guard_shmem_init_v1(); - UT_ASSERT(rf_page_guard_preflight_v1(&targets[1].page_identity, - &blocker_preflight)); + UT_ASSERT(rf_page_guard_preflight_v1(&targets[1].page_identity, &blocker_preflight)); memset(&blocker, 0, sizeof(blocker)); UT_ASSERT(rf_page_guard_promote_nowait_v1(&blocker_preflight, &blocker)); - UT_ASSERT_EQ(rf_page_authority_batch_preflight_wait_v1( - &request, 1000, &preflight), RF_PAGE_AUTHORITY_OK); - UT_ASSERT_EQ(rf_page_authority_batch_promote_nowait_v1( - preflight, &serial, &guard), RF_PAGE_AUTHORITY_WOULD_BLOCK); + UT_ASSERT_EQ(rf_page_authority_batch_preflight_wait_v1(&request, 1000, &preflight), + RF_PAGE_AUTHORITY_OK); + UT_ASSERT_EQ(rf_page_authority_batch_promote_nowait_v1(preflight, &serial, &guard), + RF_PAGE_AUTHORITY_WOULD_BLOCK); UT_ASSERT(guard == NULL); - UT_ASSERT(rf_page_guard_preflight_v1(&targets[0].page_identity, - &first_preflight)); + UT_ASSERT(rf_page_guard_preflight_v1(&targets[0].page_identity, &first_preflight)); memset(&first_probe, 0, sizeof(first_probe)); UT_ASSERT(rf_page_guard_promote_nowait_v1(&first_preflight, &first_probe)); rf_page_guard_release_v1(&first_probe); @@ -386,13 +363,13 @@ UT_TEST(test_stale_pin_after_promote_fails_revalidation) init_case(&request, targets, &serial); rf_page_guard_shmem_init_v1(); - UT_ASSERT_EQ(rf_page_authority_batch_preflight_wait_v1( - &request, 1000, &preflight), RF_PAGE_AUTHORITY_OK); - UT_ASSERT_EQ(rf_page_authority_batch_promote_nowait_v1( - preflight, &serial, &guard), RF_PAGE_AUTHORITY_OK); + UT_ASSERT_EQ(rf_page_authority_batch_preflight_wait_v1(&request, 1000, &preflight), + RF_PAGE_AUTHORITY_OK); + UT_ASSERT_EQ(rf_page_authority_batch_promote_nowait_v1(preflight, &serial, &guard), + RF_PAGE_AUTHORITY_OK); pin_current = false; - UT_ASSERT_EQ(rf_page_authority_batch_revalidate_nowait_v1( - guard, &serial), RF_PAGE_AUTHORITY_RETENTION_STALE); + UT_ASSERT_EQ(rf_page_authority_batch_revalidate_nowait_v1(guard, &serial), + RF_PAGE_AUTHORITY_RETENTION_STALE); rf_page_authority_guard_release_v1(&guard); rf_page_authority_preflight_destroy_v1(&preflight); } @@ -406,8 +383,8 @@ UT_TEST(test_missing_stable_proof_blocks_preflight) init_case(&request, targets, &serial); targets[0].stable_base = NULL; - UT_ASSERT_EQ(rf_page_authority_batch_preflight_wait_v1( - &request, 1000, &preflight), RF_PAGE_AUTHORITY_NO_STABLE_BASE); + UT_ASSERT_EQ(rf_page_authority_batch_preflight_wait_v1(&request, 1000, &preflight), + RF_PAGE_AUTHORITY_NO_STABLE_BASE); UT_ASSERT(preflight == NULL); } @@ -420,11 +397,11 @@ UT_TEST(test_stable_proof_drift_blocks_page_promotion) RfPageAuthorityGuardV1 *guard = NULL; init_case(&request, targets, &serial); - UT_ASSERT_EQ(rf_page_authority_batch_preflight_wait_v1( - &request, 1000, &preflight), RF_PAGE_AUTHORITY_OK); + UT_ASSERT_EQ(rf_page_authority_batch_preflight_wait_v1(&request, 1000, &preflight), + RF_PAGE_AUTHORITY_OK); stable_proof_current = false; - UT_ASSERT_EQ(rf_page_authority_batch_promote_nowait_v1( - preflight, &serial, &guard), RF_PAGE_AUTHORITY_NO_STABLE_BASE); + UT_ASSERT_EQ(rf_page_authority_batch_promote_nowait_v1(preflight, &serial, &guard), + RF_PAGE_AUTHORITY_NO_STABLE_BASE); UT_ASSERT(guard == NULL); rf_page_authority_preflight_destroy_v1(&preflight); } @@ -438,11 +415,11 @@ UT_TEST(test_serial_duty_mismatch_blocks_page_promotion) RfPageAuthorityGuardV1 *guard = NULL; init_case(&request, targets, &serial); - UT_ASSERT_EQ(rf_page_authority_batch_preflight_wait_v1( - &request, 1000, &preflight), RF_PAGE_AUTHORITY_OK); + UT_ASSERT_EQ(rf_page_authority_batch_preflight_wait_v1(&request, 1000, &preflight), + RF_PAGE_AUTHORITY_OK); serial.duty.root_lineage_seq++; - UT_ASSERT_EQ(rf_page_authority_batch_promote_nowait_v1( - preflight, &serial, &guard), RF_PAGE_AUTHORITY_GENERATION_STALE); + UT_ASSERT_EQ(rf_page_authority_batch_promote_nowait_v1(preflight, &serial, &guard), + RF_PAGE_AUTHORITY_GENERATION_STALE); UT_ASSERT(guard == NULL); rf_page_authority_preflight_destroy_v1(&preflight); } @@ -456,11 +433,11 @@ UT_TEST(test_serial_root_token_mismatch_blocks_page_promotion) RfPageAuthorityGuardV1 *guard = NULL; init_case(&request, targets, &serial); - UT_ASSERT_EQ(rf_page_authority_batch_preflight_wait_v1( - &request, 1000, &preflight), RF_PAGE_AUTHORITY_OK); + UT_ASSERT_EQ(rf_page_authority_batch_preflight_wait_v1(&request, 1000, &preflight), + RF_PAGE_AUTHORITY_OK); serial.root_read_token.root_publish_seq++; - UT_ASSERT_EQ(rf_page_authority_batch_promote_nowait_v1( - preflight, &serial, &guard), RF_PAGE_AUTHORITY_ROOT_STALE); + UT_ASSERT_EQ(rf_page_authority_batch_promote_nowait_v1(preflight, &serial, &guard), + RF_PAGE_AUTHORITY_ROOT_STALE); UT_ASSERT(guard == NULL); rf_page_authority_preflight_destroy_v1(&preflight); } @@ -475,18 +452,17 @@ UT_TEST(test_identity_and_incarnation_are_exact) uint8 incarnation[16]; init_case(&request, targets, &serial); - UT_ASSERT_EQ(rf_page_authority_batch_preflight_wait_v1( - &request, 1000, &preflight), RF_PAGE_AUTHORITY_OK); + UT_ASSERT_EQ(rf_page_authority_batch_preflight_wait_v1(&request, 1000, &preflight), + RF_PAGE_AUTHORITY_OK); memset(incarnation, 7, sizeof(incarnation)); - UT_ASSERT(rf_page_authority_preflight_matches_target_v1(preflight, - &targets[0].page_identity, incarnation)); + UT_ASSERT(rf_page_authority_preflight_matches_target_v1(preflight, &targets[0].page_identity, + incarnation)); other = targets[0].page_identity; other.blockno = 3; - UT_ASSERT(!rf_page_authority_preflight_matches_target_v1(preflight, - &other, incarnation)); + UT_ASSERT(!rf_page_authority_preflight_matches_target_v1(preflight, &other, incarnation)); incarnation[0]++; - UT_ASSERT(!rf_page_authority_preflight_matches_target_v1(preflight, - &targets[0].page_identity, incarnation)); + UT_ASSERT(!rf_page_authority_preflight_matches_target_v1(preflight, &targets[0].page_identity, + incarnation)); rf_page_authority_preflight_destroy_v1(&preflight); } @@ -500,13 +476,11 @@ UT_TEST(test_install_adapter_runs_promote_publish_release) init_case(&request, targets, &serial); rf_page_guard_shmem_init_v1(); - UT_ASSERT_EQ(rf_page_authority_batch_preflight_wait_v1( - &request, 1000, &preflight), RF_PAGE_AUTHORITY_OK); - UT_ASSERT(rf_page_install_authority_adapter_init_v1( - preflight, &serial, &adapter)); - UT_ASSERT(adapter.ops.validate_identity(adapter.ops.arg, - &targets[0].page_identity, - targets[0].expected_result.segment_incarnation)); + UT_ASSERT_EQ(rf_page_authority_batch_preflight_wait_v1(&request, 1000, &preflight), + RF_PAGE_AUTHORITY_OK); + UT_ASSERT(rf_page_install_authority_adapter_init_v1(preflight, &serial, &adapter)); + UT_ASSERT(adapter.ops.validate_identity(adapter.ops.arg, &targets[0].page_identity, + targets[0].expected_result.segment_incarnation)); UT_ASSERT(adapter.ops.promote(adapter.ops.arg)); UT_ASSERT(adapter.ops.publish(adapter.ops.arg)); UT_ASSERT(adapter.ops.release(adapter.ops.arg)); diff --git a/src/test/cluster_unit/test_cluster_page_detached.c b/src/test/cluster_unit/test_cluster_page_detached.c index fcb7b7c9177..ac15dd87437 100644 --- a/src/test/cluster_unit/test_cluster_page_detached.c +++ b/src/test/cluster_unit/test_cluster_page_detached.c @@ -27,11 +27,9 @@ UT_DEFINE_GLOBALS(); void -ExceptionalCondition(const char *condition_name, const char *file_name, - int line_number) +ExceptionalCondition(const char *condition_name, const char *file_name, int line_number) { - printf("# unexpected Assert: %s at %s:%d\n", condition_name, file_name, - line_number); + printf("# unexpected Assert: %s at %s:%d\n", condition_name, file_name, line_number); abort(); } @@ -63,8 +61,8 @@ int cluster_node_id = 0; bool rf_page_version_present_v1(const RfPageVersionV1 *version) { - uint8 value = 0; - int i; + uint8 value = 0; + int i; if (version == NULL || version->mutation_token == 0) return false; @@ -79,7 +77,7 @@ static bool restore_ok = true; bool RestoreBlockImage(XLogReaderState *record, uint8 block_id, char *page) { - PageHeader header = (PageHeader) page; + PageHeader header = (PageHeader)page; restore_calls++; if (!restore_ok) @@ -105,20 +103,17 @@ cluster_block_apply_heap(XLogReaderState *record, uint8 block_id, char *page) return CLUSTER_BLKAPPLY_UNSUPPORTED; } -typedef struct FakeRecord -{ +typedef struct FakeRecord { XLogReaderState state; - union - { + union { DecodedXLogRecord decoded; - char padding[sizeof(DecodedXLogRecord) + - XLR_PAGE_VERSION_EDGE_MAX_ENTRIES * sizeof(DecodedBkpBlock)]; + char padding[sizeof(DecodedXLogRecord) + + XLR_PAGE_VERSION_EDGE_MAX_ENTRIES * sizeof(DecodedBkpBlock)]; } storage; } FakeRecord; -typedef struct OwnerFixture -{ - int calls; +typedef struct OwnerFixture { + int calls; RfPageProofDetailV1 result; } OwnerFixture; @@ -129,8 +124,8 @@ set_incarnation(uint8 incarnation[16], uint8 value) } static XLogReaderState * -make_page_record(FakeRecord *record, uint8 rmid, uint8 info, - uint8 page_class, ForkNumber forknum, bool apply_image) +make_page_record(FakeRecord *record, uint8 rmid, uint8 info, uint8 page_class, ForkNumber forknum, + bool apply_image) { static char image[BLCKSZ]; DecodedXLogRecord *decoded; @@ -163,19 +158,17 @@ make_page_record(FakeRecord *record, uint8 rmid, uint8 info, edge->before.mutation_token = 21; set_incarnation(edge->result_incarnation, 7); if (apply_image) - edge->edge_flags = RF_PAGE_EDGE_FULL_IMAGE_APPLY | - RF_PAGE_EDGE_FULL_COVERAGE; + edge->edge_flags = RF_PAGE_EDGE_FULL_IMAGE_APPLY | RF_PAGE_EDGE_FULL_COVERAGE; record->state.record = decoded; record->state.EndRecPtr = 0x1234; return &record->state; } static RfPageProofDetailV1 -owner_preflight(void *arg, const RfOpcodeRouteV1 *route, - const RfPageVersionEdgeEntryV1 *edge, +owner_preflight(void *arg, const RfOpcodeRouteV1 *route, const RfPageVersionEdgeEntryV1 *edge, const DecodedBkpBlock *block) { - OwnerFixture *fixture = (OwnerFixture *) arg; + OwnerFixture *fixture = (OwnerFixture *)arg; fixture->calls++; return fixture->result; @@ -198,8 +191,7 @@ UT_TEST(test_every_page_route_has_exact_codec_vtable) { size_t i; - for (i = 0; i < rf_opcode_route_manifest_count_v1(); i++) - { + for (i = 0; i < rf_opcode_route_manifest_count_v1(); i++) { RfOpcodeRouteV1 route; const RfDetachedPageCodecV1 *codec; bool active; @@ -221,18 +213,16 @@ UT_TEST(test_ordinary_record_preflight_builds_immutable_plan) { FakeRecord record; RfDetachedRecordPlanV1 plan; - XLogReaderState *state = make_page_record(&record, RM_GENERIC_ID, 0, - RF_PAGE_CLASS_ORDINARY, MAIN_FORKNUM, true); + XLogReaderState *state + = make_page_record(&record, RM_GENERIC_ID, 0, RF_PAGE_CLASS_ORDINARY, MAIN_FORKNUM, true); memset(&plan, 0xa5, sizeof(plan)); - UT_ASSERT_EQ(rf_page_detached_preflight_v1(state, false, NULL, &plan), - RF_PAGE_PROOF_DETAIL_OK); + UT_ASSERT_EQ(rf_page_detached_preflight_v1(state, false, NULL, &plan), RF_PAGE_PROOF_DETAIL_OK); UT_ASSERT(plan.preflight_complete); UT_ASSERT_EQ(plan.component_count, 1); UT_ASSERT_EQ(plan.components[0].before_kind, RF_PAGE_STATE_PRESENT); UT_ASSERT_EQ(plan.components[0].result_kind, RF_PAGE_STATE_PRESENT); - UT_ASSERT_EQ(plan.components[0].owner, - RF_DETACHED_COMPONENT_PAGE_CODEC); + UT_ASSERT_EQ(plan.components[0].owner, RF_DETACHED_COMPONENT_PAGE_CODEC); UT_ASSERT_EQ(plan.components[0].block_id, 0); UT_ASSERT_EQ(plan.result_token, 22); } @@ -242,14 +232,14 @@ UT_TEST(test_missing_edge_fails_without_plan_exposure) FakeRecord record; RfDetachedRecordPlanV1 plan; RfDetachedRecordPlanV1 before; - XLogReaderState *state = make_page_record(&record, RM_GENERIC_ID, 0, - RF_PAGE_CLASS_ORDINARY, MAIN_FORKNUM, true); + XLogReaderState *state + = make_page_record(&record, RM_GENERIC_ID, 0, RF_PAGE_CLASS_ORDINARY, MAIN_FORKNUM, true); state->record->has_page_version_edge = false; memset(&plan, 0xa5, sizeof(plan)); before = plan; UT_ASSERT_EQ(rf_page_detached_preflight_v1(state, false, NULL, &plan), - RF_PAGE_PROOF_DETAIL_COMPONENT_INCOMPLETE); + RF_PAGE_PROOF_DETAIL_COMPONENT_INCOMPLETE); UT_ASSERT(memcmp(&plan, &before, sizeof(plan)) == 0); } @@ -257,75 +247,67 @@ UT_TEST(test_ordinary_wrong_fork_is_class_failure) { FakeRecord record; RfDetachedRecordPlanV1 plan; - XLogReaderState *state = make_page_record(&record, RM_GENERIC_ID, 0, - RF_PAGE_CLASS_ORDINARY, FSM_FORKNUM, true); + XLogReaderState *state + = make_page_record(&record, RM_GENERIC_ID, 0, RF_PAGE_CLASS_ORDINARY, FSM_FORKNUM, true); UT_ASSERT_EQ(rf_page_detached_preflight_v1(state, false, NULL, &plan), - RF_PAGE_PROOF_DETAIL_CLASS_UNKNOWN); + RF_PAGE_PROOF_DETAIL_CLASS_UNKNOWN); } UT_TEST(test_rebuildable_component_requires_owner_preflight) { FakeRecord record; RfDetachedRecordPlanV1 plan; - OwnerFixture fixture = {0, RF_PAGE_PROOF_DETAIL_OK}; + OwnerFixture fixture = { 0, RF_PAGE_PROOF_DETAIL_OK }; RfDetachedOwnerOpsV1 ops = make_owner_ops(&fixture); XLogReaderState *state = make_page_record(&record, RM_GENERIC_ID, 0, - RF_PAGE_CLASS_REBUILDABLE_FSM, FSM_FORKNUM, false); - RfPageVersionEdgeEntryV1 *edge = - &state->record->page_version_edge.entries[0]; + RF_PAGE_CLASS_REBUILDABLE_FSM, FSM_FORKNUM, false); + RfPageVersionEdgeEntryV1 *edge = &state->record->page_version_edge.entries[0]; memset(&edge->before, 0, sizeof(edge->before)); memset(edge->result_incarnation, 0, sizeof(edge->result_incarnation)); edge->before_kind = RF_PAGE_STATE_REBUILDABLE; edge->result_kind = RF_PAGE_STATE_REBUILDABLE; - UT_ASSERT_EQ(rf_page_detached_preflight_v1(state, false, &ops, &plan), - RF_PAGE_PROOF_DETAIL_OK); + UT_ASSERT_EQ(rf_page_detached_preflight_v1(state, false, &ops, &plan), RF_PAGE_PROOF_DETAIL_OK); UT_ASSERT_EQ(fixture.calls, 1); - UT_ASSERT_EQ(plan.components[0].owner, - RF_DETACHED_COMPONENT_REBUILDABLE); + UT_ASSERT_EQ(plan.components[0].owner, RF_DETACHED_COMPONENT_REBUILDABLE); } UT_TEST(test_space_component_requires_activation_and_typed_owner) { FakeRecord record; RfDetachedRecordPlanV1 plan; - OwnerFixture fixture = {0, RF_PAGE_PROOF_DETAIL_OK}; + OwnerFixture fixture = { 0, RF_PAGE_PROOF_DETAIL_OK }; RfDetachedOwnerOpsV1 ops = make_owner_ops(&fixture); - XLogReaderState *state = make_page_record(&record, RM_GENERIC_ID, 0, - RF_PAGE_CLASS_ROUTED_SPACE, (ForkNumber) 4, false); - RfPageVersionEdgeEntryV1 *edge = - &state->record->page_version_edge.entries[0]; + XLogReaderState *state = make_page_record(&record, RM_GENERIC_ID, 0, RF_PAGE_CLASS_ROUTED_SPACE, + (ForkNumber)4, false); + RfPageVersionEdgeEntryV1 *edge = &state->record->page_version_edge.entries[0]; memset(&edge->before, 0, sizeof(edge->before)); memset(edge->result_incarnation, 0, sizeof(edge->result_incarnation)); edge->before_kind = RF_PAGE_STATE_ROUTED; edge->result_kind = RF_PAGE_STATE_ROUTED; UT_ASSERT_EQ(rf_page_detached_preflight_v1(state, false, &ops, &plan), - RF_PAGE_PROOF_DETAIL_OPCODE_UNSUPPORTED); + RF_PAGE_PROOF_DETAIL_OPCODE_UNSUPPORTED); UT_ASSERT_EQ(fixture.calls, 0); - UT_ASSERT_EQ(rf_page_detached_preflight_v1(state, true, &ops, &plan), - RF_PAGE_PROOF_DETAIL_OK); + UT_ASSERT_EQ(rf_page_detached_preflight_v1(state, true, &ops, &plan), RF_PAGE_PROOF_DETAIL_OK); UT_ASSERT_EQ(fixture.calls, 1); - UT_ASSERT_EQ(plan.components[0].owner, - RF_DETACHED_COMPONENT_SIDE_TYPED); + UT_ASSERT_EQ(plan.components[0].owner, RF_DETACHED_COMPONENT_SIDE_TYPED); } UT_TEST(test_side_record_is_preflighted_by_typed_owner) { FakeRecord record; RfDetachedRecordPlanV1 plan; - OwnerFixture fixture = {0, RF_PAGE_PROOF_DETAIL_OK}; + OwnerFixture fixture = { 0, RF_PAGE_PROOF_DETAIL_OK }; RfDetachedOwnerOpsV1 ops = make_owner_ops(&fixture); - XLogReaderState *state = make_page_record(&record, RM_SMGR_ID, 0x10, - RF_PAGE_CLASS_ORDINARY, MAIN_FORKNUM, false); + XLogReaderState *state + = make_page_record(&record, RM_SMGR_ID, 0x10, RF_PAGE_CLASS_ORDINARY, MAIN_FORKNUM, false); state->record->max_block_id = -1; state->record->has_page_version_edge = false; - memset(&state->record->page_version_edge, 0, - sizeof(state->record->page_version_edge)); - UT_ASSERT_EQ(rf_page_detached_preflight_v1(state, false, &ops, &plan), - RF_PAGE_PROOF_DETAIL_OK); + memset(&state->record->page_version_edge, 0, sizeof(state->record->page_version_edge)); + UT_ASSERT_EQ(rf_page_detached_preflight_v1(state, false, &ops, &plan), RF_PAGE_PROOF_DETAIL_OK); UT_ASSERT_EQ(fixture.calls, 1); UT_ASSERT_EQ(plan.component_count, 0); UT_ASSERT(plan.preflight_complete); @@ -336,17 +318,17 @@ UT_TEST(test_owner_failure_blocks_whole_record_without_plan) FakeRecord record; RfDetachedRecordPlanV1 plan; RfDetachedRecordPlanV1 before; - OwnerFixture fixture = {0, RF_PAGE_PROOF_DETAIL_SIDE_INCOMPLETE}; + OwnerFixture fixture = { 0, RF_PAGE_PROOF_DETAIL_SIDE_INCOMPLETE }; RfDetachedOwnerOpsV1 ops = make_owner_ops(&fixture); - XLogReaderState *state = make_page_record(&record, RM_SMGR_ID, 0x10, - RF_PAGE_CLASS_ORDINARY, MAIN_FORKNUM, false); + XLogReaderState *state + = make_page_record(&record, RM_SMGR_ID, 0x10, RF_PAGE_CLASS_ORDINARY, MAIN_FORKNUM, false); state->record->max_block_id = -1; state->record->has_page_version_edge = false; memset(&plan, 0xa5, sizeof(plan)); before = plan; UT_ASSERT_EQ(rf_page_detached_preflight_v1(state, false, &ops, &plan), - RF_PAGE_PROOF_DETAIL_SIDE_INCOMPLETE); + RF_PAGE_PROOF_DETAIL_SIDE_INCOMPLETE); UT_ASSERT(memcmp(&plan, &before, sizeof(plan)) == 0); } @@ -356,19 +338,18 @@ UT_TEST(test_fpi_apply_stamps_successor_token) RfDetachedRecordPlanV1 plan; PGAlignedBlock old_page; PGAlignedBlock output; - XLogReaderState *state = make_page_record(&record, RM_GENERIC_ID, 0, - RF_PAGE_CLASS_ORDINARY, MAIN_FORKNUM, true); + XLogReaderState *state + = make_page_record(&record, RM_GENERIC_ID, 0, RF_PAGE_CLASS_ORDINARY, MAIN_FORKNUM, true); memset(old_page.data, 0, BLCKSZ); memset(output.data, 0xa5, BLCKSZ); restore_calls = 0; restore_ok = true; - UT_ASSERT_EQ(rf_page_detached_preflight_v1(state, false, NULL, &plan), - RF_PAGE_PROOF_DETAIL_OK); - UT_ASSERT_EQ(rf_page_detached_apply_v1(&plan, 0, old_page.data, - output.data), RF_PAGE_PROOF_DETAIL_OK); + UT_ASSERT_EQ(rf_page_detached_preflight_v1(state, false, NULL, &plan), RF_PAGE_PROOF_DETAIL_OK); + UT_ASSERT_EQ(rf_page_detached_apply_v1(&plan, 0, old_page.data, output.data), + RF_PAGE_PROOF_DETAIL_OK); UT_ASSERT_EQ(restore_calls, 1); - UT_ASSERT_EQ(((PageHeader) output.data)->pd_block_scn, 22); + UT_ASSERT_EQ(((PageHeader)output.data)->pd_block_scn, 22); } UT_TEST(test_unsupported_delta_leaves_output_untouched) @@ -378,19 +359,18 @@ UT_TEST(test_unsupported_delta_leaves_output_untouched) PGAlignedBlock old_page; PGAlignedBlock output; PGAlignedBlock before; - XLogReaderState *state = make_page_record(&record, RM_BTREE_ID, 0, - RF_PAGE_CLASS_ORDINARY, MAIN_FORKNUM, false); + XLogReaderState *state + = make_page_record(&record, RM_BTREE_ID, 0, RF_PAGE_CLASS_ORDINARY, MAIN_FORKNUM, false); memset(old_page.data, 0, BLCKSZ); - ((PageHeader) old_page.data)->pd_lower = SizeOfPageHeaderData; - ((PageHeader) old_page.data)->pd_upper = BLCKSZ; - ((PageHeader) old_page.data)->pd_special = BLCKSZ; + ((PageHeader)old_page.data)->pd_lower = SizeOfPageHeaderData; + ((PageHeader)old_page.data)->pd_upper = BLCKSZ; + ((PageHeader)old_page.data)->pd_special = BLCKSZ; memset(output.data, 0xa5, BLCKSZ); before = output; - UT_ASSERT_EQ(rf_page_detached_preflight_v1(state, false, NULL, &plan), - RF_PAGE_PROOF_DETAIL_OK); - UT_ASSERT_EQ(rf_page_detached_apply_v1(&plan, 0, old_page.data, - output.data), RF_PAGE_PROOF_DETAIL_OPCODE_UNSUPPORTED); + UT_ASSERT_EQ(rf_page_detached_preflight_v1(state, false, NULL, &plan), RF_PAGE_PROOF_DETAIL_OK); + UT_ASSERT_EQ(rf_page_detached_apply_v1(&plan, 0, old_page.data, output.data), + RF_PAGE_PROOF_DETAIL_OPCODE_UNSUPPORTED); UT_ASSERT(memcmp(output.data, before.data, BLCKSZ) == 0); } @@ -398,12 +378,11 @@ UT_TEST(test_component_ordinal_mismatch_blocks_before_owner) { FakeRecord record; RfDetachedRecordPlanV1 plan; - OwnerFixture fixture = {0, RF_PAGE_PROOF_DETAIL_OK}; + OwnerFixture fixture = { 0, RF_PAGE_PROOF_DETAIL_OK }; RfDetachedOwnerOpsV1 ops = make_owner_ops(&fixture); XLogReaderState *state = make_page_record(&record, RM_GENERIC_ID, 0, - RF_PAGE_CLASS_REBUILDABLE_FSM, FSM_FORKNUM, false); - RfPageVersionEdgeEntryV1 *edge = - &state->record->page_version_edge.entries[0]; + RF_PAGE_CLASS_REBUILDABLE_FSM, FSM_FORKNUM, false); + RfPageVersionEdgeEntryV1 *edge = &state->record->page_version_edge.entries[0]; memset(&edge->before, 0, sizeof(edge->before)); memset(edge->result_incarnation, 0, sizeof(edge->result_incarnation)); @@ -411,7 +390,7 @@ UT_TEST(test_component_ordinal_mismatch_blocks_before_owner) edge->result_kind = RF_PAGE_STATE_REBUILDABLE; edge->component_ordinal = 9; UT_ASSERT_EQ(rf_page_detached_preflight_v1(state, false, &ops, &plan), - RF_PAGE_PROOF_DETAIL_COMPONENT_INCOMPLETE); + RF_PAGE_PROOF_DETAIL_COMPONENT_INCOMPLETE); UT_ASSERT_EQ(fixture.calls, 0); } diff --git a/src/test/cluster_unit/test_cluster_page_edge.c b/src/test/cluster_unit/test_cluster_page_edge.c index d74a6bdf30c..db3e0fa6f6a 100644 --- a/src/test/cluster_unit/test_cluster_page_edge.c +++ b/src/test/cluster_unit/test_cluster_page_edge.c @@ -14,11 +14,9 @@ UT_DEFINE_GLOBALS(); void -ExceptionalCondition(const char *condition_name, const char *file_name, - int line_number) +ExceptionalCondition(const char *condition_name, const char *file_name, int line_number) { - printf("# Assert failed: %s at %s:%d\n", condition_name, file_name, - line_number); + printf("# Assert failed: %s at %s:%d\n", condition_name, file_name, line_number); abort(); } @@ -46,14 +44,13 @@ make_ordinary(RfPageVersionEdgeEntryV1 *entry, uint8 block_id) } static bool -encode_entries(uint64 result_token, RfPageVersionEdgeEntryV1 *entries, - uint8 entry_count, uint8 *wire, Size capacity, - Size *wire_size) +encode_entries(uint64 result_token, RfPageVersionEdgeEntryV1 *entries, uint8 entry_count, + uint8 *wire, Size capacity, Size *wire_size) { memset(wire, 0xa5, capacity); *wire_size = SIZE_MAX; - return XLogEncodePageVersionEdgeV1(wire, capacity, result_token, - entries, entry_count, wire_size); + return XLogEncodePageVersionEdgeV1(wire, capacity, result_token, entries, entry_count, + wire_size); } UT_TEST(test_successor_literals_and_layout) @@ -80,8 +77,8 @@ UT_TEST(test_encoder_writes_exact_native_endian_offsets) Size wire_size; make_ordinary(&entry, 0); - UT_ASSERT(encode_entries(UINT64_C(0x1122334455667788), &entry, 1, - wire, sizeof(wire), &wire_size)); + UT_ASSERT( + encode_entries(UINT64_C(0x1122334455667788), &entry, 1, wire, sizeof(wire), &wire_size)); UT_ASSERT_EQ(wire_size, 64); UT_ASSERT_EQ(wire[0], 251); UT_ASSERT_EQ(wire[1], 1); @@ -91,10 +88,8 @@ UT_TEST(test_encoder_writes_exact_native_endian_offsets) memcpy(&before_token, wire + 16 + 24, sizeof(before_token)); UT_ASSERT_EQ(token, UINT64_C(0x1122334455667788)); UT_ASSERT_EQ(before_token, 10); - UT_ASSERT(memcmp(wire + 16 + 8, - entry.before.segment_incarnation, 16) == 0); - UT_ASSERT(memcmp(wire + 16 + 32, - entry.result_incarnation, 16) == 0); + UT_ASSERT(memcmp(wire + 16 + 8, entry.before.segment_incarnation, 16) == 0); + UT_ASSERT(memcmp(wire + 16 + 32, entry.result_incarnation, 16) == 0); } UT_TEST(test_encoder_failure_leaves_outputs_untouched) @@ -121,11 +116,9 @@ UT_TEST(test_encoder_accepts_exact_33_entry_maximum) for (i = 0; i < 33; i++) make_ordinary(&entries[i], i); - UT_ASSERT(encode_entries(17, entries, 33, wire, sizeof(wire), - &wire_size)); + UT_ASSERT(encode_entries(17, entries, 33, wire, sizeof(wire), &wire_size)); UT_ASSERT_EQ(wire_size, XLR_PAGE_VERSION_EDGE_MAX_SIZE); - UT_ASSERT(!encode_entries(17, entries, 34, wire, sizeof(wire), - &wire_size)); + UT_ASSERT(!encode_entries(17, entries, 34, wire, sizeof(wire), &wire_size)); } UT_TEST(test_encoder_requires_sorted_unique_blocks_and_ordinals) @@ -169,24 +162,19 @@ UT_TEST(test_encoder_accepts_only_exact_anchor_masks) RfPageVersionEdgeEntryV1 entry; uint8 wire[XLR_PAGE_VERSION_EDGE_MAX_SIZE]; Size wire_size; - uint16 valid[] = {UINT16_C(0x0005), UINT16_C(0x0006), UINT16_C(0x0007)}; - uint16 invalid[] = {UINT16_C(0x0001), UINT16_C(0x0002), - UINT16_C(0x0004), UINT16_C(0x8000)}; + uint16 valid[] = { UINT16_C(0x0005), UINT16_C(0x0006), UINT16_C(0x0007) }; + uint16 invalid[] = { UINT16_C(0x0001), UINT16_C(0x0002), UINT16_C(0x0004), UINT16_C(0x8000) }; int i; - for (i = 0; i < lengthof(valid); i++) - { + for (i = 0; i < lengthof(valid); i++) { make_ordinary(&entry, 0); entry.edge_flags = valid[i]; - UT_ASSERT(encode_entries(17, &entry, 1, wire, sizeof(wire), - &wire_size)); + UT_ASSERT(encode_entries(17, &entry, 1, wire, sizeof(wire), &wire_size)); } - for (i = 0; i < lengthof(invalid); i++) - { + for (i = 0; i < lengthof(invalid); i++) { make_ordinary(&entry, 0); entry.edge_flags = invalid[i]; - UT_ASSERT(!encode_entries(17, &entry, 1, wire, sizeof(wire), - &wire_size)); + UT_ASSERT(!encode_entries(17, &entry, 1, wire, sizeof(wire), &wire_size)); } } @@ -211,19 +199,15 @@ UT_TEST(test_encoder_validates_rebuildable_and_routed_entries) UT_TEST(test_explicit_anchor_force_has_total_precedence) { - uint8 force_will_init = REGBUF_FORCE_IMAGE | REGBUF_WILL_INIT; - - UT_ASSERT(XLogPageVersionImageRequiredV1(force_will_init, false, - InvalidXLogRecPtr, InvalidXLogRecPtr)); - UT_ASSERT(XLogPageVersionImageRequiredV1( - REGBUF_FORCE_IMAGE | REGBUF_NO_IMAGE, false, - UINT64_C(900), UINT64_C(1))); - UT_ASSERT(!XLogPageVersionImageRequiredV1(REGBUF_NO_IMAGE, true, - UINT64_C(1), UINT64_C(900))); - UT_ASSERT(!XLogPageVersionImageRequiredV1(0, false, - UINT64_C(1), UINT64_C(900))); - UT_ASSERT(XLogPageVersionImageRequiredV1(0, true, - UINT64_C(1), UINT64_C(900))); + uint8 force_will_init = REGBUF_FORCE_IMAGE | REGBUF_WILL_INIT; + + UT_ASSERT(XLogPageVersionImageRequiredV1(force_will_init, false, InvalidXLogRecPtr, + InvalidXLogRecPtr)); + UT_ASSERT(XLogPageVersionImageRequiredV1(REGBUF_FORCE_IMAGE | REGBUF_NO_IMAGE, false, + UINT64_C(900), UINT64_C(1))); + UT_ASSERT(!XLogPageVersionImageRequiredV1(REGBUF_NO_IMAGE, true, UINT64_C(1), UINT64_C(900))); + UT_ASSERT(!XLogPageVersionImageRequiredV1(0, false, UINT64_C(1), UINT64_C(900))); + UT_ASSERT(XLogPageVersionImageRequiredV1(0, true, UINT64_C(1), UINT64_C(900))); } int diff --git a/src/test/cluster_unit/test_cluster_page_edge_reader.c b/src/test/cluster_unit/test_cluster_page_edge_reader.c index b4d6c950b28..b5505e189b5 100644 --- a/src/test/cluster_unit/test_cluster_page_edge_reader.c +++ b/src/test/cluster_unit/test_cluster_page_edge_reader.c @@ -18,11 +18,9 @@ UT_DEFINE_GLOBALS(); #define TEST_ERROR_BUFFER_SIZE 1001 void -ExceptionalCondition(const char *condition_name, const char *file_name, - int line_number) +ExceptionalCondition(const char *condition_name, const char *file_name, int line_number) { - printf("# Assert failed: %s at %s:%d\n", condition_name, file_name, - line_number); + printf("# Assert failed: %s at %s:%d\n", condition_name, file_name, line_number); abort(); } @@ -45,18 +43,15 @@ errmsg_internal(const char *fmt pg_attribute_unused(), ...) } bool -errstart_cold(int elevel pg_attribute_unused(), - const char *domain pg_attribute_unused()) +errstart_cold(int elevel pg_attribute_unused(), const char *domain pg_attribute_unused()) { return false; } void -errfinish(const char *filename pg_attribute_unused(), - int lineno pg_attribute_unused(), +errfinish(const char *filename pg_attribute_unused(), int lineno pg_attribute_unused(), const char *funcname pg_attribute_unused()) -{ -} +{} static void set_incarnation(uint8 incarnation[16], uint8 seed) @@ -87,7 +82,7 @@ static size_t append_block_ref(uint8 *target, uint8 block_id) { XLogRecordBlockHeader header; - RelFileLocator locator = {1663, 5, 17}; + RelFileLocator locator = { 1663, 5, 17 }; BlockNumber block = 23; uint8 *start = target; @@ -116,28 +111,26 @@ build_record(bool edge_first, bool edge_block_mismatch, size_t *record_size) make_edge(&edge); if (edge_block_mismatch) edge.entries[0].block_id = 1; - UT_ASSERT(XLogEncodePageVersionEdgeV1(edge_wire, sizeof(edge_wire), - edge.result_token, edge.entries, edge.entry_count, &edge_len)); - block_len = SizeOfXLogRecordBlockHeader + sizeof(RelFileLocator) + - sizeof(BlockNumber); + UT_ASSERT(XLogEncodePageVersionEdgeV1(edge_wire, sizeof(edge_wire), edge.result_token, + edge.entries, edge.entry_count, &edge_len)); + block_len = SizeOfXLogRecordBlockHeader + sizeof(RelFileLocator) + sizeof(BlockNumber); *record_size = SizeOfXLogRecord + edge_len + block_len; record = calloc(1, *record_size); UT_ASSERT(record != NULL); + if (record == NULL) + abort(); record->xl_tot_len = *record_size; - target = (uint8 *) record + SizeOfXLogRecord; - if (edge_first) - { + target = (uint8 *)record + SizeOfXLogRecord; + if (edge_first) { memcpy(target, edge_wire, edge_len); target += edge_len; target += append_block_ref(target, 0); - } - else - { + } else { target += append_block_ref(target, 0); memcpy(target, edge_wire, edge_len); target += edge_len; } - UT_ASSERT_EQ((size_t) (target - (uint8 *) record), *record_size); + UT_ASSERT_EQ((size_t)(target - (uint8 *)record), *record_size); return record; } @@ -147,14 +140,16 @@ build_block_only_record(size_t *record_size) XLogRecord *record; uint8 *target; - *record_size = SizeOfXLogRecord + SizeOfXLogRecordBlockHeader + - sizeof(RelFileLocator) + sizeof(BlockNumber); + *record_size = SizeOfXLogRecord + SizeOfXLogRecordBlockHeader + sizeof(RelFileLocator) + + sizeof(BlockNumber); record = calloc(1, *record_size); UT_ASSERT(record != NULL); + if (record == NULL) + abort(); record->xl_tot_len = *record_size; - target = (uint8 *) record + SizeOfXLogRecord; + target = (uint8 *)record + SizeOfXLogRecord; target += append_block_ref(target, 0); - UT_ASSERT_EQ((size_t) (target - (uint8 *) record), *record_size); + UT_ASSERT_EQ((size_t)(target - (uint8 *)record), *record_size); return record; } @@ -172,9 +167,7 @@ decode_record(XLogRecord *record, DecodedXLogRecord **decoded_out) state.ReadRecPtr = UINT64_C(0x1000000); decoded = calloc(1, DecodeXLogRecordRequiredSpace(record->xl_tot_len)); UT_ASSERT(decoded != NULL); - if (!DecodeXLogRecord(&state, decoded, record, state.ReadRecPtr, - &errormsg)) - { + if (!DecodeXLogRecord(&state, decoded, record, state.ReadRecPtr, &errormsg)) { free(decoded); *decoded_out = NULL; return false; @@ -247,21 +240,20 @@ UT_TEST(test_reader_rejects_stale_and_malformed_edge_headers) uint16 one = 1; record = build_record(true, false, &record_size); - edge_wire = (uint8 *) record + SizeOfXLogRecord; + edge_wire = (uint8 *)record + SizeOfXLogRecord; edge_wire[3] = 32; UT_ASSERT(!decode_record(record, &decoded)); free(record); record = build_record(true, false, &record_size); - edge_wire = (uint8 *) record + SizeOfXLogRecord; + edge_wire = (uint8 *)record + SizeOfXLogRecord; memcpy(edge_wire + 4, &one, sizeof(one)); UT_ASSERT(!decode_record(record, &decoded)); free(record); record = build_record(true, false, &record_size); - edge_wire = (uint8 *) record + SizeOfXLogRecord; - memcpy(edge_wire + XLR_PAGE_VERSION_EDGE_HEADER_SIZE + 4, - &one, sizeof(one)); + edge_wire = (uint8 *)record + SizeOfXLogRecord; + memcpy(edge_wire + XLR_PAGE_VERSION_EDGE_HEADER_SIZE + 4, &one, sizeof(one)); UT_ASSERT(!decode_record(record, &decoded)); free(record); } @@ -276,8 +268,7 @@ UT_TEST(test_reader_rejects_init_flag_without_block_declaration) uint64 zero = 0; record = build_record(true, false, &record_size); - entry_wire = (uint8 *) record + SizeOfXLogRecord + - XLR_PAGE_VERSION_EDGE_HEADER_SIZE; + entry_wire = (uint8 *)record + SizeOfXLogRecord + XLR_PAGE_VERSION_EDGE_HEADER_SIZE; entry_wire[2] = RF_PAGE_STATE_UNFORMATTED; memcpy(entry_wire + 4, &init_flags, sizeof(init_flags)); memcpy(entry_wire + 24, &zero, sizeof(zero)); diff --git a/src/test/cluster_unit/test_cluster_page_guard.c b/src/test/cluster_unit/test_cluster_page_guard.c index 08756eb0aed..32b9d0f7aea 100644 --- a/src/test/cluster_unit/test_cluster_page_guard.c +++ b/src/test/cluster_unit/test_cluster_page_guard.c @@ -21,11 +21,9 @@ UT_DEFINE_GLOBALS(); void -ExceptionalCondition(const char *condition_name, const char *file_name, - int line_number) +ExceptionalCondition(const char *condition_name, const char *file_name, int line_number) { - printf("# unexpected Assert: %s at %s:%d\n", condition_name, file_name, - line_number); + printf("# unexpected Assert: %s at %s:%d\n", condition_name, file_name, line_number); abort(); } @@ -114,8 +112,7 @@ UT_TEST(test_partition_conflict_fails_without_wait) uint32 blockno; UT_ASSERT(rf_page_guard_preflight_v1(&first_page, &first)); - for (blockno = 21; blockno < 100000; blockno++) - { + for (blockno = 21; blockno < 100000; blockno++) { second_page.blockno = blockno; UT_ASSERT(rf_page_guard_preflight_v1(&second_page, &second)); if (second.partition == first.partition) diff --git a/src/test/cluster_unit/test_cluster_page_install.c b/src/test/cluster_unit/test_cluster_page_install.c index c225630ad41..219dca331f3 100644 --- a/src/test/cluster_unit/test_cluster_page_install.c +++ b/src/test/cluster_unit/test_cluster_page_install.c @@ -22,11 +22,9 @@ UT_DEFINE_GLOBALS(); void -ExceptionalCondition(const char *condition_name, const char *file_name, - int line_number) +ExceptionalCondition(const char *condition_name, const char *file_name, int line_number) { - printf("# unexpected Assert: %s at %s:%d\n", condition_name, file_name, - line_number); + printf("# unexpected Assert: %s at %s:%d\n", condition_name, file_name, line_number); abort(); } @@ -51,37 +49,35 @@ main(void) #define TEST_INSTALL_BATCH_TARGETS 40 -typedef struct InstallFixture -{ +typedef struct InstallFixture { PGAlignedBlock disk[TEST_INSTALL_BATCH_TARGETS]; - bool exists[TEST_INSTALL_BATCH_TARGETS]; - bool read_ok[TEST_INSTALL_BATCH_TARGETS]; - bool write_ok[TEST_INSTALL_BATCH_TARGETS]; - bool sync_ok[TEST_INSTALL_BATCH_TARGETS]; - bool identity_ok; - bool promote_ok; - bool publish_ok; - bool release_ok; - bool checksums_enabled; - int read_calls; - int write_calls; - int sync_calls; - int identity_calls; - int promote_calls; - int publish_calls; - int release_calls; - int promote_step; - int first_initial_read_step; - int first_write_step; - int last_initial_read_step; - int step; - bool last_extend; - bool zero_postread; - uint32 initial_read_count; + bool exists[TEST_INSTALL_BATCH_TARGETS]; + bool read_ok[TEST_INSTALL_BATCH_TARGETS]; + bool write_ok[TEST_INSTALL_BATCH_TARGETS]; + bool sync_ok[TEST_INSTALL_BATCH_TARGETS]; + bool identity_ok; + bool promote_ok; + bool publish_ok; + bool release_ok; + bool checksums_enabled; + int read_calls; + int write_calls; + int sync_calls; + int identity_calls; + int promote_calls; + int publish_calls; + int release_calls; + int promote_step; + int first_initial_read_step; + int first_write_step; + int last_initial_read_step; + int step; + bool last_extend; + bool zero_postread; + uint32 initial_read_count; } InstallFixture; -typedef struct InstallCase -{ +typedef struct InstallCase { InstallFixture fixture; RfPageStorageInstallComponentV1 components[TEST_INSTALL_BATCH_TARGETS]; PGAlignedBlock canonical[TEST_INSTALL_BATCH_TARGETS]; @@ -95,19 +91,17 @@ typedef struct InstallCase bool rf_page_identity_valid_v1(const RfPageIdentityV1 *identity) { - return identity != NULL && identity->system_identifier != 0 && - identity->locator.spcOid != InvalidOid && - identity->locator.dbOid != InvalidOid && - identity->locator.relNumber != InvalidRelFileNumber && - identity->blockno != InvalidBlockNumber && - identity->reserved_zero == 0; + return identity != NULL && identity->system_identifier != 0 + && identity->locator.spcOid != InvalidOid && identity->locator.dbOid != InvalidOid + && identity->locator.relNumber != InvalidRelFileNumber + && identity->blockno != InvalidBlockNumber && identity->reserved_zero == 0; } bool rf_page_version_present_v1(const RfPageVersionV1 *version) { - uint8 value = 0; - int i; + uint8 value = 0; + int i; if (version == NULL || version->mutation_token == 0) return false; @@ -123,15 +117,14 @@ set_incarnation(uint8 incarnation[16], uint8 value) } static bool -storage_read(void *arg, uint32 index, const RfPageIdentityV1 *identity, - char page[BLCKSZ], bool *exists) +storage_read(void *arg, uint32 index, const RfPageIdentityV1 *identity, char page[BLCKSZ], + bool *exists) { - InstallFixture *fixture = (InstallFixture *) arg; + InstallFixture *fixture = (InstallFixture *)arg; fixture->step++; fixture->read_calls++; - if (fixture->read_calls <= (int) fixture->initial_read_count) - { + if (fixture->read_calls <= (int)fixture->initial_read_count) { if (fixture->first_initial_read_step == 0) fixture->first_initial_read_step = fixture->step; fixture->last_initial_read_step = fixture->step; @@ -139,9 +132,7 @@ storage_read(void *arg, uint32 index, const RfPageIdentityV1 *identity, if (!fixture->read_ok[index]) return false; *exists = fixture->exists[index]; - if (fixture->zero_postread && - fixture->read_calls > (int) fixture->initial_read_count) - { + if (fixture->zero_postread && fixture->read_calls > (int)fixture->initial_read_count) { *exists = true; memset(page, 0, BLCKSZ); return true; @@ -154,10 +145,10 @@ storage_read(void *arg, uint32 index, const RfPageIdentityV1 *identity, } static bool -storage_write(void *arg, uint32 index, const RfPageIdentityV1 *identity, - const char page[BLCKSZ], bool extend) +storage_write(void *arg, uint32 index, const RfPageIdentityV1 *identity, const char page[BLCKSZ], + bool extend) { - InstallFixture *fixture = (InstallFixture *) arg; + InstallFixture *fixture = (InstallFixture *)arg; fixture->step++; if (fixture->first_write_step == 0) @@ -174,7 +165,7 @@ storage_write(void *arg, uint32 index, const RfPageIdentityV1 *identity, static bool storage_sync(void *arg, uint32 index, const RfPageIdentityV1 *identity) { - InstallFixture *fixture = (InstallFixture *) arg; + InstallFixture *fixture = (InstallFixture *)arg; fixture->step++; fixture->sync_calls++; @@ -184,23 +175,21 @@ storage_sync(void *arg, uint32 index, const RfPageIdentityV1 *identity) static uint16 storage_checksum(void *arg, const char page[BLCKSZ], BlockNumber blockno) { - const uint8 *bytes = (const uint8 *) page; - uint32 sum = blockno + 1; - int i; + const uint8 *bytes = (const uint8 *)page; + uint32 sum = blockno + 1; + int i; for (i = 0; i < BLCKSZ; i++) - if (i < (int) offsetof(PageHeaderData, pd_checksum) || - i >= (int) (offsetof(PageHeaderData, pd_checksum) + - sizeof(uint16))) + if (i < (int)offsetof(PageHeaderData, pd_checksum) + || i >= (int)(offsetof(PageHeaderData, pd_checksum) + sizeof(uint16))) sum = (sum * 33) ^ bytes[i]; - return (uint16) ((sum % 65535) + 1); + return (uint16)((sum % 65535) + 1); } static bool -authority_identity(void *arg, const RfPageIdentityV1 *identity, - const uint8 incarnation[16]) +authority_identity(void *arg, const RfPageIdentityV1 *identity, const uint8 incarnation[16]) { - InstallFixture *fixture = (InstallFixture *) arg; + InstallFixture *fixture = (InstallFixture *)arg; fixture->identity_calls++; return fixture->identity_ok; @@ -209,7 +198,7 @@ authority_identity(void *arg, const RfPageIdentityV1 *identity, static bool authority_promote(void *arg) { - InstallFixture *fixture = (InstallFixture *) arg; + InstallFixture *fixture = (InstallFixture *)arg; fixture->step++; fixture->promote_calls++; @@ -220,7 +209,7 @@ authority_promote(void *arg) static bool authority_publish(void *arg) { - InstallFixture *fixture = (InstallFixture *) arg; + InstallFixture *fixture = (InstallFixture *)arg; fixture->step++; fixture->publish_calls++; @@ -230,7 +219,7 @@ authority_publish(void *arg) static bool authority_release(void *arg) { - InstallFixture *fixture = (InstallFixture *) arg; + InstallFixture *fixture = (InstallFixture *)arg; fixture->step++; fixture->release_calls++; @@ -243,20 +232,19 @@ init_page(char page[BLCKSZ], uint64 token, uint8 payload) PageHeader header; memset(page, payload, BLCKSZ); - header = (PageHeader) page; + header = (PageHeader)page; memset(header, 0, SizeOfPageHeaderData); header->pd_lower = SizeOfPageHeaderData; header->pd_upper = BLCKSZ; header->pd_special = BLCKSZ; - header->pd_pagesize_version = - (BLCKSZ & 0xFF00) | PG_PAGE_LAYOUT_VERSION; + header->pd_pagesize_version = (BLCKSZ & 0xFF00) | PG_PAGE_LAYOUT_VERSION; header->pd_block_scn = token; } static void init_case(InstallCase *test_case, uint32 count) { - uint32 i; + uint32 i; memset(test_case, 0, sizeof(*test_case)); test_case->fixture.identity_ok = true; @@ -264,16 +252,13 @@ init_case(InstallCase *test_case, uint32 count) test_case->fixture.publish_ok = true; test_case->fixture.release_ok = true; test_case->fixture.initial_read_count = count; - for (i = 0; i < TEST_INSTALL_BATCH_TARGETS; i++) - { + for (i = 0; i < TEST_INSTALL_BATCH_TARGETS; i++) { test_case->fixture.read_ok[i] = true; test_case->fixture.write_ok[i] = true; test_case->fixture.sync_ok[i] = true; } - for (i = 0; i < count; i++) - { - RfPageStorageInstallComponentV1 *component = - &test_case->components[i]; + for (i = 0; i < count; i++) { + RfPageStorageInstallComponentV1 *component = &test_case->components[i]; component->page_identity.system_identifier = 99; memset(component->page_identity.storage_uuid, 3, 16); @@ -288,9 +273,8 @@ init_case(InstallCase *test_case, uint32 count) set_incarnation(component->expected_result.segment_incarnation, 7); component->expected_result.mutation_token = 11; component->canonical_page = test_case->canonical[i].data; - init_page(test_case->canonical[i].data, 11, (uint8) (0x40 + i)); - init_page(test_case->fixture.disk[i].data, 10, - (uint8) (0x20 + i)); + init_page(test_case->canonical[i].data, 11, (uint8)(0x40 + i)); + init_page(test_case->fixture.disk[i].data, 10, (uint8)(0x20 + i)); test_case->fixture.exists[i] = true; } test_case->storage.arg = &test_case->fixture; @@ -298,8 +282,7 @@ init_case(InstallCase *test_case, uint32 count) test_case->storage.write = storage_write; test_case->storage.sync = storage_sync; test_case->storage.checksum = storage_checksum; - test_case->storage.checksums_enabled = - test_case->fixture.checksums_enabled; + test_case->storage.checksums_enabled = test_case->fixture.checksums_enabled; test_case->authority.arg = &test_case->fixture; test_case->authority.validate_identity = authority_identity; test_case->authority.promote = authority_promote; @@ -323,7 +306,7 @@ UT_TEST(test_expected_target_write_sync_postread_publish_release) init_case(&test_case, 1); UT_ASSERT_EQ(rf_page_storage_install_execute_v1(&test_case.request, &proof), - RF_PAGE_PROOF_DETAIL_OK); + RF_PAGE_PROOF_DETAIL_OK); UT_ASSERT_EQ(test_case.fixture.write_calls, 1); UT_ASSERT_EQ(test_case.fixture.sync_calls, 1); UT_ASSERT_EQ(test_case.fixture.read_calls, 2); @@ -339,10 +322,9 @@ UT_TEST(test_result_target_skips_write_but_proves_durability) RfPageStorageInstallProofV1 proof; init_case(&test_case, 1); - memcpy(test_case.fixture.disk[0].data, test_case.canonical[0].data, - BLCKSZ); + memcpy(test_case.fixture.disk[0].data, test_case.canonical[0].data, BLCKSZ); UT_ASSERT_EQ(rf_page_storage_install_execute_v1(&test_case.request, &proof), - RF_PAGE_PROOF_DETAIL_OK); + RF_PAGE_PROOF_DETAIL_OK); UT_ASSERT_EQ(test_case.fixture.write_calls, 0); UT_ASSERT_EQ(test_case.fixture.sync_calls, 1); UT_ASSERT_EQ(test_case.fixture.read_calls, 2); @@ -357,7 +339,7 @@ UT_TEST(test_noncanonical_result_target_blocks_whole_batch_before_promote) init_case(&test_case, 2); init_page(test_case.fixture.disk[0].data, 11, 0x7F); UT_ASSERT_EQ(rf_page_storage_install_execute_v1(&test_case.request, &proof), - RF_PAGE_PROOF_DETAIL_IMAGE_INTEGRITY_FAILED); + RF_PAGE_PROOF_DETAIL_IMAGE_INTEGRITY_FAILED); UT_ASSERT_EQ(test_case.fixture.promote_calls, 1); UT_ASSERT_EQ(test_case.fixture.release_calls, 1); UT_ASSERT_EQ(test_case.fixture.write_calls, 0); @@ -374,7 +356,7 @@ UT_TEST(test_absent_target_extends_only_for_absent_edge) memset(&test_case.components[0].expected_before, 0, sizeof(test_case.components[0].expected_before)); UT_ASSERT_EQ(rf_page_storage_install_execute_v1(&test_case.request, &proof), - RF_PAGE_PROOF_DETAIL_OK); + RF_PAGE_PROOF_DETAIL_OK); UT_ASSERT_EQ(test_case.fixture.write_calls, 1); UT_ASSERT(test_case.fixture.last_extend); } @@ -387,7 +369,7 @@ UT_TEST(test_absent_target_with_present_edge_is_zero_mutation) init_case(&test_case, 1); test_case.fixture.exists[0] = false; UT_ASSERT_EQ(rf_page_storage_install_execute_v1(&test_case.request, &proof), - RF_PAGE_PROOF_DETAIL_VERSION_MISMATCH); + RF_PAGE_PROOF_DETAIL_VERSION_MISMATCH); UT_ASSERT_EQ(test_case.fixture.promote_calls, 1); UT_ASSERT_EQ(test_case.fixture.release_calls, 1); UT_ASSERT_EQ(test_case.fixture.write_calls, 0); @@ -399,9 +381,9 @@ UT_TEST(test_unrelated_valid_token_blocks_whole_batch) RfPageStorageInstallProofV1 proof; init_case(&test_case, 2); - ((PageHeader) test_case.fixture.disk[1].data)->pd_block_scn = 99; + ((PageHeader)test_case.fixture.disk[1].data)->pd_block_scn = 99; UT_ASSERT_EQ(rf_page_storage_install_execute_v1(&test_case.request, &proof), - RF_PAGE_PROOF_DETAIL_VERSION_MISMATCH); + RF_PAGE_PROOF_DETAIL_VERSION_MISMATCH); UT_ASSERT_EQ(test_case.fixture.promote_calls, 1); UT_ASSERT_EQ(test_case.fixture.release_calls, 1); UT_ASSERT_EQ(test_case.fixture.write_calls, 0); @@ -416,7 +398,7 @@ UT_TEST(test_torn_target_requires_identity_authority) memset(test_case.fixture.disk[0].data, 0, BLCKSZ); test_case.fixture.identity_ok = false; UT_ASSERT_EQ(rf_page_storage_install_execute_v1(&test_case.request, &proof), - RF_PAGE_PROOF_DETAIL_IDENTITY_MISMATCH); + RF_PAGE_PROOF_DETAIL_IDENTITY_MISMATCH); UT_ASSERT_EQ(test_case.fixture.write_calls, 0); } @@ -428,7 +410,7 @@ UT_TEST(test_postread_zero_page_fails_and_releases_without_publish) init_case(&test_case, 1); test_case.fixture.zero_postread = true; UT_ASSERT_EQ(rf_page_storage_install_execute_v1(&test_case.request, &proof), - RF_PAGE_PROOF_DETAIL_POSTREAD_FAILED); + RF_PAGE_PROOF_DETAIL_POSTREAD_FAILED); UT_ASSERT_EQ(test_case.fixture.publish_calls, 0); UT_ASSERT_EQ(test_case.fixture.release_calls, 1); } @@ -441,7 +423,7 @@ UT_TEST(test_sync_failure_releases_without_proof) init_case(&test_case, 1); test_case.fixture.sync_ok[0] = false; UT_ASSERT_EQ(rf_page_storage_install_execute_v1(&test_case.request, &proof), - RF_PAGE_PROOF_DETAIL_POSTREAD_FAILED); + RF_PAGE_PROOF_DETAIL_POSTREAD_FAILED); UT_ASSERT_EQ(test_case.fixture.publish_calls, 0); UT_ASSERT_EQ(test_case.fixture.release_calls, 1); } @@ -455,14 +437,14 @@ UT_TEST(test_checksum_modes_canonicalize_exactly) test_case.fixture.checksums_enabled = true; test_case.storage.checksums_enabled = true; UT_ASSERT_EQ(rf_page_storage_install_execute_v1(&test_case.request, &proof), - RF_PAGE_PROOF_DETAIL_OK); - UT_ASSERT_NE(((PageHeader) test_case.fixture.disk[0].data)->pd_checksum, 0); + RF_PAGE_PROOF_DETAIL_OK); + UT_ASSERT_NE(((PageHeader)test_case.fixture.disk[0].data)->pd_checksum, 0); init_case(&test_case, 1); - ((PageHeader) test_case.canonical[0].data)->pd_checksum = 0xCAFE; + ((PageHeader)test_case.canonical[0].data)->pd_checksum = 0xCAFE; UT_ASSERT_EQ(rf_page_storage_install_execute_v1(&test_case.request, &proof), - RF_PAGE_PROOF_DETAIL_OK); - UT_ASSERT_EQ(((PageHeader) test_case.fixture.disk[0].data)->pd_checksum, 0); + RF_PAGE_PROOF_DETAIL_OK); + UT_ASSERT_EQ(((PageHeader)test_case.fixture.disk[0].data)->pd_checksum, 0); } UT_TEST(test_whole_batch_reads_precede_first_write) @@ -472,13 +454,10 @@ UT_TEST(test_whole_batch_reads_precede_first_write) init_case(&test_case, TEST_INSTALL_BATCH_TARGETS); UT_ASSERT_EQ(rf_page_storage_install_execute_v1(&test_case.request, &proof), - RF_PAGE_PROOF_DETAIL_OK); - UT_ASSERT_EQ(test_case.fixture.write_calls, - TEST_INSTALL_BATCH_TARGETS); - UT_ASSERT(test_case.fixture.first_initial_read_step > - test_case.fixture.promote_step); - UT_ASSERT(test_case.fixture.first_write_step > - test_case.fixture.last_initial_read_step); + RF_PAGE_PROOF_DETAIL_OK); + UT_ASSERT_EQ(test_case.fixture.write_calls, TEST_INSTALL_BATCH_TARGETS); + UT_ASSERT(test_case.fixture.first_initial_read_step > test_case.fixture.promote_step); + UT_ASSERT(test_case.fixture.first_write_step > test_case.fixture.last_initial_read_step); } UT_TEST(test_promote_failure_performs_no_target_io) @@ -489,7 +468,7 @@ UT_TEST(test_promote_failure_performs_no_target_io) init_case(&test_case, 1); test_case.fixture.promote_ok = false; UT_ASSERT_EQ(rf_page_storage_install_execute_v1(&test_case.request, &proof), - RF_PAGE_PROOF_DETAIL_WOULD_BLOCK); + RF_PAGE_PROOF_DETAIL_WOULD_BLOCK); UT_ASSERT_EQ(test_case.fixture.promote_calls, 1); UT_ASSERT_EQ(test_case.fixture.read_calls, 0); UT_ASSERT_EQ(test_case.fixture.write_calls, 0); @@ -504,13 +483,13 @@ UT_TEST(test_reserved_and_nonordinary_fork_are_rejected) init_case(&test_case, 1); test_case.components[0].reserved_zero[0] = 1; UT_ASSERT_EQ(rf_page_storage_install_execute_v1(&test_case.request, &proof), - RF_PAGE_PROOF_DETAIL_IDENTITY_MISMATCH); + RF_PAGE_PROOF_DETAIL_IDENTITY_MISMATCH); UT_ASSERT_EQ(test_case.fixture.promote_calls, 0); init_case(&test_case, 1); test_case.components[0].page_identity.forknum = FSM_FORKNUM; UT_ASSERT_EQ(rf_page_storage_install_execute_v1(&test_case.request, &proof), - RF_PAGE_PROOF_DETAIL_IDENTITY_MISMATCH); + RF_PAGE_PROOF_DETAIL_IDENTITY_MISMATCH); UT_ASSERT_EQ(test_case.fixture.promote_calls, 0); } diff --git a/src/test/cluster_unit/test_cluster_page_online_plan.c b/src/test/cluster_unit/test_cluster_page_online_plan.c index 4f059fdc93a..06bd43ddcaf 100644 --- a/src/test/cluster_unit/test_cluster_page_online_plan.c +++ b/src/test/cluster_unit/test_cluster_page_online_plan.c @@ -18,11 +18,9 @@ UT_DEFINE_GLOBALS(); void -ExceptionalCondition(const char *condition_name, const char *file_name, - int line_number) +ExceptionalCondition(const char *condition_name, const char *file_name, int line_number) { - printf("# unexpected Assert: %s at %s:%d\n", condition_name, file_name, - line_number); + printf("# unexpected Assert: %s at %s:%d\n", condition_name, file_name, line_number); abort(); } @@ -31,29 +29,26 @@ static int fail_component = -1; bool rf_page_identity_valid_v1(const RfPageIdentityV1 *identity) { - return identity != NULL && identity->system_identifier != 0 && - identity->locator.spcOid != InvalidOid && - identity->locator.dbOid != InvalidOid && - identity->locator.relNumber != InvalidRelFileNumber && - identity->blockno != InvalidBlockNumber && identity->reserved_zero == 0; + return identity != NULL && identity->system_identifier != 0 + && identity->locator.spcOid != InvalidOid && identity->locator.dbOid != InvalidOid + && identity->locator.relNumber != InvalidRelFileNumber + && identity->blockno != InvalidBlockNumber && identity->reserved_zero == 0; } bool -rf_page_identity_equal_v1(const RfPageIdentityV1 *left, - const RfPageIdentityV1 *right) +rf_page_identity_equal_v1(const RfPageIdentityV1 *left, const RfPageIdentityV1 *right) { - return left != NULL && right != NULL && - left->system_identifier == right->system_identifier && - memcmp(left->storage_uuid, right->storage_uuid, 16) == 0 && - RelFileLocatorEquals(left->locator, right->locator) && - left->forknum == right->forknum && left->blockno == right->blockno; + return left != NULL && right != NULL && left->system_identifier == right->system_identifier + && memcmp(left->storage_uuid, right->storage_uuid, 16) == 0 + && RelFileLocatorEquals(left->locator, right->locator) && left->forknum == right->forknum + && left->blockno == right->blockno; } bool rf_page_version_present_v1(const RfPageVersionV1 *version) { - uint8 value = 0; - int i; + uint8 value = 0; + int i; if (version == NULL || version->mutation_token == 0) return false; @@ -63,48 +58,42 @@ rf_page_version_present_v1(const RfPageVersionV1 *version) } bool -rf_page_version_equal_v1(const RfPageVersionV1 *left, - const RfPageVersionV1 *right) +rf_page_version_equal_v1(const RfPageVersionV1 *left, const RfPageVersionV1 *right) { - return left != NULL && right != NULL && - left->mutation_token == right->mutation_token && - memcmp(left->segment_incarnation, - right->segment_incarnation, 16) == 0; + return left != NULL && right != NULL && left->mutation_token == right->mutation_token + && memcmp(left->segment_incarnation, right->segment_incarnation, 16) == 0; } RfPageProofDetailV1 -rf_page_detached_apply_v1(const RfDetachedRecordPlanV1 *plan, - uint32 component_index, - const char old_page[BLCKSZ], - char new_page[BLCKSZ]) +rf_page_detached_apply_v1(const RfDetachedRecordPlanV1 *plan, uint32 component_index, + const char old_page[BLCKSZ], char new_page[BLCKSZ]) { const RfDetachedComponentPlanV1 *component; - PageHeader header; + PageHeader header; - if ((int) component_index == fail_component) + if ((int)component_index == fail_component) return RF_PAGE_PROOF_DETAIL_OPCODE_UNSUPPORTED; component = &plan->components[component_index]; - memset(new_page, (int) component->result.mutation_token, BLCKSZ); - header = (PageHeader) new_page; + memset(new_page, (int)component->result.mutation_token, BLCKSZ); + header = (PageHeader)new_page; memset(header, 0, SizeOfPageHeaderData); header->pd_lower = SizeOfPageHeaderData; header->pd_upper = BLCKSZ; header->pd_special = BLCKSZ; - header->pd_pagesize_version = - (BLCKSZ & 0xFF00) | PG_PAGE_LAYOUT_VERSION; + header->pd_pagesize_version = (BLCKSZ & 0xFF00) | PG_PAGE_LAYOUT_VERSION; header->pd_block_scn = component->result.mutation_token; return RF_PAGE_PROOF_DETAIL_OK; } -typedef struct FakeRecord -{ +typedef struct FakeRecord { XLogReaderState reader; RfDetachedRecordPlanV1 plan; - union - { + union { DecodedXLogRecord decoded; - char padding[sizeof(DecodedXLogRecord) + - RF_PAGE_STABLE_MAX_COMPONENTS * sizeof(DecodedBkpBlock)]; + /* Reserves the trailing block array addressed through decoded. */ + /* cppcheck-suppress unusedStructMember */ + char padding[sizeof(DecodedXLogRecord) + + RF_PAGE_STABLE_MAX_COMPONENTS * sizeof(DecodedBkpBlock)]; } storage; } FakeRecord; @@ -116,8 +105,7 @@ set_version(RfPageVersionV1 *version, uint64 token) } static void -init_record(FakeRecord *record, XLogRecPtr begin, XLogRecPtr end, - uint32 count) +init_record(FakeRecord *record, XLogRecPtr begin, XLogRecPtr end, uint32 count) { memset(record, 0, sizeof(*record)); record->reader.ReadRecPtr = begin; @@ -126,18 +114,18 @@ init_record(FakeRecord *record, XLogRecPtr begin, XLogRecPtr end, record->reader.record = &record->storage.decoded; record->storage.decoded.lsn = begin; record->storage.decoded.next_lsn = end; - record->storage.decoded.header.xl_crc = (pg_crc32c) (begin ^ end); + record->storage.decoded.header.xl_crc = (pg_crc32c)(begin ^ end); record->storage.decoded.header.xl_rmid = RM_XLOG_ID; - record->storage.decoded.header.xl_info = (uint8) (begin & 0xf0); - record->storage.decoded.max_block_id = (int) count - 1; + record->storage.decoded.header.xl_info = (uint8)(begin & 0xf0); + record->storage.decoded.max_block_id = (int)count - 1; record->plan.source_record = &record->reader; record->plan.component_count = count; record->plan.preflight_complete = true; } static void -set_component(FakeRecord *record, uint32 index, Oid rel, BlockNumber block, - uint64 before, uint64 result, bool anchor) +set_component(FakeRecord *record, uint32 index, Oid rel, BlockNumber block, uint64 before, + uint64 result, bool anchor) { DecodedBkpBlock *decoded = &record->storage.decoded.blocks[index]; RfDetachedComponentPlanV1 *component = &record->plan.components[index]; @@ -148,17 +136,16 @@ set_component(FakeRecord *record, uint32 index, Oid rel, BlockNumber block, decoded->rlocator.relNumber = rel; decoded->forknum = MAIN_FORKNUM; decoded->blkno = block; - component->block_id = (uint8) index; + component->block_id = (uint8)index; component->page_class = RF_PAGE_CLASS_ORDINARY; component->owner = RF_DETACHED_COMPONENT_PAGE_CODEC; - component->component_ordinal = (uint16) index; + component->component_ordinal = (uint16)index; component->before_kind = RF_PAGE_STATE_PRESENT; component->result_kind = RF_PAGE_STATE_PRESENT; set_version(&component->before, before); set_version(&component->result, result); if (anchor) - component->edge_flags = RF_PAGE_EDGE_FULL_IMAGE_APPLY | - RF_PAGE_EDGE_FULL_COVERAGE; + component->edge_flags = RF_PAGE_EDGE_FULL_IMAGE_APPLY | RF_PAGE_EDGE_FULL_COVERAGE; } static RfPageOnlinePlanV1 * @@ -180,8 +167,7 @@ create_plan(XLogRecPtr begin, XLogRecPtr end) request.physical_cuts = &cut; request.participant_count = 1; request.retention_binding_cookie = 41; - UT_ASSERT_EQ(rf_page_online_plan_create_v1(&request, &plan), - RF_PAGE_PROOF_DETAIL_OK); + UT_ASSERT_EQ(rf_page_online_plan_create_v1(&request, &plan), RF_PAGE_PROOF_DETAIL_OK); return plan; } @@ -192,14 +178,12 @@ record_identity(const FakeRecord *record) memset(&identity, 0, sizeof(identity)); identity.record.system_identifier = 99; - memset(identity.record.storage_uuid, 3, - sizeof(identity.record.storage_uuid)); + memset(identity.record.storage_uuid, 3, sizeof(identity.record.storage_uuid)); identity.record.origin_thread = 1; identity.record.timeline_id = 1; identity.record.read_rec_ptr = record->reader.ReadRecPtr; identity.record.end_rec_ptr = record->reader.EndRecPtr; - identity.record.record_crc = - (uint32) record->storage.decoded.header.xl_crc; + identity.record.record_crc = (uint32)record->storage.decoded.header.xl_crc; identity.record.rmid = record->storage.decoded.header.xl_rmid; identity.record.info = record->storage.decoded.header.xl_info; return identity; @@ -217,19 +201,18 @@ UT_TEST(test_two_record_chain_builds_canonical_target) set_component(&first, 0, 10, 4, 10, 11, true); id = record_identity(&first); UT_ASSERT_EQ(rf_page_online_plan_feed_record_v1(plan, &first.plan, &id), - RF_PAGE_PROOF_DETAIL_OK); + RF_PAGE_PROOF_DETAIL_OK); init_record(&second, 0x200, 0x300, 1); set_component(&second, 0, 10, 4, 11, 12, false); id = record_identity(&second); UT_ASSERT_EQ(rf_page_online_plan_feed_record_v1(plan, &second.plan, &id), - RF_PAGE_PROOF_DETAIL_OK); - UT_ASSERT_EQ(rf_page_online_plan_seal_v1(plan), - RF_PAGE_PROOF_DETAIL_OK); + RF_PAGE_PROOF_DETAIL_OK); + UT_ASSERT_EQ(rf_page_online_plan_seal_v1(plan), RF_PAGE_PROOF_DETAIL_OK); UT_ASSERT_EQ(rf_page_online_plan_target_count_v1(plan), 1); UT_ASSERT(rf_page_online_plan_target_v1(plan, 0, &target)); UT_ASSERT_EQ(target.expected_before.mutation_token, 10); UT_ASSERT_EQ(target.expected_result.mutation_token, 12); - UT_ASSERT_EQ(((PageHeader) target.canonical_page)->pd_block_scn, 12); + UT_ASSERT_EQ(((PageHeader)target.canonical_page)->pd_block_scn, 12); UT_ASSERT_EQ(target.source->source_version.mutation_token, 11); UT_ASSERT_EQ(target.contributors->edge_count, 2); UT_ASSERT_EQ(target.contributors->cuts[0].contributor_count, 2); @@ -251,12 +234,11 @@ UT_TEST(test_record_failure_is_atomic_and_retryable) id = record_identity(&record); fail_component = 1; UT_ASSERT_EQ(rf_page_online_plan_feed_record_v1(plan, &record.plan, &id), - RF_PAGE_PROOF_DETAIL_OPCODE_UNSUPPORTED); + RF_PAGE_PROOF_DETAIL_OPCODE_UNSUPPORTED); fail_component = -1; UT_ASSERT_EQ(rf_page_online_plan_feed_record_v1(plan, &record.plan, &id), - RF_PAGE_PROOF_DETAIL_OK); - UT_ASSERT_EQ(rf_page_online_plan_seal_v1(plan), - RF_PAGE_PROOF_DETAIL_OK); + RF_PAGE_PROOF_DETAIL_OK); + UT_ASSERT_EQ(rf_page_online_plan_seal_v1(plan), RF_PAGE_PROOF_DETAIL_OK); UT_ASSERT_EQ(rf_page_online_plan_target_count_v1(plan), 2); UT_ASSERT(rf_page_online_plan_target_v1(plan, 0, &first)); UT_ASSERT(rf_page_online_plan_target_v1(plan, 1, &second)); @@ -275,12 +257,11 @@ UT_TEST(test_first_delta_requires_full_anchor) set_component(&record, 0, 10, 1, 10, 11, false); id = record_identity(&record); UT_ASSERT_EQ(rf_page_online_plan_feed_record_v1(plan, &record.plan, &id), - RF_PAGE_PROOF_DETAIL_ANCHOR_MISSING); + RF_PAGE_PROOF_DETAIL_ANCHOR_MISSING); set_component(&record, 0, 10, 1, 10, 11, true); UT_ASSERT_EQ(rf_page_online_plan_feed_record_v1(plan, &record.plan, &id), - RF_PAGE_PROOF_DETAIL_OK); - UT_ASSERT_EQ(rf_page_online_plan_seal_v1(plan), - RF_PAGE_PROOF_DETAIL_OK); + RF_PAGE_PROOF_DETAIL_OK); + UT_ASSERT_EQ(rf_page_online_plan_seal_v1(plan), RF_PAGE_PROOF_DETAIL_OK); rf_page_online_plan_destroy_v1(&plan); } @@ -295,17 +276,16 @@ UT_TEST(test_edge_gap_does_not_advance_stream) set_component(&first, 0, 10, 1, 10, 11, true); id = record_identity(&first); UT_ASSERT_EQ(rf_page_online_plan_feed_record_v1(plan, &first.plan, &id), - RF_PAGE_PROOF_DETAIL_OK); + RF_PAGE_PROOF_DETAIL_OK); init_record(&second, 0x200, 0x300, 1); set_component(&second, 0, 10, 1, 99, 12, false); id = record_identity(&second); UT_ASSERT_EQ(rf_page_online_plan_feed_record_v1(plan, &second.plan, &id), - RF_PAGE_PROOF_DETAIL_EDGE_GAP); + RF_PAGE_PROOF_DETAIL_EDGE_GAP); set_component(&second, 0, 10, 1, 11, 12, false); UT_ASSERT_EQ(rf_page_online_plan_feed_record_v1(plan, &second.plan, &id), - RF_PAGE_PROOF_DETAIL_OK); - UT_ASSERT_EQ(rf_page_online_plan_seal_v1(plan), - RF_PAGE_PROOF_DETAIL_OK); + RF_PAGE_PROOF_DETAIL_OK); + UT_ASSERT_EQ(rf_page_online_plan_seal_v1(plan), RF_PAGE_PROOF_DETAIL_OK); rf_page_online_plan_destroy_v1(&plan); } @@ -319,9 +299,8 @@ UT_TEST(test_seal_requires_complete_physical_cut) set_component(&record, 0, 10, 1, 10, 11, true); id = record_identity(&record); UT_ASSERT_EQ(rf_page_online_plan_feed_record_v1(plan, &record.plan, &id), - RF_PAGE_PROOF_DETAIL_OK); - UT_ASSERT_EQ(rf_page_online_plan_seal_v1(plan), - RF_PAGE_PROOF_DETAIL_SOURCE_GAP); + RF_PAGE_PROOF_DETAIL_OK); + UT_ASSERT_EQ(rf_page_online_plan_seal_v1(plan), RF_PAGE_PROOF_DETAIL_SOURCE_GAP); rf_page_online_plan_destroy_v1(&plan); } @@ -337,10 +316,12 @@ UT_TEST(test_record_identity_binds_full_decoded_tuple) set_component(&record, 0, 10, 1, 10, 11, true); valid = record_identity(&record); -#define ASSERT_IDENTITY_REJECTED(statement_) \ - do { changed = valid; statement_; \ - UT_ASSERT_EQ(rf_page_online_plan_feed_record_v1(plan, \ - &record.plan, &changed), RF_PAGE_PROOF_DETAIL_IDENTITY_MISMATCH); \ +#define ASSERT_IDENTITY_REJECTED(statement_) \ + do { \ + changed = valid; \ + statement_; \ + UT_ASSERT_EQ(rf_page_online_plan_feed_record_v1(plan, &record.plan, &changed), \ + RF_PAGE_PROOF_DETAIL_IDENTITY_MISMATCH); \ } while (0) ASSERT_IDENTITY_REJECTED(changed.record.system_identifier++); ASSERT_IDENTITY_REJECTED(changed.record.storage_uuid[0]++); @@ -354,15 +335,15 @@ UT_TEST(test_record_identity_binds_full_decoded_tuple) saved_crc = record.storage.decoded.header.xl_crc; record.storage.decoded.header.xl_crc++; UT_ASSERT_EQ(rf_page_online_plan_feed_record_v1(plan, &record.plan, &valid), - RF_PAGE_PROOF_DETAIL_IDENTITY_MISMATCH); + RF_PAGE_PROOF_DETAIL_IDENTITY_MISMATCH); record.storage.decoded.header.xl_crc = saved_crc; record.storage.decoded.next_lsn++; UT_ASSERT_EQ(rf_page_online_plan_feed_record_v1(plan, &record.plan, &valid), - RF_PAGE_PROOF_DETAIL_IDENTITY_MISMATCH); + RF_PAGE_PROOF_DETAIL_IDENTITY_MISMATCH); record.storage.decoded.next_lsn--; UT_ASSERT_EQ(rf_page_online_plan_feed_record_v1(plan, &record.plan, &valid), - RF_PAGE_PROOF_DETAIL_OK); + RF_PAGE_PROOF_DETAIL_OK); UT_ASSERT_EQ(rf_page_online_plan_seal_v1(plan), RF_PAGE_PROOF_DETAIL_OK); rf_page_online_plan_destroy_v1(&plan); } diff --git a/src/test/cluster_unit/test_cluster_page_producer.c b/src/test/cluster_unit/test_cluster_page_producer.c index d80f7057eef..e47cf43a658 100644 --- a/src/test/cluster_unit/test_cluster_page_producer.c +++ b/src/test/cluster_unit/test_cluster_page_producer.c @@ -20,11 +20,9 @@ UT_DEFINE_GLOBALS(); void -ExceptionalCondition(const char *condition_name, const char *file_name, - int line_number) +ExceptionalCondition(const char *condition_name, const char *file_name, int line_number) { - printf("# Assert failed: %s at %s:%d\n", condition_name, file_name, - line_number); + printf("# Assert failed: %s at %s:%d\n", condition_name, file_name, line_number); abort(); } @@ -71,9 +69,8 @@ cluster_scn_observe(SCN token) } void -XLogRegisterPageVersionEdge(uint64 result_token, - const RfPageVersionEdgeEntryV1 *entries, - uint8 entry_count) +XLogRegisterPageVersionEdge(uint64 result_token, const RfPageVersionEdgeEntryV1 *entries, + uint8 entry_count) { register_calls++; registered_token = result_token; @@ -97,24 +94,23 @@ reset_allocator(SCN token) static void make_page(PGAlignedBlock *block, uint64 token) { - PageHeader header; + PageHeader header; memset(block, 0, sizeof(*block)); - header = (PageHeader) block->data; - if (token != 0) - { + header = (PageHeader)block->data; + if (token != 0) { header->pd_lower = SizeOfPageHeaderData; header->pd_upper = BLCKSZ; header->pd_special = BLCKSZ; header->pd_pagesize_version = BLCKSZ | PG_PAGE_LAYOUT_VERSION; } - header->pd_block_scn = (SCN) token; + header->pd_block_scn = (SCN)token; } static void set_incarnation(uint8 incarnation[16], uint8 seed) { - int i; + int i; for (i = 0; i < 16; i++) incarnation[i] = seed + i; @@ -137,17 +133,17 @@ ordinary_component(uint8 block_id, uint8 before_kind, Page page, uint8 seed) UT_TEST(test_token_next_delegates_once) { - reset_allocator((SCN) 901); + reset_allocator((SCN)901); UT_ASSERT_EQ(rf_page_mutation_token_next(), UINT64_C(901)); UT_ASSERT_EQ(advance_calls, 1); } UT_TEST(test_token_observe_delegates_exact_value) { - reset_allocator((SCN) 1); + reset_allocator((SCN)1); rf_page_mutation_token_observe(UINT64_C(777)); UT_ASSERT_EQ(observe_calls, 1); - UT_ASSERT_EQ(observed_token, (SCN) 777); + UT_ASSERT_EQ(observed_token, (SCN)777); } UT_TEST(test_prepare_captures_before_without_mutation) @@ -158,9 +154,9 @@ UT_TEST(test_prepare_captures_before_without_mutation) make_page(&page, 40); component = ordinary_component(0, RF_PAGE_STATE_PRESENT, page.data, 3); - reset_allocator((SCN) 41); + reset_allocator((SCN)41); UT_ASSERT(rf_page_producer_prepare_v1(&component, 1, &batch)); - UT_ASSERT_EQ(((PageHeader) page.data)->pd_block_scn, (SCN) 40); + UT_ASSERT_EQ(((PageHeader)page.data)->pd_block_scn, (SCN)40); UT_ASSERT_EQ(batch.entries[0].before.mutation_token, UINT64_C(40)); UT_ASSERT_EQ(batch.result_token, UINT64_C(41)); UT_ASSERT(!batch.stamped); @@ -174,10 +170,10 @@ UT_TEST(test_stamp_installs_result_token) make_page(&page, 40); component = ordinary_component(0, RF_PAGE_STATE_PRESENT, page.data, 3); - reset_allocator((SCN) 41); + reset_allocator((SCN)41); UT_ASSERT(rf_page_producer_prepare_v1(&component, 1, &batch)); UT_ASSERT(rf_page_producer_stamp_v1(&batch)); - UT_ASSERT_EQ(((PageHeader) page.data)->pd_block_scn, (SCN) 41); + UT_ASSERT_EQ(((PageHeader)page.data)->pd_block_scn, (SCN)41); UT_ASSERT(batch.stamped); } @@ -186,20 +182,18 @@ UT_TEST(test_multiblock_batch_uses_one_token) PGAlignedBlock pages[3]; RfPageProducerComponentV1 components[3]; RfPageProducerBatchV1 batch; - int i; + int i; - for (i = 0; i < 3; i++) - { + for (i = 0; i < 3; i++) { make_page(&pages[i], 10 + i); - components[i] = ordinary_component(i, RF_PAGE_STATE_PRESENT, - pages[i].data, 8); + components[i] = ordinary_component(i, RF_PAGE_STATE_PRESENT, pages[i].data, 8); } - reset_allocator((SCN) 88); + reset_allocator((SCN)88); UT_ASSERT(rf_page_producer_prepare_v1(components, 3, &batch)); UT_ASSERT_EQ(advance_calls, 1); UT_ASSERT(rf_page_producer_stamp_v1(&batch)); for (i = 0; i < 3; i++) - UT_ASSERT_EQ(((PageHeader) pages[i].data)->pd_block_scn, (SCN) 88); + UT_ASSERT_EQ(((PageHeader)pages[i].data)->pd_block_scn, (SCN)88); } UT_TEST(test_routed_component_has_zero_version_and_no_page) @@ -210,7 +204,7 @@ UT_TEST(test_routed_component_has_zero_version_and_no_page) memset(&component, 0, sizeof(component)); component.page_class = RF_PAGE_CLASS_ROUTED_SIDE; component.before_kind = RF_PAGE_STATE_ROUTED; - reset_allocator((SCN) 55); + reset_allocator((SCN)55); UT_ASSERT(rf_page_producer_prepare_v1(&component, 1, &batch)); UT_ASSERT_EQ(batch.entries[0].result_kind, RF_PAGE_STATE_ROUTED); UT_ASSERT_EQ(batch.entries[0].before.mutation_token, 0); @@ -222,10 +216,10 @@ UT_TEST(test_invalid_count_never_allocates_token) RfPageProducerBatchV1 batch; memset(&batch, 0x5a, sizeof(batch)); - reset_allocator((SCN) 60); + reset_allocator((SCN)60); UT_ASSERT(!rf_page_producer_prepare_v1(NULL, 0, &batch)); UT_ASSERT_EQ(advance_calls, 0); - UT_ASSERT_EQ(((unsigned char *) &batch)[0], 0x5a); + UT_ASSERT_EQ(((unsigned char *)&batch)[0], 0x5a); } UT_TEST(test_unsorted_block_ids_fail_before_token) @@ -236,13 +230,11 @@ UT_TEST(test_unsorted_block_ids_fail_before_token) make_page(&pages[0], 1); make_page(&pages[1], 2); - components[0] = ordinary_component(1, RF_PAGE_STATE_PRESENT, - pages[0].data, 2); + components[0] = ordinary_component(1, RF_PAGE_STATE_PRESENT, pages[0].data, 2); components[0].component_ordinal = 0; - components[1] = ordinary_component(0, RF_PAGE_STATE_PRESENT, - pages[1].data, 2); + components[1] = ordinary_component(0, RF_PAGE_STATE_PRESENT, pages[1].data, 2); components[1].component_ordinal = 1; - reset_allocator((SCN) 3); + reset_allocator((SCN)3); UT_ASSERT(!rf_page_producer_prepare_v1(components, 2, &batch)); UT_ASSERT_EQ(advance_calls, 0); } @@ -256,7 +248,7 @@ UT_TEST(test_duplicate_page_fails_before_token) make_page(&page, 1); components[0] = ordinary_component(0, RF_PAGE_STATE_PRESENT, page.data, 2); components[1] = ordinary_component(1, RF_PAGE_STATE_PRESENT, page.data, 2); - reset_allocator((SCN) 3); + reset_allocator((SCN)3); UT_ASSERT(!rf_page_producer_prepare_v1(components, 2, &batch)); UT_ASSERT_EQ(advance_calls, 0); } @@ -270,7 +262,7 @@ UT_TEST(test_zero_incarnation_fails_before_token) make_page(&page, 1); component = ordinary_component(0, RF_PAGE_STATE_PRESENT, page.data, 2); memset(component.segment_incarnation, 0, 16); - reset_allocator((SCN) 3); + reset_allocator((SCN)3); UT_ASSERT(!rf_page_producer_prepare_v1(&component, 1, &batch)); UT_ASSERT_EQ(advance_calls, 0); } @@ -286,8 +278,8 @@ UT_TEST(test_zero_allocator_result_leaves_page_and_output_untouched) memset(&batch, 0x6b, sizeof(batch)); reset_allocator(InvalidScn); UT_ASSERT(!rf_page_producer_prepare_v1(&component, 1, &batch)); - UT_ASSERT_EQ(((PageHeader) page.data)->pd_block_scn, (SCN) 9); - UT_ASSERT_EQ(((unsigned char *) &batch)[0], 0x6b); + UT_ASSERT_EQ(((PageHeader)page.data)->pd_block_scn, (SCN)9); + UT_ASSERT_EQ(((unsigned char *)&batch)[0], 0x6b); } UT_TEST(test_stamp_drift_is_zero_mutation_for_whole_batch) @@ -298,16 +290,14 @@ UT_TEST(test_stamp_drift_is_zero_mutation_for_whole_batch) make_page(&pages[0], 10); make_page(&pages[1], 20); - components[0] = ordinary_component(0, RF_PAGE_STATE_PRESENT, - pages[0].data, 2); - components[1] = ordinary_component(1, RF_PAGE_STATE_PRESENT, - pages[1].data, 2); - reset_allocator((SCN) 30); + components[0] = ordinary_component(0, RF_PAGE_STATE_PRESENT, pages[0].data, 2); + components[1] = ordinary_component(1, RF_PAGE_STATE_PRESENT, pages[1].data, 2); + reset_allocator((SCN)30); UT_ASSERT(rf_page_producer_prepare_v1(components, 2, &batch)); - ((PageHeader) pages[1].data)->pd_block_scn = (SCN) 21; + ((PageHeader)pages[1].data)->pd_block_scn = (SCN)21; UT_ASSERT(!rf_page_producer_stamp_v1(&batch)); - UT_ASSERT_EQ(((PageHeader) pages[0].data)->pd_block_scn, (SCN) 10); - UT_ASSERT_EQ(((PageHeader) pages[1].data)->pd_block_scn, (SCN) 21); + UT_ASSERT_EQ(((PageHeader)pages[0].data)->pd_block_scn, (SCN)10); + UT_ASSERT_EQ(((PageHeader)pages[1].data)->pd_block_scn, (SCN)21); } UT_TEST(test_absent_and_unformatted_before_shapes) @@ -315,23 +305,22 @@ UT_TEST(test_absent_and_unformatted_before_shapes) PGAlignedBlock pages[2]; RfPageProducerComponentV1 components[2]; RfPageProducerBatchV1 batch; - int i; + int i; make_page(&pages[0], 0); make_page(&pages[1], 0); - components[0] = ordinary_component(0, RF_PAGE_STATE_ABSENT, - pages[0].data, 4); - components[1] = ordinary_component(1, RF_PAGE_STATE_UNFORMATTED, - pages[1].data, 4); - reset_allocator((SCN) 44); + components[0] = ordinary_component(0, RF_PAGE_STATE_ABSENT, pages[0].data, 4); + components[1] = ordinary_component(1, RF_PAGE_STATE_UNFORMATTED, pages[1].data, 4); + reset_allocator((SCN)44); UT_ASSERT(rf_page_producer_prepare_v1(components, 2, &batch)); for (i = 0; i < 16; i++) UT_ASSERT_EQ(batch.entries[0].before.segment_incarnation[i], 0); - UT_ASSERT(memcmp(batch.entries[1].before.segment_incarnation, - components[1].segment_incarnation, 16) == 0); + UT_ASSERT( + memcmp(batch.entries[1].before.segment_incarnation, components[1].segment_incarnation, 16) + == 0); UT_ASSERT(rf_page_producer_stamp_v1(&batch)); - UT_ASSERT_EQ(((PageHeader) pages[0].data)->pd_block_scn, (SCN) 44); - UT_ASSERT_EQ(((PageHeader) pages[1].data)->pd_block_scn, (SCN) 44); + UT_ASSERT_EQ(((PageHeader)pages[0].data)->pd_block_scn, (SCN)44); + UT_ASSERT_EQ(((PageHeader)pages[1].data)->pd_block_scn, (SCN)44); } UT_TEST(test_stamp_retry_is_idempotent) @@ -342,11 +331,11 @@ UT_TEST(test_stamp_retry_is_idempotent) make_page(&page, 7); component = ordinary_component(0, RF_PAGE_STATE_PRESENT, page.data, 5); - reset_allocator((SCN) 8); + reset_allocator((SCN)8); UT_ASSERT(rf_page_producer_prepare_v1(&component, 1, &batch)); UT_ASSERT(rf_page_producer_stamp_v1(&batch)); UT_ASSERT(rf_page_producer_stamp_v1(&batch)); - UT_ASSERT_EQ(((PageHeader) page.data)->pd_block_scn, (SCN) 8); + UT_ASSERT_EQ(((PageHeader)page.data)->pd_block_scn, (SCN)8); } UT_TEST(test_wal_registration_requires_stamped_batch) @@ -357,7 +346,7 @@ UT_TEST(test_wal_registration_requires_stamped_batch) make_page(&page, 7); component = ordinary_component(0, RF_PAGE_STATE_PRESENT, page.data, 5); - reset_allocator((SCN) 8); + reset_allocator((SCN)8); UT_ASSERT(rf_page_producer_prepare_v1(&component, 1, &batch)); UT_ASSERT(!rf_page_producer_register_wal_v1(&batch)); UT_ASSERT_EQ(register_calls, 0); @@ -371,15 +360,14 @@ UT_TEST(test_wal_registration_forwards_exact_batch) make_page(&page, 7); component = ordinary_component(0, RF_PAGE_STATE_PRESENT, page.data, 5); - reset_allocator((SCN) 8); + reset_allocator((SCN)8); UT_ASSERT(rf_page_producer_prepare_v1(&component, 1, &batch)); UT_ASSERT(rf_page_producer_stamp_v1(&batch)); UT_ASSERT(rf_page_producer_register_wal_v1(&batch)); UT_ASSERT_EQ(register_calls, 1); UT_ASSERT_EQ(registered_token, UINT64_C(8)); UT_ASSERT_EQ(registered_count, 1); - UT_ASSERT(memcmp(®istered_entries[0], &batch.entries[0], - sizeof(batch.entries[0])) == 0); + UT_ASSERT(memcmp(®istered_entries[0], &batch.entries[0], sizeof(batch.entries[0])) == 0); } UT_TEST(test_wal_registration_revalidates_stamped_pages) @@ -390,10 +378,10 @@ UT_TEST(test_wal_registration_revalidates_stamped_pages) make_page(&page, 7); component = ordinary_component(0, RF_PAGE_STATE_PRESENT, page.data, 5); - reset_allocator((SCN) 8); + reset_allocator((SCN)8); UT_ASSERT(rf_page_producer_prepare_v1(&component, 1, &batch)); UT_ASSERT(rf_page_producer_stamp_v1(&batch)); - ((PageHeader) page.data)->pd_block_scn = (SCN) 9; + ((PageHeader)page.data)->pd_block_scn = (SCN)9; UT_ASSERT(!rf_page_producer_register_wal_v1(&batch)); UT_ASSERT_EQ(register_calls, 0); } diff --git a/src/test/cluster_unit/test_cluster_page_recovery.c b/src/test/cluster_unit/test_cluster_page_recovery.c index 3cdd0146452..c6c5fadfcd4 100644 --- a/src/test/cluster_unit/test_cluster_page_recovery.c +++ b/src/test/cluster_unit/test_cluster_page_recovery.c @@ -38,48 +38,36 @@ ExceptionalCondition(const char *conditionName pg_attribute_unused(), UT_TEST(test_action_table_closed_rows) { /* §4.1 recovery-action column, one row per class. */ - UT_ASSERT_EQ((int) cluster_page_class_recovery_action( - CLUSTER_PAGE_CLASS_NORMAL), - (int) CLUSTER_PAGE_ACTION_APPLY); - UT_ASSERT_EQ((int) cluster_page_class_recovery_action( - CLUSTER_PAGE_CLASS_CLEANOUT), - (int) CLUSTER_PAGE_ACTION_APPLY); - UT_ASSERT_EQ((int) cluster_page_class_recovery_action( - CLUSTER_PAGE_CLASS_NEW), - (int) CLUSTER_PAGE_ACTION_INIT); - UT_ASSERT_EQ((int) cluster_page_class_recovery_action( - CLUSTER_PAGE_CLASS_INCARNATION), - (int) CLUSTER_PAGE_ACTION_INCARNATE); - UT_ASSERT_EQ((int) cluster_page_class_recovery_action( - CLUSTER_PAGE_CLASS_TEMP), - (int) CLUSTER_PAGE_ACTION_DISCARD); - UT_ASSERT_EQ((int) cluster_page_class_recovery_action( - CLUSTER_PAGE_CLASS_REBUILDABLE), - (int) CLUSTER_PAGE_ACTION_REBUILD); - UT_ASSERT_EQ((int) cluster_page_class_recovery_action( - CLUSTER_PAGE_CLASS_HEADER), - (int) CLUSTER_PAGE_ACTION_ROUTE); - UT_ASSERT_EQ((int) cluster_page_class_recovery_action( - CLUSTER_PAGE_CLASS_FULLIMAGE), - (int) CLUSTER_PAGE_ACTION_IMAGE); - UT_ASSERT_EQ((int) cluster_page_class_recovery_action( - CLUSTER_PAGE_CLASS_NONLOGGED), - (int) CLUSTER_PAGE_ACTION_REBUILD); + UT_ASSERT_EQ((int)cluster_page_class_recovery_action(CLUSTER_PAGE_CLASS_NORMAL), + (int)CLUSTER_PAGE_ACTION_APPLY); + UT_ASSERT_EQ((int)cluster_page_class_recovery_action(CLUSTER_PAGE_CLASS_CLEANOUT), + (int)CLUSTER_PAGE_ACTION_APPLY); + UT_ASSERT_EQ((int)cluster_page_class_recovery_action(CLUSTER_PAGE_CLASS_NEW), + (int)CLUSTER_PAGE_ACTION_INIT); + UT_ASSERT_EQ((int)cluster_page_class_recovery_action(CLUSTER_PAGE_CLASS_INCARNATION), + (int)CLUSTER_PAGE_ACTION_INCARNATE); + UT_ASSERT_EQ((int)cluster_page_class_recovery_action(CLUSTER_PAGE_CLASS_TEMP), + (int)CLUSTER_PAGE_ACTION_DISCARD); + UT_ASSERT_EQ((int)cluster_page_class_recovery_action(CLUSTER_PAGE_CLASS_REBUILDABLE), + (int)CLUSTER_PAGE_ACTION_REBUILD); + UT_ASSERT_EQ((int)cluster_page_class_recovery_action(CLUSTER_PAGE_CLASS_HEADER), + (int)CLUSTER_PAGE_ACTION_ROUTE); + UT_ASSERT_EQ((int)cluster_page_class_recovery_action(CLUSTER_PAGE_CLASS_FULLIMAGE), + (int)CLUSTER_PAGE_ACTION_IMAGE); + UT_ASSERT_EQ((int)cluster_page_class_recovery_action(CLUSTER_PAGE_CLASS_NONLOGGED), + (int)CLUSTER_PAGE_ACTION_REBUILD); } UT_TEST(test_action_unknown_default_blocked) { /* "unknown default 必须 BLOCKED" (PGDEL-03) — UNKNOWN, UNCLASSIFIED * and the WILLINIT-without-rule row are all mutation=0. */ - UT_ASSERT_EQ((int) cluster_page_class_recovery_action( - CLUSTER_PAGE_CLASS_UNKNOWN), - (int) CLUSTER_PAGE_ACTION_BLOCKED); - UT_ASSERT_EQ((int) cluster_page_class_recovery_action( - CLUSTER_PAGE_CLASS_UNCLASSIFIED), - (int) CLUSTER_PAGE_ACTION_BLOCKED); - UT_ASSERT_EQ((int) cluster_page_class_recovery_action( - CLUSTER_PAGE_CLASS_WILLINIT), - (int) CLUSTER_PAGE_ACTION_BLOCKED); + UT_ASSERT_EQ((int)cluster_page_class_recovery_action(CLUSTER_PAGE_CLASS_UNKNOWN), + (int)CLUSTER_PAGE_ACTION_BLOCKED); + UT_ASSERT_EQ((int)cluster_page_class_recovery_action(CLUSTER_PAGE_CLASS_UNCLASSIFIED), + (int)CLUSTER_PAGE_ACTION_BLOCKED); + UT_ASSERT_EQ((int)cluster_page_class_recovery_action(CLUSTER_PAGE_CLASS_WILLINIT), + (int)CLUSTER_PAGE_ACTION_BLOCKED); } UT_TEST(test_state_machine_adjacent_advance) @@ -88,7 +76,7 @@ UT_TEST(test_state_machine_adjacent_advance) /* The full §3.5 chain, one adjacent step at a time. */ UT_ASSERT(cluster_page_state_advance(&st, CLUSTER_PAGE_STATE_CLASSIFIED)); - UT_ASSERT_EQ((int) st, (int) CLUSTER_PAGE_STATE_CLASSIFIED); + UT_ASSERT_EQ((int)st, (int)CLUSTER_PAGE_STATE_CLASSIFIED); UT_ASSERT(cluster_page_state_advance(&st, CLUSTER_PAGE_STATE_SOURCE_PROVEN)); UT_ASSERT(cluster_page_state_advance(&st, CLUSTER_PAGE_STATE_CONTRIBUTORS_CLOSED)); UT_ASSERT(cluster_page_state_advance(&st, CLUSTER_PAGE_STATE_VERSION_CHAIN_VERIFIED)); @@ -100,7 +88,7 @@ UT_TEST(test_state_machine_adjacent_advance) UT_ASSERT(cluster_page_state_advance(&st, CLUSTER_PAGE_STATE_RESOURCE_RELEASED)); /* Terminal: no further advance. */ UT_ASSERT(!cluster_page_state_advance(&st, CLUSTER_PAGE_STATE_RESOURCE_RELEASED + 1)); - UT_ASSERT_EQ((int) st, (int) CLUSTER_PAGE_STATE_RESOURCE_RELEASED); + UT_ASSERT_EQ((int)st, (int)CLUSTER_PAGE_STATE_RESOURCE_RELEASED); } UT_TEST(test_state_machine_rejects_jumps_and_repeats) @@ -109,7 +97,7 @@ UT_TEST(test_state_machine_rejects_jumps_and_repeats) /* A jump skips a proof step: rejected, state unchanged. */ UT_ASSERT(!cluster_page_state_advance(&st, CLUSTER_PAGE_STATE_SOURCE_PROVEN)); - UT_ASSERT_EQ((int) st, (int) CLUSTER_PAGE_STATE_UNCLASSIFIED); + UT_ASSERT_EQ((int)st, (int)CLUSTER_PAGE_STATE_UNCLASSIFIED); /* A repeat of the same step is not an advance. */ UT_ASSERT(!cluster_page_state_advance(&st, CLUSTER_PAGE_STATE_UNCLASSIFIED)); /* NULL state. */ @@ -117,26 +105,26 @@ UT_TEST(test_state_machine_rejects_jumps_and_repeats) /* Advancing from a valid state to itself is rejected too. */ UT_ASSERT(cluster_page_state_advance(&st, CLUSTER_PAGE_STATE_CLASSIFIED)); UT_ASSERT(!cluster_page_state_advance(&st, CLUSTER_PAGE_STATE_CLASSIFIED)); - UT_ASSERT_EQ((int) st, (int) CLUSTER_PAGE_STATE_CLASSIFIED); + UT_ASSERT_EQ((int)st, (int)CLUSTER_PAGE_STATE_CLASSIFIED); } UT_TEST(test_dispatcher_verdict_combination) { /* APPLY / SKIP come straight from the §3.2 gate. */ - UT_ASSERT_EQ((int) cluster_page_dispatcher_verdict( - CLUSTER_PAGE_CLASS_NORMAL, CLUSTER_PAGE_APPLY_APPLY), - (int) CLUSTER_PAGE_OUTCOME_APPLY); - UT_ASSERT_EQ((int) cluster_page_dispatcher_verdict( - CLUSTER_PAGE_CLASS_NORMAL, CLUSTER_PAGE_APPLY_SKIP), - (int) CLUSTER_PAGE_OUTCOME_SKIP); + UT_ASSERT_EQ( + (int)cluster_page_dispatcher_verdict(CLUSTER_PAGE_CLASS_NORMAL, CLUSTER_PAGE_APPLY_APPLY), + (int)CLUSTER_PAGE_OUTCOME_APPLY); + UT_ASSERT_EQ( + (int)cluster_page_dispatcher_verdict(CLUSTER_PAGE_CLASS_NORMAL, CLUSTER_PAGE_APPLY_SKIP), + (int)CLUSTER_PAGE_OUTCOME_SKIP); /* Any blocked verdict from the class layer is BLOCKED_CLASS (the * finer subdivisions belong to the PGDEL-04..06 proof owners). */ - UT_ASSERT_EQ((int) cluster_page_dispatcher_verdict( - CLUSTER_PAGE_CLASS_NORMAL, CLUSTER_PAGE_APPLY_BLOCKED), - (int) CLUSTER_PAGE_OUTCOME_BLOCKED_CLASS); - UT_ASSERT_EQ((int) cluster_page_dispatcher_verdict( - CLUSTER_PAGE_CLASS_UNKNOWN, CLUSTER_PAGE_APPLY_BLOCKED), - (int) CLUSTER_PAGE_OUTCOME_BLOCKED_CLASS); + UT_ASSERT_EQ( + (int)cluster_page_dispatcher_verdict(CLUSTER_PAGE_CLASS_NORMAL, CLUSTER_PAGE_APPLY_BLOCKED), + (int)CLUSTER_PAGE_OUTCOME_BLOCKED_CLASS); + UT_ASSERT_EQ((int)cluster_page_dispatcher_verdict(CLUSTER_PAGE_CLASS_UNKNOWN, + CLUSTER_PAGE_APPLY_BLOCKED), + (int)CLUSTER_PAGE_OUTCOME_BLOCKED_CLASS); } int diff --git a/src/test/cluster_unit/test_cluster_page_recovery_matrix.c b/src/test/cluster_unit/test_cluster_page_recovery_matrix.c index e0d4f6ce3c4..203cc14c1ad 100644 --- a/src/test/cluster_unit/test_cluster_page_recovery_matrix.c +++ b/src/test/cluster_unit/test_cluster_page_recovery_matrix.c @@ -71,7 +71,7 @@ static ClusterPageRedoChange ut_changes[3]; static void ut_setup_globals(void) { - int i; + int i; memset(&ut_id, 0, sizeof(ut_id)); ut_id.rlocator.spcOid = 1; @@ -84,7 +84,7 @@ ut_setup_globals(void) memset(&ut_v[i], 0, sizeof(ut_v[i])); ut_v[i].identity = ut_id; ut_v[i].incarnation = 7; - ut_v[i].token = (uint64) (100 + i); + ut_v[i].token = (uint64)(100 + i); } for (i = 0; i < 3; i++) { memset(&ut_changes[i], 0, sizeof(ut_changes[i])); @@ -105,14 +105,12 @@ UT_TEST(test_pu09_pu10_new_init_and_missing_lifecycle) memset(&cin, 0, sizeof(cin)); cin.rmid = 10; - cin.opcode = 0x80; /* INIT_PAGE-shaped */ + cin.opcode = 0x80; /* INIT_PAGE-shaped */ cin.forknum = MAIN_FORKNUM; cin.page_absent = true; - UT_ASSERT_EQ((int) cluster_page_classify(&cin), - (int) CLUSTER_PAGE_CLASS_NEW); - UT_ASSERT_EQ((int) cluster_page_class_recovery_action( - CLUSTER_PAGE_CLASS_NEW), - (int) CLUSTER_PAGE_ACTION_INIT); + UT_ASSERT_EQ((int)cluster_page_classify(&cin), (int)CLUSTER_PAGE_CLASS_NEW); + UT_ASSERT_EQ((int)cluster_page_class_recovery_action(CLUSTER_PAGE_CLASS_NEW), + (int)CLUSTER_PAGE_ACTION_INIT); /* PU-09: the typed UNFORMATTED before-state is present and exact. */ memset(&before, 0, sizeof(before)); @@ -141,11 +139,9 @@ UT_TEST(test_pu12_temp_discard_only_with_owner_proof) cin.rmid = 10; cin.opcode = 0x10; cin.forknum = INIT_FORKNUM; - UT_ASSERT_EQ((int) cluster_page_classify(&cin), - (int) CLUSTER_PAGE_CLASS_TEMP); - UT_ASSERT_EQ((int) cluster_page_class_recovery_action( - CLUSTER_PAGE_CLASS_TEMP), - (int) CLUSTER_PAGE_ACTION_DISCARD); + UT_ASSERT_EQ((int)cluster_page_classify(&cin), (int)CLUSTER_PAGE_CLASS_TEMP); + UT_ASSERT_EQ((int)cluster_page_class_recovery_action(CLUSTER_PAGE_CLASS_TEMP), + (int)CLUSTER_PAGE_ACTION_DISCARD); /* The owner/lifecycle proof is the apply layer's; classification and * action assignment are what the class layer can promise. */ } @@ -162,11 +158,9 @@ UT_TEST(test_pu15_pu16_fpi_provenance) cin.opcode = 0x10; cin.forknum = MAIN_FORKNUM; cin.has_full_page_image = true; - UT_ASSERT_EQ((int) cluster_page_classify(&cin), - (int) CLUSTER_PAGE_CLASS_FULLIMAGE); - UT_ASSERT_EQ((int) cluster_page_class_recovery_action( - CLUSTER_PAGE_CLASS_FULLIMAGE), - (int) CLUSTER_PAGE_ACTION_IMAGE); + UT_ASSERT_EQ((int)cluster_page_classify(&cin), (int)CLUSTER_PAGE_CLASS_FULLIMAGE); + UT_ASSERT_EQ((int)cluster_page_class_recovery_action(CLUSTER_PAGE_CLASS_FULLIMAGE), + (int)CLUSTER_PAGE_ACTION_IMAGE); /* PU-15: a valid source (integrity + lineage + owner) admits the * image payload path. */ @@ -199,11 +193,9 @@ UT_TEST(test_pu18_pu19_cleanout) cin.forknum = MAIN_FORKNUM; cin.is_cleanout = true; /* Class identifiable from the declaration... */ - UT_ASSERT_EQ((int) cluster_page_classify(&cin), - (int) CLUSTER_PAGE_CLASS_CLEANOUT); - UT_ASSERT_EQ((int) cluster_page_class_recovery_action( - CLUSTER_PAGE_CLASS_CLEANOUT), - (int) CLUSTER_PAGE_ACTION_APPLY); + UT_ASSERT_EQ((int)cluster_page_classify(&cin), (int)CLUSTER_PAGE_CLASS_CLEANOUT); + UT_ASSERT_EQ((int)cluster_page_class_recovery_action(CLUSTER_PAGE_CLASS_CLEANOUT), + (int)CLUSTER_PAGE_ACTION_APPLY); /* ...but the exact codec census is RED: the deterministic apply is * the apply layer's promise (PGDEL-06), and the decoder_registered * flag is false for every census row (PU-19: unknown codec stays @@ -213,8 +205,7 @@ UT_TEST(test_pu18_pu19_cleanout) * classifier returns UNKNOWN (BLOCKED). */ cin.is_cleanout = true; cin.has_will_init = true; - UT_ASSERT_EQ((int) cluster_page_classify(&cin), - (int) CLUSTER_PAGE_CLASS_UNKNOWN); + UT_ASSERT_EQ((int)cluster_page_classify(&cin), (int)CLUSTER_PAGE_CLASS_UNKNOWN); } /* PU-20/PU-21: nonlogged. */ @@ -227,14 +218,12 @@ UT_TEST(test_pu20_pu21_nonlogged) cin.opcode = 0x10; cin.forknum = MAIN_FORKNUM; cin.relation_is_unlogged = true; - UT_ASSERT_EQ((int) cluster_page_classify(&cin), - (int) CLUSTER_PAGE_CLASS_NONLOGGED); + UT_ASSERT_EQ((int)cluster_page_classify(&cin), (int)CLUSTER_PAGE_CLASS_NONLOGGED); /* Typed rebuild action; the rebuild owner proof is the apply layer's * — without it the resource stays BLOCKED (PU-21), which the action * table's REBUILD + the apply-layer owner gate express. */ - UT_ASSERT_EQ((int) cluster_page_class_recovery_action( - CLUSTER_PAGE_CLASS_NONLOGGED), - (int) CLUSTER_PAGE_ACTION_REBUILD); + UT_ASSERT_EQ((int)cluster_page_class_recovery_action(CLUSTER_PAGE_CLASS_NONLOGGED), + (int)CLUSTER_PAGE_ACTION_REBUILD); } /* PU-11/PU-27: incarnation cross + cross-thread rejection. */ @@ -254,12 +243,12 @@ UT_TEST(test_pu11_pu27_old_contributors_rejected) set.contributors = ut_changes; set.n_contributors = 2; old_inc = ut_v[1]; - old_inc.incarnation = 6; /* old incarnation */ + old_inc.incarnation = 6; /* old incarnation */ ut_changes[1].expected_before = old_inc; ut_changes[1].result_version = old_inc; ut_changes[1].result_version.token = 102; - UT_ASSERT_EQ((int) cluster_page_contributor_closure(&set), - (int) CLUSTER_PAGE_CLOSURE_INCARNATION_CROSS); + UT_ASSERT_EQ((int)cluster_page_contributor_closure(&set), + (int)CLUSTER_PAGE_CLOSURE_INCARNATION_CROSS); /* PU-27: a contributor of another failed origin is never part of * this block's chain (raw cross-thread LSN has no global ordering). */ @@ -268,8 +257,8 @@ UT_TEST(test_pu11_pu27_old_contributors_rejected) ut_changes[1].expected_before = ut_v[1]; ut_changes[1].result_version = ut_v[2]; ut_changes[1].failed_origin_thread = 3; /* other origin */ - UT_ASSERT_EQ((int) cluster_page_contributor_closure(&set), - (int) CLUSTER_PAGE_CLOSURE_THREAD_MISMATCH); + UT_ASSERT_EQ((int)cluster_page_contributor_closure(&set), + (int)CLUSTER_PAGE_CLOSURE_THREAD_MISMATCH); } /* PL face: crash-cut legs judged through the §7.7 matrix. */ @@ -277,26 +266,24 @@ UT_TEST(test_pl_legs_unit_level) { /* PL-01 death before source proof -> successor re-census (BLOCKED_ * SOURCE). */ - UT_ASSERT_EQ((int) cluster_page_crash_matrix_verdict( - CLUSTER_PAGE_CUT_BEFORE_SOURCE_PROOF), - (int) CLUSTER_PAGE_OUTCOME_BLOCKED_SOURCE); + UT_ASSERT_EQ((int)cluster_page_crash_matrix_verdict(CLUSTER_PAGE_CUT_BEFORE_SOURCE_PROOF), + (int)CLUSTER_PAGE_OUTCOME_BLOCKED_SOURCE); /* PL-02 after contributor closure -> local plan ignored (D3′). */ - UT_ASSERT_EQ((int) cluster_page_crash_matrix_verdict( - CLUSTER_PAGE_CUT_AFTER_SOURCE_PROOF), - (int) CLUSTER_PAGE_OUTCOME_BLOCKED_SOURCE); + UT_ASSERT_EQ((int)cluster_page_crash_matrix_verdict(CLUSTER_PAGE_CUT_AFTER_SOURCE_PROOF), + (int)CLUSTER_PAGE_OUTCOME_BLOCKED_SOURCE); /* PL-03 during target write -> RED/STOP, always. */ - UT_ASSERT_EQ((int) cluster_page_apply_midwrite_cut(), - (int) CLUSTER_PAGE_OUTCOME_STABLE_BASE_UNRESOLVED); + UT_ASSERT_EQ((int)cluster_page_apply_midwrite_cut(), + (int)CLUSTER_PAGE_OUTCOME_STABLE_BASE_UNRESOLVED); /* PL-04/05/06 map onto the matrix rows. */ - UT_ASSERT_EQ((int) cluster_page_crash_matrix_verdict( - CLUSTER_PAGE_CUT_AFTER_WRITE_BEFORE_DURABILITY), - (int) CLUSTER_PAGE_OUTCOME_BLOCKED_SOURCE); - UT_ASSERT_EQ((int) cluster_page_crash_matrix_verdict( - CLUSTER_PAGE_CUT_AFTER_DURABILITY_BEFORE_POST_READ), - (int) CLUSTER_PAGE_OUTCOME_BLOCKED_SOURCE); - UT_ASSERT_EQ((int) cluster_page_crash_matrix_verdict( - CLUSTER_PAGE_CUT_AFTER_POST_READ_BEFORE_RELEASE), - (int) CLUSTER_PAGE_OUTCOME_STALE_AUTHORITY); + UT_ASSERT_EQ( + (int)cluster_page_crash_matrix_verdict(CLUSTER_PAGE_CUT_AFTER_WRITE_BEFORE_DURABILITY), + (int)CLUSTER_PAGE_OUTCOME_BLOCKED_SOURCE); + UT_ASSERT_EQ( + (int)cluster_page_crash_matrix_verdict(CLUSTER_PAGE_CUT_AFTER_DURABILITY_BEFORE_POST_READ), + (int)CLUSTER_PAGE_OUTCOME_BLOCKED_SOURCE); + UT_ASSERT_EQ( + (int)cluster_page_crash_matrix_verdict(CLUSTER_PAGE_CUT_AFTER_POST_READ_BEFORE_RELEASE), + (int)CLUSTER_PAGE_OUTCOME_STALE_AUTHORITY); /* PL-12 retire-before-proof -> denied. */ { ClusterPageHandoffInput hi; diff --git a/src/test/cluster_unit/test_cluster_page_replay_batch.c b/src/test/cluster_unit/test_cluster_page_replay_batch.c index 9b08a274824..7877ae167b6 100644 --- a/src/test/cluster_unit/test_cluster_page_replay_batch.c +++ b/src/test/cluster_unit/test_cluster_page_replay_batch.c @@ -22,11 +22,9 @@ UT_DEFINE_GLOBALS(); void -ExceptionalCondition(const char *condition_name, const char *file_name, - int line_number) +ExceptionalCondition(const char *condition_name, const char *file_name, int line_number) { - printf("# unexpected Assert: %s at %s:%d\n", condition_name, file_name, - line_number); + printf("# unexpected Assert: %s at %s:%d\n", condition_name, file_name, line_number); abort(); } @@ -49,38 +47,34 @@ main(void) #else -typedef struct FakeRecord -{ +typedef struct FakeRecord { XLogReaderState state; - union - { + union { DecodedXLogRecord decoded; - char padding[sizeof(DecodedXLogRecord) + - XLR_PAGE_VERSION_EDGE_MAX_ENTRIES * sizeof(DecodedBkpBlock)]; + char padding[sizeof(DecodedXLogRecord) + + XLR_PAGE_VERSION_EDGE_MAX_ENTRIES * sizeof(DecodedBkpBlock)]; } storage; } FakeRecord; -typedef struct BatchFixture -{ +typedef struct BatchFixture { PGAlignedBlock disk[RF_PAGE_STABLE_MAX_COMPONENTS]; - bool exists[RF_PAGE_STABLE_MAX_COMPONENTS]; - int read_calls; - int write_calls; - int sync_calls; - int promote_calls; - int publish_calls; - int release_calls; - bool last_extend; + bool exists[RF_PAGE_STABLE_MAX_COMPONENTS]; + int read_calls; + int write_calls; + int sync_calls; + int promote_calls; + int publish_calls; + int release_calls; + bool last_extend; } BatchFixture; -typedef struct BatchCase -{ +typedef struct BatchCase { BatchFixture fixture; FakeRecord records[4]; RfDetachedRecordPlanV1 plans[4]; RfPageReplayRecordV1 replay_records[4]; RfContributorStreamCutV1 participants[2]; - uint8 record_component_seen[4][RF_PAGE_STABLE_MAX_COMPONENTS]; + uint8 record_component_seen[4][RF_PAGE_STABLE_MAX_COMPONENTS]; RfPageReplayStepV1 steps[RF_PAGE_STABLE_MAX_COMPONENTS][2]; RfPageReplayTargetV1 targets[RF_PAGE_STABLE_MAX_COMPONENTS]; PGAlignedBlock base[RF_PAGE_STABLE_MAX_COMPONENTS]; @@ -104,35 +98,32 @@ set_incarnation(uint8 incarnation[16], uint8 value) static void init_page(char page[BLCKSZ], uint64 token, uint8 payload) { - PageHeader header; + PageHeader header; memset(page, payload, BLCKSZ); - header = (PageHeader) page; + header = (PageHeader)page; memset(header, 0, SizeOfPageHeaderData); header->pd_lower = SizeOfPageHeaderData; header->pd_upper = BLCKSZ; header->pd_special = BLCKSZ; - header->pd_pagesize_version = - (BLCKSZ & 0xFF00) | PG_PAGE_LAYOUT_VERSION; + header->pd_pagesize_version = (BLCKSZ & 0xFF00) | PG_PAGE_LAYOUT_VERSION; header->pd_block_scn = token; } bool rf_page_identity_valid_v1(const RfPageIdentityV1 *identity) { - return identity != NULL && identity->system_identifier != 0 && - identity->locator.spcOid != InvalidOid && - identity->locator.dbOid != InvalidOid && - identity->locator.relNumber != InvalidRelFileNumber && - identity->blockno != InvalidBlockNumber && - identity->reserved_zero == 0; + return identity != NULL && identity->system_identifier != 0 + && identity->locator.spcOid != InvalidOid && identity->locator.dbOid != InvalidOid + && identity->locator.relNumber != InvalidRelFileNumber + && identity->blockno != InvalidBlockNumber && identity->reserved_zero == 0; } bool rf_page_version_present_v1(const RfPageVersionV1 *version) { - uint8 value = 0; - int i; + uint8 value = 0; + int i; if (version == NULL || version->mutation_token == 0) return false; @@ -142,43 +133,38 @@ rf_page_version_present_v1(const RfPageVersionV1 *version) } bool -rf_page_version_equal_v1(const RfPageVersionV1 *left, - const RfPageVersionV1 *right) +rf_page_version_equal_v1(const RfPageVersionV1 *left, const RfPageVersionV1 *right) { - return left != NULL && right != NULL && - left->mutation_token == right->mutation_token && - memcmp(left->segment_incarnation, right->segment_incarnation, 16) == 0; + return left != NULL && right != NULL && left->mutation_token == right->mutation_token + && memcmp(left->segment_incarnation, right->segment_incarnation, 16) == 0; } RfPageProofDetailV1 -rf_page_detached_apply_v1(const RfDetachedRecordPlanV1 *plan, - uint32 component_index, - const char old_page[BLCKSZ], - char new_page[BLCKSZ]) +rf_page_detached_apply_v1(const RfDetachedRecordPlanV1 *plan, uint32 component_index, + const char old_page[BLCKSZ], char new_page[BLCKSZ]) { const RfDetachedComponentPlanV1 *component; apply_calls++; if (apply_fail_call != 0 && apply_calls == apply_fail_call) return RF_PAGE_PROOF_DETAIL_IMAGE_DECODE_FAILED; - if (plan == NULL || !plan->preflight_complete || - component_index >= plan->component_count) + if (plan == NULL || !plan->preflight_complete || component_index >= plan->component_count) return RF_PAGE_PROOF_DETAIL_INVALID_ARGUMENT; component = &plan->components[component_index]; if (old_page != new_page) memcpy(new_page, old_page, BLCKSZ); - if (PageIsNew((Page) new_page)) + if (PageIsNew((Page)new_page)) init_page(new_page, component->result.mutation_token, 0x61); - ((PageHeader) new_page)->pd_block_scn = component->result.mutation_token; - new_page[BLCKSZ - 1] = (char) component->result.mutation_token; + ((PageHeader)new_page)->pd_block_scn = component->result.mutation_token; + new_page[BLCKSZ - 1] = (char)component->result.mutation_token; return RF_PAGE_PROOF_DETAIL_OK; } static bool -storage_read(void *arg, uint32 index, const RfPageIdentityV1 *identity, - char page[BLCKSZ], bool *exists) +storage_read(void *arg, uint32 index, const RfPageIdentityV1 *identity, char page[BLCKSZ], + bool *exists) { - BatchFixture *fixture = (BatchFixture *) arg; + BatchFixture *fixture = (BatchFixture *)arg; fixture->read_calls++; *exists = fixture->exists[index]; @@ -190,10 +176,10 @@ storage_read(void *arg, uint32 index, const RfPageIdentityV1 *identity, } static bool -storage_write(void *arg, uint32 index, const RfPageIdentityV1 *identity, - const char page[BLCKSZ], bool extend) +storage_write(void *arg, uint32 index, const RfPageIdentityV1 *identity, const char page[BLCKSZ], + bool extend) { - BatchFixture *fixture = (BatchFixture *) arg; + BatchFixture *fixture = (BatchFixture *)arg; fixture->write_calls++; fixture->last_extend = extend; @@ -205,7 +191,7 @@ storage_write(void *arg, uint32 index, const RfPageIdentityV1 *identity, static bool storage_sync(void *arg, uint32 index, const RfPageIdentityV1 *identity) { - BatchFixture *fixture = (BatchFixture *) arg; + BatchFixture *fixture = (BatchFixture *)arg; fixture->sync_calls++; return true; @@ -214,12 +200,11 @@ storage_sync(void *arg, uint32 index, const RfPageIdentityV1 *identity) static uint16 storage_checksum(void *arg, const char page[BLCKSZ], BlockNumber blockno) { - return (uint16) (blockno + 1); + return (uint16)(blockno + 1); } static bool -authority_identity(void *arg, const RfPageIdentityV1 *identity, - const uint8 incarnation[16]) +authority_identity(void *arg, const RfPageIdentityV1 *identity, const uint8 incarnation[16]) { return true; } @@ -227,7 +212,7 @@ authority_identity(void *arg, const RfPageIdentityV1 *identity, static bool authority_promote(void *arg) { - BatchFixture *fixture = (BatchFixture *) arg; + BatchFixture *fixture = (BatchFixture *)arg; fixture->promote_calls++; return true; @@ -236,7 +221,7 @@ authority_promote(void *arg) static bool authority_publish(void *arg) { - BatchFixture *fixture = (BatchFixture *) arg; + BatchFixture *fixture = (BatchFixture *)arg; fixture->publish_calls++; return true; @@ -245,16 +230,15 @@ authority_publish(void *arg) static bool authority_release(void *arg) { - BatchFixture *fixture = (BatchFixture *) arg; + BatchFixture *fixture = (BatchFixture *)arg; fixture->release_calls++; return true; } static void -init_plan(FakeRecord *record, RfDetachedRecordPlanV1 *plan, - const RfPageIdentityV1 *identity, uint8 before_kind, - uint64 before_token, uint64 result_token, uint16 edge_flags, +init_plan(FakeRecord *record, RfDetachedRecordPlanV1 *plan, const RfPageIdentityV1 *identity, + uint8 before_kind, uint64 before_token, uint64 result_token, uint16 edge_flags, uint32 record_ordinal) { DecodedXLogRecord *decoded; @@ -270,10 +254,10 @@ init_plan(FakeRecord *record, RfDetachedRecordPlanV1 *plan, block = &decoded->blocks[0]; block->in_use = true; block->rlocator = identity->locator; - block->forknum = (ForkNumber) identity->forknum; + block->forknum = (ForkNumber)identity->forknum; block->blkno = identity->blockno; record->state.record = decoded; - record->state.ReadRecPtr = 0x1100 + (XLogRecPtr) record_ordinal * 0x100; + record->state.ReadRecPtr = 0x1100 + (XLogRecPtr)record_ordinal * 0x100; record->state.EndRecPtr = record->state.ReadRecPtr + 0x80; memset(plan, 0, sizeof(*plan)); plan->source_record = &record->state; @@ -296,11 +280,9 @@ init_plan(FakeRecord *record, RfDetachedRecordPlanV1 *plan, } static void -bind_record(RfPageReplayRecordV1 *record, - const RfDetachedRecordPlanV1 *plan, - uint16 participant_index, uint64 system_identifier, - const uint8 storage_uuid[16], uint16 origin_thread, - TimeLineID timeline_id) +bind_record(RfPageReplayRecordV1 *record, const RfDetachedRecordPlanV1 *plan, + uint16 participant_index, uint64 system_identifier, const uint8 storage_uuid[16], + uint16 origin_thread, TimeLineID timeline_id) { memset(record, 0, sizeof(*record)); record->record_plan = plan; @@ -319,7 +301,7 @@ bind_record(RfPageReplayRecordV1 *record, static void init_case(BatchCase *test_case, uint32 count) { - uint32 i; + uint32 i; memset(test_case, 0, sizeof(*test_case)); apply_calls = 0; @@ -331,8 +313,7 @@ init_case(BatchCase *test_case, uint32 count) test_case->participants[0].scan_end_exclusive = 0x2000; test_case->participants[0].contributor_count = count; test_case->participants[0].component_count = count; - for (i = 0; i < count; i++) - { + for (i = 0; i < count; i++) { RfPageReplayTargetV1 *target = &test_case->targets[i]; target->page_identity.system_identifier = 99; @@ -347,16 +328,15 @@ init_case(BatchCase *test_case, uint32 count) target->expected_before.mutation_token = 10; set_incarnation(target->expected_result.segment_incarnation, 7); target->expected_result.mutation_token = 11; - init_page(test_case->base[i].data, 10, (uint8) (0x20 + i)); - init_page(test_case->fixture.disk[i].data, 10, - (uint8) (0x30 + i)); + init_page(test_case->base[i].data, 10, (uint8)(0x20 + i)); + init_page(test_case->fixture.disk[i].data, 10, (uint8)(0x30 + i)); test_case->fixture.exists[i] = true; target->base_page = test_case->base[i].data; - init_plan(&test_case->records[i], &test_case->plans[i], - &target->page_identity, RF_PAGE_STATE_PRESENT, 10, 11, 0, i); + init_plan(&test_case->records[i], &test_case->plans[i], &target->page_identity, + RF_PAGE_STATE_PRESENT, 10, 11, 0, i); bind_record(&test_case->replay_records[i], &test_case->plans[i], 0, - target->page_identity.system_identifier, - target->page_identity.storage_uuid, 1, 1); + target->page_identity.system_identifier, target->page_identity.storage_uuid, 1, + 1); test_case->steps[i][0].record_index = i; test_case->steps[i][0].component_index = 0; target->steps = test_case->steps[i]; @@ -380,10 +360,8 @@ init_case(BatchCase *test_case, uint32 count) test_case->authority.release = authority_release; test_case->request.targets = test_case->targets; test_case->request.target_count = count; - test_case->request.record_component_seen = - test_case->record_component_seen[0]; - test_case->request.record_component_seen_capacity = - sizeof(test_case->record_component_seen); + test_case->request.record_component_seen = test_case->record_component_seen[0]; + test_case->request.record_component_seen_capacity = sizeof(test_case->record_component_seen); test_case->request.canonical_pages = test_case->canonical[0].data; test_case->request.canonical_capacity = sizeof(test_case->canonical); test_case->request.install_prepared_pages = test_case->prepared[0].data; @@ -402,7 +380,7 @@ UT_TEST(test_two_targets_apply_then_install_as_one_proven_batch) init_case(&test_case, 2); UT_ASSERT_EQ(rf_page_replay_batch_execute_v1(&test_case.request, &proof), - RF_PAGE_PROOF_DETAIL_OK); + RF_PAGE_PROOF_DETAIL_OK); UT_ASSERT_EQ(apply_calls, 2); UT_ASSERT_EQ(test_case.fixture.write_calls, 2); UT_ASSERT_EQ(test_case.fixture.sync_calls, 2); @@ -420,7 +398,7 @@ UT_TEST(test_incomplete_sibling_plan_blocks_before_any_apply_or_target_read) init_case(&test_case, 2); test_case.plans[1].preflight_complete = false; UT_ASSERT_EQ(rf_page_replay_batch_execute_v1(&test_case.request, &proof), - RF_PAGE_PROOF_DETAIL_COMPONENT_INCOMPLETE); + RF_PAGE_PROOF_DETAIL_COMPONENT_INCOMPLETE); UT_ASSERT_EQ(apply_calls, 0); UT_ASSERT_EQ(test_case.fixture.read_calls, 0); UT_ASSERT_EQ(test_case.fixture.promote_calls, 0); @@ -433,11 +411,10 @@ UT_TEST(test_chain_gap_blocks_whole_batch_before_apply) RfPageReplayBatchProofV1 proof; init_case(&test_case, 1); - init_plan(&test_case.records[2], &test_case.plans[2], - &test_case.targets[0].page_identity, RF_PAGE_STATE_PRESENT, 12, 13, 0, - 1); - bind_record(&test_case.replay_records[1], &test_case.plans[2], 0, - 99, test_case.request.storage_uuid, 1, 1); + init_plan(&test_case.records[2], &test_case.plans[2], &test_case.targets[0].page_identity, + RF_PAGE_STATE_PRESENT, 12, 13, 0, 1); + bind_record(&test_case.replay_records[1], &test_case.plans[2], 0, 99, + test_case.request.storage_uuid, 1, 1); test_case.request.record_count = 2; test_case.participants[0].contributor_count = 2; test_case.participants[0].component_count = 2; @@ -445,7 +422,7 @@ UT_TEST(test_chain_gap_blocks_whole_batch_before_apply) test_case.targets[0].step_count = 2; test_case.targets[0].expected_result.mutation_token = 13; UT_ASSERT_EQ(rf_page_replay_batch_execute_v1(&test_case.request, &proof), - RF_PAGE_PROOF_DETAIL_COMPONENT_INCOMPLETE); + RF_PAGE_PROOF_DETAIL_COMPONENT_INCOMPLETE); UT_ASSERT_EQ(apply_calls, 0); UT_ASSERT_EQ(test_case.fixture.read_calls, 0); } @@ -458,7 +435,7 @@ UT_TEST(test_detached_apply_failure_never_reaches_target_install) init_case(&test_case, 2); apply_fail_call = 2; UT_ASSERT_EQ(rf_page_replay_batch_execute_v1(&test_case.request, &proof), - RF_PAGE_PROOF_DETAIL_IMAGE_DECODE_FAILED); + RF_PAGE_PROOF_DETAIL_IMAGE_DECODE_FAILED); UT_ASSERT_EQ(apply_calls, 2); UT_ASSERT_EQ(test_case.fixture.read_calls, 0); UT_ASSERT_EQ(test_case.fixture.promote_calls, 0); @@ -473,7 +450,7 @@ UT_TEST(test_record_block_identity_mismatch_is_zero_apply) init_case(&test_case, 1); test_case.records[0].storage.decoded.blocks[0].rlocator.relNumber++; UT_ASSERT_EQ(rf_page_replay_batch_execute_v1(&test_case.request, &proof), - RF_PAGE_PROOF_DETAIL_COMPONENT_INCOMPLETE); + RF_PAGE_PROOF_DETAIL_COMPONENT_INCOMPLETE); UT_ASSERT_EQ(apply_calls, 0); UT_ASSERT_EQ(test_case.fixture.read_calls, 0); } @@ -486,14 +463,14 @@ UT_TEST(test_exact_record_identity_must_match_immutable_decoded_source) init_case(&test_case, 1); test_case.replay_records[0].identity.record_crc++; UT_ASSERT_EQ(rf_page_replay_batch_execute_v1(&test_case.request, &proof), - RF_PAGE_PROOF_DETAIL_SOURCE_GAP); + RF_PAGE_PROOF_DETAIL_SOURCE_GAP); UT_ASSERT_EQ(apply_calls, 0); UT_ASSERT_EQ(test_case.fixture.read_calls, 0); init_case(&test_case, 1); test_case.replay_records[0].identity.info++; UT_ASSERT_EQ(rf_page_replay_batch_execute_v1(&test_case.request, &proof), - RF_PAGE_PROOF_DETAIL_SOURCE_GAP); + RF_PAGE_PROOF_DETAIL_SOURCE_GAP); UT_ASSERT_EQ(apply_calls, 0); } @@ -518,7 +495,7 @@ UT_TEST(test_unreferenced_page_sibling_blocks_record_wide_install) block->blkno = 1; block->component_ordinal = 1; UT_ASSERT_EQ(rf_page_replay_batch_execute_v1(&test_case.request, &proof), - RF_PAGE_PROOF_DETAIL_COMPONENT_INCOMPLETE); + RF_PAGE_PROOF_DETAIL_COMPONENT_INCOMPLETE); UT_ASSERT_EQ(apply_calls, 0); UT_ASSERT_EQ(test_case.fixture.read_calls, 0); UT_ASSERT_EQ(test_case.fixture.write_calls, 0); @@ -547,7 +524,7 @@ UT_TEST(test_all_page_siblings_of_one_record_install_together) test_case.steps[1][0].component_index = 1; test_case.request.record_count = 1; UT_ASSERT_EQ(rf_page_replay_batch_execute_v1(&test_case.request, &proof), - RF_PAGE_PROOF_DETAIL_OK); + RF_PAGE_PROOF_DETAIL_OK); UT_ASSERT_EQ(apply_calls, 2); UT_ASSERT_EQ(test_case.fixture.write_calls, 2); UT_ASSERT_EQ(proof.step_count, 2); @@ -563,8 +540,7 @@ UT_TEST(test_result_source_with_zero_steps_uses_canonical_skip) test_case.targets[0].steps = NULL; test_case.targets[0].step_count = 0; test_case.participants[0].flags = RF_CONTRIBUTOR_CUT_KNOWN_MASK; - test_case.participants[0].scan_end_exclusive = - test_case.participants[0].scan_begin_inclusive; + test_case.participants[0].scan_end_exclusive = test_case.participants[0].scan_begin_inclusive; test_case.participants[0].contributor_count = 0; test_case.participants[0].component_count = 0; test_case.request.records = NULL; @@ -574,7 +550,7 @@ UT_TEST(test_result_source_with_zero_steps_uses_canonical_skip) init_page(test_case.base[0].data, 11, 0x44); memcpy(test_case.fixture.disk[0].data, test_case.base[0].data, BLCKSZ); UT_ASSERT_EQ(rf_page_replay_batch_execute_v1(&test_case.request, &proof), - RF_PAGE_PROOF_DETAIL_OK); + RF_PAGE_PROOF_DETAIL_OK); UT_ASSERT_EQ(apply_calls, 0); UT_ASSERT_EQ(test_case.fixture.write_calls, 0); UT_ASSERT_EQ(proof.install.result_skip_count, 1); @@ -596,7 +572,7 @@ UT_TEST(test_zero_record_table_requires_explicit_empty_participant_cut) init_page(test_case.base[0].data, 11, 0x44); memcpy(test_case.fixture.disk[0].data, test_case.base[0].data, BLCKSZ); UT_ASSERT_EQ(rf_page_replay_batch_execute_v1(&test_case.request, &proof), - RF_PAGE_PROOF_DETAIL_PARTICIPANT_MISSING); + RF_PAGE_PROOF_DETAIL_PARTICIPANT_MISSING); UT_ASSERT_EQ(apply_calls, 0); UT_ASSERT_EQ(test_case.fixture.read_calls, 0); UT_ASSERT_EQ(test_case.fixture.write_calls, 0); @@ -610,7 +586,7 @@ UT_TEST(test_targets_must_be_strict_canonical_identity_order) init_case(&test_case, 2); test_case.targets[1].page_identity.locator.relNumber = 99; UT_ASSERT_EQ(rf_page_replay_batch_execute_v1(&test_case.request, &proof), - RF_PAGE_PROOF_DETAIL_ORDER_VIOLATION); + RF_PAGE_PROOF_DETAIL_ORDER_VIOLATION); UT_ASSERT_EQ(apply_calls, 0); UT_ASSERT_EQ(test_case.fixture.read_calls, 0); } @@ -623,7 +599,7 @@ UT_TEST(test_oversized_step_count_is_rejected_before_indexing) init_case(&test_case, 1); test_case.targets[0].step_count = RF_PAGE_STABLE_MAX_EDGES + 1; UT_ASSERT_EQ(rf_page_replay_batch_execute_v1(&test_case.request, &proof), - RF_PAGE_PROOF_DETAIL_CAPACITY); + RF_PAGE_PROOF_DETAIL_CAPACITY); UT_ASSERT_EQ(apply_calls, 0); UT_ASSERT_EQ(test_case.fixture.read_calls, 0); } @@ -634,11 +610,10 @@ UT_TEST(test_exact_two_step_chain_reaches_terminal_version) RfPageReplayBatchProofV1 proof; init_case(&test_case, 1); - init_plan(&test_case.records[2], &test_case.plans[2], - &test_case.targets[0].page_identity, RF_PAGE_STATE_PRESENT, 11, 12, 0, - 1); - bind_record(&test_case.replay_records[1], &test_case.plans[2], 0, - 99, test_case.request.storage_uuid, 1, 1); + init_plan(&test_case.records[2], &test_case.plans[2], &test_case.targets[0].page_identity, + RF_PAGE_STATE_PRESENT, 11, 12, 0, 1); + bind_record(&test_case.replay_records[1], &test_case.plans[2], 0, 99, + test_case.request.storage_uuid, 1, 1); test_case.request.record_count = 2; test_case.participants[0].contributor_count = 2; test_case.participants[0].component_count = 2; @@ -646,10 +621,9 @@ UT_TEST(test_exact_two_step_chain_reaches_terminal_version) test_case.targets[0].step_count = 2; test_case.targets[0].expected_result.mutation_token = 12; UT_ASSERT_EQ(rf_page_replay_batch_execute_v1(&test_case.request, &proof), - RF_PAGE_PROOF_DETAIL_OK); + RF_PAGE_PROOF_DETAIL_OK); UT_ASSERT_EQ(apply_calls, 2); - UT_ASSERT_EQ(((PageHeader) test_case.fixture.disk[0].data)->pd_block_scn, - 12); + UT_ASSERT_EQ(((PageHeader)test_case.fixture.disk[0].data)->pd_block_scn, 12); UT_ASSERT_EQ(proof.step_count, 2); } diff --git a/src/test/cluster_unit/test_cluster_page_rmgr.c b/src/test/cluster_unit/test_cluster_page_rmgr.c index a1dc20b7f95..3ef869c4021 100644 --- a/src/test/cluster_unit/test_cluster_page_rmgr.c +++ b/src/test/cluster_unit/test_cluster_page_rmgr.c @@ -57,9 +57,8 @@ typedef struct FakeRecord { } FakeRecord; static XLogReaderState * -make_record(FakeRecord *fr, RmgrId rmid, uint8 info, uint64 xl_scn, - bool has_ref, bool has_image, bool apply_image, uint8 fork_flags, - XLogRecPtr endlsn) +make_record(FakeRecord *fr, RmgrId rmid, uint8 info, uint64 xl_scn, bool has_ref, bool has_image, + bool apply_image, uint8 fork_flags, XLogRecPtr endlsn) { DecodedXLogRecord *dec = &fr->u.dec; @@ -91,16 +90,13 @@ make_record(FakeRecord *fr, RmgrId rmid, uint8 info, uint64 xl_scn, UT_TEST(test_census_heap_delta_rows) { ClusterPageRmgrCensusEntry e; - int opcodes[] = { XLOG_HEAP_INSERT, XLOG_HEAP_DELETE, - XLOG_HEAP_UPDATE, XLOG_HEAP_HOT_UPDATE - }; - int i; + int opcodes[] = { XLOG_HEAP_INSERT, XLOG_HEAP_DELETE, XLOG_HEAP_UPDATE, XLOG_HEAP_HOT_UPDATE }; + int i; /* The t/256-differenced heap deltas: NORMAL, page-affecting, known. */ - for (i = 0; i < (int) lengthof(opcodes); i++) { - UT_ASSERT(cluster_page_rmgr_census_lookup(RM_HEAP_ID, - (uint16) opcodes[i], &e)); - UT_ASSERT_EQ((int) e.page_class, (int) CLUSTER_PAGE_CLASS_NORMAL); + for (i = 0; i < (int)lengthof(opcodes); i++) { + UT_ASSERT(cluster_page_rmgr_census_lookup(RM_HEAP_ID, (uint16)opcodes[i], &e)); + UT_ASSERT_EQ((int)e.page_class, (int)CLUSTER_PAGE_CLASS_NORMAL); UT_ASSERT(e.affects_page); UT_ASSERT(e.known_delta); /* G3: no deterministic-mutation declaration exists yet. */ @@ -115,7 +111,7 @@ UT_TEST(test_census_heap_unsupported_deltas_not_known) /* LOCK/CONFIRM/INPLACE are page-affecting NORMAL rows WITHOUT * differential evidence (the matrix fails them closed, 8.A/R11). */ UT_ASSERT(cluster_page_rmgr_census_lookup(RM_HEAP_ID, XLOG_HEAP_LOCK, &e)); - UT_ASSERT_EQ((int) e.page_class, (int) CLUSTER_PAGE_CLASS_NORMAL); + UT_ASSERT_EQ((int)e.page_class, (int)CLUSTER_PAGE_CLASS_NORMAL); UT_ASSERT(e.affects_page); UT_ASSERT(!e.known_delta); @@ -126,7 +122,7 @@ UT_TEST(test_census_heap_unsupported_deltas_not_known) /* Index data pages: NORMAL row, no evidence yet. */ UT_ASSERT(cluster_page_rmgr_census_lookup(RM_BTREE_ID, 0, &e)); - UT_ASSERT_EQ((int) e.page_class, (int) CLUSTER_PAGE_CLASS_NORMAL); + UT_ASSERT_EQ((int)e.page_class, (int)CLUSTER_PAGE_CLASS_NORMAL); UT_ASSERT(e.affects_page); UT_ASSERT(!e.known_delta); } @@ -139,11 +135,11 @@ UT_TEST(test_census_header_class_typed_owner) * replay must never touch them (§4.5), and there is no differential * evidence. */ UT_ASSERT(cluster_page_rmgr_census_lookup(RM_CLOG_ID, 0, &e)); - UT_ASSERT_EQ((int) e.page_class, (int) CLUSTER_PAGE_CLASS_HEADER); + UT_ASSERT_EQ((int)e.page_class, (int)CLUSTER_PAGE_CLASS_HEADER); UT_ASSERT(e.affects_page); UT_ASSERT(!e.known_delta); UT_ASSERT(cluster_page_rmgr_census_lookup(RM_RELMAP_ID, 0, &e)); - UT_ASSERT_EQ((int) e.page_class, (int) CLUSTER_PAGE_CLASS_HEADER); + UT_ASSERT_EQ((int)e.page_class, (int)CLUSTER_PAGE_CLASS_HEADER); } UT_TEST(test_census_non_page_rmgrs) @@ -177,9 +173,8 @@ UT_TEST(test_census_heap_init_page_attribute_row) /* INIT_PAGE: NEW-class row carrying the will_init ATTRIBUTE — but no * §4.6 full-init rule (expected class state + result-version proof), * so the classifier must still return UNKNOWN for it (PU-17). */ - UT_ASSERT(cluster_page_rmgr_census_lookup(RM_HEAP_ID, XLOG_HEAP_INIT_PAGE, - &e)); - UT_ASSERT_EQ((int) e.page_class, (int) CLUSTER_PAGE_CLASS_NEW); + UT_ASSERT(cluster_page_rmgr_census_lookup(RM_HEAP_ID, XLOG_HEAP_INIT_PAGE, &e)); + UT_ASSERT_EQ((int)e.page_class, (int)CLUSTER_PAGE_CLASS_NEW); UT_ASSERT(e.will_init); UT_ASSERT(!e.known_delta); } @@ -213,17 +208,14 @@ UT_TEST(test_populate_known_set_wires_only_proven_deltas) in.opcode = XLOG_HEAP_INSERT; in.forknum = MAIN_FORKNUM; in.header_owner = CLUSTER_PAGE_HEADER_OWNER_NONE; - UT_ASSERT_EQ((int) cluster_page_classify(&in), - (int) CLUSTER_PAGE_CLASS_NORMAL); + UT_ASSERT_EQ((int)cluster_page_classify(&in), (int)CLUSTER_PAGE_CLASS_NORMAL); /* Lock stays UNKNOWN (BLOCKED) until differential evidence lands. */ in.opcode = XLOG_HEAP_LOCK; - UT_ASSERT_EQ((int) cluster_page_classify(&in), - (int) CLUSTER_PAGE_CLASS_UNKNOWN); + UT_ASSERT_EQ((int)cluster_page_classify(&in), (int)CLUSTER_PAGE_CLASS_UNKNOWN); /* INIT_PAGE keeps the WILL_INIT attribute: UNKNOWN without the * full-init rule (PU-17). */ in.opcode = XLOG_HEAP_INIT_PAGE; - UT_ASSERT_EQ((int) cluster_page_classify(&in), - (int) CLUSTER_PAGE_CLASS_UNKNOWN); + UT_ASSERT_EQ((int)cluster_page_classify(&in), (int)CLUSTER_PAGE_CLASS_UNKNOWN); } /* ========================================================================== @@ -236,24 +228,22 @@ UT_TEST(test_decode_heap_insert_extracts_facts) XLogReaderState *rec; ClusterPageRedoDecoded out; - rec = make_record(&fr, RM_HEAP_ID, XLOG_HEAP_INSERT, - UINT64_C(0x123456789), true, false, false, 0, - UINT64_C(0x1000)); + rec = make_record(&fr, RM_HEAP_ID, XLOG_HEAP_INSERT, UINT64_C(0x123456789), true, false, false, + 0, UINT64_C(0x1000)); UT_ASSERT(cluster_page_redo_decode(rec, 0, &out)); - UT_ASSERT_EQ((int) out.page_class, (int) CLUSTER_PAGE_CLASS_NORMAL); - UT_ASSERT_EQ((unsigned long long) out.identity.rlocator.spcOid, 1ULL); - UT_ASSERT_EQ((unsigned long long) out.identity.blocknum, 42ULL); - UT_ASSERT_EQ((int) out.identity.forknum, (int) MAIN_FORKNUM); + UT_ASSERT_EQ((int)out.page_class, (int)CLUSTER_PAGE_CLASS_NORMAL); + UT_ASSERT_EQ((unsigned long long)out.identity.rlocator.spcOid, 1ULL); + UT_ASSERT_EQ((unsigned long long)out.identity.blocknum, 42ULL); + UT_ASSERT_EQ((int)out.identity.forknum, (int)MAIN_FORKNUM); /* §3.1 hints: record-side facts only. */ - UT_ASSERT_EQ((unsigned long long) out.hints.record_scn, - (unsigned long long) UINT64_C(0x123456789)); - UT_ASSERT_EQ((unsigned long long) out.hints.record_lsn, - (unsigned long long) UINT64_C(0x1000)); + UT_ASSERT_EQ((unsigned long long)out.hints.record_scn, + (unsigned long long)UINT64_C(0x123456789)); + UT_ASSERT_EQ((unsigned long long)out.hints.record_lsn, (unsigned long long)UINT64_C(0x1000)); UT_ASSERT(!out.full_image); UT_ASSERT(!out.will_init); /* Page-side hints are the caller's to fill; they start zero. */ - UT_ASSERT_EQ((unsigned long long) out.hints.page_scn, 0ULL); - UT_ASSERT_EQ((unsigned long long) out.hints.page_lsn, 0ULL); + UT_ASSERT_EQ((unsigned long long)out.hints.page_scn, 0ULL); + UT_ASSERT_EQ((unsigned long long)out.hints.page_lsn, 0ULL); } UT_TEST(test_decode_fpi_and_will_init_attributes) @@ -263,17 +253,16 @@ UT_TEST(test_decode_fpi_and_will_init_attributes) ClusterPageRedoDecoded out; /* FPI present and applied. */ - rec = make_record(&fr, RM_HEAP_ID, XLOG_HEAP_INSERT, - 5, true, true, true, 0, 0x2000); + rec = make_record(&fr, RM_HEAP_ID, XLOG_HEAP_INSERT, 5, true, true, true, 0, 0x2000); UT_ASSERT(cluster_page_redo_decode(rec, 0, &out)); UT_ASSERT(out.full_image); /* BKPBLOCK_WILL_INIT attribute rides the block fork flags. */ - rec = make_record(&fr, RM_HEAP_ID, XLOG_HEAP_INIT_PAGE, - 6, true, false, false, BKPBLOCK_WILL_INIT, 0x3000); + rec = make_record(&fr, RM_HEAP_ID, XLOG_HEAP_INIT_PAGE, 6, true, false, false, + BKPBLOCK_WILL_INIT, 0x3000); UT_ASSERT(cluster_page_redo_decode(rec, 0, &out)); UT_ASSERT(out.will_init); - UT_ASSERT_EQ((int) out.page_class, (int) CLUSTER_PAGE_CLASS_NEW); + UT_ASSERT_EQ((int)out.page_class, (int)CLUSTER_PAGE_CLASS_NEW); } UT_TEST(test_decode_fail_closed_paths) @@ -283,8 +272,7 @@ UT_TEST(test_decode_fail_closed_paths) ClusterPageRedoDecoded out; /* No block reference: nothing to decode. */ - rec = make_record(&fr, RM_HEAP_ID, XLOG_HEAP_INSERT, 1, false, false, - false, 0, 0x1000); + rec = make_record(&fr, RM_HEAP_ID, XLOG_HEAP_INSERT, 1, false, false, false, 0, 0x1000); UT_ASSERT(!cluster_page_redo_decode(rec, 0, &out)); /* Non-page-affecting rmgr (SMGR): census row says not page-affecting. */ diff --git a/src/test/cluster_unit/test_cluster_page_set.c b/src/test/cluster_unit/test_cluster_page_set.c index cd7be6d17fb..2449f959f7f 100644 --- a/src/test/cluster_unit/test_cluster_page_set.c +++ b/src/test/cluster_unit/test_cluster_page_set.c @@ -47,7 +47,7 @@ static ClusterPageRedoChange ut_changes[5]; static void ut_setup_globals(void) { - int i; + int i; memset(&ut_id, 0, sizeof(ut_id)); ut_id.rlocator.spcOid = 1; @@ -60,7 +60,7 @@ ut_setup_globals(void) memset(&ut_v[i], 0, sizeof(ut_v[i])); ut_v[i].identity = ut_id; ut_v[i].incarnation = 7; - ut_v[i].token = (uint64) (100 + i); + ut_v[i].token = (uint64)(100 + i); } for (i = 0; i < 5; i++) { @@ -68,7 +68,7 @@ ut_setup_globals(void) ut_changes[i].identity = ut_id; ut_changes[i].page_class = CLUSTER_PAGE_CLASS_NORMAL; ut_changes[i].failed_origin_thread = 2; - ut_changes[i].change_identity = (uint64) (i + 1); + ut_changes[i].change_identity = (uint64)(i + 1); } } @@ -96,13 +96,13 @@ ut_set(int n_changes) static void ut_chain(int n) { - int i; + int i; for (i = 0; i < n; i++) { ut_changes[i].identity = ut_id; ut_changes[i].page_class = CLUSTER_PAGE_CLASS_NORMAL; ut_changes[i].failed_origin_thread = 2; - ut_changes[i].change_identity = (uint64) (i + 1); + ut_changes[i].change_identity = (uint64)(i + 1); ut_changes[i].expected_before = ut_v[i]; ut_changes[i].result_version = ut_v[i + 1]; } @@ -114,11 +114,9 @@ UT_TEST(test_closure_closed_chain_ok) ut_chain(3); set = ut_set(3); - UT_ASSERT_EQ((int) cluster_page_contributor_closure(&set), - (int) CLUSTER_PAGE_CLOSURE_OK); + UT_ASSERT_EQ((int)cluster_page_contributor_closure(&set), (int)CLUSTER_PAGE_CLOSURE_OK); /* Rerun determinism (§6.3-9): same inputs, same verdict. */ - UT_ASSERT_EQ((int) cluster_page_contributor_closure(&set), - (int) CLUSTER_PAGE_CLOSURE_OK); + UT_ASSERT_EQ((int)cluster_page_contributor_closure(&set), (int)CLUSTER_PAGE_CLOSURE_OK); } UT_TEST(test_closure_gap_and_terminal_mismatch) @@ -130,24 +128,21 @@ UT_TEST(test_closure_gap_and_terminal_mismatch) ut_changes[1].expected_before = ut_v[0]; /* skips v1 -> wrong join */ ut_changes[1].result_version = ut_v[2]; set = ut_set(3); - UT_ASSERT_EQ((int) cluster_page_contributor_closure(&set), - (int) CLUSTER_PAGE_CLOSURE_GAP); + UT_ASSERT_EQ((int)cluster_page_contributor_closure(&set), (int)CLUSTER_PAGE_CLOSURE_GAP); /* Gap: invalid version in a contributor (PU-05: numeric-higher or * missing is never coverage). */ ut_chain(3); - memset(&ut_changes[1].expected_before, 0, - sizeof(ut_changes[1].expected_before)); + memset(&ut_changes[1].expected_before, 0, sizeof(ut_changes[1].expected_before)); set = ut_set(3); - UT_ASSERT_EQ((int) cluster_page_contributor_closure(&set), - (int) CLUSTER_PAGE_CLOSURE_GAP); + UT_ASSERT_EQ((int)cluster_page_contributor_closure(&set), (int)CLUSTER_PAGE_CLOSURE_GAP); /* Terminal mismatch: chain ends at v3 but the set requires v4. */ ut_chain(3); set = ut_set(3); set.terminal_version = ut_v[4]; - UT_ASSERT_EQ((int) cluster_page_contributor_closure(&set), - (int) CLUSTER_PAGE_CLOSURE_TERMINAL_MISMATCH); + UT_ASSERT_EQ((int)cluster_page_contributor_closure(&set), + (int)CLUSTER_PAGE_CLOSURE_TERMINAL_MISMATCH); } UT_TEST(test_closure_unknown_class_and_incarnation_cross) @@ -158,8 +153,8 @@ UT_TEST(test_closure_unknown_class_and_incarnation_cross) ut_chain(2); ut_changes[1].page_class = CLUSTER_PAGE_CLASS_UNKNOWN; set = ut_set(2); - UT_ASSERT_EQ((int) cluster_page_contributor_closure(&set), - (int) CLUSTER_PAGE_CLOSURE_UNKNOWN_CLASS); + UT_ASSERT_EQ((int)cluster_page_contributor_closure(&set), + (int)CLUSTER_PAGE_CLOSURE_UNKNOWN_CLASS); /* Incarnation boundary: equal-SCN-looking versions with a different * incarnation are NOT adjacency (PU-06/11) — old-incarnation redo @@ -172,8 +167,8 @@ UT_TEST(test_closure_unknown_class_and_incarnation_cross) set = ut_set(2); set.terminal_version = ut_v[2]; set.terminal_version.incarnation = 8; - UT_ASSERT_EQ((int) cluster_page_contributor_closure(&set), - (int) CLUSTER_PAGE_CLOSURE_INCARNATION_CROSS); + UT_ASSERT_EQ((int)cluster_page_contributor_closure(&set), + (int)CLUSTER_PAGE_CLOSURE_INCARNATION_CROSS); } UT_TEST(test_closure_empty_chain) @@ -184,28 +179,26 @@ UT_TEST(test_closure_empty_chain) * replay set" conclusion additionally needs the production GCS * stability witness that the PGDEL-04 CURRENT validator carries. */ set = ut_set(0); - UT_ASSERT_EQ((int) cluster_page_contributor_closure(&set), - (int) CLUSTER_PAGE_CLOSURE_OK); + UT_ASSERT_EQ((int)cluster_page_contributor_closure(&set), (int)CLUSTER_PAGE_CLOSURE_OK); /* Empty chain, source != terminal: a gap, never a skip. */ set = ut_set(0); set.terminal_version = ut_v[1]; - UT_ASSERT_EQ((int) cluster_page_contributor_closure(&set), - (int) CLUSTER_PAGE_CLOSURE_GAP); + UT_ASSERT_EQ((int)cluster_page_contributor_closure(&set), (int)CLUSTER_PAGE_CLOSURE_GAP); } UT_TEST(test_closure_invalid_inputs) { - UT_ASSERT_EQ((int) cluster_page_contributor_closure(NULL), - (int) CLUSTER_PAGE_CLOSURE_INVALID_INPUT); + UT_ASSERT_EQ((int)cluster_page_contributor_closure(NULL), + (int)CLUSTER_PAGE_CLOSURE_INVALID_INPUT); { ClusterBlockRecoverySet set = ut_set(1); ClusterPageVersion invalid; memset(&invalid, 0, sizeof(invalid)); set.source_version = invalid; - UT_ASSERT_EQ((int) cluster_page_contributor_closure(&set), - (int) CLUSTER_PAGE_CLOSURE_INVALID_INPUT); + UT_ASSERT_EQ((int)cluster_page_contributor_closure(&set), + (int)CLUSTER_PAGE_CLOSURE_INVALID_INPUT); } } diff --git a/src/test/cluster_unit/test_cluster_page_source.c b/src/test/cluster_unit/test_cluster_page_source.c index 5afa6ef2605..66fb111a834 100644 --- a/src/test/cluster_unit/test_cluster_page_source.c +++ b/src/test/cluster_unit/test_cluster_page_source.c @@ -133,15 +133,15 @@ UT_TEST(test_validate_pi_conjunction) * reused; the caller discards the PI). */ in = ut_full_current_input(); in.ship_boundary_ok = true; - in.stability_ok = false; /* holder changed */ + in.stability_ok = false; /* holder changed */ UT_ASSERT(!cluster_page_source_validate_pi(&in)); in = ut_full_current_input(); in.ship_boundary_ok = true; - in.lineage_ok = false; /* wrong failure-generation lineage */ + in.lineage_ok = false; /* wrong failure-generation lineage */ UT_ASSERT(!cluster_page_source_validate_pi(&in)); in = ut_full_current_input(); in.ship_boundary_ok = true; - in.integrity_ok = false; /* corrupt past image */ + in.integrity_ok = false; /* corrupt past image */ UT_ASSERT(!cluster_page_source_validate_pi(&in)); in = ut_full_current_input(); in.ship_boundary_ok = true; diff --git a/src/test/cluster_unit/test_cluster_page_stable_base.c b/src/test/cluster_unit/test_cluster_page_stable_base.c index 6642240fd10..2f21e8b1559 100644 --- a/src/test/cluster_unit/test_cluster_page_stable_base.c +++ b/src/test/cluster_unit/test_cluster_page_stable_base.c @@ -23,11 +23,9 @@ UT_DEFINE_GLOBALS(); void -ExceptionalCondition(const char *condition_name, const char *file_name, - int line_number) +ExceptionalCondition(const char *condition_name, const char *file_name, int line_number) { - printf("# Assert failed: %s at %s:%d\n", condition_name, file_name, - line_number); + printf("# Assert failed: %s at %s:%d\n", condition_name, file_name, line_number); abort(); } @@ -50,18 +48,15 @@ errmsg_internal(const char *fmt pg_attribute_unused(), ...) } bool -errstart_cold(int elevel pg_attribute_unused(), - const char *domain pg_attribute_unused()) +errstart_cold(int elevel pg_attribute_unused(), const char *domain pg_attribute_unused()) { return false; } void -errfinish(const char *filename pg_attribute_unused(), - int lineno pg_attribute_unused(), +errfinish(const char *filename pg_attribute_unused(), int lineno pg_attribute_unused(), const char *funcname pg_attribute_unused()) -{ -} +{} #ifndef TEST_HAVE_CLUSTER_PAGE_STABLE_BASE @@ -98,11 +93,9 @@ cluster_control_root_revalidate(const ClusterControlRootReadToken *token, const ClusterControlRootIdentity *identity, ClusterControlRootSnapshot *snapshot) { - if (!canonical_root_current || token != expected_root_tokens || - identity != expected_duties) + if (!canonical_root_current || token != expected_root_tokens || identity != expected_duties) return CLUSTER_CONTROL_ROOT_STALE_TOKEN; - if (snapshot != NULL) - { + if (snapshot != NULL) { memset(snapshot, 0, sizeof(*snapshot)); snapshot->identity = *identity; snapshot->lifecycle = CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_REQUIRED; @@ -112,18 +105,16 @@ cluster_control_root_revalidate(const ClusterControlRootReadToken *token, } ClusterFormationWitnessResult -cluster_formation_witness_revalidate_nowait( - const ClusterFormationWitnessV1 *formation) +cluster_formation_witness_revalidate_nowait(const ClusterFormationWitnessV1 *formation) { - return formation == expected_formation ? CLUSTER_FORMATION_WITNESS_READY : - CLUSTER_FORMATION_WITNESS_UNSTABLE; + return formation == expected_formation ? CLUSTER_FORMATION_WITNESS_READY + : CLUSTER_FORMATION_WITNESS_UNSTABLE; } bool -cluster_external_fence_need_set_revalidate_nowait( - const PgracExternalFenceNeedSetV1 *needs, - const ClusterFormationWitnessV1 *formation, - PgracExternalFenceDenyReason *reason) +cluster_external_fence_need_set_revalidate_nowait(const PgracExternalFenceNeedSetV1 *needs, + const ClusterFormationWitnessV1 *formation, + PgracExternalFenceDenyReason *reason) { if (reason != NULL) *reason = PGRAC_EXTERNAL_FENCE_DENY_NONE; @@ -131,21 +122,19 @@ cluster_external_fence_need_set_revalidate_nowait( } bool -cluster_external_fence_revalidate_set_nowait( - const PgracExternalFenceAdmissionSetV1 *admissions, - const PgracExternalFenceNeedSetV1 *needs, - const ClusterFormationWitnessV1 *formation, - PgracExternalFenceDenyReason *reason) +cluster_external_fence_revalidate_set_nowait(const PgracExternalFenceAdmissionSetV1 *admissions, + const PgracExternalFenceNeedSetV1 *needs, + const ClusterFormationWitnessV1 *formation, + PgracExternalFenceDenyReason *reason) { if (reason != NULL) *reason = PGRAC_EXTERNAL_FENCE_DENY_NONE; - return admissions == expected_admissions && needs == expected_needs && - formation == expected_formation; + return admissions == expected_admissions && needs == expected_needs + && formation == expected_formation; } ClusterWalPinResult -cluster_wal_retention_pin_preflight_revalidate_wait_v1( - ClusterWalRetentionPin *pin) +cluster_wal_retention_pin_preflight_revalidate_wait_v1(ClusterWalRetentionPin *pin) { preflight_pin_checks++; return pin == expected_pin ? CLUSTER_WAL_PIN_OK : CLUSTER_WAL_PIN_STALE; @@ -155,12 +144,10 @@ ClusterWalPinResult cluster_wal_retention_pin_revalidate(ClusterWalRetentionPin *pin) { bound_pin_checks++; - return bound_pin_current && pin == expected_pin ? CLUSTER_WAL_PIN_OK : - CLUSTER_WAL_PIN_STALE; + return bound_pin_current && pin == expected_pin ? CLUSTER_WAL_PIN_OK : CLUSTER_WAL_PIN_STALE; } -typedef struct GraphFixture -{ +typedef struct GraphFixture { RfPageIdentityV1 identity; RfContributorStreamCutV1 cuts[4]; RfPageStableEdgeInputV1 edges[8]; @@ -169,10 +156,10 @@ typedef struct GraphFixture RfPageStableGraphRequestV1 request; ClusterRecoveryDutyKey duties[4]; ClusterControlRootReadToken root_tokens[4]; - char formation_object; - char needs_object; - char admission_object; - char pin_object; + char formation_object; + char needs_object; + char admission_object; + char pin_object; uint32 chain[16]; RfPageStableSelectionV1 selection; } GraphFixture; @@ -214,10 +201,9 @@ make_identity(BlockNumber blockno) } static void -set_edge(RfPageStableEdgeInputV1 *edge, const RfPageIdentityV1 *identity, - uint8 before_kind, const RfPageVersionV1 *before, - const RfPageVersionV1 *result, uint16 flags, uint64 record_identity, - uint16 participant_index) +set_edge(RfPageStableEdgeInputV1 *edge, const RfPageIdentityV1 *identity, uint8 before_kind, + const RfPageVersionV1 *before, const RfPageVersionV1 *result, uint16 flags, + uint64 record_identity, uint16 participant_index) { memset(edge, 0, sizeof(*edge)); edge->page_identity = *identity; @@ -237,13 +223,12 @@ set_edge(RfPageStableEdgeInputV1 *edge, const RfPageIdentityV1 *identity, edge->record_identity.timeline_id = 1; edge->record_identity.read_rec_ptr = 100 + record_identity; edge->record_identity.end_rec_ptr = 101 + record_identity; - edge->record_identity.record_crc = (uint32) record_identity; + edge->record_identity.record_crc = (uint32)record_identity; edge->record_identity.rmid = RM_XLOG_ID; - edge->record_identity.info = (uint8) (record_identity & 0xf0); + edge->record_identity.info = (uint8)(record_identity & 0xf0); edge->participant_index = participant_index; edge->component_count = 1; - memset(edge->anchor_digest, (int) (record_identity & 0xff), - sizeof(edge->anchor_digest)); + memset(edge->anchor_digest, (int)(record_identity & 0xff), sizeof(edge->anchor_digest)); edge->record_complete = true; edge->opcode_supported = true; edge->side_complete = true; @@ -251,28 +236,24 @@ set_edge(RfPageStableEdgeInputV1 *edge, const RfPageIdentityV1 *identity, } static void -graph_recount(GraphFixture *fixture, uint32 participant_count, - uint32 edge_count) +graph_recount(GraphFixture *fixture, uint32 participant_count, uint32 edge_count) { uint32 i; memset(fixture->cuts, 0, sizeof(fixture->cuts)); - for (i = 0; i < participant_count; i++) - { - fixture->cuts[i].failed_thread = (uint16) (i + 1); + for (i = 0; i < participant_count; i++) { + fixture->cuts[i].failed_thread = (uint16)(i + 1); fixture->cuts[i].timeline_id = 1; fixture->cuts[i].flags = RF_CONTRIBUTOR_CUT_KNOWN_MASK; fixture->cuts[i].scan_begin_inclusive = 100; fixture->cuts[i].scan_end_exclusive = 100; } - for (i = 0; i < edge_count; i++) - { + for (i = 0; i < edge_count; i++) { uint16 participant = fixture->edges[i].participant_index; UT_ASSERT(participant < participant_count); fixture->cuts[participant].contributor_count++; - fixture->cuts[participant].component_count += - fixture->edges[i].component_count; + fixture->cuts[participant].component_count += fixture->edges[i].component_count; fixture->cuts[participant].flags = RF_CONTRIBUTOR_CUT_COMPLETE; fixture->cuts[participant].scan_end_exclusive = 200; } @@ -288,10 +269,8 @@ graph_init(GraphFixture *fixture) memset(fixture, 0, sizeof(*fixture)); fixture->identity = make_identity(7); - set_edge(&fixture->edges[0], &fixture->identity, RF_PAGE_STATE_ABSENT, - NULL, &result, - RF_PAGE_EDGE_FULL_IMAGE_APPLY | RF_PAGE_EDGE_FULL_COVERAGE, - 1, 0); + set_edge(&fixture->edges[0], &fixture->identity, RF_PAGE_STATE_ABSENT, NULL, &result, + RF_PAGE_EDGE_FULL_IMAGE_APPLY | RF_PAGE_EDGE_FULL_COVERAGE, 1, 0); fixture->vector.system_identifier = fixture->identity.system_identifier; memcpy(fixture->vector.storage_uuid, fixture->identity.storage_uuid, 16); fixture->vector.cuts = fixture->cuts; @@ -323,15 +302,14 @@ graph_init(GraphFixture *fixture) fixture->root_tokens[0].record_crc32c = 12; fixture->duties[0].origin_thread_id = 1; fixture->duties[0].root_lineage_seq = 9; - memset(fixture->duties[0].authority_uuid, 0x31, - sizeof(fixture->duties[0].authority_uuid)); + memset(fixture->duties[0].authority_uuid, 0x31, sizeof(fixture->duties[0].authority_uuid)); } static RfPageProofDetailV1 graph_select(GraphFixture *fixture) { return rf_page_stable_base_select_v1(&fixture->request, fixture->chain, - lengthof(fixture->chain), &fixture->selection); + lengthof(fixture->chain), &fixture->selection); } static void @@ -341,14 +319,11 @@ proof_request(GraphFixture *fixture, RfPageStableBaseProofRequestV1 *request) request->graph = &fixture->request; request->duties = fixture->duties; request->root_tokens = fixture->root_tokens; - request->formation = - (const ClusterFormationWitnessV1 *) &fixture->formation_object; - request->fence_need_set = - (const PgracExternalFenceNeedSetV1 *) &fixture->needs_object; - request->fence_admission_set = - (const PgracExternalFenceAdmissionSetV1 *) &fixture->admission_object; - request->retention_pin = - (ClusterWalRetentionPin *) &fixture->pin_object; + request->formation = (const ClusterFormationWitnessV1 *)&fixture->formation_object; + request->fence_need_set = (const PgracExternalFenceNeedSetV1 *)&fixture->needs_object; + request->fence_admission_set + = (const PgracExternalFenceAdmissionSetV1 *)&fixture->admission_object; + request->retention_pin = (ClusterWalRetentionPin *)&fixture->pin_object; expected_root_tokens = fixture->root_tokens; expected_duties = fixture->duties; expected_formation = request->formation; @@ -369,13 +344,12 @@ UT_TEST(test_stable_proof_binds_exact_borrowed_owners) graph_init(&fixture); proof_request(&fixture, &request); - UT_ASSERT_EQ(rf_page_stable_base_proof_build_wait_v1(&request, - fixture.chain, lengthof(fixture.chain), 1000, &proof), - RF_PAGE_PROOF_DETAIL_OK); - UT_ASSERT(rf_page_stable_base_proof_matches_v1(proof, - &fixture.identity, &fixture.request.expected_result, - fixture.duties, fixture.root_tokens, request.formation, - request.fence_need_set, request.fence_admission_set, + UT_ASSERT_EQ(rf_page_stable_base_proof_build_wait_v1(&request, fixture.chain, + lengthof(fixture.chain), 1000, &proof), + RF_PAGE_PROOF_DETAIL_OK); + UT_ASSERT(rf_page_stable_base_proof_matches_v1( + proof, &fixture.identity, &fixture.request.expected_result, fixture.duties, + fixture.root_tokens, request.formation, request.fence_need_set, request.fence_admission_set, request.retention_pin, &fixture.source, &fixture.vector, 1)); rf_page_stable_base_proof_destroy_v1(&proof); UT_ASSERT(proof == NULL); @@ -391,17 +365,17 @@ UT_TEST(test_stable_proof_accepts_only_current_bound_pin) graph_init(&fixture); proof_request(&fixture, &request); - UT_ASSERT_EQ(rf_page_stable_base_proof_build_bound_v1(&request, - fixture.chain, lengthof(fixture.chain), &proof), - RF_PAGE_PROOF_DETAIL_OK); + UT_ASSERT_EQ(rf_page_stable_base_proof_build_bound_v1(&request, fixture.chain, + lengthof(fixture.chain), &proof), + RF_PAGE_PROOF_DETAIL_OK); UT_ASSERT(proof != NULL); UT_ASSERT_EQ(preflight_pin_checks, 0); UT_ASSERT_EQ(bound_pin_checks, 1); rf_page_stable_base_proof_destroy_v1(&proof); bound_pin_current = false; - UT_ASSERT_EQ(rf_page_stable_base_proof_build_bound_v1(&request, - fixture.chain, lengthof(fixture.chain), &proof), - RF_PAGE_PROOF_DETAIL_RETENTION_STALE); + UT_ASSERT_EQ(rf_page_stable_base_proof_build_bound_v1(&request, fixture.chain, + lengthof(fixture.chain), &proof), + RF_PAGE_PROOF_DETAIL_RETENTION_STALE); UT_ASSERT(proof == NULL); UT_ASSERT_EQ(preflight_pin_checks, 0); UT_ASSERT_EQ(bound_pin_checks, 2); @@ -418,27 +392,23 @@ UT_TEST(test_stable_proof_rejects_duplicate_owner_scalars) graph_init(&fixture); proof_request(&fixture, &request); - UT_ASSERT_EQ(rf_page_stable_base_proof_build_wait_v1(&request, - fixture.chain, lengthof(fixture.chain), 1000, &proof), - RF_PAGE_PROOF_DETAIL_OK); + UT_ASSERT_EQ(rf_page_stable_base_proof_build_wait_v1(&request, fixture.chain, + lengthof(fixture.chain), 1000, &proof), + RF_PAGE_PROOF_DETAIL_OK); memcpy(copied_root, fixture.root_tokens, sizeof(copied_root)); copied_vector = fixture.vector; copied_source = fixture.source; - UT_ASSERT(!rf_page_stable_base_proof_matches_v1(proof, - &fixture.identity, &fixture.request.expected_result, - fixture.duties, copied_root, request.formation, - request.fence_need_set, request.fence_admission_set, - request.retention_pin, - &fixture.source, &fixture.vector, 1)); - UT_ASSERT(!rf_page_stable_base_proof_matches_v1(proof, - &fixture.identity, &fixture.request.expected_result, - fixture.duties, fixture.root_tokens, request.formation, - request.fence_need_set, request.fence_admission_set, + UT_ASSERT(!rf_page_stable_base_proof_matches_v1( + proof, &fixture.identity, &fixture.request.expected_result, fixture.duties, copied_root, + request.formation, request.fence_need_set, request.fence_admission_set, + request.retention_pin, &fixture.source, &fixture.vector, 1)); + UT_ASSERT(!rf_page_stable_base_proof_matches_v1( + proof, &fixture.identity, &fixture.request.expected_result, fixture.duties, + fixture.root_tokens, request.formation, request.fence_need_set, request.fence_admission_set, request.retention_pin, &copied_source, &fixture.vector, 1)); - UT_ASSERT(!rf_page_stable_base_proof_matches_v1(proof, - &fixture.identity, &fixture.request.expected_result, - fixture.duties, fixture.root_tokens, request.formation, - request.fence_need_set, request.fence_admission_set, + UT_ASSERT(!rf_page_stable_base_proof_matches_v1( + proof, &fixture.identity, &fixture.request.expected_result, fixture.duties, + fixture.root_tokens, request.formation, request.fence_need_set, request.fence_admission_set, request.retention_pin, &fixture.source, &copied_vector, 1)); rf_page_stable_base_proof_destroy_v1(&proof); } @@ -453,9 +423,9 @@ UT_TEST(test_stable_proof_rejects_forged_root_current_boolean) proof_request(&fixture, &request); UT_ASSERT(fixture.request.root_current); canonical_root_current = false; - UT_ASSERT_EQ(rf_page_stable_base_proof_build_wait_v1(&request, - fixture.chain, lengthof(fixture.chain), 1000, &proof), - RF_PAGE_PROOF_DETAIL_ROOT_STALE); + UT_ASSERT_EQ(rf_page_stable_base_proof_build_wait_v1(&request, fixture.chain, + lengthof(fixture.chain), 1000, &proof), + RF_PAGE_PROOF_DETAIL_ROOT_STALE); UT_ASSERT(proof == NULL); } @@ -468,9 +438,9 @@ UT_TEST(test_stable_proof_rejects_root_cut_order_mismatch) graph_init(&fixture); proof_request(&fixture, &request); fixture.root_tokens[0].origin_thread_id = 2; - UT_ASSERT_EQ(rf_page_stable_base_proof_build_wait_v1(&request, - fixture.chain, lengthof(fixture.chain), 1000, &proof), - RF_PAGE_PROOF_DETAIL_ROOT_STALE); + UT_ASSERT_EQ(rf_page_stable_base_proof_build_wait_v1(&request, fixture.chain, + lengthof(fixture.chain), 1000, &proof), + RF_PAGE_PROOF_DETAIL_ROOT_STALE); UT_ASSERT(proof == NULL); } @@ -490,8 +460,7 @@ UT_TEST(test_two_stream_positive) RfPageVersionV1 v2 = make_version(1, 12); graph_init(&fixture); - set_edge(&fixture.edges[1], &fixture.identity, RF_PAGE_STATE_PRESENT, - &v1, &v2, 0, 2, 1); + set_edge(&fixture.edges[1], &fixture.identity, RF_PAGE_STATE_PRESENT, &v1, &v2, 0, 2, 1); fixture.request.expected_result = v2; graph_recount(&fixture, 2, 2); UT_ASSERT_EQ(graph_select(&fixture), RF_PAGE_PROOF_DETAIL_OK); @@ -514,8 +483,7 @@ UT_TEST(test_missing_participant) graph_init(&fixture); fixture.request.participant_count = 2; - UT_ASSERT_EQ(graph_select(&fixture), - RF_PAGE_PROOF_DETAIL_PARTICIPANT_MISSING); + UT_ASSERT_EQ(graph_select(&fixture), RF_PAGE_PROOF_DETAIL_PARTICIPANT_MISSING); } UT_TEST(test_edge_gap) @@ -525,8 +493,8 @@ UT_TEST(test_edge_gap) RfPageVersionV1 result = make_version(1, 13); graph_init(&fixture); - set_edge(&fixture.edges[0], &fixture.identity, RF_PAGE_STATE_PRESENT, - &before, &result, 0, 1, 0); + set_edge(&fixture.edges[0], &fixture.identity, RF_PAGE_STATE_PRESENT, &before, &result, 0, 1, + 0); fixture.request.expected_result = result; graph_recount(&fixture, 1, 1); UT_ASSERT_EQ(graph_select(&fixture), RF_PAGE_PROOF_DETAIL_EDGE_GAP); @@ -540,10 +508,8 @@ UT_TEST(test_edge_branch) RfPageVersionV1 v3 = make_version(1, 13); graph_init(&fixture); - set_edge(&fixture.edges[1], &fixture.identity, RF_PAGE_STATE_PRESENT, - &v1, &v2, 0, 2, 0); - set_edge(&fixture.edges[2], &fixture.identity, RF_PAGE_STATE_PRESENT, - &v1, &v3, 0, 3, 0); + set_edge(&fixture.edges[1], &fixture.identity, RF_PAGE_STATE_PRESENT, &v1, &v2, 0, 2, 0); + set_edge(&fixture.edges[2], &fixture.identity, RF_PAGE_STATE_PRESENT, &v1, &v3, 0, 3, 0); fixture.request.expected_result = v3; graph_recount(&fixture, 1, 3); UT_ASSERT_EQ(graph_select(&fixture), RF_PAGE_PROOF_DETAIL_EDGE_BRANCH); @@ -557,14 +523,11 @@ UT_TEST(test_join_ambiguity) RfPageVersionV1 v3 = make_version(1, 13); graph_init(&fixture); - set_edge(&fixture.edges[1], &fixture.identity, RF_PAGE_STATE_PRESENT, - &v1, &v3, 0, 2, 0); - set_edge(&fixture.edges[2], &fixture.identity, RF_PAGE_STATE_PRESENT, - &v2, &v3, 0, 3, 0); + set_edge(&fixture.edges[1], &fixture.identity, RF_PAGE_STATE_PRESENT, &v1, &v3, 0, 2, 0); + set_edge(&fixture.edges[2], &fixture.identity, RF_PAGE_STATE_PRESENT, &v2, &v3, 0, 3, 0); fixture.request.expected_result = v3; graph_recount(&fixture, 1, 3); - UT_ASSERT_EQ(graph_select(&fixture), - RF_PAGE_PROOF_DETAIL_TERMINAL_AMBIGUOUS); + UT_ASSERT_EQ(graph_select(&fixture), RF_PAGE_PROOF_DETAIL_TERMINAL_AMBIGUOUS); } UT_TEST(test_edge_cycle) @@ -574,10 +537,8 @@ UT_TEST(test_edge_cycle) RfPageVersionV1 v2 = make_version(1, 12); graph_init(&fixture); - set_edge(&fixture.edges[0], &fixture.identity, RF_PAGE_STATE_PRESENT, - &v1, &v2, 0, 1, 0); - set_edge(&fixture.edges[1], &fixture.identity, RF_PAGE_STATE_PRESENT, - &v2, &v1, 0, 2, 0); + set_edge(&fixture.edges[0], &fixture.identity, RF_PAGE_STATE_PRESENT, &v1, &v2, 0, 1, 0); + set_edge(&fixture.edges[1], &fixture.identity, RF_PAGE_STATE_PRESENT, &v2, &v1, 0, 2, 0); fixture.request.expected_result = v2; graph_recount(&fixture, 1, 2); UT_ASSERT_EQ(graph_select(&fixture), RF_PAGE_PROOF_DETAIL_EDGE_CYCLE); @@ -602,8 +563,7 @@ UT_TEST(test_conflicting_duplicate_record) fixture.edges[1] = fixture.edges[0]; fixture.edges[1].result_token++; graph_recount(&fixture, 1, 2); - UT_ASSERT_EQ(graph_select(&fixture), - RF_PAGE_PROOF_DETAIL_ANCHOR_AMBIGUOUS); + UT_ASSERT_EQ(graph_select(&fixture), RF_PAGE_PROOF_DETAIL_ANCHOR_AMBIGUOUS); } UT_TEST(test_duplicate_requires_full_record_identity) @@ -614,8 +574,7 @@ UT_TEST(test_duplicate_requires_full_record_identity) fixture.edges[1] = fixture.edges[0]; fixture.edges[1].record_identity.info++; graph_recount(&fixture, 1, 2); - UT_ASSERT_EQ(graph_select(&fixture), - RF_PAGE_PROOF_DETAIL_ANCHOR_AMBIGUOUS); + UT_ASSERT_EQ(graph_select(&fixture), RF_PAGE_PROOF_DETAIL_ANCHOR_AMBIGUOUS); } UT_TEST(test_unique_terminal) @@ -625,13 +584,11 @@ UT_TEST(test_unique_terminal) RfPageVersionV1 v2 = make_version(1, 12); graph_init(&fixture); - set_edge(&fixture.edges[1], &fixture.identity, RF_PAGE_STATE_PRESENT, - &v1, &v2, 0, 2, 0); + set_edge(&fixture.edges[1], &fixture.identity, RF_PAGE_STATE_PRESENT, &v1, &v2, 0, 2, 0); fixture.request.expected_result = v2; graph_recount(&fixture, 1, 2); UT_ASSERT_EQ(graph_select(&fixture), RF_PAGE_PROOF_DETAIL_OK); - UT_ASSERT(rf_page_version_equal_v1(&fixture.selection.terminal_version, - &v2)); + UT_ASSERT(rf_page_version_equal_v1(&fixture.selection.terminal_version, &v2)); } UT_TEST(test_multiple_terminals) @@ -641,12 +598,10 @@ UT_TEST(test_multiple_terminals) RfPageVersionV1 result = make_version(2, 12); graph_init(&fixture); - set_edge(&fixture.edges[1], &fixture.identity, RF_PAGE_STATE_UNFORMATTED, - &before, &result, - RF_PAGE_EDGE_WILL_INIT | RF_PAGE_EDGE_FULL_COVERAGE, 2, 0); + set_edge(&fixture.edges[1], &fixture.identity, RF_PAGE_STATE_UNFORMATTED, &before, &result, + RF_PAGE_EDGE_WILL_INIT | RF_PAGE_EDGE_FULL_COVERAGE, 2, 0); graph_recount(&fixture, 1, 2); - UT_ASSERT_EQ(graph_select(&fixture), - RF_PAGE_PROOF_DETAIL_TERMINAL_AMBIGUOUS); + UT_ASSERT_EQ(graph_select(&fixture), RF_PAGE_PROOF_DETAIL_TERMINAL_AMBIGUOUS); } UT_TEST(test_nearest_anchor) @@ -657,11 +612,9 @@ UT_TEST(test_nearest_anchor) RfPageVersionV1 v3 = make_version(1, 13); graph_init(&fixture); - set_edge(&fixture.edges[1], &fixture.identity, RF_PAGE_STATE_PRESENT, - &v1, &v2, - RF_PAGE_EDGE_FULL_IMAGE_APPLY | RF_PAGE_EDGE_FULL_COVERAGE, 2, 0); - set_edge(&fixture.edges[2], &fixture.identity, RF_PAGE_STATE_PRESENT, - &v2, &v3, 0, 3, 0); + set_edge(&fixture.edges[1], &fixture.identity, RF_PAGE_STATE_PRESENT, &v1, &v2, + RF_PAGE_EDGE_FULL_IMAGE_APPLY | RF_PAGE_EDGE_FULL_COVERAGE, 2, 0); + set_edge(&fixture.edges[2], &fixture.identity, RF_PAGE_STATE_PRESENT, &v2, &v3, 0, 3, 0); fixture.request.expected_result = v3; graph_recount(&fixture, 1, 3); UT_ASSERT_EQ(graph_select(&fixture), RF_PAGE_PROOF_DETAIL_OK); @@ -676,12 +629,10 @@ UT_TEST(test_off_chain_anchor) RfPageVersionV1 result = make_version(2, 12); graph_init(&fixture); - set_edge(&fixture.edges[1], &fixture.identity, RF_PAGE_STATE_UNFORMATTED, - &before, &result, - RF_PAGE_EDGE_WILL_INIT | RF_PAGE_EDGE_FULL_COVERAGE, 2, 0); + set_edge(&fixture.edges[1], &fixture.identity, RF_PAGE_STATE_UNFORMATTED, &before, &result, + RF_PAGE_EDGE_WILL_INIT | RF_PAGE_EDGE_FULL_COVERAGE, 2, 0); graph_recount(&fixture, 1, 2); - UT_ASSERT_EQ(graph_select(&fixture), - RF_PAGE_PROOF_DETAIL_TERMINAL_AMBIGUOUS); + UT_ASSERT_EQ(graph_select(&fixture), RF_PAGE_PROOF_DETAIL_TERMINAL_AMBIGUOUS); } UT_TEST(test_ambiguous_image) @@ -691,11 +642,9 @@ UT_TEST(test_ambiguous_image) graph_init(&fixture); fixture.edges[1] = fixture.edges[0]; fixture.edges[1].record_identity.record_crc = 2; - memset(fixture.edges[1].anchor_digest, 0x77, - sizeof(fixture.edges[1].anchor_digest)); + memset(fixture.edges[1].anchor_digest, 0x77, sizeof(fixture.edges[1].anchor_digest)); graph_recount(&fixture, 1, 2); - UT_ASSERT_EQ(graph_select(&fixture), - RF_PAGE_PROOF_DETAIL_ANCHOR_AMBIGUOUS); + UT_ASSERT_EQ(graph_select(&fixture), RF_PAGE_PROOF_DETAIL_ANCHOR_AMBIGUOUS); } UT_TEST(test_full_init_anchor) @@ -705,9 +654,8 @@ UT_TEST(test_full_init_anchor) RfPageVersionV1 result = make_version(1, 11); graph_init(&fixture); - set_edge(&fixture.edges[0], &fixture.identity, RF_PAGE_STATE_UNFORMATTED, - &before, &result, - RF_PAGE_EDGE_WILL_INIT | RF_PAGE_EDGE_FULL_COVERAGE, 1, 0); + set_edge(&fixture.edges[0], &fixture.identity, RF_PAGE_STATE_UNFORMATTED, &before, &result, + RF_PAGE_EDGE_WILL_INIT | RF_PAGE_EDGE_FULL_COVERAGE, 1, 0); graph_recount(&fixture, 1, 1); UT_ASSERT_EQ(graph_select(&fixture), RF_PAGE_PROOF_DETAIL_OK); } @@ -719,11 +667,10 @@ UT_TEST(test_partial_init_reject) RfPageVersionV1 result = make_version(1, 11); graph_init(&fixture); - set_edge(&fixture.edges[0], &fixture.identity, RF_PAGE_STATE_UNFORMATTED, - &before, &result, RF_PAGE_EDGE_WILL_INIT, 1, 0); + set_edge(&fixture.edges[0], &fixture.identity, RF_PAGE_STATE_UNFORMATTED, &before, &result, + RF_PAGE_EDGE_WILL_INIT, 1, 0); graph_recount(&fixture, 1, 1); - UT_ASSERT_EQ(graph_select(&fixture), - RF_PAGE_PROOF_DETAIL_IMAGE_DECODE_FAILED); + UT_ASSERT_EQ(graph_select(&fixture), RF_PAGE_PROOF_DETAIL_IMAGE_DECODE_FAILED); } UT_TEST(test_consistency_image_reject) @@ -732,11 +679,9 @@ UT_TEST(test_consistency_image_reject) RfPageVersionV1 result = make_version(1, 11); graph_init(&fixture); - set_edge(&fixture.edges[0], &fixture.identity, RF_PAGE_STATE_ABSENT, - NULL, &result, 0, 1, 0); + set_edge(&fixture.edges[0], &fixture.identity, RF_PAGE_STATE_ABSENT, NULL, &result, 0, 1, 0); graph_recount(&fixture, 1, 1); - UT_ASSERT_EQ(graph_select(&fixture), - RF_PAGE_PROOF_DETAIL_ANCHOR_MISSING); + UT_ASSERT_EQ(graph_select(&fixture), RF_PAGE_PROOF_DETAIL_ANCHOR_MISSING); } UT_TEST(test_source_drift) @@ -754,8 +699,7 @@ UT_TEST(test_pin_drift) graph_init(&fixture); fixture.request.current_retention_binding_cookie++; - UT_ASSERT_EQ(graph_select(&fixture), - RF_PAGE_PROOF_DETAIL_RETENTION_STALE); + UT_ASSERT_EQ(graph_select(&fixture), RF_PAGE_PROOF_DETAIL_RETENTION_STALE); } UT_TEST(test_root_drift) @@ -783,12 +727,11 @@ UT_TEST(test_incarnation_mismatch) RfPageVersionV1 result = make_version(2, 12); graph_init(&fixture); - set_edge(&fixture.edges[0], &fixture.identity, RF_PAGE_STATE_PRESENT, - &before, &result, 0, 1, 0); + set_edge(&fixture.edges[0], &fixture.identity, RF_PAGE_STATE_PRESENT, &before, &result, 0, 1, + 0); fixture.request.expected_result = result; graph_recount(&fixture, 1, 1); - UT_ASSERT_EQ(graph_select(&fixture), - RF_PAGE_PROOF_DETAIL_INCARNATION_MISMATCH); + UT_ASSERT_EQ(graph_select(&fixture), RF_PAGE_PROOF_DETAIL_INCARNATION_MISMATCH); } UT_TEST(test_foreign_identity) @@ -797,8 +740,7 @@ UT_TEST(test_foreign_identity) graph_init(&fixture); fixture.edges[0].page_identity.blockno++; - UT_ASSERT_EQ(graph_select(&fixture), - RF_PAGE_PROOF_DETAIL_IDENTITY_MISMATCH); + UT_ASSERT_EQ(graph_select(&fixture), RF_PAGE_PROOF_DETAIL_IDENTITY_MISMATCH); } UT_TEST(test_unsupported_opcode) @@ -807,8 +749,7 @@ UT_TEST(test_unsupported_opcode) graph_init(&fixture); fixture.edges[0].opcode_supported = false; - UT_ASSERT_EQ(graph_select(&fixture), - RF_PAGE_PROOF_DETAIL_OPCODE_UNSUPPORTED); + UT_ASSERT_EQ(graph_select(&fixture), RF_PAGE_PROOF_DETAIL_OPCODE_UNSUPPORTED); } UT_TEST(test_side_incomplete) @@ -817,35 +758,32 @@ UT_TEST(test_side_incomplete) graph_init(&fixture); fixture.edges[0].side_complete = false; - UT_ASSERT_EQ(graph_select(&fixture), - RF_PAGE_PROOF_DETAIL_SIDE_INCOMPLETE); -} - -typedef struct FakeInstallState -{ - char *targets; - uint32 component_count; - char log[256]; - uint32 log_length; - uint32 write_calls; - uint32 sync_calls; - uint32 postread_calls; - char fail_kind; - uint32 fail_call; - bool corrupt_postread; - bool promoted; - bool canonicalize_after_promote; + UT_ASSERT_EQ(graph_select(&fixture), RF_PAGE_PROOF_DETAIL_SIDE_INCOMPLETE); +} + +typedef struct FakeInstallState { + char *targets; + uint32 component_count; + char log[256]; + uint32 log_length; + uint32 write_calls; + uint32 sync_calls; + uint32 postread_calls; + char fail_kind; + uint32 fail_call; + bool corrupt_postread; + bool promoted; + bool canonicalize_after_promote; } FakeInstallState; -typedef struct InstallFixture -{ +typedef struct InstallFixture { RfPageInstallComponentV1 components[RF_PAGE_STABLE_MAX_COMPONENTS]; RfPageInstallOpsV1 ops; RfPageInstallRequestV1 request; RfPageInstallProofV1 proof; FakeInstallState state; - char *canonical; - char *prepared; + char *canonical; + char *prepared; } InstallFixture; static void @@ -857,17 +795,16 @@ fake_log(FakeInstallState *state, char operation) } static bool -fake_canonicalize(void *arg, uint32 index, bool checksums_enabled, - char page[BLCKSZ]) +fake_canonicalize(void *arg, uint32 index, bool checksums_enabled, char page[BLCKSZ]) { FakeInstallState *state = arg; - (void) index; + (void)index; fake_log(state, 'C'); if (state->promoted) state->canonicalize_after_promote = true; if (checksums_enabled) - page[8] = (char) 0x5a; + page[8] = (char)0x5a; return true; } @@ -890,7 +827,7 @@ fake_write(void *arg, uint32 index, const char page[BLCKSZ]) state->write_calls++; if (state->fail_kind == 'W' && state->write_calls == state->fail_call) return false; - memcpy(state->targets + (Size) index * BLCKSZ, page, BLCKSZ); + memcpy(state->targets + (Size)index * BLCKSZ, page, BLCKSZ); return true; } @@ -899,11 +836,10 @@ fake_sync(void *arg, uint32 index) { FakeInstallState *state = arg; - (void) index; + (void)index; fake_log(state, 'S'); state->sync_calls++; - return !(state->fail_kind == 'S' && - state->sync_calls == state->fail_call); + return !(state->fail_kind == 'S' && state->sync_calls == state->fail_call); } static bool @@ -913,10 +849,9 @@ fake_postread(void *arg, uint32 index, char page[BLCKSZ]) fake_log(state, 'R'); state->postread_calls++; - if (state->fail_kind == 'R' && - state->postread_calls == state->fail_call) + if (state->fail_kind == 'R' && state->postread_calls == state->fail_call) return false; - memcpy(page, state->targets + (Size) index * BLCKSZ, BLCKSZ); + memcpy(page, state->targets + (Size)index * BLCKSZ, BLCKSZ); if (state->corrupt_postread) page[BLCKSZ - 1] ^= 0x01; return true; @@ -945,7 +880,7 @@ static void install_init(InstallFixture *fixture, uint32 component_count) { uint32 i; - Size bytes = (Size) component_count * BLCKSZ; + Size bytes = (Size)component_count * BLCKSZ; memset(fixture, 0, sizeof(*fixture)); fixture->canonical = calloc(1, bytes); @@ -955,12 +890,11 @@ install_init(InstallFixture *fixture, uint32 component_count) UT_ASSERT(fixture->prepared != NULL); UT_ASSERT(fixture->state.targets != NULL); fixture->state.component_count = component_count; - for (i = 0; i < component_count; i++) - { - char *canonical = fixture->canonical + (Size) i * BLCKSZ; + for (i = 0; i < component_count; i++) { + char *canonical = fixture->canonical + (Size)i * BLCKSZ; - memset(canonical, (int) (0x10 + i), BLCKSZ); - memset(fixture->state.targets + (Size) i * BLCKSZ, 0x44, BLCKSZ); + memset(canonical, (int)(0x10 + i), BLCKSZ); + memset(fixture->state.targets + (Size)i * BLCKSZ, 0x44, BLCKSZ); fixture->components[i].page_identity = make_identity(i + 1); fixture->components[i].expected_before = make_version(1, 100 + i); fixture->components[i].expected_result = make_version(1, 200 + i); @@ -1023,8 +957,7 @@ UT_TEST(test_no_mutation_before_preflight) install_init(&fixture, 1); fixture.components[0].side_preflight_ok = false; - UT_ASSERT_EQ(install_run(&fixture), - RF_PAGE_PROOF_DETAIL_COMPONENT_INCOMPLETE); + UT_ASSERT_EQ(install_run(&fixture), RF_PAGE_PROOF_DETAIL_COMPONENT_INCOMPLETE); UT_ASSERT_EQ(fixture.state.log_length, 0); install_destroy(&fixture); } @@ -1089,8 +1022,7 @@ UT_TEST(test_unrelated_version_reject) install_init(&fixture, 1); fixture.components[0].target_state = RF_PAGE_INSTALL_TARGET_UNRELATED; - UT_ASSERT_EQ(install_run(&fixture), - RF_PAGE_PROOF_DETAIL_VERSION_MISMATCH); + UT_ASSERT_EQ(install_run(&fixture), RF_PAGE_PROOF_DETAIL_VERSION_MISMATCH); UT_ASSERT_EQ(fixture.state.log_length, 0); install_destroy(&fixture); } @@ -1118,8 +1050,7 @@ UT_TEST(test_crash_after_last_write_before_sync) install_init(&fixture, 2); fixture.state.fail_kind = 'S'; fixture.state.fail_call = 1; - UT_ASSERT_EQ(install_run(&fixture), - RF_PAGE_PROOF_DETAIL_POSTREAD_FAILED); + UT_ASSERT_EQ(install_run(&fixture), RF_PAGE_PROOF_DETAIL_POSTREAD_FAILED); fixture.components[0].target_state = RF_PAGE_INSTALL_TARGET_RESULT; fixture.components[1].target_state = RF_PAGE_INSTALL_TARGET_RESULT; install_reset_attempt(&fixture); @@ -1135,8 +1066,7 @@ UT_TEST(test_crash_after_sync_before_postread) install_init(&fixture, 1); fixture.state.fail_kind = 'R'; fixture.state.fail_call = 1; - UT_ASSERT_EQ(install_run(&fixture), - RF_PAGE_PROOF_DETAIL_POSTREAD_FAILED); + UT_ASSERT_EQ(install_run(&fixture), RF_PAGE_PROOF_DETAIL_POSTREAD_FAILED); fixture.components[0].target_state = RF_PAGE_INSTALL_TARGET_RESULT; install_reset_attempt(&fixture); UT_ASSERT_EQ(install_run(&fixture), RF_PAGE_PROOF_DETAIL_OK); @@ -1150,7 +1080,7 @@ UT_TEST(test_checksum_on_recompute) install_init(&fixture, 1); fixture.components[0].checksums_enabled = true; UT_ASSERT_EQ(install_run(&fixture), RF_PAGE_PROOF_DETAIL_OK); - UT_ASSERT_EQ((uint8) fixture.state.targets[8], 0x5a); + UT_ASSERT_EQ((uint8)fixture.state.targets[8], 0x5a); install_destroy(&fixture); } @@ -1160,8 +1090,7 @@ UT_TEST(test_checksum_off_full_page_compare) install_init(&fixture, 1); fixture.state.corrupt_postread = true; - UT_ASSERT_EQ(install_run(&fixture), - RF_PAGE_PROOF_DETAIL_POSTREAD_FAILED); + UT_ASSERT_EQ(install_run(&fixture), RF_PAGE_PROOF_DETAIL_POSTREAD_FAILED); install_destroy(&fixture); } @@ -1171,8 +1100,7 @@ UT_TEST(test_zero_page_reject) install_init(&fixture, 1); memset(fixture.canonical, 0, BLCKSZ); - UT_ASSERT_EQ(install_run(&fixture), - RF_PAGE_PROOF_DETAIL_IMAGE_INTEGRITY_FAILED); + UT_ASSERT_EQ(install_run(&fixture), RF_PAGE_PROOF_DETAIL_IMAGE_INTEGRITY_FAILED); UT_ASSERT_EQ(fixture.state.log_length, 0); install_destroy(&fixture); } @@ -1184,8 +1112,7 @@ UT_TEST(test_ignore_checksum_bypass_forbidden) install_init(&fixture, 1); fixture.components[0].checksums_enabled = true; fixture.state.corrupt_postread = true; - UT_ASSERT_EQ(install_run(&fixture), - RF_PAGE_PROOF_DETAIL_POSTREAD_FAILED); + UT_ASSERT_EQ(install_run(&fixture), RF_PAGE_PROOF_DETAIL_POSTREAD_FAILED); UT_ASSERT(!fixture.proof.proof_published); install_destroy(&fixture); } diff --git a/src/test/cluster_unit/test_cluster_page_stats.c b/src/test/cluster_unit/test_cluster_page_stats.c index 5e5cc162e76..cf97f3fe771 100644 --- a/src/test/cluster_unit/test_cluster_page_stats.c +++ b/src/test/cluster_unit/test_cluster_page_stats.c @@ -44,57 +44,50 @@ GetCurrentTimestamp(void) static int64 ticks = 1000000; ticks += 1000000; - return (TimestampTz) ticks; + return (TimestampTz)ticks; } static ClusterPageRecoveryStats ut_stats; UT_TEST(test_counters_have_one_kind_each) { - static const char *event_names[] = { - "cluster.page.source_selected_current", - "cluster.page.source_selected_pi", - "cluster.page.source_selected_storage", - "cluster.page.source_invalid", - "cluster.page.source_missing", - "cluster.page.source_conflict", - "cluster.page.result_skip", - "cluster.page.apply_count", - "cluster.page.version_mismatch", - "cluster.page.unknown_class_blocked", - "cluster.page.authority_stale_rejected", - "cluster.page.resource_early_release", - "cluster.page.retire_denied", - "cluster.page.d3_rebuild", - "cluster.page.d3_optimization_hit", - "cluster.page.stable_base_unresolved" - }; - static const char *gauge_names[] = { - "cluster.page.contributor_records", - "cluster.page.contributor_threads", - "cluster.page.contributor_gaps", - "cluster.page.retained_pinned_bytes" - }; - static const char *ts_names[] = { - "cluster.page.last_page_write_ts", - "cluster.page.last_durability_barrier_ts", - "cluster.page.last_post_read_ts" - }; - int i; + static const char *event_names[] = { "cluster.page.source_selected_current", + "cluster.page.source_selected_pi", + "cluster.page.source_selected_storage", + "cluster.page.source_invalid", + "cluster.page.source_missing", + "cluster.page.source_conflict", + "cluster.page.result_skip", + "cluster.page.apply_count", + "cluster.page.version_mismatch", + "cluster.page.unknown_class_blocked", + "cluster.page.authority_stale_rejected", + "cluster.page.resource_early_release", + "cluster.page.retire_denied", + "cluster.page.d3_rebuild", + "cluster.page.d3_optimization_hit", + "cluster.page.stable_base_unresolved" }; + static const char *gauge_names[] + = { "cluster.page.contributor_records", "cluster.page.contributor_threads", + "cluster.page.contributor_gaps", "cluster.page.retained_pinned_bytes" }; + static const char *ts_names[] + = { "cluster.page.last_page_write_ts", "cluster.page.last_durability_barrier_ts", + "cluster.page.last_post_read_ts" }; + int i; ClusterPageStatKind kind; /* G2: every §9.1 metric is exactly one of EVENT/GAUGE/TIMESTAMP. */ - for (i = 0; i < (int) lengthof(event_names); i++) { + for (i = 0; i < (int)lengthof(event_names); i++) { UT_ASSERT(cluster_page_stats_describe(event_names[i], &kind)); - UT_ASSERT_EQ((int) kind, (int) CLUSTER_PAGE_STAT_EVENT); + UT_ASSERT_EQ((int)kind, (int)CLUSTER_PAGE_STAT_EVENT); } - for (i = 0; i < (int) lengthof(gauge_names); i++) { + for (i = 0; i < (int)lengthof(gauge_names); i++) { UT_ASSERT(cluster_page_stats_describe(gauge_names[i], &kind)); - UT_ASSERT_EQ((int) kind, (int) CLUSTER_PAGE_STAT_GAUGE); + UT_ASSERT_EQ((int)kind, (int)CLUSTER_PAGE_STAT_GAUGE); } - for (i = 0; i < (int) lengthof(ts_names); i++) { + for (i = 0; i < (int)lengthof(ts_names); i++) { UT_ASSERT(cluster_page_stats_describe(ts_names[i], &kind)); - UT_ASSERT_EQ((int) kind, (int) CLUSTER_PAGE_STAT_TIMESTAMP); + UT_ASSERT_EQ((int)kind, (int)CLUSTER_PAGE_STAT_TIMESTAMP); } /* Unknown names fail closed. */ UT_ASSERT(!cluster_page_stats_describe("cluster.page.no_such", &kind)); @@ -122,11 +115,9 @@ UT_TEST(test_event_producers) cluster_page_stats_d3_rebuild(&ut_stats, false); cluster_page_stats_d3_rebuild(&ut_stats, true); - UT_ASSERT_EQ(pg_atomic_read_u64(&ut_stats.source_selected_current), - UINT64_C(1)); + UT_ASSERT_EQ(pg_atomic_read_u64(&ut_stats.source_selected_current), UINT64_C(1)); UT_ASSERT_EQ(pg_atomic_read_u64(&ut_stats.source_selected_pi), UINT64_C(1)); - UT_ASSERT_EQ(pg_atomic_read_u64(&ut_stats.source_selected_storage), - UINT64_C(1)); + UT_ASSERT_EQ(pg_atomic_read_u64(&ut_stats.source_selected_storage), UINT64_C(1)); UT_ASSERT_EQ(pg_atomic_read_u64(&ut_stats.source_invalid), UINT64_C(1)); UT_ASSERT_EQ(pg_atomic_read_u64(&ut_stats.source_missing), UINT64_C(1)); UT_ASSERT_EQ(pg_atomic_read_u64(&ut_stats.source_conflict), UINT64_C(1)); @@ -134,13 +125,10 @@ UT_TEST(test_event_producers) UT_ASSERT_EQ(pg_atomic_read_u64(&ut_stats.apply_count), UINT64_C(1)); UT_ASSERT_EQ(pg_atomic_read_u64(&ut_stats.version_mismatch), UINT64_C(1)); UT_ASSERT_EQ(pg_atomic_read_u64(&ut_stats.unknown_class_blocked), UINT64_C(1)); - UT_ASSERT_EQ(pg_atomic_read_u64(&ut_stats.authority_stale_rejected), - UINT64_C(1)); - UT_ASSERT_EQ(pg_atomic_read_u64(&ut_stats.resource_early_release), - UINT64_C(1)); + UT_ASSERT_EQ(pg_atomic_read_u64(&ut_stats.authority_stale_rejected), UINT64_C(1)); + UT_ASSERT_EQ(pg_atomic_read_u64(&ut_stats.resource_early_release), UINT64_C(1)); UT_ASSERT_EQ(pg_atomic_read_u64(&ut_stats.retire_denied), UINT64_C(1)); - UT_ASSERT_EQ(pg_atomic_read_u64(&ut_stats.stable_base_unresolved), - UINT64_C(1)); + UT_ASSERT_EQ(pg_atomic_read_u64(&ut_stats.stable_base_unresolved), UINT64_C(1)); UT_ASSERT_EQ(pg_atomic_read_u64(&ut_stats.d3_rebuild), UINT64_C(1)); UT_ASSERT_EQ(pg_atomic_read_u64(&ut_stats.d3_optimization_hit), UINT64_C(1)); @@ -158,8 +146,7 @@ UT_TEST(test_gauge_and_timestamp_producers) UT_ASSERT_EQ(pg_atomic_read_u64(&ut_stats.contributor_records), UINT64_C(12)); UT_ASSERT_EQ(pg_atomic_read_u64(&ut_stats.contributor_threads), UINT64_C(2)); UT_ASSERT_EQ(pg_atomic_read_u64(&ut_stats.contributor_gaps), UINT64_C(0)); - UT_ASSERT_EQ(pg_atomic_read_u64(&ut_stats.retained_pinned_bytes), - UINT64_C(4096)); + UT_ASSERT_EQ(pg_atomic_read_u64(&ut_stats.retained_pinned_bytes), UINT64_C(4096)); /* Timestamps are written (non-zero after note). */ cluster_page_stats_note_page_write(&ut_stats); @@ -173,10 +160,10 @@ UT_TEST(test_gauge_and_timestamp_producers) UT_TEST(test_attempt_dump_full_field_set) { ClusterPageAttemptDump d; - char buf[512]; - char small[32]; - int written; - int full; + char buf[512]; + char small[32]; + int written; + int full; memset(&d, 0, sizeof(d)); d.failed_origin_thread = 2; @@ -229,7 +216,7 @@ UT_TEST(test_attempt_dump_full_field_set) /* Small buffers truncate safely; the return is the would-be length. */ written = cluster_page_attempt_dump(&d, small, sizeof(small)); - UT_ASSERT(written >= full); /* snprintf semantics */ + UT_ASSERT(written >= full); /* snprintf semantics */ small[sizeof(small) - 1] = '\0'; /* NUL-terminated by snprintf */ /* NULL dump is a no-op. */ diff --git a/src/test/cluster_unit/test_cluster_page_version.c b/src/test/cluster_unit/test_cluster_page_version.c index e07df24ff08..27bc9e92c24 100644 --- a/src/test/cluster_unit/test_cluster_page_version.c +++ b/src/test/cluster_unit/test_cluster_page_version.c @@ -100,16 +100,13 @@ UT_TEST(test_pu01_invalid_scn_normal_page_blocked) /* InvalidScn containment: BLOCKED, never a version success. */ UT_ASSERT(!cluster_page_version_valid(&result_invalid)); - UT_ASSERT_EQ((int) cluster_page_version_decide( - ¤t, &expected, &result_invalid, &trusted), - (int) CLUSTER_PAGE_APPLY_BLOCKED); + UT_ASSERT_EQ((int)cluster_page_version_decide(¤t, &expected, &result_invalid, &trusted), + (int)CLUSTER_PAGE_APPLY_BLOCKED); /* An invalid expected-before or current is equally BLOCKED. */ - UT_ASSERT_EQ((int) cluster_page_version_decide( - NULL, &expected, ¤t, NULL), - (int) CLUSTER_PAGE_APPLY_BLOCKED); - UT_ASSERT_EQ((int) cluster_page_version_decide( - ¤t, NULL, ¤t, NULL), - (int) CLUSTER_PAGE_APPLY_BLOCKED); + UT_ASSERT_EQ((int)cluster_page_version_decide(NULL, &expected, ¤t, NULL), + (int)CLUSTER_PAGE_APPLY_BLOCKED); + UT_ASSERT_EQ((int)cluster_page_version_decide(¤t, NULL, ¤t, NULL), + (int)CLUSTER_PAGE_APPLY_BLOCKED); } UT_TEST(test_pu02_expected_before_exact_match_applies) @@ -124,14 +121,12 @@ UT_TEST(test_pu02_expected_before_exact_match_applies) result = ut_version(7, 101); trusted = ut_version(7, 50); - UT_ASSERT_EQ((int) cluster_page_version_decide( - ¤t, &expected, &result, &trusted), - (int) CLUSTER_PAGE_APPLY_APPLY); + UT_ASSERT_EQ((int)cluster_page_version_decide(¤t, &expected, &result, &trusted), + (int)CLUSTER_PAGE_APPLY_APPLY); /* The trusted source is irrelevant when it does not equal the result: * exact expected-before match still admits the apply. */ - UT_ASSERT_EQ((int) cluster_page_version_decide( - ¤t, &expected, &result, NULL), - (int) CLUSTER_PAGE_APPLY_APPLY); + UT_ASSERT_EQ((int)cluster_page_version_decide(¤t, &expected, &result, NULL), + (int)CLUSTER_PAGE_APPLY_APPLY); } UT_TEST(test_pu03_expected_before_mismatch_blocked) @@ -144,16 +139,14 @@ UT_TEST(test_pu03_expected_before_mismatch_blocked) expected = ut_version(7, 99); /* mismatch on the token */ result = ut_version(7, 101); - UT_ASSERT_EQ((int) cluster_page_version_decide( - ¤t, &expected, &result, NULL), - (int) CLUSTER_PAGE_APPLY_BLOCKED); + UT_ASSERT_EQ((int)cluster_page_version_decide(¤t, &expected, &result, NULL), + (int)CLUSTER_PAGE_APPLY_BLOCKED); /* Different incarnation with the "same" SCN-shaped token is a mismatch * too (PU-06): incarnation participates in exact equality. */ current = ut_version(8, 100); expected = ut_version(7, 100); - UT_ASSERT_EQ((int) cluster_page_version_decide( - ¤t, &expected, &result, NULL), - (int) CLUSTER_PAGE_APPLY_BLOCKED); + UT_ASSERT_EQ((int)cluster_page_version_decide(¤t, &expected, &result, NULL), + (int)CLUSTER_PAGE_APPLY_BLOCKED); } UT_TEST(test_pu04_trusted_exact_result_skips) @@ -170,9 +163,8 @@ UT_TEST(test_pu04_trusted_exact_result_skips) /* Trusted result-version skip (shape 1): zero apply, even though the * working version does not match expected_before. */ - UT_ASSERT_EQ((int) cluster_page_version_decide( - ¤t, &expected, &result, &trusted), - (int) CLUSTER_PAGE_APPLY_SKIP); + UT_ASSERT_EQ((int)cluster_page_version_decide(¤t, &expected, &result, &trusted), + (int)CLUSTER_PAGE_APPLY_SKIP); } UT_TEST(test_pu05_numeric_higher_with_gap_no_skip) @@ -191,17 +183,15 @@ UT_TEST(test_pu05_numeric_higher_with_gap_no_skip) result = ut_version(7, 101); trusted = ut_version(7, 99); - UT_ASSERT_EQ((int) cluster_page_version_decide( - ¤t, &expected, &result, &trusted), - (int) CLUSTER_PAGE_APPLY_BLOCKED); + UT_ASSERT_EQ((int)cluster_page_version_decide(¤t, &expected, &result, &trusted), + (int)CLUSTER_PAGE_APPLY_BLOCKED); /* A numerically-higher CURRENT also proves nothing: exact equality is * the only predicate. */ current = ut_version(7, 200); expected = ut_version(7, 5); - UT_ASSERT_EQ((int) cluster_page_version_decide( - ¤t, &expected, &result, NULL), - (int) CLUSTER_PAGE_APPLY_BLOCKED); + UT_ASSERT_EQ((int)cluster_page_version_decide(¤t, &expected, &result, NULL), + (int)CLUSTER_PAGE_APPLY_BLOCKED); } UT_TEST(test_pu06_same_scn_different_incarnation_mismatch) @@ -218,9 +208,8 @@ UT_TEST(test_pu06_same_scn_different_incarnation_mismatch) result = ut_version(11, 556); UT_ASSERT(!cluster_page_version_equal(¤t, &expected)); - UT_ASSERT_EQ((int) cluster_page_version_decide( - ¤t, &expected, &result, NULL), - (int) CLUSTER_PAGE_APPLY_BLOCKED); + UT_ASSERT_EQ((int)cluster_page_version_decide(¤t, &expected, &result, NULL), + (int)CLUSTER_PAGE_APPLY_BLOCKED); /* A different physical identity is likewise never equal. */ { @@ -252,7 +241,7 @@ UT_TEST(test_version_identity_helpers) v = ut_version(7, 100); UT_ASSERT(cluster_page_version_valid(&v)); UT_ASSERT(cluster_page_version_equal(&v, &v)); - UT_ASSERT(!cluster_page_version_valid(&(ClusterPageVersion){0})); + UT_ASSERT(!cluster_page_version_valid(&(ClusterPageVersion){ 0 })); { ClusterPageVersion inv = v; @@ -280,7 +269,7 @@ ut_classify_input(void) ClusterPageClassifyInput in; memset(&in, 0, sizeof(in)); - in.rmid = 250; /* deliberately unregistered by default */ + in.rmid = 250; /* deliberately unregistered by default */ in.opcode = 0x10; in.forknum = MAIN_FORKNUM; in.header_owner = CLUSTER_PAGE_HEADER_OWNER_NONE; @@ -293,11 +282,9 @@ UT_TEST(test_pu07_unknown_rmid_opcode_default_blocked) /* Unknown rmid/opcode on a main-fork persistent page: UNKNOWN -> the * caller must fail closed (mutation=0). */ - UT_ASSERT_EQ((int) cluster_page_classify(&in), - (int) CLUSTER_PAGE_CLASS_UNKNOWN); + UT_ASSERT_EQ((int)cluster_page_classify(&in), (int)CLUSTER_PAGE_CLASS_UNKNOWN); /* NULL input is UNKNOWN too. */ - UT_ASSERT_EQ((int) cluster_page_classify(NULL), - (int) CLUSTER_PAGE_CLASS_UNKNOWN); + UT_ASSERT_EQ((int)cluster_page_classify(NULL), (int)CLUSTER_PAGE_CLASS_UNKNOWN); } UT_TEST(test_pu08_normal_persistent_page_chain_required) @@ -315,8 +302,7 @@ UT_TEST(test_pu08_normal_persistent_page_chain_required) UT_ASSERT(cluster_page_class_is_known_opcode(9, 0x20)); in.rmid = 9; in.opcode = 0x20; - UT_ASSERT_EQ((int) cluster_page_classify(&in), - (int) CLUSTER_PAGE_CLASS_NORMAL); + UT_ASSERT_EQ((int)cluster_page_classify(&in), (int)CLUSTER_PAGE_CLASS_NORMAL); /* NORMAL requires the full PageVersion before/result chain: with any * invalid member the admission decision is BLOCKED (no chain -> no @@ -324,13 +310,11 @@ UT_TEST(test_pu08_normal_persistent_page_chain_required) current = ut_version(7, 100); expected = ut_version(7, 100); result = ut_version(7, 101); - UT_ASSERT_EQ((int) cluster_page_version_decide( - ¤t, &expected, &result, NULL), - (int) CLUSTER_PAGE_APPLY_APPLY); + UT_ASSERT_EQ((int)cluster_page_version_decide(¤t, &expected, &result, NULL), + (int)CLUSTER_PAGE_APPLY_APPLY); /* Missing result (chain not produced) -> BLOCKED. */ - UT_ASSERT_EQ((int) cluster_page_version_decide( - ¤t, &expected, NULL, NULL), - (int) CLUSTER_PAGE_APPLY_BLOCKED); + UT_ASSERT_EQ((int)cluster_page_version_decide(¤t, &expected, NULL, NULL), + (int)CLUSTER_PAGE_APPLY_BLOCKED); } UT_TEST(test_pu13_fsm_rebuildable_class) @@ -340,16 +324,13 @@ UT_TEST(test_pu13_fsm_rebuildable_class) in.forknum = FSM_FORKNUM; /* FSM is the approved deviation: rebuildable hint cache, never generic * redo apply — classified without any rmgr registration. */ - UT_ASSERT_EQ((int) cluster_page_classify(&in), - (int) CLUSTER_PAGE_CLASS_REBUILDABLE); + UT_ASSERT_EQ((int)cluster_page_classify(&in), (int)CLUSTER_PAGE_CLASS_REBUILDABLE); /* FSM + image/init/cleanout attributes are ambiguous -> UNKNOWN. */ in.has_full_page_image = true; - UT_ASSERT_EQ((int) cluster_page_classify(&in), - (int) CLUSTER_PAGE_CLASS_UNKNOWN); + UT_ASSERT_EQ((int)cluster_page_classify(&in), (int)CLUSTER_PAGE_CLASS_UNKNOWN); in.has_full_page_image = false; in.has_will_init = true; - UT_ASSERT_EQ((int) cluster_page_classify(&in), - (int) CLUSTER_PAGE_CLASS_UNKNOWN); + UT_ASSERT_EQ((int)cluster_page_classify(&in), (int)CLUSTER_PAGE_CLASS_UNKNOWN); } UT_TEST(test_pu14_header_routes_to_typed_owner) @@ -357,17 +338,14 @@ UT_TEST(test_pu14_header_routes_to_typed_owner) ClusterPageClassifyInput in = ut_classify_input(); in.header_owner = CLUSTER_PAGE_HEADER_OWNER_ROOT; - UT_ASSERT_EQ((int) cluster_page_classify(&in), - (int) CLUSTER_PAGE_CLASS_HEADER); + UT_ASSERT_EQ((int)cluster_page_classify(&in), (int)CLUSTER_PAGE_CLASS_HEADER); in.header_owner = CLUSTER_PAGE_HEADER_OWNER_SIDE; - UT_ASSERT_EQ((int) cluster_page_classify(&in), - (int) CLUSTER_PAGE_CLASS_HEADER); + UT_ASSERT_EQ((int)cluster_page_classify(&in), (int)CLUSTER_PAGE_CLASS_HEADER); /* A header declaration combined with temp/FSM/new/image is ambiguous * -> UNKNOWN (multi-match). */ in.header_owner = CLUSTER_PAGE_HEADER_OWNER_PG_CORE; in.forknum = INIT_FORKNUM; - UT_ASSERT_EQ((int) cluster_page_classify(&in), - (int) CLUSTER_PAGE_CLASS_UNKNOWN); + UT_ASSERT_EQ((int)cluster_page_classify(&in), (int)CLUSTER_PAGE_CLASS_UNKNOWN); } UT_TEST(test_pu17_will_init_without_rule_blocked) @@ -377,12 +355,10 @@ UT_TEST(test_pu17_will_init_without_rule_blocked) /* WILL_INIT alone never authorizes initialization; no exact rmgr * full-init rule is registered, so the class is UNKNOWN (BLOCKED). */ in.has_will_init = true; - UT_ASSERT_EQ((int) cluster_page_classify(&in), - (int) CLUSTER_PAGE_CLASS_UNKNOWN); + UT_ASSERT_EQ((int)cluster_page_classify(&in), (int)CLUSTER_PAGE_CLASS_UNKNOWN); /* FPI + WILL_INIT is a multi-match -> UNKNOWN as well. */ in.has_full_page_image = true; - UT_ASSERT_EQ((int) cluster_page_classify(&in), - (int) CLUSTER_PAGE_CLASS_UNKNOWN); + UT_ASSERT_EQ((int)cluster_page_classify(&in), (int)CLUSTER_PAGE_CLASS_UNKNOWN); } UT_TEST(test_classifier_remaining_rows_closed) @@ -391,61 +367,52 @@ UT_TEST(test_classifier_remaining_rows_closed) /* PC-TEMP: temp fork or temp-scoped relation. */ in.forknum = INIT_FORKNUM; - UT_ASSERT_EQ((int) cluster_page_classify(&in), - (int) CLUSTER_PAGE_CLASS_TEMP); + UT_ASSERT_EQ((int)cluster_page_classify(&in), (int)CLUSTER_PAGE_CLASS_TEMP); in.forknum = MAIN_FORKNUM; in.relation_is_temp = true; - UT_ASSERT_EQ((int) cluster_page_classify(&in), - (int) CLUSTER_PAGE_CLASS_TEMP); + UT_ASSERT_EQ((int)cluster_page_classify(&in), (int)CLUSTER_PAGE_CLASS_TEMP); in.relation_is_temp = false; /* PC-FULLIMAGE: FPI is an image payload row (lineage admission is the * apply layer's). */ in.has_full_page_image = true; - UT_ASSERT_EQ((int) cluster_page_classify(&in), - (int) CLUSTER_PAGE_CLASS_FULLIMAGE); + UT_ASSERT_EQ((int)cluster_page_classify(&in), (int)CLUSTER_PAGE_CLASS_FULLIMAGE); in.has_full_page_image = false; /* PC-NEW: absent or uninitialized page. */ in.page_absent = true; - UT_ASSERT_EQ((int) cluster_page_classify(&in), - (int) CLUSTER_PAGE_CLASS_NEW); + UT_ASSERT_EQ((int)cluster_page_classify(&in), (int)CLUSTER_PAGE_CLASS_NEW); in.page_absent = false; in.page_is_new = true; - UT_ASSERT_EQ((int) cluster_page_classify(&in), - (int) CLUSTER_PAGE_CLASS_NEW); + UT_ASSERT_EQ((int)cluster_page_classify(&in), (int)CLUSTER_PAGE_CLASS_NEW); in.page_is_new = false; /* PC-CLEANOUT / PC-NONLOGGED: declared classes (recovery action stays * BLOCKED until producer + exact codec census land, PGDEL-02/06). */ in.is_cleanout = true; - UT_ASSERT_EQ((int) cluster_page_classify(&in), - (int) CLUSTER_PAGE_CLASS_CLEANOUT); + UT_ASSERT_EQ((int)cluster_page_classify(&in), (int)CLUSTER_PAGE_CLASS_CLEANOUT); in.is_cleanout = false; in.relation_is_unlogged = true; - UT_ASSERT_EQ((int) cluster_page_classify(&in), - (int) CLUSTER_PAGE_CLASS_NONLOGGED); + UT_ASSERT_EQ((int)cluster_page_classify(&in), (int)CLUSTER_PAGE_CLASS_NONLOGGED); in.relation_is_unlogged = false; /* Cleanout/nonlogged combined with image/init is ambiguous. */ in.is_cleanout = true; in.has_will_init = true; - UT_ASSERT_EQ((int) cluster_page_classify(&in), - (int) CLUSTER_PAGE_CLASS_UNKNOWN); + UT_ASSERT_EQ((int)cluster_page_classify(&in), (int)CLUSTER_PAGE_CLASS_UNKNOWN); } UT_TEST(test_known_opcode_registry_fail_closed) { - uint8 rmid = 200; - int i; + uint8 rmid = 200; + int i; /* Fixed capacity: registration is refused once the table is full * (fail-closed) — an overflow must never silently admit. Run LAST: * it fills the registry. (One earlier test registered (9, 0x20), so * 63 more entries fill the 64-slot table.) */ for (i = 0; i < 63; i++) - UT_ASSERT(cluster_page_class_register_known_opcode(rmid, - (uint16) (0x100 + i))); + UT_ASSERT(cluster_page_class_register_known_opcode(rmid, (uint16)(0x100 + i))); UT_ASSERT(!cluster_page_class_register_known_opcode(rmid, 0x7fff)); /* Idempotent re-registration still succeeds. */ UT_ASSERT(cluster_page_class_register_known_opcode(rmid, 0x100)); diff --git a/src/test/cluster_unit/test_cluster_pcm_direct_init.c b/src/test/cluster_unit/test_cluster_pcm_direct_init.c index 34fa2d98452..f65756102ce 100644 --- a/src/test/cluster_unit/test_cluster_pcm_direct_init.c +++ b/src/test/cluster_unit/test_cluster_pcm_direct_init.c @@ -30,6 +30,9 @@ UT_DEFINE_GLOBALS(); #ifndef HIO_SOURCE_PATH #error "HIO_SOURCE_PATH must identify production hio.c" #endif +#ifndef PROBES_SOURCE_PATH +#error "PROBES_SOURCE_PATH must identify production probes.d" +#endif void ExceptionalCondition(const char *conditionName pg_attribute_unused(), @@ -125,11 +128,10 @@ assert_ordered(const char *source, const char *const *needles, int count) static int count_occurrences(const char *source, const char *needle) { - int count = 0; + int count = 0; const char *cursor = source; - while ((cursor = strstr(cursor, needle)) != NULL) - { + while ((cursor = strstr(cursor, needle)) != NULL) { count++; cursor += strlen(needle); } @@ -265,45 +267,50 @@ UT_TEST(test_state_s_and_live_reservations_are_rejected_by_class) UT_TEST(test_aux_pending_observer_accepts_only_exact_existing_reservation) { - ClusterPcmDirectInitSnapshot snapshot - = make_snapshot(CLUSTER_PCM_DIRECT_INIT_VM); + ClusterPcmDirectInitSnapshot snapshot = make_snapshot(CLUSTER_PCM_DIRECT_INIT_VM); snapshot.flags = PCM_OWN_FLAG_GRANT_PENDING; snapshot.reservation_token = 9; + UT_ASSERT_EQ(cluster_pcm_direct_init_aux_pending_observer_validate(CLUSTER_PCM_DIRECT_INIT_VM, + &snapshot), + CLUSTER_PCM_OWN_OK); UT_ASSERT_EQ(cluster_pcm_direct_init_aux_pending_observer_validate( - CLUSTER_PCM_DIRECT_INIT_VM, &snapshot), CLUSTER_PCM_OWN_OK); - UT_ASSERT_EQ(cluster_pcm_direct_init_aux_pending_observer_validate( - CLUSTER_PCM_DIRECT_INIT_READ_MISS, &snapshot), - CLUSTER_PCM_OWN_INVALID); + CLUSTER_PCM_DIRECT_INIT_READ_MISS, &snapshot), + CLUSTER_PCM_OWN_INVALID); snapshot.reservation_token = 0; - UT_ASSERT_EQ(cluster_pcm_direct_init_aux_pending_observer_validate( - CLUSTER_PCM_DIRECT_INIT_VM, &snapshot), CLUSTER_PCM_OWN_STALE); + UT_ASSERT_EQ(cluster_pcm_direct_init_aux_pending_observer_validate(CLUSTER_PCM_DIRECT_INIT_VM, + &snapshot), + CLUSTER_PCM_OWN_STALE); snapshot.reservation_token = UINT64_MAX; - UT_ASSERT_EQ(cluster_pcm_direct_init_aux_pending_observer_validate( - CLUSTER_PCM_DIRECT_INIT_VM, &snapshot), CLUSTER_PCM_OWN_STALE); + UT_ASSERT_EQ(cluster_pcm_direct_init_aux_pending_observer_validate(CLUSTER_PCM_DIRECT_INIT_VM, + &snapshot), + CLUSTER_PCM_OWN_STALE); snapshot = make_snapshot(CLUSTER_PCM_DIRECT_INIT_FSM); snapshot.flags = PCM_OWN_FLAG_GRANT_PENDING | PCM_OWN_FLAG_REVOKING; snapshot.reservation_token = 9; - UT_ASSERT_EQ(cluster_pcm_direct_init_aux_pending_observer_validate( - CLUSTER_PCM_DIRECT_INIT_FSM, &snapshot), CLUSTER_PCM_OWN_CORRUPT); + UT_ASSERT_EQ(cluster_pcm_direct_init_aux_pending_observer_validate(CLUSTER_PCM_DIRECT_INIT_FSM, + &snapshot), + CLUSTER_PCM_OWN_CORRUPT); snapshot = make_snapshot(CLUSTER_PCM_DIRECT_INIT_FSM); snapshot.flags = PCM_OWN_FLAG_GRANT_PENDING; snapshot.reservation_token = 9; snapshot.page_is_new = false; - UT_ASSERT_EQ(cluster_pcm_direct_init_aux_pending_observer_validate( - CLUSTER_PCM_DIRECT_INIT_FSM, &snapshot), CLUSTER_PCM_OWN_STALE); + UT_ASSERT_EQ(cluster_pcm_direct_init_aux_pending_observer_validate(CLUSTER_PCM_DIRECT_INIT_FSM, + &snapshot), + CLUSTER_PCM_OWN_STALE); snapshot.page_is_new = true; snapshot.pcm_state = (uint8)PCM_STATE_X; - UT_ASSERT_EQ(cluster_pcm_direct_init_aux_pending_observer_validate( - CLUSTER_PCM_DIRECT_INIT_FSM, &snapshot), CLUSTER_PCM_OWN_STALE); + UT_ASSERT_EQ(cluster_pcm_direct_init_aux_pending_observer_validate(CLUSTER_PCM_DIRECT_INIT_FSM, + &snapshot), + CLUSTER_PCM_OWN_STALE); snapshot.pcm_state = (uint8)PCM_STATE_N; snapshot.generation = UINT64_MAX; - UT_ASSERT_EQ(cluster_pcm_direct_init_aux_pending_observer_validate( - CLUSTER_PCM_DIRECT_INIT_FSM, &snapshot), - CLUSTER_PCM_OWN_EXHAUSTED); + UT_ASSERT_EQ(cluster_pcm_direct_init_aux_pending_observer_validate(CLUSTER_PCM_DIRECT_INIT_FSM, + &snapshot), + CLUSTER_PCM_OWN_EXHAUSTED); } UT_TEST(test_revalidate_rejects_state_pin_and_reservation_changes) @@ -366,83 +373,92 @@ UT_TEST(test_vm_fsm_fork_and_valid_shape_are_exact) UT_TEST(test_target_pending_reservation_remains_bound_to_consumed_known_new_proof) { ClusterPcmDirectInitProof proof; - ClusterPcmDirectInitSnapshot base - = make_snapshot(CLUSTER_PCM_DIRECT_INIT_EXTEND); + ClusterPcmDirectInitSnapshot base = make_snapshot(CLUSTER_PCM_DIRECT_INIT_EXTEND); ClusterPcmDirectInitSnapshot pending; - UT_ASSERT_EQ(cluster_pcm_direct_init_proof_arm( - CLUSTER_PCM_DIRECT_INIT_EXTEND, &base, &proof), CLUSTER_PCM_OWN_OK); - UT_ASSERT_EQ(cluster_pcm_direct_init_proof_consume( - CLUSTER_PCM_DIRECT_INIT_EXTEND, &base, &proof), CLUSTER_PCM_OWN_OK); + UT_ASSERT_EQ(cluster_pcm_direct_init_proof_arm(CLUSTER_PCM_DIRECT_INIT_EXTEND, &base, &proof), + CLUSTER_PCM_OWN_OK); + UT_ASSERT_EQ( + cluster_pcm_direct_init_proof_consume(CLUSTER_PCM_DIRECT_INIT_EXTEND, &base, &proof), + CLUSTER_PCM_OWN_OK); pending = base; pending.flags = PCM_OWN_FLAG_GRANT_PENDING; pending.reservation_token++; - UT_ASSERT_EQ(cluster_pcm_direct_init_target_pending_validate( - CLUSTER_PCM_DIRECT_INIT_EXTEND, &pending, &proof), CLUSTER_PCM_OWN_OK); + UT_ASSERT_EQ(cluster_pcm_direct_init_target_pending_validate(CLUSTER_PCM_DIRECT_INIT_EXTEND, + &pending, &proof), + CLUSTER_PCM_OWN_OK); pending.buf_state &= ~BM_IO_IN_PROGRESS; - UT_ASSERT_EQ(cluster_pcm_direct_init_target_pending_validate( - CLUSTER_PCM_DIRECT_INIT_EXTEND, &pending, &proof), CLUSTER_PCM_OWN_STALE); + UT_ASSERT_EQ(cluster_pcm_direct_init_target_pending_validate(CLUSTER_PCM_DIRECT_INIT_EXTEND, + &pending, &proof), + CLUSTER_PCM_OWN_STALE); pending = base; pending.flags = PCM_OWN_FLAG_GRANT_PENDING; pending.reservation_token += 2; - UT_ASSERT_EQ(cluster_pcm_direct_init_target_pending_validate( - CLUSTER_PCM_DIRECT_INIT_EXTEND, &pending, &proof), CLUSTER_PCM_OWN_STALE); + UT_ASSERT_EQ(cluster_pcm_direct_init_target_pending_validate(CLUSTER_PCM_DIRECT_INIT_EXTEND, + &pending, &proof), + CLUSTER_PCM_OWN_STALE); } UT_TEST(test_target_post_t3_commit_revalidates_exact_known_new_identity) { ClusterPcmDirectInitProof proof; - ClusterPcmDirectInitSnapshot base - = make_snapshot(CLUSTER_PCM_DIRECT_INIT_READ_MISS); + ClusterPcmDirectInitSnapshot base = make_snapshot(CLUSTER_PCM_DIRECT_INIT_READ_MISS); ClusterPcmDirectInitSnapshot committed; - UT_ASSERT_EQ(cluster_pcm_direct_init_proof_arm( - CLUSTER_PCM_DIRECT_INIT_READ_MISS, &base, &proof), CLUSTER_PCM_OWN_OK); - UT_ASSERT_EQ(cluster_pcm_direct_init_proof_consume( - CLUSTER_PCM_DIRECT_INIT_READ_MISS, &base, &proof), CLUSTER_PCM_OWN_OK); + UT_ASSERT_EQ( + cluster_pcm_direct_init_proof_arm(CLUSTER_PCM_DIRECT_INIT_READ_MISS, &base, &proof), + CLUSTER_PCM_OWN_OK); + UT_ASSERT_EQ( + cluster_pcm_direct_init_proof_consume(CLUSTER_PCM_DIRECT_INIT_READ_MISS, &base, &proof), + CLUSTER_PCM_OWN_OK); committed = base; committed.generation++; committed.reservation_token++; committed.buffer_type = (uint8)BUF_TYPE_XCUR; committed.pcm_state = (uint8)PCM_STATE_X; - UT_ASSERT_EQ(cluster_pcm_direct_init_target_commit_validate( - CLUSTER_PCM_DIRECT_INIT_READ_MISS, &committed, &proof), CLUSTER_PCM_OWN_OK); + UT_ASSERT_EQ(cluster_pcm_direct_init_target_commit_validate(CLUSTER_PCM_DIRECT_INIT_READ_MISS, + &committed, &proof), + CLUSTER_PCM_OWN_OK); committed.page_is_new = false; - UT_ASSERT_EQ(cluster_pcm_direct_init_target_commit_validate( - CLUSTER_PCM_DIRECT_INIT_READ_MISS, &committed, &proof), CLUSTER_PCM_OWN_STALE); + UT_ASSERT_EQ(cluster_pcm_direct_init_target_commit_validate(CLUSTER_PCM_DIRECT_INIT_READ_MISS, + &committed, &proof), + CLUSTER_PCM_OWN_STALE); committed.page_is_new = true; committed.generation++; - UT_ASSERT_EQ(cluster_pcm_direct_init_target_commit_validate( - CLUSTER_PCM_DIRECT_INIT_READ_MISS, &committed, &proof), CLUSTER_PCM_OWN_STALE); + UT_ASSERT_EQ(cluster_pcm_direct_init_target_commit_validate(CLUSTER_PCM_DIRECT_INIT_READ_MISS, + &committed, &proof), + CLUSTER_PCM_OWN_STALE); } UT_TEST(test_target_fresh_generation_zero_is_exact_known_new_identity) { ClusterPcmDirectInitProof proof; - ClusterPcmDirectInitSnapshot base - = make_snapshot(CLUSTER_PCM_DIRECT_INIT_EXTEND); + ClusterPcmDirectInitSnapshot base = make_snapshot(CLUSTER_PCM_DIRECT_INIT_EXTEND); ClusterPcmDirectInitSnapshot pending; ClusterPcmDirectInitSnapshot committed; base.generation = 0; - UT_ASSERT_EQ(cluster_pcm_direct_init_proof_arm( - CLUSTER_PCM_DIRECT_INIT_EXTEND, &base, &proof), CLUSTER_PCM_OWN_OK); - UT_ASSERT_EQ(cluster_pcm_direct_init_proof_consume( - CLUSTER_PCM_DIRECT_INIT_EXTEND, &base, &proof), CLUSTER_PCM_OWN_OK); + UT_ASSERT_EQ(cluster_pcm_direct_init_proof_arm(CLUSTER_PCM_DIRECT_INIT_EXTEND, &base, &proof), + CLUSTER_PCM_OWN_OK); + UT_ASSERT_EQ( + cluster_pcm_direct_init_proof_consume(CLUSTER_PCM_DIRECT_INIT_EXTEND, &base, &proof), + CLUSTER_PCM_OWN_OK); pending = base; pending.flags = PCM_OWN_FLAG_GRANT_PENDING; pending.reservation_token++; - UT_ASSERT_EQ(cluster_pcm_direct_init_target_pending_validate( - CLUSTER_PCM_DIRECT_INIT_EXTEND, &pending, &proof), CLUSTER_PCM_OWN_OK); + UT_ASSERT_EQ(cluster_pcm_direct_init_target_pending_validate(CLUSTER_PCM_DIRECT_INIT_EXTEND, + &pending, &proof), + CLUSTER_PCM_OWN_OK); committed = pending; committed.generation = 1; committed.flags = 0; committed.buffer_type = (uint8)BUF_TYPE_XCUR; committed.pcm_state = (uint8)PCM_STATE_X; - UT_ASSERT_EQ(cluster_pcm_direct_init_target_commit_validate( - CLUSTER_PCM_DIRECT_INIT_EXTEND, &committed, &proof), CLUSTER_PCM_OWN_OK); + UT_ASSERT_EQ(cluster_pcm_direct_init_target_commit_validate(CLUSTER_PCM_DIRECT_INIT_EXTEND, + &committed, &proof), + CLUSTER_PCM_OWN_OK); } UT_TEST(test_bufmgr_consumes_proof_before_reservation_and_wire) @@ -462,27 +478,25 @@ UT_TEST(test_bufmgr_consumes_proof_before_reservation_and_wire) UT_TEST(test_target_direct_init_uses_exact_resource_x_round_without_legacy_fallback) { char *source = read_source(BUFMGR_SOURCE_PATH); - static const char *const target_order[] = { - "cluster_bufmgr_pcm_gate_direct_init(", - "cluster_pcm_direct_init_proof_consume", - "cluster_pcm_own_reservation_begin_exact", - "cluster_pcm_direct_init_target_pending_validate(", - "cluster_resource_x_writer_path_snapshot(", - "writer_path != RESOURCE_X_WRITER_TARGET", - "cluster_pcm_own_abort_grant_after_error(", - "cluster_gcs_resource_x_target_direct_init_acquire_exact(", - "pending_base.generation", - "pending_token", - "cluster_pcm_direct_init_target_commit_validate(", - "cluster_bufmgr_pcm_x_writer_track_target_direct_init(" - }; + static const char *const target_order[] + = { "cluster_bufmgr_pcm_gate_direct_init(", + "cluster_pcm_direct_init_proof_consume", + "cluster_pcm_own_reservation_begin_exact", + "cluster_pcm_direct_init_target_pending_validate(", + "cluster_resource_x_writer_path_snapshot(", + "writer_path != RESOURCE_X_WRITER_TARGET", + "cluster_pcm_own_abort_grant_after_error(", + "cluster_gcs_resource_x_target_direct_init_acquire_exact(", + "pending_base.generation", + "pending_token", + "cluster_pcm_direct_init_target_commit_validate(", + "cluster_bufmgr_pcm_x_writer_track_target_direct_init(" }; UT_ASSERT(source != NULL); if (source != NULL) { assert_ordered(source, target_order, lengthof(target_order)); UT_ASSERT(strstr(source, "case RESOURCE_X_WRITER_SOURCE:") == NULL); - UT_ASSERT(strstr(source, - "cluster_pcm_lock_acquire_buffer(buf, PCM_LOCK_MODE_X") == NULL); + UT_ASSERT(strstr(source, "cluster_pcm_lock_acquire_buffer(buf, PCM_LOCK_MODE_X") == NULL); free(source); } } @@ -550,52 +564,41 @@ UT_TEST(test_aux_pending_direct_init_joins_exact_round_without_second_proof) const char *gate_end; const char *aux; const char *aux_end; - static const char *const aux_order[] = { - "LockBufferForAuxiliaryPageInit(", - "cluster_bufmgr_pcm_arm_direct_init(", - "CLUSTER_BUFMGR_PCM_DIRECT_INIT_CACHED_X", - "cluster_bufmgr_pcm_join_aux_direct_init_exact(", - "continue;", - "cluster_bufmgr_pcm_gate_direct_init(" - }; + static const char *const aux_order[] = { "LockBufferForAuxiliaryPageInit(", + "cluster_bufmgr_pcm_arm_direct_init(", + "CLUSTER_BUFMGR_PCM_DIRECT_INIT_CACHED_X", + "cluster_bufmgr_pcm_join_aux_direct_init_exact(", + "continue;", + "cluster_bufmgr_pcm_gate_direct_init(" }; UT_ASSERT(source != NULL); if (source == NULL) return; assert_ordered(source, aux_order, lengthof(aux_order)); arm_helper = strstr(source, "cluster_bufmgr_pcm_arm_direct_init("); - arm_helper_end = arm_helper != NULL - ? strstr(arm_helper, "\n}\n") : NULL; + arm_helper_end = arm_helper != NULL ? strstr(arm_helper, "\n}\n") : NULL; UT_ASSERT(arm_helper != NULL && arm_helper_end != NULL); if (arm_helper != NULL && arm_helper_end != NULL) { - UT_ASSERT(strstr(arm_helper, - "cluster_pcm_direct_init_proof_arm(") < arm_helper_end); - UT_ASSERT(strstr(arm_helper, - "cluster_pcm_direct_init_aux_pending_observer_validate(") - < arm_helper_end); + UT_ASSERT(strstr(arm_helper, "cluster_pcm_direct_init_proof_arm(") < arm_helper_end); + UT_ASSERT(strstr(arm_helper, "cluster_pcm_direct_init_aux_pending_observer_validate(") + < arm_helper_end); } - join_helper = strstr(source, - "cluster_bufmgr_pcm_join_aux_direct_init_exact("); - join_helper_end = join_helper != NULL - ? strstr(join_helper, "\n}\n") : NULL; + join_helper = strstr(source, "cluster_bufmgr_pcm_join_aux_direct_init_exact("); + join_helper_end = join_helper != NULL ? strstr(join_helper, "\n}\n") : NULL; UT_ASSERT(join_helper != NULL && join_helper_end != NULL); if (join_helper != NULL && join_helper_end != NULL) { - UT_ASSERT(strstr(join_helper, - "cluster_gcs_resource_x_target_direct_init_join_exact(") - < join_helper_end); - UT_ASSERT(strstr(join_helper, - "cluster_gcs_resource_x_target_direct_init_acquire_exact(") == NULL - || strstr(join_helper, - "cluster_gcs_resource_x_target_direct_init_acquire_exact(") - > join_helper_end); - UT_ASSERT(strstr(join_helper, - "cluster_pcm_own_reservation_begin_exact(") == NULL - || strstr(join_helper, - "cluster_pcm_own_reservation_begin_exact(") > join_helper_end); - UT_ASSERT(strstr(join_helper, - "cluster_resource_x_writer_path_snapshot(") == NULL - || strstr(join_helper, - "cluster_resource_x_writer_path_snapshot(") > join_helper_end); + UT_ASSERT(strstr(join_helper, "cluster_gcs_resource_x_target_direct_init_join_exact(") + < join_helper_end); + UT_ASSERT(strstr(join_helper, "cluster_gcs_resource_x_target_direct_init_acquire_exact(") + == NULL + || strstr(join_helper, "cluster_gcs_resource_x_target_direct_init_acquire_exact(") + > join_helper_end); + UT_ASSERT(strstr(join_helper, "cluster_pcm_own_reservation_begin_exact(") == NULL + || strstr(join_helper, "cluster_pcm_own_reservation_begin_exact(") + > join_helper_end); + UT_ASSERT(strstr(join_helper, "cluster_resource_x_writer_path_snapshot(") == NULL + || strstr(join_helper, "cluster_resource_x_writer_path_snapshot(") + > join_helper_end); } aux = strstr(source, "LockBufferForAuxiliaryPageInit("); aux_end = aux != NULL ? strstr(aux, "\n}\n") : NULL; @@ -604,22 +607,19 @@ UT_TEST(test_aux_pending_direct_init_joins_exact_round_without_second_proof) gate_end = gate != NULL ? strstr(gate, "\n}\n") : NULL; UT_ASSERT(gate != NULL && gate_end != NULL); if (gate != NULL && gate_end != NULL) - UT_ASSERT(strstr(gate, - "cluster_pcm_direct_init_target_pending_validate(") - < gate_end); + UT_ASSERT(strstr(gate, "cluster_pcm_direct_init_target_pending_validate(") < gate_end); free(source); } UT_TEST(test_valid_n_s_x_without_proof_uses_target_or_s_reservation) { char *source = read_source(BUFMGR_SOURCE_PATH); - static const char *const order[] - = { "if (pcm_mode == PCM_LOCK_MODE_X)", - "cluster_bufmgr_pcm_x_writer_prepare_target(", - "else", - "cluster_bufmgr_pcm_begin_grant_reservation_wait(", - "cluster_pcm_lock_acquire_buffer(", - "buf, PCM_LOCK_MODE_S, &retry_denied" }; + static const char *const order[] = { "if (pcm_mode == PCM_LOCK_MODE_X)", + "cluster_bufmgr_pcm_x_writer_prepare_target(", + "else", + "cluster_bufmgr_pcm_begin_grant_reservation_wait(", + "cluster_pcm_lock_acquire_buffer(", + "buf, PCM_LOCK_MODE_S, &retry_denied" }; UT_ASSERT(source != NULL); if (source != NULL) { @@ -652,10 +652,9 @@ UT_TEST(test_direct_init_one_shot_image_cannot_return_without_x) UT_TEST(test_wire_throw_exact_aborts_reservation_before_rethrow) { char *source = read_source(BUFMGR_SOURCE_PATH); - static const char *const order[] - = { "cluster_gcs_resource_x_target_direct_init_acquire_exact(", "PG_CATCH();", - "cluster_pcm_own_abort_grant_after_error(", - "\"direct-init Resource-X acquire\"", "PG_RE_THROW();" }; + static const char *const order[] = { "cluster_gcs_resource_x_target_direct_init_acquire_exact(", + "PG_CATCH();", "cluster_pcm_own_abort_grant_after_error(", + "\"direct-init Resource-X acquire\"", "PG_RE_THROW();" }; UT_ASSERT(source != NULL); if (source != NULL) { @@ -690,8 +689,7 @@ UT_TEST(test_precrit_vm_barrier_refusal_unwinds_to_caller) static const char *const wrapper_signature[] = { "ClusterLockBufferExclusiveBarrierAware(Buffer buffer,", - "ClusterBufferBarrierSiteId site_id,", - "bool *pin_replaced)" }; + "ClusterBufferBarrierSiteId site_id,", "bool *pin_replaced)" }; assert_ordered(bufmgr, wrapper_signature, lengthof(wrapper_signature)); assert_ordered(bufmgr, refusal_order, lengthof(refusal_order)); @@ -705,15 +703,14 @@ UT_TEST(test_precrit_vm_barrier_refusal_unwinds_to_caller) "vmbuffer = InvalidBuffer", "cluster_heap_lock_with_vm_repin", "goto l2;" }; - static const char *const requalify_order[] - = { "PGRAC: BARRIER_CLOSED caller-owned unwind", - "if (!old_tuple_temp_locked)", - "LockBuffer(buffer, BUFFER_LOCK_UNLOCK)", - "cluster_heap_vm_barrier_warm", - "ReleaseBuffer(vmbuffer)", - "vmbuffer = InvalidBuffer", - "cluster_heap_lock_with_vm_repin", - "goto l2;" }; + static const char *const requalify_order[] = { "PGRAC: BARRIER_CLOSED caller-owned unwind", + "if (!old_tuple_temp_locked)", + "LockBuffer(buffer, BUFFER_LOCK_UNLOCK)", + "cluster_heap_vm_barrier_warm", + "ReleaseBuffer(vmbuffer)", + "vmbuffer = InvalidBuffer", + "cluster_heap_lock_with_vm_repin", + "goto l2;" }; static const char *const reacquire_order[] = { "PGRAC: vm barrier unwind (update reacquire)", "LockBuffer(newbuf, BUFFER_LOCK_UNLOCK)", @@ -839,55 +836,47 @@ UT_TEST(test_vm_fsm_resource_x_wait_releases_and_exactly_repins) const char *direct_end; const char *follower; const char *follower_end; - static const char *const handoff_order[] = { - "cluster_pcm_x_revoke_finish_mode(expected_resource, 0)", - "GetPrivateRefCount(buffer)", - "BufferTagsEqual(expected_resource, &buf->tag)", - "handoff->tag = buf->tag", - "ReleaseBuffer(buffer)", - "ReadRecentBuffer(", - "BufferTagsEqual(&handoff->tag, &buf->tag)" - }; - static const char *const ordinary_order[] = { - "cluster_bufmgr_pcm_aux_pin_handoff_begin(", - "cluster_bufmgr_pcm_x_writer_prepare_target(", - "cluster_bufmgr_pcm_aux_pin_handoff_finish_exact(", - "LWLockAcquire(" - }; - static const char *const direct_order[] = { - "aux_pin_required = kind == CLUSTER_PCM_DIRECT_INIT_VM", - "cluster_pcm_own_reservation_begin_exact(", - "if (aux_pin_required\n\t\t&& !cluster_bufmgr_pcm_aux_pin_handoff_begin(", - "cluster_gcs_resource_x_target_direct_init_acquire_exact(", - "if (aux_pin_required\n\t\t\t\t&& !cluster_bufmgr_pcm_aux_pin_handoff_finish_exact(", - "cluster_pcm_direct_init_target_commit_validate(" - }; - static const char *const follower_order[] = { - "cluster_bufmgr_pcm_aux_pin_handoff_begin(", - "cluster_gcs_resource_x_target_direct_init_join_exact(", - "cluster_bufmgr_resource_x_wait_retry(", - "cluster_bufmgr_pcm_aux_pin_handoff_finish_exact(" - }; + static const char *const handoff_order[] + = { "cluster_pcm_x_revoke_finish_mode(expected_resource, 0)", + "GetPrivateRefCount(buffer)", + "BufferTagsEqual(expected_resource, &buf->tag)", + "handoff->tag = buf->tag", + "ReleaseBuffer(buffer)", + "ReadRecentBuffer(", + "BufferTagsEqual(&handoff->tag, &buf->tag)" }; + static const char *const ordinary_order[] + = { "cluster_bufmgr_pcm_aux_pin_handoff_begin(", + "cluster_bufmgr_pcm_x_writer_prepare_target(", + "cluster_bufmgr_pcm_aux_pin_handoff_finish_exact(", "LWLockAcquire(" }; + static const char *const direct_order[] + = { "aux_pin_required = kind == CLUSTER_PCM_DIRECT_INIT_VM", + "cluster_pcm_own_reservation_begin_exact(", + "if (aux_pin_required\n\t\t&& !cluster_bufmgr_pcm_aux_pin_handoff_begin(", + "cluster_gcs_resource_x_target_direct_init_acquire_exact(", + "if (aux_pin_required\n\t\t\t\t&& !cluster_bufmgr_pcm_aux_pin_handoff_finish_exact(", + "cluster_pcm_direct_init_target_commit_validate(" }; + static const char *const follower_order[] + = { "cluster_bufmgr_pcm_aux_pin_handoff_begin(", + "cluster_gcs_resource_x_target_direct_init_join_exact(", + "cluster_bufmgr_resource_x_wait_retry(", + "cluster_bufmgr_pcm_aux_pin_handoff_finish_exact(" }; UT_ASSERT(bufmgr != NULL); if (bufmgr == NULL) return; handoff = strstr(bufmgr, "\ncluster_bufmgr_pcm_aux_pin_handoff_begin("); - handoff_end = handoff != NULL - ? strstr(handoff, - "\nstatic bool\ncluster_bufmgr_pcm_aux_pin_handoff_finish_exact(") - : NULL; + handoff_end + = handoff != NULL + ? strstr(handoff, "\nstatic bool\ncluster_bufmgr_pcm_aux_pin_handoff_finish_exact(") + : NULL; ordinary = strstr(bufmgr, "\nLockBufferInternal("); - ordinary_end = ordinary != NULL - ? strstr(ordinary, "\nvoid\nLockBuffer(") : NULL; + ordinary_end = ordinary != NULL ? strstr(ordinary, "\nvoid\nLockBuffer(") : NULL; direct = strstr(bufmgr, "\ncluster_bufmgr_pcm_gate_direct_init("); - direct_end = direct != NULL - ? strstr(direct, "\n}\n\n#endif") : NULL; - follower = strstr(bufmgr, - "\ncluster_bufmgr_pcm_join_aux_direct_init_exact("); + direct_end = direct != NULL ? strstr(direct, "\n}\n\n#endif") : NULL; + follower = strstr(bufmgr, "\ncluster_bufmgr_pcm_join_aux_direct_init_exact("); follower_end = follower != NULL - ? strstr(follower, "\ntypedef enum ClusterBufmgrPcmDirectInitArmResult") - : NULL; + ? strstr(follower, "\ntypedef enum ClusterBufmgrPcmDirectInitArmResult") + : NULL; UT_ASSERT(handoff != NULL); UT_ASSERT(handoff_end != NULL); @@ -897,15 +886,12 @@ UT_TEST(test_vm_fsm_resource_x_wait_releases_and_exactly_repins) UT_ASSERT(direct_end != NULL); UT_ASSERT(follower != NULL); UT_ASSERT(follower_end != NULL); - if (handoff != NULL && handoff_end != NULL) - { - const char *pregrant_current_image = strstr( - handoff, - "cluster_bufmgr_pcm_current_image_locked(buf, buf_state)"); + if (handoff != NULL && handoff_end != NULL) { + const char *pregrant_current_image + = strstr(handoff, "cluster_bufmgr_pcm_current_image_locked(buf, buf_state)"); assert_ordered(handoff, handoff_order, lengthof(handoff_order)); - UT_ASSERT(pregrant_current_image == NULL - || pregrant_current_image >= handoff_end); + UT_ASSERT(pregrant_current_image == NULL || pregrant_current_image >= handoff_end); } if (ordinary != NULL && ordinary_end != NULL) assert_ordered(ordinary, ordinary_order, lengthof(ordinary_order)); @@ -932,32 +918,30 @@ UT_TEST(test_aux_direct_init_pending_lifecycle_survives_pin_handoff_only) UT_ASSERT(bufmgr != NULL); if (bufmgr == NULL) return; - known_new = strstr(bufmgr, - "\ncluster_bufmgr_pcm_direct_init_known_new_locked("); - known_new_end = known_new != NULL - ? strstr(known_new, - "\nClusterPcmOwnResult\ncluster_bufmgr_pcm_own_n_direct_init_candidate_exact(") - : NULL; + known_new = strstr(bufmgr, "\ncluster_bufmgr_pcm_direct_init_known_new_locked("); + known_new_end + = known_new != NULL + ? strstr( + known_new, + "\nClusterPcmOwnResult\ncluster_bufmgr_pcm_own_n_direct_init_candidate_exact(") + : NULL; candidate = known_new_end; - candidate_end = candidate != NULL - ? strstr(candidate, - "\n/* PGRAC adaptation for the Stage-8 remote non-requester S-holder path.") - : NULL; + candidate_end + = candidate != NULL + ? strstr(candidate, + "\n/* PGRAC adaptation for the Stage-8 remote non-requester S-holder path.") + : NULL; UT_ASSERT(known_new != NULL); UT_ASSERT(known_new_end != NULL); UT_ASSERT(candidate != NULL); UT_ASSERT(candidate_end != NULL); - if (known_new != NULL && known_new_end != NULL) - { - const char *aux_guard = strstr(known_new, - "aux_pin_handoff_protected"); - const char *pending = strstr(known_new, - "PCM_OWN_FLAG_GRANT_PENDING"); - const char *writer = strstr(known_new, - "cluster_pcm_own_writer_activation_token_get"); - const char *resource_x = strstr(known_new, - "cluster_pcm_own_resource_x_activation_generation_get"); + if (known_new != NULL && known_new_end != NULL) { + const char *aux_guard = strstr(known_new, "aux_pin_handoff_protected"); + const char *pending = strstr(known_new, "PCM_OWN_FLAG_GRANT_PENDING"); + const char *writer = strstr(known_new, "cluster_pcm_own_writer_activation_token_get"); + const char *resource_x + = strstr(known_new, "cluster_pcm_own_resource_x_activation_generation_get"); const char *fork_vm = strstr(known_new, "VISIBILITYMAP_FORKNUM"); const char *fork_fsm = strstr(known_new, "FSM_FORKNUM"); @@ -968,12 +952,12 @@ UT_TEST(test_aux_direct_init_pending_lifecycle_survives_pin_handoff_only) UT_ASSERT(fork_vm != NULL && fork_vm < known_new_end); UT_ASSERT(fork_fsm != NULL && fork_fsm < known_new_end); UT_ASSERT(strstr(known_new, - "BUF_STATE_GET_REFCOUNT(buf_state) != 0\n\t\t|| aux_pin_handoff_protected") - < known_new_end); + "BUF_STATE_GET_REFCOUNT(buf_state) != 0\n\t\t|| aux_pin_handoff_protected") + < known_new_end); } if (candidate != NULL && candidate_end != NULL) - UT_ASSERT(strstr(candidate, - "cluster_bufmgr_pcm_direct_init_known_new_locked(buf, buf_state)") + UT_ASSERT( + strstr(candidate, "cluster_bufmgr_pcm_direct_init_known_new_locked(buf, buf_state)") < candidate_end); free(bufmgr); } @@ -1033,11 +1017,9 @@ UT_TEST(test_cross_page_heap_pair_second_acquire_never_waits_under_first) UT_ASSERT(pins_end != NULL); UT_ASSERT(relation != NULL); UT_ASSERT(relation_end != NULL); - if (helper != NULL && helper_end != NULL) - { + if (helper != NULL && helper_end != NULL) { assert_ordered(helper, helper_order, lengthof(helper_order)); - UT_ASSERT(strstr(helper, - "ClusterLockBufferExclusiveBarrierAware(second,") == NULL); + UT_ASSERT(strstr(helper, "ClusterLockBufferExclusiveBarrierAware(second,") == NULL); } UT_ASSERT(pins != NULL && pins_end != NULL && pins_call != NULL && pins_call < pins_end); UT_ASSERT(lower_branch != NULL && lower_call != NULL && upper_branch != NULL @@ -1058,21 +1040,26 @@ UT_TEST(test_d11_passive_identity_probe_has_exact_sites_and_phase_chain) char *bufmgr = read_source(BUFMGR_SOURCE_PATH); char *heapam = read_source(HEAPAM_SOURCE_PATH); char *hio = read_source(HIO_SOURCE_PATH); - char *probes = read_source("../../backend/utils/probes.d"); + char *probes = read_source(PROBES_SOURCE_PATH); const char *common; const char *update; - static const char *const probe_payload[] - = { "probe r2__passive__identity__receipt(", "R2SiteId", "R2Phase", - "R2SpcOid", "R2DbOid", "R2RelNumber", "R2ForkNumber", - "R2BlockNumber", "R2Outcome", "R2ProofMask" }; - static const char *const common_chain[] - = { "CLUSTER_BUFFER_BARRIER_PHASE_LOWER_REFUSED", - "CLUSTER_BUFFER_BARRIER_OUTCOME_BARRIER_CLOSED", - "CLUSTER_BUFFER_BARRIER_PROOF_LOWER_REFUSED", - "cluster_bufmgr_pcm_unwind_barrier_refusal(", - "CLUSTER_BUFFER_BARRIER_PHASE_COMMON_EMPTY", - "CLUSTER_BUFFER_BARRIER_OUTCOME_EMPTY", - "CLUSTER_BUFFER_BARRIER_PROOF_COMMON_EMPTY" }; + static const char *const probe_payload[] = { "probe r2__passive__identity__receipt(", + "R2SiteId", + "R2Phase", + "R2SpcOid", + "R2DbOid", + "R2RelNumber", + "R2ForkNumber", + "R2BlockNumber", + "R2Outcome", + "R2ProofMask" }; + static const char *const common_chain[] = { "CLUSTER_BUFFER_BARRIER_PHASE_LOWER_REFUSED", + "CLUSTER_BUFFER_BARRIER_OUTCOME_BARRIER_CLOSED", + "CLUSTER_BUFFER_BARRIER_PROOF_LOWER_REFUSED", + "cluster_bufmgr_pcm_unwind_barrier_refusal(", + "CLUSTER_BUFFER_BARRIER_PHASE_COMMON_EMPTY", + "CLUSTER_BUFFER_BARRIER_OUTCOME_EMPTY", + "CLUSTER_BUFFER_BARRIER_PROOF_COMMON_EMPTY" }; static const char *const heap_sites[] = { "CLUSTER_BUFFER_BARRIER_SITE_HEAP_DELETE_VM", "CLUSTER_BUFFER_BARRIER_SITE_HEAP_UPDATE_PRETOAST_VM", @@ -1080,40 +1067,33 @@ UT_TEST(test_d11_passive_identity_probe_has_exact_sites_and_phase_chain) "CLUSTER_BUFFER_BARRIER_SITE_HEAP_UPDATE_PAIR_OLD_SECOND", "CLUSTER_BUFFER_BARRIER_SITE_HEAP_UPDATE_OLD", "CLUSTER_BUFFER_BARRIER_SITE_HEAP_UPDATE_NEW" }; - static const char *const caller_reentry[] - = { "CLUSTER_BUFFER_BARRIER_PHASE_CALLER_POST", - "CLUSTER_BUFFER_BARRIER_OUTCOME_POSTCONDITION_OK", - "CLUSTER_BUFFER_BARRIER_PROOF_CALLER_POST", - "cluster_heap_vm_barrier_warm(", - "CLUSTER_BUFFER_BARRIER_PHASE_REENTRY", - "CLUSTER_BUFFER_BARRIER_OUTCOME_REQUALIFIED", - "CLUSTER_BUFFER_BARRIER_PROOF_REENTRY" }; + static const char *const caller_reentry[] = { "CLUSTER_BUFFER_BARRIER_PHASE_CALLER_POST", + "CLUSTER_BUFFER_BARRIER_OUTCOME_POSTCONDITION_OK", + "CLUSTER_BUFFER_BARRIER_PROOF_CALLER_POST", + "cluster_heap_vm_barrier_warm(", + "CLUSTER_BUFFER_BARRIER_PHASE_REENTRY", + "CLUSTER_BUFFER_BARRIER_OUTCOME_REQUALIFIED", + "CLUSTER_BUFFER_BARRIER_PROOF_REENTRY" }; UT_ASSERT(bufmgr != NULL); UT_ASSERT(heapam != NULL); UT_ASSERT(hio != NULL); UT_ASSERT(probes != NULL); - if (probes != NULL) - { - UT_ASSERT_EQ(count_occurrences(probes, - "probe r2__passive__identity__receipt("), 1); + if (probes != NULL) { + UT_ASSERT_EQ(count_occurrences(probes, "probe r2__passive__identity__receipt("), 1); assert_ordered(probes, probe_payload, lengthof(probe_payload)); free(probes); } - if (bufmgr != NULL) - { + if (bufmgr != NULL) { common = strstr(bufmgr, "cluster_lockbuffer_barrier_refusal:"); UT_ASSERT(common != NULL); if (common != NULL) assert_ordered(common, common_chain, lengthof(common_chain)); - UT_ASSERT_EQ(count_occurrences(bufmgr, - "TRACE_POSTGRESQL_R2_PASSIVE_IDENTITY_RECEIPT("), 1); + UT_ASSERT_EQ(count_occurrences(bufmgr, "TRACE_POSTGRESQL_R2_PASSIVE_IDENTITY_RECEIPT("), 1); free(bufmgr); } - if (heapam != NULL) - { - const char *stamp_helper = strstr(heapam, - "cluster_current_mx_stamp_lock_buffer("); + if (heapam != NULL) { + const char *stamp_helper = strstr(heapam, "cluster_current_mx_stamp_lock_buffer("); static const char *const stamp_helper_chain[] = { "cluster_current_mx_stamp_lock_buffer(", "if (context != NULL)", @@ -1128,8 +1108,7 @@ UT_TEST(test_d11_passive_identity_probe_has_exact_sites_and_phase_chain) UT_ASSERT(strstr(heapam, heap_sites[i]) != NULL); UT_ASSERT(stamp_helper != NULL); if (stamp_helper != NULL) - assert_ordered(stamp_helper, stamp_helper_chain, - lengthof(stamp_helper_chain)); + assert_ordered(stamp_helper, stamp_helper_chain, lengthof(stamp_helper_chain)); /* Legacy compatibility stays centralized in the MX helper. Primary * VM consumers use the explicit-context branch, including DELETE. */ UT_ASSERT_EQ(count_occurrences(heapam, "ClusterLockBufferExclusiveBarrierAware("), 1); @@ -1140,10 +1119,8 @@ UT_TEST(test_d11_passive_identity_probe_has_exact_sites_and_phase_chain) assert_ordered(update, caller_reentry, lengthof(caller_reentry)); free(heapam); } - if (hio != NULL) - { - UT_ASSERT_EQ(count_occurrences(hio, - "ClusterLockBufferExclusiveBarrierAware("), 0); + if (hio != NULL) { + UT_ASSERT_EQ(count_occurrences(hio, "ClusterLockBufferExclusiveBarrierAware("), 0); UT_ASSERT(strstr(hio, "ConditionalLockBuffer(second)") != NULL); free(hio); } @@ -1173,21 +1150,18 @@ UT_TEST(test_aux_repin_replacement_restarts_from_fresh_relation_ref) UT_ASSERT(bufmgr != NULL); UT_ASSERT(vm != NULL); UT_ASSERT(fsm != NULL); - if (bufmgr != NULL) - { - join_decl = strstr(bufmgr, - "static bool\ncluster_bufmgr_pcm_join_aux_direct_init_exact("); - join = join_decl == NULL ? NULL : strstr(join_decl, - "\ncluster_bufmgr_pcm_join_aux_direct_init_exact("); - join_end = join == NULL ? NULL - : strstr(join, - "\ntypedef enum ClusterBufmgrPcmDirectInitArmResult"); + if (bufmgr != NULL) { + join_decl = strstr(bufmgr, "static bool\ncluster_bufmgr_pcm_join_aux_direct_init_exact("); + join = join_decl == NULL + ? NULL + : strstr(join_decl, "\ncluster_bufmgr_pcm_join_aux_direct_init_exact("); + join_end = join == NULL + ? NULL + : strstr(join, "\ntypedef enum ClusterBufmgrPcmDirectInitArmResult"); gate = strstr(bufmgr, "\ncluster_bufmgr_pcm_gate_direct_init("); gate_end = gate == NULL ? NULL : strstr(gate, "\n}\n\n#endif"); aux = strstr(bufmgr, "\nLockBufferForAuxiliaryPageInit("); - aux_end = aux == NULL ? NULL - : strstr(aux, - "\nBuffer\nLockBufferForVisibilityMapPageInit("); + aux_end = aux == NULL ? NULL : strstr(aux, "\nBuffer\nLockBufferForVisibilityMapPageInit("); UT_ASSERT(join != NULL); UT_ASSERT(join_end != NULL); @@ -1195,49 +1169,38 @@ UT_TEST(test_aux_repin_replacement_restarts_from_fresh_relation_ref) UT_ASSERT(gate_end != NULL); UT_ASSERT(aux != NULL); UT_ASSERT(aux_end != NULL); - if (join != NULL && join_end != NULL) - { + if (join != NULL && join_end != NULL) { UT_ASSERT(strstr(join, "pin_handoff.active = false;") < join_end); - UT_ASSERT(strstr(join, - "cluster_bufmgr_resource_x_fail_closed_current()") == NULL - || strstr(join, - "cluster_bufmgr_resource_x_fail_closed_current()") >= join_end); + UT_ASSERT(strstr(join, "cluster_bufmgr_resource_x_fail_closed_current()") == NULL + || strstr(join, "cluster_bufmgr_resource_x_fail_closed_current()") + >= join_end); } - if (gate != NULL && gate_end != NULL) - { + if (gate != NULL && gate_end != NULL) { UT_ASSERT(strstr(gate, "bool *pin_replaced") < gate_end); - repin = strstr(gate, - "cluster_bufmgr_pcm_aux_pin_handoff_finish_exact("); - post_t3 = strstr(gate, - "The terminal round has already completed T2/T3"); + repin = strstr(gate, "cluster_bufmgr_pcm_aux_pin_handoff_finish_exact("); + post_t3 = strstr(gate, "The terminal round has already completed T2/T3"); UT_ASSERT(repin != NULL); UT_ASSERT(post_t3 != NULL); - if (repin != NULL && post_t3 != NULL) - { + if (repin != NULL && post_t3 != NULL) { UT_ASSERT(repin < post_t3); UT_ASSERT(strstr(repin, "*pin_replaced = true;") < post_t3); UT_ASSERT(strstr(repin, "return false;") < post_t3); UT_ASSERT(strstr(repin, "if (pin_replaced == NULL)") < post_t3); - UT_ASSERT(strstr(repin, - "cluster_bufmgr_resource_x_fail_closed_current()") < post_t3); + UT_ASSERT(strstr(repin, "cluster_bufmgr_resource_x_fail_closed_current()") + < post_t3); } } - if (aux != NULL && aux_end != NULL) - { + if (aux != NULL && aux_end != NULL) { UT_ASSERT(strstr(aux, "static Buffer") < aux); UT_ASSERT(strstr(aux, "bool pin_replaced = false;") < aux_end); UT_ASSERT(strstr(aux, "return InvalidBuffer;") < aux_end); } free(bufmgr); } - if (vm != NULL) - { - const char *lock = strstr(vm, - "buf = LockBufferForVisibilityMapPageInit(buf);"); - const char *invalid = lock == NULL ? NULL - : strstr(lock, "if (!BufferIsValid(buf))"); - const char *retry = invalid == NULL ? NULL - : strstr(invalid, "continue;"); + if (vm != NULL) { + const char *lock = strstr(vm, "buf = LockBufferForVisibilityMapPageInit(buf);"); + const char *invalid = lock == NULL ? NULL : strstr(lock, "if (!BufferIsValid(buf))"); + const char *retry = invalid == NULL ? NULL : strstr(invalid, "continue;"); UT_ASSERT(lock != NULL); UT_ASSERT(invalid != NULL); @@ -1246,14 +1209,10 @@ UT_TEST(test_aux_repin_replacement_restarts_from_fresh_relation_ref) UT_ASSERT(lock < invalid && invalid < retry); free(vm); } - if (fsm != NULL) - { - const char *lock = strstr(fsm, - "buf = LockBufferForFreeSpaceMapPageInit(buf);"); - const char *invalid = lock == NULL ? NULL - : strstr(lock, "if (!BufferIsValid(buf))"); - const char *retry = invalid == NULL ? NULL - : strstr(invalid, "continue;"); + if (fsm != NULL) { + const char *lock = strstr(fsm, "buf = LockBufferForFreeSpaceMapPageInit(buf);"); + const char *invalid = lock == NULL ? NULL : strstr(lock, "if (!BufferIsValid(buf))"); + const char *retry = invalid == NULL ? NULL : strstr(invalid, "continue;"); UT_ASSERT(lock != NULL); UT_ASSERT(invalid != NULL); @@ -1282,52 +1241,42 @@ UT_TEST(test_ordinary_aux_repin_replacement_reaches_heap_retry) UT_ASSERT(bufmgr != NULL); UT_ASSERT(heapam != NULL); - if (bufmgr != NULL) - { - wrapper = strstr(bufmgr, - "ClusterLockBufferExclusiveBarrierAware(Buffer buffer,"); - wrapper_end = wrapper == NULL ? NULL - : strstr(wrapper, "\n}\n\n/*\n * Resource-X aware EXCLUSIVE lock"); + if (bufmgr != NULL) { + wrapper = strstr(bufmgr, "ClusterLockBufferExclusiveBarrierAware(Buffer buffer,"); + wrapper_end = wrapper == NULL + ? NULL + : strstr(wrapper, "\n}\n\n/*\n * Resource-X aware EXCLUSIVE lock"); refusal = strstr(bufmgr, "cluster_lockbuffer_barrier_refusal:"); UT_ASSERT(wrapper != NULL); UT_ASSERT(wrapper_end != NULL); UT_ASSERT(refusal != NULL); - if (wrapper != NULL && wrapper_end != NULL) - { + if (wrapper != NULL && wrapper_end != NULL) { UT_ASSERT(strstr(wrapper, "bool *pin_replaced") < wrapper_end); UT_ASSERT(strstr(wrapper, "&transient_refused") < wrapper_end); UT_ASSERT(strstr(wrapper, "*pin_replaced = replaced") < wrapper_end); UT_ASSERT(strstr(wrapper, "&& !replaced") < wrapper_end); } - if (refusal != NULL) - { - const char *common_empty = strstr(refusal, - "CLUSTER_BUFFER_BARRIER_PHASE_COMMON_EMPTY"); + if (refusal != NULL) { + const char *common_empty = strstr(refusal, "CLUSTER_BUFFER_BARRIER_PHASE_COMMON_EMPTY"); UT_ASSERT(common_empty != NULL); - if (common_empty != NULL) - { - UT_ASSERT(strstr(refusal, "if (pcm_pin_replaced != NULL)") - < common_empty); - UT_ASSERT(strstr(refusal, "*pcm_pin_replaced = true;") - < common_empty); + if (common_empty != NULL) { + UT_ASSERT(strstr(refusal, "if (pcm_pin_replaced != NULL)") < common_empty); + UT_ASSERT(strstr(refusal, "*pcm_pin_replaced = true;") < common_empty); } } free(bufmgr); } - if (heapam != NULL) - { + if (heapam != NULL) { helper = strstr(heapam, "cluster_current_mx_stamp_lock_buffer("); helper_end = helper == NULL ? NULL : strstr(helper, "\n}\n"); UT_ASSERT(helper != NULL); UT_ASSERT(helper_end != NULL); - if (helper != NULL && helper_end != NULL) - { + if (helper != NULL && helper_end != NULL) { UT_ASSERT(strstr(helper, "bool *pin_replaced") < helper_end); - UT_ASSERT(strstr(helper, - "ClusterLockBufferExclusiveBarrierAware(buffer, site,") - < helper_end); + UT_ASSERT(strstr(helper, "ClusterLockBufferExclusiveBarrierAware(buffer, site,") + < helper_end); } UT_ASSERT(strstr(heapam, "refused_pin_replaced = false;") != NULL); UT_ASSERT(strstr(heapam, "if (refused_pin_replaced)") != NULL); diff --git a/src/test/cluster_unit/test_cluster_pcm_lock.c b/src/test/cluster_unit/test_cluster_pcm_lock.c index ff4645b9a2c..f3fe0238f6a 100644 --- a/src/test/cluster_unit/test_cluster_pcm_lock.c +++ b/src/test/cluster_unit/test_cluster_pcm_lock.c @@ -46,7 +46,7 @@ #include "cluster/cluster_buffer_desc.h" /* PcmState (1.6) */ #include "cluster/cluster_clean_leave.h" -#include "cluster/cluster_cssd.h" /* spec-4.7a D4 — ClusterCssdPeerState for stub */ +#include "cluster/cluster_cssd.h" /* spec-4.7a D4 — ClusterCssdPeerState for stub */ #include "cluster/cluster_inject.h" #include "cluster/cluster_gcs.h" #include "cluster/cluster_gcs_block.h" /* spec-4.7 D1 — ClusterGcsBlockPhase + phase_for_tag proto */ @@ -64,25 +64,19 @@ #include "storage/spin.h" #include "utils/hsearch.h" +extern ResourceXApplyResult cluster_pcm_lock_resource_x_holder_pair_drain_prepare_exact( + const ResourceXAssertion *assertion, uint64 assertion_sequence, int32 authenticated_master_node, + uint64 authenticated_master_session, uint64 *source_generation_out); +extern ResourceXApplyResult cluster_pcm_lock_resource_x_holder_pair_drain_commit_exact( + const ResourceXAssertion *assertion, uint64 assertion_sequence, int32 authenticated_master_node, + uint64 authenticated_master_session, uint64 source_generation); extern ResourceXApplyResult -cluster_pcm_lock_resource_x_holder_pair_drain_prepare_exact( - const ResourceXAssertion *assertion, uint64 assertion_sequence, - int32 authenticated_master_node, uint64 authenticated_master_session, - uint64 *source_generation_out); -extern ResourceXApplyResult -cluster_pcm_lock_resource_x_holder_pair_drain_commit_exact( - const ResourceXAssertion *assertion, uint64 assertion_sequence, - int32 authenticated_master_node, uint64 authenticated_master_session, - uint64 source_generation); -extern ResourceXApplyResult -cluster_pcm_lock_resource_x_settled_retire_exact( - const ResourceXAssertion *assertion, uint64 assertion_sequence, - const ResourceXMasterSnapshot *settled); -extern ResourceXApplyResult -cluster_pcm_lock_resource_x_block_to_n_prepared_s_source_exact( +cluster_pcm_lock_resource_x_settled_retire_exact(const ResourceXAssertion *assertion, + uint64 assertion_sequence, + const ResourceXMasterSnapshot *settled); +extern ResourceXApplyResult cluster_pcm_lock_resource_x_block_to_n_prepared_s_source_exact( const ResourceXDecodedFrame *block, int32 authenticated_master_node, - const ResourceXDecodedFrame *blocked_status, - const ResourceXDecodedFrame *image_envelope, + const ResourceXDecodedFrame *blocked_status, const ResourceXDecodedFrame *image_envelope, const ClusterPcmOwnSnapshot *prepared_source, XLogRecPtr prepared_page_lsn, uint64 prepared_page_scn, uint32 prepared_page_checksum); #include "utils/timestamp.h" @@ -248,8 +242,7 @@ static int fake_local_x_transfer_holder = -1; static PcmAuthoritySnapshot fake_local_x_transfer_expected; static bool fake_pcm_x_local_s_barrier_active = false; static int fake_pcm_x_local_s_barrier_checks = 0; -static ResourceXSidecarNeutralizeResult fake_neutralize_result - = RESOURCE_X_SIDECAR_NEUTRALIZED; +static ResourceXSidecarNeutralizeResult fake_neutralize_result = RESOURCE_X_SIDECAR_NEUTRALIZED; static int fake_neutralize_count = 0; static bool fake_neutralize_without_pcm_lock = false; static BufferTag fake_neutralize_tag; @@ -262,16 +255,14 @@ static uint32 fake_resource_x_transport_snapshot_call_count = 0; static uint32 fake_resource_x_transport_advance_on_call = 0; bool -cluster_lms_outbound_resource_x_transport_snapshot( - ClusterLmsResourceXTransportSnapshot *out) +cluster_lms_outbound_resource_x_transport_snapshot(ClusterLmsResourceXTransportSnapshot *out) { if (out != NULL) memset(out, 0, sizeof(*out)); if (!fake_resource_x_transport_snapshot_available || out == NULL) return false; fake_resource_x_transport_snapshot_call_count++; - if (fake_resource_x_transport_snapshot_call_count - == fake_resource_x_transport_advance_on_call) + if (fake_resource_x_transport_snapshot_call_count == fake_resource_x_transport_advance_on_call) fake_resource_x_transport_mutation_sequence++; out->mutation_sequence = fake_resource_x_transport_mutation_sequence; out->staged_count = fake_resource_x_transport_staged_count; @@ -526,8 +517,7 @@ cluster_grd_inc_block_path_failclosed(void) {} void * -ShmemInitStruct(const char *name pg_attribute_unused(), Size size, - bool *foundPtr) +ShmemInitStruct(const char *name pg_attribute_unused(), Size size, bool *foundPtr) { Assert(size <= sizeof(fake_pcm_header.data)); fake_pcm_header_requested_size = size; @@ -858,9 +848,7 @@ cluster_gcs_lookup_master(BufferTag tag pg_attribute_unused()) } void -cluster_gcs_send_transition_and_wait(BufferTag tag, - PcmLockTransition trans, - int master_node) +cluster_gcs_send_transition_and_wait(BufferTag tag, PcmLockTransition trans, int master_node) { if (!fake_gcs_transition_allowed) abort(); @@ -871,29 +859,24 @@ cluster_gcs_send_transition_and_wait(BufferTag tag, if (fake_gcs_transition_apply_to_pcm) fake_gcs_transition_applied = cluster_pcm_lock_apply_gcs_transition(tag, trans, cluster_node_id); - if (fake_gcs_transition_rebind) - { + if (fake_gcs_transition_rebind) { PcmEntryAcquireResult acquire_result; PcmEntryRef ref; uint64 old_generation; - UT_ASSERT(pcm_entry_ref_acquire( - &tag, false, &ref, &acquire_result)); + UT_ASSERT(pcm_entry_ref_acquire(&tag, false, &ref, &acquire_result)); old_generation = ref.binding_generation; pcm_entry_ref_release(&ref); - UT_ASSERT(pcm_entry_try_retire_exact( - &tag, old_generation, PCM_RETIRE_REASON_HOLDER_RELEASE)); - UT_ASSERT(pcm_entry_ref_acquire( - &tag, true, &ref, &acquire_result)); + UT_ASSERT( + pcm_entry_try_retire_exact(&tag, old_generation, PCM_RETIRE_REASON_HOLDER_RELEASE)); + UT_ASSERT(pcm_entry_ref_acquire(&tag, true, &ref, &acquire_result)); fake_gcs_transition_rebound_generation = ref.binding_generation; pcm_entry_ref_release(&ref); } } bool -cluster_gcs_try_send_transition_and_wait(BufferTag tag, - PcmLockTransition trans, - int master_node) +cluster_gcs_try_send_transition_and_wait(BufferTag tag, PcmLockTransition trans, int master_node) { if (!fake_gcs_transition_allowed) return false; @@ -1053,14 +1036,15 @@ BackendId MyBackendId = 1; * Tests * ============================================================ */ -static void make_resource_x_remote_join_pair( - BufferTag tag, int32 requester_node, ResourceXDecodedFrame *grant, - ResourceXDecodedFrame *image); -static void retarget_resource_x_remote_join_pair( - ResourceXDecodedFrame *grant, ResourceXDecodedFrame *image, - uint64 final_authority_generation, uint64 requester_target_generation); -static ResourceXDecodedFrame make_resource_x_remote_blocked_frame( - BufferTag tag, int32 requester_node, int32 source_node); +static void make_resource_x_remote_join_pair(BufferTag tag, int32 requester_node, + ResourceXDecodedFrame *grant, + ResourceXDecodedFrame *image); +static void retarget_resource_x_remote_join_pair(ResourceXDecodedFrame *grant, + ResourceXDecodedFrame *image, + uint64 final_authority_generation, + uint64 requester_target_generation); +static ResourceXDecodedFrame +make_resource_x_remote_blocked_frame(BufferTag tag, int32 requester_node, int32 source_node); static void canonicalize_resource_x_test_image(ResourceXDecodedFrame *image); UT_TEST(test_pcm_lock_mode_constant_aliases_match_pcm_state) @@ -1374,25 +1358,18 @@ UT_TEST(test_pcm_grd_entry_abi_includes_resource_x_executor_state) { reset_fake_pcm_runtime(4); UT_ASSERT_EQ(fake_pcm_entrysize, 1128); - UT_ASSERT_EQ(cluster_pcm_grd_shmem_size(), - add_size(fake_pcm_header_requested_size, - hash_estimate_size(4, fake_pcm_entrysize))); + UT_ASSERT_EQ(cluster_pcm_grd_shmem_size(), add_size(fake_pcm_header_requested_size, + hash_estimate_size(4, fake_pcm_entrysize))); } UT_TEST(test_pcm_d2_entry_ref_is_pinned_and_binding_generation_exact) { - static const char *const ref_contract[] = { - "pg_atomic_uint32 lifecycle", - "pg_atomic_uint32 pin_count", - "pg_atomic_uint32 wait_refcount", - "pg_atomic_uint32 transport_refcount", - "uint64 binding_generation", - "uint32 registry_slot", - "next_binding_generation", - "pcm_entry_binding_generation_next(", - "pcm_entry_ref_acquire(", - "pcm_entry_ref_release(" - }; + static const char *const ref_contract[] + = { "pg_atomic_uint32 lifecycle", "pg_atomic_uint32 pin_count", + "pg_atomic_uint32 wait_refcount", "pg_atomic_uint32 transport_refcount", + "uint64 binding_generation", "uint32 registry_slot", + "next_binding_generation", "pcm_entry_binding_generation_next(", + "pcm_entry_ref_acquire(", "pcm_entry_ref_release(" }; BufferTag tag = make_tag(158); BufferTag other = make_tag(159); PcmEntryAcquireResult acquire_result = PCM_ENTRY_ACQUIRE_CORRUPT; @@ -1413,13 +1390,11 @@ UT_TEST(test_pcm_d2_entry_ref_is_pinned_and_binding_generation_exact) memset(&other_ref, 0xa5, sizeof(other_ref)); memset(&empty, 0, sizeof(empty)); - UT_ASSERT(!pcm_entry_ref_acquire( - &tag, false, &missing, &acquire_result)); + UT_ASSERT(!pcm_entry_ref_acquire(&tag, false, &missing, &acquire_result)); UT_ASSERT_EQ(acquire_result, PCM_ENTRY_ACQUIRE_NOT_FOUND); UT_ASSERT_EQ(memcmp(&missing, &empty, sizeof(empty)), 0); - UT_ASSERT(pcm_entry_ref_acquire( - &tag, true, &first, &acquire_result)); + UT_ASSERT(pcm_entry_ref_acquire(&tag, true, &first, &acquire_result)); UT_ASSERT_EQ(acquire_result, PCM_ENTRY_ACQUIRE_OK); UT_ASSERT_NOT_NULL(first.entry); UT_ASSERT(first.pinned); @@ -1429,8 +1404,7 @@ UT_TEST(test_pcm_d2_entry_ref_is_pinned_and_binding_generation_exact) UT_ASSERT(BufferTagsEqual(&first.tag, &tag)); first_generation = first.binding_generation; - UT_ASSERT(pcm_entry_ref_acquire( - &tag, false, &second, &acquire_result)); + UT_ASSERT(pcm_entry_ref_acquire(&tag, false, &second, &acquire_result)); UT_ASSERT_EQ(acquire_result, PCM_ENTRY_ACQUIRE_OK); UT_ASSERT_EQ(second.entry, first.entry); UT_ASSERT_EQ(second.binding_generation, first.binding_generation); @@ -1443,16 +1417,14 @@ UT_TEST(test_pcm_d2_entry_ref_is_pinned_and_binding_generation_exact) pcm_entry_ref_release(&second); UT_ASSERT_EQ(memcmp(&second, &empty, sizeof(empty)), 0); - UT_ASSERT(pcm_entry_ref_acquire( - &other, true, &other_ref, &acquire_result)); + UT_ASSERT(pcm_entry_ref_acquire(&other, true, &other_ref, &acquire_result)); UT_ASSERT_EQ(acquire_result, PCM_ENTRY_ACQUIRE_OK); UT_ASSERT(other_ref.binding_generation > first_generation); pcm_entry_ref_release(&other_ref); source = read_text_file(PCM_LOCK_SOURCE_PATH); cursor = source; - for (i = 0; i < lengthof(ref_contract); i++) - { + for (i = 0; i < lengthof(ref_contract); i++) { cursor = strstr(cursor, ref_contract[i]); UT_ASSERT_NOT_NULL(cursor); cursor += strlen(ref_contract[i]); @@ -1480,36 +1452,29 @@ UT_TEST(test_pcm_d2_cv_wait_holds_pin_and_exact_wait_reference) pinned_path = strstr(source, "\npcm_lock_acquire_local_pinned("); UT_ASSERT_NOT_NULL(pinned_path); wait_begin = pinned_path != NULL - ? strstr(pinned_path, "pcm_entry_wait_ref_begin(wait_context);") - : NULL; + ? strstr(pinned_path, "pcm_entry_wait_ref_begin(wait_context);") + : NULL; UT_ASSERT_NOT_NULL(wait_begin); prepare = wait_begin != NULL - ? strstr(wait_begin, "ConditionVariablePrepareToSleep(&entry->wait_cv);") - : NULL; + ? strstr(wait_begin, "ConditionVariablePrepareToSleep(&entry->wait_cv);") + : NULL; UT_ASSERT_NOT_NULL(prepare); - sleep = prepare != NULL - ? strstr(prepare, "ConditionVariableSleep(&entry->wait_cv,") - : NULL; + sleep = prepare != NULL ? strstr(prepare, "ConditionVariableSleep(&entry->wait_cv,") : NULL; UT_ASSERT_NOT_NULL(sleep); - revalidate = sleep != NULL - ? strstr(sleep, "pcm_entry_ref_identity_exact(&wait_context->ref)") - : NULL; + revalidate + = sleep != NULL ? strstr(sleep, "pcm_entry_ref_identity_exact(&wait_context->ref)") : NULL; UT_ASSERT_NOT_NULL(revalidate); - wrapper = revalidate != NULL - ? strstr(revalidate, "\npcm_lock_acquire_local(") - : NULL; + wrapper = revalidate != NULL ? strstr(revalidate, "\npcm_lock_acquire_local(") : NULL; UT_ASSERT_NOT_NULL(wrapper); UT_ASSERT_NOT_NULL(wrapper != NULL - ? strstr(wrapper, - "pcm_entry_ref_acquire(&tag, true, &wait_context.ref,") - : NULL); + ? strstr(wrapper, "pcm_entry_ref_acquire(&tag, true, &wait_context.ref,") + : NULL); finally_cleanup = wrapper != NULL - ? strstr(wrapper, "pcm_entry_wait_context_cleanup(&wait_context);") - : NULL; + ? strstr(wrapper, "pcm_entry_wait_context_cleanup(&wait_context);") + : NULL; UT_ASSERT_NOT_NULL(finally_cleanup); - UT_ASSERT(finally_cleanup != NULL && wrapper != NULL - && finally_cleanup > wrapper); + UT_ASSERT(finally_cleanup != NULL && wrapper != NULL && finally_cleanup > wrapper); free(source); } @@ -1518,36 +1483,32 @@ UT_TEST(test_pcm_d2_master_state_uses_exact_pinned_registry_slot) char *source = read_text_file(PCM_LOCK_SOURCE_PATH); UT_ASSERT_NOT_NULL(source); - UT_ASSERT_NULL(strstr(source, - "pcm_resource_x_master_state_for_tag(const BufferTag *tag)")); - UT_ASSERT_NOT_NULL(strstr(source, - "pcm_resource_x_master_state_for_entry(const struct GrdEntry *entry)")); - UT_ASSERT_NULL(strstr(source, - "pcm_resource_x_master_state_for_tag(&entry->tag)")); + UT_ASSERT_NULL(strstr(source, "pcm_resource_x_master_state_for_tag(const BufferTag *tag)")); + UT_ASSERT_NOT_NULL( + strstr(source, "pcm_resource_x_master_state_for_entry(const struct GrdEntry *entry)")); + UT_ASSERT_NULL(strstr(source, "pcm_resource_x_master_state_for_tag(&entry->tag)")); free(source); } UT_TEST(test_pcm_d3_retire_eligibility_is_one_exact_closed_table) { - static const char *const refusal_contract[] = { - "PCM_RETIRE_REFUSAL_GATE_NOT_OPEN", - "PCM_RETIRE_REFUSAL_IDENTITY_MISMATCH", - "PCM_RETIRE_REFUSAL_LIFECYCLE_NOT_LIVE", - "PCM_RETIRE_REFUSAL_PINNED", - "PCM_RETIRE_REFUSAL_WAITER_PRESENT", - "PCM_RETIRE_REFUSAL_TRANSPORT_PRESENT", - "PCM_RETIRE_REFUSAL_PCM_MODE_NOT_N", - "PCM_RETIRE_REFUSAL_HOLDER_PRESENT", - "PCM_RETIRE_REFUSAL_PI_PRESENT", - "PCM_RETIRE_REFUSAL_WATERMARK_PRESENT", - "PCM_RETIRE_REFUSAL_CONVERT_PENDING", - "PCM_RETIRE_REFUSAL_RESOURCE_X_ACTIVE", - "PCM_RETIRE_REFUSAL_RETAINED_PAIR_PRESENT", - "PCM_RETIRE_REFUSAL_REQUESTER_NOT_TERMINAL", - "PCM_RETIRE_REFUSAL_SIDECAR_NOT_TERMINAL", - "PCM_RETIRE_REFUSAL_FORMATION_STALE", - "PCM_RETIRE_REFUSAL_ENTRY_LOCK_BUSY" - }; + static const char *const refusal_contract[] = { "PCM_RETIRE_REFUSAL_GATE_NOT_OPEN", + "PCM_RETIRE_REFUSAL_IDENTITY_MISMATCH", + "PCM_RETIRE_REFUSAL_LIFECYCLE_NOT_LIVE", + "PCM_RETIRE_REFUSAL_PINNED", + "PCM_RETIRE_REFUSAL_WAITER_PRESENT", + "PCM_RETIRE_REFUSAL_TRANSPORT_PRESENT", + "PCM_RETIRE_REFUSAL_PCM_MODE_NOT_N", + "PCM_RETIRE_REFUSAL_HOLDER_PRESENT", + "PCM_RETIRE_REFUSAL_PI_PRESENT", + "PCM_RETIRE_REFUSAL_WATERMARK_PRESENT", + "PCM_RETIRE_REFUSAL_CONVERT_PENDING", + "PCM_RETIRE_REFUSAL_RESOURCE_X_ACTIVE", + "PCM_RETIRE_REFUSAL_RETAINED_PAIR_PRESENT", + "PCM_RETIRE_REFUSAL_REQUESTER_NOT_TERMINAL", + "PCM_RETIRE_REFUSAL_SIDECAR_NOT_TERMINAL", + "PCM_RETIRE_REFUSAL_FORMATION_STALE", + "PCM_RETIRE_REFUSAL_ENTRY_LOCK_BUSY" }; BufferTag tag = make_tag(160); BufferTag pi_tag = make_tag(161); BufferTag requester_tag = make_tag(163); @@ -1588,61 +1549,55 @@ UT_TEST(test_pcm_d3_retire_eligibility_is_one_exact_closed_table) UT_ASSERT(!pcm_entry_retire_classify_exact(&tag, generation + 1, &why)); UT_ASSERT_EQ(why, PCM_RETIRE_REFUSAL_IDENTITY_MISMATCH); - UT_ASSERT_EQ(cluster_pcm_lock_apply_gcs_transition_result( - tag, PCM_TRANS_N_TO_S, 0), PCM_GCS_TRANSITION_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_apply_gcs_transition_result(tag, PCM_TRANS_N_TO_S, 0), + PCM_GCS_TRANSITION_APPLIED); UT_ASSERT(!pcm_entry_retire_classify_exact(&tag, generation, &why)); UT_ASSERT_EQ(why, PCM_RETIRE_REFUSAL_PCM_MODE_NOT_N); - UT_ASSERT_EQ(cluster_pcm_lock_apply_gcs_transition_result( - tag, PCM_TRANS_S_TO_N_RELEASE, 0), PCM_GCS_TRANSITION_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_apply_gcs_transition_result(tag, PCM_TRANS_S_TO_N_RELEASE, 0), + PCM_GCS_TRANSITION_APPLIED); UT_ASSERT(cluster_pcm_lock_set_pending_x(tag, 0, 41)); UT_ASSERT(!pcm_entry_retire_classify_exact(&tag, generation, &why)); UT_ASSERT_EQ(why, PCM_RETIRE_REFUSAL_CONVERT_PENDING); cluster_pcm_lock_clear_pending_x_if(tag, 0); UT_ASSERT(pcm_entry_retire_classify_exact(&tag, generation, &why)); - UT_ASSERT(pcm_entry_ref_acquire( - &watermark_tag, true, &ref, &acquire_result)); + UT_ASSERT(pcm_entry_ref_acquire(&watermark_tag, true, &ref, &acquire_result)); watermark_generation = ref.binding_generation; pcm_entry_ref_release(&ref); cluster_pcm_lock_pi_watermark_scn_advance(watermark_tag, (SCN)0x2200, - CLUSTER_PCM_WM_SRC_REDECLARE, 0, 31, 17); - UT_ASSERT(!pcm_entry_retire_classify_exact( - &watermark_tag, watermark_generation, &why)); + CLUSTER_PCM_WM_SRC_REDECLARE, 0, 31, 17); + UT_ASSERT(!pcm_entry_retire_classify_exact(&watermark_tag, watermark_generation, &why)); UT_ASSERT_EQ(why, PCM_RETIRE_REFUSAL_WATERMARK_PRESENT); UT_ASSERT(pcm_entry_ref_acquire(&pi_tag, true, &ref, &acquire_result)); pi_generation = ref.binding_generation; pcm_entry_ref_release(&ref); - UT_ASSERT_EQ(cluster_pcm_lock_apply_gcs_transition_result( - pi_tag, PCM_TRANS_N_TO_X, 0), PCM_GCS_TRANSITION_APPLIED); - UT_ASSERT_EQ(cluster_pcm_lock_apply_gcs_transition_result( - pi_tag, PCM_TRANS_X_TO_N_DOWNGRADE, 0), PCM_GCS_TRANSITION_APPLIED); - UT_ASSERT(!pcm_entry_retire_classify_exact( - &pi_tag, pi_generation, &why)); + UT_ASSERT_EQ(cluster_pcm_lock_apply_gcs_transition_result(pi_tag, PCM_TRANS_N_TO_X, 0), + PCM_GCS_TRANSITION_APPLIED); + UT_ASSERT_EQ( + cluster_pcm_lock_apply_gcs_transition_result(pi_tag, PCM_TRANS_X_TO_N_DOWNGRADE, 0), + PCM_GCS_TRANSITION_APPLIED); + UT_ASSERT(!pcm_entry_retire_classify_exact(&pi_tag, pi_generation, &why)); UT_ASSERT_EQ(why, PCM_RETIRE_REFUSAL_PI_PRESENT); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), - RESOURCE_X_APPLY_APPLIED); + RESOURCE_X_APPLY_APPLIED); memset(&requester_ref, 0, sizeof(requester_ref)); - UT_ASSERT(resource_x_assertion_init( - &requester_tag, 2, &requester_ref.assertion)); + UT_ASSERT(resource_x_assertion_init(&requester_tag, 2, &requester_ref.assertion)); requester_ref.formation = 17; requester_ref.acquisition_generation = 41; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_t1_grant_exact(&requester_ref), - RESOURCE_X_APPLY_APPLIED); - UT_ASSERT(pcm_entry_ref_acquire( - &requester_tag, false, &ref, &acquire_result)); + RESOURCE_X_APPLY_APPLIED); + UT_ASSERT(pcm_entry_ref_acquire(&requester_tag, false, &ref, &acquire_result)); requester_generation = ref.binding_generation; pcm_entry_ref_release(&ref); memset(&install, 0, sizeof(install)); install.ownership_generation = 9; install.writer_activation_token = 12; - install.resource_x_activation_generation - = requester_ref.acquisition_generation; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_apply_exact( - &requester_ref, &install), RESOURCE_X_APPLY_APPLIED); - UT_ASSERT(!pcm_entry_retire_classify_exact( - &requester_tag, requester_generation, &why)); + install.resource_x_activation_generation = requester_ref.acquisition_generation; + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_apply_exact(&requester_ref, &install), + RESOURCE_X_APPLY_APPLIED); + UT_ASSERT(!pcm_entry_retire_classify_exact(&requester_tag, requester_generation, &why)); UT_ASSERT_EQ(why, PCM_RETIRE_REFUSAL_REQUESTER_NOT_TERMINAL); UT_ASSERT(cluster_resource_x_reconfig_freeze(17, 18, &token)); UT_ASSERT(!pcm_entry_retire_classify_exact(&tag, generation, &why)); @@ -1651,8 +1606,7 @@ UT_TEST(test_pcm_d3_retire_eligibility_is_one_exact_closed_table) source = read_text_file(PCM_LOCK_SOURCE_PATH); first = strstr(source, "\npcm_entry_retire_eligible_locked("); UT_ASSERT_NOT_NULL(first); - UT_ASSERT_NULL(first != NULL - ? strstr(first + 1, "\npcm_entry_retire_eligible_locked(") : NULL); + UT_ASSERT_NULL(first != NULL ? strstr(first + 1, "\npcm_entry_retire_eligible_locked(") : NULL); for (i = 0; i < lengthof(refusal_contract); i++) UT_ASSERT_NOT_NULL(strstr(first, refusal_contract[i])); free(source); @@ -1691,19 +1645,14 @@ UT_TEST(test_resource_x_executor_t1_t2_t3_is_exact_and_blocks_no_progress) changed = ref; changed.acquisition_generation++; ungranted = make_resource_x_acquisition_ref(ungranted_tag, 2, 17, 42); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_t1_grant_exact(&ungranted), - RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_t1_grant_exact(&ungranted), RESOURCE_X_APPLY_APPLIED); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_t1_grant_exact(&ref), - RESOURCE_X_APPLY_APPLIED); - UT_ASSERT(pcm_entry_ref_acquire( - &tag, false, &entry_ref, &acquire_result)); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_t1_grant_exact(&ref), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT(pcm_entry_ref_acquire(&tag, false, &entry_ref, &acquire_result)); binding_generation = entry_ref.binding_generation; pcm_entry_ref_release(&entry_ref); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_t1_grant_exact(&ref), - RESOURCE_X_APPLY_DUPLICATE); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_t1_grant_exact(&changed), - RESOURCE_X_APPLY_STALE); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_t1_grant_exact(&ref), RESOURCE_X_APPLY_DUPLICATE); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_t1_grant_exact(&changed), RESOURCE_X_APPLY_STALE); memset(&snapshot, 0, sizeof(snapshot)); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_executor_probe_exact(&ref, &snapshot), RESOURCE_X_EXECUTOR_READY); @@ -1715,12 +1664,10 @@ UT_TEST(test_resource_x_executor_t1_t2_t3_is_exact_and_blocks_no_progress) UT_ASSERT_EQ(snapshot.ref.formation, ref.formation); UT_ASSERT_EQ(snapshot.ref.acquisition_generation, ref.acquisition_generation); - cluster_pcm_lock_resource_x_publish_no_progress_exact( - &ref, RESOURCE_X_NO_PROGRESS_BUFFER_BUSY); + cluster_pcm_lock_resource_x_publish_no_progress_exact(&ref, RESOURCE_X_NO_PROGRESS_BUFFER_BUSY); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_executor_probe_exact(&ref, &snapshot), RESOURCE_X_EXECUTOR_BLOCKED); - UT_ASSERT(!pcm_entry_retire_classify_exact( - &tag, binding_generation, &why)); + UT_ASSERT(!pcm_entry_retire_classify_exact(&tag, binding_generation, &why)); UT_ASSERT_EQ(why, PCM_RETIRE_REFUSAL_WAITER_PRESENT); UT_ASSERT_EQ(fake_cv_prepare_count, 2); UT_ASSERT_EQ(fake_cv_cancel_count, 1); @@ -1738,8 +1685,7 @@ UT_TEST(test_resource_x_executor_t1_t2_t3_is_exact_and_blocks_no_progress) UT_ASSERT_EQ(fake_cv_cancel_count, 2); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_executor_rearm_exact(&changed), RESOURCE_X_APPLY_STALE); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_executor_rearm_exact(&ref), - RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_executor_rearm_exact(&ref), RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_executor_rearm_exact(&ref), RESOURCE_X_APPLY_DUPLICATE); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_executor_probe_exact(&ref, &snapshot), @@ -1812,8 +1758,7 @@ UT_TEST(test_resource_x_exact_t3_retires_without_physical_release_and_admits_suc reset_fake_pcm_runtime(4); first = make_resource_x_acquisition_ref(tag, 2, 17, 6); successor = make_resource_x_acquisition_ref(tag, 2, 17, 8); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_t1_grant_exact(&first), - RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_t1_grant_exact(&first), RESOURCE_X_APPLY_APPLIED); complete_resource_x_executor_no_join(&first); memset(&snapshot, 0, sizeof(snapshot)); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_executor_probe_exact(&first, &snapshot), @@ -1822,8 +1767,7 @@ UT_TEST(test_resource_x_exact_t3_retires_without_physical_release_and_admits_suc RESOURCE_X_PROGRESS_T1 | RESOURCE_X_PROGRESS_T2 | RESOURCE_X_PROGRESS_T3); UT_ASSERT_EQ(snapshot.requester_base_generation, 1); UT_ASSERT_EQ(snapshot.retired_acquisition_generation, 6); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_t1_grant_exact(&successor), - RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_t1_grant_exact(&successor), RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_executor_probe_exact(&successor, &snapshot), RESOURCE_X_EXECUTOR_READY); UT_ASSERT_EQ(snapshot.ref.acquisition_generation, 8); @@ -1845,17 +1789,13 @@ UT_TEST(test_resource_x_retired_floor_rejects_late_generation_without_touching_s first = make_resource_x_acquisition_ref(tag, 2, 17, 6); older = make_resource_x_acquisition_ref(tag, 2, 17, 4); successor = make_resource_x_acquisition_ref(tag, 2, 17, 8); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_t1_grant_exact(&first), - RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_t1_grant_exact(&first), RESOURCE_X_APPLY_APPLIED); complete_resource_x_executor_no_join(&first); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_t1_grant_exact(&successor), - RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_t1_grant_exact(&successor), RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_executor_probe_exact(&successor, &before), RESOURCE_X_EXECUTOR_READY); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_t1_grant_exact(&first), - RESOURCE_X_APPLY_STALE); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_t1_grant_exact(&older), - RESOURCE_X_APPLY_STALE); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_t1_grant_exact(&first), RESOURCE_X_APPLY_STALE); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_t1_grant_exact(&older), RESOURCE_X_APPLY_STALE); memset(&stale_install, 0, sizeof(stale_install)); stale_install.ownership_generation = 9; stale_install.writer_activation_token = 12; @@ -1881,10 +1821,8 @@ UT_TEST(test_resource_x_probe_t3_wait_window_observes_retired_duplicate) reset_fake_pcm_runtime(4); ref = make_resource_x_acquisition_ref(tag, 2, 17, 6); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_t1_grant_exact(&ref), - RESOURCE_X_APPLY_APPLIED); - cluster_pcm_lock_resource_x_publish_no_progress_exact( - &ref, RESOURCE_X_NO_PROGRESS_BUFFER_BUSY); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_t1_grant_exact(&ref), RESOURCE_X_APPLY_APPLIED); + cluster_pcm_lock_resource_x_publish_no_progress_exact(&ref, RESOURCE_X_NO_PROGRESS_BUFFER_BUSY); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_executor_probe_exact(&ref, &snapshot), RESOURCE_X_EXECUTOR_BLOCKED); UT_ASSERT(fake_cv_prepared); @@ -1962,16 +1900,14 @@ UT_TEST(test_resource_x_native_gate_snapshot_and_exact_fail_closed) UT_ASSERT_EQ(snapshot.formation, UINT64_C(0)); UT_ASSERT_EQ(snapshot.freeze_generation, UINT64_C(0)); memset(&snapshot, 0xA5, sizeof(snapshot)); - UT_ASSERT(cluster_pcm_lock_resource_x_cutover_gate_snapshot_exact( - &snapshot)); + UT_ASSERT(cluster_pcm_lock_resource_x_cutover_gate_snapshot_exact(&snapshot)); UT_ASSERT_EQ(snapshot.phase, RESOURCE_X_GATE_OPEN); UT_ASSERT_EQ(snapshot.formation, UINT64_C(0)); UT_ASSERT_EQ(snapshot.freeze_generation, UINT64_C(0)); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), RESOURCE_X_APPLY_APPLIED); - UT_ASSERT(cluster_pcm_lock_resource_x_cutover_gate_snapshot_exact( - &snapshot)); + UT_ASSERT(cluster_pcm_lock_resource_x_cutover_gate_snapshot_exact(&snapshot)); UT_ASSERT(cluster_pcm_lock_resource_x_gate_snapshot(&snapshot)); UT_ASSERT_EQ(snapshot.phase, RESOURCE_X_GATE_OPEN); UT_ASSERT_EQ(snapshot.formation, UINT64_C(17)); @@ -1985,8 +1921,7 @@ UT_TEST(test_resource_x_native_gate_snapshot_and_exact_fail_closed) UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_fail_closed_exact(&snapshot), RESOURCE_X_APPLY_APPLIED); UT_ASSERT(!cluster_pcm_lock_resource_x_gate_open_exact(17)); - UT_ASSERT(!cluster_pcm_lock_resource_x_cutover_gate_snapshot_exact( - &stale)); + UT_ASSERT(!cluster_pcm_lock_resource_x_cutover_gate_snapshot_exact(&stale)); UT_ASSERT(cluster_pcm_lock_resource_x_gate_snapshot(&stale)); UT_ASSERT_EQ(stale.phase, RESOURCE_X_GATE_RECOVERY_BLOCKED); UT_ASSERT_EQ(stale.formation, snapshot.formation); @@ -2032,13 +1967,11 @@ UT_TEST(test_resource_x_reconfig_freeze_closes_activation_drains_and_thaws_empty UT_ASSERT_EQ(cluster_pcm_lock_resource_x_activation_inflight_count(), 0); memset(&batch, 0xA5, sizeof(batch)); - UT_ASSERT_EQ(cluster_resource_x_reconfig_sweep(&token, 4, &batch), - RESOURCE_X_RECONFIG_MORE); + UT_ASSERT_EQ(cluster_resource_x_reconfig_sweep(&token, 4, &batch), RESOURCE_X_RECONFIG_MORE); UT_ASSERT_EQ(batch.examined_count, 4); UT_ASSERT_EQ(batch.complete_wrap, 1); UT_ASSERT_EQ(batch.zero_residual, 0); - UT_ASSERT_EQ(cluster_resource_x_reconfig_sweep(&token, 4, &batch), - RESOURCE_X_RECONFIG_DONE); + UT_ASSERT_EQ(cluster_resource_x_reconfig_sweep(&token, 4, &batch), RESOURCE_X_RECONFIG_DONE); UT_ASSERT_EQ(batch.examined_count, 4); UT_ASSERT_EQ(batch.complete_wrap, 1); UT_ASSERT_EQ(batch.zero_residual, 1); @@ -2078,10 +2011,8 @@ UT_TEST(test_resource_x_reconfig_pending_freeze_binds_only_published_formation) UT_ASSERT_EQ(pending_copy.new_formation, 18); UT_ASSERT(cluster_resource_x_reconfig_freeze_pending(17, &replay)); UT_ASSERT_EQ(memcmp(&replay, &token, sizeof(token)), 0); - UT_ASSERT_EQ(cluster_resource_x_reconfig_sweep(&token, 4, &batch), - RESOURCE_X_RECONFIG_MORE); - UT_ASSERT_EQ(cluster_resource_x_reconfig_sweep(&token, 4, &batch), - RESOURCE_X_RECONFIG_DONE); + UT_ASSERT_EQ(cluster_resource_x_reconfig_sweep(&token, 4, &batch), RESOURCE_X_RECONFIG_MORE); + UT_ASSERT_EQ(cluster_resource_x_reconfig_sweep(&token, 4, &batch), RESOURCE_X_RECONFIG_DONE); UT_ASSERT(cluster_resource_x_reconfig_thaw_exact(&token)); cluster_resource_x_reconfig_stats_snapshot(&stats); UT_ASSERT_EQ(stats.freeze_count, 1); @@ -2100,18 +2031,14 @@ UT_TEST(test_resource_x_reconfig_pending_freeze_binds_only_published_formation) UT_ASSERT_EQ(token.reserved, 0); UT_ASSERT(cluster_resource_x_reconfig_cutover_begin_native_exact(&replay)); UT_ASSERT_EQ(memcmp(&replay, &token, sizeof(token)), 0); - UT_ASSERT_EQ(cluster_resource_x_reconfig_sweep(&token, 4, &batch), - RESOURCE_X_RECONFIG_DONE); + UT_ASSERT_EQ(cluster_resource_x_reconfig_sweep(&token, 4, &batch), RESOURCE_X_RECONFIG_DONE); UT_ASSERT_EQ(batch.complete_wrap, 1); UT_ASSERT_EQ(batch.zero_residual, 0); UT_ASSERT(!cluster_resource_x_reconfig_zero_proof_exact(&token, &zero)); - UT_ASSERT(cluster_resource_x_reconfig_cutover_bind_native_successor_exact( - &token)); + UT_ASSERT(cluster_resource_x_reconfig_cutover_bind_native_successor_exact(&token)); UT_ASSERT_EQ(token.new_formation, 18); - UT_ASSERT_EQ(cluster_resource_x_reconfig_sweep(&token, 4, &batch), - RESOURCE_X_RECONFIG_MORE); - UT_ASSERT_EQ(cluster_resource_x_reconfig_sweep(&token, 4, &batch), - RESOURCE_X_RECONFIG_DONE); + UT_ASSERT_EQ(cluster_resource_x_reconfig_sweep(&token, 4, &batch), RESOURCE_X_RECONFIG_MORE); + UT_ASSERT_EQ(cluster_resource_x_reconfig_sweep(&token, 4, &batch), RESOURCE_X_RECONFIG_DONE); UT_ASSERT(cluster_resource_x_reconfig_zero_proof_exact(&token, &zero)); } @@ -2141,19 +2068,15 @@ UT_TEST(test_resource_x_cutover_formation_pair_is_native_not_r4_arithmetic) memset(&replay, 0, sizeof(replay)); UT_ASSERT(cluster_resource_x_reconfig_cutover_begin_native_exact(&replay)); UT_ASSERT_EQ(memcmp(&replay, &token, sizeof(token)), 0); - UT_ASSERT_EQ(cluster_resource_x_reconfig_sweep(&token, 4, &batch), - RESOURCE_X_RECONFIG_DONE); + UT_ASSERT_EQ(cluster_resource_x_reconfig_sweep(&token, 4, &batch), RESOURCE_X_RECONFIG_DONE); UT_ASSERT(!cluster_resource_x_reconfig_zero_proof_exact(&token, &zero)); - UT_ASSERT(cluster_resource_x_reconfig_cutover_bind_native_successor_exact( - &token)); + UT_ASSERT(cluster_resource_x_reconfig_cutover_bind_native_successor_exact(&token)); UT_ASSERT(token.new_formation != 0); UT_ASSERT(token.new_formation != UINT64_MAX); UT_ASSERT(token.new_formation != unrelated_r4_generation); UT_ASSERT(token.new_formation != token.old_formation); - UT_ASSERT_EQ(cluster_resource_x_reconfig_sweep(&token, 4, &batch), - RESOURCE_X_RECONFIG_MORE); - UT_ASSERT_EQ(cluster_resource_x_reconfig_sweep(&token, 4, &batch), - RESOURCE_X_RECONFIG_DONE); + UT_ASSERT_EQ(cluster_resource_x_reconfig_sweep(&token, 4, &batch), RESOURCE_X_RECONFIG_MORE); + UT_ASSERT_EQ(cluster_resource_x_reconfig_sweep(&token, 4, &batch), RESOURCE_X_RECONFIG_DONE); UT_ASSERT(cluster_resource_x_reconfig_zero_proof_exact(&token, &zero)); } @@ -2173,14 +2096,12 @@ UT_TEST(test_resource_x_reconfig_pending_sweep_waits_for_registered_inflight_to_ UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), RESOURCE_X_APPLY_APPLIED); UT_ASSERT(cluster_pcm_lock_resource_x_executor_enter(&ref, &gate)); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_t1_grant_exact(&ref), - RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_t1_grant_exact(&ref), RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_executor_probe_exact(&ref, &before), RESOURCE_X_EXECUTOR_READY); UT_ASSERT(cluster_resource_x_reconfig_cutover_begin_native_exact(&token)); - UT_ASSERT_EQ(cluster_resource_x_reconfig_sweep(&token, 4, &batch), - RESOURCE_X_RECONFIG_MORE); + UT_ASSERT_EQ(cluster_resource_x_reconfig_sweep(&token, 4, &batch), RESOURCE_X_RECONFIG_MORE); UT_ASSERT_EQ(batch.retry_count, 0); UT_ASSERT_EQ(batch.orphan_count, 0); UT_ASSERT_EQ(batch.residual_count, 0); @@ -2190,17 +2111,13 @@ UT_TEST(test_resource_x_reconfig_pending_sweep_waits_for_registered_inflight_to_ complete_resource_x_executor_no_join(&ref); cluster_pcm_lock_resource_x_executor_leave(&gate); - UT_ASSERT_EQ(cluster_resource_x_reconfig_sweep(&token, 4, &batch), - RESOURCE_X_RECONFIG_DONE); + UT_ASSERT_EQ(cluster_resource_x_reconfig_sweep(&token, 4, &batch), RESOURCE_X_RECONFIG_DONE); UT_ASSERT_EQ(batch.complete_wrap, 1); UT_ASSERT_EQ(batch.zero_residual, 0); UT_ASSERT(!cluster_resource_x_reconfig_zero_proof_exact(&token, &zero)); - UT_ASSERT(cluster_resource_x_reconfig_cutover_bind_native_successor_exact( - &token)); - UT_ASSERT_EQ(cluster_resource_x_reconfig_sweep(&token, 4, &batch), - RESOURCE_X_RECONFIG_MORE); - UT_ASSERT_EQ(cluster_resource_x_reconfig_sweep(&token, 4, &batch), - RESOURCE_X_RECONFIG_DONE); + UT_ASSERT(cluster_resource_x_reconfig_cutover_bind_native_successor_exact(&token)); + UT_ASSERT_EQ(cluster_resource_x_reconfig_sweep(&token, 4, &batch), RESOURCE_X_RECONFIG_MORE); + UT_ASSERT_EQ(cluster_resource_x_reconfig_sweep(&token, 4, &batch), RESOURCE_X_RECONFIG_DONE); UT_ASSERT(cluster_resource_x_reconfig_zero_proof_exact(&token, &zero)); } @@ -2216,20 +2133,17 @@ UT_TEST(test_resource_x_reconfig_pending_sweep_classifies_unowned_old_active_as_ ref = make_resource_x_acquisition_ref(tag, 2, 17, 42); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), RESOURCE_X_APPLY_APPLIED); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_t1_grant_exact(&ref), - RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_t1_grant_exact(&ref), RESOURCE_X_APPLY_APPLIED); UT_ASSERT(cluster_resource_x_reconfig_cutover_begin_native_exact(&token)); - UT_ASSERT_EQ(cluster_resource_x_reconfig_sweep(&token, 4, &batch), - RESOURCE_X_RECONFIG_ORPHAN); + UT_ASSERT_EQ(cluster_resource_x_reconfig_sweep(&token, 4, &batch), RESOURCE_X_RECONFIG_ORPHAN); UT_ASSERT_EQ(batch.retry_count, 0); UT_ASSERT_EQ(batch.orphan_count, 1); UT_ASSERT_EQ(batch.residual_count, 1); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_executor_probe_exact(&ref, &snapshot), RESOURCE_X_EXECUTOR_RECOVERY_BLOCKED); - UT_ASSERT_EQ(snapshot.progress_flags, - RESOURCE_X_PROGRESS_BOUND | RESOURCE_X_PROGRESS_T1 - | RESOURCE_X_PROGRESS_RECOVERY_BLOCKED); + UT_ASSERT_EQ(snapshot.progress_flags, RESOURCE_X_PROGRESS_BOUND | RESOURCE_X_PROGRESS_T1 + | RESOURCE_X_PROGRESS_RECOVERY_BLOCKED); } UT_TEST(test_resource_x_reconfig_nested_and_generation_exhaustion_fail_closed) @@ -2252,8 +2166,7 @@ UT_TEST(test_resource_x_reconfig_nested_and_generation_exhaustion_fail_closed) RESOURCE_X_APPLY_APPLIED); UT_ASSERT(cluster_resource_x_reconfig_freeze(17, 18, &token)); UT_ASSERT(!cluster_resource_x_reconfig_freeze(17, 19, &token)); - UT_ASSERT_EQ(cluster_resource_x_reconfig_sweep(&token, 4, &batch), - RESOURCE_X_RECONFIG_CORRUPT); + UT_ASSERT_EQ(cluster_resource_x_reconfig_sweep(&token, 4, &batch), RESOURCE_X_RECONFIG_CORRUPT); UT_ASSERT(!cluster_resource_x_reconfig_thaw_exact(&token)); cluster_resource_x_reconfig_stats_snapshot(&stats); UT_ASSERT_EQ(stats.freeze_count, 1); @@ -2285,14 +2198,12 @@ UT_TEST(test_resource_x_reconfig_cursor_covers_seventeen_slots_in_bounded_calls) for (i = 0; i < 10; i++) { result = cluster_resource_x_reconfig_sweep(&token, 4, &batch); UT_ASSERT_EQ(batch.examined_count, (i % 5) < 4 ? 4 : 1); - UT_ASSERT_EQ(batch.next_state_index, - (i % 5) < 4 ? (uint64)((i % 5) + 1) * 4 : 0); + UT_ASSERT_EQ(batch.next_state_index, (i % 5) < 4 ? (uint64)((i % 5) + 1) * 4 : 0); if (i < 9) { UT_ASSERT_EQ(result, RESOURCE_X_RECONFIG_MORE); UT_ASSERT_EQ(batch.complete_wrap, i == 4 ? 1 : 0); UT_ASSERT_EQ(batch.zero_residual, 0); - } - else { + } else { UT_ASSERT_EQ(result, RESOURCE_X_RECONFIG_DONE); UT_ASSERT_EQ(batch.complete_wrap, 1); UT_ASSERT_EQ(batch.zero_residual, 1); @@ -2331,8 +2242,7 @@ UT_TEST(test_resource_x_same_token_zero_and_clean_completion_proofs_are_exact) result = cluster_resource_x_reconfig_sweep(&token, 4, &batch); calls++; UT_ASSERT(calls <= 4); - } while (result == RESOURCE_X_RECONFIG_MORE - || result == RESOURCE_X_RECONFIG_RETRY); + } while (result == RESOURCE_X_RECONFIG_MORE || result == RESOURCE_X_RECONFIG_RETRY); UT_ASSERT_EQ(result, RESOURCE_X_RECONFIG_DONE); UT_ASSERT(calls >= 2); UT_ASSERT(cluster_resource_x_reconfig_zero_proof_exact(&token, &zero)); @@ -2352,85 +2262,78 @@ UT_TEST(test_resource_x_same_token_zero_and_clean_completion_proofs_are_exact) stale.new_formation++; UT_ASSERT(!cluster_resource_x_reconfig_zero_proof_exact(&stale, &zero_copy)); fake_resource_x_transport_staged_count = 1; - UT_ASSERT(!cluster_pcm_lock_resource_x_clean_completion_prove_exact( - &token, &zero, &clean)); + UT_ASSERT(!cluster_pcm_lock_resource_x_clean_completion_prove_exact(&token, &zero, &clean)); fake_resource_x_transport_staged_count = 0; fake_resource_x_transport_snapshot_call_count = 0; fake_resource_x_transport_advance_on_call = 2; - UT_ASSERT(!cluster_pcm_lock_resource_x_clean_completion_prove_exact( - &token, &zero, &clean)); + UT_ASSERT(!cluster_pcm_lock_resource_x_clean_completion_prove_exact(&token, &zero, &clean)); fake_resource_x_transport_snapshot_call_count = 0; fake_resource_x_transport_advance_on_call = 0; - UT_ASSERT(cluster_pcm_lock_resource_x_clean_completion_prove_exact( - &token, &zero, &clean)); - UT_ASSERT_EQ(clean.final_mutation_sequence, - zero.final_mutation_sequence); + UT_ASSERT(cluster_pcm_lock_resource_x_clean_completion_prove_exact(&token, &zero, &clean)); + UT_ASSERT_EQ(clean.final_mutation_sequence, zero.final_mutation_sequence); UT_ASSERT_EQ(clean.logical_debt_zero, 1); UT_ASSERT_EQ(clean.transport_debt_zero, 1); - UT_ASSERT_EQ(clean.transport_mutation_sequence, - fake_resource_x_transport_mutation_sequence); + UT_ASSERT_EQ(clean.transport_mutation_sequence, fake_resource_x_transport_mutation_sequence); UT_ASSERT_EQ(clean.transport_staged_count, 0); - UT_ASSERT(cluster_pcm_lock_resource_x_clean_completion_proof_exact( - &token, &zero, &clean_copy)); + UT_ASSERT(cluster_pcm_lock_resource_x_clean_completion_proof_exact(&token, &zero, &clean_copy)); UT_ASSERT_EQ(memcmp(&clean_copy, &clean, sizeof(clean)), 0); - UT_ASSERT(cluster_pcm_lock_resource_x_cutover_proofs_exact( - &cutover_token, &cutover_zero, &cutover_clean)); + UT_ASSERT(cluster_pcm_lock_resource_x_cutover_proofs_exact(&cutover_token, &cutover_zero, + &cutover_clean)); UT_ASSERT_EQ(memcmp(&cutover_token, &token, sizeof(token)), 0); UT_ASSERT_EQ(memcmp(&cutover_zero, &zero, sizeof(zero)), 0); UT_ASSERT_EQ(memcmp(&cutover_clean, &clean, sizeof(clean)), 0); - UT_ASSERT(cluster_pcm_lock_resource_x_cutover_current_proof_digest_exact( - false, &cutover_token, &frozen_digest)); + UT_ASSERT(cluster_pcm_lock_resource_x_cutover_current_proof_digest_exact(false, &cutover_token, + &frozen_digest)); UT_ASSERT_EQ(memcmp(&cutover_token, &token, sizeof(token)), 0); UT_ASSERT(frozen_digest != 0); /* A late physical owner may already have drained, leaving count zero. * Its mutation generation still invalidates the older zero snapshot. */ fake_resource_x_transport_mutation_sequence++; - UT_ASSERT(!cluster_pcm_lock_resource_x_clean_completion_proof_exact( - &token, &zero, &clean_copy)); + UT_ASSERT( + !cluster_pcm_lock_resource_x_clean_completion_proof_exact(&token, &zero, &clean_copy)); memset(&cutover_token, 0xff, sizeof(cutover_token)); memset(&cutover_zero, 0xff, sizeof(cutover_zero)); memset(&cutover_clean, 0xff, sizeof(cutover_clean)); - UT_ASSERT(!cluster_pcm_lock_resource_x_cutover_proofs_exact( - &cutover_token, &cutover_zero, &cutover_clean)); + UT_ASSERT(!cluster_pcm_lock_resource_x_cutover_proofs_exact(&cutover_token, &cutover_zero, + &cutover_clean)); UT_ASSERT_EQ(cutover_token.old_formation, 0); UT_ASSERT_EQ(cutover_zero.proof_generation, 0); UT_ASSERT_EQ(cutover_clean.proof_generation, 0); - UT_ASSERT(cluster_pcm_lock_resource_x_clean_completion_prove_exact( - &token, &zero, &clean)); + UT_ASSERT(cluster_pcm_lock_resource_x_clean_completion_prove_exact(&token, &zero, &clean)); fake_resource_x_transport_snapshot_available = false; - UT_ASSERT(!cluster_pcm_lock_resource_x_clean_completion_proof_exact( - &token, &zero, &clean_copy)); + UT_ASSERT( + !cluster_pcm_lock_resource_x_clean_completion_proof_exact(&token, &zero, &clean_copy)); fake_resource_x_transport_snapshot_available = true; - UT_ASSERT(!cluster_pcm_lock_resource_x_clean_completion_proof_exact( - &stale, &zero, &clean_copy)); + UT_ASSERT( + !cluster_pcm_lock_resource_x_clean_completion_proof_exact(&stale, &zero, &clean_copy)); frozen_digest = 0; - UT_ASSERT(cluster_pcm_lock_resource_x_cutover_current_proof_digest_exact( - false, &cutover_token, &frozen_digest)); + UT_ASSERT(cluster_pcm_lock_resource_x_cutover_current_proof_digest_exact(false, &cutover_token, + &frozen_digest)); UT_ASSERT(frozen_digest != 0); UT_ASSERT(cluster_resource_x_reconfig_thaw_exact(&token)); UT_ASSERT(!cluster_resource_x_reconfig_zero_proof_exact(&token, &zero_copy)); - UT_ASSERT(!cluster_pcm_lock_resource_x_clean_completion_proof_exact( - &token, &zero, &clean_copy)); - UT_ASSERT(!cluster_pcm_lock_resource_x_cutover_proofs_exact( - &cutover_token, &cutover_zero, &cutover_clean)); - UT_ASSERT(cluster_pcm_lock_resource_x_cutover_thawed_proofs_exact( - &thawed_token, &thawed_zero, &thawed_clean)); + UT_ASSERT( + !cluster_pcm_lock_resource_x_clean_completion_proof_exact(&token, &zero, &clean_copy)); + UT_ASSERT(!cluster_pcm_lock_resource_x_cutover_proofs_exact(&cutover_token, &cutover_zero, + &cutover_clean)); + UT_ASSERT(cluster_pcm_lock_resource_x_cutover_thawed_proofs_exact(&thawed_token, &thawed_zero, + &thawed_clean)); UT_ASSERT_EQ(memcmp(&thawed_token, &token, sizeof(token)), 0); UT_ASSERT_EQ(memcmp(&thawed_zero, &zero, sizeof(zero)), 0); UT_ASSERT_EQ(memcmp(&thawed_clean, &clean, sizeof(clean)), 0); - UT_ASSERT(!cluster_pcm_lock_resource_x_cutover_current_proof_digest_exact( - false, &cutover_token, &thawed_digest)); - UT_ASSERT(cluster_pcm_lock_resource_x_cutover_current_proof_digest_exact( - true, &cutover_token, &thawed_digest)); + UT_ASSERT(!cluster_pcm_lock_resource_x_cutover_current_proof_digest_exact(false, &cutover_token, + &thawed_digest)); + UT_ASSERT(cluster_pcm_lock_resource_x_cutover_current_proof_digest_exact(true, &cutover_token, + &thawed_digest)); UT_ASSERT_EQ(memcmp(&cutover_token, &token, sizeof(token)), 0); UT_ASSERT_EQ(thawed_digest, frozen_digest); fake_resource_x_transport_mutation_sequence++; - UT_ASSERT(!cluster_pcm_lock_resource_x_cutover_thawed_proofs_exact( - &thawed_token, &thawed_zero, &thawed_clean)); - UT_ASSERT(!cluster_pcm_lock_resource_x_cutover_current_proof_digest_exact( - true, &cutover_token, &thawed_digest)); + UT_ASSERT(!cluster_pcm_lock_resource_x_cutover_thawed_proofs_exact(&thawed_token, &thawed_zero, + &thawed_clean)); + UT_ASSERT(!cluster_pcm_lock_resource_x_cutover_current_proof_digest_exact(true, &cutover_token, + &thawed_digest)); UT_ASSERT_EQ(thawed_digest, UINT64_C(0)); } @@ -2450,22 +2353,18 @@ UT_TEST(test_resource_x_same_token_proofs_reject_postscan_entry_mutation) UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), RESOURCE_X_APPLY_APPLIED); UT_ASSERT(cluster_resource_x_reconfig_freeze(17, 18, &token)); - UT_ASSERT_EQ(cluster_resource_x_reconfig_sweep(&token, 4, &batch), - RESOURCE_X_RECONFIG_MORE); - UT_ASSERT_EQ(cluster_resource_x_reconfig_sweep(&token, 4, &batch), - RESOURCE_X_RECONFIG_DONE); + UT_ASSERT_EQ(cluster_resource_x_reconfig_sweep(&token, 4, &batch), RESOURCE_X_RECONFIG_MORE); + UT_ASSERT_EQ(cluster_resource_x_reconfig_sweep(&token, 4, &batch), RESOURCE_X_RECONFIG_DONE); UT_ASSERT(cluster_resource_x_reconfig_zero_proof_exact(&token, &zero)); - UT_ASSERT(cluster_pcm_lock_resource_x_clean_completion_prove_exact( - &token, &zero, &clean)); + UT_ASSERT(cluster_pcm_lock_resource_x_clean_completion_prove_exact(&token, &zero, &clean)); /* The cutover owner closes legacy admission before proof. This deliberate * legacy entry mutation models a violated barrier and must invalidate both * predecessor records rather than be hidden by a final zero snapshot. */ cluster_pcm_lock_acquire(tag, PCM_LOCK_MODE_S); - UT_ASSERT(!cluster_resource_x_reconfig_zero_proof_exact( - &token, &zero_copy)); - UT_ASSERT(!cluster_pcm_lock_resource_x_clean_completion_proof_exact( - &token, &zero, &clean_copy)); + UT_ASSERT(!cluster_resource_x_reconfig_zero_proof_exact(&token, &zero_copy)); + UT_ASSERT( + !cluster_pcm_lock_resource_x_clean_completion_proof_exact(&token, &zero, &clean_copy)); UT_ASSERT(!cluster_resource_x_reconfig_thaw_exact(&token)); } @@ -2483,13 +2382,11 @@ UT_TEST(test_resource_x_reconfig_t1_orphan_blocks_once_and_retains_evidence) RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_t1_grant_exact(&ref), RESOURCE_X_APPLY_APPLIED); UT_ASSERT(cluster_resource_x_reconfig_freeze(17, 18, &token)); - UT_ASSERT_EQ(cluster_resource_x_reconfig_sweep(&token, 4, &batch), - RESOURCE_X_RECONFIG_ORPHAN); + UT_ASSERT_EQ(cluster_resource_x_reconfig_sweep(&token, 4, &batch), RESOURCE_X_RECONFIG_ORPHAN); UT_ASSERT_EQ(batch.orphan_count, 1); UT_ASSERT_EQ(batch.residual_count, 1); UT_ASSERT(!cluster_resource_x_reconfig_thaw_exact(&token)); - UT_ASSERT_EQ(cluster_resource_x_reconfig_sweep(&token, 4, &batch), - RESOURCE_X_RECONFIG_CORRUPT); + UT_ASSERT_EQ(cluster_resource_x_reconfig_sweep(&token, 4, &batch), RESOURCE_X_RECONFIG_CORRUPT); cluster_resource_x_reconfig_stats_snapshot(&stats); UT_ASSERT_EQ(stats.orphan_count, 1); UT_ASSERT_EQ(stats.blocked_count, 1); @@ -2514,18 +2411,17 @@ UT_TEST(test_resource_x_reconfig_half_join_without_active_is_retained_orphan) UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), RESOURCE_X_APPLY_APPLIED); make_resource_x_remote_join_pair(tag, 2, &grant, &image); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact( - &image, 0, &join), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact(&image, 0, &join), + RESOURCE_X_APPLY_APPLIED); assertion = join.assertion; UT_ASSERT_EQ(join.flags, RESOURCE_X_REQUESTER_JOIN_HAS_IMAGE); UT_ASSERT(cluster_resource_x_reconfig_freeze(17, 18, &token)); - UT_ASSERT_EQ(cluster_resource_x_reconfig_sweep(&token, 4, &batch), - RESOURCE_X_RECONFIG_ORPHAN); + UT_ASSERT_EQ(cluster_resource_x_reconfig_sweep(&token, 4, &batch), RESOURCE_X_RECONFIG_ORPHAN); UT_ASSERT_EQ(batch.orphan_count, 1); UT_ASSERT_EQ(batch.residual_count, 1); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_frames_exact( - &assertion, &retained_grant, &retained_image, &join), - RESOURCE_X_APPLY_BAD_STATE); + &assertion, &retained_grant, &retained_image, &join), + RESOURCE_X_APPLY_BAD_STATE); UT_ASSERT_EQ(join.flags, RESOURCE_X_REQUESTER_JOIN_HAS_IMAGE); } @@ -2549,8 +2445,7 @@ UT_TEST(test_resource_x_reconfig_t2_neutralizes_outside_entry_lock_then_blocks_o UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_apply_exact(&ref, &proof), RESOURCE_X_APPLY_APPLIED); UT_ASSERT(cluster_resource_x_reconfig_freeze(17, 18, &token)); - UT_ASSERT_EQ(cluster_resource_x_reconfig_sweep(&token, 4, &batch), - RESOURCE_X_RECONFIG_ORPHAN); + UT_ASSERT_EQ(cluster_resource_x_reconfig_sweep(&token, 4, &batch), RESOURCE_X_RECONFIG_ORPHAN); UT_ASSERT_EQ(fake_neutralize_count, 1); UT_ASSERT(fake_neutralize_without_pcm_lock); UT_ASSERT(BufferTagsEqual(&fake_neutralize_tag, &tag)); @@ -2584,8 +2479,7 @@ UT_TEST(test_resource_x_reconfig_t2_newer_sidecar_survives_and_blocks_orphan) UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_apply_exact(&ref, &proof), RESOURCE_X_APPLY_APPLIED); UT_ASSERT(cluster_resource_x_reconfig_freeze(17, 18, &token)); - UT_ASSERT_EQ(cluster_resource_x_reconfig_sweep(&token, 4, &batch), - RESOURCE_X_RECONFIG_ORPHAN); + UT_ASSERT_EQ(cluster_resource_x_reconfig_sweep(&token, 4, &batch), RESOURCE_X_RECONFIG_ORPHAN); UT_ASSERT_EQ(fake_neutralize_count, 1); UT_ASSERT(fake_neutralize_without_pcm_lock); UT_ASSERT_EQ(batch.sidecar_neutralized_count, 0); @@ -2598,14 +2492,13 @@ UT_TEST(test_resource_x_reconfig_t2_newer_sidecar_survives_and_blocks_orphan) } static ResourceXDecodedFrame -make_resource_x_master_frame(ResourceXWireKind kind, BufferTag tag, - int32 requester_node, int32 action_node) +make_resource_x_master_frame(ResourceXWireKind kind, BufferTag tag, int32 requester_node, + int32 action_node) { ResourceXDecodedFrame frame; memset(&frame, 0, sizeof(frame)); - UT_ASSERT(resource_x_assertion_init(&tag, requester_node, - &frame.common.logical_assertion)); + UT_ASSERT(resource_x_assertion_init(&tag, requester_node, &frame.common.logical_assertion)); frame.kind = kind; frame.common.base_authority_generation = 1; frame.common.resource_formation = 17; @@ -2630,8 +2523,7 @@ put_resource_x_test_u64(uint8 *out, uint64 value) } static void -set_resource_x_test_source_fence(uint8 *fence, uint64 source_generation, - uint8 source_mode) +set_resource_x_test_source_fence(uint8 *fence, uint64 source_generation, uint8 source_mode) { put_resource_x_test_u64(fence + 20, source_generation); fence[28] = source_mode; @@ -2640,14 +2532,13 @@ set_resource_x_test_source_fence(uint8 *fence, uint64 source_generation, static ResourceXDecodedFrame make_resource_x_bootstrap_request_values(BufferTag tag, int32 requester_node, - uint64 resource_formation, - uint64 master_session_incarnation, - uint64 assertion_sequence, - uint32 sender_connection_generation) + uint64 resource_formation, + uint64 master_session_incarnation, + uint64 assertion_sequence, + uint32 sender_connection_generation) { ResourceXDecodedFrame request = make_resource_x_master_frame( - RESOURCE_X_WIRE_PREASSERT_BOOTSTRAP, tag, requester_node, - requester_node); + RESOURCE_X_WIRE_PREASSERT_BOOTSTRAP, tag, requester_node, requester_node); ResourceXDecodedFrame decoded; ResourceXWireReject reject = RESOURCE_X_WIRE_REJECT_NONE; uint8 wire[RESOURCE_X_CONTROL_V1_BYTES]; @@ -2656,31 +2547,28 @@ make_resource_x_bootstrap_request_values(BufferTag tag, int32 requester_node, request.common.base_authority_generation = 0; request.common.ordered_lane = 0; request.common.resource_formation = resource_formation; - request.common.master_session_incarnation - = master_session_incarnation; + request.common.master_session_incarnation = master_session_incarnation; request.common.assertion_sequence = assertion_sequence; - request.common.sender_connection_generation - = sender_connection_generation; + request.common.sender_connection_generation = sender_connection_generation; request.common.authority_generation = 0; - UT_ASSERT(cluster_resource_x_wire_encode(RESOURCE_X_MSG_ASSERT_X, - &request, wire, sizeof(wire), &wire_len, &reject)); + UT_ASSERT(cluster_resource_x_wire_encode(RESOURCE_X_MSG_ASSERT_X, &request, wire, sizeof(wire), + &wire_len, &reject)); UT_ASSERT_EQ(wire_len, RESOURCE_X_CONTROL_V1_BYTES); - UT_ASSERT(cluster_resource_x_wire_decode(RESOURCE_X_MSG_ASSERT_X, - wire, wire_len, &decoded, &reject)); + UT_ASSERT( + cluster_resource_x_wire_decode(RESOURCE_X_MSG_ASSERT_X, wire, wire_len, &decoded, &reject)); return decoded; } static ResourceXDecodedFrame make_resource_x_bootstrap_request(BufferTag tag, int32 requester_node) { - return make_resource_x_bootstrap_request_values( - tag, requester_node, 17, 31, 41, 51); + return make_resource_x_bootstrap_request_values(tag, requester_node, 17, 31, 41, 51); } static ResourceXDecodedFrame -make_resource_x_bootstrap_ack_values( - const ResourceXDecodedFrame *request, uint64 base_authority_generation, - uint32 sender_connection_generation) +make_resource_x_bootstrap_ack_values(const ResourceXDecodedFrame *request, + uint64 base_authority_generation, + uint32 sender_connection_generation) { ResourceXDecodedFrame ack = *request; ResourceXDecodedFrame decoded; @@ -2692,12 +2580,11 @@ make_resource_x_bootstrap_ack_values( ack.common.sender_connection_generation = sender_connection_generation; ack.common.outcome = RESOURCE_X_OUTCOME_OK; ack.common.flags = 0; - UT_ASSERT(cluster_resource_x_wire_encode( - RESOURCE_X_MSG_IMAGE_OR_GRANT, &ack, wire, sizeof(wire), - &wire_len, &reject)); + UT_ASSERT(cluster_resource_x_wire_encode(RESOURCE_X_MSG_IMAGE_OR_GRANT, &ack, wire, + sizeof(wire), &wire_len, &reject)); UT_ASSERT_EQ(wire_len, RESOURCE_X_CONTROL_V1_BYTES); - UT_ASSERT(cluster_resource_x_wire_decode( - RESOURCE_X_MSG_IMAGE_OR_GRANT, wire, wire_len, &decoded, &reject)); + UT_ASSERT(cluster_resource_x_wire_decode(RESOURCE_X_MSG_IMAGE_OR_GRANT, wire, wire_len, + &decoded, &reject)); return decoded; } @@ -2721,55 +2608,47 @@ UT_TEST(test_pcm_d4_tombstone_reuse_is_generation_exact) reset_fake_pcm_runtime(2); cluster_node_id = 0; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), - RESOURCE_X_APPLY_APPLIED); - UT_ASSERT(pcm_entry_ref_acquire( - &retired_tag, true, &ref, &acquire_result)); + RESOURCE_X_APPLY_APPLIED); + UT_ASSERT(pcm_entry_ref_acquire(&retired_tag, true, &ref, &acquire_result)); old_generation = ref.binding_generation; retired_slot = ref.registry_slot; pcm_entry_ref_release(&ref); cluster_pcm_lock_pi_watermark_scn_advance(retired_tag, (SCN)0x4400, - CLUSTER_PCM_WM_SRC_REDECLARE, 0, 71, 17); - UT_ASSERT(cluster_pcm_lock_pi_watermark_prov_query( - retired_tag, &provenance)); + CLUSTER_PCM_WM_SRC_REDECLARE, 0, 71, 17); + UT_ASSERT(cluster_pcm_lock_pi_watermark_prov_query(retired_tag, &provenance)); cluster_pcm_lock_pi_watermark_retire_for_tag(retired_tag); - UT_ASSERT(pcm_entry_ref_acquire( - &survivor_tag, true, &ref, &acquire_result)); + UT_ASSERT(pcm_entry_ref_acquire(&survivor_tag, true, &ref, &acquire_result)); survivor_generation = ref.binding_generation; survivor_slot = ref.registry_slot; pcm_entry_ref_release(&ref); UT_ASSERT(retired_slot != survivor_slot); - old_assertion = make_resource_x_master_frame( - RESOURCE_X_WIRE_ASSERT_X, retired_tag, 1, 1); - - UT_ASSERT(pcm_entry_try_retire_exact( - &retired_tag, old_generation, PCM_RETIRE_REASON_PI_DISCARDED)); - UT_ASSERT(!cluster_pcm_lock_pi_watermark_prov_query( - retired_tag, &provenance)); - UT_ASSERT(!pcm_entry_ref_acquire( - &retired_tag, false, &ref, &acquire_result)); + old_assertion = make_resource_x_master_frame(RESOURCE_X_WIRE_ASSERT_X, retired_tag, 1, 1); + + UT_ASSERT( + pcm_entry_try_retire_exact(&retired_tag, old_generation, PCM_RETIRE_REASON_PI_DISCARDED)); + UT_ASSERT(!cluster_pcm_lock_pi_watermark_prov_query(retired_tag, &provenance)); + UT_ASSERT(!pcm_entry_ref_acquire(&retired_tag, false, &ref, &acquire_result)); UT_ASSERT_EQ(acquire_result, PCM_ENTRY_ACQUIRE_NOT_FOUND); - UT_ASSERT(pcm_entry_ref_acquire( - &survivor_tag, false, &ref, &acquire_result)); + UT_ASSERT(pcm_entry_ref_acquire(&survivor_tag, false, &ref, &acquire_result)); UT_ASSERT_EQ(ref.binding_generation, survivor_generation); UT_ASSERT_EQ(ref.registry_slot, survivor_slot); pcm_entry_ref_release(&ref); - UT_ASSERT(pcm_entry_ref_acquire( - &retired_tag, true, &ref, &acquire_result)); + UT_ASSERT(pcm_entry_ref_acquire(&retired_tag, true, &ref, &acquire_result)); new_generation = ref.binding_generation; UT_ASSERT(new_generation > old_generation); UT_ASSERT_EQ(ref.registry_slot, retired_slot); pcm_entry_ref_release(&ref); - UT_ASSERT(!cluster_pcm_lock_pi_watermark_prov_query( - retired_tag, &provenance)); + UT_ASSERT(!cluster_pcm_lock_pi_watermark_prov_query(retired_tag, &provenance)); request = make_resource_x_bootstrap_request(retired_tag, 1); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_bootstrap_request_exact( - &request, 1, 61, 77, 31, 71, &ack), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ( + cluster_pcm_lock_resource_x_bootstrap_request_exact(&request, 1, 61, 77, 31, 71, &ack), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT(ack.common.base_authority_generation > UINT64_C(1)); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact( - &old_assertion, 1, &snapshot), RESOURCE_X_APPLY_STALE); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact(&old_assertion, 1, &snapshot), + RESOURCE_X_APPLY_STALE); } UT_TEST(test_pcm_d4_reused_binding_first_grant_keeps_generation_lineage) @@ -2787,34 +2666,32 @@ UT_TEST(test_pcm_d4_reused_binding_first_grant_keeps_generation_lineage) reset_fake_pcm_runtime(1); cluster_node_id = 0; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), - RESOURCE_X_APPLY_APPLIED); + RESOURCE_X_APPLY_APPLIED); UT_ASSERT(pcm_entry_ref_acquire(&tag, true, &ref, &acquire_result)); old_generation = ref.binding_generation; pcm_entry_ref_release(&ref); - UT_ASSERT(pcm_entry_try_retire_exact( - &tag, old_generation, PCM_RETIRE_REASON_PI_DISCARDED)); + UT_ASSERT(pcm_entry_try_retire_exact(&tag, old_generation, PCM_RETIRE_REASON_PI_DISCARDED)); UT_ASSERT(pcm_entry_ref_acquire(&tag, true, &ref, &acquire_result)); UT_ASSERT(ref.binding_generation > old_generation); pcm_entry_ref_release(&ref); request = make_resource_x_bootstrap_request(tag, 1); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_bootstrap_request_exact( - &request, 1, 61, 77, 31, 71, &ack), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ( + cluster_pcm_lock_resource_x_bootstrap_request_exact(&request, 1, 61, 77, 31, 71, &ack), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT(ack.common.base_authority_generation > UINT64_C(1)); assertion = ack; assertion.kind = RESOURCE_X_WIRE_ASSERT_X; assertion.common.sender_connection_generation = 51; - assertion.common.authority_generation - = assertion.common.base_authority_generation; + assertion.common.authority_generation = assertion.common.base_authority_generation; assertion.common.outcome = RESOURCE_X_OUTCOME_NONE; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_bootstrapped_exact( - &assertion, 1, 61, 77, 31, 71, &snapshot), - RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_bootstrapped_exact(&assertion, 1, 61, 77, 31, + 71, &snapshot), + RESOURCE_X_APPLY_APPLIED); memset(&durable, 0, sizeof(durable)); durable.assertion = assertion.common.logical_assertion; - durable.base_authority_generation - = assertion.common.base_authority_generation; + durable.base_authority_generation = assertion.common.base_authority_generation; durable.resource_formation = 17; durable.master_session_incarnation = 31; durable.assertion_sequence = assertion.common.assertion_sequence; @@ -2822,11 +2699,10 @@ UT_TEST(test_pcm_d4_reused_binding_first_grant_keeps_generation_lineage) durable.page_scn_lsn = 82; durable.page_checksum = UINT32_C(0x12345678); durable.source_proof_crc32c = UINT32_C(0x87654321); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_durable_proof_exact( - &durable, &snapshot), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_durable_proof_exact(&durable, &snapshot), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(snapshot.phase, RESOURCE_X_MASTER_GRANT_COMMITTED); - UT_ASSERT(snapshot.final_authority_generation - > assertion.common.base_authority_generation); + UT_ASSERT(snapshot.final_authority_generation > assertion.common.base_authority_generation); } UT_TEST(test_pcm_d4_displaced_tombstone_preserves_authority_floor) @@ -2852,60 +2728,56 @@ UT_TEST(test_pcm_d4_displaced_tombstone_preserves_authority_floor) reset_fake_pcm_runtime(2); cluster_node_id = 0; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), - RESOURCE_X_APPLY_APPLIED); - UT_ASSERT(pcm_entry_ref_acquire( - &retired_tag, true, &ref, &acquire_result)); + RESOURCE_X_APPLY_APPLIED); + UT_ASSERT(pcm_entry_ref_acquire(&retired_tag, true, &ref, &acquire_result)); retired_generation = ref.binding_generation; retired_slot = ref.registry_slot; pcm_entry_ref_release(&ref); - UT_ASSERT(pcm_entry_ref_acquire( - &survivor_tag, true, &ref, &acquire_result)); + UT_ASSERT(pcm_entry_ref_acquire(&survivor_tag, true, &ref, &acquire_result)); survivor_generation = ref.binding_generation; survivor_slot = ref.registry_slot; pcm_entry_ref_release(&ref); UT_ASSERT(retired_slot != survivor_slot); for (cycle = 0; cycle < 5; cycle++) { - UT_ASSERT_EQ(cluster_pcm_lock_apply_gcs_transition_result( - retired_tag, PCM_TRANS_N_TO_X, 0), PCM_GCS_TRANSITION_APPLIED); - UT_ASSERT_EQ(cluster_pcm_lock_apply_gcs_transition_result( - retired_tag, PCM_TRANS_X_TO_N_RELEASE, 0), + UT_ASSERT_EQ(cluster_pcm_lock_apply_gcs_transition_result(retired_tag, PCM_TRANS_N_TO_X, 0), + PCM_GCS_TRANSITION_APPLIED); + UT_ASSERT_EQ( + cluster_pcm_lock_apply_gcs_transition_result(retired_tag, PCM_TRANS_X_TO_N_RELEASE, 0), PCM_GCS_TRANSITION_APPLIED); } UT_ASSERT(cluster_pcm_lock_authority_snapshot(retired_tag, &authority)); retired_authority = authority.transition_count; UT_ASSERT(retired_authority > retired_generation); - old_assertion = make_resource_x_master_frame( - RESOURCE_X_WIRE_ASSERT_X, retired_tag, 1, 1); + old_assertion = make_resource_x_master_frame(RESOURCE_X_WIRE_ASSERT_X, retired_tag, 1, 1); old_assertion.common.base_authority_generation = retired_authority; old_assertion.common.authority_generation = retired_authority; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_adapter_base_bind_exact( - &old_assertion.common.logical_assertion, 17, - retired_authority, &authority), RESOURCE_X_APPLY_APPLIED); + &old_assertion.common.logical_assertion, 17, retired_authority, &authority), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT(pcm_entry_try_retire_exact(&retired_tag, retired_generation, - PCM_RETIRE_REASON_HOLDER_RELEASE)); + PCM_RETIRE_REASON_HOLDER_RELEASE)); /* Same-home tag consumes the old tag's tombstone. */ - UT_ASSERT(pcm_entry_ref_acquire( - &displacement_tag, true, &ref, &acquire_result)); + UT_ASSERT(pcm_entry_ref_acquire(&displacement_tag, true, &ref, &acquire_result)); displaced_slot = ref.registry_slot; pcm_entry_ref_release(&ref); UT_ASSERT_EQ(displaced_slot, retired_slot); UT_ASSERT(pcm_entry_try_retire_exact(&survivor_tag, survivor_generation, - PCM_RETIRE_REASON_HOLDER_RELEASE)); + PCM_RETIRE_REASON_HOLDER_RELEASE)); /* Rebinding the original tag now uses the other tombstone. Its base must * still dominate its own retired authority, not that lower slot floor. */ - UT_ASSERT(pcm_entry_ref_acquire( - &retired_tag, true, &ref, &acquire_result)); + UT_ASSERT(pcm_entry_ref_acquire(&retired_tag, true, &ref, &acquire_result)); UT_ASSERT_EQ(ref.registry_slot, survivor_slot); pcm_entry_ref_release(&ref); request = make_resource_x_bootstrap_request(retired_tag, 1); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_bootstrap_request_exact( - &request, 1, 61, 77, 31, 71, &ack), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ( + cluster_pcm_lock_resource_x_bootstrap_request_exact(&request, 1, 61, 77, 31, 71, &ack), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT(ack.common.base_authority_generation > retired_authority); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact( - &old_assertion, 1, &snapshot), RESOURCE_X_APPLY_STALE); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact(&old_assertion, 1, &snapshot), + RESOURCE_X_APPLY_STALE); } UT_TEST(test_pcm_d5_capacity_retry_reclaims_one_terminal_binding) @@ -2923,29 +2795,24 @@ UT_TEST(test_pcm_d5_capacity_retry_reclaims_one_terminal_binding) reset_fake_pcm_runtime(2); cluster_node_id = 0; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), - RESOURCE_X_APPLY_APPLIED); - UT_ASSERT(pcm_entry_ref_acquire( - &retired_tag, true, &retired_ref, &acquire_result)); + RESOURCE_X_APPLY_APPLIED); + UT_ASSERT(pcm_entry_ref_acquire(&retired_tag, true, &retired_ref, &acquire_result)); retired_generation = retired_ref.binding_generation; pcm_entry_ref_release(&retired_ref); - UT_ASSERT(pcm_entry_ref_acquire( - &survivor_tag, true, &survivor_ref, &acquire_result)); + UT_ASSERT(pcm_entry_ref_acquire(&survivor_tag, true, &survivor_ref, &acquire_result)); survivor_generation = survivor_ref.binding_generation; pcm_entry_ref_release(&survivor_ref); - UT_ASSERT_EQ(cluster_pcm_lock_apply_gcs_transition_result( - survivor_tag, PCM_TRANS_N_TO_S, 0), PCM_GCS_TRANSITION_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_apply_gcs_transition_result(survivor_tag, PCM_TRANS_N_TO_S, 0), + PCM_GCS_TRANSITION_APPLIED); /* The first insert sees a full directory. One bounded reclaim and one * exact insert retry may reuse only the unpinned terminal binding. */ - UT_ASSERT(pcm_entry_ref_acquire( - &new_tag, true, &new_ref, &acquire_result)); + UT_ASSERT(pcm_entry_ref_acquire(&new_tag, true, &new_ref, &acquire_result)); UT_ASSERT(new_ref.binding_generation > retired_generation); pcm_entry_ref_release(&new_ref); - UT_ASSERT(!pcm_entry_ref_acquire( - &retired_tag, false, &retired_ref, &acquire_result)); + UT_ASSERT(!pcm_entry_ref_acquire(&retired_tag, false, &retired_ref, &acquire_result)); UT_ASSERT_EQ(acquire_result, PCM_ENTRY_ACQUIRE_NOT_FOUND); - UT_ASSERT(pcm_entry_ref_acquire( - &survivor_tag, false, &survivor_ref, &acquire_result)); + UT_ASSERT(pcm_entry_ref_acquire(&survivor_tag, false, &survivor_ref, &acquire_result)); UT_ASSERT_EQ(survivor_ref.binding_generation, survivor_generation); pcm_entry_ref_release(&survivor_ref); } @@ -2960,7 +2827,7 @@ UT_TEST(test_pcm_d5_bounded_reclaim_never_exceeds_probe_budget) reset_fake_pcm_runtime(4); cluster_node_id = 0; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), - RESOURCE_X_APPLY_APPLIED); + RESOURCE_X_APPLY_APPLIED); for (blockno = 220; blockno < 224; blockno++) { BufferTag tag = make_tag((uint32)blockno); @@ -2984,7 +2851,7 @@ UT_TEST(test_pcm_d5_last_holder_release_fast_retires_exact_binding) reset_fake_pcm_runtime(4); cluster_node_id = 0; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), - RESOURCE_X_APPLY_APPLIED); + RESOURCE_X_APPLY_APPLIED); cluster_pcm_lock_acquire(tag, PCM_LOCK_MODE_S); UT_ASSERT(pcm_entry_ref_acquire(&tag, false, &ref, &acquire_result)); generation = ref.binding_generation; @@ -3008,7 +2875,7 @@ UT_TEST(test_pcm_d5_remote_master_s_eviction_fast_retires_closed_requester_proje reset_fake_pcm_runtime(4); cluster_node_id = 0; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), - RESOURCE_X_APPLY_APPLIED); + RESOURCE_X_APPLY_APPLIED); UT_ASSERT(pcm_entry_ref_acquire(&tag, true, &ref, &acquire_result)); generation = ref.binding_generation; pcm_entry_ref_release(&ref); @@ -3041,7 +2908,7 @@ UT_TEST(test_pcm_d5_remote_master_s_eviction_never_retires_rebound_projection) reset_fake_pcm_runtime(4); cluster_node_id = 0; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), - RESOURCE_X_APPLY_APPLIED); + RESOURCE_X_APPLY_APPLIED); UT_ASSERT(pcm_entry_ref_acquire(&tag, true, &ref, &acquire_result)); old_generation = ref.binding_generation; pcm_entry_ref_release(&ref); @@ -3052,8 +2919,7 @@ UT_TEST(test_pcm_d5_remote_master_s_eviction_never_retires_rebound_projection) cluster_pcm_lock_release_saved_tag_for_eviction(tag, PCM_LOCK_MODE_S); UT_ASSERT(fake_gcs_transition_rebound_generation > old_generation); UT_ASSERT(pcm_entry_ref_acquire(&tag, false, &ref, &acquire_result)); - UT_ASSERT_EQ(ref.binding_generation, - fake_gcs_transition_rebound_generation); + UT_ASSERT_EQ(ref.binding_generation, fake_gcs_transition_rebound_generation); pcm_entry_ref_release(&ref); } @@ -3065,17 +2931,17 @@ UT_TEST(test_pcm_d7_remote_s_eviction_closes_pending_x_to_s_master_state) reset_fake_pcm_runtime(4); cluster_node_id = 0; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), - RESOURCE_X_APPLY_APPLIED); + RESOURCE_X_APPLY_APPLIED); /* Reproduce the exact terminal split observed by fresh t/430: the holder * has already committed its local X->S, but the unacknowledged predecessor * notification has not changed the remote master's X@self state yet. A * cache-replacement release must close that predecessor before returning; * it may not leave the master X after the local mapping is gone. */ - UT_ASSERT_EQ(cluster_pcm_lock_apply_gcs_transition_result( - tag, PCM_TRANS_N_TO_X, 0), PCM_GCS_TRANSITION_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_apply_gcs_transition_result(tag, PCM_TRANS_N_TO_X, 0), + PCM_GCS_TRANSITION_APPLIED); UT_ASSERT(cluster_pcm_lock_authority_snapshot(tag, &authority)); - UT_ASSERT_EQ((int) authority.state, (int) PCM_STATE_X); + UT_ASSERT_EQ((int)authority.state, (int)PCM_STATE_X); UT_ASSERT_EQ(authority.x_holder_node, 0); fake_gcs_master_node = 1; @@ -3084,7 +2950,7 @@ UT_TEST(test_pcm_d7_remote_s_eviction_closes_pending_x_to_s_master_state) cluster_pcm_lock_release_saved_tag_for_eviction(tag, PCM_LOCK_MODE_S); UT_ASSERT(cluster_pcm_lock_authority_snapshot(tag, &authority)); - UT_ASSERT_EQ((int) authority.state, (int) PCM_STATE_N); + UT_ASSERT_EQ((int)authority.state, (int)PCM_STATE_N); UT_ASSERT_EQ(authority.x_holder_node, -1); } @@ -3099,20 +2965,18 @@ UT_TEST(test_pcm_d5_durable_pi_discard_fast_retires_exact_binding) reset_fake_pcm_runtime(4); cluster_node_id = 0; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), - RESOURCE_X_APPLY_APPLIED); + RESOURCE_X_APPLY_APPLIED); cluster_pcm_lock_acquire(tag, PCM_LOCK_MODE_X); cluster_pcm_lock_downgrade(tag, PCM_LOCK_MODE_N, true); - cluster_pcm_lock_pi_watermark_scn_advance(tag, (SCN)0x5500, - CLUSTER_PCM_WM_SRC_REDECLARE, 0, 31, 17); + cluster_pcm_lock_pi_watermark_scn_advance(tag, (SCN)0x5500, CLUSTER_PCM_WM_SRC_REDECLARE, 0, 31, + 17); UT_ASSERT(pcm_entry_ref_acquire(&tag, false, &ref, &acquire_result)); generation = ref.binding_generation; pcm_entry_ref_release(&ref); - UT_ASSERT(!cluster_pcm_lock_pi_discard_collect( - tag, (SCN)0x54ff, &holders)); + UT_ASSERT(!cluster_pcm_lock_pi_discard_collect(tag, (SCN)0x54ff, &holders)); UT_ASSERT_EQ(holders, 0); - UT_ASSERT(cluster_pcm_lock_pi_discard_collect( - tag, (SCN)0x5500, &holders)); + UT_ASSERT(cluster_pcm_lock_pi_discard_collect(tag, (SCN)0x5500, &holders)); UT_ASSERT_EQ(holders, UINT32_C(1)); UT_ASSERT(!pcm_entry_ref_acquire(&tag, false, &ref, &acquire_result)); UT_ASSERT_EQ(acquire_result, PCM_ENTRY_ACQUIRE_NOT_FOUND); @@ -3140,22 +3004,22 @@ UT_TEST(test_pcm_d5_resource_x_terminal_release_fast_retires_exact_binding) reset_fake_pcm_runtime(4); cluster_node_id = 0; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), - RESOURCE_X_APPLY_APPLIED); - UT_ASSERT_EQ(cluster_pcm_lock_apply_gcs_transition_result( - tag, PCM_TRANS_N_TO_X, 0), PCM_GCS_TRANSITION_APPLIED); - UT_ASSERT_EQ(cluster_pcm_lock_apply_gcs_transition_result( - tag, PCM_TRANS_X_TO_N_RELEASE, 0), PCM_GCS_TRANSITION_APPLIED); + RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_apply_gcs_transition_result(tag, PCM_TRANS_N_TO_X, 0), + PCM_GCS_TRANSITION_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_apply_gcs_transition_result(tag, PCM_TRANS_X_TO_N_RELEASE, 0), + PCM_GCS_TRANSITION_APPLIED); UT_ASSERT(cluster_pcm_lock_authority_snapshot(tag, &authority)); - assertion = make_resource_x_master_frame( - RESOURCE_X_WIRE_ASSERT_X, tag, 1, 1); + assertion = make_resource_x_master_frame(RESOURCE_X_WIRE_ASSERT_X, tag, 1, 1); assertion.common.base_authority_generation = authority.transition_count; assertion.common.authority_generation = authority.transition_count; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_adapter_base_bind_exact( - &assertion.common.logical_assertion, 17, - authority.transition_count, &authority), RESOURCE_X_APPLY_APPLIED); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact( - &assertion, 1, &snapshot), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ( + cluster_pcm_lock_resource_x_adapter_base_bind_exact(&assertion.common.logical_assertion, 17, + authority.transition_count, &authority), + RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact(&assertion, 1, &snapshot), + RESOURCE_X_APPLY_APPLIED); memset(&durable, 0, sizeof(durable)); durable.assertion = assertion.common.logical_assertion; @@ -3167,23 +3031,20 @@ UT_TEST(test_pcm_d5_resource_x_terminal_release_fast_retires_exact_binding) durable.page_scn_lsn = 82; durable.page_checksum = UINT32_C(0x12345678); durable.source_proof_crc32c = UINT32_C(0x87654321); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_durable_proof_exact( - &durable, &snapshot), RESOURCE_X_APPLY_APPLIED); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_grant_intent_snapshot_exact( - &assertion.common.logical_assertion, &grant_intent, grant_bytes, - sizeof(grant_bytes)), RESOURCE_X_APPLY_APPLIED); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_grant_intent_stage_exact( - &grant_intent, 101), RESOURCE_X_INTENT_STAGED); - UT_ASSERT(cluster_pcm_lock_resource_x_grant_intent_complete_exact( - &grant_intent)); - - settlement = make_resource_x_master_frame( - RESOURCE_X_WIRE_INSTALL_SETTLEMENT, tag, 1, 1); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_durable_proof_exact(&durable, &snapshot), + RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ( + cluster_pcm_lock_resource_x_grant_intent_snapshot_exact( + &assertion.common.logical_assertion, &grant_intent, grant_bytes, sizeof(grant_bytes)), + RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_grant_intent_stage_exact(&grant_intent, 101), + RESOURCE_X_INTENT_STAGED); + UT_ASSERT(cluster_pcm_lock_resource_x_grant_intent_complete_exact(&grant_intent)); + + settlement = make_resource_x_master_frame(RESOURCE_X_WIRE_INSTALL_SETTLEMENT, tag, 1, 1); settlement.common.outcome = RESOURCE_X_OUTCOME_OK; - settlement.common.base_authority_generation - = durable.base_authority_generation; - settlement.common.authority_generation - = snapshot.final_authority_generation; + settlement.common.base_authority_generation = durable.base_authority_generation; + settlement.common.authority_generation = snapshot.final_authority_generation; settlement.body.install_settlement.conversion_base_generation = durable.base_authority_generation; settlement.body.install_settlement.final_authority_generation @@ -3192,33 +3053,26 @@ UT_TEST(test_pcm_d5_resource_x_terminal_release_fast_retires_exact_binding) settlement.body.install_settlement.requester_target_generation = 41; settlement.body.install_settlement.page_scn_lsn = durable.page_scn_lsn; settlement.body.install_settlement.page_checksum = durable.page_checksum; - settlement.body.install_settlement.source_proof_crc32c - = durable.source_proof_crc32c; + settlement.body.install_settlement.source_proof_crc32c = durable.source_proof_crc32c; settlement.body.install_settlement.installed_mode = PCM_STATE_X; - settlement.body.install_settlement.requester_role - = RESOURCE_X_REQUESTER_ROLE_ACQUIRER; - settlement.body.install_settlement.terminal_outcome - = RESOURCE_X_OUTCOME_OK; - settlement.body.install_settlement.terminal_state - = RESOURCE_X_SETTLEMENT_TERMINAL_INSTALLED; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_install_settlement_exact( - &settlement, 1, &settled), RESOURCE_X_APPLY_APPLIED); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_settled_retire_exact( - &assertion.common.logical_assertion, - assertion.common.assertion_sequence, &settled), + settlement.body.install_settlement.requester_role = RESOURCE_X_REQUESTER_ROLE_ACQUIRER; + settlement.body.install_settlement.terminal_outcome = RESOURCE_X_OUTCOME_OK; + settlement.body.install_settlement.terminal_state = RESOURCE_X_SETTLEMENT_TERMINAL_INSTALLED; + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_install_settlement_exact(&settlement, 1, &settled), + RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ( + cluster_pcm_lock_resource_x_settled_retire_exact( + &assertion.common.logical_assertion, assertion.common.assertion_sequence, &settled), RESOURCE_X_APPLY_APPLIED); - release = make_resource_x_master_frame( - RESOURCE_X_WIRE_RELEASE_X, tag, 1, 1); + release = make_resource_x_master_frame(RESOURCE_X_WIRE_RELEASE_X, tag, 1, 1); release.common.observed_mode = PCM_STATE_X; release.common.target_mode = PCM_STATE_N; release.common.outcome = RESOURCE_X_OUTCOME_OK; - release.common.base_authority_generation - = durable.base_authority_generation; - release.common.authority_generation - = settled.final_authority_generation; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_release_x_exact( - &release, 1, &snapshot), RESOURCE_X_APPLY_APPLIED); + release.common.base_authority_generation = durable.base_authority_generation; + release.common.authority_generation = settled.final_authority_generation; + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_release_x_exact(&release, 1, &snapshot), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(snapshot.phase, RESOURCE_X_MASTER_RELEASED); UT_ASSERT(!pcm_entry_ref_acquire(&tag, false, &ref, &acquire_result)); UT_ASSERT_EQ(acquire_result, PCM_ENTRY_ACQUIRE_NOT_FOUND); @@ -3237,31 +3091,27 @@ UT_TEST(test_pcm_d5_lifecycle_stats_are_exact_not_legacy_aliases) reset_fake_pcm_runtime(2); cluster_node_id = 0; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), - RESOURCE_X_APPLY_APPLIED); + RESOURCE_X_APPLY_APPLIED); cluster_pcm_grd_lifecycle_stats_snapshot(&stats); UT_ASSERT_EQ(stats.live_entries, 0); UT_ASSERT_EQ(stats.peak_live_entries, 0); - UT_ASSERT(pcm_entry_ref_acquire( - &first_tag, true, &ref, &acquire_result)); + UT_ASSERT(pcm_entry_ref_acquire(&first_tag, true, &ref, &acquire_result)); pcm_entry_ref_release(&ref); - UT_ASSERT(pcm_entry_ref_acquire( - &second_tag, true, &ref, &acquire_result)); + UT_ASSERT(pcm_entry_ref_acquire(&second_tag, true, &ref, &acquire_result)); pcm_entry_ref_release(&ref); - UT_ASSERT_EQ(cluster_pcm_lock_apply_gcs_transition_result( - second_tag, PCM_TRANS_N_TO_S, 0), PCM_GCS_TRANSITION_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_apply_gcs_transition_result(second_tag, PCM_TRANS_N_TO_S, 0), + PCM_GCS_TRANSITION_APPLIED); /* Full allocation reclaims first_tag and reuses exactly one tombstone. */ - UT_ASSERT(pcm_entry_ref_acquire( - &third_tag, true, &ref, &acquire_result)); + UT_ASSERT(pcm_entry_ref_acquire(&third_tag, true, &ref, &acquire_result)); pcm_entry_ref_release(&ref); - UT_ASSERT_EQ(cluster_pcm_lock_apply_gcs_transition_result( - third_tag, PCM_TRANS_N_TO_S, 0), PCM_GCS_TRANSITION_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_apply_gcs_transition_result(third_tag, PCM_TRANS_N_TO_S, 0), + PCM_GCS_TRANSITION_APPLIED); /* Both live bindings are active. One bounded retry must terminate with * NO_CAPACITY and leave the Resource-X gate open. */ - UT_ASSERT(!pcm_entry_ref_acquire( - &full_tag, true, &ref, &acquire_result)); + UT_ASSERT(!pcm_entry_ref_acquire(&full_tag, true, &ref, &acquire_result)); UT_ASSERT_EQ(acquire_result, PCM_ENTRY_ACQUIRE_NO_CAPACITY); UT_ASSERT(cluster_pcm_lock_resource_x_gate_open_exact(17)); @@ -3275,8 +3125,7 @@ UT_TEST(test_pcm_d5_lifecycle_stats_are_exact_not_legacy_aliases) UT_ASSERT_EQ(stats.capacity_retry_count, UINT64_C(2)); UT_ASSERT_EQ(stats.capacity_fail_count, UINT64_C(1)); UT_ASSERT_EQ(stats.peak_live_entries, UINT64_C(2)); - UT_ASSERT(stats.reclaim_refused[PCM_RETIRE_REFUSAL_PCM_MODE_NOT_N] - >= UINT64_C(2)); + UT_ASSERT(stats.reclaim_refused[PCM_RETIRE_REFUSAL_PCM_MODE_NOT_N] >= UINT64_C(2)); } UT_TEST(test_pcm_d1_bootstrap_no_capacity_is_pre_mutation_backpressure) @@ -3294,18 +3143,16 @@ UT_TEST(test_pcm_d1_bootstrap_no_capacity_is_pre_mutation_backpressure) reset_fake_pcm_runtime(2); cluster_node_id = 0; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), - RESOURCE_X_APPLY_APPLIED); + RESOURCE_X_APPLY_APPLIED); - UT_ASSERT(pcm_entry_ref_acquire( - &first_tag, true, &ref, &acquire_result)); + UT_ASSERT(pcm_entry_ref_acquire(&first_tag, true, &ref, &acquire_result)); pcm_entry_ref_release(&ref); - UT_ASSERT_EQ(cluster_pcm_lock_apply_gcs_transition_result( - first_tag, PCM_TRANS_N_TO_S, 0), PCM_GCS_TRANSITION_APPLIED); - UT_ASSERT(pcm_entry_ref_acquire( - &second_tag, true, &ref, &acquire_result)); + UT_ASSERT_EQ(cluster_pcm_lock_apply_gcs_transition_result(first_tag, PCM_TRANS_N_TO_S, 0), + PCM_GCS_TRANSITION_APPLIED); + UT_ASSERT(pcm_entry_ref_acquire(&second_tag, true, &ref, &acquire_result)); pcm_entry_ref_release(&ref); - UT_ASSERT_EQ(cluster_pcm_lock_apply_gcs_transition_result( - second_tag, PCM_TRANS_N_TO_S, 0), PCM_GCS_TRANSITION_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_apply_gcs_transition_result(second_tag, PCM_TRANS_N_TO_S, 0), + PCM_GCS_TRANSITION_APPLIED); UT_ASSERT(resource_x_assertion_init(&full_tag, 0, &assertion)); action = cluster_pcm_lock_resource_x_bootstrap_round_step_exact( @@ -3313,8 +3160,7 @@ UT_TEST(test_pcm_d1_bootstrap_no_capacity_is_pre_mutation_backpressure) UINT64_C(100), UINT64_C(50), false, 0, &dispatch, &terminal_ref); UT_ASSERT_EQ(action, RESOURCE_X_BOOTSTRAP_ROUND_BACKPRESSURE); UT_ASSERT(cluster_pcm_lock_resource_x_gate_open_exact(17)); - UT_ASSERT(!pcm_entry_ref_acquire( - &full_tag, false, &ref, &acquire_result)); + UT_ASSERT(!pcm_entry_ref_acquire(&full_tag, false, &ref, &acquire_result)); UT_ASSERT_EQ(acquire_result, PCM_ENTRY_ACQUIRE_NOT_FOUND); } @@ -3327,12 +3173,11 @@ UT_TEST(test_pcm_d5_lmon_soft_threshold_reclaims_one_bounded_tick) reset_fake_pcm_runtime(4); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), - RESOURCE_X_APPLY_APPLIED); + RESOURCE_X_APPLY_APPLIED); for (blockno = 231; blockno < 234; blockno++) { BufferTag tag = make_tag((uint32)blockno); - UT_ASSERT(pcm_entry_ref_acquire( - &tag, true, &ref, &acquire_result)); + UT_ASSERT(pcm_entry_ref_acquire(&tag, true, &ref, &acquire_result)); pcm_entry_ref_release(&ref); } cluster_pcm_grd_lifecycle_stats_snapshot(&stats); @@ -3356,7 +3201,7 @@ UT_TEST(test_pcm_d5_reclaim_stops_while_gate_is_not_open) reset_fake_pcm_runtime(4); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), - RESOURCE_X_APPLY_APPLIED); + RESOURCE_X_APPLY_APPLIED); UT_ASSERT(pcm_entry_ref_acquire(&tag, true, &ref, &acquire_result)); pcm_entry_ref_release(&ref); UT_ASSERT(cluster_resource_x_reconfig_freeze(17, 18, &token)); @@ -3386,27 +3231,27 @@ UT_TEST(test_resource_x_native_head_is_exact_s_admission_barrier) UT_ASSERT(!cluster_pcm_lock_resource_x_s_barrier_active_exact(&tag)); request = make_resource_x_bootstrap_request(tag, 1); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_bootstrap_request_exact( - &request, 1, 61, 77, 31, 71, &ack), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ( + cluster_pcm_lock_resource_x_bootstrap_request_exact(&request, 1, 61, 77, 31, 71, &ack), + RESOURCE_X_APPLY_APPLIED); /* A kind-9 receipt is intentionally non-authority and cannot deny S. */ UT_ASSERT(!cluster_pcm_lock_resource_x_s_barrier_active_exact(&tag)); assertion = ack; assertion.kind = RESOURCE_X_WIRE_ASSERT_X; assertion.common.sender_connection_generation = 51; - assertion.common.authority_generation - = assertion.common.base_authority_generation; + assertion.common.authority_generation = assertion.common.base_authority_generation; assertion.common.outcome = RESOURCE_X_OUTCOME_NONE; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_bootstrapped_exact( - &assertion, 1, 61, 77, 31, 71, &snapshot), - RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_bootstrapped_exact(&assertion, 1, 61, 77, 31, + 71, &snapshot), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(snapshot.phase, RESOURCE_X_MASTER_WAIT_PROOF); UT_ASSERT(cluster_pcm_lock_resource_x_s_barrier_active_exact(&tag)); /* The native-head verdict and durable S publication must share the * resource entry lock. A pre-check followed by an independent apply * would let ASSERT linearize in the gap. */ - UT_ASSERT_EQ(cluster_pcm_lock_apply_gcs_transition_result( - tag, PCM_TRANS_N_TO_S, 2), PCM_GCS_TRANSITION_PENDING_X); + UT_ASSERT_EQ(cluster_pcm_lock_apply_gcs_transition_result(tag, PCM_TRANS_N_TO_S, 2), + PCM_GCS_TRANSITION_PENDING_X); UT_ASSERT_EQ(cluster_pcm_lock_query(tag), PCM_LOCK_MODE_N); memset(&durable, 0, sizeof(durable)); @@ -3419,13 +3264,12 @@ UT_TEST(test_resource_x_native_head_is_exact_s_admission_barrier) durable.page_scn_lsn = 82; durable.page_checksum = UINT32_C(0x12345678); durable.source_proof_crc32c = UINT32_C(0x87654321); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_durable_proof_exact( - &durable, &snapshot), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_durable_proof_exact(&durable, &snapshot), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(snapshot.phase, RESOURCE_X_MASTER_GRANT_COMMITTED); UT_ASSERT(cluster_pcm_lock_resource_x_s_barrier_active_exact(&tag)); - settlement = make_resource_x_master_frame( - RESOURCE_X_WIRE_INSTALL_SETTLEMENT, tag, 1, 1); + settlement = make_resource_x_master_frame(RESOURCE_X_WIRE_INSTALL_SETTLEMENT, tag, 1, 1); settlement.common.ordered_lane = 0; settlement.common.outcome = RESOURCE_X_OUTCOME_OK; settlement.common.authority_generation = 2; @@ -3435,17 +3279,13 @@ UT_TEST(test_resource_x_native_head_is_exact_s_admission_barrier) settlement.body.install_settlement.requester_target_generation = 41; settlement.body.install_settlement.page_scn_lsn = 82; settlement.body.install_settlement.page_checksum = UINT32_C(0x12345678); - settlement.body.install_settlement.source_proof_crc32c - = UINT32_C(0x87654321); + settlement.body.install_settlement.source_proof_crc32c = UINT32_C(0x87654321); settlement.body.install_settlement.installed_mode = PCM_STATE_X; - settlement.body.install_settlement.requester_role - = RESOURCE_X_REQUESTER_ROLE_ACQUIRER; - settlement.body.install_settlement.terminal_outcome - = RESOURCE_X_OUTCOME_OK; - settlement.body.install_settlement.terminal_state - = RESOURCE_X_SETTLEMENT_TERMINAL_INSTALLED; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_install_settlement_exact( - &settlement, 1, &snapshot), RESOURCE_X_APPLY_APPLIED); + settlement.body.install_settlement.requester_role = RESOURCE_X_REQUESTER_ROLE_ACQUIRER; + settlement.body.install_settlement.terminal_outcome = RESOURCE_X_OUTCOME_OK; + settlement.body.install_settlement.terminal_state = RESOURCE_X_SETTLEMENT_TERMINAL_INSTALLED; + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_install_settlement_exact(&settlement, 1, &snapshot), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(snapshot.phase, RESOURCE_X_MASTER_SETTLED); UT_ASSERT(!cluster_pcm_lock_resource_x_s_barrier_active_exact(&tag)); } @@ -3466,20 +3306,18 @@ UT_TEST(test_resource_x_bootstrap_receipt_replays_and_consumes_exactly) RESOURCE_X_APPLY_APPLIED); request = make_resource_x_bootstrap_request(tag, 1); UT_ASSERT(!cluster_pcm_lock_resource_x_s_barrier_active(&tag)); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_bootstrap_request_exact( - &request, 1, 61, 77, 31, 71, &ack), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ( + cluster_pcm_lock_resource_x_bootstrap_request_exact(&request, 1, 61, 77, 31, 71, &ack), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT(cluster_pcm_lock_resource_x_s_barrier_active(&tag)); UT_ASSERT_EQ(ack.kind, RESOURCE_X_WIRE_PREASSERT_BOOTSTRAP); UT_ASSERT(resource_x_assertion_equal(&ack.common.logical_assertion, - &request.common.logical_assertion)); + &request.common.logical_assertion)); UT_ASSERT_EQ(ack.common.base_authority_generation, UINT64_C(1)); UT_ASSERT_EQ(ack.common.authority_generation, UINT64_C(0)); - UT_ASSERT_EQ(ack.common.resource_formation, - request.common.resource_formation); - UT_ASSERT_EQ(ack.common.master_session_incarnation, - request.common.master_session_incarnation); - UT_ASSERT_EQ(ack.common.assertion_sequence, - request.common.assertion_sequence); + UT_ASSERT_EQ(ack.common.resource_formation, request.common.resource_formation); + UT_ASSERT_EQ(ack.common.master_session_incarnation, request.common.master_session_incarnation); + UT_ASSERT_EQ(ack.common.assertion_sequence, request.common.assertion_sequence); UT_ASSERT_EQ(ack.common.sender_connection_generation, UINT32_C(71)); UT_ASSERT_EQ(ack.common.outcome, RESOURCE_X_OUTCOME_OK); /* Already admitted read/proof/ASSERT work survives the new-work seal. */ @@ -3487,45 +3325,45 @@ UT_TEST(test_resource_x_bootstrap_receipt_replays_and_consumes_exactly) stop_new_work_calls = 0; memset(&replay_ack, 0, sizeof(replay_ack)); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_bootstrap_request_exact( - &request, 1, 61, 77, 31, 71, &replay_ack), - RESOURCE_X_APPLY_DUPLICATE); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_bootstrap_request_exact(&request, 1, 61, 77, 31, 71, + &replay_ack), + RESOURCE_X_APPLY_DUPLICATE); UT_ASSERT(memcmp(&ack, &replay_ack, sizeof(ack)) == 0); assertion = ack; assertion.kind = RESOURCE_X_WIRE_ASSERT_X; assertion.common.sender_connection_generation = 51; - assertion.common.authority_generation - = assertion.common.base_authority_generation; + assertion.common.authority_generation = assertion.common.base_authority_generation; assertion.common.outcome = RESOURCE_X_OUTCOME_NONE; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_bootstrapped_exact( - &assertion, 1, 61, 77, 31, 71, &snapshot), - RESOURCE_X_APPLY_APPLIED); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_bootstrapped_exact( - &assertion, 1, 61, 77, 31, 71, &snapshot), - RESOURCE_X_APPLY_DUPLICATE); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_bootstrapped_exact(&assertion, 1, 61, 77, 31, + 71, &snapshot), + RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_bootstrapped_exact(&assertion, 1, 61, 77, 31, + 71, &snapshot), + RESOURCE_X_APPLY_DUPLICATE); mutated = assertion; mutated.common.observed_mode = PCM_STATE_S; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_bootstrapped_exact( - &mutated, 1, 61, 77, 31, 71, &snapshot), - RESOURCE_X_APPLY_INVALID); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_bootstrapped_exact(&mutated, 1, 61, 77, 31, 71, + &snapshot), + RESOURCE_X_APPLY_INVALID); mutated = assertion; mutated.common.source_candidate = 1; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_bootstrapped_exact( - &mutated, 1, 61, 77, 31, 71, &snapshot), - RESOURCE_X_APPLY_INVALID); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_bootstrapped_exact(&mutated, 1, 61, 77, 31, 71, + &snapshot), + RESOURCE_X_APPLY_INVALID); mutated = assertion; mutated.common.ordered_lane = 1; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_bootstrapped_exact( - &mutated, 1, 61, 77, 31, 71, &snapshot), - RESOURCE_X_APPLY_INVALID); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_bootstrapped_exact(&mutated, 1, 61, 77, 31, 71, + &snapshot), + RESOURCE_X_APPLY_INVALID); mutated = assertion; mutated.payload_bytes--; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_bootstrapped_exact( - &mutated, 1, 61, 77, 31, 71, &snapshot), - RESOURCE_X_APPLY_INVALID); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_bootstrap_request_exact( - &request, 1, 61, 77, 31, 71, &replay_ack), RESOURCE_X_APPLY_STALE); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_bootstrapped_exact(&mutated, 1, 61, 77, 31, 71, + &snapshot), + RESOURCE_X_APPLY_INVALID); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_bootstrap_request_exact(&request, 1, 61, 77, 31, 71, + &replay_ack), + RESOURCE_X_APPLY_STALE); UT_ASSERT_EQ(stop_new_work_calls, 0); } @@ -3628,49 +3466,52 @@ UT_TEST(test_resource_x_bootstrap_receipt_drift_invalidates_but_keeps_floor) reset_fake_pcm_runtime(4); cluster_node_id = 0; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), - RESOURCE_X_APPLY_APPLIED); + RESOURCE_X_APPLY_APPLIED); request = make_resource_x_bootstrap_request(tag, 1); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_bootstrap_request_exact( - &request, 1, 61, 77, 31, 71, &ack), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ( + cluster_pcm_lock_resource_x_bootstrap_request_exact(&request, 1, 61, 77, 31, 71, &ack), + RESOURCE_X_APPLY_APPLIED); /* The requester sender coordinate changed independently of the unchanged * master-receiver ingress coordinate. The old binding is invalidated, * but the exact attempt cannot be reused. */ - different_sender = make_resource_x_bootstrap_request_values( - tag, 1, 17, 31, 41, 52); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_bootstrap_request_exact( - &different_sender, 1, 61, 77, 31, 71, &ack), + different_sender = make_resource_x_bootstrap_request_values(tag, 1, 17, 31, 41, 52); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_bootstrap_request_exact(&different_sender, 1, 61, 77, + 31, 71, &ack), + RESOURCE_X_APPLY_STALE); + UT_ASSERT_EQ( + cluster_pcm_lock_resource_x_bootstrap_request_exact(&request, 1, 61, 77, 31, 71, &ack), RESOURCE_X_APPLY_STALE); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_bootstrap_request_exact( - &request, 1, 61, 77, 31, 71, &ack), RESOURCE_X_APPLY_STALE); - higher = make_resource_x_bootstrap_request_values( - tag, 1, 17, 31, 42, 52); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_bootstrap_request_exact( - &higher, 1, 61, 77, 31, 72, &ack), RESOURCE_X_APPLY_APPLIED); + higher = make_resource_x_bootstrap_request_values(tag, 1, 17, 31, 42, 52); + UT_ASSERT_EQ( + cluster_pcm_lock_resource_x_bootstrap_request_exact(&higher, 1, 61, 77, 31, 72, &ack), + RESOURCE_X_APPLY_APPLIED); assertion = ack; assertion.kind = RESOURCE_X_WIRE_ASSERT_X; assertion.common.sender_connection_generation = 52; - assertion.common.authority_generation - = assertion.common.base_authority_generation; + assertion.common.authority_generation = assertion.common.base_authority_generation; assertion.common.outcome = RESOURCE_X_OUTCOME_NONE; /* An R4 record-generation change destroys the receipt. Returning to the * old value cannot resurrect it, and no canonical ASSERT was created. */ - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_bootstrapped_exact( - &assertion, 1, 61, 78, 31, 72, &snapshot), RESOURCE_X_APPLY_STALE); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_bootstrapped_exact( - &assertion, 1, 61, 77, 31, 72, &snapshot), RESOURCE_X_APPLY_STALE); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_master_snapshot_exact( - &higher.common.logical_assertion, &snapshot), - RESOURCE_X_APPLY_NOT_FOUND); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_bootstrapped_exact(&assertion, 1, 61, 78, 31, + 72, &snapshot), + RESOURCE_X_APPLY_STALE); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_bootstrapped_exact(&assertion, 1, 61, 77, 31, + 72, &snapshot), + RESOURCE_X_APPLY_STALE); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_master_snapshot_exact(&higher.common.logical_assertion, + &snapshot), + RESOURCE_X_APPLY_NOT_FOUND); - higher = make_resource_x_bootstrap_request_values( - tag, 1, 17, 31, 43, 52); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_bootstrap_request_exact( - &higher, 1, 61, 78, 31, 72, &ack), RESOURCE_X_APPLY_APPLIED); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_bootstrap_request_exact( - &request, 1, 61, 78, 31, 72, &ack), RESOURCE_X_APPLY_STALE); + higher = make_resource_x_bootstrap_request_values(tag, 1, 17, 31, 43, 52); + UT_ASSERT_EQ( + cluster_pcm_lock_resource_x_bootstrap_request_exact(&higher, 1, 61, 78, 31, 72, &ack), + RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ( + cluster_pcm_lock_resource_x_bootstrap_request_exact(&request, 1, 61, 78, 31, 72, &ack), + RESOURCE_X_APPLY_STALE); } UT_TEST(test_resource_x_bootstrap_terminal_retire_clears_binding_not_floor) @@ -3689,20 +3530,19 @@ UT_TEST(test_resource_x_bootstrap_terminal_retire_clears_binding_not_floor) reset_fake_pcm_runtime(4); cluster_node_id = 0; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), + RESOURCE_X_APPLY_APPLIED); + request = make_resource_x_bootstrap_request_values(tag, 3, 17, 31, 41, 51); + UT_ASSERT_EQ( + cluster_pcm_lock_resource_x_bootstrap_request_exact(&request, 3, 61, 77, 31, 71, &ack), RESOURCE_X_APPLY_APPLIED); - request = make_resource_x_bootstrap_request_values( - tag, 3, 17, 31, 41, 51); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_bootstrap_request_exact( - &request, 3, 61, 77, 31, 71, &ack), RESOURCE_X_APPLY_APPLIED); assertion = ack; assertion.kind = RESOURCE_X_WIRE_ASSERT_X; assertion.common.sender_connection_generation = 51; - assertion.common.authority_generation - = assertion.common.base_authority_generation; + assertion.common.authority_generation = assertion.common.base_authority_generation; assertion.common.outcome = RESOURCE_X_OUTCOME_NONE; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_bootstrapped_exact( - &assertion, 3, 61, 77, 31, 71, &snapshot), - RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_bootstrapped_exact(&assertion, 3, 61, 77, 31, + 71, &snapshot), + RESOURCE_X_APPLY_APPLIED); memset(&durable, 0, sizeof(durable)); durable.assertion = assertion.common.logical_assertion; @@ -3714,18 +3554,17 @@ UT_TEST(test_resource_x_bootstrap_terminal_retire_clears_binding_not_floor) durable.page_scn_lsn = 82; durable.page_checksum = UINT32_C(0x12345678); durable.source_proof_crc32c = UINT32_C(0x87654321); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_durable_proof_exact( - &durable, &snapshot), RESOURCE_X_APPLY_APPLIED); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_grant_intent_snapshot_exact( - &assertion.common.logical_assertion, &grant_intent, grant_bytes, - sizeof(grant_bytes)), RESOURCE_X_APPLY_APPLIED); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_grant_intent_stage_exact( - &grant_intent, 101), RESOURCE_X_INTENT_STAGED); - UT_ASSERT(cluster_pcm_lock_resource_x_grant_intent_complete_exact( - &grant_intent)); - - settlement = make_resource_x_master_frame( - RESOURCE_X_WIRE_INSTALL_SETTLEMENT, tag, 3, 3); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_durable_proof_exact(&durable, &snapshot), + RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ( + cluster_pcm_lock_resource_x_grant_intent_snapshot_exact( + &assertion.common.logical_assertion, &grant_intent, grant_bytes, sizeof(grant_bytes)), + RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_grant_intent_stage_exact(&grant_intent, 101), + RESOURCE_X_INTENT_STAGED); + UT_ASSERT(cluster_pcm_lock_resource_x_grant_intent_complete_exact(&grant_intent)); + + settlement = make_resource_x_master_frame(RESOURCE_X_WIRE_INSTALL_SETTLEMENT, tag, 3, 3); settlement.common.ordered_lane = 0; settlement.common.outcome = RESOURCE_X_OUTCOME_OK; settlement.common.authority_generation = 2; @@ -3734,29 +3573,24 @@ UT_TEST(test_resource_x_bootstrap_terminal_retire_clears_binding_not_floor) settlement.body.install_settlement.requester_connection_generation = 91; settlement.body.install_settlement.requester_target_generation = 41; settlement.body.install_settlement.page_scn_lsn = 82; - settlement.body.install_settlement.page_checksum - = UINT32_C(0x12345678); - settlement.body.install_settlement.source_proof_crc32c - = UINT32_C(0x87654321); + settlement.body.install_settlement.page_checksum = UINT32_C(0x12345678); + settlement.body.install_settlement.source_proof_crc32c = UINT32_C(0x87654321); settlement.body.install_settlement.installed_mode = PCM_STATE_X; - settlement.body.install_settlement.requester_role - = RESOURCE_X_REQUESTER_ROLE_ACQUIRER; - settlement.body.install_settlement.terminal_outcome - = RESOURCE_X_OUTCOME_OK; - settlement.body.install_settlement.terminal_state - = RESOURCE_X_SETTLEMENT_TERMINAL_INSTALLED; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_install_settlement_exact( - &settlement, 3, &snapshot), RESOURCE_X_APPLY_APPLIED); + settlement.body.install_settlement.requester_role = RESOURCE_X_REQUESTER_ROLE_ACQUIRER; + settlement.body.install_settlement.terminal_outcome = RESOURCE_X_OUTCOME_OK; + settlement.body.install_settlement.terminal_state = RESOURCE_X_SETTLEMENT_TERMINAL_INSTALLED; + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_install_settlement_exact(&settlement, 3, &snapshot), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_settled_retire_exact( - &assertion.common.logical_assertion, 41, &snapshot), - RESOURCE_X_APPLY_APPLIED); + &assertion.common.logical_assertion, 41, &snapshot), + RESOURCE_X_APPLY_APPLIED); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_bootstrap_request_exact( - &request, 3, 61, 77, 31, 71, &ack), RESOURCE_X_APPLY_STALE); - next_request = make_resource_x_bootstrap_request_values( - tag, 3, 17, 31, 42, 51); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_bootstrap_request_exact( - &next_request, 3, 61, 77, 31, 71, &ack), + UT_ASSERT_EQ( + cluster_pcm_lock_resource_x_bootstrap_request_exact(&request, 3, 61, 77, 31, 71, &ack), + RESOURCE_X_APPLY_STALE); + next_request = make_resource_x_bootstrap_request_values(tag, 3, 17, 31, 42, 51); + UT_ASSERT_EQ( + cluster_pcm_lock_resource_x_bootstrap_request_exact(&next_request, 3, 61, 77, 31, 71, &ack), RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(ack.common.base_authority_generation, UINT64_C(2)); } @@ -3781,25 +3615,22 @@ UT_TEST(test_resource_x_bootstrap_dispatches_one_current_base_at_a_time) reset_fake_pcm_runtime(4); cluster_node_id = 0; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), - RESOURCE_X_APPLY_APPLIED); - first_request = make_resource_x_bootstrap_request_values( - tag, 1, 17, 31, 41, 51); - second_request = make_resource_x_bootstrap_request_values( - tag, 2, 17, 31, 41, 52); - third_request = make_resource_x_bootstrap_request_values( - tag, 3, 17, 31, 41, 53); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_bootstrap_request_exact( - &first_request, 1, 61, 77, 31, 71, &first_ack), - RESOURCE_X_APPLY_APPLIED); + RESOURCE_X_APPLY_APPLIED); + first_request = make_resource_x_bootstrap_request_values(tag, 1, 17, 31, 41, 51); + second_request = make_resource_x_bootstrap_request_values(tag, 2, 17, 31, 41, 52); + third_request = make_resource_x_bootstrap_request_values(tag, 3, 17, 31, 41, 53); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_bootstrap_request_exact(&first_request, 1, 61, 77, 31, + 71, &first_ack), + RESOURCE_X_APPLY_APPLIED); /* A second requester must not freeze the same current base while the * first receipt can still become canonical authority. Its exact identity * becomes the bounded next admission while ordinary R7 drives replay. */ memset(&second_ack, 0xa5, sizeof(second_ack)); memset(&zero_ack, 0, sizeof(zero_ack)); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_bootstrap_request_exact( - &second_request, 2, 62, 77, 31, 72, &second_ack), - RESOURCE_X_APPLY_BAD_STATE); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_bootstrap_request_exact(&second_request, 2, 62, 77, 31, + 72, &second_ack), + RESOURCE_X_APPLY_BAD_STATE); UT_ASSERT(memcmp(&second_ack, &zero_ack, sizeof(second_ack)) == 0); /* The first otherwise-admissible rejection owns the single exact next @@ -3807,31 +3638,30 @@ UT_TEST(test_resource_x_bootstrap_dispatches_one_current_base_at_a_time) stop_new_work_allowed = false; stop_new_work_calls = 0; memset(&second_ack, 0xa5, sizeof(second_ack)); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_bootstrap_request_exact( - &third_request, 3, 63, 77, 31, 73, &second_ack), - RESOURCE_X_APPLY_BAD_STATE); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_bootstrap_request_exact(&third_request, 3, 63, 77, 31, + 73, &second_ack), + RESOURCE_X_APPLY_BAD_STATE); UT_ASSERT(memcmp(&second_ack, &zero_ack, sizeof(second_ack)) == 0); memset(&replay_ack, 0, sizeof(replay_ack)); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_bootstrap_request_exact( - &first_request, 1, 61, 77, 31, 71, &replay_ack), - RESOURCE_X_APPLY_DUPLICATE); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_bootstrap_request_exact(&first_request, 1, 61, 77, 31, + 71, &replay_ack), + RESOURCE_X_APPLY_DUPLICATE); UT_ASSERT(memcmp(&first_ack, &replay_ack, sizeof(first_ack)) == 0); assertion = first_ack; assertion.kind = RESOURCE_X_WIRE_ASSERT_X; assertion.common.sender_connection_generation = 51; - assertion.common.authority_generation - = assertion.common.base_authority_generation; + assertion.common.authority_generation = assertion.common.base_authority_generation; assertion.common.outcome = RESOURCE_X_OUTCOME_NONE; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_bootstrapped_exact( - &assertion, 1, 61, 77, 31, 71, &snapshot), - RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_bootstrapped_exact(&assertion, 1, 61, 77, 31, + 71, &snapshot), + RESOURCE_X_APPLY_APPLIED); memset(&second_ack, 0xa5, sizeof(second_ack)); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_bootstrap_request_exact( - &second_request, 2, 62, 77, 31, 72, &second_ack), - RESOURCE_X_APPLY_BAD_STATE); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_bootstrap_request_exact(&second_request, 2, 62, 77, 31, + 72, &second_ack), + RESOURCE_X_APPLY_BAD_STATE); UT_ASSERT(memcmp(&second_ack, &zero_ack, sizeof(second_ack)) == 0); memset(&durable, 0, sizeof(durable)); @@ -3844,18 +3674,17 @@ UT_TEST(test_resource_x_bootstrap_dispatches_one_current_base_at_a_time) durable.page_scn_lsn = 82; durable.page_checksum = UINT32_C(0x12345678); durable.source_proof_crc32c = UINT32_C(0x87654321); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_durable_proof_exact( - &durable, &snapshot), RESOURCE_X_APPLY_APPLIED); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_grant_intent_snapshot_exact( - &assertion.common.logical_assertion, &grant_intent, grant_bytes, - sizeof(grant_bytes)), RESOURCE_X_APPLY_APPLIED); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_grant_intent_stage_exact( - &grant_intent, 101), RESOURCE_X_INTENT_STAGED); - UT_ASSERT(cluster_pcm_lock_resource_x_grant_intent_complete_exact( - &grant_intent)); - - settlement = make_resource_x_master_frame( - RESOURCE_X_WIRE_INSTALL_SETTLEMENT, tag, 1, 1); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_durable_proof_exact(&durable, &snapshot), + RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ( + cluster_pcm_lock_resource_x_grant_intent_snapshot_exact( + &assertion.common.logical_assertion, &grant_intent, grant_bytes, sizeof(grant_bytes)), + RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_grant_intent_stage_exact(&grant_intent, 101), + RESOURCE_X_INTENT_STAGED); + UT_ASSERT(cluster_pcm_lock_resource_x_grant_intent_complete_exact(&grant_intent)); + + settlement = make_resource_x_master_frame(RESOURCE_X_WIRE_INSTALL_SETTLEMENT, tag, 1, 1); settlement.common.ordered_lane = 0; settlement.common.outcome = RESOURCE_X_OUTCOME_OK; settlement.common.authority_generation = 2; @@ -3864,35 +3693,30 @@ UT_TEST(test_resource_x_bootstrap_dispatches_one_current_base_at_a_time) settlement.body.install_settlement.requester_connection_generation = 91; settlement.body.install_settlement.requester_target_generation = 41; settlement.body.install_settlement.page_scn_lsn = 82; - settlement.body.install_settlement.page_checksum - = UINT32_C(0x12345678); - settlement.body.install_settlement.source_proof_crc32c - = UINT32_C(0x87654321); + settlement.body.install_settlement.page_checksum = UINT32_C(0x12345678); + settlement.body.install_settlement.source_proof_crc32c = UINT32_C(0x87654321); settlement.body.install_settlement.installed_mode = PCM_STATE_X; - settlement.body.install_settlement.requester_role - = RESOURCE_X_REQUESTER_ROLE_ACQUIRER; - settlement.body.install_settlement.terminal_outcome - = RESOURCE_X_OUTCOME_OK; - settlement.body.install_settlement.terminal_state - = RESOURCE_X_SETTLEMENT_TERMINAL_INSTALLED; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_install_settlement_exact( - &settlement, 1, &snapshot), RESOURCE_X_APPLY_APPLIED); + settlement.body.install_settlement.requester_role = RESOURCE_X_REQUESTER_ROLE_ACQUIRER; + settlement.body.install_settlement.terminal_outcome = RESOURCE_X_OUTCOME_OK; + settlement.body.install_settlement.terminal_state = RESOURCE_X_SETTLEMENT_TERMINAL_INSTALLED; + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_install_settlement_exact(&settlement, 1, &snapshot), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_settled_retire_exact( - &assertion.common.logical_assertion, 41, &snapshot), - RESOURCE_X_APPLY_APPLIED); + &assertion.common.logical_assertion, 41, &snapshot), + RESOURCE_X_APPLY_APPLIED); /* Retirement does not let a fresh contender bypass the retained exact * successor. The priority never froze base 1: only the exact successor * replay may now sample current base 2 and create an ordinary receipt. */ memset(&replay_ack, 0xa5, sizeof(replay_ack)); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_bootstrap_request_exact( - &third_request, 3, 63, 77, 31, 73, &replay_ack), - RESOURCE_X_APPLY_BAD_STATE); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_bootstrap_request_exact(&third_request, 3, 63, 77, 31, + 73, &replay_ack), + RESOURCE_X_APPLY_BAD_STATE); UT_ASSERT(memcmp(&replay_ack, &zero_ack, sizeof(replay_ack)) == 0); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_bootstrap_request_exact( - &second_request, 2, 62, 77, 31, 72, &second_ack), - RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_bootstrap_request_exact(&second_request, 2, 62, 77, 31, + 72, &second_ack), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(second_ack.common.base_authority_generation, UINT64_C(2)); UT_ASSERT_EQ(stop_new_work_calls, 0); } @@ -3915,50 +3739,42 @@ UT_TEST(test_resource_x_bootstrap_r8_clears_old_binding_not_attempt_floor) reset_fake_pcm_runtime(4); cluster_node_id = 0; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), + RESOURCE_X_APPLY_APPLIED); + old_request = make_resource_x_bootstrap_request_values(tag, 1, 17, 31, 41, 51); + UT_ASSERT_EQ( + cluster_pcm_lock_resource_x_bootstrap_request_exact(&old_request, 1, 61, 77, 31, 71, &ack), RESOURCE_X_APPLY_APPLIED); - old_request = make_resource_x_bootstrap_request_values( - tag, 1, 17, 31, 41, 51); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_bootstrap_request_exact( - &old_request, 1, 61, 77, 31, 71, &ack), - RESOURCE_X_APPLY_APPLIED); - waiting_request = make_resource_x_bootstrap_request_values( - tag, 2, 17, 31, 41, 53); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_bootstrap_request_exact( - &waiting_request, 2, 63, 77, 31, 71, &ack), - RESOURCE_X_APPLY_BAD_STATE); + waiting_request = make_resource_x_bootstrap_request_values(tag, 2, 17, 31, 41, 53); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_bootstrap_request_exact(&waiting_request, 2, 63, 77, + 31, 71, &ack), + RESOURCE_X_APPLY_BAD_STATE); UT_ASSERT(resource_x_assertion_init(&tag, 0, &round_assertion)); round_action = cluster_pcm_lock_resource_x_bootstrap_round_step_exact( &round_assertion, 0, 17, 31, 77, 51, 61, UINT64_C(1000), (UINT64_C(1000)) - (UINT64_C(100)), UINT64_C(100), UINT64_C(50), false, 0, &round_dispatch, &terminal_ref); - UT_ASSERT_EQ(round_action, - RESOURCE_X_BOOTSTRAP_ROUND_DISPATCH_REQUEST); + UT_ASSERT_EQ(round_action, RESOURCE_X_BOOTSTRAP_ROUND_DISPATCH_REQUEST); UT_ASSERT_EQ(round_dispatch.common.assertion_sequence, UINT64_C(1)); broadcast_before = fake_cv_broadcast_count; UT_ASSERT(cluster_resource_x_reconfig_freeze(17, 18, &token)); - UT_ASSERT_EQ(cluster_resource_x_reconfig_sweep(&token, 4, &batch), - RESOURCE_X_RECONFIG_MORE); + UT_ASSERT_EQ(cluster_resource_x_reconfig_sweep(&token, 4, &batch), RESOURCE_X_RECONFIG_MORE); UT_ASSERT_EQ(fake_cv_broadcast_count, broadcast_before + 1); - UT_ASSERT_EQ(cluster_resource_x_reconfig_sweep(&token, 4, &batch), - RESOURCE_X_RECONFIG_DONE); + UT_ASSERT_EQ(cluster_resource_x_reconfig_sweep(&token, 4, &batch), RESOURCE_X_RECONFIG_DONE); UT_ASSERT(cluster_resource_x_reconfig_thaw_exact(&token)); - new_request = make_resource_x_bootstrap_request_values( - tag, 1, 18, 32, 41, 52); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_bootstrap_request_exact( - &new_request, 1, 62, 78, 32, 72, &ack), + new_request = make_resource_x_bootstrap_request_values(tag, 1, 18, 32, 41, 52); + UT_ASSERT_EQ( + cluster_pcm_lock_resource_x_bootstrap_request_exact(&new_request, 1, 62, 78, 32, 72, &ack), RESOURCE_X_APPLY_STALE); - new_request = make_resource_x_bootstrap_request_values( - tag, 1, 18, 32, 42, 52); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_bootstrap_request_exact( - &new_request, 1, 62, 78, 32, 72, &ack), + new_request = make_resource_x_bootstrap_request_values(tag, 1, 18, 32, 42, 52); + UT_ASSERT_EQ( + cluster_pcm_lock_resource_x_bootstrap_request_exact(&new_request, 1, 62, 78, 32, 72, &ack), RESOURCE_X_APPLY_APPLIED); round_action = cluster_pcm_lock_resource_x_bootstrap_round_step_exact( &round_assertion, 0, 18, 32, 78, 52, 62, UINT64_C(2000), (UINT64_C(2000)) - (UINT64_C(200)), UINT64_C(200), UINT64_C(50), false, 0, &round_dispatch, &terminal_ref); - UT_ASSERT_EQ(round_action, - RESOURCE_X_BOOTSTRAP_ROUND_DISPATCH_REQUEST); + UT_ASSERT_EQ(round_action, RESOURCE_X_BOOTSTRAP_ROUND_DISPATCH_REQUEST); UT_ASSERT_EQ(round_dispatch.common.assertion_sequence, UINT64_C(2)); } @@ -3983,7 +3799,7 @@ UT_TEST(test_resource_x_bootstrap_round_fans_in_and_retries_same_attempt) fake_pcm_clock_us = 200; cluster_node_id = 1; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), - RESOURCE_X_APPLY_APPLIED); + RESOURCE_X_APPLY_APPLIED); UT_ASSERT(resource_x_assertion_init(&tag, 1, &assertion)); for (caller = 0; caller < 4; caller++) { @@ -3991,21 +3807,15 @@ UT_TEST(test_resource_x_bootstrap_round_fans_in_and_retries_same_attempt) &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(1000), (UINT64_C(1000)) - (UINT64_C(100)), UINT64_C(100), UINT64_C(50), false, 0, caller == 0 ? &first_dispatch : &retry_dispatch, &terminal_ref); - UT_ASSERT_EQ(action, - caller == 0 - ? RESOURCE_X_BOOTSTRAP_ROUND_DISPATCH_REQUEST - : RESOURCE_X_BOOTSTRAP_ROUND_WAIT); + UT_ASSERT_EQ(action, caller == 0 ? RESOURCE_X_BOOTSTRAP_ROUND_DISPATCH_REQUEST + : RESOURCE_X_BOOTSTRAP_ROUND_WAIT); } - UT_ASSERT_EQ(first_dispatch.kind, - RESOURCE_X_WIRE_PREASSERT_BOOTSTRAP); + UT_ASSERT_EQ(first_dispatch.kind, RESOURCE_X_WIRE_PREASSERT_BOOTSTRAP); UT_ASSERT_EQ(first_dispatch.common.assertion_sequence, UINT64_C(1)); UT_ASSERT_EQ(first_dispatch.common.resource_formation, UINT64_C(17)); - UT_ASSERT_EQ(first_dispatch.common.master_session_incarnation, - UINT64_C(31)); - UT_ASSERT_EQ(first_dispatch.common.sender_connection_generation, - UINT32_C(51)); - UT_ASSERT_EQ(first_dispatch.common.base_authority_generation, - UINT64_C(0)); + UT_ASSERT_EQ(first_dispatch.common.master_session_incarnation, UINT64_C(31)); + UT_ASSERT_EQ(first_dispatch.common.sender_connection_generation, UINT32_C(51)); + UT_ASSERT_EQ(first_dispatch.common.base_authority_generation, UINT64_C(0)); UT_ASSERT_EQ(first_dispatch.common.authority_generation, UINT64_C(0)); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_bootstrap_round_wait_exact( &assertion, 0, 17, 31, 78, 51, 61, UINT64_C(50), UINT64_MAX - 1, 1), @@ -4021,21 +3831,15 @@ UT_TEST(test_resource_x_bootstrap_round_fans_in_and_retries_same_attempt) action = cluster_pcm_lock_resource_x_bootstrap_round_step_exact( &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(2000), (UINT64_C(2000)) - (UINT64_C(150)), UINT64_C(150), UINT64_C(50), false, 0, &retry_dispatch, &terminal_ref); - UT_ASSERT_EQ(action, - RESOURCE_X_BOOTSTRAP_ROUND_DISPATCH_REQUEST); - UT_ASSERT(memcmp(&first_dispatch, &retry_dispatch, - sizeof(first_dispatch)) == 0); + UT_ASSERT_EQ(action, RESOURCE_X_BOOTSTRAP_ROUND_DISPATCH_REQUEST); + UT_ASSERT(memcmp(&first_dispatch, &retry_dispatch, sizeof(first_dispatch)) == 0); - ack = make_resource_x_bootstrap_ack_values( - &first_dispatch, UINT64_C(9), UINT32_C(71)); + ack = make_resource_x_bootstrap_ack_values(&first_dispatch, UINT64_C(9), UINT32_C(71)); for (caller = 0; caller < 4; caller++) { action = cluster_pcm_lock_resource_x_bootstrap_round_accept_ack_exact( - &ack, 0, 61, 77, UINT64_C(160), - caller == 0 ? &first_assertion : &retry_assertion); - UT_ASSERT_EQ(action, - caller == 0 - ? RESOURCE_X_BOOTSTRAP_ROUND_DISPATCH_ASSERT - : RESOURCE_X_BOOTSTRAP_ROUND_WAIT); + &ack, 0, 61, 77, UINT64_C(160), caller == 0 ? &first_assertion : &retry_assertion); + UT_ASSERT_EQ(action, caller == 0 ? RESOURCE_X_BOOTSTRAP_ROUND_DISPATCH_ASSERT + : RESOURCE_X_BOOTSTRAP_ROUND_WAIT); } /* The caller samples time before taking entry_lock. An exact ACK may * advance last_dispatch under that lock between the sample and the step; @@ -4045,12 +3849,10 @@ UT_TEST(test_resource_x_bootstrap_round_fans_in_and_retries_same_attempt) UINT64_C(159), UINT64_C(50), false, 0, &retry_assertion, &terminal_ref); UT_ASSERT_EQ(action, RESOURCE_X_BOOTSTRAP_ROUND_WAIT); UT_ASSERT_EQ(first_assertion.kind, RESOURCE_X_WIRE_ASSERT_X); - UT_ASSERT_EQ(first_assertion.common.base_authority_generation, - UINT64_C(9)); + UT_ASSERT_EQ(first_assertion.common.base_authority_generation, UINT64_C(9)); UT_ASSERT_EQ(first_assertion.common.authority_generation, UINT64_C(9)); UT_ASSERT_EQ(first_assertion.common.assertion_sequence, UINT64_C(1)); - UT_ASSERT_EQ(first_assertion.common.sender_connection_generation, - UINT32_C(51)); + UT_ASSERT_EQ(first_assertion.common.sender_connection_generation, UINT32_C(51)); action = cluster_pcm_lock_resource_x_bootstrap_round_step_exact( &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(2000), (UINT64_C(2000)) - (UINT64_C(209)), @@ -4060,8 +3862,7 @@ UT_TEST(test_resource_x_bootstrap_round_fans_in_and_retries_same_attempt) &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(2000), (UINT64_C(2000)) - (UINT64_C(210)), UINT64_C(210), UINT64_C(50), false, 0, &retry_assertion, &terminal_ref); UT_ASSERT_EQ(action, RESOURCE_X_BOOTSTRAP_ROUND_DISPATCH_ASSERT); - UT_ASSERT(memcmp(&first_assertion, &retry_assertion, - sizeof(first_assertion)) == 0); + UT_ASSERT(memcmp(&first_assertion, &retry_assertion, sizeof(first_assertion)) == 0); /* R9 T3 retires the active ledger but keeps node X cached. The same * requester round becomes the only complete ref cover for later local @@ -4069,27 +3870,24 @@ UT_TEST(test_resource_x_bootstrap_round_fans_in_and_retries_same_attempt) cluster_pcm_lock_acquire(tag, PCM_LOCK_MODE_X); expected_ref = make_resource_x_acquisition_ref(tag, 1, 17, 1); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_t1_grant_exact(&expected_ref), - RESOURCE_X_APPLY_APPLIED); + RESOURCE_X_APPLY_APPLIED); memset(&install, 0, sizeof(install)); install.ownership_generation = 91; install.writer_activation_token = 12; install.resource_x_activation_generation = 1; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_apply_exact( - &expected_ref, &install), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_apply_exact(&expected_ref, &install), + RESOURCE_X_APPLY_APPLIED); memset(&activation, 0, sizeof(activation)); activation.ownership_generation = 91; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_activate_exact( - &expected_ref, &activation), RESOURCE_X_APPLY_APPLIED); - UT_ASSERT_EQ( - cluster_pcm_lock_resource_x_bootstrap_round_publish_terminal_exact( - &expected_ref, 31, 77, 91, 10, UINT64_C(215)), - RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_activate_exact(&expected_ref, &activation), + RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_bootstrap_round_publish_terminal_exact( + &expected_ref, 31, 77, 91, 10, UINT64_C(215)), + RESOURCE_X_APPLY_APPLIED); memset(&failure_snapshot, 0, sizeof(failure_snapshot)); - UT_ASSERT_EQ( - cluster_pcm_lock_resource_x_bootstrap_round_failure_snapshot_exact( - &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50), - &failure_snapshot), - RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_bootstrap_round_failure_snapshot_exact( + &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50), &failure_snapshot), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(failure_snapshot.ref.acquisition_generation, UINT64_C(1)); UT_ASSERT_EQ(failure_snapshot.base_authority_generation, UINT64_C(9)); UT_ASSERT_EQ(failure_snapshot.authority_generation, UINT64_C(10)); @@ -4097,34 +3895,30 @@ UT_TEST(test_resource_x_bootstrap_round_fans_in_and_retries_same_attempt) UT_ASSERT_EQ(failure_snapshot.absolute_deadline_us, UINT64_C(1100)); UT_ASSERT_EQ(failure_snapshot.terminal, 1); memset(&failure_snapshot, 0xa5, sizeof(failure_snapshot)); - UT_ASSERT_EQ( - cluster_pcm_lock_resource_x_bootstrap_round_failure_snapshot_exact( - &assertion, 0, 17, 32, 77, 51, 61, UINT64_C(50), - &failure_snapshot), - RESOURCE_X_APPLY_STALE); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_bootstrap_round_failure_snapshot_exact( + &assertion, 0, 17, 32, 77, 51, 61, UINT64_C(50), &failure_snapshot), + RESOURCE_X_APPLY_STALE); UT_ASSERT_EQ(failure_snapshot.ref.acquisition_generation, UINT64_C(0)); - UT_ASSERT(cluster_pcm_lock_resource_x_bootstrap_round_cover_matches_exact( - &expected_ref, 31, 77, 91)); - UT_ASSERT(!cluster_pcm_lock_resource_x_bootstrap_round_cover_matches_exact( - &expected_ref, 32, 77, 91)); - UT_ASSERT(!cluster_pcm_lock_resource_x_bootstrap_round_cover_matches_exact( - &expected_ref, 31, 78, 91)); - UT_ASSERT(!cluster_pcm_lock_resource_x_bootstrap_round_cover_matches_exact( - &expected_ref, 31, 77, 92)); + UT_ASSERT( + cluster_pcm_lock_resource_x_bootstrap_round_cover_matches_exact(&expected_ref, 31, 77, 91)); + UT_ASSERT(!cluster_pcm_lock_resource_x_bootstrap_round_cover_matches_exact(&expected_ref, 32, + 77, 91)); + UT_ASSERT(!cluster_pcm_lock_resource_x_bootstrap_round_cover_matches_exact(&expected_ref, 31, + 78, 91)); + UT_ASSERT(!cluster_pcm_lock_resource_x_bootstrap_round_cover_matches_exact(&expected_ref, 31, + 77, 92)); action = cluster_pcm_lock_resource_x_bootstrap_round_step_exact( &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(2000), (UINT64_C(2000)) - (UINT64_C(220)), UINT64_C(220), UINT64_C(50), true, 91, &retry_assertion, &terminal_ref); UT_ASSERT_EQ(action, RESOURCE_X_BOOTSTRAP_ROUND_TERMINAL); - UT_ASSERT(memcmp(&terminal_ref, &expected_ref, - sizeof(terminal_ref)) == 0); + UT_ASSERT(memcmp(&terminal_ref, &expected_ref, sizeof(terminal_ref)) == 0); action = cluster_pcm_lock_resource_x_bootstrap_round_step_exact( &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(2000), (UINT64_C(2000)) - (UINT64_C(220)), UINT64_C(220), UINT64_C(50), true, 91, &retry_assertion, &terminal_ref); UT_ASSERT_EQ(action, RESOURCE_X_BOOTSTRAP_ROUND_TERMINAL); - UT_ASSERT(memcmp(&terminal_ref, &expected_ref, - sizeof(terminal_ref)) == 0); + UT_ASSERT(memcmp(&terminal_ref, &expected_ref, sizeof(terminal_ref)) == 0); memset(&terminal_ref, 0xff, sizeof(terminal_ref)); action = cluster_pcm_lock_resource_x_bootstrap_round_step_exact( @@ -4137,8 +3931,8 @@ UT_TEST(test_resource_x_bootstrap_round_fans_in_and_retries_same_attempt) * advances past the retained/retired floor. A mismatching follower cannot * clear that request, even if it presents the mismatch repeatedly. */ cluster_pcm_lock_release(tag); - UT_ASSERT(!cluster_pcm_lock_resource_x_bootstrap_round_cover_matches_exact( - &expected_ref, 31, 77, 91)); + UT_ASSERT(!cluster_pcm_lock_resource_x_bootstrap_round_cover_matches_exact(&expected_ref, 31, + 77, 91)); action = cluster_pcm_lock_resource_x_bootstrap_round_step_exact( &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(2000), (UINT64_C(2000)) - (UINT64_C(230)), UINT64_C(230), UINT64_C(50), false, 0, &retry_dispatch, &terminal_ref); @@ -4932,47 +4726,40 @@ UT_TEST(test_resource_x_requester_round_blocks_local_s_only_until_x_cached) reset_fake_pcm_runtime(4); cluster_node_id = 1; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), - RESOURCE_X_APPLY_APPLIED); + RESOURCE_X_APPLY_APPLIED); UT_ASSERT(resource_x_assertion_init(&tag, 1, &assertion)); - UT_ASSERT(!cluster_pcm_lock_resource_x_requester_s_barrier_active_exact( - &tag)); + UT_ASSERT(!cluster_pcm_lock_resource_x_requester_s_barrier_active_exact(&tag)); action = cluster_pcm_lock_resource_x_bootstrap_round_step_exact( &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(1000), (UINT64_C(1000)) - (UINT64_C(100)), UINT64_C(100), UINT64_C(50), false, 0, &request, &terminal_ref); - UT_ASSERT_EQ(action, - RESOURCE_X_BOOTSTRAP_ROUND_DISPATCH_REQUEST); - UT_ASSERT(cluster_pcm_lock_resource_x_requester_s_barrier_active_exact( - &tag)); + UT_ASSERT_EQ(action, RESOURCE_X_BOOTSTRAP_ROUND_DISPATCH_REQUEST); + UT_ASSERT(cluster_pcm_lock_resource_x_requester_s_barrier_active_exact(&tag)); - ack = make_resource_x_bootstrap_ack_values( - &request, UINT64_C(9), UINT32_C(71)); - action = cluster_pcm_lock_resource_x_bootstrap_round_accept_ack_exact( - &ack, 0, 61, 77, UINT64_C(150), &asserted); + ack = make_resource_x_bootstrap_ack_values(&request, UINT64_C(9), UINT32_C(71)); + action = cluster_pcm_lock_resource_x_bootstrap_round_accept_ack_exact(&ack, 0, 61, 77, + UINT64_C(150), &asserted); UT_ASSERT_EQ(action, RESOURCE_X_BOOTSTRAP_ROUND_DISPATCH_ASSERT); - UT_ASSERT(cluster_pcm_lock_resource_x_requester_s_barrier_active_exact( - &tag)); + UT_ASSERT(cluster_pcm_lock_resource_x_requester_s_barrier_active_exact(&tag)); cluster_pcm_lock_acquire(tag, PCM_LOCK_MODE_X); expected_ref = make_resource_x_acquisition_ref(tag, 1, 17, 1); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_t1_grant_exact(&expected_ref), - RESOURCE_X_APPLY_APPLIED); + RESOURCE_X_APPLY_APPLIED); memset(&install, 0, sizeof(install)); install.ownership_generation = 91; install.writer_activation_token = 12; install.resource_x_activation_generation = 1; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_apply_exact( - &expected_ref, &install), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_apply_exact(&expected_ref, &install), + RESOURCE_X_APPLY_APPLIED); memset(&activation, 0, sizeof(activation)); activation.ownership_generation = 91; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_activate_exact( - &expected_ref, &activation), RESOURCE_X_APPLY_APPLIED); - UT_ASSERT_EQ( - cluster_pcm_lock_resource_x_bootstrap_round_publish_terminal_exact( - &expected_ref, 31, 77, 91, 10, UINT64_C(160)), - RESOURCE_X_APPLY_APPLIED); - UT_ASSERT(!cluster_pcm_lock_resource_x_requester_s_barrier_active_exact( - &tag)); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_activate_exact(&expected_ref, &activation), + RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_bootstrap_round_publish_terminal_exact( + &expected_ref, 31, 77, 91, 10, UINT64_C(160)), + RESOURCE_X_APPLY_APPLIED); + UT_ASSERT(!cluster_pcm_lock_resource_x_requester_s_barrier_active_exact(&tag)); } UT_TEST(test_resource_x_bootstrap_threshold_keeps_same_acquisition) @@ -4992,15 +4779,14 @@ UT_TEST(test_resource_x_bootstrap_threshold_keeps_same_acquisition) reset_fake_pcm_runtime(4); cluster_node_id = 1; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), - RESOURCE_X_APPLY_APPLIED); + RESOURCE_X_APPLY_APPLIED); UT_ASSERT(resource_x_assertion_init(&tag, 1, &assertion)); action = cluster_pcm_lock_resource_x_bootstrap_round_step_exact( &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(1000), (UINT64_C(1000)) - (UINT64_C(100)), UINT64_C(100), UINT64_C(50), false, 0, &first_request, &terminal_ref); UT_ASSERT_EQ(action, RESOURCE_X_BOOTSTRAP_ROUND_DISPATCH_REQUEST); UT_ASSERT_EQ(first_request.common.assertion_sequence, UINT64_C(1)); - first_ack = make_resource_x_bootstrap_ack_values( - &first_request, UINT64_C(9), UINT32_C(71)); + first_ack = make_resource_x_bootstrap_ack_values(&first_request, UINT64_C(9), UINT32_C(71)); action = cluster_pcm_lock_resource_x_bootstrap_round_accept_ack_exact( &first_ack, 0, 61, 77, UINT64_C(150), &first_assertion); UT_ASSERT_EQ(action, RESOURCE_X_BOOTSTRAP_ROUND_DISPATCH_ASSERT); @@ -5040,7 +4826,7 @@ UT_TEST(test_resource_x_bootstrap_threshold_keeps_same_acquisition) reset_fake_pcm_runtime(4); cluster_node_id = 1; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), - RESOURCE_X_APPLY_APPLIED); + RESOURCE_X_APPLY_APPLIED); action = cluster_pcm_lock_resource_x_bootstrap_round_step_direct_init_exact( &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(1000), (UINT64_C(1000)) - (UINT64_C(100)), UINT64_C(100), UINT64_C(50), 0, 5, false, 0, &first_request, &terminal_ref); @@ -5060,28 +4846,24 @@ UT_TEST(test_resource_x_bootstrap_threshold_keeps_same_acquisition) cluster_node_id = 1; fake_gcs_master_node = 0; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), - RESOURCE_X_APPLY_APPLIED); + RESOURCE_X_APPLY_APPLIED); UT_ASSERT(resource_x_assertion_init(&tag, 1, &assertion)); action = cluster_pcm_lock_resource_x_bootstrap_round_step_exact( &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(1000), (UINT64_C(1000)) - (UINT64_C(100)), UINT64_C(100), UINT64_C(50), false, 0, &first_request, &terminal_ref); UT_ASSERT_EQ(action, RESOURCE_X_BOOTSTRAP_ROUND_DISPATCH_REQUEST); - first_ack = make_resource_x_bootstrap_ack_values( - &first_request, UINT64_C(9), UINT32_C(71)); + first_ack = make_resource_x_bootstrap_ack_values(&first_request, UINT64_C(9), UINT32_C(71)); action = cluster_pcm_lock_resource_x_bootstrap_round_accept_ack_exact( &first_ack, 0, 61, 77, UINT64_C(150), &first_assertion); UT_ASSERT_EQ(action, RESOURCE_X_BOOTSTRAP_ROUND_DISPATCH_ASSERT); - make_resource_x_remote_join_pair( - tag, 1, &retained_grant, &retained_image); - retarget_resource_x_remote_join_pair( - &retained_grant, &retained_image, UINT64_C(11), - first_assertion.common.assertion_sequence); + make_resource_x_remote_join_pair(tag, 1, &retained_grant, &retained_image); + retarget_resource_x_remote_join_pair(&retained_grant, &retained_image, UINT64_C(11), + first_assertion.common.assertion_sequence); retained_grant.common.base_authority_generation = first_assertion.common.base_authority_generation; - retained_grant.common.ordered_lane - = first_assertion.common.ordered_lane; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact( - &retained_grant, 0, &join), RESOURCE_X_APPLY_APPLIED); + retained_grant.common.ordered_lane = first_assertion.common.ordered_lane; + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact(&retained_grant, 0, &join), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(join.flags, RESOURCE_X_REQUESTER_JOIN_HAS_GRANT); action = cluster_pcm_lock_resource_x_bootstrap_round_step_exact( &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(1000), (UINT64_C(1000)) - (UINT64_C(1000)), @@ -5269,35 +5051,34 @@ UT_TEST(test_resource_x_bootstrap_round_binds_exact_direct_init_reservation) reset_fake_pcm_runtime(4); cluster_node_id = 1; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), - RESOURCE_X_APPLY_APPLIED); + RESOURCE_X_APPLY_APPLIED); UT_ASSERT(resource_x_assertion_init(&tag, 1, &assertion)); action = cluster_pcm_lock_resource_x_bootstrap_round_step_direct_init_exact( &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(10000), (UINT64_C(10000)) - (UINT64_C(100)), UINT64_C(100), UINT64_C(50), 0, 5, false, 0, &request, &terminal_ref); UT_ASSERT_EQ(action, RESOURCE_X_BOOTSTRAP_ROUND_DISPATCH_REQUEST); expected_ref = make_resource_x_acquisition_ref(tag, 1, 17, 1); - UT_ASSERT(!cluster_pcm_lock_resource_x_bootstrap_round_direct_init_matches_exact( - &expected_ref, 0, 5)); + UT_ASSERT(!cluster_pcm_lock_resource_x_bootstrap_round_direct_init_matches_exact(&expected_ref, + 0, 5)); UT_ASSERT(!cluster_pcm_lock_resource_x_bootstrap_round_direct_init_snapshot_exact( &expected_ref, &direct_generation, &direct_token)); UT_ASSERT_EQ(direct_generation, UINT64_C(0)); UT_ASSERT_EQ(direct_token, UINT64_C(0)); - ack = make_resource_x_bootstrap_ack_values( - &request, UINT64_C(9), UINT32_C(71)); + ack = make_resource_x_bootstrap_ack_values(&request, UINT64_C(9), UINT32_C(71)); action = cluster_pcm_lock_resource_x_bootstrap_round_accept_ack_exact( &ack, 0, 61, 77, UINT64_C(110), &assert_frame); UT_ASSERT_EQ(action, RESOURCE_X_BOOTSTRAP_ROUND_DISPATCH_ASSERT); - UT_ASSERT(cluster_pcm_lock_resource_x_bootstrap_round_direct_init_matches_exact( - &expected_ref, 0, 5)); + UT_ASSERT( + cluster_pcm_lock_resource_x_bootstrap_round_direct_init_matches_exact(&expected_ref, 0, 5)); UT_ASSERT(cluster_pcm_lock_resource_x_bootstrap_round_direct_init_snapshot_exact( &expected_ref, &direct_generation, &direct_token)); UT_ASSERT_EQ(direct_generation, UINT64_C(0)); UT_ASSERT_EQ(direct_token, UINT64_C(5)); - UT_ASSERT(!cluster_pcm_lock_resource_x_bootstrap_round_direct_init_matches_exact( - &expected_ref, 1, 5)); - UT_ASSERT(!cluster_pcm_lock_resource_x_bootstrap_round_direct_init_matches_exact( - &expected_ref, 0, 6)); + UT_ASSERT(!cluster_pcm_lock_resource_x_bootstrap_round_direct_init_matches_exact(&expected_ref, + 1, 5)); + UT_ASSERT(!cluster_pcm_lock_resource_x_bootstrap_round_direct_init_matches_exact(&expected_ref, + 0, 6)); } UT_TEST(test_resource_x_dispatch_observation_projects_existing_claim_without_mutation) @@ -5376,7 +5157,7 @@ UT_TEST(test_resource_x_pre_assert_authority_drift_cannot_discard_admitted_capab reset_fake_pcm_runtime(4); cluster_node_id = 1; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), - RESOURCE_X_APPLY_APPLIED); + RESOURCE_X_APPLY_APPLIED); UT_ASSERT(resource_x_assertion_init(&tag, 1, &assertion)); action = cluster_pcm_lock_resource_x_bootstrap_round_step_exact( &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(10000), (UINT64_C(10000)) - (UINT64_C(100)), @@ -5386,9 +5167,9 @@ UT_TEST(test_resource_x_pre_assert_authority_drift_cannot_discard_admitted_capab /* Missing ACK cannot distinguish a harmless receipt from a canonical * remote admission. A caller cannot discard either by assumption. */ - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_bootstrap_request_exact( - &first_request, 1, 61, 77, 31, 71, &first_ack), - RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_bootstrap_request_exact(&first_request, 1, 61, 77, 31, + 71, &first_ack), + RESOURCE_X_APPLY_APPLIED); result = cluster_pcm_lock_resource_x_bootstrap_round_discard_pre_assert_authority_drift_exact( &first_request, 0, 77, 61, UINT64_C(50), UINT64_C(10000), 0, 0); UT_ASSERT_EQ(result, RESOURCE_X_APPLY_BAD_STATE); @@ -5428,15 +5209,13 @@ UT_TEST(test_resource_x_direct_init_observer_is_join_only_and_keeps_round_deadli reset_fake_pcm_runtime(4); cluster_node_id = 1; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), - RESOURCE_X_APPLY_APPLIED); + RESOURCE_X_APPLY_APPLIED); UT_ASSERT(resource_x_assertion_init(&tag, 1, &assertion)); /* A pending BufferDesc sidecar ahead of requester-round creation cannot * let an observer allocate attempt 1 or invent an R7 deadline. */ - result - = cluster_pcm_lock_resource_x_bootstrap_round_direct_init_join_budget_exact( - &assertion, 0, 5, UINT64_C(90), - &frozen_r4_generation, &frozen_deadline); + result = cluster_pcm_lock_resource_x_bootstrap_round_direct_init_join_budget_exact( + &assertion, 0, 5, UINT64_C(90), &frozen_r4_generation, &frozen_deadline); UT_ASSERT_EQ(result, RESOURCE_X_APPLY_NOT_FOUND); UT_ASSERT_EQ(frozen_r4_generation, UINT64_C(0)); UT_ASSERT_EQ(frozen_deadline, UINT64_C(0)); @@ -5452,10 +5231,8 @@ UT_TEST(test_resource_x_direct_init_observer_is_join_only_and_keeps_round_deadli UT_ASSERT_EQ(action, RESOURCE_X_BOOTSTRAP_ROUND_DISPATCH_REQUEST); UT_ASSERT_EQ(dispatch.common.assertion_sequence, UINT64_C(1)); - result - = cluster_pcm_lock_resource_x_bootstrap_round_direct_init_join_budget_exact( - &assertion, 0, 5, UINT64_C(101), - &frozen_r4_generation, &frozen_deadline); + result = cluster_pcm_lock_resource_x_bootstrap_round_direct_init_join_budget_exact( + &assertion, 0, 5, UINT64_C(101), &frozen_r4_generation, &frozen_deadline); UT_ASSERT_EQ(result, RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(frozen_r4_generation, UINT64_C(77)); UT_ASSERT_EQ(frozen_deadline, UINT64_C(10000)); @@ -5479,9 +5256,10 @@ UT_TEST(test_resource_x_direct_init_observer_is_join_only_and_keeps_round_deadli } static void -check_resource_x_terminal_local_owner_recycle_and_revoke( - int32 next_requester, uint64 next_generation, uint64 next_attempt, - bool stale_authority_probe) +check_resource_x_terminal_local_owner_recycle_and_revoke(int32 next_requester, + uint64 next_generation, + uint64 next_attempt, + bool stale_authority_probe) { BufferTag tag = make_tag(155); ResourceXAssertion assertion; @@ -5520,38 +5298,35 @@ check_resource_x_terminal_local_owner_recycle_and_revoke( tag.forkNum = VISIBILITYMAP_FORKNUM; cluster_node_id = 1; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), - RESOURCE_X_APPLY_APPLIED); + RESOURCE_X_APPLY_APPLIED); UT_ASSERT(resource_x_assertion_init(&tag, 1, &assertion)); action = cluster_pcm_lock_resource_x_bootstrap_round_step_direct_init_exact( &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(1000), (UINT64_C(1000)) - (UINT64_C(100)), UINT64_C(100), UINT64_C(50), 90, 19, false, 0, &request, &terminal_ref); UT_ASSERT_EQ(action, RESOURCE_X_BOOTSTRAP_ROUND_DISPATCH_REQUEST); - ack = make_resource_x_bootstrap_ack_values( - &request, UINT64_C(9), UINT32_C(71)); + ack = make_resource_x_bootstrap_ack_values(&request, UINT64_C(9), UINT32_C(71)); action = cluster_pcm_lock_resource_x_bootstrap_round_accept_ack_exact( &ack, 0, 61, 77, UINT64_C(110), &assert_frame); UT_ASSERT_EQ(action, RESOURCE_X_BOOTSTRAP_ROUND_DISPATCH_ASSERT); expected_ref = make_resource_x_acquisition_ref(tag, 1, 17, 1); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_t1_grant_exact(&expected_ref), - RESOURCE_X_APPLY_APPLIED); + RESOURCE_X_APPLY_APPLIED); memset(&install, 0, sizeof(install)); install.ownership_generation = 91; install.writer_activation_token = 19; install.resource_x_activation_generation = 1; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_apply_exact( - &expected_ref, &install), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_apply_exact(&expected_ref, &install), + RESOURCE_X_APPLY_APPLIED); memset(&activation, 0, sizeof(activation)); activation.ownership_generation = 91; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_activate_exact( - &expected_ref, &activation), RESOURCE_X_APPLY_APPLIED); - UT_ASSERT_EQ( - cluster_pcm_lock_resource_x_bootstrap_round_publish_terminal_exact( - &expected_ref, 31, 77, 91, 10, UINT64_C(120)), - RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_activate_exact(&expected_ref, &activation), + RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_bootstrap_round_publish_terminal_exact( + &expected_ref, 31, 77, 91, 10, UINT64_C(120)), + RESOURCE_X_APPLY_APPLIED); - successor_block = make_resource_x_master_frame( - RESOURCE_X_WIRE_BLOCK_TO_N, tag, 2, 1); + successor_block = make_resource_x_master_frame(RESOURCE_X_WIRE_BLOCK_TO_N, tag, 2, 1); successor_block.payload_bytes = RESOURCE_X_CONTROL_V1_BYTES; successor_block.common.base_authority_generation = UINT64_C(10); successor_block.common.authority_generation = UINT64_C(10); @@ -5563,118 +5338,111 @@ check_resource_x_terminal_local_owner_recycle_and_revoke( successor_block.common.retain_pi_if_dirty = 1; memset(&recycle, 0, sizeof(recycle)); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_itl_recycle_begin_exact( - &expected_ref, 31, 77, 91, 19, 7, UINT64_C(100), &recycle), - RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_itl_recycle_begin_exact(&expected_ref, 31, 77, 91, 19, + 7, UINT64_C(100), &recycle), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(recycle.owner_generation, UINT64_C(1)); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_itl_recycle_begin_exact( - &expected_ref, 31, 77, 91, 19, 8, UINT64_C(101), &revoke), - RESOURCE_X_APPLY_BAD_STATE); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_itl_recycle_begin_exact(&expected_ref, 31, 77, 91, 19, + 8, UINT64_C(101), &revoke), + RESOURCE_X_APPLY_BAD_STATE); action = cluster_pcm_lock_resource_x_bootstrap_round_step_exact( &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(10000), (UINT64_C(10000)) - (UINT64_C(125)), UINT64_C(125), UINT64_C(50), true, 91, &unused_dispatch, &terminal_ref); UT_ASSERT_EQ(action, RESOURCE_X_BOOTSTRAP_ROUND_WAIT); memset(&lineage, 0, sizeof(lineage)); - UT_ASSERT(cluster_pcm_lock_resource_x_bootstrap_round_terminal_holder_exact( - &successor_block, 0, 77, 91, &lineage)); + UT_ASSERT(cluster_pcm_lock_resource_x_bootstrap_round_terminal_holder_exact(&successor_block, 0, + 77, 91, &lineage)); UT_ASSERT(!cluster_pcm_lock_resource_x_bootstrap_round_direct_init_terminal_holder_exact( &successor_block, 0, 77, 91, &lineage)); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_terminal_x_revoke_claim_exact( - &successor_block, 0, 77, 91, 19, 9, UINT64_C(110), - &lineage, &revoke), - RESOURCE_X_APPLY_BAD_STATE); + &successor_block, 0, 77, 91, 19, 9, UINT64_C(110), &lineage, &revoke), + RESOURCE_X_APPLY_BAD_STATE); /* The first exact type-17 owns the bounded local priority. A different * FIFO successor cannot overwrite it while the recycler is still active. */ conflict_block = successor_block; - UT_ASSERT(resource_x_assertion_init(&tag, 3, - &conflict_block.common.logical_assertion)); + UT_ASSERT(resource_x_assertion_init(&tag, 3, &conflict_block.common.logical_assertion)); conflict_block.common.assertion_sequence = UINT64_C(43); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_terminal_x_revoke_claim_exact( - &conflict_block, 0, 77, 91, 19, 10, UINT64_C(111), - &lineage, &stale), - RESOURCE_X_APPLY_STALE); + &conflict_block, 0, 77, 91, 19, 10, UINT64_C(111), &lineage, &stale), + RESOURCE_X_APPLY_STALE); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_terminal_x_revoke_claim_exact( - &successor_block, 0, 77, 91, 19, 9, UINT64_C(112), - &lineage, &revoke), - RESOURCE_X_APPLY_BAD_STATE); + &successor_block, 0, 77, 91, 19, 9, UINT64_C(112), &lineage, &revoke), + RESOURCE_X_APPLY_BAD_STATE); stale = recycle; stale.owner_generation++; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_itl_recycle_finish_exact( - &stale, UINT64_C(120)), - RESOURCE_X_APPLY_STALE); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_itl_recycle_finish_exact( - &recycle, UINT64_C(121)), - RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_itl_recycle_finish_exact(&stale, UINT64_C(120)), + RESOURCE_X_APPLY_STALE); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_itl_recycle_finish_exact(&recycle, UINT64_C(121)), + RESOURCE_X_APPLY_APPLIED); action = cluster_pcm_lock_resource_x_bootstrap_round_step_exact( &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(10000), (UINT64_C(10000)) - (UINT64_C(126)), UINT64_C(126), UINT64_C(50), true, 91, &unused_dispatch, &terminal_ref); UT_ASSERT_EQ(action, RESOURCE_X_BOOTSTRAP_ROUND_WAIT); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_itl_recycle_begin_exact( - &expected_ref, 31, 77, 91, 19, 7, UINT64_C(126), &stale), - RESOURCE_X_APPLY_BAD_STATE); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_itl_recycle_begin_exact(&expected_ref, 31, 77, 91, 19, + 7, UINT64_C(126), &stale), + RESOURCE_X_APPLY_BAD_STATE); memset(&lineage, 0, sizeof(lineage)); memset(&revoke, 0, sizeof(revoke)); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_terminal_x_revoke_claim_exact( - &successor_block, 0, 77, 91, 19, 9, UINT64_C(127), - &lineage, &revoke), - RESOURCE_X_APPLY_APPLIED); + &successor_block, 0, 77, 91, 19, 9, UINT64_C(127), &lineage, &revoke), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(revoke.owner_generation, UINT64_C(2)); UT_ASSERT_EQ(lineage.holder_attempt, UINT64_C(1)); memset(&replay_lineage, 0, sizeof(replay_lineage)); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_terminal_x_revoke_replay_exact( - &successor_block, 0, 77, 91, UINT64_C(128), &replay_lineage), - RESOURCE_X_APPLY_BAD_STATE); + &successor_block, 0, 77, 91, UINT64_C(128), &replay_lineage), + RESOURCE_X_APPLY_BAD_STATE); UT_ASSERT_EQ(memcmp(&lineage, &replay_lineage, sizeof(lineage)), 0); memset(&replay_lineage, 0, sizeof(replay_lineage)); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_terminal_x_revoke_replay_exact( - &conflict_block, 0, 77, 91, UINT64_C(128), &replay_lineage), - RESOURCE_X_APPLY_STALE); + &conflict_block, 0, 77, 91, UINT64_C(128), &replay_lineage), + RESOURCE_X_APPLY_STALE); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_terminal_x_revoke_replay_exact( - &successor_block, 0, 78, 91, UINT64_C(128), &replay_lineage), - RESOURCE_X_APPLY_RECOVERY_BLOCKED); + &successor_block, 0, 78, 91, UINT64_C(128), &replay_lineage), + RESOURCE_X_APPLY_RECOVERY_BLOCKED); UT_ASSERT(cluster_pcm_lock_resource_x_terminal_x_revoke_revalidate_held_exact( &successor_block, 0, 77, 91, &revoke, &lineage)); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_itl_recycle_begin_exact( - &expected_ref, 31, 77, 91, 19, 7, UINT64_C(128), &recycle), - RESOURCE_X_APPLY_BAD_STATE); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_itl_recycle_begin_exact(&expected_ref, 31, 77, 91, 19, + 7, UINT64_C(128), &recycle), + RESOURCE_X_APPLY_BAD_STATE); stale = revoke; stale.owner_procno++; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_terminal_x_revoke_yield_exact( - &stale, UINT64_C(128)), RESOURCE_X_APPLY_STALE); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_terminal_x_revoke_yield_exact( - &revoke, UINT64_C(129)), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_terminal_x_revoke_yield_exact(&stale, UINT64_C(128)), + RESOURCE_X_APPLY_STALE); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_terminal_x_revoke_yield_exact(&revoke, UINT64_C(129)), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT(!cluster_pcm_lock_resource_x_terminal_x_revoke_revalidate_held_exact( &successor_block, 0, 77, 91, &revoke, &lineage)); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_itl_recycle_begin_exact( - &expected_ref, 31, 77, 91, 19, 7, UINT64_C(130), &recycle), - RESOURCE_X_APPLY_BAD_STATE); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_itl_recycle_begin_exact(&expected_ref, 31, 77, 91, 19, + 7, UINT64_C(130), &recycle), + RESOURCE_X_APPLY_BAD_STATE); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_terminal_x_revoke_claim_exact( - &conflict_block, 0, 77, 91, 19, 10, UINT64_C(131), - &lineage, &stale), RESOURCE_X_APPLY_STALE); + &conflict_block, 0, 77, 91, 19, 10, UINT64_C(131), &lineage, &stale), + RESOURCE_X_APPLY_STALE); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_terminal_x_revoke_claim_exact( - &successor_block, 0, 77, 91, 19, 9, UINT64_C(132), - &lineage, &revoke), RESOURCE_X_APPLY_APPLIED); + &successor_block, 0, 77, 91, 19, 9, UINT64_C(132), &lineage, &revoke), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(revoke.owner_generation, UINT64_C(3)); UT_ASSERT(cluster_pcm_lock_resource_x_terminal_x_revoke_revalidate_held_exact( &successor_block, 0, 77, 91, &revoke, &lineage)); stale = revoke; stale.owner_procno++; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_terminal_x_revoke_release_exact(&stale), - RESOURCE_X_APPLY_STALE); + RESOURCE_X_APPLY_STALE); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_terminal_x_revoke_release_exact(&revoke), - RESOURCE_X_APPLY_APPLIED); + RESOURCE_X_APPLY_APPLIED); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_itl_recycle_begin_exact( - &expected_ref, 31, 77, 91, 19, 7, UINT64_C(200), &recycle), - RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_itl_recycle_begin_exact(&expected_ref, 31, 77, 91, 19, + 7, UINT64_C(200), &recycle), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(recycle.owner_generation, UINT64_C(4)); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_terminal_x_revoke_claim_exact( - &successor_block, 0, 77, 91, 19, 9, UINT64_C(210), - &lineage, &revoke), RESOURCE_X_APPLY_BAD_STATE); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_itl_recycle_finish_exact( - &recycle, UINT64_C(220)), RESOURCE_X_APPLY_APPLIED); + &successor_block, 0, 77, 91, 19, 9, UINT64_C(210), &lineage, &revoke), + RESOURCE_X_APPLY_BAD_STATE); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_itl_recycle_finish_exact(&recycle, UINT64_C(220)), + RESOURCE_X_APPLY_APPLIED); action = cluster_pcm_lock_resource_x_bootstrap_round_step_exact( &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(10000), (UINT64_C(10000)) - (UINT64_C(1209)), UINT64_C(1209), UINT64_C(50), true, 91, &unused_dispatch, &terminal_ref); @@ -5683,12 +5451,12 @@ check_resource_x_terminal_local_owner_recycle_and_revoke( &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(10000), (UINT64_C(10000)) - (UINT64_C(1210)), UINT64_C(1210), UINT64_C(50), true, 91, &unused_dispatch, &terminal_ref); UT_ASSERT_EQ(action, RESOURCE_X_BOOTSTRAP_ROUND_WAIT); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_itl_recycle_begin_exact( - &expected_ref, 31, 77, 91, 19, 7, UINT64_C(1220), &recycle), - RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_itl_recycle_begin_exact(&expected_ref, 31, 77, 91, 19, + 7, UINT64_C(1220), &recycle), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(recycle.owner_generation, UINT64_C(5)); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_itl_recycle_cancel_exact(&recycle), - RESOURCE_X_APPLY_APPLIED); + RESOURCE_X_APPLY_APPLIED); action = cluster_pcm_lock_resource_x_bootstrap_round_step_exact( &assertion, 0, 17, 31, 77, 51, 61, 10000, (10000) - (1221), 1221, 50, true, 91, &unused_dispatch, &terminal_ref); @@ -5704,17 +5472,17 @@ check_resource_x_terminal_local_owner_recycle_and_revoke( memset(&lineage, 0, sizeof(lineage)); memset(&revoke, 0, sizeof(revoke)); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_terminal_x_revoke_claim_exact( - &successor_block, 0, 77, 91, 19, 9, UINT64_C(1300), - &lineage, &revoke), RESOURCE_X_APPLY_APPLIED); + &successor_block, 0, 77, 91, 19, 9, UINT64_C(1300), &lineage, &revoke), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(revoke.owner_generation, UINT64_C(6)); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_terminal_x_revoke_claim_exact( - &conflict_block, 0, 77, 91, 19, 10, UINT64_C(1300), - &lineage, &stale), RESOURCE_X_APPLY_STALE); + &conflict_block, 0, 77, 91, 19, 10, UINT64_C(1300), &lineage, &stale), + RESOURCE_X_APPLY_STALE); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_terminal_x_revoke_claim_exact( - &successor_block, 0, 77, 91, 19, 9, UINT64_C(1300), - &lineage, &stale), RESOURCE_X_APPLY_BAD_STATE); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_terminal_x_revoke_yield_exact( - &revoke, UINT64_C(1301)), RESOURCE_X_APPLY_APPLIED); + &successor_block, 0, 77, 91, 19, 9, UINT64_C(1300), &lineage, &stale), + RESOURCE_X_APPLY_BAD_STATE); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_terminal_x_revoke_yield_exact(&revoke, UINT64_C(1301)), + RESOURCE_X_APPLY_APPLIED); action = cluster_pcm_lock_resource_x_bootstrap_round_step_exact( &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(10000), (UINT64_C(10000)) - (UINT64_C(1302)), UINT64_C(1302), UINT64_C(50), true, 91, &unused_dispatch, &terminal_ref); @@ -5723,30 +5491,28 @@ check_resource_x_terminal_local_owner_recycle_and_revoke( &expected_ref, 31, 77, 91, 19, 7, UINT64_C(1303), &recycle); UT_ASSERT_EQ(owner_result, RESOURCE_X_APPLY_BAD_STATE); if (owner_result == RESOURCE_X_APPLY_APPLIED) - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_itl_recycle_cancel_exact( - &recycle), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_itl_recycle_cancel_exact(&recycle), + RESOURCE_X_APPLY_APPLIED); owner_result = cluster_pcm_lock_resource_x_terminal_x_revoke_claim_exact( - &conflict_block, 0, 77, 91, 19, 10, UINT64_C(1304), - &lineage, &stale); + &conflict_block, 0, 77, 91, 19, 10, UINT64_C(1304), &lineage, &stale); UT_ASSERT_EQ(owner_result, RESOURCE_X_APPLY_STALE); if (owner_result == RESOURCE_X_APPLY_APPLIED) - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_terminal_x_revoke_release_exact( - &stale), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_terminal_x_revoke_release_exact(&stale), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_terminal_x_revoke_claim_exact( - &successor_block, 0, 77, 91, 19, 9, UINT64_C(2299), - &lineage, &revoke), RESOURCE_X_APPLY_APPLIED); + &successor_block, 0, 77, 91, 19, 9, UINT64_C(2299), &lineage, &revoke), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(revoke.owner_generation, UINT64_C(7)); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_terminal_x_revoke_yield_exact( - &revoke, UINT64_C(2299)), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_terminal_x_revoke_yield_exact(&revoke, UINT64_C(2299)), + RESOURCE_X_APPLY_APPLIED); owner_result = cluster_pcm_lock_resource_x_terminal_x_revoke_claim_exact( - &successor_block, 0, 77, 91, 19, 9, UINT64_C(2300), - &lineage, &revoke); + &successor_block, 0, 77, 91, 19, 9, UINT64_C(2300), &lineage, &revoke); /* Expiring reversible priority supplies no new grant and does not * contradict the successor. The same master must retry its request. */ UT_ASSERT_EQ(owner_result, RESOURCE_X_APPLY_BAD_STATE); if (owner_result == RESOURCE_X_APPLY_APPLIED) - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_terminal_x_revoke_release_exact( - &revoke), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_terminal_x_revoke_release_exact(&revoke), + RESOURCE_X_APPLY_APPLIED); action = cluster_pcm_lock_resource_x_bootstrap_round_step_exact( &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(10000), (UINT64_C(10000)) - (UINT64_C(2301)), UINT64_C(2301), UINT64_C(50), true, 91, &unused_dispatch, &terminal_ref); @@ -5756,12 +5522,12 @@ check_resource_x_terminal_local_owner_recycle_and_revoke( * duplicate keeps waiting without refreshing priority or taking the owner; * the original handle remains the only legal cleanup identity. */ UT_ASSERT_EQ(cluster_pcm_lock_resource_x_terminal_x_revoke_claim_exact( - &successor_block, 0, 77, 91, 19, 9, UINT64_C(2400), - &lineage, &revoke), RESOURCE_X_APPLY_APPLIED); + &successor_block, 0, 77, 91, 19, 9, UINT64_C(2400), &lineage, &revoke), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(revoke.owner_generation, UINT64_C(8)); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_terminal_x_revoke_replay_exact( - &successor_block, 0, 77, 91, UINT64_C(3399), &replay_lineage), - RESOURCE_X_APPLY_BAD_STATE); + &successor_block, 0, 77, 91, UINT64_C(3399), &replay_lineage), + RESOURCE_X_APPLY_BAD_STATE); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_terminal_x_revoke_replay_exact( &successor_block, 0, 77, 91, UINT64_C(3400), &replay_lineage), RESOURCE_X_APPLY_BAD_STATE); @@ -5778,20 +5544,17 @@ check_resource_x_terminal_local_owner_recycle_and_revoke( * and later recreates the BufferDesc. Its carrier generation therefore * belongs to the old descriptor episode even when the new episode reaches * the same numeric value. */ - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_terminal_x_revoke_release_exact( - &revoke), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_terminal_x_revoke_release_exact(&revoke), + RESOURCE_X_APPLY_APPLIED); fake_gcs_master_node = 0; old_block = successor_block; - UT_ASSERT(resource_x_assertion_init(&tag, 2, - &old_block.common.logical_assertion)); + UT_ASSERT(resource_x_assertion_init(&tag, 2, &old_block.common.logical_assertion)); old_block.common.assertion_sequence = UINT64_C(41); make_resource_x_remote_join_pair(tag, 2, &grant, &old_image); - retarget_resource_x_remote_join_pair(&grant, &old_image, UINT64_C(12), - UINT64_C(41)); + retarget_resource_x_remote_join_pair(&grant, &old_image, UINT64_C(12), UINT64_C(41)); old_image.common.ordered_lane = 0; - set_resource_x_test_source_fence( - old_image.body.image_envelope.source_fence, UINT64_C(91), - PCM_STATE_X); + set_resource_x_test_source_fence(old_image.body.image_envelope.source_fence, UINT64_C(91), + PCM_STATE_X); old_image.body.image_envelope.source_carrier_generation = UINT64_C(92); canonicalize_resource_x_test_image(&old_image); old_status = make_resource_x_remote_blocked_frame(tag, 2, 1); @@ -5800,85 +5563,72 @@ check_resource_x_terminal_local_owner_recycle_and_revoke( old_status.common.retain_pi_if_dirty = 0; old_status.common.outcome = RESOURCE_X_OUTCOME_OK; old_status.common.flags = RESOURCE_X_COMMON_FLAG_PI_ESTABLISHED; - memcpy(old_status.body.blocked_to_n.source_fence, - old_image.body.image_envelope.source_fence, - sizeof(old_status.body.blocked_to_n.source_fence)); + memcpy(old_status.body.blocked_to_n.source_fence, old_image.body.image_envelope.source_fence, + sizeof(old_status.body.blocked_to_n.source_fence)); old_status.body.blocked_to_n.source_carrier_generation = UINT64_C(92); old_status.body.blocked_to_n.requester_target_generation = UINT64_C(41); - old_status.body.blocked_to_n.page_scn_lsn - = old_image.body.image_envelope.page_scn_lsn; - old_status.body.blocked_to_n.dependency_count - = old_image.body.image_envelope.dependency_count; - memcpy(old_status.body.blocked_to_n.dependencies, - old_image.body.image_envelope.dependencies, - sizeof(old_status.body.blocked_to_n.dependencies)); - old_status.body.blocked_to_n.source_proof_crc32c - = old_image.common.semantic_crc32c; - old_status.body.blocked_to_n.page_checksum - = old_image.body.image_envelope.page_checksum; - old_status.body.blocked_to_n.source_disposition - = RESOURCE_X_DISPOSITION_REMOTE_NONWRITABLE; + old_status.body.blocked_to_n.page_scn_lsn = old_image.body.image_envelope.page_scn_lsn; + old_status.body.blocked_to_n.dependency_count = old_image.body.image_envelope.dependency_count; + memcpy(old_status.body.blocked_to_n.dependencies, old_image.body.image_envelope.dependencies, + sizeof(old_status.body.blocked_to_n.dependencies)); + old_status.body.blocked_to_n.source_proof_crc32c = old_image.common.semantic_crc32c; + old_status.body.blocked_to_n.page_checksum = old_image.body.image_envelope.page_checksum; + old_status.body.blocked_to_n.source_disposition = RESOURCE_X_DISPOSITION_REMOTE_NONWRITABLE; old_status.body.blocked_to_n.proof_kind = RESOURCE_X_PROOF_REMOTE_CARRIER; old_status.body.blocked_to_n.holder_connection_generation = 51; old_status.body.blocked_to_n.acting_formation = 17; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_block_to_n_source_exact( - &old_block, 0, &old_status, &old_image), RESOURCE_X_APPLY_APPLIED); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_holder_pair_publish_exact( - &old_block.common.logical_assertion, - old_block.common.assertion_sequence, 0, - old_block.common.master_session_incarnation), + UT_ASSERT_EQ( + cluster_pcm_lock_resource_x_block_to_n_source_exact(&old_block, 0, &old_status, &old_image), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_holder_pair_publish_exact( + &old_block.common.logical_assertion, old_block.common.assertion_sequence, 0, + old_block.common.master_session_incarnation), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_holder_status_intent_snapshot_exact( - &old_block.common.logical_assertion, &old_status_intent, - old_status_payload, sizeof(old_status_payload)), - RESOURCE_X_APPLY_APPLIED); + &old_block.common.logical_assertion, &old_status_intent, old_status_payload, + sizeof(old_status_payload)), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_holder_image_intent_snapshot_exact( - &old_block.common.logical_assertion, &old_image_intent, - old_image_payload, sizeof(old_image_payload)), - RESOURCE_X_APPLY_APPLIED); + &old_block.common.logical_assertion, &old_image_intent, old_image_payload, + sizeof(old_image_payload)), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_outbound_intent_stage_exact( - &old_status_intent, old_status_intent.first_armed_us + 1), - RESOURCE_X_INTENT_STAGED); - UT_ASSERT(cluster_pcm_lock_resource_x_outbound_intent_complete_exact( - &old_status_intent)); + &old_status_intent, old_status_intent.first_armed_us + 1), + RESOURCE_X_INTENT_STAGED); + UT_ASSERT(cluster_pcm_lock_resource_x_outbound_intent_complete_exact(&old_status_intent)); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_outbound_intent_stage_exact( - &old_image_intent, old_image_intent.first_armed_us + 1), - RESOURCE_X_INTENT_STAGED); - UT_ASSERT(cluster_pcm_lock_resource_x_outbound_intent_complete_exact( - &old_image_intent)); + &old_image_intent, old_image_intent.first_armed_us + 1), + RESOURCE_X_INTENT_STAGED); + UT_ASSERT(cluster_pcm_lock_resource_x_outbound_intent_complete_exact(&old_image_intent)); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_holder_pair_drain_prepare_exact( - &old_block.common.logical_assertion, - old_block.common.assertion_sequence, 0, - old_block.common.master_session_incarnation, - &old_source_generation), RESOURCE_X_APPLY_APPLIED); + &old_block.common.logical_assertion, old_block.common.assertion_sequence, 0, + old_block.common.master_session_incarnation, &old_source_generation), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(old_source_generation, UINT64_C(91)); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_holder_pair_drain_commit_exact( - &old_block.common.logical_assertion, - old_block.common.assertion_sequence, 0, - old_block.common.master_session_incarnation, - old_source_generation), RESOURCE_X_APPLY_APPLIED); + &old_block.common.logical_assertion, old_block.common.assertion_sequence, 0, + old_block.common.master_session_incarnation, old_source_generation), + RESOURCE_X_APPLY_APPLIED); /* DRAIN alone cannot establish a new authority episode. Keep the exact * old terminal cover, but ask it to replace the pair for another requester. */ if (stale_authority_probe) - UT_ASSERT(resource_x_assertion_init(&tag, 3, - &successor_block.common.logical_assertion)); + UT_ASSERT(resource_x_assertion_init(&tag, 3, &successor_block.common.logical_assertion)); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_terminal_x_revoke_claim_exact( - &successor_block, 0, 77, 91, 19, 9, UINT64_C(3500), - &lineage, &revoke), RESOURCE_X_APPLY_APPLIED); + &successor_block, 0, 77, 91, 19, 9, UINT64_C(3500), &lineage, &revoke), + RESOURCE_X_APPLY_APPLIED); /* The production DROP order retains the exact pair before physically * removing the descriptor. That pending pair is protocol debt, but it must * not invalidate the already-held terminal cover/REVOKING identity which * the post-drop close consumes. */ fake_gcs_master_node = 0; - make_resource_x_remote_join_pair(tag, - successor_block.common.logical_assertion.requester_node, &grant, &image); - retarget_resource_x_remote_join_pair(&grant, &image, UINT64_C(12), - UINT64_C(42)); + make_resource_x_remote_join_pair(tag, successor_block.common.logical_assertion.requester_node, + &grant, &image); + retarget_resource_x_remote_join_pair(&grant, &image, UINT64_C(12), UINT64_C(42)); image.common.ordered_lane = 0; - set_resource_x_test_source_fence( - image.body.image_envelope.source_fence, UINT64_C(91), PCM_STATE_X); + set_resource_x_test_source_fence(image.body.image_envelope.source_fence, UINT64_C(91), + PCM_STATE_X); image.body.image_envelope.source_carrier_generation = UINT64_C(92); canonicalize_resource_x_test_image(&image); status = make_resource_x_remote_blocked_frame(tag, 2, 1); @@ -5887,25 +5637,18 @@ check_resource_x_terminal_local_owner_recycle_and_revoke( status.common.retain_pi_if_dirty = 0; status.common.outcome = RESOURCE_X_OUTCOME_OK; status.common.flags = RESOURCE_X_COMMON_FLAG_PI_ESTABLISHED; - memcpy(status.body.blocked_to_n.source_fence, - image.body.image_envelope.source_fence, - sizeof(status.body.blocked_to_n.source_fence)); + memcpy(status.body.blocked_to_n.source_fence, image.body.image_envelope.source_fence, + sizeof(status.body.blocked_to_n.source_fence)); status.body.blocked_to_n.source_carrier_generation = image.body.image_envelope.source_carrier_generation; status.body.blocked_to_n.requester_target_generation = UINT64_C(42); - status.body.blocked_to_n.page_scn_lsn - = image.body.image_envelope.page_scn_lsn; - status.body.blocked_to_n.dependency_count - = image.body.image_envelope.dependency_count; - memcpy(status.body.blocked_to_n.dependencies, - image.body.image_envelope.dependencies, - sizeof(status.body.blocked_to_n.dependencies)); - status.body.blocked_to_n.source_proof_crc32c - = image.common.semantic_crc32c; - status.body.blocked_to_n.page_checksum - = image.body.image_envelope.page_checksum; - status.body.blocked_to_n.source_disposition - = RESOURCE_X_DISPOSITION_REMOTE_NONWRITABLE; + status.body.blocked_to_n.page_scn_lsn = image.body.image_envelope.page_scn_lsn; + status.body.blocked_to_n.dependency_count = image.body.image_envelope.dependency_count; + memcpy(status.body.blocked_to_n.dependencies, image.body.image_envelope.dependencies, + sizeof(status.body.blocked_to_n.dependencies)); + status.body.blocked_to_n.source_proof_crc32c = image.common.semantic_crc32c; + status.body.blocked_to_n.page_checksum = image.body.image_envelope.page_checksum; + status.body.blocked_to_n.source_disposition = RESOURCE_X_DISPOSITION_REMOTE_NONWRITABLE; status.body.blocked_to_n.proof_kind = RESOURCE_X_PROOF_REMOTE_CARRIER; status.body.blocked_to_n.holder_connection_generation = 51; status.body.blocked_to_n.acting_formation = 17; @@ -5919,30 +5662,31 @@ check_resource_x_terminal_local_owner_recycle_and_revoke( /* The generic path cannot infer a new descriptor episode from an equal * generation and must remain stale. The DROP-only path still rejects an * equal or skipped BufferDesc token. */ - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_block_to_n_source_exact( - &successor_block, 0, &status, &image), RESOURCE_X_APPLY_STALE); + UT_ASSERT_EQ( + cluster_pcm_lock_resource_x_block_to_n_source_exact(&successor_block, 0, &status, &image), + RESOURCE_X_APPLY_STALE); stale = revoke; revoking.reservation_token = revoke.reservation_token; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_block_to_n_drop_x_source_exact( - &successor_block, 0, &status, &image, &revoking, &stale), - RESOURCE_X_APPLY_STALE); + &successor_block, 0, &status, &image, &revoking, &stale), + RESOURCE_X_APPLY_STALE); revoking.reservation_token = revoke.reservation_token + UINT64_C(1); stale = revoke; stale.owner_procno++; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_block_to_n_drop_x_source_exact( - &successor_block, 0, &status, &image, &revoking, &stale), - RESOURCE_X_APPLY_STALE); + &successor_block, 0, &status, &image, &revoking, &stale), + RESOURCE_X_APPLY_STALE); if (stale_authority_probe) { UT_ASSERT_EQ(lineage.final_authority_generation, UINT64_C(10)); UT_ASSERT_EQ(old_image.common.authority_generation, UINT64_C(11)); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_block_to_n_drop_x_source_exact( - &successor_block, 0, &status, &image, &revoking, &revoke), - RESOURCE_X_APPLY_STALE); + &successor_block, 0, &status, &image, &revoking, &revoke), + RESOURCE_X_APPLY_STALE); return; } UT_ASSERT_EQ(cluster_pcm_lock_resource_x_block_to_n_drop_x_source_exact( - &successor_block, 0, &status, &image, &revoking, &revoke), - RESOURCE_X_APPLY_APPLIED); + &successor_block, 0, &status, &image, &revoking, &revoke), + RESOURCE_X_APPLY_APPLIED); /* VM/FSM DROP has no retained N+PI descriptor on which SourceSettlement * could later serialize terminal-cover cleanup. The exact type-17 owner @@ -5955,12 +5699,11 @@ check_resource_x_terminal_local_owner_recycle_and_revoke( dropped.generation = 93; dropped.flags = 0; dropped.pcm_state = (uint8)PCM_STATE_N; - UT_ASSERT_EQ( - cluster_pcm_lock_resource_x_terminal_x_revoke_finish_drop_exact( - &successor_block, 0, 77, &revoking, &dropped, &revoke), - RESOURCE_X_APPLY_STALE); - UT_ASSERT(cluster_pcm_lock_resource_x_bootstrap_round_cover_matches_exact( - &expected_ref, 31, 77, 91)); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_terminal_x_revoke_finish_drop_exact( + &successor_block, 0, 77, &revoking, &dropped, &revoke), + RESOURCE_X_APPLY_STALE); + UT_ASSERT( + cluster_pcm_lock_resource_x_bootstrap_round_cover_matches_exact(&expected_ref, 31, 77, 91)); UT_ASSERT(cluster_pcm_lock_resource_x_terminal_x_revoke_revalidate_held_exact( &successor_block, 0, 77, 91, &revoke, &lineage)); dropped.generation = 92; @@ -5969,35 +5712,31 @@ check_resource_x_terminal_local_owner_recycle_and_revoke( * exact owner or terminal cover. */ revoking.reservation_token = revoke.reservation_token; dropped.reservation_token = revoking.reservation_token; - UT_ASSERT_EQ( - cluster_pcm_lock_resource_x_terminal_x_revoke_finish_drop_exact( - &successor_block, 0, 77, &revoking, &dropped, &revoke), - RESOURCE_X_APPLY_STALE); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_terminal_x_revoke_finish_drop_exact( + &successor_block, 0, 77, &revoking, &dropped, &revoke), + RESOURCE_X_APPLY_STALE); revoking.reservation_token = revoke.reservation_token + UINT64_C(2); dropped.reservation_token = revoking.reservation_token; - UT_ASSERT_EQ( - cluster_pcm_lock_resource_x_terminal_x_revoke_finish_drop_exact( - &successor_block, 0, 77, &revoking, &dropped, &revoke), - RESOURCE_X_APPLY_STALE); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_terminal_x_revoke_finish_drop_exact( + &successor_block, 0, 77, &revoking, &dropped, &revoke), + RESOURCE_X_APPLY_STALE); stale = revoke; stale.reservation_token = UINT64_MAX; revoking.reservation_token = UINT64_MAX; dropped.reservation_token = UINT64_MAX; - UT_ASSERT_EQ( - cluster_pcm_lock_resource_x_terminal_x_revoke_finish_drop_exact( - &successor_block, 0, 77, &revoking, &dropped, &stale), - RESOURCE_X_APPLY_INVALID); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_terminal_x_revoke_finish_drop_exact( + &successor_block, 0, 77, &revoking, &dropped, &stale), + RESOURCE_X_APPLY_INVALID); revoking.reservation_token = revoke.reservation_token + UINT64_C(1); dropped.reservation_token = revoking.reservation_token; - UT_ASSERT_EQ( - cluster_pcm_lock_resource_x_terminal_x_revoke_finish_drop_exact( - &successor_block, 0, 77, &revoking, &dropped, &revoke), - RESOURCE_X_APPLY_APPLIED); - UT_ASSERT(!cluster_pcm_lock_resource_x_bootstrap_round_cover_matches_exact( - &expected_ref, 31, 77, 91)); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_terminal_x_revoke_release_exact( - &revoke), RESOURCE_X_APPLY_NOT_FOUND); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_terminal_x_revoke_finish_drop_exact( + &successor_block, 0, 77, &revoking, &dropped, &revoke), + RESOURCE_X_APPLY_APPLIED); + UT_ASSERT(!cluster_pcm_lock_resource_x_bootstrap_round_cover_matches_exact(&expected_ref, 31, + 77, 91)); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_terminal_x_revoke_release_exact(&revoke), + RESOURCE_X_APPLY_NOT_FOUND); if (next_requester == 0 || ut_current_failed != 0) return; @@ -6006,27 +5745,33 @@ check_resource_x_terminal_local_owner_recycle_and_revoke( * DRAIN alone is not evidence of a new descriptor/authority episode. */ old_block = successor_block; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_holder_pair_publish_exact( - &old_block.common.logical_assertion, UINT64_C(42), 0, 31), - RESOURCE_X_APPLY_APPLIED); + &old_block.common.logical_assertion, UINT64_C(42), 0, 31), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_holder_status_intent_snapshot_exact( - &old_block.common.logical_assertion, &old_status_intent, - old_status_payload, sizeof(old_status_payload)), RESOURCE_X_APPLY_APPLIED); + &old_block.common.logical_assertion, &old_status_intent, old_status_payload, + sizeof(old_status_payload)), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_holder_image_intent_snapshot_exact( - &old_block.common.logical_assertion, &old_image_intent, - old_image_payload, sizeof(old_image_payload)), RESOURCE_X_APPLY_APPLIED); + &old_block.common.logical_assertion, &old_image_intent, old_image_payload, + sizeof(old_image_payload)), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_outbound_intent_stage_exact( - &old_status_intent, old_status_intent.first_armed_us + 1), RESOURCE_X_INTENT_STAGED); + &old_status_intent, old_status_intent.first_armed_us + 1), + RESOURCE_X_INTENT_STAGED); UT_ASSERT(cluster_pcm_lock_resource_x_outbound_intent_complete_exact(&old_status_intent)); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_outbound_intent_stage_exact( - &old_image_intent, old_image_intent.first_armed_us + 1), RESOURCE_X_INTENT_STAGED); + &old_image_intent, old_image_intent.first_armed_us + 1), + RESOURCE_X_INTENT_STAGED); UT_ASSERT(cluster_pcm_lock_resource_x_outbound_intent_complete_exact(&old_image_intent)); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_holder_pair_drain_prepare_exact( - &old_block.common.logical_assertion, UINT64_C(42), 0, 31, - &old_source_generation), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ( + cluster_pcm_lock_resource_x_holder_pair_drain_prepare_exact( + &old_block.common.logical_assertion, UINT64_C(42), 0, 31, &old_source_generation), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(old_source_generation, UINT64_C(91)); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_holder_pair_drain_commit_exact( - &old_block.common.logical_assertion, UINT64_C(42), 0, 31, - old_source_generation), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ( + cluster_pcm_lock_resource_x_holder_pair_drain_commit_exact( + &old_block.common.logical_assertion, UINT64_C(42), 0, 31, old_source_generation), + RESOURCE_X_APPLY_APPLIED); if (ut_current_failed != 0) return; @@ -6035,55 +5780,57 @@ check_resource_x_terminal_local_owner_recycle_and_revoke( * The clock/BufferDesc proof inputs are fixture observations, not a replay * of C7's missing old-pair snapshot or a physical bufmgr DROP. */ UT_ASSERT_EQ(cluster_pcm_lock_resource_x_bootstrap_round_step_exact( - &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(10000), UINT64_C(6000), - UINT64_C(4000), UINT64_C(50), false, 0, &request, &terminal_ref), - RESOURCE_X_BOOTSTRAP_ROUND_DISPATCH_REQUEST); + &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(10000), UINT64_C(6000), + UINT64_C(4000), UINT64_C(50), false, 0, &request, &terminal_ref), + RESOURCE_X_BOOTSTRAP_ROUND_DISPATCH_REQUEST); UT_ASSERT_EQ(request.common.assertion_sequence, UINT64_C(2)); ack = make_resource_x_bootstrap_ack_values(&request, UINT64_C(12), UINT32_C(71)); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_bootstrap_round_accept_ack_exact( - &ack, 0, 61, 77, UINT64_C(4010), &assert_frame), - RESOURCE_X_BOOTSTRAP_ROUND_DISPATCH_ASSERT); + &ack, 0, 61, 77, UINT64_C(4010), &assert_frame), + RESOURCE_X_BOOTSTRAP_ROUND_DISPATCH_ASSERT); make_resource_x_remote_join_pair(tag, 1, &grant, &image); retarget_resource_x_remote_join_pair(&grant, &image, UINT64_C(14), UINT64_C(2)); { ResourceXRequesterJoinSnapshot join; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact( - &image, 0, &join), RESOURCE_X_APPLY_APPLIED); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact( - &grant, 0, &join), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact(&image, 0, &join), + RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact(&grant, 0, &join), + RESOURCE_X_APPLY_APPLIED); } expected_ref = make_resource_x_acquisition_ref(tag, 1, 17, 2); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_t1_grant_exact(&expected_ref), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_t1_grant_exact(&expected_ref), + RESOURCE_X_APPLY_APPLIED); memset(&install, 0, sizeof(install)); install.ownership_generation = next_generation; install.writer_activation_token = 1; install.resource_x_activation_generation = 2; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_apply_exact( - &expected_ref, &install), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_apply_exact(&expected_ref, &install), + RESOURCE_X_APPLY_APPLIED); memset(&activation, 0, sizeof(activation)); activation.ownership_generation = next_generation; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_activate_exact( - &expected_ref, &activation), RESOURCE_X_APPLY_APPLIED); - UT_ASSERT(cluster_pcm_lock_resource_x_bootstrap_round_cover_matches_exact( - &expected_ref, 31, 77, next_generation)); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_activate_exact(&expected_ref, &activation), + RESOURCE_X_APPLY_APPLIED); + UT_ASSERT(cluster_pcm_lock_resource_x_bootstrap_round_cover_matches_exact(&expected_ref, 31, 77, + next_generation)); if (ut_current_failed != 0) return; successor_block.common.base_authority_generation = UINT64_C(14); successor_block.common.authority_generation = UINT64_C(14); successor_block.common.assertion_sequence = next_attempt; - UT_ASSERT(resource_x_assertion_init(&tag, next_requester, - &successor_block.common.logical_assertion)); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_terminal_x_revoke_claim_exact( - &successor_block, 0, 77, next_generation, 1, 9, UINT64_C(4100), - &lineage, &revoke), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT( + resource_x_assertion_init(&tag, next_requester, &successor_block.common.logical_assertion)); + UT_ASSERT_EQ( + cluster_pcm_lock_resource_x_terminal_x_revoke_claim_exact( + &successor_block, 0, 77, next_generation, 1, 9, UINT64_C(4100), &lineage, &revoke), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(lineage.final_authority_generation, UINT64_C(14)); make_resource_x_remote_join_pair(tag, next_requester, &grant, &image); retarget_resource_x_remote_join_pair(&grant, &image, UINT64_C(16), next_attempt); image.common.ordered_lane = 0; - set_resource_x_test_source_fence(image.body.image_envelope.source_fence, - next_generation, PCM_STATE_X); + set_resource_x_test_source_fence(image.body.image_envelope.source_fence, next_generation, + PCM_STATE_X); image.body.image_envelope.source_carrier_generation = next_generation + 1; canonicalize_resource_x_test_image(&image); status.common = successor_block.common; @@ -6092,13 +5839,13 @@ check_resource_x_terminal_local_owner_recycle_and_revoke( status.common.outcome = RESOURCE_X_OUTCOME_OK; status.common.flags = RESOURCE_X_COMMON_FLAG_PI_ESTABLISHED; memcpy(status.body.blocked_to_n.source_fence, image.body.image_envelope.source_fence, - sizeof(status.body.blocked_to_n.source_fence)); + sizeof(status.body.blocked_to_n.source_fence)); status.body.blocked_to_n.source_carrier_generation = next_generation + 1; status.body.blocked_to_n.requester_target_generation = next_attempt; status.body.blocked_to_n.page_scn_lsn = image.body.image_envelope.page_scn_lsn; status.body.blocked_to_n.dependency_count = image.body.image_envelope.dependency_count; memcpy(status.body.blocked_to_n.dependencies, image.body.image_envelope.dependencies, - sizeof(status.body.blocked_to_n.dependencies)); + sizeof(status.body.blocked_to_n.dependencies)); status.body.blocked_to_n.source_proof_crc32c = image.common.semantic_crc32c; status.body.blocked_to_n.page_checksum = image.body.image_envelope.page_checksum; revoking.generation = next_generation; @@ -6106,36 +5853,43 @@ check_resource_x_terminal_local_owner_recycle_and_revoke( if (ut_current_failed != 0) return; if (next_generation <= UINT64_C(91)) - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_block_to_n_source_exact( - &successor_block, 0, &status, &image), RESOURCE_X_APPLY_STALE); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_block_to_n_source_exact(&successor_block, 0, + &status, &image), + RESOURCE_X_APPLY_STALE); stale = revoke; stale.owner_procno++; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_block_to_n_drop_x_source_exact( - &successor_block, 0, &status, &image, &revoking, &stale), RESOURCE_X_APPLY_STALE); + &successor_block, 0, &status, &image, &revoking, &stale), + RESOURCE_X_APPLY_STALE); if (next_requester == 2 && next_attempt <= UINT64_C(42)) { UT_ASSERT_EQ(cluster_pcm_lock_resource_x_block_to_n_drop_x_source_exact( - &successor_block, 0, &status, &image, &revoking, &revoke), RESOURCE_X_APPLY_STALE); + &successor_block, 0, &status, &image, &revoking, &revoke), + RESOURCE_X_APPLY_STALE); return; } UT_ASSERT_EQ(cluster_pcm_lock_resource_x_block_to_n_drop_x_source_exact( - &successor_block, 0, &status, &image, &revoking, &revoke), RESOURCE_X_APPLY_APPLIED); + &successor_block, 0, &status, &image, &revoking, &revoke), + RESOURCE_X_APPLY_APPLIED); if (ut_current_failed != 0) return; /* A delayed old DRAIN is idempotent, not permission to remove the new * pending pair or to recreate the old outbound intents. */ old_source_generation = UINT64_MAX; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_holder_pair_drain_prepare_exact( - &old_block.common.logical_assertion, UINT64_C(42), 0, 31, - &old_source_generation), RESOURCE_X_APPLY_DUPLICATE); + UT_ASSERT_EQ( + cluster_pcm_lock_resource_x_holder_pair_drain_prepare_exact( + &old_block.common.logical_assertion, UINT64_C(42), 0, 31, &old_source_generation), + RESOURCE_X_APPLY_DUPLICATE); UT_ASSERT_EQ(old_source_generation, UINT64_C(0)); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_holder_image_exact( - &successor_block.common.logical_assertion, &old_image), RESOURCE_X_APPLY_APPLIED); + &successor_block.common.logical_assertion, &old_image), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(old_image.common.assertion_sequence, next_attempt); UT_ASSERT_EQ(old_image.common.authority_generation, UINT64_C(15)); UT_ASSERT_EQ(old_image.body.image_envelope.source_carrier_generation, next_generation + 1); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_holder_image_intent_snapshot_exact( - &successor_block.common.logical_assertion, &old_image_intent, - old_image_payload, sizeof(old_image_payload)), RESOURCE_X_APPLY_NOT_FOUND); + &successor_block.common.logical_assertion, &old_image_intent, + old_image_payload, sizeof(old_image_payload)), + RESOURCE_X_APPLY_NOT_FOUND); } UT_TEST(test_resource_x_terminal_local_owner_serializes_recycle_and_revoke) @@ -6194,14 +5948,13 @@ UT_TEST(test_resource_x_bootstrap_round_waits_only_for_exact_target_install) reset_fake_pcm_runtime(4); cluster_node_id = 1; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), - RESOURCE_X_APPLY_APPLIED); + RESOURCE_X_APPLY_APPLIED); UT_ASSERT(resource_x_assertion_init(&tag, 1, &assertion)); action = cluster_pcm_lock_resource_x_bootstrap_round_step_exact( &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(1000), (UINT64_C(1000)) - (UINT64_C(100)), UINT64_C(100), UINT64_C(50), false, 0, &request, &terminal_ref); UT_ASSERT_EQ(action, RESOURCE_X_BOOTSTRAP_ROUND_DISPATCH_REQUEST); - ack = make_resource_x_bootstrap_ack_values( - &request, UINT64_C(9), UINT32_C(71)); + ack = make_resource_x_bootstrap_ack_values(&request, UINT64_C(9), UINT32_C(71)); action = cluster_pcm_lock_resource_x_bootstrap_round_accept_ack_exact( &ack, 0, 61, 77, UINT64_C(110), &assert_frame); UT_ASSERT_EQ(action, RESOURCE_X_BOOTSTRAP_ROUND_DISPATCH_ASSERT); @@ -6216,110 +5969,76 @@ UT_TEST(test_resource_x_bootstrap_round_waits_only_for_exact_target_install) installing.pcm_state = (uint8)PCM_STATE_N; installing.flags = PCM_OWN_FLAG_GRANT_PENDING; installing.reservation_token = 1; - UT_ASSERT( - !cluster_pcm_lock_resource_x_bootstrap_round_target_install_inflight_exact( - &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50), - &installing)); + UT_ASSERT(!cluster_pcm_lock_resource_x_bootstrap_round_target_install_inflight_exact( + &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50), &installing)); ref = make_resource_x_acquisition_ref(tag, 1, 17, 1); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_t1_grant_exact(&ref), - RESOURCE_X_APPLY_APPLIED); - UT_ASSERT( - cluster_pcm_lock_resource_x_bootstrap_round_target_install_inflight_exact( - &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50), - &installing)); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_t1_grant_exact(&ref), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT(cluster_pcm_lock_resource_x_bootstrap_round_target_install_inflight_exact( + &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50), &installing)); /* A conditional content-lock miss is the executor's retryable BLOCKED * state, not ownership loss. The same-node foreground follower must keep * waiting both before and after the existing scheduled tick rearms the * exact acquisition; dispatch_phase is a retry counter, not authority. */ - cluster_pcm_lock_resource_x_publish_no_progress_exact( - &ref, RESOURCE_X_NO_PROGRESS_BUFFER_BUSY); - UT_ASSERT( - cluster_pcm_lock_resource_x_bootstrap_round_target_install_inflight_exact( - &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50), - &installing)); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_executor_rearm_exact(&ref), - RESOURCE_X_APPLY_APPLIED); - UT_ASSERT( - cluster_pcm_lock_resource_x_bootstrap_round_target_install_inflight_exact( - &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50), - &installing)); - UT_ASSERT( - !cluster_pcm_lock_resource_x_bootstrap_round_target_install_inflight_exact( - &assertion, 0, 17, 31, 77, 51, 62, UINT64_C(50), - &installing)); + cluster_pcm_lock_resource_x_publish_no_progress_exact(&ref, RESOURCE_X_NO_PROGRESS_BUFFER_BUSY); + UT_ASSERT(cluster_pcm_lock_resource_x_bootstrap_round_target_install_inflight_exact( + &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50), &installing)); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_executor_rearm_exact(&ref), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT(cluster_pcm_lock_resource_x_bootstrap_round_target_install_inflight_exact( + &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50), &installing)); + UT_ASSERT(!cluster_pcm_lock_resource_x_bootstrap_round_target_install_inflight_exact( + &assertion, 0, 17, 31, 77, 51, 62, UINT64_C(50), &installing)); installing.writer_activation_token = 1; - UT_ASSERT( - !cluster_pcm_lock_resource_x_bootstrap_round_target_install_inflight_exact( - &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50), - &installing)); + UT_ASSERT(!cluster_pcm_lock_resource_x_bootstrap_round_target_install_inflight_exact( + &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50), &installing)); installing.writer_activation_token = 0; installing.reservation_token = 0; - UT_ASSERT( - !cluster_pcm_lock_resource_x_bootstrap_round_target_install_inflight_exact( - &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50), - &installing)); + UT_ASSERT(!cluster_pcm_lock_resource_x_bootstrap_round_target_install_inflight_exact( + &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50), &installing)); installing.reservation_token = 1; installing.pcm_state = (uint8)PCM_STATE_X; installing.flags = 0; installing.generation = 1; installing.writer_activation_token = 1; - UT_ASSERT( - cluster_pcm_lock_resource_x_bootstrap_round_target_install_inflight_exact( - &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50), - &installing)); + UT_ASSERT(cluster_pcm_lock_resource_x_bootstrap_round_target_install_inflight_exact( + &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50), &installing)); installing.writer_activation_token = 2; - UT_ASSERT( - !cluster_pcm_lock_resource_x_bootstrap_round_target_install_inflight_exact( - &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50), - &installing)); + UT_ASSERT(!cluster_pcm_lock_resource_x_bootstrap_round_target_install_inflight_exact( + &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50), &installing)); installing.writer_activation_token = 1; installing.resource_x_activation_generation = 1; - UT_ASSERT( - cluster_pcm_lock_resource_x_bootstrap_round_target_install_inflight_exact( - &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50), - &installing)); + UT_ASSERT(cluster_pcm_lock_resource_x_bootstrap_round_target_install_inflight_exact( + &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50), &installing)); installing.resource_x_activation_generation = 2; - UT_ASSERT( - !cluster_pcm_lock_resource_x_bootstrap_round_target_install_inflight_exact( - &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50), - &installing)); + UT_ASSERT(!cluster_pcm_lock_resource_x_bootstrap_round_target_install_inflight_exact( + &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50), &installing)); installing.resource_x_activation_generation = 1; memset(&install, 0, sizeof(install)); install.ownership_generation = 1; install.writer_activation_token = 1; install.resource_x_activation_generation = 1; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_apply_exact( - &ref, &install), RESOURCE_X_APPLY_APPLIED); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_executor_probe_exact( - &ref, &executor), RESOURCE_X_EXECUTOR_READY); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_apply_exact(&ref, &install), + RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_executor_probe_exact(&ref, &executor), + RESOURCE_X_EXECUTOR_READY); UT_ASSERT_EQ(executor.progress_flags, - RESOURCE_X_PROGRESS_BOUND | RESOURCE_X_PROGRESS_T1 - | RESOURCE_X_PROGRESS_T2); - UT_ASSERT( - cluster_pcm_lock_resource_x_bootstrap_round_target_install_inflight_exact( - &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50), - &installing)); + RESOURCE_X_PROGRESS_BOUND | RESOURCE_X_PROGRESS_T1 | RESOURCE_X_PROGRESS_T2); + UT_ASSERT(cluster_pcm_lock_resource_x_bootstrap_round_target_install_inflight_exact( + &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50), &installing)); /* T3 clears the Resource-X generation before the writer token. While * the canonical round still carries T2, that exact ordered half-clear is * part of the same install and must keep same-node followers waiting. */ installing.resource_x_activation_generation = 0; - UT_ASSERT( - cluster_pcm_lock_resource_x_bootstrap_round_target_install_inflight_exact( - &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50), - &installing)); + UT_ASSERT(cluster_pcm_lock_resource_x_bootstrap_round_target_install_inflight_exact( + &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50), &installing)); installing.writer_activation_token = 2; - UT_ASSERT( - !cluster_pcm_lock_resource_x_bootstrap_round_target_install_inflight_exact( - &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50), - &installing)); + UT_ASSERT(!cluster_pcm_lock_resource_x_bootstrap_round_target_install_inflight_exact( + &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50), &installing)); installing.resource_x_activation_generation = 1; installing.writer_activation_token = 0; - UT_ASSERT( - !cluster_pcm_lock_resource_x_bootstrap_round_target_install_inflight_exact( - &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50), - &installing)); + UT_ASSERT(!cluster_pcm_lock_resource_x_bootstrap_round_target_install_inflight_exact( + &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50), &installing)); } UT_TEST(test_resource_x_bootstrap_round_waits_across_exact_post_t3_cover_window) @@ -6338,27 +6057,25 @@ UT_TEST(test_resource_x_bootstrap_round_waits_across_exact_post_t3_cover_window) reset_fake_pcm_runtime(4); cluster_node_id = 1; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), - RESOURCE_X_APPLY_APPLIED); + RESOURCE_X_APPLY_APPLIED); UT_ASSERT(resource_x_assertion_init(&tag, 1, &assertion)); action = cluster_pcm_lock_resource_x_bootstrap_round_step_exact( &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(1000), (UINT64_C(1000)) - (UINT64_C(100)), UINT64_C(100), UINT64_C(50), false, 0, &request, &terminal_ref); UT_ASSERT_EQ(action, RESOURCE_X_BOOTSTRAP_ROUND_DISPATCH_REQUEST); - ack = make_resource_x_bootstrap_ack_values( - &request, UINT64_C(9), UINT32_C(71)); + ack = make_resource_x_bootstrap_ack_values(&request, UINT64_C(9), UINT32_C(71)); action = cluster_pcm_lock_resource_x_bootstrap_round_accept_ack_exact( &ack, 0, 61, 77, UINT64_C(110), &assert_frame); UT_ASSERT_EQ(action, RESOURCE_X_BOOTSTRAP_ROUND_DISPATCH_ASSERT); ref = make_resource_x_acquisition_ref(tag, 1, 17, 1); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_t1_grant_exact(&ref), - RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_t1_grant_exact(&ref), RESOURCE_X_APPLY_APPLIED); memset(&install, 0, sizeof(install)); install.ownership_generation = 9; install.writer_activation_token = 12; install.resource_x_activation_generation = 1; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_apply_exact( - &ref, &install), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_apply_exact(&ref, &install), + RESOURCE_X_APPLY_APPLIED); /* T3 has physically cleared the BufferDesc writer fence, but the same * executor has not yet entered the requester entry lock to retire T2 and @@ -6369,30 +6086,24 @@ UT_TEST(test_resource_x_bootstrap_round_waits_across_exact_post_t3_cover_window) post_t3.pcm_state = (uint8)PCM_STATE_X; post_t3.generation = install.ownership_generation; post_t3.reservation_token = install.writer_activation_token; - UT_ASSERT( - cluster_pcm_lock_resource_x_bootstrap_round_target_install_inflight_exact( - &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50), - &post_t3)); + UT_ASSERT(cluster_pcm_lock_resource_x_bootstrap_round_target_install_inflight_exact( + &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50), &post_t3)); post_t3.generation++; - UT_ASSERT( - !cluster_pcm_lock_resource_x_bootstrap_round_target_install_inflight_exact( - &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50), - &post_t3)); + UT_ASSERT(!cluster_pcm_lock_resource_x_bootstrap_round_target_install_inflight_exact( + &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50), &post_t3)); } static void -assert_resource_x_target_install_follow_state( - const ResourceXTargetInstallContinuation *follow, - const ClusterPcmOwnSnapshot *observed, - ResourceXTargetInstallFollowState expected) +assert_resource_x_target_install_follow_state(const ResourceXTargetInstallContinuation *follow, + const ClusterPcmOwnSnapshot *observed, + ResourceXTargetInstallFollowState expected) { ResourceXAcquisitionRef terminal_ref; ResourceXTargetInstallFollowState state; memset(&terminal_ref, 0x7f, sizeof(terminal_ref)); - state - = cluster_pcm_lock_resource_x_bootstrap_round_target_install_classify_exact( - follow, observed, &terminal_ref); + state = cluster_pcm_lock_resource_x_bootstrap_round_target_install_classify_exact( + follow, observed, &terminal_ref); UT_ASSERT_EQ(state, expected); if (expected != RESOURCE_X_TARGET_INSTALL_TERMINAL) UT_ASSERT_EQ(terminal_ref.acquisition_generation, UINT64_C(0)); @@ -6428,20 +6139,18 @@ UT_TEST(test_resource_x_target_install_continuation_classifies_exact_attempt) reset_fake_pcm_runtime(4); cluster_node_id = 1; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), - RESOURCE_X_APPLY_APPLIED); + RESOURCE_X_APPLY_APPLIED); UT_ASSERT(resource_x_assertion_init(&tag, 1, &assertion)); action = cluster_pcm_lock_resource_x_bootstrap_round_step_exact( &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(1000), (UINT64_C(1000)) - (UINT64_C(100)), UINT64_C(100), UINT64_C(50), false, 0, &request, &terminal_ref); UT_ASSERT_EQ(action, RESOURCE_X_BOOTSTRAP_ROUND_DISPATCH_REQUEST); - ack = make_resource_x_bootstrap_ack_values( - &request, UINT64_C(9), UINT32_C(71)); + ack = make_resource_x_bootstrap_ack_values(&request, UINT64_C(9), UINT32_C(71)); action = cluster_pcm_lock_resource_x_bootstrap_round_accept_ack_exact( &ack, 0, 61, 77, UINT64_C(110), &assert_frame); UT_ASSERT_EQ(action, RESOURCE_X_BOOTSTRAP_ROUND_DISPATCH_ASSERT); ref = make_resource_x_acquisition_ref(tag, 1, 17, 1); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_t1_grant_exact(&ref), - RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_t1_grant_exact(&ref), RESOURCE_X_APPLY_APPLIED); memset(&observed, 0, sizeof(observed)); observed.tag = tag; @@ -6457,20 +6166,17 @@ UT_TEST(test_resource_x_target_install_continuation_classifies_exact_attempt) late_observed = observed; late_observed.generation = 2; memset(&late_follow, 0x7f, sizeof(late_follow)); - state - = cluster_pcm_lock_resource_x_bootstrap_round_target_install_capture_exact( - &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50), - UINT64_C(900), &late_observed, &late_follow); + state = cluster_pcm_lock_resource_x_bootstrap_round_target_install_capture_exact( + &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50), UINT64_C(900), &late_observed, + &late_follow); UT_ASSERT_EQ(state, RESOURCE_X_TARGET_INSTALL_INFLIGHT); UT_ASSERT(late_follow.valid); UT_ASSERT_EQ(late_follow.pending_ownership_generation, UINT64_C(2)); UT_ASSERT_EQ(late_follow.expected_x_ownership_generation, UINT64_C(3)); UT_ASSERT_EQ(late_follow.reservation_token, UINT64_C(12)); memset(&follow, 0x7f, sizeof(follow)); - state - = cluster_pcm_lock_resource_x_bootstrap_round_target_install_capture_exact( - &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50), - UINT64_C(900), &observed, &follow); + state = cluster_pcm_lock_resource_x_bootstrap_round_target_install_capture_exact( + &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50), UINT64_C(900), &observed, &follow); UT_ASSERT_EQ(state, RESOURCE_X_TARGET_INSTALL_INFLIGHT); UT_ASSERT(follow.valid); UT_ASSERT_EQ(follow.requester_node, 1); @@ -6489,9 +6195,8 @@ UT_TEST(test_resource_x_target_install_continuation_classifies_exact_attempt) UT_ASSERT_EQ(follow.reservation_token, UINT64_C(12)); memset(&terminal_ref, 0x7f, sizeof(terminal_ref)); - state - = cluster_pcm_lock_resource_x_bootstrap_round_target_install_classify_exact( - &follow, &observed, &terminal_ref); + state = cluster_pcm_lock_resource_x_bootstrap_round_target_install_classify_exact( + &follow, &observed, &terminal_ref); UT_ASSERT_EQ(state, RESOURCE_X_TARGET_INSTALL_INFLIGHT); UT_ASSERT_EQ(terminal_ref.acquisition_generation, UINT64_C(0)); @@ -6500,22 +6205,18 @@ UT_TEST(test_resource_x_target_install_continuation_classifies_exact_attempt) observed.flags = 0; observed.generation = 1; observed.writer_activation_token = 12; - state - = cluster_pcm_lock_resource_x_bootstrap_round_target_install_classify_exact( - &follow, &observed, &terminal_ref); + state = cluster_pcm_lock_resource_x_bootstrap_round_target_install_classify_exact( + &follow, &observed, &terminal_ref); UT_ASSERT_EQ(state, RESOURCE_X_TARGET_INSTALL_INFLIGHT); memset(&captured, 0x7f, sizeof(captured)); - state - = cluster_pcm_lock_resource_x_bootstrap_round_target_install_capture_exact( - &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50), - UINT64_C(900), &observed, &captured); + state = cluster_pcm_lock_resource_x_bootstrap_round_target_install_capture_exact( + &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50), UINT64_C(900), &observed, &captured); UT_ASSERT_EQ(state, RESOURCE_X_TARGET_INSTALL_INFLIGHT); UT_ASSERT_EQ(captured.pending_ownership_generation, UINT64_C(0)); UT_ASSERT_EQ(captured.expected_x_ownership_generation, UINT64_C(1)); UT_ASSERT_EQ(captured.reservation_token, UINT64_C(12)); UT_ASSERT_EQ(captured.acquisition_generation, follow.acquisition_generation); - UT_ASSERT_EQ(captured.entry_binding_generation, - follow.entry_binding_generation); + UT_ASSERT_EQ(captured.entry_binding_generation, follow.entry_binding_generation); /* I2: the exact requester apply publishes T2 and the attempt activation. */ memset(&install, 0, sizeof(install)); @@ -6523,18 +6224,15 @@ UT_TEST(test_resource_x_target_install_continuation_classifies_exact_attempt) install.writer_activation_token = 12; install.resource_x_activation_generation = 1; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_apply_exact(&ref, &install), - RESOURCE_X_APPLY_APPLIED); + RESOURCE_X_APPLY_APPLIED); observed.resource_x_activation_generation = 1; preterminal_observed = observed; - state - = cluster_pcm_lock_resource_x_bootstrap_round_target_install_classify_exact( - &follow, &observed, &terminal_ref); + state = cluster_pcm_lock_resource_x_bootstrap_round_target_install_classify_exact( + &follow, &observed, &terminal_ref); UT_ASSERT_EQ(state, RESOURCE_X_TARGET_INSTALL_INFLIGHT); memset(&captured, 0x7f, sizeof(captured)); - state - = cluster_pcm_lock_resource_x_bootstrap_round_target_install_capture_exact( - &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50), - UINT64_C(900), &observed, &captured); + state = cluster_pcm_lock_resource_x_bootstrap_round_target_install_capture_exact( + &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50), UINT64_C(900), &observed, &captured); UT_ASSERT_EQ(state, RESOURCE_X_TARGET_INSTALL_INFLIGHT); UT_ASSERT_EQ(captured.pending_ownership_generation, UINT64_C(0)); UT_ASSERT_EQ(captured.acquisition_generation, follow.acquisition_generation); @@ -6542,96 +6240,83 @@ UT_TEST(test_resource_x_target_install_continuation_classifies_exact_attempt) /* I3: the BufferDesc fence is clear while terminal publication is pending. */ observed.writer_activation_token = 0; observed.resource_x_activation_generation = 0; - state - = cluster_pcm_lock_resource_x_bootstrap_round_target_install_classify_exact( - &follow, &observed, &terminal_ref); + state = cluster_pcm_lock_resource_x_bootstrap_round_target_install_classify_exact( + &follow, &observed, &terminal_ref); UT_ASSERT_EQ(state, RESOURCE_X_TARGET_INSTALL_INFLIGHT); memset(&captured, 0x7f, sizeof(captured)); - state - = cluster_pcm_lock_resource_x_bootstrap_round_target_install_capture_exact( - &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50), - UINT64_C(900), &observed, &captured); + state = cluster_pcm_lock_resource_x_bootstrap_round_target_install_capture_exact( + &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50), UINT64_C(900), &observed, &captured); UT_ASSERT_EQ(state, RESOURCE_X_TARGET_INSTALL_INFLIGHT); UT_ASSERT_EQ(captured.pending_ownership_generation, UINT64_C(0)); UT_ASSERT_EQ(captured.acquisition_generation, follow.acquisition_generation); memset(&before_negative, 0, sizeof(before_negative)); - UT_ASSERT_EQ( - cluster_pcm_lock_resource_x_bootstrap_round_failure_snapshot_exact( - &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50), - &before_negative), - RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_bootstrap_round_failure_snapshot_exact( + &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50), &before_negative), + RESOURCE_X_APPLY_APPLIED); /* Same-attempt malformed observations are fail-closed, never contention. */ changed = observed; changed.tag = make_tag(216); - assert_resource_x_target_install_follow_state( - &follow, &changed, RESOURCE_X_TARGET_INSTALL_STALE); + assert_resource_x_target_install_follow_state(&follow, &changed, + RESOURCE_X_TARGET_INSTALL_STALE); changed = observed; changed.reservation_token++; - assert_resource_x_target_install_follow_state( - &follow, &changed, RESOURCE_X_TARGET_INSTALL_STALE); + assert_resource_x_target_install_follow_state(&follow, &changed, + RESOURCE_X_TARGET_INSTALL_STALE); changed = observed; changed.generation++; - assert_resource_x_target_install_follow_state( - &follow, &changed, RESOURCE_X_TARGET_INSTALL_STALE); + assert_resource_x_target_install_follow_state(&follow, &changed, + RESOURCE_X_TARGET_INSTALL_STALE); changed = observed; changed.pcm_state = (uint8)PCM_STATE_S; - assert_resource_x_target_install_follow_state( - &follow, &changed, RESOURCE_X_TARGET_INSTALL_RECOVERY_BLOCKED); + assert_resource_x_target_install_follow_state(&follow, &changed, + RESOURCE_X_TARGET_INSTALL_RECOVERY_BLOCKED); changed.pcm_state = (uint8)PCM_STATE_READ_IMAGE; - assert_resource_x_target_install_follow_state( - &follow, &changed, RESOURCE_X_TARGET_INSTALL_RECOVERY_BLOCKED); + assert_resource_x_target_install_follow_state(&follow, &changed, + RESOURCE_X_TARGET_INSTALL_RECOVERY_BLOCKED); changed = observed; changed.pcm_state = (uint8)PCM_STATE_N; changed.generation = 0; - assert_resource_x_target_install_follow_state( - &follow, &changed, RESOURCE_X_TARGET_INSTALL_RECOVERY_BLOCKED); + assert_resource_x_target_install_follow_state(&follow, &changed, + RESOURCE_X_TARGET_INSTALL_RECOVERY_BLOCKED); changed = observed; changed.flags = PCM_OWN_FLAG_REVOKING; - assert_resource_x_target_install_follow_state( - &follow, &changed, RESOURCE_X_TARGET_INSTALL_RECOVERY_BLOCKED); + assert_resource_x_target_install_follow_state(&follow, &changed, + RESOURCE_X_TARGET_INSTALL_RECOVERY_BLOCKED); changed = observed; changed.writer_activation_token = changed.reservation_token; changed.resource_x_activation_generation = 2; - assert_resource_x_target_install_follow_state( - &follow, &changed, RESOURCE_X_TARGET_INSTALL_RECOVERY_BLOCKED); + assert_resource_x_target_install_follow_state(&follow, &changed, + RESOURCE_X_TARGET_INSTALL_RECOVERY_BLOCKED); changed = observed; changed.resource_x_activation_generation = 1; - assert_resource_x_target_install_follow_state( - &follow, &changed, RESOURCE_X_TARGET_INSTALL_RECOVERY_BLOCKED); + assert_resource_x_target_install_follow_state(&follow, &changed, + RESOURCE_X_TARGET_INSTALL_RECOVERY_BLOCKED); changed = observed; changed.generation = 0; memset(&captured, 0x7f, sizeof(captured)); - state - = cluster_pcm_lock_resource_x_bootstrap_round_target_install_capture_exact( - &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50), - UINT64_C(900), &changed, &captured); + state = cluster_pcm_lock_resource_x_bootstrap_round_target_install_capture_exact( + &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50), UINT64_C(900), &changed, &captured); UT_ASSERT_EQ(state, RESOURCE_X_TARGET_INSTALL_RECOVERY_BLOCKED); UT_ASSERT(!captured.valid); memset(&after_negative, 0, sizeof(after_negative)); - UT_ASSERT_EQ( - cluster_pcm_lock_resource_x_bootstrap_round_failure_snapshot_exact( - &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50), - &after_negative), - RESOURCE_X_APPLY_APPLIED); - UT_ASSERT_EQ(memcmp(&before_negative, &after_negative, - sizeof(before_negative)), 0); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_bootstrap_round_failure_snapshot_exact( + &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50), &after_negative), + RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(memcmp(&before_negative, &after_negative, sizeof(before_negative)), 0); /* Exact terminal cover is the only state that returns the acquisition ref. */ memset(&activation, 0, sizeof(activation)); activation.ownership_generation = 1; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_activate_exact( - &ref, &activation), RESOURCE_X_APPLY_APPLIED); - UT_ASSERT_EQ( - cluster_pcm_lock_resource_x_bootstrap_round_publish_terminal_exact( - &ref, 31, 77, 1, 10, UINT64_C(120)), - RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_activate_exact(&ref, &activation), + RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_bootstrap_round_publish_terminal_exact( + &ref, 31, 77, 1, 10, UINT64_C(120)), + RESOURCE_X_APPLY_APPLIED); memset(&terminal_snapshot, 0, sizeof(terminal_snapshot)); - UT_ASSERT_EQ( - cluster_pcm_lock_resource_x_bootstrap_round_failure_snapshot_exact( - &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50), - &terminal_snapshot), - RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_bootstrap_round_failure_snapshot_exact( + &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50), &terminal_snapshot), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(terminal_snapshot.round_phase, UINT8_C(4)); UT_ASSERT_EQ(terminal_snapshot.terminal, UINT8_C(1)); UT_ASSERT_EQ(terminal_snapshot.buffer_ownership_generation, UINT64_C(1)); @@ -6640,75 +6325,68 @@ UT_TEST(test_resource_x_target_install_continuation_classifies_exact_attempt) * N+GRANT_PENDING(2) sample predicted an unrelated X(3). Pending, aborted * clean N and a later N revoke are all receipt invalidation only. */ memset(&late_owner, 0, sizeof(late_owner)); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_itl_recycle_begin_exact( - &ref, 31, 77, 1, 12, 7, UINT64_C(130), &late_owner), - RESOURCE_X_APPLY_APPLIED); - assert_resource_x_target_install_follow_state( - &late_follow, &late_observed, RESOURCE_X_TARGET_INSTALL_PREUSE_RETRY); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_itl_recycle_begin_exact(&ref, 31, 77, 1, 12, 7, + UINT64_C(130), &late_owner), + RESOURCE_X_APPLY_APPLIED); + assert_resource_x_target_install_follow_state(&late_follow, &late_observed, + RESOURCE_X_TARGET_INSTALL_PREUSE_RETRY); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_itl_recycle_cancel_exact(&late_owner), - RESOURCE_X_APPLY_APPLIED); + RESOURCE_X_APPLY_APPLIED); memset(&captured, 0x7f, sizeof(captured)); - state - = cluster_pcm_lock_resource_x_bootstrap_round_target_install_capture_exact( - &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50), - UINT64_C(900), &late_observed, &captured); + state = cluster_pcm_lock_resource_x_bootstrap_round_target_install_capture_exact( + &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50), UINT64_C(900), &late_observed, &captured); UT_ASSERT_EQ(state, RESOURCE_X_TARGET_INSTALL_STALE); UT_ASSERT(!captured.valid); late_observed.flags = 0; - assert_resource_x_target_install_follow_state( - &late_follow, &late_observed, RESOURCE_X_TARGET_INSTALL_PREUSE_RETRY); + assert_resource_x_target_install_follow_state(&late_follow, &late_observed, + RESOURCE_X_TARGET_INSTALL_PREUSE_RETRY); memset(&captured, 0x7f, sizeof(captured)); - state - = cluster_pcm_lock_resource_x_bootstrap_round_target_install_capture_exact( - &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50), - UINT64_C(900), &late_observed, &captured); + state = cluster_pcm_lock_resource_x_bootstrap_round_target_install_capture_exact( + &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50), UINT64_C(900), &late_observed, &captured); UT_ASSERT_EQ(state, RESOURCE_X_TARGET_INSTALL_STALE); UT_ASSERT(!captured.valid); late_observed.flags = PCM_OWN_FLAG_REVOKING; late_observed.reservation_token = 13; - assert_resource_x_target_install_follow_state( - &late_follow, &late_observed, RESOURCE_X_TARGET_INSTALL_PREUSE_RETRY); + assert_resource_x_target_install_follow_state(&late_follow, &late_observed, + RESOURCE_X_TARGET_INSTALL_PREUSE_RETRY); memset(&captured, 0x7f, sizeof(captured)); - state - = cluster_pcm_lock_resource_x_bootstrap_round_target_install_capture_exact( - &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50), - UINT64_C(900), &late_observed, &captured); + state = cluster_pcm_lock_resource_x_bootstrap_round_target_install_capture_exact( + &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50), UINT64_C(900), &late_observed, &captured); UT_ASSERT_EQ(state, RESOURCE_X_TARGET_INSTALL_STALE); UT_ASSERT(!captured.valid); /* The amendment is deliberately not a generic generation/token retry. */ changed = late_observed; changed.generation++; - assert_resource_x_target_install_follow_state( - &late_follow, &changed, RESOURCE_X_TARGET_INSTALL_RECOVERY_BLOCKED); + assert_resource_x_target_install_follow_state(&late_follow, &changed, + RESOURCE_X_TARGET_INSTALL_RECOVERY_BLOCKED); changed = late_observed; changed.reservation_token = 11; - assert_resource_x_target_install_follow_state( - &late_follow, &changed, RESOURCE_X_TARGET_INSTALL_RECOVERY_BLOCKED); + assert_resource_x_target_install_follow_state(&late_follow, &changed, + RESOURCE_X_TARGET_INSTALL_RECOVERY_BLOCKED); changed = late_observed; changed.reservation_token = UINT64_MAX; - assert_resource_x_target_install_follow_state( - &late_follow, &changed, RESOURCE_X_TARGET_INSTALL_RECOVERY_BLOCKED); + assert_resource_x_target_install_follow_state(&late_follow, &changed, + RESOURCE_X_TARGET_INSTALL_RECOVERY_BLOCKED); changed = late_observed; changed.writer_activation_token = changed.reservation_token; - assert_resource_x_target_install_follow_state( - &late_follow, &changed, RESOURCE_X_TARGET_INSTALL_RECOVERY_BLOCKED); + assert_resource_x_target_install_follow_state(&late_follow, &changed, + RESOURCE_X_TARGET_INSTALL_RECOVERY_BLOCKED); changed = late_observed; changed.pcm_state = (uint8)PCM_STATE_X; - assert_resource_x_target_install_follow_state( - &late_follow, &changed, RESOURCE_X_TARGET_INSTALL_RECOVERY_BLOCKED); + assert_resource_x_target_install_follow_state(&late_follow, &changed, + RESOURCE_X_TARGET_INSTALL_RECOVERY_BLOCKED); stale = late_follow; stale.observed_claim_pending_generation = 2; stale.observed_claim_reservation_token = 12; - assert_resource_x_target_install_follow_state( - &stale, &late_observed, RESOURCE_X_TARGET_INSTALL_STALE); + assert_resource_x_target_install_follow_state(&stale, &late_observed, + RESOURCE_X_TARGET_INSTALL_STALE); memset(&terminal_ref, 0, sizeof(terminal_ref)); - state - = cluster_pcm_lock_resource_x_bootstrap_round_target_install_classify_exact( - &follow, &observed, &terminal_ref); + state = cluster_pcm_lock_resource_x_bootstrap_round_target_install_classify_exact( + &follow, &observed, &terminal_ref); UT_ASSERT_EQ(state, RESOURCE_X_TARGET_INSTALL_TERMINAL); UT_ASSERT_EQ(memcmp(&terminal_ref, &ref, sizeof(ref)), 0); @@ -6722,52 +6400,51 @@ UT_TEST(test_resource_x_target_install_continuation_classifies_exact_attempt) changed.generation = follow.pending_ownership_generation; changed.writer_activation_token = 0; changed.resource_x_activation_generation = 0; - assert_resource_x_target_install_follow_state( - &follow, &changed, RESOURCE_X_TARGET_INSTALL_RECOVERY_BLOCKED); + assert_resource_x_target_install_follow_state(&follow, &changed, + RESOURCE_X_TARGET_INSTALL_RECOVERY_BLOCKED); changed = preterminal_observed; changed.resource_x_activation_generation = 0; - assert_resource_x_target_install_follow_state( - &follow, &changed, RESOURCE_X_TARGET_INSTALL_RECOVERY_BLOCKED); + assert_resource_x_target_install_follow_state(&follow, &changed, + RESOURCE_X_TARGET_INSTALL_RECOVERY_BLOCKED); memset(&terminal_ref, 0x7f, sizeof(terminal_ref)); - state - = cluster_pcm_lock_resource_x_bootstrap_round_target_install_classify_exact( - &follow, &preterminal_observed, &terminal_ref); + state = cluster_pcm_lock_resource_x_bootstrap_round_target_install_classify_exact( + &follow, &preterminal_observed, &terminal_ref); UT_ASSERT_EQ(state, RESOURCE_X_TARGET_INSTALL_RECOVERY_BLOCKED); UT_ASSERT_EQ(terminal_ref.acquisition_generation, UINT64_C(0)); /* Each coherent immutable-axis drift is stale and returns no terminal ref. */ stale = follow; stale.entry_binding_generation++; - assert_resource_x_target_install_follow_state( - &stale, &observed, RESOURCE_X_TARGET_INSTALL_STALE); + assert_resource_x_target_install_follow_state(&stale, &observed, + RESOURCE_X_TARGET_INSTALL_STALE); stale = follow; stale.resource = make_tag(216); - assert_resource_x_target_install_follow_state( - &stale, &observed, RESOURCE_X_TARGET_INSTALL_STALE); + assert_resource_x_target_install_follow_state(&stale, &observed, + RESOURCE_X_TARGET_INSTALL_STALE); stale = follow; stale.master_node = 2; - assert_resource_x_target_install_follow_state( - &stale, &observed, RESOURCE_X_TARGET_INSTALL_STALE); + assert_resource_x_target_install_follow_state(&stale, &observed, + RESOURCE_X_TARGET_INSTALL_STALE); stale = follow; stale.resource_formation++; - assert_resource_x_target_install_follow_state( - &stale, &observed, RESOURCE_X_TARGET_INSTALL_STALE); + assert_resource_x_target_install_follow_state(&stale, &observed, + RESOURCE_X_TARGET_INSTALL_STALE); stale = follow; stale.master_session_incarnation++; - assert_resource_x_target_install_follow_state( - &stale, &observed, RESOURCE_X_TARGET_INSTALL_STALE); + assert_resource_x_target_install_follow_state(&stale, &observed, + RESOURCE_X_TARGET_INSTALL_STALE); stale = follow; stale.r4_record_generation++; - assert_resource_x_target_install_follow_state( - &stale, &observed, RESOURCE_X_TARGET_INSTALL_STALE); + assert_resource_x_target_install_follow_state(&stale, &observed, + RESOURCE_X_TARGET_INSTALL_STALE); stale = follow; stale.acquisition_generation++; - assert_resource_x_target_install_follow_state( - &stale, &observed, RESOURCE_X_TARGET_INSTALL_STALE); + assert_resource_x_target_install_follow_state(&stale, &observed, + RESOURCE_X_TARGET_INSTALL_STALE); stale = follow; stale.accepted_base_authority_generation++; - assert_resource_x_target_install_follow_state( - &stale, &observed, RESOURCE_X_TARGET_INSTALL_STALE); + assert_resource_x_target_install_follow_state(&stale, &observed, + RESOURCE_X_TARGET_INSTALL_STALE); stale = follow; stale.observed_head_change_generation++; assert_resource_x_target_install_follow_state(&stale, &observed, @@ -6779,35 +6456,34 @@ UT_TEST(test_resource_x_target_install_continuation_classifies_exact_attempt) stale = follow; stale.pending_ownership_generation++; stale.expected_x_ownership_generation++; - assert_resource_x_target_install_follow_state( - &stale, &observed, RESOURCE_X_TARGET_INSTALL_RECOVERY_BLOCKED); + assert_resource_x_target_install_follow_state(&stale, &observed, + RESOURCE_X_TARGET_INSTALL_RECOVERY_BLOCKED); stale = follow; stale.reservation_token++; - assert_resource_x_target_install_follow_state( - &stale, &observed, RESOURCE_X_TARGET_INSTALL_STALE); + assert_resource_x_target_install_follow_state(&stale, &observed, + RESOURCE_X_TARGET_INSTALL_STALE); stale = follow; stale.observed_claim_pending_generation = 3; stale.observed_claim_reservation_token = 4; - assert_resource_x_target_install_follow_state( - &stale, &observed, RESOURCE_X_TARGET_INSTALL_STALE); + assert_resource_x_target_install_follow_state(&stale, &observed, + RESOURCE_X_TARGET_INSTALL_STALE); stale = follow; stale.requester_sender_connection_generation++; - assert_resource_x_target_install_follow_state( - &stale, &observed, RESOURCE_X_TARGET_INSTALL_STALE); + assert_resource_x_target_install_follow_state(&stale, &observed, + RESOURCE_X_TARGET_INSTALL_STALE); stale = follow; stale.master_ingress_connection_generation++; - assert_resource_x_target_install_follow_state( - &stale, &observed, RESOURCE_X_TARGET_INSTALL_STALE); + assert_resource_x_target_install_follow_state(&stale, &observed, + RESOURCE_X_TARGET_INSTALL_STALE); /* A malformed same-identity X shape is not ordinary contention. */ observed.flags = PCM_OWN_FLAG_REVOKING; - state - = cluster_pcm_lock_resource_x_bootstrap_round_target_install_classify_exact( - &follow, &observed, &terminal_ref); + state = cluster_pcm_lock_resource_x_bootstrap_round_target_install_classify_exact( + &follow, &observed, &terminal_ref); UT_ASSERT_EQ(state, RESOURCE_X_TARGET_INSTALL_RECOVERY_BLOCKED); memset(&invalid, 0, sizeof(invalid)); - assert_resource_x_target_install_follow_state( - &invalid, &observed, RESOURCE_X_TARGET_INSTALL_INVALID); + assert_resource_x_target_install_follow_state(&invalid, &observed, + RESOURCE_X_TARGET_INSTALL_INVALID); } UT_TEST(test_resource_x_target_install_stable_direct_init_i0_t2_is_closed) @@ -6834,7 +6510,7 @@ UT_TEST(test_resource_x_target_install_stable_direct_init_i0_t2_is_closed) reset_fake_pcm_runtime(4); cluster_node_id = 1; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), - RESOURCE_X_APPLY_APPLIED); + RESOURCE_X_APPLY_APPLIED); UT_ASSERT(resource_x_assertion_init(&tag, 1, &assertion)); INSTR_TIME_SET_CURRENT(clock); now_us = (uint64)INSTR_TIME_GET_MICROSEC(clock); @@ -6844,14 +6520,12 @@ UT_TEST(test_resource_x_target_install_stable_direct_init_i0_t2_is_closed) &assertion, 0, 17, 31, 77, 51, 61, round_deadline_us, (round_deadline_us) - (now_us), now_us, UINT64_C(50000), 0, 12, false, 0, &request, &terminal_ref); UT_ASSERT_EQ(action, RESOURCE_X_BOOTSTRAP_ROUND_DISPATCH_REQUEST); - ack = make_resource_x_bootstrap_ack_values( - &request, UINT64_C(9), UINT32_C(71)); + ack = make_resource_x_bootstrap_ack_values(&request, UINT64_C(9), UINT32_C(71)); action = cluster_pcm_lock_resource_x_bootstrap_round_accept_ack_exact( &ack, 0, 61, 77, now_us + 1, &assert_frame); UT_ASSERT_EQ(action, RESOURCE_X_BOOTSTRAP_ROUND_DISPATCH_ASSERT); ref = make_resource_x_acquisition_ref(tag, 1, 17, 1); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_t1_grant_exact(&ref), - RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_t1_grant_exact(&ref), RESOURCE_X_APPLY_APPLIED); memset(&observed_i0, 0, sizeof(observed_i0)); observed_i0.tag = tag; @@ -6860,10 +6534,9 @@ UT_TEST(test_resource_x_target_install_stable_direct_init_i0_t2_is_closed) observed_i0.generation = 0; observed_i0.reservation_token = 12; memset(&follow, 0x7f, sizeof(follow)); - state - = cluster_pcm_lock_resource_x_bootstrap_round_target_install_capture_exact( - &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50000), - round_deadline_us, &observed_i0, &follow); + state = cluster_pcm_lock_resource_x_bootstrap_round_target_install_capture_exact( + &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50000), round_deadline_us, &observed_i0, + &follow); UT_ASSERT_EQ(state, RESOURCE_X_TARGET_INSTALL_INFLIGHT); UT_ASSERT(follow.valid); UT_ASSERT_EQ(follow.observed_claim_pending_generation, UINT64_C(0)); @@ -6879,85 +6552,73 @@ UT_TEST(test_resource_x_target_install_stable_direct_init_i0_t2_is_closed) install.writer_activation_token = 12; install.resource_x_activation_generation = 1; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_apply_exact(&ref, &install), - RESOURCE_X_APPLY_APPLIED); + RESOURCE_X_APPLY_APPLIED); memset(&terminal_ref, 0x7f, sizeof(terminal_ref)); - state - = cluster_pcm_lock_resource_x_bootstrap_round_target_install_classify_exact( - &follow, &observed_i0, &terminal_ref); + state = cluster_pcm_lock_resource_x_bootstrap_round_target_install_classify_exact( + &follow, &observed_i0, &terminal_ref); UT_ASSERT_EQ(state, RESOURCE_X_TARGET_INSTALL_RECOVERY_BLOCKED); UT_ASSERT_EQ(terminal_ref.acquisition_generation, UINT64_C(0)); /* No-progress debt cannot borrow A33's sampled-order classification. */ - cluster_pcm_lock_resource_x_publish_no_progress_exact( - &ref, RESOURCE_X_NO_PROGRESS_BUFFER_BUSY); - assert_resource_x_target_install_follow_state( - &follow, &observed_i0, - RESOURCE_X_TARGET_INSTALL_RECOVERY_BLOCKED); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_executor_rearm_exact(&ref), - RESOURCE_X_APPLY_APPLIED); - assert_resource_x_target_install_follow_state( - &follow, &observed_i0, - RESOURCE_X_TARGET_INSTALL_RECOVERY_BLOCKED); + cluster_pcm_lock_resource_x_publish_no_progress_exact(&ref, RESOURCE_X_NO_PROGRESS_BUFFER_BUSY); + assert_resource_x_target_install_follow_state(&follow, &observed_i0, + RESOURCE_X_TARGET_INSTALL_RECOVERY_BLOCKED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_executor_rearm_exact(&ref), RESOURCE_X_APPLY_APPLIED); + assert_resource_x_target_install_follow_state(&follow, &observed_i0, + RESOURCE_X_TARGET_INSTALL_RECOVERY_BLOCKED); /* Direct-init identity and the exact I0 envelope are mandatory. */ changed_follow = follow; changed_follow.observed_claim_reservation_token++; - assert_resource_x_target_install_follow_state( - &changed_follow, &observed_i0, RESOURCE_X_TARGET_INSTALL_STALE); + assert_resource_x_target_install_follow_state(&changed_follow, &observed_i0, + RESOURCE_X_TARGET_INSTALL_STALE); changed_i0 = observed_i0; changed_i0.flags = 0; - assert_resource_x_target_install_follow_state( - &follow, &changed_i0, - RESOURCE_X_TARGET_INSTALL_RECOVERY_BLOCKED); + assert_resource_x_target_install_follow_state(&follow, &changed_i0, + RESOURCE_X_TARGET_INSTALL_RECOVERY_BLOCKED); changed_i0 = observed_i0; changed_i0.reservation_token++; - assert_resource_x_target_install_follow_state( - &follow, &changed_i0, RESOURCE_X_TARGET_INSTALL_STALE); + assert_resource_x_target_install_follow_state(&follow, &changed_i0, + RESOURCE_X_TARGET_INSTALL_STALE); /* T3 retires the active ledger. The old I0 cannot bridge that state or * produce terminal authority. */ memset(&activation, 0, sizeof(activation)); activation.ownership_generation = 1; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_activate_exact( - &ref, &activation), RESOURCE_X_APPLY_APPLIED); - assert_resource_x_target_install_follow_state( - &follow, &observed_i0, - RESOURCE_X_TARGET_INSTALL_RECOVERY_BLOCKED); - UT_ASSERT_EQ( - cluster_pcm_lock_resource_x_bootstrap_round_publish_terminal_exact( - &ref, 31, 77, 1, 10, now_us + 2), - RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_activate_exact(&ref, &activation), + RESOURCE_X_APPLY_APPLIED); + assert_resource_x_target_install_follow_state(&follow, &observed_i0, + RESOURCE_X_TARGET_INSTALL_RECOVERY_BLOCKED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_bootstrap_round_publish_terminal_exact(&ref, 31, 77, 1, + 10, now_us + 2), + RESOURCE_X_APPLY_APPLIED); /* Ordinary T1/T2 has no exact BufferDesc token binding. Keep A30's * misbound-I0 protection closed. */ reset_fake_pcm_runtime(4); cluster_node_id = 1; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), - RESOURCE_X_APPLY_APPLIED); + RESOURCE_X_APPLY_APPLIED); UT_ASSERT(resource_x_assertion_init(&tag, 1, &assertion)); action = cluster_pcm_lock_resource_x_bootstrap_round_step_exact( &assertion, 0, 17, 31, 77, 51, 61, round_deadline_us, (round_deadline_us) - (now_us), now_us, UINT64_C(50000), false, 0, &request, &terminal_ref); UT_ASSERT_EQ(action, RESOURCE_X_BOOTSTRAP_ROUND_DISPATCH_REQUEST); - ack = make_resource_x_bootstrap_ack_values( - &request, UINT64_C(9), UINT32_C(71)); + ack = make_resource_x_bootstrap_ack_values(&request, UINT64_C(9), UINT32_C(71)); action = cluster_pcm_lock_resource_x_bootstrap_round_accept_ack_exact( &ack, 0, 61, 77, now_us + 1, &assert_frame); UT_ASSERT_EQ(action, RESOURCE_X_BOOTSTRAP_ROUND_DISPATCH_ASSERT); ref = make_resource_x_acquisition_ref(tag, 1, 17, 1); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_t1_grant_exact(&ref), - RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_t1_grant_exact(&ref), RESOURCE_X_APPLY_APPLIED); memset(&follow, 0x7f, sizeof(follow)); - state - = cluster_pcm_lock_resource_x_bootstrap_round_target_install_capture_exact( - &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50000), - round_deadline_us, &observed_i0, &follow); + state = cluster_pcm_lock_resource_x_bootstrap_round_target_install_capture_exact( + &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50000), round_deadline_us, &observed_i0, + &follow); UT_ASSERT_EQ(state, RESOURCE_X_TARGET_INSTALL_INFLIGHT); UT_ASSERT_EQ(follow.observed_claim_reservation_token, UINT64_C(0)); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_apply_exact(&ref, &install), - RESOURCE_X_APPLY_APPLIED); - assert_resource_x_target_install_follow_state( - &follow, &observed_i0, - RESOURCE_X_TARGET_INSTALL_RECOVERY_BLOCKED); + RESOURCE_X_APPLY_APPLIED); + assert_resource_x_target_install_follow_state(&follow, &observed_i0, + RESOURCE_X_TARGET_INSTALL_RECOVERY_BLOCKED); } static ResourceXAcquisitionRef target_wait_race_ref; @@ -7072,7 +6733,7 @@ UT_TEST(test_resource_x_target_install_wait_uses_receipt_and_fixed_deadline) reset_fake_pcm_runtime(4); cluster_node_id = 1; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), - RESOURCE_X_APPLY_APPLIED); + RESOURCE_X_APPLY_APPLIED); UT_ASSERT(resource_x_assertion_init(&tag, 1, &assertion)); INSTR_TIME_SET_CURRENT(clock); now_us = (uint64)INSTR_TIME_GET_MICROSEC(clock); @@ -7081,14 +6742,12 @@ UT_TEST(test_resource_x_target_install_wait_uses_receipt_and_fixed_deadline) &assertion, 0, 17, 31, 77, 51, 61, round_deadline_us, (round_deadline_us) - (now_us), now_us, UINT64_C(50000), false, 0, &request, &terminal_ref); UT_ASSERT_EQ(action, RESOURCE_X_BOOTSTRAP_ROUND_DISPATCH_REQUEST); - ack = make_resource_x_bootstrap_ack_values( - &request, UINT64_C(9), UINT32_C(71)); + ack = make_resource_x_bootstrap_ack_values(&request, UINT64_C(9), UINT32_C(71)); action = cluster_pcm_lock_resource_x_bootstrap_round_accept_ack_exact( &ack, 0, 61, 77, now_us + 1, &assert_frame); UT_ASSERT_EQ(action, RESOURCE_X_BOOTSTRAP_ROUND_DISPATCH_ASSERT); ref = make_resource_x_acquisition_ref(tag, 1, 17, 1); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_t1_grant_exact(&ref), - RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_t1_grant_exact(&ref), RESOURCE_X_APPLY_APPLIED); memset(&observed, 0, sizeof(observed)); observed.tag = tag; @@ -7096,17 +6755,15 @@ UT_TEST(test_resource_x_target_install_wait_uses_receipt_and_fixed_deadline) observed.flags = PCM_OWN_FLAG_GRANT_PENDING; observed.generation = 0; observed.reservation_token = 12; - state - = cluster_pcm_lock_resource_x_bootstrap_round_target_install_capture_exact( - &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50000), - now_us + UINT64_C(1000000), &observed, &follow); + state = cluster_pcm_lock_resource_x_bootstrap_round_target_install_capture_exact( + &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50000), now_us + UINT64_C(1000000), &observed, + &follow); UT_ASSERT_EQ(state, RESOURCE_X_TARGET_INSTALL_INFLIGHT); follow_before = follow; /* A short caller slice wins while the caller and current head leases live. */ - wait_result - = cluster_pcm_lock_resource_x_bootstrap_round_target_install_wait_exact( - &follow, RESOURCE_X_TARGET_INSTALL_INFLIGHT, 50); + wait_result = cluster_pcm_lock_resource_x_bootstrap_round_target_install_wait_exact( + &follow, RESOURCE_X_TARGET_INSTALL_INFLIGHT, 50); UT_ASSERT_EQ(wait_result, RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(fake_cv_prepare_count, 1); UT_ASSERT_EQ(fake_cv_sleep_count, 1); @@ -7115,9 +6772,8 @@ UT_TEST(test_resource_x_target_install_wait_uses_receipt_and_fixed_deadline) UT_ASSERT_EQ(memcmp(&follow, &follow_before, sizeof(follow)), 0); /* The retained caller deadline clips a longer per-call timeout. */ - wait_result - = cluster_pcm_lock_resource_x_bootstrap_round_target_install_wait_exact( - &follow, RESOURCE_X_TARGET_INSTALL_INFLIGHT, 5000); + wait_result = cluster_pcm_lock_resource_x_bootstrap_round_target_install_wait_exact( + &follow, RESOURCE_X_TARGET_INSTALL_INFLIGHT, 5000); UT_ASSERT_EQ(wait_result, RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(fake_cv_prepare_count, 2); UT_ASSERT_EQ(fake_cv_sleep_count, 2); @@ -7127,14 +6783,12 @@ UT_TEST(test_resource_x_target_install_wait_uses_receipt_and_fixed_deadline) UT_ASSERT_EQ(memcmp(&follow, &follow_before, sizeof(follow)), 0); /* A later caller budget cannot extend the current head's progress lease. */ - state - = cluster_pcm_lock_resource_x_bootstrap_round_target_install_capture_exact( - &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50000), - now_us + UINT64_C(5000000), &observed, &round_limited); + state = cluster_pcm_lock_resource_x_bootstrap_round_target_install_capture_exact( + &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50000), now_us + UINT64_C(5000000), &observed, + &round_limited); UT_ASSERT_EQ(state, RESOURCE_X_TARGET_INSTALL_INFLIGHT); - wait_result - = cluster_pcm_lock_resource_x_bootstrap_round_target_install_wait_exact( - &round_limited, RESOURCE_X_TARGET_INSTALL_INFLIGHT, 5000); + wait_result = cluster_pcm_lock_resource_x_bootstrap_round_target_install_wait_exact( + &round_limited, RESOURCE_X_TARGET_INSTALL_INFLIGHT, 5000); UT_ASSERT_EQ(wait_result, RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(fake_cv_prepare_count, 3); UT_ASSERT_EQ(fake_cv_sleep_count, 3); @@ -7145,9 +6799,8 @@ UT_TEST(test_resource_x_target_install_wait_uses_receipt_and_fixed_deadline) /* Recycled binding is stale before CV registration. */ stale = follow; stale.entry_binding_generation++; - wait_result - = cluster_pcm_lock_resource_x_bootstrap_round_target_install_wait_exact( - &stale, RESOURCE_X_TARGET_INSTALL_INFLIGHT, 50); + wait_result = cluster_pcm_lock_resource_x_bootstrap_round_target_install_wait_exact( + &stale, RESOURCE_X_TARGET_INSTALL_INFLIGHT, 50); UT_ASSERT_EQ(wait_result, RESOURCE_X_APPLY_STALE); UT_ASSERT_EQ(fake_cv_prepare_count, 3); UT_ASSERT_EQ(fake_cv_sleep_count, 3); @@ -7155,24 +6808,21 @@ UT_TEST(test_resource_x_target_install_wait_uses_receipt_and_fixed_deadline) /* A stable entry-side executor failure is fail-closed after the registered * recheck; the wait cannot borrow an old BufferDesc to reinterpret it. */ - cluster_pcm_lock_resource_x_publish_no_progress_exact( - &ref, RESOURCE_X_NO_PROGRESS_BUFFER_CORRUPT); - wait_result - = cluster_pcm_lock_resource_x_bootstrap_round_target_install_wait_exact( - &follow, RESOURCE_X_TARGET_INSTALL_INFLIGHT, 50); + cluster_pcm_lock_resource_x_publish_no_progress_exact(&ref, + RESOURCE_X_NO_PROGRESS_BUFFER_CORRUPT); + wait_result = cluster_pcm_lock_resource_x_bootstrap_round_target_install_wait_exact( + &follow, RESOURCE_X_TARGET_INSTALL_INFLIGHT, 50); UT_ASSERT_EQ(wait_result, RESOURCE_X_APPLY_RECOVERY_BLOCKED); UT_ASSERT_EQ(fake_cv_prepare_count, 4); UT_ASSERT_EQ(fake_cv_sleep_count, 3); UT_ASSERT_EQ(fake_cv_cancel_count, 4); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_executor_rearm_exact(&ref), - RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_executor_rearm_exact(&ref), RESOURCE_X_APPLY_APPLIED); /* An expired immutable budget never enters timed sleep. */ expired = follow; expired.caller_absolute_deadline_us = 1; - wait_result - = cluster_pcm_lock_resource_x_bootstrap_round_target_install_wait_exact( - &expired, RESOURCE_X_TARGET_INSTALL_INFLIGHT, 50); + wait_result = cluster_pcm_lock_resource_x_bootstrap_round_target_install_wait_exact( + &expired, RESOURCE_X_TARGET_INSTALL_INFLIGHT, 50); UT_ASSERT_EQ(wait_result, RESOURCE_X_APPLY_DUPLICATE); UT_ASSERT_EQ(fake_cv_prepare_count, 5); UT_ASSERT_EQ(fake_cv_sleep_count, 3); @@ -7184,21 +6834,19 @@ UT_TEST(test_resource_x_target_install_wait_uses_receipt_and_fixed_deadline) install.writer_activation_token = 12; install.resource_x_activation_generation = 1; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_apply_exact(&ref, &install), - RESOURCE_X_APPLY_APPLIED); + RESOURCE_X_APPLY_APPLIED); memset(&activation, 0, sizeof(activation)); activation.ownership_generation = 1; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_activate_exact( - &ref, &activation), RESOURCE_X_APPLY_APPLIED); - UT_ASSERT_EQ( - cluster_pcm_lock_resource_x_bootstrap_round_publish_terminal_exact( - &ref, 31, 77, 1, 10, now_us + 2), - RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_activate_exact(&ref, &activation), + RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_bootstrap_round_publish_terminal_exact(&ref, 31, 77, 1, + 10, now_us + 2), + RESOURCE_X_APPLY_APPLIED); /* Terminal publication before the registered entry recheck is progress, * independent of any old BufferDesc sample. The waiter must return an * immediate reprobe hint without sleeping or returning authority. */ - wait_result - = cluster_pcm_lock_resource_x_bootstrap_round_target_install_wait_exact( - &follow, RESOURCE_X_TARGET_INSTALL_INFLIGHT, 50); + wait_result = cluster_pcm_lock_resource_x_bootstrap_round_target_install_wait_exact( + &follow, RESOURCE_X_TARGET_INSTALL_INFLIGHT, 50); UT_ASSERT_EQ(wait_result, RESOURCE_X_APPLY_DUPLICATE); UT_ASSERT_EQ(fake_cv_prepare_count, 6); UT_ASSERT_EQ(fake_cv_sleep_count, 3); @@ -7208,9 +6856,8 @@ UT_TEST(test_resource_x_target_install_wait_uses_receipt_and_fixed_deadline) observed.generation = 1; observed.writer_activation_token = 0; observed.resource_x_activation_generation = 0; - wait_result - = cluster_pcm_lock_resource_x_bootstrap_round_target_install_wait_exact( - &follow, RESOURCE_X_TARGET_INSTALL_INFLIGHT, 50); + wait_result = cluster_pcm_lock_resource_x_bootstrap_round_target_install_wait_exact( + &follow, RESOURCE_X_TARGET_INSTALL_INFLIGHT, 50); UT_ASSERT_EQ(wait_result, RESOURCE_X_APPLY_DUPLICATE); UT_ASSERT_EQ(fake_cv_prepare_count, 7); UT_ASSERT_EQ(fake_cv_sleep_count, 3); @@ -7221,25 +6868,23 @@ UT_TEST(test_resource_x_target_install_wait_uses_receipt_and_fixed_deadline) * sleeps while that exact owner is live, then the owner-clear broadcast * makes the same clean terminal sample immediately re-probeable. */ memset(&recycle, 0, sizeof(recycle)); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_itl_recycle_begin_exact( - &ref, 31, 77, 1, 12, 7, now_us + 3, &recycle), - RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_itl_recycle_begin_exact(&ref, 31, 77, 1, 12, 7, + now_us + 3, &recycle), + RESOURCE_X_APPLY_APPLIED); state = cluster_pcm_lock_resource_x_bootstrap_round_target_install_capture_exact( &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50000), now_us + UINT64_C(1000000), &observed, &follow); UT_ASSERT_EQ(state, RESOURCE_X_TARGET_INSTALL_PREUSE_RETRY); - wait_result - = cluster_pcm_lock_resource_x_bootstrap_round_target_install_wait_exact( - &follow, RESOURCE_X_TARGET_INSTALL_PREUSE_RETRY, 50); + wait_result = cluster_pcm_lock_resource_x_bootstrap_round_target_install_wait_exact( + &follow, RESOURCE_X_TARGET_INSTALL_PREUSE_RETRY, 50); UT_ASSERT_EQ(wait_result, RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(fake_cv_prepare_count, 8); UT_ASSERT_EQ(fake_cv_sleep_count, 4); UT_ASSERT_EQ(fake_cv_cancel_count, 8); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_itl_recycle_cancel_exact(&recycle), - RESOURCE_X_APPLY_APPLIED); - wait_result - = cluster_pcm_lock_resource_x_bootstrap_round_target_install_wait_exact( - &follow, RESOURCE_X_TARGET_INSTALL_PREUSE_RETRY, 50); + RESOURCE_X_APPLY_APPLIED); + wait_result = cluster_pcm_lock_resource_x_bootstrap_round_target_install_wait_exact( + &follow, RESOURCE_X_TARGET_INSTALL_PREUSE_RETRY, 50); UT_ASSERT_EQ(wait_result, RESOURCE_X_APPLY_DUPLICATE); UT_ASSERT_EQ(fake_cv_prepare_count, 9); UT_ASSERT_EQ(fake_cv_sleep_count, 4); @@ -7249,62 +6894,57 @@ UT_TEST(test_resource_x_target_install_wait_uses_receipt_and_fixed_deadline) * it. Once a later caller has captured that cover, its PREUSE wait belongs * to the later caller's still-live first deadline; the completed round's * historical deadline remains identity only. */ - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_itl_recycle_begin_exact( - &ref, 31, 77, 1, 12, 7, now_us + 4, &recycle), - RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_itl_recycle_begin_exact(&ref, 31, 77, 1, 12, 7, + now_us + 4, &recycle), + RESOURCE_X_APPLY_APPLIED); state = cluster_pcm_lock_resource_x_bootstrap_round_target_install_capture_exact( &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50000), now_us + UINT64_C(5000000), &observed, &round_limited); UT_ASSERT_EQ(state, RESOURCE_X_TARGET_INSTALL_PREUSE_RETRY); - assert_resource_x_target_install_follow_state( - &round_limited, &observed, RESOURCE_X_TARGET_INSTALL_PREUSE_RETRY); + assert_resource_x_target_install_follow_state(&round_limited, &observed, + RESOURCE_X_TARGET_INSTALL_PREUSE_RETRY); fake_pcm_clock_us = now_us + UINT64_C(250000); - wait_result - = cluster_pcm_lock_resource_x_bootstrap_round_target_install_wait_exact( - &round_limited, RESOURCE_X_TARGET_INSTALL_PREUSE_RETRY, 50); + wait_result = cluster_pcm_lock_resource_x_bootstrap_round_target_install_wait_exact( + &round_limited, RESOURCE_X_TARGET_INSTALL_PREUSE_RETRY, 50); UT_ASSERT_EQ(wait_result, RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(fake_cv_prepare_count, 10); UT_ASSERT_EQ(fake_cv_sleep_count, 5); UT_ASSERT_EQ(fake_cv_cancel_count, 10); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_itl_recycle_cancel_exact(&recycle), - RESOURCE_X_APPLY_APPLIED); + RESOURCE_X_APPLY_APPLIED); /* A valid successor T1 may be admitted after the coherent PREUSE * classification but before the registered entry recheck. The old * terminal owner is still exact, but the active acquisition proves entry * progress and invalidates the old wait predicate. Re-probe immediately; * never turn this legal ordering into RECOVERY_BLOCKED or sleep on it. */ - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_itl_recycle_begin_exact( - &ref, 31, 77, 1, 12, 7, now_us + 4, &recycle), - RESOURCE_X_APPLY_APPLIED); - assert_resource_x_target_install_follow_state( - &follow, &observed, RESOURCE_X_TARGET_INSTALL_PREUSE_RETRY); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_itl_recycle_begin_exact(&ref, 31, 77, 1, 12, 7, + now_us + 4, &recycle), + RESOURCE_X_APPLY_APPLIED); + assert_resource_x_target_install_follow_state(&follow, &observed, + RESOURCE_X_TARGET_INSTALL_PREUSE_RETRY); successor_ref = make_resource_x_acquisition_ref(tag, 1, 17, 2); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_t1_grant_exact(&successor_ref), - RESOURCE_X_APPLY_APPLIED); - wait_result - = cluster_pcm_lock_resource_x_bootstrap_round_target_install_wait_exact( - &follow, RESOURCE_X_TARGET_INSTALL_PREUSE_RETRY, 50); + RESOURCE_X_APPLY_APPLIED); + wait_result = cluster_pcm_lock_resource_x_bootstrap_round_target_install_wait_exact( + &follow, RESOURCE_X_TARGET_INSTALL_PREUSE_RETRY, 50); UT_ASSERT_EQ(wait_result, RESOURCE_X_APPLY_DUPLICATE); UT_ASSERT_EQ(fake_cv_prepare_count, 11); UT_ASSERT_EQ(fake_cv_sleep_count, 5); UT_ASSERT_EQ(fake_cv_cancel_count, 11); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_itl_recycle_cancel_exact(&recycle), - RESOURCE_X_APPLY_APPLIED); + RESOURCE_X_APPLY_APPLIED); /* Invalid input never registers and cannot be repaired by a timeout. */ memset(&invalid, 0, sizeof(invalid)); - wait_result - = cluster_pcm_lock_resource_x_bootstrap_round_target_install_wait_exact( - &invalid, RESOURCE_X_TARGET_INSTALL_INFLIGHT, 50); + wait_result = cluster_pcm_lock_resource_x_bootstrap_round_target_install_wait_exact( + &invalid, RESOURCE_X_TARGET_INSTALL_INFLIGHT, 50); UT_ASSERT_EQ(wait_result, RESOURCE_X_APPLY_INVALID); - wait_result - = cluster_pcm_lock_resource_x_bootstrap_round_target_install_wait_exact( - &follow, RESOURCE_X_TARGET_INSTALL_INFLIGHT, 0); + wait_result = cluster_pcm_lock_resource_x_bootstrap_round_target_install_wait_exact( + &follow, RESOURCE_X_TARGET_INSTALL_INFLIGHT, 0); UT_ASSERT_EQ(wait_result, RESOURCE_X_APPLY_INVALID); - wait_result - = cluster_pcm_lock_resource_x_bootstrap_round_target_install_wait_exact( - &follow, RESOURCE_X_TARGET_INSTALL_TERMINAL, 50); + wait_result = cluster_pcm_lock_resource_x_bootstrap_round_target_install_wait_exact( + &follow, RESOURCE_X_TARGET_INSTALL_TERMINAL, 50); UT_ASSERT_EQ(wait_result, RESOURCE_X_APPLY_INVALID); UT_ASSERT_EQ(fake_cv_prepare_count, 11); UT_ASSERT_EQ(fake_cv_sleep_count, 5); @@ -7338,21 +6978,19 @@ UT_TEST(test_resource_x_target_install_preuse_successor_never_grants_old_receipt reset_fake_pcm_runtime(4); cluster_node_id = 1; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), - RESOURCE_X_APPLY_APPLIED); + RESOURCE_X_APPLY_APPLIED); UT_ASSERT(resource_x_assertion_init(&tag, 1, &assertion)); action = cluster_pcm_lock_resource_x_bootstrap_round_step_exact( &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(10000000), (UINT64_C(10000000)) - (UINT64_C(100)), UINT64_C(100), UINT64_C(50), false, 0, &request, &terminal_ref); UT_ASSERT_EQ(action, RESOURCE_X_BOOTSTRAP_ROUND_DISPATCH_REQUEST); - ack = make_resource_x_bootstrap_ack_values( - &request, UINT64_C(9), UINT32_C(71)); + ack = make_resource_x_bootstrap_ack_values(&request, UINT64_C(9), UINT32_C(71)); action = cluster_pcm_lock_resource_x_bootstrap_round_accept_ack_exact( &ack, 0, 61, 77, UINT64_C(110), &assert_frame); UT_ASSERT_EQ(action, RESOURCE_X_BOOTSTRAP_ROUND_DISPATCH_ASSERT); ref = make_resource_x_acquisition_ref(tag, 1, 17, 1); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_t1_grant_exact(&ref), - RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_t1_grant_exact(&ref), RESOURCE_X_APPLY_APPLIED); memset(&observed, 0, sizeof(observed)); observed.tag = tag; @@ -7362,10 +7000,8 @@ UT_TEST(test_resource_x_target_install_preuse_successor_never_grants_old_receipt observed.reservation_token = 12; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_install_claim_bind_t1_exact(&ref, &observed), RESOURCE_X_APPLY_APPLIED); - state - = cluster_pcm_lock_resource_x_bootstrap_round_target_install_capture_exact( - &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50), - UINT64_C(9000000), &observed, &follow); + state = cluster_pcm_lock_resource_x_bootstrap_round_target_install_capture_exact( + &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50), UINT64_C(9000000), &observed, &follow); UT_ASSERT_EQ(state, RESOURCE_X_TARGET_INSTALL_INFLIGHT); UT_ASSERT(follow.valid); @@ -7374,15 +7010,14 @@ UT_TEST(test_resource_x_target_install_preuse_successor_never_grants_old_receipt install.writer_activation_token = 12; install.resource_x_activation_generation = 1; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_apply_exact(&ref, &install), - RESOURCE_X_APPLY_APPLIED); + RESOURCE_X_APPLY_APPLIED); memset(&activation, 0, sizeof(activation)); activation.ownership_generation = 1; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_activate_exact( - &ref, &activation), RESOURCE_X_APPLY_APPLIED); - UT_ASSERT_EQ( - cluster_pcm_lock_resource_x_bootstrap_round_publish_terminal_exact( - &ref, 31, 77, 1, 10, UINT64_C(120)), - RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_activate_exact(&ref, &activation), + RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_bootstrap_round_publish_terminal_exact( + &ref, 31, 77, 1, 10, UINT64_C(120)), + RESOURCE_X_APPLY_APPLIED); observed.pcm_state = (uint8)PCM_STATE_X; observed.flags = 0; observed.generation = 1; @@ -7391,18 +7026,17 @@ UT_TEST(test_resource_x_target_install_preuse_successor_never_grants_old_receipt /* A terminal recycler serializes use of the same cover. The follower may * use that cover only after a fresh owner-empty classification. */ - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_itl_recycle_begin_exact( - &ref, 31, 77, 1, 12, 7, UINT64_C(130), &recycle), - RESOURCE_X_APPLY_APPLIED); - assert_resource_x_target_install_follow_state( - &follow, &observed, RESOURCE_X_TARGET_INSTALL_PREUSE_RETRY); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_itl_recycle_begin_exact(&ref, 31, 77, 1, 12, 7, + UINT64_C(130), &recycle), + RESOURCE_X_APPLY_APPLIED); + assert_resource_x_target_install_follow_state(&follow, &observed, + RESOURCE_X_TARGET_INSTALL_PREUSE_RETRY); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_itl_recycle_cancel_exact(&recycle), - RESOURCE_X_APPLY_APPLIED); - assert_resource_x_target_install_follow_state( - &follow, &observed, RESOURCE_X_TARGET_INSTALL_TERMINAL); + RESOURCE_X_APPLY_APPLIED); + assert_resource_x_target_install_follow_state(&follow, &observed, + RESOURCE_X_TARGET_INSTALL_TERMINAL); - successor_block = make_resource_x_master_frame( - RESOURCE_X_WIRE_BLOCK_TO_N, tag, 2, 1); + successor_block = make_resource_x_master_frame(RESOURCE_X_WIRE_BLOCK_TO_N, tag, 2, 1); successor_block.payload_bytes = RESOURCE_X_CONTROL_V1_BYTES; successor_block.common.base_authority_generation = UINT64_C(10); successor_block.common.authority_generation = UINT64_C(10); @@ -7415,52 +7049,52 @@ UT_TEST(test_resource_x_target_install_preuse_successor_never_grants_old_receipt memset(&lineage, 0, sizeof(lineage)); memset(&revoke, 0, sizeof(revoke)); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_terminal_x_revoke_claim_exact( - &successor_block, 0, 77, 1, 12, 8, UINT64_C(200), - &lineage, &revoke), RESOURCE_X_APPLY_APPLIED); + &successor_block, 0, 77, 1, 12, 8, UINT64_C(200), &lineage, &revoke), + RESOURCE_X_APPLY_APPLIED); /* The entry owner may win before the BufferDesc arm, or the BufferDesc * sample may observe the exact one-token REVOKING successor. Neither * ordering may return the old terminal ref. */ - assert_resource_x_target_install_follow_state( - &follow, &observed, RESOURCE_X_TARGET_INSTALL_PREUSE_RETRY); + assert_resource_x_target_install_follow_state(&follow, &observed, + RESOURCE_X_TARGET_INSTALL_PREUSE_RETRY); observed.flags = PCM_OWN_FLAG_REVOKING; observed.reservation_token = 13; - assert_resource_x_target_install_follow_state( - &follow, &observed, RESOURCE_X_TARGET_INSTALL_PREUSE_RETRY); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_terminal_x_revoke_yield_exact( - &revoke, UINT64_C(210)), RESOURCE_X_APPLY_APPLIED); + assert_resource_x_target_install_follow_state(&follow, &observed, + RESOURCE_X_TARGET_INSTALL_PREUSE_RETRY); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_terminal_x_revoke_yield_exact(&revoke, UINT64_C(210)), + RESOURCE_X_APPLY_APPLIED); observed.flags = 0; - assert_resource_x_target_install_follow_state( - &follow, &observed, RESOURCE_X_TARGET_INSTALL_PREUSE_RETRY); + assert_resource_x_target_install_follow_state(&follow, &observed, + RESOURCE_X_TARGET_INSTALL_PREUSE_RETRY); /* A busy nonblocking drain may exact-abort and replay more than once. * Every successful begin consumes a token while ownership generation stays * fixed. The original terminal receipt must treat every later cycle as * pre-use invalidation, never as authority or corruption. */ UT_ASSERT_EQ(cluster_pcm_lock_resource_x_terminal_x_revoke_claim_exact( - &successor_block, 0, 77, 1, 13, 8, UINT64_C(220), - &lineage, &revoke), RESOURCE_X_APPLY_APPLIED); + &successor_block, 0, 77, 1, 13, 8, UINT64_C(220), &lineage, &revoke), + RESOURCE_X_APPLY_APPLIED); observed.flags = PCM_OWN_FLAG_REVOKING; observed.reservation_token = 14; - assert_resource_x_target_install_follow_state( - &follow, &observed, RESOURCE_X_TARGET_INSTALL_PREUSE_RETRY); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_terminal_x_revoke_yield_exact( - &revoke, UINT64_C(230)), RESOURCE_X_APPLY_APPLIED); + assert_resource_x_target_install_follow_state(&follow, &observed, + RESOURCE_X_TARGET_INSTALL_PREUSE_RETRY); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_terminal_x_revoke_yield_exact(&revoke, UINT64_C(230)), + RESOURCE_X_APPLY_APPLIED); observed.flags = 0; - assert_resource_x_target_install_follow_state( - &follow, &observed, RESOURCE_X_TARGET_INSTALL_PREUSE_RETRY); + assert_resource_x_target_install_follow_state(&follow, &observed, + RESOURCE_X_TARGET_INSTALL_PREUSE_RETRY); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_terminal_x_revoke_claim_exact( - &successor_block, 0, 77, 1, 14, 8, UINT64_C(240), - &lineage, &revoke), RESOURCE_X_APPLY_APPLIED); + &successor_block, 0, 77, 1, 14, 8, UINT64_C(240), &lineage, &revoke), + RESOURCE_X_APPLY_APPLIED); observed.flags = PCM_OWN_FLAG_REVOKING; observed.reservation_token = 15; - assert_resource_x_target_install_follow_state( - &follow, &observed, RESOURCE_X_TARGET_INSTALL_PREUSE_RETRY); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_terminal_x_revoke_yield_exact( - &revoke, UINT64_C(250)), RESOURCE_X_APPLY_APPLIED); + assert_resource_x_target_install_follow_state(&follow, &observed, + RESOURCE_X_TARGET_INSTALL_PREUSE_RETRY); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_terminal_x_revoke_yield_exact(&revoke, UINT64_C(250)), + RESOURCE_X_APPLY_APPLIED); observed.flags = 0; - assert_resource_x_target_install_follow_state( - &follow, &observed, RESOURCE_X_TARGET_INSTALL_PREUSE_RETRY); + assert_resource_x_target_install_follow_state(&follow, &observed, + RESOURCE_X_TARGET_INSTALL_PREUSE_RETRY); /* Expiring the bounded HANDOFF clears only its local priority. The old * token still proves that this receipt crossed a revoke, while a freshly @@ -7482,13 +7116,11 @@ UT_TEST(test_resource_x_target_install_preuse_successor_never_grants_old_receipt UT_ASSERT_EQ(cluster_pcm_lock_resource_x_terminal_x_revoke_claim_exact( &successor_block, 0, 77, 1, 15, 8, UINT64_C(1000200), &lineage, &revoke), RESOURCE_X_APPLY_BAD_STATE); - assert_resource_x_target_install_follow_state( - &follow, &observed, RESOURCE_X_TARGET_INSTALL_PREUSE_RETRY); + assert_resource_x_target_install_follow_state(&follow, &observed, + RESOURCE_X_TARGET_INSTALL_PREUSE_RETRY); memset(&fresh, 0, sizeof(fresh)); - state - = cluster_pcm_lock_resource_x_bootstrap_round_target_install_capture_exact( - &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50), - UINT64_C(9000000), &observed, &fresh); + state = cluster_pcm_lock_resource_x_bootstrap_round_target_install_capture_exact( + &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50), UINT64_C(9000000), &observed, &fresh); UT_ASSERT_EQ(state, RESOURCE_X_TARGET_INSTALL_TERMINAL); UT_ASSERT(fresh.valid); UT_ASSERT_EQ(fresh.reservation_token, UINT64_C(15)); @@ -7498,46 +7130,46 @@ UT_TEST(test_resource_x_target_install_preuse_successor_never_grants_old_receipt * while EVICTING owns the cover. */ memset(&release, 0, sizeof(release)); memset(&evict, 0, sizeof(evict)); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_target_evict_prepare_exact( - &tag, 0, 17, 31, 77, 1, 15, 61, 9, &release, &evict), - RESOURCE_X_APPLY_APPLIED); - assert_resource_x_target_install_follow_state( - &fresh, &observed, RESOURCE_X_TARGET_INSTALL_PREUSE_RETRY); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_target_evict_prepare_exact(&tag, 0, 17, 31, 77, 1, 15, + 61, 9, &release, &evict), + RESOURCE_X_APPLY_APPLIED); + assert_resource_x_target_install_follow_state(&fresh, &observed, + RESOURCE_X_TARGET_INSTALL_PREUSE_RETRY); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_target_evict_abort_exact(&evict), - RESOURCE_X_APPLY_APPLIED); - assert_resource_x_target_install_follow_state( - &fresh, &observed, RESOURCE_X_TARGET_INSTALL_TERMINAL); + RESOURCE_X_APPLY_APPLIED); + assert_resource_x_target_install_follow_state(&fresh, &observed, + RESOURCE_X_TARGET_INSTALL_TERMINAL); /* A committed X->N after any finite number of reversible cycles is retry * evidence for the old receipt. A second ownership generation, token * regression/wrap or activation debt remains fail closed. */ observed.pcm_state = (uint8)PCM_STATE_N; observed.generation = 2; - assert_resource_x_target_install_follow_state( - &follow, &observed, RESOURCE_X_TARGET_INSTALL_PREUSE_RETRY); + assert_resource_x_target_install_follow_state(&follow, &observed, + RESOURCE_X_TARGET_INSTALL_PREUSE_RETRY); observed.flags = PCM_OWN_FLAG_REVOKING; - assert_resource_x_target_install_follow_state( - &follow, &observed, RESOURCE_X_TARGET_INSTALL_PREUSE_RETRY); + assert_resource_x_target_install_follow_state(&follow, &observed, + RESOURCE_X_TARGET_INSTALL_PREUSE_RETRY); changed = observed; changed.generation++; - assert_resource_x_target_install_follow_state( - &follow, &changed, RESOURCE_X_TARGET_INSTALL_RECOVERY_BLOCKED); + assert_resource_x_target_install_follow_state(&follow, &changed, + RESOURCE_X_TARGET_INSTALL_RECOVERY_BLOCKED); changed = observed; changed.reservation_token++; - assert_resource_x_target_install_follow_state( - &follow, &changed, RESOURCE_X_TARGET_INSTALL_PREUSE_RETRY); + assert_resource_x_target_install_follow_state(&follow, &changed, + RESOURCE_X_TARGET_INSTALL_PREUSE_RETRY); changed = observed; changed.reservation_token = follow.reservation_token; - assert_resource_x_target_install_follow_state( - &follow, &changed, RESOURCE_X_TARGET_INSTALL_RECOVERY_BLOCKED); + assert_resource_x_target_install_follow_state(&follow, &changed, + RESOURCE_X_TARGET_INSTALL_RECOVERY_BLOCKED); changed = observed; changed.reservation_token = UINT64_MAX; - assert_resource_x_target_install_follow_state( - &follow, &changed, RESOURCE_X_TARGET_INSTALL_RECOVERY_BLOCKED); + assert_resource_x_target_install_follow_state(&follow, &changed, + RESOURCE_X_TARGET_INSTALL_RECOVERY_BLOCKED); changed = observed; changed.writer_activation_token = changed.reservation_token; - assert_resource_x_target_install_follow_state( - &follow, &changed, RESOURCE_X_TARGET_INSTALL_RECOVERY_BLOCKED); + assert_resource_x_target_install_follow_state(&follow, &changed, + RESOURCE_X_TARGET_INSTALL_RECOVERY_BLOCKED); /* After PREUSE_RETRY discards the old process-local receipt, the same * post-terminal N+REVOKING sample is not a new install continuation: its @@ -7545,10 +7177,8 @@ UT_TEST(test_resource_x_target_install_preuse_successor_never_grants_old_receipt * the caller can enter the canonical retained-release path; fabricating an * expected X at the next generation would fail closed before that path. */ memset(&fresh, 0x5a, sizeof(fresh)); - state - = cluster_pcm_lock_resource_x_bootstrap_round_target_install_capture_exact( - &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50), - UINT64_C(9000000), &observed, &fresh); + state = cluster_pcm_lock_resource_x_bootstrap_round_target_install_capture_exact( + &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50), UINT64_C(9000000), &observed, &fresh); UT_ASSERT_EQ(state, RESOURCE_X_TARGET_INSTALL_STALE); UT_ASSERT(!fresh.valid); } @@ -7577,38 +7207,34 @@ UT_TEST(test_resource_x_target_install_capture_during_revoke_retries_same_token_ reset_fake_pcm_runtime(4); cluster_node_id = 1; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), - RESOURCE_X_APPLY_APPLIED); + RESOURCE_X_APPLY_APPLIED); UT_ASSERT(resource_x_assertion_init(&tag, 1, &assertion)); action = cluster_pcm_lock_resource_x_bootstrap_round_step_exact( &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(10000000), (UINT64_C(10000000)) - (UINT64_C(100)), UINT64_C(100), UINT64_C(50), false, 0, &request, &terminal_ref); UT_ASSERT_EQ(action, RESOURCE_X_BOOTSTRAP_ROUND_DISPATCH_REQUEST); - ack = make_resource_x_bootstrap_ack_values( - &request, UINT64_C(9), UINT32_C(71)); + ack = make_resource_x_bootstrap_ack_values(&request, UINT64_C(9), UINT32_C(71)); action = cluster_pcm_lock_resource_x_bootstrap_round_accept_ack_exact( &ack, 0, 61, 77, UINT64_C(110), &assert_frame); UT_ASSERT_EQ(action, RESOURCE_X_BOOTSTRAP_ROUND_DISPATCH_ASSERT); ref = make_resource_x_acquisition_ref(tag, 1, 17, 1); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_t1_grant_exact(&ref), - RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_t1_grant_exact(&ref), RESOURCE_X_APPLY_APPLIED); memset(&install, 0, sizeof(install)); install.ownership_generation = 1; install.writer_activation_token = 12; install.resource_x_activation_generation = 1; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_apply_exact(&ref, &install), - RESOURCE_X_APPLY_APPLIED); + RESOURCE_X_APPLY_APPLIED); memset(&activation, 0, sizeof(activation)); activation.ownership_generation = 1; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_activate_exact( - &ref, &activation), RESOURCE_X_APPLY_APPLIED); - UT_ASSERT_EQ( - cluster_pcm_lock_resource_x_bootstrap_round_publish_terminal_exact( - &ref, 31, 77, 1, 10, UINT64_C(120)), - RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_activate_exact(&ref, &activation), + RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_bootstrap_round_publish_terminal_exact( + &ref, 31, 77, 1, 10, UINT64_C(120)), + RESOURCE_X_APPLY_APPLIED); - successor_block = make_resource_x_master_frame( - RESOURCE_X_WIRE_BLOCK_TO_N, tag, 2, 1); + successor_block = make_resource_x_master_frame(RESOURCE_X_WIRE_BLOCK_TO_N, tag, 2, 1); successor_block.payload_bytes = RESOURCE_X_CONTROL_V1_BYTES; successor_block.common.base_authority_generation = UINT64_C(10); successor_block.common.authority_generation = UINT64_C(10); @@ -7621,8 +7247,8 @@ UT_TEST(test_resource_x_target_install_capture_during_revoke_retries_same_token_ memset(&lineage, 0, sizeof(lineage)); memset(&revoke, 0, sizeof(revoke)); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_terminal_x_revoke_claim_exact( - &successor_block, 0, 77, 1, 12, 8, UINT64_C(200), - &lineage, &revoke), RESOURCE_X_APPLY_APPLIED); + &successor_block, 0, 77, 1, 12, 8, UINT64_C(200), &lineage, &revoke), + RESOURCE_X_APPLY_APPLIED); /* A31 RED: capture happens after reservation-begin has consumed token 13. * The continuation therefore records the revoke token, not the earlier @@ -7635,64 +7261,60 @@ UT_TEST(test_resource_x_target_install_capture_during_revoke_retries_same_token_ observed.generation = 1; observed.reservation_token = 13; memset(&follow, 0x7f, sizeof(follow)); - state - = cluster_pcm_lock_resource_x_bootstrap_round_target_install_capture_exact( - &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50), - UINT64_C(9000000), &observed, &follow); + state = cluster_pcm_lock_resource_x_bootstrap_round_target_install_capture_exact( + &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50), UINT64_C(9000000), &observed, &follow); UT_ASSERT_EQ(state, RESOURCE_X_TARGET_INSTALL_PREUSE_RETRY); UT_ASSERT(follow.valid); UT_ASSERT_EQ(follow.pending_ownership_generation, UINT64_C(0)); UT_ASSERT_EQ(follow.expected_x_ownership_generation, UINT64_C(1)); UT_ASSERT_EQ(follow.reservation_token, UINT64_C(13)); - UT_ASSERT_EQ(follow.capture_flags, - RESOURCE_X_TARGET_INSTALL_CAPTURE_REVOKE_TOKEN); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_terminal_x_revoke_release_exact( - &revoke), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(follow.capture_flags, RESOURCE_X_TARGET_INSTALL_CAPTURE_REVOKE_TOKEN); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_terminal_x_revoke_release_exact(&revoke), + RESOURCE_X_APPLY_APPLIED); observed.pcm_state = (uint8)PCM_STATE_N; observed.flags = PCM_OWN_FLAG_REVOKING; observed.generation = 2; - assert_resource_x_target_install_follow_state( - &follow, &observed, RESOURCE_X_TARGET_INSTALL_PREUSE_RETRY); + assert_resource_x_target_install_follow_state(&follow, &observed, + RESOURCE_X_TARGET_INSTALL_PREUSE_RETRY); observed.flags = 0; - assert_resource_x_target_install_follow_state( - &follow, &observed, RESOURCE_X_TARGET_INSTALL_PREUSE_RETRY); + assert_resource_x_target_install_follow_state(&follow, &observed, + RESOURCE_X_TARGET_INSTALL_PREUSE_RETRY); changed_follow = follow; changed_follow.capture_flags = 0; - assert_resource_x_target_install_follow_state( - &changed_follow, &observed, - RESOURCE_X_TARGET_INSTALL_RECOVERY_BLOCKED); + assert_resource_x_target_install_follow_state(&changed_follow, &observed, + RESOURCE_X_TARGET_INSTALL_RECOVERY_BLOCKED); changed_follow = follow; changed_follow.capture_flags = UINT8_C(0x80); - assert_resource_x_target_install_follow_state( - &changed_follow, &observed, RESOURCE_X_TARGET_INSTALL_INVALID); + assert_resource_x_target_install_follow_state(&changed_follow, &observed, + RESOURCE_X_TARGET_INSTALL_INVALID); /* Equality is not a generic N retry. */ changed = observed; changed.flags = PCM_OWN_FLAG_GRANT_PENDING; - assert_resource_x_target_install_follow_state( - &follow, &changed, RESOURCE_X_TARGET_INSTALL_RECOVERY_BLOCKED); + assert_resource_x_target_install_follow_state(&follow, &changed, + RESOURCE_X_TARGET_INSTALL_RECOVERY_BLOCKED); changed = observed; changed.generation = 3; - assert_resource_x_target_install_follow_state( - &follow, &changed, RESOURCE_X_TARGET_INSTALL_RECOVERY_BLOCKED); + assert_resource_x_target_install_follow_state(&follow, &changed, + RESOURCE_X_TARGET_INSTALL_RECOVERY_BLOCKED); changed = observed; changed.reservation_token = 12; - assert_resource_x_target_install_follow_state( - &follow, &changed, RESOURCE_X_TARGET_INSTALL_RECOVERY_BLOCKED); + assert_resource_x_target_install_follow_state(&follow, &changed, + RESOURCE_X_TARGET_INSTALL_RECOVERY_BLOCKED); changed = observed; changed.reservation_token = UINT64_MAX; - assert_resource_x_target_install_follow_state( - &follow, &changed, RESOURCE_X_TARGET_INSTALL_RECOVERY_BLOCKED); + assert_resource_x_target_install_follow_state(&follow, &changed, + RESOURCE_X_TARGET_INSTALL_RECOVERY_BLOCKED); changed = observed; changed.writer_activation_token = changed.reservation_token; - assert_resource_x_target_install_follow_state( - &follow, &changed, RESOURCE_X_TARGET_INSTALL_RECOVERY_BLOCKED); + assert_resource_x_target_install_follow_state(&follow, &changed, + RESOURCE_X_TARGET_INSTALL_RECOVERY_BLOCKED); changed_follow = follow; changed_follow.observed_claim_pending_generation = 1; changed_follow.observed_claim_reservation_token = 13; - assert_resource_x_target_install_follow_state( - &changed_follow, &observed, RESOURCE_X_TARGET_INSTALL_STALE); + assert_resource_x_target_install_follow_state(&changed_follow, &observed, + RESOURCE_X_TARGET_INSTALL_STALE); } static void retain_resource_x_test_settlement_pair_at_attempt( @@ -8368,27 +7990,25 @@ UT_TEST(test_resource_x_bootstrap_terminal_cover_accepts_remote_master_requester cluster_node_id = 1; fake_gcs_master_node = 0; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), - RESOURCE_X_APPLY_APPLIED); + RESOURCE_X_APPLY_APPLIED); UT_ASSERT(resource_x_assertion_init(&tag, 1, &assertion)); action = cluster_pcm_lock_resource_x_bootstrap_round_step_exact( &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(1000), (UINT64_C(1000)) - (UINT64_C(100)), UINT64_C(100), UINT64_C(50), false, 0, &request, &terminal_ref); UT_ASSERT_EQ(action, RESOURCE_X_BOOTSTRAP_ROUND_DISPATCH_REQUEST); - ack = make_resource_x_bootstrap_ack_values( - &request, UINT64_C(9), UINT32_C(71)); + ack = make_resource_x_bootstrap_ack_values(&request, UINT64_C(9), UINT32_C(71)); action = cluster_pcm_lock_resource_x_bootstrap_round_accept_ack_exact( &ack, 0, 61, 77, UINT64_C(110), &assert_frame); UT_ASSERT_EQ(action, RESOURCE_X_BOOTSTRAP_ROUND_DISPATCH_ASSERT); make_resource_x_remote_join_pair(tag, 1, &grant, &image); retarget_resource_x_remote_join_pair(&grant, &image, 11, 1); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact( - &image, 0, &join), RESOURCE_X_APPLY_APPLIED); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact( - &grant, 0, &join), RESOURCE_X_APPLY_APPLIED); - UT_ASSERT_EQ(join.flags, - RESOURCE_X_REQUESTER_JOIN_HAS_IMAGE - | RESOURCE_X_REQUESTER_JOIN_HAS_GRANT - | RESOURCE_X_REQUESTER_JOIN_READY); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact(&image, 0, &join), + RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact(&grant, 0, &join), + RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(join.flags, RESOURCE_X_REQUESTER_JOIN_HAS_IMAGE + | RESOURCE_X_REQUESTER_JOIN_HAS_GRANT + | RESOURCE_X_REQUESTER_JOIN_READY); /* The canonical X grant lives at remote master node 0. This requester * keeps only its exact BufferDesc X generation, so its local GRD @@ -8399,40 +8019,38 @@ UT_TEST(test_resource_x_bootstrap_terminal_cover_accepts_remote_master_requester RESOURCE_X_APPLY_APPLIED); expected_ref = make_resource_x_acquisition_ref(tag, 1, 17, 1); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_t1_grant_exact(&expected_ref), - RESOURCE_X_APPLY_APPLIED); + RESOURCE_X_APPLY_APPLIED); memset(&install, 0, sizeof(install)); install.ownership_generation = 91; install.writer_activation_token = 12; install.resource_x_activation_generation = 1; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_apply_exact( - &expected_ref, &install), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_apply_exact(&expected_ref, &install), + RESOURCE_X_APPLY_APPLIED); memset(&activation, 0, sizeof(activation)); activation.ownership_generation = 92; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_activate_exact( - &expected_ref, &activation), RESOURCE_X_APPLY_STALE); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_activate_exact(&expected_ref, &activation), + RESOURCE_X_APPLY_STALE); activation.ownership_generation = 91; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_activate_exact( - &expected_ref, &activation), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_activate_exact(&expected_ref, &activation), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ((int)cluster_pcm_lock_query(tag), (int)PCM_LOCK_MODE_N); /* T3 retirement and the sole cached-X terminal cover share the same * entry-lock linearization point. Otherwise a same-node follower can * observe post-T3 BufferDesc X while the round is still ASSERT_DISPATCHED * and incorrectly fail the valid native acquisition. */ - UT_ASSERT(cluster_pcm_lock_resource_x_bootstrap_round_cover_matches_exact( - &expected_ref, 31, 77, 91)); + UT_ASSERT( + cluster_pcm_lock_resource_x_bootstrap_round_cover_matches_exact(&expected_ref, 31, 77, 91)); - UT_ASSERT_EQ( - cluster_pcm_lock_resource_x_bootstrap_round_publish_terminal_exact( - &expected_ref, 31, 77, 91, 11, UINT64_C(115)), - RESOURCE_X_APPLY_DUPLICATE); - UT_ASSERT(cluster_pcm_lock_resource_x_bootstrap_round_cover_matches_exact( - &expected_ref, 31, 77, 91)); - action = cluster_pcm_lock_resource_x_bootstrap_round_step_exact( + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_bootstrap_round_publish_terminal_exact( + &expected_ref, 31, 77, 91, 11, UINT64_C(115)), + RESOURCE_X_APPLY_DUPLICATE); + UT_ASSERT( + cluster_pcm_lock_resource_x_bootstrap_round_cover_matches_exact(&expected_ref, 31, 77, 91)); + action = cluster_pcm_lock_resource_x_bootstrap_round_step_exact( &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(1000), (UINT64_C(1000)) - (UINT64_C(120)), UINT64_C(120), UINT64_C(50), true, 91, &unused_dispatch, &terminal_ref); UT_ASSERT_EQ(action, RESOURCE_X_BOOTSTRAP_ROUND_TERMINAL); - UT_ASSERT(memcmp(&terminal_ref, &expected_ref, - sizeof(terminal_ref)) == 0); + UT_ASSERT(memcmp(&terminal_ref, &expected_ref, sizeof(terminal_ref)) == 0); UT_ASSERT_EQ((int)cluster_pcm_lock_query(tag), (int)PCM_LOCK_MODE_N); /* A non-X ownership snapshot invalidates the joinable cover only after @@ -8442,25 +8060,22 @@ UT_TEST(test_resource_x_bootstrap_terminal_cover_accepts_remote_master_requester lost.tag = tag; lost.pcm_state = (uint8)PCM_STATE_S; lost.generation = 91; - UT_ASSERT_EQ( - cluster_pcm_lock_resource_x_bootstrap_round_invalidate_ownership_loss_exact( - &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50), &lost), - RESOURCE_X_APPLY_STALE); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_bootstrap_round_invalidate_ownership_loss_exact( + &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50), &lost), + RESOURCE_X_APPLY_STALE); lost.generation = 92; lost.flags = PCM_OWN_FLAG_GRANT_PENDING; lost.reservation_token = 7; - UT_ASSERT_EQ( - cluster_pcm_lock_resource_x_bootstrap_round_invalidate_ownership_loss_exact( - &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50), &lost), - RESOURCE_X_APPLY_STALE); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_bootstrap_round_invalidate_ownership_loss_exact( + &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50), &lost), + RESOURCE_X_APPLY_STALE); lost.flags = 0; lost.reservation_token = 0; - UT_ASSERT_EQ( - cluster_pcm_lock_resource_x_bootstrap_round_invalidate_ownership_loss_exact( - &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50), &lost), - RESOURCE_X_APPLY_APPLIED); - UT_ASSERT(!cluster_pcm_lock_resource_x_bootstrap_round_cover_matches_exact( - &expected_ref, 31, 77, 91)); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_bootstrap_round_invalidate_ownership_loss_exact( + &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50), &lost), + RESOURCE_X_APPLY_APPLIED); + UT_ASSERT(!cluster_pcm_lock_resource_x_bootstrap_round_cover_matches_exact(&expected_ref, 31, + 77, 91)); UT_ASSERT_EQ( cluster_pcm_lock_resource_x_caller_observe_exact(&assertion, 17, 31, 77, &retry_caller), RESOURCE_X_APPLY_DUPLICATE); @@ -8491,20 +8106,19 @@ UT_TEST(test_resource_x_cached_x_to_s_commit_clears_only_exact_terminal_cover) reset_fake_pcm_runtime(4); cluster_node_id = 1; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), - RESOURCE_X_APPLY_APPLIED); + RESOURCE_X_APPLY_APPLIED); UT_ASSERT(resource_x_assertion_init(&tag, 1, &assertion)); action = cluster_pcm_lock_resource_x_bootstrap_round_step_direct_init_exact( &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(1000), (UINT64_C(1000)) - (UINT64_C(100)), UINT64_C(100), UINT64_C(50), 7, 5, false, 0, &request, &terminal_ref); UT_ASSERT_EQ(action, RESOURCE_X_BOOTSTRAP_ROUND_DISPATCH_REQUEST); - ack = make_resource_x_bootstrap_ack_values( - &request, UINT64_C(9), UINT32_C(71)); + ack = make_resource_x_bootstrap_ack_values(&request, UINT64_C(9), UINT32_C(71)); action = cluster_pcm_lock_resource_x_bootstrap_round_accept_ack_exact( &ack, 0, 61, 77, UINT64_C(110), &assert_frame); UT_ASSERT_EQ(action, RESOURCE_X_BOOTSTRAP_ROUND_DISPATCH_ASSERT); expected_ref = make_resource_x_acquisition_ref(tag, 1, 17, 1); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_t1_grant_exact(&expected_ref), - RESOURCE_X_APPLY_APPLIED); + RESOURCE_X_APPLY_APPLIED); /* An ordinary same-node caller does not own the creation proof, but it * must join (and only wait on) the exact direct-init T1 sidecar instead of * invalidating the creator's requester round. */ @@ -8514,34 +8128,28 @@ UT_TEST(test_resource_x_cached_x_to_s_commit_clears_only_exact_terminal_cover) inflight.reservation_token = 5; inflight.pcm_state = (uint8)PCM_STATE_X; inflight.writer_activation_token = 5; - UT_ASSERT( - cluster_pcm_lock_resource_x_bootstrap_round_target_install_inflight_exact( - &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50), - &inflight)); + UT_ASSERT(cluster_pcm_lock_resource_x_bootstrap_round_target_install_inflight_exact( + &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50), &inflight)); inflight.reservation_token = 6; - UT_ASSERT( - !cluster_pcm_lock_resource_x_bootstrap_round_target_install_inflight_exact( - &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50), - &inflight)); + UT_ASSERT(!cluster_pcm_lock_resource_x_bootstrap_round_target_install_inflight_exact( + &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50), &inflight)); inflight.reservation_token = 5; inflight.generation = 9; - UT_ASSERT( - !cluster_pcm_lock_resource_x_bootstrap_round_target_install_inflight_exact( - &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50), - &inflight)); + UT_ASSERT(!cluster_pcm_lock_resource_x_bootstrap_round_target_install_inflight_exact( + &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50), &inflight)); inflight.generation = 8; memset(&install, 0, sizeof(install)); install.ownership_generation = 8; install.writer_activation_token = 12; install.resource_x_activation_generation = 1; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_apply_exact( - &expected_ref, &install), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_apply_exact(&expected_ref, &install), + RESOURCE_X_APPLY_APPLIED); action = cluster_pcm_lock_resource_x_bootstrap_round_step_direct_init_exact( &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(1000), (UINT64_C(1000)) - (UINT64_C(115)), UINT64_C(115), UINT64_C(50), 7, 5, true, 8, &unused_dispatch, &terminal_ref); UT_ASSERT_EQ(action, RESOURCE_X_BOOTSTRAP_ROUND_TERMINAL); - UT_ASSERT(cluster_pcm_lock_resource_x_bootstrap_round_cover_matches_exact( - &expected_ref, 31, 77, 8)); + UT_ASSERT( + cluster_pcm_lock_resource_x_bootstrap_round_cover_matches_exact(&expected_ref, 31, 77, 8)); memset(&revoking, 0, sizeof(revoking)); revoking.tag = tag; @@ -8553,38 +8161,30 @@ UT_TEST(test_resource_x_cached_x_to_s_commit_clears_only_exact_terminal_cover) shared.pcm_state = (uint8)PCM_STATE_S; shared.flags = 0; shared.generation = 10; - UT_ASSERT_EQ( - cluster_pcm_lock_resource_x_bootstrap_round_note_x_to_s_exact( - &revoking, &shared), RESOURCE_X_APPLY_STALE); - UT_ASSERT(cluster_pcm_lock_resource_x_bootstrap_round_cover_matches_exact( - &expected_ref, 31, 77, 8)); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_bootstrap_round_note_x_to_s_exact(&revoking, &shared), + RESOURCE_X_APPLY_STALE); + UT_ASSERT( + cluster_pcm_lock_resource_x_bootstrap_round_cover_matches_exact(&expected_ref, 31, 77, 8)); shared.generation = 9; - UT_ASSERT_EQ( - cluster_pcm_lock_resource_x_bootstrap_round_note_x_to_s_exact( - &revoking, &shared), RESOURCE_X_APPLY_APPLIED); - UT_ASSERT(!cluster_pcm_lock_resource_x_bootstrap_round_cover_matches_exact( - &expected_ref, 31, 77, 8)); - UT_ASSERT_EQ( - cluster_pcm_lock_resource_x_bootstrap_round_note_x_to_s_exact( - &revoking, &shared), RESOURCE_X_APPLY_NOT_FOUND); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_bootstrap_round_note_x_to_s_exact(&revoking, &shared), + RESOURCE_X_APPLY_APPLIED); + UT_ASSERT( + !cluster_pcm_lock_resource_x_bootstrap_round_cover_matches_exact(&expected_ref, 31, 77, 8)); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_bootstrap_round_note_x_to_s_exact(&revoking, &shared), + RESOURCE_X_APPLY_NOT_FOUND); } -extern ResourceXApplyResult -cluster_pcm_lock_resource_x_target_evict_prepare_exact( - const BufferTag *tag, int32 current_master_node, - uint64 resource_formation, uint64 master_session_incarnation, - uint64 r4_record_generation, uint64 cached_ownership_generation, - uint64 reservation_token, uint32 sender_connection_generation, - int32 owner_procno, ResourceXDecodedFrame *release_out, +extern ResourceXApplyResult cluster_pcm_lock_resource_x_target_evict_prepare_exact( + const BufferTag *tag, int32 current_master_node, uint64 resource_formation, + uint64 master_session_incarnation, uint64 r4_record_generation, + uint64 cached_ownership_generation, uint64 reservation_token, + uint32 sender_connection_generation, int32 owner_procno, ResourceXDecodedFrame *release_out, ResourceXLocalOwnerHandle *handle_out); extern ResourceXApplyResult -cluster_pcm_lock_resource_x_target_evict_abort_exact( - const ResourceXLocalOwnerHandle *handle); -extern ResourceXApplyResult -cluster_pcm_lock_resource_x_target_evict_commit_exact( - const ResourceXDecodedFrame *release, int32 current_master_node, - uint64 r4_record_generation, uint64 cached_ownership_generation, - const ResourceXLocalOwnerHandle *handle); +cluster_pcm_lock_resource_x_target_evict_abort_exact(const ResourceXLocalOwnerHandle *handle); +extern ResourceXApplyResult cluster_pcm_lock_resource_x_target_evict_commit_exact( + const ResourceXDecodedFrame *release, int32 current_master_node, uint64 r4_record_generation, + uint64 cached_ownership_generation, const ResourceXLocalOwnerHandle *handle); UT_TEST(test_resource_x_bootstrap_direct_init_cached_x_consumes_same_round_t3_handoff) { @@ -8607,14 +8207,13 @@ UT_TEST(test_resource_x_bootstrap_direct_init_cached_x_consumes_same_round_t3_ha reset_fake_pcm_runtime(4); cluster_node_id = 1; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), - RESOURCE_X_APPLY_APPLIED); + RESOURCE_X_APPLY_APPLIED); UT_ASSERT(resource_x_assertion_init(&tag, 1, &assertion)); action = cluster_pcm_lock_resource_x_bootstrap_round_step_direct_init_exact( &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(1000), (UINT64_C(1000)) - (UINT64_C(100)), UINT64_C(100), UINT64_C(50), 7, 5, false, 0, &request, &terminal_ref); UT_ASSERT_EQ(action, RESOURCE_X_BOOTSTRAP_ROUND_DISPATCH_REQUEST); - ack = make_resource_x_bootstrap_ack_values( - &request, UINT64_C(9), UINT32_C(71)); + ack = make_resource_x_bootstrap_ack_values(&request, UINT64_C(9), UINT32_C(71)); action = cluster_pcm_lock_resource_x_bootstrap_round_accept_ack_exact( &ack, 0, 61, 77, UINT64_C(110), &assert_frame); UT_ASSERT_EQ(action, RESOURCE_X_BOOTSTRAP_ROUND_DISPATCH_ASSERT); @@ -8629,31 +8228,27 @@ UT_TEST(test_resource_x_bootstrap_direct_init_cached_x_consumes_same_round_t3_ha inflight.writer_activation_token = 5; inflight.pcm_state = (uint8)PCM_STATE_X; UT_ASSERT(cluster_pcm_lock_resource_x_bootstrap_round_direct_init_inflight_exact( - &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50), - 7, 5, &inflight)); + &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50), 7, 5, &inflight)); inflight.resource_x_activation_generation = 1; UT_ASSERT(cluster_pcm_lock_resource_x_bootstrap_round_direct_init_inflight_exact( - &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50), - 7, 5, &inflight)); + &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50), 7, 5, &inflight)); inflight.resource_x_activation_generation = 2; UT_ASSERT(!cluster_pcm_lock_resource_x_bootstrap_round_direct_init_inflight_exact( - &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50), - 7, 5, &inflight)); + &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50), 7, 5, &inflight)); inflight.resource_x_activation_generation = 1; inflight.writer_activation_token = 0; UT_ASSERT(!cluster_pcm_lock_resource_x_bootstrap_round_direct_init_inflight_exact( - &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50), - 7, 5, &inflight)); + &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50), 7, 5, &inflight)); expected_ref = make_resource_x_acquisition_ref(tag, 1, 17, 1); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_t1_grant_exact(&expected_ref), - RESOURCE_X_APPLY_APPLIED); + RESOURCE_X_APPLY_APPLIED); memset(&install, 0, sizeof(install)); install.ownership_generation = 8; install.writer_activation_token = 12; install.resource_x_activation_generation = 1; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_apply_exact( - &expected_ref, &install), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_apply_exact(&expected_ref, &install), + RESOURCE_X_APPLY_APPLIED); /* The direct-init sidecar clear has made exact generation 8 visible, * while the DATA worker has not yet called requester_activate/publish. @@ -8662,13 +8257,13 @@ UT_TEST(test_resource_x_bootstrap_direct_init_cached_x_consumes_same_round_t3_ha &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(1000), (UINT64_C(1000)) - (UINT64_C(115)), UINT64_C(115), UINT64_C(50), 7, 5, true, 8, &unused_dispatch, &terminal_ref); UT_ASSERT_EQ(action, RESOURCE_X_BOOTSTRAP_ROUND_TERMINAL); - UT_ASSERT(memcmp(&terminal_ref, &expected_ref, - sizeof(terminal_ref)) == 0); + UT_ASSERT(memcmp(&terminal_ref, &expected_ref, sizeof(terminal_ref)) == 0); memset(&executor_snapshot, 0, sizeof(executor_snapshot)); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_executor_probe_exact( - &expected_ref, &executor_snapshot), RESOURCE_X_EXECUTOR_COMPLETE); - UT_ASSERT(cluster_pcm_lock_resource_x_bootstrap_round_cover_matches_exact( - &expected_ref, 31, 77, 8)); + UT_ASSERT_EQ( + cluster_pcm_lock_resource_x_executor_probe_exact(&expected_ref, &executor_snapshot), + RESOURCE_X_EXECUTOR_COMPLETE); + UT_ASSERT( + cluster_pcm_lock_resource_x_bootstrap_round_cover_matches_exact(&expected_ref, 31, 77, 8)); /* BufferDesc and the requester round are separate lock domains. A * foreground direct initializer may have sampled this exact pre-T3 X @@ -8679,22 +8274,19 @@ UT_TEST(test_resource_x_bootstrap_direct_init_cached_x_consumes_same_round_t3_ha inflight.writer_activation_token = 5; inflight.resource_x_activation_generation = 1; UT_ASSERT(cluster_pcm_lock_resource_x_bootstrap_round_direct_init_inflight_exact( - &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50), - 7, 5, &inflight)); + &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50), 7, 5, &inflight)); inflight.generation = 9; UT_ASSERT(!cluster_pcm_lock_resource_x_bootstrap_round_direct_init_inflight_exact( - &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50), - 7, 5, &inflight)); + &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50), 7, 5, &inflight)); inflight.generation = 8; memset(&activation, 0, sizeof(activation)); activation.ownership_generation = 8; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_activate_exact( - &expected_ref, &activation), RESOURCE_X_APPLY_DUPLICATE); - UT_ASSERT_EQ( - cluster_pcm_lock_resource_x_bootstrap_round_publish_terminal_exact( - &expected_ref, 31, 77, 8, 10, UINT64_C(120)), - RESOURCE_X_APPLY_DUPLICATE); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_activate_exact(&expected_ref, &activation), + RESOURCE_X_APPLY_DUPLICATE); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_bootstrap_round_publish_terminal_exact( + &expected_ref, 31, 77, 8, 10, UINT64_C(120)), + RESOURCE_X_APPLY_DUPLICATE); /* Once the exact direct-init round has become the retained node-X cover, * an ordinary same-node writer joins that cover by its terminal identity. @@ -8705,15 +8297,13 @@ UT_TEST(test_resource_x_bootstrap_direct_init_cached_x_consumes_same_round_t3_ha &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(1000), (UINT64_C(1000)) - (UINT64_C(125)), UINT64_C(125), UINT64_C(50), true, 8, &unused_dispatch, &terminal_ref); UT_ASSERT_EQ(action, RESOURCE_X_BOOTSTRAP_ROUND_TERMINAL); - UT_ASSERT(memcmp(&terminal_ref, &expected_ref, - sizeof(terminal_ref)) == 0); + UT_ASSERT(memcmp(&terminal_ref, &expected_ref, sizeof(terminal_ref)) == 0); /* The old terminal holder and the incoming FIFO successor are distinct * Resource-X episodes. They join only at the exact canonical-authority * edge: accepted base 9 granted old X at 10, and the successor blocks on * base 10. */ - successor_block = make_resource_x_master_frame( - RESOURCE_X_WIRE_BLOCK_TO_N, tag, 2, 1); + successor_block = make_resource_x_master_frame(RESOURCE_X_WIRE_BLOCK_TO_N, tag, 2, 1); successor_block.payload_bytes = RESOURCE_X_CONTROL_V1_BYTES; successor_block.common.base_authority_generation = UINT64_C(10); successor_block.common.authority_generation = UINT64_C(10); @@ -8723,14 +8313,11 @@ UT_TEST(test_resource_x_bootstrap_direct_init_cached_x_consumes_same_round_t3_ha successor_block.common.source_candidate = 1; successor_block.common.retain_pi_if_dirty = 1; memset(&lineage, 0, sizeof(lineage)); - UT_ASSERT( - cluster_pcm_lock_resource_x_bootstrap_round_direct_init_terminal_holder_exact( - &successor_block, 0, 77, 8, &lineage)); - UT_ASSERT(resource_x_assertion_equal( - &lineage.holder_assertion, &expected_ref.assertion)); - UT_ASSERT(!resource_x_assertion_equal( - &lineage.holder_assertion, - &successor_block.common.logical_assertion)); + UT_ASSERT(cluster_pcm_lock_resource_x_bootstrap_round_direct_init_terminal_holder_exact( + &successor_block, 0, 77, 8, &lineage)); + UT_ASSERT(resource_x_assertion_equal(&lineage.holder_assertion, &expected_ref.assertion)); + UT_ASSERT(!resource_x_assertion_equal(&lineage.holder_assertion, + &successor_block.common.logical_assertion)); UT_ASSERT_EQ(lineage.holder_attempt, UINT64_C(1)); UT_ASSERT_EQ(lineage.accepted_base_authority_generation, UINT64_C(9)); UT_ASSERT_EQ(lineage.final_authority_generation, UINT64_C(10)); @@ -8759,26 +8346,21 @@ UT_TEST(test_resource_x_bootstrap_direct_init_cached_x_consumes_same_round_t3_ha successor_block.common.base_authority_generation = UINT64_C(9); successor_block.common.authority_generation = UINT64_C(9); - UT_ASSERT( - !cluster_pcm_lock_resource_x_bootstrap_round_direct_init_terminal_holder_exact( - &successor_block, 0, 77, 8, &lineage)); + UT_ASSERT(!cluster_pcm_lock_resource_x_bootstrap_round_direct_init_terminal_holder_exact( + &successor_block, 0, 77, 8, &lineage)); successor_block.common.base_authority_generation = UINT64_C(10); successor_block.common.authority_generation = UINT64_C(10); - UT_ASSERT( - !cluster_pcm_lock_resource_x_bootstrap_round_direct_init_terminal_holder_exact( - &successor_block, 0, 77, 9, &lineage)); - UT_ASSERT( - !cluster_pcm_lock_resource_x_bootstrap_round_direct_init_terminal_holder_exact( - &successor_block, 1, 77, 8, &lineage)); + UT_ASSERT(!cluster_pcm_lock_resource_x_bootstrap_round_direct_init_terminal_holder_exact( + &successor_block, 0, 77, 9, &lineage)); + UT_ASSERT(!cluster_pcm_lock_resource_x_bootstrap_round_direct_init_terminal_holder_exact( + &successor_block, 1, 77, 8, &lineage)); successor_block.common.resource_formation++; - UT_ASSERT( - !cluster_pcm_lock_resource_x_bootstrap_round_direct_init_terminal_holder_exact( - &successor_block, 0, 77, 8, &lineage)); + UT_ASSERT(!cluster_pcm_lock_resource_x_bootstrap_round_direct_init_terminal_holder_exact( + &successor_block, 0, 77, 8, &lineage)); successor_block.common.resource_formation--; successor_block.common.master_session_incarnation++; - UT_ASSERT( - !cluster_pcm_lock_resource_x_bootstrap_round_direct_init_terminal_holder_exact( - &successor_block, 0, 77, 8, &lineage)); + UT_ASSERT(!cluster_pcm_lock_resource_x_bootstrap_round_direct_init_terminal_holder_exact( + &successor_block, 0, 77, 8, &lineage)); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_bootstrap_round_wait_exact( &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50), UINT64_MAX - 1, 1), RESOURCE_X_APPLY_DUPLICATE); @@ -8821,34 +8403,32 @@ UT_TEST(test_resource_x_cached_x_eviction_prepares_and_commits_release) fake_pcm_clock_us = 200; cluster_node_id = 1; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), - RESOURCE_X_APPLY_APPLIED); + RESOURCE_X_APPLY_APPLIED); UT_ASSERT(resource_x_assertion_init(&tag, 1, &assertion)); action = cluster_pcm_lock_resource_x_bootstrap_round_step_direct_init_exact( &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(1000), (UINT64_C(1000)) - (UINT64_C(100)), UINT64_C(100), UINT64_C(50), 7, 5, false, 0, &request, &terminal_ref); UT_ASSERT_EQ(action, RESOURCE_X_BOOTSTRAP_ROUND_DISPATCH_REQUEST); - ack = make_resource_x_bootstrap_ack_values( - &request, UINT64_C(9), UINT32_C(71)); + ack = make_resource_x_bootstrap_ack_values(&request, UINT64_C(9), UINT32_C(71)); action = cluster_pcm_lock_resource_x_bootstrap_round_accept_ack_exact( &ack, 0, 61, 77, UINT64_C(110), &assert_frame); UT_ASSERT_EQ(action, RESOURCE_X_BOOTSTRAP_ROUND_DISPATCH_ASSERT); expected_ref = make_resource_x_acquisition_ref(tag, 1, 17, 1); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_t1_grant_exact(&expected_ref), - RESOURCE_X_APPLY_APPLIED); + RESOURCE_X_APPLY_APPLIED); memset(&install, 0, sizeof(install)); install.ownership_generation = 8; install.writer_activation_token = 12; install.resource_x_activation_generation = 1; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_apply_exact( - &expected_ref, &install), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_apply_exact(&expected_ref, &install), + RESOURCE_X_APPLY_APPLIED); action = cluster_pcm_lock_resource_x_bootstrap_round_step_direct_init_exact( &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(1000), (UINT64_C(1000)) - (UINT64_C(115)), UINT64_C(115), UINT64_C(50), 7, 5, true, 8, &unused_dispatch, &terminal_ref); UT_ASSERT_EQ(action, RESOURCE_X_BOOTSTRAP_ROUND_TERMINAL); - UT_ASSERT(cluster_pcm_lock_resource_x_bootstrap_round_cover_matches_exact( - &expected_ref, 31, 77, 8)); - UT_ASSERT(pcm_entry_ref_acquire( - &tag, false, &entry_ref, &acquire_result)); + UT_ASSERT( + cluster_pcm_lock_resource_x_bootstrap_round_cover_matches_exact(&expected_ref, 31, 77, 8)); + UT_ASSERT(pcm_entry_ref_acquire(&tag, false, &entry_ref, &acquire_result)); binding_generation = entry_ref.binding_generation; pcm_entry_ref_release(&entry_ref); @@ -8858,25 +8438,19 @@ UT_TEST(test_resource_x_cached_x_eviction_prepares_and_commits_release) * not cross that owner. */ memset(&release, 0x5a, sizeof(release)); memset(&eviction, 0x5a, sizeof(eviction)); - UT_ASSERT_EQ( - cluster_pcm_lock_resource_x_target_evict_prepare_exact( - &tag, 0, 17, 31, 77, 9, 13, 81, 7, - &release, &eviction), - RESOURCE_X_APPLY_STALE); - UT_ASSERT_EQ(memcmp(&release, - &(ResourceXDecodedFrame){0}, sizeof(release)), 0); - UT_ASSERT_EQ(memcmp(&eviction, - &(ResourceXLocalOwnerHandle){0}, sizeof(eviction)), 0); - UT_ASSERT_EQ( - cluster_pcm_lock_resource_x_target_evict_prepare_exact( - &tag, 0, 17, 31, 77, 8, 13, 81, 7, - &release, &eviction), - RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_target_evict_prepare_exact(&tag, 0, 17, 31, 77, 9, 13, + 81, 7, &release, &eviction), + RESOURCE_X_APPLY_STALE); + UT_ASSERT_EQ(memcmp(&release, &(ResourceXDecodedFrame){ 0 }, sizeof(release)), 0); + UT_ASSERT_EQ(memcmp(&eviction, &(ResourceXLocalOwnerHandle){ 0 }, sizeof(eviction)), 0); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_target_evict_prepare_exact(&tag, 0, 17, 31, 77, 8, 13, + 81, 7, &release, &eviction), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(release.kind, RESOURCE_X_WIRE_RELEASE_X); UT_ASSERT_EQ(release.payload_bytes, RESOURCE_X_CONTROL_V1_BYTES); UT_ASSERT(!release.blocked_has_remote_proof); - UT_ASSERT(resource_x_assertion_equal( - &release.common.logical_assertion, &expected_ref.assertion)); + UT_ASSERT( + resource_x_assertion_equal(&release.common.logical_assertion, &expected_ref.assertion)); UT_ASSERT_EQ(release.common.base_authority_generation, UINT64_C(9)); UT_ASSERT_EQ(release.common.authority_generation, UINT64_C(10)); UT_ASSERT_EQ(release.common.resource_formation, UINT64_C(17)); @@ -8891,8 +8465,7 @@ UT_TEST(test_resource_x_cached_x_eviction_prepares_and_commits_release) UT_ASSERT_EQ(release.common.sender_connection_generation, UINT32_C(81)); UT_ASSERT_EQ(release.common.outcome, RESOURCE_X_OUTCOME_OK); UT_ASSERT_EQ(release.common.flags, 0); - UT_ASSERT_EQ(memcmp(&eviction.ref, &expected_ref, - sizeof(expected_ref)), 0); + UT_ASSERT_EQ(memcmp(&eviction.ref, &expected_ref, sizeof(expected_ref)), 0); UT_ASSERT_EQ(eviction.master_session_incarnation, UINT64_C(31)); UT_ASSERT_EQ(eviction.r4_record_generation, UINT64_C(77)); UT_ASSERT_EQ(eviction.buffer_ownership_generation, UINT64_C(8)); @@ -8902,71 +8475,57 @@ UT_TEST(test_resource_x_cached_x_eviction_prepares_and_commits_release) memset(&replay_release, 0, sizeof(replay_release)); memset(&replay_eviction, 0, sizeof(replay_eviction)); - UT_ASSERT_EQ( - cluster_pcm_lock_resource_x_target_evict_prepare_exact( - &tag, 0, 17, 31, 77, 8, 13, 81, 7, - &replay_release, &replay_eviction), - RESOURCE_X_APPLY_DUPLICATE); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_target_evict_prepare_exact( + &tag, 0, 17, 31, 77, 8, 13, 81, 7, &replay_release, &replay_eviction), + RESOURCE_X_APPLY_DUPLICATE); UT_ASSERT_EQ(memcmp(&replay_release, &release, sizeof(release)), 0); UT_ASSERT_EQ(memcmp(&replay_eviction, &eviction, sizeof(eviction)), 0); - UT_ASSERT_EQ( - cluster_pcm_lock_resource_x_target_evict_prepare_exact( - &tag, 0, 17, 31, 77, 8, 14, 81, 7, - &replay_release, &replay_eviction), - RESOURCE_X_APPLY_BAD_STATE); - UT_ASSERT(!pcm_entry_retire_classify_exact( - &tag, binding_generation, &why)); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_target_evict_prepare_exact( + &tag, 0, 17, 31, 77, 8, 14, 81, 7, &replay_release, &replay_eviction), + RESOURCE_X_APPLY_BAD_STATE); + UT_ASSERT(!pcm_entry_retire_classify_exact(&tag, binding_generation, &why)); UT_ASSERT_EQ(why, PCM_RETIRE_REFUSAL_RESOURCE_X_ACTIVE); memset(&lost, 0, sizeof(lost)); lost.tag = tag; lost.pcm_state = (uint8)PCM_STATE_N; lost.generation = 9; - UT_ASSERT_EQ( - cluster_pcm_lock_resource_x_bootstrap_round_invalidate_ownership_loss_exact( - &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50), &lost), - RESOURCE_X_APPLY_BAD_STATE); - UT_ASSERT(cluster_pcm_lock_resource_x_bootstrap_round_cover_matches_exact( - &expected_ref, 31, 77, 8)); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_bootstrap_round_invalidate_ownership_loss_exact( + &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50), &lost), + RESOURCE_X_APPLY_BAD_STATE); + UT_ASSERT( + cluster_pcm_lock_resource_x_bootstrap_round_cover_matches_exact(&expected_ref, 31, 77, 8)); stale_eviction = eviction; stale_eviction.owner_generation++; - UT_ASSERT_EQ( - cluster_pcm_lock_resource_x_target_evict_abort_exact(&stale_eviction), - RESOURCE_X_APPLY_STALE); - UT_ASSERT_EQ( - cluster_pcm_lock_resource_x_target_evict_abort_exact(&eviction), - RESOURCE_X_APPLY_APPLIED); - UT_ASSERT(cluster_pcm_lock_resource_x_bootstrap_round_cover_matches_exact( - &expected_ref, 31, 77, 8)); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_target_evict_abort_exact(&stale_eviction), + RESOURCE_X_APPLY_STALE); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_target_evict_abort_exact(&eviction), + RESOURCE_X_APPLY_APPLIED); + UT_ASSERT( + cluster_pcm_lock_resource_x_bootstrap_round_cover_matches_exact(&expected_ref, 31, 77, 8)); - UT_ASSERT_EQ( - cluster_pcm_lock_resource_x_target_evict_prepare_exact( - &tag, 0, 17, 31, 77, 8, 14, 81, 7, - &release, &eviction), - RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_target_evict_prepare_exact(&tag, 0, 17, 31, 77, 8, 14, + 81, 7, &release, &eviction), + RESOURCE_X_APPLY_APPLIED); stale_eviction = eviction; stale_eviction.reservation_token++; UT_ASSERT_EQ( - cluster_pcm_lock_resource_x_target_evict_commit_exact( - &release, 0, 77, 8, &stale_eviction), + cluster_pcm_lock_resource_x_target_evict_commit_exact(&release, 0, 77, 8, &stale_eviction), RESOURCE_X_APPLY_STALE); UT_ASSERT_EQ( - cluster_pcm_lock_resource_x_target_evict_commit_exact( - &release, 0, 77, 8, &eviction), + cluster_pcm_lock_resource_x_target_evict_commit_exact(&release, 0, 77, 8, &eviction), RESOURCE_X_APPLY_APPLIED); - UT_ASSERT(!cluster_pcm_lock_resource_x_bootstrap_round_cover_matches_exact( - &expected_ref, 31, 77, 8)); + UT_ASSERT( + !cluster_pcm_lock_resource_x_bootstrap_round_cover_matches_exact(&expected_ref, 31, 77, 8)); UT_ASSERT_EQ((int)cluster_pcm_lock_query(tag), (int)PCM_LOCK_MODE_N); - residual_entry = pcm_entry_ref_acquire( - &tag, false, &entry_ref, &acquire_result); + residual_entry = pcm_entry_ref_acquire(&tag, false, &entry_ref, &acquire_result); if (residual_entry) pcm_entry_ref_release(&entry_ref); UT_ASSERT(!residual_entry); UT_ASSERT_EQ(acquire_result, PCM_ENTRY_ACQUIRE_NOT_FOUND); UT_ASSERT_EQ( - cluster_pcm_lock_resource_x_target_evict_commit_exact( - &release, 0, 77, 8, &eviction), + cluster_pcm_lock_resource_x_target_evict_commit_exact(&release, 0, 77, 8, &eviction), RESOURCE_X_APPLY_NOT_FOUND); } @@ -8991,14 +8550,14 @@ UT_TEST(test_resource_x_local_master_release_keeps_cached_cover_until_commit) reset_fake_pcm_runtime(4); cluster_node_id = 0; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), - RESOURCE_X_APPLY_APPLIED); + RESOURCE_X_APPLY_APPLIED); UT_ASSERT(resource_x_assertion_init(&tag, 0, &assertion)); action = cluster_pcm_lock_resource_x_bootstrap_round_step_direct_init_exact( &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(1000), (UINT64_C(1000)) - (UINT64_C(100)), UINT64_C(100), UINT64_C(50), 7, 5, false, 0, &request, &terminal_ref); UT_ASSERT_EQ(action, RESOURCE_X_BOOTSTRAP_ROUND_DISPATCH_REQUEST); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_bootstrap_request_exact( - &request, 0, 61, 77, 31, 71, &ack), + UT_ASSERT_EQ( + cluster_pcm_lock_resource_x_bootstrap_request_exact(&request, 0, 61, 77, 31, 71, &ack), RESOURCE_X_APPLY_APPLIED); action = cluster_pcm_lock_resource_x_bootstrap_round_accept_ack_exact( &ack, 0, 61, 77, UINT64_C(110), &assert_frame); @@ -9009,39 +8568,35 @@ UT_TEST(test_resource_x_local_master_release_keeps_cached_cover_until_commit) memset(&durable, 0, sizeof(durable)); durable.assertion = assertion; - durable.base_authority_generation - = assert_frame.common.base_authority_generation; + durable.base_authority_generation = assert_frame.common.base_authority_generation; durable.resource_formation = 17; durable.master_session_incarnation = 31; durable.assertion_sequence = assert_frame.common.assertion_sequence; - durable.requester_target_generation - = assert_frame.common.assertion_sequence; + durable.requester_target_generation = assert_frame.common.assertion_sequence; durable.page_scn_lsn = 82; durable.page_checksum = UINT32_C(0x12345678); durable.source_proof_crc32c = UINT32_C(0x87654321); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_durable_proof_exact( - &durable, &snapshot), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_durable_proof_exact(&durable, &snapshot), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(snapshot.phase, RESOURCE_X_MASTER_GRANT_COMMITTED); - expected_ref = make_resource_x_acquisition_ref(tag, 0, 17, - assert_frame.common.assertion_sequence); + expected_ref + = make_resource_x_acquisition_ref(tag, 0, 17, assert_frame.common.assertion_sequence); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_t1_grant_exact(&expected_ref), - RESOURCE_X_APPLY_APPLIED); + RESOURCE_X_APPLY_APPLIED); memset(&install, 0, sizeof(install)); install.ownership_generation = 8; install.writer_activation_token = 12; - install.resource_x_activation_generation - = assert_frame.common.assertion_sequence; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_apply_exact( - &expected_ref, &install), RESOURCE_X_APPLY_APPLIED); + install.resource_x_activation_generation = assert_frame.common.assertion_sequence; + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_apply_exact(&expected_ref, &install), + RESOURCE_X_APPLY_APPLIED); settlement = assert_frame; settlement.kind = RESOURCE_X_WIRE_INSTALL_SETTLEMENT; memset(&settlement.body, 0, sizeof(settlement.body)); settlement.common.ordered_lane = 0; settlement.common.outcome = RESOURCE_X_OUTCOME_OK; - settlement.common.authority_generation - = snapshot.final_authority_generation; + settlement.common.authority_generation = snapshot.final_authority_generation; settlement.body.install_settlement.conversion_base_generation = assert_frame.common.base_authority_generation; settlement.body.install_settlement.final_authority_generation @@ -9050,59 +8605,48 @@ UT_TEST(test_resource_x_local_master_release_keeps_cached_cover_until_commit) settlement.body.install_settlement.requester_target_generation = assert_frame.common.assertion_sequence; settlement.body.install_settlement.page_scn_lsn = 82; - settlement.body.install_settlement.page_checksum - = UINT32_C(0x12345678); - settlement.body.install_settlement.source_proof_crc32c - = UINT32_C(0x87654321); + settlement.body.install_settlement.page_checksum = UINT32_C(0x12345678); + settlement.body.install_settlement.source_proof_crc32c = UINT32_C(0x87654321); settlement.body.install_settlement.installed_mode = PCM_STATE_X; - settlement.body.install_settlement.requester_role - = RESOURCE_X_REQUESTER_ROLE_ACQUIRER; - settlement.body.install_settlement.terminal_outcome - = RESOURCE_X_OUTCOME_OK; - settlement.body.install_settlement.terminal_state - = RESOURCE_X_SETTLEMENT_TERMINAL_INSTALLED; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_install_settlement_exact( - &settlement, 0, &snapshot), RESOURCE_X_APPLY_APPLIED); + settlement.body.install_settlement.requester_role = RESOURCE_X_REQUESTER_ROLE_ACQUIRER; + settlement.body.install_settlement.terminal_outcome = RESOURCE_X_OUTCOME_OK; + settlement.body.install_settlement.terminal_state = RESOURCE_X_SETTLEMENT_TERMINAL_INSTALLED; + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_install_settlement_exact(&settlement, 0, &snapshot), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(snapshot.phase, RESOURCE_X_MASTER_SETTLED); action = cluster_pcm_lock_resource_x_bootstrap_round_step_direct_init_exact( &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(1000), (UINT64_C(1000)) - (UINT64_C(115)), UINT64_C(115), UINT64_C(50), 7, 5, true, 8, &unused_dispatch, &terminal_ref); UT_ASSERT_EQ(action, RESOURCE_X_BOOTSTRAP_ROUND_TERMINAL); - UT_ASSERT(cluster_pcm_lock_resource_x_bootstrap_round_cover_matches_exact( - &expected_ref, 31, 77, 8)); - UT_ASSERT_EQ( - cluster_pcm_lock_resource_x_target_evict_prepare_exact( - &tag, 0, 17, 31, 77, 8, 13, 81, 7, - &release, &eviction), - RESOURCE_X_APPLY_APPLIED); - UT_ASSERT_EQ( - cluster_pcm_lock_resource_x_target_evict_abort_exact(&eviction), - RESOURCE_X_APPLY_APPLIED); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_release_x_exact( - &release, 0, &snapshot), RESOURCE_X_APPLY_STALE); + UT_ASSERT( + cluster_pcm_lock_resource_x_bootstrap_round_cover_matches_exact(&expected_ref, 31, 77, 8)); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_target_evict_prepare_exact(&tag, 0, 17, 31, 77, 8, 13, + 81, 7, &release, &eviction), + RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_target_evict_abort_exact(&eviction), + RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_release_x_exact(&release, 0, &snapshot), + RESOURCE_X_APPLY_STALE); UT_ASSERT_EQ((int)cluster_pcm_lock_query(tag), (int)PCM_LOCK_MODE_X); - UT_ASSERT(cluster_pcm_lock_resource_x_bootstrap_round_cover_matches_exact( - &expected_ref, 31, 77, 8)); - UT_ASSERT_EQ( - cluster_pcm_lock_resource_x_target_evict_prepare_exact( - &tag, 0, 17, 31, 77, 8, 14, 81, 7, - &release, &eviction), - RESOURCE_X_APPLY_APPLIED); + UT_ASSERT( + cluster_pcm_lock_resource_x_bootstrap_round_cover_matches_exact(&expected_ref, 31, 77, 8)); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_target_evict_prepare_exact(&tag, 0, 17, 31, 77, 8, 14, + 81, 7, &release, &eviction), + RESOURCE_X_APPLY_APPLIED); /* Local-master kind-4 apply mutates the canonical GRD X to N, but the * requester cover is still the immutable admission evidence required by * the matching release commit. Only that commit may clear it. */ - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_release_x_exact( - &release, 0, &snapshot), RESOURCE_X_APPLY_APPLIED); - UT_ASSERT(cluster_pcm_lock_resource_x_bootstrap_round_cover_matches_exact( - &expected_ref, 31, 77, 8)); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_release_x_exact(&release, 0, &snapshot), + RESOURCE_X_APPLY_APPLIED); + UT_ASSERT( + cluster_pcm_lock_resource_x_bootstrap_round_cover_matches_exact(&expected_ref, 31, 77, 8)); UT_ASSERT_EQ( - cluster_pcm_lock_resource_x_target_evict_commit_exact( - &release, 0, 77, 8, &eviction), + cluster_pcm_lock_resource_x_target_evict_commit_exact(&release, 0, 77, 8, &eviction), RESOURCE_X_APPLY_APPLIED); - UT_ASSERT(!cluster_pcm_lock_resource_x_bootstrap_round_cover_matches_exact( - &expected_ref, 31, 77, 8)); + UT_ASSERT( + !cluster_pcm_lock_resource_x_bootstrap_round_cover_matches_exact(&expected_ref, 31, 77, 8)); } UT_TEST(test_resource_x_local_n_without_evicting_owner_is_post_mutation_ambiguity) @@ -9130,67 +8674,60 @@ UT_TEST(test_resource_x_local_n_without_evicting_owner_is_post_mutation_ambiguit reset_fake_pcm_runtime(4); cluster_node_id = 0; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), - RESOURCE_X_APPLY_APPLIED); + RESOURCE_X_APPLY_APPLIED); UT_ASSERT(resource_x_assertion_init(&tag, 0, &assertion)); action = cluster_pcm_lock_resource_x_bootstrap_round_step_direct_init_exact( &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(1000), (UINT64_C(1000)) - (UINT64_C(100)), UINT64_C(100), UINT64_C(50), 7, 5, false, 0, &request, &terminal_ref); UT_ASSERT_EQ(action, RESOURCE_X_BOOTSTRAP_ROUND_DISPATCH_REQUEST); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_bootstrap_request_exact( - &request, 0, 61, 77, 31, 71, &ack), + UT_ASSERT_EQ( + cluster_pcm_lock_resource_x_bootstrap_request_exact(&request, 0, 61, 77, 31, 71, &ack), RESOURCE_X_APPLY_APPLIED); action = cluster_pcm_lock_resource_x_bootstrap_round_accept_ack_exact( &ack, 0, 61, 77, UINT64_C(110), &assert_frame); UT_ASSERT_EQ(action, RESOURCE_X_BOOTSTRAP_ROUND_DISPATCH_ASSERT); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_bootstrapped_exact( - &assert_frame, 0, 61, 77, 31, 71, &snapshot), - RESOURCE_X_APPLY_APPLIED); - successor_assert = make_resource_x_master_frame( - RESOURCE_X_WIRE_ASSERT_X, tag, 1, 1); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_bootstrapped_exact(&assert_frame, 0, 61, 77, 31, + 71, &snapshot), + RESOURCE_X_APPLY_APPLIED); + successor_assert = make_resource_x_master_frame(RESOURCE_X_WIRE_ASSERT_X, tag, 1, 1); successor_assert.common.base_authority_generation = assert_frame.common.base_authority_generation; - successor_assert.common.authority_generation - = assert_frame.common.base_authority_generation; - successor_assert.common.assertion_sequence - = assert_frame.common.assertion_sequence + 1; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact( - &successor_assert, 1, &snapshot), RESOURCE_X_APPLY_APPLIED); + successor_assert.common.authority_generation = assert_frame.common.base_authority_generation; + successor_assert.common.assertion_sequence = assert_frame.common.assertion_sequence + 1; + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact(&successor_assert, 1, &snapshot), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(snapshot.phase, RESOURCE_X_MASTER_QUEUED); memset(&durable, 0, sizeof(durable)); durable.assertion = assertion; - durable.base_authority_generation - = assert_frame.common.base_authority_generation; + durable.base_authority_generation = assert_frame.common.base_authority_generation; durable.resource_formation = 17; durable.master_session_incarnation = 31; durable.assertion_sequence = assert_frame.common.assertion_sequence; - durable.requester_target_generation - = assert_frame.common.assertion_sequence; + durable.requester_target_generation = assert_frame.common.assertion_sequence; durable.page_scn_lsn = 82; durable.page_checksum = UINT32_C(0x12345678); durable.source_proof_crc32c = UINT32_C(0x87654321); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_durable_proof_exact( - &durable, &snapshot), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_durable_proof_exact(&durable, &snapshot), + RESOURCE_X_APPLY_APPLIED); - expected_ref = make_resource_x_acquisition_ref(tag, 0, 17, - assert_frame.common.assertion_sequence); + expected_ref + = make_resource_x_acquisition_ref(tag, 0, 17, assert_frame.common.assertion_sequence); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_t1_grant_exact(&expected_ref), - RESOURCE_X_APPLY_APPLIED); + RESOURCE_X_APPLY_APPLIED); memset(&install, 0, sizeof(install)); install.ownership_generation = 8; install.writer_activation_token = 12; - install.resource_x_activation_generation - = assert_frame.common.assertion_sequence; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_apply_exact( - &expected_ref, &install), RESOURCE_X_APPLY_APPLIED); + install.resource_x_activation_generation = assert_frame.common.assertion_sequence; + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_apply_exact(&expected_ref, &install), + RESOURCE_X_APPLY_APPLIED); settlement = assert_frame; settlement.kind = RESOURCE_X_WIRE_INSTALL_SETTLEMENT; memset(&settlement.body, 0, sizeof(settlement.body)); settlement.common.ordered_lane = 0; settlement.common.outcome = RESOURCE_X_OUTCOME_OK; - settlement.common.authority_generation - = snapshot.final_authority_generation; + settlement.common.authority_generation = snapshot.final_authority_generation; settlement.body.install_settlement.conversion_base_generation = assert_frame.common.base_authority_generation; settlement.body.install_settlement.final_authority_generation @@ -9199,39 +8736,30 @@ UT_TEST(test_resource_x_local_n_without_evicting_owner_is_post_mutation_ambiguit settlement.body.install_settlement.requester_target_generation = assert_frame.common.assertion_sequence; settlement.body.install_settlement.page_scn_lsn = 82; - settlement.body.install_settlement.page_checksum - = UINT32_C(0x12345678); - settlement.body.install_settlement.source_proof_crc32c - = UINT32_C(0x87654321); + settlement.body.install_settlement.page_checksum = UINT32_C(0x12345678); + settlement.body.install_settlement.source_proof_crc32c = UINT32_C(0x87654321); settlement.body.install_settlement.installed_mode = PCM_STATE_X; - settlement.body.install_settlement.requester_role - = RESOURCE_X_REQUESTER_ROLE_ACQUIRER; - settlement.body.install_settlement.terminal_outcome - = RESOURCE_X_OUTCOME_OK; - settlement.body.install_settlement.terminal_state - = RESOURCE_X_SETTLEMENT_TERMINAL_INSTALLED; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_install_settlement_exact( - &settlement, 0, &snapshot), RESOURCE_X_APPLY_APPLIED); + settlement.body.install_settlement.requester_role = RESOURCE_X_REQUESTER_ROLE_ACQUIRER; + settlement.body.install_settlement.terminal_outcome = RESOURCE_X_OUTCOME_OK; + settlement.body.install_settlement.terminal_state = RESOURCE_X_SETTLEMENT_TERMINAL_INSTALLED; + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_install_settlement_exact(&settlement, 0, &snapshot), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_master_snapshot_exact( - &successor_assert.common.logical_assertion, &successor_before), - RESOURCE_X_APPLY_APPLIED); + &successor_assert.common.logical_assertion, &successor_before), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(successor_before.phase, RESOURCE_X_MASTER_WAIT_BLOCKERS); action = cluster_pcm_lock_resource_x_bootstrap_round_step_direct_init_exact( &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(1000), (UINT64_C(1000)) - (UINT64_C(115)), UINT64_C(115), UINT64_C(50), 7, 5, true, 8, &unused_dispatch, &terminal_ref); UT_ASSERT_EQ(action, RESOURCE_X_BOOTSTRAP_ROUND_TERMINAL); - UT_ASSERT_EQ( - cluster_pcm_lock_resource_x_target_evict_prepare_exact( - &tag, 0, 17, 31, 77, 8, 13, 81, 7, - &release, &eviction), - RESOURCE_X_APPLY_BAD_STATE); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_target_evict_prepare_exact(&tag, 0, 17, 31, 77, 8, 13, + 81, 7, &release, &eviction), + RESOURCE_X_APPLY_BAD_STATE); /* A local master with an active FIFO successor rejects cache eviction * before BufferDesc X->N and returns no reusable plan bytes or owner. */ - UT_ASSERT_EQ(memcmp(&release, - &(ResourceXDecodedFrame){0}, sizeof(release)), 0); - UT_ASSERT_EQ(memcmp(&eviction, - &(ResourceXLocalOwnerHandle){0}, sizeof(eviction)), 0); + UT_ASSERT_EQ(memcmp(&release, &(ResourceXDecodedFrame){ 0 }, sizeof(release)), 0); + UT_ASSERT_EQ(memcmp(&eviction, &(ResourceXLocalOwnerHandle){ 0 }, sizeof(eviction)), 0); /* Local N without the exact EVICTING owner means the irreversible * BufferDesc step lost its completion evidence. It is post-mutation * ambiguity: retain the terminal cover and canonical master state rather @@ -9240,18 +8768,16 @@ UT_TEST(test_resource_x_local_n_without_evicting_owner_is_post_mutation_ambiguit lost.tag = tag; lost.pcm_state = (uint8)PCM_STATE_N; lost.generation = 9; - UT_ASSERT_EQ( - cluster_pcm_lock_resource_x_bootstrap_round_invalidate_ownership_loss_exact( - &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50), &lost), - RESOURCE_X_APPLY_RECOVERY_BLOCKED); - UT_ASSERT(cluster_pcm_lock_resource_x_bootstrap_round_cover_matches_exact( - &expected_ref, 31, 77, 8)); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_bootstrap_round_invalidate_ownership_loss_exact( + &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50), &lost), + RESOURCE_X_APPLY_RECOVERY_BLOCKED); + UT_ASSERT( + cluster_pcm_lock_resource_x_bootstrap_round_cover_matches_exact(&expected_ref, 31, 77, 8)); UT_ASSERT_EQ((int)cluster_pcm_lock_query(tag), (int)PCM_LOCK_MODE_X); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_master_snapshot_exact( - &successor_assert.common.logical_assertion, &successor_after), - RESOURCE_X_APPLY_APPLIED); - UT_ASSERT_EQ(memcmp(&successor_before, &successor_after, - sizeof(successor_before)), 0); + &successor_assert.common.logical_assertion, &successor_after), + RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(memcmp(&successor_before, &successor_after, sizeof(successor_before)), 0); } UT_TEST(test_resource_x_terminal_remote_holder_binds_exact_final_authority) @@ -9276,39 +8802,36 @@ UT_TEST(test_resource_x_terminal_remote_holder_binds_exact_final_authority) tag.forkNum = VISIBILITYMAP_FORKNUM; cluster_node_id = 1; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), - RESOURCE_X_APPLY_APPLIED); + RESOURCE_X_APPLY_APPLIED); UT_ASSERT(resource_x_assertion_init(&tag, 1, &assertion)); action = cluster_pcm_lock_resource_x_bootstrap_round_step_exact( &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(1000), (UINT64_C(1000)) - (UINT64_C(100)), UINT64_C(100), UINT64_C(50), false, 0, &request, &terminal_ref); UT_ASSERT_EQ(action, RESOURCE_X_BOOTSTRAP_ROUND_DISPATCH_REQUEST); - ack = make_resource_x_bootstrap_ack_values( - &request, UINT64_C(9), UINT32_C(71)); + ack = make_resource_x_bootstrap_ack_values(&request, UINT64_C(9), UINT32_C(71)); action = cluster_pcm_lock_resource_x_bootstrap_round_accept_ack_exact( &ack, 0, 61, 77, UINT64_C(110), &assert_frame); UT_ASSERT_EQ(action, RESOURCE_X_BOOTSTRAP_ROUND_DISPATCH_ASSERT); expected_ref = make_resource_x_acquisition_ref(tag, 1, 17, 1); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_t1_grant_exact(&expected_ref), - RESOURCE_X_APPLY_APPLIED); + RESOURCE_X_APPLY_APPLIED); memset(&install, 0, sizeof(install)); install.ownership_generation = 91; install.writer_activation_token = 12; install.resource_x_activation_generation = 1; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_apply_exact( - &expected_ref, &install), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_apply_exact(&expected_ref, &install), + RESOURCE_X_APPLY_APPLIED); memset(&activation, 0, sizeof(activation)); activation.ownership_generation = 91; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_activate_exact( - &expected_ref, &activation), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_activate_exact(&expected_ref, &activation), + RESOURCE_X_APPLY_APPLIED); /* A remote X->N+PI then N->X handoff consumes two authority edges. */ - UT_ASSERT_EQ( - cluster_pcm_lock_resource_x_bootstrap_round_publish_terminal_exact( - &expected_ref, 31, 77, 91, 11, UINT64_C(120)), - RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_bootstrap_round_publish_terminal_exact( + &expected_ref, 31, 77, 91, 11, UINT64_C(120)), + RESOURCE_X_APPLY_APPLIED); - successor_block = make_resource_x_master_frame( - RESOURCE_X_WIRE_BLOCK_TO_N, tag, 2, 1); + successor_block = make_resource_x_master_frame(RESOURCE_X_WIRE_BLOCK_TO_N, tag, 2, 1); successor_block.payload_bytes = RESOURCE_X_CONTROL_V1_BYTES; successor_block.common.base_authority_generation = UINT64_C(11); successor_block.common.authority_generation = UINT64_C(11); @@ -9318,8 +8841,8 @@ UT_TEST(test_resource_x_terminal_remote_holder_binds_exact_final_authority) successor_block.common.source_candidate = 1; successor_block.common.retain_pi_if_dirty = 1; memset(&lineage, 0, sizeof(lineage)); - UT_ASSERT(cluster_pcm_lock_resource_x_bootstrap_round_terminal_holder_exact( - &successor_block, 0, 77, 91, &lineage)); + UT_ASSERT(cluster_pcm_lock_resource_x_bootstrap_round_terminal_holder_exact(&successor_block, 0, + 77, 91, &lineage)); UT_ASSERT_EQ(lineage.accepted_base_authority_generation, UINT64_C(9)); UT_ASSERT_EQ(lineage.final_authority_generation, UINT64_C(11)); UT_ASSERT_EQ(lineage.direct_init_ownership_generation, UINT64_C(0)); @@ -9348,9 +8871,8 @@ UT_TEST(test_resource_x_terminal_remote_holder_binds_exact_final_authority) memset(&revoke, 0, sizeof(revoke)); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_terminal_x_revoke_claim_exact( - &successor_block, 0, 77, 91, 19, 9, UINT64_C(130), - &lineage, &revoke), - RESOURCE_X_APPLY_APPLIED); + &successor_block, 0, 77, 91, 19, 9, UINT64_C(130), &lineage, &revoke), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT(cluster_pcm_lock_resource_x_terminal_x_revoke_revalidate_held_exact( &successor_block, 0, 77, 91, &revoke, &lineage)); successor_block.common.authority_generation++; @@ -9368,7 +8890,7 @@ UT_TEST(test_resource_x_terminal_remote_holder_binds_exact_final_authority) UT_ASSERT(cluster_pcm_lock_resource_x_terminal_x_revoke_revalidate_held_exact( &successor_block, 0, 77, 91, &revoke, &lineage)); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_terminal_x_revoke_release_exact(&revoke), - RESOURCE_X_APPLY_APPLIED); + RESOURCE_X_APPLY_APPLIED); successor_block.common.base_authority_generation = UINT64_C(10); successor_block.common.authority_generation = UINT64_C(10); @@ -9406,11 +8928,10 @@ UT_TEST(test_resource_x_terminal_remote_holder_binds_exact_final_authority) } static ResourceXDecodedFrame -make_resource_x_remote_blocked_frame(BufferTag tag, int32 requester_node, - int32 source_node) +make_resource_x_remote_blocked_frame(BufferTag tag, int32 requester_node, int32 source_node) { - ResourceXDecodedFrame blocked = make_resource_x_master_frame( - RESOURCE_X_WIRE_BLOCKED_TO_N, tag, requester_node, source_node); + ResourceXDecodedFrame blocked = make_resource_x_master_frame(RESOURCE_X_WIRE_BLOCKED_TO_N, tag, + requester_node, source_node); blocked.common.observed_mode = PCM_STATE_X; blocked.common.target_mode = PCM_STATE_N; @@ -9419,8 +8940,8 @@ make_resource_x_remote_blocked_frame(BufferTag tag, int32 requester_node, blocked.blocked_has_remote_proof = true; memset(blocked.body.blocked_to_n.source_fence, 0x5a, sizeof(blocked.body.blocked_to_n.source_fence)); - set_resource_x_test_source_fence( - blocked.body.blocked_to_n.source_fence, UINT64_C(60), PCM_STATE_X); + set_resource_x_test_source_fence(blocked.body.blocked_to_n.source_fence, UINT64_C(60), + PCM_STATE_X); blocked.body.blocked_to_n.source_carrier_generation = 61; blocked.body.blocked_to_n.requester_target_generation = 41; blocked.body.blocked_to_n.page_scn_lsn = 63; @@ -9429,12 +8950,10 @@ make_resource_x_remote_blocked_frame(BufferTag tag, int32 requester_node, blocked.body.blocked_to_n.dependencies[1] = 66; blocked.body.blocked_to_n.source_proof_crc32c = UINT32_C(0x11223344); blocked.body.blocked_to_n.page_checksum = UINT32_C(0x55667788); - blocked.body.blocked_to_n.source_disposition - = RESOURCE_X_DISPOSITION_REMOTE_NONWRITABLE; + blocked.body.blocked_to_n.source_disposition = RESOURCE_X_DISPOSITION_REMOTE_NONWRITABLE; blocked.body.blocked_to_n.proof_kind = RESOURCE_X_PROOF_REMOTE_CARRIER; blocked.body.blocked_to_n.holder_connection_generation = 64; - blocked.body.blocked_to_n.acting_formation - = blocked.common.resource_formation; + blocked.body.blocked_to_n.acting_formation = blocked.common.resource_formation; return blocked; } @@ -9449,40 +8968,39 @@ UT_TEST(test_resource_x_adapter_adopts_only_exact_pristine_legacy_base) cluster_node_id = 0; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), RESOURCE_X_APPLY_APPLIED); - UT_ASSERT_EQ(cluster_pcm_lock_apply_gcs_transition_result( - tag, PCM_TRANS_N_TO_X, 0), PCM_GCS_TRANSITION_APPLIED); - UT_ASSERT_EQ(cluster_pcm_lock_apply_gcs_transition_result( - tag, PCM_TRANS_X_TO_N_RELEASE, 0), PCM_GCS_TRANSITION_APPLIED); - UT_ASSERT_EQ(cluster_pcm_lock_apply_gcs_transition_result( - tag, PCM_TRANS_N_TO_S, 0), PCM_GCS_TRANSITION_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_apply_gcs_transition_result(tag, PCM_TRANS_N_TO_X, 0), + PCM_GCS_TRANSITION_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_apply_gcs_transition_result(tag, PCM_TRANS_X_TO_N_RELEASE, 0), + PCM_GCS_TRANSITION_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_apply_gcs_transition_result(tag, PCM_TRANS_N_TO_S, 0), + PCM_GCS_TRANSITION_APPLIED); UT_ASSERT(cluster_pcm_lock_authority_snapshot(tag, &authority)); UT_ASSERT_EQ(authority.transition_count, UINT64_C(3)); UT_ASSERT_EQ(authority.state, PCM_STATE_S); - assertion = make_resource_x_master_frame( - RESOURCE_X_WIRE_ASSERT_X, tag, 0, 0); + assertion = make_resource_x_master_frame(RESOURCE_X_WIRE_ASSERT_X, tag, 0, 0); assertion.common.base_authority_generation = 3; assertion.common.authority_generation = 3; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact( - &assertion, 0, &snapshot), RESOURCE_X_APPLY_STALE); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact(&assertion, 0, &snapshot), + RESOURCE_X_APPLY_STALE); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_adapter_base_bind_exact( - &assertion.common.logical_assertion, 17, 3, &authority), - RESOURCE_X_APPLY_APPLIED); + &assertion.common.logical_assertion, 17, 3, &authority), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_adapter_base_bind_exact( - &assertion.common.logical_assertion, 17, 3, &authority), - RESOURCE_X_APPLY_DUPLICATE); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact( - &assertion, 0, &snapshot), RESOURCE_X_APPLY_APPLIED); + &assertion.common.logical_assertion, 17, 3, &authority), + RESOURCE_X_APPLY_DUPLICATE); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact(&assertion, 0, &snapshot), + RESOURCE_X_APPLY_APPLIED); /* Once any Resource-X request exists, even a later exact legacy * transition count cannot reseed canonical authority. */ - UT_ASSERT_EQ(cluster_pcm_lock_apply_gcs_transition_result( - tag, PCM_TRANS_S_TO_N_RELEASE, 0), PCM_GCS_TRANSITION_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_apply_gcs_transition_result(tag, PCM_TRANS_S_TO_N_RELEASE, 0), + PCM_GCS_TRANSITION_APPLIED); UT_ASSERT(cluster_pcm_lock_authority_snapshot(tag, &authority)); UT_ASSERT_EQ(authority.transition_count, UINT64_C(4)); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_adapter_base_bind_exact( - &assertion.common.logical_assertion, 17, 4, &authority), - RESOURCE_X_APPLY_STALE); + &assertion.common.logical_assertion, 17, 4, &authority), + RESOURCE_X_APPLY_STALE); } UT_TEST(test_resource_x_adapter_head_rebinds_only_before_assert) @@ -9502,53 +9020,52 @@ UT_TEST(test_resource_x_adapter_head_rebinds_only_before_assert) cluster_node_id = 0; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), RESOURCE_X_APPLY_APPLIED); - UT_ASSERT_EQ(cluster_pcm_lock_apply_gcs_transition_result( - tag, PCM_TRANS_N_TO_X, 0), PCM_GCS_TRANSITION_APPLIED); - UT_ASSERT_EQ(cluster_pcm_lock_apply_gcs_transition_result( - tag, PCM_TRANS_X_TO_N_RELEASE, 0), PCM_GCS_TRANSITION_APPLIED); - UT_ASSERT_EQ(cluster_pcm_lock_apply_gcs_transition_result( - tag, PCM_TRANS_N_TO_S, 0), PCM_GCS_TRANSITION_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_apply_gcs_transition_result(tag, PCM_TRANS_N_TO_X, 0), + PCM_GCS_TRANSITION_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_apply_gcs_transition_result(tag, PCM_TRANS_X_TO_N_RELEASE, 0), + PCM_GCS_TRANSITION_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_apply_gcs_transition_result(tag, PCM_TRANS_N_TO_S, 0), + PCM_GCS_TRANSITION_APPLIED); UT_ASSERT(cluster_pcm_lock_authority_snapshot(tag, &authority)); UT_ASSERT_EQ(authority.transition_count, UINT64_C(3)); - assertion = make_resource_x_master_frame( - RESOURCE_X_WIRE_ASSERT_X, tag, 0, 0); + assertion = make_resource_x_master_frame(RESOURCE_X_WIRE_ASSERT_X, tag, 0, 0); assertion.common.base_authority_generation = 3; assertion.common.authority_generation = 3; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_adapter_base_bind_exact( - &assertion.common.logical_assertion, 17, 3, &authority), - RESOURCE_X_APPLY_APPLIED); + &assertion.common.logical_assertion, 17, 3, &authority), + RESOURCE_X_APPLY_APPLIED); /* A real predecessor authority transition may make an admitted FIFO * successor's base stale before that successor sends ASSERT_X. Only the * head-only adapter entry point may update an otherwise pristine semantic * state, and exact replay is a duplicate. */ - UT_ASSERT_EQ(cluster_pcm_lock_apply_gcs_transition_result( - tag, PCM_TRANS_S_TO_N_RELEASE, 0), PCM_GCS_TRANSITION_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_apply_gcs_transition_result(tag, PCM_TRANS_S_TO_N_RELEASE, 0), + PCM_GCS_TRANSITION_APPLIED); UT_ASSERT(cluster_pcm_lock_authority_snapshot(tag, &authority)); UT_ASSERT_EQ(authority.transition_count, UINT64_C(4)); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_adapter_base_bind_exact( - &assertion.common.logical_assertion, 17, 4, &authority), - RESOURCE_X_APPLY_STALE); + &assertion.common.logical_assertion, 17, 4, &authority), + RESOURCE_X_APPLY_STALE); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_adapter_head_rebind_exact( - &assertion.common.logical_assertion, 41, 73, 17, 4, &authority), - RESOURCE_X_APPLY_APPLIED); + &assertion.common.logical_assertion, 41, 73, 17, 4, &authority), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_adapter_head_rebind_exact( - &assertion.common.logical_assertion, 41, 73, 17, 4, &authority), - RESOURCE_X_APPLY_DUPLICATE); + &assertion.common.logical_assertion, 41, 73, 17, 4, &authority), + RESOURCE_X_APPLY_DUPLICATE); assertion.common.base_authority_generation = 4; assertion.common.authority_generation = 4; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact( - &assertion, 0, &snapshot), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact(&assertion, 0, &snapshot), + RESOURCE_X_APPLY_APPLIED); /* ASSERT is the atomic native S-admission barrier: an unrelated legacy * N->S apply cannot manufacture a later base behind the canonical head. */ - UT_ASSERT_EQ(cluster_pcm_lock_apply_gcs_transition_result( - tag, PCM_TRANS_N_TO_S, 0), PCM_GCS_TRANSITION_PENDING_X); + UT_ASSERT_EQ(cluster_pcm_lock_apply_gcs_transition_result(tag, PCM_TRANS_N_TO_S, 0), + PCM_GCS_TRANSITION_PENDING_X); UT_ASSERT(cluster_pcm_lock_authority_snapshot(tag, &authority)); UT_ASSERT_EQ(authority.transition_count, UINT64_C(4)); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_adapter_head_rebind_exact( - &assertion.common.logical_assertion, 41, 73, 17, 4, &authority), - RESOURCE_X_APPLY_STALE); + &assertion.common.logical_assertion, 41, 73, 17, 4, &authority), + RESOURCE_X_APPLY_STALE); /* A prior request's SETTLED record is terminal history, not evidence that * the promoted successor already sent ASSERT_X. Preserve that history, @@ -9558,10 +9075,9 @@ UT_TEST(test_resource_x_adapter_head_rebinds_only_before_assert) cluster_node_id = 0; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), RESOURCE_X_APPLY_APPLIED); - predecessor = make_resource_x_master_frame( - RESOURCE_X_WIRE_ASSERT_X, tag, 3, 3); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact( - &predecessor, 3, &snapshot), RESOURCE_X_APPLY_APPLIED); + predecessor = make_resource_x_master_frame(RESOURCE_X_WIRE_ASSERT_X, tag, 3, 3); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact(&predecessor, 3, &snapshot), + RESOURCE_X_APPLY_APPLIED); memset(&durable, 0, sizeof(durable)); durable.assertion = predecessor.common.logical_assertion; durable.base_authority_generation = 1; @@ -9572,17 +9088,16 @@ UT_TEST(test_resource_x_adapter_head_rebinds_only_before_assert) durable.page_scn_lsn = 82; durable.page_checksum = UINT32_C(0x12345678); durable.source_proof_crc32c = UINT32_C(0x87654321); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_durable_proof_exact( - &durable, &snapshot), RESOURCE_X_APPLY_APPLIED); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_grant_intent_snapshot_exact( - &predecessor.common.logical_assertion, &grant_intent, grant_bytes, - sizeof(grant_bytes)), RESOURCE_X_APPLY_APPLIED); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_grant_intent_stage_exact( - &grant_intent, 101), RESOURCE_X_INTENT_STAGED); - UT_ASSERT(cluster_pcm_lock_resource_x_grant_intent_complete_exact( - &grant_intent)); - settlement = make_resource_x_master_frame( - RESOURCE_X_WIRE_INSTALL_SETTLEMENT, tag, 3, 3); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_durable_proof_exact(&durable, &snapshot), + RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ( + cluster_pcm_lock_resource_x_grant_intent_snapshot_exact( + &predecessor.common.logical_assertion, &grant_intent, grant_bytes, sizeof(grant_bytes)), + RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_grant_intent_stage_exact(&grant_intent, 101), + RESOURCE_X_INTENT_STAGED); + UT_ASSERT(cluster_pcm_lock_resource_x_grant_intent_complete_exact(&grant_intent)); + settlement = make_resource_x_master_frame(RESOURCE_X_WIRE_INSTALL_SETTLEMENT, tag, 3, 3); settlement.common.outcome = RESOURCE_X_OUTCOME_OK; settlement.common.authority_generation = 2; settlement.body.install_settlement.conversion_base_generation = 1; @@ -9591,53 +9106,48 @@ UT_TEST(test_resource_x_adapter_head_rebinds_only_before_assert) settlement.body.install_settlement.requester_target_generation = 41; settlement.body.install_settlement.page_scn_lsn = 82; settlement.body.install_settlement.page_checksum = UINT32_C(0x12345678); - settlement.body.install_settlement.source_proof_crc32c - = UINT32_C(0x87654321); + settlement.body.install_settlement.source_proof_crc32c = UINT32_C(0x87654321); settlement.body.install_settlement.installed_mode = PCM_STATE_X; - settlement.body.install_settlement.requester_role - = RESOURCE_X_REQUESTER_ROLE_ACQUIRER; + settlement.body.install_settlement.requester_role = RESOURCE_X_REQUESTER_ROLE_ACQUIRER; settlement.body.install_settlement.terminal_outcome = RESOURCE_X_OUTCOME_OK; - settlement.body.install_settlement.terminal_state - = RESOURCE_X_SETTLEMENT_TERMINAL_INSTALLED; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_install_settlement_exact( - &settlement, 3, &snapshot), RESOURCE_X_APPLY_APPLIED); + settlement.body.install_settlement.terminal_state = RESOURCE_X_SETTLEMENT_TERMINAL_INSTALLED; + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_install_settlement_exact(&settlement, 3, &snapshot), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(snapshot.phase, RESOURCE_X_MASTER_SETTLED); - UT_ASSERT_EQ(cluster_pcm_lock_apply_gcs_transition_result( - tag, PCM_TRANS_X_TO_N_RELEASE, 3), PCM_GCS_TRANSITION_APPLIED); - UT_ASSERT_EQ(cluster_pcm_lock_apply_gcs_transition_result( - tag, PCM_TRANS_N_TO_X, 3), PCM_GCS_TRANSITION_APPLIED); - UT_ASSERT_EQ(cluster_pcm_lock_try_reserve_pending_x(tag, 0, 78), - PCM_PENDING_X_RESERVE_OK); + UT_ASSERT_EQ(cluster_pcm_lock_apply_gcs_transition_result(tag, PCM_TRANS_X_TO_N_RELEASE, 3), + PCM_GCS_TRANSITION_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_apply_gcs_transition_result(tag, PCM_TRANS_N_TO_X, 3), + PCM_GCS_TRANSITION_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_try_reserve_pending_x(tag, 0, 78), PCM_PENDING_X_RESERVE_OK); UT_ASSERT(cluster_pcm_lock_authority_snapshot(tag, &authority)); UT_ASSERT_EQ(authority.transition_count, UINT64_C(3)); - successor = make_resource_x_master_frame( - RESOURCE_X_WIRE_ASSERT_X, tag, 0, 0); + successor = make_resource_x_master_frame(RESOURCE_X_WIRE_ASSERT_X, tag, 0, 0); successor.common.base_authority_generation = 3; successor.common.authority_generation = 3; successor.common.assertion_sequence = 42; /* A claimed pending-X barrier may coexist with the one pre-ASSERT * late-bind only when its queue cookie names this exact ticket. */ UT_ASSERT_EQ(cluster_pcm_lock_resource_x_adapter_head_rebind_exact( - &successor.common.logical_assertion, 42, 79, 17, 3, &authority), - RESOURCE_X_APPLY_INVALID); + &successor.common.logical_assertion, 42, 79, 17, 3, &authority), + RESOURCE_X_APPLY_INVALID); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_adapter_head_rebind_exact( - &successor.common.logical_assertion, 42, 78, 17, 3, &authority), - RESOURCE_X_APPLY_APPLIED); + &successor.common.logical_assertion, 42, 78, 17, 3, &authority), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_adapter_head_rebind_exact( - &successor.common.logical_assertion, 42, 78, 17, 3, &authority), - RESOURCE_X_APPLY_DUPLICATE); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact( - &successor, 0, &snapshot), RESOURCE_X_APPLY_APPLIED); + &successor.common.logical_assertion, 42, 78, 17, 3, &authority), + RESOURCE_X_APPLY_DUPLICATE); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact(&successor, 0, &snapshot), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_adapter_head_rebind_exact( - &successor.common.logical_assertion, 42, 78, 17, 3, &authority), - RESOURCE_X_APPLY_STALE); + &successor.common.logical_assertion, 42, 78, 17, 3, &authority), + RESOURCE_X_APPLY_STALE); UT_ASSERT(cluster_pcm_lock_clear_queue_pending_x_exact(tag, 0, 78)); - UT_ASSERT_EQ(cluster_pcm_lock_apply_gcs_transition_result( - tag, PCM_TRANS_X_TO_N_RELEASE, 3), PCM_GCS_TRANSITION_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_apply_gcs_transition_result(tag, PCM_TRANS_X_TO_N_RELEASE, 3), + PCM_GCS_TRANSITION_APPLIED); UT_ASSERT(cluster_pcm_lock_authority_snapshot(tag, &authority)); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_adapter_head_rebind_exact( - &successor.common.logical_assertion, 42, 78, 17, 4, &authority), - RESOURCE_X_APPLY_STALE); + &successor.common.logical_assertion, 42, 78, 17, 4, &authority), + RESOURCE_X_APPLY_STALE); } UT_TEST(test_resource_x_settled_retirement_tombstone_replays_and_frees_live_slot) @@ -9653,22 +9163,21 @@ UT_TEST(test_resource_x_settled_retirement_tombstone_replays_and_frees_live_slot reset_fake_pcm_runtime(4); cluster_node_id = 0; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), - RESOURCE_X_APPLY_APPLIED); - UT_ASSERT_EQ(cluster_pcm_lock_apply_gcs_transition_result( - tag, PCM_TRANS_N_TO_X, 0), PCM_GCS_TRANSITION_APPLIED); - UT_ASSERT_EQ(cluster_pcm_lock_apply_gcs_transition_result( - tag, PCM_TRANS_X_TO_N_RELEASE, 0), PCM_GCS_TRANSITION_APPLIED); + RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_apply_gcs_transition_result(tag, PCM_TRANS_N_TO_X, 0), + PCM_GCS_TRANSITION_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_apply_gcs_transition_result(tag, PCM_TRANS_X_TO_N_RELEASE, 0), + PCM_GCS_TRANSITION_APPLIED); UT_ASSERT(cluster_pcm_lock_authority_snapshot(tag, &authority)); UT_ASSERT_EQ(authority.transition_count, UINT64_C(2)); - first_assert = make_resource_x_master_frame( - RESOURCE_X_WIRE_ASSERT_X, tag, 3, 3); + first_assert = make_resource_x_master_frame(RESOURCE_X_WIRE_ASSERT_X, tag, 3, 3); first_assert.common.base_authority_generation = 2; first_assert.common.authority_generation = 2; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_adapter_base_bind_exact( - &first_assert.common.logical_assertion, 17, 2, &authority), - RESOURCE_X_APPLY_APPLIED); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact( - &first_assert, 3, &snapshot), RESOURCE_X_APPLY_APPLIED); + &first_assert.common.logical_assertion, 17, 2, &authority), + RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact(&first_assert, 3, &snapshot), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(snapshot.phase, RESOURCE_X_MASTER_WAIT_PROOF); memset(&durable, 0, sizeof(durable)); @@ -9681,13 +9190,12 @@ UT_TEST(test_resource_x_settled_retirement_tombstone_replays_and_frees_live_slot durable.page_scn_lsn = 82; durable.page_checksum = UINT32_C(0x12345678); durable.source_proof_crc32c = UINT32_C(0x87654321); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_durable_proof_exact( - &durable, &snapshot), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_durable_proof_exact(&durable, &snapshot), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(snapshot.phase, RESOURCE_X_MASTER_GRANT_COMMITTED); UT_ASSERT_EQ(snapshot.final_authority_generation, UINT64_C(3)); - settlement = make_resource_x_master_frame( - RESOURCE_X_WIRE_INSTALL_SETTLEMENT, tag, 3, 3); + settlement = make_resource_x_master_frame(RESOURCE_X_WIRE_INSTALL_SETTLEMENT, tag, 3, 3); settlement.common.outcome = RESOURCE_X_OUTCOME_OK; settlement.common.base_authority_generation = 2; settlement.common.authority_generation = 3; @@ -9696,61 +9204,54 @@ UT_TEST(test_resource_x_settled_retirement_tombstone_replays_and_frees_live_slot settlement.body.install_settlement.requester_connection_generation = 91; settlement.body.install_settlement.requester_target_generation = 41; settlement.body.install_settlement.page_scn_lsn = 82; - settlement.body.install_settlement.page_checksum - = UINT32_C(0x12345678); - settlement.body.install_settlement.source_proof_crc32c - = UINT32_C(0x87654321); + settlement.body.install_settlement.page_checksum = UINT32_C(0x12345678); + settlement.body.install_settlement.source_proof_crc32c = UINT32_C(0x87654321); settlement.body.install_settlement.installed_mode = PCM_STATE_X; - settlement.body.install_settlement.requester_role - = RESOURCE_X_REQUESTER_ROLE_ACQUIRER; - settlement.body.install_settlement.terminal_outcome - = RESOURCE_X_OUTCOME_OK; - settlement.body.install_settlement.terminal_state - = RESOURCE_X_SETTLEMENT_TERMINAL_INSTALLED; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_install_settlement_exact( - &settlement, 3, &snapshot), RESOURCE_X_APPLY_APPLIED); + settlement.body.install_settlement.requester_role = RESOURCE_X_REQUESTER_ROLE_ACQUIRER; + settlement.body.install_settlement.terminal_outcome = RESOURCE_X_OUTCOME_OK; + settlement.body.install_settlement.terminal_state = RESOURCE_X_SETTLEMENT_TERMINAL_INSTALLED; + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_install_settlement_exact(&settlement, 3, &snapshot), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(snapshot.phase, RESOURCE_X_MASTER_SETTLED); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_settled_retire_exact( - &first_assert.common.logical_assertion, 41, &snapshot), - RESOURCE_X_APPLY_APPLIED); + &first_assert.common.logical_assertion, 41, &snapshot), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_settled_retire_exact( - &first_assert.common.logical_assertion, 41, &snapshot), - RESOURCE_X_APPLY_DUPLICATE); + &first_assert.common.logical_assertion, 41, &snapshot), + RESOURCE_X_APPLY_DUPLICATE); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_master_snapshot_exact( - &first_assert.common.logical_assertion, &snapshot), - RESOURCE_X_APPLY_APPLIED); + &first_assert.common.logical_assertion, &snapshot), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(snapshot.phase, RESOURCE_X_MASTER_SETTLED); UT_ASSERT_EQ(snapshot.assertion_sequence, UINT64_C(41)); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_install_settlement_exact( - &settlement, 3, &snapshot), RESOURCE_X_APPLY_DUPLICATE); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_install_settlement_exact(&settlement, 3, &snapshot), + RESOURCE_X_APPLY_DUPLICATE); UT_ASSERT_EQ(snapshot.phase, RESOURCE_X_MASTER_SETTLED); /* The live conversion slot is no longer the granted-holder authority. */ - next_assert = make_resource_x_master_frame( - RESOURCE_X_WIRE_ASSERT_X, tag, 3, 3); + next_assert = make_resource_x_master_frame(RESOURCE_X_WIRE_ASSERT_X, tag, 3, 3); next_assert.common.assertion_sequence = 42; /* The old physical X may independently become one of multiple current S * holders. A fresh assertion must recompute blockers from GRD rather than * reusing the terminal conversion's sole-S shape. */ - UT_ASSERT_EQ(cluster_pcm_lock_apply_gcs_transition_result( - tag, PCM_TRANS_X_TO_S_DOWNGRADE, 3), PCM_GCS_TRANSITION_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_apply_gcs_transition_result(tag, PCM_TRANS_X_TO_S_DOWNGRADE, 3), + PCM_GCS_TRANSITION_APPLIED); cluster_node_id = 1; cluster_pcm_lock_acquire(tag, PCM_LOCK_MODE_S); cluster_node_id = 0; UT_ASSERT(cluster_pcm_lock_authority_snapshot(tag, &authority)); UT_ASSERT_EQ(authority.state, PCM_STATE_S); UT_ASSERT_EQ(authority.x_holder_node, -1); - UT_ASSERT_EQ(authority.s_holders_bitmap, - (UINT32_C(1) << 1) | (UINT32_C(1) << 3)); + UT_ASSERT_EQ(authority.s_holders_bitmap, (UINT32_C(1) << 1) | (UINT32_C(1) << 3)); UT_ASSERT_EQ(authority.transition_count, UINT64_C(4)); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_adapter_head_rebind_exact( - &next_assert.common.logical_assertion, 42, 73, 17, 4, &authority), - RESOURCE_X_APPLY_APPLIED); + &next_assert.common.logical_assertion, 42, 73, 17, 4, &authority), + RESOURCE_X_APPLY_APPLIED); next_assert.common.base_authority_generation = 4; next_assert.common.authority_generation = 4; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact( - &next_assert, 3, &snapshot), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact(&next_assert, 3, &snapshot), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(snapshot.phase, RESOURCE_X_MASTER_WAIT_BLOCKERS); UT_ASSERT_EQ(snapshot.incompatible_holders_bitmap, UINT32_C(1) << 1); UT_ASSERT_EQ(snapshot.base_authority_generation, UINT64_C(4)); @@ -9758,16 +9259,16 @@ UT_TEST(test_resource_x_settled_retirement_tombstone_replays_and_frees_live_slot /* Exact late terminal frames remain idempotent even after a fresh live * request from the same requester occupies the slot. */ - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact( - &first_assert, 3, &snapshot), RESOURCE_X_APPLY_DUPLICATE); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact(&first_assert, 3, &snapshot), + RESOURCE_X_APPLY_DUPLICATE); UT_ASSERT_EQ(snapshot.phase, RESOURCE_X_MASTER_SETTLED); UT_ASSERT_EQ(snapshot.assertion_sequence, UINT64_C(41)); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_install_settlement_exact( - &settlement, 3, &snapshot), RESOURCE_X_APPLY_DUPLICATE); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_install_settlement_exact(&settlement, 3, &snapshot), + RESOURCE_X_APPLY_DUPLICATE); UT_ASSERT_EQ(snapshot.phase, RESOURCE_X_MASTER_SETTLED); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_master_snapshot_exact( - &next_assert.common.logical_assertion, &snapshot), - RESOURCE_X_APPLY_APPLIED); + &next_assert.common.logical_assertion, &snapshot), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(snapshot.phase, RESOURCE_X_MASTER_WAIT_BLOCKERS); UT_ASSERT_EQ(snapshot.assertion_sequence, UINT64_C(42)); } @@ -9785,22 +9286,21 @@ UT_TEST(test_resource_x_tombstone_lineage_drift_remains_terminal) reset_fake_pcm_runtime(4); cluster_node_id = 0; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), - RESOURCE_X_APPLY_APPLIED); - UT_ASSERT_EQ(cluster_pcm_lock_apply_gcs_transition_result( - tag, PCM_TRANS_N_TO_X, 0), PCM_GCS_TRANSITION_APPLIED); - UT_ASSERT_EQ(cluster_pcm_lock_apply_gcs_transition_result( - tag, PCM_TRANS_X_TO_N_RELEASE, 0), PCM_GCS_TRANSITION_APPLIED); + RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_apply_gcs_transition_result(tag, PCM_TRANS_N_TO_X, 0), + PCM_GCS_TRANSITION_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_apply_gcs_transition_result(tag, PCM_TRANS_X_TO_N_RELEASE, 0), + PCM_GCS_TRANSITION_APPLIED); UT_ASSERT(cluster_pcm_lock_authority_snapshot(tag, &authority)); - assertion = make_resource_x_master_frame( - RESOURCE_X_WIRE_ASSERT_X, tag, 3, 3); + assertion = make_resource_x_master_frame(RESOURCE_X_WIRE_ASSERT_X, tag, 3, 3); assertion.common.base_authority_generation = 2; assertion.common.authority_generation = 2; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_adapter_base_bind_exact( - &assertion.common.logical_assertion, 17, 2, &authority), - RESOURCE_X_APPLY_APPLIED); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact( - &assertion, 3, &snapshot), RESOURCE_X_APPLY_APPLIED); + &assertion.common.logical_assertion, 17, 2, &authority), + RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact(&assertion, 3, &snapshot), + RESOURCE_X_APPLY_APPLIED); memset(&durable, 0, sizeof(durable)); durable.assertion = assertion.common.logical_assertion; @@ -9812,11 +9312,10 @@ UT_TEST(test_resource_x_tombstone_lineage_drift_remains_terminal) durable.page_scn_lsn = 82; durable.page_checksum = UINT32_C(0x12345678); durable.source_proof_crc32c = UINT32_C(0x87654321); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_durable_proof_exact( - &durable, &snapshot), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_durable_proof_exact(&durable, &snapshot), + RESOURCE_X_APPLY_APPLIED); - settlement = make_resource_x_master_frame( - RESOURCE_X_WIRE_INSTALL_SETTLEMENT, tag, 3, 3); + settlement = make_resource_x_master_frame(RESOURCE_X_WIRE_INSTALL_SETTLEMENT, tag, 3, 3); settlement.common.outcome = RESOURCE_X_OUTCOME_OK; settlement.common.base_authority_generation = 2; settlement.common.authority_generation = 3; @@ -9825,44 +9324,38 @@ UT_TEST(test_resource_x_tombstone_lineage_drift_remains_terminal) settlement.body.install_settlement.requester_connection_generation = 91; settlement.body.install_settlement.requester_target_generation = 41; settlement.body.install_settlement.page_scn_lsn = 82; - settlement.body.install_settlement.page_checksum - = UINT32_C(0x12345678); - settlement.body.install_settlement.source_proof_crc32c - = UINT32_C(0x87654321); + settlement.body.install_settlement.page_checksum = UINT32_C(0x12345678); + settlement.body.install_settlement.source_proof_crc32c = UINT32_C(0x87654321); settlement.body.install_settlement.installed_mode = PCM_STATE_X; - settlement.body.install_settlement.requester_role - = RESOURCE_X_REQUESTER_ROLE_ACQUIRER; - settlement.body.install_settlement.terminal_outcome - = RESOURCE_X_OUTCOME_OK; - settlement.body.install_settlement.terminal_state - = RESOURCE_X_SETTLEMENT_TERMINAL_INSTALLED; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_install_settlement_exact( - &settlement, 3, &snapshot), RESOURCE_X_APPLY_APPLIED); + settlement.body.install_settlement.requester_role = RESOURCE_X_REQUESTER_ROLE_ACQUIRER; + settlement.body.install_settlement.terminal_outcome = RESOURCE_X_OUTCOME_OK; + settlement.body.install_settlement.terminal_state = RESOURCE_X_SETTLEMENT_TERMINAL_INSTALLED; + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_install_settlement_exact(&settlement, 3, &snapshot), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_settled_retire_exact( - &assertion.common.logical_assertion, 41, &snapshot), - RESOURCE_X_APPLY_APPLIED); + &assertion.common.logical_assertion, 41, &snapshot), + RESOURCE_X_APPLY_APPLIED); /* The same physical holder may have crossed a later legacy episode before * its delayed kind-4 arrives. The old tombstone is retained evidence, not * mutable recovery state. */ - UT_ASSERT_EQ(cluster_pcm_lock_apply_gcs_transition_result( - tag, PCM_TRANS_X_TO_N_RELEASE, 3), PCM_GCS_TRANSITION_APPLIED); - UT_ASSERT_EQ(cluster_pcm_lock_apply_gcs_transition_result( - tag, PCM_TRANS_N_TO_X, 3), PCM_GCS_TRANSITION_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_apply_gcs_transition_result(tag, PCM_TRANS_X_TO_N_RELEASE, 3), + PCM_GCS_TRANSITION_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_apply_gcs_transition_result(tag, PCM_TRANS_N_TO_X, 3), + PCM_GCS_TRANSITION_APPLIED); - release = make_resource_x_master_frame( - RESOURCE_X_WIRE_RELEASE_X, tag, 3, 3); + release = make_resource_x_master_frame(RESOURCE_X_WIRE_RELEASE_X, tag, 3, 3); release.common.observed_mode = PCM_STATE_X; release.common.target_mode = PCM_STATE_N; release.common.outcome = RESOURCE_X_OUTCOME_OK; release.common.base_authority_generation = 2; release.common.authority_generation = 3; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_release_x_exact( - &release, 3, &snapshot), RESOURCE_X_APPLY_RECOVERY_BLOCKED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_release_x_exact(&release, 3, &snapshot), + RESOURCE_X_APPLY_RECOVERY_BLOCKED); UT_ASSERT_EQ(snapshot.phase, RESOURCE_X_MASTER_SETTLED); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_master_snapshot_exact( - &assertion.common.logical_assertion, &snapshot), - RESOURCE_X_APPLY_APPLIED); + &assertion.common.logical_assertion, &snapshot), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(snapshot.phase, RESOURCE_X_MASTER_SETTLED); } @@ -9881,23 +9374,22 @@ UT_TEST(test_pcm_protocol_debt_projection_rejects_settled_without_cached_or_pi) reset_fake_pcm_runtime(4); cluster_node_id = 0; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), - RESOURCE_X_APPLY_APPLIED); - UT_ASSERT_EQ(cluster_pcm_lock_apply_gcs_transition_result( - tag, PCM_TRANS_N_TO_X, 0), PCM_GCS_TRANSITION_APPLIED); - UT_ASSERT_EQ(cluster_pcm_lock_apply_gcs_transition_result( - tag, PCM_TRANS_X_TO_N_RELEASE, 0), PCM_GCS_TRANSITION_APPLIED); + RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_apply_gcs_transition_result(tag, PCM_TRANS_N_TO_X, 0), + PCM_GCS_TRANSITION_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_apply_gcs_transition_result(tag, PCM_TRANS_X_TO_N_RELEASE, 0), + PCM_GCS_TRANSITION_APPLIED); UT_ASSERT(cluster_pcm_lock_authority_snapshot(tag, &authority)); - assertion = make_resource_x_master_frame( - RESOURCE_X_WIRE_ASSERT_X, tag, 3, 3); + assertion = make_resource_x_master_frame(RESOURCE_X_WIRE_ASSERT_X, tag, 3, 3); assertion.common.base_authority_generation = authority.transition_count; assertion.common.authority_generation = authority.transition_count; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_adapter_base_bind_exact( - &assertion.common.logical_assertion, 17, - authority.transition_count, &authority), + UT_ASSERT_EQ( + cluster_pcm_lock_resource_x_adapter_base_bind_exact(&assertion.common.logical_assertion, 17, + authority.transition_count, &authority), RESOURCE_X_APPLY_APPLIED); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact( - &assertion, 3, &snapshot), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact(&assertion, 3, &snapshot), + RESOURCE_X_APPLY_APPLIED); memset(&durable, 0, sizeof(durable)); durable.assertion = assertion.common.logical_assertion; @@ -9909,23 +9401,20 @@ UT_TEST(test_pcm_protocol_debt_projection_rejects_settled_without_cached_or_pi) durable.page_scn_lsn = 82; durable.page_checksum = UINT32_C(0x12345678); durable.source_proof_crc32c = UINT32_C(0x87654321); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_durable_proof_exact( - &durable, &snapshot), RESOURCE_X_APPLY_APPLIED); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_grant_intent_snapshot_exact( - &assertion.common.logical_assertion, &grant_intent, grant_bytes, - sizeof(grant_bytes)), RESOURCE_X_APPLY_APPLIED); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_grant_intent_stage_exact( - &grant_intent, 101), RESOURCE_X_INTENT_STAGED); - UT_ASSERT(cluster_pcm_lock_resource_x_grant_intent_complete_exact( - &grant_intent)); - - settlement = make_resource_x_master_frame( - RESOURCE_X_WIRE_INSTALL_SETTLEMENT, tag, 3, 3); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_durable_proof_exact(&durable, &snapshot), + RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ( + cluster_pcm_lock_resource_x_grant_intent_snapshot_exact( + &assertion.common.logical_assertion, &grant_intent, grant_bytes, sizeof(grant_bytes)), + RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_grant_intent_stage_exact(&grant_intent, 101), + RESOURCE_X_INTENT_STAGED); + UT_ASSERT(cluster_pcm_lock_resource_x_grant_intent_complete_exact(&grant_intent)); + + settlement = make_resource_x_master_frame(RESOURCE_X_WIRE_INSTALL_SETTLEMENT, tag, 3, 3); settlement.common.outcome = RESOURCE_X_OUTCOME_OK; - settlement.common.base_authority_generation - = durable.base_authority_generation; - settlement.common.authority_generation - = snapshot.final_authority_generation; + settlement.common.base_authority_generation = durable.base_authority_generation; + settlement.common.authority_generation = snapshot.final_authority_generation; settlement.body.install_settlement.conversion_base_generation = durable.base_authority_generation; settlement.body.install_settlement.final_authority_generation @@ -9934,20 +9423,16 @@ UT_TEST(test_pcm_protocol_debt_projection_rejects_settled_without_cached_or_pi) settlement.body.install_settlement.requester_target_generation = 41; settlement.body.install_settlement.page_scn_lsn = durable.page_scn_lsn; settlement.body.install_settlement.page_checksum = durable.page_checksum; - settlement.body.install_settlement.source_proof_crc32c - = durable.source_proof_crc32c; + settlement.body.install_settlement.source_proof_crc32c = durable.source_proof_crc32c; settlement.body.install_settlement.installed_mode = PCM_STATE_X; - settlement.body.install_settlement.requester_role - = RESOURCE_X_REQUESTER_ROLE_ACQUIRER; - settlement.body.install_settlement.terminal_outcome - = RESOURCE_X_OUTCOME_OK; - settlement.body.install_settlement.terminal_state - = RESOURCE_X_SETTLEMENT_TERMINAL_INSTALLED; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_install_settlement_exact( - &settlement, 3, &snapshot), RESOURCE_X_APPLY_APPLIED); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_settled_retire_exact( - &assertion.common.logical_assertion, - assertion.common.assertion_sequence, &snapshot), + settlement.body.install_settlement.requester_role = RESOURCE_X_REQUESTER_ROLE_ACQUIRER; + settlement.body.install_settlement.terminal_outcome = RESOURCE_X_OUTCOME_OK; + settlement.body.install_settlement.terminal_state = RESOURCE_X_SETTLEMENT_TERMINAL_INSTALLED; + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_install_settlement_exact(&settlement, 3, &snapshot), + RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ( + cluster_pcm_lock_resource_x_settled_retire_exact( + &assertion.common.logical_assertion, assertion.common.assertion_sequence, &snapshot), RESOURCE_X_APPLY_APPLIED); cluster_pcm_grd_protocol_debt_snapshot(&debt); @@ -9960,8 +9445,8 @@ UT_TEST(test_pcm_protocol_debt_projection_rejects_settled_without_cached_or_pi) /* A raw physical X->N without RELEASE_X settlement leaves no cached * carrier and no durable PI for the SETTLED tombstone. The projection * must report this cross-axis terminal residue as invalid, not clean. */ - UT_ASSERT_EQ(cluster_pcm_lock_apply_gcs_transition_result( - tag, PCM_TRANS_X_TO_N_RELEASE, 3), PCM_GCS_TRANSITION_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_apply_gcs_transition_result(tag, PCM_TRANS_X_TO_N_RELEASE, 3), + PCM_GCS_TRANSITION_APPLIED); cluster_pcm_grd_protocol_debt_snapshot(&debt); UT_ASSERT_EQ(debt.retained_entry_count, UINT64_C(0)); UT_ASSERT_EQ(debt.active_resource_x_entry_count, UINT64_C(0)); @@ -9984,23 +9469,22 @@ UT_TEST(test_pcm_stop_durable_cut_replaces_exact_terminal_pi_cover) reset_fake_pcm_runtime(4); cluster_node_id = 0; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), - RESOURCE_X_APPLY_APPLIED); - UT_ASSERT_EQ(cluster_pcm_lock_apply_gcs_transition_result( - tag, PCM_TRANS_N_TO_X, 0), PCM_GCS_TRANSITION_APPLIED); - UT_ASSERT_EQ(cluster_pcm_lock_apply_gcs_transition_result( - tag, PCM_TRANS_X_TO_N_RELEASE, 0), PCM_GCS_TRANSITION_APPLIED); + RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_apply_gcs_transition_result(tag, PCM_TRANS_N_TO_X, 0), + PCM_GCS_TRANSITION_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_apply_gcs_transition_result(tag, PCM_TRANS_X_TO_N_RELEASE, 0), + PCM_GCS_TRANSITION_APPLIED); UT_ASSERT(cluster_pcm_lock_authority_snapshot(tag, &authority)); - assertion = make_resource_x_master_frame( - RESOURCE_X_WIRE_ASSERT_X, tag, 3, 3); + assertion = make_resource_x_master_frame(RESOURCE_X_WIRE_ASSERT_X, tag, 3, 3); assertion.common.base_authority_generation = authority.transition_count; assertion.common.authority_generation = authority.transition_count; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_adapter_base_bind_exact( - &assertion.common.logical_assertion, 17, - authority.transition_count, &authority), + UT_ASSERT_EQ( + cluster_pcm_lock_resource_x_adapter_base_bind_exact(&assertion.common.logical_assertion, 17, + authority.transition_count, &authority), RESOURCE_X_APPLY_APPLIED); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact( - &assertion, 3, &snapshot), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact(&assertion, 3, &snapshot), + RESOURCE_X_APPLY_APPLIED); memset(&durable, 0, sizeof(durable)); durable.assertion = assertion.common.logical_assertion; @@ -10012,23 +9496,20 @@ UT_TEST(test_pcm_stop_durable_cut_replaces_exact_terminal_pi_cover) durable.page_scn_lsn = 82; durable.page_checksum = UINT32_C(0x12345678); durable.source_proof_crc32c = UINT32_C(0x87654321); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_durable_proof_exact( - &durable, &snapshot), RESOURCE_X_APPLY_APPLIED); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_grant_intent_snapshot_exact( - &assertion.common.logical_assertion, &grant_intent, grant_bytes, - sizeof(grant_bytes)), RESOURCE_X_APPLY_APPLIED); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_grant_intent_stage_exact( - &grant_intent, 101), RESOURCE_X_INTENT_STAGED); - UT_ASSERT(cluster_pcm_lock_resource_x_grant_intent_complete_exact( - &grant_intent)); - - settlement = make_resource_x_master_frame( - RESOURCE_X_WIRE_INSTALL_SETTLEMENT, tag, 3, 3); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_durable_proof_exact(&durable, &snapshot), + RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ( + cluster_pcm_lock_resource_x_grant_intent_snapshot_exact( + &assertion.common.logical_assertion, &grant_intent, grant_bytes, sizeof(grant_bytes)), + RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_grant_intent_stage_exact(&grant_intent, 101), + RESOURCE_X_INTENT_STAGED); + UT_ASSERT(cluster_pcm_lock_resource_x_grant_intent_complete_exact(&grant_intent)); + + settlement = make_resource_x_master_frame(RESOURCE_X_WIRE_INSTALL_SETTLEMENT, tag, 3, 3); settlement.common.outcome = RESOURCE_X_OUTCOME_OK; - settlement.common.base_authority_generation - = durable.base_authority_generation; - settlement.common.authority_generation - = snapshot.final_authority_generation; + settlement.common.base_authority_generation = durable.base_authority_generation; + settlement.common.authority_generation = snapshot.final_authority_generation; settlement.body.install_settlement.conversion_base_generation = durable.base_authority_generation; settlement.body.install_settlement.final_authority_generation @@ -10037,20 +9518,16 @@ UT_TEST(test_pcm_stop_durable_cut_replaces_exact_terminal_pi_cover) settlement.body.install_settlement.requester_target_generation = 41; settlement.body.install_settlement.page_scn_lsn = durable.page_scn_lsn; settlement.body.install_settlement.page_checksum = durable.page_checksum; - settlement.body.install_settlement.source_proof_crc32c - = durable.source_proof_crc32c; + settlement.body.install_settlement.source_proof_crc32c = durable.source_proof_crc32c; settlement.body.install_settlement.installed_mode = PCM_STATE_X; - settlement.body.install_settlement.requester_role - = RESOURCE_X_REQUESTER_ROLE_ACQUIRER; - settlement.body.install_settlement.terminal_outcome - = RESOURCE_X_OUTCOME_OK; - settlement.body.install_settlement.terminal_state - = RESOURCE_X_SETTLEMENT_TERMINAL_INSTALLED; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_install_settlement_exact( - &settlement, 3, &snapshot), RESOURCE_X_APPLY_APPLIED); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_settled_retire_exact( - &assertion.common.logical_assertion, - assertion.common.assertion_sequence, &snapshot), + settlement.body.install_settlement.requester_role = RESOURCE_X_REQUESTER_ROLE_ACQUIRER; + settlement.body.install_settlement.terminal_outcome = RESOURCE_X_OUTCOME_OK; + settlement.body.install_settlement.terminal_state = RESOURCE_X_SETTLEMENT_TERMINAL_INSTALLED; + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_install_settlement_exact(&settlement, 3, &snapshot), + RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ( + cluster_pcm_lock_resource_x_settled_retire_exact( + &assertion.common.logical_assertion, assertion.common.assertion_sequence, &snapshot), RESOURCE_X_APPLY_APPLIED); cluster_pcm_grd_protocol_debt_snapshot(&debt); @@ -10061,8 +9538,8 @@ UT_TEST(test_pcm_stop_durable_cut_replaces_exact_terminal_pi_cover) UT_ASSERT_EQ(stop_pcm_poll(false, NULL, NULL, NULL), CLUSTER_NORMAL_STOP_READY); /* Actual common downgrade leaves a terminal historical PI cover. */ - UT_ASSERT_EQ(cluster_pcm_lock_apply_gcs_transition_result( - tag, PCM_TRANS_X_TO_N_DOWNGRADE, 3), PCM_GCS_TRANSITION_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_apply_gcs_transition_result(tag, PCM_TRANS_X_TO_N_DOWNGRADE, 3), + PCM_GCS_TRANSITION_APPLIED); UT_ASSERT_EQ(stop_pcm_poll(false, NULL, NULL, NULL), CLUSTER_NORMAL_STOP_READY); UT_ASSERT_EQ(stop_pcm_poll(true, NULL, NULL, NULL), CLUSTER_NORMAL_STOP_PENDING); MyAuxProcType = CheckpointerProcess; @@ -10072,7 +9549,8 @@ UT_TEST(test_pcm_stop_durable_cut_replaces_exact_terminal_pi_cover) UT_ASSERT_EQ(stop_pcm_poll(true, NULL, NULL, NULL), CLUSTER_NORMAL_STOP_READY); /* The exact tombstone is preserved, not changed to RELEASED/success. */ UT_ASSERT_EQ(cluster_pcm_lock_resource_x_master_snapshot_exact( - &assertion.common.logical_assertion, &snapshot), RESOURCE_X_APPLY_APPLIED); + &assertion.common.logical_assertion, &snapshot), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(snapshot.phase, RESOURCE_X_MASTER_SETTLED); /* Without the global durable cut, the old online negative is unchanged. */ stop_pi_cut_allowed = false; @@ -10547,20 +10025,19 @@ UT_TEST(test_resource_x_remote_lane0_settlement_retires_only_after_exact_source_ cluster_node_id = 0; cluster_pcm_lock_acquire(tag, PCM_LOCK_MODE_X); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), - RESOURCE_X_APPLY_APPLIED); + RESOURCE_X_APPLY_APPLIED); bootstrap = make_resource_x_bootstrap_request(tag, 2); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_bootstrap_request_exact( - &bootstrap, 2, 61, 77, 31, 71, &bootstrap_ack), - RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_bootstrap_request_exact(&bootstrap, 2, 61, 77, 31, 71, + &bootstrap_ack), + RESOURCE_X_APPLY_APPLIED); assertion = bootstrap_ack; assertion.kind = RESOURCE_X_WIRE_ASSERT_X; assertion.common.sender_connection_generation = 51; - assertion.common.authority_generation - = assertion.common.base_authority_generation; + assertion.common.authority_generation = assertion.common.base_authority_generation; assertion.common.outcome = RESOURCE_X_OUTCOME_NONE; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_bootstrapped_exact( - &assertion, 2, 61, 77, 31, 71, &snapshot), - RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_bootstrapped_exact(&assertion, 2, 61, 77, 31, + 71, &snapshot), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(snapshot.phase, RESOURCE_X_MASTER_WAIT_BLOCKERS); /* A requester that is still an unresolved physical blocker of the active @@ -10568,51 +10045,40 @@ UT_TEST(test_resource_x_remote_lane0_settlement_retires_only_after_exact_source_ * type-17 transition can invalidate this pre-ASSERT attempt before the * predecessor retires, so retaining it would orphan the bounded priority * and reject the required higher attempt after settlement. */ - successor_request = make_resource_x_bootstrap_request_values( - tag, 0, 17, 31, 41, 53); + successor_request = make_resource_x_bootstrap_request_values(tag, 0, 17, 31, 41, 53); memset(&successor_ack, 0, sizeof(successor_ack)); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_bootstrap_request_exact( - &successor_request, 0, 63, 77, 31, 71, &successor_ack), - RESOURCE_X_APPLY_BAD_STATE); - UT_ASSERT_EQ(successor_ack.common.base_authority_generation, - UINT64_C(0)); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_bootstrap_request_exact(&successor_request, 0, 63, 77, + 31, 71, &successor_ack), + RESOURCE_X_APPLY_BAD_STATE); + UT_ASSERT_EQ(successor_ack.common.base_authority_generation, UINT64_C(0)); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_block_intent_snapshot_exact( - &assertion.common.logical_assertion, 0, &intent, payload, - sizeof(payload)), RESOURCE_X_APPLY_APPLIED); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_outbound_intent_stage_exact( - &intent, 101), RESOURCE_X_INTENT_STAGED); - UT_ASSERT(cluster_pcm_lock_resource_x_outbound_intent_complete_exact( - &intent)); + &assertion.common.logical_assertion, 0, &intent, payload, sizeof(payload)), + RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_outbound_intent_stage_exact(&intent, 101), + RESOURCE_X_INTENT_STAGED); + UT_ASSERT(cluster_pcm_lock_resource_x_outbound_intent_complete_exact(&intent)); blocked = make_resource_x_remote_blocked_frame(tag, 2, 0); - blocked.common.base_authority_generation - = assertion.common.base_authority_generation; - blocked.common.authority_generation - = assertion.common.base_authority_generation; + blocked.common.base_authority_generation = assertion.common.base_authority_generation; + blocked.common.authority_generation = assertion.common.base_authority_generation; blocked.common.assertion_sequence = assertion.common.assertion_sequence; blocked.common.ordered_lane = 0; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_blocked_to_n_exact( - &blocked, 0, &snapshot), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_blocked_to_n_exact(&blocked, 0, &snapshot), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(snapshot.phase, RESOURCE_X_MASTER_GRANT_COMMITTED); UT_ASSERT_EQ(snapshot.proof_kind, RESOURCE_X_PROOF_REMOTE_CARRIER); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_grant_intent_snapshot_exact( &assertion.common.logical_assertion, &intent, payload, sizeof(payload)), RESOURCE_X_APPLY_NOT_FOUND); - settlement = make_resource_x_master_frame( - RESOURCE_X_WIRE_INSTALL_SETTLEMENT, tag, 2, 2); - settlement.common.base_authority_generation - = assertion.common.base_authority_generation; - settlement.common.resource_formation - = assertion.common.resource_formation; - settlement.common.master_session_incarnation - = assertion.common.master_session_incarnation; - settlement.common.assertion_sequence - = assertion.common.assertion_sequence; + settlement = make_resource_x_master_frame(RESOURCE_X_WIRE_INSTALL_SETTLEMENT, tag, 2, 2); + settlement.common.base_authority_generation = assertion.common.base_authority_generation; + settlement.common.resource_formation = assertion.common.resource_formation; + settlement.common.master_session_incarnation = assertion.common.master_session_incarnation; + settlement.common.assertion_sequence = assertion.common.assertion_sequence; settlement.common.ordered_lane = 0; - settlement.common.authority_generation - = snapshot.final_authority_generation; + settlement.common.authority_generation = snapshot.final_authority_generation; settlement.common.outcome = RESOURCE_X_OUTCOME_OK; settlement.body.install_settlement.conversion_base_generation = settlement.common.base_authority_generation; @@ -10621,47 +10087,41 @@ UT_TEST(test_resource_x_remote_lane0_settlement_retires_only_after_exact_source_ settlement.body.install_settlement.requester_connection_generation = 91; settlement.body.install_settlement.requester_target_generation = blocked.body.blocked_to_n.requester_target_generation; - settlement.body.install_settlement.page_scn_lsn - = blocked.body.blocked_to_n.page_scn_lsn; - settlement.body.install_settlement.page_checksum - = blocked.body.blocked_to_n.page_checksum; + settlement.body.install_settlement.page_scn_lsn = blocked.body.blocked_to_n.page_scn_lsn; + settlement.body.install_settlement.page_checksum = blocked.body.blocked_to_n.page_checksum; settlement.body.install_settlement.source_proof_crc32c = blocked.body.blocked_to_n.source_proof_crc32c; settlement.body.install_settlement.installed_mode = PCM_STATE_X; - settlement.body.install_settlement.requester_role - = RESOURCE_X_REQUESTER_ROLE_ACQUIRER; - settlement.body.install_settlement.terminal_outcome - = RESOURCE_X_OUTCOME_OK; - settlement.body.install_settlement.terminal_state - = RESOURCE_X_SETTLEMENT_TERMINAL_INSTALLED; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_install_settlement_exact( - &settlement, 2, &settled_snapshot), RESOURCE_X_APPLY_APPLIED); + settlement.body.install_settlement.requester_role = RESOURCE_X_REQUESTER_ROLE_ACQUIRER; + settlement.body.install_settlement.terminal_outcome = RESOURCE_X_OUTCOME_OK; + settlement.body.install_settlement.terminal_state = RESOURCE_X_SETTLEMENT_TERMINAL_INSTALLED; + UT_ASSERT_EQ( + cluster_pcm_lock_resource_x_install_settlement_exact(&settlement, 2, &settled_snapshot), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(settled_snapshot.phase, RESOURCE_X_MASTER_SETTLED); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_source_settlement_intent_snapshot_exact( - &assertion.common.logical_assertion, &intent, payload, - sizeof(payload)), RESOURCE_X_APPLY_APPLIED); - UT_ASSERT_EQ(intent.body.owner_kind, - RESOURCE_X_INTENT_OWNER_HOLDER_RELEASE); + &assertion.common.logical_assertion, &intent, payload, sizeof(payload)), + RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(intent.body.owner_kind, RESOURCE_X_INTENT_OWNER_HOLDER_RELEASE); UT_ASSERT_EQ(intent.destination_node, UINT32_C(0)); UT_ASSERT_EQ(intent.kind, RESOURCE_X_WIRE_SOURCE_SETTLEMENT_V2); UT_ASSERT_EQ(intent.payload_bytes, RESOURCE_X_PROOF_V1_BYTES); - UT_ASSERT(cluster_resource_x_wire_decode( - RESOURCE_X_MSG_BLOCK_TO_N, payload, intent.payload_bytes, - &source_request, &reject)); + UT_ASSERT(cluster_resource_x_wire_decode(RESOURCE_X_MSG_BLOCK_TO_N, payload, + intent.payload_bytes, &source_request, &reject)); UT_ASSERT_EQ(source_request.common.authority_generation, - settled_snapshot.final_authority_generation); + settled_snapshot.final_authority_generation); UT_ASSERT_EQ(source_request.body.blocked_to_n.source_carrier_generation, - blocked.body.blocked_to_n.source_carrier_generation); + blocked.body.blocked_to_n.source_carrier_generation); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_settled_retire_exact( - &assertion.common.logical_assertion, - assertion.common.assertion_sequence, &settled_snapshot), - RESOURCE_X_APPLY_APPLIED); + &assertion.common.logical_assertion, assertion.common.assertion_sequence, + &settled_snapshot), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_source_settlement_intent_snapshot_exact( - &assertion.common.logical_assertion, &intent, payload, - sizeof(payload)), RESOURCE_X_APPLY_APPLIED); + &assertion.common.logical_assertion, &intent, payload, sizeof(payload)), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_master_snapshot_exact( - &assertion.common.logical_assertion, &snapshot), - RESOURCE_X_APPLY_APPLIED); + &assertion.common.logical_assertion, &snapshot), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(snapshot.phase, RESOURCE_X_MASTER_SETTLED); /* The live conversion is terminal, but node 0 remains the selected @@ -10669,74 +10129,68 @@ UT_TEST(test_resource_x_remote_lane0_settlement_retires_only_after_exact_source_ * local successor is not otherwise admissible under the SourceSettlement * interlock, so this rejected attempt must not claim master priority. */ memset(&successor_ack, 0, sizeof(successor_ack)); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_bootstrap_request_exact( - &successor_request, 0, 63, 77, 31, 71, &successor_ack), - RESOURCE_X_APPLY_BAD_STATE); - UT_ASSERT_EQ(successor_ack.common.base_authority_generation, - UINT64_C(0)); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_bootstrap_request_exact(&successor_request, 0, 63, 77, + 31, 71, &successor_ack), + RESOURCE_X_APPLY_BAD_STATE); + UT_ASSERT_EQ(successor_ack.common.base_authority_generation, UINT64_C(0)); source_ack = source_request; source_ack.kind = RESOURCE_X_WIRE_SOURCE_SETTLEMENT_ACK_V2; source_ack.common.sender_connection_generation = 64; source_ack.common.outcome = RESOURCE_X_OUTCOME_OK; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_source_settlement_ack_exact( - &source_ack, 0, &after_ack), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ( + cluster_pcm_lock_resource_x_source_settlement_ack_exact(&source_ack, 0, &after_ack), + RESOURCE_X_APPLY_APPLIED); /* Pair retention canceled the unbound local attempt and preserved its * floor, so the requester legitimately retries with a higher attempt. It * must sample the current base immediately after the old carrier settles; * an orphan priority for attempt 41 would incorrectly reject it. */ - successor_retry = make_resource_x_bootstrap_request_values( - tag, 0, 17, 31, 42, 53); - retry_result = cluster_pcm_lock_resource_x_bootstrap_request_exact( - &successor_retry, 0, 63, 77, 31, 71, &successor_ack); + successor_retry = make_resource_x_bootstrap_request_values(tag, 0, 17, 31, 42, 53); + retry_result = cluster_pcm_lock_resource_x_bootstrap_request_exact(&successor_retry, 0, 63, 77, + 31, 71, &successor_ack); UT_ASSERT_EQ(retry_result, RESOURCE_X_APPLY_APPLIED); if (retry_result != RESOURCE_X_APPLY_APPLIED) return; UT_ASSERT_EQ(successor_ack.common.base_authority_generation, - settled_snapshot.final_authority_generation); + settled_snapshot.final_authority_generation); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_master_snapshot_exact( - &assertion.common.logical_assertion, &after_ack), - RESOURCE_X_APPLY_APPLIED); + &assertion.common.logical_assertion, &after_ack), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT(memcmp(&after_ack, &snapshot, sizeof(snapshot)) == 0); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_source_settlement_ack_exact( - &source_ack, 0, &after_ack), RESOURCE_X_APPLY_DUPLICATE); + UT_ASSERT_EQ( + cluster_pcm_lock_resource_x_source_settlement_ack_exact(&source_ack, 0, &after_ack), + RESOURCE_X_APPLY_DUPLICATE); stale_ack = source_ack; stale_ack.body.blocked_to_n.source_carrier_generation++; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_source_settlement_ack_exact( - &stale_ack, 0, &snapshot), RESOURCE_X_APPLY_STALE); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_source_settlement_ack_exact(&stale_ack, 0, &snapshot), + RESOURCE_X_APPLY_STALE); /* The exact ACK tombstone is terminal, but R8 owns formation retirement. * It clears the old bounded source debt before producing the same-token * zero proof; R10 then observes no logical or physical retry debt. */ - release = make_resource_x_master_frame( - RESOURCE_X_WIRE_RELEASE_X, tag, 2, 2); - release.common.base_authority_generation - = source_request.common.base_authority_generation; - release.common.authority_generation - = source_request.common.authority_generation; - release.common.resource_formation - = source_request.common.resource_formation; - release.common.master_session_incarnation - = source_request.common.master_session_incarnation; - release.common.assertion_sequence - = source_request.common.assertion_sequence; + release = make_resource_x_master_frame(RESOURCE_X_WIRE_RELEASE_X, tag, 2, 2); + release.common.base_authority_generation = source_request.common.base_authority_generation; + release.common.authority_generation = source_request.common.authority_generation; + release.common.resource_formation = source_request.common.resource_formation; + release.common.master_session_incarnation = source_request.common.master_session_incarnation; + release.common.assertion_sequence = source_request.common.assertion_sequence; release.common.ordered_lane = 0; release.common.observed_mode = PCM_STATE_X; release.common.target_mode = PCM_STATE_N; release.common.outcome = RESOURCE_X_OUTCOME_OK; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_release_x_exact( - &release, 2, &snapshot), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_release_x_exact(&release, 2, &snapshot), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(snapshot.phase, RESOURCE_X_MASTER_RELEASED); UT_ASSERT(cluster_resource_x_reconfig_freeze(17, 18, &token)); do { - reconfig_result = cluster_resource_x_reconfig_sweep( - &token, 4, &batch); + reconfig_result = cluster_resource_x_reconfig_sweep(&token, 4, &batch); } while (reconfig_result == RESOURCE_X_RECONFIG_MORE - || reconfig_result == RESOURCE_X_RECONFIG_RETRY); + || reconfig_result == RESOURCE_X_RECONFIG_RETRY); UT_ASSERT_EQ(reconfig_result, RESOURCE_X_RECONFIG_DONE); UT_ASSERT(cluster_resource_x_reconfig_zero_proof_exact(&token, &zero)); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_source_settlement_ack_exact( - &source_ack, 0, &after_ack), RESOURCE_X_APPLY_NOT_FOUND); + UT_ASSERT_EQ( + cluster_pcm_lock_resource_x_source_settlement_ack_exact(&source_ack, 0, &after_ack), + RESOURCE_X_APPLY_NOT_FOUND); } UT_TEST(test_resource_x_adapter_successor_samples_only_exact_canonical_base) @@ -10752,25 +10206,22 @@ UT_TEST(test_resource_x_adapter_successor_samples_only_exact_canonical_base) cluster_node_id = 0; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), RESOURCE_X_APPLY_APPLIED); - UT_ASSERT_EQ(cluster_pcm_lock_apply_gcs_transition_result( - tag, PCM_TRANS_N_TO_S, 0), PCM_GCS_TRANSITION_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_apply_gcs_transition_result(tag, PCM_TRANS_N_TO_S, 0), + PCM_GCS_TRANSITION_APPLIED); UT_ASSERT(cluster_pcm_lock_authority_snapshot(tag, &authority)); UT_ASSERT_EQ(authority.transition_count, UINT64_C(1)); - predecessor = make_resource_x_master_frame( - RESOURCE_X_WIRE_ASSERT_X, tag, 3, 3); + predecessor = make_resource_x_master_frame(RESOURCE_X_WIRE_ASSERT_X, tag, 3, 3); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_adapter_base_bind_exact( - &predecessor.common.logical_assertion, 17, 1, &authority), - RESOURCE_X_APPLY_DUPLICATE); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact( - &predecessor, 3, &snapshot), RESOURCE_X_APPLY_APPLIED); - UT_ASSERT_EQ(cluster_pcm_lock_try_reserve_pending_x(tag, 3, 77), - PCM_PENDING_X_RESERVE_OK); + &predecessor.common.logical_assertion, 17, 1, &authority), + RESOURCE_X_APPLY_DUPLICATE); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact(&predecessor, 3, &snapshot), + RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_try_reserve_pending_x(tag, 3, 77), PCM_PENDING_X_RESERVE_OK); UT_ASSERT(cluster_pcm_lock_authority_snapshot(tag, &authority)); - successor = make_resource_x_master_frame( - RESOURCE_X_WIRE_ASSERT_X, tag, 0, 0); + successor = make_resource_x_master_frame(RESOURCE_X_WIRE_ASSERT_X, tag, 0, 0); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_adapter_successor_base_exact( - &successor.common.logical_assertion, 17, &authority, - &canonical_base), RESOURCE_X_APPLY_APPLIED); + &successor.common.logical_assertion, 17, &authority, &canonical_base), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(canonical_base, UINT64_C(1)); /* The caller's complete legacy snapshot is an optimistic token. Once @@ -10779,8 +10230,8 @@ UT_TEST(test_resource_x_adapter_successor_samples_only_exact_canonical_base) UT_ASSERT(cluster_pcm_lock_clear_queue_pending_x_exact(tag, 3, 77)); canonical_base = 0; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_adapter_successor_base_exact( - &successor.common.logical_assertion, 17, &authority, - &canonical_base), RESOURCE_X_APPLY_STALE); + &successor.common.logical_assertion, 17, &authority, &canonical_base), + RESOURCE_X_APPLY_STALE); UT_ASSERT_EQ(canonical_base, UINT64_C(0)); } @@ -10800,35 +10251,31 @@ UT_TEST(test_resource_x_master_arms_exact_block_to_n_intent_per_holder) cluster_pcm_lock_acquire(tag, PCM_LOCK_MODE_X); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), RESOURCE_X_APPLY_APPLIED); - assertion = make_resource_x_master_frame( - RESOURCE_X_WIRE_ASSERT_X, tag, 2, 2); + assertion = make_resource_x_master_frame(RESOURCE_X_WIRE_ASSERT_X, tag, 2, 2); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact( - &assertion, 2, &snapshot), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact(&assertion, 2, &snapshot), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(snapshot.phase, RESOURCE_X_MASTER_WAIT_BLOCKERS); UT_ASSERT_EQ(snapshot.incompatible_holders_bitmap, UINT32_C(1)); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_block_intent_snapshot_exact( - &assertion.common.logical_assertion, 0, &intent, payload, - sizeof(payload)), RESOURCE_X_APPLY_APPLIED); + &assertion.common.logical_assertion, 0, &intent, payload, sizeof(payload)), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(intent.state, RESOURCE_X_INTENT_SLOT_ARMED); UT_ASSERT_EQ(intent.logical_generation, 41); UT_ASSERT_EQ(intent.authority_generation, 1); UT_ASSERT_EQ(intent.destination_node, 0); UT_ASSERT_EQ(intent.payload_bytes, RESOURCE_X_CONTROL_V1_BYTES); UT_ASSERT_EQ(intent.kind, RESOURCE_X_WIRE_BLOCK_TO_N); - UT_ASSERT_EQ(intent.body.owner_kind, - RESOURCE_X_INTENT_OWNER_MASTER_BLOCK); + UT_ASSERT_EQ(intent.body.owner_kind, RESOURCE_X_INTENT_OWNER_MASTER_BLOCK); UT_ASSERT_EQ(intent.body.owner_node, 0); UT_ASSERT_EQ(intent.body.owner_index, 0); - UT_ASSERT(resource_x_assertion_equal(&intent.body.assertion, - &assertion.common.logical_assertion)); - UT_ASSERT(cluster_resource_x_wire_decode( - RESOURCE_X_MSG_BLOCK_TO_N, payload, - RESOURCE_X_CONTROL_V1_BYTES, - &decoded, &reject)); + UT_ASSERT( + resource_x_assertion_equal(&intent.body.assertion, &assertion.common.logical_assertion)); + UT_ASSERT(cluster_resource_x_wire_decode(RESOURCE_X_MSG_BLOCK_TO_N, payload, + RESOURCE_X_CONTROL_V1_BYTES, &decoded, &reject)); UT_ASSERT_EQ(decoded.kind, RESOURCE_X_WIRE_BLOCK_TO_N); UT_ASSERT(resource_x_assertion_equal(&decoded.common.logical_assertion, - &assertion.common.logical_assertion)); + &assertion.common.logical_assertion)); UT_ASSERT_EQ(decoded.common.action_node, 0); UT_ASSERT_EQ(decoded.common.observed_mode, PCM_STATE_X); UT_ASSERT_EQ(decoded.common.target_mode, PCM_STATE_N); @@ -10836,25 +10283,23 @@ UT_TEST(test_resource_x_master_arms_exact_block_to_n_intent_per_holder) UT_ASSERT_EQ(decoded.common.retain_pi_if_dirty, 1); UT_ASSERT_EQ(decoded.common.sender_connection_generation, 1); UT_ASSERT(decoded.common.sender_connection_generation - != assertion.common.sender_connection_generation); + != assertion.common.sender_connection_generation); UT_ASSERT_EQ(decoded.common.authority_generation, 3); UT_ASSERT_EQ(decoded.common.flags, RESOURCE_X_COMMON_FLAG_AUTHORITY_WITH_IMAGE); UT_ASSERT_EQ(decoded.common.outcome, RESOURCE_X_OUTCOME_NONE); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_block_intent_snapshot_exact( - &assertion.common.logical_assertion, 1, &intent, payload, - sizeof(payload)), RESOURCE_X_APPLY_NOT_FOUND); + &assertion.common.logical_assertion, 1, &intent, payload, sizeof(payload)), + RESOURCE_X_APPLY_NOT_FOUND); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_outbound_intent_probe_exact( - 4, &intent, payload, sizeof(payload), &examined), - RESOURCE_X_INTENT_PROBE_FOUND); + 4, &intent, payload, sizeof(payload), &examined), + RESOURCE_X_INTENT_PROBE_FOUND); UT_ASSERT(examined >= 1 && examined <= 4); - UT_ASSERT_EQ(intent.body.owner_kind, - RESOURCE_X_INTENT_OWNER_MASTER_BLOCK); + UT_ASSERT_EQ(intent.body.owner_kind, RESOURCE_X_INTENT_OWNER_MASTER_BLOCK); UT_ASSERT_EQ(intent.body.owner_index, 0); } static ResourceXDecodedFrame -resource_x_block_intent_frame(const ResourceXAssertion *assertion, - int32 holder_node) +resource_x_block_intent_frame(const ResourceXAssertion *assertion, int32 holder_node) { ResourceXDecodedFrame decoded; ResourceXIntentSlot intent; @@ -10863,14 +10308,13 @@ resource_x_block_intent_frame(const ResourceXAssertion *assertion, memset(&decoded, 0, sizeof(decoded)); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_block_intent_snapshot_exact( - assertion, holder_node, &intent, payload, sizeof(payload)), - RESOURCE_X_APPLY_APPLIED); + assertion, holder_node, &intent, payload, sizeof(payload)), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(intent.state, RESOURCE_X_INTENT_SLOT_ARMED); UT_ASSERT_EQ(intent.destination_node, (uint32)holder_node); UT_ASSERT_EQ(intent.payload_bytes, RESOURCE_X_CONTROL_V1_BYTES); - UT_ASSERT(cluster_resource_x_wire_decode( - RESOURCE_X_MSG_BLOCK_TO_N, payload, RESOURCE_X_CONTROL_V1_BYTES, - &decoded, &reject)); + UT_ASSERT(cluster_resource_x_wire_decode(RESOURCE_X_MSG_BLOCK_TO_N, payload, + RESOURCE_X_CONTROL_V1_BYTES, &decoded, &reject)); return decoded; } @@ -10900,18 +10344,16 @@ UT_TEST(test_resource_x_requester_absent_single_s_selects_only_holder) cluster_pcm_lock_acquire(tag, PCM_LOCK_MODE_S); cluster_node_id = 0; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), - RESOURCE_X_APPLY_APPLIED); - assertion = make_resource_x_master_frame( - RESOURCE_X_WIRE_ASSERT_X, tag, 1, 1); + RESOURCE_X_APPLY_APPLIED); + assertion = make_resource_x_master_frame(RESOURCE_X_WIRE_ASSERT_X, tag, 1, 1); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact( - &assertion, 1, &snapshot), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact(&assertion, 1, &snapshot), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(snapshot.phase, RESOURCE_X_MASTER_WAIT_BLOCKERS); UT_ASSERT_EQ(snapshot.incompatible_holders_bitmap, UINT32_C(0x8)); UT_ASSERT_EQ(snapshot.source_node, 3); UT_ASSERT_EQ(snapshot.proof_kind, 0); - block = resource_x_block_intent_frame( - &assertion.common.logical_assertion, 3); + block = resource_x_block_intent_frame(&assertion.common.logical_assertion, 3); UT_ASSERT_EQ(block.common.observed_mode, PCM_STATE_S); UT_ASSERT_EQ(block.common.source_candidate, 1); UT_ASSERT_EQ(block.common.retain_pi_if_dirty, 1); @@ -10932,16 +10374,14 @@ UT_TEST(test_resource_x_requester_absent_multi_s_prefers_master_local) cluster_pcm_lock_acquire(tag, PCM_LOCK_MODE_S); cluster_node_id = 0; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), - RESOURCE_X_APPLY_APPLIED); - assertion = make_resource_x_master_frame( - RESOURCE_X_WIRE_ASSERT_X, tag, 1, 1); + RESOURCE_X_APPLY_APPLIED); + assertion = make_resource_x_master_frame(RESOURCE_X_WIRE_ASSERT_X, tag, 1, 1); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact( - &assertion, 1, &snapshot), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact(&assertion, 1, &snapshot), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(snapshot.incompatible_holders_bitmap, UINT32_C(0x9)); UT_ASSERT_EQ(snapshot.source_node, 0); - peer_block = resource_x_block_intent_frame( - &assertion.common.logical_assertion, 3); + peer_block = resource_x_block_intent_frame(&assertion.common.logical_assertion, 3); resource_x_test_ack_noncarrier(&assertion.common.logical_assertion, 3); local_block = resource_x_block_intent_frame(&assertion.common.logical_assertion, 0); UT_ASSERT_EQ(local_block.common.source_candidate, 1); @@ -10965,16 +10405,14 @@ UT_TEST(test_resource_x_requester_absent_multi_s_uses_lowest_stable_peer) cluster_pcm_lock_acquire(tag, PCM_LOCK_MODE_S); cluster_node_id = 0; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), - RESOURCE_X_APPLY_APPLIED); - assertion = make_resource_x_master_frame( - RESOURCE_X_WIRE_ASSERT_X, tag, 1, 1); + RESOURCE_X_APPLY_APPLIED); + assertion = make_resource_x_master_frame(RESOURCE_X_WIRE_ASSERT_X, tag, 1, 1); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact( - &assertion, 1, &snapshot), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact(&assertion, 1, &snapshot), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(snapshot.incompatible_holders_bitmap, UINT32_C(0xc)); UT_ASSERT_EQ(snapshot.source_node, 2); - upper_block = resource_x_block_intent_frame( - &assertion.common.logical_assertion, 3); + upper_block = resource_x_block_intent_frame(&assertion.common.logical_assertion, 3); resource_x_test_ack_noncarrier(&assertion.common.logical_assertion, 3); lower_block = resource_x_block_intent_frame(&assertion.common.logical_assertion, 2); UT_ASSERT_EQ(lower_block.common.source_candidate, 1); @@ -10997,16 +10435,14 @@ UT_TEST(test_resource_x_requester_present_does_not_select_remote_s_carrier) cluster_pcm_lock_acquire(tag, PCM_LOCK_MODE_S); cluster_node_id = 0; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), - RESOURCE_X_APPLY_APPLIED); - assertion = make_resource_x_master_frame( - RESOURCE_X_WIRE_ASSERT_X, tag, 1, 1); + RESOURCE_X_APPLY_APPLIED); + assertion = make_resource_x_master_frame(RESOURCE_X_WIRE_ASSERT_X, tag, 1, 1); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact( - &assertion, 1, &snapshot), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact(&assertion, 1, &snapshot), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(snapshot.incompatible_holders_bitmap, UINT32_C(0x8)); UT_ASSERT_EQ(snapshot.source_node, -1); - peer_block = resource_x_block_intent_frame( - &assertion.common.logical_assertion, 3); + peer_block = resource_x_block_intent_frame(&assertion.common.logical_assertion, 3); UT_ASSERT_EQ(peer_block.common.source_candidate, 0); UT_ASSERT_EQ(peer_block.common.retain_pi_if_dirty, 0); } @@ -11027,27 +10463,25 @@ UT_TEST(test_resource_x_duplicate_assertion_preserves_selected_s_carrier) cluster_pcm_lock_acquire(tag, PCM_LOCK_MODE_S); cluster_node_id = 0; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), - RESOURCE_X_APPLY_APPLIED); - assertion = make_resource_x_master_frame( - RESOURCE_X_WIRE_ASSERT_X, tag, 1, 1); + RESOURCE_X_APPLY_APPLIED); + assertion = make_resource_x_master_frame(RESOURCE_X_WIRE_ASSERT_X, tag, 1, 1); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact( - &assertion, 1, &snapshot), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact(&assertion, 1, &snapshot), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(snapshot.source_node, 2); resource_x_test_ack_noncarrier(&assertion.common.logical_assertion, 3); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_block_intent_snapshot_exact( - &assertion.common.logical_assertion, 2, &intent, payload, - sizeof(payload)), RESOURCE_X_APPLY_APPLIED); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_outbound_intent_stage_exact( - &intent, intent.first_armed_us + 1), RESOURCE_X_INTENT_STAGED); - UT_ASSERT(cluster_pcm_lock_resource_x_outbound_intent_complete_exact( - &intent)); + &assertion.common.logical_assertion, 2, &intent, payload, sizeof(payload)), + RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ( + cluster_pcm_lock_resource_x_outbound_intent_stage_exact(&intent, intent.first_armed_us + 1), + RESOURCE_X_INTENT_STAGED); + UT_ASSERT(cluster_pcm_lock_resource_x_outbound_intent_complete_exact(&intent)); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact( - &assertion, 1, &snapshot), RESOURCE_X_APPLY_DUPLICATE); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact(&assertion, 1, &snapshot), + RESOURCE_X_APPLY_DUPLICATE); UT_ASSERT_EQ(snapshot.source_node, 2); - source_block = resource_x_block_intent_frame( - &assertion.common.logical_assertion, 2); + source_block = resource_x_block_intent_frame(&assertion.common.logical_assertion, 2); UT_ASSERT_EQ(source_block.common.observed_mode, PCM_STATE_S); UT_ASSERT_EQ(source_block.common.source_candidate, 1); UT_ASSERT_EQ(source_block.common.retain_pi_if_dirty, 1); @@ -11064,21 +10498,20 @@ UT_TEST(test_resource_x_existing_selected_s_intent_conflict_fails_closed) cluster_pcm_lock_acquire(tag, PCM_LOCK_MODE_S); cluster_node_id = 0; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), - RESOURCE_X_APPLY_APPLIED); - assertion = make_resource_x_master_frame( - RESOURCE_X_WIRE_ASSERT_X, tag, 1, 1); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact( - &assertion, 1, &snapshot), RESOURCE_X_APPLY_APPLIED); + RESOURCE_X_APPLY_APPLIED); + assertion = make_resource_x_master_frame(RESOURCE_X_WIRE_ASSERT_X, tag, 1, 1); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact(&assertion, 1, &snapshot), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(snapshot.source_node, 3); /* The same retained owner now conflicts with the live source mode. A * duplicate assertion must not overwrite its S/1/1 bytes with X/1/1. */ cluster_node_id = 3; - UT_ASSERT_EQ(cluster_pcm_lock_apply_gcs_transition_result( - tag, PCM_TRANS_S_TO_X_UPGRADE, 3), PCM_GCS_TRANSITION_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_apply_gcs_transition_result(tag, PCM_TRANS_S_TO_X_UPGRADE, 3), + PCM_GCS_TRANSITION_APPLIED); cluster_node_id = 0; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact( - &assertion, 1, &snapshot), RESOURCE_X_APPLY_RECOVERY_BLOCKED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact(&assertion, 1, &snapshot), + RESOURCE_X_APPLY_RECOVERY_BLOCKED); UT_ASSERT_EQ(snapshot.phase, RESOURCE_X_MASTER_RECOVERY_BLOCKED); UT_ASSERT_EQ(snapshot.source_node, 3); } @@ -11095,9 +10528,8 @@ UT_TEST(test_resource_x_source_pair_rejects_status_image_mode_mismatch) cluster_node_id = 0; cluster_pcm_lock_acquire(tag, PCM_LOCK_MODE_X); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), - RESOURCE_X_APPLY_APPLIED); - block = make_resource_x_master_frame( - RESOURCE_X_WIRE_BLOCK_TO_N, tag, 2, 0); + RESOURCE_X_APPLY_APPLIED); + block = make_resource_x_master_frame(RESOURCE_X_WIRE_BLOCK_TO_N, tag, 2, 0); block.common.observed_mode = PCM_STATE_X; block.common.target_mode = PCM_STATE_N; block.common.source_candidate = 1; @@ -11105,11 +10537,10 @@ UT_TEST(test_resource_x_source_pair_rejects_status_image_mode_mismatch) make_resource_x_remote_join_pair(tag, 2, &grant, &image); status = make_resource_x_remote_blocked_frame(tag, 2, 0); status.common.observed_mode = PCM_STATE_S; - status.body.blocked_to_n.source_proof_crc32c - = image.common.semantic_crc32c; + status.body.blocked_to_n.source_proof_crc32c = image.common.semantic_crc32c; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_block_to_n_source_exact( - &block, 0, &status, &image), RESOURCE_X_APPLY_INVALID); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_block_to_n_source_exact(&block, 0, &status, &image), + RESOURCE_X_APPLY_INVALID); } UT_TEST(test_resource_x_s_partial_source_polarity_is_rejected_by_consumer) @@ -11121,20 +10552,19 @@ UT_TEST(test_resource_x_s_partial_source_polarity_is_rejected_by_consumer) cluster_node_id = 0; cluster_pcm_lock_acquire(tag, PCM_LOCK_MODE_S); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), - RESOURCE_X_APPLY_APPLIED); - block = make_resource_x_master_frame( - RESOURCE_X_WIRE_BLOCK_TO_N, tag, 2, 0); + RESOURCE_X_APPLY_APPLIED); + block = make_resource_x_master_frame(RESOURCE_X_WIRE_BLOCK_TO_N, tag, 2, 0); block.common.observed_mode = PCM_STATE_S; block.common.target_mode = PCM_STATE_N; block.common.source_candidate = 1; block.common.retain_pi_if_dirty = 0; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_block_to_n_exact( - &block, 0), RESOURCE_X_APPLY_BAD_STATE); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_block_to_n_exact(&block, 0), + RESOURCE_X_APPLY_BAD_STATE); block.common.source_candidate = 0; block.common.retain_pi_if_dirty = 1; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_block_to_n_exact( - &block, 0), RESOURCE_X_APPLY_BAD_STATE); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_block_to_n_exact(&block, 0), + RESOURCE_X_APPLY_BAD_STATE); } UT_TEST(test_resource_x_prepared_s_source_retains_one_exact_matching_pair) @@ -11266,11 +10696,10 @@ UT_TEST(test_resource_x_selected_s_proof_and_noncarrier_status_commit_once) cluster_pcm_lock_acquire(tag, PCM_LOCK_MODE_S); cluster_node_id = 0; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), - RESOURCE_X_APPLY_APPLIED); - assertion = make_resource_x_master_frame( - RESOURCE_X_WIRE_ASSERT_X, tag, 1, 1); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact( - &assertion, 1, &snapshot), RESOURCE_X_APPLY_APPLIED); + RESOURCE_X_APPLY_APPLIED); + assertion = make_resource_x_master_frame(RESOURCE_X_WIRE_ASSERT_X, tag, 1, 1); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact(&assertion, 1, &snapshot), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(snapshot.source_node, 2); UT_ASSERT_EQ(snapshot.incompatible_holders_bitmap, UINT32_C(0xc)); @@ -11284,13 +10713,12 @@ UT_TEST(test_resource_x_selected_s_proof_and_noncarrier_status_commit_once) UT_ASSERT_EQ(snapshot.proof_kind, 0); UT_ASSERT_EQ(snapshot.source_node, 2); - noncarrier_status = make_resource_x_master_frame( - RESOURCE_X_WIRE_BLOCKED_TO_N, tag, 1, 3); + noncarrier_status = make_resource_x_master_frame(RESOURCE_X_WIRE_BLOCKED_TO_N, tag, 1, 3); noncarrier_status.common.observed_mode = PCM_STATE_S; noncarrier_status.common.target_mode = PCM_STATE_N; noncarrier_status.common.outcome = RESOURCE_X_OUTCOME_OK; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_blocked_to_n_exact( - &noncarrier_status, 3, &snapshot), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_blocked_to_n_exact(&noncarrier_status, 3, &snapshot), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(snapshot.phase, RESOURCE_X_MASTER_WAIT_BLOCKERS); UT_ASSERT_EQ(snapshot.blocked_holders_bitmap, UINT32_C(0x8)); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_blocked_to_n_exact(&source_proof, 2, &snapshot), @@ -11298,12 +10726,11 @@ UT_TEST(test_resource_x_selected_s_proof_and_noncarrier_status_commit_once) UT_ASSERT_EQ(snapshot.phase, RESOURCE_X_MASTER_GRANT_COMMITTED); UT_ASSERT_EQ(snapshot.blocked_holders_bitmap, UINT32_C(0xc)); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_authority_grant_exact( - &assertion.common.logical_assertion, &grant), - RESOURCE_X_APPLY_APPLIED); - UT_ASSERT_EQ(grant.body.authority_grant.proof_kind, - RESOURCE_X_PROOF_REMOTE_CARRIER); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_blocked_to_n_exact( - &noncarrier_status, 3, &snapshot), RESOURCE_X_APPLY_DUPLICATE); + &assertion.common.logical_assertion, &grant), + RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(grant.body.authority_grant.proof_kind, RESOURCE_X_PROOF_REMOTE_CARRIER); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_blocked_to_n_exact(&noncarrier_status, 3, &snapshot), + RESOURCE_X_APPLY_DUPLICATE); } UT_TEST(test_resource_x_selected_s_status_only_is_rejected) @@ -11318,20 +10745,18 @@ UT_TEST(test_resource_x_selected_s_status_only_is_rejected) cluster_pcm_lock_acquire(tag, PCM_LOCK_MODE_S); cluster_node_id = 0; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), - RESOURCE_X_APPLY_APPLIED); - assertion = make_resource_x_master_frame( - RESOURCE_X_WIRE_ASSERT_X, tag, 1, 1); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact( - &assertion, 1, &snapshot), RESOURCE_X_APPLY_APPLIED); + RESOURCE_X_APPLY_APPLIED); + assertion = make_resource_x_master_frame(RESOURCE_X_WIRE_ASSERT_X, tag, 1, 1); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact(&assertion, 1, &snapshot), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(snapshot.source_node, 3); - status = make_resource_x_master_frame( - RESOURCE_X_WIRE_BLOCKED_TO_N, tag, 1, 3); + status = make_resource_x_master_frame(RESOURCE_X_WIRE_BLOCKED_TO_N, tag, 1, 3); status.common.observed_mode = PCM_STATE_S; status.common.target_mode = PCM_STATE_N; status.common.outcome = RESOURCE_X_OUTCOME_OK; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_blocked_to_n_exact( - &status, 3, &snapshot), RESOURCE_X_APPLY_BAD_STATE); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_blocked_to_n_exact(&status, 3, &snapshot), + RESOURCE_X_APPLY_BAD_STATE); UT_ASSERT_EQ(snapshot.phase, RESOURCE_X_MASTER_WAIT_BLOCKERS); UT_ASSERT_EQ(snapshot.blocked_holders_bitmap, UINT32_C(0)); UT_ASSERT_EQ(snapshot.proof_kind, 0); @@ -11352,18 +10777,17 @@ UT_TEST(test_resource_x_noncarrier_s_remote_proof_is_rejected) cluster_pcm_lock_acquire(tag, PCM_LOCK_MODE_S); cluster_node_id = 0; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), - RESOURCE_X_APPLY_APPLIED); - assertion = make_resource_x_master_frame( - RESOURCE_X_WIRE_ASSERT_X, tag, 1, 1); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact( - &assertion, 1, &snapshot), RESOURCE_X_APPLY_APPLIED); + RESOURCE_X_APPLY_APPLIED); + assertion = make_resource_x_master_frame(RESOURCE_X_WIRE_ASSERT_X, tag, 1, 1); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact(&assertion, 1, &snapshot), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(snapshot.source_node, 2); proof = make_resource_x_remote_blocked_frame(tag, 1, 3); proof.common.observed_mode = PCM_STATE_S; proof.body.blocked_to_n.source_fence[28] = PCM_STATE_S; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_blocked_to_n_exact( - &proof, 3, &snapshot), RESOURCE_X_APPLY_BAD_STATE); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_blocked_to_n_exact(&proof, 3, &snapshot), + RESOURCE_X_APPLY_BAD_STATE); UT_ASSERT_EQ(snapshot.phase, RESOURCE_X_MASTER_WAIT_BLOCKERS); UT_ASSERT_EQ(snapshot.blocked_holders_bitmap, UINT32_C(0)); UT_ASSERT_EQ(snapshot.proof_kind, 0); @@ -11382,35 +10806,33 @@ UT_TEST(test_resource_x_master_exact_replay_redrives_unanswered_blocker) cluster_pcm_lock_acquire(tag, PCM_LOCK_MODE_X); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), RESOURCE_X_APPLY_APPLIED); - assertion = make_resource_x_master_frame( - RESOURCE_X_WIRE_ASSERT_X, tag, 2, 2); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact( - &assertion, 2, &snapshot), RESOURCE_X_APPLY_APPLIED); + assertion = make_resource_x_master_frame(RESOURCE_X_WIRE_ASSERT_X, tag, 2, 2); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact(&assertion, 2, &snapshot), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(snapshot.phase, RESOURCE_X_MASTER_WAIT_BLOCKERS); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_block_intent_snapshot_exact( - &assertion.common.logical_assertion, 0, &intent, payload, - sizeof(payload)), RESOURCE_X_APPLY_APPLIED); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_outbound_intent_stage_exact( - &intent, intent.first_armed_us + 1), RESOURCE_X_INTENT_STAGED); - UT_ASSERT(cluster_pcm_lock_resource_x_outbound_intent_complete_exact( - &intent)); + &assertion.common.logical_assertion, 0, &intent, payload, sizeof(payload)), + RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ( + cluster_pcm_lock_resource_x_outbound_intent_stage_exact(&intent, intent.first_armed_us + 1), + RESOURCE_X_INTENT_STAGED); + UT_ASSERT(cluster_pcm_lock_resource_x_outbound_intent_complete_exact(&intent)); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_block_intent_snapshot_exact( - &assertion.common.logical_assertion, 0, &intent, payload, - sizeof(payload)), RESOURCE_X_APPLY_NOT_FOUND); + &assertion.common.logical_assertion, 0, &intent, payload, sizeof(payload)), + RESOURCE_X_APPLY_NOT_FOUND); /* Physical type-17 admission is not a holder acknowledgement. Until * exact type-18 clears this blocker, replay of the same assertion must * rebuild the same owner-scoped type-17 obligation. */ - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact( - &assertion, 2, &snapshot), RESOURCE_X_APPLY_DUPLICATE); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact(&assertion, 2, &snapshot), + RESOURCE_X_APPLY_DUPLICATE); UT_ASSERT_EQ(snapshot.phase, RESOURCE_X_MASTER_WAIT_BLOCKERS); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_block_intent_snapshot_exact( - &assertion.common.logical_assertion, 0, &intent, payload, - sizeof(payload)), RESOURCE_X_APPLY_APPLIED); + &assertion.common.logical_assertion, 0, &intent, payload, sizeof(payload)), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(intent.state, RESOURCE_X_INTENT_SLOT_ARMED); UT_ASSERT_EQ(intent.kind, RESOURCE_X_WIRE_BLOCK_TO_N); - UT_ASSERT_EQ(intent.body.owner_kind, - RESOURCE_X_INTENT_OWNER_MASTER_BLOCK); + UT_ASSERT_EQ(intent.body.owner_kind, RESOURCE_X_INTENT_OWNER_MASTER_BLOCK); UT_ASSERT_EQ(intent.body.owner_index, 0); } @@ -11432,64 +10854,57 @@ UT_TEST(test_resource_x_holder_retains_status_before_s_to_n) cluster_pcm_lock_acquire(tag, PCM_LOCK_MODE_S); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), RESOURCE_X_APPLY_APPLIED); - block = make_resource_x_master_frame( - RESOURCE_X_WIRE_BLOCK_TO_N, tag, 2, 0); + block = make_resource_x_master_frame(RESOURCE_X_WIRE_BLOCK_TO_N, tag, 2, 0); block.common.observed_mode = PCM_STATE_S; block.common.target_mode = PCM_STATE_N; block.common.source_candidate = 0; block.common.retain_pi_if_dirty = 0; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_block_to_n_exact(&block, 0), - RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_block_to_n_exact(&block, 0), RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(cluster_pcm_lock_query(tag), PCM_LOCK_MODE_N); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_holder_status_intent_snapshot_exact( - &block.common.logical_assertion, &intent, payload, sizeof(payload)), - RESOURCE_X_APPLY_APPLIED); + &block.common.logical_assertion, &intent, payload, sizeof(payload)), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(intent.state, RESOURCE_X_INTENT_SLOT_ARMED); UT_ASSERT_EQ(intent.logical_generation, 41); UT_ASSERT_EQ(intent.authority_generation, 1); UT_ASSERT_EQ(intent.destination_node, 0); UT_ASSERT_EQ(intent.payload_bytes, RESOURCE_X_CONTROL_V1_BYTES); UT_ASSERT_EQ(intent.kind, RESOURCE_X_WIRE_BLOCKED_TO_N); - UT_ASSERT_EQ(intent.body.owner_kind, - RESOURCE_X_INTENT_OWNER_HOLDER_STATUS); + UT_ASSERT_EQ(intent.body.owner_kind, RESOURCE_X_INTENT_OWNER_HOLDER_STATUS); UT_ASSERT_EQ(intent.body.owner_node, 0); - UT_ASSERT(resource_x_assertion_equal(&intent.body.assertion, - &block.common.logical_assertion)); - UT_ASSERT(cluster_resource_x_wire_decode( - RESOURCE_X_MSG_BLOCKED_TO_N, payload, - RESOURCE_X_CONTROL_V1_BYTES, &decoded, &reject)); + UT_ASSERT(resource_x_assertion_equal(&intent.body.assertion, &block.common.logical_assertion)); + UT_ASSERT(cluster_resource_x_wire_decode(RESOURCE_X_MSG_BLOCKED_TO_N, payload, + RESOURCE_X_CONTROL_V1_BYTES, &decoded, &reject)); UT_ASSERT_EQ(decoded.kind, RESOURCE_X_WIRE_BLOCKED_TO_N); UT_ASSERT(!decoded.blocked_has_remote_proof); UT_ASSERT(resource_x_assertion_equal(&decoded.common.logical_assertion, - &block.common.logical_assertion)); + &block.common.logical_assertion)); UT_ASSERT_EQ(decoded.common.action_node, 0); UT_ASSERT_EQ(decoded.common.observed_mode, PCM_STATE_S); UT_ASSERT_EQ(decoded.common.target_mode, PCM_STATE_N); UT_ASSERT_EQ(decoded.common.outcome, RESOURCE_X_OUTCOME_OK); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_outbound_intent_probe_exact( - 4, &intent, payload, sizeof(payload), &examined), - RESOURCE_X_INTENT_PROBE_FOUND); + 4, &intent, payload, sizeof(payload), &examined), + RESOURCE_X_INTENT_PROBE_FOUND); UT_ASSERT(examined >= 1 && examined <= 4); - UT_ASSERT_EQ(intent.body.owner_kind, - RESOURCE_X_INTENT_OWNER_HOLDER_STATUS); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_outbound_intent_stage_exact( - &intent, 101), RESOURCE_X_INTENT_STAGED); - UT_ASSERT(cluster_pcm_lock_resource_x_outbound_intent_complete_exact( - &intent)); + UT_ASSERT_EQ(intent.body.owner_kind, RESOURCE_X_INTENT_OWNER_HOLDER_STATUS); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_outbound_intent_stage_exact(&intent, 101), + RESOURCE_X_INTENT_STAGED); + UT_ASSERT(cluster_pcm_lock_resource_x_outbound_intent_complete_exact(&intent)); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_holder_status_intent_snapshot_exact( - &block.common.logical_assertion, &intent, payload, sizeof(payload)), - RESOURCE_X_APPLY_NOT_FOUND); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_holder_status_exact( - &block.common.logical_assertion, &decoded), + &block.common.logical_assertion, &intent, payload, sizeof(payload)), + RESOURCE_X_APPLY_NOT_FOUND); + UT_ASSERT_EQ( + cluster_pcm_lock_resource_x_holder_status_exact(&block.common.logical_assertion, &decoded), RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(decoded.kind, RESOURCE_X_WIRE_BLOCKED_TO_N); UT_ASSERT_EQ(decoded.common.outcome, RESOURCE_X_OUTCOME_OK); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_block_to_n_exact(&block, 0), - RESOURCE_X_APPLY_DUPLICATE); + RESOURCE_X_APPLY_DUPLICATE); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_holder_status_intent_snapshot_exact( - &block.common.logical_assertion, &intent, payload, sizeof(payload)), - RESOURCE_X_APPLY_APPLIED); + &block.common.logical_assertion, &intent, payload, sizeof(payload)), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(intent.state, RESOURCE_X_INTENT_SLOT_ARMED); UT_ASSERT_EQ(cluster_pcm_lock_query(tag), PCM_LOCK_MODE_N); UT_ASSERT(cluster_resource_x_reconfig_freeze_exact(17, 18, 0, &token)); @@ -11497,8 +10912,8 @@ UT_TEST(test_resource_x_holder_retains_status_before_s_to_n) sweep_result = cluster_resource_x_reconfig_sweep(&token, 4, &batch); } while (sweep_result == RESOURCE_X_RECONFIG_MORE); UT_ASSERT_EQ(sweep_result, RESOURCE_X_RECONFIG_DONE); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_holder_status_exact( - &block.common.logical_assertion, &decoded), + UT_ASSERT_EQ( + cluster_pcm_lock_resource_x_holder_status_exact(&block.common.logical_assertion, &decoded), RESOURCE_X_APPLY_NOT_FOUND); } @@ -11524,10 +10939,8 @@ UT_TEST(test_resource_x_master_remote_proof_is_retained_not_inferred) UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), RESOURCE_X_APPLY_APPLIED); - assertion = make_resource_x_master_frame(RESOURCE_X_WIRE_ASSERT_X, - tag, 2, 2); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact(&assertion, 2, - &snapshot), + assertion = make_resource_x_master_frame(RESOURCE_X_WIRE_ASSERT_X, tag, 2, 2); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact(&assertion, 2, &snapshot), RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(snapshot.phase, RESOURCE_X_MASTER_WAIT_BLOCKERS); UT_ASSERT_EQ(snapshot.incompatible_holders_bitmap, UINT32_C(1)); @@ -11537,13 +10950,11 @@ UT_TEST(test_resource_x_master_remote_proof_is_retained_not_inferred) /* A topology-known X holder and a positive status are not a source * proof. The master must retain X and wait for the typed proof body. */ - blocked = make_resource_x_master_frame(RESOURCE_X_WIRE_BLOCKED_TO_N, - tag, 2, 0); + blocked = make_resource_x_master_frame(RESOURCE_X_WIRE_BLOCKED_TO_N, tag, 2, 0); blocked.common.observed_mode = PCM_STATE_X; blocked.common.target_mode = PCM_STATE_N; blocked.common.outcome = RESOURCE_X_OUTCOME_OK; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_blocked_to_n_exact(&blocked, 0, - &snapshot), + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_blocked_to_n_exact(&blocked, 0, &snapshot), RESOURCE_X_APPLY_BAD_STATE); UT_ASSERT_EQ(snapshot.phase, RESOURCE_X_MASTER_WAIT_BLOCKERS); UT_ASSERT_EQ(snapshot.incompatible_holders_bitmap, UINT32_C(1)); @@ -11561,26 +10972,22 @@ UT_TEST(test_resource_x_master_remote_proof_is_retained_not_inferred) blocked.body.blocked_to_n.dependencies[1] = 66; blocked.body.blocked_to_n.source_proof_crc32c = UINT32_C(0x11223344); blocked.body.blocked_to_n.page_checksum = UINT32_C(0x55667788); - blocked.body.blocked_to_n.source_disposition - = RESOURCE_X_DISPOSITION_REMOTE_NONWRITABLE; + blocked.body.blocked_to_n.source_disposition = RESOURCE_X_DISPOSITION_REMOTE_NONWRITABLE; blocked.body.blocked_to_n.proof_kind = RESOURCE_X_PROOF_REMOTE_CARRIER; blocked.body.blocked_to_n.holder_connection_generation = 64; - blocked.body.blocked_to_n.acting_formation - = blocked.common.resource_formation; + blocked.body.blocked_to_n.acting_formation = blocked.common.resource_formation; /* A forged predecessor/base cannot consume the blocker or advance GRD. * The exact type-17 ingress below is the sole X->N + grant edge. */ changed = blocked; changed.common.base_authority_generation++; changed.common.authority_generation++; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_blocked_to_n_exact(&changed, 0, - &snapshot), + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_blocked_to_n_exact(&changed, 0, &snapshot), RESOURCE_X_APPLY_STALE); UT_ASSERT_EQ(snapshot.phase, RESOURCE_X_MASTER_WAIT_BLOCKERS); UT_ASSERT_EQ(snapshot.blocked_holders_bitmap, 0); UT_ASSERT_EQ(snapshot.final_authority_generation, 0); UT_ASSERT_EQ(cluster_pcm_lock_query(tag), PCM_LOCK_MODE_X); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_blocked_to_n_exact(&blocked, 0, - &snapshot), + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_blocked_to_n_exact(&blocked, 0, &snapshot), RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(snapshot.phase, RESOURCE_X_MASTER_GRANT_COMMITTED); UT_ASSERT_EQ(snapshot.incompatible_holders_bitmap, UINT32_C(1)); @@ -11592,12 +10999,13 @@ UT_TEST(test_resource_x_master_remote_proof_is_retained_not_inferred) /* Exact X->N+PI followed by N->X advances the bridged authority twice. */ UT_ASSERT_EQ(snapshot.final_authority_generation, 3); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_authority_grant_exact( - &assertion.common.logical_assertion, &grant), RESOURCE_X_APPLY_APPLIED); + &assertion.common.logical_assertion, &grant), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT(cluster_pcm_lock_authority_snapshot(tag, &authority_before)); UT_ASSERT_EQ(grant.kind, RESOURCE_X_WIRE_AUTHORITY_GRANT); UT_ASSERT_EQ(grant.payload_bytes, RESOURCE_X_PROOF_V1_BYTES); UT_ASSERT(resource_x_assertion_equal(&grant.common.logical_assertion, - &assertion.common.logical_assertion)); + &assertion.common.logical_assertion)); UT_ASSERT_EQ(grant.common.base_authority_generation, 1); UT_ASSERT_EQ(grant.common.resource_formation, 17); UT_ASSERT_EQ(grant.common.master_session_incarnation, 31); @@ -11606,12 +11014,12 @@ UT_TEST(test_resource_x_master_remote_proof_is_retained_not_inferred) UT_ASSERT_EQ(grant.common.action_node, 2); UT_ASSERT_EQ(grant.common.target_mode, PCM_STATE_X); UT_ASSERT_EQ(grant.common.outcome, RESOURCE_X_OUTCOME_OK); - UT_ASSERT_EQ(grant.common.flags, - RESOURCE_X_COMMON_FLAG_REMOTE_IMAGE_REQUIRED); + UT_ASSERT_EQ(grant.common.flags, RESOURCE_X_COMMON_FLAG_REMOTE_IMAGE_REQUIRED); UT_ASSERT_EQ(grant.common.authority_generation, 3); UT_ASSERT_EQ(memcmp(grant.body.authority_grant.source_fence, - blocked.body.blocked_to_n.source_fence, - sizeof(grant.body.authority_grant.source_fence)), 0); + blocked.body.blocked_to_n.source_fence, + sizeof(grant.body.authority_grant.source_fence)), + 0); UT_ASSERT_EQ(grant.body.authority_grant.final_authority_generation, 3); UT_ASSERT_EQ(grant.body.authority_grant.source_carrier_generation, 61); UT_ASSERT_EQ(grant.body.authority_grant.requester_target_generation, 41); @@ -11619,65 +11027,51 @@ UT_TEST(test_resource_x_master_remote_proof_is_retained_not_inferred) UT_ASSERT_EQ(grant.body.authority_grant.dependency_count, 2); UT_ASSERT_EQ(grant.body.authority_grant.dependencies[0], 65); UT_ASSERT_EQ(grant.body.authority_grant.dependencies[1], 66); - UT_ASSERT_EQ(grant.body.authority_grant.source_proof_crc32c, - UINT32_C(0x11223344)); - UT_ASSERT_EQ(grant.body.authority_grant.page_checksum, - UINT32_C(0x55667788)); - UT_ASSERT_EQ(grant.body.authority_grant.proof_kind, - RESOURCE_X_PROOF_REMOTE_CARRIER); + UT_ASSERT_EQ(grant.body.authority_grant.source_proof_crc32c, UINT32_C(0x11223344)); + UT_ASSERT_EQ(grant.body.authority_grant.page_checksum, UINT32_C(0x55667788)); + UT_ASSERT_EQ(grant.body.authority_grant.proof_kind, RESOURCE_X_PROOF_REMOTE_CARRIER); UT_ASSERT_EQ(grant.body.authority_grant.source_disposition, - RESOURCE_X_DISPOSITION_REMOTE_NONWRITABLE); - UT_ASSERT_EQ(grant.body.authority_grant.requester_connection_generation, - 51); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_blocked_to_n_exact(&blocked, 0, - &snapshot), + RESOURCE_X_DISPOSITION_REMOTE_NONWRITABLE); + UT_ASSERT_EQ(grant.body.authority_grant.requester_connection_generation, 51); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_blocked_to_n_exact(&blocked, 0, &snapshot), RESOURCE_X_APPLY_DUPLICATE); changed = blocked; changed.body.blocked_to_n.source_fence[0] ^= UINT8_C(1); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_blocked_to_n_exact(&changed, 0, - &snapshot), + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_blocked_to_n_exact(&changed, 0, &snapshot), RESOURCE_X_APPLY_STALE); changed = blocked; changed.body.blocked_to_n.page_scn_lsn++; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_blocked_to_n_exact(&changed, 0, - &snapshot), + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_blocked_to_n_exact(&changed, 0, &snapshot), RESOURCE_X_APPLY_STALE); changed = blocked; changed.body.blocked_to_n.source_proof_crc32c++; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_blocked_to_n_exact(&changed, 0, - &snapshot), + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_blocked_to_n_exact(&changed, 0, &snapshot), RESOURCE_X_APPLY_STALE); changed = blocked; changed.body.blocked_to_n.page_checksum++; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_blocked_to_n_exact(&changed, 0, - &snapshot), + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_blocked_to_n_exact(&changed, 0, &snapshot), RESOURCE_X_APPLY_STALE); changed = blocked; changed.body.blocked_to_n.holder_connection_generation++; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_blocked_to_n_exact(&changed, 0, - &snapshot), + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_blocked_to_n_exact(&changed, 0, &snapshot), RESOURCE_X_APPLY_STALE); changed = blocked; changed.body.blocked_to_n.acting_formation++; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_blocked_to_n_exact(&changed, 0, - &snapshot), + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_blocked_to_n_exact(&changed, 0, &snapshot), RESOURCE_X_APPLY_STALE); UT_ASSERT(cluster_pcm_lock_authority_snapshot(tag, &authority_after)); - UT_ASSERT_EQ(memcmp(&authority_before, &authority_after, - sizeof(authority_before)), 0); + UT_ASSERT_EQ(memcmp(&authority_before, &authority_after, sizeof(authority_before)), 0); /* Grant commit is an immutable authority boundary. The production * function must validate the complete retained blocker set before it can * reach the holder-transition path. */ source = read_text_file(PCM_LOCK_SOURCE_PATH); UT_ASSERT_NOT_NULL(source); - function_start = strstr(source, - "cluster_pcm_lock_resource_x_blocked_to_n_exact("); + function_start = strstr(source, "cluster_pcm_lock_resource_x_blocked_to_n_exact("); UT_ASSERT_NOT_NULL(function_start); - post_grant_guard = strstr(function_start, - "pcm_resource_x_post_grant_blocker_state_exact"); + post_grant_guard = strstr(function_start, "pcm_resource_x_post_grant_blocker_state_exact"); UT_ASSERT_NOT_NULL(post_grant_guard); - holder_transition = strstr(function_start, "direct_x_source\n\t\t="); + holder_transition = strstr(function_start, "direct_x_source ="); UT_ASSERT_NOT_NULL(holder_transition); UT_ASSERT(post_grant_guard < holder_transition); free(source); @@ -11692,16 +11086,15 @@ UT_TEST(test_resource_x_master_remote_proof_is_retained_not_inferred) cluster_node_id = 0; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), RESOURCE_X_APPLY_APPLIED); - assertion = make_resource_x_master_frame(RESOURCE_X_WIRE_ASSERT_X, - s_tag, 2, 2); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact(&assertion, 2, - &snapshot), RESOURCE_X_APPLY_APPLIED); + assertion = make_resource_x_master_frame(RESOURCE_X_WIRE_ASSERT_X, s_tag, 2, 2); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact(&assertion, 2, &snapshot), + RESOURCE_X_APPLY_APPLIED); blocked.common.logical_assertion = assertion.common.logical_assertion; blocked.common.action_node = 1; blocked.common.observed_mode = PCM_STATE_S; blocked.body.blocked_to_n.source_fence[28] = PCM_STATE_S; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_blocked_to_n_exact(&blocked, 1, - &snapshot), RESOURCE_X_APPLY_BAD_STATE); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_blocked_to_n_exact(&blocked, 1, &snapshot), + RESOURCE_X_APPLY_BAD_STATE); UT_ASSERT_EQ(cluster_pcm_lock_query(s_tag), PCM_LOCK_MODE_S); UT_ASSERT_EQ(snapshot.phase, RESOURCE_X_MASTER_WAIT_BLOCKERS); UT_ASSERT_EQ(snapshot.proof_kind, 0); @@ -11719,24 +11112,23 @@ UT_TEST(test_resource_x_blocked_to_n_exact_clear_rejects_generation_drift) cluster_node_id = 0; cluster_pcm_lock_acquire(tag, PCM_LOCK_MODE_X); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), - RESOURCE_X_APPLY_APPLIED); - assertion = make_resource_x_master_frame( - RESOURCE_X_WIRE_ASSERT_X, tag, 2, 2); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact( - &assertion, 2, &snapshot), RESOURCE_X_APPLY_APPLIED); + RESOURCE_X_APPLY_APPLIED); + assertion = make_resource_x_master_frame(RESOURCE_X_WIRE_ASSERT_X, tag, 2, 2); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact(&assertion, 2, &snapshot), + RESOURCE_X_APPLY_APPLIED); blocked = make_resource_x_remote_blocked_frame(tag, 2, 0); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_blocked_to_n_exact( - &blocked, 0, &snapshot), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_blocked_to_n_exact(&blocked, 0, &snapshot), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(snapshot.phase, RESOURCE_X_MASTER_GRANT_COMMITTED); UT_ASSERT_EQ(snapshot.blocked_holders_bitmap, UINT32_C(1)); changed = blocked; changed.body.blocked_to_n.acting_formation++; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_blocked_to_n_exact( - &changed, 0, &snapshot), RESOURCE_X_APPLY_STALE); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_blocked_to_n_exact(&changed, 0, &snapshot), + RESOURCE_X_APPLY_STALE); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_master_snapshot_exact( - &assertion.common.logical_assertion, &snapshot), - RESOURCE_X_APPLY_APPLIED); + &assertion.common.logical_assertion, &snapshot), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(snapshot.phase, RESOURCE_X_MASTER_GRANT_COMMITTED); UT_ASSERT_EQ(snapshot.blocked_holders_bitmap, UINT32_C(1)); } @@ -11757,27 +11149,24 @@ UT_TEST(test_resource_x_type18_wire_decode_drives_master_exact_apply) cluster_node_id = 0; cluster_pcm_lock_acquire(tag, PCM_LOCK_MODE_X); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), - RESOURCE_X_APPLY_APPLIED); - assertion = make_resource_x_master_frame( - RESOURCE_X_WIRE_ASSERT_X, tag, 2, 2); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact( - &assertion, 2, &snapshot), RESOURCE_X_APPLY_APPLIED); + RESOURCE_X_APPLY_APPLIED); + assertion = make_resource_x_master_frame(RESOURCE_X_WIRE_ASSERT_X, tag, 2, 2); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact(&assertion, 2, &snapshot), + RESOURCE_X_APPLY_APPLIED); blocked = make_resource_x_remote_blocked_frame(tag, 2, 0); - UT_ASSERT(cluster_resource_x_wire_encode( - RESOURCE_X_MSG_BLOCKED_TO_N, &blocked, payload, sizeof(payload), - &payload_bytes, &reject)); + UT_ASSERT(cluster_resource_x_wire_encode(RESOURCE_X_MSG_BLOCKED_TO_N, &blocked, payload, + sizeof(payload), &payload_bytes, &reject)); UT_ASSERT_EQ(payload_bytes, RESOURCE_X_PROOF_V1_BYTES); - UT_ASSERT(cluster_resource_x_wire_decode( - RESOURCE_X_MSG_BLOCKED_TO_N, payload, payload_bytes, &decoded, - &reject)); + UT_ASSERT(cluster_resource_x_wire_decode(RESOURCE_X_MSG_BLOCKED_TO_N, payload, payload_bytes, + &decoded, &reject)); UT_ASSERT_EQ(decoded.kind, RESOURCE_X_WIRE_BLOCKED_TO_N); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_blocked_to_n_exact( - &decoded, 0, &snapshot), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_blocked_to_n_exact(&decoded, 0, &snapshot), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(snapshot.phase, RESOURCE_X_MASTER_GRANT_COMMITTED); UT_ASSERT_EQ(snapshot.blocked_holders_bitmap, UINT32_C(1)); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_authority_grant_exact( - &assertion.common.logical_assertion, &grant), - RESOURCE_X_APPLY_APPLIED); + &assertion.common.logical_assertion, &grant), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(grant.kind, RESOURCE_X_WIRE_AUTHORITY_GRANT); } @@ -11799,39 +11188,35 @@ UT_TEST(test_resource_x_type18_releases_direct_old_x_request_and_tracks_exact_ge cluster_node_id = 0; cluster_pcm_lock_acquire(tag, PCM_LOCK_MODE_S); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), - RESOURCE_X_APPLY_APPLIED); - first_assert = make_resource_x_master_frame( - RESOURCE_X_WIRE_ASSERT_X, tag, 0, 0); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact( - &first_assert, 0, &snapshot), RESOURCE_X_APPLY_APPLIED); + RESOURCE_X_APPLY_APPLIED); + first_assert = make_resource_x_master_frame(RESOURCE_X_WIRE_ASSERT_X, tag, 0, 0); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact(&first_assert, 0, &snapshot), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(snapshot.phase, RESOURCE_X_MASTER_WAIT_PROOF); - local_proof = make_resource_x_master_frame( - RESOURCE_X_WIRE_LOCAL_PROOF_DECLARATION, tag, 0, 0); + local_proof = make_resource_x_master_frame(RESOURCE_X_WIRE_LOCAL_PROOF_DECLARATION, tag, 0, 0); local_proof.common.observed_mode = PCM_STATE_S; local_proof.common.outcome = RESOURCE_X_OUTCOME_OK; local_proof.body.local_proof.local_holder_authority_generation = 71; local_proof.body.local_proof.requester_target_generation = 41; local_proof.body.local_proof.page_scn_lsn = 82; local_proof.body.local_proof.page_checksum = UINT32_C(0x55667788); - local_proof.body.local_proof.local_image_proof_crc32c - = UINT32_C(0x99aabbcc); + local_proof.body.local_proof.local_image_proof_crc32c = UINT32_C(0x99aabbcc); local_proof.body.local_proof.requester_connection_generation = 73; local_proof.body.local_proof.local_proof_generation = 74; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_local_proof_exact( - &local_proof, 0, &snapshot), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_local_proof_exact(&local_proof, 0, &snapshot), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(snapshot.phase, RESOURCE_X_MASTER_GRANT_COMMITTED); UT_ASSERT_EQ(snapshot.final_authority_generation, 2); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_grant_intent_snapshot_exact( - &first_assert.common.logical_assertion, &grant_intent, grant_bytes, - sizeof(grant_bytes)), RESOURCE_X_APPLY_APPLIED); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_grant_intent_stage_exact( - &grant_intent, 101), RESOURCE_X_INTENT_STAGED); - UT_ASSERT(cluster_pcm_lock_resource_x_grant_intent_complete_exact( - &grant_intent)); - - settlement = make_resource_x_master_frame( - RESOURCE_X_WIRE_INSTALL_SETTLEMENT, tag, 0, 0); + &first_assert.common.logical_assertion, &grant_intent, grant_bytes, + sizeof(grant_bytes)), + RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_grant_intent_stage_exact(&grant_intent, 101), + RESOURCE_X_INTENT_STAGED); + UT_ASSERT(cluster_pcm_lock_resource_x_grant_intent_complete_exact(&grant_intent)); + + settlement = make_resource_x_master_frame(RESOURCE_X_WIRE_INSTALL_SETTLEMENT, tag, 0, 0); settlement.common.outcome = RESOURCE_X_OUTCOME_OK; settlement.common.authority_generation = 2; settlement.body.install_settlement.conversion_base_generation = 1; @@ -11840,26 +11225,21 @@ UT_TEST(test_resource_x_type18_releases_direct_old_x_request_and_tracks_exact_ge settlement.body.install_settlement.requester_target_generation = 41; settlement.body.install_settlement.page_scn_lsn = 82; settlement.body.install_settlement.page_checksum = UINT32_C(0x55667788); - settlement.body.install_settlement.source_proof_crc32c - = UINT32_C(0x99aabbcc); + settlement.body.install_settlement.source_proof_crc32c = UINT32_C(0x99aabbcc); settlement.body.install_settlement.installed_mode = PCM_STATE_X; - settlement.body.install_settlement.requester_role - = RESOURCE_X_REQUESTER_ROLE_ACQUIRER; - settlement.body.install_settlement.terminal_outcome - = RESOURCE_X_OUTCOME_OK; - settlement.body.install_settlement.terminal_state - = RESOURCE_X_SETTLEMENT_TERMINAL_INSTALLED; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_install_settlement_exact( - &settlement, 0, &snapshot), RESOURCE_X_APPLY_APPLIED); + settlement.body.install_settlement.requester_role = RESOURCE_X_REQUESTER_ROLE_ACQUIRER; + settlement.body.install_settlement.terminal_outcome = RESOURCE_X_OUTCOME_OK; + settlement.body.install_settlement.terminal_state = RESOURCE_X_SETTLEMENT_TERMINAL_INSTALLED; + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_install_settlement_exact(&settlement, 0, &snapshot), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(snapshot.phase, RESOURCE_X_MASTER_SETTLED); - second_assert = make_resource_x_master_frame( - RESOURCE_X_WIRE_ASSERT_X, tag, 2, 2); + second_assert = make_resource_x_master_frame(RESOURCE_X_WIRE_ASSERT_X, tag, 2, 2); second_assert.common.base_authority_generation = 2; second_assert.common.authority_generation = 2; second_assert.common.assertion_sequence = 42; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact( - &second_assert, 2, &snapshot), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact(&second_assert, 2, &snapshot), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(snapshot.phase, RESOURCE_X_MASTER_WAIT_BLOCKERS); UT_ASSERT_EQ(snapshot.incompatible_holders_bitmap, UINT32_C(1)); @@ -11868,25 +11248,23 @@ UT_TEST(test_resource_x_type18_releases_direct_old_x_request_and_tracks_exact_ge blocked.common.authority_generation = 2; blocked.common.assertion_sequence = 42; blocked.body.blocked_to_n.requester_target_generation = 42; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_blocked_to_n_exact( - &blocked, 0, &snapshot), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_blocked_to_n_exact(&blocked, 0, &snapshot), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(snapshot.phase, RESOURCE_X_MASTER_GRANT_COMMITTED); UT_ASSERT(cluster_pcm_lock_authority_snapshot(tag, &authority)); UT_ASSERT_EQ(authority.state, PCM_STATE_X); UT_ASSERT_EQ(authority.x_holder_node, 2); UT_ASSERT_EQ(authority.transition_count, 4); - UT_ASSERT_EQ(snapshot.final_authority_generation, - authority.transition_count); + UT_ASSERT_EQ(snapshot.final_authority_generation, authority.transition_count); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_master_snapshot_exact( - &first_assert.common.logical_assertion, &old_snapshot), - RESOURCE_X_APPLY_APPLIED); + &first_assert.common.logical_assertion, &old_snapshot), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(old_snapshot.phase, RESOURCE_X_MASTER_RELEASED); } static void -make_resource_x_remote_join_pair(BufferTag tag, int32 requester_node, - ResourceXDecodedFrame *grant, - ResourceXDecodedFrame *image) +make_resource_x_remote_join_pair(BufferTag tag, int32 requester_node, ResourceXDecodedFrame *grant, + ResourceXDecodedFrame *image) { ResourceXDecodedFrame decoded_image; ResourceXWireReject reject = RESOURCE_X_WIRE_REJECT_NONE; @@ -11894,16 +11272,15 @@ make_resource_x_remote_join_pair(BufferTag tag, int32 requester_node, uint16 image_payload_bytes = 0; int i; - *grant = make_resource_x_master_frame( - RESOURCE_X_WIRE_AUTHORITY_GRANT, tag, requester_node, - requester_node); + *grant = make_resource_x_master_frame(RESOURCE_X_WIRE_AUTHORITY_GRANT, tag, requester_node, + requester_node); grant->common.outcome = RESOURCE_X_OUTCOME_OK; grant->common.flags = RESOURCE_X_COMMON_FLAG_REMOTE_IMAGE_REQUIRED; grant->common.authority_generation = 3; memset(grant->body.authority_grant.source_fence, 0x5a, sizeof(grant->body.authority_grant.source_fence)); - set_resource_x_test_source_fence( - grant->body.authority_grant.source_fence, UINT64_C(60), PCM_STATE_X); + set_resource_x_test_source_fence(grant->body.authority_grant.source_fence, UINT64_C(60), + PCM_STATE_X); grant->body.authority_grant.final_authority_generation = 3; grant->body.authority_grant.source_carrier_generation = 61; grant->body.authority_grant.requester_target_generation = 41; @@ -11911,18 +11288,14 @@ make_resource_x_remote_join_pair(BufferTag tag, int32 requester_node, grant->body.authority_grant.dependency_count = 2; grant->body.authority_grant.dependencies[0] = 65; grant->body.authority_grant.dependencies[1] = 66; - grant->body.authority_grant.source_proof_crc32c - = UINT32_C(0x11223344); + grant->body.authority_grant.source_proof_crc32c = UINT32_C(0x11223344); grant->body.authority_grant.page_checksum = UINT32_C(0x55667788); - grant->body.authority_grant.proof_kind - = RESOURCE_X_PROOF_REMOTE_CARRIER; - grant->body.authority_grant.source_disposition - = RESOURCE_X_DISPOSITION_REMOTE_NONWRITABLE; + grant->body.authority_grant.proof_kind = RESOURCE_X_PROOF_REMOTE_CARRIER; + grant->body.authority_grant.source_disposition = RESOURCE_X_DISPOSITION_REMOTE_NONWRITABLE; grant->body.authority_grant.requester_connection_generation = 71; - *image = make_resource_x_master_frame( - RESOURCE_X_WIRE_IMAGE_ENVELOPE, tag, requester_node, - requester_node); + *image = make_resource_x_master_frame(RESOURCE_X_WIRE_IMAGE_ENVELOPE, tag, requester_node, + requester_node); image->common.observed_mode = PCM_STATE_X; image->common.outcome = RESOURCE_X_OUTCOME_OK; image->common.sender_connection_generation = UINT32_C(1); @@ -11930,41 +11303,33 @@ make_resource_x_remote_join_pair(BufferTag tag, int32 requester_node, for (i = 0; i < RESOURCE_X_REQUEST_TAIL_BYTES; i++) image->body.image_envelope.request_tail[i] = (uint8)(0x20 + i); image->body.image_envelope.conversion_base_generation = 1; - memcpy(image->body.image_envelope.source_fence, - grant->body.authority_grant.source_fence, - sizeof(image->body.image_envelope.source_fence)); + memcpy(image->body.image_envelope.source_fence, grant->body.authority_grant.source_fence, + sizeof(image->body.image_envelope.source_fence)); image->body.image_envelope.source_carrier_generation = 61; image->body.image_envelope.requester_target_generation = 41; image->body.image_envelope.page_scn_lsn = 63; image->body.image_envelope.dependency_count = 2; image->body.image_envelope.dependencies[0] = 65; image->body.image_envelope.dependencies[1] = 66; - image->body.image_envelope.dependency_vector_crc32c - = UINT32_C(0x99aabbcc); + image->body.image_envelope.dependency_vector_crc32c = UINT32_C(0x99aabbcc); image->body.image_envelope.page_checksum = UINT32_C(0x55667788); image->body.image_envelope.image_length = RESOURCE_X_PAGE_BYTES; - image->body.image_envelope.source_disposition - = RESOURCE_X_DISPOSITION_REMOTE_NONWRITABLE; - image->body.image_envelope.proof_kind - = RESOURCE_X_PROOF_REMOTE_CARRIER; + image->body.image_envelope.source_disposition = RESOURCE_X_DISPOSITION_REMOTE_NONWRITABLE; + image->body.image_envelope.proof_kind = RESOURCE_X_PROOF_REMOTE_CARRIER; for (i = 0; i < RESOURCE_X_PAGE_BYTES; i++) image->body.image_envelope.page_bytes[i] = (uint8)(i * 37); - UT_ASSERT(cluster_resource_x_wire_encode( - RESOURCE_X_MSG_IMAGE_OR_GRANT, image, image_payload, - sizeof(image_payload), &image_payload_bytes, &reject)); + UT_ASSERT(cluster_resource_x_wire_encode(RESOURCE_X_MSG_IMAGE_OR_GRANT, image, image_payload, + sizeof(image_payload), &image_payload_bytes, &reject)); UT_ASSERT_EQ(image_payload_bytes, RESOURCE_X_IMAGE_V1_BYTES); - UT_ASSERT(cluster_resource_x_wire_decode( - RESOURCE_X_MSG_IMAGE_OR_GRANT, image_payload, image_payload_bytes, - &decoded_image, &reject)); + UT_ASSERT(cluster_resource_x_wire_decode(RESOURCE_X_MSG_IMAGE_OR_GRANT, image_payload, + image_payload_bytes, &decoded_image, &reject)); *image = decoded_image; - grant->body.authority_grant.source_proof_crc32c - = image->common.semantic_crc32c; + grant->body.authority_grant.source_proof_crc32c = image->common.semantic_crc32c; } static void make_resource_x_s_remote_join_pair(BufferTag tag, int32 requester_node, - ResourceXDecodedFrame *grant, - ResourceXDecodedFrame *image) + ResourceXDecodedFrame *grant, ResourceXDecodedFrame *image) { ResourceXDecodedFrame canonical_image; ResourceXWireReject reject = RESOURCE_X_WIRE_REJECT_NONE; @@ -11975,21 +11340,18 @@ make_resource_x_s_remote_join_pair(BufferTag tag, int32 requester_node, grant->body.authority_grant.source_fence[28] = PCM_STATE_S; image->common.observed_mode = PCM_STATE_S; image->body.image_envelope.source_fence[28] = PCM_STATE_S; - UT_ASSERT(cluster_resource_x_wire_encode( - RESOURCE_X_MSG_IMAGE_OR_GRANT, image, image_payload, - sizeof(image_payload), &image_payload_bytes, &reject)); - UT_ASSERT(cluster_resource_x_wire_decode( - RESOURCE_X_MSG_IMAGE_OR_GRANT, image_payload, image_payload_bytes, - &canonical_image, &reject)); + UT_ASSERT(cluster_resource_x_wire_encode(RESOURCE_X_MSG_IMAGE_OR_GRANT, image, image_payload, + sizeof(image_payload), &image_payload_bytes, &reject)); + UT_ASSERT(cluster_resource_x_wire_decode(RESOURCE_X_MSG_IMAGE_OR_GRANT, image_payload, + image_payload_bytes, &canonical_image, &reject)); *image = canonical_image; - grant->body.authority_grant.source_proof_crc32c - = image->common.semantic_crc32c; + grant->body.authority_grant.source_proof_crc32c = image->common.semantic_crc32c; } static void -retarget_resource_x_remote_join_pair( - ResourceXDecodedFrame *grant, ResourceXDecodedFrame *image, - uint64 final_authority_generation, uint64 requester_target_generation) +retarget_resource_x_remote_join_pair(ResourceXDecodedFrame *grant, ResourceXDecodedFrame *image, + uint64 final_authority_generation, + uint64 requester_target_generation) { ResourceXDecodedFrame decoded_image; ResourceXWireReject reject = RESOURCE_X_WIRE_REJECT_NONE; @@ -12000,26 +11362,19 @@ retarget_resource_x_remote_join_pair( grant->common.base_authority_generation = final_authority_generation - 2; grant->common.authority_generation = final_authority_generation; grant->common.assertion_sequence = requester_target_generation; - grant->body.authority_grant.final_authority_generation - = final_authority_generation; - grant->body.authority_grant.requester_target_generation - = requester_target_generation; + grant->body.authority_grant.final_authority_generation = final_authority_generation; + grant->body.authority_grant.requester_target_generation = requester_target_generation; image->common.base_authority_generation = final_authority_generation - 2; image->common.authority_generation = final_authority_generation - 1; image->common.assertion_sequence = requester_target_generation; - image->body.image_envelope.conversion_base_generation - = final_authority_generation - 2; - image->body.image_envelope.requester_target_generation - = requester_target_generation; - UT_ASSERT(cluster_resource_x_wire_encode( - RESOURCE_X_MSG_IMAGE_OR_GRANT, image, image_payload, - sizeof(image_payload), &image_payload_bytes, &reject)); - UT_ASSERT(cluster_resource_x_wire_decode( - RESOURCE_X_MSG_IMAGE_OR_GRANT, image_payload, image_payload_bytes, - &decoded_image, &reject)); + image->body.image_envelope.conversion_base_generation = final_authority_generation - 2; + image->body.image_envelope.requester_target_generation = requester_target_generation; + UT_ASSERT(cluster_resource_x_wire_encode(RESOURCE_X_MSG_IMAGE_OR_GRANT, image, image_payload, + sizeof(image_payload), &image_payload_bytes, &reject)); + UT_ASSERT(cluster_resource_x_wire_decode(RESOURCE_X_MSG_IMAGE_OR_GRANT, image_payload, + image_payload_bytes, &decoded_image, &reject)); *image = decoded_image; - grant->body.authority_grant.source_proof_crc32c - = image->common.semantic_crc32c; + grant->body.authority_grant.source_proof_crc32c = image->common.semantic_crc32c; } static void @@ -12030,13 +11385,11 @@ canonicalize_resource_x_test_image(ResourceXDecodedFrame *image) uint8 payload[RESOURCE_X_IMAGE_V1_BYTES]; uint16 payload_bytes = 0; - UT_ASSERT(cluster_resource_x_wire_encode( - RESOURCE_X_MSG_IMAGE_OR_GRANT, image, payload, sizeof(payload), - &payload_bytes, &reject)); + UT_ASSERT(cluster_resource_x_wire_encode(RESOURCE_X_MSG_IMAGE_OR_GRANT, image, payload, + sizeof(payload), &payload_bytes, &reject)); UT_ASSERT_EQ(payload_bytes, RESOURCE_X_IMAGE_V1_BYTES); - UT_ASSERT(cluster_resource_x_wire_decode( - RESOURCE_X_MSG_IMAGE_OR_GRANT, payload, payload_bytes, - &decoded, &reject)); + UT_ASSERT(cluster_resource_x_wire_decode(RESOURCE_X_MSG_IMAGE_OR_GRANT, payload, payload_bytes, + &decoded, &reject)); *image = decoded; } @@ -12068,25 +11421,24 @@ setup_resource_x_test_terminal_cover_at_base(BufferTag tag, uint64 cached_genera UT_ASSERT_EQ(action, RESOURCE_X_BOOTSTRAP_ROUND_DISPATCH_ASSERT); make_resource_x_remote_join_pair(tag, 1, &grant, &image); retarget_resource_x_remote_join_pair(&grant, &image, canonical_base + 2, UINT64_C(1)); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact( - &image, 0, &join), RESOURCE_X_APPLY_APPLIED); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact( - &grant, 0, &join), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact(&image, 0, &join), + RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact(&grant, 0, &join), + RESOURCE_X_APPLY_APPLIED); ref = make_resource_x_acquisition_ref(tag, 1, 17, 1); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_t1_grant_exact(&ref), - RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_t1_grant_exact(&ref), RESOURCE_X_APPLY_APPLIED); memset(&install, 0, sizeof(install)); install.ownership_generation = cached_generation; install.writer_activation_token = 12; install.resource_x_activation_generation = 1; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_apply_exact( - &ref, &install), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_apply_exact(&ref, &install), + RESOURCE_X_APPLY_APPLIED); memset(&activation, 0, sizeof(activation)); activation.ownership_generation = cached_generation; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_activate_exact( - &ref, &activation), RESOURCE_X_APPLY_APPLIED); - UT_ASSERT(cluster_pcm_lock_resource_x_bootstrap_round_cover_matches_exact( - &ref, 31, 77, cached_generation)); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_activate_exact(&ref, &activation), + RESOURCE_X_APPLY_APPLIED); + UT_ASSERT(cluster_pcm_lock_resource_x_bootstrap_round_cover_matches_exact(&ref, 31, 77, + cached_generation)); return ref; } @@ -12114,8 +11466,7 @@ retain_resource_x_test_settlement_pair_at_attempt(BufferTag tag, uint8 source_mo uint8 image_payload[RESOURCE_X_IMAGE_V1_BYTES]; uint8 status_payload[RESOURCE_X_PROOF_V1_BYTES]; - block = make_resource_x_master_frame( - RESOURCE_X_WIRE_BLOCK_TO_N, tag, 2, 1); + block = make_resource_x_master_frame(RESOURCE_X_WIRE_BLOCK_TO_N, tag, 2, 1); block.common.assertion_sequence = attempt; block.common.base_authority_generation = final_authority_generation - 2; block.common.authority_generation = final_authority_generation - 2; @@ -12128,11 +11479,9 @@ retain_resource_x_test_settlement_pair_at_attempt(BufferTag tag, uint8 source_mo retarget_resource_x_remote_join_pair(&grant, &image, final_authority_generation, attempt); image.common.ordered_lane = 0; image.common.observed_mode = source_mode; - set_resource_x_test_source_fence( - image.body.image_envelope.source_fence, - source_generation, source_mode); - image.body.image_envelope.source_carrier_generation - = carrier_generation; + set_resource_x_test_source_fence(image.body.image_envelope.source_fence, source_generation, + source_mode); + image.body.image_envelope.source_carrier_generation = carrier_generation; if (source_mode == (uint8)PCM_STATE_S) ((PageHeader)image.body.image_envelope.page_bytes)->pd_block_scn = image.body.image_envelope.page_scn_lsn; @@ -12144,16 +11493,14 @@ retain_resource_x_test_settlement_pair_at_attempt(BufferTag tag, uint8 source_mo status.common.authority_generation = final_authority_generation - 2; status.common.ordered_lane = 0; status.common.observed_mode = source_mode; - memcpy(status.body.blocked_to_n.source_fence, - image.body.image_envelope.source_fence, - sizeof(status.body.blocked_to_n.source_fence)); - status.body.blocked_to_n.source_carrier_generation - = carrier_generation; - status.body.blocked_to_n.source_proof_crc32c - = image.common.semantic_crc32c; + memcpy(status.body.blocked_to_n.source_fence, image.body.image_envelope.source_fence, + sizeof(status.body.blocked_to_n.source_fence)); + status.body.blocked_to_n.source_carrier_generation = carrier_generation; + status.body.blocked_to_n.source_proof_crc32c = image.common.semantic_crc32c; if (source_mode == (uint8)PCM_STATE_X) { - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_block_to_n_source_exact( - &block, 0, &status, &image), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ( + cluster_pcm_lock_resource_x_block_to_n_source_exact(&block, 0, &status, &image), + RESOURCE_X_APPLY_APPLIED); } else { memset(&prepared, 0, sizeof(prepared)); prepared.tag = tag; @@ -12161,35 +11508,33 @@ retain_resource_x_test_settlement_pair_at_attempt(BufferTag tag, uint8 source_mo prepared.reservation_token = 77; prepared.flags = PCM_OWN_FLAG_REVOKING; prepared.pcm_state = PCM_STATE_S; - UT_ASSERT_EQ( - cluster_pcm_lock_resource_x_block_to_n_prepared_s_source_exact( - &block, 0, &status, &image, &prepared, - PageGetLSN((Page)image.body.image_envelope.page_bytes), - image.body.image_envelope.page_scn_lsn, - image.body.image_envelope.page_checksum), - RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_block_to_n_prepared_s_source_exact( + &block, 0, &status, &image, &prepared, + PageGetLSN((Page)image.body.image_envelope.page_bytes), + image.body.image_envelope.page_scn_lsn, + image.body.image_envelope.page_checksum), + RESOURCE_X_APPLY_APPLIED); } UT_ASSERT_EQ(cluster_pcm_lock_resource_x_holder_pair_publish_exact( - &block.common.logical_assertion, block.common.assertion_sequence, - 0, block.common.master_session_incarnation), - RESOURCE_X_APPLY_APPLIED); + &block.common.logical_assertion, block.common.assertion_sequence, 0, + block.common.master_session_incarnation), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_holder_status_intent_snapshot_exact( - &block.common.logical_assertion, &status_intent, status_payload, - sizeof(status_payload)), RESOURCE_X_APPLY_APPLIED); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_holder_image_intent_snapshot_exact( - &block.common.logical_assertion, &image_intent, image_payload, - sizeof(image_payload)), RESOURCE_X_APPLY_APPLIED); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_outbound_intent_stage_exact( - &status_intent, 105), RESOURCE_X_INTENT_STAGED); - UT_ASSERT(cluster_pcm_lock_resource_x_outbound_intent_complete_exact( - &status_intent)); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_outbound_intent_stage_exact( - &image_intent, 106), RESOURCE_X_INTENT_STAGED); - UT_ASSERT(cluster_pcm_lock_resource_x_outbound_intent_complete_exact( - &image_intent)); - UT_ASSERT(cluster_resource_x_wire_decode( - RESOURCE_X_MSG_BLOCKED_TO_N, status_payload, - status_intent.payload_bytes, settlement_out, &reject)); + &block.common.logical_assertion, &status_intent, status_payload, + sizeof(status_payload)), + RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ( + cluster_pcm_lock_resource_x_holder_image_intent_snapshot_exact( + &block.common.logical_assertion, &image_intent, image_payload, sizeof(image_payload)), + RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_outbound_intent_stage_exact(&status_intent, 105), + RESOURCE_X_INTENT_STAGED); + UT_ASSERT(cluster_pcm_lock_resource_x_outbound_intent_complete_exact(&status_intent)); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_outbound_intent_stage_exact(&image_intent, 106), + RESOURCE_X_INTENT_STAGED); + UT_ASSERT(cluster_pcm_lock_resource_x_outbound_intent_complete_exact(&image_intent)); + UT_ASSERT(cluster_resource_x_wire_decode(RESOURCE_X_MSG_BLOCKED_TO_N, status_payload, + status_intent.payload_bytes, settlement_out, &reject)); settlement_out->kind = RESOURCE_X_WIRE_SOURCE_SETTLEMENT_V2; settlement_out->common.observed_mode = PCM_STATE_N; settlement_out->common.target_mode = PCM_STATE_N; @@ -12237,149 +11582,135 @@ UT_TEST(test_resource_x_source_settlement_prepare_closes_total_cover_table) cluster_node_id = 1; fake_gcs_master_node = 0; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), - RESOURCE_X_APPLY_APPLIED); - cover_ref = setup_resource_x_test_terminal_cover( - mismatch_x_tag, UINT64_C(60)); - retain_resource_x_test_settlement_pair( - mismatch_x_tag, PCM_STATE_X, UINT64_C(61), UINT64_C(62), UINT64_C(5), - &settlement); + RESOURCE_X_APPLY_APPLIED); + cover_ref = setup_resource_x_test_terminal_cover(mismatch_x_tag, UINT64_C(60)); + retain_resource_x_test_settlement_pair(mismatch_x_tag, PCM_STATE_X, UINT64_C(61), UINT64_C(62), + UINT64_C(5), &settlement); memset(&plan, 0x5a, sizeof(plan)); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_source_settlement_prepare_exact( - &settlement, 0, &plan), RESOURCE_X_APPLY_STALE); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_source_settlement_prepare_exact(&settlement, 0, &plan), + RESOURCE_X_APPLY_STALE); UT_ASSERT(!plan.valid); - UT_ASSERT(cluster_pcm_lock_resource_x_bootstrap_round_cover_matches_exact( - &cover_ref, 31, 77, 60)); + UT_ASSERT( + cluster_pcm_lock_resource_x_bootstrap_round_cover_matches_exact(&cover_ref, 31, 77, 60)); reset_fake_pcm_runtime(4); cluster_node_id = 1; fake_gcs_master_node = 0; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), - RESOURCE_X_APPLY_APPLIED); - cover_ref = setup_resource_x_test_terminal_cover( - s_cover_tag, UINT64_C(60)); - retain_resource_x_test_settlement_pair( - s_cover_tag, PCM_STATE_S, UINT64_C(60), UINT64_C(61), UINT64_C(5), - &settlement); + RESOURCE_X_APPLY_APPLIED); + cover_ref = setup_resource_x_test_terminal_cover(s_cover_tag, UINT64_C(60)); + retain_resource_x_test_settlement_pair(s_cover_tag, PCM_STATE_S, UINT64_C(60), UINT64_C(61), + UINT64_C(5), &settlement); memset(&plan, 0x5a, sizeof(plan)); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_source_settlement_prepare_exact( - &settlement, 0, &plan), RESOURCE_X_APPLY_RECOVERY_BLOCKED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_source_settlement_prepare_exact(&settlement, 0, &plan), + RESOURCE_X_APPLY_RECOVERY_BLOCKED); UT_ASSERT(!plan.valid); - UT_ASSERT(cluster_pcm_lock_resource_x_bootstrap_round_cover_matches_exact( - &cover_ref, 31, 77, 60)); + UT_ASSERT( + cluster_pcm_lock_resource_x_bootstrap_round_cover_matches_exact(&cover_ref, 31, 77, 60)); reset_fake_pcm_runtime(4); cluster_node_id = 1; fake_gcs_master_node = 0; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), - RESOURCE_X_APPLY_APPLIED); - retain_resource_x_test_settlement_pair( - empty_x_tag, PCM_STATE_X, UINT64_C(60), UINT64_C(61), UINT64_C(3), - &settlement); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_source_settlement_prepare_exact( - &settlement, 0, &plan), RESOURCE_X_APPLY_APPLIED); + RESOURCE_X_APPLY_APPLIED); + retain_resource_x_test_settlement_pair(empty_x_tag, PCM_STATE_X, UINT64_C(60), UINT64_C(61), + UINT64_C(3), &settlement); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_source_settlement_prepare_exact(&settlement, 0, &plan), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT(plan.valid); UT_ASSERT_EQ(plan.source_mode, (uint8)PCM_STATE_X); - UT_ASSERT_EQ(plan.cover_action, - (uint8)RESOURCE_X_SETTLEMENT_COVER_NO_COVER); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_source_settlement_commit_exact( - &settlement, 0, &plan, &observation), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(plan.cover_action, (uint8)RESOURCE_X_SETTLEMENT_COVER_NO_COVER); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_source_settlement_commit_exact(&settlement, 0, &plan, + &observation), + RESOURCE_X_APPLY_APPLIED); memset(&plan, 0x5a, sizeof(plan)); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_source_settlement_prepare_exact( - &settlement, 0, &plan), RESOURCE_X_APPLY_DUPLICATE); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_source_settlement_prepare_exact(&settlement, 0, &plan), + RESOURCE_X_APPLY_DUPLICATE); UT_ASSERT(!plan.valid); reset_fake_pcm_runtime(4); cluster_node_id = 1; fake_gcs_master_node = 0; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), - RESOURCE_X_APPLY_APPLIED); - retain_resource_x_test_settlement_pair( - empty_s_tag, PCM_STATE_S, UINT64_C(60), UINT64_C(61), UINT64_C(5), - &settlement); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_source_settlement_prepare_exact( - &settlement, 0, &plan), RESOURCE_X_APPLY_APPLIED); + RESOURCE_X_APPLY_APPLIED); + retain_resource_x_test_settlement_pair(empty_s_tag, PCM_STATE_S, UINT64_C(60), UINT64_C(61), + UINT64_C(5), &settlement); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_source_settlement_prepare_exact(&settlement, 0, &plan), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT(plan.valid); UT_ASSERT_EQ(plan.source_mode, (uint8)PCM_STATE_S); - UT_ASSERT_EQ(plan.cover_action, - (uint8)RESOURCE_X_SETTLEMENT_COVER_NO_COVER); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_source_settlement_commit_exact( - &settlement, 0, &plan, &observation), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(plan.cover_action, (uint8)RESOURCE_X_SETTLEMENT_COVER_NO_COVER); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_source_settlement_commit_exact(&settlement, 0, &plan, + &observation), + RESOURCE_X_APPLY_APPLIED); reset_fake_pcm_runtime(4); cluster_node_id = 1; fake_gcs_master_node = 0; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), - RESOURCE_X_APPLY_APPLIED); - retain_resource_x_test_settlement_pair( - new_cover_tag, PCM_STATE_X, UINT64_C(60), UINT64_C(61), UINT64_C(3), - &settlement); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_source_settlement_prepare_exact( - &settlement, 0, &plan), RESOURCE_X_APPLY_APPLIED); + RESOURCE_X_APPLY_APPLIED); + retain_resource_x_test_settlement_pair(new_cover_tag, PCM_STATE_X, UINT64_C(60), UINT64_C(61), + UINT64_C(3), &settlement); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_source_settlement_prepare_exact(&settlement, 0, &plan), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT(plan.valid); - UT_ASSERT_EQ(plan.cover_action, - (uint8)RESOURCE_X_SETTLEMENT_COVER_NO_COVER); - UT_ASSERT(resource_x_assertion_init( - &new_cover_tag, 1, &successor_assertion)); + UT_ASSERT_EQ(plan.cover_action, (uint8)RESOURCE_X_SETTLEMENT_COVER_NO_COVER); + UT_ASSERT(resource_x_assertion_init(&new_cover_tag, 1, &successor_assertion)); action = cluster_pcm_lock_resource_x_bootstrap_round_step_exact( &successor_assertion, 0, 17, 31, 77, 51, 61, UINT64_C(1000), (UINT64_C(1000)) - (UINT64_C(100)), UINT64_C(100), UINT64_C(50), false, 0, &bootstrap, &terminal_ref); - UT_ASSERT_EQ(action, - RESOURCE_X_BOOTSTRAP_ROUND_PREDECESSOR_WAIT); + UT_ASSERT_EQ(action, RESOURCE_X_BOOTSTRAP_ROUND_PREDECESSOR_WAIT); UT_ASSERT_EQ(bootstrap.kind, UINT8_C(0)); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_source_settlement_commit_exact( - &settlement, 0, &plan, &observation), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_source_settlement_commit_exact(&settlement, 0, &plan, + &observation), + RESOURCE_X_APPLY_APPLIED); reset_fake_pcm_runtime(4); cluster_node_id = 1; fake_gcs_master_node = 0; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), - RESOURCE_X_APPLY_APPLIED); - retain_resource_x_test_settlement_pair( - generation_tag, PCM_STATE_X, UINT64_C(59), UINT64_C(61), UINT64_C(3), - &settlement); + RESOURCE_X_APPLY_APPLIED); + retain_resource_x_test_settlement_pair(generation_tag, PCM_STATE_X, UINT64_C(59), UINT64_C(61), + UINT64_C(3), &settlement); memset(&plan, 0x5a, sizeof(plan)); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_source_settlement_prepare_exact( - &settlement, 0, &plan), RESOURCE_X_APPLY_INVALID); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_source_settlement_prepare_exact(&settlement, 0, &plan), + RESOURCE_X_APPLY_INVALID); UT_ASSERT(!plan.valid); - UT_ASSERT(pcm_entry_ref_acquire( - &generation_tag, false, &entry_ref, &acquire_result)); + UT_ASSERT(pcm_entry_ref_acquire(&generation_tag, false, &entry_ref, &acquire_result)); pcm_entry_ref_release(&entry_ref); reset_fake_pcm_runtime(4); cluster_node_id = 1; fake_gcs_master_node = 0; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), - RESOURCE_X_APPLY_APPLIED); - retain_resource_x_test_settlement_pair( - zero_generation_tag, PCM_STATE_X, UINT64_C(0), UINT64_C(1), - UINT64_C(3), &settlement); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_source_settlement_prepare_exact( - &settlement, 0, &plan), RESOURCE_X_APPLY_INVALID); + RESOURCE_X_APPLY_APPLIED); + retain_resource_x_test_settlement_pair(zero_generation_tag, PCM_STATE_X, UINT64_C(0), + UINT64_C(1), UINT64_C(3), &settlement); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_source_settlement_prepare_exact(&settlement, 0, &plan), + RESOURCE_X_APPLY_INVALID); UT_ASSERT(!plan.valid); reset_fake_pcm_runtime(4); cluster_node_id = 1; fake_gcs_master_node = 0; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), - RESOURCE_X_APPLY_APPLIED); - retain_resource_x_test_settlement_pair( - max_generation_tag, PCM_STATE_X, UINT64_MAX, UINT64_C(1), - UINT64_C(3), &settlement); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_source_settlement_prepare_exact( - &settlement, 0, &plan), RESOURCE_X_APPLY_INVALID); + RESOURCE_X_APPLY_APPLIED); + retain_resource_x_test_settlement_pair(max_generation_tag, PCM_STATE_X, UINT64_MAX, UINT64_C(1), + UINT64_C(3), &settlement); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_source_settlement_prepare_exact(&settlement, 0, &plan), + RESOURCE_X_APPLY_INVALID); UT_ASSERT(!plan.valid); reset_fake_pcm_runtime(4); cluster_node_id = 1; fake_gcs_master_node = 0; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), - RESOURCE_X_APPLY_APPLIED); - retain_resource_x_test_settlement_pair( - overflow_generation_tag, PCM_STATE_X, UINT64_MAX - 1, UINT64_C(1), - UINT64_C(3), &settlement); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_source_settlement_prepare_exact( - &settlement, 0, &plan), RESOURCE_X_APPLY_INVALID); + RESOURCE_X_APPLY_APPLIED); + retain_resource_x_test_settlement_pair(overflow_generation_tag, PCM_STATE_X, UINT64_MAX - 1, + UINT64_C(1), UINT64_C(3), &settlement); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_source_settlement_prepare_exact(&settlement, 0, &plan), + RESOURCE_X_APPLY_INVALID); UT_ASSERT(!plan.valid); } @@ -12608,10 +11939,9 @@ UT_TEST(test_resource_x_s_predecessor_retained_pair_blocks_local_bootstrap) cluster_node_id = 1; fake_gcs_master_node = 0; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), - RESOURCE_X_APPLY_APPLIED); - retain_resource_x_test_settlement_pair( - tag, PCM_STATE_S, UINT64_C(60), UINT64_C(61), UINT64_C(5), - &settlement); + RESOURCE_X_APPLY_APPLIED); + retain_resource_x_test_settlement_pair(tag, PCM_STATE_S, UINT64_C(60), UINT64_C(61), + UINT64_C(5), &settlement); UT_ASSERT(resource_x_assertion_init(&tag, 1, &assertion)); /* The earlier holder settlement owns the ordering edge. A local @@ -12621,27 +11951,25 @@ UT_TEST(test_resource_x_s_predecessor_retained_pair_blocks_local_bootstrap) action = cluster_pcm_lock_resource_x_bootstrap_round_step_exact( &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(1000), (UINT64_C(1000)) - (UINT64_C(100)), UINT64_C(100), UINT64_C(50), false, 0, &bootstrap, &terminal_ref); - UT_ASSERT_EQ(action, - RESOURCE_X_BOOTSTRAP_ROUND_PREDECESSOR_WAIT); + UT_ASSERT_EQ(action, RESOURCE_X_BOOTSTRAP_ROUND_PREDECESSOR_WAIT); UT_ASSERT_EQ(bootstrap.kind, UINT8_C(0)); memset(&plan, 0, sizeof(plan)); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_source_settlement_prepare_exact( - &settlement, 0, &plan), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_source_settlement_prepare_exact(&settlement, 0, &plan), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT(plan.valid); UT_ASSERT_EQ(plan.source_mode, (uint8)PCM_STATE_S); - UT_ASSERT_EQ(plan.cover_action, - (uint8)RESOURCE_X_SETTLEMENT_COVER_NO_COVER); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_source_settlement_commit_exact( - &settlement, 0, &plan, &observation), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(plan.cover_action, (uint8)RESOURCE_X_SETTLEMENT_COVER_NO_COVER); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_source_settlement_commit_exact(&settlement, 0, &plan, + &observation), + RESOURCE_X_APPLY_APPLIED); /* Draining the predecessor exposes the ordinary local bootstrap path. Its * first attempt proves the wait did not create hidden requester state. */ action = cluster_pcm_lock_resource_x_bootstrap_round_step_exact( &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(1000), (UINT64_C(1000)) - (UINT64_C(150)), UINT64_C(150), UINT64_C(50), false, 0, &bootstrap, &terminal_ref); - UT_ASSERT_EQ(action, - RESOURCE_X_BOOTSTRAP_ROUND_DISPATCH_REQUEST); + UT_ASSERT_EQ(action, RESOURCE_X_BOOTSTRAP_ROUND_DISPATCH_REQUEST); UT_ASSERT_EQ(bootstrap.common.assertion_sequence, UINT64_C(1)); } @@ -12663,7 +11991,7 @@ UT_TEST(test_resource_x_s_predecessor_cancels_only_unbound_preassert_round) cluster_node_id = 1; fake_gcs_master_node = 0; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), - RESOURCE_X_APPLY_APPLIED); + RESOURCE_X_APPLY_APPLIED); UT_ASSERT(resource_x_assertion_init(&tag, 1, &assertion)); /* The successor sampled the resource before the predecessor pair became @@ -12675,13 +12003,11 @@ UT_TEST(test_resource_x_s_predecessor_cancels_only_unbound_preassert_round) &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(1000), (UINT64_C(1000)) - (UINT64_C(100)), UINT64_C(100), UINT64_C(50), 0, 0, true, true, false, 0, &caller, &bootstrap, &terminal_ref); - UT_ASSERT_EQ(action, - RESOURCE_X_BOOTSTRAP_ROUND_DISPATCH_REQUEST); + UT_ASSERT_EQ(action, RESOURCE_X_BOOTSTRAP_ROUND_DISPATCH_REQUEST); UT_ASSERT_EQ(bootstrap.common.assertion_sequence, UINT64_C(1)); - retain_resource_x_test_settlement_pair( - tag, PCM_STATE_S, UINT64_C(60), UINT64_C(61), UINT64_C(5), - &settlement); + retain_resource_x_test_settlement_pair(tag, PCM_STATE_S, UINT64_C(60), UINT64_C(61), + UINT64_C(5), &settlement); /* Cancellation does not let a witness cross a namespace just because the * local round is now EMPTY. These reads must leave the saved witness intact. */ UT_ASSERT_EQ(cluster_pcm_lock_resource_x_caller_observe_exact(&assertion, 18, 31, 77, &caller), @@ -12701,15 +12027,13 @@ UT_TEST(test_resource_x_s_predecessor_cancels_only_unbound_preassert_round) UT_ASSERT_EQ(caller.failed_attempt, UINT64_C(0)); memset(&plan, 0, sizeof(plan)); prepare_result - = cluster_pcm_lock_resource_x_source_settlement_prepare_exact( - &settlement, 0, &plan); + = cluster_pcm_lock_resource_x_source_settlement_prepare_exact(&settlement, 0, &plan); UT_ASSERT_EQ(prepare_result, RESOURCE_X_APPLY_APPLIED); UT_ASSERT(plan.valid); if (prepare_result != RESOURCE_X_APPLY_APPLIED || !plan.valid) return; UT_ASSERT_EQ(plan.source_mode, (uint8)PCM_STATE_S); - UT_ASSERT_EQ(plan.cover_action, - (uint8)RESOURCE_X_SETTLEMENT_COVER_NO_COVER); + UT_ASSERT_EQ(plan.cover_action, (uint8)RESOURCE_X_SETTLEMENT_COVER_NO_COVER); /* Before drain, the same foreground invocation keeps its original absolute * deadline but owns no replacement round. */ @@ -12717,11 +12041,11 @@ UT_TEST(test_resource_x_s_predecessor_cancels_only_unbound_preassert_round) &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(1000), (UINT64_C(1000)) - (UINT64_C(125)), UINT64_C(125), UINT64_C(50), 0, 0, true, true, false, 0, &caller, &bootstrap, &terminal_ref); - UT_ASSERT_EQ(action, - RESOURCE_X_BOOTSTRAP_ROUND_PREDECESSOR_WAIT); + UT_ASSERT_EQ(action, RESOURCE_X_BOOTSTRAP_ROUND_PREDECESSOR_WAIT); UT_ASSERT_EQ(bootstrap.kind, UINT8_C(0)); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_source_settlement_commit_exact( - &settlement, 0, &plan, &observation), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_source_settlement_commit_exact(&settlement, 0, &plan, + &observation), + RESOURCE_X_APPLY_APPLIED); /* Cancellation preserves the attempt floor. The next legal round uses a * strictly higher attempt without refreshing the caller's deadline. */ @@ -12729,8 +12053,7 @@ UT_TEST(test_resource_x_s_predecessor_cancels_only_unbound_preassert_round) &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(1000), (UINT64_C(1000)) - (UINT64_C(150)), UINT64_C(150), UINT64_C(50), 0, 0, true, true, false, 0, &caller, &bootstrap, &terminal_ref); - UT_ASSERT_EQ(action, - RESOURCE_X_BOOTSTRAP_ROUND_DISPATCH_REQUEST); + UT_ASSERT_EQ(action, RESOURCE_X_BOOTSTRAP_ROUND_DISPATCH_REQUEST); UT_ASSERT_EQ(bootstrap.common.assertion_sequence, UINT64_C(2)); } @@ -12750,7 +12073,7 @@ UT_TEST(test_resource_x_s_predecessor_cancellation_supersedes_old_wait) cluster_node_id = 1; fake_gcs_master_node = 0; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), - RESOURCE_X_APPLY_APPLIED); + RESOURCE_X_APPLY_APPLIED); UT_ASSERT(resource_x_assertion_init(&tag, 1, &assertion)); /* This caller has already received WAIT for attempt 1 when the exact older @@ -12762,8 +12085,7 @@ UT_TEST(test_resource_x_s_predecessor_cancellation_supersedes_old_wait) &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(1000), (UINT64_C(1000)) - (UINT64_C(100)), UINT64_C(100), UINT64_C(50), 0, 0, true, true, false, 0, &caller, &bootstrap, &terminal_ref); - UT_ASSERT_EQ(action, - RESOURCE_X_BOOTSTRAP_ROUND_DISPATCH_REQUEST); + UT_ASSERT_EQ(action, RESOURCE_X_BOOTSTRAP_ROUND_DISPATCH_REQUEST); UT_ASSERT_EQ(bootstrap.common.assertion_sequence, UINT64_C(1)); action = cluster_pcm_lock_resource_x_bootstrap_round_step_caller_exact( &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(1000), (UINT64_C(1000)) - (UINT64_C(125)), @@ -12771,9 +12093,8 @@ UT_TEST(test_resource_x_s_predecessor_cancellation_supersedes_old_wait) &terminal_ref); UT_ASSERT_EQ(action, RESOURCE_X_BOOTSTRAP_ROUND_WAIT); - retain_resource_x_test_settlement_pair( - tag, PCM_STATE_S, UINT64_C(60), UINT64_C(61), UINT64_C(5), - &settlement); + retain_resource_x_test_settlement_pair(tag, PCM_STATE_S, UINT64_C(60), UINT64_C(61), + UINT64_C(5), &settlement); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_bootstrap_round_wait_exact( &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50), UINT64_MAX - 1, 1), RESOURCE_X_APPLY_DUPLICATE); @@ -12791,20 +12112,19 @@ UT_TEST(test_resource_x_s_predecessor_cancellation_supersedes_old_wait) action = cluster_pcm_lock_resource_x_bootstrap_round_step_caller_exact( &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(1000), UINT64_C(850), UINT64_C(150), UINT64_C(50), 0, 0, true, true, false, 0, &caller, &bootstrap, &terminal_ref); - UT_ASSERT_EQ(action, - RESOURCE_X_BOOTSTRAP_ROUND_PREDECESSOR_WAIT); + UT_ASSERT_EQ(action, RESOURCE_X_BOOTSTRAP_ROUND_PREDECESSOR_WAIT); memset(&plan, 0, sizeof(plan)); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_source_settlement_prepare_exact( - &settlement, 0, &plan), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_source_settlement_prepare_exact(&settlement, 0, &plan), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT(plan.valid); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_source_settlement_commit_exact( - &settlement, 0, &plan, &observation), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_source_settlement_commit_exact(&settlement, 0, &plan, + &observation), + RESOURCE_X_APPLY_APPLIED); action = cluster_pcm_lock_resource_x_bootstrap_round_step_caller_exact( &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(1000), (UINT64_C(1000)) - (UINT64_C(175)), UINT64_C(175), UINT64_C(50), 0, 0, true, true, false, 0, &caller, &bootstrap, &terminal_ref); - UT_ASSERT_EQ(action, - RESOURCE_X_BOOTSTRAP_ROUND_DISPATCH_REQUEST); + UT_ASSERT_EQ(action, RESOURCE_X_BOOTSTRAP_ROUND_DISPATCH_REQUEST); UT_ASSERT_EQ(bootstrap.common.assertion_sequence, UINT64_C(2)); } @@ -12821,18 +12141,17 @@ UT_TEST(test_resource_x_source_settlement_accepts_multi_blocker_authority_span) cluster_node_id = 1; fake_gcs_master_node = 0; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), - RESOURCE_X_APPLY_APPLIED); + RESOURCE_X_APPLY_APPLIED); /* The retained carrier consumes the first authority edge (base 1 -> * image 2), while two additional blockers and the final N -> X grant * advance the authenticated master settlement to generation 5. */ - retain_resource_x_test_settlement_pair( - tag, PCM_STATE_X, UINT64_C(60), UINT64_C(61), UINT64_C(3), - &settlement); + retain_resource_x_test_settlement_pair(tag, PCM_STATE_X, UINT64_C(60), UINT64_C(61), + UINT64_C(3), &settlement); UT_ASSERT_EQ(settlement.common.base_authority_generation, UINT64_C(1)); settlement.common.authority_generation = UINT64_C(5); memset(&plan, 0x5a, sizeof(plan)); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_source_settlement_prepare_exact( - &settlement, 0, &plan), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_source_settlement_prepare_exact(&settlement, 0, &plan), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT(plan.valid); UT_ASSERT_EQ(plan.pair_base_authority_generation, UINT64_C(1)); UT_ASSERT_EQ(plan.pair_image_authority_generation, UINT64_C(2)); @@ -12843,18 +12162,18 @@ UT_TEST(test_resource_x_source_settlement_accepts_multi_blocker_authority_span) drifted = settlement; drifted.common.authority_generation = UINT64_C(6); memset(&observation, 0x5a, sizeof(observation)); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_source_settlement_commit_exact( - &drifted, 0, &plan, &observation), RESOURCE_X_APPLY_STALE); - UT_ASSERT(observation.mismatch_mask - & RESOURCE_X_SOURCE_SETTLEMENT_MISMATCH_PAIR_BYTES); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_source_settlement_commit_exact(&drifted, 0, &plan, + &observation), + RESOURCE_X_APPLY_STALE); + UT_ASSERT(observation.mismatch_mask & RESOURCE_X_SOURCE_SETTLEMENT_MISMATCH_PAIR_BYTES); /* A final authority which does not advance beyond the retained carrier * is not a settlement for this request, even when all other bytes match. */ stale = settlement; stale.common.authority_generation = UINT64_C(2); memset(&plan, 0x5a, sizeof(plan)); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_source_settlement_prepare_exact( - &stale, 0, &plan), RESOURCE_X_APPLY_STALE); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_source_settlement_prepare_exact(&stale, 0, &plan), + RESOURCE_X_APPLY_STALE); UT_ASSERT(!plan.valid); } @@ -12879,15 +12198,14 @@ UT_TEST(test_resource_x_direct_n_origin_offset_advances_blocker_and_grant) cluster_node_id = 0; fake_gcs_master_node = 0; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), - RESOURCE_X_APPLY_APPLIED); + RESOURCE_X_APPLY_APPLIED); /* A pristine N resource starts Resource-X one generation ahead of the * legacy transition counter. That exact origin offset must survive the * later X->N blocker edge and the successor N->X grant edge. */ - first_assert = make_resource_x_master_frame( - RESOURCE_X_WIRE_ASSERT_X, tag, 0, 0); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact( - &first_assert, 0, &snapshot), RESOURCE_X_APPLY_APPLIED); + first_assert = make_resource_x_master_frame(RESOURCE_X_WIRE_ASSERT_X, tag, 0, 0); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact(&first_assert, 0, &snapshot), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(snapshot.phase, RESOURCE_X_MASTER_WAIT_PROOF); memset(&durable, 0, sizeof(durable)); durable.assertion = first_assert.common.logical_assertion; @@ -12899,19 +12217,18 @@ UT_TEST(test_resource_x_direct_n_origin_offset_advances_blocker_and_grant) durable.page_scn_lsn = 82; durable.page_checksum = UINT32_C(0x55667788); durable.source_proof_crc32c = UINT32_C(0x99aabbcc); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_durable_proof_exact( - &durable, &snapshot), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_durable_proof_exact(&durable, &snapshot), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(snapshot.final_authority_generation, UINT64_C(2)); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_grant_intent_snapshot_exact( - &first_assert.common.logical_assertion, &grant_intent, grant_bytes, - sizeof(grant_bytes)), RESOURCE_X_APPLY_APPLIED); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_grant_intent_stage_exact( - &grant_intent, 101), RESOURCE_X_INTENT_STAGED); - UT_ASSERT(cluster_pcm_lock_resource_x_grant_intent_complete_exact( - &grant_intent)); - - settlement = make_resource_x_master_frame( - RESOURCE_X_WIRE_INSTALL_SETTLEMENT, tag, 0, 0); + &first_assert.common.logical_assertion, &grant_intent, grant_bytes, + sizeof(grant_bytes)), + RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_grant_intent_stage_exact(&grant_intent, 101), + RESOURCE_X_INTENT_STAGED); + UT_ASSERT(cluster_pcm_lock_resource_x_grant_intent_complete_exact(&grant_intent)); + + settlement = make_resource_x_master_frame(RESOURCE_X_WIRE_INSTALL_SETTLEMENT, tag, 0, 0); settlement.common.outcome = RESOURCE_X_OUTCOME_OK; settlement.common.authority_generation = 2; settlement.body.install_settlement.conversion_base_generation = 1; @@ -12920,25 +12237,20 @@ UT_TEST(test_resource_x_direct_n_origin_offset_advances_blocker_and_grant) settlement.body.install_settlement.requester_target_generation = 41; settlement.body.install_settlement.page_scn_lsn = 82; settlement.body.install_settlement.page_checksum = UINT32_C(0x55667788); - settlement.body.install_settlement.source_proof_crc32c - = UINT32_C(0x99aabbcc); + settlement.body.install_settlement.source_proof_crc32c = UINT32_C(0x99aabbcc); settlement.body.install_settlement.installed_mode = PCM_STATE_X; - settlement.body.install_settlement.requester_role - = RESOURCE_X_REQUESTER_ROLE_ACQUIRER; - settlement.body.install_settlement.terminal_outcome - = RESOURCE_X_OUTCOME_OK; - settlement.body.install_settlement.terminal_state - = RESOURCE_X_SETTLEMENT_TERMINAL_INSTALLED; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_install_settlement_exact( - &settlement, 0, &snapshot), RESOURCE_X_APPLY_APPLIED); - - second_assert = make_resource_x_master_frame( - RESOURCE_X_WIRE_ASSERT_X, tag, 2, 2); + settlement.body.install_settlement.requester_role = RESOURCE_X_REQUESTER_ROLE_ACQUIRER; + settlement.body.install_settlement.terminal_outcome = RESOURCE_X_OUTCOME_OK; + settlement.body.install_settlement.terminal_state = RESOURCE_X_SETTLEMENT_TERMINAL_INSTALLED; + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_install_settlement_exact(&settlement, 0, &snapshot), + RESOURCE_X_APPLY_APPLIED); + + second_assert = make_resource_x_master_frame(RESOURCE_X_WIRE_ASSERT_X, tag, 2, 2); second_assert.common.base_authority_generation = 2; second_assert.common.authority_generation = 2; second_assert.common.assertion_sequence = 42; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact( - &second_assert, 2, &snapshot), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact(&second_assert, 2, &snapshot), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(snapshot.phase, RESOURCE_X_MASTER_WAIT_BLOCKERS); make_resource_x_remote_join_pair(tag, 2, &pair_grant, &image); @@ -12948,29 +12260,27 @@ UT_TEST(test_resource_x_direct_n_origin_offset_advances_blocker_and_grant) blocked.common.authority_generation = 2; blocked.common.assertion_sequence = 42; blocked.body.blocked_to_n.requester_target_generation = 42; - blocked.body.blocked_to_n.source_proof_crc32c - = image.common.semantic_crc32c; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_blocked_to_n_exact( - &blocked, 0, &snapshot), RESOURCE_X_APPLY_APPLIED); + blocked.body.blocked_to_n.source_proof_crc32c = image.common.semantic_crc32c; + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_blocked_to_n_exact(&blocked, 0, &snapshot), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(snapshot.phase, RESOURCE_X_MASTER_GRANT_COMMITTED); UT_ASSERT_EQ(snapshot.final_authority_generation, UINT64_C(4)); UT_ASSERT(cluster_pcm_lock_authority_snapshot(tag, &authority)); UT_ASSERT_EQ(authority.transition_count, UINT64_C(3)); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_authority_grant_exact( - &second_assert.common.logical_assertion, &grant), - RESOURCE_X_APPLY_APPLIED); + &second_assert.common.logical_assertion, &grant), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(grant.common.base_authority_generation, UINT64_C(2)); UT_ASSERT_EQ(grant.common.authority_generation, UINT64_C(4)); cluster_node_id = 2; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact( - &image, 0, &join), RESOURCE_X_APPLY_APPLIED); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact( - &grant, 0, &join), RESOURCE_X_APPLY_APPLIED); - UT_ASSERT_EQ(join.flags, - RESOURCE_X_REQUESTER_JOIN_HAS_IMAGE - | RESOURCE_X_REQUESTER_JOIN_HAS_GRANT - | RESOURCE_X_REQUESTER_JOIN_READY); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact(&image, 0, &join), + RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact(&grant, 0, &join), + RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(join.flags, RESOURCE_X_REQUESTER_JOIN_HAS_IMAGE + | RESOURCE_X_REQUESTER_JOIN_HAS_GRANT + | RESOURCE_X_REQUESTER_JOIN_READY); } UT_TEST(test_resource_x_head_accepts_exact_blockers_after_prior_pcm_s_churn) @@ -12986,7 +12296,7 @@ UT_TEST(test_resource_x_head_accepts_exact_blockers_after_prior_pcm_s_churn) reset_fake_pcm_runtime(4); cluster_node_id = 0; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), - RESOURCE_X_APPLY_APPLIED); + RESOURCE_X_APPLY_APPLIED); cluster_pcm_lock_acquire(tag, PCM_LOCK_MODE_S); for (cycle = 0; cycle < 2; cycle++) { for (holder_node = 1; holder_node < 4; holder_node++) { @@ -12997,18 +12307,17 @@ UT_TEST(test_resource_x_head_accepts_exact_blockers_after_prior_pcm_s_churn) } cluster_node_id = 0; - assertion = make_resource_x_master_frame( - RESOURCE_X_WIRE_ASSERT_X, tag, 2, 2); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact( - &assertion, 2, &snapshot), RESOURCE_X_APPLY_APPLIED); + assertion = make_resource_x_master_frame(RESOURCE_X_WIRE_ASSERT_X, tag, 2, 2); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact(&assertion, 2, &snapshot), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(snapshot.phase, RESOURCE_X_MASTER_WAIT_BLOCKERS); UT_ASSERT_EQ(snapshot.incompatible_holders_bitmap, UINT32_C(1)); blocked = make_resource_x_remote_blocked_frame(tag, 2, 0); blocked.common.observed_mode = PCM_STATE_S; blocked.body.blocked_to_n.source_fence[28] = PCM_STATE_S; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_blocked_to_n_exact( - &blocked, 0, &snapshot), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_blocked_to_n_exact(&blocked, 0, &snapshot), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(snapshot.phase, RESOURCE_X_MASTER_GRANT_COMMITTED); UT_ASSERT_EQ(snapshot.final_authority_generation, UINT64_C(3)); UT_ASSERT(cluster_pcm_lock_authority_snapshot(tag, &authority)); @@ -13024,36 +12333,31 @@ UT_TEST(test_resource_x_head_rejects_uncovered_pcm_transition_drift) reset_fake_pcm_runtime(4); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), - RESOURCE_X_APPLY_APPLIED); + RESOURCE_X_APPLY_APPLIED); cluster_node_id = 2; cluster_pcm_lock_acquire(tag, PCM_LOCK_MODE_X); cluster_node_id = 0; - assertion = make_resource_x_master_frame( - RESOURCE_X_WIRE_ASSERT_X, tag, 2, 2); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact( - &assertion, 2, &snapshot), RESOURCE_X_APPLY_APPLIED); + assertion = make_resource_x_master_frame(RESOURCE_X_WIRE_ASSERT_X, tag, 2, 2); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact(&assertion, 2, &snapshot), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(snapshot.phase, RESOURCE_X_MASTER_WAIT_PROOF); - UT_ASSERT(cluster_pcm_lock_apply_gcs_transition( - tag, PCM_TRANS_X_TO_S_DOWNGRADE, 2)); - UT_ASSERT(cluster_pcm_lock_apply_gcs_transition( - tag, PCM_TRANS_S_TO_X_UPGRADE, 2)); + UT_ASSERT(cluster_pcm_lock_apply_gcs_transition(tag, PCM_TRANS_X_TO_S_DOWNGRADE, 2)); + UT_ASSERT(cluster_pcm_lock_apply_gcs_transition(tag, PCM_TRANS_S_TO_X_UPGRADE, 2)); - local_proof = make_resource_x_master_frame( - RESOURCE_X_WIRE_LOCAL_PROOF_DECLARATION, tag, 2, 2); + local_proof = make_resource_x_master_frame(RESOURCE_X_WIRE_LOCAL_PROOF_DECLARATION, tag, 2, 2); local_proof.common.observed_mode = PCM_STATE_X; local_proof.common.outcome = RESOURCE_X_OUTCOME_OK; local_proof.body.local_proof.local_holder_authority_generation = 71; local_proof.body.local_proof.requester_target_generation = 41; local_proof.body.local_proof.page_scn_lsn = 82; local_proof.body.local_proof.page_checksum = UINT32_C(0x55667788); - local_proof.body.local_proof.local_image_proof_crc32c - = UINT32_C(0x99aabbcc); + local_proof.body.local_proof.local_image_proof_crc32c = UINT32_C(0x99aabbcc); local_proof.body.local_proof.requester_connection_generation = 73; local_proof.body.local_proof.local_proof_generation = 74; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_local_proof_exact( - &local_proof, 2, &snapshot), RESOURCE_X_APPLY_RECOVERY_BLOCKED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_local_proof_exact(&local_proof, 2, &snapshot), + RESOURCE_X_APPLY_RECOVERY_BLOCKED); UT_ASSERT_EQ(snapshot.phase, RESOURCE_X_MASTER_RECOVERY_BLOCKED); UT_ASSERT_EQ(snapshot.final_authority_generation, UINT64_C(0)); } @@ -13084,74 +12388,69 @@ UT_TEST(test_resource_x_requester_join_accepts_either_order_and_never_overwrites cluster_pcm_lock_acquire(mismatch_tag, PCM_LOCK_MODE_S); cluster_pcm_lock_release(mismatch_tag); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), - RESOURCE_X_APPLY_APPLIED); + RESOURCE_X_APPLY_APPLIED); make_resource_x_remote_join_pair(image_first_tag, 2, &grant, &image); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact( - &image, 0, &snapshot), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact(&image, 0, &snapshot), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(snapshot.flags, RESOURCE_X_REQUESTER_JOIN_HAS_IMAGE); UT_ASSERT(snapshot.t_image_us != 0); UT_ASSERT_EQ(snapshot.t_grant_us, 0); first = snapshot; changed = image; changed.common.sender_connection_generation++; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact( - &changed, 0, &snapshot), RESOURCE_X_APPLY_DUPLICATE); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact(&changed, 0, &snapshot), + RESOURCE_X_APPLY_DUPLICATE); UT_ASSERT_EQ(snapshot.t_image_us, first.t_image_us); changed = image; changed.body.image_envelope.page_bytes[0] ^= UINT8_C(1); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact( - &changed, 0, &snapshot), RESOURCE_X_APPLY_STALE); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact(&changed, 0, &snapshot), + RESOURCE_X_APPLY_STALE); UT_ASSERT_EQ(snapshot.flags, RESOURCE_X_REQUESTER_JOIN_HAS_IMAGE); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact( - &grant, 2, &snapshot), RESOURCE_X_APPLY_APPLIED); - UT_ASSERT_EQ(snapshot.flags, - RESOURCE_X_REQUESTER_JOIN_HAS_IMAGE - | RESOURCE_X_REQUESTER_JOIN_HAS_GRANT - | RESOURCE_X_REQUESTER_JOIN_READY); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact(&grant, 2, &snapshot), + RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(snapshot.flags, RESOURCE_X_REQUESTER_JOIN_HAS_IMAGE + | RESOURCE_X_REQUESTER_JOIN_HAS_GRANT + | RESOURCE_X_REQUESTER_JOIN_READY); UT_ASSERT(snapshot.t_grant_us != 0); first = snapshot; changed = grant; changed.common.sender_connection_generation++; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact( - &changed, 2, &snapshot), RESOURCE_X_APPLY_DUPLICATE); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact(&changed, 2, &snapshot), + RESOURCE_X_APPLY_DUPLICATE); UT_ASSERT_EQ(snapshot.t_image_us, first.t_image_us); UT_ASSERT_EQ(snapshot.t_grant_us, first.t_grant_us); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_frames_exact( - &grant.common.logical_assertion, &retained_grant, - &retained_image, &snapshot), RESOURCE_X_APPLY_APPLIED); + &grant.common.logical_assertion, &retained_grant, &retained_image, &snapshot), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(retained_grant.kind, RESOURCE_X_WIRE_AUTHORITY_GRANT); UT_ASSERT_EQ(retained_image.kind, RESOURCE_X_WIRE_IMAGE_ENVELOPE); - UT_ASSERT_EQ(retained_grant.body.authority_grant.final_authority_generation, - 3); + UT_ASSERT_EQ(retained_grant.body.authority_grant.final_authority_generation, 3); UT_ASSERT_EQ(retained_image.body.image_envelope.page_bytes[4095], - image.body.image_envelope.page_bytes[4095]); + image.body.image_envelope.page_bytes[4095]); make_resource_x_remote_join_pair(grant_first_tag, 2, &grant, &image); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact( - &grant, 2, &snapshot), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact(&grant, 2, &snapshot), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(snapshot.flags, RESOURCE_X_REQUESTER_JOIN_HAS_GRANT); changed = image; changed.common.sender_connection_generation = 85; - UT_ASSERT(cluster_resource_x_wire_encode( - RESOURCE_X_MSG_IMAGE_OR_GRANT, &changed, image_payload, - sizeof(image_payload), &image_payload_bytes, &reject)); + UT_ASSERT(cluster_resource_x_wire_encode(RESOURCE_X_MSG_IMAGE_OR_GRANT, &changed, image_payload, + sizeof(image_payload), &image_payload_bytes, &reject)); UT_ASSERT_EQ(image_payload_bytes, RESOURCE_X_IMAGE_V1_BYTES); - UT_ASSERT(cluster_resource_x_wire_decode( - RESOURCE_X_MSG_IMAGE_OR_GRANT, image_payload, image_payload_bytes, - &resealed_image, &reject)); - UT_ASSERT(resealed_image.common.semantic_crc32c - != image.common.semantic_crc32c); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact( - &resealed_image, 0, &snapshot), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT(cluster_resource_x_wire_decode(RESOURCE_X_MSG_IMAGE_OR_GRANT, image_payload, + image_payload_bytes, &resealed_image, &reject)); + UT_ASSERT(resealed_image.common.semantic_crc32c != image.common.semantic_crc32c); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact(&resealed_image, 0, &snapshot), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT((snapshot.flags & RESOURCE_X_REQUESTER_JOIN_READY) != 0); make_resource_x_remote_join_pair(mismatch_tag, 2, &grant, &image); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact( - &image, 0, &snapshot), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact(&image, 0, &snapshot), + RESOURCE_X_APPLY_APPLIED); grant.body.authority_grant.source_proof_crc32c++; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact( - &grant, 2, &snapshot), RESOURCE_X_APPLY_STALE); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact(&grant, 2, &snapshot), + RESOURCE_X_APPLY_STALE); UT_ASSERT_EQ(snapshot.flags, RESOURCE_X_REQUESTER_JOIN_HAS_IMAGE); UT_ASSERT_EQ(snapshot.t_grant_us, 0); } @@ -13168,19 +12467,18 @@ UT_TEST(test_resource_x_requester_join_accepts_exact_base_carrier_final_lineage) cluster_pcm_lock_acquire(tag, PCM_LOCK_MODE_S); cluster_pcm_lock_release(tag); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), - RESOURCE_X_APPLY_APPLIED); + RESOURCE_X_APPLY_APPLIED); make_resource_x_remote_join_pair(tag, 2, &grant, &image); UT_ASSERT_EQ(grant.common.base_authority_generation, 1); UT_ASSERT_EQ(image.common.authority_generation, 2); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact( - &image, 0, &join), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact(&image, 0, &join), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(join.flags, RESOURCE_X_REQUESTER_JOIN_HAS_IMAGE); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact( - &grant, 2, &join), RESOURCE_X_APPLY_APPLIED); - UT_ASSERT_EQ(join.flags, - RESOURCE_X_REQUESTER_JOIN_HAS_IMAGE - | RESOURCE_X_REQUESTER_JOIN_HAS_GRANT - | RESOURCE_X_REQUESTER_JOIN_READY); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact(&grant, 2, &join), + RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(join.flags, RESOURCE_X_REQUESTER_JOIN_HAS_IMAGE + | RESOURCE_X_REQUESTER_JOIN_HAS_GRANT + | RESOURCE_X_REQUESTER_JOIN_READY); UT_ASSERT_EQ(join.base_authority_generation, 1); UT_ASSERT_EQ(join.final_authority_generation, 3); } @@ -14563,31 +13861,29 @@ resource_x_test_live_base_not_binding_floor(bool image_bound) cluster_node_id = 2; fake_gcs_master_node = 0; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), - RESOURCE_X_APPLY_APPLIED); + RESOURCE_X_APPLY_APPLIED); /* Raise only the node-local physical binding/retirement floor. It is * lifecycle/ABA state for another resource, not current master authority * for the request below. */ - UT_ASSERT(pcm_entry_ref_acquire( - &retired_tag, true, &entry_ref, &acquire_result)); + UT_ASSERT(pcm_entry_ref_acquire(&retired_tag, true, &entry_ref, &acquire_result)); retired_binding_generation = entry_ref.binding_generation; pcm_entry_ref_release(&entry_ref); for (cycle = 0; cycle < 3; cycle++) { - UT_ASSERT_EQ(cluster_pcm_lock_apply_gcs_transition_result( - retired_tag, PCM_TRANS_N_TO_X, 2), PCM_GCS_TRANSITION_APPLIED); - UT_ASSERT_EQ(cluster_pcm_lock_apply_gcs_transition_result( - retired_tag, PCM_TRANS_X_TO_N_RELEASE, 2), + UT_ASSERT_EQ(cluster_pcm_lock_apply_gcs_transition_result(retired_tag, PCM_TRANS_N_TO_X, 2), + PCM_GCS_TRANSITION_APPLIED); + UT_ASSERT_EQ( + cluster_pcm_lock_apply_gcs_transition_result(retired_tag, PCM_TRANS_X_TO_N_RELEASE, 2), PCM_GCS_TRANSITION_APPLIED); } UT_ASSERT(cluster_pcm_lock_authority_snapshot(retired_tag, &authority)); UT_ASSERT(authority.transition_count > UINT64_C(3)); - UT_ASSERT(resource_x_assertion_init( - &retired_tag, 2, &retired_assertion)); + UT_ASSERT(resource_x_assertion_init(&retired_tag, 2, &retired_assertion)); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_adapter_base_bind_exact( - &retired_assertion, 17, authority.transition_count, &authority), - RESOURCE_X_APPLY_APPLIED); - UT_ASSERT(pcm_entry_try_retire_exact(&retired_tag, - retired_binding_generation, PCM_RETIRE_REASON_HOLDER_RELEASE)); + &retired_assertion, 17, authority.transition_count, &authority), + RESOURCE_X_APPLY_APPLIED); + UT_ASSERT(pcm_entry_try_retire_exact(&retired_tag, retired_binding_generation, + PCM_RETIRE_REASON_HOLDER_RELEASE)); /* Actual ACK or actual delegated IMAGE must bind the master's base, * not the unrelated local physical slot floor. Exercise both origins. */ @@ -14605,25 +13901,21 @@ resource_x_test_live_base_not_binding_floor(bool image_bound) &ack, 0, 61, 77, UINT64_C(110), &assert_frame); UT_ASSERT_EQ(action, RESOURCE_X_BOOTSTRAP_ROUND_DISPATCH_ASSERT); } - UT_ASSERT_EQ( - cluster_pcm_lock_resource_x_bootstrap_round_failure_snapshot_exact( - &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50), &failure), - RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_bootstrap_round_failure_snapshot_exact( + &assertion, 0, 17, 31, 77, 51, 61, UINT64_C(50), &failure), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT(failure.requester_base_generation > UINT64_C(3)); UT_ASSERT_EQ(failure.base_authority_generation, image_bound ? UINT64_C(0) : UINT64_C(2)); make_resource_x_remote_join_pair(tag, 2, &grant, &image); retarget_resource_x_remote_join_pair(&grant, &image, UINT64_C(3), - assert_frame.common.assertion_sequence); - grant.common.base_authority_generation - = assert_frame.common.base_authority_generation; + assert_frame.common.assertion_sequence); + grant.common.base_authority_generation = assert_frame.common.base_authority_generation; grant.common.ordered_lane = assert_frame.common.ordered_lane; grant.common.flags = 0; grant.body.authority_grant.source_carrier_generation = 0; - grant.body.authority_grant.proof_kind - = RESOURCE_X_PROOF_DURABLE_STORAGE; - grant.body.authority_grant.source_disposition - = RESOURCE_X_DISPOSITION_DURABLE_STORAGE; + grant.body.authority_grant.proof_kind = RESOURCE_X_PROOF_DURABLE_STORAGE; + grant.body.authority_grant.source_disposition = RESOURCE_X_DISPOSITION_DURABLE_STORAGE; UT_ASSERT_EQ(grant.common.base_authority_generation, UINT64_C(2)); if (image_bound) { image.common.base_authority_generation = 2; @@ -14640,20 +13932,18 @@ resource_x_test_live_base_not_binding_floor(bool image_bound) RESOURCE_X_REQUESTER_JOIN_HAS_GRANT | RESOURCE_X_REQUESTER_JOIN_READY); } - ref = make_resource_x_acquisition_ref(tag, 2, 17, - assert_frame.common.assertion_sequence); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_t1_grant_exact(&ref), - RESOURCE_X_APPLY_APPLIED); + ref = make_resource_x_acquisition_ref(tag, 2, 17, assert_frame.common.assertion_sequence); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_t1_grant_exact(&ref), RESOURCE_X_APPLY_APPLIED); memset(&install, 0, sizeof(install)); install.ownership_generation = 9; install.writer_activation_token = 12; install.resource_x_activation_generation = ref.acquisition_generation; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_apply_exact( - &ref, &install), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_apply_exact(&ref, &install), + RESOURCE_X_APPLY_APPLIED); memset(&activation, 0, sizeof(activation)); activation.ownership_generation = install.ownership_generation; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_activate_exact( - &ref, &activation), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_activate_exact(&ref, &activation), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT(cluster_pcm_lock_resource_x_bootstrap_round_cover_matches_exact( &ref, 31, 77, install.ownership_generation)); } @@ -14680,48 +13970,42 @@ UT_TEST(test_resource_x_requester_join_accepts_s_carrier_either_order_and_reject reset_fake_pcm_runtime(8); cluster_node_id = 2; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), - RESOURCE_X_APPLY_APPLIED); + RESOURCE_X_APPLY_APPLIED); - make_resource_x_s_remote_join_pair( - image_first_tag, 2, &grant, &image); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact( - &image, 0, &join), RESOURCE_X_APPLY_APPLIED); + make_resource_x_s_remote_join_pair(image_first_tag, 2, &grant, &image); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact(&image, 0, &join), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(join.flags, RESOURCE_X_REQUESTER_JOIN_HAS_IMAGE); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact( - &image, 0, &join), RESOURCE_X_APPLY_DUPLICATE); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact( - &grant, 2, &join), RESOURCE_X_APPLY_APPLIED); - UT_ASSERT_EQ(join.flags, - RESOURCE_X_REQUESTER_JOIN_HAS_IMAGE - | RESOURCE_X_REQUESTER_JOIN_HAS_GRANT - | RESOURCE_X_REQUESTER_JOIN_READY); - - make_resource_x_s_remote_join_pair( - grant_first_tag, 2, &grant, &image); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact( - &grant, 2, &join), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact(&image, 0, &join), + RESOURCE_X_APPLY_DUPLICATE); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact(&grant, 2, &join), + RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(join.flags, RESOURCE_X_REQUESTER_JOIN_HAS_IMAGE + | RESOURCE_X_REQUESTER_JOIN_HAS_GRANT + | RESOURCE_X_REQUESTER_JOIN_READY); + + make_resource_x_s_remote_join_pair(grant_first_tag, 2, &grant, &image); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact(&grant, 2, &join), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(join.flags, RESOURCE_X_REQUESTER_JOIN_HAS_GRANT); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact( - &grant, 2, &join), RESOURCE_X_APPLY_DUPLICATE); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact( - &image, 0, &join), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact(&grant, 2, &join), + RESOURCE_X_APPLY_DUPLICATE); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact(&image, 0, &join), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT((join.flags & RESOURCE_X_REQUESTER_JOIN_READY) != 0); make_resource_x_s_remote_join_pair(mismatch_tag, 2, &grant, &image); image.common.observed_mode = PCM_STATE_X; - UT_ASSERT(cluster_resource_x_wire_encode( - RESOURCE_X_MSG_IMAGE_OR_GRANT, &image, image_payload, - sizeof(image_payload), &image_payload_bytes, &reject)); - UT_ASSERT(cluster_resource_x_wire_decode( - RESOURCE_X_MSG_IMAGE_OR_GRANT, image_payload, image_payload_bytes, - &canonical_image, &reject)); + UT_ASSERT(cluster_resource_x_wire_encode(RESOURCE_X_MSG_IMAGE_OR_GRANT, &image, image_payload, + sizeof(image_payload), &image_payload_bytes, &reject)); + UT_ASSERT(cluster_resource_x_wire_decode(RESOURCE_X_MSG_IMAGE_OR_GRANT, image_payload, + image_payload_bytes, &canonical_image, &reject)); image = canonical_image; - grant.body.authority_grant.source_proof_crc32c - = image.common.semantic_crc32c; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact( - &image, 0, &join), RESOURCE_X_APPLY_APPLIED); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact( - &grant, 2, &join), RESOURCE_X_APPLY_STALE); + grant.body.authority_grant.source_proof_crc32c = image.common.semantic_crc32c; + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact(&image, 0, &join), + RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact(&grant, 2, &join), + RESOURCE_X_APPLY_STALE); UT_ASSERT_EQ(join.flags, RESOURCE_X_REQUESTER_JOIN_HAS_IMAGE); } @@ -14736,7 +14020,7 @@ UT_TEST(test_resource_x_requester_join_accepts_multi_blocker_authority_span) cluster_node_id = 0; fake_gcs_master_node = 0; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), - RESOURCE_X_APPLY_APPLIED); + RESOURCE_X_APPLY_APPLIED); make_resource_x_s_remote_join_pair(tag, 0, &grant, &image); /* Three remote S blockers consume three holder authority edges before @@ -14747,15 +14031,14 @@ UT_TEST(test_resource_x_requester_join_accepts_multi_blocker_authority_span) grant.body.authority_grant.final_authority_generation = UINT64_C(5); UT_ASSERT_EQ(grant.common.base_authority_generation, UINT64_C(1)); UT_ASSERT_EQ(image.common.authority_generation, UINT64_C(2)); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact( - &image, 1, &join), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact(&image, 1, &join), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(join.flags, RESOURCE_X_REQUESTER_JOIN_HAS_IMAGE); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact( - &grant, 0, &join), RESOURCE_X_APPLY_APPLIED); - UT_ASSERT_EQ(join.flags, - RESOURCE_X_REQUESTER_JOIN_HAS_IMAGE - | RESOURCE_X_REQUESTER_JOIN_HAS_GRANT - | RESOURCE_X_REQUESTER_JOIN_READY); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact(&grant, 0, &join), + RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(join.flags, RESOURCE_X_REQUESTER_JOIN_HAS_IMAGE + | RESOURCE_X_REQUESTER_JOIN_HAS_GRANT + | RESOURCE_X_REQUESTER_JOIN_READY); } UT_TEST(test_resource_x_requester_join_creates_fresh_local_entry_before_t1) @@ -14769,21 +14052,20 @@ UT_TEST(test_resource_x_requester_join_creates_fresh_local_entry_before_t1) reset_fake_pcm_runtime(8); cluster_node_id = 2; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), - RESOURCE_X_APPLY_APPLIED); + RESOURCE_X_APPLY_APPLIED); make_resource_x_remote_join_pair(tag, 2, &grant, &image); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact( - &grant, 2, &join), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact(&grant, 2, &join), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(join.flags, RESOURCE_X_REQUESTER_JOIN_HAS_GRANT); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact( - &image, 0, &join), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact(&image, 0, &join), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT((join.flags & RESOURCE_X_REQUESTER_JOIN_READY) != 0); memset(&ref, 0, sizeof(ref)); ref.assertion = join.assertion; ref.formation = join.resource_formation; ref.acquisition_generation = join.requester_target_generation; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_t1_grant_exact(&ref), - RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_t1_grant_exact(&ref), RESOURCE_X_APPLY_APPLIED); } static void @@ -14791,16 +14073,15 @@ wait_for_resource_x_timestamp_after(uint64 timestamp_us) { instr_time now; - do - { + do { INSTR_TIME_SET_CURRENT(now); } while ((uint64)INSTR_TIME_GET_MICROSEC(now) <= timestamp_us); } static void -complete_resource_x_remote_requester_terminal( - const ResourceXRequesterJoinSnapshot *join, ResourceXAcquisitionRef *ref_out, - ResourceXBufferActivationProof *activation_out) +complete_resource_x_remote_requester_terminal(const ResourceXRequesterJoinSnapshot *join, + ResourceXAcquisitionRef *ref_out, + ResourceXBufferActivationProof *activation_out) { ResourceXBufferInstallProof install; @@ -14808,8 +14089,7 @@ complete_resource_x_remote_requester_terminal( ref_out->assertion = join->assertion; ref_out->formation = join->resource_formation; ref_out->acquisition_generation = join->requester_target_generation; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_t1_grant_exact(ref_out), - RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_t1_grant_exact(ref_out), RESOURCE_X_APPLY_APPLIED); memset(&install, 0, sizeof(install)); install.ownership_generation = 9; install.writer_activation_token = 12; @@ -14818,8 +14098,8 @@ complete_resource_x_remote_requester_terminal( RESOURCE_X_APPLY_APPLIED); memset(activation_out, 0, sizeof(*activation_out)); activation_out->ownership_generation = install.ownership_generation; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_activate_exact( - ref_out, activation_out), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_activate_exact(ref_out, activation_out), + RESOURCE_X_APPLY_APPLIED); } UT_TEST(test_resource_x_remote_terminal_settles_o1_once_and_keeps_first_times) @@ -14857,11 +14137,11 @@ UT_TEST(test_resource_x_remote_terminal_settles_o1_once_and_keeps_first_times) UT_ASSERT(cluster_pcm_lock_resource_x_trace_begin(&image_first_tag, 1)); make_resource_x_remote_join_pair(image_first_tag, 2, &grant, &image); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact( - &image, 0, &join), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact(&image, 0, &join), + RESOURCE_X_APPLY_APPLIED); wait_for_resource_x_timestamp_after(join.t_image_us); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact( - &grant, 2, &join), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact(&grant, 2, &join), + RESOURCE_X_APPLY_APPLIED); ready_join = join; complete_resource_x_remote_requester_terminal(&join, &ref, &activation); /* This valid retirement has no bootstrap round. Observation must retain @@ -14874,50 +14154,40 @@ UT_TEST(test_resource_x_remote_terminal_settles_o1_once_and_keeps_first_times) UT_ASSERT_EQ(trace_rows[0].attempt, ready_join.requester_target_generation); UT_ASSERT_EQ(trace_rows[0].value[3], 0); UT_ASSERT(cluster_pcm_lock_resource_x_trace_release(1)); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_outbound_intent_probe_exact( - 4, &settlement_intent, settlement_payload, - sizeof(settlement_payload), &examined), + UT_ASSERT_EQ( + cluster_pcm_lock_resource_x_outbound_intent_probe_exact( + 4, &settlement_intent, settlement_payload, sizeof(settlement_payload), &examined), RESOURCE_X_INTENT_PROBE_FOUND); - UT_ASSERT_EQ(settlement_intent.body.owner_kind, - RESOURCE_X_INTENT_OWNER_REQUESTER_SETTLEMENT); - UT_ASSERT_EQ(settlement_intent.destination_node, - (uint32)ready_join.grant_source_node); - UT_ASSERT_EQ(settlement_intent.kind, - RESOURCE_X_WIRE_INSTALL_SETTLEMENT); - UT_ASSERT_EQ(settlement_intent.payload_bytes, - RESOURCE_X_SHORT_V1_BYTES); - UT_ASSERT(cluster_resource_x_wire_decode( - RESOURCE_X_MSG_SETTLEMENT_OR_RELEASE, settlement_payload, - settlement_intent.payload_bytes, &settlement, &reject)); - UT_ASSERT(resource_x_assertion_equal( - &settlement.common.logical_assertion, &ready_join.assertion)); - UT_ASSERT_EQ(settlement.common.base_authority_generation, - ready_join.base_authority_generation); - UT_ASSERT_EQ(settlement.common.resource_formation, - ready_join.resource_formation); + UT_ASSERT_EQ(settlement_intent.body.owner_kind, RESOURCE_X_INTENT_OWNER_REQUESTER_SETTLEMENT); + UT_ASSERT_EQ(settlement_intent.destination_node, (uint32)ready_join.grant_source_node); + UT_ASSERT_EQ(settlement_intent.kind, RESOURCE_X_WIRE_INSTALL_SETTLEMENT); + UT_ASSERT_EQ(settlement_intent.payload_bytes, RESOURCE_X_SHORT_V1_BYTES); + UT_ASSERT(cluster_resource_x_wire_decode(RESOURCE_X_MSG_SETTLEMENT_OR_RELEASE, + settlement_payload, settlement_intent.payload_bytes, + &settlement, &reject)); + UT_ASSERT( + resource_x_assertion_equal(&settlement.common.logical_assertion, &ready_join.assertion)); + UT_ASSERT_EQ(settlement.common.base_authority_generation, ready_join.base_authority_generation); + UT_ASSERT_EQ(settlement.common.resource_formation, ready_join.resource_formation); UT_ASSERT_EQ(settlement.common.master_session_incarnation, - ready_join.master_session_incarnation); - UT_ASSERT_EQ(settlement.common.assertion_sequence, - ready_join.assertion_sequence); - UT_ASSERT_EQ(settlement.common.authority_generation, - ready_join.final_authority_generation); + ready_join.master_session_incarnation); + UT_ASSERT_EQ(settlement.common.assertion_sequence, ready_join.assertion_sequence); + UT_ASSERT_EQ(settlement.common.authority_generation, ready_join.final_authority_generation); UT_ASSERT_EQ(settlement.body.install_settlement.requester_target_generation, - ready_join.requester_target_generation); - UT_ASSERT_EQ(settlement.body.install_settlement.installed_mode, - PCM_STATE_X); + ready_join.requester_target_generation); + UT_ASSERT_EQ(settlement.body.install_settlement.installed_mode, PCM_STATE_X); UT_ASSERT_EQ(settlement.body.install_settlement.requester_role, - RESOURCE_X_REQUESTER_ROLE_ACQUIRER); + RESOURCE_X_REQUESTER_ROLE_ACQUIRER); UT_ASSERT_EQ(settlement.body.install_settlement.terminal_state, - RESOURCE_X_SETTLEMENT_TERMINAL_INSTALLED); + RESOURCE_X_SETTLEMENT_TERMINAL_INSTALLED); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_outbound_intent_stage_exact( - &settlement_intent, settlement_intent.first_armed_us + 1), - RESOURCE_X_INTENT_STAGED); - UT_ASSERT(cluster_pcm_lock_resource_x_outbound_intent_complete_exact( - &settlement_intent)); + &settlement_intent, settlement_intent.first_armed_us + 1), + RESOURCE_X_INTENT_STAGED); + UT_ASSERT(cluster_pcm_lock_resource_x_outbound_intent_complete_exact(&settlement_intent)); assertion = join.assertion; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_frames_exact( - &assertion, &retained_grant, &retained_image, &join), - RESOURCE_X_APPLY_NOT_FOUND); + &assertion, &retained_grant, &retained_image, &join), + RESOURCE_X_APPLY_NOT_FOUND); cluster_pcm_lock_resource_x_o1_stats_snapshot(&stats); UT_ASSERT_EQ(stats.remote_install_observed_count, 1); UT_ASSERT_EQ(stats.remote_grant_after_image_count, 1); @@ -14928,23 +14198,23 @@ UT_TEST(test_resource_x_remote_terminal_settles_o1_once_and_keeps_first_times) UT_ASSERT_EQ(stats.last_remote_t_image_us, ready_join.t_image_us); UT_ASSERT_EQ(stats.last_remote_t_grant_us, ready_join.t_grant_us); UT_ASSERT(stats.last_remote_t_install_us != 0); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_activate_exact( - &ref, &activation), RESOURCE_X_APPLY_DUPLICATE); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_activate_exact(&ref, &activation), + RESOURCE_X_APPLY_DUPLICATE); cluster_pcm_lock_resource_x_o1_stats_snapshot(&duplicate_stats); UT_ASSERT_EQ(memcmp(&duplicate_stats, &stats, sizeof(stats)), 0); make_resource_x_remote_join_pair(grant_first_tag, 2, &grant, &image); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact( - &grant, 2, &join), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact(&grant, 2, &join), + RESOURCE_X_APPLY_APPLIED); wait_for_resource_x_timestamp_after(join.t_grant_us); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact( - &image, 0, &join), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact(&image, 0, &join), + RESOURCE_X_APPLY_APPLIED); ready_join = join; complete_resource_x_remote_requester_terminal(&join, &ref, &activation); assertion = join.assertion; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_frames_exact( - &assertion, &retained_grant, &retained_image, &join), - RESOURCE_X_APPLY_NOT_FOUND); + &assertion, &retained_grant, &retained_image, &join), + RESOURCE_X_APPLY_NOT_FOUND); cluster_pcm_lock_resource_x_o1_stats_snapshot(&stats); UT_ASSERT_EQ(stats.remote_install_observed_count, 2); UT_ASSERT_EQ(stats.remote_grant_after_image_count, 1); @@ -15018,10 +14288,10 @@ UT_TEST(test_resource_x_requester_floors_keep_authority_and_target_axes_distinct make_resource_x_remote_join_pair(tag, 2, &grant, &image); UT_ASSERT_EQ(grant.body.authority_grant.final_authority_generation, 3); UT_ASSERT_EQ(grant.body.authority_grant.requester_target_generation, 41); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact( - &image, 0, &join), RESOURCE_X_APPLY_APPLIED); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact( - &grant, 2, &join), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact(&image, 0, &join), + RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact(&grant, 2, &join), + RESOURCE_X_APPLY_APPLIED); assertion = join.assertion; complete_resource_x_remote_requester_terminal(&join, &ref, &activation); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_executor_probe_exact(&ref, &snapshot), @@ -15029,12 +14299,12 @@ UT_TEST(test_resource_x_requester_floors_keep_authority_and_target_axes_distinct UT_ASSERT_EQ(snapshot.requester_base_generation, 3); UT_ASSERT_EQ(snapshot.retired_acquisition_generation, 41); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_frames_exact( - &assertion, &retained_grant, &retained_image, &join), - RESOURCE_X_APPLY_NOT_FOUND); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact( - &image, 0, &join), RESOURCE_X_APPLY_STALE); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact( - &grant, 2, &join), RESOURCE_X_APPLY_STALE); + &assertion, &retained_grant, &retained_image, &join), + RESOURCE_X_APPLY_NOT_FOUND); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact(&image, 0, &join), + RESOURCE_X_APPLY_STALE); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact(&grant, 2, &join), + RESOURCE_X_APPLY_STALE); } UT_TEST(test_resource_x_requester_join_gates_both_floors_before_successor) @@ -15057,41 +14327,40 @@ UT_TEST(test_resource_x_requester_join_gates_both_floors_before_successor) UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), RESOURCE_X_APPLY_APPLIED); make_resource_x_remote_join_pair(tag, 2, &grant, &image); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact( - &image, 0, &join), RESOURCE_X_APPLY_APPLIED); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact( - &grant, 2, &join), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact(&image, 0, &join), + RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact(&grant, 2, &join), + RESOURCE_X_APPLY_APPLIED); complete_resource_x_remote_requester_terminal(&join, &ref, &activation); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_outbound_intent_probe_exact( - 4, &settlement_intent, settlement_payload, - sizeof(settlement_payload), &examined), + UT_ASSERT_EQ( + cluster_pcm_lock_resource_x_outbound_intent_probe_exact( + 4, &settlement_intent, settlement_payload, sizeof(settlement_payload), &examined), RESOURCE_X_INTENT_PROBE_FOUND); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_outbound_intent_stage_exact( - &settlement_intent, settlement_intent.first_armed_us + 1), - RESOURCE_X_INTENT_STAGED); - UT_ASSERT(cluster_pcm_lock_resource_x_outbound_intent_complete_exact( - &settlement_intent)); + &settlement_intent, settlement_intent.first_armed_us + 1), + RESOURCE_X_INTENT_STAGED); + UT_ASSERT(cluster_pcm_lock_resource_x_outbound_intent_complete_exact(&settlement_intent)); make_resource_x_remote_join_pair(tag, 2, &grant, &image); retarget_resource_x_remote_join_pair(&grant, &image, 5, 41); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact( - &image, 0, &join), RESOURCE_X_APPLY_STALE); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact( - &grant, 2, &join), RESOURCE_X_APPLY_STALE); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact(&image, 0, &join), + RESOURCE_X_APPLY_STALE); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact(&grant, 2, &join), + RESOURCE_X_APPLY_STALE); make_resource_x_remote_join_pair(tag, 2, &grant, &image); retarget_resource_x_remote_join_pair(&grant, &image, 3, 42); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact( - &image, 0, &join), RESOURCE_X_APPLY_STALE); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact( - &grant, 2, &join), RESOURCE_X_APPLY_STALE); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact(&image, 0, &join), + RESOURCE_X_APPLY_STALE); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact(&grant, 2, &join), + RESOURCE_X_APPLY_STALE); make_resource_x_remote_join_pair(tag, 2, &grant, &image); retarget_resource_x_remote_join_pair(&grant, &image, 5, 42); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact( - &image, 0, &join), RESOURCE_X_APPLY_APPLIED); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact( - &grant, 2, &join), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact(&image, 0, &join), + RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact(&grant, 2, &join), + RESOURCE_X_APPLY_APPLIED); complete_resource_x_remote_requester_terminal(&join, &ref, &activation); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_executor_probe_exact(&ref, &snapshot), RESOURCE_X_EXECUTOR_COMPLETE); @@ -15136,9 +14405,8 @@ UT_TEST(test_resource_x_x_source_defers_self_master_grd_transition_to_ingress) cluster_node_id = 0; cluster_pcm_lock_acquire(tag, PCM_LOCK_MODE_X); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), - RESOURCE_X_APPLY_APPLIED); - block = make_resource_x_master_frame( - RESOURCE_X_WIRE_BLOCK_TO_N, tag, 2, 0); + RESOURCE_X_APPLY_APPLIED); + block = make_resource_x_master_frame(RESOURCE_X_WIRE_BLOCK_TO_N, tag, 2, 0); block.common.observed_mode = PCM_STATE_X; block.common.target_mode = PCM_STATE_N; block.common.source_candidate = 1; @@ -15146,95 +14414,90 @@ UT_TEST(test_resource_x_x_source_defers_self_master_grd_transition_to_ingress) make_resource_x_remote_join_pair(tag, 2, &grant, &image); image.common.sender_connection_generation = 84; - UT_ASSERT(cluster_resource_x_wire_encode( - RESOURCE_X_MSG_IMAGE_OR_GRANT, &image, image_payload, - sizeof(image_payload), &image_payload_bytes, &reject)); + UT_ASSERT(cluster_resource_x_wire_encode(RESOURCE_X_MSG_IMAGE_OR_GRANT, &image, image_payload, + sizeof(image_payload), &image_payload_bytes, &reject)); UT_ASSERT_EQ(image_payload_bytes, RESOURCE_X_IMAGE_V1_BYTES); - UT_ASSERT(cluster_resource_x_wire_decode( - RESOURCE_X_MSG_IMAGE_OR_GRANT, image_payload, image_payload_bytes, - &decoded, &reject)); + UT_ASSERT(cluster_resource_x_wire_decode(RESOURCE_X_MSG_IMAGE_OR_GRANT, image_payload, + image_payload_bytes, &decoded, &reject)); image = decoded; - status = make_resource_x_master_frame( - RESOURCE_X_WIRE_BLOCKED_TO_N, tag, 2, 0); + status = make_resource_x_master_frame(RESOURCE_X_WIRE_BLOCKED_TO_N, tag, 2, 0); status.common.observed_mode = PCM_STATE_X; status.common.target_mode = PCM_STATE_N; status.common.outcome = RESOURCE_X_OUTCOME_OK; status.common.flags = RESOURCE_X_COMMON_FLAG_PI_ESTABLISHED; status.blocked_has_remote_proof = true; - memcpy(status.body.blocked_to_n.source_fence, - image.body.image_envelope.source_fence, - sizeof(status.body.blocked_to_n.source_fence)); + memcpy(status.body.blocked_to_n.source_fence, image.body.image_envelope.source_fence, + sizeof(status.body.blocked_to_n.source_fence)); status.body.blocked_to_n.source_carrier_generation = image.body.image_envelope.source_carrier_generation; status.body.blocked_to_n.requester_target_generation = image.body.image_envelope.requester_target_generation; - status.body.blocked_to_n.page_scn_lsn - = image.body.image_envelope.page_scn_lsn; - status.body.blocked_to_n.dependency_count - = image.body.image_envelope.dependency_count; - memcpy(status.body.blocked_to_n.dependencies, - image.body.image_envelope.dependencies, - sizeof(status.body.blocked_to_n.dependencies)); - status.body.blocked_to_n.source_proof_crc32c - = image.common.semantic_crc32c; - status.body.blocked_to_n.page_checksum - = image.body.image_envelope.page_checksum; - status.body.blocked_to_n.source_disposition - = RESOURCE_X_DISPOSITION_REMOTE_NONWRITABLE; - status.body.blocked_to_n.proof_kind - = RESOURCE_X_PROOF_REMOTE_CARRIER; + status.body.blocked_to_n.page_scn_lsn = image.body.image_envelope.page_scn_lsn; + status.body.blocked_to_n.dependency_count = image.body.image_envelope.dependency_count; + memcpy(status.body.blocked_to_n.dependencies, image.body.image_envelope.dependencies, + sizeof(status.body.blocked_to_n.dependencies)); + status.body.blocked_to_n.source_proof_crc32c = image.common.semantic_crc32c; + status.body.blocked_to_n.page_checksum = image.body.image_envelope.page_checksum; + status.body.blocked_to_n.source_disposition = RESOURCE_X_DISPOSITION_REMOTE_NONWRITABLE; + status.body.blocked_to_n.proof_kind = RESOURCE_X_PROOF_REMOTE_CARRIER; status.body.blocked_to_n.holder_connection_generation = 91; status.body.blocked_to_n.acting_formation = 17; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_block_to_n_source_exact( - &block, 0, &status, &image), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_block_to_n_source_exact(&block, 0, &status, &image), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_holder_pair_supersedes_exact( - &block.common.logical_assertion, block.common.assertion_sequence, - 0, block.common.master_session_incarnation), RESOURCE_X_APPLY_STALE); + &block.common.logical_assertion, block.common.assertion_sequence, 0, + block.common.master_session_incarnation), + RESOURCE_X_APPLY_STALE); UT_ASSERT_EQ(cluster_pcm_lock_query(tag), PCM_LOCK_MODE_X); /* Retaining canonical type-18/type-15 bytes is not transport readiness. * The holder must finish the exact physical X revoke before publishing * either half of the pair to the outbound scanner. */ UT_ASSERT_EQ(cluster_pcm_lock_resource_x_holder_status_intent_snapshot_exact( - &block.common.logical_assertion, &status_intent, status_payload, - sizeof(status_payload)), RESOURCE_X_APPLY_NOT_FOUND); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_holder_image_intent_snapshot_exact( - &block.common.logical_assertion, &image_intent, image_payload, - sizeof(image_payload)), RESOURCE_X_APPLY_NOT_FOUND); + &block.common.logical_assertion, &status_intent, status_payload, + sizeof(status_payload)), + RESOURCE_X_APPLY_NOT_FOUND); + UT_ASSERT_EQ( + cluster_pcm_lock_resource_x_holder_image_intent_snapshot_exact( + &block.common.logical_assertion, &image_intent, image_payload, sizeof(image_payload)), + RESOURCE_X_APPLY_NOT_FOUND); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_holder_pair_publish_needed_exact( - &block.common.logical_assertion, block.common.assertion_sequence, - 0, block.common.master_session_incarnation), RESOURCE_X_APPLY_APPLIED); + &block.common.logical_assertion, block.common.assertion_sequence, 0, + block.common.master_session_incarnation), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_holder_pair_publish_exact( - &block.common.logical_assertion, block.common.assertion_sequence, - 0, block.common.master_session_incarnation), RESOURCE_X_APPLY_APPLIED); + &block.common.logical_assertion, block.common.assertion_sequence, 0, + block.common.master_session_incarnation), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_holder_pair_publish_needed_exact( - &block.common.logical_assertion, block.common.assertion_sequence, - 0, block.common.master_session_incarnation), RESOURCE_X_APPLY_DUPLICATE); + &block.common.logical_assertion, block.common.assertion_sequence, 0, + block.common.master_session_incarnation), + RESOURCE_X_APPLY_DUPLICATE); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_holder_status_intent_snapshot_exact( - &block.common.logical_assertion, &status_intent, status_payload, - sizeof(status_payload)), RESOURCE_X_APPLY_APPLIED); + &block.common.logical_assertion, &status_intent, status_payload, + sizeof(status_payload)), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(status_intent.kind, RESOURCE_X_WIRE_BLOCKED_TO_N); UT_ASSERT_EQ(status_intent.payload_bytes, RESOURCE_X_PROOF_V1_BYTES); - UT_ASSERT(cluster_resource_x_wire_decode( - RESOURCE_X_MSG_BLOCKED_TO_N, status_payload, - status_intent.payload_bytes, &decoded, &reject)); - canonical_proof_crc - = decoded.body.blocked_to_n.source_proof_crc32c; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_holder_image_intent_snapshot_exact( - &block.common.logical_assertion, &image_intent, image_payload, - sizeof(image_payload)), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT(cluster_resource_x_wire_decode(RESOURCE_X_MSG_BLOCKED_TO_N, status_payload, + status_intent.payload_bytes, &decoded, &reject)); + canonical_proof_crc = decoded.body.blocked_to_n.source_proof_crc32c; + UT_ASSERT_EQ( + cluster_pcm_lock_resource_x_holder_image_intent_snapshot_exact( + &block.common.logical_assertion, &image_intent, image_payload, sizeof(image_payload)), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(image_intent.kind, RESOURCE_X_WIRE_IMAGE_ENVELOPE); UT_ASSERT_EQ(image_intent.payload_bytes, RESOURCE_X_IMAGE_V1_BYTES); UT_ASSERT_EQ(image_intent.destination_node, 2); - UT_ASSERT(cluster_resource_x_wire_decode( - RESOURCE_X_MSG_IMAGE_OR_GRANT, image_payload, - image_intent.payload_bytes, &decoded, &reject)); + UT_ASSERT(cluster_resource_x_wire_decode(RESOURCE_X_MSG_IMAGE_OR_GRANT, image_payload, + image_intent.payload_bytes, &decoded, &reject)); UT_ASSERT_EQ(decoded.common.sender_connection_generation, UINT32_C(1)); canonical_image_crc = decoded.common.semantic_crc32c; UT_ASSERT_EQ(canonical_proof_crc, canonical_image_crc); UT_ASSERT(canonical_image_crc != image.common.semantic_crc32c); - UT_ASSERT(memcmp(decoded.body.image_envelope.page_bytes, - image.body.image_envelope.page_bytes, RESOURCE_X_PAGE_BYTES) == 0); + UT_ASSERT(memcmp(decoded.body.image_envelope.page_bytes, image.body.image_envelope.page_bytes, + RESOURCE_X_PAGE_BYTES) + == 0); for (calls = 0; calls < 12 && (!saw_status || !saw_image); calls++) { ResourceXIntentProbeResult probe_result @@ -15242,8 +14505,8 @@ UT_TEST(test_resource_x_x_source_defers_self_master_grd_transition_to_ingress) 1, &probe, probe_payload, sizeof(probe_payload), &examined); UT_ASSERT(probe_result == RESOURCE_X_INTENT_PROBE_FOUND - || probe_result == RESOURCE_X_INTENT_PROBE_MORE - || probe_result == RESOURCE_X_INTENT_PROBE_COMPLETE); + || probe_result == RESOURCE_X_INTENT_PROBE_MORE + || probe_result == RESOURCE_X_INTENT_PROBE_COMPLETE); if (probe_result != RESOURCE_X_INTENT_PROBE_FOUND) continue; if (probe.kind == RESOURCE_X_WIRE_BLOCKED_TO_N) @@ -15254,78 +14517,77 @@ UT_TEST(test_resource_x_x_source_defers_self_master_grd_transition_to_ingress) UT_ASSERT(saw_status); UT_ASSERT(saw_image); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_outbound_intent_stage_exact( - &status_intent, 101), RESOURCE_X_INTENT_STAGED); - UT_ASSERT(cluster_pcm_lock_resource_x_outbound_intent_complete_exact( - &status_intent)); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_outbound_intent_stage_exact(&status_intent, 101), + RESOURCE_X_INTENT_STAGED); + UT_ASSERT(cluster_pcm_lock_resource_x_outbound_intent_complete_exact(&status_intent)); /* A partial transport terminal is not permission to recreate only the * missing half. Keep the surviving image exact and fail closed until the * already-admitted pair finishes its normal drain. */ UT_ASSERT_EQ(cluster_pcm_lock_resource_x_holder_pair_publish_needed_exact( - &block.common.logical_assertion, block.common.assertion_sequence, - 0, block.common.master_session_incarnation), RESOURCE_X_APPLY_DUPLICATE); + &block.common.logical_assertion, block.common.assertion_sequence, 0, + block.common.master_session_incarnation), + RESOURCE_X_APPLY_DUPLICATE); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_holder_pair_publish_exact( - &block.common.logical_assertion, block.common.assertion_sequence, - 0, block.common.master_session_incarnation), - RESOURCE_X_APPLY_RECOVERY_BLOCKED); + &block.common.logical_assertion, block.common.assertion_sequence, 0, + block.common.master_session_incarnation), + RESOURCE_X_APPLY_RECOVERY_BLOCKED); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_holder_status_intent_snapshot_exact( - &block.common.logical_assertion, &probe, probe_payload, - sizeof(probe_payload)), RESOURCE_X_APPLY_NOT_FOUND); + &block.common.logical_assertion, &probe, probe_payload, sizeof(probe_payload)), + RESOURCE_X_APPLY_NOT_FOUND); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_holder_image_intent_snapshot_exact( - &block.common.logical_assertion, &probe, probe_payload, - sizeof(probe_payload)), RESOURCE_X_APPLY_APPLIED); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_outbound_intent_stage_exact( - &image_intent, 102), RESOURCE_X_INTENT_STAGED); - UT_ASSERT(cluster_pcm_lock_resource_x_outbound_intent_complete_exact( - &image_intent)); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_holder_image_exact( - &block.common.logical_assertion, &retained_image), - RESOURCE_X_APPLY_APPLIED); + &block.common.logical_assertion, &probe, probe_payload, sizeof(probe_payload)), + RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_outbound_intent_stage_exact(&image_intent, 102), + RESOURCE_X_INTENT_STAGED); + UT_ASSERT(cluster_pcm_lock_resource_x_outbound_intent_complete_exact(&image_intent)); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_holder_image_exact(&block.common.logical_assertion, + &retained_image), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(retained_image.kind, RESOURCE_X_WIRE_IMAGE_ENVELOPE); - UT_ASSERT_EQ(retained_image.common.semantic_crc32c, - canonical_image_crc); + UT_ASSERT_EQ(retained_image.common.semantic_crc32c, canonical_image_crc); UT_ASSERT(memcmp(retained_image.body.image_envelope.page_bytes, - image.body.image_envelope.page_bytes, RESOURCE_X_PAGE_BYTES) == 0); + image.body.image_envelope.page_bytes, RESOURCE_X_PAGE_BYTES) + == 0); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_holder_pair_drain_prepare_exact( - &block.common.logical_assertion, block.common.assertion_sequence, - 0, block.common.master_session_incarnation + 1, &source_generation), - RESOURCE_X_APPLY_STALE); + &block.common.logical_assertion, block.common.assertion_sequence, 0, + block.common.master_session_incarnation + 1, &source_generation), + RESOURCE_X_APPLY_STALE); UT_ASSERT_EQ(source_generation, 0); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_holder_pair_drain_prepare_exact( - &block.common.logical_assertion, block.common.assertion_sequence, - 0, block.common.master_session_incarnation, &source_generation), - RESOURCE_X_APPLY_APPLIED); - UT_ASSERT_EQ(source_generation, - image.body.image_envelope.source_carrier_generation - 1); + &block.common.logical_assertion, block.common.assertion_sequence, 0, + block.common.master_session_incarnation, &source_generation), + RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(source_generation, image.body.image_envelope.source_carrier_generation - 1); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_holder_pair_drain_commit_exact( - &block.common.logical_assertion, block.common.assertion_sequence, - 0, block.common.master_session_incarnation, source_generation), - RESOURCE_X_APPLY_APPLIED); - UT_ASSERT(resource_x_assertion_init(&tag, cluster_node_id, - &requester_assertion)); + &block.common.logical_assertion, block.common.assertion_sequence, 0, + block.common.master_session_incarnation, source_generation), + RESOURCE_X_APPLY_APPLIED); + UT_ASSERT(resource_x_assertion_init(&tag, cluster_node_id, &requester_assertion)); source_generation = UINT64_MAX; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_holder_pair_drain_prepare_exact( - &requester_assertion, block.common.assertion_sequence, - 0, block.common.master_session_incarnation, &source_generation), - RESOURCE_X_APPLY_NOT_FOUND); + &requester_assertion, block.common.assertion_sequence, 0, + block.common.master_session_incarnation, &source_generation), + RESOURCE_X_APPLY_NOT_FOUND); UT_ASSERT_EQ(source_generation, 0); source_generation = UINT64_MAX; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_holder_pair_drain_prepare_exact( - &block.common.logical_assertion, block.common.assertion_sequence, - 0, block.common.master_session_incarnation, &source_generation), - RESOURCE_X_APPLY_DUPLICATE); + &block.common.logical_assertion, block.common.assertion_sequence, 0, + block.common.master_session_incarnation, &source_generation), + RESOURCE_X_APPLY_DUPLICATE); UT_ASSERT_EQ(source_generation, 0); /* A replay of an already drained pair must not resurrect its outbound * intents or reopen the retained physical carrier. */ - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_block_to_n_source_exact( - &block, 0, &status, &image), RESOURCE_X_APPLY_DUPLICATE); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_block_to_n_source_exact(&block, 0, &status, &image), + RESOURCE_X_APPLY_DUPLICATE); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_holder_status_intent_snapshot_exact( - &block.common.logical_assertion, &status_intent, status_payload, - sizeof(status_payload)), RESOURCE_X_APPLY_NOT_FOUND); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_holder_image_intent_snapshot_exact( - &block.common.logical_assertion, &image_intent, image_payload, - sizeof(image_payload)), RESOURCE_X_APPLY_NOT_FOUND); + &block.common.logical_assertion, &status_intent, status_payload, + sizeof(status_payload)), + RESOURCE_X_APPLY_NOT_FOUND); + UT_ASSERT_EQ( + cluster_pcm_lock_resource_x_holder_image_intent_snapshot_exact( + &block.common.logical_assertion, &image_intent, image_payload, sizeof(image_payload)), + RESOURCE_X_APPLY_NOT_FOUND); /* A later direct-current-X lineage for the same requester may replace the * drained tombstone only with a strictly newer admission. A lower attempt @@ -15342,20 +14604,17 @@ UT_TEST(test_resource_x_x_source_defers_self_master_grd_transition_to_ingress) newer_image.body.image_envelope.source_carrier_generation = 62; newer_image.body.image_envelope.requester_target_generation = 40; reject = RESOURCE_X_WIRE_REJECT_NONE; - UT_ASSERT(cluster_resource_x_wire_encode( - RESOURCE_X_MSG_IMAGE_OR_GRANT, &newer_image, - newer_image_payload, sizeof(newer_image_payload), - &newer_image_payload_bytes, &reject)); + UT_ASSERT(cluster_resource_x_wire_encode(RESOURCE_X_MSG_IMAGE_OR_GRANT, &newer_image, + newer_image_payload, sizeof(newer_image_payload), + &newer_image_payload_bytes, &reject)); UT_ASSERT_EQ(newer_image_payload_bytes, RESOURCE_X_IMAGE_V1_BYTES); reject = RESOURCE_X_WIRE_REJECT_NONE; - UT_ASSERT(cluster_resource_x_wire_decode( - RESOURCE_X_MSG_IMAGE_OR_GRANT, newer_image_payload, - newer_image_payload_bytes, &newer_image, &reject)); - newer_status.body.blocked_to_n.source_proof_crc32c - = newer_image.common.semantic_crc32c; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_block_to_n_source_exact( - &newer_block, 0, &newer_status, &newer_image), - RESOURCE_X_APPLY_STALE); + UT_ASSERT(cluster_resource_x_wire_decode(RESOURCE_X_MSG_IMAGE_OR_GRANT, newer_image_payload, + newer_image_payload_bytes, &newer_image, &reject)); + newer_status.body.blocked_to_n.source_proof_crc32c = newer_image.common.semantic_crc32c; + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_block_to_n_source_exact(&newer_block, 0, &newer_status, + &newer_image), + RESOURCE_X_APPLY_STALE); /* Attempts from different requesters are in different namespaces and are * therefore not numerically comparable. Once the old pair has exact DRAIN @@ -15365,12 +14624,9 @@ UT_TEST(test_resource_x_x_source_defers_self_master_grd_transition_to_ingress) newer_block = block; newer_status = status; newer_image = image; - UT_ASSERT(resource_x_assertion_init(&tag, 3, - &newer_block.common.logical_assertion)); - UT_ASSERT(resource_x_assertion_init(&tag, 3, - &newer_status.common.logical_assertion)); - UT_ASSERT(resource_x_assertion_init(&tag, 3, - &newer_image.common.logical_assertion)); + UT_ASSERT(resource_x_assertion_init(&tag, 3, &newer_block.common.logical_assertion)); + UT_ASSERT(resource_x_assertion_init(&tag, 3, &newer_status.common.logical_assertion)); + UT_ASSERT(resource_x_assertion_init(&tag, 3, &newer_image.common.logical_assertion)); newer_block.common.assertion_sequence = 1; newer_status.common.assertion_sequence = 1; newer_status.body.blocked_to_n.source_carrier_generation = 62; @@ -15380,88 +14636,83 @@ UT_TEST(test_resource_x_x_source_defers_self_master_grd_transition_to_ingress) newer_image.body.image_envelope.source_carrier_generation = 62; newer_image.body.image_envelope.requester_target_generation = 1; reject = RESOURCE_X_WIRE_REJECT_NONE; - UT_ASSERT(cluster_resource_x_wire_encode( - RESOURCE_X_MSG_IMAGE_OR_GRANT, &newer_image, - newer_image_payload, sizeof(newer_image_payload), - &newer_image_payload_bytes, &reject)); + UT_ASSERT(cluster_resource_x_wire_encode(RESOURCE_X_MSG_IMAGE_OR_GRANT, &newer_image, + newer_image_payload, sizeof(newer_image_payload), + &newer_image_payload_bytes, &reject)); UT_ASSERT_EQ(newer_image_payload_bytes, RESOURCE_X_IMAGE_V1_BYTES); reject = RESOURCE_X_WIRE_REJECT_NONE; - UT_ASSERT(cluster_resource_x_wire_decode( - RESOURCE_X_MSG_IMAGE_OR_GRANT, newer_image_payload, - newer_image_payload_bytes, &newer_image, &reject)); - newer_status.body.blocked_to_n.source_proof_crc32c - = newer_image.common.semantic_crc32c; + UT_ASSERT(cluster_resource_x_wire_decode(RESOURCE_X_MSG_IMAGE_OR_GRANT, newer_image_payload, + newer_image_payload_bytes, &newer_image, &reject)); + newer_status.body.blocked_to_n.source_proof_crc32c = newer_image.common.semantic_crc32c; /* The retained predecessor has the same logical (tag, requester) identity, * only within one requester namespace. A different requester must not use * that predecessor as evidence for its attempt. */ UT_ASSERT_EQ(cluster_pcm_lock_resource_x_holder_pair_publish_needed_exact( - &newer_block.common.logical_assertion, - newer_block.common.assertion_sequence, 0, - newer_block.common.master_session_incarnation), - RESOURCE_X_APPLY_STALE); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_block_to_n_source_exact( - &newer_block, 0, &newer_status, &newer_image), - RESOURCE_X_APPLY_APPLIED); + &newer_block.common.logical_assertion, newer_block.common.assertion_sequence, + 0, newer_block.common.master_session_incarnation), + RESOURCE_X_APPLY_STALE); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_block_to_n_source_exact(&newer_block, 0, &newer_status, + &newer_image), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_holder_pair_publish_exact( - &newer_block.common.logical_assertion, - newer_block.common.assertion_sequence, 0, - newer_block.common.master_session_incarnation), - RESOURCE_X_APPLY_APPLIED); + &newer_block.common.logical_assertion, newer_block.common.assertion_sequence, + 0, newer_block.common.master_session_incarnation), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_holder_pair_supersedes_exact( - &block.common.logical_assertion, block.common.assertion_sequence, - 0, block.common.master_session_incarnation), RESOURCE_X_APPLY_STALE); + &block.common.logical_assertion, block.common.assertion_sequence, 0, + block.common.master_session_incarnation), + RESOURCE_X_APPLY_STALE); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_holder_pair_supersedes_exact( - &newer_block.common.logical_assertion, - newer_block.common.assertion_sequence, 0, - newer_block.common.master_session_incarnation), RESOURCE_X_APPLY_STALE); + &newer_block.common.logical_assertion, newer_block.common.assertion_sequence, + 0, newer_block.common.master_session_incarnation), + RESOURCE_X_APPLY_STALE); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_holder_pair_supersedes_exact( - &block.common.logical_assertion, block.common.assertion_sequence, - 0, block.common.master_session_incarnation + 1), - RESOURCE_X_APPLY_STALE); + &block.common.logical_assertion, block.common.assertion_sequence, 0, + block.common.master_session_incarnation + 1), + RESOURCE_X_APPLY_STALE); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_holder_status_intent_snapshot_exact( - &newer_block.common.logical_assertion, &status_intent, status_payload, - sizeof(status_payload)), RESOURCE_X_APPLY_APPLIED); + &newer_block.common.logical_assertion, &status_intent, status_payload, + sizeof(status_payload)), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_holder_image_intent_snapshot_exact( - &newer_block.common.logical_assertion, &image_intent, image_payload, - sizeof(image_payload)), RESOURCE_X_APPLY_APPLIED); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_outbound_intent_stage_exact( - &status_intent, 103), RESOURCE_X_INTENT_STAGED); - UT_ASSERT(cluster_pcm_lock_resource_x_outbound_intent_complete_exact( - &status_intent)); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_outbound_intent_stage_exact( - &image_intent, 104), RESOURCE_X_INTENT_STAGED); - UT_ASSERT(cluster_pcm_lock_resource_x_outbound_intent_complete_exact( - &image_intent)); + &newer_block.common.logical_assertion, &image_intent, image_payload, + sizeof(image_payload)), + RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_outbound_intent_stage_exact(&status_intent, 103), + RESOURCE_X_INTENT_STAGED); + UT_ASSERT(cluster_pcm_lock_resource_x_outbound_intent_complete_exact(&status_intent)); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_outbound_intent_stage_exact(&image_intent, 104), + RESOURCE_X_INTENT_STAGED); + UT_ASSERT(cluster_pcm_lock_resource_x_outbound_intent_complete_exact(&image_intent)); source_generation = UINT64_MAX; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_holder_pair_drain_prepare_exact( - &block.common.logical_assertion, block.common.assertion_sequence, - 0, block.common.master_session_incarnation, &source_generation), - RESOURCE_X_APPLY_DUPLICATE); + &block.common.logical_assertion, block.common.assertion_sequence, 0, + block.common.master_session_incarnation, &source_generation), + RESOURCE_X_APPLY_DUPLICATE); UT_ASSERT_EQ(source_generation, 0); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_holder_pair_drain_prepare_exact( - &newer_block.common.logical_assertion, - newer_block.common.assertion_sequence, 0, - newer_block.common.master_session_incarnation, &source_generation), - RESOURCE_X_APPLY_APPLIED); + &newer_block.common.logical_assertion, newer_block.common.assertion_sequence, + 0, newer_block.common.master_session_incarnation, &source_generation), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(source_generation, 61); UT_ASSERT_EQ(cluster_pcm_lock_query(tag), PCM_LOCK_MODE_X); UT_ASSERT(cluster_resource_x_reconfig_freeze(17, 18, &token)); - UT_ASSERT_EQ(cluster_resource_x_reconfig_sweep(&token, 4, &batch), - RESOURCE_X_RECONFIG_MORE); - UT_ASSERT_EQ(cluster_resource_x_reconfig_sweep(&token, 4, &batch), - RESOURCE_X_RECONFIG_ORPHAN); + UT_ASSERT_EQ(cluster_resource_x_reconfig_sweep(&token, 4, &batch), RESOURCE_X_RECONFIG_MORE); + UT_ASSERT_EQ(cluster_resource_x_reconfig_sweep(&token, 4, &batch), RESOURCE_X_RECONFIG_ORPHAN); UT_ASSERT_EQ(batch.residual_count, UINT64_C(1)); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_holder_image_exact( - &newer_block.common.logical_assertion, &retained_image), - RESOURCE_X_APPLY_APPLIED); + &newer_block.common.logical_assertion, &retained_image), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(retained_image.common.assertion_sequence, UINT64_C(1)); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_holder_status_intent_snapshot_exact( - &block.common.logical_assertion, &status_intent, status_payload, - sizeof(status_payload)), RESOURCE_X_APPLY_NOT_FOUND); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_holder_image_intent_snapshot_exact( - &block.common.logical_assertion, &image_intent, image_payload, - sizeof(image_payload)), RESOURCE_X_APPLY_NOT_FOUND); + &block.common.logical_assertion, &status_intent, status_payload, + sizeof(status_payload)), + RESOURCE_X_APPLY_NOT_FOUND); + UT_ASSERT_EQ( + cluster_pcm_lock_resource_x_holder_image_intent_snapshot_exact( + &block.common.logical_assertion, &image_intent, image_payload, sizeof(image_payload)), + RESOURCE_X_APPLY_NOT_FOUND); } static void @@ -15510,48 +14761,42 @@ check_resource_x_source_settlement_drains_only_the_exact_retained_pair(bool dele cluster_node_id = 1; fake_gcs_master_node = 0; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), - RESOURCE_X_APPLY_APPLIED); + RESOURCE_X_APPLY_APPLIED); UT_ASSERT(resource_x_assertion_init(&tag, 1, &holder_assertion)); action = cluster_pcm_lock_resource_x_bootstrap_round_step_exact( &holder_assertion, 0, 17, 31, 77, 51, 61, UINT64_C(1000), (UINT64_C(1000)) - (UINT64_C(100)), UINT64_C(100), UINT64_C(50), false, 0, &bootstrap, &terminal_ref); UT_ASSERT_EQ(action, RESOURCE_X_BOOTSTRAP_ROUND_DISPATCH_REQUEST); - bootstrap_ack = make_resource_x_bootstrap_ack_values( - &bootstrap, UINT64_C(1), UINT32_C(71)); + bootstrap_ack = make_resource_x_bootstrap_ack_values(&bootstrap, UINT64_C(1), UINT32_C(71)); action = cluster_pcm_lock_resource_x_bootstrap_round_accept_ack_exact( &bootstrap_ack, 0, 61, 77, UINT64_C(110), &bootstrap_assert); UT_ASSERT_EQ(action, RESOURCE_X_BOOTSTRAP_ROUND_DISPATCH_ASSERT); - make_resource_x_remote_join_pair( - tag, 1, &holder_grant, &holder_image); - retarget_resource_x_remote_join_pair( - &holder_grant, &holder_image, UINT64_C(3), UINT64_C(1)); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact( - &holder_image, 0, &join), RESOURCE_X_APPLY_APPLIED); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact( - &holder_grant, 0, &join), RESOURCE_X_APPLY_APPLIED); + make_resource_x_remote_join_pair(tag, 1, &holder_grant, &holder_image); + retarget_resource_x_remote_join_pair(&holder_grant, &holder_image, UINT64_C(3), UINT64_C(1)); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact(&holder_image, 0, &join), + RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact(&holder_grant, 0, &join), + RESOURCE_X_APPLY_APPLIED); holder_ref = make_resource_x_acquisition_ref(tag, 1, 17, 1); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_t1_grant_exact(&holder_ref), - RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_t1_grant_exact(&holder_ref), RESOURCE_X_APPLY_APPLIED); memset(&install, 0, sizeof(install)); install.ownership_generation = 60; install.writer_activation_token = 12; install.resource_x_activation_generation = 1; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_apply_exact( - &holder_ref, &install), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_apply_exact(&holder_ref, &install), + RESOURCE_X_APPLY_APPLIED); memset(&activation, 0, sizeof(activation)); activation.ownership_generation = install.ownership_generation; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_activate_exact( - &holder_ref, &activation), RESOURCE_X_APPLY_APPLIED); - UT_ASSERT_EQ( - cluster_pcm_lock_resource_x_bootstrap_round_publish_terminal_exact( - &holder_ref, 31, 77, 60, 3, UINT64_C(115)), - RESOURCE_X_APPLY_DUPLICATE); - UT_ASSERT(cluster_pcm_lock_resource_x_bootstrap_round_cover_matches_exact( - &holder_ref, 31, 77, 60)); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_activate_exact(&holder_ref, &activation), + RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_bootstrap_round_publish_terminal_exact( + &holder_ref, 31, 77, 60, 3, UINT64_C(115)), + RESOURCE_X_APPLY_DUPLICATE); + UT_ASSERT( + cluster_pcm_lock_resource_x_bootstrap_round_cover_matches_exact(&holder_ref, 31, 77, 60)); - block = make_resource_x_master_frame( - RESOURCE_X_WIRE_BLOCK_TO_N, tag, 2, 1); + block = make_resource_x_master_frame(RESOURCE_X_WIRE_BLOCK_TO_N, tag, 2, 1); block.common.base_authority_generation = 3; block.common.authority_generation = 3; block.common.ordered_lane = 0; @@ -15577,69 +14822,65 @@ check_resource_x_source_settlement_drains_only_the_exact_retained_pair(bool dele status.common.base_authority_generation = 3; status.common.authority_generation = 3; status.common.ordered_lane = 0; - status.body.blocked_to_n.source_proof_crc32c - = image.common.semantic_crc32c; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_block_to_n_source_exact( - &block, 0, &status, &image), RESOURCE_X_APPLY_APPLIED); + status.body.blocked_to_n.source_proof_crc32c = image.common.semantic_crc32c; + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_block_to_n_source_exact(&block, 0, &status, &image), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT(cluster_pcm_lock_resource_x_holder_pair_retained_fence_exact( &tag, 0, block.common.master_session_incarnation, 17, image.body.image_envelope.source_carrier_generation)); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_holder_pair_publish_exact( - &block.common.logical_assertion, block.common.assertion_sequence, - 0, block.common.master_session_incarnation), + &block.common.logical_assertion, block.common.assertion_sequence, 0, + block.common.master_session_incarnation), + RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_holder_status_intent_snapshot_exact( + &block.common.logical_assertion, &status_intent, status_payload, + sizeof(status_payload)), + RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ( + cluster_pcm_lock_resource_x_holder_image_intent_snapshot_exact( + &block.common.logical_assertion, &image_intent, image_payload, sizeof(image_payload)), RESOURCE_X_APPLY_APPLIED); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_holder_status_intent_snapshot_exact( - &block.common.logical_assertion, &status_intent, status_payload, - sizeof(status_payload)), RESOURCE_X_APPLY_APPLIED); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_holder_image_intent_snapshot_exact( - &block.common.logical_assertion, &image_intent, image_payload, - sizeof(image_payload)), RESOURCE_X_APPLY_APPLIED); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_outbound_intent_stage_exact( - &status_intent, 105), RESOURCE_X_INTENT_STAGED); - UT_ASSERT(cluster_pcm_lock_resource_x_outbound_intent_complete_exact( - &status_intent)); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_outbound_intent_stage_exact( - &image_intent, 106), RESOURCE_X_INTENT_STAGED); - UT_ASSERT(cluster_pcm_lock_resource_x_outbound_intent_complete_exact( - &image_intent)); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_outbound_intent_stage_exact(&status_intent, 105), + RESOURCE_X_INTENT_STAGED); + UT_ASSERT(cluster_pcm_lock_resource_x_outbound_intent_complete_exact(&status_intent)); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_outbound_intent_stage_exact(&image_intent, 106), + RESOURCE_X_INTENT_STAGED); + UT_ASSERT(cluster_pcm_lock_resource_x_outbound_intent_complete_exact(&image_intent)); for (calls = 0; calls < 12; calls++) { probe_result = cluster_pcm_lock_resource_x_outbound_intent_probe_exact( - 1, &requester_settlement_intent, - requester_settlement_payload, + 1, &requester_settlement_intent, requester_settlement_payload, sizeof(requester_settlement_payload), &examined); UT_ASSERT(probe_result == RESOURCE_X_INTENT_PROBE_FOUND - || probe_result == RESOURCE_X_INTENT_PROBE_MORE - || probe_result == RESOURCE_X_INTENT_PROBE_COMPLETE); + || probe_result == RESOURCE_X_INTENT_PROBE_MORE + || probe_result == RESOURCE_X_INTENT_PROBE_COMPLETE); if (probe_result == RESOURCE_X_INTENT_PROBE_FOUND && requester_settlement_intent.body.owner_kind - == RESOURCE_X_INTENT_OWNER_REQUESTER_SETTLEMENT) + == RESOURCE_X_INTENT_OWNER_REQUESTER_SETTLEMENT) break; } UT_ASSERT_EQ(probe_result, RESOURCE_X_INTENT_PROBE_FOUND); UT_ASSERT_EQ(requester_settlement_intent.body.owner_kind, - RESOURCE_X_INTENT_OWNER_REQUESTER_SETTLEMENT); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_outbound_intent_stage_exact( - &requester_settlement_intent, 107), RESOURCE_X_INTENT_STAGED); - UT_ASSERT(cluster_pcm_lock_resource_x_outbound_intent_complete_exact( - &requester_settlement_intent)); + RESOURCE_X_INTENT_OWNER_REQUESTER_SETTLEMENT); + UT_ASSERT_EQ( + cluster_pcm_lock_resource_x_outbound_intent_stage_exact(&requester_settlement_intent, 107), + RESOURCE_X_INTENT_STAGED); + UT_ASSERT( + cluster_pcm_lock_resource_x_outbound_intent_complete_exact(&requester_settlement_intent)); UT_ASSERT(cluster_pcm_lock_resource_x_holder_pair_retained_fence_exact( &tag, 0, block.common.master_session_incarnation, 17, image.body.image_envelope.source_carrier_generation)); - UT_ASSERT( - !cluster_pcm_lock_resource_x_holder_pair_retained_fence_exact( - &tag, 0, block.common.master_session_incarnation + 1, 17, - image.body.image_envelope.source_carrier_generation)); - UT_ASSERT( - !cluster_pcm_lock_resource_x_holder_pair_retained_fence_exact( - &tag, 0, block.common.master_session_incarnation, 17, - image.body.image_envelope.source_carrier_generation + 1)); + UT_ASSERT(!cluster_pcm_lock_resource_x_holder_pair_retained_fence_exact( + &tag, 0, block.common.master_session_incarnation + 1, 17, + image.body.image_envelope.source_carrier_generation)); + UT_ASSERT(!cluster_pcm_lock_resource_x_holder_pair_retained_fence_exact( + &tag, 0, block.common.master_session_incarnation, 17, + image.body.image_envelope.source_carrier_generation + 1)); cluster_pcm_grd_protocol_debt_snapshot(&debt); UT_ASSERT_EQ(debt.retained_entry_count, UINT64_C(1)); UT_ASSERT_EQ(stop_pcm_poll(false, NULL, NULL, NULL), CLUSTER_NORMAL_STOP_PENDING); - UT_ASSERT(cluster_resource_x_wire_decode( - RESOURCE_X_MSG_BLOCKED_TO_N, status_payload, - status_intent.payload_bytes, &settlement, &reject)); + UT_ASSERT(cluster_resource_x_wire_decode(RESOURCE_X_MSG_BLOCKED_TO_N, status_payload, + status_intent.payload_bytes, &settlement, &reject)); settlement.kind = RESOURCE_X_WIRE_SOURCE_SETTLEMENT_V2; settlement.common.observed_mode = PCM_STATE_N; settlement.common.target_mode = PCM_STATE_N; @@ -15659,35 +14900,29 @@ check_resource_x_source_settlement_drains_only_the_exact_retained_pair(bool dele stale = settlement; stale.body.blocked_to_n.page_scn_lsn++; memset(&plan, 0x5a, sizeof(plan)); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_source_settlement_prepare_exact( - &stale, 0, &plan), RESOURCE_X_APPLY_STALE); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_source_settlement_prepare_exact(&stale, 0, &plan), + RESOURCE_X_APPLY_STALE); UT_ASSERT(!plan.valid); UT_ASSERT_EQ(plan.source_generation, UINT64_C(0)); - UT_ASSERT_EQ( - cluster_pcm_lock_resource_x_source_settlement_prepare_observed_exact( - &settlement, 0, &plan, &prepare_observation), - RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_source_settlement_prepare_observed_exact( + &settlement, 0, &plan, &prepare_observation), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT(plan.valid); UT_ASSERT_EQ(prepare_observation.commit_stage, - RESOURCE_X_SOURCE_SETTLEMENT_COMMIT_STAGE_TERMINAL_COVER); + RESOURCE_X_SOURCE_SETTLEMENT_COMMIT_STAGE_TERMINAL_COVER); UT_ASSERT_EQ(prepare_observation.mismatch_mask, UINT32_C(0)); UT_ASSERT_EQ(prepare_observation.current_round_phase, UINT8_C(4)); UT_ASSERT_EQ(prepare_observation.current_owner_state, UINT8_C(0)); - UT_ASSERT_EQ(prepare_observation.current_terminal_cover_present, - UINT8_C(1)); + UT_ASSERT_EQ(prepare_observation.current_terminal_cover_present, UINT8_C(1)); UT_ASSERT_EQ(prepare_observation.current_holder_status_valid, UINT8_C(2)); UT_ASSERT_EQ(prepare_observation.current_holder_image_valid, UINT8_C(2)); UT_ASSERT_EQ(prepare_observation.current_status_intent_state, UINT8_C(0)); UT_ASSERT_EQ(prepare_observation.current_image_intent_state, UINT8_C(0)); - UT_ASSERT_EQ(prepare_observation.current_pair_source_generation, - UINT64_C(60)); - UT_ASSERT_EQ(prepare_observation.current_pair_carrier_generation, - UINT64_C(61)); - UT_ASSERT_EQ(prepare_observation.current_pair_observed_mode, - (uint8)PCM_STATE_X); + UT_ASSERT_EQ(prepare_observation.current_pair_source_generation, UINT64_C(60)); + UT_ASSERT_EQ(prepare_observation.current_pair_carrier_generation, UINT64_C(61)); + UT_ASSERT_EQ(prepare_observation.current_pair_observed_mode, (uint8)PCM_STATE_X); UT_ASSERT_EQ(plan.source_mode, (uint8)PCM_STATE_X); - UT_ASSERT_EQ(plan.cover_action, - (uint8)RESOURCE_X_SETTLEMENT_COVER_CLOSE_EXACT_X); + UT_ASSERT_EQ(plan.cover_action, (uint8)RESOURCE_X_SETTLEMENT_COVER_CLOSE_EXACT_X); UT_ASSERT_EQ(plan.source_generation, UINT64_C(60)); UT_ASSERT_EQ(plan.carrier_generation, UINT64_C(61)); UT_ASSERT_EQ(plan.terminal_cached_generation, UINT64_C(60)); @@ -15704,24 +14939,24 @@ check_resource_x_source_settlement_drains_only_the_exact_retained_pair(bool dele stale_plan.carrier_generation++; stale_plan.terminal_cached_generation++; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_source_settlement_commit_exact( - &settlement, 0, &stale_plan, &commit_observation), - RESOURCE_X_APPLY_STALE); + &settlement, 0, &stale_plan, &commit_observation), + RESOURCE_X_APPLY_STALE); UT_ASSERT_EQ(commit_observation.commit_stage, - RESOURCE_X_SOURCE_SETTLEMENT_COMMIT_STAGE_TERMINAL_COVER); - UT_ASSERT_EQ(commit_observation.current_pair_observed_mode, - (uint8)PCM_STATE_X); - UT_ASSERT((commit_observation.mismatch_mask - & RESOURCE_X_SOURCE_SETTLEMENT_MISMATCH_SOURCE_GENERATION) != 0); - UT_ASSERT(cluster_pcm_lock_resource_x_bootstrap_round_cover_matches_exact( - &holder_ref, 31, 77, 60)); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_source_settlement_commit_exact( - &settlement, 0, &plan, &commit_observation), - RESOURCE_X_APPLY_APPLIED); + RESOURCE_X_SOURCE_SETTLEMENT_COMMIT_STAGE_TERMINAL_COVER); + UT_ASSERT_EQ(commit_observation.current_pair_observed_mode, (uint8)PCM_STATE_X); + UT_ASSERT( + (commit_observation.mismatch_mask & RESOURCE_X_SOURCE_SETTLEMENT_MISMATCH_SOURCE_GENERATION) + != 0); + UT_ASSERT( + cluster_pcm_lock_resource_x_bootstrap_round_cover_matches_exact(&holder_ref, 31, 77, 60)); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_source_settlement_commit_exact(&settlement, 0, &plan, + &commit_observation), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(commit_observation.commit_stage, - RESOURCE_X_SOURCE_SETTLEMENT_COMMIT_STAGE_TERMINAL_COVER); + RESOURCE_X_SOURCE_SETTLEMENT_COMMIT_STAGE_TERMINAL_COVER); UT_ASSERT_EQ(commit_observation.mismatch_mask, UINT32_C(0)); - UT_ASSERT(!cluster_pcm_lock_resource_x_bootstrap_round_cover_matches_exact( - &holder_ref, 31, 77, 60)); + UT_ASSERT( + !cluster_pcm_lock_resource_x_bootstrap_round_cover_matches_exact(&holder_ref, 31, 77, 60)); /* The exact drained tombstone makes the still-retained pair bounded * duplicate/recovery history, not unfinished protocol debt. Keep the * bytes for an exact kind-10 replay while exposing zero terminal debt. */ @@ -15729,18 +14964,18 @@ check_resource_x_source_settlement_drains_only_the_exact_retained_pair(bool dele UT_ASSERT_EQ(debt.retained_entry_count, UINT64_C(0)); UT_ASSERT_EQ(debt.invalid_entry_count, UINT64_C(0)); UT_ASSERT_EQ(stop_pcm_poll(false, NULL, NULL, NULL), CLUSTER_NORMAL_STOP_READY); - UT_ASSERT( - !cluster_pcm_lock_resource_x_holder_pair_retained_fence_exact( - &tag, 0, block.common.master_session_incarnation, 17, - image.body.image_envelope.source_carrier_generation)); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_source_settlement_ack_build_exact( - &settlement, 64, &ack), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT(!cluster_pcm_lock_resource_x_holder_pair_retained_fence_exact( + &tag, 0, block.common.master_session_incarnation, 17, + image.body.image_envelope.source_carrier_generation)); + UT_ASSERT_EQ( + cluster_pcm_lock_resource_x_source_settlement_ack_build_exact(&settlement, 64, &ack), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(ack.kind, RESOURCE_X_WIRE_SOURCE_SETTLEMENT_ACK_V2); UT_ASSERT_EQ(ack.common.outcome, RESOURCE_X_OUTCOME_OK); UT_ASSERT_EQ(ack.common.sender_connection_generation, UINT32_C(64)); memset(&plan, 0x5a, sizeof(plan)); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_source_settlement_prepare_exact( - &settlement, 0, &plan), RESOURCE_X_APPLY_DUPLICATE); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_source_settlement_prepare_exact(&settlement, 0, &plan), + RESOURCE_X_APPLY_DUPLICATE); UT_ASSERT(!plan.valid); UT_ASSERT_EQ(plan.source_generation, UINT64_C(0)); } @@ -15766,18 +15001,18 @@ UT_TEST(test_resource_x_source_settlement_debt_participates_in_same_token_r8_r10 char *clean; char *clean_end; - decoder = strstr(source, - "\npcm_resource_x_source_settlement_debt_decode_locked("); - proof = strstr(source, - "\npcm_resource_x_reconfig_proof_slot_locked("); - proof_end = proof != NULL ? strstr(proof, - "\nstatic bool\npcm_resource_x_zero_proof_phase_exact(") : NULL; + decoder = strstr(source, "\npcm_resource_x_source_settlement_debt_decode_locked("); + proof = strstr(source, "\npcm_resource_x_reconfig_proof_slot_locked("); + proof_end = proof != NULL + ? strstr(proof, "\nstatic bool\npcm_resource_x_zero_proof_phase_exact(") + : NULL; sweep = strstr(source, "\ncluster_resource_x_reconfig_sweep("); - sweep_end = sweep != NULL ? strstr(sweep, - "\nbool\ncluster_resource_x_reconfig_zero_proof_exact(") : NULL; + sweep_end = sweep != NULL + ? strstr(sweep, "\nbool\ncluster_resource_x_reconfig_zero_proof_exact(") + : NULL; clean = strstr(source, "\npcm_resource_x_terminal_state_locked("); - clean_end = clean != NULL ? strstr(clean, - "\nstatic bool\npcm_resource_x_clean_state_locked(") : NULL; + clean_end + = clean != NULL ? strstr(clean, "\nstatic bool\npcm_resource_x_clean_state_locked(") : NULL; UT_ASSERT_NOT_NULL(decoder); UT_ASSERT_NOT_NULL(proof); @@ -15786,22 +15021,14 @@ UT_TEST(test_resource_x_source_settlement_debt_participates_in_same_token_r8_r10 UT_ASSERT_NOT_NULL(sweep_end); UT_ASSERT_NOT_NULL(clean); UT_ASSERT_NOT_NULL(clean_end); - UT_ASSERT(strstr(proof, - "pcm_resource_x_source_settlement_debt_decode_locked(") < proof_end); - UT_ASSERT(strstr(proof, - "RESOURCE_X_SOURCE_SETTLEMENT_PENDING") < proof_end); - UT_ASSERT(strstr(proof, - "RESOURCE_X_SOURCE_SETTLEMENT_ACKED") < proof_end); - UT_ASSERT(strstr(sweep, - "pcm_resource_x_source_settlement_debt_decode_locked(") < sweep_end); - UT_ASSERT(strstr(sweep, - "memset(&master_state->source_settlement") < sweep_end); - UT_ASSERT(strstr(clean, - "pcm_resource_x_source_settlement_debt_decode_locked(") < clean_end); - UT_ASSERT(strstr(clean, - "RESOURCE_X_SOURCE_SETTLEMENT_PENDING") < clean_end); - UT_ASSERT(strstr(clean, - "RESOURCE_X_SOURCE_SETTLEMENT_ACKED") < clean_end); + UT_ASSERT(strstr(proof, "pcm_resource_x_source_settlement_debt_decode_locked(") < proof_end); + UT_ASSERT(strstr(proof, "RESOURCE_X_SOURCE_SETTLEMENT_PENDING") < proof_end); + UT_ASSERT(strstr(proof, "RESOURCE_X_SOURCE_SETTLEMENT_ACKED") < proof_end); + UT_ASSERT(strstr(sweep, "pcm_resource_x_source_settlement_debt_decode_locked(") < sweep_end); + UT_ASSERT(strstr(sweep, "memset(&master_state->source_settlement") < sweep_end); + UT_ASSERT(strstr(clean, "pcm_resource_x_source_settlement_debt_decode_locked(") < clean_end); + UT_ASSERT(strstr(clean, "RESOURCE_X_SOURCE_SETTLEMENT_PENDING") < clean_end); + UT_ASSERT(strstr(clean, "RESOURCE_X_SOURCE_SETTLEMENT_ACKED") < clean_end); free(source); } @@ -15823,52 +15050,51 @@ UT_TEST(test_resource_x_holder_pair_drain_allows_master_requester_colocation) cluster_pcm_lock_acquire(tag, PCM_LOCK_MODE_X); fake_gcs_master_node = 1; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), - RESOURCE_X_APPLY_APPLIED); - block = make_resource_x_master_frame( - RESOURCE_X_WIRE_BLOCK_TO_N, tag, 1, 0); + RESOURCE_X_APPLY_APPLIED); + block = make_resource_x_master_frame(RESOURCE_X_WIRE_BLOCK_TO_N, tag, 1, 0); block.common.observed_mode = PCM_STATE_X; block.common.target_mode = PCM_STATE_N; block.common.source_candidate = 1; block.common.retain_pi_if_dirty = 1; make_resource_x_remote_join_pair(tag, 1, &grant, &image); status = make_resource_x_remote_blocked_frame(tag, 1, 0); - status.body.blocked_to_n.source_proof_crc32c - = image.common.semantic_crc32c; + status.body.blocked_to_n.source_proof_crc32c = image.common.semantic_crc32c; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_block_to_n_source_exact( - &block, 1, &status, &image), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_block_to_n_source_exact(&block, 1, &status, &image), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_holder_pair_publish_exact( - &block.common.logical_assertion, block.common.assertion_sequence, - 1, block.common.master_session_incarnation), RESOURCE_X_APPLY_APPLIED); + &block.common.logical_assertion, block.common.assertion_sequence, 1, + block.common.master_session_incarnation), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_holder_status_intent_snapshot_exact( - &block.common.logical_assertion, &status_intent, status_payload, - sizeof(status_payload)), RESOURCE_X_APPLY_APPLIED); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_holder_image_intent_snapshot_exact( - &block.common.logical_assertion, &image_intent, image_payload, - sizeof(image_payload)), RESOURCE_X_APPLY_APPLIED); + &block.common.logical_assertion, &status_intent, status_payload, + sizeof(status_payload)), + RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ( + cluster_pcm_lock_resource_x_holder_image_intent_snapshot_exact( + &block.common.logical_assertion, &image_intent, image_payload, sizeof(image_payload)), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(status_intent.destination_node, UINT32_C(1)); UT_ASSERT_EQ(image_intent.destination_node, UINT32_C(1)); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_outbound_intent_stage_exact( - &status_intent, 105), RESOURCE_X_INTENT_STAGED); - UT_ASSERT(cluster_pcm_lock_resource_x_outbound_intent_complete_exact( - &status_intent)); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_outbound_intent_stage_exact( - &image_intent, 106), RESOURCE_X_INTENT_STAGED); - UT_ASSERT(cluster_pcm_lock_resource_x_outbound_intent_complete_exact( - &image_intent)); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_outbound_intent_stage_exact(&status_intent, 105), + RESOURCE_X_INTENT_STAGED); + UT_ASSERT(cluster_pcm_lock_resource_x_outbound_intent_complete_exact(&status_intent)); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_outbound_intent_stage_exact(&image_intent, 106), + RESOURCE_X_INTENT_STAGED); + UT_ASSERT(cluster_pcm_lock_resource_x_outbound_intent_complete_exact(&image_intent)); /* Master and requester are independent authenticated roles, but a local * master request legitimately assigns both to node 1. Colocation must * not invalidate an otherwise exact retained pair. */ UT_ASSERT_EQ(cluster_pcm_lock_resource_x_holder_pair_drain_prepare_exact( - &block.common.logical_assertion, block.common.assertion_sequence, - 1, block.common.master_session_incarnation, &source_generation), - RESOURCE_X_APPLY_APPLIED); + &block.common.logical_assertion, block.common.assertion_sequence, 1, + block.common.master_session_incarnation, &source_generation), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(source_generation, UINT64_C(60)); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_holder_pair_drain_commit_exact( - &block.common.logical_assertion, block.common.assertion_sequence, - 1, block.common.master_session_incarnation, source_generation), - RESOURCE_X_APPLY_APPLIED); + &block.common.logical_assertion, block.common.assertion_sequence, 1, + block.common.master_session_incarnation, source_generation), + RESOURCE_X_APPLY_APPLIED); } UT_TEST(test_resource_x_remote_master_uses_exact_installed_holder_lineage) @@ -15891,20 +15117,19 @@ UT_TEST(test_resource_x_remote_master_uses_exact_installed_holder_lineage) cluster_node_id = 0; fake_gcs_master_node = 1; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), - RESOURCE_X_APPLY_APPLIED); + RESOURCE_X_APPLY_APPLIED); /* First install the exact current X carrier from authenticated master 1. * The requester terminal deliberately leaves this non-master node's GRD * mirror at N; its existing requester base records final authority 3. */ make_resource_x_remote_join_pair(tag, 0, &grant, &image); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact( - &image, 2, &join), RESOURCE_X_APPLY_APPLIED); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact( - &grant, 1, &join), RESOURCE_X_APPLY_APPLIED); - complete_resource_x_remote_requester_terminal( - &join, &installed_ref, &activation); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_executor_probe_exact( - &installed_ref, &executor), RESOURCE_X_EXECUTOR_COMPLETE); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact(&image, 2, &join), + RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_join_exact(&grant, 1, &join), + RESOURCE_X_APPLY_APPLIED); + complete_resource_x_remote_requester_terminal(&join, &installed_ref, &activation); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_executor_probe_exact(&installed_ref, &executor), + RESOURCE_X_EXECUTOR_COMPLETE); UT_ASSERT_EQ(executor.requester_base_generation, 3); UT_ASSERT_EQ(cluster_pcm_lock_query(tag), PCM_LOCK_MODE_N); @@ -15912,8 +15137,7 @@ UT_TEST(test_resource_x_remote_master_uses_exact_installed_holder_lineage) * master-only serialization can advance while this node remains the same * physical X carrier. The installed final authority is therefore a * monotonic lineage floor, not an equality with the current type-17 base. */ - block = make_resource_x_master_frame( - RESOURCE_X_WIRE_BLOCK_TO_N, tag, 3, 0); + block = make_resource_x_master_frame(RESOURCE_X_WIRE_BLOCK_TO_N, tag, 3, 0); block.common.base_authority_generation = 6; block.common.authority_generation = 6; block.common.assertion_sequence = 43; @@ -15934,42 +15158,37 @@ UT_TEST(test_resource_x_remote_master_uses_exact_installed_holder_lineage) status.common.outcome = RESOURCE_X_OUTCOME_OK; status.common.flags = RESOURCE_X_COMMON_FLAG_PI_ESTABLISHED; status.common.authority_generation = 6; - memcpy(status.body.blocked_to_n.source_fence, - image.body.image_envelope.source_fence, - sizeof(status.body.blocked_to_n.source_fence)); + memcpy(status.body.blocked_to_n.source_fence, image.body.image_envelope.source_fence, + sizeof(status.body.blocked_to_n.source_fence)); status.body.blocked_to_n.source_carrier_generation = image.body.image_envelope.source_carrier_generation; status.body.blocked_to_n.requester_target_generation = 43; - status.body.blocked_to_n.page_scn_lsn - = image.body.image_envelope.page_scn_lsn; - status.body.blocked_to_n.dependency_count - = image.body.image_envelope.dependency_count; - memcpy(status.body.blocked_to_n.dependencies, - image.body.image_envelope.dependencies, - sizeof(status.body.blocked_to_n.dependencies)); - status.body.blocked_to_n.source_proof_crc32c - = image.common.semantic_crc32c; - status.body.blocked_to_n.page_checksum - = image.body.image_envelope.page_checksum; - status.body.blocked_to_n.source_disposition - = RESOURCE_X_DISPOSITION_REMOTE_NONWRITABLE; - status.body.blocked_to_n.proof_kind - = RESOURCE_X_PROOF_REMOTE_CARRIER; + status.body.blocked_to_n.page_scn_lsn = image.body.image_envelope.page_scn_lsn; + status.body.blocked_to_n.dependency_count = image.body.image_envelope.dependency_count; + memcpy(status.body.blocked_to_n.dependencies, image.body.image_envelope.dependencies, + sizeof(status.body.blocked_to_n.dependencies)); + status.body.blocked_to_n.source_proof_crc32c = image.common.semantic_crc32c; + status.body.blocked_to_n.page_checksum = image.body.image_envelope.page_checksum; + status.body.blocked_to_n.source_disposition = RESOURCE_X_DISPOSITION_REMOTE_NONWRITABLE; + status.body.blocked_to_n.proof_kind = RESOURCE_X_PROOF_REMOTE_CARRIER; status.body.blocked_to_n.holder_connection_generation = 51; status.body.blocked_to_n.acting_formation = 17; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_block_to_n_source_exact( - &block, 1, &status, &image), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_block_to_n_source_exact(&block, 1, &status, &image), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(cluster_pcm_lock_query(tag), PCM_LOCK_MODE_N); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_holder_pair_publish_exact( - &block.common.logical_assertion, block.common.assertion_sequence, - 1, block.common.master_session_incarnation), RESOURCE_X_APPLY_APPLIED); + &block.common.logical_assertion, block.common.assertion_sequence, 1, + block.common.master_session_incarnation), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_holder_status_intent_snapshot_exact( - &block.common.logical_assertion, &status_intent, status_payload, - sizeof(status_payload)), RESOURCE_X_APPLY_APPLIED); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_holder_image_intent_snapshot_exact( - &block.common.logical_assertion, &image_intent, image_payload, - sizeof(image_payload)), RESOURCE_X_APPLY_APPLIED); + &block.common.logical_assertion, &status_intent, status_payload, + sizeof(status_payload)), + RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ( + cluster_pcm_lock_resource_x_holder_image_intent_snapshot_exact( + &block.common.logical_assertion, &image_intent, image_payload, sizeof(image_payload)), + RESOURCE_X_APPLY_APPLIED); } UT_TEST(test_resource_x_remote_master_retains_exact_current_x_without_local_authority) @@ -15993,26 +15212,24 @@ UT_TEST(test_resource_x_remote_master_retains_exact_current_x_without_local_auth cluster_node_id = 0; fake_gcs_master_node = 1; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), - RESOURCE_X_APPLY_APPLIED); + RESOURCE_X_APPLY_APPLIED); /* The GCS caller has already frozen and revalidated this node's exact * BufferDesc X carrier. A remote authoritative master may therefore ask * this node to retain the indivisible type-18/type-15 pair even when this * process has no local authority entry for the page. */ - block = make_resource_x_master_frame( - RESOURCE_X_WIRE_BLOCK_TO_N, tag, 3, 0); + block = make_resource_x_master_frame(RESOURCE_X_WIRE_BLOCK_TO_N, tag, 3, 0); block.common.observed_mode = PCM_STATE_X; block.common.target_mode = PCM_STATE_N; block.common.source_candidate = 1; block.common.retain_pi_if_dirty = 1; make_resource_x_remote_join_pair(tag, 3, &grant, &image); status = make_resource_x_remote_blocked_frame(tag, 3, 0); - status.body.blocked_to_n.source_proof_crc32c - = image.common.semantic_crc32c; + status.body.blocked_to_n.source_proof_crc32c = image.common.semantic_crc32c; UT_ASSERT_EQ(cluster_pcm_lock_query(tag), PCM_LOCK_MODE_N); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_block_to_n_source_exact( - &block, 1, &status, &image), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_block_to_n_source_exact(&block, 1, &status, &image), + RESOURCE_X_APPLY_APPLIED); /* Creating retained-pair storage must not mint a local GRD owner. */ UT_ASSERT(cluster_pcm_lock_authority_snapshot(tag, &authority)); @@ -16020,22 +15237,23 @@ UT_TEST(test_resource_x_remote_master_retains_exact_current_x_without_local_auth UT_ASSERT_EQ(authority.x_holder_node, -1); UT_ASSERT_EQ(authority.s_holders_bitmap, UINT32_C(0)); UT_ASSERT_EQ(authority.transition_count, UINT64_C(0)); - UT_ASSERT(pcm_entry_ref_acquire( - &tag, false, &entry_ref, &acquire_result)); + UT_ASSERT(pcm_entry_ref_acquire(&tag, false, &entry_ref, &acquire_result)); binding_generation = entry_ref.binding_generation; pcm_entry_ref_release(&entry_ref); - UT_ASSERT(!pcm_entry_retire_classify_exact( - &tag, binding_generation, &why)); + UT_ASSERT(!pcm_entry_retire_classify_exact(&tag, binding_generation, &why)); UT_ASSERT_EQ(why, PCM_RETIRE_REFUSAL_RETAINED_PAIR_PRESENT); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_holder_pair_publish_exact( - &block.common.logical_assertion, block.common.assertion_sequence, - 1, block.common.master_session_incarnation), RESOURCE_X_APPLY_APPLIED); + &block.common.logical_assertion, block.common.assertion_sequence, 1, + block.common.master_session_incarnation), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_holder_status_intent_snapshot_exact( - &block.common.logical_assertion, &status_intent, status_payload, - sizeof(status_payload)), RESOURCE_X_APPLY_APPLIED); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_holder_image_intent_snapshot_exact( - &block.common.logical_assertion, &image_intent, image_payload, - sizeof(image_payload)), RESOURCE_X_APPLY_APPLIED); + &block.common.logical_assertion, &status_intent, status_payload, + sizeof(status_payload)), + RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ( + cluster_pcm_lock_resource_x_holder_image_intent_snapshot_exact( + &block.common.logical_assertion, &image_intent, image_payload, sizeof(image_payload)), + RESOURCE_X_APPLY_APPLIED); } static ResourceXDecodedFrame prepared_finish_block; @@ -16067,7 +15285,7 @@ check_resource_x_prepared_retain_episode_mode(uint64 old_generation, int old_req cluster_node_id = 1; fake_gcs_master_node = 0; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), - RESOURCE_X_APPLY_APPLIED); + RESOURCE_X_APPLY_APPLIED); if (old_generation != 0) { ResourceXIntentSlot status_intent; @@ -16158,8 +15376,8 @@ check_resource_x_prepared_retain_episode_mode(uint64 old_generation, int old_req } cover_ref = setup_resource_x_test_terminal_cover_at_base(tag, UINT64_C(91), source_base - 2); - UT_ASSERT(cluster_pcm_lock_resource_x_bootstrap_round_cover_matches_exact( - &cover_ref, 31, 77, 91)); + UT_ASSERT( + cluster_pcm_lock_resource_x_bootstrap_round_cover_matches_exact(&cover_ref, 31, 77, 91)); UT_ASSERT(cluster_pcm_lock_authority_snapshot(tag, &authority)); if (old_generation == 0) UT_ASSERT(authority.transition_count > UINT64_C(3)); @@ -16167,8 +15385,7 @@ check_resource_x_prepared_retain_episode_mode(uint64 old_generation, int old_req UT_ASSERT_EQ(authority.x_holder_node, -1); UT_ASSERT_EQ(authority.s_holders_bitmap, UINT32_C(0)); - block = make_resource_x_master_frame( - RESOURCE_X_WIRE_BLOCK_TO_N, tag, 2, 1); + block = make_resource_x_master_frame(RESOURCE_X_WIRE_BLOCK_TO_N, tag, 2, 1); block.payload_bytes = RESOURCE_X_CONTROL_V1_BYTES; block.common.base_authority_generation = source_base; block.common.authority_generation = source_base; @@ -16182,16 +15399,16 @@ check_resource_x_prepared_retain_episode_mode(uint64 old_generation, int old_req memset(&lineage, 0, sizeof(lineage)); memset(&owner, 0, sizeof(owner)); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_terminal_x_revoke_claim_exact( - &block, 0, 77, 91, 12, 9, UINT64_C(130), - &lineage, &owner), RESOURCE_X_APPLY_APPLIED); + &block, 0, 77, 91, 12, 9, UINT64_C(130), &lineage, &owner), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT(cluster_pcm_lock_resource_x_terminal_x_revoke_revalidate_held_exact( &block, 0, 77, 91, &owner, &lineage)); make_resource_x_remote_join_pair(tag, 2, &grant, &image); retarget_resource_x_remote_join_pair(&grant, &image, source_base + 2, UINT64_C(42)); image.common.ordered_lane = 0; - set_resource_x_test_source_fence( - image.body.image_envelope.source_fence, UINT64_C(91), PCM_STATE_X); + set_resource_x_test_source_fence(image.body.image_envelope.source_fence, UINT64_C(91), + PCM_STATE_X); image.body.image_envelope.source_carrier_generation = UINT64_C(92); canonicalize_resource_x_test_image(&image); status = make_resource_x_remote_blocked_frame(tag, 2, 1); @@ -16200,25 +15417,18 @@ check_resource_x_prepared_retain_episode_mode(uint64 old_generation, int old_req status.common.retain_pi_if_dirty = 0; status.common.outcome = RESOURCE_X_OUTCOME_OK; status.common.flags = RESOURCE_X_COMMON_FLAG_PI_ESTABLISHED; - memcpy(status.body.blocked_to_n.source_fence, - image.body.image_envelope.source_fence, - sizeof(status.body.blocked_to_n.source_fence)); + memcpy(status.body.blocked_to_n.source_fence, image.body.image_envelope.source_fence, + sizeof(status.body.blocked_to_n.source_fence)); status.body.blocked_to_n.source_carrier_generation = image.body.image_envelope.source_carrier_generation; status.body.blocked_to_n.requester_target_generation = UINT64_C(42); - status.body.blocked_to_n.page_scn_lsn - = image.body.image_envelope.page_scn_lsn; - status.body.blocked_to_n.dependency_count - = image.body.image_envelope.dependency_count; - memcpy(status.body.blocked_to_n.dependencies, - image.body.image_envelope.dependencies, - sizeof(status.body.blocked_to_n.dependencies)); - status.body.blocked_to_n.source_proof_crc32c - = image.common.semantic_crc32c; - status.body.blocked_to_n.page_checksum - = image.body.image_envelope.page_checksum; - status.body.blocked_to_n.source_disposition - = RESOURCE_X_DISPOSITION_REMOTE_NONWRITABLE; + status.body.blocked_to_n.page_scn_lsn = image.body.image_envelope.page_scn_lsn; + status.body.blocked_to_n.dependency_count = image.body.image_envelope.dependency_count; + memcpy(status.body.blocked_to_n.dependencies, image.body.image_envelope.dependencies, + sizeof(status.body.blocked_to_n.dependencies)); + status.body.blocked_to_n.source_proof_crc32c = image.common.semantic_crc32c; + status.body.blocked_to_n.page_checksum = image.body.image_envelope.page_checksum; + status.body.blocked_to_n.source_disposition = RESOURCE_X_DISPOSITION_REMOTE_NONWRITABLE; status.body.blocked_to_n.proof_kind = RESOURCE_X_PROOF_REMOTE_CARRIER; status.body.blocked_to_n.holder_connection_generation = 51; status.body.blocked_to_n.acting_formation = 17; @@ -16238,19 +15448,17 @@ check_resource_x_prepared_retain_episode_mode(uint64 old_generation, int old_req old_generation == 0 ? RESOURCE_X_APPLY_BAD_STATE : RESOURCE_X_APPLY_STALE); stale_owner = owner; stale_owner.owner_procno++; - UT_ASSERT_EQ( - cluster_pcm_lock_resource_x_block_to_n_prepared_x_source_exact( - &block, 0, &status, &image, &revoking, &stale_owner), - RESOURCE_X_APPLY_STALE); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_block_to_n_prepared_x_source_exact( + &block, 0, &status, &image, &revoking, &stale_owner), + RESOURCE_X_APPLY_STALE); stale_revoking = revoking; stale_revoking.generation++; - UT_ASSERT_EQ( - cluster_pcm_lock_resource_x_block_to_n_prepared_x_source_exact( - &block, 0, &status, &image, &stale_revoking, &owner), - RESOURCE_X_APPLY_STALE); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_block_to_n_prepared_x_source_exact( + &block, 0, &status, &image, &stale_revoking, &owner), + RESOURCE_X_APPLY_STALE); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_block_to_n_drop_x_source_exact( - &block, 0, &status, &image, &revoking, &owner), - RESOURCE_X_APPLY_STALE); + &block, 0, &status, &image, &revoking, &owner), + RESOURCE_X_APPLY_STALE); UT_ASSERT_EQ( cluster_pcm_lock_resource_x_block_to_n_prepared_x_source_exact(&block, 0, &status, &image, &revoking, &owner), @@ -16597,7 +15805,7 @@ check_resource_x_self_master_source_episode(bool with_history, ForkNumber fork, if (with_history) cluster_pcm_lock_acquire(tag, PCM_LOCK_MODE_X); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), - RESOURCE_X_APPLY_APPLIED); + RESOURCE_X_APPLY_APPLIED); UT_ASSERT(resource_x_assertion_init(&tag, 0, &holder_assertion)); if (with_history) { ResourceXIntentSlot status_intent; @@ -16727,8 +15935,8 @@ check_resource_x_self_master_source_episode(bool with_history, ForkNumber fork, (UINT64_C(1000)) - (UINT64_C(100)), UINT64_C(100), UINT64_C(50), holder_generation - 1, 5, false, 0, &request, &terminal_ref); UT_ASSERT_EQ(action, RESOURCE_X_BOOTSTRAP_ROUND_DISPATCH_REQUEST); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_bootstrap_request_exact( - &request, 0, 61, 77, 31, 71, &ack), + UT_ASSERT_EQ( + cluster_pcm_lock_resource_x_bootstrap_request_exact(&request, 0, 61, 77, 31, 71, &ack), RESOURCE_X_APPLY_APPLIED); if (with_history) { UT_ASSERT_EQ(ack.kind, RESOURCE_X_WIRE_ASSERT_X); @@ -16749,13 +15957,11 @@ check_resource_x_self_master_source_episode(bool with_history, ForkNumber fork, memset(&durable, 0, sizeof(durable)); durable.assertion = holder_assertion; - durable.base_authority_generation - = assert_frame.common.base_authority_generation; + durable.base_authority_generation = assert_frame.common.base_authority_generation; durable.resource_formation = 17; durable.master_session_incarnation = 31; durable.assertion_sequence = assert_frame.common.assertion_sequence; - durable.requester_target_generation - = assert_frame.common.assertion_sequence; + durable.requester_target_generation = assert_frame.common.assertion_sequence; durable.page_scn_lsn = 82; durable.page_checksum = UINT32_C(0x12345678); durable.source_proof_crc32c = UINT32_C(0x87654321); @@ -16804,25 +16010,23 @@ check_resource_x_self_master_source_episode(bool with_history, ForkNumber fork, if (ut_current_failed) return; - expected_ref = make_resource_x_acquisition_ref( - tag, 0, 17, assert_frame.common.assertion_sequence); + expected_ref + = make_resource_x_acquisition_ref(tag, 0, 17, assert_frame.common.assertion_sequence); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_t1_grant_exact(&expected_ref), - RESOURCE_X_APPLY_APPLIED); + RESOURCE_X_APPLY_APPLIED); memset(&install, 0, sizeof(install)); install.ownership_generation = holder_generation; install.writer_activation_token = 12; - install.resource_x_activation_generation - = assert_frame.common.assertion_sequence; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_apply_exact( - &expected_ref, &install), RESOURCE_X_APPLY_APPLIED); + install.resource_x_activation_generation = assert_frame.common.assertion_sequence; + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_requester_apply_exact(&expected_ref, &install), + RESOURCE_X_APPLY_APPLIED); settlement = assert_frame; settlement.kind = RESOURCE_X_WIRE_INSTALL_SETTLEMENT; memset(&settlement.body, 0, sizeof(settlement.body)); settlement.common.ordered_lane = 0; settlement.common.outcome = RESOURCE_X_OUTCOME_OK; - settlement.common.authority_generation - = snapshot.final_authority_generation; + settlement.common.authority_generation = snapshot.final_authority_generation; settlement.body.install_settlement.conversion_base_generation = assert_frame.common.base_authority_generation; settlement.body.install_settlement.final_authority_generation @@ -16831,24 +16035,19 @@ check_resource_x_self_master_source_episode(bool with_history, ForkNumber fork, settlement.body.install_settlement.requester_target_generation = assert_frame.common.assertion_sequence; settlement.body.install_settlement.page_scn_lsn = 82; - settlement.body.install_settlement.page_checksum - = UINT32_C(0x12345678); - settlement.body.install_settlement.source_proof_crc32c - = UINT32_C(0x87654321); + settlement.body.install_settlement.page_checksum = UINT32_C(0x12345678); + settlement.body.install_settlement.source_proof_crc32c = UINT32_C(0x87654321); settlement.body.install_settlement.installed_mode = PCM_STATE_X; - settlement.body.install_settlement.requester_role - = RESOURCE_X_REQUESTER_ROLE_ACQUIRER; - settlement.body.install_settlement.terminal_outcome - = RESOURCE_X_OUTCOME_OK; - settlement.body.install_settlement.terminal_state - = RESOURCE_X_SETTLEMENT_TERMINAL_INSTALLED; + settlement.body.install_settlement.requester_role = RESOURCE_X_REQUESTER_ROLE_ACQUIRER; + settlement.body.install_settlement.terminal_outcome = RESOURCE_X_OUTCOME_OK; + settlement.body.install_settlement.terminal_state = RESOURCE_X_SETTLEMENT_TERMINAL_INSTALLED; if (with_history) { settlement.body.install_settlement.page_scn_lsn = image.body.image_envelope.page_scn_lsn; settlement.body.install_settlement.page_checksum = image.body.image_envelope.page_checksum; settlement.body.install_settlement.source_proof_crc32c = image.common.semantic_crc32c; } - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_install_settlement_exact( - &settlement, 0, &snapshot), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_install_settlement_exact(&settlement, 0, &snapshot), + RESOURCE_X_APPLY_APPLIED); base_generation = snapshot.final_authority_generation; if (with_history) { ResourceXBufferActivationProof activation; @@ -16890,9 +16089,8 @@ check_resource_x_self_master_source_episode(bool with_history, ForkNumber fork, RESOURCE_X_APPLY_APPLIED); make_resource_x_remote_join_pair(tag, next_requester, &grant, &image); - retarget_resource_x_remote_join_pair( - &grant, &image, base_generation + UINT64_C(2), - block.common.assertion_sequence); + retarget_resource_x_remote_join_pair(&grant, &image, base_generation + UINT64_C(2), + block.common.assertion_sequence); image.common.ordered_lane = 0; set_resource_x_test_source_fence(image.body.image_envelope.source_fence, holder_generation, PCM_STATE_X); @@ -16904,26 +16102,18 @@ check_resource_x_self_master_source_episode(bool with_history, ForkNumber fork, status.common.retain_pi_if_dirty = 0; status.common.outcome = RESOURCE_X_OUTCOME_OK; status.common.flags = RESOURCE_X_COMMON_FLAG_PI_ESTABLISHED; - memcpy(status.body.blocked_to_n.source_fence, - image.body.image_envelope.source_fence, - sizeof(status.body.blocked_to_n.source_fence)); + memcpy(status.body.blocked_to_n.source_fence, image.body.image_envelope.source_fence, + sizeof(status.body.blocked_to_n.source_fence)); status.body.blocked_to_n.source_carrier_generation = image.body.image_envelope.source_carrier_generation; - status.body.blocked_to_n.requester_target_generation - = block.common.assertion_sequence; - status.body.blocked_to_n.page_scn_lsn - = image.body.image_envelope.page_scn_lsn; - status.body.blocked_to_n.dependency_count - = image.body.image_envelope.dependency_count; - memcpy(status.body.blocked_to_n.dependencies, - image.body.image_envelope.dependencies, - sizeof(status.body.blocked_to_n.dependencies)); - status.body.blocked_to_n.source_proof_crc32c - = image.common.semantic_crc32c; - status.body.blocked_to_n.page_checksum - = image.body.image_envelope.page_checksum; - status.body.blocked_to_n.source_disposition - = RESOURCE_X_DISPOSITION_REMOTE_NONWRITABLE; + status.body.blocked_to_n.requester_target_generation = block.common.assertion_sequence; + status.body.blocked_to_n.page_scn_lsn = image.body.image_envelope.page_scn_lsn; + status.body.blocked_to_n.dependency_count = image.body.image_envelope.dependency_count; + memcpy(status.body.blocked_to_n.dependencies, image.body.image_envelope.dependencies, + sizeof(status.body.blocked_to_n.dependencies)); + status.body.blocked_to_n.source_proof_crc32c = image.common.semantic_crc32c; + status.body.blocked_to_n.page_checksum = image.body.image_envelope.page_checksum; + status.body.blocked_to_n.source_disposition = RESOURCE_X_DISPOSITION_REMOTE_NONWRITABLE; status.body.blocked_to_n.proof_kind = RESOURCE_X_PROOF_REMOTE_CARRIER; status.body.blocked_to_n.holder_connection_generation = 51; status.body.blocked_to_n.acting_formation = 17; @@ -17025,45 +16215,38 @@ UT_TEST(test_resource_x_master_local_and_durable_proofs_are_exact_and_closed) reset_fake_pcm_runtime(4); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), RESOURCE_X_APPLY_APPLIED); - assertion = make_resource_x_master_frame(RESOURCE_X_WIRE_ASSERT_X, - local_tag, 1, 1); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact(&assertion, 1, - &snapshot), + assertion = make_resource_x_master_frame(RESOURCE_X_WIRE_ASSERT_X, local_tag, 1, 1); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact(&assertion, 1, &snapshot), RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(snapshot.phase, RESOURCE_X_MASTER_WAIT_PROOF); - local_proof = make_resource_x_master_frame( - RESOURCE_X_WIRE_LOCAL_PROOF_DECLARATION, local_tag, 1, 1); + local_proof + = make_resource_x_master_frame(RESOURCE_X_WIRE_LOCAL_PROOF_DECLARATION, local_tag, 1, 1); local_proof.common.observed_mode = PCM_STATE_S; local_proof.common.outcome = RESOURCE_X_OUTCOME_OK; local_proof.body.local_proof.local_holder_authority_generation = 71; local_proof.body.local_proof.requester_target_generation = 41; local_proof.body.local_proof.dependency_count = 2; - local_proof.body.local_proof.dependency_vector_crc32c - = UINT32_C(0x11223344); + local_proof.body.local_proof.dependency_vector_crc32c = UINT32_C(0x11223344); local_proof.body.local_proof.page_checksum = UINT32_C(0x55667788); - local_proof.body.local_proof.local_image_proof_crc32c - = UINT32_C(0x99aabbcc); + local_proof.body.local_proof.local_image_proof_crc32c = UINT32_C(0x99aabbcc); local_proof.body.local_proof.requester_connection_generation = 73; local_proof.body.local_proof.local_proof_generation = 74; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_local_proof_exact(&local_proof, - 1, &snapshot), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_local_proof_exact(&local_proof, 1, &snapshot), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(snapshot.phase, RESOURCE_X_MASTER_GRANT_COMMITTED); UT_ASSERT_EQ(snapshot.proof_kind, RESOURCE_X_PROOF_LOCAL_IMAGE); - UT_ASSERT_EQ(snapshot.source_disposition, - RESOURCE_X_DISPOSITION_LOCAL_IMAGE); + UT_ASSERT_EQ(snapshot.source_disposition, RESOURCE_X_DISPOSITION_LOCAL_IMAGE); UT_ASSERT_EQ(snapshot.requester_target_generation, 41); UT_ASSERT_EQ(snapshot.final_authority_generation, 2); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_local_proof_exact(&local_proof, - 1, &snapshot), RESOURCE_X_APPLY_DUPLICATE); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_local_proof_exact(&local_proof, 1, &snapshot), + RESOURCE_X_APPLY_DUPLICATE); reset_fake_pcm_runtime(4); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), RESOURCE_X_APPLY_APPLIED); - assertion = make_resource_x_master_frame(RESOURCE_X_WIRE_ASSERT_X, - durable_tag, 2, 2); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact(&assertion, 2, - &snapshot), + assertion = make_resource_x_master_frame(RESOURCE_X_WIRE_ASSERT_X, durable_tag, 2, 2); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact(&assertion, 2, &snapshot), RESOURCE_X_APPLY_APPLIED); memset(&durable_proof, 0, sizeof(durable_proof)); durable_proof.assertion = assertion.common.logical_assertion; @@ -17075,33 +16258,31 @@ UT_TEST(test_resource_x_master_local_and_durable_proofs_are_exact_and_closed) durable_proof.page_scn_lsn = 82; durable_proof.page_checksum = UINT32_C(0x12345678); durable_proof.source_proof_crc32c = UINT32_C(0x87654321); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_durable_proof_exact(&durable_proof, - &snapshot), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_durable_proof_exact(&durable_proof, &snapshot), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(snapshot.phase, RESOURCE_X_MASTER_GRANT_COMMITTED); UT_ASSERT_EQ(snapshot.proof_kind, RESOURCE_X_PROOF_DURABLE_STORAGE); - UT_ASSERT_EQ(snapshot.source_disposition, - RESOURCE_X_DISPOSITION_DURABLE_STORAGE); + UT_ASSERT_EQ(snapshot.source_disposition, RESOURCE_X_DISPOSITION_DURABLE_STORAGE); UT_ASSERT_EQ(snapshot.requester_target_generation, 41); UT_ASSERT_EQ(snapshot.final_authority_generation, 2); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_grant_intent_snapshot_exact( - &assertion.common.logical_assertion, &grant_intent, grant_bytes, - sizeof(grant_bytes)), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ( + cluster_pcm_lock_resource_x_grant_intent_snapshot_exact( + &assertion.common.logical_assertion, &grant_intent, grant_bytes, sizeof(grant_bytes)), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(grant_intent.state, RESOURCE_X_INTENT_SLOT_ARMED); UT_ASSERT_EQ(grant_intent.logical_generation, 41); UT_ASSERT_EQ(grant_intent.authority_generation, 2); UT_ASSERT_EQ(grant_intent.destination_node, 2); UT_ASSERT_EQ(grant_intent.payload_bytes, RESOURCE_X_PROOF_V1_BYTES); UT_ASSERT_EQ(grant_intent.kind, RESOURCE_X_WIRE_AUTHORITY_GRANT); - UT_ASSERT_EQ(grant_intent.body.owner_kind, - RESOURCE_X_INTENT_OWNER_MASTER_GRANT); + UT_ASSERT_EQ(grant_intent.body.owner_kind, RESOURCE_X_INTENT_OWNER_MASTER_GRANT); UT_ASSERT(resource_x_assertion_equal(&grant_intent.body.assertion, - &assertion.common.logical_assertion)); - UT_ASSERT(cluster_resource_x_wire_decode(RESOURCE_X_MSG_IMAGE_OR_GRANT, - grant_bytes, sizeof(grant_bytes), &decoded_grant, &reject)); + &assertion.common.logical_assertion)); + UT_ASSERT(cluster_resource_x_wire_decode(RESOURCE_X_MSG_IMAGE_OR_GRANT, grant_bytes, + sizeof(grant_bytes), &decoded_grant, &reject)); UT_ASSERT_EQ(decoded_grant.kind, RESOURCE_X_WIRE_AUTHORITY_GRANT); UT_ASSERT_EQ(decoded_grant.common.authority_generation, 2); - UT_ASSERT_EQ(decoded_grant.body.authority_grant.requester_target_generation, - 41); + UT_ASSERT_EQ(decoded_grant.body.authority_grant.requester_target_generation, 41); /* A retained PI makes durable storage non-authoritative. */ reset_fake_pcm_runtime(4); @@ -17110,14 +16291,12 @@ UT_TEST(test_resource_x_master_local_and_durable_proofs_are_exact_and_closed) cluster_pcm_lock_downgrade(pi_tag, PCM_LOCK_MODE_N, true); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), RESOURCE_X_APPLY_APPLIED); - assertion = make_resource_x_master_frame(RESOURCE_X_WIRE_ASSERT_X, - pi_tag, 2, 2); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact(&assertion, 2, - &snapshot), + assertion = make_resource_x_master_frame(RESOURCE_X_WIRE_ASSERT_X, pi_tag, 2, 2); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact(&assertion, 2, &snapshot), RESOURCE_X_APPLY_APPLIED); durable_proof.assertion = assertion.common.logical_assertion; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_durable_proof_exact(&durable_proof, - &snapshot), RESOURCE_X_APPLY_BAD_STATE); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_durable_proof_exact(&durable_proof, &snapshot), + RESOURCE_X_APPLY_BAD_STATE); UT_ASSERT_EQ(snapshot.phase, RESOURCE_X_MASTER_WAIT_PROOF); UT_ASSERT_EQ(snapshot.proof_kind, 0); } @@ -17130,7 +16309,7 @@ UT_TEST(test_resource_x_master_multi_s_blockers_advance_exact_frontier) ResourceXDecodedFrame blocked; ResourceXDecodedFrame local_proof; ResourceXMasterSnapshot snapshot; - const int32 blocker_nodes[] = {0, 2, 3}; + const int32 blocker_nodes[] = { 0, 2, 3 }; uint64 base_authority_generation; int node; @@ -17141,35 +16320,35 @@ UT_TEST(test_resource_x_master_multi_s_blockers_advance_exact_frontier) } cluster_node_id = 0; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), - RESOURCE_X_APPLY_APPLIED); + RESOURCE_X_APPLY_APPLIED); UT_ASSERT(cluster_pcm_lock_authority_snapshot(tag, &authority)); UT_ASSERT_EQ(authority.transition_count, UINT64_C(1)); UT_ASSERT_EQ(authority.s_holders_bitmap, UINT32_C(0xf)); base_authority_generation = authority.transition_count; - assertion = make_resource_x_master_frame( - RESOURCE_X_WIRE_ASSERT_X, tag, 1, 1); + assertion = make_resource_x_master_frame(RESOURCE_X_WIRE_ASSERT_X, tag, 1, 1); assertion.common.base_authority_generation = base_authority_generation; assertion.common.authority_generation = base_authority_generation; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_adapter_base_bind_exact( - &assertion.common.logical_assertion, 17, - base_authority_generation, &authority), RESOURCE_X_APPLY_DUPLICATE); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact( - &assertion, 1, &snapshot), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ( + cluster_pcm_lock_resource_x_adapter_base_bind_exact(&assertion.common.logical_assertion, 17, + base_authority_generation, &authority), + RESOURCE_X_APPLY_DUPLICATE); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact(&assertion, 1, &snapshot), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(snapshot.phase, RESOURCE_X_MASTER_WAIT_BLOCKERS); UT_ASSERT_EQ(snapshot.incompatible_holders_bitmap, UINT32_C(0xd)); for (node = 0; node < lengthof(blocker_nodes); node++) { - blocked = make_resource_x_master_frame( - RESOURCE_X_WIRE_BLOCKED_TO_N, tag, 1, blocker_nodes[node]); + blocked = make_resource_x_master_frame(RESOURCE_X_WIRE_BLOCKED_TO_N, tag, 1, + blocker_nodes[node]); blocked.common.base_authority_generation = base_authority_generation; blocked.common.authority_generation = base_authority_generation; blocked.common.observed_mode = PCM_STATE_S; blocked.common.target_mode = PCM_STATE_N; blocked.common.outcome = RESOURCE_X_OUTCOME_OK; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_blocked_to_n_exact( - &blocked, blocker_nodes[node], &snapshot), - RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_blocked_to_n_exact(&blocked, blocker_nodes[node], + &snapshot), + RESOURCE_X_APPLY_APPLIED); } UT_ASSERT_EQ(snapshot.phase, RESOURCE_X_MASTER_WAIT_PROOF); UT_ASSERT_EQ(snapshot.blocked_holders_bitmap, UINT32_C(0xd)); @@ -17177,8 +16356,7 @@ UT_TEST(test_resource_x_master_multi_s_blockers_advance_exact_frontier) UT_ASSERT_EQ(authority.transition_count, UINT64_C(4)); UT_ASSERT_EQ(authority.s_holders_bitmap, UINT32_C(1) << 1); - local_proof = make_resource_x_master_frame( - RESOURCE_X_WIRE_LOCAL_PROOF_DECLARATION, tag, 1, 1); + local_proof = make_resource_x_master_frame(RESOURCE_X_WIRE_LOCAL_PROOF_DECLARATION, tag, 1, 1); local_proof.common.base_authority_generation = base_authority_generation; local_proof.common.authority_generation = base_authority_generation; local_proof.common.observed_mode = PCM_STATE_S; @@ -17187,12 +16365,11 @@ UT_TEST(test_resource_x_master_multi_s_blockers_advance_exact_frontier) local_proof.body.local_proof.requester_target_generation = 41; local_proof.body.local_proof.page_scn_lsn = 82; local_proof.body.local_proof.page_checksum = UINT32_C(0x55667788); - local_proof.body.local_proof.local_image_proof_crc32c - = UINT32_C(0x99aabbcc); + local_proof.body.local_proof.local_image_proof_crc32c = UINT32_C(0x99aabbcc); local_proof.body.local_proof.requester_connection_generation = 73; local_proof.body.local_proof.local_proof_generation = 74; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_local_proof_exact( - &local_proof, 1, &snapshot), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_local_proof_exact(&local_proof, 1, &snapshot), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(snapshot.phase, RESOURCE_X_MASTER_GRANT_COMMITTED); UT_ASSERT_EQ(snapshot.final_authority_generation, UINT64_C(5)); UT_ASSERT(cluster_pcm_lock_authority_snapshot(tag, &authority)); @@ -17217,33 +16394,29 @@ UT_TEST(test_resource_x_local_settlement_reconciles_exact_requester_prestate) reset_fake_pcm_runtime(4); cluster_node_id = 1; - cluster_pcm_lock_acquire(tag, - scenario == 0 ? PCM_LOCK_MODE_S : PCM_LOCK_MODE_X); + cluster_pcm_lock_acquire(tag, scenario == 0 ? PCM_LOCK_MODE_S : PCM_LOCK_MODE_X); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), RESOURCE_X_APPLY_APPLIED); - assertion = make_resource_x_master_frame( - RESOURCE_X_WIRE_ASSERT_X, tag, 1, 1); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact( - &assertion, 1, &snapshot), RESOURCE_X_APPLY_APPLIED); + assertion = make_resource_x_master_frame(RESOURCE_X_WIRE_ASSERT_X, tag, 1, 1); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact(&assertion, 1, &snapshot), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(snapshot.phase, RESOURCE_X_MASTER_WAIT_PROOF); UT_ASSERT_EQ(snapshot.incompatible_holders_bitmap, 0); - local_proof = make_resource_x_master_frame( - RESOURCE_X_WIRE_LOCAL_PROOF_DECLARATION, tag, 1, 1); - local_proof.common.observed_mode - = scenario == 0 ? PCM_STATE_S : PCM_STATE_X; + local_proof + = make_resource_x_master_frame(RESOURCE_X_WIRE_LOCAL_PROOF_DECLARATION, tag, 1, 1); + local_proof.common.observed_mode = scenario == 0 ? PCM_STATE_S : PCM_STATE_X; local_proof.common.outcome = RESOURCE_X_OUTCOME_OK; local_proof.body.local_proof.local_holder_authority_generation = 71; local_proof.body.local_proof.requester_target_generation = 41; local_proof.body.local_proof.page_scn_lsn = 82; local_proof.body.local_proof.page_checksum = UINT32_C(0x55667788); - local_proof.body.local_proof.local_image_proof_crc32c - = UINT32_C(0x99aabbcc); + local_proof.body.local_proof.local_image_proof_crc32c = UINT32_C(0x99aabbcc); local_proof.body.local_proof.requester_connection_generation = 73; local_proof.body.local_proof.local_proof_generation = 74; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_local_proof_exact( - &local_proof, 1, &snapshot), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_local_proof_exact(&local_proof, 1, &snapshot), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(snapshot.phase, RESOURCE_X_MASTER_GRANT_COMMITTED); UT_ASSERT_EQ(snapshot.proof_kind, RESOURCE_X_PROOF_LOCAL_IMAGE); UT_ASSERT(cluster_pcm_lock_authority_snapshot(tag, &authority)); @@ -17253,8 +16426,7 @@ UT_TEST(test_resource_x_local_settlement_reconciles_exact_requester_prestate) UT_ASSERT_EQ(authority.pending_x_requester_node, -1); UT_ASSERT_EQ(authority.pending_x_since_lsn, 0); - settlement = make_resource_x_master_frame( - RESOURCE_X_WIRE_INSTALL_SETTLEMENT, tag, 1, 1); + settlement = make_resource_x_master_frame(RESOURCE_X_WIRE_INSTALL_SETTLEMENT, tag, 1, 1); settlement.common.outcome = RESOURCE_X_OUTCOME_OK; settlement.common.authority_generation = 2; settlement.body.install_settlement.conversion_base_generation = 1; @@ -17262,26 +16434,24 @@ UT_TEST(test_resource_x_local_settlement_reconciles_exact_requester_prestate) settlement.body.install_settlement.requester_connection_generation = 73; settlement.body.install_settlement.requester_target_generation = 41; settlement.body.install_settlement.page_scn_lsn = 82; - settlement.body.install_settlement.page_checksum - = UINT32_C(0x55667788); - settlement.body.install_settlement.source_proof_crc32c - = UINT32_C(0x99aabbcc); + settlement.body.install_settlement.page_checksum = UINT32_C(0x55667788); + settlement.body.install_settlement.source_proof_crc32c = UINT32_C(0x99aabbcc); settlement.body.install_settlement.installed_mode = PCM_STATE_X; - settlement.body.install_settlement.requester_role - = RESOURCE_X_REQUESTER_ROLE_ACQUIRER; - settlement.body.install_settlement.terminal_outcome - = RESOURCE_X_OUTCOME_OK; + settlement.body.install_settlement.requester_role = RESOURCE_X_REQUESTER_ROLE_ACQUIRER; + settlement.body.install_settlement.terminal_outcome = RESOURCE_X_OUTCOME_OK; settlement.body.install_settlement.terminal_state = RESOURCE_X_SETTLEMENT_TERMINAL_INSTALLED; if (scenario == 0) { - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_install_settlement_exact( - &settlement, 1, &snapshot), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ( + cluster_pcm_lock_resource_x_install_settlement_exact(&settlement, 1, &snapshot), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(snapshot.phase, RESOURCE_X_MASTER_SETTLED); UT_ASSERT_EQ(cluster_pcm_lock_query(tag), PCM_LOCK_MODE_X); } else { cluster_pcm_lock_downgrade(tag, PCM_LOCK_MODE_N, false); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_install_settlement_exact( - &settlement, 1, &snapshot), RESOURCE_X_APPLY_BAD_STATE); + UT_ASSERT_EQ( + cluster_pcm_lock_resource_x_install_settlement_exact(&settlement, 1, &snapshot), + RESOURCE_X_APPLY_BAD_STATE); UT_ASSERT_EQ(snapshot.phase, RESOURCE_X_MASTER_GRANT_COMMITTED); UT_ASSERT_EQ(cluster_pcm_lock_query(tag), PCM_LOCK_MODE_N); } @@ -17307,17 +16477,15 @@ UT_TEST(test_resource_x_master_settlement_release_starts_fifo_successor) reset_fake_pcm_runtime(4); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), RESOURCE_X_APPLY_APPLIED); - first_assert = make_resource_x_master_frame(RESOURCE_X_WIRE_ASSERT_X, - tag, 1, 1); - second_assert = make_resource_x_master_frame(RESOURCE_X_WIRE_ASSERT_X, - tag, 2, 2); + first_assert = make_resource_x_master_frame(RESOURCE_X_WIRE_ASSERT_X, tag, 1, 1); + second_assert = make_resource_x_master_frame(RESOURCE_X_WIRE_ASSERT_X, tag, 2, 2); second_assert.common.assertion_sequence = 42; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact(&first_assert, 1, - &snapshot), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact(&first_assert, 1, &snapshot), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(snapshot.phase, RESOURCE_X_MASTER_WAIT_PROOF); UT_ASSERT_EQ(snapshot.is_head, 1); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact(&second_assert, 2, - &snapshot), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact(&second_assert, 2, &snapshot), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(snapshot.phase, RESOURCE_X_MASTER_QUEUED); UT_ASSERT_EQ(snapshot.is_head, 0); @@ -17331,19 +16499,18 @@ UT_TEST(test_resource_x_master_settlement_release_starts_fifo_successor) durable.page_scn_lsn = 82; durable.page_checksum = UINT32_C(0x12345678); durable.source_proof_crc32c = UINT32_C(0x87654321); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_durable_proof_exact(&durable, - &snapshot), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_durable_proof_exact(&durable, &snapshot), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(snapshot.final_authority_generation, 2); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_grant_intent_snapshot_exact( - &first_assert.common.logical_assertion, &grant_intent, grant_bytes, - sizeof(grant_bytes)), RESOURCE_X_APPLY_APPLIED); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_grant_intent_stage_exact( - &grant_intent, 101), RESOURCE_X_INTENT_STAGED); - UT_ASSERT(cluster_pcm_lock_resource_x_grant_intent_complete_exact( - &grant_intent)); - - settlement = make_resource_x_master_frame( - RESOURCE_X_WIRE_INSTALL_SETTLEMENT, tag, 1, 1); + &first_assert.common.logical_assertion, &grant_intent, grant_bytes, + sizeof(grant_bytes)), + RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_grant_intent_stage_exact(&grant_intent, 101), + RESOURCE_X_INTENT_STAGED); + UT_ASSERT(cluster_pcm_lock_resource_x_grant_intent_complete_exact(&grant_intent)); + + settlement = make_resource_x_master_frame(RESOURCE_X_WIRE_INSTALL_SETTLEMENT, tag, 1, 1); settlement.common.outcome = RESOURCE_X_OUTCOME_OK; settlement.common.authority_generation = 2; settlement.body.install_settlement.conversion_base_generation = 1; @@ -17352,76 +16519,73 @@ UT_TEST(test_resource_x_master_settlement_release_starts_fifo_successor) settlement.body.install_settlement.requester_target_generation = 41; settlement.body.install_settlement.page_scn_lsn = 82; settlement.body.install_settlement.page_checksum = UINT32_C(0x12345678); - settlement.body.install_settlement.source_proof_crc32c - = UINT32_C(0x87654321); + settlement.body.install_settlement.source_proof_crc32c = UINT32_C(0x87654321); settlement.body.install_settlement.installed_mode = PCM_STATE_X; - settlement.body.install_settlement.requester_role - = RESOURCE_X_REQUESTER_ROLE_ACQUIRER; + settlement.body.install_settlement.requester_role = RESOURCE_X_REQUESTER_ROLE_ACQUIRER; settlement.body.install_settlement.terminal_outcome = RESOURCE_X_OUTCOME_OK; - settlement.body.install_settlement.terminal_state - = RESOURCE_X_SETTLEMENT_TERMINAL_INSTALLED; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_install_settlement_exact( - &settlement, 1, &snapshot), RESOURCE_X_APPLY_APPLIED); + settlement.body.install_settlement.terminal_state = RESOURCE_X_SETTLEMENT_TERMINAL_INSTALLED; + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_install_settlement_exact(&settlement, 1, &snapshot), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(snapshot.phase, RESOURCE_X_MASTER_SETTLED); UT_ASSERT_EQ(cluster_pcm_lock_query(tag), PCM_LOCK_MODE_X); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_master_snapshot_exact( - &second_assert.common.logical_assertion, &snapshot), - RESOURCE_X_APPLY_APPLIED); + &second_assert.common.logical_assertion, &snapshot), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(snapshot.phase, RESOURCE_X_MASTER_WAIT_BLOCKERS); UT_ASSERT_EQ(snapshot.incompatible_holders_bitmap, UINT32_C(1) << 1); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_current_x_successor_exact( - &tag, 1, &preserve_current_x), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ( + cluster_pcm_lock_resource_x_current_x_successor_exact(&tag, 1, &preserve_current_x), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT(preserve_current_x); - release = make_resource_x_master_frame(RESOURCE_X_WIRE_RELEASE_X, - tag, 1, 1); + release = make_resource_x_master_frame(RESOURCE_X_WIRE_RELEASE_X, tag, 1, 1); release.common.observed_mode = PCM_STATE_X; release.common.target_mode = PCM_STATE_N; release.common.outcome = RESOURCE_X_OUTCOME_OK; release.common.authority_generation = 2; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_release_x_exact(&release, 1, - &snapshot), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_release_x_exact(&release, 1, &snapshot), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(snapshot.phase, RESOURCE_X_MASTER_RELEASED); /* A terminal requester remains the exact current source until its FIFO * successor consumes BLOCK_TO_N and returns type-18. Releasing to N first * would strand the successor at N+historical-PI with no current carrier. */ UT_ASSERT_EQ(cluster_pcm_lock_query(tag), PCM_LOCK_MODE_X); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_release_x_exact(&release, 1, - &snapshot), RESOURCE_X_APPLY_DUPLICATE); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_release_x_exact(&release, 1, &snapshot), + RESOURCE_X_APPLY_DUPLICATE); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_master_snapshot_exact( - &second_assert.common.logical_assertion, &snapshot), - RESOURCE_X_APPLY_APPLIED); + &second_assert.common.logical_assertion, &snapshot), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(snapshot.phase, RESOURCE_X_MASTER_WAIT_BLOCKERS); UT_ASSERT_EQ(snapshot.incompatible_holders_bitmap, UINT32_C(1) << 1); UT_ASSERT_EQ(snapshot.blocked_holders_bitmap, 0); UT_ASSERT_EQ(snapshot.is_head, 1); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_block_intent_snapshot_exact( - &second_assert.common.logical_assertion, 1, &block_intent, - block_bytes, sizeof(block_bytes)), RESOURCE_X_APPLY_APPLIED); + &second_assert.common.logical_assertion, 1, &block_intent, block_bytes, + sizeof(block_bytes)), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(block_intent.state, RESOURCE_X_INTENT_SLOT_ARMED); UT_ASSERT_EQ(block_intent.destination_node, 1); /* The released requester slot accepts only a fresh attempt based on the * current monotonic authority. A late old release cannot alias it. */ - next_assert = make_resource_x_master_frame(RESOURCE_X_WIRE_ASSERT_X, - tag, 1, 1); + next_assert = make_resource_x_master_frame(RESOURCE_X_WIRE_ASSERT_X, tag, 1, 1); next_assert.common.base_authority_generation = 2; next_assert.common.authority_generation = 2; next_assert.common.assertion_sequence = 43; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact(&next_assert, 1, - &snapshot), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact(&next_assert, 1, &snapshot), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(snapshot.phase, RESOURCE_X_MASTER_QUEUED); UT_ASSERT_EQ(snapshot.base_authority_generation, 2); UT_ASSERT_EQ(snapshot.assertion_sequence, 43); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_release_x_exact(&release, 1, - &snapshot), RESOURCE_X_APPLY_STALE); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_release_x_exact(&release, 1, &snapshot), + RESOURCE_X_APPLY_STALE); UT_ASSERT_EQ(snapshot.phase, RESOURCE_X_MASTER_QUEUED); durable.assertion = second_assert.common.logical_assertion; durable.assertion_sequence = 42; durable.requester_target_generation = 42; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_durable_proof_exact(&durable, - &snapshot), RESOURCE_X_APPLY_BAD_STATE); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_durable_proof_exact(&durable, &snapshot), + RESOURCE_X_APPLY_BAD_STATE); UT_ASSERT_EQ(snapshot.phase, RESOURCE_X_MASTER_WAIT_BLOCKERS); UT_ASSERT_EQ(snapshot.proof_kind, 0); } @@ -17443,21 +16607,21 @@ UT_TEST(test_resource_x_release_without_successor_advances_canonical_base) cluster_node_id = 0; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), RESOURCE_X_APPLY_APPLIED); - UT_ASSERT_EQ(cluster_pcm_lock_apply_gcs_transition_result( - tag, PCM_TRANS_N_TO_X, 0), PCM_GCS_TRANSITION_APPLIED); - UT_ASSERT_EQ(cluster_pcm_lock_apply_gcs_transition_result( - tag, PCM_TRANS_X_TO_N_RELEASE, 0), PCM_GCS_TRANSITION_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_apply_gcs_transition_result(tag, PCM_TRANS_N_TO_X, 0), + PCM_GCS_TRANSITION_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_apply_gcs_transition_result(tag, PCM_TRANS_X_TO_N_RELEASE, 0), + PCM_GCS_TRANSITION_APPLIED); UT_ASSERT(cluster_pcm_lock_authority_snapshot(tag, &authority)); UT_ASSERT_EQ(authority.transition_count, 2); - first_assert = make_resource_x_master_frame( - RESOURCE_X_WIRE_ASSERT_X, tag, 1, 1); + first_assert = make_resource_x_master_frame(RESOURCE_X_WIRE_ASSERT_X, tag, 1, 1); first_assert.common.base_authority_generation = 2; first_assert.common.authority_generation = 2; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_adapter_base_bind_exact( - &first_assert.common.logical_assertion, 17, - authority.transition_count, &authority), RESOURCE_X_APPLY_APPLIED); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact( - &first_assert, 1, &snapshot), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ( + cluster_pcm_lock_resource_x_adapter_base_bind_exact( + &first_assert.common.logical_assertion, 17, authority.transition_count, &authority), + RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact(&first_assert, 1, &snapshot), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(snapshot.phase, RESOURCE_X_MASTER_WAIT_PROOF); memset(&durable, 0, sizeof(durable)); @@ -17470,12 +16634,11 @@ UT_TEST(test_resource_x_release_without_successor_advances_canonical_base) durable.page_scn_lsn = 82; durable.page_checksum = UINT32_C(0x12345678); durable.source_proof_crc32c = UINT32_C(0x87654321); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_durable_proof_exact( - &durable, &snapshot), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_durable_proof_exact(&durable, &snapshot), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(snapshot.final_authority_generation, 3); - settlement = make_resource_x_master_frame( - RESOURCE_X_WIRE_INSTALL_SETTLEMENT, tag, 1, 1); + settlement = make_resource_x_master_frame(RESOURCE_X_WIRE_INSTALL_SETTLEMENT, tag, 1, 1); settlement.common.outcome = RESOURCE_X_OUTCOME_OK; settlement.common.base_authority_generation = 2; settlement.common.authority_generation = 3; @@ -17485,30 +16648,26 @@ UT_TEST(test_resource_x_release_without_successor_advances_canonical_base) settlement.body.install_settlement.requester_target_generation = 41; settlement.body.install_settlement.page_scn_lsn = 82; settlement.body.install_settlement.page_checksum = UINT32_C(0x12345678); - settlement.body.install_settlement.source_proof_crc32c - = UINT32_C(0x87654321); + settlement.body.install_settlement.source_proof_crc32c = UINT32_C(0x87654321); settlement.body.install_settlement.installed_mode = PCM_STATE_X; - settlement.body.install_settlement.requester_role - = RESOURCE_X_REQUESTER_ROLE_ACQUIRER; - settlement.body.install_settlement.terminal_outcome - = RESOURCE_X_OUTCOME_OK; - settlement.body.install_settlement.terminal_state - = RESOURCE_X_SETTLEMENT_TERMINAL_INSTALLED; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_install_settlement_exact( - &settlement, 1, &snapshot), RESOURCE_X_APPLY_APPLIED); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_current_x_successor_exact( - &tag, 1, &preserve_current_x), RESOURCE_X_APPLY_APPLIED); + settlement.body.install_settlement.requester_role = RESOURCE_X_REQUESTER_ROLE_ACQUIRER; + settlement.body.install_settlement.terminal_outcome = RESOURCE_X_OUTCOME_OK; + settlement.body.install_settlement.terminal_state = RESOURCE_X_SETTLEMENT_TERMINAL_INSTALLED; + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_install_settlement_exact(&settlement, 1, &snapshot), + RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ( + cluster_pcm_lock_resource_x_current_x_successor_exact(&tag, 1, &preserve_current_x), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT(!preserve_current_x); - release = make_resource_x_master_frame( - RESOURCE_X_WIRE_RELEASE_X, tag, 1, 1); + release = make_resource_x_master_frame(RESOURCE_X_WIRE_RELEASE_X, tag, 1, 1); release.common.observed_mode = PCM_STATE_X; release.common.target_mode = PCM_STATE_N; release.common.outcome = RESOURCE_X_OUTCOME_OK; release.common.base_authority_generation = 2; release.common.authority_generation = 3; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_release_x_exact( - &release, 1, &snapshot), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_release_x_exact(&release, 1, &snapshot), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(snapshot.phase, RESOURCE_X_MASTER_RELEASED); UT_ASSERT(cluster_pcm_lock_authority_snapshot(tag, &authority)); UT_ASSERT_EQ(authority.state, PCM_STATE_N); @@ -17516,15 +16675,14 @@ UT_TEST(test_resource_x_release_without_successor_advances_canonical_base) UT_ASSERT(resource_x_assertion_init(&tag, 2, &next_assertion)); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_adapter_base_bind_exact( - &next_assertion, 17, authority.transition_count, &authority), - RESOURCE_X_APPLY_DUPLICATE); - next_assert = make_resource_x_master_frame( - RESOURCE_X_WIRE_ASSERT_X, tag, 2, 2); + &next_assertion, 17, authority.transition_count, &authority), + RESOURCE_X_APPLY_DUPLICATE); + next_assert = make_resource_x_master_frame(RESOURCE_X_WIRE_ASSERT_X, tag, 2, 2); next_assert.common.base_authority_generation = authority.transition_count; next_assert.common.authority_generation = authority.transition_count; next_assert.common.assertion_sequence = 42; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact( - &next_assert, 2, &snapshot), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact(&next_assert, 2, &snapshot), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(snapshot.phase, RESOURCE_X_MASTER_WAIT_PROOF); } @@ -17552,25 +16710,26 @@ UT_TEST(test_resource_x_reclaim_nonhead_preserves_survivor_fifo) RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact(&third, 3, &snapshot), RESOURCE_X_APPLY_APPLIED); - UT_ASSERT(cluster_resource_x_reconfig_freeze_exact( - 17, 18, UINT32_C(1) << 2, &token)); + UT_ASSERT(cluster_resource_x_reconfig_freeze_exact(17, 18, UINT32_C(1) << 2, &token)); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_reclaim_requester_exact( - &tag, 3, 17, &witness), RESOURCE_X_RECLAIM_NONE); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_reclaim_requester_exact( - &tag, 2, 17, &witness), RESOURCE_X_RECLAIM_NONHEAD); - UT_ASSERT(resource_x_assertion_equal(&witness.assertion, - &dead.common.logical_assertion)); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_reclaim_requester_exact(&tag, 3, 17, &witness), + RESOURCE_X_RECLAIM_NONE); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_reclaim_requester_exact(&tag, 2, 17, &witness), + RESOURCE_X_RECLAIM_NONHEAD); + UT_ASSERT(resource_x_assertion_equal(&witness.assertion, &dead.common.logical_assertion)); UT_ASSERT_EQ(witness.previous_phase, RESOURCE_X_MASTER_QUEUED); UT_ASSERT_EQ(witness.was_head, 0); UT_ASSERT_EQ(witness.successor_node, -1); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_master_snapshot_exact( - &dead.common.logical_assertion, &snapshot), RESOURCE_X_APPLY_NOT_FOUND); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_master_snapshot_exact( - &first.common.logical_assertion, &snapshot), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_master_snapshot_exact(&dead.common.logical_assertion, + &snapshot), + RESOURCE_X_APPLY_NOT_FOUND); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_master_snapshot_exact(&first.common.logical_assertion, + &snapshot), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(snapshot.is_head, 1); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_master_snapshot_exact( - &third.common.logical_assertion, &snapshot), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_master_snapshot_exact(&third.common.logical_assertion, + &snapshot), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(snapshot.phase, RESOURCE_X_MASTER_QUEUED); UT_ASSERT_EQ(snapshot.is_head, 0); } @@ -17588,28 +16747,27 @@ UT_TEST(test_resource_x_reclaim_safe_head_starts_exact_successor) UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), RESOURCE_X_APPLY_APPLIED); dead = make_resource_x_master_frame(RESOURCE_X_WIRE_ASSERT_X, tag, 1, 1); - successor = make_resource_x_master_frame(RESOURCE_X_WIRE_ASSERT_X, - tag, 2, 2); + successor = make_resource_x_master_frame(RESOURCE_X_WIRE_ASSERT_X, tag, 2, 2); successor.common.assertion_sequence = 42; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact(&dead, 1, &snapshot), RESOURCE_X_APPLY_APPLIED); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact(&successor, 2, - &snapshot), RESOURCE_X_APPLY_APPLIED); - UT_ASSERT(cluster_resource_x_reconfig_freeze_exact( - 17, 18, UINT32_C(1) << 1, &token)); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact(&successor, 2, &snapshot), + RESOURCE_X_APPLY_APPLIED); + UT_ASSERT(cluster_resource_x_reconfig_freeze_exact(17, 18, UINT32_C(1) << 1, &token)); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_reclaim_requester_exact( - &tag, 1, 17, &witness), - RESOURCE_X_RECLAIM_HEAD_SUCCESSOR_STARTED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_reclaim_requester_exact(&tag, 1, 17, &witness), + RESOURCE_X_RECLAIM_HEAD_SUCCESSOR_STARTED); UT_ASSERT_EQ(witness.previous_phase, RESOURCE_X_MASTER_WAIT_PROOF); UT_ASSERT_EQ(witness.was_head, 1); UT_ASSERT_EQ(witness.successor_node, 2); UT_ASSERT_EQ(witness.successor_phase, RESOURCE_X_MASTER_WAIT_PROOF); UT_ASSERT_EQ(witness.successor_assertion_sequence, 42); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_master_snapshot_exact(&dead.common.logical_assertion, + &snapshot), + RESOURCE_X_APPLY_NOT_FOUND); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_master_snapshot_exact( - &dead.common.logical_assertion, &snapshot), RESOURCE_X_APPLY_NOT_FOUND); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_master_snapshot_exact( - &successor.common.logical_assertion, &snapshot), RESOURCE_X_APPLY_APPLIED); + &successor.common.logical_assertion, &snapshot), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(snapshot.phase, RESOURCE_X_MASTER_WAIT_PROOF); UT_ASSERT_EQ(snapshot.is_head, 1); } @@ -17639,19 +16797,19 @@ UT_TEST(test_resource_x_reclaim_post_grant_preserves_orphan_evidence) durable.page_scn_lsn = 82; durable.page_checksum = UINT32_C(0x12345678); durable.source_proof_crc32c = UINT32_C(0x87654321); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_durable_proof_exact(&durable, - &snapshot), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_durable_proof_exact(&durable, &snapshot), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(snapshot.phase, RESOURCE_X_MASTER_GRANT_COMMITTED); - UT_ASSERT(cluster_resource_x_reconfig_freeze_exact( - 17, 18, UINT32_C(1) << 1, &token)); + UT_ASSERT(cluster_resource_x_reconfig_freeze_exact(17, 18, UINT32_C(1) << 1, &token)); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_reclaim_requester_exact( - &tag, 1, 17, &witness), RESOURCE_X_RECLAIM_ORPHAN_BLOCKED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_reclaim_requester_exact(&tag, 1, 17, &witness), + RESOURCE_X_RECLAIM_ORPHAN_BLOCKED); UT_ASSERT_EQ(witness.previous_phase, RESOURCE_X_MASTER_GRANT_COMMITTED); UT_ASSERT_EQ(witness.source_evidence_preserved, 1); UT_ASSERT_EQ(witness.final_authority_generation, 2); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_master_snapshot_exact( - &dead.common.logical_assertion, &snapshot), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_master_snapshot_exact(&dead.common.logical_assertion, + &snapshot), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(snapshot.phase, RESOURCE_X_MASTER_RECOVERY_BLOCKED); UT_ASSERT_EQ(snapshot.proof_kind, RESOURCE_X_PROOF_DURABLE_STORAGE); UT_ASSERT_EQ(snapshot.final_authority_generation, 2); @@ -17670,33 +16828,30 @@ UT_TEST(test_resource_x_reconfig_sweep_drives_exact_dead_requester_reclaim) UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), RESOURCE_X_APPLY_APPLIED); dead = make_resource_x_master_frame(RESOURCE_X_WIRE_ASSERT_X, tag, 1, 1); - successor = make_resource_x_master_frame(RESOURCE_X_WIRE_ASSERT_X, - tag, 2, 2); + successor = make_resource_x_master_frame(RESOURCE_X_WIRE_ASSERT_X, tag, 2, 2); successor.common.assertion_sequence = 42; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact(&dead, 1, &snapshot), RESOURCE_X_APPLY_APPLIED); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact(&successor, 2, - &snapshot), RESOURCE_X_APPLY_APPLIED); - UT_ASSERT(cluster_resource_x_reconfig_freeze_exact( - 17, 18, UINT32_C(1) << 1, &token)); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact(&successor, 2, &snapshot), + RESOURCE_X_APPLY_APPLIED); + UT_ASSERT(cluster_resource_x_reconfig_freeze_exact(17, 18, UINT32_C(1) << 1, &token)); UT_ASSERT_EQ(token.dead_requester_bitmap, UINT32_C(1) << 1); - UT_ASSERT_EQ(cluster_resource_x_reconfig_sweep(&token, 4, &batch), - RESOURCE_X_RECONFIG_MORE); + UT_ASSERT_EQ(cluster_resource_x_reconfig_sweep(&token, 4, &batch), RESOURCE_X_RECONFIG_MORE); UT_ASSERT_EQ(batch.reclaim_count, 1); UT_ASSERT_EQ(batch.reclaim_head_count, 1); UT_ASSERT_EQ(batch.reclaim_nonhead_count, 0); UT_ASSERT_EQ(batch.reclaim_orphan_count, 0); - UT_ASSERT_EQ(batch.reclaim_witnesses[0].result, - RESOURCE_X_RECLAIM_HEAD_SUCCESSOR_STARTED); + UT_ASSERT_EQ(batch.reclaim_witnesses[0].result, RESOURCE_X_RECLAIM_HEAD_SUCCESSOR_STARTED); UT_ASSERT_EQ(batch.reclaim_witnesses[0].successor_node, 2); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_master_snapshot_exact(&dead.common.logical_assertion, + &snapshot), + RESOURCE_X_APPLY_NOT_FOUND); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_master_snapshot_exact( - &dead.common.logical_assertion, &snapshot), RESOURCE_X_APPLY_NOT_FOUND); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_master_snapshot_exact( - &successor.common.logical_assertion, &snapshot), RESOURCE_X_APPLY_APPLIED); + &successor.common.logical_assertion, &snapshot), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(snapshot.phase, RESOURCE_X_MASTER_WAIT_PROOF); - UT_ASSERT_EQ(cluster_resource_x_reconfig_sweep(&token, 4, &batch), - RESOURCE_X_RECONFIG_ORPHAN); + UT_ASSERT_EQ(cluster_resource_x_reconfig_sweep(&token, 4, &batch), RESOURCE_X_RECONFIG_ORPHAN); UT_ASSERT(!cluster_resource_x_reconfig_thaw_exact(&token)); } @@ -17715,42 +16870,40 @@ UT_TEST(test_resource_x_intent_retains_logical_owner_across_physical_scarcity) handle.owner_node = 1; handle.owner_kind = RESOURCE_X_INTENT_OWNER_MASTER_GRANT; - UT_ASSERT(!cluster_pcm_lock_resource_x_intent_arm_exact( - &slot, &handle, 51, 61, 71, 2, RESOURCE_X_CONTROL_V1_BYTES, - RESOURCE_X_WIRE_AUTHORITY_GRANT)); + UT_ASSERT(!cluster_pcm_lock_resource_x_intent_arm_exact(&slot, &handle, 51, 61, 71, 2, + RESOURCE_X_CONTROL_V1_BYTES, + RESOURCE_X_WIRE_AUTHORITY_GRANT)); UT_ASSERT_EQ(slot.state, RESOURCE_X_INTENT_SLOT_EMPTY); UT_ASSERT(cluster_pcm_lock_resource_x_intent_arm_exact( - &slot, &handle, 51, 61, 71, 2, RESOURCE_X_PROOF_V1_BYTES, - RESOURCE_X_WIRE_AUTHORITY_GRANT)); + &slot, &handle, 51, 61, 71, 2, RESOURCE_X_PROOF_V1_BYTES, RESOURCE_X_WIRE_AUTHORITY_GRANT)); UT_ASSERT_EQ(slot.state, RESOURCE_X_INTENT_SLOT_ARMED); UT_ASSERT_EQ(slot.first_armed_us, 71); UT_ASSERT_EQ(slot.last_attempt_us, 0); snapshot = slot; UT_ASSERT(!cluster_pcm_lock_resource_x_intent_arm_exact( - &slot, &handle, 51, 61, 72, 3, RESOURCE_X_PROOF_V1_BYTES, - RESOURCE_X_WIRE_AUTHORITY_GRANT)); + &slot, &handle, 51, 61, 72, 3, RESOURCE_X_PROOF_V1_BYTES, RESOURCE_X_WIRE_AUTHORITY_GRANT)); UT_ASSERT_EQ(memcmp(&slot, &snapshot, sizeof(slot)), 0); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_intent_not_admitted_exact( - &slot, &snapshot, 73), RESOURCE_X_INTENT_NOT_ADMITTED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_intent_not_admitted_exact(&slot, &snapshot, 73), + RESOURCE_X_INTENT_NOT_ADMITTED); UT_ASSERT_EQ(slot.state, RESOURCE_X_INTENT_SLOT_ARMED); UT_ASSERT_EQ(slot.last_attempt_us, 73); stale = snapshot; stale.authority_generation++; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_intent_stage_exact(&slot, &stale, 74), - RESOURCE_X_INTENT_STALE); + RESOURCE_X_INTENT_STALE); UT_ASSERT_EQ(slot.state, RESOURCE_X_INTENT_SLOT_ARMED); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_intent_stage_exact(&slot, &snapshot, 74), - RESOURCE_X_INTENT_STAGED); + RESOURCE_X_INTENT_STAGED); UT_ASSERT_EQ(slot.state, RESOURCE_X_INTENT_SLOT_STAGED); UT_ASSERT_EQ(slot.last_attempt_us, 74); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_intent_hard_rearm_exact( - &slot, &snapshot, 75), RESOURCE_X_INTENT_HARD_REARMED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_intent_hard_rearm_exact(&slot, &snapshot, 75), + RESOURCE_X_INTENT_HARD_REARMED); UT_ASSERT_EQ(slot.state, RESOURCE_X_INTENT_SLOT_ARMED); UT_ASSERT_EQ(slot.first_armed_us, 71); UT_ASSERT_EQ(slot.last_attempt_us, 75); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_intent_stage_exact(&slot, &snapshot, 76), - RESOURCE_X_INTENT_STAGED); + RESOURCE_X_INTENT_STAGED); UT_ASSERT(!cluster_pcm_lock_resource_x_intent_complete_exact(&slot, &stale)); UT_ASSERT_EQ(slot.state, RESOURCE_X_INTENT_SLOT_STAGED); UT_ASSERT(cluster_pcm_lock_resource_x_intent_complete_exact(&slot, &snapshot)); @@ -17776,10 +16929,9 @@ UT_TEST(test_resource_x_intent_sparse_probe_rediscovers_exact_rearm) reset_fake_pcm_runtime(4); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), RESOURCE_X_APPLY_APPLIED); - assertion = make_resource_x_master_frame( - RESOURCE_X_WIRE_ASSERT_X, tag, 2, 2); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact( - &assertion, 2, &snapshot), RESOURCE_X_APPLY_APPLIED); + assertion = make_resource_x_master_frame(RESOURCE_X_WIRE_ASSERT_X, tag, 2, 2); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_exact(&assertion, 2, &snapshot), + RESOURCE_X_APPLY_APPLIED); memset(&durable, 0, sizeof(durable)); durable.assertion = assertion.common.logical_assertion; durable.base_authority_generation = 1; @@ -17790,8 +16942,8 @@ UT_TEST(test_resource_x_intent_sparse_probe_rediscovers_exact_rearm) durable.page_scn_lsn = 82; durable.page_checksum = UINT32_C(0x12345678); durable.source_proof_crc32c = UINT32_C(0x87654321); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_durable_proof_exact( - &durable, &snapshot), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_durable_proof_exact(&durable, &snapshot), + RESOURCE_X_APPLY_APPLIED); for (calls = 0; calls < 8; calls++) { probe_result = cluster_pcm_lock_resource_x_outbound_intent_probe_exact( @@ -17804,15 +16956,14 @@ UT_TEST(test_resource_x_intent_sparse_probe_rediscovers_exact_rearm) UT_ASSERT_EQ(probe_result, RESOURCE_X_INTENT_PROBE_FOUND); UT_ASSERT_EQ(intent.state, RESOURCE_X_INTENT_SLOT_ARMED); UT_ASSERT_EQ(intent.logical_generation, 41); - UT_ASSERT(cluster_resource_x_wire_decode( - RESOURCE_X_MSG_IMAGE_OR_GRANT, payload, sizeof(payload), - &decoded, &reject)); + UT_ASSERT(cluster_resource_x_wire_decode(RESOURCE_X_MSG_IMAGE_OR_GRANT, payload, + sizeof(payload), &decoded, &reject)); UT_ASSERT_EQ(decoded.kind, RESOURCE_X_WIRE_AUTHORITY_GRANT); UT_ASSERT_EQ(decoded.common.authority_generation, 2); staged_intent = intent; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_grant_intent_stage_exact( - &staged_intent, 201), RESOURCE_X_INTENT_STAGED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_grant_intent_stage_exact(&staged_intent, 201), + RESOURCE_X_INTENT_STAGED); for (calls = 0; calls < 8; calls++) { probe_result = cluster_pcm_lock_resource_x_outbound_intent_probe_exact( 1, &intent, payload, sizeof(payload), &examined); @@ -17823,8 +16974,8 @@ UT_TEST(test_resource_x_intent_sparse_probe_rediscovers_exact_rearm) } UT_ASSERT_EQ(probe_result, RESOURCE_X_INTENT_PROBE_COMPLETE); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_grant_intent_hard_rearm_exact( - &staged_intent, 202), RESOURCE_X_INTENT_HARD_REARMED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_grant_intent_hard_rearm_exact(&staged_intent, 202), + RESOURCE_X_INTENT_HARD_REARMED); for (calls = 0; calls < 8; calls++) { probe_result = cluster_pcm_lock_resource_x_outbound_intent_probe_exact( 1, &intent, payload, sizeof(payload), &examined); @@ -18022,20 +17173,19 @@ UT_TEST(test_resource_x_duplicate_assert_redrives_completed_grant_delivery) reset_fake_pcm_runtime(4); cluster_node_id = 0; UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), + RESOURCE_X_APPLY_APPLIED); + request = make_resource_x_bootstrap_request_values(tag, 2, 17, 31, 41, 51); + UT_ASSERT_EQ( + cluster_pcm_lock_resource_x_bootstrap_request_exact(&request, 2, 61, 77, 31, 71, &ack), RESOURCE_X_APPLY_APPLIED); - request = make_resource_x_bootstrap_request_values( - tag, 2, 17, 31, 41, 51); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_bootstrap_request_exact( - &request, 2, 61, 77, 31, 71, &ack), RESOURCE_X_APPLY_APPLIED); assertion = ack; assertion.kind = RESOURCE_X_WIRE_ASSERT_X; assertion.common.sender_connection_generation = 51; - assertion.common.authority_generation - = assertion.common.base_authority_generation; + assertion.common.authority_generation = assertion.common.base_authority_generation; assertion.common.outcome = RESOURCE_X_OUTCOME_NONE; - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_bootstrapped_exact( - &assertion, 2, 61, 77, 31, 71, &snapshot), - RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_bootstrapped_exact(&assertion, 2, 61, 77, 31, + 71, &snapshot), + RESOURCE_X_APPLY_APPLIED); memset(&durable, 0, sizeof(durable)); durable.assertion = assertion.common.logical_assertion; @@ -18047,37 +17197,33 @@ UT_TEST(test_resource_x_duplicate_assert_redrives_completed_grant_delivery) durable.page_scn_lsn = 82; durable.page_checksum = UINT32_C(0x12345678); durable.source_proof_crc32c = UINT32_C(0x87654321); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_durable_proof_exact( - &durable, &snapshot), RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_durable_proof_exact(&durable, &snapshot), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_grant_intent_snapshot_exact( - &assertion.common.logical_assertion, &completed_intent, - completed_payload, sizeof(completed_payload)), - RESOURCE_X_APPLY_APPLIED); - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_grant_intent_stage_exact( - &completed_intent, 101), RESOURCE_X_INTENT_STAGED); - UT_ASSERT(cluster_pcm_lock_resource_x_grant_intent_complete_exact( - &completed_intent)); + &assertion.common.logical_assertion, &completed_intent, completed_payload, + sizeof(completed_payload)), + RESOURCE_X_APPLY_APPLIED); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_grant_intent_stage_exact(&completed_intent, 101), + RESOURCE_X_INTENT_STAGED); + UT_ASSERT(cluster_pcm_lock_resource_x_grant_intent_complete_exact(&completed_intent)); /* Transport completion is not requester T3. The existing R7 ASSERT * replay must reconstruct the same frozen grant from the canonical * GRANT_COMMITTED request, without changing authority or attempt. */ - UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_bootstrapped_exact( - &assertion, 2, 61, 77, 31, 71, &snapshot), - RESOURCE_X_APPLY_DUPLICATE); + UT_ASSERT_EQ(cluster_pcm_lock_resource_x_assert_bootstrapped_exact(&assertion, 2, 61, 77, 31, + 71, &snapshot), + RESOURCE_X_APPLY_DUPLICATE); UT_ASSERT_EQ(snapshot.phase, RESOURCE_X_MASTER_GRANT_COMMITTED); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_grant_intent_snapshot_exact( - &assertion.common.logical_assertion, &replay_intent, - replay_payload, sizeof(replay_payload)), RESOURCE_X_APPLY_APPLIED); + &assertion.common.logical_assertion, &replay_intent, replay_payload, + sizeof(replay_payload)), + RESOURCE_X_APPLY_APPLIED); UT_ASSERT_EQ(replay_intent.state, RESOURCE_X_INTENT_SLOT_ARMED); - UT_ASSERT_EQ(replay_intent.logical_generation, - completed_intent.logical_generation); - UT_ASSERT_EQ(replay_intent.authority_generation, - completed_intent.authority_generation); - UT_ASSERT_EQ(memcmp(replay_payload, completed_payload, - sizeof(replay_payload)), 0); - UT_ASSERT(cluster_resource_x_wire_decode( - RESOURCE_X_MSG_IMAGE_OR_GRANT, replay_payload, - sizeof(replay_payload), &decoded, &reject)); + UT_ASSERT_EQ(replay_intent.logical_generation, completed_intent.logical_generation); + UT_ASSERT_EQ(replay_intent.authority_generation, completed_intent.authority_generation); + UT_ASSERT_EQ(memcmp(replay_payload, completed_payload, sizeof(replay_payload)), 0); + UT_ASSERT(cluster_resource_x_wire_decode(RESOURCE_X_MSG_IMAGE_OR_GRANT, replay_payload, + sizeof(replay_payload), &decoded, &reject)); UT_ASSERT_EQ(decoded.kind, RESOURCE_X_WIRE_AUTHORITY_GRANT); UT_ASSERT_EQ(decoded.common.assertion_sequence, UINT64_C(41)); UT_ASSERT_EQ(decoded.common.authority_generation, UINT64_C(2)); @@ -18593,12 +17739,12 @@ UT_TEST(test_pcm_acquire_buffer_local_s_retries_while_pcm_x_head_is_active) fake_pcm_x_local_s_barrier_active = true; memset(&buf, 0, sizeof(buf)); buf.tag = tag; - buf.pcm_state = (uint8) PCM_STATE_N; + buf.pcm_state = (uint8)PCM_STATE_N; UT_ASSERT(!cluster_pcm_lock_acquire_buffer(&buf, PCM_LOCK_MODE_S, &retry_denied)); UT_ASSERT(retry_denied); UT_ASSERT_EQ(fake_pcm_x_local_s_barrier_checks, 1); - UT_ASSERT_EQ((int) cluster_pcm_lock_query(tag), (int) PCM_LOCK_MODE_N); + UT_ASSERT_EQ((int)cluster_pcm_lock_query(tag), (int)PCM_LOCK_MODE_N); UT_ASSERT_EQ(fake_local_read_image_count, 0); } @@ -18933,11 +18079,11 @@ UT_TEST(test_pcm_r4_route_snapshot_co_samples_master_generation_and_watermark) cluster_node_id = 1; ut_lms_master_generation = (UINT64_C(23) << 32) | UINT64_C(7); cluster_pcm_lock_acquire(tag, PCM_LOCK_MODE_S); - cluster_pcm_lock_pi_watermark_scn_advance(tag, (SCN)0x6600, - CLUSTER_PCM_WM_SRC_REDECLARE, 1, 88, 23); + cluster_pcm_lock_pi_watermark_scn_advance(tag, (SCN)0x6600, CLUSTER_PCM_WM_SRC_REDECLARE, 1, 88, + 23); - UT_ASSERT(cluster_pcm_lock_r4_route_snapshot(tag, &snapshot, &master_generation, - &expected_page_scn)); + UT_ASSERT( + cluster_pcm_lock_r4_route_snapshot(tag, &snapshot, &master_generation, &expected_page_scn)); UT_ASSERT_EQ((int)snapshot.state, (int)PCM_STATE_S); UT_ASSERT_EQ(snapshot.master_holder.node_id, (uint32)1); UT_ASSERT(snapshot.transition_count > 0); @@ -19243,13 +18389,14 @@ UT_TEST(test_resource_x_trace_observes_actual_head_and_same_ref_waiters) fake_pcm_clock_us = 100; UT_ASSERT(cluster_pcm_lock_resource_x_trace_begin(&tag, 1)); UT_ASSERT_EQ(cluster_pcm_lock_resource_x_gate_bind_formation_exact(17), - RESOURCE_X_APPLY_APPLIED); + RESOURCE_X_APPLY_APPLIED); UT_ASSERT(resource_x_assertion_init(&tag, 1, &assertion)); for (int caller = 0; caller < 4; caller++) UT_ASSERT_EQ(cluster_pcm_lock_resource_x_bootstrap_round_step_exact( - &assertion, 0, 17, 31, 77, 51, 61, 1000, 900, 100, 50, false, 0, - &dispatch, &terminal), caller == 0 ? RESOURCE_X_BOOTSTRAP_ROUND_DISPATCH_REQUEST - : RESOURCE_X_BOOTSTRAP_ROUND_WAIT); + &assertion, 0, 17, 31, 77, 51, 61, 1000, 900, 100, 50, false, 0, &dispatch, + &terminal), + caller == 0 ? RESOURCE_X_BOOTSTRAP_ROUND_DISPATCH_REQUEST + : RESOURCE_X_BOOTSTRAP_ROUND_WAIT); UT_ASSERT(cluster_pcm_lock_resource_x_trace_seal(1)); count = cluster_pcm_lock_resource_x_trace_read(1, 0, rows, lengthof(rows)); for (uint32 i = 0; i < count; i++) { @@ -19297,7 +18444,7 @@ UT_TEST(test_resource_x_trace_is_exact_bounded_and_cannot_erase_unexported_evide { BufferTag tag = make_tag(40); ResourceXTraceStats stats; - ResourceXTraceEvent event = {0}; + ResourceXTraceEvent event = { 0 }; ResourceXTraceEvent rows[64]; uint64 cursor; uint32 copied; @@ -20018,26 +19165,26 @@ main(void) UT_RUN(test_resource_x_drained_drop_pair_allows_other_requester_lower_attempt); UT_RUN(test_resource_x_drained_drop_pair_rejects_old_requester_attempt); UT_RUN(test_resource_x_drained_drop_pair_requires_new_terminal_authority); - UT_RUN(test_resource_x_bootstrap_round_waits_only_for_exact_target_install); - UT_RUN(test_resource_x_bootstrap_round_waits_across_exact_post_t3_cover_window); - UT_RUN(test_resource_x_target_install_continuation_classifies_exact_attempt); - UT_RUN(test_resource_x_target_install_stable_direct_init_i0_t2_is_closed); - UT_RUN(test_resource_x_target_wait_old_lease_is_only_a_reprobe_hint); - UT_RUN(test_resource_x_target_install_wait_uses_receipt_and_fixed_deadline); - UT_RUN(test_resource_x_target_install_preuse_successor_never_grants_old_receipt); - UT_RUN(test_resource_x_target_install_capture_during_revoke_retries_same_token_n); - UT_RUN(test_resource_x_completed_aux_direct_init_is_not_failed_authority); - UT_RUN(test_resource_x_aux_creation_reobserve_preserves_live_source_owner_and_successor); - UT_RUN(test_resource_x_completed_install_observer_discards_multiple_retired_cycles); - UT_RUN(test_resource_x_completed_install_wait_reregisters_after_multiple_cycles); - UT_RUN(test_resource_x_round_wait_reobserves_completed_retirement); - UT_RUN(test_resource_x_wait_retirement_during_enrollment_is_reobserved); - UT_RUN(test_resource_x_wait_age_survives_rejoin_and_reason_changes); - UT_RUN(test_resource_x_retired_wait_preserves_full_namespace_and_failure); - UT_RUN(test_resource_x_gcs_wait_reobserves_retired_caller); - UT_RUN(test_resource_x_caller_retirement_is_not_current_success); - UT_RUN(test_resource_x_completed_install_floor_never_erases_failure); - UT_RUN(test_resource_x_bootstrap_terminal_cover_accepts_remote_master_requester_projection); + UT_RUN(test_resource_x_bootstrap_round_waits_only_for_exact_target_install); + UT_RUN(test_resource_x_bootstrap_round_waits_across_exact_post_t3_cover_window); + UT_RUN(test_resource_x_target_install_continuation_classifies_exact_attempt); + UT_RUN(test_resource_x_target_install_stable_direct_init_i0_t2_is_closed); + UT_RUN(test_resource_x_target_wait_old_lease_is_only_a_reprobe_hint); + UT_RUN(test_resource_x_target_install_wait_uses_receipt_and_fixed_deadline); + UT_RUN(test_resource_x_target_install_preuse_successor_never_grants_old_receipt); + UT_RUN(test_resource_x_target_install_capture_during_revoke_retries_same_token_n); + UT_RUN(test_resource_x_completed_aux_direct_init_is_not_failed_authority); + UT_RUN(test_resource_x_aux_creation_reobserve_preserves_live_source_owner_and_successor); + UT_RUN(test_resource_x_completed_install_observer_discards_multiple_retired_cycles); + UT_RUN(test_resource_x_completed_install_wait_reregisters_after_multiple_cycles); + UT_RUN(test_resource_x_round_wait_reobserves_completed_retirement); + UT_RUN(test_resource_x_wait_retirement_during_enrollment_is_reobserved); + UT_RUN(test_resource_x_wait_age_survives_rejoin_and_reason_changes); + UT_RUN(test_resource_x_retired_wait_preserves_full_namespace_and_failure); + UT_RUN(test_resource_x_gcs_wait_reobserves_retired_caller); + UT_RUN(test_resource_x_caller_retirement_is_not_current_success); + UT_RUN(test_resource_x_completed_install_floor_never_erases_failure); + UT_RUN(test_resource_x_bootstrap_terminal_cover_accepts_remote_master_requester_projection); UT_RUN(test_resource_x_cached_x_to_s_commit_clears_only_exact_terminal_cover); UT_RUN(test_resource_x_bootstrap_direct_init_cached_x_consumes_same_round_t3_handoff); UT_RUN(test_resource_x_cached_x_eviction_prepares_and_commits_release); diff --git a/src/test/cluster_unit/test_cluster_port_runtime.c b/src/test/cluster_unit/test_cluster_port_runtime.c new file mode 100644 index 00000000000..e4013b9357c --- /dev/null +++ b/src/test/cluster_unit/test_cluster_port_runtime.c @@ -0,0 +1,68 @@ +/*------------------------------------------------------------------------- + * test_cluster_port_runtime.c + * Real portability-library CRC and fail-stop standalone logging boundary. + * + * Portions Copyright (c) 2026, pgrac contributors + * Author: SqlRush + * + * IDENTIFICATION + * src/test/cluster_unit/test_cluster_port_runtime.c + *------------------------------------------------------------------------- + */ +#include "postgres.h" +#include "port/pg_crc32c.h" +#include +#include +#include +#include +#undef printf +#include "unit_test.h" + +UT_DEFINE_GLOBALS(); + +UT_TEST(test_crc32c_known_answer) +{ + pg_crc32c crc; + INIT_CRC32C(crc); + COMP_CRC32C(crc, "123456789", 9); + FIN_CRC32C(crc); + UT_ASSERT_EQ(crc, UINT32_C(0xe3069283)); +} + +UT_TEST(test_only_crc_debug_message_is_ignored) +{ + UT_ASSERT(!errstart(DEBUG1, NULL)); +} + +UT_TEST(test_unexpected_error_and_warning_abort) +{ + const int levels[] = { WARNING, ERROR }; + for (int i = 0; i < lengthof(levels); i++) { + pid_t pid = fork(); + int status = 0; + UT_ASSERT(pid >= 0); + if (pid < 0) + return; + if (pid == 0) { + struct rlimit limit = { 0, 0 }; + if (setrlimit(RLIMIT_CORE, &limit) != 0) + _exit(2); + (void)errstart_cold(levels[i], NULL); + _exit(0); + } + UT_ASSERT_EQ(waitpid(pid, &status, 0), pid); + UT_ASSERT(WIFSIGNALED(status)); + UT_ASSERT_EQ(WTERMSIG(status), SIGABRT); + } +} + +int +main(void) +{ + UT_PLAN(3); + UT_RUN(test_crc32c_known_answer); + UT_RUN(test_only_crc_debug_message_is_ignored); + UT_RUN(test_unexpected_error_and_warning_abort); + UT_DONE(); + return ut_failed_count ? 1 : 0; +} diff --git a/src/test/cluster_unit/test_cluster_qvotec.c b/src/test/cluster_unit/test_cluster_qvotec.c index 0ffafc8d1b5..608f8858a5c 100644 --- a/src/test/cluster_unit/test_cluster_qvotec.c +++ b/src/test/cluster_unit/test_cluster_qvotec.c @@ -67,7 +67,7 @@ #include "cluster/cluster_ic_tier1.h" #include "cluster/cluster_lms.h" #include "cluster/cluster_pcm_lock.h" -#include "cluster/cluster_reconfig.h" /* ReconfigEvent for spec-4.12b D2 stub */ +#include "cluster/cluster_reconfig.h" /* ReconfigEvent for spec-4.12b D2 stub */ #include "cluster/cluster_control_root.h" /* B′ bit22 cutover references */ #include "cluster/cluster_replacement_request.h" #include "cluster/cluster_semantic_activation.h" @@ -79,6 +79,7 @@ #include "cluster/storage/cluster_undo_block0_current.h" #include "storage/proc.h" #include "access/xlog.h" +#include "cluster_unit_no_normal_stop.h" #undef printf #undef fprintf @@ -114,48 +115,40 @@ /* Test-only linkage; deliberately absent from every product header/ABI. */ extern ClusterSemanticActivationResult cluster_qvotec_test_semantic_activation_record_cas_write( - const int *fds, int n_disks, uint64 expected_generation, - uint64 expected_source_feature_bitmap, + const int *fds, int n_disks, uint64 expected_generation, uint64 expected_source_feature_bitmap, const uint8 desired_bytes[CLUSTER_SEMANTIC_ACTIVATION_RECORD_BYTES]); extern ClusterSemanticActivationResult cluster_qvotec_test_semantic_activation_record_read( - const int *fds, int n_disks, - uint8 selected_bytes[CLUSTER_SEMANTIC_ACTIVATION_RECORD_BYTES], + const int *fds, int n_disks, uint8 selected_bytes[CLUSTER_SEMANTIC_ACTIVATION_RECORD_BYTES], bool *implicit_open); -extern bool cluster_qvotec_test_join_marker_ack_proven( - const int *fds, int n_disks, int32 target_node, - const uint8 *staged_slot, uint32 writes_ok); +extern bool cluster_qvotec_test_join_marker_ack_proven(const int *fds, int n_disks, + int32 target_node, const uint8 *staged_slot, + uint32 writes_ok); extern bool cluster_qvotec_test_join_marker_verify_committed_closed( const int *fds, int n_disks, int32 target_node, uint8 verified_image96[CLUSTER_JCMK_REPLACEMENT_BYTES]); -extern ClusterQvotecMailboxResult cluster_qvotec_test_epoch_ballot_recover_head( - const int *fds, int n_disks, uint64 system_identifier, - const uint64 admitted_incarnations[CLUSTER_MAX_NODES], - uint8 out_value[CLUSTER_QVOTEC_AUTHORITY_VALUE_BYTES], - uint8 out_ballot[CLUSTER_QVOTEC_BALLOT_BYTES], - uint8 *out_observed_disk_bitmap); +extern ClusterQvotecMailboxResult +cluster_qvotec_test_epoch_ballot_recover_head(const int *fds, int n_disks, uint64 system_identifier, + const uint64 admitted_incarnations[CLUSTER_MAX_NODES], + uint8 out_value[CLUSTER_QVOTEC_AUTHORITY_VALUE_BYTES], + uint8 out_ballot[CLUSTER_QVOTEC_BALLOT_BYTES], + uint8 *out_observed_disk_bitmap); extern bool cluster_qvotec_test_epoch_ballot_phase1_promise( const int *fds, int n_disks, uint64 system_identifier, - const uint64 admitted_incarnations[CLUSTER_MAX_NODES], - int32 proposer_node_id, const ClusterEpochBallotId *ballot, - uint8 *out_completed_disk_bitmap); -extern bool cluster_qvotec_test_epoch_ballot_formation_attested( - const int *fds, int n_disks); -extern bool cluster_qvotec_test_undo_root_descriptor_formation_attested( - const int *fds, int n_disks); + const uint64 admitted_incarnations[CLUSTER_MAX_NODES], int32 proposer_node_id, + const ClusterEpochBallotId *ballot, uint8 *out_completed_disk_bitmap); +extern bool cluster_qvotec_test_epoch_ballot_formation_attested(const int *fds, int n_disks); +extern bool cluster_qvotec_test_undo_root_descriptor_formation_attested(const int *fds, + int n_disks); extern bool cluster_qvotec_test_undo_root_descriptor_provision( const int *fds, int n_disks, uint64 system_identifier, - const uint8 desired[CLUSTER_UNDO_ROOT_DESCRIPTOR_BYTES], - uint8 *out_completed_disk_bitmap); -extern ClusterUndoRootDescriptorState -cluster_qvotec_test_undo_root_descriptor_read( - const int *fds, int n_disks, uint64 system_identifier, - uint8 root_kind, int32 owner_node, ClusterUndoRootDescriptorV1 *out, - uint8 *out_observed_disk_bitmap); + const uint8 desired[CLUSTER_UNDO_ROOT_DESCRIPTOR_BYTES], uint8 *out_completed_disk_bitmap); +extern ClusterUndoRootDescriptorState cluster_qvotec_test_undo_root_descriptor_read( + const int *fds, int n_disks, uint64 system_identifier, uint8 root_kind, int32 owner_node, + ClusterUndoRootDescriptorV1 *out, uint8 *out_observed_disk_bitmap); extern ClusterReplacementRequestSlotState -cluster_qvotec_test_replacement_request_preserve( - ClusterVotingSlot *next, const ClusterVotingSlot *prior); -extern long cluster_qvotec_test_poll_wait_timeout_ms( - uint64 elapsed_us, int poll_interval_ms); +cluster_qvotec_test_replacement_request_preserve(ClusterVotingSlot *next, + const ClusterVotingSlot *prior); +extern long cluster_qvotec_test_poll_wait_timeout_ms(uint64 elapsed_us, int poll_interval_ms); extern bool cluster_qvotec_test_clean_shutdown(const int *fds, int n_disks, uint64 incarnation, uint64 generation); #ifdef __APPLE__ @@ -257,8 +250,7 @@ cluster_grd_recovery_state_value(void) } bool -cluster_reconfig_snapshot_initial_clean_formation( - ClusterInitialCleanFormationSnapshot *out) +cluster_reconfig_snapshot_initial_clean_formation(ClusterInitialCleanFormationSnapshot *out) { if (out != NULL) memset(out, 0, sizeof(*out)); @@ -288,9 +280,9 @@ cluster_pcm_lock_resource_x_cutover_gate_snapshot_exact(ResourceXGateSnapshot *o } bool -cluster_pcm_lock_resource_x_cutover_current_proof_digest_exact( - bool thawed pg_attribute_unused(), ResourceXReconfigToken *token_out, - uint64 *digest_out) +cluster_pcm_lock_resource_x_cutover_current_proof_digest_exact(bool thawed pg_attribute_unused(), + ResourceXReconfigToken *token_out, + uint64 *digest_out) { if (token_out != NULL) memset(token_out, 0, sizeof(*token_out)); @@ -300,8 +292,8 @@ cluster_pcm_lock_resource_x_cutover_current_proof_digest_exact( } bool -cluster_reconfig_get_observed_slot(int32 node_id pg_attribute_unused(), - uint64 *incarnation, uint64 *generation) +cluster_reconfig_get_observed_slot(int32 node_id pg_attribute_unused(), uint64 *incarnation, + uint64 *generation) { if (incarnation != NULL) *incarnation = 0; @@ -468,23 +460,22 @@ cluster_ic_local_capability_word(void) ClusterICSendResult cluster_ic_send_envelope(uint8 msg_type pg_attribute_unused(), - int32 dest_node_id pg_attribute_unused(), - const void *payload pg_attribute_unused(), - uint32 payload_len pg_attribute_unused()) + int32 dest_node_id pg_attribute_unused(), + const void *payload pg_attribute_unused(), + uint32 payload_len pg_attribute_unused()) { return CLUSTER_IC_SEND_NOT_ADMITTED; } void cluster_ic_tier1_close_peer(int32 peer_id pg_attribute_unused(), - const char *reason pg_attribute_unused()) + const char *reason pg_attribute_unused()) {} bool -cluster_sf_peer_capability_word_sample( - int32 peer_id pg_attribute_unused(), - uint32 required_capabilities pg_attribute_unused(), - uint32 *capability_word_out, uint32 *generation_out) +cluster_sf_peer_capability_word_sample(int32 peer_id pg_attribute_unused(), + uint32 required_capabilities pg_attribute_unused(), + uint32 *capability_word_out, uint32 *generation_out) { if (capability_word_out != NULL) *capability_word_out = 0; @@ -909,8 +900,7 @@ void cluster_reconfig_formation_qvotec_complete(bool success pg_attribute_unused()) {} void -cluster_reconfig_formation_qvotec_note_max_generation( - uint64 generation pg_attribute_unused()) +cluster_reconfig_formation_qvotec_note_max_generation(uint64 generation pg_attribute_unused()) {} void cluster_reconfig_formation_qvotec_publish_observed( @@ -940,8 +930,7 @@ cluster_reconfig_bootstrap_publish_end(void) * test_cluster_formation_marker / test_cluster_reconfig. */ ClusterControlRootResult cluster_control_root_bootstrap_validate_active_round_fields( - uint64 transition_epoch pg_attribute_unused(), - uint64 prepare_generation pg_attribute_unused(), + uint64 transition_epoch pg_attribute_unused(), uint64 prepare_generation pg_attribute_unused(), uint64 source_feature_bitmap pg_attribute_unused(), uint64 target_feature_bitmap pg_attribute_unused()) { @@ -969,18 +958,18 @@ cluster_control_root_activate_prepared( return CLUSTER_CONTROL_ROOT_OK_PRIMARY; } bool -cluster_control_root_round_sha256( - const ClusterControlRootMigrationRoundV1 *round pg_attribute_unused(), - uint8 out_sha[PG_SHA256_DIGEST_LENGTH]) +cluster_control_root_round_sha256(const ClusterControlRootMigrationRoundV1 *round + pg_attribute_unused(), + uint8 out_sha[PG_SHA256_DIGEST_LENGTH]) { if (out_sha != NULL) memset(out_sha, 0x11, PG_SHA256_DIGEST_LENGTH); return true; } ClusterControlRootResult -cluster_control_root_build_migration_image( - const ClusterControlRootMigrationRoundV1 *round pg_attribute_unused(), - ClusterControlRootMigrationImage *out) +cluster_control_root_build_migration_image(const ClusterControlRootMigrationRoundV1 *round + pg_attribute_unused(), + ClusterControlRootMigrationImage *out) { if (out != NULL) memset(out, 0, sizeof(*out)); @@ -1023,9 +1012,9 @@ void cluster_write_fence_supersede_by_admit(uint64 admitted_epoch pg_attribute_unused()) {} bool -cluster_reconfig_join_qvotec_poll_pending( - ClusterJoinMarkerMailboxOperationV1 *operation_out, - int32 *out_target_node, void *out_slot512 pg_attribute_unused()) +cluster_reconfig_join_qvotec_poll_pending(ClusterJoinMarkerMailboxOperationV1 *operation_out, + int32 *out_target_node, + void *out_slot512 pg_attribute_unused()) { if (operation_out != NULL) *operation_out = CLUSTER_JOIN_MARKER_MAILBOX_WRITE_EXACT; @@ -1036,19 +1025,17 @@ cluster_reconfig_join_qvotec_poll_pending( void cluster_reconfig_join_qvotec_complete( ClusterJoinMarkerMailboxOperationV1 operation pg_attribute_unused(), - bool acked pg_attribute_unused(), - const uint8 *verified_image96 pg_attribute_unused()) + bool acked pg_attribute_unused(), const uint8 *verified_image96 pg_attribute_unused()) {} bool -cluster_reconfig_qvotec_lifecycle_transition( - ClusterQvotecMailbox *authority_mailbox, - pg_atomic_uint32 *qvotec_status, ClusterQvotecStatus next_status) +cluster_reconfig_qvotec_lifecycle_transition(ClusterQvotecMailbox *authority_mailbox, + pg_atomic_uint32 *qvotec_status, + ClusterQvotecStatus next_status) { if (authority_mailbox == NULL || qvotec_status == NULL) return false; pg_atomic_write_u32(qvotec_status, (uint32)next_status); - if (next_status == CLUSTER_QVOTEC_STARTING - || next_status == CLUSTER_QVOTEC_SHUTTING_DOWN) + if (next_status == CLUSTER_QVOTEC_STARTING || next_status == CLUSTER_QVOTEC_SHUTTING_DOWN) cluster_qvotec_mailbox_restart_reset(authority_mailbox); return true; } @@ -1065,8 +1052,7 @@ cluster_reconfig_lmon_observe_replacement_ready( return false; } bool -cluster_replacement_episode_is_valid( - const ClusterReplacementEpisode *episode pg_attribute_unused()) +cluster_replacement_episode_is_valid(const ClusterReplacementEpisode *episode pg_attribute_unused()) { return false; } @@ -1078,9 +1064,8 @@ cluster_reconfig_lmon_snapshot_replacement_admitted( return false; } bool -cluster_reconfig_lmon_snapshot_admitted_membership( - uint64 *out_members_lo, uint64 *out_members_hi, - uint64 *out_formation_epoch) +cluster_reconfig_lmon_snapshot_admitted_membership(uint64 *out_members_lo, uint64 *out_members_hi, + uint64 *out_formation_epoch) { if (out_members_lo != NULL) *out_members_lo = 0; @@ -1110,10 +1095,9 @@ cluster_lms_shared_state(void) return NULL; } bool -cluster_lms_r4_drain_request( - ClusterLmsSharedState *state pg_attribute_unused(), - uint64 generation pg_attribute_unused(), - uint64 *worker_incarnation pg_attribute_unused()) +cluster_lms_r4_drain_request(ClusterLmsSharedState *state pg_attribute_unused(), + uint64 generation pg_attribute_unused(), + uint64 *worker_incarnation pg_attribute_unused()) { return false; } @@ -1121,9 +1105,8 @@ void cluster_lms_wakeup(int worker_id pg_attribute_unused()) {} bool -cluster_cr_server_r4_lmon_reclaim_closed( - uint64 worker_incarnation pg_attribute_unused(), - uint64 generation pg_attribute_unused()) +cluster_cr_server_r4_lmon_reclaim_closed(uint64 worker_incarnation pg_attribute_unused(), + uint64 generation pg_attribute_unused()) { return false; } @@ -1195,12 +1178,12 @@ void cluster_reconfig_note_self_admitted(uint64 admitted_epoch); void cluster_reconfig_note_self_admitted(uint64 admitted_epoch pg_attribute_unused()) {} -bool cluster_reconfig_qvotec_observe_replacement_admitted( - const int *fds, int n_disks, uint64 live_incarnation); +bool cluster_reconfig_qvotec_observe_replacement_admitted(const int *fds, int n_disks, + uint64 live_incarnation); bool -cluster_reconfig_qvotec_observe_replacement_admitted( - const int *fds pg_attribute_unused(), int n_disks pg_attribute_unused(), - uint64 live_incarnation pg_attribute_unused()) +cluster_reconfig_qvotec_observe_replacement_admitted(const int *fds pg_attribute_unused(), + int n_disks pg_attribute_unused(), + uint64 live_incarnation pg_attribute_unused()) { return false; } @@ -1215,7 +1198,7 @@ cluster_reconfig_join_publish_proven(uint64 admitted_epoch pg_attribute_unused() } #ifndef CLUSTER_QVOTEC_PGSA_UNIT_TEST ClusterVotingDiskIoState cluster_voting_disk_read_join_slot(int fd, uint32 node_id, - void *out_slot512); + void *out_slot512); ClusterVotingDiskIoState cluster_voting_disk_read_join_slot(int fd pg_attribute_unused(), uint32 node_id pg_attribute_unused(), @@ -1240,11 +1223,11 @@ GetSystemIdentifier(void) return UINT64_C(1); } bool cluster_sf_peer_capability_generation_matches(int32 peer_id, uint32 required_capabilities, - uint32 expected_generation); + uint32 expected_generation); bool cluster_sf_peer_capability_generation_matches(int32 peer_id pg_attribute_unused(), - uint32 required_capabilities pg_attribute_unused(), - uint32 expected_generation pg_attribute_unused()) + uint32 required_capabilities pg_attribute_unused(), + uint32 expected_generation pg_attribute_unused()) { return false; } @@ -1353,8 +1336,7 @@ UT_TEST(test_qvotec_preserves_replacement_request_per_disk_fail_closed) marker.old_admitted_incarnation = 40; marker.fresh_incarnation = 41; marker.request_nonce = 42; - marker.grammar_fingerprint - = CLUSTER_REPLACEMENT_EPISODE_GRAMMAR_FINGERPRINT; + marker.grammar_fingerprint = CLUSTER_REPLACEMENT_EPISODE_GRAMMAR_FINGERPRINT; memset(&prior, 0, sizeof(prior)); prior.node_id = 3; @@ -1366,12 +1348,12 @@ UT_TEST(test_qvotec_preserves_replacement_request_per_disk_fail_closed) next.incarnation = 41; next.flags = CLUSTER_VOTING_SLOT_FLAG_ALIVE; UT_ASSERT_EQ(cluster_qvotec_test_replacement_request_preserve(&next, &prior), - CLUSTER_REPLACEMENT_REQUEST_SLOT_VALID); + CLUSTER_REPLACEMENT_REQUEST_SLOT_VALID); UT_ASSERT((next.flags & CLUSTER_VOTING_SLOT_FLAG_REPLACEMENT_REQUESTED) != 0); - UT_ASSERT_EQ(memcmp( - next._reserved1 + CLUSTER_REPLACEMENT_MARKER_RESERVED1_OFFSET, - prior._reserved1 + CLUSTER_REPLACEMENT_MARKER_RESERVED1_OFFSET, - CLUSTER_REPLACEMENT_MARKER_BYTES), 0); + UT_ASSERT_EQ(memcmp(next._reserved1 + CLUSTER_REPLACEMENT_MARKER_RESERVED1_OFFSET, + prior._reserved1 + CLUSTER_REPLACEMENT_MARKER_RESERVED1_OFFSET, + CLUSTER_REPLACEMENT_MARKER_BYTES), + 0); memset(&prior, 0, sizeof(prior)); memset(&next, 0x3c, sizeof(next)); @@ -1381,7 +1363,7 @@ UT_TEST(test_qvotec_preserves_replacement_request_per_disk_fail_closed) cluster_replacement_request_clear(next._reserved1); before = next; UT_ASSERT_EQ(cluster_qvotec_test_replacement_request_preserve(&next, &prior), - CLUSTER_REPLACEMENT_REQUEST_SLOT_CLEAR); + CLUSTER_REPLACEMENT_REQUEST_SLOT_CLEAR); UT_ASSERT_EQ(memcmp(&next, &before, sizeof(next)), 0); prior.node_id = 3; @@ -1389,14 +1371,14 @@ UT_TEST(test_qvotec_preserves_replacement_request_per_disk_fail_closed) UT_ASSERT(cluster_replacement_request_pack(prior._reserved1, &marker)); before = next; UT_ASSERT_EQ(cluster_qvotec_test_replacement_request_preserve(&next, &prior), - CLUSTER_REPLACEMENT_REQUEST_SLOT_HOLD); + CLUSTER_REPLACEMENT_REQUEST_SLOT_HOLD); UT_ASSERT_EQ(memcmp(&next, &before, sizeof(next)), 0); prior.flags = CLUSTER_VOTING_SLOT_FLAG_REPLACEMENT_REQUESTED; next.incarnation = 42; before = next; UT_ASSERT_EQ(cluster_qvotec_test_replacement_request_preserve(&next, &prior), - CLUSTER_REPLACEMENT_REQUEST_SLOT_HOLD); + CLUSTER_REPLACEMENT_REQUEST_SLOT_HOLD); UT_ASSERT_EQ(memcmp(&next, &before, sizeof(next)), 0); } @@ -1436,7 +1418,7 @@ UT_TEST(test_qvotec_shmem_and_mailbox_layout) UT_TEST(test_qvotec_mailbox_reset_discards_volatile_handoff) { ClusterQvotecMailbox mailbox; - const uint8 zero[sizeof(mailbox)] = {0}; + const uint8 zero[sizeof(mailbox)] = { 0 }; memset(&mailbox, 0xa5, sizeof(mailbox)); cluster_qvotec_mailbox_restart_reset(&mailbox); @@ -1448,12 +1430,12 @@ UT_TEST(test_qvotec_mailbox_recover_head_is_even_stable_and_single_outstanding) { ClusterQvotecMailbox mailbox; ClusterQvotecMailboxRequest request; - uint8 zero_value[CLUSTER_QVOTEC_AUTHORITY_VALUE_BYTES] = {0}; + uint8 zero_value[CLUSTER_QVOTEC_AUTHORITY_VALUE_BYTES] = { 0 }; uint64 request_seq = 0; cluster_qvotec_mailbox_restart_reset(&mailbox); - UT_ASSERT_EQ(cluster_qvotec_mailbox_lmon_submit( - &mailbox, CLUSTER_QVOTEC_MAILBOX_RECOVER_HEAD, zero_value, &request_seq), + UT_ASSERT_EQ(cluster_qvotec_mailbox_lmon_submit(&mailbox, CLUSTER_QVOTEC_MAILBOX_RECOVER_HEAD, + zero_value, &request_seq), CLUSTER_QVOTEC_MAILBOX_SUBMIT_ACCEPTED); UT_ASSERT_EQ(request_seq, 2); UT_ASSERT_EQ(pg_atomic_read_u64(&mailbox.request_seq), 2); @@ -1462,8 +1444,8 @@ UT_TEST(test_qvotec_mailbox_recover_head_is_even_stable_and_single_outstanding) UT_ASSERT_EQ(request.request_seq, 2); UT_ASSERT_EQ(request.opcode, CLUSTER_QVOTEC_MAILBOX_RECOVER_HEAD); UT_ASSERT_EQ(memcmp(request.request_value, zero_value, sizeof(zero_value)), 0); - UT_ASSERT_EQ(cluster_qvotec_mailbox_lmon_submit( - &mailbox, CLUSTER_QVOTEC_MAILBOX_RECOVER_HEAD, zero_value, &request_seq), + UT_ASSERT_EQ(cluster_qvotec_mailbox_lmon_submit(&mailbox, CLUSTER_QVOTEC_MAILBOX_RECOVER_HEAD, + zero_value, &request_seq), CLUSTER_QVOTEC_MAILBOX_SUBMIT_BUSY); } @@ -1480,8 +1462,8 @@ UT_TEST(test_qvotec_mailbox_actor_completion_round_trip) for (i = 0; i < (int)sizeof(request_value); i++) request_value[i] = (uint8)(i + 1); cluster_qvotec_mailbox_restart_reset(&mailbox); - UT_ASSERT_EQ(cluster_qvotec_mailbox_lmon_submit( - &mailbox, CLUSTER_QVOTEC_MAILBOX_PROPOSE_VALUE, request_value, &request_seq), + UT_ASSERT_EQ(cluster_qvotec_mailbox_lmon_submit(&mailbox, CLUSTER_QVOTEC_MAILBOX_PROPOSE_VALUE, + request_value, &request_seq), CLUSTER_QVOTEC_MAILBOX_SUBMIT_ACCEPTED); UT_ASSERT(cluster_qvotec_mailbox_qvotec_poll(&mailbox, &request)); UT_ASSERT_EQ(memcmp(request.request_value, request_value, sizeof(request_value)), 0); @@ -1508,14 +1490,14 @@ UT_TEST(test_qvotec_mailbox_actor_completion_round_trip) UT_ASSERT_EQ(observed.result, CLUSTER_QVOTEC_MAILBOX_CHOSEN); UT_ASSERT_EQ(memcmp(observed.completion_value, request_value, sizeof(request_value)), 0); UT_ASSERT_EQ(memcmp(observed.completion_ballot, completion.completion_ballot, - sizeof(completion.completion_ballot)), + sizeof(completion.completion_ballot)), 0); UT_ASSERT_EQ(observed.observed_disk_bitmap, UINT8_C(0x05)); UT_ASSERT_EQ(observed.actor_phase, CLUSTER_QVOTEC_ACTOR_SETTLE_WRITE); UT_ASSERT_EQ(observed.detail, UINT16_C(0x1234)); - UT_ASSERT_EQ(cluster_qvotec_mailbox_lmon_submit( - &mailbox, CLUSTER_QVOTEC_MAILBOX_PROPOSE_VALUE, request_value, &request_seq), + UT_ASSERT_EQ(cluster_qvotec_mailbox_lmon_submit(&mailbox, CLUSTER_QVOTEC_MAILBOX_PROPOSE_VALUE, + request_value, &request_seq), CLUSTER_QVOTEC_MAILBOX_SUBMIT_ACCEPTED); UT_ASSERT_EQ(request_seq, 4); } @@ -1523,22 +1505,22 @@ UT_TEST(test_qvotec_mailbox_actor_completion_round_trip) UT_TEST(test_qvotec_mailbox_rejects_invalid_and_holds_on_sequence_overflow) { ClusterQvotecMailbox mailbox; - uint8 zero_value[CLUSTER_QVOTEC_AUTHORITY_VALUE_BYTES] = {0}; - uint8 nonzero_value[CLUSTER_QVOTEC_AUTHORITY_VALUE_BYTES] = {1}; + uint8 zero_value[CLUSTER_QVOTEC_AUTHORITY_VALUE_BYTES] = { 0 }; + uint8 nonzero_value[CLUSTER_QVOTEC_AUTHORITY_VALUE_BYTES] = { 1 }; uint64 request_seq = 0; cluster_qvotec_mailbox_restart_reset(&mailbox); - UT_ASSERT_EQ(cluster_qvotec_mailbox_lmon_submit( - &mailbox, CLUSTER_QVOTEC_MAILBOX_NONE, zero_value, &request_seq), + UT_ASSERT_EQ(cluster_qvotec_mailbox_lmon_submit(&mailbox, CLUSTER_QVOTEC_MAILBOX_NONE, + zero_value, &request_seq), CLUSTER_QVOTEC_MAILBOX_SUBMIT_INVALID); - UT_ASSERT_EQ(cluster_qvotec_mailbox_lmon_submit( - &mailbox, CLUSTER_QVOTEC_MAILBOX_RECOVER_HEAD, nonzero_value, &request_seq), + UT_ASSERT_EQ(cluster_qvotec_mailbox_lmon_submit(&mailbox, CLUSTER_QVOTEC_MAILBOX_RECOVER_HEAD, + nonzero_value, &request_seq), CLUSTER_QVOTEC_MAILBOX_SUBMIT_INVALID); pg_atomic_write_u64(&mailbox.request_seq, UINT64_MAX - 1); pg_atomic_write_u64(&mailbox.completion_seq, UINT64_MAX - 1); - UT_ASSERT_EQ(cluster_qvotec_mailbox_lmon_submit( - &mailbox, CLUSTER_QVOTEC_MAILBOX_RECOVER_HEAD, zero_value, &request_seq), + UT_ASSERT_EQ(cluster_qvotec_mailbox_lmon_submit(&mailbox, CLUSTER_QVOTEC_MAILBOX_RECOVER_HEAD, + zero_value, &request_seq), CLUSTER_QVOTEC_MAILBOX_SUBMIT_HOLD); UT_ASSERT_EQ(pg_atomic_read_u64(&mailbox.request_seq), UINT64_MAX - 1); UT_ASSERT_EQ(pg_atomic_read_u64(&mailbox.completion_seq), UINT64_MAX - 1); @@ -1549,12 +1531,12 @@ UT_TEST(test_qvotec_mailbox_terminal_hold_completion) ClusterQvotecMailbox mailbox; ClusterQvotecMailboxCompletion completion; ClusterQvotecMailboxCompletion observed; - uint8 zero_value[CLUSTER_QVOTEC_AUTHORITY_VALUE_BYTES] = {0}; + uint8 zero_value[CLUSTER_QVOTEC_AUTHORITY_VALUE_BYTES] = { 0 }; uint64 request_seq = 0; cluster_qvotec_mailbox_restart_reset(&mailbox); - UT_ASSERT_EQ(cluster_qvotec_mailbox_lmon_submit( - &mailbox, CLUSTER_QVOTEC_MAILBOX_RECOVER_HEAD, zero_value, &request_seq), + UT_ASSERT_EQ(cluster_qvotec_mailbox_lmon_submit(&mailbox, CLUSTER_QVOTEC_MAILBOX_RECOVER_HEAD, + zero_value, &request_seq), CLUSTER_QVOTEC_MAILBOX_SUBMIT_ACCEPTED); memset(&completion, 0, sizeof(completion)); completion.request_seq = request_seq; @@ -2037,14 +2019,13 @@ pgsa_disk_set_open(PgsaDiskSet *set) for (i = 0; i < PGSA_TEST_DISKS; i++) set->fds[i] = -1; for (i = 0; i < PGSA_TEST_DISKS; i++) { - int n = snprintf(set->paths[i], sizeof(set->paths[i]), - "/tmp/pgrac-pgsa-%ld-%d-XXXXXX", (long)getpid(), i); + int n = snprintf(set->paths[i], sizeof(set->paths[i]), "/tmp/pgrac-pgsa-%ld-%d-XXXXXX", + (long)getpid(), i); if (n < 0 || n >= (int)sizeof(set->paths[i])) goto fail; set->fds[i] = mkstemp(set->paths[i]); - if (set->fds[i] < 0 - || ftruncate(set->fds[i], CLUSTER_VOTING_FILE_BYTES_MIN) != 0) + if (set->fds[i] < 0 || ftruncate(set->fds[i], CLUSTER_VOTING_FILE_BYTES_MIN) != 0) goto fail; } return true; @@ -2070,24 +2051,20 @@ pgsa_disk_set_close(PgsaDiskSet *set) static bool pgrd_test_image(uint8 root_kind, int32 owner_node, uint8 uuid_marker, - uint8 out[CLUSTER_UNDO_ROOT_DESCRIPTOR_BYTES]) + uint8 out[CLUSTER_UNDO_ROOT_DESCRIPTOR_BYTES]) { ClusterUndoRootDescriptorV1 descriptor; uint32 root_ordinal; memset(&descriptor, 0, sizeof(descriptor)); - root_ordinal = root_kind == CLUSTER_UNDO_ROOT_KIND_SHARED - ? 0 - : (uint32)owner_node + 1; + root_ordinal = root_kind == CLUSTER_UNDO_ROOT_KIND_SHARED ? 0 : (uint32)owner_node + 1; descriptor.descriptor_incarnation = 1; descriptor.root_kind = root_kind; descriptor.owner_node = owner_node; descriptor.root_ordinal = root_ordinal; - memset(descriptor.root_uuid, uuid_marker, - sizeof(descriptor.root_uuid)); + memset(descriptor.root_uuid, uuid_marker, sizeof(descriptor.root_uuid)); descriptor.system_identifier = UINT64_C(0x0123456789abcdef); - if (!cluster_undo_root_namespace_id(1, root_ordinal, - &descriptor.namespace_id)) + if (!cluster_undo_root_namespace_id(1, root_ordinal, &descriptor.namespace_id)) return false; return cluster_undo_root_descriptor_encode(&descriptor, out); } @@ -2321,7 +2298,7 @@ UT_TEST(test_normal_stop_no_config_generation_overflow_and_legacy_boundary) static int pgrd_count_image(const PgsaDiskSet *set, off_t offset, - const uint8 expected[CLUSTER_UNDO_ROOT_DESCRIPTOR_BYTES]) + const uint8 expected[CLUSTER_UNDO_ROOT_DESCRIPTOR_BYTES]) { uint8 actual[CLUSTER_UNDO_ROOT_DESCRIPTOR_BYTES]; int count = 0; @@ -2347,15 +2324,12 @@ UT_TEST(test_pgrd_initial_shared_eof_provisions_exact_majority) UT_ASSERT(false); return; } - UT_ASSERT(pgrd_test_image(CLUSTER_UNDO_ROOT_KIND_SHARED, -1, 0x31, - desired)); + UT_ASSERT(pgrd_test_image(CLUSTER_UNDO_ROOT_KIND_SHARED, -1, 0x31, desired)); UT_ASSERT(cluster_qvotec_test_undo_root_descriptor_provision( - set.fds, PGSA_TEST_DISKS, UINT64_C(0x0123456789abcdef), desired, - &completed)); + set.fds, PGSA_TEST_DISKS, UINT64_C(0x0123456789abcdef), desired, &completed)); UT_ASSERT_EQ(completed, UINT8_C(0x07)); - UT_ASSERT_EQ(pgrd_count_image( - &set, CLUSTER_UNDO_ROOT_DESCRIPTOR_SHARED_OFFSET, desired), - PGSA_TEST_DISKS); + UT_ASSERT_EQ(pgrd_count_image(&set, CLUSTER_UNDO_ROOT_DESCRIPTOR_SHARED_OFFSET, desired), + PGSA_TEST_DISKS); pgsa_disk_set_close(&set); } @@ -2369,19 +2343,15 @@ UT_TEST(test_pgrd_exact_partial_retry_is_idempotent) UT_ASSERT(false); return; } - UT_ASSERT(pgrd_test_image(CLUSTER_UNDO_ROOT_KIND_SHARED, -1, 0x42, - desired)); + UT_ASSERT(pgrd_test_image(CLUSTER_UNDO_ROOT_KIND_SHARED, -1, 0x42, desired)); UT_ASSERT_EQ(cluster_voting_disk_write_raw_slot_at( - set.fds[0], CLUSTER_UNDO_ROOT_DESCRIPTOR_SHARED_OFFSET, - desired), + set.fds[0], CLUSTER_UNDO_ROOT_DESCRIPTOR_SHARED_OFFSET, desired), CLUSTER_VOTING_DISK_IO_OK); UT_ASSERT(cluster_qvotec_test_undo_root_descriptor_provision( - set.fds, PGSA_TEST_DISKS, UINT64_C(0x0123456789abcdef), desired, - &completed)); + set.fds, PGSA_TEST_DISKS, UINT64_C(0x0123456789abcdef), desired, &completed)); UT_ASSERT_EQ(completed, UINT8_C(0x07)); - UT_ASSERT_EQ(pgrd_count_image( - &set, CLUSTER_UNDO_ROOT_DESCRIPTOR_SHARED_OFFSET, desired), - PGSA_TEST_DISKS); + UT_ASSERT_EQ(pgrd_count_image(&set, CLUSTER_UNDO_ROOT_DESCRIPTOR_SHARED_OFFSET, desired), + PGSA_TEST_DISKS); pgsa_disk_set_close(&set); } @@ -2398,21 +2368,16 @@ UT_TEST(test_pgrd_reachable_conflict_holds_without_mutation) UT_ASSERT(false); return; } - UT_ASSERT(pgrd_test_image(CLUSTER_UNDO_ROOT_KIND_SHARED, -1, 0x53, - desired)); - UT_ASSERT(pgrd_test_image(CLUSTER_UNDO_ROOT_KIND_SHARED, -1, 0x64, - conflict)); + UT_ASSERT(pgrd_test_image(CLUSTER_UNDO_ROOT_KIND_SHARED, -1, 0x53, desired)); + UT_ASSERT(pgrd_test_image(CLUSTER_UNDO_ROOT_KIND_SHARED, -1, 0x64, conflict)); UT_ASSERT_EQ(cluster_voting_disk_write_raw_slot_at( - set.fds[0], CLUSTER_UNDO_ROOT_DESCRIPTOR_SHARED_OFFSET, - conflict), + set.fds[0], CLUSTER_UNDO_ROOT_DESCRIPTOR_SHARED_OFFSET, conflict), CLUSTER_VOTING_DISK_IO_OK); UT_ASSERT(!cluster_qvotec_test_undo_root_descriptor_provision( - set.fds, PGSA_TEST_DISKS, UINT64_C(0x0123456789abcdef), desired, - &completed)); + set.fds, PGSA_TEST_DISKS, UINT64_C(0x0123456789abcdef), desired, &completed)); UT_ASSERT_EQ(completed, UINT8_C(0xa5)); UT_ASSERT_EQ(cluster_voting_disk_read_raw_slot_at( - set.fds[0], CLUSTER_UNDO_ROOT_DESCRIPTOR_SHARED_OFFSET, - observed), + set.fds[0], CLUSTER_UNDO_ROOT_DESCRIPTOR_SHARED_OFFSET, observed), CLUSTER_VOTING_DISK_RAW_READ_FULL); UT_ASSERT_EQ(memcmp(observed, conflict, sizeof(observed)), 0); UT_ASSERT_EQ(fstat(set.fds[1], &st), 0); @@ -2432,16 +2397,12 @@ UT_TEST(test_pgrd_short_read_holds_despite_clean_majority) UT_ASSERT(false); return; } - UT_ASSERT(pgrd_test_image(CLUSTER_UNDO_ROOT_KIND_SHARED, -1, 0x75, - desired)); - UT_ASSERT_EQ(ftruncate( - set.fds[0], CLUSTER_UNDO_ROOT_DESCRIPTOR_SHARED_OFFSET + 17), 0); + UT_ASSERT(pgrd_test_image(CLUSTER_UNDO_ROOT_KIND_SHARED, -1, 0x75, desired)); + UT_ASSERT_EQ(ftruncate(set.fds[0], CLUSTER_UNDO_ROOT_DESCRIPTOR_SHARED_OFFSET + 17), 0); UT_ASSERT(!cluster_qvotec_test_undo_root_descriptor_provision( - set.fds, PGSA_TEST_DISKS, UINT64_C(0x0123456789abcdef), desired, - &completed)); + set.fds, PGSA_TEST_DISKS, UINT64_C(0x0123456789abcdef), desired, &completed)); UT_ASSERT_EQ(completed, UINT8_C(0x96)); - UT_ASSERT_EQ(pgrd_count_image( - &set, CLUSTER_UNDO_ROOT_DESCRIPTOR_SHARED_OFFSET, desired), 0); + UT_ASSERT_EQ(pgrd_count_image(&set, CLUSTER_UNDO_ROOT_DESCRIPTOR_SHARED_OFFSET, desired), 0); pgsa_disk_set_close(&set); } @@ -2456,19 +2417,16 @@ UT_TEST(test_pgrd_postwrite_one_of_three_exact_does_not_commit) UT_ASSERT(false); return; } - UT_ASSERT(pgrd_test_image(CLUSTER_UNDO_ROOT_KIND_SHARED, -1, 0x80, - desired)); + UT_ASSERT(pgrd_test_image(CLUSTER_UNDO_ROOT_KIND_SHARED, -1, 0x80, desired)); for (i = 1; i < PGSA_TEST_DISKS; i++) { UT_ASSERT_EQ(close(set.fds[i]), 0); set.fds[i] = open(set.paths[i], O_RDONLY | PG_BINARY); UT_ASSERT(set.fds[i] >= 0); } UT_ASSERT(!cluster_qvotec_test_undo_root_descriptor_provision( - set.fds, PGSA_TEST_DISKS, UINT64_C(0x0123456789abcdef), desired, - &completed)); + set.fds, PGSA_TEST_DISKS, UINT64_C(0x0123456789abcdef), desired, &completed)); UT_ASSERT_EQ(completed, UINT8_C(0x87)); - UT_ASSERT_EQ(pgrd_count_image( - &set, CLUSTER_UNDO_ROOT_DESCRIPTOR_SHARED_OFFSET, desired), 1); + UT_ASSERT_EQ(pgrd_count_image(&set, CLUSTER_UNDO_ROOT_DESCRIPTOR_SHARED_OFFSET, desired), 1); pgsa_disk_set_close(&set); } @@ -2486,11 +2444,9 @@ UT_TEST(test_pgrd_local_node_127_uses_last_frozen_slot) UT_ASSERT(false); return; } - UT_ASSERT(pgrd_test_image(CLUSTER_UNDO_ROOT_KIND_LOCAL, 127, 0x86, - desired)); + UT_ASSERT(pgrd_test_image(CLUSTER_UNDO_ROOT_KIND_LOCAL, 127, 0x86, desired)); UT_ASSERT(cluster_qvotec_test_undo_root_descriptor_provision( - set.fds, PGSA_TEST_DISKS, UINT64_C(0x0123456789abcdef), desired, - &completed)); + set.fds, PGSA_TEST_DISKS, UINT64_C(0x0123456789abcdef), desired, &completed)); UT_ASSERT_EQ(completed, UINT8_C(0x07)); for (i = 0; i < PGSA_TEST_DISKS; i++) { UT_ASSERT_EQ(fstat(set.fds[i], &st), 0); @@ -2498,18 +2454,15 @@ UT_TEST(test_pgrd_local_node_127_uses_last_frozen_slot) * 8N+3 slots) now covers region 7, but the runtime file still * materializes regions lazily — the node-127 write extends the * base file exactly through the last descriptor slot. */ - UT_ASSERT_EQ(st.st_size, - CLUSTER_UNDO_ROOT_DESCRIPTOR_LOCAL_OFFSET(127) - + CLUSTER_UNDO_ROOT_DESCRIPTOR_BYTES); + UT_ASSERT_EQ(st.st_size, CLUSTER_UNDO_ROOT_DESCRIPTOR_LOCAL_OFFSET(127) + + CLUSTER_UNDO_ROOT_DESCRIPTOR_BYTES); UT_ASSERT_EQ(cluster_voting_disk_read_raw_slot_at( - set.fds[i], - CLUSTER_UNDO_ROOT_DESCRIPTOR_SHARED_OFFSET, observed), + set.fds[i], CLUSTER_UNDO_ROOT_DESCRIPTOR_SHARED_OFFSET, observed), CLUSTER_VOTING_DISK_RAW_READ_FULL); UT_ASSERT_EQ(memcmp(observed, zero, sizeof(observed)), 0); } - UT_ASSERT_EQ(pgrd_count_image( - &set, CLUSTER_UNDO_ROOT_DESCRIPTOR_LOCAL_OFFSET(127), desired), - PGSA_TEST_DISKS); + UT_ASSERT_EQ(pgrd_count_image(&set, CLUSTER_UNDO_ROOT_DESCRIPTOR_LOCAL_OFFSET(127), desired), + PGSA_TEST_DISKS); pgsa_disk_set_close(&set); } @@ -2525,11 +2478,9 @@ UT_TEST(test_pgrd_majority_read_requires_two_exact_images) UT_ASSERT(false); return; } - UT_ASSERT(pgrd_test_image(CLUSTER_UNDO_ROOT_KIND_SHARED, -1, 0x91, - desired)); + UT_ASSERT(pgrd_test_image(CLUSTER_UNDO_ROOT_KIND_SHARED, -1, 0x91, desired)); UT_ASSERT_EQ(cluster_voting_disk_write_raw_slot_at( - set.fds[0], CLUSTER_UNDO_ROOT_DESCRIPTOR_SHARED_OFFSET, - desired), + set.fds[0], CLUSTER_UNDO_ROOT_DESCRIPTOR_SHARED_OFFSET, desired), CLUSTER_VOTING_DISK_IO_OK); UT_ASSERT_EQ(close(set.fds[1]), 0); set.fds[1] = -1; @@ -2537,10 +2488,8 @@ UT_TEST(test_pgrd_majority_read_requires_two_exact_images) set.fds[2] = -1; memset(&observed, 0, sizeof(observed)); UT_ASSERT_EQ(cluster_qvotec_test_undo_root_descriptor_read( - set.fds, PGSA_TEST_DISKS, - UINT64_C(0x0123456789abcdef), - CLUSTER_UNDO_ROOT_KIND_SHARED, -1, &observed, - &observed_bitmap), + set.fds, PGSA_TEST_DISKS, UINT64_C(0x0123456789abcdef), + CLUSTER_UNDO_ROOT_KIND_SHARED, -1, &observed, &observed_bitmap), CLUSTER_UNDO_ROOT_DESCRIPTOR_HOLD); set.fds[1] = open(set.paths[1], O_RDWR | PG_BINARY); @@ -2548,14 +2497,11 @@ UT_TEST(test_pgrd_majority_read_requires_two_exact_images) set.fds[2] = open(set.paths[2], O_RDWR | PG_BINARY); UT_ASSERT(set.fds[2] >= 0); UT_ASSERT_EQ(cluster_voting_disk_write_raw_slot_at( - set.fds[1], CLUSTER_UNDO_ROOT_DESCRIPTOR_SHARED_OFFSET, - desired), + set.fds[1], CLUSTER_UNDO_ROOT_DESCRIPTOR_SHARED_OFFSET, desired), CLUSTER_VOTING_DISK_IO_OK); UT_ASSERT_EQ(cluster_qvotec_test_undo_root_descriptor_read( - set.fds, PGSA_TEST_DISKS, - UINT64_C(0x0123456789abcdef), - CLUSTER_UNDO_ROOT_KIND_SHARED, -1, &observed, - &observed_bitmap), + set.fds, PGSA_TEST_DISKS, UINT64_C(0x0123456789abcdef), + CLUSTER_UNDO_ROOT_KIND_SHARED, -1, &observed, &observed_bitmap), CLUSTER_UNDO_ROOT_DESCRIPTOR_VALID); UT_ASSERT_EQ(observed_bitmap, UINT8_C(0x03)); UT_ASSERT_EQ(observed.descriptor_incarnation, UINT64_C(1)); @@ -2565,8 +2511,7 @@ UT_TEST(test_pgrd_majority_read_requires_two_exact_images) for (i = 0; i < CLUSTER_UNDO_ROOT_UUID_BYTES; i++) UT_ASSERT_EQ(observed.root_uuid[i], UINT8_C(0x91)); UT_ASSERT_EQ(observed.namespace_id, UINT64_C(1)); - UT_ASSERT_EQ(observed.system_identifier, - UINT64_C(0x0123456789abcdef)); + UT_ASSERT_EQ(observed.system_identifier, UINT64_C(0x0123456789abcdef)); pgsa_disk_set_close(&set); } @@ -2582,25 +2527,19 @@ UT_TEST(test_pgrd_majority_read_short_member_holds) UT_ASSERT(false); return; } - UT_ASSERT(pgrd_test_image(CLUSTER_UNDO_ROOT_KIND_SHARED, -1, 0x92, - desired)); + UT_ASSERT(pgrd_test_image(CLUSTER_UNDO_ROOT_KIND_SHARED, -1, 0x92, desired)); UT_ASSERT_EQ(cluster_voting_disk_write_raw_slot_at( - set.fds[0], CLUSTER_UNDO_ROOT_DESCRIPTOR_SHARED_OFFSET, - desired), + set.fds[0], CLUSTER_UNDO_ROOT_DESCRIPTOR_SHARED_OFFSET, desired), CLUSTER_VOTING_DISK_IO_OK); UT_ASSERT_EQ(cluster_voting_disk_write_raw_slot_at( - set.fds[1], CLUSTER_UNDO_ROOT_DESCRIPTOR_SHARED_OFFSET, - desired), + set.fds[1], CLUSTER_UNDO_ROOT_DESCRIPTOR_SHARED_OFFSET, desired), CLUSTER_VOTING_DISK_IO_OK); - UT_ASSERT_EQ(ftruncate( - set.fds[2], CLUSTER_UNDO_ROOT_DESCRIPTOR_SHARED_OFFSET + 17), 0); + UT_ASSERT_EQ(ftruncate(set.fds[2], CLUSTER_UNDO_ROOT_DESCRIPTOR_SHARED_OFFSET + 17), 0); memset(&observed, 0xa5, sizeof(observed)); memset(&zero, 0, sizeof(zero)); UT_ASSERT_EQ(cluster_qvotec_test_undo_root_descriptor_read( - set.fds, PGSA_TEST_DISKS, - UINT64_C(0x0123456789abcdef), - CLUSTER_UNDO_ROOT_KIND_SHARED, -1, &observed, - &observed_bitmap), + set.fds, PGSA_TEST_DISKS, UINT64_C(0x0123456789abcdef), + CLUSTER_UNDO_ROOT_KIND_SHARED, -1, &observed, &observed_bitmap), CLUSTER_UNDO_ROOT_DESCRIPTOR_HOLD); UT_ASSERT_EQ(memcmp(&observed, &zero, sizeof(observed)), 0); UT_ASSERT_EQ(observed_bitmap, UINT8_C(0)); @@ -2621,10 +2560,8 @@ UT_TEST(test_pgrd_majority_read_same_incarnation_conflict_holds) UT_ASSERT(false); return; } - UT_ASSERT(pgrd_test_image(CLUSTER_UNDO_ROOT_KIND_SHARED, -1, 0x93, - desired)); - UT_ASSERT(pgrd_test_image(CLUSTER_UNDO_ROOT_KIND_SHARED, -1, 0x94, - conflict)); + UT_ASSERT(pgrd_test_image(CLUSTER_UNDO_ROOT_KIND_SHARED, -1, 0x93, desired)); + UT_ASSERT(pgrd_test_image(CLUSTER_UNDO_ROOT_KIND_SHARED, -1, 0x94, conflict)); for (i = 0; i < PGSA_TEST_DISKS; i++) UT_ASSERT_EQ(cluster_voting_disk_write_raw_slot_at( set.fds[i], CLUSTER_UNDO_ROOT_DESCRIPTOR_SHARED_OFFSET, @@ -2633,10 +2570,8 @@ UT_TEST(test_pgrd_majority_read_same_incarnation_conflict_holds) memset(&observed, 0xa5, sizeof(observed)); memset(&zero, 0, sizeof(zero)); UT_ASSERT_EQ(cluster_qvotec_test_undo_root_descriptor_read( - set.fds, PGSA_TEST_DISKS, - UINT64_C(0x0123456789abcdef), - CLUSTER_UNDO_ROOT_KIND_SHARED, -1, &observed, - &observed_bitmap), + set.fds, PGSA_TEST_DISKS, UINT64_C(0x0123456789abcdef), + CLUSTER_UNDO_ROOT_KIND_SHARED, -1, &observed, &observed_bitmap), CLUSTER_UNDO_ROOT_DESCRIPTOR_HOLD); UT_ASSERT_EQ(memcmp(&observed, &zero, sizeof(observed)), 0); UT_ASSERT_EQ(observed_bitmap, UINT8_C(0)); @@ -2650,7 +2585,7 @@ UT_TEST(test_normal_start_pgrd_bootstrap_reads_exact_and_zero_without_writes) PgsaDiskSet set; char csv[3 * MAXPGPATH + 16]; char *saved_csv = cluster_voting_disks; - uint8 wanted[512], observed[512], disk[512], zero[512] = {0}; + uint8 wanted[512], observed[512], disk[512], zero[512] = { 0 }; int i; int fd_before, fd_after; @@ -2663,24 +2598,28 @@ UT_TEST(test_normal_start_pgrd_bootstrap_reads_exact_and_zero_without_writes) UT_ASSERT(fd_before >= 0); UT_ASSERT_EQ(close(fd_before), 0); memset(observed, 0xa5, sizeof(observed)); - UT_ASSERT_EQ(cluster_qvotec_bootstrap_read_undo_root_descriptor( - UINT64_C(0x0123456789abcdef), observed), CLUSTER_UNDO_ROOT_DESCRIPTOR_UNPROVISIONED); + UT_ASSERT_EQ( + cluster_qvotec_bootstrap_read_undo_root_descriptor(UINT64_C(0x0123456789abcdef), observed), + CLUSTER_UNDO_ROOT_DESCRIPTOR_UNPROVISIONED); UT_ASSERT_EQ(memcmp(observed, zero, sizeof(zero)), 0); UT_ASSERT(pgrd_test_image(CLUSTER_UNDO_ROOT_KIND_SHARED, -1, 0x91, wanted)); for (i = 0; i < 2; i++) - UT_ASSERT_EQ(cluster_voting_disk_write_raw_slot_at(set.fds[i], - CLUSTER_UNDO_ROOT_DESCRIPTOR_SHARED_OFFSET, wanted), CLUSTER_VOTING_DISK_IO_OK); - UT_ASSERT_EQ(cluster_qvotec_bootstrap_read_undo_root_descriptor( - UINT64_C(0x0123456789abcdef), observed), CLUSTER_UNDO_ROOT_DESCRIPTOR_VALID); + UT_ASSERT_EQ(cluster_voting_disk_write_raw_slot_at( + set.fds[i], CLUSTER_UNDO_ROOT_DESCRIPTOR_SHARED_OFFSET, wanted), + CLUSTER_VOTING_DISK_IO_OK); + UT_ASSERT_EQ( + cluster_qvotec_bootstrap_read_undo_root_descriptor(UINT64_C(0x0123456789abcdef), observed), + CLUSTER_UNDO_ROOT_DESCRIPTOR_VALID); UT_ASSERT_EQ(memcmp(observed, wanted, sizeof(wanted)), 0); for (i = 0; i < 2; i++) { - UT_ASSERT_EQ(pread(set.fds[i], disk, sizeof(disk), - CLUSTER_UNDO_ROOT_DESCRIPTOR_SHARED_OFFSET), sizeof(disk)); + UT_ASSERT_EQ( + pread(set.fds[i], disk, sizeof(disk), CLUSTER_UNDO_ROOT_DESCRIPTOR_SHARED_OFFSET), + sizeof(disk)); UT_ASSERT_EQ(memcmp(disk, wanted, sizeof(disk)), 0); } /* An EOF member is not back-filled by a read. */ - UT_ASSERT_EQ(pread(set.fds[2], disk, sizeof(disk), - CLUSTER_UNDO_ROOT_DESCRIPTOR_SHARED_OFFSET), 0); + UT_ASSERT_EQ(pread(set.fds[2], disk, sizeof(disk), CLUSTER_UNDO_ROOT_DESCRIPTOR_SHARED_OFFSET), + 0); fd_after = open("/dev/null", O_RDONLY); UT_ASSERT_EQ(fd_after, fd_before); UT_ASSERT_EQ(close(fd_after), 0); @@ -2707,29 +2646,32 @@ UT_TEST(test_normal_start_pgrd_bootstrap_preserves_strict_refusals) memset(sentinel, 0xa5, sizeof(sentinel)); for (variant = 0; variant < 4; variant++) { for (i = 0; i < 3; i++) - UT_ASSERT_EQ(cluster_voting_disk_write_raw_slot_at(set.fds[i], - CLUSTER_UNDO_ROOT_DESCRIPTOR_SHARED_OFFSET, wanted), CLUSTER_VOTING_DISK_IO_OK); + UT_ASSERT_EQ(cluster_voting_disk_write_raw_slot_at( + set.fds[i], CLUSTER_UNDO_ROOT_DESCRIPTOR_SHARED_OFFSET, wanted), + CLUSTER_VOTING_DISK_IO_OK); if (variant == 1) UT_ASSERT_EQ(ftruncate(set.fds[2], CLUSTER_UNDO_ROOT_DESCRIPTOR_SHARED_OFFSET + 17), 0); if (variant == 2) - UT_ASSERT_EQ(cluster_voting_disk_write_raw_slot_at(set.fds[2], - CLUSTER_UNDO_ROOT_DESCRIPTOR_SHARED_OFFSET, conflict), CLUSTER_VOTING_DISK_IO_OK); + UT_ASSERT_EQ(cluster_voting_disk_write_raw_slot_at( + set.fds[2], CLUSTER_UNDO_ROOT_DESCRIPTOR_SHARED_OFFSET, conflict), + CLUSTER_VOTING_DISK_IO_OK); if (variant == 3) { uint8 bad = 1; - UT_ASSERT_EQ(pwrite(set.fds[2], &bad, 1, - CLUSTER_UNDO_ROOT_DESCRIPTOR_SHARED_OFFSET + 200), 1); + UT_ASSERT_EQ( + pwrite(set.fds[2], &bad, 1, CLUSTER_UNDO_ROOT_DESCRIPTOR_SHARED_OFFSET + 200), 1); } memcpy(observed, sentinel, sizeof(observed)); UT_ASSERT_EQ(cluster_qvotec_bootstrap_read_undo_root_descriptor( - variant == 0 ? 7 : UINT64_C(0x0123456789abcdef), observed), - CLUSTER_UNDO_ROOT_DESCRIPTOR_HOLD); + variant == 0 ? 7 : UINT64_C(0x0123456789abcdef), observed), + CLUSTER_UNDO_ROOT_DESCRIPTOR_HOLD); UT_ASSERT_EQ(memcmp(observed, sentinel, sizeof(observed)), 0); } /* A configured inaccessible disk cannot be silently removed from quorum. */ UT_ASSERT_EQ(unlink(set.paths[2]), 0); memcpy(observed, sentinel, sizeof(observed)); - UT_ASSERT_EQ(cluster_qvotec_bootstrap_read_undo_root_descriptor( - UINT64_C(0x0123456789abcdef), observed), CLUSTER_UNDO_ROOT_DESCRIPTOR_HOLD); + UT_ASSERT_EQ( + cluster_qvotec_bootstrap_read_undo_root_descriptor(UINT64_C(0x0123456789abcdef), observed), + CLUSTER_UNDO_ROOT_DESCRIPTOR_HOLD); UT_ASSERT_EQ(memcmp(observed, sentinel, sizeof(observed)), 0); cluster_voting_disks = saved_csv; pgsa_disk_set_close(&set); @@ -2771,8 +2713,7 @@ static bool pgsa_read_image(int fd, uint8 bytes[CLUSTER_SEMANTIC_ACTIVATION_RECORD_BYTES]) { memset(bytes, 0, CLUSTER_SEMANTIC_ACTIVATION_RECORD_BYTES); - return cluster_voting_disk_read_raw_tail_slot(fd, bytes) - == CLUSTER_VOTING_DISK_RAW_READ_FULL; + return cluster_voting_disk_read_raw_tail_slot(fd, bytes) == CLUSTER_VOTING_DISK_RAW_READ_FULL; } static bool @@ -2814,8 +2755,7 @@ pgsa_count_image(const PgsaDiskSet *set, int i; for (i = 0; i < PGSA_TEST_DISKS; i++) { - if (pgsa_read_image(set->fds[i], actual) - && memcmp(actual, expected, sizeof(actual)) == 0) + if (pgsa_read_image(set->fds[i], actual) && memcmp(actual, expected, sizeof(actual)) == 0) count++; } return count; @@ -2840,11 +2780,9 @@ UT_TEST(test_pgsa_01_expected_majority_plus_stale_commits_desired) UT_ASSERT(false); return; } - UT_ASSERT(pgsa_encode(pgsa_record(CLUSTER_SEMANTIC_PHASE_PREPARE, 7, 0x11, 0x22), - current)); + UT_ASSERT(pgsa_encode(pgsa_record(CLUSTER_SEMANTIC_PHASE_PREPARE, 7, 0x11, 0x22), current)); UT_ASSERT(pgsa_encode(pgsa_record(CLUSTER_SEMANTIC_PHASE_OPEN, 6, 0x11, 0x11), stale)); - UT_ASSERT(pgsa_encode(pgsa_record(CLUSTER_SEMANTIC_PHASE_COMMIT, 8, 0x11, 0x22), - desired)); + UT_ASSERT(pgsa_encode(pgsa_record(CLUSTER_SEMANTIC_PHASE_COMMIT, 8, 0x11, 0x22), desired)); UT_ASSERT(pgsa_write_image(set.fds[0], current)); UT_ASSERT(pgsa_write_image(set.fds[1], current)); UT_ASSERT(pgsa_write_image(set.fds[2], stale)); @@ -2865,14 +2803,12 @@ UT_TEST(test_pgsa_02_generation_mismatch_is_conflict_without_mutation) UT_ASSERT(false); return; } - UT_ASSERT(pgsa_encode(pgsa_record(CLUSTER_SEMANTIC_PHASE_COMMIT, 7, 0x11, 0x22), - current)); + UT_ASSERT(pgsa_encode(pgsa_record(CLUSTER_SEMANTIC_PHASE_COMMIT, 7, 0x11, 0x22), current)); UT_ASSERT(pgsa_encode(pgsa_record(CLUSTER_SEMANTIC_PHASE_OPEN, 7, 0x11, 0x22), desired)); for (i = 0; i < PGSA_TEST_DISKS; i++) UT_ASSERT(pgsa_write_image(set.fds[i], current)); UT_ASSERT(pgsa_snapshot(&set, before)); - UT_ASSERT_EQ(pgsa_cas(&set, 6, 0x11, desired), - CLUSTER_SEMANTIC_ACTIVATION_RECORD_CONFLICT); + UT_ASSERT_EQ(pgsa_cas(&set, 6, 0x11, desired), CLUSTER_SEMANTIC_ACTIVATION_RECORD_CONFLICT); UT_ASSERT(pgsa_snapshot_matches(&set, before)); pgsa_disk_set_close(&set); } @@ -2889,14 +2825,12 @@ UT_TEST(test_pgsa_03_source_mismatch_is_conflict_without_mutation) UT_ASSERT(false); return; } - UT_ASSERT(pgsa_encode(pgsa_record(CLUSTER_SEMANTIC_PHASE_COMMIT, 7, 0x11, 0x22), - current)); + UT_ASSERT(pgsa_encode(pgsa_record(CLUSTER_SEMANTIC_PHASE_COMMIT, 7, 0x11, 0x22), current)); UT_ASSERT(pgsa_encode(pgsa_record(CLUSTER_SEMANTIC_PHASE_OPEN, 8, 0x44, 0x22), desired)); for (i = 0; i < PGSA_TEST_DISKS; i++) UT_ASSERT(pgsa_write_image(set.fds[i], current)); UT_ASSERT(pgsa_snapshot(&set, before)); - UT_ASSERT_EQ(pgsa_cas(&set, 7, 0x44, desired), - CLUSTER_SEMANTIC_ACTIVATION_RECORD_CONFLICT); + UT_ASSERT_EQ(pgsa_cas(&set, 7, 0x44, desired), CLUSTER_SEMANTIC_ACTIVATION_RECORD_CONFLICT); UT_ASSERT(pgsa_snapshot_matches(&set, before)); pgsa_disk_set_close(&set); } @@ -2913,14 +2847,12 @@ UT_TEST(test_pgsa_04_commit_to_open_requires_explicit_prior_source) UT_ASSERT(false); return; } - UT_ASSERT(pgsa_encode(pgsa_record(CLUSTER_SEMANTIC_PHASE_COMMIT, 7, 0x11, 0x22), - current)); + UT_ASSERT(pgsa_encode(pgsa_record(CLUSTER_SEMANTIC_PHASE_COMMIT, 7, 0x11, 0x22), current)); UT_ASSERT(pgsa_encode(pgsa_record(CLUSTER_SEMANTIC_PHASE_OPEN, 8, 0x11, 0x22), desired)); for (i = 0; i < PGSA_TEST_DISKS; i++) UT_ASSERT(pgsa_write_image(set.fds[i], current)); UT_ASSERT(pgsa_snapshot(&set, before)); - UT_ASSERT_EQ(pgsa_cas(&set, 7, 0x22, desired), - CLUSTER_SEMANTIC_ACTIVATION_BAD_STATE); + UT_ASSERT_EQ(pgsa_cas(&set, 7, 0x22, desired), CLUSTER_SEMANTIC_ACTIVATION_BAD_STATE); UT_ASSERT(pgsa_snapshot_matches(&set, before)); UT_ASSERT_EQ(pgsa_cas(&set, 7, 0x11, desired), CLUSTER_SEMANTIC_ACTIVATION_OK); pgsa_disk_set_close(&set); @@ -2937,14 +2869,11 @@ UT_TEST(test_pgsa_04a_open_to_next_prepare_uses_open_target_as_current_source) UT_ASSERT(false); return; } - UT_ASSERT(pgsa_encode(pgsa_record( - CLUSTER_SEMANTIC_PHASE_OPEN, 7, 0x11, 0x22), current)); - UT_ASSERT(pgsa_encode(pgsa_record( - CLUSTER_SEMANTIC_PHASE_PREPARE, 8, 0x22, 0x422), desired)); + UT_ASSERT(pgsa_encode(pgsa_record(CLUSTER_SEMANTIC_PHASE_OPEN, 7, 0x11, 0x22), current)); + UT_ASSERT(pgsa_encode(pgsa_record(CLUSTER_SEMANTIC_PHASE_PREPARE, 8, 0x22, 0x422), desired)); for (i = 0; i < PGSA_TEST_DISKS; i++) UT_ASSERT(pgsa_write_image(set.fds[i], current)); - UT_ASSERT_EQ(pgsa_cas(&set, 7, 0x22, desired), - CLUSTER_SEMANTIC_ACTIVATION_OK); + UT_ASSERT_EQ(pgsa_cas(&set, 7, 0x22, desired), CLUSTER_SEMANTIC_ACTIVATION_OK); UT_ASSERT_EQ(pgsa_count_image(&set, desired), PGSA_TEST_DISKS); pgsa_disk_set_close(&set); } @@ -2953,11 +2882,10 @@ UT_TEST(test_pgsa_04b_desired_source_mismatch_is_bad_state_before_io) { uint8 desired[CLUSTER_SEMANTIC_ACTIVATION_RECORD_BYTES]; - UT_ASSERT(pgsa_encode(pgsa_record( - CLUSTER_SEMANTIC_PHASE_COMMIT, 8, 0x44, 0x55), desired)); - UT_ASSERT_EQ(cluster_qvotec_test_semantic_activation_record_cas_write( - NULL, 0, 7, 0x11, desired), - CLUSTER_SEMANTIC_ACTIVATION_BAD_STATE); + UT_ASSERT(pgsa_encode(pgsa_record(CLUSTER_SEMANTIC_PHASE_COMMIT, 8, 0x44, 0x55), desired)); + UT_ASSERT_EQ( + cluster_qvotec_test_semantic_activation_record_cas_write(NULL, 0, 7, 0x11, desired), + CLUSTER_SEMANTIC_ACTIVATION_BAD_STATE); } UT_TEST(test_pgsa_04c_rollback_complete_projects_target_as_current_source) @@ -2971,15 +2899,12 @@ UT_TEST(test_pgsa_04c_rollback_complete_projects_target_as_current_source) UT_ASSERT(false); return; } - UT_ASSERT(pgsa_encode(pgsa_record( - CLUSTER_SEMANTIC_PHASE_ROLLBACK_COMPLETE, 7, 0x11, 0x22), - current)); - UT_ASSERT(pgsa_encode(pgsa_record( - CLUSTER_SEMANTIC_PHASE_PREPARE, 8, 0x22, 0x422), desired)); + UT_ASSERT( + pgsa_encode(pgsa_record(CLUSTER_SEMANTIC_PHASE_ROLLBACK_COMPLETE, 7, 0x11, 0x22), current)); + UT_ASSERT(pgsa_encode(pgsa_record(CLUSTER_SEMANTIC_PHASE_PREPARE, 8, 0x22, 0x422), desired)); for (i = 0; i < PGSA_TEST_DISKS; i++) UT_ASSERT(pgsa_write_image(set.fds[i], current)); - UT_ASSERT_EQ(pgsa_cas(&set, 7, 0x22, desired), - CLUSTER_SEMANTIC_ACTIVATION_OK); + UT_ASSERT_EQ(pgsa_cas(&set, 7, 0x22, desired), CLUSTER_SEMANTIC_ACTIVATION_OK); UT_ASSERT_EQ(pgsa_count_image(&set, desired), PGSA_TEST_DISKS); pgsa_disk_set_close(&set); } @@ -2996,16 +2921,13 @@ UT_TEST(test_pgsa_04d_unknown_current_phase_holds_without_mutation) UT_ASSERT(false); return; } - UT_ASSERT(pgsa_encode(pgsa_record( - CLUSTER_SEMANTIC_PHASE_COMMIT, 7, 0x11, 0x22), current)); + UT_ASSERT(pgsa_encode(pgsa_record(CLUSTER_SEMANTIC_PHASE_COMMIT, 7, 0x11, 0x22), current)); current[16] = (uint8)(CLUSTER_SEMANTIC_PHASE_ROLLBACK_COMPLETE + 1); - UT_ASSERT(pgsa_encode(pgsa_record( - CLUSTER_SEMANTIC_PHASE_OPEN, 8, 0x11, 0x22), desired)); + UT_ASSERT(pgsa_encode(pgsa_record(CLUSTER_SEMANTIC_PHASE_OPEN, 8, 0x11, 0x22), desired)); for (i = 0; i < PGSA_TEST_DISKS; i++) UT_ASSERT(pgsa_write_image(set.fds[i], current)); UT_ASSERT(pgsa_snapshot(&set, before)); - UT_ASSERT_EQ(pgsa_cas(&set, 7, 0x11, desired), - CLUSTER_SEMANTIC_ACTIVATION_QUORUM_HOLD); + UT_ASSERT_EQ(pgsa_cas(&set, 7, 0x11, desired), CLUSTER_SEMANTIC_ACTIVATION_QUORUM_HOLD); UT_ASSERT(pgsa_snapshot_matches(&set, before)); pgsa_disk_set_close(&set); } @@ -3021,10 +2943,8 @@ UT_TEST(test_pgsa_05_lost_completion_replay_is_idempotent_ok) UT_ASSERT(false); return; } - UT_ASSERT(pgsa_encode(pgsa_record(CLUSTER_SEMANTIC_PHASE_PREPARE, 7, 0x11, 0x22), - current)); - UT_ASSERT(pgsa_encode(pgsa_record(CLUSTER_SEMANTIC_PHASE_COMMIT, 8, 0x11, 0x22), - desired)); + UT_ASSERT(pgsa_encode(pgsa_record(CLUSTER_SEMANTIC_PHASE_PREPARE, 7, 0x11, 0x22), current)); + UT_ASSERT(pgsa_encode(pgsa_record(CLUSTER_SEMANTIC_PHASE_COMMIT, 8, 0x11, 0x22), desired)); for (i = 0; i < PGSA_TEST_DISKS; i++) UT_ASSERT(pgsa_write_image(set.fds[i], current)); UT_ASSERT_EQ(pgsa_cas(&set, 7, 0x11, desired), CLUSTER_SEMANTIC_ACTIVATION_OK); @@ -3046,19 +2966,17 @@ UT_TEST(test_pgsa_06_split_or_no_disks_holds_without_mutation) return; } for (i = 0; i < PGSA_TEST_DISKS; i++) { - UT_ASSERT(pgsa_encode(pgsa_record(CLUSTER_SEMANTIC_PHASE_COMMIT, 7, 0x11, - 0x20 + (uint64)i), + UT_ASSERT(pgsa_encode(pgsa_record(CLUSTER_SEMANTIC_PHASE_COMMIT, 7, 0x11, 0x20 + (uint64)i), images[i])); UT_ASSERT(pgsa_write_image(set.fds[i], images[i])); } UT_ASSERT(pgsa_encode(pgsa_record(CLUSTER_SEMANTIC_PHASE_OPEN, 8, 0x11, 0x22), desired)); UT_ASSERT(pgsa_snapshot(&set, before)); - UT_ASSERT_EQ(pgsa_cas(&set, 7, 0x11, desired), - CLUSTER_SEMANTIC_ACTIVATION_QUORUM_HOLD); + UT_ASSERT_EQ(pgsa_cas(&set, 7, 0x11, desired), CLUSTER_SEMANTIC_ACTIVATION_QUORUM_HOLD); UT_ASSERT(pgsa_snapshot_matches(&set, before)); - UT_ASSERT_EQ(cluster_qvotec_test_semantic_activation_record_cas_write( - NULL, 0, 7, 0x11, desired), - CLUSTER_SEMANTIC_ACTIVATION_QUORUM_HOLD); + UT_ASSERT_EQ( + cluster_qvotec_test_semantic_activation_record_cas_write(NULL, 0, 7, 0x11, desired), + CLUSTER_SEMANTIC_ACTIVATION_QUORUM_HOLD); pgsa_disk_set_close(&set); } @@ -3073,10 +2991,8 @@ UT_TEST(test_pgsa_07_postwrite_one_of_three_desired_holds) UT_ASSERT(false); return; } - UT_ASSERT(pgsa_encode(pgsa_record(CLUSTER_SEMANTIC_PHASE_PREPARE, 7, 0x11, 0x22), - current)); - UT_ASSERT(pgsa_encode(pgsa_record(CLUSTER_SEMANTIC_PHASE_COMMIT, 8, 0x11, 0x22), - desired)); + UT_ASSERT(pgsa_encode(pgsa_record(CLUSTER_SEMANTIC_PHASE_PREPARE, 7, 0x11, 0x22), current)); + UT_ASSERT(pgsa_encode(pgsa_record(CLUSTER_SEMANTIC_PHASE_COMMIT, 8, 0x11, 0x22), desired)); for (i = 0; i < PGSA_TEST_DISKS; i++) UT_ASSERT(pgsa_write_image(set.fds[i], current)); for (i = 1; i < PGSA_TEST_DISKS; i++) { @@ -3084,8 +3000,7 @@ UT_TEST(test_pgsa_07_postwrite_one_of_three_desired_holds) set.fds[i] = open(set.paths[i], O_RDONLY); UT_ASSERT(set.fds[i] >= 0); } - UT_ASSERT_EQ(pgsa_cas(&set, 7, 0x11, desired), - CLUSTER_SEMANTIC_ACTIVATION_QUORUM_HOLD); + UT_ASSERT_EQ(pgsa_cas(&set, 7, 0x11, desired), CLUSTER_SEMANTIC_ACTIVATION_QUORUM_HOLD); UT_ASSERT_EQ(pgsa_count_image(&set, desired), 1); pgsa_disk_set_close(&set); } @@ -3123,13 +3038,11 @@ UT_TEST(test_pgsa_09_invalid_desired_and_overflow_are_bad_state_no_mutation) for (i = 0; i < PGSA_TEST_DISKS; i++) UT_ASSERT(pgsa_write_image(set.fds[i], current)); UT_ASSERT(pgsa_snapshot(&set, before)); - UT_ASSERT_EQ(pgsa_cas(&set, 7, 0x11, invalid), - CLUSTER_SEMANTIC_ACTIVATION_BAD_STATE); - UT_ASSERT_EQ(cluster_qvotec_test_semantic_activation_record_cas_write( - set.fds, PGSA_TEST_DISKS, 7, 0x11, NULL), - CLUSTER_SEMANTIC_ACTIVATION_BAD_STATE); - UT_ASSERT_EQ(pgsa_cas(&set, UINT64_MAX, 0x11, desired), + UT_ASSERT_EQ(pgsa_cas(&set, 7, 0x11, invalid), CLUSTER_SEMANTIC_ACTIVATION_BAD_STATE); + UT_ASSERT_EQ(cluster_qvotec_test_semantic_activation_record_cas_write(set.fds, PGSA_TEST_DISKS, + 7, 0x11, NULL), CLUSTER_SEMANTIC_ACTIVATION_BAD_STATE); + UT_ASSERT_EQ(pgsa_cas(&set, UINT64_MAX, 0x11, desired), CLUSTER_SEMANTIC_ACTIVATION_BAD_STATE); UT_ASSERT(pgsa_snapshot_matches(&set, before)); pgsa_disk_set_close(&set); } @@ -3148,32 +3061,30 @@ UT_TEST(test_pgsa_10_read_selects_exact_majority_and_reports_conflict) return; } memset(selected, 0xa5, sizeof(selected)); - UT_ASSERT_EQ(cluster_qvotec_test_semantic_activation_record_read( - set.fds, PGSA_TEST_DISKS, selected, &implicit_open), + UT_ASSERT_EQ(cluster_qvotec_test_semantic_activation_record_read(set.fds, PGSA_TEST_DISKS, + selected, &implicit_open), CLUSTER_SEMANTIC_ACTIVATION_OK); UT_ASSERT(implicit_open); for (i = 0; i < CLUSTER_SEMANTIC_ACTIVATION_RECORD_BYTES; i++) UT_ASSERT_EQ(selected[i], 0); - UT_ASSERT(pgsa_encode( - pgsa_record(CLUSTER_SEMANTIC_PHASE_OPEN, 7, 0x11, 0x11), first)); + UT_ASSERT(pgsa_encode(pgsa_record(CLUSTER_SEMANTIC_PHASE_OPEN, 7, 0x11, 0x11), first)); UT_ASSERT(pgsa_write_image(set.fds[0], first)); UT_ASSERT(pgsa_write_image(set.fds[1], first)); memset(selected, 0, sizeof(selected)); implicit_open = true; - UT_ASSERT_EQ(cluster_qvotec_test_semantic_activation_record_read( - set.fds, PGSA_TEST_DISKS, selected, &implicit_open), + UT_ASSERT_EQ(cluster_qvotec_test_semantic_activation_record_read(set.fds, PGSA_TEST_DISKS, + selected, &implicit_open), CLUSTER_SEMANTIC_ACTIVATION_OK); UT_ASSERT(!implicit_open); UT_ASSERT_EQ(memcmp(selected, first, sizeof(first)), 0); - UT_ASSERT(pgsa_encode( - pgsa_record(CLUSTER_SEMANTIC_PHASE_OPEN, 7, 0x22, 0x22), second)); + UT_ASSERT(pgsa_encode(pgsa_record(CLUSTER_SEMANTIC_PHASE_OPEN, 7, 0x22, 0x22), second)); UT_ASSERT(pgsa_write_image(set.fds[1], second)); memset(selected, 0xa5, sizeof(selected)); implicit_open = true; - UT_ASSERT_EQ(cluster_qvotec_test_semantic_activation_record_read( - set.fds, PGSA_TEST_DISKS, selected, &implicit_open), + UT_ASSERT_EQ(cluster_qvotec_test_semantic_activation_record_read(set.fds, PGSA_TEST_DISKS, + selected, &implicit_open), CLUSTER_SEMANTIC_ACTIVATION_RECORD_CONFLICT); UT_ASSERT(!implicit_open); for (i = 0; i < CLUSTER_SEMANTIC_ACTIVATION_RECORD_BYTES; i++) @@ -3192,8 +3103,7 @@ UT_TEST(test_jcmk_v3_write_tally_cannot_ack_without_exact_readback) staged[2] = 'C'; staged[3] = 'J'; staged[4] = CLUSTER_JCMK_REPLACEMENT_VERSION; - UT_ASSERT(!cluster_qvotec_test_join_marker_ack_proven( - unreadable_fds, 3, 1, staged, 3)); + UT_ASSERT(!cluster_qvotec_test_join_marker_ack_proven(unreadable_fds, 3, 1, staged, 3)); } UT_TEST(test_jcmk_v3_exact_readback_majority_acks) @@ -3209,11 +3119,10 @@ UT_TEST(test_jcmk_v3_exact_readback_majority_acks) for (i = 0; i < CLUSTER_VOTING_SLOT_BYTES; i++) staged[i] = (uint8)(i ^ 0x5a); for (i = 0; i < PGSA_TEST_DISKS; i++) - UT_ASSERT_EQ(cluster_voting_disk_write_join_slot( - set.fds[i], 1, staged), + UT_ASSERT_EQ(cluster_voting_disk_write_join_slot(set.fds[i], 1, staged), CLUSTER_VOTING_DISK_IO_OK); - UT_ASSERT(cluster_qvotec_test_join_marker_ack_proven( - set.fds, PGSA_TEST_DISKS, 1, staged, PGSA_TEST_DISKS)); + UT_ASSERT(cluster_qvotec_test_join_marker_ack_proven(set.fds, PGSA_TEST_DISKS, 1, staged, + PGSA_TEST_DISKS)); pgsa_disk_set_close(&set); } @@ -3235,11 +3144,10 @@ UT_TEST(test_jcmk_v3_split_readback_cannot_form_false_majority) UT_ASSERT_EQ(cluster_voting_disk_write_join_slot(set.fds[0], 1, staged), CLUSTER_VOTING_DISK_IO_OK); for (i = 1; i < PGSA_TEST_DISKS; i++) - UT_ASSERT_EQ(cluster_voting_disk_write_join_slot( - set.fds[i], 1, other), + UT_ASSERT_EQ(cluster_voting_disk_write_join_slot(set.fds[i], 1, other), CLUSTER_VOTING_DISK_IO_OK); - UT_ASSERT(!cluster_qvotec_test_join_marker_ack_proven( - set.fds, PGSA_TEST_DISKS, 1, staged, PGSA_TEST_DISKS)); + UT_ASSERT(!cluster_qvotec_test_join_marker_ack_proven(set.fds, PGSA_TEST_DISKS, 1, staged, + PGSA_TEST_DISKS)); pgsa_disk_set_close(&set); } @@ -3284,13 +3192,12 @@ UT_TEST(test_jcmk_v3_verify_reads_configured_majority_without_writes) memcpy(slot, image, sizeof(image)); memcpy(other_slot, other_image, sizeof(other_image)); for (i = 0; i < PGSA_TEST_DISKS; i++) - UT_ASSERT_EQ(cluster_voting_disk_write_join_slot( - set.fds[i], (uint32)marker.target_node_id, - i < 2 ? slot : other_slot), + UT_ASSERT_EQ(cluster_voting_disk_write_join_slot(set.fds[i], (uint32)marker.target_node_id, + i < 2 ? slot : other_slot), CLUSTER_VOTING_DISK_IO_OK); for (i = 0; i < PGSA_TEST_DISKS; i++) - UT_ASSERT_EQ(cluster_voting_disk_read_join_slot( - set.fds[i], (uint32)marker.target_node_id, before[i]), + UT_ASSERT_EQ(cluster_voting_disk_read_join_slot(set.fds[i], (uint32)marker.target_node_id, + before[i]), CLUSTER_VOTING_DISK_IO_OK); memset(verified, 0xa5, sizeof(verified)); @@ -3298,9 +3205,9 @@ UT_TEST(test_jcmk_v3_verify_reads_configured_majority_without_writes) set.fds, PGSA_TEST_DISKS, marker.target_node_id, verified)); UT_ASSERT_EQ(memcmp(verified, image, sizeof(image)), 0); for (i = 0; i < PGSA_TEST_DISKS; i++) { - UT_ASSERT_EQ(cluster_voting_disk_read_join_slot( - set.fds[i], (uint32)marker.target_node_id, after[i]), - CLUSTER_VOTING_DISK_IO_OK); + UT_ASSERT_EQ( + cluster_voting_disk_read_join_slot(set.fds[i], (uint32)marker.target_node_id, after[i]), + CLUSTER_VOTING_DISK_IO_OK); UT_ASSERT_EQ(memcmp(before[i], after[i], sizeof(before[i])), 0); } @@ -3322,9 +3229,9 @@ UT_TEST(test_jcmk_v3_verify_reads_configured_majority_without_writes) memset(slot, 0, sizeof(slot)); memcpy(slot, image, sizeof(image)); for (i = 0; i < 2; i++) - UT_ASSERT_EQ(cluster_voting_disk_write_join_slot( - set.fds[i], (uint32)marker.target_node_id, slot), - CLUSTER_VOTING_DISK_IO_OK); + UT_ASSERT_EQ( + cluster_voting_disk_write_join_slot(set.fds[i], (uint32)marker.target_node_id, slot), + CLUSTER_VOTING_DISK_IO_OK); memset(verified, 0xa5, sizeof(verified)); UT_ASSERT(!cluster_qvotec_test_join_marker_verify_committed_closed( set.fds, PGSA_TEST_DISKS, marker.target_node_id, verified)); @@ -3376,8 +3283,7 @@ UT_TEST(test_epoch_ballot_recover_head_requires_exact_settled_majority) lane.last_write_phase = CLUSTER_EPOCH_BALLOT_PHASE_SETTLED; lane.proposer_node_id = 1; lane.configured_disk_count = PGSA_TEST_DISKS; - lane.proposer_admitted_incarnation - = ballot.proposer_admitted_incarnation; + lane.proposer_admitted_incarnation = ballot.proposer_admitted_incarnation; lane.lane_generation = UINT64_C(5); lane.system_identifier = sysid; lane.grammar_fingerprint = CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT; @@ -3387,32 +3293,28 @@ UT_TEST(test_epoch_ballot_recover_head_requires_exact_settled_majority) lane.settled_ballot = ballot; lane.settled_value = value; UT_ASSERT(cluster_epoch_ballot_lane_encode( - &lane, 1, PGSA_TEST_DISKS, ballot.proposer_admitted_incarnation, - sysid, CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT, lane_image)); + &lane, 1, PGSA_TEST_DISKS, ballot.proposer_admitted_incarnation, sysid, + CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT, lane_image)); admitted[1] = ballot.proposer_admitted_incarnation; - UT_ASSERT_EQ(cluster_voting_disk_write_epoch_ballot_slot( - set.fds[0], 1, lane_image), + UT_ASSERT_EQ(cluster_voting_disk_write_epoch_ballot_slot(set.fds[0], 1, lane_image), CLUSTER_VOTING_DISK_IO_OK); - UT_ASSERT_EQ((int)cluster_qvotec_test_epoch_ballot_recover_head( - set.fds, PGSA_TEST_DISKS, sysid, admitted, value_image, - ballot_image, &observed), + UT_ASSERT_EQ((int)cluster_qvotec_test_epoch_ballot_recover_head(set.fds, PGSA_TEST_DISKS, sysid, + admitted, value_image, + ballot_image, &observed), (int)CLUSTER_QVOTEC_MAILBOX_HOLD); UT_ASSERT_EQ((int)observed, 0); - UT_ASSERT_EQ(cluster_voting_disk_write_epoch_ballot_slot( - set.fds[1], 1, lane_image), + UT_ASSERT_EQ(cluster_voting_disk_write_epoch_ballot_slot(set.fds[1], 1, lane_image), CLUSTER_VOTING_DISK_IO_OK); - UT_ASSERT_EQ((int)cluster_qvotec_test_epoch_ballot_recover_head( - set.fds, PGSA_TEST_DISKS, sysid, admitted, value_image, - ballot_image, &observed), + UT_ASSERT_EQ((int)cluster_qvotec_test_epoch_ballot_recover_head(set.fds, PGSA_TEST_DISKS, sysid, + admitted, value_image, + ballot_image, &observed), (int)CLUSTER_QVOTEC_MAILBOX_CHOSEN); UT_ASSERT_EQ((int)observed, (int)UINT8_C(0x03)); UT_ASSERT(cluster_epoch_authority_value_decode( - value_image, CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT, - &recovered_value)); - UT_ASSERT(cluster_epoch_ballot_id_decode( - ballot_image, &recovered_ballot)); + value_image, CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT, &recovered_value)); + UT_ASSERT(cluster_epoch_ballot_id_decode(ballot_image, &recovered_ballot)); UT_ASSERT_EQ(memcmp(&recovered_value, &value, sizeof(value)), 0); UT_ASSERT_EQ(memcmp(&recovered_ballot, &ballot, sizeof(ballot)), 0); pgsa_disk_set_close(&set); @@ -3469,12 +3371,11 @@ UT_TEST(test_epoch_ballot_phase1_preserves_history_and_observed_promise_floor) lane.settled_ballot = settled_ballot; lane.settled_value = value; UT_ASSERT(cluster_epoch_ballot_lane_encode( - &lane, 1, PGSA_TEST_DISKS, settled_ballot.proposer_admitted_incarnation, - sysid, CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT, lane_image)); + &lane, 1, PGSA_TEST_DISKS, settled_ballot.proposer_admitted_incarnation, sysid, + CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT, lane_image)); for (i = 0; i < 2; i++) - UT_ASSERT_EQ(cluster_voting_disk_write_epoch_ballot_slot( - set.fds[i], 1, lane_image), - CLUSTER_VOTING_DISK_IO_OK); + UT_ASSERT_EQ(cluster_voting_disk_write_epoch_ballot_slot(set.fds[i], 1, lane_image), + CLUSTER_VOTING_DISK_IO_OK); admitted[1] = settled_ballot.proposer_admitted_incarnation; admitted[2] = UINT64_C(222); @@ -3482,27 +3383,21 @@ UT_TEST(test_epoch_ballot_phase1_preserves_history_and_observed_promise_floor) promised_ballot.counter = UINT64_C(8); promised_ballot.nonce = UINT64_C(0x6162636465666768); UT_ASSERT(cluster_qvotec_test_epoch_ballot_phase1_promise( - set.fds, PGSA_TEST_DISKS, sysid, admitted, 1, - &promised_ballot, &observed)); + set.fds, PGSA_TEST_DISKS, sysid, admitted, 1, &promised_ballot, &observed)); UT_ASSERT_EQ((int)observed, (int)UINT8_C(0x07)); for (i = 0; i < PGSA_TEST_DISKS; i++) { - UT_ASSERT_EQ(cluster_voting_disk_read_epoch_ballot_slot( - set.fds[i], 1, lane_image), - CLUSTER_VOTING_DISK_IO_OK); + UT_ASSERT_EQ(cluster_voting_disk_read_epoch_ballot_slot(set.fds[i], 1, lane_image), + CLUSTER_VOTING_DISK_IO_OK); UT_ASSERT(cluster_epoch_ballot_lane_decode( - lane_image, 1, PGSA_TEST_DISKS, - settled_ballot.proposer_admitted_incarnation, sysid, + lane_image, 1, PGSA_TEST_DISKS, settled_ballot.proposer_admitted_incarnation, sysid, CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT, &decoded)); - UT_ASSERT_EQ((int)decoded.last_write_phase, - (int)CLUSTER_EPOCH_BALLOT_PHASE_PROMISED); + UT_ASSERT_EQ((int)decoded.last_write_phase, (int)CLUSTER_EPOCH_BALLOT_PHASE_PROMISED); UT_ASSERT_EQ(decoded.lane_generation, UINT64_C(6)); - UT_ASSERT_EQ(memcmp(&decoded.promised_ballot, &promised_ballot, - sizeof(promised_ballot)), 0); - UT_ASSERT_EQ(memcmp(&decoded.accepted_ballot, &settled_ballot, - sizeof(settled_ballot)), 0); + UT_ASSERT_EQ(memcmp(&decoded.promised_ballot, &promised_ballot, sizeof(promised_ballot)), + 0); + UT_ASSERT_EQ(memcmp(&decoded.accepted_ballot, &settled_ballot, sizeof(settled_ballot)), 0); UT_ASSERT_EQ(memcmp(&decoded.accepted_value, &value, sizeof(value)), 0); - UT_ASSERT_EQ(memcmp(&decoded.settled_ballot, &settled_ballot, - sizeof(settled_ballot)), 0); + UT_ASSERT_EQ(memcmp(&decoded.settled_ballot, &settled_ballot, sizeof(settled_ballot)), 0); UT_ASSERT_EQ(memcmp(&decoded.settled_value, &value, sizeof(value)), 0); } @@ -3522,31 +3417,27 @@ UT_TEST(test_epoch_ballot_phase1_preserves_history_and_observed_promise_floor) lane.system_identifier = sysid; lane.grammar_fingerprint = CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT; lane.promised_ballot = higher_peer_ballot; - UT_ASSERT(cluster_epoch_ballot_lane_encode( - &lane, 2, PGSA_TEST_DISKS, admitted[2], sysid, - CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT, lane_image)); - UT_ASSERT_EQ(cluster_voting_disk_write_epoch_ballot_slot( - set.fds[0], 2, lane_image), - CLUSTER_VOTING_DISK_IO_OK); + UT_ASSERT(cluster_epoch_ballot_lane_encode(&lane, 2, PGSA_TEST_DISKS, admitted[2], sysid, + CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT, + lane_image)); + UT_ASSERT_EQ(cluster_voting_disk_write_epoch_ballot_slot(set.fds[0], 2, lane_image), + CLUSTER_VOTING_DISK_IO_OK); stale_attempt = promised_ballot; stale_attempt.counter = UINT64_C(9); stale_attempt.nonce = UINT64_C(0x8182838485868788); observed = UINT8_C(0xff); UT_ASSERT(!cluster_qvotec_test_epoch_ballot_phase1_promise( - set.fds, PGSA_TEST_DISKS, sysid, admitted, 1, - &stale_attempt, &observed)); + set.fds, PGSA_TEST_DISKS, sysid, admitted, 1, &stale_attempt, &observed)); UT_ASSERT_EQ((int)observed, 0); for (i = 0; i < PGSA_TEST_DISKS; i++) { - UT_ASSERT_EQ(cluster_voting_disk_read_epoch_ballot_slot( - set.fds[i], 1, lane_image), - CLUSTER_VOTING_DISK_IO_OK); + UT_ASSERT_EQ(cluster_voting_disk_read_epoch_ballot_slot(set.fds[i], 1, lane_image), + CLUSTER_VOTING_DISK_IO_OK); UT_ASSERT(cluster_epoch_ballot_lane_decode( - lane_image, 1, PGSA_TEST_DISKS, - settled_ballot.proposer_admitted_incarnation, sysid, + lane_image, 1, PGSA_TEST_DISKS, settled_ballot.proposer_admitted_incarnation, sysid, CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT, &decoded)); UT_ASSERT_EQ(decoded.lane_generation, UINT64_C(6)); - UT_ASSERT_EQ(memcmp(&decoded.promised_ballot, &promised_ballot, - sizeof(promised_ballot)), 0); + UT_ASSERT_EQ(memcmp(&decoded.promised_ballot, &promised_ballot, sizeof(promised_ballot)), + 0); } pgsa_disk_set_close(&set); } @@ -3559,8 +3450,7 @@ UT_TEST(test_epoch_ballot_formation_rejects_fixture_disks) UT_ASSERT(false); return; } - UT_ASSERT(!cluster_qvotec_test_epoch_ballot_formation_attested( - set.fds, PGSA_TEST_DISKS)); + UT_ASSERT(!cluster_qvotec_test_epoch_ballot_formation_attested(set.fds, PGSA_TEST_DISKS)); UT_ASSERT(!cluster_qvotec_test_epoch_ballot_formation_attested(NULL, 0)); UT_ASSERT(!cluster_qvotec_test_epoch_ballot_formation_attested(set.fds, 2)); pgsa_disk_set_close(&set); @@ -3576,25 +3466,20 @@ UT_TEST(test_pgrd_formation_accepts_only_bounded_nonlinux_development_disks) return; } for (i = 0; i < PGSA_TEST_DISKS; i++) - UT_ASSERT_EQ(ftruncate( - set.fds[i], CLUSTER_UNDO_ROOT_DESCRIPTOR_FILE_BYTES_MIN), 0); + UT_ASSERT_EQ(ftruncate(set.fds[i], CLUSTER_UNDO_ROOT_DESCRIPTOR_FILE_BYTES_MIN), 0); #ifndef __linux__ - UT_ASSERT(cluster_qvotec_test_undo_root_descriptor_formation_attested( - set.fds, PGSA_TEST_DISKS)); + UT_ASSERT( + cluster_qvotec_test_undo_root_descriptor_formation_attested(set.fds, PGSA_TEST_DISKS)); #else - UT_ASSERT(!cluster_qvotec_test_undo_root_descriptor_formation_attested( - set.fds, PGSA_TEST_DISKS)); + UT_ASSERT( + !cluster_qvotec_test_undo_root_descriptor_formation_attested(set.fds, PGSA_TEST_DISKS)); #endif - UT_ASSERT_EQ(ftruncate( - set.fds[2], CLUSTER_UNDO_ROOT_DESCRIPTOR_FILE_BYTES_MIN - 1), 0); - UT_ASSERT(!cluster_qvotec_test_undo_root_descriptor_formation_attested( - set.fds, PGSA_TEST_DISKS)); - UT_ASSERT_EQ(ftruncate( - set.fds[2], CLUSTER_UNDO_ROOT_DESCRIPTOR_FILE_BYTES_MIN), 0); - UT_ASSERT(!cluster_qvotec_test_undo_root_descriptor_formation_attested( - NULL, 0)); - UT_ASSERT(!cluster_qvotec_test_undo_root_descriptor_formation_attested( - set.fds, 2)); + UT_ASSERT_EQ(ftruncate(set.fds[2], CLUSTER_UNDO_ROOT_DESCRIPTOR_FILE_BYTES_MIN - 1), 0); + UT_ASSERT( + !cluster_qvotec_test_undo_root_descriptor_formation_attested(set.fds, PGSA_TEST_DISKS)); + UT_ASSERT_EQ(ftruncate(set.fds[2], CLUSTER_UNDO_ROOT_DESCRIPTOR_FILE_BYTES_MIN), 0); + UT_ASSERT(!cluster_qvotec_test_undo_root_descriptor_formation_attested(NULL, 0)); + UT_ASSERT(!cluster_qvotec_test_undo_root_descriptor_formation_attested(set.fds, 2)); pgsa_disk_set_close(&set); } @@ -3685,8 +3570,7 @@ UT_TEST(test_pgsa_source_graph_and_test_linkage_are_exact) UT_ASSERT_NOT_NULL(strstr(qvotec, "CLUSTER_QVOTEC_PGSA_UNIT_TEST")); UT_ASSERT_NOT_NULL( strstr(qvotec, "cluster_qvotec_test_semantic_activation_record_cas_write")); - UT_ASSERT_NOT_NULL( - strstr(qvotec, "cluster_semantic_activation_qvotec_poll_record_cas")); + UT_ASSERT_NOT_NULL(strstr(qvotec, "cluster_semantic_activation_qvotec_poll_record_cas")); UT_ASSERT_NOT_NULL( strstr(qvotec, "cluster_semantic_activation_qvotec_complete_record_cas")); UT_ASSERT_NULL(strstr(qvotec, "cluster_qvotec_set_semantic_activation_fds")); @@ -3708,9 +3592,8 @@ UT_TEST(test_pgsa_source_graph_and_test_linkage_are_exact) UT_ASSERT_NOT_NULL(strstr(semantic, "pg_write_barrier();")); UT_ASSERT_NOT_NULL(strstr(semantic, "pg_read_barrier();")); submit = strstr(semantic, "cluster_semantic_activation_submit("); - submit_end = submit == NULL - ? NULL - : strstr(submit, "cluster_semantic_activation_r4_descriptor("); + submit_end + = submit == NULL ? NULL : strstr(submit, "cluster_semantic_activation_r4_descriptor("); UT_ASSERT_NOT_NULL(submit); UT_ASSERT_NOT_NULL(submit_end); if (submit != NULL && submit_end != NULL) { diff --git a/src/test/cluster_unit/test_cluster_r4_activation_fsm.c b/src/test/cluster_unit/test_cluster_r4_activation_fsm.c index 6181bc2e8c9..742591c22b2 100644 --- a/src/test/cluster_unit/test_cluster_r4_activation_fsm.c +++ b/src/test/cluster_unit/test_cluster_r4_activation_fsm.c @@ -30,9 +30,8 @@ #include "cluster/storage/cluster_undo_block0_current.h" extern bool cluster_semantic_activation_resolve_shared_undo_root_live_owner_source( - const ClusterSemanticAdmissionToken *token, ClusterUndoPathIntent intent, - uint32 owner_instance, uint32 segment_id, - ClusterUndoBlock0ResolvedRoot *out); + const ClusterSemanticAdmissionToken *token, ClusterUndoPathIntent intent, uint32 owner_instance, + uint32 segment_id, ClusterUndoBlock0ResolvedRoot *out); #include "port/atomics.h" #include "storage/ipc.h" #include "storage/shmem.h" @@ -150,16 +149,12 @@ static ClusterICSendResult test_send_results[CLUSTER_MAX_NODES]; static int test_send_calls[CLUSTER_MAX_NODES]; static uint8 test_send_msg_types[CLUSTER_MAX_NODES]; static uint32 test_send_payload_lengths[CLUSTER_MAX_NODES]; -static uint8 test_send_payloads[CLUSTER_MAX_NODES] - [CLUSTER_SEMANTIC_ACTIVATION_ACK_WIRE_BYTES]; +static uint8 test_send_payloads[CLUSTER_MAX_NODES][CLUSTER_SEMANTIC_ACTIVATION_ACK_WIRE_BYTES]; #define TEST_SEND_HISTORY_CAPACITY 16 -static uint8 test_send_history_msg_types[CLUSTER_MAX_NODES] - [TEST_SEND_HISTORY_CAPACITY]; -static uint32 test_send_history_payload_lengths[CLUSTER_MAX_NODES] - [TEST_SEND_HISTORY_CAPACITY]; -static uint8 test_send_history_payloads[CLUSTER_MAX_NODES] - [TEST_SEND_HISTORY_CAPACITY] - [CLUSTER_SEMANTIC_ACTIVATION_ACK_WIRE_BYTES]; +static uint8 test_send_history_msg_types[CLUSTER_MAX_NODES][TEST_SEND_HISTORY_CAPACITY]; +static uint32 test_send_history_payload_lengths[CLUSTER_MAX_NODES][TEST_SEND_HISTORY_CAPACITY]; +static uint8 test_send_history_payloads[CLUSTER_MAX_NODES][TEST_SEND_HISTORY_CAPACITY] + [CLUSTER_SEMANTIC_ACTIVATION_ACK_WIRE_BYTES]; static int test_close_calls[CLUSTER_MAX_NODES]; static int test_phase3_observe_calls; static ClusterReplacementPhase3HandoffItem test_phase3_observed_item; @@ -239,12 +234,12 @@ volatile uint32 InterruptHoldoffCount = 0; volatile uint32 QueryCancelHoldoffCount = 0; volatile uint32 CritSectionCount = 0; -static bool semantic_activation_utility_mailbox_complete( - uint64 request_seq, ClusterSemanticActivationResult result, - uint64 feature_bit, uint64 expected_generation); -ClusterICSendResult cluster_ic_send_envelope( - uint8 msg_type, int32 dest_node_id, const void *payload, - uint32 payload_len); +static bool semantic_activation_utility_mailbox_complete(uint64 request_seq, + ClusterSemanticActivationResult result, + uint64 feature_bit, + uint64 expected_generation); +ClusterICSendResult cluster_ic_send_envelope(uint8 msg_type, int32 dest_node_id, + const void *payload, uint32 payload_len); void cluster_ic_tier1_close_peer(int32 peer_id, const char *reason); bool @@ -260,8 +255,7 @@ cluster_pcm_lock_resource_x_gate_snapshot(ResourceXGateSnapshot *snapshot_out) } bool -cluster_pcm_lock_resource_x_cutover_gate_snapshot_exact( - ResourceXGateSnapshot *snapshot_out) +cluster_pcm_lock_resource_x_cutover_gate_snapshot_exact(ResourceXGateSnapshot *snapshot_out) { if (!cluster_pcm_lock_resource_x_gate_snapshot(snapshot_out) || snapshot_out->phase != RESOURCE_X_GATE_OPEN) { @@ -273,15 +267,15 @@ cluster_pcm_lock_resource_x_cutover_gate_snapshot_exact( } bool -cluster_pcm_lock_resource_x_cutover_current_proof_digest_exact( - bool thawed, ResourceXReconfigToken *token_out, uint64 *digest_out) +cluster_pcm_lock_resource_x_cutover_current_proof_digest_exact(bool thawed, + ResourceXReconfigToken *token_out, + uint64 *digest_out) { if (token_out == NULL || digest_out == NULL) return false; memset(token_out, 0, sizeof(*token_out)); *digest_out = 0; - if (!test_resource_x_cutover_digest_valid - || thawed != test_resource_x_cutover_thawed + if (!test_resource_x_cutover_digest_valid || thawed != test_resource_x_cutover_thawed || test_resource_x_cutover_digest == 0) return false; *token_out = test_resource_x_cutover_token; @@ -364,8 +358,7 @@ cluster_ctrc_shmem_ready(void) /* RF-ROOT P7 (contract, step ②): the root activation stub — this binary * does not link cluster_control_root.o. The advance's executor path is * exercised via ut_activate_result (OK advances; non-OK stays PREPARED). */ -static ClusterControlRootResult ut_activate_result - = CLUSTER_CONTROL_ROOT_OK_PRIMARY; +static ClusterControlRootResult ut_activate_result = CLUSTER_CONTROL_ROOT_OK_PRIMARY; static int ut_activate_calls = 0; ClusterControlRootResult @@ -383,14 +376,13 @@ cluster_control_root_activate_prepared( /* RF-ROOT P9 verification: bootstrap_validate_active_round stub — the * member-side COMMIT_APPLIED verification of the ACTIVE root. */ -static ClusterControlRootResult ut_bootstrap_validate_result - = CLUSTER_CONTROL_ROOT_OK_PRIMARY; +static ClusterControlRootResult ut_bootstrap_validate_result = CLUSTER_CONTROL_ROOT_OK_PRIMARY; static int ut_bootstrap_validate_calls = 0; ClusterControlRootResult -cluster_control_root_bootstrap_validate_active_round( - const ClusterControlRootMigrationRoundV1 *round pg_attribute_unused(), - ClusterControlRootFileToken *token) +cluster_control_root_bootstrap_validate_active_round(const ClusterControlRootMigrationRoundV1 *round + pg_attribute_unused(), + ClusterControlRootFileToken *token) { ut_bootstrap_validate_calls++; if (token != NULL) @@ -400,8 +392,7 @@ cluster_control_root_bootstrap_validate_active_round( /* RF-ROOT P7 (contract step ④c): create_prepared / round_sha256 stubs — this * binary does not link cluster_control_root.o. */ -static ClusterControlRootResult ut_create_result - = CLUSTER_CONTROL_ROOT_OK_PRIMARY; +static ClusterControlRootResult ut_create_result = CLUSTER_CONTROL_ROOT_OK_PRIMARY; static int ut_create_calls = 0; ClusterControlRootResult @@ -428,9 +419,9 @@ superuser(void) } ClusterControlRootResult -cluster_control_root_build_migration_image( - const ClusterControlRootMigrationRoundV1 *round pg_attribute_unused(), - ClusterControlRootMigrationImage *out) +cluster_control_root_build_migration_image(const ClusterControlRootMigrationRoundV1 *round + pg_attribute_unused(), + ClusterControlRootMigrationImage *out) { if (out != NULL) memset(out, 0, sizeof(*out)); @@ -438,9 +429,9 @@ cluster_control_root_build_migration_image( } bool -cluster_control_root_round_sha256( - const ClusterControlRootMigrationRoundV1 *round pg_attribute_unused(), - uint8 out_sha[PG_SHA256_DIGEST_LENGTH]) +cluster_control_root_round_sha256(const ClusterControlRootMigrationRoundV1 *round + pg_attribute_unused(), + uint8 out_sha[PG_SHA256_DIGEST_LENGTH]) { if (out_sha != NULL) memset(out_sha, 0x11, PG_SHA256_DIGEST_LENGTH); @@ -453,13 +444,11 @@ cluster_control_root_round_sha256( * does not link cluster_control_root.o. Configurable stub — the OPEN_PROOF * reconstruction tests drive both the GREEN binding and the RED identity * refusal. */ -static ClusterControlRootResult test_r4fsm_root_validate_result - = CLUSTER_CONTROL_ROOT_OK_PRIMARY; +static ClusterControlRootResult test_r4fsm_root_validate_result = CLUSTER_CONTROL_ROOT_OK_PRIMARY; ClusterControlRootResult cluster_control_root_bootstrap_validate_active_round_fields( - uint64 transition_epoch pg_attribute_unused(), - uint64 prepare_generation pg_attribute_unused(), + uint64 transition_epoch pg_attribute_unused(), uint64 prepare_generation pg_attribute_unused(), uint64 source_feature_bitmap pg_attribute_unused(), uint64 target_feature_bitmap pg_attribute_unused()) { @@ -535,9 +524,8 @@ cluster_membership_get_last_admitted_incarnation(int32 node_id) { if (node_id == cluster_node_id) return test_last_admitted_incarnation; - return node_id >= 0 && node_id < CLUSTER_MAX_NODES - ? test_remote_admitted_incarnations[node_id] - : 0; + return node_id >= 0 && node_id < CLUSTER_MAX_NODES ? test_remote_admitted_incarnations[node_id] + : 0; } void * @@ -586,15 +574,13 @@ test_pg_usleep(long microsec pg_attribute_unused()) test_wait_sleep_calls++; if (test_complete_after_wait_sleeps > 0 && test_wait_sleep_calls == test_complete_after_wait_sleeps) - test_wait_completion_succeeded - = semantic_activation_utility_mailbox_complete( - test_wait_completion_request_seq, - CLUSTER_SEMANTIC_ACTIVATION_OK, 0, 0); + test_wait_completion_succeeded = semantic_activation_utility_mailbox_complete( + test_wait_completion_request_seq, CLUSTER_SEMANTIC_ACTIVATION_OK, 0, 0); } bool cluster_sf_peer_capability_generation_matches(int32 peer_id, uint32 required_capabilities, - uint32 expected_generation) + uint32 expected_generation) { test_peer_capability_match_calls++; test_peer_capability_match_peer = peer_id; @@ -661,22 +647,19 @@ cluster_ic_local_capability_word(void) } ClusterICSendResult -cluster_ic_send_envelope(uint8 msg_type, int32 dest_node_id, - const void *payload, uint32 payload_len) +cluster_ic_send_envelope(uint8 msg_type, int32 dest_node_id, const void *payload, + uint32 payload_len) { int history_index; - if (dest_node_id < 0 || dest_node_id >= CLUSTER_MAX_NODES - || payload == NULL + if (dest_node_id < 0 || dest_node_id >= CLUSTER_MAX_NODES || payload == NULL || payload_len != CLUSTER_SEMANTIC_ACTIVATION_ACK_WIRE_BYTES) return CLUSTER_IC_SEND_HARD_ERROR; history_index = test_send_calls[dest_node_id]; if (history_index < TEST_SEND_HISTORY_CAPACITY) { test_send_history_msg_types[dest_node_id][history_index] = msg_type; - test_send_history_payload_lengths[dest_node_id][history_index] - = payload_len; - memcpy(test_send_history_payloads[dest_node_id][history_index], - payload, payload_len); + test_send_history_payload_lengths[dest_node_id][history_index] = payload_len; + memcpy(test_send_history_payloads[dest_node_id][history_index], payload, payload_len); } test_send_calls[dest_node_id]++; test_send_msg_types[dest_node_id] = msg_type; @@ -686,8 +669,7 @@ cluster_ic_send_envelope(uint8 msg_type, int32 dest_node_id, } void -cluster_ic_tier1_close_peer(int32 peer_id, - const char *reason pg_attribute_unused()) +cluster_ic_tier1_close_peer(int32 peer_id, const char *reason pg_attribute_unused()) { if (peer_id >= 0 && peer_id < CLUSTER_MAX_NODES) test_close_calls[peer_id]++; @@ -708,21 +690,17 @@ cluster_membership_is_member(int32 node_id) ClusterMembershipState cluster_membership_get_state(int32 node_id) { - return cluster_membership_is_member(node_id) - ? CLUSTER_MEMBER_MEMBER - : CLUSTER_MEMBER_REMOVED; + return cluster_membership_is_member(node_id) ? CLUSTER_MEMBER_MEMBER : CLUSTER_MEMBER_REMOVED; } bool -cluster_reconfig_get_observed_slot(int32 node_id, uint64 *incarnation, - uint64 *generation) +cluster_reconfig_get_observed_slot(int32 node_id, uint64 *incarnation, uint64 *generation) { if (incarnation != NULL) *incarnation = 0; if (generation != NULL) *generation = 0; - if (node_id < 0 || node_id >= CLUSTER_MAX_NODES - || incarnation == NULL || generation == NULL + if (node_id < 0 || node_id >= CLUSTER_MAX_NODES || incarnation == NULL || generation == NULL || !test_observed_slot_valid[node_id]) return false; *incarnation = test_observed_slot_incarnation[node_id]; @@ -733,9 +711,7 @@ cluster_reconfig_get_observed_slot(int32 node_id, uint64 *incarnation, uint64 cluster_reconfig_get_observed_epoch(int32 node_id) { - return node_id >= 0 && node_id < CLUSTER_MAX_NODES - ? test_observed_slot_epoch[node_id] - : 0; + return node_id >= 0 && node_id < CLUSTER_MAX_NODES ? test_observed_slot_epoch[node_id] : 0; } int @@ -775,8 +751,7 @@ test_stop_observation_current(const ClusterSemanticActivationRecord *open, const } bool -cluster_reconfig_lmon_observe_replacement_ready( - const ClusterReplacementPhase3HandoffItem *item) +cluster_reconfig_lmon_observe_replacement_ready(const ClusterReplacementPhase3HandoffItem *item) { test_phase3_observe_calls++; if (item != NULL) @@ -785,9 +760,8 @@ cluster_reconfig_lmon_observe_replacement_ready( } bool -cluster_reconfig_lmon_snapshot_replacement_admitted( - ClusterReplacementEpisode *out_episode, - ClusterReplacementCommitMarkerV3 *out_marker) +cluster_reconfig_lmon_snapshot_replacement_admitted(ClusterReplacementEpisode *out_episode, + ClusterReplacementCommitMarkerV3 *out_marker) { test_admitted_snapshot_calls++; if (!test_admitted_snapshot_valid || out_episode == NULL || out_marker == NULL) @@ -798,8 +772,7 @@ cluster_reconfig_lmon_snapshot_replacement_admitted( } bool -cluster_reconfig_snapshot_initial_clean_formation( - ClusterInitialCleanFormationSnapshot *out) +cluster_reconfig_snapshot_initial_clean_formation(ClusterInitialCleanFormationSnapshot *out) { test_initial_clean_snapshot_calls++; if (!test_initial_clean_snapshot_valid || out == NULL) @@ -815,9 +788,8 @@ cluster_grd_recovery_state_value(void) } bool -cluster_reconfig_lmon_snapshot_admitted_membership( - uint64 *out_members_lo, uint64 *out_members_hi, - uint64 *out_formation_epoch) +cluster_reconfig_lmon_snapshot_admitted_membership(uint64 *out_members_lo, uint64 *out_members_hi, + uint64 *out_formation_epoch) { test_membership_snapshot_calls++; if (test_membership_snapshot_hook != NULL) { @@ -889,8 +861,7 @@ cluster_lms_r4_drain_request(ClusterLmsSharedState *state, uint64 generation, { test_drain_request_calls++; test_drain_request_generation = generation; - if (!test_drain_request_succeeds || state != &test_lms_state - || worker_incarnation == NULL) + if (!test_drain_request_succeeds || state != &test_lms_state || worker_incarnation == NULL) return false; *worker_incarnation = test_drain_worker_incarnation; return true; @@ -904,8 +875,7 @@ cluster_lms_wakeup(int worker_id) } bool -cluster_cr_server_r4_lmon_reclaim_closed(uint64 worker_incarnation, - uint64 generation) +cluster_cr_server_r4_lmon_reclaim_closed(uint64 worker_incarnation, uint64 generation) { test_reclaim_calls++; test_reclaim_worker_incarnation = worker_incarnation; @@ -935,38 +905,30 @@ cluster_gcs_block_r4_requester_count(void) } ClusterUndoSmgrRootMirrorState -cluster_undo_smgr_root_descriptor_read_candidate( - const char *root_directory, - uint8 observed[CLUSTER_UNDO_ROOT_DESCRIPTOR_BYTES]) +cluster_undo_smgr_root_descriptor_read_candidate(const char *root_directory, + uint8 observed[CLUSTER_UNDO_ROOT_DESCRIPTOR_BYTES]) { test_pgrd_candidate_read_calls++; - strlcpy(test_pgrd_candidate_root_directory, - root_directory != NULL ? root_directory : "", + strlcpy(test_pgrd_candidate_root_directory, root_directory != NULL ? root_directory : "", sizeof(test_pgrd_candidate_root_directory)); - if (test_pgrd_candidate_state - == CLUSTER_UNDO_SMGR_ROOT_MIRROR_EXACT && observed != NULL) + if (test_pgrd_candidate_state == CLUSTER_UNDO_SMGR_ROOT_MIRROR_EXACT && observed != NULL) memcpy(observed, test_pgrd_candidate, sizeof(test_pgrd_candidate)); return test_pgrd_candidate_state; } ClusterUndoSmgrRootMirrorState -cluster_undo_smgr_root_descriptor_publish( - const char *root_directory, - const uint8 image[CLUSTER_UNDO_ROOT_DESCRIPTOR_BYTES]) +cluster_undo_smgr_root_descriptor_publish(const char *root_directory, + const uint8 image[CLUSTER_UNDO_ROOT_DESCRIPTOR_BYTES]) { test_pgrd_publish_calls++; - strlcpy(test_pgrd_publish_root_directory, - root_directory != NULL ? root_directory : "", + strlcpy(test_pgrd_publish_root_directory, root_directory != NULL ? root_directory : "", sizeof(test_pgrd_publish_root_directory)); if (image != NULL) { memcpy(test_pgrd_published, image, sizeof(test_pgrd_published)); - if (test_pgrd_publish_result - == CLUSTER_UNDO_SMGR_ROOT_MIRROR_PUBLISHED - || test_pgrd_publish_result - == CLUSTER_UNDO_SMGR_ROOT_MIRROR_EXACT) { + if (test_pgrd_publish_result == CLUSTER_UNDO_SMGR_ROOT_MIRROR_PUBLISHED + || test_pgrd_publish_result == CLUSTER_UNDO_SMGR_ROOT_MIRROR_EXACT) { memcpy(test_pgrd_candidate, image, sizeof(test_pgrd_candidate)); - test_pgrd_candidate_state - = CLUSTER_UNDO_SMGR_ROOT_MIRROR_EXACT; + test_pgrd_candidate_state = CLUSTER_UNDO_SMGR_ROOT_MIRROR_EXACT; } } return test_pgrd_publish_result; @@ -1129,8 +1091,7 @@ test_gate_reset(void) test_r4fsm_bootstrap_implicit_open = false; test_restart_unclean = false; test_restart_in_recovery = false; - memset(test_r4fsm_bootstrap_bytes, 0, - sizeof(test_r4fsm_bootstrap_bytes)); + memset(test_r4fsm_bootstrap_bytes, 0, sizeof(test_r4fsm_bootstrap_bytes)); test_peer_capability_matches = false; test_peer_capability_match_calls = 0; test_peer_capability_match_peer = -1; @@ -1139,35 +1100,27 @@ test_gate_reset(void) test_peer_capability_word_sample_ok = false; test_peer_capability_word = 0; test_peer_capability_generation = 0; - memset(test_peer_capability_sample_calls, 0, - sizeof(test_peer_capability_sample_calls)); + memset(test_peer_capability_sample_calls, 0, sizeof(test_peer_capability_sample_calls)); test_local_capability_word = 0; test_ctrc_shmem_is_ready = true; memset(test_send_results, 0, sizeof(test_send_results)); memset(test_send_calls, 0, sizeof(test_send_calls)); memset(test_send_msg_types, 0, sizeof(test_send_msg_types)); - memset(test_send_payload_lengths, 0, - sizeof(test_send_payload_lengths)); + memset(test_send_payload_lengths, 0, sizeof(test_send_payload_lengths)); memset(test_send_payloads, 0, sizeof(test_send_payloads)); - memset(test_send_history_msg_types, 0, - sizeof(test_send_history_msg_types)); - memset(test_send_history_payload_lengths, 0, - sizeof(test_send_history_payload_lengths)); - memset(test_send_history_payloads, 0, - sizeof(test_send_history_payloads)); + memset(test_send_history_msg_types, 0, sizeof(test_send_history_msg_types)); + memset(test_send_history_payload_lengths, 0, sizeof(test_send_history_payload_lengths)); + memset(test_send_history_payloads, 0, sizeof(test_send_history_payloads)); memset(test_close_calls, 0, sizeof(test_close_calls)); test_phase3_observe_calls = 0; memset(&test_phase3_observed_item, 0, sizeof(test_phase3_observed_item)); test_admitted_snapshot_calls = 0; test_admitted_snapshot_valid = false; - memset(&test_admitted_snapshot_episode, 0, - sizeof(test_admitted_snapshot_episode)); - memset(&test_admitted_snapshot_marker, 0, - sizeof(test_admitted_snapshot_marker)); + memset(&test_admitted_snapshot_episode, 0, sizeof(test_admitted_snapshot_episode)); + memset(&test_admitted_snapshot_marker, 0, sizeof(test_admitted_snapshot_marker)); test_initial_clean_snapshot_calls = 0; test_initial_clean_snapshot_valid = false; - memset(&test_initial_clean_snapshot, 0, - sizeof(test_initial_clean_snapshot)); + memset(&test_initial_clean_snapshot, 0, sizeof(test_initial_clean_snapshot)); test_grd_recovery_state = GRD_RECOVERY_IDLE; test_membership_snapshot_calls = 0; test_membership_snapshot_hook = NULL; @@ -1216,21 +1169,15 @@ test_gate_reset(void) test_stop_not_fresh_peer = -1; test_qvotec_self_incarnation = UINT64_C(0x445566778899aabb); test_last_admitted_incarnation = UINT64_C(0x445566778899aabb); - memset(test_remote_admitted_incarnations, 0, - sizeof(test_remote_admitted_incarnations)); + memset(test_remote_admitted_incarnations, 0, sizeof(test_remote_admitted_incarnations)); memset(test_observed_slot_valid, 0, sizeof(test_observed_slot_valid)); - memset(test_observed_slot_incarnation, 0, - sizeof(test_observed_slot_incarnation)); - memset(test_observed_slot_generation, 0, - sizeof(test_observed_slot_generation)); - memset(test_observed_slot_epoch, 0, - sizeof(test_observed_slot_epoch)); + memset(test_observed_slot_incarnation, 0, sizeof(test_observed_slot_incarnation)); + memset(test_observed_slot_generation, 0, sizeof(test_observed_slot_generation)); + memset(test_observed_slot_epoch, 0, sizeof(test_observed_slot_epoch)); test_resource_x_gate_snapshot_valid = false; - memset(&test_resource_x_gate_snapshot, 0, - sizeof(test_resource_x_gate_snapshot)); + memset(&test_resource_x_gate_snapshot, 0, sizeof(test_resource_x_gate_snapshot)); test_resource_x_cutover_digest_valid = false; - memset(&test_resource_x_cutover_token, 0, - sizeof(test_resource_x_cutover_token)); + memset(&test_resource_x_cutover_token, 0, sizeof(test_resource_x_cutover_token)); test_resource_x_cutover_thawed = false; test_resource_x_cutover_digest = 0; cluster_shared_data_dir = NULL; @@ -1269,8 +1216,7 @@ test_gate_reset(void) * CAS driver state is per-round — reset it like the R4 CAS state. */ semantic_activation_lmon_bit22_prepare_cas_seq = 0; semantic_activation_lmon_bit22_prepare_cas_done = false; - semantic_activation_ack_ingress_init( - &semantic_activation_ack_local_ingress); + semantic_activation_ack_ingress_init(&semantic_activation_ack_local_ingress); memset(&semantic_activation_ack_local_pending_send, 0, sizeof(semantic_activation_ack_local_pending_send)); memset(&semantic_activation_ack_local_request_origin, 0, @@ -1449,8 +1395,7 @@ UT_TEST(test_10_r4_descriptor_has_every_callback) UT_TEST(test_10a_r11_resource_x_cutover_descriptor_is_compiled_exact) { - const ClusterSemanticActivationDescriptor *r4 - = cluster_semantic_activation_r4_descriptor(); + const ClusterSemanticActivationDescriptor *r4 = cluster_semantic_activation_r4_descriptor(); const ClusterSemanticActivationDescriptor *cutover = cluster_semantic_activation_r11_resource_x_descriptor(); ClusterSemanticActivationRefusal refusal; @@ -1458,11 +1403,9 @@ UT_TEST(test_10a_r11_resource_x_cutover_descriptor_is_compiled_exact) UT_ASSERT_NOT_NULL(cutover); UT_ASSERT_STR_EQ(cutover->name, "R11_RESOURCE_X_D5_CUTOVER_V1"); - UT_ASSERT_EQ(cutover->feature_bit, - CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1); - UT_ASSERT_EQ(cutover->required_hello_caps, - PGRAC_IC_HELLO_CAP_SEMANTIC_ACTIVATION_V1 - | PGRAC_IC_HELLO_CAP_GCS_RESOURCE_X_CONVERT_V1); + UT_ASSERT_EQ(cutover->feature_bit, CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1); + UT_ASSERT_EQ(cutover->required_hello_caps, PGRAC_IC_HELLO_CAP_SEMANTIC_ACTIVATION_V1 + | PGRAC_IC_HELLO_CAP_GCS_RESOURCE_X_CONVERT_V1); UT_ASSERT_EQ(cutover->required_active_bits, 0); UT_ASSERT(!cutover->source_available); UT_ASSERT_NOT_NULL(cutover->pre_prepare_readiness); @@ -1473,26 +1416,24 @@ UT_TEST(test_10a_r11_resource_x_cutover_descriptor_is_compiled_exact) UT_ASSERT_NOT_NULL(cutover->apply_target_closed); UT_ASSERT_NOT_NULL(cutover->revert_source_closed); UT_ASSERT_NOT_NULL(cutover->open_target_admission); + UT_ASSERT_EQ(cluster_semantic_activation_descriptor(CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1), + r4); UT_ASSERT_EQ(cluster_semantic_activation_descriptor( - CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1), r4); - UT_ASSERT_EQ(cluster_semantic_activation_descriptor( - CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1), + CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1), cutover); UT_ASSERT_EQ(cluster_semantic_activation_compiled_feature_bitmap(), CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1 - | CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1); + | CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1); /* Source removal does not remove the native Resource-X owner. R4 only * revalidates freshness: a nonzero native Resource-X formation is a * separate numeric domain and need not equal the R4 generation. */ test_gate_reset(); - test_gate_publish(2, CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, - 7, test_current_epoch, false); + test_gate_publish(2, CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, 7, test_current_epoch, false); test_resource_x_gate_snapshot_valid = true; test_resource_x_gate_snapshot.phase = RESOURCE_X_GATE_OPEN; test_resource_x_gate_snapshot.formation = 17; memset(&refusal, 0, sizeof(refusal)); - UT_ASSERT_EQ(cutover->pre_prepare_readiness(7, &refusal), - CLUSTER_SEMANTIC_ACTIVATION_OK); + UT_ASSERT_EQ(cutover->pre_prepare_readiness(7, &refusal), CLUSTER_SEMANTIC_ACTIVATION_OK); UT_ASSERT_EQ(refusal.result, CLUSTER_SEMANTIC_ACTIVATION_OK); UT_ASSERT_EQ(refusal.feature_bit, UINT64_C(0)); UT_ASSERT_EQ(refusal.expected_generation, 7); @@ -1511,21 +1452,15 @@ UT_TEST(test_10a_r11_resource_x_cutover_descriptor_is_compiled_exact) UT_ASSERT_EQ(proof.debt_count, 0); UT_ASSERT_EQ(proof.sample_digest, 0); memset(&proof, 0x7f, sizeof(proof)); - UT_ASSERT_EQ(cutover->source_transport_zero(7, &proof), - CLUSTER_SEMANTIC_ACTIVATION_BAD_STATE); + UT_ASSERT_EQ(cutover->source_transport_zero(7, &proof), CLUSTER_SEMANTIC_ACTIVATION_BAD_STATE); UT_ASSERT_EQ(proof.record_generation, 0); UT_ASSERT_EQ(proof.debt_count, 0); UT_ASSERT_EQ(proof.sample_digest, 0); - UT_ASSERT_EQ(cutover->close_source_admission(7), - CLUSTER_SEMANTIC_ACTIVATION_BAD_STATE); - UT_ASSERT_EQ(cutover->prepare_target(7), - CLUSTER_SEMANTIC_ACTIVATION_BAD_STATE); - UT_ASSERT_EQ(cutover->apply_target_closed(7), - CLUSTER_SEMANTIC_ACTIVATION_BAD_STATE); - UT_ASSERT_EQ(cutover->revert_source_closed(7), - CLUSTER_SEMANTIC_ACTIVATION_BAD_STATE); - UT_ASSERT_EQ(cutover->open_target_admission(7), - CLUSTER_SEMANTIC_ACTIVATION_BAD_STATE); + UT_ASSERT_EQ(cutover->close_source_admission(7), CLUSTER_SEMANTIC_ACTIVATION_BAD_STATE); + UT_ASSERT_EQ(cutover->prepare_target(7), CLUSTER_SEMANTIC_ACTIVATION_BAD_STATE); + UT_ASSERT_EQ(cutover->apply_target_closed(7), CLUSTER_SEMANTIC_ACTIVATION_BAD_STATE); + UT_ASSERT_EQ(cutover->revert_source_closed(7), CLUSTER_SEMANTIC_ACTIVATION_BAD_STATE); + UT_ASSERT_EQ(cutover->open_target_admission(7), CLUSTER_SEMANTIC_ACTIVATION_BAD_STATE); test_gate_reset(); } @@ -1536,41 +1471,33 @@ UT_TEST(test_10b_r11_writer_selector_snapshots_one_exact_gate_generation) ClusterSemanticR11CutoverSnapshot cutover; ClusterSemanticActivationAckTableV1 *table; ClusterSemanticZeroProof proof; - uint32 resource_x_caps - = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS - | PGRAC_IC_HELLO_CAP_GCS_RESOURCE_X_CONVERT_V1; + uint32 resource_x_caps = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS + | PGRAC_IC_HELLO_CAP_GCS_RESOURCE_X_CONVERT_V1; uint64 generation = UINT64_MAX; uint64 sample_digest = 0; int node; test_gate_reset(); test_gate_publish(2, 0, 19, test_current_epoch, false); - UT_ASSERT_EQ(cluster_resource_x_writer_path_snapshot(&generation), - RESOURCE_X_WRITER_CLOSED); + UT_ASSERT_EQ(cluster_resource_x_writer_path_snapshot(&generation), RESOURCE_X_WRITER_CLOSED); UT_ASSERT_EQ(generation, UINT64_C(19)); - test_gate_publish(4, - CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1, - 20, test_current_epoch, false); - UT_ASSERT_EQ(cluster_resource_x_writer_path_snapshot(&generation), - RESOURCE_X_WRITER_TARGET); + test_gate_publish(4, CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1, 20, + test_current_epoch, false); + UT_ASSERT_EQ(cluster_resource_x_writer_path_snapshot(&generation), RESOURCE_X_WRITER_TARGET); UT_ASSERT_EQ(generation, UINT64_C(20)); - test_gate_publish(6, - CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1, - 21, test_current_epoch, true); - UT_ASSERT_EQ(cluster_resource_x_writer_path_snapshot(&generation), - RESOURCE_X_WRITER_CLOSED); + test_gate_publish(6, CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1, 21, + test_current_epoch, true); + UT_ASSERT_EQ(cluster_resource_x_writer_path_snapshot(&generation), RESOURCE_X_WRITER_CLOSED); UT_ASSERT_EQ(generation, UINT64_C(21)); /* A torn gate and a missing output owner both fail closed. */ test_gate_publish(7, 0, 22, test_current_epoch, false); generation = UINT64_MAX; - UT_ASSERT_EQ(cluster_resource_x_writer_path_snapshot(&generation), - RESOURCE_X_WRITER_CLOSED); + UT_ASSERT_EQ(cluster_resource_x_writer_path_snapshot(&generation), RESOURCE_X_WRITER_CLOSED); UT_ASSERT_EQ(generation, UINT64_C(0)); - UT_ASSERT_EQ(cluster_resource_x_writer_path_snapshot(NULL), - RESOURCE_X_WRITER_CLOSED); + UT_ASSERT_EQ(cluster_resource_x_writer_path_snapshot(NULL), RESOURCE_X_WRITER_CLOSED); /* Exact R11 SOURCE_CLOSED is a read-only co-sample of the admission gate, * current formation/capabilities, and the complete SAMPLE ACK image. The @@ -1586,14 +1513,12 @@ UT_TEST(test_10b_r11_writer_selector_snapshots_one_exact_gate_generation) test_peer_capability_word = resource_x_caps; test_peer_capability_generation = 19; for (node = 0; node < 4; node++) - test_remote_admitted_incarnations[node] - = UINT64_C(0x100) + (uint64)node; + test_remote_admitted_incarnations[node] = UINT64_C(0x100) + (uint64)node; for (node = 0; node < 4; node++) { test_observed_slot_valid[node] = true; - test_observed_slot_incarnation[node] - = node == cluster_node_id - ? test_qvotec_self_incarnation - : test_remote_admitted_incarnations[node]; + test_observed_slot_incarnation[node] = node == cluster_node_id + ? test_qvotec_self_incarnation + : test_remote_admitted_incarnations[node]; test_observed_slot_generation[node] = UINT64_C(41) + (uint64)node; test_observed_slot_epoch[node] = 7; } @@ -1609,23 +1534,18 @@ UT_TEST(test_10b_r11_writer_selector_snapshots_one_exact_gate_generation) table->observed_members_lo = UINT64_C(0x0f); table->transition_epoch = test_current_epoch; table->record_generation = 23; - table->source_feature_bitmap - = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1; - table->target_feature_bitmap - = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1 - | CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1; + table->source_feature_bitmap = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1; + table->target_feature_bitmap = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1 + | CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1; table->capability_sample_digest = 0; for (node = 0; node < 4; node++) { if (node == cluster_node_id) { - UT_ASSERT(semantic_activation_ack_self_tuple( - node, resource_x_caps, test_current_epoch, 23, - &table->expected[node])); + UT_ASSERT(semantic_activation_ack_self_tuple(node, resource_x_caps, test_current_epoch, + 23, &table->expected[node])); } else { table->expected[node].node_id = (uint32)node; - table->expected[node].boot_id - = test_remote_admitted_incarnations[node]; - table->expected[node].admitted_incarnation - = test_remote_admitted_incarnations[node]; + table->expected[node].boot_id = test_remote_admitted_incarnations[node]; + table->expected[node].admitted_incarnation = test_remote_admitted_incarnations[node]; table->expected[node].control_connection_generation = 19; table->expected[node].capability_word = resource_x_caps; table->expected[node].capability_generation = 19; @@ -1634,15 +1554,11 @@ UT_TEST(test_10b_r11_writer_selector_snapshots_one_exact_gate_generation) } table->observed[node] = table->expected[node]; } - UT_ASSERT(semantic_activation_ack_sample_digest( - table, &sample_digest)); + UT_ASSERT(semantic_activation_ack_sample_digest(table, &sample_digest)); UT_ASSERT(sample_digest != 0); - test_gate_publish(8, - CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, - 23, test_current_epoch, true); + test_gate_publish(8, CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, 23, test_current_epoch, true); UT_ASSERT(cluster_semantic_activation_r11_cutover_snapshot(&cutover)); - UT_ASSERT_EQ(cutover.phase, - CLUSTER_SEMANTIC_R11_CUTOVER_SOURCE_CLOSED); + UT_ASSERT_EQ(cutover.phase, CLUSTER_SEMANTIC_R11_CUTOVER_SOURCE_CLOSED); UT_ASSERT_EQ(cutover.record_generation, UINT64_C(23)); UT_ASSERT_EQ(cutover.formation_epoch, test_current_epoch); test_resource_x_cutover_digest_valid = true; @@ -1656,26 +1572,19 @@ UT_TEST(test_10b_r11_writer_selector_snapshots_one_exact_gate_generation) test_resource_x_gate_snapshot.phase = RESOURCE_X_GATE_FROZEN; test_resource_x_gate_snapshot.formation = 17; test_resource_x_gate_snapshot.freeze_generation = 1; - UT_ASSERT_EQ(descriptor->close_source_admission(23), - CLUSTER_SEMANTIC_ACTIVATION_OK); + UT_ASSERT_EQ(descriptor->close_source_admission(23), CLUSTER_SEMANTIC_ACTIVATION_OK); memset(&proof, 0, sizeof(proof)); - UT_ASSERT_EQ(descriptor->source_logical_debt_zero(23, &proof), - CLUSTER_SEMANTIC_ACTIVATION_OK); + UT_ASSERT_EQ(descriptor->source_logical_debt_zero(23, &proof), CLUSTER_SEMANTIC_ACTIVATION_OK); UT_ASSERT_EQ(proof.record_generation, UINT64_C(23)); UT_ASSERT_EQ(proof.debt_count, UINT64_C(0)); UT_ASSERT_EQ(proof.sample_digest, UINT64_C(0xa55a9911)); memset(&proof, 0, sizeof(proof)); - UT_ASSERT_EQ(descriptor->source_transport_zero(23, &proof), - CLUSTER_SEMANTIC_ACTIVATION_OK); + UT_ASSERT_EQ(descriptor->source_transport_zero(23, &proof), CLUSTER_SEMANTIC_ACTIVATION_OK); UT_ASSERT_EQ(proof.sample_digest, UINT64_C(0xa55a9911)); - UT_ASSERT_EQ(descriptor->prepare_target(23), - CLUSTER_SEMANTIC_ACTIVATION_OK); - UT_ASSERT_EQ(descriptor->apply_target_closed(23), - CLUSTER_SEMANTIC_ACTIVATION_OK); - UT_ASSERT_EQ(descriptor->revert_source_closed(23), - CLUSTER_SEMANTIC_ACTIVATION_BAD_STATE); - UT_ASSERT_EQ(descriptor->open_target_admission(23), - CLUSTER_SEMANTIC_ACTIVATION_BAD_STATE); + UT_ASSERT_EQ(descriptor->prepare_target(23), CLUSTER_SEMANTIC_ACTIVATION_OK); + UT_ASSERT_EQ(descriptor->apply_target_closed(23), CLUSTER_SEMANTIC_ACTIVATION_OK); + UT_ASSERT_EQ(descriptor->revert_source_closed(23), CLUSTER_SEMANTIC_ACTIVATION_BAD_STATE); + UT_ASSERT_EQ(descriptor->open_target_admission(23), CLUSTER_SEMANTIC_ACTIVATION_BAD_STATE); /* Durable OPEN is one record generation ahead of the still-closed local * selector. It becomes TARGET_OPEN only after local publication. */ @@ -1686,28 +1595,19 @@ UT_TEST(test_10b_r11_writer_selector_snapshots_one_exact_gate_generation) table->expected[node].record_generation = 25; table->observed[node].record_generation = 25; } - test_gate_publish(10, - CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, - 24, test_current_epoch, true); + test_gate_publish(10, CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, 24, test_current_epoch, true); UT_ASSERT(cluster_semantic_activation_r11_cutover_snapshot(&cutover)); - UT_ASSERT_EQ(cutover.phase, - CLUSTER_SEMANTIC_R11_CUTOVER_DURABLE_OPEN_PENDING_LOCAL); + UT_ASSERT_EQ(cutover.phase, CLUSTER_SEMANTIC_R11_CUTOVER_DURABLE_OPEN_PENDING_LOCAL); UT_ASSERT_EQ(cutover.record_generation, UINT64_C(23)); test_resource_x_cutover_thawed = true; - UT_ASSERT_EQ(descriptor->open_target_admission(23), - CLUSTER_SEMANTIC_ACTIVATION_OK); - UT_ASSERT_EQ(descriptor->open_target_admission(24), - CLUSTER_SEMANTIC_ACTIVATION_BAD_STATE); - test_gate_publish(12, table->target_feature_bitmap, 25, - test_current_epoch, false); + UT_ASSERT_EQ(descriptor->open_target_admission(23), CLUSTER_SEMANTIC_ACTIVATION_OK); + UT_ASSERT_EQ(descriptor->open_target_admission(24), CLUSTER_SEMANTIC_ACTIVATION_BAD_STATE); + test_gate_publish(12, table->target_feature_bitmap, 25, test_current_epoch, false); UT_ASSERT(cluster_semantic_activation_r11_cutover_snapshot(&cutover)); - UT_ASSERT_EQ(cutover.phase, - CLUSTER_SEMANTIC_R11_CUTOVER_TARGET_OPEN); + UT_ASSERT_EQ(cutover.phase, CLUSTER_SEMANTIC_R11_CUTOVER_TARGET_OPEN); /* Any round or generation drift is not a cutover phase. */ - test_gate_publish(12, - CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, - 22, test_current_epoch, true); + test_gate_publish(12, CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, 22, test_current_epoch, true); UT_ASSERT(!cluster_semantic_activation_r11_cutover_snapshot(&cutover)); UT_ASSERT_EQ(cutover.phase, CLUSTER_SEMANTIC_R11_CUTOVER_NONE); test_gate_reset(); @@ -1720,41 +1620,29 @@ UT_TEST(test_10c_r4_carrier_selects_one_exact_compiled_feature_round) uint64 r4 = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1; uint64 r11 = CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1; - UT_ASSERT(semantic_activation_round_descriptor( - 0, r4, 0, &descriptor, &required_caps)); + UT_ASSERT(semantic_activation_round_descriptor(0, r4, 0, &descriptor, &required_caps)); UT_ASSERT_EQ(descriptor, cluster_semantic_activation_r4_descriptor()); UT_ASSERT_EQ(required_caps, - CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS - | descriptor->required_hello_caps); + CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS | descriptor->required_hello_caps); descriptor = NULL; required_caps = 0; - UT_ASSERT(semantic_activation_round_descriptor( - r4, r4 | r11, 0, &descriptor, &required_caps)); - UT_ASSERT_EQ(descriptor, - cluster_semantic_activation_r11_resource_x_descriptor()); + UT_ASSERT(semantic_activation_round_descriptor(r4, r4 | r11, 0, &descriptor, &required_caps)); + UT_ASSERT_EQ(descriptor, cluster_semantic_activation_r11_resource_x_descriptor()); UT_ASSERT_EQ(required_caps, - CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS - | descriptor->required_hello_caps); + CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS | descriptor->required_hello_caps); /* R4 remains the carrier for every later exact one-feature round. */ - UT_ASSERT(!semantic_activation_round_descriptor( - 0, r11, 0, &descriptor, &required_caps)); - UT_ASSERT(!semantic_activation_round_descriptor( - 0, r4 | r11, 0, &descriptor, &required_caps)); - UT_ASSERT(!semantic_activation_round_descriptor( - r4 | r11, r4, 0, &descriptor, &required_caps)); - UT_ASSERT(!semantic_activation_round_descriptor( - r4, r4, 0, &descriptor, &required_caps)); - UT_ASSERT(!semantic_activation_round_descriptor( - r4, r4 | (UINT64_C(1) << 9), 0, - &descriptor, &required_caps)); - UT_ASSERT(!semantic_activation_round_descriptor( - r4, r4 | r11, r11, &descriptor, &required_caps)); - UT_ASSERT(!semantic_activation_round_descriptor( - r4, r4 | r11, 0, NULL, &required_caps)); - UT_ASSERT(!semantic_activation_round_descriptor( - r4, r4 | r11, 0, &descriptor, NULL)); + UT_ASSERT(!semantic_activation_round_descriptor(0, r11, 0, &descriptor, &required_caps)); + UT_ASSERT(!semantic_activation_round_descriptor(0, r4 | r11, 0, &descriptor, &required_caps)); + UT_ASSERT(!semantic_activation_round_descriptor(r4 | r11, r4, 0, &descriptor, &required_caps)); + UT_ASSERT(!semantic_activation_round_descriptor(r4, r4, 0, &descriptor, &required_caps)); + UT_ASSERT(!semantic_activation_round_descriptor(r4, r4 | (UINT64_C(1) << 9), 0, &descriptor, + &required_caps)); + UT_ASSERT( + !semantic_activation_round_descriptor(r4, r4 | r11, r11, &descriptor, &required_caps)); + UT_ASSERT(!semantic_activation_round_descriptor(r4, r4 | r11, 0, NULL, &required_caps)); + UT_ASSERT(!semantic_activation_round_descriptor(r4, r4 | r11, 0, &descriptor, NULL)); } UT_TEST(test_11_source_only_is_exclusive) @@ -1988,18 +1876,16 @@ UT_TEST(test_75a_d13_full_ack_table_requires_exact_member_set_and_tuples) observed[1] = expected[1]; observed[3] = expected[3]; - UT_ASSERT(semantic_activation_full_ack_table_matches( - observed, members_lo, 0, expected, members_lo, 0)); + UT_ASSERT(semantic_activation_full_ack_table_matches(observed, members_lo, 0, expected, + members_lo, 0)); observed[3].capability_generation++; - UT_ASSERT(!semantic_activation_full_ack_table_matches( - observed, members_lo, 0, expected, members_lo, 0)); + UT_ASSERT(!semantic_activation_full_ack_table_matches(observed, members_lo, 0, expected, + members_lo, 0)); observed[3] = expected[3]; UT_ASSERT(!semantic_activation_full_ack_table_matches( - observed, members_lo & ~(UINT64_C(1) << 3), 0, - expected, members_lo, 0)); - UT_ASSERT(!semantic_activation_full_ack_table_matches( - observed, members_lo | (UINT64_C(1) << 4), 0, - expected, members_lo, 0)); + observed, members_lo & ~(UINT64_C(1) << 3), 0, expected, members_lo, 0)); + UT_ASSERT(!semantic_activation_full_ack_table_matches(observed, members_lo | (UINT64_C(1) << 4), + 0, expected, members_lo, 0)); } UT_TEST(test_76_inactive_feature_source_is_admitted) @@ -2079,8 +1965,8 @@ UT_TEST(test_85a_modifier_gate_requires_durable_source_or_target_open) CLUSTER_SEMANTIC_ADMISSION_CLOSED); UT_ASSERT(!semantic_activation_modifier_policy(0, 0, true)); UT_ASSERT(semantic_activation_modifier_policy(0, 8, false)); - UT_ASSERT(semantic_activation_modifier_policy( - CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, 9, false)); + UT_ASSERT( + semantic_activation_modifier_policy(CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, 9, false)); UT_ASSERT(semantic_activation_modifier_policy( CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1 | CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1, @@ -2090,15 +1976,13 @@ UT_TEST(test_85a_modifier_gate_requires_durable_source_or_target_open) UT_TEST(test_85b_modifier_gate_closes_replacement_until_uniform_open) { UT_ASSERT(!semantic_activation_modifier_policy(0, 9, true)); + UT_ASSERT( + !semantic_activation_modifier_policy(CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, 9, true)); UT_ASSERT(!semantic_activation_modifier_policy( - CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, 9, true)); - UT_ASSERT(!semantic_activation_modifier_policy( - CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1, - 12, false)); + CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1, 12, false)); UT_ASSERT(!semantic_activation_modifier_policy( CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1 - | CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1 - | (UINT64_C(1) << 63), + | CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1 | (UINT64_C(1) << 63), 12, false)); UT_ASSERT(!semantic_activation_modifier_policy(UINT64_C(1) << 63, 9, false)); } @@ -2156,8 +2040,7 @@ valid_r4a_ready_snapshot(void) snapshot.old_admitted_incarnation = UINT64_C(9001); snapshot.fresh_incarnation = UINT64_C(9002); snapshot.committed_epoch = UINT64_C(71); - snapshot.grammar_fingerprint - = CANDIDATE2_CORRECTED_A1_GRAMMAR_FINGERPRINT; + snapshot.grammar_fingerprint = CANDIDATE2_CORRECTED_A1_GRAMMAR_FINGERPRINT; return snapshot; } @@ -2167,8 +2050,7 @@ UT_TEST(test_89d_local_ready_alone_cannot_enter_prepare) test_gate_reset(); test_r4a_snapshot = snapshot; - UT_ASSERT_EQ(r4_pre_prepare_readiness(19, NULL), - CLUSTER_SEMANTIC_ACTIVATION_RF_DEFERRED); + UT_ASSERT_EQ(r4_pre_prepare_readiness(19, NULL), CLUSTER_SEMANTIC_ACTIVATION_RF_DEFERRED); } UT_TEST(test_89e_malformed_local_ready_remains_typed_deferred) @@ -2179,8 +2061,7 @@ UT_TEST(test_89e_malformed_local_ready_remains_typed_deferred) test_r4a_snapshot = valid_r4a_ready_snapshot(); test_r4a_snapshot.reserved0[1] = 1; memset(&refusal, 0, sizeof(refusal)); - UT_ASSERT_EQ(r4_pre_prepare_readiness(19, &refusal), - CLUSTER_SEMANTIC_ACTIVATION_RF_DEFERRED); + UT_ASSERT_EQ(r4_pre_prepare_readiness(19, &refusal), CLUSTER_SEMANTIC_ACTIVATION_RF_DEFERRED); UT_ASSERT_EQ(refusal.result, CLUSTER_SEMANTIC_ACTIVATION_RF_DEFERRED); } @@ -2298,8 +2179,7 @@ UT_TEST(test_89f_positive_ready_stays_deferred_until_full_d13_conjunction) test_gate_reset(); test_r4a_snapshot = valid_r4a_ready_snapshot(); memset(&refusal, 0, sizeof(refusal)); - UT_ASSERT_EQ(r4_pre_prepare_readiness(19, &refusal), - CLUSTER_SEMANTIC_ACTIVATION_RF_DEFERRED); + UT_ASSERT_EQ(r4_pre_prepare_readiness(19, &refusal), CLUSTER_SEMANTIC_ACTIVATION_RF_DEFERRED); test_gate_reset(); } @@ -2326,13 +2206,11 @@ UT_TEST(test_89h_pre_prepare_consumes_durable_admitted_not_ready_getter) test_admitted_snapshot_episode = valid_d13_admitted_episode(); test_admitted_snapshot_marker = valid_d13_admitted_marker(); memset(&refusal, 0, sizeof(refusal)); - UT_ASSERT_EQ(r4_pre_prepare_readiness(19, &refusal), - CLUSTER_SEMANTIC_ACTIVATION_OK); + UT_ASSERT_EQ(r4_pre_prepare_readiness(19, &refusal), CLUSTER_SEMANTIC_ACTIVATION_OK); UT_ASSERT_EQ(test_admitted_snapshot_calls, 1); UT_ASSERT_EQ(test_r4a_snapshot_calls, 0); UT_ASSERT_EQ(refusal.result, CLUSTER_SEMANTIC_ACTIVATION_OK); - UT_ASSERT_EQ(refusal.feature_bit, - CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1); + UT_ASSERT_EQ(refusal.feature_bit, CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1); UT_ASSERT_EQ(refusal.expected_generation, 19); test_gate_reset(); } @@ -2347,8 +2225,7 @@ UT_TEST(test_89h1_pre_prepare_refuses_when_ctrc_storage_is_not_ready) test_admitted_snapshot_marker = valid_d13_admitted_marker(); test_ctrc_shmem_is_ready = false; MemSet(&refusal, 0, sizeof(refusal)); - UT_ASSERT_EQ(r4_pre_prepare_readiness(19, &refusal), - CLUSTER_SEMANTIC_ACTIVATION_RF_DEFERRED); + UT_ASSERT_EQ(r4_pre_prepare_readiness(19, &refusal), CLUSTER_SEMANTIC_ACTIVATION_RF_DEFERRED); UT_ASSERT_EQ(refusal.result, CLUSTER_SEMANTIC_ACTIVATION_RF_DEFERRED); test_gate_reset(); } @@ -2385,30 +2262,24 @@ UT_TEST(test_89i_d13_invalidator_rescan_accepts_only_same_settled_closed_head) = (uint8)(1u << (episode.target_node_id % 8)); head.grammar_fingerprint = episode.grammar_fingerprint; memset(head.predecessor_digest, 0x5a, sizeof(head.predecessor_digest)); - UT_ASSERT(cluster_epoch_authority_value_encode( - &head, CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT, - completion.completion_value)); + UT_ASSERT(cluster_epoch_authority_value_encode(&head, CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT, + completion.completion_value)); memset(&ballot, 0, sizeof(ballot)); ballot.counter = UINT64_C(7); ballot.proposer_node_id = 1; ballot.proposer_admitted_incarnation = UINT64_C(111); ballot.nonce = UINT64_C(0xabcdef); - UT_ASSERT(cluster_epoch_ballot_id_encode( - &ballot, completion.completion_ballot)); + UT_ASSERT(cluster_epoch_ballot_id_encode(&ballot, completion.completion_ballot)); - UT_ASSERT(semantic_activation_r4_invalidator_rescan_matches( - &completion, &marker, &episode)); + UT_ASSERT(semantic_activation_r4_invalidator_rescan_matches(&completion, &marker, &episode)); completion.result = CLUSTER_QVOTEC_MAILBOX_ADOPTED_OTHER; - UT_ASSERT(!semantic_activation_r4_invalidator_rescan_matches( - &completion, &marker, &episode)); + UT_ASSERT(!semantic_activation_r4_invalidator_rescan_matches(&completion, &marker, &episode)); completion.result = CLUSTER_QVOTEC_MAILBOX_CHOSEN; head.fresh_incarnation++; - UT_ASSERT(cluster_epoch_authority_value_encode( - &head, CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT, - completion.completion_value)); - UT_ASSERT(!semantic_activation_r4_invalidator_rescan_matches( - &completion, &marker, &episode)); + UT_ASSERT(cluster_epoch_authority_value_encode(&head, CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT, + completion.completion_value)); + UT_ASSERT(!semantic_activation_r4_invalidator_rescan_matches(&completion, &marker, &episode)); } UT_TEST(test_90_descriptor_uses_the_only_r4a_adapter) @@ -2473,8 +2344,7 @@ UT_TEST(test_90ac_r4_logical_zero_rechecks_gate_before_proof) test_gate_reset(); test_gate_publish(2, 0, 24, test_current_epoch, true); - UT_ASSERT_EQ(descriptor->source_logical_debt_zero(24, &proof), - CLUSTER_SEMANTIC_ACTIVATION_OK); + UT_ASSERT_EQ(descriptor->source_logical_debt_zero(24, &proof), CLUSTER_SEMANTIC_ACTIVATION_OK); UT_ASSERT_EQ(proof.record_generation, UINT64_C(24)); UT_ASSERT_EQ(proof.debt_count, UINT64_C(0)); UT_ASSERT_EQ(proof.sample_digest, UINT64_C(0)); @@ -2577,8 +2447,7 @@ UT_TEST(test_90d_r4_transport_zero_publishes_only_full_zero_proof) test_gate_publish(2, 0, 24, test_current_epoch, true); test_reclaim_succeeds = true; test_route_purge_result = 3; - UT_ASSERT_EQ(descriptor->source_transport_zero(24, &proof), - CLUSTER_SEMANTIC_ACTIVATION_OK); + UT_ASSERT_EQ(descriptor->source_transport_zero(24, &proof), CLUSTER_SEMANTIC_ACTIVATION_OK); UT_ASSERT_EQ(test_drain_request_calls, 1); UT_ASSERT_EQ(test_drain_request_generation, UINT64_C(24)); UT_ASSERT_EQ(test_lms_wakeup_calls, 1); @@ -2626,48 +2495,47 @@ UT_TEST(test_93_preflight_rejects_bad_action_without_effects) UT_TEST(test_93a_activation_actor_effect_ownership_is_exact) { UT_ASSERT(semantic_activation_actor_effect_allowed( - SEMANTIC_ACTIVATION_ACTOR_PROCESS_UTILITY, - SEMANTIC_ACTIVATION_EFFECT_REQUEST_PUBLICATION)); + SEMANTIC_ACTIVATION_ACTOR_PROCESS_UTILITY, SEMANTIC_ACTIVATION_EFFECT_REQUEST_PUBLICATION)); UT_ASSERT(!semantic_activation_actor_effect_allowed(SEMANTIC_ACTIVATION_ACTOR_PROCESS_UTILITY, - SEMANTIC_ACTIVATION_EFFECT_PGSA_WRITE)); + SEMANTIC_ACTIVATION_EFFECT_PGSA_WRITE)); UT_ASSERT(semantic_activation_actor_effect_allowed(SEMANTIC_ACTIVATION_ACTOR_LMON, - SEMANTIC_ACTIVATION_EFFECT_SOURCE_CLOSE)); + SEMANTIC_ACTIVATION_EFFECT_SOURCE_CLOSE)); UT_ASSERT(semantic_activation_actor_effect_allowed(SEMANTIC_ACTIVATION_ACTOR_LMON, - SEMANTIC_ACTIVATION_EFFECT_TARGET_OPEN)); + SEMANTIC_ACTIVATION_EFFECT_TARGET_OPEN)); UT_ASSERT(semantic_activation_actor_effect_allowed(SEMANTIC_ACTIVATION_ACTOR_LMON, - SEMANTIC_ACTIVATION_EFFECT_ACK_MUTATION)); + SEMANTIC_ACTIVATION_EFFECT_ACK_MUTATION)); UT_ASSERT(semantic_activation_actor_effect_allowed(SEMANTIC_ACTIVATION_ACTOR_LMON, - SEMANTIC_ACTIVATION_EFFECT_CONTROL_WIRE)); + SEMANTIC_ACTIVATION_EFFECT_CONTROL_WIRE)); UT_ASSERT(!semantic_activation_actor_effect_allowed(SEMANTIC_ACTIVATION_ACTOR_LMON, - SEMANTIC_ACTIVATION_EFFECT_PGSA_WRITE)); + SEMANTIC_ACTIVATION_EFFECT_PGSA_WRITE)); UT_ASSERT(semantic_activation_actor_effect_allowed(SEMANTIC_ACTIVATION_ACTOR_QVOTEC, - SEMANTIC_ACTIVATION_EFFECT_PGSA_WRITE)); + SEMANTIC_ACTIVATION_EFFECT_PGSA_WRITE)); UT_ASSERT(!semantic_activation_actor_effect_allowed(SEMANTIC_ACTIVATION_ACTOR_QVOTEC, - SEMANTIC_ACTIVATION_EFFECT_ACK_MUTATION)); + SEMANTIC_ACTIVATION_EFFECT_ACK_MUTATION)); UT_ASSERT(!semantic_activation_actor_effect_allowed(SEMANTIC_ACTIVATION_ACTOR_LMS, - SEMANTIC_ACTIVATION_EFFECT_DATA_WIRE)); + SEMANTIC_ACTIVATION_EFFECT_DATA_WIRE)); UT_ASSERT(!semantic_activation_actor_effect_allowed(SEMANTIC_ACTIVATION_ACTOR_DATA, - SEMANTIC_ACTIVATION_EFFECT_DATA_WIRE)); + SEMANTIC_ACTIVATION_EFFECT_DATA_WIRE)); UT_ASSERT(!semantic_activation_actor_effect_allowed( SEMANTIC_ACTIVATION_ACTOR_PROCESS_UTILITY, (SemanticActivationEffect)(SEMANTIC_ACTIVATION_EFFECT_REQUEST_PUBLICATION - | SEMANTIC_ACTIVATION_EFFECT_PGSA_WRITE))); + | SEMANTIC_ACTIVATION_EFFECT_PGSA_WRITE))); } UT_TEST(test_93b_activation_mailbox_route_has_no_owner_bypass) { - UT_ASSERT(semantic_activation_actor_edge_allowed( - SEMANTIC_ACTIVATION_ACTOR_PROCESS_UTILITY, SEMANTIC_ACTIVATION_ACTOR_LMON)); + UT_ASSERT(semantic_activation_actor_edge_allowed(SEMANTIC_ACTIVATION_ACTOR_PROCESS_UTILITY, + SEMANTIC_ACTIVATION_ACTOR_LMON)); UT_ASSERT(semantic_activation_actor_edge_allowed(SEMANTIC_ACTIVATION_ACTOR_LMON, - SEMANTIC_ACTIVATION_ACTOR_QVOTEC)); - UT_ASSERT(!semantic_activation_actor_edge_allowed( - SEMANTIC_ACTIVATION_ACTOR_PROCESS_UTILITY, SEMANTIC_ACTIVATION_ACTOR_QVOTEC)); + SEMANTIC_ACTIVATION_ACTOR_QVOTEC)); UT_ASSERT(!semantic_activation_actor_edge_allowed(SEMANTIC_ACTIVATION_ACTOR_PROCESS_UTILITY, - SEMANTIC_ACTIVATION_ACTOR_LMS)); + SEMANTIC_ACTIVATION_ACTOR_QVOTEC)); + UT_ASSERT(!semantic_activation_actor_edge_allowed(SEMANTIC_ACTIVATION_ACTOR_PROCESS_UTILITY, + SEMANTIC_ACTIVATION_ACTOR_LMS)); UT_ASSERT(!semantic_activation_actor_edge_allowed(SEMANTIC_ACTIVATION_ACTOR_LMON, - SEMANTIC_ACTIVATION_ACTOR_DATA)); + SEMANTIC_ACTIVATION_ACTOR_DATA)); UT_ASSERT(!semantic_activation_actor_edge_allowed(SEMANTIC_ACTIVATION_ACTOR_QVOTEC, - SEMANTIC_ACTIVATION_ACTOR_LMON)); + SEMANTIC_ACTIVATION_ACTOR_LMON)); } UT_TEST(test_93c_utility_mailbox_preserves_exact_owner_tuple_and_completion) @@ -2681,11 +2549,11 @@ UT_TEST(test_93c_utility_mailbox_preserves_exact_owner_tuple_and_completion) memset(&request, 0, sizeof(request)); memset(&refusal, 0, sizeof(refusal)); UT_ASSERT(semantic_activation_utility_mailbox_submit( - CLUSTER_SEMANTIC_ENABLE_ALL, UINT64_C(0x11), UINT64_C(0x22), - UINT64_C(0x33), UINT64_C(41), &request_seq)); + CLUSTER_SEMANTIC_ENABLE_ALL, UINT64_C(0x11), UINT64_C(0x22), UINT64_C(0x33), UINT64_C(41), + &request_seq)); UT_ASSERT(request_seq != 0); - UT_ASSERT(!semantic_activation_utility_mailbox_submit( - CLUSTER_SEMANTIC_DISABLE_ALL, 0, 0, 0, 0, &blocked_seq)); + UT_ASSERT(!semantic_activation_utility_mailbox_submit(CLUSTER_SEMANTIC_DISABLE_ALL, 0, 0, 0, 0, + &blocked_seq)); UT_ASSERT(semantic_activation_utility_mailbox_poll(&request)); UT_ASSERT_EQ(request.request_seq, request_seq); UT_ASSERT_EQ(request.action, CLUSTER_SEMANTIC_ENABLE_ALL); @@ -2693,21 +2561,17 @@ UT_TEST(test_93c_utility_mailbox_preserves_exact_owner_tuple_and_completion) UT_ASSERT_EQ(request.target_feature_bitmap, UINT64_C(0x22)); UT_ASSERT_EQ(request.rollback_feature_bitmap, UINT64_C(0x33)); UT_ASSERT_EQ(request.expected_record_generation, UINT64_C(41)); - UT_ASSERT_EQ(pg_atomic_read_u64( - &SemanticActivationShmem->record_cas_request_seq), UINT64_C(0)); - UT_ASSERT(!semantic_activation_utility_mailbox_complete( - request_seq + 1, CLUSTER_SEMANTIC_ACTIVATION_OK, 0, 41)); + UT_ASSERT_EQ(pg_atomic_read_u64(&SemanticActivationShmem->record_cas_request_seq), UINT64_C(0)); + UT_ASSERT(!semantic_activation_utility_mailbox_complete(request_seq + 1, + CLUSTER_SEMANTIC_ACTIVATION_OK, 0, 41)); UT_ASSERT(semantic_activation_utility_mailbox_complete( request_seq, CLUSTER_SEMANTIC_ACTIVATION_RF_DEFERRED, CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, 41)); - UT_ASSERT(semantic_activation_utility_mailbox_poll_completion( - request_seq, &refusal)); + UT_ASSERT(semantic_activation_utility_mailbox_poll_completion(request_seq, &refusal)); UT_ASSERT_EQ(refusal.result, CLUSTER_SEMANTIC_ACTIVATION_RF_DEFERRED); - UT_ASSERT_EQ(refusal.feature_bit, - CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1); + UT_ASSERT_EQ(refusal.feature_bit, CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1); UT_ASSERT_EQ(refusal.expected_generation, UINT64_C(41)); - UT_ASSERT(!semantic_activation_utility_mailbox_poll_completion( - request_seq, &refusal)); + UT_ASSERT(!semantic_activation_utility_mailbox_poll_completion(request_seq, &refusal)); } UT_TEST(test_93d_formation_lmon_alone_consumes_utility_request) @@ -2719,20 +2583,17 @@ UT_TEST(test_93d_formation_lmon_alone_consumes_utility_request) test_admitted_snapshot_valid = true; test_admitted_snapshot_episode = valid_d13_admitted_episode(); test_admitted_snapshot_marker = valid_d13_admitted_marker(); - UT_ASSERT(semantic_activation_utility_mailbox_submit( - CLUSTER_SEMANTIC_ENABLE_ALL, 0, - CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, 0, 0, &request_seq)); + UT_ASSERT(semantic_activation_utility_mailbox_submit(CLUSTER_SEMANTIC_ENABLE_ALL, 0, + CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, 0, + 0, &request_seq)); cluster_semantic_activation_lmon_tick(); memset(&refusal, 0, sizeof(refusal)); - UT_ASSERT(semantic_activation_utility_mailbox_poll_completion( - request_seq, &refusal)); + UT_ASSERT(semantic_activation_utility_mailbox_poll_completion(request_seq, &refusal)); UT_ASSERT_EQ(refusal.result, CLUSTER_SEMANTIC_ACTIVATION_RF_DEFERRED); - UT_ASSERT_EQ(refusal.feature_bit, - CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1); + UT_ASSERT_EQ(refusal.feature_bit, CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1); UT_ASSERT_EQ(refusal.expected_generation, UINT64_C(0)); UT_ASSERT_EQ(test_admitted_snapshot_calls, 1); - UT_ASSERT_EQ(pg_atomic_read_u64( - &SemanticActivationShmem->record_cas_request_seq), UINT64_C(0)); + UT_ASSERT_EQ(pg_atomic_read_u64(&SemanticActivationShmem->record_cas_request_seq), UINT64_C(0)); test_gate_reset(); } @@ -2751,30 +2612,25 @@ UT_TEST(test_93da_coordinator_begins_exact_four_node_sample_round) test_admitted_snapshot_valid = true; test_admitted_snapshot_episode = valid_d13_admitted_episode(); test_admitted_snapshot_marker = valid_d13_admitted_marker(); - test_local_capability_word - = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS; + test_local_capability_word = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS; test_peer_capability_word_sample_ok = true; - test_peer_capability_word - = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS; + test_peer_capability_word = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS; test_peer_capability_generation = 19; for (node = 0; node < CLUSTER_MAX_NODES; node++) test_send_results[node] = CLUSTER_IC_SEND_DONE; - UT_ASSERT(semantic_activation_utility_mailbox_submit( - CLUSTER_SEMANTIC_ENABLE_ALL, 0, - CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, 0, 7, - &request_seq)); + UT_ASSERT(semantic_activation_utility_mailbox_submit(CLUSTER_SEMANTIC_ENABLE_ALL, 0, + CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, 0, + 7, &request_seq)); cluster_semantic_activation_lmon_tick(); memset(&pending_request, 0, sizeof(pending_request)); UT_ASSERT(semantic_activation_utility_mailbox_poll(&pending_request)); UT_ASSERT_EQ(pending_request.request_seq, request_seq); memset(&refusal, 0, sizeof(refusal)); - UT_ASSERT(!semantic_activation_utility_mailbox_poll_completion( - request_seq, &refusal)); + UT_ASSERT(!semantic_activation_utility_mailbox_poll_completion(request_seq, &refusal)); UT_ASSERT(semantic_activation_ack_table_snapshot(&table)); - UT_ASSERT_EQ(table.stage, - CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_SAMPLE); + UT_ASSERT_EQ(table.stage, CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_SAMPLE); UT_ASSERT_EQ(table.flags, UINT32_C(0)); UT_ASSERT_EQ(table.coordinator_node, UINT32_C(0)); UT_ASSERT_EQ(table.round_nonce, request_seq); @@ -2785,36 +2641,27 @@ UT_TEST(test_93da_coordinator_begins_exact_four_node_sample_round) UT_ASSERT_EQ(table.transition_epoch, test_current_epoch); UT_ASSERT_EQ(table.record_generation, UINT64_C(8)); UT_ASSERT_EQ(table.source_feature_bitmap, UINT64_C(0)); - UT_ASSERT_EQ(table.target_feature_bitmap, - CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1); + UT_ASSERT_EQ(table.target_feature_bitmap, CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1); UT_ASSERT_EQ(table.rollback_feature_bitmap, UINT64_C(0)); UT_ASSERT_EQ(table.capability_sample_digest, UINT64_C(0)); UT_ASSERT_EQ(table.observed[0].node_id, UINT32_C(0)); - UT_ASSERT_EQ(table.observed[0].boot_id, - test_qvotec_self_incarnation); - UT_ASSERT_EQ(table.observed[0].admitted_incarnation, - test_qvotec_self_incarnation); - UT_ASSERT_EQ(table.observed[0].capability_word, - CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS); - UT_ASSERT_EQ(table.observed[0].transition_epoch, - test_current_epoch); + UT_ASSERT_EQ(table.observed[0].boot_id, test_qvotec_self_incarnation); + UT_ASSERT_EQ(table.observed[0].admitted_incarnation, test_qvotec_self_incarnation); + UT_ASSERT_EQ(table.observed[0].capability_word, CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS); + UT_ASSERT_EQ(table.observed[0].transition_epoch, test_current_epoch); UT_ASSERT_EQ(table.observed[0].record_generation, UINT64_C(8)); UT_ASSERT_EQ(test_send_calls[0], 0); for (node = 1; node < 4; node++) { UT_ASSERT_EQ(test_send_calls[node], 2); - UT_ASSERT_EQ(test_send_history_msg_types[node][0], - PGRAC_IC_MSG_SEMANTIC_ACTIVATION_ACK_V1); + UT_ASSERT_EQ(test_send_history_msg_types[node][0], PGRAC_IC_MSG_SEMANTIC_ACTIVATION_ACK_V1); UT_ASSERT_EQ(test_send_history_payload_lengths[node][0], CLUSTER_SEMANTIC_ACTIVATION_ACK_WIRE_BYTES); memset(&message, 0, sizeof(message)); - UT_ASSERT(cluster_semantic_activation_ack_wire_decode( - test_send_history_payloads[node][0], &message)); - UT_ASSERT_EQ(message.kind, - CLUSTER_SEMANTIC_ACTIVATION_ACK_KIND_REQUEST); - UT_ASSERT_EQ(message.stage, - CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_SAMPLE); - UT_ASSERT_EQ(message.result, - CLUSTER_SEMANTIC_ACTIVATION_ACK_RESULT_REQUEST); + UT_ASSERT(cluster_semantic_activation_ack_wire_decode(test_send_history_payloads[node][0], + &message)); + UT_ASSERT_EQ(message.kind, CLUSTER_SEMANTIC_ACTIVATION_ACK_KIND_REQUEST); + UT_ASSERT_EQ(message.stage, CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_SAMPLE); + UT_ASSERT_EQ(message.result, CLUSTER_SEMANTIC_ACTIVATION_ACK_RESULT_REQUEST); UT_ASSERT_EQ(message.reason, UINT32_C(0)); UT_ASSERT_EQ(message.coordinator_node, UINT32_C(0)); UT_ASSERT_EQ(message.member_node, (uint32)node); @@ -2822,8 +2669,7 @@ UT_TEST(test_93da_coordinator_begins_exact_four_node_sample_round) UT_ASSERT_EQ(message.record_generation, UINT64_C(8)); UT_ASSERT_EQ(message.round_nonce, request_seq); UT_ASSERT_EQ(message.source_feature_bitmap, UINT64_C(0)); - UT_ASSERT_EQ(message.target_feature_bitmap, - CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1); + UT_ASSERT_EQ(message.target_feature_bitmap, CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1); UT_ASSERT_EQ(message.rollback_feature_bitmap, UINT64_C(0)); UT_ASSERT_EQ(message.admitted_members_lo, UINT64_C(0x0f)); UT_ASSERT_EQ(message.admitted_members_hi, UINT64_C(0)); @@ -2832,43 +2678,34 @@ UT_TEST(test_93da_coordinator_begins_exact_four_node_sample_round) UT_ASSERT_EQ(message.admitted_incarnation, UINT64_C(0)); UT_ASSERT_EQ(message.capability_word, UINT32_C(0)); - UT_ASSERT_EQ(test_send_history_msg_types[node][1], - PGRAC_IC_MSG_SEMANTIC_ACTIVATION_ACK_V1); + UT_ASSERT_EQ(test_send_history_msg_types[node][1], PGRAC_IC_MSG_SEMANTIC_ACTIVATION_ACK_V1); UT_ASSERT_EQ(test_send_history_payload_lengths[node][1], CLUSTER_SEMANTIC_ACTIVATION_ACK_WIRE_BYTES); memset(&message, 0, sizeof(message)); - UT_ASSERT(cluster_semantic_activation_ack_wire_decode( - test_send_history_payloads[node][1], &message)); - UT_ASSERT_EQ(message.kind, - CLUSTER_SEMANTIC_ACTIVATION_ACK_KIND_ACK); - UT_ASSERT_EQ(message.stage, - CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_SAMPLE); - UT_ASSERT_EQ(message.result, - CLUSTER_SEMANTIC_ACTIVATION_ACK_RESULT_OK); - UT_ASSERT_EQ(message.reason, - CLUSTER_SEMANTIC_ACTIVATION_OK); + UT_ASSERT(cluster_semantic_activation_ack_wire_decode(test_send_history_payloads[node][1], + &message)); + UT_ASSERT_EQ(message.kind, CLUSTER_SEMANTIC_ACTIVATION_ACK_KIND_ACK); + UT_ASSERT_EQ(message.stage, CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_SAMPLE); + UT_ASSERT_EQ(message.result, CLUSTER_SEMANTIC_ACTIVATION_ACK_RESULT_OK); + UT_ASSERT_EQ(message.reason, CLUSTER_SEMANTIC_ACTIVATION_OK); UT_ASSERT_EQ(message.coordinator_node, UINT32_C(0)); UT_ASSERT_EQ(message.member_node, UINT32_C(0)); UT_ASSERT_EQ(message.transition_epoch, test_current_epoch); UT_ASSERT_EQ(message.record_generation, UINT64_C(8)); UT_ASSERT_EQ(message.round_nonce, request_seq); UT_ASSERT_EQ(message.source_feature_bitmap, UINT64_C(0)); - UT_ASSERT_EQ(message.target_feature_bitmap, - CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1); + UT_ASSERT_EQ(message.target_feature_bitmap, CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1); UT_ASSERT_EQ(message.rollback_feature_bitmap, UINT64_C(0)); UT_ASSERT_EQ(message.admitted_members_lo, UINT64_C(0x0f)); UT_ASSERT_EQ(message.admitted_members_hi, UINT64_C(0)); UT_ASSERT_EQ(message.capability_sample_digest, UINT64_C(0)); UT_ASSERT_EQ(message.boot_id, test_qvotec_self_incarnation); - UT_ASSERT_EQ(message.admitted_incarnation, - test_qvotec_self_incarnation); - UT_ASSERT_EQ(message.capability_word, - CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS); + UT_ASSERT_EQ(message.admitted_incarnation, test_qvotec_self_incarnation); + UT_ASSERT_EQ(message.capability_word, CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS); } cluster_semantic_activation_lmon_tick(); UT_ASSERT(semantic_activation_utility_mailbox_poll(&pending_request)); - UT_ASSERT(!semantic_activation_utility_mailbox_poll_completion( - request_seq, &refusal)); + UT_ASSERT(!semantic_activation_utility_mailbox_poll_completion(request_seq, &refusal)); for (node = 1; node < 4; node++) UT_ASSERT_EQ(test_send_calls[node], 2); test_gate_reset(); @@ -2887,11 +2724,9 @@ UT_TEST(test_93da0_early_sample_without_common_view_sends_one_directed_refusal) cluster_node_id = 3; test_gate_publish(2, 0, 0, test_current_epoch, false); test_membership_snapshot_valid = false; - test_local_capability_word - = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS; + test_local_capability_word = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS; test_peer_capability_word_sample_ok = true; - test_peer_capability_word - = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS; + test_peer_capability_word = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS; test_peer_capability_generation = 19; test_peer_capability_matches = true; test_send_results[0] = CLUSTER_IC_SEND_DONE; @@ -2905,11 +2740,9 @@ UT_TEST(test_93da0_early_sample_without_common_view_sends_one_directed_refusal) message.transition_epoch = test_current_epoch; message.record_generation = 1; message.round_nonce = UINT64_C(404); - message.target_feature_bitmap - = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1; + message.target_feature_bitmap = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1; message.admitted_members_lo = UINT64_C(0x0f); - UT_ASSERT(cluster_semantic_activation_ack_wire_encode( - &message, payload)); + UT_ASSERT(cluster_semantic_activation_ack_wire_encode(&message, payload)); memset(&envelope, 0, sizeof(envelope)); envelope.msg_type = PGRAC_IC_MSG_SEMANTIC_ACTIVATION_ACK_V1; envelope.source_node_id = 0; @@ -2925,19 +2758,15 @@ UT_TEST(test_93da0_early_sample_without_common_view_sends_one_directed_refusal) UT_ASSERT_EQ(semantic_activation_ack_local_pending_send.message.result, CLUSTER_SEMANTIC_ACTIVATION_ACK_RESULT_REFUSED); UT_ASSERT(!semantic_activation_ack_local_pending_send.invalidated); - UT_ASSERT_EQ( - semantic_activation_ack_local_pending_send.refusal_connection_generation, - UINT32_C(19)); - UT_ASSERT_EQ(semantic_activation_ack_local_pending_send.pending_members_lo, - UINT64_C(0)); + UT_ASSERT_EQ(semantic_activation_ack_local_pending_send.refusal_connection_generation, + UINT32_C(19)); + UT_ASSERT_EQ(semantic_activation_ack_local_pending_send.pending_members_lo, UINT64_C(0)); for (node = 0; node < 4; node++) UT_ASSERT_EQ(test_send_calls[node], node == 0 ? 1 : 0); - UT_ASSERT(cluster_semantic_activation_ack_wire_decode( - test_send_payloads[0], &sent)); + UT_ASSERT(cluster_semantic_activation_ack_wire_decode(test_send_payloads[0], &sent)); UT_ASSERT_EQ(sent.kind, CLUSTER_SEMANTIC_ACTIVATION_ACK_KIND_ACK); UT_ASSERT_EQ(sent.stage, message.stage); - UT_ASSERT_EQ(sent.result, - CLUSTER_SEMANTIC_ACTIVATION_ACK_RESULT_REFUSED); + UT_ASSERT_EQ(sent.result, CLUSTER_SEMANTIC_ACTIVATION_ACK_RESULT_REFUSED); UT_ASSERT_EQ(sent.reason, CLUSTER_SEMANTIC_ACTIVATION_RF_DEFERRED); UT_ASSERT_EQ(sent.coordinator_node, UINT32_C(0)); UT_ASSERT_EQ(sent.member_node, UINT32_C(3)); @@ -2946,12 +2775,10 @@ UT_TEST(test_93da0_early_sample_without_common_view_sends_one_directed_refusal) UT_ASSERT_EQ(sent.round_nonce, message.round_nonce); UT_ASSERT_EQ(sent.source_feature_bitmap, message.source_feature_bitmap); UT_ASSERT_EQ(sent.target_feature_bitmap, message.target_feature_bitmap); - UT_ASSERT_EQ(sent.rollback_feature_bitmap, - message.rollback_feature_bitmap); + UT_ASSERT_EQ(sent.rollback_feature_bitmap, message.rollback_feature_bitmap); UT_ASSERT_EQ(sent.admitted_members_lo, message.admitted_members_lo); UT_ASSERT_EQ(sent.admitted_members_hi, message.admitted_members_hi); - UT_ASSERT_EQ(sent.capability_sample_digest, - message.capability_sample_digest); + UT_ASSERT_EQ(sent.capability_sample_digest, message.capability_sample_digest); UT_ASSERT_EQ(sent.boot_id, UINT64_C(0)); UT_ASSERT_EQ(sent.admitted_incarnation, UINT64_C(0)); UT_ASSERT_EQ(sent.capability_word, UINT32_C(0)); @@ -2977,15 +2804,13 @@ UT_TEST(test_93da0_exact_refusal_completes_active_utility_as_deferred) test_gate_reset(); cluster_node_id = 0; - test_local_capability_word - = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS; + test_local_capability_word = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS; test_peer_capability_word_sample_ok = true; - test_peer_capability_word - = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS; + test_peer_capability_word = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS; test_peer_capability_generation = 19; test_peer_capability_matches = true; - UT_ASSERT(semantic_activation_utility_mailbox_submit( - CLUSTER_SEMANTIC_ENABLE_ALL, 0, r4, 0, 0, &request_seq)); + UT_ASSERT(semantic_activation_utility_mailbox_submit(CLUSTER_SEMANTIC_ENABLE_ALL, 0, r4, 0, 0, + &request_seq)); table = SemanticActivationAckTable; memset(table, 0, sizeof(*table)); @@ -3011,8 +2836,7 @@ UT_TEST(test_93da0_exact_refusal_completes_active_utility_as_deferred) message.round_nonce = request_seq + 1; message.target_feature_bitmap = r4; message.admitted_members_lo = UINT64_C(0x0f); - UT_ASSERT(cluster_semantic_activation_ack_wire_encode( - &message, payload)); + UT_ASSERT(cluster_semantic_activation_ack_wire_encode(&message, payload)); memset(&envelope, 0, sizeof(envelope)); envelope.msg_type = PGRAC_IC_MSG_SEMANTIC_ACTIVATION_ACK_V1; envelope.source_node_id = 3; @@ -3024,18 +2848,15 @@ UT_TEST(test_93da0_exact_refusal_completes_active_utility_as_deferred) cluster_semantic_activation_ack_handler(&envelope, payload); semantic_activation_ack_lmon_drain(); UT_ASSERT_EQ(table->expected_members_lo, UINT64_C(0x0f)); - UT_ASSERT(!semantic_activation_utility_mailbox_poll_completion( - request_seq, &refusal)); + UT_ASSERT(!semantic_activation_utility_mailbox_poll_completion(request_seq, &refusal)); message.round_nonce = request_seq; - UT_ASSERT(cluster_semantic_activation_ack_wire_encode( - &message, payload)); + UT_ASSERT(cluster_semantic_activation_ack_wire_encode(&message, payload)); cluster_semantic_activation_ack_handler(&envelope, payload); semantic_activation_ack_lmon_drain(); UT_ASSERT_EQ(table->expected_members_lo, UINT64_C(0)); UT_ASSERT_EQ(table->observed_members_lo, UINT64_C(0)); - UT_ASSERT(semantic_activation_utility_mailbox_poll_completion( - request_seq, &refusal)); + UT_ASSERT(semantic_activation_utility_mailbox_poll_completion(request_seq, &refusal)); UT_ASSERT_EQ(refusal.result, CLUSTER_SEMANTIC_ACTIVATION_RF_DEFERRED); UT_ASSERT_EQ(refusal.feature_bit, r4); test_gate_reset(); @@ -3061,17 +2882,14 @@ UT_TEST(test_93da1_member_retains_sample_ack_until_exact_request_arrives) test_initial_clean_snapshot.arbiter_node = 0; test_system_identifier = system_identifier; cluster_shared_data_dir = "/cluster-share"; - test_local_capability_word - = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS; + test_local_capability_word = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS; test_peer_capability_word_sample_ok = true; - test_peer_capability_word - = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS; + test_peer_capability_word = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS; test_peer_capability_generation = 19; test_peer_capability_matches = true; for (node = 0; node < 4; node++) { test_send_results[node] = CLUSTER_IC_SEND_DONE; - test_remote_admitted_incarnations[node] - = UINT64_C(0x100) + (uint64)node; + test_remote_admitted_incarnations[node] = UINT64_C(0x100) + (uint64)node; test_initial_clean_snapshot.admitted_incarnation[node] = test_remote_admitted_incarnations[node]; } @@ -3086,11 +2904,9 @@ UT_TEST(test_93da1_member_retains_sample_ack_until_exact_request_arrives) memset(descriptor.root_uuid, 0x6b, sizeof(descriptor.root_uuid)); descriptor.namespace_id = 1; descriptor.system_identifier = system_identifier; - UT_ASSERT(cluster_undo_root_descriptor_encode( - &descriptor, test_pgrd_candidate)); + UT_ASSERT(cluster_undo_root_descriptor_encode(&descriptor, test_pgrd_candidate)); test_pgrd_candidate_state = CLUSTER_UNDO_SMGR_ROOT_MIRROR_EXACT; - UT_ASSERT(semantic_activation_pgrd_snapshot_publish( - test_pgrd_candidate)); + UT_ASSERT(semantic_activation_pgrd_snapshot_publish(test_pgrd_candidate)); /* Node 1 can finish the directed SAMPLE request and fan out its ACK * before node 3 receives the coordinator's directed request. A * non-initial generation remains stale even with the same wire shape. */ @@ -3104,14 +2920,12 @@ UT_TEST(test_93da1_member_retains_sample_ack_until_exact_request_arrives) message.transition_epoch = test_current_epoch; message.record_generation = 8; message.round_nonce = UINT64_C(77); - message.target_feature_bitmap - = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1; + message.target_feature_bitmap = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1; message.admitted_members_lo = UINT64_C(0x0f); message.boot_id = test_remote_admitted_incarnations[1]; message.admitted_incarnation = message.boot_id; message.capability_word = test_peer_capability_word; - UT_ASSERT(cluster_semantic_activation_ack_wire_encode( - &message, payload)); + UT_ASSERT(cluster_semantic_activation_ack_wire_encode(&message, payload)); memset(&envelope, 0, sizeof(envelope)); envelope.msg_type = PGRAC_IC_MSG_SEMANTIC_ACTIVATION_ACK_V1; envelope.source_node_id = 1; @@ -3120,19 +2934,16 @@ UT_TEST(test_93da1_member_retains_sample_ack_until_exact_request_arrives) envelope.payload_length = sizeof(payload); cluster_semantic_activation_ack_handler(&envelope, payload); cluster_semantic_activation_lmon_tick(); - UT_ASSERT_EQ(semantic_activation_ack_local_stage_ahead.count, - UINT32_C(0)); + UT_ASSERT_EQ(semantic_activation_ack_local_stage_ahead.count, UINT32_C(0)); test_gate_publish(4, 0, 0, test_current_epoch, false); message.record_generation = 1; message.round_nonce = UINT64_C(78); - UT_ASSERT(cluster_semantic_activation_ack_wire_encode( - &message, payload)); + UT_ASSERT(cluster_semantic_activation_ack_wire_encode(&message, payload)); cluster_semantic_activation_ack_handler(&envelope, payload); cluster_semantic_activation_lmon_tick(); - UT_ASSERT_EQ(semantic_activation_ack_local_stage_ahead.count, - UINT32_C(1)); + UT_ASSERT_EQ(semantic_activation_ack_local_stage_ahead.count, UINT32_C(1)); UT_ASSERT(semantic_activation_ack_table_snapshot(&table)); UT_ASSERT_EQ(table.expected_members_lo, UINT64_C(0)); @@ -3145,45 +2956,38 @@ UT_TEST(test_93da1_member_retains_sample_ack_until_exact_request_arrives) message.transition_epoch = test_current_epoch; message.record_generation = 1; message.round_nonce = UINT64_C(78); - message.target_feature_bitmap - = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1; + message.target_feature_bitmap = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1; message.admitted_members_lo = UINT64_C(0x0f); - UT_ASSERT(cluster_semantic_activation_ack_wire_encode( - &message, payload)); + UT_ASSERT(cluster_semantic_activation_ack_wire_encode(&message, payload)); envelope.source_node_id = 0; cluster_semantic_activation_ack_handler(&envelope, payload); cluster_semantic_activation_lmon_tick(); - UT_ASSERT_EQ(semantic_activation_ack_local_stage_ahead.count, - UINT32_C(0)); + UT_ASSERT_EQ(semantic_activation_ack_local_stage_ahead.count, UINT32_C(0)); UT_ASSERT(semantic_activation_ack_table_snapshot(&table)); - UT_ASSERT_EQ(table.stage, - CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_SAMPLE); + UT_ASSERT_EQ(table.stage, CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_SAMPLE); UT_ASSERT_EQ(table.observed_members_lo, UINT64_C(0x0a)); UT_ASSERT(semantic_activation_ack_matches( - &table.observed[1], - &(SemanticActivationAckTuple){ - .node_id = 1, - .boot_id = test_remote_admitted_incarnations[1], - .admitted_incarnation = test_remote_admitted_incarnations[1], - .control_connection_generation = 19, - .capability_word = test_peer_capability_word, - .capability_generation = 19, - .transition_epoch = test_current_epoch, - .record_generation = 1, - })); + &table.observed[1], &(SemanticActivationAckTuple){ + .node_id = 1, + .boot_id = test_remote_admitted_incarnations[1], + .admitted_incarnation = test_remote_admitted_incarnations[1], + .control_connection_generation = 19, + .capability_word = test_peer_capability_word, + .capability_generation = 19, + .transition_epoch = test_current_epoch, + .record_generation = 1, + })); test_gate_reset(); } UT_TEST(test_93da2_member_retains_next_round_sample_ack_until_exact_request_arrives) { - const uint32 resource_x_caps - = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS - | PGRAC_IC_HELLO_CAP_GCS_RESOURCE_X_CONVERT_V1; + const uint32 resource_x_caps = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS + | PGRAC_IC_HELLO_CAP_GCS_RESOURCE_X_CONVERT_V1; const uint64 r4 = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1; - const uint64 target - = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1 - | CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1; + const uint64 target = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1 + | CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1; ClusterSemanticActivationAckTableV1 *table; ClusterSemanticActivationAckWireV1 message; ClusterICEnvelope envelope; @@ -3199,8 +3003,7 @@ UT_TEST(test_93da2_member_retains_next_round_sample_ack_until_exact_request_arri test_peer_capability_generation = 19; test_peer_capability_matches = true; for (node = 0; node < 4; node++) - test_remote_admitted_incarnations[node] - = UINT64_C(0x100) + (uint64)node; + test_remote_admitted_incarnations[node] = UINT64_C(0x100) + (uint64)node; table = SemanticActivationAckTable; memset(table, 0, sizeof(*table)); @@ -3217,15 +3020,12 @@ UT_TEST(test_93da2_member_retains_next_round_sample_ack_until_exact_request_arri table->target_feature_bitmap = r4; for (node = 0; node < 4; node++) { if (node == cluster_node_id) { - UT_ASSERT(semantic_activation_ack_self_tuple( - node, resource_x_caps, test_current_epoch, 1, - &table->expected[node])); + UT_ASSERT(semantic_activation_ack_self_tuple(node, resource_x_caps, test_current_epoch, + 1, &table->expected[node])); } else { table->expected[node].node_id = (uint32)node; - table->expected[node].boot_id - = test_remote_admitted_incarnations[node]; - table->expected[node].admitted_incarnation - = test_remote_admitted_incarnations[node]; + table->expected[node].boot_id = test_remote_admitted_incarnations[node]; + table->expected[node].admitted_incarnation = test_remote_admitted_incarnations[node]; table->expected[node].control_connection_generation = 19; table->expected[node].capability_word = resource_x_caps; table->expected[node].capability_generation = 19; @@ -3252,8 +3052,7 @@ UT_TEST(test_93da2_member_retains_next_round_sample_ack_until_exact_request_arri message.boot_id = test_remote_admitted_incarnations[1]; message.admitted_incarnation = message.boot_id; message.capability_word = resource_x_caps; - UT_ASSERT(cluster_semantic_activation_ack_wire_encode( - &message, payload)); + UT_ASSERT(cluster_semantic_activation_ack_wire_encode(&message, payload)); memset(&envelope, 0, sizeof(envelope)); envelope.msg_type = PGRAC_IC_MSG_SEMANTIC_ACTIVATION_ACK_V1; envelope.source_node_id = 1; @@ -3263,11 +3062,9 @@ UT_TEST(test_93da2_member_retains_next_round_sample_ack_until_exact_request_arri cluster_semantic_activation_ack_handler(&envelope, payload); cluster_semantic_activation_lmon_tick(); - UT_ASSERT_EQ(semantic_activation_ack_local_stage_ahead.count, - UINT32_C(1)); + UT_ASSERT_EQ(semantic_activation_ack_local_stage_ahead.count, UINT32_C(1)); UT_ASSERT(semantic_activation_ack_table_snapshot(table)); - UT_ASSERT_EQ(table->stage, - CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_OPEN_APPLIED); + UT_ASSERT_EQ(table->stage, CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_OPEN_APPLIED); UT_ASSERT_EQ(table->record_generation, UINT64_C(1)); memset(&message, 0, sizeof(message)); @@ -3282,17 +3079,14 @@ UT_TEST(test_93da2_member_retains_next_round_sample_ack_until_exact_request_arri message.source_feature_bitmap = r4; message.target_feature_bitmap = target; message.admitted_members_lo = UINT64_C(0x0f); - UT_ASSERT(cluster_semantic_activation_ack_wire_encode( - &message, payload)); + UT_ASSERT(cluster_semantic_activation_ack_wire_encode(&message, payload)); envelope.source_node_id = 0; cluster_semantic_activation_ack_handler(&envelope, payload); cluster_semantic_activation_lmon_tick(); - UT_ASSERT_EQ(semantic_activation_ack_local_stage_ahead.count, - UINT32_C(0)); + UT_ASSERT_EQ(semantic_activation_ack_local_stage_ahead.count, UINT32_C(0)); UT_ASSERT(semantic_activation_ack_table_snapshot(table)); - UT_ASSERT_EQ(table->stage, - CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_SAMPLE); + UT_ASSERT_EQ(table->stage, CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_SAMPLE); UT_ASSERT_EQ(table->record_generation, UINT64_C(2)); UT_ASSERT_EQ(table->observed_members_lo, UINT64_C(0x0a)); UT_ASSERT_EQ(table->source_feature_bitmap, r4); @@ -3302,13 +3096,11 @@ UT_TEST(test_93da2_member_retains_next_round_sample_ack_until_exact_request_arri UT_TEST(test_93da2a_next_sample_waits_for_exact_local_open_publish) { - const uint32 resource_x_caps - = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS - | PGRAC_IC_HELLO_CAP_GCS_RESOURCE_X_CONVERT_V1; + const uint32 resource_x_caps = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS + | PGRAC_IC_HELLO_CAP_GCS_RESOURCE_X_CONVERT_V1; const uint64 r4 = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1; - const uint64 target - = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1 - | CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1; + const uint64 target = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1 + | CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1; ClusterSemanticActivationAckTableV1 *table; ClusterSemanticActivationAckTableV1 before_duplicate; ClusterSemanticActivationAckWireV1 message; @@ -3328,8 +3120,7 @@ UT_TEST(test_93da2a_next_sample_waits_for_exact_local_open_publish) test_peer_capability_generation = 19; test_peer_capability_matches = true; for (node = 0; node < 4; node++) { - test_remote_admitted_incarnations[node] - = UINT64_C(0x100) + (uint64)node; + test_remote_admitted_incarnations[node] = UINT64_C(0x100) + (uint64)node; test_send_results[node] = CLUSTER_IC_SEND_DONE; } @@ -3350,15 +3141,12 @@ UT_TEST(test_93da2a_next_sample_waits_for_exact_local_open_publish) table->capability_sample_digest = UINT64_C(0x3141592653589793); for (node = 0; node < 4; node++) { if (node == cluster_node_id) - UT_ASSERT(semantic_activation_ack_self_tuple( - node, resource_x_caps, test_current_epoch, 3, - &table->expected[node])); + UT_ASSERT(semantic_activation_ack_self_tuple(node, resource_x_caps, test_current_epoch, + 3, &table->expected[node])); else { table->expected[node].node_id = (uint32)node; - table->expected[node].boot_id - = test_remote_admitted_incarnations[node]; - table->expected[node].admitted_incarnation - = test_remote_admitted_incarnations[node]; + table->expected[node].boot_id = test_remote_admitted_incarnations[node]; + table->expected[node].admitted_incarnation = test_remote_admitted_incarnations[node]; table->expected[node].control_connection_generation = 19; table->expected[node].capability_word = resource_x_caps; table->expected[node].capability_generation = 19; @@ -3394,16 +3182,13 @@ UT_TEST(test_93da2a_next_sample_waits_for_exact_local_open_publish) message.member_node = (uint32)peer; message.boot_id = test_remote_admitted_incarnations[peer]; message.admitted_incarnation = message.boot_id; - UT_ASSERT(cluster_semantic_activation_ack_wire_encode( - &message, payload)); + UT_ASSERT(cluster_semantic_activation_ack_wire_encode(&message, payload)); envelope.source_node_id = (uint32)peer; cluster_semantic_activation_ack_handler(&envelope, payload); semantic_activation_ack_lmon_drain(); } - UT_ASSERT_EQ(semantic_activation_ack_local_stage_ahead.count, - UINT32_C(2)); - UT_ASSERT_EQ(table->stage, - CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_OPEN_APPLIED); + UT_ASSERT_EQ(semantic_activation_ack_local_stage_ahead.count, UINT32_C(2)); + UT_ASSERT_EQ(table->stage, CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_OPEN_APPLIED); message.kind = CLUSTER_SEMANTIC_ACTIVATION_ACK_KIND_REQUEST; message.result = CLUSTER_SEMANTIC_ACTIVATION_ACK_RESULT_REQUEST; @@ -3412,14 +3197,12 @@ UT_TEST(test_93da2a_next_sample_waits_for_exact_local_open_publish) message.boot_id = 0; message.admitted_incarnation = 0; message.capability_word = 0; - UT_ASSERT(cluster_semantic_activation_ack_wire_encode( - &message, payload)); + UT_ASSERT(cluster_semantic_activation_ack_wire_encode(&message, payload)); envelope.source_node_id = 0; cluster_semantic_activation_ack_handler(&envelope, payload); semantic_activation_ack_lmon_drain(); UT_ASSERT(semantic_activation_ack_local_request_ahead.valid); - UT_ASSERT_EQ(table->stage, - CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_OPEN_APPLIED); + UT_ASSERT_EQ(table->stage, CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_OPEN_APPLIED); for (node = 0; node < 4; node++) UT_ASSERT_EQ(test_send_calls[node], 0); @@ -3429,10 +3212,8 @@ UT_TEST(test_93da2a_next_sample_waits_for_exact_local_open_publish) test_gate_publish(4, r4, 3, test_current_epoch, false); semantic_activation_ack_lmon_drain(); UT_ASSERT(!semantic_activation_ack_local_request_ahead.valid); - UT_ASSERT_EQ(semantic_activation_ack_local_stage_ahead.count, - UINT32_C(0)); - UT_ASSERT_EQ(table->stage, - CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_SAMPLE); + UT_ASSERT_EQ(semantic_activation_ack_local_stage_ahead.count, UINT32_C(0)); + UT_ASSERT_EQ(table->stage, CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_SAMPLE); UT_ASSERT_EQ(table->record_generation, UINT64_C(4)); UT_ASSERT_EQ(table->observed_members_lo, UINT64_C(0x0e)); for (node = 0; node < 4; node++) @@ -3451,13 +3232,11 @@ UT_TEST(test_93da2a_next_sample_waits_for_exact_local_open_publish) UT_TEST(test_93da3_member_retains_barrier_request_and_fans_out_once) { - const uint32 resource_x_caps - = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS - | PGRAC_IC_HELLO_CAP_GCS_RESOURCE_X_CONVERT_V1; + const uint32 resource_x_caps = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS + | PGRAC_IC_HELLO_CAP_GCS_RESOURCE_X_CONVERT_V1; const uint64 r4 = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1; - const uint64 target - = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1 - | CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1; + const uint64 target = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1 + | CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1; ClusterSemanticActivationAckTableV1 *table; ClusterSemanticActivationAckTableV1 complete; ClusterSemanticActivationAckWireV1 barrier_request; @@ -3479,8 +3258,7 @@ UT_TEST(test_93da3_member_retains_barrier_request_and_fans_out_once) test_peer_capability_generation = 19; test_peer_capability_matches = true; for (node = 0; node < 4; node++) - test_remote_admitted_incarnations[node] - = UINT64_C(0x100) + (uint64)node; + test_remote_admitted_incarnations[node] = UINT64_C(0x100) + (uint64)node; table = SemanticActivationAckTable; memset(table, 0, sizeof(*table)); @@ -3499,15 +3277,12 @@ UT_TEST(test_93da3_member_retains_barrier_request_and_fans_out_once) memset(&tuple, 0, sizeof(tuple)); if (node == cluster_node_id) - UT_ASSERT(semantic_activation_ack_self_tuple( - node, resource_x_caps, test_current_epoch, 2, - &tuple)); + UT_ASSERT(semantic_activation_ack_self_tuple(node, resource_x_caps, test_current_epoch, + 2, &tuple)); else { tuple.node_id = (uint32)node; - tuple.boot_id - = test_remote_admitted_incarnations[node]; - tuple.admitted_incarnation - = test_remote_admitted_incarnations[node]; + tuple.boot_id = test_remote_admitted_incarnations[node]; + tuple.admitted_incarnation = test_remote_admitted_incarnations[node]; tuple.control_connection_generation = 19; tuple.capability_word = resource_x_caps; tuple.capability_generation = 19; @@ -3525,15 +3300,12 @@ UT_TEST(test_93da3_member_retains_barrier_request_and_fans_out_once) complete.observed_members_lo = UINT64_C(0x0f); for (node = 0; node < 4; node++) { if (node == cluster_node_id) - UT_ASSERT(semantic_activation_ack_self_tuple( - node, resource_x_caps, test_current_epoch, 2, - &complete.observed[node])); + UT_ASSERT(semantic_activation_ack_self_tuple(node, resource_x_caps, test_current_epoch, + 2, &complete.observed[node])); else { complete.observed[node].node_id = (uint32)node; - complete.observed[node].boot_id - = test_remote_admitted_incarnations[node]; - complete.observed[node].admitted_incarnation - = test_remote_admitted_incarnations[node]; + complete.observed[node].boot_id = test_remote_admitted_incarnations[node]; + complete.observed[node].admitted_incarnation = test_remote_admitted_incarnations[node]; complete.observed[node].control_connection_generation = 19; complete.observed[node].capability_word = resource_x_caps; complete.observed[node].capability_generation = 19; @@ -3547,8 +3319,7 @@ UT_TEST(test_93da3_member_retains_barrier_request_and_fans_out_once) memset(&barrier_request, 0, sizeof(barrier_request)); barrier_request.kind = CLUSTER_SEMANTIC_ACTIVATION_ACK_KIND_REQUEST; barrier_request.stage = CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_BARRIER; - barrier_request.result - = CLUSTER_SEMANTIC_ACTIVATION_ACK_RESULT_REQUEST; + barrier_request.result = CLUSTER_SEMANTIC_ACTIVATION_ACK_RESULT_REQUEST; barrier_request.coordinator_node = table->coordinator_node; barrier_request.member_node = UINT32_C(3); barrier_request.transition_epoch = table->transition_epoch; @@ -3556,13 +3327,11 @@ UT_TEST(test_93da3_member_retains_barrier_request_and_fans_out_once) barrier_request.round_nonce = table->round_nonce; barrier_request.source_feature_bitmap = table->source_feature_bitmap; barrier_request.target_feature_bitmap = table->target_feature_bitmap; - barrier_request.rollback_feature_bitmap - = table->rollback_feature_bitmap; + barrier_request.rollback_feature_bitmap = table->rollback_feature_bitmap; barrier_request.admitted_members_lo = table->expected_members_lo; barrier_request.admitted_members_hi = table->expected_members_hi; barrier_request.capability_sample_digest = digest; - UT_ASSERT(cluster_semantic_activation_ack_wire_encode( - &barrier_request, payload)); + UT_ASSERT(cluster_semantic_activation_ack_wire_encode(&barrier_request, payload)); memset(&envelope, 0, sizeof(envelope)); envelope.msg_type = PGRAC_IC_MSG_SEMANTIC_ACTIVATION_ACK_V1; envelope.source_node_id = 0; @@ -3573,8 +3342,7 @@ UT_TEST(test_93da3_member_retains_barrier_request_and_fans_out_once) semantic_activation_ack_lmon_drain(); UT_ASSERT(semantic_activation_ack_local_request_ahead.valid); - UT_ASSERT_EQ(table->stage, - CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_SAMPLE); + UT_ASSERT_EQ(table->stage, CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_SAMPLE); UT_ASSERT_EQ(table->observed_members_lo, UINT64_C(0x0b)); UT_ASSERT_EQ(test_drain_request_calls, 0); for (node = 0; node < 4; node++) @@ -3605,8 +3373,7 @@ UT_TEST(test_93da3_member_retains_barrier_request_and_fans_out_once) message.boot_id = test_remote_admitted_incarnations[2]; message.admitted_incarnation = message.boot_id; message.capability_word = resource_x_caps; - UT_ASSERT(cluster_semantic_activation_ack_wire_encode( - &message, payload)); + UT_ASSERT(cluster_semantic_activation_ack_wire_encode(&message, payload)); envelope.source_node_id = 2; for (node = 0; node < 4; node++) test_send_results[node] = CLUSTER_IC_SEND_DONE; @@ -3614,10 +3381,8 @@ UT_TEST(test_93da3_member_retains_barrier_request_and_fans_out_once) semantic_activation_ack_lmon_drain(); UT_ASSERT(!semantic_activation_ack_local_request_ahead.valid); - UT_ASSERT_EQ(table->stage, - CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_BARRIER); - UT_ASSERT_EQ(table->flags, - CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID); + UT_ASSERT_EQ(table->stage, CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_BARRIER); + UT_ASSERT_EQ(table->flags, CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID); UT_ASSERT_EQ(table->observed_members_lo, UINT64_C(0)); UT_ASSERT_EQ(table->record_generation, UINT64_C(2)); for (node = 0; node < 4; node++) @@ -3629,8 +3394,7 @@ UT_TEST(test_93da3_member_retains_barrier_request_and_fans_out_once) * digest. Only that completion may publish the self row and fan out. */ cluster_semantic_activation_lmon_tick(); memset(&read_request, 0, sizeof(read_request)); - UT_ASSERT(cluster_semantic_activation_qvotec_poll_record_read( - &read_request)); + UT_ASSERT(cluster_semantic_activation_qvotec_poll_record_read(&read_request)); /* The member can complete its first read before the current Resource-X * PREPARE image wins the voting majority. That completed-but-stale * result must be consumed without changing the gate or ACK table, and @@ -3641,25 +3405,20 @@ UT_TEST(test_93da3_member_retains_barrier_request_and_fans_out_once) prepare.record_generation = 1; prepare.transition_epoch = test_current_epoch; prepare.coordinator_node = 0; - prepare.coordinator_incarnation - = table->expected[0].admitted_incarnation; + prepare.coordinator_incarnation = table->expected[0].admitted_incarnation; prepare.admitted_members_lo = UINT64_C(0x0f); prepare.source_feature_bitmap = r4; prepare.target_feature_bitmap = r4; prepare.capability_sample_digest = digest; - UT_ASSERT(cluster_semantic_activation_record_encode( - &prepare, record_bytes)); + UT_ASSERT(cluster_semantic_activation_record_encode(&prepare, record_bytes)); UT_ASSERT(cluster_semantic_activation_qvotec_complete_record_read( - read_request.request_seq, CLUSTER_SEMANTIC_ACTIVATION_OK, - false, record_bytes)); + read_request.request_seq, CLUSTER_SEMANTIC_ACTIVATION_OK, false, record_bytes)); cluster_semantic_activation_lmon_tick(); UT_ASSERT_EQ(semantic_activation_lmon_record_read_seq, UINT64_C(0)); - UT_ASSERT_EQ(pg_atomic_read_u64( - test_gate_u64(TEST_GATE_RECORD_GENERATION_OFFSET)), UINT64_C(1)); - UT_ASSERT_EQ(pg_atomic_read_u32( - test_gate_u32(TEST_GATE_CLOSED_OFFSET)), UINT32_C(0)); - UT_ASSERT_EQ(table->stage, - CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_BARRIER); + UT_ASSERT_EQ(pg_atomic_read_u64(test_gate_u64(TEST_GATE_RECORD_GENERATION_OFFSET)), + UINT64_C(1)); + UT_ASSERT_EQ(pg_atomic_read_u32(test_gate_u32(TEST_GATE_CLOSED_OFFSET)), UINT32_C(0)); + UT_ASSERT_EQ(table->stage, CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_BARRIER); UT_ASSERT_EQ(table->observed_members_lo, UINT64_C(0)); for (node = 0; node < 4; node++) UT_ASSERT_EQ(test_send_calls[node], 0); @@ -3670,24 +3429,20 @@ UT_TEST(test_93da3_member_retains_barrier_request_and_fans_out_once) cluster_semantic_activation_lmon_tick(); memset(&read_request, 0, sizeof(read_request)); - UT_ASSERT(cluster_semantic_activation_qvotec_poll_record_read( - &read_request)); + UT_ASSERT(cluster_semantic_activation_qvotec_poll_record_read(&read_request)); memset(&prepare, 0, sizeof(prepare)); prepare.phase = CLUSTER_SEMANTIC_PHASE_PREPARE; prepare.record_generation = 2; prepare.transition_epoch = test_current_epoch; prepare.coordinator_node = 0; - prepare.coordinator_incarnation - = table->expected[0].admitted_incarnation; + prepare.coordinator_incarnation = table->expected[0].admitted_incarnation; prepare.admitted_members_lo = UINT64_C(0x0f); prepare.source_feature_bitmap = r4; prepare.target_feature_bitmap = target; prepare.capability_sample_digest = digest; - UT_ASSERT(cluster_semantic_activation_record_encode( - &prepare, record_bytes)); + UT_ASSERT(cluster_semantic_activation_record_encode(&prepare, record_bytes)); UT_ASSERT(cluster_semantic_activation_qvotec_complete_record_read( - read_request.request_seq, CLUSTER_SEMANTIC_ACTIVATION_OK, - false, record_bytes)); + read_request.request_seq, CLUSTER_SEMANTIC_ACTIVATION_OK, false, record_bytes)); test_resource_x_gate_snapshot_valid = true; test_resource_x_gate_snapshot.phase = RESOURCE_X_GATE_FROZEN; test_resource_x_gate_snapshot.formation = 17; @@ -3700,34 +3455,28 @@ UT_TEST(test_93da3_member_retains_barrier_request_and_fans_out_once) test_resource_x_cutover_digest = UINT64_C(0xa55a9911); cluster_semantic_activation_lmon_tick(); - UT_ASSERT_EQ(pg_atomic_read_u32( - test_gate_u32(TEST_GATE_CLOSED_OFFSET)), UINT32_C(1)); - UT_ASSERT_EQ(pg_atomic_read_u64( - test_gate_u64(TEST_GATE_RECORD_GENERATION_OFFSET)), UINT64_C(2)); + UT_ASSERT_EQ(pg_atomic_read_u32(test_gate_u32(TEST_GATE_CLOSED_OFFSET)), UINT32_C(1)); + UT_ASSERT_EQ(pg_atomic_read_u64(test_gate_u64(TEST_GATE_RECORD_GENERATION_OFFSET)), + UINT64_C(2)); UT_ASSERT_EQ(table->observed_members_lo, UINT64_C(0x08)); for (node = 0; node < 3; node++) { ClusterSemanticActivationAckWireV1 sent; UT_ASSERT_EQ(test_send_calls[node], 1); - UT_ASSERT(cluster_semantic_activation_ack_wire_decode( - test_send_payloads[node], &sent)); - UT_ASSERT_EQ(sent.kind, - CLUSTER_SEMANTIC_ACTIVATION_ACK_KIND_ACK); - UT_ASSERT_EQ(sent.stage, - CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_BARRIER); + UT_ASSERT(cluster_semantic_activation_ack_wire_decode(test_send_payloads[node], &sent)); + UT_ASSERT_EQ(sent.kind, CLUSTER_SEMANTIC_ACTIVATION_ACK_KIND_ACK); + UT_ASSERT_EQ(sent.stage, CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_BARRIER); UT_ASSERT_EQ(sent.member_node, UINT32_C(3)); } UT_ASSERT_EQ(test_send_calls[3], 0); /* A duplicate after exact consumption is idempotent: no second local * callback or positive fan-out, and the installed table stays current. */ - UT_ASSERT(cluster_semantic_activation_ack_wire_encode( - &barrier_request, payload)); + UT_ASSERT(cluster_semantic_activation_ack_wire_encode(&barrier_request, payload)); envelope.source_node_id = 0; cluster_semantic_activation_ack_handler(&envelope, payload); semantic_activation_ack_lmon_drain(); - UT_ASSERT_EQ(table->stage, - CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_BARRIER); + UT_ASSERT_EQ(table->stage, CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_BARRIER); UT_ASSERT_EQ(table->observed_members_lo, UINT64_C(0x08)); UT_ASSERT_EQ(test_drain_request_calls, 0); for (node = 0; node < 3; node++) @@ -3746,8 +3495,7 @@ UT_TEST(test_93da3_member_retains_barrier_request_and_fans_out_once) test_peer_capability_generation = 19; test_peer_capability_matches = true; for (node = 0; node < 4; node++) - test_remote_admitted_incarnations[node] - = UINT64_C(0x100) + (uint64)node; + test_remote_admitted_incarnations[node] = UINT64_C(0x100) + (uint64)node; table = SemanticActivationAckTable; *table = complete; @@ -3759,8 +3507,7 @@ UT_TEST(test_93da3_member_retains_barrier_request_and_fans_out_once) memset(&table->observed[2], 0, sizeof(table->observed[2])); barrier_request.round_nonce = UINT64_C(79); - UT_ASSERT(cluster_semantic_activation_ack_wire_encode( - &barrier_request, payload)); + UT_ASSERT(cluster_semantic_activation_ack_wire_encode(&barrier_request, payload)); envelope.source_node_id = 0; cluster_semantic_activation_ack_handler(&envelope, payload); semantic_activation_ack_lmon_drain(); @@ -3768,21 +3515,17 @@ UT_TEST(test_93da3_member_retains_barrier_request_and_fans_out_once) if (drift == 0) { barrier_request.round_nonce++; - UT_ASSERT(cluster_semantic_activation_ack_wire_encode( - &barrier_request, payload)); + UT_ASSERT(cluster_semantic_activation_ack_wire_encode(&barrier_request, payload)); cluster_semantic_activation_ack_handler(&envelope, payload); } else if (drift == 1) - test_gate_publish( - 4, r4, 1, test_current_epoch + 1, false); + test_gate_publish(4, r4, 1, test_current_epoch + 1, false); else test_gate_publish(4, r4, 9, test_current_epoch, false); semantic_activation_ack_lmon_drain(); UT_ASSERT(!semantic_activation_ack_local_request_ahead.valid); UT_ASSERT_EQ(table->expected_members_lo, UINT64_C(0)); - UT_ASSERT_EQ( - semantic_activation_ack_local_pending_send.pending_members_lo, - UINT64_C(0)); + UT_ASSERT_EQ(semantic_activation_ack_local_pending_send.pending_members_lo, UINT64_C(0)); for (node = 0; node < 4; node++) UT_ASSERT_EQ(test_send_calls[node], 0); } @@ -3791,13 +3534,11 @@ UT_TEST(test_93da3_member_retains_barrier_request_and_fans_out_once) UT_TEST(test_93da4_member_direct_barrier_request_waits_for_lifecycle) { - const uint32 resource_x_caps - = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS - | PGRAC_IC_HELLO_CAP_GCS_RESOURCE_X_CONVERT_V1; + const uint32 resource_x_caps = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS + | PGRAC_IC_HELLO_CAP_GCS_RESOURCE_X_CONVERT_V1; const uint64 r4 = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1; - const uint64 target - = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1 - | CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1; + const uint64 target = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1 + | CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1; ClusterSemanticActivationAckTableV1 *table; ClusterSemanticActivationAckWireV1 request; ClusterICEnvelope envelope; @@ -3814,8 +3555,7 @@ UT_TEST(test_93da4_member_direct_barrier_request_waits_for_lifecycle) test_peer_capability_generation = 19; test_peer_capability_matches = true; for (node = 0; node < 4; node++) { - test_remote_admitted_incarnations[node] - = UINT64_C(0x100) + (uint64)node; + test_remote_admitted_incarnations[node] = UINT64_C(0x100) + (uint64)node; test_send_results[node] = CLUSTER_IC_SEND_DONE; } @@ -3838,8 +3578,8 @@ UT_TEST(test_93da4_member_direct_barrier_request_waits_for_lifecycle) memset(&tuple, 0, sizeof(tuple)); if (node == cluster_node_id) - UT_ASSERT(semantic_activation_ack_self_tuple( - node, resource_x_caps, test_current_epoch, 2, &tuple)); + UT_ASSERT(semantic_activation_ack_self_tuple(node, resource_x_caps, test_current_epoch, + 2, &tuple)); else { tuple.node_id = (uint32)node; tuple.boot_id = test_remote_admitted_incarnations[node]; @@ -3868,8 +3608,7 @@ UT_TEST(test_93da4_member_direct_barrier_request_waits_for_lifecycle) request.target_feature_bitmap = target; request.admitted_members_lo = table->expected_members_lo; request.capability_sample_digest = digest; - UT_ASSERT(cluster_semantic_activation_ack_wire_encode( - &request, payload)); + UT_ASSERT(cluster_semantic_activation_ack_wire_encode(&request, payload)); memset(&envelope, 0, sizeof(envelope)); envelope.msg_type = PGRAC_IC_MSG_SEMANTIC_ACTIVATION_ACK_V1; envelope.source_node_id = 0; @@ -3879,8 +3618,7 @@ UT_TEST(test_93da4_member_direct_barrier_request_waits_for_lifecycle) cluster_semantic_activation_ack_handler(&envelope, payload); semantic_activation_ack_lmon_drain(); - UT_ASSERT_EQ(table->stage, - CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_BARRIER); + UT_ASSERT_EQ(table->stage, CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_BARRIER); UT_ASSERT_EQ(table->observed_members_lo, UINT64_C(0)); for (node = 0; node < 4; node++) { UT_ASSERT_EQ(test_send_calls[node], 0); @@ -3924,55 +3662,55 @@ UT_TEST(test_g3_ack_complete_matches_round_binding) /* COMPLETE + round binding at PREPARED satisfies any minimum stage up * to PREPARED (create proof: SAMPLE; activate proof: PREPARED). */ UT_ASSERT(cluster_semantic_activation_ack_complete_matches( - 3, 7, UINT64_C(0x0f), 0, UINT64_C(1), UINT64_C(1) | bit22, - UINT64_C(0xabcd), CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_SAMPLE)); + 3, 7, UINT64_C(0x0f), 0, UINT64_C(1), UINT64_C(1) | bit22, UINT64_C(0xabcd), + CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_SAMPLE)); UT_ASSERT(cluster_semantic_activation_ack_complete_matches( - 3, 7, UINT64_C(0x0f), 0, UINT64_C(1), UINT64_C(1) | bit22, - UINT64_C(0xabcd), CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_PREPARED)); + 3, 7, UINT64_C(0x0f), 0, UINT64_C(1), UINT64_C(1) | bit22, UINT64_C(0xabcd), + CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_PREPARED)); /* Stage below the demanded minimum -> false (W6 clause 3: the activate * proof needs the PREPARED-stage all-member ACK, the CLOSED binding). */ table->stage = CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_SAMPLE; UT_ASSERT(!cluster_semantic_activation_ack_complete_matches( - 3, 7, UINT64_C(0x0f), 0, UINT64_C(1), UINT64_C(1) | bit22, - UINT64_C(0xabcd), CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_PREPARED)); + 3, 7, UINT64_C(0x0f), 0, UINT64_C(1), UINT64_C(1) | bit22, UINT64_C(0xabcd), + CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_PREPARED)); /* ...but the create proof's SAMPLE minimum still holds at SAMPLE. */ UT_ASSERT(cluster_semantic_activation_ack_complete_matches( - 3, 7, UINT64_C(0x0f), 0, UINT64_C(1), UINT64_C(1) | bit22, - UINT64_C(0xabcd), CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_SAMPLE)); + 3, 7, UINT64_C(0x0f), 0, UINT64_C(1), UINT64_C(1) | bit22, UINT64_C(0xabcd), + CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_SAMPLE)); table->stage = CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_PREPARED; /* Invalid minimum stage -> false (fail-closed). */ UT_ASSERT(!cluster_semantic_activation_ack_complete_matches( - 3, 7, UINT64_C(0x0f), 0, UINT64_C(1), UINT64_C(1) | bit22, - UINT64_C(0xabcd), CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_INVALID)); + 3, 7, UINT64_C(0x0f), 0, UINT64_C(1), UINT64_C(1) | bit22, UINT64_C(0xabcd), + CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_INVALID)); /* Not COMPLETE -> false. */ table->flags = 0; UT_ASSERT(!cluster_semantic_activation_ack_complete_matches( - 3, 7, UINT64_C(0x0f), 0, UINT64_C(1), UINT64_C(1) | bit22, - UINT64_C(0xabcd), CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_SAMPLE)); + 3, 7, UINT64_C(0x0f), 0, UINT64_C(1), UINT64_C(1) | bit22, UINT64_C(0xabcd), + CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_SAMPLE)); table->flags = CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE; /* Round binding: wrong epoch / generation / members / digest -> false. */ UT_ASSERT(!cluster_semantic_activation_ack_complete_matches( - 4, 7, UINT64_C(0x0f), 0, UINT64_C(1), UINT64_C(1) | bit22, - UINT64_C(0xabcd), CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_SAMPLE)); + 4, 7, UINT64_C(0x0f), 0, UINT64_C(1), UINT64_C(1) | bit22, UINT64_C(0xabcd), + CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_SAMPLE)); UT_ASSERT(!cluster_semantic_activation_ack_complete_matches( - 3, 8, UINT64_C(0x0f), 0, UINT64_C(1), UINT64_C(1) | bit22, - UINT64_C(0xabcd), CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_SAMPLE)); + 3, 8, UINT64_C(0x0f), 0, UINT64_C(1), UINT64_C(1) | bit22, UINT64_C(0xabcd), + CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_SAMPLE)); UT_ASSERT(!cluster_semantic_activation_ack_complete_matches( - 3, 7, UINT64_C(0x07), 0, UINT64_C(1), UINT64_C(1) | bit22, - UINT64_C(0xabcd), CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_SAMPLE)); + 3, 7, UINT64_C(0x07), 0, UINT64_C(1), UINT64_C(1) | bit22, UINT64_C(0xabcd), + CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_SAMPLE)); UT_ASSERT(!cluster_semantic_activation_ack_complete_matches( - 3, 7, UINT64_C(0x0f), 0, UINT64_C(1), UINT64_C(1) | bit22, - UINT64_C(0xdcba), CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_SAMPLE)); + 3, 7, UINT64_C(0x0f), 0, UINT64_C(1), UINT64_C(1) | bit22, UINT64_C(0xdcba), + CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_SAMPLE)); /* observed != expected -> false (a member has not ACKed). */ table->observed_members_lo = UINT64_C(0x0e); UT_ASSERT(!cluster_semantic_activation_ack_complete_matches( - 3, 7, UINT64_C(0x0f), 0, UINT64_C(1), UINT64_C(1) | bit22, - UINT64_C(0xabcd), CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_SAMPLE)); + 3, 7, UINT64_C(0x0f), 0, UINT64_C(1), UINT64_C(1) | bit22, UINT64_C(0xabcd), + CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_SAMPLE)); test_gate_reset(); } @@ -3994,17 +3732,14 @@ UT_TEST(test_93daa_member_accumulates_sample_and_closes_barrier) test_admitted_snapshot_valid = true; test_admitted_snapshot_episode = valid_d13_admitted_episode(); test_admitted_snapshot_marker = valid_d13_admitted_marker(); - test_local_capability_word - = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS; + test_local_capability_word = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS; test_peer_capability_word_sample_ok = true; - test_peer_capability_word - = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS; + test_peer_capability_word = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS; test_peer_capability_generation = 19; test_peer_capability_matches = true; for (node = 0; node < 3; node++) { test_send_results[node] = CLUSTER_IC_SEND_DONE; - test_remote_admitted_incarnations[node] - = UINT64_C(0x100) + (uint64)node; + test_remote_admitted_incarnations[node] = UINT64_C(0x100) + (uint64)node; } memset(&message, 0, sizeof(message)); @@ -4016,11 +3751,9 @@ UT_TEST(test_93daa_member_accumulates_sample_and_closes_barrier) message.transition_epoch = test_current_epoch; message.record_generation = 8; message.round_nonce = UINT64_C(77); - message.target_feature_bitmap - = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1; + message.target_feature_bitmap = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1; message.admitted_members_lo = UINT64_C(0x0f); - UT_ASSERT(cluster_semantic_activation_ack_wire_encode( - &message, payload)); + UT_ASSERT(cluster_semantic_activation_ack_wire_encode(&message, payload)); memset(&envelope, 0, sizeof(envelope)); envelope.msg_type = PGRAC_IC_MSG_SEMANTIC_ACTIVATION_ACK_V1; envelope.source_node_id = 0; @@ -4030,8 +3763,7 @@ UT_TEST(test_93daa_member_accumulates_sample_and_closes_barrier) cluster_semantic_activation_ack_handler(&envelope, payload); cluster_semantic_activation_lmon_tick(); UT_ASSERT(semantic_activation_ack_table_snapshot(&table)); - UT_ASSERT_EQ(table.stage, - CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_SAMPLE); + UT_ASSERT_EQ(table.stage, CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_SAMPLE); UT_ASSERT_EQ(table.observed_members_lo, UINT64_C(0x08)); for (node = 0; node < 3; node++) { @@ -4041,24 +3773,20 @@ UT_TEST(test_93daa_member_accumulates_sample_and_closes_barrier) message.boot_id = test_remote_admitted_incarnations[node]; message.admitted_incarnation = message.boot_id; message.capability_word = test_peer_capability_word; - UT_ASSERT(cluster_semantic_activation_ack_wire_encode( - &message, payload)); + UT_ASSERT(cluster_semantic_activation_ack_wire_encode(&message, payload)); envelope.source_node_id = (uint32)node; cluster_semantic_activation_ack_handler(&envelope, payload); } cluster_semantic_activation_lmon_tick(); UT_ASSERT(semantic_activation_ack_table_snapshot(&table)); - UT_ASSERT_EQ(table.stage, - CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_SAMPLE); - UT_ASSERT_EQ(table.flags, - CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID - | CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE); + UT_ASSERT_EQ(table.stage, CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_SAMPLE); + UT_ASSERT_EQ(table.flags, CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID + | CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE); UT_ASSERT_EQ(table.expected_members_lo, UINT64_C(0x0f)); UT_ASSERT_EQ(table.observed_members_lo, UINT64_C(0x0f)); for (node = 0; node < 4; node++) - UT_ASSERT(semantic_activation_ack_matches( - &table.expected[node], &table.observed[node])); + UT_ASSERT(semantic_activation_ack_matches(&table.expected[node], &table.observed[node])); UT_ASSERT(semantic_activation_ack_sample_digest(&table, &digest)); memset(&message, 0, sizeof(message)); @@ -4070,23 +3798,19 @@ UT_TEST(test_93daa_member_accumulates_sample_and_closes_barrier) message.transition_epoch = test_current_epoch; message.record_generation = 8; message.round_nonce = UINT64_C(77); - message.target_feature_bitmap - = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1; + message.target_feature_bitmap = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1; message.admitted_members_lo = UINT64_C(0x0f); message.capability_sample_digest = digest; - UT_ASSERT(cluster_semantic_activation_ack_wire_encode( - &message, payload)); + UT_ASSERT(cluster_semantic_activation_ack_wire_encode(&message, payload)); envelope.source_node_id = 0; cluster_semantic_activation_ack_handler(&envelope, payload); cluster_semantic_activation_lmon_tick(); UT_ASSERT(semantic_activation_ack_table_snapshot(&table)); - UT_ASSERT_EQ(table.stage, - CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_BARRIER); + UT_ASSERT_EQ(table.stage, CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_BARRIER); UT_ASSERT_EQ(table.observed_members_lo, UINT64_C(0)); memset(&read_request, 0, sizeof(read_request)); - if (!cluster_semantic_activation_qvotec_poll_record_read( - &read_request)) { + if (!cluster_semantic_activation_qvotec_poll_record_read(&read_request)) { UT_ASSERT(false); test_gate_reset(); return; @@ -4096,52 +3820,39 @@ UT_TEST(test_93daa_member_accumulates_sample_and_closes_barrier) prepare.record_generation = 8; prepare.transition_epoch = test_current_epoch; prepare.coordinator_node = 0; - prepare.coordinator_incarnation - = table.expected[0].admitted_incarnation; + prepare.coordinator_incarnation = table.expected[0].admitted_incarnation; prepare.admitted_members_lo = UINT64_C(0x0f); - prepare.target_feature_bitmap - = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1; + prepare.target_feature_bitmap = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1; prepare.capability_sample_digest = digest; - UT_ASSERT(cluster_semantic_activation_record_encode( - &prepare, record_bytes)); + UT_ASSERT(cluster_semantic_activation_record_encode(&prepare, record_bytes)); UT_ASSERT(cluster_semantic_activation_qvotec_complete_record_read( - read_request.request_seq, CLUSTER_SEMANTIC_ACTIVATION_OK, - false, record_bytes)); + read_request.request_seq, CLUSTER_SEMANTIC_ACTIVATION_OK, false, record_bytes)); test_reclaim_succeeds = true; cluster_semantic_activation_lmon_tick(); - UT_ASSERT_EQ(pg_atomic_read_u64( - test_gate_u64(TEST_GATE_RECORD_GENERATION_OFFSET)), UINT64_C(8)); - UT_ASSERT_EQ(pg_atomic_read_u32( - test_gate_u32(TEST_GATE_CLOSED_OFFSET)), UINT32_C(1)); + UT_ASSERT_EQ(pg_atomic_read_u64(test_gate_u64(TEST_GATE_RECORD_GENERATION_OFFSET)), + UINT64_C(8)); + UT_ASSERT_EQ(pg_atomic_read_u32(test_gate_u32(TEST_GATE_CLOSED_OFFSET)), UINT32_C(1)); UT_ASSERT(semantic_activation_ack_table_snapshot(&table)); - UT_ASSERT_EQ(table.stage, - CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_BARRIER); - UT_ASSERT_EQ(table.flags, - CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID); + UT_ASSERT_EQ(table.stage, CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_BARRIER); + UT_ASSERT_EQ(table.flags, CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID); UT_ASSERT_EQ(table.observed_members_lo, UINT64_C(0x08)); - UT_ASSERT(semantic_activation_ack_matches( - &table.expected[3], &table.observed[3])); + UT_ASSERT(semantic_activation_ack_matches(&table.expected[3], &table.observed[3])); UT_ASSERT_EQ(test_drain_request_calls, 1); UT_ASSERT_EQ(semantic_activation_lmon_record_read_seq, UINT64_C(0)); for (node = 0; node < 3; node++) { UT_ASSERT_EQ(test_send_calls[node], 2); memset(&message, 0, sizeof(message)); - UT_ASSERT(cluster_semantic_activation_ack_wire_decode( - test_send_payloads[node], &message)); - UT_ASSERT_EQ(message.kind, - CLUSTER_SEMANTIC_ACTIVATION_ACK_KIND_ACK); - UT_ASSERT_EQ(message.stage, - CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_BARRIER); - UT_ASSERT_EQ(message.result, - CLUSTER_SEMANTIC_ACTIVATION_ACK_RESULT_OK); + UT_ASSERT(cluster_semantic_activation_ack_wire_decode(test_send_payloads[node], &message)); + UT_ASSERT_EQ(message.kind, CLUSTER_SEMANTIC_ACTIVATION_ACK_KIND_ACK); + UT_ASSERT_EQ(message.stage, CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_BARRIER); + UT_ASSERT_EQ(message.result, CLUSTER_SEMANTIC_ACTIVATION_ACK_RESULT_OK); UT_ASSERT_EQ(message.member_node, UINT32_C(3)); UT_ASSERT_EQ(message.capability_sample_digest, digest); } cluster_semantic_activation_lmon_tick(); UT_ASSERT(semantic_activation_ack_table_snapshot(&table)); - UT_ASSERT_EQ(table.stage, - CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_BARRIER); + UT_ASSERT_EQ(table.stage, CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_BARRIER); UT_ASSERT_EQ(semantic_activation_lmon_record_read_seq, UINT64_C(0)); for (node = 0; node < 3; node++) UT_ASSERT_EQ(test_send_calls[node], 2); @@ -4156,25 +3867,21 @@ UT_TEST(test_93daa_member_accumulates_sample_and_closes_barrier) message.transition_epoch = test_current_epoch; message.record_generation = 8; message.round_nonce = UINT64_C(77); - message.target_feature_bitmap - = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1; + message.target_feature_bitmap = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1; message.admitted_members_lo = UINT64_C(0x0f); message.capability_sample_digest = digest; message.boot_id = test_remote_admitted_incarnations[node]; message.admitted_incarnation = message.boot_id; message.capability_word = test_peer_capability_word; - UT_ASSERT(cluster_semantic_activation_ack_wire_encode( - &message, payload)); + UT_ASSERT(cluster_semantic_activation_ack_wire_encode(&message, payload)); envelope.source_node_id = (uint32)node; cluster_semantic_activation_ack_handler(&envelope, payload); } cluster_semantic_activation_lmon_tick(); UT_ASSERT(semantic_activation_ack_table_snapshot(&table)); - UT_ASSERT_EQ(table.stage, - CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_BARRIER); - UT_ASSERT_EQ(table.flags, - CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID - | CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE); + UT_ASSERT_EQ(table.stage, CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_BARRIER); + UT_ASSERT_EQ(table.flags, CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID + | CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE); memset(&message, 0, sizeof(message)); message.kind = CLUSTER_SEMANTIC_ACTIVATION_ACK_KIND_REQUEST; @@ -4185,61 +3892,48 @@ UT_TEST(test_93daa_member_accumulates_sample_and_closes_barrier) message.transition_epoch = test_current_epoch; message.record_generation = 8; message.round_nonce = UINT64_C(77); - message.target_feature_bitmap - = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1; + message.target_feature_bitmap = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1; message.admitted_members_lo = UINT64_C(0x0f); message.capability_sample_digest = digest; - UT_ASSERT(cluster_semantic_activation_ack_wire_encode( - &message, payload)); + UT_ASSERT(cluster_semantic_activation_ack_wire_encode(&message, payload)); envelope.source_node_id = 0; cluster_semantic_activation_ack_handler(&envelope, payload); cluster_semantic_activation_lmon_tick(); UT_ASSERT(semantic_activation_ack_table_snapshot(&table)); - UT_ASSERT_EQ(table.stage, - CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_PREPARED); - UT_ASSERT_EQ(table.flags, - CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID); + UT_ASSERT_EQ(table.stage, CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_PREPARED); + UT_ASSERT_EQ(table.flags, CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID); UT_ASSERT_EQ(table.expected_members_lo, UINT64_C(0x0f)); UT_ASSERT_EQ(table.observed_members_lo, UINT64_C(0)); UT_ASSERT_EQ(table.observed_members_hi, UINT64_C(0)); UT_ASSERT_EQ(table.capability_sample_digest, digest); - UT_ASSERT_EQ(pg_atomic_read_u64( - test_gate_u64(TEST_GATE_RECORD_GENERATION_OFFSET)), UINT64_C(8)); - UT_ASSERT_EQ(pg_atomic_read_u32( - test_gate_u32(TEST_GATE_CLOSED_OFFSET)), UINT32_C(1)); + UT_ASSERT_EQ(pg_atomic_read_u64(test_gate_u64(TEST_GATE_RECORD_GENERATION_OFFSET)), + UINT64_C(8)); + UT_ASSERT_EQ(pg_atomic_read_u32(test_gate_u32(TEST_GATE_CLOSED_OFFSET)), UINT32_C(1)); UT_ASSERT_EQ(semantic_activation_lmon_record_read_seq, UINT64_C(0)); for (node = 0; node < 3; node++) UT_ASSERT_EQ(test_send_calls[node], 2); - UT_ASSERT(semantic_activation_ack_lmon_finish_member_prepared( - &table, CLUSTER_SEMANTIC_ACTIVATION_OK)); + UT_ASSERT(semantic_activation_ack_lmon_finish_member_prepared(&table, + CLUSTER_SEMANTIC_ACTIVATION_OK)); UT_ASSERT(semantic_activation_ack_table_snapshot(&table)); - UT_ASSERT_EQ(table.stage, - CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_PREPARED); - UT_ASSERT_EQ(table.flags, - CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID); + UT_ASSERT_EQ(table.stage, CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_PREPARED); + UT_ASSERT_EQ(table.flags, CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID); UT_ASSERT_EQ(table.observed_members_lo, UINT64_C(0x08)); UT_ASSERT_EQ(table.observed_members_hi, UINT64_C(0)); - UT_ASSERT(semantic_activation_ack_matches( - &table.observed[3], &table.expected[3])); - UT_ASSERT_EQ(pg_atomic_read_u64( - test_gate_u64(TEST_GATE_RECORD_GENERATION_OFFSET)), UINT64_C(8)); - UT_ASSERT_EQ(pg_atomic_read_u32( - test_gate_u32(TEST_GATE_CLOSED_OFFSET)), UINT32_C(1)); + UT_ASSERT(semantic_activation_ack_matches(&table.observed[3], &table.expected[3])); + UT_ASSERT_EQ(pg_atomic_read_u64(test_gate_u64(TEST_GATE_RECORD_GENERATION_OFFSET)), + UINT64_C(8)); + UT_ASSERT_EQ(pg_atomic_read_u32(test_gate_u32(TEST_GATE_CLOSED_OFFSET)), UINT32_C(1)); UT_ASSERT_EQ(semantic_activation_lmon_record_read_seq, UINT64_C(0)); for (node = 0; node < 3; node++) { ClusterSemanticActivationAckWireV1 sent; UT_ASSERT_EQ(test_send_calls[node], 3); - UT_ASSERT(cluster_semantic_activation_ack_wire_decode( - test_send_payloads[node], &sent)); - UT_ASSERT_EQ(sent.kind, - CLUSTER_SEMANTIC_ACTIVATION_ACK_KIND_ACK); - UT_ASSERT_EQ(sent.stage, - CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_PREPARED); - UT_ASSERT_EQ(sent.result, - CLUSTER_SEMANTIC_ACTIVATION_ACK_RESULT_OK); + UT_ASSERT(cluster_semantic_activation_ack_wire_decode(test_send_payloads[node], &sent)); + UT_ASSERT_EQ(sent.kind, CLUSTER_SEMANTIC_ACTIVATION_ACK_KIND_ACK); + UT_ASSERT_EQ(sent.stage, CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_PREPARED); + UT_ASSERT_EQ(sent.result, CLUSTER_SEMANTIC_ACTIVATION_ACK_RESULT_OK); UT_ASSERT_EQ(sent.member_node, UINT32_C(3)); } @@ -4253,25 +3947,21 @@ UT_TEST(test_93daa_member_accumulates_sample_and_closes_barrier) message.transition_epoch = test_current_epoch; message.record_generation = 8; message.round_nonce = UINT64_C(77); - message.target_feature_bitmap - = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1; + message.target_feature_bitmap = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1; message.admitted_members_lo = UINT64_C(0x0f); message.capability_sample_digest = digest; message.boot_id = test_remote_admitted_incarnations[node]; message.admitted_incarnation = message.boot_id; message.capability_word = test_peer_capability_word; - UT_ASSERT(cluster_semantic_activation_ack_wire_encode( - &message, payload)); + UT_ASSERT(cluster_semantic_activation_ack_wire_encode(&message, payload)); envelope.source_node_id = (uint32)node; cluster_semantic_activation_ack_handler(&envelope, payload); } cluster_semantic_activation_lmon_tick(); UT_ASSERT(semantic_activation_ack_table_snapshot(&table)); - UT_ASSERT_EQ(table.stage, - CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_PREPARED); - UT_ASSERT_EQ(table.flags, - CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID - | CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE); + UT_ASSERT_EQ(table.stage, CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_PREPARED); + UT_ASSERT_EQ(table.flags, CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID + | CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE); UT_ASSERT_EQ(table.observed_members_lo, UINT64_C(0x0f)); memset(&message, 0, sizeof(message)); @@ -4283,45 +3973,37 @@ UT_TEST(test_93daa_member_accumulates_sample_and_closes_barrier) message.transition_epoch = test_current_epoch; message.record_generation = 9; message.round_nonce = UINT64_C(77); - message.target_feature_bitmap - = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1; + message.target_feature_bitmap = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1; message.admitted_members_lo = UINT64_C(0x0f); message.capability_sample_digest = digest; - UT_ASSERT(cluster_semantic_activation_ack_wire_encode( - &message, payload)); + UT_ASSERT(cluster_semantic_activation_ack_wire_encode(&message, payload)); envelope.source_node_id = 0; cluster_semantic_activation_ack_handler(&envelope, payload); cluster_semantic_activation_lmon_tick(); UT_ASSERT(semantic_activation_ack_table_snapshot(&table)); - if (table.stage - != CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_COMMIT_APPLIED) { - UT_ASSERT_EQ(table.stage, - CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_COMMIT_APPLIED); + if (table.stage != CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_COMMIT_APPLIED) { + UT_ASSERT_EQ(table.stage, CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_COMMIT_APPLIED); test_gate_reset(); return; } - UT_ASSERT_EQ(table.flags, - CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID); + UT_ASSERT_EQ(table.flags, CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID); UT_ASSERT_EQ(table.record_generation, UINT64_C(9)); UT_ASSERT_EQ(table.expected_members_lo, UINT64_C(0x0f)); UT_ASSERT_EQ(table.observed_members_lo, UINT64_C(0)); UT_ASSERT_EQ(table.observed_members_hi, UINT64_C(0)); UT_ASSERT_EQ(table.capability_sample_digest, digest); for (node = 0; node < 4; node++) - UT_ASSERT_EQ(table.expected[node].record_generation, - UINT64_C(9)); - UT_ASSERT_EQ(pg_atomic_read_u64( - test_gate_u64(TEST_GATE_RECORD_GENERATION_OFFSET)), UINT64_C(8)); - UT_ASSERT_EQ(pg_atomic_read_u32( - test_gate_u32(TEST_GATE_CLOSED_OFFSET)), UINT32_C(1)); + UT_ASSERT_EQ(table.expected[node].record_generation, UINT64_C(9)); + UT_ASSERT_EQ(pg_atomic_read_u64(test_gate_u64(TEST_GATE_RECORD_GENERATION_OFFSET)), + UINT64_C(8)); + UT_ASSERT_EQ(pg_atomic_read_u32(test_gate_u32(TEST_GATE_CLOSED_OFFSET)), UINT32_C(1)); UT_ASSERT(semantic_activation_lmon_record_read_seq != 0); for (node = 0; node < 3; node++) UT_ASSERT_EQ(test_send_calls[node], 3); cluster_semantic_activation_lmon_tick(); memset(&read_request, 0, sizeof(read_request)); - if (!cluster_semantic_activation_qvotec_poll_record_read( - &read_request)) { + if (!cluster_semantic_activation_qvotec_poll_record_read(&read_request)) { UT_ASSERT(false); test_gate_reset(); return; @@ -4331,25 +4013,19 @@ UT_TEST(test_93daa_member_accumulates_sample_and_closes_barrier) prepare.record_generation = 9; prepare.transition_epoch = test_current_epoch; prepare.coordinator_node = 0; - prepare.coordinator_incarnation - = table.expected[0].admitted_incarnation; + prepare.coordinator_incarnation = table.expected[0].admitted_incarnation; prepare.admitted_members_lo = UINT64_C(0x0f); - prepare.target_feature_bitmap - = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1; + prepare.target_feature_bitmap = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1; prepare.capability_sample_digest = digest; - UT_ASSERT(cluster_semantic_activation_record_encode( - &prepare, record_bytes)); + UT_ASSERT(cluster_semantic_activation_record_encode(&prepare, record_bytes)); UT_ASSERT(cluster_semantic_activation_qvotec_complete_record_read( - read_request.request_seq, CLUSTER_SEMANTIC_ACTIVATION_OK, - false, record_bytes)); + read_request.request_seq, CLUSTER_SEMANTIC_ACTIVATION_OK, false, record_bytes)); cluster_semantic_activation_lmon_tick(); - UT_ASSERT_EQ(pg_atomic_read_u64( - test_gate_u64(TEST_GATE_RECORD_GENERATION_OFFSET)), UINT64_C(9)); - UT_ASSERT_EQ(pg_atomic_read_u32( - test_gate_u32(TEST_GATE_CLOSED_OFFSET)), UINT32_C(1)); + UT_ASSERT_EQ(pg_atomic_read_u64(test_gate_u64(TEST_GATE_RECORD_GENERATION_OFFSET)), + UINT64_C(9)); + UT_ASSERT_EQ(pg_atomic_read_u32(test_gate_u32(TEST_GATE_CLOSED_OFFSET)), UINT32_C(1)); UT_ASSERT(semantic_activation_ack_table_snapshot(&table)); - UT_ASSERT_EQ(table.stage, - CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_COMMIT_APPLIED); + UT_ASSERT_EQ(table.stage, CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_COMMIT_APPLIED); UT_ASSERT_EQ(table.observed_members_lo, UINT64_C(0)); UT_ASSERT_EQ(semantic_activation_lmon_record_read_seq, UINT64_C(0)); for (node = 0; node < 3; node++) @@ -4357,28 +4033,21 @@ UT_TEST(test_93daa_member_accumulates_sample_and_closes_barrier) /* Model only the already-separated successful apply_target_closed return; * the real descriptor remains fail-closed until its owner census exists. */ - UT_ASSERT(semantic_activation_ack_lmon_finish_member_prepared( - &table, CLUSTER_SEMANTIC_ACTIVATION_OK)); + UT_ASSERT(semantic_activation_ack_lmon_finish_member_prepared(&table, + CLUSTER_SEMANTIC_ACTIVATION_OK)); UT_ASSERT(semantic_activation_ack_table_snapshot(&table)); - UT_ASSERT_EQ(table.stage, - CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_COMMIT_APPLIED); - UT_ASSERT_EQ(table.flags, - CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID); + UT_ASSERT_EQ(table.stage, CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_COMMIT_APPLIED); + UT_ASSERT_EQ(table.flags, CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID); UT_ASSERT_EQ(table.observed_members_lo, UINT64_C(0x08)); - UT_ASSERT(semantic_activation_ack_matches( - &table.observed[3], &table.expected[3])); + UT_ASSERT(semantic_activation_ack_matches(&table.observed[3], &table.expected[3])); for (node = 0; node < 3; node++) { ClusterSemanticActivationAckWireV1 sent; UT_ASSERT_EQ(test_send_calls[node], 4); - UT_ASSERT(cluster_semantic_activation_ack_wire_decode( - test_send_payloads[node], &sent)); - UT_ASSERT_EQ(sent.kind, - CLUSTER_SEMANTIC_ACTIVATION_ACK_KIND_ACK); - UT_ASSERT_EQ(sent.stage, - CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_COMMIT_APPLIED); - UT_ASSERT_EQ(sent.result, - CLUSTER_SEMANTIC_ACTIVATION_ACK_RESULT_OK); + UT_ASSERT(cluster_semantic_activation_ack_wire_decode(test_send_payloads[node], &sent)); + UT_ASSERT_EQ(sent.kind, CLUSTER_SEMANTIC_ACTIVATION_ACK_KIND_ACK); + UT_ASSERT_EQ(sent.stage, CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_COMMIT_APPLIED); + UT_ASSERT_EQ(sent.result, CLUSTER_SEMANTIC_ACTIVATION_ACK_RESULT_OK); UT_ASSERT_EQ(sent.member_node, UINT32_C(3)); UT_ASSERT_EQ(sent.record_generation, UINT64_C(9)); } @@ -4406,23 +4075,19 @@ UT_TEST(test_93db_coordinator_reaches_exact_prepared_origin) test_admitted_snapshot_valid = true; test_admitted_snapshot_episode = valid_d13_admitted_episode(); test_admitted_snapshot_marker = valid_d13_admitted_marker(); - test_local_capability_word - = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS; + test_local_capability_word = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS; test_peer_capability_word_sample_ok = true; - test_peer_capability_word - = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS; + test_peer_capability_word = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS; test_peer_capability_generation = 19; test_peer_capability_matches = true; for (node = 1; node < 4; node++) { test_send_results[node] = CLUSTER_IC_SEND_DONE; - test_remote_admitted_incarnations[node] - = UINT64_C(0x100) + (uint64)node; + test_remote_admitted_incarnations[node] = UINT64_C(0x100) + (uint64)node; } - UT_ASSERT(semantic_activation_utility_mailbox_submit( - CLUSTER_SEMANTIC_ENABLE_ALL, 0, - CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, 0, 7, - &request_seq)); + UT_ASSERT(semantic_activation_utility_mailbox_submit(CLUSTER_SEMANTIC_ENABLE_ALL, 0, + CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, 0, + 7, &request_seq)); cluster_semantic_activation_lmon_tick(); for (node = 1; node < 4; node++) { memset(&ack, 0, sizeof(ack)); @@ -4434,14 +4099,12 @@ UT_TEST(test_93db_coordinator_reaches_exact_prepared_origin) ack.transition_epoch = test_current_epoch; ack.record_generation = 8; ack.round_nonce = request_seq; - ack.target_feature_bitmap - = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1; + ack.target_feature_bitmap = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1; ack.admitted_members_lo = UINT64_C(0x0f); ack.boot_id = test_remote_admitted_incarnations[node]; ack.admitted_incarnation = ack.boot_id; ack.capability_word = test_peer_capability_word; - UT_ASSERT(cluster_semantic_activation_ack_wire_encode( - &ack, payload)); + UT_ASSERT(cluster_semantic_activation_ack_wire_encode(&ack, payload)); memset(&envelope, 0, sizeof(envelope)); envelope.msg_type = PGRAC_IC_MSG_SEMANTIC_ACTIVATION_ACK_V1; envelope.source_node_id = (uint32)node; @@ -4453,16 +4116,13 @@ UT_TEST(test_93db_coordinator_reaches_exact_prepared_origin) cluster_semantic_activation_lmon_tick(); UT_ASSERT(semantic_activation_ack_table_snapshot(&table)); - UT_ASSERT_EQ(table.stage, - CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_SAMPLE); - UT_ASSERT_EQ(table.flags, - CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID - | CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE); + UT_ASSERT_EQ(table.stage, CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_SAMPLE); + UT_ASSERT_EQ(table.flags, CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID + | CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE); UT_ASSERT_EQ(table.observed_members_lo, UINT64_C(0x0f)); UT_ASSERT_EQ(table.expected_members_lo, UINT64_C(0x0f)); UT_ASSERT(semantic_activation_ack_complete_image_current( - &table, UINT64_C(0x0f), 0, test_current_epoch, 0, 0, - test_local_capability_word)); + &table, UINT64_C(0x0f), 0, test_current_epoch, 0, 0, test_local_capability_word)); { uint64 digest = 0; @@ -4470,87 +4130,68 @@ UT_TEST(test_93db_coordinator_reaches_exact_prepared_origin) UT_ASSERT(digest != 0); } memset(&cas_request, 0, sizeof(cas_request)); - UT_ASSERT(cluster_semantic_activation_qvotec_poll_record_cas( - &cas_request)); + UT_ASSERT(cluster_semantic_activation_qvotec_poll_record_cas(&cas_request)); UT_ASSERT_EQ(cas_request.expected_generation, UINT64_C(7)); UT_ASSERT_EQ(cas_request.expected_source_feature_bitmap, UINT64_C(0)); memset(&desired, 0, sizeof(desired)); - UT_ASSERT(cluster_semantic_activation_record_decode( - cas_request.desired_bytes, &desired, NULL)); + UT_ASSERT(cluster_semantic_activation_record_decode(cas_request.desired_bytes, &desired, NULL)); UT_ASSERT_EQ(desired.phase, CLUSTER_SEMANTIC_PHASE_PREPARE); UT_ASSERT_EQ(desired.record_generation, UINT64_C(8)); UT_ASSERT_EQ(desired.transition_epoch, test_current_epoch); UT_ASSERT_EQ(desired.source_feature_bitmap, UINT64_C(0)); - UT_ASSERT_EQ(desired.target_feature_bitmap, - CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1); + UT_ASSERT_EQ(desired.target_feature_bitmap, CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1); UT_ASSERT_EQ(desired.rollback_feature_bitmap, UINT64_C(0)); UT_ASSERT_EQ(desired.admitted_members_lo, UINT64_C(0x0f)); UT_ASSERT_EQ(desired.admitted_members_hi, UINT64_C(0)); UT_ASSERT(desired.capability_sample_digest != 0); UT_ASSERT_EQ(desired.coordinator_node, UINT32_C(0)); - UT_ASSERT_EQ(desired.coordinator_incarnation, - test_qvotec_self_incarnation); + UT_ASSERT_EQ(desired.coordinator_incarnation, test_qvotec_self_incarnation); UT_ASSERT(semantic_activation_ack_table_snapshot(&table)); - UT_ASSERT_EQ(table.stage, - CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_SAMPLE); - UT_ASSERT_EQ(table.flags, - CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID - | CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE); + UT_ASSERT_EQ(table.stage, CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_SAMPLE); + UT_ASSERT_EQ(table.flags, CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID + | CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE); UT_ASSERT_EQ(table.capability_sample_digest, UINT64_C(0)); UT_ASSERT(semantic_activation_ack_sample_digest(&table, &digest)); UT_ASSERT_EQ(desired.capability_sample_digest, digest); memset(&pending_request, 0, sizeof(pending_request)); UT_ASSERT(semantic_activation_utility_mailbox_poll(&pending_request)); memset(&refusal, 0, sizeof(refusal)); - UT_ASSERT(!semantic_activation_utility_mailbox_poll_completion( - pending_request.request_seq, &refusal)); - UT_ASSERT_EQ(pg_atomic_read_u64( - test_gate_u64(TEST_GATE_RECORD_GENERATION_OFFSET)), UINT64_C(7)); - UT_ASSERT_EQ(pg_atomic_read_u32( - test_gate_u32(TEST_GATE_CLOSED_OFFSET)), UINT32_C(0)); + UT_ASSERT(!semantic_activation_utility_mailbox_poll_completion(pending_request.request_seq, + &refusal)); + UT_ASSERT_EQ(pg_atomic_read_u64(test_gate_u64(TEST_GATE_RECORD_GENERATION_OFFSET)), + UINT64_C(7)); + UT_ASSERT_EQ(pg_atomic_read_u32(test_gate_u32(TEST_GATE_CLOSED_OFFSET)), UINT32_C(0)); request_seq = cas_request.request_seq; prepare_cas_seq = request_seq; cluster_semantic_activation_lmon_tick(); memset(&cas_request, 0, sizeof(cas_request)); - UT_ASSERT(cluster_semantic_activation_qvotec_poll_record_cas( - &cas_request)); + UT_ASSERT(cluster_semantic_activation_qvotec_poll_record_cas(&cas_request)); UT_ASSERT_EQ(cas_request.request_seq, request_seq); - UT_ASSERT_EQ(pg_atomic_read_u64( - &SemanticActivationShmem->record_cas_request_seq), request_seq); + UT_ASSERT_EQ(pg_atomic_read_u64(&SemanticActivationShmem->record_cas_request_seq), request_seq); UT_ASSERT(cluster_semantic_activation_qvotec_complete_record_cas( request_seq, CLUSTER_SEMANTIC_ACTIVATION_OK)); cluster_semantic_activation_lmon_tick(); - UT_ASSERT_EQ(pg_atomic_read_u64( - test_gate_u64(TEST_GATE_RECORD_GENERATION_OFFSET)), UINT64_C(8)); - UT_ASSERT_EQ(pg_atomic_read_u64( - test_gate_u64(TEST_GATE_ACTIVE_BITS_OFFSET)), UINT64_C(0)); - UT_ASSERT_EQ(pg_atomic_read_u32( - test_gate_u32(TEST_GATE_CLOSED_OFFSET)), UINT32_C(1)); + UT_ASSERT_EQ(pg_atomic_read_u64(test_gate_u64(TEST_GATE_RECORD_GENERATION_OFFSET)), + UINT64_C(8)); + UT_ASSERT_EQ(pg_atomic_read_u64(test_gate_u64(TEST_GATE_ACTIVE_BITS_OFFSET)), UINT64_C(0)); + UT_ASSERT_EQ(pg_atomic_read_u32(test_gate_u32(TEST_GATE_CLOSED_OFFSET)), UINT32_C(1)); UT_ASSERT(semantic_activation_ack_table_snapshot(&table)); - UT_ASSERT_EQ(table.stage, - CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_SAMPLE); - pg_atomic_write_u32( - test_gate_inflight(CLUSTER_SEMANTIC_SOURCE_SIDE, 0), 1); + UT_ASSERT_EQ(table.stage, CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_SAMPLE); + pg_atomic_write_u32(test_gate_inflight(CLUSTER_SEMANTIC_SOURCE_SIDE, 0), 1); cluster_semantic_activation_lmon_tick(); - UT_ASSERT_EQ(pg_atomic_read_u64( - test_gate_u64(TEST_GATE_RECORD_GENERATION_OFFSET)), UINT64_C(8)); - UT_ASSERT_EQ(pg_atomic_read_u64( - test_gate_u64(TEST_GATE_ACTIVE_BITS_OFFSET)), UINT64_C(0)); - UT_ASSERT_EQ(pg_atomic_read_u32( - test_gate_u32(TEST_GATE_CLOSED_OFFSET)), UINT32_C(1)); + UT_ASSERT_EQ(pg_atomic_read_u64(test_gate_u64(TEST_GATE_RECORD_GENERATION_OFFSET)), + UINT64_C(8)); + UT_ASSERT_EQ(pg_atomic_read_u64(test_gate_u64(TEST_GATE_ACTIVE_BITS_OFFSET)), UINT64_C(0)); + UT_ASSERT_EQ(pg_atomic_read_u32(test_gate_u32(TEST_GATE_CLOSED_OFFSET)), UINT32_C(1)); UT_ASSERT(semantic_activation_ack_table_snapshot(&table)); - UT_ASSERT_EQ(table.stage, - CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_SAMPLE); + UT_ASSERT_EQ(table.stage, CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_SAMPLE); UT_ASSERT_EQ(test_drain_request_calls, 0); - pg_atomic_write_u32( - test_gate_inflight(CLUSTER_SEMANTIC_SOURCE_SIDE, 0), 0); + pg_atomic_write_u32(test_gate_inflight(CLUSTER_SEMANTIC_SOURCE_SIDE, 0), 0); test_reclaim_succeeds = true; cluster_semantic_activation_lmon_tick(); UT_ASSERT(semantic_activation_ack_table_snapshot(&table)); - UT_ASSERT_EQ(table.stage, - CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_BARRIER); - UT_ASSERT_EQ(table.flags, - CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID); + UT_ASSERT_EQ(table.stage, CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_BARRIER); + UT_ASSERT_EQ(table.flags, CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID); UT_ASSERT_EQ(table.expected_members_lo, UINT64_C(0x0f)); UT_ASSERT_EQ(table.observed_members_lo, UINT64_C(1)); UT_ASSERT_EQ(table.observed_members_hi, UINT64_C(0)); @@ -4559,12 +4200,10 @@ UT_TEST(test_93db_coordinator_reaches_exact_prepared_origin) for (node = 1; node < 4; node++) { memset(&ack, 0, sizeof(ack)); UT_ASSERT_EQ(test_send_calls[node], 4); - UT_ASSERT(cluster_semantic_activation_ack_wire_decode( - test_send_history_payloads[node][2], &ack)); - UT_ASSERT_EQ(ack.kind, - CLUSTER_SEMANTIC_ACTIVATION_ACK_KIND_REQUEST); - UT_ASSERT_EQ(ack.stage, - CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_BARRIER); + UT_ASSERT( + cluster_semantic_activation_ack_wire_decode(test_send_history_payloads[node][2], &ack)); + UT_ASSERT_EQ(ack.kind, CLUSTER_SEMANTIC_ACTIVATION_ACK_KIND_REQUEST); + UT_ASSERT_EQ(ack.stage, CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_BARRIER); UT_ASSERT_EQ(ack.member_node, (uint32)node); UT_ASSERT_EQ(ack.record_generation, UINT64_C(8)); UT_ASSERT_EQ(ack.round_nonce, request_seq); @@ -4572,8 +4211,7 @@ UT_TEST(test_93db_coordinator_reaches_exact_prepared_origin) } cluster_semantic_activation_lmon_tick(); UT_ASSERT(semantic_activation_ack_table_snapshot(&table)); - UT_ASSERT_EQ(table.stage, - CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_BARRIER); + UT_ASSERT_EQ(table.stage, CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_BARRIER); for (node = 1; node < 4; node++) UT_ASSERT_EQ(test_send_calls[node], 4); @@ -4587,15 +4225,13 @@ UT_TEST(test_93db_coordinator_reaches_exact_prepared_origin) ack.transition_epoch = test_current_epoch; ack.record_generation = 8; ack.round_nonce = table.round_nonce; - ack.target_feature_bitmap - = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1; + ack.target_feature_bitmap = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1; ack.admitted_members_lo = UINT64_C(0x0f); ack.capability_sample_digest = digest; ack.boot_id = test_remote_admitted_incarnations[node]; ack.admitted_incarnation = ack.boot_id; ack.capability_word = test_peer_capability_word; - UT_ASSERT(cluster_semantic_activation_ack_wire_encode( - &ack, payload)); + UT_ASSERT(cluster_semantic_activation_ack_wire_encode(&ack, payload)); memset(&envelope, 0, sizeof(envelope)); envelope.msg_type = PGRAC_IC_MSG_SEMANTIC_ACTIVATION_ACK_V1; envelope.source_node_id = (uint32)node; @@ -4606,10 +4242,8 @@ UT_TEST(test_93db_coordinator_reaches_exact_prepared_origin) } cluster_semantic_activation_lmon_tick(); UT_ASSERT(semantic_activation_ack_table_snapshot(&table)); - UT_ASSERT_EQ(table.stage, - CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_PREPARED); - UT_ASSERT_EQ(table.flags, - CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID); + UT_ASSERT_EQ(table.stage, CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_PREPARED); + UT_ASSERT_EQ(table.flags, CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID); UT_ASSERT_EQ(table.expected_members_lo, UINT64_C(0x0f)); UT_ASSERT_EQ(table.observed_members_lo, UINT64_C(0)); UT_ASSERT_EQ(table.observed_members_hi, UINT64_C(0)); @@ -4617,12 +4251,9 @@ UT_TEST(test_93db_coordinator_reaches_exact_prepared_origin) for (node = 1; node < 4; node++) { memset(&ack, 0, sizeof(ack)); UT_ASSERT_EQ(test_send_calls[node], 5); - UT_ASSERT(cluster_semantic_activation_ack_wire_decode( - test_send_payloads[node], &ack)); - UT_ASSERT_EQ(ack.kind, - CLUSTER_SEMANTIC_ACTIVATION_ACK_KIND_REQUEST); - UT_ASSERT_EQ(ack.stage, - CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_PREPARED); + UT_ASSERT(cluster_semantic_activation_ack_wire_decode(test_send_payloads[node], &ack)); + UT_ASSERT_EQ(ack.kind, CLUSTER_SEMANTIC_ACTIVATION_ACK_KIND_REQUEST); + UT_ASSERT_EQ(ack.stage, CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_PREPARED); UT_ASSERT_EQ(ack.member_node, (uint32)node); UT_ASSERT_EQ(ack.record_generation, UINT64_C(8)); UT_ASSERT_EQ(ack.round_nonce, table.round_nonce); @@ -4630,28 +4261,24 @@ UT_TEST(test_93db_coordinator_reaches_exact_prepared_origin) } cluster_semantic_activation_lmon_tick(); UT_ASSERT(semantic_activation_ack_table_snapshot(&table)); - UT_ASSERT_EQ(table.stage, - CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_PREPARED); + UT_ASSERT_EQ(table.stage, CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_PREPARED); for (node = 1; node < 4; node++) UT_ASSERT_EQ(test_send_calls[node], 5); UT_ASSERT(semantic_activation_utility_mailbox_poll(&pending_request)); - UT_ASSERT(!semantic_activation_utility_mailbox_poll_completion( - pending_request.request_seq, &refusal)); + UT_ASSERT(!semantic_activation_utility_mailbox_poll_completion(pending_request.request_seq, + &refusal)); /* Model only the already-separated successful post-prepare_target return; * the carrier under test begins at the exact PREPARED table. */ - UT_ASSERT(semantic_activation_ack_lmon_finish_member_prepared( - &table, CLUSTER_SEMANTIC_ACTIVATION_OK)); + UT_ASSERT(semantic_activation_ack_lmon_finish_member_prepared(&table, + CLUSTER_SEMANTIC_ACTIVATION_OK)); UT_ASSERT(semantic_activation_ack_table_snapshot(&table)); - UT_ASSERT_EQ(table.stage, - CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_PREPARED); - UT_ASSERT_EQ(table.flags, - CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID); + UT_ASSERT_EQ(table.stage, CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_PREPARED); + UT_ASSERT_EQ(table.flags, CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID); UT_ASSERT_EQ(table.observed_members_lo, UINT64_C(0x01)); cluster_semantic_activation_lmon_tick(); - UT_ASSERT_EQ(pg_atomic_read_u64( - &SemanticActivationShmem->record_cas_request_seq), - prepare_cas_seq); + UT_ASSERT_EQ(pg_atomic_read_u64(&SemanticActivationShmem->record_cas_request_seq), + prepare_cas_seq); for (node = 1; node < 4; node++) { memset(&ack, 0, sizeof(ack)); @@ -4663,15 +4290,13 @@ UT_TEST(test_93db_coordinator_reaches_exact_prepared_origin) ack.transition_epoch = test_current_epoch; ack.record_generation = 8; ack.round_nonce = table.round_nonce; - ack.target_feature_bitmap - = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1; + ack.target_feature_bitmap = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1; ack.admitted_members_lo = UINT64_C(0x0f); ack.capability_sample_digest = digest; ack.boot_id = test_remote_admitted_incarnations[node]; ack.admitted_incarnation = ack.boot_id; ack.capability_word = test_peer_capability_word; - UT_ASSERT(cluster_semantic_activation_ack_wire_encode( - &ack, payload)); + UT_ASSERT(cluster_semantic_activation_ack_wire_encode(&ack, payload)); memset(&envelope, 0, sizeof(envelope)); envelope.msg_type = PGRAC_IC_MSG_SEMANTIC_ACTIVATION_ACK_V1; envelope.source_node_id = (uint32)node; @@ -4682,85 +4307,67 @@ UT_TEST(test_93db_coordinator_reaches_exact_prepared_origin) } cluster_semantic_activation_lmon_tick(); UT_ASSERT(semantic_activation_ack_table_snapshot(&table)); - UT_ASSERT_EQ(table.stage, - CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_PREPARED); - UT_ASSERT_EQ(table.flags, - CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID - | CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE); + UT_ASSERT_EQ(table.stage, CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_PREPARED); + UT_ASSERT_EQ(table.flags, CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID + | CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE); UT_ASSERT_EQ(table.observed_members_lo, UINT64_C(0x0f)); memset(&cas_request, 0, sizeof(cas_request)); - UT_ASSERT(cluster_semantic_activation_qvotec_poll_record_cas( - &cas_request)); + UT_ASSERT(cluster_semantic_activation_qvotec_poll_record_cas(&cas_request)); UT_ASSERT_EQ(cas_request.request_seq, prepare_cas_seq + 1); UT_ASSERT_EQ(cas_request.expected_generation, UINT64_C(8)); UT_ASSERT_EQ(cas_request.expected_source_feature_bitmap, UINT64_C(0)); memset(&desired, 0, sizeof(desired)); - UT_ASSERT(cluster_semantic_activation_record_decode( - cas_request.desired_bytes, &desired, NULL)); + UT_ASSERT(cluster_semantic_activation_record_decode(cas_request.desired_bytes, &desired, NULL)); UT_ASSERT_EQ(desired.phase, CLUSTER_SEMANTIC_PHASE_COMMIT); UT_ASSERT_EQ(desired.record_generation, UINT64_C(9)); UT_ASSERT_EQ(desired.transition_epoch, test_current_epoch); UT_ASSERT_EQ(desired.source_feature_bitmap, UINT64_C(0)); - UT_ASSERT_EQ(desired.target_feature_bitmap, - CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1); + UT_ASSERT_EQ(desired.target_feature_bitmap, CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1); UT_ASSERT_EQ(desired.rollback_feature_bitmap, UINT64_C(0)); UT_ASSERT_EQ(desired.admitted_members_lo, UINT64_C(0x0f)); UT_ASSERT_EQ(desired.admitted_members_hi, UINT64_C(0)); UT_ASSERT_EQ(desired.capability_sample_digest, digest); UT_ASSERT_EQ(desired.coordinator_node, UINT32_C(0)); - UT_ASSERT_EQ(desired.coordinator_incarnation, - test_qvotec_self_incarnation); + UT_ASSERT_EQ(desired.coordinator_incarnation, test_qvotec_self_incarnation); UT_ASSERT(cluster_semantic_activation_qvotec_complete_record_cas( cas_request.request_seq, CLUSTER_SEMANTIC_ACTIVATION_OK)); cluster_semantic_activation_lmon_tick(); - if (pg_atomic_read_u64( - test_gate_u64(TEST_GATE_RECORD_GENERATION_OFFSET)) - != UINT64_C(9)) { - UT_ASSERT_EQ(pg_atomic_read_u64( - test_gate_u64(TEST_GATE_RECORD_GENERATION_OFFSET)), - UINT64_C(9)); + if (pg_atomic_read_u64(test_gate_u64(TEST_GATE_RECORD_GENERATION_OFFSET)) != UINT64_C(9)) { + UT_ASSERT_EQ(pg_atomic_read_u64(test_gate_u64(TEST_GATE_RECORD_GENERATION_OFFSET)), + UINT64_C(9)); test_gate_reset(); return; } - UT_ASSERT_EQ(pg_atomic_read_u64( - test_gate_u64(TEST_GATE_ACTIVE_BITS_OFFSET)), UINT64_C(0)); - UT_ASSERT_EQ(pg_atomic_read_u32( - test_gate_u32(TEST_GATE_CLOSED_OFFSET)), UINT32_C(1)); + UT_ASSERT_EQ(pg_atomic_read_u64(test_gate_u64(TEST_GATE_ACTIVE_BITS_OFFSET)), UINT64_C(0)); + UT_ASSERT_EQ(pg_atomic_read_u32(test_gate_u32(TEST_GATE_CLOSED_OFFSET)), UINT32_C(1)); UT_ASSERT(semantic_activation_ack_table_snapshot(&table)); - UT_ASSERT_EQ(table.stage, - CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_COMMIT_APPLIED); - UT_ASSERT_EQ(table.flags, - CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID); + UT_ASSERT_EQ(table.stage, CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_COMMIT_APPLIED); + UT_ASSERT_EQ(table.flags, CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID); UT_ASSERT_EQ(table.expected_members_lo, UINT64_C(0x0f)); UT_ASSERT_EQ(table.observed_members_lo, UINT64_C(0)); UT_ASSERT_EQ(table.observed_members_hi, UINT64_C(0)); UT_ASSERT_EQ(table.record_generation, UINT64_C(9)); UT_ASSERT_EQ(table.capability_sample_digest, digest); for (node = 0; node < 4; node++) - UT_ASSERT_EQ(table.expected[node].record_generation, - UINT64_C(9)); + UT_ASSERT_EQ(table.expected[node].record_generation, UINT64_C(9)); UT_ASSERT_EQ(semantic_activation_lmon_record_read_seq, UINT64_C(0)); for (node = 1; node < 4; node++) { memset(&ack, 0, sizeof(ack)); UT_ASSERT_EQ(test_send_calls[node], 7); - UT_ASSERT(cluster_semantic_activation_ack_wire_decode( - test_send_payloads[node], &ack)); - UT_ASSERT_EQ(ack.kind, - CLUSTER_SEMANTIC_ACTIVATION_ACK_KIND_REQUEST); - UT_ASSERT_EQ(ack.stage, - CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_COMMIT_APPLIED); + UT_ASSERT(cluster_semantic_activation_ack_wire_decode(test_send_payloads[node], &ack)); + UT_ASSERT_EQ(ack.kind, CLUSTER_SEMANTIC_ACTIVATION_ACK_KIND_REQUEST); + UT_ASSERT_EQ(ack.stage, CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_COMMIT_APPLIED); UT_ASSERT_EQ(ack.member_node, (uint32)node); UT_ASSERT_EQ(ack.record_generation, UINT64_C(9)); UT_ASSERT_EQ(ack.round_nonce, table.round_nonce); UT_ASSERT_EQ(ack.capability_sample_digest, digest); } UT_ASSERT(semantic_activation_utility_mailbox_poll(&pending_request)); - UT_ASSERT(!semantic_activation_utility_mailbox_poll_completion( - pending_request.request_seq, &refusal)); + UT_ASSERT(!semantic_activation_utility_mailbox_poll_completion(pending_request.request_seq, + &refusal)); cluster_semantic_activation_lmon_tick(); UT_ASSERT(semantic_activation_ack_table_snapshot(&table)); - UT_ASSERT_EQ(table.stage, - CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_COMMIT_APPLIED); + UT_ASSERT_EQ(table.stage, CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_COMMIT_APPLIED); for (node = 1; node < 4; node++) UT_ASSERT_EQ(test_send_calls[node], 7); test_gate_reset(); @@ -4779,9 +4386,8 @@ UT_TEST(test_93dc_source_removed_round_waits_without_reviving_source) test_gate_reset(); cluster_node_id = 0; test_gate_publish(2, r4, 7, test_current_epoch, false); - test_local_capability_word - = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS - | PGRAC_IC_HELLO_CAP_GCS_RESOURCE_X_CONVERT_V1; + test_local_capability_word = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS + | PGRAC_IC_HELLO_CAP_GCS_RESOURCE_X_CONVERT_V1; test_peer_capability_word_sample_ok = true; test_peer_capability_word = test_local_capability_word; test_peer_capability_generation = 23; @@ -4790,29 +4396,24 @@ UT_TEST(test_93dc_source_removed_round_waits_without_reviving_source) test_resource_x_gate_snapshot.phase = RESOURCE_X_GATE_OPEN; test_resource_x_gate_snapshot.formation = 0; - UT_ASSERT(semantic_activation_utility_mailbox_submit( - CLUSTER_SEMANTIC_ENABLE_ALL, r4, r4 | r11, 0, 7, - &request_seq)); + UT_ASSERT(semantic_activation_utility_mailbox_submit(CLUSTER_SEMANTIC_ENABLE_ALL, r4, r4 | r11, + 0, 7, &request_seq)); cluster_semantic_activation_lmon_tick(); memset(&refusal, 0, sizeof(refusal)); - UT_ASSERT(!semantic_activation_utility_mailbox_poll_completion( - request_seq, &refusal)); + UT_ASSERT(!semantic_activation_utility_mailbox_poll_completion(request_seq, &refusal)); memset(&pending, 0, sizeof(pending)); UT_ASSERT(semantic_activation_utility_mailbox_poll(&pending)); UT_ASSERT_EQ(pending.request_seq, request_seq); memset(&cas_request, 0, sizeof(cas_request)); - UT_ASSERT(!cluster_semantic_activation_qvotec_poll_record_cas( - &cas_request)); - UT_ASSERT_EQ(cluster_resource_x_writer_path_snapshot( - &writer_generation), RESOURCE_X_WRITER_CLOSED); + UT_ASSERT(!cluster_semantic_activation_qvotec_poll_record_cas(&cas_request)); + UT_ASSERT_EQ(cluster_resource_x_writer_path_snapshot(&writer_generation), + RESOURCE_X_WRITER_CLOSED); UT_ASSERT_EQ(writer_generation, UINT64_C(7)); - UT_ASSERT_EQ(pg_atomic_read_u64( - test_gate_u64(TEST_GATE_ACTIVE_BITS_OFFSET)), r4); - UT_ASSERT_EQ(pg_atomic_read_u64( - test_gate_u64(TEST_GATE_RECORD_GENERATION_OFFSET)), UINT64_C(7)); - UT_ASSERT_EQ(pg_atomic_read_u32( - test_gate_u32(TEST_GATE_CLOSED_OFFSET)), UINT32_C(0)); + UT_ASSERT_EQ(pg_atomic_read_u64(test_gate_u64(TEST_GATE_ACTIVE_BITS_OFFSET)), r4); + UT_ASSERT_EQ(pg_atomic_read_u64(test_gate_u64(TEST_GATE_RECORD_GENERATION_OFFSET)), + UINT64_C(7)); + UT_ASSERT_EQ(pg_atomic_read_u32(test_gate_u32(TEST_GATE_CLOSED_OFFSET)), UINT32_C(0)); test_gate_reset(); } @@ -4821,15 +4422,13 @@ UT_TEST(test_93dca_source_removed_open_target_remains_selectable) const ClusterSemanticActivationDescriptor *cutover = cluster_semantic_activation_r11_resource_x_descriptor(); uint64 generation = 0; - uint64 active_bits - = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1 - | CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1; + uint64 active_bits = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1 + | CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1; test_gate_reset(); test_gate_publish(4, active_bits, 10, test_current_epoch, false); UT_ASSERT(!cutover->source_available); - UT_ASSERT_EQ(cluster_resource_x_writer_path_snapshot(&generation), - RESOURCE_X_WRITER_TARGET); + UT_ASSERT_EQ(cluster_resource_x_writer_path_snapshot(&generation), RESOURCE_X_WRITER_TARGET); UT_ASSERT_EQ(generation, UINT64_C(10)); test_gate_reset(); } @@ -4841,21 +4440,19 @@ UT_TEST(test_93e_utility_wait_returns_only_matching_terminal_result) uint64 request_seq = 0; test_gate_reset(); - UT_ASSERT(semantic_activation_utility_mailbox_submit( - CLUSTER_SEMANTIC_ENABLE_ALL, 0, - CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, 0, 0, &request_seq)); + UT_ASSERT(semantic_activation_utility_mailbox_submit(CLUSTER_SEMANTIC_ENABLE_ALL, 0, + CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, 0, + 0, &request_seq)); UT_ASSERT(semantic_activation_utility_mailbox_poll(&request)); - UT_ASSERT(semantic_activation_utility_mailbox_complete( - request.request_seq, CLUSTER_SEMANTIC_ACTIVATION_OK, 0, 0)); + UT_ASSERT(semantic_activation_utility_mailbox_complete(request.request_seq, + CLUSTER_SEMANTIC_ACTIVATION_OK, 0, 0)); memset(&refusal, 0xa5, sizeof(refusal)); - UT_ASSERT_EQ(semantic_activation_utility_mailbox_wait( - request_seq, &refusal), + UT_ASSERT_EQ(semantic_activation_utility_mailbox_wait(request_seq, &refusal), CLUSTER_SEMANTIC_ACTIVATION_OK); UT_ASSERT_EQ(refusal.result, CLUSTER_SEMANTIC_ACTIVATION_OK); UT_ASSERT_EQ(refusal.feature_bit, UINT64_C(0)); UT_ASSERT_EQ(refusal.expected_generation, UINT64_C(0)); - UT_ASSERT(!semantic_activation_utility_mailbox_poll_completion( - request_seq, &refusal)); + UT_ASSERT(!semantic_activation_utility_mailbox_poll_completion(request_seq, &refusal)); } UT_TEST(test_93ea_utility_wait_does_not_synthesize_elapsed_terminal) @@ -4864,20 +4461,18 @@ UT_TEST(test_93ea_utility_wait_does_not_synthesize_elapsed_terminal) uint64 request_seq = 0; test_gate_reset(); - UT_ASSERT(semantic_activation_utility_mailbox_submit( - CLUSTER_SEMANTIC_ENABLE_ALL, 0, - CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, 0, 0, &request_seq)); + UT_ASSERT(semantic_activation_utility_mailbox_submit(CLUSTER_SEMANTIC_ENABLE_ALL, 0, + CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, 0, + 0, &request_seq)); test_complete_after_wait_sleeps = 6000; test_wait_completion_request_seq = request_seq; memset(&refusal, 0xa5, sizeof(refusal)); - UT_ASSERT_EQ(semantic_activation_utility_mailbox_wait( - request_seq, &refusal), + UT_ASSERT_EQ(semantic_activation_utility_mailbox_wait(request_seq, &refusal), CLUSTER_SEMANTIC_ACTIVATION_OK); UT_ASSERT(test_wait_completion_succeeded); UT_ASSERT_EQ(test_wait_sleep_calls, 6000); UT_ASSERT_EQ(refusal.result, CLUSTER_SEMANTIC_ACTIVATION_OK); - UT_ASSERT(!semantic_activation_utility_mailbox_poll_completion( - request_seq, &refusal)); + UT_ASSERT(!semantic_activation_utility_mailbox_poll_completion(request_seq, &refusal)); } UT_TEST(test_93f_pgsa_read_mailbox_round_trip_is_qvotec_owned) @@ -4908,17 +4503,15 @@ UT_TEST(test_93f_pgsa_read_mailbox_round_trip_is_qvotec_owned) UT_ASSERT(cluster_semantic_activation_qvotec_complete_record_read( request_seq, CLUSTER_SEMANTIC_ACTIVATION_OK, false, bytes)); memset(&completion, 0, sizeof(completion)); - UT_ASSERT(semantic_activation_record_read_mailbox_poll_completion( - request_seq, &completion)); + UT_ASSERT(semantic_activation_record_read_mailbox_poll_completion(request_seq, &completion)); UT_ASSERT_EQ(completion.result, CLUSTER_SEMANTIC_ACTIVATION_OK); UT_ASSERT(!completion.implicit_open); UT_ASSERT_EQ(memcmp(completion.selected_bytes, bytes, sizeof(bytes)), 0); } static bool -test_encode_prepare_record_cas( - uint64 expected_generation, - uint8 desired[CLUSTER_SEMANTIC_ACTIVATION_RECORD_BYTES]) +test_encode_prepare_record_cas(uint64 expected_generation, + uint8 desired[CLUSTER_SEMANTIC_ACTIVATION_RECORD_BYTES]) { ClusterSemanticActivationRecord record; @@ -4926,8 +4519,7 @@ test_encode_prepare_record_cas( return false; memset(&record, 0, sizeof(record)); record.source_feature_bitmap = 0; - record.target_feature_bitmap - = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1; + record.target_feature_bitmap = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1; record.transition_epoch = test_current_epoch; record.record_generation = expected_generation + 1; record.admitted_members_lo = UINT64_C(0x0f); @@ -4939,9 +4531,8 @@ test_encode_prepare_record_cas( } static bool -test_submit_current_prepare_record_cas( - uint64 *out_request_seq, - uint8 desired[CLUSTER_SEMANTIC_ACTIVATION_RECORD_BYTES]) +test_submit_current_prepare_record_cas(uint64 *out_request_seq, + uint8 desired[CLUSTER_SEMANTIC_ACTIVATION_RECORD_BYTES]) { uint64 utility_request_seq = 0; @@ -4951,13 +4542,11 @@ test_submit_current_prepare_record_cas( test_admitted_snapshot_valid = true; test_admitted_snapshot_episode = valid_d13_admitted_episode(); test_admitted_snapshot_marker = valid_d13_admitted_marker(); - return semantic_activation_utility_mailbox_submit( - CLUSTER_SEMANTIC_ENABLE_ALL, 0, - CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, 0, 0, - &utility_request_seq) + return semantic_activation_utility_mailbox_submit(CLUSTER_SEMANTIC_ENABLE_ALL, 0, + CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, 0, 0, + &utility_request_seq) && test_encode_prepare_record_cas(0, desired) - && semantic_activation_record_cas_mailbox_submit( - 0, 0, desired, out_request_seq); + && semantic_activation_record_cas_mailbox_submit(0, 0, desired, out_request_seq); } UT_TEST(test_93fa_wrong_read_completion_cannot_mutate_pending_cas) @@ -4968,8 +4557,7 @@ UT_TEST(test_93fa_wrong_read_completion_cannot_mutate_pending_cas) uint64 request_seq = 0; test_gate_reset(); - UT_ASSERT(test_submit_current_prepare_record_cas( - &request_seq, desired)); + UT_ASSERT(test_submit_current_prepare_record_cas(&request_seq, desired)); UT_ASSERT(!cluster_semantic_activation_qvotec_complete_record_read( request_seq, CLUSTER_SEMANTIC_ACTIVATION_OK, true, zero)); memset(&request, 0, sizeof(request)); @@ -4986,15 +4574,13 @@ UT_TEST(test_93fb_out_of_quorum_qvotec_rejects_pending_record_cas) uint64 request_seq = 0; test_gate_reset(); - UT_ASSERT(test_submit_current_prepare_record_cas( - &request_seq, desired)); + UT_ASSERT(test_submit_current_prepare_record_cas(&request_seq, desired)); test_qvotec_in_quorum = false; memset(&request, 0xa5, sizeof(request)); memset(&zero, 0, sizeof(zero)); UT_ASSERT(!cluster_semantic_activation_qvotec_poll_record_cas(&request)); UT_ASSERT_EQ(memcmp(&request, &zero, sizeof(request)), 0); - UT_ASSERT(semantic_activation_record_cas_mailbox_poll_completion( - request_seq, &result)); + UT_ASSERT(semantic_activation_record_cas_mailbox_poll_completion(request_seq, &result)); UT_ASSERT_EQ(result, CLUSTER_SEMANTIC_ACTIVATION_QUORUM_HOLD); } @@ -5007,15 +4593,13 @@ UT_TEST(test_93fc_epoch_drift_qvotec_rejects_pending_record_cas) uint64 request_seq = 0; test_gate_reset(); - UT_ASSERT(test_submit_current_prepare_record_cas( - &request_seq, desired)); + UT_ASSERT(test_submit_current_prepare_record_cas(&request_seq, desired)); test_current_epoch++; memset(&request, 0xa5, sizeof(request)); memset(&zero, 0, sizeof(zero)); UT_ASSERT(!cluster_semantic_activation_qvotec_poll_record_cas(&request)); UT_ASSERT_EQ(memcmp(&request, &zero, sizeof(request)), 0); - UT_ASSERT(semantic_activation_record_cas_mailbox_poll_completion( - request_seq, &result)); + UT_ASSERT(semantic_activation_record_cas_mailbox_poll_completion(request_seq, &result)); UT_ASSERT_EQ(result, CLUSTER_SEMANTIC_ACTIVATION_QUORUM_HOLD); } @@ -5028,15 +4612,13 @@ UT_TEST(test_93fd_incarnation_drift_qvotec_rejects_pending_record_cas) uint64 request_seq = 0; test_gate_reset(); - UT_ASSERT(test_submit_current_prepare_record_cas( - &request_seq, desired)); + UT_ASSERT(test_submit_current_prepare_record_cas(&request_seq, desired)); test_qvotec_self_incarnation++; memset(&request, 0xa5, sizeof(request)); memset(&zero, 0, sizeof(zero)); UT_ASSERT(!cluster_semantic_activation_qvotec_poll_record_cas(&request)); UT_ASSERT_EQ(memcmp(&request, &zero, sizeof(request)), 0); - UT_ASSERT(semantic_activation_record_cas_mailbox_poll_completion( - request_seq, &result)); + UT_ASSERT(semantic_activation_record_cas_mailbox_poll_completion(request_seq, &result)); UT_ASSERT_EQ(result, CLUSTER_SEMANTIC_ACTIVATION_QUORUM_HOLD); } @@ -5048,31 +4630,26 @@ UT_TEST(test_93fe_record_cas_submit_requires_pending_formation) test_gate_reset(); UT_ASSERT(test_encode_prepare_record_cas(0, desired)); - UT_ASSERT(!semantic_activation_record_cas_mailbox_submit( - 0, 0, desired, &request_seq)); + UT_ASSERT(!semantic_activation_record_cas_mailbox_submit(0, 0, desired, &request_seq)); test_gate_reset(); test_gate_publish(2, 0, 0, test_current_epoch, false); - UT_ASSERT(semantic_activation_utility_mailbox_submit( - CLUSTER_SEMANTIC_ENABLE_ALL, 0, - CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, 0, 0, - &utility_request_seq)); + UT_ASSERT(semantic_activation_utility_mailbox_submit(CLUSTER_SEMANTIC_ENABLE_ALL, 0, + CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, 0, + 0, &utility_request_seq)); UT_ASSERT(test_encode_prepare_record_cas(0, desired)); - UT_ASSERT(!semantic_activation_record_cas_mailbox_submit( - 0, 0, desired, &request_seq)); + UT_ASSERT(!semantic_activation_record_cas_mailbox_submit(0, 0, desired, &request_seq)); test_gate_reset(); test_gate_publish(2, 0, 0, test_current_epoch, false); - UT_ASSERT(semantic_activation_utility_mailbox_submit( - CLUSTER_SEMANTIC_ENABLE_ALL, 0, - CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, 0, 0, - &utility_request_seq)); + UT_ASSERT(semantic_activation_utility_mailbox_submit(CLUSTER_SEMANTIC_ENABLE_ALL, 0, + CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, 0, + 0, &utility_request_seq)); UT_ASSERT(test_encode_prepare_record_cas(0, desired)); test_admitted_snapshot_valid = true; test_admitted_snapshot_episode = valid_d13_admitted_episode(); test_admitted_snapshot_marker = valid_d13_admitted_marker(); - UT_ASSERT(semantic_activation_record_cas_mailbox_submit( - 0, 0, desired, &request_seq)); + UT_ASSERT(semantic_activation_record_cas_mailbox_submit(0, 0, desired, &request_seq)); } UT_TEST(test_93ff_utility_slot_drift_rejects_pending_record_cas) @@ -5085,19 +4662,16 @@ UT_TEST(test_93ff_utility_slot_drift_rejects_pending_record_cas) uint64 utility_request_seq; test_gate_reset(); - UT_ASSERT(test_submit_current_prepare_record_cas( - &request_seq, desired)); - utility_request_seq = pg_atomic_read_u64( - &SemanticActivationUtilityMailbox->utility_request_seq); - pg_atomic_write_u64( - &SemanticActivationUtilityMailbox->utility_request_seq, - utility_request_seq + 1); + UT_ASSERT(test_submit_current_prepare_record_cas(&request_seq, desired)); + utility_request_seq + = pg_atomic_read_u64(&SemanticActivationUtilityMailbox->utility_request_seq); + pg_atomic_write_u64(&SemanticActivationUtilityMailbox->utility_request_seq, + utility_request_seq + 1); memset(&request, 0xa5, sizeof(request)); memset(&zero, 0, sizeof(zero)); UT_ASSERT(!cluster_semantic_activation_qvotec_poll_record_cas(&request)); UT_ASSERT_EQ(memcmp(&request, &zero, sizeof(request)), 0); - UT_ASSERT(semantic_activation_record_cas_mailbox_poll_completion( - request_seq, &result)); + UT_ASSERT(semantic_activation_record_cas_mailbox_poll_completion(request_seq, &result)); UT_ASSERT_EQ(result, CLUSTER_SEMANTIC_ACTIVATION_QUORUM_HOLD); } @@ -5110,15 +4684,13 @@ UT_TEST(test_93fg_admitted_basis_drift_rejects_pending_record_cas) uint64 request_seq = 0; test_gate_reset(); - UT_ASSERT(test_submit_current_prepare_record_cas( - &request_seq, desired)); + UT_ASSERT(test_submit_current_prepare_record_cas(&request_seq, desired)); test_admitted_snapshot_valid = false; memset(&request, 0xa5, sizeof(request)); memset(&zero, 0, sizeof(zero)); UT_ASSERT(!cluster_semantic_activation_qvotec_poll_record_cas(&request)); UT_ASSERT_EQ(memcmp(&request, &zero, sizeof(request)), 0); - UT_ASSERT(semantic_activation_record_cas_mailbox_poll_completion( - request_seq, &result)); + UT_ASSERT(semantic_activation_record_cas_mailbox_poll_completion(request_seq, &result)); UT_ASSERT_EQ(result, CLUSTER_SEMANTIC_ACTIVATION_QUORUM_HOLD); } @@ -5131,15 +4703,13 @@ UT_TEST(test_93fh_utility_expected_generation_drift_rejects_pending_record_cas) uint64 request_seq = 0; test_gate_reset(); - UT_ASSERT(test_submit_current_prepare_record_cas( - &request_seq, desired)); + UT_ASSERT(test_submit_current_prepare_record_cas(&request_seq, desired)); SemanticActivationUtilityMailbox->utility_expected_record_generation++; memset(&request, 0xa5, sizeof(request)); memset(&zero, 0, sizeof(zero)); UT_ASSERT(!cluster_semantic_activation_qvotec_poll_record_cas(&request)); UT_ASSERT_EQ(memcmp(&request, &zero, sizeof(request)), 0); - UT_ASSERT(semantic_activation_record_cas_mailbox_poll_completion( - request_seq, &result)); + UT_ASSERT(semantic_activation_record_cas_mailbox_poll_completion(request_seq, &result)); UT_ASSERT_EQ(result, CLUSTER_SEMANTIC_ACTIVATION_QUORUM_HOLD); test_gate_reset(); } @@ -5153,15 +4723,13 @@ UT_TEST(test_93fi_pgsa_generation_drift_rejects_pending_record_cas) uint64 request_seq = 0; test_gate_reset(); - UT_ASSERT(test_submit_current_prepare_record_cas( - &request_seq, desired)); + UT_ASSERT(test_submit_current_prepare_record_cas(&request_seq, desired)); test_gate_publish(2, 0, 1, test_current_epoch, false); memset(&request, 0xa5, sizeof(request)); memset(&zero, 0, sizeof(zero)); UT_ASSERT(!cluster_semantic_activation_qvotec_poll_record_cas(&request)); UT_ASSERT_EQ(memcmp(&request, &zero, sizeof(request)), 0); - UT_ASSERT(semantic_activation_record_cas_mailbox_poll_completion( - request_seq, &result)); + UT_ASSERT(semantic_activation_record_cas_mailbox_poll_completion(request_seq, &result)); UT_ASSERT_EQ(result, CLUSTER_SEMANTIC_ACTIVATION_QUORUM_HOLD); test_gate_reset(); } @@ -5169,17 +4737,13 @@ UT_TEST(test_93fi_pgsa_generation_drift_rejects_pending_record_cas) UT_TEST(test_94_rf_deferred_enable_may_drive_only_preopen_pgrd_setup) { UT_ASSERT(semantic_activation_preopen_pgrd_setup_allowed( - CLUSTER_SEMANTIC_ENABLE_ALL, - CLUSTER_SEMANTIC_ACTIVATION_RF_DEFERRED)); - UT_ASSERT(semantic_activation_preopen_pgrd_setup_allowed( - CLUSTER_SEMANTIC_ENABLE_ALL, - CLUSTER_SEMANTIC_ACTIVATION_OK)); + CLUSTER_SEMANTIC_ENABLE_ALL, CLUSTER_SEMANTIC_ACTIVATION_RF_DEFERRED)); + UT_ASSERT(semantic_activation_preopen_pgrd_setup_allowed(CLUSTER_SEMANTIC_ENABLE_ALL, + CLUSTER_SEMANTIC_ACTIVATION_OK)); UT_ASSERT(!semantic_activation_preopen_pgrd_setup_allowed( - CLUSTER_SEMANTIC_DISABLE_ALL, - CLUSTER_SEMANTIC_ACTIVATION_RF_DEFERRED)); + CLUSTER_SEMANTIC_DISABLE_ALL, CLUSTER_SEMANTIC_ACTIVATION_RF_DEFERRED)); UT_ASSERT(!semantic_activation_preopen_pgrd_setup_allowed( - CLUSTER_SEMANTIC_ENABLE_ALL, - CLUSTER_SEMANTIC_ACTIVATION_QUORUM_HOLD)); + CLUSTER_SEMANTIC_ENABLE_ALL, CLUSTER_SEMANTIC_ACTIVATION_QUORUM_HOLD)); } UT_TEST(test_94a_public_submit_cannot_bypass_busy_lmon_mailbox) @@ -5191,17 +4755,15 @@ UT_TEST(test_94a_public_submit_cannot_bypass_busy_lmon_mailbox) test_admitted_snapshot_valid = true; test_admitted_snapshot_episode = valid_d13_admitted_episode(); test_admitted_snapshot_marker = valid_d13_admitted_marker(); - UT_ASSERT(semantic_activation_utility_mailbox_submit( - CLUSTER_SEMANTIC_ENABLE_ALL, 0, - CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, 0, 0, &request_seq)); + UT_ASSERT(semantic_activation_utility_mailbox_submit(CLUSTER_SEMANTIC_ENABLE_ALL, 0, + CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, 0, + 0, &request_seq)); memset(&refusal, 0, sizeof(refusal)); - UT_ASSERT_EQ(cluster_semantic_activation_submit( - CLUSTER_SEMANTIC_ENABLE_ALL, &refusal), + UT_ASSERT_EQ(cluster_semantic_activation_submit(CLUSTER_SEMANTIC_ENABLE_ALL, &refusal), CLUSTER_SEMANTIC_ACTIVATION_QUORUM_HOLD); UT_ASSERT_EQ(refusal.result, CLUSTER_SEMANTIC_ACTIVATION_QUORUM_HOLD); UT_ASSERT_EQ(refusal.expected_generation, UINT64_C(0)); - UT_ASSERT_EQ(pg_atomic_read_u64( - &SemanticActivationShmem->record_cas_request_seq), UINT64_C(0)); + UT_ASSERT_EQ(pg_atomic_read_u64(&SemanticActivationShmem->record_cas_request_seq), UINT64_C(0)); test_gate_reset(); } @@ -5223,24 +4785,19 @@ UT_TEST(test_94ab_initial_clean_candidate_can_enter_sample_without_replacement) test_initial_clean_snapshot.members_lo = UINT64_C(0x0f); test_initial_clean_snapshot.members_hi = 0; test_initial_clean_snapshot.arbiter_node = 0; - test_initial_clean_snapshot.arbiter_incarnation - = UINT64_C(0x445566778899aabb); + test_initial_clean_snapshot.arbiter_incarnation = UINT64_C(0x445566778899aabb); test_system_identifier = system_identifier; cluster_shared_data_dir = "/cluster-share"; - test_local_capability_word - = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS; + test_local_capability_word = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS; test_peer_capability_word_sample_ok = true; - test_peer_capability_word - = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS; + test_peer_capability_word = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS; test_peer_capability_generation = 19; for (node = 0; node < 4; node++) - test_remote_admitted_incarnations[node] - = UINT64_C(0x445566778899aabb) + (uint64)node; + test_remote_admitted_incarnations[node] = UINT64_C(0x445566778899aabb) + (uint64)node; for (node = 0; node < 4; node++) test_initial_clean_snapshot.admitted_incarnation[node] = test_remote_admitted_incarnations[node]; - test_last_admitted_incarnation - = test_remote_admitted_incarnations[cluster_node_id]; + test_last_admitted_incarnation = test_remote_admitted_incarnations[cluster_node_id]; memset(&descriptor, 0, sizeof(descriptor)); descriptor.descriptor_incarnation = 1; @@ -5250,15 +4807,12 @@ UT_TEST(test_94ab_initial_clean_candidate_can_enter_sample_without_replacement) memset(descriptor.root_uuid, 0x5a, sizeof(descriptor.root_uuid)); descriptor.namespace_id = 1; descriptor.system_identifier = system_identifier; - UT_ASSERT(cluster_undo_root_descriptor_encode( - &descriptor, test_pgrd_candidate)); + UT_ASSERT(cluster_undo_root_descriptor_encode(&descriptor, test_pgrd_candidate)); test_pgrd_candidate_state = CLUSTER_UNDO_SMGR_ROOT_MIRROR_EXACT; - UT_ASSERT(semantic_activation_pgrd_snapshot_publish( - test_pgrd_candidate)); + UT_ASSERT(semantic_activation_pgrd_snapshot_publish(test_pgrd_candidate)); memset(&refusal, 0, sizeof(refusal)); - UT_ASSERT_EQ(r4_pre_prepare_readiness(0, &refusal), - CLUSTER_SEMANTIC_ACTIVATION_OK); + UT_ASSERT_EQ(r4_pre_prepare_readiness(0, &refusal), CLUSTER_SEMANTIC_ACTIVATION_OK); UT_ASSERT_EQ(refusal.result, CLUSTER_SEMANTIC_ACTIVATION_OK); UT_ASSERT_EQ(test_admitted_snapshot_calls, 1); UT_ASSERT(test_initial_clean_snapshot_valid); @@ -5288,26 +4842,21 @@ UT_TEST(test_94ac_initial_clean_prepare_waits_for_exact_full_sample_ack) test_initial_clean_snapshot.formation_epoch = test_current_epoch; test_initial_clean_snapshot.members_lo = UINT64_C(0x0f); test_initial_clean_snapshot.arbiter_node = 0; - test_initial_clean_snapshot.arbiter_incarnation - = test_qvotec_self_incarnation; + test_initial_clean_snapshot.arbiter_incarnation = test_qvotec_self_incarnation; test_system_identifier = system_identifier; cluster_shared_data_dir = "/cluster-share"; - test_local_capability_word - = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS; + test_local_capability_word = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS; test_peer_capability_word_sample_ok = true; - test_peer_capability_word - = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS; + test_peer_capability_word = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS; test_peer_capability_generation = 19; test_peer_capability_matches = true; for (node = 0; node < 4; node++) { - test_remote_admitted_incarnations[node] - = test_qvotec_self_incarnation + (uint64)node; + test_remote_admitted_incarnations[node] = test_qvotec_self_incarnation + (uint64)node; test_initial_clean_snapshot.admitted_incarnation[node] = test_remote_admitted_incarnations[node]; test_send_results[node] = CLUSTER_IC_SEND_DONE; } - test_last_admitted_incarnation - = test_initial_clean_snapshot.admitted_incarnation[0]; + test_last_admitted_incarnation = test_initial_clean_snapshot.admitted_incarnation[0]; memset(&descriptor, 0, sizeof(descriptor)); descriptor.descriptor_incarnation = 1; descriptor.root_kind = CLUSTER_UNDO_ROOT_KIND_SHARED; @@ -5316,29 +4865,23 @@ UT_TEST(test_94ac_initial_clean_prepare_waits_for_exact_full_sample_ack) memset(descriptor.root_uuid, 0x6b, sizeof(descriptor.root_uuid)); descriptor.namespace_id = 1; descriptor.system_identifier = system_identifier; - UT_ASSERT(cluster_undo_root_descriptor_encode( - &descriptor, test_pgrd_candidate)); + UT_ASSERT(cluster_undo_root_descriptor_encode(&descriptor, test_pgrd_candidate)); test_pgrd_candidate_state = CLUSTER_UNDO_SMGR_ROOT_MIRROR_EXACT; - UT_ASSERT(semantic_activation_pgrd_snapshot_publish( - test_pgrd_candidate)); - UT_ASSERT(semantic_activation_utility_mailbox_submit( - CLUSTER_SEMANTIC_ENABLE_ALL, 0, - CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, 0, 0, - &request_seq)); + UT_ASSERT(semantic_activation_pgrd_snapshot_publish(test_pgrd_candidate)); + UT_ASSERT(semantic_activation_utility_mailbox_submit(CLUSTER_SEMANTIC_ENABLE_ALL, 0, + CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, 0, + 0, &request_seq)); cluster_semantic_activation_lmon_tick(); memset(&pgrd_request, 0, sizeof(pgrd_request)); - UT_ASSERT(cluster_semantic_activation_qvotec_poll_undo_root_descriptor( - &pgrd_request)); + UT_ASSERT(cluster_semantic_activation_qvotec_poll_undo_root_descriptor(&pgrd_request)); UT_ASSERT(cluster_semantic_activation_qvotec_complete_undo_root_descriptor( pgrd_request.request_seq, CLUSTER_SEMANTIC_ACTIVATION_OK)); cluster_semantic_activation_lmon_tick(); UT_ASSERT(semantic_activation_ack_table_snapshot(&table)); - UT_ASSERT_EQ(table.stage, - CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_SAMPLE); + UT_ASSERT_EQ(table.stage, CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_SAMPLE); memset(&cas_request, 0, sizeof(cas_request)); - UT_ASSERT(!cluster_semantic_activation_qvotec_poll_record_cas( - &cas_request)); + UT_ASSERT(!cluster_semantic_activation_qvotec_poll_record_cas(&cas_request)); for (node = 1; node < 4; node++) { memset(&ack, 0, sizeof(ack)); @@ -5350,15 +4893,12 @@ UT_TEST(test_94ac_initial_clean_prepare_waits_for_exact_full_sample_ack) ack.transition_epoch = test_current_epoch; ack.record_generation = 1; ack.round_nonce = request_seq; - ack.target_feature_bitmap - = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1; + ack.target_feature_bitmap = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1; ack.admitted_members_lo = UINT64_C(0x0f); ack.boot_id = test_remote_admitted_incarnations[node]; ack.admitted_incarnation = ack.boot_id; - ack.capability_word - = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS; - UT_ASSERT(cluster_semantic_activation_ack_wire_encode( - &ack, payload)); + ack.capability_word = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS; + UT_ASSERT(cluster_semantic_activation_ack_wire_encode(&ack, payload)); memset(&envelope, 0, sizeof(envelope)); envelope.msg_type = PGRAC_IC_MSG_SEMANTIC_ACTIVATION_ACK_V1; envelope.source_node_id = (uint32)node; @@ -5369,31 +4909,24 @@ UT_TEST(test_94ac_initial_clean_prepare_waits_for_exact_full_sample_ack) } cluster_semantic_activation_lmon_tick(); UT_ASSERT(semantic_activation_ack_table_snapshot(&table)); - UT_ASSERT_EQ(table.flags, - CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID - | CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE); + UT_ASSERT_EQ(table.flags, CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID + | CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE); memset(&pgrd_request, 0, sizeof(pgrd_request)); - UT_ASSERT(cluster_semantic_activation_qvotec_poll_undo_root_descriptor( - &pgrd_request)); + UT_ASSERT(cluster_semantic_activation_qvotec_poll_undo_root_descriptor(&pgrd_request)); UT_ASSERT(cluster_semantic_activation_qvotec_complete_undo_root_descriptor( pgrd_request.request_seq, CLUSTER_SEMANTIC_ACTIVATION_OK)); cluster_semantic_activation_lmon_tick(); memset(&cas_request, 0, sizeof(cas_request)); - UT_ASSERT(cluster_semantic_activation_qvotec_poll_record_cas( - &cas_request)); + UT_ASSERT(cluster_semantic_activation_qvotec_poll_record_cas(&cas_request)); UT_ASSERT_EQ(cas_request.expected_generation, UINT64_C(0)); memset(&desired, 0, sizeof(desired)); - UT_ASSERT(cluster_semantic_activation_record_decode( - cas_request.desired_bytes, &desired, NULL)); + UT_ASSERT(cluster_semantic_activation_record_decode(cas_request.desired_bytes, &desired, NULL)); UT_ASSERT_EQ(desired.phase, CLUSTER_SEMANTIC_PHASE_PREPARE); UT_ASSERT_EQ(desired.record_generation, UINT64_C(1)); - clean_incarnation - = test_initial_clean_snapshot.admitted_incarnation[2]; - test_initial_clean_snapshot.admitted_incarnation[2] - = clean_incarnation + 1; + clean_incarnation = test_initial_clean_snapshot.admitted_incarnation[2]; + test_initial_clean_snapshot.admitted_incarnation[2] = clean_incarnation + 1; memset(&cas_request, 0, sizeof(cas_request)); - UT_ASSERT(!cluster_semantic_activation_qvotec_poll_record_cas( - &cas_request)); + UT_ASSERT(!cluster_semantic_activation_qvotec_poll_record_cas(&cas_request)); test_gate_reset(); } @@ -5415,25 +4948,20 @@ UT_TEST(test_94ad_initial_clean_basis_is_revalidated_for_commit_and_open) test_initial_clean_snapshot.formation_epoch = test_current_epoch; test_initial_clean_snapshot.members_lo = UINT64_C(0x0f); test_initial_clean_snapshot.arbiter_node = 0; - test_initial_clean_snapshot.arbiter_incarnation - = test_qvotec_self_incarnation; + test_initial_clean_snapshot.arbiter_incarnation = test_qvotec_self_incarnation; test_system_identifier = system_identifier; cluster_shared_data_dir = "/cluster-share"; - test_local_capability_word - = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS; + test_local_capability_word = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS; test_peer_capability_word_sample_ok = true; - test_peer_capability_word - = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS; + test_peer_capability_word = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS; test_peer_capability_generation = 19; test_peer_capability_matches = true; for (node = 0; node < 4; node++) { - test_remote_admitted_incarnations[node] - = test_qvotec_self_incarnation + (uint64)node; + test_remote_admitted_incarnations[node] = test_qvotec_self_incarnation + (uint64)node; test_initial_clean_snapshot.admitted_incarnation[node] = test_remote_admitted_incarnations[node]; } - test_last_admitted_incarnation - = test_initial_clean_snapshot.admitted_incarnation[0]; + test_last_admitted_incarnation = test_initial_clean_snapshot.admitted_incarnation[0]; memset(&descriptor, 0, sizeof(descriptor)); descriptor.descriptor_incarnation = 1; descriptor.root_kind = CLUSTER_UNDO_ROOT_KIND_SHARED; @@ -5442,15 +4970,12 @@ UT_TEST(test_94ad_initial_clean_basis_is_revalidated_for_commit_and_open) memset(descriptor.root_uuid, 0x3d, sizeof(descriptor.root_uuid)); descriptor.namespace_id = 1; descriptor.system_identifier = system_identifier; - UT_ASSERT(cluster_undo_root_descriptor_encode( - &descriptor, test_pgrd_candidate)); + UT_ASSERT(cluster_undo_root_descriptor_encode(&descriptor, test_pgrd_candidate)); test_pgrd_candidate_state = CLUSTER_UNDO_SMGR_ROOT_MIRROR_EXACT; - UT_ASSERT(semantic_activation_pgrd_snapshot_publish( - test_pgrd_candidate)); - UT_ASSERT(semantic_activation_utility_mailbox_submit( - CLUSTER_SEMANTIC_ENABLE_ALL, 0, - CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, 0, 0, - &request_seq)); + UT_ASSERT(semantic_activation_pgrd_snapshot_publish(test_pgrd_candidate)); + UT_ASSERT(semantic_activation_utility_mailbox_submit(CLUSTER_SEMANTIC_ENABLE_ALL, 0, + CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, 0, + 0, &request_seq)); table = SemanticActivationAckTable; memset(table, 0, sizeof(*table)); @@ -5464,23 +4989,18 @@ UT_TEST(test_94ad_initial_clean_basis_is_revalidated_for_commit_and_open) table->observed_members_lo = UINT64_C(0x0f); table->transition_epoch = test_current_epoch; table->record_generation = 1; - table->target_feature_bitmap - = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1; + table->target_feature_bitmap = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1; table->capability_sample_digest = digest; for (node = 0; node < 4; node++) { if (node == 0) { UT_ASSERT(semantic_activation_ack_self_tuple( - node, test_local_capability_word, test_current_epoch, 1, - &table->expected[node])); + node, test_local_capability_word, test_current_epoch, 1, &table->expected[node])); } else { table->expected[node].node_id = (uint32)node; - table->expected[node].boot_id - = test_remote_admitted_incarnations[node]; - table->expected[node].admitted_incarnation - = test_remote_admitted_incarnations[node]; + table->expected[node].boot_id = test_remote_admitted_incarnations[node]; + table->expected[node].admitted_incarnation = test_remote_admitted_incarnations[node]; table->expected[node].control_connection_generation = 19; - table->expected[node].capability_word - = test_peer_capability_word; + table->expected[node].capability_word = test_peer_capability_word; table->expected[node].capability_generation = 19; table->expected[node].transition_epoch = test_current_epoch; table->expected[node].record_generation = 1; @@ -5497,18 +5017,15 @@ UT_TEST(test_94ad_initial_clean_basis_is_revalidated_for_commit_and_open) desired.phase = CLUSTER_SEMANTIC_PHASE_COMMIT; desired.record_generation = 2; desired.transition_epoch = test_current_epoch; - desired.target_feature_bitmap - = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1; + desired.target_feature_bitmap = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1; desired.admitted_members_lo = UINT64_C(0x0f); desired.capability_sample_digest = digest; desired.coordinator_node = 0; desired.coordinator_incarnation = test_qvotec_self_incarnation; test_gate_publish(2, 0, 1, test_current_epoch, true); - UT_ASSERT(semantic_activation_record_cas_formation_matches( - &formation, &desired)); + UT_ASSERT(semantic_activation_record_cas_formation_matches(&formation, &desired)); - table->stage - = CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_COMMIT_APPLIED; + table->stage = CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_COMMIT_APPLIED; table->record_generation = 2; for (node = 0; node < 4; node++) { table->expected[node].record_generation = 2; @@ -5518,8 +5035,7 @@ UT_TEST(test_94ad_initial_clean_basis_is_revalidated_for_commit_and_open) desired.phase = CLUSTER_SEMANTIC_PHASE_OPEN; desired.record_generation = 3; test_gate_publish(4, 0, 2, test_current_epoch, true); - UT_ASSERT(semantic_activation_record_cas_formation_matches( - &formation, &desired)); + UT_ASSERT(semantic_activation_record_cas_formation_matches(&formation, &desired)); test_gate_reset(); } @@ -5546,21 +5062,17 @@ UT_TEST(test_94ae_initial_clean_stage_callbacks_require_exact_current_basis) test_initial_clean_snapshot.arbiter_incarnation = 0; test_system_identifier = system_identifier; cluster_shared_data_dir = "/cluster-share"; - test_local_capability_word - = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS; + test_local_capability_word = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS; test_peer_capability_word_sample_ok = true; - test_peer_capability_word - = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS; + test_peer_capability_word = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS; test_peer_capability_generation = 19; test_peer_capability_matches = true; for (node = 0; node < 4; node++) { - test_remote_admitted_incarnations[node] - = test_qvotec_self_incarnation + (uint64)node; + test_remote_admitted_incarnations[node] = test_qvotec_self_incarnation + (uint64)node; test_initial_clean_snapshot.admitted_incarnation[node] = test_remote_admitted_incarnations[node]; } - test_last_admitted_incarnation - = test_initial_clean_snapshot.admitted_incarnation[0]; + test_last_admitted_incarnation = test_initial_clean_snapshot.admitted_incarnation[0]; memset(&pgrd, 0, sizeof(pgrd)); pgrd.descriptor_incarnation = 1; @@ -5569,11 +5081,9 @@ UT_TEST(test_94ae_initial_clean_stage_callbacks_require_exact_current_basis) memset(pgrd.root_uuid, 0x47, sizeof(pgrd.root_uuid)); pgrd.namespace_id = 1; pgrd.system_identifier = system_identifier; - UT_ASSERT(cluster_undo_root_descriptor_encode( - &pgrd, test_pgrd_candidate)); + UT_ASSERT(cluster_undo_root_descriptor_encode(&pgrd, test_pgrd_candidate)); test_pgrd_candidate_state = CLUSTER_UNDO_SMGR_ROOT_MIRROR_EXACT; - UT_ASSERT(semantic_activation_pgrd_snapshot_publish( - test_pgrd_candidate)); + UT_ASSERT(semantic_activation_pgrd_snapshot_publish(test_pgrd_candidate)); table = SemanticActivationAckTable; memset(table, 0, sizeof(*table)); @@ -5585,47 +5095,37 @@ UT_TEST(test_94ae_initial_clean_stage_callbacks_require_exact_current_basis) table->expected_members_lo = UINT64_C(0x0f); table->transition_epoch = test_current_epoch; table->record_generation = 1; - table->target_feature_bitmap - = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1; + table->target_feature_bitmap = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1; table->capability_sample_digest = UINT64_C(0x3141592653589793); for (node = 0; node < 4; node++) { if (node == 0) { UT_ASSERT(semantic_activation_ack_self_tuple( - node, test_local_capability_word, test_current_epoch, 1, - &table->expected[node])); + node, test_local_capability_word, test_current_epoch, 1, &table->expected[node])); } else { table->expected[node].node_id = (uint32)node; - table->expected[node].boot_id - = test_remote_admitted_incarnations[node]; - table->expected[node].admitted_incarnation - = test_remote_admitted_incarnations[node]; + table->expected[node].boot_id = test_remote_admitted_incarnations[node]; + table->expected[node].admitted_incarnation = test_remote_admitted_incarnations[node]; table->expected[node].control_connection_generation = 19; - table->expected[node].capability_word - = test_peer_capability_word; + table->expected[node].capability_word = test_peer_capability_word; table->expected[node].capability_generation = 19; table->expected[node].transition_epoch = test_current_epoch; table->expected[node].record_generation = 1; } } test_gate_publish(2, 0, 1, test_current_epoch, true); - UT_ASSERT_EQ(descriptor->prepare_target(1), - CLUSTER_SEMANTIC_ACTIVATION_OK); + UT_ASSERT_EQ(descriptor->prepare_target(1), CLUSTER_SEMANTIC_ACTIVATION_OK); - original_incarnation - = test_initial_clean_snapshot.admitted_incarnation[2]; + original_incarnation = test_initial_clean_snapshot.admitted_incarnation[2]; test_initial_clean_snapshot.admitted_incarnation[2]++; - UT_ASSERT_EQ(descriptor->prepare_target(1), - CLUSTER_SEMANTIC_ACTIVATION_RF_DEFERRED); - test_initial_clean_snapshot.admitted_incarnation[2] - = original_incarnation; + UT_ASSERT_EQ(descriptor->prepare_target(1), CLUSTER_SEMANTIC_ACTIVATION_RF_DEFERRED); + test_initial_clean_snapshot.admitted_incarnation[2] = original_incarnation; table->stage = CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_COMMIT_APPLIED; table->record_generation = 2; for (node = 0; node < 4; node++) table->expected[node].record_generation = 2; test_gate_publish(4, 0, 2, test_current_epoch, true); - UT_ASSERT_EQ(descriptor->apply_target_closed(2), - CLUSTER_SEMANTIC_ACTIVATION_OK); + UT_ASSERT_EQ(descriptor->apply_target_closed(2), CLUSTER_SEMANTIC_ACTIVATION_OK); table->stage = CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_OPEN_APPLIED; table->flags = CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID @@ -5636,14 +5136,11 @@ UT_TEST(test_94ae_initial_clean_stage_callbacks_require_exact_current_basis) table->expected[node].record_generation = 3; table->observed[node] = table->expected[node]; } - UT_ASSERT_EQ(descriptor->open_target_admission(3), - CLUSTER_SEMANTIC_ACTIVATION_OK); + UT_ASSERT_EQ(descriptor->open_target_admission(3), CLUSTER_SEMANTIC_ACTIVATION_OK); table->observed[3].capability_generation++; - UT_ASSERT_EQ(descriptor->open_target_admission(3), - CLUSTER_SEMANTIC_ACTIVATION_RF_DEFERRED); - UT_ASSERT_EQ(descriptor->revert_source_closed(3), - CLUSTER_SEMANTIC_ACTIVATION_RF_DEFERRED); + UT_ASSERT_EQ(descriptor->open_target_admission(3), CLUSTER_SEMANTIC_ACTIVATION_RF_DEFERRED); + UT_ASSERT_EQ(descriptor->revert_source_closed(3), CLUSTER_SEMANTIC_ACTIVATION_RF_DEFERRED); test_gate_reset(); } @@ -5657,19 +5154,16 @@ UT_TEST(test_94b_utility_cannot_close_source_before_prepare_commit) test_admitted_snapshot_valid = true; test_admitted_snapshot_episode = valid_d13_admitted_episode(); test_admitted_snapshot_marker = valid_d13_admitted_marker(); - UT_ASSERT(semantic_activation_utility_mailbox_submit( - CLUSTER_SEMANTIC_ENABLE_ALL, 0, - CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, 0, 0, &request_seq)); + UT_ASSERT(semantic_activation_utility_mailbox_submit(CLUSTER_SEMANTIC_ENABLE_ALL, 0, + CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, 0, + 0, &request_seq)); cluster_semantic_activation_lmon_tick(); memset(&refusal, 0, sizeof(refusal)); - UT_ASSERT(semantic_activation_utility_mailbox_poll_completion( - request_seq, &refusal)); + UT_ASSERT(semantic_activation_utility_mailbox_poll_completion(request_seq, &refusal)); UT_ASSERT_EQ(refusal.result, CLUSTER_SEMANTIC_ACTIVATION_RF_DEFERRED); - UT_ASSERT_EQ(pg_atomic_read_u64(test_gate_u64(TEST_GATE_SEQ_OFFSET)), - UINT64_C(2)); + UT_ASSERT_EQ(pg_atomic_read_u64(test_gate_u64(TEST_GATE_SEQ_OFFSET)), UINT64_C(2)); UT_ASSERT_EQ(pg_atomic_read_u32(test_gate_u32(TEST_GATE_CLOSED_OFFSET)), 0); - UT_ASSERT_EQ(pg_atomic_read_u64( - &SemanticActivationShmem->record_cas_request_seq), UINT64_C(0)); + UT_ASSERT_EQ(pg_atomic_read_u64(&SemanticActivationShmem->record_cas_request_seq), UINT64_C(0)); } UT_TEST(test_95_dormant_target_enter_has_no_token) @@ -5714,31 +5208,23 @@ UT_TEST(test_97_old_epoch_completion_is_inert_and_requires_revalidation) uint64 utility_request_seq = 0; test_gate_reset(); - test_gate_publish(2, CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, 7, - test_current_epoch, true); + test_gate_publish(2, CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, 7, test_current_epoch, true); test_admitted_snapshot_valid = true; test_admitted_snapshot_episode = valid_d13_admitted_episode(); test_admitted_snapshot_marker = valid_d13_admitted_marker(); UT_ASSERT(semantic_activation_utility_mailbox_submit( - CLUSTER_SEMANTIC_ENABLE_ALL, - CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, + CLUSTER_SEMANTIC_ENABLE_ALL, CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1 | CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1, - 0, 7, - &utility_request_seq)); - before_active_bits = pg_atomic_read_u64( - &SemanticActivationShmem->active_bits); - before_generation = pg_atomic_read_u64( - &SemanticActivationShmem->record_generation); - before_closed = pg_atomic_read_u32( - &SemanticActivationShmem->transition_closed) != 0; + 0, 7, &utility_request_seq)); + before_active_bits = pg_atomic_read_u64(&SemanticActivationShmem->active_bits); + before_generation = pg_atomic_read_u64(&SemanticActivationShmem->record_generation); + before_closed = pg_atomic_read_u32(&SemanticActivationShmem->transition_closed) != 0; memset(&desired_record, 0, sizeof(desired_record)); - desired_record.source_feature_bitmap - = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1; - desired_record.target_feature_bitmap - = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1 - | CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1; + desired_record.source_feature_bitmap = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1; + desired_record.target_feature_bitmap = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1 + | CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1; desired_record.transition_epoch = test_current_epoch; desired_record.record_generation = 8; desired_record.coordinator_node = (uint32)cluster_node_id; @@ -5753,8 +5239,7 @@ UT_TEST(test_97_old_epoch_completion_is_inert_and_requires_revalidation) test_current_epoch++; UT_ASSERT(semantic_activation_record_cas_mailbox_poll_completion(seq, &result)); UT_ASSERT_EQ(result, CLUSTER_SEMANTIC_ACTIVATION_QUORUM_HOLD); - UT_ASSERT_EQ(pg_atomic_read_u64(&SemanticActivationShmem->active_bits), - before_active_bits); + UT_ASSERT_EQ(pg_atomic_read_u64(&SemanticActivationShmem->active_bits), before_active_bits); UT_ASSERT_EQ(pg_atomic_read_u64(&SemanticActivationShmem->record_generation), before_generation); UT_ASSERT_EQ(pg_atomic_read_u32(&SemanticActivationShmem->transition_closed) != 0, @@ -5778,14 +5263,10 @@ UT_TEST(test_99_shared_gate_layout_and_bootstrap_are_fail_closed) { test_gate_reset(); UT_ASSERT_EQ(test_shmem_requested_size, TEST_SEMANTIC_GATE_SHMEM_BYTES); - UT_ASSERT_EQ(test_utility_mailbox_requested_size, - TEST_SEMANTIC_UTILITY_MAILBOX_BYTES); - UT_ASSERT_EQ(test_ack_table_requested_size, - TEST_SEMANTIC_ACK_TABLE_BYTES); - UT_ASSERT_EQ(test_pgrd_snapshot_requested_size, - TEST_SEMANTIC_PGRD_SNAPSHOT_BYTES); - UT_ASSERT_EQ(test_bit22_latch_requested_size, - TEST_SEMANTIC_BIT22_LATCH_BYTES); + UT_ASSERT_EQ(test_utility_mailbox_requested_size, TEST_SEMANTIC_UTILITY_MAILBOX_BYTES); + UT_ASSERT_EQ(test_ack_table_requested_size, TEST_SEMANTIC_ACK_TABLE_BYTES); + UT_ASSERT_EQ(test_pgrd_snapshot_requested_size, TEST_SEMANTIC_PGRD_SNAPSHOT_BYTES); + UT_ASSERT_EQ(test_bit22_latch_requested_size, TEST_SEMANTIC_BIT22_LATCH_BYTES); UT_ASSERT_EQ(cluster_semantic_activation_shmem_size(), TEST_SEMANTIC_GATE_SHMEM_BYTES + TEST_SEMANTIC_UTILITY_MAILBOX_BYTES + TEST_SEMANTIC_ACK_TABLE_BYTES + TEST_SEMANTIC_PGRD_SNAPSHOT_BYTES @@ -5796,8 +5277,8 @@ UT_TEST(test_99_shared_gate_layout_and_bootstrap_are_fail_closed) UT_ASSERT(!cluster_r4_bit22_cutover_active()); UT_ASSERT(SemanticActivationAckTable == (ClusterSemanticActivationAckTableV1 *)test_semantic_ack_table.bytes); - UT_ASSERT(semantic_activation_bytes_are_zero( - test_semantic_ack_table.bytes, sizeof(test_semantic_ack_table.bytes))); + UT_ASSERT(semantic_activation_bytes_are_zero(test_semantic_ack_table.bytes, + sizeof(test_semantic_ack_table.bytes))); UT_ASSERT_EQ(pg_atomic_read_u64(&SemanticActivationAckTable->publication_seq), 0); UT_ASSERT_EQ(pg_atomic_read_u64(test_gate_u64(TEST_GATE_SEQ_OFFSET)), 0); UT_ASSERT_EQ(pg_atomic_read_u64(test_gate_u64(TEST_GATE_ACTIVE_BITS_OFFSET)), 0); @@ -5810,16 +5291,14 @@ UT_TEST(test_99a_existing_ack_table_is_preserved_on_attach) { test_gate_reset(); pg_atomic_write_u64(&SemanticActivationAckTable->publication_seq, 8); - SemanticActivationAckTable->stage - = CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_BARRIER; + SemanticActivationAckTable->stage = CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_BARRIER; test_shmem_found = true; test_utility_mailbox_found = true; test_ack_table_found = true; cluster_semantic_activation_shmem_init(); UT_ASSERT_EQ(pg_atomic_read_u64(&SemanticActivationAckTable->publication_seq), 8); - UT_ASSERT_EQ(SemanticActivationAckTable->stage, - CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_BARRIER); + UT_ASSERT_EQ(SemanticActivationAckTable->stage, CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_BARRIER); } UT_TEST(test_100_source_enter_owns_shared_debt_and_epoch_token) @@ -5899,23 +5378,20 @@ UT_TEST(test_102a_terminal_census_is_the_only_inactive_target_exception) CLUSTER_SEMANTIC_ADMISSION_OK); UT_ASSERT(token.entered); UT_ASSERT_EQ(token.side, CLUSTER_SEMANTIC_TARGET_SIDE); - UT_ASSERT_EQ(pg_atomic_read_u32( - test_gate_inflight(CLUSTER_SEMANTIC_TARGET_SIDE, 0)), 1); + UT_ASSERT_EQ(pg_atomic_read_u32(test_gate_inflight(CLUSTER_SEMANTIC_TARGET_SIDE, 0)), 1); UT_ASSERT(cluster_semantic_activation_recheck_r4_terminal_census(&token)); UT_ASSERT(!cluster_semantic_activation_recheck(&token)); test_gate_publish(4, 0, 14, test_current_epoch, false); UT_ASSERT(!cluster_semantic_activation_recheck_r4_terminal_census(&token)); cluster_semantic_activation_leave(&token); - UT_ASSERT_EQ(pg_atomic_read_u32( - test_gate_inflight(CLUSTER_SEMANTIC_TARGET_SIDE, 0)), 0); + UT_ASSERT_EQ(pg_atomic_read_u32(test_gate_inflight(CLUSTER_SEMANTIC_TARGET_SIDE, 0)), 0); test_gate_publish(6, 0, 15, test_current_epoch, true); UT_ASSERT_EQ(cluster_semantic_activation_enter_r4_terminal_census(&token), CLUSTER_SEMANTIC_ADMISSION_CLOSED); UT_ASSERT(!token.entered); - UT_ASSERT_EQ(pg_atomic_read_u32( - test_gate_inflight(CLUSTER_SEMANTIC_TARGET_SIDE, 0)), 0); + UT_ASSERT_EQ(pg_atomic_read_u32(test_gate_inflight(CLUSTER_SEMANTIC_TARGET_SIDE, 0)), 0); } UT_TEST(test_103_epoch_drift_invalidates_recheck_without_losing_debt) @@ -6026,7 +5502,7 @@ UT_TEST(test_109_lmon_without_validated_majority_remains_closed) test_current_epoch); UT_ASSERT_EQ(pg_atomic_read_u32(test_gate_u32(TEST_GATE_CLOSED_OFFSET)), 1); UT_ASSERT_EQ(cluster_semantic_activation_enter(CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, - CLUSTER_SEMANTIC_SOURCE_SIDE, &token), + CLUSTER_SEMANTIC_SOURCE_SIDE, &token), CLUSTER_SEMANTIC_ADMISSION_CLOSED); UT_ASSERT(!token.entered); } @@ -6045,10 +5521,8 @@ UT_TEST(test_109a_lmon_publishes_source_open_only_after_majority_legacy_zero) UT_ASSERT(cluster_semantic_activation_qvotec_complete_record_read( request.request_seq, CLUSTER_SEMANTIC_ACTIVATION_OK, true, zero)); cluster_semantic_activation_lmon_tick(); - UT_ASSERT_EQ(pg_atomic_read_u64(test_gate_u64(TEST_GATE_ACTIVE_BITS_OFFSET)), - UINT64_C(0)); - UT_ASSERT_EQ(pg_atomic_read_u64( - test_gate_u64(TEST_GATE_RECORD_GENERATION_OFFSET)), + UT_ASSERT_EQ(pg_atomic_read_u64(test_gate_u64(TEST_GATE_ACTIVE_BITS_OFFSET)), UINT64_C(0)); + UT_ASSERT_EQ(pg_atomic_read_u64(test_gate_u64(TEST_GATE_RECORD_GENERATION_OFFSET)), UINT64_C(0)); UT_ASSERT_EQ(pg_atomic_read_u64(test_gate_u64(TEST_GATE_FORMATION_EPOCH_OFFSET)), test_current_epoch); @@ -6110,7 +5584,7 @@ UT_TEST(test_111_formation_change_closes_before_debt_drain) test_gate_reset(); test_gate_publish(2, 0, 0, test_current_epoch, false); UT_ASSERT_EQ(cluster_semantic_activation_enter(CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, - CLUSTER_SEMANTIC_SOURCE_SIDE, &old_token), + CLUSTER_SEMANTIC_SOURCE_SIDE, &old_token), CLUSTER_SEMANTIC_ADMISSION_OK); test_current_epoch++; cluster_semantic_activation_lmon_tick(); @@ -6119,7 +5593,7 @@ UT_TEST(test_111_formation_change_closes_before_debt_drain) UT_ASSERT_EQ(pg_atomic_read_u32(test_gate_u32(TEST_GATE_CLOSED_OFFSET)), 1); UT_ASSERT_EQ(pg_atomic_read_u32(test_gate_inflight(CLUSTER_SEMANTIC_SOURCE_SIDE, 0)), 1); UT_ASSERT_EQ(cluster_semantic_activation_enter(CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, - CLUSTER_SEMANTIC_SOURCE_SIDE, &new_token), + CLUSTER_SEMANTIC_SOURCE_SIDE, &new_token), CLUSTER_SEMANTIC_ADMISSION_CLOSED); if (new_token.entered) cluster_semantic_activation_leave(&new_token); @@ -6132,27 +5606,21 @@ UT_TEST(test_111a_close_source_publishes_closed_before_debt_result) test_gate_reset(); test_gate_publish(2, 0, 25, test_current_epoch, false); - UT_ASSERT_EQ(cluster_semantic_activation_enter( - CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, - CLUSTER_SEMANTIC_SOURCE_SIDE, &token), + UT_ASSERT_EQ(cluster_semantic_activation_enter(CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, + CLUSTER_SEMANTIC_SOURCE_SIDE, &token), CLUSTER_SEMANTIC_ADMISSION_OK); UT_ASSERT_EQ(r4_descriptor.close_source_admission(25), CLUSTER_SEMANTIC_ACTIVATION_DEBT_NONZERO); - UT_ASSERT_EQ(pg_atomic_read_u64(test_gate_u64(TEST_GATE_SEQ_OFFSET)), - UINT64_C(4)); - UT_ASSERT_EQ(pg_atomic_read_u64(test_gate_u64(TEST_GATE_ACTIVE_BITS_OFFSET)), - UINT64_C(0)); - UT_ASSERT_EQ(pg_atomic_read_u64( - test_gate_u64(TEST_GATE_RECORD_GENERATION_OFFSET)), + UT_ASSERT_EQ(pg_atomic_read_u64(test_gate_u64(TEST_GATE_SEQ_OFFSET)), UINT64_C(4)); + UT_ASSERT_EQ(pg_atomic_read_u64(test_gate_u64(TEST_GATE_ACTIVE_BITS_OFFSET)), UINT64_C(0)); + UT_ASSERT_EQ(pg_atomic_read_u64(test_gate_u64(TEST_GATE_RECORD_GENERATION_OFFSET)), UINT64_C(25)); UT_ASSERT_EQ(pg_atomic_read_u64(test_gate_u64(TEST_GATE_FORMATION_EPOCH_OFFSET)), test_current_epoch); UT_ASSERT_EQ(pg_atomic_read_u32(test_gate_u32(TEST_GATE_CLOSED_OFFSET)), 1); cluster_semantic_activation_leave(&token); - UT_ASSERT_EQ(r4_descriptor.close_source_admission(25), - CLUSTER_SEMANTIC_ACTIVATION_OK); - UT_ASSERT_EQ(pg_atomic_read_u64(test_gate_u64(TEST_GATE_SEQ_OFFSET)), - UINT64_C(4)); + UT_ASSERT_EQ(r4_descriptor.close_source_admission(25), CLUSTER_SEMANTIC_ACTIVATION_OK); + UT_ASSERT_EQ(pg_atomic_read_u64(test_gate_u64(TEST_GATE_SEQ_OFFSET)), UINT64_C(4)); } UT_TEST(test_112_enter_samples_second_snapshot_before_epoch) @@ -6179,7 +5647,7 @@ UT_TEST(test_113_recheck_samples_snapshot_before_epoch) test_gate_reset(); test_gate_publish(2, 0, 22, test_current_epoch, false); UT_ASSERT_EQ(cluster_semantic_activation_enter(CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, - CLUSTER_SEMANTIC_SOURCE_SIDE, &token), + CLUSTER_SEMANTIC_SOURCE_SIDE, &token), CLUSTER_SEMANTIC_ADMISSION_OK); test_read_barrier_count = 0; test_advance_epoch_on_read_barrier = 2; @@ -6195,20 +5663,19 @@ UT_TEST(test_114_peer_open_matcher_stays_closed_until_d13_ack_table) test_gate_reset(); test_gate_publish(2, CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, 23, test_current_epoch, false); UT_ASSERT_EQ(cluster_semantic_activation_enter(CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, - CLUSTER_SEMANTIC_TARGET_SIDE, &token), + CLUSTER_SEMANTIC_TARGET_SIDE, &token), CLUSTER_SEMANTIC_ADMISSION_OK); test_peer_capability_matches = true; UT_ASSERT(!cluster_semantic_activation_peer_open_matches( - &token, 7, PGRAC_IC_HELLO_CAP_SEMANTIC_ACTIVATION_V1 - | PGRAC_IC_HELLO_CAP_R4_SYNC_CR_V1 - | PGRAC_IC_HELLO_CAP_CANDIDATE2_CORRECTED_A1_V1 - | PGRAC_IC_HELLO_CAP_UNDO_ROOT_DESCRIPTOR_V1, + &token, 7, + PGRAC_IC_HELLO_CAP_SEMANTIC_ACTIVATION_V1 | PGRAC_IC_HELLO_CAP_R4_SYNC_CR_V1 + | PGRAC_IC_HELLO_CAP_CANDIDATE2_CORRECTED_A1_V1 + | PGRAC_IC_HELLO_CAP_UNDO_ROOT_DESCRIPTOR_V1, 0)); UT_ASSERT_EQ(test_peer_capability_match_calls, 1); UT_ASSERT_EQ(test_peer_capability_match_peer, 7); UT_ASSERT_EQ(test_peer_capability_match_caps, - PGRAC_IC_HELLO_CAP_SEMANTIC_ACTIVATION_V1 - | PGRAC_IC_HELLO_CAP_R4_SYNC_CR_V1 + PGRAC_IC_HELLO_CAP_SEMANTIC_ACTIVATION_V1 | PGRAC_IC_HELLO_CAP_R4_SYNC_CR_V1 | PGRAC_IC_HELLO_CAP_CANDIDATE2_CORRECTED_A1_V1 | PGRAC_IC_HELLO_CAP_UNDO_ROOT_DESCRIPTOR_V1); UT_ASSERT_EQ(test_peer_capability_match_generation, 0); @@ -6221,14 +5688,14 @@ UT_TEST(test_115_peer_open_matcher_rejects_invalid_inputs_before_capability_matc ClusterSemanticAdmissionToken source_token; ClusterSemanticAdmissionToken wrong_feature_token; uint32 required_caps = PGRAC_IC_HELLO_CAP_SEMANTIC_ACTIVATION_V1 - | PGRAC_IC_HELLO_CAP_R4_SYNC_CR_V1 - | PGRAC_IC_HELLO_CAP_CANDIDATE2_CORRECTED_A1_V1 - | PGRAC_IC_HELLO_CAP_UNDO_ROOT_DESCRIPTOR_V1; + | PGRAC_IC_HELLO_CAP_R4_SYNC_CR_V1 + | PGRAC_IC_HELLO_CAP_CANDIDATE2_CORRECTED_A1_V1 + | PGRAC_IC_HELLO_CAP_UNDO_ROOT_DESCRIPTOR_V1; test_gate_reset(); test_gate_publish(2, 0, 24, test_current_epoch, false); UT_ASSERT_EQ(cluster_semantic_activation_enter(CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, - CLUSTER_SEMANTIC_SOURCE_SIDE, &source_token), + CLUSTER_SEMANTIC_SOURCE_SIDE, &source_token), CLUSTER_SEMANTIC_ADMISSION_OK); UT_ASSERT(!cluster_semantic_activation_peer_open_matches(&source_token, 7, required_caps, 0)); UT_ASSERT_EQ(test_peer_capability_match_calls, 0); @@ -6237,19 +5704,19 @@ UT_TEST(test_115_peer_open_matcher_rejects_invalid_inputs_before_capability_matc test_gate_reset(); test_gate_publish(2, CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, 24, test_current_epoch, false); UT_ASSERT_EQ(cluster_semantic_activation_enter(CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, - CLUSTER_SEMANTIC_TARGET_SIDE, &target_token), + CLUSTER_SEMANTIC_TARGET_SIDE, &target_token), CLUSTER_SEMANTIC_ADMISSION_OK); wrong_feature_token = target_token; wrong_feature_token.feature_bit = 0; test_peer_capability_matches = true; UT_ASSERT(!cluster_semantic_activation_peer_open_matches(NULL, 7, required_caps, 0)); - UT_ASSERT(!cluster_semantic_activation_peer_open_matches(&(ClusterSemanticAdmissionToken){0}, 7, - required_caps, 0)); - UT_ASSERT(!cluster_semantic_activation_peer_open_matches(&wrong_feature_token, 7, - required_caps, 0)); + UT_ASSERT(!cluster_semantic_activation_peer_open_matches(&(ClusterSemanticAdmissionToken){ 0 }, + 7, required_caps, 0)); + UT_ASSERT( + !cluster_semantic_activation_peer_open_matches(&wrong_feature_token, 7, required_caps, 0)); UT_ASSERT(!cluster_semantic_activation_peer_open_matches(&target_token, -1, required_caps, 0)); UT_ASSERT(!cluster_semantic_activation_peer_open_matches(&target_token, CLUSTER_MAX_NODES, - required_caps, 0)); + required_caps, 0)); UT_ASSERT(!cluster_semantic_activation_peer_open_matches(&target_token, 7, 0, 0)); UT_ASSERT_EQ(test_peer_capability_match_calls, 0); test_current_epoch++; @@ -6286,8 +5753,7 @@ UT_TEST(test_116_formation_lmon_consumes_phase3_handoff) message.identity1 = UINT64_C(9002); message.body.phase3.jcmk_generation = UINT64_C(41); message.body.phase3.episode_state_generation = UINT32_C(17); - message.grammar_fingerprint - = CANDIDATE2_CORRECTED_A1_GRAMMAR_FINGERPRINT; + message.grammar_fingerprint = CANDIDATE2_CORRECTED_A1_GRAMMAR_FINGERPRINT; UT_ASSERT(cluster_replacement_wire_encode(&message, bytes)); memset(&envelope, 0, sizeof(envelope)); envelope.msg_type = PGRAC_IC_MSG_GES_REQUEST; @@ -6295,18 +5761,16 @@ UT_TEST(test_116_formation_lmon_consumes_phase3_handoff) envelope.dest_node_id = 1; envelope.epoch = test_current_epoch; envelope.payload_length = sizeof(bytes); - UT_ASSERT_EQ((int)cluster_replacement_wire_phase3_ingress_local( - &envelope, bytes, sizeof(bytes), message.target_node_id, 1, - test_current_epoch, 9), + UT_ASSERT_EQ((int)cluster_replacement_wire_phase3_ingress_local(&envelope, bytes, sizeof(bytes), + message.target_node_id, 1, + test_current_epoch, 9), (int)CLUSTER_REPLACEMENT_PHASE3_INGRESS_ENQUEUED); cluster_semantic_activation_lmon_tick(); UT_ASSERT_EQ((int)cluster_replacement_phase3_handoff_pending_local(), 0); UT_ASSERT_EQ(test_phase3_observe_calls, 1); - UT_ASSERT_EQ(memcmp(&test_phase3_observed_item.message, &message, - sizeof(message)), - 0); + UT_ASSERT_EQ(memcmp(&test_phase3_observed_item.message, &message, sizeof(message)), 0); UT_ASSERT_EQ(test_phase3_observed_item.authenticated_source_node_id, 3); UT_ASSERT_EQ(test_phase3_observed_item.local_receiver_node_id, 1); UT_ASSERT_EQ((int)test_phase3_observed_item.control_connection_generation, 9); @@ -6340,13 +5804,11 @@ UT_TEST(test_117_formation_lmon_submits_exact_mirror_candidate_to_qvotec) descriptor.root_uuid[i] = (uint8)(0x40 + i); descriptor.namespace_id = 1; descriptor.system_identifier = system_identifier; - UT_ASSERT(cluster_undo_root_descriptor_encode( - &descriptor, test_pgrd_candidate)); + UT_ASSERT(cluster_undo_root_descriptor_encode(&descriptor, test_pgrd_candidate)); test_pgrd_candidate_state = CLUSTER_UNDO_SMGR_ROOT_MIRROR_EXACT; - UT_ASSERT(semantic_activation_utility_mailbox_submit( - CLUSTER_SEMANTIC_ENABLE_ALL, 0, - CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, 0, 0, - &utility_request_seq)); + UT_ASSERT(semantic_activation_utility_mailbox_submit(CLUSTER_SEMANTIC_ENABLE_ALL, 0, + CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, 0, + 0, &utility_request_seq)); formation = (ClusterSemanticFormationBinding){ .utility_request_seq = utility_request_seq, .formation_epoch = test_current_epoch, @@ -6354,15 +5816,14 @@ UT_TEST(test_117_formation_lmon_submits_exact_mirror_candidate_to_qvotec) .expected_record_generation = 0, }; - UT_ASSERT(semantic_activation_lmon_submit_pgrd_exact_retry( - "/unused/pg_undo", &formation, system_identifier, &request_seq)); + UT_ASSERT(semantic_activation_lmon_submit_pgrd_exact_retry("/unused/pg_undo", &formation, + system_identifier, &request_seq)); UT_ASSERT_EQ(request_seq, 1); memset(&request, 0, sizeof(request)); - UT_ASSERT(cluster_semantic_activation_qvotec_poll_undo_root_descriptor( - &request)); + UT_ASSERT(cluster_semantic_activation_qvotec_poll_undo_root_descriptor(&request)); UT_ASSERT_EQ(request.system_identifier, system_identifier); - UT_ASSERT_EQ(memcmp(request.desired_bytes, test_pgrd_candidate, - sizeof(test_pgrd_candidate)), 0); + UT_ASSERT_EQ(memcmp(request.desired_bytes, test_pgrd_candidate, sizeof(test_pgrd_candidate)), + 0); test_gate_reset(); } @@ -6392,49 +5853,38 @@ UT_TEST(test_118_formation_lmon_waits_for_pgrd_majority_before_carrier) descriptor.root_uuid[i] = (uint8)(0x70 + i); descriptor.namespace_id = 1; descriptor.system_identifier = system_identifier; - UT_ASSERT(cluster_undo_root_descriptor_encode( - &descriptor, test_pgrd_candidate)); + UT_ASSERT(cluster_undo_root_descriptor_encode(&descriptor, test_pgrd_candidate)); test_pgrd_candidate_state = CLUSTER_UNDO_SMGR_ROOT_MIRROR_EXACT; - UT_ASSERT(semantic_activation_utility_mailbox_submit( - CLUSTER_SEMANTIC_ENABLE_ALL, 0, - CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, 0, 0, - &utility_request_seq)); + UT_ASSERT(semantic_activation_utility_mailbox_submit(CLUSTER_SEMANTIC_ENABLE_ALL, 0, + CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, 0, + 0, &utility_request_seq)); cluster_semantic_activation_lmon_tick(); memset(&refusal, 0, sizeof(refusal)); - UT_ASSERT(!semantic_activation_utility_mailbox_poll_completion( - utility_request_seq, &refusal)); + UT_ASSERT(!semantic_activation_utility_mailbox_poll_completion(utility_request_seq, &refusal)); memset(&pgrd_request, 0, sizeof(pgrd_request)); - pgrd_polled - = cluster_semantic_activation_qvotec_poll_undo_root_descriptor( - &pgrd_request); + pgrd_polled = cluster_semantic_activation_qvotec_poll_undo_root_descriptor(&pgrd_request); UT_ASSERT(pgrd_polled); UT_ASSERT_EQ(test_pgrd_candidate_read_calls, 1); - UT_ASSERT_STR_EQ(test_pgrd_candidate_root_directory, - "/cluster-share/pg_undo"); - UT_ASSERT_EQ(pg_atomic_read_u64(test_gate_u64(TEST_GATE_SEQ_OFFSET)), - UINT64_C(2)); - UT_ASSERT_EQ(pg_atomic_read_u32(test_gate_u32(TEST_GATE_CLOSED_OFFSET)), - 0); + UT_ASSERT_STR_EQ(test_pgrd_candidate_root_directory, "/cluster-share/pg_undo"); + UT_ASSERT_EQ(pg_atomic_read_u64(test_gate_u64(TEST_GATE_SEQ_OFFSET)), UINT64_C(2)); + UT_ASSERT_EQ(pg_atomic_read_u32(test_gate_u32(TEST_GATE_CLOSED_OFFSET)), 0); if (pgrd_polled) { UT_ASSERT_EQ(pgrd_request.system_identifier, system_identifier); - UT_ASSERT_EQ(memcmp(pgrd_request.desired_bytes, test_pgrd_candidate, - sizeof(test_pgrd_candidate)), 0); - UT_ASSERT( - cluster_semantic_activation_qvotec_complete_undo_root_descriptor( - pgrd_request.request_seq, CLUSTER_SEMANTIC_ACTIVATION_OK)); + UT_ASSERT_EQ( + memcmp(pgrd_request.desired_bytes, test_pgrd_candidate, sizeof(test_pgrd_candidate)), + 0); + UT_ASSERT(cluster_semantic_activation_qvotec_complete_undo_root_descriptor( + pgrd_request.request_seq, CLUSTER_SEMANTIC_ACTIVATION_OK)); } cluster_semantic_activation_lmon_tick(); memset(&refusal, 0, sizeof(refusal)); - UT_ASSERT(semantic_activation_utility_mailbox_poll_completion( - utility_request_seq, &refusal)); + UT_ASSERT(semantic_activation_utility_mailbox_poll_completion(utility_request_seq, &refusal)); UT_ASSERT_EQ(refusal.result, CLUSTER_SEMANTIC_ACTIVATION_RF_DEFERRED); UT_ASSERT_EQ(test_pgrd_candidate_read_calls, 2); - UT_ASSERT_EQ(pg_atomic_read_u64(test_gate_u64(TEST_GATE_SEQ_OFFSET)), - UINT64_C(2)); - UT_ASSERT_EQ(pg_atomic_read_u32(test_gate_u32(TEST_GATE_CLOSED_OFFSET)), - 0); + UT_ASSERT_EQ(pg_atomic_read_u64(test_gate_u64(TEST_GATE_SEQ_OFFSET)), UINT64_C(2)); + UT_ASSERT_EQ(pg_atomic_read_u32(test_gate_u32(TEST_GATE_CLOSED_OFFSET)), 0); test_gate_reset(); } @@ -6458,39 +5908,31 @@ UT_TEST(test_119_formation_lmon_reads_zero_quorum_before_fresh_pgrd) test_admitted_snapshot_marker = valid_d13_admitted_marker(); test_system_identifier = system_identifier; cluster_shared_data_dir = "/cluster-share"; - UT_ASSERT(semantic_activation_utility_mailbox_submit( - CLUSTER_SEMANTIC_ENABLE_ALL, 0, - CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, 0, 0, - &utility_request_seq)); + UT_ASSERT(semantic_activation_utility_mailbox_submit(CLUSTER_SEMANTIC_ENABLE_ALL, 0, + CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, 0, + 0, &utility_request_seq)); cluster_semantic_activation_lmon_tick(); memset(&refusal, 0, sizeof(refusal)); - UT_ASSERT(!semantic_activation_utility_mailbox_poll_completion( - utility_request_seq, &refusal)); + UT_ASSERT(!semantic_activation_utility_mailbox_poll_completion(utility_request_seq, &refusal)); memset(&read_request, 0, sizeof(read_request)); - UT_ASSERT( - cluster_semantic_activation_qvotec_poll_undo_root_descriptor_read( - &read_request)); + UT_ASSERT(cluster_semantic_activation_qvotec_poll_undo_root_descriptor_read(&read_request)); UT_ASSERT_EQ(read_request.system_identifier, system_identifier); UT_ASSERT_EQ(test_pgrd_candidate_read_calls, 1); UT_ASSERT_EQ(test_strong_random_calls, 0); UT_ASSERT_EQ(test_pgrd_publish_calls, 0); memset(&provision_request, 0, sizeof(provision_request)); - UT_ASSERT(!cluster_semantic_activation_qvotec_poll_undo_root_descriptor( - &provision_request)); - UT_ASSERT( - cluster_semantic_activation_qvotec_complete_undo_root_descriptor_read( - read_request.request_seq, - CLUSTER_UNDO_ROOT_DESCRIPTOR_UNPROVISIONED, zero)); + UT_ASSERT(!cluster_semantic_activation_qvotec_poll_undo_root_descriptor(&provision_request)); + UT_ASSERT(cluster_semantic_activation_qvotec_complete_undo_root_descriptor_read( + read_request.request_seq, CLUSTER_UNDO_ROOT_DESCRIPTOR_UNPROVISIONED, zero)); cluster_semantic_activation_lmon_tick(); UT_ASSERT_EQ(test_strong_random_calls, 1); UT_ASSERT_EQ(test_pgrd_publish_calls, 1); - UT_ASSERT_STR_EQ(test_pgrd_publish_root_directory, - "/cluster-share/pg_undo"); - UT_ASSERT_EQ(cluster_undo_root_descriptor_decode( - test_pgrd_published, system_identifier, &descriptor), - CLUSTER_UNDO_ROOT_DESCRIPTOR_VALID); + UT_ASSERT_STR_EQ(test_pgrd_publish_root_directory, "/cluster-share/pg_undo"); + UT_ASSERT_EQ( + cluster_undo_root_descriptor_decode(test_pgrd_published, system_identifier, &descriptor), + CLUSTER_UNDO_ROOT_DESCRIPTOR_VALID); UT_ASSERT_EQ(descriptor.descriptor_incarnation, UINT64_C(1)); UT_ASSERT_EQ(descriptor.root_kind, CLUSTER_UNDO_ROOT_KIND_SHARED); UT_ASSERT_EQ(descriptor.owner_node, -1); @@ -6500,32 +5942,25 @@ UT_TEST(test_119_formation_lmon_reads_zero_quorum_before_fresh_pgrd) UT_ASSERT_EQ(descriptor.root_uuid[i], UINT8_C(0xa6)); memset(&provision_request, 0, sizeof(provision_request)); provision_polled - = cluster_semantic_activation_qvotec_poll_undo_root_descriptor( - &provision_request); + = cluster_semantic_activation_qvotec_poll_undo_root_descriptor(&provision_request); UT_ASSERT(provision_polled); if (provision_polled) { - UT_ASSERT_EQ(memcmp(provision_request.desired_bytes, - test_pgrd_published, - sizeof(test_pgrd_published)), 0); - UT_ASSERT( - cluster_semantic_activation_qvotec_complete_undo_root_descriptor( - provision_request.request_seq, - CLUSTER_SEMANTIC_ACTIVATION_OK)); + UT_ASSERT_EQ(memcmp(provision_request.desired_bytes, test_pgrd_published, + sizeof(test_pgrd_published)), + 0); + UT_ASSERT(cluster_semantic_activation_qvotec_complete_undo_root_descriptor( + provision_request.request_seq, CLUSTER_SEMANTIC_ACTIVATION_OK)); } memset(&refusal, 0, sizeof(refusal)); - UT_ASSERT(!semantic_activation_utility_mailbox_poll_completion( - utility_request_seq, &refusal)); + UT_ASSERT(!semantic_activation_utility_mailbox_poll_completion(utility_request_seq, &refusal)); cluster_semantic_activation_lmon_tick(); memset(&refusal, 0, sizeof(refusal)); - UT_ASSERT(semantic_activation_utility_mailbox_poll_completion( - utility_request_seq, &refusal)); + UT_ASSERT(semantic_activation_utility_mailbox_poll_completion(utility_request_seq, &refusal)); UT_ASSERT_EQ(refusal.result, CLUSTER_SEMANTIC_ACTIVATION_RF_DEFERRED); UT_ASSERT_EQ(test_pgrd_candidate_read_calls, 2); - UT_ASSERT_EQ(pg_atomic_read_u64(test_gate_u64(TEST_GATE_SEQ_OFFSET)), - UINT64_C(2)); - UT_ASSERT_EQ(pg_atomic_read_u32(test_gate_u32(TEST_GATE_CLOSED_OFFSET)), - 0); + UT_ASSERT_EQ(pg_atomic_read_u64(test_gate_u64(TEST_GATE_SEQ_OFFSET)), UINT64_C(2)); + UT_ASSERT_EQ(pg_atomic_read_u32(test_gate_u32(TEST_GATE_CLOSED_OFFSET)), 0); test_gate_reset(); } @@ -6548,15 +5983,12 @@ UT_TEST(test_120_authority_without_mirror_holds_before_carrier) test_admitted_snapshot_marker = valid_d13_admitted_marker(); test_system_identifier = system_identifier; cluster_shared_data_dir = "/cluster-share"; - UT_ASSERT(semantic_activation_utility_mailbox_submit( - CLUSTER_SEMANTIC_ENABLE_ALL, 0, - CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, 0, 0, - &utility_request_seq)); + UT_ASSERT(semantic_activation_utility_mailbox_submit(CLUSTER_SEMANTIC_ENABLE_ALL, 0, + CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, 0, + 0, &utility_request_seq)); cluster_semantic_activation_lmon_tick(); memset(&read_request, 0, sizeof(read_request)); - UT_ASSERT( - cluster_semantic_activation_qvotec_poll_undo_root_descriptor_read( - &read_request)); + UT_ASSERT(cluster_semantic_activation_qvotec_poll_undo_root_descriptor_read(&read_request)); memset(&descriptor, 0, sizeof(descriptor)); descriptor.descriptor_incarnation = 1; @@ -6568,25 +6000,19 @@ UT_TEST(test_120_authority_without_mirror_holds_before_carrier) descriptor.namespace_id = 1; descriptor.system_identifier = system_identifier; UT_ASSERT(cluster_undo_root_descriptor_encode(&descriptor, authority)); - UT_ASSERT( - cluster_semantic_activation_qvotec_complete_undo_root_descriptor_read( - read_request.request_seq, CLUSTER_UNDO_ROOT_DESCRIPTOR_VALID, - authority)); + UT_ASSERT(cluster_semantic_activation_qvotec_complete_undo_root_descriptor_read( + read_request.request_seq, CLUSTER_UNDO_ROOT_DESCRIPTOR_VALID, authority)); cluster_semantic_activation_lmon_tick(); memset(&refusal, 0, sizeof(refusal)); - UT_ASSERT(semantic_activation_utility_mailbox_poll_completion( - utility_request_seq, &refusal)); + UT_ASSERT(semantic_activation_utility_mailbox_poll_completion(utility_request_seq, &refusal)); UT_ASSERT_EQ(refusal.result, CLUSTER_SEMANTIC_ACTIVATION_QUORUM_HOLD); UT_ASSERT_EQ(test_strong_random_calls, 0); UT_ASSERT_EQ(test_pgrd_publish_calls, 0); memset(&provision_request, 0, sizeof(provision_request)); - UT_ASSERT(!cluster_semantic_activation_qvotec_poll_undo_root_descriptor( - &provision_request)); - UT_ASSERT_EQ(pg_atomic_read_u64(test_gate_u64(TEST_GATE_SEQ_OFFSET)), - UINT64_C(2)); - UT_ASSERT_EQ(pg_atomic_read_u32(test_gate_u32(TEST_GATE_CLOSED_OFFSET)), - 0); + UT_ASSERT(!cluster_semantic_activation_qvotec_poll_undo_root_descriptor(&provision_request)); + UT_ASSERT_EQ(pg_atomic_read_u64(test_gate_u64(TEST_GATE_SEQ_OFFSET)), UINT64_C(2)); + UT_ASSERT_EQ(pg_atomic_read_u32(test_gate_u32(TEST_GATE_CLOSED_OFFSET)), 0); test_gate_reset(); } @@ -6614,28 +6040,22 @@ UT_TEST(test_121_out_of_quorum_coordinator_cannot_submit_pgrd) memset(descriptor.root_uuid, 0x9a, sizeof(descriptor.root_uuid)); descriptor.namespace_id = 1; descriptor.system_identifier = system_identifier; - UT_ASSERT(cluster_undo_root_descriptor_encode( - &descriptor, test_pgrd_candidate)); + UT_ASSERT(cluster_undo_root_descriptor_encode(&descriptor, test_pgrd_candidate)); test_pgrd_candidate_state = CLUSTER_UNDO_SMGR_ROOT_MIRROR_EXACT; test_qvotec_in_quorum = false; - UT_ASSERT(semantic_activation_utility_mailbox_submit( - CLUSTER_SEMANTIC_ENABLE_ALL, 0, - CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, 0, 0, - &utility_request_seq)); + UT_ASSERT(semantic_activation_utility_mailbox_submit(CLUSTER_SEMANTIC_ENABLE_ALL, 0, + CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, 0, + 0, &utility_request_seq)); cluster_semantic_activation_lmon_tick(); memset(&refusal, 0, sizeof(refusal)); - UT_ASSERT(semantic_activation_utility_mailbox_poll_completion( - utility_request_seq, &refusal)); + UT_ASSERT(semantic_activation_utility_mailbox_poll_completion(utility_request_seq, &refusal)); UT_ASSERT_EQ(refusal.result, CLUSTER_SEMANTIC_ACTIVATION_QUORUM_HOLD); UT_ASSERT_EQ(test_pgrd_candidate_read_calls, 0); memset(&pgrd_request, 0, sizeof(pgrd_request)); - UT_ASSERT(!cluster_semantic_activation_qvotec_poll_undo_root_descriptor( - &pgrd_request)); - UT_ASSERT_EQ(pg_atomic_read_u64(test_gate_u64(TEST_GATE_SEQ_OFFSET)), - UINT64_C(2)); - UT_ASSERT_EQ(pg_atomic_read_u32(test_gate_u32(TEST_GATE_CLOSED_OFFSET)), - 0); + UT_ASSERT(!cluster_semantic_activation_qvotec_poll_undo_root_descriptor(&pgrd_request)); + UT_ASSERT_EQ(pg_atomic_read_u64(test_gate_u64(TEST_GATE_SEQ_OFFSET)), UINT64_C(2)); + UT_ASSERT_EQ(pg_atomic_read_u32(test_gate_u32(TEST_GATE_CLOSED_OFFSET)), 0); test_gate_reset(); } @@ -6666,10 +6086,9 @@ UT_TEST(test_122_epoch_drift_rejects_pending_pgrd_without_mutation) descriptor.namespace_id = 1; descriptor.system_identifier = system_identifier; UT_ASSERT(cluster_undo_root_descriptor_encode(&descriptor, desired)); - UT_ASSERT(semantic_activation_utility_mailbox_submit( - CLUSTER_SEMANTIC_ENABLE_ALL, 0, - CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, 0, 0, - &utility_request_seq)); + UT_ASSERT(semantic_activation_utility_mailbox_submit(CLUSTER_SEMANTIC_ENABLE_ALL, 0, + CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, 0, + 0, &utility_request_seq)); formation = (ClusterSemanticFormationBinding){ .utility_request_seq = utility_request_seq, .formation_epoch = test_current_epoch, @@ -6681,10 +6100,9 @@ UT_TEST(test_122_epoch_drift_rejects_pending_pgrd_without_mutation) test_current_epoch++; memset(&pgrd_request, 0, sizeof(pgrd_request)); - UT_ASSERT(!cluster_semantic_activation_qvotec_poll_undo_root_descriptor( - &pgrd_request)); - UT_ASSERT(cluster_semantic_activation_undo_root_descriptor_mailbox_poll_completion( - request_seq, &result)); + UT_ASSERT(!cluster_semantic_activation_qvotec_poll_undo_root_descriptor(&pgrd_request)); + UT_ASSERT(cluster_semantic_activation_undo_root_descriptor_mailbox_poll_completion(request_seq, + &result)); UT_ASSERT_EQ(result, CLUSTER_SEMANTIC_ACTIVATION_QUORUM_HOLD); test_gate_reset(); } @@ -6716,10 +6134,9 @@ UT_TEST(test_123_incarnation_drift_rejects_pending_pgrd_without_mutation) descriptor.namespace_id = 1; descriptor.system_identifier = system_identifier; UT_ASSERT(cluster_undo_root_descriptor_encode(&descriptor, desired)); - UT_ASSERT(semantic_activation_utility_mailbox_submit( - CLUSTER_SEMANTIC_ENABLE_ALL, 0, - CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, 0, 0, - &utility_request_seq)); + UT_ASSERT(semantic_activation_utility_mailbox_submit(CLUSTER_SEMANTIC_ENABLE_ALL, 0, + CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, 0, + 0, &utility_request_seq)); formation = (ClusterSemanticFormationBinding){ .utility_request_seq = utility_request_seq, .formation_epoch = test_current_epoch, @@ -6731,10 +6148,9 @@ UT_TEST(test_123_incarnation_drift_rejects_pending_pgrd_without_mutation) test_qvotec_self_incarnation++; memset(&pgrd_request, 0, sizeof(pgrd_request)); - UT_ASSERT(!cluster_semantic_activation_qvotec_poll_undo_root_descriptor( - &pgrd_request)); - UT_ASSERT(cluster_semantic_activation_undo_root_descriptor_mailbox_poll_completion( - request_seq, &result)); + UT_ASSERT(!cluster_semantic_activation_qvotec_poll_undo_root_descriptor(&pgrd_request)); + UT_ASSERT(cluster_semantic_activation_undo_root_descriptor_mailbox_poll_completion(request_seq, + &result)); UT_ASSERT_EQ(result, CLUSTER_SEMANTIC_ACTIVATION_QUORUM_HOLD); test_gate_reset(); } @@ -6766,10 +6182,9 @@ UT_TEST(test_124_cold_bootstrap_zero_historical_floor_accepts_live_pgrd_binding) descriptor.namespace_id = 1; descriptor.system_identifier = system_identifier; UT_ASSERT(cluster_undo_root_descriptor_encode(&descriptor, desired)); - UT_ASSERT(semantic_activation_utility_mailbox_submit( - CLUSTER_SEMANTIC_ENABLE_ALL, 0, - CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, 0, 0, - &utility_request_seq)); + UT_ASSERT(semantic_activation_utility_mailbox_submit(CLUSTER_SEMANTIC_ENABLE_ALL, 0, + CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, 0, + 0, &utility_request_seq)); formation = (ClusterSemanticFormationBinding){ .utility_request_seq = utility_request_seq, .formation_epoch = test_current_epoch, @@ -6780,13 +6195,10 @@ UT_TEST(test_124_cold_bootstrap_zero_historical_floor_accepts_live_pgrd_binding) &formation, system_identifier, desired, &request_seq)); memset(&pgrd_request, 0, sizeof(pgrd_request)); - UT_ASSERT(cluster_semantic_activation_qvotec_poll_undo_root_descriptor( - &pgrd_request)); + UT_ASSERT(cluster_semantic_activation_qvotec_poll_undo_root_descriptor(&pgrd_request)); UT_ASSERT_EQ(pgrd_request.request_seq, request_seq); - UT_ASSERT_EQ(pgrd_request.formation.coordinator_incarnation, - test_qvotec_self_incarnation); - UT_ASSERT_EQ(memcmp(pgrd_request.desired_bytes, desired, sizeof(desired)), - 0); + UT_ASSERT_EQ(pgrd_request.formation.coordinator_incarnation, test_qvotec_self_incarnation); + UT_ASSERT_EQ(memcmp(pgrd_request.desired_bytes, desired, sizeof(desired)), 0); test_gate_reset(); } @@ -6834,27 +6246,22 @@ UT_TEST(test_125_pgrd_snapshot_requires_majority_mirror_and_current_admission) descriptor.root_uuid[i] = (uint8)(0x20 + i); descriptor.namespace_id = 1; descriptor.system_identifier = system_identifier; - UT_ASSERT(cluster_undo_root_descriptor_encode( - &descriptor, test_pgrd_candidate)); + UT_ASSERT(cluster_undo_root_descriptor_encode(&descriptor, test_pgrd_candidate)); test_pgrd_candidate_state = CLUSTER_UNDO_SMGR_ROOT_MIRROR_EXACT; - UT_ASSERT(semantic_activation_utility_mailbox_submit( - CLUSTER_SEMANTIC_ENABLE_ALL, 0, - CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, 0, 0, - &utility_request_seq)); + UT_ASSERT(semantic_activation_utility_mailbox_submit(CLUSTER_SEMANTIC_ENABLE_ALL, 0, + CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, 0, + 0, &utility_request_seq)); cluster_semantic_activation_lmon_tick(); memset(&pgrd_request, 0, sizeof(pgrd_request)); - UT_ASSERT(cluster_semantic_activation_qvotec_poll_undo_root_descriptor( - &pgrd_request)); + UT_ASSERT(cluster_semantic_activation_qvotec_poll_undo_root_descriptor(&pgrd_request)); /* A live target token cannot consume the candidate before QVOTEC and * exact mirror proof complete in the same formation episode. */ - test_gate_publish(4, CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, 1, - test_current_epoch, false); - UT_ASSERT_EQ(cluster_semantic_activation_enter( - CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, - CLUSTER_SEMANTIC_TARGET_SIDE, &token), - CLUSTER_SEMANTIC_ADMISSION_OK); + test_gate_publish(4, CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, 1, test_current_epoch, false); + UT_ASSERT_EQ(cluster_semantic_activation_enter(CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, + CLUSTER_SEMANTIC_TARGET_SIDE, &token), + CLUSTER_SEMANTIC_ADMISSION_OK); resolved = (ClusterUndoBlock0ResolvedRoot){ .intent = CLUSTER_UNDO_PATH_MATERIALIZED_LOCAL, .root_id = UINT64_MAX, @@ -6870,14 +6277,12 @@ UT_TEST(test_125_pgrd_snapshot_requires_majority_mirror_and_current_admission) pgrd_request.request_seq, CLUSTER_SEMANTIC_ACTIVATION_OK)); cluster_semantic_activation_lmon_tick(); memset(&refusal, 0, sizeof(refusal)); - UT_ASSERT(semantic_activation_utility_mailbox_poll_completion( - utility_request_seq, &refusal)); + UT_ASSERT(semantic_activation_utility_mailbox_poll_completion(utility_request_seq, &refusal)); UT_ASSERT_EQ(refusal.result, CLUSTER_SEMANTIC_ACTIVATION_RF_DEFERRED); UT_ASSERT_EQ(test_pgrd_candidate_read_calls, 2); - UT_ASSERT_EQ(cluster_semantic_activation_enter( - CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, - CLUSTER_SEMANTIC_SOURCE_SIDE, &token), - CLUSTER_SEMANTIC_ADMISSION_OK); + UT_ASSERT_EQ(cluster_semantic_activation_enter(CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, + CLUSTER_SEMANTIC_SOURCE_SIDE, &token), + CLUSTER_SEMANTIC_ADMISSION_OK); resolved.root_id = UINT64_MAX; UT_ASSERT(cluster_semantic_activation_resolve_shared_undo_root_live_owner_source( &token, CLUSTER_UNDO_PATH_RUNTIME_SHARED, 1, 1, &resolved)); @@ -6889,7 +6294,7 @@ UT_TEST(test_125_pgrd_snapshot_requires_majority_mirror_and_current_admission) /* M4 consumes the same immutable PGRD root while ordinary TARGET remains * dormant; the census token is the sole scoped pre-OPEN exception. */ UT_ASSERT_EQ(cluster_semantic_activation_enter_r4_terminal_census(&token), - CLUSTER_SEMANTIC_ADMISSION_OK); + CLUSTER_SEMANTIC_ADMISSION_OK); resolved.root_id = UINT64_MAX; UT_ASSERT(!cluster_semantic_activation_resolve_shared_undo_root( &token, CLUSTER_UNDO_PATH_RUNTIME_SHARED, 1, 1, &resolved)); @@ -6897,20 +6302,17 @@ UT_TEST(test_125_pgrd_snapshot_requires_majority_mirror_and_current_admission) &token, CLUSTER_UNDO_PATH_MATERIALIZED_LOCAL, 1, 1, &resolved)); UT_ASSERT_EQ(resolved.root_id, UINT64_MAX); UT_ASSERT(!cluster_semantic_activation_resolve_shared_undo_root_r4_terminal_census( - &token, CLUSTER_UNDO_PATH_RUNTIME_SHARED_AUTHORITY_BLOCK0, - 1, 1, &resolved)); + &token, CLUSTER_UNDO_PATH_RUNTIME_SHARED_AUTHORITY_BLOCK0, 1, 1, &resolved)); UT_ASSERT_EQ(resolved.root_id, UINT64_MAX); UT_ASSERT(cluster_semantic_activation_resolve_shared_undo_root_r4_terminal_census( &token, CLUSTER_UNDO_PATH_RUNTIME_SHARED, 1, 1, &resolved)); UT_ASSERT_EQ(resolved.root_id, UINT64_C(32768)); cluster_semantic_activation_leave(&token); - test_gate_publish(8, CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, 1, - test_current_epoch, false); - UT_ASSERT_EQ(cluster_semantic_activation_enter( - CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, - CLUSTER_SEMANTIC_TARGET_SIDE, &token), - CLUSTER_SEMANTIC_ADMISSION_OK); + test_gate_publish(8, CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, 1, test_current_epoch, false); + UT_ASSERT_EQ(cluster_semantic_activation_enter(CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, + CLUSTER_SEMANTIC_TARGET_SIDE, &token), + CLUSTER_SEMANTIC_ADMISSION_OK); UT_ASSERT(!cluster_semantic_activation_resolve_shared_undo_root_live_owner_source( &token, CLUSTER_UNDO_PATH_RUNTIME_SHARED, 1, 1, &resolved)); UT_ASSERT(cluster_semantic_activation_resolve_shared_undo_root( @@ -6921,17 +6323,15 @@ UT_TEST(test_125_pgrd_snapshot_requires_majority_mirror_and_current_admission) /* PGSA movement independently fences the old token without mutating the * root snapshot. A new current token consumes the same PGRD identity. */ - test_gate_publish(10, CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, 2, - test_current_epoch, false); + test_gate_publish(10, CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, 2, test_current_epoch, false); resolved.root_id = UINT64_MAX; UT_ASSERT(!cluster_semantic_activation_resolve_shared_undo_root( &token, CLUSTER_UNDO_PATH_RUNTIME_SHARED, 1, 1, &resolved)); UT_ASSERT_EQ(resolved.root_id, UINT64_MAX); cluster_semantic_activation_leave(&token); - UT_ASSERT_EQ(cluster_semantic_activation_enter( - CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, - CLUSTER_SEMANTIC_TARGET_SIDE, &token), - CLUSTER_SEMANTIC_ADMISSION_OK); + UT_ASSERT_EQ(cluster_semantic_activation_enter(CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, + CLUSTER_SEMANTIC_TARGET_SIDE, &token), + CLUSTER_SEMANTIC_ADMISSION_OK); UT_ASSERT(cluster_semantic_activation_resolve_shared_undo_root( &token, CLUSTER_UNDO_PATH_RUNTIME_SHARED, 1, 1, &resolved)); UT_ASSERT_EQ(resolved.root_id, UINT64_C(32768)); @@ -6943,10 +6343,9 @@ UT_TEST(test_125_pgrd_snapshot_requires_majority_mirror_and_current_admission) test_current_epoch++; cluster_semantic_activation_lmon_tick(); test_gate_publish(12, 0, 0, test_current_epoch, false); - UT_ASSERT_EQ(cluster_semantic_activation_enter( - CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, - CLUSTER_SEMANTIC_SOURCE_SIDE, &token), - CLUSTER_SEMANTIC_ADMISSION_OK); + UT_ASSERT_EQ(cluster_semantic_activation_enter(CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1, + CLUSTER_SEMANTIC_SOURCE_SIDE, &token), + CLUSTER_SEMANTIC_ADMISSION_OK); resolved.root_id = UINT64_MAX; UT_ASSERT(!cluster_semantic_activation_resolve_shared_undo_root_live_owner_source( &token, CLUSTER_UNDO_PATH_RUNTIME_SHARED, 1, 1, &resolved)); @@ -7056,8 +6455,7 @@ ut_open_applied_table_setup(void) table->record_generation = 5; table->expected_members_lo = UINT64_C(0x03); table->expected_members_hi = 0; - table->target_feature_bitmap - = PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1; + table->target_feature_bitmap = PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1; table->capability_sample_digest = UINT64_C(0xabcd); table->flags = CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID; /* The complete-image check derives each non-local member's tuple from @@ -7067,20 +6465,17 @@ ut_open_applied_table_setup(void) if (!cluster_membership_is_member(node)) continue; if (node == cluster_node_id) { - (void)semantic_activation_ack_self_tuple( - node, test_local_capability_word, 7, 5, - &table->expected[node]); + (void)semantic_activation_ack_self_tuple(node, test_local_capability_word, 7, 5, + &table->expected[node]); continue; } memset(&remote, 0, sizeof(remote)); remote.node_id = (uint32)node; remote.boot_id = test_remote_admitted_incarnations[node]; remote.admitted_incarnation = test_remote_admitted_incarnations[node]; - remote.control_connection_generation - = (uint64)test_peer_capability_generation; + remote.control_connection_generation = (uint64)test_peer_capability_generation; remote.capability_word = test_peer_capability_word; - remote.capability_generation - = (uint64)test_peer_capability_generation; + remote.capability_generation = (uint64)test_peer_capability_generation; remote.transition_epoch = 7; remote.record_generation = 5; table->expected[node] = remote; @@ -7099,15 +6494,12 @@ ut_open_applied_env_setup(void) test_membership_snapshot_lo = UINT64_C(0x03); test_membership_snapshot_hi = 0; test_membership_snapshot_epoch = 7; - test_local_capability_word - = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS; + test_local_capability_word = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS; test_peer_capability_word_sample_ok = true; - test_peer_capability_word - = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS; + test_peer_capability_word = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS; test_peer_capability_generation = 19; for (node = 0; node < CLUSTER_MAX_NODES; node++) - test_remote_admitted_incarnations[node] - = UINT64_C(0x100) + (uint64)node; + test_remote_admitted_incarnations[node] = UINT64_C(0x100) + (uint64)node; ut_open_applied_table_setup(); } @@ -7115,13 +6507,12 @@ UT_TEST(test_131_member_open_applied_applies_latch_and_acks) { ut_open_applied_env_setup(); UT_ASSERT(!cluster_r4_bit22_cutover_active()); - UT_ASSERT(semantic_activation_ack_lmon_progress_member_open_applied( - SemanticActivationAckTable)); + UT_ASSERT( + semantic_activation_ack_lmon_progress_member_open_applied(SemanticActivationAckTable)); UT_ASSERT(cluster_r4_bit22_cutover_active()); UT_ASSERT_EQ(pg_atomic_read_u64(&SemanticActivationBit22Latch->transition_epoch), 7); UT_ASSERT_EQ(pg_atomic_read_u64(&SemanticActivationBit22Latch->round_generation), 5); - UT_ASSERT_EQ(SemanticActivationAckTable->observed_members_lo - & UINT64_C(0x02), UINT64_C(0x02)); + UT_ASSERT_EQ(SemanticActivationAckTable->observed_members_lo & UINT64_C(0x02), UINT64_C(0x02)); /* COMPLETE awaits the coordinator's own observed bit, which the * coordinator-side OPEN_APPLIED advance (contract step ②) sets when all * members ACKed — covered there. */ @@ -7131,19 +6522,17 @@ UT_TEST(test_131_member_open_applied_applies_latch_and_acks) UT_TEST(test_132_member_open_applied_replay_is_idempotent) { ut_open_applied_env_setup(); - UT_ASSERT(semantic_activation_ack_lmon_progress_member_open_applied( - SemanticActivationAckTable)); + UT_ASSERT( + semantic_activation_ack_lmon_progress_member_open_applied(SemanticActivationAckTable)); UT_ASSERT(cluster_r4_bit22_cutover_active()); - UT_ASSERT_EQ(SemanticActivationAckTable->observed_members_lo - & UINT64_C(0x02), UINT64_C(0x02)); + UT_ASSERT_EQ(SemanticActivationAckTable->observed_members_lo & UINT64_C(0x02), UINT64_C(0x02)); /* Replay (duplicate REQUEST) — the latch is monotonic, the member just * re-ACKs; the observed set and latch round identity must not move. */ - UT_ASSERT(semantic_activation_ack_lmon_progress_member_open_applied( - SemanticActivationAckTable)); + UT_ASSERT( + semantic_activation_ack_lmon_progress_member_open_applied(SemanticActivationAckTable)); UT_ASSERT_EQ(pg_atomic_read_u64(&SemanticActivationBit22Latch->transition_epoch), 7); UT_ASSERT_EQ(pg_atomic_read_u64(&SemanticActivationBit22Latch->round_generation), 5); - UT_ASSERT_EQ(SemanticActivationAckTable->observed_members_lo - & UINT64_C(0x02), UINT64_C(0x02)); + UT_ASSERT_EQ(SemanticActivationAckTable->observed_members_lo & UINT64_C(0x02), UINT64_C(0x02)); test_gate_reset(); } @@ -7152,11 +6541,10 @@ UT_TEST(test_133_member_open_applied_rejects_round_without_bit22) ut_open_applied_env_setup(); SemanticActivationAckTable->target_feature_bitmap = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1; /* no bit22 */ - UT_ASSERT(semantic_activation_ack_lmon_progress_member_open_applied( - SemanticActivationAckTable)); + UT_ASSERT( + semantic_activation_ack_lmon_progress_member_open_applied(SemanticActivationAckTable)); UT_ASSERT(!cluster_r4_bit22_cutover_active()); - UT_ASSERT_EQ(SemanticActivationAckTable->observed_members_lo - & UINT64_C(0x02), UINT64_C(0)); + UT_ASSERT_EQ(SemanticActivationAckTable->observed_members_lo & UINT64_C(0x02), UINT64_C(0)); test_gate_reset(); } @@ -7164,8 +6552,8 @@ UT_TEST(test_134_member_open_applied_coordinator_does_not_apply) { ut_open_applied_env_setup(); cluster_node_id = 0; /* the coordinator drives, it does not apply */ - UT_ASSERT(!semantic_activation_ack_lmon_progress_member_open_applied( - SemanticActivationAckTable)); + UT_ASSERT( + !semantic_activation_ack_lmon_progress_member_open_applied(SemanticActivationAckTable)); UT_ASSERT(!cluster_r4_bit22_cutover_active()); test_gate_reset(); } @@ -7174,11 +6562,11 @@ UT_TEST(test_135_member_open_applied_fail_closed_when_census_red) { ut_open_applied_env_setup(); ut_r4fsm_census_ok = false; /* a KNOWN-DEFERRED regression turns RED */ - UT_ASSERT(semantic_activation_ack_lmon_progress_member_open_applied( - SemanticActivationAckTable)); + UT_ASSERT( + semantic_activation_ack_lmon_progress_member_open_applied(SemanticActivationAckTable)); UT_ASSERT(!cluster_r4_bit22_cutover_active()); - UT_ASSERT_EQ(SemanticActivationAckTable->observed_members_lo - & UINT64_C(0x02), UINT64_C(0)); /* un-observed, fail-closed */ + UT_ASSERT_EQ(SemanticActivationAckTable->observed_members_lo & UINT64_C(0x02), + UINT64_C(0)); /* un-observed, fail-closed */ test_gate_reset(); } @@ -7201,8 +6589,7 @@ ut_open_applied_prepared_table_setup(void) table->expected_members_hi = 0; table->observed_members_lo = UINT64_C(0x03); /* all-member ACK */ table->observed_members_hi = 0; - table->target_feature_bitmap - = PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1; + table->target_feature_bitmap = PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1; table->capability_sample_digest = UINT64_C(0xabcd); table->flags = CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID | CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE; @@ -7210,24 +6597,20 @@ ut_open_applied_prepared_table_setup(void) if (!cluster_membership_is_member(node)) continue; if (node == cluster_node_id) { - (void)semantic_activation_ack_self_tuple( - node, test_local_capability_word, 7, 5, - &table->expected[node]); - (void)semantic_activation_ack_self_tuple( - node, test_local_capability_word, 7, 5, - &table->observed[node]); + (void)semantic_activation_ack_self_tuple(node, test_local_capability_word, 7, 5, + &table->expected[node]); + (void)semantic_activation_ack_self_tuple(node, test_local_capability_word, 7, 5, + &table->observed[node]); continue; } /* remote tuple (mirror of ut_open_applied_table_setup) */ table->expected[node].node_id = (uint32)node; table->expected[node].boot_id = test_remote_admitted_incarnations[node]; - table->expected[node].admitted_incarnation - = test_remote_admitted_incarnations[node]; + table->expected[node].admitted_incarnation = test_remote_admitted_incarnations[node]; table->expected[node].control_connection_generation = (uint64)test_peer_capability_generation; table->expected[node].capability_word = test_peer_capability_word; - table->expected[node].capability_generation - = (uint64)test_peer_capability_generation; + table->expected[node].capability_generation = (uint64)test_peer_capability_generation; table->expected[node].transition_epoch = 7; table->expected[node].record_generation = 5; table->observed[node] = table->expected[node]; @@ -7267,8 +6650,7 @@ ut_open_applied_env_setup_coordinator(void) test_membership_snapshot_lo = UINT64_C(0x03); test_membership_snapshot_epoch = 7; for (node = 0; node < CLUSTER_MAX_NODES; node++) - test_remote_admitted_incarnations[node] - = UINT64_C(0x100) + (uint64)node; + test_remote_admitted_incarnations[node] = UINT64_C(0x100) + (uint64)node; } UT_TEST(test_136_coordinator_open_applied_advance_activates_and_publishes) @@ -7288,8 +6670,7 @@ UT_TEST(test_136_coordinator_open_applied_advance_activates_and_publishes) UT_ASSERT(cluster_r4_bit22_cutover_seam_store(&token, sha, &round)); ut_activate_calls = 0; UT_ASSERT(semantic_activation_ack_lmon_bit22_commit_applied_begin( - SemanticActivationAckTable, UINT64_C(0x03), 0, 7, 0, - test_local_capability_word)); + SemanticActivationAckTable, UINT64_C(0x03), 0, 7, 0, test_local_capability_word)); UT_ASSERT_EQ(ut_activate_calls, 1); /* RF-ROOT P9 verification: the coordinator latch is NOT flipped at * COMMIT_APPLIED — it waits for the durable majority OPEN(P+2) @@ -7303,8 +6684,7 @@ UT_TEST(test_136_coordinator_open_applied_advance_activates_and_publishes) UT_ASSERT_EQ(SemanticActivationAckTable->stage, CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_COMMIT_APPLIED); UT_ASSERT_EQ(SemanticActivationAckTable->record_generation, 6); - UT_ASSERT_EQ(SemanticActivationAckTable->observed_members_lo, - UINT64_C(0x01)); + UT_ASSERT_EQ(SemanticActivationAckTable->observed_members_lo, UINT64_C(0x01)); test_gate_reset(); } @@ -7315,12 +6695,10 @@ UT_TEST(test_137_coordinator_open_applied_advance_waits_for_seam) /* no seam staged */ ut_activate_calls = 0; UT_ASSERT(semantic_activation_ack_lmon_bit22_commit_applied_begin( - SemanticActivationAckTable, UINT64_C(0x03), 0, 7, 0, - test_local_capability_word)); + SemanticActivationAckTable, UINT64_C(0x03), 0, 7, 0, test_local_capability_word)); UT_ASSERT_EQ(ut_activate_calls, 0); UT_ASSERT(!cluster_r4_bit22_cutover_active()); - UT_ASSERT_EQ(SemanticActivationAckTable->stage, - CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_PREPARED); + UT_ASSERT_EQ(SemanticActivationAckTable->stage, CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_PREPARED); test_gate_reset(); } @@ -7341,12 +6719,10 @@ UT_TEST(test_138_coordinator_open_applied_advance_fail_closed_on_activate_failur UT_ASSERT(cluster_r4_bit22_cutover_seam_store(&token, sha, &round)); ut_activate_result = CLUSTER_CONTROL_ROOT_IO_ERROR; UT_ASSERT(semantic_activation_ack_lmon_bit22_commit_applied_begin( - SemanticActivationAckTable, UINT64_C(0x03), 0, 7, 0, - test_local_capability_word)); + SemanticActivationAckTable, UINT64_C(0x03), 0, 7, 0, test_local_capability_word)); UT_ASSERT_EQ(ut_activate_calls, 1); UT_ASSERT(!cluster_r4_bit22_cutover_active()); - UT_ASSERT_EQ(SemanticActivationAckTable->stage, - CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_PREPARED); + UT_ASSERT_EQ(SemanticActivationAckTable->stage, CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_PREPARED); test_gate_reset(); } @@ -7372,8 +6748,7 @@ UT_TEST(test_145_coordinator_latch_refused_leaves_round_commit_applied) UT_ASSERT(cluster_r4_bit22_cutover_seam_store(&token, sha, &round)); ut_r4fsm_census_ok = false; /* latch apply refuses (census RED) */ UT_ASSERT(semantic_activation_ack_lmon_bit22_open_applied_begin( - SemanticActivationAckTable, UINT64_C(0x03), 0, 7, 0, - test_local_capability_word)); + SemanticActivationAckTable, UINT64_C(0x03), 0, 7, 0, test_local_capability_word)); UT_ASSERT(!cluster_r4_bit22_cutover_active()); UT_ASSERT_EQ(SemanticActivationAckTable->stage, CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_COMMIT_APPLIED); @@ -7398,12 +6773,10 @@ UT_TEST(test_139_coordinator_open_applied_advance_rejects_mismatched_seam) UT_ASSERT(cluster_r4_bit22_cutover_seam_store(&token, sha, &round)); ut_activate_calls = 0; UT_ASSERT(semantic_activation_ack_lmon_bit22_commit_applied_begin( - SemanticActivationAckTable, UINT64_C(0x03), 0, 7, 0, - test_local_capability_word)); + SemanticActivationAckTable, UINT64_C(0x03), 0, 7, 0, test_local_capability_word)); UT_ASSERT_EQ(ut_activate_calls, 0); UT_ASSERT(!cluster_r4_bit22_cutover_active()); - UT_ASSERT_EQ(SemanticActivationAckTable->stage, - CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_PREPARED); + UT_ASSERT_EQ(SemanticActivationAckTable->stage, CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_PREPARED); test_gate_reset(); } @@ -7415,8 +6788,7 @@ UT_TEST(test_140_member_prepared_bit22_round_parameterized) ut_open_applied_env_setup(); /* member cluster_node_id = 1 */ ut_open_applied_table_setup(); - SemanticActivationAckTable->stage - = CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_PREPARED; + SemanticActivationAckTable->stage = CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_PREPARED; UT_ASSERT(semantic_activation_ack_member_prepared_image_current_bit22( SemanticActivationAckTable, &self)); UT_ASSERT_EQ(self.node_id, 1); @@ -7425,8 +6797,7 @@ UT_TEST(test_140_member_prepared_bit22_round_parameterized) } static void -ut_bit22_request_ahead_predecessor_setup(uint32 predecessor_stage, - uint64 predecessor_generation) +ut_bit22_request_ahead_predecessor_setup(uint32 predecessor_stage, uint64 predecessor_generation) { const uint32 caps = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS; ClusterSemanticActivationAckTableV1 *table = SemanticActivationAckTable; @@ -7443,8 +6814,7 @@ ut_bit22_request_ahead_predecessor_setup(uint32 predecessor_stage, test_peer_capability_generation = 19; test_peer_capability_matches = true; for (node = 0; node < 4; node++) { - test_remote_admitted_incarnations[node] - = UINT64_C(0x100) + (uint64)node; + test_remote_admitted_incarnations[node] = UINT64_C(0x100) + (uint64)node; test_send_results[node] = CLUSTER_IC_SEND_DONE; } @@ -7459,25 +6829,20 @@ ut_bit22_request_ahead_predecessor_setup(uint32 predecessor_stage, table->transition_epoch = 7; table->record_generation = predecessor_generation; table->source_feature_bitmap = 0; - table->target_feature_bitmap - = PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1; + table->target_feature_bitmap = PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1; table->capability_sample_digest = UINT64_C(0xabcd); for (node = 0; node < 4; node++) { SemanticActivationAckTuple *expected = &table->expected[node]; expected->node_id = (uint32)node; - expected->boot_id - = node == cluster_node_id - ? test_qvotec_self_incarnation - : test_remote_admitted_incarnations[node]; + expected->boot_id = node == cluster_node_id ? test_qvotec_self_incarnation + : test_remote_admitted_incarnations[node]; expected->admitted_incarnation = expected->boot_id; - expected->control_connection_generation - = node == cluster_node_id - ? test_qvotec_self_incarnation - : (uint64)test_peer_capability_generation; + expected->control_connection_generation = node == cluster_node_id + ? test_qvotec_self_incarnation + : (uint64)test_peer_capability_generation; expected->capability_word = caps; - expected->capability_generation - = expected->control_connection_generation; + expected->capability_generation = expected->control_connection_generation; expected->transition_epoch = 7; expected->record_generation = predecessor_generation; } @@ -7494,12 +6859,12 @@ UT_TEST(test_140a_member_retains_each_bit22_successor_and_fans_out_once) uint64 predecessor_generation; uint64 request_generation; } cases[] = { - {CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_BARRIER, - CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_PREPARED, 5, 5}, - {CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_PREPARED, - CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_COMMIT_APPLIED, 5, 6}, - {CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_COMMIT_APPLIED, - CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_OPEN_APPLIED, 6, 7}, + { CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_BARRIER, + CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_PREPARED, 5, 5 }, + { CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_PREPARED, + CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_COMMIT_APPLIED, 5, 6 }, + { CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_COMMIT_APPLIED, + CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_OPEN_APPLIED, 6, 7 }, }; ClusterSemanticActivationAckWireV1 message; ClusterICEnvelope envelope; @@ -7510,9 +6875,8 @@ UT_TEST(test_140a_member_retains_each_bit22_successor_and_fans_out_once) ClusterSemanticActivationAckTableV1 *table; int node; - ut_bit22_request_ahead_predecessor_setup( - cases[case_index].predecessor_stage, - cases[case_index].predecessor_generation); + ut_bit22_request_ahead_predecessor_setup(cases[case_index].predecessor_stage, + cases[case_index].predecessor_generation); table = SemanticActivationAckTable; memset(&message, 0, sizeof(message)); message.kind = CLUSTER_SEMANTIC_ACTIVATION_ACK_KIND_REQUEST; @@ -7524,12 +6888,10 @@ UT_TEST(test_140a_member_retains_each_bit22_successor_and_fans_out_once) message.record_generation = cases[case_index].request_generation; message.round_nonce = UINT64_C(42); message.source_feature_bitmap = 0; - message.target_feature_bitmap - = PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1; + message.target_feature_bitmap = PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1; message.admitted_members_lo = UINT64_C(0x0f); message.capability_sample_digest = UINT64_C(0xabcd); - UT_ASSERT(cluster_semantic_activation_ack_wire_encode( - &message, payload)); + UT_ASSERT(cluster_semantic_activation_ack_wire_encode(&message, payload)); memset(&envelope, 0, sizeof(envelope)); envelope.msg_type = PGRAC_IC_MSG_SEMANTIC_ACTIVATION_ACK_V1; envelope.source_node_id = 0; @@ -7561,8 +6923,7 @@ UT_TEST(test_140a_member_retains_each_bit22_successor_and_fans_out_once) cluster_semantic_activation_lmon_tick(); UT_ASSERT(!semantic_activation_ack_local_request_ahead.valid); UT_ASSERT_EQ(table->stage, cases[case_index].request_stage); - UT_ASSERT_EQ(table->record_generation, - cases[case_index].request_generation); + UT_ASSERT_EQ(table->record_generation, cases[case_index].request_generation); UT_ASSERT_EQ(table->observed_members_lo, UINT64_C(0x04)); for (node = 0; node < 4; node++) { ClusterSemanticActivationAckWireV1 sent; @@ -7570,10 +6931,8 @@ UT_TEST(test_140a_member_retains_each_bit22_successor_and_fans_out_once) UT_ASSERT_EQ(test_send_calls[node], node == 2 ? 0 : 1); if (node == 2) continue; - UT_ASSERT(cluster_semantic_activation_ack_wire_decode( - test_send_payloads[node], &sent)); - UT_ASSERT_EQ(sent.kind, - CLUSTER_SEMANTIC_ACTIVATION_ACK_KIND_ACK); + UT_ASSERT(cluster_semantic_activation_ack_wire_decode(test_send_payloads[node], &sent)); + UT_ASSERT_EQ(sent.kind, CLUSTER_SEMANTIC_ACTIVATION_ACK_KIND_ACK); UT_ASSERT_EQ(sent.stage, cases[case_index].request_stage); UT_ASSERT_EQ(sent.member_node, UINT32_C(2)); } @@ -7597,8 +6956,7 @@ UT_TEST(test_140b_bit22_retained_successor_drift_invalidates_without_ack) uint8 payload[CLUSTER_SEMANTIC_ACTIVATION_ACK_WIRE_BYTES]; int node; - ut_bit22_request_ahead_predecessor_setup( - CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_BARRIER, 5); + ut_bit22_request_ahead_predecessor_setup(CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_BARRIER, 5); table = SemanticActivationAckTable; memset(&message, 0, sizeof(message)); message.kind = CLUSTER_SEMANTIC_ACTIVATION_ACK_KIND_REQUEST; @@ -7609,8 +6967,7 @@ UT_TEST(test_140b_bit22_retained_successor_drift_invalidates_without_ack) message.transition_epoch = 7; message.record_generation = 5; message.round_nonce = UINT64_C(42); - message.target_feature_bitmap - = PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1; + message.target_feature_bitmap = PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1; message.admitted_members_lo = UINT64_C(0x0f); message.capability_sample_digest = UINT64_C(0xabcd); UT_ASSERT(cluster_semantic_activation_ack_wire_encode(&message, payload)); @@ -7641,8 +6998,7 @@ UT_TEST(test_140c_bit22_prepared_request_waits_for_local_source_close) uint8 payload[CLUSTER_SEMANTIC_ACTIVATION_ACK_WIRE_BYTES]; int node; - ut_bit22_request_ahead_predecessor_setup( - CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_BARRIER, 5); + ut_bit22_request_ahead_predecessor_setup(CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_BARRIER, 5); /* The BARRIER table is current, but this member has not yet executed its * local source-close callback. Retention is still evidence-only. */ test_gate_publish(2, 0, 4, 7, false); @@ -7656,8 +7012,7 @@ UT_TEST(test_140c_bit22_prepared_request_waits_for_local_source_close) message.transition_epoch = 7; message.record_generation = 5; message.round_nonce = UINT64_C(42); - message.target_feature_bitmap - = PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1; + message.target_feature_bitmap = PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1; message.admitted_members_lo = UINT64_C(0x0f); message.capability_sample_digest = UINT64_C(0xabcd); UT_ASSERT(cluster_semantic_activation_ack_wire_encode(&message, payload)); @@ -7670,8 +7025,7 @@ UT_TEST(test_140c_bit22_prepared_request_waits_for_local_source_close) cluster_semantic_activation_ack_handler(&envelope, payload); semantic_activation_ack_lmon_drain(); UT_ASSERT(semantic_activation_ack_local_request_ahead.valid); - UT_ASSERT_EQ(table->stage, - CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_BARRIER); + UT_ASSERT_EQ(table->stage, CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_BARRIER); for (node = 0; node < 4; node++) UT_ASSERT_EQ(test_send_calls[node], 0); @@ -7680,8 +7034,7 @@ UT_TEST(test_140c_bit22_prepared_request_waits_for_local_source_close) table->observed[2] = table->expected[2]; cluster_semantic_activation_lmon_tick(); UT_ASSERT(!semantic_activation_ack_local_request_ahead.valid); - UT_ASSERT_EQ(table->stage, - CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_PREPARED); + UT_ASSERT_EQ(table->stage, CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_PREPARED); for (node = 0; node < 4; node++) UT_ASSERT_EQ(test_send_calls[node], node == 2 ? 0 : 1); test_gate_reset(); @@ -7701,8 +7054,7 @@ UT_TEST(test_140d_initial_r4_prepared_request_waits_for_local_source_close) uint8 payload[CLUSTER_SEMANTIC_ACTIVATION_ACK_WIRE_BYTES]; int node; - ut_bit22_request_ahead_predecessor_setup( - CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_BARRIER, 1); + ut_bit22_request_ahead_predecessor_setup(CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_BARRIER, 1); test_gate_publish(2, 0, 0, 7, false); table = SemanticActivationAckTable; table->target_feature_bitmap = r4; @@ -7735,28 +7087,26 @@ UT_TEST(test_140d_initial_r4_prepared_request_waits_for_local_source_close) semantic_activation_ack_lmon_drain(); UT_ASSERT(semantic_activation_ack_local_request_ahead.valid); - UT_ASSERT_EQ(table->stage, - CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_BARRIER); + UT_ASSERT_EQ(table->stage, CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_BARRIER); for (node = 0; node < 4; node++) UT_ASSERT_EQ(test_send_calls[node], 0); test_gate_publish(4, 0, 1, 7, true); cluster_semantic_activation_lmon_tick(); UT_ASSERT(!semantic_activation_ack_local_request_ahead.valid); - UT_ASSERT_EQ(table->stage, - CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_PREPARED); + UT_ASSERT_EQ(table->stage, CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_PREPARED); /* Installing PREPARED is authority-neutral. The actual R4 callback also * requires the initial-clean formation/PGRD image, which is deliberately * outside this request-ahead fixture and is covered by the R4 lifecycle * tests. Model only its already-established successful return here, then * prove that the retained request starts one exact positive fan-out. */ - UT_ASSERT(semantic_activation_ack_lmon_finish_member_prepared( - table, CLUSTER_SEMANTIC_ACTIVATION_OK)); + UT_ASSERT( + semantic_activation_ack_lmon_finish_member_prepared(table, CLUSTER_SEMANTIC_ACTIVATION_OK)); UT_ASSERT_EQ(table->observed_members_lo, UINT64_C(0x04)); for (node = 0; node < 4; node++) UT_ASSERT_EQ(test_send_calls[node], node == 2 ? 0 : 1); - UT_ASSERT(semantic_activation_ack_lmon_finish_member_prepared( - table, CLUSTER_SEMANTIC_ACTIVATION_OK)); + UT_ASSERT( + semantic_activation_ack_lmon_finish_member_prepared(table, CLUSTER_SEMANTIC_ACTIVATION_OK)); for (node = 0; node < 4; node++) UT_ASSERT_EQ(test_send_calls[node], node == 2 ? 0 : 1); test_gate_reset(); @@ -7788,17 +7138,14 @@ UT_TEST(test_140e_initial_r4_member_fetches_pgrd_before_prepared_ack) test_initial_clean_snapshot.arbiter_incarnation = 0; test_system_identifier = system_identifier; cluster_shared_data_dir = "/cluster-share"; - test_local_capability_word - = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS; + test_local_capability_word = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS; test_peer_capability_word_sample_ok = true; - test_peer_capability_word - = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS; + test_peer_capability_word = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS; test_peer_capability_generation = 19; test_peer_capability_matches = true; for (node = 0; node < 4; node++) { test_send_results[node] = CLUSTER_IC_SEND_DONE; - test_remote_admitted_incarnations[node] - = UINT64_C(0x100) + (uint64)node; + test_remote_admitted_incarnations[node] = UINT64_C(0x100) + (uint64)node; test_initial_clean_snapshot.admitted_incarnation[node] = test_remote_admitted_incarnations[node]; } @@ -7813,8 +7160,7 @@ UT_TEST(test_140e_initial_r4_member_fetches_pgrd_before_prepared_ack) memset(pgrd.root_uuid, 0x5c, sizeof(pgrd.root_uuid)); pgrd.namespace_id = 1; pgrd.system_identifier = system_identifier; - UT_ASSERT(cluster_undo_root_descriptor_encode( - &pgrd, test_pgrd_candidate)); + UT_ASSERT(cluster_undo_root_descriptor_encode(&pgrd, test_pgrd_candidate)); test_pgrd_candidate_state = CLUSTER_UNDO_SMGR_ROOT_MIRROR_EXACT; table = SemanticActivationAckTable; @@ -7828,23 +7174,18 @@ UT_TEST(test_140e_initial_r4_member_fetches_pgrd_before_prepared_ack) table->observed_members_lo = UINT64_C(0x01); table->transition_epoch = test_current_epoch; table->record_generation = 1; - table->target_feature_bitmap - = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1; + table->target_feature_bitmap = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1; table->capability_sample_digest = UINT64_C(0x3141592653589793); for (node = 0; node < 4; node++) { if (node == cluster_node_id) { UT_ASSERT(semantic_activation_ack_self_tuple( - node, test_local_capability_word, test_current_epoch, 1, - &table->expected[node])); + node, test_local_capability_word, test_current_epoch, 1, &table->expected[node])); } else { table->expected[node].node_id = (uint32)node; - table->expected[node].boot_id - = test_remote_admitted_incarnations[node]; - table->expected[node].admitted_incarnation - = test_remote_admitted_incarnations[node]; + table->expected[node].boot_id = test_remote_admitted_incarnations[node]; + table->expected[node].admitted_incarnation = test_remote_admitted_incarnations[node]; table->expected[node].control_connection_generation = 19; - table->expected[node].capability_word - = test_peer_capability_word; + table->expected[node].capability_word = test_peer_capability_word; table->expected[node].capability_generation = 19; table->expected[node].transition_epoch = test_current_epoch; table->expected[node].record_generation = 1; @@ -7860,25 +7201,18 @@ UT_TEST(test_140e_initial_r4_member_fetches_pgrd_before_prepared_ack) UT_ASSERT_EQ(test_send_calls[node], 0); memset(&read_request, 0, sizeof(read_request)); - UT_ASSERT(cluster_semantic_activation_qvotec_poll_undo_root_descriptor_read( - &read_request)); + UT_ASSERT(cluster_semantic_activation_qvotec_poll_undo_root_descriptor_read(&read_request)); UT_ASSERT_EQ(read_request.system_identifier, system_identifier); - UT_ASSERT_EQ(read_request.formation.utility_request_seq, - UINT64_C(42)); - UT_ASSERT_EQ(read_request.formation.formation_epoch, - test_current_epoch); - UT_ASSERT_EQ(read_request.formation.coordinator_incarnation, - test_qvotec_self_incarnation); - UT_ASSERT_EQ(read_request.formation.expected_record_generation, - UINT64_C(1)); + UT_ASSERT_EQ(read_request.formation.utility_request_seq, UINT64_C(42)); + UT_ASSERT_EQ(read_request.formation.formation_epoch, test_current_epoch); + UT_ASSERT_EQ(read_request.formation.coordinator_incarnation, test_qvotec_self_incarnation); + UT_ASSERT_EQ(read_request.formation.expected_record_generation, UINT64_C(1)); UT_ASSERT(cluster_semantic_activation_qvotec_complete_undo_root_descriptor_read( - read_request.request_seq, CLUSTER_UNDO_ROOT_DESCRIPTOR_VALID, - test_pgrd_candidate)); + read_request.request_seq, CLUSTER_UNDO_ROOT_DESCRIPTOR_VALID, test_pgrd_candidate)); UT_ASSERT(semantic_activation_ack_lmon_progress_member_barrier()); UT_ASSERT(semantic_activation_pgrd_snapshot_copy(snapshot)); - UT_ASSERT_EQ(memcmp(snapshot, test_pgrd_candidate, - sizeof(snapshot)), 0); + UT_ASSERT_EQ(memcmp(snapshot, test_pgrd_candidate, sizeof(snapshot)), 0); UT_ASSERT_EQ(table->observed_members_lo, UINT64_C(0x05)); for (node = 0; node < 4; node++) UT_ASSERT_EQ(test_send_calls[node], node == cluster_node_id ? 0 : 1); @@ -7891,14 +7225,13 @@ UT_TEST(test_141_member_prepared_r4_round_keeps_four_member_shape) ut_open_applied_env_setup(); ut_open_applied_table_setup(); - SemanticActivationAckTable->stage - = CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_PREPARED; + SemanticActivationAckTable->stage = CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_PREPARED; SemanticActivationAckTable->target_feature_bitmap = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1; /* R4 round: no bit22 */ /* The R4 four-member shape (expected 0x0f, coordinator 0) is violated by * the 2-node table — the frozen R4 check must still reject it. */ - UT_ASSERT(!semantic_activation_ack_member_prepared_image_current( - SemanticActivationAckTable, &self)); + UT_ASSERT( + !semantic_activation_ack_member_prepared_image_current(SemanticActivationAckTable, &self)); test_gate_reset(); } @@ -7912,8 +7245,7 @@ ut_cutover_round(void) round.prepare_generation = 5; round.transition_epoch = 7; round.source_feature_bitmap = 0; - round.target_feature_bitmap - = PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1; + round.target_feature_bitmap = PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1; round.admitted_bitmap_low = UINT64_C(0x03); round.capability_sample_digest = UINT64_C(0xabcd); return round; @@ -7947,11 +7279,10 @@ UT_TEST(test_142_cutover_begin_stages_seam_and_publishes_prepared) UT_ASSERT_EQ(table->stage, CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_BARRIER); UT_ASSERT_EQ(table->record_generation, 1); UT_ASSERT_EQ(table->expected_members_lo, UINT64_C(0x03)); - UT_ASSERT((table->target_feature_bitmap - & PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1) != 0); + UT_ASSERT((table->target_feature_bitmap & PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1) + != 0); UT_ASSERT(cluster_r4_bit22_source_close_current(7, 1)); - UT_ASSERT_EQ(pg_atomic_read_u32( - &SemanticActivationBit22SourceClose->writer_count), 0); + UT_ASSERT_EQ(pg_atomic_read_u32(&SemanticActivationBit22SourceClose->writer_count), 0); /* All-member BARRIER ACK -> the tick advances: PREPARE(P) CAS -> * build + create + seam + PREPARED stage + REQUEST. The B′ redo @@ -7969,8 +7300,7 @@ UT_TEST(test_142_cutover_begin_stages_seam_and_publishes_prepared) UT_ASSERT(semantic_activation_ack_lmon_bit22_advance()); cas_seq = pg_atomic_read_u64(&SemanticActivationShmem->record_cas_request_seq); UT_ASSERT_EQ(cas_seq, UINT64_C(1)); - pg_atomic_write_u64(&SemanticActivationShmem->record_cas_completion_seq, - cas_seq); + pg_atomic_write_u64(&SemanticActivationShmem->record_cas_completion_seq, cas_seq); pg_atomic_write_u32(&SemanticActivationShmem->record_cas_result, CLUSTER_SEMANTIC_ACTIVATION_OK); UT_ASSERT(semantic_activation_ack_lmon_bit22_advance()); @@ -7981,16 +7311,14 @@ UT_TEST(test_142_cutover_begin_stages_seam_and_publishes_prepared) UT_ASSERT_EQ(table->round_nonce, 1); UT_ASSERT_EQ(table->record_generation, 1); UT_ASSERT_EQ(table->expected_members_lo, UINT64_C(0x03)); - UT_ASSERT((table->target_feature_bitmap - & PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1) != 0); + UT_ASSERT((table->target_feature_bitmap & PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1) + != 0); UT_ASSERT(table->expected[0].boot_id != 0); UT_ASSERT(table->expected[1].boot_id != 0); - UT_ASSERT(table->expected[1].capability_word - == CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS); + UT_ASSERT(table->expected[1].capability_word == CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS); /* Both the BARRIER REQUEST (begin) and the PREPARED REQUEST (tick * advance) went out through the origin mechanism. */ - UT_ASSERT_EQ(semantic_activation_ack_local_request_origin.unsent_members_lo, - UINT64_C(0)); + UT_ASSERT_EQ(semantic_activation_ack_local_request_origin.unsent_members_lo, UINT64_C(0)); UT_ASSERT_EQ(test_send_calls[1], 2); test_gate_reset(); } @@ -8041,8 +7369,7 @@ UT_TEST(test_144_cutover_begin_fail_closed_on_create_failure) UT_ASSERT(semantic_activation_ack_lmon_bit22_advance()); cas_seq = pg_atomic_read_u64(&SemanticActivationShmem->record_cas_request_seq); UT_ASSERT_EQ(cas_seq, UINT64_C(1)); - pg_atomic_write_u64(&SemanticActivationShmem->record_cas_completion_seq, - cas_seq); + pg_atomic_write_u64(&SemanticActivationShmem->record_cas_completion_seq, cas_seq); pg_atomic_write_u32(&SemanticActivationShmem->record_cas_result, CLUSTER_SEMANTIC_ACTIVATION_OK); UT_ASSERT(!semantic_activation_ack_lmon_bit22_advance()); @@ -8065,15 +7392,13 @@ ut_open_proof_env_setup(uint64 generation) ut_open_applied_env_setup_coordinator(); /* node 0, epoch 7, members 0x03 */ /* Model the production restart boundary: shmem initialization leaves the * volatile carrier byte-zero before durable OPEN reconstruction. */ - memset(SemanticActivationAckTable, 0, - sizeof(*SemanticActivationAckTable)); + memset(SemanticActivationAckTable, 0, sizeof(*SemanticActivationAckTable)); UT_ASSERT(cluster_r4_bit22_cutover_latch_apply(7, generation)); UT_ASSERT(cluster_r4_bit22_cutover_active()); memset(&record, 0, sizeof(record)); record.source_feature_bitmap = 0; - record.target_feature_bitmap - = PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1 - | CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1; + record.target_feature_bitmap = PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1 + | CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1; record.transition_epoch = 7; record.record_generation = generation; record.admitted_members_lo = UINT64_C(0x03); @@ -8085,8 +7410,7 @@ ut_open_proof_env_setup(uint64 generation) test_r4fsm_bootstrap_read_ok = true; test_r4fsm_bootstrap_implicit_open = true; test_r4fsm_root_validate_result = CLUSTER_CONTROL_ROOT_OK_PRIMARY; - UT_ASSERT(cluster_semantic_activation_record_encode( - &record, test_r4fsm_bootstrap_bytes)); + UT_ASSERT(cluster_semantic_activation_record_encode(&record, test_r4fsm_bootstrap_bytes)); } UT_TEST(test_145a_restore_open_proof_reconstructs_table) @@ -8095,23 +7419,18 @@ UT_TEST(test_145a_restore_open_proof_reconstructs_table) ut_open_proof_env_setup(3); UT_ASSERT(cluster_semantic_activation_restore_open_proof_if_active()); - UT_ASSERT((table->flags - & CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_OPEN_PROOF) != 0); - UT_ASSERT_EQ(table->stage, - CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_OPEN_APPLIED); + UT_ASSERT((table->flags & CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_OPEN_PROOF) != 0); + UT_ASSERT_EQ(table->stage, CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_OPEN_APPLIED); UT_ASSERT_EQ(table->record_generation, UINT64_C(3)); UT_ASSERT_EQ(table->transition_epoch, UINT64_C(7)); UT_ASSERT_EQ(table->expected_members_lo, UINT64_C(0x03)); UT_ASSERT_EQ(table->observed_members_lo, UINT64_C(0x03)); UT_ASSERT((table->flags & CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE) != 0); /* a complete current observed image is promoted to expected */ - UT_ASSERT_EQ(memcmp(table->observed, table->expected, - sizeof(table->expected)), 0); + UT_ASSERT_EQ(memcmp(table->observed, table->expected, sizeof(table->expected)), 0); UT_ASSERT(table->expected[0].boot_id == test_qvotec_self_incarnation); - UT_ASSERT(table->expected[1].boot_id - == test_remote_admitted_incarnations[1]); - UT_ASSERT(table->expected[1].capability_word - == CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS); + UT_ASSERT(table->expected[1].boot_id == test_remote_admitted_incarnations[1]); + UT_ASSERT(table->expected[1].capability_word == CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS); test_gate_reset(); } @@ -8120,8 +7439,8 @@ UT_TEST(test_145b_restore_open_proof_fail_closed_on_missing_open) ut_open_proof_env_setup(3); test_r4fsm_bootstrap_read_ok = false; UT_ASSERT(!cluster_semantic_activation_restore_open_proof_if_active()); - UT_ASSERT((SemanticActivationAckTable->flags - & CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_OPEN_PROOF) == 0); + UT_ASSERT((SemanticActivationAckTable->flags & CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_OPEN_PROOF) + == 0); test_gate_reset(); } @@ -8130,8 +7449,8 @@ UT_TEST(test_145c_restore_open_proof_fail_closed_on_root_refusal) ut_open_proof_env_setup(3); test_r4fsm_root_validate_result = CLUSTER_CONTROL_ROOT_IDENTITY_MISMATCH; UT_ASSERT(!cluster_semantic_activation_restore_open_proof_if_active()); - UT_ASSERT((SemanticActivationAckTable->flags - & CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_OPEN_PROOF) == 0); + UT_ASSERT((SemanticActivationAckTable->flags & CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_OPEN_PROOF) + == 0); test_gate_reset(); } @@ -8140,8 +7459,8 @@ UT_TEST(test_145d_restore_open_proof_fail_closed_on_membership_drift) ut_open_proof_env_setup(3); test_membership_snapshot_lo = UINT64_C(0x01); /* != OPEN admitted 0x03 */ UT_ASSERT(!cluster_semantic_activation_restore_open_proof_if_active()); - UT_ASSERT((SemanticActivationAckTable->flags - & CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_OPEN_PROOF) == 0); + UT_ASSERT((SemanticActivationAckTable->flags & CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_OPEN_PROOF) + == 0); test_gate_reset(); } @@ -8164,8 +7483,8 @@ UT_TEST(test_145f_restore_open_proof_requires_active_latch) pg_atomic_write_u32(&SemanticActivationBit22Latch->active, 0); UT_ASSERT(!cluster_r4_bit22_cutover_active()); UT_ASSERT(!cluster_semantic_activation_restore_open_proof_if_active()); - UT_ASSERT((SemanticActivationAckTable->flags - & CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_OPEN_PROOF) == 0); + UT_ASSERT((SemanticActivationAckTable->flags & CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_OPEN_PROOF) + == 0); test_gate_reset(); } @@ -8210,15 +7529,13 @@ UT_TEST(test_145g_peer_open_matches_consumes_open_proof) } static void -ut_resource_x_open_carrier_setup_at_epoch( - ClusterSemanticAdmissionToken *token, uint64 transition_epoch) -{ - const uint32 resource_x_caps - = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS - | PGRAC_IC_HELLO_CAP_GCS_RESOURCE_X_CONVERT_V1; - const uint64 target_bits - = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1 - | CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1; +ut_resource_x_open_carrier_setup_at_epoch(ClusterSemanticAdmissionToken *token, + uint64 transition_epoch) +{ + const uint32 resource_x_caps = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS + | PGRAC_IC_HELLO_CAP_GCS_RESOURCE_X_CONVERT_V1; + const uint64 target_bits = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1 + | CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1; ClusterSemanticActivationAckTableV1 *table; int node; @@ -8239,21 +7556,19 @@ ut_resource_x_open_carrier_setup_at_epoch( test_peer_capability_generation = 19; test_peer_capability_matches = true; for (node = 0; node < 4; node++) - test_remote_admitted_incarnations[node] - = UINT64_C(0x100) + (uint64)node; + test_remote_admitted_incarnations[node] = UINT64_C(0x100) + (uint64)node; memset(table, 0, sizeof(*table)); table->stage = CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_OPEN_APPLIED; table->flags = CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID - | CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE; + | CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE; table->coordinator_node = 0; table->round_nonce = 3; table->expected_members_lo = UINT64_C(0x0f); table->observed_members_lo = UINT64_C(0x0f); table->transition_epoch = transition_epoch; table->record_generation = 6; - table->source_feature_bitmap - = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1; + table->source_feature_bitmap = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1; table->target_feature_bitmap = target_bits; table->capability_sample_digest = UINT64_C(0xabc123); for (node = 0; node < 4; node++) { @@ -8261,14 +7576,12 @@ ut_resource_x_open_carrier_setup_at_epoch( memset(&tuple, 0, sizeof(tuple)); if (node == cluster_node_id) - UT_ASSERT(semantic_activation_ack_self_tuple( - node, test_local_capability_word, transition_epoch, 6, - &tuple)); + UT_ASSERT(semantic_activation_ack_self_tuple(node, test_local_capability_word, + transition_epoch, 6, &tuple)); else { tuple.node_id = (uint32)node; tuple.boot_id = test_remote_admitted_incarnations[node]; - tuple.admitted_incarnation - = test_remote_admitted_incarnations[node]; + tuple.admitted_incarnation = test_remote_admitted_incarnations[node]; tuple.control_connection_generation = 19; tuple.capability_word = test_peer_capability_word; tuple.capability_generation = 19; @@ -8281,14 +7594,12 @@ ut_resource_x_open_carrier_setup_at_epoch( test_gate_publish(2, target_bits, 6, transition_epoch, false); memset(token, 0, sizeof(*token)); - token->feature_bit - = CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1; + token->feature_bit = CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1; token->record_generation = 6; token->formation_epoch = transition_epoch; token->side = CLUSTER_SEMANTIC_TARGET_SIDE; token->entered = true; - UT_ASSERT(cluster_semantic_activation_resource_x_peer_open_matches( - token, 2, 19)); + UT_ASSERT(cluster_semantic_activation_resource_x_peer_open_matches(token, 2, 19)); } static void @@ -8447,17 +7758,14 @@ UT_TEST(test_145h_resource_x_open_carrier_survives_unavailable_snapshot) * let every consumer remain fail-closed until a later exact capture. */ test_membership_snapshot_valid = false; semantic_activation_ack_lmon_drain(); - UT_ASSERT_EQ(table->stage, - CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_OPEN_APPLIED); - UT_ASSERT_EQ(table->flags, - CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID - | CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE); + UT_ASSERT_EQ(table->stage, CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_OPEN_APPLIED); + UT_ASSERT_EQ(table->flags, CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID + | CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE); UT_ASSERT_EQ(table->expected_members_lo, UINT64_C(0x0f)); UT_ASSERT_EQ(table->observed_members_lo, UINT64_C(0x0f)); test_membership_snapshot_valid = true; - UT_ASSERT(cluster_semantic_activation_resource_x_peer_open_matches( - &token, 2, 19)); + UT_ASSERT(cluster_semantic_activation_resource_x_peer_open_matches(&token, 2, 19)); test_gate_reset(); } @@ -8476,8 +7784,7 @@ UT_TEST(test_145i_resource_x_open_carrier_invalidates_formation_drift) UT_ASSERT_EQ(table->expected_members_hi, UINT64_C(0)); UT_ASSERT_EQ(table->observed_members_lo, UINT64_C(0)); UT_ASSERT_EQ(table->observed_members_hi, UINT64_C(0)); - UT_ASSERT(!cluster_semantic_activation_resource_x_peer_open_matches( - &token, 2, 19)); + UT_ASSERT(!cluster_semantic_activation_resource_x_peer_open_matches(&token, 2, 19)); test_gate_reset(); } @@ -8487,32 +7794,24 @@ UT_TEST(test_145j_resource_x_peer_match_reports_first_failed_predicate) ClusterSemanticAdmissionToken token; ut_resource_x_open_carrier_setup(&token); - UT_ASSERT_EQ( - cluster_semantic_activation_resource_x_peer_open_check( - &token, 2, 19), - CLUSTER_SEMANTIC_RESOURCE_X_PEER_OPEN_MATCH); + UT_ASSERT_EQ(cluster_semantic_activation_resource_x_peer_open_check(&token, 2, 19), + CLUSTER_SEMANTIC_RESOURCE_X_PEER_OPEN_MATCH); table->flags = 0; - UT_ASSERT_EQ( - cluster_semantic_activation_resource_x_peer_open_check( - &token, 2, 19), - CLUSTER_SEMANTIC_RESOURCE_X_PEER_OPEN_FLAGS_MISMATCH); + UT_ASSERT_EQ(cluster_semantic_activation_resource_x_peer_open_check(&token, 2, 19), + CLUSTER_SEMANTIC_RESOURCE_X_PEER_OPEN_FLAGS_MISMATCH); table->flags = CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID - | CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE; + | CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE; test_membership_snapshot_valid = false; - UT_ASSERT_EQ( - cluster_semantic_activation_resource_x_peer_open_check( - &token, 2, 19), - CLUSTER_SEMANTIC_RESOURCE_X_PEER_OPEN_AUTHORITY_UNAVAILABLE); + UT_ASSERT_EQ(cluster_semantic_activation_resource_x_peer_open_check(&token, 2, 19), + CLUSTER_SEMANTIC_RESOURCE_X_PEER_OPEN_AUTHORITY_UNAVAILABLE); test_membership_snapshot_valid = true; test_peer_capability_matches = false; test_peer_capability_generation++; - UT_ASSERT_EQ( - cluster_semantic_activation_resource_x_peer_open_check( - &token, 2, 19), - CLUSTER_SEMANTIC_RESOURCE_X_PEER_OPEN_CAPABILITY_DRIFT); + UT_ASSERT_EQ(cluster_semantic_activation_resource_x_peer_open_check(&token, 2, 19), + CLUSTER_SEMANTIC_RESOURCE_X_PEER_OPEN_CAPABILITY_DRIFT); test_gate_reset(); } @@ -8609,8 +7908,7 @@ UT_TEST(test_a89_peer_open_full_image_pending_and_independent_contradiction) UT_TEST(test_145k_restore_open_proof_does_not_overwrite_resource_x_carrier) { const uint64 r4 = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1; - const uint64 target_bits - = r4 | CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1; + const uint64 target_bits = r4 | CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1; ClusterSemanticActivationAckTableV1 before; ClusterSemanticActivationRecord open; ClusterSemanticAdmissionToken token; @@ -8630,15 +7928,12 @@ UT_TEST(test_145k_restore_open_proof_does_not_overwrite_resource_x_carrier) test_r4fsm_bootstrap_read_result = CLUSTER_SEMANTIC_ACTIVATION_OK; test_r4fsm_bootstrap_read_ok = true; test_r4fsm_bootstrap_implicit_open = false; - UT_ASSERT(cluster_semantic_activation_record_encode( - &open, test_r4fsm_bootstrap_bytes)); + UT_ASSERT(cluster_semantic_activation_record_encode(&open, test_r4fsm_bootstrap_bytes)); memcpy(&before, SemanticActivationAckTable, sizeof(before)); UT_ASSERT(!cluster_semantic_activation_restore_open_proof_if_active()); - UT_ASSERT_EQ(memcmp(&before, SemanticActivationAckTable, - sizeof(before)), 0); - UT_ASSERT(cluster_semantic_activation_resource_x_peer_open_matches( - &token, 2, 19)); + UT_ASSERT_EQ(memcmp(&before, SemanticActivationAckTable, sizeof(before)), 0); + UT_ASSERT(cluster_semantic_activation_resource_x_peer_open_matches(&token, 2, 19)); test_gate_reset(); } @@ -8654,17 +7949,14 @@ UT_TEST(test_145l_epoch_zero_resource_x_open_carrier_survives_unavailable_snapsh ut_resource_x_open_carrier_setup_at_epoch(&token, 0); test_membership_snapshot_valid = false; semantic_activation_ack_lmon_drain(); - UT_ASSERT_EQ(table->stage, - CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_OPEN_APPLIED); - UT_ASSERT_EQ(table->flags, - CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID - | CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE); + UT_ASSERT_EQ(table->stage, CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_OPEN_APPLIED); + UT_ASSERT_EQ(table->flags, CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID + | CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE); UT_ASSERT_EQ(table->expected_members_lo, UINT64_C(0x0f)); UT_ASSERT_EQ(table->observed_members_lo, UINT64_C(0x0f)); test_membership_snapshot_valid = true; - UT_ASSERT(cluster_semantic_activation_resource_x_peer_open_matches( - &token, 2, 19)); + UT_ASSERT(cluster_semantic_activation_resource_x_peer_open_matches(&token, 2, 19)); test_gate_reset(); } @@ -8684,19 +7976,17 @@ UT_TEST(test_145m_resource_x_prepare_carrier_survives_unavailable_snapshot) ut_resource_x_open_carrier_setup(&token); table->stage = CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_SAMPLE; table->flags = CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID - | CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE; + | CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE; table->source_feature_bitmap = r4; table->capability_sample_digest = 0; for (node = 0; node < 4; node++) { table->expected[node].record_generation = table->record_generation; table->observed[node].record_generation = table->record_generation; } - test_gate_publish(2, r4, table->record_generation, - table->transition_epoch, true); + test_gate_publish(2, r4, table->record_generation, table->transition_epoch, true); semantic_activation_ack_local_request_origin.active = true; semantic_activation_lmon_prepare_cas_seq = 41; - semantic_activation_lmon_prepare_cas_utility_request_seq - = table->round_nonce; + semantic_activation_lmon_prepare_cas_utility_request_seq = table->round_nonce; memcpy(&before, table, sizeof(before)); test_membership_snapshot_valid = false; @@ -9307,7 +8597,7 @@ UT_TEST(test_normal_census_absent_own_directory_is_exact_zero_not_a_create) for (i = 0; i < 256; i++) UT_ASSERT_EQ(cold_probe_count[i], 1); UT_ASSERT_EQ(lstat(path, &st), -1); - UT_ASSERT_EQ(errno, ENOENT); /* Finish did not manufacture a directory. */ + UT_ASSERT_EQ(errno, ENOENT); /* Finish did not manufacture a directory. */ UT_ASSERT_EQ(mkdir(path, 0700), 0); /* Restore the fixture for existing cleanup. */ ut_cold_cleanup(); } @@ -10328,7 +9618,8 @@ UT_TEST(test_clean_restart_consumes_original_bootstrap_read_before_taking_mailbo UT_ASSERT_EQ(cluster_semantic_normal_stop_read_identity(&got, root, incarnations, NULL), CLUSTER_NORMAL_STOP_READY); UT_ASSERT_EQ(semantic_activation_lmon_stop_read_seq, 0); - UT_ASSERT_EQ(cluster_semantic_normal_stop_poll(NULL, NULL, NULL), CLUSTER_NORMAL_STOP_READY); + UT_ASSERT_EQ(cluster_semantic_normal_stop_poll(NULL, NULL, NULL), + CLUSTER_NORMAL_STOP_READY); test_gate_reset(); } } diff --git a/src/test/cluster_unit/test_cluster_r4_activation_record.c b/src/test/cluster_unit/test_cluster_r4_activation_record.c index 5438830c430..db02406eacd 100644 --- a/src/test/cluster_unit/test_cluster_r4_activation_record.c +++ b/src/test/cluster_unit/test_cluster_r4_activation_record.c @@ -17,8 +17,10 @@ #include "storage/shmem.h" #include "cluster_r4_activation_test_stubs.h" +#include "cluster_unit_no_normal_stop.h" int cluster_node_id = 0; +bool cluster_enabled = true; bool RecoveryInProgress(void) @@ -93,8 +95,7 @@ superuser(void) * refusal path is covered in the control-root suites. */ ClusterControlRootResult cluster_control_root_bootstrap_validate_active_round_fields( - uint64 transition_epoch pg_attribute_unused(), - uint64 prepare_generation pg_attribute_unused(), + uint64 transition_epoch pg_attribute_unused(), uint64 prepare_generation pg_attribute_unused(), uint64 source_feature_bitmap pg_attribute_unused(), uint64 target_feature_bitmap pg_attribute_unused()) { @@ -124,8 +125,7 @@ cluster_grd_recovery_state_value(void) } bool -cluster_reconfig_snapshot_initial_clean_formation( - ClusterInitialCleanFormationSnapshot *out) +cluster_reconfig_snapshot_initial_clean_formation(ClusterInitialCleanFormationSnapshot *out) { if (out != NULL) memset(out, 0, sizeof(*out)); @@ -133,8 +133,8 @@ cluster_reconfig_snapshot_initial_clean_formation( } bool -cluster_reconfig_get_observed_slot(int32 node_id pg_attribute_unused(), - uint64 *incarnation, uint64 *generation) +cluster_reconfig_get_observed_slot(int32 node_id pg_attribute_unused(), uint64 *incarnation, + uint64 *generation) { if (incarnation != NULL) *incarnation = 0; @@ -164,8 +164,7 @@ cluster_pcm_lock_resource_x_gate_snapshot(ResourceXGateSnapshot *snapshot_out) } bool -cluster_pcm_lock_resource_x_cutover_gate_snapshot_exact( - ResourceXGateSnapshot *snapshot_out) +cluster_pcm_lock_resource_x_cutover_gate_snapshot_exact(ResourceXGateSnapshot *snapshot_out) { if (snapshot_out != NULL) memset(snapshot_out, 0, sizeof(*snapshot_out)); @@ -173,9 +172,9 @@ cluster_pcm_lock_resource_x_cutover_gate_snapshot_exact( } bool -cluster_pcm_lock_resource_x_cutover_current_proof_digest_exact( - bool thawed pg_attribute_unused(), - ResourceXReconfigToken *token_out, uint64 *digest_out) +cluster_pcm_lock_resource_x_cutover_current_proof_digest_exact(bool thawed pg_attribute_unused(), + ResourceXReconfigToken *token_out, + uint64 *digest_out) { if (token_out != NULL) memset(token_out, 0, sizeof(*token_out)); @@ -852,7 +851,8 @@ UT_TEST(test_49_record_cas_mailbox_exact_sequence_lifecycle) ClusterSemanticActivationShmem shmem; ClusterSemanticActivationUtilityMailboxShmem utility; ClusterSemanticActivationCasRequest request; - ClusterSemanticActivationRecord desired_record = valid_record(CLUSTER_SEMANTIC_PHASE_PREPARE, 8); + ClusterSemanticActivationRecord desired_record + = valid_record(CLUSTER_SEMANTIC_PHASE_PREPARE, 8); ClusterSemanticActivationResult result = CLUSTER_SEMANTIC_ACTIVATION_BAD_STATE; uint8 desired[CLUSTER_SEMANTIC_ACTIVATION_RECORD_BYTES]; uint64 seq = UINT64_MAX; @@ -860,35 +860,27 @@ UT_TEST(test_49_record_cas_mailbox_exact_sequence_lifecycle) desired_record.transition_epoch = 0; desired_record.coordinator_node = (uint32)cluster_node_id; desired_record.coordinator_incarnation = 1; - desired_record.source_feature_bitmap - = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1; - desired_record.target_feature_bitmap - = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1 - | CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1; + desired_record.source_feature_bitmap = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1; + desired_record.target_feature_bitmap = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1 + | CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1; memset(&shmem, 0, sizeof(shmem)); pg_atomic_init_u64(&shmem.record_cas_request_seq, 0); pg_atomic_init_u64(&shmem.record_cas_completion_seq, 0); pg_atomic_init_u32(&shmem.record_cas_result, CLUSTER_SEMANTIC_ACTIVATION_BAD_STATE); - pg_atomic_init_u32(&shmem.record_cas_request_kind, - CLUSTER_SEMANTIC_AUTHORITY_REQUEST_NONE); + pg_atomic_init_u32(&shmem.record_cas_request_kind, CLUSTER_SEMANTIC_AUTHORITY_REQUEST_NONE); pg_atomic_init_u64(&shmem.admission_seq, 0); - pg_atomic_init_u64(&shmem.active_bits, - CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1); + pg_atomic_init_u64(&shmem.active_bits, CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1); pg_atomic_init_u64(&shmem.record_generation, 7); pg_atomic_init_u64(&shmem.formation_epoch, 0); pg_atomic_init_u32(&shmem.transition_closed, 1); memset(&utility, 0, sizeof(utility)); pg_atomic_init_u64(&utility.utility_request_seq, 1); pg_atomic_init_u64(&utility.utility_completion_seq, 0); - pg_atomic_init_u32(&utility.utility_mailbox_state, - SEMANTIC_ACTIVATION_UTILITY_MAILBOX_PENDING); + pg_atomic_init_u32(&utility.utility_mailbox_state, SEMANTIC_ACTIVATION_UTILITY_MAILBOX_PENDING); utility.utility_action = CLUSTER_SEMANTIC_ENABLE_ALL; - utility.utility_source_feature_bitmap - = desired_record.source_feature_bitmap; - utility.utility_target_feature_bitmap - = desired_record.target_feature_bitmap; - utility.utility_rollback_feature_bitmap - = desired_record.rollback_feature_bitmap; + utility.utility_source_feature_bitmap = desired_record.source_feature_bitmap; + utility.utility_target_feature_bitmap = desired_record.target_feature_bitmap; + utility.utility_rollback_feature_bitmap = desired_record.rollback_feature_bitmap; utility.utility_expected_record_generation = 7; SemanticActivationUtilityMailbox = &utility; cluster_r4_activation_test_formation_valid = true; @@ -902,8 +894,8 @@ UT_TEST(test_49_record_cas_mailbox_exact_sequence_lifecycle) 7, desired_record.source_feature_bitmap, NULL, &seq)); UT_ASSERT(!semantic_activation_record_cas_mailbox_submit( 7, desired_record.source_feature_bitmap, desired, NULL)); - UT_ASSERT(semantic_activation_record_cas_mailbox_submit( - 7, desired_record.source_feature_bitmap, desired, &seq)); + UT_ASSERT(semantic_activation_record_cas_mailbox_submit(7, desired_record.source_feature_bitmap, + desired, &seq)); UT_ASSERT_EQ(seq, 1); UT_ASSERT_EQ(pg_atomic_read_u64(&shmem.record_cas_request_seq), 1); UT_ASSERT_EQ(pg_atomic_read_u64(&shmem.record_cas_completion_seq), 0); @@ -913,8 +905,7 @@ UT_TEST(test_49_record_cas_mailbox_exact_sequence_lifecycle) UT_ASSERT(cluster_semantic_activation_qvotec_poll_record_cas(&request)); UT_ASSERT_EQ(request.request_seq, 1); UT_ASSERT_EQ(request.expected_generation, 7); - UT_ASSERT_EQ(request.expected_source_feature_bitmap, - desired_record.source_feature_bitmap); + UT_ASSERT_EQ(request.expected_source_feature_bitmap, desired_record.source_feature_bitmap); UT_ASSERT_EQ(memcmp(request.desired_bytes, desired, sizeof(desired)), 0); UT_ASSERT( !cluster_semantic_activation_qvotec_complete_record_cas(0, CLUSTER_SEMANTIC_ACTIVATION_OK)); @@ -929,8 +920,8 @@ UT_TEST(test_49_record_cas_mailbox_exact_sequence_lifecycle) UT_ASSERT_EQ(result, CLUSTER_SEMANTIC_ACTIVATION_RECORD_CONFLICT); UT_ASSERT(!semantic_activation_record_cas_mailbox_poll_completion(2, &result)); - UT_ASSERT(semantic_activation_record_cas_mailbox_submit( - 7, desired_record.source_feature_bitmap, desired, &seq)); + UT_ASSERT(semantic_activation_record_cas_mailbox_submit(7, desired_record.source_feature_bitmap, + desired, &seq)); UT_ASSERT_EQ(seq, 2); pg_atomic_write_u64(&shmem.record_cas_request_seq, UINT64_MAX); pg_atomic_write_u64(&shmem.record_cas_completion_seq, UINT64_MAX); @@ -963,18 +954,14 @@ UT_TEST(test_50_pgrd_uses_distinct_kind_in_existing_512_byte_mailbox) memset(&shmem, 0, sizeof(shmem)); pg_atomic_init_u64(&shmem.record_cas_request_seq, 0); pg_atomic_init_u64(&shmem.record_cas_completion_seq, 0); - pg_atomic_init_u32(&shmem.record_cas_result, - CLUSTER_SEMANTIC_ACTIVATION_BAD_STATE); - pg_atomic_init_u32(&shmem.record_cas_request_kind, - CLUSTER_SEMANTIC_AUTHORITY_REQUEST_NONE); + pg_atomic_init_u32(&shmem.record_cas_result, CLUSTER_SEMANTIC_ACTIVATION_BAD_STATE); + pg_atomic_init_u32(&shmem.record_cas_request_kind, CLUSTER_SEMANTIC_AUTHORITY_REQUEST_NONE); memset(&utility, 0, sizeof(utility)); pg_atomic_init_u64(&utility.utility_request_seq, 1); pg_atomic_init_u64(&utility.utility_completion_seq, 0); - pg_atomic_init_u32(&utility.utility_mailbox_state, - SEMANTIC_ACTIVATION_UTILITY_MAILBOX_PENDING); + pg_atomic_init_u32(&utility.utility_mailbox_state, SEMANTIC_ACTIVATION_UTILITY_MAILBOX_PENDING); utility.utility_action = CLUSTER_SEMANTIC_ENABLE_ALL; - utility.utility_target_feature_bitmap - = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1; + utility.utility_target_feature_bitmap = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1; for (i = 0; i < (int)sizeof(desired); i++) desired[i] = (uint8)(i ^ 0x5c); SemanticActivationShmem = &shmem; @@ -984,14 +971,11 @@ UT_TEST(test_50_pgrd_uses_distinct_kind_in_existing_512_byte_mailbox) UT_ASSERT(cluster_semantic_activation_undo_root_descriptor_mailbox_submit( &formation, UINT64_C(0x0123456789abcdef), desired, &seq)); UT_ASSERT_EQ(seq, 1); - UT_ASSERT(!cluster_semantic_activation_qvotec_poll_record_cas( - &record_request)); + UT_ASSERT(!cluster_semantic_activation_qvotec_poll_record_cas(&record_request)); memset(&request, 0, sizeof(request)); - UT_ASSERT(cluster_semantic_activation_qvotec_poll_undo_root_descriptor( - &request)); + UT_ASSERT(cluster_semantic_activation_qvotec_poll_undo_root_descriptor(&request)); UT_ASSERT_EQ(request.request_seq, 1); - UT_ASSERT_EQ(request.system_identifier, - UINT64_C(0x0123456789abcdef)); + UT_ASSERT_EQ(request.system_identifier, UINT64_C(0x0123456789abcdef)); UT_ASSERT_EQ(request.formation.utility_request_seq, UINT64_C(1)); UT_ASSERT_EQ(request.formation.formation_epoch, UINT64_C(0)); UT_ASSERT_EQ(request.formation.coordinator_incarnation, UINT64_C(1)); @@ -999,11 +983,10 @@ UT_TEST(test_50_pgrd_uses_distinct_kind_in_existing_512_byte_mailbox) UT_ASSERT_EQ(memcmp(request.desired_bytes, desired, sizeof(desired)), 0); UT_ASSERT(cluster_semantic_activation_qvotec_complete_undo_root_descriptor( request.request_seq, CLUSTER_SEMANTIC_ACTIVATION_OK)); - UT_ASSERT(cluster_semantic_activation_undo_root_descriptor_mailbox_poll_completion( - seq, &result)); + UT_ASSERT( + cluster_semantic_activation_undo_root_descriptor_mailbox_poll_completion(seq, &result)); UT_ASSERT_EQ(result, CLUSTER_SEMANTIC_ACTIVATION_OK); - UT_ASSERT_EQ(offsetof(ClusterSemanticActivationShmem, - record_cas_request_kind), 20); + UT_ASSERT_EQ(offsetof(ClusterSemanticActivationShmem, record_cas_request_kind), 20); UT_ASSERT_EQ(offsetof(ClusterSemanticActivationShmem, admission_seq), 552); UT_ASSERT_EQ(sizeof(ClusterSemanticActivationShmem), 1104); SemanticActivationShmem = NULL; @@ -1033,10 +1016,8 @@ UT_TEST(test_51_ack_sample_request_has_exact_wire_bytes) memset(bytes, 0xa5, sizeof(bytes)); UT_ASSERT_EQ(PGRAC_IC_MSG_SEMANTIC_ACTIVATION_ACK_V1, 65); - UT_ASSERT_EQ(PGRAC_IC_HELLO_CAP_SEMANTIC_ACTIVATION_ACK_V1, - UINT32_C(0x00008000)); - UT_ASSERT_EQ(CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS, - UINT32_C(0x0071B000)); + UT_ASSERT_EQ(PGRAC_IC_HELLO_CAP_SEMANTIC_ACTIVATION_ACK_V1, UINT32_C(0x00008000)); + UT_ASSERT_EQ(CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS, UINT32_C(0x0071B000)); UT_ASSERT_EQ(CLUSTER_SEMANTIC_ACTIVATION_ACK_WIRE_BYTES, 120); UT_ASSERT(cluster_semantic_activation_ack_wire_encode(&message, bytes)); UT_ASSERT_EQ(bytes[0], 0x41); @@ -1067,30 +1048,22 @@ UT_TEST(test_51_ack_sample_request_has_exact_wire_bytes) UT_TEST(test_52_ack_wire_decodes_hand_written_little_endian_bytes) { - static const uint8 bytes[CLUSTER_SEMANTIC_ACTIVATION_ACK_WIRE_BYTES] = { - 0x41, 0x43, 0x4b, 0x31, 0x01, 0x00, 0x02, 0x04, - 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, - 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, - 0x18, 0x17, 0x16, 0x15, 0x14, 0x13, 0x12, 0x11, - 0x28, 0x27, 0x26, 0x25, 0x24, 0x23, 0x22, 0x21, - 0x38, 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x31, - 0x48, 0x47, 0x46, 0x45, 0x44, 0x43, 0x42, 0x41, - 0x58, 0x57, 0x56, 0x55, 0x54, 0x53, 0x52, 0x51, - 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x68, 0x67, 0x66, 0x65, 0x64, 0x63, 0x62, 0x61, - 0x78, 0x77, 0x76, 0x75, 0x74, 0x73, 0x72, 0x71, - 0x88, 0x87, 0x86, 0x85, 0x84, 0x83, 0x82, 0x81, - 0x98, 0x97, 0x96, 0x95, 0x94, 0x93, 0x92, 0x91, - 0x00, 0xb0, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00 - }; + static const uint8 bytes[CLUSTER_SEMANTIC_ACTIVATION_ACK_WIRE_BYTES] + = { 0x41, 0x43, 0x4b, 0x31, 0x01, 0x00, 0x02, 0x04, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x08, 0x07, 0x06, 0x05, + 0x04, 0x03, 0x02, 0x01, 0x18, 0x17, 0x16, 0x15, 0x14, 0x13, 0x12, 0x11, 0x28, 0x27, + 0x26, 0x25, 0x24, 0x23, 0x22, 0x21, 0x38, 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x31, + 0x48, 0x47, 0x46, 0x45, 0x44, 0x43, 0x42, 0x41, 0x58, 0x57, 0x56, 0x55, 0x54, 0x53, + 0x52, 0x51, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x68, 0x67, 0x66, 0x65, + 0x64, 0x63, 0x62, 0x61, 0x78, 0x77, 0x76, 0x75, 0x74, 0x73, 0x72, 0x71, 0x88, 0x87, + 0x86, 0x85, 0x84, 0x83, 0x82, 0x81, 0x98, 0x97, 0x96, 0x95, 0x94, 0x93, 0x92, 0x91, + 0x00, 0xb0, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00 }; ClusterSemanticActivationAckWireV1 message; memset(&message, 0xa5, sizeof(message)); UT_ASSERT(cluster_semantic_activation_ack_wire_decode(bytes, &message)); UT_ASSERT_EQ(message.kind, CLUSTER_SEMANTIC_ACTIVATION_ACK_KIND_ACK); - UT_ASSERT_EQ(message.stage, - CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_COMMIT_APPLIED); + UT_ASSERT_EQ(message.stage, CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_COMMIT_APPLIED); UT_ASSERT_EQ(message.result, CLUSTER_SEMANTIC_ACTIVATION_ACK_RESULT_OK); UT_ASSERT_EQ(message.reason, UINT32_C(0)); UT_ASSERT_EQ(message.coordinator_node, UINT32_C(1)); @@ -1417,19 +1390,15 @@ UT_TEST(test_62_ack_tuple_and_table_have_exact_frozen_layout) { UT_ASSERT_EQ(CLUSTER_SEMANTIC_ACTIVATION_ACK_TUPLE_BYTES, 64); UT_ASSERT_EQ(CLUSTER_SEMANTIC_ACTIVATION_ACK_TABLE_BYTES, 16496); - UT_ASSERT_EQ(CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID, - UINT32_C(1)); - UT_ASSERT_EQ(CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE, - UINT32_C(2)); - UT_ASSERT_EQ(CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_OPEN_PROOF, - UINT32_C(4)); + UT_ASSERT_EQ(CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID, UINT32_C(1)); + UT_ASSERT_EQ(CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE, UINT32_C(2)); + UT_ASSERT_EQ(CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_OPEN_PROOF, UINT32_C(4)); UT_ASSERT_EQ(sizeof(SemanticActivationAckTuple), 64); UT_ASSERT_EQ(offsetof(SemanticActivationAckTuple, node_id), 0); UT_ASSERT_EQ(offsetof(SemanticActivationAckTuple, boot_id), 8); UT_ASSERT_EQ(offsetof(SemanticActivationAckTuple, admitted_incarnation), 16); - UT_ASSERT_EQ(offsetof(SemanticActivationAckTuple, - control_connection_generation), 24); + UT_ASSERT_EQ(offsetof(SemanticActivationAckTuple, control_connection_generation), 24); UT_ASSERT_EQ(offsetof(SemanticActivationAckTuple, capability_word), 32); UT_ASSERT_EQ(offsetof(SemanticActivationAckTuple, capability_generation), 40); UT_ASSERT_EQ(offsetof(SemanticActivationAckTuple, transition_epoch), 48); @@ -1448,14 +1417,10 @@ UT_TEST(test_62_ack_tuple_and_table_have_exact_frozen_layout) UT_ASSERT_EQ(offsetof(ClusterSemanticActivationAckTableV1, observed_members_hi), 56); UT_ASSERT_EQ(offsetof(ClusterSemanticActivationAckTableV1, transition_epoch), 64); UT_ASSERT_EQ(offsetof(ClusterSemanticActivationAckTableV1, record_generation), 72); - UT_ASSERT_EQ(offsetof(ClusterSemanticActivationAckTableV1, - source_feature_bitmap), 80); - UT_ASSERT_EQ(offsetof(ClusterSemanticActivationAckTableV1, - target_feature_bitmap), 88); - UT_ASSERT_EQ(offsetof(ClusterSemanticActivationAckTableV1, - rollback_feature_bitmap), 96); - UT_ASSERT_EQ(offsetof(ClusterSemanticActivationAckTableV1, - capability_sample_digest), 104); + UT_ASSERT_EQ(offsetof(ClusterSemanticActivationAckTableV1, source_feature_bitmap), 80); + UT_ASSERT_EQ(offsetof(ClusterSemanticActivationAckTableV1, target_feature_bitmap), 88); + UT_ASSERT_EQ(offsetof(ClusterSemanticActivationAckTableV1, rollback_feature_bitmap), 96); + UT_ASSERT_EQ(offsetof(ClusterSemanticActivationAckTableV1, capability_sample_digest), 104); UT_ASSERT_EQ(offsetof(ClusterSemanticActivationAckTableV1, expected), 112); UT_ASSERT_EQ(offsetof(ClusterSemanticActivationAckTableV1, observed), 8304); } @@ -1502,7 +1467,8 @@ UT_TEST(test_64_shmem_size_includes_exact_ack_table) /* contract: online first-open via the source-close * BARRIER. */ + MAXALIGN(sizeof(ClusterR4Bit22SourceCloseShmem)) - + MAXALIGN(sizeof(pg_atomic_uint32)); /* local clean-start observation */ + + MAXALIGN(sizeof(pg_atomic_uint32)) /* local clean-start observation */ + + MAXALIGN(sizeof(ClusterNormalStartCompletion)); UT_ASSERT_EQ(cluster_semantic_activation_shmem_size(), expected); } @@ -1527,10 +1493,8 @@ UT_TEST(test_65_ack_table_snapshot_accepts_even_and_rejects_odd) UT_ASSERT(semantic_activation_ack_table_snapshot(&snapshot)); UT_ASSERT_EQ(pg_atomic_read_u64(&snapshot.publication_seq), 2); - UT_ASSERT_EQ(snapshot.stage, - CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_BARRIER); - UT_ASSERT_EQ(snapshot.flags, - CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID); + UT_ASSERT_EQ(snapshot.stage, CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_BARRIER); + UT_ASSERT_EQ(snapshot.flags, CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID); UT_ASSERT_EQ(snapshot.coordinator_node, 1); UT_ASSERT_EQ(snapshot.round_nonce, 7); UT_ASSERT_EQ(snapshot.expected_members_lo, UINT64_C(0x0f)); @@ -1567,10 +1531,8 @@ UT_TEST(test_66_ack_table_publish_advances_even_and_refuses_bad_sequence) UT_ASSERT(semantic_activation_ack_table_publish(&image)); UT_ASSERT_EQ(pg_atomic_read_u64(&table.publication_seq), 6); - UT_ASSERT_EQ(table.stage, - CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_BARRIER); - UT_ASSERT_EQ(table.flags, - CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID); + UT_ASSERT_EQ(table.stage, CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_BARRIER); + UT_ASSERT_EQ(table.flags, CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID); UT_ASSERT_EQ(table.coordinator_node, 1); UT_ASSERT_EQ(table.round_nonce, 7); UT_ASSERT_EQ(table.expected_members_lo, UINT64_C(0x0f)); @@ -1583,13 +1545,11 @@ UT_TEST(test_66_ack_table_publish_advances_even_and_refuses_bad_sequence) image.stage = CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_PREPARED; UT_ASSERT(!semantic_activation_ack_table_publish(&image)); UT_ASSERT_EQ(pg_atomic_read_u64(&table.publication_seq), 7); - UT_ASSERT_EQ(table.stage, - CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_BARRIER); + UT_ASSERT_EQ(table.stage, CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_BARRIER); pg_atomic_write_u64(&table.publication_seq, UINT64_MAX - 1); UT_ASSERT(!semantic_activation_ack_table_publish(&image)); UT_ASSERT_EQ(pg_atomic_read_u64(&table.publication_seq), UINT64_MAX - 1); - UT_ASSERT_EQ(table.stage, - CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_BARRIER); + UT_ASSERT_EQ(table.stage, CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_BARRIER); SemanticActivationAckTable = NULL; } @@ -1599,14 +1559,10 @@ UT_TEST(test_67_ack_ingress_handoff_has_exact_frozen_layout) UT_ASSERT_EQ(sizeof(ClusterSemanticActivationAckWireV1), 120); UT_ASSERT_EQ(sizeof(SemanticActivationAckIngressItem), 136); UT_ASSERT_EQ(offsetof(SemanticActivationAckIngressItem, message), 0); - UT_ASSERT_EQ(offsetof(SemanticActivationAckIngressItem, - authenticated_source_node_id), 120); - UT_ASSERT_EQ(offsetof(SemanticActivationAckIngressItem, - local_receiver_node_id), 124); - UT_ASSERT_EQ(offsetof(SemanticActivationAckIngressItem, - sampled_capability_word), 128); - UT_ASSERT_EQ(offsetof(SemanticActivationAckIngressItem, - sampled_capability_generation), 132); + UT_ASSERT_EQ(offsetof(SemanticActivationAckIngressItem, authenticated_source_node_id), 120); + UT_ASSERT_EQ(offsetof(SemanticActivationAckIngressItem, local_receiver_node_id), 124); + UT_ASSERT_EQ(offsetof(SemanticActivationAckIngressItem, sampled_capability_word), 128); + UT_ASSERT_EQ(offsetof(SemanticActivationAckIngressItem, sampled_capability_generation), 132); UT_ASSERT_EQ(sizeof(SemanticActivationAckIngress), 34832); UT_ASSERT_EQ(offsetof(SemanticActivationAckIngress, producer_seq), 0); UT_ASSERT_EQ(offsetof(SemanticActivationAckIngress, consumer_seq), 8); @@ -1631,8 +1587,7 @@ UT_TEST(test_68_ack_ingress_handoff_is_bounded_and_fail_closed) UT_ASSERT_EQ(semantic_activation_ack_ingress_pending(&ingress), 0); memset(&out, 0xa5, sizeof(out)); UT_ASSERT(!semantic_activation_ack_ingress_poll(&ingress, &out)); - UT_ASSERT_EQ((uint32)out.authenticated_source_node_id, - UINT32_C(0xa5a5a5a5)); + UT_ASSERT_EQ((uint32)out.authenticated_source_node_id, UINT32_C(0xa5a5a5a5)); for (i = 0; i < CLUSTER_SEMANTIC_ACTIVATION_ACK_INGRESS_CAPACITY; i++) { item.message.member_node = i % CLUSTER_MAX_NODES; @@ -1642,12 +1597,10 @@ UT_TEST(test_68_ack_ingress_handoff_is_bounded_and_fail_closed) UT_ASSERT(!semantic_activation_ack_ingress_push(&ingress, &item)); UT_ASSERT_EQ(ingress.producer_seq, UINT64_C(256)); UT_ASSERT(semantic_activation_ack_ingress_poll(&ingress, &out)); - UT_ASSERT_EQ(out.message.kind, - CLUSTER_SEMANTIC_ACTIVATION_ACK_KIND_ACK); + UT_ASSERT_EQ(out.message.kind, CLUSTER_SEMANTIC_ACTIVATION_ACK_KIND_ACK); UT_ASSERT_EQ(out.authenticated_source_node_id, 3); UT_ASSERT_EQ(out.local_receiver_node_id, 1); - UT_ASSERT_EQ(out.sampled_capability_word, - CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS); + UT_ASSERT_EQ(out.sampled_capability_word, CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS); UT_ASSERT_EQ(out.sampled_capability_generation, 7); UT_ASSERT_EQ(semantic_activation_ack_ingress_pending(&ingress), 255); @@ -1657,8 +1610,7 @@ UT_TEST(test_68_ack_ingress_handoff_is_bounded_and_fail_closed) UT_ASSERT_EQ(semantic_activation_ack_ingress_pending(&ingress), 0); UT_ASSERT(!semantic_activation_ack_ingress_push(&ingress, &item)); UT_ASSERT(!semantic_activation_ack_ingress_poll(&ingress, &out)); - UT_ASSERT_EQ((uint32)out.authenticated_source_node_id, - UINT32_C(0xa5a5a5a5)); + UT_ASSERT_EQ((uint32)out.authenticated_source_node_id, UINT32_C(0xa5a5a5a5)); } static ClusterSemanticActivationAckWireV1 @@ -1676,14 +1628,12 @@ valid_positive_ack(void) message.record_generation = 10; message.round_nonce = 11; message.source_feature_bitmap = 0; - message.target_feature_bitmap - = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1; + message.target_feature_bitmap = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1; message.admitted_members_lo = UINT64_C(0x0b); message.boot_id = 12; message.admitted_incarnation = 12; message.capability_word - = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS - | PGRAC_IC_HELLO_CAP_GCS_DONE_V1; + = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS | PGRAC_IC_HELLO_CAP_GCS_DONE_V1; return message; } @@ -1714,9 +1664,9 @@ UT_TEST(test_69_ack_ingress_stamps_coherent_remote_sample) cluster_r4_activation_test_capability_generation = 7; semantic_activation_ack_ingress_init(&ingress); UT_ASSERT(cluster_semantic_activation_ack_wire_encode(&message, payload)); - UT_ASSERT_EQ(semantic_activation_ack_ingress_receive( - &ingress, &env, payload, sizeof(payload), 1, 9), - SEMANTIC_ACTIVATION_ACK_INGRESS_ENQUEUED); + UT_ASSERT_EQ( + semantic_activation_ack_ingress_receive(&ingress, &env, payload, sizeof(payload), 1, 9), + SEMANTIC_ACTIVATION_ACK_INGRESS_ENQUEUED); UT_ASSERT(semantic_activation_ack_ingress_poll(&ingress, &out)); UT_ASSERT_EQ(memcmp(&out.message, &message, sizeof(message)), 0); UT_ASSERT_EQ(out.authenticated_source_node_id, 3); @@ -1738,43 +1688,43 @@ UT_TEST(test_70_ack_ingress_rejects_role_epoch_and_sample_drift) semantic_activation_ack_ingress_init(&ingress); UT_ASSERT(cluster_semantic_activation_ack_wire_encode(&message, payload)); - UT_ASSERT_EQ(semantic_activation_ack_ingress_receive( - &ingress, &env, payload, sizeof(payload) - 1, 1, 9), - SEMANTIC_ACTIVATION_ACK_INGRESS_REJECTED); + UT_ASSERT_EQ( + semantic_activation_ack_ingress_receive(&ingress, &env, payload, sizeof(payload) - 1, 1, 9), + SEMANTIC_ACTIVATION_ACK_INGRESS_REJECTED); env.dest_node_id = 2; - UT_ASSERT_EQ(semantic_activation_ack_ingress_receive( - &ingress, &env, payload, sizeof(payload), 1, 9), - SEMANTIC_ACTIVATION_ACK_INGRESS_REJECTED); + UT_ASSERT_EQ( + semantic_activation_ack_ingress_receive(&ingress, &env, payload, sizeof(payload), 1, 9), + SEMANTIC_ACTIVATION_ACK_INGRESS_REJECTED); env = valid_ack_envelope(3, 1); env.epoch = 8; - UT_ASSERT_EQ(semantic_activation_ack_ingress_receive( - &ingress, &env, payload, sizeof(payload), 1, 9), - SEMANTIC_ACTIVATION_ACK_INGRESS_REJECTED); + UT_ASSERT_EQ( + semantic_activation_ack_ingress_receive(&ingress, &env, payload, sizeof(payload), 1, 9), + SEMANTIC_ACTIVATION_ACK_INGRESS_REJECTED); env = valid_ack_envelope(4, 1); - UT_ASSERT_EQ(semantic_activation_ack_ingress_receive( - &ingress, &env, payload, sizeof(payload), 1, 9), - SEMANTIC_ACTIVATION_ACK_INGRESS_REJECTED); + UT_ASSERT_EQ( + semantic_activation_ack_ingress_receive(&ingress, &env, payload, sizeof(payload), 1, 9), + SEMANTIC_ACTIVATION_ACK_INGRESS_REJECTED); env = valid_ack_envelope(3, 1); cluster_r4_activation_test_capability_word_sample_ok = false; - UT_ASSERT_EQ(semantic_activation_ack_ingress_receive( - &ingress, &env, payload, sizeof(payload), 1, 9), - SEMANTIC_ACTIVATION_ACK_INGRESS_REJECTED); + UT_ASSERT_EQ( + semantic_activation_ack_ingress_receive(&ingress, &env, payload, sizeof(payload), 1, 9), + SEMANTIC_ACTIVATION_ACK_INGRESS_REJECTED); cluster_r4_activation_test_capability_word_sample_ok = true; cluster_r4_activation_test_capability_generation = 0; - UT_ASSERT_EQ(semantic_activation_ack_ingress_receive( - &ingress, &env, payload, sizeof(payload), 1, 9), - SEMANTIC_ACTIVATION_ACK_INGRESS_REJECTED); + UT_ASSERT_EQ( + semantic_activation_ack_ingress_receive(&ingress, &env, payload, sizeof(payload), 1, 9), + SEMANTIC_ACTIVATION_ACK_INGRESS_REJECTED); cluster_r4_activation_test_capability_generation = 7; cluster_r4_activation_test_capability_word ^= PGRAC_IC_HELLO_CAP_GCS_DONE_V1; - UT_ASSERT_EQ(semantic_activation_ack_ingress_receive( - &ingress, &env, payload, sizeof(payload), 1, 9), - SEMANTIC_ACTIVATION_ACK_INGRESS_REJECTED); + UT_ASSERT_EQ( + semantic_activation_ack_ingress_receive(&ingress, &env, payload, sizeof(payload), 1, 9), + SEMANTIC_ACTIVATION_ACK_INGRESS_REJECTED); cluster_r4_activation_test_capability_word = message.capability_word; message.admitted_incarnation++; UT_ASSERT(cluster_semantic_activation_ack_wire_encode(&message, payload)); - UT_ASSERT_EQ(semantic_activation_ack_ingress_receive( - &ingress, &env, payload, sizeof(payload), 1, 9), - SEMANTIC_ACTIVATION_ACK_INGRESS_REJECTED); + UT_ASSERT_EQ( + semantic_activation_ack_ingress_receive(&ingress, &env, payload, sizeof(payload), 1, 9), + SEMANTIC_ACTIVATION_ACK_INGRESS_REJECTED); UT_ASSERT_EQ(semantic_activation_ack_ingress_pending(&ingress), 0); } @@ -1786,8 +1736,7 @@ UT_TEST(test_71_ack_ingress_accepts_request_and_refusal_roles) uint8 payload[CLUSTER_SEMANTIC_ACTIVATION_ACK_WIRE_BYTES]; cluster_r4_activation_test_capability_word_sample_ok = true; - cluster_r4_activation_test_capability_word - = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS; + cluster_r4_activation_test_capability_word = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS; cluster_r4_activation_test_capability_generation = 7; semantic_activation_ack_ingress_init(&ingress); memset(&message, 0, sizeof(message)); @@ -1800,14 +1749,13 @@ UT_TEST(test_71_ack_ingress_accepts_request_and_refusal_roles) message.record_generation = 10; message.round_nonce = 11; message.source_feature_bitmap = 0; - message.target_feature_bitmap - = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1; + message.target_feature_bitmap = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1; message.admitted_members_lo = UINT64_C(0x0a); env = valid_ack_envelope(3, 1); UT_ASSERT(cluster_semantic_activation_ack_wire_encode(&message, payload)); - UT_ASSERT_EQ(semantic_activation_ack_ingress_receive( - &ingress, &env, payload, sizeof(payload), 1, 9), - SEMANTIC_ACTIVATION_ACK_INGRESS_ENQUEUED); + UT_ASSERT_EQ( + semantic_activation_ack_ingress_receive(&ingress, &env, payload, sizeof(payload), 1, 9), + SEMANTIC_ACTIVATION_ACK_INGRESS_ENQUEUED); message.kind = CLUSTER_SEMANTIC_ACTIVATION_ACK_KIND_ACK; message.result = CLUSTER_SEMANTIC_ACTIVATION_ACK_RESULT_REFUSED; @@ -1816,9 +1764,9 @@ UT_TEST(test_71_ack_ingress_accepts_request_and_refusal_roles) message.member_node = 3; env = valid_ack_envelope(3, 1); UT_ASSERT(cluster_semantic_activation_ack_wire_encode(&message, payload)); - UT_ASSERT_EQ(semantic_activation_ack_ingress_receive( - &ingress, &env, payload, sizeof(payload), 1, 9), - SEMANTIC_ACTIVATION_ACK_INGRESS_ENQUEUED); + UT_ASSERT_EQ( + semantic_activation_ack_ingress_receive(&ingress, &env, payload, sizeof(payload), 1, 9), + SEMANTIC_ACTIVATION_ACK_INGRESS_ENQUEUED); UT_ASSERT_EQ(semantic_activation_ack_ingress_pending(&ingress), 2); } @@ -1840,25 +1788,28 @@ UT_TEST(test_72_ack_handler_only_enqueues_and_counts_typed_drops) UT_ASSERT(cluster_semantic_activation_ack_wire_encode(&message, payload)); cluster_semantic_activation_ack_handler(&env, payload); - UT_ASSERT_EQ(semantic_activation_ack_ingress_pending( - &semantic_activation_ack_local_ingress), 1); - UT_ASSERT_EQ(semantic_activation_ack_ingress_result_count[ - SEMANTIC_ACTIVATION_ACK_INGRESS_ENQUEUED], UINT64_C(1)); - UT_ASSERT_EQ(semantic_activation_ack_ingress_result_count[ - SEMANTIC_ACTIVATION_ACK_INGRESS_REJECTED], UINT64_C(0)); + UT_ASSERT_EQ(semantic_activation_ack_ingress_pending(&semantic_activation_ack_local_ingress), + 1); + UT_ASSERT_EQ( + semantic_activation_ack_ingress_result_count[SEMANTIC_ACTIVATION_ACK_INGRESS_ENQUEUED], + UINT64_C(1)); + UT_ASSERT_EQ( + semantic_activation_ack_ingress_result_count[SEMANTIC_ACTIVATION_ACK_INGRESS_REJECTED], + UINT64_C(0)); payload[119] = 1; cluster_semantic_activation_ack_handler(&env, payload); - UT_ASSERT_EQ(semantic_activation_ack_ingress_pending( - &semantic_activation_ack_local_ingress), 1); - UT_ASSERT_EQ(semantic_activation_ack_ingress_result_count[ - SEMANTIC_ACTIVATION_ACK_INGRESS_REJECTED], UINT64_C(1)); + UT_ASSERT_EQ(semantic_activation_ack_ingress_pending(&semantic_activation_ack_local_ingress), + 1); + UT_ASSERT_EQ( + semantic_activation_ack_ingress_result_count[SEMANTIC_ACTIVATION_ACK_INGRESS_REJECTED], + UINT64_C(1)); payload[119] = 0; semantic_activation_ack_local_ingress.consumer_seq = 0; semantic_activation_ack_local_ingress.producer_seq = CLUSTER_SEMANTIC_ACTIVATION_ACK_INGRESS_CAPACITY; cluster_semantic_activation_ack_handler(&env, payload); - UT_ASSERT_EQ(semantic_activation_ack_ingress_result_count[ - SEMANTIC_ACTIVATION_ACK_INGRESS_FULL], UINT64_C(1)); + UT_ASSERT_EQ(semantic_activation_ack_ingress_result_count[SEMANTIC_ACTIVATION_ACK_INGRESS_FULL], + UINT64_C(1)); } static SemanticActivationAckIngressItem @@ -1877,19 +1828,16 @@ valid_positive_ack_item(void) static void assert_remote_ack_tuple_rejected(const SemanticActivationAckIngressItem *item, - uint64 current_members_lo, - uint64 current_members_hi, - uint64 current_epoch, - int32 current_coordinator) + uint64 current_members_lo, uint64 current_members_hi, + uint64 current_epoch, int32 current_coordinator) { SemanticActivationAckTuple output; SemanticActivationAckTuple before; memset(&output, 0xa5, sizeof(output)); before = output; - UT_ASSERT(!semantic_activation_ack_remote_tuple( - item, current_members_lo, current_members_hi, current_epoch, - current_coordinator, &output)); + UT_ASSERT(!semantic_activation_ack_remote_tuple(item, current_members_lo, current_members_hi, + current_epoch, current_coordinator, &output)); UT_ASSERT_EQ(memcmp(&output, &before, sizeof(output)), 0); } @@ -1903,13 +1851,11 @@ UT_TEST(test_73_lmon_remote_ack_builds_exact_current_tuple) cluster_r4_activation_test_membership_state = CLUSTER_MEMBER_MEMBER; cluster_r4_activation_test_capability_generation_matches = true; cluster_r4_activation_test_capability_peer = 3; - cluster_r4_activation_test_capability_required - = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS; + cluster_r4_activation_test_capability_required = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS; cluster_r4_activation_test_capability_expected_generation = 7; memset(&output, 0xa5, sizeof(output)); - UT_ASSERT(semantic_activation_ack_remote_tuple( - &item, UINT64_C(0x0b), 0, 9, 0, &output)); + UT_ASSERT(semantic_activation_ack_remote_tuple(&item, UINT64_C(0x0b), 0, 9, 0, &output)); UT_ASSERT_EQ(output.node_id, 3); UT_ASSERT_EQ(output.boot_id, UINT64_C(12)); UT_ASSERT_EQ(output.admitted_incarnation, UINT64_C(12)); @@ -1929,8 +1875,7 @@ UT_TEST(test_74_lmon_remote_ack_revalidates_every_authority_input) cluster_r4_activation_test_membership_state = CLUSTER_MEMBER_MEMBER; cluster_r4_activation_test_capability_generation_matches = true; cluster_r4_activation_test_capability_peer = 3; - cluster_r4_activation_test_capability_required - = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS; + cluster_r4_activation_test_capability_required = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS; cluster_r4_activation_test_capability_expected_generation = 7; assert_remote_ack_tuple_rejected(NULL, UINT64_C(0x0b), 0, 9, 0); @@ -1976,8 +1921,7 @@ UT_TEST(test_75_lmon_self_ack_builds_exact_local_tuple) { SemanticActivationAckTuple output; uint32 local_capability_word - = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS - | PGRAC_IC_HELLO_CAP_GCS_DONE_V1; + = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS | PGRAC_IC_HELLO_CAP_GCS_DONE_V1; cluster_r4_activation_test_self_incarnation = 11; cluster_r4_activation_test_membership_node = 0; @@ -1985,8 +1929,7 @@ UT_TEST(test_75_lmon_self_ack_builds_exact_local_tuple) cluster_r4_activation_test_membership_state = CLUSTER_MEMBER_MEMBER; memset(&output, 0xa5, sizeof(output)); - UT_ASSERT(semantic_activation_ack_self_tuple( - 0, local_capability_word, 9, 10, &output)); + UT_ASSERT(semantic_activation_ack_self_tuple(0, local_capability_word, 9, 10, &output)); UT_ASSERT_EQ(output.node_id, 0); UT_ASSERT_EQ(output.boot_id, UINT64_C(11)); UT_ASSERT_EQ(output.admitted_incarnation, UINT64_C(11)); @@ -2002,8 +1945,7 @@ UT_TEST(test_76_lmon_self_ack_is_fail_closed_on_local_drift) SemanticActivationAckTuple output; SemanticActivationAckTuple before; uint32 local_capability_word - = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS - | PGRAC_IC_HELLO_CAP_GCS_DONE_V1; + = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS | PGRAC_IC_HELLO_CAP_GCS_DONE_V1; cluster_r4_activation_test_self_incarnation = 11; cluster_r4_activation_test_membership_node = 0; @@ -2012,31 +1954,24 @@ UT_TEST(test_76_lmon_self_ack_is_fail_closed_on_local_drift) memset(&output, 0xa5, sizeof(output)); before = output; - UT_ASSERT(!semantic_activation_ack_self_tuple( - -1, local_capability_word, 9, 10, &output)); + UT_ASSERT(!semantic_activation_ack_self_tuple(-1, local_capability_word, 9, 10, &output)); UT_ASSERT_EQ(memcmp(&output, &before, sizeof(output)), 0); cluster_r4_activation_test_self_incarnation = 0; - UT_ASSERT(!semantic_activation_ack_self_tuple( - 0, local_capability_word, 9, 10, &output)); + UT_ASSERT(!semantic_activation_ack_self_tuple(0, local_capability_word, 9, 10, &output)); UT_ASSERT_EQ(memcmp(&output, &before, sizeof(output)), 0); cluster_r4_activation_test_self_incarnation = 11; cluster_r4_activation_test_membership_state = CLUSTER_MEMBER_JOINING; - UT_ASSERT(!semantic_activation_ack_self_tuple( - 0, local_capability_word, 9, 10, &output)); + UT_ASSERT(!semantic_activation_ack_self_tuple(0, local_capability_word, 9, 10, &output)); UT_ASSERT_EQ(memcmp(&output, &before, sizeof(output)), 0); cluster_r4_activation_test_membership_state = CLUSTER_MEMBER_MEMBER; cluster_r4_activation_test_membership_floor = 12; - UT_ASSERT(!semantic_activation_ack_self_tuple( - 0, local_capability_word, 9, 10, &output)); + UT_ASSERT(!semantic_activation_ack_self_tuple(0, local_capability_word, 9, 10, &output)); UT_ASSERT_EQ(memcmp(&output, &before, sizeof(output)), 0); cluster_r4_activation_test_membership_floor = 11; UT_ASSERT(!semantic_activation_ack_self_tuple( - 0, local_capability_word - & ~PGRAC_IC_HELLO_CAP_SEMANTIC_ACTIVATION_ACK_V1, - 9, 10, &output)); + 0, local_capability_word & ~PGRAC_IC_HELLO_CAP_SEMANTIC_ACTIVATION_ACK_V1, 9, 10, &output)); UT_ASSERT_EQ(memcmp(&output, &before, sizeof(output)), 0); - UT_ASSERT(!semantic_activation_ack_self_tuple( - 0, local_capability_word, 9, 0, &output)); + UT_ASSERT(!semantic_activation_ack_self_tuple(0, local_capability_word, 9, 0, &output)); UT_ASSERT_EQ(memcmp(&output, &before, sizeof(output)), 0); } @@ -2051,18 +1986,16 @@ UT_TEST(test_77_lmon_current_ack_authority_uses_exact_member_snapshot) cluster_r4_activation_test_in_quorum = true; cluster_r4_activation_test_admitted_snapshot_valid = true; - cluster_r4_activation_test_admitted_members_lo - = (UINT64_C(1) << 3) | (UINT64_C(1) << 7); + cluster_r4_activation_test_admitted_members_lo = (UINT64_C(1) << 3) | (UINT64_C(1) << 7); cluster_r4_activation_test_admitted_members_hi = 0; cluster_r4_activation_test_admitted_epoch = 9; cluster_r4_activation_test_current_epoch = 9; cluster_r4_activation_test_membership_node = 7; cluster_r4_activation_test_membership_state = CLUSTER_MEMBER_MEMBER; - UT_ASSERT(semantic_activation_ack_current_authority( - 7, &members_lo, &members_hi, &formation_epoch, &coordinator)); - UT_ASSERT_EQ(members_lo, - (UINT64_C(1) << 3) | (UINT64_C(1) << 7)); + UT_ASSERT(semantic_activation_ack_current_authority(7, &members_lo, &members_hi, + &formation_epoch, &coordinator)); + UT_ASSERT_EQ(members_lo, (UINT64_C(1) << 3) | (UINT64_C(1) << 7)); UT_ASSERT_EQ(members_hi, 0); UT_ASSERT_EQ(formation_epoch, UINT64_C(9)); UT_ASSERT_EQ(coordinator, 3); @@ -2081,9 +2014,8 @@ assert_current_ack_authority_rejected(int32 local_node_id) uint64 formation_epoch = UINT64_MAX; int32 coordinator = 127; - UT_ASSERT(!semantic_activation_ack_current_authority( - local_node_id, &members_lo, &members_hi, &formation_epoch, - &coordinator)); + UT_ASSERT(!semantic_activation_ack_current_authority(local_node_id, &members_lo, &members_hi, + &formation_epoch, &coordinator)); UT_ASSERT_EQ(members_lo, 0); UT_ASSERT_EQ(members_hi, 0); UT_ASSERT_EQ(formation_epoch, 0); @@ -2139,8 +2071,7 @@ valid_current_self_tuple(void) .admitted_incarnation = 11, .control_connection_generation = 11, .capability_word - = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS - | PGRAC_IC_HELLO_CAP_GCS_DONE_V1, + = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS | PGRAC_IC_HELLO_CAP_GCS_DONE_V1, .capability_generation = 11, .transition_epoch = 9, .record_generation = 10, @@ -2159,8 +2090,7 @@ init_current_sample_table(ClusterSemanticActivationAckTableV1 *table) table->transition_epoch = 9; table->record_generation = 10; table->source_feature_bitmap = 0; - table->target_feature_bitmap - = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1; + table->target_feature_bitmap = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1; table->observed_members_lo = UINT64_C(0x01); table->observed[0] = valid_current_self_tuple(); } @@ -2173,8 +2103,7 @@ set_current_remote_ack_dependencies(void) cluster_r4_activation_test_membership_state = CLUSTER_MEMBER_MEMBER; cluster_r4_activation_test_capability_generation_matches = true; cluster_r4_activation_test_capability_peer = 3; - cluster_r4_activation_test_capability_required - = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS; + cluster_r4_activation_test_capability_required = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS; cluster_r4_activation_test_capability_expected_generation = 7; } @@ -2186,19 +2115,16 @@ UT_TEST(test_79_lmon_sample_ack_promotes_complete_observed_image) init_current_sample_table(&table); set_current_remote_ack_dependencies(); SemanticActivationAckTable = &table; - UT_ASSERT_EQ(semantic_activation_ack_lmon_apply_item( - &item, UINT64_C(0x09), 0, 9, 0), - SEMANTIC_ACTIVATION_ACK_CONSUME_APPLIED); + UT_ASSERT_EQ(semantic_activation_ack_lmon_apply_item(&item, UINT64_C(0x09), 0, 9, 0), + SEMANTIC_ACTIVATION_ACK_CONSUME_APPLIED); UT_ASSERT_EQ(pg_atomic_read_u64(&table.publication_seq), 2); - UT_ASSERT_EQ(table.flags, - CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID - | CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE); + UT_ASSERT_EQ(table.flags, CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID + | CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE); UT_ASSERT_EQ(table.expected_members_lo, UINT64_C(0x09)); UT_ASSERT_EQ(table.observed_members_lo, UINT64_C(0x09)); UT_ASSERT(semantic_activation_full_ack_table_matches( - table.observed, table.observed_members_lo, table.observed_members_hi, - table.expected, table.expected_members_lo, - table.expected_members_hi)); + table.observed, table.observed_members_lo, table.observed_members_hi, table.expected, + table.expected_members_lo, table.expected_members_hi)); UT_ASSERT_EQ(table.expected[3].node_id, 3); UT_ASSERT_EQ(table.expected[3].boot_id, UINT64_C(12)); UT_ASSERT_EQ(table.expected[3].capability_generation, UINT64_C(7)); @@ -2216,27 +2142,25 @@ UT_TEST(test_80_lmon_ack_stale_drop_and_current_drift_invalidation) SemanticActivationAckTable = &table; item.message.round_nonce++; before = table; - UT_ASSERT_EQ(semantic_activation_ack_lmon_apply_item( - &item, UINT64_C(0x09), 0, 9, 0), - SEMANTIC_ACTIVATION_ACK_CONSUME_STALE); + UT_ASSERT_EQ(semantic_activation_ack_lmon_apply_item(&item, UINT64_C(0x09), 0, 9, 0), + SEMANTIC_ACTIVATION_ACK_CONSUME_STALE); UT_ASSERT_EQ(memcmp(&table, &before, sizeof(table)), 0); item = valid_current_sample_item(); - UT_ASSERT_EQ(semantic_activation_ack_lmon_apply_item( - &item, UINT64_C(0x19), 0, 9, 0), - SEMANTIC_ACTIVATION_ACK_CONSUME_INVALIDATED); + UT_ASSERT_EQ(semantic_activation_ack_lmon_apply_item(&item, UINT64_C(0x19), 0, 9, 0), + SEMANTIC_ACTIVATION_ACK_CONSUME_INVALIDATED); UT_ASSERT_EQ(pg_atomic_read_u64(&table.publication_seq), 2); UT_ASSERT_EQ(table.flags, 0); UT_ASSERT_EQ(table.expected_members_lo, 0); UT_ASSERT_EQ(table.expected_members_hi, 0); UT_ASSERT_EQ(table.observed_members_lo, 0); UT_ASSERT_EQ(table.observed_members_hi, 0); - UT_ASSERT_EQ(memcmp(table.expected, - (SemanticActivationAckTuple[CLUSTER_MAX_NODES]){{0}}, - sizeof(table.expected)), 0); - UT_ASSERT_EQ(memcmp(table.observed, - (SemanticActivationAckTuple[CLUSTER_MAX_NODES]){{0}}, - sizeof(table.observed)), 0); + UT_ASSERT_EQ(memcmp(table.expected, (SemanticActivationAckTuple[CLUSTER_MAX_NODES]){ { 0 } }, + sizeof(table.expected)), + 0); + UT_ASSERT_EQ(memcmp(table.observed, (SemanticActivationAckTuple[CLUSTER_MAX_NODES]){ { 0 } }, + sizeof(table.observed)), + 0); init_current_sample_table(&table); item = valid_current_sample_item(); @@ -2245,9 +2169,8 @@ UT_TEST(test_80_lmon_ack_stale_drop_and_current_drift_invalidation) item.message.boot_id = 0; item.message.admitted_incarnation = 0; item.message.capability_word = 0; - UT_ASSERT_EQ(semantic_activation_ack_lmon_apply_item( - &item, UINT64_C(0x09), 0, 9, 0), - SEMANTIC_ACTIVATION_ACK_CONSUME_INVALIDATED); + UT_ASSERT_EQ(semantic_activation_ack_lmon_apply_item(&item, UINT64_C(0x09), 0, 9, 0), + SEMANTIC_ACTIVATION_ACK_CONSUME_INVALIDATED); UT_ASSERT_EQ(table.flags, 0); UT_ASSERT_EQ(table.expected_members_lo, 0); UT_ASSERT_EQ(table.observed_members_lo, 0); @@ -2263,22 +2186,18 @@ UT_TEST(test_81_lmon_ack_duplicate_is_idempotent_but_conflict_invalidates) init_current_sample_table(&table); set_current_remote_ack_dependencies(); SemanticActivationAckTable = &table; - UT_ASSERT_EQ(semantic_activation_ack_lmon_apply_item( - &item, UINT64_C(0x09), 0, 9, 0), - SEMANTIC_ACTIVATION_ACK_CONSUME_APPLIED); + UT_ASSERT_EQ(semantic_activation_ack_lmon_apply_item(&item, UINT64_C(0x09), 0, 9, 0), + SEMANTIC_ACTIVATION_ACK_CONSUME_APPLIED); publication_seq = pg_atomic_read_u64(&table.publication_seq); - UT_ASSERT_EQ(semantic_activation_ack_lmon_apply_item( - &item, UINT64_C(0x09), 0, 9, 0), - SEMANTIC_ACTIVATION_ACK_CONSUME_DUPLICATE); - UT_ASSERT_EQ(pg_atomic_read_u64(&table.publication_seq), - publication_seq); + UT_ASSERT_EQ(semantic_activation_ack_lmon_apply_item(&item, UINT64_C(0x09), 0, 9, 0), + SEMANTIC_ACTIVATION_ACK_CONSUME_DUPLICATE); + UT_ASSERT_EQ(pg_atomic_read_u64(&table.publication_seq), publication_seq); item.message.boot_id = 13; item.message.admitted_incarnation = 13; cluster_r4_activation_test_membership_floor = 13; - UT_ASSERT_EQ(semantic_activation_ack_lmon_apply_item( - &item, UINT64_C(0x09), 0, 9, 0), - SEMANTIC_ACTIVATION_ACK_CONSUME_INVALIDATED); + UT_ASSERT_EQ(semantic_activation_ack_lmon_apply_item(&item, UINT64_C(0x09), 0, 9, 0), + SEMANTIC_ACTIVATION_ACK_CONSUME_INVALIDATED); UT_ASSERT_EQ(table.flags, 0); UT_ASSERT_EQ(table.expected_members_lo, 0); UT_ASSERT_EQ(table.observed_members_lo, 0); @@ -2307,18 +2226,15 @@ UT_TEST(test_82_semantic_lmon_tick_drains_ack_ingress_before_other_work) cluster_node_id = 0; SemanticActivationShmem = NULL; SemanticActivationAckTable = &table; - semantic_activation_ack_ingress_init( - &semantic_activation_ack_local_ingress); - UT_ASSERT(semantic_activation_ack_ingress_push( - &semantic_activation_ack_local_ingress, &item)); + semantic_activation_ack_ingress_init(&semantic_activation_ack_local_ingress); + UT_ASSERT(semantic_activation_ack_ingress_push(&semantic_activation_ack_local_ingress, &item)); cluster_semantic_activation_lmon_tick(); - UT_ASSERT_EQ(semantic_activation_ack_ingress_pending( - &semantic_activation_ack_local_ingress), 0); - UT_ASSERT_EQ(table.flags, - CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID - | CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE); + UT_ASSERT_EQ(semantic_activation_ack_ingress_pending(&semantic_activation_ack_local_ingress), + 0); + UT_ASSERT_EQ(table.flags, CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID + | CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE); UT_ASSERT_EQ(table.observed_members_lo, UINT64_C(0x09)); SemanticActivationAckTable = NULL; } @@ -2333,8 +2249,7 @@ UT_TEST(test_83_semantic_lmon_tick_invalidates_active_ack_on_authority_loss) cluster_node_id = 0; SemanticActivationShmem = NULL; SemanticActivationAckTable = &table; - semantic_activation_ack_ingress_init( - &semantic_activation_ack_local_ingress); + semantic_activation_ack_ingress_init(&semantic_activation_ack_local_ingress); cluster_semantic_activation_lmon_tick(); @@ -2355,8 +2270,7 @@ UT_TEST(test_84_semantic_lmon_idle_ack_path_takes_no_authority_snapshot) cluster_node_id = 0; SemanticActivationShmem = NULL; SemanticActivationAckTable = &table; - semantic_activation_ack_ingress_init( - &semantic_activation_ack_local_ingress); + semantic_activation_ack_ingress_init(&semantic_activation_ack_local_ingress); cluster_r4_activation_test_admitted_snapshot_calls = 0; cluster_semantic_activation_lmon_tick(); @@ -2367,9 +2281,8 @@ UT_TEST(test_84_semantic_lmon_idle_ack_path_takes_no_authority_snapshot) } static void -build_complete_current_sample_table( - ClusterSemanticActivationAckTableV1 *table, - SemanticActivationAckIngressItem *item) +build_complete_current_sample_table(ClusterSemanticActivationAckTableV1 *table, + SemanticActivationAckIngressItem *item) { init_current_sample_table(table); *item = valid_current_sample_item(); @@ -2382,9 +2295,8 @@ build_complete_current_sample_table( cluster_r4_activation_test_capability_word = item->message.capability_word; cluster_r4_activation_test_capability_generation = 7; SemanticActivationAckTable = table; - UT_ASSERT_EQ(semantic_activation_ack_lmon_apply_item( - item, UINT64_C(0x09), 0, 9, 0), - SEMANTIC_ACTIVATION_ACK_CONSUME_APPLIED); + UT_ASSERT_EQ(semantic_activation_ack_lmon_apply_item(item, UINT64_C(0x09), 0, 9, 0), + SEMANTIC_ACTIVATION_ACK_CONSUME_APPLIED); SemanticActivationAckTable = NULL; } @@ -2393,13 +2305,11 @@ UT_TEST(test_85_complete_ack_image_revalidates_every_current_tuple) ClusterSemanticActivationAckTableV1 table; SemanticActivationAckIngressItem item; uint32 local_capability_word - = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS - | PGRAC_IC_HELLO_CAP_GCS_DONE_V1; + = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS | PGRAC_IC_HELLO_CAP_GCS_DONE_V1; build_complete_current_sample_table(&table, &item); - UT_ASSERT(semantic_activation_ack_complete_image_current( - &table, UINT64_C(0x09), 0, 9, 0, 0, - local_capability_word)); + UT_ASSERT(semantic_activation_ack_complete_image_current(&table, UINT64_C(0x09), 0, 9, 0, 0, + local_capability_word)); } UT_TEST(test_86_complete_ack_image_rejects_self_remote_and_row_drift) @@ -2407,36 +2317,29 @@ UT_TEST(test_86_complete_ack_image_rejects_self_remote_and_row_drift) ClusterSemanticActivationAckTableV1 table; SemanticActivationAckIngressItem item; uint32 local_capability_word - = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS - | PGRAC_IC_HELLO_CAP_GCS_DONE_V1; + = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS | PGRAC_IC_HELLO_CAP_GCS_DONE_V1; build_complete_current_sample_table(&table, &item); - UT_ASSERT(!semantic_activation_ack_complete_image_current( - &table, UINT64_C(0x19), 0, 9, 0, 0, - local_capability_word)); - UT_ASSERT(!semantic_activation_ack_complete_image_current( - &table, UINT64_C(0x09), 0, 9, 1, 0, - local_capability_word)); + UT_ASSERT(!semantic_activation_ack_complete_image_current(&table, UINT64_C(0x19), 0, 9, 0, 0, + local_capability_word)); + UT_ASSERT(!semantic_activation_ack_complete_image_current(&table, UINT64_C(0x09), 0, 9, 1, 0, + local_capability_word)); cluster_r4_activation_test_self_incarnation = 12; - UT_ASSERT(!semantic_activation_ack_complete_image_current( - &table, UINT64_C(0x09), 0, 9, 0, 0, - local_capability_word)); + UT_ASSERT(!semantic_activation_ack_complete_image_current(&table, UINT64_C(0x09), 0, 9, 0, 0, + local_capability_word)); cluster_r4_activation_test_self_incarnation = 11; cluster_r4_activation_test_membership_floor = 13; - UT_ASSERT(!semantic_activation_ack_complete_image_current( - &table, UINT64_C(0x09), 0, 9, 0, 0, - local_capability_word)); + UT_ASSERT(!semantic_activation_ack_complete_image_current(&table, UINT64_C(0x09), 0, 9, 0, 0, + local_capability_word)); cluster_r4_activation_test_membership_floor = 12; cluster_r4_activation_test_capability_generation = 8; - UT_ASSERT(!semantic_activation_ack_complete_image_current( - &table, UINT64_C(0x09), 0, 9, 0, 0, - local_capability_word)); + UT_ASSERT(!semantic_activation_ack_complete_image_current(&table, UINT64_C(0x09), 0, 9, 0, 0, + local_capability_word)); cluster_r4_activation_test_capability_generation = 7; table.observed[3].capability_word ^= PGRAC_IC_HELLO_CAP_GCS_DONE_V1; - UT_ASSERT(!semantic_activation_ack_complete_image_current( - &table, UINT64_C(0x09), 0, 9, 0, 0, - local_capability_word)); + UT_ASSERT(!semantic_activation_ack_complete_image_current(&table, UINT64_C(0x09), 0, 9, 0, 0, + local_capability_word)); } static SemanticActivationAckIngressItem @@ -2454,14 +2357,12 @@ valid_current_sample_request_item(void) item.message.record_generation = 10; item.message.round_nonce = 11; item.message.source_feature_bitmap = 0; - item.message.target_feature_bitmap - = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1; + item.message.target_feature_bitmap = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1; item.message.admitted_members_lo = UINT64_C(0x09); item.authenticated_source_node_id = 0; item.local_receiver_node_id = 3; item.sampled_capability_word - = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS - | PGRAC_IC_HELLO_CAP_GCS_DONE_V1; + = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS | PGRAC_IC_HELLO_CAP_GCS_DONE_V1; item.sampled_capability_generation = 7; return item; } @@ -2478,8 +2379,7 @@ set_current_sample_request_dependencies(void) cluster_r4_activation_test_membership_state2 = CLUSTER_MEMBER_MEMBER; cluster_r4_activation_test_capability_generation_matches = true; cluster_r4_activation_test_capability_peer = 0; - cluster_r4_activation_test_capability_required - = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS; + cluster_r4_activation_test_capability_required = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS; cluster_r4_activation_test_capability_expected_generation = 7; } @@ -2487,12 +2387,10 @@ UT_TEST(test_87_authorized_request_installs_self_and_duplicate_is_inert) { ClusterSemanticActivationAckTableV1 table; ClusterSemanticActivationAckTableV1 before; - SemanticActivationAckIngressItem item - = valid_current_sample_request_item(); - SemanticActivationAckTuple expected_observed[CLUSTER_MAX_NODES] = {{0}}; + SemanticActivationAckIngressItem item = valid_current_sample_request_item(); + SemanticActivationAckTuple expected_observed[CLUSTER_MAX_NODES] = { { 0 } }; uint32 local_capability_word - = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS - | PGRAC_IC_HELLO_CAP_GCS_DONE_V1; + = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS | PGRAC_IC_HELLO_CAP_GCS_DONE_V1; memset(&table, 0, sizeof(table)); pg_atomic_init_u64(&table.publication_seq, 0); @@ -2500,11 +2398,10 @@ UT_TEST(test_87_authorized_request_installs_self_and_duplicate_is_inert) SemanticActivationAckTable = &table; UT_ASSERT_EQ(semantic_activation_ack_lmon_install_authorized_request( - &item, UINT64_C(0x09), 0, 9, 0, local_capability_word), - SEMANTIC_ACTIVATION_ACK_CONSUME_APPLIED); + &item, UINT64_C(0x09), 0, 9, 0, local_capability_word), + SEMANTIC_ACTIVATION_ACK_CONSUME_APPLIED); UT_ASSERT_EQ(pg_atomic_read_u64(&table.publication_seq), 2); - UT_ASSERT_EQ(table.stage, - CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_SAMPLE); + UT_ASSERT_EQ(table.stage, CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_SAMPLE); UT_ASSERT_EQ(table.flags, 0); UT_ASSERT_EQ(table.coordinator_node, 0); UT_ASSERT_EQ(table.reserved, 0); @@ -2516,13 +2413,12 @@ UT_TEST(test_87_authorized_request_installs_self_and_duplicate_is_inert) UT_ASSERT_EQ(table.transition_epoch, UINT64_C(9)); UT_ASSERT_EQ(table.record_generation, UINT64_C(10)); UT_ASSERT_EQ(table.source_feature_bitmap, UINT64_C(0)); - UT_ASSERT_EQ(table.target_feature_bitmap, - CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1); + UT_ASSERT_EQ(table.target_feature_bitmap, CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1); UT_ASSERT_EQ(table.rollback_feature_bitmap, 0); UT_ASSERT_EQ(table.capability_sample_digest, 0); - UT_ASSERT_EQ(memcmp(table.expected, - (SemanticActivationAckTuple[CLUSTER_MAX_NODES]){{0}}, - sizeof(table.expected)), 0); + UT_ASSERT_EQ(memcmp(table.expected, (SemanticActivationAckTuple[CLUSTER_MAX_NODES]){ { 0 } }, + sizeof(table.expected)), + 0); expected_observed[3] = (SemanticActivationAckTuple){ .node_id = 3, .boot_id = 12, @@ -2533,30 +2429,27 @@ UT_TEST(test_87_authorized_request_installs_self_and_duplicate_is_inert) .transition_epoch = 9, .record_generation = 10, }; - UT_ASSERT_EQ(memcmp(table.observed, expected_observed, - sizeof(table.observed)), 0); + UT_ASSERT_EQ(memcmp(table.observed, expected_observed, sizeof(table.observed)), 0); before = table; UT_ASSERT_EQ(semantic_activation_ack_lmon_install_authorized_request( - &item, UINT64_C(0x09), 0, 9, 0, local_capability_word), - SEMANTIC_ACTIVATION_ACK_CONSUME_DUPLICATE); + &item, UINT64_C(0x09), 0, 9, 0, local_capability_word), + SEMANTIC_ACTIVATION_ACK_CONSUME_DUPLICATE); UT_ASSERT_EQ(memcmp(&table, &before, sizeof(table)), 0); SemanticActivationAckTable = NULL; } static void -assert_authorized_request_rejected_without_mutation( - const SemanticActivationAckIngressItem *item, - ClusterSemanticActivationAckTableV1 *table) +assert_authorized_request_rejected_without_mutation(const SemanticActivationAckIngressItem *item, + ClusterSemanticActivationAckTableV1 *table) { ClusterSemanticActivationAckTableV1 before = *table; uint32 local_capability_word - = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS - | PGRAC_IC_HELLO_CAP_GCS_DONE_V1; + = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS | PGRAC_IC_HELLO_CAP_GCS_DONE_V1; - UT_ASSERT_EQ(semantic_activation_ack_lmon_install_authorized_request( - item, UINT64_C(0x09), 0, 9, 0, local_capability_word), - SEMANTIC_ACTIVATION_ACK_CONSUME_REJECTED); + UT_ASSERT_EQ(semantic_activation_ack_lmon_install_authorized_request(item, UINT64_C(0x09), 0, 9, + 0, local_capability_word), + SEMANTIC_ACTIVATION_ACK_CONSUME_REJECTED); UT_ASSERT_EQ(memcmp(table, &before, sizeof(*table)), 0); } @@ -2616,25 +2509,20 @@ valid_source_open_snapshot(void) static SemanticActivationAckIngressItem valid_current_durable_sample_request_item(void) { - SemanticActivationAckIngressItem item - = valid_current_sample_request_item(); + SemanticActivationAckIngressItem item = valid_current_sample_request_item(); item.message.source_feature_bitmap = 0; - item.message.target_feature_bitmap - = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1; + item.message.target_feature_bitmap = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1; return item; } UT_TEST(test_89_current_sample_request_accepts_exact_durable_source_open) { ClusterSemanticActivationAckTableV1 table; - SemanticActivationAckIngressItem item - = valid_current_durable_sample_request_item(); - SemanticActivationAdmissionSnapshot snapshot - = valid_source_open_snapshot(); + SemanticActivationAckIngressItem item = valid_current_durable_sample_request_item(); + SemanticActivationAdmissionSnapshot snapshot = valid_source_open_snapshot(); uint32 local_capability_word - = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS - | PGRAC_IC_HELLO_CAP_GCS_DONE_V1; + = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS | PGRAC_IC_HELLO_CAP_GCS_DONE_V1; memset(&table, 0, sizeof(table)); pg_atomic_init_u64(&table.publication_seq, 0); @@ -2642,9 +2530,8 @@ UT_TEST(test_89_current_sample_request_accepts_exact_durable_source_open) SemanticActivationAckTable = &table; UT_ASSERT_EQ(semantic_activation_ack_lmon_accept_current_sample_request( - &item, &snapshot, UINT64_C(0x09), 0, 9, 0, - local_capability_word), - SEMANTIC_ACTIVATION_ACK_CONSUME_APPLIED); + &item, &snapshot, UINT64_C(0x09), 0, 9, 0, local_capability_word), + SEMANTIC_ACTIVATION_ACK_CONSUME_APPLIED); UT_ASSERT_EQ(pg_atomic_read_u64(&table.publication_seq), 2); UT_ASSERT_EQ(table.record_generation, UINT64_C(10)); UT_ASSERT_EQ(table.observed_members_lo, UINT64_C(0x08)); @@ -2653,20 +2540,17 @@ UT_TEST(test_89_current_sample_request_accepts_exact_durable_source_open) } static void -assert_current_sample_request_not_authorized( - const SemanticActivationAckIngressItem *item, - const SemanticActivationAdmissionSnapshot *snapshot, - ClusterSemanticActivationAckTableV1 *table) +assert_current_sample_request_not_authorized(const SemanticActivationAckIngressItem *item, + const SemanticActivationAdmissionSnapshot *snapshot, + ClusterSemanticActivationAckTableV1 *table) { ClusterSemanticActivationAckTableV1 before = *table; uint32 local_capability_word - = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS - | PGRAC_IC_HELLO_CAP_GCS_DONE_V1; + = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS | PGRAC_IC_HELLO_CAP_GCS_DONE_V1; UT_ASSERT_EQ(semantic_activation_ack_lmon_accept_current_sample_request( - item, snapshot, UINT64_C(0x09), 0, 9, 0, - local_capability_word), - SEMANTIC_ACTIVATION_ACK_CONSUME_REJECTED); + item, snapshot, UINT64_C(0x09), 0, 9, 0, local_capability_word), + SEMANTIC_ACTIVATION_ACK_CONSUME_REJECTED); UT_ASSERT_EQ(memcmp(table, &before, sizeof(*table)), 0); } @@ -2696,8 +2580,7 @@ UT_TEST(test_90_current_sample_request_rejects_durable_stage_drift) assert_current_sample_request_not_authorized(&item, &snapshot, &table); snapshot = valid_source_open_snapshot(); snapshot.active_bits = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1; - item.message.source_feature_bitmap - = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1; + item.message.source_feature_bitmap = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1; assert_current_sample_request_not_authorized(&item, &snapshot, &table); item = valid_current_durable_sample_request_item(); snapshot = valid_source_open_snapshot(); @@ -2712,8 +2595,7 @@ UT_TEST(test_90_current_sample_request_rejects_durable_stage_drift) static SemanticActivationAckPendingSend valid_pending_send(uint64 pending_members_lo, uint64 pending_members_hi) { - SemanticActivationAckIngressItem item - = valid_current_durable_sample_request_item(); + SemanticActivationAckIngressItem item = valid_current_durable_sample_request_item(); SemanticActivationAckPendingSend pending; memset(&pending, 0, sizeof(pending)); @@ -2725,18 +2607,17 @@ valid_pending_send(uint64 pending_members_lo, uint64 pending_members_hi) UT_TEST(test_91_pending_send_clears_done_and_admitted_would_block) { - SemanticActivationAckPendingSend pending - = valid_pending_send(UINT64_C(0x0c), 0); + SemanticActivationAckPendingSend pending = valid_pending_send(UINT64_C(0x0c), 0); - UT_ASSERT_EQ(semantic_activation_ack_pending_send_note_result( - &pending, 2, CLUSTER_IC_SEND_DONE), + UT_ASSERT_EQ( + semantic_activation_ack_pending_send_note_result(&pending, 2, CLUSTER_IC_SEND_DONE), SEMANTIC_ACTIVATION_ACK_SEND_ADMITTED); UT_ASSERT_EQ(pending.pending_members_lo, UINT64_C(0x08)); UT_ASSERT_EQ(pending.pending_members_hi, 0); UT_ASSERT(!pending.invalidated); - UT_ASSERT_EQ(semantic_activation_ack_pending_send_note_result( - &pending, 3, CLUSTER_IC_SEND_WOULD_BLOCK), + UT_ASSERT_EQ( + semantic_activation_ack_pending_send_note_result(&pending, 3, CLUSTER_IC_SEND_WOULD_BLOCK), SEMANTIC_ACTIVATION_ACK_SEND_ADMITTED); UT_ASSERT_EQ(pending.pending_members_lo, 0); UT_ASSERT_EQ(pending.pending_members_hi, 0); @@ -2745,25 +2626,24 @@ UT_TEST(test_91_pending_send_clears_done_and_admitted_would_block) UT_TEST(test_92_pending_send_retains_refusal_and_aborts_hard_error) { - SemanticActivationAckPendingSend pending - = valid_pending_send(UINT64_C(0x04), UINT64_C(0x40)); + SemanticActivationAckPendingSend pending = valid_pending_send(UINT64_C(0x04), UINT64_C(0x40)); SemanticActivationAckPendingSend before = pending; - UT_ASSERT_EQ(semantic_activation_ack_pending_send_note_result( - &pending, 2, CLUSTER_IC_SEND_NOT_ADMITTED), + UT_ASSERT_EQ( + semantic_activation_ack_pending_send_note_result(&pending, 2, CLUSTER_IC_SEND_NOT_ADMITTED), SEMANTIC_ACTIVATION_ACK_SEND_RETAINED); UT_ASSERT_EQ(memcmp(&pending, &before, sizeof(pending)), 0); - UT_ASSERT_EQ(semantic_activation_ack_pending_send_note_result( - &pending, 70, CLUSTER_IC_SEND_HARD_ERROR), + UT_ASSERT_EQ( + semantic_activation_ack_pending_send_note_result(&pending, 70, CLUSTER_IC_SEND_HARD_ERROR), SEMANTIC_ACTIVATION_ACK_SEND_INVALIDATED); UT_ASSERT_EQ(pending.pending_members_lo, 0); UT_ASSERT_EQ(pending.pending_members_hi, 0); UT_ASSERT(pending.invalidated); before = pending; - UT_ASSERT_EQ(semantic_activation_ack_pending_send_note_result( - &pending, 2, CLUSTER_IC_SEND_DONE), + UT_ASSERT_EQ( + semantic_activation_ack_pending_send_note_result(&pending, 2, CLUSTER_IC_SEND_DONE), SEMANTIC_ACTIVATION_ACK_SEND_REJECTED); UT_ASSERT_EQ(memcmp(&pending, &before, sizeof(pending)), 0); } @@ -2772,13 +2652,11 @@ UT_TEST(test_93_four_node_sample_request_installs_self_and_sends_positive_ack) { ClusterSemanticActivationShmem shmem; ClusterSemanticActivationAckTableV1 table; - SemanticActivationAckIngressItem item - = valid_current_durable_sample_request_item(); + SemanticActivationAckIngressItem item = valid_current_durable_sample_request_item(); ClusterSemanticActivationAckWireV1 expected; ClusterSemanticActivationAckWireV1 sent; uint32 local_capability_word - = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS - | PGRAC_IC_HELLO_CAP_GCS_DONE_V1; + = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS | PGRAC_IC_HELLO_CAP_GCS_DONE_V1; int node; memset(&shmem, 0, sizeof(shmem)); @@ -2802,38 +2680,34 @@ UT_TEST(test_93_four_node_sample_request_installs_self_and_sends_positive_ack) cluster_r4_activation_test_capability_generation = 7; cluster_r4_activation_test_local_capability_word = local_capability_word; memset(cluster_r4_activation_test_capability_sample_calls, 0, - sizeof(cluster_r4_activation_test_capability_sample_calls)); + sizeof(cluster_r4_activation_test_capability_sample_calls)); memset(cluster_r4_activation_test_send_results, 0, - sizeof(cluster_r4_activation_test_send_results)); - memset(cluster_r4_activation_test_send_calls, 0, - sizeof(cluster_r4_activation_test_send_calls)); + sizeof(cluster_r4_activation_test_send_results)); + memset(cluster_r4_activation_test_send_calls, 0, sizeof(cluster_r4_activation_test_send_calls)); memset(cluster_r4_activation_test_send_payloads, 0, - sizeof(cluster_r4_activation_test_send_payloads)); + sizeof(cluster_r4_activation_test_send_payloads)); memset(cluster_r4_activation_test_send_payload_lengths, 0, - sizeof(cluster_r4_activation_test_send_payload_lengths)); + sizeof(cluster_r4_activation_test_send_payload_lengths)); memset(cluster_r4_activation_test_send_msg_types, 0, - sizeof(cluster_r4_activation_test_send_msg_types)); + sizeof(cluster_r4_activation_test_send_msg_types)); memset(cluster_r4_activation_test_close_calls, 0, - sizeof(cluster_r4_activation_test_close_calls)); + sizeof(cluster_r4_activation_test_close_calls)); memset(&semantic_activation_ack_local_pending_send, 0, - sizeof(semantic_activation_ack_local_pending_send)); + sizeof(semantic_activation_ack_local_pending_send)); cluster_node_id = 3; SemanticActivationShmem = &shmem; SemanticActivationAckTable = &table; - semantic_activation_ack_ingress_init( - &semantic_activation_ack_local_ingress); - UT_ASSERT(semantic_activation_ack_ingress_push( - &semantic_activation_ack_local_ingress, &item)); + semantic_activation_ack_ingress_init(&semantic_activation_ack_local_ingress); + UT_ASSERT(semantic_activation_ack_ingress_push(&semantic_activation_ack_local_ingress, &item)); cluster_semantic_activation_lmon_tick(); - UT_ASSERT_EQ(semantic_activation_ack_ingress_pending( - &semantic_activation_ack_local_ingress), 0); + UT_ASSERT_EQ(semantic_activation_ack_ingress_pending(&semantic_activation_ack_local_ingress), + 0); UT_ASSERT_EQ(table.expected_members_lo, UINT64_C(0x0f)); UT_ASSERT_EQ(table.observed_members_lo, UINT64_C(0x08)); UT_ASSERT_EQ(table.observed[3].boot_id, UINT64_C(12)); - UT_ASSERT_EQ(table.observed[3].capability_word, - local_capability_word); + UT_ASSERT_EQ(table.observed[3].capability_word, local_capability_word); expected = item.message; expected.kind = CLUSTER_SEMANTIC_ACTIVATION_ACK_KIND_ACK; expected.result = CLUSTER_SEMANTIC_ACTIVATION_ACK_RESULT_OK; @@ -2845,9 +2719,9 @@ UT_TEST(test_93_four_node_sample_request_installs_self_and_sends_positive_ack) UT_ASSERT_EQ(cluster_r4_activation_test_capability_sample_calls[node], 1); UT_ASSERT_EQ(cluster_r4_activation_test_send_calls[node], 1); UT_ASSERT_EQ(cluster_r4_activation_test_send_msg_types[node], - PGRAC_IC_MSG_SEMANTIC_ACTIVATION_ACK_V1); + PGRAC_IC_MSG_SEMANTIC_ACTIVATION_ACK_V1); UT_ASSERT_EQ(cluster_r4_activation_test_send_payload_lengths[node], - CLUSTER_SEMANTIC_ACTIVATION_ACK_WIRE_BYTES); + CLUSTER_SEMANTIC_ACTIVATION_ACK_WIRE_BYTES); UT_ASSERT(cluster_semantic_activation_ack_wire_decode( cluster_r4_activation_test_send_payloads[node], &sent)); UT_ASSERT_EQ(memcmp(&sent, &expected, sizeof(sent)), 0); @@ -2863,8 +2737,7 @@ UT_TEST(test_93_four_node_sample_request_installs_self_and_sends_positive_ack) } static void -init_four_member_digest_table(ClusterSemanticActivationAckTableV1 *table, - bool reverse_fill) +init_four_member_digest_table(ClusterSemanticActivationAckTableV1 *table, bool reverse_fill) { int index; @@ -2880,8 +2753,7 @@ init_four_member_digest_table(ClusterSemanticActivationAckTableV1 *table, table->transition_epoch = UINT64_C(0x0102030405060708); table->record_generation = UINT64_C(0x1112131415161718); table->source_feature_bitmap = UINT64_C(0); - table->target_feature_bitmap - = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1; + table->target_feature_bitmap = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1; for (index = 0; index < 4; index++) { SemanticActivationAckTuple tuple; int node = reverse_fill ? 3 - index : index; @@ -2890,13 +2762,9 @@ init_four_member_digest_table(ClusterSemanticActivationAckTableV1 *table, tuple.node_id = (uint32)node; tuple.boot_id = UINT64_C(0x100) + (uint64)node; tuple.admitted_incarnation = tuple.boot_id; - tuple.control_connection_generation - = UINT64_C(0x200) + (uint64)node; - tuple.capability_word - = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS - | (uint32)node; - tuple.capability_generation - = UINT64_C(0x300) + (uint64)node; + tuple.control_connection_generation = UINT64_C(0x200) + (uint64)node; + tuple.capability_word = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS | (uint32)node; + tuple.capability_generation = UINT64_C(0x300) + (uint64)node; tuple.transition_epoch = table->transition_epoch; tuple.record_generation = table->record_generation; table->expected[node] = tuple; @@ -2914,23 +2782,19 @@ UT_TEST(test_94_four_member_sample_digest_is_canonical) init_four_member_digest_table(&forward, false); init_four_member_digest_table(&reverse, true); - UT_ASSERT(semantic_activation_ack_sample_digest( - &forward, &forward_digest)); + UT_ASSERT(semantic_activation_ack_sample_digest(&forward, &forward_digest)); UT_ASSERT_EQ(forward_digest, UINT64_C(0x00db946c7c55c2f1)); - UT_ASSERT(semantic_activation_ack_sample_digest( - &reverse, &reverse_digest)); + UT_ASSERT(semantic_activation_ack_sample_digest(&reverse, &reverse_digest)); UT_ASSERT_EQ(reverse_digest, forward_digest); reverse.expected[2].capability_generation ^= UINT64_C(1); reverse.observed[2] = reverse.expected[2]; - UT_ASSERT(semantic_activation_ack_sample_digest( - &reverse, &changed_digest)); + UT_ASSERT(semantic_activation_ack_sample_digest(&reverse, &changed_digest)); UT_ASSERT(changed_digest != forward_digest); forward.flags &= ~CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE; forward_digest = UINT64_MAX; - UT_ASSERT(!semantic_activation_ack_sample_digest( - &forward, &forward_digest)); + UT_ASSERT(!semantic_activation_ack_sample_digest(&forward, &forward_digest)); UT_ASSERT_EQ(forward_digest, UINT64_C(0)); } @@ -2942,8 +2806,7 @@ UT_TEST(test_95_four_node_barrier_request_retains_expected_without_ack) SemanticActivationAckIngressItem item; uint64 digest = 0; uint32 local_capability_word - = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS - | PGRAC_IC_HELLO_CAP_GCS_DONE_V1; + = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS | PGRAC_IC_HELLO_CAP_GCS_DONE_V1; int node; init_four_member_digest_table(&table, false); @@ -2958,11 +2821,9 @@ UT_TEST(test_95_four_node_barrier_request_retains_expected_without_ack) if (node == 3) { UT_ASSERT(semantic_activation_ack_self_tuple( - 3, local_capability_word, table.transition_epoch, - table.record_generation, &tuple)); + 3, local_capability_word, table.transition_epoch, table.record_generation, &tuple)); } else { - admitted_incarnation - = cluster_membership_get_last_admitted_incarnation(node); + admitted_incarnation = cluster_membership_get_last_admitted_incarnation(node); tuple = (SemanticActivationAckTuple){ .node_id = (uint32)node, .boot_id = admitted_incarnation, @@ -2996,15 +2857,13 @@ UT_TEST(test_95_four_node_barrier_request_retains_expected_without_ack) item.message.capability_sample_digest = digest; item.authenticated_source_node_id = 0; item.local_receiver_node_id = 3; - item.sampled_capability_word - = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS; + item.sampled_capability_word = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS; item.sampled_capability_generation = 7; memset(&shmem, 0, sizeof(shmem)); pg_atomic_init_u64(&shmem.admission_seq, 6); pg_atomic_init_u64(&shmem.active_bits, 0); - pg_atomic_init_u64(&shmem.record_generation, - table.record_generation - 1); + pg_atomic_init_u64(&shmem.record_generation, table.record_generation - 1); pg_atomic_init_u64(&shmem.formation_epoch, table.transition_epoch); pg_atomic_init_u32(&shmem.transition_closed, 0); cluster_r4_activation_test_admitted_snapshot_valid = true; @@ -3012,37 +2871,31 @@ UT_TEST(test_95_four_node_barrier_request_retains_expected_without_ack) cluster_r4_activation_test_admitted_members_hi = 0; cluster_r4_activation_test_admitted_epoch = table.transition_epoch; cluster_r4_activation_test_current_epoch = table.transition_epoch; - memset(cluster_r4_activation_test_send_calls, 0, - sizeof(cluster_r4_activation_test_send_calls)); + memset(cluster_r4_activation_test_send_calls, 0, sizeof(cluster_r4_activation_test_send_calls)); memset(&semantic_activation_ack_local_pending_send, 0, - sizeof(semantic_activation_ack_local_pending_send)); + sizeof(semantic_activation_ack_local_pending_send)); cluster_node_id = 3; SemanticActivationShmem = &shmem; SemanticActivationAckTable = &table; - semantic_activation_ack_ingress_init( - &semantic_activation_ack_local_ingress); - UT_ASSERT(semantic_activation_ack_ingress_push( - &semantic_activation_ack_local_ingress, &item)); + semantic_activation_ack_ingress_init(&semantic_activation_ack_local_ingress); + UT_ASSERT(semantic_activation_ack_ingress_push(&semantic_activation_ack_local_ingress, &item)); cluster_semantic_activation_lmon_tick(); - UT_ASSERT_EQ(semantic_activation_ack_ingress_pending( - &semantic_activation_ack_local_ingress), 0); - UT_ASSERT_EQ(table.stage, - CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_BARRIER); - UT_ASSERT_EQ(table.flags, - CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID); + UT_ASSERT_EQ(semantic_activation_ack_ingress_pending(&semantic_activation_ack_local_ingress), + 0); + UT_ASSERT_EQ(table.stage, CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_BARRIER); + UT_ASSERT_EQ(table.flags, CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID); UT_ASSERT_EQ(table.capability_sample_digest, digest); UT_ASSERT_EQ(table.observed_members_lo, UINT64_C(0)); UT_ASSERT_EQ(table.observed_members_hi, UINT64_C(0)); UT_ASSERT_EQ(memcmp(table.expected, expected, sizeof(expected)), 0); - UT_ASSERT_EQ(memcmp(table.observed, - (SemanticActivationAckTuple[CLUSTER_MAX_NODES]){{0}}, - sizeof(table.observed)), 0); + UT_ASSERT_EQ(memcmp(table.observed, (SemanticActivationAckTuple[CLUSTER_MAX_NODES]){ { 0 } }, + sizeof(table.observed)), + 0); for (node = 0; node < 4; node++) UT_ASSERT_EQ(cluster_r4_activation_test_send_calls[node], 0); - UT_ASSERT_EQ(pg_atomic_read_u64(&shmem.record_generation), - table.record_generation - 1); + UT_ASSERT_EQ(pg_atomic_read_u64(&shmem.record_generation), table.record_generation - 1); UT_ASSERT_EQ(pg_atomic_read_u32(&shmem.transition_closed), 0); SemanticActivationAckTable = NULL; SemanticActivationShmem = NULL; @@ -3063,17 +2916,15 @@ stage_ahead_prepared_fixture_init(StageAheadPreparedFixture *fixture) ClusterSemanticActivationAckTableV1 *table = &fixture->table; SemanticActivationAckIngressItem *early = &fixture->early; SemanticActivationAckIngressItem *request = &fixture->request; - uint32 required_caps - = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS - | PGRAC_IC_HELLO_CAP_SEMANTIC_ACTIVATION_V1 - | PGRAC_IC_HELLO_CAP_GCS_RESOURCE_X_CONVERT_V1; + uint32 required_caps = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS + | PGRAC_IC_HELLO_CAP_SEMANTIC_ACTIVATION_V1 + | PGRAC_IC_HELLO_CAP_GCS_RESOURCE_X_CONVERT_V1; int node; memset(fixture, 0, sizeof(*fixture)); fixture->required_caps = required_caps; pg_atomic_init_u64(&shmem->admission_seq, 6); - pg_atomic_init_u64(&shmem->active_bits, - CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1); + pg_atomic_init_u64(&shmem->active_bits, CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1); pg_atomic_init_u64(&shmem->record_generation, 10); pg_atomic_init_u64(&shmem->formation_epoch, 9); pg_atomic_init_u32(&shmem->transition_closed, 1); @@ -3081,18 +2932,16 @@ stage_ahead_prepared_fixture_init(StageAheadPreparedFixture *fixture) pg_atomic_init_u64(&table->publication_seq, 0); table->stage = CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_BARRIER; table->flags = CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID - | CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE; + | CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE; table->coordinator_node = 0; table->round_nonce = UINT64_C(0x55); table->expected_members_lo = UINT64_C(0x0f); table->observed_members_lo = UINT64_C(0x0f); table->transition_epoch = 9; table->record_generation = 10; - table->source_feature_bitmap - = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1; - table->target_feature_bitmap - = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1 - | CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1; + table->source_feature_bitmap = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1; + table->target_feature_bitmap = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1 + | CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1; table->capability_sample_digest = UINT64_C(0x778899); for (node = 0; node < 4; node++) { SemanticActivationAckTuple tuple; @@ -3122,8 +2971,7 @@ stage_ahead_prepared_fixture_init(StageAheadPreparedFixture *fixture) early->message.source_feature_bitmap = table->source_feature_bitmap; early->message.target_feature_bitmap = table->target_feature_bitmap; early->message.admitted_members_lo = table->expected_members_lo; - early->message.capability_sample_digest - = table->capability_sample_digest; + early->message.capability_sample_digest = table->capability_sample_digest; early->message.boot_id = 1; early->message.admitted_incarnation = 1; early->message.capability_word = required_caps; @@ -3160,15 +3008,14 @@ stage_ahead_prepared_fixture_init(StageAheadPreparedFixture *fixture) cluster_r4_activation_test_capability_required = required_caps; cluster_r4_activation_test_capability_expected_generation = 7; memset(&semantic_activation_ack_local_pending_send, 0, - sizeof(semantic_activation_ack_local_pending_send)); + sizeof(semantic_activation_ack_local_pending_send)); memset(&semantic_activation_ack_local_request_origin, 0, - sizeof(semantic_activation_ack_local_request_origin)); + sizeof(semantic_activation_ack_local_request_origin)); memset(&semantic_activation_ack_local_stage_ahead, 0, - sizeof(semantic_activation_ack_local_stage_ahead)); + sizeof(semantic_activation_ack_local_stage_ahead)); memset(&semantic_activation_ack_local_request_ahead, 0, - sizeof(semantic_activation_ack_local_request_ahead)); - semantic_activation_ack_ingress_init( - &semantic_activation_ack_local_ingress); + sizeof(semantic_activation_ack_local_request_ahead)); + semantic_activation_ack_ingress_init(&semantic_activation_ack_local_ingress); SemanticActivationShmem = shmem; SemanticActivationAckTable = table; } @@ -3180,7 +3027,7 @@ stage_ahead_prepared_fixture_cleanup(void) SemanticActivationShmem = NULL; cluster_r4_activation_test_capability_peer_mask = 0; memset(&semantic_activation_ack_local_stage_ahead, 0, - sizeof(semantic_activation_ack_local_stage_ahead)); + sizeof(semantic_activation_ack_local_stage_ahead)); } UT_TEST(test_96_stage_ahead_ack_is_applied_once_after_matching_request) @@ -3189,23 +3036,22 @@ UT_TEST(test_96_stage_ahead_ack_is_applied_once_after_matching_request) stage_ahead_prepared_fixture_init(&fixture); - UT_ASSERT(semantic_activation_ack_ingress_push( - &semantic_activation_ack_local_ingress, &fixture.early)); - UT_ASSERT(semantic_activation_ack_ingress_push( - &semantic_activation_ack_local_ingress, &fixture.early)); + UT_ASSERT(semantic_activation_ack_ingress_push(&semantic_activation_ack_local_ingress, + &fixture.early)); + UT_ASSERT(semantic_activation_ack_ingress_push(&semantic_activation_ack_local_ingress, + &fixture.early)); semantic_activation_ack_lmon_drain(); - UT_ASSERT_EQ(fixture.table.stage, - CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_BARRIER); + UT_ASSERT_EQ(fixture.table.stage, CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_BARRIER); UT_ASSERT_EQ(fixture.table.observed_members_lo, UINT64_C(0x0f)); - UT_ASSERT(semantic_activation_ack_ingress_push( - &semantic_activation_ack_local_ingress, &fixture.request)); + UT_ASSERT(semantic_activation_ack_ingress_push(&semantic_activation_ack_local_ingress, + &fixture.request)); semantic_activation_ack_lmon_drain(); - UT_ASSERT_EQ(fixture.table.stage, - CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_PREPARED); + UT_ASSERT_EQ(fixture.table.stage, CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_PREPARED); UT_ASSERT_EQ(fixture.table.observed_members_lo, UINT64_C(0x01)); - UT_ASSERT_EQ(memcmp(&fixture.table.observed[0], - &fixture.table.expected[0], sizeof(fixture.table.observed[0])), 0); + UT_ASSERT_EQ(memcmp(&fixture.table.observed[0], &fixture.table.expected[0], + sizeof(fixture.table.observed[0])), + 0); stage_ahead_prepared_fixture_cleanup(); } @@ -3218,16 +3064,16 @@ UT_TEST(test_97_stage_ahead_identity_conflict_invalidates_round) stage_ahead_prepared_fixture_init(&fixture); conflict = fixture.early; conflict.message.round_nonce++; - UT_ASSERT(semantic_activation_ack_ingress_push( - &semantic_activation_ack_local_ingress, &fixture.early)); - UT_ASSERT(semantic_activation_ack_ingress_push( - &semantic_activation_ack_local_ingress, &conflict)); + UT_ASSERT(semantic_activation_ack_ingress_push(&semantic_activation_ack_local_ingress, + &fixture.early)); + UT_ASSERT( + semantic_activation_ack_ingress_push(&semantic_activation_ack_local_ingress, &conflict)); semantic_activation_ack_lmon_drain(); UT_ASSERT_EQ(fixture.table.flags, UINT32_C(0)); UT_ASSERT_EQ(fixture.table.expected_members_lo, UINT64_C(0)); - UT_ASSERT(semantic_activation_ack_ingress_push( - &semantic_activation_ack_local_ingress, &fixture.request)); + UT_ASSERT(semantic_activation_ack_ingress_push(&semantic_activation_ack_local_ingress, + &fixture.request)); semantic_activation_ack_lmon_drain(); UT_ASSERT_EQ(fixture.table.expected_members_lo, UINT64_C(0)); @@ -3244,22 +3090,21 @@ UT_TEST(test_98_stage_ahead_refusal_invalidates_round) refusal.authenticated_source_node_id = 1; refusal.local_receiver_node_id = 0; refusal.message.member_node = 1; - refusal.message.result - = CLUSTER_SEMANTIC_ACTIVATION_ACK_RESULT_REFUSED; + refusal.message.result = CLUSTER_SEMANTIC_ACTIVATION_ACK_RESULT_REFUSED; refusal.message.reason = CLUSTER_SEMANTIC_ACTIVATION_BAD_STATE; refusal.message.boot_id = 0; refusal.message.admitted_incarnation = 0; refusal.message.capability_word = 0; - UT_ASSERT(semantic_activation_ack_ingress_push( - &semantic_activation_ack_local_ingress, &fixture.early)); - UT_ASSERT(semantic_activation_ack_ingress_push( - &semantic_activation_ack_local_ingress, &refusal)); + UT_ASSERT(semantic_activation_ack_ingress_push(&semantic_activation_ack_local_ingress, + &fixture.early)); + UT_ASSERT( + semantic_activation_ack_ingress_push(&semantic_activation_ack_local_ingress, &refusal)); semantic_activation_ack_lmon_drain(); UT_ASSERT_EQ(fixture.table.flags, UINT32_C(0)); UT_ASSERT_EQ(fixture.table.expected_members_lo, UINT64_C(0)); - UT_ASSERT(semantic_activation_ack_ingress_push( - &semantic_activation_ack_local_ingress, &fixture.request)); + UT_ASSERT(semantic_activation_ack_ingress_push(&semantic_activation_ack_local_ingress, + &fixture.request)); semantic_activation_ack_lmon_drain(); UT_ASSERT_EQ(fixture.table.expected_members_lo, UINT64_C(0)); @@ -3276,42 +3121,36 @@ typedef struct StageAheadBarrierRequestFixture { } StageAheadBarrierRequestFixture; static void -stage_ahead_barrier_request_fixture_init( - StageAheadBarrierRequestFixture *fixture) +stage_ahead_barrier_request_fixture_init(StageAheadBarrierRequestFixture *fixture) { ClusterSemanticActivationAckTableV1 *table = &fixture->table; SemanticActivationAckIngressItem *request = &fixture->request; - SemanticActivationAckIngressItem *final_ack - = &fixture->final_sample_ack; - uint32 required_caps - = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS - | PGRAC_IC_HELLO_CAP_SEMANTIC_ACTIVATION_V1 - | PGRAC_IC_HELLO_CAP_GCS_RESOURCE_X_CONVERT_V1; + SemanticActivationAckIngressItem *final_ack = &fixture->final_sample_ack; + uint32 required_caps = CLUSTER_SEMANTIC_ACTIVATION_ACK_REQUIRED_CAPS + | PGRAC_IC_HELLO_CAP_SEMANTIC_ACTIVATION_V1 + | PGRAC_IC_HELLO_CAP_GCS_RESOURCE_X_CONVERT_V1; int node; memset(fixture, 0, sizeof(*fixture)); fixture->required_caps = required_caps; pg_atomic_init_u64(&table->publication_seq, 0); table->stage = CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_SAMPLE; - table->flags - = CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID - | CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE; + table->flags = CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID + | CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_COMPLETE; table->coordinator_node = 0; table->round_nonce = UINT64_C(0x6655); table->expected_members_lo = UINT64_C(0x0f); table->observed_members_lo = UINT64_C(0x0f); table->transition_epoch = UINT64_C(9); table->record_generation = UINT64_C(10); - table->source_feature_bitmap - = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1; - table->target_feature_bitmap - = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1 - | CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1; + table->source_feature_bitmap = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1; + table->target_feature_bitmap = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1 + | CLUSTER_SEMANTIC_FEATURE_R11_RESOURCE_X_D5_CUTOVER_V1; for (node = 0; node < 4; node++) { SemanticActivationAckTuple tuple; memset(&tuple, 0, sizeof(tuple)); - tuple.node_id = (uint32) node; + tuple.node_id = (uint32)node; tuple.boot_id = 1; tuple.admitted_incarnation = 1; tuple.control_connection_generation = node == 2 ? 1 : 7; @@ -3322,8 +3161,7 @@ stage_ahead_barrier_request_fixture_init( table->expected[node] = tuple; table->observed[node] = tuple; } - UT_ASSERT(semantic_activation_ack_sample_digest( - table, &fixture->digest)); + UT_ASSERT(semantic_activation_ack_sample_digest(table, &fixture->digest)); /* Recreate the exact receiver state from the four-node failure: the * current SAMPLE round lacks only node 3 and therefore has no frozen @@ -3334,23 +3172,17 @@ stage_ahead_barrier_request_fixture_init( memset(table->expected, 0, sizeof(table->expected)); memset(&table->observed[3], 0, sizeof(table->observed[3])); - request->message.kind - = CLUSTER_SEMANTIC_ACTIVATION_ACK_KIND_REQUEST; - request->message.stage - = CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_BARRIER; - request->message.result - = CLUSTER_SEMANTIC_ACTIVATION_ACK_RESULT_REQUEST; + request->message.kind = CLUSTER_SEMANTIC_ACTIVATION_ACK_KIND_REQUEST; + request->message.stage = CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_BARRIER; + request->message.result = CLUSTER_SEMANTIC_ACTIVATION_ACK_RESULT_REQUEST; request->message.coordinator_node = 0; request->message.member_node = 2; request->message.transition_epoch = table->transition_epoch; request->message.record_generation = table->record_generation; request->message.round_nonce = table->round_nonce; - request->message.source_feature_bitmap - = table->source_feature_bitmap; - request->message.target_feature_bitmap - = table->target_feature_bitmap; - request->message.rollback_feature_bitmap - = table->rollback_feature_bitmap; + request->message.source_feature_bitmap = table->source_feature_bitmap; + request->message.target_feature_bitmap = table->target_feature_bitmap; + request->message.rollback_feature_bitmap = table->rollback_feature_bitmap; request->message.admitted_members_lo = table->expected_members_lo; request->message.admitted_members_hi = table->expected_members_hi; request->message.capability_sample_digest = fixture->digest; @@ -3360,22 +3192,17 @@ stage_ahead_barrier_request_fixture_init( request->sampled_capability_generation = 7; final_ack->message.kind = CLUSTER_SEMANTIC_ACTIVATION_ACK_KIND_ACK; - final_ack->message.stage - = CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_SAMPLE; - final_ack->message.result - = CLUSTER_SEMANTIC_ACTIVATION_ACK_RESULT_OK; + final_ack->message.stage = CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_SAMPLE; + final_ack->message.result = CLUSTER_SEMANTIC_ACTIVATION_ACK_RESULT_OK; final_ack->message.reason = CLUSTER_SEMANTIC_ACTIVATION_OK; final_ack->message.coordinator_node = 0; final_ack->message.member_node = 3; final_ack->message.transition_epoch = table->transition_epoch; final_ack->message.record_generation = table->record_generation; final_ack->message.round_nonce = table->round_nonce; - final_ack->message.source_feature_bitmap - = table->source_feature_bitmap; - final_ack->message.target_feature_bitmap - = table->target_feature_bitmap; - final_ack->message.rollback_feature_bitmap - = table->rollback_feature_bitmap; + final_ack->message.source_feature_bitmap = table->source_feature_bitmap; + final_ack->message.target_feature_bitmap = table->target_feature_bitmap; + final_ack->message.rollback_feature_bitmap = table->rollback_feature_bitmap; final_ack->message.admitted_members_lo = table->expected_members_lo; final_ack->message.admitted_members_hi = table->expected_members_hi; final_ack->message.boot_id = 1; @@ -3387,11 +3214,9 @@ stage_ahead_barrier_request_fixture_init( final_ack->sampled_capability_generation = 7; pg_atomic_init_u64(&fixture->shmem.admission_seq, 6); - pg_atomic_init_u64(&fixture->shmem.active_bits, - CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1); + pg_atomic_init_u64(&fixture->shmem.active_bits, CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1); pg_atomic_init_u64(&fixture->shmem.record_generation, 9); - pg_atomic_init_u64(&fixture->shmem.formation_epoch, - table->transition_epoch); + pg_atomic_init_u64(&fixture->shmem.formation_epoch, table->transition_epoch); pg_atomic_init_u32(&fixture->shmem.transition_closed, 0); cluster_node_id = 2; @@ -3413,18 +3238,16 @@ stage_ahead_barrier_request_fixture_init( cluster_r4_activation_test_capability_word = required_caps; cluster_r4_activation_test_capability_generation = 7; cluster_r4_activation_test_local_capability_word = required_caps; - memset(cluster_r4_activation_test_send_calls, 0, - sizeof(cluster_r4_activation_test_send_calls)); + memset(cluster_r4_activation_test_send_calls, 0, sizeof(cluster_r4_activation_test_send_calls)); memset(&semantic_activation_ack_local_pending_send, 0, - sizeof(semantic_activation_ack_local_pending_send)); + sizeof(semantic_activation_ack_local_pending_send)); memset(&semantic_activation_ack_local_request_origin, 0, - sizeof(semantic_activation_ack_local_request_origin)); + sizeof(semantic_activation_ack_local_request_origin)); memset(&semantic_activation_ack_local_stage_ahead, 0, - sizeof(semantic_activation_ack_local_stage_ahead)); + sizeof(semantic_activation_ack_local_stage_ahead)); memset(&semantic_activation_ack_local_request_ahead, 0, - sizeof(semantic_activation_ack_local_request_ahead)); - semantic_activation_ack_ingress_init( - &semantic_activation_ack_local_ingress); + sizeof(semantic_activation_ack_local_request_ahead)); + semantic_activation_ack_ingress_init(&semantic_activation_ack_local_ingress); SemanticActivationShmem = &fixture->shmem; SemanticActivationAckTable = table; } @@ -3438,7 +3261,7 @@ stage_ahead_barrier_request_fixture_cleanup(void) cluster_r4_activation_test_capability_generation = 7; cluster_r4_activation_test_capability_expected_generation = 7; memset(&semantic_activation_ack_local_request_ahead, 0, - sizeof(semantic_activation_ack_local_request_ahead)); + sizeof(semantic_activation_ack_local_request_ahead)); } UT_TEST(test_99_stage_ahead_barrier_request_waits_without_mutation_then_applies) @@ -3449,21 +3272,18 @@ UT_TEST(test_99_stage_ahead_barrier_request_waits_without_mutation_then_applies) stage_ahead_barrier_request_fixture_init(&fixture); before = fixture.table; - UT_ASSERT(semantic_activation_ack_ingress_push( - &semantic_activation_ack_local_ingress, &fixture.request)); + UT_ASSERT(semantic_activation_ack_ingress_push(&semantic_activation_ack_local_ingress, + &fixture.request)); semantic_activation_ack_lmon_drain(); UT_ASSERT_EQ(memcmp(&fixture.table, &before, sizeof(before)), 0); for (node = 0; node < 4; node++) UT_ASSERT_EQ(cluster_r4_activation_test_send_calls[node], 0); - UT_ASSERT(semantic_activation_ack_ingress_push( - &semantic_activation_ack_local_ingress, - &fixture.final_sample_ack)); + UT_ASSERT(semantic_activation_ack_ingress_push(&semantic_activation_ack_local_ingress, + &fixture.final_sample_ack)); semantic_activation_ack_lmon_drain(); - UT_ASSERT_EQ(fixture.table.stage, - CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_BARRIER); - UT_ASSERT_EQ(fixture.table.flags, - CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID); + UT_ASSERT_EQ(fixture.table.stage, CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_BARRIER); + UT_ASSERT_EQ(fixture.table.flags, CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID); UT_ASSERT_EQ(fixture.table.capability_sample_digest, fixture.digest); UT_ASSERT_EQ(fixture.table.observed_members_lo, UINT64_C(0)); UT_ASSERT_EQ(fixture.table.observed_members_hi, UINT64_C(0)); @@ -3478,18 +3298,15 @@ UT_TEST(test_100_stage_ahead_barrier_request_duplicate_is_consumed_once) StageAheadBarrierRequestFixture fixture; stage_ahead_barrier_request_fixture_init(&fixture); - UT_ASSERT(semantic_activation_ack_ingress_push( - &semantic_activation_ack_local_ingress, &fixture.request)); - UT_ASSERT(semantic_activation_ack_ingress_push( - &semantic_activation_ack_local_ingress, &fixture.request)); - UT_ASSERT(semantic_activation_ack_ingress_push( - &semantic_activation_ack_local_ingress, - &fixture.final_sample_ack)); + UT_ASSERT(semantic_activation_ack_ingress_push(&semantic_activation_ack_local_ingress, + &fixture.request)); + UT_ASSERT(semantic_activation_ack_ingress_push(&semantic_activation_ack_local_ingress, + &fixture.request)); + UT_ASSERT(semantic_activation_ack_ingress_push(&semantic_activation_ack_local_ingress, + &fixture.final_sample_ack)); semantic_activation_ack_lmon_drain(); - UT_ASSERT_EQ(fixture.table.stage, - CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_BARRIER); - UT_ASSERT_EQ(fixture.table.flags, - CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID); + UT_ASSERT_EQ(fixture.table.stage, CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_BARRIER); + UT_ASSERT_EQ(fixture.table.flags, CLUSTER_SEMANTIC_ACTIVATION_ACK_FLAG_EXPECTED_VALID); UT_ASSERT_EQ(fixture.table.capability_sample_digest, fixture.digest); UT_ASSERT_EQ(fixture.table.observed_members_lo, UINT64_C(0)); @@ -3502,16 +3319,16 @@ UT_TEST(test_101_stage_ahead_barrier_request_connection_conflict_fails_closed) SemanticActivationAckIngressItem conflict; stage_ahead_barrier_request_fixture_init(&fixture); - UT_ASSERT(semantic_activation_ack_ingress_push( - &semantic_activation_ack_local_ingress, &fixture.request)); + UT_ASSERT(semantic_activation_ack_ingress_push(&semantic_activation_ack_local_ingress, + &fixture.request)); semantic_activation_ack_lmon_drain(); conflict = fixture.request; conflict.sampled_capability_generation = 8; cluster_r4_activation_test_capability_generation = 8; cluster_r4_activation_test_capability_expected_generation = 8; - UT_ASSERT(semantic_activation_ack_ingress_push( - &semantic_activation_ack_local_ingress, &conflict)); + UT_ASSERT( + semantic_activation_ack_ingress_push(&semantic_activation_ack_local_ingress, &conflict)); semantic_activation_ack_lmon_drain(); UT_ASSERT_EQ(fixture.table.flags, UINT32_C(0)); UT_ASSERT_EQ(fixture.table.expected_members_lo, UINT64_C(0)); diff --git a/src/test/cluster_unit/test_cluster_r4_d10_hint_source.c b/src/test/cluster_unit/test_cluster_r4_d10_hint_source.c index 5c658af9c4d..c7ef4852ec9 100644 --- a/src/test/cluster_unit/test_cluster_r4_d10_hint_source.c +++ b/src/test/cluster_unit/test_cluster_r4_d10_hint_source.c @@ -79,6 +79,21 @@ BackendType MyBackendType = B_BACKEND; sigjmp_buf *PG_exception_stack = NULL; ErrorContextCallback *error_context_stack = NULL; +void +cluster_vis_evidence_note(ClusterVisEvidenceMetric metric pg_attribute_unused()) +{ + /* Diagnostics are not the source-admission policy under test. */ +} + +const ClusterNodeInfo * +cluster_conf_lookup_node(int32 node_id) +{ + for (int i = 0; i < test_cluster_conf.node_count; i++) + if (test_cluster_conf.nodes[i].node_id == node_id) + return &test_cluster_conf.nodes[i]; + return NULL; +} + void ExceptionalCondition(const char *condition_name pg_attribute_unused(), const char *file_name pg_attribute_unused(), @@ -154,7 +169,8 @@ cluster_epoch_get_current(void) ClusterSemanticAdmissionResult cluster_multixact_source_dispatch(ClusterMultiXactSourceOp op pg_attribute_unused(), - const ClusterMultiXactSourceRequest *request pg_attribute_unused(), + const ClusterMultiXactSourceRequest *request + pg_attribute_unused(), ClusterMultiXactSourceResult *result) { memset(result, 0, sizeof(*result)); @@ -164,8 +180,8 @@ cluster_multixact_source_dispatch(ClusterMultiXactSourceOp op pg_attribute_unuse ClusterSemanticAdmissionResult cluster_tt_status_source_dispatch(ClusterTTStatusSourceOp op pg_attribute_unused(), - const ClusterTTStatusSourceRequest *request pg_attribute_unused(), - ClusterTTStatusSourceResult *result) + const ClusterTTStatusSourceRequest *request pg_attribute_unused(), + ClusterTTStatusSourceResult *result) { memset(result, 0, sizeof(*result)); result->bool_value = true; @@ -276,6 +292,8 @@ test_prepare_hint_state(void) { memset(&test_cluster_conf, 0, sizeof(test_cluster_conf)); test_cluster_conf.node_count = 2; + test_cluster_conf.nodes[0].node_id = 0; + test_cluster_conf.nodes[1].node_id = 1; cluster_tt_status_hint_shmem_init(); } diff --git a/src/test/cluster_unit/test_cluster_r4_d10_multi_source.c b/src/test/cluster_unit/test_cluster_r4_d10_multi_source.c index 5adef192eab..140ef16c9c7 100644 --- a/src/test/cluster_unit/test_cluster_r4_d10_multi_source.c +++ b/src/test/cluster_unit/test_cluster_r4_d10_multi_source.c @@ -80,16 +80,14 @@ static bool fake_force_error; static bool fake_state_found; static bool fake_lock_found; -static union -{ +static union { uint64 align; unsigned char bytes[128]; } fake_state; static LWLockPadded fake_lock; -static union -{ +static union { uint64 align; unsigned char bytes[8192]; } fake_hash_entry; @@ -109,10 +107,12 @@ cluster_xid_origin_slot(TransactionId xid pg_attribute_unused()) } ClusterTTDurableLocate -cluster_tt_slot_durable_locate_any_by_xid_origin( - int origin_node pg_attribute_unused(), TransactionId xid pg_attribute_unused(), - uint16 *out_seg pg_attribute_unused(), uint16 *out_slot pg_attribute_unused(), - uint16 *out_wrap pg_attribute_unused(), uint8 *out_status pg_attribute_unused()) +cluster_tt_slot_durable_locate_any_by_xid_origin(int origin_node pg_attribute_unused(), + TransactionId xid pg_attribute_unused(), + uint16 *out_seg pg_attribute_unused(), + uint16 *out_slot pg_attribute_unused(), + uint16 *out_wrap pg_attribute_unused(), + uint8 *out_status pg_attribute_unused()) { return CLUSTER_TT_DURABLE_LOCATE_MISSING; } @@ -134,8 +134,7 @@ reset_admission(ClusterSemanticAdmissionResult result, bool recheck_ok) static void reset_admission_sides(ClusterSemanticAdmissionResult target_result, - ClusterSemanticAdmissionResult source_result, - bool recheck_ok) + ClusterSemanticAdmissionResult source_result, bool recheck_ok) { reset_admission(target_result, recheck_ok); target_admission_result = target_result; @@ -157,20 +156,19 @@ cluster_semantic_activation_enter(uint64 feature_bit, ClusterSemanticAdmissionSi { ClusterSemanticAdmissionResult selected_result = admission_result_by_side - ? (side == CLUSTER_SEMANTIC_TARGET_SIDE - ? target_admission_result : source_admission_result) - : admission_result; + ? (side == CLUSTER_SEMANTIC_TARGET_SIDE ? target_admission_result + : source_admission_result) + : admission_result; admission_enter_count++; admission_feature = feature_bit; admission_side = side; memset(token, 0, sizeof(*token)); - if (selected_result == CLUSTER_SEMANTIC_ADMISSION_OK) - { + if (selected_result == CLUSTER_SEMANTIC_ADMISSION_OK) { token->feature_bit = feature_bit; token->record_generation = 7; token->formation_epoch = 11; - token->side = (uint8) side; + token->side = (uint8)side; token->entered = true; } return selected_result; @@ -194,8 +192,7 @@ cluster_semantic_activation_leave(ClusterSemanticAdmissionToken *token) void * ShmemInitStruct(const char *name, Size size, bool *found_ptr) { - if (strcmp(name, "ClusterMultiXactState") == 0) - { + if (strcmp(name, "ClusterMultiXactState") == 0) { UT_ASSERT(size <= sizeof(fake_state.bytes)); *found_ptr = fake_state_found; fake_state_found = true; @@ -219,7 +216,7 @@ ShmemInitHash(const char *name pg_attribute_unused(), long init_size pg_attribut Size hash_estimate_size(long num_entries, Size entry_size) { - return (Size) num_entries * entry_size; + return (Size)num_entries * entry_size; } Size @@ -234,22 +231,18 @@ hash_search(HTAB *hashp, const void *key_ptr, HASHACTION action, bool *found_ptr fake_hash_search_count++; UT_ASSERT(hashp == fake_hash); - if (action == HASH_ENTER_NULL) - { + if (action == HASH_ENTER_NULL) { if (found_ptr != NULL) - *found_ptr = memcmp(fake_hash_entry.bytes, key_ptr, - sizeof(ClusterMultiXactKey)) == 0; + *found_ptr = memcmp(fake_hash_entry.bytes, key_ptr, sizeof(ClusterMultiXactKey)) == 0; memcpy(fake_hash_entry.bytes, key_ptr, sizeof(ClusterMultiXactKey)); return fake_hash_entry.bytes; } - if (action == HASH_FIND) - { + if (action == HASH_FIND) { if (memcmp(fake_hash_entry.bytes, key_ptr, sizeof(ClusterMultiXactKey)) == 0) return fake_hash_entry.bytes; return NULL; } - if (action == HASH_REMOVE) - { + if (action == HASH_REMOVE) { memset(fake_hash_entry.bytes, 0, sizeof(fake_hash_entry.bytes)); return fake_hash_entry.bytes; } @@ -268,8 +261,7 @@ hash_seq_search(HASH_SEQ_STATUS *status pg_attribute_unused()) ClusterMultiXactKey zero; memset(&zero, 0, sizeof(zero)); - if (fake_hash_seq_index++ == 0 && - memcmp(fake_hash_entry.bytes, &zero, sizeof(zero)) != 0) + if (fake_hash_seq_index++ == 0 && memcmp(fake_hash_entry.bytes, &zero, sizeof(zero)) != 0) return fake_hash_entry.bytes; return NULL; } @@ -293,7 +285,7 @@ GetCurrentTimestamp(void) { if (fake_force_error && PG_exception_stack != NULL) siglongjmp(*PG_exception_stack, 1); - return (TimestampTz) 12345; + return (TimestampTz)12345; } uint64 @@ -308,8 +300,8 @@ cluster_shmem_register_region(const ClusterShmemRegion *region pg_attribute_unus ClusterSemanticAdmissionResult cluster_tt_status_source_dispatch(ClusterTTStatusSourceOp op pg_attribute_unused(), - const ClusterTTStatusSourceRequest *request pg_attribute_unused(), - ClusterTTStatusSourceResult *result) + const ClusterTTStatusSourceRequest *request pg_attribute_unused(), + ClusterTTStatusSourceResult *result) { memset(result, 0, sizeof(*result)); return CLUSTER_SEMANTIC_ADMISSION_OK; @@ -329,17 +321,16 @@ cluster_vis_cr_xmax_verdict(ClusterTTStatus status pg_attribute_unused(), } bool -cluster_gcs_block_undo_multi_verdict_fetch_and_wait(int32 origin_node pg_attribute_unused(), - MultiXactId mxid pg_attribute_unused(), - char *page_out pg_attribute_unused(), - ClusterLiveAuthority *auth_out pg_attribute_unused()) +cluster_gcs_block_undo_multi_verdict_fetch_and_wait( + int32 origin_node pg_attribute_unused(), MultiXactId mxid pg_attribute_unused(), + char *page_out pg_attribute_unused(), ClusterLiveAuthority *auth_out pg_attribute_unused()) { return false; } bool cluster_vis_live_authority_covers(SCN demand_scn pg_attribute_unused(), - ClusterLiveAuthority auth pg_attribute_unused()) + ClusterLiveAuthority auth pg_attribute_unused()) { return false; } @@ -437,13 +428,13 @@ make_install_request(ClusterMultiXactKey *key, ClusterMultiXactMember *member) UT_TEST(t1_frozen_dispatch_surface) { - UT_ASSERT_EQ((int) CLUSTER_MULTI_SOURCE_OVERLAY_INSTALL, 0); - UT_ASSERT_EQ((int) CLUSTER_MULTI_SOURCE_OVERLAY_LOOKUP, 1); - UT_ASSERT_EQ((int) CLUSTER_MULTI_SOURCE_RESOLVE_VISIBILITY, 2); - UT_ASSERT_EQ((int) CLUSTER_MULTI_SOURCE_GET_MEMBER_COUNT, 3); - UT_ASSERT_EQ((int) CLUSTER_MULTI_SOURCE_REMOTE_XMAX_RESOLVE, 4); - UT_ASSERT_EQ((int) CLUSTER_MULTI_SOURCE_NOTE_HALFSPACE_REFUSE, 5); - UT_ASSERT_EQ((int) CLUSTER_MULTI_SOURCE_NOTE_UNDERIVABLE_READ, 6); + UT_ASSERT_EQ((int)CLUSTER_MULTI_SOURCE_OVERLAY_INSTALL, 0); + UT_ASSERT_EQ((int)CLUSTER_MULTI_SOURCE_OVERLAY_LOOKUP, 1); + UT_ASSERT_EQ((int)CLUSTER_MULTI_SOURCE_RESOLVE_VISIBILITY, 2); + UT_ASSERT_EQ((int)CLUSTER_MULTI_SOURCE_GET_MEMBER_COUNT, 3); + UT_ASSERT_EQ((int)CLUSTER_MULTI_SOURCE_REMOTE_XMAX_RESOLVE, 4); + UT_ASSERT_EQ((int)CLUSTER_MULTI_SOURCE_NOTE_HALFSPACE_REFUSE, 5); + UT_ASSERT_EQ((int)CLUSTER_MULTI_SOURCE_NOTE_UNDERIVABLE_READ, 6); } UT_TEST(t2_dormant_refuses_before_request_and_mutation) @@ -454,21 +445,20 @@ UT_TEST(t2_dormant_refuses_before_request_and_mutation) memset(&result, 0x7f, sizeof(result)); reset_admission(CLUSTER_SEMANTIC_ADMISSION_SOURCE_DORMANT, true); - UT_ASSERT_EQ((int) cluster_multixact_source_dispatch( - (ClusterMultiXactSourceOp) CLUSTER_MULTI_SOURCE_OVERLAY_INSTALL, - (const ClusterMultiXactSourceRequest *) (uintptr_t) 1, &result), - (int) CLUSTER_SEMANTIC_ADMISSION_SOURCE_DORMANT); + UT_ASSERT_EQ((int)cluster_multixact_source_dispatch( + (ClusterMultiXactSourceOp)CLUSTER_MULTI_SOURCE_OVERLAY_INSTALL, + (const ClusterMultiXactSourceRequest *)(uintptr_t)1, &result), + (int)CLUSTER_SEMANTIC_ADMISSION_SOURCE_DORMANT); UT_ASSERT_EQ(admission_enter_count, 1); UT_ASSERT_EQ(admission_recheck_count, 0); UT_ASSERT_EQ(admission_leave_count, 0); - UT_ASSERT_EQ((uint64) admission_feature, - (uint64) CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1); - UT_ASSERT_EQ((int) admission_side, (int) CLUSTER_SEMANTIC_SOURCE_SIDE); - UT_ASSERT_EQ((int) result.bool_value, 0); - UT_ASSERT_EQ((int) result.member_count, 0); - UT_ASSERT_EQ((int) result.visibility, 0); - UT_ASSERT_EQ((int) result.overlay_hit, 0); - UT_ASSERT_EQ((uint64) cluster_multixact_get_overlay_install_count(), before); + UT_ASSERT_EQ((uint64)admission_feature, (uint64)CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1); + UT_ASSERT_EQ((int)admission_side, (int)CLUSTER_SEMANTIC_SOURCE_SIDE); + UT_ASSERT_EQ((int)result.bool_value, 0); + UT_ASSERT_EQ((int)result.member_count, 0); + UT_ASSERT_EQ((int)result.visibility, 0); + UT_ASSERT_EQ((int)result.overlay_hit, 0); + UT_ASSERT_EQ((uint64)cluster_multixact_get_overlay_install_count(), before); UT_ASSERT_EQ(fake_hash_search_count, searches_before); } @@ -478,18 +468,18 @@ UT_TEST(t3_invalid_after_admission_closes_and_leaves) memset(&result, 0x7f, sizeof(result)); reset_admission(CLUSTER_SEMANTIC_ADMISSION_OK, true); - UT_ASSERT_EQ((int) cluster_multixact_source_dispatch( - CLUSTER_MULTI_SOURCE_OVERLAY_INSTALL, NULL, &result), - (int) CLUSTER_SEMANTIC_ADMISSION_CLOSED); + UT_ASSERT_EQ( + (int)cluster_multixact_source_dispatch(CLUSTER_MULTI_SOURCE_OVERLAY_INSTALL, NULL, &result), + (int)CLUSTER_SEMANTIC_ADMISSION_CLOSED); UT_ASSERT_EQ(admission_enter_count, 1); UT_ASSERT_EQ(admission_recheck_count, 0); UT_ASSERT_EQ(admission_leave_count, 1); UT_ASSERT(!result.bool_value); reset_admission(CLUSTER_SEMANTIC_ADMISSION_OK, true); - UT_ASSERT_EQ((int) cluster_multixact_source_dispatch( - (ClusterMultiXactSourceOp) 99, NULL, &result), - (int) CLUSTER_SEMANTIC_ADMISSION_CLOSED); + UT_ASSERT_EQ( + (int)cluster_multixact_source_dispatch((ClusterMultiXactSourceOp)99, NULL, &result), + (int)CLUSTER_SEMANTIC_ADMISSION_CLOSED); UT_ASSERT_EQ(admission_leave_count, 1); } @@ -499,14 +489,13 @@ UT_TEST(t4_source_install_and_lookup_are_positive) ClusterMultiXactMember member; ClusterMultiXactSourceRequest request; ClusterMultiXactSourceResult result; - union - { + union { uint64 align; unsigned char bytes[offsetof(ClusterMultiXactMemberOverlayResult, members) + sizeof(ClusterMultiXactMember)]; } output; ClusterMultiXactMemberOverlayResult *overlay - = (ClusterMultiXactMemberOverlayResult *) output.bytes; + = (ClusterMultiXactMemberOverlayResult *)output.bytes; memset(&key, 0, sizeof(key)); key.origin_node_id = 3; @@ -517,9 +506,9 @@ UT_TEST(t4_source_install_and_lookup_are_positive) member.status = MultiXactStatusForShare; request = make_install_request(&key, &member); reset_admission(CLUSTER_SEMANTIC_ADMISSION_OK, true); - UT_ASSERT_EQ((int) cluster_multixact_source_dispatch( - CLUSTER_MULTI_SOURCE_OVERLAY_INSTALL, &request, &result), - (int) CLUSTER_SEMANTIC_ADMISSION_OK); + UT_ASSERT_EQ((int)cluster_multixact_source_dispatch(CLUSTER_MULTI_SOURCE_OVERLAY_INSTALL, + &request, &result), + (int)CLUSTER_SEMANTIC_ADMISSION_OK); UT_ASSERT(result.bool_value); UT_ASSERT_EQ(admission_recheck_count, 1); UT_ASSERT_EQ(admission_leave_count, 1); @@ -530,13 +519,13 @@ UT_TEST(t4_source_install_and_lookup_are_positive) request.overlay_out = overlay; request.max_members_buf = 1; reset_admission(CLUSTER_SEMANTIC_ADMISSION_OK, true); - UT_ASSERT_EQ((int) cluster_multixact_source_dispatch( - CLUSTER_MULTI_SOURCE_OVERLAY_LOOKUP, &request, &result), - (int) CLUSTER_SEMANTIC_ADMISSION_OK); + UT_ASSERT_EQ((int)cluster_multixact_source_dispatch(CLUSTER_MULTI_SOURCE_OVERLAY_LOOKUP, + &request, &result), + (int)CLUSTER_SEMANTIC_ADMISSION_OK); UT_ASSERT(result.bool_value); - UT_ASSERT_EQ((int) result.member_count, 1); + UT_ASSERT_EQ((int)result.member_count, 1); UT_ASSERT(overlay->authoritative); - UT_ASSERT_EQ((int) overlay->members[0].xid, (int) member.xid); + UT_ASSERT_EQ((int)overlay->members[0].xid, (int)member.xid); } UT_TEST(t5_source_visibility_count_and_remote_map_results) @@ -544,14 +533,13 @@ UT_TEST(t5_source_visibility_count_and_remote_map_results) ClusterMultiXactSourceRequest request; ClusterMultiXactSourceResult result; SnapshotData snapshot; - union - { + union { uint64 align; unsigned char bytes[offsetof(ClusterMultiXactMemberOverlayResult, members) + sizeof(ClusterMultiXactMember)]; } input; ClusterMultiXactMemberOverlayResult *overlay - = (ClusterMultiXactMemberOverlayResult *) input.bytes; + = (ClusterMultiXactMemberOverlayResult *)input.bytes; ClusterMultiXactKey key; memset(&snapshot, 0, sizeof(snapshot)); @@ -564,10 +552,10 @@ UT_TEST(t5_source_visibility_count_and_remote_map_results) request.overlay_in = overlay; request.snapshot = &snapshot; reset_admission(CLUSTER_SEMANTIC_ADMISSION_OK, true); - UT_ASSERT_EQ((int) cluster_multixact_source_dispatch( - CLUSTER_MULTI_SOURCE_RESOLVE_VISIBILITY, &request, &result), - (int) CLUSTER_SEMANTIC_ADMISSION_OK); - UT_ASSERT_EQ((int) result.visibility, (int) CLUSTER_VISIBILITY_VISIBLE); + UT_ASSERT_EQ((int)cluster_multixact_source_dispatch(CLUSTER_MULTI_SOURCE_RESOLVE_VISIBILITY, + &request, &result), + (int)CLUSTER_SEMANTIC_ADMISSION_OK); + UT_ASSERT_EQ((int)result.visibility, (int)CLUSTER_VISIBILITY_VISIBLE); memset(&key, 0, sizeof(key)); key.origin_node_id = 3; @@ -576,20 +564,20 @@ UT_TEST(t5_source_visibility_count_and_remote_map_results) memset(&request, 0, sizeof(request)); request.key = &key; reset_admission(CLUSTER_SEMANTIC_ADMISSION_OK, true); - UT_ASSERT_EQ((int) cluster_multixact_source_dispatch( - CLUSTER_MULTI_SOURCE_GET_MEMBER_COUNT, &request, &result), - (int) CLUSTER_SEMANTIC_ADMISSION_OK); - UT_ASSERT_EQ((int) result.member_count, 1); + UT_ASSERT_EQ((int)cluster_multixact_source_dispatch(CLUSTER_MULTI_SOURCE_GET_MEMBER_COUNT, + &request, &result), + (int)CLUSTER_SEMANTIC_ADMISSION_OK); + UT_ASSERT_EQ((int)result.member_count, 1); memset(&request, 0, sizeof(request)); request.snapshot = &snapshot; request.origin_slot = 3; request.mxid = 71; reset_admission(CLUSTER_SEMANTIC_ADMISSION_OK, true); - UT_ASSERT_EQ((int) cluster_multixact_source_dispatch( - CLUSTER_MULTI_SOURCE_REMOTE_XMAX_RESOLVE, &request, &result), - (int) CLUSTER_SEMANTIC_ADMISSION_OK); - UT_ASSERT_EQ((int) result.visibility, (int) CLUSTER_VISIBILITY_VISIBLE); + UT_ASSERT_EQ((int)cluster_multixact_source_dispatch(CLUSTER_MULTI_SOURCE_REMOTE_XMAX_RESOLVE, + &request, &result), + (int)CLUSTER_SEMANTIC_ADMISSION_OK); + UT_ASSERT_EQ((int)result.visibility, (int)CLUSTER_VISIBILITY_VISIBLE); UT_ASSERT(result.overlay_hit); } @@ -600,18 +588,17 @@ UT_TEST(t6_source_counter_ops_execute_only_after_admission) uint64 underivable_before = cluster_multixact_get_mxid_underivable_read_count(); reset_admission(CLUSTER_SEMANTIC_ADMISSION_OK, true); - UT_ASSERT_EQ((int) cluster_multixact_source_dispatch( - CLUSTER_MULTI_SOURCE_NOTE_HALFSPACE_REFUSE, NULL, &result), - (int) CLUSTER_SEMANTIC_ADMISSION_OK); - UT_ASSERT_EQ((uint64) cluster_multixact_get_mxid_halfspace_refuse_count(), - halfspace_before + 1); + UT_ASSERT_EQ((int)cluster_multixact_source_dispatch(CLUSTER_MULTI_SOURCE_NOTE_HALFSPACE_REFUSE, + NULL, &result), + (int)CLUSTER_SEMANTIC_ADMISSION_OK); + UT_ASSERT_EQ((uint64)cluster_multixact_get_mxid_halfspace_refuse_count(), halfspace_before + 1); UT_ASSERT_EQ(admission_leave_count, 1); reset_admission(CLUSTER_SEMANTIC_ADMISSION_OK, true); - UT_ASSERT_EQ((int) cluster_multixact_source_dispatch( - CLUSTER_MULTI_SOURCE_NOTE_UNDERIVABLE_READ, NULL, &result), - (int) CLUSTER_SEMANTIC_ADMISSION_OK); - UT_ASSERT_EQ((uint64) cluster_multixact_get_mxid_underivable_read_count(), + UT_ASSERT_EQ((int)cluster_multixact_source_dispatch(CLUSTER_MULTI_SOURCE_NOTE_UNDERIVABLE_READ, + NULL, &result), + (int)CLUSTER_SEMANTIC_ADMISSION_OK); + UT_ASSERT_EQ((uint64)cluster_multixact_get_mxid_underivable_read_count(), underivable_before + 1); } @@ -631,12 +618,12 @@ UT_TEST(t7_generation_drift_keeps_fixed_result_canonical) request = make_install_request(&key, &member); memset(&result, 0x7f, sizeof(result)); reset_admission(CLUSTER_SEMANTIC_ADMISSION_OK, false); - UT_ASSERT_EQ((int) cluster_multixact_source_dispatch( - CLUSTER_MULTI_SOURCE_OVERLAY_INSTALL, &request, &result), - (int) CLUSTER_SEMANTIC_ADMISSION_GENERATION_CHANGED); + UT_ASSERT_EQ((int)cluster_multixact_source_dispatch(CLUSTER_MULTI_SOURCE_OVERLAY_INSTALL, + &request, &result), + (int)CLUSTER_SEMANTIC_ADMISSION_GENERATION_CHANGED); UT_ASSERT(!result.bool_value); - UT_ASSERT_EQ((int) result.member_count, 0); - UT_ASSERT_EQ((int) result.visibility, 0); + UT_ASSERT_EQ((int)result.member_count, 0); + UT_ASSERT_EQ((int)result.visibility, 0); UT_ASSERT(!result.overlay_hit); UT_ASSERT_EQ(admission_recheck_count, 1); UT_ASSERT_EQ(admission_leave_count, 1); @@ -659,8 +646,8 @@ UT_TEST(t8_error_path_leaves_once_before_rethrow) fake_force_error = true; PG_TRY(); { - (void) cluster_multixact_source_dispatch(CLUSTER_MULTI_SOURCE_OVERLAY_INSTALL, - &request, &result); + (void)cluster_multixact_source_dispatch(CLUSTER_MULTI_SOURCE_OVERLAY_INSTALL, &request, + &result); } PG_CATCH(); { @@ -675,9 +662,9 @@ UT_TEST(t8_error_path_leaves_once_before_rethrow) UT_TEST(t9_null_result_is_closed_after_balanced_admission) { reset_admission(CLUSTER_SEMANTIC_ADMISSION_OK, true); - UT_ASSERT_EQ((int) cluster_multixact_source_dispatch( - CLUSTER_MULTI_SOURCE_NOTE_HALFSPACE_REFUSE, NULL, NULL), - (int) CLUSTER_SEMANTIC_ADMISSION_CLOSED); + UT_ASSERT_EQ((int)cluster_multixact_source_dispatch(CLUSTER_MULTI_SOURCE_NOTE_HALFSPACE_REFUSE, + NULL, NULL), + (int)CLUSTER_SEMANTIC_ADMISSION_CLOSED); UT_ASSERT_EQ(admission_enter_count, 1); UT_ASSERT_EQ(admission_recheck_count, 0); UT_ASSERT_EQ(admission_leave_count, 1); @@ -690,15 +677,13 @@ UT_TEST(t10_recovery_projection_create_has_exact_postread) ClusterMultiXactKey key; ClusterMultiXactSourceRequest request; ClusterMultiXactSourceResult result; - union - { + union { uint64 align; - unsigned char bytes[ - offsetof(ClusterMultiXactMemberOverlayResult, members) + - 2 * sizeof(ClusterMultiXactMember)]; + unsigned char bytes[offsetof(ClusterMultiXactMemberOverlayResult, members) + + 2 * sizeof(ClusterMultiXactMember)]; } output; - ClusterMultiXactMemberOverlayResult *overlay = - (ClusterMultiXactMemberOverlayResult *) output.bytes; + ClusterMultiXactMemberOverlayResult *overlay + = (ClusterMultiXactMemberOverlayResult *)output.bytes; memset(&operation, 0, sizeof(operation)); operation.kind = CLUSTER_SIDE_PROJECTION_MULTIXACT; @@ -712,12 +697,12 @@ UT_TEST(t10_recovery_projection_create_has_exact_postread) members[0].status = MultiXactStatusForKeyShare; members[1].xid = 816; members[1].status = MultiXactStatusForShare; - UT_ASSERT(cluster_multixact_recovery_projection_apply(NULL, 0, 19, - &operation, (const uint8 *) members, sizeof(members), 100, 200)); - UT_ASSERT(cluster_multixact_recovery_projection_verify(NULL, 0, 19, - &operation, (const uint8 *) members, sizeof(members), 100, 200)); - UT_ASSERT(!cluster_multixact_recovery_projection_verify(NULL, 0, 19, - &operation, (const uint8 *) members, sizeof(members), 100, 201)); + UT_ASSERT(cluster_multixact_recovery_projection_apply( + NULL, 0, 19, &operation, (const uint8 *)members, sizeof(members), 100, 200)); + UT_ASSERT(cluster_multixact_recovery_projection_verify( + NULL, 0, 19, &operation, (const uint8 *)members, sizeof(members), 100, 200)); + UT_ASSERT(!cluster_multixact_recovery_projection_verify( + NULL, 0, 19, &operation, (const uint8 *)members, sizeof(members), 100, 201)); /* The immediate recovery post-read may inspect the row, but ordinary * serving has no retained-source freshness carrier. RFSIDE-V2-A keeps * this projection unserved rather than treating its bytes as truth. */ @@ -731,9 +716,9 @@ UT_TEST(t10_recovery_projection_create_has_exact_postread) request.overlay_out = overlay; request.max_members_buf = 2; reset_admission(CLUSTER_SEMANTIC_ADMISSION_OK, true); - UT_ASSERT_EQ((int) cluster_multixact_source_dispatch( - CLUSTER_MULTI_SOURCE_OVERLAY_LOOKUP, &request, &result), - (int) CLUSTER_SEMANTIC_ADMISSION_OK); + UT_ASSERT_EQ((int)cluster_multixact_source_dispatch(CLUSTER_MULTI_SOURCE_OVERLAY_LOOKUP, + &request, &result), + (int)CLUSTER_SEMANTIC_ADMISSION_OK); UT_ASSERT(!result.bool_value); UT_ASSERT(!overlay->authoritative); memset(&operation, 0, sizeof(operation)); @@ -741,10 +726,10 @@ UT_TEST(t10_recovery_projection_create_has_exact_postread) operation.action = CLUSTER_SIDE_PROJECTION_ACTION_ZERO_PAGE; operation.normalized_info = XLOG_MULTIXACT_ZERO_OFF_PAGE; operation.page_number = 0; - UT_ASSERT(cluster_multixact_recovery_projection_apply(NULL, 0, 19, - &operation, NULL, 0, 201, 202)); - UT_ASSERT(cluster_multixact_recovery_projection_verify(NULL, 0, 19, - &operation, NULL, 0, 201, 202)); + UT_ASSERT( + cluster_multixact_recovery_projection_apply(NULL, 0, 19, &operation, NULL, 0, 201, 202)); + UT_ASSERT( + cluster_multixact_recovery_projection_verify(NULL, 0, 19, &operation, NULL, 0, 201, 202)); } UT_TEST(t11_remote_visibility_follows_current_semantic_side) @@ -764,9 +749,9 @@ UT_TEST(t11_remote_visibility_follows_current_semantic_side) member.status = MultiXactStatusForShare; request = make_install_request(&key, &member); reset_admission(CLUSTER_SEMANTIC_ADMISSION_OK, true); - UT_ASSERT_EQ((int) cluster_multixact_source_dispatch( - CLUSTER_MULTI_SOURCE_OVERLAY_INSTALL, &request, &result), - (int) CLUSTER_SEMANTIC_ADMISSION_OK); + UT_ASSERT_EQ((int)cluster_multixact_source_dispatch(CLUSTER_MULTI_SOURCE_OVERLAY_INSTALL, + &request, &result), + (int)CLUSTER_SEMANTIC_ADMISSION_OK); UT_ASSERT(result.bool_value); memset(&snapshot, 0, sizeof(snapshot)); @@ -776,39 +761,38 @@ UT_TEST(t11_remote_visibility_follows_current_semantic_side) request.mxid = 91; /* OPEN R4 owns the frozen reader operation through TARGET admission. */ - reset_admission_sides(CLUSTER_SEMANTIC_ADMISSION_OK, - CLUSTER_SEMANTIC_ADMISSION_SOURCE_DORMANT, true); - UT_ASSERT_EQ((int) cluster_multixact_remote_xmax_visibility_dispatch( - &request, &result), (int) CLUSTER_SEMANTIC_ADMISSION_OK); + reset_admission_sides(CLUSTER_SEMANTIC_ADMISSION_OK, CLUSTER_SEMANTIC_ADMISSION_SOURCE_DORMANT, + true); + UT_ASSERT_EQ((int)cluster_multixact_remote_xmax_visibility_dispatch(&request, &result), + (int)CLUSTER_SEMANTIC_ADMISSION_OK); UT_ASSERT_EQ(admission_enter_count, 1); - UT_ASSERT_EQ((int) admission_side, (int) CLUSTER_SEMANTIC_TARGET_SIDE); + UT_ASSERT_EQ((int)admission_side, (int)CLUSTER_SEMANTIC_TARGET_SIDE); UT_ASSERT_EQ(admission_recheck_count, 1); UT_ASSERT_EQ(admission_leave_count, 1); - UT_ASSERT_EQ((int) result.visibility, (int) CLUSTER_VISIBILITY_VISIBLE); + UT_ASSERT_EQ((int)result.visibility, (int)CLUSTER_VISIBILITY_VISIBLE); UT_ASSERT(result.overlay_hit); /* Before activation, exact TARGET_DISABLED may fall back to SOURCE. */ - reset_admission_sides(CLUSTER_SEMANTIC_ADMISSION_TARGET_DISABLED, - CLUSTER_SEMANTIC_ADMISSION_OK, true); - UT_ASSERT_EQ((int) cluster_multixact_remote_xmax_visibility_dispatch( - &request, &result), (int) CLUSTER_SEMANTIC_ADMISSION_OK); + reset_admission_sides(CLUSTER_SEMANTIC_ADMISSION_TARGET_DISABLED, CLUSTER_SEMANTIC_ADMISSION_OK, + true); + UT_ASSERT_EQ((int)cluster_multixact_remote_xmax_visibility_dispatch(&request, &result), + (int)CLUSTER_SEMANTIC_ADMISSION_OK); UT_ASSERT_EQ(admission_enter_count, 2); - UT_ASSERT_EQ((int) admission_side, (int) CLUSTER_SEMANTIC_SOURCE_SIDE); + UT_ASSERT_EQ((int)admission_side, (int)CLUSTER_SEMANTIC_SOURCE_SIDE); UT_ASSERT_EQ(admission_recheck_count, 1); UT_ASSERT_EQ(admission_leave_count, 1); - UT_ASSERT_EQ((int) result.visibility, (int) CLUSTER_VISIBILITY_VISIBLE); + UT_ASSERT_EQ((int)result.visibility, (int)CLUSTER_VISIBILITY_VISIBLE); /* Generation drift is not a license to cross the cutover boundary. */ memset(&result, 0x7f, sizeof(result)); reset_admission_sides(CLUSTER_SEMANTIC_ADMISSION_GENERATION_CHANGED, - CLUSTER_SEMANTIC_ADMISSION_OK, true); - UT_ASSERT_EQ((int) cluster_multixact_remote_xmax_visibility_dispatch( - &request, &result), - (int) CLUSTER_SEMANTIC_ADMISSION_GENERATION_CHANGED); + CLUSTER_SEMANTIC_ADMISSION_OK, true); + UT_ASSERT_EQ((int)cluster_multixact_remote_xmax_visibility_dispatch(&request, &result), + (int)CLUSTER_SEMANTIC_ADMISSION_GENERATION_CHANGED); UT_ASSERT_EQ(admission_enter_count, 1); UT_ASSERT_EQ(admission_recheck_count, 0); UT_ASSERT_EQ(admission_leave_count, 0); - UT_ASSERT_EQ((int) result.visibility, 0); + UT_ASSERT_EQ((int)result.visibility, 0); UT_ASSERT(!result.overlay_hit); } diff --git a/src/test/cluster_unit/test_cluster_r4_d10_tt_source.c b/src/test/cluster_unit/test_cluster_r4_d10_tt_source.c index 8f198a88f56..8c6604e66d0 100644 --- a/src/test/cluster_unit/test_cluster_r4_d10_tt_source.c +++ b/src/test/cluster_unit/test_cluster_r4_d10_tt_source.c @@ -225,8 +225,7 @@ hash_search(HTAB *hashp pg_attribute_unused(), const void *key_ptr pg_attribute_ switch (action) { case HASH_FIND: for (i = 0; i < fake_hash_count; i++) - if (memcmp(fake_hash_storage[i], key_ptr, - sizeof(ClusterTTStatusKey)) == 0) { + if (memcmp(fake_hash_storage[i], key_ptr, sizeof(ClusterTTStatusKey)) == 0) { if (found_ptr != NULL) *found_ptr = true; return fake_hash_storage[i]; @@ -237,8 +236,7 @@ hash_search(HTAB *hashp pg_attribute_unused(), const void *key_ptr pg_attribute_ case HASH_ENTER: case HASH_ENTER_NULL: for (i = 0; i < fake_hash_count; i++) - if (memcmp(fake_hash_storage[i], key_ptr, - sizeof(ClusterTTStatusKey)) == 0) { + if (memcmp(fake_hash_storage[i], key_ptr, sizeof(ClusterTTStatusKey)) == 0) { if (found_ptr != NULL) *found_ptr = true; return fake_hash_storage[i]; @@ -247,21 +245,17 @@ hash_search(HTAB *hashp pg_attribute_unused(), const void *key_ptr pg_attribute_ *found_ptr = false; if (fake_hash_count >= lengthof(fake_hash_storage)) return NULL; - memset(fake_hash_storage[fake_hash_count], 0, - sizeof(fake_hash_storage[fake_hash_count])); - memcpy(fake_hash_storage[fake_hash_count], key_ptr, - sizeof(ClusterTTStatusKey)); + memset(fake_hash_storage[fake_hash_count], 0, sizeof(fake_hash_storage[fake_hash_count])); + memcpy(fake_hash_storage[fake_hash_count], key_ptr, sizeof(ClusterTTStatusKey)); return fake_hash_storage[fake_hash_count++]; case HASH_REMOVE: for (i = 0; i < fake_hash_count; i++) - if (memcmp(fake_hash_storage[i], key_ptr, - sizeof(ClusterTTStatusKey)) == 0) { + if (memcmp(fake_hash_storage[i], key_ptr, sizeof(ClusterTTStatusKey)) == 0) { if (found_ptr != NULL) *found_ptr = true; if (i + 1 < fake_hash_count) memmove(fake_hash_storage[i], fake_hash_storage[i + 1], - (sizeof(fake_hash_storage[0]) - * (fake_hash_count - i - 1))); + (sizeof(fake_hash_storage[0]) * (fake_hash_count - i - 1))); fake_hash_count--; return fake_hash_storage[fake_hash_count]; } @@ -396,9 +390,9 @@ cluster_tt_slot_durable_resolve_by_xid_origin(int origin_node pg_attribute_unuse } ClusterTTDurableLocate -cluster_tt_slot_durable_locate_any_by_xid_origin(int origin_node, - TransactionId xid, uint16 *out_seg, uint16 *out_slot, - uint16 *out_wrap, uint8 *out_status) +cluster_tt_slot_durable_locate_any_by_xid_origin(int origin_node, TransactionId xid, + uint16 *out_seg, uint16 *out_slot, + uint16 *out_wrap, uint8 *out_status) { UT_ASSERT_EQ(origin_node, cluster_node_id); UT_ASSERT(TransactionIdIsNormal(xid)); @@ -416,8 +410,7 @@ cluster_tt_slot_durable_locate_any_by_xid_origin(int origin_node, } bool -cluster_tt_slot_current_owner_by_xid(int node_id, TransactionId xid, - ClusterTTSlotCurrentOwner *out) +cluster_tt_slot_current_owner_by_xid(int node_id, TransactionId xid, ClusterTTSlotCurrentOwner *out) { UT_ASSERT_EQ(node_id, cluster_node_id); UT_ASSERT(TransactionIdIsNormal(xid)); @@ -640,8 +633,8 @@ UT_TEST(test_current_own_candidate_is_exact_and_admission_bound) request.xid = key.local_xid; memset(&result, 0xA5, sizeof(result)); - UT_ASSERT_EQ(cluster_tt_status_source_dispatch( - CLUSTER_TT_SOURCE_LOOKUP_CURRENT_OWN_XID, &request, &result), + UT_ASSERT_EQ(cluster_tt_status_source_dispatch(CLUSTER_TT_SOURCE_LOOKUP_CURRENT_OWN_XID, + &request, &result), CLUSTER_SEMANTIC_ADMISSION_OK); UT_ASSERT(result.bool_value); UT_ASSERT_EQ(memcmp(&result.current_key, &key, sizeof(key)), 0); @@ -694,13 +687,13 @@ UT_TEST(test_current_own_uses_exact_allocator_canonical_among_matching_data_alia request.status = CLUSTER_TT_STATUS_IN_PROGRESS; request.commit_scn = InvalidScn; request.key = &canonical; - UT_ASSERT_EQ(cluster_tt_status_source_dispatch( - CLUSTER_TT_SOURCE_INSTALL_LOCAL, &request, &result), + UT_ASSERT_EQ( + cluster_tt_status_source_dispatch(CLUSTER_TT_SOURCE_INSTALL_LOCAL, &request, &result), CLUSTER_SEMANTIC_ADMISSION_OK); UT_ASSERT(result.bool_value); request.key = &data_alias; - UT_ASSERT_EQ(cluster_tt_status_source_dispatch( - CLUSTER_TT_SOURCE_INSTALL_LOCAL, &request, &result), + UT_ASSERT_EQ( + cluster_tt_status_source_dispatch(CLUSTER_TT_SOURCE_INSTALL_LOCAL, &request, &result), CLUSTER_SEMANTIC_ADMISSION_OK); UT_ASSERT(result.bool_value); @@ -711,16 +704,15 @@ UT_TEST(test_current_own_uses_exact_allocator_canonical_among_matching_data_alia fake_current_owner.segment_id = canonical.undo_segment_id; fake_current_owner.xid = canonical.local_xid; fake_current_owner.commit_scn = InvalidScn; - fake_current_owner.slot_offset = - cluster_tt_slot_id_to_offset(canonical.tt_slot_id); + fake_current_owner.slot_offset = cluster_tt_slot_id_to_offset(canonical.tt_slot_id); fake_current_owner.wrap = 4; fake_current_owner.status = CTS_ACTIVE; memset(&request, 0, sizeof(request)); request.xid = canonical.local_xid; memset(&result, 0xA5, sizeof(result)); - UT_ASSERT_EQ(cluster_tt_status_source_dispatch( - CLUSTER_TT_SOURCE_LOOKUP_CURRENT_OWN_XID, &request, &result), - CLUSTER_SEMANTIC_ADMISSION_OK); + UT_ASSERT_EQ(cluster_tt_status_source_dispatch(CLUSTER_TT_SOURCE_LOOKUP_CURRENT_OWN_XID, + &request, &result), + CLUSTER_SEMANTIC_ADMISSION_OK); UT_ASSERT(result.bool_value); UT_ASSERT_EQ(memcmp(&result.current_key, &canonical, sizeof(canonical)), 0); UT_ASSERT_EQ(result.lookup.status, CLUSTER_TT_STATUS_IN_PROGRESS); @@ -730,9 +722,9 @@ UT_TEST(test_current_own_uses_exact_allocator_canonical_among_matching_data_alia * ambiguous; semantic agreement alone never grants authority. */ fake_current_owner_found = false; memset(&result, 0xA5, sizeof(result)); - UT_ASSERT_EQ(cluster_tt_status_source_dispatch( - CLUSTER_TT_SOURCE_LOOKUP_CURRENT_OWN_XID, &request, &result), - CLUSTER_SEMANTIC_ADMISSION_OK); + UT_ASSERT_EQ(cluster_tt_status_source_dispatch(CLUSTER_TT_SOURCE_LOOKUP_CURRENT_OWN_XID, + &request, &result), + CLUSTER_SEMANTIC_ADMISSION_OK); UT_ASSERT(!result.bool_value); /* A status-divergent alias is rejected even when the allocator owner still @@ -740,16 +732,16 @@ UT_TEST(test_current_own_uses_exact_allocator_canonical_among_matching_data_alia fake_current_owner_found = true; request.key = &data_alias; request.status = CLUSTER_TT_STATUS_ABORTED; - UT_ASSERT_EQ(cluster_tt_status_source_dispatch( - CLUSTER_TT_SOURCE_INSTALL_LOCAL, &request, &result), + UT_ASSERT_EQ( + cluster_tt_status_source_dispatch(CLUSTER_TT_SOURCE_INSTALL_LOCAL, &request, &result), CLUSTER_SEMANTIC_ADMISSION_OK); UT_ASSERT(result.bool_value); memset(&request, 0, sizeof(request)); request.xid = canonical.local_xid; memset(&result, 0xA5, sizeof(result)); - UT_ASSERT_EQ(cluster_tt_status_source_dispatch( - CLUSTER_TT_SOURCE_LOOKUP_CURRENT_OWN_XID, &request, &result), - CLUSTER_SEMANTIC_ADMISSION_OK); + UT_ASSERT_EQ(cluster_tt_status_source_dispatch(CLUSTER_TT_SOURCE_LOOKUP_CURRENT_OWN_XID, + &request, &result), + CLUSTER_SEMANTIC_ADMISSION_OK); UT_ASSERT(!result.bool_value); } diff --git a/src/test/cluster_unit/test_cluster_r4_itl_capacity.c b/src/test/cluster_unit/test_cluster_r4_itl_capacity.c index f3b3fe5c4c3..8bd452e669c 100644 --- a/src/test/cluster_unit/test_cluster_r4_itl_capacity.c +++ b/src/test/cluster_unit/test_cluster_r4_itl_capacity.c @@ -74,6 +74,8 @@ itl_origin(const ClusterTxLocator *locator, uint64 epoch, ClusterTxResolution *o out->proof_kind = CLUSTER_TX_PROOF_ORIGIN_TWOPHASE; } else if (origin_fault == 4) pg_atomic_write_u64(&ut_itl_census_semantic.record_generation, 74); + else if (origin_fault == 6) + out->outcome = CLUSTER_TX_ABORTED; return out->outcome; } @@ -188,12 +190,70 @@ UT_TEST(test_capacity_keeps_unknown_identity_prepared_and_admission_refusals) } } +/* The origin producer's TT-reuse proof is tested in r4_tx_outcome. Here its + * exact terminal response traverses the real resolver and real heap census; + * all eight old lock-only slots must be terminalized, not left active. */ +UT_TEST(test_origin_abort_releases_eight_lock_only_slots_through_real_census) +{ + UtR4HotProductFixture fixture; + HeapHotSearchResult hot; + ClusterItlSlotData *slots; + + ut_itl_census_begin(&fixture, &hot, true); + origin_fault = 6; + origin_calls = active_publications = 0; + UT_ASSERT_EQ(cluster_heap_test_itl_capacity_outcome(UT_HOT_BUFFER, 9900, true), + CLUSTER_HEAP_ITL_CAPACITY_READY); + slots = ClusterPageGetItlSlots((Page)fixture.live_page); + for (int i = 0; i < CLUSTER_ITL_INITRANS_DEFAULT; i++) { + UT_ASSERT_EQ(slots[i].flags, ITL_FLAG_LOCK_ONLY_ABORTED); + UT_ASSERT_EQ(slots[i].commit_scn, InvalidScn); + } + UT_ASSERT_EQ(origin_calls, 8); + UT_ASSERT_EQ(active_publications, 0); + UT_ASSERT_EQ(ut_itl_wait_calls, 0); + UT_ASSERT_EQ(ut_itl_census_dirty_hint_calls, 1); + ut_itl_census_end(); +} + +UT_TEST(test_lock_capacity_does_not_mistake_self_data_slot_for_lock_capacity) +{ + for (int self_lock_slot = 0; self_lock_slot < 2; self_lock_slot++) { + UtR4HotProductFixture fixture; + HeapHotSearchResult hot; + PGAlignedBlock before; + uint64 deadline = 0; + const char *reason = NULL; + + ut_itl_census_begin(&fixture, &hot, true); + origin_fault = 0; + origin_calls = active_publications = 0; + ClusterPageGetItlSlots((Page)fixture.live_page)[0].flags + = self_lock_slot ? ITL_FLAG_LOCK_ONLY_ACTIVE : ITL_FLAG_ACTIVE; + pg_atomic_write_u64(&ut_itl_census_semantic.active_bits, + CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1); + memcpy(before.data, fixture.live_page, BLCKSZ); + UT_ASSERT_EQ(cluster_heap_test_itl_wait_lock_capacity(1, 1200, &deadline, &reason), + self_lock_slot ? CLUSTER_TXW_RETRY : CLUSTER_TXW_RESOLVED); + UT_ASSERT_EQ(ut_itl_wait_calls, self_lock_slot ? 0 : 1); + if (!self_lock_slot) + UT_ASSERT_EQ(ut_itl_wait_locator.xid, 1201); + UT_ASSERT_EQ(ut_itl_census_dirty_hint_calls, 0); + UT_ASSERT_EQ(memcmp(before.data, fixture.live_page, BLCKSZ), 0); + UT_ASSERT(!ut_hot_content_lock_held); + LockBuffer(1, BUFFER_LOCK_EXCLUSIVE); /* fixture teardown only */ + ut_itl_census_end(); + } +} + int main(void) { - UT_PLAN(2); + UT_PLAN(4); UT_RUN(test_exact_active_owner_reaches_capacity_wait_through_real_resolver); UT_RUN(test_capacity_keeps_unknown_identity_prepared_and_admission_refusals); + UT_RUN(test_origin_abort_releases_eight_lock_only_slots_through_real_census); + UT_RUN(test_lock_capacity_does_not_mistake_self_data_slot_for_lock_capacity); UT_DONE(); return ut_failed_count == 0 ? 0 : 1; } diff --git a/src/test/cluster_unit/test_cluster_r4_lms_controls.c b/src/test/cluster_unit/test_cluster_r4_lms_controls.c index df5fd7737c6..b6403268723 100644 --- a/src/test/cluster_unit/test_cluster_r4_lms_controls.c +++ b/src/test/cluster_unit/test_cluster_r4_lms_controls.c @@ -19,18 +19,15 @@ UT_DEFINE_GLOBALS(); extern uint64 cluster_lms_test_publish_r4_worker_incarnation(ClusterLmsSharedState *state, - int worker_id); -extern bool cluster_lms_test_r4_drain_request(ClusterLmsSharedState *state, - uint64 generation, - uint64 *worker_incarnation); -extern bool cluster_lms_test_r4_drain_ack(ClusterLmsSharedState *state, - uint64 worker_incarnation, - uint64 generation); + int worker_id); +extern bool cluster_lms_test_r4_drain_request(ClusterLmsSharedState *state, uint64 generation, + uint64 *worker_incarnation); +extern bool cluster_lms_test_r4_drain_ack(ClusterLmsSharedState *state, uint64 worker_incarnation, + uint64 generation); extern bool cluster_lms_test_r4_drain_ack_matches(ClusterLmsSharedState *state, - uint64 worker_incarnation, - uint64 generation); + uint64 worker_incarnation, uint64 generation); extern bool cluster_lms_test_r4_drain_ack_tick(ClusterLmsSharedState *state, - uint64 worker_incarnation); + uint64 worker_incarnation); int cluster_node_id = 1; @@ -173,8 +170,7 @@ UT_TEST(test_invalid_worker_refuses_without_lock_or_mutation) before = state; UT_ASSERT_EQ(cluster_lms_test_publish_r4_worker_incarnation(&state, -1), UINT64_C(0)); - UT_ASSERT_EQ(cluster_lms_test_publish_r4_worker_incarnation( - &state, CLUSTER_LMS_MAX_WORKERS), + UT_ASSERT_EQ(cluster_lms_test_publish_r4_worker_incarnation(&state, CLUSTER_LMS_MAX_WORKERS), UINT64_C(0)); UT_ASSERT(memcmp(&state, &before, sizeof(state)) == 0); UT_ASSERT_EQ(ut_lock_acquire_count, 0); @@ -190,8 +186,7 @@ UT_TEST(test_drain_request_and_ack_are_current_incarnation_bound) state.r4_controls.data_worker_incarnation[0] = UINT64_C(8); state.r4_controls.drain_ack_generation = UINT64_C(99); - UT_ASSERT(cluster_lms_test_r4_drain_request(&state, UINT64_C(17), - &worker_incarnation)); + UT_ASSERT(cluster_lms_test_r4_drain_request(&state, UINT64_C(17), &worker_incarnation)); UT_ASSERT_EQ(worker_incarnation, UINT64_C(8)); UT_ASSERT_EQ(state.r4_controls.drain_request_generation, UINT64_C(17)); UT_ASSERT_EQ(state.r4_controls.drain_ack_generation, UINT64_C(0)); @@ -202,12 +197,10 @@ UT_TEST(test_drain_request_and_ack_are_current_incarnation_bound) UT_ASSERT_EQ(state.r4_controls.drain_ack_generation, UINT64_C(0)); UT_ASSERT(cluster_lms_test_r4_drain_ack(&state, UINT64_C(8), UINT64_C(17))); UT_ASSERT_EQ(state.r4_controls.drain_ack_generation, UINT64_C(17)); - UT_ASSERT(cluster_lms_test_r4_drain_ack_matches( - &state, UINT64_C(8), UINT64_C(17))); + UT_ASSERT(cluster_lms_test_r4_drain_ack_matches(&state, UINT64_C(8), UINT64_C(17))); state.r4_controls.data_worker_incarnation[0] = UINT64_C(9); - UT_ASSERT(!cluster_lms_test_r4_drain_ack_matches( - &state, UINT64_C(8), UINT64_C(17))); + UT_ASSERT(!cluster_lms_test_r4_drain_ack_matches(&state, UINT64_C(8), UINT64_C(17))); UT_ASSERT_EQ(ut_lock_acquire_count, 6); UT_ASSERT_EQ(ut_lock_release_count, 6); UT_ASSERT_EQ(ut_lock_mode, LW_SHARED); @@ -223,14 +216,12 @@ UT_TEST(test_same_generation_drain_request_preserves_matching_ack) state.r4_controls.drain_request_generation = UINT64_C(17); state.r4_controls.drain_ack_generation = UINT64_C(17); - UT_ASSERT(cluster_lms_test_r4_drain_request( - &state, UINT64_C(17), &worker_incarnation)); + UT_ASSERT(cluster_lms_test_r4_drain_request(&state, UINT64_C(17), &worker_incarnation)); UT_ASSERT_EQ(worker_incarnation, UINT64_C(8)); UT_ASSERT_EQ(state.r4_controls.drain_request_generation, UINT64_C(17)); UT_ASSERT_EQ(state.r4_controls.drain_ack_generation, UINT64_C(17)); - UT_ASSERT(cluster_lms_test_r4_drain_request( - &state, UINT64_C(18), &worker_incarnation)); + UT_ASSERT(cluster_lms_test_r4_drain_request(&state, UINT64_C(18), &worker_incarnation)); UT_ASSERT_EQ(state.r4_controls.drain_request_generation, UINT64_C(18)); UT_ASSERT_EQ(state.r4_controls.drain_ack_generation, UINT64_C(0)); } @@ -246,19 +237,15 @@ UT_TEST(test_drain_request_rejects_zero_and_missing_worker_without_mutation) state.r4_controls.drain_ack_generation = UINT64_C(12); before = state; - UT_ASSERT(!cluster_lms_test_r4_drain_request( - &state, UINT64_C(0), &worker_incarnation)); - UT_ASSERT(!cluster_lms_test_r4_drain_request( - &state, UINT64_C(13), NULL)); - UT_ASSERT(!cluster_lms_test_r4_drain_request( - NULL, UINT64_C(13), &worker_incarnation)); + UT_ASSERT(!cluster_lms_test_r4_drain_request(&state, UINT64_C(0), &worker_incarnation)); + UT_ASSERT(!cluster_lms_test_r4_drain_request(&state, UINT64_C(13), NULL)); + UT_ASSERT(!cluster_lms_test_r4_drain_request(NULL, UINT64_C(13), &worker_incarnation)); UT_ASSERT_EQ(worker_incarnation, UINT64_C(55)); UT_ASSERT(memcmp(&state, &before, sizeof(state)) == 0); UT_ASSERT_EQ(ut_lock_acquire_count, 0); UT_ASSERT_EQ(ut_lock_release_count, 0); - UT_ASSERT(!cluster_lms_test_r4_drain_request( - &state, UINT64_C(13), &worker_incarnation)); + UT_ASSERT(!cluster_lms_test_r4_drain_request(&state, UINT64_C(13), &worker_incarnation)); UT_ASSERT_EQ(worker_incarnation, UINT64_C(55)); UT_ASSERT(memcmp(&state, &before, sizeof(state)) == 0); UT_ASSERT_EQ(ut_lock_acquire_count, 1); diff --git a/src/test/cluster_unit/test_cluster_r4_lock_order.c b/src/test/cluster_unit/test_cluster_r4_lock_order.c index ec5bd2ed9c2..fd13985c2de 100644 --- a/src/test/cluster_unit/test_cluster_r4_lock_order.c +++ b/src/test/cluster_unit/test_cluster_r4_lock_order.c @@ -156,7 +156,7 @@ CommandId GetCurrentCommandId(bool used) { UT_ASSERT(!used); - return (CommandId) 7; + return (CommandId)7; } CommandId @@ -167,10 +167,9 @@ HeapTupleHeaderGetCmax(HeapTupleHeader tup pg_attribute_unused()) } ClusterTxwResult -cluster_tx_enqueue_wait_current_mx( - const ClusterTTStatusKey *holder_key pg_attribute_unused(), - int effective_timeout_ms pg_attribute_unused(), - uint64 *absolute_deadline_mono_us pg_attribute_unused()) +cluster_tx_enqueue_wait_current_mx(const ClusterTTStatusKey *holder_key pg_attribute_unused(), + int effective_timeout_ms pg_attribute_unused(), + uint64 *absolute_deadline_mono_us pg_attribute_unused()) { UT_ASSERT(false); return CLUSTER_TXW_UNPROVABLE; @@ -218,8 +217,7 @@ cluster_grd_recovery_state_value(void) } bool -cluster_reconfig_snapshot_initial_clean_formation( - ClusterInitialCleanFormationSnapshot *out) +cluster_reconfig_snapshot_initial_clean_formation(ClusterInitialCleanFormationSnapshot *out) { if (out != NULL) memset(out, 0, sizeof(*out)); @@ -227,8 +225,7 @@ cluster_reconfig_snapshot_initial_clean_formation( } bool -cluster_pcm_lock_resource_x_gate_snapshot( - ResourceXGateSnapshot *snapshot_out) +cluster_pcm_lock_resource_x_gate_snapshot(ResourceXGateSnapshot *snapshot_out) { if (snapshot_out != NULL) memset(snapshot_out, 0, sizeof(*snapshot_out)); @@ -236,8 +233,7 @@ cluster_pcm_lock_resource_x_gate_snapshot( } bool -cluster_pcm_lock_resource_x_cutover_gate_snapshot_exact( - ResourceXGateSnapshot *snapshot_out) +cluster_pcm_lock_resource_x_cutover_gate_snapshot_exact(ResourceXGateSnapshot *snapshot_out) { if (snapshot_out != NULL) memset(snapshot_out, 0, sizeof(*snapshot_out)); @@ -245,9 +241,9 @@ cluster_pcm_lock_resource_x_cutover_gate_snapshot_exact( } bool -cluster_pcm_lock_resource_x_cutover_current_proof_digest_exact( - bool thawed pg_attribute_unused(), ResourceXReconfigToken *token_out, - uint64 *digest_out) +cluster_pcm_lock_resource_x_cutover_current_proof_digest_exact(bool thawed pg_attribute_unused(), + ResourceXReconfigToken *token_out, + uint64 *digest_out) { if (token_out != NULL) memset(token_out, 0, sizeof(*token_out)); @@ -282,10 +278,8 @@ pg_re_throw(void) bool ItemPointerEquals(ItemPointer pointer1, ItemPointer pointer2) { - return ItemPointerGetBlockNumber(pointer1) - == ItemPointerGetBlockNumber(pointer2) - && ItemPointerGetOffsetNumber(pointer1) - == ItemPointerGetOffsetNumber(pointer2); + return ItemPointerGetBlockNumber(pointer1) == ItemPointerGetBlockNumber(pointer2) + && ItemPointerGetOffsetNumber(pointer1) == ItemPointerGetOffsetNumber(pointer2); } static int ut_alloc_calls; @@ -344,7 +338,7 @@ static bool ut_hot_content_lock_held; static bool ut_hot_production_core_active; static bool ut_hot_r4_target_reachable; static bool ut_hot_current_mx_active; -static uint8 ut_hot_current_mx_pcm_state = (uint8) PCM_STATE_X; +static uint8 ut_hot_current_mx_pcm_state = (uint8)PCM_STATE_X; static bool ut_hot_current_mx_one_shot; static uint64 ut_hot_current_read_bracket; static int ut_hot_current_read_acquire_calls; @@ -442,8 +436,7 @@ cluster_tx_enqueue_wait_exact(const ClusterTxLocator *locator, int effective_tim return ut_itl_wait_result; } void -cluster_multixact_current_stats_bump( - ClusterCurrentMxStatId stat pg_attribute_unused()) +cluster_multixact_current_stats_bump(ClusterCurrentMxStatId stat pg_attribute_unused()) {} void @@ -467,8 +460,7 @@ cluster_heap_test_r4_target_reachable(void) #define UT_ORDINARY_REQUESTER ((TransactionId)905) bool -cluster_itl_find_data_slot_index_by_xid(Page page, TransactionId raw_xid, - uint8 *slot_index_out) +cluster_itl_find_data_slot_index_by_xid(Page page, TransactionId raw_xid, uint8 *slot_index_out) { const ClusterItlSlotData *slots; int match = -1; @@ -482,29 +474,23 @@ cluster_itl_find_data_slot_index_by_xid(Page page, TransactionId raw_xid, if (!PageHasItl(page) || !TransactionIdIsValid(raw_xid)) return false; slots = ClusterPageGetItlSlots(page); - for (i = 0; i < CLUSTER_ITL_INITRANS_DEFAULT; i++) - { + for (i = 0; i < CLUSTER_ITL_INITRANS_DEFAULT; i++) { const ClusterItlSlotData *slot = &slots[i]; - bool data = slot->flags == ITL_FLAG_ACTIVE - || slot->flags == ITL_FLAG_COMMITTED - || slot->flags == ITL_FLAG_ABORTED - || slot->flags == ITL_FLAG_NEEDS_CLEANOUT; + bool data = slot->flags == ITL_FLAG_ACTIVE || slot->flags == ITL_FLAG_COMMITTED + || slot->flags == ITL_FLAG_ABORTED || slot->flags == ITL_FLAG_NEEDS_CLEANOUT; - if (!data || slot->xid != raw_xid - || UBA_is_invalid(slot->undo_segment_head)) + if (!data || slot->xid != raw_xid || UBA_is_invalid(slot->undo_segment_head)) continue; - if (match < 0 || slot->wrap > winning_wrap) - { + if (match < 0 || slot->wrap > winning_wrap) { match = i; winning_wrap = slot->wrap; ambiguous = false; - } - else if (slot->wrap == winning_wrap) + } else if (slot->wrap == winning_wrap) ambiguous = true; } if (match < 0 || ambiguous) return false; - *slot_index_out = (uint8) match; + *slot_index_out = (uint8)match; return true; } @@ -516,11 +502,9 @@ cluster_itl_get_tt_ref(Page page, uint8 itl_slot_idx, ClusterUndoTTSlotRef *ref) *ref = ut_scratch_expected_ref; return true; } - if (page == ut_hot_live_ref_page) - { + if (page == ut_hot_live_ref_page) { ut_hot_live_ref_calls++; - if (ut_hot_current_mx_active && itl_slot_idx == 3) - { + if (ut_hot_current_mx_active && itl_slot_idx == 3) { *ref = ut_hot_successor_ref; return true; } @@ -567,7 +551,7 @@ cluster_tx_resolve_reason_name(ClusterTxResolveReason reason pg_attribute_unused bool cluster_itl_find_multixact_origin_by_xmax(Page page, MultiXactId multixact_id, - uint16 *origin_node_id) + uint16 *origin_node_id) { UT_ASSERT(page == ut_hot_live_ref_page); UT_ASSERT_EQ(multixact_id, UT_HOT_FOREIGN_MXID); @@ -578,10 +562,8 @@ cluster_itl_find_multixact_origin_by_xmax(Page page, MultiXactId multixact_id, } void -cluster_visibility_resolve_from_ref_scn(TransactionId raw_xid, - const ClusterUndoTTSlotRef *ref, - XLogRecPtr anchor_lsn, SCN read_scn, - ClusterVisResolve *out) +cluster_visibility_resolve_from_ref_scn(TransactionId raw_xid, const ClusterUndoTTSlotRef *ref, + XLogRecPtr anchor_lsn, SCN read_scn, ClusterVisResolve *out) { ut_scratch_exact_resolve_calls++; if (ut_hot_production_core_active) @@ -815,11 +797,10 @@ cluster_tt_status_source_dispatch(ClusterTTStatusSourceOp op pg_attribute_unused void cluster_visibility_resolve_tuple_scn(Buffer buffer pg_attribute_unused(), - HeapTupleHeader tuple pg_attribute_unused(), - TransactionId raw_xid pg_attribute_unused(), - ClusterVisXidKind which pg_attribute_unused(), - SCN read_scn pg_attribute_unused(), - ClusterVisResolve *out) + HeapTupleHeader tuple pg_attribute_unused(), + TransactionId raw_xid pg_attribute_unused(), + ClusterVisXidKind which pg_attribute_unused(), + SCN read_scn pg_attribute_unused(), ClusterVisResolve *out) { ut_scratch_live_resolve_calls++; memset(out, 0, sizeof(*out)); @@ -828,8 +809,7 @@ cluster_visibility_resolve_tuple_scn(Buffer buffer pg_attribute_unused(), ClusterCrVerdict cluster_cr_satisfies_mvcc(HeapTuple htup pg_attribute_unused(), Snapshot snapshot pg_attribute_unused(), - Buffer buffer pg_attribute_unused(), - bool *visible pg_attribute_unused()) + Buffer buffer pg_attribute_unused(), bool *visible pg_attribute_unused()) { ut_scratch_cr_calls++; return CLUSTER_CR_FAILCLOSED; @@ -837,19 +817,17 @@ cluster_cr_satisfies_mvcc(HeapTuple htup pg_attribute_unused(), void cluster_heap_test_r4_conflict_out(bool visible pg_attribute_unused(), - Relation relation pg_attribute_unused(), - HeapTuple tuple pg_attribute_unused(), - Buffer buffer pg_attribute_unused(), - Snapshot snapshot pg_attribute_unused()) + Relation relation pg_attribute_unused(), + HeapTuple tuple pg_attribute_unused(), + Buffer buffer pg_attribute_unused(), + Snapshot snapshot pg_attribute_unused()) { ut_scratch_ssi_calls++; } void -PredicateLockTID(Relation relation pg_attribute_unused(), - ItemPointer tid pg_attribute_unused(), - Snapshot snapshot pg_attribute_unused(), - TransactionId xid pg_attribute_unused()) +PredicateLockTID(Relation relation pg_attribute_unused(), ItemPointer tid pg_attribute_unused(), + Snapshot snapshot pg_attribute_unused(), TransactionId xid pg_attribute_unused()) { ut_scratch_ssi_calls++; } @@ -866,8 +844,7 @@ cluster_heap_test_r4_live_visibility(HeapTuple tuple pg_attribute_unused(), void HeapTupleSetHintBits(HeapTupleHeader tuple pg_attribute_unused(), - Buffer buffer pg_attribute_unused(), - uint16 infomask pg_attribute_unused(), + Buffer buffer pg_attribute_unused(), uint16 infomask pg_attribute_unused(), TransactionId xid pg_attribute_unused()) { ut_scratch_hint_calls++; @@ -893,8 +870,7 @@ cluster_heap_test_r4_surely_dead(HeapTuple tuple pg_attribute_unused(), } int -GetMultiXactIdMembers(MultiXactId multi pg_attribute_unused(), - MultiXactMember **members, +GetMultiXactIdMembers(MultiXactId multi pg_attribute_unused(), MultiXactMember **members, bool from_pgupgrade pg_attribute_unused(), bool isLockOnly pg_attribute_unused()) { @@ -934,15 +910,12 @@ ClusterPcmOwnResult cluster_bufmgr_pcm_own_snapshot(BufferDesc *buf, ClusterPcmOwnSnapshot *out) { UT_ASSERT(ut_hot_current_mx_active || ut_itl_census_active); - if (ut_itl_pair_active) - { - int index = (int) (buf - &ut_buffer_descriptors[0].bufferdesc); + if (ut_itl_pair_active) { + int index = (int)(buf - &ut_buffer_descriptors[0].bufferdesc); UT_ASSERT(index >= 0 && index < 2); UT_ASSERT(ut_itl_pair_content_lock_held[index]); - } - else - { + } else { UT_ASSERT(ut_hot_content_lock_held); UT_ASSERT(buf == &ut_buffer_descriptors[0].bufferdesc); } @@ -950,47 +923,44 @@ cluster_bufmgr_pcm_own_snapshot(BufferDesc *buf, ClusterPcmOwnSnapshot *out) ut_hot_pcm_snapshot_calls++; memset(out, 0, sizeof(*out)); out->tag = ut_itl_census_tag; - out->generation - = (ut_itl_census_replace_current_page - || ut_itl_census_stale_first_round_full) - && ut_hot_pcm_snapshot_calls > 1 ? 18 : 17; + out->generation = (ut_itl_census_replace_current_page || ut_itl_census_stale_first_round_full) + && ut_hot_pcm_snapshot_calls > 1 + ? 18 + : 17; out->reservation_token = ut_itl_census_pcm_reservation_token; out->flags = ut_itl_census_pcm_flags; - if (ut_hot_current_mx_active && ut_hot_current_mx_one_shot) - { - UT_ASSERT_EQ(ut_hot_current_mx_pcm_state, - (uint8) PCM_STATE_READ_IMAGE); + if (ut_hot_current_mx_active && ut_hot_current_mx_one_shot) { + UT_ASSERT_EQ(ut_hot_current_mx_pcm_state, (uint8)PCM_STATE_READ_IMAGE); UT_ASSERT(ut_hot_current_read_bracket > 0); out->generation = 16 + ut_hot_current_read_bracket; out->reservation_token = ut_hot_current_read_bracket; } - if (ut_itl_census_second_round_drift - && ut_hot_pcm_snapshot_calls > 3) + if (ut_itl_census_second_round_drift && ut_hot_pcm_snapshot_calls > 3) out->generation = 19; out->writer_activation_token - = ut_itl_census_change_writer_activation_projection - && ut_hot_pcm_snapshot_calls > 1 ? UINT64_C(99) : 0; + = ut_itl_census_change_writer_activation_projection && ut_hot_pcm_snapshot_calls > 1 + ? UINT64_C(99) + : 0; if (ut_hot_current_mx_active) out->pcm_state = ut_hot_current_mx_pcm_state; else out->pcm_state = cluster_conf_has_peers() && !ut_itl_census_force_pcm_n - ? (uint8) PCM_STATE_X : (uint8) PCM_STATE_N; + ? (uint8)PCM_STATE_X + : (uint8)PCM_STATE_N; ut_hot_last_pcm_snapshot_state = out->pcm_state; return CLUSTER_PCM_OWN_OK; } ClusterBufmgrItlRecycleGuardResult -cluster_bufmgr_itl_recycle_guard_arm( - Buffer buffer, const ClusterPcmOwnSnapshot *expected) +cluster_bufmgr_itl_recycle_guard_arm(Buffer buffer, const ClusterPcmOwnSnapshot *expected) { - UT_ASSERT_EQ(buffer, (Buffer) 1); + UT_ASSERT_EQ(buffer, (Buffer)1); UT_ASSERT_NOT_NULL(expected); UT_ASSERT(ut_hot_content_lock_held); UT_ASSERT(!ut_itl_recycle_guard_active); - UT_ASSERT_EQ(expected->pcm_state, (uint8) PCM_STATE_X); + UT_ASSERT_EQ(expected->pcm_state, (uint8)PCM_STATE_X); ut_itl_recycle_guard_arm_calls++; - if (ut_itl_recycle_guard_arm_result - != CLUSTER_BUFMGR_ITL_RECYCLE_ARMED) + if (ut_itl_recycle_guard_arm_result != CLUSTER_BUFMGR_ITL_RECYCLE_ARMED) return ut_itl_recycle_guard_arm_result; ut_itl_recycle_guard_active = true; return CLUSTER_BUFMGR_ITL_RECYCLE_ARMED; @@ -999,7 +969,7 @@ cluster_bufmgr_itl_recycle_guard_arm( void cluster_bufmgr_itl_recycle_guard_unlock(Buffer buffer) { - UT_ASSERT_EQ(buffer, (Buffer) 1); + UT_ASSERT_EQ(buffer, (Buffer)1); UT_ASSERT(ut_itl_recycle_guard_active); UT_ASSERT(ut_hot_content_lock_held); ut_itl_recycle_guard_unlock_calls++; @@ -1009,7 +979,7 @@ cluster_bufmgr_itl_recycle_guard_unlock(Buffer buffer) bool cluster_bufmgr_itl_recycle_guard_relock(Buffer buffer) { - UT_ASSERT_EQ(buffer, (Buffer) 1); + UT_ASSERT_EQ(buffer, (Buffer)1); UT_ASSERT(ut_itl_recycle_guard_active); UT_ASSERT(!ut_hot_content_lock_held); ut_itl_recycle_guard_relock_calls++; @@ -1021,7 +991,7 @@ cluster_bufmgr_itl_recycle_guard_relock(Buffer buffer) void cluster_bufmgr_itl_recycle_guard_cancel(Buffer buffer) { - UT_ASSERT_EQ(buffer, (Buffer) 1); + UT_ASSERT_EQ(buffer, (Buffer)1); UT_ASSERT(ut_itl_recycle_guard_active); UT_ASSERT(!ut_hot_content_lock_held); ut_itl_recycle_guard_cancel_calls++; @@ -1029,35 +999,28 @@ cluster_bufmgr_itl_recycle_guard_cancel(Buffer buffer) } static bool -ut_itl_census_alloc(Buffer buf, TransactionId xid, - bool lock_only, uint8 *slot_index_out) +ut_itl_census_alloc(Buffer buf, TransactionId xid, bool lock_only, uint8 *slot_index_out) { ClusterItlSlotData *slots; uint8 i; UT_ASSERT(ut_itl_census_active); UT_ASSERT(ut_hot_content_lock_held); - UT_ASSERT_EQ(buf, (Buffer) 1); + UT_ASSERT_EQ(buf, (Buffer)1); UT_ASSERT_EQ(lock_only, ut_itl_census_lock_only); ut_itl_census_alloc_calls++; slots = ClusterPageGetItlSlots(BufferGetPage(buf)); - for (i = 0; i < CLUSTER_ITL_INITRANS_DEFAULT; i++) - { + for (i = 0; i < CLUSTER_ITL_INITRANS_DEFAULT; i++) { if (ut_itl_census_protected_history && (slots[i].flags == ITL_FLAG_COMMITTED || slots[i].flags == ITL_FLAG_ABORTED)) continue; - if (slots[i].flags == ITL_FLAG_FREE - || slots[i].flags == ITL_FLAG_COMMITTED - || slots[i].flags == ITL_FLAG_ABORTED - || slots[i].flags == ITL_FLAG_LOCK_ONLY_COMMITTED - || slots[i].flags == ITL_FLAG_LOCK_ONLY_ABORTED) - { + if (slots[i].flags == ITL_FLAG_FREE || slots[i].flags == ITL_FLAG_COMMITTED + || slots[i].flags == ITL_FLAG_ABORTED || slots[i].flags == ITL_FLAG_LOCK_ONLY_COMMITTED + || slots[i].flags == ITL_FLAG_LOCK_ONLY_ABORTED) { *slot_index_out = i; - if (ut_itl_census_consume_allocated_slot) - { + if (ut_itl_census_consume_allocated_slot) { slots[i].xid = xid; - slots[i].flags = lock_only - ? ITL_FLAG_LOCK_ONLY_ACTIVE : ITL_FLAG_ACTIVE; + slots[i].flags = lock_only ? ITL_FLAG_LOCK_ONLY_ACTIVE : ITL_FLAG_ACTIVE; slots[i].commit_scn = InvalidScn; } return true; @@ -1067,44 +1030,36 @@ ut_itl_census_alloc(Buffer buf, TransactionId xid, } bool -cluster_itl_alloc_or_reuse_slot(Buffer buf, TransactionId xid, - uint8 *slot_index_out) +cluster_itl_alloc_or_reuse_slot(Buffer buf, TransactionId xid, uint8 *slot_index_out) { return ut_itl_census_alloc(buf, xid, false, slot_index_out); } bool -cluster_itl_alloc_or_reuse_lock_slot(Buffer buf, TransactionId xid, - uint8 *slot_index_out) +cluster_itl_alloc_or_reuse_lock_slot(Buffer buf, TransactionId xid, uint8 *slot_index_out) { return ut_itl_census_alloc(buf, xid, true, slot_index_out); } bool -cluster_itl_has_allocatable_slot(Buffer buf, TransactionId xid, - bool lock_only) +cluster_itl_has_allocatable_slot(Buffer buf, TransactionId xid, bool lock_only) { ClusterItlSlotData *slots; uint8 i; UT_ASSERT(ut_itl_census_active); UT_ASSERT(ut_itl_pair_active ? ut_itl_pair_content_lock_held[0] : ut_hot_content_lock_held); - UT_ASSERT_EQ(buf, (Buffer) 1); + UT_ASSERT_EQ(buf, (Buffer)1); ut_itl_census_capacity_calls++; slots = ClusterPageGetItlSlots(BufferGetPage(buf)); - for (i = 0; i < CLUSTER_ITL_INITRANS_DEFAULT; i++) - { + for (i = 0; i < CLUSTER_ITL_INITRANS_DEFAULT; i++) { if (ut_itl_census_protected_history && (slots[i].flags == ITL_FLAG_COMMITTED || slots[i].flags == ITL_FLAG_ABORTED)) continue; - if ((!lock_only && slots[i].flags == ITL_FLAG_ACTIVE - && slots[i].xid == xid) - || (lock_only && slots[i].flags == ITL_FLAG_LOCK_ONLY_ACTIVE - && slots[i].xid == xid) - || slots[i].flags == ITL_FLAG_FREE - || slots[i].flags == ITL_FLAG_COMMITTED - || slots[i].flags == ITL_FLAG_ABORTED - || slots[i].flags == ITL_FLAG_LOCK_ONLY_COMMITTED + if ((!lock_only && slots[i].flags == ITL_FLAG_ACTIVE && slots[i].xid == xid) + || (lock_only && slots[i].flags == ITL_FLAG_LOCK_ONLY_ACTIVE && slots[i].xid == xid) + || slots[i].flags == ITL_FLAG_FREE || slots[i].flags == ITL_FLAG_COMMITTED + || slots[i].flags == ITL_FLAG_ABORTED || slots[i].flags == ITL_FLAG_LOCK_ONLY_COMMITTED || slots[i].flags == ITL_FLAG_LOCK_ONLY_ABORTED) return true; } @@ -1112,8 +1067,7 @@ cluster_itl_has_allocatable_slot(Buffer buf, TransactionId xid, } bool -cluster_tx_locator_from_itl(Page page, uint8 slot_index, - ClusterTxLocator *out, +cluster_tx_locator_from_itl(Page page, uint8 slot_index, ClusterTxLocator *out, ClusterTxResolveReason *reason_out) { ClusterItlSlotData *slot = &ClusterPageGetItlSlots(page)[slot_index]; @@ -1129,9 +1083,8 @@ cluster_tx_locator_from_itl(Page page, uint8 slot_index, } bool -cluster_tx_locator_from_itl_terminal_census( - Page page, uint8 slot_index, ClusterTxLocator *out, - ClusterTxResolveReason *reason_out) +cluster_tx_locator_from_itl_terminal_census(Page page, uint8 slot_index, ClusterTxLocator *out, + ClusterTxResolveReason *reason_out) { if (!cluster_tx_locator_from_itl(page, slot_index, out, reason_out)) return false; @@ -1141,9 +1094,8 @@ cluster_tx_locator_from_itl_terminal_census( bool cluster_multixact_current_successor_provenance_well_formed( - const ClusterCurrentMxSuccessorAlias *alias, - const ClusterTxLocator *locator, TransactionId updater_xid, - uint16 updater_origin_node, uint32 current_epoch) + const ClusterCurrentMxSuccessorAlias *alias, const ClusterTxLocator *locator, + TransactionId updater_xid, uint16 updater_origin_node, uint32 current_epoch) { uint32 segment_id; uint32 block_no; @@ -1151,15 +1103,12 @@ cluster_multixact_current_successor_provenance_well_formed( uint16 row_offset; return alias != NULL && locator != NULL - && uba_decode(locator->uba, &segment_id, &block_no, &slot_offset, - &row_offset) - && alias->origin_node_id == updater_origin_node - && alias->undo_record_segment_id == segment_id - && alias->tt_slot_id == (uint32)slot_offset + 1 - && alias->cluster_epoch == current_epoch - && alias->local_xid == updater_xid - && locator->xid == updater_xid - && locator->tt_wrap == TT_WRAP_INVALID; + && uba_decode(locator->uba, &segment_id, &block_no, &slot_offset, &row_offset) + && alias->origin_node_id == updater_origin_node + && alias->undo_record_segment_id == segment_id + && alias->tt_slot_id == (uint32)slot_offset + 1 && alias->cluster_epoch == current_epoch + && alias->local_xid == updater_xid && locator->xid == updater_xid + && locator->tt_wrap == TT_WRAP_INVALID; } static ClusterTxOutcome ut_itl_resolve_fixture(const ClusterTxLocator *locator, @@ -1169,10 +1118,8 @@ static ClusterTxOutcome ut_itl_resolve_fixture(const ClusterTxLocator *locator, ClusterTxResolveReason *reason_out); ClusterTxOutcome -cluster_tx_resolve_exact(const ClusterTxLocator *locator, - ClusterTxResolveMode mode, - ClusterTxResolution *out, - ClusterTxResolveReason *reason_out) +cluster_tx_resolve_exact(const ClusterTxLocator *locator, ClusterTxResolveMode mode, + ClusterTxResolution *out, ClusterTxResolveReason *reason_out) { ClusterTxOutcome outcome; @@ -1229,8 +1176,7 @@ cluster_tx_resolve_terminal_census_batch_preflight(void) UT_ASSERT(ut_itl_census_active); UT_ASSERT(!ut_hot_content_lock_held); UT_ASSERT_EQ(ut_itl_census_resolve_calls, - ut_itl_census_preflight_calls - * CLUSTER_ITL_INITRANS_DEFAULT); + ut_itl_census_preflight_calls * CLUSTER_ITL_INITRANS_DEFAULT); ut_itl_census_preflight_calls++; } @@ -1252,35 +1198,26 @@ ut_itl_resolve_fixture(const ClusterTxLocator *locator, ClusterTxResolveMode mod UT_ASSERT(admission == ut_itl_census_admission); } else UT_ASSERT_EQ(mode, CLUSTER_TX_RESOLVE_VISIBILITY); - UT_ASSERT_EQ(pg_atomic_read_u32( - &ut_itl_census_semantic.inflight[CLUSTER_SEMANTIC_TARGET_SIDE][0]), 1); - UT_ASSERT_EQ(semantic_activation_local_inflight - [CLUSTER_SEMANTIC_TARGET_SIDE][0], 1); - if (ut_itl_pair_active) - { + UT_ASSERT_EQ( + pg_atomic_read_u32(&ut_itl_census_semantic.inflight[CLUSTER_SEMANTIC_TARGET_SIDE][0]), 1); + UT_ASSERT_EQ(semantic_activation_local_inflight[CLUSTER_SEMANTIC_TARGET_SIDE][0], 1); + if (ut_itl_pair_active) { UT_ASSERT(!ut_itl_pair_content_lock_held[0]); UT_ASSERT(!ut_itl_pair_content_lock_held[1]); - } - else + } else UT_ASSERT(!ut_hot_content_lock_held); UT_ASSERT(locator->itl_slot_index < CLUSTER_ITL_INITRANS_DEFAULT); UT_ASSERT_EQ(locator->tt_wrap, TT_WRAP_INVALID); if (ut_itl_census_mutate_wrap && ut_itl_census_resolve_calls == 0) - ClusterPageGetItlSlots(BufferGetPage((Buffer) 1))[0].wrap++; - if (ut_itl_census_mutate_activation - && ut_itl_census_resolve_calls == 0) - pg_atomic_write_u64(&ut_itl_census_semantic.record_generation, - UINT64_C(74)); - if (ut_itl_census_replace_current_page - && ut_itl_census_resolve_calls == 0) - { - ClusterItlSlotData *current_slots = ClusterPageGetItlSlots( - BufferGetPage((Buffer) 1)); + ClusterPageGetItlSlots(BufferGetPage((Buffer)1))[0].wrap++; + if (ut_itl_census_mutate_activation && ut_itl_census_resolve_calls == 0) + pg_atomic_write_u64(&ut_itl_census_semantic.record_generation, UINT64_C(74)); + if (ut_itl_census_replace_current_page && ut_itl_census_resolve_calls == 0) { + ClusterItlSlotData *current_slots = ClusterPageGetItlSlots(BufferGetPage((Buffer)1)); current_slots[4].flags = ITL_FLAG_COMMITTED; - current_slots[4].commit_scn = (SCN) 8001; - PageSetLSN(BufferGetPage((Buffer) 1), - (XLogRecPtr) UINT64_C(0x334456)); + current_slots[4].commit_scn = (SCN)8001; + PageSetLSN(BufferGetPage((Buffer)1), (XLogRecPtr)UINT64_C(0x334456)); if (ut_itl_census_change_page_geometry) { Page page = BufferGetPage((Buffer)1); PageHeader header = (PageHeader)page; @@ -1290,48 +1227,35 @@ ut_itl_resolve_fixture(const ClusterTxLocator *locator, ClusterTxResolveMode mod ItemIdSetUnused(PageGetItemId(page, PageGetMaxOffsetNumber(page))); } } - if (ut_itl_census_stale_first_round_full - && ut_itl_census_resolve_calls == 0) - { - ClusterItlSlotData *current_slots = ClusterPageGetItlSlots( - BufferGetPage((Buffer) 1)); + if (ut_itl_census_stale_first_round_full && ut_itl_census_resolve_calls == 0) { + ClusterItlSlotData *current_slots = ClusterPageGetItlSlots(BufferGetPage((Buffer)1)); - current_slots[0].xid = (TransactionId) 1400; - current_slots[0].wrap = (uint16) 40; + current_slots[0].xid = (TransactionId)1400; + current_slots[0].wrap = (uint16)40; current_slots[0].undo_segment_head = uba_encode(1, 40, 0, 0); - PageSetLSN(BufferGetPage((Buffer) 1), - (XLogRecPtr) UINT64_C(0x334456)); - } - else if (ut_itl_census_stale_first_round_full - && ut_itl_census_resolve_calls - == CLUSTER_ITL_INITRANS_DEFAULT) - { + PageSetLSN(BufferGetPage((Buffer)1), (XLogRecPtr)UINT64_C(0x334456)); + } else if (ut_itl_census_stale_first_round_full + && ut_itl_census_resolve_calls == CLUSTER_ITL_INITRANS_DEFAULT) { UBA expected_uba = uba_encode(1, 40, 0, 0); - UT_ASSERT_EQ(locator->xid, (TransactionId) 1400); + UT_ASSERT_EQ(locator->xid, (TransactionId)1400); UT_ASSERT_EQ(locator->uba.raw[0], expected_uba.raw[0]); UT_ASSERT_EQ(locator->uba.raw[1], expected_uba.raw[1]); ut_itl_census_second_round_fresh_locator_seen = true; - if (ut_itl_census_second_round_drift) - { - ClusterItlSlotData *current_slots = ClusterPageGetItlSlots( - BufferGetPage((Buffer) 1)); + if (ut_itl_census_second_round_drift) { + ClusterItlSlotData *current_slots = ClusterPageGetItlSlots(BufferGetPage((Buffer)1)); current_slots[1].wrap++; - PageSetLSN(BufferGetPage((Buffer) 1), - (XLogRecPtr) UINT64_C(0x334457)); + PageSetLSN(BufferGetPage((Buffer)1), (XLogRecPtr)UINT64_C(0x334457)); } } if (ut_itl_census_mutate_second_terminal_after_full_resolve - && !ut_itl_census_second_terminal_mutated - && ut_itl_census_resolve_calls == 7) - { - ClusterItlSlotData *current_slots = ClusterPageGetItlSlots( - BufferGetPage((Buffer) 1)); + && !ut_itl_census_second_terminal_mutated && ut_itl_census_resolve_calls == 7) { + ClusterItlSlotData *current_slots = ClusterPageGetItlSlots(BufferGetPage((Buffer)1)); current_slots[1].wrap++; current_slots[4].flags = ITL_FLAG_COMMITTED; - current_slots[4].commit_scn = (SCN) 8001; + current_slots[4].commit_scn = (SCN)8001; ut_itl_census_second_terminal_mutated = true; } ut_itl_census_resolve_calls++; @@ -1342,14 +1266,13 @@ ut_itl_resolve_fixture(const ClusterTxLocator *locator, ClusterTxResolveMode mod out->top_xid = locator->xid; out->outcome = outcome; out->proof_kind = CLUSTER_TX_PROOF_ORIGIN_DURABLE_TT_CLOG; - out->commit_scn = outcome == CLUSTER_TX_COMMITTED ? (SCN) 9001 : InvalidScn; + out->commit_scn = outcome == CLUSTER_TX_COMMITTED ? (SCN)9001 : InvalidScn; out->authority.origin_epoch = UINT32_C(9); - out->authority.live_hwm_lsn = (XLogRecPtr) 1; + out->authority.live_hwm_lsn = (XLogRecPtr)1; out->authority.tt_generation = ut_itl_census_origin_tt_generation; - out->authority.authority_scn = (SCN) 9002; - *reason_out = outcome == CLUSTER_TX_UNKNOWN - ? CLUSTER_TX_RESOLVE_AUTHORITY_UNAVAILABLE - : CLUSTER_TX_RESOLVE_NONE; + out->authority.authority_scn = (SCN)9002; + *reason_out = outcome == CLUSTER_TX_UNKNOWN ? CLUSTER_TX_RESOLVE_AUTHORITY_UNAVAILABLE + : CLUSTER_TX_RESOLVE_NONE; return outcome; } @@ -1362,17 +1285,17 @@ cluster_tx_resolve_exact_admitted(const ClusterTxLocator *locator, ClusterTxReso } ClusterTxOutcome -cluster_tx_resolve_terminal_census_retained_admitted( - const ClusterTxLocator *locator, SCN retained_commit_scn, - const ClusterSemanticAdmissionToken *admission, ClusterTxResolution *out, - ClusterTxResolveReason *reason_out) +cluster_tx_resolve_terminal_census_retained_admitted(const ClusterTxLocator *locator, + SCN retained_commit_scn, + const ClusterSemanticAdmissionToken *admission, + ClusterTxResolution *out, + ClusterTxResolveReason *reason_out) { UT_ASSERT_EQ(locator->itl_kind, ITL_FLAG_NEEDS_CLEANOUT); UT_ASSERT(SCN_VALID(retained_commit_scn)); ut_itl_census_retained_resolve_calls++; - return cluster_tx_resolve_exact_admitted( - locator, CLUSTER_TX_RESOLVE_TERMINAL_CENSUS, admission, out, - reason_out); + return cluster_tx_resolve_exact_admitted(locator, CLUSTER_TX_RESOLVE_TERMINAL_CENSUS, admission, + out, reason_out); } uint64 @@ -1390,7 +1313,7 @@ cluster_ctrc_shmem_ready(void) void MarkBufferDirtyHint(Buffer buffer, bool buffer_std pg_attribute_unused()) { - UT_ASSERT_EQ(buffer, (Buffer) 1); + UT_ASSERT_EQ(buffer, (Buffer)1); UT_ASSERT(ut_hot_content_lock_held); ut_itl_census_dirty_hint_calls++; } @@ -1406,20 +1329,14 @@ cluster_multixact_current_descriptor_hash(const ClusterCurrentMxKey *key, UT_ASSERT_EQ(key->multixact_id, UT_HOT_FOREIGN_MXID); UT_ASSERT_EQ(key->cluster_epoch, UT_HOT_CURRENT_EPOCH); UT_ASSERT_EQ(nmembers, ut_hot_current_mx_member_count); - if (ut_current_mx_ordinary_lock_only) - { + if (ut_current_mx_ordinary_lock_only) { UT_ASSERT_EQ(nmembers, 1); UT_ASSERT_EQ(members[0].xid, UT_ORDINARY_LOCKER); - UT_ASSERT_EQ(members[0].member_status, - MultiXactStatusForKeyShare); - } - else if (nmembers == 1) - { + UT_ASSERT_EQ(members[0].member_status, MultiXactStatusForKeyShare); + } else if (nmembers == 1) { UT_ASSERT_EQ(members[0].xid, UT_HOT_AUTH_UPDATER); UT_ASSERT_EQ(members[0].member_status, MultiXactStatusUpdate); - } - else - { + } else { UT_ASSERT_EQ(nmembers, 2); UT_ASSERT_EQ(members[0].member_status, MultiXactStatusForShare); UT_ASSERT_EQ(members[1].xid, UT_HOT_AUTH_UPDATER); @@ -1429,10 +1346,10 @@ cluster_multixact_current_descriptor_hash(const ClusterCurrentMxKey *key, } ClusterMxDescribeResult -cluster_multixact_current_validate_descriptor( - const ClusterCurrentMxKey *key, uint16 source_node_id, uint32 current_epoch, - const ClusterCurrentMxMemberDesc *members, uint16 nmembers, - uint32 reported_total_members) +cluster_multixact_current_validate_descriptor(const ClusterCurrentMxKey *key, uint16 source_node_id, + uint32 current_epoch, + const ClusterCurrentMxMemberDesc *members, + uint16 nmembers, uint32 reported_total_members) { UT_ASSERT_NOT_NULL(key); UT_ASSERT_NOT_NULL(members); @@ -1440,26 +1357,20 @@ cluster_multixact_current_validate_descriptor( UT_ASSERT_EQ(current_epoch, UT_HOT_CURRENT_EPOCH); UT_ASSERT_EQ(nmembers, ut_hot_current_mx_member_count); UT_ASSERT_EQ(reported_total_members, nmembers); - if (ut_current_mx_ordinary_lock_only) - { + if (ut_current_mx_ordinary_lock_only) { UT_ASSERT_EQ(members[0].xid, UT_ORDINARY_LOCKER); - UT_ASSERT_EQ(members[0].member_status, - MultiXactStatusForKeyShare); - } - else - { + UT_ASSERT_EQ(members[0].member_status, MultiXactStatusForKeyShare); + } else { UT_ASSERT_EQ(members[nmembers - 1].xid, UT_HOT_AUTH_UPDATER); - UT_ASSERT_EQ(members[nmembers - 1].member_status, - MultiXactStatusUpdate); + UT_ASSERT_EQ(members[nmembers - 1].member_status, MultiXactStatusUpdate); } return CMX_DESC_OK; } ClusterMxDescribeResult cluster_multixact_current_describe(const ClusterCurrentMxKey *key, - ClusterCurrentMxMemberDesc *members, - uint16 members_cap, uint16 *nmembers, - uint32 *reported_total_members) + ClusterCurrentMxMemberDesc *members, uint16 members_cap, + uint16 *nmembers, uint32 *reported_total_members) { UT_ASSERT(ut_hot_current_mx_active); UT_ASSERT(!ut_hot_content_lock_held); @@ -1470,21 +1381,16 @@ cluster_multixact_current_describe(const ClusterCurrentMxKey *key, UT_ASSERT_EQ(key->cluster_epoch, UT_HOT_CURRENT_EPOCH); ut_hot_current_mx_describe_calls++; memset(members, 0, sizeof(*members) * members_cap); - if (ut_current_mx_ordinary_lock_only) - { + if (ut_current_mx_ordinary_lock_only) { UT_ASSERT_EQ(ut_hot_current_mx_member_count, 1); members[0].xid = UT_ORDINARY_LOCKER; members[0].member_status = MultiXactStatusForKeyShare; - } - else if (ut_hot_current_mx_member_count == 1) - { + } else if (ut_hot_current_mx_member_count == 1) { members[0].xid = UT_HOT_AUTH_UPDATER; members[0].member_status = MultiXactStatusUpdate; - } - else - { + } else { UT_ASSERT_EQ(ut_hot_current_mx_member_count, 2); - members[0].xid = (TransactionId) 897; + members[0].xid = (TransactionId)897; members[0].member_status = MultiXactStatusForShare; members[1].xid = UT_HOT_AUTH_UPDATER; members[1].member_status = MultiXactStatusUpdate; @@ -1510,13 +1416,11 @@ cluster_multixact_current_members_resolve(const ClusterCurrentMxKey *key, UT_ASSERT(!ut_hot_content_lock_held); UT_ASSERT_EQ(nmembers, ut_hot_current_mx_member_count); UT_ASSERT_EQ(descriptor_hash, UT_HOT_CURRENT_MX_HASH); - if (ut_current_mx_ordinary_lock_only) - { + if (ut_current_mx_ordinary_lock_only) { UT_ASSERT(challenge == NULL); UT_ASSERT_EQ(nmembers, 1); UT_ASSERT_EQ(members[0].xid, UT_ORDINARY_LOCKER); - UT_ASSERT_EQ(members[0].member_status, - MultiXactStatusForKeyShare); + UT_ASSERT_EQ(members[0].member_status, MultiXactStatusForKeyShare); ut_hot_current_mx_resolve_calls++; memset(proofs, 0, sizeof(*proofs)); proofs[0].member_xid = members[0].xid; @@ -1534,35 +1438,28 @@ cluster_multixact_current_members_resolve(const ClusterCurrentMxKey *key, } UT_ASSERT_EQ(challenge->updater_xid, UT_HOT_AUTH_UPDATER); UT_ASSERT_EQ(challenge->member_ordinal, updater_ordinal); - UT_ASSERT_EQ(challenge->candidate_next_xmin_alias.origin_node_id, - UT_HOT_CURRENT_MX_ORIGIN); + UT_ASSERT_EQ(challenge->candidate_next_xmin_alias.origin_node_id, UT_HOT_CURRENT_MX_ORIGIN); UT_ASSERT_EQ(challenge->candidate_next_xmin_alias.undo_record_segment_id, ut_hot_successor_ref.undo_segment_id); - UT_ASSERT_EQ(challenge->candidate_next_xmin_alias.tt_slot_id, - ut_hot_successor_ref.tt_slot_id); - UT_ASSERT_EQ(challenge->candidate_next_xmin_alias.cluster_epoch, - UT_HOT_CURRENT_EPOCH); - UT_ASSERT_EQ(challenge->candidate_next_xmin_alias.local_xid, - UT_HOT_AUTH_UPDATER); + UT_ASSERT_EQ(challenge->candidate_next_xmin_alias.tt_slot_id, ut_hot_successor_ref.tt_slot_id); + UT_ASSERT_EQ(challenge->candidate_next_xmin_alias.cluster_epoch, UT_HOT_CURRENT_EPOCH); + UT_ASSERT_EQ(challenge->candidate_next_xmin_alias.local_xid, UT_HOT_AUTH_UPDATER); ut_hot_current_mx_resolve_calls++; UT_ASSERT_NOT_NULL(proof_capability_generations); memset(proofs, 0, sizeof(*proofs) * nmembers); - for (i = 0; i < nmembers; i++) - { + for (i = 0; i < nmembers; i++) { proof_capability_generations[i] = 41; proofs[i].member_xid = members[i].xid; proofs[i].member_ordinal = i; proofs[i].member_status = members[i].member_status; proofs[i].state = i == updater_ordinal ? CCM_COMMITTED : CCM_ACTIVE; if (i == updater_ordinal) - proofs[i].commit_scn = (SCN) 101; + proofs[i].commit_scn = (SCN)101; } memset(updater_proof, 0, sizeof(*updater_proof)); updater_proof->mxkey = *key; - updater_proof->candidate_next_xmin_alias - = challenge->candidate_next_xmin_alias; - updater_proof->candidate_next_xmin_locator - = challenge->candidate_next_xmin_locator; + updater_proof->candidate_next_xmin_alias = challenge->candidate_next_xmin_alias; + updater_proof->candidate_next_xmin_locator = challenge->candidate_next_xmin_locator; /* The origin's exact undo record supplies the canonical TT wrap; make it * deliberately distinct from the page ITL wrap in this fixture. */ updater_proof->candidate_next_xmin_locator.tt_wrap = 42; @@ -1574,33 +1471,29 @@ cluster_multixact_current_members_resolve(const ClusterCurrentMxKey *key, ClusterMxResolveResult cluster_multixact_current_members_resolve_until( - const ClusterCurrentMxKey *key, - const ClusterCurrentMxMemberDesc *members, - uint16 nmembers, uint64 descriptor_hash, - const ClusterCurrentUpdaterChallenge *challenge, - ClusterCurrentMemberProof *proofs, - ClusterCurrentUpdaterProof *updater_proof, - uint32 *proof_capability_generations, - TimestampTz *operation_deadline) + const ClusterCurrentMxKey *key, const ClusterCurrentMxMemberDesc *members, uint16 nmembers, + uint64 descriptor_hash, const ClusterCurrentUpdaterChallenge *challenge, + ClusterCurrentMemberProof *proofs, ClusterCurrentUpdaterProof *updater_proof, + uint32 *proof_capability_generations, TimestampTz *operation_deadline) { UT_ASSERT_NOT_NULL(operation_deadline); if (*operation_deadline == 0) - *operation_deadline = (TimestampTz) UINT64_C(123456789); + *operation_deadline = (TimestampTz)UINT64_C(123456789); else - UT_ASSERT_EQ(*operation_deadline, - (TimestampTz) UINT64_C(123456789)); - return cluster_multixact_current_members_resolve( - key, members, nmembers, descriptor_hash, challenge, proofs, - updater_proof, proof_capability_generations); + UT_ASSERT_EQ(*operation_deadline, (TimestampTz)UINT64_C(123456789)); + return cluster_multixact_current_members_resolve(key, members, nmembers, descriptor_hash, + challenge, proofs, updater_proof, + proof_capability_generations); } bool -cluster_multixact_current_validate_updater_proof( - const ClusterCurrentMxKey *key, const ClusterCurrentMxMemberDesc *members, - const ClusterCurrentMemberProof *proofs, uint16 nmembers, - const ClusterCurrentUpdaterChallenge *challenge, - const ClusterCurrentUpdaterProof *updater_proof, - uint16 updater_origin_node_id) +cluster_multixact_current_validate_updater_proof(const ClusterCurrentMxKey *key, + const ClusterCurrentMxMemberDesc *members, + const ClusterCurrentMemberProof *proofs, + uint16 nmembers, + const ClusterCurrentUpdaterChallenge *challenge, + const ClusterCurrentUpdaterProof *updater_proof, + uint16 updater_origin_node_id) { uint16 updater_ordinal = ut_hot_current_mx_member_count - 1; @@ -1614,26 +1507,24 @@ cluster_multixact_current_validate_updater_proof( UT_ASSERT_EQ(updater_proof->verdict, CUCP_MATCH); UT_ASSERT(memcmp(key, &updater_proof->mxkey, sizeof(*key)) == 0); UT_ASSERT(memcmp(&challenge->candidate_next_xmin_alias, - &updater_proof->candidate_next_xmin_alias, - sizeof(ClusterCurrentMxSuccessorAlias)) == 0); - UT_ASSERT_EQ(challenge->candidate_next_xmin_locator.tt_wrap, - TT_WRAP_INVALID); + &updater_proof->candidate_next_xmin_alias, + sizeof(ClusterCurrentMxSuccessorAlias)) + == 0); + UT_ASSERT_EQ(challenge->candidate_next_xmin_locator.tt_wrap, TT_WRAP_INVALID); UT_ASSERT_EQ(updater_proof->candidate_next_xmin_locator.tt_wrap, 42); - UT_ASSERT(cluster_tx_locator_reply_matches( - &challenge->candidate_next_xmin_locator, - &updater_proof->candidate_next_xmin_locator)); + UT_ASSERT(cluster_tx_locator_reply_matches(&challenge->candidate_next_xmin_locator, + &updater_proof->candidate_next_xmin_locator)); ut_hot_current_mx_validate_calls++; return true; } ClusterCurrentMxDecision -cluster_multixact_current_decide( - const ClusterCurrentMxMemberDesc *members, - const ClusterCurrentMemberProof *proofs, uint16 nmembers, - const ClusterCurrentMxRequestContext *ctx, - const ClusterCurrentUpdaterChallenge *challenge, - const ClusterCurrentUpdaterProof *updater_proof, - ClusterTTStatusKey *wait_key) +cluster_multixact_current_decide(const ClusterCurrentMxMemberDesc *members, + const ClusterCurrentMemberProof *proofs, uint16 nmembers, + const ClusterCurrentMxRequestContext *ctx, + const ClusterCurrentUpdaterChallenge *challenge, + const ClusterCurrentUpdaterProof *updater_proof, + ClusterTTStatusKey *wait_key) { UT_ASSERT(ut_current_mx_ordinary_lock_only); UT_ASSERT_EQ(nmembers, 1); @@ -1654,38 +1545,36 @@ cluster_multixact_current_decide( } ClusterCurrentMxDecision -cluster_multixact_current_decide_observed( - const ClusterCurrentMxMemberDesc *members, - const ClusterCurrentMemberProof *proofs, uint16 nmembers, - const ClusterCurrentMxRequestContext *ctx, - const ClusterCurrentUpdaterChallenge *challenge, - const ClusterCurrentUpdaterProof *updater_proof, - ClusterTTStatusKey *wait_key, ClusterCurrentMxDecisionTrace *trace) +cluster_multixact_current_decide_observed(const ClusterCurrentMxMemberDesc *members, + const ClusterCurrentMemberProof *proofs, uint16 nmembers, + const ClusterCurrentMxRequestContext *ctx, + const ClusterCurrentUpdaterChallenge *challenge, + const ClusterCurrentUpdaterProof *updater_proof, + ClusterTTStatusKey *wait_key, + ClusterCurrentMxDecisionTrace *trace) { if (trace != NULL) { trace->unknown_reason = CMX_UNKNOWN_NONE; trace->member_ordinal = -1; } - return cluster_multixact_current_decide(members, proofs, nmembers, ctx, - challenge, updater_proof, wait_key); + return cluster_multixact_current_decide(members, proofs, nmembers, ctx, challenge, + updater_proof, wait_key); } ClusterUndoRecordConsumePreflightResult -cluster_undo_record_consume_preflight(ClusterUndoRecordPrepareReceipt *receipt, - uint16 payload_len) +cluster_undo_record_consume_preflight(ClusterUndoRecordPrepareReceipt *receipt, uint16 payload_len) { - (void) receipt; - (void) payload_len; + (void)receipt; + (void)payload_len; return CLUSTER_UNDO_RECORD_CONSUME_PREFLIGHT_READY; } ClusterMxRecomposeResult -cluster_multixact_current_recompose( - const ClusterCurrentMxMemberDesc *members, - const ClusterCurrentMemberProof *proofs, uint16 nmembers, - TransactionId requester_xid, MultiXactStatus requester_status, - MultiXactMember *normalized_members, uint16 normalized_cap, - uint16 *normalized_count) +cluster_multixact_current_recompose(const ClusterCurrentMxMemberDesc *members, + const ClusterCurrentMemberProof *proofs, uint16 nmembers, + TransactionId requester_xid, MultiXactStatus requester_status, + MultiXactMember *normalized_members, uint16 normalized_cap, + uint16 *normalized_count) { UT_ASSERT(ut_current_mx_ordinary_lock_only); UT_ASSERT_EQ(nmembers, 1); @@ -1695,7 +1584,7 @@ cluster_multixact_current_recompose( UT_ASSERT(normalized_cap >= 2); UT_ASSERT_NOT_NULL(normalized_count); normalized_members[0].xid = members[0].xid; - normalized_members[0].status = (MultiXactStatus) members[0].member_status; + normalized_members[0].status = (MultiXactStatus)members[0].member_status; normalized_members[1].xid = requester_xid; normalized_members[1].status = requester_status; *normalized_count = 2; @@ -1755,14 +1644,11 @@ MemoryContextAllocZeroAligned(MemoryContext context pg_attribute_unused(), Size void pfree(void *pointer) { - if (pointer != NULL) - { + if (pointer != NULL) { int i; - for (i = 0; i < ut_alloc_calls; i++) - { - if (ut_allocations[i] == pointer) - { + for (i = 0; i < ut_alloc_calls; i++) { + if (ut_allocations[i] == pointer) { ut_allocations[i] = NULL; ut_free_calls++; free(pointer); @@ -1813,38 +1699,31 @@ EOH_get_flat_size(ExpandedObjectHeader *eohptr pg_attribute_unused()) void EOH_flatten_into(ExpandedObjectHeader *eohptr pg_attribute_unused(), - void *result pg_attribute_unused(), - Size allocated_size pg_attribute_unused()) + void *result pg_attribute_unused(), Size allocated_size pg_attribute_unused()) {} Datum -datumCopy(Datum value, bool typByVal pg_attribute_unused(), - int typLen pg_attribute_unused()) +datumCopy(Datum value, bool typByVal pg_attribute_unused(), int typLen pg_attribute_unused()) { return value; } uint32 -hash_bytes(const unsigned char *key pg_attribute_unused(), - int keylen pg_attribute_unused()) +hash_bytes(const unsigned char *key pg_attribute_unused(), int keylen pg_attribute_unused()) { return 0; } HTAB * -hash_create(const char *tabname pg_attribute_unused(), - long nelem pg_attribute_unused(), - const HASHCTL *info pg_attribute_unused(), - int flags pg_attribute_unused()) +hash_create(const char *tabname pg_attribute_unused(), long nelem pg_attribute_unused(), + const HASHCTL *info pg_attribute_unused(), int flags pg_attribute_unused()) { return NULL; } void * -hash_search(HTAB *hashp pg_attribute_unused(), - const void *keyPtr pg_attribute_unused(), - HASHACTION action pg_attribute_unused(), - bool *foundPtr pg_attribute_unused()) +hash_search(HTAB *hashp pg_attribute_unused(), const void *keyPtr pg_attribute_unused(), + HASHACTION action pg_attribute_unused(), bool *foundPtr pg_attribute_unused()) { return NULL; } @@ -2037,7 +1916,7 @@ UT_TEST(test_32_qvotec_completion_never_enters_origin_data) #define UT_HOT_BUFFER_HEADER UINT32_C(0x02) #define UT_HOT_GRD UINT32_C(0x04) #define UT_HOT_SLRU UINT32_C(0x08) -#define UT_HOT_FORBIDDEN_LOCKS \ +#define UT_HOT_FORBIDDEN_LOCKS \ (UT_HOT_CONTENT_SHARE | UT_HOT_BUFFER_HEADER | UT_HOT_GRD | UT_HOT_SLRU) #define UT_HOT_BUFFER 1 #define UT_HOT_LIVE_XMIN ((TransactionId)900) @@ -2064,8 +1943,7 @@ typedef struct UtR4HotLifecycleFixture { int relock_calls; } UtR4HotLifecycleFixture; -typedef struct UtR4HotProductFixture -{ +typedef struct UtR4HotProductFixture { char live_page[BLCKSZ] pg_attribute_aligned(MAXIMUM_ALIGNOF); char full_source[BLCKSZ] pg_attribute_aligned(MAXIMUM_ALIGNOF); BufferTag expected_tag; @@ -2356,8 +2234,7 @@ cluster_ctrc_test_barrier_wait(ClusterCtrcTestBarrierPhase phase) UT_ASSERT_EQ(ut_hot_current_mx_resolve_calls, 1); UT_ASSERT_NOT_NULL(ut_hot_product_fixture); ut_hot_requester_requalify_barrier_calls++; - ut_hot_requester_requalify_barrier_lock_calls - = ut_hot_product_fixture->lock_calls; + ut_hot_requester_requalify_barrier_lock_calls = ut_hot_product_fixture->lock_calls; } static HeapTupleHeader ut_r4_hot_tuple_at(Page page, OffsetNumber offnum); @@ -2371,8 +2248,7 @@ BufferGetBlockNumber(Buffer buffer) } void -BufferGetTag(Buffer buffer, RelFileLocator *rlocator, - ForkNumber *forknum, BlockNumber *blocknum) +BufferGetTag(Buffer buffer, RelFileLocator *rlocator, ForkNumber *forknum, BlockNumber *blocknum) { UT_ASSERT_EQ(buffer, UT_HOT_BUFFER); UT_ASSERT_NOT_NULL(ut_hot_product_fixture); @@ -2391,16 +2267,14 @@ LockBuffer(Buffer buffer, int mode) UT_ASSERT_NOT_NULL(fixture); if (fixture == NULL) return; - if (ut_itl_pair_active) - { + if (ut_itl_pair_active) { int index; - UT_ASSERT(buffer == (Buffer) 1 || buffer == (Buffer) 2); + UT_ASSERT(buffer == (Buffer)1 || buffer == (Buffer)2); index = buffer - 1; UT_ASSERT_EQ(mode, BUFFER_LOCK_UNLOCK); UT_ASSERT(ut_itl_pair_content_lock_held[index]); - UT_ASSERT(ut_itl_pair_lock_calls - < lengthof(ut_itl_pair_lock_buffers)); + UT_ASSERT(ut_itl_pair_lock_calls < lengthof(ut_itl_pair_lock_buffers)); ut_itl_pair_content_lock_held[index] = false; ut_itl_pair_lock_buffers[ut_itl_pair_lock_calls++] = buffer; return; @@ -2411,42 +2285,32 @@ LockBuffer(Buffer buffer, int mode) fixture->lock_modes[fixture->lock_calls] = mode; fixture->lock_calls++; - if (mode == BUFFER_LOCK_UNLOCK) - { + if (mode == BUFFER_LOCK_UNLOCK) { UT_ASSERT(ut_hot_content_lock_held); ut_hot_content_lock_held = false; - if (ut_hot_current_mx_active && ut_hot_current_mx_one_shot) - { - UT_ASSERT_EQ(ut_hot_current_mx_pcm_state, - (uint8) PCM_STATE_READ_IMAGE); - ut_hot_current_mx_pcm_state = (uint8) PCM_STATE_N; + if (ut_hot_current_mx_active && ut_hot_current_mx_one_shot) { + UT_ASSERT_EQ(ut_hot_current_mx_pcm_state, (uint8)PCM_STATE_READ_IMAGE); + ut_hot_current_mx_pcm_state = (uint8)PCM_STATE_N; ut_hot_current_read_clear_calls++; } - } - else if (mode == BUFFER_LOCK_SHARE) - { + } else if (mode == BUFFER_LOCK_SHARE) { UT_ASSERT(!ut_hot_content_lock_held); ut_hot_content_lock_held = true; - if (ut_hot_current_mx_active && ut_hot_current_mx_one_shot) - { - UT_ASSERT_EQ(ut_hot_current_mx_pcm_state, (uint8) PCM_STATE_N); + if (ut_hot_current_mx_active && ut_hot_current_mx_one_shot) { + UT_ASSERT_EQ(ut_hot_current_mx_pcm_state, (uint8)PCM_STATE_N); ut_hot_current_read_bracket++; - ut_hot_current_mx_pcm_state = (uint8) PCM_STATE_READ_IMAGE; + ut_hot_current_mx_pcm_state = (uint8)PCM_STATE_READ_IMAGE; ut_hot_current_read_acquire_calls++; } - } - else if (mode == BUFFER_LOCK_EXCLUSIVE) - { + } else if (mode == BUFFER_LOCK_EXCLUSIVE) { UT_ASSERT(!ut_hot_content_lock_held); ut_hot_content_lock_held = true; - } - else + } else UT_ASSERT(false); } ClusterCrBuildResult -cluster_gcs_block_cr_fetch_and_wait(BufferTag tag, SCN read_scn, - char dst_page[BLCKSZ], +cluster_gcs_block_cr_fetch_and_wait(BufferTag tag, SCN read_scn, char dst_page[BLCKSZ], ClusterCrBuildReason *reason_out) { UtR4HotProductFixture *fixture = ut_hot_product_fixture; @@ -2457,25 +2321,22 @@ cluster_gcs_block_cr_fetch_and_wait(BufferTag tag, SCN read_scn, fixture->fetch_calls++; UT_ASSERT(!ut_hot_content_lock_held); UT_ASSERT(BufferTagsEqual(&tag, &fixture->expected_tag)); - UT_ASSERT_EQ((uint64) read_scn, (uint64) fixture->expected_read_scn); + UT_ASSERT_EQ((uint64)read_scn, (uint64)fixture->expected_read_scn); UT_ASSERT(dst_page == fixture->expected_result->scratch_page); UT_ASSERT(dst_page != fixture->live_page); UT_ASSERT(dst_page != fixture->full_source); memcpy(dst_page, fixture->full_source, BLCKSZ); - if (OffsetNumberIsValid(fixture->mutate_hint_offset)) - { + if (OffsetNumberIsValid(fixture->mutate_hint_offset)) { /* Repeated refresh of an ordinary hint must not discard FULL forever. * Bound a broken consumer with a real refusal on its third fetch. */ - if (fixture->fetch_calls > 2) - { + if (fixture->fetch_calls > 2) { *reason_out = CLUSTER_CR_BUILD_IO_ERROR; return CLUSTER_CR_BUILD_FAIL_CLOSED; } - if (fixture->fetch_calls <= fixture->hint_changes) - { - HeapTupleHeader live_tuple = ut_r4_hot_tuple_at( - (Page) fixture->live_page, fixture->mutate_hint_offset); + if (fixture->fetch_calls <= fixture->hint_changes) { + HeapTupleHeader live_tuple + = ut_r4_hot_tuple_at((Page)fixture->live_page, fixture->mutate_hint_offset); live_tuple->t_infomask ^= fixture->hint_mask != 0 ? fixture->hint_mask : HEAP_XMIN_COMMITTED; @@ -2485,31 +2346,24 @@ cluster_gcs_block_cr_fetch_and_wait(BufferTag tag, SCN read_scn, *reason_out = CLUSTER_CR_BUILD_NONE; return CLUSTER_CR_BUILD_FULL; } - if (fixture->fetch_calls == 1) - { - if (fixture->mutate_non_target_itl) - { + if (fixture->fetch_calls == 1) { + if (fixture->mutate_non_target_itl) { ClusterItlSlotData *non_target_slot - = &ClusterPageGetItlSlots((Page) fixture->live_page)[0]; + = &ClusterPageGetItlSlots((Page)fixture->live_page)[0]; non_target_slot->wrap++; - } - else - { - HeapTupleHeader live_tuple = ut_r4_hot_tuple_at( - (Page) fixture->live_page, UT_HOT_ROOT_OFF); + } else { + HeapTupleHeader live_tuple + = ut_r4_hot_tuple_at((Page)fixture->live_page, UT_HOT_ROOT_OFF); live_tuple->t_infomask2 ^= HEAP_KEYS_UPDATED; } fixture->live_poisoned = true; - if (fixture->fail_first_after_mutation) - { + if (fixture->fail_first_after_mutation) { *reason_out = CLUSTER_CR_BUILD_IO_ERROR; return CLUSTER_CR_BUILD_FAIL_CLOSED; } - } - else - { + } else { memset(fixture->full_source, 0x5a, BLCKSZ); fixture->full_source_poisoned = true; } @@ -2526,8 +2380,8 @@ ut_r4_hot_tuple_at(Page page, OffsetNumber offnum) } static void -ut_r4_hot_set_tuple(HeapTupleHeader tuple, TransactionId xmin, - uint8 itl_slot_index, unsigned char payload) +ut_r4_hot_set_tuple(HeapTupleHeader tuple, TransactionId xmin, uint8 itl_slot_index, + unsigned char payload) { memset(tuple, 0, UT_HOT_TUPLE_LEN); HeapTupleHeaderSetXmin(tuple, xmin); @@ -2537,14 +2391,12 @@ ut_r4_hot_set_tuple(HeapTupleHeader tuple, TransactionId xmin, tuple->t_hoff = SizeofHeapTupleHeader; tuple->t_itl_slot_idx = itl_slot_index; ItemPointerSet(&tuple->t_ctid, UT_HOT_BLOCK, UT_HOT_ROOT_OFF); - memset((char *)tuple + tuple->t_hoff, payload, - UT_HOT_TUPLE_LEN - tuple->t_hoff); + memset((char *)tuple + tuple->t_hoff, payload, UT_HOT_TUPLE_LEN - tuple->t_hoff); } static Page -ut_r4_hot_build_page(char storage[BLCKSZ], TransactionId xmin, - uint8 itl_slot_index, TransactionId itl_xid, - uint16 itl_wrap, unsigned char payload) +ut_r4_hot_build_page(char storage[BLCKSZ], TransactionId xmin, uint8 itl_slot_index, + TransactionId itl_xid, uint16 itl_wrap, unsigned char payload) { Page page = (Page)storage; PageHeader header; @@ -2560,8 +2412,8 @@ ut_r4_hot_build_page(char storage[BLCKSZ], TransactionId xmin, header->pd_upper = (LocationIndex)UT_HOT_DATA_OFF; item_id = PageGetItemId(page, UT_HOT_ROOT_OFF); ItemIdSetNormal(item_id, UT_HOT_DATA_OFF, UT_HOT_TUPLE_LEN); - ut_r4_hot_set_tuple((HeapTupleHeader)(storage + UT_HOT_DATA_OFF), - xmin, itl_slot_index, payload); + ut_r4_hot_set_tuple((HeapTupleHeader)(storage + UT_HOT_DATA_OFF), xmin, itl_slot_index, + payload); slot = &ClusterPageGetItlSlots(page)[itl_slot_index]; slot->xid = itl_xid; slot->wrap = itl_wrap; @@ -2572,33 +2424,31 @@ ut_r4_hot_build_page(char storage[BLCKSZ], TransactionId xmin, static void ut_r4_hot_build_foreign_multixact_chain(char storage[BLCKSZ]) { - Page page = (Page) storage; + Page page = (Page)storage; PageHeader header; HeapTupleHeader root; HeapTupleHeader successor; ClusterItlSlotData *slot; memset(storage, 0, BLCKSZ); - header = (PageHeader) page; + header = (PageHeader)page; header->pd_flags = PD_HAS_ITL; - header->pd_special = (LocationIndex) (BLCKSZ - CLUSTER_ITL_SPECIAL_SIZE); + header->pd_special = (LocationIndex)(BLCKSZ - CLUSTER_ITL_SPECIAL_SIZE); header->pd_pagesize_version = BLCKSZ | PG_PAGE_LAYOUT_VERSION; header->pd_lower = SizeOfPageHeaderData + 2 * sizeof(ItemIdData); - header->pd_upper = (LocationIndex) UT_HOT_SUCCESSOR_DATA_OFF; - ItemIdSetNormal(PageGetItemId(page, UT_HOT_ROOT_OFF), - UT_HOT_DATA_OFF, UT_HOT_TUPLE_LEN); - ItemIdSetNormal(PageGetItemId(page, UT_HOT_SUCCESSOR_OFF), - UT_HOT_SUCCESSOR_DATA_OFF, UT_HOT_TUPLE_LEN); + header->pd_upper = (LocationIndex)UT_HOT_SUCCESSOR_DATA_OFF; + ItemIdSetNormal(PageGetItemId(page, UT_HOT_ROOT_OFF), UT_HOT_DATA_OFF, UT_HOT_TUPLE_LEN); + ItemIdSetNormal(PageGetItemId(page, UT_HOT_SUCCESSOR_OFF), UT_HOT_SUCCESSOR_DATA_OFF, + UT_HOT_TUPLE_LEN); - root = (HeapTupleHeader) (storage + UT_HOT_DATA_OFF); + root = (HeapTupleHeader)(storage + UT_HOT_DATA_OFF); ut_r4_hot_set_tuple(root, UT_HOT_FULL_XMIN, 2, 0x41); HeapTupleHeaderSetXmax(root, UT_HOT_FOREIGN_MXID); - root->t_infomask = HEAP_XMIN_COMMITTED | HEAP_XMAX_IS_MULTI - | HEAP_XMAX_EXCL_LOCK; + root->t_infomask = HEAP_XMIN_COMMITTED | HEAP_XMAX_IS_MULTI | HEAP_XMAX_EXCL_LOCK; root->t_infomask2 = HEAP_HOT_UPDATED; ItemPointerSet(&root->t_ctid, UT_HOT_BLOCK, UT_HOT_SUCCESSOR_OFF); - successor = (HeapTupleHeader) (storage + UT_HOT_SUCCESSOR_DATA_OFF); + successor = (HeapTupleHeader)(storage + UT_HOT_SUCCESSOR_DATA_OFF); ut_r4_hot_set_tuple(successor, UT_HOT_AUTH_UPDATER, 3, 0x42); successor->t_infomask2 = HEAP_ONLY_TUPLE; ItemPointerSet(&successor->t_ctid, UT_HOT_BLOCK, UT_HOT_SUCCESSOR_OFF); @@ -2615,8 +2465,7 @@ ut_r4_hot_build_foreign_multixact_chain(char storage[BLCKSZ]) } static void -ut_r4_hot_init_product_fixture(UtR4HotProductFixture *fixture, - HeapHotSearchResult *result) +ut_r4_hot_init_product_fixture(UtR4HotProductFixture *fixture, HeapHotSearchResult *result) { RelFileLocator locator = { .spcOid = 1663, @@ -2627,14 +2476,12 @@ ut_r4_hot_init_product_fixture(UtR4HotProductFixture *fixture, memset(fixture, 0, sizeof(*fixture)); memset(result, 0, sizeof(*result)); - (void) ut_r4_hot_build_page(fixture->live_page, UT_HOT_LIVE_XMIN, 2, - UT_HOT_LIVE_XMIN, 7, 0x77); - (void) ut_r4_hot_build_page(fixture->full_source, UT_HOT_FULL_XMIN, 1, - UT_HOT_FULL_XMIN, 4, UT_HOT_PAYLOAD); - full_tuple = ut_r4_hot_tuple_at((Page) fixture->full_source, - UT_HOT_ROOT_OFF); + (void)ut_r4_hot_build_page(fixture->live_page, UT_HOT_LIVE_XMIN, 2, UT_HOT_LIVE_XMIN, 7, 0x77); + (void)ut_r4_hot_build_page(fixture->full_source, UT_HOT_FULL_XMIN, 1, UT_HOT_FULL_XMIN, 4, + UT_HOT_PAYLOAD); + full_tuple = ut_r4_hot_tuple_at((Page)fixture->full_source, UT_HOT_ROOT_OFF); full_tuple->t_infomask = HEAP_XMAX_INVALID; - PageSetLSN((Page) fixture->full_source, UINT64_C(0x123450)); + PageSetLSN((Page)fixture->full_source, UINT64_C(0x123450)); InitBufferTag(&fixture->expected_tag, &locator, MAIN_FORKNUM, UT_HOT_BLOCK); fixture->expected_result = result; fixture->expected_read_scn = UT_HOT_READ_SCN; @@ -2645,7 +2492,7 @@ ut_r4_hot_init_product_fixture(UtR4HotProductFixture *fixture, ut_hot_live_ref.tt_slot_id = 7; ut_hot_live_ref.cluster_epoch = 9; ut_hot_live_ref.local_xid = UT_HOT_LIVE_XMIN + 1; - ut_hot_live_ref_page = (Page) fixture->live_page; + ut_hot_live_ref_page = (Page)fixture->live_page; ut_hot_live_ref_calls = 0; ut_hot_product_fixture = fixture; ut_hot_content_lock_held = true; @@ -2666,20 +2513,16 @@ ut_r4_hot_content_share(void *arg, bool acquire) { UtR4HotLifecycleFixture *fixture = (UtR4HotLifecycleFixture *)arg; - if (acquire) - { + if (acquire) { UT_ASSERT_EQ(fixture->event, 3); UT_ASSERT_EQ(fixture->held_locks & UT_HOT_FORBIDDEN_LOCKS, 0); ut_r4_hot_poison_live(fixture); fixture->held_locks |= UT_HOT_CONTENT_SHARE; fixture->relock_calls++; fixture->event = 4; - } - else - { + } else { UT_ASSERT_EQ(fixture->event, 0); - UT_ASSERT_EQ(fixture->held_locks & UT_HOT_FORBIDDEN_LOCKS, - UT_HOT_CONTENT_SHARE); + UT_ASSERT_EQ(fixture->held_locks & UT_HOT_FORBIDDEN_LOCKS, UT_HOT_CONTENT_SHARE); fixture->held_locks &= ~UT_HOT_CONTENT_SHARE; fixture->unlock_calls++; fixture->event = 1; @@ -2687,8 +2530,7 @@ ut_r4_hot_content_share(void *arg, bool acquire) } static bool -ut_r4_hot_fetch_full(void *arg, const BufferTag *tag, SCN read_scn, - char dst_page[BLCKSZ]) +ut_r4_hot_fetch_full(void *arg, const BufferTag *tag, SCN read_scn, char dst_page[BLCKSZ]) { UtR4HotLifecycleFixture *fixture = (UtR4HotLifecycleFixture *)arg; @@ -2710,8 +2552,7 @@ ut_r4_hot_fetch_full(void *arg, const BufferTag *tag, SCN read_scn, } static bool -ut_r4_hot_search_scratch(void *arg, - const ClusterR4HotScratchTestContext *context, +ut_r4_hot_search_scratch(void *arg, const ClusterR4HotScratchTestContext *context, HeapTuple scratch_tuple) { UtR4HotLifecycleFixture *fixture = (UtR4HotLifecycleFixture *)arg; @@ -2723,12 +2564,9 @@ ut_r4_hot_search_scratch(void *arg, UT_ASSERT(fixture->full_source_poisoned); UT_ASSERT(context->scratch_page == (Page)fixture->expected_scratch_page); UT_ASSERT(BufferTagsEqual(&context->tag, &fixture->expected_tag)); - UT_ASSERT_EQ(ItemPointerGetBlockNumber(&context->logical_root), - UT_HOT_BLOCK); - UT_ASSERT_EQ(ItemPointerGetOffsetNumber(&context->logical_root), - UT_HOT_ROOT_OFF); - UT_ASSERT_EQ((uint64)context->read_scn, - (uint64)fixture->expected_read_scn); + UT_ASSERT_EQ(ItemPointerGetBlockNumber(&context->logical_root), UT_HOT_BLOCK); + UT_ASSERT_EQ(ItemPointerGetOffsetNumber(&context->logical_root), UT_HOT_ROOT_OFF); + UT_ASSERT_EQ((uint64)context->read_scn, (uint64)fixture->expected_read_scn); UT_ASSERT(context->already_full); UT_ASSERT(!context->allow_hint); UT_ASSERT(!context->allow_cleanout); @@ -2736,15 +2574,13 @@ ut_r4_hot_search_scratch(void *arg, item_id = PageGetItemId(context->scratch_page, UT_HOT_ROOT_OFF); UT_ASSERT(ItemIdIsNormal(item_id)); - scratch_tuple->t_data = - (HeapTupleHeader)PageGetItem(context->scratch_page, item_id); + scratch_tuple->t_data = (HeapTupleHeader)PageGetItem(context->scratch_page, item_id); scratch_tuple->t_len = ItemIdGetLength(item_id); ItemPointerSet(&scratch_tuple->t_self, UT_HOT_BLOCK, UT_HOT_ROOT_OFF); scratch_tuple->t_tableOid = UT_HOT_TABLE_OID; - UT_ASSERT_EQ(HeapTupleHeaderGetRawXmin(scratch_tuple->t_data), - UT_HOT_FULL_XMIN); - UT_ASSERT_EQ(*((unsigned char *)scratch_tuple->t_data + - scratch_tuple->t_data->t_hoff), UT_HOT_PAYLOAD); + UT_ASSERT_EQ(HeapTupleHeaderGetRawXmin(scratch_tuple->t_data), UT_HOT_FULL_XMIN); + UT_ASSERT_EQ(*((unsigned char *)scratch_tuple->t_data + scratch_tuple->t_data->t_hoff), + UT_HOT_PAYLOAD); fixture->scratch_search_calls++; fixture->event = 3; @@ -2752,8 +2588,7 @@ ut_r4_hot_search_scratch(void *arg, } static void -ut_r4_hot_init_fixture(UtR4HotLifecycleFixture *fixture, - HeapHotSearchResult *result) +ut_r4_hot_init_fixture(UtR4HotLifecycleFixture *fixture, HeapHotSearchResult *result) { RelFileLocator locator = { .spcOid = 1663, @@ -2763,10 +2598,9 @@ ut_r4_hot_init_fixture(UtR4HotLifecycleFixture *fixture, memset(fixture, 0, sizeof(*fixture)); memset(result, 0, sizeof(*result)); - (void)ut_r4_hot_build_page(fixture->live_page, UT_HOT_LIVE_XMIN, 2, - UT_HOT_LIVE_XMIN, 7, 0x77); - (void)ut_r4_hot_build_page(fixture->full_source, UT_HOT_FULL_XMIN, 1, - UT_HOT_FULL_XMIN, 4, UT_HOT_PAYLOAD); + (void)ut_r4_hot_build_page(fixture->live_page, UT_HOT_LIVE_XMIN, 2, UT_HOT_LIVE_XMIN, 7, 0x77); + (void)ut_r4_hot_build_page(fixture->full_source, UT_HOT_FULL_XMIN, 1, UT_HOT_FULL_XMIN, 4, + UT_HOT_PAYLOAD); InitBufferTag(&fixture->expected_tag, &locator, MAIN_FORKNUM, UT_HOT_BLOCK); ItemPointerSet(&fixture->expected_root, UT_HOT_BLOCK, UT_HOT_ROOT_OFF); fixture->expected_read_scn = UT_HOT_READ_SCN; @@ -2810,8 +2644,7 @@ UT_TEST(test_33_buffer_backed_result_keeps_real_buffer_pin) ut_r4_hot_reset_resources(); memset(&result, 0, sizeof(result)); - (void)ut_r4_hot_build_page(live_page, UT_HOT_LIVE_XMIN, 2, - UT_HOT_LIVE_XMIN, 7, 0x77); + (void)ut_r4_hot_build_page(live_page, UT_HOT_LIVE_XMIN, 2, UT_HOT_LIVE_XMIN, 7, 0x77); result.kind = HEAP_HOT_SEARCH_BUFFER_BACKED; result.tuple.t_data = ut_r4_hot_tuple_at((Page)live_page, UT_HOT_ROOT_OFF); result.tuple.t_len = UT_HOT_TUPLE_LEN; @@ -2821,8 +2654,8 @@ UT_TEST(test_33_buffer_backed_result_keeps_real_buffer_pin) slot = ut_r4_hot_make_slot(&tuple_desc); buffer_slot = (BufferHeapTupleTableSlot *)slot; - stored = cluster_heap_test_r4_store_hot_result( - &result, slot, UT_HOT_BUFFER, &call_again, &all_dead); + stored = cluster_heap_test_r4_store_hot_result(&result, slot, UT_HOT_BUFFER, &call_again, + &all_dead); UT_ASSERT_EQ(stored, TABLE_INDEX_FETCH_FOUND); UT_ASSERT(!call_again); UT_ASSERT(!all_dead); @@ -2842,14 +2675,12 @@ UT_TEST(test_33_buffer_backed_result_keeps_real_buffer_pin) memset(&result.tuple, 0, sizeof(result.tuple)); UT_ASSERT(buffer_slot->base.tuple == &buffer_slot->base.tupdata); UT_ASSERT(buffer_slot->base.tupdata.t_data == live_tuple_data); - UT_ASSERT_EQ(HeapTupleHeaderGetRawXmin(buffer_slot->base.tupdata.t_data), - UT_HOT_LIVE_XMIN); - UT_ASSERT_EQ(*((unsigned char *)buffer_slot->base.tupdata.t_data + - buffer_slot->base.tupdata.t_data->t_hoff), 0x77); - UT_ASSERT_EQ(ItemPointerGetBlockNumber(&buffer_slot->base.tupdata.t_self), - UT_HOT_BLOCK); - UT_ASSERT_EQ(ItemPointerGetOffsetNumber(&buffer_slot->base.tupdata.t_self), - UT_HOT_ROOT_OFF); + UT_ASSERT_EQ(HeapTupleHeaderGetRawXmin(buffer_slot->base.tupdata.t_data), UT_HOT_LIVE_XMIN); + UT_ASSERT_EQ(*((unsigned char *)buffer_slot->base.tupdata.t_data + + buffer_slot->base.tupdata.t_data->t_hoff), + 0x77); + UT_ASSERT_EQ(ItemPointerGetBlockNumber(&buffer_slot->base.tupdata.t_self), UT_HOT_BLOCK); + UT_ASSERT_EQ(ItemPointerGetOffsetNumber(&buffer_slot->base.tupdata.t_self), UT_HOT_ROOT_OFF); UT_ASSERT_EQ(buffer_slot->base.tupdata.t_tableOid, UT_HOT_TABLE_OID); frees_before_clear = ut_free_calls; @@ -2884,9 +2715,9 @@ UT_TEST(test_34_owned_scratch_result_survives_source_and_live_poison) ut_r4_hot_init_fixture(&fixture, &result); kind = cluster_heap_test_r4_hot_full_cycle( - fixture.expected_tag, fixture.expected_root, fixture.expected_read_scn, - &result, ut_r4_hot_content_share, ut_r4_hot_fetch_full, - ut_r4_hot_search_scratch, &fixture, &call_again, &all_dead); + fixture.expected_tag, fixture.expected_root, fixture.expected_read_scn, &result, + ut_r4_hot_content_share, ut_r4_hot_fetch_full, ut_r4_hot_search_scratch, &fixture, + &call_again, &all_dead); UT_ASSERT_EQ(kind, HEAP_HOT_SEARCH_OWNED_SCRATCH); UT_ASSERT_EQ(result.kind, HEAP_HOT_SEARCH_OWNED_SCRATCH); UT_ASSERT(!call_again); @@ -2896,8 +2727,7 @@ UT_TEST(test_34_owned_scratch_result_survives_source_and_live_poison) UT_ASSERT_EQ(fixture.fetch_calls, 1); UT_ASSERT_EQ(fixture.scratch_search_calls, 1); UT_ASSERT_EQ(fixture.relock_calls, 1); - UT_ASSERT_EQ(fixture.held_locks & UT_HOT_FORBIDDEN_LOCKS, - UT_HOT_CONTENT_SHARE); + UT_ASSERT_EQ(fixture.held_locks & UT_HOT_FORBIDDEN_LOCKS, UT_HOT_CONTENT_SHARE); scratch_begin = (uintptr_t)result.scratch_page; scratch_end = scratch_begin + BLCKSZ; UT_ASSERT((uintptr_t)result.tuple.t_data >= scratch_begin); @@ -2907,8 +2737,8 @@ UT_TEST(test_34_owned_scratch_result_survives_source_and_live_poison) buffer_slot = (BufferHeapTupleTableSlot *)slot; call_again = true; all_dead = true; - stored = cluster_heap_test_r4_store_hot_result( - &result, slot, UT_HOT_BUFFER, &call_again, &all_dead); + stored = cluster_heap_test_r4_store_hot_result(&result, slot, UT_HOT_BUFFER, &call_again, + &all_dead); UT_ASSERT_EQ(stored, TABLE_INDEX_FETCH_FOUND); UT_ASSERT(!call_again); UT_ASSERT(!all_dead); @@ -2919,14 +2749,12 @@ UT_TEST(test_34_owned_scratch_result_survives_source_and_live_poison) UT_ASSERT_EQ(ut_invalid_free_calls, 0); owned_tuple = buffer_slot->base.tuple; UT_ASSERT_NOT_NULL(owned_tuple); - if (owned_tuple != NULL) - { + if (owned_tuple != NULL) { owned_data_addr = (uintptr_t)owned_tuple->t_data; UT_ASSERT(owned_tuple != &result.tuple); UT_ASSERT(owned_data_addr < scratch_begin || owned_data_addr >= scratch_end); UT_ASSERT_EQ(ItemPointerGetBlockNumber(&owned_tuple->t_self), UT_HOT_BLOCK); - UT_ASSERT_EQ(ItemPointerGetOffsetNumber(&owned_tuple->t_self), - UT_HOT_ROOT_OFF); + UT_ASSERT_EQ(ItemPointerGetOffsetNumber(&owned_tuple->t_self), UT_HOT_ROOT_OFF); UT_ASSERT_EQ(owned_tuple->t_tableOid, UT_HOT_TABLE_OID); } UT_ASSERT_EQ(ItemPointerGetBlockNumber(&slot->tts_tid), UT_HOT_BLOCK); @@ -2936,12 +2764,10 @@ UT_TEST(test_34_owned_scratch_result_survives_source_and_live_poison) memset(result.scratch_page, 0x00, BLCKSZ); memset(fixture.live_page, 0x00, BLCKSZ); memset(fixture.full_source, 0x00, BLCKSZ); - if (owned_tuple != NULL) - { - UT_ASSERT_EQ(HeapTupleHeaderGetRawXmin(owned_tuple->t_data), - UT_HOT_FULL_XMIN); - UT_ASSERT_EQ(*((unsigned char *)owned_tuple->t_data + - owned_tuple->t_data->t_hoff), UT_HOT_PAYLOAD); + if (owned_tuple != NULL) { + UT_ASSERT_EQ(HeapTupleHeaderGetRawXmin(owned_tuple->t_data), UT_HOT_FULL_XMIN); + UT_ASSERT_EQ(*((unsigned char *)owned_tuple->t_data + owned_tuple->t_data->t_hoff), + UT_HOT_PAYLOAD); } frees_before_clear = ut_free_calls; @@ -2958,8 +2784,8 @@ UT_TEST(test_34_owned_scratch_result_survives_source_and_live_poison) } static void -ut_r4_hot_reset_scratch_authority(Page scratch_page, Page forbidden_live_page, - SCN read_scn, XLogRecPtr page_lsn) +ut_r4_hot_reset_scratch_authority(Page scratch_page, Page forbidden_live_page, SCN read_scn, + XLogRecPtr page_lsn) { memset(&ut_scratch_expected_ref, 0, sizeof(ut_scratch_expected_ref)); ut_scratch_expected_page = scratch_page; @@ -3001,10 +2827,9 @@ UT_TEST(test_35_scratch_mvcc_uses_exact_ref_without_hints_or_live_page) XLogRecPtr page_lsn = UINT64_C(0x123450); bool visible; - scratch_page = ut_r4_hot_build_page(scratch_storage, UT_HOT_FULL_XMIN, 1, - UT_HOT_FULL_XMIN, 4, UT_HOT_PAYLOAD); - live_page = ut_r4_hot_build_page(live_storage, UT_HOT_LIVE_XMIN, 2, - UT_HOT_LIVE_XMIN, 7, 0x77); + scratch_page = ut_r4_hot_build_page(scratch_storage, UT_HOT_FULL_XMIN, 1, UT_HOT_FULL_XMIN, 4, + UT_HOT_PAYLOAD); + live_page = ut_r4_hot_build_page(live_storage, UT_HOT_LIVE_XMIN, 2, UT_HOT_LIVE_XMIN, 7, 0x77); tuple_header = ut_r4_hot_tuple_at(scratch_page, UT_HOT_ROOT_OFF); /* No xmin hint: the exact resolver, never native CLOG/hinting, decides. */ tuple_header->t_infomask = HEAP_XMAX_INVALID; @@ -3030,8 +2855,7 @@ UT_TEST(test_35_scratch_mvcc_uses_exact_ref_without_hints_or_live_page) context.allow_hint = false; context.allow_cleanout = false; - ut_r4_hot_reset_scratch_authority(scratch_page, live_page, - snapshot.read_scn, page_lsn); + ut_r4_hot_reset_scratch_authority(scratch_page, live_page, snapshot.read_scn, page_lsn); visible = HeapTupleSatisfiesMVCCScratch(&tuple, &snapshot, &context); UT_ASSERT(visible); UT_ASSERT_EQ(ut_scratch_ref_calls, 1); @@ -3249,17 +3073,16 @@ ut_hot_full_hint_mask_recheck_case(bool non_target, bool initially_committed, ui fixture.hint_mask = hint_mask; fixture.hint_changes = semantic_change ? 1 : 2; fixture.mutate_hint_payload = payload_change; - if (non_target) - { + if (non_target) { Page page = (Page)fixture.live_page; PageHeader header = (PageHeader)page; header->pd_lower = SizeOfPageHeaderData + 2 * sizeof(ItemIdData); header->pd_upper = UT_HOT_SUCCESSOR_DATA_OFF; - ItemIdSetNormal(PageGetItemId(page, UT_HOT_SUCCESSOR_OFF), - UT_HOT_SUCCESSOR_DATA_OFF, UT_HOT_TUPLE_LEN); - ut_r4_hot_set_tuple(ut_r4_hot_tuple_at(page, UT_HOT_SUCCESSOR_OFF), - UT_HOT_FULL_XMIN, 1, 0x42); + ItemIdSetNormal(PageGetItemId(page, UT_HOT_SUCCESSOR_OFF), UT_HOT_SUCCESSOR_DATA_OFF, + UT_HOT_TUPLE_LEN); + ut_r4_hot_set_tuple(ut_r4_hot_tuple_at(page, UT_HOT_SUCCESSOR_OFF), UT_HOT_FULL_XMIN, 1, + 0x42); } hint_tuple = ut_r4_hot_tuple_at((Page)fixture.live_page, fixture.mutate_hint_offset); hint_tuple->t_infomask &= ~hint_mask; @@ -3288,8 +3111,8 @@ ut_hot_full_hint_mask_recheck_case(bool non_target, bool initially_committed, ui ut_capture_error = true; PG_TRY(); { - kind = heap_hot_search_buffer_result(&tid, &relation, UT_HOT_BUFFER, &snapshot, - &result, NULL, true); + kind = heap_hot_search_buffer_result(&tid, &relation, UT_HOT_BUFFER, &snapshot, &result, + NULL, true); } PG_CATCH(); { @@ -3304,8 +3127,7 @@ ut_hot_full_hint_mask_recheck_case(bool non_target, bool initially_committed, ui UT_ASSERT_EQ(memcmp(expected_live.data, fixture.live_page, BLCKSZ), 0); UT_ASSERT_EQ(ut_live_visibility_calls, 0); UT_ASSERT(ut_hot_content_lock_held); - if (!caught) - { + if (!caught) { UT_ASSERT_EQ(HeapTupleHeaderGetRawXmin(result.tuple.t_data), UT_HOT_FULL_XMIN); UT_ASSERT_EQ(((unsigned char *)result.tuple.t_data)[result.tuple.t_data->t_hoff], UT_HOT_PAYLOAD); @@ -3923,8 +3745,7 @@ UT_TEST(test_36_production_hot_core_full_result_is_owned) ut_r4_hot_reset_resources(); ut_r4_hot_init_product_fixture(&fixture, &result); - ut_r4_hot_reset_scratch_authority((Page) result.scratch_page, - (Page) fixture.live_page, + ut_r4_hot_reset_scratch_authority((Page)result.scratch_page, (Page)fixture.live_page, UT_HOT_READ_SCN, UINT64_C(0x123450)); memset(&relation, 0, sizeof(relation)); @@ -3939,11 +3760,10 @@ UT_TEST(test_36_production_hot_core_full_result_is_owned) snapshot.cluster_source = SNAPSHOT_SOURCE_CLUSTER; ItemPointerSet(&tid, UT_HOT_BLOCK, UT_HOT_ROOT_OFF); slot = ut_r4_hot_make_slot(&tuple_desc); - buffer_slot = (BufferHeapTupleTableSlot *) slot; + buffer_slot = (BufferHeapTupleTableSlot *)slot; - stored = cluster_heap_test_r4_index_hot_result( - &tid, &relation, UT_HOT_BUFFER, &snapshot, &result, slot, - &call_again, &all_dead); + stored = cluster_heap_test_r4_index_hot_result(&tid, &relation, UT_HOT_BUFFER, &snapshot, + &result, slot, &call_again, &all_dead); UT_ASSERT_EQ(stored, TABLE_INDEX_FETCH_FOUND); UT_ASSERT_EQ(result.kind, HEAP_HOT_SEARCH_OWNED_SCRATCH); UT_ASSERT(!call_again); @@ -3968,25 +3788,22 @@ UT_TEST(test_36_production_hot_core_full_result_is_owned) UT_ASSERT_EQ(ut_scratch_hint_calls, 0); UT_ASSERT_EQ(ut_scratch_dirty_calls, 0); - scratch_begin = (uintptr_t) result.scratch_page; + scratch_begin = (uintptr_t)result.scratch_page; scratch_end = scratch_begin + BLCKSZ; - UT_ASSERT((uintptr_t) result.tuple.t_data >= scratch_begin); - UT_ASSERT((uintptr_t) result.tuple.t_data + result.tuple.t_len <= scratch_end); + UT_ASSERT((uintptr_t)result.tuple.t_data >= scratch_begin); + UT_ASSERT((uintptr_t)result.tuple.t_data + result.tuple.t_len <= scratch_end); UT_ASSERT_EQ(buffer_slot->buffer, InvalidBuffer); UT_ASSERT(TTS_SHOULDFREE(slot)); UT_ASSERT_EQ(ut_buffer_incr_calls, 0); UT_ASSERT_EQ(ut_buffer_release_calls, 0); owned_tuple = buffer_slot->base.tuple; UT_ASSERT_NOT_NULL(owned_tuple); - if (owned_tuple != NULL) - { + if (owned_tuple != NULL) { UT_ASSERT(owned_tuple != &result.tuple); - UT_ASSERT((uintptr_t) owned_tuple->t_data < scratch_begin - || (uintptr_t) owned_tuple->t_data >= scratch_end); - UT_ASSERT_EQ(ItemPointerGetBlockNumber(&owned_tuple->t_self), - UT_HOT_BLOCK); - UT_ASSERT_EQ(ItemPointerGetOffsetNumber(&owned_tuple->t_self), - UT_HOT_ROOT_OFF); + UT_ASSERT((uintptr_t)owned_tuple->t_data < scratch_begin + || (uintptr_t)owned_tuple->t_data >= scratch_end); + UT_ASSERT_EQ(ItemPointerGetBlockNumber(&owned_tuple->t_self), UT_HOT_BLOCK); + UT_ASSERT_EQ(ItemPointerGetOffsetNumber(&owned_tuple->t_self), UT_HOT_ROOT_OFF); UT_ASSERT_EQ(owned_tuple->t_tableOid, UT_HOT_TABLE_OID); } UT_ASSERT_EQ(ItemPointerGetBlockNumber(&slot->tts_tid), UT_HOT_BLOCK); @@ -3996,12 +3813,10 @@ UT_TEST(test_36_production_hot_core_full_result_is_owned) memset(result.scratch_page, 0, BLCKSZ); memset(fixture.live_page, 0, BLCKSZ); memset(fixture.full_source, 0, BLCKSZ); - if (owned_tuple != NULL) - { - UT_ASSERT_EQ(HeapTupleHeaderGetRawXmin(owned_tuple->t_data), - UT_HOT_FULL_XMIN); - UT_ASSERT_EQ(*((unsigned char *) owned_tuple->t_data - + owned_tuple->t_data->t_hoff), UT_HOT_PAYLOAD); + if (owned_tuple != NULL) { + UT_ASSERT_EQ(HeapTupleHeaderGetRawXmin(owned_tuple->t_data), UT_HOT_FULL_XMIN); + UT_ASSERT_EQ(*((unsigned char *)owned_tuple->t_data + owned_tuple->t_data->t_hoff), + UT_HOT_PAYLOAD); } ut_hot_production_core_active = false; @@ -4032,17 +3847,15 @@ UT_TEST(test_37_full_input_recheck_catches_non_target_itl_with_stable_tuple_and_ HeapHotSearchResultKind kind; ClusterItlSlotData non_target_before; char target_before[UT_HOT_TUPLE_LEN]; - XLogRecPtr stable_lsn = (XLogRecPtr) UINT64_C(0x445566); + XLogRecPtr stable_lsn = (XLogRecPtr)UINT64_C(0x445566); ut_r4_hot_init_product_fixture(&fixture, &result); fixture.mutate_non_target_itl = true; - PageSetLSN((Page) fixture.live_page, stable_lsn); - memcpy(target_before, - ut_r4_hot_tuple_at((Page) fixture.live_page, UT_HOT_ROOT_OFF), + PageSetLSN((Page)fixture.live_page, stable_lsn); + memcpy(target_before, ut_r4_hot_tuple_at((Page)fixture.live_page, UT_HOT_ROOT_OFF), sizeof(target_before)); - non_target_before = ClusterPageGetItlSlots((Page) fixture.live_page)[0]; - ut_r4_hot_reset_scratch_authority((Page) result.scratch_page, - (Page) fixture.live_page, + non_target_before = ClusterPageGetItlSlots((Page)fixture.live_page)[0]; + ut_r4_hot_reset_scratch_authority((Page)result.scratch_page, (Page)fixture.live_page, UT_HOT_READ_SCN, UINT64_C(0x123450)); memset(&relation, 0, sizeof(relation)); @@ -4057,19 +3870,17 @@ UT_TEST(test_37_full_input_recheck_catches_non_target_itl_with_stable_tuple_and_ snapshot.cluster_source = SNAPSHOT_SOURCE_CLUSTER; ItemPointerSet(&tid, UT_HOT_BLOCK, UT_HOT_ROOT_OFF); - kind = heap_hot_search_buffer_result(&tid, &relation, UT_HOT_BUFFER, - &snapshot, &result, NULL, true); + kind = heap_hot_search_buffer_result(&tid, &relation, UT_HOT_BUFFER, &snapshot, &result, NULL, + true); UT_ASSERT_EQ(kind, HEAP_HOT_SEARCH_OWNED_SCRATCH); UT_ASSERT_EQ(fixture.fetch_calls, 2); UT_ASSERT_EQ(fixture.lock_calls, 4); UT_ASSERT(fixture.live_poisoned); - UT_ASSERT_EQ(PageGetLSN((Page) fixture.live_page), stable_lsn); - UT_ASSERT_EQ(memcmp(target_before, - ut_r4_hot_tuple_at((Page) fixture.live_page, - UT_HOT_ROOT_OFF), - sizeof(target_before)), 0); - UT_ASSERT(ClusterPageGetItlSlots((Page) fixture.live_page)[0].wrap - != non_target_before.wrap); + UT_ASSERT_EQ(PageGetLSN((Page)fixture.live_page), stable_lsn); + UT_ASSERT_EQ(memcmp(target_before, ut_r4_hot_tuple_at((Page)fixture.live_page, UT_HOT_ROOT_OFF), + sizeof(target_before)), + 0); + UT_ASSERT(ClusterPageGetItlSlots((Page)fixture.live_page)[0].wrap != non_target_before.wrap); UT_ASSERT_EQ(ut_hot_live_ref_calls, 2); UT_ASSERT_EQ(ut_scratch_ref_calls, 2); @@ -4094,8 +3905,7 @@ UT_TEST(test_38_changed_input_discards_old_fetch_failure_before_error_mapping) ut_r4_hot_init_product_fixture(&fixture, &result); fixture.mutate_non_target_itl = true; fixture.fail_first_after_mutation = true; - ut_r4_hot_reset_scratch_authority((Page) result.scratch_page, - (Page) fixture.live_page, + ut_r4_hot_reset_scratch_authority((Page)result.scratch_page, (Page)fixture.live_page, UT_HOT_READ_SCN, UINT64_C(0x123450)); memset(&relation, 0, sizeof(relation)); @@ -4110,8 +3920,8 @@ UT_TEST(test_38_changed_input_discards_old_fetch_failure_before_error_mapping) snapshot.cluster_source = SNAPSHOT_SOURCE_CLUSTER; ItemPointerSet(&tid, UT_HOT_BLOCK, UT_HOT_ROOT_OFF); - kind = heap_hot_search_buffer_result(&tid, &relation, UT_HOT_BUFFER, - &snapshot, &result, NULL, true); + kind = heap_hot_search_buffer_result(&tid, &relation, UT_HOT_BUFFER, &snapshot, &result, NULL, + true); UT_ASSERT_EQ(kind, HEAP_HOT_SEARCH_OWNED_SCRATCH); UT_ASSERT_EQ(fixture.fetch_calls, 2); UT_ASSERT_EQ(fixture.lock_calls, 4); @@ -4352,26 +4162,22 @@ UT_TEST(test_40_dormant_r4_does_not_intercept_live_hot_path) } static void -ut_itl_census_begin(UtR4HotProductFixture *fixture, - HeapHotSearchResult *result, bool lock_only) +ut_itl_census_begin(UtR4HotProductFixture *fixture, HeapHotSearchResult *result, bool lock_only) { ClusterItlSlotData *slots; uint8 i; ut_r4_hot_init_product_fixture(fixture, result); - slots = ClusterPageGetItlSlots((Page) fixture->live_page); - memset(slots, 0, - sizeof(ClusterItlSlotData) * CLUSTER_ITL_INITRANS_DEFAULT); - for (i = 0; i < CLUSTER_ITL_INITRANS_DEFAULT; i++) - { - slots[i].xid = (TransactionId) (1200 + i); - slots[i].wrap = (uint16) (20 + i); - slots[i].flags = lock_only - ? ITL_FLAG_LOCK_ONLY_ACTIVE : ITL_FLAG_ACTIVE; + slots = ClusterPageGetItlSlots((Page)fixture->live_page); + memset(slots, 0, sizeof(ClusterItlSlotData) * CLUSTER_ITL_INITRANS_DEFAULT); + for (i = 0; i < CLUSTER_ITL_INITRANS_DEFAULT; i++) { + slots[i].xid = (TransactionId)(1200 + i); + slots[i].wrap = (uint16)(20 + i); + slots[i].flags = lock_only ? ITL_FLAG_LOCK_ONLY_ACTIVE : ITL_FLAG_ACTIVE; slots[i].undo_segment_head = uba_encode(1, i + 1, i, 0); ut_itl_census_outcomes[i] = CLUSTER_TX_UNKNOWN; } - PageSetLSN((Page) fixture->live_page, (XLogRecPtr) UINT64_C(0x334455)); + PageSetLSN((Page)fixture->live_page, (XLogRecPtr)UINT64_C(0x334455)); ut_itl_census_active = true; ut_itl_census_mutate_wrap = false; ut_itl_census_lock_only = lock_only; @@ -4392,33 +4198,27 @@ ut_itl_census_begin(UtR4HotProductFixture *fixture, ut_itl_census_origin_tt_generation = UINT64_C(77); ut_itl_census_mutate_activation = false; ut_itl_census_admission = NULL; - memset(&ut_itl_census_semantic, 0, - sizeof(ut_itl_census_semantic)); + memset(&ut_itl_census_semantic, 0, sizeof(ut_itl_census_semantic)); pg_atomic_init_u64(&ut_itl_census_semantic.admission_seq, 2); pg_atomic_init_u64(&ut_itl_census_semantic.active_bits, 0); pg_atomic_init_u64(&ut_itl_census_semantic.record_generation, 73); pg_atomic_init_u64(&ut_itl_census_semantic.formation_epoch, 9); pg_atomic_init_u32(&ut_itl_census_semantic.transition_closed, 0); - for (i = 0; i < 2; i++) - { + for (i = 0; i < 2; i++) { int feature; for (feature = 0; feature < 64; feature++) - pg_atomic_init_u32( - &ut_itl_census_semantic.inflight[i][feature], 0); + pg_atomic_init_u32(&ut_itl_census_semantic.inflight[i][feature], 0); } - memset(semantic_activation_local_inflight, 0, - sizeof(semantic_activation_local_inflight)); + memset(semantic_activation_local_inflight, 0, sizeof(semantic_activation_local_inflight)); semantic_activation_exit_hook_pid = 0; SemanticActivationShmem = &ut_itl_census_semantic; cluster_r4_activation_test_current_epoch = 9; ut_itl_census_tag = fixture->expected_tag; ut_cluster_conf.node_count = 2; ut_itl_pair_active = false; - memset(ut_itl_pair_content_lock_held, 0, - sizeof(ut_itl_pair_content_lock_held)); - memset(ut_itl_pair_lock_buffers, 0, - sizeof(ut_itl_pair_lock_buffers)); + memset(ut_itl_pair_content_lock_held, 0, sizeof(ut_itl_pair_content_lock_held)); + memset(ut_itl_pair_lock_buffers, 0, sizeof(ut_itl_pair_lock_buffers)); ut_itl_pair_lock_calls = 0; fixture->lock_calls = 0; ut_hot_pcm_snapshot_calls = 0; @@ -4445,18 +4245,15 @@ ut_itl_census_begin(UtR4HotProductFixture *fixture, static void ut_itl_census_end(void) { - UT_ASSERT_EQ(pg_atomic_read_u32( - &ut_itl_census_semantic.inflight[CLUSTER_SEMANTIC_TARGET_SIDE][0]), 0); - UT_ASSERT_EQ(semantic_activation_local_inflight - [CLUSTER_SEMANTIC_TARGET_SIDE][0], 0); - if (ut_itl_pair_active) - { + UT_ASSERT_EQ( + pg_atomic_read_u32(&ut_itl_census_semantic.inflight[CLUSTER_SEMANTIC_TARGET_SIDE][0]), 0); + UT_ASSERT_EQ(semantic_activation_local_inflight[CLUSTER_SEMANTIC_TARGET_SIDE][0], 0); + if (ut_itl_pair_active) { UT_ASSERT(!ut_itl_pair_content_lock_held[0]); UT_ASSERT(!ut_itl_pair_content_lock_held[1]); ut_itl_pair_active = false; ut_hot_content_lock_held = false; - } - else + } else LockBuffer(UT_HOT_BUFFER, BUFFER_LOCK_UNLOCK); ut_itl_census_active = false; ut_hot_production_core_active = false; @@ -4475,15 +4272,14 @@ UT_TEST(test_41_data_itl_full_census_resolves_terminal_without_content_lock) ut_itl_census_begin(&fixture, &result, false); ut_itl_census_outcomes[0] = CLUSTER_TX_COMMITTED; - UT_ASSERT(cluster_heap_test_itl_alloc_with_terminal_census( - UT_HOT_BUFFER, (TransactionId) 1300, false, &slot_index)); - slots = ClusterPageGetItlSlots((Page) fixture.live_page); + UT_ASSERT(cluster_heap_test_itl_alloc_with_terminal_census(UT_HOT_BUFFER, (TransactionId)1300, + false, &slot_index)); + slots = ClusterPageGetItlSlots((Page)fixture.live_page); UT_ASSERT_EQ(slot_index, 0); UT_ASSERT_EQ(slots[0].flags, ITL_FLAG_COMMITTED); - UT_ASSERT_EQ((uint64) slots[0].commit_scn, UINT64_C(9001)); + UT_ASSERT_EQ((uint64)slots[0].commit_scn, UINT64_C(9001)); UT_ASSERT_EQ(ut_itl_census_alloc_calls, 1); - UT_ASSERT_EQ(ut_itl_census_resolve_calls, - CLUSTER_ITL_INITRANS_DEFAULT); + UT_ASSERT_EQ(ut_itl_census_resolve_calls, CLUSTER_ITL_INITRANS_DEFAULT); UT_ASSERT_EQ(ut_itl_census_dirty_hint_calls, 1); UT_ASSERT_EQ(fixture.lock_calls, 2); UT_ASSERT_EQ(fixture.lock_modes[0], BUFFER_LOCK_UNLOCK); @@ -4501,15 +4297,14 @@ UT_TEST(test_42_lock_only_itl_full_census_recycles_exact_abort) ut_itl_census_begin(&fixture, &result, true); ut_itl_census_outcomes[0] = CLUSTER_TX_ABORTED; - UT_ASSERT(cluster_heap_test_itl_alloc_with_terminal_census( - UT_HOT_BUFFER, (TransactionId) 1301, true, &slot_index)); - slots = ClusterPageGetItlSlots((Page) fixture.live_page); + UT_ASSERT(cluster_heap_test_itl_alloc_with_terminal_census(UT_HOT_BUFFER, (TransactionId)1301, + true, &slot_index)); + slots = ClusterPageGetItlSlots((Page)fixture.live_page); UT_ASSERT_EQ(slot_index, 0); UT_ASSERT_EQ(slots[0].flags, ITL_FLAG_LOCK_ONLY_ABORTED); - UT_ASSERT_EQ((uint64) slots[0].commit_scn, (uint64) InvalidScn); + UT_ASSERT_EQ((uint64)slots[0].commit_scn, (uint64)InvalidScn); UT_ASSERT_EQ(ut_itl_census_alloc_calls, 1); - UT_ASSERT_EQ(ut_itl_census_resolve_calls, - CLUSTER_ITL_INITRANS_DEFAULT); + UT_ASSERT_EQ(ut_itl_census_resolve_calls, CLUSTER_ITL_INITRANS_DEFAULT); UT_ASSERT_EQ(ut_itl_census_dirty_hint_calls, 1); ut_itl_census_end(); } @@ -4523,13 +4318,11 @@ UT_TEST(test_43_prepared_and_unknown_census_preserve_every_slot) ut_itl_census_begin(&fixture, &result, false); ut_itl_census_outcomes[0] = CLUSTER_TX_PREPARED; - memcpy(before, ClusterPageGetItlSlots((Page) fixture.live_page), - sizeof(before)); - UT_ASSERT(!cluster_heap_test_itl_alloc_with_terminal_census( - UT_HOT_BUFFER, (TransactionId) 1302, false, &slot_index)); - UT_ASSERT_EQ(memcmp(before, - ClusterPageGetItlSlots((Page) fixture.live_page), - sizeof(before)), 0); + memcpy(before, ClusterPageGetItlSlots((Page)fixture.live_page), sizeof(before)); + UT_ASSERT(!cluster_heap_test_itl_alloc_with_terminal_census(UT_HOT_BUFFER, (TransactionId)1302, + false, &slot_index)); + UT_ASSERT_EQ(memcmp(before, ClusterPageGetItlSlots((Page)fixture.live_page), sizeof(before)), + 0); UT_ASSERT_EQ(slot_index, CLUSTER_ITL_SLOT_UNALLOCATED); UT_ASSERT_EQ(ut_itl_census_alloc_calls, 0); UT_ASSERT_EQ(ut_itl_census_resolve_calls, 8); @@ -4548,7 +4341,7 @@ UT_TEST(test_44_wrap_aba_recycles_only_after_fresh_second_census) ut_itl_census_begin(&fixture, &result, false); ut_itl_census_outcomes[0] = CLUSTER_TX_COMMITTED; ut_itl_census_mutate_wrap = true; - slot = &ClusterPageGetItlSlots((Page) fixture.live_page)[0]; + slot = &ClusterPageGetItlSlots((Page)fixture.live_page)[0]; before = *slot; UT_ASSERT_EQ(cluster_heap_test_itl_capacity_outcome(UT_HOT_BUFFER, (TransactionId)1303, false), CLUSTER_HEAP_ITL_CAPACITY_RETRY_REQUALIFY); @@ -4556,15 +4349,14 @@ UT_TEST(test_44_wrap_aba_recycles_only_after_fresh_second_census) UT_ASSERT_EQ(ut_itl_census_dirty_hint_calls, 0); /* A fresh call represents the DML owner's requalified plan. */ ut_itl_census_admission = NULL; - UT_ASSERT(cluster_heap_test_itl_alloc_with_terminal_census( - UT_HOT_BUFFER, (TransactionId) 1303, false, &slot_index)); - UT_ASSERT_EQ(slot->wrap, (uint16) (before.wrap + 1)); + UT_ASSERT(cluster_heap_test_itl_alloc_with_terminal_census(UT_HOT_BUFFER, (TransactionId)1303, + false, &slot_index)); + UT_ASSERT_EQ(slot->wrap, (uint16)(before.wrap + 1)); UT_ASSERT_EQ(slot->flags, ITL_FLAG_COMMITTED); UT_ASSERT_EQ(slot->xid, before.xid); UT_ASSERT_EQ(slot_index, 0); UT_ASSERT_EQ(ut_itl_census_alloc_calls, 1); - UT_ASSERT_EQ(ut_itl_census_resolve_calls, - 2 * CLUSTER_ITL_INITRANS_DEFAULT); + UT_ASSERT_EQ(ut_itl_census_resolve_calls, 2 * CLUSTER_ITL_INITRANS_DEFAULT); UT_ASSERT_EQ(ut_itl_census_dirty_hint_calls, 1); ut_itl_census_end(); } @@ -4581,15 +4373,13 @@ UT_TEST(test_45_cross_page_census_resolves_below_neither_content_lock) ut_itl_pair_content_lock_held[1] = true; ut_hot_content_lock_held = false; - UT_ASSERT(cluster_heap_test_itl_resolve_pair_terminal_census( - (Buffer) 1, (Buffer) 2, (Buffer) 1)); - UT_ASSERT_EQ(ut_itl_census_resolve_calls, - CLUSTER_ITL_INITRANS_DEFAULT); + UT_ASSERT(cluster_heap_test_itl_resolve_pair_terminal_census((Buffer)1, (Buffer)2, (Buffer)1)); + UT_ASSERT_EQ(ut_itl_census_resolve_calls, CLUSTER_ITL_INITRANS_DEFAULT); UT_ASSERT(!ut_itl_pair_content_lock_held[0]); UT_ASSERT(!ut_itl_pair_content_lock_held[1]); UT_ASSERT_EQ(ut_itl_pair_lock_calls, 2); - UT_ASSERT_EQ(ut_itl_pair_lock_buffers[0], (Buffer) 2); - UT_ASSERT_EQ(ut_itl_pair_lock_buffers[1], (Buffer) 1); + UT_ASSERT_EQ(ut_itl_pair_lock_buffers[0], (Buffer)2); + UT_ASSERT_EQ(ut_itl_pair_lock_buffers[1], (Buffer)1); UT_ASSERT_EQ(ut_itl_census_dirty_hint_calls, 0); ut_itl_census_end(); } @@ -4604,9 +4394,9 @@ UT_TEST(test_46_activation_generation_drift_preserves_terminal_candidate) ut_itl_census_begin(&fixture, &result, false); ut_itl_census_outcomes[0] = CLUSTER_TX_COMMITTED; ut_itl_census_mutate_activation = true; - UT_ASSERT(!cluster_heap_test_itl_alloc_with_terminal_census( - UT_HOT_BUFFER, (TransactionId) 1304, false, &slot_index)); - slots = ClusterPageGetItlSlots((Page) fixture.live_page); + UT_ASSERT(!cluster_heap_test_itl_alloc_with_terminal_census(UT_HOT_BUFFER, (TransactionId)1304, + false, &slot_index)); + slots = ClusterPageGetItlSlots((Page)fixture.live_page); UT_ASSERT_EQ(slot_index, CLUSTER_ITL_SLOT_UNALLOCATED); UT_ASSERT_EQ(slots[0].flags, ITL_FLAG_ACTIVE); UT_ASSERT_EQ(ut_itl_census_dirty_hint_calls, 0); @@ -4623,14 +4413,13 @@ UT_TEST(test_47_origin_tt_generation_is_not_compared_to_requester_counter) ut_itl_census_begin(&fixture, &result, false); ut_itl_census_outcomes[0] = CLUSTER_TX_COMMITTED; ut_itl_census_origin_tt_generation = UINT64_C(991); - UT_ASSERT(cluster_heap_test_itl_alloc_with_terminal_census( - UT_HOT_BUFFER, (TransactionId) 1305, false, &slot_index)); - slots = ClusterPageGetItlSlots((Page) fixture.live_page); + UT_ASSERT(cluster_heap_test_itl_alloc_with_terminal_census(UT_HOT_BUFFER, (TransactionId)1305, + false, &slot_index)); + slots = ClusterPageGetItlSlots((Page)fixture.live_page); UT_ASSERT_EQ(slot_index, 0); UT_ASSERT_EQ(slots[0].flags, ITL_FLAG_COMMITTED); UT_ASSERT_EQ(ut_itl_census_dirty_hint_calls, 1); - UT_ASSERT_EQ(ut_itl_census_resolve_calls, - CLUSTER_ITL_INITRANS_DEFAULT); + UT_ASSERT_EQ(ut_itl_census_resolve_calls, CLUSTER_ITL_INITRANS_DEFAULT); ut_itl_census_end(); } @@ -4640,15 +4429,13 @@ UT_TEST(test_48_same_page_full_without_borrowed_census_never_leaves_token) HeapHotSearchResult result; ut_itl_census_begin(&fixture, &result, false); - UT_ASSERT_EQ(pg_atomic_read_u32( - &ut_itl_census_semantic.inflight[CLUSTER_SEMANTIC_TARGET_SIDE][0]), 0); - UT_ASSERT_EQ(semantic_activation_local_inflight - [CLUSTER_SEMANTIC_TARGET_SIDE][0], 0); + UT_ASSERT_EQ( + pg_atomic_read_u32(&ut_itl_census_semantic.inflight[CLUSTER_SEMANTIC_TARGET_SIDE][0]), 0); + UT_ASSERT_EQ(semantic_activation_local_inflight[CLUSTER_SEMANTIC_TARGET_SIDE][0], 0); UT_ASSERT(!cluster_heap_test_itl_update_same_page_failure_cleanup()); - UT_ASSERT_EQ(pg_atomic_read_u32( - &ut_itl_census_semantic.inflight[CLUSTER_SEMANTIC_TARGET_SIDE][0]), 0); - UT_ASSERT_EQ(semantic_activation_local_inflight - [CLUSTER_SEMANTIC_TARGET_SIDE][0], 0); + UT_ASSERT_EQ( + pg_atomic_read_u32(&ut_itl_census_semantic.inflight[CLUSTER_SEMANTIC_TARGET_SIDE][0]), 0); + UT_ASSERT_EQ(semantic_activation_local_inflight[CLUSTER_SEMANTIC_TARGET_SIDE][0], 0); ut_itl_census_end(); } @@ -4664,16 +4451,15 @@ UT_TEST(test_49_known_single_node_pcm_n_resolves_and_recycles) ut_itl_census_outcomes[0] = CLUSTER_TX_COMMITTED; UT_ASSERT(!cluster_conf_has_peers()); UT_ASSERT(ut_hot_content_lock_held); - UT_ASSERT(cluster_heap_test_itl_alloc_with_terminal_census( - UT_HOT_BUFFER, (TransactionId) 1306, false, &slot_index)); - slots = ClusterPageGetItlSlots((Page) fixture.live_page); + UT_ASSERT(cluster_heap_test_itl_alloc_with_terminal_census(UT_HOT_BUFFER, (TransactionId)1306, + false, &slot_index)); + slots = ClusterPageGetItlSlots((Page)fixture.live_page); UT_ASSERT_EQ(slot_index, 0); UT_ASSERT_EQ(slots[0].flags, ITL_FLAG_COMMITTED); - UT_ASSERT_EQ((uint64) slots[0].commit_scn, UINT64_C(9001)); + UT_ASSERT_EQ((uint64)slots[0].commit_scn, UINT64_C(9001)); UT_ASSERT_EQ(ut_hot_pcm_snapshot_calls, 2); - UT_ASSERT_EQ(ut_hot_last_pcm_snapshot_state, (uint8) PCM_STATE_N); - UT_ASSERT_EQ(ut_itl_census_resolve_calls, - CLUSTER_ITL_INITRANS_DEFAULT); + UT_ASSERT_EQ(ut_hot_last_pcm_snapshot_state, (uint8)PCM_STATE_N); + UT_ASSERT_EQ(ut_itl_census_resolve_calls, CLUSTER_ITL_INITRANS_DEFAULT); UT_ASSERT_EQ(ut_itl_census_alloc_calls, 1); UT_ASSERT_EQ(ut_itl_census_dirty_hint_calls, 1); UT_ASSERT_EQ(fixture.lock_calls, 2); @@ -4690,11 +4476,11 @@ UT_TEST(test_50_peer_pcm_n_refuses_before_resolve) ut_itl_census_begin(&fixture, &result, false); ut_itl_census_force_pcm_n = true; UT_ASSERT(cluster_conf_has_peers()); - UT_ASSERT(!cluster_heap_test_itl_alloc_with_terminal_census( - UT_HOT_BUFFER, (TransactionId) 1307, false, &slot_index)); + UT_ASSERT(!cluster_heap_test_itl_alloc_with_terminal_census(UT_HOT_BUFFER, (TransactionId)1307, + false, &slot_index)); UT_ASSERT_EQ(slot_index, CLUSTER_ITL_SLOT_UNALLOCATED); UT_ASSERT_EQ(ut_hot_pcm_snapshot_calls, 1); - UT_ASSERT_EQ(ut_hot_last_pcm_snapshot_state, (uint8) PCM_STATE_N); + UT_ASSERT_EQ(ut_hot_last_pcm_snapshot_state, (uint8)PCM_STATE_N); UT_ASSERT_EQ(ut_itl_census_resolve_calls, 0); UT_ASSERT_EQ(ut_itl_census_alloc_calls, 0); UT_ASSERT_EQ(fixture.lock_calls, 0); @@ -4716,26 +4502,22 @@ UT_TEST(test_51_terminal_census_resolves_and_stamps_complete_eight_slot_set) ut_itl_census_begin(&fixture, &result, false); for (i = 0; i < CLUSTER_ITL_INITRANS_DEFAULT; i++) - ut_itl_census_outcomes[i] = (i % 2) == 0 - ? CLUSTER_TX_COMMITTED : CLUSTER_TX_ABORTED; - UT_ASSERT(cluster_heap_test_itl_alloc_with_terminal_census( - UT_HOT_BUFFER, (TransactionId) 1308, false, &slot_index)); - slots = ClusterPageGetItlSlots((Page) fixture.live_page); + ut_itl_census_outcomes[i] = (i % 2) == 0 ? CLUSTER_TX_COMMITTED : CLUSTER_TX_ABORTED; + UT_ASSERT(cluster_heap_test_itl_alloc_with_terminal_census(UT_HOT_BUFFER, (TransactionId)1308, + false, &slot_index)); + slots = ClusterPageGetItlSlots((Page)fixture.live_page); UT_ASSERT_EQ(slot_index, 0); - for (i = 0; i < CLUSTER_ITL_INITRANS_DEFAULT; i++) - { - UT_ASSERT_EQ(slots[i].flags, (i % 2) == 0 - ? ITL_FLAG_COMMITTED : ITL_FLAG_ABORTED); + for (i = 0; i < CLUSTER_ITL_INITRANS_DEFAULT; i++) { + UT_ASSERT_EQ(slots[i].flags, (i % 2) == 0 ? ITL_FLAG_COMMITTED : ITL_FLAG_ABORTED); if ((i % 2) == 0) - UT_ASSERT_EQ((uint64) slots[i].commit_scn, UINT64_C(9001)); + UT_ASSERT_EQ((uint64)slots[i].commit_scn, UINT64_C(9001)); else UT_ASSERT(!SCN_VALID(slots[i].commit_scn)); } - UT_ASSERT_EQ(ut_itl_census_resolve_calls, - CLUSTER_ITL_INITRANS_DEFAULT); + UT_ASSERT_EQ(ut_itl_census_resolve_calls, CLUSTER_ITL_INITRANS_DEFAULT); UT_ASSERT_EQ(ut_itl_census_preflight_calls, 1); - cluster_heap_test_itl_last_census_stats( - &locator_mask, &attempted_mask, &terminal_mask, &terminal_count); + cluster_heap_test_itl_last_census_stats(&locator_mask, &attempted_mask, &terminal_mask, + &terminal_count); UT_ASSERT_EQ(locator_mask, UINT8_MAX); UT_ASSERT_EQ(attempted_mask, UINT8_MAX); UT_ASSERT_EQ(terminal_mask, UINT8_MAX); @@ -4754,12 +4536,11 @@ UT_TEST(test_52_writer_activation_projection_drift_is_not_pcm_identity_drift) ut_itl_census_begin(&fixture, &result, false); ut_itl_census_outcomes[0] = CLUSTER_TX_COMMITTED; ut_itl_census_change_writer_activation_projection = true; - UT_ASSERT(cluster_heap_test_itl_alloc_with_terminal_census( - UT_HOT_BUFFER, (TransactionId) 1309, false, &slot_index)); + UT_ASSERT(cluster_heap_test_itl_alloc_with_terminal_census(UT_HOT_BUFFER, (TransactionId)1309, + false, &slot_index)); UT_ASSERT_EQ(slot_index, 0); UT_ASSERT_EQ(ut_hot_pcm_snapshot_calls, 2); - UT_ASSERT_EQ(ut_itl_census_resolve_calls, - CLUSTER_ITL_INITRANS_DEFAULT); + UT_ASSERT_EQ(ut_itl_census_resolve_calls, CLUSTER_ITL_INITRANS_DEFAULT); ut_itl_census_end(); } @@ -4776,17 +4557,16 @@ UT_TEST(test_53_stale_census_retries_only_the_relocked_current_page_once) UT_ASSERT_EQ(cluster_heap_test_itl_capacity_outcome(UT_HOT_BUFFER, (TransactionId)1310, false), CLUSTER_HEAP_ITL_CAPACITY_RETRY_REQUALIFY); UT_ASSERT_EQ(ut_itl_census_alloc_calls, 0); - UT_ASSERT(cluster_heap_test_itl_alloc_with_terminal_census( - UT_HOT_BUFFER, (TransactionId) 1310, false, &slot_index)); - slots = ClusterPageGetItlSlots((Page) fixture.live_page); + UT_ASSERT(cluster_heap_test_itl_alloc_with_terminal_census(UT_HOT_BUFFER, (TransactionId)1310, + false, &slot_index)); + slots = ClusterPageGetItlSlots((Page)fixture.live_page); UT_ASSERT_EQ(slot_index, 4); UT_ASSERT_EQ(slots[0].flags, ITL_FLAG_ACTIVE); UT_ASSERT(!SCN_VALID(slots[0].commit_scn)); UT_ASSERT_EQ(slots[4].flags, ITL_FLAG_COMMITTED); - UT_ASSERT_EQ((uint64) slots[4].commit_scn, UINT64_C(8001)); + UT_ASSERT_EQ((uint64)slots[4].commit_scn, UINT64_C(8001)); UT_ASSERT_EQ(ut_itl_census_alloc_calls, 1); - UT_ASSERT_EQ(ut_itl_census_resolve_calls, - CLUSTER_ITL_INITRANS_DEFAULT); + UT_ASSERT_EQ(ut_itl_census_resolve_calls, CLUSTER_ITL_INITRANS_DEFAULT); UT_ASSERT_EQ(ut_itl_census_dirty_hint_calls, 0); UT_ASSERT_EQ(ut_hot_pcm_snapshot_calls, 2); UT_ASSERT_EQ(fixture.lock_calls, 2); @@ -4805,18 +4585,17 @@ UT_TEST(test_54_stale_single_node_pcm_n_does_not_retry_current_page) ut_cluster_conf.node_count = 1; ut_itl_census_outcomes[0] = CLUSTER_TX_COMMITTED; ut_itl_census_replace_current_page = true; - UT_ASSERT(!cluster_heap_test_itl_alloc_with_terminal_census( - UT_HOT_BUFFER, (TransactionId) 1311, false, &slot_index)); - slots = ClusterPageGetItlSlots((Page) fixture.live_page); + UT_ASSERT(!cluster_heap_test_itl_alloc_with_terminal_census(UT_HOT_BUFFER, (TransactionId)1311, + false, &slot_index)); + slots = ClusterPageGetItlSlots((Page)fixture.live_page); UT_ASSERT_EQ(slot_index, CLUSTER_ITL_SLOT_UNALLOCATED); UT_ASSERT_EQ(slots[0].flags, ITL_FLAG_ACTIVE); UT_ASSERT(!SCN_VALID(slots[0].commit_scn)); UT_ASSERT_EQ(ut_itl_census_alloc_calls, 0); - UT_ASSERT_EQ(ut_itl_census_resolve_calls, - CLUSTER_ITL_INITRANS_DEFAULT); + UT_ASSERT_EQ(ut_itl_census_resolve_calls, CLUSTER_ITL_INITRANS_DEFAULT); UT_ASSERT_EQ(ut_itl_census_dirty_hint_calls, 0); UT_ASSERT_EQ(ut_hot_pcm_snapshot_calls, 2); - UT_ASSERT_EQ(ut_hot_last_pcm_snapshot_state, (uint8) PCM_STATE_N); + UT_ASSERT_EQ(ut_hot_last_pcm_snapshot_state, (uint8)PCM_STATE_N); UT_ASSERT(ut_hot_content_lock_held); ut_itl_census_end(); } @@ -4836,17 +4615,16 @@ UT_TEST(test_55_second_census_recaptures_fresh_identity_after_current_page_full) UT_ASSERT_EQ(ut_itl_census_alloc_calls, 0); UT_ASSERT_EQ(ut_itl_census_dirty_hint_calls, 0); ut_itl_census_admission = NULL; - UT_ASSERT(cluster_heap_test_itl_alloc_with_terminal_census( - UT_HOT_BUFFER, (TransactionId) 1312, false, &slot_index)); - slots = ClusterPageGetItlSlots((Page) fixture.live_page); + UT_ASSERT(cluster_heap_test_itl_alloc_with_terminal_census(UT_HOT_BUFFER, (TransactionId)1312, + false, &slot_index)); + slots = ClusterPageGetItlSlots((Page)fixture.live_page); UT_ASSERT(ut_itl_census_second_round_fresh_locator_seen); UT_ASSERT_EQ(slot_index, 0); - UT_ASSERT_EQ(slots[0].xid, (TransactionId) 1400); + UT_ASSERT_EQ(slots[0].xid, (TransactionId)1400); UT_ASSERT_EQ(slots[0].flags, ITL_FLAG_COMMITTED); - UT_ASSERT_EQ((uint64) slots[0].commit_scn, UINT64_C(9001)); + UT_ASSERT_EQ((uint64)slots[0].commit_scn, UINT64_C(9001)); UT_ASSERT_EQ(ut_itl_census_alloc_calls, 1); - UT_ASSERT_EQ(ut_itl_census_resolve_calls, - 2 * CLUSTER_ITL_INITRANS_DEFAULT); + UT_ASSERT_EQ(ut_itl_census_resolve_calls, 2 * CLUSTER_ITL_INITRANS_DEFAULT); UT_ASSERT_EQ(ut_itl_census_dirty_hint_calls, 1); UT_ASSERT_EQ(ut_hot_pcm_snapshot_calls, 4); UT_ASSERT_EQ(fixture.lock_calls, 4); @@ -4869,15 +4647,14 @@ UT_TEST(test_56_second_census_drift_overflows_without_third_retry) CLUSTER_HEAP_ITL_CAPACITY_RETRY_REQUALIFY); UT_ASSERT_EQ(cluster_heap_test_itl_capacity_outcome(UT_HOT_BUFFER, (TransactionId)1313, false), CLUSTER_HEAP_ITL_CAPACITY_RETRY_REQUALIFY); - slots = ClusterPageGetItlSlots((Page) fixture.live_page); + slots = ClusterPageGetItlSlots((Page)fixture.live_page); UT_ASSERT(ut_itl_census_second_round_fresh_locator_seen); UT_ASSERT_EQ(slot_index, CLUSTER_ITL_SLOT_UNALLOCATED); - UT_ASSERT_EQ(slots[0].xid, (TransactionId) 1400); + UT_ASSERT_EQ(slots[0].xid, (TransactionId)1400); UT_ASSERT_EQ(slots[0].flags, ITL_FLAG_ACTIVE); UT_ASSERT(!SCN_VALID(slots[0].commit_scn)); UT_ASSERT_EQ(ut_itl_census_alloc_calls, 0); - UT_ASSERT_EQ(ut_itl_census_resolve_calls, - 2 * CLUSTER_ITL_INITRANS_DEFAULT); + UT_ASSERT_EQ(ut_itl_census_resolve_calls, 2 * CLUSTER_ITL_INITRANS_DEFAULT); UT_ASSERT_EQ(ut_itl_census_dirty_hint_calls, 0); UT_ASSERT_EQ(ut_hot_pcm_snapshot_calls, 4); UT_ASSERT_EQ(fixture.lock_calls, 4); @@ -4900,17 +4677,16 @@ UT_TEST(test_57_terminal_census_validates_all_before_mutating_any) CLUSTER_HEAP_ITL_CAPACITY_RETRY_REQUALIFY); UT_ASSERT_EQ(ut_itl_census_alloc_calls, 0); UT_ASSERT_EQ(ut_itl_census_dirty_hint_calls, 0); - UT_ASSERT(cluster_heap_test_itl_alloc_with_terminal_census( - UT_HOT_BUFFER, (TransactionId) 1314, false, &slot_index)); - slots = ClusterPageGetItlSlots((Page) fixture.live_page); + UT_ASSERT(cluster_heap_test_itl_alloc_with_terminal_census(UT_HOT_BUFFER, (TransactionId)1314, + false, &slot_index)); + slots = ClusterPageGetItlSlots((Page)fixture.live_page); UT_ASSERT(ut_itl_census_second_terminal_mutated); UT_ASSERT_EQ(slot_index, 4); UT_ASSERT_EQ(slots[0].flags, ITL_FLAG_ACTIVE); UT_ASSERT_EQ(slots[1].flags, ITL_FLAG_ACTIVE); UT_ASSERT_EQ(slots[4].flags, ITL_FLAG_COMMITTED); - UT_ASSERT_EQ((uint64) slots[4].commit_scn, UINT64_C(8001)); - UT_ASSERT_EQ(ut_itl_census_resolve_calls, - CLUSTER_ITL_INITRANS_DEFAULT); + UT_ASSERT_EQ((uint64)slots[4].commit_scn, UINT64_C(8001)); + UT_ASSERT_EQ(ut_itl_census_resolve_calls, CLUSTER_ITL_INITRANS_DEFAULT); UT_ASSERT_EQ(ut_itl_census_alloc_calls, 1); UT_ASSERT_EQ(ut_itl_census_dirty_hint_calls, 0); ut_itl_census_end(); @@ -4930,9 +4706,9 @@ UT_TEST(test_58_terminal_census_continues_past_nonterminal_outcomes) ut_itl_census_outcomes[4] = CLUSTER_TX_ABORTED; ut_itl_census_outcomes[6] = CLUSTER_TX_PREPARED; ut_itl_census_outcomes[7] = CLUSTER_TX_COMMITTED; - UT_ASSERT(cluster_heap_test_itl_alloc_with_terminal_census( - UT_HOT_BUFFER, (TransactionId) 1315, false, &slot_index)); - slots = ClusterPageGetItlSlots((Page) fixture.live_page); + UT_ASSERT(cluster_heap_test_itl_alloc_with_terminal_census(UT_HOT_BUFFER, (TransactionId)1315, + false, &slot_index)); + slots = ClusterPageGetItlSlots((Page)fixture.live_page); UT_ASSERT_EQ(slot_index, 3); UT_ASSERT_EQ(slots[0].flags, ITL_FLAG_ACTIVE); UT_ASSERT_EQ(slots[1].flags, ITL_FLAG_ACTIVE); @@ -4942,8 +4718,7 @@ UT_TEST(test_58_terminal_census_continues_past_nonterminal_outcomes) UT_ASSERT_EQ(slots[5].flags, ITL_FLAG_ACTIVE); UT_ASSERT_EQ(slots[6].flags, ITL_FLAG_ACTIVE); UT_ASSERT_EQ(slots[7].flags, ITL_FLAG_COMMITTED); - UT_ASSERT_EQ(ut_itl_census_resolve_calls, - CLUSTER_ITL_INITRANS_DEFAULT); + UT_ASSERT_EQ(ut_itl_census_resolve_calls, CLUSTER_ITL_INITRANS_DEFAULT); UT_ASSERT_EQ(ut_itl_census_dirty_hint_calls, 1); ut_itl_census_end(); } @@ -4959,30 +4734,24 @@ UT_TEST(test_59_one_batch_leaves_capacity_for_three_stale_followers) ut_itl_census_begin(&fixture, &result, false); for (i = 0; i < CLUSTER_ITL_INITRANS_DEFAULT; i++) - ut_itl_census_outcomes[i] = (i % 2) == 0 - ? CLUSTER_TX_COMMITTED : CLUSTER_TX_ABORTED; + ut_itl_census_outcomes[i] = (i % 2) == 0 ? CLUSTER_TX_COMMITTED : CLUSTER_TX_ABORTED; ut_itl_census_consume_allocated_slot = true; - for (i = 0; i < 4; i++) - { + for (i = 0; i < 4; i++) { UT_ASSERT(cluster_heap_test_itl_alloc_with_terminal_census( - UT_HOT_BUFFER, (TransactionId) (1316 + i), false, &slot_index)); + UT_HOT_BUFFER, (TransactionId)(1316 + i), false, &slot_index)); UT_ASSERT_EQ(slot_index, i); } - slots = ClusterPageGetItlSlots((Page) fixture.live_page); - for (i = 0; i < CLUSTER_ITL_INITRANS_DEFAULT; i++) - { - if (slots[i].flags == ITL_FLAG_COMMITTED - || slots[i].flags == ITL_FLAG_ABORTED) + slots = ClusterPageGetItlSlots((Page)fixture.live_page); + for (i = 0; i < CLUSTER_ITL_INITRANS_DEFAULT; i++) { + if (slots[i].flags == ITL_FLAG_COMMITTED || slots[i].flags == ITL_FLAG_ABORTED) reusable_count++; - if (i < 4) - { + if (i < 4) { UT_ASSERT_EQ(slots[i].flags, ITL_FLAG_ACTIVE); - UT_ASSERT_EQ(slots[i].xid, (TransactionId) (1316 + i)); + UT_ASSERT_EQ(slots[i].xid, (TransactionId)(1316 + i)); } } UT_ASSERT_EQ(reusable_count, 4); - UT_ASSERT_EQ(ut_itl_census_resolve_calls, - CLUSTER_ITL_INITRANS_DEFAULT); + UT_ASSERT_EQ(ut_itl_census_resolve_calls, CLUSTER_ITL_INITRANS_DEFAULT); UT_ASSERT_EQ(ut_itl_census_alloc_calls, 4); UT_ASSERT_EQ(ut_itl_census_dirty_hint_calls, 1); ut_itl_census_end(); @@ -4996,8 +4765,8 @@ UT_TEST(test_60_same_page_peer_census_uses_exact_holder_singleflight) ut_itl_census_begin(&fixture, &result, false); ut_itl_census_outcomes[0] = CLUSTER_TX_COMMITTED; - UT_ASSERT(cluster_heap_test_itl_alloc_with_terminal_census( - UT_HOT_BUFFER, (TransactionId) 1320, false, &slot_index)); + UT_ASSERT(cluster_heap_test_itl_alloc_with_terminal_census(UT_HOT_BUFFER, (TransactionId)1320, + false, &slot_index)); UT_ASSERT_EQ(slot_index, 0); UT_ASSERT_EQ(ut_itl_recycle_guard_arm_calls, 1); UT_ASSERT_EQ(ut_itl_recycle_guard_unlock_calls, 1); @@ -5016,18 +4785,17 @@ UT_TEST(test_61_precommit_cleanout_requires_exact_terminal_census) ClusterItlSlotData *slots; ut_itl_census_begin(&fixture, &result, false); - slots = ClusterPageGetItlSlots((Page) fixture.live_page); + slots = ClusterPageGetItlSlots((Page)fixture.live_page); slots[0].flags = ITL_FLAG_NEEDS_CLEANOUT; - slots[0].commit_scn = (SCN) UINT64_C(9001); + slots[0].commit_scn = (SCN)UINT64_C(9001); ut_itl_census_outcomes[0] = CLUSTER_TX_COMMITTED; - UT_ASSERT(cluster_heap_test_itl_alloc_with_terminal_census( - UT_HOT_BUFFER, (TransactionId) 1321, false, &slot_index)); + UT_ASSERT(cluster_heap_test_itl_alloc_with_terminal_census(UT_HOT_BUFFER, (TransactionId)1321, + false, &slot_index)); UT_ASSERT_EQ(slot_index, 0); UT_ASSERT_EQ(slots[0].flags, ITL_FLAG_COMMITTED); - UT_ASSERT_EQ((uint64) slots[0].commit_scn, UINT64_C(9001)); - UT_ASSERT_EQ(ut_itl_census_resolve_calls, - CLUSTER_ITL_INITRANS_DEFAULT); + UT_ASSERT_EQ((uint64)slots[0].commit_scn, UINT64_C(9001)); + UT_ASSERT_EQ(ut_itl_census_resolve_calls, CLUSTER_ITL_INITRANS_DEFAULT); UT_ASSERT_EQ(ut_itl_census_dirty_hint_calls, 1); ut_itl_census_end(); } @@ -5040,18 +4808,17 @@ UT_TEST(test_62_in_progress_cleanout_evidence_is_never_stamped) ClusterItlSlotData *slots; ut_itl_census_begin(&fixture, &result, false); - slots = ClusterPageGetItlSlots((Page) fixture.live_page); + slots = ClusterPageGetItlSlots((Page)fixture.live_page); slots[0].flags = ITL_FLAG_NEEDS_CLEANOUT; - slots[0].commit_scn = (SCN) UINT64_C(8001); + slots[0].commit_scn = (SCN)UINT64_C(8001); ut_itl_census_outcomes[0] = CLUSTER_TX_IN_PROGRESS; - UT_ASSERT(!cluster_heap_test_itl_alloc_with_terminal_census( - UT_HOT_BUFFER, (TransactionId) 1322, false, &slot_index)); + UT_ASSERT(!cluster_heap_test_itl_alloc_with_terminal_census(UT_HOT_BUFFER, (TransactionId)1322, + false, &slot_index)); UT_ASSERT_EQ(slot_index, CLUSTER_ITL_SLOT_UNALLOCATED); UT_ASSERT_EQ(slots[0].flags, ITL_FLAG_NEEDS_CLEANOUT); - UT_ASSERT_EQ((uint64) slots[0].commit_scn, UINT64_C(8001)); - UT_ASSERT_EQ(ut_itl_census_resolve_calls, - CLUSTER_ITL_INITRANS_DEFAULT); + UT_ASSERT_EQ((uint64)slots[0].commit_scn, UINT64_C(8001)); + UT_ASSERT_EQ(ut_itl_census_resolve_calls, CLUSTER_ITL_INITRANS_DEFAULT); UT_ASSERT_EQ(ut_itl_census_dirty_hint_calls, 0); ut_itl_census_end(); } @@ -5064,23 +4831,22 @@ UT_TEST(test_63_cleanout_evidence_scn_drift_is_never_stamped) ClusterItlSlotData *slots; ut_itl_census_begin(&fixture, &result, false); - slots = ClusterPageGetItlSlots((Page) fixture.live_page); + slots = ClusterPageGetItlSlots((Page)fixture.live_page); slots[0].flags = ITL_FLAG_NEEDS_CLEANOUT; - slots[0].commit_scn = (SCN) UINT64_C(8001); + slots[0].commit_scn = (SCN)UINT64_C(8001); ut_itl_census_outcomes[0] = CLUSTER_TX_COMMITTED; - UT_ASSERT(!cluster_heap_test_itl_alloc_with_terminal_census( - UT_HOT_BUFFER, (TransactionId) 1323, false, &slot_index)); + UT_ASSERT(!cluster_heap_test_itl_alloc_with_terminal_census(UT_HOT_BUFFER, (TransactionId)1323, + false, &slot_index)); UT_ASSERT_EQ(slot_index, CLUSTER_ITL_SLOT_UNALLOCATED); UT_ASSERT_EQ(slots[0].flags, ITL_FLAG_NEEDS_CLEANOUT); - UT_ASSERT_EQ((uint64) slots[0].commit_scn, UINT64_C(8001)); + UT_ASSERT_EQ((uint64)slots[0].commit_scn, UINT64_C(8001)); UT_ASSERT_EQ(ut_itl_census_dirty_hint_calls, 0); ut_itl_census_end(); } static void -ut_dml_guard_advance_hint_lsn(Buffer buffer, HeapTuple tuple pg_attribute_unused(), - void *arg) +ut_dml_guard_advance_hint_lsn(Buffer buffer, HeapTuple tuple pg_attribute_unused(), void *arg) { int saved_node_id = cluster_node_id; @@ -5088,14 +4854,13 @@ ut_dml_guard_advance_hint_lsn(Buffer buffer, HeapTuple tuple pg_attribute_unused * census hint FPI legitimately advances both pd_lsn and its origin to * this writer's stream. */ cluster_node_id = saved_node_id == 3 ? 2 : 3; - PageSetLSN(BufferGetPage(buffer), *(XLogRecPtr *) arg); + PageSetLSN(BufferGetPage(buffer), *(XLogRecPtr *)arg); cluster_node_id = saved_node_id; } static void -ut_dml_guard_drift_pcm(Buffer buffer pg_attribute_unused(), - HeapTuple tuple pg_attribute_unused(), - void *arg pg_attribute_unused()) +ut_dml_guard_drift_pcm(Buffer buffer pg_attribute_unused(), HeapTuple tuple pg_attribute_unused(), + void *arg pg_attribute_unused()) { ut_itl_census_replace_current_page = true; } @@ -5109,7 +4874,7 @@ ut_dml_guard_drift_tuple(Buffer buffer pg_attribute_unused(), HeapTuple tuple, static void ut_dml_guard_begin_revoke(Buffer buffer pg_attribute_unused(), - HeapTuple tuple pg_attribute_unused(), void *arg pg_attribute_unused()) + HeapTuple tuple pg_attribute_unused(), void *arg pg_attribute_unused()) { ut_itl_census_pcm_reservation_token++; ut_itl_census_pcm_flags = PCM_OWN_FLAG_REVOKING; @@ -5117,25 +4882,23 @@ ut_dml_guard_begin_revoke(Buffer buffer pg_attribute_unused(), static void ut_dml_guard_abort_revoke(Buffer buffer pg_attribute_unused(), - HeapTuple tuple pg_attribute_unused(), void *arg pg_attribute_unused()) + HeapTuple tuple pg_attribute_unused(), void *arg pg_attribute_unused()) { ut_itl_census_pcm_flags = 0; } static void -ut_dml_guard_occupy_selected_slot(Buffer buffer, - HeapTuple tuple pg_attribute_unused(), void *arg) +ut_dml_guard_occupy_selected_slot(Buffer buffer, HeapTuple tuple pg_attribute_unused(), void *arg) { - uint8 slot_index = *(uint8 *) arg; - ClusterItlSlotData *slot - = &ClusterPageGetItlSlots(BufferGetPage(buffer))[slot_index]; + uint8 slot_index = *(uint8 *)arg; + ClusterItlSlotData *slot = &ClusterPageGetItlSlots(BufferGetPage(buffer))[slot_index]; - slot->xid = (TransactionId) 9911; + slot->xid = (TransactionId)9911; slot->wrap++; slot->flags = ITL_FLAG_ACTIVE; slot->lock_count = 3; slot->undo_segment_head = uba_encode(9, 8, 7, 6); - slot->write_scn = (SCN) UINT64_C(0x99112233); + slot->write_scn = (SCN)UINT64_C(0x99112233); } UT_TEST(test_64_dml_guard_allows_terminal_hint_lsn_but_rejects_authority_drift) @@ -5143,14 +4906,12 @@ UT_TEST(test_64_dml_guard_allows_terminal_hint_lsn_but_rejects_authority_drift) UtR4HotProductFixture fixture; HeapHotSearchResult result; HeapTupleData tuple; - XLogRecPtr hint_lsn = (XLogRecPtr) UINT64_C(0x334466); + XLogRecPtr hint_lsn = (XLogRecPtr)UINT64_C(0x334466); ut_itl_census_begin(&fixture, &result, false); memset(&tuple, 0, sizeof(tuple)); - tuple.t_data = ut_r4_hot_tuple_at((Page) fixture.live_page, - UT_HOT_ROOT_OFF); - tuple.t_len = ItemIdGetLength( - PageGetItemId((Page) fixture.live_page, UT_HOT_ROOT_OFF)); + tuple.t_data = ut_r4_hot_tuple_at((Page)fixture.live_page, UT_HOT_ROOT_OFF); + tuple.t_len = ItemIdGetLength(PageGetItemId((Page)fixture.live_page, UT_HOT_ROOT_OFF)); ItemPointerSet(&tuple.t_self, UT_HOT_BLOCK, UT_HOT_ROOT_OFF); /* A terminal-census hint FPI may advance the page LSN and its coupled @@ -5162,8 +4923,8 @@ UT_TEST(test_64_dml_guard_allows_terminal_hint_lsn_but_rejects_authority_drift) * is diagnostic projection, not Resource-X/PCM identity. */ ut_hot_pcm_snapshot_calls = 0; ut_itl_census_change_writer_activation_projection = true; - UT_ASSERT(cluster_heap_test_dml_authority_guard_recheck_with_hook( - UT_HOT_BUFFER, &tuple, NULL, NULL)); + UT_ASSERT( + cluster_heap_test_dml_authority_guard_recheck_with_hook(UT_HOT_BUFFER, &tuple, NULL, NULL)); ut_itl_census_change_writer_activation_projection = false; /* A27: a type-17 drain can publish or exact-abort REVOKING after this @@ -5200,12 +4961,10 @@ UT_TEST(test_81_terminal_census_transient_lifecycle_is_typed_retry) /* HANDOFF can become visible between capture and the exact RECYCLING * claim. The bufmgr seam reports that collision without arming debt. */ ut_itl_census_begin(&fixture, &result, false); - ut_itl_recycle_guard_arm_result - = CLUSTER_BUFMGR_ITL_RECYCLE_RETRY_REQUALIFY; - capacity_result = cluster_heap_test_itl_capacity_outcome( - UT_HOT_BUFFER, (TransactionId) 1381, false); - UT_ASSERT_EQ(capacity_result, - CLUSTER_HEAP_ITL_CAPACITY_RETRY_REQUALIFY); + ut_itl_recycle_guard_arm_result = CLUSTER_BUFMGR_ITL_RECYCLE_RETRY_REQUALIFY; + capacity_result + = cluster_heap_test_itl_capacity_outcome(UT_HOT_BUFFER, (TransactionId)1381, false); + UT_ASSERT_EQ(capacity_result, CLUSTER_HEAP_ITL_CAPACITY_RETRY_REQUALIFY); UT_ASSERT_EQ(ut_itl_recycle_guard_arm_calls, 1); UT_ASSERT_EQ(ut_itl_recycle_guard_unlock_calls, 0); UT_ASSERT_EQ(ut_itl_recycle_guard_relock_calls, 0); @@ -5220,10 +4979,9 @@ UT_TEST(test_81_terminal_census_transient_lifecycle_is_typed_retry) ut_itl_census_begin(&fixture, &result, false); ut_itl_census_pcm_reservation_token = UINT64_C(18); ut_itl_census_pcm_flags = PCM_OWN_FLAG_REVOKING; - capacity_result = cluster_heap_test_itl_capacity_outcome( - UT_HOT_BUFFER, (TransactionId) 1382, false); - UT_ASSERT_EQ(capacity_result, - CLUSTER_HEAP_ITL_CAPACITY_RETRY_REQUALIFY); + capacity_result + = cluster_heap_test_itl_capacity_outcome(UT_HOT_BUFFER, (TransactionId)1382, false); + UT_ASSERT_EQ(capacity_result, CLUSTER_HEAP_ITL_CAPACITY_RETRY_REQUALIFY); UT_ASSERT_EQ(ut_hot_pcm_snapshot_calls, 1); UT_ASSERT_EQ(ut_itl_recycle_guard_arm_calls, 0); UT_ASSERT_EQ(ut_itl_census_resolve_calls, 0); @@ -5244,12 +5002,11 @@ UT_TEST(test_82_cross_page_transient_census_releases_both_locks) ut_itl_census_pcm_reservation_token = UINT64_C(18); ut_itl_census_pcm_flags = PCM_OWN_FLAG_REVOKING; - UT_ASSERT(!cluster_heap_test_itl_resolve_pair_terminal_census( - (Buffer) 1, (Buffer) 2, (Buffer) 1)); + UT_ASSERT(!cluster_heap_test_itl_resolve_pair_terminal_census((Buffer)1, (Buffer)2, (Buffer)1)); UT_ASSERT_EQ(ut_itl_census_resolve_calls, 0); UT_ASSERT_EQ(ut_itl_pair_lock_calls, 2); - UT_ASSERT_EQ(ut_itl_pair_lock_buffers[0], (Buffer) 2); - UT_ASSERT_EQ(ut_itl_pair_lock_buffers[1], (Buffer) 1); + UT_ASSERT_EQ(ut_itl_pair_lock_buffers[0], (Buffer)2); + UT_ASSERT_EQ(ut_itl_pair_lock_buffers[1], (Buffer)1); UT_ASSERT(!ut_itl_pair_content_lock_held[0]); UT_ASSERT(!ut_itl_pair_content_lock_held[1]); ut_itl_census_end(); @@ -5265,15 +5022,12 @@ UT_TEST(test_69_dml_guard_rejects_selected_itl_slot_only_aba) ut_itl_census_begin(&fixture, &result, false); memset(&tuple, 0, sizeof(tuple)); - tuple.t_data = ut_r4_hot_tuple_at((Page) fixture.live_page, - UT_HOT_ROOT_OFF); - tuple.t_len = ItemIdGetLength( - PageGetItemId((Page) fixture.live_page, UT_HOT_ROOT_OFF)); + tuple.t_data = ut_r4_hot_tuple_at((Page)fixture.live_page, UT_HOT_ROOT_OFF); + tuple.t_len = ItemIdGetLength(PageGetItemId((Page)fixture.live_page, UT_HOT_ROOT_OFF)); ItemPointerSet(&tuple.t_self, UT_HOT_BLOCK, UT_HOT_ROOT_OFF); original_infomask = tuple.t_data->t_infomask; UT_ASSERT(!cluster_heap_test_dml_authority_guard_slot_recheck_with_hook( - UT_HOT_BUFFER, &tuple, slot_index, - ut_dml_guard_occupy_selected_slot, &slot_index)); + UT_HOT_BUFFER, &tuple, slot_index, ut_dml_guard_occupy_selected_slot, &slot_index)); UT_ASSERT_EQ(tuple.t_data->t_infomask, original_infomask); ut_itl_census_end(); } @@ -5283,14 +5037,11 @@ UT_TEST(test_70_all_heap_callers_retry_only_from_zero_apply_drift) ClusterHeapNoRetryTestCaller caller; for (caller = CLUSTER_HEAP_NO_RETRY_TEST_INSERT; - caller <= CLUSTER_HEAP_NO_RETRY_TEST_UPDATE_CHAIN; caller++) - { + caller <= CLUSTER_HEAP_NO_RETRY_TEST_UPDATE_CHAIN; caller++) { ClusterHeapNoRetryTestReport report; - UT_ASSERT(cluster_heap_test_no_retry_boundary( - caller, true, false, &report)); - UT_ASSERT_EQ(report.outcome, - CLUSTER_HEAP_NO_RETRY_TEST_ZERO_APPLY_RETRY); + UT_ASSERT(cluster_heap_test_no_retry_boundary(caller, true, false, &report)); + UT_ASSERT_EQ(report.outcome, CLUSTER_HEAP_NO_RETRY_TEST_ZERO_APPLY_RETRY); UT_ASSERT_EQ(report.apply_calls, 0); UT_ASSERT_EQ(report.consume_calls, 0); UT_ASSERT(report.retry_edge); @@ -5302,14 +5053,11 @@ UT_TEST(test_71_all_heap_callers_refuse_partial_apply_without_retry_edge) ClusterHeapNoRetryTestCaller caller; for (caller = CLUSTER_HEAP_NO_RETRY_TEST_INSERT; - caller <= CLUSTER_HEAP_NO_RETRY_TEST_UPDATE_CHAIN; caller++) - { + caller <= CLUSTER_HEAP_NO_RETRY_TEST_UPDATE_CHAIN; caller++) { ClusterHeapNoRetryTestReport report; - UT_ASSERT(cluster_heap_test_no_retry_boundary( - caller, false, true, &report)); - UT_ASSERT_EQ(report.outcome, - CLUSTER_HEAP_NO_RETRY_TEST_REFUSED); + UT_ASSERT(cluster_heap_test_no_retry_boundary(caller, false, true, &report)); + UT_ASSERT_EQ(report.outcome, CLUSTER_HEAP_NO_RETRY_TEST_REFUSED); UT_ASSERT(report.preflight_calls > 0); UT_ASSERT(report.apply_calls > 0); UT_ASSERT_EQ(report.consume_calls, 0); @@ -5322,26 +5070,21 @@ UT_TEST(test_71_all_heap_callers_refuse_partial_apply_without_retry_edge) * consumed only after the final receipt has become APPLIED. */ UT_TEST(test_76_all_heap_callers_preflight_apply_then_consume) { - static const uint8 expected_undo_plans[] = {1, 1, 2, 0, 1, 1}; - static const uint8 expected_mx_publications[] = {0, 1, 2, 1, 1, 0}; + static const uint8 expected_undo_plans[] = { 1, 1, 2, 0, 1, 1 }; + static const uint8 expected_mx_publications[] = { 0, 1, 2, 1, 1, 0 }; ClusterHeapNoRetryTestCaller caller; for (caller = CLUSTER_HEAP_NO_RETRY_TEST_INSERT; - caller <= CLUSTER_HEAP_NO_RETRY_TEST_UPDATE_CHAIN; caller++) - { + caller <= CLUSTER_HEAP_NO_RETRY_TEST_UPDATE_CHAIN; caller++) { ClusterHeapNoRetryTestReport report; - uint8 expected_total = expected_undo_plans[caller] - + expected_mx_publications[caller]; + uint8 expected_total = expected_undo_plans[caller] + expected_mx_publications[caller]; - UT_ASSERT(cluster_heap_test_no_retry_boundary( - caller, false, false, &report)); + UT_ASSERT(cluster_heap_test_no_retry_boundary(caller, false, false, &report)); UT_ASSERT_EQ(report.outcome, CLUSTER_HEAP_NO_RETRY_TEST_APPLIED); UT_ASSERT_EQ(report.preflight_calls, expected_total); UT_ASSERT_EQ(report.apply_calls, expected_total); - UT_ASSERT_EQ(report.consume_calls, - expected_undo_plans[caller] == 0 ? 0 : 1); - UT_ASSERT_EQ(report.retained_undo_handle_count, - expected_undo_plans[caller]); + UT_ASSERT_EQ(report.consume_calls, expected_undo_plans[caller] == 0 ? 0 : 1); + UT_ASSERT_EQ(report.retained_undo_handle_count, expected_undo_plans[caller]); UT_ASSERT(report.last_preflight_event > 0); UT_ASSERT(report.first_apply_event > report.last_preflight_event); if (report.consume_calls != 0) @@ -5362,8 +5105,8 @@ UT_TEST(test_77_heap_prepare_retries_with_one_frozen_deadline) }; ClusterHeapPrepareRetryTestReport report; - UT_ASSERT(cluster_heap_test_prepare_retry_sequence(results, - lengthof(results), UINT64_C(987654321), &report)); + UT_ASSERT(cluster_heap_test_prepare_retry_sequence(results, lengthof(results), + UINT64_C(987654321), &report)); UT_ASSERT_EQ(report.prepare_calls, 3); UT_ASSERT(report.deadline_stable); UT_ASSERT_EQ(report.observed_deadline_us, UINT64_C(987654321)); @@ -5379,8 +5122,8 @@ UT_TEST(test_78_heap_prepare_refusal_stops_without_extra_attempt) }; ClusterHeapPrepareRetryTestReport report; - UT_ASSERT(!cluster_heap_test_prepare_retry_sequence(results, - lengthof(results), UINT64_C(123456789), &report)); + UT_ASSERT(!cluster_heap_test_prepare_retry_sequence(results, lengthof(results), + UINT64_C(123456789), &report)); UT_ASSERT_EQ(report.prepare_calls, 2); UT_ASSERT(report.deadline_stable); UT_ASSERT_EQ(report.observed_deadline_us, UINT64_C(123456789)); @@ -5389,36 +5132,29 @@ UT_TEST(test_78_heap_prepare_refusal_stops_without_extra_attempt) UT_TEST(test_72_itl_reference_admission_requires_current_receipt_identity) { - UT_ASSERT(cluster_heap_test_itl_receipt_identity_admitted( - FirstNormalTransactionId, 1)); - UT_ASSERT(cluster_heap_test_itl_receipt_identity_admitted( - FirstNormalTransactionId, UINT16_MAX)); - UT_ASSERT(!cluster_heap_test_itl_receipt_identity_admitted( - InvalidTransactionId, 1)); - UT_ASSERT(!cluster_heap_test_itl_receipt_identity_admitted( - FirstNormalTransactionId, 0)); - UT_ASSERT(!cluster_heap_test_itl_receipt_identity_admitted( - FirstNormalTransactionId, ((uint32) UINT16_MAX) + 1)); + UT_ASSERT(cluster_heap_test_itl_receipt_identity_admitted(FirstNormalTransactionId, 1)); + UT_ASSERT( + cluster_heap_test_itl_receipt_identity_admitted(FirstNormalTransactionId, UINT16_MAX)); + UT_ASSERT(!cluster_heap_test_itl_receipt_identity_admitted(InvalidTransactionId, 1)); + UT_ASSERT(!cluster_heap_test_itl_receipt_identity_admitted(FirstNormalTransactionId, 0)); + UT_ASSERT(!cluster_heap_test_itl_receipt_identity_admitted(FirstNormalTransactionId, + ((uint32)UINT16_MAX) + 1)); } UT_TEST(test_73_current_multi_insert_delegates_to_receipt_safe_heap_insert) { UT_ASSERT_EQ(cluster_heap_test_multi_insert_route(false), - CLUSTER_HEAP_MULTI_INSERT_NATIVE_BATCH); + CLUSTER_HEAP_MULTI_INSERT_NATIVE_BATCH); UT_ASSERT_EQ(cluster_heap_test_multi_insert_route(true), - CLUSTER_HEAP_MULTI_INSERT_RECEIPT_SAFE_PER_TUPLE); + CLUSTER_HEAP_MULTI_INSERT_RECEIPT_SAFE_PER_TUPLE); } UT_TEST(test_75_update_predicts_successor_only_for_receipt_consumers) { - UT_ASSERT(!cluster_heap_test_update_needs_successor_prediction( - false, false)); - UT_ASSERT(cluster_heap_test_update_needs_successor_prediction( - true, false)); - UT_ASSERT(cluster_heap_test_update_needs_successor_prediction( - false, true)); - UT_ASSERT(cluster_heap_test_update_needs_successor_prediction( - true, true)); + UT_ASSERT(!cluster_heap_test_update_needs_successor_prediction(false, false)); + UT_ASSERT(cluster_heap_test_update_needs_successor_prediction(true, false)); + UT_ASSERT(cluster_heap_test_update_needs_successor_prediction(false, true)); + UT_ASSERT(cluster_heap_test_update_needs_successor_prediction(true, true)); } /* A local catalog page has no PCM generation and therefore cannot produce a @@ -5427,16 +5163,16 @@ UT_TEST(test_75_update_predicts_successor_only_for_receipt_consumers) * the cluster path. */ UT_TEST(test_80_itl_route_matches_shared_relation_boundary) { - UT_ASSERT(!cluster_heap_test_itl_relation_route( - false, false, false, (RelFileNumber) FirstNormalObjectId)); - UT_ASSERT(!cluster_heap_test_itl_relation_route( - true, true, true, (RelFileNumber) FirstNormalObjectId)); - UT_ASSERT(!cluster_heap_test_itl_relation_route( - true, false, false, (RelFileNumber) (FirstNormalObjectId - 1))); - UT_ASSERT(cluster_heap_test_itl_relation_route( - true, false, true, (RelFileNumber) (FirstNormalObjectId - 1))); - UT_ASSERT(cluster_heap_test_itl_relation_route( - true, false, false, (RelFileNumber) FirstNormalObjectId)); + UT_ASSERT(!cluster_heap_test_itl_relation_route(false, false, false, + (RelFileNumber)FirstNormalObjectId)); + UT_ASSERT(!cluster_heap_test_itl_relation_route(true, true, true, + (RelFileNumber)FirstNormalObjectId)); + UT_ASSERT(!cluster_heap_test_itl_relation_route(true, false, false, + (RelFileNumber)(FirstNormalObjectId - 1))); + UT_ASSERT(cluster_heap_test_itl_relation_route(true, false, true, + (RelFileNumber)(FirstNormalObjectId - 1))); + UT_ASSERT(cluster_heap_test_itl_relation_route(true, false, false, + (RelFileNumber)FirstNormalObjectId)); } UT_TEST(test_65_batch_cleanout_routes_every_retained_scn_to_exact_c1b_pair) @@ -5448,23 +5184,20 @@ UT_TEST(test_65_batch_cleanout_routes_every_retained_scn_to_exact_c1b_pair) uint8 i; ut_itl_census_begin(&fixture, &result, false); - slots = ClusterPageGetItlSlots((Page) fixture.live_page); - for (i = 0; i < CLUSTER_ITL_INITRANS_DEFAULT; i++) - { + slots = ClusterPageGetItlSlots((Page)fixture.live_page); + for (i = 0; i < CLUSTER_ITL_INITRANS_DEFAULT; i++) { slots[i].flags = ITL_FLAG_NEEDS_CLEANOUT; - slots[i].commit_scn = (SCN) UINT64_C(9001); + slots[i].commit_scn = (SCN)UINT64_C(9001); ut_itl_census_outcomes[i] = CLUSTER_TX_COMMITTED; } - UT_ASSERT(cluster_heap_test_itl_alloc_with_terminal_census( - UT_HOT_BUFFER, (TransactionId) 1324, false, &slot_index)); + UT_ASSERT(cluster_heap_test_itl_alloc_with_terminal_census(UT_HOT_BUFFER, (TransactionId)1324, + false, &slot_index)); UT_ASSERT_EQ(slot_index, 0); - UT_ASSERT_EQ(ut_itl_census_retained_resolve_calls, - CLUSTER_ITL_INITRANS_DEFAULT); - for (i = 0; i < CLUSTER_ITL_INITRANS_DEFAULT; i++) - { + UT_ASSERT_EQ(ut_itl_census_retained_resolve_calls, CLUSTER_ITL_INITRANS_DEFAULT); + for (i = 0; i < CLUSTER_ITL_INITRANS_DEFAULT; i++) { UT_ASSERT_EQ(slots[i].flags, ITL_FLAG_COMMITTED); - UT_ASSERT_EQ((uint64) slots[i].commit_scn, UINT64_C(9001)); + UT_ASSERT_EQ((uint64)slots[i].commit_scn, UINT64_C(9001)); } ut_itl_census_end(); } @@ -5548,7 +5281,7 @@ UT_TEST(test_67_one_member_current_mx_reaches_standard_hot_consumer) ut_native_multixact_decode_calls = 0; cluster_r4_activation_test_current_epoch = UT_HOT_CURRENT_EPOCH; ut_hot_current_mx_active = true; - ut_hot_current_mx_pcm_state = (uint8) PCM_STATE_S; + ut_hot_current_mx_pcm_state = (uint8)PCM_STATE_S; ut_hot_current_mx_member_count = 1; memset(&ut_hot_successor_ref, 0, sizeof(ut_hot_successor_ref)); ut_hot_successor_ref.origin_node_id = UT_HOT_CURRENT_MX_ORIGIN; @@ -5572,8 +5305,7 @@ UT_TEST(test_67_one_member_current_mx_reaches_standard_hot_consumer) ItemPointerSet(&tid, UT_HOT_BLOCK, UT_HOT_ROOT_OFF); /* first_call=false makes the real consumer traverse past the known root. */ - found = heap_hot_search_buffer(&tid, &relation, UT_HOT_BUFFER, - &snapshot, &tuple, NULL, false); + found = heap_hot_search_buffer(&tid, &relation, UT_HOT_BUFFER, &snapshot, &tuple, NULL, false); UT_ASSERT(found); UT_ASSERT_EQ(ItemPointerGetOffsetNumber(&tid), UT_HOT_SUCCESSOR_OFF); UT_ASSERT_EQ(HeapTupleHeaderGetRawXmin(tuple.t_data), UT_HOT_AUTH_UPDATER); @@ -5583,7 +5315,7 @@ UT_TEST(test_67_one_member_current_mx_reaches_standard_hot_consumer) UT_ASSERT_EQ(ut_native_multixact_decode_calls, 0); LockBuffer(UT_HOT_BUFFER, BUFFER_LOCK_UNLOCK); - ut_hot_current_mx_pcm_state = (uint8) PCM_STATE_X; + ut_hot_current_mx_pcm_state = (uint8)PCM_STATE_X; ut_hot_current_mx_member_count = 2; ut_hot_current_mx_active = false; ut_hot_production_core_active = false; @@ -5606,9 +5338,9 @@ UT_TEST(test_68_one_member_current_mx_reaches_ordinary_heap_consumer) ut_r4_hot_init_product_fixture(&fixture, &fixture_result); ut_r4_hot_build_foreign_multixact_chain(fixture.live_page); - root = ut_r4_hot_tuple_at((Page) fixture.live_page, UT_HOT_ROOT_OFF); - root->t_infomask = HEAP_XMIN_COMMITTED | HEAP_XMAX_IS_MULTI - | HEAP_XMAX_KEYSHR_LOCK | HEAP_XMAX_LOCK_ONLY; + root = ut_r4_hot_tuple_at((Page)fixture.live_page, UT_HOT_ROOT_OFF); + root->t_infomask + = HEAP_XMIN_COMMITTED | HEAP_XMAX_IS_MULTI | HEAP_XMAX_KEYSHR_LOCK | HEAP_XMAX_LOCK_ONLY; root->t_infomask2 = 0; ItemPointerSet(&root->t_ctid, UT_HOT_BLOCK, UT_HOT_ROOT_OFF); @@ -5634,15 +5366,14 @@ UT_TEST(test_68_one_member_current_mx_reaches_ordinary_heap_consumer) relation_form.relpersistence = RELPERSISTENCE_PERMANENT; memset(&tuple, 0, sizeof(tuple)); tuple.t_data = root; - tuple.t_len = ItemIdGetLength( - PageGetItemId((Page) fixture.live_page, UT_HOT_ROOT_OFF)); + tuple.t_len = ItemIdGetLength(PageGetItemId((Page)fixture.live_page, UT_HOT_ROOT_OFF)); tuple.t_tableOid = UT_HOT_TABLE_OID; ItemPointerSet(&tuple.t_self, UT_HOT_BLOCK, UT_HOT_ROOT_OFF); memset(normalized, 0, sizeof(normalized)); UT_ASSERT(cluster_heap_test_current_mx_authorize_keyshare( - &relation, UT_HOT_BUFFER, &tuple, UT_ORDINARY_REQUESTER, - &result, normalized, lengthof(normalized), &normalized_count)); + &relation, UT_HOT_BUFFER, &tuple, UT_ORDINARY_REQUESTER, &result, normalized, + lengthof(normalized), &normalized_count)); UT_ASSERT_EQ(result, TM_Ok); UT_ASSERT_EQ(normalized_count, 2); UT_ASSERT_EQ(normalized[0].xid, UT_ORDINARY_LOCKER); @@ -5672,8 +5403,7 @@ UT_TEST(test_79_current_mx_epoch_zero_requires_clean_four_node_formation) UT_ASSERT(cluster_heap_test_current_mx_epoch_supported(0)); UT_ASSERT(cluster_heap_test_current_mx_epoch_supported(1)); UT_ASSERT(cluster_heap_test_current_mx_epoch_supported(UINT32_MAX)); - UT_ASSERT(!cluster_heap_test_current_mx_epoch_supported( - UINT64_C(1) + UINT32_MAX)); + UT_ASSERT(!cluster_heap_test_current_mx_epoch_supported(UINT64_C(1) + UINT32_MAX)); ut_cluster_conf.node_count = 2; UT_ASSERT(!cluster_heap_test_current_mx_epoch_supported(0)); @@ -5744,8 +5474,8 @@ UT_TEST(test_lock_only_xid_breach_never_asks_fallback_or_changes_page) } static bool -ut_writer_wait_with_relation(Buffer buffer, HeapTuple tuple, TransactionId xid, - uint16 infomask, TM_Result *result) +ut_writer_wait_with_relation(Buffer buffer, HeapTuple tuple, TransactionId xid, uint16 infomask, + TM_Result *result) { RelationData relation = { 0 }; FormData_pg_class form = { 0 }; @@ -5792,8 +5522,7 @@ UT_TEST(test_recycled_writer_terminal_consumes_proof_only_after_fresh_recheck) ut_writer_bridge_mutation = leg >= 2 ? leg - 1 : 0; ut_writer_bridge_tuple_pulls = 0; memcpy(before.data, fixture.live_page, BLCKSZ); - UT_ASSERT(ut_writer_wait_with_relation(1, &tuple, 1200, tuple.t_data->t_infomask, - &result)); + UT_ASSERT(ut_writer_wait_with_relation(1, &tuple, 1200, tuple.t_data->t_infomask, &result)); UT_ASSERT_EQ(result, leg >= 2 ? TM_BeingModified : leg == 1 ? TM_Ok : TM_Deleted); UT_ASSERT_EQ(ut_scratch_exact_resolve_calls, 1); UT_ASSERT_EQ(ut_writer_bridge_tuple_pulls, 0); @@ -5846,8 +5575,7 @@ UT_TEST(test_target_writer_uses_bit0_exact_wait_and_requalifies_terminal_proof) ut_writer_target_outcome = leg == 1 || leg == 3 || leg == 7 ? CLUSTER_TX_ABORTED : CLUSTER_TX_COMMITTED; memcpy(before.data, fixture.live_page, BLCKSZ); - UT_ASSERT(ut_writer_wait_with_relation(1, &tuple, 1200, tuple.t_data->t_infomask, - &result)); + UT_ASSERT(ut_writer_wait_with_relation(1, &tuple, 1200, tuple.t_data->t_infomask, &result)); UT_ASSERT_EQ(result, leg >= 4 ? TM_BeingModified : ut_writer_target_outcome == CLUSTER_TX_ABORTED ? TM_Ok : TM_Deleted); @@ -5966,7 +5694,7 @@ UT_TEST(test_pending_writer_enters_unlocked_bridge_without_a_locked_rpc) ut_writer_target_outcome = leg == 1 ? CLUSTER_TX_ABORTED : CLUSTER_TX_COMMITTED; ut_writer_bridge_mutation = leg >= 2 && leg < 5 ? leg - 1 : 0; UT_ASSERT(ut_writer_wait_with_relation(1, &tuple, 1200, tuple.t_data->t_infomask, - &bridge_result)); + &bridge_result)); UT_ASSERT_EQ(bridge_result, leg >= 2 && leg < 5 ? TM_BeingModified : leg == 1 ? TM_Ok : TM_Deleted); @@ -6051,7 +5779,7 @@ ut_lock_only_writer_route_case(int negative) ut_writer_target_outcome = CLUSTER_TX_COMMITTED; ut_writer_bridge_mutation = negative == 7 ? 2 : negative == 8 ? 3 : 0; UT_ASSERT(ut_writer_wait_with_relation(UT_HOT_BUFFER, &tuple, 1200, - tuple.t_data->t_infomask, &bridge)); + tuple.t_data->t_infomask, &bridge)); UT_ASSERT_EQ(bridge, negative >= 7 ? TM_BeingModified : TM_Ok); UT_ASSERT_EQ(ut_itl_wait_calls, 1); UT_ASSERT_EQ(ut_writer_target_resolve_calls, 2); @@ -6925,8 +6653,8 @@ UT_TEST(test_hot_prune_without_xmin_hint_never_reads_requester_clog) UT_ASSERT_EQ(ut_prune_wal.snapshotConflictHorizon, 903); UT_ASSERT_EQ(ItemIdGetRedirect(PageGetItemId(page, 1)), 3); UT_ASSERT_EQ(PageGetItem(page, PageGetItemId(page, 3))[63], 0x33); - UT_ASSERT(!HeapTupleHeaderXminCommitted( - (HeapTupleHeader)PageGetItem(page, PageGetItemId(page, 3)))); + UT_ASSERT( + !HeapTupleHeaderXminCommitted((HeapTupleHeader)PageGetItem(page, PageGetItemId(page, 3)))); ut_prune_end(); } diff --git a/src/test/cluster_unit/test_cluster_r4_multi_subx_2pc.c b/src/test/cluster_unit/test_cluster_r4_multi_subx_2pc.c index 8451662e577..bd9e70aa776 100644 --- a/src/test/cluster_unit/test_cluster_r4_multi_subx_2pc.c +++ b/src/test/cluster_unit/test_cluster_r4_multi_subx_2pc.c @@ -45,8 +45,7 @@ static int test_native_read_count; static int test_native_read_calls; static int test_enter_calls; static int test_leave_calls; -static ClusterSemanticAdmissionResult test_admission_result - = CLUSTER_SEMANTIC_ADMISSION_OK; +static ClusterSemanticAdmissionResult test_admission_result = CLUSTER_SEMANTIC_ADMISSION_OK; sigjmp_buf *PG_exception_stack = NULL; ErrorContextCallback *error_context_stack = NULL; @@ -90,9 +89,8 @@ cluster_semantic_activation_leave(ClusterSemanticAdmissionToken *token) } int -GetMultiXactIdMembersWithOffset(MultiXactId multi, MultiXactMember **members, - bool from_pgupgrade, bool isLockOnly, - MultiXactOffset *start_offset_out) +GetMultiXactIdMembersWithOffset(MultiXactId multi, MultiXactMember **members, bool from_pgupgrade, + bool isLockOnly, MultiXactOffset *start_offset_out) { TestNativeRead *read; Size size; @@ -121,7 +119,7 @@ typedef int (*ClusterR4NativeMultiReadFn)(MultiXactId, MultiXactMember **, bool, MultiXactOffset *); StaticAssertDecl(__builtin_types_compatible_p(__typeof__(&GetMultiXactIdMembersWithOffset), - ClusterR4NativeMultiReadFn), + ClusterR4NativeMultiReadFn), "R4 native MultiXact reader signature must remain exact"); static void @@ -477,8 +475,7 @@ UT_TEST(test_null_output_refuses_before_native_read) ClusterTxResolveReason reason = CLUSTER_TX_RESOLVE_NONE; reset_runtime_fixture(); - UT_ASSERT_EQ(cluster_tx_resolve_multixact((MultiXactId)73, NULL, &reason), - CLUSTER_TX_UNKNOWN); + UT_ASSERT_EQ(cluster_tx_resolve_multixact((MultiXactId)73, NULL, &reason), CLUSTER_TX_UNKNOWN); UT_ASSERT_EQ(reason, CLUSTER_TX_RESOLVE_PROTOCOL); UT_ASSERT_EQ(test_native_read_calls, 0); UT_ASSERT_EQ(test_leave_calls, 1); diff --git a/src/test/cluster_unit/test_cluster_r4_observe.c b/src/test/cluster_unit/test_cluster_r4_observe.c index 0626f234737..32633a768d9 100644 --- a/src/test/cluster_unit/test_cluster_r4_observe.c +++ b/src/test/cluster_unit/test_cluster_r4_observe.c @@ -107,8 +107,8 @@ cluster_semantic_activation_leave(ClusterSemanticAdmissionToken *token) bool cluster_bufmgr_copy_block_for_r4_cr(BufferTag tag pg_attribute_unused(), SCN expected_page_scn pg_attribute_unused(), - XLogRecPtr *page_lsn_out, SCN *page_scn_out, - char *dst, ClusterBufmgrGcsCopyRefusal *refusal_out) + XLogRecPtr *page_lsn_out, SCN *page_scn_out, char *dst, + ClusterBufmgrGcsCopyRefusal *refusal_out) { if (page_lsn_out != NULL) *page_lsn_out = (XLogRecPtr)1; @@ -133,8 +133,7 @@ cluster_cr_construct_page_for_server(const char *cur_page pg_attribute_unused(), void FlushErrorState(void) -{ -} +{} void pg_re_throw(void) @@ -188,12 +187,10 @@ UT_TEST(test_event_domain_is_exact_and_adapter_is_one_to_one) UT_ASSERT_EQ(CLUSTER_R4_EVENT_COUNT, 9); UT_ASSERT_EQ(CLUSTER_R4_OBSERVATION_EVENT_COUNT, 71); for (i = 0; i < CLUSTER_R4_OBSERVATION_EVENT_COUNT; i++) - cluster_r4_observe((ClusterR4Event)i, CLUSTER_TX_RESOLVE_NONE, - CLUSTER_CR_BUILD_NONE); + cluster_r4_observe((ClusterR4Event)i, CLUSTER_TX_RESOLVE_NONE, CLUSTER_CR_BUILD_NONE); for (i = 0; i < CLUSTER_R4_OBSERVATION_EVENT_COUNT; i++) UT_ASSERT_EQ(observed[i], 1); - cluster_r4_observe((ClusterR4Event)-1, CLUSTER_TX_RESOLVE_PROTOCOL, - CLUSTER_CR_BUILD_PROTOCOL); + cluster_r4_observe((ClusterR4Event)-1, CLUSTER_TX_RESOLVE_PROTOCOL, CLUSTER_CR_BUILD_PROTOCOL); cluster_r4_observe((ClusterR4Event)CLUSTER_R4_OBSERVATION_EVENT_COUNT, CLUSTER_TX_RESOLVE_PROTOCOL, CLUSTER_CR_BUILD_PROTOCOL); UT_ASSERT_EQ(observation_total(), CLUSTER_R4_OBSERVATION_EVENT_COUNT); @@ -201,13 +198,12 @@ UT_TEST(test_event_domain_is_exact_and_adapter_is_one_to_one) UT_TEST(test_holder_full_is_observed_after_accepted_build) { - BufferTag tag = {0}; + BufferTag tag = { 0 }; char page[BLCKSZ]; ClusterCrBuildReason reason = CLUSTER_CR_BUILD_PROTOCOL; reset_fixture(); - UT_ASSERT_EQ(cluster_cr_build_on_holder(&tag, (SCN)1, page, &reason), - CLUSTER_CR_BUILD_FULL); + UT_ASSERT_EQ(cluster_cr_build_on_holder(&tag, (SCN)1, page, &reason), CLUSTER_CR_BUILD_FULL); UT_ASSERT_EQ(reason, CLUSTER_CR_BUILD_NONE); UT_ASSERT_EQ(observed[CLUSTER_R4_EVENT_CR_HOLDER_FULL], 1); UT_ASSERT_EQ(observation_total(), 1); @@ -218,7 +214,7 @@ UT_TEST(test_holder_full_is_observed_after_accepted_build) UT_TEST(test_holder_retry_is_observed_with_typed_reason) { - BufferTag tag = {0}; + BufferTag tag = { 0 }; char page[BLCKSZ]; ClusterCrBuildReason reason = CLUSTER_CR_BUILD_NONE; @@ -247,7 +243,7 @@ UT_TEST(test_holder_nonretryable_failure_is_observed) UT_TEST(test_holder_admission_refusal_is_not_an_event) { - BufferTag tag = {0}; + BufferTag tag = { 0 }; char page[BLCKSZ]; ClusterCrBuildReason reason = CLUSTER_CR_BUILD_NONE; diff --git a/src/test/cluster_unit/test_cluster_r4_route_policy.c b/src/test/cluster_unit/test_cluster_r4_route_policy.c index 6c29de5f80f..66f5fc686db 100644 --- a/src/test/cluster_unit/test_cluster_r4_route_policy.c +++ b/src/test/cluster_unit/test_cluster_r4_route_policy.c @@ -66,53 +66,48 @@ UT_DEFINE_GLOBALS(); /* The two symbols exist only in the USE_CLUSTER_UNIT special object. They * call the same static exact-length branches used by the production envelope * handlers; neither symbol is present in a production build. */ -extern bool cluster_gcs_block_test_r4_request80(const ClusterICEnvelope *env, - const void *payload); -extern bool cluster_gcs_block_test_r4_forward96(const ClusterICEnvelope *env, - const void *payload); +extern bool cluster_gcs_block_test_r4_request80(const ClusterICEnvelope *env, const void *payload); +extern bool cluster_gcs_block_test_r4_forward96(const ClusterICEnvelope *env, const void *payload); extern int cluster_gcs_block_test_r4_tx_origin_context_count(void); extern void cluster_gcs_block_test_r4_tx_origin_drain(void); extern int cluster_gcs_block_r4_tx_resolve_pending_detail(char *out, Size capacity); -extern bool cluster_gcs_block_test_current_mx_forward128( - const ClusterICEnvelope *env, const void *payload); +extern bool cluster_gcs_block_test_current_mx_forward128(const ClusterICEnvelope *env, + const void *payload); extern bool cluster_gcs_block_test_r4_refusal_status(ClusterCrBuildResult result, - ClusterCrBuildReason reason, - bool admitted_forward, - GcsBlockReplyStatus *status_out); + ClusterCrBuildReason reason, + bool admitted_forward, + GcsBlockReplyStatus *status_out); extern bool cluster_gcs_block_test_decode_r4_reply( const ClusterICEnvelope *env, const void *payload, uint64 expected_request_id, uint64 expected_epoch, int32 expected_requester_backend_id, uint8 expected_transition_id, - int32 expected_sender_node, int32 expected_forwarding_master_node, - uint8 expected_reply_domain); -extern bool cluster_gcs_block_test_arm_r4_reply_slot(uint64 request_id, - uint64 request_epoch, - int32 requester_backend_id, - uint8 transition_id, - int32 expected_master_node); -extern bool cluster_gcs_block_test_arm_legacy_reply_slot(uint64 request_id, - uint64 request_epoch, + int32 expected_sender_node, int32 expected_forwarding_master_node, uint8 expected_reply_domain); +extern bool cluster_gcs_block_test_arm_r4_reply_slot(uint64 request_id, uint64 request_epoch, int32 requester_backend_id, uint8 transition_id, int32 expected_master_node); -extern bool cluster_gcs_block_test_snapshot_r4_reply_slot( - GcsBlockReplyHeader *header_out, char block_out[GCS_BLOCK_DATA_SIZE], - bool *reply_received_out, uint64 *stale_drop_count_out); -extern bool cluster_gcs_block_test_r4_requester_arm( - BufferTag tag, uint64 request_epoch, int32 expected_master_node, - uint64 next_sequence, uint64 *request_id_out); +extern bool cluster_gcs_block_test_arm_legacy_reply_slot(uint64 request_id, uint64 request_epoch, + int32 requester_backend_id, + uint8 transition_id, + int32 expected_master_node); +extern bool cluster_gcs_block_test_snapshot_r4_reply_slot(GcsBlockReplyHeader *header_out, + char block_out[GCS_BLOCK_DATA_SIZE], + bool *reply_received_out, + uint64 *stale_drop_count_out); +extern bool cluster_gcs_block_test_r4_requester_arm(BufferTag tag, uint64 request_epoch, + int32 expected_master_node, + uint64 next_sequence, uint64 *request_id_out); extern bool cluster_gcs_block_test_snapshot_r4_requester_slot( - bool *in_use_out, uint8 *reply_domain_out, uint64 *request_id_out, - uint8 *transition_id_out, BufferTag *tag_out, uint64 *request_epoch_out, - int32 *expected_master_node_out, ClusterGcsBlockDirectState *direct_state_out, - bool *direct_target_prepared_out); + bool *in_use_out, uint8 *reply_domain_out, uint64 *request_id_out, uint8 *transition_id_out, + BufferTag *tag_out, uint64 *request_epoch_out, int32 *expected_master_node_out, + ClusterGcsBlockDirectState *direct_state_out, bool *direct_target_prepared_out); extern bool cluster_gcs_block_test_release_r4_requester_slot(void); extern uint64 cluster_gcs_block_r4_requester_count(void); extern bool cluster_gcs_block_test_r4_fetch_and_wait(BufferTag tag, SCN read_scn, - int32 real_master_node, - char dst_page[GCS_BLOCK_DATA_SIZE]); -extern ClusterCrBuildResult cluster_gcs_block_cr_fetch_and_wait( - BufferTag tag, SCN read_scn, char dst_page[BLCKSZ], - ClusterCrBuildReason *reason_out); + int32 real_master_node, + char dst_page[GCS_BLOCK_DATA_SIZE]); +extern ClusterCrBuildResult cluster_gcs_block_cr_fetch_and_wait(BufferTag tag, SCN read_scn, + char dst_page[BLCKSZ], + ClusterCrBuildReason *reason_out); /* Backend globals reached by the narrow production route section. */ sigjmp_buf *PG_exception_stack = NULL; @@ -319,13 +314,13 @@ errdetail(const char *fmt pg_attribute_unused(), ...) } bool -cluster_multixact_current_member_proof_bind_ctrc( - ClusterCurrentMemberProof *proof, const ClusterCtrcTxnKeyV1 *ctrc_key) +cluster_multixact_current_member_proof_bind_ctrc(ClusterCurrentMemberProof *proof, + const ClusterCtrcTxnKeyV1 *ctrc_key) { if (proof == NULL || ctrc_key == NULL) return false; - ClusterCurrentMemberProofSetCtrcBinding( - proof, ctrc_key->segment_generation, ctrc_key->slot_wrap); + ClusterCurrentMemberProofSetCtrcBinding(proof, ctrc_key->segment_generation, + ctrc_key->slot_wrap); return true; } @@ -333,8 +328,7 @@ ClusterMxResolveResult cluster_cr_server_current_mx_build_proof_page( uint16 source_node_id pg_attribute_unused(), const ClusterCurrentMxProofForwardV2 *request pg_attribute_unused(), - ClusterMxResolveResult result, - uint32 requester_capability_generation pg_attribute_unused(), + ClusterMxResolveResult result, uint32 requester_capability_generation pg_attribute_unused(), const ClusterCurrentMemberProof *proofs pg_attribute_unused(), uint16 proof_count pg_attribute_unused(), const ClusterCurrentUpdaterProof *updater_proof pg_attribute_unused(), @@ -345,42 +339,39 @@ cluster_cr_server_current_mx_build_proof_page( bool cluster_ctrc_origin_ack_land_shared(uint64 request_id pg_attribute_unused(), - const ClusterCtrcLocalReleaseAckV1 *ack pg_attribute_unused()) + const ClusterCtrcLocalReleaseAckV1 *ack pg_attribute_unused()) { return false; } bool -cluster_ctrc_origin_grant_publishable( - const ClusterCtrcTxnKeyV1 *key pg_attribute_unused(), - const ClusterCtrcParticipantIdentity *participant pg_attribute_unused(), - uint32 grant_generation pg_attribute_unused()) +cluster_ctrc_origin_grant_publishable(const ClusterCtrcTxnKeyV1 *key pg_attribute_unused(), + const ClusterCtrcParticipantIdentity *participant + pg_attribute_unused(), + uint32 grant_generation pg_attribute_unused()) { return false; } bool cluster_ctrc_origin_note_certificate_reply_shared( - uint64 request_id pg_attribute_unused(), - uint16 participant_node_id pg_attribute_unused(), + uint64 request_id pg_attribute_unused(), uint16 participant_node_id pg_attribute_unused(), ClusterCtrcSealReplyResult result pg_attribute_unused()) { return false; } bool -cluster_ctrc_origin_note_close_reply_shared( - uint64 request_id pg_attribute_unused(), - uint16 participant_node_id pg_attribute_unused(), - ClusterCtrcSealReplyResult result pg_attribute_unused()) +cluster_ctrc_origin_note_close_reply_shared(uint64 request_id pg_attribute_unused(), + uint16 participant_node_id pg_attribute_unused(), + ClusterCtrcSealReplyResult result pg_attribute_unused()) { return false; } bool cluster_ctrc_origin_request_snapshot_shared( - uint64 request_id pg_attribute_unused(), - uint16 participant_node_id pg_attribute_unused(), + uint64 request_id pg_attribute_unused(), uint16 participant_node_id pg_attribute_unused(), ClusterCtrcTxnKeyV1 *key_out pg_attribute_unused(), ClusterCtrcParticipantIdentity *identity_out pg_attribute_unused(), uint32 *grant_generation_out pg_attribute_unused(), @@ -391,34 +382,32 @@ cluster_ctrc_origin_request_snapshot_shared( } ClusterCtrcTouchResult -cluster_ctrc_origin_touch_exact( - const ClusterCtrcTxnKeyV1 *key pg_attribute_unused(), - const ClusterCtrcParticipantIdentity *participant pg_attribute_unused(), - ClusterCtrcProofClass proof_class pg_attribute_unused(), - uint32 *grant_out pg_attribute_unused()) +cluster_ctrc_origin_touch_exact(const ClusterCtrcTxnKeyV1 *key pg_attribute_unused(), + const ClusterCtrcParticipantIdentity *participant + pg_attribute_unused(), + ClusterCtrcProofClass proof_class pg_attribute_unused(), + uint32 *grant_out pg_attribute_unused()) { return CLUSTER_CTRC_TOUCH_REFUSED; } bool -cluster_ctrc_seal_reply_decode( - const uint8 *page pg_attribute_unused(), Size page_length pg_attribute_unused(), - const uint8 *request_bytes pg_attribute_unused(), - Size request_length pg_attribute_unused(), - int32 expected_source_node pg_attribute_unused(), - int32 expected_destination_node pg_attribute_unused(), - ClusterCtrcSealReplyHeaderV1 *header_out pg_attribute_unused(), - ClusterCtrcLocalReleaseAckV1 *ack_out pg_attribute_unused()) +cluster_ctrc_seal_reply_decode(const uint8 *page pg_attribute_unused(), + Size page_length pg_attribute_unused(), + const uint8 *request_bytes pg_attribute_unused(), + Size request_length pg_attribute_unused(), + int32 expected_source_node pg_attribute_unused(), + int32 expected_destination_node pg_attribute_unused(), + ClusterCtrcSealReplyHeaderV1 *header_out pg_attribute_unused(), + ClusterCtrcLocalReleaseAckV1 *ack_out pg_attribute_unused()) { return false; } bool cluster_ctrc_seal_request_encode( - const ClusterCtrcTxnKeyV1 *key pg_attribute_unused(), - uint64 request_id pg_attribute_unused(), - uint32 grant_generation pg_attribute_unused(), - uint64 seal_generation pg_attribute_unused(), + const ClusterCtrcTxnKeyV1 *key pg_attribute_unused(), uint64 request_id pg_attribute_unused(), + uint32 grant_generation pg_attribute_unused(), uint64 seal_generation pg_attribute_unused(), uint32 participant_capability_record_generation pg_attribute_unused(), ClusterCtrcSealSuboperation suboperation pg_attribute_unused(), uint8 *bytes pg_attribute_unused(), Size length pg_attribute_unused()) @@ -448,12 +437,9 @@ cluster_membership_is_member(int32 node_id pg_attribute_unused()) bool cluster_multixact_current_resolve_origin_member_proof( - TransactionId member_xid pg_attribute_unused(), - uint8 member_status pg_attribute_unused(), - uint16 member_ordinal pg_attribute_unused(), - uint16 member_origin_node pg_attribute_unused(), - uint32 current_epoch pg_attribute_unused(), - bool requester_self pg_attribute_unused(), + TransactionId member_xid pg_attribute_unused(), uint8 member_status pg_attribute_unused(), + uint16 member_ordinal pg_attribute_unused(), uint16 member_origin_node pg_attribute_unused(), + uint32 current_epoch pg_attribute_unused(), bool requester_self pg_attribute_unused(), const ClusterTTStatusKey *initial_key pg_attribute_unused(), const ClusterTTStatusResult *initial_result pg_attribute_unused(), ClusterCurrentMxExactLookupFn exact_lookup pg_attribute_unused(), @@ -469,16 +455,12 @@ cluster_multixact_current_stats_bump(ClusterCurrentMxStatId stat pg_attribute_un bool cluster_multixact_current_successor_provenance_well_formed( - const ClusterCurrentMxSuccessorAlias *alias, - const ClusterTxLocator *locator, TransactionId updater_xid, - uint16 updater_origin_node, uint32 current_epoch) + const ClusterCurrentMxSuccessorAlias *alias, const ClusterTxLocator *locator, + TransactionId updater_xid, uint16 updater_origin_node, uint32 current_epoch) { - return alias != NULL && locator != NULL - && alias->local_xid == updater_xid - && alias->origin_node_id == updater_origin_node - && alias->cluster_epoch == current_epoch - && locator->xid == updater_xid - && !UBA_is_invalid(locator->uba); + return alias != NULL && locator != NULL && alias->local_xid == updater_xid + && alias->origin_node_id == updater_origin_node && alias->cluster_epoch == current_epoch + && locator->xid == updater_xid && !UBA_is_invalid(locator->uba); } uint64 @@ -494,8 +476,8 @@ cluster_reconfig_get_observed_epoch(int32 node_id pg_attribute_unused()) } bool -cluster_reconfig_get_observed_slot(int32 node_id pg_attribute_unused(), - uint64 *incarnation, uint64 *generation) +cluster_reconfig_get_observed_slot(int32 node_id pg_attribute_unused(), uint64 *incarnation, + uint64 *generation) { if (incarnation != NULL) *incarnation = UINT64_C(1); @@ -537,27 +519,28 @@ cluster_runtime_visibility_physical_locator_sample_held( } bool -cluster_sf_peer_capability_generation_matches( - int32 peer_id pg_attribute_unused(), - uint32 required_capabilities pg_attribute_unused(), - uint32 expected_generation pg_attribute_unused()) +cluster_sf_peer_capability_generation_matches(int32 peer_id pg_attribute_unused(), + uint32 required_capabilities pg_attribute_unused(), + uint32 expected_generation pg_attribute_unused()) { return true; } bool -cluster_tt_slot_current_owner_by_xid( - int node_id pg_attribute_unused(), TransactionId xid pg_attribute_unused(), - ClusterTTSlotCurrentOwner *out pg_attribute_unused()) +cluster_tt_slot_current_owner_by_xid(int node_id pg_attribute_unused(), + TransactionId xid pg_attribute_unused(), + ClusterTTSlotCurrentOwner *out pg_attribute_unused()) { return false; } ClusterTTDurableLocate -cluster_tt_slot_durable_locate_any_by_xid_origin( - int origin_node pg_attribute_unused(), TransactionId xid pg_attribute_unused(), - uint16 *out_seg pg_attribute_unused(), uint16 *out_slot pg_attribute_unused(), - uint16 *out_wrap pg_attribute_unused(), uint8 *out_status pg_attribute_unused()) +cluster_tt_slot_durable_locate_any_by_xid_origin(int origin_node pg_attribute_unused(), + TransactionId xid pg_attribute_unused(), + uint16 *out_seg pg_attribute_unused(), + uint16 *out_slot pg_attribute_unused(), + uint16 *out_wrap pg_attribute_unused(), + uint8 *out_status pg_attribute_unused()) { return CLUSTER_TT_DURABLE_LOCATE_MISSING; } @@ -587,12 +570,11 @@ cluster_undo_block0_current_sample_generation(ClusterUndoBlock0CurrentGuard *gua } bool -cluster_undo_block0_root_matches( - const ClusterUndoBlock0ResolvedRoot *observed, - const ClusterUndoBlock0ResolvedRoot *expected) +cluster_undo_block0_root_matches(const ClusterUndoBlock0ResolvedRoot *observed, + const ClusterUndoBlock0ResolvedRoot *expected) { return observed != NULL && expected != NULL - && memcmp(observed, expected, sizeof(*observed)) == 0; + && memcmp(observed, expected, sizeof(*observed)) == 0; } int @@ -686,8 +668,8 @@ ConditionVariablePrepareToSleep(ConditionVariable *cv pg_attribute_unused()) bool ConditionVariableTimedSleep(ConditionVariable *cv pg_attribute_unused(), - long timeout pg_attribute_unused(), - uint32 wait_event_info pg_attribute_unused()) + long timeout pg_attribute_unused(), + uint32 wait_event_info pg_attribute_unused()) { reply_cv_timed_sleep_calls++; if (reply_cv_timed_sleep_raise) @@ -705,9 +687,7 @@ ConditionVariableCancelSleep(void) } void -cluster_sf_dep_note_lost_failclosed(void) -{} - +cluster_sf_dep_note_lost_failclosed(void){} #define UT_FORMATION_EPOCH UINT64_C(9) #define UT_ACTIVATION_GENERATION UINT64_C(12) #define UT_LOCAL_OPEN_GENERATION UINT64_C(0xffffffff) @@ -729,10 +709,9 @@ cluster_sf_dep_note_lost_failclosed(void) #define UT_REPLY_DOMAIN_R4_CR ((uint8)1) #define UT_REPLY_DOMAIN_CURRENT_MX ((uint8)2) #define UT_R4_INTERNAL_ENDPOINT (-2) -#define UT_R4_REQUIRED_CAPABILITIES \ - (PGRAC_IC_HELLO_CAP_SEMANTIC_ACTIVATION_V1 | PGRAC_IC_HELLO_CAP_R4_SYNC_CR_V1 \ - | PGRAC_IC_HELLO_CAP_CANDIDATE2_CORRECTED_A1_V1 \ - | PGRAC_IC_HELLO_CAP_UNDO_ROOT_DESCRIPTOR_V1) +#define UT_R4_REQUIRED_CAPABILITIES \ + (PGRAC_IC_HELLO_CAP_SEMANTIC_ACTIVATION_V1 | PGRAC_IC_HELLO_CAP_R4_SYNC_CR_V1 \ + | PGRAC_IC_HELLO_CAP_CANDIDATE2_CORRECTED_A1_V1 | PGRAC_IC_HELLO_CAP_UNDO_ROOT_DESCRIPTOR_V1) typedef struct RouteSeamCapture { ClusterSemanticAdmissionResult admission_result; @@ -899,38 +878,35 @@ cluster_normal_stop_service_new_work(bool modifies_data) } bool -cluster_cr_server_r4_land_foreign_undo( - const ClusterICEnvelope *env, const GcsBlockReplyHeader *header, - const char undo_page[BLCKSZ], const ClusterGcsUndoAuthTrailer *undo_auth) +cluster_cr_server_r4_land_foreign_undo(const ClusterICEnvelope *env, + const GcsBlockReplyHeader *header, + const char undo_page[BLCKSZ], + const ClusterGcsUndoAuthTrailer *undo_auth) { route_seam.foreign_undo_land_calls++; if (env == NULL || header == NULL || undo_page == NULL || undo_auth == NULL) return false; route_seam.foreign_undo_env = *env; route_seam.foreign_undo_header = *header; - memcpy(route_seam.foreign_undo_page, undo_page, - sizeof(route_seam.foreign_undo_page)); + memcpy(route_seam.foreign_undo_page, undo_page, sizeof(route_seam.foreign_undo_page)); route_seam.foreign_undo_auth = *undo_auth; return true; } void -cluster_gcs_current_mx_describe_serve_inline( - const ClusterICEnvelope *env, const void *payload) +cluster_gcs_current_mx_describe_serve_inline(const ClusterICEnvelope *env, const void *payload) { route_seam.current_mx_describe_serve_calls++; if (env != NULL) route_seam.current_mx_describe_env = *env; if (payload != NULL && env != NULL - && env->payload_length - == sizeof(route_seam.current_mx_describe_request)) + && env->payload_length == sizeof(route_seam.current_mx_describe_request)) memcpy(&route_seam.current_mx_describe_request, payload, sizeof(route_seam.current_mx_describe_request)); } void -cluster_gcs_current_mx_member_proof_serve_inline( - const ClusterICEnvelope *env, const void *payload) +cluster_gcs_current_mx_member_proof_serve_inline(const ClusterICEnvelope *env, const void *payload) { route_seam.current_mx_proof_serve_calls++; if (env != NULL) @@ -1117,8 +1093,7 @@ route_seam_reset(void) route_seam.snapshot_ok = true; route_seam.local_dispatch_ok = true; route_seam.current_mx_capability_ok = true; - route_seam.current_mx_capability_generation - = UT_CURRENT_MX_CAPABILITY_GENERATION; + route_seam.current_mx_capability_generation = UT_CURRENT_MX_CAPABILITY_GENERATION; route_seam.current_mx_validate_result = CMX_DESC_UNKNOWN; route_seam.current_mx_proof_validate_result = CMX_RESOLVE_UNKNOWN; route_seam.arm_result = GCS_BLOCK_R4_ROUTE_ARM_NEW; @@ -1174,22 +1149,19 @@ route_test_envelope(uint8 msg_type, uint32 source, uint32 dest, uint32 payload_l } bool -cluster_ic_envelope_build(ClusterICEnvelope *out_env, uint8 msg_type, - uint32 source_node_id, uint32 dest_node_id, - const void *payload, uint32 payload_length) +cluster_ic_envelope_build(ClusterICEnvelope *out_env, uint8 msg_type, uint32 source_node_id, + uint32 dest_node_id, const void *payload, uint32 payload_length) { route_seam.envelope_build_calls++; route_seam.envelope_build_sequence = ++route_seam.sequence; if (!route_seam.local_dispatch_ok || out_env == NULL || payload == NULL) return false; - *out_env = route_test_envelope(msg_type, source_node_id, dest_node_id, - payload_length); + *out_env = route_test_envelope(msg_type, source_node_id, dest_node_id, payload_length); return true; } bool -cluster_ic_dispatch_envelope(const ClusterICEnvelope *env, const void *payload, - int32 peer_id) +cluster_ic_dispatch_envelope(const ClusterICEnvelope *env, const void *payload, int32 peer_id) { typedef struct TestR4Reply8240 { GcsBlockReplyHeader header; @@ -1214,27 +1186,23 @@ cluster_ic_dispatch_envelope(const ClusterICEnvelope *env, const void *payload, route_seam.local_dispatch_envelope = *env; route_seam.local_dispatch_peer = peer_id; route_seam.local_dispatch_payload_len = env != NULL ? env->payload_length : 0; - if (payload != NULL && route_seam.local_dispatch_payload_len - <= sizeof(route_seam.local_dispatch_payload)) - memcpy(route_seam.local_dispatch_payload, payload, - route_seam.local_dispatch_payload_len); + if (payload != NULL + && route_seam.local_dispatch_payload_len <= sizeof(route_seam.local_dispatch_payload)) + memcpy(route_seam.local_dispatch_payload, payload, route_seam.local_dispatch_payload_len); if (route_seam.local_dispatch_ok && env != NULL && payload != NULL && env->msg_type == PGRAC_IC_MSG_GCS_BLOCK_REQUEST && env->payload_length == sizeof(ClusterR4CrRequestPayload)) { request = (const ClusterR4CrRequestPayload *)payload; route_seam.local_request_slot_armed = cluster_gcs_block_test_snapshot_r4_requester_slot( - &in_use, &slot_domain, &slot_request_id, &transition_id, - &slot_tag, &slot_epoch, &slot_master, &direct_state, - &direct_target_prepared) + &in_use, &slot_domain, &slot_request_id, &transition_id, &slot_tag, &slot_epoch, + &slot_master, &direct_state, &direct_target_prepared) && in_use && slot_domain == UT_REPLY_DOMAIN_R4_CR && slot_request_id == request->base.request_id && transition_id == request->base.transition_id && memcmp(&slot_tag, &request->base.tag, sizeof(slot_tag)) == 0 - && slot_epoch == request->base.epoch - && slot_master == (int32)env->dest_node_id - && direct_state == GCS_BLOCK_DIRECT_UNARMED - && !direct_target_prepared; + && slot_epoch == request->base.epoch && slot_master == (int32)env->dest_node_id + && direct_state == GCS_BLOCK_DIRECT_UNARMED && !direct_target_prepared; if (!route_seam.local_request_slot_armed) return false; memset(&reply, 0, sizeof(reply)); @@ -1242,26 +1210,22 @@ cluster_ic_dispatch_envelope(const ClusterICEnvelope *env, const void *payload, reply.header.epoch = request->base.epoch; reply.header.page_lsn = UINT64_C(0xabcdef); reply.header.sender_node = UT_HOLDER_NODE; - reply.header.requester_backend_id - = request->base.requester_backend_id; + reply.header.requester_backend_id = request->base.requester_backend_id; reply.header.transition_id = request->base.transition_id; reply.header.status = GCS_BLOCK_REPLY_R4_CR_FULL; - GcsBlockReplyHeaderSetForwardingMasterNode( - &reply.header, (int32)env->dest_node_id); + GcsBlockReplyHeaderSetForwardingMasterNode(&reply.header, (int32)env->dest_node_id); memset(reply.block_data, 0x6d, sizeof(reply.block_data)); - reply.header.checksum - = cluster_gcs_block_compute_checksum(reply.block_data); - reply_env = route_test_envelope( - PGRAC_IC_MSG_GCS_BLOCK_REPLY, UT_HOLDER_NODE, - (uint32)cluster_node_id, sizeof(reply)); + reply.header.checksum = cluster_gcs_block_compute_checksum(reply.block_data); + reply_env = route_test_envelope(PGRAC_IC_MSG_GCS_BLOCK_REPLY, UT_HOLDER_NODE, + (uint32)cluster_node_id, sizeof(reply)); cluster_gcs_handle_block_reply_envelope(&reply_env, &reply); } return route_seam.local_dispatch_ok; } ClusterICSendResult -cluster_ic_send_envelope(uint8 msg_type, int32 dest_node_id, - const void *payload, uint32 payload_len) +cluster_ic_send_envelope(uint8 msg_type, int32 dest_node_id, const void *payload, + uint32 payload_len) { route_seam.raw_send_calls++; route_seam.raw_send_msg_type = msg_type; @@ -1271,18 +1235,15 @@ cluster_ic_send_envelope(uint8 msg_type, int32 dest_node_id, && (payload_len == GCS_BLOCK_REPLY_PAYLOAD_TOTAL_SIZE || payload_len == GCS_BLOCK_REPLY_PAYLOAD_TOTAL_SIZE + sizeof(ClusterGcsUndoAuthTrailer))) { - memcpy(&route_seam.raw_send_header, payload, - sizeof(route_seam.raw_send_header)); - memcpy(route_seam.raw_send_page, - ((const char *)payload) + sizeof(GcsBlockReplyHeader), + memcpy(&route_seam.raw_send_header, payload, sizeof(route_seam.raw_send_header)); + memcpy(route_seam.raw_send_page, ((const char *)payload) + sizeof(GcsBlockReplyHeader), sizeof(route_seam.raw_send_page)); } return route_seam.raw_send_result; } uint32 -cluster_gcs_block_dedup_lifetime_ms(int initial_backoff_ms, int max_retries, - int reply_timeout_ms) +cluster_gcs_block_dedup_lifetime_ms(int initial_backoff_ms, int max_retries, int reply_timeout_ms) { int64 lifetime_ms; @@ -1306,8 +1267,8 @@ cluster_gcs_block_dedup_register_backend_exit_hook(void) {} bool -cluster_grd_outbound_enqueue_backend_msg(uint8 msg_type, uint32 dest_node_id, - const void *payload, uint16 payload_len) +cluster_grd_outbound_enqueue_backend_msg(uint8 msg_type, uint32 dest_node_id, const void *payload, + uint16 payload_len) { typedef struct TestR4Reply8240 { GcsBlockReplyHeader header; @@ -1321,14 +1282,12 @@ cluster_grd_outbound_enqueue_backend_msg(uint8 msg_type, uint32 dest_node_id, int32 slot_master = -1; uint8 transition_id = 0; BufferTag slot_tag; - RequesterReplyStep reply_step = { - .status = GCS_BLOCK_REPLY_R4_CR_FULL, - .envelope_source_node = UT_HOLDER_NODE, - .header_sender_node = UT_HOLDER_NODE, - .forwarding_master_node = UT_MASTER_NODE, - .page_lsn = UINT64_C(0xabcdef), - .block_fill = 0x6d - }; + RequesterReplyStep reply_step = { .status = GCS_BLOCK_REPLY_R4_CR_FULL, + .envelope_source_node = UT_HOLDER_NODE, + .header_sender_node = UT_HOLDER_NODE, + .forwarding_master_node = UT_MASTER_NODE, + .page_lsn = UINT64_C(0xabcdef), + .block_fill = 0x6d }; int call_index = requester_send.calls; if (msg_type == PGRAC_IC_MSG_GCS_BLOCK_DONE) { @@ -1361,26 +1320,18 @@ cluster_grd_outbound_enqueue_backend_msg(uint8 msg_type, uint32 dest_node_id, ClusterTxResolution resolution; uint32 physical_generation = UINT32_MAX; - memcpy(&requester_send.tx_forward, payload, - sizeof(requester_send.tx_forward)); - requester_send.tx_kind2 - = ClusterR4ForwardExtensionGetLocatorGeneration( - &requester_send.tx_forward.extension, - CLUSTER_R4_WIRE_TX_RESOLVE, &locator, - &physical_generation); + memcpy(&requester_send.tx_forward, payload, sizeof(requester_send.tx_forward)); + requester_send.tx_kind2 = ClusterR4ForwardExtensionGetLocatorGeneration( + &requester_send.tx_forward.extension, CLUSTER_R4_WIRE_TX_RESOLVE, &locator, + &physical_generation); requester_send.slot_armed = cluster_gcs_block_test_snapshot_r4_requester_slot( - &in_use, &requester_send.slot_domain, &slot_request_id, - &transition_id, &slot_tag, &slot_epoch, &slot_master, - &requester_send.direct_state, - &requester_send.direct_target_prepared) - && in_use - && slot_request_id - == requester_send.tx_forward.base.request_id - && transition_id - == requester_send.tx_forward.base.transition_id - && memcmp(&slot_tag, &requester_send.tx_forward.base.tag, - sizeof(slot_tag)) == 0 + &in_use, &requester_send.slot_domain, &slot_request_id, &transition_id, &slot_tag, + &slot_epoch, &slot_master, &requester_send.direct_state, + &requester_send.direct_target_prepared) + && in_use && slot_request_id == requester_send.tx_forward.base.request_id + && transition_id == requester_send.tx_forward.base.transition_id + && memcmp(&slot_tag, &requester_send.tx_forward.base.tag, sizeof(slot_tag)) == 0 && slot_epoch == requester_send.tx_forward.base.epoch && slot_master == (int32)dest_node_id; if (!requester_send.tx_kind2 @@ -1397,31 +1348,24 @@ cluster_grd_outbound_enqueue_backend_msg(uint8 msg_type, uint32 dest_node_id, resolution.proof_kind = CLUSTER_TX_PROOF_ORIGIN_DURABLE_TT_CLOG; resolution.commit_scn = (SCN)101; resolution.horizon_scn = (SCN)89; - resolution.authority.origin_epoch - = requester_send.tx_forward.base.epoch; + resolution.authority.origin_epoch = requester_send.tx_forward.base.epoch; resolution.authority.tt_generation = UINT64_C(17); resolution.authority.authority_scn = (SCN)103; memset(&reply, 0, sizeof(reply)); - reply.header.request_id - = requester_send.tx_forward.base.request_id; + reply.header.request_id = requester_send.tx_forward.base.request_id; reply.header.epoch = requester_send.tx_forward.base.epoch; reply.header.page_lsn = UINT64_C(0xabcdef); reply.header.sender_node = (int32)dest_node_id; - reply.header.requester_backend_id - = requester_send.tx_forward.base.requester_backend_id; - reply.header.transition_id - = requester_send.tx_forward.base.transition_id; + reply.header.requester_backend_id = requester_send.tx_forward.base.requester_backend_id; + reply.header.transition_id = requester_send.tx_forward.base.transition_id; reply.header.status = GCS_BLOCK_REPLY_R4_TX_RESOLVE_RESULT; - GcsBlockReplyHeaderSetForwardingMasterNode( - &reply.header, GCS_BLOCK_REPLY_NO_FORWARDING_MASTER); - if (!ClusterR4TxVerdictPageEncode( - (uint8 *)reply.block_data, &resolution)) + GcsBlockReplyHeaderSetForwardingMasterNode(&reply.header, + GCS_BLOCK_REPLY_NO_FORWARDING_MASTER); + if (!ClusterR4TxVerdictPageEncode((uint8 *)reply.block_data, &resolution)) return false; - reply.header.checksum - = cluster_gcs_block_compute_checksum(reply.block_data); - env = route_test_envelope(PGRAC_IC_MSG_GCS_BLOCK_REPLY, - dest_node_id, (uint32)cluster_node_id, - sizeof(reply)); + reply.header.checksum = cluster_gcs_block_compute_checksum(reply.block_data); + env = route_test_envelope(PGRAC_IC_MSG_GCS_BLOCK_REPLY, dest_node_id, + (uint32)cluster_node_id, sizeof(reply)); cluster_gcs_handle_block_reply_envelope(&env, &reply); return true; } @@ -1431,15 +1375,15 @@ cluster_grd_outbound_enqueue_backend_msg(uint8 msg_type, uint32 dest_node_id, return false; memset(&requester_send.request, 0, sizeof(requester_send.request)); memcpy(&requester_send.request, payload, payload_len); - requester_send.slot_armed = cluster_gcs_block_test_snapshot_r4_requester_slot( - &in_use, &requester_send.slot_domain, &slot_request_id, &transition_id, - &slot_tag, &slot_epoch, &slot_master, &requester_send.direct_state, - &requester_send.direct_target_prepared) - && in_use && slot_request_id == requester_send.request.base.request_id - && transition_id == requester_send.request.base.transition_id - && memcmp(&slot_tag, &requester_send.request.base.tag, sizeof(slot_tag)) == 0 - && slot_epoch == requester_send.request.base.epoch - && slot_master == (int32)dest_node_id; + requester_send.slot_armed + = cluster_gcs_block_test_snapshot_r4_requester_slot( + &in_use, &requester_send.slot_domain, &slot_request_id, &transition_id, &slot_tag, + &slot_epoch, &slot_master, &requester_send.direct_state, + &requester_send.direct_target_prepared) + && in_use && slot_request_id == requester_send.request.base.request_id + && transition_id == requester_send.request.base.transition_id + && memcmp(&slot_tag, &requester_send.request.base.tag, sizeof(slot_tag)) == 0 + && slot_epoch == requester_send.request.base.epoch && slot_master == (int32)dest_node_id; if (call_index >= 0 && call_index < REQUESTER_REPLY_SCRIPT_CAPACITY) { requester_send.request_ids[call_index] = requester_send.request.base.request_id; requester_send.slot_armed_by_call[call_index] = requester_send.slot_armed; @@ -1460,8 +1404,7 @@ cluster_grd_outbound_enqueue_backend_msg(uint8 msg_type, uint32 dest_node_id, reply.header.requester_backend_id = requester_send.request.base.requester_backend_id; reply.header.transition_id = requester_send.request.base.transition_id; reply.header.status = (uint8)reply_step.status; - GcsBlockReplyHeaderSetForwardingMasterNode( - &reply.header, reply_step.forwarding_master_node); + GcsBlockReplyHeaderSetForwardingMasterNode(&reply.header, reply_step.forwarding_master_node); memset(reply.block_data, reply_step.block_fill, sizeof(reply.block_data)); memcpy(requester_send.reply_page, reply.block_data, sizeof(reply.block_data)); reply.header.checksum = cluster_gcs_block_compute_checksum(reply.block_data); @@ -1469,9 +1412,8 @@ cluster_grd_outbound_enqueue_backend_msg(uint8 msg_type, uint32 dest_node_id, reply.header.checksum ^= UINT32_C(1); if (requester_send.corrupt_reply_identity) reply.header.request_id++; - env = route_test_envelope(PGRAC_IC_MSG_GCS_BLOCK_REPLY, - reply_step.envelope_source_node, - (uint32)cluster_node_id, sizeof(reply)); + env = route_test_envelope(PGRAC_IC_MSG_GCS_BLOCK_REPLY, reply_step.envelope_source_node, + (uint32)cluster_node_id, sizeof(reply)); cluster_gcs_handle_block_reply_envelope(&env, &reply); return true; } @@ -1505,12 +1447,10 @@ route_test_request80(void) static ClusterR4CrForwardPayload route_test_forward96(void) { - static const uint8 extension_bytes[32] = { - 0x01, 0x01, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, - 0x09, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x22, 0x22, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - }; + static const uint8 extension_bytes[32] + = { 0x01, 0x01, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, + 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x22, 0x22, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; ClusterR4CrForwardPayload forward; memset(&forward, 0, sizeof(forward)); @@ -1530,7 +1470,8 @@ route_test_forward96(void) void ExceptionalCondition(const char *conditionName pg_attribute_unused(), - const char *fileName pg_attribute_unused(), int lineNumber pg_attribute_unused()) + const char *fileName pg_attribute_unused(), + int lineNumber pg_attribute_unused()) { abort(); } @@ -1633,14 +1574,12 @@ cluster_touched_peers_stamp(int32 node_id pg_attribute_unused(), const ClusterICMsgTypeInfo * cluster_ic_get_msg_type_info(uint8 msg_type) { - static const ClusterICMsgTypeInfo data_info = { - .msg_type = PGRAC_IC_MSG_GCS_BLOCK_REPLY, - .name = "test_gcs_block_reply", - .allowed_producer_mask = 0, - .broadcast_ok = false, - .handler = NULL, - .plane = CLUSTER_IC_PLANE_DATA - }; + static const ClusterICMsgTypeInfo data_info = { .msg_type = PGRAC_IC_MSG_GCS_BLOCK_REPLY, + .name = "test_gcs_block_reply", + .allowed_producer_mask = 0, + .broadcast_ok = false, + .handler = NULL, + .plane = CLUSTER_IC_PLANE_DATA }; return msg_type == PGRAC_IC_MSG_GCS_BLOCK_REPLY ? &data_info : NULL; } @@ -1789,8 +1728,7 @@ cluster_semantic_activation_leave(ClusterSemanticAdmissionToken *token) } ClusterSemanticAdmissionResult -cluster_semantic_activation_enter_r4_terminal_census( - ClusterSemanticAdmissionToken *token) +cluster_semantic_activation_enter_r4_terminal_census(ClusterSemanticAdmissionToken *token) { route_seam.terminal_census_enter_calls++; if (token == NULL) @@ -1805,8 +1743,7 @@ cluster_semantic_activation_enter_r4_terminal_census( } bool -cluster_semantic_activation_recheck_r4_terminal_census( - const ClusterSemanticAdmissionToken *token) +cluster_semantic_activation_recheck_r4_terminal_census(const ClusterSemanticAdmissionToken *token) { route_seam.terminal_census_recheck_calls++; return route_seam.recheck_ok && token != NULL && token->entered @@ -1814,15 +1751,14 @@ cluster_semantic_activation_recheck_r4_terminal_census( } bool -cluster_semantic_activation_resolve_shared_undo_root( - const ClusterSemanticAdmissionToken *token, ClusterUndoPathIntent intent, - uint32 owner_instance, uint32 segment_id, - ClusterUndoBlock0ResolvedRoot *out) +cluster_semantic_activation_resolve_shared_undo_root(const ClusterSemanticAdmissionToken *token, + ClusterUndoPathIntent intent, + uint32 owner_instance, uint32 segment_id, + ClusterUndoBlock0ResolvedRoot *out) { if (token == NULL || !token->entered || out == NULL || intent != CLUSTER_UNDO_PATH_RUNTIME_SHARED - || owner_instance != (uint32)UT_MASTER_NODE + 1 - || (segment_id != 5 && segment_id != 6)) + || owner_instance != (uint32)UT_MASTER_NODE + 1 || (segment_id != 5 && segment_id != 6)) return false; memset(out, 0, sizeof(*out)); out->intent = intent; @@ -1833,15 +1769,13 @@ cluster_semantic_activation_resolve_shared_undo_root( bool cluster_semantic_activation_resolve_shared_undo_root_r4_terminal_census( - const ClusterSemanticAdmissionToken *token, ClusterUndoPathIntent intent, - uint32 owner_instance, uint32 segment_id, - ClusterUndoBlock0ResolvedRoot *out) + const ClusterSemanticAdmissionToken *token, ClusterUndoPathIntent intent, uint32 owner_instance, + uint32 segment_id, ClusterUndoBlock0ResolvedRoot *out) { route_seam.terminal_census_root_calls++; if (token == NULL || !token->entered || out == NULL || intent != CLUSTER_UNDO_PATH_RUNTIME_SHARED - || owner_instance != (uint32)UT_MASTER_NODE + 1 - || (segment_id != 5 && segment_id != 6)) + || owner_instance != (uint32)UT_MASTER_NODE + 1 || (segment_id != 5 && segment_id != 6)) return false; memset(out, 0, sizeof(*out)); out->intent = intent; @@ -1857,42 +1791,39 @@ uba_origin_node_id(UBA uba pg_attribute_unused()) } ClusterUndoBlock0CurrentStep -cluster_undo_block0_current_acquire_begin_admitted( - const ClusterUndoBlock0LogicalKey *key, ClusterUndoBlock0CurrentMode mode, - int timeout_ms pg_attribute_unused(), - const ClusterSemanticAdmissionToken *admission, - ClusterUndoBlock0CurrentGuard *guard, ClusterUndoBlock0Result *failure) +cluster_undo_block0_current_acquire_begin_admitted(const ClusterUndoBlock0LogicalKey *key, + ClusterUndoBlock0CurrentMode mode, + int timeout_ms pg_attribute_unused(), + const ClusterSemanticAdmissionToken *admission, + ClusterUndoBlock0CurrentGuard *guard, + ClusterUndoBlock0Result *failure) { route_seam.candidate_acquire_begin_calls++; if (failure != NULL) *failure = CLUSTER_UNDO_BLOCK0_OK; if (key == NULL || key->owner_instance != (uint8)(UT_MASTER_NODE + 1) - || (key->segment_id != 5 && key->segment_id != 6) - || mode != CLUSTER_UNDO_BLOCK0_SCUR + || (key->segment_id != 5 && key->segment_id != 6) || mode != CLUSTER_UNDO_BLOCK0_SCUR || admission == NULL || !admission->entered || guard == NULL) return CLUSTER_UNDO_BLOCK0_CURRENT_FAILED; return CLUSTER_UNDO_BLOCK0_CURRENT_HELD; } ClusterUndoBlock0CurrentStep -cluster_undo_block0_current_acquire_poll( - ClusterUndoBlock0CurrentGuard *guard pg_attribute_unused(), - ClusterUndoBlock0Result *failure pg_attribute_unused()) +cluster_undo_block0_current_acquire_poll(ClusterUndoBlock0CurrentGuard *guard pg_attribute_unused(), + ClusterUndoBlock0Result *failure pg_attribute_unused()) { return CLUSTER_UNDO_BLOCK0_CURRENT_FAILED; } void -cluster_undo_block0_current_cancel( - ClusterUndoBlock0CurrentGuard *guard pg_attribute_unused()) +cluster_undo_block0_current_cancel(ClusterUndoBlock0CurrentGuard *guard pg_attribute_unused()) { route_seam.candidate_cancel_calls++; } ClusterUndoBlock0CurrentStep -cluster_undo_block0_current_release_begin( - ClusterUndoBlock0CurrentGuard *guard, - ClusterUndoBlock0Result *failure) +cluster_undo_block0_current_release_begin(ClusterUndoBlock0CurrentGuard *guard, + ClusterUndoBlock0Result *failure) { route_seam.candidate_release_begin_calls++; if (failure != NULL) @@ -1902,21 +1833,19 @@ cluster_undo_block0_current_release_begin( } ClusterUndoBlock0CurrentStep -cluster_undo_block0_current_release_poll( - ClusterUndoBlock0CurrentGuard *guard pg_attribute_unused(), - ClusterUndoBlock0Result *failure pg_attribute_unused()) +cluster_undo_block0_current_release_poll(ClusterUndoBlock0CurrentGuard *guard pg_attribute_unused(), + ClusterUndoBlock0Result *failure pg_attribute_unused()) { return CLUSTER_UNDO_BLOCK0_CURRENT_FAILED; } static ClusterTxOutcome -route_test_fill_origin_resolution( - const ClusterTxLocator *locator, - const ClusterSemanticAdmissionToken *admission, - ClusterTxResolution *out, ClusterTxResolveReason *reason_out) +route_test_fill_origin_resolution(const ClusterTxLocator *locator, + const ClusterSemanticAdmissionToken *admission, + ClusterTxResolution *out, ClusterTxResolveReason *reason_out) { - if (locator == NULL || admission == NULL || !admission->entered - || out == NULL || reason_out == NULL) + if (locator == NULL || admission == NULL || !admission->entered || out == NULL + || reason_out == NULL) return CLUSTER_TX_UNKNOWN; memset(out, 0, sizeof(*out)); out->locator_echo = *locator; @@ -1924,9 +1853,7 @@ route_test_fill_origin_resolution( out->top_xid = locator->xid; out->outcome = route_seam.candidate_outcome; out->proof_kind = route_seam.candidate_proof; - out->commit_scn = route_seam.candidate_outcome == CLUSTER_TX_COMMITTED - ? (SCN)101 - : InvalidScn; + out->commit_scn = route_seam.candidate_outcome == CLUSTER_TX_COMMITTED ? (SCN)101 : InvalidScn; out->horizon_scn = (SCN)89; out->authority.origin_epoch = admission->formation_epoch; out->authority.live_hwm_lsn = (XLogRecPtr)UINT64_C(0xabcdef); @@ -1940,11 +1867,9 @@ ClusterRuntimeVisibilityOriginStep cluster_runtime_visibility_origin_plan_freeze_data_held( const ClusterTxLocator *locator, ClusterTxResolveMode mode, const ClusterSemanticAdmissionToken *admission, - const ClusterUndoBlock0Generation *expected_generation, - ClusterUndoBlock0CurrentGuard *guard, - const ClusterUndoBlock0ResolvedRoot *root, - ClusterRuntimeVisibilityOriginPlan *plan, ClusterTxResolution *out, - ClusterTxResolveReason *reason_out) + const ClusterUndoBlock0Generation *expected_generation, ClusterUndoBlock0CurrentGuard *guard, + const ClusterUndoBlock0ResolvedRoot *root, ClusterRuntimeVisibilityOriginPlan *plan, + ClusterTxResolution *out, ClusterTxResolveReason *reason_out) { route_seam.candidate_resolve_calls++; if (locator == NULL @@ -1967,8 +1892,7 @@ cluster_runtime_visibility_origin_plan_freeze_data_held( bool cluster_runtime_visibility_origin_plan_canonical_logical( - const ClusterRuntimeVisibilityOriginPlan *plan, - ClusterUndoBlock0LogicalKey *logical_out) + const ClusterRuntimeVisibilityOriginPlan *plan, ClusterUndoBlock0LogicalKey *logical_out) { if (plan == NULL || logical_out == NULL || plan->opaque[0] != 1) return false; @@ -1980,10 +1904,8 @@ cluster_runtime_visibility_origin_plan_canonical_logical( bool cluster_runtime_visibility_origin_plan_sample_canonical_held( ClusterRuntimeVisibilityOriginPlan *plan, ClusterTxResolveMode mode, - const ClusterSemanticAdmissionToken *admission, - ClusterUndoBlock0CurrentGuard *guard, - const ClusterUndoBlock0ResolvedRoot *root, - ClusterTxResolveReason *reason_out) + const ClusterSemanticAdmissionToken *admission, ClusterUndoBlock0CurrentGuard *guard, + const ClusterUndoBlock0ResolvedRoot *root, ClusterTxResolveReason *reason_out) { route_seam.candidate_canonical_sample_calls++; if (plan == NULL || plan->opaque[0] != 1 @@ -1999,8 +1921,7 @@ cluster_runtime_visibility_origin_plan_sample_canonical_held( ClusterTxOutcome cluster_runtime_visibility_origin_plan_recheck_data_held( ClusterRuntimeVisibilityOriginPlan *plan, ClusterTxResolveMode mode, - const ClusterSemanticAdmissionToken *admission, - ClusterUndoBlock0CurrentGuard *guard, + const ClusterSemanticAdmissionToken *admission, ClusterUndoBlock0CurrentGuard *guard, const ClusterUndoBlock0ResolvedRoot *root, ClusterTxResolution *out, ClusterTxResolveReason *reason_out) { @@ -2008,13 +1929,11 @@ cluster_runtime_visibility_origin_plan_recheck_data_held( route_seam.candidate_data_recheck_calls++; if (plan == NULL || plan->opaque[0] != 1 || plan->opaque[1] != 1 - || mode != CLUSTER_TX_RESOLVE_TERMINAL_CENSUS - || admission == NULL || !admission->entered || guard == NULL - || root == NULL || root->root_id != UINT64_C(0x8000)) + || mode != CLUSTER_TX_RESOLVE_TERMINAL_CENSUS || admission == NULL || !admission->entered + || guard == NULL || root == NULL || root->root_id != UINT64_C(0x8000)) return CLUSTER_TX_UNKNOWN; memcpy(&locator, plan->opaque + 8, sizeof(locator)); - return route_test_fill_origin_resolution( - &locator, admission, out, reason_out); + return route_test_fill_origin_resolution(&locator, admission, out, reason_out); } ClusterTxOutcome @@ -2045,18 +1964,15 @@ ClusterTxOutcome cluster_runtime_visibility_resolve_exact_origin_held( const ClusterTxLocator *locator, ClusterTxResolveMode mode, const ClusterSemanticAdmissionToken *admission, - const ClusterUndoBlock0Generation *expected_generation, - ClusterUndoBlock0CurrentGuard *guard, + const ClusterUndoBlock0Generation *expected_generation, ClusterUndoBlock0CurrentGuard *guard, const ClusterUndoBlock0ResolvedRoot *root, ClusterTxResolution *out, ClusterTxResolveReason *reason_out) { route_seam.candidate_resolve_calls++; - if (locator == NULL || mode != CLUSTER_TX_RESOLVE_TERMINAL_CENSUS - || admission == NULL || !admission->entered - || expected_generation == NULL || !expected_generation->known - || expected_generation->value != UINT32_C(9) || guard == NULL - || root == NULL || root->root_id != UINT64_C(0x8000) - || out == NULL || reason_out == NULL) + if (locator == NULL || mode != CLUSTER_TX_RESOLVE_TERMINAL_CENSUS || admission == NULL + || !admission->entered || expected_generation == NULL || !expected_generation->known + || expected_generation->value != UINT32_C(9) || guard == NULL || root == NULL + || root->root_id != UINT64_C(0x8000) || out == NULL || reason_out == NULL) return CLUSTER_TX_UNKNOWN; memset(out, 0, sizeof(*out)); out->locator_echo = *locator; @@ -2064,9 +1980,7 @@ cluster_runtime_visibility_resolve_exact_origin_held( out->top_xid = locator->xid; out->outcome = route_seam.candidate_outcome; out->proof_kind = route_seam.candidate_proof; - out->commit_scn = route_seam.candidate_outcome == CLUSTER_TX_COMMITTED - ? (SCN)101 - : InvalidScn; + out->commit_scn = route_seam.candidate_outcome == CLUSTER_TX_COMMITTED ? (SCN)101 : InvalidScn; out->horizon_scn = (SCN)89; out->authority.origin_epoch = admission->formation_epoch; out->authority.live_hwm_lsn = (XLogRecPtr)UINT64_C(0xabcdef); @@ -2107,9 +2021,8 @@ cluster_r4_observe_refusal(ClusterR4RefusalStage stage, ClusterCrBuildReason rea } bool -cluster_sf_peer_capability_family_sample(int32 peer_id, uint32 required_bits, - uint32 optional_bits, bool *optional_out, - uint32 *generation_out) +cluster_sf_peer_capability_family_sample(int32 peer_id, uint32 required_bits, uint32 optional_bits, + bool *optional_out, uint32 *generation_out) { int slot = route_seam.capability_calls++; int sequence = ++route_seam.sequence; @@ -2133,8 +2046,7 @@ cluster_sf_peer_capability_family_sample(int32 peer_id, uint32 required_bits, } bool -cluster_sf_peer_multixact_current_capability_generation( - int32 peer_id, uint32 *generation_out) +cluster_sf_peer_multixact_current_capability_generation(int32 peer_id, uint32 *generation_out) { route_seam.current_mx_capability_calls++; route_seam.current_mx_capability_peer = peer_id; @@ -2148,9 +2060,9 @@ cluster_sf_peer_multixact_current_capability_generation( bool cluster_semantic_activation_peer_open_matches(const ClusterSemanticAdmissionToken *token, - int32 authenticated_peer, - uint32 required_capabilities, - uint32 sampled_generation) + int32 authenticated_peer, + uint32 required_capabilities, + uint32 sampled_generation) { int slot = route_seam.peer_open_calls++; int sequence = ++route_seam.sequence; @@ -2173,8 +2085,8 @@ cluster_pcm_lock_r4_route_snapshot(BufferTag tag, PcmAuthoritySnapshot *authorit { route_seam.snapshot_calls++; route_seam.snapshot_sequence = ++route_seam.sequence; - if (!route_seam.snapshot_ok || authority_out == NULL - || master_authority_generation_out == NULL || expected_page_scn_out == NULL) + if (!route_seam.snapshot_ok || authority_out == NULL || master_authority_generation_out == NULL + || expected_page_scn_out == NULL) return false; memset(authority_out, 0, sizeof(*authority_out)); authority_out->state = PCM_STATE_S; @@ -2216,9 +2128,10 @@ cluster_gcs_block_dedup_r4_route_arm_or_match( } GcsBlockR4RouteSendResult -cluster_gcs_block_dedup_r4_route_finish_send( - int worker_id, const GcsBlockR4RouteIdentity *identity, uint8 transition_id, - const ClusterR4CrRouteProof *armed_proof, bool outbound_admitted) +cluster_gcs_block_dedup_r4_route_finish_send(int worker_id, const GcsBlockR4RouteIdentity *identity, + uint8 transition_id, + const ClusterR4CrRouteProof *armed_proof, + bool outbound_admitted) { (void)worker_id; route_seam.finish_calls++; @@ -2235,8 +2148,7 @@ cluster_gcs_block_dedup_r4_route_finish_send( bool cluster_lms_outbound_enqueue_cap_bound(int worker_id, uint8 msg_type, uint32 dest_node_id, const void *payload, uint16 payload_len, - uint32 required_capability, - uint32 connection_generation) + uint32 required_capability, uint32 connection_generation) { route_seam.enqueue_calls++; route_seam.enqueue_sequence = ++route_seam.sequence; @@ -2248,8 +2160,7 @@ cluster_lms_outbound_enqueue_cap_bound(int worker_id, uint8 msg_type, uint32 des route_seam.enqueue_connection_generation = connection_generation; if (payload != NULL && payload_len <= sizeof(route_seam.enqueue_payload)) memcpy(route_seam.enqueue_payload, payload, payload_len); - if (payload != NULL - && payload_len == sizeof(ClusterCurrentMxDescribeForwardV2)) { + if (payload != NULL && payload_len == sizeof(ClusterCurrentMxDescribeForwardV2)) { const ClusterCurrentMxDescribeForwardV2 *request = payload; typedef struct TestCurrentMxDescribeReply { GcsBlockReplyHeader header; @@ -2268,55 +2179,39 @@ cluster_lms_outbound_enqueue_cap_bound(int worker_id, uint8 msg_type, uint32 des route_seam.current_mx_slot_armed = cluster_gcs_block_test_snapshot_r4_requester_slot( - &in_use, &route_seam.current_mx_slot_domain, - &slot_request_id, &transition_id, &slot_tag, &slot_epoch, - &slot_master, &direct_state, &direct_target_prepared) - && in_use - && route_seam.current_mx_slot_domain - == UT_REPLY_DOMAIN_CURRENT_MX - && slot_request_id == request->prefix.request_id - && transition_id == 0 - && slot_epoch == request->prefix.epoch - && slot_master == (int32)dest_node_id - && direct_state == GCS_BLOCK_DIRECT_UNARMED - && !direct_target_prepared; - if (route_seam.current_mx_reply_enabled - && route_seam.current_mx_slot_armed) { + &in_use, &route_seam.current_mx_slot_domain, &slot_request_id, &transition_id, + &slot_tag, &slot_epoch, &slot_master, &direct_state, &direct_target_prepared) + && in_use && route_seam.current_mx_slot_domain == UT_REPLY_DOMAIN_CURRENT_MX + && slot_request_id == request->prefix.request_id && transition_id == 0 + && slot_epoch == request->prefix.epoch && slot_master == (int32)dest_node_id + && direct_state == GCS_BLOCK_DIRECT_UNARMED && !direct_target_prepared; + if (route_seam.current_mx_reply_enabled && route_seam.current_mx_slot_armed) { memset(&reply, 0, sizeof(reply)); reply.header.request_id = request->prefix.request_id; reply.header.epoch = request->prefix.epoch; reply.header.sender_node = (int32)dest_node_id; - reply.header.requester_backend_id - = request->prefix.requester_backend_id; - reply.header.status - = (uint8)GCS_BLOCK_REPLY_CURRENT_MX_DESCRIBE_RESULT; - GcsBlockReplyHeaderSetForwardingMasterNode( - &reply.header, GCS_BLOCK_REPLY_NO_FORWARDING_MASTER); + reply.header.requester_backend_id = request->prefix.requester_backend_id; + reply.header.status = (uint8)GCS_BLOCK_REPLY_CURRENT_MX_DESCRIBE_RESULT; + GcsBlockReplyHeaderSetForwardingMasterNode(&reply.header, + GCS_BLOCK_REPLY_NO_FORWARDING_MASTER); reply.page.header.magic = CLUSTER_CURRENT_MX_WIRE_MAGIC; reply.page.header.version = CLUSTER_CURRENT_MX_WIRE_VERSION; - reply.page.header.kind - = GCS_BLOCK_FORWARD_KIND_CURRENT_MX_DESCRIBE; - reply.page.header.result - = (uint8)route_seam.current_mx_validate_result; + reply.page.header.kind = GCS_BLOCK_FORWARD_KIND_CURRENT_MX_DESCRIBE; + reply.page.header.result = (uint8)route_seam.current_mx_validate_result; reply.page.header.source_node_id = dest_node_id; reply.page.header.request_id = request->prefix.request_id; reply.page.header.mxkey = request->prefix.mxkey; - reply.page.header.wire_length - = sizeof(ClusterCurrentMxDescribeReplyHeader); - reply.header.checksum = cluster_gcs_block_compute_checksum( - (const char *)&reply.page); - reply_env = route_test_envelope( - PGRAC_IC_MSG_GCS_BLOCK_REPLY, dest_node_id, - (uint32)cluster_node_id, sizeof(reply)); + reply.page.header.wire_length = sizeof(ClusterCurrentMxDescribeReplyHeader); + reply.header.checksum = cluster_gcs_block_compute_checksum((const char *)&reply.page); + reply_env = route_test_envelope(PGRAC_IC_MSG_GCS_BLOCK_REPLY, dest_node_id, + (uint32)cluster_node_id, sizeof(reply)); cluster_gcs_handle_block_reply_envelope(&reply_env, &reply); } } - if (payload != NULL - && payload_len == sizeof(ClusterCurrentMxProofForwardV2) + if (payload != NULL && payload_len == sizeof(ClusterCurrentMxProofForwardV2) && ((const ClusterCurrentMxProofForwardV2 *)payload)->prefix.kind == GCS_BLOCK_FORWARD_KIND_CURRENT_MX_MEMBER_PROOF - && route_seam.current_mx_proof_reply_enabled - && route_seam.current_mx_slot_armed) { + && route_seam.current_mx_proof_reply_enabled && route_seam.current_mx_slot_armed) { const ClusterCurrentMxProofForwardV2 *request = payload; typedef struct TestCurrentMxProofReply { GcsBlockReplyHeader header; @@ -2329,18 +2224,14 @@ cluster_lms_outbound_enqueue_cap_bound(int worker_id, uint8 msg_type, uint32 des reply.header.request_id = request->prefix.request_id; reply.header.epoch = request->prefix.epoch; reply.header.sender_node = (int32)dest_node_id; - reply.header.requester_backend_id - = request->prefix.requester_backend_id; - reply.header.status - = (uint8)GCS_BLOCK_REPLY_CURRENT_MX_MEMBER_PROOF_RESULT; - GcsBlockReplyHeaderSetForwardingMasterNode( - &reply.header, GCS_BLOCK_REPLY_NO_FORWARDING_MASTER); + reply.header.requester_backend_id = request->prefix.requester_backend_id; + reply.header.status = (uint8)GCS_BLOCK_REPLY_CURRENT_MX_MEMBER_PROOF_RESULT; + GcsBlockReplyHeaderSetForwardingMasterNode(&reply.header, + GCS_BLOCK_REPLY_NO_FORWARDING_MASTER); reply.page.header.magic = CLUSTER_CURRENT_MX_WIRE_MAGIC; reply.page.header.version = CLUSTER_CURRENT_MX_WIRE_VERSION; - reply.page.header.kind - = GCS_BLOCK_FORWARD_KIND_CURRENT_MX_MEMBER_PROOF; - reply.page.header.result - = (uint8)route_seam.current_mx_proof_validate_result; + reply.page.header.kind = GCS_BLOCK_FORWARD_KIND_CURRENT_MX_MEMBER_PROOF; + reply.page.header.result = (uint8)route_seam.current_mx_proof_validate_result; reply.page.header.source_node_id = dest_node_id; reply.page.header.request_id = request->prefix.request_id; reply.page.header.mxkey = request->prefix.mxkey; @@ -2348,15 +2239,11 @@ cluster_lms_outbound_enqueue_cap_bound(int worker_id, uint8 msg_type, uint32 des = ClusterCurrentMxProofPrefixGetDescriptorHash(&request->prefix); reply.page.header.total_count = request->prefix.total_count; reply.page.header.chunk_ordinal = request->prefix.chunk_ordinal; - reply.page.header.chunk_count_minus_one - = request->prefix.chunk_count_minus_one; - reply.page.header.wire_length - = sizeof(ClusterCurrentMxProofReplyHeader); - reply.header.checksum = cluster_gcs_block_compute_checksum( - (const char *)&reply.page); - reply_env = route_test_envelope( - PGRAC_IC_MSG_GCS_BLOCK_REPLY, dest_node_id, - (uint32)cluster_node_id, sizeof(reply)); + reply.page.header.chunk_count_minus_one = request->prefix.chunk_count_minus_one; + reply.page.header.wire_length = sizeof(ClusterCurrentMxProofReplyHeader); + reply.header.checksum = cluster_gcs_block_compute_checksum((const char *)&reply.page); + reply_env = route_test_envelope(PGRAC_IC_MSG_GCS_BLOCK_REPLY, dest_node_id, + (uint32)cluster_node_id, sizeof(reply)); cluster_gcs_handle_block_reply_envelope(&reply_env, &reply); } return route_seam.enqueue_ok; @@ -2364,12 +2251,10 @@ cluster_lms_outbound_enqueue_cap_bound(int worker_id, uint8 msg_type, uint32 des ClusterMxDescribeResult cluster_multixact_current_wire_validate_describe_reply( - const void *payload, uint32 payload_length, int32 expected_source, - uint64 current_epoch, uint64 expected_request_id, - const ClusterCurrentMxKey *expected_key, + const void *payload, uint32 payload_length, int32 expected_source, uint64 current_epoch, + uint64 expected_request_id, const ClusterCurrentMxKey *expected_key, ClusterCurrentMxMemberDesc *members pg_attribute_unused(), - uint16 members_cap pg_attribute_unused(), - uint16 *members_count, uint32 *reported_total_members) + uint16 members_cap pg_attribute_unused(), uint16 *members_count, uint32 *reported_total_members) { const ClusterCurrentMxDescribeReplyPage *page = payload; @@ -2378,15 +2263,13 @@ cluster_multixact_current_wire_validate_describe_reply( *members_count = 0; if (reported_total_members != NULL) *reported_total_members = 0; - if (payload == NULL || payload_length != sizeof(*page) - || expected_key == NULL + if (payload == NULL || payload_length != sizeof(*page) || expected_key == NULL || page->header.magic != CLUSTER_CURRENT_MX_WIRE_MAGIC || page->header.version != CLUSTER_CURRENT_MX_WIRE_VERSION || page->header.kind != GCS_BLOCK_FORWARD_KIND_CURRENT_MX_DESCRIBE || page->header.source_node_id != (uint32)expected_source || page->header.request_id != expected_request_id - || page->header.mxkey.origin_node_id - != expected_key->origin_node_id + || page->header.mxkey.origin_node_id != expected_key->origin_node_id || page->header.mxkey.multixact_id != expected_key->multixact_id || page->header.mxkey.cluster_epoch != (uint32)current_epoch) return CMX_DESC_UNKNOWN; @@ -2394,23 +2277,21 @@ cluster_multixact_current_wire_validate_describe_reply( } bool -cluster_multixact_current_wire_validate_proof_forward( - const void *payload, uint32 payload_length, int32 envelope_source, - int32 local_node pg_attribute_unused(), uint64 current_epoch, - ClusterCurrentMxProofForwardV2 *decoded) +cluster_multixact_current_wire_validate_proof_forward(const void *payload, uint32 payload_length, + int32 envelope_source, + int32 local_node pg_attribute_unused(), + uint64 current_epoch, + ClusterCurrentMxProofForwardV2 *decoded) { const ClusterCurrentMxProofForwardV2 *request = payload; if (decoded != NULL) memset(decoded, 0, sizeof(*decoded)); - if (request == NULL || decoded == NULL - || payload_length != sizeof(*request) - || request->prefix.request_id == 0 - || request->prefix.epoch != current_epoch + if (request == NULL || decoded == NULL || payload_length != sizeof(*request) + || request->prefix.request_id == 0 || request->prefix.epoch != current_epoch || request->prefix.original_requester_node != envelope_source || request->prefix.requester_backend_id <= 0 - || request->prefix.kind - != GCS_BLOCK_FORWARD_KIND_CURRENT_MX_MEMBER_PROOF + || request->prefix.kind != GCS_BLOCK_FORWARD_KIND_CURRENT_MX_MEMBER_PROOF || request->trailer.magic != CLUSTER_CURRENT_MX_WIRE_MAGIC || request->trailer.version != CLUSTER_CURRENT_MX_WIRE_VERSION) return false; @@ -2420,14 +2301,11 @@ cluster_multixact_current_wire_validate_proof_forward( bool cluster_multixact_current_wire_validate_proof_reply_frame( - const void *payload, uint32 payload_length, int32 expected_source, - uint64 current_epoch, - const ClusterCurrentMxProofForwardV2 *expected_request, - ClusterMxResolveResult *result, + const void *payload, uint32 payload_length, int32 expected_source, uint64 current_epoch, + const ClusterCurrentMxProofForwardV2 *expected_request, ClusterMxResolveResult *result, ClusterCurrentMemberProof *proofs pg_attribute_unused(), uint16 proofs_cap pg_attribute_unused(), uint16 *proof_count, - ClusterCurrentUpdaterProof *updater_proof, - uint32 *requester_capability_generation_out) + ClusterCurrentUpdaterProof *updater_proof, uint32 *requester_capability_generation_out) { const ClusterCurrentMxProofReplyPage *page = payload; @@ -2442,32 +2320,27 @@ cluster_multixact_current_wire_validate_proof_reply_frame( } if (requester_capability_generation_out != NULL) *requester_capability_generation_out = 0; - if (payload == NULL || payload_length != sizeof(*page) - || expected_request == NULL || result == NULL - || page->header.magic != CLUSTER_CURRENT_MX_WIRE_MAGIC + if (payload == NULL || payload_length != sizeof(*page) || expected_request == NULL + || result == NULL || page->header.magic != CLUSTER_CURRENT_MX_WIRE_MAGIC || page->header.version != CLUSTER_CURRENT_MX_WIRE_VERSION - || page->header.kind - != GCS_BLOCK_FORWARD_KIND_CURRENT_MX_MEMBER_PROOF + || page->header.kind != GCS_BLOCK_FORWARD_KIND_CURRENT_MX_MEMBER_PROOF || page->header.source_node_id != (uint32)expected_source || page->header.request_id != expected_request->prefix.request_id - || page->header.mxkey.origin_node_id - != expected_request->prefix.mxkey.origin_node_id - || page->header.mxkey.multixact_id - != expected_request->prefix.mxkey.multixact_id + || page->header.mxkey.origin_node_id != expected_request->prefix.mxkey.origin_node_id + || page->header.mxkey.multixact_id != expected_request->prefix.mxkey.multixact_id || page->header.mxkey.cluster_epoch != (uint32)current_epoch) return false; *result = route_seam.current_mx_proof_validate_result; - if (*result == CMX_RESOLVE_OK - && requester_capability_generation_out != NULL) - *requester_capability_generation_out - = page->header.requester_capability_generation; + if (*result == CMX_RESOLVE_OK && requester_capability_generation_out != NULL) + *requester_capability_generation_out = page->header.requester_capability_generation; return true; } bool -cluster_lms_outbound_enqueue_zero_block_reply_cap_bound( - int worker_id, uint32 dest_node_id, const GcsBlockReplyHeader *header, - uint32 required_capability, uint32 connection_generation) +cluster_lms_outbound_enqueue_zero_block_reply_cap_bound(int worker_id, uint32 dest_node_id, + const GcsBlockReplyHeader *header, + uint32 required_capability, + uint32 connection_generation) { route_seam.refusal_enqueue_calls++; route_seam.refusal_enqueue_sequence = ++route_seam.sequence; @@ -2512,8 +2385,7 @@ route_assert_holder_refusal(GcsBlockReplyStatus status) UT_ASSERT_EQ(route_seam.refusal_enqueue_calls, 1); UT_ASSERT_EQ(route_seam.refusal_enqueue_worker, 0); UT_ASSERT_EQ(route_seam.refusal_enqueue_dest, UT_REQUESTER_NODE); - UT_ASSERT_EQ(route_seam.refusal_enqueue_required_capability, - UT_R4_REQUIRED_CAPABILITIES); + UT_ASSERT_EQ(route_seam.refusal_enqueue_required_capability, UT_R4_REQUIRED_CAPABILITIES); UT_ASSERT_EQ(route_seam.refusal_enqueue_connection_generation, UT_REQUESTER_CAPABILITY_GENERATION); UT_ASSERT_EQ(route_seam.refusal_header.request_id, UT_REQUEST_ID); @@ -2534,8 +2406,7 @@ ClusterCrBuildResult cluster_lms_cr_submit_r4(const ClusterR4CrForwardPayload *forward, const ClusterSemanticAdmissionToken *receive_admission, uint32 requester_capability_generation, - uint32 master_capability_generation, - ClusterCrBuildReason *reason_out) + uint32 master_capability_generation, ClusterCrBuildReason *reason_out) { route_seam.holder_submit_calls++; route_seam.holder_submit_sequence = ++route_seam.sequence; @@ -2544,8 +2415,7 @@ cluster_lms_cr_submit_r4(const ClusterR4CrForwardPayload *forward, route_seam.submitted_forward = *forward; if (receive_admission != NULL) route_seam.submitted_admission = *receive_admission; - route_seam.submitted_requester_capability_generation - = requester_capability_generation; + route_seam.submitted_requester_capability_generation = requester_capability_generation; route_seam.submitted_master_capability_generation = master_capability_generation; route_seam.submitted_reason_out_present = reason_out != NULL; if (reason_out != NULL) @@ -2568,8 +2438,7 @@ route_snapshot(PcmState state) } static ClusterCrBuildReason -classify(const PcmAuthoritySnapshot *authority, uint64 epoch, uint64 generation, - int32 *holder_out) +classify(const PcmAuthoritySnapshot *authority, uint64 epoch, uint64 generation, int32 *holder_out) { return cluster_r4_route_policy_classify(authority, epoch, generation, holder_out); } @@ -2577,118 +2446,101 @@ classify(const PcmAuthoritySnapshot *authority, uint64 epoch, uint64 generation, #define DEFINE_REASON_TEST(test_name, setup_code, expected_reason, expected_holder) \ UT_TEST(test_name) \ { \ - PcmAuthoritySnapshot authority = route_snapshot(PCM_STATE_N); \ - PcmAuthoritySnapshot *authority_ptr = &authority; \ - uint64 epoch = 9; \ - uint64 generation = (epoch << 32) | 3; \ - int32 holder = -1; \ - setup_code; \ - UT_ASSERT_EQ(classify(authority_ptr, epoch, generation, &holder), (expected_reason)); \ - UT_ASSERT_EQ(holder, (expected_holder)); \ + PcmAuthoritySnapshot authority = route_snapshot(PCM_STATE_N); \ + PcmAuthoritySnapshot *authority_ptr = &authority; \ + uint64 epoch = 9; \ + uint64 generation = (epoch << 32) | 3; \ + int32 holder = -1; \ + setup_code; \ + UT_ASSERT_EQ(classify(authority_ptr, epoch, generation, &holder), (expected_reason)); \ + UT_ASSERT_EQ(holder, (expected_holder)); \ } DEFINE_REASON_TEST(test_01_null_authority_is_protocol, authority_ptr = NULL, - CLUSTER_CR_BUILD_PROTOCOL, -1) + CLUSTER_CR_BUILD_PROTOCOL, -1) UT_TEST(test_02_null_output_is_protocol) { PcmAuthoritySnapshot authority = route_snapshot(PCM_STATE_N); - UT_ASSERT_EQ(classify(&authority, 9, (UINT64_C(9) << 32) | 3, NULL), - CLUSTER_CR_BUILD_PROTOCOL); + UT_ASSERT_EQ(classify(&authority, 9, (UINT64_C(9) << 32) | 3, NULL), CLUSTER_CR_BUILD_PROTOCOL); } DEFINE_REASON_TEST(test_03_canonical_n_has_no_holder, (void)0, CLUSTER_CR_BUILD_NO_HOLDER, -1) DEFINE_REASON_TEST(test_04_n_with_x_is_ambiguous, authority.x_holder_node = 1, - CLUSTER_CR_BUILD_HOLDER_AMBIGUOUS, -1) + CLUSTER_CR_BUILD_HOLDER_AMBIGUOUS, -1) DEFINE_REASON_TEST(test_05_n_with_s_is_ambiguous, authority.s_holders_bitmap = 1, - CLUSTER_CR_BUILD_HOLDER_AMBIGUOUS, -1) + CLUSTER_CR_BUILD_HOLDER_AMBIGUOUS, -1) DEFINE_REASON_TEST(test_06_n_with_master_is_ambiguous, authority.master_holder.node_id = 1, - CLUSTER_CR_BUILD_HOLDER_AMBIGUOUS, -1) -DEFINE_REASON_TEST(test_07_x_node_zero_is_selected, - authority.state = PCM_STATE_X; authority.x_holder_node = 0; - authority.master_holder.node_id = 0, - CLUSTER_CR_BUILD_NONE, 0) -DEFINE_REASON_TEST(test_08_x_node_31_is_selected, - authority.state = PCM_STATE_X; authority.x_holder_node = 31; - authority.master_holder.node_id = 31, - CLUSTER_CR_BUILD_NONE, 31) + CLUSTER_CR_BUILD_HOLDER_AMBIGUOUS, -1) +DEFINE_REASON_TEST(test_07_x_node_zero_is_selected, authority.state = PCM_STATE_X; + authority.x_holder_node = 0; + authority.master_holder.node_id = 0, CLUSTER_CR_BUILD_NONE, 0) +DEFINE_REASON_TEST(test_08_x_node_31_is_selected, authority.state = PCM_STATE_X; + authority.x_holder_node = 31; + authority.master_holder.node_id = 31, CLUSTER_CR_BUILD_NONE, 31) DEFINE_REASON_TEST(test_09_x_without_holder_is_ambiguous, authority.state = PCM_STATE_X, - CLUSTER_CR_BUILD_HOLDER_AMBIGUOUS, -1) -DEFINE_REASON_TEST(test_10_x_negative_holder_is_ambiguous, - authority.state = PCM_STATE_X; authority.x_holder_node = -2, - CLUSTER_CR_BUILD_HOLDER_AMBIGUOUS, -1) -DEFINE_REASON_TEST(test_11_x_out_of_range_is_ambiguous, - authority.state = PCM_STATE_X; authority.x_holder_node = 32; - authority.master_holder.node_id = 32, - CLUSTER_CR_BUILD_HOLDER_AMBIGUOUS, -1) -DEFINE_REASON_TEST(test_12_x_master_mismatch_is_ambiguous, - authority.state = PCM_STATE_X; authority.x_holder_node = 4; - authority.master_holder.node_id = 5, - CLUSTER_CR_BUILD_HOLDER_AMBIGUOUS, -1) -DEFINE_REASON_TEST(test_13_x_with_s_bitmap_is_ambiguous, - authority.state = PCM_STATE_X; authority.x_holder_node = 4; - authority.master_holder.node_id = 4; authority.s_holders_bitmap = 1, - CLUSTER_CR_BUILD_HOLDER_AMBIGUOUS, -1) -DEFINE_REASON_TEST(test_14_s_node_zero_is_selected, - authority.state = PCM_STATE_S; authority.master_holder.node_id = 0; - authority.s_holders_bitmap = 1, - CLUSTER_CR_BUILD_NONE, 0) -DEFINE_REASON_TEST(test_15_s_node_31_is_selected, - authority.state = PCM_STATE_S; authority.master_holder.node_id = 31; - authority.s_holders_bitmap = UINT32_C(1) << 31, - CLUSTER_CR_BUILD_NONE, 31) -DEFINE_REASON_TEST(test_16_s_multiple_selects_canonical, - authority.state = PCM_STATE_S; authority.master_holder.node_id = 3; - authority.s_holders_bitmap = (UINT32_C(1) << 2) | (UINT32_C(1) << 3), - CLUSTER_CR_BUILD_NONE, 3) -DEFINE_REASON_TEST(test_17_s_zero_bitmap_is_ambiguous, - authority.state = PCM_STATE_S; authority.master_holder.node_id = 3, - CLUSTER_CR_BUILD_HOLDER_AMBIGUOUS, -1) -DEFINE_REASON_TEST(test_18_s_with_x_is_ambiguous, - authority.state = PCM_STATE_S; authority.master_holder.node_id = 3; - authority.s_holders_bitmap = UINT32_C(1) << 3; authority.x_holder_node = 3, - CLUSTER_CR_BUILD_HOLDER_AMBIGUOUS, -1) -DEFINE_REASON_TEST(test_19_s_without_master_is_ambiguous, - authority.state = PCM_STATE_S; authority.s_holders_bitmap = 1, - CLUSTER_CR_BUILD_HOLDER_AMBIGUOUS, -1) -DEFINE_REASON_TEST(test_20_s_out_of_range_master_is_ambiguous, - authority.state = PCM_STATE_S; authority.master_holder.node_id = 33; - authority.s_holders_bitmap = 1, - CLUSTER_CR_BUILD_HOLDER_AMBIGUOUS, -1) -DEFINE_REASON_TEST(test_21_s_missing_canonical_bit_is_ambiguous, - authority.state = PCM_STATE_S; authority.master_holder.node_id = 3; - authority.s_holders_bitmap = UINT32_C(1) << 2, - CLUSTER_CR_BUILD_HOLDER_AMBIGUOUS, -1) + CLUSTER_CR_BUILD_HOLDER_AMBIGUOUS, -1) +DEFINE_REASON_TEST(test_10_x_negative_holder_is_ambiguous, authority.state = PCM_STATE_X; + authority.x_holder_node = -2, CLUSTER_CR_BUILD_HOLDER_AMBIGUOUS, -1) +DEFINE_REASON_TEST(test_11_x_out_of_range_is_ambiguous, authority.state = PCM_STATE_X; + authority.x_holder_node = 32; + authority.master_holder.node_id = 32, CLUSTER_CR_BUILD_HOLDER_AMBIGUOUS, -1) +DEFINE_REASON_TEST(test_12_x_master_mismatch_is_ambiguous, authority.state = PCM_STATE_X; + authority.x_holder_node = 4; + authority.master_holder.node_id = 5, CLUSTER_CR_BUILD_HOLDER_AMBIGUOUS, -1) +DEFINE_REASON_TEST(test_13_x_with_s_bitmap_is_ambiguous, authority.state = PCM_STATE_X; + authority.x_holder_node = 4; authority.master_holder.node_id = 4; + authority.s_holders_bitmap = 1, CLUSTER_CR_BUILD_HOLDER_AMBIGUOUS, -1) +DEFINE_REASON_TEST(test_14_s_node_zero_is_selected, authority.state = PCM_STATE_S; + authority.master_holder.node_id = 0; + authority.s_holders_bitmap = 1, CLUSTER_CR_BUILD_NONE, 0) +DEFINE_REASON_TEST(test_15_s_node_31_is_selected, authority.state = PCM_STATE_S; + authority.master_holder.node_id = 31; + authority.s_holders_bitmap = UINT32_C(1) << 31, CLUSTER_CR_BUILD_NONE, 31) +DEFINE_REASON_TEST(test_16_s_multiple_selects_canonical, authority.state = PCM_STATE_S; + authority.master_holder.node_id = 3; + authority.s_holders_bitmap = (UINT32_C(1) << 2) | (UINT32_C(1) << 3), + CLUSTER_CR_BUILD_NONE, 3) +DEFINE_REASON_TEST(test_17_s_zero_bitmap_is_ambiguous, authority.state = PCM_STATE_S; + authority.master_holder.node_id = 3, CLUSTER_CR_BUILD_HOLDER_AMBIGUOUS, -1) +DEFINE_REASON_TEST(test_18_s_with_x_is_ambiguous, authority.state = PCM_STATE_S; + authority.master_holder.node_id = 3; + authority.s_holders_bitmap = UINT32_C(1) << 3; + authority.x_holder_node = 3, CLUSTER_CR_BUILD_HOLDER_AMBIGUOUS, -1) +DEFINE_REASON_TEST(test_19_s_without_master_is_ambiguous, authority.state = PCM_STATE_S; + authority.s_holders_bitmap = 1, CLUSTER_CR_BUILD_HOLDER_AMBIGUOUS, -1) +DEFINE_REASON_TEST(test_20_s_out_of_range_master_is_ambiguous, authority.state = PCM_STATE_S; + authority.master_holder.node_id = 33; + authority.s_holders_bitmap = 1, CLUSTER_CR_BUILD_HOLDER_AMBIGUOUS, -1) +DEFINE_REASON_TEST(test_21_s_missing_canonical_bit_is_ambiguous, authority.state = PCM_STATE_S; + authority.master_holder.node_id = 3; + authority.s_holders_bitmap = UINT32_C(1) << 2, CLUSTER_CR_BUILD_HOLDER_AMBIGUOUS, + -1) DEFINE_REASON_TEST(test_22_unknown_state_is_ambiguous, authority.state = (PcmState)99, - CLUSTER_CR_BUILD_HOLDER_AMBIGUOUS, -1) + CLUSTER_CR_BUILD_HOLDER_AMBIGUOUS, -1) DEFINE_REASON_TEST(test_23_reserved_zero_is_required, authority.reserved[0] = 1, - CLUSTER_CR_BUILD_HOLDER_AMBIGUOUS, -1) + CLUSTER_CR_BUILD_HOLDER_AMBIGUOUS, -1) DEFINE_REASON_TEST(test_24_reserved_one_is_required, authority.reserved[1] = 1, - CLUSTER_CR_BUILD_HOLDER_AMBIGUOUS, -1) + CLUSTER_CR_BUILD_HOLDER_AMBIGUOUS, -1) DEFINE_REASON_TEST(test_25_pending_destructive_convert_is_recovering, - authority.pending_x_requester_node = 4, - CLUSTER_CR_BUILD_RECOVERING, -1) -DEFINE_REASON_TEST(test_26_zero_master_generation_is_rejected, - authority.state = PCM_STATE_S; authority.master_holder.node_id = 0; - authority.s_holders_bitmap = 1; generation = 0, - CLUSTER_CR_BUILD_GENERATION_MISMATCH, -1) -DEFINE_REASON_TEST(test_27_zero_restart_half_is_rejected, - authority.state = PCM_STATE_S; authority.master_holder.node_id = 0; - authority.s_holders_bitmap = 1; generation = epoch << 32, - CLUSTER_CR_BUILD_GENERATION_MISMATCH, -1) -DEFINE_REASON_TEST(test_28_wrong_epoch_half_is_rejected, - authority.state = PCM_STATE_S; authority.master_holder.node_id = 0; - authority.s_holders_bitmap = 1; generation = ((epoch + 1) << 32) | 3, - CLUSTER_CR_BUILD_GENERATION_MISMATCH, -1) -DEFINE_REASON_TEST(test_29_zero_transition_count_is_rejected, - authority.state = PCM_STATE_S; authority.master_holder.node_id = 0; - authority.s_holders_bitmap = 1; authority.transition_count = 0, - CLUSTER_CR_BUILD_GENERATION_MISMATCH, -1) -DEFINE_REASON_TEST(test_30_exhausted_transition_count_is_rejected, - authority.state = PCM_STATE_S; authority.master_holder.node_id = 0; - authority.s_holders_bitmap = 1; authority.transition_count = UINT64_MAX, - CLUSTER_CR_BUILD_GENERATION_MISMATCH, -1) + authority.pending_x_requester_node = 4, CLUSTER_CR_BUILD_RECOVERING, -1) +DEFINE_REASON_TEST(test_26_zero_master_generation_is_rejected, authority.state = PCM_STATE_S; + authority.master_holder.node_id = 0; authority.s_holders_bitmap = 1; + generation = 0, CLUSTER_CR_BUILD_GENERATION_MISMATCH, -1) +DEFINE_REASON_TEST(test_27_zero_restart_half_is_rejected, authority.state = PCM_STATE_S; + authority.master_holder.node_id = 0; authority.s_holders_bitmap = 1; + generation = epoch << 32, CLUSTER_CR_BUILD_GENERATION_MISMATCH, -1) +DEFINE_REASON_TEST(test_28_wrong_epoch_half_is_rejected, authority.state = PCM_STATE_S; + authority.master_holder.node_id = 0; authority.s_holders_bitmap = 1; + generation = ((epoch + 1) << 32) | 3, CLUSTER_CR_BUILD_GENERATION_MISMATCH, -1) +DEFINE_REASON_TEST(test_29_zero_transition_count_is_rejected, authority.state = PCM_STATE_S; + authority.master_holder.node_id = 0; authority.s_holders_bitmap = 1; + authority.transition_count = 0, CLUSTER_CR_BUILD_GENERATION_MISMATCH, -1) +DEFINE_REASON_TEST(test_30_exhausted_transition_count_is_rejected, authority.state = PCM_STATE_S; + authority.master_holder.node_id = 0; authority.s_holders_bitmap = 1; + authority.transition_count = UINT64_MAX, CLUSTER_CR_BUILD_GENERATION_MISMATCH, + -1) static ClusterR4CrRouteProof route_proof(void) @@ -2708,16 +2560,14 @@ UT_TEST(test_31_exact_duplicate_route_matches) { ClusterR4CrRouteProof proof = route_proof(); - UT_ASSERT(cluster_r4_route_proof_matches(&proof, 9, (UINT64_C(9) << 32) | 3, 4, 7, - (SCN)11)); + UT_ASSERT(cluster_r4_route_proof_matches(&proof, 9, (UINT64_C(9) << 32) | 3, 4, 7, (SCN)11)); } UT_TEST(test_32_transition_drift_closes_duplicate) { ClusterR4CrRouteProof proof = route_proof(); - UT_ASSERT(!cluster_r4_route_proof_matches(&proof, 9, (UINT64_C(9) << 32) | 3, 4, 8, - (SCN)11)); + UT_ASSERT(!cluster_r4_route_proof_matches(&proof, 9, (UINT64_C(9) << 32) | 3, 4, 8, (SCN)11)); } static const ClusterCrBuildResult reason_result[18] = { @@ -2748,8 +2598,11 @@ run_reason_polarity(int reason) reason_result[reason]); } -#define DEFINE_POLARITY_TEST(n) \ - UT_TEST(test_reason_polarity_##n) { run_reason_polarity(n); } +#define DEFINE_POLARITY_TEST(n) \ + UT_TEST(test_reason_polarity_##n) \ + { \ + run_reason_polarity(n); \ + } DEFINE_POLARITY_TEST(0) DEFINE_POLARITY_TEST(1) @@ -2780,45 +2633,42 @@ UT_TEST(test_unknown_reason_fails_closed) UT_TEST(test_d3_result_reason_mapping_is_closed) { - static const GcsBlockReplyStatus expected[18] = { - GCS_BLOCK_REPLY_R4_DENIED, - GCS_BLOCK_REPLY_R4_RETRYABLE_HOLDER_MOVED, - GCS_BLOCK_REPLY_R4_RETRYABLE_HOLDER_MOVED, - GCS_BLOCK_REPLY_R4_RETRYABLE_HOLDER_MOVED, - GCS_BLOCK_REPLY_R4_RETRYABLE_HOLDER_MOVED, - GCS_BLOCK_REPLY_R4_RETRYABLE_HOLDER_MOVED, - GCS_BLOCK_REPLY_R4_RETRYABLE_HOLDER_MOVED, - GCS_BLOCK_REPLY_R4_RETRYABLE_HOLDER_MOVED, - GCS_BLOCK_REPLY_R4_RETRYABLE_HOLDER_MOVED, - GCS_BLOCK_REPLY_R4_RETRYABLE_HOLDER_MOVED, - GCS_BLOCK_REPLY_R4_DENIED, - GCS_BLOCK_REPLY_R4_DENIED, - GCS_BLOCK_REPLY_R4_DENIED, - GCS_BLOCK_REPLY_R4_DENIED, - GCS_BLOCK_REPLY_R4_RETRYABLE_HOLDER_MOVED, - GCS_BLOCK_REPLY_R4_DENIED, - GCS_BLOCK_REPLY_R4_DENIED, - GCS_BLOCK_REPLY_R4_DENIED - }; + static const GcsBlockReplyStatus expected[18] = { GCS_BLOCK_REPLY_R4_DENIED, + GCS_BLOCK_REPLY_R4_RETRYABLE_HOLDER_MOVED, + GCS_BLOCK_REPLY_R4_RETRYABLE_HOLDER_MOVED, + GCS_BLOCK_REPLY_R4_RETRYABLE_HOLDER_MOVED, + GCS_BLOCK_REPLY_R4_RETRYABLE_HOLDER_MOVED, + GCS_BLOCK_REPLY_R4_RETRYABLE_HOLDER_MOVED, + GCS_BLOCK_REPLY_R4_RETRYABLE_HOLDER_MOVED, + GCS_BLOCK_REPLY_R4_RETRYABLE_HOLDER_MOVED, + GCS_BLOCK_REPLY_R4_RETRYABLE_HOLDER_MOVED, + GCS_BLOCK_REPLY_R4_RETRYABLE_HOLDER_MOVED, + GCS_BLOCK_REPLY_R4_DENIED, + GCS_BLOCK_REPLY_R4_DENIED, + GCS_BLOCK_REPLY_R4_DENIED, + GCS_BLOCK_REPLY_R4_DENIED, + GCS_BLOCK_REPLY_R4_RETRYABLE_HOLDER_MOVED, + GCS_BLOCK_REPLY_R4_DENIED, + GCS_BLOCK_REPLY_R4_DENIED, + GCS_BLOCK_REPLY_R4_DENIED }; int reason; - for (reason = CLUSTER_CR_BUILD_TARGET_DISABLED; reason <= CLUSTER_CR_BUILD_PROTOCOL; - reason++) { + for (reason = CLUSTER_CR_BUILD_TARGET_DISABLED; reason <= CLUSTER_CR_BUILD_PROTOCOL; reason++) { ClusterCrBuildResult result = cluster_cr_build_result_for_reason((ClusterCrBuildReason)reason); GcsBlockReplyStatus status = GCS_BLOCK_REPLY_GRANTED; - UT_ASSERT(cluster_gcs_block_test_r4_refusal_status( - result, (ClusterCrBuildReason)reason, false, &status)); + UT_ASSERT(cluster_gcs_block_test_r4_refusal_status(result, (ClusterCrBuildReason)reason, + false, &status)); UT_ASSERT_EQ(status, expected[reason]); } { GcsBlockReplyStatus status = GCS_BLOCK_REPLY_GRANTED; - UT_ASSERT(!cluster_gcs_block_test_r4_refusal_status( - CLUSTER_CR_BUILD_FULL, CLUSTER_CR_BUILD_NONE, true, &status)); - UT_ASSERT(cluster_gcs_block_test_r4_refusal_status( - CLUSTER_CR_BUILD_FULL, CLUSTER_CR_BUILD_NONE, false, &status)); + UT_ASSERT(!cluster_gcs_block_test_r4_refusal_status(CLUSTER_CR_BUILD_FULL, + CLUSTER_CR_BUILD_NONE, true, &status)); + UT_ASSERT(cluster_gcs_block_test_r4_refusal_status(CLUSTER_CR_BUILD_FULL, + CLUSTER_CR_BUILD_NONE, false, &status)); UT_ASSERT_EQ(status, GCS_BLOCK_REPLY_R4_DENIED); UT_ASSERT(cluster_gcs_block_test_r4_refusal_status( CLUSTER_CR_BUILD_FAIL_CLOSED, CLUSTER_CR_BUILD_HOLDER_MOVED, false, &status)); @@ -2836,9 +2686,8 @@ UT_TEST(test_r4_refusal_decoder_requires_exact_domain_identity_and_zero_body) char block_data[GCS_BLOCK_DATA_SIZE]; } TestR4Reply; TestR4Reply reply; - ClusterICEnvelope env - = route_test_envelope(PGRAC_IC_MSG_GCS_BLOCK_REPLY, UT_REQUESTER_NODE, UT_MASTER_NODE, - sizeof(reply)); + ClusterICEnvelope env = route_test_envelope(PGRAC_IC_MSG_GCS_BLOCK_REPLY, UT_REQUESTER_NODE, + UT_MASTER_NODE, sizeof(reply)); memset(&reply, 0, sizeof(reply)); reply.header.request_id = UT_REQUEST_ID; @@ -2848,13 +2697,11 @@ UT_TEST(test_r4_refusal_decoder_requires_exact_domain_identity_and_zero_body) reply.header.transition_id = PCM_TRANS_N_TO_S; reply.header.status = GCS_BLOCK_REPLY_R4_RETRYABLE_HOLDER_MOVED; reply.header.page_lsn = 1; - GcsBlockReplyHeaderSetForwardingMasterNode( - &reply.header, GCS_BLOCK_REPLY_NO_FORWARDING_MASTER); + GcsBlockReplyHeaderSetForwardingMasterNode(&reply.header, GCS_BLOCK_REPLY_NO_FORWARDING_MASTER); reply.header.checksum = cluster_gcs_block_compute_checksum(reply.block_data); UT_ASSERT(cluster_gcs_block_test_decode_r4_reply( - &env, &reply, UT_REQUEST_ID, UT_FORMATION_EPOCH, UT_REQUESTER_BACKEND, - PCM_TRANS_N_TO_S, UT_REQUESTER_NODE, GCS_BLOCK_REPLY_NO_FORWARDING_MASTER, - UT_REPLY_DOMAIN_R4_CR)); + &env, &reply, UT_REQUEST_ID, UT_FORMATION_EPOCH, UT_REQUESTER_BACKEND, PCM_TRANS_N_TO_S, + UT_REQUESTER_NODE, GCS_BLOCK_REPLY_NO_FORWARDING_MASTER, UT_REPLY_DOMAIN_R4_CR)); /* Only the D3 master-refusal role may carry WRONG_MASTER in page_lsn. * A holder refusal names the real master in forwarding_master_node and @@ -2863,38 +2710,32 @@ UT_TEST(test_r4_refusal_decoder_requires_exact_domain_identity_and_zero_body) reply.header.sender_node = UT_HOLDER_NODE; GcsBlockReplyHeaderSetForwardingMasterNode(&reply.header, UT_MASTER_NODE); UT_ASSERT(!cluster_gcs_block_test_decode_r4_reply( - &env, &reply, UT_REQUEST_ID, UT_FORMATION_EPOCH, UT_REQUESTER_BACKEND, - PCM_TRANS_N_TO_S, UT_HOLDER_NODE, UT_MASTER_NODE, - UT_REPLY_DOMAIN_R4_CR)); + &env, &reply, UT_REQUEST_ID, UT_FORMATION_EPOCH, UT_REQUESTER_BACKEND, PCM_TRANS_N_TO_S, + UT_HOLDER_NODE, UT_MASTER_NODE, UT_REPLY_DOMAIN_R4_CR)); env.source_node_id = UT_REQUESTER_NODE; reply.header.sender_node = UT_REQUESTER_NODE; - GcsBlockReplyHeaderSetForwardingMasterNode( - &reply.header, GCS_BLOCK_REPLY_NO_FORWARDING_MASTER); + GcsBlockReplyHeaderSetForwardingMasterNode(&reply.header, GCS_BLOCK_REPLY_NO_FORWARDING_MASTER); reply.header.status = GCS_BLOCK_REPLY_DENIED_PENDING_X; UT_ASSERT(!cluster_gcs_block_test_decode_r4_reply( - &env, &reply, UT_REQUEST_ID, UT_FORMATION_EPOCH, UT_REQUESTER_BACKEND, - PCM_TRANS_N_TO_S, UT_REQUESTER_NODE, GCS_BLOCK_REPLY_NO_FORWARDING_MASTER, - UT_REPLY_DOMAIN_R4_CR)); + &env, &reply, UT_REQUEST_ID, UT_FORMATION_EPOCH, UT_REQUESTER_BACKEND, PCM_TRANS_N_TO_S, + UT_REQUESTER_NODE, GCS_BLOCK_REPLY_NO_FORWARDING_MASTER, UT_REPLY_DOMAIN_R4_CR)); reply.header.status = GCS_BLOCK_REPLY_R4_DENIED; reply.header.page_lsn = 1; UT_ASSERT(!cluster_gcs_block_test_decode_r4_reply( - &env, &reply, UT_REQUEST_ID, UT_FORMATION_EPOCH, UT_REQUESTER_BACKEND, - PCM_TRANS_N_TO_S, UT_REQUESTER_NODE, GCS_BLOCK_REPLY_NO_FORWARDING_MASTER, - UT_REPLY_DOMAIN_R4_CR)); + &env, &reply, UT_REQUEST_ID, UT_FORMATION_EPOCH, UT_REQUESTER_BACKEND, PCM_TRANS_N_TO_S, + UT_REQUESTER_NODE, GCS_BLOCK_REPLY_NO_FORWARDING_MASTER, UT_REPLY_DOMAIN_R4_CR)); reply.header.page_lsn = 0; reply.header.reserved_0[0] = 1; UT_ASSERT(!cluster_gcs_block_test_decode_r4_reply( - &env, &reply, UT_REQUEST_ID, UT_FORMATION_EPOCH, UT_REQUESTER_BACKEND, - PCM_TRANS_N_TO_S, UT_REQUESTER_NODE, GCS_BLOCK_REPLY_NO_FORWARDING_MASTER, - UT_REPLY_DOMAIN_R4_CR)); + &env, &reply, UT_REQUEST_ID, UT_FORMATION_EPOCH, UT_REQUESTER_BACKEND, PCM_TRANS_N_TO_S, + UT_REQUESTER_NODE, GCS_BLOCK_REPLY_NO_FORWARDING_MASTER, UT_REPLY_DOMAIN_R4_CR)); reply.header.reserved_0[0] = 0; reply.block_data[0] = 1; reply.header.checksum = cluster_gcs_block_compute_checksum(reply.block_data); UT_ASSERT(!cluster_gcs_block_test_decode_r4_reply( - &env, &reply, UT_REQUEST_ID, UT_FORMATION_EPOCH, UT_REQUESTER_BACKEND, - PCM_TRANS_N_TO_S, UT_REQUESTER_NODE, GCS_BLOCK_REPLY_NO_FORWARDING_MASTER, - UT_REPLY_DOMAIN_R4_CR)); + &env, &reply, UT_REQUEST_ID, UT_FORMATION_EPOCH, UT_REQUESTER_BACKEND, PCM_TRANS_N_TO_S, + UT_REQUESTER_NODE, GCS_BLOCK_REPLY_NO_FORWARDING_MASTER, UT_REPLY_DOMAIN_R4_CR)); } /* Removing the expected R4 domain gate, accepting a status at the other @@ -2930,26 +2771,24 @@ UT_TEST(test_r4_reply_decoder_binds_domain_status_length_and_undo_authority) reply8240.block_data[0] = 0x5a; reply8240.header.checksum = cluster_gcs_block_compute_checksum(reply8240.block_data); env = route_test_envelope(PGRAC_IC_MSG_GCS_BLOCK_REPLY, UT_HOLDER_NODE, cluster_node_id, - sizeof(reply8240)); + sizeof(reply8240)); UT_ASSERT(cluster_gcs_block_test_decode_r4_reply( - &env, &reply8240, UT_REQUEST_ID, UT_FORMATION_EPOCH, UT_REQUESTER_BACKEND, - PCM_TRANS_N_TO_S, UT_HOLDER_NODE, UT_MASTER_NODE, UT_REPLY_DOMAIN_R4_CR)); + &env, &reply8240, UT_REQUEST_ID, UT_FORMATION_EPOCH, UT_REQUESTER_BACKEND, PCM_TRANS_N_TO_S, + UT_HOLDER_NODE, UT_MASTER_NODE, UT_REPLY_DOMAIN_R4_CR)); UT_ASSERT(!cluster_gcs_block_test_decode_r4_reply( - &env, &reply8240, UT_REQUEST_ID, UT_FORMATION_EPOCH, UT_REQUESTER_BACKEND, - PCM_TRANS_N_TO_S, UT_HOLDER_NODE, UT_MASTER_NODE, - UT_REPLY_DOMAIN_LEGACY_ACQUIRE)); + &env, &reply8240, UT_REQUEST_ID, UT_FORMATION_EPOCH, UT_REQUESTER_BACKEND, PCM_TRANS_N_TO_S, + UT_HOLDER_NODE, UT_MASTER_NODE, UT_REPLY_DOMAIN_LEGACY_ACQUIRE)); UT_ASSERT(!cluster_gcs_block_test_decode_r4_reply( - &env, &reply8240, UT_REQUEST_ID, UT_FORMATION_EPOCH, UT_REQUESTER_BACKEND, - PCM_TRANS_N_TO_S, UT_HOLDER_NODE, GCS_BLOCK_REPLY_NO_FORWARDING_MASTER, - UT_REPLY_DOMAIN_R4_CR)); + &env, &reply8240, UT_REQUEST_ID, UT_FORMATION_EPOCH, UT_REQUESTER_BACKEND, PCM_TRANS_N_TO_S, + UT_HOLDER_NODE, GCS_BLOCK_REPLY_NO_FORWARDING_MASTER, UT_REPLY_DOMAIN_R4_CR)); /* The same status must not alias the authenticated 8256-byte undo shape. */ memset(&reply8256, 0, sizeof(reply8256)); reply8256.base = reply8240; env.payload_length = sizeof(reply8256); UT_ASSERT(!cluster_gcs_block_test_decode_r4_reply( - &env, &reply8256, UT_REQUEST_ID, UT_FORMATION_EPOCH, UT_REQUESTER_BACKEND, - PCM_TRANS_N_TO_S, UT_HOLDER_NODE, UT_MASTER_NODE, UT_REPLY_DOMAIN_R4_CR)); + &env, &reply8256, UT_REQUEST_ID, UT_FORMATION_EPOCH, UT_REQUESTER_BACKEND, PCM_TRANS_N_TO_S, + UT_HOLDER_NODE, UT_MASTER_NODE, UT_REPLY_DOMAIN_R4_CR)); /* Status 24 is the endpoint -2 internal result. Its reply supplies the * first nonzero live-HWM/TT-generation/authority-SCN co-sample. */ @@ -2961,17 +2800,15 @@ UT_TEST(test_r4_reply_decoder_binds_domain_status_length_and_undo_authority) reply8256.base.header.transition_id = PCM_TRANS_N_TO_S; reply8256.base.header.status = GCS_BLOCK_REPLY_R4_UNDO_DATA_RESULT; reply8256.base.header.page_lsn = UINT64_C(0x4000); - UT_ASSERT(GcsBlockReplyHeaderSetR4UndoGeneration( - &reply8256.base.header, UINT32_C(0x01020304))); - GcsBlockReplyHeaderSetForwardingMasterNode( - &reply8256.base.header, GCS_BLOCK_REPLY_NO_FORWARDING_MASTER); + UT_ASSERT(GcsBlockReplyHeaderSetR4UndoGeneration(&reply8256.base.header, UINT32_C(0x01020304))); + GcsBlockReplyHeaderSetForwardingMasterNode(&reply8256.base.header, + GCS_BLOCK_REPLY_NO_FORWARDING_MASTER); reply8256.base.block_data[0] = 0xa5; - reply8256.base.header.checksum - = cluster_gcs_block_compute_checksum(reply8256.base.block_data); + reply8256.base.header.checksum = cluster_gcs_block_compute_checksum(reply8256.base.block_data); ClusterGcsUndoAuthTrailerSetTtGeneration(&reply8256.auth, UINT64_C(3)); ClusterGcsUndoAuthTrailerSetAuthorityScn(&reply8256.auth, (uint64)UT_READ_SCN); env = route_test_envelope(PGRAC_IC_MSG_GCS_BLOCK_REPLY, UT_HOLDER_NODE, cluster_node_id, - sizeof(reply8256)); + sizeof(reply8256)); UT_ASSERT(cluster_gcs_block_test_decode_r4_reply( &env, &reply8256, UT_REQUEST_ID, UT_FORMATION_EPOCH, UT_R4_INTERNAL_ENDPOINT, PCM_TRANS_N_TO_S, UT_HOLDER_NODE, GCS_BLOCK_REPLY_NO_FORWARDING_MASTER, @@ -2986,15 +2823,13 @@ UT_TEST(test_r4_reply_decoder_binds_domain_status_length_and_undo_authority) PCM_TRANS_N_TO_S, UT_HOLDER_NODE, GCS_BLOCK_REPLY_NO_FORWARDING_MASTER, UT_REPLY_DOMAIN_R4_CR)); reply8256.base.header.reserved_0[4] = 0; - UT_ASSERT(GcsBlockReplyHeaderSetR4UndoGeneration( - &reply8256.base.header, UINT32_MAX) == false); + UT_ASSERT(GcsBlockReplyHeaderSetR4UndoGeneration(&reply8256.base.header, UINT32_MAX) == false); memset(reply8256.base.header.reserved_0, 0xff, 4); UT_ASSERT(!cluster_gcs_block_test_decode_r4_reply( &env, &reply8256, UT_REQUEST_ID, UT_FORMATION_EPOCH, UT_R4_INTERNAL_ENDPOINT, PCM_TRANS_N_TO_S, UT_HOLDER_NODE, GCS_BLOCK_REPLY_NO_FORWARDING_MASTER, UT_REPLY_DOMAIN_R4_CR)); - UT_ASSERT(GcsBlockReplyHeaderSetR4UndoGeneration( - &reply8256.base.header, UINT32_C(0x01020304))); + UT_ASSERT(GcsBlockReplyHeaderSetR4UndoGeneration(&reply8256.base.header, UINT32_C(0x01020304))); /* A short frame is not status 24. Initial rollover generation zero is * valid when the complete authenticated authority trailer is present. */ @@ -3023,21 +2858,19 @@ UT_TEST(test_r4_reply_decoder_binds_domain_status_length_and_undo_authority) reply8240.header.sender_node = UT_MASTER_NODE; reply8240.header.requester_backend_id = UT_REQUESTER_BACKEND; reply8240.header.transition_id = PCM_TRANS_N_TO_S; - GcsBlockReplyHeaderSetForwardingMasterNode( - &reply8240.header, GCS_BLOCK_REPLY_NO_FORWARDING_MASTER); + GcsBlockReplyHeaderSetForwardingMasterNode(&reply8240.header, + GCS_BLOCK_REPLY_NO_FORWARDING_MASTER); reply8240.header.checksum = cluster_gcs_block_compute_checksum(reply8240.block_data); env = route_test_envelope(PGRAC_IC_MSG_GCS_BLOCK_REPLY, UT_MASTER_NODE, cluster_node_id, - sizeof(reply8240)); + sizeof(reply8240)); reply8240.header.status = GCS_BLOCK_REPLY_R4_RETRYABLE_HOLDER_MOVED; UT_ASSERT(cluster_gcs_block_test_decode_r4_reply( - &env, &reply8240, UT_REQUEST_ID, UT_FORMATION_EPOCH, UT_REQUESTER_BACKEND, - PCM_TRANS_N_TO_S, UT_MASTER_NODE, GCS_BLOCK_REPLY_NO_FORWARDING_MASTER, - UT_REPLY_DOMAIN_R4_CR)); + &env, &reply8240, UT_REQUEST_ID, UT_FORMATION_EPOCH, UT_REQUESTER_BACKEND, PCM_TRANS_N_TO_S, + UT_MASTER_NODE, GCS_BLOCK_REPLY_NO_FORWARDING_MASTER, UT_REPLY_DOMAIN_R4_CR)); reply8240.header.status = GCS_BLOCK_REPLY_R4_DENIED; UT_ASSERT(cluster_gcs_block_test_decode_r4_reply( - &env, &reply8240, UT_REQUEST_ID, UT_FORMATION_EPOCH, UT_REQUESTER_BACKEND, - PCM_TRANS_N_TO_S, UT_MASTER_NODE, GCS_BLOCK_REPLY_NO_FORWARDING_MASTER, - UT_REPLY_DOMAIN_R4_CR)); + &env, &reply8240, UT_REQUEST_ID, UT_FORMATION_EPOCH, UT_REQUESTER_BACKEND, PCM_TRANS_N_TO_S, + UT_MASTER_NODE, GCS_BLOCK_REPLY_NO_FORWARDING_MASTER, UT_REPLY_DOMAIN_R4_CR)); } /* Removing the status-24 internal landing call, or deriving a backend index @@ -3061,16 +2894,14 @@ UT_TEST(test_r4_status24_routes_only_to_internal_foreign_undo_landing) reply.header.requester_backend_id = UT_R4_INTERNAL_ENDPOINT; reply.header.transition_id = PCM_TRANS_N_TO_S; reply.header.status = GCS_BLOCK_REPLY_R4_UNDO_DATA_RESULT; - GcsBlockReplyHeaderSetForwardingMasterNode( - &reply.header, GCS_BLOCK_REPLY_NO_FORWARDING_MASTER); - UT_ASSERT(GcsBlockReplyHeaderSetR4UndoGeneration( - &reply.header, UINT32_C(0x01020304))); + GcsBlockReplyHeaderSetForwardingMasterNode(&reply.header, GCS_BLOCK_REPLY_NO_FORWARDING_MASTER); + UT_ASSERT(GcsBlockReplyHeaderSetR4UndoGeneration(&reply.header, UINT32_C(0x01020304))); memset(reply.block_data, 0xa5, sizeof(reply.block_data)); reply.header.checksum = cluster_gcs_block_compute_checksum(reply.block_data); ClusterGcsUndoAuthTrailerSetTtGeneration(&reply.auth, UINT64_C(3)); ClusterGcsUndoAuthTrailerSetAuthorityScn(&reply.auth, (uint64)UT_READ_SCN); - env = route_test_envelope(PGRAC_IC_MSG_GCS_BLOCK_REPLY, UT_HOLDER_NODE, - cluster_node_id, sizeof(reply)); + env = route_test_envelope(PGRAC_IC_MSG_GCS_BLOCK_REPLY, UT_HOLDER_NODE, cluster_node_id, + sizeof(reply)); route_seam_reset(); reply_lock_acquire_calls = 0; @@ -3078,12 +2909,10 @@ UT_TEST(test_r4_status24_routes_only_to_internal_foreign_undo_landing) UT_ASSERT_EQ(route_seam.foreign_undo_land_calls, 1); UT_ASSERT_EQ(reply_lock_acquire_calls, 0); UT_ASSERT_EQ(memcmp(&route_seam.foreign_undo_env, &env, sizeof(env)), 0); - UT_ASSERT_EQ(memcmp(&route_seam.foreign_undo_header, &reply.header, - sizeof(reply.header)), 0); - UT_ASSERT_EQ(memcmp(route_seam.foreign_undo_page, reply.block_data, - sizeof(reply.block_data)), 0); - UT_ASSERT_EQ(memcmp(&route_seam.foreign_undo_auth, &reply.auth, - sizeof(reply.auth)), 0); + UT_ASSERT_EQ(memcmp(&route_seam.foreign_undo_header, &reply.header, sizeof(reply.header)), 0); + UT_ASSERT_EQ(memcmp(route_seam.foreign_undo_page, reply.block_data, sizeof(reply.block_data)), + 0); + UT_ASSERT_EQ(memcmp(&route_seam.foreign_undo_auth, &reply.auth, sizeof(reply.auth)), 0); route_seam_reset(); reply.header.requester_backend_id = UT_REQUESTER_BACKEND; @@ -3118,8 +2947,8 @@ UT_TEST(test_r4_reply_decoder_checks_minimum_length_before_header_read) UT_ASSERT(page_size > 0); if (page_size <= 0) return; - mapping = mmap(NULL, (size_t)page_size * 2, PROT_READ | PROT_WRITE, - MAP_PRIVATE | MAP_ANON, -1, 0); + mapping + = mmap(NULL, (size_t)page_size * 2, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0); UT_ASSERT(mapping != MAP_FAILED); if (mapping == MAP_FAILED) return; @@ -3132,8 +2961,7 @@ UT_TEST(test_r4_reply_decoder_checks_minimum_length_before_header_read) truncated_payload = mapping + page_size - 1; mapping[page_size - 1] = 0; - env = route_test_envelope(PGRAC_IC_MSG_GCS_BLOCK_REPLY, UT_MASTER_NODE, - cluster_node_id, 1); + env = route_test_envelope(PGRAC_IC_MSG_GCS_BLOCK_REPLY, UT_MASTER_NODE, cluster_node_id, 1); UT_ASSERT(!cluster_gcs_block_test_decode_r4_reply( &env, truncated_payload, UT_REQUEST_ID, UT_FORMATION_EPOCH, UT_REQUESTER_BACKEND, PCM_TRANS_N_TO_S, UT_MASTER_NODE, GCS_BLOCK_REPLY_NO_FORWARDING_MASTER, @@ -3174,17 +3002,17 @@ UT_TEST(test_r4_full_reply_lands_once_in_armed_r4_slot) GcsBlockReplyHeaderSetForwardingMasterNode(&first.header, UT_MASTER_NODE); memset(first.block_data, 0x5a, sizeof(first.block_data)); first.header.checksum = cluster_gcs_block_compute_checksum(first.block_data); - env = route_test_envelope(PGRAC_IC_MSG_GCS_BLOCK_REPLY, UT_HOLDER_NODE, - cluster_node_id, sizeof(first)); + env = route_test_envelope(PGRAC_IC_MSG_GCS_BLOCK_REPLY, UT_HOLDER_NODE, cluster_node_id, + sizeof(first)); reply_lock_acquire_calls = 0; reply_lock_release_calls = 0; reply_cv_signal_calls = 0; - UT_ASSERT(cluster_gcs_block_test_arm_r4_reply_slot( - UT_REQUEST_ID, UT_FORMATION_EPOCH, 1, PCM_TRANS_N_TO_S, UT_MASTER_NODE)); + UT_ASSERT(cluster_gcs_block_test_arm_r4_reply_slot(UT_REQUEST_ID, UT_FORMATION_EPOCH, 1, + PCM_TRANS_N_TO_S, UT_MASTER_NODE)); cluster_gcs_handle_block_reply_envelope(&env, &first); - UT_ASSERT(cluster_gcs_block_test_snapshot_r4_reply_slot( - &landed_header, landed_block, &reply_received, &stale_drop_count)); + UT_ASSERT(cluster_gcs_block_test_snapshot_r4_reply_slot(&landed_header, landed_block, + &reply_received, &stale_drop_count)); UT_ASSERT(reply_received); UT_ASSERT_EQ(memcmp(&landed_header, &first.header, sizeof(first.header)), 0); UT_ASSERT_EQ(memcmp(landed_block, first.block_data, sizeof(landed_block)), 0); @@ -3196,11 +3024,10 @@ UT_TEST(test_r4_full_reply_lands_once_in_armed_r4_slot) duplicate = first; duplicate.header.page_lsn++; memset(duplicate.block_data, 0xa5, sizeof(duplicate.block_data)); - duplicate.header.checksum - = cluster_gcs_block_compute_checksum(duplicate.block_data); + duplicate.header.checksum = cluster_gcs_block_compute_checksum(duplicate.block_data); cluster_gcs_handle_block_reply_envelope(&env, &duplicate); - UT_ASSERT(cluster_gcs_block_test_snapshot_r4_reply_slot( - &landed_header, landed_block, &reply_received, &stale_drop_count)); + UT_ASSERT(cluster_gcs_block_test_snapshot_r4_reply_slot(&landed_header, landed_block, + &reply_received, &stale_drop_count)); UT_ASSERT(reply_received); UT_ASSERT_EQ(memcmp(&landed_header, &first.header, sizeof(first.header)), 0); UT_ASSERT_EQ(memcmp(landed_block, first.block_data, sizeof(landed_block)), 0); @@ -3237,18 +3064,17 @@ UT_TEST(test_forwarded_holder_pending_x_lands_in_legacy_slot) reply.header.status = GCS_BLOCK_REPLY_DENIED_PENDING_X; GcsBlockReplyHeaderSetForwardingMasterNode(&reply.header, UT_MASTER_NODE); reply.header.checksum = cluster_gcs_block_compute_checksum(reply.block_data); - env = route_test_envelope(PGRAC_IC_MSG_GCS_BLOCK_REPLY, UT_HOLDER_NODE, - cluster_node_id, sizeof(reply)); + env = route_test_envelope(PGRAC_IC_MSG_GCS_BLOCK_REPLY, UT_HOLDER_NODE, cluster_node_id, + sizeof(reply)); reply_lock_acquire_calls = 0; reply_lock_release_calls = 0; reply_cv_signal_calls = 0; - UT_ASSERT(cluster_gcs_block_test_arm_legacy_reply_slot( - UT_REQUEST_ID, UT_FORMATION_EPOCH, 1, PCM_TRANS_N_TO_S, - UT_MASTER_NODE)); + UT_ASSERT(cluster_gcs_block_test_arm_legacy_reply_slot(UT_REQUEST_ID, UT_FORMATION_EPOCH, 1, + PCM_TRANS_N_TO_S, UT_MASTER_NODE)); cluster_gcs_handle_block_reply_envelope(&env, &reply); - UT_ASSERT(cluster_gcs_block_test_snapshot_r4_reply_slot( - &landed_header, landed_block, &reply_received, &stale_drop_count)); + UT_ASSERT(cluster_gcs_block_test_snapshot_r4_reply_slot(&landed_header, landed_block, + &reply_received, &stale_drop_count)); UT_ASSERT(reply_received); UT_ASSERT_EQ(memcmp(&landed_header, &reply.header, sizeof(reply.header)), 0); UT_ASSERT_EQ(reply_lock_acquire_calls, 1); @@ -3274,13 +3100,13 @@ UT_TEST(test_r4_requester_arm_selects_closed_domain_and_releases_cleanly) bool in_use = false; bool direct_target_prepared = true; - UT_ASSERT(cluster_gcs_block_test_r4_requester_arm( - tag, UT_FORMATION_EPOCH, UT_MASTER_NODE, UINT64_C(1), &request_id)); + UT_ASSERT(cluster_gcs_block_test_r4_requester_arm(tag, UT_FORMATION_EPOCH, UT_MASTER_NODE, + UINT64_C(1), &request_id)); UT_ASSERT_EQ(request_id, gcs_reqid_requester(cluster_node_id, (int)MyBackendId - 1, UINT64_C(1))); UT_ASSERT(cluster_gcs_block_test_snapshot_r4_requester_slot( - &in_use, &reply_domain, &armed_request_id, &transition_id, &armed_tag, - &armed_epoch, &armed_master, &direct_state, &direct_target_prepared)); + &in_use, &reply_domain, &armed_request_id, &transition_id, &armed_tag, &armed_epoch, + &armed_master, &direct_state, &direct_target_prepared)); UT_ASSERT(in_use); UT_ASSERT_EQ(reply_domain, UT_REPLY_DOMAIN_R4_CR); UT_ASSERT_EQ(armed_request_id, request_id); @@ -3293,8 +3119,8 @@ UT_TEST(test_r4_requester_arm_selects_closed_domain_and_releases_cleanly) UT_ASSERT(cluster_gcs_block_test_release_r4_requester_slot()); UT_ASSERT(cluster_gcs_block_test_snapshot_r4_requester_slot( - &in_use, &reply_domain, &armed_request_id, &transition_id, &armed_tag, - &armed_epoch, &armed_master, &direct_state, &direct_target_prepared)); + &in_use, &reply_domain, &armed_request_id, &transition_id, &armed_tag, &armed_epoch, + &armed_master, &direct_state, &direct_target_prepared)); UT_ASSERT(!in_use); UT_ASSERT_EQ(reply_domain, UT_REPLY_DOMAIN_LEGACY_ACQUIRE); UT_ASSERT_EQ(armed_request_id, 0); @@ -3319,8 +3145,7 @@ UT_TEST(test_current_mx_describe_requester_is_capability_bound_and_times_out_cle int32 released_master = INT32_MIN; uint8 released_domain = UINT8_MAX; uint8 released_transition = UINT8_MAX; - ClusterGcsBlockDirectState released_direct_state - = GCS_BLOCK_DIRECT_ABORTED; + ClusterGcsBlockDirectState released_direct_state = GCS_BLOCK_DIRECT_ABORTED; bool released_in_use = true; bool released_direct_target_prepared = true; int saved_node_id = cluster_node_id; @@ -3336,48 +3161,42 @@ UT_TEST(test_current_mx_describe_requester_is_capability_bound_and_times_out_cle route_seam_reset(); route_seam.current_mx_capability_ok = false; memset(members, 0xa5, sizeof(members)); - UT_ASSERT_EQ(cluster_gcs_current_mx_describe_fetch_and_wait( - UT_MASTER_NODE, &key, members, lengthof(members), - &members_count, &reported_total), - CMX_DESC_UNKNOWN); + UT_ASSERT_EQ(cluster_gcs_current_mx_describe_fetch_and_wait(UT_MASTER_NODE, &key, members, + lengthof(members), &members_count, + &reported_total), + CMX_DESC_UNKNOWN); UT_ASSERT_EQ(route_seam.current_mx_capability_calls, 1); UT_ASSERT_EQ(route_seam.current_mx_capability_peer, UT_MASTER_NODE); UT_ASSERT_EQ(route_seam.enqueue_calls, 0); UT_ASSERT_EQ(members_count, 0); UT_ASSERT_EQ(reported_total, (uint32)0); - UT_ASSERT_EQ(memcmp(members, - (ClusterCurrentMxMemberDesc[lengthof(members)]){{0}}, - sizeof(members)), - 0); + UT_ASSERT_EQ( + memcmp(members, (ClusterCurrentMxMemberDesc[lengthof(members)]){ { 0 } }, sizeof(members)), + 0); /* Seed the single-backend product fixture, then let the real Current-MX * requester own and release the same slot. */ - UT_ASSERT(cluster_gcs_block_test_r4_requester_arm( - reset_tag, UT_FORMATION_EPOCH, UT_MASTER_NODE, UINT64_C(1), - &reset_request_id)); + UT_ASSERT(cluster_gcs_block_test_r4_requester_arm(reset_tag, UT_FORMATION_EPOCH, UT_MASTER_NODE, + UINT64_C(1), &reset_request_id)); UT_ASSERT(cluster_gcs_block_test_release_r4_requester_slot()); route_seam_reset(); members_count = UINT16_MAX; reported_total = UINT32_MAX; memset(members, 0xa5, sizeof(members)); - UT_ASSERT_EQ(cluster_gcs_current_mx_describe_fetch_and_wait( - UT_MASTER_NODE, &key, members, lengthof(members), - &members_count, &reported_total), - CMX_DESC_TIMEOUT); + UT_ASSERT_EQ(cluster_gcs_current_mx_describe_fetch_and_wait(UT_MASTER_NODE, &key, members, + lengthof(members), &members_count, + &reported_total), + CMX_DESC_TIMEOUT); UT_ASSERT_EQ(route_seam.current_mx_capability_calls, 1); UT_ASSERT_EQ(route_seam.current_mx_capability_peer, UT_MASTER_NODE); UT_ASSERT_EQ(route_seam.enqueue_calls, 1); UT_ASSERT_EQ(route_seam.enqueue_msg_type, PGRAC_IC_MSG_GCS_BLOCK_FORWARD); UT_ASSERT_EQ(route_seam.enqueue_dest, (uint32)UT_MASTER_NODE); - UT_ASSERT_EQ(route_seam.enqueue_payload_len, - sizeof(ClusterCurrentMxDescribeForwardV2)); - UT_ASSERT_EQ(route_seam.enqueue_required_capability, - PGRAC_IC_HELLO_CAP_MULTIXACT_CURRENT_V1); - UT_ASSERT_EQ(route_seam.enqueue_connection_generation, - UT_CURRENT_MX_CAPABILITY_GENERATION); + UT_ASSERT_EQ(route_seam.enqueue_payload_len, sizeof(ClusterCurrentMxDescribeForwardV2)); + UT_ASSERT_EQ(route_seam.enqueue_required_capability, PGRAC_IC_HELLO_CAP_MULTIXACT_CURRENT_V1); + UT_ASSERT_EQ(route_seam.enqueue_connection_generation, UT_CURRENT_MX_CAPABILITY_GENERATION); UT_ASSERT(route_seam.current_mx_slot_armed); - UT_ASSERT_EQ(route_seam.current_mx_slot_domain, - UT_REPLY_DOMAIN_CURRENT_MX); + UT_ASSERT_EQ(route_seam.current_mx_slot_domain, UT_REPLY_DOMAIN_CURRENT_MX); request = (const ClusterCurrentMxDescribeForwardV2 *)route_seam.enqueue_payload; UT_ASSERT_EQ(request->prefix.epoch, UT_FORMATION_EPOCH); @@ -3385,8 +3204,7 @@ UT_TEST(test_current_mx_describe_requester_is_capability_bound_and_times_out_cle UT_ASSERT_EQ(request->prefix.mxkey.multixact_id, (MultiXactId)42); UT_ASSERT_EQ(request->prefix.original_requester_node, UT_REQUESTER_NODE); UT_ASSERT_EQ(request->prefix.requester_backend_id, (int32)MyBackendId); - UT_ASSERT_EQ(request->prefix.kind, - GCS_BLOCK_FORWARD_KIND_CURRENT_MX_DESCRIBE); + UT_ASSERT_EQ(request->prefix.kind, GCS_BLOCK_FORWARD_KIND_CURRENT_MX_DESCRIBE); UT_ASSERT_EQ(request->trailer.magic, CLUSTER_CURRENT_MX_WIRE_MAGIC); UT_ASSERT_EQ(request->trailer.version, CLUSTER_CURRENT_MX_WIRE_VERSION); UT_ASSERT_EQ(request->trailer.flags, CLUSTER_CURRENT_MX_WIRE_FLAGS_NONE); @@ -3394,9 +3212,8 @@ UT_TEST(test_current_mx_describe_requester_is_capability_bound_and_times_out_cle UT_ASSERT_EQ(reported_total, (uint32)0); UT_ASSERT(cluster_gcs_block_test_snapshot_r4_requester_slot( - &released_in_use, &released_domain, &released_request_id, - &released_transition, &released_tag, &released_epoch, - &released_master, &released_direct_state, + &released_in_use, &released_domain, &released_request_id, &released_transition, + &released_tag, &released_epoch, &released_master, &released_direct_state, &released_direct_target_prepared)); UT_ASSERT(!released_in_use); UT_ASSERT_EQ(released_domain, UT_REPLY_DOMAIN_LEGACY_ACQUIRE); @@ -3427,9 +3244,8 @@ UT_TEST(test_current_mx_describe_reply_lands_in_current_domain) key.cluster_epoch = (uint32)UT_FORMATION_EPOCH; cluster_node_id = UT_REQUESTER_NODE; cluster_gcs_reply_timeout_ms = 1; - UT_ASSERT(cluster_gcs_block_test_r4_requester_arm( - reset_tag, UT_FORMATION_EPOCH, UT_MASTER_NODE, UINT64_C(1), - &reset_request_id)); + UT_ASSERT(cluster_gcs_block_test_r4_requester_arm(reset_tag, UT_FORMATION_EPOCH, UT_MASTER_NODE, + UINT64_C(1), &reset_request_id)); UT_ASSERT(cluster_gcs_block_test_release_r4_requester_slot()); route_seam_reset(); route_seam.current_mx_reply_enabled = true; @@ -3438,14 +3254,13 @@ UT_TEST(test_current_mx_describe_reply_lands_in_current_domain) reply_cv_signal_calls = 0; reply_cv_timed_sleep_calls = 0; - UT_ASSERT_EQ(cluster_gcs_current_mx_describe_fetch_and_wait( - UT_MASTER_NODE, &key, members, lengthof(members), - &members_count, &reported_total), - CMX_DESC_DENIED); + UT_ASSERT_EQ(cluster_gcs_current_mx_describe_fetch_and_wait(UT_MASTER_NODE, &key, members, + lengthof(members), &members_count, + &reported_total), + CMX_DESC_DENIED); UT_ASSERT_EQ(route_seam.enqueue_calls, 1); UT_ASSERT(route_seam.current_mx_slot_armed); - UT_ASSERT_EQ(route_seam.current_mx_slot_domain, - UT_REPLY_DOMAIN_CURRENT_MX); + UT_ASSERT_EQ(route_seam.current_mx_slot_domain, UT_REPLY_DOMAIN_CURRENT_MX); UT_ASSERT_EQ(route_seam.current_mx_validate_calls, 2); UT_ASSERT_EQ(reply_cv_signal_calls, 1); UT_ASSERT_EQ(reply_cv_timed_sleep_calls, 0); @@ -3476,18 +3291,14 @@ UT_TEST(test_current_mx_describe_forward128_routes_to_origin_serve) request.trailer.magic = CLUSTER_CURRENT_MX_WIRE_MAGIC; request.trailer.version = CLUSTER_CURRENT_MX_WIRE_VERSION; request.trailer.flags = CLUSTER_CURRENT_MX_WIRE_FLAGS_NONE; - env = route_test_envelope( - PGRAC_IC_MSG_GCS_BLOCK_FORWARD, UT_REQUESTER_NODE, - UT_MASTER_NODE, sizeof(request)); + env = route_test_envelope(PGRAC_IC_MSG_GCS_BLOCK_FORWARD, UT_REQUESTER_NODE, UT_MASTER_NODE, + sizeof(request)); UT_ASSERT(cluster_gcs_block_test_current_mx_forward128(&env, &request)); UT_ASSERT_EQ(route_seam.current_mx_describe_serve_calls, 1); - UT_ASSERT_EQ(route_seam.current_mx_describe_env.source_node_id, - (uint32)UT_REQUESTER_NODE); - UT_ASSERT_EQ(route_seam.current_mx_describe_env.dest_node_id, - (uint32)UT_MASTER_NODE); - UT_ASSERT_EQ(route_seam.current_mx_describe_request.prefix.request_id, - UT_REQUEST_ID); + UT_ASSERT_EQ(route_seam.current_mx_describe_env.source_node_id, (uint32)UT_REQUESTER_NODE); + UT_ASSERT_EQ(route_seam.current_mx_describe_env.dest_node_id, (uint32)UT_MASTER_NODE); + UT_ASSERT_EQ(route_seam.current_mx_describe_request.prefix.request_id, UT_REQUEST_ID); UT_ASSERT_EQ(route_seam.current_mx_describe_request.prefix.kind, GCS_BLOCK_FORWARD_KIND_CURRENT_MX_DESCRIBE); @@ -3518,8 +3329,7 @@ UT_TEST(test_current_mx_member_proof_requester_is_capability_bound_and_times_out request.prefix.original_requester_node = UT_REQUESTER_NODE; request.prefix.requester_backend_id = (int32)MyBackendId; request.prefix.total_count = 2; - ClusterCurrentMxProofPrefixSetDescriptorHash( - &request.prefix, UINT64_C(0x12345678)); + ClusterCurrentMxProofPrefixSetDescriptorHash(&request.prefix, UINT64_C(0x12345678)); request.prefix.entry_count = 1; request.prefix.body_kind = CLUSTER_CURRENT_MX_PROOF_BODY_MEMBER_ASKS; request.prefix.kind = GCS_BLOCK_FORWARD_KIND_CURRENT_MX_MEMBER_PROOF; @@ -3528,44 +3338,33 @@ UT_TEST(test_current_mx_member_proof_requester_is_capability_bound_and_times_out request.trailer.body.asks[0].xid = (TransactionId)501; request.trailer.body.asks[0].member_ordinal = 0; request.trailer.body.asks[0].member_status = MultiXactStatusForShare; - UT_ASSERT(cluster_gcs_block_test_r4_requester_arm( - reset_tag, UT_FORMATION_EPOCH, 4, UINT64_C(1), - &reset_request_id)); + UT_ASSERT(cluster_gcs_block_test_r4_requester_arm(reset_tag, UT_FORMATION_EPOCH, 4, UINT64_C(1), + &reset_request_id)); UT_ASSERT(cluster_gcs_block_test_release_r4_requester_slot()); route_seam_reset(); memset(proofs, 0xa5, sizeof(proofs)); memset(&updater, 0xa5, sizeof(updater)); UT_ASSERT_EQ(cluster_gcs_current_mx_member_proof_fetch_and_wait( - 4, &request, proofs, lengthof(proofs), - &proof_count, &updater, + 4, &request, proofs, lengthof(proofs), &proof_count, &updater, &requester_capability_generation, - GetCurrentTimestamp() - + (TimestampTz)cluster_gcs_reply_timeout_ms * 10000), + GetCurrentTimestamp() + (TimestampTz)cluster_gcs_reply_timeout_ms * 10000), CMX_RESOLVE_TIMEOUT); UT_ASSERT_EQ(requester_capability_generation, (uint32)0); UT_ASSERT_EQ(route_seam.current_mx_capability_calls, 1); UT_ASSERT_EQ(route_seam.current_mx_capability_peer, 4); UT_ASSERT_EQ(route_seam.enqueue_calls, 1); - UT_ASSERT_EQ(route_seam.enqueue_msg_type, - PGRAC_IC_MSG_GCS_BLOCK_FORWARD); + UT_ASSERT_EQ(route_seam.enqueue_msg_type, PGRAC_IC_MSG_GCS_BLOCK_FORWARD); UT_ASSERT_EQ(route_seam.enqueue_dest, (uint32)4); - UT_ASSERT_EQ(route_seam.enqueue_payload_len, - sizeof(ClusterCurrentMxProofForwardV2)); - UT_ASSERT_EQ(route_seam.enqueue_required_capability, - PGRAC_IC_HELLO_CAP_MULTIXACT_CURRENT_V1); - UT_ASSERT_EQ(route_seam.enqueue_connection_generation, - UT_CURRENT_MX_CAPABILITY_GENERATION); + UT_ASSERT_EQ(route_seam.enqueue_payload_len, sizeof(ClusterCurrentMxProofForwardV2)); + UT_ASSERT_EQ(route_seam.enqueue_required_capability, PGRAC_IC_HELLO_CAP_MULTIXACT_CURRENT_V1); + UT_ASSERT_EQ(route_seam.enqueue_connection_generation, UT_CURRENT_MX_CAPABILITY_GENERATION); UT_ASSERT(route_seam.current_mx_slot_armed); - UT_ASSERT_EQ(route_seam.current_mx_slot_domain, - UT_REPLY_DOMAIN_CURRENT_MX); - sent_request - = (const ClusterCurrentMxProofForwardV2 *)route_seam.enqueue_payload; - UT_ASSERT_EQ(sent_request->prefix.kind, - GCS_BLOCK_FORWARD_KIND_CURRENT_MX_MEMBER_PROOF); + UT_ASSERT_EQ(route_seam.current_mx_slot_domain, UT_REPLY_DOMAIN_CURRENT_MX); + sent_request = (const ClusterCurrentMxProofForwardV2 *)route_seam.enqueue_payload; + UT_ASSERT_EQ(sent_request->prefix.kind, GCS_BLOCK_FORWARD_KIND_CURRENT_MX_MEMBER_PROOF); UT_ASSERT_EQ(sent_request->prefix.epoch, UT_FORMATION_EPOCH); - UT_ASSERT_EQ(sent_request->prefix.original_requester_node, - UT_REQUESTER_NODE); + UT_ASSERT_EQ(sent_request->prefix.original_requester_node, UT_REQUESTER_NODE); UT_ASSERT_EQ(proof_count, (uint16)0); UT_ASSERT_EQ(proofs[0].state, CCM_UNKNOWN); UT_ASSERT_EQ(updater.verdict, CUCP_UNKNOWN); @@ -3598,9 +3397,8 @@ UT_TEST(test_current_mx_member_proof_forward128_routes_to_cooperative_origin) request.trailer.version = CLUSTER_CURRENT_MX_WIRE_VERSION; request.trailer.body.asks[0].xid = (TransactionId)503; request.trailer.body.asks[0].member_status = MultiXactStatusForShare; - env = route_test_envelope( - PGRAC_IC_MSG_GCS_BLOCK_FORWARD, UT_REQUESTER_NODE, - UT_MASTER_NODE, sizeof(request)); + env = route_test_envelope(PGRAC_IC_MSG_GCS_BLOCK_FORWARD, UT_REQUESTER_NODE, UT_MASTER_NODE, + sizeof(request)); UT_ASSERT(cluster_gcs_block_test_current_mx_forward128(&env, &request)); UT_ASSERT_EQ(route_seam.current_mx_proof_serve_calls, 0); @@ -3648,8 +3446,7 @@ UT_TEST(test_current_mx_member_proof_reply_lands_in_current_domain) request.prefix.original_requester_node = UT_REQUESTER_NODE; request.prefix.requester_backend_id = (int32)MyBackendId; request.prefix.total_count = 2; - ClusterCurrentMxProofPrefixSetDescriptorHash( - &request.prefix, UINT64_C(0x12345678)); + ClusterCurrentMxProofPrefixSetDescriptorHash(&request.prefix, UINT64_C(0x12345678)); request.prefix.entry_count = 1; request.prefix.body_kind = CLUSTER_CURRENT_MX_PROOF_BODY_MEMBER_ASKS; request.prefix.kind = GCS_BLOCK_FORWARD_KIND_CURRENT_MX_MEMBER_PROOF; @@ -3658,9 +3455,8 @@ UT_TEST(test_current_mx_member_proof_reply_lands_in_current_domain) request.trailer.body.asks[0].xid = (TransactionId)502; request.trailer.body.asks[0].member_ordinal = 0; request.trailer.body.asks[0].member_status = MultiXactStatusForShare; - UT_ASSERT(cluster_gcs_block_test_r4_requester_arm( - reset_tag, UT_FORMATION_EPOCH, 4, UINT64_C(1), - &reset_request_id)); + UT_ASSERT(cluster_gcs_block_test_r4_requester_arm(reset_tag, UT_FORMATION_EPOCH, 4, UINT64_C(1), + &reset_request_id)); UT_ASSERT(cluster_gcs_block_test_release_r4_requester_slot()); route_seam_reset(); route_seam.current_mx_proof_reply_enabled = true; @@ -3671,17 +3467,14 @@ UT_TEST(test_current_mx_member_proof_reply_lands_in_current_domain) reply_cv_timed_sleep_calls = 0; UT_ASSERT_EQ(cluster_gcs_current_mx_member_proof_fetch_and_wait( - 4, &request, proofs, lengthof(proofs), - &proof_count, &updater, + 4, &request, proofs, lengthof(proofs), &proof_count, &updater, &requester_capability_generation, - GetCurrentTimestamp() - + (TimestampTz)cluster_gcs_reply_timeout_ms * 10000), + GetCurrentTimestamp() + (TimestampTz)cluster_gcs_reply_timeout_ms * 10000), CMX_RESOLVE_DENIED); UT_ASSERT_EQ(requester_capability_generation, (uint32)0); UT_ASSERT_EQ(route_seam.enqueue_calls, 1); UT_ASSERT(route_seam.current_mx_slot_armed); - UT_ASSERT_EQ(route_seam.current_mx_slot_domain, - UT_REPLY_DOMAIN_CURRENT_MX); + UT_ASSERT_EQ(route_seam.current_mx_slot_domain, UT_REPLY_DOMAIN_CURRENT_MX); UT_ASSERT_EQ(route_seam.current_mx_proof_validate_calls, 2); UT_ASSERT_EQ(reply_cv_signal_calls, 1); UT_ASSERT_EQ(reply_cv_timed_sleep_calls, 0); @@ -3700,8 +3493,8 @@ UT_TEST(test_r4_requester_count_tracks_only_live_r4_domain_slots) int saved_max_backends = MaxBackends; MaxBackends = 1; - UT_ASSERT(cluster_gcs_block_test_r4_requester_arm( - tag, UT_FORMATION_EPOCH, UT_MASTER_NODE, UINT64_C(1), &request_id)); + UT_ASSERT(cluster_gcs_block_test_r4_requester_arm(tag, UT_FORMATION_EPOCH, UT_MASTER_NODE, + UINT64_C(1), &request_id)); UT_ASSERT_EQ(cluster_gcs_block_r4_requester_count(), UINT64_C(1)); UT_ASSERT(cluster_gcs_block_test_release_r4_requester_slot()); UT_ASSERT_EQ(cluster_gcs_block_r4_requester_count(), UINT64_C(0)); @@ -3734,8 +3527,7 @@ UT_TEST(test_r4_remote_requester_arms_request80_waits_full_and_releases) reply_cv_timed_sleep_calls = 0; reply_cv_cancel_calls = 0; reply_cv_signal_calls = 0; - UT_ASSERT(cluster_gcs_block_test_r4_fetch_and_wait( - tag, UT_READ_SCN, UT_MASTER_NODE, dst_page)); + UT_ASSERT(cluster_gcs_block_test_r4_fetch_and_wait(tag, UT_READ_SCN, UT_MASTER_NODE, dst_page)); UT_ASSERT_EQ(requester_send.calls, 1); UT_ASSERT_EQ(requester_send.msg_type, PGRAC_IC_MSG_GCS_BLOCK_REQUEST); UT_ASSERT_EQ(requester_send.dest_node, UT_MASTER_NODE); @@ -3752,8 +3544,7 @@ UT_TEST(test_r4_remote_requester_arms_request80_waits_full_and_releases) UT_ASSERT_EQ(requester_send.request.base.transition_id, PCM_TRANS_N_TO_S); UT_ASSERT(!GcsBlockRequestPayloadIsCleanEligible(&requester_send.request.base)); UT_ASSERT(!GcsBlockRequestPayloadIsDirectLandArmed(&requester_send.request.base)); - UT_ASSERT(ClusterR4RequestExtensionGetCr( - &requester_send.request.extension, &decoded_read_scn)); + UT_ASSERT(ClusterR4RequestExtensionGetCr(&requester_send.request.extension, &decoded_read_scn)); UT_ASSERT_EQ(decoded_read_scn, UT_READ_SCN); UT_ASSERT_EQ(memcmp(dst_page, requester_send.reply_page, sizeof(dst_page)), 0); UT_ASSERT_EQ(reply_cv_prepare_calls, 1); @@ -3762,8 +3553,8 @@ UT_TEST(test_r4_remote_requester_arms_request80_waits_full_and_releases) UT_ASSERT_EQ(reply_cv_signal_calls, 1); UT_ASSERT(cluster_gcs_block_test_snapshot_r4_requester_slot( - &in_use, &reply_domain, &request_id, &transition_id, &released_tag, - &request_epoch, &expected_master, &direct_state, &direct_target_prepared)); + &in_use, &reply_domain, &request_id, &transition_id, &released_tag, &request_epoch, + &expected_master, &direct_state, &direct_target_prepared)); UT_ASSERT(!in_use); UT_ASSERT_EQ(reply_domain, UT_REPLY_DOMAIN_LEGACY_ACQUIRE); UT_ASSERT_EQ(request_id, 0); @@ -3802,12 +3593,10 @@ UT_TEST(test_r4_requester_status25_releases_then_retries_with_fresh_id) cluster_gcs_block_retransmit_max_retries = 1; memset(&requester_send, 0, sizeof(requester_send)); requester_send.reply_step_count = 2; - requester_send.reply_steps[0].status - = GCS_BLOCK_REPLY_R4_RETRYABLE_HOLDER_MOVED; + requester_send.reply_steps[0].status = GCS_BLOCK_REPLY_R4_RETRYABLE_HOLDER_MOVED; requester_send.reply_steps[0].envelope_source_node = UT_MASTER_NODE; requester_send.reply_steps[0].header_sender_node = UT_MASTER_NODE; - requester_send.reply_steps[0].forwarding_master_node - = GCS_BLOCK_REPLY_NO_FORWARDING_MASTER; + requester_send.reply_steps[0].forwarding_master_node = GCS_BLOCK_REPLY_NO_FORWARDING_MASTER; requester_send.reply_steps[0].page_lsn = 0; requester_send.reply_steps[0].block_fill = 0; requester_send.reply_steps[1].status = GCS_BLOCK_REPLY_R4_CR_FULL; @@ -3825,8 +3614,7 @@ UT_TEST(test_r4_requester_status25_releases_then_retries_with_fresh_id) memset(reply_cv_prepared, 0, sizeof(reply_cv_prepared)); memset(reply_cv_signaled, 0, sizeof(reply_cv_signaled)); - UT_ASSERT(cluster_gcs_block_test_r4_fetch_and_wait( - tag, UT_READ_SCN, UT_MASTER_NODE, dst_page)); + UT_ASSERT(cluster_gcs_block_test_r4_fetch_and_wait(tag, UT_READ_SCN, UT_MASTER_NODE, dst_page)); UT_ASSERT_EQ(requester_send.calls, 2); UT_ASSERT_EQ(requester_send.request_ids[0], UINT64_C(0x0200000000000001)); UT_ASSERT_EQ(requester_send.request_ids[1], UINT64_C(0x0200000000000002)); @@ -3846,8 +3634,8 @@ UT_TEST(test_r4_requester_status25_releases_then_retries_with_fresh_id) UT_ASSERT(reply_cv_prepared[0] == reply_cv_prepared[1]); UT_ASSERT(cluster_gcs_block_test_snapshot_r4_requester_slot( - &in_use, &reply_domain, &request_id, &transition_id, &released_tag, - &request_epoch, &expected_master, &direct_state, &direct_target_prepared)); + &in_use, &reply_domain, &request_id, &transition_id, &released_tag, &request_epoch, + &expected_master, &direct_state, &direct_target_prepared)); UT_ASSERT(!in_use); UT_ASSERT_EQ(reply_domain, UT_REPLY_DOMAIN_LEGACY_ACQUIRE); UT_ASSERT_EQ(request_id, 0); @@ -3903,8 +3691,8 @@ UT_TEST(test_r4_requester_status26_fails_closed_without_retry_and_cleans_slot) memset(reply_cv_prepared, 0, sizeof(reply_cv_prepared)); memset(reply_cv_signaled, 0, sizeof(reply_cv_signaled)); - UT_ASSERT(!cluster_gcs_block_test_r4_fetch_and_wait( - tag, UT_READ_SCN, UT_MASTER_NODE, dst_page)); + UT_ASSERT( + !cluster_gcs_block_test_r4_fetch_and_wait(tag, UT_READ_SCN, UT_MASTER_NODE, dst_page)); UT_ASSERT_EQ(requester_send.calls, 1); UT_ASSERT_EQ(requester_send.request_ids[0], UINT64_C(0x0200000000000001)); UT_ASSERT(requester_send.slot_armed_by_call[0]); @@ -3918,8 +3706,8 @@ UT_TEST(test_r4_requester_status26_fails_closed_without_retry_and_cleans_slot) UT_ASSERT(reply_cv_prepared[0] == reply_cv_signaled[0]); UT_ASSERT(cluster_gcs_block_test_snapshot_r4_requester_slot( - &in_use, &reply_domain, &request_id, &transition_id, &released_tag, - &request_epoch, &expected_master, &direct_state, &direct_target_prepared)); + &in_use, &reply_domain, &request_id, &transition_id, &released_tag, &request_epoch, + &expected_master, &direct_state, &direct_target_prepared)); UT_ASSERT(!in_use); UT_ASSERT_EQ(reply_domain, UT_REPLY_DOMAIN_LEGACY_ACQUIRE); UT_ASSERT_EQ(request_id, 0); @@ -3940,8 +3728,8 @@ route_test_reset_public_target_requester(void) uint64 request_id = 0; bool armed; - armed = cluster_gcs_block_test_r4_requester_arm( - tag, UT_FORMATION_EPOCH, UT_MASTER_NODE, UINT64_C(1), &request_id); + armed = cluster_gcs_block_test_r4_requester_arm(tag, UT_FORMATION_EPOCH, UT_MASTER_NODE, + UINT64_C(1), &request_id); UT_ASSERT(armed); if (armed) UT_ASSERT(cluster_gcs_block_test_release_r4_requester_slot()); @@ -3969,8 +3757,8 @@ route_test_assert_public_target_slot_is_canonical(void) bool direct_target_prepared = true; UT_ASSERT(cluster_gcs_block_test_snapshot_r4_requester_slot( - &in_use, &reply_domain, &request_id, &transition_id, &tag, - &request_epoch, &expected_master, &direct_state, &direct_target_prepared)); + &in_use, &reply_domain, &request_id, &transition_id, &tag, &request_epoch, &expected_master, + &direct_state, &direct_target_prepared)); UT_ASSERT(!in_use); UT_ASSERT_EQ(reply_domain, UT_REPLY_DOMAIN_LEGACY_ACQUIRE); UT_ASSERT_EQ(request_id, 0); @@ -4003,12 +3791,10 @@ UT_TEST(test_target_wrapper_status25_beyond_old_limit_waits_for_full) cluster_gcs_block_retransmit_max_retries = 8; route_test_reset_public_target_requester(); requester_send.reply_step_count = 10; - requester_send.reply_steps[0].status - = GCS_BLOCK_REPLY_R4_RETRYABLE_HOLDER_MOVED; + requester_send.reply_steps[0].status = GCS_BLOCK_REPLY_R4_RETRYABLE_HOLDER_MOVED; requester_send.reply_steps[0].envelope_source_node = UT_MASTER_NODE; requester_send.reply_steps[0].header_sender_node = UT_MASTER_NODE; - requester_send.reply_steps[0].forwarding_master_node - = GCS_BLOCK_REPLY_NO_FORWARDING_MASTER; + requester_send.reply_steps[0].forwarding_master_node = GCS_BLOCK_REPLY_NO_FORWARDING_MASTER; requester_send.reply_steps[0].page_lsn = 0; requester_send.reply_steps[0].block_fill = 0; for (i = 1; i < 9; i++) @@ -4570,8 +4356,7 @@ UT_TEST(test_target_wrapper_disabled_returns_typed_before_lookup_or_wire) memset(dst_page, 0xa7, sizeof(dst_page)); memcpy(original_page, dst_page, sizeof(original_page)); - result = cluster_gcs_block_cr_fetch_and_wait( - tag, InvalidScn, dst_page, &reason); + result = cluster_gcs_block_cr_fetch_and_wait(tag, InvalidScn, dst_page, &reason); UT_ASSERT_EQ(result, CLUSTER_CR_BUILD_RETRYABLE); UT_ASSERT_EQ(reason, CLUSTER_CR_BUILD_TARGET_DISABLED); @@ -4603,8 +4388,7 @@ UT_TEST(test_target_wrapper_status21_rechecks_private_scratch_then_copies_full) memset(dst_page, 0xa7, sizeof(dst_page)); memset(expected_page, 0x6d, sizeof(expected_page)); - result = cluster_gcs_block_cr_fetch_and_wait( - tag, UT_READ_SCN, dst_page, &reason); + result = cluster_gcs_block_cr_fetch_and_wait(tag, UT_READ_SCN, dst_page, &reason); UT_ASSERT_EQ(result, CLUSTER_CR_BUILD_FULL); UT_ASSERT_EQ(reason, CLUSTER_CR_BUILD_NONE); @@ -4618,8 +4402,7 @@ UT_TEST(test_target_wrapper_status21_rechecks_private_scratch_then_copies_full) UT_ASSERT(route_seam.lookup_sequence < requester_send.send_sequence); UT_ASSERT(requester_send.send_sequence < route_seam.recheck_sequence); UT_ASSERT(route_seam.recheck_sequence < route_seam.leave_sequence); - UT_ASSERT(route_seam.rechecked_admission_address - == route_seam.left_admission_address); + UT_ASSERT(route_seam.rechecked_admission_address == route_seam.left_admission_address); UT_ASSERT_EQ(memcmp(dst_page, expected_page, sizeof(dst_page)), 0); route_test_assert_public_target_slot_is_canonical(); cluster_node_id = saved_node_id; @@ -4648,8 +4431,7 @@ UT_TEST(test_target_wrapper_local_master_stages_request80_to_data_owner_and_retu memset(expected_page, 0x6d, sizeof(expected_page)); memset(&request, 0, sizeof(request)); - result = cluster_gcs_block_cr_fetch_and_wait( - tag, UT_READ_SCN, dst_page, &reason); + result = cluster_gcs_block_cr_fetch_and_wait(tag, UT_READ_SCN, dst_page, &reason); if (requester_send.payload_len == sizeof(request)) memcpy(&request, &requester_send.request, sizeof(request)); @@ -4669,8 +4451,7 @@ UT_TEST(test_target_wrapper_local_master_stages_request80_to_data_owner_and_retu UT_ASSERT_EQ(request.base.requester_backend_id, (int32)MyBackendId); UT_ASSERT_EQ(request.base.transition_id, PCM_TRANS_N_TO_S); UT_ASSERT_EQ(memcmp(&request.base.tag, &tag, sizeof(tag)), 0); - UT_ASSERT(ClusterR4RequestExtensionGetCr( - &request.extension, &decoded_read_scn)); + UT_ASSERT(ClusterR4RequestExtensionGetCr(&request.extension, &decoded_read_scn)); UT_ASSERT_EQ(decoded_read_scn, UT_READ_SCN); UT_ASSERT_EQ(route_seam.capability_calls, 0); UT_ASSERT_EQ(route_seam.peer_open_calls, 0); @@ -4709,8 +4490,7 @@ UT_TEST(test_target_wrapper_recheck_drift_keeps_dst_and_canonicalizes_slot) memset(dst_page, 0xa7, sizeof(dst_page)); memcpy(original_page, dst_page, sizeof(original_page)); - result = cluster_gcs_block_cr_fetch_and_wait( - tag, UT_READ_SCN, dst_page, &reason); + result = cluster_gcs_block_cr_fetch_and_wait(tag, UT_READ_SCN, dst_page, &reason); UT_ASSERT_EQ(result, CLUSTER_CR_BUILD_RETRYABLE); UT_ASSERT_EQ(reason, CLUSTER_CR_BUILD_RF_DEFERRED); @@ -4722,8 +4502,7 @@ UT_TEST(test_target_wrapper_recheck_drift_keeps_dst_and_canonicalizes_slot) UT_ASSERT_EQ(route_seam.leave_calls, 1); UT_ASSERT(requester_send.send_sequence < route_seam.recheck_sequence); UT_ASSERT(route_seam.recheck_sequence < route_seam.leave_sequence); - UT_ASSERT(route_seam.rechecked_admission_address - == route_seam.left_admission_address); + UT_ASSERT(route_seam.rechecked_admission_address == route_seam.left_admission_address); UT_ASSERT_EQ(memcmp(dst_page, original_page, sizeof(dst_page)), 0); route_test_assert_public_target_slot_is_canonical(); cluster_node_id = saved_node_id; @@ -4735,16 +4514,13 @@ UT_TEST(test_target_wrapper_recheck_drift_keeps_dst_and_canonicalizes_slot) * this one request -> holder behavior test. */ UT_TEST(test_request80_routes_stored_proof_to_real_forward96_handler) { - static const uint8 expected_extension[32] = { - 0x01, 0x01, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, - 0x09, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x22, 0x22, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - }; + static const uint8 expected_extension[32] + = { 0x01, 0x01, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, + 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x22, 0x22, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; ClusterR4CrRequestPayload request = route_test_request80(); - ClusterICEnvelope request_env - = route_test_envelope(PGRAC_IC_MSG_GCS_BLOCK_REQUEST, UT_REQUESTER_NODE, UT_MASTER_NODE, - sizeof(request)); + ClusterICEnvelope request_env = route_test_envelope( + PGRAC_IC_MSG_GCS_BLOCK_REQUEST, UT_REQUESTER_NODE, UT_MASTER_NODE, sizeof(request)); ClusterR4CrForwardPayload forwarded; ClusterICEnvelope forward_env; int saved_node_id = cluster_node_id; @@ -4768,8 +4544,7 @@ UT_TEST(test_request80_routes_stored_proof_to_real_forward96_handler) UT_ASSERT_EQ(route_seam.armed_lifetime_hint_ms, 1000); UT_ASSERT(route_seam.armed_lifetime_hint_trusted); UT_ASSERT_EQ(route_seam.armed_identity.legacy_key.origin_node_id, UT_REQUESTER_NODE); - UT_ASSERT_EQ(route_seam.armed_identity.legacy_key.requester_backend_id, - UT_REQUESTER_BACKEND); + UT_ASSERT_EQ(route_seam.armed_identity.legacy_key.requester_backend_id, UT_REQUESTER_BACKEND); UT_ASSERT_EQ(route_seam.armed_identity.legacy_key.request_id, UT_REQUEST_ID); UT_ASSERT_EQ(route_seam.armed_identity.legacy_key.cluster_epoch, UT_FORMATION_EPOCH); UT_ASSERT_EQ(route_seam.armed_identity.read_scn, UT_READ_SCN); @@ -4786,9 +4561,11 @@ UT_TEST(test_request80_routes_stored_proof_to_real_forward96_handler) UT_ASSERT_EQ(route_seam.refusal_enqueue_calls, 0); UT_ASSERT(route_seam.finished_outbound_admitted); UT_ASSERT_EQ(memcmp(&route_seam.finished_identity, &route_seam.armed_identity, - sizeof(route_seam.armed_identity)), 0); - UT_ASSERT_EQ(memcmp(&route_seam.finished_proof, &route_seam.armed_proof, - sizeof(route_seam.armed_proof)), 0); + sizeof(route_seam.armed_identity)), + 0); + UT_ASSERT_EQ( + memcmp(&route_seam.finished_proof, &route_seam.armed_proof, sizeof(route_seam.armed_proof)), + 0); UT_ASSERT_EQ(route_seam.recheck_calls, 1); UT_ASSERT(route_seam.snapshot_sequence < route_seam.arm_sequence); UT_ASSERT(route_seam.arm_sequence < route_seam.enqueue_sequence); @@ -4817,7 +4594,7 @@ UT_TEST(test_request80_routes_stored_proof_to_real_forward96_handler) UT_ASSERT_EQ(memcmp(((const uint8 *)&forwarded) + 76, expected_extension + 12, 8), 0); forward_env = route_test_envelope(PGRAC_IC_MSG_GCS_BLOCK_FORWARD, UT_MASTER_NODE, - UT_HOLDER_NODE, sizeof(forwarded)); + UT_HOLDER_NODE, sizeof(forwarded)); cluster_node_id = UT_HOLDER_NODE; route_seam_reset(); UT_ASSERT(cluster_gcs_block_test_r4_forward96(&forward_env, &forwarded)); @@ -4842,8 +4619,7 @@ UT_TEST(test_request80_routes_stored_proof_to_real_forward96_handler) UT_ASSERT(route_seam.submitted_admission.entered); UT_ASSERT_EQ(route_seam.submitted_admission.feature_bit, CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1); - UT_ASSERT_EQ(route_seam.submitted_admission.record_generation, - UT_ACTIVATION_GENERATION); + UT_ASSERT_EQ(route_seam.submitted_admission.record_generation, UT_ACTIVATION_GENERATION); UT_ASSERT_EQ(route_seam.submitted_admission.formation_epoch, UT_FORMATION_EPOCH); UT_ASSERT_EQ(route_seam.submitted_admission.side, CLUSTER_SEMANTIC_TARGET_SIDE); UT_ASSERT_EQ(route_seam.submitted_requester_capability_generation, @@ -4874,18 +4650,16 @@ UT_TEST(test_request80_local_master_uses_compiled_capability_and_routes_remote_h cluster_node_id = UT_MASTER_NODE; request.base.sender_node = UT_MASTER_NODE; - env = route_test_envelope(PGRAC_IC_MSG_GCS_BLOCK_REQUEST, UT_MASTER_NODE, - UT_MASTER_NODE, sizeof(request)); + env = route_test_envelope(PGRAC_IC_MSG_GCS_BLOCK_REQUEST, UT_MASTER_NODE, UT_MASTER_NODE, + sizeof(request)); route_seam_reset(); UT_ASSERT(cluster_gcs_block_test_r4_request80(&env, &request)); UT_ASSERT_EQ(route_seam.enter_calls, 1); UT_ASSERT_EQ(route_seam.leave_calls, 1); - UT_ASSERT(route_seam.capability_calls == 1 - && route_seam.capability_peers[0] == UT_HOLDER_NODE + UT_ASSERT(route_seam.capability_calls == 1 && route_seam.capability_peers[0] == UT_HOLDER_NODE && route_seam.capability_required[0] == UT_R4_REQUIRED_CAPABILITIES - && route_seam.peer_open_calls == 1 - && route_seam.peer_open_peers[0] == UT_HOLDER_NODE + && route_seam.peer_open_calls == 1 && route_seam.peer_open_peers[0] == UT_HOLDER_NODE && route_seam.peer_open_required[0] == UT_R4_REQUIRED_CAPABILITIES && route_seam.peer_open_generation[0] == UT_HOLDER_CAPABILITY_GENERATION && route_seam.enter_sequence < route_seam.snapshot_sequence @@ -4899,10 +4673,8 @@ UT_TEST(test_request80_local_master_uses_compiled_capability_and_routes_remote_h UT_ASSERT_EQ(route_seam.recheck_calls, 1); UT_ASSERT(route_seam.finished_outbound_admitted); UT_ASSERT_EQ(route_seam.armed_identity.legacy_key.origin_node_id, UT_MASTER_NODE); - UT_ASSERT_EQ(route_seam.armed_identity.activation_generation, - UT_ACTIVATION_GENERATION); - UT_ASSERT_EQ(route_seam.armed_proof.activation_generation, - UT_ACTIVATION_GENERATION); + UT_ASSERT_EQ(route_seam.armed_identity.activation_generation, UT_ACTIVATION_GENERATION); + UT_ASSERT_EQ(route_seam.armed_proof.activation_generation, UT_ACTIVATION_GENERATION); UT_ASSERT_EQ(route_seam.armed_proof.real_master_node, UT_MASTER_NODE); UT_ASSERT_EQ(route_seam.armed_proof.selected_holder_node, UT_HOLDER_NODE); UT_ASSERT_EQ(route_seam.armed_lifetime_hint_ms, 1000); @@ -4911,8 +4683,7 @@ UT_TEST(test_request80_local_master_uses_compiled_capability_and_routes_remote_h UT_ASSERT_EQ(route_seam.enqueue_dest, UT_HOLDER_NODE); UT_ASSERT_EQ(route_seam.enqueue_payload_len, sizeof(ClusterR4CrForwardPayload)); UT_ASSERT_EQ(route_seam.enqueue_required_capability, UT_R4_REQUIRED_CAPABILITIES); - UT_ASSERT_EQ(route_seam.enqueue_connection_generation, - UT_HOLDER_CAPABILITY_GENERATION); + UT_ASSERT_EQ(route_seam.enqueue_connection_generation, UT_HOLDER_CAPABILITY_GENERATION); memcpy(&forwarded, route_seam.enqueue_payload, sizeof(forwarded)); UT_ASSERT_EQ(forwarded.base.original_requester_node, UT_MASTER_NODE); UT_ASSERT_EQ(forwarded.base.master_node, UT_MASTER_NODE); @@ -4943,40 +4714,33 @@ UT_TEST(test_request80_all_local_routes_forward96_through_registered_dispatch) cluster_node_id = UT_HOLDER_NODE; request.base.sender_node = UT_HOLDER_NODE; - env = route_test_envelope(PGRAC_IC_MSG_GCS_BLOCK_REQUEST, UT_HOLDER_NODE, - UT_HOLDER_NODE, sizeof(request)); + env = route_test_envelope(PGRAC_IC_MSG_GCS_BLOCK_REQUEST, UT_HOLDER_NODE, UT_HOLDER_NODE, + sizeof(request)); route_seam_reset(); route_seam.lookup_master_node = UT_HOLDER_NODE; UT_ASSERT(cluster_gcs_block_test_r4_request80(&env, &request)); memcpy(&forwarded, route_seam.local_dispatch_payload, sizeof(forwarded)); proof_ok = ClusterR4ForwardExtensionGetCrProof( - &forwarded.extension, UT_FORMATION_EPOCH, - &master_authority_generation, &master_resource_transition_count, - &expected_page_scn); - - UT_ASSERT(route_seam.capability_calls == 0 - && route_seam.peer_open_calls == 0 - && route_seam.enqueue_calls == 0 - && route_seam.raw_send_calls == 0 - && route_seam.envelope_build_calls == 1 - && route_seam.local_dispatch_calls == 1 + &forwarded.extension, UT_FORMATION_EPOCH, &master_authority_generation, + &master_resource_transition_count, &expected_page_scn); + + UT_ASSERT(route_seam.capability_calls == 0 && route_seam.peer_open_calls == 0 + && route_seam.enqueue_calls == 0 && route_seam.raw_send_calls == 0 + && route_seam.envelope_build_calls == 1 && route_seam.local_dispatch_calls == 1 && route_seam.local_dispatch_peer == UT_HOLDER_NODE - && route_seam.local_dispatch_envelope.msg_type - == PGRAC_IC_MSG_GCS_BLOCK_FORWARD + && route_seam.local_dispatch_envelope.msg_type == PGRAC_IC_MSG_GCS_BLOCK_FORWARD && route_seam.local_dispatch_envelope.source_node_id == UT_HOLDER_NODE && route_seam.local_dispatch_envelope.dest_node_id == UT_HOLDER_NODE && route_seam.local_dispatch_envelope.epoch == UT_FORMATION_EPOCH - && route_seam.local_dispatch_payload_len - == sizeof(ClusterR4CrForwardPayload) + && route_seam.local_dispatch_payload_len == sizeof(ClusterR4CrForwardPayload) && forwarded.base.request_id == UT_REQUEST_ID && forwarded.base.epoch == UT_FORMATION_EPOCH && memcmp(&forwarded.base.tag, &request.base.tag, sizeof(BufferTag)) == 0 && forwarded.base.original_requester_node == UT_HOLDER_NODE && forwarded.base.requester_backend_id == UT_REQUESTER_BACKEND && forwarded.base.master_node == UT_HOLDER_NODE - && forwarded.base.transition_id == PCM_TRANS_N_TO_S - && proof_ok + && forwarded.base.transition_id == PCM_TRANS_N_TO_S && proof_ok && master_authority_generation == UT_MASTER_GENERATION && master_resource_transition_count == UT_MASTER_TRANSITION && expected_page_scn == UT_EXPECTED_PAGE_SCN @@ -4994,16 +4758,16 @@ UT_TEST(test_request80_all_local_routes_forward96_through_registered_dispatch) UT_ASSERT_EQ(route_seam.recheck_calls, 1); UT_ASSERT(route_seam.finished_outbound_admitted); UT_ASSERT_EQ(route_seam.armed_identity.legacy_key.origin_node_id, UT_HOLDER_NODE); - UT_ASSERT_EQ(route_seam.armed_identity.activation_generation, - UT_ACTIVATION_GENERATION); - UT_ASSERT_EQ(route_seam.armed_proof.activation_generation, - UT_ACTIVATION_GENERATION); + UT_ASSERT_EQ(route_seam.armed_identity.activation_generation, UT_ACTIVATION_GENERATION); + UT_ASSERT_EQ(route_seam.armed_proof.activation_generation, UT_ACTIVATION_GENERATION); UT_ASSERT_EQ(route_seam.armed_proof.real_master_node, UT_HOLDER_NODE); UT_ASSERT_EQ(route_seam.armed_proof.selected_holder_node, UT_HOLDER_NODE); UT_ASSERT_EQ(memcmp(&route_seam.finished_identity, &route_seam.armed_identity, - sizeof(route_seam.armed_identity)), 0); - UT_ASSERT_EQ(memcmp(&route_seam.finished_proof, &route_seam.armed_proof, - sizeof(route_seam.armed_proof)), 0); + sizeof(route_seam.armed_identity)), + 0); + UT_ASSERT_EQ( + memcmp(&route_seam.finished_proof, &route_seam.armed_proof, sizeof(route_seam.armed_proof)), + 0); UT_ASSERT(route_seam.finish_sequence < route_seam.recheck_sequence); UT_ASSERT(route_seam.recheck_sequence < route_seam.leave_sequence); cluster_node_id = saved_node_id; @@ -5022,8 +4786,8 @@ UT_TEST(test_forward96_all_local_uses_checked_open_generation_for_both_submit_id cluster_node_id = UT_HOLDER_NODE; forward.base.original_requester_node = UT_HOLDER_NODE; forward.base.master_node = UT_HOLDER_NODE; - env = route_test_envelope(PGRAC_IC_MSG_GCS_BLOCK_FORWARD, UT_HOLDER_NODE, - UT_HOLDER_NODE, sizeof(forward)); + env = route_test_envelope(PGRAC_IC_MSG_GCS_BLOCK_FORWARD, UT_HOLDER_NODE, UT_HOLDER_NODE, + sizeof(forward)); route_seam_reset(); route_seam.activation_generation = UT_LOCAL_OPEN_GENERATION; route_seam.lookup_master_node = UT_HOLDER_NODE; @@ -5045,8 +4809,7 @@ UT_TEST(test_forward96_all_local_uses_checked_open_generation_for_both_submit_id UT_ASSERT(route_seam.submitted_admission.entered); UT_ASSERT_EQ(route_seam.submitted_admission.feature_bit, CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1); - UT_ASSERT_EQ(route_seam.submitted_admission.record_generation, - UT_LOCAL_OPEN_GENERATION); + UT_ASSERT_EQ(route_seam.submitted_admission.record_generation, UT_LOCAL_OPEN_GENERATION); UT_ASSERT_EQ(route_seam.submitted_admission.formation_epoch, UT_FORMATION_EPOCH); UT_ASSERT_EQ(route_seam.submitted_admission.side, CLUSTER_SEMANTIC_TARGET_SIDE); UT_ASSERT_EQ(route_seam.submitted_requester_capability_generation, @@ -5054,14 +4817,14 @@ UT_TEST(test_forward96_all_local_uses_checked_open_generation_for_both_submit_id UT_ASSERT_EQ(route_seam.submitted_master_capability_generation, (uint32)UT_LOCAL_OPEN_GENERATION); UT_ASSERT(route_seam.submitted_admission_address != NULL); - UT_ASSERT(route_seam.submitted_admission_address - == route_seam.rechecked_admission_address); + UT_ASSERT(route_seam.submitted_admission_address == route_seam.rechecked_admission_address); UT_ASSERT(route_seam.submitted_admission_address == route_seam.left_admission_address); - UT_ASSERT_EQ(memcmp(&route_seam.submitted_admission, - &route_seam.rechecked_admission, - sizeof(route_seam.submitted_admission)), 0); + UT_ASSERT_EQ(memcmp(&route_seam.submitted_admission, &route_seam.rechecked_admission, + sizeof(route_seam.submitted_admission)), + 0); UT_ASSERT_EQ(memcmp(&route_seam.submitted_admission, &route_seam.left_admission, - sizeof(route_seam.submitted_admission)), 0); + sizeof(route_seam.submitted_admission)), + 0); UT_ASSERT(route_seam.enter_sequence < route_seam.holder_submit_sequence); UT_ASSERT(route_seam.holder_submit_sequence < route_seam.recheck_sequence); UT_ASSERT(route_seam.recheck_sequence < route_seam.leave_sequence); @@ -5081,8 +4844,8 @@ UT_TEST(test_forward96_all_local_refuses_open_generation_overflow_before_submit) cluster_node_id = UT_HOLDER_NODE; forward.base.original_requester_node = UT_HOLDER_NODE; forward.base.master_node = UT_HOLDER_NODE; - env = route_test_envelope(PGRAC_IC_MSG_GCS_BLOCK_FORWARD, UT_HOLDER_NODE, - UT_HOLDER_NODE, sizeof(forward)); + env = route_test_envelope(PGRAC_IC_MSG_GCS_BLOCK_FORWARD, UT_HOLDER_NODE, UT_HOLDER_NODE, + sizeof(forward)); route_seam_reset(); route_seam.activation_generation = UT_LOCAL_OPEN_GENERATION_OVERFLOW; route_seam.lookup_master_node = UT_HOLDER_NODE; @@ -5111,19 +4874,15 @@ UT_TEST(test_forward96_holder_submit_failure_publishes_typed_remote_refusal) ClusterCrBuildResult result; ClusterCrBuildReason reason; GcsBlockReplyStatus status; - } cases[] = { - { CLUSTER_CR_BUILD_RETRYABLE, CLUSTER_CR_BUILD_HOLDER_MOVED, - GCS_BLOCK_REPLY_R4_RETRYABLE_HOLDER_MOVED }, - { CLUSTER_CR_BUILD_FAIL_CLOSED, CLUSTER_CR_BUILD_PROTOCOL, - GCS_BLOCK_REPLY_R4_DENIED }, - /* A polarity-invalid pair must never inherit FULL or retry semantics. */ - { CLUSTER_CR_BUILD_FULL, CLUSTER_CR_BUILD_HOLDER_MOVED, - GCS_BLOCK_REPLY_R4_DENIED } - }; + } cases[] + = { { CLUSTER_CR_BUILD_RETRYABLE, CLUSTER_CR_BUILD_HOLDER_MOVED, + GCS_BLOCK_REPLY_R4_RETRYABLE_HOLDER_MOVED }, + { CLUSTER_CR_BUILD_FAIL_CLOSED, CLUSTER_CR_BUILD_PROTOCOL, GCS_BLOCK_REPLY_R4_DENIED }, + /* A polarity-invalid pair must never inherit FULL or retry semantics. */ + { CLUSTER_CR_BUILD_FULL, CLUSTER_CR_BUILD_HOLDER_MOVED, GCS_BLOCK_REPLY_R4_DENIED } }; ClusterR4CrForwardPayload forward = route_test_forward96(); - ClusterICEnvelope env - = route_test_envelope(PGRAC_IC_MSG_GCS_BLOCK_FORWARD, UT_MASTER_NODE, - UT_HOLDER_NODE, sizeof(forward)); + ClusterICEnvelope env = route_test_envelope(PGRAC_IC_MSG_GCS_BLOCK_FORWARD, UT_MASTER_NODE, + UT_HOLDER_NODE, sizeof(forward)); int saved_node_id = cluster_node_id; int i; @@ -5167,7 +4926,7 @@ UT_TEST(test_r4_try_handlers_consume_only_exact_extended_lengths) route_seam.capability_ok = false; env = route_test_envelope(PGRAC_IC_MSG_GCS_BLOCK_REQUEST, UT_REQUESTER_NODE, UT_MASTER_NODE, - sizeof(ClusterR4CrRequestPayload)); + sizeof(ClusterR4CrRequestPayload)); UT_ASSERT(cluster_gcs_block_test_r4_request80(&env, bytes)); UT_ASSERT_EQ(route_seam.refusal_enqueue_calls, 0); env.payload_length = sizeof(GcsBlockRequestPayload); @@ -5178,7 +4937,7 @@ UT_TEST(test_r4_try_handlers_consume_only_exact_extended_lengths) UT_ASSERT(!cluster_gcs_block_test_r4_request80(&env, bytes)); env = route_test_envelope(PGRAC_IC_MSG_GCS_BLOCK_FORWARD, UT_MASTER_NODE, UT_HOLDER_NODE, - sizeof(ClusterR4CrForwardPayload)); + sizeof(ClusterR4CrForwardPayload)); UT_ASSERT(cluster_gcs_block_test_r4_forward96(&env, bytes)); env.payload_length = sizeof(GcsBlockForwardPayload); UT_ASSERT(!cluster_gcs_block_test_r4_forward96(&env, bytes)); @@ -5195,9 +4954,8 @@ UT_TEST(test_r4_same_open_mismatch_has_zero_route_or_holder_mutation) { ClusterR4CrRequestPayload request = route_test_request80(); ClusterR4CrForwardPayload forward = route_test_forward96(); - ClusterICEnvelope env - = route_test_envelope(PGRAC_IC_MSG_GCS_BLOCK_REQUEST, UT_REQUESTER_NODE, UT_MASTER_NODE, - sizeof(request)); + ClusterICEnvelope env = route_test_envelope(PGRAC_IC_MSG_GCS_BLOCK_REQUEST, UT_REQUESTER_NODE, + UT_MASTER_NODE, sizeof(request)); int saved_node_id = cluster_node_id; route_seam_reset(); @@ -5222,7 +4980,7 @@ UT_TEST(test_r4_same_open_mismatch_has_zero_route_or_holder_mutation) UT_ASSERT_EQ(memcmp(&route_seam.refusal_tag, &request.base.tag, sizeof(BufferTag)), 0); env = route_test_envelope(PGRAC_IC_MSG_GCS_BLOCK_FORWARD, UT_MASTER_NODE, UT_HOLDER_NODE, - sizeof(forward)); + sizeof(forward)); cluster_node_id = UT_HOLDER_NODE; route_seam_reset(); route_seam.peer_open_ok = false; @@ -5249,15 +5007,12 @@ UT_TEST(test_r4_same_open_mismatch_has_zero_route_or_holder_mutation) * state. */ UT_TEST(test_request80_admission_refusals_publish_without_token) { - static const ClusterSemanticAdmissionResult refusals[] = { - CLUSTER_SEMANTIC_ADMISSION_TARGET_DISABLED, - CLUSTER_SEMANTIC_ADMISSION_CLOSED, - CLUSTER_SEMANTIC_ADMISSION_GENERATION_CHANGED - }; + static const ClusterSemanticAdmissionResult refusals[] + = { CLUSTER_SEMANTIC_ADMISSION_TARGET_DISABLED, CLUSTER_SEMANTIC_ADMISSION_CLOSED, + CLUSTER_SEMANTIC_ADMISSION_GENERATION_CHANGED }; ClusterR4CrRequestPayload request = route_test_request80(); - ClusterICEnvelope env - = route_test_envelope(PGRAC_IC_MSG_GCS_BLOCK_REQUEST, UT_REQUESTER_NODE, UT_MASTER_NODE, - sizeof(request)); + ClusterICEnvelope env = route_test_envelope(PGRAC_IC_MSG_GCS_BLOCK_REQUEST, UT_REQUESTER_NODE, + UT_MASTER_NODE, sizeof(request)); int i; for (i = 0; i < lengthof(refusals); i++) { @@ -5283,9 +5038,8 @@ UT_TEST(test_request80_admission_refusals_publish_without_token) UT_TEST(test_request80_sender_mismatch_is_consumed_without_route_mutation) { ClusterR4CrRequestPayload request = route_test_request80(); - ClusterICEnvelope env - = route_test_envelope(PGRAC_IC_MSG_GCS_BLOCK_REQUEST, UT_REQUESTER_NODE, UT_MASTER_NODE, - sizeof(request)); + ClusterICEnvelope env = route_test_envelope(PGRAC_IC_MSG_GCS_BLOCK_REQUEST, UT_REQUESTER_NODE, + UT_MASTER_NODE, sizeof(request)); request.base.sender_node = UT_HOLDER_NODE; route_seam_reset(); @@ -5308,9 +5062,8 @@ UT_TEST(test_request80_sender_mismatch_is_consumed_without_route_mutation) UT_TEST(test_request80_reserved_extension_is_consumed_without_route_mutation) { ClusterR4CrRequestPayload request = route_test_request80(); - ClusterICEnvelope env - = route_test_envelope(PGRAC_IC_MSG_GCS_BLOCK_REQUEST, UT_REQUESTER_NODE, UT_MASTER_NODE, - sizeof(request)); + ClusterICEnvelope env = route_test_envelope(PGRAC_IC_MSG_GCS_BLOCK_REQUEST, UT_REQUESTER_NODE, + UT_MASTER_NODE, sizeof(request)); request.extension.reserved[0] = 1; route_seam_reset(); @@ -5332,9 +5085,8 @@ UT_TEST(test_request80_reserved_extension_is_consumed_without_route_mutation) UT_TEST(test_request80_epoch_mismatch_is_consumed_without_route_mutation) { ClusterR4CrRequestPayload request = route_test_request80(); - ClusterICEnvelope env - = route_test_envelope(PGRAC_IC_MSG_GCS_BLOCK_REQUEST, UT_REQUESTER_NODE, UT_MASTER_NODE, - sizeof(request)); + ClusterICEnvelope env = route_test_envelope(PGRAC_IC_MSG_GCS_BLOCK_REQUEST, UT_REQUESTER_NODE, + UT_MASTER_NODE, sizeof(request)); request.base.epoch = UT_FORMATION_EPOCH + 1; route_seam_reset(); @@ -5356,9 +5108,8 @@ UT_TEST(test_request80_epoch_mismatch_is_consumed_without_route_mutation) UT_TEST(test_request80_wrong_master_is_consumed_before_snapshot) { ClusterR4CrRequestPayload request = route_test_request80(); - ClusterICEnvelope env - = route_test_envelope(PGRAC_IC_MSG_GCS_BLOCK_REQUEST, UT_REQUESTER_NODE, UT_MASTER_NODE, - sizeof(request)); + ClusterICEnvelope env = route_test_envelope(PGRAC_IC_MSG_GCS_BLOCK_REQUEST, UT_REQUESTER_NODE, + UT_MASTER_NODE, sizeof(request)); route_seam_reset(); route_seam.lookup_master_node = 0; @@ -5380,9 +5131,8 @@ UT_TEST(test_request80_wrong_master_is_consumed_before_snapshot) UT_TEST(test_request80_snapshot_failure_stops_before_route_arm) { ClusterR4CrRequestPayload request = route_test_request80(); - ClusterICEnvelope env - = route_test_envelope(PGRAC_IC_MSG_GCS_BLOCK_REQUEST, UT_REQUESTER_NODE, UT_MASTER_NODE, - sizeof(request)); + ClusterICEnvelope env = route_test_envelope(PGRAC_IC_MSG_GCS_BLOCK_REQUEST, UT_REQUESTER_NODE, + UT_MASTER_NODE, sizeof(request)); route_seam_reset(); route_seam.snapshot_ok = false; @@ -5405,9 +5155,8 @@ UT_TEST(test_request80_snapshot_failure_stops_before_route_arm) UT_TEST(test_request80_arm_full_stops_before_publication) { ClusterR4CrRequestPayload request = route_test_request80(); - ClusterICEnvelope env - = route_test_envelope(PGRAC_IC_MSG_GCS_BLOCK_REQUEST, UT_REQUESTER_NODE, UT_MASTER_NODE, - sizeof(request)); + ClusterICEnvelope env = route_test_envelope(PGRAC_IC_MSG_GCS_BLOCK_REQUEST, UT_REQUESTER_NODE, + UT_MASTER_NODE, sizeof(request)); route_seam_reset(); route_seam.arm_result = GCS_BLOCK_R4_ROUTE_ARM_FULL; @@ -5431,9 +5180,8 @@ UT_TEST(test_request80_arm_full_stops_before_publication) UT_TEST(test_request80_enqueue_refusal_finishes_unadmitted_once) { ClusterR4CrRequestPayload request = route_test_request80(); - ClusterICEnvelope env - = route_test_envelope(PGRAC_IC_MSG_GCS_BLOCK_REQUEST, UT_REQUESTER_NODE, UT_MASTER_NODE, - sizeof(request)); + ClusterICEnvelope env = route_test_envelope(PGRAC_IC_MSG_GCS_BLOCK_REQUEST, UT_REQUESTER_NODE, + UT_MASTER_NODE, sizeof(request)); route_seam_reset(); route_seam.enqueue_ok = false; @@ -5462,9 +5210,8 @@ UT_TEST(test_request80_enqueue_refusal_finishes_unadmitted_once) UT_TEST(test_request80_final_recheck_failure_leaves_after_one_publication) { ClusterR4CrRequestPayload request = route_test_request80(); - ClusterICEnvelope env - = route_test_envelope(PGRAC_IC_MSG_GCS_BLOCK_REQUEST, UT_REQUESTER_NODE, UT_MASTER_NODE, - sizeof(request)); + ClusterICEnvelope env = route_test_envelope(PGRAC_IC_MSG_GCS_BLOCK_REQUEST, UT_REQUESTER_NODE, + UT_MASTER_NODE, sizeof(request)); route_seam_reset(); route_seam.recheck_ok = false; @@ -5491,9 +5238,8 @@ UT_TEST(test_request80_final_recheck_failure_leaves_after_one_publication) UT_TEST(test_forward96_master_mismatch_is_consumed_without_holder_submit) { ClusterR4CrForwardPayload forward = route_test_forward96(); - ClusterICEnvelope env - = route_test_envelope(PGRAC_IC_MSG_GCS_BLOCK_FORWARD, UT_MASTER_NODE, UT_HOLDER_NODE, - sizeof(forward)); + ClusterICEnvelope env = route_test_envelope(PGRAC_IC_MSG_GCS_BLOCK_FORWARD, UT_MASTER_NODE, + UT_HOLDER_NODE, sizeof(forward)); int saved_node_id = cluster_node_id; forward.base.master_node = UT_HOLDER_NODE; @@ -5519,15 +5265,13 @@ UT_TEST(test_forward96_master_mismatch_is_consumed_without_holder_submit) UT_TEST(test_forward96_proof_epoch_mismatch_is_consumed_without_holder_submit) { ClusterR4CrForwardPayload forward = route_test_forward96(); - ClusterICEnvelope env - = route_test_envelope(PGRAC_IC_MSG_GCS_BLOCK_FORWARD, UT_MASTER_NODE, UT_HOLDER_NODE, - sizeof(forward)); + ClusterICEnvelope env = route_test_envelope(PGRAC_IC_MSG_GCS_BLOCK_FORWARD, UT_MASTER_NODE, + UT_HOLDER_NODE, sizeof(forward)); int saved_node_id = cluster_node_id; /* Corrupt the proof's embedded formation-epoch half while keeping the base * and authenticated envelope epochs valid. */ - forward.extension.kind.cr.master_authority_generation_le[4] - = (uint8)(UT_FORMATION_EPOCH + 1); + forward.extension.kind.cr.master_authority_generation_le[4] = (uint8)(UT_FORMATION_EPOCH + 1); cluster_node_id = UT_HOLDER_NODE; route_seam_reset(); UT_ASSERT_EQ(env.payload_length, 96); @@ -5569,9 +5313,8 @@ test_kind2_requester_generation_roundtrip(uint32 requested_generation) int saved_node_id = cluster_node_id; cluster_node_id = UT_REQUESTER_NODE; - UT_ASSERT(cluster_gcs_block_test_r4_requester_arm( - seed_tag, UT_FORMATION_EPOCH, UT_MASTER_NODE, UINT64_C(1), - &seed_request_id)); + UT_ASSERT(cluster_gcs_block_test_r4_requester_arm(seed_tag, UT_FORMATION_EPOCH, UT_MASTER_NODE, + UINT64_C(1), &seed_request_id)); UT_ASSERT(cluster_gcs_block_test_release_r4_requester_slot()); memset(&requester_send, 0, sizeof(requester_send)); memset(&locator, 0, sizeof(locator)); @@ -5589,30 +5332,25 @@ test_kind2_requester_generation_roundtrip(uint32 requested_generation) UT_ASSERT_EQ(reason, CLUSTER_TX_RESOLVE_NONE); UT_ASSERT_EQ(resolution.locator_echo.tt_wrap, 19); UT_ASSERT_EQ(resolution.authority.origin_epoch, UT_FORMATION_EPOCH); - UT_ASSERT_EQ(resolution.authority.live_hwm_lsn, - (XLogRecPtr)UINT64_C(0xabcdef)); + UT_ASSERT_EQ(resolution.authority.live_hwm_lsn, (XLogRecPtr)UINT64_C(0xabcdef)); UT_ASSERT_EQ(requester_send.calls, 1); UT_ASSERT(requester_send.tx_kind2); UT_ASSERT(requester_send.slot_armed); - UT_ASSERT_EQ(requester_send.payload_len, - sizeof(ClusterR4CrForwardPayload)); + UT_ASSERT_EQ(requester_send.payload_len, sizeof(ClusterR4CrForwardPayload)); UT_ASSERT_EQ(requester_send.dest_node, UT_MASTER_NODE); - UT_ASSERT_EQ(requester_send.tx_forward.base.original_requester_node, - UT_REQUESTER_NODE); - UT_ASSERT_EQ(requester_send.tx_forward.base.master_node, - UT_MASTER_NODE); - UT_ASSERT_EQ(memcmp(requester_send.tx_forward.base.reserved_0, - (const uint8[7]){ 0 }, - sizeof(requester_send.tx_forward.base.reserved_0)), 0); - UT_ASSERT(ClusterR4ForwardExtensionGetLocatorGeneration( - &requester_send.tx_forward.extension, - CLUSTER_R4_WIRE_TX_RESOLVE, &wire_locator, &wire_generation)); + UT_ASSERT_EQ(requester_send.tx_forward.base.original_requester_node, UT_REQUESTER_NODE); + UT_ASSERT_EQ(requester_send.tx_forward.base.master_node, UT_MASTER_NODE); + UT_ASSERT_EQ(memcmp(requester_send.tx_forward.base.reserved_0, (const uint8[7]){ 0 }, + sizeof(requester_send.tx_forward.base.reserved_0)), + 0); + UT_ASSERT(ClusterR4ForwardExtensionGetLocatorGeneration(&requester_send.tx_forward.extension, + CLUSTER_R4_WIRE_TX_RESOLVE, + &wire_locator, &wire_generation)); UT_ASSERT_EQ(wire_generation, requested_generation); UT_ASSERT_EQ(memcmp(&wire_locator, &locator, sizeof(locator)), 0); UT_ASSERT(cluster_gcs_block_test_snapshot_r4_requester_slot( - &released_in_use, &released_domain, &released_request_id, - &released_transition, &released_tag, &released_epoch, - &released_master, &direct_state, &direct_target_prepared)); + &released_in_use, &released_domain, &released_request_id, &released_transition, + &released_tag, &released_epoch, &released_master, &direct_state, &direct_target_prepared)); UT_ASSERT(!released_in_use); UT_ASSERT_EQ(released_domain, UT_REPLY_DOMAIN_LEGACY_ACQUIRE); UT_ASSERT_EQ(released_request_id, 0); @@ -5651,9 +5389,8 @@ UT_TEST(test_kind2_requester_sleep_error_cancels_cv_before_slot_release) int saved_node_id = cluster_node_id; cluster_node_id = UT_REQUESTER_NODE; - UT_ASSERT(cluster_gcs_block_test_r4_requester_arm( - seed_tag, UT_FORMATION_EPOCH, UT_MASTER_NODE, UINT64_C(1), - &seed_request_id)); + UT_ASSERT(cluster_gcs_block_test_r4_requester_arm(seed_tag, UT_FORMATION_EPOCH, UT_MASTER_NODE, + UINT64_C(1), &seed_request_id)); UT_ASSERT(cluster_gcs_block_test_release_r4_requester_slot()); memset(&requester_send, 0, sizeof(requester_send)); requester_send.suppress_reply = true; @@ -5671,8 +5408,7 @@ UT_TEST(test_kind2_requester_sleep_error_cancels_cv_before_slot_release) PG_TRY(); { (void)cluster_gcs_block_r4_tx_resolve_fetch_and_wait( - UT_MASTER_NODE, &locator, 9, UT_FORMATION_EPOCH, - &resolution, &reason); + UT_MASTER_NODE, &locator, 9, UT_FORMATION_EPOCH, &resolution, &reason); } PG_CATCH(); { @@ -5686,9 +5422,8 @@ UT_TEST(test_kind2_requester_sleep_error_cancels_cv_before_slot_release) UT_ASSERT_EQ(reply_cv_timed_sleep_calls, 1); UT_ASSERT_EQ(reply_cv_cancel_calls, 1); UT_ASSERT(cluster_gcs_block_test_snapshot_r4_requester_slot( - &released_in_use, &released_domain, &released_request_id, - &released_transition, &released_tag, &released_epoch, - &released_master, &direct_state, &direct_target_prepared)); + &released_in_use, &released_domain, &released_request_id, &released_transition, + &released_tag, &released_epoch, &released_master, &direct_state, &direct_target_prepared)); UT_ASSERT(!released_in_use); UT_ASSERT_EQ(released_domain, UT_REPLY_DOMAIN_LEGACY_ACQUIRE); UT_ASSERT_EQ(released_request_id, 0); @@ -5723,15 +5458,13 @@ UT_TEST(test_kind2_origin_runs_candidate2_cooperatively_and_ships_exact_status22 forward.base.transition_id = (uint8)PCM_TRANS_N_TO_S; UT_ASSERT(ClusterR4ForwardExtensionSetLocatorGeneration( &forward.extension, CLUSTER_R4_WIRE_TX_RESOLVE, &locator, 9)); - UT_ASSERT_EQ(memcmp(forward.base.reserved_0, - (const uint8[7]){ 0 }, - sizeof(forward.base.reserved_0)), 0); - env = route_test_envelope(PGRAC_IC_MSG_GCS_BLOCK_FORWARD, - UT_REQUESTER_NODE, UT_MASTER_NODE, sizeof(forward)); + UT_ASSERT_EQ( + memcmp(forward.base.reserved_0, (const uint8[7]){ 0 }, sizeof(forward.base.reserved_0)), 0); + env = route_test_envelope(PGRAC_IC_MSG_GCS_BLOCK_FORWARD, UT_REQUESTER_NODE, UT_MASTER_NODE, + sizeof(forward)); route_seam_reset(); - route_seam.admission_result - = CLUSTER_SEMANTIC_ADMISSION_TARGET_DISABLED; + route_seam.admission_result = CLUSTER_SEMANTIC_ADMISSION_TARGET_DISABLED; route_seam.raw_send_result = CLUSTER_IC_SEND_DONE; UT_ASSERT(cluster_gcs_block_test_r4_forward96(&env, &forward)); UT_ASSERT_EQ(cluster_gcs_block_test_r4_tx_origin_context_count(), 1); @@ -5749,26 +5482,21 @@ UT_TEST(test_kind2_origin_runs_candidate2_cooperatively_and_ships_exact_status22 UT_ASSERT_EQ(cluster_gcs_block_test_r4_tx_origin_context_count(), 0); UT_ASSERT_EQ(route_seam.raw_send_msg_type, PGRAC_IC_MSG_GCS_BLOCK_REPLY); UT_ASSERT_EQ(route_seam.raw_send_dest, UT_REQUESTER_NODE); - UT_ASSERT_EQ(route_seam.raw_send_payload_len, - GCS_BLOCK_REPLY_PAYLOAD_TOTAL_SIZE); + UT_ASSERT_EQ(route_seam.raw_send_payload_len, GCS_BLOCK_REPLY_PAYLOAD_TOTAL_SIZE); UT_ASSERT_EQ(route_seam.raw_send_header.request_id, UT_REQUEST_ID); UT_ASSERT_EQ(route_seam.raw_send_header.epoch, UT_FORMATION_EPOCH); UT_ASSERT_EQ(route_seam.raw_send_header.sender_node, UT_MASTER_NODE); - UT_ASSERT_EQ(route_seam.raw_send_header.requester_backend_id, - UT_REQUESTER_BACKEND); - UT_ASSERT_EQ(route_seam.raw_send_header.transition_id, - (uint8)PCM_TRANS_N_TO_S); - UT_ASSERT_EQ(route_seam.raw_send_header.status, - GCS_BLOCK_REPLY_R4_TX_RESOLVE_RESULT); - UT_ASSERT_EQ(GcsBlockReplyHeaderGetForwardingMasterNode( - &route_seam.raw_send_header), + UT_ASSERT_EQ(route_seam.raw_send_header.requester_backend_id, UT_REQUESTER_BACKEND); + UT_ASSERT_EQ(route_seam.raw_send_header.transition_id, (uint8)PCM_TRANS_N_TO_S); + UT_ASSERT_EQ(route_seam.raw_send_header.status, GCS_BLOCK_REPLY_R4_TX_RESOLVE_RESULT); + UT_ASSERT_EQ(GcsBlockReplyHeaderGetForwardingMasterNode(&route_seam.raw_send_header), GCS_BLOCK_REPLY_NO_FORWARDING_MASTER); UT_ASSERT_EQ(route_seam.raw_send_header.page_lsn, UINT64_C(0xabcdef)); UT_ASSERT_EQ(route_seam.raw_send_header.checksum, cluster_gcs_block_compute_checksum(route_seam.raw_send_page)); memset(&decoded, 0, sizeof(decoded)); - UT_ASSERT(ClusterR4TxVerdictPageDecode( - (const uint8 *)route_seam.raw_send_page, &locator, &decoded)); + UT_ASSERT( + ClusterR4TxVerdictPageDecode((const uint8 *)route_seam.raw_send_page, &locator, &decoded)); UT_ASSERT_EQ(decoded.outcome, CLUSTER_TX_COMMITTED); UT_ASSERT_EQ(decoded.locator_echo.tt_wrap, 19); UT_ASSERT_EQ(decoded.authority.origin_epoch, UT_FORMATION_EPOCH); @@ -5789,8 +5517,7 @@ UT_TEST(test_kind2_origin_runs_candidate2_cooperatively_and_ships_exact_status22 * non-stamping: status 26 with a canonical zero page. */ forward.base.reserved_0[6] = 0; route_seam_reset(); - route_seam.admission_result - = CLUSTER_SEMANTIC_ADMISSION_TARGET_DISABLED; + route_seam.admission_result = CLUSTER_SEMANTIC_ADMISSION_TARGET_DISABLED; route_seam.raw_send_result = CLUSTER_IC_SEND_DONE; route_seam.candidate_outcome = CLUSTER_TX_PREPARED; route_seam.candidate_proof = CLUSTER_TX_PROOF_ORIGIN_TWOPHASE; @@ -5798,8 +5525,7 @@ UT_TEST(test_kind2_origin_runs_candidate2_cooperatively_and_ships_exact_status22 for (i = 0; i < 4; i++) cluster_gcs_block_test_r4_tx_origin_drain(); UT_ASSERT_EQ(route_seam.raw_send_calls, 1); - UT_ASSERT_EQ(route_seam.raw_send_header.status, - GCS_BLOCK_REPLY_R4_DENIED); + UT_ASSERT_EQ(route_seam.raw_send_header.status, GCS_BLOCK_REPLY_R4_DENIED); UT_ASSERT_EQ(route_seam.raw_send_header.page_lsn, 0); for (i = 0; i < GCS_BLOCK_DATA_SIZE; i++) UT_ASSERT_EQ((uint8)route_seam.raw_send_page[i], 0); @@ -5807,8 +5533,7 @@ UT_TEST(test_kind2_origin_runs_candidate2_cooperatively_and_ships_exact_status22 /* A capability-generation/connection drift before publication sends no * verdict on the replacement connection and leaves the sole token. */ route_seam_reset(); - route_seam.admission_result - = CLUSTER_SEMANTIC_ADMISSION_TARGET_DISABLED; + route_seam.admission_result = CLUSTER_SEMANTIC_ADMISSION_TARGET_DISABLED; route_seam.raw_send_result = CLUSTER_IC_SEND_DONE; route_seam.candidate_cross_segment = true; UT_ASSERT(cluster_gcs_block_test_r4_forward96(&env, &forward)); @@ -5858,12 +5583,11 @@ UT_TEST(test_kind2_origin_capacity_covers_three_remote_c32_bursts) forward.base.transition_id = (uint8)PCM_TRANS_N_TO_S; UT_ASSERT(ClusterR4ForwardExtensionSetLocatorGeneration( &forward.extension, CLUSTER_R4_WIRE_TX_RESOLVE, &locator, 9)); - env = route_test_envelope(PGRAC_IC_MSG_GCS_BLOCK_FORWARD, - UT_REQUESTER_NODE, UT_MASTER_NODE, sizeof(forward)); + env = route_test_envelope(PGRAC_IC_MSG_GCS_BLOCK_FORWARD, UT_REQUESTER_NODE, UT_MASTER_NODE, + sizeof(forward)); route_seam_reset(); - route_seam.admission_result - = CLUSTER_SEMANTIC_ADMISSION_TARGET_DISABLED; + route_seam.admission_result = CLUSTER_SEMANTIC_ADMISSION_TARGET_DISABLED; route_seam.raw_send_result = CLUSTER_IC_SEND_DONE; for (i = 0; i < 96; i++) { forward.base.request_id = UT_REQUEST_ID + (uint64)i; diff --git a/src/test/cluster_unit/test_cluster_r4_scratch_resolver.c b/src/test/cluster_unit/test_cluster_r4_scratch_resolver.c index c4c003752a9..f852507944b 100644 --- a/src/test/cluster_unit/test_cluster_r4_scratch_resolver.c +++ b/src/test/cluster_unit/test_cluster_r4_scratch_resolver.c @@ -446,8 +446,7 @@ cluster_subtrans_lookup_parent(const ClusterTTStatusResult *child_result pg_attr } void -cluster_vis_memo_install(const ClusterTTStatusKey *key, uint8 status, - SCN commit_scn) +cluster_vis_memo_install(const ClusterTTStatusKey *key, uint8 status, SCN commit_scn) { ut_calls.memo_install++; ut_installed_key = *key; @@ -545,10 +544,10 @@ cluster_undo_verdict_resolve(int origin_node pg_attribute_unused(), } ClusterUndoVerdictResult -cluster_undo_verdict_resolve_freshref_c1b_pair( - int origin_node, uint32 undo_segment_id, TransactionId raw_xid, - TransactionId ref_xid, uint32 expected_tt_slot_id, uint32 ref_epoch, - SCN cached_commit_scn, SCN read_scn) +cluster_undo_verdict_resolve_freshref_c1b_pair(int origin_node, uint32 undo_segment_id, + TransactionId raw_xid, TransactionId ref_xid, + uint32 expected_tt_slot_id, uint32 ref_epoch, + SCN cached_commit_scn, SCN read_scn) { ut_calls.wire++; ut_calls.pair_resolve++; @@ -580,11 +579,11 @@ cluster_undo_verdict_resolve_freshref_c1b_pair( } bool -cluster_vis_freshref_c1b_pair_request_eligible( - TransactionId raw_xid, TransactionId ref_xid, bool has_cached_status, - SCN cached_commit_scn, uint32 ref_epoch, uint64 current_epoch, - int32 origin_node, int32 local_node, uint32 segment_id, - uint32 expected_tt_slot_id) +cluster_vis_freshref_c1b_pair_request_eligible(TransactionId raw_xid, TransactionId ref_xid, + bool has_cached_status, SCN cached_commit_scn, + uint32 ref_epoch, uint64 current_epoch, + int32 origin_node, int32 local_node, + uint32 segment_id, uint32 expected_tt_slot_id) { if (ut_full_scratch_fixture && ut_full_scratch_scenario >= 12) return raw_xid == UT_RAW_XID && ref_xid == UT_RAW_XID && has_cached_status @@ -592,12 +591,10 @@ cluster_vis_freshref_c1b_pair_request_eligible( && current_epoch == ut_current_epoch && origin_node == UT_PEER_NODE && local_node == UT_SELF_NODE && segment_id == UT_UNDO_SEGMENT && expected_tt_slot_id == UT_TT_SLOT; - return raw_xid == UT_RAW_XID && ref_xid == UT_RAW_XID - && has_cached_status && cached_commit_scn == UT_COMMIT_SCN - && ref_epoch == UT_CLUSTER_EPOCH - && current_epoch == UT_CLUSTER_EPOCH - && origin_node == UT_PEER_NODE && local_node == UT_SELF_NODE - && segment_id == UT_UNDO_SEGMENT + return raw_xid == UT_RAW_XID && ref_xid == UT_RAW_XID && has_cached_status + && cached_commit_scn == UT_COMMIT_SCN && ref_epoch == UT_CLUSTER_EPOCH + && current_epoch == UT_CLUSTER_EPOCH && origin_node == UT_PEER_NODE + && local_node == UT_SELF_NODE && segment_id == UT_UNDO_SEGMENT && expected_tt_slot_id == UT_TT_SLOT; } @@ -799,8 +796,8 @@ cluster_tt_recovery_count_remote_active_failclosed(void) ClusterTxOutcome cluster_tx_resolve_exact(const ClusterTxLocator *locator pg_attribute_unused(), - ClusterTxResolveMode mode pg_attribute_unused(), - ClusterTxResolution *out, ClusterTxResolveReason *reason_out) + ClusterTxResolveMode mode pg_attribute_unused(), ClusterTxResolution *out, + ClusterTxResolveReason *reason_out) { ut_calls.exact_resolve++; if (ut_full_scratch_fixture && ut_full_scratch_scenario >= 12) { @@ -1397,8 +1394,8 @@ UT_TEST(test_peer_fresh_native_ref_uses_covered_prehistory_before_overlay) } static void -ut_run_freshref_terminal_memo(ClusterUndoVerdictKind kind, - ClusterTTStatus expected_status, SCN verdict_scn) +ut_run_freshref_terminal_memo(ClusterUndoVerdictKind kind, ClusterTTStatus expected_status, + SCN verdict_scn) { ClusterUndoTTSlotRef ref = ut_exact_peer_ref(); ClusterVisResolve out; @@ -1413,8 +1410,7 @@ ut_run_freshref_terminal_memo(ClusterUndoVerdictKind kind, cluster_crossnode_runtime_visibility = true; memset(&out, 0xA5, sizeof(out)); - cluster_visibility_resolve_from_ref_scn( - UT_RAW_XID, &ref, UT_ANCHOR_LSN, UT_READ_SCN, &out); + cluster_visibility_resolve_from_ref_scn(UT_RAW_XID, &ref, UT_ANCHOR_LSN, UT_READ_SCN, &out); UT_ASSERT_EQ(out.evidence, CLUSTER_VIS_EVIDENCE_REMOTE); UT_ASSERT_EQ(out.status, expected_status); UT_ASSERT_EQ(out.commit_scn, verdict_scn); @@ -1423,14 +1419,12 @@ ut_run_freshref_terminal_memo(ClusterUndoVerdictKind kind, UT_ASSERT_EQ(ut_installed_status, expected_status); UT_ASSERT_EQ(ut_installed_scn, verdict_scn); ut_assert_exact_key(); - UT_ASSERT_EQ(memcmp(&ut_installed_key, &ut_seen_key, - sizeof(ut_installed_key)), 0); + UT_ASSERT_EQ(memcmp(&ut_installed_key, &ut_seen_key, sizeof(ut_installed_key)), 0); first_pair_resolve = ut_calls.pair_resolve; UT_ASSERT_EQ(first_pair_resolve, 1); memset(&out, 0xA5, sizeof(out)); - cluster_visibility_resolve_from_ref_scn( - UT_RAW_XID, &ref, UT_ANCHOR_LSN, UT_READ_SCN, &out); + cluster_visibility_resolve_from_ref_scn(UT_RAW_XID, &ref, UT_ANCHOR_LSN, UT_READ_SCN, &out); UT_ASSERT_EQ(out.evidence, CLUSTER_VIS_EVIDENCE_REMOTE); UT_ASSERT_EQ(out.status, expected_status); UT_ASSERT_EQ(out.commit_scn, verdict_scn); @@ -1441,9 +1435,8 @@ ut_run_freshref_terminal_memo(ClusterUndoVerdictKind kind, UT_TEST(test_freshref_committed_exact_installs_then_hits_terminal_memo) { - ut_run_freshref_terminal_memo( - CLUSTER_UNDO_VERDICT_COMMITTED_EXACT, - CLUSTER_TT_STATUS_COMMITTED, UT_COMMIT_SCN); + ut_run_freshref_terminal_memo(CLUSTER_UNDO_VERDICT_COMMITTED_EXACT, CLUSTER_TT_STATUS_COMMITTED, + UT_COMMIT_SCN); } /* @@ -1467,8 +1460,7 @@ UT_TEST(test_pair_eligible_freshref_bypasses_slotless_bound) cluster_crossnode_write_write = true; memset(&out, 0xA5, sizeof(out)); - cluster_visibility_resolve_from_ref_scn( - UT_RAW_XID, &ref, UT_ANCHOR_LSN, UT_READ_SCN, &out); + cluster_visibility_resolve_from_ref_scn(UT_RAW_XID, &ref, UT_ANCHOR_LSN, UT_READ_SCN, &out); UT_ASSERT_EQ(out.evidence, CLUSTER_VIS_EVIDENCE_REMOTE); UT_ASSERT_EQ(out.status, CLUSTER_TT_STATUS_COMMITTED); UT_ASSERT_EQ(out.commit_scn, UT_COMMIT_SCN); @@ -1479,9 +1471,8 @@ UT_TEST(test_pair_eligible_freshref_bypasses_slotless_bound) UT_TEST(test_freshref_aborted_installs_then_hits_terminal_memo) { - ut_run_freshref_terminal_memo( - CLUSTER_UNDO_VERDICT_ABORTED, - CLUSTER_TT_STATUS_ABORTED, InvalidScn); + ut_run_freshref_terminal_memo(CLUSTER_UNDO_VERDICT_ABORTED, CLUSTER_TT_STATUS_ABORTED, + InvalidScn); } UT_TEST(test_freshref_nonexact_verdicts_never_enter_terminal_memo) @@ -1492,12 +1483,9 @@ UT_TEST(test_freshref_nonexact_verdicts_never_enter_terminal_memo) ClusterTTStatus status; bool bound; } cases[] = { - { CLUSTER_UNDO_VERDICT_COMMITTED_BOUND, UT_COMMIT_SCN, - CLUSTER_TT_STATUS_COMMITTED, true }, - { CLUSTER_UNDO_VERDICT_IN_PROGRESS, InvalidScn, - CLUSTER_TT_STATUS_IN_PROGRESS, false }, - { CLUSTER_UNDO_VERDICT_UNKNOWN_FAIL_CLOSED, InvalidScn, - CLUSTER_TT_STATUS_UNKNOWN, false } + { CLUSTER_UNDO_VERDICT_COMMITTED_BOUND, UT_COMMIT_SCN, CLUSTER_TT_STATUS_COMMITTED, true }, + { CLUSTER_UNDO_VERDICT_IN_PROGRESS, InvalidScn, CLUSTER_TT_STATUS_IN_PROGRESS, false }, + { CLUSTER_UNDO_VERDICT_UNKNOWN_FAIL_CLOSED, InvalidScn, CLUSTER_TT_STATUS_UNKNOWN, false } }; uint32 i; @@ -1514,8 +1502,7 @@ UT_TEST(test_freshref_nonexact_verdicts_never_enter_terminal_memo) cluster_crossnode_runtime_visibility = true; memset(&out, 0xA5, sizeof(out)); - cluster_visibility_resolve_from_ref_scn( - UT_RAW_XID, &ref, UT_ANCHOR_LSN, UT_READ_SCN, &out); + cluster_visibility_resolve_from_ref_scn(UT_RAW_XID, &ref, UT_ANCHOR_LSN, UT_READ_SCN, &out); UT_ASSERT_EQ(out.status, cases[i].status); UT_ASSERT_EQ(out.commit_scn_is_bound, cases[i].bound); UT_ASSERT_EQ(ut_calls.memo_install, 0); diff --git a/src/test/cluster_unit/test_cluster_r4_slot_machine.c b/src/test/cluster_unit/test_cluster_r4_slot_machine.c index 10f0f674cdb..9a914735a22 100644 --- a/src/test/cluster_unit/test_cluster_r4_slot_machine.c +++ b/src/test/cluster_unit/test_cluster_r4_slot_machine.c @@ -24,245 +24,253 @@ UT_DEFINE_GLOBALS(); #define LMS CLUSTER_R4_OWNER_HOLDER_LMS #define UNDO (CLUSTER_R4_OWNER_HOLDER_LMON | CLUSTER_R4_OWNER_HOLDER_LMS | CLUSTER_R4_OWNER_ORIGIN) -#define DEFINE_CELL_TEST(test_name, state_value, event_value, next_value, alternate_value, \ - owner_value, action_value, text_value) \ +#define DEFINE_CELL_TEST(test_name, state_value, event_value, next_value, alternate_value, \ + owner_value, action_value, text_value) \ UT_TEST(test_name) \ { \ const ClusterR4TransitionCell *cell \ = cluster_r4_transition_lookup((state_value), (event_value)); \ - UT_ASSERT_NOT_NULL(cell); \ - if (cell != NULL) { \ - UT_ASSERT_EQ(cell->next_state, (next_value)); \ - UT_ASSERT_EQ(cell->alternate_state, (alternate_value)); \ + UT_ASSERT_NOT_NULL(cell); \ + if (cell != NULL) { \ + UT_ASSERT_EQ(cell->next_state, (next_value)); \ + UT_ASSERT_EQ(cell->alternate_state, (alternate_value)); \ UT_ASSERT_EQ(cell->owner_mask, (owner_value)); \ - UT_ASSERT_EQ(cell->action, (action_value)); \ - UT_ASSERT_STR_EQ(cell->spec_action, (text_value)); \ - } \ + UT_ASSERT_EQ(cell->action, (action_value)); \ + UT_ASSERT_STR_EQ(cell->spec_action, (text_value)); \ + } \ } /* E — EMPTY. */ DEFINE_CELL_TEST(test_01_e_valid, CLUSTER_R4_STATE_EMPTY, CLUSTER_R4_EVENT_VALID, - CLUSTER_R4_STATE_ROUTING, NONE, REQ, CLUSTER_R4_ACTION_ARM_BEFORE_SEND, "R/arm-before-send") + CLUSTER_R4_STATE_ROUTING, NONE, REQ, CLUSTER_R4_ACTION_ARM_BEFORE_SEND, + "R/arm-before-send") DEFINE_CELL_TEST(test_02_e_duplicate, CLUSTER_R4_STATE_EMPTY, CLUSTER_R4_EVENT_DUPLICATE, - CLUSTER_R4_STATE_EMPTY, NONE, REQ, CLUSTER_R4_ACTION_DROP, "E/drop") + CLUSTER_R4_STATE_EMPTY, NONE, REQ, CLUSTER_R4_ACTION_DROP, "E/drop") DEFINE_CELL_TEST(test_03_e_stale, CLUSTER_R4_STATE_EMPTY, CLUSTER_R4_EVENT_STALE, - CLUSTER_R4_STATE_EMPTY, NONE, REQ, CLUSTER_R4_ACTION_DROP, "E/drop") + CLUSTER_R4_STATE_EMPTY, NONE, REQ, CLUSTER_R4_ACTION_DROP, "E/drop") DEFINE_CELL_TEST(test_04_e_timeout, CLUSTER_R4_STATE_EMPTY, CLUSTER_R4_EVENT_TIMEOUT, - CLUSTER_R4_STATE_EMPTY, NONE, REQ, CLUSTER_R4_ACTION_DROP, "E/drop") + CLUSTER_R4_STATE_EMPTY, NONE, REQ, CLUSTER_R4_ACTION_DROP, "E/drop") DEFINE_CELL_TEST(test_05_e_cancel, CLUSTER_R4_STATE_EMPTY, CLUSTER_R4_EVENT_CANCEL, - CLUSTER_R4_STATE_CANCELLED, NONE, REQ, CLUSTER_R4_ACTION_NO_SEND, "K/no-send") + CLUSTER_R4_STATE_CANCELLED, NONE, REQ, CLUSTER_R4_ACTION_NO_SEND, "K/no-send") DEFINE_CELL_TEST(test_06_e_death, CLUSTER_R4_STATE_EMPTY, CLUSTER_R4_EVENT_DEATH, - CLUSTER_R4_STATE_EMPTY, NONE, REQ, CLUSTER_R4_ACTION_DROP, "E/drop") + CLUSTER_R4_STATE_EMPTY, NONE, REQ, CLUSTER_R4_ACTION_DROP, "E/drop") DEFINE_CELL_TEST(test_07_e_reconfig, CLUSTER_R4_STATE_EMPTY, CLUSTER_R4_EVENT_RECONFIG, - CLUSTER_R4_STATE_EMPTY, NONE, REQ, CLUSTER_R4_ACTION_DROP, "E/drop") + CLUSTER_R4_STATE_EMPTY, NONE, REQ, CLUSTER_R4_ACTION_DROP, "E/drop") DEFINE_CELL_TEST(test_08_e_capacity, CLUSTER_R4_STATE_EMPTY, CLUSTER_R4_EVENT_CAPACITY, - CLUSTER_R4_STATE_RETRYABLE, NONE, REQ, CLUSTER_R4_ACTION_RETRY, "T/retry") + CLUSTER_R4_STATE_RETRYABLE, NONE, REQ, CLUSTER_R4_ACTION_RETRY, "T/retry") DEFINE_CELL_TEST(test_09_e_malformed, CLUSTER_R4_STATE_EMPTY, CLUSTER_R4_EVENT_MALFORMED, - CLUSTER_R4_STATE_FAIL_CLOSED, NONE, REQ, CLUSTER_R4_ACTION_FAIL_PROTOCOL, "X/FC(protocol)") + CLUSTER_R4_STATE_FAIL_CLOSED, NONE, REQ, CLUSTER_R4_ACTION_FAIL_PROTOCOL, + "X/FC(protocol)") /* R — ROUTING. */ DEFINE_CELL_TEST(test_10_r_valid, CLUSTER_R4_STATE_ROUTING, CLUSTER_R4_EVENT_VALID, - CLUSTER_R4_STATE_FORWARDED, NONE, ROUTE, CLUSTER_R4_ACTION_MASTER_FORWARD, - "F/master selects+forwards") + CLUSTER_R4_STATE_FORWARDED, NONE, ROUTE, CLUSTER_R4_ACTION_MASTER_FORWARD, + "F/master selects+forwards") DEFINE_CELL_TEST(test_11_r_duplicate, CLUSTER_R4_STATE_ROUTING, CLUSTER_R4_EVENT_DUPLICATE, - CLUSTER_R4_STATE_ROUTING, NONE, ROUTE, CLUSTER_R4_ACTION_REPLAY_ROUTE, - "R/replay same route") + CLUSTER_R4_STATE_ROUTING, NONE, ROUTE, CLUSTER_R4_ACTION_REPLAY_ROUTE, + "R/replay same route") DEFINE_CELL_TEST(test_12_r_stale, CLUSTER_R4_STATE_ROUTING, CLUSTER_R4_EVENT_STALE, - CLUSTER_R4_STATE_RETRYABLE, NONE, ROUTE, CLUSTER_R4_ACTION_RETRY, "T/retry") + CLUSTER_R4_STATE_RETRYABLE, NONE, ROUTE, CLUSTER_R4_ACTION_RETRY, "T/retry") DEFINE_CELL_TEST(test_13_r_timeout, CLUSTER_R4_STATE_ROUTING, CLUSTER_R4_EVENT_TIMEOUT, - CLUSTER_R4_STATE_RETRYABLE, NONE, ROUTE, CLUSTER_R4_ACTION_CLOSE_ATTEMPT, - "T/close attempt") + CLUSTER_R4_STATE_RETRYABLE, NONE, ROUTE, CLUSTER_R4_ACTION_CLOSE_ATTEMPT, + "T/close attempt") DEFINE_CELL_TEST(test_14_r_cancel, CLUSTER_R4_STATE_ROUTING, CLUSTER_R4_EVENT_CANCEL, - CLUSTER_R4_STATE_CANCELLED, NONE, ROUTE, CLUSTER_R4_ACTION_CANCEL_ROUTE, "K/cancel route") + CLUSTER_R4_STATE_CANCELLED, NONE, ROUTE, CLUSTER_R4_ACTION_CANCEL_ROUTE, + "K/cancel route") DEFINE_CELL_TEST(test_15_r_death, CLUSTER_R4_STATE_ROUTING, CLUSTER_R4_EVENT_DEATH, - CLUSTER_R4_STATE_RETRYABLE, NONE, ROUTE, CLUSTER_R4_ACTION_RETRY, "T/retry") + CLUSTER_R4_STATE_RETRYABLE, NONE, ROUTE, CLUSTER_R4_ACTION_RETRY, "T/retry") DEFINE_CELL_TEST(test_16_r_reconfig, CLUSTER_R4_STATE_ROUTING, CLUSTER_R4_EVENT_RECONFIG, - CLUSTER_R4_STATE_RETRYABLE, NONE, ROUTE, CLUSTER_R4_ACTION_STALE_ROUTE, "T/stale route") + CLUSTER_R4_STATE_RETRYABLE, NONE, ROUTE, CLUSTER_R4_ACTION_STALE_ROUTE, + "T/stale route") DEFINE_CELL_TEST(test_17_r_capacity, CLUSTER_R4_STATE_ROUTING, CLUSTER_R4_EVENT_CAPACITY, - CLUSTER_R4_STATE_RETRYABLE, NONE, ROUTE, CLUSTER_R4_ACTION_RETRY, "T/retry") + CLUSTER_R4_STATE_RETRYABLE, NONE, ROUTE, CLUSTER_R4_ACTION_RETRY, "T/retry") DEFINE_CELL_TEST(test_18_r_malformed, CLUSTER_R4_STATE_ROUTING, CLUSTER_R4_EVENT_MALFORMED, - CLUSTER_R4_STATE_FAIL_CLOSED, NONE, ROUTE, CLUSTER_R4_ACTION_FAIL_PROTOCOL, - "X/FC(protocol)") + CLUSTER_R4_STATE_FAIL_CLOSED, NONE, ROUTE, CLUSTER_R4_ACTION_FAIL_PROTOCOL, + "X/FC(protocol)") /* F — FORWARDED. */ DEFINE_CELL_TEST(test_19_f_valid, CLUSTER_R4_STATE_FORWARDED, CLUSTER_R4_EVENT_VALID, - CLUSTER_R4_STATE_BUILDING, NONE, FWD, CLUSTER_R4_ACTION_HOLDER_STABLE_COPY, - "B/holder stable copy") + CLUSTER_R4_STATE_BUILDING, NONE, FWD, CLUSTER_R4_ACTION_HOLDER_STABLE_COPY, + "B/holder stable copy") DEFINE_CELL_TEST(test_20_f_duplicate, CLUSTER_R4_STATE_FORWARDED, CLUSTER_R4_EVENT_DUPLICATE, - CLUSTER_R4_STATE_FORWARDED, NONE, FWD, CLUSTER_R4_ACTION_DROP_OR_REPLAY, - "F/drop or replay") + CLUSTER_R4_STATE_FORWARDED, NONE, FWD, CLUSTER_R4_ACTION_DROP_OR_REPLAY, + "F/drop or replay") DEFINE_CELL_TEST(test_21_f_stale, CLUSTER_R4_STATE_FORWARDED, CLUSTER_R4_EVENT_STALE, - CLUSTER_R4_STATE_RETRYABLE, NONE, FWD, CLUSTER_R4_ACTION_RETRY, "T/retry") + CLUSTER_R4_STATE_RETRYABLE, NONE, FWD, CLUSTER_R4_ACTION_RETRY, "T/retry") DEFINE_CELL_TEST(test_22_f_timeout, CLUSTER_R4_STATE_FORWARDED, CLUSTER_R4_EVENT_TIMEOUT, - CLUSTER_R4_STATE_RETRYABLE, NONE, FWD, CLUSTER_R4_ACTION_CLOSE_ATTEMPT, - "T/close attempt") + CLUSTER_R4_STATE_RETRYABLE, NONE, FWD, CLUSTER_R4_ACTION_CLOSE_ATTEMPT, + "T/close attempt") DEFINE_CELL_TEST(test_23_f_cancel, CLUSTER_R4_STATE_FORWARDED, CLUSTER_R4_EVENT_CANCEL, - CLUSTER_R4_STATE_CANCELLED, NONE, FWD, CLUSTER_R4_ACTION_CANCEL_SLOT, "K/cancel slot") + CLUSTER_R4_STATE_CANCELLED, NONE, FWD, CLUSTER_R4_ACTION_CANCEL_SLOT, + "K/cancel slot") DEFINE_CELL_TEST(test_24_f_death, CLUSTER_R4_STATE_FORWARDED, CLUSTER_R4_EVENT_DEATH, - CLUSTER_R4_STATE_RETRYABLE, NONE, FWD, CLUSTER_R4_ACTION_RETRY, "T/retry") + CLUSTER_R4_STATE_RETRYABLE, NONE, FWD, CLUSTER_R4_ACTION_RETRY, "T/retry") DEFINE_CELL_TEST(test_25_f_reconfig, CLUSTER_R4_STATE_FORWARDED, CLUSTER_R4_EVENT_RECONFIG, - CLUSTER_R4_STATE_RETRYABLE, NONE, FWD, CLUSTER_R4_ACTION_STALE_SLOT, "T/stale slot") + CLUSTER_R4_STATE_RETRYABLE, NONE, FWD, CLUSTER_R4_ACTION_STALE_SLOT, + "T/stale slot") DEFINE_CELL_TEST(test_26_f_capacity, CLUSTER_R4_STATE_FORWARDED, CLUSTER_R4_EVENT_CAPACITY, - CLUSTER_R4_STATE_RETRYABLE, NONE, FWD, CLUSTER_R4_ACTION_RETRY, "T/retry") + CLUSTER_R4_STATE_RETRYABLE, NONE, FWD, CLUSTER_R4_ACTION_RETRY, "T/retry") DEFINE_CELL_TEST(test_27_f_malformed, CLUSTER_R4_STATE_FORWARDED, CLUSTER_R4_EVENT_MALFORMED, - CLUSTER_R4_STATE_FAIL_CLOSED, NONE, FWD, CLUSTER_R4_ACTION_FAIL_PROTOCOL, - "X/FC(protocol)") + CLUSTER_R4_STATE_FAIL_CLOSED, NONE, FWD, CLUSTER_R4_ACTION_FAIL_PROTOCOL, + "X/FC(protocol)") /* B — BUILDING. */ DEFINE_CELL_TEST(test_28_b_valid, CLUSTER_R4_STATE_BUILDING, CLUSTER_R4_EVENT_VALID, - CLUSTER_R4_STATE_WAIT_UNDO, CLUSTER_R4_STATE_REPLIED, LMS, - CLUSTER_R4_ACTION_REQUEST_UNDO_OR_PUBLISH, "U/request foreign undo or P/publish result") + CLUSTER_R4_STATE_WAIT_UNDO, CLUSTER_R4_STATE_REPLIED, LMS, + CLUSTER_R4_ACTION_REQUEST_UNDO_OR_PUBLISH, + "U/request foreign undo or P/publish result") DEFINE_CELL_TEST(test_29_b_duplicate, CLUSTER_R4_STATE_BUILDING, CLUSTER_R4_EVENT_DUPLICATE, - CLUSTER_R4_STATE_BUILDING, NONE, LMS, CLUSTER_R4_ACTION_DROP, "B/drop") + CLUSTER_R4_STATE_BUILDING, NONE, LMS, CLUSTER_R4_ACTION_DROP, "B/drop") DEFINE_CELL_TEST(test_30_b_stale, CLUSTER_R4_STATE_BUILDING, CLUSTER_R4_EVENT_STALE, - CLUSTER_R4_STATE_RETRYABLE, NONE, LMS, CLUSTER_R4_ACTION_RETRY, "T/retry") + CLUSTER_R4_STATE_RETRYABLE, NONE, LMS, CLUSTER_R4_ACTION_RETRY, "T/retry") DEFINE_CELL_TEST(test_31_b_timeout, CLUSTER_R4_STATE_BUILDING, CLUSTER_R4_EVENT_TIMEOUT, - CLUSTER_R4_STATE_RETRYABLE, NONE, LMS, CLUSTER_R4_ACTION_ABORT_SCRATCH, - "T/abort scratch") + CLUSTER_R4_STATE_RETRYABLE, NONE, LMS, CLUSTER_R4_ACTION_ABORT_SCRATCH, + "T/abort scratch") DEFINE_CELL_TEST(test_32_b_cancel, CLUSTER_R4_STATE_BUILDING, CLUSTER_R4_EVENT_CANCEL, - CLUSTER_R4_STATE_CANCELLED, NONE, LMS, CLUSTER_R4_ACTION_ABORT_SCRATCH, - "K/abort scratch") + CLUSTER_R4_STATE_CANCELLED, NONE, LMS, CLUSTER_R4_ACTION_ABORT_SCRATCH, + "K/abort scratch") DEFINE_CELL_TEST(test_33_b_death, CLUSTER_R4_STATE_BUILDING, CLUSTER_R4_EVENT_DEATH, - CLUSTER_R4_STATE_RETRYABLE, NONE, LMS, CLUSTER_R4_ACTION_RETRY, "T/retry") + CLUSTER_R4_STATE_RETRYABLE, NONE, LMS, CLUSTER_R4_ACTION_RETRY, "T/retry") DEFINE_CELL_TEST(test_34_b_reconfig, CLUSTER_R4_STATE_BUILDING, CLUSTER_R4_EVENT_RECONFIG, - CLUSTER_R4_STATE_RETRYABLE, NONE, LMS, CLUSTER_R4_ACTION_ABORT_SCRATCH, - "T/abort scratch") + CLUSTER_R4_STATE_RETRYABLE, NONE, LMS, CLUSTER_R4_ACTION_ABORT_SCRATCH, + "T/abort scratch") DEFINE_CELL_TEST(test_35_b_capacity, CLUSTER_R4_STATE_BUILDING, CLUSTER_R4_EVENT_CAPACITY, - CLUSTER_R4_STATE_RETRYABLE, NONE, LMS, CLUSTER_R4_ACTION_RETRY, "T/retry") + CLUSTER_R4_STATE_RETRYABLE, NONE, LMS, CLUSTER_R4_ACTION_RETRY, "T/retry") DEFINE_CELL_TEST(test_36_b_malformed, CLUSTER_R4_STATE_BUILDING, CLUSTER_R4_EVENT_MALFORMED, - CLUSTER_R4_STATE_FAIL_CLOSED, NONE, LMS, CLUSTER_R4_ACTION_FAIL_DATA_PROTOCOL, - "X/FC(data/protocol)") + CLUSTER_R4_STATE_FAIL_CLOSED, NONE, LMS, CLUSTER_R4_ACTION_FAIL_DATA_PROTOCOL, + "X/FC(data/protocol)") /* U — WAIT_UNDO. */ DEFINE_CELL_TEST(test_37_u_valid, CLUSTER_R4_STATE_WAIT_UNDO, CLUSTER_R4_EVENT_VALID, - CLUSTER_R4_STATE_BUILDING, NONE, UNDO, CLUSTER_R4_ACTION_EXACT_UNDO_REPLY, - "B/exact undo reply") + CLUSTER_R4_STATE_BUILDING, NONE, UNDO, CLUSTER_R4_ACTION_EXACT_UNDO_REPLY, + "B/exact undo reply") DEFINE_CELL_TEST(test_38_u_duplicate, CLUSTER_R4_STATE_WAIT_UNDO, CLUSTER_R4_EVENT_DUPLICATE, - CLUSTER_R4_STATE_WAIT_UNDO, NONE, UNDO, CLUSTER_R4_ACTION_DROP, "U/drop") + CLUSTER_R4_STATE_WAIT_UNDO, NONE, UNDO, CLUSTER_R4_ACTION_DROP, "U/drop") DEFINE_CELL_TEST(test_39_u_stale, CLUSTER_R4_STATE_WAIT_UNDO, CLUSTER_R4_EVENT_STALE, - CLUSTER_R4_STATE_RETRYABLE, NONE, UNDO, CLUSTER_R4_ACTION_RETRY, "T/retry") + CLUSTER_R4_STATE_RETRYABLE, NONE, UNDO, CLUSTER_R4_ACTION_RETRY, "T/retry") DEFINE_CELL_TEST(test_40_u_timeout, CLUSTER_R4_STATE_WAIT_UNDO, CLUSTER_R4_EVENT_TIMEOUT, - CLUSTER_R4_STATE_RETRYABLE, NONE, UNDO, CLUSTER_R4_ACTION_ABORT_SCRATCH, - "T/abort scratch") + CLUSTER_R4_STATE_RETRYABLE, NONE, UNDO, CLUSTER_R4_ACTION_ABORT_SCRATCH, + "T/abort scratch") DEFINE_CELL_TEST(test_41_u_cancel, CLUSTER_R4_STATE_WAIT_UNDO, CLUSTER_R4_EVENT_CANCEL, - CLUSTER_R4_STATE_CANCELLED, NONE, UNDO, CLUSTER_R4_ACTION_ABORT_SCRATCH, - "K/abort scratch") + CLUSTER_R4_STATE_CANCELLED, NONE, UNDO, CLUSTER_R4_ACTION_ABORT_SCRATCH, + "K/abort scratch") DEFINE_CELL_TEST(test_42_u_death, CLUSTER_R4_STATE_WAIT_UNDO, CLUSTER_R4_EVENT_DEATH, - CLUSTER_R4_STATE_RETRYABLE, NONE, UNDO, CLUSTER_R4_ACTION_RETRY, "T/retry") + CLUSTER_R4_STATE_RETRYABLE, NONE, UNDO, CLUSTER_R4_ACTION_RETRY, "T/retry") DEFINE_CELL_TEST(test_43_u_reconfig, CLUSTER_R4_STATE_WAIT_UNDO, CLUSTER_R4_EVENT_RECONFIG, - CLUSTER_R4_STATE_RETRYABLE, NONE, UNDO, CLUSTER_R4_ACTION_ABORT_SCRATCH, - "T/abort scratch") + CLUSTER_R4_STATE_RETRYABLE, NONE, UNDO, CLUSTER_R4_ACTION_ABORT_SCRATCH, + "T/abort scratch") DEFINE_CELL_TEST(test_44_u_capacity, CLUSTER_R4_STATE_WAIT_UNDO, CLUSTER_R4_EVENT_CAPACITY, - CLUSTER_R4_STATE_RETRYABLE, NONE, UNDO, CLUSTER_R4_ACTION_RETRY, "T/retry") + CLUSTER_R4_STATE_RETRYABLE, NONE, UNDO, CLUSTER_R4_ACTION_RETRY, "T/retry") DEFINE_CELL_TEST(test_45_u_malformed, CLUSTER_R4_STATE_WAIT_UNDO, CLUSTER_R4_EVENT_MALFORMED, - CLUSTER_R4_STATE_FAIL_CLOSED, NONE, UNDO, CLUSTER_R4_ACTION_FAIL_DATA_PROTOCOL, - "X/FC(data/protocol)") + CLUSTER_R4_STATE_FAIL_CLOSED, NONE, UNDO, CLUSTER_R4_ACTION_FAIL_DATA_PROTOCOL, + "X/FC(data/protocol)") /* P — REPLIED. */ DEFINE_CELL_TEST(test_46_p_valid, CLUSTER_R4_STATE_REPLIED, CLUSTER_R4_EVENT_VALID, - CLUSTER_R4_STATE_CONSUMED, NONE, REQ, CLUSTER_R4_ACTION_CONSUMER_CAS, - "C/exact consumer CAS") + CLUSTER_R4_STATE_CONSUMED, NONE, REQ, CLUSTER_R4_ACTION_CONSUMER_CAS, + "C/exact consumer CAS") DEFINE_CELL_TEST(test_47_p_duplicate, CLUSTER_R4_STATE_REPLIED, CLUSTER_R4_EVENT_DUPLICATE, - CLUSTER_R4_STATE_REPLIED, NONE, REQ, CLUSTER_R4_ACTION_DROP, "P/drop") + CLUSTER_R4_STATE_REPLIED, NONE, REQ, CLUSTER_R4_ACTION_DROP, "P/drop") DEFINE_CELL_TEST(test_48_p_stale, CLUSTER_R4_STATE_REPLIED, CLUSTER_R4_EVENT_STALE, - CLUSTER_R4_STATE_REPLIED, NONE, REQ, CLUSTER_R4_ACTION_DROP, "P/drop") + CLUSTER_R4_STATE_REPLIED, NONE, REQ, CLUSTER_R4_ACTION_DROP, "P/drop") DEFINE_CELL_TEST(test_49_p_timeout, CLUSTER_R4_STATE_REPLIED, CLUSTER_R4_EVENT_TIMEOUT, - CLUSTER_R4_STATE_REPLIED, NONE, REQ, CLUSTER_R4_ACTION_DROP, "P/drop") + CLUSTER_R4_STATE_REPLIED, NONE, REQ, CLUSTER_R4_ACTION_DROP, "P/drop") DEFINE_CELL_TEST(test_50_p_cancel, CLUSTER_R4_STATE_REPLIED, CLUSTER_R4_EVENT_CANCEL, - CLUSTER_R4_STATE_CANCELLED, NONE, REQ, CLUSTER_R4_ACTION_DROP_RESULT, "K/drop result") + CLUSTER_R4_STATE_CANCELLED, NONE, REQ, CLUSTER_R4_ACTION_DROP_RESULT, + "K/drop result") DEFINE_CELL_TEST(test_51_p_death, CLUSTER_R4_STATE_REPLIED, CLUSTER_R4_EVENT_DEATH, - CLUSTER_R4_STATE_REPLIED, NONE, REQ, CLUSTER_R4_ACTION_DROP, "P/drop") + CLUSTER_R4_STATE_REPLIED, NONE, REQ, CLUSTER_R4_ACTION_DROP, "P/drop") DEFINE_CELL_TEST(test_52_p_reconfig, CLUSTER_R4_STATE_REPLIED, CLUSTER_R4_EVENT_RECONFIG, - CLUSTER_R4_STATE_REPLIED, NONE, REQ, CLUSTER_R4_ACTION_DROP, "P/drop") + CLUSTER_R4_STATE_REPLIED, NONE, REQ, CLUSTER_R4_ACTION_DROP, "P/drop") DEFINE_CELL_TEST(test_53_p_capacity, CLUSTER_R4_STATE_REPLIED, CLUSTER_R4_EVENT_CAPACITY, - CLUSTER_R4_STATE_REPLIED, NONE, REQ, CLUSTER_R4_ACTION_DROP, "P/drop") + CLUSTER_R4_STATE_REPLIED, NONE, REQ, CLUSTER_R4_ACTION_DROP, "P/drop") DEFINE_CELL_TEST(test_54_p_malformed, CLUSTER_R4_STATE_REPLIED, CLUSTER_R4_EVENT_MALFORMED, - CLUSTER_R4_STATE_REPLIED, NONE, REQ, CLUSTER_R4_ACTION_DROP, "P/drop") + CLUSTER_R4_STATE_REPLIED, NONE, REQ, CLUSTER_R4_ACTION_DROP, "P/drop") /* C — CONSUMED, absorbing. */ DEFINE_CELL_TEST(test_55_c_valid, CLUSTER_R4_STATE_CONSUMED, CLUSTER_R4_EVENT_VALID, - CLUSTER_R4_STATE_CONSUMED, NONE, REQ, CLUSTER_R4_ACTION_DROP, "C/drop") + CLUSTER_R4_STATE_CONSUMED, NONE, REQ, CLUSTER_R4_ACTION_DROP, "C/drop") DEFINE_CELL_TEST(test_56_c_duplicate, CLUSTER_R4_STATE_CONSUMED, CLUSTER_R4_EVENT_DUPLICATE, - CLUSTER_R4_STATE_CONSUMED, NONE, REQ, CLUSTER_R4_ACTION_DROP, "C/drop") + CLUSTER_R4_STATE_CONSUMED, NONE, REQ, CLUSTER_R4_ACTION_DROP, "C/drop") DEFINE_CELL_TEST(test_57_c_stale, CLUSTER_R4_STATE_CONSUMED, CLUSTER_R4_EVENT_STALE, - CLUSTER_R4_STATE_CONSUMED, NONE, REQ, CLUSTER_R4_ACTION_DROP, "C/drop") + CLUSTER_R4_STATE_CONSUMED, NONE, REQ, CLUSTER_R4_ACTION_DROP, "C/drop") DEFINE_CELL_TEST(test_58_c_timeout, CLUSTER_R4_STATE_CONSUMED, CLUSTER_R4_EVENT_TIMEOUT, - CLUSTER_R4_STATE_CONSUMED, NONE, REQ, CLUSTER_R4_ACTION_DROP, "C/drop") + CLUSTER_R4_STATE_CONSUMED, NONE, REQ, CLUSTER_R4_ACTION_DROP, "C/drop") DEFINE_CELL_TEST(test_59_c_cancel, CLUSTER_R4_STATE_CONSUMED, CLUSTER_R4_EVENT_CANCEL, - CLUSTER_R4_STATE_CONSUMED, NONE, REQ, CLUSTER_R4_ACTION_DROP, "C/drop") + CLUSTER_R4_STATE_CONSUMED, NONE, REQ, CLUSTER_R4_ACTION_DROP, "C/drop") DEFINE_CELL_TEST(test_60_c_death, CLUSTER_R4_STATE_CONSUMED, CLUSTER_R4_EVENT_DEATH, - CLUSTER_R4_STATE_CONSUMED, NONE, REQ, CLUSTER_R4_ACTION_DROP, "C/drop") + CLUSTER_R4_STATE_CONSUMED, NONE, REQ, CLUSTER_R4_ACTION_DROP, "C/drop") DEFINE_CELL_TEST(test_61_c_reconfig, CLUSTER_R4_STATE_CONSUMED, CLUSTER_R4_EVENT_RECONFIG, - CLUSTER_R4_STATE_CONSUMED, NONE, REQ, CLUSTER_R4_ACTION_DROP, "C/drop") + CLUSTER_R4_STATE_CONSUMED, NONE, REQ, CLUSTER_R4_ACTION_DROP, "C/drop") DEFINE_CELL_TEST(test_62_c_capacity, CLUSTER_R4_STATE_CONSUMED, CLUSTER_R4_EVENT_CAPACITY, - CLUSTER_R4_STATE_CONSUMED, NONE, REQ, CLUSTER_R4_ACTION_DROP, "C/drop") + CLUSTER_R4_STATE_CONSUMED, NONE, REQ, CLUSTER_R4_ACTION_DROP, "C/drop") DEFINE_CELL_TEST(test_63_c_malformed, CLUSTER_R4_STATE_CONSUMED, CLUSTER_R4_EVENT_MALFORMED, - CLUSTER_R4_STATE_CONSUMED, NONE, REQ, CLUSTER_R4_ACTION_DROP, "C/drop") + CLUSTER_R4_STATE_CONSUMED, NONE, REQ, CLUSTER_R4_ACTION_DROP, "C/drop") /* T — RETRYABLE. */ DEFINE_CELL_TEST(test_64_t_valid, CLUSTER_R4_STATE_RETRYABLE, CLUSTER_R4_EVENT_VALID, - CLUSTER_R4_STATE_ROUTING, NONE, REQ, CLUSTER_R4_ACTION_NEW_REQUEST, - "R/new request id after typed close") + CLUSTER_R4_STATE_ROUTING, NONE, REQ, CLUSTER_R4_ACTION_NEW_REQUEST, + "R/new request id after typed close") DEFINE_CELL_TEST(test_65_t_duplicate, CLUSTER_R4_STATE_RETRYABLE, CLUSTER_R4_EVENT_DUPLICATE, - CLUSTER_R4_STATE_RETRYABLE, NONE, REQ, CLUSTER_R4_ACTION_DROP, "T/drop") + CLUSTER_R4_STATE_RETRYABLE, NONE, REQ, CLUSTER_R4_ACTION_DROP, "T/drop") DEFINE_CELL_TEST(test_66_t_stale, CLUSTER_R4_STATE_RETRYABLE, CLUSTER_R4_EVENT_STALE, - CLUSTER_R4_STATE_RETRYABLE, NONE, REQ, CLUSTER_R4_ACTION_DROP, "T/drop") + CLUSTER_R4_STATE_RETRYABLE, NONE, REQ, CLUSTER_R4_ACTION_DROP, "T/drop") DEFINE_CELL_TEST(test_67_t_timeout, CLUSTER_R4_STATE_RETRYABLE, CLUSTER_R4_EVENT_TIMEOUT, - CLUSTER_R4_STATE_FAIL_CLOSED, NONE, REQ, CLUSTER_R4_ACTION_OVERALL_DEADLINE, - "X/overall deadline") + CLUSTER_R4_STATE_FAIL_CLOSED, NONE, REQ, CLUSTER_R4_ACTION_OVERALL_DEADLINE, + "X/overall deadline") DEFINE_CELL_TEST(test_68_t_cancel, CLUSTER_R4_STATE_RETRYABLE, CLUSTER_R4_EVENT_CANCEL, - CLUSTER_R4_STATE_CANCELLED, NONE, REQ, CLUSTER_R4_ACTION_CLEANUP, "K/cleanup") + CLUSTER_R4_STATE_CANCELLED, NONE, REQ, CLUSTER_R4_ACTION_CLEANUP, "K/cleanup") DEFINE_CELL_TEST(test_69_t_death, CLUSTER_R4_STATE_RETRYABLE, CLUSTER_R4_EVENT_DEATH, - CLUSTER_R4_STATE_RETRYABLE, NONE, REQ, CLUSTER_R4_ACTION_WAIT_TOPOLOGY, - "T/wait topology") + CLUSTER_R4_STATE_RETRYABLE, NONE, REQ, CLUSTER_R4_ACTION_WAIT_TOPOLOGY, + "T/wait topology") DEFINE_CELL_TEST(test_70_t_reconfig, CLUSTER_R4_STATE_RETRYABLE, CLUSTER_R4_EVENT_RECONFIG, - CLUSTER_R4_STATE_RETRYABLE, NONE, REQ, CLUSTER_R4_ACTION_WAIT_ADMISSION, - "T/wait admission") + CLUSTER_R4_STATE_RETRYABLE, NONE, REQ, CLUSTER_R4_ACTION_WAIT_ADMISSION, + "T/wait admission") DEFINE_CELL_TEST(test_71_t_capacity, CLUSTER_R4_STATE_RETRYABLE, CLUSTER_R4_EVENT_CAPACITY, - CLUSTER_R4_STATE_RETRYABLE, NONE, REQ, CLUSTER_R4_ACTION_BACKOFF, "T/backoff") + CLUSTER_R4_STATE_RETRYABLE, NONE, REQ, CLUSTER_R4_ACTION_BACKOFF, "T/backoff") DEFINE_CELL_TEST(test_72_t_malformed, CLUSTER_R4_STATE_RETRYABLE, CLUSTER_R4_EVENT_MALFORMED, - CLUSTER_R4_STATE_FAIL_CLOSED, NONE, REQ, CLUSTER_R4_ACTION_FAIL_PROTOCOL, - "X/FC(protocol)") + CLUSTER_R4_STATE_FAIL_CLOSED, NONE, REQ, CLUSTER_R4_ACTION_FAIL_PROTOCOL, + "X/FC(protocol)") /* X — FAIL_CLOSED, absorbing. */ DEFINE_CELL_TEST(test_73_x_valid, CLUSTER_R4_STATE_FAIL_CLOSED, CLUSTER_R4_EVENT_VALID, - CLUSTER_R4_STATE_FAIL_CLOSED, NONE, REQ, CLUSTER_R4_ACTION_DROP, "X/drop") + CLUSTER_R4_STATE_FAIL_CLOSED, NONE, REQ, CLUSTER_R4_ACTION_DROP, "X/drop") DEFINE_CELL_TEST(test_74_x_duplicate, CLUSTER_R4_STATE_FAIL_CLOSED, CLUSTER_R4_EVENT_DUPLICATE, - CLUSTER_R4_STATE_FAIL_CLOSED, NONE, REQ, CLUSTER_R4_ACTION_DROP, "X/drop") + CLUSTER_R4_STATE_FAIL_CLOSED, NONE, REQ, CLUSTER_R4_ACTION_DROP, "X/drop") DEFINE_CELL_TEST(test_75_x_stale, CLUSTER_R4_STATE_FAIL_CLOSED, CLUSTER_R4_EVENT_STALE, - CLUSTER_R4_STATE_FAIL_CLOSED, NONE, REQ, CLUSTER_R4_ACTION_DROP, "X/drop") + CLUSTER_R4_STATE_FAIL_CLOSED, NONE, REQ, CLUSTER_R4_ACTION_DROP, "X/drop") DEFINE_CELL_TEST(test_76_x_timeout, CLUSTER_R4_STATE_FAIL_CLOSED, CLUSTER_R4_EVENT_TIMEOUT, - CLUSTER_R4_STATE_FAIL_CLOSED, NONE, REQ, CLUSTER_R4_ACTION_DROP, "X/drop") + CLUSTER_R4_STATE_FAIL_CLOSED, NONE, REQ, CLUSTER_R4_ACTION_DROP, "X/drop") DEFINE_CELL_TEST(test_77_x_cancel, CLUSTER_R4_STATE_FAIL_CLOSED, CLUSTER_R4_EVENT_CANCEL, - CLUSTER_R4_STATE_FAIL_CLOSED, NONE, REQ, CLUSTER_R4_ACTION_CLEANUP, "X/cleanup") + CLUSTER_R4_STATE_FAIL_CLOSED, NONE, REQ, CLUSTER_R4_ACTION_CLEANUP, "X/cleanup") DEFINE_CELL_TEST(test_78_x_death, CLUSTER_R4_STATE_FAIL_CLOSED, CLUSTER_R4_EVENT_DEATH, - CLUSTER_R4_STATE_FAIL_CLOSED, NONE, REQ, CLUSTER_R4_ACTION_DROP, "X/drop") + CLUSTER_R4_STATE_FAIL_CLOSED, NONE, REQ, CLUSTER_R4_ACTION_DROP, "X/drop") DEFINE_CELL_TEST(test_79_x_reconfig, CLUSTER_R4_STATE_FAIL_CLOSED, CLUSTER_R4_EVENT_RECONFIG, - CLUSTER_R4_STATE_FAIL_CLOSED, NONE, REQ, CLUSTER_R4_ACTION_DROP, "X/drop") + CLUSTER_R4_STATE_FAIL_CLOSED, NONE, REQ, CLUSTER_R4_ACTION_DROP, "X/drop") DEFINE_CELL_TEST(test_80_x_capacity, CLUSTER_R4_STATE_FAIL_CLOSED, CLUSTER_R4_EVENT_CAPACITY, - CLUSTER_R4_STATE_FAIL_CLOSED, NONE, REQ, CLUSTER_R4_ACTION_DROP, "X/drop") + CLUSTER_R4_STATE_FAIL_CLOSED, NONE, REQ, CLUSTER_R4_ACTION_DROP, "X/drop") DEFINE_CELL_TEST(test_81_x_malformed, CLUSTER_R4_STATE_FAIL_CLOSED, CLUSTER_R4_EVENT_MALFORMED, - CLUSTER_R4_STATE_FAIL_CLOSED, NONE, REQ, CLUSTER_R4_ACTION_DROP, "X/drop") + CLUSTER_R4_STATE_FAIL_CLOSED, NONE, REQ, CLUSTER_R4_ACTION_DROP, "X/drop") /* K — CANCELLED, absorbing. */ DEFINE_CELL_TEST(test_82_k_valid, CLUSTER_R4_STATE_CANCELLED, CLUSTER_R4_EVENT_VALID, - CLUSTER_R4_STATE_CANCELLED, NONE, REQ, CLUSTER_R4_ACTION_DROP, "K/drop") + CLUSTER_R4_STATE_CANCELLED, NONE, REQ, CLUSTER_R4_ACTION_DROP, "K/drop") DEFINE_CELL_TEST(test_83_k_duplicate, CLUSTER_R4_STATE_CANCELLED, CLUSTER_R4_EVENT_DUPLICATE, - CLUSTER_R4_STATE_CANCELLED, NONE, REQ, CLUSTER_R4_ACTION_DROP, "K/drop") + CLUSTER_R4_STATE_CANCELLED, NONE, REQ, CLUSTER_R4_ACTION_DROP, "K/drop") DEFINE_CELL_TEST(test_84_k_stale, CLUSTER_R4_STATE_CANCELLED, CLUSTER_R4_EVENT_STALE, - CLUSTER_R4_STATE_CANCELLED, NONE, REQ, CLUSTER_R4_ACTION_DROP, "K/drop") + CLUSTER_R4_STATE_CANCELLED, NONE, REQ, CLUSTER_R4_ACTION_DROP, "K/drop") DEFINE_CELL_TEST(test_85_k_timeout, CLUSTER_R4_STATE_CANCELLED, CLUSTER_R4_EVENT_TIMEOUT, - CLUSTER_R4_STATE_CANCELLED, NONE, REQ, CLUSTER_R4_ACTION_DROP, "K/drop") + CLUSTER_R4_STATE_CANCELLED, NONE, REQ, CLUSTER_R4_ACTION_DROP, "K/drop") DEFINE_CELL_TEST(test_86_k_cancel, CLUSTER_R4_STATE_CANCELLED, CLUSTER_R4_EVENT_CANCEL, - CLUSTER_R4_STATE_CANCELLED, NONE, REQ, CLUSTER_R4_ACTION_DROP, "K/drop") + CLUSTER_R4_STATE_CANCELLED, NONE, REQ, CLUSTER_R4_ACTION_DROP, "K/drop") DEFINE_CELL_TEST(test_87_k_death, CLUSTER_R4_STATE_CANCELLED, CLUSTER_R4_EVENT_DEATH, - CLUSTER_R4_STATE_CANCELLED, NONE, REQ, CLUSTER_R4_ACTION_DROP, "K/drop") + CLUSTER_R4_STATE_CANCELLED, NONE, REQ, CLUSTER_R4_ACTION_DROP, "K/drop") DEFINE_CELL_TEST(test_88_k_reconfig, CLUSTER_R4_STATE_CANCELLED, CLUSTER_R4_EVENT_RECONFIG, - CLUSTER_R4_STATE_CANCELLED, NONE, REQ, CLUSTER_R4_ACTION_DROP, "K/drop") + CLUSTER_R4_STATE_CANCELLED, NONE, REQ, CLUSTER_R4_ACTION_DROP, "K/drop") DEFINE_CELL_TEST(test_89_k_capacity, CLUSTER_R4_STATE_CANCELLED, CLUSTER_R4_EVENT_CAPACITY, - CLUSTER_R4_STATE_CANCELLED, NONE, REQ, CLUSTER_R4_ACTION_DROP, "K/drop") + CLUSTER_R4_STATE_CANCELLED, NONE, REQ, CLUSTER_R4_ACTION_DROP, "K/drop") DEFINE_CELL_TEST(test_90_k_malformed, CLUSTER_R4_STATE_CANCELLED, CLUSTER_R4_EVENT_MALFORMED, - CLUSTER_R4_STATE_CANCELLED, NONE, REQ, CLUSTER_R4_ACTION_DROP, "K/drop") + CLUSTER_R4_STATE_CANCELLED, NONE, REQ, CLUSTER_R4_ACTION_DROP, "K/drop") /* Physical LMS slot ABI: legacy ordinals stay fixed; R4 is append-only. */ UT_TEST(test_91_physical_lms_slot_abi) @@ -301,12 +309,9 @@ UT_TEST(test_91_physical_lms_slot_abi) UT_ASSERT_EQ((int)offsetof(ClusterLmsCrSlot, foreign_undo_page), (int)offsetof(ClusterLmsCrSlot, r4) + 256); UT_ASSERT_EQ((int)sizeof(((ClusterLmsCrSlot *)0)->foreign_undo_page), BLCKSZ); - UT_ASSERT_EQ((int)sizeof(ClusterLmsCrSlot), - (int)offsetof(ClusterLmsCrSlot, r4) + 256 + BLCKSZ); + UT_ASSERT_EQ((int)sizeof(ClusterLmsCrSlot), (int)offsetof(ClusterLmsCrSlot, r4) + 256 + BLCKSZ); UT_ASSERT_EQ((int)(sizeof(ClusterR4CrSlotExtension) + BLCKSZ), 8448); - UT_ASSERT_EQ((int)(CLUSTER_LMS_CR_SLOTS - * (sizeof(ClusterR4CrSlotExtension) + BLCKSZ)), - 33792); + UT_ASSERT_EQ((int)(CLUSTER_LMS_CR_SLOTS * (sizeof(ClusterR4CrSlotExtension) + BLCKSZ)), 33792); } /* D4-B exact append-only LMS incarnation/drain control ABI. */ @@ -320,8 +325,7 @@ UT_TEST(test_92_physical_lms_r4_control_abi) UT_ASSERT_EQ((int)offsetof(ClusterLmsSharedState, r4_controls), (int)sizeof(ClusterLmsSharedState) - 80); - UT_ASSERT_EQ((int)(CLUSTER_LMS_CR_SLOTS - * (sizeof(ClusterR4CrSlotExtension) + BLCKSZ) + UT_ASSERT_EQ((int)(CLUSTER_LMS_CR_SLOTS * (sizeof(ClusterR4CrSlotExtension) + BLCKSZ) + sizeof(ClusterLmsR4Controls)), 33872); } diff --git a/src/test/cluster_unit/test_cluster_r4_slot_reservation.c b/src/test/cluster_unit/test_cluster_r4_slot_reservation.c index dad71599405..ae1deb19594 100644 --- a/src/test/cluster_unit/test_cluster_r4_slot_reservation.c +++ b/src/test/cluster_unit/test_cluster_r4_slot_reservation.c @@ -39,31 +39,30 @@ UT_DEFINE_GLOBALS(); extern bool cluster_cr_server_test_reserve_legacy_slot(ClusterLmsCrSlot *slot, - uint32 reserved_state); + uint32 reserved_state); /* Expected USE_CLUSTER_UNIT claim-only seams. They expose no builder step. */ extern bool cluster_cr_server_test_r4_claim_queued(uint32 slot_index); extern bool cluster_cr_server_test_r4_build_step(uint32 slot_index); extern bool cluster_cr_server_test_r4_send_foreign_undo(uint32 slot_index); -extern bool cluster_cr_server_r4_land_foreign_undo( - const ClusterICEnvelope *env, const GcsBlockReplyHeader *header, - const char undo_page[BLCKSZ], const ClusterGcsUndoAuthTrailer *undo_auth); -extern bool cluster_cr_server_test_r4_freeze_foreign_generation( - uint32 slot_index, uint32 physical_generation); +extern bool cluster_cr_server_r4_land_foreign_undo(const ClusterICEnvelope *env, + const GcsBlockReplyHeader *header, + const char undo_page[BLCKSZ], + const ClusterGcsUndoAuthTrailer *undo_auth); +extern bool cluster_cr_server_test_r4_freeze_foreign_generation(uint32 slot_index, + uint32 physical_generation); extern bool cluster_cr_server_test_r4_ship_terminal(uint32 slot_index); extern void cluster_cr_server_test_r4_reset_contexts(void); -extern bool cluster_cr_server_test_r4_context_matches( - uint32 slot_index, bool expect_present, uint64 slot_generation, - uint64 builder_incarnation, const ClusterSemanticAdmissionToken *admission); +extern bool +cluster_cr_server_test_r4_context_matches(uint32 slot_index, bool expect_present, + uint64 slot_generation, uint64 builder_incarnation, + const ClusterSemanticAdmissionToken *admission); extern bool cluster_cr_server_r4_worker0_drained(void); -extern bool cluster_cr_server_r4_lmon_reclaim_closed(uint64 worker_incarnation, - uint64 generation); +extern bool cluster_cr_server_r4_lmon_reclaim_closed(uint64 worker_incarnation, uint64 generation); extern void cluster_lms_data_plane_close_peer_now(int32 peer_id); -extern void cluster_lms_data_plane_test_seed_peer(int32 peer_id, int fd, - bool connected, bool enabled, - bool wes_dirty); -extern bool cluster_lms_data_plane_test_peer_snapshot(int32 peer_id, - int *fd_out, bool *down_out, - bool *wes_dirty_out); +extern void cluster_lms_data_plane_test_seed_peer(int32 peer_id, int fd, bool connected, + bool enabled, bool wes_dirty); +extern bool cluster_lms_data_plane_test_peer_snapshot(int32 peer_id, int *fd_out, bool *down_out, + bool *wes_dirty_out); #define UT_FORMATION_EPOCH UINT64_C(9) #define UT_ACTIVATION_GENERATION UINT64_C(12) @@ -89,10 +88,9 @@ extern bool cluster_lms_data_plane_test_peer_snapshot(int32 peer_id, #define UT_FOREIGN_LIVE_HWM ((XLogRecPtr)UINT64_C(0x4000)) #define UT_FOREIGN_TT_GENERATION UINT64_C(3) #define UT_FOREIGN_AUTHORITY_SCN ((SCN)(UT_READ_SCN + 1)) -#define UT_R4_REQUIRED_CAPABILITIES \ - (PGRAC_IC_HELLO_CAP_SEMANTIC_ACTIVATION_V1 | PGRAC_IC_HELLO_CAP_R4_SYNC_CR_V1 \ - | PGRAC_IC_HELLO_CAP_CANDIDATE2_CORRECTED_A1_V1 \ - | PGRAC_IC_HELLO_CAP_UNDO_ROOT_DESCRIPTOR_V1) +#define UT_R4_REQUIRED_CAPABILITIES \ + (PGRAC_IC_HELLO_CAP_SEMANTIC_ACTIVATION_V1 | PGRAC_IC_HELLO_CAP_R4_SYNC_CR_V1 \ + | PGRAC_IC_HELLO_CAP_CANDIDATE2_CORRECTED_A1_V1 | PGRAC_IC_HELLO_CAP_UNDO_ROOT_DESCRIPTOR_V1) typedef struct UtClusterCrServerShared { pg_atomic_uint64 lms_latch_ptr; @@ -388,10 +386,10 @@ errfinish(const char *file pg_attribute_unused(), int line pg_attribute_unused() } bool -cluster_cr_r4_extract_resident_record( - const char resident_undo_page[BLCKSZ], - const ClusterTxLocator *request_locator, char record_out[BLCKSZ], - size_t *record_length_out, ClusterTxLocator *canonical_locator_out) +cluster_cr_r4_extract_resident_record(const char resident_undo_page[BLCKSZ], + const ClusterTxLocator *request_locator, + char record_out[BLCKSZ], size_t *record_length_out, + ClusterTxLocator *canonical_locator_out) { ut_extract_calls++; if (ut_real_builder) @@ -402,8 +400,8 @@ cluster_cr_r4_extract_resident_record( if (request_locator != NULL) ut_extract_locator = *request_locator; if (!ut_extract_ok || resident_undo_page == NULL || resident_undo_page[0] != (char)0xa5 - || request_locator == NULL || record_out == NULL - || record_length_out == NULL || canonical_locator_out == NULL) + || request_locator == NULL || record_out == NULL || record_length_out == NULL + || canonical_locator_out == NULL) return false; memset(record_out, 0x6b, sizeof(UndoRecordHeader)); *record_length_out = sizeof(UndoRecordHeader); @@ -413,10 +411,8 @@ cluster_cr_r4_extract_resident_record( } ClusterR4CrBuildStepResult -cluster_cr_build_on_holder_step(uint32 slot_index, uint64 slot_generation, - bool foreign_undo_ready, - ClusterR4CrSlotExtension *extension, - char result_page[BLCKSZ], +cluster_cr_build_on_holder_step(uint32 slot_index, uint64 slot_generation, bool foreign_undo_ready, + ClusterR4CrSlotExtension *extension, char result_page[BLCKSZ], const char foreign_undo_page[BLCKSZ], ClusterCrBuildReason *reason_out) { @@ -429,8 +425,7 @@ cluster_cr_build_on_holder_step(uint32 slot_index, uint64 slot_generation, ut_builder_extension = extension; ut_builder_result_page = result_page; ut_builder_foreign_page = foreign_undo_page; - ut_state_at_builder_step - = pg_atomic_read_u32(&ut_cr_server_shared.slots[slot_index].state); + ut_state_at_builder_step = pg_atomic_read_u32(&ut_cr_server_shared.slots[slot_index].state); if (ut_real_builder) return continuation_real_step(slot_index, slot_generation, foreign_undo_ready, extension, result_page, foreign_undo_page, reason_out); @@ -482,17 +477,15 @@ cluster_cr_build_on_holder_forget(uint32 slot_index, uint64 slot_generation) } bool -cluster_cr_build_on_holder_pending_locator(uint32 slot_index, - uint64 slot_generation, - ClusterTxLocator *locator_out) +cluster_cr_build_on_holder_pending_locator(uint32 slot_index, uint64 slot_generation, + ClusterTxLocator *locator_out) { if (ut_real_builder) return continuation_real_pending(slot_index, slot_generation, locator_out); ut_pending_locator_calls++; ut_pending_locator_slot_index = slot_index; ut_pending_locator_slot_generation = slot_generation; - ut_state_at_pending_locator - = pg_atomic_read_u32(&ut_cr_server_shared.slots[slot_index].state); + ut_state_at_pending_locator = pg_atomic_read_u32(&ut_cr_server_shared.slots[slot_index].state); if (locator_out != NULL) memset(locator_out, 0, sizeof(*locator_out)); if (!ut_pending_locator_ok || locator_out == NULL) @@ -502,14 +495,13 @@ cluster_cr_build_on_holder_pending_locator(uint32 slot_index, } bool -cluster_semantic_activation_resolve_shared_undo_root( - const ClusterSemanticAdmissionToken *token, ClusterUndoPathIntent intent, - uint32 owner_instance, uint32 segment_id, - ClusterUndoBlock0ResolvedRoot *out) +cluster_semantic_activation_resolve_shared_undo_root(const ClusterSemanticAdmissionToken *token, + ClusterUndoPathIntent intent, + uint32 owner_instance, uint32 segment_id, + ClusterUndoBlock0ResolvedRoot *out) { ut_pgrd_resolve_calls++; - memset(&ut_pgrd_resolve_admission, 0, - sizeof(ut_pgrd_resolve_admission)); + memset(&ut_pgrd_resolve_admission, 0, sizeof(ut_pgrd_resolve_admission)); if (token != NULL) ut_pgrd_resolve_admission = *token; ut_pgrd_resolve_intent = intent; @@ -522,10 +514,10 @@ cluster_semantic_activation_resolve_shared_undo_root( } ClusterUndoBlock0CurrentStep -cluster_undo_block0_current_acquire_begin( - const ClusterUndoBlock0LogicalKey *key, ClusterUndoBlock0CurrentMode mode, - int timeout_ms, ClusterUndoBlock0CurrentGuard *guard, - ClusterUndoBlock0Result *failure) +cluster_undo_block0_current_acquire_begin(const ClusterUndoBlock0LogicalKey *key, + ClusterUndoBlock0CurrentMode mode, int timeout_ms, + ClusterUndoBlock0CurrentGuard *guard, + ClusterUndoBlock0Result *failure) { ut_current_acquire_calls++; memset(&ut_current_logical, 0, sizeof(ut_current_logical)); @@ -542,8 +534,8 @@ cluster_undo_block0_current_acquire_begin( } ClusterUndoBlock0CurrentStep -cluster_undo_block0_current_acquire_poll( - ClusterUndoBlock0CurrentGuard *guard, ClusterUndoBlock0Result *failure) +cluster_undo_block0_current_acquire_poll(ClusterUndoBlock0CurrentGuard *guard, + ClusterUndoBlock0Result *failure) { ut_current_acquire_poll_calls++; UT_ASSERT_NOT_NULL(guard); @@ -555,18 +547,16 @@ cluster_undo_block0_current_acquire_poll( } ClusterUndoBlock0Result -cluster_undo_block0_current_sample_generation( - ClusterUndoBlock0CurrentGuard *guard, - const ClusterUndoBlock0ResolvedRoot *root, - ClusterUndoBlock0Generation *observed) +cluster_undo_block0_current_sample_generation(ClusterUndoBlock0CurrentGuard *guard, + const ClusterUndoBlock0ResolvedRoot *root, + ClusterUndoBlock0Generation *observed) { ut_current_sample_calls++; UT_ASSERT_NOT_NULL(guard); memset(&ut_current_sample_root, 0, sizeof(ut_current_sample_root)); if (root != NULL) ut_current_sample_root = *root; - if (ut_current_sample_result == CLUSTER_UNDO_BLOCK0_OK - && observed != NULL) { + if (ut_current_sample_result == CLUSTER_UNDO_BLOCK0_OK && observed != NULL) { observed->known = true; observed->value = ut_current_sample_generation; } @@ -574,8 +564,8 @@ cluster_undo_block0_current_sample_generation( } ClusterUndoBlock0CurrentStep -cluster_undo_block0_current_release_begin( - ClusterUndoBlock0CurrentGuard *guard, ClusterUndoBlock0Result *failure) +cluster_undo_block0_current_release_begin(ClusterUndoBlock0CurrentGuard *guard, + ClusterUndoBlock0Result *failure) { ut_current_release_calls++; UT_ASSERT_NOT_NULL(guard); @@ -587,8 +577,8 @@ cluster_undo_block0_current_release_begin( } ClusterUndoBlock0CurrentStep -cluster_undo_block0_current_release_poll( - ClusterUndoBlock0CurrentGuard *guard, ClusterUndoBlock0Result *failure) +cluster_undo_block0_current_release_poll(ClusterUndoBlock0CurrentGuard *guard, + ClusterUndoBlock0Result *failure) { ut_current_release_poll_calls++; UT_ASSERT_NOT_NULL(guard); @@ -607,8 +597,7 @@ cluster_undo_block0_current_cancel(ClusterUndoBlock0CurrentGuard *guard) } void -cluster_gcs_block_note_send_outcome(GcsBlockSendFamily family, - ClusterICSendResult rc) +cluster_gcs_block_note_send_outcome(GcsBlockSendFamily family, ClusterICSendResult rc) { ut_note_send_calls++; ut_note_send_family = family; @@ -642,8 +631,8 @@ cluster_gcs_block_compute_checksum(const char *block_data) } ClusterICSendResult -cluster_ic_send_envelope(uint8 msg_type, int32 dest_node_id, - const void *payload, uint32 payload_len) +cluster_ic_send_envelope(uint8 msg_type, int32 dest_node_id, const void *payload, + uint32 payload_len) { ut_send_calls++; ut_state_at_send = pg_atomic_read_u32(&ut_cr_server_shared.slots[0].state); @@ -657,9 +646,8 @@ cluster_ic_send_envelope(uint8 msg_type, int32 dest_node_id, } bool -cluster_ic_envelope_build(ClusterICEnvelope *out_env, uint8 msg_type, - uint32 source_node_id, uint32 dest_node_id, - const void *payload, uint32 payload_length) +cluster_ic_envelope_build(ClusterICEnvelope *out_env, uint8 msg_type, uint32 source_node_id, + uint32 dest_node_id, const void *payload, uint32 payload_length) { ut_envelope_build_calls++; ut_envelope_build_sequence = ++ut_sequence; @@ -678,26 +666,23 @@ cluster_ic_envelope_build(ClusterICEnvelope *out_env, uint8 msg_type, } bool -cluster_ic_dispatch_envelope(const ClusterICEnvelope *env, const void *payload, - int32 peer_id) +cluster_ic_dispatch_envelope(const ClusterICEnvelope *env, const void *payload, int32 peer_id) { ut_local_dispatch_calls++; ut_local_dispatch_sequence = ++ut_sequence; ut_local_dispatch_peer = peer_id; - ut_state_at_local_dispatch - = pg_atomic_read_u32(&ut_cr_server_shared.slots[0].state); + ut_state_at_local_dispatch = pg_atomic_read_u32(&ut_cr_server_shared.slots[0].state); UT_ASSERT_NOT_NULL(env); UT_ASSERT_NOT_NULL(payload); UT_ASSERT(env == NULL || env->payload_length <= sizeof(ut_local_dispatch_payload)); - if (env != NULL && payload != NULL - && env->payload_length <= sizeof(ut_local_dispatch_payload)) + if (env != NULL && payload != NULL && env->payload_length <= sizeof(ut_local_dispatch_payload)) memcpy(ut_local_dispatch_payload, payload, env->payload_length); return ut_local_dispatch_ok; } void cluster_ic_tier1_request_close_peer(int32 peer_id pg_attribute_unused(), - const char *reason pg_attribute_unused()) + const char *reason pg_attribute_unused()) { ut_close_peer_calls++; } @@ -751,9 +736,9 @@ SetLatch(Latch *latch) } bool -cluster_bufmgr_copy_block_for_r4_cr(BufferTag tag, SCN expected_page_scn, - XLogRecPtr *page_lsn_out, SCN *page_scn_out, - char *dst, ClusterBufmgrGcsCopyRefusal *refusal_out) +cluster_bufmgr_copy_block_for_r4_cr(BufferTag tag, SCN expected_page_scn, XLogRecPtr *page_lsn_out, + SCN *page_scn_out, char *dst, + ClusterBufmgrGcsCopyRefusal *refusal_out) { ut_copy_calls++; ut_copy_sequence = ++ut_sequence; @@ -807,9 +792,9 @@ cluster_semantic_activation_recheck(const ClusterSemanticAdmissionToken *token) bool cluster_semantic_activation_peer_open_matches(const ClusterSemanticAdmissionToken *token, - int32 authenticated_peer_node_id, - uint32 required_hello_caps, - uint32 sampled_capability_generation) + int32 authenticated_peer_node_id, + uint32 required_hello_caps, + uint32 sampled_capability_generation) { int slot = ut_peer_open_calls++; @@ -818,8 +803,7 @@ cluster_semantic_activation_peer_open_matches(const ClusterSemanticAdmissionToke ut_peer_open_required[slot] = required_hello_caps; ut_peer_open_generations[slot] = sampled_capability_generation; ut_peer_open_sequence[slot] = ++ut_sequence; - ut_state_at_peer_open[slot] - = pg_atomic_read_u32(&ut_cr_server_shared.slots[0].state); + ut_state_at_peer_open[slot] = pg_atomic_read_u32(&ut_cr_server_shared.slots[0].state); } return ut_peer_open_ok && token != NULL && memcmp(token, &ut_expected_admission, sizeof(*token)) == 0 @@ -841,9 +825,8 @@ cluster_semantic_activation_leave(ClusterSemanticAdmissionToken *token) bool LWLockAcquire(LWLock *lock, LWLockMode mode) { - if (ut_reclaim_race_on_proof && !ut_reclaim_race_injected - && ut_lms_state != NULL && lock == &ut_lms_state->lwlock - && mode == LW_EXCLUSIVE) { + if (ut_reclaim_race_on_proof && !ut_reclaim_race_injected && ut_lms_state != NULL + && lock == &ut_lms_state->lwlock && mode == LW_EXCLUSIVE) { ut_lms_state->r4_controls.data_worker_incarnation[0]++; ut_reclaim_race_injected = true; } @@ -916,12 +899,10 @@ submit_test_tag(void) static ClusterR4CrForwardPayload submit_test_forward96(void) { - static const uint8 extension_bytes[32] = { - 0x01, 0x01, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, - 0x09, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x22, 0x22, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - }; + static const uint8 extension_bytes[32] + = { 0x01, 0x01, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, + 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x22, 0x22, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; ClusterR4CrForwardPayload forward; memset(&forward, 0, sizeof(forward)); @@ -1045,8 +1026,7 @@ reset_submit_fixture(ClusterLmsSharedState *state) ut_pending_locator.itl_slot_index = 0; ut_pgrd_resolve_ok = true; ut_pgrd_resolve_calls = 0; - memset(&ut_pgrd_resolve_admission, 0, - sizeof(ut_pgrd_resolve_admission)); + memset(&ut_pgrd_resolve_admission, 0, sizeof(ut_pgrd_resolve_admission)); ut_pgrd_resolve_intent = CLUSTER_UNDO_PATH_MATERIALIZED_LOCAL; ut_pgrd_resolve_owner_instance = 0; ut_pgrd_resolve_segment_id = 0; @@ -1162,8 +1142,7 @@ peer_recheck_seen(int32 peer, uint32 generation) int i; for (i = 0; i < ut_peer_open_calls && i < lengthof(ut_peer_open_peers); i++) { - if (ut_peer_open_peers[i] == peer - && ut_peer_open_generations[i] == generation + if (ut_peer_open_peers[i] == peer && ut_peer_open_generations[i] == generation && ut_peer_open_required[i] == UT_R4_REQUIRED_CAPABILITIES) return true; } @@ -1182,8 +1161,7 @@ slot_is_canonical_free_with_generation(const ClusterLmsCrSlot *slot, uint64 gene } static void -prepare_reclaimable_r4_slot(ClusterLmsCrSlot *slot, uint32 state, - uint64 generation, int worker_id) +prepare_reclaimable_r4_slot(ClusterLmsCrSlot *slot, uint32 state, uint64 generation, int worker_id) { memset(slot, 0, sizeof(*slot)); pg_atomic_init_u32(&slot->state, state); @@ -1191,15 +1169,13 @@ prepare_reclaimable_r4_slot(ClusterLmsCrSlot *slot, uint32 state, slot->r4.owner.edge_owner_incarnation = UINT64_C(41) + (uint64)worker_id; slot->r4.owner.edge_owner_pid = 7000 + worker_id; slot->r4.owner.edge_owner_worker_id = (uint8)worker_id; - slot->r4.owner.edge_owner_role - = (uint8)(worker_id == 0 ? B_LMS : B_LMS_WORKER); + slot->r4.owner.edge_owner_role = (uint8)(worker_id == 0 ? B_LMS : B_LMS_WORKER); if (state != CLUSTER_LMS_CR_FILLING) slot->req_kind = (uint8)CLUSTER_LMS_SLOT_KIND_R4_CR_BUILD; } static void -prepare_exact_drain_ack(ClusterLmsSharedState *state, - uint64 worker_incarnation, uint64 generation) +prepare_exact_drain_ack(ClusterLmsSharedState *state, uint64 worker_incarnation, uint64 generation) { state->r4_controls.data_worker_incarnation[0] = worker_incarnation; state->r4_controls.drain_request_generation = generation; @@ -1215,9 +1191,8 @@ prepare_worker0_claim(ClusterLmsSharedState *state) ClusterCrBuildResult result; reset_submit_fixture(state); - result = cluster_lms_cr_submit_r4( - &forward, &admission, UT_REQUESTER_CAPABILITY_GENERATION, - UT_MASTER_CAPABILITY_GENERATION, &reason); + result = cluster_lms_cr_submit_r4(&forward, &admission, UT_REQUESTER_CAPABILITY_GENERATION, + UT_MASTER_CAPABILITY_GENERATION, &reason); UT_ASSERT_EQ(result, CLUSTER_CR_BUILD_FULL); UT_ASSERT_EQ(reason, CLUSTER_CR_BUILD_NONE); @@ -1263,25 +1238,22 @@ prepare_worker0_need_undo(ClusterLmsSharedState *state) } static ClusterLmsCrSlot * -prepare_worker0_need_undo_frozen(ClusterLmsSharedState *state, - uint32 physical_generation) +prepare_worker0_need_undo_frozen(ClusterLmsSharedState *state, uint32 physical_generation) { ClusterLmsCrSlot *slot = prepare_worker0_need_undo(state); - UT_ASSERT(cluster_cr_server_test_r4_freeze_foreign_generation( - 0, physical_generation)); + UT_ASSERT(cluster_cr_server_test_r4_freeze_foreign_generation(0, physical_generation)); return slot; } static ClusterLmsCrSlot * prepare_worker0_undo_inflight(ClusterLmsSharedState *state) { - ClusterLmsCrSlot *slot = prepare_worker0_need_undo_frozen( - state, UT_FOREIGN_PHYSICAL_GENERATION); + ClusterLmsCrSlot *slot + = prepare_worker0_need_undo_frozen(state, UT_FOREIGN_PHYSICAL_GENERATION); UT_ASSERT(cluster_cr_server_test_r4_send_foreign_undo(0)); - UT_ASSERT_EQ(pg_atomic_read_u32(&slot->state), - CLUSTER_LMS_CR_R4_UNDO_INFLIGHT); + UT_ASSERT_EQ(pg_atomic_read_u32(&slot->state), CLUSTER_LMS_CR_R4_UNDO_INFLIGHT); /* Measure the receive-side short TARGET episode independently from the * retained builder episode that prepare_worker0_need_undo() entered. */ @@ -1299,8 +1271,7 @@ prepare_worker0_undo_inflight(ClusterLmsSharedState *state) } static void -make_foreign_undo_reply(GcsBlockReplyHeader *header, - ClusterGcsUndoAuthTrailer *auth, +make_foreign_undo_reply(GcsBlockReplyHeader *header, ClusterGcsUndoAuthTrailer *auth, ClusterICEnvelope *env, char page[BLCKSZ]) { memset(header, 0, sizeof(*header)); @@ -1312,10 +1283,8 @@ make_foreign_undo_reply(GcsBlockReplyHeader *header, header->requester_backend_id = CLUSTER_GCS_BLOCK_R4_INTERNAL_ENDPOINT; header->transition_id = (uint8)PCM_TRANS_N_TO_S; header->status = (uint8)GCS_BLOCK_REPLY_R4_UNDO_DATA_RESULT; - GcsBlockReplyHeaderSetForwardingMasterNode( - header, GCS_BLOCK_REPLY_NO_FORWARDING_MASTER); - UT_ASSERT(GcsBlockReplyHeaderSetR4UndoGeneration( - header, UT_FOREIGN_PHYSICAL_GENERATION)); + GcsBlockReplyHeaderSetForwardingMasterNode(header, GCS_BLOCK_REPLY_NO_FORWARDING_MASTER); + UT_ASSERT(GcsBlockReplyHeaderSetR4UndoGeneration(header, UT_FOREIGN_PHYSICAL_GENERATION)); memset(page, 0, BLCKSZ); page[0] = (char)0xa5; @@ -1334,14 +1303,11 @@ make_foreign_undo_reply(GcsBlockReplyHeader *header, static void assert_exact_foreign_undo_forward96(void) { - static const uint8 extension_bytes[32] = { - 0x01, 0x04, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, - 0x09, 0x00, 0x00, 0x00, 0x03, 0x00, 0x06, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x1d, 0x03, 0x00, 0x00, - 0x07, 0x00, 0x01, 0x00, 0x04, 0x03, 0x02, 0x01 - }; - const ClusterR4CrForwardPayload *forward - = (const ClusterR4CrForwardPayload *)ut_send_payload; + static const uint8 extension_bytes[32] + = { 0x01, 0x04, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x09, 0x00, 0x00, + 0x00, 0x03, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1d, 0x03, + 0x00, 0x00, 0x07, 0x00, 0x01, 0x00, 0x04, 0x03, 0x02, 0x01 }; + const ClusterR4CrForwardPayload *forward = (const ClusterR4CrForwardPayload *)ut_send_payload; UT_ASSERT_EQ(ut_send_msg_type, PGRAC_IC_MSG_GCS_BLOCK_FORWARD); UT_ASSERT_EQ(ut_send_dest, 1); @@ -1357,12 +1323,10 @@ assert_exact_foreign_undo_forward96(void) UT_ASSERT_EQ(forward->base.requester_backend_id, -2); UT_ASSERT_EQ(forward->base.master_node, UT_HOLDER_NODE); UT_ASSERT_EQ(forward->base.transition_id, PCM_TRANS_N_TO_S); - UT_ASSERT_EQ(GcsBlockForwardPayloadGetExpectedPiWatermarkScn(&forward->base), - UT_READ_SCN); + UT_ASSERT_EQ(GcsBlockForwardPayloadGetExpectedPiWatermarkScn(&forward->base), UT_READ_SCN); UT_ASSERT(bytes_are(forward->base.reserved_0, 6, 0)); UT_ASSERT_EQ(forward->base.reserved_0[6], CLUSTER_R4_FORWARD_EXTENDED); - UT_ASSERT_EQ(memcmp(&forward->extension, extension_bytes, - sizeof(extension_bytes)), 0); + UT_ASSERT_EQ(memcmp(&forward->extension, extension_bytes, sizeof(extension_bytes)), 0); } UT_TEST(test_free_to_pending_canonicalizes_owner_under_lms_lock) @@ -1449,9 +1413,8 @@ UT_TEST(test_r4_submit_publishes_complete_stable_copy_once) reset_submit_fixture(&state); slot = &ut_cr_server_shared.slots[0]; - result = cluster_lms_cr_submit_r4( - &forward, &admission, UT_REQUESTER_CAPABILITY_GENERATION, - UT_MASTER_CAPABILITY_GENERATION, &reason); + result = cluster_lms_cr_submit_r4(&forward, &admission, UT_REQUESTER_CAPABILITY_GENERATION, + UT_MASTER_CAPABILITY_GENERATION, &reason); UT_ASSERT_EQ(result, CLUSTER_CR_BUILD_FULL); UT_ASSERT_EQ(reason, CLUSTER_CR_BUILD_NONE); @@ -1462,16 +1425,15 @@ UT_TEST(test_r4_submit_publishes_complete_stable_copy_once) UT_ASSERT_EQ(ut_lock_mode, LW_EXCLUSIVE); UT_ASSERT_EQ(ut_state_at_lock_release, CLUSTER_LMS_CR_FILLING); UT_ASSERT_EQ(ut_generation_at_lock_release, 1); - UT_ASSERT_EQ(ut_owner_at_lock_release.edge_owner_incarnation, - UT_WORKER_INCARNATION); + UT_ASSERT_EQ(ut_owner_at_lock_release.edge_owner_incarnation, UT_WORKER_INCARNATION); UT_ASSERT_EQ(ut_owner_at_lock_release.edge_owner_pid, MyProcPid); UT_ASSERT_EQ(ut_owner_at_lock_release.edge_owner_worker_id, UT_WORKER_ID); UT_ASSERT(ut_owner_at_lock_release.edge_owner_role != 0); UT_ASSERT_EQ(ut_owner_at_lock_release.builder_incarnation, 0); UT_ASSERT_EQ(ut_owner_at_lock_release.builder_pid, 0); UT_ASSERT_EQ(ut_owner_at_lock_release.builder_worker_id, 0); - UT_ASSERT(bytes_are(ut_owner_at_lock_release.reserved, - sizeof(ut_owner_at_lock_release.reserved), 0)); + UT_ASSERT( + bytes_are(ut_owner_at_lock_release.reserved, sizeof(ut_owner_at_lock_release.reserved), 0)); UT_ASSERT_EQ(pg_atomic_read_u32(&slot->state), CLUSTER_LMS_CR_R4_QUEUED); UT_ASSERT_EQ(slot->r4.slot_generation, 1); @@ -1484,23 +1446,17 @@ UT_TEST(test_r4_submit_publishes_complete_stable_copy_once) UT_ASSERT_EQ(slot->requester_backend, UT_REQUESTER_BACKEND); UT_ASSERT_EQ(slot->reply_master_node, UT_MASTER_NODE); UT_ASSERT_EQ(slot->transition_id, PCM_TRANS_N_TO_S); - UT_ASSERT_EQ(memcmp(&slot->r4.route_proof.tag, &forward.base.tag, - sizeof(BufferTag)), 0); + UT_ASSERT_EQ(memcmp(&slot->r4.route_proof.tag, &forward.base.tag, sizeof(BufferTag)), 0); UT_ASSERT_EQ(slot->r4.route_proof.read_scn, UT_READ_SCN); UT_ASSERT_EQ(slot->r4.route_proof.formation_epoch, UT_FORMATION_EPOCH); - UT_ASSERT_EQ(slot->r4.route_proof.activation_generation, - UT_ACTIVATION_GENERATION); - UT_ASSERT_EQ(slot->r4.route_proof.master_authority_generation, - UT_MASTER_GENERATION); - UT_ASSERT_EQ(slot->r4.route_proof.master_resource_transition_count, - UT_MASTER_TRANSITION); + UT_ASSERT_EQ(slot->r4.route_proof.activation_generation, UT_ACTIVATION_GENERATION); + UT_ASSERT_EQ(slot->r4.route_proof.master_authority_generation, UT_MASTER_GENERATION); + UT_ASSERT_EQ(slot->r4.route_proof.master_resource_transition_count, UT_MASTER_TRANSITION); UT_ASSERT_EQ(slot->r4.route_proof.expected_page_scn, UT_EXPECTED_PAGE_SCN); UT_ASSERT_EQ(slot->r4.route_proof.real_master_node, UT_MASTER_NODE); UT_ASSERT_EQ(slot->r4.route_proof.selected_holder_node, UT_HOLDER_NODE); - UT_ASSERT_EQ(slot->r4.requester_capability_generation, - UT_REQUESTER_CAPABILITY_GENERATION); - UT_ASSERT_EQ(slot->r4.master_capability_generation, - UT_MASTER_CAPABILITY_GENERATION); + UT_ASSERT_EQ(slot->r4.requester_capability_generation, UT_REQUESTER_CAPABILITY_GENERATION); + UT_ASSERT_EQ(slot->r4.master_capability_generation, UT_MASTER_CAPABILITY_GENERATION); UT_ASSERT_EQ(slot->r4.foreign_request_id, 0); UT_ASSERT_EQ(slot->r4.origin_formation_epoch, 0); UT_ASSERT_EQ(slot->r4.origin_live_hwm_lsn, 0); @@ -1512,8 +1468,7 @@ UT_TEST(test_r4_submit_publishes_complete_stable_copy_once) UT_ASSERT_EQ(slot->r4.owner.builder_incarnation, 0); UT_ASSERT_EQ(slot->r4.owner.builder_pid, 0); UT_ASSERT_EQ(slot->r4.owner.builder_worker_id, 0); - UT_ASSERT(bytes_are(slot->r4.owner.reserved, - sizeof(slot->r4.owner.reserved), 0)); + UT_ASSERT(bytes_are(slot->r4.owner.reserved, sizeof(slot->r4.owner.reserved), 0)); UT_ASSERT_EQ(ut_copy_calls, 1); UT_ASSERT_EQ(memcmp(&ut_copy_tag, &forward.base.tag, sizeof(BufferTag)), 0); @@ -1525,8 +1480,7 @@ UT_TEST(test_r4_submit_publishes_complete_stable_copy_once) UT_ASSERT_EQ(ut_recheck_calls, 1); UT_ASSERT_EQ(ut_peer_open_calls, 2); UT_ASSERT(peer_recheck_seen(UT_MASTER_NODE, UT_MASTER_CAPABILITY_GENERATION)); - UT_ASSERT(peer_recheck_seen(UT_REQUESTER_NODE, - UT_REQUESTER_CAPABILITY_GENERATION)); + UT_ASSERT(peer_recheck_seen(UT_REQUESTER_NODE, UT_REQUESTER_CAPABILITY_GENERATION)); UT_ASSERT_EQ(ut_wake_calls, 1); UT_ASSERT(ut_lock_release_sequence < ut_copy_sequence); UT_ASSERT(ut_copy_sequence < ut_recheck_sequence); @@ -1536,8 +1490,7 @@ UT_TEST(test_r4_submit_publishes_complete_stable_copy_once) UT_ASSERT(ut_peer_open_sequence[i] < ut_wake_sequence); } for (i = 1; i < CLUSTER_LMS_CR_SLOTS; i++) { - UT_ASSERT_EQ(pg_atomic_read_u32(&ut_cr_server_shared.slots[i].state), - CLUSTER_LMS_CR_FREE); + UT_ASSERT_EQ(pg_atomic_read_u32(&ut_cr_server_shared.slots[i].state), CLUSTER_LMS_CR_FREE); UT_ASSERT_EQ(ut_cr_server_shared.slots[i].r4.slot_generation, 0); } } @@ -1562,9 +1515,8 @@ UT_TEST(test_r4_all_local_submit_uses_exact_token_generation_without_peer_matche admission_before = admission; slot = &ut_cr_server_shared.slots[0]; - result = cluster_lms_cr_submit_r4( - &forward, &admission, (uint32)admission.record_generation, - (uint32)admission.record_generation, &reason); + result = cluster_lms_cr_submit_r4(&forward, &admission, (uint32)admission.record_generation, + (uint32)admission.record_generation, &reason); UT_ASSERT_EQ(result, CLUSTER_CR_BUILD_FULL); UT_ASSERT_EQ(reason, CLUSTER_CR_BUILD_NONE); @@ -1578,12 +1530,9 @@ UT_TEST(test_r4_all_local_submit_uses_exact_token_generation_without_peer_matche UT_ASSERT_EQ(slot->reply_master_node, UT_HOLDER_NODE); UT_ASSERT_EQ(slot->r4.route_proof.real_master_node, UT_HOLDER_NODE); UT_ASSERT_EQ(slot->r4.route_proof.selected_holder_node, UT_HOLDER_NODE); - UT_ASSERT_EQ(slot->r4.route_proof.activation_generation, - admission.record_generation); - UT_ASSERT_EQ((uint64)slot->r4.requester_capability_generation, - admission.record_generation); - UT_ASSERT_EQ((uint64)slot->r4.master_capability_generation, - admission.record_generation); + UT_ASSERT_EQ(slot->r4.route_proof.activation_generation, admission.record_generation); + UT_ASSERT_EQ((uint64)slot->r4.requester_capability_generation, admission.record_generation); + UT_ASSERT_EQ((uint64)slot->r4.master_capability_generation, admission.record_generation); UT_ASSERT_EQ(ut_copy_calls, 1); UT_ASSERT_EQ(ut_recheck_calls, 1); UT_ASSERT_EQ(ut_state_at_recheck, CLUSTER_LMS_CR_FILLING); @@ -1617,9 +1566,8 @@ UT_TEST(test_r4_all_local_submit_refuses_generation_mismatch_before_slot_mutatio slot = &ut_cr_server_shared.slots[0]; before = *slot; - result = cluster_lms_cr_submit_r4( - &forward, &admission, (uint32)admission.record_generation - 1, - (uint32)admission.record_generation, &reason); + result = cluster_lms_cr_submit_r4(&forward, &admission, (uint32)admission.record_generation - 1, + (uint32)admission.record_generation, &reason); UT_ASSERT_EQ(result, CLUSTER_CR_BUILD_FAIL_CLOSED); UT_ASSERT_EQ(reason, CLUSTER_CR_BUILD_PROTOCOL); @@ -1644,31 +1592,29 @@ UT_TEST(test_r4_submit_copy_refusal_mapping_is_closed) ClusterBufmgrGcsCopyRefusal refusal; ClusterCrBuildResult result; ClusterCrBuildReason reason; - } cases[] = { - { CLUSTER_BUFMGR_GCS_COPY_REFUSAL_INVALID_ARGUMENT, - CLUSTER_CR_BUILD_FAIL_CLOSED, CLUSTER_CR_BUILD_PROTOCOL }, - { CLUSTER_BUFMGR_GCS_COPY_REFUSAL_NONE, - CLUSTER_CR_BUILD_FAIL_CLOSED, CLUSTER_CR_BUILD_PROTOCOL }, - { CLUSTER_BUFMGR_GCS_COPY_REFUSAL_HC89_LSN_DRIFT, - CLUSTER_CR_BUILD_FAIL_CLOSED, CLUSTER_CR_BUILD_PROTOCOL }, - { CLUSTER_BUFMGR_GCS_COPY_REFUSAL_SMART_FUSION_UNCLASSIFIED, - CLUSTER_CR_BUILD_FAIL_CLOSED, CLUSTER_CR_BUILD_PROTOCOL }, - { CLUSTER_BUFMGR_GCS_COPY_REFUSAL_INJECTED_EVICT, - CLUSTER_CR_BUILD_FAIL_CLOSED, CLUSTER_CR_BUILD_PROTOCOL }, - { (ClusterBufmgrGcsCopyRefusal) - (CLUSTER_BUFMGR_GCS_COPY_REFUSAL_INJECTED_EVICT + 1), - CLUSTER_CR_BUILD_FAIL_CLOSED, CLUSTER_CR_BUILD_PROTOCOL }, - { CLUSTER_BUFMGR_GCS_COPY_REFUSAL_NOT_RESIDENT, - CLUSTER_CR_BUILD_RETRYABLE, CLUSTER_CR_BUILD_HOLDER_MOVED }, - { CLUSTER_BUFMGR_GCS_COPY_REFUSAL_CURRENT_INVALID, - CLUSTER_CR_BUILD_RETRYABLE, CLUSTER_CR_BUILD_HOLDER_MOVED }, - { CLUSTER_BUFMGR_GCS_COPY_REFUSAL_CONTENT_LOCK_FIRST, - CLUSTER_CR_BUILD_RETRYABLE, CLUSTER_CR_BUILD_HOLDER_MOVED }, - { CLUSTER_BUFMGR_GCS_COPY_REFUSAL_CONTENT_LOCK_SECOND, - CLUSTER_CR_BUILD_RETRYABLE, CLUSTER_CR_BUILD_HOLDER_MOVED }, - { CLUSTER_BUFMGR_GCS_COPY_REFUSAL_OWNERSHIP_REVOKE_BUSY, - CLUSTER_CR_BUILD_RETRYABLE, CLUSTER_CR_BUILD_HOLDER_MOVED } - }; + } cases[] + = { { CLUSTER_BUFMGR_GCS_COPY_REFUSAL_INVALID_ARGUMENT, CLUSTER_CR_BUILD_FAIL_CLOSED, + CLUSTER_CR_BUILD_PROTOCOL }, + { CLUSTER_BUFMGR_GCS_COPY_REFUSAL_NONE, CLUSTER_CR_BUILD_FAIL_CLOSED, + CLUSTER_CR_BUILD_PROTOCOL }, + { CLUSTER_BUFMGR_GCS_COPY_REFUSAL_HC89_LSN_DRIFT, CLUSTER_CR_BUILD_FAIL_CLOSED, + CLUSTER_CR_BUILD_PROTOCOL }, + { CLUSTER_BUFMGR_GCS_COPY_REFUSAL_SMART_FUSION_UNCLASSIFIED, + CLUSTER_CR_BUILD_FAIL_CLOSED, CLUSTER_CR_BUILD_PROTOCOL }, + { CLUSTER_BUFMGR_GCS_COPY_REFUSAL_INJECTED_EVICT, CLUSTER_CR_BUILD_FAIL_CLOSED, + CLUSTER_CR_BUILD_PROTOCOL }, + { (ClusterBufmgrGcsCopyRefusal)(CLUSTER_BUFMGR_GCS_COPY_REFUSAL_INJECTED_EVICT + 1), + CLUSTER_CR_BUILD_FAIL_CLOSED, CLUSTER_CR_BUILD_PROTOCOL }, + { CLUSTER_BUFMGR_GCS_COPY_REFUSAL_NOT_RESIDENT, CLUSTER_CR_BUILD_RETRYABLE, + CLUSTER_CR_BUILD_HOLDER_MOVED }, + { CLUSTER_BUFMGR_GCS_COPY_REFUSAL_CURRENT_INVALID, CLUSTER_CR_BUILD_RETRYABLE, + CLUSTER_CR_BUILD_HOLDER_MOVED }, + { CLUSTER_BUFMGR_GCS_COPY_REFUSAL_CONTENT_LOCK_FIRST, CLUSTER_CR_BUILD_RETRYABLE, + CLUSTER_CR_BUILD_HOLDER_MOVED }, + { CLUSTER_BUFMGR_GCS_COPY_REFUSAL_CONTENT_LOCK_SECOND, CLUSTER_CR_BUILD_RETRYABLE, + CLUSTER_CR_BUILD_HOLDER_MOVED }, + { CLUSTER_BUFMGR_GCS_COPY_REFUSAL_OWNERSHIP_REVOKE_BUSY, CLUSTER_CR_BUILD_RETRYABLE, + CLUSTER_CR_BUILD_HOLDER_MOVED } }; ClusterR4CrForwardPayload forward = submit_test_forward96(); ClusterSemanticAdmissionToken admission = submit_test_admission(); ClusterSemanticAdmissionToken admission_before = admission; @@ -1685,9 +1631,8 @@ UT_TEST(test_r4_submit_copy_refusal_mapping_is_closed) ut_copy_refusal = cases[i].refusal; slot = &ut_cr_server_shared.slots[0]; - result = cluster_lms_cr_submit_r4( - &forward, &admission, UT_REQUESTER_CAPABILITY_GENERATION, - UT_MASTER_CAPABILITY_GENERATION, &reason); + result = cluster_lms_cr_submit_r4(&forward, &admission, UT_REQUESTER_CAPABILITY_GENERATION, + UT_MASTER_CAPABILITY_GENERATION, &reason); UT_ASSERT_EQ(result, cases[i].result); UT_ASSERT_EQ(reason, cases[i].reason); @@ -1720,9 +1665,8 @@ UT_TEST(test_r4_submit_final_recheck_failure_canonicalizes_before_free) reset_submit_fixture(&state); ut_recheck_ok = false; slot = &ut_cr_server_shared.slots[0]; - result = cluster_lms_cr_submit_r4( - &forward, &admission, UT_REQUESTER_CAPABILITY_GENERATION, - UT_MASTER_CAPABILITY_GENERATION, &reason); + result = cluster_lms_cr_submit_r4(&forward, &admission, UT_REQUESTER_CAPABILITY_GENERATION, + UT_MASTER_CAPABILITY_GENERATION, &reason); UT_ASSERT_EQ(result, CLUSTER_CR_BUILD_RETRYABLE); UT_ASSERT_EQ(reason, CLUSTER_CR_BUILD_RF_DEFERRED); @@ -1756,8 +1700,8 @@ UT_TEST(test_r4_worker0_claim_peer_refusal_preserves_queued_slot) UT_ASSERT_EQ(ut_peer_open_calls, 1); UT_ASSERT_EQ(ut_state_at_peer_open[0], CLUSTER_LMS_CR_R4_QUEUED); UT_ASSERT_EQ(ut_leave_calls, 1); - UT_ASSERT_EQ(memcmp(&ut_left_admission, &ut_expected_admission, - sizeof(ut_expected_admission)), 0); + UT_ASSERT_EQ(memcmp(&ut_left_admission, &ut_expected_admission, sizeof(ut_expected_admission)), + 0); UT_ASSERT(ut_enter_sequence < ut_peer_open_sequence[0]); UT_ASSERT(ut_peer_open_sequence[0] < ut_leave_sequence); UT_ASSERT(cluster_cr_server_test_r4_context_matches(0, false, 0, 0, NULL)); @@ -1782,8 +1726,7 @@ UT_TEST(test_r4_worker0_claim_rebinds_owner_and_retains_context) UT_ASSERT_EQ(slot->r4.owner.edge_owner_worker_id, 0); UT_ASSERT_EQ(slot->r4.owner.builder_worker_id, 0); UT_ASSERT_EQ(slot->r4.owner.edge_owner_role, B_LMS); - UT_ASSERT(bytes_are(slot->r4.owner.reserved, - sizeof(slot->r4.owner.reserved), 0)); + UT_ASSERT(bytes_are(slot->r4.owner.reserved, sizeof(slot->r4.owner.reserved), 0)); UT_ASSERT_EQ(ut_enter_calls, 1); UT_ASSERT_EQ(ut_peer_open_calls, 2); UT_ASSERT_EQ(ut_peer_open_peers[0], UT_MASTER_NODE); @@ -1795,8 +1738,8 @@ UT_TEST(test_r4_worker0_claim_rebinds_owner_and_retains_context) UT_ASSERT_EQ(ut_state_at_peer_open[0], CLUSTER_LMS_CR_R4_QUEUED); UT_ASSERT_EQ(ut_state_at_peer_open[1], CLUSTER_LMS_CR_R4_QUEUED); UT_ASSERT_EQ(ut_leave_calls, 0); - UT_ASSERT(cluster_cr_server_test_r4_context_matches( - 0, true, 1, UT_WORKER0_INCARNATION, &ut_expected_admission)); + UT_ASSERT(cluster_cr_server_test_r4_context_matches(0, true, 1, UT_WORKER0_INCARNATION, + &ut_expected_admission)); UT_ASSERT(ut_enter_sequence < ut_peer_open_sequence[0]); UT_ASSERT(ut_peer_open_sequence[0] < ut_peer_open_sequence[1]); UT_ASSERT_EQ(ut_wake_calls, 0); @@ -1820,13 +1763,9 @@ UT_TEST(test_r4_worker0_drain_requires_exact_empty_contexts) UT_TEST(test_r4_worker0_drain_rejects_every_terminal_and_shipping_state) { - static const uint32 blocked_states[] = { - CLUSTER_LMS_CR_R4_READY_FULL, - CLUSTER_LMS_CR_R4_READY_RETRY, - CLUSTER_LMS_CR_R4_READY_FAIL, - CLUSTER_LMS_CR_R4_CANCELLED, - CLUSTER_LMS_CR_R4_SHIPPING - }; + static const uint32 blocked_states[] + = { CLUSTER_LMS_CR_R4_READY_FULL, CLUSTER_LMS_CR_R4_READY_RETRY, + CLUSTER_LMS_CR_R4_READY_FAIL, CLUSTER_LMS_CR_R4_CANCELLED, CLUSTER_LMS_CR_R4_SHIPPING }; ClusterLmsSharedState state; ClusterLmsCrSlot *slot; int i; @@ -1862,21 +1801,18 @@ UT_TEST(test_r4_lmon_reclaim_requires_exact_ack_then_canonicalizes_all_slots) slot2->r4.slot_generation = 3; prepare_exact_drain_ack(&state, UINT64_C(8), UINT64_C(17)); - UT_ASSERT(cluster_cr_server_r4_lmon_reclaim_closed( - UINT64_C(8), UINT64_C(17))); + UT_ASSERT(cluster_cr_server_r4_lmon_reclaim_closed(UINT64_C(8), UINT64_C(17))); UT_ASSERT_EQ(ut_lock_acquire_count, 1); UT_ASSERT_EQ(ut_lock_release_count, 1); UT_ASSERT(ut_lock == &state.lwlock); UT_ASSERT_EQ(ut_lock_mode, LW_EXCLUSIVE); UT_ASSERT_EQ(ut_state_at_lock_release, CLUSTER_LMS_CR_R4_RECLAIMING); UT_ASSERT_EQ(ut_generation_at_lock_release, UINT64_C(1)); - UT_ASSERT_EQ(memcmp(&ut_owner_at_lock_release, &slot0_owner, - sizeof(slot0_owner)), 0); + UT_ASSERT_EQ(memcmp(&ut_owner_at_lock_release, &slot0_owner, sizeof(slot0_owner)), 0); UT_ASSERT(slot_is_canonical_free_with_generation(slot0, 1)); UT_ASSERT(slot_is_canonical_free_with_generation(slot1, 2)); UT_ASSERT(slot_is_canonical_free_with_generation(slot2, 3)); - UT_ASSERT(slot_is_canonical_free_with_generation( - &ut_cr_server_shared.slots[3], 0)); + UT_ASSERT(slot_is_canonical_free_with_generation(&ut_cr_server_shared.slots[3], 0)); } UT_TEST(test_r4_lmon_reclaim_rechecks_ack_inside_exclusive_claim_window) @@ -1892,8 +1828,7 @@ UT_TEST(test_r4_lmon_reclaim_rechecks_ack_inside_exclusive_claim_window) prepare_exact_drain_ack(&state, UINT64_C(8), UINT64_C(17)); ut_reclaim_race_on_proof = true; - UT_ASSERT(!cluster_cr_server_r4_lmon_reclaim_closed( - UINT64_C(8), UINT64_C(17))); + UT_ASSERT(!cluster_cr_server_r4_lmon_reclaim_closed(UINT64_C(8), UINT64_C(17))); UT_ASSERT(ut_reclaim_race_injected); UT_ASSERT_EQ(state.r4_controls.data_worker_incarnation[0], UINT64_C(9)); UT_ASSERT_EQ(memcmp(&ut_cr_server_shared, &before, sizeof(before)), 0); @@ -1913,8 +1848,7 @@ UT_TEST(test_r4_lmon_reclaim_refuses_unproved_or_legacy_slot_without_mutation) slot = &ut_cr_server_shared.slots[0]; prepare_reclaimable_r4_slot(slot, CLUSTER_LMS_CR_R4_QUEUED, 1, 2); before = ut_cr_server_shared; - UT_ASSERT(!cluster_cr_server_r4_lmon_reclaim_closed( - UINT64_C(8), UINT64_C(17))); + UT_ASSERT(!cluster_cr_server_r4_lmon_reclaim_closed(UINT64_C(8), UINT64_C(17))); UT_ASSERT(memcmp(&ut_cr_server_shared, &before, sizeof(before)) == 0); reset_submit_fixture(&state); @@ -1922,8 +1856,7 @@ UT_TEST(test_r4_lmon_reclaim_refuses_unproved_or_legacy_slot_without_mutation) pg_atomic_write_u32(&slot->state, CLUSTER_LMS_CR_FILLING); before = ut_cr_server_shared; prepare_exact_drain_ack(&state, UINT64_C(8), UINT64_C(17)); - UT_ASSERT(!cluster_cr_server_r4_lmon_reclaim_closed( - UINT64_C(8), UINT64_C(17))); + UT_ASSERT(!cluster_cr_server_r4_lmon_reclaim_closed(UINT64_C(8), UINT64_C(17))); UT_ASSERT(memcmp(&ut_cr_server_shared, &before, sizeof(before)) == 0); } @@ -1964,8 +1897,8 @@ UT_TEST(test_r4_worker0_claim_all_local_uses_token_without_peer_matcher) UT_ASSERT_EQ(ut_state_at_enter, CLUSTER_LMS_CR_R4_QUEUED); UT_ASSERT_EQ(ut_peer_open_calls, 0); UT_ASSERT_EQ(ut_leave_calls, 0); - UT_ASSERT(cluster_cr_server_test_r4_context_matches( - 0, true, 1, UT_WORKER0_INCARNATION, &ut_expected_admission)); + UT_ASSERT(cluster_cr_server_test_r4_context_matches(0, true, 1, UT_WORKER0_INCARNATION, + &ut_expected_admission)); UT_ASSERT_EQ(ut_wake_calls, 0); } @@ -1985,8 +1918,8 @@ UT_TEST(test_r4_worker0_build_step_publishes_ready_full) UT_ASSERT(ut_builder_foreign_page == slot->foreign_undo_page); UT_ASSERT_EQ(pg_atomic_read_u32(&slot->state), CLUSTER_LMS_CR_R4_READY_FULL); UT_ASSERT_EQ(slot->r4.terminal_reason, CLUSTER_CR_BUILD_NONE); - UT_ASSERT(cluster_cr_server_test_r4_context_matches( - 0, true, 1, UT_WORKER0_INCARNATION, &ut_expected_admission)); + UT_ASSERT(cluster_cr_server_test_r4_context_matches(0, true, 1, UT_WORKER0_INCARNATION, + &ut_expected_admission)); UT_ASSERT_EQ(ut_leave_calls, 0); } @@ -2031,8 +1964,8 @@ UT_TEST(test_r4_worker0_build_step_publishes_one_need_undo) UT_ASSERT_EQ(ut_forget_calls, 0); UT_ASSERT_EQ(ut_leave_calls, 0); UT_ASSERT_EQ(ut_wake_calls, 0); - UT_ASSERT(cluster_cr_server_test_r4_context_matches( - 0, true, 1, UT_WORKER0_INCARNATION, &ut_expected_admission)); + UT_ASSERT(cluster_cr_server_test_r4_context_matches(0, true, 1, UT_WORKER0_INCARNATION, + &ut_expected_admission)); } /* A query cancel raised by the immutable-page builder belongs to the exact @@ -2072,10 +2005,8 @@ UT_TEST(test_r4_worker0_query_cancel_terminalizes_exact_building_slot) UT_ASSERT(!caught); UT_ASSERT(returned); - UT_ASSERT(ut_context_at_flush - == (MemoryContext)&ut_initial_memory_context_storage); - UT_ASSERT(CurrentMemoryContext - == (MemoryContext)&ut_initial_memory_context_storage); + UT_ASSERT(ut_context_at_flush == (MemoryContext)&ut_initial_memory_context_storage); + UT_ASSERT(CurrentMemoryContext == (MemoryContext)&ut_initial_memory_context_storage); UT_ASSERT_EQ(ut_flush_error_calls, 1); UT_ASSERT_EQ(memcmp(slot, &expected, sizeof(expected)), 0); UT_ASSERT_EQ(ut_builder_step_calls, 1); @@ -2084,8 +2015,8 @@ UT_TEST(test_r4_worker0_query_cancel_terminalizes_exact_building_slot) UT_ASSERT_EQ(ut_forget_slot_generation, 1); UT_ASSERT_EQ(ut_wake_calls, 1); UT_ASSERT_EQ(ut_leave_calls, 0); - UT_ASSERT(cluster_cr_server_test_r4_context_matches( - 0, true, 1, UT_WORKER0_INCARNATION, &ut_expected_admission)); + UT_ASSERT(cluster_cr_server_test_r4_context_matches(0, true, 1, UT_WORKER0_INCARNATION, + &ut_expected_admission)); UT_ASSERT(cluster_cr_server_test_r4_ship_terminal(0)); UT_ASSERT_EQ(ut_send_calls, 1); @@ -2147,28 +2078,24 @@ UT_TEST(test_r4_worker0_foreign_undo_sends_frozen_zero_generation) UT_ASSERT(cluster_cr_server_test_r4_send_foreign_undo(0)); UT_ASSERT_EQ(ut_send_calls, 1); - UT_ASSERT_EQ(pg_atomic_read_u32(&slot->state), - CLUSTER_LMS_CR_R4_UNDO_INFLIGHT); + UT_ASSERT_EQ(pg_atomic_read_u32(&slot->state), CLUSTER_LMS_CR_R4_UNDO_INFLIGHT); forward = (const ClusterR4CrForwardPayload *)ut_send_payload; UT_ASSERT(ClusterR4ForwardExtensionGetLocatorGeneration( - &forward->extension, CLUSTER_R4_WIRE_UNDO_DATA_FETCH, &locator, - &physical_generation)); + &forward->extension, CLUSTER_R4_WIRE_UNDO_DATA_FETCH, &locator, &physical_generation)); UT_ASSERT_EQ(physical_generation, 0); UT_ASSERT_EQ(memcmp(&locator, &ut_pending_locator, sizeof(locator)), 0); } UT_TEST(test_r4_worker0_foreign_undo_admitted_send_is_exact_and_one_shot) { - const ClusterICSendResult admitted_results[] = { - CLUSTER_IC_SEND_DONE, - CLUSTER_IC_SEND_WOULD_BLOCK - }; + const ClusterICSendResult admitted_results[] + = { CLUSTER_IC_SEND_DONE, CLUSTER_IC_SEND_WOULD_BLOCK }; int i; for (i = 0; i < lengthof(admitted_results); i++) { ClusterLmsSharedState state; - ClusterLmsCrSlot *slot = prepare_worker0_need_undo_frozen( - &state, UT_FOREIGN_PHYSICAL_GENERATION); + ClusterLmsCrSlot *slot + = prepare_worker0_need_undo_frozen(&state, UT_FOREIGN_PHYSICAL_GENERATION); ut_send_result = admitted_results[i]; UT_ASSERT(cluster_cr_server_test_r4_send_foreign_undo(0)); @@ -2182,14 +2109,13 @@ UT_TEST(test_r4_worker0_foreign_undo_admitted_send_is_exact_and_one_shot) UT_ASSERT_EQ(ut_note_send_calls, 1); UT_ASSERT_EQ(ut_note_send_family, GCS_BLOCK_SEND_FAMILY_FORWARD); UT_ASSERT_EQ(ut_note_send_result, admitted_results[i]); - UT_ASSERT_EQ(pg_atomic_read_u32(&slot->state), - CLUSTER_LMS_CR_R4_UNDO_INFLIGHT); + UT_ASSERT_EQ(pg_atomic_read_u32(&slot->state), CLUSTER_LMS_CR_R4_UNDO_INFLIGHT); UT_ASSERT_EQ(slot->r4.terminal_reason, CLUSTER_CR_BUILD_NONE); UT_ASSERT_EQ(ut_tier1_close_calls, 0); UT_ASSERT_EQ(ut_forget_calls, 0); UT_ASSERT_EQ(ut_leave_calls, 0); - UT_ASSERT(cluster_cr_server_test_r4_context_matches( - 0, true, 1, UT_WORKER0_INCARNATION, &ut_expected_admission)); + UT_ASSERT(cluster_cr_server_test_r4_context_matches(0, true, 1, UT_WORKER0_INCARNATION, + &ut_expected_admission)); UT_ASSERT(!cluster_cr_server_test_r4_send_foreign_undo(0)); UT_ASSERT_EQ(ut_pending_locator_calls, 1); UT_ASSERT_EQ(ut_send_calls, 1); @@ -2202,8 +2128,8 @@ UT_TEST(test_r4_worker0_foreign_undo_admitted_send_is_exact_and_one_shot) UT_TEST(test_r4_worker0_foreign_undo_accepts_initial_tt_wrap) { ClusterLmsSharedState state; - ClusterLmsCrSlot *slot = prepare_worker0_need_undo_frozen( - &state, UT_FOREIGN_PHYSICAL_GENERATION); + ClusterLmsCrSlot *slot + = prepare_worker0_need_undo_frozen(&state, UT_FOREIGN_PHYSICAL_GENERATION); const ClusterR4CrForwardPayload *forward; slot->r4.foreign_wrap = TT_WRAP_INITIAL; @@ -2212,8 +2138,7 @@ UT_TEST(test_r4_worker0_foreign_undo_accepts_initial_tt_wrap) UT_ASSERT_EQ(ut_pending_locator_calls, 1); UT_ASSERT_EQ(ut_send_calls, 1); UT_ASSERT_EQ(ut_state_at_send, CLUSTER_LMS_CR_R4_UNDO_INFLIGHT); - UT_ASSERT_EQ(pg_atomic_read_u32(&slot->state), - CLUSTER_LMS_CR_R4_UNDO_INFLIGHT); + UT_ASSERT_EQ(pg_atomic_read_u32(&slot->state), CLUSTER_LMS_CR_R4_UNDO_INFLIGHT); UT_ASSERT_EQ(slot->r4.terminal_reason, CLUSTER_CR_BUILD_NONE); forward = (const ClusterR4CrForwardPayload *)ut_send_payload; UT_ASSERT_EQ(forward->extension.kind.locator_bytes[20], 0); @@ -2226,8 +2151,8 @@ UT_TEST(test_r4_worker0_foreign_undo_accepts_initial_tt_wrap) UT_TEST(test_r4_worker0_foreign_undo_sends_unresolved_wrap_for_origin_upgrade) { ClusterLmsSharedState state; - ClusterLmsCrSlot *slot = prepare_worker0_need_undo_frozen( - &state, UT_FOREIGN_PHYSICAL_GENERATION); + ClusterLmsCrSlot *slot + = prepare_worker0_need_undo_frozen(&state, UT_FOREIGN_PHYSICAL_GENERATION); const ClusterR4CrForwardPayload *forward; slot->r4.foreign_wrap = TT_WRAP_INVALID; @@ -2235,8 +2160,7 @@ UT_TEST(test_r4_worker0_foreign_undo_sends_unresolved_wrap_for_origin_upgrade) UT_ASSERT(cluster_cr_server_test_r4_send_foreign_undo(0)); UT_ASSERT_EQ(ut_send_calls, 1); UT_ASSERT_EQ(ut_note_send_calls, 1); - UT_ASSERT_EQ(pg_atomic_read_u32(&slot->state), - CLUSTER_LMS_CR_R4_UNDO_INFLIGHT); + UT_ASSERT_EQ(pg_atomic_read_u32(&slot->state), CLUSTER_LMS_CR_R4_UNDO_INFLIGHT); UT_ASSERT_EQ(slot->r4.terminal_reason, CLUSTER_CR_BUILD_NONE); forward = (const ClusterR4CrForwardPayload *)ut_send_payload; UT_ASSERT_EQ(forward->extension.kind.locator_bytes[20], 0xff); @@ -2254,18 +2178,16 @@ UT_TEST(test_r4_worker0_foreign_undo_refusal_mapping_is_close_first) uint32 terminal_state; ClusterCrBuildReason reason; bool closes_peer; - } cases[] = { - { CLUSTER_IC_SEND_NOT_ADMITTED, CLUSTER_LMS_CR_R4_READY_RETRY, - CLUSTER_CR_BUILD_CAPACITY, false }, - { CLUSTER_IC_SEND_HARD_ERROR, CLUSTER_LMS_CR_R4_READY_FAIL, - CLUSTER_CR_BUILD_PROTOCOL, true } - }; + } cases[] = { { CLUSTER_IC_SEND_NOT_ADMITTED, CLUSTER_LMS_CR_R4_READY_RETRY, + CLUSTER_CR_BUILD_CAPACITY, false }, + { CLUSTER_IC_SEND_HARD_ERROR, CLUSTER_LMS_CR_R4_READY_FAIL, + CLUSTER_CR_BUILD_PROTOCOL, true } }; int i; for (i = 0; i < lengthof(cases); i++) { ClusterLmsSharedState state; - ClusterLmsCrSlot *slot = prepare_worker0_need_undo_frozen( - &state, UT_FOREIGN_PHYSICAL_GENERATION); + ClusterLmsCrSlot *slot + = prepare_worker0_need_undo_frozen(&state, UT_FOREIGN_PHYSICAL_GENERATION); int fd = -1; bool down = false; bool wes_dirty = false; @@ -2283,12 +2205,10 @@ UT_TEST(test_r4_worker0_foreign_undo_refusal_mapping_is_close_first) UT_ASSERT_EQ(slot->r4.terminal_reason, cases[i].reason); UT_ASSERT_EQ(ut_tier1_close_calls, cases[i].closes_peer ? 1 : 0); UT_ASSERT_EQ(ut_close_peer_calls, 0); - UT_ASSERT(cluster_lms_data_plane_test_peer_snapshot( - 1, &fd, &down, &wes_dirty)); + UT_ASSERT(cluster_lms_data_plane_test_peer_snapshot(1, &fd, &down, &wes_dirty)); if (cases[i].closes_peer) { UT_ASSERT_EQ(ut_tier1_close_peer, 1); - UT_ASSERT_EQ(ut_state_at_tier1_close, - CLUSTER_LMS_CR_R4_UNDO_INFLIGHT); + UT_ASSERT_EQ(ut_state_at_tier1_close, CLUSTER_LMS_CR_R4_UNDO_INFLIGHT); UT_ASSERT_EQ(fd, -1); UT_ASSERT(down); UT_ASSERT(wes_dirty); @@ -2299,8 +2219,8 @@ UT_TEST(test_r4_worker0_foreign_undo_refusal_mapping_is_close_first) } UT_ASSERT_EQ(ut_forget_calls, 0); UT_ASSERT_EQ(ut_leave_calls, 0); - UT_ASSERT(cluster_cr_server_test_r4_context_matches( - 0, true, 1, UT_WORKER0_INCARNATION, &ut_expected_admission)); + UT_ASSERT(cluster_cr_server_test_r4_context_matches(0, true, 1, UT_WORKER0_INCARNATION, + &ut_expected_admission)); UT_ASSERT(!cluster_cr_server_test_r4_send_foreign_undo(0)); UT_ASSERT_EQ(ut_send_calls, 1); } @@ -2312,8 +2232,8 @@ UT_TEST(test_r4_worker0_foreign_undo_refusal_mapping_is_close_first) UT_TEST(test_r4_worker0_foreign_undo_locator_mismatch_fails_before_send) { ClusterLmsSharedState state; - ClusterLmsCrSlot *slot = prepare_worker0_need_undo_frozen( - &state, UT_FOREIGN_PHYSICAL_GENERATION); + ClusterLmsCrSlot *slot + = prepare_worker0_need_undo_frozen(&state, UT_FOREIGN_PHYSICAL_GENERATION); ut_pending_locator.xid = 798; UT_ASSERT(cluster_cr_server_test_r4_send_foreign_undo(0)); @@ -2326,8 +2246,8 @@ UT_TEST(test_r4_worker0_foreign_undo_locator_mismatch_fails_before_send) UT_ASSERT_EQ(slot->r4.terminal_reason, CLUSTER_CR_BUILD_PROTOCOL); UT_ASSERT_EQ(ut_forget_calls, 0); UT_ASSERT_EQ(ut_leave_calls, 0); - UT_ASSERT(cluster_cr_server_test_r4_context_matches( - 0, true, 1, UT_WORKER0_INCARNATION, &ut_expected_admission)); + UT_ASSERT(cluster_cr_server_test_r4_context_matches(0, true, 1, UT_WORKER0_INCARNATION, + &ut_expected_admission)); UT_ASSERT(!cluster_cr_server_test_r4_send_foreign_undo(0)); UT_ASSERT_EQ(ut_pending_locator_calls, 1); UT_ASSERT_EQ(ut_send_calls, 0); @@ -2347,11 +2267,9 @@ UT_TEST(test_r4_worker0_status24_lands_exact_foreign_undo_and_short_admission) char page[BLCKSZ]; make_foreign_undo_reply(&header, &auth, &env, page); - UT_ASSERT(cluster_cr_server_r4_land_foreign_undo( - &env, &header, page, &auth)); + UT_ASSERT(cluster_cr_server_r4_land_foreign_undo(&env, &header, page, &auth)); - UT_ASSERT_EQ(pg_atomic_read_u32(&slot->state), - CLUSTER_LMS_CR_R4_UNDO_READY); + UT_ASSERT_EQ(pg_atomic_read_u32(&slot->state), CLUSTER_LMS_CR_R4_UNDO_READY); UT_ASSERT_EQ(memcmp(slot->foreign_undo_page, page, BLCKSZ), 0); UT_ASSERT_EQ(slot->r4.origin_formation_epoch, UT_FORMATION_EPOCH); UT_ASSERT_EQ(slot->r4.origin_live_hwm_lsn, UT_FOREIGN_LIVE_HWM); @@ -2360,8 +2278,7 @@ UT_TEST(test_r4_worker0_status24_lands_exact_foreign_undo_and_short_admission) UT_ASSERT_EQ(slot->r4.foreign_wrap, ut_pending_locator.tt_wrap); UT_ASSERT_EQ(ut_extract_calls, 1); UT_ASSERT_EQ(ut_state_at_extract, CLUSTER_LMS_CR_R4_UNDO_INFLIGHT); - UT_ASSERT_EQ(memcmp(&ut_extract_locator, &ut_pending_locator, - sizeof(ut_pending_locator)), 0); + UT_ASSERT_EQ(memcmp(&ut_extract_locator, &ut_pending_locator, sizeof(ut_pending_locator)), 0); UT_ASSERT_EQ(ut_checksum_calls, 1); UT_ASSERT_EQ(ut_enter_calls, 1); UT_ASSERT_EQ(ut_enter_feature_bit, CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1); @@ -2373,8 +2290,8 @@ UT_TEST(test_r4_worker0_status24_lands_exact_foreign_undo_and_short_admission) UT_ASSERT(ut_enter_sequence < ut_recheck_sequence); UT_ASSERT(ut_recheck_sequence < ut_leave_sequence); UT_ASSERT_EQ(ut_wake_calls, 1); - UT_ASSERT(cluster_cr_server_test_r4_context_matches( - 0, true, 1, UT_WORKER0_INCARNATION, &ut_expected_admission)); + UT_ASSERT(cluster_cr_server_test_r4_context_matches(0, true, 1, UT_WORKER0_INCARNATION, + &ut_expected_admission)); } /* TT_WRAP_INVALID is the one legal unresolved request generation. A valid @@ -2393,8 +2310,8 @@ UT_TEST(test_r4_worker0_status24_canonicalizes_invalid_wrap_before_ready) slot->r4.foreign_wrap = TT_WRAP_INVALID; ut_pending_locator.tt_wrap = TT_WRAP_INVALID; ut_extract_canonical_wrap = 7; - UT_ASSERT(cluster_cr_server_test_r4_freeze_foreign_generation( - 0, UT_FOREIGN_PHYSICAL_GENERATION)); + UT_ASSERT( + cluster_cr_server_test_r4_freeze_foreign_generation(0, UT_FOREIGN_PHYSICAL_GENERATION)); pg_atomic_write_u32(&slot->state, CLUSTER_LMS_CR_R4_UNDO_INFLIGHT); ut_enter_calls = 0; ut_recheck_calls = 0; @@ -2403,10 +2320,8 @@ UT_TEST(test_r4_worker0_status24_canonicalizes_invalid_wrap_before_ready) ut_extract_calls = 0; make_foreign_undo_reply(&header, &auth, &env, page); - UT_ASSERT(cluster_cr_server_r4_land_foreign_undo( - &env, &header, page, &auth)); - UT_ASSERT_EQ(pg_atomic_read_u32(&slot->state), - CLUSTER_LMS_CR_R4_UNDO_READY); + UT_ASSERT(cluster_cr_server_r4_land_foreign_undo(&env, &header, page, &auth)); + UT_ASSERT_EQ(pg_atomic_read_u32(&slot->state), CLUSTER_LMS_CR_R4_UNDO_READY); UT_ASSERT_EQ(slot->r4.foreign_wrap, 7); UT_ASSERT_EQ(ut_extract_calls, 1); UT_ASSERT_EQ(ut_extract_locator.tt_wrap, TT_WRAP_INVALID); @@ -2461,102 +2376,97 @@ UT_TEST(test_r4_worker0_status24_mismatches_leave_shared_slot_unchanged) make_foreign_undo_reply(&header, &auth, &env, page); switch ((RejectCase)i) { - case REJECT_ENV_SOURCE: - env.source_node_id = 2; - break; - case REJECT_ENV_DEST: - env.dest_node_id = 2; - break; - case REJECT_ENV_LENGTH: - env.payload_length--; - break; - case REJECT_STATUS: - header.status = GCS_BLOCK_REPLY_R4_CR_FULL; - break; - case REJECT_ENDPOINT: - header.requester_backend_id = UT_REQUESTER_BACKEND; - break; - case REJECT_TRANSITION: - header.transition_id = PCM_TRANS_N_TO_X; - break; - case REJECT_FORWARDING: - GcsBlockReplyHeaderSetForwardingMasterNode(&header, UT_MASTER_NODE); - break; - case REJECT_REQUEST_ID: - header.request_id = UINT64CONST(8); - break; - case REJECT_EPOCH: - header.epoch++; - break; - case REJECT_ORIGIN: - header.sender_node = 2; - env.source_node_id = 2; - break; - case REJECT_PHYSICAL_GENERATION: - UT_ASSERT(GcsBlockReplyHeaderSetR4UndoGeneration( - &header, UT_FOREIGN_PHYSICAL_GENERATION + 1)); - break; - case REJECT_LIVE_HWM: - header.page_lsn = InvalidXLogRecPtr; - break; - case REJECT_ENV_EPOCH: - env.epoch++; - break; - case REJECT_AUTHORITY_ZERO: - ClusterGcsUndoAuthTrailerSetAuthorityScn(&auth, InvalidScn); - break; - case REJECT_AUTHORITY_BELOW_DEMAND: - ClusterGcsUndoAuthTrailerSetAuthorityScn( - &auth, (uint64)(UT_READ_SCN - 1)); - break; - case REJECT_CHECKSUM: - header.checksum ^= UINT32_C(1); - break; - case REJECT_RECORD: - ut_extract_ok = false; - break; - case REJECT_CANONICAL_WRAP: - ut_extract_canonical_wrap++; - break; - case REJECT_SLOT_CONTEXT_KEY: - slot->requester_backend++; - break; - case REJECT_DIRTY_FOREIGN_PAGE: - slot->foreign_undo_page[BLCKSZ - 1] = 1; - break; - case REJECT_FINAL_RECHECK: - ut_recheck_ok = false; - break; - case REJECT_WRONG_WORKER: - ut_data_worker_id = 1; - break; - case REJECT_WORKER_INCARCATION: - state.r4_controls.data_worker_incarnation[0]++; - break; - case REJECT_WRONG_STATE: - pg_atomic_write_u32( - &slot->state, CLUSTER_LMS_CR_R4_UNDO_READY); - break; + case REJECT_ENV_SOURCE: + env.source_node_id = 2; + break; + case REJECT_ENV_DEST: + env.dest_node_id = 2; + break; + case REJECT_ENV_LENGTH: + env.payload_length--; + break; + case REJECT_STATUS: + header.status = GCS_BLOCK_REPLY_R4_CR_FULL; + break; + case REJECT_ENDPOINT: + header.requester_backend_id = UT_REQUESTER_BACKEND; + break; + case REJECT_TRANSITION: + header.transition_id = PCM_TRANS_N_TO_X; + break; + case REJECT_FORWARDING: + GcsBlockReplyHeaderSetForwardingMasterNode(&header, UT_MASTER_NODE); + break; + case REJECT_REQUEST_ID: + header.request_id = UINT64CONST(8); + break; + case REJECT_EPOCH: + header.epoch++; + break; + case REJECT_ORIGIN: + header.sender_node = 2; + env.source_node_id = 2; + break; + case REJECT_PHYSICAL_GENERATION: + UT_ASSERT(GcsBlockReplyHeaderSetR4UndoGeneration(&header, + UT_FOREIGN_PHYSICAL_GENERATION + 1)); + break; + case REJECT_LIVE_HWM: + header.page_lsn = InvalidXLogRecPtr; + break; + case REJECT_ENV_EPOCH: + env.epoch++; + break; + case REJECT_AUTHORITY_ZERO: + ClusterGcsUndoAuthTrailerSetAuthorityScn(&auth, InvalidScn); + break; + case REJECT_AUTHORITY_BELOW_DEMAND: + ClusterGcsUndoAuthTrailerSetAuthorityScn(&auth, (uint64)(UT_READ_SCN - 1)); + break; + case REJECT_CHECKSUM: + header.checksum ^= UINT32_C(1); + break; + case REJECT_RECORD: + ut_extract_ok = false; + break; + case REJECT_CANONICAL_WRAP: + ut_extract_canonical_wrap++; + break; + case REJECT_SLOT_CONTEXT_KEY: + slot->requester_backend++; + break; + case REJECT_DIRTY_FOREIGN_PAGE: + slot->foreign_undo_page[BLCKSZ - 1] = 1; + break; + case REJECT_FINAL_RECHECK: + ut_recheck_ok = false; + break; + case REJECT_WRONG_WORKER: + ut_data_worker_id = 1; + break; + case REJECT_WORKER_INCARCATION: + state.r4_controls.data_worker_incarnation[0]++; + break; + case REJECT_WRONG_STATE: + pg_atomic_write_u32(&slot->state, CLUSTER_LMS_CR_R4_UNDO_READY); + break; } ut_checksum_calls = 0; before = *slot; - UT_ASSERT(!cluster_cr_server_r4_land_foreign_undo( - &env, &header, page, &auth)); + UT_ASSERT(!cluster_cr_server_r4_land_foreign_undo(&env, &header, page, &auth)); UT_ASSERT_EQ(memcmp(slot, &before, sizeof(before)), 0); UT_ASSERT_EQ(ut_wake_calls, 0); UT_ASSERT_EQ(ut_leave_calls, ut_enter_calls); if ((RejectCase)i != REJECT_SLOT_CONTEXT_KEY) - UT_ASSERT(cluster_cr_server_test_r4_context_matches( - 0, true, 1, UT_WORKER0_INCARNATION, &retained)); + UT_ASSERT(cluster_cr_server_test_r4_context_matches(0, true, 1, UT_WORKER0_INCARNATION, + &retained)); } } UT_TEST(test_r4_worker0_remote_full_ship_transfers_frame_and_cleans_context) { - const ClusterICSendResult admitted_results[] = { - CLUSTER_IC_SEND_DONE, - CLUSTER_IC_SEND_WOULD_BLOCK - }; + const ClusterICSendResult admitted_results[] + = { CLUSTER_IC_SEND_DONE, CLUSTER_IC_SEND_WOULD_BLOCK }; int i; for (i = 0; i < lengthof(admitted_results); i++) { @@ -2591,8 +2501,8 @@ UT_TEST(test_r4_worker0_remote_full_ship_transfers_frame_and_cleans_context) UT_ASSERT_EQ(ut_forget_slot_index, 0); UT_ASSERT_EQ(ut_forget_slot_generation, 1); UT_ASSERT_EQ(ut_leave_calls, 1); - UT_ASSERT_EQ(memcmp(&ut_left_admission, &ut_expected_admission, - sizeof(ut_expected_admission)), 0); + UT_ASSERT_EQ( + memcmp(&ut_left_admission, &ut_expected_admission, sizeof(ut_expected_admission)), 0); UT_ASSERT(slot_is_canonical_free_with_generation(slot, 1)); UT_ASSERT(cluster_cr_server_test_r4_context_matches(0, false, 0, 0, NULL)); } @@ -2664,13 +2574,10 @@ UT_TEST(test_r4_worker0_retry_and_fail_ship_zero_body_without_image_fence) ClusterCrBuildReason reason; uint32 terminal_state; GcsBlockReplyStatus status; - } cases[] = { - { CLUSTER_R4_CR_STEP_RETRY, CLUSTER_CR_BUILD_CAPACITY, - CLUSTER_LMS_CR_R4_READY_RETRY, - GCS_BLOCK_REPLY_R4_RETRYABLE_HOLDER_MOVED }, - { CLUSTER_R4_CR_STEP_FAIL, CLUSTER_CR_BUILD_PROTOCOL, - CLUSTER_LMS_CR_R4_READY_FAIL, GCS_BLOCK_REPLY_R4_DENIED } - }; + } cases[] = { { CLUSTER_R4_CR_STEP_RETRY, CLUSTER_CR_BUILD_CAPACITY, + CLUSTER_LMS_CR_R4_READY_RETRY, GCS_BLOCK_REPLY_R4_RETRYABLE_HOLDER_MOVED }, + { CLUSTER_R4_CR_STEP_FAIL, CLUSTER_CR_BUILD_PROTOCOL, + CLUSTER_LMS_CR_R4_READY_FAIL, GCS_BLOCK_REPLY_R4_DENIED } }; int i; for (i = 0; i < lengthof(cases); i++) { @@ -2703,8 +2610,7 @@ UT_TEST(test_r4_worker0_retry_and_fail_ship_zero_body_without_image_fence) UT_ASSERT_EQ(header->requester_backend_id, UT_REQUESTER_BACKEND); UT_ASSERT_EQ(header->transition_id, PCM_TRANS_N_TO_S); UT_ASSERT_EQ(header->status, cases[i].status); - UT_ASSERT_EQ(GcsBlockReplyHeaderGetForwardingMasterNode(header), - UT_MASTER_NODE); + UT_ASSERT_EQ(GcsBlockReplyHeaderGetForwardingMasterNode(header), UT_MASTER_NODE); UT_ASSERT(bytes_are(header->reserved_0, sizeof(header->reserved_0), 0)); UT_ASSERT(bytes_are(ut_send_payload + sizeof(*header), BLCKSZ, 0)); UT_ASSERT_EQ(ut_checksum_calls, 1); @@ -2731,8 +2637,7 @@ UT_TEST(test_data_plane_close_peer_now_is_same_process_and_idempotent) UT_ASSERT_EQ(ut_tier1_close_calls, 1); UT_ASSERT_EQ(ut_tier1_close_peer, UT_REQUESTER_NODE); UT_ASSERT(strstr(ut_tier1_close_reason, "R4 undo data send hard error") != NULL); - UT_ASSERT(cluster_lms_data_plane_test_peer_snapshot( - UT_REQUESTER_NODE, &fd, &down, &wes_dirty)); + UT_ASSERT(cluster_lms_data_plane_test_peer_snapshot(UT_REQUESTER_NODE, &fd, &down, &wes_dirty)); UT_ASSERT_EQ(fd, -1); UT_ASSERT(down); UT_ASSERT(wes_dirty); @@ -2744,8 +2649,7 @@ UT_TEST(test_data_plane_close_peer_now_is_same_process_and_idempotent) /* The thin API is legal only for a live remote peer on this DATA plane. */ cluster_lms_data_plane_test_seed_peer(UT_REQUESTER_NODE, 78, true, false, false); cluster_lms_data_plane_close_peer_now(UT_REQUESTER_NODE); - UT_ASSERT(cluster_lms_data_plane_test_peer_snapshot( - UT_REQUESTER_NODE, &fd, &down, &wes_dirty)); + UT_ASSERT(cluster_lms_data_plane_test_peer_snapshot(UT_REQUESTER_NODE, &fd, &down, &wes_dirty)); UT_ASSERT_EQ(fd, 78); UT_ASSERT(!down); UT_ASSERT(!wes_dirty); @@ -2777,8 +2681,7 @@ UT_TEST(test_r4_worker0_terminal_hard_error_closes_data_peer_before_cleanup) UT_ASSERT_EQ(ut_forget_calls_at_tier1_close, 0); UT_ASSERT_EQ(ut_leave_calls_at_tier1_close, 0); UT_ASSERT_EQ(ut_close_peer_calls, 0); - UT_ASSERT(cluster_lms_data_plane_test_peer_snapshot( - UT_REQUESTER_NODE, &fd, &down, &wes_dirty)); + UT_ASSERT(cluster_lms_data_plane_test_peer_snapshot(UT_REQUESTER_NODE, &fd, &down, &wes_dirty)); UT_ASSERT_EQ(fd, -1); UT_ASSERT(down); UT_ASSERT(wes_dirty); @@ -2840,13 +2743,13 @@ UT_TEST(test_all_four_legacy_submitters_use_common_reserver) UT_ASSERT_NOT_NULL(source); if (source != NULL) { UT_ASSERT(function_uses_common_reserver(source, "cluster_lms_cr_submit", - "cluster_lms_cr_submit_r4")); + "cluster_lms_cr_submit_r4")); UT_ASSERT(function_uses_common_reserver(source, "cluster_lms_undo_fetch_submit", - "cluster_lms_undo_verdict_submit")); + "cluster_lms_undo_verdict_submit")); UT_ASSERT(function_uses_common_reserver(source, "cluster_lms_undo_verdict_submit", - "cluster_lms_undo_multi_verdict_submit")); + "cluster_lms_undo_multi_verdict_submit")); UT_ASSERT(function_uses_common_reserver(source, "cluster_lms_undo_multi_verdict_submit", - "lms_undo_fetch_serve")); + "lms_undo_fetch_serve")); } free(source); } diff --git a/src/test/cluster_unit/test_cluster_r4_static_model.c b/src/test/cluster_unit/test_cluster_r4_static_model.c index e4491a9f9f6..8344ae73c02 100644 --- a/src/test/cluster_unit/test_cluster_r4_static_model.c +++ b/src/test/cluster_unit/test_cluster_r4_static_model.c @@ -350,7 +350,7 @@ function_region_has_ordered(const char *source, const char *symbol, const char * static bool function_region_has_single_finally_leave(const char *source, const char *symbol, - const char *next_symbol) + const char *next_symbol) { const char *const ordered[] = { "PG_FINALLY();", "cluster_semantic_activation_leave" }; char start_marker[128]; @@ -375,8 +375,8 @@ function_region_has_single_finally_leave(const char *source, const char *symbol, for (cursor = start; (cursor = strstr(cursor, "PG_FINALLY();")) != NULL && cursor < end; cursor += strlen("PG_FINALLY();")) finally_count++; - for (cursor = start; (cursor = strstr(cursor, "cluster_semantic_activation_leave")) != NULL - && cursor < end; + for (cursor = start; + (cursor = strstr(cursor, "cluster_semantic_activation_leave")) != NULL && cursor < end; cursor += strlen("cluster_semantic_activation_leave")) leave_count++; return finally_count == 1 && leave_count == 1; @@ -421,7 +421,7 @@ d10_tt_source_edge_present(void) return source_has_definition(sources.tt_status_source, "cluster_tt_status_lookup_exact") && source_has_definition(sources.tt_status_source, "cluster_tt_status_source_dispatch") && source_has(sources.vis_resolve_source, - "cluster_tt_status_source_dispatch(CLUSTER_TT_SOURCE_LOOKUP"); + "cluster_tt_status_source_dispatch(CLUSTER_TT_SOURCE_LOOKUP"); } static bool @@ -441,10 +441,8 @@ d10_multi_source_edge_present(void) "cluster_multixact_member_overlay_install_raw") && source_has_definition(sources.multixact_source, "cluster_multixact_member_overlay_lookup_raw") - && source_has(sources.multixact_source, - "cluster_multixact_source_dispatch_body(") - && source_has_definition(sources.multixact_source, - "cluster_multixact_source_dispatch"); + && source_has(sources.multixact_source, "cluster_multixact_source_dispatch_body(") + && source_has_definition(sources.multixact_source, "cluster_multixact_source_dispatch"); } static bool @@ -473,16 +471,16 @@ static bool all_four_d10_dispatches_gate_before_body(void) { return dispatch_orders_gate_before_body(sources.gcs_source, "cluster_r4_source_cr_dispatch", - "cluster_gcs_block_cr_fetch_and_wait_raw") + "cluster_gcs_block_cr_fetch_and_wait_raw") && dispatch_orders_gate_before_body(sources.tt_status_source, - "cluster_tt_status_source_dispatch", - "cluster_tt_status_lookup_exact") + "cluster_tt_status_source_dispatch", + "cluster_tt_status_lookup_exact") && dispatch_orders_gate_before_body(sources.tt_hint_source, - "cluster_tt_status_hint_source_dispatch", - "cluster_tt_status_hint_emit_raw") + "cluster_tt_status_hint_source_dispatch", + "cluster_tt_status_hint_emit_raw") && dispatch_orders_gate_before_body(sources.multixact_source, - "cluster_multixact_source_dispatch", - "cluster_multixact_source_dispatch_body"); + "cluster_multixact_source_dispatch", + "cluster_multixact_source_dispatch_body"); } static bool @@ -495,18 +493,17 @@ d10_admitted_wrappers_have_single_finally_leave(void) * cluster_gcs_block_redo_lsn_covered, and each of them legitimately * owns its own PG_FINALLY/leave pair. */ - return function_region_has_single_finally_leave( - sources.gcs_source, "cluster_r4_source_cr_dispatch", - "cluster_gcs_block_undo_tt_fetch_and_wait") - && function_region_has_single_finally_leave( - sources.gcs_source, "cluster_gcs_block_r4_route_cr", - "gcs_block_try_r4_request80") + return function_region_has_single_finally_leave(sources.gcs_source, + "cluster_r4_source_cr_dispatch", + "cluster_gcs_block_undo_tt_fetch_and_wait") && function_region_has_single_finally_leave( - sources.cr_server_source, "cluster_cr_build_on_holder", - "cluster_cr_server_shmem_size") - && function_region_has_single_finally_leave( - sources.tx_resolve_source, "cluster_tx_resolve_exact", - "cluster_tx_resolve_multixact"); + sources.gcs_source, "cluster_gcs_block_r4_route_cr", "gcs_block_try_r4_request80") + && function_region_has_single_finally_leave(sources.cr_server_source, + "cluster_cr_build_on_holder", + "cluster_cr_server_shmem_size") + && function_region_has_single_finally_leave(sources.tx_resolve_source, + "cluster_tx_resolve_exact", + "cluster_tx_resolve_multixact"); } static bool @@ -522,9 +519,8 @@ d10_epoch_sampling_order_is_exact(void) const char *const enter_order[] = { "pg_write_barrier();", "semantic_activation_snapshot(&after)", "epoch_after = cluster_epoch_get_current()" }; - const char *const recheck_order[] - = { "semantic_activation_snapshot(&snapshot)", - "current_epoch = cluster_epoch_get_current()" }; + const char *const recheck_order[] = { "semantic_activation_snapshot(&snapshot)", + "current_epoch = cluster_epoch_get_current()" }; return function_region_has_ordered( sources.semantic_source, "semantic_activation_enter_internal", @@ -552,7 +548,8 @@ legacy_d6_live_page_semantics_present(void) const char *const ordered[] = { "cluster_visibility_resolve_tuple_scn(", "page = BufferGetPage(buffer);", "cluster_itl_get_tt_ref(page, htup->t_itl_slot_idx, &ref)", - "classify_page_ref(page, raw_xid, &ref, anchor_lsn, read_scn, out);" }; + "classify_page_ref(page, htup->t_itl_slot_idx, which, raw_xid, &ref, anchor_lsn,", + "read_scn, out);" }; return source_has_ordered(sources.vis_resolve_source, ordered, lengthof(ordered)); } @@ -654,7 +651,7 @@ contract_actual(int contract_number) && source_has(sources.tt_hint_source, "CLUSTER_TT_STATUS_HINT_V4")) return contract_required[5]; return all_four_d10_source_edges_present() ? "FOUR_SOURCE_EDGES_WITHOUT_ACTIVE_ZERO_PROOF" - : "ABSENT"; + : "ABSENT"; case 7: return semantic_gate && holder_route && sources.tx_resolve_source != NULL ? contract_required[6] @@ -692,8 +689,7 @@ contract_actual(int contract_number) if (source_has(sources.semantic_source, "cluster_semantic_activation_lmon_tick") && source_has(sources.semantic_source, "cluster_semantic_activation_qvotec_poll_record_cas") - && source_has(sources.qvotec_source, - "cluster_semantic_activation_record_cas_write") + && source_has(sources.qvotec_source, "cluster_semantic_activation_record_cas_write") && source_has(sources.semantic_source, "QVOTEC")) return contract_required[10]; return "ABSENT"; @@ -706,7 +702,7 @@ contract_actual(int contract_number) if (semantic_gate && all_four_d10_source_edges_present()) return contract_required[12]; return all_four_d10_source_edges_present() ? "FOUR_SOURCE_EDGES_WITHOUT_COMMON_GATE" - : "ABSENT"; + : "ABSENT"; case 14: if (source_has(sources.semantic_source, "DefineCustomBoolVariable") || source_has(sources.semantic_source, "StartChildProcess") @@ -725,9 +721,8 @@ contract_actual(int contract_number) return contract_required[14]; return "RAW_OLD_SOURCE_LINK_VISIBLE"; case 16: - return semantic_gate && all_four_d10_dispatches_gate_before_body() - ? contract_required[15] - : "ABSENT"; + return semantic_gate && all_four_d10_dispatches_gate_before_body() ? contract_required[15] + : "ABSENT"; case 17: /* XMIN_MISMATCH_FULL_CR_ONLY (spec-8.4 §2.6g / D6 row): an * updated-row XMIN/current-last-writer mismatch enters the FULL-CR @@ -750,7 +745,7 @@ contract_actual(int contract_number) && source_has(sources.heapam_source, "scratch") && full_builder) return contract_required[17]; return legacy_d6_live_page_semantics_present() ? "LIVE_PAGE_FIELDS_NO_SCRATCH_REEVALUATION" - : "ABSENT"; + : "ABSENT"; case 19: if (source_has(sources.gcs_header, "master_resource_transition_count") && source_has(sources.gcs_source, "master_resource_transition_count") @@ -765,11 +760,9 @@ contract_actual(int contract_number) return "ABSENT"; case 21: if (source_has(sources.gcs_header, "cluster_bufmgr_copy_block_for_r4_cr") - && source_has_definition(sources.bufmgr_source, - "cluster_bufmgr_copy_block_for_r4_cr") + && source_has_definition(sources.bufmgr_source, "cluster_bufmgr_copy_block_for_r4_cr") && (source_has(sources.gcs_source, "cluster_bufmgr_copy_block_for_r4_cr(") - || source_has(sources.cr_server_source, - "cluster_bufmgr_copy_block_for_r4_cr("))) + || source_has(sources.cr_server_source, "cluster_bufmgr_copy_block_for_r4_cr("))) return contract_required[20]; return "ABSENT"; default: diff --git a/src/test/cluster_unit/test_cluster_r4_tx_enqueue.c b/src/test/cluster_unit/test_cluster_r4_tx_enqueue.c index e3fb6e191ab..7806cc4fb53 100644 --- a/src/test/cluster_unit/test_cluster_r4_tx_enqueue.c +++ b/src/test/cluster_unit/test_cluster_r4_tx_enqueue.c @@ -28,14 +28,13 @@ static void test_wait_state_write_barrier(void); extern void test_real_wait_state_init(ClusterLmdProcWaitState *ws); extern void test_real_wait_state_reset(ClusterLmdProcWaitState *ws); extern uint64 test_real_wait_state_publish(ClusterLmdProcWaitState *ws, uint8 kind, - uint64 request_id, uint64 cluster_epoch, - TransactionId xid); + uint64 request_id, uint64 cluster_epoch, + TransactionId xid); extern void test_real_wait_state_clear(ClusterLmdProcWaitState *ws); extern ClusterLmdWaitStateReadResult -test_real_wait_state_read_exact(ClusterLmdProcWaitState *ws, - ClusterLmdWaitStateSnapshot *out); +test_real_wait_state_read_exact(ClusterLmdProcWaitState *ws, ClusterLmdWaitStateSnapshot *out); extern bool test_real_wait_state_read(ClusterLmdProcWaitState *ws, - ClusterLmdWaitStateSnapshot *out); + ClusterLmdWaitStateSnapshot *out); #define cluster_lmd_wait_state_init test_real_wait_state_init #define cluster_lmd_wait_state_reset test_real_wait_state_reset @@ -67,9 +66,9 @@ UT_DEFINE_GLOBALS(); #define TEST_XID ((TransactionId)900) #define TEST_EPOCH UINT64CONST(77) -static char test_txw_storage[MAXALIGN(offsetof(ClusterTxwShmem, slots) - + TEST_NSLOTS * sizeof(ClusterTxwWaitSlot))] - pg_attribute_aligned(MAXIMUM_ALIGNOF); +static char test_txw_storage[MAXALIGN( + offsetof(ClusterTxwShmem, slots) + + TEST_NSLOTS * sizeof(ClusterTxwWaitSlot))] pg_attribute_aligned(MAXIMUM_ALIGNOF); static PGPROC test_procs[TEST_NSLOTS]; static PROC_HDR test_proc_hdr; @@ -157,7 +156,8 @@ cluster_cancel_token_consume(void) void ExceptionalCondition(const char *conditionName pg_attribute_unused(), - const char *fileName pg_attribute_unused(), int lineNumber pg_attribute_unused()) + const char *fileName pg_attribute_unused(), + int lineNumber pg_attribute_unused()) { test_exceptional_condition_hit = true; if (test_fail_stop_armed) { @@ -212,7 +212,8 @@ LWLockInitialize(LWLock *lock pg_attribute_unused(), int tranche_id pg_attribute {} void * -ShmemInitStruct(const char *name pg_attribute_unused(), Size size pg_attribute_unused(), bool *found) +ShmemInitStruct(const char *name pg_attribute_unused(), Size size pg_attribute_unused(), + bool *found) { *found = true; return test_txw_storage; @@ -263,8 +264,8 @@ cluster_tx_resolve_exact(const ClusterTxLocator *locator pg_attribute_unused(), ClusterSemanticAdmissionResult cluster_tt_status_source_dispatch(ClusterTTStatusSourceOp op, - const ClusterTTStatusSourceRequest *request, - ClusterTTStatusSourceResult *result) + const ClusterTTStatusSourceRequest *request, + ClusterTTStatusSourceResult *result) { test_legacy_tt_dispatch_calls++; UT_ASSERT_EQ((int)op, (int)CLUSTER_TT_SOURCE_LOOKUP); @@ -280,8 +281,8 @@ cluster_tt_status_source_dispatch(ClusterTTStatusSourceOp op, } uint64 -cluster_lmd_wait_state_publish(ClusterLmdProcWaitState *ws, uint8 kind, - uint64 request_id, uint64 epoch, TransactionId xid) +cluster_lmd_wait_state_publish(ClusterLmdProcWaitState *ws, uint8 kind, uint64 request_id, + uint64 epoch, TransactionId xid) { uint64 wait_seq; @@ -312,8 +313,7 @@ cluster_lmd_wait_state_clear(ClusterLmdProcWaitState *ws) } ClusterLmdWaitStateReadResult -cluster_lmd_wait_state_read_exact(ClusterLmdProcWaitState *ws, - ClusterLmdWaitStateSnapshot *out) +cluster_lmd_wait_state_read_exact(ClusterLmdProcWaitState *ws, ClusterLmdWaitStateSnapshot *out) { ClusterLmdWaitStateReadResult result; @@ -321,8 +321,7 @@ cluster_lmd_wait_state_read_exact(ClusterLmdProcWaitState *ws, if (test_wait_read_override) { *out = test_wait_snapshot; result = test_wait_read_result; - } - else + } else result = test_real_wait_state_read_exact(ws, out); if (test_mutate_slot_during_wait_read) { ClusterTxw->slots[MyProc->pgprocno].waiting = test_mutated_slot_kind; @@ -332,8 +331,8 @@ cluster_lmd_wait_state_read_exact(ClusterLmdProcWaitState *ws, } bool -cluster_lmd_submit_wait_edge_real(const ClusterLmdVertex *waiter, - const ClusterLmdVertex *blocker, uint64 request_id) +cluster_lmd_submit_wait_edge_real(const ClusterLmdVertex *waiter, const ClusterLmdVertex *blocker, + uint64 request_id) { test_wfg_submit_calls++; test_wfg_waiter = *waiter; @@ -362,15 +361,13 @@ cluster_lmd_graph_remove_edge_by_waiter_exact_result(const ClusterLmdVertex *wai test_cleanup_events[test_cleanup_event_count++] = 'G'; if (!test_wfg_live) test_wfg_last_remove_result = CLUSTER_LMD_GRAPH_REMOVE_ABSENT; - else if (waiter->node_id == test_wfg_waiter.node_id - && waiter->procno == test_wfg_waiter.procno + else if (waiter->node_id == test_wfg_waiter.node_id && waiter->procno == test_wfg_waiter.procno && waiter->cluster_epoch == test_wfg_waiter.cluster_epoch && waiter->request_id == test_wfg_waiter.request_id && waiter->wait_seq == test_wfg_waiter.wait_seq) { test_wfg_live = false; test_wfg_last_remove_result = CLUSTER_LMD_GRAPH_REMOVE_REMOVED; - } - else + } else test_wfg_last_remove_result = CLUSTER_LMD_GRAPH_REMOVE_STALE; return test_wfg_last_remove_result; } @@ -439,8 +436,7 @@ test_wait_state_write_barrier(void) return; UT_ASSERT_NOT_NULL(test_wait_write_ws); - test_pending_fatal_saw_odd - = (pg_atomic_read_u32(&test_wait_write_ws->change_seq) & 1U) != 0; + test_pending_fatal_saw_odd = (pg_atomic_read_u32(&test_wait_write_ws->change_seq) & 1U) != 0; test_pending_fatal_saw_holdoff = InterruptHoldoffCount > 0; InterruptPending = true; test_pending_fatal_delivery = true; @@ -494,15 +490,13 @@ prepare_owned_active_wait(uint32 slot_kind, bool insert_edge) ClusterTTStatusKey source = test_source_key(); txw_slot_set(0, &source, false); - } - else { + } else { ClusterTxLocator locator = test_locator(); UT_ASSERT(txw_target_slot_set_if_free(0, &locator)); } - wait_seq = cluster_lmd_wait_state_publish(&MyProc->cluster_lmd_wait, - CLUSTER_LMD_WAIT_TX, 0, TEST_EPOCH, - test_local_xid); + wait_seq = cluster_lmd_wait_state_publish(&MyProc->cluster_lmd_wait, CLUSTER_LMD_WAIT_TX, 0, + TEST_EPOCH, test_local_xid); txw_exact_waiter_vertex(&test_wfg_waiter, 0, TEST_EPOCH, test_local_xid, wait_seq); memset(&blocker, 0, sizeof(blocker)); test_wfg_blocker = blocker; @@ -666,13 +660,12 @@ assert_d9_authorities_equal(const TestD9AuthoritySnapshot *expected) { UT_ASSERT_EQ(memcmp(&ClusterTxw->slots[0], &expected->slot, sizeof(expected->slot)), 0); UT_ASSERT_EQ(pg_atomic_read_u32(&ClusterTxw->active_waiters), expected->active_waiters); - UT_ASSERT_EQ(memcmp(&MyProc->cluster_lmd_wait, &expected->wait_state, - sizeof(expected->wait_state)), 0); + UT_ASSERT_EQ( + memcmp(&MyProc->cluster_lmd_wait, &expected->wait_state, sizeof(expected->wait_state)), 0); UT_ASSERT_EQ(test_wfg_live, expected->wfg_live); - UT_ASSERT_EQ(memcmp(&test_wfg_waiter, &expected->wfg_waiter, - sizeof(expected->wfg_waiter)), 0); - UT_ASSERT_EQ(memcmp(&test_wfg_blocker, &expected->wfg_blocker, - sizeof(expected->wfg_blocker)), 0); + UT_ASSERT_EQ(memcmp(&test_wfg_waiter, &expected->wfg_waiter, sizeof(expected->wfg_waiter)), 0); + UT_ASSERT_EQ(memcmp(&test_wfg_blocker, &expected->wfg_blocker, sizeof(expected->wfg_blocker)), + 0); } static void @@ -994,8 +987,7 @@ UT_TEST(test_current_mx_source_wait_consumes_deadlock_token_after_cleanup) reset_fixture(); test_cancel_token_pending = true; - UT_ASSERT_EQ(cluster_tx_enqueue_wait_current_mx(&source, 1000, - &deadline_mono_us), + UT_ASSERT_EQ(cluster_tx_enqueue_wait_current_mx(&source, 1000, &deadline_mono_us), CLUSTER_TXW_DEADLOCK); UT_ASSERT(deadline_mono_us != 0); UT_ASSERT(!test_cancel_token_pending); @@ -1014,8 +1006,7 @@ UT_TEST(test_current_mx_active_poll_retries_without_dormant_source) /* A terminal legacy SOURCE row must not decide an active R4 wait. */ test_legacy_tt_found = true; test_legacy_tt_status = CLUSTER_TT_STATUS_COMMITTED; - UT_ASSERT_EQ(cluster_tx_enqueue_wait_current_mx(&source, 1000, - &deadline_mono_us), + UT_ASSERT_EQ(cluster_tx_enqueue_wait_current_mx(&source, 1000, &deadline_mono_us), CLUSTER_TXW_RETRY); UT_ASSERT(deadline_mono_us != 0); frozen_deadline_mono_us = deadline_mono_us; @@ -1026,8 +1017,7 @@ UT_TEST(test_current_mx_active_poll_retries_without_dormant_source) assert_slot_clean(); /* A full tuple/DESCRIBE retry keeps the original operation deadline. */ - UT_ASSERT_EQ(cluster_tx_enqueue_wait_current_mx(&source, 1000, - &deadline_mono_us), + UT_ASSERT_EQ(cluster_tx_enqueue_wait_current_mx(&source, 1000, &deadline_mono_us), CLUSTER_TXW_RETRY); UT_ASSERT_EQ(deadline_mono_us, frozen_deadline_mono_us); UT_ASSERT_EQ(test_legacy_tt_dispatch_calls, 0); @@ -1036,8 +1026,7 @@ UT_TEST(test_current_mx_active_poll_retries_without_dormant_source) /* An exhausted retained budget times out after exact registration cleanup. */ deadline_mono_us = 1; - UT_ASSERT_EQ(cluster_tx_enqueue_wait_current_mx(&source, 1000, - &deadline_mono_us), + UT_ASSERT_EQ(cluster_tx_enqueue_wait_current_mx(&source, 1000, &deadline_mono_us), CLUSTER_TXW_TIMEOUT); UT_ASSERT_EQ(deadline_mono_us, 1); UT_ASSERT_EQ(test_legacy_tt_dispatch_calls, 0); @@ -1063,9 +1052,8 @@ UT_TEST(test_backend_exit_cleans_exact_target_and_allows_procno_reuse) reset_fixture(); UT_ASSERT(txw_target_slot_set_if_free(0, &locator)); - wait_seq = cluster_lmd_wait_state_publish(&MyProc->cluster_lmd_wait, - CLUSTER_LMD_WAIT_TX, 0, TEST_EPOCH, - test_local_xid); + wait_seq = cluster_lmd_wait_state_publish(&MyProc->cluster_lmd_wait, CLUSTER_LMD_WAIT_TX, 0, + TEST_EPOCH, test_local_xid); txw_exact_waiter_vertex(&waiter, 0, TEST_EPOCH, test_local_xid, wait_seq); memset(&blocker, 0, sizeof(blocker)); UT_ASSERT(cluster_lmd_submit_wait_edge_real(&waiter, &blocker, 0)); @@ -1099,9 +1087,8 @@ UT_TEST(test_backend_exit_cleans_exact_source_and_allows_procno_reuse) reset_fixture(); txw_slot_set(0, &source, false); - wait_seq = cluster_lmd_wait_state_publish(&MyProc->cluster_lmd_wait, - CLUSTER_LMD_WAIT_TX, 0, TEST_EPOCH, - test_local_xid); + wait_seq = cluster_lmd_wait_state_publish(&MyProc->cluster_lmd_wait, CLUSTER_LMD_WAIT_TX, 0, + TEST_EPOCH, test_local_xid); txw_exact_waiter_vertex(&waiter, 0, TEST_EPOCH, test_local_xid, wait_seq); memset(&blocker, 0, sizeof(blocker)); UT_ASSERT(cluster_lmd_submit_wait_edge_real(&waiter, &blocker, 0)); @@ -1299,12 +1286,10 @@ UT_TEST(test_pending_fatal_during_wait_state_publish_finishes_even_before_exit) test_inject_pending_fatal = true; if (sigsetjmp(test_fail_stop_stack, 1) == 0) { test_fail_stop_armed = true; - (void)cluster_lmd_wait_state_publish(&MyProc->cluster_lmd_wait, - CLUSTER_LMD_WAIT_TX, 0, TEST_EPOCH, - test_local_xid); + (void)cluster_lmd_wait_state_publish(&MyProc->cluster_lmd_wait, CLUSTER_LMD_WAIT_TX, 0, + TEST_EPOCH, test_local_xid); test_fail_stop_armed = false; - } - else { + } else { test_fail_stop_armed = false; caught = true; } @@ -1342,8 +1327,7 @@ UT_TEST(test_pending_fatal_during_wait_state_clear_finishes_even_before_exit) test_fail_stop_armed = true; cluster_lmd_wait_state_clear(&MyProc->cluster_lmd_wait); test_fail_stop_armed = false; - } - else { + } else { test_fail_stop_armed = false; caught = true; } diff --git a/src/test/cluster_unit/test_cluster_r4_tx_locator.c b/src/test/cluster_unit/test_cluster_r4_tx_locator.c index b55f9c1e52d..c32518694b7 100644 --- a/src/test/cluster_unit/test_cluster_r4_tx_locator.c +++ b/src/test/cluster_unit/test_cluster_r4_tx_locator.c @@ -20,11 +20,9 @@ extern ClusterTxOutcome cluster_runtime_visibility_resolve_exact_origin_admitted const ClusterSemanticAdmissionToken *admission, ClusterTxResolution *out, ClusterTxResolveReason *reason_out); extern ClusterTxOutcome cluster_runtime_visibility_resolve_exact_origin( - const ClusterTxLocator *locator, ClusterTxResolveMode mode, - uint64 formation_epoch, ClusterTxResolution *out, - ClusterTxResolveReason *reason_out); -extern ClusterTxOutcome -cluster_runtime_visibility_resolve_terminal_census_retained_exact( + const ClusterTxLocator *locator, ClusterTxResolveMode mode, uint64 formation_epoch, + ClusterTxResolution *out, ClusterTxResolveReason *reason_out); +extern ClusterTxOutcome cluster_runtime_visibility_resolve_terminal_census_retained_exact( const ClusterTxLocator *locator, SCN retained_commit_scn, const ClusterSemanticAdmissionToken *admission, ClusterTxResolution *out, ClusterTxResolveReason *reason_out); @@ -122,12 +120,10 @@ cluster_semantic_activation_enter(uint64 feature_bit, ClusterSemanticAdmissionSi } ClusterSemanticAdmissionResult -cluster_semantic_activation_enter_r4_terminal_census( - ClusterSemanticAdmissionToken *token) +cluster_semantic_activation_enter_r4_terminal_census(ClusterSemanticAdmissionToken *token) { test_terminal_census_enter_calls++; - if (test_terminal_census_admission_result - == CLUSTER_SEMANTIC_ADMISSION_OK) { + if (test_terminal_census_admission_result == CLUSTER_SEMANTIC_ADMISSION_OK) { memset(token, 0, sizeof(*token)); token->feature_bit = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1; token->record_generation = UINT64_C(73); @@ -147,13 +143,11 @@ cluster_semantic_activation_recheck(const ClusterSemanticAdmissionToken *token) } bool -cluster_semantic_activation_recheck_r4_terminal_census( - const ClusterSemanticAdmissionToken *token) +cluster_semantic_activation_recheck_r4_terminal_census(const ClusterSemanticAdmissionToken *token) { test_terminal_census_recheck_calls++; UT_ASSERT(token->entered); - UT_ASSERT_EQ(token->feature_bit, - CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1); + UT_ASSERT_EQ(token->feature_bit, CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1); UT_ASSERT_EQ(token->side, CLUSTER_SEMANTIC_TARGET_SIDE); return test_terminal_census_recheck_result; } @@ -188,10 +182,10 @@ cluster_conf_node_count(void) } ClusterTxOutcome -cluster_runtime_visibility_resolve_exact_origin( - const ClusterTxLocator *locator, ClusterTxResolveMode mode, - uint64 formation_epoch, ClusterTxResolution *out, - ClusterTxResolveReason *reason_out) +cluster_runtime_visibility_resolve_exact_origin(const ClusterTxLocator *locator, + ClusterTxResolveMode mode, uint64 formation_epoch, + ClusterTxResolution *out, + ClusterTxResolveReason *reason_out) { test_provider_calls++; test_legacy_provider_calls++; @@ -219,8 +213,7 @@ cluster_runtime_visibility_resolve_exact_origin_admitted( { test_provider_calls++; test_admitted_provider_calls++; - UT_ASSERT(mode == CLUSTER_TX_RESOLVE_VISIBILITY - || mode == CLUSTER_TX_RESOLVE_TERMINAL_CENSUS); + UT_ASSERT(mode == CLUSTER_TX_RESOLVE_VISIBILITY || mode == CLUSTER_TX_RESOLVE_TERMINAL_CENSUS); if (test_provider_raise) siglongjmp(*PG_exception_stack, 1); test_provider_locator = *locator; @@ -238,8 +231,8 @@ ClusterTxOutcome cluster_runtime_visibility_resolve_terminal_census_retained_exact( const ClusterTxLocator *locator pg_attribute_unused(), SCN retained_commit_scn pg_attribute_unused(), - const ClusterSemanticAdmissionToken *admission pg_attribute_unused(), - ClusterTxResolution *out, ClusterTxResolveReason *reason_out) + const ClusterSemanticAdmissionToken *admission pg_attribute_unused(), ClusterTxResolution *out, + ClusterTxResolveReason *reason_out) { memset(out, 0, sizeof(*out)); *reason_out = CLUSTER_TX_RESOLVE_AUTHORITY_UNAVAILABLE; @@ -379,8 +372,7 @@ prepare_epoch_zero_partial_visibility_fixture(void) test_formation_epoch = 0; test_node_count = 4; locator.tt_wrap = TT_WRAP_INVALID; - locator.uba.raw[0] = (locator.uba.raw[0] & UINT64_C(0xffffffff00000000)) - | UINT64_C(257); + locator.uba.raw[0] = (locator.uba.raw[0] & UINT64_C(0xffffffff00000000)) | UINT64_C(257); test_provider_resolution.locator_echo = locator; test_provider_resolution.locator_echo.tt_wrap = 7; test_provider_resolution.authority.origin_epoch = 0; @@ -388,17 +380,16 @@ prepare_epoch_zero_partial_visibility_fixture(void) } static void -assert_epoch_zero_refused(const ClusterTxLocator *locator, - ClusterTxResolveMode mode, - const ClusterSemanticAdmissionToken *admission, - ClusterTxResolveReason expected_reason) +assert_epoch_zero_refused(const ClusterTxLocator *locator, ClusterTxResolveMode mode, + const ClusterSemanticAdmissionToken *admission, + ClusterTxResolveReason expected_reason) { ClusterTxResolution resolution; ClusterTxResolveReason reason = CLUSTER_TX_RESOLVE_NONE; memset(&resolution, 0xA5, sizeof(resolution)); - UT_ASSERT_EQ(cluster_tx_resolve_exact_admitted( - locator, mode, admission, &resolution, &reason), CLUSTER_TX_UNKNOWN); + UT_ASSERT_EQ(cluster_tx_resolve_exact_admitted(locator, mode, admission, &resolution, &reason), + CLUSTER_TX_UNKNOWN); UT_ASSERT_EQ(reason, expected_reason); UT_ASSERT_EQ(test_provider_calls, 0); UT_ASSERT(bytes_are_zero(&resolution, sizeof(resolution))); @@ -506,9 +497,9 @@ UT_TEST(test_exact_resolver_binds_exact_origin_provider_and_publishes_only_after reset_exact_resolver_fixture(); memset(&resolution, 0xA5, sizeof(resolution)); - UT_ASSERT_EQ(cluster_tx_resolve_exact(&locator, CLUSTER_TX_RESOLVE_ROW_WAIT, &resolution, - &reason), - CLUSTER_TX_COMMITTED); + UT_ASSERT_EQ( + cluster_tx_resolve_exact(&locator, CLUSTER_TX_RESOLVE_ROW_WAIT, &resolution, &reason), + CLUSTER_TX_COMMITTED); UT_ASSERT_EQ(reason, CLUSTER_TX_RESOLVE_NONE); UT_ASSERT_EQ(test_enter_calls, 1); UT_ASSERT_EQ(test_provider_calls, 1); @@ -538,16 +529,14 @@ UT_TEST(test_exact_resolver_observes_each_positive_outcome_once) ClusterTxProofKind proof; ClusterR4Event event; SCN commit_scn; - } cases[] = { - {CLUSTER_TX_IN_PROGRESS, CLUSTER_TX_PROOF_ORIGIN_DURABLE_TT_CLOG, - CLUSTER_R4_EVENT_TX_IN_PROGRESS, InvalidScn}, - {CLUSTER_TX_PREPARED, CLUSTER_TX_PROOF_ORIGIN_TWOPHASE, - CLUSTER_R4_EVENT_TX_PREPARED, InvalidScn}, - {CLUSTER_TX_COMMITTED, CLUSTER_TX_PROOF_ORIGIN_DURABLE_TT_CLOG, - CLUSTER_R4_EVENT_TX_COMMITTED, (SCN)101}, - {CLUSTER_TX_ABORTED, CLUSTER_TX_PROOF_ORIGIN_DURABLE_TT_CLOG, - CLUSTER_R4_EVENT_TX_ABORTED, InvalidScn} - }; + } cases[] = { { CLUSTER_TX_IN_PROGRESS, CLUSTER_TX_PROOF_ORIGIN_DURABLE_TT_CLOG, + CLUSTER_R4_EVENT_TX_IN_PROGRESS, InvalidScn }, + { CLUSTER_TX_PREPARED, CLUSTER_TX_PROOF_ORIGIN_TWOPHASE, + CLUSTER_R4_EVENT_TX_PREPARED, InvalidScn }, + { CLUSTER_TX_COMMITTED, CLUSTER_TX_PROOF_ORIGIN_DURABLE_TT_CLOG, + CLUSTER_R4_EVENT_TX_COMMITTED, (SCN)101 }, + { CLUSTER_TX_ABORTED, CLUSTER_TX_PROOF_ORIGIN_DURABLE_TT_CLOG, + CLUSTER_R4_EVENT_TX_ABORTED, InvalidScn } }; ClusterTxLocator locator = exact_locator(); int i; @@ -560,9 +549,9 @@ UT_TEST(test_exact_resolver_observes_each_positive_outcome_once) test_provider_resolution.outcome = cases[i].outcome; test_provider_resolution.proof_kind = cases[i].proof; test_provider_resolution.commit_scn = cases[i].commit_scn; - UT_ASSERT_EQ(cluster_tx_resolve_exact(&locator, CLUSTER_TX_RESOLVE_VISIBILITY, - &resolution, &reason), - cases[i].outcome); + UT_ASSERT_EQ( + cluster_tx_resolve_exact(&locator, CLUSTER_TX_RESOLVE_VISIBILITY, &resolution, &reason), + cases[i].outcome); UT_ASSERT_EQ(reason, CLUSTER_TX_RESOLVE_NONE); UT_ASSERT_EQ(test_observed[cases[i].event], 1); UT_ASSERT_EQ(observed_total(), 1); @@ -578,9 +567,9 @@ UT_TEST(test_exact_resolver_rejects_mismatched_locator_echo) reset_exact_resolver_fixture(); test_provider_resolution.locator_echo.tt_wrap++; memset(&resolution, 0xA5, sizeof(resolution)); - UT_ASSERT_EQ(cluster_tx_resolve_exact(&locator, CLUSTER_TX_RESOLVE_VISIBILITY, &resolution, - &reason), - CLUSTER_TX_UNKNOWN); + UT_ASSERT_EQ( + cluster_tx_resolve_exact(&locator, CLUSTER_TX_RESOLVE_VISIBILITY, &resolution, &reason), + CLUSTER_TX_UNKNOWN); UT_ASSERT_EQ(reason, CLUSTER_TX_RESOLVE_PROTOCOL); UT_ASSERT_EQ(test_provider_calls, 1); UT_ASSERT_EQ(test_recheck_calls, 0); @@ -599,9 +588,9 @@ UT_TEST(test_exact_resolver_discards_provider_result_when_activation_generation_ reset_exact_resolver_fixture(); test_recheck_result = false; memset(&resolution, 0xA5, sizeof(resolution)); - UT_ASSERT_EQ(cluster_tx_resolve_exact(&locator, CLUSTER_TX_RESOLVE_CR_BUILD, &resolution, - &reason), - CLUSTER_TX_UNKNOWN); + UT_ASSERT_EQ( + cluster_tx_resolve_exact(&locator, CLUSTER_TX_RESOLVE_CR_BUILD, &resolution, &reason), + CLUSTER_TX_UNKNOWN); UT_ASSERT_EQ(reason, CLUSTER_TX_RESOLVE_RF_DEFERRED); UT_ASSERT_EQ(test_provider_calls, 1); UT_ASSERT_EQ(test_recheck_calls, 1); @@ -623,9 +612,9 @@ UT_TEST(test_exact_cleanout_consumer_rejects_live_provider_outcome) test_provider_resolution.proof_kind = CLUSTER_TX_PROOF_ORIGIN_DURABLE_TT_CLOG; test_provider_resolution.commit_scn = InvalidScn; memset(&resolution, 0xA5, sizeof(resolution)); - UT_ASSERT_EQ(cluster_tx_resolve_exact(&locator, CLUSTER_TX_RESOLVE_CLEANOUT_HINT, &resolution, - &reason), - CLUSTER_TX_UNKNOWN); + UT_ASSERT_EQ( + cluster_tx_resolve_exact(&locator, CLUSTER_TX_RESOLVE_CLEANOUT_HINT, &resolution, &reason), + CLUSTER_TX_UNKNOWN); UT_ASSERT_EQ(reason, CLUSTER_TX_RESOLVE_PROTOCOL); UT_ASSERT_EQ(test_provider_calls, 1); UT_ASSERT_EQ(test_recheck_calls, 0); @@ -644,9 +633,8 @@ UT_TEST(test_exact_terminal_census_uses_only_scoped_inactive_target_admission) reset_exact_resolver_fixture(); test_admission_result = CLUSTER_SEMANTIC_ADMISSION_TARGET_DISABLED; memset(&resolution, 0xA5, sizeof(resolution)); - UT_ASSERT_EQ(cluster_tx_resolve_exact( - &locator, CLUSTER_TX_RESOLVE_TERMINAL_CENSUS, - &resolution, &reason), + UT_ASSERT_EQ(cluster_tx_resolve_exact(&locator, CLUSTER_TX_RESOLVE_TERMINAL_CENSUS, &resolution, + &reason), CLUSTER_TX_COMMITTED); UT_ASSERT_EQ(reason, CLUSTER_TX_RESOLVE_NONE); UT_ASSERT_EQ(test_enter_calls, 0); @@ -674,9 +662,8 @@ UT_TEST(test_exact_terminal_census_rejects_prepared_provider_outcome) test_provider_resolution.proof_kind = CLUSTER_TX_PROOF_ORIGIN_TWOPHASE; test_provider_resolution.commit_scn = InvalidScn; memset(&resolution, 0xA5, sizeof(resolution)); - UT_ASSERT_EQ(cluster_tx_resolve_exact( - &locator, CLUSTER_TX_RESOLVE_TERMINAL_CENSUS, - &resolution, &reason), + UT_ASSERT_EQ(cluster_tx_resolve_exact(&locator, CLUSTER_TX_RESOLVE_TERMINAL_CENSUS, &resolution, + &reason), CLUSTER_TX_UNKNOWN); UT_ASSERT_EQ(reason, CLUSTER_TX_RESOLVE_PROTOCOL); UT_ASSERT_EQ(test_enter_calls, 0); @@ -703,9 +690,8 @@ UT_TEST(test_exact_terminal_census_admitted_uses_caller_token_without_reentry) admission.side = CLUSTER_SEMANTIC_TARGET_SIDE; admission.entered = true; memset(&resolution, 0xA5, sizeof(resolution)); - UT_ASSERT_EQ(cluster_tx_resolve_exact_admitted( - &locator, CLUSTER_TX_RESOLVE_TERMINAL_CENSUS, - &admission, &resolution, &reason), + UT_ASSERT_EQ(cluster_tx_resolve_exact_admitted(&locator, CLUSTER_TX_RESOLVE_TERMINAL_CENSUS, + &admission, &resolution, &reason), CLUSTER_TX_COMMITTED); UT_ASSERT_EQ(reason, CLUSTER_TX_RESOLVE_NONE); UT_ASSERT_EQ(test_enter_calls, 0); @@ -733,9 +719,8 @@ UT_TEST(test_partial_terminal_census_accepts_one_canonical_provider_echo) admission.side = CLUSTER_SEMANTIC_TARGET_SIDE; admission.entered = true; memset(&resolution, 0xA5, sizeof(resolution)); - UT_ASSERT_EQ(cluster_tx_resolve_exact_admitted( - &locator, CLUSTER_TX_RESOLVE_TERMINAL_CENSUS, - &admission, &resolution, &reason), + UT_ASSERT_EQ(cluster_tx_resolve_exact_admitted(&locator, CLUSTER_TX_RESOLVE_TERMINAL_CENSUS, + &admission, &resolution, &reason), CLUSTER_TX_COMMITTED); UT_ASSERT_EQ(reason, CLUSTER_TX_RESOLVE_NONE); UT_ASSERT_EQ(test_provider_locator.tt_wrap, TT_WRAP_INVALID); @@ -752,8 +737,8 @@ UT_TEST(test_partial_visibility_uses_exact_admitted_provider_and_canonical_echo) reset_exact_resolver_fixture(); locator.tt_wrap = TT_WRAP_INVALID; memset(&resolution, 0xA5, sizeof(resolution)); - UT_ASSERT_EQ(cluster_tx_resolve_exact( - &locator, CLUSTER_TX_RESOLVE_VISIBILITY, &resolution, &reason), + UT_ASSERT_EQ( + cluster_tx_resolve_exact(&locator, CLUSTER_TX_RESOLVE_VISIBILITY, &resolution, &reason), CLUSTER_TX_COMMITTED); UT_ASSERT_EQ(reason, CLUSTER_TX_RESOLVE_NONE); UT_ASSERT_EQ(test_enter_calls, 1); @@ -777,11 +762,10 @@ UT_TEST(test_partial_visibility_publishes_exact_in_progress_but_terminal_census_ locator.tt_wrap = TT_WRAP_INVALID; test_provider_outcome = CLUSTER_TX_IN_PROGRESS; test_provider_resolution.outcome = CLUSTER_TX_IN_PROGRESS; - test_provider_resolution.proof_kind - = CLUSTER_TX_PROOF_ORIGIN_DURABLE_TT_CLOG; + test_provider_resolution.proof_kind = CLUSTER_TX_PROOF_ORIGIN_DURABLE_TT_CLOG; test_provider_resolution.commit_scn = InvalidScn; - UT_ASSERT_EQ(cluster_tx_resolve_exact( - &locator, CLUSTER_TX_RESOLVE_VISIBILITY, &resolution, &reason), + UT_ASSERT_EQ( + cluster_tx_resolve_exact(&locator, CLUSTER_TX_RESOLVE_VISIBILITY, &resolution, &reason), CLUSTER_TX_IN_PROGRESS); UT_ASSERT_EQ(reason, CLUSTER_TX_RESOLVE_NONE); UT_ASSERT_EQ(test_admitted_provider_calls, 1); @@ -790,13 +774,12 @@ UT_TEST(test_partial_visibility_publishes_exact_in_progress_but_terminal_census_ locator.tt_wrap = TT_WRAP_INVALID; test_provider_outcome = CLUSTER_TX_IN_PROGRESS; test_provider_resolution.outcome = CLUSTER_TX_IN_PROGRESS; - test_provider_resolution.proof_kind - = CLUSTER_TX_PROOF_ORIGIN_DURABLE_TT_CLOG; + test_provider_resolution.proof_kind = CLUSTER_TX_PROOF_ORIGIN_DURABLE_TT_CLOG; test_provider_resolution.commit_scn = InvalidScn; memset(&resolution, 0xA5, sizeof(resolution)); - UT_ASSERT_EQ(cluster_tx_resolve_exact( - &locator, CLUSTER_TX_RESOLVE_TERMINAL_CENSUS, - &resolution, &reason), CLUSTER_TX_UNKNOWN); + UT_ASSERT_EQ(cluster_tx_resolve_exact(&locator, CLUSTER_TX_RESOLVE_TERMINAL_CENSUS, &resolution, + &reason), + CLUSTER_TX_UNKNOWN); UT_ASSERT_EQ(reason, CLUSTER_TX_RESOLVE_PROTOCOL); UT_ASSERT(bytes_are_zero(&resolution, sizeof(resolution))); } @@ -810,9 +793,9 @@ UT_TEST(test_epoch_zero_terminal_census_local_single_node_publishes_exact_termin prepare_epoch_zero_terminal_fixture(&admission); memset(&resolution, 0xA5, sizeof(resolution)); - UT_ASSERT_EQ(cluster_tx_resolve_exact_admitted( - &locator, CLUSTER_TX_RESOLVE_TERMINAL_CENSUS, - &admission, &resolution, &reason), CLUSTER_TX_COMMITTED); + UT_ASSERT_EQ(cluster_tx_resolve_exact_admitted(&locator, CLUSTER_TX_RESOLVE_TERMINAL_CENSUS, + &admission, &resolution, &reason), + CLUSTER_TX_COMMITTED); UT_ASSERT_EQ(reason, CLUSTER_TX_RESOLVE_NONE); UT_ASSERT_EQ(test_provider_calls, 1); UT_ASSERT_EQ(test_admitted_provider_calls, 1); @@ -834,13 +817,12 @@ UT_TEST(test_epoch_zero_terminal_census_homogeneous_four_node_foreign_publishes_ /* The homogeneous clean-formation override binds the exact current * admission generation; it is not limited to the pre-PGSA zero sentinel. */ admission.record_generation = UINT64_C(73); - locator.uba.raw[0] = (locator.uba.raw[0] & UINT64_C(0xffffffff00000000)) - | UINT64_C(257); + locator.uba.raw[0] = (locator.uba.raw[0] & UINT64_C(0xffffffff00000000)) | UINT64_C(257); test_provider_resolution.locator_echo = locator; memset(&resolution, 0xA5, sizeof(resolution)); - UT_ASSERT_EQ(cluster_tx_resolve_exact_admitted( - &locator, CLUSTER_TX_RESOLVE_TERMINAL_CENSUS, - &admission, &resolution, &reason), CLUSTER_TX_COMMITTED); + UT_ASSERT_EQ(cluster_tx_resolve_exact_admitted(&locator, CLUSTER_TX_RESOLVE_TERMINAL_CENSUS, + &admission, &resolution, &reason), + CLUSTER_TX_COMMITTED); UT_ASSERT_EQ(reason, CLUSTER_TX_RESOLVE_NONE); UT_ASSERT_EQ(test_provider_calls, 1); UT_ASSERT_EQ(test_admitted_provider_calls, 1); @@ -859,8 +841,8 @@ UT_TEST(test_epoch_zero_partial_visibility_homogeneous_four_node_uses_exact_stat ClusterTxResolveReason reason = CLUSTER_TX_RESOLVE_PROTOCOL; memset(&resolution, 0xA5, sizeof(resolution)); - UT_ASSERT_EQ(cluster_tx_resolve_exact( - &locator, CLUSTER_TX_RESOLVE_VISIBILITY, &resolution, &reason), + UT_ASSERT_EQ( + cluster_tx_resolve_exact(&locator, CLUSTER_TX_RESOLVE_VISIBILITY, &resolution, &reason), CLUSTER_TX_COMMITTED); UT_ASSERT_EQ(reason, CLUSTER_TX_RESOLVE_NONE); UT_ASSERT_EQ(test_enter_calls, 1); @@ -885,8 +867,8 @@ UT_TEST(test_epoch_zero_complete_visibility_remains_fail_closed) locator.tt_wrap = 7; test_provider_resolution.locator_echo = locator; memset(&resolution, 0xA5, sizeof(resolution)); - UT_ASSERT_EQ(cluster_tx_resolve_exact( - &locator, CLUSTER_TX_RESOLVE_VISIBILITY, &resolution, &reason), + UT_ASSERT_EQ( + cluster_tx_resolve_exact(&locator, CLUSTER_TX_RESOLVE_VISIBILITY, &resolution, &reason), CLUSTER_TX_UNKNOWN); UT_ASSERT_EQ(reason, CLUSTER_TX_RESOLVE_RF_DEFERRED); UT_ASSERT_EQ(test_provider_calls, 0); @@ -979,8 +961,8 @@ UT_TEST(test_epoch_zero_partial_visibility_generation_drift_refuses_before_provi test_recheck_result = false; memset(&resolution, 0xA5, sizeof(resolution)); - UT_ASSERT_EQ(cluster_tx_resolve_exact( - &locator, CLUSTER_TX_RESOLVE_VISIBILITY, &resolution, &reason), + UT_ASSERT_EQ( + cluster_tx_resolve_exact(&locator, CLUSTER_TX_RESOLVE_VISIBILITY, &resolution, &reason), CLUSTER_TX_UNKNOWN); UT_ASSERT_EQ(reason, CLUSTER_TX_RESOLVE_RF_DEFERRED); UT_ASSERT_EQ(test_provider_calls, 0); @@ -995,8 +977,8 @@ UT_TEST(test_epoch_zero_terminal_census_peer_topology_refuses_before_provider) prepare_epoch_zero_terminal_fixture(&admission); test_node_count = 2; - assert_epoch_zero_refused(&locator, CLUSTER_TX_RESOLVE_TERMINAL_CENSUS, - &admission, CLUSTER_TX_RESOLVE_RF_DEFERRED); + assert_epoch_zero_refused(&locator, CLUSTER_TX_RESOLVE_TERMINAL_CENSUS, &admission, + CLUSTER_TX_RESOLVE_RF_DEFERRED); } UT_TEST(test_epoch_zero_terminal_census_unknown_topology_refuses_before_provider) @@ -1006,8 +988,8 @@ UT_TEST(test_epoch_zero_terminal_census_unknown_topology_refuses_before_provider prepare_epoch_zero_terminal_fixture(&admission); test_node_count = 0; - assert_epoch_zero_refused(&locator, CLUSTER_TX_RESOLVE_TERMINAL_CENSUS, - &admission, CLUSTER_TX_RESOLVE_RF_DEFERRED); + assert_epoch_zero_refused(&locator, CLUSTER_TX_RESOLVE_TERMINAL_CENSUS, &admission, + CLUSTER_TX_RESOLVE_RF_DEFERRED); } UT_TEST(test_epoch_zero_terminal_census_foreign_locator_refuses_before_provider) @@ -1016,10 +998,9 @@ UT_TEST(test_epoch_zero_terminal_census_foreign_locator_refuses_before_provider) ClusterSemanticAdmissionToken admission; prepare_epoch_zero_terminal_fixture(&admission); - locator.uba.raw[0] = (locator.uba.raw[0] & UINT64_C(0xffffffff00000000)) - | UINT64_C(257); - assert_epoch_zero_refused(&locator, CLUSTER_TX_RESOLVE_TERMINAL_CENSUS, - &admission, CLUSTER_TX_RESOLVE_RF_DEFERRED); + locator.uba.raw[0] = (locator.uba.raw[0] & UINT64_C(0xffffffff00000000)) | UINT64_C(257); + assert_epoch_zero_refused(&locator, CLUSTER_TX_RESOLVE_TERMINAL_CENSUS, &admission, + CLUSTER_TX_RESOLVE_RF_DEFERRED); } UT_TEST(test_epoch_zero_terminal_census_nonterminal_mode_refuses_before_provider) @@ -1028,8 +1009,8 @@ UT_TEST(test_epoch_zero_terminal_census_nonterminal_mode_refuses_before_provider ClusterSemanticAdmissionToken admission; prepare_epoch_zero_terminal_fixture(&admission); - assert_epoch_zero_refused(&locator, CLUSTER_TX_RESOLVE_VISIBILITY, - &admission, CLUSTER_TX_RESOLVE_PROTOCOL); + assert_epoch_zero_refused(&locator, CLUSTER_TX_RESOLVE_VISIBILITY, &admission, + CLUSTER_TX_RESOLVE_PROTOCOL); } UT_TEST(test_epoch_zero_terminal_census_recovery_refuses_before_provider) @@ -1039,8 +1020,8 @@ UT_TEST(test_epoch_zero_terminal_census_recovery_refuses_before_provider) prepare_epoch_zero_terminal_fixture(&admission); cluster_recmerge_window_active = true; - assert_epoch_zero_refused(&locator, CLUSTER_TX_RESOLVE_TERMINAL_CENSUS, - &admission, CLUSTER_TX_RESOLVE_RF_DEFERRED); + assert_epoch_zero_refused(&locator, CLUSTER_TX_RESOLVE_TERMINAL_CENSUS, &admission, + CLUSTER_TX_RESOLVE_RF_DEFERRED); } UT_TEST(test_epoch_zero_terminal_census_single_node_nonzero_generation_refuses_before_provider) @@ -1050,8 +1031,8 @@ UT_TEST(test_epoch_zero_terminal_census_single_node_nonzero_generation_refuses_b prepare_epoch_zero_terminal_fixture(&admission); admission.record_generation = 1; - assert_epoch_zero_refused(&locator, CLUSTER_TX_RESOLVE_TERMINAL_CENSUS, - &admission, CLUSTER_TX_RESOLVE_RF_DEFERRED); + assert_epoch_zero_refused(&locator, CLUSTER_TX_RESOLVE_TERMINAL_CENSUS, &admission, + CLUSTER_TX_RESOLVE_RF_DEFERRED); } UT_TEST(test_epoch_zero_terminal_census_current_generation_drift_refuses_before_provider) @@ -1062,8 +1043,8 @@ UT_TEST(test_epoch_zero_terminal_census_current_generation_drift_refuses_before_ prepare_epoch_zero_terminal_fixture(&admission); test_node_count = 4; test_terminal_census_recheck_result = false; - assert_epoch_zero_refused(&locator, CLUSTER_TX_RESOLVE_TERMINAL_CENSUS, - &admission, CLUSTER_TX_RESOLVE_RF_DEFERRED); + assert_epoch_zero_refused(&locator, CLUSTER_TX_RESOLVE_TERMINAL_CENSUS, &admission, + CLUSTER_TX_RESOLVE_RF_DEFERRED); } UT_TEST(test_epoch_zero_terminal_census_storage_disabled_refuses_before_provider) @@ -1073,8 +1054,8 @@ UT_TEST(test_epoch_zero_terminal_census_storage_disabled_refuses_before_provider prepare_epoch_zero_terminal_fixture(&admission); cluster_enabled = false; - assert_epoch_zero_refused(&locator, CLUSTER_TX_RESOLVE_TERMINAL_CENSUS, - &admission, CLUSTER_TX_RESOLVE_RF_DEFERRED); + assert_epoch_zero_refused(&locator, CLUSTER_TX_RESOLVE_TERMINAL_CENSUS, &admission, + CLUSTER_TX_RESOLVE_RF_DEFERRED); } UT_TEST(test_epoch_zero_terminal_census_zero_to_nonzero_drift_discards_provider_result) @@ -1087,9 +1068,9 @@ UT_TEST(test_epoch_zero_terminal_census_zero_to_nonzero_drift_discards_provider_ prepare_epoch_zero_terminal_fixture(&admission); test_provider_mutates_epoch = true; memset(&resolution, 0xA5, sizeof(resolution)); - UT_ASSERT_EQ(cluster_tx_resolve_exact_admitted( - &locator, CLUSTER_TX_RESOLVE_TERMINAL_CENSUS, - &admission, &resolution, &reason), CLUSTER_TX_UNKNOWN); + UT_ASSERT_EQ(cluster_tx_resolve_exact_admitted(&locator, CLUSTER_TX_RESOLVE_TERMINAL_CENSUS, + &admission, &resolution, &reason), + CLUSTER_TX_UNKNOWN); UT_ASSERT_EQ(reason, CLUSTER_TX_RESOLVE_RF_DEFERRED); UT_ASSERT_EQ(test_provider_calls, 1); UT_ASSERT_EQ(test_terminal_census_recheck_calls, 1); @@ -1233,8 +1214,7 @@ UT_TEST(test_terminal_census_locator_keeps_page_wrap_out_of_durable_request) ClusterTxResolveReason reason; set_slot(page, 0, ITL_FLAG_ACTIVE, (TransactionId)919, 6, 9, 17, 6, 1); - UT_ASSERT(cluster_tx_locator_from_itl_terminal_census( - page, 0, &locator, &reason)); + UT_ASSERT(cluster_tx_locator_from_itl_terminal_census(page, 0, &locator, &reason)); UT_ASSERT_EQ(reason, CLUSTER_TX_RESOLVE_NONE); UT_ASSERT_EQ(locator.tt_wrap, TT_WRAP_INVALID); } diff --git a/src/test/cluster_unit/test_cluster_r4_tx_outcome.c b/src/test/cluster_unit/test_cluster_r4_tx_outcome.c index 800ff0872b4..cc3454cff22 100644 --- a/src/test/cluster_unit/test_cluster_r4_tx_outcome.c +++ b/src/test/cluster_unit/test_cluster_r4_tx_outcome.c @@ -174,10 +174,8 @@ static int test_remote_origin_calls; static uint32 test_remote_origin_generation; static ClusterTxOutcome test_remote_origin_outcome; static bool test_remote_origin_revoke_admission; -static ClusterUndoBlock0CurrentStep test_candidate_acquire_step - = CLUSTER_UNDO_BLOCK0_CURRENT_HELD; -static ClusterUndoBlock0CurrentStep test_candidate_poll_step - = CLUSTER_UNDO_BLOCK0_CURRENT_FAILED; +static ClusterUndoBlock0CurrentStep test_candidate_acquire_step = CLUSTER_UNDO_BLOCK0_CURRENT_HELD; +static ClusterUndoBlock0CurrentStep test_candidate_poll_step = CLUSTER_UNDO_BLOCK0_CURRENT_FAILED; static ClusterUndoBlock0CurrentStep test_candidate_after_wait_step = CLUSTER_UNDO_BLOCK0_CURRENT_FAILED; @@ -190,7 +188,8 @@ cluster_vis_evidence_note(ClusterVisEvidenceMetric metric) void ExceptionalCondition(const char *conditionName pg_attribute_unused(), - const char *fileName pg_attribute_unused(), int lineNumber pg_attribute_unused()) + const char *fileName pg_attribute_unused(), + int lineNumber pg_attribute_unused()) { abort(); } @@ -304,9 +303,10 @@ cluster_undo_get_record(UBA uba, void *out_buffer, size_t buffer_size) } bool -cluster_tt_slot_durable_lookup_committed_stable( - uint32 segment_id, uint16 slot_offset, TransactionId xid, uint32 expected_wrap, - ClusterTTDurableXidCommitCheck xid_committed, SCN *commit_scn) +cluster_tt_slot_durable_lookup_committed_stable(uint32 segment_id, uint16 slot_offset, + TransactionId xid, uint32 expected_wrap, + ClusterTTDurableXidCommitCheck xid_committed, + SCN *commit_scn) { test_tt_exact_calls++; test_tt_segment_seen = segment_id; @@ -322,17 +322,16 @@ cluster_tt_slot_durable_lookup_committed_stable( } bool -cluster_tt_slot_durable_read_exact_stable(uint32 segment_id, uint16 slot_offset, - TransactionId xid, uint16 expected_wrap, - TTSlot *slot_out) +cluster_tt_slot_durable_read_exact_stable(uint32 segment_id, uint16 slot_offset, TransactionId xid, + uint16 expected_wrap, TTSlot *slot_out) { test_tt_snapshot_calls++; test_tt_segment_seen = segment_id; test_tt_slot_seen = slot_offset; test_tt_xid_seen = xid; test_tt_wrap_seen = expected_wrap; - if (slot_out == NULL || test_tt_slot.status > TT_SLOT_RECYCLABLE - || test_tt_slot.xid != xid || test_tt_slot.wrap != expected_wrap) + if (slot_out == NULL || test_tt_slot.status > TT_SLOT_RECYCLABLE || test_tt_slot.xid != xid + || test_tt_slot.wrap != expected_wrap) return false; *slot_out = test_tt_slot; return true; @@ -352,9 +351,9 @@ cluster_tt_slot_durable_resolve_by_xid_origin(int origin_node pg_attribute_unuse } ClusterTTDurableLocate -cluster_tt_slot_durable_locate_any_by_xid_origin(int origin_node, - TransactionId xid, uint16 *out_seg, uint16 *out_slot, - uint16 *out_wrap, uint8 *out_status) +cluster_tt_slot_durable_locate_any_by_xid_origin(int origin_node, TransactionId xid, + uint16 *out_seg, uint16 *out_slot, + uint16 *out_wrap, uint8 *out_status) { UT_ASSERT_EQ(origin_node, 0); UT_ASSERT_EQ((int)xid, (int)TEST_ORIGIN_XID); @@ -397,8 +396,8 @@ cluster_qvotec_get_self_incarnation(void) } bool -cluster_reconfig_get_observed_slot(int32 node_id pg_attribute_unused(), - uint64 *incarnation, uint64 *generation) +cluster_reconfig_get_observed_slot(int32 node_id pg_attribute_unused(), uint64 *incarnation, + uint64 *generation) { if (incarnation != NULL) *incarnation = 0; @@ -414,15 +413,14 @@ cluster_reconfig_get_observed_epoch(int32 node_id pg_attribute_unused()) } uint64 -cluster_membership_get_last_admitted_incarnation( - int32 node_id pg_attribute_unused()) +cluster_membership_get_last_admitted_incarnation(int32 node_id pg_attribute_unused()) { return 0; } ClusterSemanticAdmissionResult -cluster_semantic_activation_enter(uint64 feature_bit, - ClusterSemanticAdmissionSide side, ClusterSemanticAdmissionToken *token) +cluster_semantic_activation_enter(uint64 feature_bit, ClusterSemanticAdmissionSide side, + ClusterSemanticAdmissionToken *token) { UT_ASSERT_NOT_NULL(token); UT_ASSERT_EQ(feature_bit, CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1); @@ -490,7 +488,7 @@ SubTransGetParent(TransactionId xid) if (test_subtrans_mutate_recheck && phase > 0 && i == 0) return test_subtrans_chain[i] - 2; return i + 1 < test_subtrans_chain_count ? test_subtrans_chain[i + 1] - : InvalidTransactionId; + : InvalidTransactionId; } UT_ASSERT(false); return InvalidTransactionId; @@ -540,16 +538,14 @@ test_admission_token_exact(const ClusterSemanticAdmissionToken *token) } bool -cluster_semantic_activation_recheck( - const ClusterSemanticAdmissionToken *token) +cluster_semantic_activation_recheck(const ClusterSemanticAdmissionToken *token) { test_regular_admission_recheck_calls++; return test_admission_token_exact(token); } bool -cluster_semantic_activation_recheck_r4_terminal_census( - const ClusterSemanticAdmissionToken *token) +cluster_semantic_activation_recheck_r4_terminal_census(const ClusterSemanticAdmissionToken *token) { test_terminal_census_recheck_calls++; return test_admission_token_exact(token); @@ -557,8 +553,8 @@ cluster_semantic_activation_recheck_r4_terminal_census( static bool test_resolve_shared_undo_root(const ClusterSemanticAdmissionToken *token, - ClusterUndoPathIntent intent, uint32 owner_instance, uint32 segment_id, - ClusterUndoBlock0ResolvedRoot *out) + ClusterUndoPathIntent intent, uint32 owner_instance, + uint32 segment_id, ClusterUndoBlock0ResolvedRoot *out) { UT_ASSERT(test_admission_token_exact(token)); UT_ASSERT_EQ(intent, CLUSTER_UNDO_PATH_RUNTIME_SHARED); @@ -571,43 +567,36 @@ test_resolve_shared_undo_root(const ClusterSemanticAdmissionToken *token, } bool -cluster_semantic_activation_resolve_shared_undo_root( - const ClusterSemanticAdmissionToken *token, ClusterUndoPathIntent intent, - uint32 owner_instance, uint32 segment_id, - ClusterUndoBlock0ResolvedRoot *out) +cluster_semantic_activation_resolve_shared_undo_root(const ClusterSemanticAdmissionToken *token, + ClusterUndoPathIntent intent, + uint32 owner_instance, uint32 segment_id, + ClusterUndoBlock0ResolvedRoot *out) { test_regular_root_resolve_calls++; - return test_resolve_shared_undo_root(token, intent, owner_instance, - segment_id, out); + return test_resolve_shared_undo_root(token, intent, owner_instance, segment_id, out); } bool cluster_semantic_activation_resolve_shared_undo_root_r4_terminal_census( - const ClusterSemanticAdmissionToken *token, ClusterUndoPathIntent intent, - uint32 owner_instance, uint32 segment_id, - ClusterUndoBlock0ResolvedRoot *out) + const ClusterSemanticAdmissionToken *token, ClusterUndoPathIntent intent, uint32 owner_instance, + uint32 segment_id, ClusterUndoBlock0ResolvedRoot *out) { test_terminal_census_root_resolve_calls++; - return test_resolve_shared_undo_root(token, intent, owner_instance, - segment_id, out); + return test_resolve_shared_undo_root(token, intent, owner_instance, segment_id, out); } ClusterUndoBlock0CurrentStep cluster_undo_block0_current_acquire_begin_admitted( const ClusterUndoBlock0LogicalKey *key, ClusterUndoBlock0CurrentMode mode, - int timeout_ms pg_attribute_unused(), - const ClusterSemanticAdmissionToken *admission, + int timeout_ms pg_attribute_unused(), const ClusterSemanticAdmissionToken *admission, ClusterUndoBlock0CurrentGuard *guard pg_attribute_unused(), ClusterUndoBlock0Result *failure pg_attribute_unused()) { - UT_ASSERT(test_candidate_acquire_calls - < (int)lengthof(test_candidate_acquire_segments)); - test_candidate_acquire_segments[test_candidate_acquire_calls] - = key->segment_id; + UT_ASSERT(test_candidate_acquire_calls < (int)lengthof(test_candidate_acquire_segments)); + test_candidate_acquire_segments[test_candidate_acquire_calls] = key->segment_id; test_candidate_acquire_calls++; UT_ASSERT_EQ(key->owner_instance, 1); - UT_ASSERT(key->segment_id == TEST_RECORD_SEGMENT - || key->segment_id == TEST_TT_SEGMENT); + UT_ASSERT(key->segment_id == TEST_RECORD_SEGMENT || key->segment_id == TEST_TT_SEGMENT); UT_ASSERT_EQ(mode, CLUSTER_UNDO_BLOCK0_SCUR); UT_ASSERT(test_admission_token_exact(admission)); if (test_candidate_acquire_step == CLUSTER_UNDO_BLOCK0_CURRENT_HELD) { @@ -619,9 +608,8 @@ cluster_undo_block0_current_acquire_begin_admitted( } ClusterUndoBlock0CurrentStep -cluster_undo_block0_current_acquire_poll( - ClusterUndoBlock0CurrentGuard *guard pg_attribute_unused(), - ClusterUndoBlock0Result *failure pg_attribute_unused()) +cluster_undo_block0_current_acquire_poll(ClusterUndoBlock0CurrentGuard *guard pg_attribute_unused(), + ClusterUndoBlock0Result *failure pg_attribute_unused()) { test_candidate_poll_calls++; if (test_candidate_poll_step == CLUSTER_UNDO_BLOCK0_CURRENT_HELD) { @@ -649,8 +637,7 @@ cluster_undo_block0_current_wait_reply(ClusterUndoBlock0CurrentGuard *guard pg_a ClusterUndoBlock0Result cluster_undo_block0_current_sample_generation( ClusterUndoBlock0CurrentGuard *guard pg_attribute_unused(), - const ClusterUndoBlock0ResolvedRoot *root, - ClusterUndoBlock0Generation *observed) + const ClusterUndoBlock0ResolvedRoot *root, ClusterUndoBlock0Generation *observed) { test_candidate_sample_calls++; UT_ASSERT(root->root_id == 91 || root->root_id == 92); @@ -664,8 +651,8 @@ cluster_undo_block0_current_sample_generation( ClusterUndoBlock0Result cluster_undo_block0_current_copy_resident( ClusterUndoBlock0CurrentGuard *guard pg_attribute_unused(), - const ClusterUndoBlock0ResolvedRoot *root, - const ClusterUndoBlock0Generation *expected, char private_page[BLCKSZ]) + const ClusterUndoBlock0ResolvedRoot *root, const ClusterUndoBlock0Generation *expected, + char private_page[BLCKSZ]) { UndoSegmentHeaderData *header = (UndoSegmentHeaderData *)private_page; @@ -680,8 +667,7 @@ cluster_undo_block0_current_copy_resident( } bool -cluster_tt_slot_current_owner_by_xid(int node_id, TransactionId xid, - ClusterTTSlotCurrentOwner *out) +cluster_tt_slot_current_owner_by_xid(int node_id, TransactionId xid, ClusterTTSlotCurrentOwner *out) { ClusterTTSlotCurrentOwner sampled; @@ -700,8 +686,7 @@ cluster_tt_slot_current_owner_by_xid(int node_id, TransactionId xid, } bool -cluster_tt_local_get_published_binding(TransactionId xid, - ClusterCanonicalTxnBinding *out) +cluster_tt_local_get_published_binding(TransactionId xid, ClusterCanonicalTxnBinding *out) { ClusterCanonicalTxnBinding sampled; @@ -720,8 +705,8 @@ cluster_tt_local_get_published_binding(TransactionId xid, ClusterCtrcTouchResult cluster_ctrc_origin_touch_exact(const ClusterCtrcTxnKeyV1 *key, - const ClusterCtrcParticipantIdentity *participant, - ClusterCtrcProofClass proof_class, uint32 *grant_out) + const ClusterCtrcParticipantIdentity *participant, + ClusterCtrcProofClass proof_class, uint32 *grant_out) { test_ctrc_touch_calls++; UT_ASSERT_NOT_NULL(key); @@ -735,8 +720,7 @@ cluster_ctrc_origin_touch_exact(const ClusterCtrcTxnKeyV1 *key, UT_ASSERT_EQ(participant->node_id, (uint16)cluster_node_id); UT_ASSERT_EQ(proof_class, CTRC_PROOF_ACTIVE); *grant_out = test_ctrc_touch_grant; - return test_ctrc_touch_grant == 0 - ? CLUSTER_CTRC_TOUCH_REFUSED : CLUSTER_CTRC_TOUCH_RECORDED; + return test_ctrc_touch_grant == 0 ? CLUSTER_CTRC_TOUCH_REFUSED : CLUSTER_CTRC_TOUCH_RECORDED; } uint32 @@ -744,8 +728,7 @@ cluster_tt_slot_current_segment(int node_id) { test_current_segment_calls++; UT_ASSERT_EQ(node_id, cluster_node_id); - if (test_current_segment_drift_on_recheck - && test_current_segment_calls > 1) + if (test_current_segment_drift_on_recheck && test_current_segment_calls > 1) return test_current_segment + 1; return test_current_segment; } @@ -758,16 +741,15 @@ cluster_xid_is_mine(TransactionId xid) } bool -cluster_cr_server_local_freshref_c1b_pair_exact( - TransactionId xid, uint32 expected_segment_id, - uint32 expected_tt_slot_id, SCN proposed_scn, uint16 *out_wrap) +cluster_cr_server_local_freshref_c1b_pair_exact(TransactionId xid, uint32 expected_segment_id, + uint32 expected_tt_slot_id, SCN proposed_scn, + uint16 *out_wrap) { test_local_freshref_pair_calls++; - UT_ASSERT_EQ((int) xid, (int) TEST_ORIGIN_XID); + UT_ASSERT_EQ((int)xid, (int)TEST_ORIGIN_XID); UT_ASSERT_EQ(expected_segment_id, TEST_RECORD_SEGMENT); - UT_ASSERT_EQ(expected_tt_slot_id, - (uint32) TEST_TT_OFFSET + 1); - UT_ASSERT_EQ((uint64) proposed_scn, (uint64) test_commit_scn); + UT_ASSERT_EQ(expected_tt_slot_id, (uint32)TEST_TT_OFFSET + 1); + UT_ASSERT_EQ((uint64)proposed_scn, (uint64)test_commit_scn); UT_ASSERT_NOT_NULL(out_wrap); if (!test_local_freshref_pair_exact) return false; @@ -780,8 +762,7 @@ cluster_cr_native_prehistory_reader_lock(void) { test_native_fence_lock_calls++; test_native_fence_depth++; - if (test_no_raw_reuse_drift_on_recheck - && test_native_fence_lock_calls > 1) + if (test_no_raw_reuse_drift_on_recheck && test_native_fence_lock_calls > 1) test_no_raw_reuse_window = false; } @@ -843,8 +824,7 @@ LWLockReleaseAll(void) } bool -cluster_undo_buf_copy_resident(uint32 segment_id, uint8 owner, - uint32 block_no, char dst[BLCKSZ]) +cluster_undo_buf_copy_resident(uint32 segment_id, uint8 owner, uint32 block_no, char dst[BLCKSZ]) { test_candidate_data_copy_calls++; UT_ASSERT_EQ(segment_id, TEST_RECORD_SEGMENT); @@ -892,15 +872,14 @@ cluster_undo_buf_unpin(ClusterUndoBufPin *pin) } bool -cluster_cr_r4_extract_resident_record( - const char resident_undo_page[BLCKSZ] pg_attribute_unused(), - const ClusterTxLocator *request_locator, char record_out[BLCKSZ], - size_t *record_length_out, ClusterTxLocator *canonical_locator_out) +cluster_cr_r4_extract_resident_record(const char resident_undo_page[BLCKSZ] pg_attribute_unused(), + const ClusterTxLocator *request_locator, + char record_out[BLCKSZ], size_t *record_length_out, + ClusterTxLocator *canonical_locator_out) { test_candidate_extract_calls++; UT_ASSERT_EQ(request_locator->tt_wrap, TT_WRAP_INVALID); - if (test_candidate_mutate_record_on_recheck - && test_candidate_extract_calls == 2) + if (test_candidate_mutate_record_on_recheck && test_candidate_extract_calls == 2) test_origin_record.payload_length++; memcpy(record_out, &test_origin_record, sizeof(test_origin_record)); *record_length_out = sizeof(test_origin_record); @@ -910,9 +889,9 @@ cluster_cr_r4_extract_resident_record( } ClusterUndoBlock0CurrentStep -cluster_undo_block0_current_release_begin( - ClusterUndoBlock0CurrentGuard *guard pg_attribute_unused(), - ClusterUndoBlock0Result *failure pg_attribute_unused()) +cluster_undo_block0_current_release_begin(ClusterUndoBlock0CurrentGuard *guard + pg_attribute_unused(), + ClusterUndoBlock0Result *failure pg_attribute_unused()) { test_candidate_release_calls++; UT_ASSERT(test_candidate_held_count > 0); @@ -921,17 +900,15 @@ cluster_undo_block0_current_release_begin( } ClusterUndoBlock0CurrentStep -cluster_undo_block0_current_release_poll( - ClusterUndoBlock0CurrentGuard *guard pg_attribute_unused(), - ClusterUndoBlock0Result *failure pg_attribute_unused()) +cluster_undo_block0_current_release_poll(ClusterUndoBlock0CurrentGuard *guard pg_attribute_unused(), + ClusterUndoBlock0Result *failure pg_attribute_unused()) { UT_ASSERT(false); return CLUSTER_UNDO_BLOCK0_CURRENT_FAILED; } void -cluster_undo_block0_current_cancel( - ClusterUndoBlock0CurrentGuard *guard pg_attribute_unused()) +cluster_undo_block0_current_cancel(ClusterUndoBlock0CurrentGuard *guard pg_attribute_unused()) { test_candidate_cancel_calls++; } @@ -1028,8 +1005,7 @@ reset_exact_origin_fixture(void) test_candidate_wakes_before_terminal = 1; memset(test_vis_evidence, 0, sizeof(test_vis_evidence)); test_candidate_exit_hooks_ensure_calls = 0; - memset(test_candidate_acquire_segments, 0, - sizeof(test_candidate_acquire_segments)); + memset(test_candidate_acquire_segments, 0, sizeof(test_candidate_acquire_segments)); test_candidate_held_count = 0; test_candidate_max_held_count = 0; test_candidate_extract_calls = 0; @@ -1135,11 +1111,9 @@ static const bool expected[5][8] = { * is only a locator/corroboration input; no SOURCE overlay participates. */ extern bool cluster_runtime_visibility_current_owner_sample_held( TransactionId xid, const ClusterTTSlotCurrentOwner *expected_owner, - const ClusterSemanticAdmissionToken *admission, - ClusterUndoBlock0CurrentGuard *guard, - const ClusterUndoBlock0ResolvedRoot *root, - ClusterTTStatusKey *key_out, ClusterTTStatusResult *result_out, - bool *ctrc_physical_active_out); + const ClusterSemanticAdmissionToken *admission, ClusterUndoBlock0CurrentGuard *guard, + const ClusterUndoBlock0ResolvedRoot *root, ClusterTTStatusKey *key_out, + ClusterTTStatusResult *result_out, bool *ctrc_physical_active_out); static void run_pair(unsigned int pair) @@ -1150,8 +1124,11 @@ run_pair(unsigned int pair) UT_ASSERT_EQ(cluster_tx_outcome_proof_is_valid(outcome, proof), expected[outcome][proof]); } -#define DEFINE_PAIR_TEST(n) \ - UT_TEST(test_outcome_proof_pair_##n) { run_pair(n); } +#define DEFINE_PAIR_TEST(n) \ + UT_TEST(test_outcome_proof_pair_##n) \ + { \ + run_pair(n); \ + } #define RUN_PAIR_TEST(n) UT_RUN(test_outcome_proof_pair_##n) @@ -1236,12 +1213,10 @@ UT_TEST(test_current_member_target_canonical_active_requires_exact_physical_slot memset(&result, 0xa5, sizeof(result)); UT_ASSERT(cluster_runtime_visibility_current_owner_sample_held( - TEST_ORIGIN_XID, &test_current_owner, &admission, &guard, &root, - &key, &result, NULL)); + TEST_ORIGIN_XID, &test_current_owner, &admission, &guard, &root, &key, &result, NULL)); UT_ASSERT_EQ(key.origin_node_id, (uint16)cluster_node_id); UT_ASSERT_EQ(key.undo_segment_id, (uint16)TEST_TT_SEGMENT); - UT_ASSERT_EQ(key.tt_slot_id, - cluster_tt_slot_offset_to_id(TEST_TT_OFFSET)); + UT_ASSERT_EQ(key.tt_slot_id, cluster_tt_slot_offset_to_id(TEST_TT_OFFSET)); UT_ASSERT_EQ(key.cluster_epoch, (uint32)test_formation_epoch); UT_ASSERT_EQ(key.local_xid, TEST_ORIGIN_XID); UT_ASSERT_EQ(result.status, CLUSTER_TT_STATUS_IN_PROGRESS); @@ -1257,8 +1232,7 @@ UT_TEST(test_current_member_target_canonical_active_requires_exact_physical_slot memset(&key, 0xa5, sizeof(key)); memset(&result, 0xa5, sizeof(result)); UT_ASSERT(!cluster_runtime_visibility_current_owner_sample_held( - TEST_ORIGIN_XID, &test_current_owner, &admission, &guard, &root, - &key, &result, NULL)); + TEST_ORIGIN_XID, &test_current_owner, &admission, &guard, &root, &key, &result, NULL)); UT_ASSERT_EQ(result.status, CLUSTER_TT_STATUS_UNKNOWN); UT_ASSERT(!result.authoritative); @@ -1267,15 +1241,13 @@ UT_TEST(test_current_member_target_canonical_active_requires_exact_physical_slot test_candidate_copy_physical_slot = true; test_tt_slot.wrap++; UT_ASSERT(!cluster_runtime_visibility_current_owner_sample_held( - TEST_ORIGIN_XID, &test_current_owner, &admission, &guard, &root, - &key, &result, NULL)); + TEST_ORIGIN_XID, &test_current_owner, &admission, &guard, &root, &key, &result, NULL)); test_tt_slot.wrap = TEST_ORIGIN_WRAP; /* The shared fixture mutates on its third owner sample. */ test_current_owner_calls = 2; test_current_owner_drift_on_recheck = true; UT_ASSERT(!cluster_runtime_visibility_current_owner_sample_held( - TEST_ORIGIN_XID, &test_current_owner, &admission, &guard, &root, - &key, &result, NULL)); + TEST_ORIGIN_XID, &test_current_owner, &admission, &guard, &root, &key, &result, NULL)); } /* MXA-T19 x MXA-T20: the visibility bracket deliberately keeps a physical @@ -1307,8 +1279,8 @@ UT_TEST(test_ctrc_physical_active_sample_excludes_precommit_committed_window) root.root_generation = 7; UT_ASSERT(cluster_runtime_visibility_current_owner_sample_held( - TEST_ORIGIN_XID, &test_current_owner, &admission, &guard, &root, - &key, &result, &physical_active)); + TEST_ORIGIN_XID, &test_current_owner, &admission, &guard, &root, &key, &result, + &physical_active)); UT_ASSERT_EQ(result.status, CLUSTER_TT_STATUS_IN_PROGRESS); UT_ASSERT_EQ(result.commit_scn, InvalidScn); UT_ASSERT(!physical_active); @@ -1317,8 +1289,8 @@ UT_TEST(test_ctrc_physical_active_sample_excludes_precommit_committed_window) test_tt_slot.commit_scn = InvalidScn; test_current_owner_calls = 0; UT_ASSERT(cluster_runtime_visibility_current_owner_sample_held( - TEST_ORIGIN_XID, &test_current_owner, &admission, &guard, &root, - &key, &result, &physical_active)); + TEST_ORIGIN_XID, &test_current_owner, &admission, &guard, &root, &key, &result, + &physical_active)); UT_ASSERT(physical_active); } @@ -1351,15 +1323,13 @@ UT_TEST(test_ctrc_current_owner_uses_published_binding_across_rollover) memset(&participant, 0xa5, sizeof(participant)); UT_ASSERT(cluster_runtime_visibility_current_owner_lookup_exact_ctrc_full( - TEST_ORIGIN_XID, &status_key, &status, &grant, &ctrc_key, - &participant)); + TEST_ORIGIN_XID, &status_key, &status, &grant, &ctrc_key, &participant)); UT_ASSERT_EQ(status.status, CLUSTER_TT_STATUS_IN_PROGRESS); UT_ASSERT(status.authoritative); UT_ASSERT_EQ(grant, test_ctrc_touch_grant); UT_ASSERT_EQ(status_key.undo_segment_id, (uint16)TEST_TT_SEGMENT); UT_ASSERT_EQ(ctrc_key.segment_id, TEST_TT_SEGMENT); - UT_ASSERT_EQ(ctrc_key.segment_generation, - test_local_binding.segment_generation); + UT_ASSERT_EQ(ctrc_key.segment_generation, test_local_binding.segment_generation); UT_ASSERT_EQ(ctrc_key.slot_offset, TEST_TT_OFFSET); UT_ASSERT_EQ(ctrc_key.slot_wrap, TEST_ORIGIN_WRAP); UT_ASSERT_EQ(test_local_binding_calls, 2); @@ -1377,8 +1347,7 @@ UT_TEST(test_ctrc_current_owner_uses_published_binding_across_rollover) test_local_binding_available = true; test_local_binding.segment_generation = 22; UT_ASSERT(!cluster_runtime_visibility_current_owner_lookup_exact_ctrc_full( - TEST_ORIGIN_XID, &status_key, &status, &grant, &ctrc_key, - &participant)); + TEST_ORIGIN_XID, &status_key, &status, &grant, &ctrc_key, &participant)); UT_ASSERT_EQ(test_ctrc_touch_calls, 0); /* Binding drift during the physical sample is equally fail closed. */ @@ -1392,8 +1361,7 @@ UT_TEST(test_ctrc_current_owner_uses_published_binding_across_rollover) test_local_binding_available = true; test_local_binding_drift_on_recheck = true; UT_ASSERT(!cluster_runtime_visibility_current_owner_lookup_exact_ctrc_full( - TEST_ORIGIN_XID, &status_key, &status, &grant, &ctrc_key, - &participant)); + TEST_ORIGIN_XID, &status_key, &status, &grant, &ctrc_key, &participant)); UT_ASSERT_EQ(test_ctrc_touch_calls, 0); } @@ -1418,8 +1386,8 @@ UT_TEST(test_current_mx_active_proof_reconstructs_exact_ctrc_identity) memset(&ctrc_key, 0xa5, sizeof(ctrc_key)); memset(&participant, 0xa5, sizeof(participant)); - UT_ASSERT(cluster_runtime_visibility_active_proof_ctrc_identity_exact( - &proof_key, 17, 313, &ctrc_key, &participant)); + UT_ASSERT(cluster_runtime_visibility_active_proof_ctrc_identity_exact(&proof_key, 17, 313, + &ctrc_key, &participant)); UT_ASSERT_EQ(ctrc_key.format_version, CLUSTER_CTRC_FORMAT_VERSION); UT_ASSERT_EQ(ctrc_key.origin_node_id, 0); UT_ASSERT_EQ(ctrc_key.owner_instance, 1); @@ -1434,8 +1402,7 @@ UT_TEST(test_current_mx_active_proof_reconstructs_exact_ctrc_identity) UT_ASSERT_EQ(participant.capability_record_generation, (uint32)313); UT_ASSERT_EQ(participant.formation_epoch, test_formation_epoch); UT_ASSERT_EQ(participant.admission_record_generation, (uint64)77); - UT_ASSERT_EQ(participant.admission_record_generation, - ctrc_key.admission_record_generation); + UT_ASSERT_EQ(participant.admission_record_generation, ctrc_key.admission_record_generation); memset(&ctrc_key, 0xa5, sizeof(ctrc_key)); memset(&participant, 0xa5, sizeof(participant)); @@ -1471,8 +1438,8 @@ UT_TEST(test_current_mx_active_proof_uses_origin_binding_without_foreign_storage memset(&ctrc_key, 0xa5, sizeof(ctrc_key)); memset(&participant, 0xa5, sizeof(participant)); - UT_ASSERT(cluster_runtime_visibility_active_proof_ctrc_identity_exact( - &proof_key, 17, 313, &ctrc_key, &participant)); + UT_ASSERT(cluster_runtime_visibility_active_proof_ctrc_identity_exact(&proof_key, 17, 313, + &ctrc_key, &participant)); UT_ASSERT_EQ(test_candidate_acquire_calls, 0); UT_ASSERT_EQ(test_candidate_sample_calls, 0); UT_ASSERT_EQ(test_candidate_block0_copy_calls, 0); @@ -1519,32 +1486,31 @@ UT_TEST(test_current_member_rolled_terminal_uses_locator_then_canonical_scur) locator.slot_offset = TEST_TT_OFFSET; locator.wrap = TEST_ORIGIN_WRAP; - UT_ASSERT(cluster_runtime_visibility_physical_locator_sample_held( - &locator, &admission, &guard, &root, &key, &result, NULL)); + UT_ASSERT(cluster_runtime_visibility_physical_locator_sample_held(&locator, &admission, &guard, + &root, &key, &result, NULL)); UT_ASSERT_EQ(result.status, CLUSTER_TT_STATUS_ABORTED); UT_ASSERT(result.authoritative); UT_ASSERT_EQ(key.undo_segment_id, (uint16)TEST_TT_SEGMENT); - UT_ASSERT_EQ(key.tt_slot_id, - cluster_tt_slot_offset_to_id(TEST_TT_OFFSET)); + UT_ASSERT_EQ(key.tt_slot_id, cluster_tt_slot_offset_to_id(TEST_TT_OFFSET)); UT_ASSERT_EQ(test_current_owner_calls, 0); UT_ASSERT_EQ(test_current_segment_calls, 2); /* Locator status is never a verdict: missing/mismatched canonical bytes * and allocator rollover drift remain UNKNOWN. */ test_candidate_copy_physical_slot = false; - UT_ASSERT(!cluster_runtime_visibility_physical_locator_sample_held( - &locator, &admission, &guard, &root, &key, &result, NULL)); + UT_ASSERT(!cluster_runtime_visibility_physical_locator_sample_held(&locator, &admission, &guard, + &root, &key, &result, NULL)); UT_ASSERT_EQ(result.status, CLUSTER_TT_STATUS_UNKNOWN); UT_ASSERT(!result.authoritative); test_candidate_copy_physical_slot = true; test_tt_slot.xid++; - UT_ASSERT(!cluster_runtime_visibility_physical_locator_sample_held( - &locator, &admission, &guard, &root, &key, &result, NULL)); + UT_ASSERT(!cluster_runtime_visibility_physical_locator_sample_held(&locator, &admission, &guard, + &root, &key, &result, NULL)); test_tt_slot.xid = TEST_ORIGIN_XID; test_current_segment_calls = 0; test_current_segment_drift_on_recheck = true; - UT_ASSERT(!cluster_runtime_visibility_physical_locator_sample_held( - &locator, &admission, &guard, &root, &key, &result, NULL)); + UT_ASSERT(!cluster_runtime_visibility_physical_locator_sample_held(&locator, &admission, &guard, + &root, &key, &result, NULL)); } UT_TEST(test_current_member_terminal_on_current_segment_survives_retired_owner_index) @@ -1583,8 +1549,8 @@ UT_TEST(test_current_member_terminal_on_current_segment_survives_retired_owner_i /* A terminal canonical slot remains authoritative after its allocator * owner entry retires, even while the allocator still uses the segment. */ - UT_ASSERT(cluster_runtime_visibility_physical_locator_sample_held( - &locator, &admission, &guard, &root, &key, &result, NULL)); + UT_ASSERT(cluster_runtime_visibility_physical_locator_sample_held(&locator, &admission, &guard, + &root, &key, &result, NULL)); UT_ASSERT_EQ(result.status, CLUSTER_TT_STATUS_COMMITTED); UT_ASSERT_EQ(result.commit_scn, test_commit_scn); UT_ASSERT(result.authoritative); @@ -1610,12 +1576,11 @@ UT_TEST(test_current_member_local_terminal_accepts_clean_formation_epoch_zero) memset(&key, 0xa5, sizeof(key)); memset(&result, 0xa5, sizeof(result)); - UT_ASSERT(cluster_runtime_visibility_local_terminal_lookup_exact( - TEST_ORIGIN_XID, &key, &result)); + UT_ASSERT( + cluster_runtime_visibility_local_terminal_lookup_exact(TEST_ORIGIN_XID, &key, &result)); UT_ASSERT_EQ(key.origin_node_id, (uint16)cluster_node_id); UT_ASSERT_EQ(key.undo_segment_id, (uint16)TEST_TT_SEGMENT); - UT_ASSERT_EQ(key.tt_slot_id, - cluster_tt_slot_offset_to_id(TEST_TT_OFFSET)); + UT_ASSERT_EQ(key.tt_slot_id, cluster_tt_slot_offset_to_id(TEST_TT_OFFSET)); UT_ASSERT_EQ(key.cluster_epoch, (uint32)0); UT_ASSERT_EQ(key.local_xid, TEST_ORIGIN_XID); UT_ASSERT_EQ(result.status, CLUSTER_TT_STATUS_COMMITTED); @@ -1662,8 +1627,8 @@ UT_TEST(test_current_member_active_on_current_segment_requires_live_owner_index) locator.slot_offset = TEST_TT_OFFSET; locator.wrap = TEST_ORIGIN_WRAP; - UT_ASSERT(!cluster_runtime_visibility_physical_locator_sample_held( - &locator, &admission, &guard, &root, &key, &result, NULL)); + UT_ASSERT(!cluster_runtime_visibility_physical_locator_sample_held(&locator, &admission, &guard, + &root, &key, &result, NULL)); UT_ASSERT_EQ(result.status, CLUSTER_TT_STATUS_UNKNOWN); UT_ASSERT(!result.authoritative); } @@ -1682,9 +1647,8 @@ UT_TEST(test_exact_origin_committed_uses_canonical_tt_identity_and_direct_clog) UT_ASSERT_EQ(outcome, CLUSTER_TX_COMMITTED); UT_ASSERT_EQ(reason, CLUSTER_TX_RESOLVE_NONE); - UT_ASSERT_EQ(memcmp(&resolution.locator_echo, &test_origin_locator, - sizeof(test_origin_locator)), - 0); + UT_ASSERT_EQ( + memcmp(&resolution.locator_echo, &test_origin_locator, sizeof(test_origin_locator)), 0); UT_ASSERT_EQ((int)resolution.top_xid, (int)TEST_ORIGIN_XID); UT_ASSERT_EQ(resolution.outcome, CLUSTER_TX_COMMITTED); UT_ASSERT_EQ(resolution.proof_kind, CLUSTER_TX_PROOF_ORIGIN_DURABLE_TT_CLOG); @@ -1815,8 +1779,9 @@ UT_TEST(test_terminal_census_local_origin_uses_resident_candidate2_and_canonical admission.entered = true; UT_ASSERT_EQ(cluster_runtime_visibility_resolve_exact_origin_admitted( - &test_origin_locator, CLUSTER_TX_RESOLVE_TERMINAL_CENSUS, &admission, - &resolution, &reason), CLUSTER_TX_COMMITTED); + &test_origin_locator, CLUSTER_TX_RESOLVE_TERMINAL_CENSUS, &admission, + &resolution, &reason), + CLUSTER_TX_COMMITTED); UT_ASSERT_EQ(reason, CLUSTER_TX_RESOLVE_NONE); UT_ASSERT_EQ(resolution.locator_echo.tt_wrap, TEST_ORIGIN_WRAP); UT_ASSERT_EQ(test_candidate_acquire_calls, 1); @@ -1847,19 +1812,15 @@ UT_TEST(test_terminal_census_nonresident_cleanout_uses_exact_local_c1b_pair) admission.side = CLUSTER_SEMANTIC_TARGET_SIDE; admission.entered = true; - UT_ASSERT_EQ( - cluster_runtime_visibility_resolve_terminal_census_retained_local_exact( - &test_origin_locator, test_commit_scn, &admission, - &resolution, &reason), - CLUSTER_TX_COMMITTED); + UT_ASSERT_EQ(cluster_runtime_visibility_resolve_terminal_census_retained_local_exact( + &test_origin_locator, test_commit_scn, &admission, &resolution, &reason), + CLUSTER_TX_COMMITTED); UT_ASSERT_EQ(reason, CLUSTER_TX_RESOLVE_NONE); UT_ASSERT_EQ(resolution.outcome, CLUSTER_TX_COMMITTED); - UT_ASSERT_EQ(resolution.proof_kind, - CLUSTER_TX_PROOF_ORIGIN_DURABLE_TT_CLOG); - UT_ASSERT_EQ((uint64) resolution.commit_scn, - (uint64) test_commit_scn); - UT_ASSERT_EQ(memcmp(&resolution.locator_echo, &test_origin_locator, - sizeof(test_origin_locator)), 0); + UT_ASSERT_EQ(resolution.proof_kind, CLUSTER_TX_PROOF_ORIGIN_DURABLE_TT_CLOG); + UT_ASSERT_EQ((uint64)resolution.commit_scn, (uint64)test_commit_scn); + UT_ASSERT_EQ( + memcmp(&resolution.locator_echo, &test_origin_locator, sizeof(test_origin_locator)), 0); UT_ASSERT_EQ(test_local_freshref_pair_calls, 1); UT_ASSERT_EQ(test_candidate_acquire_calls, 0); UT_ASSERT_EQ(test_candidate_data_copy_calls, 0); @@ -1883,28 +1844,22 @@ UT_TEST(test_terminal_census_retained_pair_negative_matrix_fails_closed) /* Exact origin pair denial cannot be converted into a terminal stamp. */ reason = CLUSTER_TX_RESOLVE_NONE; - UT_ASSERT_EQ( - cluster_runtime_visibility_resolve_terminal_census_retained_local_exact( - &test_origin_locator, test_commit_scn, &admission, - &resolution, &reason), - CLUSTER_TX_UNKNOWN); + UT_ASSERT_EQ(cluster_runtime_visibility_resolve_terminal_census_retained_local_exact( + &test_origin_locator, test_commit_scn, &admission, &resolution, &reason), + CLUSTER_TX_UNKNOWN); UT_ASSERT_EQ(reason, CLUSTER_TX_RESOLVE_AUTHORITY_UNAVAILABLE); /* The retained path is closed to ACTIVE and invalid-SCN carriers. */ test_local_freshref_pair_exact = true; test_origin_locator.itl_kind = ITL_FLAG_ACTIVE; reason = CLUSTER_TX_RESOLVE_NONE; - UT_ASSERT_EQ( - cluster_runtime_visibility_resolve_terminal_census_retained_local_exact( - &test_origin_locator, test_commit_scn, &admission, - &resolution, &reason), - CLUSTER_TX_UNKNOWN); + UT_ASSERT_EQ(cluster_runtime_visibility_resolve_terminal_census_retained_local_exact( + &test_origin_locator, test_commit_scn, &admission, &resolution, &reason), + CLUSTER_TX_UNKNOWN); test_origin_locator.itl_kind = ITL_FLAG_NEEDS_CLEANOUT; - UT_ASSERT_EQ( - cluster_runtime_visibility_resolve_terminal_census_retained_local_exact( - &test_origin_locator, InvalidScn, &admission, - &resolution, &reason), - CLUSTER_TX_UNKNOWN); + UT_ASSERT_EQ(cluster_runtime_visibility_resolve_terminal_census_retained_local_exact( + &test_origin_locator, InvalidScn, &admission, &resolution, &reason), + CLUSTER_TX_UNKNOWN); UT_ASSERT_EQ(test_local_freshref_pair_calls, 1); } @@ -1924,8 +1879,9 @@ UT_TEST(test_terminal_census_same_owner_cross_segment_is_sequential_and_exact) admission.entered = true; UT_ASSERT_EQ(cluster_runtime_visibility_resolve_exact_origin_admitted( - &test_origin_locator, CLUSTER_TX_RESOLVE_TERMINAL_CENSUS, &admission, - &resolution, &reason), CLUSTER_TX_COMMITTED); + &test_origin_locator, CLUSTER_TX_RESOLVE_TERMINAL_CENSUS, &admission, + &resolution, &reason), + CLUSTER_TX_COMMITTED); UT_ASSERT_EQ(reason, CLUSTER_TX_RESOLVE_NONE); UT_ASSERT_EQ(resolution.locator_echo.tt_wrap, TEST_ORIGIN_WRAP); UT_ASSERT_EQ(test_candidate_acquire_calls, 3); @@ -1961,9 +1917,10 @@ UT_TEST(test_visibility_same_owner_cross_segment_is_sequential_and_exact) admission.side = CLUSTER_SEMANTIC_TARGET_SIDE; admission.entered = true; - UT_ASSERT_EQ(cluster_runtime_visibility_resolve_exact_origin_admitted( - &test_origin_locator, CLUSTER_TX_RESOLVE_VISIBILITY, &admission, - &resolution, &reason), CLUSTER_TX_COMMITTED); + UT_ASSERT_EQ( + cluster_runtime_visibility_resolve_exact_origin_admitted( + &test_origin_locator, CLUSTER_TX_RESOLVE_VISIBILITY, &admission, &resolution, &reason), + CLUSTER_TX_COMMITTED); UT_ASSERT_EQ(reason, CLUSTER_TX_RESOLVE_NONE); UT_ASSERT_EQ(resolution.locator_echo.tt_wrap, TEST_ORIGIN_WRAP); UT_ASSERT_EQ(test_candidate_acquire_calls, 3); @@ -2133,13 +2090,13 @@ UT_TEST(test_visibility_precommit_committed_slot_with_live_origin_stays_in_progr admission.entered = true; memset(&resolution, 0xa5, sizeof(resolution)); - UT_ASSERT_EQ(cluster_runtime_visibility_resolve_exact_origin_admitted( - &test_origin_locator, CLUSTER_TX_RESOLVE_VISIBILITY, &admission, - &resolution, &reason), CLUSTER_TX_IN_PROGRESS); + UT_ASSERT_EQ( + cluster_runtime_visibility_resolve_exact_origin_admitted( + &test_origin_locator, CLUSTER_TX_RESOLVE_VISIBILITY, &admission, &resolution, &reason), + CLUSTER_TX_IN_PROGRESS); UT_ASSERT_EQ(reason, CLUSTER_TX_RESOLVE_NONE); UT_ASSERT_EQ(resolution.outcome, CLUSTER_TX_IN_PROGRESS); - UT_ASSERT_EQ(resolution.proof_kind, - CLUSTER_TX_PROOF_ORIGIN_DURABLE_TT_CLOG); + UT_ASSERT_EQ(resolution.proof_kind, CLUSTER_TX_PROOF_ORIGIN_DURABLE_TT_CLOG); UT_ASSERT_EQ(resolution.commit_scn, InvalidScn); UT_ASSERT_EQ(test_candidate_acquire_calls, 3); UT_ASSERT_EQ(test_candidate_release_calls, 3); @@ -2246,7 +2203,7 @@ UT_TEST(test_reborn_empty_canonical_preserves_exact_origin_abort) * The later occupant's SCN must never become the old transaction's status. */ UT_TEST(test_reborn_allocated_canonical_preserves_exact_origin_abort) { - const uint16 wraps[] = {0, TEST_ORIGIN_WRAP - 1, TEST_ORIGIN_WRAP}; + const uint16 wraps[] = { 0, TEST_ORIGIN_WRAP - 1, TEST_ORIGIN_WRAP }; ClusterSemanticAdmissionToken admission; ClusterTxResolution resolution; ClusterTxResolveReason reason; @@ -2283,28 +2240,28 @@ reset_reborn_abort_fixture(ClusterSemanticAdmissionToken *admission, int shape) test_tt_slot.wrap = 0; } -UT_TEST(test_reborn_canonical_nonabort_and_census_refuse) +UT_TEST(test_reborn_canonical_nonabort_refuses_in_both_modes) { - const XidStatus states[] = {TRANSACTION_STATUS_IN_PROGRESS, TRANSACTION_STATUS_COMMITTED, - TRANSACTION_STATUS_SUB_COMMITTED}; + const XidStatus states[] = { TRANSACTION_STATUS_IN_PROGRESS, TRANSACTION_STATUS_COMMITTED, + TRANSACTION_STATUS_SUB_COMMITTED }; ClusterSemanticAdmissionToken admission; ClusterTxResolution resolution; - ClusterTxResolution zero = {0}; + ClusterTxResolution zero = { 0 }; ClusterTxResolveReason reason; for (int shape = 0; shape < 2; shape++) { - for (unsigned i = 0; i <= lengthof(states); i++) { - ClusterTxResolveMode mode = i == lengthof(states) - ? CLUSTER_TX_RESOLVE_TERMINAL_CENSUS : CLUSTER_TX_RESOLVE_VISIBILITY; + for (unsigned i = 0; i < 2 * lengthof(states); i++) { + ClusterTxResolveMode mode = i >= lengthof(states) ? CLUSTER_TX_RESOLVE_TERMINAL_CENSUS + : CLUSTER_TX_RESOLVE_VISIBILITY; reset_reborn_abort_fixture(&admission, shape); - if (i < lengthof(states)) - test_native_status = states[i]; + test_native_status = states[i % lengthof(states)]; memset(&resolution, 0xa5, sizeof(resolution)); UT_ASSERT_EQ(cluster_runtime_visibility_resolve_exact_origin_admitted( - &test_origin_locator, mode, &admission, &resolution, &reason), CLUSTER_TX_UNKNOWN); + &test_origin_locator, mode, &admission, &resolution, &reason), + CLUSTER_TX_UNKNOWN); UT_ASSERT_EQ(memcmp(&resolution, &zero, sizeof(zero)), 0); - UT_ASSERT_EQ(test_native_status_calls, i == lengthof(states) ? 0 : 1); + UT_ASSERT_EQ(test_native_status_calls, 1); UT_ASSERT_EQ(test_current_owner_calls, 0); UT_ASSERT_EQ(test_twophase_calls, 0); UT_ASSERT_EQ(test_subtrans_parent_calls, 0); @@ -2320,7 +2277,7 @@ UT_TEST(test_reborn_canonical_malformed_or_initial_generation_refuses) { ClusterSemanticAdmissionToken admission; ClusterTxResolution resolution; - ClusterTxResolution zero = {0}; + ClusterTxResolution zero = { 0 }; ClusterTxResolveReason reason; /* Even an UNUSED slot's flags, UBA and otherwise unused bytes must be @@ -2336,8 +2293,9 @@ UT_TEST(test_reborn_canonical_malformed_or_initial_generation_refuses) } memset(&resolution, 0xa5, sizeof(resolution)); UT_ASSERT_EQ(cluster_runtime_visibility_resolve_exact_origin_admitted( - &test_origin_locator, CLUSTER_TX_RESOLVE_VISIBILITY, &admission, - &resolution, &reason), CLUSTER_TX_UNKNOWN); + &test_origin_locator, CLUSTER_TX_RESOLVE_VISIBILITY, &admission, + &resolution, &reason), + CLUSTER_TX_UNKNOWN); UT_ASSERT_EQ(memcmp(&resolution, &zero, sizeof(zero)), 0); UT_ASSERT_EQ(test_native_status_calls, 0); UT_ASSERT_EQ(test_native_fence_lock_calls, 0); @@ -2349,7 +2307,7 @@ UT_TEST(test_reborn_canonical_revocation_truncation_and_data_drift_refuse) { ClusterSemanticAdmissionToken admission; ClusterTxResolution resolution; - ClusterTxResolution zero = {0}; + ClusterTxResolution zero = { 0 }; ClusterTxResolveReason reason; for (int shape = 0; shape < 2; shape++) { @@ -2371,8 +2329,9 @@ UT_TEST(test_reborn_canonical_revocation_truncation_and_data_drift_refuse) } memset(&resolution, 0xa5, sizeof(resolution)); UT_ASSERT_EQ(cluster_runtime_visibility_resolve_exact_origin_admitted( - &test_origin_locator, CLUSTER_TX_RESOLVE_VISIBILITY, &admission, - &resolution, &reason), CLUSTER_TX_UNKNOWN); + &test_origin_locator, CLUSTER_TX_RESOLVE_VISIBILITY, &admission, + &resolution, &reason), + CLUSTER_TX_UNKNOWN); UT_ASSERT_EQ(memcmp(&resolution, &zero, sizeof(zero)), 0); UT_ASSERT_EQ(test_native_status_calls, failure < 2 ? 0 : 1); UT_ASSERT_EQ(test_native_fence_depth, 0); @@ -2385,7 +2344,8 @@ UT_TEST(test_reborn_canonical_revocation_truncation_and_data_drift_refuse) /* Exercise the production continuation used by the LMS adapter, rather * than just the synchronous wrapper. Its transport/SCUR seams are fixtures; * freeze, canonical classification and final DATA publication are real C. */ -UT_TEST(test_reborn_split_plan_rechecks_before_publication) +static void +check_reborn_split_plan_rechecks_before_publication(ClusterTxResolveMode mode) { for (int shape = 0; shape < 2; shape++) { for (int failure = 0; failure < 5; failure++) { @@ -2393,12 +2353,12 @@ UT_TEST(test_reborn_split_plan_rechecks_before_publication) ClusterRuntimeVisibilityOriginPlan plan; ClusterRuntimeVisibilityCanonicalDiagnostic diagnostic; ClusterTxResolution resolution; - ClusterTxResolution zero = {0}; + ClusterTxResolution zero = { 0 }; ClusterTxResolveReason reason; - ClusterUndoBlock0CurrentGuard data_guard = {0}; - ClusterUndoBlock0CurrentGuard tt_guard = {0}; - ClusterUndoBlock0ResolvedRoot data_root = {0}; - ClusterUndoBlock0ResolvedRoot tt_root = {0}; + ClusterUndoBlock0CurrentGuard data_guard = { 0 }; + ClusterUndoBlock0CurrentGuard tt_guard = { 0 }; + ClusterUndoBlock0ResolvedRoot data_root = { 0 }; + ClusterUndoBlock0ResolvedRoot tt_root = { 0 }; PGAlignedBlock copied; PGAlignedBlock expected; @@ -2408,15 +2368,17 @@ UT_TEST(test_reborn_split_plan_rechecks_before_publication) tt_root.root_id = 92; data_root.root_generation = tt_root.root_generation = 7; UT_ASSERT_EQ(cluster_runtime_visibility_origin_plan_freeze_data_held( - &test_origin_locator, CLUSTER_TX_RESOLVE_VISIBILITY, &admission, NULL, - &data_guard, &data_root, &plan, &resolution, &reason), - CLUSTER_RUNTIME_VISIBILITY_ORIGIN_NEEDS_CANONICAL); + &test_origin_locator, mode, &admission, NULL, &data_guard, &data_root, + &plan, &resolution, &reason), + CLUSTER_RUNTIME_VISIBILITY_ORIGIN_NEEDS_CANONICAL); UT_ASSERT(cluster_runtime_visibility_origin_plan_sample_canonical_held( - &plan, CLUSTER_TX_RESOLVE_VISIBILITY, &admission, &tt_guard, &tt_root, &reason)); - UT_ASSERT(cluster_runtime_visibility_origin_plan_canonical_diagnostic(&plan, &diagnostic)); + &plan, mode, &admission, &tt_guard, &tt_root, &reason)); + UT_ASSERT( + cluster_runtime_visibility_origin_plan_canonical_diagnostic(&plan, &diagnostic)); UT_ASSERT(diagnostic.native_sampled); UT_ASSERT_EQ(diagnostic.native_status, TRANSACTION_STATUS_ABORTED); - UT_ASSERT_EQ(diagnostic.first_failure, CLUSTER_RUNTIME_VISIBILITY_CANONICAL_FAILURE_NONE); + UT_ASSERT_EQ(diagnostic.first_failure, + CLUSTER_RUNTIME_VISIBILITY_CANONICAL_FAILURE_NONE); if (failure == 1) test_candidate_mutate_record_on_recheck = true; else if (failure == 2) @@ -2429,9 +2391,9 @@ UT_TEST(test_reborn_split_plan_rechecks_before_publication) memset(&copied, 0xa5, sizeof(copied)); memset(&expected, failure == 0 ? 0x5a : 0xa5, sizeof(expected)); UT_ASSERT_EQ(cluster_runtime_visibility_origin_plan_copy_data_held( - &plan, CLUSTER_TX_RESOLVE_VISIBILITY, &admission, &data_guard, - &data_root, &resolution, copied.data, &reason), - failure == 0 ? CLUSTER_TX_ABORTED : CLUSTER_TX_UNKNOWN); + &plan, mode, &admission, &data_guard, &data_root, &resolution, + copied.data, &reason), + failure == 0 ? CLUSTER_TX_ABORTED : CLUSTER_TX_UNKNOWN); UT_ASSERT_EQ(memcmp(copied.data, expected.data, BLCKSZ), 0); if (failure == 0) { UT_ASSERT_EQ(reason, CLUSTER_TX_RESOLVE_NONE); @@ -2447,6 +2409,87 @@ UT_TEST(test_reborn_split_plan_rechecks_before_publication) } } +UT_TEST(test_reborn_split_plan_rechecks_before_publication) +{ + check_reborn_split_plan_rechecks_before_publication(CLUSTER_TX_RESOLVE_VISIBILITY); +} + +UT_TEST(test_terminal_census_split_plan_rechecks_before_publication) +{ + check_reborn_split_plan_rechecks_before_publication(CLUSTER_TX_RESOLVE_TERMINAL_CENSUS); +} + +/* Execute the real origin provider with terminal-only admission. Physical + * TT reuse must not hide an independently proved old ABORT, but neither a + * successor's outcome nor an unproved/changed native byte can clean a page. */ +UT_TEST(test_terminal_census_recycled_abort_proof_and_boundaries) +{ + for (int shape = 0; shape < 3; shape++) { + for (int same_segment = 0; same_segment < 2; same_segment++) { + for (int fault = 0; fault < 9; fault++) { + ClusterSemanticAdmissionToken admission; + ClusterTxResolution resolution; + ClusterTxResolution zero = { 0 }; + ClusterTxResolveReason reason; + bool rejected = fault != 0; + + reset_recycled_abort_fixture(&admission); + if (shape < 2) + reset_reborn_abort_fixture(&admission, shape); + if (same_segment) + test_origin_record.tt_slot_segment_id = TEST_RECORD_SEGMENT; + switch (fault) { + case 1: + test_native_status = TRANSACTION_STATUS_IN_PROGRESS; + break; + case 2: + test_native_status = TRANSACTION_STATUS_COMMITTED; + break; + case 3: + test_native_status = TRANSACTION_STATUS_SUB_COMMITTED; + break; + case 4: + test_native_origin_provable = false; + break; + case 5: + test_variable_cache.oldestClogXid = TEST_ORIGIN_XID + 1; + break; + case 6: + test_no_raw_reuse_drift_on_recheck = true; + rejected = !same_segment; + break; + case 7: + test_candidate_mutate_record_on_recheck = true; + rejected = !same_segment; + break; + case 8: + test_tt_slot.wrap = TT_WRAP_INVALID; + break; + } + memset(&resolution, 0xa5, sizeof(resolution)); + UT_ASSERT_EQ(cluster_runtime_visibility_resolve_exact_origin_admitted( + &test_origin_locator, CLUSTER_TX_RESOLVE_TERMINAL_CENSUS, + &admission, &resolution, &reason), + rejected ? CLUSTER_TX_UNKNOWN : CLUSTER_TX_ABORTED); + if (rejected) + UT_ASSERT_EQ(memcmp(&resolution, &zero, sizeof(zero)), 0); + else { + UT_ASSERT_EQ(reason, CLUSTER_TX_RESOLVE_NONE); + UT_ASSERT_EQ(resolution.locator_echo.xid, TEST_ORIGIN_XID); + UT_ASSERT_EQ(resolution.locator_echo.tt_wrap, TEST_ORIGIN_WRAP); + UT_ASSERT_EQ(resolution.top_xid, TEST_ORIGIN_XID); + UT_ASSERT_EQ(resolution.commit_scn, InvalidScn); + UT_ASSERT_EQ(resolution.proof_kind, CLUSTER_TX_PROOF_ORIGIN_DURABLE_TT_CLOG); + UT_ASSERT_EQ(test_native_status_calls, same_segment ? 1 : 2); + } + UT_ASSERT_EQ(test_native_fence_depth, 0); + UT_ASSERT_EQ(test_xact_lock_depth, 0); + UT_ASSERT_EQ(test_candidate_held_count, 0); + } + } + } +} + UT_TEST(test_recycled_canonical_nonabort_never_borrows_successor_status) { const XidStatus states[] = { TRANSACTION_STATUS_IN_PROGRESS, TRANSACTION_STATUS_COMMITTED, @@ -2572,7 +2615,10 @@ UT_TEST(test_recycled_canonical_clog_error_rethrows_and_releases_own_locks) ClusterSemanticAdmissionToken admission; ClusterTxResolution resolution; ClusterTxResolveReason reason; - for (int shape = 0; shape < 3; shape++) { + for (int variant = 0; variant < 6; variant++) { + int shape = variant % 3; + ClusterTxResolveMode mode + = variant < 3 ? CLUSTER_TX_RESOLVE_VISIBILITY : CLUSTER_TX_RESOLVE_TERMINAL_CENSUS; volatile bool caught = false; reset_recycled_abort_fixture(&admission); @@ -2582,7 +2628,7 @@ UT_TEST(test_recycled_canonical_clog_error_rethrows_and_releases_own_locks) PG_TRY(); { (void)cluster_runtime_visibility_resolve_exact_origin_admitted( - &test_origin_locator, CLUSTER_TX_RESOLVE_VISIBILITY, &admission, &resolution, &reason); + &test_origin_locator, mode, &admission, &resolution, &reason); } PG_CATCH(); { @@ -2629,25 +2675,21 @@ UT_TEST(test_canonical_sample_reports_first_failed_predicate) tt_root.root_generation = 7; UT_ASSERT_EQ(cluster_runtime_visibility_origin_plan_freeze_data_held( - &test_origin_locator, CLUSTER_TX_RESOLVE_VISIBILITY, &admission, NULL, - &data_guard, &data_root, &plan, &resolution, &reason), - CLUSTER_RUNTIME_VISIBILITY_ORIGIN_NEEDS_CANONICAL); - UT_ASSERT(cluster_runtime_visibility_origin_plan_canonical_logical( - &plan, &canonical_logical)); + &test_origin_locator, CLUSTER_TX_RESOLVE_VISIBILITY, &admission, NULL, + &data_guard, &data_root, &plan, &resolution, &reason), + CLUSTER_RUNTIME_VISIBILITY_ORIGIN_NEEDS_CANONICAL); + UT_ASSERT(cluster_runtime_visibility_origin_plan_canonical_logical(&plan, &canonical_logical)); UT_ASSERT_EQ(canonical_logical.segment_id, TEST_TT_SEGMENT); test_candidate_sample_result = CLUSTER_UNDO_BLOCK0_NOT_PUBLISHED; UT_ASSERT(!cluster_runtime_visibility_origin_plan_sample_canonical_held( - &plan, CLUSTER_TX_RESOLVE_VISIBILITY, &admission, &tt_guard, &tt_root, - &reason)); + &plan, CLUSTER_TX_RESOLVE_VISIBILITY, &admission, &tt_guard, &tt_root, &reason)); UT_ASSERT_EQ(reason, CLUSTER_TX_RESOLVE_AUTHORITY_UNAVAILABLE); memset(&diagnostic, 0xa5, sizeof(diagnostic)); - UT_ASSERT(cluster_runtime_visibility_origin_plan_canonical_diagnostic( - &plan, &diagnostic)); + UT_ASSERT(cluster_runtime_visibility_origin_plan_canonical_diagnostic(&plan, &diagnostic)); UT_ASSERT(diagnostic.valid); UT_ASSERT_EQ(diagnostic.first_failure, - CLUSTER_RUNTIME_VISIBILITY_CANONICAL_FAILURE_GENERATION_SAMPLE); - UT_ASSERT_EQ(diagnostic.generation_result, - CLUSTER_UNDO_BLOCK0_NOT_PUBLISHED); + CLUSTER_RUNTIME_VISIBILITY_CANONICAL_FAILURE_GENERATION_SAMPLE); + UT_ASSERT_EQ(diagnostic.generation_result, CLUSTER_UNDO_BLOCK0_NOT_PUBLISHED); UT_ASSERT(!diagnostic.generation_known); UT_ASSERT_EQ(diagnostic.locator_xid, TEST_ORIGIN_XID); UT_ASSERT_EQ(diagnostic.locator_wrap, TEST_ORIGIN_WRAP); @@ -2680,9 +2722,10 @@ UT_TEST(test_empty_physical_slot_remains_unknown_despite_current_allocator_owner admission.entered = true; memset(&resolution, 0xa5, sizeof(resolution)); - UT_ASSERT_EQ(cluster_runtime_visibility_resolve_exact_origin_admitted( - &test_origin_locator, CLUSTER_TX_RESOLVE_VISIBILITY, &admission, - &resolution, &reason), CLUSTER_TX_UNKNOWN); + UT_ASSERT_EQ( + cluster_runtime_visibility_resolve_exact_origin_admitted( + &test_origin_locator, CLUSTER_TX_RESOLVE_VISIBILITY, &admission, &resolution, &reason), + CLUSTER_TX_UNKNOWN); UT_ASSERT_EQ(reason, CLUSTER_TX_RESOLVE_AUTHORITY_UNAVAILABLE); UT_ASSERT_EQ(memcmp(&resolution, &zero, sizeof(resolution)), 0); UT_ASSERT_EQ(test_current_owner_calls, 0); @@ -2707,21 +2750,21 @@ UT_TEST(test_allocator_identity_never_overrides_empty_physical_slot) test_native_status = TRANSACTION_STATUS_IN_PROGRESS; test_twophase_xid = TEST_ORIGIN_XID; switch (mismatch) { - case 0: - test_current_owner.segment_id++; - break; - case 1: - test_current_owner.slot_offset++; - break; - case 2: - test_current_owner.xid++; - break; - case 3: - test_current_owner.wrap++; - break; - default: - test_current_owner.status = CTS_COMMITTED; - break; + case 0: + test_current_owner.segment_id++; + break; + case 1: + test_current_owner.slot_offset++; + break; + case 2: + test_current_owner.xid++; + break; + case 3: + test_current_owner.wrap++; + break; + default: + test_current_owner.status = CTS_COMMITTED; + break; } memset(&admission, 0, sizeof(admission)); admission.feature_bit = CLUSTER_SEMANTIC_FEATURE_R4_SYNC_CR_V1; @@ -2733,8 +2776,9 @@ UT_TEST(test_allocator_identity_never_overrides_empty_physical_slot) reason = CLUSTER_TX_RESOLVE_PROTOCOL; UT_ASSERT_EQ(cluster_runtime_visibility_resolve_exact_origin_admitted( - &test_origin_locator, CLUSTER_TX_RESOLVE_VISIBILITY, &admission, - &resolution, &reason), CLUSTER_TX_UNKNOWN); + &test_origin_locator, CLUSTER_TX_RESOLVE_VISIBILITY, &admission, + &resolution, &reason), + CLUSTER_TX_UNKNOWN); UT_ASSERT_EQ(memcmp(&resolution, &zero, sizeof(resolution)), 0); UT_ASSERT_EQ(reason, CLUSTER_TX_RESOLVE_AUTHORITY_UNAVAILABLE); UT_ASSERT_EQ(test_current_owner_calls, 0); @@ -2753,9 +2797,10 @@ UT_TEST(test_allocator_identity_never_overrides_empty_physical_slot) admission.entered = true; memset(&resolution, 0xa5, sizeof(resolution)); reason = CLUSTER_TX_RESOLVE_PROTOCOL; - UT_ASSERT_EQ(cluster_runtime_visibility_resolve_exact_origin_admitted( - &test_origin_locator, CLUSTER_TX_RESOLVE_VISIBILITY, &admission, - &resolution, &reason), CLUSTER_TX_UNKNOWN); + UT_ASSERT_EQ( + cluster_runtime_visibility_resolve_exact_origin_admitted( + &test_origin_locator, CLUSTER_TX_RESOLVE_VISIBILITY, &admission, &resolution, &reason), + CLUSTER_TX_UNKNOWN); UT_ASSERT_EQ(memcmp(&resolution, &zero, sizeof(resolution)), 0); UT_ASSERT_EQ(reason, CLUSTER_TX_RESOLVE_AUTHORITY_UNAVAILABLE); UT_ASSERT_EQ(test_current_owner_calls, 0); @@ -2776,9 +2821,10 @@ UT_TEST(test_allocator_identity_never_overrides_empty_physical_slot) admission.entered = true; memset(&resolution, 0xa5, sizeof(resolution)); reason = CLUSTER_TX_RESOLVE_PROTOCOL; - UT_ASSERT_EQ(cluster_runtime_visibility_resolve_exact_origin_admitted( - &test_origin_locator, CLUSTER_TX_RESOLVE_VISIBILITY, &admission, - &resolution, &reason), CLUSTER_TX_UNKNOWN); + UT_ASSERT_EQ( + cluster_runtime_visibility_resolve_exact_origin_admitted( + &test_origin_locator, CLUSTER_TX_RESOLVE_VISIBILITY, &admission, &resolution, &reason), + CLUSTER_TX_UNKNOWN); UT_ASSERT_EQ(reason, CLUSTER_TX_RESOLVE_AUTHORITY_UNAVAILABLE); UT_ASSERT_EQ(memcmp(&resolution, &zero, sizeof(resolution)), 0); UT_ASSERT_EQ(test_current_owner_calls, 0); @@ -2801,9 +2847,10 @@ UT_TEST(test_allocator_identity_never_overrides_empty_physical_slot) memset(&resolution, 0xa5, sizeof(resolution)); reason = CLUSTER_TX_RESOLVE_PROTOCOL; - UT_ASSERT_EQ(cluster_runtime_visibility_resolve_exact_origin_admitted( - &test_origin_locator, CLUSTER_TX_RESOLVE_VISIBILITY, &admission, - &resolution, &reason), CLUSTER_TX_UNKNOWN); + UT_ASSERT_EQ( + cluster_runtime_visibility_resolve_exact_origin_admitted( + &test_origin_locator, CLUSTER_TX_RESOLVE_VISIBILITY, &admission, &resolution, &reason), + CLUSTER_TX_UNKNOWN); UT_ASSERT_EQ(reason, CLUSTER_TX_RESOLVE_AUTHORITY_UNAVAILABLE); UT_ASSERT_EQ(memcmp(&resolution, &zero, sizeof(resolution)), 0); UT_ASSERT_EQ(test_current_owner_calls, 0); @@ -2829,9 +2876,10 @@ UT_TEST(test_empty_physical_slot_remains_unknown_despite_rolled_live_xid) admission.entered = true; memset(&resolution, 0xa5, sizeof(resolution)); - UT_ASSERT_EQ(cluster_runtime_visibility_resolve_exact_origin_admitted( - &test_origin_locator, CLUSTER_TX_RESOLVE_VISIBILITY, &admission, - &resolution, &reason), CLUSTER_TX_UNKNOWN); + UT_ASSERT_EQ( + cluster_runtime_visibility_resolve_exact_origin_admitted( + &test_origin_locator, CLUSTER_TX_RESOLVE_VISIBILITY, &admission, &resolution, &reason), + CLUSTER_TX_UNKNOWN); UT_ASSERT_EQ(reason, CLUSTER_TX_RESOLVE_AUTHORITY_UNAVAILABLE); UT_ASSERT_EQ(memcmp(&resolution, &zero, sizeof(resolution)), 0); UT_ASSERT_EQ(test_current_owner_calls, 0); @@ -2860,10 +2908,9 @@ UT_TEST(test_rolled_live_evidence_never_overrides_mismatched_physical_slot) test_tt_slot.xid = TEST_ORIGIN_XID + 1; test_tt_slot.wrap = TEST_ORIGIN_WRAP + 1; test_tt_slot.status = physical_kind == 0 - ? TT_SLOT_COMMITTED - : (physical_kind == 1 ? TT_SLOT_ABORTED : TT_SLOT_ACTIVE); - test_tt_slot.commit_scn = physical_kind == 0 - ? scn_encode(0, 79) : InvalidScn; + ? TT_SLOT_COMMITTED + : (physical_kind == 1 ? TT_SLOT_ABORTED : TT_SLOT_ACTIVE); + test_tt_slot.commit_scn = physical_kind == 0 ? scn_encode(0, 79) : InvalidScn; test_twophase_xid = TEST_ORIGIN_XID; test_native_status = TRANSACTION_STATUS_IN_PROGRESS; memset(&admission, 0, sizeof(admission)); @@ -2876,8 +2923,9 @@ UT_TEST(test_rolled_live_evidence_never_overrides_mismatched_physical_slot) reason = CLUSTER_TX_RESOLVE_PROTOCOL; UT_ASSERT_EQ(cluster_runtime_visibility_resolve_exact_origin_admitted( - &test_origin_locator, CLUSTER_TX_RESOLVE_VISIBILITY, &admission, - &resolution, &reason), CLUSTER_TX_UNKNOWN); + &test_origin_locator, CLUSTER_TX_RESOLVE_VISIBILITY, &admission, + &resolution, &reason), + CLUSTER_TX_UNKNOWN); UT_ASSERT_EQ(reason, CLUSTER_TX_RESOLVE_AUTHORITY_UNAVAILABLE); UT_ASSERT_EQ(memcmp(&resolution, &zero, sizeof(resolution)), 0); UT_ASSERT_EQ(test_current_segment_calls, 0); @@ -2929,8 +2977,9 @@ UT_TEST(test_empty_physical_slot_never_consults_rolled_native_axes) reason = CLUSTER_TX_RESOLVE_PROTOCOL; UT_ASSERT_EQ(cluster_runtime_visibility_resolve_exact_origin_admitted( - &test_origin_locator, CLUSTER_TX_RESOLVE_VISIBILITY, &admission, - &resolution, &reason), CLUSTER_TX_UNKNOWN); + &test_origin_locator, CLUSTER_TX_RESOLVE_VISIBILITY, &admission, + &resolution, &reason), + CLUSTER_TX_UNKNOWN); UT_ASSERT_EQ(reason, CLUSTER_TX_RESOLVE_AUTHORITY_UNAVAILABLE); UT_ASSERT_EQ(memcmp(&resolution, &zero, sizeof(resolution)), 0); UT_ASSERT_EQ(test_current_segment_calls, 0); @@ -2969,8 +3018,9 @@ UT_TEST(test_empty_physical_slot_cannot_reach_rolled_recheck) reason = CLUSTER_TX_RESOLVE_PROTOCOL; UT_ASSERT_EQ(cluster_runtime_visibility_resolve_exact_origin_admitted( - &test_origin_locator, CLUSTER_TX_RESOLVE_VISIBILITY, &admission, - &resolution, &reason), CLUSTER_TX_UNKNOWN); + &test_origin_locator, CLUSTER_TX_RESOLVE_VISIBILITY, &admission, + &resolution, &reason), + CLUSTER_TX_UNKNOWN); UT_ASSERT_EQ(reason, CLUSTER_TX_RESOLVE_AUTHORITY_UNAVAILABLE); UT_ASSERT_EQ(memcmp(&resolution, &zero, sizeof(resolution)), 0); UT_ASSERT_EQ(test_current_segment_calls, 0); @@ -3006,13 +3056,17 @@ UT_TEST(test_terminal_census_never_projects_current_active_owner) memset(&resolution, 0xa5, sizeof(resolution)); UT_ASSERT_EQ(cluster_runtime_visibility_resolve_exact_origin_admitted( - &test_origin_locator, CLUSTER_TX_RESOLVE_TERMINAL_CENSUS, &admission, - &resolution, &reason), CLUSTER_TX_UNKNOWN); + &test_origin_locator, CLUSTER_TX_RESOLVE_TERMINAL_CENSUS, &admission, + &resolution, &reason), + CLUSTER_TX_UNKNOWN); UT_ASSERT_EQ(reason, CLUSTER_TX_RESOLVE_AUTHORITY_UNAVAILABLE); UT_ASSERT_EQ(memcmp(&resolution, &zero, sizeof(resolution)), 0); UT_ASSERT_EQ(test_current_owner_calls, 0); UT_ASSERT_EQ(test_current_segment_calls, 0); - UT_ASSERT_EQ(test_native_fence_lock_calls, 0); + /* The terminal abort probe checks its origin window but cannot project + * this allocator/live-owner fixture or sample an unproved native xid. */ + UT_ASSERT_EQ(test_native_fence_lock_calls, 1); + UT_ASSERT_EQ(test_native_fence_unlock_calls, 1); UT_ASSERT_EQ(test_procarray_calls, 0); UT_ASSERT_EQ(test_native_status_calls, 0); } @@ -3037,8 +3091,9 @@ UT_TEST(test_terminal_census_rejects_precommit_committed_slot_with_live_origin) memset(&resolution, 0xa5, sizeof(resolution)); UT_ASSERT_EQ(cluster_runtime_visibility_resolve_exact_origin_admitted( - &test_origin_locator, CLUSTER_TX_RESOLVE_TERMINAL_CENSUS, &admission, - &resolution, &reason), CLUSTER_TX_UNKNOWN); + &test_origin_locator, CLUSTER_TX_RESOLVE_TERMINAL_CENSUS, &admission, + &resolution, &reason), + CLUSTER_TX_UNKNOWN); UT_ASSERT_EQ(reason, CLUSTER_TX_RESOLVE_AUTHORITY_UNAVAILABLE); UT_ASSERT_EQ(memcmp(&resolution, &zero, sizeof(resolution)), 0); UT_ASSERT_EQ(test_candidate_acquire_calls, 2); @@ -3066,8 +3121,9 @@ UT_TEST(test_terminal_census_cross_segment_data_drift_fails_closed) memset(&resolution, 0xa5, sizeof(resolution)); UT_ASSERT_EQ(cluster_runtime_visibility_resolve_exact_origin_admitted( - &test_origin_locator, CLUSTER_TX_RESOLVE_TERMINAL_CENSUS, &admission, - &resolution, &reason), CLUSTER_TX_UNKNOWN); + &test_origin_locator, CLUSTER_TX_RESOLVE_TERMINAL_CENSUS, &admission, + &resolution, &reason), + CLUSTER_TX_UNKNOWN); UT_ASSERT_EQ(reason, CLUSTER_TX_RESOLVE_AUTHORITY_STALE); UT_ASSERT_EQ(memcmp(&resolution, &zero, sizeof(zero)), 0); UT_ASSERT_EQ(test_candidate_acquire_calls, 3); @@ -3098,8 +3154,9 @@ UT_TEST(test_terminal_census_cross_owner_tt_alias_fails_closed) memset(&resolution, 0xa5, sizeof(resolution)); UT_ASSERT_EQ(cluster_runtime_visibility_resolve_exact_origin_admitted( - &test_origin_locator, CLUSTER_TX_RESOLVE_TERMINAL_CENSUS, &admission, - &resolution, &reason), CLUSTER_TX_UNKNOWN); + &test_origin_locator, CLUSTER_TX_RESOLVE_TERMINAL_CENSUS, &admission, + &resolution, &reason), + CLUSTER_TX_UNKNOWN); UT_ASSERT_EQ(reason, CLUSTER_TX_RESOLVE_AUTHORITY_UNAVAILABLE); UT_ASSERT_EQ(memcmp(&resolution, &zero, sizeof(zero)), 0); UT_ASSERT_EQ(test_candidate_acquire_calls, 1); @@ -3130,8 +3187,9 @@ UT_TEST(test_terminal_census_pending_acquire_failure_cancels_candidate_guard) memset(&resolution, 0xa5, sizeof(resolution)); UT_ASSERT_EQ(cluster_runtime_visibility_resolve_exact_origin_admitted( - &test_origin_locator, CLUSTER_TX_RESOLVE_TERMINAL_CENSUS, - &admission, &resolution, &reason), CLUSTER_TX_UNKNOWN); + &test_origin_locator, CLUSTER_TX_RESOLVE_TERMINAL_CENSUS, &admission, + &resolution, &reason), + CLUSTER_TX_UNKNOWN); UT_ASSERT_EQ(reason, CLUSTER_TX_RESOLVE_AUTHORITY_UNAVAILABLE); UT_ASSERT_EQ(memcmp(&resolution, &zero, sizeof(zero)), 0); UT_ASSERT_EQ(test_candidate_acquire_calls, 1); @@ -3186,7 +3244,7 @@ UT_TEST(test_terminal_census_pending_wakes_repoll_until_exact_terminal) UT_TEST(test_exact_origin_bad_record_wrap_fails_before_tt_or_clog) { ClusterTxResolution resolution; - ClusterTxResolution zero = {0}; + ClusterTxResolution zero = { 0 }; ClusterTxResolveReason reason = CLUSTER_TX_RESOLVE_PROTOCOL; reset_exact_origin_fixture(); @@ -3225,9 +3283,8 @@ UT_TEST(test_exact_origin_aborted_uses_exact_tt_and_direct_clog) UT_ASSERT_EQ(resolution.outcome, CLUSTER_TX_ABORTED); UT_ASSERT_EQ(resolution.proof_kind, CLUSTER_TX_PROOF_ORIGIN_DURABLE_TT_CLOG); UT_ASSERT_EQ(resolution.commit_scn, InvalidScn); - UT_ASSERT_EQ(memcmp(&resolution.locator_echo, &test_origin_locator, - sizeof(test_origin_locator)), - 0); + UT_ASSERT_EQ( + memcmp(&resolution.locator_echo, &test_origin_locator, sizeof(test_origin_locator)), 0); UT_ASSERT_EQ(test_undo_read_calls, 1); UT_ASSERT_EQ(test_tt_exact_calls, 1); UT_ASSERT_EQ(test_tt_snapshot_calls, 1); @@ -3240,7 +3297,7 @@ UT_TEST(test_exact_origin_aborted_uses_exact_tt_and_direct_clog) UT_TEST(test_exact_origin_conflicting_terminal_evidence_fails_closed) { ClusterTxResolution resolution; - ClusterTxResolution zero = {0}; + ClusterTxResolution zero = { 0 }; ClusterTxResolveReason reason = CLUSTER_TX_RESOLVE_PROTOCOL; reset_exact_origin_fixture(); @@ -3281,9 +3338,8 @@ UT_TEST(test_exact_origin_active_and_native_in_progress_stays_live) UT_ASSERT_EQ(resolution.proof_kind, CLUSTER_TX_PROOF_ORIGIN_DURABLE_TT_CLOG); UT_ASSERT_EQ(resolution.commit_scn, InvalidScn); UT_ASSERT_EQ(resolution.horizon_scn, InvalidScn); - UT_ASSERT_EQ(memcmp(&resolution.locator_echo, &test_origin_locator, - sizeof(test_origin_locator)), - 0); + UT_ASSERT_EQ( + memcmp(&resolution.locator_echo, &test_origin_locator, sizeof(test_origin_locator)), 0); UT_ASSERT_EQ(test_undo_read_calls, 1); UT_ASSERT_EQ(test_tt_exact_calls, 1); UT_ASSERT_EQ(test_tt_snapshot_calls, 1); @@ -3365,7 +3421,7 @@ UT_TEST(test_exact_origin_prepared_finish_abort_terminal_wins) UT_TEST(test_exact_origin_prepared_finish_commit_without_exact_scn_fails_closed) { ClusterTxResolution resolution; - ClusterTxResolution zero = {0}; + ClusterTxResolution zero = { 0 }; ClusterTxResolveReason reason = CLUSTER_TX_RESOLVE_PROTOCOL; reset_exact_origin_fixture(); @@ -3415,7 +3471,7 @@ UT_TEST(test_exact_origin_tt_aborted_does_not_beat_direct_prepared_owner) UT_TEST(test_exact_origin_tt_aborted_without_direct_native_terminal_fails_closed) { ClusterTxResolution resolution; - ClusterTxResolution zero = {0}; + ClusterTxResolution zero = { 0 }; ClusterTxResolveReason reason = CLUSTER_TX_RESOLVE_PROTOCOL; reset_exact_origin_fixture(); @@ -3463,7 +3519,7 @@ UT_TEST(test_exact_origin_tt_aborted_direct_second_clog_abort_is_terminal) UT_TEST(test_exact_origin_tt_aborted_direct_second_clog_commit_conflicts) { ClusterTxResolution resolution; - ClusterTxResolution zero = {0}; + ClusterTxResolution zero = { 0 }; ClusterTxResolveReason reason = CLUSTER_TX_RESOLVE_PROTOCOL; reset_exact_origin_fixture(); @@ -3519,7 +3575,7 @@ UT_TEST(test_exact_origin_tt_aborted_does_not_beat_subtrans_prepared_owner) UT_TEST(test_exact_origin_tt_aborted_without_subtrans_native_terminal_fails_closed) { ClusterTxResolution resolution; - ClusterTxResolution zero = {0}; + ClusterTxResolution zero = { 0 }; ClusterTxResolveReason reason = CLUSTER_TX_RESOLVE_PROTOCOL; TransactionId top = TEST_ORIGIN_XID - 1; @@ -3580,7 +3636,7 @@ UT_TEST(test_exact_origin_tt_aborted_subtrans_second_clog_abort_is_terminal) UT_TEST(test_exact_origin_tt_aborted_subtrans_second_clog_commit_conflicts) { ClusterTxResolution resolution; - ClusterTxResolution zero = {0}; + ClusterTxResolution zero = { 0 }; ClusterTxResolveReason reason = CLUSTER_TX_RESOLVE_PROTOCOL; TransactionId top = TEST_ORIGIN_XID - 1; @@ -3610,7 +3666,7 @@ UT_TEST(test_exact_origin_tt_aborted_subtrans_second_clog_commit_conflicts) UT_TEST(test_exact_origin_nested_subcommitted_top_commit_without_locator_fails_closed) { ClusterTxResolution resolution; - ClusterTxResolution zero = {0}; + ClusterTxResolution zero = { 0 }; ClusterTxResolveReason reason = CLUSTER_TX_RESOLVE_PROTOCOL; TransactionId parent = TEST_ORIGIN_XID - 1; TransactionId top = TEST_ORIGIN_XID - 2; @@ -3727,7 +3783,7 @@ UT_TEST(test_exact_origin_subcommitted_top_prepared_stays_live) UT_TEST(test_exact_origin_subtrans_edge_change_fails_closed) { ClusterTxResolution resolution; - ClusterTxResolution zero = {0}; + ClusterTxResolution zero = { 0 }; ClusterTxResolveReason reason = CLUSTER_TX_RESOLVE_PROTOCOL; TransactionId top = TEST_ORIGIN_XID - 1; @@ -3755,7 +3811,7 @@ UT_TEST(test_exact_origin_subtrans_edge_change_fails_closed) UT_TEST(test_exact_origin_subtrans_cycle_fails_closed) { ClusterTxResolution resolution; - ClusterTxResolution zero = {0}; + ClusterTxResolution zero = { 0 }; ClusterTxResolveReason reason = CLUSTER_TX_RESOLVE_PROTOCOL; reset_exact_origin_fixture(); @@ -3777,7 +3833,7 @@ UT_TEST(test_exact_origin_subtrans_cycle_fails_closed) UT_TEST(test_exact_origin_subcommitted_before_transaction_xmin_fails_closed) { ClusterTxResolution resolution; - ClusterTxResolution zero = {0}; + ClusterTxResolution zero = { 0 }; ClusterTxResolveReason reason = CLUSTER_TX_RESOLVE_PROTOCOL; reset_exact_origin_fixture(); @@ -3801,7 +3857,7 @@ UT_TEST(test_exact_origin_subcommitted_before_transaction_xmin_fails_closed) UT_TEST(test_exact_origin_subtrans_depth_fails_closed) { ClusterTxResolution resolution; - ClusterTxResolution zero = {0}; + ClusterTxResolution zero = { 0 }; ClusterTxResolveReason reason = CLUSTER_TX_RESOLVE_PROTOCOL; TransactionId child = 5000; int i; @@ -4110,7 +4166,7 @@ UT_TEST(test_self_fresh_role_does_not_inherit_ordinary_abort_permission) int main(void) { - UT_PLAN(125); + UT_PLAN(127); UT_RUN(test_self_fresh_role_does_not_inherit_ordinary_abort_permission); UT_RUN(test_local_retained_read_bound_precedes_exact_pair_without_promoting_it); UT_RUN(test_local_retained_read_preserves_same_stamp_origin_exact); @@ -4189,10 +4245,12 @@ main(void) UT_RUN(test_recycled_canonical_abort_same_segment); UT_RUN(test_reborn_empty_canonical_preserves_exact_origin_abort); UT_RUN(test_reborn_allocated_canonical_preserves_exact_origin_abort); - UT_RUN(test_reborn_canonical_nonabort_and_census_refuse); + UT_RUN(test_reborn_canonical_nonabort_refuses_in_both_modes); UT_RUN(test_reborn_canonical_malformed_or_initial_generation_refuses); UT_RUN(test_reborn_canonical_revocation_truncation_and_data_drift_refuse); UT_RUN(test_reborn_split_plan_rechecks_before_publication); + UT_RUN(test_terminal_census_split_plan_rechecks_before_publication); + UT_RUN(test_terminal_census_recycled_abort_proof_and_boundaries); UT_RUN(test_recycled_canonical_nonabort_never_borrows_successor_status); UT_RUN(test_recycled_canonical_invalid_successor_never_reads_native); UT_RUN(test_recycled_canonical_missing_or_revoked_window_refuses); diff --git a/src/test/cluster_unit/test_cluster_r4_wire_codec.c b/src/test/cluster_unit/test_cluster_r4_wire_codec.c index 4016837d03b..6aad0f46a0e 100644 --- a/src/test/cluster_unit/test_cluster_r4_wire_codec.c +++ b/src/test/cluster_unit/test_cluster_r4_wire_codec.c @@ -43,8 +43,8 @@ verdict_resolution(ClusterTxOutcome outcome, ClusterTxProofKind proof_kind) resolution.proof_kind = proof_kind; resolution.commit_scn = outcome == CLUSTER_TX_COMMITTED ? (SCN)0x2122232425262728 : InvalidScn; resolution.horizon_scn = proof_kind == CLUSTER_TX_PROOF_RECYCLED_BELOW_HORIZON - ? (SCN)0x3132333435363738 - : InvalidScn; + ? (SCN)0x3132333435363738 + : InvalidScn; resolution.authority.origin_epoch = 0; resolution.authority.live_hwm_lsn = (XLogRecPtr)0x4142434445464748; resolution.authority.tt_generation = UINT64_C(0x5152535455565758); @@ -95,504 +95,467 @@ run_wire_vector(int vector) locator.itl_slot_index = 1; switch (vector) { - case 0: - UT_ASSERT_EQ(sizeof(request), 16); - break; - case 1: - UT_ASSERT_EQ(sizeof(forward), 32); - break; - case 2: - UT_ASSERT_EQ(offsetof(ClusterR4ForwardExtension, - kind.cr.master_resource_transition_count_le), 12); - break; - case 3: - UT_ASSERT_EQ(CLUSTER_R4_WIRE_VERSION, 1); - break; - case 4: - UT_ASSERT_EQ(CLUSTER_R4_FORWARD_EXTENDED, 6); - break; - case 5: - UT_ASSERT_EQ(CLUSTER_R4_WIRE_CR_BUILD, 1); - break; - case 6: - UT_ASSERT(ClusterR4RequestExtensionSetCr(&request, (SCN)0x1234)); - UT_ASSERT(ClusterR4RequestExtensionGetCr(&request, &scn)); - UT_ASSERT_EQ((uint64)scn, UINT64_C(0x1234)); - break; - case 7: - UT_ASSERT(!ClusterR4RequestExtensionSetCr(NULL, (SCN)1)); - break; - case 8: - UT_ASSERT(!ClusterR4RequestExtensionSetCr(&request, InvalidScn)); - break; - case 9: - UT_ASSERT(!ClusterR4RequestExtensionGetCr(NULL, &scn)); - break; - case 10: - UT_ASSERT(!ClusterR4RequestExtensionGetCr(&request, NULL)); - break; - case 11: - ClusterR4RequestExtensionSetCr(&request, (SCN)1); - request.r4_version++; - UT_ASSERT(!ClusterR4RequestExtensionGetCr(&request, &scn)); - break; - case 12: - ClusterR4RequestExtensionSetCr(&request, (SCN)1); - request.r4_kind = CLUSTER_R4_WIRE_TX_RESOLVE; - UT_ASSERT(!ClusterR4RequestExtensionGetCr(&request, &scn)); - break; - case 13: - ClusterR4RequestExtensionSetCr(&request, (SCN)1); - request.flags_le[0] = 1; - UT_ASSERT(!ClusterR4RequestExtensionGetCr(&request, &scn)); - break; - case 14: - ClusterR4RequestExtensionSetCr(&request, (SCN)1); - request.flags_le[1] = 1; - UT_ASSERT(!ClusterR4RequestExtensionGetCr(&request, &scn)); - break; - case 15: - ClusterR4RequestExtensionSetCr(&request, (SCN)1); - request.reserved[3] = 1; - UT_ASSERT(!ClusterR4RequestExtensionGetCr(&request, &scn)); - break; - case 16: - ClusterR4ForwardExtensionSetCrProof(&forward, (UINT64_C(9) << 32) | 4, - UINT64_C(7), (SCN)0x5678); - UT_ASSERT(ClusterR4ForwardExtensionGetCrProof(&forward, 9, &master_generation, - &transition_count, &scn)); - UT_ASSERT(master_generation == ((UINT64_C(9) << 32) | 4)); - UT_ASSERT(transition_count == UINT64_C(7)); - UT_ASSERT((uint64)scn == UINT64_C(0x5678)); - break; - case 17: - UT_ASSERT(!ClusterR4ForwardExtensionGetCrProof(NULL, 0, &master_generation, - &transition_count, &scn)); - break; - case 18: - ClusterR4ForwardExtensionSetCrProof(&forward, 1, 1, InvalidScn); - UT_ASSERT(!ClusterR4ForwardExtensionGetCrProof(&forward, 0, NULL, - &transition_count, &scn)); - break; - case 19: - ClusterR4ForwardExtensionSetCrProof(&forward, 1, 1, InvalidScn); - UT_ASSERT(!ClusterR4ForwardExtensionGetCrProof(&forward, 0, &master_generation, NULL, - &scn)); - break; - case 20: - ClusterR4ForwardExtensionSetCrProof(&forward, 1, 1, InvalidScn); - UT_ASSERT(!ClusterR4ForwardExtensionGetCrProof(&forward, 0, &master_generation, - &transition_count, NULL)); - break; - case 21: - ClusterR4ForwardExtensionSetCrProof(&forward, 1, 1, InvalidScn); - forward.r4_version++; - UT_ASSERT(!ClusterR4ForwardExtensionGetCrProof(&forward, 0, &master_generation, - &transition_count, &scn)); - break; - case 22: - ClusterR4ForwardExtensionSetCrProof(&forward, 1, 1, InvalidScn); - forward.r4_kind = CLUSTER_R4_WIRE_TX_RESOLVE; - UT_ASSERT(!ClusterR4ForwardExtensionGetCrProof(&forward, 0, &master_generation, - &transition_count, &scn)); - break; - case 23: - ClusterR4ForwardExtensionSetCrProof(&forward, 1, 1, InvalidScn); - forward.flags_le[0] = 1; - UT_ASSERT(!ClusterR4ForwardExtensionGetCrProof(&forward, 0, &master_generation, - &transition_count, &scn)); - break; - case 24: - ClusterR4ForwardExtensionSetCrProof(&forward, 1, 1, InvalidScn); - forward.subject_id_le[0] = 1; - UT_ASSERT(!ClusterR4ForwardExtensionGetCrProof(&forward, 0, &master_generation, - &transition_count, &scn)); - break; - case 25: - ClusterR4ForwardExtensionSetCrProof(&forward, 0, 1, InvalidScn); - UT_ASSERT(!ClusterR4ForwardExtensionGetCrProof(&forward, 0, &master_generation, - &transition_count, &scn)); - break; - case 26: - ClusterR4ForwardExtensionSetCrProof(&forward, UINT64_C(1) << 32, 1, InvalidScn); - UT_ASSERT(!ClusterR4ForwardExtensionGetCrProof(&forward, 1, &master_generation, - &transition_count, &scn)); - break; - case 27: - ClusterR4ForwardExtensionSetCrProof(&forward, 1, 0, InvalidScn); - UT_ASSERT(!ClusterR4ForwardExtensionGetCrProof(&forward, 0, &master_generation, - &transition_count, &scn)); - break; - case 28: - ClusterR4ForwardExtensionSetCrProof(&forward, 1, UINT64_MAX, InvalidScn); - UT_ASSERT(!ClusterR4ForwardExtensionGetCrProof(&forward, 0, &master_generation, - &transition_count, &scn)); - break; - case 29: - ClusterR4ForwardExtensionSetCrProof(&forward, (UINT64_C(2) << 32) | 1, 1, - InvalidScn); - UT_ASSERT(!ClusterR4ForwardExtensionGetCrProof(&forward, 1, &master_generation, - &transition_count, &scn)); - break; - case 30: - ClusterR4ForwardExtensionSetCrProof(&forward, 1, 1, InvalidScn); - UT_ASSERT(ClusterR4ForwardExtensionGetCrProof(&forward, 0, &master_generation, - &transition_count, &scn)); - UT_ASSERT_EQ((uint64)scn, (uint64)InvalidScn); - break; - case 31: - ClusterR4ForwardExtensionSetCrProof(&forward, (UINT64_C(0xffffffff) << 32) | 1, 1, - InvalidScn); - UT_ASSERT(ClusterR4ForwardExtensionGetCrProof(&forward, UINT64_MAX, - &master_generation, &transition_count, &scn)); - break; - case 32: - UT_ASSERT(ClusterR4ForwardExtensionSetLocator( - &forward, CLUSTER_R4_WIRE_TX_RESOLVE, &locator)); - UT_ASSERT(ClusterR4ForwardExtensionGetLocator( - &forward, CLUSTER_R4_WIRE_TX_RESOLVE, &decoded_locator)); - UT_ASSERT_EQ(memcmp(&decoded_locator, &locator, sizeof(locator)), 0); - break; - case 33: - UT_ASSERT(ClusterR4ForwardExtensionSetLocator( - &forward, CLUSTER_R4_WIRE_UNDO_DATA_FETCH, &locator)); - UT_ASSERT(ClusterR4ForwardExtensionGetLocator( - &forward, CLUSTER_R4_WIRE_UNDO_DATA_FETCH, &decoded_locator)); - UT_ASSERT_EQ(memcmp(&decoded_locator, &locator, sizeof(locator)), 0); - break; - case 34: - UT_ASSERT(ClusterR4ForwardExtensionSetLocator( - &forward, CLUSTER_R4_WIRE_TX_RESOLVE, &locator)); - UT_ASSERT_EQ(ClusterR4WireReadU64(&forward.kind.locator_bytes[0]), - locator.uba.raw[0]); - UT_ASSERT_EQ(ClusterR4WireReadU64(&forward.kind.locator_bytes[8]), - locator.uba.raw[1]); - UT_ASSERT_EQ(ClusterR4WireReadU32(&forward.kind.locator_bytes[16]), - (uint32)locator.xid); - UT_ASSERT_EQ(ClusterR4WireReadU16(&forward.kind.locator_bytes[20]), locator.tt_wrap); - UT_ASSERT_EQ(forward.kind.locator_bytes[22], locator.itl_kind); - UT_ASSERT_EQ(forward.kind.locator_bytes[23], locator.itl_slot_index); - break; - case 35: - memset(&forward, 0xa5, sizeof(forward)); - UT_ASSERT(!ClusterR4ForwardExtensionSetLocator( - &forward, CLUSTER_R4_WIRE_CR_BUILD, &locator)); - UT_ASSERT(bytes_are_zero((const uint8 *)&forward, sizeof(forward))); - break; - case 36: - memset(&forward, 0xa5, sizeof(forward)); - UT_ASSERT(!ClusterR4ForwardExtensionSetLocator( - &forward, CLUSTER_R4_WIRE_MULTI_RESOLVE, &locator)); - UT_ASSERT(bytes_are_zero((const uint8 *)&forward, sizeof(forward))); - break; - case 37: - UT_ASSERT(!ClusterR4ForwardExtensionSetLocator( - NULL, CLUSTER_R4_WIRE_TX_RESOLVE, &locator)); - memset(&forward, 0xa5, sizeof(forward)); - UT_ASSERT(!ClusterR4ForwardExtensionSetLocator( - &forward, CLUSTER_R4_WIRE_TX_RESOLVE, NULL)); - UT_ASSERT(bytes_are_zero((const uint8 *)&forward, sizeof(forward))); - break; - case 38: - ClusterR4ForwardExtensionSetLocator(&forward, CLUSTER_R4_WIRE_TX_RESOLVE, - &locator); - memset(&decoded_locator, 0xa5, sizeof(decoded_locator)); - forward.flags_le[0] = 1; - UT_ASSERT(!ClusterR4ForwardExtensionGetLocator( - &forward, CLUSTER_R4_WIRE_TX_RESOLVE, &decoded_locator)); - UT_ASSERT(bytes_are_zero((const uint8 *)&decoded_locator, sizeof(decoded_locator))); - break; - case 39: - ClusterR4ForwardExtensionSetLocator(&forward, CLUSTER_R4_WIRE_TX_RESOLVE, - &locator); - forward.subject_id_le[3] = 1; - UT_ASSERT(!ClusterR4ForwardExtensionGetLocator( - &forward, CLUSTER_R4_WIRE_TX_RESOLVE, &decoded_locator)); - break; - case 40: - ClusterR4ForwardExtensionSetLocator(&forward, CLUSTER_R4_WIRE_TX_RESOLVE, - &locator); - forward.r4_version++; - UT_ASSERT(!ClusterR4ForwardExtensionGetLocator( - &forward, CLUSTER_R4_WIRE_TX_RESOLVE, &decoded_locator)); - break; - case 41: - ClusterR4ForwardExtensionSetLocator(&forward, CLUSTER_R4_WIRE_TX_RESOLVE, - &locator); - UT_ASSERT(!ClusterR4ForwardExtensionGetLocator( - &forward, CLUSTER_R4_WIRE_UNDO_DATA_FETCH, &decoded_locator)); - break; - case 42: - UT_ASSERT(!ClusterR4ForwardExtensionGetLocator( - NULL, CLUSTER_R4_WIRE_TX_RESOLVE, &decoded_locator)); - ClusterR4ForwardExtensionSetLocator(&forward, CLUSTER_R4_WIRE_TX_RESOLVE, - &locator); - UT_ASSERT(!ClusterR4ForwardExtensionGetLocator( - &forward, CLUSTER_R4_WIRE_TX_RESOLVE, NULL)); - break; - case 43: - ClusterR4ForwardExtensionSetLocator(&forward, CLUSTER_R4_WIRE_TX_RESOLVE, - &locator); - forward.kind.locator_bytes[16] ^= 1; - UT_ASSERT(ClusterR4ForwardExtensionGetLocator( - &forward, CLUSTER_R4_WIRE_TX_RESOLVE, &decoded_locator)); - UT_ASSERT(decoded_locator.xid != locator.xid); - break; - case 44: - UT_ASSERT(ClusterR4ForwardExtensionSetLocatorGeneration( - &forward, CLUSTER_R4_WIRE_UNDO_DATA_FETCH, &locator, - UINT32_C(0x01020304))); - UT_ASSERT(ClusterR4ForwardExtensionGetLocatorGeneration( - &forward, CLUSTER_R4_WIRE_UNDO_DATA_FETCH, &decoded_locator, - &physical_generation)); - UT_ASSERT_EQ(physical_generation, UINT32_C(0x01020304)); - UT_ASSERT_EQ(memcmp(&decoded_locator, &locator, sizeof(locator)), 0); - UT_ASSERT_EQ(forward.subject_id_le[0], 0x04); - UT_ASSERT_EQ(forward.subject_id_le[3], 0x01); - break; - case 45: - UT_ASSERT(ClusterR4ForwardExtensionSetLocatorGeneration( - &forward, CLUSTER_R4_WIRE_TX_RESOLVE, &locator, 0)); - UT_ASSERT(ClusterR4ForwardExtensionGetLocatorGeneration( - &forward, CLUSTER_R4_WIRE_TX_RESOLVE, &decoded_locator, - &physical_generation)); - UT_ASSERT_EQ(physical_generation, 0); - break; - case 46: - memset(&forward, 0xa5, sizeof(forward)); - UT_ASSERT(ClusterR4ForwardExtensionSetLocatorGeneration( - &forward, CLUSTER_R4_WIRE_TX_RESOLVE, &locator, UINT32_MAX)); - UT_ASSERT_EQ(ClusterR4WireReadU32(forward.subject_id_le), UINT32_MAX); - UT_ASSERT(bytes_are_zero(forward.flags_le, sizeof(forward.flags_le))); - break; - case 47: - ClusterR4ForwardExtensionSetLocator(&forward, CLUSTER_R4_WIRE_TX_RESOLVE, &locator); - ClusterR4WireWriteU32(forward.subject_id_le, UINT32_MAX); - memset(&decoded_locator, 0xa5, sizeof(decoded_locator)); - physical_generation = UINT32_C(0xa5a5a5a5); - UT_ASSERT(ClusterR4ForwardExtensionGetLocatorGeneration( - &forward, CLUSTER_R4_WIRE_TX_RESOLVE, &decoded_locator, &physical_generation)); - UT_ASSERT_EQ(memcmp(&decoded_locator, &locator, sizeof(locator)), 0); - UT_ASSERT_EQ(physical_generation, UINT32_MAX); - break; - case 48: - UT_ASSERT(ClusterR4ForwardExtensionSetLocatorGeneration( - &forward, CLUSTER_R4_WIRE_UNDO_DATA_FETCH, &locator, 7)); - forward.flags_le[0] = 1; - UT_ASSERT(!ClusterR4ForwardExtensionGetLocatorGeneration( - &forward, CLUSTER_R4_WIRE_UNDO_DATA_FETCH, &decoded_locator, - &physical_generation)); - break; - case 49: - UT_ASSERT(ClusterR4ForwardExtensionSetLocatorGeneration( - &forward, CLUSTER_R4_WIRE_TX_RESOLVE, &locator, 9)); - UT_ASSERT(!ClusterR4ForwardExtensionGetLocatorGeneration( - &forward, CLUSTER_R4_WIRE_UNDO_DATA_FETCH, &decoded_locator, - &physical_generation)); - break; - case 64: - UT_ASSERT_EQ(CLUSTER_R4_TX_VERDICT_VERSION, 3); - UT_ASSERT_EQ(CLUSTER_R4_TX_VERDICT_HEADER_LEN, 80); - break; - case 65: - input = verdict_resolution(CLUSTER_TX_COMMITTED, - CLUSTER_TX_PROOF_ORIGIN_DURABLE_TT_CLOG); - UT_ASSERT(ClusterR4TxVerdictPageEncode(page, &input)); - UT_ASSERT(ClusterR4TxVerdictPageDecode(page, &input.locator_echo, &output)); - UT_ASSERT_EQ(output.outcome, input.outcome); - UT_ASSERT_EQ(output.proof_kind, input.proof_kind); - UT_ASSERT_EQ((uint64)output.commit_scn, (uint64)input.commit_scn); - break; - case 66: - input = verdict_resolution(CLUSTER_TX_ABORTED, CLUSTER_TX_PROOF_ITL_CLEANOUT); - UT_ASSERT(ClusterR4TxVerdictPageEncode(page, &input)); - UT_ASSERT(ClusterR4TxVerdictPageDecode(page, &input.locator_echo, &output)); - UT_ASSERT_EQ(output.outcome, CLUSTER_TX_ABORTED); - break; - case 67: - input = verdict_resolution(CLUSTER_TX_IN_PROGRESS, - CLUSTER_TX_PROOF_ORIGIN_DURABLE_TT_CLOG); - UT_ASSERT(ClusterR4TxVerdictPageEncode(page, &input)); - UT_ASSERT(ClusterR4TxVerdictPageDecode(page, &input.locator_echo, &output)); - UT_ASSERT_EQ(output.outcome, CLUSTER_TX_IN_PROGRESS); - break; - case 68: - input = verdict_resolution(CLUSTER_TX_PREPARED, CLUSTER_TX_PROOF_ORIGIN_TWOPHASE); - UT_ASSERT(ClusterR4TxVerdictPageEncode(page, &input)); - UT_ASSERT(ClusterR4TxVerdictPageDecode(page, &input.locator_echo, &output)); - UT_ASSERT_EQ(output.outcome, CLUSTER_TX_PREPARED); - break; - case 69: - input = verdict_resolution(CLUSTER_TX_UNKNOWN, CLUSTER_TX_PROOF_NONE); - UT_ASSERT(ClusterR4TxVerdictPageEncode(page, &input)); - UT_ASSERT(ClusterR4TxVerdictPageDecode(page, &input.locator_echo, &output)); - UT_ASSERT_EQ(output.outcome, CLUSTER_TX_UNKNOWN); - break; - case 70: - input = verdict_resolution(CLUSTER_TX_UNKNOWN, - CLUSTER_TX_PROOF_RECYCLED_BELOW_HORIZON); - UT_ASSERT(ClusterR4TxVerdictPageEncode(page, &input)); - UT_ASSERT(ClusterR4TxVerdictPageDecode(page, &input.locator_echo, &output)); - UT_ASSERT_EQ((uint64)output.horizon_scn, (uint64)input.horizon_scn); - break; - case 71: - input = verdict_resolution(CLUSTER_TX_COMMITTED, - CLUSTER_TX_PROOF_RECOVERY_MATERIALIZED); - UT_ASSERT(ClusterR4TxVerdictPageEncode(page, &input)); - UT_ASSERT(ClusterR4TxVerdictPageDecode(page, &input.locator_echo, &output)); - UT_ASSERT_EQ(output.authority.origin_epoch, 0); - break; - case 72: - input = verdict_resolution(CLUSTER_TX_COMMITTED, - CLUSTER_TX_PROOF_ORIGIN_DURABLE_TT_CLOG); - UT_ASSERT(ClusterR4TxVerdictPageEncode(page, &input)); - UT_ASSERT_EQ(ClusterR4WireReadU64(&page[12]), input.locator_echo.uba.raw[0]); - UT_ASSERT_EQ(ClusterR4WireReadU64(&page[20]), input.locator_echo.uba.raw[1]); - break; - case 73: - input = verdict_resolution(CLUSTER_TX_COMMITTED, - CLUSTER_TX_PROOF_ORIGIN_DURABLE_TT_CLOG); - UT_ASSERT(ClusterR4TxVerdictPageEncode(page, &input)); - UT_ASSERT_EQ(page[28], (uint8)(input.locator_echo.xid & 0xff)); - UT_ASSERT_EQ(page[32], 7); - break; - case 74: - input = verdict_resolution(CLUSTER_TX_COMMITTED, - CLUSTER_TX_PROOF_ORIGIN_DURABLE_TT_CLOG); - UT_ASSERT(ClusterR4TxVerdictPageEncode(page, &input)); - UT_ASSERT_EQ((uint32)ClusterR4WireReadU32(&page[36]), (uint32)input.top_xid); - UT_ASSERT_EQ(ClusterR4WireReadU64(&page[40]), (uint64)input.commit_scn); - break; - case 75: - input = verdict_resolution(CLUSTER_TX_COMMITTED, - CLUSTER_TX_PROOF_ORIGIN_DURABLE_TT_CLOG); - UT_ASSERT(ClusterR4TxVerdictPageEncode(page, &input)); - UT_ASSERT(bytes_are_zero(page + CLUSTER_R4_TX_VERDICT_HEADER_LEN, - BLCKSZ - CLUSTER_R4_TX_VERDICT_HEADER_LEN)); - break; - case 76: - input = verdict_resolution(CLUSTER_TX_PREPARED, CLUSTER_TX_PROOF_ITL_CLEANOUT); - memset(page, 0xa5, sizeof(page)); - UT_ASSERT(!ClusterR4TxVerdictPageEncode(page, &input)); - UT_ASSERT(bytes_are_zero(page, sizeof(page))); - break; - case 77: - UT_ASSERT(!ClusterR4TxVerdictPageEncode(page, NULL)); - UT_ASSERT(!ClusterR4TxVerdictPageEncode(NULL, &input)); - break; - case 78: - input = verdict_resolution(CLUSTER_TX_COMMITTED, - CLUSTER_TX_PROOF_ORIGIN_DURABLE_TT_CLOG); - ClusterR4TxVerdictPageEncode(page, &input); - page[0] ^= 1; - UT_ASSERT(!ClusterR4TxVerdictPageDecode(page, &input.locator_echo, &output)); - break; - case 79: - input = verdict_resolution(CLUSTER_TX_COMMITTED, - CLUSTER_TX_PROOF_ORIGIN_DURABLE_TT_CLOG); - ClusterR4TxVerdictPageEncode(page, &input); - page[4]++; - UT_ASSERT(!ClusterR4TxVerdictPageDecode(page, &input.locator_echo, &output)); - break; - case 80: - input = verdict_resolution(CLUSTER_TX_COMMITTED, - CLUSTER_TX_PROOF_ORIGIN_DURABLE_TT_CLOG); - ClusterR4TxVerdictPageEncode(page, &input); - page[6]++; - UT_ASSERT(!ClusterR4TxVerdictPageDecode(page, &input.locator_echo, &output)); - break; - case 81: - input = verdict_resolution(CLUSTER_TX_COMMITTED, - CLUSTER_TX_PROOF_ORIGIN_DURABLE_TT_CLOG); - ClusterR4TxVerdictPageEncode(page, &input); - page[10] = 1; - UT_ASSERT(!ClusterR4TxVerdictPageDecode(page, &input.locator_echo, &output)); - break; - case 82: - input = verdict_resolution(CLUSTER_TX_COMMITTED, - CLUSTER_TX_PROOF_ORIGIN_DURABLE_TT_CLOG); - ClusterR4TxVerdictPageEncode(page, &input); - page[BLCKSZ - 1] = 1; - UT_ASSERT(!ClusterR4TxVerdictPageDecode(page, &input.locator_echo, &output)); - break; - case 83: - input = verdict_resolution(CLUSTER_TX_COMMITTED, - CLUSTER_TX_PROOF_ORIGIN_DURABLE_TT_CLOG); - ClusterR4TxVerdictPageEncode(page, &input); - input.locator_echo.xid++; - UT_ASSERT(!ClusterR4TxVerdictPageDecode(page, &input.locator_echo, &output)); - break; - case 84: - input = verdict_resolution(CLUSTER_TX_COMMITTED, - CLUSTER_TX_PROOF_ORIGIN_DURABLE_TT_CLOG); - ClusterR4TxVerdictPageEncode(page, &input); - page[8] = CLUSTER_TX_PREPARED; - UT_ASSERT(!ClusterR4TxVerdictPageDecode(page, &input.locator_echo, &output)); - break; - case 85: - input = verdict_resolution(CLUSTER_TX_COMMITTED, - CLUSTER_TX_PROOF_ORIGIN_DURABLE_TT_CLOG); - ClusterR4TxVerdictPageEncode(page, &input); - memset(&output, 0xa5, sizeof(output)); - page[9] = 0xff; - UT_ASSERT(!ClusterR4TxVerdictPageDecode(page, &input.locator_echo, &output)); - UT_ASSERT(bytes_are_zero((const uint8 *)&output, sizeof(output))); - break; - case 86: - input = verdict_resolution(CLUSTER_TX_COMMITTED, - CLUSTER_TX_PROOF_ORIGIN_DURABLE_TT_CLOG); - ClusterR4TxVerdictPageEncode(page, &input); - UT_ASSERT_EQ(ClusterR4WireReadU64(&page[56]), input.authority.origin_epoch); - UT_ASSERT_EQ(ClusterR4WireReadU64(&page[64]), input.authority.tt_generation); - UT_ASSERT_EQ(ClusterR4WireReadU64(&page[72]), (uint64)input.authority.authority_scn); - break; - case 87: - input = verdict_resolution(CLUSTER_TX_COMMITTED, - CLUSTER_TX_PROOF_ORIGIN_DURABLE_TT_CLOG); - ClusterR4TxVerdictPageEncode(page, &input); - UT_ASSERT(!ClusterR4TxVerdictPageDecode(NULL, &input.locator_echo, &output)); - UT_ASSERT(!ClusterR4TxVerdictPageDecode(page, NULL, &output)); - UT_ASSERT(!ClusterR4TxVerdictPageDecode(page, &input.locator_echo, NULL)); - break; - case 88: - input = verdict_resolution(CLUSTER_TX_COMMITTED, - CLUSTER_TX_PROOF_ORIGIN_DURABLE_TT_CLOG); - locator = input.locator_echo; - locator.tt_wrap = TT_WRAP_INVALID; - UT_ASSERT(ClusterR4TxVerdictPageEncode(page, &input)); - UT_ASSERT(ClusterR4TxVerdictPageDecode(page, &locator, &output)); - UT_ASSERT_EQ(output.locator_echo.tt_wrap, 7); - break; - case 89: - input = verdict_resolution(CLUSTER_TX_COMMITTED, - CLUSTER_TX_PROOF_ORIGIN_DURABLE_TT_CLOG); - locator = input.locator_echo; - locator.tt_wrap = TT_WRAP_INVALID; - input.locator_echo.tt_wrap = TT_WRAP_INVALID; - UT_ASSERT(ClusterR4TxVerdictPageEncode(page, &input)); - memset(&output, 0xA5, sizeof(output)); - UT_ASSERT(!ClusterR4TxVerdictPageDecode(page, &locator, &output)); - UT_ASSERT(bytes_are_zero((const uint8 *)&output, sizeof(output))); - break; - case 90: - input = verdict_resolution(CLUSTER_TX_COMMITTED, - CLUSTER_TX_PROOF_ORIGIN_DURABLE_TT_CLOG); - locator = input.locator_echo; - locator.tt_wrap = 8; - UT_ASSERT(ClusterR4TxVerdictPageEncode(page, &input)); - UT_ASSERT(!ClusterR4TxVerdictPageDecode(page, &locator, &output)); - break; - default: - value = UINT64_C(0x0102030405060708) ^ ((uint64)vector << 33) - ^ ((uint64)vector * UINT64_C(0x9e3779b97f4a7c15)); - ClusterR4WireWriteU64(bytes, value); - UT_ASSERT(ClusterR4WireReadU64(bytes) == value); - break; + case 0: + UT_ASSERT_EQ(sizeof(request), 16); + break; + case 1: + UT_ASSERT_EQ(sizeof(forward), 32); + break; + case 2: + UT_ASSERT_EQ( + offsetof(ClusterR4ForwardExtension, kind.cr.master_resource_transition_count_le), 12); + break; + case 3: + UT_ASSERT_EQ(CLUSTER_R4_WIRE_VERSION, 1); + break; + case 4: + UT_ASSERT_EQ(CLUSTER_R4_FORWARD_EXTENDED, 6); + break; + case 5: + UT_ASSERT_EQ(CLUSTER_R4_WIRE_CR_BUILD, 1); + break; + case 6: + UT_ASSERT(ClusterR4RequestExtensionSetCr(&request, (SCN)0x1234)); + UT_ASSERT(ClusterR4RequestExtensionGetCr(&request, &scn)); + UT_ASSERT_EQ((uint64)scn, UINT64_C(0x1234)); + break; + case 7: + UT_ASSERT(!ClusterR4RequestExtensionSetCr(NULL, (SCN)1)); + break; + case 8: + UT_ASSERT(!ClusterR4RequestExtensionSetCr(&request, InvalidScn)); + break; + case 9: + UT_ASSERT(!ClusterR4RequestExtensionGetCr(NULL, &scn)); + break; + case 10: + UT_ASSERT(!ClusterR4RequestExtensionGetCr(&request, NULL)); + break; + case 11: + ClusterR4RequestExtensionSetCr(&request, (SCN)1); + request.r4_version++; + UT_ASSERT(!ClusterR4RequestExtensionGetCr(&request, &scn)); + break; + case 12: + ClusterR4RequestExtensionSetCr(&request, (SCN)1); + request.r4_kind = CLUSTER_R4_WIRE_TX_RESOLVE; + UT_ASSERT(!ClusterR4RequestExtensionGetCr(&request, &scn)); + break; + case 13: + ClusterR4RequestExtensionSetCr(&request, (SCN)1); + request.flags_le[0] = 1; + UT_ASSERT(!ClusterR4RequestExtensionGetCr(&request, &scn)); + break; + case 14: + ClusterR4RequestExtensionSetCr(&request, (SCN)1); + request.flags_le[1] = 1; + UT_ASSERT(!ClusterR4RequestExtensionGetCr(&request, &scn)); + break; + case 15: + ClusterR4RequestExtensionSetCr(&request, (SCN)1); + request.reserved[3] = 1; + UT_ASSERT(!ClusterR4RequestExtensionGetCr(&request, &scn)); + break; + case 16: + ClusterR4ForwardExtensionSetCrProof(&forward, (UINT64_C(9) << 32) | 4, UINT64_C(7), + (SCN)0x5678); + UT_ASSERT(ClusterR4ForwardExtensionGetCrProof(&forward, 9, &master_generation, + &transition_count, &scn)); + UT_ASSERT(master_generation == ((UINT64_C(9) << 32) | 4)); + UT_ASSERT(transition_count == UINT64_C(7)); + UT_ASSERT((uint64)scn == UINT64_C(0x5678)); + break; + case 17: + UT_ASSERT(!ClusterR4ForwardExtensionGetCrProof(NULL, 0, &master_generation, + &transition_count, &scn)); + break; + case 18: + ClusterR4ForwardExtensionSetCrProof(&forward, 1, 1, InvalidScn); + UT_ASSERT(!ClusterR4ForwardExtensionGetCrProof(&forward, 0, NULL, &transition_count, &scn)); + break; + case 19: + ClusterR4ForwardExtensionSetCrProof(&forward, 1, 1, InvalidScn); + UT_ASSERT( + !ClusterR4ForwardExtensionGetCrProof(&forward, 0, &master_generation, NULL, &scn)); + break; + case 20: + ClusterR4ForwardExtensionSetCrProof(&forward, 1, 1, InvalidScn); + UT_ASSERT(!ClusterR4ForwardExtensionGetCrProof(&forward, 0, &master_generation, + &transition_count, NULL)); + break; + case 21: + ClusterR4ForwardExtensionSetCrProof(&forward, 1, 1, InvalidScn); + forward.r4_version++; + UT_ASSERT(!ClusterR4ForwardExtensionGetCrProof(&forward, 0, &master_generation, + &transition_count, &scn)); + break; + case 22: + ClusterR4ForwardExtensionSetCrProof(&forward, 1, 1, InvalidScn); + forward.r4_kind = CLUSTER_R4_WIRE_TX_RESOLVE; + UT_ASSERT(!ClusterR4ForwardExtensionGetCrProof(&forward, 0, &master_generation, + &transition_count, &scn)); + break; + case 23: + ClusterR4ForwardExtensionSetCrProof(&forward, 1, 1, InvalidScn); + forward.flags_le[0] = 1; + UT_ASSERT(!ClusterR4ForwardExtensionGetCrProof(&forward, 0, &master_generation, + &transition_count, &scn)); + break; + case 24: + ClusterR4ForwardExtensionSetCrProof(&forward, 1, 1, InvalidScn); + forward.subject_id_le[0] = 1; + UT_ASSERT(!ClusterR4ForwardExtensionGetCrProof(&forward, 0, &master_generation, + &transition_count, &scn)); + break; + case 25: + ClusterR4ForwardExtensionSetCrProof(&forward, 0, 1, InvalidScn); + UT_ASSERT(!ClusterR4ForwardExtensionGetCrProof(&forward, 0, &master_generation, + &transition_count, &scn)); + break; + case 26: + ClusterR4ForwardExtensionSetCrProof(&forward, UINT64_C(1) << 32, 1, InvalidScn); + UT_ASSERT(!ClusterR4ForwardExtensionGetCrProof(&forward, 1, &master_generation, + &transition_count, &scn)); + break; + case 27: + ClusterR4ForwardExtensionSetCrProof(&forward, 1, 0, InvalidScn); + UT_ASSERT(!ClusterR4ForwardExtensionGetCrProof(&forward, 0, &master_generation, + &transition_count, &scn)); + break; + case 28: + ClusterR4ForwardExtensionSetCrProof(&forward, 1, UINT64_MAX, InvalidScn); + UT_ASSERT(!ClusterR4ForwardExtensionGetCrProof(&forward, 0, &master_generation, + &transition_count, &scn)); + break; + case 29: + ClusterR4ForwardExtensionSetCrProof(&forward, (UINT64_C(2) << 32) | 1, 1, InvalidScn); + UT_ASSERT(!ClusterR4ForwardExtensionGetCrProof(&forward, 1, &master_generation, + &transition_count, &scn)); + break; + case 30: + ClusterR4ForwardExtensionSetCrProof(&forward, 1, 1, InvalidScn); + UT_ASSERT(ClusterR4ForwardExtensionGetCrProof(&forward, 0, &master_generation, + &transition_count, &scn)); + UT_ASSERT_EQ((uint64)scn, (uint64)InvalidScn); + break; + case 31: + ClusterR4ForwardExtensionSetCrProof(&forward, (UINT64_C(0xffffffff) << 32) | 1, 1, + InvalidScn); + UT_ASSERT(ClusterR4ForwardExtensionGetCrProof(&forward, UINT64_MAX, &master_generation, + &transition_count, &scn)); + break; + case 32: + UT_ASSERT( + ClusterR4ForwardExtensionSetLocator(&forward, CLUSTER_R4_WIRE_TX_RESOLVE, &locator)); + UT_ASSERT(ClusterR4ForwardExtensionGetLocator(&forward, CLUSTER_R4_WIRE_TX_RESOLVE, + &decoded_locator)); + UT_ASSERT_EQ(memcmp(&decoded_locator, &locator, sizeof(locator)), 0); + break; + case 33: + UT_ASSERT(ClusterR4ForwardExtensionSetLocator(&forward, CLUSTER_R4_WIRE_UNDO_DATA_FETCH, + &locator)); + UT_ASSERT(ClusterR4ForwardExtensionGetLocator(&forward, CLUSTER_R4_WIRE_UNDO_DATA_FETCH, + &decoded_locator)); + UT_ASSERT_EQ(memcmp(&decoded_locator, &locator, sizeof(locator)), 0); + break; + case 34: + UT_ASSERT( + ClusterR4ForwardExtensionSetLocator(&forward, CLUSTER_R4_WIRE_TX_RESOLVE, &locator)); + UT_ASSERT_EQ(ClusterR4WireReadU64(&forward.kind.locator_bytes[0]), locator.uba.raw[0]); + UT_ASSERT_EQ(ClusterR4WireReadU64(&forward.kind.locator_bytes[8]), locator.uba.raw[1]); + UT_ASSERT_EQ(ClusterR4WireReadU32(&forward.kind.locator_bytes[16]), (uint32)locator.xid); + UT_ASSERT_EQ(ClusterR4WireReadU16(&forward.kind.locator_bytes[20]), locator.tt_wrap); + UT_ASSERT_EQ(forward.kind.locator_bytes[22], locator.itl_kind); + UT_ASSERT_EQ(forward.kind.locator_bytes[23], locator.itl_slot_index); + break; + case 35: + memset(&forward, 0xa5, sizeof(forward)); + UT_ASSERT( + !ClusterR4ForwardExtensionSetLocator(&forward, CLUSTER_R4_WIRE_CR_BUILD, &locator)); + UT_ASSERT(bytes_are_zero((const uint8 *)&forward, sizeof(forward))); + break; + case 36: + memset(&forward, 0xa5, sizeof(forward)); + UT_ASSERT(!ClusterR4ForwardExtensionSetLocator(&forward, CLUSTER_R4_WIRE_MULTI_RESOLVE, + &locator)); + UT_ASSERT(bytes_are_zero((const uint8 *)&forward, sizeof(forward))); + break; + case 37: + UT_ASSERT(!ClusterR4ForwardExtensionSetLocator(NULL, CLUSTER_R4_WIRE_TX_RESOLVE, &locator)); + memset(&forward, 0xa5, sizeof(forward)); + UT_ASSERT(!ClusterR4ForwardExtensionSetLocator(&forward, CLUSTER_R4_WIRE_TX_RESOLVE, NULL)); + UT_ASSERT(bytes_are_zero((const uint8 *)&forward, sizeof(forward))); + break; + case 38: + ClusterR4ForwardExtensionSetLocator(&forward, CLUSTER_R4_WIRE_TX_RESOLVE, &locator); + memset(&decoded_locator, 0xa5, sizeof(decoded_locator)); + forward.flags_le[0] = 1; + UT_ASSERT(!ClusterR4ForwardExtensionGetLocator(&forward, CLUSTER_R4_WIRE_TX_RESOLVE, + &decoded_locator)); + UT_ASSERT(bytes_are_zero((const uint8 *)&decoded_locator, sizeof(decoded_locator))); + break; + case 39: + ClusterR4ForwardExtensionSetLocator(&forward, CLUSTER_R4_WIRE_TX_RESOLVE, &locator); + forward.subject_id_le[3] = 1; + UT_ASSERT(!ClusterR4ForwardExtensionGetLocator(&forward, CLUSTER_R4_WIRE_TX_RESOLVE, + &decoded_locator)); + break; + case 40: + ClusterR4ForwardExtensionSetLocator(&forward, CLUSTER_R4_WIRE_TX_RESOLVE, &locator); + forward.r4_version++; + UT_ASSERT(!ClusterR4ForwardExtensionGetLocator(&forward, CLUSTER_R4_WIRE_TX_RESOLVE, + &decoded_locator)); + break; + case 41: + ClusterR4ForwardExtensionSetLocator(&forward, CLUSTER_R4_WIRE_TX_RESOLVE, &locator); + UT_ASSERT(!ClusterR4ForwardExtensionGetLocator(&forward, CLUSTER_R4_WIRE_UNDO_DATA_FETCH, + &decoded_locator)); + break; + case 42: + UT_ASSERT(!ClusterR4ForwardExtensionGetLocator(NULL, CLUSTER_R4_WIRE_TX_RESOLVE, + &decoded_locator)); + ClusterR4ForwardExtensionSetLocator(&forward, CLUSTER_R4_WIRE_TX_RESOLVE, &locator); + UT_ASSERT(!ClusterR4ForwardExtensionGetLocator(&forward, CLUSTER_R4_WIRE_TX_RESOLVE, NULL)); + break; + case 43: + ClusterR4ForwardExtensionSetLocator(&forward, CLUSTER_R4_WIRE_TX_RESOLVE, &locator); + forward.kind.locator_bytes[16] ^= 1; + UT_ASSERT(ClusterR4ForwardExtensionGetLocator(&forward, CLUSTER_R4_WIRE_TX_RESOLVE, + &decoded_locator)); + UT_ASSERT(decoded_locator.xid != locator.xid); + break; + case 44: + UT_ASSERT(ClusterR4ForwardExtensionSetLocatorGeneration( + &forward, CLUSTER_R4_WIRE_UNDO_DATA_FETCH, &locator, UINT32_C(0x01020304))); + UT_ASSERT(ClusterR4ForwardExtensionGetLocatorGeneration( + &forward, CLUSTER_R4_WIRE_UNDO_DATA_FETCH, &decoded_locator, &physical_generation)); + UT_ASSERT_EQ(physical_generation, UINT32_C(0x01020304)); + UT_ASSERT_EQ(memcmp(&decoded_locator, &locator, sizeof(locator)), 0); + UT_ASSERT_EQ(forward.subject_id_le[0], 0x04); + UT_ASSERT_EQ(forward.subject_id_le[3], 0x01); + break; + case 45: + UT_ASSERT(ClusterR4ForwardExtensionSetLocatorGeneration( + &forward, CLUSTER_R4_WIRE_TX_RESOLVE, &locator, 0)); + UT_ASSERT(ClusterR4ForwardExtensionGetLocatorGeneration( + &forward, CLUSTER_R4_WIRE_TX_RESOLVE, &decoded_locator, &physical_generation)); + UT_ASSERT_EQ(physical_generation, 0); + break; + case 46: + memset(&forward, 0xa5, sizeof(forward)); + UT_ASSERT(ClusterR4ForwardExtensionSetLocatorGeneration( + &forward, CLUSTER_R4_WIRE_TX_RESOLVE, &locator, UINT32_MAX)); + UT_ASSERT_EQ(ClusterR4WireReadU32(forward.subject_id_le), UINT32_MAX); + UT_ASSERT(bytes_are_zero(forward.flags_le, sizeof(forward.flags_le))); + break; + case 47: + ClusterR4ForwardExtensionSetLocator(&forward, CLUSTER_R4_WIRE_TX_RESOLVE, &locator); + ClusterR4WireWriteU32(forward.subject_id_le, UINT32_MAX); + memset(&decoded_locator, 0xa5, sizeof(decoded_locator)); + physical_generation = UINT32_C(0xa5a5a5a5); + UT_ASSERT(ClusterR4ForwardExtensionGetLocatorGeneration( + &forward, CLUSTER_R4_WIRE_TX_RESOLVE, &decoded_locator, &physical_generation)); + UT_ASSERT_EQ(memcmp(&decoded_locator, &locator, sizeof(locator)), 0); + UT_ASSERT_EQ(physical_generation, UINT32_MAX); + break; + case 48: + UT_ASSERT(ClusterR4ForwardExtensionSetLocatorGeneration( + &forward, CLUSTER_R4_WIRE_UNDO_DATA_FETCH, &locator, 7)); + forward.flags_le[0] = 1; + UT_ASSERT(!ClusterR4ForwardExtensionGetLocatorGeneration( + &forward, CLUSTER_R4_WIRE_UNDO_DATA_FETCH, &decoded_locator, &physical_generation)); + break; + case 49: + UT_ASSERT(ClusterR4ForwardExtensionSetLocatorGeneration( + &forward, CLUSTER_R4_WIRE_TX_RESOLVE, &locator, 9)); + UT_ASSERT(!ClusterR4ForwardExtensionGetLocatorGeneration( + &forward, CLUSTER_R4_WIRE_UNDO_DATA_FETCH, &decoded_locator, &physical_generation)); + break; + case 64: + UT_ASSERT_EQ(CLUSTER_R4_TX_VERDICT_VERSION, 3); + UT_ASSERT_EQ(CLUSTER_R4_TX_VERDICT_HEADER_LEN, 80); + break; + case 65: + input = verdict_resolution(CLUSTER_TX_COMMITTED, CLUSTER_TX_PROOF_ORIGIN_DURABLE_TT_CLOG); + UT_ASSERT(ClusterR4TxVerdictPageEncode(page, &input)); + UT_ASSERT(ClusterR4TxVerdictPageDecode(page, &input.locator_echo, &output)); + UT_ASSERT_EQ(output.outcome, input.outcome); + UT_ASSERT_EQ(output.proof_kind, input.proof_kind); + UT_ASSERT_EQ((uint64)output.commit_scn, (uint64)input.commit_scn); + break; + case 66: + input = verdict_resolution(CLUSTER_TX_ABORTED, CLUSTER_TX_PROOF_ITL_CLEANOUT); + UT_ASSERT(ClusterR4TxVerdictPageEncode(page, &input)); + UT_ASSERT(ClusterR4TxVerdictPageDecode(page, &input.locator_echo, &output)); + UT_ASSERT_EQ(output.outcome, CLUSTER_TX_ABORTED); + break; + case 67: + input = verdict_resolution(CLUSTER_TX_IN_PROGRESS, CLUSTER_TX_PROOF_ORIGIN_DURABLE_TT_CLOG); + UT_ASSERT(ClusterR4TxVerdictPageEncode(page, &input)); + UT_ASSERT(ClusterR4TxVerdictPageDecode(page, &input.locator_echo, &output)); + UT_ASSERT_EQ(output.outcome, CLUSTER_TX_IN_PROGRESS); + break; + case 68: + input = verdict_resolution(CLUSTER_TX_PREPARED, CLUSTER_TX_PROOF_ORIGIN_TWOPHASE); + UT_ASSERT(ClusterR4TxVerdictPageEncode(page, &input)); + UT_ASSERT(ClusterR4TxVerdictPageDecode(page, &input.locator_echo, &output)); + UT_ASSERT_EQ(output.outcome, CLUSTER_TX_PREPARED); + break; + case 69: + input = verdict_resolution(CLUSTER_TX_UNKNOWN, CLUSTER_TX_PROOF_NONE); + UT_ASSERT(ClusterR4TxVerdictPageEncode(page, &input)); + UT_ASSERT(ClusterR4TxVerdictPageDecode(page, &input.locator_echo, &output)); + UT_ASSERT_EQ(output.outcome, CLUSTER_TX_UNKNOWN); + break; + case 70: + input = verdict_resolution(CLUSTER_TX_UNKNOWN, CLUSTER_TX_PROOF_RECYCLED_BELOW_HORIZON); + UT_ASSERT(ClusterR4TxVerdictPageEncode(page, &input)); + UT_ASSERT(ClusterR4TxVerdictPageDecode(page, &input.locator_echo, &output)); + UT_ASSERT_EQ((uint64)output.horizon_scn, (uint64)input.horizon_scn); + break; + case 71: + input = verdict_resolution(CLUSTER_TX_COMMITTED, CLUSTER_TX_PROOF_RECOVERY_MATERIALIZED); + UT_ASSERT(ClusterR4TxVerdictPageEncode(page, &input)); + UT_ASSERT(ClusterR4TxVerdictPageDecode(page, &input.locator_echo, &output)); + UT_ASSERT_EQ(output.authority.origin_epoch, 0); + break; + case 72: + input = verdict_resolution(CLUSTER_TX_COMMITTED, CLUSTER_TX_PROOF_ORIGIN_DURABLE_TT_CLOG); + UT_ASSERT(ClusterR4TxVerdictPageEncode(page, &input)); + UT_ASSERT_EQ(ClusterR4WireReadU64(&page[12]), input.locator_echo.uba.raw[0]); + UT_ASSERT_EQ(ClusterR4WireReadU64(&page[20]), input.locator_echo.uba.raw[1]); + break; + case 73: + input = verdict_resolution(CLUSTER_TX_COMMITTED, CLUSTER_TX_PROOF_ORIGIN_DURABLE_TT_CLOG); + UT_ASSERT(ClusterR4TxVerdictPageEncode(page, &input)); + UT_ASSERT_EQ(page[28], (uint8)(input.locator_echo.xid & 0xff)); + UT_ASSERT_EQ(page[32], 7); + break; + case 74: + input = verdict_resolution(CLUSTER_TX_COMMITTED, CLUSTER_TX_PROOF_ORIGIN_DURABLE_TT_CLOG); + UT_ASSERT(ClusterR4TxVerdictPageEncode(page, &input)); + UT_ASSERT_EQ((uint32)ClusterR4WireReadU32(&page[36]), (uint32)input.top_xid); + UT_ASSERT_EQ(ClusterR4WireReadU64(&page[40]), (uint64)input.commit_scn); + break; + case 75: + input = verdict_resolution(CLUSTER_TX_COMMITTED, CLUSTER_TX_PROOF_ORIGIN_DURABLE_TT_CLOG); + UT_ASSERT(ClusterR4TxVerdictPageEncode(page, &input)); + UT_ASSERT(bytes_are_zero(page + CLUSTER_R4_TX_VERDICT_HEADER_LEN, + BLCKSZ - CLUSTER_R4_TX_VERDICT_HEADER_LEN)); + break; + case 76: + input = verdict_resolution(CLUSTER_TX_PREPARED, CLUSTER_TX_PROOF_ITL_CLEANOUT); + memset(page, 0xa5, sizeof(page)); + UT_ASSERT(!ClusterR4TxVerdictPageEncode(page, &input)); + UT_ASSERT(bytes_are_zero(page, sizeof(page))); + break; + case 77: + UT_ASSERT(!ClusterR4TxVerdictPageEncode(page, NULL)); + UT_ASSERT(!ClusterR4TxVerdictPageEncode(NULL, &input)); + break; + case 78: + input = verdict_resolution(CLUSTER_TX_COMMITTED, CLUSTER_TX_PROOF_ORIGIN_DURABLE_TT_CLOG); + ClusterR4TxVerdictPageEncode(page, &input); + page[0] ^= 1; + UT_ASSERT(!ClusterR4TxVerdictPageDecode(page, &input.locator_echo, &output)); + break; + case 79: + input = verdict_resolution(CLUSTER_TX_COMMITTED, CLUSTER_TX_PROOF_ORIGIN_DURABLE_TT_CLOG); + ClusterR4TxVerdictPageEncode(page, &input); + page[4]++; + UT_ASSERT(!ClusterR4TxVerdictPageDecode(page, &input.locator_echo, &output)); + break; + case 80: + input = verdict_resolution(CLUSTER_TX_COMMITTED, CLUSTER_TX_PROOF_ORIGIN_DURABLE_TT_CLOG); + ClusterR4TxVerdictPageEncode(page, &input); + page[6]++; + UT_ASSERT(!ClusterR4TxVerdictPageDecode(page, &input.locator_echo, &output)); + break; + case 81: + input = verdict_resolution(CLUSTER_TX_COMMITTED, CLUSTER_TX_PROOF_ORIGIN_DURABLE_TT_CLOG); + ClusterR4TxVerdictPageEncode(page, &input); + page[10] = 1; + UT_ASSERT(!ClusterR4TxVerdictPageDecode(page, &input.locator_echo, &output)); + break; + case 82: + input = verdict_resolution(CLUSTER_TX_COMMITTED, CLUSTER_TX_PROOF_ORIGIN_DURABLE_TT_CLOG); + ClusterR4TxVerdictPageEncode(page, &input); + page[BLCKSZ - 1] = 1; + UT_ASSERT(!ClusterR4TxVerdictPageDecode(page, &input.locator_echo, &output)); + break; + case 83: + input = verdict_resolution(CLUSTER_TX_COMMITTED, CLUSTER_TX_PROOF_ORIGIN_DURABLE_TT_CLOG); + ClusterR4TxVerdictPageEncode(page, &input); + input.locator_echo.xid++; + UT_ASSERT(!ClusterR4TxVerdictPageDecode(page, &input.locator_echo, &output)); + break; + case 84: + input = verdict_resolution(CLUSTER_TX_COMMITTED, CLUSTER_TX_PROOF_ORIGIN_DURABLE_TT_CLOG); + ClusterR4TxVerdictPageEncode(page, &input); + page[8] = CLUSTER_TX_PREPARED; + UT_ASSERT(!ClusterR4TxVerdictPageDecode(page, &input.locator_echo, &output)); + break; + case 85: + input = verdict_resolution(CLUSTER_TX_COMMITTED, CLUSTER_TX_PROOF_ORIGIN_DURABLE_TT_CLOG); + ClusterR4TxVerdictPageEncode(page, &input); + memset(&output, 0xa5, sizeof(output)); + page[9] = 0xff; + UT_ASSERT(!ClusterR4TxVerdictPageDecode(page, &input.locator_echo, &output)); + UT_ASSERT(bytes_are_zero((const uint8 *)&output, sizeof(output))); + break; + case 86: + input = verdict_resolution(CLUSTER_TX_COMMITTED, CLUSTER_TX_PROOF_ORIGIN_DURABLE_TT_CLOG); + ClusterR4TxVerdictPageEncode(page, &input); + UT_ASSERT_EQ(ClusterR4WireReadU64(&page[56]), input.authority.origin_epoch); + UT_ASSERT_EQ(ClusterR4WireReadU64(&page[64]), input.authority.tt_generation); + UT_ASSERT_EQ(ClusterR4WireReadU64(&page[72]), (uint64)input.authority.authority_scn); + break; + case 87: + input = verdict_resolution(CLUSTER_TX_COMMITTED, CLUSTER_TX_PROOF_ORIGIN_DURABLE_TT_CLOG); + ClusterR4TxVerdictPageEncode(page, &input); + UT_ASSERT(!ClusterR4TxVerdictPageDecode(NULL, &input.locator_echo, &output)); + UT_ASSERT(!ClusterR4TxVerdictPageDecode(page, NULL, &output)); + UT_ASSERT(!ClusterR4TxVerdictPageDecode(page, &input.locator_echo, NULL)); + break; + case 88: + input = verdict_resolution(CLUSTER_TX_COMMITTED, CLUSTER_TX_PROOF_ORIGIN_DURABLE_TT_CLOG); + locator = input.locator_echo; + locator.tt_wrap = TT_WRAP_INVALID; + UT_ASSERT(ClusterR4TxVerdictPageEncode(page, &input)); + UT_ASSERT(ClusterR4TxVerdictPageDecode(page, &locator, &output)); + UT_ASSERT_EQ(output.locator_echo.tt_wrap, 7); + break; + case 89: + input = verdict_resolution(CLUSTER_TX_COMMITTED, CLUSTER_TX_PROOF_ORIGIN_DURABLE_TT_CLOG); + locator = input.locator_echo; + locator.tt_wrap = TT_WRAP_INVALID; + input.locator_echo.tt_wrap = TT_WRAP_INVALID; + UT_ASSERT(ClusterR4TxVerdictPageEncode(page, &input)); + memset(&output, 0xA5, sizeof(output)); + UT_ASSERT(!ClusterR4TxVerdictPageDecode(page, &locator, &output)); + UT_ASSERT(bytes_are_zero((const uint8 *)&output, sizeof(output))); + break; + case 90: + input = verdict_resolution(CLUSTER_TX_COMMITTED, CLUSTER_TX_PROOF_ORIGIN_DURABLE_TT_CLOG); + locator = input.locator_echo; + locator.tt_wrap = 8; + UT_ASSERT(ClusterR4TxVerdictPageEncode(page, &input)); + UT_ASSERT(!ClusterR4TxVerdictPageDecode(page, &locator, &output)); + break; + default: + value = UINT64_C(0x0102030405060708) ^ ((uint64)vector << 33) + ^ ((uint64)vector * UINT64_C(0x9e3779b97f4a7c15)); + ClusterR4WireWriteU64(bytes, value); + UT_ASSERT(ClusterR4WireReadU64(bytes) == value); + break; } } -#define DEFINE_WIRE_TEST(n) \ - UT_TEST(test_wire_vector_##n) { run_wire_vector(n); } +#define DEFINE_WIRE_TEST(n) \ + UT_TEST(test_wire_vector_##n) \ + { \ + run_wire_vector(n); \ + } DEFINE_WIRE_TEST(0) DEFINE_WIRE_TEST(1) @@ -710,8 +673,7 @@ UT_TEST(test_r4_and_legacy_reply_status_domains_are_disjoint) for (status = 21; status <= 26; status++) { UT_ASSERT(!GcsBlockReplyStatusIsLegacy((GcsBlockReplyStatus)status)); UT_ASSERT(GcsBlockReplyStatusIsR4((GcsBlockReplyStatus)status)); - UT_ASSERT_EQ(GcsBlockReplyStatusIsR4Refusal((GcsBlockReplyStatus)status), - status >= 25); + UT_ASSERT_EQ(GcsBlockReplyStatusIsR4Refusal((GcsBlockReplyStatus)status), status >= 25); } UT_ASSERT(!GcsBlockReplyStatusIsLegacy((GcsBlockReplyStatus)-1)); UT_ASSERT(!GcsBlockReplyStatusIsR4((GcsBlockReplyStatus)27)); @@ -719,14 +681,13 @@ UT_TEST(test_r4_and_legacy_reply_status_domains_are_disjoint) UT_TEST(test_r4_undo_data_status_selects_existing_authenticated_reply_shape) { - UT_ASSERT(GcsBlockReplyStatusCarriesUndoAuthTrailer( - GCS_BLOCK_REPLY_R4_UNDO_DATA_RESULT)); + UT_ASSERT(GcsBlockReplyStatusCarriesUndoAuthTrailer(GCS_BLOCK_REPLY_R4_UNDO_DATA_RESULT)); UT_ASSERT_EQ(sizeof(GcsBlockReplyHeader) + GCS_BLOCK_DATA_SIZE - + sizeof(ClusterGcsUndoAuthTrailer), - 8256); + + sizeof(ClusterGcsUndoAuthTrailer), + 8256); UT_ASSERT(!GcsBlockReplyStatusCarriesUndoAuthTrailer(GCS_BLOCK_REPLY_R4_CR_FULL)); - UT_ASSERT(!GcsBlockReplyStatusCarriesUndoAuthTrailer( - GCS_BLOCK_REPLY_R4_RETRYABLE_HOLDER_MOVED)); + UT_ASSERT( + !GcsBlockReplyStatusCarriesUndoAuthTrailer(GCS_BLOCK_REPLY_R4_RETRYABLE_HOLDER_MOVED)); UT_ASSERT(!GcsBlockReplyStatusCarriesUndoAuthTrailer(GCS_BLOCK_REPLY_R4_DENIED)); } diff --git a/src/test/cluster_unit/test_cluster_reconfig.c b/src/test/cluster_unit/test_cluster_reconfig.c index ad87f719eaa..6e4c81d5c18 100644 --- a/src/test/cluster_unit/test_cluster_reconfig.c +++ b/src/test/cluster_unit/test_cluster_reconfig.c @@ -75,19 +75,16 @@ UT_DEFINE_GLOBALS(); -static ClusterReplacementEpisode ut_admitted_replacement_episode( - int32 target_node_id); +static ClusterReplacementEpisode ut_admitted_replacement_episode(int32 target_node_id); static bool jb_test(const uint8 *bmp, int i); static void ut_join_setup(void); -static void ut_set_self_incarnation_sequence(uint64 first, uint64 second, - uint64 later); -static bool ut_join_qvotec_poll_write_pending(int32 *target_node_out, - void *write_slot512_out); +static void ut_set_self_incarnation_sequence(uint64 first, uint64 second, uint64 later); +static bool ut_join_qvotec_poll_write_pending(int32 *target_node_out, void *write_slot512_out); static void ut_join_qvotec_complete_write(bool acked); -extern bool cluster_reconfig_qvotec_lifecycle_transition( - ClusterQvotecMailbox *authority_mailbox, - pg_atomic_uint32 *qvotec_status, ClusterQvotecStatus next_status); +extern bool cluster_reconfig_qvotec_lifecycle_transition(ClusterQvotecMailbox *authority_mailbox, + pg_atomic_uint32 *qvotec_status, + ClusterQvotecStatus next_status); void cluster_qvotec_mailbox_restart_reset(ClusterQvotecMailbox *mailbox) @@ -97,10 +94,8 @@ cluster_qvotec_mailbox_restart_reset(ClusterQvotecMailbox *mailbox) memset(mailbox, 0, sizeof(*mailbox)); pg_atomic_init_u64(&mailbox->request_seq, 0); pg_atomic_init_u64(&mailbox->completion_seq, 0); - pg_atomic_init_u32(&mailbox->request_opcode, - CLUSTER_QVOTEC_MAILBOX_NONE); - pg_atomic_init_u32(&mailbox->completion_result, - CLUSTER_QVOTEC_MAILBOX_RESULT_NONE); + pg_atomic_init_u32(&mailbox->request_opcode, CLUSTER_QVOTEC_MAILBOX_NONE); + pg_atomic_init_u32(&mailbox->completion_result, CLUSTER_QVOTEC_MAILBOX_RESULT_NONE); } /* spec-5.22e D5-8 stub: cluster_membership_set_state notes self-admission @@ -151,8 +146,7 @@ static ClusterControlRootIdentity ut_recovery_root_identity; static bool ut_rejoin_root_complete; static bool ut_external_fence_active; static bool ut_authority_managed; -static ClusterAuthorityReadiness ut_authority_readiness - = CLUSTER_AUTHORITY_OFF; +static ClusterAuthorityReadiness ut_authority_readiness = CLUSTER_AUTHORITY_OFF; static uint64 ut_handoff_identity_incarnation; static uint64 ut_handoff_identity_predecessor_floor; static bool ut_serving_ready; @@ -176,21 +170,19 @@ static char ut_rejoin_op_storage; static char ut_rejoin_clear_storage; ClusterControlRootResult -cluster_control_root_lookup_owner_by_node_runtime( - int32 old_node_id pg_attribute_unused(), - ClusterControlRootIdentity *out_identity, - ClusterControlRootSnapshot *out_snapshot, - ClusterControlRootReadToken *out_token) +cluster_control_root_lookup_owner_by_node_runtime(int32 old_node_id pg_attribute_unused(), + ClusterControlRootIdentity *out_identity, + ClusterControlRootSnapshot *out_snapshot, + ClusterControlRootReadToken *out_token) { if (out_identity != NULL) *out_identity = ut_recovery_root_identity; - if (out_snapshot != NULL) - { + if (out_snapshot != NULL) { memset(out_snapshot, 0, sizeof(*out_snapshot)); out_snapshot->identity = ut_recovery_root_identity; out_snapshot->lifecycle = ut_rejoin_root_complete - ? CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_COMPLETE - : CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_REQUIRED; + ? CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_COMPLETE + : CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_REQUIRED; } if (out_token != NULL) memset(out_token, 0, sizeof(*out_token)); @@ -216,14 +208,12 @@ cluster_authority_readiness_get(void) } bool -cluster_authority_handoff_identity_current( - uint64 expected_self_incarnation, uint64 expected_predecessor_floor) +cluster_authority_handoff_identity_current(uint64 expected_self_incarnation, + uint64 expected_predecessor_floor) { - return ut_authority_managed - && ut_authority_readiness == CLUSTER_AUTHORITY_OFF - && expected_self_incarnation == ut_handoff_identity_incarnation - && expected_predecessor_floor - == ut_handoff_identity_predecessor_floor; + return ut_authority_managed && ut_authority_readiness == CLUSTER_AUTHORITY_OFF + && expected_self_incarnation == ut_handoff_identity_incarnation + && expected_predecessor_floor == ut_handoff_identity_predecessor_floor; } bool @@ -263,43 +253,39 @@ cluster_external_fence_rejoin_protected_set_digest(uint8 out[32]) } PgracExternalFenceRejoinStatus -cluster_external_fence_rejoin_start_async( - int timeout_ms, PgracExternalFenceRejoinOpV1 **out_op) +cluster_external_fence_rejoin_start_async(int timeout_ms, PgracExternalFenceRejoinOpV1 **out_op) { ut_rejoin_start_calls++; - if (ut_rejoin_start_calls > 1 || - timeout_ms != PGRAC_EXTERNAL_FENCE_ACQUIRE_TIMEOUT_DEFAULT_MS || - out_op == NULL || *out_op != NULL) + if (ut_rejoin_start_calls > 1 || timeout_ms != PGRAC_EXTERNAL_FENCE_ACQUIRE_TIMEOUT_DEFAULT_MS + || out_op == NULL || *out_op != NULL) return PGRAC_EXTERNAL_FENCE_REJOIN_UNAVAILABLE; - *out_op = (PgracExternalFenceRejoinOpV1 *) &ut_rejoin_op_storage; + *out_op = (PgracExternalFenceRejoinOpV1 *)&ut_rejoin_op_storage; ut_rejoin_poll_status = PGRAC_EXTERNAL_FENCE_REJOIN_OFFERED; return PGRAC_EXTERNAL_FENCE_REJOIN_PENDING; } PgracExternalFenceRejoinStatus -cluster_external_fence_rejoin_poll_nowait( - PgracExternalFenceRejoinOpV1 *op, PgracExternalFenceDenyReason *reason) +cluster_external_fence_rejoin_poll_nowait(PgracExternalFenceRejoinOpV1 *op, + PgracExternalFenceDenyReason *reason) { ut_rejoin_poll_calls++; if (reason != NULL) *reason = PGRAC_EXTERNAL_FENCE_DENY_NONE; - if (op != (PgracExternalFenceRejoinOpV1 *) &ut_rejoin_op_storage) + if (op != (PgracExternalFenceRejoinOpV1 *)&ut_rejoin_op_storage) return PGRAC_EXTERNAL_FENCE_REJOIN_UNAVAILABLE; return ut_rejoin_poll_status; } const PgracExternalFenceRejoinOfferV1 * -cluster_external_fence_rejoin_offer( - const PgracExternalFenceRejoinOpV1 *op) +cluster_external_fence_rejoin_offer(const PgracExternalFenceRejoinOpV1 *op) { - return op == (const PgracExternalFenceRejoinOpV1 *) &ut_rejoin_op_storage - ? &ut_rejoin_offer : NULL; + return op == (const PgracExternalFenceRejoinOpV1 *)&ut_rejoin_op_storage ? &ut_rejoin_offer + : NULL; } bool -cluster_grd_rejoin_clear_snapshot( - const ClusterReconfigRejoinFailureSnapshotV1 *failure, - ClusterGrdRejoinClearSnapshotV1 *out_clear) +cluster_grd_rejoin_clear_snapshot(const ClusterReconfigRejoinFailureSnapshotV1 *failure, + ClusterGrdRejoinClearSnapshotV1 *out_clear) { if (!ut_rejoin_grd_clear_ready || failure == NULL || out_clear == NULL) return false; @@ -313,43 +299,36 @@ cluster_grd_rejoin_clear_snapshot( PgracExternalFenceRejoinStatus cluster_external_fence_rejoin_authority_clear_build( - const PgracExternalFenceRejoinOpV1 *op, - const ClusterReconfigRejoinFailureSnapshotV1 *failure, + const PgracExternalFenceRejoinOpV1 *op, const ClusterReconfigRejoinFailureSnapshotV1 *failure, const ClusterGrdRejoinClearSnapshotV1 *grd_clear, - PgracExternalFenceRejoinAuthorityClearV1 **out_clear, - PgracExternalFenceDenyReason *reason) + PgracExternalFenceRejoinAuthorityClearV1 **out_clear, PgracExternalFenceDenyReason *reason) { ut_rejoin_clear_build_calls++; if (reason != NULL) *reason = PGRAC_EXTERNAL_FENCE_DENY_NONE; - if (op != (const PgracExternalFenceRejoinOpV1 *) &ut_rejoin_op_storage || - failure == NULL || grd_clear == NULL || out_clear == NULL || - *out_clear != NULL) + if (op != (const PgracExternalFenceRejoinOpV1 *)&ut_rejoin_op_storage || failure == NULL + || grd_clear == NULL || out_clear == NULL || *out_clear != NULL) return PGRAC_EXTERNAL_FENCE_REJOIN_UNAVAILABLE; ut_rejoin_failure_seen = *failure; - *out_clear = (PgracExternalFenceRejoinAuthorityClearV1 *) - &ut_rejoin_clear_storage; + *out_clear = (PgracExternalFenceRejoinAuthorityClearV1 *)&ut_rejoin_clear_storage; return PGRAC_EXTERNAL_FENCE_REJOIN_WAITING_ROOT; } PgracExternalFenceRejoinStatus -cluster_external_fence_rejoin_authorize_on_async( - PgracExternalFenceRejoinOpV1 *op, - PgracExternalFenceRejoinAuthorityClearV1 **clear, - const ClusterControlRootIdentity *identity, - const ClusterControlRootSnapshot *snapshot, - const ClusterControlRootReadToken *token, - const uint8 protected_set_digest[32], - PgracExternalFenceDenyReason *reason) +cluster_external_fence_rejoin_authorize_on_async(PgracExternalFenceRejoinOpV1 *op, + PgracExternalFenceRejoinAuthorityClearV1 **clear, + const ClusterControlRootIdentity *identity, + const ClusterControlRootSnapshot *snapshot, + const ClusterControlRootReadToken *token, + const uint8 protected_set_digest[32], + PgracExternalFenceDenyReason *reason) { ut_rejoin_authorize_calls++; if (reason != NULL) *reason = PGRAC_EXTERNAL_FENCE_DENY_NONE; - if (op != (PgracExternalFenceRejoinOpV1 *) &ut_rejoin_op_storage || - clear == NULL || - *clear != (PgracExternalFenceRejoinAuthorityClearV1 *) - &ut_rejoin_clear_storage || identity == NULL || snapshot == NULL || - token == NULL || protected_set_digest == NULL) + if (op != (PgracExternalFenceRejoinOpV1 *)&ut_rejoin_op_storage || clear == NULL + || *clear != (PgracExternalFenceRejoinAuthorityClearV1 *)&ut_rejoin_clear_storage + || identity == NULL || snapshot == NULL || token == NULL || protected_set_digest == NULL) return PGRAC_EXTERNAL_FENCE_REJOIN_UNAVAILABLE; *clear = NULL; ut_rejoin_poll_status = PGRAC_EXTERNAL_FENCE_REJOIN_WAITING_JOINER; @@ -358,15 +337,13 @@ cluster_external_fence_rejoin_authorize_on_async( PgracExternalFenceRejoinStatus cluster_external_fence_rejoin_refresh_on_async( - PgracExternalFenceRejoinOpV1 *op, - const ClusterReconfigRejoinPendingSnapshotV1 *pending, + PgracExternalFenceRejoinOpV1 *op, const ClusterReconfigRejoinPendingSnapshotV1 *pending, PgracExternalFenceDenyReason *reason) { ut_rejoin_refresh_calls++; if (reason != NULL) *reason = PGRAC_EXTERNAL_FENCE_DENY_NONE; - if (op != (PgracExternalFenceRejoinOpV1 *) &ut_rejoin_op_storage || - pending == NULL) + if (op != (PgracExternalFenceRejoinOpV1 *)&ut_rejoin_op_storage || pending == NULL) return PGRAC_EXTERNAL_FENCE_REJOIN_UNAVAILABLE; ut_rejoin_pending_seen = *pending; ut_rejoin_poll_status = PGRAC_EXTERNAL_FENCE_REJOIN_READY; @@ -374,16 +351,14 @@ cluster_external_fence_rejoin_refresh_on_async( } bool -cluster_external_fence_rejoin_revalidate_root( - PgracExternalFenceRejoinOpV1 *op, - ClusterControlRootSnapshot *out_snapshot, - PgracExternalFenceDenyReason *reason) +cluster_external_fence_rejoin_revalidate_root(PgracExternalFenceRejoinOpV1 *op, + ClusterControlRootSnapshot *out_snapshot, + PgracExternalFenceDenyReason *reason) { ut_rejoin_root_revalidate_calls++; if (reason != NULL) *reason = PGRAC_EXTERNAL_FENCE_DENY_NONE; - if (op != (PgracExternalFenceRejoinOpV1 *) &ut_rejoin_op_storage || - out_snapshot == NULL) + if (op != (PgracExternalFenceRejoinOpV1 *)&ut_rejoin_op_storage || out_snapshot == NULL) return false; memset(out_snapshot, 0, sizeof(*out_snapshot)); out_snapshot->lifecycle = CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_COMPLETE; @@ -391,11 +366,10 @@ cluster_external_fence_rejoin_revalidate_root( } bool -cluster_external_fence_rejoin_consume_nowait( - PgracExternalFenceRejoinOpV1 *op, - const ClusterReconfigRejoinPendingSnapshotV1 *pending, - const ClusterJoinCommitMarker *marker, - PgracExternalFenceDenyReason *reason) +cluster_external_fence_rejoin_consume_nowait(PgracExternalFenceRejoinOpV1 *op, + const ClusterReconfigRejoinPendingSnapshotV1 *pending, + const ClusterJoinCommitMarker *marker, + PgracExternalFenceDenyReason *reason) { ClusterJoinMarkerMailboxOperationV1 operation; int32 target = -1; @@ -404,10 +378,10 @@ cluster_external_fence_rejoin_consume_nowait( ut_rejoin_consume_calls++; if (reason != NULL) *reason = PGRAC_EXTERNAL_FENCE_DENY_NONE; - ut_rejoin_consume_saw_prior_marker_submit = - cluster_reconfig_join_qvotec_poll_pending(&operation, &target, slot); - if (op != (PgracExternalFenceRejoinOpV1 *) &ut_rejoin_op_storage || - pending == NULL || marker == NULL) + ut_rejoin_consume_saw_prior_marker_submit + = cluster_reconfig_join_qvotec_poll_pending(&operation, &target, slot); + if (op != (PgracExternalFenceRejoinOpV1 *)&ut_rejoin_op_storage || pending == NULL + || marker == NULL) return false; ut_rejoin_pending_seen = *pending; ut_rejoin_committed_seen = *marker; @@ -417,8 +391,7 @@ cluster_external_fence_rejoin_consume_nowait( void cluster_external_fence_rejoin_release(PgracExternalFenceRejoinOpV1 **op) { - if (op != NULL && *op != NULL) - { + if (op != NULL && *op != NULL) { ut_rejoin_release_calls++; *op = NULL; } @@ -470,18 +443,16 @@ cluster_ic_tier1_close_peer(int32 peer_id, const char *reason pg_attribute_unuse } bool -cluster_sf_peer_capability_family_sample( - int32 peer_id, uint32 required_capabilities, - uint32 optional_capabilities, bool *optional_supported_out, - uint32 *generation_out) +cluster_sf_peer_capability_family_sample(int32 peer_id, uint32 required_capabilities, + uint32 optional_capabilities, bool *optional_supported_out, + uint32 *generation_out) { if (optional_supported_out != NULL) *optional_supported_out = false; if (generation_out != NULL) *generation_out = 0; if (peer_id < 0 || peer_id >= CLUSTER_MAX_NODES - || required_capabilities - != PGRAC_IC_HELLO_CAP_CANDIDATE2_CORRECTED_A1_V1 + || required_capabilities != PGRAC_IC_HELLO_CAP_CANDIDATE2_CORRECTED_A1_V1 || optional_capabilities != 0 || !ut_candidate2_capable[peer_id]) return false; if (generation_out != NULL) @@ -561,14 +532,12 @@ LWLockAcquire(LWLock *lock pg_attribute_unused(), LWLockMode mode pg_attribute_u return true; } bool -LWLockConditionalAcquire(LWLock *lock pg_attribute_unused(), - LWLockMode mode pg_attribute_unused()) +LWLockConditionalAcquire(LWLock *lock pg_attribute_unused(), LWLockMode mode pg_attribute_unused()) { ut_lwlock_conditional_calls++; return ut_lwlock_conditional_result - && (ut_lwlock_conditional_fail_call == 0 - || ut_lwlock_conditional_calls - != ut_lwlock_conditional_fail_call); + && (ut_lwlock_conditional_fail_call == 0 + || ut_lwlock_conditional_calls != ut_lwlock_conditional_fail_call); } void LWLockRelease(LWLock *lock pg_attribute_unused()) @@ -677,14 +646,12 @@ static ClusterQvotecMailboxCompletion ut_authority_completion; ClusterQvotecMailboxSubmitStatus cluster_qvotec_authority_lmon_submit( ClusterQvotecMailboxOpcode opcode, - const uint8 request_value[CLUSTER_QVOTEC_AUTHORITY_VALUE_BYTES], - uint64 *request_seq_out) + const uint8 request_value[CLUSTER_QVOTEC_AUTHORITY_VALUE_BYTES], uint64 *request_seq_out) { static const uint8 zero_value[CLUSTER_QVOTEC_AUTHORITY_VALUE_BYTES] = { 0 }; - if (opcode != CLUSTER_QVOTEC_MAILBOX_RECOVER_HEAD - || request_value == NULL || request_seq_out == NULL - || memcmp(request_value, zero_value, sizeof(zero_value)) != 0) + if (opcode != CLUSTER_QVOTEC_MAILBOX_RECOVER_HEAD || request_value == NULL + || request_seq_out == NULL || memcmp(request_value, zero_value, sizeof(zero_value)) != 0) return CLUSTER_QVOTEC_MAILBOX_SUBMIT_INVALID; ut_authority_submit_calls++; if (ut_authority_submit_status != CLUSTER_QVOTEC_MAILBOX_SUBMIT_ACCEPTED) @@ -695,8 +662,8 @@ cluster_qvotec_authority_lmon_submit( } bool -cluster_qvotec_authority_lmon_poll_completion( - uint64 request_seq, ClusterQvotecMailboxCompletion *completion_out) +cluster_qvotec_authority_lmon_poll_completion(uint64 request_seq, + ClusterQvotecMailboxCompletion *completion_out) { if (!ut_authority_completion_ready || completion_out == NULL || ut_authority_completion.request_seq != request_seq) @@ -868,8 +835,8 @@ cluster_gcs_block_on_epoch_advance(uint64 new_epoch pg_attribute_unused()) {} void -cluster_gcs_block_on_epoch_advance_exact( - uint64 new_epoch pg_attribute_unused(), const uint8 *dead_bitmap pg_attribute_unused()) +cluster_gcs_block_on_epoch_advance_exact(uint64 new_epoch pg_attribute_unused(), + const uint8 *dead_bitmap pg_attribute_unused()) {} /* spec-2.39 D14 stub: cluster_reconfig_apply_epoch_bump_as_coordinator @@ -924,8 +891,7 @@ static bool ut_fence_async_marker_captured = false; static ClusterFenceMarker ut_fence_async_marker; bool -cluster_write_fence_submit_marker_async(ClusterMarkerAsync *a, - const ClusterFenceMarker *m, +cluster_write_fence_submit_marker_async(ClusterMarkerAsync *a, const ClusterFenceMarker *m, ClusterMarkerAsyncKind kind, int32 target_node, TimestampTz now pg_attribute_unused()) { @@ -1028,16 +994,13 @@ cluster_grd_inc_offpath_crash_rejoin_fenced(void) /* spec-6.15 D5b: stripe joiner gate. Most tests keep the legacy PROCEED * fixture; the AD-023 cold-boot ordering test drives the HOLD edge. */ #include "cluster/cluster_xid_stripe_boot.h" -static ClusterXidStripeJoinVerdict ut_xid_stripe_verdict - = CLUSTER_XID_STRIPE_JOIN_PROCEED; +static ClusterXidStripeJoinVerdict ut_xid_stripe_verdict = CLUSTER_XID_STRIPE_JOIN_PROCEED; static int ut_xid_stripe_join_gate_calls; static bool ut_xid_stripe_last_may_seed; -static ClusterXidStripeJoinProgress ut_xid_stripe_progress - = STRIPE_JOIN_PROCEED; +static ClusterXidStripeJoinProgress ut_xid_stripe_progress = STRIPE_JOIN_PROCEED; static int ut_xid_stripe_join_progress_calls; static bool ut_xid_stripe_progress_last_may_seed; -static ClusterXidStripeDiskState ut_xid_stripe_disk_state - = CLUSTER_XID_STRIPE_DISK_UNKNOWN; +static ClusterXidStripeDiskState ut_xid_stripe_disk_state = CLUSTER_XID_STRIPE_DISK_UNKNOWN; static ClusterWalSlotVerdict ut_wal_slot_verdict[CLUSTER_MAX_NODES]; static ClusterWalStateSlot ut_wal_slot[CLUSTER_MAX_NODES]; static bool ut_recovery_in_progress = false; @@ -1089,18 +1052,17 @@ void on_shmem_exit(pg_on_exit_callback function pg_attribute_unused(), Datum arg pg_attribute_unused()) {} void -before_shmem_exit(pg_on_exit_callback function pg_attribute_unused(), Datum arg pg_attribute_unused()) +before_shmem_exit(pg_on_exit_callback function pg_attribute_unused(), + Datum arg pg_attribute_unused()) {} #include "cluster/cluster_voting_disk_io.h" static bool ut_join_disk_readable[CLUSTER_MAX_VOTING_DISKS]; static uint8 ut_join_disk_images[CLUSTER_MAX_VOTING_DISKS][CLUSTER_VOTING_SLOT_BYTES]; ClusterVotingDiskIoState -cluster_voting_disk_read_join_slot(int fd, - uint32 node_id pg_attribute_unused(), - void *out_slot512) +cluster_voting_disk_read_join_slot(int fd, uint32 node_id pg_attribute_unused(), void *out_slot512) { - if (fd >= 0 && fd < CLUSTER_MAX_VOTING_DISKS - && ut_join_disk_readable[fd] && out_slot512 != NULL) { + if (fd >= 0 && fd < CLUSTER_MAX_VOTING_DISKS && ut_join_disk_readable[fd] + && out_slot512 != NULL) { memcpy(out_slot512, ut_join_disk_images[fd], CLUSTER_VOTING_SLOT_BYTES); return CLUSTER_VOTING_DISK_IO_OK; } @@ -1155,8 +1117,7 @@ ut_reset_mocks(void) memset(&ut_authority_completion, 0, sizeof(ut_authority_completion)); memset(ut_join_disk_readable, 0, sizeof(ut_join_disk_readable)); memset(ut_join_disk_images, 0, sizeof(ut_join_disk_images)); - memset(&ut_r4_prerequisite_snapshot, 0, - sizeof(ut_r4_prerequisite_snapshot)); + memset(&ut_r4_prerequisite_snapshot, 0, sizeof(ut_r4_prerequisite_snapshot)); ut_r4_prerequisite_snapshot.target_node_id = -1; ut_r4_snapshot_use_reconfig = false; ut_phase3_send_result = CLUSTER_IC_SEND_DONE; @@ -1370,9 +1331,7 @@ UT_TEST(test_reconfig_replacement_episode_is_embedded_and_zero_initialized) memset(&empty_episode, 0, sizeof(empty_episode)); UT_ASSERT_EQ(sizeof(ClusterReconfigState), 12640); - UT_ASSERT_EQ(memcmp(&state->replacement_episode, &empty_episode, - sizeof(empty_episode)), - 0); + UT_ASSERT_EQ(memcmp(&state->replacement_episode, &empty_episode, sizeof(empty_episode)), 0); } @@ -1620,11 +1579,9 @@ UT_TEST(test_reconfig_builds_exact_replacement_committed_event) episode.readiness_flags = 0; memset(&event, 0, sizeof(event)); UT_ASSERT(cluster_reconfig_build_replacement_committed_event( - &episode, CLUSTER_RECONFIG_OBSERVER_SURVIVOR, - (TimestampTz)UINT64_C(1234), &event)); + &episode, CLUSTER_RECONFIG_OBSERVER_SURVIVOR, (TimestampTz)UINT64_C(1234), &event)); UT_ASSERT_EQ((int)RECONFIG_KIND_REPLACEMENT_COMMITTED, 6); - UT_ASSERT_EQ((int)event.reconfig_kind, - (int)RECONFIG_KIND_REPLACEMENT_COMMITTED); + UT_ASSERT_EQ((int)event.reconfig_kind, (int)RECONFIG_KIND_REPLACEMENT_COMMITTED); UT_ASSERT(event.event_id != 0); UT_ASSERT_EQ(event.coordinator_node_id, episode.coordinator_node_id); UT_ASSERT_EQ(event.old_epoch, episode.baseline_epoch); @@ -1643,15 +1600,13 @@ UT_TEST(test_reconfig_builds_exact_replacement_committed_event) changed = episode; changed.request_nonce++; UT_ASSERT(cluster_reconfig_build_replacement_committed_event( - &changed, CLUSTER_RECONFIG_OBSERVER_SURVIVOR, - (TimestampTz)UINT64_C(1234), &changed_event)); + &changed, CLUSTER_RECONFIG_OBSERVER_SURVIVOR, (TimestampTz)UINT64_C(1234), &changed_event)); UT_ASSERT(changed_event.event_id != event.event_id); changed = episode; changed.expected_survivors[0] ^= UINT8_C(0x10); changed.acknowledgements[0] = changed.expected_survivors[0]; UT_ASSERT(cluster_reconfig_build_replacement_committed_event( - &changed, CLUSTER_RECONFIG_OBSERVER_SURVIVOR, - (TimestampTz)UINT64_C(1234), &changed_event)); + &changed, CLUSTER_RECONFIG_OBSERVER_SURVIVOR, (TimestampTz)UINT64_C(1234), &changed_event)); UT_ASSERT(changed_event.event_id != event.event_id); memset(&sentinel, 0xa5, sizeof(sentinel)); @@ -1659,19 +1614,16 @@ UT_TEST(test_reconfig_builds_exact_replacement_committed_event) changed = episode; changed.acknowledgements[0] &= (uint8)~UINT8_C(0x04); UT_ASSERT(!cluster_reconfig_build_replacement_committed_event( - &changed, CLUSTER_RECONFIG_OBSERVER_SURVIVOR, - (TimestampTz)UINT64_C(1234), &changed_event)); + &changed, CLUSTER_RECONFIG_OBSERVER_SURVIVOR, (TimestampTz)UINT64_C(1234), &changed_event)); UT_ASSERT_EQ(memcmp(&changed_event, &sentinel, sizeof(sentinel)), 0); changed = episode; changed.phase = CLUSTER_REPLACEMENT_EPISODE_PURGING; UT_ASSERT(!cluster_reconfig_build_replacement_committed_event( - &changed, CLUSTER_RECONFIG_OBSERVER_SURVIVOR, - (TimestampTz)UINT64_C(1234), &changed_event)); + &changed, CLUSTER_RECONFIG_OBSERVER_SURVIVOR, (TimestampTz)UINT64_C(1234), &changed_event)); UT_ASSERT_EQ(memcmp(&changed_event, &sentinel, sizeof(sentinel)), 0); UT_ASSERT(!cluster_reconfig_build_replacement_committed_event( - &episode, CLUSTER_RECONFIG_OBSERVER_NONE, - (TimestampTz)UINT64_C(1234), &changed_event)); + &episode, CLUSTER_RECONFIG_OBSERVER_NONE, (TimestampTz)UINT64_C(1234), &changed_event)); UT_ASSERT_EQ(memcmp(&changed_event, &sentinel, sizeof(sentinel)), 0); } @@ -1702,44 +1654,40 @@ UT_TEST(test_reconfig_replacement_grd_basis_uses_immutable_survivors) committed.old_admitted_incarnation = episode.old_admitted_incarnation; committed.fresh_incarnation = episode.fresh_incarnation; committed.baseline_epoch = episode.baseline_epoch; - committed.reserved_or_committed_epoch - = episode.reserved_or_committed_epoch; + committed.reserved_or_committed_epoch = episode.reserved_or_committed_epoch; committed.request_nonce = episode.request_nonce; memcpy(committed.expected_purge_survivors, episode.expected_survivors, sizeof(committed.expected_purge_survivors)); committed.grammar_fingerprint = episode.grammar_fingerprint; UT_ASSERT(cluster_reconfig_build_replacement_committed_event( - &episode, CLUSTER_RECONFIG_OBSERVER_SURVIVOR, - (TimestampTz)UINT64_C(1234), &event)); + &episode, CLUSTER_RECONFIG_OBSERVER_SURVIVOR, (TimestampTz)UINT64_C(1234), &event)); event.event_seq = UINT64_C(7); /* proves local publication, not a builder */ memset(survivors, 0xa5, sizeof(survivors)); memcpy(sentinel, survivors, sizeof(sentinel)); - UT_ASSERT(cluster_reconfig_replacement_grd_basis_authorized( - &event, &episode, &committed, 2, survivors, &epoch)); - UT_ASSERT_EQ(memcmp(survivors, episode.expected_survivors, - sizeof(survivors)), 0); + UT_ASSERT(cluster_reconfig_replacement_grd_basis_authorized(&event, &episode, &committed, 2, + survivors, &epoch)); + UT_ASSERT_EQ(memcmp(survivors, episode.expected_survivors, sizeof(survivors)), 0); UT_ASSERT_EQ(epoch, episode.reserved_or_committed_epoch); memcpy(survivors, sentinel, sizeof(survivors)); epoch = epoch_sentinel; event.reconfig_kind = RECONFIG_KIND_JOIN_COMMITTED; - UT_ASSERT(!cluster_reconfig_replacement_grd_basis_authorized( - &event, &episode, &committed, 2, survivors, &epoch)); + UT_ASSERT(!cluster_reconfig_replacement_grd_basis_authorized(&event, &episode, &committed, 2, + survivors, &epoch)); UT_ASSERT_EQ(memcmp(survivors, sentinel, sizeof(survivors)), 0); UT_ASSERT_EQ(epoch, epoch_sentinel); event.reconfig_kind = RECONFIG_KIND_REPLACEMENT_COMMITTED; committed.expected_purge_survivors[0] ^= UINT8_C(0x02); - UT_ASSERT(!cluster_reconfig_replacement_grd_basis_authorized( - &event, &episode, &committed, 2, survivors, &epoch)); + UT_ASSERT(!cluster_reconfig_replacement_grd_basis_authorized(&event, &episode, &committed, 2, + survivors, &epoch)); UT_ASSERT_EQ(memcmp(survivors, sentinel, sizeof(survivors)), 0); UT_ASSERT_EQ(epoch, epoch_sentinel); committed.expected_purge_survivors[0] ^= UINT8_C(0x02); UT_ASSERT(!cluster_reconfig_replacement_grd_basis_authorized( - &event, &episode, &committed, episode.target_node_id, - survivors, &epoch)); + &event, &episode, &committed, episode.target_node_id, survivors, &epoch)); UT_ASSERT_EQ(memcmp(survivors, sentinel, sizeof(survivors)), 0); UT_ASSERT_EQ(epoch, epoch_sentinel); @@ -1751,33 +1699,25 @@ UT_TEST(test_reconfig_replacement_grd_basis_uses_immutable_survivors) state->replacement_episode = episode; epoch_init_done = false; cluster_epoch_shmem_init(); - UT_ASSERT(cluster_epoch_observe_remote( - episode.reserved_or_committed_epoch)); - UT_ASSERT(cluster_replacement_marker_v3_encode( - &committed, committed_image)); - memcpy(state->join_pending_marker, committed_image, - sizeof(committed_image)); + UT_ASSERT(cluster_epoch_observe_remote(episode.reserved_or_committed_epoch)); + UT_ASSERT(cluster_replacement_marker_v3_encode(&committed, committed_image)); + memcpy(state->join_pending_marker, committed_image, sizeof(committed_image)); pg_atomic_write_u64(&state->join_marker_request_seq, UINT64_C(11)); pg_atomic_write_u64(&state->join_marker_completion_seq, UINT64_C(11)); - pg_atomic_write_u32(&state->join_marker_result, - CLUSTER_JOIN_MARKER_SUBMIT_ACK); + pg_atomic_write_u32(&state->join_marker_result, CLUSTER_JOIN_MARKER_SUBMIT_ACK); UT_ASSERT(cluster_reconfig_build_replacement_committed_event( - &episode, CLUSTER_RECONFIG_OBSERVER_SURVIVOR, - (TimestampTz)UINT64_C(4321), &event)); + &episode, CLUSTER_RECONFIG_OBSERVER_SURVIVOR, (TimestampTz)UINT64_C(4321), &event)); cluster_reconfig_publish_event(&event); memset(survivors, 0xa5, sizeof(survivors)); epoch = epoch_sentinel; - UT_ASSERT(cluster_reconfig_lmon_snapshot_replacement_grd_basis( - survivors, &epoch)); - UT_ASSERT_EQ(memcmp(survivors, episode.expected_survivors, - sizeof(survivors)), 0); + UT_ASSERT(cluster_reconfig_lmon_snapshot_replacement_grd_basis(survivors, &epoch)); + UT_ASSERT_EQ(memcmp(survivors, episode.expected_survivors, sizeof(survivors)), 0); UT_ASSERT_EQ(epoch, episode.reserved_or_committed_epoch); memcpy(survivors, sentinel, sizeof(survivors)); epoch = epoch_sentinel; state->join_pending_marker[24] ^= UINT8_C(0x01); - UT_ASSERT(!cluster_reconfig_lmon_snapshot_replacement_grd_basis( - survivors, &epoch)); + UT_ASSERT(!cluster_reconfig_lmon_snapshot_replacement_grd_basis(survivors, &epoch)); UT_ASSERT_EQ(memcmp(survivors, sentinel, sizeof(survivors)), 0); UT_ASSERT_EQ(epoch, epoch_sentinel); } @@ -2273,8 +2213,7 @@ UT_TEST(test_reconfig_node_remove_marker_carries_full_excluded_set) ut_fence_async_poll_pr = CLUSTER_MARKER_POLL_ACKED; ut_fence_async_poll_result = CLUSTER_FENCE_MARKER_SUBMIT_ACK; contest = true; - ret = cluster_reconfig_apply_node_removed_as_coordinator(1, baseline, 42, 7, - &contest); + ret = cluster_reconfig_apply_node_removed_as_coordinator(1, baseline, 42, 7, &contest); UT_ASSERT(ret > baseline); UT_ASSERT(!contest); cluster_reconfig_get_last_event(&applied); @@ -2533,12 +2472,12 @@ ut_join_setup(void) cluster_epoch_shmem_init(); cluster_qvotec_mailbox_restart_reset(&authority_mailbox); pg_atomic_init_u32(&qvotec_status, CLUSTER_QVOTEC_READY); - UT_ASSERT(cluster_reconfig_qvotec_lifecycle_transition( - &authority_mailbox, &qvotec_status, CLUSTER_QVOTEC_STARTING)); - UT_ASSERT(cluster_reconfig_qvotec_lifecycle_transition( - &authority_mailbox, &qvotec_status, CLUSTER_QVOTEC_READY)); - cluster_node_id = 0; /* self */ - ut_declared_set[0] = true; /* self declared */ + UT_ASSERT(cluster_reconfig_qvotec_lifecycle_transition(&authority_mailbox, &qvotec_status, + CLUSTER_QVOTEC_STARTING)); + UT_ASSERT(cluster_reconfig_qvotec_lifecycle_transition(&authority_mailbox, &qvotec_status, + CLUSTER_QVOTEC_READY)); + cluster_node_id = 0; /* self */ + ut_declared_set[0] = true; /* self declared */ } static ClusterReplacementEpisode @@ -2570,17 +2509,15 @@ ut_prepare_exact_r4_membership(void) ut_join_setup(); ut_in_quorum_value = true; - ut_set_self_incarnation_sequence(UINT64_C(100), UINT64_C(100), - UINT64_C(100)); + ut_set_self_incarnation_sequence(UINT64_C(100), UINT64_C(100), UINT64_C(100)); for (node = 0; node < 4; node++) { uint64 incarnation = UINT64_C(100) + (uint64)node; ut_declared_set[node] = true; cluster_membership_record_admitted(node, incarnation); cluster_membership_set_state(node, CLUSTER_MEMBER_MEMBER); - cluster_reconfig_record_observed_slot( - node, incarnation, UINT64_C(20) + (uint64)node, - CLUSTER_EPOCH_INITIAL); + cluster_reconfig_record_observed_slot(node, incarnation, UINT64_C(20) + (uint64)node, + CLUSTER_EPOCH_INITIAL); cluster_reconfig_record_observed_fresh_alive(node, true); } } @@ -2674,10 +2611,8 @@ UT_TEST(test_r4_membership_snapshot_captures_exact_current_four_node_view) UT_ASSERT_EQ(snapshot.admitted_members_hi, 0); UT_ASSERT_EQ(snapshot.local_self_boot_incarnation, UINT64_C(100)); for (node = 0; node < 4; node++) { - UT_ASSERT_EQ(snapshot.admitted_incarnation[node], - UINT64_C(100) + (uint64)node); - UT_ASSERT_EQ(snapshot.observed_generation[node], - UINT64_C(20) + (uint64)node); + UT_ASSERT_EQ(snapshot.admitted_incarnation[node], UINT64_C(100) + (uint64)node); + UT_ASSERT_EQ(snapshot.observed_generation[node], UINT64_C(20) + (uint64)node); } for (; node < CLUSTER_MAX_NODES; node++) { UT_ASSERT_EQ(snapshot.admitted_incarnation[node], 0); @@ -2696,8 +2631,7 @@ UT_TEST(test_r4_membership_snapshot_fails_closed_on_inexact_member_evidence) UT_ASSERT_EQ(snapshot.admitted_incarnation[3], 0); ut_prepare_exact_r4_membership(); - cluster_reconfig_record_observed_slot( - 3, UINT64_C(999), UINT64_C(23), CLUSTER_EPOCH_INITIAL); + cluster_reconfig_record_observed_slot(3, UINT64_C(999), UINT64_C(23), CLUSTER_EPOCH_INITIAL); UT_ASSERT(!cluster_reconfig_lmon_snapshot_r4_membership(&snapshot)); UT_ASSERT_EQ(snapshot.admitted_members_lo, 0); @@ -2707,8 +2641,7 @@ UT_TEST(test_r4_membership_snapshot_fails_closed_on_inexact_member_evidence) UT_ASSERT_EQ(snapshot.admitted_members_lo, 0); ut_prepare_exact_r4_membership(); - ut_set_self_incarnation_sequence(UINT64_C(101), UINT64_C(101), - UINT64_C(101)); + ut_set_self_incarnation_sequence(UINT64_C(101), UINT64_C(101), UINT64_C(101)); UT_ASSERT(!cluster_reconfig_lmon_snapshot_r4_membership(&snapshot)); UT_ASSERT_EQ(snapshot.admitted_members_lo, 0); } @@ -2736,14 +2669,12 @@ UT_TEST(test_replacement_purge_request_requires_exact_reserve_prepare_authority) episode = ut_admitted_replacement_episode(3); episode.phase = CLUSTER_REPLACEMENT_EPISODE_PREPARE_DURABLE; episode.readiness_flags = 0; - memset(episode.acknowledgements, 0, - sizeof(episode.acknowledgements)); + memset(episode.acknowledgements, 0, sizeof(episode.acknowledgements)); state->replacement_episode = episode; cluster_membership_set_state(1, CLUSTER_MEMBER_MEMBER); cluster_membership_set_state(2, CLUSTER_MEMBER_MEMBER); cluster_membership_record_admitted(1, UINT64_C(111)); - cluster_membership_record_admitted( - episode.target_node_id, episode.old_admitted_incarnation); + cluster_membership_record_admitted(episode.target_node_id, episode.old_admitted_incarnation); cluster_membership_record_admitted(2, UINT64_C(222)); epoch_init_done = false; cluster_epoch_shmem_init(); @@ -2758,8 +2689,7 @@ UT_TEST(test_replacement_purge_request_requires_exact_reserve_prepare_authority) prepare.old_admitted_incarnation = episode.old_admitted_incarnation; prepare.fresh_incarnation = episode.fresh_incarnation; prepare.baseline_epoch = episode.baseline_epoch; - prepare.reserved_or_committed_epoch - = episode.reserved_or_committed_epoch; + prepare.reserved_or_committed_epoch = episode.reserved_or_committed_epoch; prepare.request_nonce = episode.request_nonce; memcpy(prepare.expected_purge_survivors, episode.expected_survivors, sizeof(prepare.expected_purge_survivors)); @@ -2782,8 +2712,7 @@ UT_TEST(test_replacement_purge_request_requires_exact_reserve_prepare_authority) reserve.event_subject_bitmap[episode.target_node_id / 8] = (uint8)(1u << (episode.target_node_id % 8)); reserve.grammar_fingerprint = episode.grammar_fingerprint; - memset(reserve.predecessor_digest, 0x5a, - sizeof(reserve.predecessor_digest)); + memset(reserve.predecessor_digest, 0x5a, sizeof(reserve.predecessor_digest)); memset(&ballot, 0, sizeof(ballot)); ballot.counter = UINT64_C(7); @@ -2798,16 +2727,13 @@ UT_TEST(test_replacement_purge_request_requires_exact_reserve_prepare_authority) request.request_nonce = episode.request_nonce; request.identity0 = episode.old_admitted_incarnation; request.identity1 = episode.fresh_incarnation; - memcpy(request.body.bitmap, episode.expected_survivors, - sizeof(request.body.bitmap)); + memcpy(request.body.bitmap, episode.expected_survivors, sizeof(request.body.bitmap)); request.grammar_fingerprint = episode.grammar_fingerprint; before = state->replacement_episode; UT_ASSERT(cluster_reconfig_replacement_purge_request_authorized( - &request, episode.coordinator_node_id, cluster_node_id, - &reserve, &ballot, &prepare)); - UT_ASSERT_EQ(memcmp(&state->replacement_episode, &before, - sizeof(before)), 0); + &request, episode.coordinator_node_id, cluster_node_id, &reserve, &ballot, &prepare)); + UT_ASSERT_EQ(memcmp(&state->replacement_episode, &before, sizeof(before)), 0); UT_ASSERT(cluster_replacement_wire_encode(&request, request_bytes)); memset(&envelope, 0, sizeof(envelope)); @@ -2818,54 +2744,45 @@ UT_TEST(test_replacement_purge_request_requires_exact_reserve_prepare_authority) envelope.payload_length = CLUSTER_REPLACEMENT_WIRE_BYTES; memset(&observed, 0, sizeof(observed)); UT_ASSERT(cluster_reconfig_replacement_purge_request_ingress_authorized( - &envelope, request_bytes, sizeof(request_bytes), - episode.coordinator_node_id, cluster_node_id, - &reserve, &ballot, &prepare, &observed)); + &envelope, request_bytes, sizeof(request_bytes), episode.coordinator_node_id, + cluster_node_id, &reserve, &ballot, &prepare, &observed)); UT_ASSERT_EQ(memcmp(&observed, &request, sizeof(request)), 0); memset(&sentinel, 0xa5, sizeof(sentinel)); observed = sentinel; envelope.source_node_id = (uint32)cluster_node_id; UT_ASSERT(!cluster_reconfig_replacement_purge_request_ingress_authorized( - &envelope, request_bytes, sizeof(request_bytes), - episode.coordinator_node_id, cluster_node_id, - &reserve, &ballot, &prepare, &observed)); + &envelope, request_bytes, sizeof(request_bytes), episode.coordinator_node_id, + cluster_node_id, &reserve, &ballot, &prepare, &observed)); UT_ASSERT_EQ(memcmp(&observed, &sentinel, sizeof(sentinel)), 0); envelope.source_node_id = (uint32)episode.coordinator_node_id; envelope.epoch++; UT_ASSERT(!cluster_reconfig_replacement_purge_request_ingress_authorized( - &envelope, request_bytes, sizeof(request_bytes), - episode.coordinator_node_id, cluster_node_id, - &reserve, &ballot, &prepare, &observed)); + &envelope, request_bytes, sizeof(request_bytes), episode.coordinator_node_id, + cluster_node_id, &reserve, &ballot, &prepare, &observed)); UT_ASSERT_EQ(memcmp(&observed, &sentinel, sizeof(sentinel)), 0); envelope.epoch--; UT_ASSERT(!cluster_reconfig_replacement_purge_request_ingress_authorized( - &envelope, request_bytes, sizeof(request_bytes) - 1, - episode.coordinator_node_id, cluster_node_id, - &reserve, &ballot, &prepare, &observed)); + &envelope, request_bytes, sizeof(request_bytes) - 1, episode.coordinator_node_id, + cluster_node_id, &reserve, &ballot, &prepare, &observed)); UT_ASSERT_EQ(memcmp(&observed, &sentinel, sizeof(sentinel)), 0); ballot.proposer_node_id = cluster_node_id; UT_ASSERT(!cluster_reconfig_replacement_purge_request_authorized( - &request, episode.coordinator_node_id, cluster_node_id, - &reserve, &ballot, &prepare)); + &request, episode.coordinator_node_id, cluster_node_id, &reserve, &ballot, &prepare)); ballot.proposer_node_id = episode.coordinator_node_id; prepare.phase = CLUSTER_JCMK_REPLACEMENT_PHASE_COMMITTED_CLOSED; UT_ASSERT(!cluster_reconfig_replacement_purge_request_authorized( - &request, episode.coordinator_node_id, cluster_node_id, - &reserve, &ballot, &prepare)); + &request, episode.coordinator_node_id, cluster_node_id, &reserve, &ballot, &prepare)); prepare.phase = CLUSTER_JCMK_REPLACEMENT_PHASE_PREPARE; request.body.bitmap[0] ^= UINT8_C(0x02); UT_ASSERT(!cluster_reconfig_replacement_purge_request_authorized( - &request, episode.coordinator_node_id, cluster_node_id, - &reserve, &ballot, &prepare)); + &request, episode.coordinator_node_id, cluster_node_id, &reserve, &ballot, &prepare)); request.body.bitmap[0] ^= UINT8_C(0x02); ut_candidate2_capable[episode.target_node_id] = false; UT_ASSERT(!cluster_reconfig_replacement_purge_request_authorized( - &request, episode.coordinator_node_id, cluster_node_id, - &reserve, &ballot, &prepare)); - UT_ASSERT_EQ(memcmp(&state->replacement_episode, &before, - sizeof(before)), 0); + &request, episode.coordinator_node_id, cluster_node_id, &reserve, &ballot, &prepare)); + UT_ASSERT_EQ(memcmp(&state->replacement_episode, &before, sizeof(before)), 0); /* Phase 2 derives the ACK node only from the authenticated endpoint. The * wire bitmap is identity, never a self-asserted ACK selector. A duplicate @@ -2879,11 +2796,9 @@ UT_TEST(test_replacement_purge_request_requires_exact_reserve_prepare_authority) int32 ack_node = -1; UT_ASSERT(cluster_reconfig_replacement_purge_ack_authorized( - &request, 2, cluster_node_id, &reserve, &ballot, &prepare, - &ack_node)); + &request, 2, cluster_node_id, &reserve, &ballot, &prepare, &ack_node)); UT_ASSERT_EQ(ack_node, 2); - UT_ASSERT_EQ(memcmp(&state->replacement_episode, &before, - sizeof(before)), 0); + UT_ASSERT_EQ(memcmp(&state->replacement_episode, &before, sizeof(before)), 0); UT_ASSERT(cluster_replacement_wire_encode(&request, request_bytes)); memset(&envelope, 0, sizeof(envelope)); @@ -2893,50 +2808,42 @@ UT_TEST(test_replacement_purge_request_requires_exact_reserve_prepare_authority) envelope.epoch = episode.baseline_epoch; envelope.payload_length = CLUSTER_REPLACEMENT_WIRE_BYTES; ack_node = -1; - UT_ASSERT( - cluster_reconfig_replacement_purge_ack_ingress_authorized( - &envelope, request_bytes, sizeof(request_bytes), 2, - cluster_node_id, &reserve, &ballot, &prepare, &ack_node)); + UT_ASSERT(cluster_reconfig_replacement_purge_ack_ingress_authorized( + &envelope, request_bytes, sizeof(request_bytes), 2, cluster_node_id, &reserve, &ballot, + &prepare, &ack_node)); UT_ASSERT_EQ(ack_node, 2); - UT_ASSERT_EQ(memcmp(&state->replacement_episode, &before, - sizeof(before)), 0); + UT_ASSERT_EQ(memcmp(&state->replacement_episode, &before, sizeof(before)), 0); ack_node = -1; envelope.dest_node_id = UINT32_C(2); - UT_ASSERT( - !cluster_reconfig_replacement_purge_ack_ingress_authorized( - &envelope, request_bytes, sizeof(request_bytes), 2, - cluster_node_id, &reserve, &ballot, &prepare, &ack_node)); + UT_ASSERT(!cluster_reconfig_replacement_purge_ack_ingress_authorized( + &envelope, request_bytes, sizeof(request_bytes), 2, cluster_node_id, &reserve, &ballot, + &prepare, &ack_node)); UT_ASSERT_EQ(ack_node, -1); envelope.dest_node_id = (uint32)cluster_node_id; - UT_ASSERT( - !cluster_reconfig_replacement_purge_ack_ingress_authorized( - &envelope, request_bytes, sizeof(request_bytes) - 1, 2, - cluster_node_id, &reserve, &ballot, &prepare, &ack_node)); + UT_ASSERT(!cluster_reconfig_replacement_purge_ack_ingress_authorized( + &envelope, request_bytes, sizeof(request_bytes) - 1, 2, cluster_node_id, &reserve, + &ballot, &prepare, &ack_node)); UT_ASSERT_EQ(ack_node, -1); state->replacement_episode.acknowledgements[0] |= UINT8_C(0x04); before = state->replacement_episode; ack_node = -1; UT_ASSERT(cluster_reconfig_replacement_purge_ack_authorized( - &request, 2, cluster_node_id, &reserve, &ballot, &prepare, - &ack_node)); + &request, 2, cluster_node_id, &reserve, &ballot, &prepare, &ack_node)); UT_ASSERT_EQ(ack_node, 2); - UT_ASSERT_EQ(memcmp(&state->replacement_episode, &before, - sizeof(before)), 0); + UT_ASSERT_EQ(memcmp(&state->replacement_episode, &before, sizeof(before)), 0); ack_node = -1; ballot.proposer_node_id = 2; UT_ASSERT(!cluster_reconfig_replacement_purge_ack_authorized( - &request, 2, cluster_node_id, &reserve, &ballot, &prepare, - &ack_node)); + &request, 2, cluster_node_id, &reserve, &ballot, &prepare, &ack_node)); UT_ASSERT_EQ(ack_node, -1); ballot.proposer_node_id = episode.coordinator_node_id; UT_ASSERT(!cluster_reconfig_replacement_purge_ack_authorized( - &request, episode.target_node_id, cluster_node_id, - &reserve, &ballot, &prepare, &ack_node)); + &request, episode.target_node_id, cluster_node_id, &reserve, &ballot, &prepare, + &ack_node)); UT_ASSERT_EQ(ack_node, -1); - UT_ASSERT_EQ(memcmp(&state->replacement_episode, &before, - sizeof(before)), 0); + UT_ASSERT_EQ(memcmp(&state->replacement_episode, &before, sizeof(before)), 0); } } @@ -2999,8 +2906,7 @@ UT_TEST(test_initial_absent_peer_is_not_a_runtime_join_edge) UT_ASSERT_EQ(inc, UINT64_C(103)); UT_ASSERT_EQ(cluster_reconfig_compute_join_bitmap(jb), 0); UT_ASSERT(!jb_test(jb, 3)); - UT_ASSERT_EQ((int)cluster_membership_get_state(3), - (int)CLUSTER_MEMBER_ABSENT); + UT_ASSERT_EQ((int)cluster_membership_get_state(3), (int)CLUSTER_MEMBER_ABSENT); UT_ASSERT_EQ(cluster_membership_get_last_admitted_incarnation(3), 0); /* A real past-INITIAL cluster still owns ordinary never-seen admission. */ @@ -3122,10 +3028,8 @@ UT_TEST(test_shared_cf_fast_rejoin_evicts_prior_live_incarnation) cluster_reconfig_bootstrap_publish_in_quorum(true); cluster_reconfig_lmon_tick(); - UT_ASSERT_EQ((int)cluster_membership_get_state(1), - (int)CLUSTER_MEMBER_ABSENT); - UT_ASSERT_EQ(cluster_membership_get_last_admitted_incarnation(1), - UINT64_C(0)); + UT_ASSERT_EQ((int)cluster_membership_get_state(1), (int)CLUSTER_MEMBER_ABSENT); + UT_ASSERT_EQ(cluster_membership_get_last_admitted_incarnation(1), UINT64_C(0)); UT_ASSERT_EQ(state->fast_rejoin_incarnation[1], UINT64_C(0)); UT_ASSERT_EQ(cluster_reconfig_get_apply_counter(), UINT64_C(0)); @@ -3135,10 +3039,8 @@ UT_TEST(test_shared_cf_fast_rejoin_evicts_prior_live_incarnation) cluster_reconfig_record_observed_slot(1, UINT64_C(70), UINT64_C(2), 0); cluster_reconfig_record_observed_fresh_alive(1, true); cluster_reconfig_lmon_tick(); - UT_ASSERT_EQ((int)cluster_membership_get_state(1), - (int)CLUSTER_MEMBER_MEMBER); - UT_ASSERT_EQ(cluster_membership_get_last_admitted_incarnation(1), - UINT64_C(70)); + UT_ASSERT_EQ((int)cluster_membership_get_state(1), (int)CLUSTER_MEMBER_MEMBER); + UT_ASSERT_EQ(cluster_membership_get_last_admitted_incarnation(1), UINT64_C(70)); UT_ASSERT_EQ(state->fast_rejoin_incarnation[1], UINT64_C(0)); UT_ASSERT_EQ(cluster_reconfig_get_apply_counter(), UINT64_C(0)); @@ -3146,10 +3048,8 @@ UT_TEST(test_shared_cf_fast_rejoin_evicts_prior_live_incarnation) * already-formed peer's fresh slot establishes fast_rejoin_incarnation * (a zero floor is bootstrap, never rollover evidence). */ cluster_reconfig_lmon_tick(); - UT_ASSERT_EQ(state->fast_rejoin_incarnation[1], - UINT64_C(70)); - UT_ASSERT_EQ(cluster_membership_get_last_admitted_incarnation(1), - UINT64_C(70)); + UT_ASSERT_EQ(state->fast_rejoin_incarnation[1], UINT64_C(70)); + UT_ASSERT_EQ(cluster_membership_get_last_admitted_incarnation(1), UINT64_C(70)); UT_ASSERT_EQ(cluster_reconfig_get_apply_counter(), UINT64_C(0)); /* A later fresh slot for the same live node is an incarnation rollover, @@ -3158,8 +3058,7 @@ UT_TEST(test_shared_cf_fast_rejoin_evicts_prior_live_incarnation) cluster_reconfig_record_observed_slot(1, UINT64_C(77), UINT64_C(3), 0); cluster_reconfig_lmon_tick(); cluster_reconfig_get_last_event(&event); - UT_ASSERT_EQ((int)cluster_membership_get_state(1), - (int)CLUSTER_MEMBER_DEAD); + UT_ASSERT_EQ((int)cluster_membership_get_state(1), (int)CLUSTER_MEMBER_DEAD); UT_ASSERT_EQ((int)event.reconfig_kind, (int)RECONFIG_KIND_FAIL_STOP); UT_ASSERT((event.dead_bitmap[0] & UINT8_C(0x02)) != 0); UT_ASSERT_EQ(event.new_epoch, UINT64_C(1)); @@ -3246,16 +3145,14 @@ UT_TEST(test_fast_rejoin_control_episode_carries_only_bound_join_to_terminal) UT_ASSERT_EQ(target, 1); memcpy(&marker, slot, sizeof(marker)); UT_ASSERT_EQ((int)marker.phase, (int)CLUSTER_JCMK_PHASE_COMMITTED); - UT_ASSERT_EQ((int)cluster_membership_get_state(2), - (int)CLUSTER_MEMBER_DEAD); + UT_ASSERT_EQ((int)cluster_membership_get_state(2), (int)CLUSTER_MEMBER_DEAD); /* Complete the bound terminal so no process-local stage leaks to later tests. */ ut_join_qvotec_complete_write(true); cluster_reconfig_lmon_tick(); cluster_reconfig_get_last_event(&event); UT_ASSERT_EQ((int)event.reconfig_kind, (int)RECONFIG_KIND_JOIN_COMMITTED); - UT_ASSERT_EQ((int)cluster_membership_get_state(1), - (int)CLUSTER_MEMBER_MEMBER); + UT_ASSERT_EQ((int)cluster_membership_get_state(1), (int)CLUSTER_MEMBER_MEMBER); UT_ASSERT(!jb_test(state->fast_rejoin_bitmap, 1)); ut_authority_managed = false; @@ -3293,8 +3190,7 @@ UT_TEST(test_fast_rejoin_control_episode_lms_generation_loss_fails_closed) memcpy(&marker, slot, sizeof(marker)); UT_ASSERT_EQ((int)marker.phase, (int)CLUSTER_JCMK_PHASE_COMMITTED); UT_ASSERT_EQ(marker.admitted_incarnation, UINT64_C(77)); - UT_ASSERT_EQ((int)cluster_membership_get_state(1), - (int)CLUSTER_MEMBER_JOINING); + UT_ASSERT_EQ((int)cluster_membership_get_state(1), (int)CLUSTER_MEMBER_JOINING); /* Complete the already-authorized terminal so no stage leaks to later * tests: the drain publishes JOIN_COMMITTED after the majority ACK. */ @@ -3302,8 +3198,7 @@ UT_TEST(test_fast_rejoin_control_episode_lms_generation_loss_fails_closed) cluster_reconfig_lmon_tick(); cluster_reconfig_get_last_event(&event); UT_ASSERT_EQ((int)event.reconfig_kind, (int)RECONFIG_KIND_JOIN_COMMITTED); - UT_ASSERT_EQ((int)cluster_membership_get_state(1), - (int)CLUSTER_MEMBER_MEMBER); + UT_ASSERT_EQ((int)cluster_membership_get_state(1), (int)CLUSTER_MEMBER_MEMBER); /* Fail-closed half: restoring the old generation must NOT resurrect the * capability — an unrelated newly eligible peer stays out of the episode @@ -3318,8 +3213,7 @@ UT_TEST(test_fast_rejoin_control_episode_lms_generation_loss_fails_closed) cluster_reconfig_get_last_event(&event); UT_ASSERT_EQ((int)event.reconfig_kind, (int)RECONFIG_KIND_JOIN_COMMITTED); UT_ASSERT(!jb_test(event.join_bitmap, 2)); - UT_ASSERT_EQ((int)cluster_membership_get_state(2), - (int)CLUSTER_MEMBER_DEAD); + UT_ASSERT_EQ((int)cluster_membership_get_state(2), (int)CLUSTER_MEMBER_DEAD); ut_authority_managed = false; ut_serving_ready = false; @@ -3346,8 +3240,7 @@ UT_TEST(test_legacy_online_join_off_does_not_evict_live_member) apply_before = cluster_reconfig_get_apply_counter(); cluster_reconfig_lmon_tick(); - UT_ASSERT_EQ((int)cluster_membership_get_state(1), - (int)CLUSTER_MEMBER_MEMBER); + UT_ASSERT_EQ((int)cluster_membership_get_state(1), (int)CLUSTER_MEMBER_MEMBER); UT_ASSERT_EQ(cluster_reconfig_get_apply_counter(), apply_before); } @@ -3467,27 +3360,22 @@ UT_TEST(test_cold_bootstrap_records_exact_floor_before_opening_gate) UT_ASSERT_EQ(state->self_join_admitted, 0); UT_ASSERT_EQ((int)cluster_membership_get_state(cluster_node_id), (int)CLUSTER_MEMBER_JOINING); - UT_ASSERT_EQ( - cluster_membership_get_last_admitted_incarnation(cluster_node_id), - UINT64_C(0)); + UT_ASSERT_EQ(cluster_membership_get_last_admitted_incarnation(cluster_node_id), + UINT64_C(0)); - ut_set_self_incarnation_sequence(UINT64_C(61), UINT64_C(61), - UINT64_C(61)); + ut_set_self_incarnation_sequence(UINT64_C(61), UINT64_C(61), UINT64_C(61)); cluster_reconfig_lmon_tick(); - UT_ASSERT_EQ( - cluster_membership_get_last_admitted_incarnation(cluster_node_id), - UINT64_C(61)); + UT_ASSERT_EQ(cluster_membership_get_last_admitted_incarnation(cluster_node_id), + UINT64_C(61)); UT_ASSERT_EQ((int)cluster_membership_get_state(cluster_node_id), (int)CLUSTER_MEMBER_MEMBER); UT_ASSERT_EQ(state->self_join_admitted, 1); UT_ASSERT(ut_self_member_callback_seen); - UT_ASSERT_EQ((int)ut_self_member_callback_gate, - (int)CLUSTER_JOIN_GATE_BLOCK_53R60); + UT_ASSERT_EQ((int)ut_self_member_callback_gate, (int)CLUSTER_JOIN_GATE_BLOCK_53R60); cluster_reconfig_lmon_tick(); - UT_ASSERT_EQ( - cluster_membership_get_last_admitted_incarnation(cluster_node_id), - UINT64_C(61)); + UT_ASSERT_EQ(cluster_membership_get_last_admitted_incarnation(cluster_node_id), + UINT64_C(61)); UT_ASSERT_EQ(state->self_join_admitted, 1); fflush(stdout); _exit(ut_current_failed == 0 ? 0 : 1); @@ -3519,17 +3407,15 @@ UT_TEST(test_initial_bootstrap_stripe_gate_publishes_control_member_only) cluster_online_join = true; ut_join_setup(); ut_in_quorum_value = true; - ut_set_self_incarnation_sequence(UINT64_C(61), UINT64_C(61), - UINT64_C(61)); + ut_set_self_incarnation_sequence(UINT64_C(61), UINT64_C(61), UINT64_C(61)); state = (ClusterReconfigState *)reconfig_shmem_storage; ut_xid_stripe_verdict = CLUSTER_XID_STRIPE_JOIN_HOLD; cluster_reconfig_lmon_tick(); UT_ASSERT_EQ((int)cluster_membership_get_state(cluster_node_id), (int)CLUSTER_MEMBER_MEMBER); - UT_ASSERT_EQ( - cluster_membership_get_last_admitted_incarnation(cluster_node_id), - UINT64_C(61)); + UT_ASSERT_EQ(cluster_membership_get_last_admitted_incarnation(cluster_node_id), + UINT64_C(61)); UT_ASSERT_EQ(state->self_join_admitted, 0); /* HOLD remains idempotent and cannot latch the one-shot decision. */ @@ -3542,9 +3428,8 @@ UT_TEST(test_initial_bootstrap_stripe_gate_publishes_control_member_only) cluster_reconfig_lmon_tick(); UT_ASSERT_EQ((int)cluster_membership_get_state(cluster_node_id), (int)CLUSTER_MEMBER_MEMBER); - UT_ASSERT_EQ( - cluster_membership_get_last_admitted_incarnation(cluster_node_id), - UINT64_C(61)); + UT_ASSERT_EQ(cluster_membership_get_last_admitted_incarnation(cluster_node_id), + UINT64_C(61)); UT_ASSERT_EQ(state->self_join_admitted, 1); fflush(stdout); _exit(ut_current_failed == 0 ? 0 : 1); @@ -3578,16 +3463,14 @@ UT_TEST(test_late_initial_node_becomes_online_joiner) ut_join_setup(); cluster_node_id = 1; ut_in_quorum_value = true; - ut_set_self_incarnation_sequence(UINT64_C(61), UINT64_C(61), - UINT64_C(61)); + ut_set_self_incarnation_sequence(UINT64_C(61), UINT64_C(61), UINT64_C(61)); state = (ClusterReconfigState *)reconfig_shmem_storage; for (i = 0; i < 4; i++) { ut_declared_set[i] = true; if (i == cluster_node_id) continue; - cluster_reconfig_record_observed_slot( - i, UINT64_C(100) + (uint64)i, UINT64_C(1), - CLUSTER_EPOCH_INITIAL); + cluster_reconfig_record_observed_slot(i, UINT64_C(100) + (uint64)i, UINT64_C(1), + CLUSTER_EPOCH_INITIAL); cluster_reconfig_record_observed_fresh_alive(i, true); } @@ -3602,8 +3485,7 @@ UT_TEST(test_late_initial_node_becomes_online_joiner) * advanced their formation. Their fresh QVOTEC-authenticated slot is * still sufficient to close this node's gate and classify it as an * ordinary JCMK joiner; it is never authority to admit the node. */ - cluster_reconfig_record_observed_slot( - 0, UINT64_C(100), UINT64_C(2), UINT64_C(7)); + cluster_reconfig_record_observed_slot(0, UINT64_C(100), UINT64_C(2), UINT64_C(7)); cluster_reconfig_record_observed_fresh_alive(0, true); ut_in_quorum_value = false; cluster_reconfig_lmon_tick(); @@ -3648,8 +3530,7 @@ UT_TEST(test_late_joiner_does_not_adopt_stale_peer_epoch) ut_declared_set[1] = true; ut_in_quorum_value = false; state = (ClusterReconfigState *)reconfig_shmem_storage; - cluster_reconfig_record_observed_slot( - 0, UINT64_C(100), UINT64_C(2), UINT64_C(7)); + cluster_reconfig_record_observed_slot(0, UINT64_C(100), UINT64_C(2), UINT64_C(7)); cluster_reconfig_record_observed_fresh_alive(0, false); cluster_reconfig_lmon_tick(); @@ -3694,8 +3575,7 @@ UT_TEST(test_late_joiner_epoch_adoption_waits_for_exact_publish_window) state = (ClusterReconfigState *)reconfig_shmem_storage; cluster_reconfig_bootstrap_publish_begin(); - cluster_reconfig_record_observed_slot( - 0, UINT64_C(101), UINT64_C(2), UINT64_C(7)); + cluster_reconfig_record_observed_slot(0, UINT64_C(101), UINT64_C(2), UINT64_C(7)); cluster_reconfig_record_observed_fresh_alive(0, true); cluster_reconfig_lmon_tick(); UT_ASSERT_EQ(cluster_epoch_get_current(), CLUSTER_EPOCH_INITIAL); @@ -3740,11 +3620,9 @@ UT_TEST(test_late_joiner_deadline_starts_only_after_stripe_claim_owned) cluster_node_id = 1; ut_declared_set[0] = true; ut_declared_set[1] = true; - ut_set_self_incarnation_sequence(UINT64_C(71), UINT64_C(71), - UINT64_C(71)); + ut_set_self_incarnation_sequence(UINT64_C(71), UINT64_C(71), UINT64_C(71)); state = (ClusterReconfigState *)reconfig_shmem_storage; - cluster_reconfig_record_observed_slot( - 0, UINT64_C(100), UINT64_C(2), UINT64_C(7)); + cluster_reconfig_record_observed_slot(0, UINT64_C(100), UINT64_C(2), UINT64_C(7)); cluster_reconfig_record_observed_fresh_alive(0, true); /* Classification is allowed without local quorum, but ownership and @@ -3806,11 +3684,9 @@ UT_TEST(test_clean_leave_suppresses_late_joiner_classification_and_progress) ut_declared_set[0] = true; ut_declared_set[1] = true; ut_in_quorum_value = true; - ut_set_self_incarnation_sequence(UINT64_C(73), UINT64_C(73), - UINT64_C(73)); + ut_set_self_incarnation_sequence(UINT64_C(73), UINT64_C(73), UINT64_C(73)); state = (ClusterReconfigState *)reconfig_shmem_storage; - cluster_reconfig_record_observed_slot( - 0, UINT64_C(100), UINT64_C(2), UINT64_C(7)); + cluster_reconfig_record_observed_slot(0, UINT64_C(100), UINT64_C(2), UINT64_C(7)); cluster_reconfig_record_observed_fresh_alive(0, true); ut_xid_stripe_progress = STRIPE_JOIN_CLAIM_OWNED; @@ -3864,15 +3740,13 @@ UT_TEST(test_epoch0_late_founder_classifies_only_after_recovery) ut_declared_set[0] = true; ut_declared_set[3] = true; ut_in_quorum_value = true; - ut_set_self_incarnation_sequence(UINT64_C(83), UINT64_C(83), - UINT64_C(83)); + ut_set_self_incarnation_sequence(UINT64_C(83), UINT64_C(83), UINT64_C(83)); state = (ClusterReconfigState *)reconfig_shmem_storage; - cluster_reconfig_record_observed_slot( - 0, UINT64_C(80), UINT64_C(7), CLUSTER_EPOCH_INITIAL); + cluster_reconfig_record_observed_slot(0, UINT64_C(80), UINT64_C(7), CLUSTER_EPOCH_INITIAL); cluster_reconfig_record_observed_fresh_alive(0, true); cluster_membership_record_admitted(0, UINT64_C(80)); cluster_membership_set_state(0, CLUSTER_MEMBER_MEMBER); - ut_xid_stripe_disk_state = CLUSTER_XID_STRIPE_DISK_PUBLISHED; + ut_xid_stripe_disk_state = CLUSTER_XID_STRIPE_DISK_PUBLISHED; ut_wal_slot_verdict[0] = CLUSTER_WAL_SLOT_OK; ut_wal_slot[0].thread_id = 1; ut_wal_slot[0].node_id = 0; @@ -3935,11 +3809,9 @@ UT_TEST(test_epoch0_current_authority_is_not_reclassified_as_late_founder) ut_declared_set[0] = true; ut_declared_set[3] = true; ut_in_quorum_value = true; - ut_set_self_incarnation_sequence(UINT64_C(83), UINT64_C(83), - UINT64_C(83)); + ut_set_self_incarnation_sequence(UINT64_C(83), UINT64_C(83), UINT64_C(83)); state = (ClusterReconfigState *)reconfig_shmem_storage; - cluster_reconfig_record_observed_slot( - 0, UINT64_C(80), UINT64_C(7), CLUSTER_EPOCH_INITIAL); + cluster_reconfig_record_observed_slot(0, UINT64_C(80), UINT64_C(7), CLUSTER_EPOCH_INITIAL); cluster_reconfig_record_observed_fresh_alive(0, true); cluster_membership_record_admitted(0, UINT64_C(80)); cluster_membership_set_state(0, CLUSTER_MEMBER_MEMBER); @@ -3976,11 +3848,9 @@ ut_prepare_epoch0_managed_handoff(void) ut_declared_set[0] = true; ut_declared_set[3] = true; ut_in_quorum_value = true; - ut_set_self_incarnation_sequence(UINT64_C(83), UINT64_C(83), - UINT64_C(83)); + ut_set_self_incarnation_sequence(UINT64_C(83), UINT64_C(83), UINT64_C(83)); state = (ClusterReconfigState *)reconfig_shmem_storage; - cluster_reconfig_record_observed_slot( - 0, UINT64_C(80), UINT64_C(7), CLUSTER_EPOCH_INITIAL); + cluster_reconfig_record_observed_slot(0, UINT64_C(80), UINT64_C(7), CLUSTER_EPOCH_INITIAL); cluster_reconfig_record_observed_fresh_alive(0, true); cluster_membership_record_admitted(0, UINT64_C(80)); cluster_membership_set_state(0, CLUSTER_MEMBER_MEMBER); @@ -4022,37 +3892,29 @@ UT_TEST(test_pre_publish_join_handoff_is_exact_idempotent_and_nonblocking) ut_lwlock_blocking_calls = 0; /* Two exact peer captures precede the handoff's EXCLUSIVE claim. */ ut_lwlock_conditional_fail_call = 3; - UT_ASSERT(!cluster_reconfig_stage_pre_publish_join_handoff( - UINT64_C(83), UINT64_C(82))); + UT_ASSERT(!cluster_reconfig_stage_pre_publish_join_handoff(UINT64_C(83), UINT64_C(82))); UT_ASSERT_EQ(ut_lwlock_conditional_calls, 3); UT_ASSERT_EQ(ut_lwlock_blocking_calls, 0); - UT_ASSERT_EQ((int)cluster_membership_get_state(cluster_node_id), - (int)CLUSTER_MEMBER_MEMBER); + UT_ASSERT_EQ((int)cluster_membership_get_state(cluster_node_id), (int)CLUSTER_MEMBER_MEMBER); - ut_set_self_incarnation_sequence(UINT64_C(83), UINT64_C(83), - UINT64_C(83)); + ut_set_self_incarnation_sequence(UINT64_C(83), UINT64_C(83), UINT64_C(83)); ut_lwlock_conditional_fail_call = 0; ut_lwlock_conditional_calls = 0; ut_lwlock_blocking_calls = 0; - UT_ASSERT(cluster_reconfig_stage_pre_publish_join_handoff( - UINT64_C(83), UINT64_C(82))); + UT_ASSERT(cluster_reconfig_stage_pre_publish_join_handoff(UINT64_C(83), UINT64_C(82))); UT_ASSERT_EQ(ut_lwlock_blocking_calls, 0); - UT_ASSERT_EQ((int)cluster_membership_get_state(cluster_node_id), - (int)CLUSTER_MEMBER_JOINING); + UT_ASSERT_EQ((int)cluster_membership_get_state(cluster_node_id), (int)CLUSTER_MEMBER_JOINING); UT_ASSERT(cluster_reconfig_pre_publish_join_handoff_current()); admitted_before = state->self_join_admitted; failed_before = state->self_join_failed; deadline_before = state->self_join_deadline_us; - ut_set_self_incarnation_sequence(UINT64_C(83), UINT64_C(83), - UINT64_C(83)); - UT_ASSERT(cluster_reconfig_stage_pre_publish_join_handoff( - UINT64_C(83), UINT64_C(82))); + ut_set_self_incarnation_sequence(UINT64_C(83), UINT64_C(83), UINT64_C(83)); + UT_ASSERT(cluster_reconfig_stage_pre_publish_join_handoff(UINT64_C(83), UINT64_C(82))); UT_ASSERT_EQ(state->self_join_admitted, admitted_before); UT_ASSERT_EQ(state->self_join_failed, failed_before); UT_ASSERT_EQ(state->self_join_deadline_us, deadline_before); - UT_ASSERT_EQ(cluster_membership_get_last_admitted_incarnation( - cluster_node_id), UINT64_C(82)); + UT_ASSERT_EQ(cluster_membership_get_last_admitted_incarnation(cluster_node_id), UINT64_C(82)); } /* Every conjunct is fail-closed: no generic managed+OFF+JOINING state may be @@ -4064,46 +3926,35 @@ UT_TEST(test_pre_publish_join_handoff_rejects_nonexact_state) state = ut_prepare_epoch0_managed_handoff(); ut_authority_readiness = CLUSTER_AUTHORITY_RECOVERY_READY; - UT_ASSERT(!cluster_reconfig_stage_pre_publish_join_handoff( - UINT64_C(83), UINT64_C(82))); - UT_ASSERT_EQ((int)cluster_membership_get_state(cluster_node_id), - (int)CLUSTER_MEMBER_MEMBER); + UT_ASSERT(!cluster_reconfig_stage_pre_publish_join_handoff(UINT64_C(83), UINT64_C(82))); + UT_ASSERT_EQ((int)cluster_membership_get_state(cluster_node_id), (int)CLUSTER_MEMBER_MEMBER); state = ut_prepare_epoch0_managed_handoff(); - UT_ASSERT(!cluster_reconfig_stage_pre_publish_join_handoff( - UINT64_C(84), UINT64_C(82))); + UT_ASSERT(!cluster_reconfig_stage_pre_publish_join_handoff(UINT64_C(84), UINT64_C(82))); state = ut_prepare_epoch0_managed_handoff(); - UT_ASSERT(!cluster_reconfig_stage_pre_publish_join_handoff( - UINT64_C(83), UINT64_C(81))); + UT_ASSERT(!cluster_reconfig_stage_pre_publish_join_handoff(UINT64_C(83), UINT64_C(81))); state = ut_prepare_epoch0_managed_handoff(); cluster_membership_record_admitted(cluster_node_id, UINT64_C(83)); - UT_ASSERT(!cluster_reconfig_stage_pre_publish_join_handoff( - UINT64_C(83), UINT64_C(83))); - UT_ASSERT_EQ((int)cluster_membership_get_state(cluster_node_id), - (int)CLUSTER_MEMBER_MEMBER); + UT_ASSERT(!cluster_reconfig_stage_pre_publish_join_handoff(UINT64_C(83), UINT64_C(83))); + UT_ASSERT_EQ((int)cluster_membership_get_state(cluster_node_id), (int)CLUSTER_MEMBER_MEMBER); state = ut_prepare_epoch0_managed_handoff(); cluster_membership_record_admitted(cluster_node_id, UINT64_C(84)); - UT_ASSERT(!cluster_reconfig_stage_pre_publish_join_handoff( - UINT64_C(83), UINT64_C(84))); + UT_ASSERT(!cluster_reconfig_stage_pre_publish_join_handoff(UINT64_C(83), UINT64_C(84))); state = ut_prepare_epoch0_managed_handoff(); state->replacement_episode = ut_admitted_replacement_episode(cluster_node_id); - UT_ASSERT(!cluster_reconfig_stage_pre_publish_join_handoff( - UINT64_C(83), UINT64_C(82))); + UT_ASSERT(!cluster_reconfig_stage_pre_publish_join_handoff(UINT64_C(83), UINT64_C(82))); state = ut_prepare_epoch0_managed_handoff(); ut_clean_leave_in_progress = true; - UT_ASSERT(!cluster_reconfig_stage_pre_publish_join_handoff( - UINT64_C(83), UINT64_C(82))); + UT_ASSERT(!cluster_reconfig_stage_pre_publish_join_handoff(UINT64_C(83), UINT64_C(82))); state = ut_prepare_epoch0_managed_handoff(); - state->removed_bitmap[cluster_node_id / 8] - |= (uint8)(1u << (cluster_node_id % 8)); - UT_ASSERT(!cluster_reconfig_stage_pre_publish_join_handoff( - UINT64_C(83), UINT64_C(82))); + state->removed_bitmap[cluster_node_id / 8] |= (uint8)(1u << (cluster_node_id % 8)); + UT_ASSERT(!cluster_reconfig_stage_pre_publish_join_handoff(UINT64_C(83), UINT64_C(82))); state = ut_prepare_epoch0_managed_handoff(); state->self_join_failed = 1; @@ -4116,12 +3967,9 @@ UT_TEST(test_pre_publish_join_handoff_rejects_nonexact_state) UT_ASSERT(!cluster_reconfig_pre_publish_join_handoff_current()); state = ut_prepare_epoch0_managed_handoff(); - ut_set_self_incarnation_sequence(UINT64_C(83), UINT64_C(84), - UINT64_C(84)); - UT_ASSERT(!cluster_reconfig_stage_pre_publish_join_handoff( - UINT64_C(83), UINT64_C(82))); - UT_ASSERT_EQ((int)cluster_membership_get_state(cluster_node_id), - (int)CLUSTER_MEMBER_JOINING); + ut_set_self_incarnation_sequence(UINT64_C(83), UINT64_C(84), UINT64_C(84)); + UT_ASSERT(!cluster_reconfig_stage_pre_publish_join_handoff(UINT64_C(83), UINT64_C(82))); + UT_ASSERT_EQ((int)cluster_membership_get_state(cluster_node_id), (int)CLUSTER_MEMBER_JOINING); UT_ASSERT_EQ(state->self_join_admitted, 0); UT_ASSERT_EQ(state->self_join_failed, 0); UT_ASSERT_EQ(state->self_join_deadline_us, 0); @@ -4130,8 +3978,7 @@ UT_TEST(test_pre_publish_join_handoff_rejects_nonexact_state) * handoff does not retain a second cross-boot identity authority. */ state = ut_prepare_epoch0_managed_handoff(); - UT_ASSERT(cluster_reconfig_stage_pre_publish_join_handoff( - UINT64_C(83), UINT64_C(82))); + UT_ASSERT(cluster_reconfig_stage_pre_publish_join_handoff(UINT64_C(83), UINT64_C(82))); cluster_membership_record_admitted(cluster_node_id, UINT64_C(83)); UT_ASSERT(!cluster_reconfig_pre_publish_join_handoff_current()); UT_ASSERT_EQ(state->self_join_admitted, 0); @@ -4148,10 +3995,8 @@ UT_TEST(test_epoch0_managed_pivot_drives_ordinary_join_owner) int status = 0; ClusterReconfigState *state = ut_prepare_epoch0_managed_handoff(); - UT_ASSERT(cluster_reconfig_stage_pre_publish_join_handoff( - UINT64_C(83), UINT64_C(82))); - UT_ASSERT_EQ((int)cluster_membership_get_state(cluster_node_id), - (int)CLUSTER_MEMBER_JOINING); + UT_ASSERT(cluster_reconfig_stage_pre_publish_join_handoff(UINT64_C(83), UINT64_C(82))); + UT_ASSERT_EQ((int)cluster_membership_get_state(cluster_node_id), (int)CLUSTER_MEMBER_JOINING); fflush(NULL); pid = fork(); @@ -4160,8 +4005,7 @@ UT_TEST(test_epoch0_managed_pivot_drives_ordinary_join_owner) return; if (pid == 0) { ut_current_failed = 0; - ut_set_self_incarnation_sequence(UINT64_C(83), UINT64_C(83), - UINT64_C(83)); + ut_set_self_incarnation_sequence(UINT64_C(83), UINT64_C(83), UINT64_C(83)); ut_xid_stripe_verdict = CLUSTER_XID_STRIPE_JOIN_HOLD; ut_xid_stripe_progress = STRIPE_JOIN_CLAIM_OWNED; ut_recovery_in_progress = false; @@ -4183,14 +4027,14 @@ UT_TEST(test_epoch0_managed_pivot_drives_ordinary_join_owner) cluster_reconfig_note_self_admitted(UINT64_C(7)); UT_ASSERT_EQ(state->self_join_admitted, 0); UT_ASSERT_EQ((int)cluster_membership_get_state(cluster_node_id), - (int)CLUSTER_MEMBER_JOINING); + (int)CLUSTER_MEMBER_JOINING); ut_xid_stripe_verdict = CLUSTER_XID_STRIPE_JOIN_PROCEED; cluster_reconfig_note_self_admitted(UINT64_C(7)); UT_ASSERT_EQ(state->self_join_admitted, 1); UT_ASSERT_EQ((int)cluster_membership_get_state(cluster_node_id), - (int)CLUSTER_MEMBER_MEMBER); - UT_ASSERT_EQ(cluster_membership_get_last_admitted_incarnation( - cluster_node_id), UINT64_C(83)); + (int)CLUSTER_MEMBER_MEMBER); + UT_ASSERT_EQ(cluster_membership_get_last_admitted_incarnation(cluster_node_id), + UINT64_C(83)); fflush(stdout); _exit(ut_current_failed == 0 ? 0 : 1); } @@ -4208,8 +4052,7 @@ UT_TEST(test_epoch0_late_founder_evidence_requires_exact_peer_and_pgxa) ut_declared_set[0] = true; ut_declared_set[3] = true; ut_in_quorum_value = true; - cluster_reconfig_record_observed_slot( - 0, UINT64_C(80), UINT64_C(7), CLUSTER_EPOCH_INITIAL); + cluster_reconfig_record_observed_slot(0, UINT64_C(80), UINT64_C(7), CLUSTER_EPOCH_INITIAL); cluster_reconfig_record_observed_fresh_alive(0, true); cluster_membership_record_admitted(0, UINT64_C(80)); cluster_membership_set_state(0, CLUSTER_MEMBER_MEMBER); @@ -4239,8 +4082,7 @@ UT_TEST(test_epoch0_late_founder_evidence_requires_exact_peer_and_pgxa) cluster_reconfig_record_observed_fresh_alive(0, false); UT_ASSERT(!cluster_reconfig_epoch0_late_founder_evidence_current()); cluster_reconfig_record_observed_fresh_alive(0, true); - cluster_reconfig_record_observed_slot( - 0, UINT64_C(81), UINT64_C(8), CLUSTER_EPOCH_INITIAL); + cluster_reconfig_record_observed_slot(0, UINT64_C(81), UINT64_C(8), CLUSTER_EPOCH_INITIAL); UT_ASSERT(!cluster_reconfig_epoch0_late_founder_evidence_current()); cluster_membership_record_admitted(0, UINT64_C(81)); UT_ASSERT(cluster_reconfig_epoch0_late_founder_evidence_current()); @@ -4250,8 +4092,7 @@ UT_TEST(test_epoch0_late_founder_evidence_requires_exact_peer_and_pgxa) cluster_reconfig_bootstrap_publish_begin(); UT_ASSERT(!cluster_reconfig_epoch0_late_founder_evidence_current()); cluster_reconfig_bootstrap_publish_end(); - cluster_reconfig_record_observed_slot( - 0, UINT64_C(81), UINT64_C(9), UINT64_C(1)); + cluster_reconfig_record_observed_slot(0, UINT64_C(81), UINT64_C(9), UINT64_C(1)); UT_ASSERT(!cluster_reconfig_epoch0_late_founder_evidence_current()); } @@ -4275,11 +4116,9 @@ UT_TEST(test_late_joiner_stripe_refuse_is_terminal_fail_closed) ut_declared_set[0] = true; ut_declared_set[1] = true; ut_in_quorum_value = true; - ut_set_self_incarnation_sequence(UINT64_C(72), UINT64_C(72), - UINT64_C(72)); + ut_set_self_incarnation_sequence(UINT64_C(72), UINT64_C(72), UINT64_C(72)); state = (ClusterReconfigState *)reconfig_shmem_storage; - cluster_reconfig_record_observed_slot( - 0, UINT64_C(100), UINT64_C(2), UINT64_C(7)); + cluster_reconfig_record_observed_slot(0, UINT64_C(100), UINT64_C(2), UINT64_C(7)); cluster_reconfig_record_observed_fresh_alive(0, true); ut_xid_stripe_progress = STRIPE_JOIN_REFUSE; @@ -4312,8 +4151,7 @@ UT_TEST(test_online_join_waits_for_own_stripe_claim) ut_join_setup(); cluster_node_id = 1; ut_declared_set[1] = true; - ut_set_self_incarnation_sequence(UINT64_C(81), UINT64_C(81), - UINT64_C(81)); + ut_set_self_incarnation_sequence(UINT64_C(81), UINT64_C(81), UINT64_C(81)); state = (ClusterReconfigState *)reconfig_shmem_storage; cluster_membership_set_state(cluster_node_id, CLUSTER_MEMBER_JOINING); ut_xid_stripe_verdict = CLUSTER_XID_STRIPE_JOIN_HOLD; @@ -4322,20 +4160,16 @@ UT_TEST(test_online_join_waits_for_own_stripe_claim) UT_ASSERT_EQ(ut_xid_stripe_join_gate_calls, 1); UT_ASSERT(!ut_xid_stripe_last_may_seed); UT_ASSERT_EQ(state->self_join_admitted, 0); - UT_ASSERT_EQ((int)cluster_membership_get_state(cluster_node_id), - (int)CLUSTER_MEMBER_JOINING); - UT_ASSERT_EQ(cluster_membership_get_last_admitted_incarnation( - cluster_node_id), UINT64_C(0)); + UT_ASSERT_EQ((int)cluster_membership_get_state(cluster_node_id), (int)CLUSTER_MEMBER_JOINING); + UT_ASSERT_EQ(cluster_membership_get_last_admitted_incarnation(cluster_node_id), UINT64_C(0)); ut_xid_stripe_verdict = CLUSTER_XID_STRIPE_JOIN_PROCEED; cluster_reconfig_note_self_admitted(UINT64_C(7)); UT_ASSERT_EQ(ut_xid_stripe_join_gate_calls, 2); UT_ASSERT(!ut_xid_stripe_last_may_seed); UT_ASSERT_EQ(state->self_join_admitted, 1); - UT_ASSERT_EQ((int)cluster_membership_get_state(cluster_node_id), - (int)CLUSTER_MEMBER_MEMBER); - UT_ASSERT_EQ(cluster_membership_get_last_admitted_incarnation( - cluster_node_id), UINT64_C(81)); + UT_ASSERT_EQ((int)cluster_membership_get_state(cluster_node_id), (int)CLUSTER_MEMBER_MEMBER); + UT_ASSERT_EQ(cluster_membership_get_last_admitted_incarnation(cluster_node_id), UINT64_C(81)); cluster_online_join = false; } @@ -4350,8 +4184,7 @@ UT_TEST(test_online_join_waits_for_join_wal) ut_join_setup(); cluster_node_id = 2; ut_declared_set[2] = true; - ut_set_self_incarnation_sequence(UINT64_C(82), UINT64_C(82), - UINT64_C(82)); + ut_set_self_incarnation_sequence(UINT64_C(82), UINT64_C(82), UINT64_C(82)); state = (ClusterReconfigState *)reconfig_shmem_storage; cluster_membership_set_state(cluster_node_id, CLUSTER_MEMBER_JOINING); ut_xid_stripe_verdict = CLUSTER_XID_STRIPE_JOIN_HOLD; @@ -4360,18 +4193,15 @@ UT_TEST(test_online_join_waits_for_join_wal) UT_ASSERT_EQ(ut_xid_stripe_join_gate_calls, 1); UT_ASSERT(!ut_xid_stripe_last_may_seed); UT_ASSERT_EQ(state->self_join_admitted, 0); - UT_ASSERT_EQ((int)cluster_membership_get_state(cluster_node_id), - (int)CLUSTER_MEMBER_JOINING); + UT_ASSERT_EQ((int)cluster_membership_get_state(cluster_node_id), (int)CLUSTER_MEMBER_JOINING); ut_xid_stripe_verdict = CLUSTER_XID_STRIPE_JOIN_PROCEED; cluster_reconfig_note_self_admitted(UINT64_C(9)); UT_ASSERT_EQ(ut_xid_stripe_join_gate_calls, 2); UT_ASSERT(!ut_xid_stripe_last_may_seed); UT_ASSERT_EQ(state->self_join_admitted, 1); - UT_ASSERT_EQ((int)cluster_membership_get_state(cluster_node_id), - (int)CLUSTER_MEMBER_MEMBER); - UT_ASSERT_EQ(cluster_membership_get_last_admitted_incarnation( - cluster_node_id), UINT64_C(82)); + UT_ASSERT_EQ((int)cluster_membership_get_state(cluster_node_id), (int)CLUSTER_MEMBER_MEMBER); + UT_ASSERT_EQ(cluster_membership_get_last_admitted_incarnation(cluster_node_id), UINT64_C(82)); cluster_online_join = false; } @@ -4433,18 +4263,14 @@ UT_TEST(test_offpath_member_requires_decided_boot_and_exact_current_floor) ut_in_quorum_value = true; state = (ClusterReconfigState *)reconfig_shmem_storage; ut_offpath_boot_decided = true; - ut_set_self_incarnation_sequence(UINT64_C(101), UINT64_C(101), - UINT64_C(101)); + ut_set_self_incarnation_sequence(UINT64_C(101), UINT64_C(101), UINT64_C(101)); cluster_reconfig_lmon_tick(); UT_ASSERT_EQ(state->self_join_admitted, 1); - UT_ASSERT_EQ(cluster_membership_get_last_admitted_incarnation(cluster_node_id), - UINT64_C(101)); - UT_ASSERT_EQ((int)cluster_membership_get_state(cluster_node_id), - (int)CLUSTER_MEMBER_MEMBER); + UT_ASSERT_EQ(cluster_membership_get_last_admitted_incarnation(cluster_node_id), UINT64_C(101)); + UT_ASSERT_EQ((int)cluster_membership_get_state(cluster_node_id), (int)CLUSTER_MEMBER_MEMBER); invalidations_after_publish = ut_authority_cache_invalidate_count; cluster_reconfig_lmon_tick(); - UT_ASSERT_EQ(ut_authority_cache_invalidate_count, - invalidations_after_publish); + UT_ASSERT_EQ(ut_authority_cache_invalidate_count, invalidations_after_publish); /* With multiple declared nodes and no fresh bootstrap quorum, Shape A is * UNDECIDED. The ordinary maintenance choke must withhold both floor and @@ -4455,14 +4281,11 @@ UT_TEST(test_offpath_member_requires_decided_boot_and_exact_current_floor) ut_declared_set[1] = true; ut_declared_set[2] = true; ut_offpath_boot_decided = false; - ut_set_self_incarnation_sequence(UINT64_C(102), UINT64_C(102), - UINT64_C(102)); + ut_set_self_incarnation_sequence(UINT64_C(102), UINT64_C(102), UINT64_C(102)); cluster_reconfig_lmon_tick(); UT_ASSERT_EQ(state->self_join_admitted, 1); - UT_ASSERT_EQ(cluster_membership_get_last_admitted_incarnation(cluster_node_id), - UINT64_C(0)); - UT_ASSERT_EQ((int)cluster_membership_get_state(cluster_node_id), - (int)CLUSTER_MEMBER_JOINING); + UT_ASSERT_EQ(cluster_membership_get_last_admitted_incarnation(cluster_node_id), UINT64_C(0)); + UT_ASSERT_EQ((int)cluster_membership_get_state(cluster_node_id), (int)CLUSTER_MEMBER_JOINING); } UT_TEST(test_ordinary_self_floor_drift_and_high_water_fail_closed_then_retry) @@ -4474,16 +4297,12 @@ UT_TEST(test_ordinary_self_floor_drift_and_high_water_fail_closed_then_retry) ut_offpath_boot_decided = true; ut_set_self_incarnation_sequence(0, 0, 0); cluster_reconfig_lmon_tick(); - UT_ASSERT_EQ((int)cluster_membership_get_state(cluster_node_id), - (int)CLUSTER_MEMBER_JOINING); - UT_ASSERT_EQ(cluster_membership_get_last_admitted_incarnation(cluster_node_id), - UINT64_C(0)); + UT_ASSERT_EQ((int)cluster_membership_get_state(cluster_node_id), (int)CLUSTER_MEMBER_JOINING); + UT_ASSERT_EQ(cluster_membership_get_last_admitted_incarnation(cluster_node_id), UINT64_C(0)); ut_set_self_incarnation_sequence(UINT64_C(31), UINT64_C(31), UINT64_C(31)); cluster_reconfig_lmon_tick(); - UT_ASSERT_EQ((int)cluster_membership_get_state(cluster_node_id), - (int)CLUSTER_MEMBER_MEMBER); - UT_ASSERT_EQ(cluster_membership_get_last_admitted_incarnation(cluster_node_id), - UINT64_C(31)); + UT_ASSERT_EQ((int)cluster_membership_get_state(cluster_node_id), (int)CLUSTER_MEMBER_MEMBER); + UT_ASSERT_EQ(cluster_membership_get_last_admitted_incarnation(cluster_node_id), UINT64_C(31)); /* A change between the pre-lock and lock-held samples records nothing. */ ut_join_setup(); @@ -4491,16 +4310,12 @@ UT_TEST(test_ordinary_self_floor_drift_and_high_water_fail_closed_then_retry) ut_offpath_boot_decided = true; ut_set_self_incarnation_sequence(UINT64_C(40), UINT64_C(41), UINT64_C(41)); cluster_reconfig_lmon_tick(); - UT_ASSERT_EQ((int)cluster_membership_get_state(cluster_node_id), - (int)CLUSTER_MEMBER_JOINING); - UT_ASSERT_EQ(cluster_membership_get_last_admitted_incarnation(cluster_node_id), - UINT64_C(0)); + UT_ASSERT_EQ((int)cluster_membership_get_state(cluster_node_id), (int)CLUSTER_MEMBER_JOINING); + UT_ASSERT_EQ(cluster_membership_get_last_admitted_incarnation(cluster_node_id), UINT64_C(0)); ut_set_self_incarnation_sequence(UINT64_C(41), UINT64_C(41), UINT64_C(41)); cluster_reconfig_lmon_tick(); - UT_ASSERT_EQ(cluster_membership_get_last_admitted_incarnation(cluster_node_id), - UINT64_C(41)); - UT_ASSERT_EQ((int)cluster_membership_get_state(cluster_node_id), - (int)CLUSTER_MEMBER_MEMBER); + UT_ASSERT_EQ(cluster_membership_get_last_admitted_incarnation(cluster_node_id), UINT64_C(41)); + UT_ASSERT_EQ((int)cluster_membership_get_state(cluster_node_id), (int)CLUSTER_MEMBER_MEMBER); /* A post-record incarnation change leaves the raised floor but withholds * MEMBER until a later stable incarnation raises it again. */ @@ -4509,16 +4324,12 @@ UT_TEST(test_ordinary_self_floor_drift_and_high_water_fail_closed_then_retry) ut_offpath_boot_decided = true; ut_set_self_incarnation_sequence(UINT64_C(60), UINT64_C(60), UINT64_C(61)); cluster_reconfig_lmon_tick(); - UT_ASSERT_EQ(cluster_membership_get_last_admitted_incarnation(cluster_node_id), - UINT64_C(60)); - UT_ASSERT_EQ((int)cluster_membership_get_state(cluster_node_id), - (int)CLUSTER_MEMBER_JOINING); + UT_ASSERT_EQ(cluster_membership_get_last_admitted_incarnation(cluster_node_id), UINT64_C(60)); + UT_ASSERT_EQ((int)cluster_membership_get_state(cluster_node_id), (int)CLUSTER_MEMBER_JOINING); ut_set_self_incarnation_sequence(UINT64_C(61), UINT64_C(61), UINT64_C(61)); cluster_reconfig_lmon_tick(); - UT_ASSERT_EQ(cluster_membership_get_last_admitted_incarnation(cluster_node_id), - UINT64_C(61)); - UT_ASSERT_EQ((int)cluster_membership_get_state(cluster_node_id), - (int)CLUSTER_MEMBER_MEMBER); + UT_ASSERT_EQ(cluster_membership_get_last_admitted_incarnation(cluster_node_id), UINT64_C(61)); + UT_ASSERT_EQ((int)cluster_membership_get_state(cluster_node_id), (int)CLUSTER_MEMBER_MEMBER); /* Monotonic record_admitted cannot lower a prior floor. Exact equality is * still required before MEMBER, then the matching formation retries. */ @@ -4528,16 +4339,12 @@ UT_TEST(test_ordinary_self_floor_drift_and_high_water_fail_closed_then_retry) cluster_membership_record_admitted(cluster_node_id, UINT64_C(70)); ut_set_self_incarnation_sequence(UINT64_C(69), UINT64_C(69), UINT64_C(69)); cluster_reconfig_lmon_tick(); - UT_ASSERT_EQ(cluster_membership_get_last_admitted_incarnation(cluster_node_id), - UINT64_C(70)); - UT_ASSERT_EQ((int)cluster_membership_get_state(cluster_node_id), - (int)CLUSTER_MEMBER_JOINING); + UT_ASSERT_EQ(cluster_membership_get_last_admitted_incarnation(cluster_node_id), UINT64_C(70)); + UT_ASSERT_EQ((int)cluster_membership_get_state(cluster_node_id), (int)CLUSTER_MEMBER_JOINING); ut_set_self_incarnation_sequence(UINT64_C(70), UINT64_C(70), UINT64_C(70)); cluster_reconfig_lmon_tick(); - UT_ASSERT_EQ((int)cluster_membership_get_state(cluster_node_id), - (int)CLUSTER_MEMBER_MEMBER); - UT_ASSERT_EQ(cluster_membership_get_last_admitted_incarnation(cluster_node_id), - UINT64_C(70)); + UT_ASSERT_EQ((int)cluster_membership_get_state(cluster_node_id), (int)CLUSTER_MEMBER_MEMBER); + UT_ASSERT_EQ(cluster_membership_get_last_admitted_incarnation(cluster_node_id), UINT64_C(70)); } UT_TEST(test_self_join_gate_lifecycle) @@ -4585,18 +4392,15 @@ UT_TEST(test_replacement_member_publish_is_exact_and_write_closed) wrong = episode; wrong.phase = CLUSTER_REPLACEMENT_EPISODE_COMMITTED_CLOSED; UT_ASSERT(!cluster_reconfig_publish_replacement_member_closed(&wrong)); - UT_ASSERT_EQ((int)cluster_membership_get_state(cluster_node_id), - (int)CLUSTER_MEMBER_ABSENT); - UT_ASSERT_EQ((int)cluster_reconfig_self_join_gate_verdict(), - (int)CLUSTER_JOIN_GATE_ALLOW); + UT_ASSERT_EQ((int)cluster_membership_get_state(cluster_node_id), (int)CLUSTER_MEMBER_ABSENT); + UT_ASSERT_EQ((int)cluster_reconfig_self_join_gate_verdict(), (int)CLUSTER_JOIN_GATE_ALLOW); wrong = episode; wrong.target_node_id = 3; UT_ASSERT(!cluster_reconfig_publish_replacement_member_closed(&wrong)); UT_ASSERT(cluster_reconfig_publish_replacement_member_closed(&episode)); - UT_ASSERT_EQ((int)cluster_membership_get_state(cluster_node_id), - (int)CLUSTER_MEMBER_MEMBER); + UT_ASSERT_EQ((int)cluster_membership_get_state(cluster_node_id), (int)CLUSTER_MEMBER_MEMBER); UT_ASSERT_EQ((int)cluster_reconfig_self_join_gate_verdict(), (int)CLUSTER_JOIN_GATE_BLOCK_53R60); UT_ASSERT_EQ(memcmp(&state->replacement_episode, &episode, sizeof(episode)), 0); @@ -4612,8 +4416,7 @@ UT_TEST(test_replacement_member_publish_is_exact_and_write_closed) cluster_reconfig_note_self_admitted(episode.reserved_or_committed_epoch); UT_ASSERT_EQ((int)cluster_reconfig_self_join_gate_verdict(), (int)CLUSTER_JOIN_GATE_BLOCK_53R60); - UT_ASSERT_EQ((int)cluster_membership_get_state(cluster_node_id), - (int)CLUSTER_MEMBER_MEMBER); + UT_ASSERT_EQ((int)cluster_membership_get_state(cluster_node_id), (int)CLUSTER_MEMBER_MEMBER); } /* The ordinary LMON self-state maintenance must not infer JOINING solely from @@ -4632,12 +4435,10 @@ UT_TEST(test_lmon_preserves_replacement_admitted_member_while_write_closed) UT_ASSERT(cluster_reconfig_publish_replacement_member_closed(&episode)); cluster_reconfig_lmon_tick(); - UT_ASSERT_EQ((int)cluster_membership_get_state(cluster_node_id), - (int)CLUSTER_MEMBER_MEMBER); + UT_ASSERT_EQ((int)cluster_membership_get_state(cluster_node_id), (int)CLUSTER_MEMBER_MEMBER); UT_ASSERT_EQ((int)cluster_reconfig_self_join_gate_verdict(), (int)CLUSTER_JOIN_GATE_BLOCK_53R60); - UT_ASSERT_EQ(cluster_membership_get_last_admitted_incarnation(cluster_node_id), - UINT64_C(0)); + UT_ASSERT_EQ(cluster_membership_get_last_admitted_incarnation(cluster_node_id), UINT64_C(0)); } /* With online join enabled, the ordinary cold-bootstrap classifier also runs @@ -4658,8 +4459,7 @@ UT_TEST(test_ordinary_bootstrap_cannot_open_replacement_admitted_member) UT_ASSERT_EQ((int)cluster_reconfig_self_join_gate_verdict(), (int)CLUSTER_JOIN_GATE_BLOCK_53R60); - UT_ASSERT_EQ((int)cluster_membership_get_state(cluster_node_id), - (int)CLUSTER_MEMBER_MEMBER); + UT_ASSERT_EQ((int)cluster_membership_get_state(cluster_node_id), (int)CLUSTER_MEMBER_MEMBER); cluster_online_join = false; } @@ -4701,35 +4501,27 @@ UT_TEST(test_uniform_open_requires_exact_replacement_episode_and_generation) ut_join_setup(); episode = ut_admitted_replacement_episode(cluster_node_id); - UT_ASSERT(!cluster_reconfig_open_replacement_admission( - &episode, episode.state_generation)); + UT_ASSERT(!cluster_reconfig_open_replacement_admission(&episode, episode.state_generation)); UT_ASSERT(cluster_reconfig_publish_replacement_member_closed(&episode)); - UT_ASSERT(!cluster_reconfig_open_replacement_admission( - &episode, episode.state_generation + 1)); + UT_ASSERT(!cluster_reconfig_open_replacement_admission(&episode, episode.state_generation + 1)); wrong = episode; wrong.request_nonce++; - UT_ASSERT(!cluster_reconfig_open_replacement_admission( - &wrong, wrong.state_generation)); + UT_ASSERT(!cluster_reconfig_open_replacement_admission(&wrong, wrong.state_generation)); cluster_membership_set_state(cluster_node_id, CLUSTER_MEMBER_JOINING); - UT_ASSERT(!cluster_reconfig_open_replacement_admission( - &episode, episode.state_generation)); + UT_ASSERT(!cluster_reconfig_open_replacement_admission(&episode, episode.state_generation)); UT_ASSERT_EQ((int)cluster_reconfig_self_join_gate_verdict(), (int)CLUSTER_JOIN_GATE_BLOCK_53R60); cluster_membership_set_state(cluster_node_id, CLUSTER_MEMBER_MEMBER); - UT_ASSERT(cluster_reconfig_open_replacement_admission( - &episode, episode.state_generation)); - UT_ASSERT_EQ((int)cluster_reconfig_self_join_gate_verdict(), - (int)CLUSTER_JOIN_GATE_ALLOW); - UT_ASSERT(cluster_reconfig_open_replacement_admission( - &episode, episode.state_generation)); + UT_ASSERT(cluster_reconfig_open_replacement_admission(&episode, episode.state_generation)); + UT_ASSERT_EQ((int)cluster_reconfig_self_join_gate_verdict(), (int)CLUSTER_JOIN_GATE_ALLOW); + UT_ASSERT(cluster_reconfig_open_replacement_admission(&episode, episode.state_generation)); /* A delayed closed-MEMBER duplicate cannot re-close a completed OPEN. */ UT_ASSERT(!cluster_reconfig_publish_replacement_member_closed(&episode)); - UT_ASSERT_EQ((int)cluster_reconfig_self_join_gate_verdict(), - (int)CLUSTER_JOIN_GATE_ALLOW); + UT_ASSERT_EQ((int)cluster_reconfig_self_join_gate_verdict(), (int)CLUSTER_JOIN_GATE_ALLOW); } /* ====================================================================== @@ -4829,12 +4621,12 @@ UT_TEST(test_reconfig_bootstrap_quorum_epoch_proof) UT_TEST(test_reconfig_bootstrap_proof_seqlock) { ClusterReconfigState *state; - uint64 inc = 0; + uint64 inc = 0; - ut_join_setup(); /* self = node 0, fresh shmem, seq 0 even */ + ut_join_setup(); /* self = node 0, fresh shmem, seq 0 even */ ut_declared_set[1] = true; ut_declared_set[2] = true; - state = (ClusterReconfigState *) reconfig_shmem_storage; + state = (ClusterReconfigState *)reconfig_shmem_storage; /* --- A. ODD seq (writer in progress) is never accepted. --- */ cluster_reconfig_record_observed_slot(1, 7, 1, 0); @@ -4861,10 +4653,10 @@ UT_TEST(test_reconfig_bootstrap_proof_seqlock) * publishes fresh for the same round inside the same window, * so the mixed state cannot survive end(). --- */ pg_atomic_write_u64(&state->observed_bootstrap_seq, 5); /* begin: odd */ - cluster_reconfig_record_observed_slot(1, 9, 2, 0); /* NEW incarnation */ + cluster_reconfig_record_observed_slot(1, 9, 2, 0); /* NEW incarnation */ /* fresh_alive(1) is still true from the OLD round — the mixed view */ UT_ASSERT(!cluster_reconfig_bootstrap_proof_node(1, &inc)); /* odd: reject */ - pg_atomic_write_u64(&state->observed_bootstrap_seq, 6); /* end: even */ + pg_atomic_write_u64(&state->observed_bootstrap_seq, 6); /* end: even */ UT_ASSERT(cluster_reconfig_bootstrap_proof_node(1, &inc)); UT_ASSERT(inc == UINT64_C(9)); @@ -4998,22 +4790,20 @@ UT_TEST(test_reconfig_bootstrap_proof_stale_slot_failclosed) } static bool -ut_join_qvotec_poll_write_pending(int32 *target_node_out, - void *write_slot512_out) +ut_join_qvotec_poll_write_pending(int32 *target_node_out, void *write_slot512_out) { ClusterJoinMarkerMailboxOperationV1 operation; bool pending; - pending = cluster_reconfig_join_qvotec_poll_pending( - &operation, target_node_out, write_slot512_out); + pending + = cluster_reconfig_join_qvotec_poll_pending(&operation, target_node_out, write_slot512_out); return pending && operation == CLUSTER_JOIN_MARKER_MAILBOX_WRITE_EXACT; } static void ut_join_qvotec_complete_write(bool acked) { - cluster_reconfig_join_qvotec_complete( - CLUSTER_JOIN_MARKER_MAILBOX_WRITE_EXACT, acked, NULL); + cluster_reconfig_join_qvotec_complete(CLUSTER_JOIN_MARKER_MAILBOX_WRITE_EXACT, acked, NULL); } static void @@ -5074,13 +4864,11 @@ UT_TEST(test_join_commit_clears_only_owner_after_root_rejoin_gate) UT_ASSERT_EQ(ut_owner_rejoin_incarnation, UINT64_C(77)); UT_ASSERT(ut_fence_async_marker_captured); UT_ASSERT(cluster_fence_marker_valid_v1(&ut_fence_async_marker)); - UT_ASSERT_EQ((int)ut_fence_async_marker.marker_kind, - (int)CLUSTER_FENCE_MARKER_KIND_BASELINE); + UT_ASSERT_EQ((int)ut_fence_async_marker.marker_kind, (int)CLUSTER_FENCE_MARKER_KIND_BASELINE); UT_ASSERT_EQ(ut_fence_async_marker.fenced_dead_bitmap[0], UINT8_C(0x04)); cluster_reconfig_get_last_event(&applied); UT_ASSERT_EQ(applied.event_id, UINT64_C(501)); - UT_ASSERT_EQ((int)cluster_membership_get_state(1), - (int)CLUSTER_MEMBER_JOINING); + UT_ASSERT_EQ((int)cluster_membership_get_state(1), (int)CLUSTER_MEMBER_JOINING); ut_fence_async_poll_pr = CLUSTER_MARKER_POLL_ACKED; ut_fence_async_poll_result = CLUSTER_FENCE_MARKER_SUBMIT_ACK; @@ -5089,10 +4877,8 @@ UT_TEST(test_join_commit_clears_only_owner_after_root_rejoin_gate) UT_ASSERT_EQ((int)applied.reconfig_kind, (int)RECONFIG_KIND_JOIN_COMMITTED); UT_ASSERT_EQ(ut_fence_async_marker.fence_epoch, applied.new_epoch); UT_ASSERT_EQ(ut_fence_async_marker.fence_event_id, applied.event_id); - UT_ASSERT_EQ(ut_fence_async_marker.fence_generation, - applied.cssd_dead_generation); - UT_ASSERT_EQ(ut_fence_async_marker.issuer_node_id, - applied.coordinator_node_id); + UT_ASSERT_EQ(ut_fence_async_marker.fence_generation, applied.cssd_dead_generation); + UT_ASSERT_EQ(ut_fence_async_marker.issuer_node_id, applied.coordinator_node_id); UT_ASSERT((applied.dead_bitmap[0] & UINT8_C(0x02)) == 0); UT_ASSERT((applied.dead_bitmap[0] & UINT8_C(0x04)) != 0); MyBackendType = B_INVALID; @@ -5110,8 +4896,7 @@ UT_TEST(test_join_commit_root_gate_failure_keeps_owner_excluded) cluster_reconfig_get_last_event(&applied); UT_ASSERT_EQ(applied.event_id, UINT64_C(501)); UT_ASSERT((applied.dead_bitmap[0] & UINT8_C(0x02)) != 0); - UT_ASSERT_EQ((int)cluster_membership_get_state(1), - (int)CLUSTER_MEMBER_JOINING); + UT_ASSERT_EQ((int)cluster_membership_get_state(1), (int)CLUSTER_MEMBER_JOINING); MyBackendType = B_INVALID; cluster_write_fence_enforcement = CLUSTER_WRITE_FENCE_ENFORCE_OFF; cluster_online_join = false; @@ -5130,8 +4915,7 @@ UT_TEST(test_join_commit_fence_ack_failure_keeps_owner_excluded) cluster_reconfig_get_last_event(&applied); UT_ASSERT_EQ(applied.event_id, UINT64_C(501)); UT_ASSERT_EQ(applied.dead_bitmap[0], UINT8_C(0x06)); - UT_ASSERT_EQ((int)cluster_membership_get_state(1), - (int)CLUSTER_MEMBER_JOINING); + UT_ASSERT_EQ((int)cluster_membership_get_state(1), (int)CLUSTER_MEMBER_JOINING); MyBackendType = B_INVALID; cluster_write_fence_enforcement = CLUSTER_WRITE_FENCE_ENFORCE_OFF; cluster_online_join = false; @@ -5229,8 +5013,7 @@ UT_TEST(test_survivor_join_observation_requires_root_rejoin_gate) UT_ASSERT_EQ(ut_owner_rejoin_calls, 1); UT_ASSERT_EQ(ut_owner_rejoin_node, 2); UT_ASSERT_EQ(ut_owner_rejoin_incarnation, UINT64_C(77)); - UT_ASSERT_EQ((int)cluster_membership_get_state(2), - (int)CLUSTER_MEMBER_DEAD); + UT_ASSERT_EQ((int)cluster_membership_get_state(2), (int)CLUSTER_MEMBER_DEAD); cluster_reconfig_get_last_event(&applied); UT_ASSERT_EQ(applied.event_id, UINT64_C(601)); UT_ASSERT_EQ(applied.dead_bitmap[0], UINT8_C(0x0c)); @@ -5244,11 +5027,9 @@ UT_TEST(test_survivor_join_observation_clears_only_gated_origin) ut_stage_survivor_join_observation(true); cluster_reconfig_lmon_tick(); UT_ASSERT_EQ(ut_owner_rejoin_calls, 1); - UT_ASSERT_EQ((int)cluster_membership_get_state(2), - (int)CLUSTER_MEMBER_MEMBER); + UT_ASSERT_EQ((int)cluster_membership_get_state(2), (int)CLUSTER_MEMBER_MEMBER); cluster_reconfig_get_last_event(&applied); - UT_ASSERT_EQ((int)applied.reconfig_kind, - (int)RECONFIG_KIND_JOIN_COMMITTED); + UT_ASSERT_EQ((int)applied.reconfig_kind, (int)RECONFIG_KIND_JOIN_COMMITTED); UT_ASSERT((applied.dead_bitmap[0] & UINT8_C(0x04)) == 0); UT_ASSERT((applied.dead_bitmap[0] & UINT8_C(0x08)) != 0); cluster_online_join = false; @@ -5263,16 +5044,14 @@ UT_TEST(test_survivor_join_observation_waits_for_serving_ready) ut_serving_ready = false; cluster_reconfig_lmon_tick(); UT_ASSERT_EQ(ut_owner_rejoin_calls, 0); - UT_ASSERT_EQ((int)cluster_membership_get_state(2), - (int)CLUSTER_MEMBER_DEAD); + UT_ASSERT_EQ((int)cluster_membership_get_state(2), (int)CLUSTER_MEMBER_DEAD); cluster_reconfig_get_last_event(&applied); UT_ASSERT_EQ(applied.event_id, UINT64_C(601)); ut_serving_ready = true; cluster_reconfig_lmon_tick(); UT_ASSERT_EQ(ut_owner_rejoin_calls, 1); - UT_ASSERT_EQ((int)cluster_membership_get_state(2), - (int)CLUSTER_MEMBER_MEMBER); + UT_ASSERT_EQ((int)cluster_membership_get_state(2), (int)CLUSTER_MEMBER_MEMBER); cluster_online_join = false; } @@ -5307,8 +5086,7 @@ UT_TEST(test_reconfig_region3_mailbox_preserves_v2_and_canonical_v3) cluster_join_marker_compute_crc(&v2); cluster_marker_async_init(&async); UT_ASSERT(cluster_reconfig_submit_join_marker_async( - &async, 2, &v2, CLUSTER_MARKER_KIND_JOIN_PREPARE, - (TimestampTz)UINT64_C(1000))); + &async, 2, &v2, CLUSTER_MARKER_KIND_JOIN_PREPARE, (TimestampTz)UINT64_C(1000))); memset(slot, 0xa5, sizeof(slot)); UT_ASSERT(ut_join_qvotec_poll_write_pending(&target, slot)); UT_ASSERT_EQ(target, 2); @@ -5336,15 +5114,13 @@ UT_TEST(test_reconfig_region3_mailbox_preserves_v2_and_canonical_v3) cluster_marker_async_init(&async); UT_ASSERT(cluster_reconfig_submit_replacement_marker_v3_async( - &async, 3, &v3, CLUSTER_MARKER_KIND_JOIN_COMMITTED, - (TimestampTz)UINT64_C(2000))); + &async, 3, &v3, CLUSTER_MARKER_KIND_JOIN_COMMITTED, (TimestampTz)UINT64_C(2000))); memset(slot, 0xa5, sizeof(slot)); target = -1; UT_ASSERT(ut_join_qvotec_poll_write_pending(&target, slot)); UT_ASSERT_EQ(target, 3); UT_ASSERT_EQ(memcmp(slot, expected_v3, sizeof(expected_v3)), 0); - for (i = CLUSTER_JCMK_REPLACEMENT_BYTES; - i < CLUSTER_VOTING_SLOT_BYTES; i++) + for (i = CLUSTER_JCMK_REPLACEMENT_BYTES; i < CLUSTER_VOTING_SLOT_BYTES; i++) UT_ASSERT_EQ(slot[i], 0); ut_join_qvotec_complete_write(true); @@ -5353,15 +5129,13 @@ UT_TEST(test_reconfig_region3_mailbox_preserves_v2_and_canonical_v3) v3.reserved0[0] = 1; cluster_marker_async_init(&async); UT_ASSERT(!cluster_reconfig_submit_replacement_marker_v3_async( - &async, 3, &v3, CLUSTER_MARKER_KIND_JOIN_COMMITTED, - (TimestampTz)UINT64_C(3000))); + &async, 3, &v3, CLUSTER_MARKER_KIND_JOIN_COMMITTED, (TimestampTz)UINT64_C(3000))); UT_ASSERT(!cluster_marker_async_is_submitted(&async)); UT_ASSERT_EQ(pg_atomic_read_u64(&state->join_marker_request_seq), seq_before); UT_ASSERT(!ut_join_qvotec_poll_write_pending(&target, slot)); v3.reserved0[0] = 0; UT_ASSERT(!cluster_reconfig_submit_replacement_marker_v3_async( - &async, 4, &v3, CLUSTER_MARKER_KIND_JOIN_COMMITTED, - (TimestampTz)UINT64_C(3001))); + &async, 4, &v3, CLUSTER_MARKER_KIND_JOIN_COMMITTED, (TimestampTz)UINT64_C(3001))); UT_ASSERT(!cluster_marker_async_is_submitted(&async)); UT_ASSERT_EQ(pg_atomic_read_u64(&state->join_marker_request_seq), seq_before); UT_ASSERT(!ut_join_qvotec_poll_write_pending(&target, slot)); @@ -5386,12 +5160,9 @@ UT_TEST(test_reconfig_region3_mailbox_request_word_is_exact_duplex) ut_join_setup(); state = (ClusterReconfigState *)reconfig_shmem_storage; UT_ASSERT_EQ(sizeof(ClusterReconfigState), 12640); - UT_ASSERT_EQ(CLUSTER_JOIN_MARKER_REQUEST_TARGET_MASK, - UINT32_C(0x0000007f)); - UT_ASSERT_EQ(CLUSTER_JOIN_MARKER_REQUEST_RESERVED_MASK, - UINT32_C(0x7fffff80)); - UT_ASSERT_EQ(CLUSTER_JOIN_MARKER_REQUEST_VERIFY_COMMITTED_CLOSED, - UINT32_C(0x80000000)); + UT_ASSERT_EQ(CLUSTER_JOIN_MARKER_REQUEST_TARGET_MASK, UINT32_C(0x0000007f)); + UT_ASSERT_EQ(CLUSTER_JOIN_MARKER_REQUEST_RESERVED_MASK, UINT32_C(0x7fffff80)); + UT_ASSERT_EQ(CLUSTER_JOIN_MARKER_REQUEST_VERIFY_COMMITTED_CLOSED, UINT32_C(0x80000000)); memset(&marker, 0, sizeof(marker)); marker.magic = CLUSTER_JCMK_MAGIC; @@ -5413,25 +5184,21 @@ UT_TEST(test_reconfig_region3_mailbox_request_word_is_exact_duplex) &async, marker.target_node_id, (TimestampTz)UINT64_C(4000))); UT_ASSERT_EQ(state->join_marker_request_word, CLUSTER_JOIN_MARKER_REQUEST_VERIFY_COMMITTED_CLOSED - | (uint32)marker.target_node_id); + | (uint32)marker.target_node_id); for (i = 0; i < CLUSTER_JCMK_REPLACEMENT_BYTES; i++) UT_ASSERT_EQ(state->join_pending_marker[i], 0); memset(slot, 0xa5, sizeof(slot)); operation = CLUSTER_JOIN_MARKER_MAILBOX_WRITE_EXACT; target = -1; - UT_ASSERT(cluster_reconfig_join_qvotec_poll_pending( - &operation, &target, slot)); - UT_ASSERT_EQ((int)operation, - (int)CLUSTER_JOIN_MARKER_MAILBOX_VERIFY_COMMITTED_CLOSED); + UT_ASSERT(cluster_reconfig_join_qvotec_poll_pending(&operation, &target, slot)); + UT_ASSERT_EQ((int)operation, (int)CLUSTER_JOIN_MARKER_MAILBOX_VERIFY_COMMITTED_CLOSED); UT_ASSERT_EQ(target, marker.target_node_id); for (i = 0; i < CLUSTER_VOTING_SLOT_BYTES; i++) UT_ASSERT_EQ(slot[i], 0); cluster_reconfig_join_qvotec_complete(operation, true, image); - UT_ASSERT_EQ(pg_atomic_read_u32(&state->join_marker_result), - CLUSTER_JOIN_MARKER_SUBMIT_ACK); - UT_ASSERT_EQ(pg_atomic_read_u64(&state->join_marker_completion_seq), - async.inflight_seq); + UT_ASSERT_EQ(pg_atomic_read_u32(&state->join_marker_result), CLUSTER_JOIN_MARKER_SUBMIT_ACK); + UT_ASSERT_EQ(pg_atomic_read_u64(&state->join_marker_completion_seq), async.inflight_seq); UT_ASSERT_EQ(memcmp(state->join_pending_marker, image, sizeof(image)), 0); /* The next VERIFY deliberately completes through the WRITE branch. */ @@ -5439,12 +5206,9 @@ UT_TEST(test_reconfig_region3_mailbox_request_word_is_exact_duplex) UT_ASSERT(cluster_reconfig_verify_replacement_committed_closed_async( &async, marker.target_node_id, (TimestampTz)UINT64_C(5000))); memset(slot, 0xa5, sizeof(slot)); - UT_ASSERT(cluster_reconfig_join_qvotec_poll_pending( - &operation, &target, slot)); - cluster_reconfig_join_qvotec_complete( - CLUSTER_JOIN_MARKER_MAILBOX_WRITE_EXACT, true, NULL); - UT_ASSERT_EQ(pg_atomic_read_u32(&state->join_marker_result), - CLUSTER_JOIN_MARKER_SUBMIT_FAILED); + UT_ASSERT(cluster_reconfig_join_qvotec_poll_pending(&operation, &target, slot)); + cluster_reconfig_join_qvotec_complete(CLUSTER_JOIN_MARKER_MAILBOX_WRITE_EXACT, true, NULL); + UT_ASSERT_EQ(pg_atomic_read_u32(&state->join_marker_result), CLUSTER_JOIN_MARKER_SUBMIT_FAILED); for (i = 0; i < CLUSTER_JCMK_REPLACEMENT_BYTES; i++) UT_ASSERT_EQ(state->join_pending_marker[i], 0); } @@ -5466,58 +5230,41 @@ UT_TEST(test_reconfig_qvotec_lifecycle_double_invalidates_mailboxes) memset(authority_zero, 0, sizeof(authority_zero)); pg_atomic_init_u32(&qvotec_status, CLUSTER_QVOTEC_READY); state->join_marker_request_word = UINT32_C(5); - memset(state->join_pending_marker, 0x5a, - sizeof(state->join_pending_marker)); - memcpy(payload_before, state->join_pending_marker, - sizeof(payload_before)); + memset(state->join_pending_marker, 0x5a, sizeof(state->join_pending_marker)); + memcpy(payload_before, state->join_pending_marker, sizeof(payload_before)); pg_atomic_write_u64(&state->join_marker_request_seq, UINT64_C(701)); pg_atomic_write_u64(&state->join_marker_completion_seq, UINT64_C(701)); - pg_atomic_write_u32(&state->join_marker_result, - CLUSTER_JOIN_MARKER_SUBMIT_ACK); + pg_atomic_write_u32(&state->join_marker_result, CLUSTER_JOIN_MARKER_SUBMIT_ACK); /* Poll transfers the persistent request to the old QVOTEC process. */ - UT_ASSERT(cluster_reconfig_join_qvotec_poll_pending( - &operation, &target, slot)); - UT_ASSERT_EQ((int)operation, - (int)CLUSTER_JOIN_MARKER_MAILBOX_WRITE_EXACT); + UT_ASSERT(cluster_reconfig_join_qvotec_poll_pending(&operation, &target, slot)); + UT_ASSERT_EQ((int)operation, (int)CLUSTER_JOIN_MARKER_MAILBOX_WRITE_EXACT); UT_ASSERT_EQ(target, 5); - UT_ASSERT(cluster_reconfig_qvotec_lifecycle_transition( - &authority_mailbox, &qvotec_status, - CLUSTER_QVOTEC_SHUTTING_DOWN)); - UT_ASSERT_EQ(pg_atomic_read_u32(&qvotec_status), - CLUSTER_QVOTEC_SHUTTING_DOWN); - UT_ASSERT_EQ(memcmp(&authority_mailbox, authority_zero, - sizeof(authority_mailbox)), 0); - UT_ASSERT_EQ(pg_atomic_read_u64(&state->join_marker_request_seq), - UINT64_C(701)); - UT_ASSERT_EQ(pg_atomic_read_u64(&state->join_marker_completion_seq), - UINT64_C(0)); - UT_ASSERT_EQ(pg_atomic_read_u32(&state->join_marker_result), - CLUSTER_JOIN_MARKER_SUBMIT_FAILED); + UT_ASSERT(cluster_reconfig_qvotec_lifecycle_transition(&authority_mailbox, &qvotec_status, + CLUSTER_QVOTEC_SHUTTING_DOWN)); + UT_ASSERT_EQ(pg_atomic_read_u32(&qvotec_status), CLUSTER_QVOTEC_SHUTTING_DOWN); + UT_ASSERT_EQ(memcmp(&authority_mailbox, authority_zero, sizeof(authority_mailbox)), 0); + UT_ASSERT_EQ(pg_atomic_read_u64(&state->join_marker_request_seq), UINT64_C(701)); + UT_ASSERT_EQ(pg_atomic_read_u64(&state->join_marker_completion_seq), UINT64_C(0)); + UT_ASSERT_EQ(pg_atomic_read_u32(&state->join_marker_result), CLUSTER_JOIN_MARKER_SUBMIT_FAILED); UT_ASSERT_EQ(state->join_marker_request_word, UINT32_C(5)); - UT_ASSERT_EQ(memcmp(state->join_pending_marker, payload_before, - sizeof(payload_before)), 0); + UT_ASSERT_EQ(memcmp(state->join_pending_marker, payload_before, sizeof(payload_before)), 0); /* The successor repeats the invalidation before publishing a latch. */ memset(&authority_mailbox, 0xa5, sizeof(authority_mailbox)); pg_atomic_write_u64(&state->join_marker_completion_seq, UINT64_C(701)); - pg_atomic_write_u32(&state->join_marker_result, - CLUSTER_JOIN_MARKER_SUBMIT_ACK); - UT_ASSERT(cluster_reconfig_qvotec_lifecycle_transition( - &authority_mailbox, &qvotec_status, CLUSTER_QVOTEC_STARTING)); - UT_ASSERT_EQ(pg_atomic_read_u32(&qvotec_status), - CLUSTER_QVOTEC_STARTING); - UT_ASSERT_EQ(memcmp(&authority_mailbox, authority_zero, - sizeof(authority_mailbox)), 0); - UT_ASSERT_EQ(pg_atomic_read_u64(&state->join_marker_completion_seq), - UINT64_C(0)); - - UT_ASSERT(cluster_reconfig_qvotec_lifecycle_transition( - &authority_mailbox, &qvotec_status, CLUSTER_QVOTEC_READY)); + pg_atomic_write_u32(&state->join_marker_result, CLUSTER_JOIN_MARKER_SUBMIT_ACK); + UT_ASSERT(cluster_reconfig_qvotec_lifecycle_transition(&authority_mailbox, &qvotec_status, + CLUSTER_QVOTEC_STARTING)); + UT_ASSERT_EQ(pg_atomic_read_u32(&qvotec_status), CLUSTER_QVOTEC_STARTING); + UT_ASSERT_EQ(memcmp(&authority_mailbox, authority_zero, sizeof(authority_mailbox)), 0); + UT_ASSERT_EQ(pg_atomic_read_u64(&state->join_marker_completion_seq), UINT64_C(0)); + + UT_ASSERT(cluster_reconfig_qvotec_lifecycle_transition(&authority_mailbox, &qvotec_status, + CLUSTER_QVOTEC_READY)); UT_ASSERT_EQ(pg_atomic_read_u32(&qvotec_status), CLUSTER_QVOTEC_READY); - UT_ASSERT(cluster_reconfig_join_qvotec_poll_pending( - &operation, &target, slot)); + UT_ASSERT(cluster_reconfig_join_qvotec_poll_pending(&operation, &target, slot)); UT_ASSERT_EQ(target, 5); UT_ASSERT_EQ(memcmp(slot, payload_before, sizeof(payload_before)), 0); cluster_reconfig_join_qvotec_complete(operation, false, NULL); @@ -5538,17 +5285,15 @@ UT_TEST(test_reconfig_target_refuses_ready_without_startup_closure_proof) episode = ut_admitted_replacement_episode(cluster_node_id); episode.phase = CLUSTER_REPLACEMENT_EPISODE_COMMITTED_CLOSED; episode.state_generation = UINT32_C(17); - episode.readiness_flags - = CLUSTER_REPLACEMENT_EPISODE_GRD_POSTEPOCH_READY - | CLUSTER_REPLACEMENT_EPISODE_INTENT_CLEARED; + episode.readiness_flags = CLUSTER_REPLACEMENT_EPISODE_GRD_POSTEPOCH_READY + | CLUSTER_REPLACEMENT_EPISODE_INTENT_CLEARED; state->replacement_episode = episode; state->self_join_admitted = 0; cluster_membership_set_state(1, CLUSTER_MEMBER_MEMBER); cluster_membership_set_state(2, CLUSTER_MEMBER_MEMBER); epoch_init_done = false; cluster_epoch_shmem_init(); - UT_ASSERT(cluster_epoch_observe_remote( - episode.reserved_or_committed_epoch)); + UT_ASSERT(cluster_epoch_observe_remote(episode.reserved_or_committed_epoch)); memset(&marker, 0, sizeof(marker)); marker.magic = CLUSTER_JCMK_MAGIC; @@ -5559,8 +5304,7 @@ UT_TEST(test_reconfig_target_refuses_ready_without_startup_closure_proof) marker.old_admitted_incarnation = episode.old_admitted_incarnation; marker.fresh_incarnation = episode.fresh_incarnation; marker.baseline_epoch = episode.baseline_epoch; - marker.reserved_or_committed_epoch - = episode.reserved_or_committed_epoch; + marker.reserved_or_committed_epoch = episode.reserved_or_committed_epoch; marker.request_nonce = episode.request_nonce; memcpy(marker.expected_purge_survivors, episode.expected_survivors, sizeof(marker.expected_purge_survivors)); @@ -5569,8 +5313,7 @@ UT_TEST(test_reconfig_target_refuses_ready_without_startup_closure_proof) memcpy(state->join_pending_marker, marker_image, sizeof(marker_image)); pg_atomic_write_u64(&state->join_marker_request_seq, UINT64_C(900)); pg_atomic_write_u64(&state->join_marker_completion_seq, UINT64_C(900)); - pg_atomic_write_u32(&state->join_marker_result, - CLUSTER_JOIN_MARKER_SUBMIT_ACK); + pg_atomic_write_u32(&state->join_marker_result, CLUSTER_JOIN_MARKER_SUBMIT_ACK); memset(&expected, 0, sizeof(expected)); expected.status = CLUSTER_R4_PREREQUISITE_R4A_READY; @@ -5585,10 +5328,8 @@ UT_TEST(test_reconfig_target_refuses_ready_without_startup_closure_proof) expected.grammar_fingerprint = episode.grammar_fingerprint; UT_ASSERT(!cluster_reconfig_r4_publish_ready(&expected)); - UT_ASSERT_EQ(state->replacement_episode.state_generation, - episode.state_generation); - UT_ASSERT_EQ(state->replacement_episode.readiness_flags, - episode.readiness_flags); + UT_ASSERT_EQ(state->replacement_episode.state_generation, episode.state_generation); + UT_ASSERT_EQ(state->replacement_episode.readiness_flags, episode.readiness_flags); observed = cluster_reconfig_r4_prerequisite_snapshot(); UT_ASSERT_EQ(observed.status, CLUSTER_R4_PREREQUISITE_RF_DEFERRED); UT_ASSERT(!observed.ready); @@ -5618,14 +5359,12 @@ UT_TEST(test_reconfig_phase3_observation_sets_only_existing_ready_bit) episode = ut_admitted_replacement_episode(3); episode.phase = CLUSTER_REPLACEMENT_EPISODE_COMMITTED_CLOSED; episode.state_generation = UINT32_C(17); - episode.readiness_flags - = CLUSTER_REPLACEMENT_EPISODE_GRD_POSTEPOCH_READY - | CLUSTER_REPLACEMENT_EPISODE_INTENT_CLEARED; + episode.readiness_flags = CLUSTER_REPLACEMENT_EPISODE_GRD_POSTEPOCH_READY + | CLUSTER_REPLACEMENT_EPISODE_INTENT_CLEARED; state->replacement_episode = episode; epoch_init_done = false; cluster_epoch_shmem_init(); - UT_ASSERT(cluster_epoch_observe_remote( - episode.reserved_or_committed_epoch)); + UT_ASSERT(cluster_epoch_observe_remote(episode.reserved_or_committed_epoch)); memset(&marker, 0, sizeof(marker)); marker.magic = CLUSTER_JCMK_MAGIC; @@ -5643,37 +5382,32 @@ UT_TEST(test_reconfig_phase3_observation_sets_only_existing_ready_bit) marker.grammar_fingerprint = episode.grammar_fingerprint; cluster_marker_async_init(&async); UT_ASSERT(cluster_reconfig_submit_replacement_marker_v3_async( - &async, marker.target_node_id, &marker, - CLUSTER_MARKER_KIND_JOIN_COMMITTED, (TimestampTz)UINT64_C(2000))); + &async, marker.target_node_id, &marker, CLUSTER_MARKER_KIND_JOIN_COMMITTED, + (TimestampTz)UINT64_C(2000))); UT_ASSERT(ut_join_qvotec_poll_write_pending(&target, slot)); UT_ASSERT_EQ(target, marker.target_node_id); ut_join_qvotec_complete_write(true); memset(&item, 0, sizeof(item)); - item.message.phase - = CLUSTER_REPLACEMENT_WIRE_PHASE_TARGET_RECOVERY_READY; + item.message.phase = CLUSTER_REPLACEMENT_WIRE_PHASE_TARGET_RECOVERY_READY; item.message.target_node_id = episode.target_node_id; item.message.epoch = episode.baseline_epoch; item.message.request_nonce = episode.request_nonce; item.message.identity0 = episode.old_admitted_incarnation; item.message.identity1 = episode.fresh_incarnation; item.message.body.phase3.jcmk_generation = marker.generation; - item.message.body.phase3.episode_state_generation - = episode.state_generation; + item.message.body.phase3.episode_state_generation = episode.state_generation; item.message.grammar_fingerprint = episode.grammar_fingerprint; item.authenticated_source_node_id = episode.target_node_id; item.local_receiver_node_id = episode.coordinator_node_id; item.control_connection_generation = UINT32_C(9); UT_ASSERT(cluster_reconfig_lmon_observe_replacement_ready(&item)); - UT_ASSERT_EQ(state->replacement_episode.phase, - CLUSTER_REPLACEMENT_EPISODE_COMMITTED_CLOSED); - UT_ASSERT_EQ(state->replacement_episode.state_generation, - episode.state_generation); + UT_ASSERT_EQ(state->replacement_episode.phase, CLUSTER_REPLACEMENT_EPISODE_COMMITTED_CLOSED); + UT_ASSERT_EQ(state->replacement_episode.state_generation, episode.state_generation); UT_ASSERT_EQ(state->replacement_episode.readiness_flags, CLUSTER_REPLACEMENT_EPISODE_READINESS_MASK); - UT_ASSERT_EQ((int)cluster_reconfig_self_join_gate_verdict(), - (int)gate_before); + UT_ASSERT_EQ((int)cluster_reconfig_self_join_gate_verdict(), (int)gate_before); } /* Building ADMITTED is a zero-mutation derivation from three exact durable @@ -5701,8 +5435,7 @@ UT_TEST(test_reconfig_builds_admitted_only_from_terminal_same_episode) cluster_membership_set_state(2, CLUSTER_MEMBER_MEMBER); epoch_init_done = false; cluster_epoch_shmem_init(); - UT_ASSERT(cluster_epoch_observe_remote( - episode.reserved_or_committed_epoch)); + UT_ASSERT(cluster_epoch_observe_remote(episode.reserved_or_committed_epoch)); memset(&committed, 0, sizeof(committed)); committed.magic = CLUSTER_JCMK_MAGIC; @@ -5713,20 +5446,16 @@ UT_TEST(test_reconfig_builds_admitted_only_from_terminal_same_episode) committed.old_admitted_incarnation = episode.old_admitted_incarnation; committed.fresh_incarnation = episode.fresh_incarnation; committed.baseline_epoch = episode.baseline_epoch; - committed.reserved_or_committed_epoch - = episode.reserved_or_committed_epoch; + committed.reserved_or_committed_epoch = episode.reserved_or_committed_epoch; committed.request_nonce = episode.request_nonce; memcpy(committed.expected_purge_survivors, episode.expected_survivors, sizeof(committed.expected_purge_survivors)); committed.grammar_fingerprint = episode.grammar_fingerprint; - UT_ASSERT(cluster_replacement_marker_v3_encode( - &committed, committed_image)); - memcpy(state->join_pending_marker, committed_image, - sizeof(committed_image)); + UT_ASSERT(cluster_replacement_marker_v3_encode(&committed, committed_image)); + memcpy(state->join_pending_marker, committed_image, sizeof(committed_image)); pg_atomic_write_u64(&state->join_marker_request_seq, UINT64_C(9)); pg_atomic_write_u64(&state->join_marker_completion_seq, UINT64_C(9)); - pg_atomic_write_u32(&state->join_marker_result, - CLUSTER_JOIN_MARKER_SUBMIT_ACK); + pg_atomic_write_u32(&state->join_marker_result, CLUSTER_JOIN_MARKER_SUBMIT_ACK); memset(&head, 0, sizeof(head)); head.value_version = CLUSTER_EPOCH_AUTHORITY_VALUE_VERSION; @@ -5745,96 +5474,71 @@ UT_TEST(test_reconfig_builds_admitted_only_from_terminal_same_episode) head.event_subject_bitmap[episode.target_node_id / 8] = (uint8)(1u << (episode.target_node_id % 8)); head.grammar_fingerprint = episode.grammar_fingerprint; - memset(head.predecessor_digest, 0x5a, - sizeof(head.predecessor_digest)); + memset(head.predecessor_digest, 0x5a, sizeof(head.predecessor_digest)); cluster_membership_set_state(2, CLUSTER_MEMBER_ABSENT); memset(&admitted, 0, sizeof(admitted)); - UT_ASSERT(!cluster_reconfig_lmon_build_replacement_admitted( - &head, &admitted)); + UT_ASSERT(!cluster_reconfig_lmon_build_replacement_admitted(&head, &admitted)); UT_ASSERT_EQ((int)admitted.phase, 0); cluster_membership_set_state(2, CLUSTER_MEMBER_MEMBER); - cluster_membership_set_state(episode.target_node_id, - CLUSTER_MEMBER_MEMBER); - UT_ASSERT(!cluster_reconfig_lmon_build_replacement_admitted( - &head, &admitted)); + cluster_membership_set_state(episode.target_node_id, CLUSTER_MEMBER_MEMBER); + UT_ASSERT(!cluster_reconfig_lmon_build_replacement_admitted(&head, &admitted)); UT_ASSERT_EQ((int)admitted.phase, 0); - cluster_membership_set_state(episode.target_node_id, - CLUSTER_MEMBER_ABSENT); + cluster_membership_set_state(episode.target_node_id, CLUSTER_MEMBER_ABSENT); cluster_membership_set_state(4, CLUSTER_MEMBER_MEMBER); - UT_ASSERT(!cluster_reconfig_lmon_build_replacement_admitted( - &head, &admitted)); + UT_ASSERT(!cluster_reconfig_lmon_build_replacement_admitted(&head, &admitted)); UT_ASSERT_EQ((int)admitted.phase, 0); cluster_membership_set_state(4, CLUSTER_MEMBER_ABSENT); ut_candidate2_capable[episode.target_node_id] = false; memset(&admitted, 0, sizeof(admitted)); - UT_ASSERT(!cluster_reconfig_lmon_build_replacement_admitted( - &head, &admitted)); + UT_ASSERT(!cluster_reconfig_lmon_build_replacement_admitted(&head, &admitted)); UT_ASSERT_EQ((int)admitted.phase, 0); ut_candidate2_capable[episode.target_node_id] = true; ut_candidate2_capable[2] = false; - UT_ASSERT(!cluster_reconfig_lmon_build_replacement_admitted( - &head, &admitted)); + UT_ASSERT(!cluster_reconfig_lmon_build_replacement_admitted(&head, &admitted)); UT_ASSERT_EQ((int)admitted.phase, 0); ut_candidate2_capable[2] = true; memset(&admitted, 0, sizeof(admitted)); - UT_ASSERT(cluster_reconfig_lmon_build_replacement_admitted( - &head, &admitted)); - UT_ASSERT_EQ((int)admitted.phase, - CLUSTER_JCMK_REPLACEMENT_PHASE_ADMITTED); + UT_ASSERT(cluster_reconfig_lmon_build_replacement_admitted(&head, &admitted)); + UT_ASSERT_EQ((int)admitted.phase, CLUSTER_JCMK_REPLACEMENT_PHASE_ADMITTED); UT_ASSERT_EQ(admitted.generation, committed.generation + 1); - UT_ASSERT_EQ(admitted.ready_state_generation, - episode.state_generation); + UT_ASSERT_EQ(admitted.ready_state_generation, episode.state_generation); built = admitted; - UT_ASSERT_EQ(state->replacement_episode.phase, - CLUSTER_REPLACEMENT_EPISODE_COMMITTED_CLOSED); - UT_ASSERT_EQ((int)cluster_reconfig_self_join_gate_verdict(), - (int)CLUSTER_JOIN_GATE_ALLOW); + UT_ASSERT_EQ(state->replacement_episode.phase, CLUSTER_REPLACEMENT_EPISODE_COMMITTED_CLOSED); + UT_ASSERT_EQ((int)cluster_reconfig_self_join_gate_verdict(), (int)CLUSTER_JOIN_GATE_ALLOW); head.request_nonce++; memset(&admitted, 0, sizeof(admitted)); - UT_ASSERT(!cluster_reconfig_lmon_build_replacement_admitted( - &head, &admitted)); + UT_ASSERT(!cluster_reconfig_lmon_build_replacement_admitted(&head, &admitted)); UT_ASSERT_EQ((int)admitted.phase, 0); head.request_nonce--; - UT_ASSERT(cluster_replacement_marker_v3_encode( - &built, committed_image)); - memcpy(state->join_pending_marker, committed_image, - sizeof(committed_image)); + UT_ASSERT(cluster_replacement_marker_v3_encode(&built, committed_image)); + memcpy(state->join_pending_marker, committed_image, sizeof(committed_image)); pg_atomic_write_u64(&state->join_marker_request_seq, UINT64_C(10)); pg_atomic_write_u64(&state->join_marker_completion_seq, UINT64_C(10)); - pg_atomic_write_u32(&state->join_marker_result, - CLUSTER_JOIN_MARKER_SUBMIT_ACK); + pg_atomic_write_u32(&state->join_marker_result, CLUSTER_JOIN_MARKER_SUBMIT_ACK); ut_candidate2_capable[episode.target_node_id] = false; - UT_ASSERT(!cluster_reconfig_lmon_finalize_replacement_admitted( - &head, &built)); - UT_ASSERT_EQ(state->replacement_episode.phase, - CLUSTER_REPLACEMENT_EPISODE_COMMITTED_CLOSED); + UT_ASSERT(!cluster_reconfig_lmon_finalize_replacement_admitted(&head, &built)); + UT_ASSERT_EQ(state->replacement_episode.phase, CLUSTER_REPLACEMENT_EPISODE_COMMITTED_CLOSED); UT_ASSERT_EQ((int)cluster_membership_get_state(episode.target_node_id), (int)CLUSTER_MEMBER_ABSENT); ut_candidate2_capable[episode.target_node_id] = true; ut_candidate2_capable[2] = false; - UT_ASSERT(!cluster_reconfig_lmon_finalize_replacement_admitted( - &head, &built)); - UT_ASSERT_EQ(state->replacement_episode.phase, - CLUSTER_REPLACEMENT_EPISODE_COMMITTED_CLOSED); + UT_ASSERT(!cluster_reconfig_lmon_finalize_replacement_admitted(&head, &built)); + UT_ASSERT_EQ(state->replacement_episode.phase, CLUSTER_REPLACEMENT_EPISODE_COMMITTED_CLOSED); UT_ASSERT_EQ((int)cluster_membership_get_state(episode.target_node_id), (int)CLUSTER_MEMBER_ABSENT); ut_candidate2_capable[2] = true; - UT_ASSERT(cluster_reconfig_lmon_finalize_replacement_admitted( - &head, &built)); - UT_ASSERT_EQ(state->replacement_episode.phase, - CLUSTER_REPLACEMENT_EPISODE_ADMITTED); + UT_ASSERT(cluster_reconfig_lmon_finalize_replacement_admitted(&head, &built)); + UT_ASSERT_EQ(state->replacement_episode.phase, CLUSTER_REPLACEMENT_EPISODE_ADMITTED); UT_ASSERT_EQ((int)cluster_membership_get_state(episode.target_node_id), (int)CLUSTER_MEMBER_MEMBER); - UT_ASSERT_EQ(cluster_membership_get_last_admitted_incarnation( - episode.target_node_id), + UT_ASSERT_EQ(cluster_membership_get_last_admitted_incarnation(episode.target_node_id), episode.fresh_incarnation); - UT_ASSERT_EQ((int)cluster_reconfig_self_join_gate_verdict(), - (int)CLUSTER_JOIN_GATE_ALLOW); + UT_ASSERT_EQ((int)cluster_reconfig_self_join_gate_verdict(), (int)CLUSTER_JOIN_GATE_ALLOW); } /* The formation LMON actor may publish ADMITTED/MEMBER only between two exact @@ -5868,8 +5572,7 @@ UT_TEST(test_reconfig_lmon_admits_between_identical_terminal_head_reads) cluster_membership_set_state(2, CLUSTER_MEMBER_MEMBER); epoch_init_done = false; cluster_epoch_shmem_init(); - UT_ASSERT(cluster_epoch_observe_remote( - episode.reserved_or_committed_epoch)); + UT_ASSERT(cluster_epoch_observe_remote(episode.reserved_or_committed_epoch)); memset(&committed, 0, sizeof(committed)); committed.magic = CLUSTER_JCMK_MAGIC; @@ -5880,20 +5583,16 @@ UT_TEST(test_reconfig_lmon_admits_between_identical_terminal_head_reads) committed.old_admitted_incarnation = episode.old_admitted_incarnation; committed.fresh_incarnation = episode.fresh_incarnation; committed.baseline_epoch = episode.baseline_epoch; - committed.reserved_or_committed_epoch - = episode.reserved_or_committed_epoch; + committed.reserved_or_committed_epoch = episode.reserved_or_committed_epoch; committed.request_nonce = episode.request_nonce; memcpy(committed.expected_purge_survivors, episode.expected_survivors, sizeof(committed.expected_purge_survivors)); committed.grammar_fingerprint = episode.grammar_fingerprint; - UT_ASSERT(cluster_replacement_marker_v3_encode( - &committed, committed_image)); - memcpy(state->join_pending_marker, committed_image, - sizeof(committed_image)); + UT_ASSERT(cluster_replacement_marker_v3_encode(&committed, committed_image)); + memcpy(state->join_pending_marker, committed_image, sizeof(committed_image)); pg_atomic_write_u64(&state->join_marker_request_seq, UINT64_C(9)); pg_atomic_write_u64(&state->join_marker_completion_seq, UINT64_C(9)); - pg_atomic_write_u32(&state->join_marker_result, - CLUSTER_JOIN_MARKER_SUBMIT_ACK); + pg_atomic_write_u32(&state->join_marker_result, CLUSTER_JOIN_MARKER_SUBMIT_ACK); memset(&head, 0, sizeof(head)); head.value_version = CLUSTER_EPOCH_AUTHORITY_VALUE_VERSION; @@ -5912,10 +5611,9 @@ UT_TEST(test_reconfig_lmon_admits_between_identical_terminal_head_reads) head.event_subject_bitmap[episode.target_node_id / 8] = (uint8)(1u << (episode.target_node_id % 8)); head.grammar_fingerprint = episode.grammar_fingerprint; - memset(head.predecessor_digest, 0x5a, - sizeof(head.predecessor_digest)); - UT_ASSERT(cluster_epoch_authority_value_encode( - &head, CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT, head_image)); + memset(head.predecessor_digest, 0x5a, sizeof(head.predecessor_digest)); + UT_ASSERT(cluster_epoch_authority_value_encode(&head, CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT, + head_image)); memset(&ballot, 0, sizeof(ballot)); ballot.counter = UINT64_C(7); @@ -5927,12 +5625,9 @@ UT_TEST(test_reconfig_lmon_admits_between_identical_terminal_head_reads) memset(&ut_authority_completion, 0, sizeof(ut_authority_completion)); ut_authority_completion.request_seq = UINT64_C(2); ut_authority_completion.result = CLUSTER_QVOTEC_MAILBOX_CHOSEN; - memcpy(ut_authority_completion.completion_value, head_image, - sizeof(head_image)); - memcpy(ut_authority_completion.completion_ballot, ballot_image, - sizeof(ballot_image)); - ut_authority_completion.actor_phase - = CLUSTER_QVOTEC_ACTOR_RECOVER_SCAN_B; + memcpy(ut_authority_completion.completion_value, head_image, sizeof(head_image)); + memcpy(ut_authority_completion.completion_ballot, ballot_image, sizeof(ballot_image)); + ut_authority_completion.actor_phase = CLUSTER_QVOTEC_ACTOR_RECOVER_SCAN_B; cluster_reconfig_lmon_replacement_admit_tick(); /* submit pre-read */ UT_ASSERT_EQ(ut_authority_submit_calls, 1); @@ -5944,10 +5639,8 @@ UT_TEST(test_reconfig_lmon_admits_between_identical_terminal_head_reads) if (ut_join_qvotec_poll_write_pending(&target, slot)) { ClusterReplacementCommitMarkerV3 observed; - UT_ASSERT(cluster_replacement_marker_v3_decode( - slot, episode.target_node_id, &observed)); - UT_ASSERT(observed.phase - != CLUSTER_JCMK_REPLACEMENT_PHASE_ADMITTED); + UT_ASSERT(cluster_replacement_marker_v3_decode(slot, episode.target_node_id, &observed)); + UT_ASSERT(observed.phase != CLUSTER_JCMK_REPLACEMENT_PHASE_ADMITTED); ut_join_qvotec_complete_write(true); } UT_ASSERT_EQ((int)state->replacement_episode.phase, @@ -5963,13 +5656,11 @@ UT_TEST(test_reconfig_lmon_admits_between_identical_terminal_head_reads) memset(slot, 0, sizeof(slot)); UT_ASSERT(ut_join_qvotec_poll_write_pending(&target, slot)); UT_ASSERT_EQ(target, episode.target_node_id); - UT_ASSERT(cluster_replacement_marker_v3_decode( - slot, episode.target_node_id, &durable_admitted)); - UT_ASSERT_EQ((int)durable_admitted.phase, - (int)CLUSTER_JCMK_REPLACEMENT_PHASE_ADMITTED); + UT_ASSERT( + cluster_replacement_marker_v3_decode(slot, episode.target_node_id, &durable_admitted)); + UT_ASSERT_EQ((int)durable_admitted.phase, (int)CLUSTER_JCMK_REPLACEMENT_PHASE_ADMITTED); UT_ASSERT_EQ(durable_admitted.generation, committed.generation + 1); - UT_ASSERT_EQ(durable_admitted.ready_state_generation, - episode.state_generation); + UT_ASSERT_EQ(durable_admitted.ready_state_generation, episode.state_generation); ut_join_qvotec_complete_write(true); cluster_reconfig_lmon_replacement_admit_tick(); /* observe ADMITTED ACK */ @@ -5979,15 +5670,12 @@ UT_TEST(test_reconfig_lmon_admits_between_identical_terminal_head_reads) ut_authority_completion_ready = true; cluster_reconfig_lmon_replacement_admit_tick(); /* consume + publish */ - UT_ASSERT_EQ((int)state->replacement_episode.phase, - (int)CLUSTER_REPLACEMENT_EPISODE_ADMITTED); + UT_ASSERT_EQ((int)state->replacement_episode.phase, (int)CLUSTER_REPLACEMENT_EPISODE_ADMITTED); UT_ASSERT_EQ((int)cluster_membership_get_state(episode.target_node_id), (int)CLUSTER_MEMBER_MEMBER); - UT_ASSERT_EQ(cluster_membership_get_last_admitted_incarnation( - episode.target_node_id), + UT_ASSERT_EQ(cluster_membership_get_last_admitted_incarnation(episode.target_node_id), episode.fresh_incarnation); - UT_ASSERT_EQ((int)cluster_reconfig_self_join_gate_verdict(), - (int)CLUSTER_JOIN_GATE_ALLOW); + UT_ASSERT_EQ((int)cluster_reconfig_self_join_gate_verdict(), (int)CLUSTER_JOIN_GATE_ALLOW); } UT_TEST(test_reconfig_lmon_closed_apply_consumes_recovered_verify_pair) @@ -6019,8 +5707,7 @@ UT_TEST(test_reconfig_lmon_closed_apply_consumes_recovered_verify_pair) cluster_membership_set_state(1, CLUSTER_MEMBER_MEMBER); cluster_membership_set_state(2, CLUSTER_MEMBER_MEMBER); cluster_membership_record_admitted(1, UINT64_C(111)); - cluster_membership_record_admitted( - episode.target_node_id, episode.old_admitted_incarnation); + cluster_membership_record_admitted(episode.target_node_id, episode.old_admitted_incarnation); epoch_init_done = false; cluster_epoch_shmem_init(); UT_ASSERT(cluster_epoch_observe_remote(episode.baseline_epoch)); @@ -6034,14 +5721,12 @@ UT_TEST(test_reconfig_lmon_closed_apply_consumes_recovered_verify_pair) committed.old_admitted_incarnation = episode.old_admitted_incarnation; committed.fresh_incarnation = episode.fresh_incarnation; committed.baseline_epoch = episode.baseline_epoch; - committed.reserved_or_committed_epoch - = episode.reserved_or_committed_epoch; + committed.reserved_or_committed_epoch = episode.reserved_or_committed_epoch; committed.request_nonce = episode.request_nonce; memcpy(committed.expected_purge_survivors, episode.expected_survivors, sizeof(committed.expected_purge_survivors)); committed.grammar_fingerprint = episode.grammar_fingerprint; - UT_ASSERT(cluster_replacement_marker_v3_encode( - &committed, committed_image)); + UT_ASSERT(cluster_replacement_marker_v3_encode(&committed, committed_image)); memset(&head, 0, sizeof(head)); head.value_version = CLUSTER_EPOCH_AUTHORITY_VALUE_VERSION; @@ -6060,10 +5745,9 @@ UT_TEST(test_reconfig_lmon_closed_apply_consumes_recovered_verify_pair) head.event_subject_bitmap[episode.target_node_id / 8] = (uint8)(1u << (episode.target_node_id % 8)); head.grammar_fingerprint = episode.grammar_fingerprint; - memset(head.predecessor_digest, 0x5a, - sizeof(head.predecessor_digest)); - UT_ASSERT(cluster_epoch_authority_value_encode( - &head, CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT, head_image)); + memset(head.predecessor_digest, 0x5a, sizeof(head.predecessor_digest)); + UT_ASSERT(cluster_epoch_authority_value_encode(&head, CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT, + head_image)); memset(&ballot, 0, sizeof(ballot)); ballot.counter = UINT64_C(7); @@ -6074,47 +5758,36 @@ UT_TEST(test_reconfig_lmon_closed_apply_consumes_recovered_verify_pair) cluster_reconfig_lmon_replacement_closed_tick(); UT_ASSERT_EQ(ut_authority_submit_calls, 1); - UT_ASSERT(cluster_reconfig_join_qvotec_poll_pending( - &operation, &target, slot)); - UT_ASSERT_EQ((int)operation, - (int)CLUSTER_JOIN_MARKER_MAILBOX_VERIFY_COMMITTED_CLOSED); + UT_ASSERT(cluster_reconfig_join_qvotec_poll_pending(&operation, &target, slot)); + UT_ASSERT_EQ((int)operation, (int)CLUSTER_JOIN_MARKER_MAILBOX_VERIFY_COMMITTED_CLOSED); UT_ASSERT_EQ(target, episode.target_node_id); cluster_reconfig_join_qvotec_complete(operation, true, committed_image); cluster_marker_async_init(&conflicting_marker); UT_ASSERT(!cluster_reconfig_submit_replacement_marker_v3_async( - &conflicting_marker, episode.target_node_id, &committed, - CLUSTER_MARKER_KIND_JOIN_COMMITTED, + &conflicting_marker, episode.target_node_id, &committed, CLUSTER_MARKER_KIND_JOIN_COMMITTED, (TimestampTz)UINT64_C(8000))); - memset(&ut_authority_completion, 0, - sizeof(ut_authority_completion)); + memset(&ut_authority_completion, 0, sizeof(ut_authority_completion)); ut_authority_completion.request_seq = UINT64_C(2); ut_authority_completion.result = CLUSTER_QVOTEC_MAILBOX_CHOSEN; - memcpy(ut_authority_completion.completion_value, head_image, - sizeof(head_image)); - memcpy(ut_authority_completion.completion_ballot, ballot_image, - sizeof(ballot_image)); - ut_authority_completion.actor_phase - = CLUSTER_QVOTEC_ACTOR_RECOVER_SCAN_B; + memcpy(ut_authority_completion.completion_value, head_image, sizeof(head_image)); + memcpy(ut_authority_completion.completion_ballot, ballot_image, sizeof(ballot_image)); + ut_authority_completion.actor_phase = CLUSTER_QVOTEC_ACTOR_RECOVER_SCAN_B; ut_authority_completion_ready = true; cluster_reconfig_lmon_replacement_closed_tick(); UT_ASSERT_EQ((int)state->replacement_episode.phase, (int)CLUSTER_REPLACEMENT_EPISODE_COMMITTED_CLOSED); - UT_ASSERT_EQ(state->replacement_episode.state_generation, - UINT32_C(18)); - UT_ASSERT_EQ(cluster_epoch_get_current(), - episode.reserved_or_committed_epoch); + UT_ASSERT_EQ(state->replacement_episode.state_generation, UINT32_C(18)); + UT_ASSERT_EQ(cluster_epoch_get_current(), episode.reserved_or_committed_epoch); cluster_reconfig_get_last_event(&event); - UT_ASSERT_EQ((int)event.reconfig_kind, - (int)RECONFIG_KIND_REPLACEMENT_COMMITTED); + UT_ASSERT_EQ((int)event.reconfig_kind, (int)RECONFIG_KIND_REPLACEMENT_COMMITTED); UT_ASSERT_EQ(event.old_epoch, episode.baseline_epoch); UT_ASSERT_EQ(event.new_epoch, episode.reserved_or_committed_epoch); - UT_ASSERT_EQ((int)event.observer_role, - (int)CLUSTER_RECONFIG_OBSERVER_SURVIVOR); + UT_ASSERT_EQ((int)event.observer_role, (int)CLUSTER_RECONFIG_OBSERVER_SURVIVOR); UT_ASSERT_EQ((int)cluster_reconfig_lmon_publish_replacement_committed_closed( - UINT64_C(2), pg_atomic_read_u64(&state->join_marker_request_seq)), - (int)CLUSTER_REPLACEMENT_CLOSED_RETRY); + UINT64_C(2), pg_atomic_read_u64(&state->join_marker_request_seq)), + (int)CLUSTER_REPLACEMENT_CLOSED_RETRY); } /* Target QVOTEC must not infer replacement membership from one disk, a v2 @@ -6136,18 +5809,17 @@ UT_TEST(test_reconfig_qvotec_majority_admitted_publishes_member_closed) state->replacement_episode = episode; epoch_init_done = false; cluster_epoch_shmem_init(); - UT_ASSERT(cluster_epoch_observe_remote( - episode.reserved_or_committed_epoch)); + UT_ASSERT(cluster_epoch_observe_remote(episode.reserved_or_committed_epoch)); /* The immutable expected survivor set {1,2} has published E+1. */ ut_declared_set[1] = true; ut_declared_set[2] = true; cluster_membership_set_state(1, CLUSTER_MEMBER_MEMBER); cluster_membership_set_state(2, CLUSTER_MEMBER_MEMBER); - cluster_reconfig_record_observed_slot( - 1, UINT64_C(101), UINT64_C(1), episode.reserved_or_committed_epoch); - cluster_reconfig_record_observed_slot( - 2, UINT64_C(102), UINT64_C(1), episode.reserved_or_committed_epoch); + cluster_reconfig_record_observed_slot(1, UINT64_C(101), UINT64_C(1), + episode.reserved_or_committed_epoch); + cluster_reconfig_record_observed_slot(2, UINT64_C(102), UINT64_C(1), + episode.reserved_or_committed_epoch); memset(&admitted, 0, sizeof(admitted)); admitted.magic = CLUSTER_JCMK_MAGIC; @@ -6158,43 +5830,37 @@ UT_TEST(test_reconfig_qvotec_majority_admitted_publishes_member_closed) admitted.old_admitted_incarnation = episode.old_admitted_incarnation; admitted.fresh_incarnation = episode.fresh_incarnation; admitted.baseline_epoch = episode.baseline_epoch; - admitted.reserved_or_committed_epoch - = episode.reserved_or_committed_epoch; + admitted.reserved_or_committed_epoch = episode.reserved_or_committed_epoch; admitted.request_nonce = episode.request_nonce; memcpy(admitted.expected_purge_survivors, episode.expected_survivors, sizeof(admitted.expected_purge_survivors)); admitted.grammar_fingerprint = episode.grammar_fingerprint; admitted.ready_state_generation = episode.state_generation; - UT_ASSERT(cluster_replacement_marker_v3_encode( - &admitted, admitted_image)); + UT_ASSERT(cluster_replacement_marker_v3_encode(&admitted, admitted_image)); memcpy(ut_join_disk_images[0], admitted_image, sizeof(admitted_image)); memcpy(ut_join_disk_images[1], admitted_image, sizeof(admitted_image)); ut_join_disk_readable[0] = true; - UT_ASSERT(!cluster_reconfig_qvotec_observe_replacement_admitted( - fds, 3, episode.fresh_incarnation)); + UT_ASSERT( + !cluster_reconfig_qvotec_observe_replacement_admitted(fds, 3, episode.fresh_incarnation)); UT_ASSERT_EQ((int)state->replacement_episode.phase, (int)CLUSTER_REPLACEMENT_EPISODE_POST_EPOCH); - UT_ASSERT_EQ((int)cluster_membership_get_state(cluster_node_id), - (int)CLUSTER_MEMBER_ABSENT); + UT_ASSERT_EQ((int)cluster_membership_get_state(cluster_node_id), (int)CLUSTER_MEMBER_ABSENT); ut_join_disk_readable[1] = true; - UT_ASSERT(!cluster_reconfig_qvotec_observe_replacement_admitted( - fds, 3, episode.fresh_incarnation + 1)); + UT_ASSERT(!cluster_reconfig_qvotec_observe_replacement_admitted(fds, 3, + episode.fresh_incarnation + 1)); ut_candidate2_capable[2] = false; - UT_ASSERT(!cluster_reconfig_qvotec_observe_replacement_admitted( - fds, 3, episode.fresh_incarnation)); + UT_ASSERT( + !cluster_reconfig_qvotec_observe_replacement_admitted(fds, 3, episode.fresh_incarnation)); UT_ASSERT_EQ((int)state->replacement_episode.phase, (int)CLUSTER_REPLACEMENT_EPISODE_POST_EPOCH); - UT_ASSERT_EQ((int)cluster_membership_get_state(cluster_node_id), - (int)CLUSTER_MEMBER_ABSENT); + UT_ASSERT_EQ((int)cluster_membership_get_state(cluster_node_id), (int)CLUSTER_MEMBER_ABSENT); ut_candidate2_capable[2] = true; - UT_ASSERT(cluster_reconfig_qvotec_observe_replacement_admitted( - fds, 3, episode.fresh_incarnation)); - UT_ASSERT_EQ((int)state->replacement_episode.phase, - (int)CLUSTER_REPLACEMENT_EPISODE_ADMITTED); - UT_ASSERT_EQ((int)cluster_membership_get_state(cluster_node_id), - (int)CLUSTER_MEMBER_MEMBER); + UT_ASSERT( + cluster_reconfig_qvotec_observe_replacement_admitted(fds, 3, episode.fresh_incarnation)); + UT_ASSERT_EQ((int)state->replacement_episode.phase, (int)CLUSTER_REPLACEMENT_EPISODE_ADMITTED); + UT_ASSERT_EQ((int)cluster_membership_get_state(cluster_node_id), (int)CLUSTER_MEMBER_MEMBER); UT_ASSERT_EQ((int)cluster_reconfig_self_join_gate_verdict(), (int)CLUSTER_JOIN_GATE_BLOCK_53R60); } @@ -6220,13 +5886,11 @@ UT_TEST(test_reconfig_lmon_snapshots_only_exact_admitted_certificate) state->replacement_episode = episode; epoch_init_done = false; cluster_epoch_shmem_init(); - UT_ASSERT(cluster_epoch_observe_remote( - episode.reserved_or_committed_epoch)); + UT_ASSERT(cluster_epoch_observe_remote(episode.reserved_or_committed_epoch)); cluster_membership_set_state(1, CLUSTER_MEMBER_MEMBER); cluster_membership_set_state(2, CLUSTER_MEMBER_MEMBER); cluster_membership_set_state(episode.target_node_id, CLUSTER_MEMBER_MEMBER); - cluster_membership_record_admitted(episode.target_node_id, - episode.fresh_incarnation); + cluster_membership_record_admitted(episode.target_node_id, episode.fresh_incarnation); memset(&admitted, 0, sizeof(admitted)); admitted.magic = CLUSTER_JCMK_MAGIC; @@ -6237,50 +5901,41 @@ UT_TEST(test_reconfig_lmon_snapshots_only_exact_admitted_certificate) admitted.old_admitted_incarnation = episode.old_admitted_incarnation; admitted.fresh_incarnation = episode.fresh_incarnation; admitted.baseline_epoch = episode.baseline_epoch; - admitted.reserved_or_committed_epoch - = episode.reserved_or_committed_epoch; + admitted.reserved_or_committed_epoch = episode.reserved_or_committed_epoch; admitted.request_nonce = episode.request_nonce; memcpy(admitted.expected_purge_survivors, episode.expected_survivors, sizeof(admitted.expected_purge_survivors)); admitted.grammar_fingerprint = episode.grammar_fingerprint; admitted.ready_state_generation = episode.state_generation; - UT_ASSERT(cluster_replacement_marker_v3_encode( - &admitted, admitted_image)); - memcpy(state->join_pending_marker, admitted_image, - sizeof(admitted_image)); + UT_ASSERT(cluster_replacement_marker_v3_encode(&admitted, admitted_image)); + memcpy(state->join_pending_marker, admitted_image, sizeof(admitted_image)); pg_atomic_write_u64(&state->join_marker_request_seq, UINT64_C(10)); pg_atomic_write_u64(&state->join_marker_completion_seq, UINT64_C(10)); - pg_atomic_write_u32(&state->join_marker_result, - CLUSTER_JOIN_MARKER_SUBMIT_ACK); + pg_atomic_write_u32(&state->join_marker_result, CLUSTER_JOIN_MARKER_SUBMIT_ACK); memset(&observed_episode, 0xa5, sizeof(observed_episode)); memset(&observed_marker, 0x5a, sizeof(observed_marker)); - UT_ASSERT(cluster_reconfig_lmon_snapshot_replacement_admitted( - &observed_episode, &observed_marker)); + UT_ASSERT( + cluster_reconfig_lmon_snapshot_replacement_admitted(&observed_episode, &observed_marker)); UT_ASSERT_EQ(memcmp(&observed_episode, &episode, sizeof(episode)), 0); - UT_ASSERT(cluster_replacement_marker_v3_same_image( - &observed_marker, &admitted)); + UT_ASSERT(cluster_replacement_marker_v3_same_image(&observed_marker, &admitted)); memset(&observed_episode, 0xa5, sizeof(observed_episode)); memset(&observed_marker, 0x5a, sizeof(observed_marker)); before_episode = observed_episode; before_marker = observed_marker; cluster_membership_set_state(4, CLUSTER_MEMBER_MEMBER); - UT_ASSERT(!cluster_reconfig_lmon_snapshot_replacement_admitted( - &observed_episode, &observed_marker)); - UT_ASSERT_EQ(memcmp(&observed_episode, &before_episode, - sizeof(observed_episode)), 0); - UT_ASSERT_EQ(memcmp(&observed_marker, &before_marker, - sizeof(observed_marker)), 0); + UT_ASSERT( + !cluster_reconfig_lmon_snapshot_replacement_admitted(&observed_episode, &observed_marker)); + UT_ASSERT_EQ(memcmp(&observed_episode, &before_episode, sizeof(observed_episode)), 0); + UT_ASSERT_EQ(memcmp(&observed_marker, &before_marker, sizeof(observed_marker)), 0); cluster_membership_set_state(4, CLUSTER_MEMBER_ABSENT); admitted.ready_state_generation++; - UT_ASSERT(cluster_replacement_marker_v3_encode( - &admitted, admitted_image)); - memcpy(state->join_pending_marker, admitted_image, - sizeof(admitted_image)); - UT_ASSERT(!cluster_reconfig_lmon_snapshot_replacement_admitted( - &observed_episode, &observed_marker)); + UT_ASSERT(cluster_replacement_marker_v3_encode(&admitted, admitted_image)); + memcpy(state->join_pending_marker, admitted_image, sizeof(admitted_image)); + UT_ASSERT( + !cluster_reconfig_lmon_snapshot_replacement_admitted(&observed_episode, &observed_marker)); } /* The target LMON is the CONTROL-plane sender for Startup's instantaneous @@ -6310,11 +5965,9 @@ UT_TEST(test_reconfig_target_lmon_retransmits_exact_phase3_until_admitted) cluster_qvotec_mailbox_restart_reset(&lifecycle_authority_mailbox); pg_atomic_init_u32(&lifecycle_status, CLUSTER_QVOTEC_DOWN); UT_ASSERT(cluster_reconfig_qvotec_lifecycle_transition( - &lifecycle_authority_mailbox, &lifecycle_status, - CLUSTER_QVOTEC_STARTING)); + &lifecycle_authority_mailbox, &lifecycle_status, CLUSTER_QVOTEC_STARTING)); UT_ASSERT(cluster_reconfig_qvotec_lifecycle_transition( - &lifecycle_authority_mailbox, &lifecycle_status, - CLUSTER_QVOTEC_READY)); + &lifecycle_authority_mailbox, &lifecycle_status, CLUSTER_QVOTEC_READY)); cluster_node_id = 3; MyBackendType = B_LMON; ut_in_quorum_value = true; @@ -6329,12 +5982,10 @@ UT_TEST(test_reconfig_target_lmon_retransmits_exact_phase3_until_admitted) cluster_membership_set_state(1, CLUSTER_MEMBER_MEMBER); cluster_membership_set_state(2, CLUSTER_MEMBER_MEMBER); cluster_membership_record_admitted(1, UINT64_C(111)); - cluster_membership_record_admitted( - episode.target_node_id, episode.old_admitted_incarnation); + cluster_membership_record_admitted(episode.target_node_id, episode.old_admitted_incarnation); epoch_init_done = false; cluster_epoch_shmem_init(); - UT_ASSERT(cluster_epoch_observe_remote( - episode.reserved_or_committed_epoch)); + UT_ASSERT(cluster_epoch_observe_remote(episode.reserved_or_committed_epoch)); memset(&committed, 0, sizeof(committed)); committed.magic = CLUSTER_JCMK_MAGIC; @@ -6345,14 +5996,12 @@ UT_TEST(test_reconfig_target_lmon_retransmits_exact_phase3_until_admitted) committed.old_admitted_incarnation = episode.old_admitted_incarnation; committed.fresh_incarnation = episode.fresh_incarnation; committed.baseline_epoch = episode.baseline_epoch; - committed.reserved_or_committed_epoch - = episode.reserved_or_committed_epoch; + committed.reserved_or_committed_epoch = episode.reserved_or_committed_epoch; committed.request_nonce = episode.request_nonce; memcpy(committed.expected_purge_survivors, episode.expected_survivors, sizeof(committed.expected_purge_survivors)); committed.grammar_fingerprint = episode.grammar_fingerprint; - UT_ASSERT(cluster_replacement_marker_v3_encode( - &committed, committed_image)); + UT_ASSERT(cluster_replacement_marker_v3_encode(&committed, committed_image)); memset(&head, 0, sizeof(head)); head.value_version = CLUSTER_EPOCH_AUTHORITY_VALUE_VERSION; @@ -6371,10 +6020,9 @@ UT_TEST(test_reconfig_target_lmon_retransmits_exact_phase3_until_admitted) head.event_subject_bitmap[episode.target_node_id / 8] = (uint8)(1u << (episode.target_node_id % 8)); head.grammar_fingerprint = episode.grammar_fingerprint; - memset(head.predecessor_digest, 0x5a, - sizeof(head.predecessor_digest)); - UT_ASSERT(cluster_epoch_authority_value_encode( - &head, CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT, head_image)); + memset(head.predecessor_digest, 0x5a, sizeof(head.predecessor_digest)); + UT_ASSERT(cluster_epoch_authority_value_encode(&head, CLUSTER_EPOCH_BALLOT_GRAMMAR_FINGERPRINT, + head_image)); memset(&ballot, 0, sizeof(ballot)); ballot.counter = UINT64_C(7); @@ -6387,51 +6035,39 @@ UT_TEST(test_reconfig_target_lmon_retransmits_exact_phase3_until_admitted) cluster_reconfig_lmon_replacement_ready_tick(); UT_ASSERT_EQ(ut_phase3_send_calls, 0); UT_ASSERT_EQ(ut_authority_submit_calls, 1); - UT_ASSERT(cluster_reconfig_join_qvotec_poll_pending( - &operation, &target, slot)); - UT_ASSERT_EQ((int)operation, - (int)CLUSTER_JOIN_MARKER_MAILBOX_VERIFY_COMMITTED_CLOSED); + UT_ASSERT(cluster_reconfig_join_qvotec_poll_pending(&operation, &target, slot)); + UT_ASSERT_EQ((int)operation, (int)CLUSTER_JOIN_MARKER_MAILBOX_VERIFY_COMMITTED_CLOSED); UT_ASSERT_EQ(target, episode.target_node_id); cluster_reconfig_join_qvotec_complete(operation, true, committed_image); cluster_marker_async_init(&conflicting_marker); UT_ASSERT(!cluster_reconfig_submit_replacement_marker_v3_async( - &conflicting_marker, episode.target_node_id, &committed, - CLUSTER_MARKER_KIND_JOIN_COMMITTED, + &conflicting_marker, episode.target_node_id, &committed, CLUSTER_MARKER_KIND_JOIN_COMMITTED, (TimestampTz)UINT64_C(9000))); - memset(&ut_authority_completion, 0, - sizeof(ut_authority_completion)); + memset(&ut_authority_completion, 0, sizeof(ut_authority_completion)); ut_authority_completion.request_seq = UINT64_C(2); ut_authority_completion.result = CLUSTER_QVOTEC_MAILBOX_CHOSEN; - memcpy(ut_authority_completion.completion_value, head_image, - sizeof(head_image)); - memcpy(ut_authority_completion.completion_ballot, ballot_image, - sizeof(ballot_image)); - ut_authority_completion.actor_phase - = CLUSTER_QVOTEC_ACTOR_RECOVER_SCAN_B; + memcpy(ut_authority_completion.completion_value, head_image, sizeof(head_image)); + memcpy(ut_authority_completion.completion_ballot, ballot_image, sizeof(ballot_image)); + ut_authority_completion.actor_phase = CLUSTER_QVOTEC_ACTOR_RECOVER_SCAN_B; ut_authority_completion_ready = true; cluster_reconfig_lmon_replacement_ready_tick(); UT_ASSERT_EQ(ut_phase3_send_calls, 1); - UT_ASSERT_EQ((int)ut_phase3_send_msg_type, - (int)PGRAC_IC_MSG_GES_REQUEST); + UT_ASSERT_EQ((int)ut_phase3_send_msg_type, (int)PGRAC_IC_MSG_GES_REQUEST); UT_ASSERT_EQ(ut_phase3_send_dest, episode.coordinator_node_id); - UT_ASSERT_EQ((int)ut_phase3_send_length, - CLUSTER_REPLACEMENT_WIRE_BYTES); + UT_ASSERT_EQ((int)ut_phase3_send_length, CLUSTER_REPLACEMENT_WIRE_BYTES); memcpy(first_image, ut_phase3_send_bytes, sizeof(first_image)); UT_ASSERT(cluster_replacement_wire_decode(first_image, &decoded)); - UT_ASSERT_EQ((int)decoded.phase, - CLUSTER_REPLACEMENT_WIRE_PHASE_TARGET_RECOVERY_READY); + UT_ASSERT_EQ((int)decoded.phase, CLUSTER_REPLACEMENT_WIRE_PHASE_TARGET_RECOVERY_READY); UT_ASSERT_EQ(decoded.target_node_id, episode.target_node_id); UT_ASSERT(decoded.body.phase3.jcmk_generation == committed.generation); - UT_ASSERT_EQ((int)decoded.body.phase3.episode_state_generation, - (int)episode.state_generation); + UT_ASSERT_EQ((int)decoded.body.phase3.episode_state_generation, (int)episode.state_generation); ut_phase3_send_result = CLUSTER_IC_SEND_NOT_ADMITTED; cluster_reconfig_lmon_replacement_ready_tick(); UT_ASSERT_EQ(ut_phase3_send_calls, 2); - UT_ASSERT_EQ(memcmp(first_image, ut_phase3_send_bytes, - sizeof(first_image)), 0); + UT_ASSERT_EQ(memcmp(first_image, ut_phase3_send_bytes, sizeof(first_image)), 0); ut_phase3_send_result = CLUSTER_IC_SEND_HARD_ERROR; cluster_reconfig_lmon_replacement_ready_tick(); @@ -6456,8 +6092,7 @@ UT_TEST(test_thread_recovery_eligibility_uses_current_failstop_and_root_duty) ReconfigEvent event; cluster_reconfig_shmem_init(); - memset(&ut_recovery_root_identity, 0, - sizeof(ut_recovery_root_identity)); + memset(&ut_recovery_root_identity, 0, sizeof(ut_recovery_root_identity)); ut_recovery_root_identity.system_identifier = UINT64_C(0x1234); memset(ut_recovery_root_identity.storage_uuid, 0x11, 16); memset(ut_recovery_root_identity.authority_uuid, 0x22, 16); @@ -6480,21 +6115,17 @@ UT_TEST(test_thread_recovery_eligibility_uses_current_failstop_and_root_duty) cluster_reconfig_publish_event(&event); memset(&eligibility, 0xA5, sizeof(eligibility)); - UT_ASSERT(cluster_reconfig_thread_recovery_eligibility_consume( - 1, &eligibility)); + UT_ASSERT(cluster_reconfig_thread_recovery_eligibility_consume(1, &eligibility)); UT_ASSERT_EQ(eligibility.origin_thread, 1); UT_ASSERT_EQ(eligibility.attempt_stamp, 7); - UT_ASSERT(memcmp(&eligibility.duty, &ut_recovery_root_identity, - sizeof(eligibility.duty)) == 0); + UT_ASSERT(memcmp(&eligibility.duty, &ut_recovery_root_identity, sizeof(eligibility.duty)) == 0); event.dead_bitmap[0] = 0; cluster_reconfig_publish_event(&event); memset(&eligibility, 0xA5, sizeof(eligibility)); - UT_ASSERT(!cluster_reconfig_thread_recovery_eligibility_consume( - 1, &eligibility)); - UT_ASSERT(memcmp(&eligibility, - &(ClusterThreadRecLaunchEligibility){ 0 }, - sizeof(eligibility)) == 0); + UT_ASSERT(!cluster_reconfig_thread_recovery_eligibility_consume(1, &eligibility)); + UT_ASSERT(memcmp(&eligibility, &(ClusterThreadRecLaunchEligibility){ 0 }, sizeof(eligibility)) + == 0); UT_ASSERT(!cluster_reconfig_thread_recovery_eligibility_consume(1, NULL)); } @@ -6504,14 +6135,11 @@ UT_TEST(test_rejoin_observed_slot_getter_is_coherent) uint64 generation = UINT64_MAX; ut_join_setup(); - UT_ASSERT(!cluster_reconfig_get_observed_slot_coherent( - 1, &incarnation, &generation)); + UT_ASSERT(!cluster_reconfig_get_observed_slot_coherent(1, &incarnation, &generation)); UT_ASSERT_EQ(incarnation, 0); UT_ASSERT_EQ(generation, 0); - cluster_reconfig_record_observed_slot(1, UINT64_C(77), UINT64_C(9), - UINT64_C(12)); - UT_ASSERT(cluster_reconfig_get_observed_slot_coherent( - 1, &incarnation, &generation)); + cluster_reconfig_record_observed_slot(1, UINT64_C(77), UINT64_C(9), UINT64_C(12)); + UT_ASSERT(cluster_reconfig_get_observed_slot_coherent(1, &incarnation, &generation)); UT_ASSERT_EQ(incarnation, UINT64_C(77)); UT_ASSERT_EQ(generation, UINT64_C(9)); } @@ -6537,8 +6165,7 @@ UT_TEST(test_rejoin_failure_snapshot_requires_exact_nonempty_survivors_and_floor event.reconfig_kind = RECONFIG_KIND_FAIL_STOP; cluster_reconfig_publish_event(&event); - UT_ASSERT(cluster_reconfig_rejoin_failure_snapshot( - 1, UINT64_C(70), &failure)); + UT_ASSERT(cluster_reconfig_rejoin_failure_snapshot(1, UINT64_C(70), &failure)); UT_ASSERT_EQ(failure.reconfig_kind, RECONFIG_KIND_FAIL_STOP); UT_ASSERT_EQ(failure.event_id, UINT64_C(501)); UT_ASSERT_EQ(failure.new_epoch, UINT64_C(9)); @@ -6550,8 +6177,7 @@ UT_TEST(test_rejoin_failure_snapshot_requires_exact_nonempty_survivors_and_floor memset(&failure, 0xa5, sizeof(failure)); memset(&zero, 0, sizeof(zero)); - UT_ASSERT(!cluster_reconfig_rejoin_failure_snapshot( - 1, UINT64_C(69), &failure)); + UT_ASSERT(!cluster_reconfig_rejoin_failure_snapshot(1, UINT64_C(69), &failure)); UT_ASSERT(memcmp(&failure, &zero, sizeof(failure)) == 0); } @@ -6577,13 +6203,11 @@ UT_TEST(test_rejoin_pending_snapshot_requires_exact_singleton_lineage) event.dead_bitmap[0] = UINT8_C(0x02); event.reconfig_kind = RECONFIG_KIND_FAIL_STOP; cluster_reconfig_publish_event(&event); - UT_ASSERT(cluster_reconfig_rejoin_failure_snapshot( - 1, UINT64_C(70), &failure)); + UT_ASSERT(cluster_reconfig_rejoin_failure_snapshot(1, UINT64_C(70), &failure)); cluster_membership_set_state(1, CLUSTER_MEMBER_JOINING); state->pending_join_bitmap[0] = UINT8_C(0x02); - cluster_reconfig_record_observed_slot(1, UINT64_C(77), UINT64_C(11), - UINT64_C(10)); + cluster_reconfig_record_observed_slot(1, UINT64_C(77), UINT64_C(11), UINT64_C(10)); memset(incarnations, 0, sizeof(incarnations)); incarnations[1] = UINT64_C(77); memset(&event, 0, sizeof(event)); @@ -6592,13 +6216,12 @@ UT_TEST(test_rejoin_pending_snapshot_requires_exact_singleton_lineage) event.cssd_dead_generation = UINT64_C(5); event.join_bitmap[0] = UINT8_C(0x02); event.reconfig_kind = RECONFIG_KIND_JOIN_PENDING; - event.event_id = cluster_reconfig_compute_event_id_v2( - RECONFIG_KIND_JOIN_PENDING, event.dead_bitmap, event.join_bitmap, - incarnations, event.cssd_dead_generation); + event.event_id = cluster_reconfig_compute_event_id_v2(RECONFIG_KIND_JOIN_PENDING, + event.dead_bitmap, event.join_bitmap, + incarnations, event.cssd_dead_generation); cluster_reconfig_publish_event(&event); - UT_ASSERT(cluster_reconfig_rejoin_pending_snapshot( - &failure, UINT64_C(77), &pending)); + UT_ASSERT(cluster_reconfig_rejoin_pending_snapshot(&failure, UINT64_C(77), &pending)); UT_ASSERT_EQ(pending.reconfig_kind, RECONFIG_KIND_JOIN_PENDING); UT_ASSERT_EQ(pending.old_epoch, UINT64_C(9)); UT_ASSERT_EQ(pending.new_epoch, UINT64_C(10)); @@ -6611,8 +6234,7 @@ UT_TEST(test_rejoin_pending_snapshot_requires_exact_singleton_lineage) cluster_reconfig_publish_event(&event); memset(&pending, 0xa5, sizeof(pending)); memset(&zero, 0, sizeof(zero)); - UT_ASSERT(!cluster_reconfig_rejoin_pending_snapshot( - &failure, UINT64_C(77), &pending)); + UT_ASSERT(!cluster_reconfig_rejoin_pending_snapshot(&failure, UINT64_C(77), &pending)); UT_ASSERT(memcmp(&pending, &zero, sizeof(pending)) == 0); } @@ -6633,7 +6255,7 @@ UT_TEST(test_external_rejoin_consumes_exact_candidate_before_jcmk_submit) ut_dead_generation = UINT64_C(9); ut_declared_set[1] = true; ut_peer_state[1] = CLUSTER_CSSD_PEER_DEAD; - state = (ClusterReconfigState *) reconfig_shmem_storage; + state = (ClusterReconfigState *)reconfig_shmem_storage; state->self_join_admitted = 1; cluster_membership_set_state(0, CLUSTER_MEMBER_MEMBER); cluster_membership_set_state(1, CLUSTER_MEMBER_DEAD); @@ -6653,18 +6275,16 @@ UT_TEST(test_external_rejoin_consumes_exact_candidate_before_jcmk_submit) event.cssd_dead_generation = UINT64_C(9); event.dead_bitmap[0] = UINT8_C(0x02); event.reconfig_kind = RECONFIG_KIND_FAIL_STOP; - event.event_id = cluster_reconfig_compute_event_id( - event.dead_bitmap, event.cssd_dead_generation); + event.event_id + = cluster_reconfig_compute_event_id(event.dead_bitmap, event.cssd_dead_generation); cluster_reconfig_publish_event(&event); memset(&ut_rejoin_offer, 0, sizeof(ut_rejoin_offer)); - memset(ut_rejoin_offer.operation_id, 0x33, - sizeof(ut_rejoin_offer.operation_id)); + memset(ut_rejoin_offer.operation_id, 0x33, sizeof(ut_rejoin_offer.operation_id)); ut_rejoin_offer.old_node_id = 1; ut_rejoin_offer.old_incarnation = UINT64_C(70); ut_rejoin_offer.candidate_incarnation = UINT64_C(77); - memset(&ut_recovery_root_identity, 0, - sizeof(ut_recovery_root_identity)); + memset(&ut_recovery_root_identity, 0, sizeof(ut_recovery_root_identity)); ut_recovery_root_identity.system_identifier = UINT64_C(0x1234); ut_recovery_root_identity.origin_thread_id = 2; ut_recovery_root_identity.origin_node_id = 1; @@ -6708,8 +6328,7 @@ UT_TEST(test_external_rejoin_consumes_exact_candidate_before_jcmk_submit) * may now publish exact singleton P, whose dead bitmap excludes B-old while * membership remains JOINING and the durable fence marker still retains it. */ ut_peer_state[1] = CLUSTER_CSSD_PEER_ALIVE; - cluster_reconfig_record_observed_slot(1, UINT64_C(77), UINT64_C(11), - UINT64_C(9)); + cluster_reconfig_record_observed_slot(1, UINT64_C(77), UINT64_C(11), UINT64_C(9)); cluster_reconfig_lmon_tick(); UT_ASSERT_EQ(cluster_epoch_get_current(), UINT64_C(10)); memset(slot, 0, sizeof(slot)); @@ -6719,15 +6338,13 @@ UT_TEST(test_external_rejoin_consumes_exact_candidate_before_jcmk_submit) cluster_reconfig_lmon_tick(); UT_ASSERT_EQ(cluster_epoch_get_current(), UINT64_C(10)); cluster_reconfig_get_last_event(&pending_event); - UT_ASSERT_EQ((int) pending_event.reconfig_kind, - (int) RECONFIG_KIND_JOIN_PENDING); - UT_ASSERT_EQ(pending_event.old_epoch, - ut_rejoin_failure_seen.new_epoch); + UT_ASSERT_EQ((int)pending_event.reconfig_kind, (int)RECONFIG_KIND_JOIN_PENDING); + UT_ASSERT_EQ(pending_event.old_epoch, ut_rejoin_failure_seen.new_epoch); UT_ASSERT_EQ(pending_event.dead_bitmap[0], 0); UT_ASSERT_EQ(pending_event.join_bitmap[0], UINT8_C(0x02)); memset(&exact_pending, 0, sizeof(exact_pending)); - UT_ASSERT(cluster_reconfig_rejoin_pending_snapshot( - &ut_rejoin_failure_seen, UINT64_C(77), &exact_pending)); + UT_ASSERT(cluster_reconfig_rejoin_pending_snapshot(&ut_rejoin_failure_seen, UINT64_C(77), + &exact_pending)); UT_ASSERT(cluster_reconfig_rejoin_pending_ready(&exact_pending)); /* Refresh reaches READY on a later poll. The final root revalidate and @@ -6740,22 +6357,17 @@ UT_TEST(test_external_rejoin_consumes_exact_candidate_before_jcmk_submit) UT_ASSERT_EQ(ut_rejoin_consume_calls, 1); UT_ASSERT(!ut_rejoin_consume_saw_prior_marker_submit); UT_ASSERT_EQ(ut_rejoin_pending_seen.node_id, 1); - UT_ASSERT_EQ(ut_rejoin_pending_seen.candidate_incarnation, - UINT64_C(77)); + UT_ASSERT_EQ(ut_rejoin_pending_seen.candidate_incarnation, UINT64_C(77)); UT_ASSERT_EQ(ut_rejoin_committed_seen.node_id, 1); - UT_ASSERT_EQ(ut_rejoin_committed_seen.phase, - CLUSTER_JCMK_PHASE_COMMITTED); - UT_ASSERT_EQ(ut_rejoin_committed_seen.admitted_incarnation, - UINT64_C(77)); + UT_ASSERT_EQ(ut_rejoin_committed_seen.phase, CLUSTER_JCMK_PHASE_COMMITTED); + UT_ASSERT_EQ(ut_rejoin_committed_seen.admitted_incarnation, UINT64_C(77)); UT_ASSERT_EQ(ut_rejoin_committed_seen.generation, UINT64_C(77)); - UT_ASSERT_EQ(ut_rejoin_committed_seen.admitted_epoch, - pending_event.new_epoch + 1); + UT_ASSERT_EQ(ut_rejoin_committed_seen.admitted_epoch, pending_event.new_epoch + 1); UT_ASSERT(ut_rejoin_committed_seen.commit_nonce != 0); memset(slot, 0, sizeof(slot)); UT_ASSERT(ut_join_qvotec_poll_write_pending(&target, slot)); memcpy(&submitted, slot, sizeof(submitted)); - UT_ASSERT(memcmp(&submitted, &ut_rejoin_committed_seen, - sizeof(submitted)) == 0); + UT_ASSERT(memcmp(&submitted, &ut_rejoin_committed_seen, sizeof(submitted)) == 0); } /* ====================================================================== @@ -6804,7 +6416,7 @@ UT_TEST(test_formation_marker_admission_waits_for_stripe) { ClusterReconfigState *state; ClusterFormationCommitMarker marker; - uint64 incs[CLUSTER_MAX_NODES] = {0}; + uint64 incs[CLUSTER_MAX_NODES] = { 0 }; int t; cluster_online_join = false; @@ -6831,20 +6443,16 @@ UT_TEST(test_formation_marker_admission_waits_for_stripe) cluster_reconfig_cold_formation_tick(); UT_ASSERT_EQ(ut_xid_stripe_join_gate_calls, 1); UT_ASSERT(!ut_xid_stripe_last_may_seed); - UT_ASSERT_EQ((int)cluster_membership_get_state(1), - (int)CLUSTER_MEMBER_ABSENT); - UT_ASSERT_EQ(cluster_membership_get_last_admitted_incarnation(1), - UINT64_C(0)); + UT_ASSERT_EQ((int)cluster_membership_get_state(1), (int)CLUSTER_MEMBER_ABSENT); + UT_ASSERT_EQ(cluster_membership_get_last_admitted_incarnation(1), UINT64_C(0)); UT_ASSERT_EQ(state->self_join_admitted, 0); ut_xid_stripe_verdict = CLUSTER_XID_STRIPE_JOIN_PROCEED; cluster_reconfig_cold_formation_tick(); UT_ASSERT_EQ(ut_xid_stripe_join_gate_calls, 2); UT_ASSERT(!ut_xid_stripe_last_may_seed); - UT_ASSERT_EQ((int)cluster_membership_get_state(1), - (int)CLUSTER_MEMBER_MEMBER); - UT_ASSERT_EQ(cluster_membership_get_last_admitted_incarnation(1), - UINT64_C(77)); + UT_ASSERT_EQ((int)cluster_membership_get_state(1), (int)CLUSTER_MEMBER_MEMBER); + UT_ASSERT_EQ(cluster_membership_get_last_admitted_incarnation(1), UINT64_C(77)); UT_ASSERT_EQ(state->self_join_admitted, 1); } @@ -6852,11 +6460,11 @@ UT_TEST(test_cold_formation_leg1_writer_crash_midwrite_survivor_admits) { ClusterReconfigState *state; ClusterFormationCommitMarker marker; - uint64 incs[CLUSTER_MAX_NODES] = {0}; - int t; + uint64 incs[CLUSTER_MAX_NODES] = { 0 }; + int t; ut_cold_formation_setup_coboot(); - state = (ClusterReconfigState *) reconfig_shmem_storage; + state = (ClusterReconfigState *)reconfig_shmem_storage; /* * The arbiter (node 0, lowest co-boot node) submitted the COMMITTED @@ -6887,8 +6495,7 @@ UT_TEST(test_cold_formation_leg1_writer_crash_midwrite_survivor_admits) for (t = 0; t < 3; t++) cluster_reconfig_cold_formation_tick(); - UT_ASSERT_EQ((int)cluster_membership_get_state(1), - (int)CLUSTER_MEMBER_MEMBER); + UT_ASSERT_EQ((int)cluster_membership_get_state(1), (int)CLUSTER_MEMBER_MEMBER); UT_ASSERT_EQ(cluster_membership_get_last_admitted_incarnation(1), UINT64_C(77)); /* D13 exact floor, from the marker */ UT_ASSERT_EQ(cluster_membership_get_last_admitted_incarnation(0), @@ -6896,8 +6503,7 @@ UT_TEST(test_cold_formation_leg1_writer_crash_midwrite_survivor_admits) UT_ASSERT_EQ(state->self_join_admitted, 1); /* The survivor never submitted anything (no takeover write): the * durable marker alone carried the admission. */ - UT_ASSERT_EQ(pg_atomic_read_u64(&state->formation_marker_request_seq), - UINT64_C(0)); + UT_ASSERT_EQ(pg_atomic_read_u64(&state->formation_marker_request_seq), UINT64_C(0)); /* The dead writer's slot ages out: the window goes PENDING, but the * admission is already durable — self stays MEMBER with the exact @@ -6905,10 +6511,8 @@ UT_TEST(test_cold_formation_leg1_writer_crash_midwrite_survivor_admits) cluster_reconfig_record_observed_fresh_alive(0, false); for (t = 0; t < 5; t++) cluster_reconfig_cold_formation_tick(); - UT_ASSERT_EQ((int)cluster_membership_get_state(1), - (int)CLUSTER_MEMBER_MEMBER); - UT_ASSERT_EQ(cluster_membership_get_last_admitted_incarnation(1), - UINT64_C(77)); + UT_ASSERT_EQ((int)cluster_membership_get_state(1), (int)CLUSTER_MEMBER_MEMBER); + UT_ASSERT_EQ(cluster_membership_get_last_admitted_incarnation(1), UINT64_C(77)); } UT_TEST(test_initial_clean_snapshot_requires_exact_four_node_marker_and_empty_replacement) @@ -6917,7 +6521,7 @@ UT_TEST(test_initial_clean_snapshot_requires_exact_four_node_marker_and_empty_re ClusterFormationCommitMarker marker; ClusterInitialCleanFormationSnapshot snapshot; ClusterReplacementEpisode replacement; - uint64 incarnations[CLUSTER_MAX_NODES] = {0}; + uint64 incarnations[CLUSTER_MAX_NODES] = { 0 }; int node; ut_join_setup(); @@ -6940,8 +6544,7 @@ UT_TEST(test_initial_clean_snapshot_requires_exact_four_node_marker_and_empty_re cluster_membership_record_admitted(node, incarnations[node]); cluster_membership_set_state(node, CLUSTER_MEMBER_MEMBER); } - cluster_reconfig_formation_qvotec_publish_observed( - &marker, incarnations); + cluster_reconfig_formation_qvotec_publish_observed(&marker, incarnations); memset(&snapshot, 0xa5, sizeof(snapshot)); UT_ASSERT(cluster_reconfig_snapshot_initial_clean_formation(&snapshot)); @@ -6952,8 +6555,7 @@ UT_TEST(test_initial_clean_snapshot_requires_exact_four_node_marker_and_empty_re UT_ASSERT_EQ(snapshot.arbiter_node, UINT64_C(0)); UT_ASSERT_EQ(snapshot.arbiter_incarnation, UINT64_C(60)); for (node = 0; node < 4; node++) - UT_ASSERT_EQ(snapshot.admitted_incarnation[node], - incarnations[node]); + UT_ASSERT_EQ(snapshot.admitted_incarnation[node], incarnations[node]); replacement = ut_admitted_replacement_episode(3); state->replacement_episode = replacement; @@ -6974,14 +6576,12 @@ UT_TEST(test_initial_clean_snapshot_accepts_exact_initial_quorum_without_marker) state = (ClusterReconfigState *)reconfig_shmem_storage; state->self_join_admitted = 1; ut_in_quorum_value = true; - ut_set_self_incarnation_sequence( - UINT64_C(80), UINT64_C(80), UINT64_C(80)); + ut_set_self_incarnation_sequence(UINT64_C(80), UINT64_C(80), UINT64_C(80)); for (node = 0; node < 4; node++) { incarnations[node] = UINT64_C(80) + (uint64)node; ut_declared_set[node] = true; - cluster_reconfig_record_observed_slot( - node, incarnations[node], UINT64_C(1), - CLUSTER_EPOCH_INITIAL); + cluster_reconfig_record_observed_slot(node, incarnations[node], UINT64_C(1), + CLUSTER_EPOCH_INITIAL); cluster_reconfig_record_observed_fresh_alive(node, true); cluster_membership_record_admitted(node, incarnations[node]); cluster_membership_set_state(node, CLUSTER_MEMBER_MEMBER); @@ -6996,13 +6596,11 @@ UT_TEST(test_initial_clean_snapshot_accepts_exact_initial_quorum_without_marker) UT_ASSERT_EQ(snapshot.formation_epoch, CLUSTER_EPOCH_INITIAL); UT_ASSERT_EQ(snapshot.members_lo, UINT64_C(0x0f)); for (node = 0; node < 4; node++) - UT_ASSERT_EQ(snapshot.admitted_incarnation[node], - incarnations[node]); + UT_ASSERT_EQ(snapshot.admitted_incarnation[node], incarnations[node]); cluster_reconfig_bootstrap_publish_begin(); - cluster_reconfig_record_observed_slot( - 2, incarnations[2] + 1, UINT64_C(2), - CLUSTER_EPOCH_INITIAL); + cluster_reconfig_record_observed_slot(2, incarnations[2] + 1, UINT64_C(2), + CLUSTER_EPOCH_INITIAL); cluster_reconfig_bootstrap_publish_in_quorum(true); cluster_reconfig_bootstrap_publish_end(); memset(&snapshot, 0xa5, sizeof(snapshot)); @@ -7014,7 +6612,7 @@ UT_TEST(test_initial_clean_snapshot_accepts_exact_initial_quorum_without_marker) UT_TEST(test_cold_formation_leg2_live_survivor_refuses) { ClusterReconfigState *state; - int t; + int t; ut_join_setup(); cluster_node_id = 1; @@ -7024,11 +6622,10 @@ UT_TEST(test_cold_formation_leg2_live_survivor_refuses) UT_ASSERT(cluster_epoch_observe_remote(UINT64_C(5))); /* node 0 is a LIVE survivor: fresh slot publishing the LIVE epoch * (A-semantics: a formed node publishes the real epoch). */ - cluster_reconfig_record_observed_slot(0, UINT64_C(66), UINT64_C(1), - UINT64_C(7)); + cluster_reconfig_record_observed_slot(0, UINT64_C(66), UINT64_C(1), UINT64_C(7)); cluster_reconfig_record_observed_fresh_alive(0, true); cluster_reconfig_test_reset_cold_formation(); - state = (ClusterReconfigState *) reconfig_shmem_storage; + state = (ClusterReconfigState *)reconfig_shmem_storage; for (t = 0; t < 12; t++) cluster_reconfig_cold_formation_tick(); @@ -7037,26 +6634,23 @@ UT_TEST(test_cold_formation_leg2_live_survivor_refuses) * ever staged, and this node never admitted through the cold-formation * path (a live cluster has no cold formation — the ordinary join/JCMK * chain owns this node). */ - UT_ASSERT_EQ(pg_atomic_read_u64(&state->formation_marker_request_seq), - UINT64_C(0)); - UT_ASSERT_EQ((int)cluster_membership_get_state(1), - (int)CLUSTER_MEMBER_ABSENT); - UT_ASSERT_EQ(cluster_membership_get_last_admitted_incarnation(1), - UINT64_C(0)); + UT_ASSERT_EQ(pg_atomic_read_u64(&state->formation_marker_request_seq), UINT64_C(0)); + UT_ASSERT_EQ((int)cluster_membership_get_state(1), (int)CLUSTER_MEMBER_ABSENT); + UT_ASSERT_EQ(cluster_membership_get_last_admitted_incarnation(1), UINT64_C(0)); } UT_TEST(test_cold_formation_leg3_divergent_marker_rejected_no_majority) { ClusterReconfigState *state; ClusterFormationCommitMarker marker; - uint64 incs[CLUSTER_MAX_NODES] = {0}; - int t; + uint64 incs[CLUSTER_MAX_NODES] = { 0 }; + int t; /* ---- A. non-arbiter: a DIVERGENT marker (names an OLD incarnation * for self — a stale/divergent generation's image) is rejected; the * node keeps waiting and never admits. ---- */ ut_cold_formation_setup_coboot(); - state = (ClusterReconfigState *) reconfig_shmem_storage; + state = (ClusterReconfigState *)reconfig_shmem_storage; marker.magic = CLUSTER_FORMATION_MARKER_MAGIC; marker.version = CLUSTER_FORMATION_MARKER_VERSION; marker.phase = CLUSTER_FORMATION_MARKER_PHASE_COMMITTED; @@ -7072,18 +6666,15 @@ UT_TEST(test_cold_formation_leg3_divergent_marker_rejected_no_majority) cluster_reconfig_formation_qvotec_publish_observed(&marker, incs); for (t = 0; t < 6; t++) cluster_reconfig_cold_formation_tick(); - UT_ASSERT_EQ((int)cluster_membership_get_state(1), - (int)CLUSTER_MEMBER_ABSENT); - UT_ASSERT_EQ(cluster_membership_get_last_admitted_incarnation(1), - UINT64_C(0)); - UT_ASSERT_EQ(cluster_membership_get_last_admitted_incarnation(0), - UINT64_C(0)); + UT_ASSERT_EQ((int)cluster_membership_get_state(1), (int)CLUSTER_MEMBER_ABSENT); + UT_ASSERT_EQ(cluster_membership_get_last_admitted_incarnation(1), UINT64_C(0)); + UT_ASSERT_EQ(cluster_membership_get_last_admitted_incarnation(0), UINT64_C(0)); /* ---- B. arbiter: the marker write did NOT reach quorum-majority * readback (qvotec completes FAILED) — no admission happens; the * arbiter resets and re-submits with a fresh nonce, and only a * later PROVEN write admits. ---- */ - ut_join_setup(); /* self = 0 = the LOWEST co-boot node */ + ut_join_setup(); /* self = 0 = the LOWEST co-boot node */ cluster_node_id = 0; ut_declared_set[0] = true; ut_declared_set[1] = true; @@ -7092,7 +6683,7 @@ UT_TEST(test_cold_formation_leg3_divergent_marker_rejected_no_majority) cluster_reconfig_record_observed_slot(1, UINT64_C(70), UINT64_C(1), 0); cluster_reconfig_record_observed_fresh_alive(1, true); cluster_reconfig_test_reset_cold_formation(); - state = (ClusterReconfigState *) reconfig_shmem_storage; + state = (ClusterReconfigState *)reconfig_shmem_storage; for (t = 0; t < 3; t++) cluster_reconfig_cold_formation_tick(); @@ -7102,31 +6693,24 @@ UT_TEST(test_cold_formation_leg3_divergent_marker_rejected_no_majority) /* qvotec read back fewer than a strict majority of exact images. */ cluster_reconfig_formation_qvotec_complete(false); cluster_reconfig_cold_formation_tick(); - UT_ASSERT_EQ((int)cluster_membership_get_state(0), - (int)CLUSTER_MEMBER_ABSENT); - UT_ASSERT_EQ(cluster_membership_get_last_admitted_incarnation(0), - UINT64_C(0)); + UT_ASSERT_EQ((int)cluster_membership_get_state(0), (int)CLUSTER_MEMBER_ABSENT); + UT_ASSERT_EQ(cluster_membership_get_last_admitted_incarnation(0), UINT64_C(0)); /* The failed submission is retried (fresh nonce, same generation * lineage: max observed generation + 1 stays 1). */ cluster_reconfig_cold_formation_tick(); UT_ASSERT_EQ(pg_atomic_read_u64(&state->formation_marker_request_seq), UINT64_C(2)); /* re-submitted */ - UT_ASSERT_EQ((int)cluster_membership_get_state(0), - (int)CLUSTER_MEMBER_ABSENT); - UT_ASSERT_EQ(cluster_membership_get_last_admitted_incarnation(0), - UINT64_C(0)); + UT_ASSERT_EQ((int)cluster_membership_get_state(0), (int)CLUSTER_MEMBER_ABSENT); + UT_ASSERT_EQ(cluster_membership_get_last_admitted_incarnation(0), UINT64_C(0)); /* The retried write proves on a majority: admission lands with the * exact per-member floors. */ cluster_reconfig_formation_qvotec_complete(true); cluster_reconfig_cold_formation_tick(); - UT_ASSERT_EQ((int)cluster_membership_get_state(0), - (int)CLUSTER_MEMBER_MEMBER); - UT_ASSERT_EQ(cluster_membership_get_last_admitted_incarnation(0), - UINT64_C(77)); - UT_ASSERT_EQ(cluster_membership_get_last_admitted_incarnation(1), - UINT64_C(70)); + UT_ASSERT_EQ((int)cluster_membership_get_state(0), (int)CLUSTER_MEMBER_MEMBER); + UT_ASSERT_EQ(cluster_membership_get_last_admitted_incarnation(0), UINT64_C(77)); + UT_ASSERT_EQ(cluster_membership_get_last_admitted_incarnation(1), UINT64_C(70)); UT_ASSERT_EQ(state->self_join_admitted, 1); } diff --git a/src/test/cluster_unit/test_cluster_recovery_anchor.c b/src/test/cluster_unit/test_cluster_recovery_anchor.c index 57dd030e2e9..c775eb6bad8 100644 --- a/src/test/cluster_unit/test_cluster_recovery_anchor.c +++ b/src/test/cluster_unit/test_cluster_recovery_anchor.c @@ -404,9 +404,8 @@ wipe_anchor_files(void) test_wal_registry_ready = true; test_wal_slot_verdict = CLUSTER_WAL_SLOT_OK; cluster_wal_state_slot_fill(&test_wal_slot, test_wal_thread_id, cluster_node_id, - CLUSTER_WAL_SLOT_STATE_ACTIVE, 1, - test_stats_spawned_at, test_stats_spawned_at + 1, - 0x1000, 0x2000); + CLUSTER_WAL_SLOT_STATE_ACTIVE, 1, test_stats_spawned_at, + test_stats_spawned_at + 1, 0x1000, 0x2000); test_wal_slot_read_calls = 0; test_wal_slot_last_read_thread = 0; test_cf_x_held = true; @@ -728,9 +727,8 @@ publish_checkpoint_panics(const CheckPoint *cp) { test_expect_panic = true; if (setjmp(test_panic_jump) == 0) { - cluster_recovery_anchor_publish_checkpoint( - 0x0000000398770000ULL, cp, TEST_SYSID, - (uint32)DB_IN_PRODUCTION, InvalidXLogRecPtr); + cluster_recovery_anchor_publish_checkpoint(0x0000000398770000ULL, cp, TEST_SYSID, + (uint32)DB_IN_PRODUCTION, InvalidXLogRecPtr); test_expect_panic = false; return false; } @@ -807,9 +805,8 @@ UT_TEST(test_checkpoint_publish_requires_current_owner_before_io) UT_ASSERT_EQ(out.checkPoint, 0x0000000398770000ULL); wipe_anchor_files(); - cluster_recovery_anchor_publish_checkpoint( - 0x0000000398770000ULL, &cp, TEST_SYSID, - (uint32)DB_IN_PRODUCTION, InvalidXLogRecPtr); + cluster_recovery_anchor_publish_checkpoint(0x0000000398770000ULL, &cp, TEST_SYSID, + (uint32)DB_IN_PRODUCTION, InvalidXLogRecPtr); UT_ASSERT_EQ(test_write_fence_calls, 1); UT_ASSERT(cluster_recovery_anchor_read(TEST_SYSID, &out, &used_bak)); UT_ASSERT_EQ(out.checkPoint, 0x0000000398770000ULL); diff --git a/src/test/cluster_unit/test_cluster_recovery_duty.c b/src/test/cluster_unit/test_cluster_recovery_duty.c index ccb7e19f583..0d1183c751f 100644 --- a/src/test/cluster_unit/test_cluster_recovery_duty.c +++ b/src/test/cluster_unit/test_cluster_recovery_duty.c @@ -70,16 +70,16 @@ GetCurrentTimestamp(void) TimestampTz TimestampTzPlusMilliseconds(TimestampTz t, int64 ms) { - return t + (TimestampTz) ms * 1000; + return t + (TimestampTz)ms * 1000; } int WaitLatch(Latch *latch, int wakeEvents, long timeout, uint32 wait_event_info) { - (void) latch; - (void) wakeEvents; - (void) timeout; - (void) wait_event_info; + (void)latch; + (void)wakeEvents; + (void)timeout; + (void)wait_event_info; ut_waitlatch_calls++; /* Advance the fake clock 100ms per backoff so the bounded-retry * deadline tests complete quickly. */ @@ -90,15 +90,14 @@ WaitLatch(Latch *latch, int wakeEvents, long timeout, uint32 wait_event_info) void ResetLatch(Latch *latch) { - (void) latch; + (void)latch; } volatile sig_atomic_t InterruptPending = 0; void ProcessInterrupts(void) -{ -} +{} bool cluster_authority_serving_rebind_leaver(void) @@ -107,9 +106,10 @@ cluster_authority_serving_rebind_leaver(void) } ClusterControlRootResult -cluster_control_root_lookup_owner_by_node_runtime( - int32 old_node_id, ClusterControlRootIdentity *out_identity, - ClusterControlRootSnapshot *out_snapshot, ClusterControlRootReadToken *out_token) +cluster_control_root_lookup_owner_by_node_runtime(int32 old_node_id, + ClusterControlRootIdentity *out_identity, + ClusterControlRootSnapshot *out_snapshot, + ClusterControlRootReadToken *out_token) { (void)old_node_id; if (ut_root_lookup_result == CLUSTER_CONTROL_ROOT_OK_PRIMARY @@ -122,10 +122,9 @@ cluster_control_root_lookup_owner_by_node_runtime( } ClusterRecoveryOwnerImportResult -cluster_recovery_owner_import_read_v1( - int32 node_id, const ClusterWalThreadClaim *immutable_claim, - uint64 frozen_admitted_bitmap_low, uint64 frozen_admitted_bitmap_high, - uint64 *out_incarnation) +cluster_recovery_owner_import_read_v1(int32 node_id, const ClusterWalThreadClaim *immutable_claim, + uint64 frozen_admitted_bitmap_low, + uint64 frozen_admitted_bitmap_high, uint64 *out_incarnation) { (void)node_id; (void)immutable_claim; @@ -137,10 +136,11 @@ cluster_recovery_owner_import_read_v1( } ClusterControlRootResult -cluster_control_root_compare_and_publish( - const ClusterControlRootReadToken *expected_token, - const ClusterControlRootPatch *patch, ClusterControlRootPublishReason reason, - ClusterControlRootSnapshot *out_snapshot, ClusterControlRootReadToken *out_token) +cluster_control_root_compare_and_publish(const ClusterControlRootReadToken *expected_token, + const ClusterControlRootPatch *patch, + ClusterControlRootPublishReason reason, + ClusterControlRootSnapshot *out_snapshot, + ClusterControlRootReadToken *out_token) { ClusterControlRootReadToken observed_token = *expected_token; @@ -155,9 +155,8 @@ cluster_control_root_compare_and_publish( ut_root_published_reason = reason; if (ut_root_publish_mutate_token) observed_token.root_publish_seq++; - ut_root_publish_context_authorized = - cluster_control_root_publish_authority_current_v1( - &observed_token, patch, reason); + ut_root_publish_context_authorized + = cluster_control_root_publish_authority_current_v1(&observed_token, patch, reason); if (!ut_root_publish_context_authorized) return CLUSTER_CONTROL_ROOT_INVALID_ARGUMENT; /* Mirror the real CAS monotonicity (control_root.c compare_and_publish, @@ -180,40 +179,32 @@ cluster_control_root_compare_and_publish( if ((patch->mask & CLUSTER_CONTROL_ROOT_PATCH_LIFECYCLE) != 0) out_snapshot->lifecycle = patch->desired.lifecycle; if ((patch->mask & CLUSTER_CONTROL_ROOT_PATCH_OWNER_LINEAGE) != 0) { - out_snapshot->identity.origin_owner_incarnation = - patch->desired.identity.origin_owner_incarnation; - out_snapshot->identity.root_lineage_seq = - patch->desired.identity.root_lineage_seq; + out_snapshot->identity.origin_owner_incarnation + = patch->desired.identity.origin_owner_incarnation; + out_snapshot->identity.root_lineage_seq = patch->desired.identity.root_lineage_seq; } if ((patch->mask & CLUSTER_CONTROL_ROOT_PATCH_CHECKPOINT) != 0) { out_snapshot->checkpoint_tli = patch->desired.checkpoint_tli; - out_snapshot->checkpoint_source_kind = - patch->desired.checkpoint_source_kind; - out_snapshot->checkpoint_lower_lsn = - patch->desired.checkpoint_lower_lsn; - out_snapshot->checkpoint_record_crc32c = - patch->desired.checkpoint_record_crc32c; + out_snapshot->checkpoint_source_kind = patch->desired.checkpoint_source_kind; + out_snapshot->checkpoint_lower_lsn = patch->desired.checkpoint_lower_lsn; + out_snapshot->checkpoint_record_crc32c = patch->desired.checkpoint_record_crc32c; } if ((patch->mask & CLUSTER_CONTROL_ROOT_PATCH_TAIL) != 0) { out_snapshot->tail_tli = patch->desired.tail_tli; - out_snapshot->tail_validation_kind = - patch->desired.tail_validation_kind; - out_snapshot->validated_tail_lsn_exclusive = - patch->desired.validated_tail_lsn_exclusive; - out_snapshot->tail_last_record_lsn = - patch->desired.tail_last_record_lsn; - out_snapshot->tail_last_record_crc32c = - patch->desired.tail_last_record_crc32c; + out_snapshot->tail_validation_kind = patch->desired.tail_validation_kind; + out_snapshot->validated_tail_lsn_exclusive + = patch->desired.validated_tail_lsn_exclusive; + out_snapshot->tail_last_record_lsn = patch->desired.tail_last_record_lsn; + out_snapshot->tail_last_record_crc32c = patch->desired.tail_last_record_crc32c; } if ((patch->mask & CLUSTER_CONTROL_ROOT_PATCH_RECOVERY_PROGRESS) != 0) { out_snapshot->root_flags = patch->desired.root_flags; out_snapshot->recovered_tli = patch->desired.recovered_tli; - out_snapshot->recovered_through_lsn_exclusive = - patch->desired.recovered_through_lsn_exclusive; - out_snapshot->recovered_last_record_lsn = - patch->desired.recovered_last_record_lsn; - out_snapshot->recovered_last_record_crc32c = - patch->desired.recovered_last_record_crc32c; + out_snapshot->recovered_through_lsn_exclusive + = patch->desired.recovered_through_lsn_exclusive; + out_snapshot->recovered_last_record_lsn = patch->desired.recovered_last_record_lsn; + out_snapshot->recovered_last_record_crc32c + = patch->desired.recovered_last_record_crc32c; } if ((patch->mask & CLUSTER_CONTROL_ROOT_PATCH_FPW_STICKY) != 0) out_snapshot->root_flags = patch->desired.root_flags; @@ -243,7 +234,7 @@ ExceptionalCondition(const char *conditionName, const char *fileName, int lineNu bool cluster_reconfig_capture_formation_snapshot_v1(uint16 origin_thread, - ClusterFormationSnapshotV1 *out) + ClusterFormationSnapshotV1 *out) { (void)origin_thread; (void)out; @@ -265,8 +256,8 @@ cluster_write_fence_authority_cache_sequence(void) bool cluster_write_fence_authority_cache_publish_if_unchanged(const ClusterFenceMarker *marker, - uint64 published_at_us, - uint64 expected_sequence) + uint64 published_at_us, + uint64 expected_sequence) { (void)marker; (void)published_at_us; @@ -378,8 +369,7 @@ sha256_bytes(const uint8 *bytes, size_t len, uint8 out[PG_SHA256_DIGEST_LENGTH]) { pg_cryptohash_ctx *ctx = pg_cryptohash_create(PG_SHA256); - if (ctx == NULL || pg_cryptohash_init(ctx) < 0 - || pg_cryptohash_update(ctx, bytes, len) < 0 + if (ctx == NULL || pg_cryptohash_init(ctx) < 0 || pg_cryptohash_update(ctx, bytes, len) < 0 || pg_cryptohash_final(ctx, out, PG_SHA256_DIGEST_LENGTH) < 0) abort(); pg_cryptohash_free(ctx); @@ -403,7 +393,7 @@ build_valid_key(ClusterRecoveryDutyKey *key) key->origin_node_id = 3; key->thread_claim_created_at = INT64_C(1700000000000123); cluster_wal_thread_claim_fill(&claim, key->origin_thread_id, key->origin_node_id, - key->thread_claim_created_at); + key->thread_claim_created_at); key->thread_claim_crc32c = claim.crc; key->origin_owner_incarnation = UINT64_C(0x1122334455667788); key->root_lineage_seq = UINT64_C(9); @@ -419,17 +409,14 @@ setup_owner_rejoin(uint64 old_incarnation, uint64 new_incarnation) ut_root_snapshot.identity.origin_owner_incarnation = old_incarnation; ut_root_identity = ut_root_snapshot.identity; ut_root_snapshot.lifecycle = CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_COMPLETE; - ut_root_snapshot.root_flags = CLUSTER_CONTROL_ROOT_FLAG_CLAIM_VALID - | CLUSTER_CONTROL_ROOT_FLAG_CHECKPOINT_VALID - | CLUSTER_CONTROL_ROOT_FLAG_TAIL_VALID - | CLUSTER_CONTROL_ROOT_FLAG_RECOVERED_VALID; + ut_root_snapshot.root_flags + = CLUSTER_CONTROL_ROOT_FLAG_CLAIM_VALID | CLUSTER_CONTROL_ROOT_FLAG_CHECKPOINT_VALID + | CLUSTER_CONTROL_ROOT_FLAG_TAIL_VALID | CLUSTER_CONTROL_ROOT_FLAG_RECOVERED_VALID; ut_root_snapshot.checkpoint_tli = 1; ut_root_snapshot.tail_tli = 1; ut_root_snapshot.recovered_tli = 1; - ut_root_snapshot.checkpoint_source_kind = - CLUSTER_CONTROL_ROOT_CHECKPOINT_NATIVE_V1; - ut_root_snapshot.tail_validation_kind = - CLUSTER_CONTROL_ROOT_TAIL_WAL_RECORD_SCAN_V1; + ut_root_snapshot.checkpoint_source_kind = CLUSTER_CONTROL_ROOT_CHECKPOINT_NATIVE_V1; + ut_root_snapshot.tail_validation_kind = CLUSTER_CONTROL_ROOT_TAIL_WAL_RECORD_SCAN_V1; ut_root_snapshot.checkpoint_lower_lsn = UINT64_C(0x1000000); ut_root_snapshot.validated_tail_lsn_exclusive = UINT64_C(0x1100000); ut_root_snapshot.recovered_through_lsn_exclusive = UINT64_C(0x1100000); @@ -466,21 +453,19 @@ static uint32 ut_ack_min_stage = 0; bool cluster_semantic_activation_ack_complete_matches( - uint64 transition_epoch, uint64 record_generation, - uint64 expected_members_lo, uint64 expected_members_hi, - uint64 source_feature_bitmap, uint64 target_feature_bitmap, - uint64 capability_sample_digest, - ClusterSemanticActivationAckStage minimum_stage) + uint64 transition_epoch, uint64 record_generation, uint64 expected_members_lo, + uint64 expected_members_hi, uint64 source_feature_bitmap, uint64 target_feature_bitmap, + uint64 capability_sample_digest, ClusterSemanticActivationAckStage minimum_stage) { ut_ack_complete_calls++; - ut_ack_min_stage = (uint32) minimum_stage; - (void) transition_epoch; - (void) record_generation; - (void) expected_members_lo; - (void) expected_members_hi; - (void) source_feature_bitmap; - (void) target_feature_bitmap; - (void) capability_sample_digest; + ut_ack_min_stage = (uint32)minimum_stage; + (void)transition_epoch; + (void)record_generation; + (void)expected_members_lo; + (void)expected_members_hi; + (void)source_feature_bitmap; + (void)target_feature_bitmap; + (void)capability_sample_digest; return ut_ack_complete_ok; } @@ -515,46 +500,35 @@ UT_TEST(test_checkpoint_advance_publishes_canonical_bound) setup_owner_rejoin(UINT64_C(70), UINT64_C(77)); ut_root_snapshot.lifecycle = CLUSTER_CONTROL_ROOT_LIFECYCLE_OPEN; UT_ASSERT(cluster_control_root_checkpoint_advance_publish( - UINT64_C(0x2000000), 1, UINT64_C(0x1fffff0), UINT64_C(0x2000020), - UINT32_C(0x44556677))); + UINT64_C(0x2000000), 1, UINT64_C(0x1fffff0), UINT64_C(0x2000020), UINT32_C(0x44556677))); UT_ASSERT_EQ(ut_root_publish_calls, 1); UT_ASSERT(ut_root_publish_context_authorized); UT_ASSERT_EQ((int)ut_root_published_reason, (int)CLUSTER_CONTROL_ROOT_PUBLISH_CHECKPOINT_ADVANCE); UT_ASSERT_EQ(ut_root_published_patch.mask, UINT64_C(0x38)); - UT_ASSERT_EQ(ut_root_published_patch.expected_lifecycle, - CLUSTER_CONTROL_ROOT_LIFECYCLE_OPEN); + UT_ASSERT_EQ(ut_root_published_patch.expected_lifecycle, CLUSTER_CONTROL_ROOT_LIFECYCLE_OPEN); /* The 0x38 mask has no LIFECYCLE bit: desired.lifecycle stays 0. */ - UT_ASSERT_EQ(ut_root_published_patch.desired.lifecycle, - CLUSTER_CONTROL_ROOT_LIFECYCLE_UNUSED); - UT_ASSERT_EQ(ut_root_published_patch.desired.checkpoint_lower_lsn, - UINT64_C(0x2000000)); - UT_ASSERT_EQ(ut_root_published_patch.desired.checkpoint_record_crc32c, - UINT32_C(0x44556677)); - UT_ASSERT_EQ(ut_root_published_patch.desired.validated_tail_lsn_exclusive, - UINT64_C(0x2000020)); - UT_ASSERT_EQ(ut_root_published_patch.desired.tail_last_record_lsn, - UINT64_C(0x1fffff0)); - UT_ASSERT_EQ(ut_root_published_patch.desired.tail_last_record_crc32c, - UINT32_C(0x44556677)); - UT_ASSERT_EQ( - ut_root_published_patch.desired.identity.origin_owner_incarnation, 0); + UT_ASSERT_EQ(ut_root_published_patch.desired.lifecycle, CLUSTER_CONTROL_ROOT_LIFECYCLE_UNUSED); + UT_ASSERT_EQ(ut_root_published_patch.desired.checkpoint_lower_lsn, UINT64_C(0x2000000)); + UT_ASSERT_EQ(ut_root_published_patch.desired.checkpoint_record_crc32c, UINT32_C(0x44556677)); + UT_ASSERT_EQ(ut_root_published_patch.desired.validated_tail_lsn_exclusive, UINT64_C(0x2000020)); + UT_ASSERT_EQ(ut_root_published_patch.desired.tail_last_record_lsn, UINT64_C(0x1fffff0)); + UT_ASSERT_EQ(ut_root_published_patch.desired.tail_last_record_crc32c, UINT32_C(0x44556677)); + UT_ASSERT_EQ(ut_root_published_patch.desired.identity.origin_owner_incarnation, 0); UT_ASSERT_EQ(ut_root_published_patch.desired.identity.root_lineage_seq, 0); /* A non-advancing redo (<= current bound) is a no-op: zero publishes. */ setup_owner_rejoin(UINT64_C(70), UINT64_C(77)); ut_root_snapshot.lifecycle = CLUSTER_CONTROL_ROOT_LIFECYCLE_OPEN; UT_ASSERT(!cluster_control_root_checkpoint_advance_publish( - UINT64_C(0x1000000), 1, UINT64_C(0xfffff0), UINT64_C(0x1000020), - UINT32_C(0x44556677))); + UINT64_C(0x1000000), 1, UINT64_C(0xfffff0), UINT64_C(0x1000020), UINT32_C(0x44556677))); UT_ASSERT_EQ(ut_root_publish_calls, 0); /* Not OPEN (e.g. CLOSED / RECOVERY_COMPLETE) is fail-closed. */ setup_owner_rejoin(UINT64_C(70), UINT64_C(77)); ut_root_snapshot.lifecycle = CLUSTER_CONTROL_ROOT_LIFECYCLE_CLOSED; UT_ASSERT(!cluster_control_root_checkpoint_advance_publish( - UINT64_C(0x2000000), 1, UINT64_C(0x1fffff0), UINT64_C(0x2000020), - UINT32_C(0x44556677))); + UINT64_C(0x2000000), 1, UINT64_C(0x1fffff0), UINT64_C(0x2000020), UINT32_C(0x44556677))); UT_ASSERT_EQ(ut_root_publish_calls, 0); } @@ -567,14 +541,11 @@ UT_TEST(test_fpw_sticky_publishes_canonical_flag) UT_ASSERT(cluster_control_root_fpw_sticky_publish()); UT_ASSERT_EQ(ut_root_publish_calls, 1); UT_ASSERT(ut_root_publish_context_authorized); - UT_ASSERT_EQ((int)ut_root_published_reason, - (int)CLUSTER_CONTROL_ROOT_PUBLISH_FPW_STICKY); - UT_ASSERT_EQ(ut_root_published_patch.mask, - CLUSTER_CONTROL_ROOT_PATCH_FPW_STICKY); - UT_ASSERT_EQ(ut_root_published_patch.expected_lifecycle, - CLUSTER_CONTROL_ROOT_LIFECYCLE_OPEN); - UT_ASSERT((ut_root_published_patch.desired.root_flags - & CLUSTER_CONTROL_ROOT_FLAG_FPW_WAS_OFF) != 0); + UT_ASSERT_EQ((int)ut_root_published_reason, (int)CLUSTER_CONTROL_ROOT_PUBLISH_FPW_STICKY); + UT_ASSERT_EQ(ut_root_published_patch.mask, CLUSTER_CONTROL_ROOT_PATCH_FPW_STICKY); + UT_ASSERT_EQ(ut_root_published_patch.expected_lifecycle, CLUSTER_CONTROL_ROOT_LIFECYCLE_OPEN); + UT_ASSERT((ut_root_published_patch.desired.root_flags & CLUSTER_CONTROL_ROOT_FLAG_FPW_WAS_OFF) + != 0); /* Already sticky is a no-op (the apply_patch guard never clears it). */ setup_owner_rejoin(UINT64_C(70), UINT64_C(77)); @@ -607,8 +578,8 @@ UT_TEST(test_create_authority_requires_complete_ack_round) round.prepare_generation = 7; round.transition_epoch = 3; round.source_feature_bitmap = UINT64_C(1); - round.target_feature_bitmap = - UINT64_C(1) | PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1; + round.target_feature_bitmap + = UINT64_C(1) | PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1; round.admitted_bitmap_low = UINT64_C(0x03); round.admitted_bitmap_high = 0; round.capability_sample_digest = UINT64_C(0xabcd); @@ -653,18 +624,17 @@ UT_TEST(test_create_authority_requires_complete_ack_round) ut_ack_complete_calls = 0; UT_ASSERT(!cluster_control_root_create_authority_current_v1(&image, &round)); UT_ASSERT_EQ(ut_ack_complete_calls, 1); - UT_ASSERT_EQ((int)ut_ack_min_stage, - (int)CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_SAMPLE); + UT_ASSERT_EQ((int)ut_ack_min_stage, (int)CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_SAMPLE); /* Target with an UNKNOWN feature bit + bit22 -> refused (whitelist * gate), with no ACK read (exempt round). */ - round.target_feature_bitmap = (UINT64_C(1) << 20) - | PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1; + round.target_feature_bitmap + = (UINT64_C(1) << 20) | PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1; ut_ack_complete_calls = 0; UT_ASSERT(!cluster_control_root_create_authority_current_v1(&image, &round)); UT_ASSERT_EQ(ut_ack_complete_calls, 0); - round.target_feature_bitmap = - UINT64_C(1) | PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1; + round.target_feature_bitmap + = UINT64_C(1) | PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1; } UT_TEST(test_activate_authority_requires_complete_ack_round) @@ -689,8 +659,8 @@ UT_TEST(test_activate_authority_requires_complete_ack_round) round.prepare_generation = 7; round.transition_epoch = 3; round.source_feature_bitmap = UINT64_C(1); - round.target_feature_bitmap = - UINT64_C(1) | PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1; + round.target_feature_bitmap + = UINT64_C(1) | PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1; round.admitted_bitmap_low = UINT64_C(0x03); round.admitted_bitmap_high = 0; round.capability_sample_digest = UINT64_C(0xabcd); @@ -704,61 +674,52 @@ UT_TEST(test_activate_authority_requires_complete_ack_round) ut_census_ok = false; ut_ack_complete_ok = true; ut_ack_complete_calls = 0; - UT_ASSERT(cluster_control_root_activate_authority_current_v1( - &token, sha, &round)); + UT_ASSERT(cluster_control_root_activate_authority_current_v1(&token, sha, &round)); UT_ASSERT_EQ(ut_ack_complete_calls, 1); /* ACK COMPLETE + bit22 target -> granted, and the activate proof * demands the PREPARED stage (W6 clause 3). */ ut_census_ok = true; ut_ack_min_stage = 0; - UT_ASSERT(cluster_control_root_activate_authority_current_v1( - &token, sha, &round)); - UT_ASSERT_EQ((int)ut_ack_min_stage, - (int)CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_PREPARED); + UT_ASSERT(cluster_control_root_activate_authority_current_v1(&token, sha, &round)); + UT_ASSERT_EQ((int)ut_ack_min_stage, (int)CLUSTER_SEMANTIC_ACTIVATION_ACK_STAGE_PREPARED); /* ACK not COMPLETE -> refused. */ ut_ack_complete_ok = false; ut_ack_complete_calls = 0; - UT_ASSERT(!cluster_control_root_activate_authority_current_v1( - &token, sha, &round)); + UT_ASSERT(!cluster_control_root_activate_authority_current_v1(&token, sha, &round)); UT_ASSERT_EQ(ut_ack_complete_calls, 1); ut_ack_complete_ok = true; /* Non-coordinator -> refused BEFORE any ACK read (fail-fast). */ cluster_node_id = 1; ut_ack_complete_calls = 0; - UT_ASSERT(!cluster_control_root_activate_authority_current_v1( - &token, sha, &round)); + UT_ASSERT(!cluster_control_root_activate_authority_current_v1(&token, sha, &round)); UT_ASSERT_EQ(ut_ack_complete_calls, 0); cluster_node_id = 0; /* Target WITHOUT bit22 -> refused (the bit22 cutover carrier). */ round.target_feature_bitmap = UINT64_C(1); ut_ack_complete_calls = 0; - UT_ASSERT(!cluster_control_root_activate_authority_current_v1( - &token, sha, &round)); + UT_ASSERT(!cluster_control_root_activate_authority_current_v1(&token, sha, &round)); UT_ASSERT_EQ(ut_ack_complete_calls, 1); - round.target_feature_bitmap = - UINT64_C(1) | PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1; + round.target_feature_bitmap + = UINT64_C(1) | PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1; /* Target with an UNKNOWN feature bit -> refused (whitelist gate). */ - round.target_feature_bitmap = (UINT64_C(1) << 20) - | PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1; + round.target_feature_bitmap + = (UINT64_C(1) << 20) | PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1; ut_ack_complete_calls = 0; - UT_ASSERT(!cluster_control_root_activate_authority_current_v1( - &token, sha, &round)); + UT_ASSERT(!cluster_control_root_activate_authority_current_v1(&token, sha, &round)); UT_ASSERT_EQ(ut_ack_complete_calls, 1); - round.target_feature_bitmap = - UINT64_C(1) | PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1; + round.target_feature_bitmap + = UINT64_C(1) | PGRAC_CONTROL_ROOT_FEATURE_RECOVERY_DUTY_IDENTITY_V1; /* NULL round / NULL sha -> refused before any read. */ ut_ack_complete_calls = 0; - UT_ASSERT(!cluster_control_root_activate_authority_current_v1( - &token, sha, NULL)); + UT_ASSERT(!cluster_control_root_activate_authority_current_v1(&token, sha, NULL)); UT_ASSERT_EQ(ut_ack_complete_calls, 0); - UT_ASSERT(!cluster_control_root_activate_authority_current_v1( - &token, NULL, &round)); + UT_ASSERT(!cluster_control_root_activate_authority_current_v1(&token, NULL, &round)); UT_ASSERT_EQ(ut_ack_complete_calls, 0); } @@ -773,16 +734,13 @@ UT_TEST(test_owner_rejoin_requires_jcmk_and_publishes_exact_root_cas) UT_ASSERT_EQ(ut_root_publish_calls, 1); UT_ASSERT(ut_root_publish_context_authorized); UT_ASSERT(!cluster_control_root_publish_authority_current_v1( - &ut_root_token, &ut_root_published_patch, - CLUSTER_CONTROL_ROOT_PUBLISH_OWNER_REJOIN)); + &ut_root_token, &ut_root_published_patch, CLUSTER_CONTROL_ROOT_PUBLISH_OWNER_REJOIN)); UT_ASSERT_EQ(ut_root_published_patch.mask, UINT64_C(0x3b)); UT_ASSERT_EQ(ut_root_published_patch.expected_lifecycle, CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_COMPLETE); - UT_ASSERT_EQ(ut_root_published_patch.desired.lifecycle, - CLUSTER_CONTROL_ROOT_LIFECYCLE_OPEN); - UT_ASSERT_EQ( - ut_root_published_patch.desired.identity.origin_owner_incarnation, - new_incarnation); + UT_ASSERT_EQ(ut_root_published_patch.desired.lifecycle, CLUSTER_CONTROL_ROOT_LIFECYCLE_OPEN); + UT_ASSERT_EQ(ut_root_published_patch.desired.identity.origin_owner_incarnation, + new_incarnation); UT_ASSERT_EQ(ut_root_published_patch.desired.identity.root_lineage_seq, ut_root_identity.root_lineage_seq + 1); } @@ -795,8 +753,7 @@ UT_TEST(test_owner_rejoin_publication_context_rejects_token_drift) UT_ASSERT_EQ(ut_root_publish_calls, 1); UT_ASSERT(!ut_root_publish_context_authorized); UT_ASSERT(!cluster_control_root_publish_authority_current_v1( - &ut_root_token, &ut_root_published_patch, - CLUSTER_CONTROL_ROOT_PUBLISH_OWNER_REJOIN)); + &ut_root_token, &ut_root_published_patch, CLUSTER_CONTROL_ROOT_PUBLISH_OWNER_REJOIN)); } UT_TEST(test_recovery_complete_uses_exact_private_publish_authority) @@ -807,30 +764,24 @@ UT_TEST(test_recovery_complete_uses_exact_private_publish_authority) ClusterControlRootResult result; setup_owner_rejoin(UINT64_C(70), UINT64_C(77)); - ut_root_snapshot.lifecycle = - CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_REQUIRED; + ut_root_snapshot.lifecycle = CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_REQUIRED; ut_root_token.lifecycle = ut_root_snapshot.lifecycle; memset(&patch, 0, sizeof(patch)); - patch.mask = CLUSTER_CONTROL_ROOT_PATCH_LIFECYCLE | - CLUSTER_CONTROL_ROOT_PATCH_RECOVERY_PROGRESS; - patch.expected_lifecycle = - CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_REQUIRED; - patch.desired.lifecycle = - CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_COMPLETE; - patch.desired.root_flags = ut_root_snapshot.root_flags | - CLUSTER_CONTROL_ROOT_FLAG_RECOVERED_VALID; + patch.mask + = CLUSTER_CONTROL_ROOT_PATCH_LIFECYCLE | CLUSTER_CONTROL_ROOT_PATCH_RECOVERY_PROGRESS; + patch.expected_lifecycle = CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_REQUIRED; + patch.desired.lifecycle = CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_COMPLETE; + patch.desired.root_flags + = ut_root_snapshot.root_flags | CLUSTER_CONTROL_ROOT_FLAG_RECOVERED_VALID; patch.desired.recovered_tli = ut_root_snapshot.tail_tli; - patch.desired.recovered_through_lsn_exclusive = - ut_root_snapshot.validated_tail_lsn_exclusive; - result = cluster_control_root_recovery_complete_publish_v1( - &ut_root_token, &patch, &published, &published_token); + patch.desired.recovered_through_lsn_exclusive = ut_root_snapshot.validated_tail_lsn_exclusive; + result = cluster_control_root_recovery_complete_publish_v1(&ut_root_token, &patch, &published, + &published_token); UT_ASSERT_EQ(result, CLUSTER_CONTROL_ROOT_OK_PRIMARY); UT_ASSERT_EQ(ut_root_publish_calls, 1); UT_ASSERT(ut_root_publish_context_authorized); - UT_ASSERT_EQ(ut_root_published_reason, - CLUSTER_CONTROL_ROOT_PUBLISH_RECOVERY_COMPLETE); - UT_ASSERT_EQ(published.lifecycle, - CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_COMPLETE); + UT_ASSERT_EQ(ut_root_published_reason, CLUSTER_CONTROL_ROOT_PUBLISH_RECOVERY_COMPLETE); + UT_ASSERT_EQ(published.lifecycle, CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_COMPLETE); } UT_TEST(test_owner_rejoin_rejects_open_stale_owner_frozen) @@ -885,8 +836,8 @@ UT_TEST(test_clean_close_retry_deadline_gives_up_fail_closed) ut_now_us = 1700000000000000LL; ut_waitlatch_calls = 0; UT_ASSERT(!cluster_control_root_thread_clean_close_publish_retry()); - UT_ASSERT(ut_root_publish_calls > 1); /* multiple attempts */ - UT_ASSERT(ut_waitlatch_calls >= 40); /* bounded: ~50 backoffs, never unbounded */ + UT_ASSERT(ut_root_publish_calls > 1); /* multiple attempts */ + UT_ASSERT(ut_waitlatch_calls >= 40); /* bounded: ~50 backoffs, never unbounded */ ut_root_publish_result = CLUSTER_CONTROL_ROOT_OK_PRIMARY; } @@ -905,15 +856,10 @@ UT_TEST(test_owner_rejoin_closed_lifecycle_routes_to_thread_open) UT_ASSERT_EQ(ut_owner_read_calls, 1); UT_ASSERT_EQ(ut_root_publish_calls, 1); UT_ASSERT(ut_root_publish_context_authorized); - UT_ASSERT_EQ((int)ut_root_published_reason, - (int)CLUSTER_CONTROL_ROOT_PUBLISH_THREAD_OPEN); - UT_ASSERT_EQ(ut_root_published_patch.expected_lifecycle, - CLUSTER_CONTROL_ROOT_LIFECYCLE_CLOSED); - UT_ASSERT_EQ(ut_root_published_patch.desired.lifecycle, - CLUSTER_CONTROL_ROOT_LIFECYCLE_OPEN); - UT_ASSERT_EQ( - ut_root_published_patch.desired.identity.origin_owner_incarnation, - UINT64_C(77)); + UT_ASSERT_EQ((int)ut_root_published_reason, (int)CLUSTER_CONTROL_ROOT_PUBLISH_THREAD_OPEN); + UT_ASSERT_EQ(ut_root_published_patch.expected_lifecycle, CLUSTER_CONTROL_ROOT_LIFECYCLE_CLOSED); + UT_ASSERT_EQ(ut_root_published_patch.desired.lifecycle, CLUSTER_CONTROL_ROOT_LIFECYCLE_OPEN); + UT_ASSERT_EQ(ut_root_published_patch.desired.identity.origin_owner_incarnation, UINT64_C(77)); UT_ASSERT_EQ(ut_root_published_patch.desired.identity.root_lineage_seq, ut_root_identity.root_lineage_seq + 1); @@ -993,8 +939,8 @@ build_expected_encoding(const ClusterRecoveryDutyKey *key, } static void -build_valid_formation(ClusterFormationSnapshotV1 *snapshot, - ClusterFenceAuthorityProof *proof, uint16 origin_thread) +build_valid_formation(ClusterFormationSnapshotV1 *snapshot, ClusterFenceAuthorityProof *proof, + uint16 origin_thread) { int32 origin_node = (int32)origin_thread - 1; @@ -1028,8 +974,7 @@ build_valid_formation(ClusterFormationSnapshotV1 *snapshot, } static void -build_owner_samples(ClusterRecoveryOwnerDiskSampleV1 samples[3], int32 node_id, - uint64 incarnation) +build_owner_samples(ClusterRecoveryOwnerDiskSampleV1 samples[3], int32 node_id, uint64 incarnation) { int i; @@ -1043,8 +988,8 @@ build_owner_samples(ClusterRecoveryOwnerDiskSampleV1 samples[3], int32 node_id, } static void -set_committed_join_marker(ClusterJoinCommitMarker *marker, int32 node_id, - uint64 incarnation, uint64 nonce) +set_committed_join_marker(ClusterJoinCommitMarker *marker, int32 node_id, uint64 incarnation, + uint64 nonce) { pg_crc32c crc; @@ -1074,8 +1019,8 @@ UT_TEST(test_owner_import_prefers_exact_jcmk_majority) set_committed_join_marker(&samples[0].join_marker, 3, 77, 11); samples[1].join_marker = samples[0].join_marker; set_committed_join_marker(&samples[2].join_marker, 3, 88, 12); - UT_ASSERT_EQ(cluster_recovery_owner_import_select_v1( - 3, &claim, UINT64_C(1) << 3, 0, samples, 3, &incarnation), + UT_ASSERT_EQ(cluster_recovery_owner_import_select_v1(3, &claim, UINT64_C(1) << 3, 0, samples, 3, + &incarnation), CLUSTER_RECOVERY_OWNER_IMPORT_JCMK); UT_ASSERT_EQ(incarnation, 77); } @@ -1091,8 +1036,8 @@ UT_TEST(test_owner_import_never_falls_back_from_split_jcmk) set_committed_join_marker(&samples[0].join_marker, 3, 77, 11); set_committed_join_marker(&samples[1].join_marker, 3, 88, 12); set_committed_join_marker(&samples[2].join_marker, 3, 99, 13); - UT_ASSERT_EQ(cluster_recovery_owner_import_select_v1( - 3, &claim, UINT64_C(1) << 3, 0, samples, 3, &incarnation), + UT_ASSERT_EQ(cluster_recovery_owner_import_select_v1(3, &claim, UINT64_C(1) << 3, 0, samples, 3, + &incarnation), CLUSTER_RECOVERY_OWNER_IMPORT_JCMK_UNPROVEN); UT_ASSERT_EQ(incarnation, 0); } @@ -1106,19 +1051,18 @@ UT_TEST(test_owner_import_slot_fallback_requires_absent_jcmk_and_claim) build_owner_samples(samples, 3, 70); samples[2].slot.incarnation = 71; cluster_wal_thread_claim_fill(&claim, 4, 3, INT64_C(12345)); - UT_ASSERT_EQ(cluster_recovery_owner_import_select_v1( - 3, &claim, UINT64_C(1) << 3, 0, samples, 3, &incarnation), + UT_ASSERT_EQ(cluster_recovery_owner_import_select_v1(3, &claim, UINT64_C(1) << 3, 0, samples, 3, + &incarnation), CLUSTER_RECOVERY_OWNER_IMPORT_VOTING_SLOT); UT_ASSERT_EQ(incarnation, 70); claim.node_id = 4; incarnation = UINT64_C(0xdeadbeef); - UT_ASSERT_EQ(cluster_recovery_owner_import_select_v1( - 3, &claim, UINT64_C(1) << 3, 0, samples, 3, &incarnation), + UT_ASSERT_EQ(cluster_recovery_owner_import_select_v1(3, &claim, UINT64_C(1) << 3, 0, samples, 3, + &incarnation), CLUSTER_RECOVERY_OWNER_IMPORT_CLAIM_MISMATCH); UT_ASSERT_EQ(incarnation, 0); cluster_wal_thread_claim_fill(&claim, 4, 3, INT64_C(12345)); - UT_ASSERT_EQ(cluster_recovery_owner_import_select_v1( - 3, &claim, 0, 0, samples, 3, &incarnation), + UT_ASSERT_EQ(cluster_recovery_owner_import_select_v1(3, &claim, 0, 0, samples, 3, &incarnation), CLUSTER_RECOVERY_OWNER_IMPORT_SLOT_UNPROVEN); } @@ -1131,8 +1075,8 @@ UT_TEST(test_owner_import_cannot_prove_jcmk_absence_with_unreadable_disk) build_owner_samples(samples, 3, 70); samples[2].join_io_state = CLUSTER_VOTING_DISK_IO_FAILED; cluster_wal_thread_claim_fill(&claim, 4, 3, INT64_C(12345)); - UT_ASSERT_EQ(cluster_recovery_owner_import_select_v1( - 3, &claim, UINT64_C(1) << 3, 0, samples, 3, &incarnation), + UT_ASSERT_EQ(cluster_recovery_owner_import_select_v1(3, &claim, UINT64_C(1) << 3, 0, samples, 3, + &incarnation), CLUSTER_RECOVERY_OWNER_IMPORT_IO_FAILED); UT_ASSERT_EQ(incarnation, 0); } @@ -1204,11 +1148,12 @@ assert_invalid_key(ClusterRecoveryDutyKey *key) memset(encoded, 0xee, sizeof(encoded)); memset(&digest, 0xee, sizeof(digest)); UT_ASSERT(!cluster_recovery_duty_key_encode_v1(key, encoded)); - UT_ASSERT(memcmp(encoded, (uint8[CLUSTER_RECOVERY_DUTY_KEY_V1_BYTES]){0}, - sizeof(encoded)) == 0); + UT_ASSERT(memcmp(encoded, (uint8[CLUSTER_RECOVERY_DUTY_KEY_V1_BYTES]){ 0 }, sizeof(encoded)) + == 0); UT_ASSERT(!cluster_recovery_duty_digest_v1(key, &digest)); - UT_ASSERT(memcmp(digest.bytes, (uint8[CLUSTER_RECOVERY_DUTY_DIGEST_BYTES]){0}, - sizeof(digest.bytes)) == 0); + UT_ASSERT( + memcmp(digest.bytes, (uint8[CLUSTER_RECOVERY_DUTY_DIGEST_BYTES]){ 0 }, sizeof(digest.bytes)) + == 0); UT_ASSERT_EQ(cluster_recovery_duty_key_compare(key, &valid), CLUSTER_RECOVERY_DUTY_COMPARE_INVALID); } diff --git a/src/test/cluster_unit/test_cluster_recovery_merge.c b/src/test/cluster_unit/test_cluster_recovery_merge.c index 19207743672..ed494b615e5 100644 --- a/src/test/cluster_unit/test_cluster_recovery_merge.c +++ b/src/test/cluster_unit/test_cluster_recovery_merge.c @@ -497,45 +497,39 @@ UT_TEST(test_claim_classify_rejections) * strictly ascending origin vector names every foreign bit once. */ UT_TEST(test_external_fence_plan_shape_exact) { - uint64 replay[2] = {0, 0}; - uint64 foreign[2] = {0, 0}; - uint16 origins[2] = {2, 65}; + uint64 replay[2] = { 0, 0 }; + uint64 foreign[2] = { 0, 0 }; + uint16 origins[2] = { 2, 65 }; - replay[0] = UINT64_C(1) << 0; /* own thread 1 */ + replay[0] = UINT64_C(1) << 0; /* own thread 1 */ replay[0] |= UINT64_C(1) << 1; /* foreign thread 2 */ - replay[1] = UINT64_C(1) << 0; /* foreign thread 65 */ + replay[1] = UINT64_C(1) << 0; /* foreign thread 65 */ foreign[0] = UINT64_C(1) << 1; foreign[1] = UINT64_C(1) << 0; - UT_ASSERT(cluster_recovery_fence_plan_shape_valid( - 1, replay, foreign, origins, 2)); + UT_ASSERT(cluster_recovery_fence_plan_shape_valid(1, replay, foreign, origins, 2)); /* A missing proof-origin bit, duplicate/out-of-order vector entry, or * replay set without own is never a partial success. */ foreign[1] = 0; - UT_ASSERT(!cluster_recovery_fence_plan_shape_valid( - 1, replay, foreign, origins, 2)); + UT_ASSERT(!cluster_recovery_fence_plan_shape_valid(1, replay, foreign, origins, 2)); foreign[1] = UINT64_C(1) << 0; origins[1] = 2; - UT_ASSERT(!cluster_recovery_fence_plan_shape_valid( - 1, replay, foreign, origins, 2)); + UT_ASSERT(!cluster_recovery_fence_plan_shape_valid(1, replay, foreign, origins, 2)); origins[1] = 65; replay[0] &= ~(UINT64_C(1) << 0); - UT_ASSERT(!cluster_recovery_fence_plan_shape_valid( - 1, replay, foreign, origins, 2)); + UT_ASSERT(!cluster_recovery_fence_plan_shape_valid(1, replay, foreign, origins, 2)); } UT_TEST(test_external_fence_plan_native_and_restore_gate) { - uint64 bitmap[2] = {UINT64_C(1) << 2, 0}; /* own thread 3 only */ + uint64 bitmap[2] = { UINT64_C(1) << 2, 0 }; /* own thread 3 only */ uint16 foreign_thread = 0; - UT_ASSERT(cluster_recovery_fence_plan_shape_valid( - 3, bitmap, (uint64[2]){0, 0}, NULL, 0)); + UT_ASSERT(cluster_recovery_fence_plan_shape_valid(3, bitmap, (uint64[2]){ 0, 0 }, NULL, 0)); UT_ASSERT(!cluster_recovery_restore_has_foreign(bitmap, 3)); bitmap[0] |= UINT64_C(1) << 6; UT_ASSERT(cluster_recovery_restore_has_foreign(bitmap, 3)); - UT_ASSERT(cluster_recovery_restore_first_foreign( - bitmap, 3, &foreign_thread)); + UT_ASSERT(cluster_recovery_restore_first_foreign(bitmap, 3, &foreign_thread)); UT_ASSERT_EQ(foreign_thread, 7); UT_ASSERT(cluster_recovery_restore_has_foreign(bitmap, 0)); } diff --git a/src/test/cluster_unit/test_cluster_recovery_plan.c b/src/test/cluster_unit/test_cluster_recovery_plan.c index 0a88072be71..5fd885c0de6 100644 --- a/src/test/cluster_unit/test_cluster_recovery_plan.c +++ b/src/test/cluster_unit/test_cluster_recovery_plan.c @@ -234,8 +234,8 @@ UT_TEST(test_node_id_out_of_range_is_unknown) * ---- UNKNOWN (fail-closed). */ #define ROOT_TID ((uint16)9) -#define ROOT_NODE ((int32)8) /* tid - 1 invariant */ -#define ROOT_CKPT 300 /* 300s checkpoint_timeout -> 600s threshold */ +#define ROOT_NODE ((int32)8) /* tid - 1 invariant */ +#define ROOT_CKPT 300 /* 300s checkpoint_timeout -> 600s threshold */ /* Fresh: well inside the 600s threshold. */ #define ROOT_FRESH_US (NOW_US - (int64)60 * 1000000) @@ -257,10 +257,9 @@ UT_TEST(test_root_absent_is_empty) ClusterControlRootSnapshot snap; fill_root_snapshot(&snap, CLUSTER_CONTROL_ROOT_LIFECYCLE_OPEN, ROOT_FRESH_US); - UT_ASSERT_EQ( - (int)cluster_recovery_classify_root_slot( - CLUSTER_CONTROL_ROOT_ABSENT, &snap, OWN_TID, ROOT_TID, NOW_US, ROOT_CKPT), - (int)CLUSTER_RECOVERY_THREAD_EMPTY); + UT_ASSERT_EQ((int)cluster_recovery_classify_root_slot(CLUSTER_CONTROL_ROOT_ABSENT, &snap, + OWN_TID, ROOT_TID, NOW_US, ROOT_CKPT), + (int)CLUSTER_RECOVERY_THREAD_EMPTY); } UT_TEST(test_root_closed_is_clean) @@ -268,10 +267,9 @@ UT_TEST(test_root_closed_is_clean) ClusterControlRootSnapshot snap; fill_root_snapshot(&snap, CLUSTER_CONTROL_ROOT_LIFECYCLE_CLOSED, ROOT_STALE_US); - UT_ASSERT_EQ( - (int)cluster_recovery_classify_root_slot( - CLUSTER_CONTROL_ROOT_OK_PRIMARY, &snap, OWN_TID, ROOT_TID, NOW_US, ROOT_CKPT), - (int)CLUSTER_RECOVERY_THREAD_CLEAN); + UT_ASSERT_EQ((int)cluster_recovery_classify_root_slot(CLUSTER_CONTROL_ROOT_OK_PRIMARY, &snap, + OWN_TID, ROOT_TID, NOW_US, ROOT_CKPT), + (int)CLUSTER_RECOVERY_THREAD_CLEAN); } UT_TEST(test_root_open_fresh_is_alive) @@ -279,10 +277,9 @@ UT_TEST(test_root_open_fresh_is_alive) ClusterControlRootSnapshot snap; fill_root_snapshot(&snap, CLUSTER_CONTROL_ROOT_LIFECYCLE_OPEN, ROOT_FRESH_US); - UT_ASSERT_EQ( - (int)cluster_recovery_classify_root_slot( - CLUSTER_CONTROL_ROOT_OK_PRIMARY, &snap, OWN_TID, ROOT_TID, NOW_US, ROOT_CKPT), - (int)CLUSTER_RECOVERY_THREAD_ALIVE); + UT_ASSERT_EQ((int)cluster_recovery_classify_root_slot(CLUSTER_CONTROL_ROOT_OK_PRIMARY, &snap, + OWN_TID, ROOT_TID, NOW_US, ROOT_CKPT), + (int)CLUSTER_RECOVERY_THREAD_ALIVE); } UT_TEST(test_root_open_stale_is_crashed_candidate) @@ -290,10 +287,9 @@ UT_TEST(test_root_open_stale_is_crashed_candidate) ClusterControlRootSnapshot snap; fill_root_snapshot(&snap, CLUSTER_CONTROL_ROOT_LIFECYCLE_OPEN, ROOT_STALE_US); - UT_ASSERT_EQ( - (int)cluster_recovery_classify_root_slot( - CLUSTER_CONTROL_ROOT_OK_PRIMARY, &snap, OWN_TID, ROOT_TID, NOW_US, ROOT_CKPT), - (int)CLUSTER_RECOVERY_THREAD_CRASHED_CANDIDATE); + UT_ASSERT_EQ((int)cluster_recovery_classify_root_slot(CLUSTER_CONTROL_ROOT_OK_PRIMARY, &snap, + OWN_TID, ROOT_TID, NOW_US, ROOT_CKPT), + (int)CLUSTER_RECOVERY_THREAD_CRASHED_CANDIDATE); } UT_TEST(test_root_threshold_boundary_exact_is_alive) @@ -302,20 +298,17 @@ UT_TEST(test_root_threshold_boundary_exact_is_alive) /* Exactly 600s old == threshold: ALIVE (age < threshold is ALIVE; * the boundary is included in the alive side). */ - fill_root_snapshot(&snap, CLUSTER_CONTROL_ROOT_LIFECYCLE_OPEN, - NOW_US - (int64)600 * 1000000); - UT_ASSERT_EQ( - (int)cluster_recovery_classify_root_slot( - CLUSTER_CONTROL_ROOT_OK_PRIMARY, &snap, OWN_TID, ROOT_TID, NOW_US, ROOT_CKPT), - (int)CLUSTER_RECOVERY_THREAD_ALIVE); + fill_root_snapshot(&snap, CLUSTER_CONTROL_ROOT_LIFECYCLE_OPEN, NOW_US - (int64)600 * 1000000); + UT_ASSERT_EQ((int)cluster_recovery_classify_root_slot(CLUSTER_CONTROL_ROOT_OK_PRIMARY, &snap, + OWN_TID, ROOT_TID, NOW_US, ROOT_CKPT), + (int)CLUSTER_RECOVERY_THREAD_ALIVE); /* 600s + 1us: CRASHED_CANDIDATE. */ fill_root_snapshot(&snap, CLUSTER_CONTROL_ROOT_LIFECYCLE_OPEN, NOW_US - (int64)600 * 1000000 - 1); - UT_ASSERT_EQ( - (int)cluster_recovery_classify_root_slot( - CLUSTER_CONTROL_ROOT_OK_PRIMARY, &snap, OWN_TID, ROOT_TID, NOW_US, ROOT_CKPT), - (int)CLUSTER_RECOVERY_THREAD_CRASHED_CANDIDATE); + UT_ASSERT_EQ((int)cluster_recovery_classify_root_slot(CLUSTER_CONTROL_ROOT_OK_PRIMARY, &snap, + OWN_TID, ROOT_TID, NOW_US, ROOT_CKPT), + (int)CLUSTER_RECOVERY_THREAD_CRASHED_CANDIDATE); } UT_TEST(test_root_future_published_is_alive) @@ -324,10 +317,9 @@ UT_TEST(test_root_future_published_is_alive) /* Clock skew: a future publication timestamp must err ALIVE. */ fill_root_snapshot(&snap, CLUSTER_CONTROL_ROOT_LIFECYCLE_OPEN, NOW_US + 5000000); - UT_ASSERT_EQ( - (int)cluster_recovery_classify_root_slot( - CLUSTER_CONTROL_ROOT_OK_PRIMARY, &snap, OWN_TID, ROOT_TID, NOW_US, ROOT_CKPT), - (int)CLUSTER_RECOVERY_THREAD_ALIVE); + UT_ASSERT_EQ((int)cluster_recovery_classify_root_slot(CLUSTER_CONTROL_ROOT_OK_PRIMARY, &snap, + OWN_TID, ROOT_TID, NOW_US, ROOT_CKPT), + (int)CLUSTER_RECOVERY_THREAD_ALIVE); } UT_TEST(test_root_non_open_lifecycle_is_unknown) @@ -343,10 +335,10 @@ UT_TEST(test_root_non_open_lifecycle_is_unknown) for (i = 0; i < lengthof(lifecycles); i++) { fill_root_snapshot(&snap, lifecycles[i], ROOT_FRESH_US); - UT_ASSERT_EQ( - (int)cluster_recovery_classify_root_slot( - CLUSTER_CONTROL_ROOT_OK_PRIMARY, &snap, OWN_TID, ROOT_TID, NOW_US, ROOT_CKPT), - (int)CLUSTER_RECOVERY_THREAD_UNKNOWN); + UT_ASSERT_EQ((int)cluster_recovery_classify_root_slot(CLUSTER_CONTROL_ROOT_OK_PRIMARY, + &snap, OWN_TID, ROOT_TID, NOW_US, + ROOT_CKPT), + (int)CLUSTER_RECOVERY_THREAD_UNKNOWN); } } @@ -357,10 +349,9 @@ UT_TEST(test_root_identity_violation_is_unknown) /* Node id breaks the tid-1 invariant: never ALIVE/CRASHED. */ fill_root_snapshot(&snap, CLUSTER_CONTROL_ROOT_LIFECYCLE_OPEN, ROOT_STALE_US); snap.identity.origin_node_id = ROOT_NODE - 1; - UT_ASSERT_EQ( - (int)cluster_recovery_classify_root_slot( - CLUSTER_CONTROL_ROOT_OK_PRIMARY, &snap, OWN_TID, ROOT_TID, NOW_US, ROOT_CKPT), - (int)CLUSTER_RECOVERY_THREAD_UNKNOWN); + UT_ASSERT_EQ((int)cluster_recovery_classify_root_slot(CLUSTER_CONTROL_ROOT_OK_PRIMARY, &snap, + OWN_TID, ROOT_TID, NOW_US, ROOT_CKPT), + (int)CLUSTER_RECOVERY_THREAD_UNKNOWN); } UT_TEST(test_root_read_failure_is_unknown) @@ -368,14 +359,13 @@ UT_TEST(test_root_read_failure_is_unknown) ClusterControlRootSnapshot snap; fill_root_snapshot(&snap, CLUSTER_CONTROL_ROOT_LIFECYCLE_OPEN, ROOT_FRESH_US); - UT_ASSERT_EQ( - (int)cluster_recovery_classify_root_slot( - CLUSTER_CONTROL_ROOT_IO_ERROR, &snap, OWN_TID, ROOT_TID, NOW_US, ROOT_CKPT), - (int)CLUSTER_RECOVERY_THREAD_UNKNOWN); - UT_ASSERT_EQ( - (int)cluster_recovery_classify_root_slot( - CLUSTER_CONTROL_ROOT_OK_BAK_BLOCKED, &snap, OWN_TID, ROOT_TID, NOW_US, ROOT_CKPT), - (int)CLUSTER_RECOVERY_THREAD_UNKNOWN); + UT_ASSERT_EQ((int)cluster_recovery_classify_root_slot(CLUSTER_CONTROL_ROOT_IO_ERROR, &snap, + OWN_TID, ROOT_TID, NOW_US, ROOT_CKPT), + (int)CLUSTER_RECOVERY_THREAD_UNKNOWN); + UT_ASSERT_EQ((int)cluster_recovery_classify_root_slot(CLUSTER_CONTROL_ROOT_OK_BAK_BLOCKED, + &snap, OWN_TID, ROOT_TID, NOW_US, + ROOT_CKPT), + (int)CLUSTER_RECOVERY_THREAD_UNKNOWN); } UT_TEST(test_root_own_thread_priority) @@ -384,10 +374,9 @@ UT_TEST(test_root_own_thread_priority) /* Own thread wins regardless of record state. */ fill_root_snapshot(&snap, CLUSTER_CONTROL_ROOT_LIFECYCLE_CLOSED, ROOT_STALE_US); - UT_ASSERT_EQ( - (int)cluster_recovery_classify_root_slot( - CLUSTER_CONTROL_ROOT_OK_PRIMARY, &snap, OWN_TID, OWN_TID, NOW_US, ROOT_CKPT), - (int)CLUSTER_RECOVERY_THREAD_OWN); + UT_ASSERT_EQ((int)cluster_recovery_classify_root_slot(CLUSTER_CONTROL_ROOT_OK_PRIMARY, &snap, + OWN_TID, OWN_TID, NOW_US, ROOT_CKPT), + (int)CLUSTER_RECOVERY_THREAD_OWN); } UT_TEST(test_root_floor_60s_dominates_tiny_checkpoint) @@ -396,12 +385,10 @@ UT_TEST(test_root_floor_60s_dominates_tiny_checkpoint) /* checkpoint_timeout=1s would give a 2s threshold; the 60s floor * keeps a live peer alive for at least a minute. */ - fill_root_snapshot(&snap, CLUSTER_CONTROL_ROOT_LIFECYCLE_OPEN, - NOW_US - (int64)30 * 1000000); - UT_ASSERT_EQ( - (int)cluster_recovery_classify_root_slot( - CLUSTER_CONTROL_ROOT_OK_PRIMARY, &snap, OWN_TID, ROOT_TID, NOW_US, 1), - (int)CLUSTER_RECOVERY_THREAD_ALIVE); + fill_root_snapshot(&snap, CLUSTER_CONTROL_ROOT_LIFECYCLE_OPEN, NOW_US - (int64)30 * 1000000); + UT_ASSERT_EQ((int)cluster_recovery_classify_root_slot(CLUSTER_CONTROL_ROOT_OK_PRIMARY, &snap, + OWN_TID, ROOT_TID, NOW_US, 1), + (int)CLUSTER_RECOVERY_THREAD_ALIVE); } UT_TEST(test_bitmap_addressing_locks) @@ -582,8 +569,7 @@ UT_TEST(test_pin_fill_copies_every_field) UT_ASSERT(memcmp(&slot.pin_token, &token, sizeof(token)) == 0); UT_ASSERT_EQ((long long)slot.pin_validated_tail, 0x2000000LL); UT_ASSERT_EQ((long long)slot.pin_checkpoint_lower, 0x1000000LL); - UT_ASSERT_EQ((long long)slot.pin_lifecycle, - (long long)CLUSTER_CONTROL_ROOT_LIFECYCLE_OPEN); + UT_ASSERT_EQ((long long)slot.pin_lifecycle, (long long)CLUSTER_CONTROL_ROOT_LIFECYCLE_OPEN); UT_ASSERT_EQ((int)slot.pin_tail_tli, 7); UT_ASSERT_EQ((int)slot.pin_checkpoint_tli, 6); /* The pin fill must not touch the state/episode gate fields. */ @@ -624,14 +610,14 @@ UT_TEST(test_projection_read_rejects_stale_episode) memset(&slot, 0, sizeof(slot)); pg_atomic_init_u64(&slot.episode_epoch, 0); pg_atomic_init_u32(&slot.state, 0); /* CLUSTER_THREADREC_REPLAY_IDLE */ - UT_ASSERT(!cluster_thread_recovery_projection_read( - &slot, 42, &token, &validated_tail, &checkpoint_lower, &lifecycle, - &tail_tli, &checkpoint_tli)); + UT_ASSERT(!cluster_thread_recovery_projection_read(&slot, 42, &token, &validated_tail, + &checkpoint_lower, &lifecycle, &tail_tli, + &checkpoint_tli)); /* NULL slot -> fail-closed. */ - UT_ASSERT(!cluster_thread_recovery_projection_read( - NULL, 42, &token, &validated_tail, &checkpoint_lower, &lifecycle, - &tail_tli, &checkpoint_tli)); + UT_ASSERT(!cluster_thread_recovery_projection_read(NULL, 42, &token, &validated_tail, + &checkpoint_lower, &lifecycle, &tail_tli, + &checkpoint_tli)); } UT_TEST(test_projection_read_matching_episode_returns_pinned_fields) @@ -653,9 +639,9 @@ UT_TEST(test_projection_read_matching_episode_returns_pinned_fields) pg_atomic_init_u64(&slot.episode_epoch, 42); pg_atomic_init_u32(&slot.state, 0); /* CLUSTER_THREADREC_REPLAY_IDLE */ - UT_ASSERT(cluster_thread_recovery_projection_read( - &slot, 42, &token, &validated_tail, &checkpoint_lower, &lifecycle, - &tail_tli, &checkpoint_tli)); + UT_ASSERT(cluster_thread_recovery_projection_read(&slot, 42, &token, &validated_tail, + &checkpoint_lower, &lifecycle, &tail_tli, + &checkpoint_tli)); UT_ASSERT(memcmp(&token, &expected_token, sizeof(token)) == 0); UT_ASSERT_EQ((long long)validated_tail, 0x2000000LL); UT_ASSERT_EQ((long long)checkpoint_lower, 0x1000000LL); @@ -664,9 +650,9 @@ UT_TEST(test_projection_read_matching_episode_returns_pinned_fields) UT_ASSERT_EQ((int)checkpoint_tli, 6); /* A later episode invalidates the projection (episode 43). */ - UT_ASSERT(!cluster_thread_recovery_projection_read( - &slot, 43, &token, &validated_tail, &checkpoint_lower, &lifecycle, - &tail_tli, &checkpoint_tli)); + UT_ASSERT(!cluster_thread_recovery_projection_read(&slot, 43, &token, &validated_tail, + &checkpoint_lower, &lifecycle, &tail_tli, + &checkpoint_tli)); } diff --git a/src/test/cluster_unit/test_cluster_recovery_serial.c b/src/test/cluster_unit/test_cluster_recovery_serial.c index a5ed6a7c662..c59228f3f6c 100644 --- a/src/test/cluster_unit/test_cluster_recovery_serial.c +++ b/src/test/cluster_unit/test_cluster_recovery_serial.c @@ -53,16 +53,14 @@ static union { uint64 align; char bytes[4096]; } fake_ir_shmem; -static ClusterLockAcquireResult stub_acquire_result - = CLUSTER_LOCK_ACQUIRE_FAIL_INTERNAL; +static ClusterLockAcquireResult stub_acquire_result = CLUSTER_LOCK_ACQUIRE_FAIL_INTERNAL; static uint32 stub_acquire_calls; static bool stub_formation_ready; static bool stub_need_set_ready; static bool stub_admission_set_ready; static ClusterControlRootResult stub_root_result; static ClusterControlRootReadToken stub_root_token; -static ClusterLockAcquireResult stub_release_result - = CLUSTER_LOCK_ACQUIRE_FAIL_INTERNAL; +static ClusterLockAcquireResult stub_release_result = CLUSTER_LOCK_ACQUIRE_FAIL_INTERNAL; static ClusterLockAcquireResult stub_release_results[CLUSTER_RECOVERY_SERIAL_SET_MAX]; static uint16 stub_release_result_count; static uint16 stub_release_result_index; @@ -77,8 +75,7 @@ GetCurrentTimestamp(void) } void * -ShmemInitStruct(const char *name pg_attribute_unused(), Size size, - bool *found) +ShmemInitStruct(const char *name pg_attribute_unused(), Size size, bool *found) { UT_ASSERT(size <= sizeof(fake_ir_shmem.bytes)); *found = false; @@ -87,17 +84,13 @@ ShmemInitStruct(const char *name pg_attribute_unused(), Size size, } void -cluster_shmem_register_region( - const ClusterShmemRegion *region pg_attribute_unused()) -{ -} +cluster_shmem_register_region(const ClusterShmemRegion *region pg_attribute_unused()) +{} ClusterLockAcquireResult -cluster_lock_acquire_seven_step( - const ClusterLockAcquireRequest *request) +cluster_lock_acquire_seven_step(const ClusterLockAcquireRequest *request) { - ClusterLockAcquireRequest *mutable_request = - (ClusterLockAcquireRequest *)request; + ClusterLockAcquireRequest *mutable_request = (ClusterLockAcquireRequest *)request; stub_acquire_calls++; mutable_request->request_id = UINT64_C(9001); @@ -109,27 +102,23 @@ cluster_lock_acquire_seven_step( } ClusterLockAcquireResult -cluster_lock_acquire_s5_promote( - const ClusterLockAcquireRequest *request pg_attribute_unused()) +cluster_lock_acquire_s5_promote(const ClusterLockAcquireRequest *request pg_attribute_unused()) { return CLUSTER_LOCK_ACQUIRE_OK_GRANTED; } ClusterControlRootResult -cluster_control_root_read_canonical( - uint16 origin_thread_id pg_attribute_unused(), - const ClusterControlRootIdentity *expected_identity, - ClusterControlRootReadMode mode pg_attribute_unused(), - ClusterControlRootSnapshot *out_snapshot, - ClusterControlRootReadToken *out_token) -{ - if (out_snapshot != NULL) - { +cluster_control_root_read_canonical(uint16 origin_thread_id pg_attribute_unused(), + const ClusterControlRootIdentity *expected_identity, + ClusterControlRootReadMode mode pg_attribute_unused(), + ClusterControlRootSnapshot *out_snapshot, + ClusterControlRootReadToken *out_token) +{ + if (out_snapshot != NULL) { memset(out_snapshot, 0, sizeof(*out_snapshot)); if (expected_identity != NULL) out_snapshot->identity = *expected_identity; - out_snapshot->lifecycle = - CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_REQUIRED; + out_snapshot->lifecycle = CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_REQUIRED; out_snapshot->root_flags = stub_root_token.root_flags; } if (out_token != NULL) @@ -141,20 +130,20 @@ ClusterFormationWitnessResult cluster_formation_witness_revalidate_nowait( const ClusterFormationWitnessV1 *witness pg_attribute_unused()) { - return stub_formation_ready ? CLUSTER_FORMATION_WITNESS_READY : - CLUSTER_FORMATION_WITNESS_UNSTABLE; + return stub_formation_ready ? CLUSTER_FORMATION_WITNESS_READY + : CLUSTER_FORMATION_WITNESS_UNSTABLE; } ClusterRecoveryDutyCompare cluster_recovery_duty_key_compare(const ClusterRecoveryDutyKey *expected, const ClusterRecoveryDutyKey *observed) { - if (!cluster_recovery_duty_key_valid_v1(expected) || - !cluster_recovery_duty_key_valid_v1(observed)) + if (!cluster_recovery_duty_key_valid_v1(expected) + || !cluster_recovery_duty_key_valid_v1(observed)) return CLUSTER_RECOVERY_DUTY_COMPARE_INVALID; - return memcmp(expected, observed, sizeof(*expected)) == 0 ? - CLUSTER_RECOVERY_DUTY_COMPARE_EXACT : - CLUSTER_RECOVERY_DUTY_COMPARE_DIFFERENT; + return memcmp(expected, observed, sizeof(*expected)) == 0 + ? CLUSTER_RECOVERY_DUTY_COMPARE_EXACT + : CLUSTER_RECOVERY_DUTY_COMPARE_DIFFERENT; } bool @@ -164,8 +153,8 @@ cluster_external_fence_need_set_revalidate_nowait( PgracExternalFenceDenyReason *reason) { if (reason != NULL) - *reason = stub_need_set_ready ? PGRAC_EXTERNAL_FENCE_DENY_NONE : - PGRAC_EXTERNAL_FENCE_DENY_WRITER_SET_STALE; + *reason = stub_need_set_ready ? PGRAC_EXTERNAL_FENCE_DENY_NONE + : PGRAC_EXTERNAL_FENCE_DENY_WRITER_SET_STALE; return stub_need_set_ready; } @@ -177,8 +166,8 @@ cluster_external_fence_revalidate_set_nowait( PgracExternalFenceDenyReason *reason) { if (reason != NULL) - *reason = stub_admission_set_ready ? PGRAC_EXTERNAL_FENCE_DENY_NONE : - PGRAC_EXTERNAL_FENCE_DENY_EXPIRED; + *reason = stub_admission_set_ready ? PGRAC_EXTERNAL_FENCE_DENY_NONE + : PGRAC_EXTERNAL_FENCE_DENY_EXPIRED; return stub_admission_set_ready; } @@ -215,16 +204,13 @@ valid_duty(uint16 origin_thread, uint64 lineage) duty.storage_uuid[i] = (uint8)(i + 1); duty.authority_uuid[i] = (uint8)(0x80 + i); } - duty.authority_uuid[6] - = (duty.authority_uuid[6] & UINT8_C(0x0f)) | UINT8_C(0x40); - duty.authority_uuid[8] - = (duty.authority_uuid[8] & UINT8_C(0x3f)) | UINT8_C(0x80); + duty.authority_uuid[6] = (duty.authority_uuid[6] & UINT8_C(0x0f)) | UINT8_C(0x40); + duty.authority_uuid[8] = (duty.authority_uuid[8] & UINT8_C(0x3f)) | UINT8_C(0x80); duty.origin_thread_id = origin_thread; duty.origin_node_id = (int32)origin_thread - 1; duty.thread_claim_created_at = INT64_C(0x1112131415161718); - cluster_wal_thread_claim_fill(&claim, duty.origin_thread_id, - duty.origin_node_id, - duty.thread_claim_created_at); + cluster_wal_thread_claim_fill(&claim, duty.origin_thread_id, duty.origin_node_id, + duty.thread_claim_created_at); duty.thread_claim_crc32c = claim.crc; duty.origin_owner_incarnation = UINT64_C(77); duty.root_lineage_seq = lineage; @@ -242,26 +228,20 @@ valid_held_guard(void) guard.duty = valid_duty(3, UINT64_C(100)); guard.root_read_token.origin_thread_id = guard.duty.origin_thread_id; guard.root_read_token.root_lineage_seq = guard.duty.root_lineage_seq; - guard.root_read_token.lifecycle - = CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_REQUIRED; + guard.root_read_token.lifecycle = CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_REQUIRED; guard.root_read_token.file_txn_seq = UINT64_C(5); guard.root_read_token.root_publish_seq = UINT64_C(6); guard.root_read_token.record_crc32c = UINT32_C(7); guard.root_read_token.root_flags - = CLUSTER_CONTROL_ROOT_FLAG_CLAIM_VALID - | CLUSTER_CONTROL_ROOT_FLAG_CHECKPOINT_VALID - | CLUSTER_CONTROL_ROOT_FLAG_TAIL_VALID - | CLUSTER_CONTROL_ROOT_FLAG_RECOVERED_VALID; + = CLUSTER_CONTROL_ROOT_FLAG_CLAIM_VALID | CLUSTER_CONTROL_ROOT_FLAG_CHECKPOINT_VALID + | CLUSTER_CONTROL_ROOT_FLAG_TAIL_VALID | CLUSTER_CONTROL_ROOT_FLAG_RECOVERED_VALID; memcpy(guard.root_read_token.authority_uuid, guard.duty.authority_uuid, sizeof(guard.root_read_token.authority_uuid)); guard.formation = (const ClusterFormationWitnessV1 *)(uintptr_t)1; - guard.fence_need_set - = (const PgracExternalFenceNeedSetV1 *)(uintptr_t)2; - guard.fence_admission_set - = (const PgracExternalFenceAdmissionSetV1 *)(uintptr_t)3; + guard.fence_need_set = (const PgracExternalFenceNeedSetV1 *)(uintptr_t)2; + guard.fence_admission_set = (const PgracExternalFenceAdmissionSetV1 *)(uintptr_t)3; guard.release_timeout_ms = 5000; - UT_ASSERT(cluster_recovery_serial_resid_encode(&guard.duty, - &guard.resid)); + UT_ASSERT(cluster_recovery_serial_resid_encode(&guard.duty, &guard.resid)); guard.lock_request.resid = guard.resid; guard.lock_request.lockmode = ExclusiveLock; guard.lock_request.op = CLUSTER_LOCK_OP_REQUEST; @@ -287,8 +267,7 @@ valid_held_guard_for_thread(uint16 thread) guard.root_read_token.root_lineage_seq = guard.duty.root_lineage_seq; memcpy(guard.root_read_token.authority_uuid, guard.duty.authority_uuid, sizeof(guard.root_read_token.authority_uuid)); - UT_ASSERT(cluster_recovery_serial_resid_encode(&guard.duty, - &guard.resid)); + UT_ASSERT(cluster_recovery_serial_resid_encode(&guard.duty, &guard.resid)); guard.lock_request.resid = guard.resid; guard.lock_request.holder.request_id = UINT64_C(1000) + thread; guard.lock_request.request_id = UINT64_C(1000) + thread; @@ -320,8 +299,7 @@ valid_serial_request(void) * ====================================================================== */ UT_TEST(test_recovery_serial_resid_encode) { - ClusterRecoveryDutyKey duty - = valid_duty(3, (UINT64_C(0x1234) << 32) | UINT64_C(0xABCD0001)); + ClusterRecoveryDutyKey duty = valid_duty(3, (UINT64_C(0x1234) << 32) | UINT64_C(0xABCD0001)); ClusterResId r; memset(&r, 0xEE, sizeof(r)); @@ -447,20 +425,13 @@ UT_TEST(test_recovery_serial_counter_surface_starts_zero) UT_ASSERT_EQ(cluster_recovery_serial_grant_count(), UINT64_C(0)); UT_ASSERT_EQ(cluster_recovery_serial_busy_count(), UINT64_C(0)); UT_ASSERT_EQ(cluster_recovery_serial_retry_count(), UINT64_C(0)); - UT_ASSERT_EQ(cluster_recovery_serial_revalidate_reject_count(), - UINT64_C(0)); - UT_ASSERT_EQ(cluster_recovery_serial_node_cleanup_wait_count(), - UINT64_C(0)); - UT_ASSERT_EQ(cluster_recovery_serial_release_confirmed_count(), - UINT64_C(0)); - UT_ASSERT_EQ(cluster_recovery_serial_release_unconfirmed_count(), - UINT64_C(0)); - UT_ASSERT_EQ(cluster_recovery_serial_cold_set_grant_count(), - UINT64_C(0)); - UT_ASSERT_EQ(cluster_recovery_serial_capability_denied_count(), - UINT64_C(0)); - UT_ASSERT_EQ(cluster_recovery_serial_native_result_rejected_count(), - UINT64_C(0)); + UT_ASSERT_EQ(cluster_recovery_serial_revalidate_reject_count(), UINT64_C(0)); + UT_ASSERT_EQ(cluster_recovery_serial_node_cleanup_wait_count(), UINT64_C(0)); + UT_ASSERT_EQ(cluster_recovery_serial_release_confirmed_count(), UINT64_C(0)); + UT_ASSERT_EQ(cluster_recovery_serial_release_unconfirmed_count(), UINT64_C(0)); + UT_ASSERT_EQ(cluster_recovery_serial_cold_set_grant_count(), UINT64_C(0)); + UT_ASSERT_EQ(cluster_recovery_serial_capability_denied_count(), UINT64_C(0)); + UT_ASSERT_EQ(cluster_recovery_serial_native_result_rejected_count(), UINT64_C(0)); } UT_TEST(test_recovery_serial_release_confirmed_and_clipped) @@ -477,10 +448,8 @@ UT_TEST(test_recovery_serial_release_confirmed_and_clipped) UT_ASSERT_EQ(guard.lock_request.timeout_ms, 9999); UT_ASSERT(!guard.held); UT_ASSERT(!guard.release_uncertain); - UT_ASSERT_EQ(cluster_recovery_serial_release_confirmed_count(), - UINT64_C(1)); - UT_ASSERT_EQ(cluster_recovery_serial_release_unconfirmed_count(), - UINT64_C(0)); + UT_ASSERT_EQ(cluster_recovery_serial_release_confirmed_count(), UINT64_C(1)); + UT_ASSERT_EQ(cluster_recovery_serial_release_unconfirmed_count(), UINT64_C(0)); } UT_TEST(test_recovery_serial_release_unconfirmed_preserves_guard) @@ -495,10 +464,8 @@ UT_TEST(test_recovery_serial_release_unconfirmed_preserves_guard) UT_ASSERT_EQ(stub_release_calls, 1); UT_ASSERT(guard.held); UT_ASSERT(guard.release_uncertain); - UT_ASSERT_EQ(cluster_recovery_serial_release_confirmed_count(), - UINT64_C(0)); - UT_ASSERT_EQ(cluster_recovery_serial_release_unconfirmed_count(), - UINT64_C(1)); + UT_ASSERT_EQ(cluster_recovery_serial_release_confirmed_count(), UINT64_C(0)); + UT_ASSERT_EQ(cluster_recovery_serial_release_unconfirmed_count(), UINT64_C(1)); stub_release_result = CLUSTER_LOCK_ACQUIRE_OK_GRANTED; UT_ASSERT_EQ(cluster_recovery_serial_release(&guard), @@ -506,10 +473,8 @@ UT_TEST(test_recovery_serial_release_unconfirmed_preserves_guard) UT_ASSERT_EQ(stub_release_calls, 2); UT_ASSERT(!guard.held); UT_ASSERT(!guard.release_uncertain); - UT_ASSERT_EQ(cluster_recovery_serial_release_confirmed_count(), - UINT64_C(1)); - UT_ASSERT_EQ(cluster_recovery_serial_release_unconfirmed_count(), - UINT64_C(1)); + UT_ASSERT_EQ(cluster_recovery_serial_release_confirmed_count(), UINT64_C(1)); + UT_ASSERT_EQ(cluster_recovery_serial_release_unconfirmed_count(), UINT64_C(1)); } UT_TEST(test_recovery_serial_release_not_held_and_invalid) @@ -518,21 +483,16 @@ UT_TEST(test_recovery_serial_release_not_held_and_invalid) memset(&guard, 0, sizeof(guard)); stub_release_calls = 0; - UT_ASSERT_EQ(cluster_recovery_serial_release(NULL), - CLUSTER_RECOVERY_SERIAL_RELEASE_INVALID); - UT_ASSERT_EQ(cluster_recovery_serial_release(&guard), - CLUSTER_RECOVERY_SERIAL_RELEASE_NOT_HELD); + UT_ASSERT_EQ(cluster_recovery_serial_release(NULL), CLUSTER_RECOVERY_SERIAL_RELEASE_INVALID); + UT_ASSERT_EQ(cluster_recovery_serial_release(&guard), CLUSTER_RECOVERY_SERIAL_RELEASE_NOT_HELD); guard.release_uncertain = true; - UT_ASSERT_EQ(cluster_recovery_serial_release(&guard), - CLUSTER_RECOVERY_SERIAL_RELEASE_INVALID); + UT_ASSERT_EQ(cluster_recovery_serial_release(&guard), CLUSTER_RECOVERY_SERIAL_RELEASE_INVALID); guard = valid_held_guard(); guard.release_timeout_ms = 0; - UT_ASSERT_EQ(cluster_recovery_serial_release(&guard), - CLUSTER_RECOVERY_SERIAL_RELEASE_INVALID); + UT_ASSERT_EQ(cluster_recovery_serial_release(&guard), CLUSTER_RECOVERY_SERIAL_RELEASE_INVALID); guard = valid_held_guard(); guard.lock_request.resid.field1++; - UT_ASSERT_EQ(cluster_recovery_serial_release(&guard), - CLUSTER_RECOVERY_SERIAL_RELEASE_INVALID); + UT_ASSERT_EQ(cluster_recovery_serial_release(&guard), CLUSTER_RECOVERY_SERIAL_RELEASE_INVALID); UT_ASSERT_EQ(stub_release_calls, 0); } @@ -575,8 +535,7 @@ UT_TEST(test_recovery_serial_release_set_reverse_and_compact) CLUSTER_RECOVERY_SERIAL_RELEASE_CONFIRMED); UT_ASSERT_EQ(stub_release_calls, 1); UT_ASSERT_EQ(set.count, 0); - UT_ASSERT(memcmp(&set, &(ClusterRecoverySerialGuardSet){ 0 }, - sizeof(set)) == 0); + UT_ASSERT(memcmp(&set, &(ClusterRecoverySerialGuardSet){ 0 }, sizeof(set)) == 0); } UT_TEST(test_recovery_serial_release_set_invalid_sends_nothing) @@ -610,8 +569,7 @@ UT_TEST(test_recovery_serial_p4_acquire_requires_fresh_fence_then_actual_grant) stub_acquire_calls = 0; UT_ASSERT_EQ(cluster_recovery_serial_acquire(&request, &guard), CLUSTER_RECOVERY_SERIAL_FENCE_DENIED); - UT_ASSERT(memcmp(&guard, &(ClusterRecoverySerialGuard){ 0 }, - sizeof(guard)) == 0); + UT_ASSERT(memcmp(&guard, &(ClusterRecoverySerialGuard){ 0 }, sizeof(guard)) == 0); UT_ASSERT_EQ(stub_acquire_calls, 0); stub_need_set_ready = true; @@ -622,8 +580,7 @@ UT_TEST(test_recovery_serial_p4_acquire_requires_fresh_fence_then_actual_grant) UT_ASSERT(!guard.release_uncertain); UT_ASSERT_EQ(stub_acquire_calls, 1); UT_ASSERT_EQ(guard.lock_request.timeout_ms, 1000); - UT_ASSERT_EQ(guard.duty.origin_thread_id, - request.duty.origin_thread_id); + UT_ASSERT_EQ(guard.duty.origin_thread_id, request.duty.origin_thread_id); stub_release_result = CLUSTER_LOCK_ACQUIRE_OK_GRANTED; UT_ASSERT_EQ(cluster_recovery_serial_release(&guard), @@ -633,8 +590,7 @@ UT_TEST(test_recovery_serial_p4_acquire_requires_fresh_fence_then_actual_grant) request.acquire_timeout_ms = 0; UT_ASSERT_EQ(cluster_recovery_serial_acquire(&request, &guard), CLUSTER_RECOVERY_SERIAL_INTERNAL_FAILURE); - UT_ASSERT(memcmp(&guard, &(ClusterRecoverySerialGuard){ 0 }, - sizeof(guard)) == 0); + UT_ASSERT(memcmp(&guard, &(ClusterRecoverySerialGuard){ 0 }, sizeof(guard)) == 0); UT_ASSERT_EQ(cluster_recovery_serial_acquire(NULL, &guard), CLUSTER_RECOVERY_SERIAL_INTERNAL_FAILURE); UT_ASSERT_EQ(cluster_recovery_serial_acquire(&request, NULL), @@ -647,12 +603,9 @@ UT_TEST(test_recovery_serial_p4_revalidate_is_two_phase_fail_closed) cluster_ir_shmem_init(); memset(&guard, 0, sizeof(guard)); - UT_ASSERT_EQ(cluster_recovery_serial_revalidate(NULL), - CLUSTER_RECOVERY_SERIAL_NOT_HELD); - UT_ASSERT_EQ(cluster_recovery_serial_revalidate(&guard), - CLUSTER_RECOVERY_SERIAL_NOT_HELD); - UT_ASSERT_EQ(cluster_recovery_serial_revalidate_reject_count(), - UINT64_C(0)); + UT_ASSERT_EQ(cluster_recovery_serial_revalidate(NULL), CLUSTER_RECOVERY_SERIAL_NOT_HELD); + UT_ASSERT_EQ(cluster_recovery_serial_revalidate(&guard), CLUSTER_RECOVERY_SERIAL_NOT_HELD); + UT_ASSERT_EQ(cluster_recovery_serial_revalidate_reject_count(), UINT64_C(0)); guard = valid_held_guard(); guard.release_uncertain = true; UT_ASSERT_EQ(cluster_recovery_serial_revalidate(&guard), @@ -661,13 +614,10 @@ UT_TEST(test_recovery_serial_p4_revalidate_is_two_phase_fail_closed) stub_formation_ready = true; stub_need_set_ready = true; stub_admission_set_ready = true; - UT_ASSERT_EQ(cluster_recovery_serial_revalidate(&guard), - CLUSTER_RECOVERY_SERIAL_CURRENT); + UT_ASSERT_EQ(cluster_recovery_serial_revalidate(&guard), CLUSTER_RECOVERY_SERIAL_CURRENT); stub_admission_set_ready = false; - UT_ASSERT_EQ(cluster_recovery_serial_revalidate(&guard), - CLUSTER_RECOVERY_SERIAL_FENCE_STALE); - UT_ASSERT_EQ(cluster_recovery_serial_revalidate_reject_count(), - UINT64_C(2)); + UT_ASSERT_EQ(cluster_recovery_serial_revalidate(&guard), CLUSTER_RECOVERY_SERIAL_FENCE_STALE); + UT_ASSERT_EQ(cluster_recovery_serial_revalidate_reject_count(), UINT64_C(2)); } UT_TEST(test_external_rejoin_new_epoch_invalidates_held_guard) @@ -679,15 +629,13 @@ UT_TEST(test_external_rejoin_new_epoch_invalidates_held_guard) stub_formation_ready = true; stub_need_set_ready = true; stub_admission_set_ready = true; - UT_ASSERT_EQ(cluster_recovery_serial_revalidate(&guard), - CLUSTER_RECOVERY_SERIAL_CURRENT); + UT_ASSERT_EQ(cluster_recovery_serial_revalidate(&guard), CLUSTER_RECOVERY_SERIAL_CURRENT); /* P/new epoch invalidates the formation before any held-IR mutation. */ stub_formation_ready = false; UT_ASSERT_EQ(cluster_recovery_serial_revalidate(&guard), - CLUSTER_RECOVERY_SERIAL_MEMBERSHIP_STALE); - UT_ASSERT_EQ(cluster_recovery_serial_revalidate_reject_count(), - UINT64_C(1)); + CLUSTER_RECOVERY_SERIAL_MEMBERSHIP_STALE); + UT_ASSERT_EQ(cluster_recovery_serial_revalidate_reject_count(), UINT64_C(1)); } UT_TEST(test_recovery_serial_acquire_set_zero_before_first_grant) @@ -699,12 +647,9 @@ UT_TEST(test_recovery_serial_acquire_set_zero_before_first_grant) requests[0] = valid_serial_request(); requests[1] = valid_serial_request(); requests[1].duty = valid_duty(4, UINT64_C(104)); - requests[1].expected_root_token.origin_thread_id - = requests[1].duty.origin_thread_id; - requests[1].expected_root_token.root_lineage_seq - = requests[1].duty.root_lineage_seq; - memcpy(requests[1].expected_root_token.authority_uuid, - requests[1].duty.authority_uuid, + requests[1].expected_root_token.origin_thread_id = requests[1].duty.origin_thread_id; + requests[1].expected_root_token.root_lineage_seq = requests[1].duty.root_lineage_seq; + memcpy(requests[1].expected_root_token.authority_uuid, requests[1].duty.authority_uuid, sizeof(requests[1].expected_root_token.authority_uuid)); memset(&set, 0xA5, sizeof(set)); @@ -714,23 +659,19 @@ UT_TEST(test_recovery_serial_acquire_set_zero_before_first_grant) stub_need_set_ready = false; stub_admission_set_ready = true; stub_acquire_calls = 0; - UT_ASSERT_EQ(cluster_recovery_serial_acquire_set( - requests, 2, 5000, &set, &failed_index), + UT_ASSERT_EQ(cluster_recovery_serial_acquire_set(requests, 2, 5000, &set, &failed_index), CLUSTER_RECOVERY_SERIAL_FENCE_DENIED); UT_ASSERT_EQ(failed_index, CLUSTER_RECOVERY_SERIAL_SET_FAILED_NONE); UT_ASSERT_EQ(stub_acquire_calls, 0); - UT_ASSERT(memcmp(&set, &(ClusterRecoverySerialGuardSet){ 0 }, - sizeof(set)) == 0); + UT_ASSERT(memcmp(&set, &(ClusterRecoverySerialGuardSet){ 0 }, sizeof(set)) == 0); memset(&set, 0xA5, sizeof(set)); failed_index = 7; requests[1] = requests[0]; - UT_ASSERT_EQ(cluster_recovery_serial_acquire_set( - requests, 2, 5000, &set, &failed_index), + UT_ASSERT_EQ(cluster_recovery_serial_acquire_set(requests, 2, 5000, &set, &failed_index), CLUSTER_RECOVERY_SERIAL_INTERNAL_FAILURE); UT_ASSERT_EQ(failed_index, CLUSTER_RECOVERY_SERIAL_SET_FAILED_NONE); - UT_ASSERT(memcmp(&set, &(ClusterRecoverySerialGuardSet){ 0 }, - sizeof(set)) == 0); + UT_ASSERT(memcmp(&set, &(ClusterRecoverySerialGuardSet){ 0 }, sizeof(set)) == 0); } int diff --git a/src/test/cluster_unit/test_cluster_remote_xact.c b/src/test/cluster_unit/test_cluster_remote_xact.c index c16860c65df..7ccfac94fb0 100644 --- a/src/test/cluster_unit/test_cluster_remote_xact.c +++ b/src/test/cluster_unit/test_cluster_remote_xact.c @@ -117,9 +117,8 @@ UT_TEST(test_remote_xact_terminal_codec_carries_commit_ts_and_wrap) ClusterRemoteXactEntryV2 entry; ClusterRemoteXactEntryDecodedV2 decoded; - UT_ASSERT(cluster_remote_xact_entry_encode_terminal_v2(&entry, - CLUSTER_REMOTE_XACT_COMMITTED, UINT64_C(9123), INT64_C(77112233), - true, 17)); + UT_ASSERT(cluster_remote_xact_entry_encode_terminal_v2( + &entry, CLUSTER_REMOTE_XACT_COMMITTED, UINT64_C(9123), INT64_C(77112233), true, 17)); UT_ASSERT(cluster_remote_xact_entry_decode_terminal_v2(&entry, &decoded)); UT_ASSERT_EQ(decoded.outcome, CLUSTER_REMOTE_XACT_COMMITTED); UT_ASSERT_EQ(decoded.commit_scn, UINT64_C(9123)); @@ -129,8 +128,8 @@ UT_TEST(test_remote_xact_terminal_codec_carries_commit_ts_and_wrap) entry.payload[18] = 1; UT_ASSERT(!cluster_remote_xact_entry_decode_terminal_v2(&entry, &decoded)); - UT_ASSERT(cluster_remote_xact_entry_encode_terminal_v2(&entry, - CLUSTER_REMOTE_XACT_ABORTED, InvalidScn, 0, false, 0)); + UT_ASSERT(cluster_remote_xact_entry_encode_terminal_v2(&entry, CLUSTER_REMOTE_XACT_ABORTED, + InvalidScn, 0, false, 0)); UT_ASSERT(cluster_remote_xact_entry_decode_terminal_v2(&entry, &decoded)); UT_ASSERT_EQ(decoded.outcome, CLUSTER_REMOTE_XACT_ABORTED); UT_ASSERT_EQ(decoded.commit_timestamp, 0); @@ -146,17 +145,17 @@ UT_TEST(test_remote_xact_prepare_transition_is_idempotent_and_conflict_closed) memset(¤t, 0, sizeof(current)); memset(first, 0x31, sizeof(first)); memset(second, 0x32, sizeof(second)); - UT_ASSERT_EQ(cluster_remote_xact_entry_prepare_transition_v2( - ¤t, first, &next), CLUSTER_REMOTE_XACT_ENTRY_WRITE); + UT_ASSERT_EQ(cluster_remote_xact_entry_prepare_transition_v2(¤t, first, &next), + CLUSTER_REMOTE_XACT_ENTRY_WRITE); current = next; - UT_ASSERT_EQ(cluster_remote_xact_entry_prepare_transition_v2( - ¤t, first, &next), CLUSTER_REMOTE_XACT_ENTRY_NOOP); - UT_ASSERT_EQ(cluster_remote_xact_entry_prepare_transition_v2( - ¤t, second, &next), CLUSTER_REMOTE_XACT_ENTRY_CONFLICT); - UT_ASSERT(cluster_remote_xact_entry_encode_terminal_v2(¤t, - CLUSTER_REMOTE_XACT_ABORTED, InvalidScn, 0, false, 0)); - UT_ASSERT_EQ(cluster_remote_xact_entry_prepare_transition_v2( - ¤t, first, &next), CLUSTER_REMOTE_XACT_ENTRY_CONFLICT); + UT_ASSERT_EQ(cluster_remote_xact_entry_prepare_transition_v2(¤t, first, &next), + CLUSTER_REMOTE_XACT_ENTRY_NOOP); + UT_ASSERT_EQ(cluster_remote_xact_entry_prepare_transition_v2(¤t, second, &next), + CLUSTER_REMOTE_XACT_ENTRY_CONFLICT); + UT_ASSERT(cluster_remote_xact_entry_encode_terminal_v2(¤t, CLUSTER_REMOTE_XACT_ABORTED, + InvalidScn, 0, false, 0)); + UT_ASSERT_EQ(cluster_remote_xact_entry_prepare_transition_v2(¤t, first, &next), + CLUSTER_REMOTE_XACT_ENTRY_CONFLICT); } UT_TEST(test_remote_xact_prepared_terminal_requires_pending_or_exact_result) @@ -170,24 +169,27 @@ UT_TEST(test_remote_xact_prepared_terminal_requires_pending_or_exact_result) memset(digest, 0x77, sizeof(digest)); memset(wrong_digest, 0x78, sizeof(wrong_digest)); UT_ASSERT_EQ(cluster_remote_xact_entry_terminal_transition_v2( - ¤t, true, digest, CLUSTER_REMOTE_XACT_COMMITTED, UINT64_C(91), - INT64_C(1234), true, 7, &next), - CLUSTER_REMOTE_XACT_ENTRY_CONFLICT); + ¤t, true, digest, CLUSTER_REMOTE_XACT_COMMITTED, UINT64_C(91), + INT64_C(1234), true, 7, &next), + CLUSTER_REMOTE_XACT_ENTRY_CONFLICT); UT_ASSERT(cluster_remote_xact_entry_encode_pending_v2(¤t, digest)); UT_ASSERT_EQ(cluster_remote_xact_entry_terminal_transition_v2( - ¤t, true, wrong_digest, CLUSTER_REMOTE_XACT_COMMITTED, - UINT64_C(91), INT64_C(1234), true, 7, &next), - CLUSTER_REMOTE_XACT_ENTRY_CONFLICT); + ¤t, true, wrong_digest, CLUSTER_REMOTE_XACT_COMMITTED, UINT64_C(91), + INT64_C(1234), true, 7, &next), + CLUSTER_REMOTE_XACT_ENTRY_CONFLICT); UT_ASSERT_EQ(cluster_remote_xact_entry_terminal_transition_v2( - ¤t, true, digest, CLUSTER_REMOTE_XACT_COMMITTED, UINT64_C(91), - INT64_C(1234), true, 7, &next), CLUSTER_REMOTE_XACT_ENTRY_WRITE); + ¤t, true, digest, CLUSTER_REMOTE_XACT_COMMITTED, UINT64_C(91), + INT64_C(1234), true, 7, &next), + CLUSTER_REMOTE_XACT_ENTRY_WRITE); current = next; UT_ASSERT_EQ(cluster_remote_xact_entry_terminal_transition_v2( - ¤t, true, digest, CLUSTER_REMOTE_XACT_COMMITTED, UINT64_C(91), - INT64_C(1234), true, 7, &next), CLUSTER_REMOTE_XACT_ENTRY_NOOP); - UT_ASSERT_EQ(cluster_remote_xact_entry_terminal_transition_v2( - ¤t, true, digest, CLUSTER_REMOTE_XACT_ABORTED, InvalidScn, 0, - false, 0, &next), CLUSTER_REMOTE_XACT_ENTRY_CONFLICT); + ¤t, true, digest, CLUSTER_REMOTE_XACT_COMMITTED, UINT64_C(91), + INT64_C(1234), true, 7, &next), + CLUSTER_REMOTE_XACT_ENTRY_NOOP); + UT_ASSERT_EQ(cluster_remote_xact_entry_terminal_transition_v2(¤t, true, digest, + CLUSTER_REMOTE_XACT_ABORTED, + InvalidScn, 0, false, 0, &next), + CLUSTER_REMOTE_XACT_ENTRY_CONFLICT); } UT_TEST(test_remote_xact_projection_reset_is_idempotent_invalidation) @@ -197,31 +199,29 @@ UT_TEST(test_remote_xact_projection_reset_is_idempotent_invalidation) memset(¤t, 0, sizeof(current)); UT_ASSERT_EQ(cluster_remote_xact_entry_reset_transition_v2(¤t, &next), - CLUSTER_REMOTE_XACT_ENTRY_NOOP); + CLUSTER_REMOTE_XACT_ENTRY_NOOP); UT_ASSERT(cluster_remote_xact_entry_is_empty_v2(&next)); - UT_ASSERT(cluster_remote_xact_entry_encode_terminal_v2(¤t, - CLUSTER_REMOTE_XACT_COMMITTED, UINT64_C(991), INT64_C(881), true, 7)); + UT_ASSERT(cluster_remote_xact_entry_encode_terminal_v2(¤t, CLUSTER_REMOTE_XACT_COMMITTED, + UINT64_C(991), INT64_C(881), true, 7)); UT_ASSERT_EQ(cluster_remote_xact_entry_reset_transition_v2(¤t, &next), - CLUSTER_REMOTE_XACT_ENTRY_WRITE); + CLUSTER_REMOTE_XACT_ENTRY_WRITE); UT_ASSERT(cluster_remote_xact_entry_is_empty_v2(&next)); /* Projection corruption is invalidated, never promoted to authority. */ memset(¤t, 0xee, sizeof(current)); UT_ASSERT_EQ(cluster_remote_xact_entry_reset_transition_v2(¤t, &next), - CLUSTER_REMOTE_XACT_ENTRY_WRITE); + CLUSTER_REMOTE_XACT_ENTRY_WRITE); UT_ASSERT(cluster_remote_xact_entry_is_empty_v2(&next)); } UT_TEST(test_remote_xact_projection_reset_range_is_bounded) { UT_ASSERT(cluster_remote_xact_reset_range_valid_v2(0, 0, 1)); - UT_ASSERT(cluster_remote_xact_reset_range_valid_v2(127, - UINT32_MAX - 32767, 32768)); + UT_ASSERT(cluster_remote_xact_reset_range_valid_v2(127, UINT32_MAX - 32767, 32768)); UT_ASSERT(!cluster_remote_xact_reset_range_valid_v2(-1, 0, 1)); UT_ASSERT(!cluster_remote_xact_reset_range_valid_v2(128, 0, 1)); UT_ASSERT(!cluster_remote_xact_reset_range_valid_v2(0, 0, 0)); UT_ASSERT(!cluster_remote_xact_reset_range_valid_v2(0, 0, 32769)); - UT_ASSERT(!cluster_remote_xact_reset_range_valid_v2(0, - UINT32_MAX - 2, 4)); + UT_ASSERT(!cluster_remote_xact_reset_range_valid_v2(0, UINT32_MAX - 2, 4)); } UT_TEST(test_remote_xact_origin_no_cross_partition_overlap) diff --git a/src/test/cluster_unit/test_cluster_replacement_episode.c b/src/test/cluster_unit/test_cluster_replacement_episode.c index dc73e6b9082..b4299cca10a 100644 --- a/src/test/cluster_unit/test_cluster_replacement_episode.c +++ b/src/test/cluster_unit/test_cluster_replacement_episode.c @@ -89,8 +89,7 @@ UT_TEST(test_all_frozen_phases_and_readiness_combinations_validate) CLUSTER_REPLACEMENT_EPISODE_R4A_TARGET_READY | CLUSTER_REPLACEMENT_EPISODE_GRD_POSTEPOCH_READY, CLUSTER_REPLACEMENT_EPISODE_INTENT_CLEARED, - CLUSTER_REPLACEMENT_EPISODE_R4A_TARGET_READY - | CLUSTER_REPLACEMENT_EPISODE_INTENT_CLEARED, + CLUSTER_REPLACEMENT_EPISODE_R4A_TARGET_READY | CLUSTER_REPLACEMENT_EPISODE_INTENT_CLEARED, CLUSTER_REPLACEMENT_EPISODE_GRD_POSTEPOCH_READY | CLUSTER_REPLACEMENT_EPISODE_INTENT_CLEARED, CLUSTER_REPLACEMENT_EPISODE_READINESS_MASK, diff --git a/src/test/cluster_unit/test_cluster_replacement_request.c b/src/test/cluster_unit/test_cluster_replacement_request.c index 5e4020d8cb7..9d37d6a287a 100644 --- a/src/test/cluster_unit/test_cluster_replacement_request.c +++ b/src/test/cluster_unit/test_cluster_replacement_request.c @@ -57,15 +57,11 @@ UT_TEST(test_replacement_request_exact_layout_and_roundtrip) ClusterReplacementRequestMarker marker = valid_marker(); ClusterReplacementRequestMarker decoded; uint8 image[CLUSTER_REPLACEMENT_MARKER_BYTES]; - static const uint8 expected_prefix[56] = { - 0x4d, 0x4c, 0x50, 0x52, 0x01, 0x00, 0x01, 0x00, - 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, - 0x18, 0x17, 0x16, 0x15, 0x14, 0x13, 0x12, 0x11, - 0x28, 0x27, 0x26, 0x25, 0x24, 0x23, 0x22, 0x21, - 0x38, 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x31, - 0xe4, 0x05, 0x89, 0x42, 0x5b, 0xae, 0x0d, 0x8e - }; + static const uint8 expected_prefix[56] + = { 0x4d, 0x4c, 0x50, 0x52, 0x01, 0x00, 0x01, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x18, 0x17, 0x16, 0x15, + 0x14, 0x13, 0x12, 0x11, 0x28, 0x27, 0x26, 0x25, 0x24, 0x23, 0x22, 0x21, 0x38, 0x37, + 0x36, 0x35, 0x34, 0x33, 0x32, 0x31, 0xe4, 0x05, 0x89, 0x42, 0x5b, 0xae, 0x0d, 0x8e }; memset(image, 0xa5, sizeof(image)); UT_ASSERT(cluster_replacement_request_encode(&marker, image)); @@ -78,8 +74,7 @@ UT_TEST(test_replacement_request_exact_layout_and_roundtrip) UT_ASSERT(cluster_replacement_request_decode(image, 3, &decoded)); UT_ASSERT_EQ(decoded.target_node_id, 3); UT_ASSERT_EQ(decoded.baseline_epoch, marker.baseline_epoch); - UT_ASSERT_EQ(decoded.old_admitted_incarnation, - marker.old_admitted_incarnation); + UT_ASSERT_EQ(decoded.old_admitted_incarnation, marker.old_admitted_incarnation); UT_ASSERT_EQ(decoded.fresh_incarnation, marker.fresh_incarnation); UT_ASSERT_EQ(decoded.request_nonce, marker.request_nonce); UT_ASSERT_EQ(decoded.grammar_fingerprint, marker.grammar_fingerprint); @@ -139,28 +134,26 @@ UT_TEST(test_replacement_request_reserved1_pack_clear_is_exact) memset(reserved1, 0x7c, sizeof(reserved1)); memcpy(before, reserved1, sizeof(before)); UT_ASSERT(cluster_replacement_request_pack(reserved1, &marker)); - UT_ASSERT_EQ(memcmp(reserved1, before, - CLUSTER_REPLACEMENT_MARKER_RESERVED1_OFFSET), 0); - UT_ASSERT_EQ(memcmp( - reserved1 + CLUSTER_REPLACEMENT_MARKER_RESERVED1_OFFSET - + CLUSTER_REPLACEMENT_MARKER_BYTES, - before + CLUSTER_REPLACEMENT_MARKER_RESERVED1_OFFSET - + CLUSTER_REPLACEMENT_MARKER_BYTES, - sizeof(reserved1) - CLUSTER_REPLACEMENT_MARKER_RESERVED1_OFFSET - - CLUSTER_REPLACEMENT_MARKER_BYTES), 0); + UT_ASSERT_EQ(memcmp(reserved1, before, CLUSTER_REPLACEMENT_MARKER_RESERVED1_OFFSET), 0); + UT_ASSERT_EQ(memcmp(reserved1 + CLUSTER_REPLACEMENT_MARKER_RESERVED1_OFFSET + + CLUSTER_REPLACEMENT_MARKER_BYTES, + before + CLUSTER_REPLACEMENT_MARKER_RESERVED1_OFFSET + + CLUSTER_REPLACEMENT_MARKER_BYTES, + sizeof(reserved1) - CLUSTER_REPLACEMENT_MARKER_RESERVED1_OFFSET + - CLUSTER_REPLACEMENT_MARKER_BYTES), + 0); UT_ASSERT(cluster_replacement_request_unpack(reserved1, 3, &decoded)); UT_ASSERT_EQ(decoded.request_nonce, marker.request_nonce); cluster_replacement_request_clear(reserved1); UT_ASSERT(cluster_replacement_request_is_clear(reserved1)); - UT_ASSERT_EQ(memcmp(reserved1, before, - CLUSTER_REPLACEMENT_MARKER_RESERVED1_OFFSET), 0); - UT_ASSERT_EQ(memcmp( - reserved1 + CLUSTER_REPLACEMENT_MARKER_RESERVED1_OFFSET - + CLUSTER_REPLACEMENT_MARKER_BYTES, - before + CLUSTER_REPLACEMENT_MARKER_RESERVED1_OFFSET - + CLUSTER_REPLACEMENT_MARKER_BYTES, - sizeof(reserved1) - CLUSTER_REPLACEMENT_MARKER_RESERVED1_OFFSET - - CLUSTER_REPLACEMENT_MARKER_BYTES), 0); + UT_ASSERT_EQ(memcmp(reserved1, before, CLUSTER_REPLACEMENT_MARKER_RESERVED1_OFFSET), 0); + UT_ASSERT_EQ(memcmp(reserved1 + CLUSTER_REPLACEMENT_MARKER_RESERVED1_OFFSET + + CLUSTER_REPLACEMENT_MARKER_BYTES, + before + CLUSTER_REPLACEMENT_MARKER_RESERVED1_OFFSET + + CLUSTER_REPLACEMENT_MARKER_BYTES, + sizeof(reserved1) - CLUSTER_REPLACEMENT_MARKER_RESERVED1_OFFSET + - CLUSTER_REPLACEMENT_MARKER_BYTES), + 0); } UT_TEST(test_replacement_request_slot_state_requires_exact_pair) @@ -173,37 +166,37 @@ UT_TEST(test_replacement_request_slot_state_requires_exact_pair) memset(reserved1, 0, sizeof(reserved1)); memset(&sentinel, 0x5a, sizeof(sentinel)); decoded = sentinel; - UT_ASSERT_EQ(cluster_replacement_request_slot_state( - 0, reserved1, 3, marker.fresh_incarnation, &decoded), + UT_ASSERT_EQ( + cluster_replacement_request_slot_state(0, reserved1, 3, marker.fresh_incarnation, &decoded), CLUSTER_REPLACEMENT_REQUEST_SLOT_CLEAR); UT_ASSERT_EQ(memcmp(&decoded, &sentinel, sizeof(decoded)), 0); UT_ASSERT(cluster_replacement_request_pack(reserved1, &marker)); decoded = sentinel; - UT_ASSERT_EQ(cluster_replacement_request_slot_state( - CLUSTER_VOTING_SLOT_FLAG_REPLACEMENT_REQUESTED, reserved1, 3, - marker.fresh_incarnation, &decoded), + UT_ASSERT_EQ( + cluster_replacement_request_slot_state(CLUSTER_VOTING_SLOT_FLAG_REPLACEMENT_REQUESTED, + reserved1, 3, marker.fresh_incarnation, &decoded), CLUSTER_REPLACEMENT_REQUEST_SLOT_VALID); UT_ASSERT_EQ(decoded.request_nonce, marker.request_nonce); decoded = sentinel; - UT_ASSERT_EQ(cluster_replacement_request_slot_state( - 0, reserved1, 3, marker.fresh_incarnation, &decoded), + UT_ASSERT_EQ( + cluster_replacement_request_slot_state(0, reserved1, 3, marker.fresh_incarnation, &decoded), CLUSTER_REPLACEMENT_REQUEST_SLOT_HOLD); UT_ASSERT_EQ(memcmp(&decoded, &sentinel, sizeof(decoded)), 0); decoded = sentinel; UT_ASSERT_EQ(cluster_replacement_request_slot_state( - CLUSTER_VOTING_SLOT_FLAG_REPLACEMENT_REQUESTED, reserved1, 3, - marker.fresh_incarnation + 1, &decoded), - CLUSTER_REPLACEMENT_REQUEST_SLOT_HOLD); + CLUSTER_VOTING_SLOT_FLAG_REPLACEMENT_REQUESTED, reserved1, 3, + marker.fresh_incarnation + 1, &decoded), + CLUSTER_REPLACEMENT_REQUEST_SLOT_HOLD); UT_ASSERT_EQ(memcmp(&decoded, &sentinel, sizeof(decoded)), 0); cluster_replacement_request_clear(reserved1); decoded = sentinel; - UT_ASSERT_EQ(cluster_replacement_request_slot_state( - CLUSTER_VOTING_SLOT_FLAG_REPLACEMENT_REQUESTED, reserved1, 3, - marker.fresh_incarnation, &decoded), + UT_ASSERT_EQ( + cluster_replacement_request_slot_state(CLUSTER_VOTING_SLOT_FLAG_REPLACEMENT_REQUESTED, + reserved1, 3, marker.fresh_incarnation, &decoded), CLUSTER_REPLACEMENT_REQUEST_SLOT_HOLD); UT_ASSERT_EQ(memcmp(&decoded, &sentinel, sizeof(decoded)), 0); } @@ -220,9 +213,9 @@ UT_TEST(test_replacement_request_slot_state_rejects_corrupt_pair) reserved1[CLUSTER_REPLACEMENT_MARKER_RESERVED1_OFFSET + 24] ^= UINT8_C(1); memset(&sentinel, 0xa5, sizeof(sentinel)); decoded = sentinel; - UT_ASSERT_EQ(cluster_replacement_request_slot_state( - CLUSTER_VOTING_SLOT_FLAG_REPLACEMENT_REQUESTED, reserved1, 3, - marker.fresh_incarnation, &decoded), + UT_ASSERT_EQ( + cluster_replacement_request_slot_state(CLUSTER_VOTING_SLOT_FLAG_REPLACEMENT_REQUESTED, + reserved1, 3, marker.fresh_incarnation, &decoded), CLUSTER_REPLACEMENT_REQUEST_SLOT_HOLD); UT_ASSERT_EQ(memcmp(&decoded, &sentinel, sizeof(decoded)), 0); } @@ -241,39 +234,37 @@ UT_TEST(test_replacement_request_preserve_is_per_disk_and_exact) memcpy(before, next, sizeof(before)); flags = UINT64_C(0x1); UT_ASSERT_EQ(cluster_replacement_request_preserve_per_disk( - CLUSTER_VOTING_SLOT_FLAG_REPLACEMENT_REQUESTED, prior, 3, - marker.fresh_incarnation, &flags, next), - CLUSTER_REPLACEMENT_REQUEST_SLOT_VALID); - UT_ASSERT_EQ(flags, UINT64_C(0x1) - | CLUSTER_VOTING_SLOT_FLAG_REPLACEMENT_REQUESTED); - UT_ASSERT_EQ(memcmp(next, before, - CLUSTER_REPLACEMENT_MARKER_RESERVED1_OFFSET), 0); - UT_ASSERT_EQ(memcmp( - next + CLUSTER_REPLACEMENT_MARKER_RESERVED1_OFFSET, - prior + CLUSTER_REPLACEMENT_MARKER_RESERVED1_OFFSET, - CLUSTER_REPLACEMENT_MARKER_BYTES), 0); - UT_ASSERT_EQ(memcmp( - next + CLUSTER_REPLACEMENT_MARKER_RESERVED1_OFFSET - + CLUSTER_REPLACEMENT_MARKER_BYTES, - before + CLUSTER_REPLACEMENT_MARKER_RESERVED1_OFFSET - + CLUSTER_REPLACEMENT_MARKER_BYTES, - sizeof(next) - CLUSTER_REPLACEMENT_MARKER_RESERVED1_OFFSET - - CLUSTER_REPLACEMENT_MARKER_BYTES), 0); + CLUSTER_VOTING_SLOT_FLAG_REPLACEMENT_REQUESTED, prior, 3, + marker.fresh_incarnation, &flags, next), + CLUSTER_REPLACEMENT_REQUEST_SLOT_VALID); + UT_ASSERT_EQ(flags, UINT64_C(0x1) | CLUSTER_VOTING_SLOT_FLAG_REPLACEMENT_REQUESTED); + UT_ASSERT_EQ(memcmp(next, before, CLUSTER_REPLACEMENT_MARKER_RESERVED1_OFFSET), 0); + UT_ASSERT_EQ(memcmp(next + CLUSTER_REPLACEMENT_MARKER_RESERVED1_OFFSET, + prior + CLUSTER_REPLACEMENT_MARKER_RESERVED1_OFFSET, + CLUSTER_REPLACEMENT_MARKER_BYTES), + 0); + UT_ASSERT_EQ( + memcmp( + next + CLUSTER_REPLACEMENT_MARKER_RESERVED1_OFFSET + CLUSTER_REPLACEMENT_MARKER_BYTES, + before + CLUSTER_REPLACEMENT_MARKER_RESERVED1_OFFSET + CLUSTER_REPLACEMENT_MARKER_BYTES, + sizeof(next) - CLUSTER_REPLACEMENT_MARKER_RESERVED1_OFFSET + - CLUSTER_REPLACEMENT_MARKER_BYTES), + 0); memset(prior, 0, sizeof(prior)); memset(next, 0x3d, sizeof(next)); memcpy(before, next, sizeof(before)); flags = UINT64_C(0x1); UT_ASSERT_EQ(cluster_replacement_request_preserve_per_disk( - 0, prior, 3, marker.fresh_incarnation, &flags, next), - CLUSTER_REPLACEMENT_REQUEST_SLOT_CLEAR); + 0, prior, 3, marker.fresh_incarnation, &flags, next), + CLUSTER_REPLACEMENT_REQUEST_SLOT_CLEAR); UT_ASSERT_EQ(flags, UINT64_C(0x1)); UT_ASSERT_EQ(memcmp(next, before, sizeof(next)), 0); UT_ASSERT(cluster_replacement_request_pack(prior, &marker)); UT_ASSERT_EQ(cluster_replacement_request_preserve_per_disk( - 0, prior, 3, marker.fresh_incarnation, &flags, next), - CLUSTER_REPLACEMENT_REQUEST_SLOT_HOLD); + 0, prior, 3, marker.fresh_incarnation, &flags, next), + CLUSTER_REPLACEMENT_REQUEST_SLOT_HOLD); UT_ASSERT_EQ(flags, UINT64_C(0x1)); UT_ASSERT_EQ(memcmp(next, before, sizeof(next)), 0); } diff --git a/src/test/cluster_unit/test_cluster_replacement_wire.c b/src/test/cluster_unit/test_cluster_replacement_wire.c index b1e6ad36621..085844c37f8 100644 --- a/src/test/cluster_unit/test_cluster_replacement_wire.c +++ b/src/test/cluster_unit/test_cluster_replacement_wire.c @@ -20,8 +20,7 @@ UT_DEFINE_GLOBALS(); static uint32 test_get_le32(const uint8 *p) { - return (uint32)p[0] | ((uint32)p[1] << 8) | ((uint32)p[2] << 16) - | ((uint32)p[3] << 24); + return (uint32)p[0] | ((uint32)p[1] << 8) | ((uint32)p[2] << 16) | ((uint32)p[3] << 24); } @@ -50,8 +49,7 @@ make_valid_message(uint32 phase) message.request_nonce = UINT64_C(0x2122232425262728); message.identity0 = UINT64_C(0x3132333435363738); message.identity1 = UINT64_C(0x4142434445464748); - message.grammar_fingerprint - = CANDIDATE2_CORRECTED_A1_GRAMMAR_FINGERPRINT; + message.grammar_fingerprint = CANDIDATE2_CORRECTED_A1_GRAMMAR_FINGERPRINT; if (phase == CLUSTER_REPLACEMENT_WIRE_PHASE_TARGET_RECOVERY_READY) { message.body.phase3.jcmk_generation = UINT64_C(0x5152535455565758); message.body.phase3.episode_state_generation = UINT32_C(0x61626364); @@ -80,15 +78,13 @@ make_ready_snapshot(void) snapshot.old_admitted_incarnation = UINT64_C(0x3132333435363738); snapshot.fresh_incarnation = UINT64_C(0x4142434445464748); snapshot.committed_epoch = UINT64_C(71); - snapshot.grammar_fingerprint - = CANDIDATE2_CORRECTED_A1_GRAMMAR_FINGERPRINT; + snapshot.grammar_fingerprint = CANDIDATE2_CORRECTED_A1_GRAMMAR_FINGERPRINT; return snapshot; } static ClusterICEnvelope -make_phase3_envelope(int32 source_node_id, int32 dest_node_id, - uint64 epoch) +make_phase3_envelope(int32 source_node_id, int32 dest_node_id, uint64 epoch) { ClusterICEnvelope envelope; @@ -103,15 +99,13 @@ make_phase3_envelope(int32 source_node_id, int32 dest_node_id, static ClusterReplacementPhase3IngressResult -ingress_phase3(ClusterReplacementPhase3Handoff *handoff, - ClusterICEnvelope *envelope, uint8 *bytes, - int32 authenticated_source, int32 local_node, - uint64 current_epoch, uint32 connection_generation) +ingress_phase3(ClusterReplacementPhase3Handoff *handoff, ClusterICEnvelope *envelope, uint8 *bytes, + int32 authenticated_source, int32 local_node, uint64 current_epoch, + uint32 connection_generation) { return cluster_replacement_wire_phase3_ingress( - handoff, envelope, bytes, CLUSTER_REPLACEMENT_WIRE_BYTES, - authenticated_source, local_node, current_epoch, - connection_generation); + handoff, envelope, bytes, CLUSTER_REPLACEMENT_WIRE_BYTES, authenticated_source, local_node, + current_epoch, connection_generation); } @@ -125,13 +119,10 @@ UT_TEST(test_codec_is_exact_72_byte_little_endian) memset(bytes, 0xA5, sizeof(bytes)); UT_ASSERT(cluster_replacement_wire_encode(&in, bytes)); UT_ASSERT_EQ((int)sizeof(bytes), 72); - UT_ASSERT_EQ((int)test_get_le32(bytes + 0), - (int)GES_REQ_OPCODE_REPLACEMENT_EPISODE); - UT_ASSERT_EQ((int)test_get_le32(bytes + 4), - (int)CLUSTER_REPLACEMENT_WIRE_PHASE_PURGE_REQUEST); + UT_ASSERT_EQ((int)test_get_le32(bytes + 0), (int)GES_REQ_OPCODE_REPLACEMENT_EPISODE); + UT_ASSERT_EQ((int)test_get_le32(bytes + 4), (int)CLUSTER_REPLACEMENT_WIRE_PHASE_PURGE_REQUEST); UT_ASSERT_EQ((int)test_get_le32(bytes + 8), 3); - UT_ASSERT_EQ((int)test_get_le32(bytes + 12), - (int)CLUSTER_REPLACEMENT_WIRE_VERSION); + UT_ASSERT_EQ((int)test_get_le32(bytes + 12), (int)CLUSTER_REPLACEMENT_WIRE_VERSION); UT_ASSERT(test_get_le64(bytes + 16) == in.epoch); UT_ASSERT(test_get_le64(bytes + 24) == in.request_nonce); UT_ASSERT(test_get_le64(bytes + 32) == in.identity0); @@ -153,8 +144,7 @@ UT_TEST(test_codec_round_trips_all_four_phase_layouts) uint32 phase; for (phase = CLUSTER_REPLACEMENT_WIRE_PHASE_PURGE_REQUEST; - phase <= CLUSTER_REPLACEMENT_WIRE_PHASE_FAILSTOP_APPLICATION_ACK; - phase++) { + phase <= CLUSTER_REPLACEMENT_WIRE_PHASE_FAILSTOP_APPLICATION_ACK; phase++) { in = make_valid_message(phase); memset(&out, 0, sizeof(out)); UT_ASSERT(cluster_replacement_wire_encode(&in, bytes)); @@ -172,12 +162,10 @@ UT_TEST(test_phase3_maps_exact_generation_ready_and_zero_reserved) uint8 bytes[CLUSTER_REPLACEMENT_WIRE_BYTES]; uint8 unchanged[CLUSTER_REPLACEMENT_WIRE_BYTES]; - in = make_valid_message( - CLUSTER_REPLACEMENT_WIRE_PHASE_TARGET_RECOVERY_READY); + in = make_valid_message(CLUSTER_REPLACEMENT_WIRE_PHASE_TARGET_RECOVERY_READY); UT_ASSERT(cluster_replacement_wire_encode(&in, bytes)); UT_ASSERT(test_get_le64(bytes + 48) == in.body.phase3.jcmk_generation); - UT_ASSERT_EQ((int)test_get_le32(bytes + 56), - (int)in.body.phase3.episode_state_generation); + UT_ASSERT_EQ((int)test_get_le32(bytes + 56), (int)in.body.phase3.episode_state_generation); UT_ASSERT_EQ((int)test_get_le32(bytes + 60), 0); memset(bytes, 0xA5, sizeof(bytes)); memcpy(unchanged, bytes, sizeof(unchanged)); @@ -211,8 +199,7 @@ UT_TEST(test_phase3_snapshot_encoder_maps_exact_positive_snapshot) memset(bytes, 0xA5, sizeof(bytes)); UT_ASSERT(cluster_replacement_wire_encode_phase3_snapshot(&snapshot, bytes)); UT_ASSERT(cluster_replacement_wire_decode(bytes, &decoded)); - UT_ASSERT_EQ((int)decoded.phase, - (int)CLUSTER_REPLACEMENT_WIRE_PHASE_TARGET_RECOVERY_READY); + UT_ASSERT_EQ((int)decoded.phase, (int)CLUSTER_REPLACEMENT_WIRE_PHASE_TARGET_RECOVERY_READY); UT_ASSERT_EQ(decoded.target_node_id, snapshot.target_node_id); UT_ASSERT(decoded.epoch == snapshot.committed_epoch - 1); UT_ASSERT(decoded.request_nonce == snapshot.request_nonce); @@ -234,12 +221,12 @@ UT_TEST(test_phase3_snapshot_encoder_rejects_without_output_mutation) uint8 bytes[CLUSTER_REPLACEMENT_WIRE_BYTES]; uint8 before[CLUSTER_REPLACEMENT_WIRE_BYTES]; -#define ASSERT_SNAPSHOT_REJECTED() \ - do { \ - memset(bytes, 0xA5, sizeof(bytes)); \ - memcpy(before, bytes, sizeof(before)); \ - UT_ASSERT(!cluster_replacement_wire_encode_phase3_snapshot(&snapshot, bytes)); \ - UT_ASSERT_EQ(memcmp(bytes, before, sizeof(bytes)), 0); \ +#define ASSERT_SNAPSHOT_REJECTED() \ + do { \ + memset(bytes, 0xA5, sizeof(bytes)); \ + memcpy(before, bytes, sizeof(before)); \ + UT_ASSERT(!cluster_replacement_wire_encode_phase3_snapshot(&snapshot, bytes)); \ + UT_ASSERT_EQ(memcmp(bytes, before, sizeof(bytes)), 0); \ } while (0) snapshot.ready = false; @@ -315,8 +302,7 @@ UT_TEST(test_codec_rejects_grammar_fingerprint_drift) in.grammar_fingerprint ^= UINT64_C(1); UT_ASSERT(!cluster_replacement_wire_encode(&in, bytes)); - in.grammar_fingerprint - = CANDIDATE2_CORRECTED_A1_GRAMMAR_FINGERPRINT; + in.grammar_fingerprint = CANDIDATE2_CORRECTED_A1_GRAMMAR_FINGERPRINT; UT_ASSERT(cluster_replacement_wire_encode(&in, bytes)); bytes[64] ^= 1; memset(&out, 0xD4, sizeof(out)); @@ -337,26 +323,25 @@ UT_TEST(test_phase3_ingress_rejects_wrong_endpoint_without_handoff_mutation) uint8 bytes[CLUSTER_REPLACEMENT_WIRE_BYTES]; cluster_replacement_phase3_handoff_init(&handoff); - message = make_valid_message( - CLUSTER_REPLACEMENT_WIRE_PHASE_TARGET_RECOVERY_READY); + message = make_valid_message(CLUSTER_REPLACEMENT_WIRE_PHASE_TARGET_RECOVERY_READY); envelope = make_phase3_envelope(message.target_node_id, 1, message.epoch + 1); UT_ASSERT(cluster_replacement_wire_encode(&message, bytes)); before = handoff; envelope.msg_type = PGRAC_IC_MSG_GES_REPLY; - UT_ASSERT_EQ((int)ingress_phase3(&handoff, &envelope, bytes, - message.target_node_id, 1, message.epoch + 1, 7), + UT_ASSERT_EQ((int)ingress_phase3(&handoff, &envelope, bytes, message.target_node_id, 1, + message.epoch + 1, 7), (int)CLUSTER_REPLACEMENT_PHASE3_INGRESS_REJECTED); UT_ASSERT_EQ(memcmp(&handoff, &before, sizeof(handoff)), 0); envelope.msg_type = PGRAC_IC_MSG_GES_REQUEST; - UT_ASSERT_EQ((int)ingress_phase3(&handoff, &envelope, bytes, - message.target_node_id + 1, 1, message.epoch + 1, 7), + UT_ASSERT_EQ((int)ingress_phase3(&handoff, &envelope, bytes, message.target_node_id + 1, 1, + message.epoch + 1, 7), (int)CLUSTER_REPLACEMENT_PHASE3_INGRESS_REJECTED); UT_ASSERT_EQ(memcmp(&handoff, &before, sizeof(handoff)), 0); envelope.dest_node_id = 2; - UT_ASSERT_EQ((int)ingress_phase3(&handoff, &envelope, bytes, - message.target_node_id, 1, message.epoch + 1, 7), + UT_ASSERT_EQ((int)ingress_phase3(&handoff, &envelope, bytes, message.target_node_id, 1, + message.epoch + 1, 7), (int)CLUSTER_REPLACEMENT_PHASE3_INGRESS_REJECTED); UT_ASSERT_EQ(memcmp(&handoff, &before, sizeof(handoff)), 0); } @@ -373,34 +358,33 @@ UT_TEST(test_phase3_ingress_rejects_wire_drift_without_handoff_mutation) uint8 bytes[CLUSTER_REPLACEMENT_WIRE_BYTES]; cluster_replacement_phase3_handoff_init(&handoff); - message = make_valid_message( - CLUSTER_REPLACEMENT_WIRE_PHASE_TARGET_RECOVERY_READY); + message = make_valid_message(CLUSTER_REPLACEMENT_WIRE_PHASE_TARGET_RECOVERY_READY); envelope = make_phase3_envelope(message.target_node_id, 1, message.epoch + 1); UT_ASSERT(cluster_replacement_wire_encode(&message, bytes)); before = handoff; bytes[12] = 2; - UT_ASSERT_EQ((int)ingress_phase3(&handoff, &envelope, bytes, - message.target_node_id, 1, message.epoch + 1, 7), + UT_ASSERT_EQ((int)ingress_phase3(&handoff, &envelope, bytes, message.target_node_id, 1, + message.epoch + 1, 7), (int)CLUSTER_REPLACEMENT_PHASE3_INGRESS_REJECTED); UT_ASSERT_EQ(memcmp(&handoff, &before, sizeof(handoff)), 0); bytes[12] = CLUSTER_REPLACEMENT_WIRE_VERSION; bytes[64] ^= 1; - UT_ASSERT_EQ((int)ingress_phase3(&handoff, &envelope, bytes, - message.target_node_id, 1, message.epoch + 1, 7), + UT_ASSERT_EQ((int)ingress_phase3(&handoff, &envelope, bytes, message.target_node_id, 1, + message.epoch + 1, 7), (int)CLUSTER_REPLACEMENT_PHASE3_INGRESS_REJECTED); UT_ASSERT_EQ(memcmp(&handoff, &before, sizeof(handoff)), 0); bytes[64] ^= 1; bytes[60] = 1; - UT_ASSERT_EQ((int)ingress_phase3(&handoff, &envelope, bytes, - message.target_node_id, 1, message.epoch + 1, 7), + UT_ASSERT_EQ((int)ingress_phase3(&handoff, &envelope, bytes, message.target_node_id, 1, + message.epoch + 1, 7), (int)CLUSTER_REPLACEMENT_PHASE3_INGRESS_REJECTED); UT_ASSERT_EQ(memcmp(&handoff, &before, sizeof(handoff)), 0); message = make_valid_message(CLUSTER_REPLACEMENT_WIRE_PHASE_PURGE_ACK); UT_ASSERT(cluster_replacement_wire_encode(&message, bytes)); - UT_ASSERT_EQ((int)ingress_phase3(&handoff, &envelope, bytes, - message.target_node_id, 1, message.epoch + 1, 7), + UT_ASSERT_EQ((int)ingress_phase3(&handoff, &envelope, bytes, message.target_node_id, 1, + message.epoch + 1, 7), (int)CLUSTER_REPLACEMENT_PHASE3_INGRESS_REJECTED); UT_ASSERT_EQ(memcmp(&handoff, &before, sizeof(handoff)), 0); } @@ -417,13 +401,12 @@ UT_TEST(test_phase3_ingress_enqueues_only_observation_handoff) uint8 bytes[CLUSTER_REPLACEMENT_WIRE_BYTES]; cluster_replacement_phase3_handoff_init(&handoff); - message = make_valid_message( - CLUSTER_REPLACEMENT_WIRE_PHASE_TARGET_RECOVERY_READY); + message = make_valid_message(CLUSTER_REPLACEMENT_WIRE_PHASE_TARGET_RECOVERY_READY); envelope = make_phase3_envelope(message.target_node_id, 1, message.epoch + 1); UT_ASSERT(cluster_replacement_wire_encode(&message, bytes)); - UT_ASSERT_EQ((int)ingress_phase3(&handoff, &envelope, bytes, - message.target_node_id, 1, message.epoch + 1, 7), + UT_ASSERT_EQ((int)ingress_phase3(&handoff, &envelope, bytes, message.target_node_id, 1, + message.epoch + 1, 7), (int)CLUSTER_REPLACEMENT_PHASE3_INGRESS_ENQUEUED); UT_ASSERT_EQ((int)cluster_replacement_phase3_handoff_pending(&handoff), 1); memset(&item, 0xA5, sizeof(item)); @@ -450,16 +433,13 @@ UT_TEST(test_phase3_ingress_maps_wire_baseline_to_outer_committed_epoch) const uint64 committed_epoch = UINT64_C(71); cluster_replacement_phase3_handoff_init(&handoff); - message = make_valid_message( - CLUSTER_REPLACEMENT_WIRE_PHASE_TARGET_RECOVERY_READY); + message = make_valid_message(CLUSTER_REPLACEMENT_WIRE_PHASE_TARGET_RECOVERY_READY); message.epoch = baseline_epoch; - envelope = make_phase3_envelope( - message.target_node_id, 1, committed_epoch); + envelope = make_phase3_envelope(message.target_node_id, 1, committed_epoch); UT_ASSERT(cluster_replacement_wire_encode(&message, bytes)); - UT_ASSERT_EQ((int)ingress_phase3( - &handoff, &envelope, bytes, message.target_node_id, 1, - committed_epoch, 7), + UT_ASSERT_EQ((int)ingress_phase3(&handoff, &envelope, bytes, message.target_node_id, 1, + committed_epoch, 7), (int)CLUSTER_REPLACEMENT_PHASE3_INGRESS_ENQUEUED); UT_ASSERT_EQ((int)cluster_replacement_phase3_handoff_pending(&handoff), 1); } @@ -478,14 +458,13 @@ UT_TEST(test_phase3_handoff_is_bounded_fifo_without_overwrite) uint32 i; cluster_replacement_phase3_handoff_init(&handoff); - message = make_valid_message( - CLUSTER_REPLACEMENT_WIRE_PHASE_TARGET_RECOVERY_READY); + message = make_valid_message(CLUSTER_REPLACEMENT_WIRE_PHASE_TARGET_RECOVERY_READY); envelope = make_phase3_envelope(message.target_node_id, 1, message.epoch + 1); for (i = 0; i < CLUSTER_REPLACEMENT_PHASE3_HANDOFF_CAPACITY; i++) { message.request_nonce = UINT64_C(1000) + i; UT_ASSERT(cluster_replacement_wire_encode(&message, bytes)); - UT_ASSERT_EQ((int)ingress_phase3(&handoff, &envelope, bytes, - message.target_node_id, 1, message.epoch + 1, 7), + UT_ASSERT_EQ((int)ingress_phase3(&handoff, &envelope, bytes, message.target_node_id, 1, + message.epoch + 1, 7), (int)CLUSTER_REPLACEMENT_PHASE3_INGRESS_ENQUEUED); } UT_ASSERT_EQ((int)cluster_replacement_phase3_handoff_pending(&handoff), @@ -493,8 +472,8 @@ UT_TEST(test_phase3_handoff_is_bounded_fifo_without_overwrite) before_full = handoff; message.request_nonce = UINT64_C(9999); UT_ASSERT(cluster_replacement_wire_encode(&message, bytes)); - UT_ASSERT_EQ((int)ingress_phase3(&handoff, &envelope, bytes, - message.target_node_id, 1, message.epoch + 1, 7), + UT_ASSERT_EQ((int)ingress_phase3(&handoff, &envelope, bytes, message.target_node_id, 1, + message.epoch + 1, 7), (int)CLUSTER_REPLACEMENT_PHASE3_INGRESS_FULL); UT_ASSERT_EQ(memcmp(&handoff, &before_full, sizeof(handoff)), 0); diff --git a/src/test/cluster_unit/test_cluster_resource_x_handoff.c b/src/test/cluster_unit/test_cluster_resource_x_handoff.c index dbedc34afa6..d624e2bc1fb 100644 --- a/src/test/cluster_unit/test_cluster_resource_x_handoff.c +++ b/src/test/cluster_unit/test_cluster_resource_x_handoff.c @@ -18,11 +18,9 @@ UT_DEFINE_GLOBALS(); void -ExceptionalCondition(const char *condition_name, const char *file_name, - int line_number) +ExceptionalCondition(const char *condition_name, const char *file_name, int line_number) { - printf("# Assert failed: %s at %s:%d\n", condition_name, file_name, - line_number); + printf("# Assert failed: %s at %s:%d\n", condition_name, file_name, line_number); abort(); } diff --git a/src/test/cluster_unit/test_cluster_resource_x_identity.c b/src/test/cluster_unit/test_cluster_resource_x_identity.c index 1384f47a796..0f917087f3e 100644 --- a/src/test/cluster_unit/test_cluster_resource_x_identity.c +++ b/src/test/cluster_unit/test_cluster_resource_x_identity.c @@ -14,11 +14,9 @@ UT_DEFINE_GLOBALS(); void -ExceptionalCondition(const char *condition_name, const char *file_name, - int line_number) +ExceptionalCondition(const char *condition_name, const char *file_name, int line_number) { - printf("# Assert failed: %s at %s:%d\n", condition_name, file_name, - line_number); + printf("# Assert failed: %s at %s:%d\n", condition_name, file_name, line_number); abort(); } @@ -69,8 +67,7 @@ UT_TEST(test_validation_rejects_invalid_native_tag_fields) BufferTag tag = make_tag(); ResourceXAssertion assertion; - UT_ASSERT(resource_x_assertion_init(&tag, RESOURCE_X_PROTOCOL_NODE_LIMIT - 1, - &assertion)); + UT_ASSERT(resource_x_assertion_init(&tag, RESOURCE_X_PROTOCOL_NODE_LIMIT - 1, &assertion)); assertion.resource.relNumber = InvalidRelFileNumber; UT_ASSERT(!resource_x_assertion_valid(&assertion)); assertion.resource = tag; @@ -108,8 +105,7 @@ UT_TEST(test_equality_is_exactly_resource_and_requester_node) UT_ASSERT(resource_x_assertion_init(&tag, 7, &left)); UT_ASSERT(resource_x_assertion_init(&tag, 7, &right)); UT_ASSERT(resource_x_assertion_equal(&left, &right)); - UT_ASSERT_EQ(resource_x_assertion_hash(&left), - resource_x_assertion_hash(&right)); + UT_ASSERT_EQ(resource_x_assertion_hash(&left), resource_x_assertion_hash(&right)); right.requester_node++; UT_ASSERT(!resource_x_assertion_equal(&left, &right)); right = left; @@ -150,8 +146,7 @@ UT_TEST(test_null_comparisons_fail_closed) UT_TEST(test_proof_readiness_is_explicitly_available) { - UT_ASSERT_STR_EQ(resource_x_proof_readiness_status(), - "AVAILABLE_PROOF_KIND"); + UT_ASSERT_STR_EQ(resource_x_proof_readiness_status(), "AVAILABLE_PROOF_KIND"); } int diff --git a/src/test/cluster_unit/test_cluster_resource_x_node_wire.c b/src/test/cluster_unit/test_cluster_resource_x_node_wire.c index 72a47b21be8..ad4627c4c70 100644 --- a/src/test/cluster_unit/test_cluster_resource_x_node_wire.c +++ b/src/test/cluster_unit/test_cluster_resource_x_node_wire.c @@ -43,11 +43,9 @@ errfinish(const char *filename pg_attribute_unused(), int lineno pg_attribute_un } void -ExceptionalCondition(const char *condition_name, const char *file_name, - int line_number) +ExceptionalCondition(const char *condition_name, const char *file_name, int line_number) { - printf("# Assert failed: %s at %s:%d\n", condition_name, file_name, - line_number); + printf("# Assert failed: %s at %s:%d\n", condition_name, file_name, line_number); abort(); } @@ -69,25 +67,18 @@ UT_TEST(test_wire_kind_and_proof_domains_are_closed) UT_ASSERT_EQ(RESOURCE_X_PROOF_LOCAL_IMAGE, 2); UT_ASSERT_EQ(RESOURCE_X_PROOF_DURABLE_STORAGE, 3); UT_ASSERT_EQ(RESOURCE_X_WIRE_KIND_MIN, RESOURCE_X_WIRE_ASSERT_X); - UT_ASSERT_EQ(RESOURCE_X_WIRE_KIND_MAX, - RESOURCE_X_WIRE_SOURCE_SETTLEMENT_ACK_V2); + UT_ASSERT_EQ(RESOURCE_X_WIRE_KIND_MAX, RESOURCE_X_WIRE_SOURCE_SETTLEMENT_ACK_V2); UT_ASSERT_EQ(RESOURCE_X_PROOF_KIND_MIN, RESOURCE_X_PROOF_REMOTE_CARRIER); - UT_ASSERT_EQ(RESOURCE_X_PROOF_KIND_MAX, - RESOURCE_X_PROOF_DURABLE_STORAGE); + UT_ASSERT_EQ(RESOURCE_X_PROOF_KIND_MAX, RESOURCE_X_PROOF_DURABLE_STORAGE); } UT_TEST(test_reused_message_numbers_remain_exact) { - UT_ASSERT_EQ(RESOURCE_X_MSG_ASSERT_X, - PGRAC_IC_MSG_GCS_BLOCK_REQUEST); - UT_ASSERT_EQ(RESOURCE_X_MSG_IMAGE_OR_GRANT, - PGRAC_IC_MSG_GCS_BLOCK_REPLY); - UT_ASSERT_EQ(RESOURCE_X_MSG_BLOCK_TO_N, - PGRAC_IC_MSG_GCS_BLOCK_INVALIDATE); - UT_ASSERT_EQ(RESOURCE_X_MSG_BLOCKED_TO_N, - PGRAC_IC_MSG_GCS_BLOCK_INVALIDATE_ACK); - UT_ASSERT_EQ(RESOURCE_X_MSG_SETTLEMENT_OR_RELEASE, - PGRAC_IC_MSG_GCS_BLOCK_DONE); + UT_ASSERT_EQ(RESOURCE_X_MSG_ASSERT_X, PGRAC_IC_MSG_GCS_BLOCK_REQUEST); + UT_ASSERT_EQ(RESOURCE_X_MSG_IMAGE_OR_GRANT, PGRAC_IC_MSG_GCS_BLOCK_REPLY); + UT_ASSERT_EQ(RESOURCE_X_MSG_BLOCK_TO_N, PGRAC_IC_MSG_GCS_BLOCK_INVALIDATE); + UT_ASSERT_EQ(RESOURCE_X_MSG_BLOCKED_TO_N, PGRAC_IC_MSG_GCS_BLOCK_INVALIDATE_ACK); + UT_ASSERT_EQ(RESOURCE_X_MSG_SETTLEMENT_OR_RELEASE, PGRAC_IC_MSG_GCS_BLOCK_DONE); } UT_TEST(test_common_wire_layout_is_exact) @@ -119,31 +110,23 @@ UT_TEST(test_common_wire_layout_is_exact) UT_TEST(test_local_proof_layout_is_exact) { UT_ASSERT_EQ(sizeof(ResourceXLocalProofDeclarationV1), 152); - UT_ASSERT_EQ(offsetof(ResourceXLocalProofDeclarationV1, - local_holder_authority_generation), 96); - UT_ASSERT_EQ(offsetof(ResourceXLocalProofDeclarationV1, - requester_target_generation), 104); + UT_ASSERT_EQ(offsetof(ResourceXLocalProofDeclarationV1, local_holder_authority_generation), 96); + UT_ASSERT_EQ(offsetof(ResourceXLocalProofDeclarationV1, requester_target_generation), 104); UT_ASSERT_EQ(offsetof(ResourceXLocalProofDeclarationV1, page_scn_lsn), 112); UT_ASSERT_EQ(offsetof(ResourceXLocalProofDeclarationV1, dependency_count), 120); - UT_ASSERT_EQ(offsetof(ResourceXLocalProofDeclarationV1, - dependency_vector_crc32c), 124); + UT_ASSERT_EQ(offsetof(ResourceXLocalProofDeclarationV1, dependency_vector_crc32c), 124); UT_ASSERT_EQ(offsetof(ResourceXLocalProofDeclarationV1, page_checksum), 128); - UT_ASSERT_EQ(offsetof(ResourceXLocalProofDeclarationV1, - local_image_proof_crc32c), 132); - UT_ASSERT_EQ(offsetof(ResourceXLocalProofDeclarationV1, - requester_connection_generation), 136); - UT_ASSERT_EQ(offsetof(ResourceXLocalProofDeclarationV1, - local_proof_generation), 144); + UT_ASSERT_EQ(offsetof(ResourceXLocalProofDeclarationV1, local_image_proof_crc32c), 132); + UT_ASSERT_EQ(offsetof(ResourceXLocalProofDeclarationV1, requester_connection_generation), 136); + UT_ASSERT_EQ(offsetof(ResourceXLocalProofDeclarationV1, local_proof_generation), 144); } UT_TEST(test_blocked_to_n_layout_is_exact) { UT_ASSERT_EQ(sizeof(ResourceXBlockedToNProofV1), 312); UT_ASSERT_EQ(offsetof(ResourceXBlockedToNProofV1, source_fence), 96); - UT_ASSERT_EQ(offsetof(ResourceXBlockedToNProofV1, - source_carrier_generation), 130); - UT_ASSERT_EQ(offsetof(ResourceXBlockedToNProofV1, - requester_target_generation), 138); + UT_ASSERT_EQ(offsetof(ResourceXBlockedToNProofV1, source_carrier_generation), 130); + UT_ASSERT_EQ(offsetof(ResourceXBlockedToNProofV1, requester_target_generation), 138); UT_ASSERT_EQ(offsetof(ResourceXBlockedToNProofV1, page_scn_lsn), 146); UT_ASSERT_EQ(offsetof(ResourceXBlockedToNProofV1, dependency_count), 154); UT_ASSERT_EQ(offsetof(ResourceXBlockedToNProofV1, dependencies), 156); @@ -152,8 +135,7 @@ UT_TEST(test_blocked_to_n_layout_is_exact) UT_ASSERT_EQ(offsetof(ResourceXBlockedToNProofV1, source_disposition), 292); UT_ASSERT_EQ(offsetof(ResourceXBlockedToNProofV1, proof_kind), 293); UT_ASSERT_EQ(offsetof(ResourceXBlockedToNProofV1, proof_flags), 294); - UT_ASSERT_EQ(offsetof(ResourceXBlockedToNProofV1, - holder_connection_generation), 296); + UT_ASSERT_EQ(offsetof(ResourceXBlockedToNProofV1, holder_connection_generation), 296); UT_ASSERT_EQ(offsetof(ResourceXBlockedToNProofV1, acting_formation), 304); } @@ -161,12 +143,9 @@ UT_TEST(test_authority_grant_layout_is_exact) { UT_ASSERT_EQ(sizeof(ResourceXAuthorityGrantV1), 312); UT_ASSERT_EQ(offsetof(ResourceXAuthorityGrantV1, source_fence), 96); - UT_ASSERT_EQ(offsetof(ResourceXAuthorityGrantV1, - final_authority_generation), 130); - UT_ASSERT_EQ(offsetof(ResourceXAuthorityGrantV1, - source_carrier_generation), 138); - UT_ASSERT_EQ(offsetof(ResourceXAuthorityGrantV1, - requester_target_generation), 146); + UT_ASSERT_EQ(offsetof(ResourceXAuthorityGrantV1, final_authority_generation), 130); + UT_ASSERT_EQ(offsetof(ResourceXAuthorityGrantV1, source_carrier_generation), 138); + UT_ASSERT_EQ(offsetof(ResourceXAuthorityGrantV1, requester_target_generation), 146); UT_ASSERT_EQ(offsetof(ResourceXAuthorityGrantV1, page_scn_lsn), 154); UT_ASSERT_EQ(offsetof(ResourceXAuthorityGrantV1, dependency_count), 162); UT_ASSERT_EQ(offsetof(ResourceXAuthorityGrantV1, dependencies), 164); @@ -175,26 +154,21 @@ UT_TEST(test_authority_grant_layout_is_exact) UT_ASSERT_EQ(offsetof(ResourceXAuthorityGrantV1, proof_kind), 300); UT_ASSERT_EQ(offsetof(ResourceXAuthorityGrantV1, source_disposition), 301); UT_ASSERT_EQ(offsetof(ResourceXAuthorityGrantV1, grant_flags), 302); - UT_ASSERT_EQ(offsetof(ResourceXAuthorityGrantV1, - requester_connection_generation), 304); + UT_ASSERT_EQ(offsetof(ResourceXAuthorityGrantV1, requester_connection_generation), 304); } UT_TEST(test_image_envelope_layout_is_exact) { UT_ASSERT_EQ(sizeof(ResourceXImageEnvelopeV1), 8520); UT_ASSERT_EQ(offsetof(ResourceXImageEnvelopeV1, request_tail), 96); - UT_ASSERT_EQ(offsetof(ResourceXImageEnvelopeV1, - conversion_base_generation), 116); + UT_ASSERT_EQ(offsetof(ResourceXImageEnvelopeV1, conversion_base_generation), 116); UT_ASSERT_EQ(offsetof(ResourceXImageEnvelopeV1, source_fence), 124); - UT_ASSERT_EQ(offsetof(ResourceXImageEnvelopeV1, - source_carrier_generation), 158); - UT_ASSERT_EQ(offsetof(ResourceXImageEnvelopeV1, - requester_target_generation), 166); + UT_ASSERT_EQ(offsetof(ResourceXImageEnvelopeV1, source_carrier_generation), 158); + UT_ASSERT_EQ(offsetof(ResourceXImageEnvelopeV1, requester_target_generation), 166); UT_ASSERT_EQ(offsetof(ResourceXImageEnvelopeV1, page_scn_lsn), 174); UT_ASSERT_EQ(offsetof(ResourceXImageEnvelopeV1, dependency_count), 182); UT_ASSERT_EQ(offsetof(ResourceXImageEnvelopeV1, dependencies), 184); - UT_ASSERT_EQ(offsetof(ResourceXImageEnvelopeV1, - dependency_vector_crc32c), 312); + UT_ASSERT_EQ(offsetof(ResourceXImageEnvelopeV1, dependency_vector_crc32c), 312); UT_ASSERT_EQ(offsetof(ResourceXImageEnvelopeV1, page_checksum), 316); UT_ASSERT_EQ(offsetof(ResourceXImageEnvelopeV1, image_length), 320); UT_ASSERT_EQ(offsetof(ResourceXImageEnvelopeV1, source_disposition), 324); @@ -207,18 +181,13 @@ UT_TEST(test_image_envelope_layout_is_exact) UT_TEST(test_install_settlement_layout_is_exact) { UT_ASSERT_EQ(sizeof(ResourceXInstallSettlementV1), 152); - UT_ASSERT_EQ(offsetof(ResourceXInstallSettlementV1, - conversion_base_generation), 96); - UT_ASSERT_EQ(offsetof(ResourceXInstallSettlementV1, - final_authority_generation), 104); - UT_ASSERT_EQ(offsetof(ResourceXInstallSettlementV1, - requester_connection_generation), 112); - UT_ASSERT_EQ(offsetof(ResourceXInstallSettlementV1, - requester_target_generation), 120); + UT_ASSERT_EQ(offsetof(ResourceXInstallSettlementV1, conversion_base_generation), 96); + UT_ASSERT_EQ(offsetof(ResourceXInstallSettlementV1, final_authority_generation), 104); + UT_ASSERT_EQ(offsetof(ResourceXInstallSettlementV1, requester_connection_generation), 112); + UT_ASSERT_EQ(offsetof(ResourceXInstallSettlementV1, requester_target_generation), 120); UT_ASSERT_EQ(offsetof(ResourceXInstallSettlementV1, page_scn_lsn), 128); UT_ASSERT_EQ(offsetof(ResourceXInstallSettlementV1, page_checksum), 136); - UT_ASSERT_EQ(offsetof(ResourceXInstallSettlementV1, - source_proof_crc32c), 140); + UT_ASSERT_EQ(offsetof(ResourceXInstallSettlementV1, source_proof_crc32c), 140); UT_ASSERT_EQ(offsetof(ResourceXInstallSettlementV1, installed_mode), 144); UT_ASSERT_EQ(offsetof(ResourceXInstallSettlementV1, requester_role), 145); UT_ASSERT_EQ(offsetof(ResourceXInstallSettlementV1, terminal_outcome), 146); @@ -276,34 +245,30 @@ static void test_reseal(uint8 *bytes, uint16 len); static ResourceXDecodedFrame make_bootstrap_frame(bool ack) { - ResourceXDecodedFrame frame - = make_control_frame(RESOURCE_X_WIRE_ASSERT_X); + ResourceXDecodedFrame frame = make_control_frame(RESOURCE_X_WIRE_ASSERT_X); frame.kind = RESOURCE_X_WIRE_PREASSERT_BOOTSTRAP; - frame.common.base_authority_generation - = ack ? UINT64_C(0x0102030405060708) : 0; + frame.common.base_authority_generation = ack ? UINT64_C(0x0102030405060708) : 0; frame.common.authority_generation = 0; frame.common.ordered_lane = 0; frame.common.observed_mode = PCM_STATE_N; frame.common.target_mode = PCM_STATE_X; frame.common.source_candidate = 0; frame.common.retain_pi_if_dirty = 0; - frame.common.outcome - = ack ? RESOURCE_X_OUTCOME_OK : RESOURCE_X_OUTCOME_NONE; + frame.common.outcome = ack ? RESOURCE_X_OUTCOME_OK : RESOURCE_X_OUTCOME_NONE; frame.common.flags = 0; return frame; } static void -assert_bootstrap_encode_rejected(uint8 msg_type, - ResourceXDecodedFrame *frame) +assert_bootstrap_encode_rejected(uint8 msg_type, ResourceXDecodedFrame *frame) { ResourceXWireReject reject = RESOURCE_X_WIRE_REJECT_NONE; uint8 bytes[RESOURCE_X_CONTROL_V1_BYTES]; uint16 len = 0; - UT_ASSERT(!cluster_resource_x_wire_encode( - msg_type, frame, bytes, sizeof(bytes), &len, &reject)); + UT_ASSERT( + !cluster_resource_x_wire_encode(msg_type, frame, bytes, sizeof(bytes), &len, &reject)); UT_ASSERT(reject != RESOURCE_X_WIRE_REJECT_NONE); } @@ -316,25 +281,22 @@ UT_TEST(test_preassert_bootstrap_request_and_ack_are_direction_exact) uint8 bytes[RESOURCE_X_CONTROL_V1_BYTES]; uint16 len = 0; - UT_ASSERT(cluster_resource_x_wire_encode( - RESOURCE_X_MSG_ASSERT_X, &request, bytes, sizeof(bytes), &len, - &reject)); + UT_ASSERT(cluster_resource_x_wire_encode(RESOURCE_X_MSG_ASSERT_X, &request, bytes, + sizeof(bytes), &len, &reject)); UT_ASSERT_EQ(len, RESOURCE_X_CONTROL_V1_BYTES); UT_ASSERT_EQ(bytes[1], RESOURCE_X_WIRE_PREASSERT_BOOTSTRAP); - UT_ASSERT(cluster_resource_x_wire_decode( - RESOURCE_X_MSG_ASSERT_X, bytes, len, &decoded, &reject)); + UT_ASSERT( + cluster_resource_x_wire_decode(RESOURCE_X_MSG_ASSERT_X, bytes, len, &decoded, &reject)); UT_ASSERT_EQ(decoded.common.base_authority_generation, 0); UT_ASSERT_EQ(decoded.common.authority_generation, 0); UT_ASSERT_EQ(decoded.common.outcome, RESOURCE_X_OUTCOME_NONE); - UT_ASSERT(cluster_resource_x_wire_encode( - RESOURCE_X_MSG_IMAGE_OR_GRANT, &ack, bytes, sizeof(bytes), &len, - &reject)); + UT_ASSERT(cluster_resource_x_wire_encode(RESOURCE_X_MSG_IMAGE_OR_GRANT, &ack, bytes, + sizeof(bytes), &len, &reject)); UT_ASSERT_EQ(len, RESOURCE_X_CONTROL_V1_BYTES); - UT_ASSERT(cluster_resource_x_wire_decode( - RESOURCE_X_MSG_IMAGE_OR_GRANT, bytes, len, &decoded, &reject)); - UT_ASSERT_EQ(decoded.common.base_authority_generation, - UINT64_C(0x0102030405060708)); + UT_ASSERT(cluster_resource_x_wire_decode(RESOURCE_X_MSG_IMAGE_OR_GRANT, bytes, len, &decoded, + &reject)); + UT_ASSERT_EQ(decoded.common.base_authority_generation, UINT64_C(0x0102030405060708)); UT_ASSERT_EQ(decoded.common.authority_generation, 0); UT_ASSERT_EQ(decoded.common.outcome, RESOURCE_X_OUTCOME_OK); @@ -438,19 +400,18 @@ UT_TEST(test_preassert_bootstrap_decode_rejects_reserved_length_and_pair_drift) uint8 bytes[RESOURCE_X_CONTROL_V1_BYTES]; uint16 len = 0; - UT_ASSERT(cluster_resource_x_wire_encode( - RESOURCE_X_MSG_ASSERT_X, &request, bytes, sizeof(bytes), &len, - &reject)); + UT_ASSERT(cluster_resource_x_wire_encode(RESOURCE_X_MSG_ASSERT_X, &request, bytes, + sizeof(bytes), &len, &reject)); bytes[82] = 1; test_reseal(bytes, len); - UT_ASSERT(!cluster_resource_x_wire_decode( - RESOURCE_X_MSG_ASSERT_X, bytes, len, &decoded, &reject)); + UT_ASSERT( + !cluster_resource_x_wire_decode(RESOURCE_X_MSG_ASSERT_X, bytes, len, &decoded, &reject)); UT_ASSERT_EQ(reject, RESOURCE_X_WIRE_REJECT_RESERVED); - UT_ASSERT(!cluster_resource_x_wire_decode( - RESOURCE_X_MSG_ASSERT_X, bytes, len - 1, &decoded, &reject)); + UT_ASSERT(!cluster_resource_x_wire_decode(RESOURCE_X_MSG_ASSERT_X, bytes, len - 1, &decoded, + &reject)); UT_ASSERT_EQ(reject, RESOURCE_X_WIRE_REJECT_LEGACY_LENGTH); - UT_ASSERT(!cluster_resource_x_wire_decode( - RESOURCE_X_MSG_BLOCK_TO_N, bytes, len, &decoded, &reject)); + UT_ASSERT( + !cluster_resource_x_wire_decode(RESOURCE_X_MSG_BLOCK_TO_N, bytes, len, &decoded, &reject)); UT_ASSERT_EQ(reject, RESOURCE_X_WIRE_REJECT_TYPE_KIND); } @@ -462,8 +423,8 @@ UT_TEST(test_control_codec_is_network_order_and_crc_exact) uint8 bytes[RESOURCE_X_CONTROL_V1_BYTES]; uint16 encoded_len = 0; - UT_ASSERT(cluster_resource_x_wire_encode(RESOURCE_X_MSG_ASSERT_X, &frame, - bytes, sizeof(bytes), &encoded_len, &reject)); + UT_ASSERT(cluster_resource_x_wire_encode(RESOURCE_X_MSG_ASSERT_X, &frame, bytes, sizeof(bytes), + &encoded_len, &reject)); UT_ASSERT_EQ(reject, RESOURCE_X_WIRE_REJECT_NONE); UT_ASSERT_EQ(encoded_len, RESOURCE_X_CONTROL_V1_BYTES); UT_ASSERT_EQ(bytes[0], RESOURCE_X_WIRE_VERSION); @@ -477,74 +438,63 @@ UT_TEST(test_control_codec_is_network_order_and_crc_exact) UT_ASSERT(memcmp(bytes + 4, "\0\0\0\0", 4) != 0); memset(&decoded, 0xa5, sizeof(decoded)); - UT_ASSERT(cluster_resource_x_wire_decode(RESOURCE_X_MSG_ASSERT_X, bytes, - encoded_len, &decoded, &reject)); + UT_ASSERT(cluster_resource_x_wire_decode(RESOURCE_X_MSG_ASSERT_X, bytes, encoded_len, &decoded, + &reject)); UT_ASSERT_EQ(reject, RESOURCE_X_WIRE_REJECT_NONE); UT_ASSERT_EQ(decoded.kind, RESOURCE_X_WIRE_ASSERT_X); UT_ASSERT_EQ(decoded.payload_bytes, RESOURCE_X_CONTROL_V1_BYTES); UT_ASSERT(resource_x_assertion_equal(&decoded.common.logical_assertion, - &frame.common.logical_assertion)); - UT_ASSERT_EQ(decoded.common.base_authority_generation, - frame.common.base_authority_generation); + &frame.common.logical_assertion)); + UT_ASSERT_EQ(decoded.common.base_authority_generation, frame.common.base_authority_generation); UT_ASSERT_EQ(decoded.common.ordered_lane, frame.common.ordered_lane); - UT_ASSERT_EQ(decoded.common.authority_generation, - frame.common.authority_generation); + UT_ASSERT_EQ(decoded.common.authority_generation, frame.common.authority_generation); } UT_TEST(test_physical_sender_generation_rebind_preserves_block_semantics) { - ResourceXDecodedFrame frame - = make_control_frame(RESOURCE_X_WIRE_BLOCK_TO_N); + ResourceXDecodedFrame frame = make_control_frame(RESOURCE_X_WIRE_BLOCK_TO_N); ResourceXDecodedFrame decoded; ResourceXWireReject reject = RESOURCE_X_WIRE_REJECT_NONE; uint8 bytes[RESOURCE_X_CONTROL_V1_BYTES]; uint16 encoded_len = 0; - UT_ASSERT(cluster_resource_x_wire_encode( - RESOURCE_X_MSG_BLOCK_TO_N, &frame, bytes, sizeof(bytes), - &encoded_len, &reject)); + UT_ASSERT(cluster_resource_x_wire_encode(RESOURCE_X_MSG_BLOCK_TO_N, &frame, bytes, + sizeof(bytes), &encoded_len, &reject)); UT_ASSERT_EQ(encoded_len, RESOURCE_X_CONTROL_V1_BYTES); - UT_ASSERT(cluster_resource_x_wire_rebind_sender_generation( - RESOURCE_X_MSG_BLOCK_TO_N, bytes, encoded_len, 77, &reject)); - UT_ASSERT(cluster_resource_x_wire_decode( - RESOURCE_X_MSG_BLOCK_TO_N, bytes, encoded_len, &decoded, &reject)); + UT_ASSERT(cluster_resource_x_wire_rebind_sender_generation(RESOURCE_X_MSG_BLOCK_TO_N, bytes, + encoded_len, 77, &reject)); + UT_ASSERT(cluster_resource_x_wire_decode(RESOURCE_X_MSG_BLOCK_TO_N, bytes, encoded_len, + &decoded, &reject)); UT_ASSERT_EQ(decoded.common.sender_connection_generation, 77); UT_ASSERT_EQ(decoded.kind, RESOURCE_X_WIRE_BLOCK_TO_N); UT_ASSERT(resource_x_assertion_equal(&decoded.common.logical_assertion, - &frame.common.logical_assertion)); - UT_ASSERT_EQ(decoded.common.base_authority_generation, - frame.common.base_authority_generation); - UT_ASSERT_EQ(decoded.common.assertion_sequence, - frame.common.assertion_sequence); + &frame.common.logical_assertion)); + UT_ASSERT_EQ(decoded.common.base_authority_generation, frame.common.base_authority_generation); + UT_ASSERT_EQ(decoded.common.assertion_sequence, frame.common.assertion_sequence); UT_ASSERT_EQ(decoded.common.action_node, frame.common.action_node); UT_ASSERT_EQ(decoded.common.observed_mode, frame.common.observed_mode); UT_ASSERT_EQ(decoded.common.target_mode, frame.common.target_mode); - UT_ASSERT_EQ(decoded.common.source_candidate, - frame.common.source_candidate); - UT_ASSERT_EQ(decoded.common.retain_pi_if_dirty, - frame.common.retain_pi_if_dirty); - UT_ASSERT_EQ(decoded.common.authority_generation, - frame.common.authority_generation); - UT_ASSERT(!cluster_resource_x_wire_rebind_sender_generation( - RESOURCE_X_MSG_BLOCK_TO_N, bytes, encoded_len, 0, &reject)); + UT_ASSERT_EQ(decoded.common.source_candidate, frame.common.source_candidate); + UT_ASSERT_EQ(decoded.common.retain_pi_if_dirty, frame.common.retain_pi_if_dirty); + UT_ASSERT_EQ(decoded.common.authority_generation, frame.common.authority_generation); + UT_ASSERT(!cluster_resource_x_wire_rebind_sender_generation(RESOURCE_X_MSG_BLOCK_TO_N, bytes, + encoded_len, 0, &reject)); } UT_TEST(test_shared_s_carrier_block_to_n_round_trip_is_exact) { - ResourceXDecodedFrame frame - = make_control_frame(RESOURCE_X_WIRE_BLOCK_TO_N); + ResourceXDecodedFrame frame = make_control_frame(RESOURCE_X_WIRE_BLOCK_TO_N); ResourceXDecodedFrame decoded; ResourceXWireReject reject = RESOURCE_X_WIRE_REJECT_NONE; uint8 bytes[RESOURCE_X_CONTROL_V1_BYTES]; uint16 encoded_len = 0; frame.common.observed_mode = PCM_STATE_S; - UT_ASSERT(cluster_resource_x_wire_encode( - RESOURCE_X_MSG_BLOCK_TO_N, &frame, bytes, sizeof(bytes), - &encoded_len, &reject)); + UT_ASSERT(cluster_resource_x_wire_encode(RESOURCE_X_MSG_BLOCK_TO_N, &frame, bytes, + sizeof(bytes), &encoded_len, &reject)); UT_ASSERT_EQ(encoded_len, RESOURCE_X_CONTROL_V1_BYTES); - UT_ASSERT(cluster_resource_x_wire_decode( - RESOURCE_X_MSG_BLOCK_TO_N, bytes, encoded_len, &decoded, &reject)); + UT_ASSERT(cluster_resource_x_wire_decode(RESOURCE_X_MSG_BLOCK_TO_N, bytes, encoded_len, + &decoded, &reject)); UT_ASSERT_EQ(decoded.common.observed_mode, PCM_STATE_S); UT_ASSERT_EQ(decoded.common.target_mode, PCM_STATE_N); UT_ASSERT_EQ(decoded.common.source_candidate, 1); @@ -553,41 +503,36 @@ UT_TEST(test_shared_s_carrier_block_to_n_round_trip_is_exact) UT_TEST(test_shared_s_carrier_proof_and_image_round_trip_preserve_mode) { - ResourceXDecodedFrame proof - = make_typed_frame(RESOURCE_X_WIRE_BLOCKED_TO_N); - ResourceXDecodedFrame image - = make_typed_frame(RESOURCE_X_WIRE_IMAGE_ENVELOPE); + ResourceXDecodedFrame proof = make_typed_frame(RESOURCE_X_WIRE_BLOCKED_TO_N); + ResourceXDecodedFrame image = make_typed_frame(RESOURCE_X_WIRE_IMAGE_ENVELOPE); ResourceXDecodedFrame decoded; ResourceXWireReject reject = RESOURCE_X_WIRE_REJECT_NONE; uint8 bytes[RESOURCE_X_IMAGE_V1_BYTES]; uint16 encoded_len = 0; proof.common.observed_mode = PCM_STATE_S; - UT_ASSERT(cluster_resource_x_wire_encode( - RESOURCE_X_MSG_BLOCKED_TO_N, &proof, bytes, sizeof(bytes), - &encoded_len, &reject)); + UT_ASSERT(cluster_resource_x_wire_encode(RESOURCE_X_MSG_BLOCKED_TO_N, &proof, bytes, + sizeof(bytes), &encoded_len, &reject)); UT_ASSERT_EQ(encoded_len, RESOURCE_X_PROOF_V1_BYTES); - UT_ASSERT(cluster_resource_x_wire_decode( - RESOURCE_X_MSG_BLOCKED_TO_N, bytes, encoded_len, &decoded, &reject)); + UT_ASSERT(cluster_resource_x_wire_decode(RESOURCE_X_MSG_BLOCKED_TO_N, bytes, encoded_len, + &decoded, &reject)); UT_ASSERT_EQ(decoded.common.observed_mode, PCM_STATE_S); UT_ASSERT_EQ(decoded.common.target_mode, PCM_STATE_N); UT_ASSERT(decoded.blocked_has_remote_proof); image.common.observed_mode = PCM_STATE_S; - UT_ASSERT(cluster_resource_x_wire_encode( - RESOURCE_X_MSG_IMAGE_OR_GRANT, &image, bytes, sizeof(bytes), - &encoded_len, &reject)); + UT_ASSERT(cluster_resource_x_wire_encode(RESOURCE_X_MSG_IMAGE_OR_GRANT, &image, bytes, + sizeof(bytes), &encoded_len, &reject)); UT_ASSERT_EQ(encoded_len, RESOURCE_X_IMAGE_V1_BYTES); - UT_ASSERT(cluster_resource_x_wire_decode( - RESOURCE_X_MSG_IMAGE_OR_GRANT, bytes, encoded_len, &decoded, &reject)); + UT_ASSERT(cluster_resource_x_wire_decode(RESOURCE_X_MSG_IMAGE_OR_GRANT, bytes, encoded_len, + &decoded, &reject)); UT_ASSERT_EQ(decoded.common.observed_mode, PCM_STATE_S); UT_ASSERT_EQ(decoded.common.target_mode, PCM_STATE_X); } UT_TEST(test_block_to_n_source_polarity_truth_table_is_closed) { - ResourceXDecodedFrame frame - = make_control_frame(RESOURCE_X_WIRE_BLOCK_TO_N); + ResourceXDecodedFrame frame = make_control_frame(RESOURCE_X_WIRE_BLOCK_TO_N); ResourceXWireReject reject = RESOURCE_X_WIRE_REJECT_NONE; uint8 bytes[RESOURCE_X_CONTROL_V1_BYTES]; uint16 encoded_len = 0; @@ -595,15 +540,13 @@ UT_TEST(test_block_to_n_source_polarity_truth_table_is_closed) frame.common.observed_mode = PCM_STATE_S; frame.common.source_candidate = 1; frame.common.retain_pi_if_dirty = 0; - UT_ASSERT(!cluster_resource_x_wire_encode( - RESOURCE_X_MSG_BLOCK_TO_N, &frame, bytes, sizeof(bytes), - &encoded_len, &reject)); + UT_ASSERT(!cluster_resource_x_wire_encode(RESOURCE_X_MSG_BLOCK_TO_N, &frame, bytes, + sizeof(bytes), &encoded_len, &reject)); frame.common.source_candidate = 0; frame.common.retain_pi_if_dirty = 1; - UT_ASSERT(!cluster_resource_x_wire_encode( - RESOURCE_X_MSG_BLOCK_TO_N, &frame, bytes, sizeof(bytes), - &encoded_len, &reject)); + UT_ASSERT(!cluster_resource_x_wire_encode(RESOURCE_X_MSG_BLOCK_TO_N, &frame, bytes, + sizeof(bytes), &encoded_len, &reject)); } UT_TEST(test_all_control_kind_type_pairs_round_trip) @@ -611,12 +554,10 @@ UT_TEST(test_all_control_kind_type_pairs_round_trip) static const struct { uint8 msg_type; ResourceXWireKind kind; - } cases[] = { - {RESOURCE_X_MSG_ASSERT_X, RESOURCE_X_WIRE_ASSERT_X}, - {RESOURCE_X_MSG_BLOCK_TO_N, RESOURCE_X_WIRE_BLOCK_TO_N}, - {RESOURCE_X_MSG_BLOCKED_TO_N, RESOURCE_X_WIRE_BLOCKED_TO_N}, - {RESOURCE_X_MSG_SETTLEMENT_OR_RELEASE, RESOURCE_X_WIRE_RELEASE_X} - }; + } cases[] = { { RESOURCE_X_MSG_ASSERT_X, RESOURCE_X_WIRE_ASSERT_X }, + { RESOURCE_X_MSG_BLOCK_TO_N, RESOURCE_X_WIRE_BLOCK_TO_N }, + { RESOURCE_X_MSG_BLOCKED_TO_N, RESOURCE_X_WIRE_BLOCKED_TO_N }, + { RESOURCE_X_MSG_SETTLEMENT_OR_RELEASE, RESOURCE_X_WIRE_RELEASE_X } }; uint8 bytes[RESOURCE_X_CONTROL_V1_BYTES]; Size i; @@ -626,10 +567,10 @@ UT_TEST(test_all_control_kind_type_pairs_round_trip) ResourceXWireReject reject; uint16 encoded_len; - UT_ASSERT(cluster_resource_x_wire_encode(cases[i].msg_type, &frame, - bytes, sizeof(bytes), &encoded_len, &reject)); - UT_ASSERT(cluster_resource_x_wire_decode(cases[i].msg_type, bytes, - encoded_len, &decoded, &reject)); + UT_ASSERT(cluster_resource_x_wire_encode(cases[i].msg_type, &frame, bytes, sizeof(bytes), + &encoded_len, &reject)); + UT_ASSERT(cluster_resource_x_wire_decode(cases[i].msg_type, bytes, encoded_len, &decoded, + &reject)); UT_ASSERT_EQ(decoded.kind, cases[i].kind); } } @@ -645,25 +586,25 @@ UT_TEST(test_control_codec_rejects_pair_identity_crc_and_legacy_length) memset(&sentinel, 0xa5, sizeof(sentinel)); decoded = sentinel; - UT_ASSERT(!cluster_resource_x_wire_encode(RESOURCE_X_MSG_BLOCK_TO_N, - &frame, bytes, sizeof(bytes), &encoded_len, &reject)); + UT_ASSERT(!cluster_resource_x_wire_encode(RESOURCE_X_MSG_BLOCK_TO_N, &frame, bytes, + sizeof(bytes), &encoded_len, &reject)); UT_ASSERT_EQ(reject, RESOURCE_X_WIRE_REJECT_TYPE_KIND); frame.common.logical_assertion.requester_node = -1; - UT_ASSERT(!cluster_resource_x_wire_encode(RESOURCE_X_MSG_ASSERT_X, - &frame, bytes, sizeof(bytes), &encoded_len, &reject)); + UT_ASSERT(!cluster_resource_x_wire_encode(RESOURCE_X_MSG_ASSERT_X, &frame, bytes, sizeof(bytes), + &encoded_len, &reject)); UT_ASSERT_EQ(reject, RESOURCE_X_WIRE_REJECT_IDENTITY); frame = make_control_frame(RESOURCE_X_WIRE_ASSERT_X); - UT_ASSERT(cluster_resource_x_wire_encode(RESOURCE_X_MSG_ASSERT_X, &frame, - bytes, sizeof(bytes), &encoded_len, &reject)); + UT_ASSERT(cluster_resource_x_wire_encode(RESOURCE_X_MSG_ASSERT_X, &frame, bytes, sizeof(bytes), + &encoded_len, &reject)); bytes[20] ^= 0x01; - UT_ASSERT(!cluster_resource_x_wire_decode(RESOURCE_X_MSG_ASSERT_X, bytes, - encoded_len, &decoded, &reject)); + UT_ASSERT(!cluster_resource_x_wire_decode(RESOURCE_X_MSG_ASSERT_X, bytes, encoded_len, &decoded, + &reject)); UT_ASSERT_EQ(reject, RESOURCE_X_WIRE_REJECT_CRC); UT_ASSERT(memcmp(&decoded, &sentinel, sizeof(decoded)) == 0); UT_ASSERT(!cluster_resource_x_wire_decode(RESOURCE_X_MSG_ASSERT_X, bytes, - RESOURCE_X_CONTROL_V1_BYTES - 1, &decoded, &reject)); + RESOURCE_X_CONTROL_V1_BYTES - 1, &decoded, &reject)); UT_ASSERT_EQ(reject, RESOURCE_X_WIRE_REJECT_LEGACY_LENGTH); } @@ -676,8 +617,7 @@ make_typed_frame(ResourceXWireKind kind) frame.common.outcome = RESOURCE_X_OUTCOME_OK; if (kind == RESOURCE_X_WIRE_LOCAL_PROOF_DECLARATION) { frame.body.local_proof.local_holder_authority_generation = 71; - frame.body.local_proof.requester_target_generation - = frame.common.assertion_sequence; + frame.body.local_proof.requester_target_generation = frame.common.assertion_sequence; frame.body.local_proof.page_scn_lsn = 73; frame.body.local_proof.dependency_count = 2; frame.body.local_proof.dependency_vector_crc32c = UINT32_C(0x01020304); @@ -685,53 +625,45 @@ make_typed_frame(ResourceXWireKind kind) frame.body.local_proof.local_image_proof_crc32c = UINT32_C(0x21222324); frame.body.local_proof.requester_connection_generation = 74; frame.body.local_proof.local_proof_generation = 75; - } else if (kind == RESOURCE_X_WIRE_BLOCKED_TO_N - || kind == RESOURCE_X_WIRE_SOURCE_SETTLEMENT_V2 + } else if (kind == RESOURCE_X_WIRE_BLOCKED_TO_N || kind == RESOURCE_X_WIRE_SOURCE_SETTLEMENT_V2 || kind == RESOURCE_X_WIRE_SOURCE_SETTLEMENT_ACK_V2) { frame.blocked_has_remote_proof = true; frame.common.action_node = 7; frame.common.observed_mode - = kind == RESOURCE_X_WIRE_BLOCKED_TO_N - ? PCM_STATE_X : PCM_STATE_N; + = kind == RESOURCE_X_WIRE_BLOCKED_TO_N ? PCM_STATE_X : PCM_STATE_N; frame.common.target_mode = PCM_STATE_N; frame.common.flags - = kind == RESOURCE_X_WIRE_BLOCKED_TO_N - ? RESOURCE_X_COMMON_FLAG_PI_ESTABLISHED : 0; + = kind == RESOURCE_X_WIRE_BLOCKED_TO_N ? RESOURCE_X_COMMON_FLAG_PI_ESTABLISHED : 0; if (kind == RESOURCE_X_WIRE_SOURCE_SETTLEMENT_V2 || kind == RESOURCE_X_WIRE_SOURCE_SETTLEMENT_ACK_V2) { frame.common.ordered_lane = 0; frame.common.source_candidate = 1; frame.common.retain_pi_if_dirty = 1; - frame.common.outcome - = kind == RESOURCE_X_WIRE_SOURCE_SETTLEMENT_V2 - ? RESOURCE_X_OUTCOME_NONE : RESOURCE_X_OUTCOME_OK; + frame.common.outcome = kind == RESOURCE_X_WIRE_SOURCE_SETTLEMENT_V2 + ? RESOURCE_X_OUTCOME_NONE + : RESOURCE_X_OUTCOME_OK; } for (i = 0; i < RESOURCE_X_SOURCE_FENCE_BYTES; i++) frame.body.blocked_to_n.source_fence[i] = (uint8)(i + 1); frame.body.blocked_to_n.source_carrier_generation = 81; - frame.body.blocked_to_n.requester_target_generation - = frame.common.assertion_sequence; + frame.body.blocked_to_n.requester_target_generation = frame.common.assertion_sequence; frame.body.blocked_to_n.page_scn_lsn = 83; frame.body.blocked_to_n.dependency_count = 2; frame.body.blocked_to_n.dependencies[0] = 84; frame.body.blocked_to_n.dependencies[1] = 85; frame.body.blocked_to_n.source_proof_crc32c = UINT32_C(0x31323334); frame.body.blocked_to_n.page_checksum = UINT32_C(0x41424344); - frame.body.blocked_to_n.source_disposition - = RESOURCE_X_DISPOSITION_REMOTE_NONWRITABLE; + frame.body.blocked_to_n.source_disposition = RESOURCE_X_DISPOSITION_REMOTE_NONWRITABLE; frame.body.blocked_to_n.proof_kind = RESOURCE_X_PROOF_REMOTE_CARRIER; frame.body.blocked_to_n.holder_connection_generation = 86; - frame.body.blocked_to_n.acting_formation - = frame.common.resource_formation; + frame.body.blocked_to_n.acting_formation = frame.common.resource_formation; } else if (kind == RESOURCE_X_WIRE_AUTHORITY_GRANT) { frame.common.flags = RESOURCE_X_COMMON_FLAG_REMOTE_IMAGE_REQUIRED; for (i = 0; i < RESOURCE_X_SOURCE_FENCE_BYTES; i++) frame.body.authority_grant.source_fence[i] = (uint8)(0x40 + i); - frame.body.authority_grant.final_authority_generation - = frame.common.authority_generation; + frame.body.authority_grant.final_authority_generation = frame.common.authority_generation; frame.body.authority_grant.source_carrier_generation = 92; - frame.body.authority_grant.requester_target_generation - = frame.common.assertion_sequence; + frame.body.authority_grant.requester_target_generation = frame.common.assertion_sequence; frame.body.authority_grant.page_scn_lsn = 94; frame.body.authority_grant.dependency_count = 2; frame.body.authority_grant.dependencies[0] = 95; @@ -739,8 +671,7 @@ make_typed_frame(ResourceXWireKind kind) frame.body.authority_grant.source_proof_crc32c = UINT32_C(0x51525354); frame.body.authority_grant.page_checksum = UINT32_C(0x61626364); frame.body.authority_grant.proof_kind = RESOURCE_X_PROOF_REMOTE_CARRIER; - frame.body.authority_grant.source_disposition - = RESOURCE_X_DISPOSITION_REMOTE_NONWRITABLE; + frame.body.authority_grant.source_disposition = RESOURCE_X_DISPOSITION_REMOTE_NONWRITABLE; frame.body.authority_grant.requester_connection_generation = 97; } else if (kind == RESOURCE_X_WIRE_IMAGE_ENVELOPE) { frame.common.action_node = 7; @@ -751,8 +682,7 @@ make_typed_frame(ResourceXWireKind kind) for (i = 0; i < RESOURCE_X_SOURCE_FENCE_BYTES; i++) frame.body.image_envelope.source_fence[i] = (uint8)(0x60 + i); frame.body.image_envelope.source_carrier_generation = 102; - frame.body.image_envelope.requester_target_generation - = frame.common.assertion_sequence; + frame.body.image_envelope.requester_target_generation = frame.common.assertion_sequence; frame.body.image_envelope.page_scn_lsn = 104; frame.body.image_envelope.dependency_count = 2; frame.body.image_envelope.dependencies[0] = 105; @@ -760,8 +690,7 @@ make_typed_frame(ResourceXWireKind kind) frame.body.image_envelope.dependency_vector_crc32c = UINT32_C(0x71727374); frame.body.image_envelope.page_checksum = UINT32_C(0x81828384); frame.body.image_envelope.image_length = RESOURCE_X_PAGE_BYTES; - frame.body.image_envelope.source_disposition - = RESOURCE_X_DISPOSITION_REMOTE_NONWRITABLE; + frame.body.image_envelope.source_disposition = RESOURCE_X_DISPOSITION_REMOTE_NONWRITABLE; frame.body.image_envelope.proof_kind = RESOURCE_X_PROOF_REMOTE_CARRIER; for (i = 0; i < RESOURCE_X_PAGE_BYTES; i++) frame.body.image_envelope.page_bytes[i] = (uint8)(i * 37); @@ -771,112 +700,93 @@ make_typed_frame(ResourceXWireKind kind) frame.body.install_settlement.final_authority_generation = frame.common.authority_generation; frame.body.install_settlement.requester_connection_generation = 113; - frame.body.install_settlement.requester_target_generation - = frame.common.assertion_sequence; + frame.body.install_settlement.requester_target_generation = frame.common.assertion_sequence; frame.body.install_settlement.page_scn_lsn = 115; frame.body.install_settlement.page_checksum = UINT32_C(0x91929394); frame.body.install_settlement.source_proof_crc32c = UINT32_C(0xa1a2a3a4); frame.body.install_settlement.installed_mode = PCM_STATE_X; - frame.body.install_settlement.requester_role - = RESOURCE_X_REQUESTER_ROLE_ACQUIRER; + frame.body.install_settlement.requester_role = RESOURCE_X_REQUESTER_ROLE_ACQUIRER; frame.body.install_settlement.terminal_outcome = RESOURCE_X_OUTCOME_OK; - frame.body.install_settlement.terminal_state - = RESOURCE_X_SETTLEMENT_TERMINAL_INSTALLED; + frame.body.install_settlement.terminal_state = RESOURCE_X_SETTLEMENT_TERMINAL_INSTALLED; } return frame; } static void -assert_source_settlement_encode_rejected(uint8 msg_type, - ResourceXDecodedFrame *frame) +assert_source_settlement_encode_rejected(uint8 msg_type, ResourceXDecodedFrame *frame) { ResourceXWireReject reject = RESOURCE_X_WIRE_REJECT_NONE; uint8 bytes[RESOURCE_X_PROOF_V1_BYTES]; uint16 len = 0; - UT_ASSERT(!cluster_resource_x_wire_encode( - msg_type, frame, bytes, sizeof(bytes), &len, &reject)); + UT_ASSERT( + !cluster_resource_x_wire_encode(msg_type, frame, bytes, sizeof(bytes), &len, &reject)); UT_ASSERT(reject != RESOURCE_X_WIRE_REJECT_NONE); } UT_TEST(test_source_settlement_request_and_ack_are_direction_exact) { - ResourceXDecodedFrame request - = make_typed_frame(RESOURCE_X_WIRE_SOURCE_SETTLEMENT_V2); - ResourceXDecodedFrame ack - = make_typed_frame(RESOURCE_X_WIRE_SOURCE_SETTLEMENT_ACK_V2); + ResourceXDecodedFrame request = make_typed_frame(RESOURCE_X_WIRE_SOURCE_SETTLEMENT_V2); + ResourceXDecodedFrame ack = make_typed_frame(RESOURCE_X_WIRE_SOURCE_SETTLEMENT_ACK_V2); ResourceXDecodedFrame decoded; ResourceXWireReject reject = RESOURCE_X_WIRE_REJECT_NONE; uint8 bytes[RESOURCE_X_PROOF_V1_BYTES]; uint16 len = 0; - UT_ASSERT(cluster_resource_x_wire_encode( - RESOURCE_X_MSG_BLOCK_TO_N, &request, bytes, sizeof(bytes), - &len, &reject)); + UT_ASSERT(cluster_resource_x_wire_encode(RESOURCE_X_MSG_BLOCK_TO_N, &request, bytes, + sizeof(bytes), &len, &reject)); UT_ASSERT_EQ(len, RESOURCE_X_PROOF_V1_BYTES); - UT_ASSERT(cluster_resource_x_wire_decode( - RESOURCE_X_MSG_BLOCK_TO_N, bytes, len, &decoded, &reject)); + UT_ASSERT( + cluster_resource_x_wire_decode(RESOURCE_X_MSG_BLOCK_TO_N, bytes, len, &decoded, &reject)); UT_ASSERT_EQ(decoded.kind, RESOURCE_X_WIRE_SOURCE_SETTLEMENT_V2); UT_ASSERT_EQ(decoded.common.action_node, 7); - UT_ASSERT_EQ(decoded.common.authority_generation, - request.common.authority_generation); + UT_ASSERT_EQ(decoded.common.authority_generation, request.common.authority_generation); UT_ASSERT_EQ(decoded.body.blocked_to_n.source_carrier_generation, - request.body.blocked_to_n.source_carrier_generation); - UT_ASSERT(!cluster_resource_x_wire_decode( - RESOURCE_X_MSG_BLOCKED_TO_N, bytes, len, &decoded, &reject)); + request.body.blocked_to_n.source_carrier_generation); + UT_ASSERT(!cluster_resource_x_wire_decode(RESOURCE_X_MSG_BLOCKED_TO_N, bytes, len, &decoded, + &reject)); - UT_ASSERT(cluster_resource_x_wire_encode( - RESOURCE_X_MSG_BLOCKED_TO_N, &ack, bytes, sizeof(bytes), - &len, &reject)); + UT_ASSERT(cluster_resource_x_wire_encode(RESOURCE_X_MSG_BLOCKED_TO_N, &ack, bytes, + sizeof(bytes), &len, &reject)); UT_ASSERT_EQ(len, RESOURCE_X_PROOF_V1_BYTES); - UT_ASSERT(cluster_resource_x_wire_decode( - RESOURCE_X_MSG_BLOCKED_TO_N, bytes, len, &decoded, &reject)); + UT_ASSERT( + cluster_resource_x_wire_decode(RESOURCE_X_MSG_BLOCKED_TO_N, bytes, len, &decoded, &reject)); UT_ASSERT_EQ(decoded.kind, RESOURCE_X_WIRE_SOURCE_SETTLEMENT_ACK_V2); UT_ASSERT_EQ(decoded.common.outcome, RESOURCE_X_OUTCOME_OK); - UT_ASSERT(!cluster_resource_x_wire_decode( - RESOURCE_X_MSG_BLOCK_TO_N, bytes, len, &decoded, &reject)); + UT_ASSERT( + !cluster_resource_x_wire_decode(RESOURCE_X_MSG_BLOCK_TO_N, bytes, len, &decoded, &reject)); } UT_TEST(test_source_settlement_truth_tables_fail_closed) { - ResourceXDecodedFrame frame - = make_typed_frame(RESOURCE_X_WIRE_SOURCE_SETTLEMENT_V2); + ResourceXDecodedFrame frame = make_typed_frame(RESOURCE_X_WIRE_SOURCE_SETTLEMENT_V2); frame.common.ordered_lane = 1; - assert_source_settlement_encode_rejected( - RESOURCE_X_MSG_BLOCK_TO_N, &frame); + assert_source_settlement_encode_rejected(RESOURCE_X_MSG_BLOCK_TO_N, &frame); frame = make_typed_frame(RESOURCE_X_WIRE_SOURCE_SETTLEMENT_V2); frame.common.authority_generation = 0; - assert_source_settlement_encode_rejected( - RESOURCE_X_MSG_BLOCK_TO_N, &frame); + assert_source_settlement_encode_rejected(RESOURCE_X_MSG_BLOCK_TO_N, &frame); frame = make_typed_frame(RESOURCE_X_WIRE_SOURCE_SETTLEMENT_V2); frame.common.observed_mode = PCM_STATE_X; - assert_source_settlement_encode_rejected( - RESOURCE_X_MSG_BLOCK_TO_N, &frame); + assert_source_settlement_encode_rejected(RESOURCE_X_MSG_BLOCK_TO_N, &frame); frame = make_typed_frame(RESOURCE_X_WIRE_SOURCE_SETTLEMENT_V2); frame.common.target_mode = PCM_STATE_X; - assert_source_settlement_encode_rejected( - RESOURCE_X_MSG_BLOCK_TO_N, &frame); + assert_source_settlement_encode_rejected(RESOURCE_X_MSG_BLOCK_TO_N, &frame); frame = make_typed_frame(RESOURCE_X_WIRE_SOURCE_SETTLEMENT_V2); frame.common.source_candidate = 0; - assert_source_settlement_encode_rejected( - RESOURCE_X_MSG_BLOCK_TO_N, &frame); + assert_source_settlement_encode_rejected(RESOURCE_X_MSG_BLOCK_TO_N, &frame); frame = make_typed_frame(RESOURCE_X_WIRE_SOURCE_SETTLEMENT_V2); frame.common.retain_pi_if_dirty = 0; - assert_source_settlement_encode_rejected( - RESOURCE_X_MSG_BLOCK_TO_N, &frame); + assert_source_settlement_encode_rejected(RESOURCE_X_MSG_BLOCK_TO_N, &frame); frame = make_typed_frame(RESOURCE_X_WIRE_SOURCE_SETTLEMENT_V2); frame.common.outcome = RESOURCE_X_OUTCOME_OK; - assert_source_settlement_encode_rejected( - RESOURCE_X_MSG_BLOCK_TO_N, &frame); + assert_source_settlement_encode_rejected(RESOURCE_X_MSG_BLOCK_TO_N, &frame); frame = make_typed_frame(RESOURCE_X_WIRE_SOURCE_SETTLEMENT_ACK_V2); frame.common.outcome = RESOURCE_X_OUTCOME_NONE; - assert_source_settlement_encode_rejected( - RESOURCE_X_MSG_BLOCKED_TO_N, &frame); + assert_source_settlement_encode_rejected(RESOURCE_X_MSG_BLOCKED_TO_N, &frame); frame = make_typed_frame(RESOURCE_X_WIRE_SOURCE_SETTLEMENT_ACK_V2); frame.body.blocked_to_n.source_carrier_generation = 0; - assert_source_settlement_encode_rejected( - RESOURCE_X_MSG_BLOCKED_TO_N, &frame); + assert_source_settlement_encode_rejected(RESOURCE_X_MSG_BLOCKED_TO_N, &frame); } UT_TEST(test_short_typed_frames_round_trip) @@ -884,11 +794,8 @@ UT_TEST(test_short_typed_frames_round_trip) static const struct { uint8 msg_type; ResourceXWireKind kind; - } cases[] = { - {RESOURCE_X_MSG_ASSERT_X, RESOURCE_X_WIRE_LOCAL_PROOF_DECLARATION}, - {RESOURCE_X_MSG_SETTLEMENT_OR_RELEASE, - RESOURCE_X_WIRE_INSTALL_SETTLEMENT} - }; + } cases[] = { { RESOURCE_X_MSG_ASSERT_X, RESOURCE_X_WIRE_LOCAL_PROOF_DECLARATION }, + { RESOURCE_X_MSG_SETTLEMENT_OR_RELEASE, RESOURCE_X_WIRE_INSTALL_SETTLEMENT } }; uint8 bytes[RESOURCE_X_SHORT_V1_BYTES]; Size i; @@ -898,11 +805,10 @@ UT_TEST(test_short_typed_frames_round_trip) ResourceXWireReject reject; uint16 len; - UT_ASSERT(cluster_resource_x_wire_encode(cases[i].msg_type, &frame, - bytes, sizeof(bytes), &len, &reject)); + UT_ASSERT(cluster_resource_x_wire_encode(cases[i].msg_type, &frame, bytes, sizeof(bytes), + &len, &reject)); UT_ASSERT_EQ(len, RESOURCE_X_SHORT_V1_BYTES); - UT_ASSERT(cluster_resource_x_wire_decode(cases[i].msg_type, bytes, - len, &decoded, &reject)); + UT_ASSERT(cluster_resource_x_wire_decode(cases[i].msg_type, bytes, len, &decoded, &reject)); UT_ASSERT_EQ(decoded.kind, cases[i].kind); } } @@ -912,10 +818,8 @@ UT_TEST(test_proof_typed_frames_round_trip) static const struct { uint8 msg_type; ResourceXWireKind kind; - } cases[] = { - {RESOURCE_X_MSG_BLOCKED_TO_N, RESOURCE_X_WIRE_BLOCKED_TO_N}, - {RESOURCE_X_MSG_IMAGE_OR_GRANT, RESOURCE_X_WIRE_AUTHORITY_GRANT} - }; + } cases[] = { { RESOURCE_X_MSG_BLOCKED_TO_N, RESOURCE_X_WIRE_BLOCKED_TO_N }, + { RESOURCE_X_MSG_IMAGE_OR_GRANT, RESOURCE_X_WIRE_AUTHORITY_GRANT } }; uint8 bytes[RESOURCE_X_PROOF_V1_BYTES]; Size i; @@ -925,11 +829,10 @@ UT_TEST(test_proof_typed_frames_round_trip) ResourceXWireReject reject; uint16 len; - UT_ASSERT(cluster_resource_x_wire_encode(cases[i].msg_type, &frame, - bytes, sizeof(bytes), &len, &reject)); + UT_ASSERT(cluster_resource_x_wire_encode(cases[i].msg_type, &frame, bytes, sizeof(bytes), + &len, &reject)); UT_ASSERT_EQ(len, RESOURCE_X_PROOF_V1_BYTES); - UT_ASSERT(cluster_resource_x_wire_decode(cases[i].msg_type, bytes, - len, &decoded, &reject)); + UT_ASSERT(cluster_resource_x_wire_decode(cases[i].msg_type, bytes, len, &decoded, &reject)); UT_ASSERT_EQ(decoded.kind, cases[i].kind); if (cases[i].kind == RESOURCE_X_WIRE_BLOCKED_TO_N) { UT_ASSERT(decoded.blocked_has_remote_proof); @@ -947,15 +850,15 @@ UT_TEST(test_image_envelope_round_trip_preserves_exact_page) uint8 bytes[RESOURCE_X_IMAGE_V1_BYTES]; uint16 len; - UT_ASSERT(cluster_resource_x_wire_encode(RESOURCE_X_MSG_IMAGE_OR_GRANT, - &frame, bytes, sizeof(bytes), &len, &reject)); + UT_ASSERT(cluster_resource_x_wire_encode(RESOURCE_X_MSG_IMAGE_OR_GRANT, &frame, bytes, + sizeof(bytes), &len, &reject)); UT_ASSERT_EQ(len, RESOURCE_X_IMAGE_V1_BYTES); - UT_ASSERT(cluster_resource_x_wire_decode(RESOURCE_X_MSG_IMAGE_OR_GRANT, - bytes, len, &decoded, &reject)); - UT_ASSERT_EQ(decoded.body.image_envelope.image_length, - RESOURCE_X_PAGE_BYTES); - UT_ASSERT(memcmp(decoded.body.image_envelope.page_bytes, - frame.body.image_envelope.page_bytes, RESOURCE_X_PAGE_BYTES) == 0); + UT_ASSERT(cluster_resource_x_wire_decode(RESOURCE_X_MSG_IMAGE_OR_GRANT, bytes, len, &decoded, + &reject)); + UT_ASSERT_EQ(decoded.body.image_envelope.image_length, RESOURCE_X_PAGE_BYTES); + UT_ASSERT(memcmp(decoded.body.image_envelope.page_bytes, frame.body.image_envelope.page_bytes, + RESOURCE_X_PAGE_BYTES) + == 0); } UT_TEST(test_delegated_block_and_image_keep_exact_wire_layout) @@ -1051,32 +954,32 @@ UT_TEST(test_typed_body_validation_is_fail_closed) frame = make_typed_frame(RESOURCE_X_WIRE_LOCAL_PROOF_DECLARATION); frame.body.local_proof.dependency_count = RESOURCE_X_DEPENDENCY_MAX + 1; - UT_ASSERT(!cluster_resource_x_wire_encode(RESOURCE_X_MSG_ASSERT_X, &frame, - bytes, sizeof(bytes), &len, &reject)); + UT_ASSERT(!cluster_resource_x_wire_encode(RESOURCE_X_MSG_ASSERT_X, &frame, bytes, sizeof(bytes), + &len, &reject)); UT_ASSERT_EQ(reject, RESOURCE_X_WIRE_REJECT_BODY); frame = make_typed_frame(RESOURCE_X_WIRE_BLOCKED_TO_N); frame.body.blocked_to_n.dependencies[2] = 1; - UT_ASSERT(!cluster_resource_x_wire_encode(RESOURCE_X_MSG_BLOCKED_TO_N, - &frame, bytes, sizeof(bytes), &len, &reject)); + UT_ASSERT(!cluster_resource_x_wire_encode(RESOURCE_X_MSG_BLOCKED_TO_N, &frame, bytes, + sizeof(bytes), &len, &reject)); UT_ASSERT_EQ(reject, RESOURCE_X_WIRE_REJECT_BODY); frame = make_typed_frame(RESOURCE_X_WIRE_AUTHORITY_GRANT); frame.body.authority_grant.proof_kind = 0; - UT_ASSERT(!cluster_resource_x_wire_encode(RESOURCE_X_MSG_IMAGE_OR_GRANT, - &frame, bytes, sizeof(bytes), &len, &reject)); + UT_ASSERT(!cluster_resource_x_wire_encode(RESOURCE_X_MSG_IMAGE_OR_GRANT, &frame, bytes, + sizeof(bytes), &len, &reject)); UT_ASSERT_EQ(reject, RESOURCE_X_WIRE_REJECT_BODY); frame = make_typed_frame(RESOURCE_X_WIRE_IMAGE_ENVELOPE); frame.body.image_envelope.image_length--; - UT_ASSERT(!cluster_resource_x_wire_encode(RESOURCE_X_MSG_IMAGE_OR_GRANT, - &frame, bytes, sizeof(bytes), &len, &reject)); + UT_ASSERT(!cluster_resource_x_wire_encode(RESOURCE_X_MSG_IMAGE_OR_GRANT, &frame, bytes, + sizeof(bytes), &len, &reject)); UT_ASSERT_EQ(reject, RESOURCE_X_WIRE_REJECT_BODY); frame = make_typed_frame(RESOURCE_X_WIRE_AUTHORITY_GRANT); frame.body.authority_grant.requester_target_generation++; - UT_ASSERT(!cluster_resource_x_wire_encode(RESOURCE_X_MSG_IMAGE_OR_GRANT, - &frame, bytes, sizeof(bytes), &len, &reject)); + UT_ASSERT(!cluster_resource_x_wire_encode(RESOURCE_X_MSG_IMAGE_OR_GRANT, &frame, bytes, + sizeof(bytes), &len, &reject)); UT_ASSERT_EQ(reject, RESOURCE_X_WIRE_REJECT_BODY); } @@ -1092,7 +995,7 @@ test_put_u32_be(uint8 *bytes, uint32 value) static void test_reseal(uint8 *bytes, uint16 len) { - static const uint8 zero_crc[4] = {0, 0, 0, 0}; + static const uint8 zero_crc[4] = { 0, 0, 0, 0 }; pg_crc32c crc; INIT_CRC32C(crc); @@ -1105,96 +1008,92 @@ test_reseal(uint8 *bytes, uint16 len) UT_TEST(test_ingress_semantic_mutations_with_valid_crc_are_rejected) { - ResourceXDecodedFrame frame - = make_typed_frame(RESOURCE_X_WIRE_AUTHORITY_GRANT); + ResourceXDecodedFrame frame = make_typed_frame(RESOURCE_X_WIRE_AUTHORITY_GRANT); ResourceXDecodedFrame decoded; ResourceXWireReject reject; uint8 original[RESOURCE_X_PROOF_V1_BYTES]; uint8 bytes[RESOURCE_X_PROOF_V1_BYTES]; uint16 len; - UT_ASSERT(cluster_resource_x_wire_encode(RESOURCE_X_MSG_IMAGE_OR_GRANT, - &frame, original, sizeof(original), &len, &reject)); + UT_ASSERT(cluster_resource_x_wire_encode(RESOURCE_X_MSG_IMAGE_OR_GRANT, &frame, original, + sizeof(original), &len, &reject)); memcpy(bytes, original, len); bytes[0]++; - UT_ASSERT(!cluster_resource_x_wire_decode(RESOURCE_X_MSG_IMAGE_OR_GRANT, - bytes, len, &decoded, &reject)); + UT_ASSERT(!cluster_resource_x_wire_decode(RESOURCE_X_MSG_IMAGE_OR_GRANT, bytes, len, &decoded, + &reject)); UT_ASSERT_EQ(reject, RESOURCE_X_WIRE_REJECT_VERSION); memcpy(bytes, original, len); bytes[3]--; - UT_ASSERT(!cluster_resource_x_wire_decode(RESOURCE_X_MSG_IMAGE_OR_GRANT, - bytes, len, &decoded, &reject)); + UT_ASSERT(!cluster_resource_x_wire_decode(RESOURCE_X_MSG_IMAGE_OR_GRANT, bytes, len, &decoded, + &reject)); UT_ASSERT_EQ(reject, RESOURCE_X_WIRE_REJECT_DECLARED_LENGTH); memcpy(bytes, original, len); test_put_u32_be(bytes + 68, UINT32_MAX); test_reseal(bytes, len); - UT_ASSERT(!cluster_resource_x_wire_decode(RESOURCE_X_MSG_IMAGE_OR_GRANT, - bytes, len, &decoded, &reject)); + UT_ASSERT(!cluster_resource_x_wire_decode(RESOURCE_X_MSG_IMAGE_OR_GRANT, bytes, len, &decoded, + &reject)); UT_ASSERT_EQ(reject, RESOURCE_X_WIRE_REJECT_ROLE); memcpy(bytes, original, len); test_put_u32_be(bytes + 20, MAX_FORKNUM + 1); test_reseal(bytes, len); - UT_ASSERT(!cluster_resource_x_wire_decode(RESOURCE_X_MSG_IMAGE_OR_GRANT, - bytes, len, &decoded, &reject)); + UT_ASSERT(!cluster_resource_x_wire_decode(RESOURCE_X_MSG_IMAGE_OR_GRANT, bytes, len, &decoded, + &reject)); UT_ASSERT_EQ(reject, RESOURCE_X_WIRE_REJECT_IDENTITY); memcpy(bytes, original, len); bytes[72] = PCM_STATE_X + 1; test_reseal(bytes, len); - UT_ASSERT(!cluster_resource_x_wire_decode(RESOURCE_X_MSG_IMAGE_OR_GRANT, - bytes, len, &decoded, &reject)); + UT_ASSERT(!cluster_resource_x_wire_decode(RESOURCE_X_MSG_IMAGE_OR_GRANT, bytes, len, &decoded, + &reject)); UT_ASSERT_EQ(reject, RESOURCE_X_WIRE_REJECT_ENUM); memcpy(bytes, original, len); bytes[81] |= 0x80; test_reseal(bytes, len); - UT_ASSERT(!cluster_resource_x_wire_decode(RESOURCE_X_MSG_IMAGE_OR_GRANT, - bytes, len, &decoded, &reject)); + UT_ASSERT(!cluster_resource_x_wire_decode(RESOURCE_X_MSG_IMAGE_OR_GRANT, bytes, len, &decoded, + &reject)); UT_ASSERT_EQ(reject, RESOURCE_X_WIRE_REJECT_FLAGS); memcpy(bytes, original, len); bytes[82] = 1; test_reseal(bytes, len); - UT_ASSERT(!cluster_resource_x_wire_decode(RESOURCE_X_MSG_IMAGE_OR_GRANT, - bytes, len, &decoded, &reject)); + UT_ASSERT(!cluster_resource_x_wire_decode(RESOURCE_X_MSG_IMAGE_OR_GRANT, bytes, len, &decoded, + &reject)); UT_ASSERT_EQ(reject, RESOURCE_X_WIRE_REJECT_RESERVED); memcpy(bytes, original, len); bytes[300] = 0; test_reseal(bytes, len); - UT_ASSERT(!cluster_resource_x_wire_decode(RESOURCE_X_MSG_IMAGE_OR_GRANT, - bytes, len, &decoded, &reject)); + UT_ASSERT(!cluster_resource_x_wire_decode(RESOURCE_X_MSG_IMAGE_OR_GRANT, bytes, len, &decoded, + &reject)); UT_ASSERT_EQ(reject, RESOURCE_X_WIRE_REJECT_BODY); memcpy(bytes, original, len); bytes[180] = 1; test_reseal(bytes, len); - UT_ASSERT(!cluster_resource_x_wire_decode(RESOURCE_X_MSG_IMAGE_OR_GRANT, - bytes, len, &decoded, &reject)); + UT_ASSERT(!cluster_resource_x_wire_decode(RESOURCE_X_MSG_IMAGE_OR_GRANT, bytes, len, &decoded, + &reject)); UT_ASSERT_EQ(reject, RESOURCE_X_WIRE_REJECT_BODY); memcpy(bytes, original, len); bytes[302] = 1; test_reseal(bytes, len); - UT_ASSERT(!cluster_resource_x_wire_decode(RESOURCE_X_MSG_IMAGE_OR_GRANT, - bytes, len, &decoded, &reject)); + UT_ASSERT(!cluster_resource_x_wire_decode(RESOURCE_X_MSG_IMAGE_OR_GRANT, bytes, len, &decoded, + &reject)); UT_ASSERT_EQ(reject, RESOURCE_X_WIRE_REJECT_BODY); } UT_TEST(test_resource_x_capability_has_complete_collision_census) { - UT_ASSERT_EQ(PGRAC_IC_HELLO_CAP_GCS_RESOURCE_X_CONVERT_V1, - UINT32_C(0x00020000)); - UT_ASSERT_EQ(PGRAC_IC_HELLO_CAP_MULTIXACT_CTRC_V1, - UINT32_C(0x00400000)); + UT_ASSERT_EQ(PGRAC_IC_HELLO_CAP_GCS_RESOURCE_X_CONVERT_V1, UINT32_C(0x00020000)); + UT_ASSERT_EQ(PGRAC_IC_HELLO_CAP_MULTIXACT_CTRC_V1, UINT32_C(0x00400000)); UT_ASSERT_EQ(PGRAC_IC_HELLO_CAP_DEFINED_COUNT, 21); UT_ASSERT_EQ(PGRAC_IC_HELLO_CAP_DEFINED_MASK, UINT32_C(0x007BBFFF)); - UT_ASSERT_EQ(PGRAC_IC_HELLO_CAP_DEFINED_SUM, - PGRAC_IC_HELLO_CAP_DEFINED_MASK); + UT_ASSERT_EQ(PGRAC_IC_HELLO_CAP_DEFINED_SUM, PGRAC_IC_HELLO_CAP_DEFINED_MASK); UT_ASSERT_EQ(PGRAC_IC_HELLO_CAP_DEFINED_MASK & UINT32_C(0x00044000), 0); } diff --git a/src/test/cluster_unit/test_cluster_resource_x_retry.c b/src/test/cluster_unit/test_cluster_resource_x_retry.c index 2da887bcf26..3618624f481 100644 --- a/src/test/cluster_unit/test_cluster_resource_x_retry.c +++ b/src/test/cluster_unit/test_cluster_resource_x_retry.c @@ -14,11 +14,9 @@ UT_DEFINE_GLOBALS(); void -ExceptionalCondition(const char *condition_name, const char *file_name, - int line_number) +ExceptionalCondition(const char *condition_name, const char *file_name, int line_number) { - printf("# Assert failed: %s at %s:%d\n", condition_name, file_name, - line_number); + printf("# Assert failed: %s at %s:%d\n", condition_name, file_name, line_number); abort(); } @@ -76,8 +74,7 @@ UT_TEST(test_retry_state_initialization_publishes_exact_attempt) ResourceXRetryStateV1 state; memset(&state, 0xa5, sizeof(state)); - UT_ASSERT(resource_x_retry_state_init(&attempt, 1000, 60000, 4, 10, 7, - &state)); + UT_ASSERT(resource_x_retry_state_init(&attempt, 1000, 60000, 4, 10, 7, &state)); UT_ASSERT(memcmp(&state.attempt, &attempt, sizeof(attempt)) == 0); UT_ASSERT_EQ(state.first_submit_mono_us, 1000); UT_ASSERT_EQ(state.next_retry_due_mono_us, 11000); @@ -98,23 +95,15 @@ UT_TEST(test_retry_state_initialization_rejects_unpublishable_state) memset(&state, 0x5a, sizeof(state)); before = state; - UT_ASSERT(!resource_x_retry_state_init(NULL, 1000, 6000, 4, 10, 7, - &state)); + UT_ASSERT(!resource_x_retry_state_init(NULL, 1000, 6000, 4, 10, 7, &state)); UT_ASSERT(memcmp(&state, &before, sizeof(state)) == 0); - UT_ASSERT(!resource_x_retry_state_init(&attempt, 0, 6000, 4, 10, 7, - &state)); - UT_ASSERT(!resource_x_retry_state_init(&attempt, 1000, 999, 4, 10, 7, - &state)); - UT_ASSERT(!resource_x_retry_state_init(&attempt, 1000, 6000, 9, 10, 7, - &state)); - UT_ASSERT(!resource_x_retry_state_init(&attempt, 1000, 6000, 4, 0, 7, - &state)); - UT_ASSERT(!resource_x_retry_state_init(&attempt, 1000, 6000, 4, 5001, 7, - &state)); - UT_ASSERT(!resource_x_retry_state_init(&attempt, 1000, 6000, 4, 10, 0, - &state)); - UT_ASSERT(!resource_x_retry_state_init(&attempt, 1000, 6000, 4, 10, 7, - NULL)); + UT_ASSERT(!resource_x_retry_state_init(&attempt, 0, 6000, 4, 10, 7, &state)); + UT_ASSERT(!resource_x_retry_state_init(&attempt, 1000, 999, 4, 10, 7, &state)); + UT_ASSERT(!resource_x_retry_state_init(&attempt, 1000, 6000, 9, 10, 7, &state)); + UT_ASSERT(!resource_x_retry_state_init(&attempt, 1000, 6000, 4, 0, 7, &state)); + UT_ASSERT(!resource_x_retry_state_init(&attempt, 1000, 6000, 4, 5001, 7, &state)); + UT_ASSERT(!resource_x_retry_state_init(&attempt, 1000, 6000, 4, 10, 0, &state)); + UT_ASSERT(!resource_x_retry_state_init(&attempt, 1000, 6000, 4, 10, 7, NULL)); UT_ASSERT(memcmp(&state, &before, sizeof(state)) == 0); } @@ -123,8 +112,7 @@ UT_TEST(test_retry_state_clear_removes_all_attempt_state) ResourceXAttemptWitness attempt = make_attempt(17); ResourceXRetryStateV1 state; - UT_ASSERT(resource_x_retry_state_init(&attempt, 1000, 60000, 4, 10, 7, - &state)); + UT_ASSERT(resource_x_retry_state_init(&attempt, 1000, 60000, 4, 10, 7, &state)); resource_x_retry_state_clear(&state); UT_ASSERT(resource_x_retry_state_is_clear(&state)); state.flags = 1; @@ -141,13 +129,11 @@ UT_TEST(test_classifier_stages_same_attempt_with_fresh_transport) ResourceXRetryStateV1 before; ResourceXRetryAction action; - UT_ASSERT(resource_x_retry_state_init(&attempt, 1000, 60000, 4, 10, 7, - &state)); + UT_ASSERT(resource_x_retry_state_init(&attempt, 1000, 60000, 4, 10, 7, &state)); before = state; MemSet(&action, 0xa5, sizeof(action)); - UT_ASSERT_EQ(resource_x_retry_classify_exact(&state, &attempt, &transport, - 11000, &action), - RESOURCE_X_RETRY_STAGE_EXACT); + UT_ASSERT_EQ(resource_x_retry_classify_exact(&state, &attempt, &transport, 11000, &action), + RESOURCE_X_RETRY_STAGE_EXACT); UT_ASSERT(memcmp(&action.attempt, &attempt, sizeof(attempt)) == 0); UT_ASSERT(memcmp(&action.transport, &transport, sizeof(transport)) == 0); UT_ASSERT_EQ(action.expected_state_generation, 7); @@ -155,9 +141,8 @@ UT_TEST(test_classifier_stages_same_attempt_with_fresh_transport) UT_ASSERT(memcmp(&state, &before, sizeof(state)) == 0); transport.connection_generation++; - UT_ASSERT_EQ(resource_x_retry_classify_exact(&state, &attempt, &transport, - 11000, &action), - RESOURCE_X_RETRY_STAGE_EXACT); + UT_ASSERT_EQ(resource_x_retry_classify_exact(&state, &attempt, &transport, 11000, &action), + RESOURCE_X_RETRY_STAGE_EXACT); UT_ASSERT(memcmp(&action.attempt, &attempt, sizeof(attempt)) == 0); UT_ASSERT_EQ(action.transport.connection_generation, 10); } @@ -171,13 +156,11 @@ UT_TEST(test_classifier_never_retries_successor_attempt) ResourceXRetryAction action; ResourceXRetryAction zero; - UT_ASSERT(resource_x_retry_state_init(&attempt, 1000, 6000, 4, 1, 7, - &state)); + UT_ASSERT(resource_x_retry_state_init(&attempt, 1000, 6000, 4, 1, 7, &state)); MemSet(&action, 0xa5, sizeof(action)); MemSet(&zero, 0, sizeof(zero)); - UT_ASSERT_EQ(resource_x_retry_classify_exact(&state, &successor, &transport, - 2000, &action), - RESOURCE_X_RETRY_RECOVERY_BLOCKED); + UT_ASSERT_EQ(resource_x_retry_classify_exact(&state, &successor, &transport, 2000, &action), + RESOURCE_X_RETRY_RECOVERY_BLOCKED); UT_ASSERT(memcmp(&action, &zero, sizeof(action)) == 0); } @@ -189,18 +172,15 @@ UT_TEST(test_classifier_rejects_unbound_transport_without_staging) ResourceXRetryAction action; ResourceXRetryAction zero; - UT_ASSERT(resource_x_retry_state_init(&attempt, 1000, 6000, 4, 1, 7, - &state)); + UT_ASSERT(resource_x_retry_state_init(&attempt, 1000, 6000, 4, 1, 7, &state)); MemSet(&zero, 0, sizeof(zero)); transport.connection_generation = 0; - UT_ASSERT_EQ(resource_x_retry_classify_exact(&state, &attempt, &transport, - 2000, &action), + UT_ASSERT_EQ(resource_x_retry_classify_exact(&state, &attempt, &transport, 2000, &action), RESOURCE_X_RETRY_WAIT_SCHEDULER); UT_ASSERT(memcmp(&action, &zero, sizeof(action)) == 0); transport = make_transport(9); transport.flags = 1; - UT_ASSERT_EQ(resource_x_retry_classify_exact(&state, &attempt, &transport, - 1010, &action), + UT_ASSERT_EQ(resource_x_retry_classify_exact(&state, &attempt, &transport, 1010, &action), RESOURCE_X_RETRY_RECOVERY_BLOCKED); } @@ -211,19 +191,17 @@ UT_TEST(test_retry_policy_snapshot_is_lossless_across_guc_domain) uint32 initial_backoff_ms; uint32 max_retries; - UT_ASSERT(resource_x_retry_state_init(&attempt, 1000, UINT64_C(6000000000), - 8, 5000, 7, &state)); + UT_ASSERT( + resource_x_retry_state_init(&attempt, 1000, UINT64_C(6000000000), 8, 5000, 7, &state)); UT_ASSERT_EQ(state.flags, 44999); - UT_ASSERT(resource_x_retry_policy_exact(&state, &max_retries, - &initial_backoff_ms)); + UT_ASSERT(resource_x_retry_policy_exact(&state, &max_retries, &initial_backoff_ms)); UT_ASSERT_EQ(max_retries, 8); UT_ASSERT_EQ(initial_backoff_ms, 5000); UT_ASSERT_EQ(state.next_retry_due_mono_us, UINT64_C(5001000)); UT_ASSERT(resource_x_retry_state_init(&attempt, 1000, 6000, 0, 1, 7, &state)); UT_ASSERT_EQ(state.flags, 0); - UT_ASSERT(resource_x_retry_policy_exact(&state, &max_retries, - &initial_backoff_ms)); + UT_ASSERT(resource_x_retry_policy_exact(&state, &max_retries, &initial_backoff_ms)); UT_ASSERT_EQ(max_retries, 0); UT_ASSERT_EQ(initial_backoff_ms, 1); UT_ASSERT_EQ(state.next_retry_due_mono_us, 2000); @@ -238,20 +216,16 @@ UT_TEST(test_classifier_enforces_sampled_retry_budget) UT_ASSERT(resource_x_retry_state_init(&attempt, 1000, 6000, 4, 1, 7, &state)); state.retry_count = 3; - UT_ASSERT_EQ(resource_x_retry_classify_exact(&state, &attempt, &transport, - 2000, &action), + UT_ASSERT_EQ(resource_x_retry_classify_exact(&state, &attempt, &transport, 2000, &action), RESOURCE_X_RETRY_STAGE_EXACT); state.retry_count = 4; - UT_ASSERT_EQ(resource_x_retry_classify_exact(&state, &attempt, &transport, - 2000, &action), + UT_ASSERT_EQ(resource_x_retry_classify_exact(&state, &attempt, &transport, 2000, &action), RESOURCE_X_RETRY_TERMINAL_EXHAUSTED); state.last_phase = RESOURCE_X_RETRY_POST_NO_RETURN; - UT_ASSERT_EQ(resource_x_retry_classify_exact(&state, &attempt, &transport, - 2000, &action), + UT_ASSERT_EQ(resource_x_retry_classify_exact(&state, &attempt, &transport, 2000, &action), RESOURCE_X_RETRY_ROLL_FORWARD); state.flags = UINT16_MAX; - UT_ASSERT_EQ(resource_x_retry_classify_exact(&state, &attempt, &transport, - 2000, &action), + UT_ASSERT_EQ(resource_x_retry_classify_exact(&state, &attempt, &transport, 2000, &action), RESOURCE_X_RETRY_RECOVERY_BLOCKED); } @@ -261,8 +235,7 @@ UT_TEST(test_exponential_backoff_saturates_and_clamps_to_deadline) ResourceXRetryStateV1 state; uint64 next_due; - UT_ASSERT(resource_x_retry_state_init(&attempt, 1000, UINT64_C(1000000000), - 8, 10, 7, &state)); + UT_ASSERT(resource_x_retry_state_init(&attempt, 1000, UINT64_C(1000000000), 8, 10, 7, &state)); UT_ASSERT_EQ(state.next_retry_due_mono_us, 11000); UT_ASSERT(resource_x_retry_next_due_exact(&state, 20000, 1, &next_due)); UT_ASSERT_EQ(next_due, 40000); @@ -272,8 +245,7 @@ UT_TEST(test_exponential_backoff_saturates_and_clamps_to_deadline) UT_ASSERT(resource_x_retry_state_init(&attempt, 1000, 50000, 8, 10, 7, &state)); UT_ASSERT(resource_x_retry_next_due_exact(&state, 40000, 1, &next_due)); UT_ASSERT_EQ(next_due, 50000); - UT_ASSERT(resource_x_retry_state_init(&attempt, 1000, UINT64_MAX, 8, 5000, 7, - &state)); + UT_ASSERT(resource_x_retry_state_init(&attempt, 1000, UINT64_MAX, 8, 5000, 7, &state)); UT_ASSERT(resource_x_retry_next_due_exact(&state, UINT64_MAX - 5, 8, &next_due)); UT_ASSERT_EQ(next_due, UINT64_MAX); UT_ASSERT(!resource_x_retry_next_due_exact(&state, 20000, 9, &next_due)); @@ -290,51 +262,43 @@ UT_TEST(test_terminal_transition_is_attempt_generation_and_phase_exact) UT_ASSERT(resource_x_retry_state_init(&attempt, 1000, 6000, 0, 1, 7, ¤t)); expected = current; - UT_ASSERT_EQ(resource_x_retry_terminalize_exact( - ¤t, &expected, errcode, 2000, &terminal), + UT_ASSERT_EQ(resource_x_retry_terminalize_exact(¤t, &expected, errcode, 2000, &terminal), RESOURCE_X_RETRY_APPLY_APPLIED); UT_ASSERT_EQ(terminal.last_phase, RESOURCE_X_RETRY_TERMINAL); UT_ASSERT_EQ(terminal.terminal_errcode, errcode); UT_ASSERT_EQ(terminal.next_retry_due_mono_us, 2000); UT_ASSERT_EQ(terminal.terminal_deadline_mono_us, 2000); UT_ASSERT_EQ(terminal.state_generation, 8); - UT_ASSERT_EQ(resource_x_retry_terminalize_exact( - &terminal, &expected, errcode, 3000, ¤t), + UT_ASSERT_EQ(resource_x_retry_terminalize_exact(&terminal, &expected, errcode, 3000, ¤t), RESOURCE_X_RETRY_APPLY_DUPLICATE); UT_ASSERT(memcmp(¤t, &terminal, sizeof(current)) == 0); current = expected; current.last_phase = RESOURCE_X_RETRY_POST_NO_RETURN; before = current; - UT_ASSERT_EQ(resource_x_retry_terminalize_exact( - ¤t, ¤t, errcode, 2000, &terminal), + UT_ASSERT_EQ(resource_x_retry_terminalize_exact(¤t, ¤t, errcode, 2000, &terminal), RESOURCE_X_RETRY_APPLY_ROLL_FORWARD); UT_ASSERT(memcmp(¤t, &before, sizeof(current)) == 0); current = expected; current.state_generation = PG_UINT32_MAX; - UT_ASSERT_EQ(resource_x_retry_terminalize_exact( - ¤t, ¤t, errcode, 2000, &terminal), + UT_ASSERT_EQ(resource_x_retry_terminalize_exact(¤t, ¤t, errcode, 2000, &terminal), RESOURCE_X_RETRY_APPLY_RECOVERY_BLOCKED); current = expected; - UT_ASSERT_EQ(resource_x_retry_terminalize_exact( - ¤t, ¤t, ERRCODE_DATA_CORRUPTED, 2000, &terminal), + UT_ASSERT_EQ(resource_x_retry_terminalize_exact(¤t, ¤t, ERRCODE_DATA_CORRUPTED, + 2000, &terminal), RESOURCE_X_RETRY_APPLY_RECOVERY_BLOCKED); } UT_TEST(test_terminal_reason_codec_is_closed) { - UT_ASSERT_EQ(resource_x_terminal_reason_decode(0), - RESOURCE_X_TERMINAL_REASON_LEGACY_CANCEL); - UT_ASSERT_EQ(resource_x_terminal_reason_decode( - ERRCODE_CLUSTER_GCS_BLOCK_RETRANSMIT_EXHAUSTED), + UT_ASSERT_EQ(resource_x_terminal_reason_decode(0), RESOURCE_X_TERMINAL_REASON_LEGACY_CANCEL); + UT_ASSERT_EQ(resource_x_terminal_reason_decode(ERRCODE_CLUSTER_GCS_BLOCK_RETRANSMIT_EXHAUSTED), RESOURCE_X_TERMINAL_REASON_RETRY_EXHAUSTED); - UT_ASSERT_EQ(resource_x_terminal_reason_decode( - ERRCODE_CLUSTER_GCS_BLOCK_INVALIDATE_TIMEOUT), + UT_ASSERT_EQ(resource_x_terminal_reason_decode(ERRCODE_CLUSTER_GCS_BLOCK_INVALIDATE_TIMEOUT), RESOURCE_X_TERMINAL_REASON_INVALIDATE_TIMEOUT); UT_ASSERT_EQ(resource_x_terminal_reason_decode(ERRCODE_CLUSTER_LOST_WRITE_DETECTED), RESOURCE_X_TERMINAL_REASON_LOST_WRITE); - UT_ASSERT_EQ(resource_x_terminal_reason_decode(1), - RESOURCE_X_TERMINAL_REASON_INVALID); + UT_ASSERT_EQ(resource_x_terminal_reason_decode(1), RESOURCE_X_TERMINAL_REASON_INVALID); UT_ASSERT_EQ(resource_x_terminal_reason_decode(ERRCODE_DATA_CORRUPTED), RESOURCE_X_TERMINAL_REASON_INVALID); } @@ -351,8 +315,7 @@ UT_TEST(test_terminal_record_replays_one_exact_attempt_byte_for_byte) UT_ASSERT_EQ(sizeof(ResourceXTerminalRecordV1), 72); UT_ASSERT(resource_x_retry_state_init(&attempt, 1000, 6000, 4, 1, 7, ¤t)); current.retry_count = 3; - UT_ASSERT_EQ(resource_x_retry_terminalize_exact( - ¤t, ¤t, + UT_ASSERT_EQ(resource_x_retry_terminalize_exact(¤t, ¤t, ERRCODE_CLUSTER_GCS_BLOCK_INVALIDATE_TIMEOUT, 2000, &terminal), RESOURCE_X_RETRY_APPLY_APPLIED); diff --git a/src/test/cluster_unit/test_cluster_retained_remote.c b/src/test/cluster_unit/test_cluster_retained_remote.c new file mode 100644 index 00000000000..c8b10de21d8 --- /dev/null +++ b/src/test/cluster_unit/test_cluster_retained_remote.c @@ -0,0 +1,77 @@ +/*------------------------------------------------------------------------- + * test_cluster_retained_remote.c + * Reject missing outputs before entering remote authority services. + * + * Author: SqlRush + * Portions Copyright (c) 2026, pgrac contributors + *------------------------------------------------------------------------- + */ +#include "postgres.h" +#include "cluster/cluster_runtime_visibility.h" +#include "cluster/cluster_tx_resolve.h" +#include "cluster/cluster_semantic_activation.h" +#include "cluster/cluster_itl.h" +#include "cluster/cluster_tt_slot.h" +#include "cluster/cluster_uba.h" +#include "cluster/cluster_undo_verdict.h" +#undef printf +#include "unit_test.h" + +UT_DEFINE_GLOBALS(); +int cluster_node_id = 0; + +void +ExceptionalCondition(const char *conditionName, const char *fileName, int lineNumber) +{ + abort(); +} + +/* These boundaries must not be reached by a rejected argument list. */ +static bool +fixture_admission(ClusterTxResolveMode mode, const ClusterSemanticAdmissionToken *admission) +{ + abort(); +} + +static void +fixture_stamp(ClusterTxResolution *out, const ClusterSemanticAdmissionToken *admission) +{ + abort(); +} + +static ClusterUndoVerdictResult +fixture_verdict(int origin, uint32 segment, TransactionId xid, TransactionId ref_xid, uint32 slot, + uint32 epoch, SCN committed, SCN snapshot) +{ + abort(); +} + +#define cluster_runtime_visibility_admission_current fixture_admission +#define cluster_runtime_visibility_origin_candidate_stamp fixture_stamp +#define cluster_undo_verdict_resolve_freshref_c1b_pair fixture_verdict +/* Generated verbatim from the production function, not a copied model. */ +#include "test_cluster_retained_remote.inc" + +UT_TEST(test_missing_output_is_unknown_without_authority_access) +{ + ClusterTxLocator locator = { 0 }; + ClusterTxResolveReason reason = CLUSTER_TX_RESOLVE_NONE; + + UT_ASSERT_EQ(cluster_runtime_visibility_resolve_terminal_census_retained_remote_exact( + &locator, InvalidScn, NULL, NULL, &reason), + CLUSTER_TX_UNKNOWN); + UT_ASSERT_EQ(reason, CLUSTER_TX_RESOLVE_PROTOCOL); + UT_ASSERT_EQ(cluster_runtime_visibility_resolve_terminal_census_retained_remote_exact( + NULL, InvalidScn, NULL, NULL, &reason), + CLUSTER_TX_UNKNOWN); + UT_ASSERT_EQ(reason, CLUSTER_TX_RESOLVE_BAD_LOCATOR); +} + +int +main(void) +{ + UT_PLAN(1); + UT_RUN(test_missing_output_is_unknown_without_authority_access); + UT_DONE(); + return ut_failed_count == 0 ? 0 : 1; +} diff --git a/src/test/cluster_unit/test_cluster_rf_route.c b/src/test/cluster_unit/test_cluster_rf_route.c index cddbc54ad0a..43fc7c687c6 100644 --- a/src/test/cluster_unit/test_cluster_rf_route.c +++ b/src/test/cluster_unit/test_cluster_rf_route.c @@ -24,11 +24,9 @@ UT_DEFINE_GLOBALS(); void -ExceptionalCondition(const char *condition_name, const char *file_name, - int line_number) +ExceptionalCondition(const char *condition_name, const char *file_name, int line_number) { - printf("# Assert failed: %s at %s:%d\n", condition_name, file_name, - line_number); + printf("# Assert failed: %s at %s:%d\n", condition_name, file_name, line_number); abort(); } @@ -52,35 +50,28 @@ main(void) #else static void -sha256_bytes(const uint8 *bytes, size_t len, - uint8 digest[PG_SHA256_DIGEST_LENGTH]) +sha256_bytes(const uint8 *bytes, size_t len, uint8 digest[PG_SHA256_DIGEST_LENGTH]) { pg_cryptohash_ctx *ctx = pg_cryptohash_create(PG_SHA256); UT_ASSERT(ctx != NULL); UT_ASSERT_EQ(pg_cryptohash_init(ctx), 0); UT_ASSERT_EQ(pg_cryptohash_update(ctx, bytes, len), 0); - UT_ASSERT_EQ(pg_cryptohash_final(ctx, digest, - PG_SHA256_DIGEST_LENGTH), 0); + UT_ASSERT_EQ(pg_cryptohash_final(ctx, digest, PG_SHA256_DIGEST_LENGTH), 0); pg_cryptohash_free(ctx); } static bool -find_manifest_route(uint8 rmid, uint8 normalized_info, - RfOpcodeRouteV1 *route, bool *active) +find_manifest_route(uint8 rmid, uint8 normalized_info, RfOpcodeRouteV1 *route, bool *active) { size_t i; - for (i = 0; i < rf_opcode_route_manifest_count_v1(); i++) - { + for (i = 0; i < rf_opcode_route_manifest_count_v1(); i++) { RfOpcodeRouteV1 candidate; bool candidate_active; - UT_ASSERT(rf_opcode_route_manifest_entry_v1(i, &candidate, - &candidate_active)); - if (candidate.rmid == rmid && - candidate.normalized_info == normalized_info) - { + UT_ASSERT(rf_opcode_route_manifest_entry_v1(i, &candidate, &candidate_active)); + if (candidate.rmid == rmid && candidate.normalized_info == normalized_info) { *route = candidate; *active = candidate_active; return true; @@ -98,12 +89,10 @@ UT_TEST(test_route_abi_and_counts) UT_TEST(test_route_canonical_key_stream) { - static const uint8 expected[PG_SHA256_DIGEST_LENGTH] = { - 0x65, 0xb6, 0xc7, 0x28, 0xec, 0xb5, 0xe4, 0xb4, - 0x84, 0x07, 0xbb, 0xb4, 0x96, 0x5b, 0x3e, 0xf4, - 0x68, 0x79, 0x25, 0x55, 0xc6, 0x07, 0xed, 0x5f, - 0xcc, 0x32, 0x06, 0xae, 0xec, 0x40, 0xe8, 0xbe - }; + static const uint8 expected[PG_SHA256_DIGEST_LENGTH] + = { 0x65, 0xb6, 0xc7, 0x28, 0xec, 0xb5, 0xe4, 0xb4, 0x84, 0x07, 0xbb, + 0xb4, 0x96, 0x5b, 0x3e, 0xf4, 0x68, 0x79, 0x25, 0x55, 0xc6, 0x07, + 0xed, 0x5f, 0xcc, 0x32, 0x06, 0xae, 0xec, 0x40, 0xe8, 0xbe }; char stream[1024]; uint8 digest[PG_SHA256_DIGEST_LENGTH]; RfOpcodeRouteV1 route; @@ -111,27 +100,23 @@ UT_TEST(test_route_canonical_key_stream) size_t used = 0; size_t i; - for (i = 0; i < rf_opcode_route_manifest_count_v1(); i++) - { + for (i = 0; i < rf_opcode_route_manifest_count_v1(); i++) { UT_ASSERT(rf_opcode_route_manifest_entry_v1(i, &route, &active)); - if (i > 0) - { + if (i > 0) { RfOpcodeRouteV1 previous; bool previous_active; - UT_ASSERT(rf_opcode_route_manifest_entry_v1(i - 1, &previous, - &previous_active)); - UT_ASSERT(previous.rmid < route.rmid || - (previous.rmid == route.rmid && - previous.normalized_info < route.normalized_info)); + UT_ASSERT(rf_opcode_route_manifest_entry_v1(i - 1, &previous, &previous_active)); + UT_ASSERT(previous.rmid < route.rmid + || (previous.rmid == route.rmid + && previous.normalized_info < route.normalized_info)); } - used += pg_snprintf(stream + used, sizeof(stream) - used, - "%03u:%02X\n", route.rmid, route.normalized_info); + used += pg_snprintf(stream + used, sizeof(stream) - used, "%03u:%02X\n", route.rmid, + route.normalized_info); } UT_ASSERT_EQ(used, 966); - sha256_bytes((const uint8 *) stream, used, digest); - if (memcmp(digest, expected, sizeof(expected)) != 0) - { + sha256_bytes((const uint8 *)stream, used, digest); + if (memcmp(digest, expected, sizeof(expected)) != 0) { size_t j; printf("# route stream SHA-256: "); @@ -146,40 +131,40 @@ UT_TEST(test_route_page_and_side_block_policies) { RfOpcodeRouteV1 route; - UT_ASSERT_EQ(rf_opcode_route_lookup_v1(RM_HEAP_ID, 0x00, true, - false, &route), RF_OPCODE_ROUTE_OK); + UT_ASSERT_EQ(rf_opcode_route_lookup_v1(RM_HEAP_ID, 0x00, true, false, &route), + RF_OPCODE_ROUTE_OK); UT_ASSERT_EQ(route.record_owner, RF_ROUTE_OWNER_PAGE_CODEC); UT_ASSERT_EQ(route.codec_id, RF_ROUTE_CODEC_HEAP); - UT_ASSERT_EQ(rf_opcode_route_lookup_v1(RM_HEAP_ID, 0x00, false, - false, &route), RF_OPCODE_ROUTE_BLOCK_SHAPE_INVALID); - UT_ASSERT_EQ(rf_opcode_route_lookup_v1(RM_SMGR_ID, 0x10, false, - false, &route), RF_OPCODE_ROUTE_OK); + UT_ASSERT_EQ(rf_opcode_route_lookup_v1(RM_HEAP_ID, 0x00, false, false, &route), + RF_OPCODE_ROUTE_BLOCK_SHAPE_INVALID); + UT_ASSERT_EQ(rf_opcode_route_lookup_v1(RM_SMGR_ID, 0x10, false, false, &route), + RF_OPCODE_ROUTE_OK); UT_ASSERT_EQ(route.record_owner, RF_ROUTE_OWNER_SIDE_TYPED); - UT_ASSERT_EQ(rf_opcode_route_lookup_v1(RM_SMGR_ID, 0x10, true, - false, &route), RF_OPCODE_ROUTE_BLOCK_SHAPE_INVALID); + UT_ASSERT_EQ(rf_opcode_route_lookup_v1(RM_SMGR_ID, 0x10, true, false, &route), + RF_OPCODE_ROUTE_BLOCK_SHAPE_INVALID); } UT_TEST(test_route_xact_flags_are_exact) { RfOpcodeRouteV1 route; - UT_ASSERT_EQ(rf_opcode_route_lookup_v1(RM_XACT_ID, 0x80, false, - false, &route), RF_OPCODE_ROUTE_OK); + UT_ASSERT_EQ(rf_opcode_route_lookup_v1(RM_XACT_ID, 0x80, false, false, &route), + RF_OPCODE_ROUTE_OK); UT_ASSERT_EQ(route.normalized_info, 0x00); - UT_ASSERT_EQ(rf_opcode_route_lookup_v1(RM_XACT_ID, 0x90, false, - false, &route), RF_OPCODE_ROUTE_FLAG_ILLEGAL); - UT_ASSERT_EQ(rf_opcode_route_lookup_v1(RM_XACT_ID, 0xB0, false, - false, &route), RF_OPCODE_ROUTE_OK); + UT_ASSERT_EQ(rf_opcode_route_lookup_v1(RM_XACT_ID, 0x90, false, false, &route), + RF_OPCODE_ROUTE_FLAG_ILLEGAL); + UT_ASSERT_EQ(rf_opcode_route_lookup_v1(RM_XACT_ID, 0xB0, false, false, &route), + RF_OPCODE_ROUTE_OK); } UT_TEST(test_route_ctrc_release_is_active_typed_side_record) { RfOpcodeRouteV1 route; - UT_ASSERT_EQ(rf_opcode_route_lookup_v1(RM_CLUSTER_UNDO_ID, 0xA0, - false, false, &route), RF_OPCODE_ROUTE_OK); - UT_ASSERT_EQ(rf_opcode_route_lookup_v1(RM_CLUSTER_UNDO_ID, 0xA0, - true, false, &route), RF_OPCODE_ROUTE_BLOCK_SHAPE_INVALID); + UT_ASSERT_EQ(rf_opcode_route_lookup_v1(RM_CLUSTER_UNDO_ID, 0xA0, false, false, &route), + RF_OPCODE_ROUTE_OK); + UT_ASSERT_EQ(rf_opcode_route_lookup_v1(RM_CLUSTER_UNDO_ID, 0xA0, true, false, &route), + RF_OPCODE_ROUTE_BLOCK_SHAPE_INVALID); UT_ASSERT_EQ(route.codec_id, RF_ROUTE_CODEC_SIDE_CLUSTER_UNDO); } @@ -187,11 +172,11 @@ UT_TEST(test_route_cluster_owners_are_not_family_defaults) { RfOpcodeRouteV1 route; - UT_ASSERT_EQ(rf_opcode_route_lookup_v1(RM_CLUSTER_ADG_ID, 0x10, - false, false, &route), RF_OPCODE_ROUTE_OK); + UT_ASSERT_EQ(rf_opcode_route_lookup_v1(RM_CLUSTER_ADG_ID, 0x10, false, false, &route), + RF_OPCODE_ROUTE_OK); UT_ASSERT_EQ(route.codec_id, RF_ROUTE_CODEC_SIDE_ADG_BARRIER); - UT_ASSERT_EQ(rf_opcode_route_lookup_v1(RM_CLUSTER_XID_STRIPE_ID, 0x00, - false, false, &route), RF_OPCODE_ROUTE_OK); + UT_ASSERT_EQ(rf_opcode_route_lookup_v1(RM_CLUSTER_XID_STRIPE_ID, 0x00, false, false, &route), + RF_OPCODE_ROUTE_OK); UT_ASSERT_EQ(route.codec_id, RF_ROUTE_CODEC_SIDE_XID_STRIPE_SHMEM); } @@ -202,8 +187,7 @@ UT_TEST(test_every_manifest_row_has_one_total_route) size_t logical_count = 0; size_t i; - for (i = 0; i < rf_opcode_route_manifest_count_v1(); i++) - { + for (i = 0; i < rf_opcode_route_manifest_count_v1(); i++) { RfOpcodeRouteV1 expected; RfOpcodeRouteV1 actual; bool active; @@ -212,36 +196,34 @@ UT_TEST(test_every_manifest_row_has_one_total_route) UT_ASSERT(rf_opcode_route_manifest_entry_v1(i, &expected, &active)); UT_ASSERT_EQ(expected.reserved_zero, 0); has_blocks = expected.block_policy != RF_ROUTE_BLOCKS_FORBIDDEN; - UT_ASSERT_EQ(rf_opcode_route_lookup_v1(expected.rmid, - expected.normalized_info, has_blocks, !active, &actual), - RF_OPCODE_ROUTE_OK); + UT_ASSERT_EQ(rf_opcode_route_lookup_v1(expected.rmid, expected.normalized_info, has_blocks, + !active, &actual), + RF_OPCODE_ROUTE_OK); UT_ASSERT(memcmp(&actual, &expected, sizeof(actual)) == 0); - switch (expected.record_owner) - { - case RF_ROUTE_OWNER_PAGE_CODEC: - page_count++; - UT_ASSERT_EQ(expected.block_policy, RF_ROUTE_BLOCKS_REQUIRED); - UT_ASSERT(expected.codec_id >= RF_ROUTE_CODEC_XLOG_FPI); - UT_ASSERT(expected.codec_id <= RF_ROUTE_CODEC_GENERIC); - break; - case RF_ROUTE_OWNER_SIDE_TYPED: - side_count++; - UT_ASSERT(expected.codec_id == RF_ROUTE_CODEC_SIDE_STANDARD || - expected.codec_id == RF_ROUTE_CODEC_SIDE_CLUSTER_UNDO || - expected.codec_id == RF_ROUTE_CODEC_SIDE_RAW_LAYOUT || - expected.codec_id == RF_ROUTE_CODEC_SIDE_ADG_BARRIER || - expected.codec_id == RF_ROUTE_CODEC_SIDE_XID_STRIPE_SHMEM); - UT_ASSERT_EQ(expected.block_policy, - RF_ROUTE_BLOCKS_FORBIDDEN); - break; - case RF_ROUTE_OWNER_LOGICAL_NOOP: - logical_count++; - UT_ASSERT_EQ(expected.codec_id, RF_ROUTE_CODEC_LOGICAL_NOOP); - UT_ASSERT_EQ(expected.block_policy, RF_ROUTE_BLOCKS_FORBIDDEN); - break; - default: - UT_ASSERT(false); + switch (expected.record_owner) { + case RF_ROUTE_OWNER_PAGE_CODEC: + page_count++; + UT_ASSERT_EQ(expected.block_policy, RF_ROUTE_BLOCKS_REQUIRED); + UT_ASSERT(expected.codec_id >= RF_ROUTE_CODEC_XLOG_FPI); + UT_ASSERT(expected.codec_id <= RF_ROUTE_CODEC_GENERIC); + break; + case RF_ROUTE_OWNER_SIDE_TYPED: + side_count++; + UT_ASSERT(expected.codec_id == RF_ROUTE_CODEC_SIDE_STANDARD + || expected.codec_id == RF_ROUTE_CODEC_SIDE_CLUSTER_UNDO + || expected.codec_id == RF_ROUTE_CODEC_SIDE_RAW_LAYOUT + || expected.codec_id == RF_ROUTE_CODEC_SIDE_ADG_BARRIER + || expected.codec_id == RF_ROUTE_CODEC_SIDE_XID_STRIPE_SHMEM); + UT_ASSERT_EQ(expected.block_policy, RF_ROUTE_BLOCKS_FORBIDDEN); + break; + case RF_ROUTE_OWNER_LOGICAL_NOOP: + logical_count++; + UT_ASSERT_EQ(expected.codec_id, RF_ROUTE_CODEC_LOGICAL_NOOP); + UT_ASSERT_EQ(expected.block_policy, RF_ROUTE_BLOCKS_FORBIDDEN); + break; + default: + UT_ASSERT(false); } } @@ -254,47 +236,40 @@ UT_TEST(test_every_high_nibble_is_closed) { uint16 rmid; - for (rmid = 0; rmid < RM_N_BUILTIN_IDS; rmid++) - { + for (rmid = 0; rmid < RM_N_BUILTIN_IDS; rmid++) { uint8 nibble; - for (nibble = 0; nibble < 16; nibble++) - { + for (nibble = 0; nibble < 16; nibble++) { RfOpcodeRouteV1 expected; RfOpcodeRouteV1 actual; RfOpcodeRouteV1 before; RfOpcodeRouteLookupResultV1 result; - uint8 raw_info = (uint8) ((nibble << 4) | XLR_INFO_MASK); + uint8 raw_info = (uint8)((nibble << 4) | XLR_INFO_MASK); uint8 normalized_info; uint8 info_flags = 0; bool active; bool found; bool has_blocks = false; - if (rmid == RM_XACT_ID) - { + if (rmid == RM_XACT_ID) { normalized_info = raw_info & XLOG_XACT_OPMASK; info_flags = raw_info & XLOG_XACT_HAS_INFO; - } - else + } else normalized_info = raw_info & ~XLR_INFO_MASK; - found = find_manifest_route((uint8) rmid, normalized_info, - &expected, &active); + found = find_manifest_route((uint8)rmid, normalized_info, &expected, &active); if (found) has_blocks = expected.block_policy != RF_ROUTE_BLOCKS_FORBIDDEN; memset(&actual, 0xa5, sizeof(actual)); before = actual; - result = rf_opcode_route_lookup_v1((uint8) rmid, raw_info, - has_blocks, true, &actual); + result = rf_opcode_route_lookup_v1((uint8)rmid, raw_info, has_blocks, true, &actual); if (!found) UT_ASSERT_EQ(result, RF_OPCODE_ROUTE_OPCODE_UNSUPPORTED); else if ((info_flags & ~expected.legal_info_flags) != 0) UT_ASSERT_EQ(result, RF_OPCODE_ROUTE_FLAG_ILLEGAL); - else - { + else { UT_ASSERT_EQ(result, RF_OPCODE_ROUTE_OK); UT_ASSERT(memcmp(&actual, &expected, sizeof(actual)) == 0); continue; @@ -311,17 +286,15 @@ UT_TEST(test_all_custom_rmids_and_wrong_block_shapes_are_closed) uint16 rmid; size_t i; - for (rmid = RM_MIN_CUSTOM_ID; rmid <= RM_MAX_CUSTOM_ID; rmid++) - { + for (rmid = RM_MIN_CUSTOM_ID; rmid <= RM_MAX_CUSTOM_ID; rmid++) { memset(&route, 0xa5, sizeof(route)); before = route; - UT_ASSERT_EQ(rf_opcode_route_lookup_v1((uint8) rmid, 0, false, - false, &route), RF_OPCODE_ROUTE_RMID_UNSUPPORTED); + UT_ASSERT_EQ(rf_opcode_route_lookup_v1((uint8)rmid, 0, false, false, &route), + RF_OPCODE_ROUTE_RMID_UNSUPPORTED); UT_ASSERT(memcmp(&route, &before, sizeof(route)) == 0); } - for (i = 0; i < rf_opcode_route_manifest_count_v1(); i++) - { + for (i = 0; i < rf_opcode_route_manifest_count_v1(); i++) { RfOpcodeRouteV1 expected; bool active; bool wrong_blocks; @@ -332,9 +305,9 @@ UT_TEST(test_all_custom_rmids_and_wrong_block_shapes_are_closed) wrong_blocks = expected.block_policy == RF_ROUTE_BLOCKS_FORBIDDEN; memset(&route, 0xa5, sizeof(route)); before = route; - UT_ASSERT_EQ(rf_opcode_route_lookup_v1(expected.rmid, - expected.normalized_info, wrong_blocks, true, &route), - RF_OPCODE_ROUTE_BLOCK_SHAPE_INVALID); + UT_ASSERT_EQ(rf_opcode_route_lookup_v1(expected.rmid, expected.normalized_info, + wrong_blocks, true, &route), + RF_OPCODE_ROUTE_BLOCK_SHAPE_INVALID); UT_ASSERT(memcmp(&route, &before, sizeof(route)) == 0); } } @@ -347,13 +320,13 @@ UT_TEST(test_route_failures_leave_output_untouched) memset(&route, 0xa5, sizeof(route)); before = route; UT_ASSERT_EQ(rf_opcode_route_lookup_v1(128, 0, false, false, &route), - RF_OPCODE_ROUTE_RMID_UNSUPPORTED); + RF_OPCODE_ROUTE_RMID_UNSUPPORTED); UT_ASSERT(memcmp(&route, &before, sizeof(route)) == 0); - UT_ASSERT_EQ(rf_opcode_route_lookup_v1(RM_HEAP_ID, 0x30, true, - false, &route), RF_OPCODE_ROUTE_BLOCK_SHAPE_INVALID); + UT_ASSERT_EQ(rf_opcode_route_lookup_v1(RM_HEAP_ID, 0x30, true, false, &route), + RF_OPCODE_ROUTE_BLOCK_SHAPE_INVALID); UT_ASSERT(memcmp(&route, &before, sizeof(route)) == 0); - UT_ASSERT_EQ(rf_opcode_route_lookup_v1(RM_HEAP_ID, 0xF0, true, - false, &route), RF_OPCODE_ROUTE_OPCODE_UNSUPPORTED); + UT_ASSERT_EQ(rf_opcode_route_lookup_v1(RM_HEAP_ID, 0xF0, true, false, &route), + RF_OPCODE_ROUTE_OPCODE_UNSUPPORTED); UT_ASSERT(memcmp(&route, &before, sizeof(route)) == 0); } diff --git a/src/test/cluster_unit/test_cluster_runtime_visibility.c b/src/test/cluster_unit/test_cluster_runtime_visibility.c index e49993b5916..ffd627d6e65 100644 --- a/src/test/cluster_unit/test_cluster_runtime_visibility.c +++ b/src/test/cluster_unit/test_cluster_runtime_visibility.c @@ -23,6 +23,8 @@ */ #include "postgres.h" +#include + #include "access/multixact.h" /* MultiXactStatus* member kinds (D3-b) */ #include "cluster/cluster_gcs_block.h" /* undo-fetch tag + auth trailer (CP2) */ #include "cluster/cluster_runtime_visibility.h" @@ -32,9 +34,8 @@ #include "unit_test.h" extern bool cluster_vis_freshref_c1b_pair_request_eligible( - TransactionId raw_xid, TransactionId ref_xid, bool has_cached_status, - SCN cached_commit_scn, uint32 ref_epoch, uint64 current_epoch, - int32 origin_node, int32 local_node, uint32 segment_id, + TransactionId raw_xid, TransactionId ref_xid, bool has_cached_status, SCN cached_commit_scn, + uint32 ref_epoch, uint64 current_epoch, int32 origin_node, int32 local_node, uint32 segment_id, uint32 expected_tt_slot_id); UT_DEFINE_GLOBALS(); @@ -51,12 +52,10 @@ read_runtime_visibility_source(void) char *source; if (suffix_at != NULL) - snprintf(path, sizeof(path), - "%.*s/src/backend/cluster/cluster_runtime_visibility.c", + snprintf(path, sizeof(path), "%.*s/src/backend/cluster/cluster_runtime_visibility.c", (int)(suffix_at - source_file), source_file); else - snprintf(path, sizeof(path), - "../../../src/backend/cluster/cluster_runtime_visibility.c"); + snprintf(path, sizeof(path), "../../../src/backend/cluster/cluster_runtime_visibility.c"); file = fopen(path, "rb"); UT_ASSERT_NOT_NULL(file); @@ -82,8 +81,7 @@ static char * read_visibility_resolve_source(void) { const char *source_file = __FILE__; - const char *source_suffix - = "/src/test/cluster_unit/test_cluster_runtime_visibility.c"; + const char *source_suffix = "/src/test/cluster_unit/test_cluster_runtime_visibility.c"; const char *suffix_at = strstr(source_file, source_suffix); char path[MAXPGPATH]; FILE *file; @@ -91,12 +89,10 @@ read_visibility_resolve_source(void) char *source; if (suffix_at != NULL) - snprintf(path, sizeof(path), - "%.*s/src/backend/cluster/cluster_visibility_resolve.c", + snprintf(path, sizeof(path), "%.*s/src/backend/cluster/cluster_visibility_resolve.c", (int)(suffix_at - source_file), source_file); else - snprintf(path, sizeof(path), - "../../../src/backend/cluster/cluster_visibility_resolve.c"); + snprintf(path, sizeof(path), "../../../src/backend/cluster/cluster_visibility_resolve.c"); file = fopen(path, "rb"); UT_ASSERT_NOT_NULL(file); if (file == NULL) @@ -270,34 +266,32 @@ UT_TEST(test_committed_bound_admission_terminal_vs_snapshot) UT_TEST(test_freshref_c1b_pair_request_eligibility) { - UT_ASSERT(cluster_vis_freshref_c1b_pair_request_eligible( - 4195136, 4195136, true, (SCN)10498, 11, 11, 1, 0, 7, 1)); + UT_ASSERT(cluster_vis_freshref_c1b_pair_request_eligible(4195136, 4195136, true, (SCN)10498, 11, + 11, 1, 0, 7, 1)); /* The homogeneous Stage-8 clean formation legitimately carries exact * epoch zero. This pure classifier may select that exact pair; the * requester and origin still require a current R4 TARGET admission before * any zero-epoch frame can be sent or consumed. */ - UT_ASSERT(cluster_vis_freshref_c1b_pair_request_eligible( - 4195136, 4195136, true, (SCN)10498, 0, 0, 1, 0, 7, 1)); - UT_ASSERT(!cluster_vis_freshref_c1b_pair_request_eligible( - 4195136, 4195136, true, (SCN)10498, 1, 0, 1, 0, 7, 1)); - UT_ASSERT(!cluster_vis_freshref_c1b_pair_request_eligible( - 4195136, 4195137, true, (SCN)10498, 11, 11, 1, 0, 7, 1)); - UT_ASSERT(!cluster_vis_freshref_c1b_pair_request_eligible( - 4195136, 4195136, false, (SCN)10498, 11, 11, 1, 0, 7, 1)); - UT_ASSERT(!cluster_vis_freshref_c1b_pair_request_eligible( - 4195136, 4195136, true, InvalidScn, 11, 11, 1, 0, 7, 1)); + UT_ASSERT(cluster_vis_freshref_c1b_pair_request_eligible(4195136, 4195136, true, (SCN)10498, 0, + 0, 1, 0, 7, 1)); + UT_ASSERT(!cluster_vis_freshref_c1b_pair_request_eligible(4195136, 4195136, true, (SCN)10498, 1, + 0, 1, 0, 7, 1)); + UT_ASSERT(!cluster_vis_freshref_c1b_pair_request_eligible(4195136, 4195137, true, (SCN)10498, + 11, 11, 1, 0, 7, 1)); + UT_ASSERT(!cluster_vis_freshref_c1b_pair_request_eligible(4195136, 4195136, false, (SCN)10498, + 11, 11, 1, 0, 7, 1)); + UT_ASSERT(!cluster_vis_freshref_c1b_pair_request_eligible(4195136, 4195136, true, InvalidScn, + 11, 11, 1, 0, 7, 1)); + UT_ASSERT(!cluster_vis_freshref_c1b_pair_request_eligible(4195136, 4195136, true, (SCN)10498, + 10, 11, 1, 0, 7, 1)); + UT_ASSERT(!cluster_vis_freshref_c1b_pair_request_eligible(4195136, 4195136, true, (SCN)10498, + 11, 11, 0, 0, 7, 1)); + UT_ASSERT(!cluster_vis_freshref_c1b_pair_request_eligible(4195136, 4195136, true, (SCN)10498, + 11, 11, 1, 0, 0, 1)); UT_ASSERT(!cluster_vis_freshref_c1b_pair_request_eligible( - 4195136, 4195136, true, (SCN)10498, 10, 11, 1, 0, 7, 1)); + 4195136, 4195136, true, (SCN)10498, 11, 11, 1, 0, 7, TT_SLOTS_PER_SEGMENT + 1)); UT_ASSERT(!cluster_vis_freshref_c1b_pair_request_eligible( - 4195136, 4195136, true, (SCN)10498, 11, 11, 0, 0, 7, 1)); - UT_ASSERT(!cluster_vis_freshref_c1b_pair_request_eligible( - 4195136, 4195136, true, (SCN)10498, 11, 11, 1, 0, 0, 1)); - UT_ASSERT(!cluster_vis_freshref_c1b_pair_request_eligible( - 4195136, 4195136, true, (SCN)10498, 11, 11, 1, 0, 7, - TT_SLOTS_PER_SEGMENT + 1)); - UT_ASSERT(!cluster_vis_freshref_c1b_pair_request_eligible( - 4195136, 4195136, true, (SCN)10498, 11, - UINT64_C(0x100000000), 1, 0, 7, 1)); + 4195136, 4195136, true, (SCN)10498, 11, UINT64_C(0x100000000), 1, 0, 7, 1)); } /* CP2: authority trailer little-endian carrier roundtrip (wire ABI). */ @@ -1006,23 +1000,19 @@ UT_TEST(test_terminal_remote_wrapper_rejects_in_progress_verdict) const char *origin = source != NULL ? strstr(source, "\nrtvis_try_origin_verdict(") : NULL; const char *origin_end = origin != NULL ? strstr(origin, "\nrtvis_try_resolve_remote_internal(") : NULL; - const char *kind4 - = origin != NULL - ? strstr(origin, "case (uint8)CLUSTER_GCS_UNDO_VERDICT_IN_PROGRESS:") - : NULL; + const char *kind4 = origin != NULL + ? strstr(origin, "case (uint8)CLUSTER_GCS_UNDO_VERDICT_IN_PROGRESS:") + : NULL; const char *authoritative_gate = kind4 != NULL ? strstr(kind4, "if (!authoritative || expected_tt_slot_id < 1") : NULL; const char *slot_ceiling = authoritative_gate != NULL - ? strstr(authoritative_gate, - "expected_tt_slot_id > TT_SLOTS_PER_SEGMENT") - : NULL; - const char *publish_live - = kind4 != NULL ? strstr(kind4, "*out_in_progress = true;") : NULL; - const char *wrapper - = source != NULL - ? strstr(source, "\ncluster_runtime_visibility_try_resolve_remote(") + ? strstr(authoritative_gate, "expected_tt_slot_id > TT_SLOTS_PER_SEGMENT") : NULL; + const char *publish_live = kind4 != NULL ? strstr(kind4, "*out_in_progress = true;") : NULL; + const char *wrapper = source != NULL + ? strstr(source, "\ncluster_runtime_visibility_try_resolve_remote(") + : NULL; const char *wrapper_end = wrapper != NULL ? strstr(wrapper, "\n}\n\n/*\n * rtvis_resolve_own_xid") : NULL; const char *guarded_call @@ -1040,8 +1030,8 @@ UT_TEST(test_terminal_remote_wrapper_rejects_in_progress_verdict) UT_ASSERT_NOT_NULL(wrapper_end); UT_ASSERT_NOT_NULL(guarded_call); UT_ASSERT_NOT_NULL(terminal_reject); - if (origin_end != NULL && kind4 != NULL && authoritative_gate != NULL - && slot_ceiling != NULL && publish_live != NULL) + if (origin_end != NULL && kind4 != NULL && authoritative_gate != NULL && slot_ceiling != NULL + && publish_live != NULL) UT_ASSERT(kind4 < authoritative_gate && authoritative_gate < slot_ceiling && slot_ceiling < publish_live && publish_live < origin_end); if (wrapper_end != NULL && guarded_call != NULL && terminal_reject != NULL) @@ -1061,9 +1051,7 @@ UT_TEST(test_pair_eligible_freshref_tries_exact_live_before_terminal_pair) { char *source = read_runtime_visibility_source(); const char *resolver - = source != NULL - ? strstr(source, "\ncluster_undo_verdict_resolve_internal(") - : NULL; + = source != NULL ? strstr(source, "\ncluster_undo_verdict_resolve_internal(") : NULL; const char *resolver_end = resolver != NULL ? strstr(resolver, "\n}\n\nClusterUndoVerdictResult\ncluster_undo_verdict_resolve(") @@ -1073,17 +1061,20 @@ UT_TEST(test_pair_eligible_freshref_tries_exact_live_before_terminal_pair) ? strstr(resolver, "freshref exact-live verdict precedes terminal C1b pair") : NULL; const char *generic_call - = live_first != NULL - ? strstr(live_first, "rtvis_try_resolve_remote_internal(") - : NULL; + = live_first != NULL ? strstr(live_first, "rtvis_try_resolve_remote_internal(") : NULL; const char *generic_shape - = generic_call != NULL - ? strstr(generic_call, "0, InvalidScn, read_scn, true") - : NULL; - const char *pair_call - = generic_shape != NULL - ? strstr(generic_shape, "ref_epoch, freshref_pair_scn, read_scn, authoritative") - : NULL; + = generic_call != NULL ? strstr(generic_call, "0, InvalidScn, read_scn, true") : NULL; + const char *pair_call = generic_shape != NULL + ? strstr(generic_shape, "ref_epoch, freshref_pair_scn, read_scn,") + : NULL; + const char *pair_authority + = pair_call != NULL ? pair_call + strlen("ref_epoch, freshref_pair_scn, read_scn,") : NULL; + + if (pair_authority != NULL) { + while (isspace((unsigned char)*pair_authority)) + pair_authority++; + UT_ASSERT(strncmp(pair_authority, "authoritative,", strlen("authoritative,")) == 0); + } UT_ASSERT_NOT_NULL(resolver); UT_ASSERT_NOT_NULL(resolver_end); @@ -1091,8 +1082,8 @@ UT_TEST(test_pair_eligible_freshref_tries_exact_live_before_terminal_pair) UT_ASSERT_NOT_NULL(generic_call); UT_ASSERT_NOT_NULL(generic_shape); UT_ASSERT_NOT_NULL(pair_call); - if (resolver_end != NULL && live_first != NULL && generic_call != NULL - && generic_shape != NULL && pair_call != NULL) + if (resolver_end != NULL && live_first != NULL && generic_call != NULL && generic_shape != NULL + && pair_call != NULL) UT_ASSERT(live_first < generic_call && generic_call < generic_shape && generic_shape < pair_call && pair_call < resolver_end); free(source); @@ -1101,27 +1092,16 @@ UT_TEST(test_pair_eligible_freshref_tries_exact_live_before_terminal_pair) UT_TEST(test_freshref_unknown_uses_page_exact_locator_without_bound_or_memo) { char *source = read_visibility_resolve_source(); - const char *classifier - = source != NULL ? strstr(source, "\nclassify_ref_guts(") : NULL; + const char *classifier = source != NULL ? strstr(source, "\nclassify_ref_guts(") : NULL; const char *classifier_end = classifier != NULL ? strstr(classifier, "\n}\n\n/*\n * classify_ref") : NULL; - const char *pair - = classifier != NULL - ? strstr(classifier, - "cluster_undo_verdict_resolve_freshref_c1b_pair(") - : NULL; - const char *exact - = pair != NULL - ? strstr(pair, "cluster_tx_resolve_exact(") - : NULL; - const char *visibility - = exact != NULL - ? strstr(exact, "CLUSTER_TX_RESOLVE_VISIBILITY") - : NULL; + const char *pair = classifier != NULL + ? strstr(classifier, "cluster_undo_verdict_resolve_freshref_c1b_pair(") + : NULL; + const char *exact = pair != NULL ? strstr(pair, "cluster_tx_resolve_exact(") : NULL; + const char *visibility = exact != NULL ? strstr(exact, "CLUSTER_TX_RESOLVE_VISIBILITY") : NULL; const char *exact_map - = visibility != NULL - ? strstr(visibility, "cluster_vis_from_exact_tx_resolution(") - : NULL; + = visibility != NULL ? strstr(visibility, "cluster_vis_from_exact_tx_resolution(") : NULL; UT_ASSERT_NOT_NULL(classifier); UT_ASSERT_NOT_NULL(classifier_end); @@ -1133,10 +1113,10 @@ UT_TEST(test_freshref_unknown_uses_page_exact_locator_without_bound_or_memo) UT_ASSERT_NOT_NULL(strstr(source, "*row_wait_locator_out = candidate;")); UT_ASSERT_NOT_NULL(strstr(source, "candidate.tt_wrap = TT_WRAP_INVALID;")); UT_ASSERT_NOT_NULL(strstr(source, "*visibility_locator_out = candidate;")); - if (classifier_end != NULL && pair != NULL && exact != NULL - && visibility != NULL && exact_map != NULL) - UT_ASSERT(pair < exact && exact < visibility - && visibility < exact_map && exact_map < classifier_end); + if (classifier_end != NULL && pair != NULL && exact != NULL && visibility != NULL + && exact_map != NULL) + UT_ASSERT(pair < exact && exact < visibility && visibility < exact_map + && exact_map < classifier_end); /* The exact fallback is operation-local evidence only. */ UT_ASSERT_NULL(strstr(exact != NULL ? exact : "", "cluster_vis_memo_install(")); free(source); @@ -1144,31 +1124,25 @@ UT_TEST(test_freshref_unknown_uses_page_exact_locator_without_bound_or_memo) UT_TEST(test_freshref_failclosed_records_exact_first_local_predicate) { - static const char *const diagnostic_fields[] = { - "raw_xid", - "ref->origin_node_id", - "ref->undo_segment_id", - "ref->tt_slot_id", - "freshref_pair", - "(int)v.kind", - "exact_locator != NULL", - "(int)exact_outcome", - "cluster_tx_resolve_reason_name(exact_reason)" - }; + static const char *const diagnostic_fields[] + = { "raw_xid", + "ref->origin_node_id", + "ref->undo_segment_id", + "ref->tt_slot_id", + "freshref_pair", + "(int)v.kind", + "exact_locator != NULL", + "(int)exact_outcome", + "cluster_tx_resolve_reason_name(exact_reason)" }; char *source = read_visibility_resolve_source(); - const char *classifier - = source != NULL ? strstr(source, "\nclassify_ref_guts(") : NULL; + const char *classifier = source != NULL ? strstr(source, "\nclassify_ref_guts(") : NULL; const char *classifier_end = classifier != NULL ? strstr(classifier, "\n}\n\n/*\n * classify_ref") : NULL; const char *diagnostic - = classifier != NULL - ? strstr(classifier, "cluster_vis_log_freshref_unproven(") - : NULL; + = classifier != NULL ? strstr(classifier, "cluster_vis_log_freshref_unproven(") : NULL; const char *failclosed - = diagnostic != NULL - ? strstr(diagnostic, - "cluster_vis_freshref_verdict_note_failclosed()") - : NULL; + = diagnostic != NULL ? strstr(diagnostic, "cluster_vis_freshref_verdict_note_failclosed()") + : NULL; size_t i; /* This is observability only: the first local fail-closed predicate is diff --git a/src/test/cluster_unit/test_cluster_scn_frontier.c b/src/test/cluster_unit/test_cluster_scn_frontier.c index 29c19a4c6c1..f5857ad95ee 100644 --- a/src/test/cluster_unit/test_cluster_scn_frontier.c +++ b/src/test/cluster_unit/test_cluster_scn_frontier.c @@ -1090,8 +1090,7 @@ UT_TEST(test_spec74_drain_retries_only_exact_not_admitted_peer) UT_ASSERT_EQ(test_unicast_calls[1], 1); UT_ASSERT_EQ(test_unicast_calls[2], 0); UT_ASSERT_EQ(test_unicast_last_len[1], test_fanout_last_len); - UT_ASSERT(memcmp(test_unicast_last_payload[1], test_fanout_last_payload, - test_fanout_last_len) + UT_ASSERT(memcmp(test_unicast_last_payload[1], test_fanout_last_payload, test_fanout_last_len) == 0); /* Once every live peer accepts the latest frontier, no duplicate diff --git a/src/test/cluster_unit/test_cluster_sf_dep.c b/src/test/cluster_unit/test_cluster_sf_dep.c index 254c85da4e6..cb4c664c112 100644 --- a/src/test/cluster_unit/test_cluster_sf_dep.c +++ b/src/test/cluster_unit/test_cluster_sf_dep.c @@ -39,11 +39,10 @@ UT_DEFINE_GLOBALS(); #define TEST_SF_CAP_PEER 7 #define TEST_SF_SHMEM_BYTES 8192 -#define TEST_R4_REQUIRED_CAPS \ - (PGRAC_IC_HELLO_CAP_SEMANTIC_ACTIVATION_V1 | PGRAC_IC_HELLO_CAP_R4_SYNC_CR_V1 \ - | PGRAC_IC_HELLO_CAP_CANDIDATE2_CORRECTED_A1_V1 \ - | PGRAC_IC_HELLO_CAP_UNDO_ROOT_DESCRIPTOR_V1) -#define TEST_STAGE8_ACK_REQUIRED_CAPS \ +#define TEST_R4_REQUIRED_CAPS \ + (PGRAC_IC_HELLO_CAP_SEMANTIC_ACTIVATION_V1 | PGRAC_IC_HELLO_CAP_R4_SYNC_CR_V1 \ + | PGRAC_IC_HELLO_CAP_CANDIDATE2_CORRECTED_A1_V1 | PGRAC_IC_HELLO_CAP_UNDO_ROOT_DESCRIPTOR_V1) +#define TEST_STAGE8_ACK_REQUIRED_CAPS \ (TEST_R4_REQUIRED_CAPS | PGRAC_IC_HELLO_CAP_SEMANTIC_ACTIVATION_ACK_V1) typedef union TestSfShmemStorage { @@ -507,39 +506,40 @@ UT_TEST(test_r4_exported_family_sample_requires_both_bits_and_canonicalizes_outp bool want_done; uint32 want_generation; } cases[] = { - {PGRAC_IC_HELLO_CAP_SEMANTIC_ACTIVATION_V1, 11, TEST_R4_REQUIRED_CAPS, - PGRAC_IC_HELLO_CAP_GCS_DONE_V1, false, false, 0}, - {PGRAC_IC_HELLO_CAP_R4_SYNC_CR_V1, 12, TEST_R4_REQUIRED_CAPS, - PGRAC_IC_HELLO_CAP_GCS_DONE_V1, false, false, 0}, - {PGRAC_IC_HELLO_CAP_GCS_DONE_V1, 13, TEST_R4_REQUIRED_CAPS, - PGRAC_IC_HELLO_CAP_GCS_DONE_V1, false, false, 0}, - {TEST_R4_REQUIRED_CAPS, 14, TEST_R4_REQUIRED_CAPS, - PGRAC_IC_HELLO_CAP_GCS_DONE_V1, true, false, 14}, - {TEST_R4_REQUIRED_CAPS | PGRAC_IC_HELLO_CAP_GCS_DONE_V1, 15, - TEST_R4_REQUIRED_CAPS, PGRAC_IC_HELLO_CAP_GCS_DONE_V1, true, true, 15}, - {TEST_R4_REQUIRED_CAPS | PGRAC_IC_HELLO_CAP_GCS_DONE_V1, 16, 0, - PGRAC_IC_HELLO_CAP_GCS_DONE_V1, false, false, 0}, - {TEST_R4_REQUIRED_CAPS | PGRAC_IC_HELLO_CAP_GCS_DONE_V1, 17, - TEST_R4_REQUIRED_CAPS, 0, true, false, 17}, + { PGRAC_IC_HELLO_CAP_SEMANTIC_ACTIVATION_V1, 11, TEST_R4_REQUIRED_CAPS, + PGRAC_IC_HELLO_CAP_GCS_DONE_V1, false, false, 0 }, + { PGRAC_IC_HELLO_CAP_R4_SYNC_CR_V1, 12, TEST_R4_REQUIRED_CAPS, + PGRAC_IC_HELLO_CAP_GCS_DONE_V1, false, false, 0 }, + { PGRAC_IC_HELLO_CAP_GCS_DONE_V1, 13, TEST_R4_REQUIRED_CAPS, PGRAC_IC_HELLO_CAP_GCS_DONE_V1, + false, false, 0 }, + { TEST_R4_REQUIRED_CAPS, 14, TEST_R4_REQUIRED_CAPS, PGRAC_IC_HELLO_CAP_GCS_DONE_V1, true, + false, 14 }, + { TEST_R4_REQUIRED_CAPS | PGRAC_IC_HELLO_CAP_GCS_DONE_V1, 15, TEST_R4_REQUIRED_CAPS, + PGRAC_IC_HELLO_CAP_GCS_DONE_V1, true, true, 15 }, + { TEST_R4_REQUIRED_CAPS | PGRAC_IC_HELLO_CAP_GCS_DONE_V1, 16, 0, + PGRAC_IC_HELLO_CAP_GCS_DONE_V1, false, false, 0 }, + { TEST_R4_REQUIRED_CAPS | PGRAC_IC_HELLO_CAP_GCS_DONE_V1, 17, TEST_R4_REQUIRED_CAPS, 0, + true, false, 17 }, }; bool done = true; uint32 generation = UINT32_MAX; Size i; test_sf_cap_store_reset(); - UT_ASSERT(!cluster_sf_peer_capability_family_sample( - TEST_SF_CAP_PEER, TEST_R4_REQUIRED_CAPS, PGRAC_IC_HELLO_CAP_GCS_DONE_V1, &done, - &generation)); + UT_ASSERT(!cluster_sf_peer_capability_family_sample(TEST_SF_CAP_PEER, TEST_R4_REQUIRED_CAPS, + PGRAC_IC_HELLO_CAP_GCS_DONE_V1, &done, + &generation)); UT_ASSERT(!done); UT_ASSERT_EQ(generation, (uint32)0); for (i = 0; i < lengthof(cases); i++) { cluster_sf_note_peer_hello_capabilities_gen(TEST_SF_CAP_PEER, cases[i].bits, - cases[i].noted_generation); + cases[i].noted_generation); done = !cases[i].want_done; generation = UINT32_MAX; - UT_ASSERT_EQ(cluster_sf_peer_capability_family_sample( - TEST_SF_CAP_PEER, cases[i].required, cases[i].optional, &done, &generation), + UT_ASSERT_EQ(cluster_sf_peer_capability_family_sample(TEST_SF_CAP_PEER, cases[i].required, + cases[i].optional, &done, + &generation), cases[i].want_supported); UT_ASSERT_EQ(done, cases[i].want_done); UT_ASSERT_EQ(generation, cases[i].want_generation); @@ -566,13 +566,13 @@ UT_TEST(test_r4_exported_family_sample_accepts_registered_generation_zero) test_sf_cap_store_reset(); cluster_sf_note_peer_hello_capabilities_gen( TEST_SF_CAP_PEER, TEST_R4_REQUIRED_CAPS | PGRAC_IC_HELLO_CAP_GCS_DONE_V1, 0); - UT_ASSERT(cluster_sf_peer_capability_family_sample( - TEST_SF_CAP_PEER, TEST_R4_REQUIRED_CAPS, PGRAC_IC_HELLO_CAP_GCS_DONE_V1, &done, - &generation)); + UT_ASSERT(cluster_sf_peer_capability_family_sample(TEST_SF_CAP_PEER, TEST_R4_REQUIRED_CAPS, + PGRAC_IC_HELLO_CAP_GCS_DONE_V1, &done, + &generation)); UT_ASSERT(done); UT_ASSERT_EQ(generation, (uint32)1); - UT_ASSERT(cluster_sf_peer_capability_generation_matches(TEST_SF_CAP_PEER, - TEST_R4_REQUIRED_CAPS, 1)); + UT_ASSERT( + cluster_sf_peer_capability_generation_matches(TEST_SF_CAP_PEER, TEST_R4_REQUIRED_CAPS, 1)); } UT_TEST(test_r4_exported_family_sample_reconnect_generation_is_exact) @@ -583,39 +583,39 @@ UT_TEST(test_r4_exported_family_sample_reconnect_generation_is_exact) test_sf_cap_store_reset(); cluster_sf_note_peer_hello_capabilities_gen( TEST_SF_CAP_PEER, TEST_R4_REQUIRED_CAPS | PGRAC_IC_HELLO_CAP_GCS_DONE_V1, 21); - UT_ASSERT(cluster_sf_peer_capability_family_sample( - TEST_SF_CAP_PEER, TEST_R4_REQUIRED_CAPS, PGRAC_IC_HELLO_CAP_GCS_DONE_V1, &done, - &generation)); + UT_ASSERT(cluster_sf_peer_capability_family_sample(TEST_SF_CAP_PEER, TEST_R4_REQUIRED_CAPS, + PGRAC_IC_HELLO_CAP_GCS_DONE_V1, &done, + &generation)); UT_ASSERT(done); UT_ASSERT_EQ(generation, (uint32)21); - UT_ASSERT(cluster_sf_peer_capability_generation_matches(TEST_SF_CAP_PEER, - TEST_R4_REQUIRED_CAPS, 21)); + UT_ASSERT( + cluster_sf_peer_capability_generation_matches(TEST_SF_CAP_PEER, TEST_R4_REQUIRED_CAPS, 21)); cluster_sf_note_peer_hello_capabilities_gen( TEST_SF_CAP_PEER, TEST_R4_REQUIRED_CAPS | PGRAC_IC_HELLO_CAP_GCS_DONE_V1, 22); UT_ASSERT(!cluster_sf_peer_capability_generation_matches(TEST_SF_CAP_PEER, - TEST_R4_REQUIRED_CAPS, 21)); - UT_ASSERT(cluster_sf_peer_capability_generation_matches(TEST_SF_CAP_PEER, - TEST_R4_REQUIRED_CAPS, 22)); + TEST_R4_REQUIRED_CAPS, 21)); + UT_ASSERT( + cluster_sf_peer_capability_generation_matches(TEST_SF_CAP_PEER, TEST_R4_REQUIRED_CAPS, 22)); done = false; generation = UINT32_MAX; - UT_ASSERT(cluster_sf_peer_capability_family_sample( - TEST_SF_CAP_PEER, TEST_R4_REQUIRED_CAPS, PGRAC_IC_HELLO_CAP_GCS_DONE_V1, &done, - &generation)); + UT_ASSERT(cluster_sf_peer_capability_family_sample(TEST_SF_CAP_PEER, TEST_R4_REQUIRED_CAPS, + PGRAC_IC_HELLO_CAP_GCS_DONE_V1, &done, + &generation)); UT_ASSERT(done); UT_ASSERT_EQ(generation, (uint32)22); - cluster_sf_note_peer_hello_capabilities_gen(TEST_SF_CAP_PEER, - PGRAC_IC_HELLO_CAP_GCS_DONE_V1, 23); + cluster_sf_note_peer_hello_capabilities_gen(TEST_SF_CAP_PEER, PGRAC_IC_HELLO_CAP_GCS_DONE_V1, + 23); done = true; generation = UINT32_MAX; - UT_ASSERT(!cluster_sf_peer_capability_family_sample( - TEST_SF_CAP_PEER, TEST_R4_REQUIRED_CAPS, PGRAC_IC_HELLO_CAP_GCS_DONE_V1, &done, - &generation)); + UT_ASSERT(!cluster_sf_peer_capability_family_sample(TEST_SF_CAP_PEER, TEST_R4_REQUIRED_CAPS, + PGRAC_IC_HELLO_CAP_GCS_DONE_V1, &done, + &generation)); UT_ASSERT(!done); UT_ASSERT_EQ(generation, (uint32)0); UT_ASSERT(!cluster_sf_peer_capability_generation_matches(TEST_SF_CAP_PEER, - TEST_R4_REQUIRED_CAPS, 23)); + TEST_R4_REQUIRED_CAPS, 23)); cluster_sf_note_peer_disconnected_gen(TEST_SF_CAP_PEER, 22); UT_ASSERT(cluster_sf_peer_supports_gcs_done(TEST_SF_CAP_PEER)); @@ -625,45 +625,36 @@ UT_TEST(test_r4_exported_family_sample_reconnect_generation_is_exact) UT_TEST(test_stage8_ack_full_word_sample_is_record_coherent) { - const uint32 full_word - = TEST_STAGE8_ACK_REQUIRED_CAPS - | PGRAC_IC_HELLO_CAP_GCS_DONE_V1; + const uint32 full_word = TEST_STAGE8_ACK_REQUIRED_CAPS | PGRAC_IC_HELLO_CAP_GCS_DONE_V1; uint32 sampled_word = UINT32_MAX; uint32 generation = UINT32_MAX; test_sf_cap_store_reset(); UT_ASSERT(!cluster_sf_peer_capability_word_sample( - TEST_SF_CAP_PEER, TEST_STAGE8_ACK_REQUIRED_CAPS, - &sampled_word, &generation)); + TEST_SF_CAP_PEER, TEST_STAGE8_ACK_REQUIRED_CAPS, &sampled_word, &generation)); UT_ASSERT_EQ(sampled_word, (uint32)0); UT_ASSERT_EQ(generation, (uint32)0); - cluster_sf_note_peer_hello_capabilities_gen( - TEST_SF_CAP_PEER, full_word, 41); + cluster_sf_note_peer_hello_capabilities_gen(TEST_SF_CAP_PEER, full_word, 41); UT_ASSERT(cluster_sf_peer_capability_word_sample( - TEST_SF_CAP_PEER, TEST_STAGE8_ACK_REQUIRED_CAPS, - &sampled_word, &generation)); + TEST_SF_CAP_PEER, TEST_STAGE8_ACK_REQUIRED_CAPS, &sampled_word, &generation)); UT_ASSERT_EQ(sampled_word, full_word); UT_ASSERT_EQ(generation, (uint32)41); cluster_sf_note_peer_hello_capabilities_gen( TEST_SF_CAP_PEER, - TEST_STAGE8_ACK_REQUIRED_CAPS - & ~PGRAC_IC_HELLO_CAP_SEMANTIC_ACTIVATION_ACK_V1, - 42); + TEST_STAGE8_ACK_REQUIRED_CAPS & ~PGRAC_IC_HELLO_CAP_SEMANTIC_ACTIVATION_ACK_V1, 42); sampled_word = UINT32_MAX; generation = UINT32_MAX; UT_ASSERT(!cluster_sf_peer_capability_word_sample( - TEST_SF_CAP_PEER, TEST_STAGE8_ACK_REQUIRED_CAPS, - &sampled_word, &generation)); + TEST_SF_CAP_PEER, TEST_STAGE8_ACK_REQUIRED_CAPS, &sampled_word, &generation)); UT_ASSERT_EQ(sampled_word, (uint32)0); UT_ASSERT_EQ(generation, (uint32)0); sampled_word = UINT32_MAX; generation = UINT32_MAX; - UT_ASSERT(!cluster_sf_peer_capability_word_sample( - -1, TEST_STAGE8_ACK_REQUIRED_CAPS, - &sampled_word, &generation)); + UT_ASSERT(!cluster_sf_peer_capability_word_sample(-1, TEST_STAGE8_ACK_REQUIRED_CAPS, + &sampled_word, &generation)); UT_ASSERT_EQ(sampled_word, (uint32)0); UT_ASSERT_EQ(generation, (uint32)0); } @@ -673,32 +664,32 @@ UT_TEST(test_current_mx_capability_generation_sample_is_connection_exact) uint32 generation = UINT32_MAX; test_sf_cap_store_reset(); - UT_ASSERT(!cluster_sf_peer_multixact_current_capability_generation( - TEST_SF_CAP_PEER, &generation)); + UT_ASSERT( + !cluster_sf_peer_multixact_current_capability_generation(TEST_SF_CAP_PEER, &generation)); UT_ASSERT_EQ(generation, (uint32)0); /* The former 0x00001000 allocation belongs to semantic activation and * must not admit the migrated Current-MX transport. */ - cluster_sf_note_peer_hello_capabilities_gen( - TEST_SF_CAP_PEER, PGRAC_IC_HELLO_CAP_SEMANTIC_ACTIVATION_V1, 72); + cluster_sf_note_peer_hello_capabilities_gen(TEST_SF_CAP_PEER, + PGRAC_IC_HELLO_CAP_SEMANTIC_ACTIVATION_V1, 72); generation = UINT32_MAX; - UT_ASSERT(!cluster_sf_peer_multixact_current_capability_generation( - TEST_SF_CAP_PEER, &generation)); + UT_ASSERT( + !cluster_sf_peer_multixact_current_capability_generation(TEST_SF_CAP_PEER, &generation)); UT_ASSERT_EQ(generation, (uint32)0); - cluster_sf_note_peer_hello_capabilities_gen( - TEST_SF_CAP_PEER, PGRAC_IC_HELLO_CAP_MULTIXACT_CURRENT_V1, 73); - UT_ASSERT(cluster_sf_peer_multixact_current_capability_generation( - TEST_SF_CAP_PEER, &generation)); + cluster_sf_note_peer_hello_capabilities_gen(TEST_SF_CAP_PEER, + PGRAC_IC_HELLO_CAP_MULTIXACT_CURRENT_V1, 73); + UT_ASSERT( + cluster_sf_peer_multixact_current_capability_generation(TEST_SF_CAP_PEER, &generation)); UT_ASSERT_EQ(generation, (uint32)73); /* A reconnect that withdraws the bit invalidates both authority and the * previously sampled generation. */ - cluster_sf_note_peer_hello_capabilities_gen( - TEST_SF_CAP_PEER, PGRAC_IC_HELLO_CAP_SEMANTIC_ACTIVATION_V1, 74); + cluster_sf_note_peer_hello_capabilities_gen(TEST_SF_CAP_PEER, + PGRAC_IC_HELLO_CAP_SEMANTIC_ACTIVATION_V1, 74); generation = UINT32_MAX; - UT_ASSERT(!cluster_sf_peer_multixact_current_capability_generation( - TEST_SF_CAP_PEER, &generation)); + UT_ASSERT( + !cluster_sf_peer_multixact_current_capability_generation(TEST_SF_CAP_PEER, &generation)); UT_ASSERT_EQ(generation, (uint32)0); } diff --git a/src/test/cluster_unit/test_cluster_share_barrier.c b/src/test/cluster_unit/test_cluster_share_barrier.c index a826742b1b1..210e1a9ec61 100644 --- a/src/test/cluster_unit/test_cluster_share_barrier.c +++ b/src/test/cluster_unit/test_cluster_share_barrier.c @@ -32,8 +32,7 @@ UT_DEFINE_GLOBALS(); -typedef enum FixtureAction -{ +typedef enum FixtureAction { ACTION_ABORT_HOLDER = 1, ACTION_ABORT_WRITER, ACTION_RELEASE_MASTER, @@ -42,24 +41,23 @@ typedef enum FixtureAction ACTION_PROVE_EMPTY } FixtureAction; -typedef struct BarrierFixture -{ - bool content_lock; - bool holder; - bool writer; - bool pending; - bool master_grant; - bool cached_share_cover; - bool outer_lock; - bool first_buffer_lock; - int pins; +typedef struct BarrierFixture { + bool content_lock; + bool holder; + bool writer; + bool pending; + bool master_grant; + bool cached_share_cover; + bool outer_lock; + bool first_buffer_lock; + int pins; ClusterBufferBarrierCleanupResult holder_result; ClusterBufferBarrierCleanupResult writer_result; ClusterBufferBarrierCleanupResult master_result; ClusterBufferBarrierCleanupResult converge_result; ClusterBufferBarrierCleanupResult pending_result; FixtureAction actions[8]; - int action_count; + int action_count; } BarrierFixture; void @@ -137,25 +135,23 @@ fixture_prove_empty(void *context) BarrierFixture *fixture = context; record_action(fixture, ACTION_PROVE_EMPTY); - return !fixture->content_lock && !fixture->holder && !fixture->writer - && !fixture->pending && !fixture->master_grant; + return !fixture->content_lock && !fixture->holder && !fixture->writer && !fixture->pending + && !fixture->master_grant; } -static const ClusterBufferBarrierUnwindOps fixture_ops = { - .abort_holder = fixture_abort_holder, - .abort_writer = fixture_abort_writer, - .release_master = fixture_release_master, - .converge_local = fixture_converge_local, - .abort_pending = fixture_abort_pending, - .prove_empty = fixture_prove_empty -}; +static const ClusterBufferBarrierUnwindOps fixture_ops = { .abort_holder = fixture_abort_holder, + .abort_writer = fixture_abort_writer, + .release_master = fixture_release_master, + .converge_local = fixture_converge_local, + .abort_pending = fixture_abort_pending, + .prove_empty = fixture_prove_empty }; static BarrierFixture clean_fixture(void) { BarrierFixture fixture; - MemSet(&fixture, 0, sizeof(fixture)); + memset(&fixture, 0, sizeof(fixture)); fixture.outer_lock = true; fixture.first_buffer_lock = true; fixture.cached_share_cover = true; @@ -167,8 +163,7 @@ UT_TEST(test_u1_early_barrier_proves_empty) { BarrierFixture fixture = clean_fixture(); - UT_ASSERT_EQ(cluster_buffer_barrier_unwind_execute(&fixture_ops, &fixture, - false, false), + UT_ASSERT_EQ(cluster_buffer_barrier_unwind_execute(&fixture_ops, &fixture, false, false), CLUSTER_BUFFER_BARRIER_UNWIND_OK); UT_ASSERT_EQ(fixture.action_count, 3); UT_ASSERT_EQ(fixture.actions[2], ACTION_PROVE_EMPTY); @@ -178,8 +173,7 @@ UT_TEST(test_u2_cached_cover_is_not_released) { BarrierFixture fixture = clean_fixture(); - UT_ASSERT_EQ(cluster_buffer_barrier_unwind_execute(&fixture_ops, &fixture, - false, false), + UT_ASSERT_EQ(cluster_buffer_barrier_unwind_execute(&fixture_ops, &fixture, false, false), CLUSTER_BUFFER_BARRIER_UNWIND_OK); UT_ASSERT(!fixture.master_grant); UT_ASSERT(fixture.cached_share_cover); @@ -191,8 +185,7 @@ UT_TEST(test_u3_read_image_clears_exact_pending) BarrierFixture fixture = clean_fixture(); fixture.pending = true; - UT_ASSERT_EQ(cluster_buffer_barrier_unwind_execute(&fixture_ops, &fixture, - false, true), + UT_ASSERT_EQ(cluster_buffer_barrier_unwind_execute(&fixture_ops, &fixture, false, true), CLUSTER_BUFFER_BARRIER_UNWIND_OK); UT_ASSERT(!fixture.pending); UT_ASSERT_EQ(fixture.actions[2], ACTION_ABORT_PENDING); @@ -204,8 +197,7 @@ UT_TEST(test_u4_durable_grant_releases_master_before_local) fixture.pending = true; fixture.master_grant = true; - UT_ASSERT_EQ(cluster_buffer_barrier_unwind_execute(&fixture_ops, &fixture, - true, true), + UT_ASSERT_EQ(cluster_buffer_barrier_unwind_execute(&fixture_ops, &fixture, true, true), CLUSTER_BUFFER_BARRIER_UNWIND_OK); UT_ASSERT_EQ(fixture.actions[2], ACTION_RELEASE_MASTER); UT_ASSERT_EQ(fixture.actions[3], ACTION_CONVERGE_LOCAL); @@ -216,8 +208,7 @@ UT_TEST(test_u5_rearm_barrier_does_not_abort_twice) { BarrierFixture fixture = clean_fixture(); - UT_ASSERT_EQ(cluster_buffer_barrier_unwind_execute(&fixture_ops, &fixture, - false, false), + UT_ASSERT_EQ(cluster_buffer_barrier_unwind_execute(&fixture_ops, &fixture, false, false), CLUSTER_BUFFER_BARRIER_UNWIND_OK); UT_ASSERT_EQ(fixture.action_count, 3); } @@ -228,16 +219,14 @@ UT_TEST(test_u6_holder_is_removed_before_clean_return) BarrierFixture deferred = clean_fixture(); fixture.holder = true; - UT_ASSERT_EQ(cluster_buffer_barrier_unwind_execute(&fixture_ops, &fixture, - false, false), + UT_ASSERT_EQ(cluster_buffer_barrier_unwind_execute(&fixture_ops, &fixture, false, false), CLUSTER_BUFFER_BARRIER_UNWIND_OK); UT_ASSERT(!fixture.holder); UT_ASSERT_EQ(fixture.actions[2], ACTION_PROVE_EMPTY); deferred.holder = true; deferred.holder_result = CLUSTER_BUFFER_BARRIER_DEFERRED; - UT_ASSERT_EQ(cluster_buffer_barrier_unwind_execute(&fixture_ops, &deferred, - false, false), + UT_ASSERT_EQ(cluster_buffer_barrier_unwind_execute(&fixture_ops, &deferred, false, false), CLUSTER_BUFFER_BARRIER_UNWIND_HOLDER_NOT_EMPTY); UT_ASSERT(deferred.holder); } @@ -249,8 +238,7 @@ UT_TEST(test_u7_master_release_failure_preserves_pending) fixture.pending = true; fixture.master_grant = true; fixture.master_result = CLUSTER_BUFFER_BARRIER_FAILED; - UT_ASSERT_EQ(cluster_buffer_barrier_unwind_execute(&fixture_ops, &fixture, - true, true), + UT_ASSERT_EQ(cluster_buffer_barrier_unwind_execute(&fixture_ops, &fixture, true, true), CLUSTER_BUFFER_BARRIER_UNWIND_MASTER_RELEASE_FAILED); UT_ASSERT(fixture.pending); UT_ASSERT(fixture.master_grant); @@ -263,8 +251,7 @@ UT_TEST(test_u8_local_convergence_failure_is_not_clean) fixture.pending = true; fixture.master_grant = true; fixture.converge_result = CLUSTER_BUFFER_BARRIER_FAILED; - UT_ASSERT_EQ(cluster_buffer_barrier_unwind_execute(&fixture_ops, &fixture, - true, true), + UT_ASSERT_EQ(cluster_buffer_barrier_unwind_execute(&fixture_ops, &fixture, true, true), CLUSTER_BUFFER_BARRIER_UNWIND_LOCAL_CONVERGENCE_FAILED); UT_ASSERT(fixture.pending); UT_ASSERT(!fixture.master_grant); @@ -274,8 +261,7 @@ UT_TEST(test_u9_clean_success_is_the_only_false_postcondition) { BarrierFixture fixture = clean_fixture(); - UT_ASSERT_EQ(cluster_buffer_barrier_unwind_execute(&fixture_ops, &fixture, - false, false), + UT_ASSERT_EQ(cluster_buffer_barrier_unwind_execute(&fixture_ops, &fixture, false, false), CLUSTER_BUFFER_BARRIER_UNWIND_OK); UT_ASSERT(!fixture.content_lock); } @@ -286,16 +272,14 @@ UT_TEST(test_u10_exclusive_writer_cleanup_is_exact) BarrierFixture deferred = clean_fixture(); fixture.writer = true; - UT_ASSERT_EQ(cluster_buffer_barrier_unwind_execute(&fixture_ops, &fixture, - false, false), + UT_ASSERT_EQ(cluster_buffer_barrier_unwind_execute(&fixture_ops, &fixture, false, false), CLUSTER_BUFFER_BARRIER_UNWIND_OK); UT_ASSERT(!fixture.writer); UT_ASSERT(fixture.outer_lock); deferred.writer = true; deferred.writer_result = CLUSTER_BUFFER_BARRIER_DEFERRED; - UT_ASSERT_EQ(cluster_buffer_barrier_unwind_execute(&fixture_ops, &deferred, - false, false), + UT_ASSERT_EQ(cluster_buffer_barrier_unwind_execute(&fixture_ops, &deferred, false, false), CLUSTER_BUFFER_BARRIER_UNWIND_WRITER_NOT_EMPTY); UT_ASSERT(deferred.writer); } @@ -304,8 +288,7 @@ UT_TEST(test_u11_two_buffer_outer_lock_stays_owned) { BarrierFixture fixture = clean_fixture(); - UT_ASSERT_EQ(cluster_buffer_barrier_unwind_execute(&fixture_ops, &fixture, - false, false), + UT_ASSERT_EQ(cluster_buffer_barrier_unwind_execute(&fixture_ops, &fixture, false, false), CLUSTER_BUFFER_BARRIER_UNWIND_OK); UT_ASSERT(fixture.first_buffer_lock); } @@ -314,8 +297,7 @@ UT_TEST(test_u12_pins_and_outer_ownership_are_unchanged) { BarrierFixture fixture = clean_fixture(); - UT_ASSERT_EQ(cluster_buffer_barrier_unwind_execute(&fixture_ops, &fixture, - false, false), + UT_ASSERT_EQ(cluster_buffer_barrier_unwind_execute(&fixture_ops, &fixture, false, false), CLUSTER_BUFFER_BARRIER_UNWIND_OK); UT_ASSERT_EQ(fixture.pins, 2); UT_ASSERT(fixture.outer_lock); diff --git a/src/test/cluster_unit/test_cluster_shared_fs.c b/src/test/cluster_unit/test_cluster_shared_fs.c index d3f19ee8243..4adb5abc644 100644 --- a/src/test/cluster_unit/test_cluster_shared_fs.c +++ b/src/test/cluster_unit/test_cluster_shared_fs.c @@ -769,18 +769,15 @@ UT_TEST(test_undo_shared_path_resolve) UT_TEST(test_external_fence_protected_set_identity_is_exact_and_closed) { - static const uint8 expected_uuid[16] = { - 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, - 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff - }; + static const uint8 expected_uuid[16] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, + 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff }; ClusterProtectedSetIdentityV1 identity; cluster_shared_storage_backend = CLUSTER_SHARED_FS_BACKEND_BLOCK_DEVICE; stub_block_device_storage_uuid = "00112233445566778899aabbccddeeff"; UT_ASSERT(cluster_shared_fs_get_protected_set_identity(&identity)); UT_ASSERT_EQ(identity.backend_id, CLUSTER_SHARED_FS_BACKEND_BLOCK_DEVICE); - UT_ASSERT(memcmp(identity.storage_uuid, expected_uuid, - sizeof(expected_uuid)) == 0); + UT_ASSERT(memcmp(identity.storage_uuid, expected_uuid, sizeof(expected_uuid)) == 0); stub_block_device_storage_uuid = "raw-block-device"; UT_ASSERT(!cluster_shared_fs_get_protected_set_identity(&identity)); diff --git a/src/test/cluster_unit/test_cluster_shared_fs_block_device.c b/src/test/cluster_unit/test_cluster_shared_fs_block_device.c index 979c574eb94..af931efdc34 100644 --- a/src/test/cluster_unit/test_cluster_shared_fs_block_device.c +++ b/src/test/cluster_unit/test_cluster_shared_fs_block_device.c @@ -398,10 +398,9 @@ UT_TEST(test_block_device_roundtrip_layout_and_eof) { char protected_uuid[CLUSTER_SHARED_UUID_LEN]; - UT_ASSERT(cluster_shared_fs_block_device_get_storage_uuid( - protected_uuid, sizeof(protected_uuid))); - UT_ASSERT_STR_EQ(protected_uuid, - "00112233445566778899aabbccddeeff"); + UT_ASSERT(cluster_shared_fs_block_device_get_storage_uuid(protected_uuid, + sizeof(protected_uuid))); + UT_ASSERT_STR_EQ(protected_uuid, "00112233445566778899aabbccddeeff"); } raw_wal_emit_count = 0; diff --git a/src/test/cluster_unit/test_cluster_side_corpus.c b/src/test/cluster_unit/test_cluster_side_corpus.c index 35a6c10b8b0..c1d1c94ded1 100644 --- a/src/test/cluster_unit/test_cluster_side_corpus.c +++ b/src/test/cluster_unit/test_cluster_side_corpus.c @@ -80,7 +80,7 @@ static ClusterPageVersion ut_v[3]; static void ut_setup_globals(void) { - int i; + int i; memset(&ut_id, 0, sizeof(ut_id)); ut_id.rlocator.spcOid = 1; @@ -93,7 +93,7 @@ ut_setup_globals(void) memset(&ut_v[i], 0, sizeof(ut_v[i])); ut_v[i].identity = ut_id; ut_v[i].incarnation = 7; - ut_v[i].token = (uint64) (100 + i); + ut_v[i].token = (uint64)(100 + i); } } @@ -108,22 +108,20 @@ UT_TEST(test_u17_l1_production_reachable_and_consistent) ClusterPageApplyVerdict verdict; memset(&cin, 0, sizeof(cin)); - cin.rmid = 10; /* RM_HEAP_ID (census-registered shape) */ - cin.opcode = 0x10; /* XLOG_HEAP_INSERT-shaped */ + cin.rmid = 10; /* RM_HEAP_ID (census-registered shape) */ + cin.opcode = 0x10; /* XLOG_HEAP_INSERT-shaped */ cin.forknum = MAIN_FORKNUM; cin.header_owner = CLUSTER_PAGE_HEADER_OWNER_NONE; /* The probe's classify shape: a registered main-fork delta is NORMAL * only after the census wiring; without it the honest UNKNOWN. */ cls = cluster_page_classify(&cin); - UT_ASSERT(cls == CLUSTER_PAGE_CLASS_UNKNOWN - || cls == CLUSTER_PAGE_CLASS_NORMAL); + UT_ASSERT(cls == CLUSTER_PAGE_CLASS_UNKNOWN || cls == CLUSTER_PAGE_CLASS_NORMAL); /* The probe's admission shape: no VersionToken producer yet -> the * decision fails closed. */ verdict = cluster_page_version_decide(NULL, NULL, NULL, NULL); - UT_ASSERT_EQ((int) verdict, (int) CLUSTER_PAGE_APPLY_BLOCKED); + UT_ASSERT_EQ((int)verdict, (int)CLUSTER_PAGE_APPLY_BLOCKED); /* Deterministic: same inputs, same outputs (L1 cold/online). */ - UT_ASSERT_EQ((int) cluster_page_version_decide(NULL, NULL, NULL, NULL), - (int) verdict); + UT_ASSERT_EQ((int)cluster_page_version_decide(NULL, NULL, NULL, NULL), (int)verdict); } /* L3: commit cuts — TT write/fsync/terminal missing one-at-a-time keep @@ -138,8 +136,7 @@ UT_TEST(test_l3_commit_cuts_blocked_until_truth_complete) prepare.pending_durable_ok = true; prepare.tt_undo_match = true; prepare.gid_identity_match = true; - UT_ASSERT_EQ((int) cluster_side_prepared_verdict(&prepare), - (int) CLUSTER_SIDE_PREPARED_IN_DOUBT); + UT_ASSERT_EQ((int)cluster_side_prepared_verdict(&prepare), (int)CLUSTER_SIDE_PREPARED_IN_DOUBT); memset(&resolve, 0, sizeof(resolve)); resolve.terminal_redo_ok = true; @@ -164,11 +161,9 @@ UT_TEST(test_l5_prepare_restart_in_doubt) prepare.gid_identity_match = true; /* A restart with the same durable evidence keeps IN_DOUBT (never a * guessed abort). */ - UT_ASSERT_EQ((int) cluster_side_prepared_verdict(&prepare), - (int) CLUSTER_SIDE_PREPARED_IN_DOUBT); + UT_ASSERT_EQ((int)cluster_side_prepared_verdict(&prepare), (int)CLUSTER_SIDE_PREPARED_IN_DOUBT); prepare.pending_durable_ok = false; /* pending write cut */ - UT_ASSERT_EQ((int) cluster_side_prepared_verdict(&prepare), - (int) CLUSTER_SIDE_PREPARED_BLOCKED); + UT_ASSERT_EQ((int)cluster_side_prepared_verdict(&prepare), (int)CLUSTER_SIDE_PREPARED_BLOCKED); } /* L7: CLOG miss fails closed until the truth rebuild completes. */ @@ -178,13 +173,11 @@ UT_TEST(test_l7_clog_miss_fail_closed) memset(&verify, 0, sizeof(verify)); verify.canonical_truth_ok = false; - UT_ASSERT(!cluster_side_projection_verified(CLUSTER_SIDE_PROJECTION_CLOG, - &verify)); - UT_ASSERT_EQ((int) cluster_side_projection_lookup(false), - (int) CLUSTER_SIDE_PROJECTION_LOOKUP_FAIL_CLOSED); + UT_ASSERT(!cluster_side_projection_verified(CLUSTER_SIDE_PROJECTION_CLOG, &verify)); + UT_ASSERT_EQ((int)cluster_side_projection_lookup(false), + (int)CLUSTER_SIDE_PROJECTION_LOOKUP_FAIL_CLOSED); /* Rebuild from canonical truth (CLOG needs no redo retention). */ - UT_ASSERT(cluster_side_projection_rebuildable(CLUSTER_SIDE_PROJECTION_CLOG, - false, true)); + UT_ASSERT(cluster_side_projection_rebuildable(CLUSTER_SIDE_PROJECTION_CLOG, false, true)); } /* L8: MULTIXACT retire denied while the consumer still needs the redo. */ @@ -192,8 +185,7 @@ UT_TEST(test_l8_multixact_retire_denied) { /* Source not retained -> not rebuildable -> the projection cannot * survive retirement -> deny. */ - UT_ASSERT(!cluster_side_projection_rebuildable( - CLUSTER_SIDE_PROJECTION_MULTIXACT, false, true)); + UT_ASSERT(!cluster_side_projection_rebuildable(CLUSTER_SIDE_PROJECTION_MULTIXACT, false, true)); /* And the retention exporter denies on any missing post-read. */ { ClusterSideRetentionProof retention; @@ -204,16 +196,15 @@ UT_TEST(test_l8_multixact_retire_denied) retention.all_bytes_durable = true; retention.all_post_read_ok = false; retention.consumers_zero = true; - UT_ASSERT_EQ((int) cluster_side_retention_proof_ready(&retention), - (int) CLUSTER_SIDE_RETENTION_DENY_NO_POST_READ); + UT_ASSERT_EQ((int)cluster_side_retention_proof_ready(&retention), + (int)CLUSTER_SIDE_RETENTION_DENY_NO_POST_READ); } } /* L10: canonical HWM update under the ABI STOP -> mutation=0. */ UT_TEST(test_l10_hwm_stop_mutation_zero) { - UT_ASSERT(!cluster_side_space_metadata_mutation_allowed( - CLUSTER_SIDE_SPACE_HWM)); + UT_ASSERT(!cluster_side_space_metadata_mutation_allowed(CLUSTER_SIDE_SPACE_HWM)); } /* L12: recoverer death -> successor never adopts private progress. */ @@ -221,12 +212,11 @@ UT_TEST(test_l12_no_private_progress_adoption) { /* Death after the source proof: the successor re-censuses and never * adopts the predecessor-local plan (crash matrix row 2). */ - UT_ASSERT_EQ((int) cluster_page_crash_matrix_verdict( - CLUSTER_PAGE_CUT_AFTER_SOURCE_PROOF), - (int) CLUSTER_PAGE_OUTCOME_BLOCKED_SOURCE); + UT_ASSERT_EQ((int)cluster_page_crash_matrix_verdict(CLUSTER_PAGE_CUT_AFTER_SOURCE_PROOF), + (int)CLUSTER_PAGE_OUTCOME_BLOCKED_SOURCE); /* Death during the target write: STOP (no stable base). */ - UT_ASSERT_EQ((int) cluster_page_apply_midwrite_cut(), - (int) CLUSTER_PAGE_OUTCOME_STABLE_BASE_UNRESOLVED); + UT_ASSERT_EQ((int)cluster_page_apply_midwrite_cut(), + (int)CLUSTER_PAGE_OUTCOME_STABLE_BASE_UNRESOLVED); } /* L14 + L20: resource A recovered opens while B stays BLOCKED, and the @@ -263,20 +253,20 @@ UT_TEST(test_l17_retire_denied_missing_post_read) retention.all_bytes_durable = true; retention.all_post_read_ok = false; retention.consumers_zero = true; - UT_ASSERT_EQ((int) cluster_side_retention_proof_ready(&retention), - (int) CLUSTER_SIDE_RETENTION_DENY_NO_POST_READ); + UT_ASSERT_EQ((int)cluster_side_retention_proof_ready(&retention), + (int)CLUSTER_SIDE_RETENTION_DENY_NO_POST_READ); /* Complete proof -> ready (the ROOT caller still owns the removal). */ retention.all_post_read_ok = true; - UT_ASSERT_EQ((int) cluster_side_retention_proof_ready(&retention), - (int) CLUSTER_SIDE_RETENTION_READY); + UT_ASSERT_EQ((int)cluster_side_retention_proof_ready(&retention), + (int)CLUSTER_SIDE_RETENTION_READY); } /* L18: the stable-base unresolved fixture must report STOP — never a * skip, never a forced green. */ UT_TEST(test_l18_stable_base_never_green) { - UT_ASSERT_EQ((int) cluster_page_apply_midwrite_cut(), - (int) CLUSTER_PAGE_OUTCOME_STABLE_BASE_UNRESOLVED); + UT_ASSERT_EQ((int)cluster_page_apply_midwrite_cut(), + (int)CLUSTER_PAGE_OUTCOME_STABLE_BASE_UNRESOLVED); } /* L19: same identity/version, different bytes / opposite terminal diff --git a/src/test/cluster_unit/test_cluster_side_online_owner.c b/src/test/cluster_unit/test_cluster_side_online_owner.c index a99617a39fe..50cb0122672 100644 --- a/src/test/cluster_unit/test_cluster_side_online_owner.c +++ b/src/test/cluster_unit/test_cluster_side_online_owner.c @@ -13,13 +13,13 @@ UT_DEFINE_GLOBALS(); void ExceptionalCondition(const char *condition_name pg_attribute_unused(), - const char *file_name pg_attribute_unused(), int line_number pg_attribute_unused()) + const char *file_name pg_attribute_unused(), + int line_number pg_attribute_unused()) { abort(); } -typedef struct OwnerCapture -{ +typedef struct OwnerCapture { uint32 plan_operation_count; uint32 authority_calls; uint32 authority_fail_call; @@ -45,11 +45,10 @@ rf_side_online_plan_operation_count_v1(const RfSideOnlinePlanV1 *plan) static bool fresh_authority(void *arg) { - OwnerCapture *state = (OwnerCapture *) arg; + OwnerCapture *state = (OwnerCapture *)arg; state->authority_calls++; - return state->authority_fail_call == 0 || - state->authority_calls != state->authority_fail_call; + return state->authority_fail_call == 0 || state->authority_calls != state->authority_fail_call; } void @@ -65,9 +64,8 @@ cluster_remote_xact_online_writer_pop(void) } bool -rf_side_online_projection_owner_init_v1( - RfSideOnlineProjectionOwnerV1 *owner, uint32 cluster_epoch, - bool failed_origin_redo_retained) +rf_side_online_projection_owner_init_v1(RfSideOnlineProjectionOwnerV1 *owner, uint32 cluster_epoch, + bool failed_origin_redo_retained) { memset(owner, 0, sizeof(*owner)); owner->cluster_epoch = cluster_epoch; @@ -76,70 +74,61 @@ rf_side_online_projection_owner_init_v1( } bool -rf_side_online_projection_preflight_owned_v1(void *arg, - const RfSideOnlineOperationV1 *operation) +rf_side_online_projection_preflight_owned_v1(void *arg, const RfSideOnlineOperationV1 *operation) { - RfSideOnlineProjectionOwnerV1 *projection = - (RfSideOnlineProjectionOwnerV1 *) arg; + RfSideOnlineProjectionOwnerV1 *projection = (RfSideOnlineProjectionOwnerV1 *)arg; capture.projection_preflights++; - return projection->cluster_epoch == 19 && - projection->failed_origin_redo_retained && operation != NULL && - operation->kind == RF_SIDE_ONLINE_OPERATION_PROJECTION; + return projection->cluster_epoch == 19 && projection->failed_origin_redo_retained + && operation != NULL && operation->kind == RF_SIDE_ONLINE_OPERATION_PROJECTION; } bool -rf_side_online_projection_apply_owned_v1(void *arg, - const RfSideOnlineOperationV1 *operation) +rf_side_online_projection_apply_owned_v1(void *arg, const RfSideOnlineOperationV1 *operation) { - RfSideOnlineProjectionOwnerV1 *projection = - (RfSideOnlineProjectionOwnerV1 *) arg; + RfSideOnlineProjectionOwnerV1 *projection = (RfSideOnlineProjectionOwnerV1 *)arg; capture.projection_applies++; - return projection->cluster_epoch == 19 && operation != NULL && - operation->kind == RF_SIDE_ONLINE_OPERATION_PROJECTION; + return projection->cluster_epoch == 19 && operation != NULL + && operation->kind == RF_SIDE_ONLINE_OPERATION_PROJECTION; } RfSideXactApplyResultV1 -rf_side_xact_target_preflight_owned_v1( - const RfSideXactOperationV1 *operation, const uint8 *owned_payload, - uint32 owned_payload_length) +rf_side_xact_target_preflight_owned_v1(const RfSideXactOperationV1 *operation, + const uint8 *owned_payload, uint32 owned_payload_length) { capture.xact_preflights++; - return operation != NULL && owned_payload == NULL && - owned_payload_length == 0 ? RF_SIDE_XACT_APPLY_OK : - RF_SIDE_XACT_APPLY_BLOCKED; + return operation != NULL && owned_payload == NULL && owned_payload_length == 0 + ? RF_SIDE_XACT_APPLY_OK + : RF_SIDE_XACT_APPLY_BLOCKED; } RfSideXactApplyResultV1 -rf_side_xact_apply_owned_v1(const RfSideXactOperationV1 *operation, - const uint8 *owned_payload, uint32 owned_payload_length) +rf_side_xact_apply_owned_v1(const RfSideXactOperationV1 *operation, const uint8 *owned_payload, + uint32 owned_payload_length) { capture.xact_applies++; - return operation != NULL && owned_payload == NULL && - owned_payload_length == 0 ? RF_SIDE_XACT_APPLY_OK : - RF_SIDE_XACT_APPLY_BLOCKED; + return operation != NULL && owned_payload == NULL && owned_payload_length == 0 + ? RF_SIDE_XACT_APPLY_OK + : RF_SIDE_XACT_APPLY_BLOCKED; } ClusterUndoTargetPreflightV1 cluster_undo_preflight_tt_target_v1(const ClusterUndoDecoded *decoded) { capture.undo_preflights++; - return decoded != NULL ? CLUSTER_UNDO_TARGET_APPLY : - CLUSTER_UNDO_TARGET_BLOCKED; + return decoded != NULL ? CLUSTER_UNDO_TARGET_APPLY : CLUSTER_UNDO_TARGET_BLOCKED; } ClusterUndoApplyResultV1 cluster_undo_apply_tt_v1(const ClusterUndoDecoded *decoded) { capture.undo_applies++; - return decoded != NULL ? CLUSTER_UNDO_APPLY_OK : - CLUSTER_UNDO_APPLY_BLOCKED; + return decoded != NULL ? CLUSTER_UNDO_APPLY_OK : CLUSTER_UNDO_APPLY_BLOCKED; } RfPageProofDetailV1 -rf_side_online_plan_preflight_v1(const RfSideOnlinePlanV1 *plan, - const RfSideOnlineApplyOpsV1 *ops) +rf_side_online_plan_preflight_v1(const RfSideOnlinePlanV1 *plan, const RfSideOnlineApplyOpsV1 *ops) { RfSideOnlineOperationV1 operations[3]; uint32 i; @@ -151,15 +140,12 @@ rf_side_online_plan_preflight_v1(const RfSideOnlinePlanV1 *plan, operations[2].kind = RF_SIDE_ONLINE_OPERATION_PROJECTION; if (!ops->begin_protected_set(ops->arg)) return RF_PAGE_PROOF_DETAIL_SIDE_INCOMPLETE; - for (i = 0; i < 3; i++) - { - bool accepted = i == 0 ? ops->preflight_xact(ops->arg, - &operations[i]) : i == 1 ? ops->preflight_undo(ops->arg, - &operations[i]) : ops->preflight_projection(ops->arg, - &operations[i]); - - if (!accepted) - { + for (i = 0; i < 3; i++) { + bool accepted = i == 0 ? ops->preflight_xact(ops->arg, &operations[i]) + : i == 1 ? ops->preflight_undo(ops->arg, &operations[i]) + : ops->preflight_projection(ops->arg, &operations[i]); + + if (!accepted) { ops->end_protected_set(ops->arg, false); return RF_PAGE_PROOF_DETAIL_SIDE_INCOMPLETE; } @@ -169,8 +155,7 @@ rf_side_online_plan_preflight_v1(const RfSideOnlinePlanV1 *plan, } RfPageProofDetailV1 -rf_side_online_plan_apply_v1(const RfSideOnlinePlanV1 *plan, - const RfSideOnlineApplyOpsV1 *ops) +rf_side_online_plan_apply_v1(const RfSideOnlinePlanV1 *plan, const RfSideOnlineApplyOpsV1 *ops) { RfSideOnlineOperationV1 operations[3]; uint32 i; @@ -184,28 +169,22 @@ rf_side_online_plan_apply_v1(const RfSideOnlinePlanV1 *plan, operations[2].kind = RF_SIDE_ONLINE_OPERATION_PROJECTION; if (!ops->begin_protected_set(ops->arg)) return RF_PAGE_PROOF_DETAIL_SIDE_INCOMPLETE; - for (i = 0; i < 3; i++) - { - bool accepted = i == 0 ? ops->preflight_xact(ops->arg, - &operations[i]) : i == 1 ? ops->preflight_undo(ops->arg, - &operations[i]) : ops->preflight_projection(ops->arg, - &operations[i]); - - if (!accepted) - { + for (i = 0; i < 3; i++) { + bool accepted = i == 0 ? ops->preflight_xact(ops->arg, &operations[i]) + : i == 1 ? ops->preflight_undo(ops->arg, &operations[i]) + : ops->preflight_projection(ops->arg, &operations[i]); + + if (!accepted) { ops->end_protected_set(ops->arg, false); return RF_PAGE_PROOF_DETAIL_SIDE_INCOMPLETE; } } - for (i = 0; i < 3; i++) - { - bool applied = i == 0 ? ops->apply_xact(ops->arg, - &operations[i]) : i == 1 ? ops->apply_undo(ops->arg, - &operations[i]) : ops->apply_projection(ops->arg, - &operations[i]); - - if (!applied) - { + for (i = 0; i < 3; i++) { + bool applied = i == 0 ? ops->apply_xact(ops->arg, &operations[i]) + : i == 1 ? ops->apply_undo(ops->arg, &operations[i]) + : ops->apply_projection(ops->arg, &operations[i]); + + if (!applied) { ops->end_protected_set(ops->arg, false); return RF_PAGE_PROOF_DETAIL_SIDE_INCOMPLETE; } @@ -217,14 +196,12 @@ rf_side_online_plan_apply_v1(const RfSideOnlinePlanV1 *plan, UT_TEST(test_owner_runs_all_preflights_before_fresh_gated_mutations) { RfSideOnlineProductionOwnerV1 owner; - RfSideOnlinePlanV1 *plan = (RfSideOnlinePlanV1 *) (uintptr_t) 1; + RfSideOnlinePlanV1 *plan = (RfSideOnlinePlanV1 *)(uintptr_t)1; memset(&capture, 0, sizeof(capture)); capture.plan_operation_count = 3; - UT_ASSERT(rf_side_online_production_owner_init_v1(&owner, &capture, - fresh_authority, 19, true)); - UT_ASSERT_EQ(rf_side_online_production_preflight_v1(plan, &owner), - RF_PAGE_PROOF_DETAIL_OK); + UT_ASSERT(rf_side_online_production_owner_init_v1(&owner, &capture, fresh_authority, 19, true)); + UT_ASSERT_EQ(rf_side_online_production_preflight_v1(plan, &owner), RF_PAGE_PROOF_DETAIL_OK); UT_ASSERT_EQ(capture.authority_calls, 4); UT_ASSERT_EQ(capture.pushes, 1); UT_ASSERT_EQ(capture.pops, 1); @@ -233,8 +210,7 @@ UT_TEST(test_owner_runs_all_preflights_before_fresh_gated_mutations) UT_ASSERT_EQ(capture.projection_applies, 0); memset(&capture, 0, sizeof(capture)); capture.plan_operation_count = 3; - UT_ASSERT_EQ(rf_side_online_production_apply_v1(plan, &owner), - RF_PAGE_PROOF_DETAIL_OK); + UT_ASSERT_EQ(rf_side_online_production_apply_v1(plan, &owner), RF_PAGE_PROOF_DETAIL_OK); UT_ASSERT_EQ(capture.authority_calls, 8); UT_ASSERT_EQ(capture.pushes, 1); UT_ASSERT_EQ(capture.pops, 1); @@ -250,15 +226,14 @@ UT_TEST(test_owner_runs_all_preflights_before_fresh_gated_mutations) UT_TEST(test_stale_authority_before_first_mutation_closes_whole_set) { RfSideOnlineProductionOwnerV1 owner; - RfSideOnlinePlanV1 *plan = (RfSideOnlinePlanV1 *) (uintptr_t) 1; + RfSideOnlinePlanV1 *plan = (RfSideOnlinePlanV1 *)(uintptr_t)1; memset(&capture, 0, sizeof(capture)); capture.plan_operation_count = 3; capture.authority_fail_call = 5; - UT_ASSERT(rf_side_online_production_owner_init_v1(&owner, &capture, - fresh_authority, 19, true)); + UT_ASSERT(rf_side_online_production_owner_init_v1(&owner, &capture, fresh_authority, 19, true)); UT_ASSERT_EQ(rf_side_online_production_apply_v1(plan, &owner), - RF_PAGE_PROOF_DETAIL_SIDE_INCOMPLETE); + RF_PAGE_PROOF_DETAIL_SIDE_INCOMPLETE); UT_ASSERT_EQ(capture.xact_preflights, 1); UT_ASSERT_EQ(capture.undo_preflights, 1); UT_ASSERT_EQ(capture.projection_preflights, 1); @@ -273,13 +248,11 @@ UT_TEST(test_stale_authority_before_first_mutation_closes_whole_set) UT_TEST(test_empty_plan_closes_without_writer_barrier_or_mutation) { RfSideOnlineProductionOwnerV1 owner; - RfSideOnlinePlanV1 *plan = (RfSideOnlinePlanV1 *) (uintptr_t) 1; + RfSideOnlinePlanV1 *plan = (RfSideOnlinePlanV1 *)(uintptr_t)1; memset(&capture, 0, sizeof(capture)); - UT_ASSERT(rf_side_online_production_owner_init_v1(&owner, &capture, - fresh_authority, 19, true)); - UT_ASSERT_EQ(rf_side_online_production_apply_v1(plan, &owner), - RF_PAGE_PROOF_DETAIL_OK); + UT_ASSERT(rf_side_online_production_owner_init_v1(&owner, &capture, fresh_authority, 19, true)); + UT_ASSERT_EQ(rf_side_online_production_apply_v1(plan, &owner), RF_PAGE_PROOF_DETAIL_OK); UT_ASSERT_EQ(capture.authority_calls, 1); UT_ASSERT_EQ(capture.pushes, 0); UT_ASSERT_EQ(capture.pops, 0); @@ -295,14 +268,13 @@ UT_TEST(test_empty_plan_closes_without_writer_barrier_or_mutation) UT_TEST(test_empty_plan_requires_fresh_closure_authority) { RfSideOnlineProductionOwnerV1 owner; - RfSideOnlinePlanV1 *plan = (RfSideOnlinePlanV1 *) (uintptr_t) 1; + RfSideOnlinePlanV1 *plan = (RfSideOnlinePlanV1 *)(uintptr_t)1; memset(&capture, 0, sizeof(capture)); capture.authority_fail_call = 1; - UT_ASSERT(rf_side_online_production_owner_init_v1(&owner, &capture, - fresh_authority, 19, true)); + UT_ASSERT(rf_side_online_production_owner_init_v1(&owner, &capture, fresh_authority, 19, true)); UT_ASSERT_EQ(rf_side_online_production_apply_v1(plan, &owner), - RF_PAGE_PROOF_DETAIL_SIDE_INCOMPLETE); + RF_PAGE_PROOF_DETAIL_SIDE_INCOMPLETE); UT_ASSERT_EQ(capture.authority_calls, 1); UT_ASSERT_EQ(capture.pushes, 0); UT_ASSERT_EQ(capture.pops, 0); diff --git a/src/test/cluster_unit/test_cluster_side_prepared.c b/src/test/cluster_unit/test_cluster_side_prepared.c index dfe4bc7ea17..e52c586ee62 100644 --- a/src/test/cluster_unit/test_cluster_side_prepared.c +++ b/src/test/cluster_unit/test_cluster_side_prepared.c @@ -55,27 +55,21 @@ UT_TEST(test_in_doubt_conjunction) { ClusterSidePreparedInput in = ut_full_prepare(); - UT_ASSERT_EQ((int) cluster_side_prepared_verdict(&in), - (int) CLUSTER_SIDE_PREPARED_IN_DOUBT); + UT_ASSERT_EQ((int)cluster_side_prepared_verdict(&in), (int)CLUSTER_SIDE_PREPARED_IN_DOUBT); /* U-SIDE-06/07: each fact one-at-a-time missing -> BLOCKED. */ in.prepare_redo_ok = false; - UT_ASSERT_EQ((int) cluster_side_prepared_verdict(&in), - (int) CLUSTER_SIDE_PREPARED_BLOCKED); + UT_ASSERT_EQ((int)cluster_side_prepared_verdict(&in), (int)CLUSTER_SIDE_PREPARED_BLOCKED); in = ut_full_prepare(); in.pending_durable_ok = false; /* origin-local/cache only: no weight */ - UT_ASSERT_EQ((int) cluster_side_prepared_verdict(&in), - (int) CLUSTER_SIDE_PREPARED_BLOCKED); + UT_ASSERT_EQ((int)cluster_side_prepared_verdict(&in), (int)CLUSTER_SIDE_PREPARED_BLOCKED); in = ut_full_prepare(); in.tt_undo_match = false; - UT_ASSERT_EQ((int) cluster_side_prepared_verdict(&in), - (int) CLUSTER_SIDE_PREPARED_BLOCKED); + UT_ASSERT_EQ((int)cluster_side_prepared_verdict(&in), (int)CLUSTER_SIDE_PREPARED_BLOCKED); in = ut_full_prepare(); in.gid_identity_match = false; /* same tx, different GID: conflict */ - UT_ASSERT_EQ((int) cluster_side_prepared_verdict(&in), - (int) CLUSTER_SIDE_PREPARED_BLOCKED); - UT_ASSERT_EQ((int) cluster_side_prepared_verdict(NULL), - (int) CLUSTER_SIDE_PREPARED_BLOCKED); + UT_ASSERT_EQ((int)cluster_side_prepared_verdict(&in), (int)CLUSTER_SIDE_PREPARED_BLOCKED); + UT_ASSERT_EQ((int)cluster_side_prepared_verdict(NULL), (int)CLUSTER_SIDE_PREPARED_BLOCKED); } UT_TEST(test_resolution_ready_conjunction) @@ -122,21 +116,21 @@ UT_TEST(test_gid_identity_leg_exact) { const char gid_ok[] = "pgrac-2pc-42"; - UT_ASSERT(cluster_side_prepared_gid_identity_ok( - gid_ok, (uint16) strlen(gid_ok), (uint32) strlen(gid_ok))); + UT_ASSERT(cluster_side_prepared_gid_identity_ok(gid_ok, (uint16)strlen(gid_ok), + (uint32)strlen(gid_ok))); /* extra available bytes are fine (GID need not end the payload) */ - UT_ASSERT(cluster_side_prepared_gid_identity_ok( - gid_ok, (uint16) strlen(gid_ok), (uint32) strlen(gid_ok) + 64)); + UT_ASSERT(cluster_side_prepared_gid_identity_ok(gid_ok, (uint16)strlen(gid_ok), + (uint32)strlen(gid_ok) + 64)); /* empty GID */ UT_ASSERT(!cluster_side_prepared_gid_identity_ok(gid_ok, 0, 128)); /* NULL GID */ UT_ASSERT(!cluster_side_prepared_gid_identity_ok(NULL, 8, 128)); /* truncated payload: GID does not fit */ - UT_ASSERT(!cluster_side_prepared_gid_identity_ok( - gid_ok, (uint16) strlen(gid_ok), (uint32) strlen(gid_ok) - 1)); + UT_ASSERT(!cluster_side_prepared_gid_identity_ok(gid_ok, (uint16)strlen(gid_ok), + (uint32)strlen(gid_ok) - 1)); /* oversize GID (the 2PC path caps at MAXPGPATH) */ - UT_ASSERT(!cluster_side_prepared_gid_identity_ok( - gid_ok, (uint16) (MAXPGPATH + 1), (uint32) (MAXPGPATH + 2))); + UT_ASSERT(!cluster_side_prepared_gid_identity_ok(gid_ok, (uint16)(MAXPGPATH + 1), + (uint32)(MAXPGPATH + 2))); /* NUL-first payload: no usable identity */ { const char empty[] = ""; diff --git a/src/test/cluster_unit/test_cluster_side_projection.c b/src/test/cluster_unit/test_cluster_side_projection.c index 4902014c913..accc5590a12 100644 --- a/src/test/cluster_unit/test_cluster_side_projection.c +++ b/src/test/cluster_unit/test_cluster_side_projection.c @@ -49,8 +49,7 @@ ut_full_verify(void) return in; } -typedef struct ProjectionApplyCapture -{ +typedef struct ProjectionApplyCapture { uint32 reset_count; uint32 postread_count; uint32 truncate_count; @@ -68,10 +67,9 @@ typedef struct ProjectionApplyCapture } ProjectionApplyCapture; static bool -capture_reset(void *arg, int origin_slot, TransactionId first_xid, - uint32 xid_count) +capture_reset(void *arg, int origin_slot, TransactionId first_xid, uint32 xid_count) { - ProjectionApplyCapture *capture = (ProjectionApplyCapture *) arg; + ProjectionApplyCapture *capture = (ProjectionApplyCapture *)arg; capture->reset_count++; capture->origin_slot = origin_slot; @@ -81,10 +79,9 @@ capture_reset(void *arg, int origin_slot, TransactionId first_xid, } static bool -capture_postread(void *arg, int origin_slot, TransactionId first_xid, - uint32 xid_count) +capture_postread(void *arg, int origin_slot, TransactionId first_xid, uint32 xid_count) { - ProjectionApplyCapture *capture = (ProjectionApplyCapture *) arg; + ProjectionApplyCapture *capture = (ProjectionApplyCapture *)arg; capture->postread_count++; UT_ASSERT_EQ(origin_slot, capture->origin_slot); @@ -96,7 +93,7 @@ capture_postread(void *arg, int origin_slot, TransactionId first_xid, static bool capture_truncate(void *arg, int origin_slot, TransactionId oldest_xid) { - ProjectionApplyCapture *capture = (ProjectionApplyCapture *) arg; + ProjectionApplyCapture *capture = (ProjectionApplyCapture *)arg; capture->truncate_count++; capture->origin_slot = origin_slot; @@ -106,12 +103,11 @@ capture_truncate(void *arg, int origin_slot, TransactionId oldest_xid) static bool capture_multixact(void *arg, int origin_slot, uint32 cluster_epoch, - const ClusterSideProjectionOperationV1 *operation, - const uint8 *owned_payload, uint32 owned_payload_length, - XLogRecPtr source_lsn, XLogRecPtr source_end_lsn) + const ClusterSideProjectionOperationV1 *operation, const uint8 *owned_payload, + uint32 owned_payload_length, XLogRecPtr source_lsn, XLogRecPtr source_end_lsn) { - ProjectionApplyCapture *capture = (ProjectionApplyCapture *) arg; - const MultiXactMember *members = (const MultiXactMember *) owned_payload; + ProjectionApplyCapture *capture = (ProjectionApplyCapture *)arg; + const MultiXactMember *members = (const MultiXactMember *)owned_payload; UT_ASSERT_EQ(origin_slot, 2); UT_ASSERT_EQ(cluster_epoch, 19); @@ -128,11 +124,11 @@ capture_multixact(void *arg, int origin_slot, uint32 cluster_epoch, static bool capture_multixact_postread(void *arg, int origin_slot, uint32 cluster_epoch, - const ClusterSideProjectionOperationV1 *operation, - const uint8 *owned_payload, uint32 owned_payload_length, - XLogRecPtr source_lsn, XLogRecPtr source_end_lsn) + const ClusterSideProjectionOperationV1 *operation, + const uint8 *owned_payload, uint32 owned_payload_length, + XLogRecPtr source_lsn, XLogRecPtr source_end_lsn) { - ProjectionApplyCapture *capture = (ProjectionApplyCapture *) arg; + ProjectionApplyCapture *capture = (ProjectionApplyCapture *)arg; UT_ASSERT_EQ(origin_slot, 2); UT_ASSERT_EQ(cluster_epoch, 19); @@ -148,61 +144,56 @@ capture_multixact_postread(void *arg, int origin_slot, uint32 cluster_epoch, static ProjectionApplyCapture owner_capture; bool -cluster_remote_xact_reset_range_v2(int origin_slot, TransactionId first_xid, - uint32 xid_count) +cluster_remote_xact_reset_range_v2(int origin_slot, TransactionId first_xid, uint32 xid_count) { return capture_reset(&owner_capture, origin_slot, first_xid, xid_count); } bool -cluster_remote_xact_range_empty_v2(int origin_slot, TransactionId first_xid, - uint32 xid_count) +cluster_remote_xact_range_empty_v2(int origin_slot, TransactionId first_xid, uint32 xid_count) { return capture_postread(&owner_capture, origin_slot, first_xid, xid_count); } bool -cluster_remote_xact_truncate_before_v2(int origin_slot, - TransactionId oldest_xid) +cluster_remote_xact_truncate_before_v2(int origin_slot, TransactionId oldest_xid) { return capture_truncate(&owner_capture, origin_slot, oldest_xid); } bool -cluster_multixact_recovery_projection_apply(void *arg, int origin_slot, - uint32 cluster_epoch, const ClusterSideProjectionOperationV1 *operation, - const uint8 *owned_payload, uint32 owned_payload_length, - XLogRecPtr source_lsn, XLogRecPtr source_end_lsn) +cluster_multixact_recovery_projection_apply(void *arg, int origin_slot, uint32 cluster_epoch, + const ClusterSideProjectionOperationV1 *operation, + const uint8 *owned_payload, uint32 owned_payload_length, + XLogRecPtr source_lsn, XLogRecPtr source_end_lsn) { UT_ASSERT(arg == NULL); - return capture_multixact(&owner_capture, origin_slot, cluster_epoch, - operation, owned_payload, owned_payload_length, source_lsn, - source_end_lsn); + return capture_multixact(&owner_capture, origin_slot, cluster_epoch, operation, owned_payload, + owned_payload_length, source_lsn, source_end_lsn); } bool -cluster_multixact_recovery_projection_verify(void *arg, int origin_slot, - uint32 cluster_epoch, const ClusterSideProjectionOperationV1 *operation, - const uint8 *owned_payload, uint32 owned_payload_length, - XLogRecPtr source_lsn, XLogRecPtr source_end_lsn) +cluster_multixact_recovery_projection_verify(void *arg, int origin_slot, uint32 cluster_epoch, + const ClusterSideProjectionOperationV1 *operation, + const uint8 *owned_payload, + uint32 owned_payload_length, XLogRecPtr source_lsn, + XLogRecPtr source_end_lsn) { UT_ASSERT(arg == NULL); - return capture_multixact_postread(&owner_capture, origin_slot, - cluster_epoch, operation, owned_payload, owned_payload_length, - source_lsn, source_end_lsn); + return capture_multixact_postread(&owner_capture, origin_slot, cluster_epoch, operation, + owned_payload, owned_payload_length, source_lsn, + source_end_lsn); } UT_TEST(test_projection_verified_conjunction) { ClusterSideProjectionVerifyInput in = ut_full_verify(); - ClusterSideProjectionKind kinds[] = { - CLUSTER_SIDE_PROJECTION_CLOG, - CLUSTER_SIDE_PROJECTION_MULTIXACT, - CLUSTER_SIDE_PROJECTION_COMMIT_TS - }; - int i; - - for (i = 0; i < (int) lengthof(kinds); i++) { + ClusterSideProjectionKind kinds[] + = { CLUSTER_SIDE_PROJECTION_CLOG, CLUSTER_SIDE_PROJECTION_MULTIXACT, + CLUSTER_SIDE_PROJECTION_COMMIT_TS }; + int i; + + for (i = 0; i < (int)lengthof(kinds); i++) { UT_ASSERT(cluster_side_projection_verified(kinds[i], &in)); in.canonical_truth_ok = false; UT_ASSERT(!cluster_side_projection_verified(kinds[i], &in)); @@ -216,50 +207,40 @@ UT_TEST(test_projection_verified_conjunction) } UT_ASSERT(!cluster_side_projection_verified(CLUSTER_SIDE_PROJECTION_CLOG, NULL)); /* Out-of-range kind fails closed. */ - UT_ASSERT(!cluster_side_projection_verified((ClusterSideProjectionKind) 99, - &in)); + UT_ASSERT(!cluster_side_projection_verified((ClusterSideProjectionKind)99, &in)); } UT_TEST(test_projection_lookup_fail_closed) { /* A miss/UNKNOWN projection NEVER answers from a local guess * (U-SIDE-08: local bit cannot override TT/redo truth). */ - UT_ASSERT_EQ((int) cluster_side_projection_lookup(false), - (int) CLUSTER_SIDE_PROJECTION_LOOKUP_FAIL_CLOSED); - UT_ASSERT_EQ((int) cluster_side_projection_lookup(true), - (int) CLUSTER_SIDE_PROJECTION_LOOKUP_OK); + UT_ASSERT_EQ((int)cluster_side_projection_lookup(false), + (int)CLUSTER_SIDE_PROJECTION_LOOKUP_FAIL_CLOSED); + UT_ASSERT_EQ((int)cluster_side_projection_lookup(true), (int)CLUSTER_SIDE_PROJECTION_LOOKUP_OK); } UT_TEST(test_projection_rebuildable_per_kind) { /* CLOG rebuilds from the canonical transaction truth: no redo * retention required. */ - UT_ASSERT(cluster_side_projection_rebuildable(CLUSTER_SIDE_PROJECTION_CLOG, - false, true)); + UT_ASSERT(cluster_side_projection_rebuildable(CLUSTER_SIDE_PROJECTION_CLOG, false, true)); /* MULTIXACT / COMMIT_TS rebuild from the retained redo: the source * must still be retained (U-SIDE-09/10). L9: a COMMIT_TS projection * loss or unknown timestamp never changes the commit truth — the * rebuild needs the source redo retained and the lookup fails * closed until it is. */ - UT_ASSERT(cluster_side_projection_rebuildable(CLUSTER_SIDE_PROJECTION_MULTIXACT, - true, true)); - UT_ASSERT(!cluster_side_projection_rebuildable(CLUSTER_SIDE_PROJECTION_MULTIXACT, - false, true)); - UT_ASSERT(cluster_side_projection_rebuildable(CLUSTER_SIDE_PROJECTION_COMMIT_TS, - true, true)); - UT_ASSERT(!cluster_side_projection_rebuildable(CLUSTER_SIDE_PROJECTION_COMMIT_TS, - false, true)); + UT_ASSERT(cluster_side_projection_rebuildable(CLUSTER_SIDE_PROJECTION_MULTIXACT, true, true)); + UT_ASSERT(!cluster_side_projection_rebuildable(CLUSTER_SIDE_PROJECTION_MULTIXACT, false, true)); + UT_ASSERT(cluster_side_projection_rebuildable(CLUSTER_SIDE_PROJECTION_COMMIT_TS, true, true)); + UT_ASSERT(!cluster_side_projection_rebuildable(CLUSTER_SIDE_PROJECTION_COMMIT_TS, false, true)); /* Every rebuild needs the verified canonical producer — without it, * the rebuild is a guess and the resource stays BLOCKED. */ - UT_ASSERT(!cluster_side_projection_rebuildable(CLUSTER_SIDE_PROJECTION_CLOG, - false, false)); - UT_ASSERT(!cluster_side_projection_rebuildable(CLUSTER_SIDE_PROJECTION_MULTIXACT, - true, false)); + UT_ASSERT(!cluster_side_projection_rebuildable(CLUSTER_SIDE_PROJECTION_CLOG, false, false)); + UT_ASSERT(!cluster_side_projection_rebuildable(CLUSTER_SIDE_PROJECTION_MULTIXACT, true, false)); /* Out-of-range kind fails closed. */ - UT_ASSERT(!cluster_side_projection_rebuildable((ClusterSideProjectionKind) 99, - true, true)); + UT_ASSERT(!cluster_side_projection_rebuildable((ClusterSideProjectionKind)99, true, true)); } UT_TEST(test_projection_zero_range_preflight_and_postread) @@ -277,7 +258,7 @@ UT_TEST(test_projection_zero_range_preflight_and_postread) input.operation = &operation; input.origin_thread = 3; UT_ASSERT_EQ(cluster_side_projection_target_preflight_v1(&input), - CLUSTER_SIDE_PROJECTION_APPLY_OK); + CLUSTER_SIDE_PROJECTION_APPLY_OK); memset(&capture, 0, sizeof(capture)); capture.reset_ok = true; capture.postread_ok = true; @@ -287,7 +268,7 @@ UT_TEST(test_projection_zero_range_preflight_and_postread) ops.remote_xact_range_empty = capture_postread; ops.truncate_remote_xact_before = capture_truncate; UT_ASSERT_EQ(cluster_side_projection_apply_owned_v1(&input, &ops), - CLUSTER_SIDE_PROJECTION_APPLY_OK); + CLUSTER_SIDE_PROJECTION_APPLY_OK); UT_ASSERT_EQ(capture.reset_count, 1); UT_ASSERT_EQ(capture.postread_count, 1); UT_ASSERT_EQ(capture.origin_slot, 2); @@ -296,7 +277,7 @@ UT_TEST(test_projection_zero_range_preflight_and_postread) capture.postread_ok = false; UT_ASSERT_EQ(cluster_side_projection_apply_owned_v1(&input, &ops), - CLUSTER_SIDE_PROJECTION_APPLY_POST_READ_FAILED); + CLUSTER_SIDE_PROJECTION_APPLY_POST_READ_FAILED); UT_ASSERT_EQ(capture.reset_count, 2); UT_ASSERT_EQ(capture.postread_count, 2); } @@ -317,10 +298,10 @@ UT_TEST(test_projection_commit_ts_requires_retained_source_and_truncates) input.operation = &operation; input.origin_thread = 3; UT_ASSERT_EQ(cluster_side_projection_target_preflight_v1(&input), - CLUSTER_SIDE_PROJECTION_APPLY_BLOCKED); + CLUSTER_SIDE_PROJECTION_APPLY_BLOCKED); input.source_retained = true; UT_ASSERT_EQ(cluster_side_projection_target_preflight_v1(&input), - CLUSTER_SIDE_PROJECTION_APPLY_OK); + CLUSTER_SIDE_PROJECTION_APPLY_OK); memset(&capture, 0, sizeof(capture)); capture.truncate_ok = true; memset(&ops, 0, sizeof(ops)); @@ -329,7 +310,7 @@ UT_TEST(test_projection_commit_ts_requires_retained_source_and_truncates) ops.remote_xact_range_empty = capture_postread; ops.truncate_remote_xact_before = capture_truncate; UT_ASSERT_EQ(cluster_side_projection_apply_owned_v1(&input, &ops), - CLUSTER_SIDE_PROJECTION_APPLY_OK); + CLUSTER_SIDE_PROJECTION_APPLY_OK); UT_ASSERT_EQ(capture.truncate_count, 1); UT_ASSERT_EQ(capture.origin_slot, 2); UT_ASSERT_EQ(capture.oldest_xid, 800); @@ -358,17 +339,17 @@ UT_TEST(test_projection_multixact_requires_retained_exact_source_and_postread) members[1].status = MultiXactStatusUpdate; memset(&input, 0, sizeof(input)); input.operation = &operation; - input.owned_payload = (const uint8 *) members; + input.owned_payload = (const uint8 *)members; input.owned_payload_length = sizeof(members); input.origin_thread = 3; input.cluster_epoch = 19; input.source_lsn = 100; input.source_end_lsn = 200; UT_ASSERT_EQ(cluster_side_projection_target_preflight_v1(&input), - CLUSTER_SIDE_PROJECTION_APPLY_BLOCKED); + CLUSTER_SIDE_PROJECTION_APPLY_BLOCKED); input.source_retained = true; UT_ASSERT_EQ(cluster_side_projection_target_preflight_v1(&input), - CLUSTER_SIDE_PROJECTION_APPLY_OK); + CLUSTER_SIDE_PROJECTION_APPLY_OK); memset(&capture, 0, sizeof(capture)); capture.multixact_mutate_ok = true; capture.multixact_verify_ok = true; @@ -377,12 +358,12 @@ UT_TEST(test_projection_multixact_requires_retained_exact_source_and_postread) ops.apply_multixact_projection = capture_multixact; ops.verify_multixact_projection = capture_multixact_postread; UT_ASSERT_EQ(cluster_side_projection_apply_owned_v1(&input, &ops), - CLUSTER_SIDE_PROJECTION_APPLY_OK); + CLUSTER_SIDE_PROJECTION_APPLY_OK); UT_ASSERT_EQ(capture.multixact_mutate_count, 1); UT_ASSERT_EQ(capture.multixact_verify_count, 1); capture.multixact_verify_ok = false; UT_ASSERT_EQ(cluster_side_projection_apply_owned_v1(&input, &ops), - CLUSTER_SIDE_PROJECTION_APPLY_POST_READ_FAILED); + CLUSTER_SIDE_PROJECTION_APPLY_POST_READ_FAILED); } UT_TEST(test_online_owner_wires_retained_source_identity_and_real_callbacks) @@ -407,22 +388,20 @@ UT_TEST(test_online_owner_wires_retained_source_identity_and_real_callbacks) members[0].status = MultiXactStatusForKeyShare; members[1].xid = 816; members[1].status = MultiXactStatusUpdate; - operation.owned_payload = (const uint8 *) members; + operation.owned_payload = (const uint8 *)members; operation.owned_payload_length = sizeof(members); UT_ASSERT(rf_side_online_projection_owner_init_v1(&owner, 19, true)); memset(&owner_capture, 0, sizeof(owner_capture)); owner_capture.multixact_mutate_ok = true; owner_capture.multixact_verify_ok = true; - UT_ASSERT(rf_side_online_projection_preflight_owned_v1(&owner, - &operation)); + UT_ASSERT(rf_side_online_projection_preflight_owned_v1(&owner, &operation)); UT_ASSERT(rf_side_online_projection_apply_owned_v1(&owner, &operation)); UT_ASSERT_EQ(owner_capture.multixact_mutate_count, 1); UT_ASSERT_EQ(owner_capture.multixact_verify_count, 1); UT_ASSERT(rf_side_online_projection_owner_init_v1(&owner, 19, false)); - UT_ASSERT(!rf_side_online_projection_preflight_owned_v1(&owner, - &operation)); + UT_ASSERT(!rf_side_online_projection_preflight_owned_v1(&owner, &operation)); operation.kind = RF_SIDE_ONLINE_OPERATION_XACT; UT_ASSERT(!rf_side_online_projection_apply_owned_v1(&owner, &operation)); } diff --git a/src/test/cluster_unit/test_cluster_side_recovery.c b/src/test/cluster_unit/test_cluster_side_recovery.c index ef5acb6afbb..8d33ee87e75 100644 --- a/src/test/cluster_unit/test_cluster_side_recovery.c +++ b/src/test/cluster_unit/test_cluster_side_recovery.c @@ -52,7 +52,7 @@ ut_setup_globals(void) ut_id.rlocator.dbOid = 2; ut_id.rlocator.relNumber = 3; ut_id.forknum = MAIN_FORKNUM; - ut_id.blocknum = 7; /* a TT/undo/space canonical page */ + ut_id.blocknum = 7; /* a TT/undo/space canonical page */ memset(&ut_expected, 0, sizeof(ut_expected)); ut_expected.identity = ut_id; @@ -130,7 +130,7 @@ UT_TEST(test_side_readiness_per_resource) * readiness judgement has no side-wide state. */ memset(&b, 0, sizeof(b)); b.resource_id = 2; - b.page_proof_ok = false; /* B blocked */ + b.page_proof_ok = false; /* B blocked */ UT_ASSERT(!cluster_side_resource_readiness(&b)); UT_ASSERT(cluster_side_resource_readiness(&a)); /* A unaffected */ @@ -160,41 +160,40 @@ UT_TEST(test_side_retention_proof_verdicts) p.all_bytes_durable = true; p.all_post_read_ok = true; p.consumers_zero = true; - UT_ASSERT_EQ((int) cluster_side_retention_proof_ready(&p), - (int) CLUSTER_SIDE_RETENTION_READY); + UT_ASSERT_EQ((int)cluster_side_retention_proof_ready(&p), (int)CLUSTER_SIDE_RETENTION_READY); /* Not durable -> precise denial. */ p.all_bytes_durable = false; - UT_ASSERT_EQ((int) cluster_side_retention_proof_ready(&p), - (int) CLUSTER_SIDE_RETENTION_DENY_NOT_DURABLE); + UT_ASSERT_EQ((int)cluster_side_retention_proof_ready(&p), + (int)CLUSTER_SIDE_RETENTION_DENY_NOT_DURABLE); p.all_bytes_durable = true; /* Missing post-read -> precise denial (logical DONE never * substitutes). */ p.all_post_read_ok = false; - UT_ASSERT_EQ((int) cluster_side_retention_proof_ready(&p), - (int) CLUSTER_SIDE_RETENTION_DENY_NO_POST_READ); + UT_ASSERT_EQ((int)cluster_side_retention_proof_ready(&p), + (int)CLUSTER_SIDE_RETENTION_DENY_NO_POST_READ); p.all_post_read_ok = true; /* Remaining consumer -> precise denial. */ p.consumers_zero = false; - UT_ASSERT_EQ((int) cluster_side_retention_proof_ready(&p), - (int) CLUSTER_SIDE_RETENTION_DENY_CONSUMER); + UT_ASSERT_EQ((int)cluster_side_retention_proof_ready(&p), + (int)CLUSTER_SIDE_RETENTION_DENY_CONSUMER); p.consumers_zero = true; /* Invalid inputs. */ - UT_ASSERT_EQ((int) cluster_side_retention_proof_ready(NULL), - (int) CLUSTER_SIDE_RETENTION_DENY_INVALID); + UT_ASSERT_EQ((int)cluster_side_retention_proof_ready(NULL), + (int)CLUSTER_SIDE_RETENTION_DENY_INVALID); /* D-SIDE-08 production caller (implementation): origin_thread_id unset * (0) is the judge's fail-closed shape until the orchestrator wires * the real dead_tid — never READY with an anonymous origin. */ p.failed_origin_thread = 0; - UT_ASSERT_EQ((int) cluster_side_retention_proof_ready(&p), - (int) CLUSTER_SIDE_RETENTION_DENY_INVALID); + UT_ASSERT_EQ((int)cluster_side_retention_proof_ready(&p), + (int)CLUSTER_SIDE_RETENTION_DENY_INVALID); p.failed_origin_thread = 2; p.affected_count = 0; - UT_ASSERT_EQ((int) cluster_side_retention_proof_ready(&p), - (int) CLUSTER_SIDE_RETENTION_DENY_INVALID); + UT_ASSERT_EQ((int)cluster_side_retention_proof_ready(&p), + (int)CLUSTER_SIDE_RETENTION_DENY_INVALID); } int diff --git a/src/test/cluster_unit/test_cluster_side_route.c b/src/test/cluster_unit/test_cluster_side_route.c index aadd8a90cc7..b4c17ab02c9 100644 --- a/src/test/cluster_unit/test_cluster_side_route.c +++ b/src/test/cluster_unit/test_cluster_side_route.c @@ -50,61 +50,60 @@ UT_TEST(test_route_matrix_named_rows) /* XLOG: FPI -> PAGE; control-only -> PROVED_NOOP; control -> BLOCKED. */ UT_ASSERT(cluster_side_route_lookup(RM_XLOG_ID, XLOG_FPI, &row)); - UT_ASSERT_EQ((int) row.kind, (int) CLUSTER_SIDE_ROUTE_PAGE); + UT_ASSERT_EQ((int)row.kind, (int)CLUSTER_SIDE_ROUTE_PAGE); UT_ASSERT(cluster_side_route_lookup(RM_XLOG_ID, XLOG_NOOP, &row)); - UT_ASSERT_EQ((int) row.kind, (int) CLUSTER_SIDE_ROUTE_PROVED_NOOP); - UT_ASSERT_EQ((int) cluster_side_route_verdict(&row), - (int) CLUSTER_SIDE_ROUTE_VERDICT_PROVED_NOOP); + UT_ASSERT_EQ((int)row.kind, (int)CLUSTER_SIDE_ROUTE_PROVED_NOOP); + UT_ASSERT_EQ((int)cluster_side_route_verdict(&row), + (int)CLUSTER_SIDE_ROUTE_VERDICT_PROVED_NOOP); UT_ASSERT(cluster_side_route_lookup(RM_XLOG_ID, XLOG_CHECKPOINT_SHUTDOWN, &row)); - UT_ASSERT_EQ((int) row.kind, (int) CLUSTER_SIDE_ROUTE_BLOCKED); + UT_ASSERT_EQ((int)row.kind, (int)CLUSTER_SIDE_ROUTE_BLOCKED); /* XACT: commit/abort/prepare -> TT/undo truth; the HAS_INFO modifier * does not change the row (masked). */ UT_ASSERT(cluster_side_route_lookup(RM_XACT_ID, XLOG_XACT_COMMIT, &row)); - UT_ASSERT_EQ((int) row.kind, (int) CLUSTER_SIDE_ROUTE_TT_UNDO); + UT_ASSERT_EQ((int)row.kind, (int)CLUSTER_SIDE_ROUTE_TT_UNDO); UT_ASSERT(cluster_side_route_lookup(RM_XACT_ID, XLOG_XACT_ABORT, &row)); - UT_ASSERT_EQ((int) row.kind, (int) CLUSTER_SIDE_ROUTE_TT_UNDO); + UT_ASSERT_EQ((int)row.kind, (int)CLUSTER_SIDE_ROUTE_TT_UNDO); UT_ASSERT(cluster_side_route_lookup(RM_XACT_ID, XLOG_XACT_PREPARE, &row)); - UT_ASSERT_EQ((int) row.kind, (int) CLUSTER_SIDE_ROUTE_TT_UNDO); + UT_ASSERT_EQ((int)row.kind, (int)CLUSTER_SIDE_ROUTE_TT_UNDO); UT_ASSERT(cluster_side_route_lookup(RM_XACT_ID, XLOG_XACT_COMMIT_PREPARED, &row)); - UT_ASSERT_EQ((int) row.kind, (int) CLUSTER_SIDE_ROUTE_TT_UNDO); + UT_ASSERT_EQ((int)row.kind, (int)CLUSTER_SIDE_ROUTE_TT_UNDO); UT_ASSERT(cluster_side_route_lookup(RM_XACT_ID, XLOG_XACT_ABORT_PREPARED, &row)); - UT_ASSERT_EQ((int) row.kind, (int) CLUSTER_SIDE_ROUTE_TT_UNDO); + UT_ASSERT_EQ((int)row.kind, (int)CLUSTER_SIDE_ROUTE_TT_UNDO); UT_ASSERT(cluster_side_route_lookup(RM_XACT_ID, XLOG_XACT_ASSIGNMENT, &row)); - UT_ASSERT_EQ((int) row.kind, (int) CLUSTER_SIDE_ROUTE_TT_UNDO); + UT_ASSERT_EQ((int)row.kind, (int)CLUSTER_SIDE_ROUTE_TT_UNDO); UT_ASSERT(cluster_side_route_lookup(RM_XACT_ID, XLOG_XACT_INVALIDATIONS, &row)); - UT_ASSERT_EQ((int) row.kind, (int) CLUSTER_SIDE_ROUTE_BLOCKED); + UT_ASSERT_EQ((int)row.kind, (int)CLUSTER_SIDE_ROUTE_BLOCKED); /* SMGR lifecycle -> STORAGE. */ UT_ASSERT(cluster_side_route_lookup(RM_SMGR_ID, XLOG_SMGR_CREATE, &row)); - UT_ASSERT_EQ((int) row.kind, (int) CLUSTER_SIDE_ROUTE_STORAGE); + UT_ASSERT_EQ((int)row.kind, (int)CLUSTER_SIDE_ROUTE_STORAGE); /* CLOG / COMMIT_TS / MULTIXACT -> derived projection. */ UT_ASSERT(cluster_side_route_lookup(RM_CLOG_ID, CLOG_ZEROPAGE, &row)); - UT_ASSERT_EQ((int) row.kind, (int) CLUSTER_SIDE_ROUTE_PROJECTION); + UT_ASSERT_EQ((int)row.kind, (int)CLUSTER_SIDE_ROUTE_PROJECTION); UT_ASSERT(cluster_side_route_lookup(RM_COMMIT_TS_ID, COMMIT_TS_TRUNCATE, &row)); - UT_ASSERT_EQ((int) row.kind, (int) CLUSTER_SIDE_ROUTE_PROJECTION); + UT_ASSERT_EQ((int)row.kind, (int)CLUSTER_SIDE_ROUTE_PROJECTION); /* STANDBY: no standby consumer in the physical primary -> no-op. */ UT_ASSERT(cluster_side_route_lookup(RM_STANDBY_ID, XLOG_STANDBY_LOCK, &row)); - UT_ASSERT_EQ((int) row.kind, (int) CLUSTER_SIDE_ROUTE_PROVED_NOOP); + UT_ASSERT_EQ((int)row.kind, (int)CLUSTER_SIDE_ROUTE_PROVED_NOOP); /* Page family -> PAGE. */ UT_ASSERT(cluster_side_route_lookup(RM_HEAP_ID, 0x10, &row)); - UT_ASSERT_EQ((int) row.kind, (int) CLUSTER_SIDE_ROUTE_PAGE); + UT_ASSERT_EQ((int)row.kind, (int)CLUSTER_SIDE_ROUTE_PAGE); UT_ASSERT(cluster_side_route_lookup(RM_BTREE_ID, 0, &row)); - UT_ASSERT_EQ((int) row.kind, (int) CLUSTER_SIDE_ROUTE_PAGE); + UT_ASSERT_EQ((int)row.kind, (int)CLUSTER_SIDE_ROUTE_PAGE); /* Cluster undo truth; HWM stays BLOCKED (STOP-RF-SIDE-SPACE-ABI). */ UT_ASSERT(cluster_side_route_lookup(RM_CLUSTER_UNDO_ID, XLOG_UNDO_TT_SLOT_BIND, &row)); - UT_ASSERT_EQ((int) row.kind, (int) CLUSTER_SIDE_ROUTE_TT_UNDO); + UT_ASSERT_EQ((int)row.kind, (int)CLUSTER_SIDE_ROUTE_TT_UNDO); UT_ASSERT(cluster_side_route_lookup(RM_CLUSTER_UNDO_ID, XLOG_UNDO_TT_SLOT_COMMIT, &row)); - UT_ASSERT_EQ((int) row.kind, (int) CLUSTER_SIDE_ROUTE_TT_UNDO); - UT_ASSERT(cluster_side_route_lookup(RM_CLUSTER_UNDO_ID, - XLOG_UNDO_TT_SLOT_CTRC_RELEASE, &row)); - UT_ASSERT_EQ((int) row.kind, (int) CLUSTER_SIDE_ROUTE_TT_UNDO); + UT_ASSERT_EQ((int)row.kind, (int)CLUSTER_SIDE_ROUTE_TT_UNDO); + UT_ASSERT(cluster_side_route_lookup(RM_CLUSTER_UNDO_ID, XLOG_UNDO_TT_SLOT_CTRC_RELEASE, &row)); + UT_ASSERT_EQ((int)row.kind, (int)CLUSTER_SIDE_ROUTE_TT_UNDO); UT_ASSERT(cluster_side_route_lookup(RM_CLUSTER_UNDO_ID, XLOG_HW_RESERVE, &row)); - UT_ASSERT_EQ((int) row.kind, (int) CLUSTER_SIDE_ROUTE_BLOCKED); + UT_ASSERT_EQ((int)row.kind, (int)CLUSTER_SIDE_ROUTE_BLOCKED); } UT_TEST(test_route_unknown_default_blocked) @@ -118,8 +117,7 @@ UT_TEST(test_route_unknown_default_blocked) /* NULL out. */ UT_ASSERT(!cluster_side_route_lookup(RM_XLOG_ID, XLOG_FPI, NULL)); /* NULL row -> BLOCKED verdict. */ - UT_ASSERT_EQ((int) cluster_side_route_verdict(NULL), - (int) CLUSTER_SIDE_ROUTE_VERDICT_BLOCKED); + UT_ASSERT_EQ((int)cluster_side_route_verdict(NULL), (int)CLUSTER_SIDE_ROUTE_VERDICT_BLOCKED); } UT_TEST(test_route_verdict_pure_cold_online_agree) @@ -130,55 +128,47 @@ UT_TEST(test_route_verdict_pure_cold_online_agree) * input exists, so cold and online produce the identical verdict for * the same record (U-SIDE-02). Exercise the full verdict mapping. */ UT_ASSERT(cluster_side_route_lookup(RM_HEAP_ID, 0x10, &row)); - UT_ASSERT_EQ((int) cluster_side_route_verdict(&row), - (int) CLUSTER_SIDE_ROUTE_VERDICT_APPLY); + UT_ASSERT_EQ((int)cluster_side_route_verdict(&row), (int)CLUSTER_SIDE_ROUTE_VERDICT_APPLY); UT_ASSERT(cluster_side_route_lookup(RM_XACT_ID, XLOG_XACT_COMMIT, &row)); - UT_ASSERT_EQ((int) cluster_side_route_verdict(&row), - (int) CLUSTER_SIDE_ROUTE_VERDICT_APPLY); + UT_ASSERT_EQ((int)cluster_side_route_verdict(&row), (int)CLUSTER_SIDE_ROUTE_VERDICT_APPLY); UT_ASSERT(cluster_side_route_lookup(RM_XLOG_ID, XLOG_BACKUP_END, &row)); - UT_ASSERT_EQ((int) cluster_side_route_verdict(&row), - (int) CLUSTER_SIDE_ROUTE_VERDICT_PROVED_NOOP); + UT_ASSERT_EQ((int)cluster_side_route_verdict(&row), + (int)CLUSTER_SIDE_ROUTE_VERDICT_PROVED_NOOP); UT_ASSERT(cluster_side_route_lookup(RM_XLOG_ID, XLOG_NEXTOID, &row)); - UT_ASSERT_EQ((int) cluster_side_route_verdict(&row), - (int) CLUSTER_SIDE_ROUTE_VERDICT_BLOCKED); + UT_ASSERT_EQ((int)cluster_side_route_verdict(&row), (int)CLUSTER_SIDE_ROUTE_VERDICT_BLOCKED); UT_ASSERT(cluster_side_route_lookup(RM_REPLORIGIN_ID, 0, &row)); - UT_ASSERT_EQ((int) cluster_side_route_verdict(&row), - (int) CLUSTER_SIDE_ROUTE_VERDICT_BLOCKED); + UT_ASSERT_EQ((int)cluster_side_route_verdict(&row), (int)CLUSTER_SIDE_ROUTE_VERDICT_BLOCKED); } UT_TEST(test_route_consumes_the_exhaustive_manifest) { ClusterSideRouteRow side; RfOpcodeRouteV1 route; - bool active; - size_t i; + bool active; + size_t i; UT_ASSERT_EQ(rf_opcode_route_manifest_count_v1(), 138); - for (i = 0; i < rf_opcode_route_manifest_count_v1(); i++) - { + for (i = 0; i < rf_opcode_route_manifest_count_v1(); i++) { UT_ASSERT(rf_opcode_route_manifest_entry_v1(i, &route, &active)); - UT_ASSERT(cluster_side_route_lookup(route.rmid, - route.normalized_info, &side)); + UT_ASSERT(cluster_side_route_lookup(route.rmid, route.normalized_info, &side)); UT_ASSERT_EQ(side.rmid, route.rmid); UT_ASSERT_EQ(side.opcode, route.normalized_info); if (!active) - UT_ASSERT_EQ((int) side.kind, - (int) CLUSTER_SIDE_ROUTE_BLOCKED); + UT_ASSERT_EQ((int)side.kind, (int)CLUSTER_SIDE_ROUTE_BLOCKED); } /* SIDE disposition must refine SIDE_STANDARD rows rather than letting * an rmgr-wide PAGE wildcard silently claim them. */ UT_ASSERT(cluster_side_route_lookup(RM_HEAP2_ID, 0x00, &side)); - UT_ASSERT_EQ((int) side.kind, (int) CLUSTER_SIDE_ROUTE_BLOCKED); + UT_ASSERT_EQ((int)side.kind, (int)CLUSTER_SIDE_ROUTE_BLOCKED); UT_ASSERT(cluster_side_route_lookup(RM_HEAP2_ID, 0x70, &side)); - UT_ASSERT_EQ((int) side.kind, (int) CLUSTER_SIDE_ROUTE_PROVED_NOOP); + UT_ASSERT_EQ((int)side.kind, (int)CLUSTER_SIDE_ROUTE_PROVED_NOOP); UT_ASSERT(cluster_side_route_lookup(RM_HEAP_ID, 0x30, &side)); - UT_ASSERT_EQ((int) side.kind, (int) CLUSTER_SIDE_ROUTE_BLOCKED); + UT_ASSERT_EQ((int)side.kind, (int)CLUSTER_SIDE_ROUTE_BLOCKED); UT_ASSERT(cluster_side_route_lookup(RM_GIST_ID, 0x70, &side)); - UT_ASSERT_EQ((int) side.kind, (int) CLUSTER_SIDE_ROUTE_PROVED_NOOP); - UT_ASSERT(cluster_side_route_lookup(RM_CLUSTER_UNDO_ID, - XLOG_UNDO_TT_SLOT_CTRC_RELEASE, &side)); - UT_ASSERT_EQ((int) side.kind, (int) CLUSTER_SIDE_ROUTE_TT_UNDO); + UT_ASSERT_EQ((int)side.kind, (int)CLUSTER_SIDE_ROUTE_PROVED_NOOP); + UT_ASSERT(cluster_side_route_lookup(RM_CLUSTER_UNDO_ID, XLOG_UNDO_TT_SLOT_CTRC_RELEASE, &side)); + UT_ASSERT_EQ((int)side.kind, (int)CLUSTER_SIDE_ROUTE_TT_UNDO); } int diff --git a/src/test/cluster_unit/test_cluster_side_space.c b/src/test/cluster_unit/test_cluster_side_space.c index 8b49da18c32..bb766222301 100644 --- a/src/test/cluster_unit/test_cluster_side_space.c +++ b/src/test/cluster_unit/test_cluster_side_space.c @@ -43,20 +43,20 @@ static ClusterPageVersion ut_v[3]; static void ut_setup_globals(void) { - int i; + int i; memset(&ut_id, 0, sizeof(ut_id)); ut_id.rlocator.spcOid = 1; ut_id.rlocator.dbOid = 2; ut_id.rlocator.relNumber = 3; ut_id.forknum = MAIN_FORKNUM; - ut_id.blocknum = 7; /* a canonical HWM/extent/bitmap page */ + ut_id.blocknum = 7; /* a canonical HWM/extent/bitmap page */ for (i = 0; i < 3; i++) { memset(&ut_v[i], 0, sizeof(ut_v[i])); ut_v[i].identity = ut_id; ut_v[i].incarnation = 7; - ut_v[i].token = (uint64) (100 + i); + ut_v[i].token = (uint64)(100 + i); } } @@ -65,53 +65,45 @@ UT_TEST(test_mutation_gate_always_closed) /* U-SIDE-18: STOP-RF-SIDE-SPACE-ABI cannot be overridden — the gate * is unconditionally closed for every kind, and there is no * parameter in the API that could open it. */ - UT_ASSERT(!cluster_side_space_metadata_mutation_allowed( - CLUSTER_SIDE_SPACE_HWM)); - UT_ASSERT(!cluster_side_space_metadata_mutation_allowed( - CLUSTER_SIDE_SPACE_EXTENT)); - UT_ASSERT(!cluster_side_space_metadata_mutation_allowed( - CLUSTER_SIDE_SPACE_BITMAP)); - UT_ASSERT(!cluster_side_space_metadata_mutation_allowed( - (ClusterSideSpaceKind) 99)); + UT_ASSERT(!cluster_side_space_metadata_mutation_allowed(CLUSTER_SIDE_SPACE_HWM)); + UT_ASSERT(!cluster_side_space_metadata_mutation_allowed(CLUSTER_SIDE_SPACE_EXTENT)); + UT_ASSERT(!cluster_side_space_metadata_mutation_allowed(CLUSTER_SIDE_SPACE_BITMAP)); + UT_ASSERT(!cluster_side_space_metadata_mutation_allowed((ClusterSideSpaceKind)99)); } UT_TEST(test_metadata_page_verdict_gates) { - ClusterSideSpaceKind kinds[] = { - CLUSTER_SIDE_SPACE_HWM, - CLUSTER_SIDE_SPACE_EXTENT, - CLUSTER_SIDE_SPACE_BITMAP - }; - int i; - - for (i = 0; i < (int) lengthof(kinds); i++) { + ClusterSideSpaceKind kinds[] + = { CLUSTER_SIDE_SPACE_HWM, CLUSTER_SIDE_SPACE_EXTENT, CLUSTER_SIDE_SPACE_BITMAP }; + int i; + + for (i = 0; i < (int)lengthof(kinds); i++) { ClusterSideSpaceKind kind = kinds[i]; /* U-SIDE-12: expected-before exact match -> one APPLY. */ - UT_ASSERT_EQ((int) cluster_side_space_metadata_page_verdict( - kind, &ut_v[0], &ut_v[0], &ut_v[1], NULL), - (int) CLUSTER_PAGE_APPLY_APPLY); + UT_ASSERT_EQ( + (int)cluster_side_space_metadata_page_verdict(kind, &ut_v[0], &ut_v[0], &ut_v[1], NULL), + (int)CLUSTER_PAGE_APPLY_APPLY); /* Trusted exact result -> SKIP. */ - UT_ASSERT_EQ((int) cluster_side_space_metadata_page_verdict( - kind, &ut_v[0], &ut_v[2], &ut_v[1], &ut_v[1]), - (int) CLUSTER_PAGE_APPLY_SKIP); + UT_ASSERT_EQ((int)cluster_side_space_metadata_page_verdict(kind, &ut_v[0], &ut_v[2], + &ut_v[1], &ut_v[1]), + (int)CLUSTER_PAGE_APPLY_SKIP); /* Mismatch / numeric-higher never applies nor skips. */ - UT_ASSERT_EQ((int) cluster_side_space_metadata_page_verdict( - kind, &ut_v[0], &ut_v[2], &ut_v[1], NULL), - (int) CLUSTER_PAGE_APPLY_BLOCKED); - UT_ASSERT_EQ((int) cluster_side_space_metadata_page_verdict( - kind, &ut_v[0], &ut_v[2], &ut_v[1], &ut_v[2]), - (int) CLUSTER_PAGE_APPLY_BLOCKED); + UT_ASSERT_EQ( + (int)cluster_side_space_metadata_page_verdict(kind, &ut_v[0], &ut_v[2], &ut_v[1], NULL), + (int)CLUSTER_PAGE_APPLY_BLOCKED); + UT_ASSERT_EQ((int)cluster_side_space_metadata_page_verdict(kind, &ut_v[0], &ut_v[2], + &ut_v[1], &ut_v[2]), + (int)CLUSTER_PAGE_APPLY_BLOCKED); /* Invalid inputs fail closed. */ - UT_ASSERT_EQ((int) cluster_side_space_metadata_page_verdict( - kind, NULL, &ut_v[0], &ut_v[1], NULL), - (int) CLUSTER_PAGE_APPLY_BLOCKED); + UT_ASSERT_EQ( + (int)cluster_side_space_metadata_page_verdict(kind, NULL, &ut_v[0], &ut_v[1], NULL), + (int)CLUSTER_PAGE_APPLY_BLOCKED); } /* Bad kind fails closed. */ - UT_ASSERT_EQ((int) cluster_side_space_metadata_page_verdict( - (ClusterSideSpaceKind) 99, &ut_v[0], &ut_v[0], &ut_v[1], - NULL), - (int) CLUSTER_PAGE_APPLY_BLOCKED); + UT_ASSERT_EQ((int)cluster_side_space_metadata_page_verdict((ClusterSideSpaceKind)99, &ut_v[0], + &ut_v[0], &ut_v[1], NULL), + (int)CLUSTER_PAGE_APPLY_BLOCKED); } /* STOP-07 product TDD (implementation): chain-level semantics — @@ -120,21 +112,18 @@ UT_TEST(test_metadata_page_verdict_gates) * path opens before the ABI is approved; U-SIDE-18: no override). */ UT_TEST(test_apply_verdict_never_reaches_mutation) { - ClusterSideSpaceKind kinds[] = { - CLUSTER_SIDE_SPACE_HWM, - CLUSTER_SIDE_SPACE_EXTENT, - CLUSTER_SIDE_SPACE_BITMAP - }; - int i; - - for (i = 0; i < (int) lengthof(kinds); i++) { + ClusterSideSpaceKind kinds[] + = { CLUSTER_SIDE_SPACE_HWM, CLUSTER_SIDE_SPACE_EXTENT, CLUSTER_SIDE_SPACE_BITMAP }; + int i; + + for (i = 0; i < (int)lengthof(kinds); i++) { ClusterSideSpaceKind kind = kinds[i]; /* The version gate may say APPLY (exact expected-before match) — * the mutation gate still refuses, so the chain is BLOCKED. */ - UT_ASSERT_EQ((int) cluster_side_space_metadata_page_verdict( - kind, &ut_v[0], &ut_v[0], &ut_v[1], NULL), - (int) CLUSTER_PAGE_APPLY_APPLY); + UT_ASSERT_EQ( + (int)cluster_side_space_metadata_page_verdict(kind, &ut_v[0], &ut_v[0], &ut_v[1], NULL), + (int)CLUSTER_PAGE_APPLY_APPLY); UT_ASSERT(!cluster_side_space_metadata_mutation_allowed(kind)); } } diff --git a/src/test/cluster_unit/test_cluster_side_stats.c b/src/test/cluster_unit/test_cluster_side_stats.c index db821c3dfe7..a1df3b2411f 100644 --- a/src/test/cluster_unit/test_cluster_side_stats.c +++ b/src/test/cluster_unit/test_cluster_side_stats.c @@ -37,20 +37,14 @@ static ClusterSideStats ut_stats; UT_TEST(test_counters_and_vocabulary) { - static const char *names[] = { - "cluster.side.route_applies", - "cluster.side.route_noops", - "cluster.side.route_blocked", - "cluster.side.domain_tt_undo", - "cluster.side.domain_projection", - "cluster.side.domain_storage", - "cluster.side.blocked_unknown_class", - "cluster.side.blocked_authority", - "cluster.side.rebuild_events", - "cluster.side.durability_events" - }; - int i; - int kind; + static const char *names[] + = { "cluster.side.route_applies", "cluster.side.route_noops", + "cluster.side.route_blocked", "cluster.side.domain_tt_undo", + "cluster.side.domain_projection", "cluster.side.domain_storage", + "cluster.side.blocked_unknown_class", "cluster.side.blocked_authority", + "cluster.side.rebuild_events", "cluster.side.durability_events" }; + int i; + int kind; cluster_side_stats_init(&ut_stats); @@ -71,15 +65,14 @@ UT_TEST(test_counters_and_vocabulary) UT_ASSERT_EQ(pg_atomic_read_u64(&ut_stats.domain_tt_undo), UINT64_C(1)); UT_ASSERT_EQ(pg_atomic_read_u64(&ut_stats.domain_projection), UINT64_C(1)); UT_ASSERT_EQ(pg_atomic_read_u64(&ut_stats.domain_storage), UINT64_C(1)); - UT_ASSERT_EQ(pg_atomic_read_u64(&ut_stats.blocked_unknown_class), - UINT64_C(1)); + UT_ASSERT_EQ(pg_atomic_read_u64(&ut_stats.blocked_unknown_class), UINT64_C(1)); UT_ASSERT_EQ(pg_atomic_read_u64(&ut_stats.blocked_authority), UINT64_C(1)); UT_ASSERT_EQ(pg_atomic_read_u64(&ut_stats.rebuild_events), UINT64_C(1)); UT_ASSERT_EQ(pg_atomic_read_u64(&ut_stats.durability_events), UINT64_C(1)); /* G2 vocabulary: every name maps to exactly one kind; unknown names * fail closed. */ - for (i = 0; i < (int) lengthof(names); i++) + for (i = 0; i < (int)lengthof(names); i++) UT_ASSERT(cluster_side_stats_describe(names[i], &kind)); UT_ASSERT(!cluster_side_stats_describe("cluster.side.no_such", &kind)); UT_ASSERT(!cluster_side_stats_describe(NULL, &kind)); @@ -97,18 +90,16 @@ UT_TEST(test_counter_never_changes_verdict) * judgements are pure over their typed facts and never read a * counter, so every verdict must be identical. */ { - int i; - pg_atomic_uint64 *fields = - (pg_atomic_uint64 *) &ut_stats; - int nfields = sizeof(ClusterSideStats) / sizeof(pg_atomic_uint64); + int i; + pg_atomic_uint64 *fields = (pg_atomic_uint64 *)&ut_stats; + int nfields = sizeof(ClusterSideStats) / sizeof(pg_atomic_uint64); for (i = 0; i < nfields; i++) pg_atomic_write_u64(&fields[i], UINT64_MAX / 2); } UT_ASSERT(cluster_side_route_lookup(10 /* RM_HEAP_ID */, 0x10, &row)); - UT_ASSERT_EQ((int) cluster_side_route_verdict(&row), - (int) CLUSTER_SIDE_ROUTE_VERDICT_APPLY); + UT_ASSERT_EQ((int)cluster_side_route_verdict(&row), (int)CLUSTER_SIDE_ROUTE_VERDICT_APPLY); memset(&ready, 0, sizeof(ready)); ready.resource_id = 1; diff --git a/src/test/cluster_unit/test_cluster_side_undo.c b/src/test/cluster_unit/test_cluster_side_undo.c index ea0418e7bce..85ce639d798 100644 --- a/src/test/cluster_unit/test_cluster_side_undo.c +++ b/src/test/cluster_unit/test_cluster_side_undo.c @@ -47,8 +47,9 @@ static int apply_fail_on_read; void cluster_tt_durable_redo_stamp_slot(uint8 instance pg_attribute_unused(), - uint32 segment_id pg_attribute_unused(), uint16 slot_offset pg_attribute_unused(), - uint16 wrap, TransactionId xid, SCN commit_scn) + uint32 segment_id pg_attribute_unused(), + uint16 slot_offset pg_attribute_unused(), uint16 wrap, + TransactionId xid, SCN commit_scn) { memset(&apply_slot, 0, sizeof(apply_slot)); apply_slot.status = TT_SLOT_COMMITTED; @@ -59,18 +60,20 @@ cluster_tt_durable_redo_stamp_slot(uint8 instance pg_attribute_unused(), ClusterTTActiveTransitionDecision cluster_tt_durable_bind_preflight_exact(uint8 instance pg_attribute_unused(), - uint32 segment_id pg_attribute_unused(), uint32 segment_generation, - uint16 slot_offset pg_attribute_unused(), uint16 wrap, TransactionId xid) + uint32 segment_id pg_attribute_unused(), + uint32 segment_generation, + uint16 slot_offset pg_attribute_unused(), uint16 wrap, + TransactionId xid) { if (segment_generation != apply_generation) - return segment_generation < apply_generation - ? CLUSTER_TT_ACTIVE_STALE : CLUSTER_TT_ACTIVE_CORRUPT; + return segment_generation < apply_generation ? CLUSTER_TT_ACTIVE_STALE + : CLUSTER_TT_ACTIVE_CORRUPT; if (apply_slot.status == TT_SLOT_UNUSED) - return memcmp(&apply_slot, &(TTSlot){0}, sizeof(apply_slot)) == 0 - ? CLUSTER_TT_ACTIVE_APPLY : CLUSTER_TT_ACTIVE_CORRUPT; - if (apply_slot.status == TT_SLOT_ACTIVE && apply_slot.xid == xid - && apply_slot.wrap == wrap && apply_slot.flags == TT_FLAGS_RESERVED - && !SCN_VALID(apply_slot.commit_scn) + return memcmp(&apply_slot, &(TTSlot){ 0 }, sizeof(apply_slot)) == 0 + ? CLUSTER_TT_ACTIVE_APPLY + : CLUSTER_TT_ACTIVE_CORRUPT; + if (apply_slot.status == TT_SLOT_ACTIVE && apply_slot.xid == xid && apply_slot.wrap == wrap + && apply_slot.flags == TT_FLAGS_RESERVED && !SCN_VALID(apply_slot.commit_scn) && UBA_is_invalid(apply_slot.first_undo_block)) return CLUSTER_TT_ACTIVE_IDEMPOTENT; return CLUSTER_TT_ACTIVE_CONFLICT; @@ -78,11 +81,13 @@ cluster_tt_durable_bind_preflight_exact(uint8 instance pg_attribute_unused(), void cluster_tt_durable_redo_bind_slot(uint8 instance pg_attribute_unused(), - uint32 segment_id pg_attribute_unused(), uint32 segment_generation, - uint16 slot_offset pg_attribute_unused(), uint16 wrap, TransactionId xid) + uint32 segment_id pg_attribute_unused(), + uint32 segment_generation, + uint16 slot_offset pg_attribute_unused(), uint16 wrap, + TransactionId xid) { - if (cluster_tt_durable_bind_preflight_exact(instance, segment_id, - segment_generation, slot_offset, wrap, xid) + if (cluster_tt_durable_bind_preflight_exact(instance, segment_id, segment_generation, + slot_offset, wrap, xid) != CLUSTER_TT_ACTIVE_APPLY) return; memset(&apply_slot, 0, sizeof(apply_slot)); @@ -93,50 +98,47 @@ cluster_tt_durable_redo_bind_slot(uint8 instance pg_attribute_unused(), ClusterTTTerminalTransitionDecision cluster_tt_durable_abort_preflight_exact(uint8 instance pg_attribute_unused(), - uint32 segment_id pg_attribute_unused(), uint32 segment_generation, - uint16 slot_offset pg_attribute_unused(), uint16 wrap, TransactionId xid) + uint32 segment_id pg_attribute_unused(), + uint32 segment_generation, + uint16 slot_offset pg_attribute_unused(), uint16 wrap, + TransactionId xid) { if (segment_generation != apply_generation) - return segment_generation < apply_generation - ? CLUSTER_TT_TERMINAL_STALE : CLUSTER_TT_TERMINAL_CORRUPT; - if (apply_slot.status == TT_SLOT_ACTIVE - && apply_slot.xid == xid && apply_slot.wrap == wrap + return segment_generation < apply_generation ? CLUSTER_TT_TERMINAL_STALE + : CLUSTER_TT_TERMINAL_CORRUPT; + if (apply_slot.status == TT_SLOT_ACTIVE && apply_slot.xid == xid && apply_slot.wrap == wrap && !SCN_VALID(apply_slot.commit_scn)) return CLUSTER_TT_TERMINAL_APPLY; - if (apply_slot.status == TT_SLOT_ABORTED - && apply_slot.xid == xid && apply_slot.wrap == wrap - && !SCN_VALID(apply_slot.commit_scn) - && UBA_is_invalid(apply_slot.first_undo_block)) + if (apply_slot.status == TT_SLOT_ABORTED && apply_slot.xid == xid && apply_slot.wrap == wrap + && !SCN_VALID(apply_slot.commit_scn) && UBA_is_invalid(apply_slot.first_undo_block)) return CLUSTER_TT_TERMINAL_IDEMPOTENT; return CLUSTER_TT_TERMINAL_CONFLICT; } void cluster_tt_durable_redo_abort_slot_exact(uint8 instance pg_attribute_unused(), - uint32 segment_id pg_attribute_unused(), uint32 segment_generation, - uint16 slot_offset pg_attribute_unused(), uint16 wrap, TransactionId xid) + uint32 segment_id pg_attribute_unused(), + uint32 segment_generation, + uint16 slot_offset pg_attribute_unused(), uint16 wrap, + TransactionId xid) { - if (cluster_tt_durable_abort_preflight_exact(instance, segment_id, - segment_generation, slot_offset, wrap, xid) + if (cluster_tt_durable_abort_preflight_exact(instance, segment_id, segment_generation, + slot_offset, wrap, xid) != CLUSTER_TT_TERMINAL_APPLY) return; apply_slot.status = TT_SLOT_ABORTED; apply_slot.commit_scn = InvalidScn; - memset(&apply_slot.first_undo_block, 0, - sizeof(apply_slot.first_undo_block)); + memset(&apply_slot.first_undo_block, 0, sizeof(apply_slot.first_undo_block)); } ClusterUndoTtCtrcReleaseRedoDecision -cluster_tt_durable_ctrc_release_preflight_exact( - const xl_undo_tt_slot_ctrc_release_v1 *record) +cluster_tt_durable_ctrc_release_preflight_exact(const xl_undo_tt_slot_ctrc_release_v1 *record) { - return cluster_undo_tt_ctrc_release_redo_decide( - apply_generation, &apply_slot, record); + return cluster_undo_tt_ctrc_release_redo_decide(apply_generation, &apply_slot, record); } void -cluster_tt_durable_redo_ctrc_release_slot_exact( - const xl_undo_tt_slot_ctrc_release_v1 *record) +cluster_tt_durable_redo_ctrc_release_slot_exact(const xl_undo_tt_slot_ctrc_release_v1 *record) { if (cluster_tt_durable_ctrc_release_preflight_exact(record) == CLUSTER_UNDO_TT_CTRC_RELEASE_REDO_APPLY) @@ -145,8 +147,9 @@ cluster_tt_durable_redo_ctrc_release_slot_exact( void cluster_tt_durable_redo_abort_slot(uint8 instance pg_attribute_unused(), - uint32 segment_id pg_attribute_unused(), uint16 slot_offset pg_attribute_unused(), - uint16 wrap, TransactionId xid) + uint32 segment_id pg_attribute_unused(), + uint16 slot_offset pg_attribute_unused(), uint16 wrap, + TransactionId xid) { memset(&apply_slot, 0, sizeof(apply_slot)); apply_slot.status = TT_SLOT_ABORTED; @@ -156,8 +159,9 @@ cluster_tt_durable_redo_abort_slot(uint8 instance pg_attribute_unused(), void cluster_tt_durable_redo_set_head_slot(uint8 instance pg_attribute_unused(), - uint32 segment_id pg_attribute_unused(), uint16 slot_offset pg_attribute_unused(), - uint16 wrap, TransactionId xid, UBA first_undo_block) + uint32 segment_id pg_attribute_unused(), + uint16 slot_offset pg_attribute_unused(), uint16 wrap, + TransactionId xid, UBA first_undo_block) { apply_slot.status = TT_SLOT_ABORTED; apply_slot.xid = xid; @@ -167,13 +171,12 @@ cluster_tt_durable_redo_set_head_slot(uint8 instance pg_attribute_unused(), bool cluster_tt_slot_durable_read_exact_stable(uint32 segment_id pg_attribute_unused(), - uint16 slot_offset pg_attribute_unused(), TransactionId xid, - uint16 expected_wrap, TTSlot *slot_out) + uint16 slot_offset pg_attribute_unused(), + TransactionId xid, uint16 expected_wrap, TTSlot *slot_out) { apply_read_calls++; - if ((apply_fail_on_read > 0 && apply_read_calls == apply_fail_on_read) || - slot_out == NULL || apply_slot.xid != xid || - apply_slot.wrap != expected_wrap) + if ((apply_fail_on_read > 0 && apply_read_calls == apply_fail_on_read) || slot_out == NULL + || apply_slot.xid != xid || apply_slot.wrap != expected_wrap) return false; *slot_out = apply_slot; return true; @@ -185,7 +188,7 @@ cluster_tt_slot_durable_read_exact_stable(uint32 segment_id pg_attribute_unused( * ---------- */ typedef struct FakeRecord { XLogReaderState st; - uint8 data[BLCKSZ + 128]; + uint8 data[BLCKSZ + 128]; union { DecodedXLogRecord dec; /* cppcheck-suppress unusedStructMember */ @@ -194,18 +197,16 @@ typedef struct FakeRecord { } FakeRecord; static XLogReaderState * -make_record(FakeRecord *fr, RmgrId rmid, uint8 info, const void *payload, - uint32 payload_len) +make_record(FakeRecord *fr, RmgrId rmid, uint8 info, const void *payload, uint32 payload_len) { DecodedXLogRecord *dec = &fr->u.dec; memset(fr, 0, sizeof(*fr)); dec->header.xl_rmid = rmid; dec->header.xl_info = info; - if (payload != NULL && payload_len > 0) - { + if (payload != NULL && payload_len > 0) { memcpy(fr->data, payload, payload_len); - dec->main_data = (char *) fr->data; + dec->main_data = (char *)fr->data; dec->main_data_len = payload_len; } fr->st.record = dec; @@ -227,17 +228,15 @@ UT_TEST(test_decode_tt_commit_fields) payload.xid = 1234; payload.commit_scn = UINT64_C(0x123456789); - rec = make_record(&fr, RM_CLUSTER_UNDO_ID, XLOG_UNDO_TT_SLOT_COMMIT, - &payload, sizeof(payload)); + rec = make_record(&fr, RM_CLUSTER_UNDO_ID, XLOG_UNDO_TT_SLOT_COMMIT, &payload, sizeof(payload)); UT_ASSERT(cluster_undo_decode(rec, &out)); - UT_ASSERT_EQ((int) out.kind, (int) CLUSTER_UNDO_KIND_TT_COMMIT); - UT_ASSERT_EQ((unsigned) out.instance, 1U); - UT_ASSERT_EQ((unsigned) out.segment_id, 7U); - UT_ASSERT_EQ((unsigned) out.slot_offset, 3U); - UT_ASSERT_EQ((unsigned) out.wrap, 2U); - UT_ASSERT_EQ((unsigned) out.xid, 1234U); - UT_ASSERT_EQ((unsigned long long) out.commit_scn, - (unsigned long long) UINT64_C(0x123456789)); + UT_ASSERT_EQ((int)out.kind, (int)CLUSTER_UNDO_KIND_TT_COMMIT); + UT_ASSERT_EQ((unsigned)out.instance, 1U); + UT_ASSERT_EQ((unsigned)out.segment_id, 7U); + UT_ASSERT_EQ((unsigned)out.slot_offset, 3U); + UT_ASSERT_EQ((unsigned)out.wrap, 2U); + UT_ASSERT_EQ((unsigned)out.xid, 1234U); + UT_ASSERT_EQ((unsigned long long)out.commit_scn, (unsigned long long)UINT64_C(0x123456789)); /* preflight passes for a valid TT commit. */ UT_ASSERT(cluster_undo_preflight(&out)); @@ -258,8 +257,7 @@ UT_TEST(test_decode_tt_bind_exact_shape_and_reserved_bytes) payload.wrap = 0; payload.xid = 1234; payload.format_version = CLUSTER_UNDO_TT_BIND_VERSION; - rec = make_record(&fr, RM_CLUSTER_UNDO_ID, XLOG_UNDO_TT_SLOT_BIND, - &payload, sizeof(payload)); + rec = make_record(&fr, RM_CLUSTER_UNDO_ID, XLOG_UNDO_TT_SLOT_BIND, &payload, sizeof(payload)); UT_ASSERT(cluster_undo_decode(rec, &out)); UT_ASSERT_EQ((int)out.kind, (int)CLUSTER_UNDO_KIND_TT_BIND); UT_ASSERT_EQ(out.instance, 1); @@ -272,16 +270,14 @@ UT_TEST(test_decode_tt_bind_exact_shape_and_reserved_bytes) UT_ASSERT(cluster_undo_preflight(&out)); payload.reserved32 = 1; - rec = make_record(&fr, RM_CLUSTER_UNDO_ID, XLOG_UNDO_TT_SLOT_BIND, - &payload, sizeof(payload)); + rec = make_record(&fr, RM_CLUSTER_UNDO_ID, XLOG_UNDO_TT_SLOT_BIND, &payload, sizeof(payload)); UT_ASSERT(!cluster_undo_decode(rec, &out)); payload.reserved32 = 0; payload.format_version++; - rec = make_record(&fr, RM_CLUSTER_UNDO_ID, XLOG_UNDO_TT_SLOT_BIND, - &payload, sizeof(payload)); + rec = make_record(&fr, RM_CLUSTER_UNDO_ID, XLOG_UNDO_TT_SLOT_BIND, &payload, sizeof(payload)); UT_ASSERT(!cluster_undo_decode(rec, &out)); - rec = make_record(&fr, RM_CLUSTER_UNDO_ID, XLOG_UNDO_TT_SLOT_BIND, - &payload, sizeof(payload) - 1); + rec = make_record(&fr, RM_CLUSTER_UNDO_ID, XLOG_UNDO_TT_SLOT_BIND, &payload, + sizeof(payload) - 1); UT_ASSERT(!cluster_undo_decode(rec, &out)); } @@ -297,8 +293,7 @@ UT_TEST(test_decode_malformed_and_unknown_blocked) /* Wrong rmgr. */ memset(&payload, 0, sizeof(payload)); - rec = make_record(&fr, RM_HEAP_ID, XLOG_UNDO_TT_SLOT_COMMIT, - &payload, sizeof(payload)); + rec = make_record(&fr, RM_HEAP_ID, XLOG_UNDO_TT_SLOT_COMMIT, &payload, sizeof(payload)); UT_ASSERT(!cluster_undo_decode(rec, &out)); /* Unknown info byte. */ @@ -306,13 +301,13 @@ UT_TEST(test_decode_malformed_and_unknown_blocked) UT_ASSERT(!cluster_undo_decode(rec, &out)); /* Malformed length (too short) — U-SIDE-04: BLOCKED pre-mutation. */ - rec = make_record(&fr, RM_CLUSTER_UNDO_ID, XLOG_UNDO_TT_SLOT_COMMIT, - &payload, sizeof(payload) - 1); + rec = make_record(&fr, RM_CLUSTER_UNDO_ID, XLOG_UNDO_TT_SLOT_COMMIT, &payload, + sizeof(payload) - 1); UT_ASSERT(!cluster_undo_decode(rec, &out)); /* Malformed length (too long). */ - rec = make_record(&fr, RM_CLUSTER_UNDO_ID, XLOG_UNDO_TT_SLOT_COMMIT, - &payload, sizeof(payload) + 1); + rec = make_record(&fr, RM_CLUSTER_UNDO_ID, XLOG_UNDO_TT_SLOT_COMMIT, &payload, + sizeof(payload) + 1); UT_ASSERT(!cluster_undo_decode(rec, &out)); memset(&exact_abort, 0, sizeof(exact_abort)); @@ -323,27 +318,27 @@ UT_TEST(test_decode_malformed_and_unknown_blocked) exact_abort.wrap = 0; exact_abort.instance = 3; exact_abort.format_version = CLUSTER_UNDO_TT_ABORT_EXACT_VERSION; - rec = make_record(&fr, RM_CLUSTER_UNDO_ID, XLOG_UNDO_TT_SLOT_ABORT, - &exact_abort, sizeof(exact_abort)); + rec = make_record(&fr, RM_CLUSTER_UNDO_ID, XLOG_UNDO_TT_SLOT_ABORT, &exact_abort, + sizeof(exact_abort)); UT_ASSERT(cluster_undo_decode(rec, &out)); UT_ASSERT_EQ(out.expected_generation, 9); UT_ASSERT_EQ(out.format_version, CLUSTER_UNDO_TT_ABORT_EXACT_VERSION); UT_ASSERT(cluster_undo_preflight(&out)); exact_abort.reserved = 1; - rec = make_record(&fr, RM_CLUSTER_UNDO_ID, XLOG_UNDO_TT_SLOT_ABORT, - &exact_abort, sizeof(exact_abort)); + rec = make_record(&fr, RM_CLUSTER_UNDO_ID, XLOG_UNDO_TT_SLOT_ABORT, &exact_abort, + sizeof(exact_abort)); UT_ASSERT(!cluster_undo_decode(rec, &out)); /* Cold and online share this padding gate before either may mutate. */ memset(&abort_payload, 0, sizeof(abort_payload)); abort_payload._pad[0] = 1; - rec = make_record(&fr, RM_CLUSTER_UNDO_ID, XLOG_UNDO_TT_SLOT_ABORT, - &abort_payload, sizeof(abort_payload)); + rec = make_record(&fr, RM_CLUSTER_UNDO_ID, XLOG_UNDO_TT_SLOT_ABORT, &abort_payload, + sizeof(abort_payload)); UT_ASSERT(!cluster_undo_decode(rec, &out)); memset(&head_payload, 0, sizeof(head_payload)); head_payload._pad[2] = 1; - rec = make_record(&fr, RM_CLUSTER_UNDO_ID, XLOG_UNDO_TT_SLOT_SET_HEAD, - &head_payload, sizeof(head_payload)); + rec = make_record(&fr, RM_CLUSTER_UNDO_ID, XLOG_UNDO_TT_SLOT_SET_HEAD, &head_payload, + sizeof(head_payload)); UT_ASSERT(!cluster_undo_decode(rec, &out)); /* NULL inputs. */ @@ -366,8 +361,7 @@ UT_TEST(test_preflight_field_integrity_and_route) payload.wrap = 2; payload.xid = 1234; payload.commit_scn = 55; - rec = make_record(&fr, RM_CLUSTER_UNDO_ID, XLOG_UNDO_TT_SLOT_COMMIT, - &payload, sizeof(payload)); + rec = make_record(&fr, RM_CLUSTER_UNDO_ID, XLOG_UNDO_TT_SLOT_COMMIT, &payload, sizeof(payload)); UT_ASSERT(cluster_undo_decode(rec, &out)); UT_ASSERT(cluster_undo_preflight(&out)); @@ -390,10 +384,9 @@ UT_TEST(test_preflight_field_integrity_and_route) /* XLOG_HW_RESERVE decodes but stays BLOCKED (STOP-RF-SIDE-SPACE-ABI). */ memset(&hw, 0, sizeof(hw)); hw.new_hwm = 42; - rec = make_record(&fr, RM_CLUSTER_UNDO_ID, XLOG_HW_RESERVE, - &hw, sizeof(hw)); + rec = make_record(&fr, RM_CLUSTER_UNDO_ID, XLOG_HW_RESERVE, &hw, sizeof(hw)); UT_ASSERT(cluster_undo_decode(rec, &out)); - UT_ASSERT_EQ((int) out.kind, (int) CLUSTER_UNDO_KIND_HW_RESERVE); + UT_ASSERT_EQ((int)out.kind, (int)CLUSTER_UNDO_KIND_HW_RESERVE); UT_ASSERT(!cluster_undo_preflight(&out)); } @@ -403,26 +396,23 @@ UT_TEST(test_decode_block_write_fields) xl_undo_block_write payload; ClusterUndoDecoded out; XLogReaderState *rec; - uint8 fpi[sizeof(payload) + BLCKSZ]; - uint8 delta[sizeof(payload) + UNDO_BLOCK_HDR_PREFIX_LEN + 32 + - sizeof(UndoSlotDirEntry)]; + uint8 fpi[sizeof(payload) + BLCKSZ]; + uint8 delta[sizeof(payload) + UNDO_BLOCK_HDR_PREFIX_LEN + 32 + sizeof(UndoSlotDirEntry)]; memset(&payload, 0, sizeof(payload)); payload.instance = 2; payload.segment_id = 9; payload.block_no = 5; payload.has_fpi = 1; - rec = make_record(&fr, RM_CLUSTER_UNDO_ID, XLOG_UNDO_BLOCK_WRITE, - &payload, sizeof(payload)); + rec = make_record(&fr, RM_CLUSTER_UNDO_ID, XLOG_UNDO_BLOCK_WRITE, &payload, sizeof(payload)); UT_ASSERT(!cluster_undo_decode(rec, &out)); memcpy(fpi, &payload, sizeof(payload)); memset(fpi + sizeof(payload), 0x5a, BLCKSZ); - rec = make_record(&fr, RM_CLUSTER_UNDO_ID, XLOG_UNDO_BLOCK_WRITE, - fpi, sizeof(fpi)); + rec = make_record(&fr, RM_CLUSTER_UNDO_ID, XLOG_UNDO_BLOCK_WRITE, fpi, sizeof(fpi)); UT_ASSERT(cluster_undo_decode(rec, &out)); - UT_ASSERT_EQ((int) out.kind, (int) CLUSTER_UNDO_KIND_BLOCK_WRITE); - UT_ASSERT_EQ((unsigned) out.segment_id, 9U); - UT_ASSERT_EQ((unsigned) out.block_no, 5U); + UT_ASSERT_EQ((int)out.kind, (int)CLUSTER_UNDO_KIND_BLOCK_WRITE); + UT_ASSERT_EQ((unsigned)out.segment_id, 9U); + UT_ASSERT_EQ((unsigned)out.block_no, 5U); UT_ASSERT(out.has_payload); UT_ASSERT(out.has_fpi); UT_ASSERT_EQ(out.payload_offset, sizeof(payload)); @@ -437,17 +427,14 @@ UT_TEST(test_decode_block_write_fields) payload.slot_off = BLCKSZ - sizeof(UndoSlotDirEntry); memcpy(delta, &payload, sizeof(payload)); memset(delta + sizeof(payload), 0x6b, sizeof(delta) - sizeof(payload)); - rec = make_record(&fr, RM_CLUSTER_UNDO_ID, XLOG_UNDO_BLOCK_WRITE, - delta, sizeof(delta)); + rec = make_record(&fr, RM_CLUSTER_UNDO_ID, XLOG_UNDO_BLOCK_WRITE, delta, sizeof(delta)); UT_ASSERT(cluster_undo_decode(rec, &out)); UT_ASSERT(!out.has_fpi); UT_ASSERT_EQ(out.rec_off, sizeof(UndoBlockHeader)); UT_ASSERT_EQ(out.rec_len, 32); UT_ASSERT_EQ(out.slot_off, BLCKSZ - sizeof(UndoSlotDirEntry)); - UT_ASSERT_EQ(out.payload_length, - UNDO_BLOCK_HDR_PREFIX_LEN + 32 + sizeof(UndoSlotDirEntry)); - rec = make_record(&fr, RM_CLUSTER_UNDO_ID, XLOG_UNDO_BLOCK_WRITE, - delta, sizeof(delta) - 1); + UT_ASSERT_EQ(out.payload_length, UNDO_BLOCK_HDR_PREFIX_LEN + 32 + sizeof(UndoSlotDirEntry)); + rec = make_record(&fr, RM_CLUSTER_UNDO_ID, XLOG_UNDO_BLOCK_WRITE, delta, sizeof(delta) - 1); UT_ASSERT(!cluster_undo_decode(rec, &out)); } @@ -458,8 +445,7 @@ UT_TEST(test_decode_set_head_and_multi_exact_shape) xl_undo_block_write_multi multi; ClusterUndoDecoded out; XLogReaderState *rec; - uint8 body[sizeof(multi) + UNDO_BLOCK_HDR_PREFIX_LEN + 24 + - 2 * sizeof(UndoSlotDirEntry)]; + uint8 body[sizeof(multi) + UNDO_BLOCK_HDR_PREFIX_LEN + 24 + 2 * sizeof(UndoSlotDirEntry)]; memset(&set_head, 0, sizeof(set_head)); set_head.instance = 3; @@ -469,11 +455,10 @@ UT_TEST(test_decode_set_head_and_multi_exact_shape) set_head.xid = 801; set_head.first_undo_block.raw[0] = UINT64_C(513) | (UINT64_C(9) << 32); set_head.first_undo_block.raw[1] = UINT64_C(4); - rec = make_record(&fr, RM_CLUSTER_UNDO_ID, XLOG_UNDO_TT_SLOT_SET_HEAD, - &set_head, sizeof(set_head)); + rec = make_record(&fr, RM_CLUSTER_UNDO_ID, XLOG_UNDO_TT_SLOT_SET_HEAD, &set_head, + sizeof(set_head)); UT_ASSERT(cluster_undo_decode(rec, &out)); - UT_ASSERT(memcmp(&out.first_undo_block, &set_head.first_undo_block, - sizeof(UBA)) == 0); + UT_ASSERT(memcmp(&out.first_undo_block, &set_head.first_undo_block, sizeof(UBA)) == 0); memset(&multi, 0, sizeof(multi)); multi.instance = 3; @@ -485,13 +470,11 @@ UT_TEST(test_decode_set_head_and_multi_exact_shape) multi.slot_off = BLCKSZ - multi.slot_len; memcpy(body, &multi, sizeof(multi)); memset(body + sizeof(multi), 0x31, sizeof(body) - sizeof(multi)); - rec = make_record(&fr, RM_CLUSTER_UNDO_ID, XLOG_UNDO_BLOCK_WRITE_MULTI, - body, sizeof(body)); + rec = make_record(&fr, RM_CLUSTER_UNDO_ID, XLOG_UNDO_BLOCK_WRITE_MULTI, body, sizeof(body)); UT_ASSERT(cluster_undo_decode(rec, &out)); - UT_ASSERT_EQ((int) out.kind, (int) CLUSTER_UNDO_KIND_BLOCK_WRITE_MULTI); + UT_ASSERT_EQ((int)out.kind, (int)CLUSTER_UNDO_KIND_BLOCK_WRITE_MULTI); UT_ASSERT_EQ(out.slot_len, 2 * sizeof(UndoSlotDirEntry)); - rec = make_record(&fr, RM_CLUSTER_UNDO_ID, XLOG_UNDO_BLOCK_WRITE_MULTI, - body, sizeof(body) - 1); + rec = make_record(&fr, RM_CLUSTER_UNDO_ID, XLOG_UNDO_BLOCK_WRITE_MULTI, body, sizeof(body) - 1); UT_ASSERT(!cluster_undo_decode(rec, &out)); } @@ -515,50 +498,39 @@ UT_TEST(test_typed_tt_apply_requires_exact_post_read) apply_slot.status = TT_SLOT_ACTIVE; apply_slot.xid = operation.xid; apply_slot.wrap = operation.wrap; - UT_ASSERT_EQ(cluster_undo_preflight_tt_target_v1(&operation), - CLUSTER_UNDO_TARGET_APPLY); - UT_ASSERT_EQ(cluster_undo_apply_tt_v1(&operation), - CLUSTER_UNDO_APPLY_OK); - UT_ASSERT_EQ((int) apply_slot.status, (int) TT_SLOT_COMMITTED); - UT_ASSERT_EQ(cluster_undo_preflight_tt_target_v1(&operation), - CLUSTER_UNDO_TARGET_PROVED_NOOP); + UT_ASSERT_EQ(cluster_undo_preflight_tt_target_v1(&operation), CLUSTER_UNDO_TARGET_APPLY); + UT_ASSERT_EQ(cluster_undo_apply_tt_v1(&operation), CLUSTER_UNDO_APPLY_OK); + UT_ASSERT_EQ((int)apply_slot.status, (int)TT_SLOT_COMMITTED); + UT_ASSERT_EQ(cluster_undo_preflight_tt_target_v1(&operation), CLUSTER_UNDO_TARGET_PROVED_NOOP); operation.kind = CLUSTER_UNDO_KIND_TT_ABORT; operation.opcode = XLOG_UNDO_TT_SLOT_ABORT; operation.commit_scn = InvalidScn; - UT_ASSERT_EQ(cluster_undo_preflight_tt_target_v1(&operation), - CLUSTER_UNDO_TARGET_BLOCKED); + UT_ASSERT_EQ(cluster_undo_preflight_tt_target_v1(&operation), CLUSTER_UNDO_TARGET_BLOCKED); apply_slot.status = TT_SLOT_ACTIVE; apply_slot.commit_scn = InvalidScn; - UT_ASSERT_EQ(cluster_undo_apply_tt_v1(&operation), - CLUSTER_UNDO_APPLY_OK); - UT_ASSERT_EQ((int) apply_slot.status, (int) TT_SLOT_ABORTED); + UT_ASSERT_EQ(cluster_undo_apply_tt_v1(&operation), CLUSTER_UNDO_APPLY_OK); + UT_ASSERT_EQ((int)apply_slot.status, (int)TT_SLOT_ABORTED); head.raw[0] = UINT64_C(513) | (UINT64_C(9) << 32); head.raw[1] = UINT64_C(4); operation.kind = CLUSTER_UNDO_KIND_TT_SET_HEAD; operation.opcode = XLOG_UNDO_TT_SLOT_SET_HEAD; operation.first_undo_block = head; - UT_ASSERT_EQ(cluster_undo_preflight_tt_target_v1(&operation), - CLUSTER_UNDO_TARGET_APPLY); - UT_ASSERT_EQ(cluster_undo_apply_tt_v1(&operation), - CLUSTER_UNDO_APPLY_OK); + UT_ASSERT_EQ(cluster_undo_preflight_tt_target_v1(&operation), CLUSTER_UNDO_TARGET_APPLY); + UT_ASSERT_EQ(cluster_undo_apply_tt_v1(&operation), CLUSTER_UNDO_APPLY_OK); UT_ASSERT_EQ(memcmp(&apply_slot.first_undo_block, &head, sizeof(head)), 0); - UT_ASSERT_EQ(cluster_undo_preflight_tt_target_v1(&operation), - CLUSTER_UNDO_TARGET_PROVED_NOOP); + UT_ASSERT_EQ(cluster_undo_preflight_tt_target_v1(&operation), CLUSTER_UNDO_TARGET_PROVED_NOOP); apply_slot.first_undo_block.raw[0]++; - UT_ASSERT_EQ(cluster_undo_preflight_tt_target_v1(&operation), - CLUSTER_UNDO_TARGET_BLOCKED); + UT_ASSERT_EQ(cluster_undo_preflight_tt_target_v1(&operation), CLUSTER_UNDO_TARGET_BLOCKED); apply_slot.first_undo_block = head; apply_slot.status = TT_SLOT_ABORTED; apply_slot.commit_scn = InvalidScn; - memset(&apply_slot.first_undo_block, 0, - sizeof(apply_slot.first_undo_block)); + memset(&apply_slot.first_undo_block, 0, sizeof(apply_slot.first_undo_block)); apply_read_calls = 0; apply_fail_on_read = 2; - UT_ASSERT_EQ(cluster_undo_apply_tt_v1(&operation), - CLUSTER_UNDO_APPLY_POST_READ_FAILED); + UT_ASSERT_EQ(cluster_undo_apply_tt_v1(&operation), CLUSTER_UNDO_APPLY_POST_READ_FAILED); apply_fail_on_read = 0; } @@ -580,23 +552,18 @@ UT_TEST(test_typed_tt_bind_applies_only_exact_generation_and_predecessor) apply_read_calls = 0; apply_fail_on_read = 0; - UT_ASSERT_EQ(cluster_undo_preflight_tt_target_v1(&operation), - CLUSTER_UNDO_TARGET_APPLY); - UT_ASSERT_EQ(cluster_undo_apply_tt_v1(&operation), - CLUSTER_UNDO_APPLY_OK); + UT_ASSERT_EQ(cluster_undo_preflight_tt_target_v1(&operation), CLUSTER_UNDO_TARGET_APPLY); + UT_ASSERT_EQ(cluster_undo_apply_tt_v1(&operation), CLUSTER_UNDO_APPLY_OK); UT_ASSERT_EQ(apply_slot.status, TT_SLOT_ACTIVE); UT_ASSERT_EQ(apply_slot.xid, operation.xid); UT_ASSERT_EQ(apply_slot.wrap, operation.wrap); - UT_ASSERT_EQ(cluster_undo_preflight_tt_target_v1(&operation), - CLUSTER_UNDO_TARGET_PROVED_NOOP); + UT_ASSERT_EQ(cluster_undo_preflight_tt_target_v1(&operation), CLUSTER_UNDO_TARGET_PROVED_NOOP); operation.expected_generation--; - UT_ASSERT_EQ(cluster_undo_preflight_tt_target_v1(&operation), - CLUSTER_UNDO_TARGET_PROVED_NOOP); + UT_ASSERT_EQ(cluster_undo_preflight_tt_target_v1(&operation), CLUSTER_UNDO_TARGET_PROVED_NOOP); operation.expected_generation += 2; - UT_ASSERT_EQ(cluster_undo_preflight_tt_target_v1(&operation), - CLUSTER_UNDO_TARGET_BLOCKED); + UT_ASSERT_EQ(cluster_undo_preflight_tt_target_v1(&operation), CLUSTER_UNDO_TARGET_BLOCKED); } UT_TEST(test_typed_exact_abort_requires_same_active_predecessor) @@ -621,25 +588,19 @@ UT_TEST(test_typed_exact_abort_requires_same_active_predecessor) apply_read_calls = 0; apply_fail_on_read = 0; - UT_ASSERT_EQ(cluster_undo_preflight_tt_target_v1(&operation), - CLUSTER_UNDO_TARGET_APPLY); - UT_ASSERT_EQ(cluster_undo_apply_tt_v1(&operation), - CLUSTER_UNDO_APPLY_OK); - UT_ASSERT_EQ((int) apply_slot.status, (int) TT_SLOT_ABORTED); - UT_ASSERT_EQ(cluster_undo_preflight_tt_target_v1(&operation), - CLUSTER_UNDO_TARGET_PROVED_NOOP); + UT_ASSERT_EQ(cluster_undo_preflight_tt_target_v1(&operation), CLUSTER_UNDO_TARGET_APPLY); + UT_ASSERT_EQ(cluster_undo_apply_tt_v1(&operation), CLUSTER_UNDO_APPLY_OK); + UT_ASSERT_EQ((int)apply_slot.status, (int)TT_SLOT_ABORTED); + UT_ASSERT_EQ(cluster_undo_preflight_tt_target_v1(&operation), CLUSTER_UNDO_TARGET_PROVED_NOOP); operation.expected_generation--; - UT_ASSERT_EQ(cluster_undo_preflight_tt_target_v1(&operation), - CLUSTER_UNDO_TARGET_PROVED_NOOP); + UT_ASSERT_EQ(cluster_undo_preflight_tt_target_v1(&operation), CLUSTER_UNDO_TARGET_PROVED_NOOP); operation.expected_generation += 2; - UT_ASSERT_EQ(cluster_undo_preflight_tt_target_v1(&operation), - CLUSTER_UNDO_TARGET_BLOCKED); + UT_ASSERT_EQ(cluster_undo_preflight_tt_target_v1(&operation), CLUSTER_UNDO_TARGET_BLOCKED); operation.expected_generation = apply_generation; apply_slot.status = TT_SLOT_ACTIVE; apply_slot.xid++; - UT_ASSERT_EQ(cluster_undo_preflight_tt_target_v1(&operation), - CLUSTER_UNDO_TARGET_BLOCKED); + UT_ASSERT_EQ(cluster_undo_preflight_tt_target_v1(&operation), CLUSTER_UNDO_TARGET_BLOCKED); } UT_TEST(test_typed_ctrc_release_requires_exact_terminal_generation_and_post_read) @@ -665,8 +626,7 @@ UT_TEST(test_typed_ctrc_release_requires_exact_terminal_generation_and_post_read operation.terminal_status = TT_SLOT_COMMITTED; operation.format_version = CLUSTER_UNDO_TT_CTRC_RELEASE_VERSION; operation.flags = CLUSTER_UNDO_TT_CTRC_RELEASE_ALL_TOUCHED_ACKED; - memset(operation.ack_set_digest, 0x5a, - sizeof(operation.ack_set_digest)); + memset(operation.ack_set_digest, 0x5a, sizeof(operation.ack_set_digest)); apply_generation = operation.expected_generation; memset(&apply_slot, 0, sizeof(apply_slot)); apply_slot.status = TT_SLOT_COMMITTED; @@ -676,13 +636,10 @@ UT_TEST(test_typed_ctrc_release_requires_exact_terminal_generation_and_post_read apply_read_calls = 0; apply_fail_on_read = 0; - UT_ASSERT_EQ(cluster_undo_preflight_tt_target_v1(&operation), - CLUSTER_UNDO_TARGET_APPLY); - UT_ASSERT_EQ(cluster_undo_apply_tt_v1(&operation), - CLUSTER_UNDO_APPLY_OK); + UT_ASSERT_EQ(cluster_undo_preflight_tt_target_v1(&operation), CLUSTER_UNDO_TARGET_APPLY); + UT_ASSERT_EQ(cluster_undo_apply_tt_v1(&operation), CLUSTER_UNDO_APPLY_OK); UT_ASSERT_EQ(apply_slot.flags, TT_SLOT_FLAG_CTRC_RELEASE_PROVEN); - UT_ASSERT_EQ(cluster_undo_preflight_tt_target_v1(&operation), - CLUSTER_UNDO_TARGET_PROVED_NOOP); + UT_ASSERT_EQ(cluster_undo_preflight_tt_target_v1(&operation), CLUSTER_UNDO_TARGET_PROVED_NOOP); } int diff --git a/src/test/cluster_unit/test_cluster_side_xact.c b/src/test/cluster_unit/test_cluster_side_xact.c index aa27b44e690..41de3eccf18 100644 --- a/src/test/cluster_unit/test_cluster_side_xact.c +++ b/src/test/cluster_unit/test_cluster_side_xact.c @@ -35,8 +35,7 @@ ExceptionalCondition(const char *conditionName pg_attribute_unused(), #include -typedef struct PrepareApplyCapture -{ +typedef struct PrepareApplyCapture { uint64 system_identifier; int origin_slot; TransactionId mismatched_origin_xid; @@ -96,18 +95,18 @@ GetSystemIdentifier(void) int cluster_xid_origin_slot(TransactionId xid pg_attribute_unused()) { - if (TransactionIdIsValid(prepare_apply.mismatched_origin_xid) && - TransactionIdEquals(xid, prepare_apply.mismatched_origin_xid)) + if (TransactionIdIsValid(prepare_apply.mismatched_origin_xid) + && TransactionIdEquals(xid, prepare_apply.mismatched_origin_xid)) return prepare_apply.origin_slot + 1; return prepare_apply.origin_slot; } bool -cluster_tt_slot_durable_read_exact_stable( - uint32 segment_id pg_attribute_unused(), - uint16 slot_offset pg_attribute_unused(), - TransactionId xid pg_attribute_unused(), - uint16 expected_wrap pg_attribute_unused(), TTSlot *slot_out) +cluster_tt_slot_durable_read_exact_stable(uint32 segment_id pg_attribute_unused(), + uint16 slot_offset pg_attribute_unused(), + TransactionId xid pg_attribute_unused(), + uint16 expected_wrap pg_attribute_unused(), + TTSlot *slot_out) { prepare_apply.tt_reads++; *slot_out = prepare_apply.slot; @@ -115,22 +114,25 @@ cluster_tt_slot_durable_read_exact_stable( } TwoPhaseRecoveryPendingResult -TwoPhaseRecoveryPendingPreflight( - TransactionId xid pg_attribute_unused(), Oid database pg_attribute_unused(), - Oid owner pg_attribute_unused(), TimestampTz prepared_at pg_attribute_unused(), - const char *gid pg_attribute_unused(), const void *content pg_attribute_unused(), - uint32 len pg_attribute_unused()) +TwoPhaseRecoveryPendingPreflight(TransactionId xid pg_attribute_unused(), + Oid database pg_attribute_unused(), + Oid owner pg_attribute_unused(), + TimestampTz prepared_at pg_attribute_unused(), + const char *gid pg_attribute_unused(), + const void *content pg_attribute_unused(), + uint32 len pg_attribute_unused()) { prepare_apply.pending_preflights++; return prepare_apply.pending_preflight; } TwoPhaseRecoveryPendingResult -TwoPhaseRecoveryPendingInstall( - TransactionId xid pg_attribute_unused(), Oid database pg_attribute_unused(), - Oid owner pg_attribute_unused(), TimestampTz prepared_at pg_attribute_unused(), - const char *gid pg_attribute_unused(), const void *content pg_attribute_unused(), - uint32 len pg_attribute_unused()) +TwoPhaseRecoveryPendingInstall(TransactionId xid pg_attribute_unused(), + Oid database pg_attribute_unused(), Oid owner pg_attribute_unused(), + TimestampTz prepared_at pg_attribute_unused(), + const char *gid pg_attribute_unused(), + const void *content pg_attribute_unused(), + uint32 len pg_attribute_unused()) { prepare_apply.pending_installs++; prepare_apply.install_order = ++prepare_apply.next_order; @@ -138,35 +140,33 @@ TwoPhaseRecoveryPendingInstall( } TwoPhaseRecoveryPendingResult -TwoPhaseRecoveryPendingReadExact( - TransactionId xid pg_attribute_unused(), Oid database pg_attribute_unused(), - const char *gid pg_attribute_unused(), void **content_out, - uint32 *len_out) +TwoPhaseRecoveryPendingReadExact(TransactionId xid pg_attribute_unused(), + Oid database pg_attribute_unused(), + const char *gid pg_attribute_unused(), void **content_out, + uint32 *len_out) { prepare_apply.pending_reads++; if (prepare_apply.pending_read != TWOPHASE_RECOVERY_PENDING_OK) return prepare_apply.pending_read; - if (content_out == NULL || len_out == NULL || - prepare_apply.native_payload_length == 0) + if (content_out == NULL || len_out == NULL || prepare_apply.native_payload_length == 0) return TWOPHASE_RECOVERY_PENDING_BLOCKED; *content_out = malloc(prepare_apply.native_payload_length); - memcpy(*content_out, prepare_apply.native_payload, - prepare_apply.native_payload_length); + memcpy(*content_out, prepare_apply.native_payload, prepare_apply.native_payload_length); *len_out = prepare_apply.native_payload_length; return TWOPHASE_RECOVERY_PENDING_OK; } TwoPhaseRecoveryPendingResult -TwoPhaseRecoveryPendingResolveExact( - TransactionId xid pg_attribute_unused(), Oid database pg_attribute_unused(), - const char *gid pg_attribute_unused(), const void *content, - uint32 len, bool isCommit) +TwoPhaseRecoveryPendingResolveExact(TransactionId xid pg_attribute_unused(), + Oid database pg_attribute_unused(), + const char *gid pg_attribute_unused(), const void *content, + uint32 len, bool isCommit) { prepare_apply.pending_resolves++; prepare_apply.resolved_is_commit = isCommit; prepare_apply.resolve_order = ++prepare_apply.next_order; - if (content == NULL || len != prepare_apply.native_payload_length || - memcmp(content, prepare_apply.native_payload, len) != 0) + if (content == NULL || len != prepare_apply.native_payload_length + || memcmp(content, prepare_apply.native_payload, len) != 0) return TWOPHASE_RECOVERY_PENDING_CONFLICT; return prepare_apply.pending_resolve; } @@ -191,27 +191,30 @@ cluster_remote_xact_pending_matches_v2( } void -cluster_tt_durable_redo_stamp_slot( - uint8 instance pg_attribute_unused(), uint32 segment_id pg_attribute_unused(), - uint16 slot_offset pg_attribute_unused(), uint16 wrap pg_attribute_unused(), - TransactionId xid pg_attribute_unused(), SCN commit_scn pg_attribute_unused()) -{ -} +cluster_tt_durable_redo_stamp_slot(uint8 instance pg_attribute_unused(), + uint32 segment_id pg_attribute_unused(), + uint16 slot_offset pg_attribute_unused(), + uint16 wrap pg_attribute_unused(), + TransactionId xid pg_attribute_unused(), + SCN commit_scn pg_attribute_unused()) +{} void -cluster_tt_durable_redo_stamp_slot_exact( - uint8 instance pg_attribute_unused(), uint32 segment_id pg_attribute_unused(), - uint32 segment_generation pg_attribute_unused(), - uint16 slot_offset pg_attribute_unused(), uint16 wrap pg_attribute_unused(), - TransactionId xid pg_attribute_unused(), SCN commit_scn pg_attribute_unused()) -{ -} +cluster_tt_durable_redo_stamp_slot_exact(uint8 instance pg_attribute_unused(), + uint32 segment_id pg_attribute_unused(), + uint32 segment_generation pg_attribute_unused(), + uint16 slot_offset pg_attribute_unused(), + uint16 wrap pg_attribute_unused(), + TransactionId xid pg_attribute_unused(), + SCN commit_scn pg_attribute_unused()) +{} ClusterTTDurableResolve -cluster_tt_slot_durable_resolve_by_xid_origin( - int origin_node pg_attribute_unused(), TransactionId xid pg_attribute_unused(), - uint32 expected_wrap pg_attribute_unused(), SCN *commit_scn, - uint16 *out_seg, uint16 *out_slot, uint16 *out_wrap) +cluster_tt_slot_durable_resolve_by_xid_origin(int origin_node pg_attribute_unused(), + TransactionId xid pg_attribute_unused(), + uint32 expected_wrap pg_attribute_unused(), + SCN *commit_scn, uint16 *out_seg, uint16 *out_slot, + uint16 *out_wrap) { *commit_scn = UINT64_C(901); *out_seg = 9; @@ -222,19 +225,17 @@ cluster_tt_slot_durable_resolve_by_xid_origin( void cluster_scn_recovery_replay_observe(SCN scn pg_attribute_unused()) -{ -} +{} ClusterRemoteXactMutationV2 cluster_remote_xact_store_terminal_v2( int origin_node pg_attribute_unused(), TransactionId xid pg_attribute_unused(), bool require_prepared pg_attribute_unused(), - const uint8 expected_prepare_digest[CLUSTER_REMOTE_XACT_PREPARE_DIGEST_BYTES] - pg_attribute_unused(), - ClusterRemoteXactOutcome outcome, - SCN commit_scn pg_attribute_unused(), - TimestampTz commit_timestamp pg_attribute_unused(), - bool wrap_valid pg_attribute_unused(), uint16 wrap pg_attribute_unused()) + const uint8 + expected_prepare_digest[CLUSTER_REMOTE_XACT_PREPARE_DIGEST_BYTES] pg_attribute_unused(), + ClusterRemoteXactOutcome outcome, SCN commit_scn pg_attribute_unused(), + TimestampTz commit_timestamp pg_attribute_unused(), bool wrap_valid pg_attribute_unused(), + uint16 wrap pg_attribute_unused()) { prepare_apply.terminal_projection_stores++; prepare_apply.terminal_outcome = outcome; @@ -243,18 +244,15 @@ cluster_remote_xact_store_terminal_v2( } ClusterRemoteXactOutcome -cluster_remote_commit_outcome_ex( - int origin_node pg_attribute_unused(), TransactionId xid pg_attribute_unused(), - SCN *commit_scn, uint16 *out_wrap, bool *out_wrap_valid) +cluster_remote_commit_outcome_ex(int origin_node pg_attribute_unused(), + TransactionId xid pg_attribute_unused(), SCN *commit_scn, + uint16 *out_wrap, bool *out_wrap_valid) { - if (prepare_apply.terminal_outcome == CLUSTER_REMOTE_XACT_COMMITTED) - { + if (prepare_apply.terminal_outcome == CLUSTER_REMOTE_XACT_COMMITTED) { *commit_scn = UINT64_C(901); *out_wrap = 7; *out_wrap_valid = true; - } - else - { + } else { *commit_scn = InvalidScn; *out_wrap = 0; *out_wrap_valid = false; @@ -263,9 +261,9 @@ cluster_remote_commit_outcome_ex( } bool -cluster_remote_commit_timestamp( - int origin_node pg_attribute_unused(), TransactionId xid pg_attribute_unused(), - TimestampTz *commit_timestamp) +cluster_remote_commit_timestamp(int origin_node pg_attribute_unused(), + TransactionId xid pg_attribute_unused(), + TimestampTz *commit_timestamp) { if (prepare_apply.terminal_outcome != CLUSTER_REMOTE_XACT_COMMITTED) return false; @@ -273,20 +271,18 @@ cluster_remote_commit_timestamp( return true; } -typedef struct FakeXactRecord -{ +typedef struct FakeXactRecord { XLogReaderState reader; uint8 data[512]; - union - { + union { DecodedXLogRecord decoded; char pad[sizeof(DecodedXLogRecord) + 2 * sizeof(DecodedBkpBlock)]; } u; } FakeXactRecord; static XLogReaderState * -make_commit(FakeXactRecord *fake, TransactionId xid, SCN scn, - TimestampTz timestamp, bool conflicting_tt) +make_commit(FakeXactRecord *fake, TransactionId xid, SCN scn, TimestampTz timestamp, + bool conflicting_tt) { xl_xact_commit commit; xl_xact_xinfo xinfo; @@ -322,18 +318,17 @@ make_commit(FakeXactRecord *fake, TransactionId xid, SCN scn, fake->u.decoded.header.xl_rmid = RM_XACT_ID; fake->u.decoded.header.xl_info = XLOG_XACT_COMMIT | XLOG_XACT_HAS_INFO; fake->u.decoded.header.xl_xid = xid; - fake->u.decoded.main_data = (char *) fake->data; - fake->u.decoded.main_data_len = (uint32) (cursor - fake->data); + fake->u.decoded.main_data = (char *)fake->data; + fake->u.decoded.main_data_len = (uint32)(cursor - fake->data); fake->reader.record = &fake->u.decoded; return &fake->reader; } static XLogReaderState * -make_prepare_with_head(FakeXactRecord *fake, TransactionId xid, bool with_tt, - bool truncated_gid, const UBA *head) +make_prepare_with_head(FakeXactRecord *fake, TransactionId xid, bool with_tt, bool truncated_gid, + const UBA *head) { - typedef struct FakeTwoPhaseRecordOnDisk - { + typedef struct FakeTwoPhaseRecordOnDisk { uint32 len; TwoPhaseRmgrId rmid; uint16 info; @@ -341,10 +336,10 @@ make_prepare_with_head(FakeXactRecord *fake, TransactionId xid, bool with_tt, xl_xact_prepare prepare; ClusterTT2PCBinding binding; FakeTwoPhaseRecordOnDisk disk_record; - Size header_size = MAXALIGN(sizeof(prepare)); - Size payload_size; - uint32 tt_size; - char *cursor; + Size header_size = MAXALIGN(sizeof(prepare)); + Size payload_size; + uint32 tt_size; + char *cursor; memset(fake, 0, sizeof(*fake)); memset(&prepare, 0, sizeof(prepare)); @@ -356,11 +351,10 @@ make_prepare_with_head(FakeXactRecord *fake, TransactionId xid, bool with_tt, prepare.owner = 10; prepare.prepared_at = INT64_C(123456); prepare.gidlen = 4; - cursor = (char *) fake->data + header_size; + cursor = (char *)fake->data + header_size; memcpy(cursor, "gid", 4); cursor += MAXALIGN(4); - if (with_tt) - { + if (with_tt) { binding.undo_segment_id = 513; binding.slot_offset = 4; binding.wrap = 7; @@ -371,43 +365,41 @@ make_prepare_with_head(FakeXactRecord *fake, TransactionId xid, bool with_tt, disk_record.rmid = TWOPHASE_RM_CLUSTER_TT_ID; memcpy(cursor, &disk_record, sizeof(disk_record)); cursor += MAXALIGN(sizeof(disk_record)); - UT_ASSERT_EQ(cluster_tt_2pc_serialize(&binding, head, 1, NULL, 0, - cursor, tt_size), tt_size); + UT_ASSERT_EQ(cluster_tt_2pc_serialize(&binding, head, 1, NULL, 0, cursor, tt_size), + tt_size); cursor += MAXALIGN(tt_size); } memset(&disk_record, 0, sizeof(disk_record)); disk_record.rmid = TWOPHASE_RM_END_ID; memcpy(cursor, &disk_record, sizeof(disk_record)); cursor += MAXALIGN(sizeof(disk_record)); - payload_size = (Size) (cursor - (char *) fake->data); - prepare.total_len = (uint32) payload_size + sizeof(uint32); + payload_size = (Size)(cursor - (char *)fake->data); + prepare.total_len = (uint32)payload_size + sizeof(uint32); memcpy(fake->data, &prepare, sizeof(prepare)); fake->u.decoded.header.xl_rmid = RM_XACT_ID; fake->u.decoded.header.xl_info = XLOG_XACT_PREPARE; - fake->u.decoded.main_data = (char *) fake->data; - fake->u.decoded.main_data_len = truncated_gid ? - (uint32) header_size : (uint32) payload_size; + fake->u.decoded.main_data = (char *)fake->data; + fake->u.decoded.main_data_len = truncated_gid ? (uint32)header_size : (uint32)payload_size; fake->reader.record = &fake->u.decoded; return &fake->reader; } static XLogReaderState * -make_prepare(FakeXactRecord *fake, TransactionId xid, bool with_tt, - bool truncated_gid) +make_prepare(FakeXactRecord *fake, TransactionId xid, bool with_tt, bool truncated_gid) { return make_prepare_with_head(fake, xid, with_tt, truncated_gid, NULL); } static XLogReaderState * -make_commit_prepared(FakeXactRecord *fake, TransactionId xid, Oid database, - SCN scn, TimestampTz timestamp) +make_commit_prepared(FakeXactRecord *fake, TransactionId xid, Oid database, SCN scn, + TimestampTz timestamp) { xl_xact_commit commit; xl_xact_xinfo xinfo; xl_xact_dbinfo dbinfo; xl_xact_twophase twophase; xl_xact_scn wal_scn; - char *cursor; + char *cursor; memset(fake, 0, sizeof(*fake)); memset(&commit, 0, sizeof(commit)); @@ -416,12 +408,12 @@ make_commit_prepared(FakeXactRecord *fake, TransactionId xid, Oid database, memset(&twophase, 0, sizeof(twophase)); memset(&wal_scn, 0, sizeof(wal_scn)); commit.xact_time = timestamp; - xinfo.xinfo = XACT_XINFO_HAS_DBINFO | XACT_XINFO_HAS_TWOPHASE | - XACT_XINFO_HAS_GID | XACT_XINFO_HAS_SCN; + xinfo.xinfo + = XACT_XINFO_HAS_DBINFO | XACT_XINFO_HAS_TWOPHASE | XACT_XINFO_HAS_GID | XACT_XINFO_HAS_SCN; dbinfo.dbId = database; twophase.xid = xid; wal_scn.scn = scn; - cursor = (char *) fake->data; + cursor = (char *)fake->data; memcpy(cursor, &commit, sizeof(commit)); cursor += sizeof(commit); memcpy(cursor, &xinfo, sizeof(xinfo)); @@ -435,24 +427,22 @@ make_commit_prepared(FakeXactRecord *fake, TransactionId xid, Oid database, memcpy(cursor, &wal_scn, sizeof(wal_scn)); cursor += sizeof(wal_scn); fake->u.decoded.header.xl_rmid = RM_XACT_ID; - fake->u.decoded.header.xl_info = - XLOG_XACT_COMMIT_PREPARED | XLOG_XACT_HAS_INFO; - fake->u.decoded.main_data = (char *) fake->data; - fake->u.decoded.main_data_len = (uint32) (cursor - (char *) fake->data); + fake->u.decoded.header.xl_info = XLOG_XACT_COMMIT_PREPARED | XLOG_XACT_HAS_INFO; + fake->u.decoded.main_data = (char *)fake->data; + fake->u.decoded.main_data_len = (uint32)(cursor - (char *)fake->data); fake->reader.record = &fake->u.decoded; return &fake->reader; } static XLogReaderState * -make_abort_prepared(FakeXactRecord *fake, TransactionId xid, Oid database, - SCN scn) +make_abort_prepared(FakeXactRecord *fake, TransactionId xid, Oid database, SCN scn) { xl_xact_abort abort; xl_xact_xinfo xinfo; xl_xact_dbinfo dbinfo; xl_xact_twophase twophase; xl_xact_scn wal_scn; - char *cursor; + char *cursor; memset(fake, 0, sizeof(*fake)); memset(&abort, 0, sizeof(abort)); @@ -461,12 +451,12 @@ make_abort_prepared(FakeXactRecord *fake, TransactionId xid, Oid database, memset(&twophase, 0, sizeof(twophase)); memset(&wal_scn, 0, sizeof(wal_scn)); abort.xact_time = INT64_C(123456); - xinfo.xinfo = XACT_XINFO_HAS_DBINFO | XACT_XINFO_HAS_TWOPHASE | - XACT_XINFO_HAS_GID | XACT_XINFO_HAS_SCN; + xinfo.xinfo + = XACT_XINFO_HAS_DBINFO | XACT_XINFO_HAS_TWOPHASE | XACT_XINFO_HAS_GID | XACT_XINFO_HAS_SCN; dbinfo.dbId = database; twophase.xid = xid; wal_scn.scn = scn; - cursor = (char *) fake->data; + cursor = (char *)fake->data; memcpy(cursor, &abort, sizeof(abort)); cursor += sizeof(abort); memcpy(cursor, &xinfo, sizeof(xinfo)); @@ -480,10 +470,9 @@ make_abort_prepared(FakeXactRecord *fake, TransactionId xid, Oid database, memcpy(cursor, &wal_scn, sizeof(wal_scn)); cursor += sizeof(wal_scn); fake->u.decoded.header.xl_rmid = RM_XACT_ID; - fake->u.decoded.header.xl_info = - XLOG_XACT_ABORT_PREPARED | XLOG_XACT_HAS_INFO; - fake->u.decoded.main_data = (char *) fake->data; - fake->u.decoded.main_data_len = (uint32) (cursor - (char *) fake->data); + fake->u.decoded.header.xl_info = XLOG_XACT_ABORT_PREPARED | XLOG_XACT_HAS_INFO; + fake->u.decoded.main_data = (char *)fake->data; + fake->u.decoded.main_data_len = (uint32)(cursor - (char *)fake->data); fake->reader.record = &fake->u.decoded; return &fake->reader; } @@ -513,8 +502,8 @@ make_identity(FakeXactRecord *fake, uint8 storage_uuid[16]) } static void -set_identity_range(FakeXactRecord *fake, RfPageOnlineRecordIdentityV1 *identity, - XLogRecPtr begin, XLogRecPtr end) +set_identity_range(FakeXactRecord *fake, RfPageOnlineRecordIdentityV1 *identity, XLogRecPtr begin, + XLogRecPtr end) { identity->record.read_rec_ptr = begin; identity->record.end_rec_ptr = end; @@ -528,8 +517,7 @@ static XLogReaderState * make_undo_delta(FakeXactRecord *fake) { xl_undo_block_write undo; - uint32 body_len = UNDO_BLOCK_HDR_PREFIX_LEN + 24 + - sizeof(UndoSlotDirEntry); + uint32 body_len = UNDO_BLOCK_HDR_PREFIX_LEN + 24 + sizeof(UndoSlotDirEntry); memset(fake, 0, sizeof(*fake)); memset(&undo, 0, sizeof(undo)); @@ -543,7 +531,7 @@ make_undo_delta(FakeXactRecord *fake) memset(fake->data + sizeof(undo), 0x6b, body_len); fake->u.decoded.header.xl_rmid = RM_CLUSTER_UNDO_ID; fake->u.decoded.header.xl_info = XLOG_UNDO_BLOCK_WRITE; - fake->u.decoded.main_data = (char *) fake->data; + fake->u.decoded.main_data = (char *)fake->data; fake->u.decoded.main_data_len = sizeof(undo) + body_len; fake->reader.record = &fake->u.decoded; return &fake->reader; @@ -565,7 +553,7 @@ make_tt_commit_delta(FakeXactRecord *fake, TransactionId xid, SCN commit_scn) memcpy(fake->data, &commit, sizeof(commit)); fake->u.decoded.header.xl_rmid = RM_CLUSTER_UNDO_ID; fake->u.decoded.header.xl_info = XLOG_UNDO_TT_SLOT_COMMIT; - fake->u.decoded.main_data = (char *) fake->data; + fake->u.decoded.main_data = (char *)fake->data; fake->u.decoded.main_data_len = sizeof(commit); fake->reader.record = &fake->u.decoded; return &fake->reader; @@ -586,15 +574,14 @@ make_tt_abort_delta(FakeXactRecord *fake, TransactionId xid) memcpy(fake->data, &abort, sizeof(abort)); fake->u.decoded.header.xl_rmid = RM_CLUSTER_UNDO_ID; fake->u.decoded.header.xl_info = XLOG_UNDO_TT_SLOT_ABORT; - fake->u.decoded.main_data = (char *) fake->data; + fake->u.decoded.main_data = (char *)fake->data; fake->u.decoded.main_data_len = sizeof(abort); fake->reader.record = &fake->u.decoded; return &fake->reader; } static XLogReaderState * -make_tt_set_head_delta(FakeXactRecord *fake, TransactionId xid, - const UBA *head) +make_tt_set_head_delta(FakeXactRecord *fake, TransactionId xid, const UBA *head) { xl_undo_tt_slot_set_head set_head; @@ -609,7 +596,7 @@ make_tt_set_head_delta(FakeXactRecord *fake, TransactionId xid, memcpy(fake->data, &set_head, sizeof(set_head)); fake->u.decoded.header.xl_rmid = RM_CLUSTER_UNDO_ID; fake->u.decoded.header.xl_info = XLOG_UNDO_TT_SLOT_SET_HEAD; - fake->u.decoded.main_data = (char *) fake->data; + fake->u.decoded.main_data = (char *)fake->data; fake->u.decoded.main_data_len = sizeof(set_head); fake->reader.record = &fake->u.decoded; return &fake->reader; @@ -623,8 +610,7 @@ make_undo_record_plan(FakeXactRecord *fake) memset(&record_plan, 0, sizeof(record_plan)); record_plan.source_record = &fake->reader; record_plan.route.rmid = RM_CLUSTER_UNDO_ID; - record_plan.route.normalized_info = - fake->u.decoded.header.xl_info & XLR_RMGR_INFO_MASK; + record_plan.route.normalized_info = fake->u.decoded.header.xl_info & XLR_RMGR_INFO_MASK; record_plan.route.record_owner = RF_ROUTE_OWNER_SIDE_TYPED; record_plan.route.block_policy = RF_ROUTE_BLOCKS_FORBIDDEN; record_plan.route.codec_id = RF_ROUTE_CODEC_SIDE_CLUSTER_UNDO; @@ -640,8 +626,7 @@ make_record_plan(FakeXactRecord *fake) memset(&record_plan, 0, sizeof(record_plan)); record_plan.source_record = &fake->reader; record_plan.route.rmid = RM_XACT_ID; - record_plan.route.normalized_info = - fake->u.decoded.header.xl_info & XLOG_XACT_OPMASK; + record_plan.route.normalized_info = fake->u.decoded.header.xl_info & XLOG_XACT_OPMASK; record_plan.route.legal_info_flags = XLOG_XACT_HAS_INFO; record_plan.route.record_owner = RF_ROUTE_OWNER_SIDE_TYPED; record_plan.route.block_policy = RF_ROUTE_BLOCKS_FORBIDDEN; @@ -651,15 +636,15 @@ make_record_plan(FakeXactRecord *fake) } static XLogReaderState * -make_projection_record(FakeXactRecord *fake, RmgrId rmid, uint8 info, - const void *payload, uint32 payload_length) +make_projection_record(FakeXactRecord *fake, RmgrId rmid, uint8 info, const void *payload, + uint32 payload_length) { memset(fake, 0, sizeof(*fake)); UT_ASSERT(payload_length <= sizeof(fake->data)); memcpy(fake->data, payload, payload_length); fake->u.decoded.header.xl_rmid = rmid; fake->u.decoded.header.xl_info = info; - fake->u.decoded.main_data = (char *) fake->data; + fake->u.decoded.main_data = (char *)fake->data; fake->u.decoded.main_data_len = payload_length; fake->reader.record = &fake->u.decoded; return &fake->reader; @@ -673,8 +658,7 @@ make_projection_record_plan(FakeXactRecord *fake) memset(&record_plan, 0, sizeof(record_plan)); record_plan.source_record = &fake->reader; record_plan.route.rmid = fake->u.decoded.header.xl_rmid; - record_plan.route.normalized_info = - fake->u.decoded.header.xl_info & ~XLR_INFO_MASK; + record_plan.route.normalized_info = fake->u.decoded.header.xl_info & ~XLR_INFO_MASK; record_plan.route.record_owner = RF_ROUTE_OWNER_SIDE_TYPED; record_plan.route.block_policy = RF_ROUTE_BLOCKS_FORBIDDEN; record_plan.route.codec_id = RF_ROUTE_CODEC_SIDE_STANDARD; @@ -682,8 +666,7 @@ make_projection_record_plan(FakeXactRecord *fake) return record_plan; } -typedef struct ApplyCapture -{ +typedef struct ApplyCapture { uint32 count; uint32 undo_count; uint32 projection_count; @@ -699,7 +682,7 @@ typedef struct ApplyCapture static bool capture_begin(void *arg) { - ApplyCapture *capture = (ApplyCapture *) arg; + ApplyCapture *capture = (ApplyCapture *)arg; capture->begin_count++; return true; @@ -708,7 +691,7 @@ capture_begin(void *arg) static void capture_end(void *arg, bool complete) { - ApplyCapture *capture = (ApplyCapture *) arg; + ApplyCapture *capture = (ApplyCapture *)arg; capture->end_count++; capture->end_complete = complete; @@ -717,7 +700,7 @@ capture_end(void *arg, bool complete) static bool capture_apply(void *arg, const RfSideOnlineOperationV1 *operation) { - ApplyCapture *capture = (ApplyCapture *) arg; + ApplyCapture *capture = (ApplyCapture *)arg; capture->count++; capture->xid = operation->xact.xid; @@ -728,7 +711,7 @@ capture_apply(void *arg, const RfSideOnlineOperationV1 *operation) static bool capture_apply_undo(void *arg, const RfSideOnlineOperationV1 *operation) { - ApplyCapture *capture = (ApplyCapture *) arg; + ApplyCapture *capture = (ApplyCapture *)arg; capture->undo_count++; if (operation->owned_payload_length > 0) @@ -739,7 +722,7 @@ capture_apply_undo(void *arg, const RfSideOnlineOperationV1 *operation) static bool capture_apply_projection(void *arg, const RfSideOnlineOperationV1 *operation) { - ApplyCapture *capture = (ApplyCapture *) arg; + ApplyCapture *capture = (ApplyCapture *)arg; capture->projection_count++; if (operation->owned_payload_length > 0) @@ -755,8 +738,7 @@ accept_preflight(void *arg pg_attribute_unused(), } static bool -reject_undo_preflight(void *arg pg_attribute_unused(), - const RfSideOnlineOperationV1 *operation) +reject_undo_preflight(void *arg pg_attribute_unused(), const RfSideOnlineOperationV1 *operation) { return operation->kind != RF_SIDE_ONLINE_OPERATION_UNDO; } @@ -766,9 +748,8 @@ UT_TEST(test_commit_decodes_to_immutable_truth_operation) FakeXactRecord fake; RfSideXactOperationV1 operation; - UT_ASSERT(rf_side_xact_decode_v1( - make_commit(&fake, 800, UINT64_C(901), INT64_C(123456), false), - UINT64_C(0x11223344), 3, &operation)); + UT_ASSERT(rf_side_xact_decode_v1(make_commit(&fake, 800, UINT64_C(901), INT64_C(123456), false), + UINT64_C(0x11223344), 3, &operation)); UT_ASSERT_EQ(operation.kind, RF_SIDE_XACT_COMMIT); UT_ASSERT_EQ(operation.system_identifier, UINT64_C(0x11223344)); UT_ASSERT_EQ(operation.origin_thread, 3); @@ -787,9 +768,8 @@ UT_TEST(test_commit_tt_conflict_is_blocked_before_apply) FakeXactRecord fake; RfSideXactOperationV1 operation; - UT_ASSERT(!rf_side_xact_decode_v1( - make_commit(&fake, 800, UINT64_C(901), INT64_C(123456), true), - UINT64_C(0x11223344), 3, &operation)); + UT_ASSERT(!rf_side_xact_decode_v1(make_commit(&fake, 800, UINT64_C(901), INT64_C(123456), true), + UINT64_C(0x11223344), 3, &operation)); UT_ASSERT_EQ(operation.kind, RF_SIDE_XACT_INVALID); } @@ -797,16 +777,13 @@ UT_TEST(test_non_xact_and_missing_tt_are_blocked) { FakeXactRecord fake; RfSideXactOperationV1 operation; - XLogReaderState *record = make_commit( - &fake, 800, UINT64_C(901), INT64_C(123456), false); + XLogReaderState *record = make_commit(&fake, 800, UINT64_C(901), INT64_C(123456), false); fake.u.decoded.header.xl_rmid = RM_HEAP_ID; - UT_ASSERT(!rf_side_xact_decode_v1(record, UINT64_C(0x11223344), 3, - &operation)); + UT_ASSERT(!rf_side_xact_decode_v1(record, UINT64_C(0x11223344), 3, &operation)); record = make_commit(&fake, 800, UINT64_C(901), INT64_C(123456), false); fake.u.decoded.main_data_len -= sizeof(xl_xact_tt_commit); - UT_ASSERT(!rf_side_xact_decode_v1(record, UINT64_C(0x11223344), 3, - &operation)); + UT_ASSERT(!rf_side_xact_decode_v1(record, UINT64_C(0x11223344), 3, &operation)); UT_ASSERT(!rf_side_xact_structural_preflight_v1(NULL)); } @@ -815,9 +792,8 @@ UT_TEST(test_prepare_requires_bounded_aligned_gid) FakeXactRecord fake; RfSideXactOperationV1 operation; - UT_ASSERT(rf_side_xact_decode_v1( - make_prepare(&fake, 801, true, false), UINT64_C(0x11223344), 3, - &operation)); + UT_ASSERT(rf_side_xact_decode_v1(make_prepare(&fake, 801, true, false), UINT64_C(0x11223344), 3, + &operation)); UT_ASSERT_EQ(operation.kind, RF_SIDE_XACT_PREPARE); UT_ASSERT_EQ(operation.xid, 801); UT_ASSERT_EQ(operation.database, 16384); @@ -830,12 +806,10 @@ UT_TEST(test_prepare_requires_bounded_aligned_gid) UT_ASSERT_EQ(operation.prepared_bindings[0].slot_offset, 4); UT_ASSERT_EQ(operation.prepared_bindings[0].wrap, 7); UT_ASSERT_EQ(operation.prepared_bindings[0].xid, 801); - UT_ASSERT(!rf_side_xact_decode_v1( - make_prepare(&fake, 801, false, false), UINT64_C(0x11223344), 3, - &operation)); - UT_ASSERT(!rf_side_xact_decode_v1( - make_prepare(&fake, 801, true, true), UINT64_C(0x11223344), 3, - &operation)); + UT_ASSERT(!rf_side_xact_decode_v1(make_prepare(&fake, 801, false, false), UINT64_C(0x11223344), + 3, &operation)); + UT_ASSERT(!rf_side_xact_decode_v1(make_prepare(&fake, 801, true, true), UINT64_C(0x11223344), 3, + &operation)); UT_ASSERT_EQ(operation.kind, RF_SIDE_XACT_INVALID); } @@ -847,17 +821,18 @@ UT_TEST(test_prepare_apply_installs_authoritative_pending_before_projection) reset_prepare_apply(); record = make_prepare(&fake, 802, true, false); - UT_ASSERT(rf_side_xact_decode_v1(record, UINT64_C(0x11223344), 3, - &operation)); - UT_ASSERT_EQ(rf_side_xact_target_preflight_owned_v1(&operation, - fake.data, operation.prepare_payload_length), RF_SIDE_XACT_APPLY_OK); + UT_ASSERT(rf_side_xact_decode_v1(record, UINT64_C(0x11223344), 3, &operation)); + UT_ASSERT_EQ(rf_side_xact_target_preflight_owned_v1(&operation, fake.data, + operation.prepare_payload_length), + RF_SIDE_XACT_APPLY_OK); UT_ASSERT_EQ(prepare_apply.tt_reads, 1); UT_ASSERT_EQ(prepare_apply.pending_preflights, 1); UT_ASSERT_EQ(prepare_apply.pending_installs, 0); UT_ASSERT_EQ(prepare_apply.projection_stores, 0); - UT_ASSERT_EQ(rf_side_xact_apply_owned_v1(&operation, fake.data, - operation.prepare_payload_length), RF_SIDE_XACT_APPLY_OK); + UT_ASSERT_EQ( + rf_side_xact_apply_owned_v1(&operation, fake.data, operation.prepare_payload_length), + RF_SIDE_XACT_APPLY_OK); UT_ASSERT_EQ(prepare_apply.pending_installs, 1); UT_ASSERT_EQ(prepare_apply.projection_stores, 1); UT_ASSERT_EQ(prepare_apply.projection_postreads, 1); @@ -870,18 +845,20 @@ UT_TEST(test_prepare_apply_blocks_underivable_or_wrong_system_before_pending) RfSideXactOperationV1 operation; reset_prepare_apply(); - UT_ASSERT(rf_side_xact_decode_v1(make_prepare(&fake, 802, true, false), - UINT64_C(0x11223344), 3, &operation)); + UT_ASSERT(rf_side_xact_decode_v1(make_prepare(&fake, 802, true, false), UINT64_C(0x11223344), 3, + &operation)); prepare_apply.origin_slot = -1; - UT_ASSERT_EQ(rf_side_xact_target_preflight_owned_v1(&operation, - fake.data, operation.prepare_payload_length), RF_SIDE_XACT_APPLY_BLOCKED); + UT_ASSERT_EQ(rf_side_xact_target_preflight_owned_v1(&operation, fake.data, + operation.prepare_payload_length), + RF_SIDE_XACT_APPLY_BLOCKED); UT_ASSERT_EQ(prepare_apply.tt_reads, 0); UT_ASSERT_EQ(prepare_apply.pending_preflights, 0); prepare_apply.origin_slot = 2; prepare_apply.system_identifier++; - UT_ASSERT_EQ(rf_side_xact_apply_owned_v1(&operation, fake.data, - operation.prepare_payload_length), RF_SIDE_XACT_APPLY_BLOCKED); + UT_ASSERT_EQ( + rf_side_xact_apply_owned_v1(&operation, fake.data, operation.prepare_payload_length), + RF_SIDE_XACT_APPLY_BLOCKED); UT_ASSERT_EQ(prepare_apply.pending_installs, 0); UT_ASSERT_EQ(prepare_apply.projection_stores, 0); } @@ -894,8 +871,8 @@ UT_TEST(test_prepare_apply_blocks_wrong_origin_subxid_before_target_reads) ClusterTT2PCSubLink *link; reset_prepare_apply(); - UT_ASSERT(rf_side_xact_decode_v1(make_prepare(&fake, 802, true, false), - UINT64_C(0x11223344), 3, &operation)); + UT_ASSERT(rf_side_xact_decode_v1(make_prepare(&fake, 802, true, false), UINT64_C(0x11223344), 3, + &operation)); child = &operation.prepared_bindings[1]; memset(child, 0, sizeof(*child)); child->undo_segment_id = 514; @@ -920,8 +897,9 @@ UT_TEST(test_prepare_apply_blocks_wrong_origin_subxid_before_target_reads) UT_ASSERT(rf_side_xact_structural_preflight_v1(&operation)); prepare_apply.mismatched_origin_xid = 803; - UT_ASSERT_EQ(rf_side_xact_target_preflight_owned_v1(&operation, - fake.data, operation.prepare_payload_length), RF_SIDE_XACT_APPLY_BLOCKED); + UT_ASSERT_EQ(rf_side_xact_target_preflight_owned_v1(&operation, fake.data, + operation.prepare_payload_length), + RF_SIDE_XACT_APPLY_BLOCKED); UT_ASSERT_EQ(prepare_apply.tt_reads, 0); UT_ASSERT_EQ(prepare_apply.pending_preflights, 0); UT_ASSERT_EQ(prepare_apply.pending_installs, 0); @@ -934,20 +912,20 @@ UT_TEST(test_prepare_apply_never_projects_unverified_pending) RfSideXactOperationV1 operation; reset_prepare_apply(); - UT_ASSERT(rf_side_xact_decode_v1(make_prepare(&fake, 802, true, false), - UINT64_C(0x11223344), 3, &operation)); - prepare_apply.pending_install = - TWOPHASE_RECOVERY_PENDING_POST_READ_FAILED; - UT_ASSERT_EQ(rf_side_xact_apply_owned_v1(&operation, fake.data, - operation.prepare_payload_length), + UT_ASSERT(rf_side_xact_decode_v1(make_prepare(&fake, 802, true, false), UINT64_C(0x11223344), 3, + &operation)); + prepare_apply.pending_install = TWOPHASE_RECOVERY_PENDING_POST_READ_FAILED; + UT_ASSERT_EQ( + rf_side_xact_apply_owned_v1(&operation, fake.data, operation.prepare_payload_length), RF_SIDE_XACT_APPLY_POST_READ_FAILED); UT_ASSERT_EQ(prepare_apply.pending_installs, 1); UT_ASSERT_EQ(prepare_apply.projection_stores, 0); reset_prepare_apply(); prepare_apply.projection_store = CLUSTER_REMOTE_XACT_MUTATION_CONFLICT; - UT_ASSERT_EQ(rf_side_xact_apply_owned_v1(&operation, fake.data, - operation.prepare_payload_length), RF_SIDE_XACT_APPLY_CONFLICT); + UT_ASSERT_EQ( + rf_side_xact_apply_owned_v1(&operation, fake.data, operation.prepare_payload_length), + RF_SIDE_XACT_APPLY_CONFLICT); UT_ASSERT_EQ(prepare_apply.pending_installs, 1); UT_ASSERT_EQ(prepare_apply.projection_stores, 1); UT_ASSERT_EQ(prepare_apply.projection_postreads, 0); @@ -964,27 +942,24 @@ UT_TEST(test_commit_prepared_resolves_exact_native_owner_after_tt_truth) reset_prepare_apply(); head.raw[0] = UINT64_C(513) | (UINT64_C(9) << 32); head.raw[1] = UINT64_C(4); - prepare_record = make_prepare_with_head(&prepare_fake, 802, true, false, - &head); + prepare_record = make_prepare_with_head(&prepare_fake, 802, true, false, &head); prepare_apply.native_payload_length = XLogRecGetDataLen(prepare_record); memcpy(prepare_apply.native_payload, XLogRecGetData(prepare_record), - prepare_apply.native_payload_length); + prepare_apply.native_payload_length); prepare_apply.slot.status = TT_SLOT_COMMITTED; prepare_apply.slot.commit_scn = UINT64_C(901); - prepare_apply.slot.first_undo_block = (UBA) InvalidUba_init; - UT_ASSERT(rf_side_xact_decode_v1(make_commit_prepared(&terminal_fake, - 802, 16384, UINT64_C(901), INT64_C(123456)), + prepare_apply.slot.first_undo_block = (UBA)InvalidUba_init; + UT_ASSERT(rf_side_xact_decode_v1( + make_commit_prepared(&terminal_fake, 802, 16384, UINT64_C(901), INT64_C(123456)), UINT64_C(0x11223344), 3, &operation)); UT_ASSERT_EQ(operation.kind, RF_SIDE_XACT_COMMIT_PREPARED); - UT_ASSERT_EQ(rf_side_xact_target_preflight_owned_v1( - &operation, NULL, 0), RF_SIDE_XACT_APPLY_OK); - UT_ASSERT_EQ(rf_side_xact_apply_owned_v1(&operation, NULL, 0), - RF_SIDE_XACT_APPLY_OK); + UT_ASSERT_EQ(rf_side_xact_target_preflight_owned_v1(&operation, NULL, 0), + RF_SIDE_XACT_APPLY_OK); + UT_ASSERT_EQ(rf_side_xact_apply_owned_v1(&operation, NULL, 0), RF_SIDE_XACT_APPLY_OK); UT_ASSERT(prepare_apply.pending_reads > 0); UT_ASSERT_EQ(prepare_apply.terminal_projection_stores, 1); UT_ASSERT_EQ(prepare_apply.pending_resolves, 1); - UT_ASSERT(prepare_apply.terminal_projection_order < - prepare_apply.resolve_order); + UT_ASSERT(prepare_apply.terminal_projection_order < prepare_apply.resolve_order); } UT_TEST(test_abort_prepared_resolves_exact_native_owner_after_tt_truth) @@ -998,25 +973,22 @@ UT_TEST(test_abort_prepared_resolves_exact_native_owner_after_tt_truth) prepare_record = make_prepare(&prepare_fake, 802, true, false); prepare_apply.native_payload_length = XLogRecGetDataLen(prepare_record); memcpy(prepare_apply.native_payload, XLogRecGetData(prepare_record), - prepare_apply.native_payload_length); + prepare_apply.native_payload_length); prepare_apply.slot.status = TT_SLOT_ABORTED; prepare_apply.slot.commit_scn = InvalidScn; - prepare_apply.slot.first_undo_block = (UBA) InvalidUba_init; - UT_ASSERT(rf_side_xact_decode_v1(make_abort_prepared(&terminal_fake, - 802, 16384, UINT64_C(902)), UINT64_C(0x11223344), 3, &operation)); + prepare_apply.slot.first_undo_block = (UBA)InvalidUba_init; + UT_ASSERT(rf_side_xact_decode_v1(make_abort_prepared(&terminal_fake, 802, 16384, UINT64_C(902)), + UINT64_C(0x11223344), 3, &operation)); UT_ASSERT_EQ(operation.kind, RF_SIDE_XACT_ABORT_PREPARED); - UT_ASSERT_EQ(rf_side_xact_target_preflight_owned_v1( - &operation, NULL, 0), RF_SIDE_XACT_APPLY_OK); - UT_ASSERT_EQ(rf_side_xact_apply_owned_v1(&operation, NULL, 0), - RF_SIDE_XACT_APPLY_OK); + UT_ASSERT_EQ(rf_side_xact_target_preflight_owned_v1(&operation, NULL, 0), + RF_SIDE_XACT_APPLY_OK); + UT_ASSERT_EQ(rf_side_xact_apply_owned_v1(&operation, NULL, 0), RF_SIDE_XACT_APPLY_OK); UT_ASSERT(prepare_apply.pending_reads > 0); UT_ASSERT_EQ(prepare_apply.terminal_projection_stores, 1); - UT_ASSERT_EQ(prepare_apply.terminal_outcome, - CLUSTER_REMOTE_XACT_ABORTED); + UT_ASSERT_EQ(prepare_apply.terminal_outcome, CLUSTER_REMOTE_XACT_ABORTED); UT_ASSERT_EQ(prepare_apply.pending_resolves, 1); UT_ASSERT(!prepare_apply.resolved_is_commit); - UT_ASSERT(prepare_apply.terminal_projection_order < - prepare_apply.resolve_order); + UT_ASSERT(prepare_apply.terminal_projection_order < prepare_apply.resolve_order); } UT_TEST(test_abort_prepared_nonempty_undo_retains_native_owner) @@ -1030,20 +1002,18 @@ UT_TEST(test_abort_prepared_nonempty_undo_retains_native_owner) head.raw[0] = UINT64_C(513) | (UINT64_C(9) << 32); head.raw[1] = UINT64_C(4); reset_prepare_apply(); - prepare_record = make_prepare_with_head(&prepare_fake, 802, true, false, - &head); + prepare_record = make_prepare_with_head(&prepare_fake, 802, true, false, &head); prepare_apply.native_payload_length = XLogRecGetDataLen(prepare_record); memcpy(prepare_apply.native_payload, XLogRecGetData(prepare_record), - prepare_apply.native_payload_length); + prepare_apply.native_payload_length); prepare_apply.slot.status = TT_SLOT_ABORTED; prepare_apply.slot.commit_scn = InvalidScn; - prepare_apply.slot.first_undo_block = (UBA) InvalidUba_init; - UT_ASSERT(rf_side_xact_decode_v1(make_abort_prepared(&terminal_fake, - 802, 16384, UINT64_C(902)), UINT64_C(0x11223344), 3, &operation)); - UT_ASSERT_EQ(rf_side_xact_target_preflight_owned_v1( - &operation, NULL, 0), RF_SIDE_XACT_APPLY_BLOCKED); - UT_ASSERT_EQ(rf_side_xact_apply_owned_v1(&operation, NULL, 0), - RF_SIDE_XACT_APPLY_BLOCKED); + prepare_apply.slot.first_undo_block = (UBA)InvalidUba_init; + UT_ASSERT(rf_side_xact_decode_v1(make_abort_prepared(&terminal_fake, 802, 16384, UINT64_C(902)), + UINT64_C(0x11223344), 3, &operation)); + UT_ASSERT_EQ(rf_side_xact_target_preflight_owned_v1(&operation, NULL, 0), + RF_SIDE_XACT_APPLY_BLOCKED); + UT_ASSERT_EQ(rf_side_xact_apply_owned_v1(&operation, NULL, 0), RF_SIDE_XACT_APPLY_BLOCKED); UT_ASSERT_EQ(prepare_apply.terminal_projection_stores, 0); UT_ASSERT_EQ(prepare_apply.pending_resolves, 0); } @@ -1062,7 +1032,7 @@ UT_TEST(test_online_plan_owns_decoded_operation_not_raw_record) uint8 storage_uuid[16]; memset(storage_uuid, 0x42, sizeof(storage_uuid)); - (void) make_commit(&fake, 800, UINT64_C(901), INT64_C(123456), false); + (void)make_commit(&fake, 800, UINT64_C(901), INT64_C(123456), false); identity = make_identity(&fake, storage_uuid); record_plan = make_record_plan(&fake); memset(&cut, 0, sizeof(cut)); @@ -1076,13 +1046,11 @@ UT_TEST(test_online_plan_owns_decoded_operation_not_raw_record) memcpy(request.storage_uuid, storage_uuid, sizeof(storage_uuid)); request.physical_cuts = &cut; request.participant_count = 1; - UT_ASSERT_EQ(rf_side_online_plan_create_v1(&request, &plan), - RF_PAGE_PROOF_DETAIL_OK); - UT_ASSERT_EQ(rf_side_online_plan_feed_record_v1( - plan, &record_plan, &identity), RF_PAGE_PROOF_DETAIL_OK); + UT_ASSERT_EQ(rf_side_online_plan_create_v1(&request, &plan), RF_PAGE_PROOF_DETAIL_OK); + UT_ASSERT_EQ(rf_side_online_plan_feed_record_v1(plan, &record_plan, &identity), + RF_PAGE_PROOF_DETAIL_OK); memset(fake.data, 0xee, sizeof(fake.data)); - UT_ASSERT_EQ(rf_side_online_plan_seal_v1(plan), - RF_PAGE_PROOF_DETAIL_OK); + UT_ASSERT_EQ(rf_side_online_plan_seal_v1(plan), RF_PAGE_PROOF_DETAIL_OK); UT_ASSERT_EQ(rf_side_online_plan_operation_count_v1(plan), 1); UT_ASSERT(rf_side_online_plan_operation_v1(plan, 0, &operation)); UT_ASSERT_EQ(operation.xact.xid, 800); @@ -1094,8 +1062,7 @@ UT_TEST(test_online_plan_owns_decoded_operation_not_raw_record) apply_ops.end_protected_set = capture_end; apply_ops.preflight_xact = accept_preflight; apply_ops.apply_xact = capture_apply; - UT_ASSERT_EQ(rf_side_online_plan_apply_v1(plan, &apply_ops), - RF_PAGE_PROOF_DETAIL_OK); + UT_ASSERT_EQ(rf_side_online_plan_apply_v1(plan, &apply_ops), RF_PAGE_PROOF_DETAIL_OK); UT_ASSERT_EQ(capture.count, 1); UT_ASSERT_EQ(capture.xid, 800); UT_ASSERT_EQ(capture.scn, UINT64_C(901)); @@ -1130,10 +1097,10 @@ UT_TEST(test_online_plan_owns_typed_projection_records) int clog_page = 17; memset(storage_uuid, 0x45, sizeof(storage_uuid)); - (void) make_projection_record(&clog_fake, RM_CLOG_ID, CLOG_ZEROPAGE, - &clog_page, sizeof(clog_page)); + (void)make_projection_record(&clog_fake, RM_CLOG_ID, CLOG_ZEROPAGE, &clog_page, + sizeof(clog_page)); memset(create_payload, 0, sizeof(create_payload)); - create = (xl_multixact_create *) create_payload; + create = (xl_multixact_create *)create_payload; create->mid = 33; create->moff = 71; create->nmembers = 2; @@ -1141,13 +1108,13 @@ UT_TEST(test_online_plan_owns_typed_projection_records) create->members[0].status = MultiXactStatusForKeyShare; create->members[1].xid = 816; create->members[1].status = MultiXactStatusUpdate; - (void) make_projection_record(&multi_fake, RM_MULTIXACT_ID, - XLOG_MULTIXACT_CREATE_ID, create_payload, sizeof(create_payload)); + (void)make_projection_record(&multi_fake, RM_MULTIXACT_ID, XLOG_MULTIXACT_CREATE_ID, + create_payload, sizeof(create_payload)); memset(&commit_ts, 0, sizeof(commit_ts)); commit_ts.pageno = 19; commit_ts.oldestXid = 800; - (void) make_projection_record(&commit_ts_fake, RM_COMMIT_TS_ID, - COMMIT_TS_TRUNCATE, &commit_ts, SizeOfCommitTsTruncate); + (void)make_projection_record(&commit_ts_fake, RM_COMMIT_TS_ID, COMMIT_TS_TRUNCATE, &commit_ts, + SizeOfCommitTsTruncate); clog_identity = make_identity(&clog_fake, storage_uuid); multi_identity = make_identity(&multi_fake, storage_uuid); @@ -1168,14 +1135,13 @@ UT_TEST(test_online_plan_owns_typed_projection_records) memcpy(request.storage_uuid, storage_uuid, sizeof(storage_uuid)); request.physical_cuts = &cut; request.participant_count = 1; - UT_ASSERT_EQ(rf_side_online_plan_create_v1(&request, &plan), - RF_PAGE_PROOF_DETAIL_OK); - UT_ASSERT_EQ(rf_side_online_plan_feed_record_v1(plan, &clog_plan, - &clog_identity), RF_PAGE_PROOF_DETAIL_OK); - UT_ASSERT_EQ(rf_side_online_plan_feed_record_v1(plan, &multi_plan, - &multi_identity), RF_PAGE_PROOF_DETAIL_OK); - UT_ASSERT_EQ(rf_side_online_plan_feed_record_v1(plan, &commit_ts_plan, - &commit_ts_identity), RF_PAGE_PROOF_DETAIL_OK); + UT_ASSERT_EQ(rf_side_online_plan_create_v1(&request, &plan), RF_PAGE_PROOF_DETAIL_OK); + UT_ASSERT_EQ(rf_side_online_plan_feed_record_v1(plan, &clog_plan, &clog_identity), + RF_PAGE_PROOF_DETAIL_OK); + UT_ASSERT_EQ(rf_side_online_plan_feed_record_v1(plan, &multi_plan, &multi_identity), + RF_PAGE_PROOF_DETAIL_OK); + UT_ASSERT_EQ(rf_side_online_plan_feed_record_v1(plan, &commit_ts_plan, &commit_ts_identity), + RF_PAGE_PROOF_DETAIL_OK); memset(create_payload, 0xee, sizeof(create_payload)); memset(multi_fake.data, 0xee, sizeof(multi_fake.data)); UT_ASSERT_EQ(rf_side_online_plan_seal_v1(plan), RF_PAGE_PROOF_DETAIL_OK); @@ -1183,26 +1149,19 @@ UT_TEST(test_online_plan_owns_typed_projection_records) UT_ASSERT(rf_side_online_plan_operation_v1(plan, 0, &operation)); UT_ASSERT_EQ(operation.kind, RF_SIDE_ONLINE_OPERATION_PROJECTION); UT_ASSERT_EQ(operation.projection.kind, CLUSTER_SIDE_PROJECTION_CLOG); - UT_ASSERT_EQ(operation.projection.action, - CLUSTER_SIDE_PROJECTION_ACTION_ZERO_PAGE); + UT_ASSERT_EQ(operation.projection.action, CLUSTER_SIDE_PROJECTION_ACTION_ZERO_PAGE); UT_ASSERT_EQ(operation.projection.page_number, 17); UT_ASSERT(rf_side_online_plan_operation_v1(plan, 1, &operation)); - UT_ASSERT_EQ(operation.projection.kind, - CLUSTER_SIDE_PROJECTION_MULTIXACT); - UT_ASSERT_EQ(operation.projection.action, - CLUSTER_SIDE_PROJECTION_ACTION_CREATE); + UT_ASSERT_EQ(operation.projection.kind, CLUSTER_SIDE_PROJECTION_MULTIXACT); + UT_ASSERT_EQ(operation.projection.action, CLUSTER_SIDE_PROJECTION_ACTION_CREATE); UT_ASSERT_EQ(operation.projection.multixact_id, 33); UT_ASSERT_EQ(operation.projection.member_offset, 71); UT_ASSERT_EQ(operation.projection.member_count, 2); - UT_ASSERT_EQ(operation.owned_payload_length, - 2 * sizeof(MultiXactMember)); - UT_ASSERT_EQ(((const MultiXactMember *) operation.owned_payload)[1].xid, - 816); + UT_ASSERT_EQ(operation.owned_payload_length, 2 * sizeof(MultiXactMember)); + UT_ASSERT_EQ(((const MultiXactMember *)operation.owned_payload)[1].xid, 816); UT_ASSERT(rf_side_online_plan_operation_v1(plan, 2, &operation)); - UT_ASSERT_EQ(operation.projection.kind, - CLUSTER_SIDE_PROJECTION_COMMIT_TS); - UT_ASSERT_EQ(operation.projection.action, - CLUSTER_SIDE_PROJECTION_ACTION_TRUNCATE); + UT_ASSERT_EQ(operation.projection.kind, CLUSTER_SIDE_PROJECTION_COMMIT_TS); + UT_ASSERT_EQ(operation.projection.action, CLUSTER_SIDE_PROJECTION_ACTION_TRUNCATE); UT_ASSERT_EQ(operation.projection.page_number, 19); UT_ASSERT_EQ(operation.projection.oldest_xid, 800); @@ -1213,8 +1172,7 @@ UT_TEST(test_online_plan_owns_typed_projection_records) apply_ops.end_protected_set = capture_end; apply_ops.preflight_projection = accept_preflight; apply_ops.apply_projection = capture_apply_projection; - UT_ASSERT_EQ(rf_side_online_plan_apply_v1(plan, &apply_ops), - RF_PAGE_PROOF_DETAIL_OK); + UT_ASSERT_EQ(rf_side_online_plan_apply_v1(plan, &apply_ops), RF_PAGE_PROOF_DETAIL_OK); UT_ASSERT_EQ(capture.projection_count, 3); UT_ASSERT_EQ(capture.projection_first_byte, 0x20); UT_ASSERT(capture.end_complete); @@ -1237,8 +1195,8 @@ UT_TEST(test_online_plan_rejects_malformed_multixact_projection) create.mid = 33; create.moff = 71; create.nmembers = 2; - (void) make_projection_record(&fake, RM_MULTIXACT_ID, - XLOG_MULTIXACT_CREATE_ID, &create, SizeOfMultiXactCreate); + (void)make_projection_record(&fake, RM_MULTIXACT_ID, XLOG_MULTIXACT_CREATE_ID, &create, + SizeOfMultiXactCreate); identity = make_identity(&fake, storage_uuid); record_plan = make_projection_record_plan(&fake); memset(&cut, 0, sizeof(cut)); @@ -1252,10 +1210,9 @@ UT_TEST(test_online_plan_rejects_malformed_multixact_projection) memcpy(request.storage_uuid, storage_uuid, sizeof(storage_uuid)); request.physical_cuts = &cut; request.participant_count = 1; - UT_ASSERT_EQ(rf_side_online_plan_create_v1(&request, &plan), - RF_PAGE_PROOF_DETAIL_OK); - UT_ASSERT_EQ(rf_side_online_plan_feed_record_v1(plan, &record_plan, - &identity), RF_PAGE_PROOF_DETAIL_SIDE_INCOMPLETE); + UT_ASSERT_EQ(rf_side_online_plan_create_v1(&request, &plan), RF_PAGE_PROOF_DETAIL_OK); + UT_ASSERT_EQ(rf_side_online_plan_feed_record_v1(plan, &record_plan, &identity), + RF_PAGE_PROOF_DETAIL_SIDE_INCOMPLETE); UT_ASSERT_EQ(rf_side_online_plan_operation_count_v1(plan), 0); rf_side_online_plan_destroy_v1(&plan); } @@ -1279,10 +1236,8 @@ UT_TEST(test_online_plan_denies_incomplete_physical_cut) memcpy(request.storage_uuid, storage_uuid, sizeof(storage_uuid)); request.physical_cuts = &cut; request.participant_count = 1; - UT_ASSERT_EQ(rf_side_online_plan_create_v1(&request, &plan), - RF_PAGE_PROOF_DETAIL_OK); - UT_ASSERT_EQ(rf_side_online_plan_seal_v1(plan), - RF_PAGE_PROOF_DETAIL_SOURCE_GAP); + UT_ASSERT_EQ(rf_side_online_plan_create_v1(&request, &plan), RF_PAGE_PROOF_DETAIL_OK); + UT_ASSERT_EQ(rf_side_online_plan_seal_v1(plan), RF_PAGE_PROOF_DETAIL_SOURCE_GAP); UT_ASSERT_EQ(rf_side_online_plan_operation_count_v1(plan), 0); rf_side_online_plan_destroy_v1(&plan); } @@ -1301,7 +1256,7 @@ UT_TEST(test_online_plan_owns_undo_payload_not_raw_record) uint8 storage_uuid[16]; memset(storage_uuid, 0x44, sizeof(storage_uuid)); - (void) make_undo_delta(&fake); + (void)make_undo_delta(&fake); identity = make_identity(&fake, storage_uuid); record_plan = make_undo_record_plan(&fake); memset(&cut, 0, sizeof(cut)); @@ -1315,19 +1270,16 @@ UT_TEST(test_online_plan_owns_undo_payload_not_raw_record) memcpy(request.storage_uuid, storage_uuid, sizeof(storage_uuid)); request.physical_cuts = &cut; request.participant_count = 1; - UT_ASSERT_EQ(rf_side_online_plan_create_v1(&request, &plan), - RF_PAGE_PROOF_DETAIL_OK); - UT_ASSERT_EQ(rf_side_online_plan_feed_record_v1( - plan, &record_plan, &identity), RF_PAGE_PROOF_DETAIL_OK); + UT_ASSERT_EQ(rf_side_online_plan_create_v1(&request, &plan), RF_PAGE_PROOF_DETAIL_OK); + UT_ASSERT_EQ(rf_side_online_plan_feed_record_v1(plan, &record_plan, &identity), + RF_PAGE_PROOF_DETAIL_OK); memset(fake.data, 0xee, sizeof(fake.data)); - UT_ASSERT_EQ(rf_side_online_plan_seal_v1(plan), - RF_PAGE_PROOF_DETAIL_OK); + UT_ASSERT_EQ(rf_side_online_plan_seal_v1(plan), RF_PAGE_PROOF_DETAIL_OK); UT_ASSERT(rf_side_online_plan_operation_v1(plan, 0, &operation)); UT_ASSERT_EQ(operation.kind, RF_SIDE_ONLINE_OPERATION_UNDO); - UT_ASSERT_EQ((int) operation.undo.kind, - (int) CLUSTER_UNDO_KIND_BLOCK_WRITE); + UT_ASSERT_EQ((int)operation.undo.kind, (int)CLUSTER_UNDO_KIND_BLOCK_WRITE); UT_ASSERT_EQ(operation.owned_payload_length, - UNDO_BLOCK_HDR_PREFIX_LEN + 24 + sizeof(UndoSlotDirEntry)); + UNDO_BLOCK_HDR_PREFIX_LEN + 24 + sizeof(UndoSlotDirEntry)); UT_ASSERT_EQ(operation.owned_payload[0], 0x6b); memset(&capture, 0, sizeof(capture)); memset(&apply_ops, 0, sizeof(apply_ops)); @@ -1337,8 +1289,7 @@ UT_TEST(test_online_plan_owns_undo_payload_not_raw_record) apply_ops.preflight_undo = accept_preflight; apply_ops.apply_xact = capture_apply; apply_ops.apply_undo = capture_apply_undo; - UT_ASSERT_EQ(rf_side_online_plan_apply_v1(plan, &apply_ops), - RF_PAGE_PROOF_DETAIL_OK); + UT_ASSERT_EQ(rf_side_online_plan_apply_v1(plan, &apply_ops), RF_PAGE_PROOF_DETAIL_OK); UT_ASSERT_EQ(capture.undo_count, 1); UT_ASSERT_EQ(capture.undo_first_byte, 0x6b); rf_side_online_plan_destroy_v1(&plan); @@ -1357,7 +1308,7 @@ UT_TEST(test_online_plan_owns_prepare_state_not_raw_record) uint32 magic; memset(storage_uuid, 0x46, sizeof(storage_uuid)); - (void) make_prepare(&fake, 801, true, false); + (void)make_prepare(&fake, 801, true, false); identity = make_identity(&fake, storage_uuid); record_plan = make_record_plan(&fake); memset(&cut, 0, sizeof(cut)); @@ -1371,20 +1322,17 @@ UT_TEST(test_online_plan_owns_prepare_state_not_raw_record) memcpy(request.storage_uuid, storage_uuid, sizeof(storage_uuid)); request.physical_cuts = &cut; request.participant_count = 1; - UT_ASSERT_EQ(rf_side_online_plan_create_v1(&request, &plan), - RF_PAGE_PROOF_DETAIL_OK); - UT_ASSERT_EQ(rf_side_online_plan_feed_record_v1( - plan, &record_plan, &identity), RF_PAGE_PROOF_DETAIL_OK); + UT_ASSERT_EQ(rf_side_online_plan_create_v1(&request, &plan), RF_PAGE_PROOF_DETAIL_OK); + UT_ASSERT_EQ(rf_side_online_plan_feed_record_v1(plan, &record_plan, &identity), + RF_PAGE_PROOF_DETAIL_OK); memset(fake.data, 0xee, sizeof(fake.data)); - UT_ASSERT_EQ(rf_side_online_plan_seal_v1(plan), - RF_PAGE_PROOF_DETAIL_OK); + UT_ASSERT_EQ(rf_side_online_plan_seal_v1(plan), RF_PAGE_PROOF_DETAIL_OK); UT_ASSERT(rf_side_online_plan_operation_v1(plan, 0, &operation)); UT_ASSERT_EQ(operation.kind, RF_SIDE_ONLINE_OPERATION_XACT); UT_ASSERT_EQ(operation.xact.kind, RF_SIDE_XACT_PREPARE); UT_ASSERT_EQ(operation.xact.prepared_owner, 10); UT_ASSERT(strcmp(operation.xact.prepare_gid, "gid") == 0); - UT_ASSERT_EQ(operation.owned_payload_length, - operation.xact.prepare_payload_length); + UT_ASSERT_EQ(operation.owned_payload_length, operation.xact.prepare_payload_length); UT_ASSERT(operation.owned_payload != NULL); magic = 0; if (operation.owned_payload != NULL) @@ -1409,14 +1357,13 @@ UT_TEST(test_online_plan_preflights_all_targets_before_first_mutation) uint8 storage_uuid[16]; memset(storage_uuid, 0x45, sizeof(storage_uuid)); - (void) make_commit(&xact_fake, 800, UINT64_C(901), - INT64_C(123456), false); + (void)make_commit(&xact_fake, 800, UINT64_C(901), INT64_C(123456), false); xact_identity = make_identity(&xact_fake, storage_uuid); xact_identity.record.end_rec_ptr = 150; xact_fake.reader.EndRecPtr = 150; xact_fake.u.decoded.next_lsn = 150; xact_plan = make_record_plan(&xact_fake); - (void) make_undo_delta(&undo_fake); + (void)make_undo_delta(&undo_fake); undo_identity = make_identity(&undo_fake, storage_uuid); undo_identity.record.read_rec_ptr = 150; undo_fake.reader.ReadRecPtr = 150; @@ -1433,14 +1380,12 @@ UT_TEST(test_online_plan_preflights_all_targets_before_first_mutation) memcpy(request.storage_uuid, storage_uuid, sizeof(storage_uuid)); request.physical_cuts = &cut; request.participant_count = 1; - UT_ASSERT_EQ(rf_side_online_plan_create_v1(&request, &plan), - RF_PAGE_PROOF_DETAIL_OK); - UT_ASSERT_EQ(rf_side_online_plan_feed_record_v1( - plan, &xact_plan, &xact_identity), RF_PAGE_PROOF_DETAIL_OK); - UT_ASSERT_EQ(rf_side_online_plan_feed_record_v1( - plan, &undo_plan, &undo_identity), RF_PAGE_PROOF_DETAIL_OK); - UT_ASSERT_EQ(rf_side_online_plan_seal_v1(plan), - RF_PAGE_PROOF_DETAIL_OK); + UT_ASSERT_EQ(rf_side_online_plan_create_v1(&request, &plan), RF_PAGE_PROOF_DETAIL_OK); + UT_ASSERT_EQ(rf_side_online_plan_feed_record_v1(plan, &xact_plan, &xact_identity), + RF_PAGE_PROOF_DETAIL_OK); + UT_ASSERT_EQ(rf_side_online_plan_feed_record_v1(plan, &undo_plan, &undo_identity), + RF_PAGE_PROOF_DETAIL_OK); + UT_ASSERT_EQ(rf_side_online_plan_seal_v1(plan), RF_PAGE_PROOF_DETAIL_OK); memset(&capture, 0, sizeof(capture)); memset(&apply_ops, 0, sizeof(apply_ops)); apply_ops.arg = &capture; @@ -1451,7 +1396,7 @@ UT_TEST(test_online_plan_preflights_all_targets_before_first_mutation) apply_ops.apply_xact = capture_apply; apply_ops.apply_undo = capture_apply_undo; UT_ASSERT_EQ(rf_side_online_plan_preflight_v1(plan, &apply_ops), - RF_PAGE_PROOF_DETAIL_SIDE_INCOMPLETE); + RF_PAGE_PROOF_DETAIL_SIDE_INCOMPLETE); UT_ASSERT_EQ(capture.count, 0); UT_ASSERT_EQ(capture.undo_count, 0); UT_ASSERT_EQ(capture.begin_count, 1); @@ -1459,7 +1404,7 @@ UT_TEST(test_online_plan_preflights_all_targets_before_first_mutation) UT_ASSERT(!capture.end_complete); memset(&capture, 0, sizeof(capture)); UT_ASSERT_EQ(rf_side_online_plan_apply_v1(plan, &apply_ops), - RF_PAGE_PROOF_DETAIL_SIDE_INCOMPLETE); + RF_PAGE_PROOF_DETAIL_SIDE_INCOMPLETE); UT_ASSERT_EQ(capture.count, 0); UT_ASSERT_EQ(capture.undo_count, 0); UT_ASSERT_EQ(capture.begin_count, 1); @@ -1486,9 +1431,8 @@ UT_TEST(test_online_plan_denies_terminal_missing_required_tt_commit) prepare_record = make_prepare(&prepare_fake, 802, true, false); prepare_apply.native_payload_length = XLogRecGetDataLen(prepare_record); memcpy(prepare_apply.native_payload, XLogRecGetData(prepare_record), - prepare_apply.native_payload_length); - (void) make_commit_prepared(&terminal_fake, 802, 16384, - UINT64_C(901), INT64_C(123456)); + prepare_apply.native_payload_length); + (void)make_commit_prepared(&terminal_fake, 802, 16384, UINT64_C(901), INT64_C(123456)); memset(storage_uuid, 0x42, sizeof(storage_uuid)); terminal_identity = make_identity(&terminal_fake, storage_uuid); terminal_plan = make_record_plan(&terminal_fake); @@ -1503,10 +1447,9 @@ UT_TEST(test_online_plan_denies_terminal_missing_required_tt_commit) memcpy(request.storage_uuid, storage_uuid, sizeof(storage_uuid)); request.physical_cuts = &cut; request.participant_count = 1; - UT_ASSERT_EQ(rf_side_online_plan_create_v1(&request, &plan), - RF_PAGE_PROOF_DETAIL_OK); - UT_ASSERT_EQ(rf_side_online_plan_feed_record_v1(plan, &terminal_plan, - &terminal_identity), RF_PAGE_PROOF_DETAIL_OK); + UT_ASSERT_EQ(rf_side_online_plan_create_v1(&request, &plan), RF_PAGE_PROOF_DETAIL_OK); + UT_ASSERT_EQ(rf_side_online_plan_feed_record_v1(plan, &terminal_plan, &terminal_identity), + RF_PAGE_PROOF_DETAIL_OK); UT_ASSERT_EQ(rf_side_online_plan_seal_v1(plan), RF_PAGE_PROOF_DETAIL_OK); memset(&capture, 0, sizeof(capture)); memset(&apply_ops, 0, sizeof(apply_ops)); @@ -1516,7 +1459,7 @@ UT_TEST(test_online_plan_denies_terminal_missing_required_tt_commit) apply_ops.preflight_xact = accept_preflight; apply_ops.apply_xact = capture_apply; UT_ASSERT_EQ(rf_side_online_plan_apply_v1(plan, &apply_ops), - RF_PAGE_PROOF_DETAIL_SIDE_INCOMPLETE); + RF_PAGE_PROOF_DETAIL_SIDE_INCOMPLETE); UT_ASSERT_EQ(capture.count, 0); UT_ASSERT_EQ(capture.begin_count, 1); UT_ASSERT_EQ(capture.end_count, 1); @@ -1545,10 +1488,9 @@ UT_TEST(test_online_plan_accepts_exact_preceding_tt_commit_dependency) prepare_record = make_prepare(&prepare_fake, 802, true, false); prepare_apply.native_payload_length = XLogRecGetDataLen(prepare_record); memcpy(prepare_apply.native_payload, XLogRecGetData(prepare_record), - prepare_apply.native_payload_length); - (void) make_tt_commit_delta(&undo_fake, 802, UINT64_C(901)); - (void) make_commit_prepared(&terminal_fake, 802, 16384, - UINT64_C(901), INT64_C(123456)); + prepare_apply.native_payload_length); + (void)make_tt_commit_delta(&undo_fake, 802, UINT64_C(901)); + (void)make_commit_prepared(&terminal_fake, 802, 16384, UINT64_C(901), INT64_C(123456)); memset(storage_uuid, 0x42, sizeof(storage_uuid)); undo_identity = make_identity(&undo_fake, storage_uuid); terminal_identity = make_identity(&terminal_fake, storage_uuid); @@ -1571,12 +1513,11 @@ UT_TEST(test_online_plan_accepts_exact_preceding_tt_commit_dependency) memcpy(request.storage_uuid, storage_uuid, sizeof(storage_uuid)); request.physical_cuts = &cut; request.participant_count = 1; - UT_ASSERT_EQ(rf_side_online_plan_create_v1(&request, &plan), - RF_PAGE_PROOF_DETAIL_OK); - UT_ASSERT_EQ(rf_side_online_plan_feed_record_v1(plan, &undo_plan, - &undo_identity), RF_PAGE_PROOF_DETAIL_OK); - UT_ASSERT_EQ(rf_side_online_plan_feed_record_v1(plan, &terminal_plan, - &terminal_identity), RF_PAGE_PROOF_DETAIL_OK); + UT_ASSERT_EQ(rf_side_online_plan_create_v1(&request, &plan), RF_PAGE_PROOF_DETAIL_OK); + UT_ASSERT_EQ(rf_side_online_plan_feed_record_v1(plan, &undo_plan, &undo_identity), + RF_PAGE_PROOF_DETAIL_OK); + UT_ASSERT_EQ(rf_side_online_plan_feed_record_v1(plan, &terminal_plan, &terminal_identity), + RF_PAGE_PROOF_DETAIL_OK); UT_ASSERT_EQ(rf_side_online_plan_seal_v1(plan), RF_PAGE_PROOF_DETAIL_OK); memset(&capture, 0, sizeof(capture)); memset(&apply_ops, 0, sizeof(apply_ops)); @@ -1587,8 +1528,7 @@ UT_TEST(test_online_plan_accepts_exact_preceding_tt_commit_dependency) apply_ops.preflight_undo = accept_preflight; apply_ops.apply_xact = capture_apply; apply_ops.apply_undo = capture_apply_undo; - UT_ASSERT_EQ(rf_side_online_plan_apply_v1(plan, &apply_ops), - RF_PAGE_PROOF_DETAIL_OK); + UT_ASSERT_EQ(rf_side_online_plan_apply_v1(plan, &apply_ops), RF_PAGE_PROOF_DETAIL_OK); UT_ASSERT_EQ(capture.count, 1); UT_ASSERT_EQ(capture.undo_count, 1); UT_ASSERT(capture.end_complete); @@ -1613,8 +1553,8 @@ UT_TEST(test_online_plan_denies_abort_terminal_missing_tt_abort) prepare_record = make_prepare(&prepare_fake, 802, true, false); prepare_apply.native_payload_length = XLogRecGetDataLen(prepare_record); memcpy(prepare_apply.native_payload, XLogRecGetData(prepare_record), - prepare_apply.native_payload_length); - (void) make_abort_prepared(&terminal_fake, 802, 16384, UINT64_C(902)); + prepare_apply.native_payload_length); + (void)make_abort_prepared(&terminal_fake, 802, 16384, UINT64_C(902)); memset(storage_uuid, 0x42, sizeof(storage_uuid)); terminal_identity = make_identity(&terminal_fake, storage_uuid); terminal_plan = make_record_plan(&terminal_fake); @@ -1629,10 +1569,9 @@ UT_TEST(test_online_plan_denies_abort_terminal_missing_tt_abort) memcpy(request.storage_uuid, storage_uuid, sizeof(storage_uuid)); request.physical_cuts = &cut; request.participant_count = 1; - UT_ASSERT_EQ(rf_side_online_plan_create_v1(&request, &plan), - RF_PAGE_PROOF_DETAIL_OK); - UT_ASSERT_EQ(rf_side_online_plan_feed_record_v1(plan, &terminal_plan, - &terminal_identity), RF_PAGE_PROOF_DETAIL_OK); + UT_ASSERT_EQ(rf_side_online_plan_create_v1(&request, &plan), RF_PAGE_PROOF_DETAIL_OK); + UT_ASSERT_EQ(rf_side_online_plan_feed_record_v1(plan, &terminal_plan, &terminal_identity), + RF_PAGE_PROOF_DETAIL_OK); UT_ASSERT_EQ(rf_side_online_plan_seal_v1(plan), RF_PAGE_PROOF_DETAIL_OK); memset(&capture, 0, sizeof(capture)); memset(&apply_ops, 0, sizeof(apply_ops)); @@ -1642,7 +1581,7 @@ UT_TEST(test_online_plan_denies_abort_terminal_missing_tt_abort) apply_ops.preflight_xact = accept_preflight; apply_ops.apply_xact = capture_apply; UT_ASSERT_EQ(rf_side_online_plan_apply_v1(plan, &apply_ops), - RF_PAGE_PROOF_DETAIL_SIDE_INCOMPLETE); + RF_PAGE_PROOF_DETAIL_SIDE_INCOMPLETE); UT_ASSERT_EQ(capture.count, 0); UT_ASSERT(!capture.end_complete); rf_side_online_plan_destroy_v1(&plan); @@ -1669,10 +1608,10 @@ UT_TEST(test_online_plan_accepts_exact_preceding_tt_abort_dependency) prepare_record = make_prepare(&prepare_fake, 802, true, false); prepare_apply.native_payload_length = XLogRecGetDataLen(prepare_record); memcpy(prepare_apply.native_payload, XLogRecGetData(prepare_record), - prepare_apply.native_payload_length); - prepare_apply.slot.first_undo_block = (UBA) InvalidUba_init; - (void) make_tt_abort_delta(&abort_fake, 802); - (void) make_abort_prepared(&terminal_fake, 802, 16384, UINT64_C(902)); + prepare_apply.native_payload_length); + prepare_apply.slot.first_undo_block = (UBA)InvalidUba_init; + (void)make_tt_abort_delta(&abort_fake, 802); + (void)make_abort_prepared(&terminal_fake, 802, 16384, UINT64_C(902)); memset(storage_uuid, 0x42, sizeof(storage_uuid)); abort_identity = make_identity(&abort_fake, storage_uuid); terminal_identity = make_identity(&terminal_fake, storage_uuid); @@ -1690,12 +1629,11 @@ UT_TEST(test_online_plan_accepts_exact_preceding_tt_abort_dependency) memcpy(request.storage_uuid, storage_uuid, sizeof(storage_uuid)); request.physical_cuts = &cut; request.participant_count = 1; - UT_ASSERT_EQ(rf_side_online_plan_create_v1(&request, &plan), - RF_PAGE_PROOF_DETAIL_OK); - UT_ASSERT_EQ(rf_side_online_plan_feed_record_v1(plan, &abort_plan, - &abort_identity), RF_PAGE_PROOF_DETAIL_OK); - UT_ASSERT_EQ(rf_side_online_plan_feed_record_v1(plan, &terminal_plan, - &terminal_identity), RF_PAGE_PROOF_DETAIL_OK); + UT_ASSERT_EQ(rf_side_online_plan_create_v1(&request, &plan), RF_PAGE_PROOF_DETAIL_OK); + UT_ASSERT_EQ(rf_side_online_plan_feed_record_v1(plan, &abort_plan, &abort_identity), + RF_PAGE_PROOF_DETAIL_OK); + UT_ASSERT_EQ(rf_side_online_plan_feed_record_v1(plan, &terminal_plan, &terminal_identity), + RF_PAGE_PROOF_DETAIL_OK); UT_ASSERT_EQ(rf_side_online_plan_seal_v1(plan), RF_PAGE_PROOF_DETAIL_OK); memset(&capture, 0, sizeof(capture)); memset(&apply_ops, 0, sizeof(apply_ops)); @@ -1706,8 +1644,7 @@ UT_TEST(test_online_plan_accepts_exact_preceding_tt_abort_dependency) apply_ops.preflight_undo = accept_preflight; apply_ops.apply_xact = capture_apply; apply_ops.apply_undo = capture_apply_undo; - UT_ASSERT_EQ(rf_side_online_plan_apply_v1(plan, &apply_ops), - RF_PAGE_PROOF_DETAIL_OK); + UT_ASSERT_EQ(rf_side_online_plan_apply_v1(plan, &apply_ops), RF_PAGE_PROOF_DETAIL_OK); UT_ASSERT_EQ(capture.count, 1); UT_ASSERT_EQ(capture.undo_count, 1); UT_ASSERT(capture.end_complete); @@ -1738,15 +1675,14 @@ UT_TEST(test_online_plan_denies_nonempty_abort_without_undo_completion) head.raw[0] = UINT64_C(513) | (UINT64_C(9) << 32); head.raw[1] = UINT64_C(4); reset_prepare_apply(); - prepare_record = make_prepare_with_head(&prepare_fake, 802, true, false, - &head); + prepare_record = make_prepare_with_head(&prepare_fake, 802, true, false, &head); prepare_apply.native_payload_length = XLogRecGetDataLen(prepare_record); memcpy(prepare_apply.native_payload, XLogRecGetData(prepare_record), - prepare_apply.native_payload_length); + prepare_apply.native_payload_length); prepare_apply.slot.first_undo_block = head; - (void) make_tt_abort_delta(&abort_fake, 802); - (void) make_tt_set_head_delta(&head_fake, 802, &head); - (void) make_abort_prepared(&terminal_fake, 802, 16384, UINT64_C(902)); + (void)make_tt_abort_delta(&abort_fake, 802); + (void)make_tt_set_head_delta(&head_fake, 802, &head); + (void)make_abort_prepared(&terminal_fake, 802, 16384, UINT64_C(902)); memset(storage_uuid, 0x42, sizeof(storage_uuid)); abort_identity = make_identity(&abort_fake, storage_uuid); head_identity = make_identity(&head_fake, storage_uuid); @@ -1767,12 +1703,11 @@ UT_TEST(test_online_plan_denies_nonempty_abort_without_undo_completion) memcpy(request.storage_uuid, storage_uuid, sizeof(storage_uuid)); request.physical_cuts = &cut; request.participant_count = 1; - UT_ASSERT_EQ(rf_side_online_plan_create_v1(&request, &plan), - RF_PAGE_PROOF_DETAIL_OK); - UT_ASSERT_EQ(rf_side_online_plan_feed_record_v1(plan, &abort_plan, - &abort_identity), RF_PAGE_PROOF_DETAIL_OK); - UT_ASSERT_EQ(rf_side_online_plan_feed_record_v1(plan, &terminal_plan, - &terminal_identity), RF_PAGE_PROOF_DETAIL_OK); + UT_ASSERT_EQ(rf_side_online_plan_create_v1(&request, &plan), RF_PAGE_PROOF_DETAIL_OK); + UT_ASSERT_EQ(rf_side_online_plan_feed_record_v1(plan, &abort_plan, &abort_identity), + RF_PAGE_PROOF_DETAIL_OK); + UT_ASSERT_EQ(rf_side_online_plan_feed_record_v1(plan, &terminal_plan, &terminal_identity), + RF_PAGE_PROOF_DETAIL_OK); UT_ASSERT_EQ(rf_side_online_plan_seal_v1(plan), RF_PAGE_PROOF_DETAIL_OK); memset(&capture, 0, sizeof(capture)); memset(&apply_ops, 0, sizeof(apply_ops)); @@ -1784,21 +1719,20 @@ UT_TEST(test_online_plan_denies_nonempty_abort_without_undo_completion) apply_ops.apply_xact = capture_apply; apply_ops.apply_undo = capture_apply_undo; UT_ASSERT_EQ(rf_side_online_plan_apply_v1(plan, &apply_ops), - RF_PAGE_PROOF_DETAIL_SIDE_INCOMPLETE); + RF_PAGE_PROOF_DETAIL_SIDE_INCOMPLETE); UT_ASSERT_EQ(capture.count, 0); UT_ASSERT_EQ(capture.undo_count, 0); rf_side_online_plan_destroy_v1(&plan); cut.scan_end_exclusive = 400; set_identity_range(&terminal_fake, &terminal_identity, 300, 400); - UT_ASSERT_EQ(rf_side_online_plan_create_v1(&request, &plan), - RF_PAGE_PROOF_DETAIL_OK); - UT_ASSERT_EQ(rf_side_online_plan_feed_record_v1(plan, &abort_plan, - &abort_identity), RF_PAGE_PROOF_DETAIL_OK); - UT_ASSERT_EQ(rf_side_online_plan_feed_record_v1(plan, &head_plan, - &head_identity), RF_PAGE_PROOF_DETAIL_OK); - UT_ASSERT_EQ(rf_side_online_plan_feed_record_v1(plan, &terminal_plan, - &terminal_identity), RF_PAGE_PROOF_DETAIL_OK); + UT_ASSERT_EQ(rf_side_online_plan_create_v1(&request, &plan), RF_PAGE_PROOF_DETAIL_OK); + UT_ASSERT_EQ(rf_side_online_plan_feed_record_v1(plan, &abort_plan, &abort_identity), + RF_PAGE_PROOF_DETAIL_OK); + UT_ASSERT_EQ(rf_side_online_plan_feed_record_v1(plan, &head_plan, &head_identity), + RF_PAGE_PROOF_DETAIL_OK); + UT_ASSERT_EQ(rf_side_online_plan_feed_record_v1(plan, &terminal_plan, &terminal_identity), + RF_PAGE_PROOF_DETAIL_OK); UT_ASSERT_EQ(rf_side_online_plan_seal_v1(plan), RF_PAGE_PROOF_DETAIL_OK); memset(&capture, 0, sizeof(capture)); memset(&apply_ops, 0, sizeof(apply_ops)); @@ -1810,7 +1744,7 @@ UT_TEST(test_online_plan_denies_nonempty_abort_without_undo_completion) apply_ops.apply_xact = capture_apply; apply_ops.apply_undo = capture_apply_undo; UT_ASSERT_EQ(rf_side_online_plan_apply_v1(plan, &apply_ops), - RF_PAGE_PROOF_DETAIL_SIDE_INCOMPLETE); + RF_PAGE_PROOF_DETAIL_SIDE_INCOMPLETE); UT_ASSERT_EQ(capture.count, 0); UT_ASSERT_EQ(capture.undo_count, 0); UT_ASSERT(!capture.end_complete); diff --git a/src/test/cluster_unit/test_cluster_startup_phase.c b/src/test/cluster_unit/test_cluster_startup_phase.c index 29cc08dd14d..3cd0573d092 100644 --- a/src/test/cluster_unit/test_cluster_startup_phase.c +++ b/src/test/cluster_unit/test_cluster_startup_phase.c @@ -71,7 +71,9 @@ #include "unit_test.h" -#define STARTUP_PHASE_SOURCE_PATH "../../backend/cluster/cluster_startup_phase.c" +#ifndef STARTUP_PHASE_SOURCE_PATH +#error "STARTUP_PHASE_SOURCE_PATH must identify production cluster_startup_phase.c" +#endif static char * read_startup_phase_source(void) @@ -83,8 +85,7 @@ read_startup_phase_source(void) file = fopen(STARTUP_PHASE_SOURCE_PATH, "rb"); if (file == NULL) return NULL; - if (fseek(file, 0, SEEK_END) != 0 - || (length = ftell(file)) < 0 + if (fseek(file, 0, SEEK_END) != 0 || (length = ftell(file)) < 0 || fseek(file, 0, SEEK_SET) != 0) { fclose(file); return NULL; @@ -287,8 +288,7 @@ LWLockAcquire(LWLock *lock pg_attribute_unused(), LWLockMode mode pg_attribute_u } bool -LWLockConditionalAcquire(LWLock *lock pg_attribute_unused(), - LWLockMode mode pg_attribute_unused()) +LWLockConditionalAcquire(LWLock *lock pg_attribute_unused(), LWLockMode mode pg_attribute_unused()) { phase_lwlock_conditional_calls++; return phase_lwlock_conditional_result; @@ -365,8 +365,7 @@ static bool phase_test_cssd_spawn_ok = true; static bool phase_test_cssd_ready_ok = true; static bool phase_test_qvotec_spawn_ok = true; static bool phase_test_qvotec_ready_ok = true; -static ClusterFormationWitnessResult phase_test_formation_result - = CLUSTER_FORMATION_WITNESS_READY; +static ClusterFormationWitnessResult phase_test_formation_result = CLUSTER_FORMATION_WITNESS_READY; static int phase_test_formation_unavailable_attempts = 0; static int64 phase_test_formation_unavailable_advance_us = 0; static bool phase_test_classification_current = true; @@ -394,8 +393,7 @@ static uint64 phase_test_last_admitted_incarnation = 11; /* RF-ROOT P6 (L4/L5 wiring): steady-state defaults for the membership / * reconfig / GRD accessor stubs added below. */ static bool phase_test_membership_member = true; -static ClusterMembershipState phase_test_nonmember_state - = CLUSTER_MEMBER_JOINING; +static ClusterMembershipState phase_test_nonmember_state = CLUSTER_MEMBER_JOINING; static bool phase_test_self_join_admitted = false; static uint64 phase_test_episode_epoch = 0; static bool phase_test_join_remaster = false; @@ -540,8 +538,8 @@ cluster_wal_thread_id(void) ClusterFormationWitnessResult cluster_formation_witness_build_live_wait(uint16 origin_thread pg_attribute_unused(), - int timeout_ms pg_attribute_unused(), - ClusterFormationWitnessV1 **out) + int timeout_ms pg_attribute_unused(), + ClusterFormationWitnessV1 **out) { phase_test_live_formation_calls++; record_phase4_event('F'); @@ -554,14 +552,15 @@ cluster_formation_witness_build_live_wait(uint16 origin_thread pg_attribute_unus return CLUSTER_FORMATION_WITNESS_CAPABILITY_UNAVAILABLE; } *out = phase_test_formation_result == CLUSTER_FORMATION_WITNESS_READY - ? (ClusterFormationWitnessV1 *)(uintptr_t)1 : NULL; + ? (ClusterFormationWitnessV1 *)(uintptr_t)1 + : NULL; return phase_test_formation_result; } ClusterFormationWitnessResult -cluster_formation_witness_build_recovery_control_wait( - uint16 origin_thread pg_attribute_unused(), int timeout_ms pg_attribute_unused(), - ClusterFormationWitnessV1 **out) +cluster_formation_witness_build_recovery_control_wait(uint16 origin_thread pg_attribute_unused(), + int timeout_ms pg_attribute_unused(), + ClusterFormationWitnessV1 **out) { phase_test_recovery_control_formation_calls++; record_phase4_event('F'); @@ -572,7 +571,8 @@ cluster_formation_witness_build_recovery_control_wait( return CLUSTER_FORMATION_WITNESS_CAPABILITY_UNAVAILABLE; } *out = phase_test_formation_result == CLUSTER_FORMATION_WITNESS_READY - ? (ClusterFormationWitnessV1 *)(uintptr_t)1 : NULL; + ? (ClusterFormationWitnessV1 *)(uintptr_t)1 + : NULL; return phase_test_formation_result; } @@ -584,17 +584,15 @@ cluster_formation_witness_destroy(ClusterFormationWitnessV1 **witness) bool cluster_formation_witness_copy_classification_v1( - const ClusterFormationWitnessV1 *witness pg_attribute_unused(), - uint16 *origin_thread, ClusterFenceAuthorityProof *authority, - ClusterFormationSnapshotV1 *snapshot) + const ClusterFormationWitnessV1 *witness pg_attribute_unused(), uint16 *origin_thread, + ClusterFenceAuthorityProof *authority, ClusterFormationSnapshotV1 *snapshot) { record_phase4_event('X'); memset(authority, 0, sizeof(*authority)); memset(snapshot, 0, sizeof(*snapshot)); *origin_thread = 1; snapshot->membership.membership_state[0] = CLUSTER_MEMBER_MEMBER; - snapshot->membership.last_admitted_incarnation[0] - = phase_test_last_admitted_incarnation; + snapshot->membership.last_admitted_incarnation[0] = phase_test_last_admitted_incarnation; snapshot->reserved[0] = phase_test_formation_epoch; return true; } @@ -603,9 +601,8 @@ ClusterFormationWitnessResult cluster_formation_witness_revalidate_nowait( const ClusterFormationWitnessV1 *witness pg_attribute_unused()) { - return phase_test_classification_current - ? CLUSTER_FORMATION_WITNESS_READY - : CLUSTER_FORMATION_WITNESS_UNSTABLE; + return phase_test_classification_current ? CLUSTER_FORMATION_WITNESS_READY + : CLUSTER_FORMATION_WITNESS_UNSTABLE; } ClusterFormationWitnessResult @@ -614,31 +611,28 @@ cluster_formation_classification_revalidate_nowait( const ClusterFenceAuthorityProof *authority pg_attribute_unused(), const ClusterFormationSnapshotV1 *snapshot pg_attribute_unused()) { - return phase_test_classification_current - && snapshot->reserved[0] == phase_test_formation_epoch - ? CLUSTER_FORMATION_WITNESS_READY - : CLUSTER_FORMATION_WITNESS_UNSTABLE; + return phase_test_classification_current && snapshot->reserved[0] == phase_test_formation_epoch + ? CLUSTER_FORMATION_WITNESS_READY + : CLUSTER_FORMATION_WITNESS_UNSTABLE; } bool -cluster_formation_snapshot_matches_v1( - const ClusterFormationSnapshotV1 *expected, - const ClusterFormationSnapshotV1 *observed) +cluster_formation_snapshot_matches_v1(const ClusterFormationSnapshotV1 *expected, + const ClusterFormationSnapshotV1 *observed) { return expected != NULL && observed != NULL - && memcmp(expected, observed, sizeof(*expected)) == 0; + && memcmp(expected, observed, sizeof(*expected)) == 0; } bool -cluster_reconfig_capture_formation_snapshot_v1( - uint16 origin_thread, ClusterFormationSnapshotV1 *snapshot) +cluster_reconfig_capture_formation_snapshot_v1(uint16 origin_thread, + ClusterFormationSnapshotV1 *snapshot) { if (origin_thread != 1 || snapshot == NULL) return false; memset(snapshot, 0, sizeof(*snapshot)); snapshot->membership.membership_state[0] = CLUSTER_MEMBER_MEMBER; - snapshot->membership.last_admitted_incarnation[0] - = phase_test_last_admitted_incarnation; + snapshot->membership.last_admitted_incarnation[0] = phase_test_last_admitted_incarnation; snapshot->reserved[0] = phase_test_formation_epoch; return true; } @@ -657,9 +651,8 @@ cluster_membership_get_last_admitted_incarnation(int32 node_id pg_attribute_unus bool cluster_grd_recovery_authority_barrier_wait( - const ClusterFormationSnapshotV1 *formation pg_attribute_unused(), - uint64 boot_incarnation, uint64 lms_generation, - int timeout_ms pg_attribute_unused()) + const ClusterFormationSnapshotV1 *formation pg_attribute_unused(), uint64 boot_incarnation, + uint64 lms_generation, int timeout_ms pg_attribute_unused()) { bool saved_grd_authority_ok; @@ -670,47 +663,41 @@ cluster_grd_recovery_authority_barrier_wait( if (phase_test_publish_recovery_after_grd_barrier) { saved_grd_authority_ok = phase_test_grd_authority_ok; phase_test_grd_authority_ok = true; - UT_ASSERT(cluster_authority_readiness_publish_recovery( - lms_generation)); + UT_ASSERT(cluster_authority_readiness_publish_recovery(lms_generation)); phase_test_grd_authority_ok = saved_grd_authority_ok; } if (phase_test_drift_lms_generation_after_grd_barrier) phase_test_lms_generation++; return phase_test_grd_authority_ok && boot_incarnation == 11 - && lms_generation == phase_test_lms_generation; + && lms_generation == phase_test_lms_generation; } bool -cluster_grd_recovery_authority_is_current(uint64 boot_incarnation, - uint64 lms_generation) +cluster_grd_recovery_authority_is_current(uint64 boot_incarnation, uint64 lms_generation) { return phase_test_grd_authority_ok && boot_incarnation == 11 - && lms_generation == phase_test_lms_generation; + && lms_generation == phase_test_lms_generation; } bool -cluster_grd_serving_authority_rebind_lmon( - const ClusterFormationSnapshotV1 *formation, uint64 boot_incarnation, - uint64 lms_generation) +cluster_grd_serving_authority_rebind_lmon(const ClusterFormationSnapshotV1 *formation, + uint64 boot_incarnation, uint64 lms_generation) { return phase_test_grd_authority_ok && formation != NULL - && formation->reserved[0] == phase_test_formation_epoch - && boot_incarnation == 11 - && lms_generation == phase_test_lms_generation; + && formation->reserved[0] == phase_test_formation_epoch && boot_incarnation == 11 + && lms_generation == phase_test_lms_generation; } /* RF-ROOT P6 (L5 leaver serving rebind): cluster_startup_phase.o references * the leaver-side GRD rebind; the pure unit pins it to the same authority * gate as the LMON rebind above. */ bool -cluster_grd_serving_authority_rebind_leaver( - const ClusterFormationSnapshotV1 *formation, uint64 boot_incarnation, - uint64 lms_generation) +cluster_grd_serving_authority_rebind_leaver(const ClusterFormationSnapshotV1 *formation, + uint64 boot_incarnation, uint64 lms_generation) { return phase_test_grd_authority_ok && formation != NULL - && formation->reserved[0] == phase_test_formation_epoch - && boot_incarnation == 11 - && lms_generation == phase_test_lms_generation; + && formation->reserved[0] == phase_test_formation_epoch && boot_incarnation == 11 + && lms_generation == phase_test_lms_generation; } /* RF-ROOT P6 (L4/L5 wiring): unit stubs for the membership / reconfig / GRD @@ -725,8 +712,7 @@ cluster_membership_is_member(int32 node_id pg_attribute_unused()) ClusterMembershipState cluster_membership_get_state(int32 node_id pg_attribute_unused()) { - return phase_test_membership_member - ? CLUSTER_MEMBER_MEMBER : phase_test_nonmember_state; + return phase_test_membership_member ? CLUSTER_MEMBER_MEMBER : phase_test_nonmember_state; } bool @@ -742,18 +728,15 @@ cluster_reconfig_epoch0_late_founder_evidence_current(void) } bool -cluster_reconfig_stage_pre_publish_join_handoff( - uint64 expected_self_incarnation, uint64 expected_predecessor_floor) +cluster_reconfig_stage_pre_publish_join_handoff(uint64 expected_self_incarnation, + uint64 expected_predecessor_floor) { phase_test_join_readonly_handoff_calls++; - phase_test_join_readonly_handoff_incarnation - = expected_self_incarnation; - phase_test_join_readonly_handoff_predecessor_floor - = expected_predecessor_floor; + phase_test_join_readonly_handoff_incarnation = expected_self_incarnation; + phase_test_join_readonly_handoff_predecessor_floor = expected_predecessor_floor; phase_test_membership_member = false; phase_test_nonmember_state = CLUSTER_MEMBER_JOINING; - return expected_self_incarnation == 11 - && expected_predecessor_floor == 10; + return expected_self_incarnation == 11 && expected_predecessor_floor == 10; } uint64 @@ -774,8 +757,7 @@ cluster_grd_join_remaster_in_progress(void) * sequence assertions above are exact strings. */ void cluster_cf_phase2_verify_or_fail(const char *datadir pg_attribute_unused()) -{ -} +{} bool cluster_cf_phase2_peer_verified(void) @@ -813,8 +795,7 @@ bool cluster_lms_wait_for_recovery_ready(int timeout_ms pg_attribute_unused()) { record_phase4_event('r'); - if (phase_test_expire_formation_during_lms - && !phase_test_formation_expired) { + if (phase_test_expire_formation_during_lms && !phase_test_formation_expired) { phase_test_formation_epoch++; phase_test_formation_expired = true; } @@ -1058,10 +1039,8 @@ UT_TEST(test_rf_a1_no_pgproc_phase_reads_never_block) phase_lwlock_conditional_result = false; phase_lwlock_blocking_calls = 0; phase_lwlock_conditional_calls = 0; - UT_ASSERT_EQ((int)cluster_current_phase(), - (int)CLUSTER_PHASE_PRE_INIT); - UT_ASSERT_EQ((int)cluster_authority_readiness_get(), - (int)CLUSTER_AUTHORITY_OFF); + UT_ASSERT_EQ((int)cluster_current_phase(), (int)CLUSTER_PHASE_PRE_INIT); + UT_ASSERT_EQ((int)cluster_authority_readiness_get(), (int)CLUSTER_AUTHORITY_OFF); UT_ASSERT(!cluster_authority_readiness_managed()); /* * AD-023 A1 (lock-free branch): the three hot phase-state words are @@ -1076,8 +1055,7 @@ UT_TEST(test_rf_a1_no_pgproc_phase_reads_never_block) phase_lwlock_conditional_result = true; phase_lwlock_blocking_calls = 0; phase_lwlock_conditional_calls = 0; - UT_ASSERT_EQ((int)cluster_current_phase(), - (int)CLUSTER_PHASE_PRE_INIT); + UT_ASSERT_EQ((int)cluster_current_phase(), (int)CLUSTER_PHASE_PRE_INIT); UT_ASSERT_EQ(phase_lwlock_blocking_calls, 0); UT_ASSERT_EQ(phase_lwlock_conditional_calls, 0); @@ -1085,8 +1063,7 @@ UT_TEST(test_rf_a1_no_pgproc_phase_reads_never_block) MyProc = &fake_proc; phase_lwlock_blocking_calls = 0; phase_lwlock_conditional_calls = 0; - UT_ASSERT_EQ((int)cluster_current_phase(), - (int)CLUSTER_PHASE_PRE_INIT); + UT_ASSERT_EQ((int)cluster_current_phase(), (int)CLUSTER_PHASE_PRE_INIT); UT_ASSERT_EQ(phase_lwlock_blocking_calls, 0); UT_ASSERT_EQ(phase_lwlock_conditional_calls, 0); MyProc = NULL; @@ -1100,11 +1077,9 @@ UT_TEST(test_rf_a1_phase3_establishes_formation_and_phase4_does_not_respawn) cluster_voting_disks = "disk1,disk2,disk3"; cluster_run_startup_sequence(); - UT_ASSERT_EQ((int)cluster_current_phase(), - (int)CLUSTER_PHASE_3_RECOVERY); + UT_ASSERT_EQ((int)cluster_current_phase(), (int)CLUSTER_PHASE_3_RECOVERY); UT_ASSERT_STR_EQ(phase4_events, "CcQqVFXLrG"); - UT_ASSERT_EQ((int)cluster_authority_readiness_get(), - (int)CLUSTER_AUTHORITY_RECOVERY_READY); + UT_ASSERT_EQ((int)cluster_authority_readiness_get(), (int)CLUSTER_AUTHORITY_RECOVERY_READY); UT_ASSERT(cluster_recovery_authority_is_current()); UT_ASSERT(!cluster_serving_ready_is_current()); UT_ASSERT_EQ(phase_test_lms_start_calls, 1); @@ -1116,8 +1091,7 @@ UT_TEST(test_rf_a1_phase3_establishes_formation_and_phase4_does_not_respawn) UT_ASSERT_STR_EQ(phase4_events, "CcQqVFXLrGDdFXWlEESs"); UT_ASSERT_EQ(phase_test_lms_start_calls, 1); UT_ASSERT_EQ(phase_test_live_formation_calls, 1); - UT_ASSERT_EQ((int)cluster_authority_readiness_get(), - (int)CLUSTER_AUTHORITY_SERVING_READY); + UT_ASSERT_EQ((int)cluster_authority_readiness_get(), (int)CLUSTER_AUTHORITY_SERVING_READY); UT_ASSERT(cluster_serving_ready_is_current()); } @@ -1140,14 +1114,12 @@ UT_TEST(test_phase3_join_readonly_defers_authority_until_post_startup_admission) UT_ASSERT_STR_EQ(phase4_events, "CcQqV"); UT_ASSERT_EQ(phase_test_recovery_control_formation_calls, 0); UT_ASSERT_EQ(phase_test_lms_start_calls, 0); - UT_ASSERT_EQ((int)cluster_authority_readiness_get(), - (int)CLUSTER_AUTHORITY_OFF); + UT_ASSERT_EQ((int)cluster_authority_readiness_get(), (int)CLUSTER_AUTHORITY_OFF); /* StartupXLOG has returned. The unchanged stripe/JOIN-WAL/JCMK path now * admits this boot; only then may the same phase-3 recovery state machine * complete before phase 4 publishes ordinary serving. */ - phase4_test_now = (TimestampTz)(cluster_phase3_timeout + 60) - * INT64CONST(1000000); + phase4_test_now = (TimestampTz)(cluster_phase3_timeout + 60) * INT64CONST(1000000); phase_test_membership_member = true; phase_test_self_join_admitted = true; phase4_capture_fatal = true; @@ -1160,8 +1132,7 @@ UT_TEST(test_phase3_join_readonly_defers_authority_until_post_startup_admission) UT_ASSERT_STR_EQ(phase4_events, "CcQqVFXLrGDdFXWlEESs"); UT_ASSERT_EQ(phase_test_recovery_control_formation_calls, 1); UT_ASSERT_EQ(phase_test_lms_start_calls, 1); - UT_ASSERT_EQ((int)cluster_authority_readiness_get(), - (int)CLUSTER_AUTHORITY_SERVING_READY); + UT_ASSERT_EQ((int)cluster_authority_readiness_get(), (int)CLUSTER_AUTHORITY_SERVING_READY); } /* A transient bootstrap HOLD may expose JOINING before any peer from the @@ -1182,8 +1153,7 @@ UT_TEST(test_phase3_joining_without_exact_peer_active_stays_recovery_control) UT_ASSERT_STR_EQ(phase4_events, "CcQqVFXLrG"); UT_ASSERT_EQ(phase_test_recovery_control_formation_calls, 1); UT_ASSERT_EQ(phase_test_grd_barrier_calls, 1); - UT_ASSERT_EQ((int)cluster_authority_readiness_get(), - (int)CLUSTER_AUTHORITY_RECOVERY_READY); + UT_ASSERT_EQ((int)cluster_authority_readiness_get(), (int)CLUSTER_AUTHORITY_RECOVERY_READY); } UT_TEST(test_phase3_epoch0_late_founder_defers_only_with_exact_current_evidence) @@ -1203,8 +1173,7 @@ UT_TEST(test_phase3_epoch0_late_founder_defers_only_with_exact_current_evidence) UT_ASSERT_STR_EQ(phase4_events, "CcQqV"); UT_ASSERT_EQ(phase_test_recovery_control_formation_calls, 0); UT_ASSERT_EQ(phase_test_lms_start_calls, 0); - UT_ASSERT_EQ((int)cluster_authority_readiness_get(), - (int)CLUSTER_AUTHORITY_OFF); + UT_ASSERT_EQ((int)cluster_authority_readiness_get(), (int)CLUSTER_AUTHORITY_OFF); /* Missing exact epoch-0 peer evidence preserves the existing recovery- * control path; CFP2 alone is never admission or a stripe owner. */ @@ -1258,8 +1227,7 @@ UT_TEST(test_phase3_pre_published_recovery_pivots_once_to_join_readonly) UT_ASSERT(cluster_authority_handoff_identity_current(11, 10)); UT_ASSERT_EQ(phase_test_recovery_control_formation_calls, 1); UT_ASSERT_EQ(phase_test_lms_start_calls, 1); - UT_ASSERT_EQ((int)cluster_authority_readiness_get(), - (int)CLUSTER_AUTHORITY_OFF); + UT_ASSERT_EQ((int)cluster_authority_readiness_get(), (int)CLUSTER_AUTHORITY_OFF); /* The pivot owns no admission. Only the existing terminal ordinary join * permits Phase 4 to rebuild authority, reusing the same idle LMS. */ @@ -1275,8 +1243,7 @@ UT_TEST(test_phase3_pre_published_recovery_pivots_once_to_join_readonly) phase4_capture_fatal = false; UT_ASSERT(!caught_fatal); UT_ASSERT_EQ(phase_test_lms_start_calls, 1); - UT_ASSERT_EQ((int)cluster_authority_readiness_get(), - (int)CLUSTER_AUTHORITY_SERVING_READY); + UT_ASSERT_EQ((int)cluster_authority_readiness_get(), (int)CLUSTER_AUTHORITY_SERVING_READY); } /* The handoff owns only the exact reversible STARTING generation captured by @@ -1358,8 +1325,7 @@ UT_TEST(test_phase3_join_readonly_obeys_existing_join_failure_terminal) UT_ASSERT(caught_fatal); UT_ASSERT_STR_EQ(phase4_events, "CcQqV"); UT_ASSERT_EQ(phase_test_lms_start_calls, 0); - UT_ASSERT_EQ((int)cluster_authority_readiness_get(), - (int)CLUSTER_AUTHORITY_OFF); + UT_ASSERT_EQ((int)cluster_authority_readiness_get(), (int)CLUSTER_AUTHORITY_OFF); } UT_TEST(test_rf_a1_phase4_waits_for_stripe_admission_before_serving) @@ -1371,8 +1337,7 @@ UT_TEST(test_rf_a1_phase4_waits_for_stripe_admission_before_serving) phase_test_self_join_admitted = false; cluster_phase4_timeout = 1; cluster_run_startup_sequence(); - UT_ASSERT_EQ((int)cluster_authority_readiness_get(), - (int)CLUSTER_AUTHORITY_RECOVERY_READY); + UT_ASSERT_EQ((int)cluster_authority_readiness_get(), (int)CLUSTER_AUTHORITY_RECOVERY_READY); phase4_capture_fatal = true; if (setjmp(phase4_fatal_jump) == 0) @@ -1385,8 +1350,7 @@ UT_TEST(test_rf_a1_phase4_waits_for_stripe_admission_before_serving) UT_ASSERT(caught_fatal); UT_ASSERT(strchr(phase4_events, 'W') == NULL); UT_ASSERT_EQ(phase_test_live_formation_calls, 0); - UT_ASSERT_EQ((int)cluster_authority_readiness_get(), - (int)CLUSTER_AUTHORITY_RECOVERY_READY); + UT_ASSERT_EQ((int)cluster_authority_readiness_get(), (int)CLUSTER_AUTHORITY_RECOVERY_READY); } @@ -1396,8 +1360,7 @@ UT_TEST(test_rf_a1_phase4_refreshes_expired_recovery_proof_before_serving) reset_phase_service_fixture(true); cluster_run_startup_sequence(); - UT_ASSERT_EQ((int)cluster_authority_readiness_get(), - (int)CLUSTER_AUTHORITY_RECOVERY_READY); + UT_ASSERT_EQ((int)cluster_authority_readiness_get(), (int)CLUSTER_AUTHORITY_RECOVERY_READY); /* The phase-3 cache can expire while StartupXLOG and the exact stripe * admission complete. A post-admission live reread must refresh the same @@ -1414,8 +1377,7 @@ UT_TEST(test_rf_a1_phase4_refreshes_expired_recovery_proof_before_serving) UT_ASSERT(!caught_fatal); UT_ASSERT_EQ(phase_test_live_formation_calls, 1); UT_ASSERT(strstr(phase4_events, "DdFXW") != NULL); - UT_ASSERT_EQ((int)cluster_authority_readiness_get(), - (int)CLUSTER_AUTHORITY_SERVING_READY); + UT_ASSERT_EQ((int)cluster_authority_readiness_get(), (int)CLUSTER_AUTHORITY_SERVING_READY); } @@ -1429,8 +1391,7 @@ UT_TEST(test_rf_a2_serving_does_not_consume_recovery_duty_cache) * formation and sealed serving generation remain current. */ phase_test_classification_current = false; UT_ASSERT(cluster_serving_ready_is_current()); - UT_ASSERT_EQ((int)cluster_authority_readiness_get(), - (int)CLUSTER_AUTHORITY_SERVING_READY); + UT_ASSERT_EQ((int)cluster_authority_readiness_get(), (int)CLUSTER_AUTHORITY_SERVING_READY); } @@ -1442,8 +1403,7 @@ UT_TEST(test_rf_a2_serving_rebinds_only_after_lmon_closes_recovery) phase_test_formation_epoch++; UT_ASSERT(!cluster_serving_ready_is_current()); - UT_ASSERT_EQ((int)cluster_authority_readiness_get(), - (int)CLUSTER_AUTHORITY_SERVING_READY); + UT_ASSERT_EQ((int)cluster_authority_readiness_get(), (int)CLUSTER_AUTHORITY_SERVING_READY); UT_ASSERT(cluster_authority_serving_rebind_lmon()); UT_ASSERT(cluster_serving_ready_is_current()); } @@ -1453,8 +1413,7 @@ UT_TEST(test_rf_a1_readiness_is_monotone_and_generation_bound) ClusterResId recovery_resid; reset_phase_service_fixture(true); - UT_ASSERT_EQ((int)cluster_authority_readiness_get(), - (int)CLUSTER_AUTHORITY_OFF); + UT_ASSERT_EQ((int)cluster_authority_readiness_get(), (int)CLUSTER_AUTHORITY_OFF); UT_ASSERT(!cluster_authority_readiness_publish_serving()); cluster_run_startup_sequence(); @@ -1462,20 +1421,16 @@ UT_TEST(test_rf_a1_readiness_is_monotone_and_generation_bound) memset(&recovery_resid, 0, sizeof(recovery_resid)); recovery_resid.type = CLUSTER_CF_RESID_TYPE; recovery_resid.lockmethodid = DEFAULT_LOCKMETHOD; - UT_ASSERT(cluster_recovery_authority_request_allowed( - &recovery_resid, ShareLock, true)); + UT_ASSERT(cluster_recovery_authority_request_allowed(&recovery_resid, ShareLock, true)); recovery_resid.field1 = 1; - UT_ASSERT(!cluster_recovery_authority_request_allowed( - &recovery_resid, ShareLock, true)); + UT_ASSERT(!cluster_recovery_authority_request_allowed(&recovery_resid, ShareLock, true)); memset(&recovery_resid, 0, sizeof(recovery_resid)); recovery_resid.field1 = 1; recovery_resid.type = CLUSTER_WAL_RETENTION_RESID_TYPE; recovery_resid.lockmethodid = DEFAULT_LOCKMETHOD; - UT_ASSERT(cluster_recovery_authority_request_allowed( - &recovery_resid, ExclusiveLock, true)); + UT_ASSERT(cluster_recovery_authority_request_allowed(&recovery_resid, ExclusiveLock, true)); recovery_resid.field1 = 0; - UT_ASSERT(!cluster_recovery_authority_request_allowed( - &recovery_resid, ExclusiveLock, true)); + UT_ASSERT(!cluster_recovery_authority_request_allowed(&recovery_resid, ExclusiveLock, true)); phase_test_lms_generation++; UT_ASSERT(!cluster_recovery_authority_is_current()); UT_ASSERT(!cluster_serving_ready_is_current()); @@ -1510,30 +1465,25 @@ UT_TEST(test_rf_a1_transport_stale_clear_skips_mid_bind_gen_zero) formation.membership.last_admitted_incarnation[0] = 11; formation.reserved[0] = phase_test_formation_epoch; UT_ASSERT(cluster_authority_readiness_begin(1, &authority, &formation)); - UT_ASSERT_EQ((int)cluster_authority_readiness_get(), - (int)CLUSTER_AUTHORITY_STARTING); + UT_ASSERT_EQ((int)cluster_authority_readiness_get(), (int)CLUSTER_AUTHORITY_STARTING); /* The transport check fails on the unbound generation, but the binding * is mid-bind, NOT stale: the stale-clear is gated on * lms_generation != 0 (STOP-01 contract), so a peer DONE ingress * during the window cannot destroy the STARTING binding. */ UT_ASSERT(!cluster_recovery_transport_is_current()); - UT_ASSERT_EQ((int)cluster_authority_readiness_get(), - (int)CLUSTER_AUTHORITY_STARTING); + UT_ASSERT_EQ((int)cluster_authority_readiness_get(), (int)CLUSTER_AUTHORITY_STARTING); /* Once the loop binds the generation, the same check passes... */ - UT_ASSERT(cluster_authority_readiness_bind_recovery_generation( - phase_test_lms_generation)); + UT_ASSERT(cluster_authority_readiness_bind_recovery_generation(phase_test_lms_generation)); UT_ASSERT(cluster_recovery_transport_is_current()); - UT_ASSERT_EQ((int)cluster_authority_readiness_get(), - (int)CLUSTER_AUTHORITY_STARTING); + UT_ASSERT_EQ((int)cluster_authority_readiness_get(), (int)CLUSTER_AUTHORITY_STARTING); /* ... and a BOUND generation whose formation drifted from the live * formation IS stale: the transport check clears it (fail-closed). */ phase_test_classification_current = false; UT_ASSERT(!cluster_recovery_transport_is_current()); - UT_ASSERT_EQ((int)cluster_authority_readiness_get(), - (int)CLUSTER_AUTHORITY_OFF); + UT_ASSERT_EQ((int)cluster_authority_readiness_get(), (int)CLUSTER_AUTHORITY_OFF); phase_test_classification_current = true; } @@ -1558,8 +1508,7 @@ UT_TEST(test_rf_a1_missing_authoritative_grd_stops_before_recovery) * deadline, so the event stream keeps the phase-3 prefix and adds * repeated witness/classification/barrier cycles before the FATAL. */ UT_ASSERT(strncmp(phase4_events, "CcQqVFXLrG", 10) == 0); - UT_ASSERT_EQ((int)cluster_authority_readiness_get(), - (int)CLUSTER_AUTHORITY_OFF); + UT_ASSERT_EQ((int)cluster_authority_readiness_get(), (int)CLUSTER_AUTHORITY_OFF); } @@ -1578,8 +1527,7 @@ UT_TEST(test_rf_a1_refreshes_formation_if_proof_expires_during_lms_start) UT_ASSERT(!caught_fatal); UT_ASSERT_STR_EQ(phase4_events, "CcQqVFXLrFXG"); - UT_ASSERT_EQ((int)cluster_authority_readiness_get(), - (int)CLUSTER_AUTHORITY_RECOVERY_READY); + UT_ASSERT_EQ((int)cluster_authority_readiness_get(), (int)CLUSTER_AUTHORITY_RECOVERY_READY); } @@ -1698,8 +1646,7 @@ UT_TEST(test_rf_a1_phase3_retries_no_pgproc_snapshot_contention) UT_ASSERT(!caught_fatal); UT_ASSERT_STR_EQ(phase4_events, "CcQqVFFXLrG"); - UT_ASSERT_EQ((int)cluster_authority_readiness_get(), - (int)CLUSTER_AUTHORITY_RECOVERY_READY); + UT_ASSERT_EQ((int)cluster_authority_readiness_get(), (int)CLUSTER_AUTHORITY_RECOVERY_READY); } @@ -1722,8 +1669,7 @@ UT_TEST(test_rf_a1_phase3_snapshot_contention_expires_fail_closed) UT_ASSERT(caught_fatal); UT_ASSERT_STR_EQ(phase4_events, "CcQqVF"); - UT_ASSERT_EQ((int)cluster_authority_readiness_get(), - (int)CLUSTER_AUTHORITY_OFF); + UT_ASSERT_EQ((int)cluster_authority_readiness_get(), (int)CLUSTER_AUTHORITY_OFF); } @@ -1801,24 +1747,22 @@ UT_TEST(test_join_readonly_rebuild_binds_generation_once_per_iteration) const char *function_end; const char *function_start; const char *match; - const char *needle - = "cluster_authority_readiness_bind_recovery_generation("; + const char *needle = "cluster_authority_readiness_bind_recovery_generation("; char *source = read_startup_phase_source(); int count = 0; UT_ASSERT_NOT_NULL(source); if (source == NULL) return; - function_start = strstr(source, - "\ncluster_phase4_establish_join_readonly_authority("); - function_end = function_start == NULL ? NULL - : strstr(function_start, "\n\n/*\n * cluster_phase_remaining_budget_ms"); + function_start = strstr(source, "\ncluster_phase4_establish_join_readonly_authority("); + function_end = function_start == NULL + ? NULL + : strstr(function_start, "\n\n/*\n * cluster_phase_remaining_budget_ms"); UT_ASSERT_NOT_NULL(function_start); UT_ASSERT_NOT_NULL(function_end); if (function_start != NULL && function_end != NULL) { match = function_start; - while ((match = strstr(match, needle)) != NULL - && match < function_end) { + while ((match = strstr(match, needle)) != NULL && match < function_end) { count++; match += strlen(needle); } diff --git a/src/test/cluster_unit/test_cluster_stats.c b/src/test/cluster_unit/test_cluster_stats.c index 4ee0dbf9e15..69aeafbe9c3 100644 --- a/src/test/cluster_unit/test_cluster_stats.c +++ b/src/test/cluster_unit/test_cluster_stats.c @@ -393,8 +393,7 @@ cluster_wal_state_read_slot(uint16 thread_id, ClusterWalStateSlot *slot_out) } ClusterWalStateUpdateResult -cluster_wal_state_update_own(const ClusterWalStateUpdate *update, - ClusterWalStateCfMode cf_mode, +cluster_wal_state_update_own(const ClusterWalStateUpdate *update, ClusterWalStateCfMode cf_mode, ClusterWalStateSlot *published_slot pg_attribute_unused()) { UT_ASSERT_EQ((int)cf_mode, (int)CLUSTER_WAL_STATE_CF_ACQUIRE_X); @@ -523,8 +522,7 @@ UT_TEST(test_rf_a1_initial_stats_owns_active_checkpoint_then_telemetry) UT_ASSERT_EQ(stats_test_self_check_calls, 1); UT_ASSERT_EQ(stats_test_active_calls, 1); UT_ASSERT_EQ((int)stats_test_active_status, (int)CLUSTER_STATS_SPAWNING); - UT_ASSERT_EQ((int)stats_test_active_update.kind, - (int)CLUSTER_WAL_STATE_UPDATE_ACTIVE); + UT_ASSERT_EQ((int)stats_test_active_update.kind, (int)CLUSTER_WAL_STATE_UPDATE_ACTIVE); UT_ASSERT_EQ((int)stats_test_active_update.tli, 7); UT_ASSERT_EQ((uint64)stats_test_active_update.highest_lsn, (uint64)300); UT_ASSERT_EQ((uint64)stats_test_active_update.highest_scn, (uint64)400); @@ -534,8 +532,7 @@ UT_TEST(test_rf_a1_initial_stats_owns_active_checkpoint_then_telemetry) CHECKPOINT_IMMEDIATE | CHECKPOINT_FORCE | CHECKPOINT_WAIT); UT_ASSERT_EQ(stats_test_telemetry_calls, 1); UT_ASSERT_EQ((int)stats_test_telemetry_status, (int)CLUSTER_STATS_READY); - UT_ASSERT_EQ((int)stats_test_telemetry_update.kind, - (int)CLUSTER_WAL_STATE_UPDATE_TELEMETRY); + UT_ASSERT_EQ((int)stats_test_telemetry_update.kind, (int)CLUSTER_WAL_STATE_UPDATE_TELEMETRY); UT_ASSERT_EQ((int)stats_test_telemetry_update.tli, 7); UT_ASSERT_EQ((int64)stats_test_telemetry_update.started_at, (int64)0); UT_ASSERT_EQ((uint64)stats_test_telemetry_update.highest_lsn, (uint64)300); diff --git a/src/test/cluster_unit/test_cluster_subtrans.c b/src/test/cluster_unit/test_cluster_subtrans.c index 869e93e830d..abd9c81bbb8 100644 --- a/src/test/cluster_unit/test_cluster_subtrans.c +++ b/src/test/cluster_unit/test_cluster_subtrans.c @@ -118,16 +118,16 @@ cluster_subtrans_get_xact_has_state_check_count(void) ClusterSemanticAdmissionResult cluster_tt_status_source_dispatch(ClusterTTStatusSourceOp op pg_attribute_unused(), - const ClusterTTStatusSourceRequest *request pg_attribute_unused(), - ClusterTTStatusSourceResult *result pg_attribute_unused()) + const ClusterTTStatusSourceRequest *request pg_attribute_unused(), + ClusterTTStatusSourceResult *result pg_attribute_unused()) { return CLUSTER_SEMANTIC_ADMISSION_CLOSED; } ClusterSemanticAdmissionResult -cluster_tt_status_hint_source_dispatch( - ClusterTTStatusHintSourceOp op pg_attribute_unused(), - const ClusterTTStatusHintSourceRequest *request pg_attribute_unused()) +cluster_tt_status_hint_source_dispatch(ClusterTTStatusHintSourceOp op pg_attribute_unused(), + const ClusterTTStatusHintSourceRequest *request + pg_attribute_unused()) { return CLUSTER_SEMANTIC_ADMISSION_CLOSED; } diff --git a/src/test/cluster_unit/test_cluster_terminal_ref_census.c b/src/test/cluster_unit/test_cluster_terminal_ref_census.c index 1e8bf18f1b4..b31cad8a785 100644 --- a/src/test/cluster_unit/test_cluster_terminal_ref_census.c +++ b/src/test/cluster_unit/test_cluster_terminal_ref_census.c @@ -3093,7 +3093,10 @@ typedef struct CtrcTestCase { CtrcTestFn function; } CtrcTestCase; -#define CTRC_TEST_ENTRY(name) { #name, name } +#define CTRC_TEST_ENTRY(name) \ + { \ + #name, name \ + } int main(void) diff --git a/src/test/cluster_unit/test_cluster_thread_orchestrator.c b/src/test/cluster_unit/test_cluster_thread_orchestrator.c index 1e290fc6fb7..cf1bf4a6af0 100644 --- a/src/test/cluster_unit/test_cluster_thread_orchestrator.c +++ b/src/test/cluster_unit/test_cluster_thread_orchestrator.c @@ -210,8 +210,7 @@ UT_TEST(test_worker_terminal_state_done_only_for_done) { ClusterThreadRecReplayState state = CLUSTER_THREADREC_REPLAY_IDLE; - UT_ASSERT(cluster_thread_recovery_worker_terminal_state( - CLUSTER_THREADREC_DONE, &state)); + UT_ASSERT(cluster_thread_recovery_worker_terminal_state(CLUSTER_THREADREC_DONE, &state)); UT_ASSERT_EQ((int)state, (int)CLUSTER_THREADREC_REPLAY_DONE); } @@ -219,8 +218,7 @@ UT_TEST(test_worker_terminal_state_blocked_is_blocked) { ClusterThreadRecReplayState state = CLUSTER_THREADREC_REPLAY_IDLE; - UT_ASSERT(cluster_thread_recovery_worker_terminal_state( - CLUSTER_THREADREC_BLOCKED, &state)); + UT_ASSERT(cluster_thread_recovery_worker_terminal_state(CLUSTER_THREADREC_BLOCKED, &state)); UT_ASSERT_EQ((int)state, (int)CLUSTER_THREADREC_REPLAY_BLOCKED); } @@ -231,29 +229,23 @@ UT_TEST(test_worker_deferred_is_numeric_three_and_nonterminal) /* STOP03 U12: DEFERRED is result value 3, but must never be cast/stored as * replay-slot BLOCKED (also numeric 3). Only DONE/BLOCKED are terminal. */ UT_ASSERT_EQ((int)CLUSTER_THREADREC_DEFERRED, 3); - UT_ASSERT(!cluster_thread_recovery_worker_terminal_state( - CLUSTER_THREADREC_DEFERRED, &state)); + UT_ASSERT(!cluster_thread_recovery_worker_terminal_state(CLUSTER_THREADREC_DEFERRED, &state)); UT_ASSERT_EQ((int)state, (int)CLUSTER_THREADREC_REPLAY_BLOCKED); - UT_ASSERT(!cluster_thread_recovery_worker_terminal_state( - CLUSTER_THREADREC_NOT_APPLICABLE, &state)); + UT_ASSERT( + !cluster_thread_recovery_worker_terminal_state(CLUSTER_THREADREC_NOT_APPLICABLE, &state)); UT_ASSERT_EQ((int)CLUSTER_THREADREC_MATCH_CHANGED, 0); UT_ASSERT_EQ((int)CLUSTER_THREADREC_MATCH_INVALID, 3); UT_ASSERT(cluster_thread_recovery_replay_transition_shape_valid( - CLUSTER_THREADREC_REPLAY_REPLAYING, - CLUSTER_THREADREC_REPLAY_IDLE)); + CLUSTER_THREADREC_REPLAY_REPLAYING, CLUSTER_THREADREC_REPLAY_IDLE)); UT_ASSERT(cluster_thread_recovery_replay_transition_shape_valid( - CLUSTER_THREADREC_REPLAY_REPLAYING, - CLUSTER_THREADREC_REPLAY_DONE)); + CLUSTER_THREADREC_REPLAY_REPLAYING, CLUSTER_THREADREC_REPLAY_DONE)); UT_ASSERT(cluster_thread_recovery_replay_transition_shape_valid( - CLUSTER_THREADREC_REPLAY_REPLAYING, - CLUSTER_THREADREC_REPLAY_BLOCKED)); + CLUSTER_THREADREC_REPLAY_REPLAYING, CLUSTER_THREADREC_REPLAY_BLOCKED)); UT_ASSERT(!cluster_thread_recovery_replay_transition_shape_valid( - CLUSTER_THREADREC_REPLAY_IDLE, - CLUSTER_THREADREC_REPLAY_REPLAYING)); + CLUSTER_THREADREC_REPLAY_IDLE, CLUSTER_THREADREC_REPLAY_REPLAYING)); UT_ASSERT(!cluster_thread_recovery_replay_transition_shape_valid( - CLUSTER_THREADREC_REPLAY_REPLAYING, - CLUSTER_THREADREC_REPLAY_REPLAYING)); + CLUSTER_THREADREC_REPLAY_REPLAYING, CLUSTER_THREADREC_REPLAY_REPLAYING)); } UT_TEST(test_a2_reap_decision_matrix) @@ -261,37 +253,35 @@ UT_TEST(test_a2_reap_decision_matrix) uint64 stamp = UINT64_C(77); UT_ASSERT_EQ((int)cluster_thread_recovery_reap_decide( - BGWH_STARTED, true, stamp, CLUSTER_THREADREC_REPLAY_REPLAYING, - stamp), (int)CLUSTER_THREADREC_REAP_RETAIN); - UT_ASSERT_EQ((int)cluster_thread_recovery_reap_decide( - BGWH_NOT_YET_STARTED, true, stamp, - CLUSTER_THREADREC_REPLAY_REPLAYING, stamp), - (int)CLUSTER_THREADREC_REAP_RETAIN); - UT_ASSERT_EQ((int)cluster_thread_recovery_reap_decide( - BGWH_POSTMASTER_DIED, true, stamp, - CLUSTER_THREADREC_REPLAY_REPLAYING, stamp), - (int)CLUSTER_THREADREC_REAP_RETAIN); - UT_ASSERT_EQ((int)cluster_thread_recovery_reap_decide( - BGWH_STOPPED, true, stamp, CLUSTER_THREADREC_REPLAY_REPLAYING, - stamp), (int)CLUSTER_THREADREC_REAP_RESET_IDLE); - UT_ASSERT_EQ((int)cluster_thread_recovery_reap_decide( - BGWH_STOPPED, true, stamp, CLUSTER_THREADREC_REPLAY_DONE, - stamp), (int)CLUSTER_THREADREC_REAP_KEEP_TERMINAL); + BGWH_STARTED, true, stamp, CLUSTER_THREADREC_REPLAY_REPLAYING, stamp), + (int)CLUSTER_THREADREC_REAP_RETAIN); UT_ASSERT_EQ((int)cluster_thread_recovery_reap_decide( - BGWH_STOPPED, true, stamp, CLUSTER_THREADREC_REPLAY_BLOCKED, - stamp), (int)CLUSTER_THREADREC_REAP_KEEP_TERMINAL); + BGWH_NOT_YET_STARTED, true, stamp, CLUSTER_THREADREC_REPLAY_REPLAYING, stamp), + (int)CLUSTER_THREADREC_REAP_RETAIN); UT_ASSERT_EQ((int)cluster_thread_recovery_reap_decide( - BGWH_STOPPED, false, stamp, CLUSTER_THREADREC_REPLAY_REPLAYING, - stamp), (int)CLUSTER_THREADREC_REAP_INVALID); + BGWH_POSTMASTER_DIED, true, stamp, CLUSTER_THREADREC_REPLAY_REPLAYING, stamp), + (int)CLUSTER_THREADREC_REAP_RETAIN); UT_ASSERT_EQ((int)cluster_thread_recovery_reap_decide( - BGWH_STOPPED, true, stamp, CLUSTER_THREADREC_REPLAY_IDLE, - stamp), (int)CLUSTER_THREADREC_REAP_INVALID); + BGWH_STOPPED, true, stamp, CLUSTER_THREADREC_REPLAY_REPLAYING, stamp), + (int)CLUSTER_THREADREC_REAP_RESET_IDLE); + UT_ASSERT_EQ((int)cluster_thread_recovery_reap_decide(BGWH_STOPPED, true, stamp, + CLUSTER_THREADREC_REPLAY_DONE, stamp), + (int)CLUSTER_THREADREC_REAP_KEEP_TERMINAL); + UT_ASSERT_EQ((int)cluster_thread_recovery_reap_decide(BGWH_STOPPED, true, stamp, + CLUSTER_THREADREC_REPLAY_BLOCKED, stamp), + (int)CLUSTER_THREADREC_REAP_KEEP_TERMINAL); UT_ASSERT_EQ((int)cluster_thread_recovery_reap_decide( - BGWH_STOPPED, true, stamp, CLUSTER_THREADREC_REPLAY_REPLAYING, - stamp + 1), (int)CLUSTER_THREADREC_REAP_INVALID); + BGWH_STOPPED, false, stamp, CLUSTER_THREADREC_REPLAY_REPLAYING, stamp), + (int)CLUSTER_THREADREC_REAP_INVALID); + UT_ASSERT_EQ((int)cluster_thread_recovery_reap_decide(BGWH_STOPPED, true, stamp, + CLUSTER_THREADREC_REPLAY_IDLE, stamp), + (int)CLUSTER_THREADREC_REAP_INVALID); UT_ASSERT_EQ((int)cluster_thread_recovery_reap_decide( - BGWH_STOPPED, true, 0, CLUSTER_THREADREC_REPLAY_REPLAYING, 0), - (int)CLUSTER_THREADREC_REAP_INVALID); + BGWH_STOPPED, true, stamp, CLUSTER_THREADREC_REPLAY_REPLAYING, stamp + 1), + (int)CLUSTER_THREADREC_REAP_INVALID); + UT_ASSERT_EQ((int)cluster_thread_recovery_reap_decide(BGWH_STOPPED, true, 0, + CLUSTER_THREADREC_REPLAY_REPLAYING, 0), + (int)CLUSTER_THREADREC_REAP_INVALID); } static ClusterRecoveryDutyKey @@ -309,9 +299,8 @@ valid_a2_duty(uint16 origin_thread) duty.origin_thread_id = origin_thread; duty.origin_node_id = (int32)origin_thread - 1; duty.thread_claim_created_at = INT64_C(77); - cluster_wal_thread_claim_fill(&claim, origin_thread, - duty.origin_node_id, - duty.thread_claim_created_at); + cluster_wal_thread_claim_fill(&claim, origin_thread, duty.origin_node_id, + duty.thread_claim_created_at); duty.thread_claim_crc32c = claim.crc; duty.origin_owner_incarnation = UINT64_C(9); duty.root_lineage_seq = UINT64_C(10); @@ -329,27 +318,20 @@ UT_TEST(test_a2_worker_payload_fresh_validation) eligibility.duty = valid_a2_duty(thread); UT_ASSERT(cluster_thread_recovery_worker_start_valid( - &eligibility, thread, true, CLUSTER_THREADREC_REPLAY_REPLAYING, - UINT64_C(77))); + &eligibility, thread, true, CLUSTER_THREADREC_REPLAY_REPLAYING, UINT64_C(77))); UT_ASSERT(!cluster_thread_recovery_worker_start_valid( - NULL, thread, true, CLUSTER_THREADREC_REPLAY_REPLAYING, - UINT64_C(77))); + NULL, thread, true, CLUSTER_THREADREC_REPLAY_REPLAYING, UINT64_C(77))); UT_ASSERT(!cluster_thread_recovery_worker_start_valid( - &eligibility, thread + 1, true, - CLUSTER_THREADREC_REPLAY_REPLAYING, UINT64_C(77))); + &eligibility, thread + 1, true, CLUSTER_THREADREC_REPLAY_REPLAYING, UINT64_C(77))); UT_ASSERT(!cluster_thread_recovery_worker_start_valid( - &eligibility, thread, false, CLUSTER_THREADREC_REPLAY_REPLAYING, - UINT64_C(77))); + &eligibility, thread, false, CLUSTER_THREADREC_REPLAY_REPLAYING, UINT64_C(77))); UT_ASSERT(!cluster_thread_recovery_worker_start_valid( - &eligibility, thread, true, CLUSTER_THREADREC_REPLAY_IDLE, - UINT64_C(77))); + &eligibility, thread, true, CLUSTER_THREADREC_REPLAY_IDLE, UINT64_C(77))); UT_ASSERT(!cluster_thread_recovery_worker_start_valid( - &eligibility, thread, true, CLUSTER_THREADREC_REPLAY_REPLAYING, - UINT64_C(78))); + &eligibility, thread, true, CLUSTER_THREADREC_REPLAY_REPLAYING, UINT64_C(78))); eligibility.duty.root_lineage_seq = 0; UT_ASSERT(!cluster_thread_recovery_worker_start_valid( - &eligibility, thread, true, CLUSTER_THREADREC_REPLAY_REPLAYING, - UINT64_C(77))); + &eligibility, thread, true, CLUSTER_THREADREC_REPLAY_REPLAYING, UINT64_C(77))); } /* ---------- diff --git a/src/test/cluster_unit/test_cluster_thread_recovery_authority.c b/src/test/cluster_unit/test_cluster_thread_recovery_authority.c index 087fd0c7382..e0463700ef0 100644 --- a/src/test/cluster_unit/test_cluster_thread_recovery_authority.c +++ b/src/test/cluster_unit/test_cluster_thread_recovery_authority.c @@ -19,11 +19,9 @@ UT_DEFINE_GLOBALS(); void -ExceptionalCondition(const char *condition_name, const char *file_name, - int line_number) +ExceptionalCondition(const char *condition_name, const char *file_name, int line_number) { - printf("# unexpected Assert: %s at %s:%d\n", condition_name, file_name, - line_number); + printf("# unexpected Assert: %s at %s:%d\n", condition_name, file_name, line_number); abort(); } @@ -65,75 +63,68 @@ static ClusterControlRootReadToken finalize_read_token; static ClusterWalPinResult finalize_adopt_result; static int finalize_adopt_calls; -#define FORMATION ((const ClusterFormationWitnessV1 *) &formation_object) -#define NEEDS ((const PgracExternalFenceNeedSetV1 *) &needs_object) -#define ADMISSIONS ((const PgracExternalFenceAdmissionSetV1 *) &admissions_object) -#define PIN ((ClusterWalRetentionPin *) &pin_object) +#define FORMATION ((const ClusterFormationWitnessV1 *)&formation_object) +#define NEEDS ((const PgracExternalFenceNeedSetV1 *)&needs_object) +#define ADMISSIONS ((const PgracExternalFenceAdmissionSetV1 *)&admissions_object) +#define PIN ((ClusterWalRetentionPin *)&pin_object) ClusterRecoverySerialRevalidateResult cluster_recovery_serial_revalidate(ClusterRecoverySerialGuard *guard) { - return guard != NULL && serial_current ? CLUSTER_RECOVERY_SERIAL_CURRENT : - CLUSTER_RECOVERY_SERIAL_MEMBERSHIP_STALE; + return guard != NULL && serial_current ? CLUSTER_RECOVERY_SERIAL_CURRENT + : CLUSTER_RECOVERY_SERIAL_MEMBERSHIP_STALE; } ClusterFormationWitnessResult -cluster_formation_witness_revalidate_nowait( - const ClusterFormationWitnessV1 *formation) +cluster_formation_witness_revalidate_nowait(const ClusterFormationWitnessV1 *formation) { - return formation == FORMATION && fence_current ? - CLUSTER_FORMATION_WITNESS_READY : CLUSTER_FORMATION_WITNESS_UNSTABLE; + return formation == FORMATION && fence_current ? CLUSTER_FORMATION_WITNESS_READY + : CLUSTER_FORMATION_WITNESS_UNSTABLE; } bool -cluster_external_fence_need_set_revalidate_nowait( - const PgracExternalFenceNeedSetV1 *needs, - const ClusterFormationWitnessV1 *formation, - PgracExternalFenceDenyReason *reason) +cluster_external_fence_need_set_revalidate_nowait(const PgracExternalFenceNeedSetV1 *needs, + const ClusterFormationWitnessV1 *formation, + PgracExternalFenceDenyReason *reason) { if (reason != NULL) - *reason = fence_current ? PGRAC_EXTERNAL_FENCE_DENY_NONE : - PGRAC_EXTERNAL_FENCE_DENY_EXPIRED; + *reason + = fence_current ? PGRAC_EXTERNAL_FENCE_DENY_NONE : PGRAC_EXTERNAL_FENCE_DENY_EXPIRED; return needs == NEEDS && formation == FORMATION && fence_current; } bool -cluster_external_fence_revalidate_set_nowait( - const PgracExternalFenceAdmissionSetV1 *admissions, - const PgracExternalFenceNeedSetV1 *needs, - const ClusterFormationWitnessV1 *formation, - PgracExternalFenceDenyReason *reason) +cluster_external_fence_revalidate_set_nowait(const PgracExternalFenceAdmissionSetV1 *admissions, + const PgracExternalFenceNeedSetV1 *needs, + const ClusterFormationWitnessV1 *formation, + PgracExternalFenceDenyReason *reason) { if (reason != NULL) - *reason = fence_current ? PGRAC_EXTERNAL_FENCE_DENY_NONE : - PGRAC_EXTERNAL_FENCE_DENY_EXPIRED; - return admissions == ADMISSIONS && needs == NEEDS && - formation == FORMATION && fence_current; + *reason + = fence_current ? PGRAC_EXTERNAL_FENCE_DENY_NONE : PGRAC_EXTERNAL_FENCE_DENY_EXPIRED; + return admissions == ADMISSIONS && needs == NEEDS && formation == FORMATION && fence_current; } ClusterWalPinResult cluster_wal_retention_pin_revalidate(ClusterWalRetentionPin *pin) { - return pin == PIN && pin_current ? CLUSTER_WAL_PIN_OK : - CLUSTER_WAL_PIN_STALE; + return pin == PIN && pin_current ? CLUSTER_WAL_PIN_OK : CLUSTER_WAL_PIN_STALE; } ClusterControlRootResult -cluster_control_root_recovery_complete_publish_v1( - const ClusterControlRootReadToken *expected_token, - const ClusterControlRootPatch *patch, - ClusterControlRootSnapshot *out_snapshot, - ClusterControlRootReadToken *out_token) +cluster_control_root_recovery_complete_publish_v1(const ClusterControlRootReadToken *expected_token, + const ClusterControlRootPatch *patch, + ClusterControlRootSnapshot *out_snapshot, + ClusterControlRootReadToken *out_token) { ClusterControlRootResult result = CLUSTER_CONTROL_ROOT_IO_ERROR; - (void) expected_token; - (void) patch; + (void)expected_token; + (void)patch; if (finalize_publish_calls < finalize_publish_result_count) result = finalize_publish_results[finalize_publish_calls]; finalize_publish_calls++; - if (result == CLUSTER_CONTROL_ROOT_OK_PRIMARY) - { + if (result == CLUSTER_CONTROL_ROOT_OK_PRIMARY) { *out_snapshot = finalize_published_root; *out_token = finalize_published_token; } @@ -141,19 +132,18 @@ cluster_control_root_recovery_complete_publish_v1( } ClusterControlRootResult -cluster_control_root_read_canonical( - uint16 origin_thread_id, const ClusterControlRootIdentity *expected_identity, - ClusterControlRootReadMode mode, - ClusterControlRootSnapshot *out_snapshot, - ClusterControlRootReadToken *out_token) +cluster_control_root_read_canonical(uint16 origin_thread_id, + const ClusterControlRootIdentity *expected_identity, + ClusterControlRootReadMode mode, + ClusterControlRootSnapshot *out_snapshot, + ClusterControlRootReadToken *out_token) { - (void) origin_thread_id; - (void) expected_identity; - (void) mode; + (void)origin_thread_id; + (void)expected_identity; + (void)mode; finalize_read_calls++; - if (finalize_read_result == CLUSTER_CONTROL_ROOT_OK_PRIMARY || - finalize_read_result == CLUSTER_CONTROL_ROOT_OK_PRIMARY_DEGRADED) - { + if (finalize_read_result == CLUSTER_CONTROL_ROOT_OK_PRIMARY + || finalize_read_result == CLUSTER_CONTROL_ROOT_OK_PRIMARY_DEGRADED) { *out_snapshot = finalize_read_root; *out_token = finalize_read_token; } @@ -162,26 +152,23 @@ cluster_control_root_read_canonical( ClusterWalPinResult cluster_wal_retention_pin_adopt_root_readback_v1( - ClusterWalRetentionPin *pin, - const ClusterControlRootSnapshot *expected_snapshot, + ClusterWalRetentionPin *pin, const ClusterControlRootSnapshot *expected_snapshot, const ClusterControlRootReadToken *expected_token, const ClusterControlRootSnapshot *observed_snapshot, const ClusterControlRootReadToken *observed_token) { - (void) pin; - (void) expected_snapshot; - (void) expected_token; - (void) observed_snapshot; - (void) observed_token; + (void)pin; + (void)expected_snapshot; + (void)expected_token; + (void)observed_snapshot; + (void)observed_token; finalize_adopt_calls++; return finalize_adopt_result; } static void -init_case(ClusterRecoveryDutyKey *duty, - ClusterControlRootSnapshot *root, - ClusterControlRootReadToken *token, - ClusterRecoverySerialGuard *serial, +init_case(ClusterRecoveryDutyKey *duty, ClusterControlRootSnapshot *root, + ClusterControlRootReadToken *token, ClusterRecoverySerialGuard *serial, ClusterThreadRecoveryAuthorityV1 *authority) { memset(duty, 0, sizeof(*duty)); @@ -194,8 +181,8 @@ init_case(ClusterRecoveryDutyKey *duty, memset(duty->authority_uuid, 0x41, sizeof(duty->authority_uuid)); root->identity = *duty; root->lifecycle = CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_REQUIRED; - root->root_flags = CLUSTER_CONTROL_ROOT_FLAG_CHECKPOINT_VALID | - CLUSTER_CONTROL_ROOT_FLAG_TAIL_VALID; + root->root_flags + = CLUSTER_CONTROL_ROOT_FLAG_CHECKPOINT_VALID | CLUSTER_CONTROL_ROOT_FLAG_TAIL_VALID; root->checkpoint_tli = 7; root->tail_tli = 7; root->checkpoint_lower_lsn = 100; @@ -250,15 +237,15 @@ UT_TEST(test_exact_root_builds_one_pin_interval) ClusterWalRetentionPinThreadRequest request; init_case(&duty, &root, &token, &serial, &authority); - UT_ASSERT(cluster_thread_recovery_pin_request_build_v1(3, &duty, &root, - &token, FORMATION, NEEDS, ADMISSIONS, &interval, &request)); + UT_ASSERT(cluster_thread_recovery_pin_request_build_v1(3, &duty, &root, &token, FORMATION, + NEEDS, ADMISSIONS, &interval, &request)); UT_ASSERT_EQ(interval.thread_id, 3); UT_ASSERT_EQ(interval.tli, 7); UT_ASSERT_EQ(interval.start_lsn, 100); UT_ASSERT_EQ(interval.end_lsn, 500); UT_ASSERT(request.intervals == &interval && request.nintervals == 1); - UT_ASSERT(request.formation == FORMATION && request.needs == NEEDS && - request.admissions == ADMISSIONS); + UT_ASSERT(request.formation == FORMATION && request.needs == NEEDS + && request.admissions == ADMISSIONS); } UT_TEST(test_foreign_root_identity_is_zero_output) @@ -275,8 +262,8 @@ UT_TEST(test_foreign_root_identity_is_zero_output) root.identity.root_lineage_seq++; memset(&interval, 0x7f, sizeof(interval)); memset(&request, 0x7f, sizeof(request)); - UT_ASSERT(!cluster_thread_recovery_pin_request_build_v1(3, &duty, &root, - &token, FORMATION, NEEDS, ADMISSIONS, &interval, &request)); + UT_ASSERT(!cluster_thread_recovery_pin_request_build_v1( + 3, &duty, &root, &token, FORMATION, NEEDS, ADMISSIONS, &interval, &request)); UT_ASSERT_EQ(interval.end_lsn, 0); UT_ASSERT(request.intervals == NULL); } @@ -293,8 +280,8 @@ UT_TEST(test_cross_timeline_interval_fails_closed) init_case(&duty, &root, &token, &serial, &authority); root.tail_tli++; - UT_ASSERT(!cluster_thread_recovery_pin_request_build_v1(3, &duty, &root, - &token, FORMATION, NEEDS, ADMISSIONS, &interval, &request)); + UT_ASSERT(!cluster_thread_recovery_pin_request_build_v1( + 3, &duty, &root, &token, FORMATION, NEEDS, ADMISSIONS, &interval, &request)); } UT_TEST(test_empty_or_reversed_interval_fails_closed) @@ -309,8 +296,8 @@ UT_TEST(test_empty_or_reversed_interval_fails_closed) init_case(&duty, &root, &token, &serial, &authority); root.validated_tail_lsn_exclusive = root.checkpoint_lower_lsn; - UT_ASSERT(!cluster_thread_recovery_pin_request_build_v1(3, &duty, &root, - &token, FORMATION, NEEDS, ADMISSIONS, &interval, &request)); + UT_ASSERT(!cluster_thread_recovery_pin_request_build_v1( + 3, &duty, &root, &token, FORMATION, NEEDS, ADMISSIONS, &interval, &request)); } UT_TEST(test_exact_owner_bundle_revalidates) @@ -322,8 +309,8 @@ UT_TEST(test_exact_owner_bundle_revalidates) ClusterThreadRecoveryAuthorityV1 authority; init_case(&duty, &root, &token, &serial, &authority); - UT_ASSERT_EQ(cluster_thread_recovery_authority_revalidate_nowait_v1( - &authority), CLUSTER_THREAD_AUTHORITY_OK); + UT_ASSERT_EQ(cluster_thread_recovery_authority_revalidate_nowait_v1(&authority), + CLUSTER_THREAD_AUTHORITY_OK); } UT_TEST(test_serial_root_drift_is_stale) @@ -336,8 +323,8 @@ UT_TEST(test_serial_root_drift_is_stale) init_case(&duty, &root, &token, &serial, &authority); serial.root_read_token.root_publish_seq++; - UT_ASSERT_EQ(cluster_thread_recovery_authority_revalidate_nowait_v1( - &authority), CLUSTER_THREAD_AUTHORITY_ROOT_STALE); + UT_ASSERT_EQ(cluster_thread_recovery_authority_revalidate_nowait_v1(&authority), + CLUSTER_THREAD_AUTHORITY_ROOT_STALE); } UT_TEST(test_fence_drift_is_stale) @@ -350,8 +337,8 @@ UT_TEST(test_fence_drift_is_stale) init_case(&duty, &root, &token, &serial, &authority); fence_current = false; - UT_ASSERT_EQ(cluster_thread_recovery_authority_revalidate_nowait_v1( - &authority), CLUSTER_THREAD_AUTHORITY_FENCE_STALE); + UT_ASSERT_EQ(cluster_thread_recovery_authority_revalidate_nowait_v1(&authority), + CLUSTER_THREAD_AUTHORITY_FENCE_STALE); } UT_TEST(test_pin_drift_is_stale) @@ -364,8 +351,8 @@ UT_TEST(test_pin_drift_is_stale) init_case(&duty, &root, &token, &serial, &authority); pin_current = false; - UT_ASSERT_EQ(cluster_thread_recovery_authority_revalidate_nowait_v1( - &authority), CLUSTER_THREAD_AUTHORITY_PIN_STALE); + UT_ASSERT_EQ(cluster_thread_recovery_authority_revalidate_nowait_v1(&authority), + CLUSTER_THREAD_AUTHORITY_PIN_STALE); } UT_TEST(test_exact_window_is_covered_by_held_pin) @@ -377,10 +364,8 @@ UT_TEST(test_exact_window_is_covered_by_held_pin) ClusterThreadRecoveryAuthorityV1 authority; init_case(&duty, &root, &token, &serial, &authority); - UT_ASSERT(cluster_thread_recovery_authority_covers_window_v1( - &authority, 3, 100, 500)); - UT_ASSERT(cluster_thread_recovery_authority_covers_window_v1( - &authority, 3, 200, 400)); + UT_ASSERT(cluster_thread_recovery_authority_covers_window_v1(&authority, 3, 100, 500)); + UT_ASSERT(cluster_thread_recovery_authority_covers_window_v1(&authority, 3, 200, 400)); } UT_TEST(test_window_outside_held_pin_fails_closed) @@ -392,14 +377,10 @@ UT_TEST(test_window_outside_held_pin_fails_closed) ClusterThreadRecoveryAuthorityV1 authority; init_case(&duty, &root, &token, &serial, &authority); - UT_ASSERT(!cluster_thread_recovery_authority_covers_window_v1( - &authority, 3, 99, 500)); - UT_ASSERT(!cluster_thread_recovery_authority_covers_window_v1( - &authority, 3, 100, 501)); - UT_ASSERT(!cluster_thread_recovery_authority_covers_window_v1( - &authority, 4, 100, 500)); - UT_ASSERT(!cluster_thread_recovery_authority_covers_window_v1( - &authority, 3, 500, 500)); + UT_ASSERT(!cluster_thread_recovery_authority_covers_window_v1(&authority, 3, 99, 500)); + UT_ASSERT(!cluster_thread_recovery_authority_covers_window_v1(&authority, 3, 100, 501)); + UT_ASSERT(!cluster_thread_recovery_authority_covers_window_v1(&authority, 4, 100, 500)); + UT_ASSERT(!cluster_thread_recovery_authority_covers_window_v1(&authority, 3, 500, 500)); } UT_TEST(test_complete_window_builds_exact_root_patch) @@ -412,27 +393,25 @@ UT_TEST(test_complete_window_builds_exact_root_patch) ClusterControlRootPatch patch; init_case(&duty, &root, &token, &serial, &authority); - root.root_flags |= CLUSTER_CONTROL_ROOT_FLAG_CLAIM_VALID | - CLUSTER_CONTROL_ROOT_FLAG_TAIL_LAST_RECORD_VALID; + root.root_flags + |= CLUSTER_CONTROL_ROOT_FLAG_CLAIM_VALID | CLUSTER_CONTROL_ROOT_FLAG_TAIL_LAST_RECORD_VALID; token.root_flags = root.root_flags; serial.root_read_token = token; root.tail_last_record_lsn = 450; root.tail_last_record_crc32c = 88; - UT_ASSERT(cluster_thread_recovery_root_complete_patch_build_v1( - &authority, 500, &patch)); - UT_ASSERT_EQ(patch.mask, CLUSTER_CONTROL_ROOT_PATCH_LIFECYCLE | - CLUSTER_CONTROL_ROOT_PATCH_RECOVERY_PROGRESS); - UT_ASSERT_EQ(patch.expected_lifecycle, - CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_REQUIRED); - UT_ASSERT_EQ(patch.desired.lifecycle, - CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_COMPLETE); + UT_ASSERT(cluster_thread_recovery_root_complete_patch_build_v1(&authority, 500, &patch)); + UT_ASSERT_EQ(patch.mask, CLUSTER_CONTROL_ROOT_PATCH_LIFECYCLE + | CLUSTER_CONTROL_ROOT_PATCH_RECOVERY_PROGRESS); + UT_ASSERT_EQ(patch.expected_lifecycle, CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_REQUIRED); + UT_ASSERT_EQ(patch.desired.lifecycle, CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_COMPLETE); UT_ASSERT_EQ(patch.desired.recovered_tli, 7); UT_ASSERT_EQ(patch.desired.recovered_through_lsn_exclusive, 500); UT_ASSERT_EQ(patch.desired.recovered_last_record_lsn, 450); UT_ASSERT_EQ(patch.desired.recovered_last_record_crc32c, 88); - UT_ASSERT((patch.desired.root_flags & - (CLUSTER_CONTROL_ROOT_FLAG_RECOVERED_VALID | - CLUSTER_CONTROL_ROOT_FLAG_RECOVERED_LAST_RECORD_VALID)) != 0); + UT_ASSERT((patch.desired.root_flags + & (CLUSTER_CONTROL_ROOT_FLAG_RECOVERED_VALID + | CLUSTER_CONTROL_ROOT_FLAG_RECOVERED_LAST_RECORD_VALID)) + != 0); } UT_TEST(test_short_window_cannot_build_complete_root_patch) @@ -445,49 +424,42 @@ UT_TEST(test_short_window_cannot_build_complete_root_patch) ClusterControlRootPatch patch; init_case(&duty, &root, &token, &serial, &authority); - root.root_flags |= CLUSTER_CONTROL_ROOT_FLAG_CLAIM_VALID | - CLUSTER_CONTROL_ROOT_FLAG_TAIL_LAST_RECORD_VALID; + root.root_flags + |= CLUSTER_CONTROL_ROOT_FLAG_CLAIM_VALID | CLUSTER_CONTROL_ROOT_FLAG_TAIL_LAST_RECORD_VALID; token.root_flags = root.root_flags; serial.root_read_token = token; root.tail_last_record_lsn = 450; root.tail_last_record_crc32c = 88; memset(&patch, 0x7f, sizeof(patch)); - UT_ASSERT(!cluster_thread_recovery_root_complete_patch_build_v1( - &authority, 499, &patch)); + UT_ASSERT(!cluster_thread_recovery_root_complete_patch_build_v1(&authority, 499, &patch)); UT_ASSERT_EQ(patch.mask, 0); } static void -prepare_finalize_case(ClusterRecoveryDutyKey *duty, - ClusterControlRootSnapshot *root, ClusterControlRootReadToken *token, - ClusterRecoverySerialGuard *serial, - ClusterThreadRecoveryAuthorityV1 *authority, - ClusterControlRootPatch *patch) +prepare_finalize_case(ClusterRecoveryDutyKey *duty, ClusterControlRootSnapshot *root, + ClusterControlRootReadToken *token, ClusterRecoverySerialGuard *serial, + ClusterThreadRecoveryAuthorityV1 *authority, ClusterControlRootPatch *patch) { init_case(duty, root, token, serial, authority); - root->root_flags |= CLUSTER_CONTROL_ROOT_FLAG_CLAIM_VALID | - CLUSTER_CONTROL_ROOT_FLAG_TAIL_LAST_RECORD_VALID; + root->root_flags + |= CLUSTER_CONTROL_ROOT_FLAG_CLAIM_VALID | CLUSTER_CONTROL_ROOT_FLAG_TAIL_LAST_RECORD_VALID; token->root_flags = root->root_flags; serial->root_read_token = *token; root->tail_last_record_lsn = 450; root->tail_last_record_crc32c = 88; - UT_ASSERT(cluster_thread_recovery_root_complete_patch_build_v1( - authority, 500, patch)); + UT_ASSERT(cluster_thread_recovery_root_complete_patch_build_v1(authority, 500, patch)); serial->held = false; finalize_published_root = *root; - finalize_published_root.lifecycle = - CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_COMPLETE; + finalize_published_root.lifecycle = CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_COMPLETE; finalize_published_root.root_flags = patch->desired.root_flags; finalize_published_root.recovered_tli = patch->desired.recovered_tli; - finalize_published_root.recovered_through_lsn_exclusive = - patch->desired.recovered_through_lsn_exclusive; - finalize_published_root.recovered_last_record_lsn = - patch->desired.recovered_last_record_lsn; - finalize_published_root.recovered_last_record_crc32c = - patch->desired.recovered_last_record_crc32c; + finalize_published_root.recovered_through_lsn_exclusive + = patch->desired.recovered_through_lsn_exclusive; + finalize_published_root.recovered_last_record_lsn = patch->desired.recovered_last_record_lsn; + finalize_published_root.recovered_last_record_crc32c + = patch->desired.recovered_last_record_crc32c; finalize_published_token = *token; - finalize_published_token.lifecycle = - CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_COMPLETE; + finalize_published_token.lifecycle = CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_COMPLETE; finalize_published_token.root_flags = finalize_published_root.root_flags; finalize_published_token.root_publish_seq++; finalize_published_token.record_crc32c++; @@ -506,12 +478,11 @@ UT_TEST(test_root_finalize_exact_cas_succeeds) prepare_finalize_case(&duty, &root, &token, &serial, &authority, &patch); finalize_publish_results[0] = CLUSTER_CONTROL_ROOT_OK_PRIMARY; finalize_publish_result_count = 1; - UT_ASSERT_EQ(cluster_thread_recovery_root_finalize_after_ir_v1( - &authority, &patch, &published), CLUSTER_THREAD_ROOT_FINALIZE_OK); + UT_ASSERT_EQ(cluster_thread_recovery_root_finalize_after_ir_v1(&authority, &patch, &published), + CLUSTER_THREAD_ROOT_FINALIZE_OK); UT_ASSERT_EQ(finalize_publish_calls, 1); UT_ASSERT_EQ(finalize_read_calls, 0); - UT_ASSERT_EQ(published.lifecycle, - CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_COMPLETE); + UT_ASSERT_EQ(published.lifecycle, CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_COMPLETE); } UT_TEST(test_root_finalize_stale_token_reconciles_without_page_replay) @@ -534,8 +505,8 @@ UT_TEST(test_root_finalize_stale_token_reconciles_without_page_replay) finalize_read_token.file_txn_seq++; finalize_read_token.root_publish_seq++; finalize_read_token.record_crc32c++; - UT_ASSERT_EQ(cluster_thread_recovery_root_finalize_after_ir_v1( - &authority, &patch, &published), CLUSTER_THREAD_ROOT_FINALIZE_OK); + UT_ASSERT_EQ(cluster_thread_recovery_root_finalize_after_ir_v1(&authority, &patch, &published), + CLUSTER_THREAD_ROOT_FINALIZE_OK); UT_ASSERT_EQ(finalize_publish_calls, 2); UT_ASSERT_EQ(finalize_read_calls, 1); UT_ASSERT_EQ(finalize_adopt_calls, 1); @@ -557,9 +528,8 @@ UT_TEST(test_root_finalize_adopts_already_complete_readback) finalize_read_result = CLUSTER_CONTROL_ROOT_OK_PRIMARY; finalize_read_root = finalize_published_root; finalize_read_token = finalize_published_token; - UT_ASSERT_EQ(cluster_thread_recovery_root_finalize_after_ir_v1( - &authority, &patch, &published), - CLUSTER_THREAD_ROOT_FINALIZE_ALREADY_COMPLETE); + UT_ASSERT_EQ(cluster_thread_recovery_root_finalize_after_ir_v1(&authority, &patch, &published), + CLUSTER_THREAD_ROOT_FINALIZE_ALREADY_COMPLETE); UT_ASSERT_EQ(finalize_publish_calls, 1); UT_ASSERT_EQ(finalize_read_calls, 1); UT_ASSERT_EQ(finalize_adopt_calls, 1); @@ -583,8 +553,8 @@ UT_TEST(test_root_finalize_immutable_drift_requests_fresh_plan) finalize_read_token = token; finalize_read_token.root_publish_seq++; finalize_adopt_result = CLUSTER_WAL_PIN_STALE; - UT_ASSERT_EQ(cluster_thread_recovery_root_finalize_after_ir_v1( - &authority, &patch, &published), CLUSTER_THREAD_ROOT_FINALIZE_RETRY); + UT_ASSERT_EQ(cluster_thread_recovery_root_finalize_after_ir_v1(&authority, &patch, &published), + CLUSTER_THREAD_ROOT_FINALIZE_RETRY); UT_ASSERT_EQ(finalize_publish_calls, 1); UT_ASSERT_EQ(finalize_adopt_calls, 1); } @@ -602,9 +572,8 @@ UT_TEST(test_root_finalize_release_uncertain_preserves_cleanup_ownership) prepare_finalize_case(&duty, &root, &token, &serial, &authority, &patch); finalize_publish_results[0] = CLUSTER_CONTROL_ROOT_RELEASE_UNCERTAIN; finalize_publish_result_count = 1; - UT_ASSERT_EQ(cluster_thread_recovery_root_finalize_after_ir_v1( - &authority, &patch, &published), - CLUSTER_THREAD_ROOT_FINALIZE_CLEANUP_UNCERTAIN); + UT_ASSERT_EQ(cluster_thread_recovery_root_finalize_after_ir_v1(&authority, &patch, &published), + CLUSTER_THREAD_ROOT_FINALIZE_CLEANUP_UNCERTAIN); UT_ASSERT_EQ(finalize_read_calls, 0); } diff --git a/src/test/cluster_unit/test_cluster_thread_recovery_fabric_apply.c b/src/test/cluster_unit/test_cluster_thread_recovery_fabric_apply.c index 04b65abc259..688ddff35fe 100644 --- a/src/test/cluster_unit/test_cluster_thread_recovery_fabric_apply.c +++ b/src/test/cluster_unit/test_cluster_thread_recovery_fabric_apply.c @@ -17,11 +17,9 @@ UT_DEFINE_GLOBALS(); void -ExceptionalCondition(const char *condition_name, const char *file_name, - int line_number) +ExceptionalCondition(const char *condition_name, const char *file_name, int line_number) { - printf("# unexpected Assert: %s at %s:%d\n", condition_name, file_name, - line_number); + printf("# unexpected Assert: %s at %s:%d\n", condition_name, file_name, line_number); abort(); } @@ -48,45 +46,42 @@ static bool authority_current; static bool retained_coverage_current; const RfPageOnlinePlanV1 * -cluster_thread_recovery_fabric_page_plan_v1( - const ClusterThreadRecoveryFabricPlanV1 *plan) +cluster_thread_recovery_fabric_page_plan_v1(const ClusterThreadRecoveryFabricPlanV1 *plan) { - return plan == (const ClusterThreadRecoveryFabricPlanV1 *) &fabric_object ? - (const RfPageOnlinePlanV1 *) &page_plan_object : NULL; + return plan == (const ClusterThreadRecoveryFabricPlanV1 *)&fabric_object + ? (const RfPageOnlinePlanV1 *)&page_plan_object + : NULL; } const RfSideOnlinePlanV1 * -cluster_thread_recovery_fabric_side_plan_v1( - const ClusterThreadRecoveryFabricPlanV1 *plan) +cluster_thread_recovery_fabric_side_plan_v1(const ClusterThreadRecoveryFabricPlanV1 *plan) { - return plan == (const ClusterThreadRecoveryFabricPlanV1 *) &fabric_object ? - (const RfSideOnlinePlanV1 *) &side_plan_object : NULL; + return plan == (const ClusterThreadRecoveryFabricPlanV1 *)&fabric_object + ? (const RfSideOnlinePlanV1 *)&side_plan_object + : NULL; } uint32 -cluster_thread_recovery_fabric_participant_count_v1( - const ClusterThreadRecoveryFabricPlanV1 *plan) +cluster_thread_recovery_fabric_participant_count_v1(const ClusterThreadRecoveryFabricPlanV1 *plan) { - return plan == (const ClusterThreadRecoveryFabricPlanV1 *) &fabric_object ? - 1 : 0; + return plan == (const ClusterThreadRecoveryFabricPlanV1 *)&fabric_object ? 1 : 0; } bool -cluster_thread_recovery_fabric_identity_matches_v1( - const ClusterThreadRecoveryFabricPlanV1 *plan, uint64 system_identifier, - const uint8 storage_uuid[16]) +cluster_thread_recovery_fabric_identity_matches_v1(const ClusterThreadRecoveryFabricPlanV1 *plan, + uint64 system_identifier, + const uint8 storage_uuid[16]) { - return plan == (const ClusterThreadRecoveryFabricPlanV1 *) &fabric_object && - system_identifier == 99 && storage_uuid != NULL && storage_uuid[0] == 3; + return plan == (const ClusterThreadRecoveryFabricPlanV1 *)&fabric_object + && system_identifier == 99 && storage_uuid != NULL && storage_uuid[0] == 3; } bool -cluster_thread_recovery_fabric_cut_v1( - const ClusterThreadRecoveryFabricPlanV1 *plan, uint32 index, - RfContributorStreamCutV1 *out_cut) +cluster_thread_recovery_fabric_cut_v1(const ClusterThreadRecoveryFabricPlanV1 *plan, uint32 index, + RfContributorStreamCutV1 *out_cut) { - if (plan != (const ClusterThreadRecoveryFabricPlanV1 *) &fabric_object || - index != 0 || out_cut == NULL) + if (plan != (const ClusterThreadRecoveryFabricPlanV1 *)&fabric_object || index != 0 + || out_cut == NULL) return false; memset(out_cut, 0, sizeof(*out_cut)); out_cut->failed_thread = 2; @@ -100,16 +95,14 @@ cluster_thread_recovery_fabric_cut_v1( uint32 rf_page_online_plan_target_count_v1(const RfPageOnlinePlanV1 *plan) { - return plan == (const RfPageOnlinePlanV1 *) &page_plan_object ? - (uint32) target_count : 0; + return plan == (const RfPageOnlinePlanV1 *)&page_plan_object ? (uint32)target_count : 0; } bool rf_page_online_plan_target_v1(const RfPageOnlinePlanV1 *plan, uint32 index, - RfPageOnlineTargetViewV1 *out_target) + RfPageOnlineTargetViewV1 *out_target) { - if (plan != (const RfPageOnlinePlanV1 *) &page_plan_object || - index >= (uint32) target_count) + if (plan != (const RfPageOnlinePlanV1 *)&page_plan_object || index >= (uint32)target_count) return false; *out_target = targets[index]; return true; @@ -118,24 +111,24 @@ rf_page_online_plan_target_v1(const RfPageOnlinePlanV1 *plan, uint32 index, uint32 rf_side_online_plan_operation_count_v1(const RfSideOnlinePlanV1 *plan) { - return plan == (const RfSideOnlinePlanV1 *) &side_plan_object ? 3 : 0; + return plan == (const RfSideOnlinePlanV1 *)&side_plan_object ? 3 : 0; } ClusterThreadRecoveryAuthorityResultV1 cluster_thread_recovery_authority_revalidate_nowait_v1( const ClusterThreadRecoveryAuthorityV1 *authority) { - return authority != NULL && authority_current ? CLUSTER_THREAD_AUTHORITY_OK : - CLUSTER_THREAD_AUTHORITY_ROOT_STALE; + return authority != NULL && authority_current ? CLUSTER_THREAD_AUTHORITY_OK + : CLUSTER_THREAD_AUTHORITY_ROOT_STALE; } bool cluster_thread_recovery_authority_covers_window_v1( - const ClusterThreadRecoveryAuthorityV1 *authority, uint16 dead_tid, - XLogRecPtr scan_lower, XLogRecPtr scan_upper) + const ClusterThreadRecoveryAuthorityV1 *authority, uint16 dead_tid, XLogRecPtr scan_lower, + XLogRecPtr scan_upper) { - return authority != NULL && retained_coverage_current && dead_tid == 2 && - scan_lower == 0x100 && scan_upper == 0x200; + return authority != NULL && retained_coverage_current && dead_tid == 2 && scan_lower == 0x100 + && scan_upper == 0x200; } uint64 @@ -145,18 +138,17 @@ cluster_epoch_get_current(void) } RfPageProofDetailV1 -rf_page_stable_base_proof_build_bound_v1( - const RfPageStableBaseProofRequestV1 *request, uint32 *chain_indices, - uint32 chain_capacity, RfPageStableBaseProofV1 **out_proof) +rf_page_stable_base_proof_build_bound_v1(const RfPageStableBaseProofRequestV1 *request, + uint32 *chain_indices, uint32 chain_capacity, + RfPageStableBaseProofV1 **out_proof) { int index; - UT_ASSERT(request != NULL && request->graph != NULL && - chain_indices != NULL && chain_capacity != 0); - index = request->graph == &graphs[0] ? 0 : - (request->graph == &graphs[1] ? 1 : -1); + UT_ASSERT(request != NULL && request->graph != NULL && chain_indices != NULL + && chain_capacity != 0); + index = request->graph == &graphs[0] ? 0 : (request->graph == &graphs[1] ? 1 : -1); UT_ASSERT(index >= 0); - *out_proof = (RfPageStableBaseProofV1 *) &proof_objects[index]; + *out_proof = (RfPageStableBaseProofV1 *)&proof_objects[index]; proof_step = ++step; return RF_PAGE_PROOF_DETAIL_OK; } @@ -168,19 +160,18 @@ rf_page_stable_base_proof_destroy_v1(RfPageStableBaseProofV1 **proof) } RfPageAuthorityVerdictV1 -rf_page_authority_batch_preflight_wait_v1( - const RfPageAuthorityBatchRequestV1 *request, int timeout_ms, - RfPageAuthorityPreflightV1 **out_preflight) +rf_page_authority_batch_preflight_wait_v1(const RfPageAuthorityBatchRequestV1 *request, + int timeout_ms, + RfPageAuthorityPreflightV1 **out_preflight) { - UT_ASSERT(request != NULL && request->target_count == (uint32) target_count && - timeout_ms == 1000); - if (target_count == 2) - { + UT_ASSERT(request != NULL && request->target_count == (uint32)target_count + && timeout_ms == 1000); + if (target_count == 2) { UT_ASSERT(request->targets[0].contributors == &contributors[0]); UT_ASSERT(request->targets[1].contributors == &contributors[1]); } page_preflight_step = ++step; - *out_preflight = (RfPageAuthorityPreflightV1 *) &preflight_object; + *out_preflight = (RfPageAuthorityPreflightV1 *)&preflight_object; return RF_PAGE_AUTHORITY_OK; } @@ -191,13 +182,12 @@ rf_page_authority_preflight_destroy_v1(RfPageAuthorityPreflightV1 **preflight) } bool -rf_page_install_authority_adapter_init_v1( - RfPageAuthorityPreflightV1 *preflight, - ClusterRecoverySerialGuard *serial_guard, - RfPageInstallAuthorityAdapterV1 *adapter) +rf_page_install_authority_adapter_init_v1(RfPageAuthorityPreflightV1 *preflight, + ClusterRecoverySerialGuard *serial_guard, + RfPageInstallAuthorityAdapterV1 *adapter) { - UT_ASSERT(preflight == (RfPageAuthorityPreflightV1 *) &preflight_object && - serial_guard != NULL && adapter != NULL); + UT_ASSERT(preflight == (RfPageAuthorityPreflightV1 *)&preflight_object && serial_guard != NULL + && adapter != NULL); memset(adapter, 0, sizeof(*adapter)); adapter->ops.arg = adapter; return true; @@ -205,12 +195,12 @@ rf_page_install_authority_adapter_init_v1( RfPageProofDetailV1 rf_page_storage_smgr_preopen_v1(const RfPageStorageInstallRequestV1 *request, - RfPageSmgrPreopenV1 **out_preopen) + RfPageSmgrPreopenV1 **out_preopen) { - UT_ASSERT(request != NULL && request->component_count == - (uint32) target_count && request->storage == NULL); + UT_ASSERT(request != NULL && request->component_count == (uint32)target_count + && request->storage == NULL); preopen_step = ++step; - *out_preopen = (RfPageSmgrPreopenV1 *) &preopen_object; + *out_preopen = (RfPageSmgrPreopenV1 *)&preopen_object; return RF_PAGE_PROOF_DETAIL_OK; } @@ -221,13 +211,12 @@ rf_page_storage_smgr_preopen_destroy_v1(RfPageSmgrPreopenV1 **preopen) } RfPageProofDetailV1 -rf_page_storage_install_smgr_preopened_v1( - const RfPageStorageInstallRequestV1 *request, - RfPageSmgrPreopenV1 *preopen, RfPageStorageInstallProofV1 *proof) +rf_page_storage_install_smgr_preopened_v1(const RfPageStorageInstallRequestV1 *request, + RfPageSmgrPreopenV1 *preopen, + RfPageStorageInstallProofV1 *proof) { - UT_ASSERT(request != NULL && preopen == - (RfPageSmgrPreopenV1 *) &preopen_object && - side_preflight_step != 0 && side_preflight_step < step + 1); + UT_ASSERT(request != NULL && preopen == (RfPageSmgrPreopenV1 *)&preopen_object + && side_preflight_step != 0 && side_preflight_step < step + 1); page_install_step = ++step; memset(proof, 0, sizeof(*proof)); proof->component_count = request->component_count; @@ -240,35 +229,31 @@ rf_page_storage_install_smgr_preopened_v1( } bool -rf_side_online_production_owner_init_v1( - RfSideOnlineProductionOwnerV1 *owner, void *authority_arg, - RfSideOnlineFreshAuthorityV1 revalidate_authority, uint32 cluster_epoch, - bool failed_origin_redo_retained) +rf_side_online_production_owner_init_v1(RfSideOnlineProductionOwnerV1 *owner, void *authority_arg, + RfSideOnlineFreshAuthorityV1 revalidate_authority, + uint32 cluster_epoch, bool failed_origin_redo_retained) { - UT_ASSERT(owner != NULL && authority_arg != NULL && - revalidate_authority != NULL && revalidate_authority(authority_arg) && - cluster_epoch == 9 && failed_origin_redo_retained); + UT_ASSERT(owner != NULL && authority_arg != NULL && revalidate_authority != NULL + && revalidate_authority(authority_arg) && cluster_epoch == 9 + && failed_origin_redo_retained); memset(owner, 0, sizeof(*owner)); return true; } RfPageProofDetailV1 rf_side_online_production_preflight_v1(const RfSideOnlinePlanV1 *plan, - RfSideOnlineProductionOwnerV1 *owner) + RfSideOnlineProductionOwnerV1 *owner) { - UT_ASSERT(plan == (const RfSideOnlinePlanV1 *) &side_plan_object && - owner != NULL); + UT_ASSERT(plan == (const RfSideOnlinePlanV1 *)&side_plan_object && owner != NULL); side_preflight_step = ++step; - return side_preflight_ok ? RF_PAGE_PROOF_DETAIL_OK : - RF_PAGE_PROOF_DETAIL_SIDE_INCOMPLETE; + return side_preflight_ok ? RF_PAGE_PROOF_DETAIL_OK : RF_PAGE_PROOF_DETAIL_SIDE_INCOMPLETE; } RfPageProofDetailV1 rf_side_online_production_apply_v1(const RfSideOnlinePlanV1 *plan, - RfSideOnlineProductionOwnerV1 *owner) + RfSideOnlineProductionOwnerV1 *owner) { - UT_ASSERT(plan == (const RfSideOnlinePlanV1 *) &side_plan_object && - owner != NULL); + UT_ASSERT(plan == (const RfSideOnlinePlanV1 *)&side_plan_object && owner != NULL); side_apply_step = ++step; return RF_PAGE_PROOF_DETAIL_OK; } @@ -296,17 +281,14 @@ init_case(ClusterThreadRecoveryAuthorityV1 *authority) authority->duty = &duty; authority->root_snapshot = &root; authority->root_token = &token; - authority->formation = (const ClusterFormationWitnessV1 *) &fabric_object; - authority->fence_need_set = - (const PgracExternalFenceNeedSetV1 *) &page_plan_object; - authority->fence_admission_set = - (const PgracExternalFenceAdmissionSetV1 *) &side_plan_object; - authority->retention_pin = (ClusterWalRetentionPin *) &proof_objects[0]; + authority->formation = (const ClusterFormationWitnessV1 *)&fabric_object; + authority->fence_need_set = (const PgracExternalFenceNeedSetV1 *)&page_plan_object; + authority->fence_admission_set = (const PgracExternalFenceAdmissionSetV1 *)&side_plan_object; + authority->retention_pin = (ClusterWalRetentionPin *)&proof_objects[0]; authority->serial_guard = &serial; memset(targets, 0, sizeof(targets)); memset(graphs, 0, sizeof(graphs)); - for (i = 0; i < 2; i++) - { + for (i = 0; i < 2; i++) { targets[i].page_identity.system_identifier = 99; memset(targets[i].page_identity.storage_uuid, 3, 16); targets[i].page_identity.locator.spcOid = 1; @@ -319,7 +301,7 @@ init_case(ClusterThreadRecoveryAuthorityV1 *authority) targets[i].expected_before.mutation_token = 10 + i; targets[i].expected_result.mutation_token = 20 + i; targets[i].before_kind = RF_PAGE_STATE_PRESENT; - targets[i].canonical_page = (const char *) &fabric_object; + targets[i].canonical_page = (const char *)&fabric_object; targets[i].source = &sources[i]; targets[i].contributors = &contributors[i]; graphs[i].contributors = &contributors[i]; @@ -340,18 +322,17 @@ UT_TEST(test_all_page_and_side_targets_preflight_before_first_mutation) ClusterThreadRecoveryFabricApplyResultV1 result; init_case(&authority); - UT_ASSERT_EQ(cluster_thread_recovery_fabric_apply_v1( - (const ClusterThreadRecoveryFabricPlanV1 *) &fabric_object, - &authority, &result), RF_PAGE_PROOF_DETAIL_OK); - UT_ASSERT(proof_step < page_preflight_step && - page_preflight_step < preopen_step && - preopen_step < side_preflight_step && - side_preflight_step < page_install_step && - page_install_step < side_apply_step); + UT_ASSERT_EQ( + cluster_thread_recovery_fabric_apply_v1( + (const ClusterThreadRecoveryFabricPlanV1 *)&fabric_object, &authority, &result), + RF_PAGE_PROOF_DETAIL_OK); + UT_ASSERT(proof_step < page_preflight_step && page_preflight_step < preopen_step + && preopen_step < side_preflight_step && side_preflight_step < page_install_step + && page_install_step < side_apply_step); UT_ASSERT_EQ(result.page_target_count, 2); UT_ASSERT_EQ(result.side_operation_count, 3); - UT_ASSERT(result.page_durability_complete && - result.page_postread_complete && result.side_apply_complete); + UT_ASSERT(result.page_durability_complete && result.page_postread_complete + && result.side_apply_complete); } UT_TEST(test_side_preflight_failure_leaves_page_unmodified) @@ -361,9 +342,10 @@ UT_TEST(test_side_preflight_failure_leaves_page_unmodified) init_case(&authority); side_preflight_ok = false; - UT_ASSERT_EQ(cluster_thread_recovery_fabric_apply_v1( - (const ClusterThreadRecoveryFabricPlanV1 *) &fabric_object, - &authority, &result), RF_PAGE_PROOF_DETAIL_SIDE_INCOMPLETE); + UT_ASSERT_EQ( + cluster_thread_recovery_fabric_apply_v1( + (const ClusterThreadRecoveryFabricPlanV1 *)&fabric_object, &authority, &result), + RF_PAGE_PROOF_DETAIL_SIDE_INCOMPLETE); UT_ASSERT_EQ(page_install_step, 0); UT_ASSERT_EQ(side_apply_step, 0); } @@ -375,9 +357,10 @@ UT_TEST(test_side_only_plan_skips_page_authority_and_install) init_case(&authority); target_count = 0; - UT_ASSERT_EQ(cluster_thread_recovery_fabric_apply_v1( - (const ClusterThreadRecoveryFabricPlanV1 *) &fabric_object, - &authority, &result), RF_PAGE_PROOF_DETAIL_OK); + UT_ASSERT_EQ( + cluster_thread_recovery_fabric_apply_v1( + (const ClusterThreadRecoveryFabricPlanV1 *)&fabric_object, &authority, &result), + RF_PAGE_PROOF_DETAIL_OK); UT_ASSERT_EQ(proof_step, 0); UT_ASSERT_EQ(page_preflight_step, 0); UT_ASSERT_EQ(page_install_step, 0); @@ -392,9 +375,10 @@ UT_TEST(test_retained_cut_mismatch_blocks_before_any_target_preflight) init_case(&authority); retained_coverage_current = false; - UT_ASSERT_EQ(cluster_thread_recovery_fabric_apply_v1( - (const ClusterThreadRecoveryFabricPlanV1 *) &fabric_object, - &authority, &result), RF_PAGE_PROOF_DETAIL_RETENTION_STALE); + UT_ASSERT_EQ( + cluster_thread_recovery_fabric_apply_v1( + (const ClusterThreadRecoveryFabricPlanV1 *)&fabric_object, &authority, &result), + RF_PAGE_PROOF_DETAIL_RETENTION_STALE); UT_ASSERT_EQ(proof_step, 0); UT_ASSERT_EQ(page_preflight_step, 0); UT_ASSERT_EQ(side_preflight_step, 0); diff --git a/src/test/cluster_unit/test_cluster_thread_recovery_fabric_execute.c b/src/test/cluster_unit/test_cluster_thread_recovery_fabric_execute.c index 9d0f43dfe41..56f7110688f 100644 --- a/src/test/cluster_unit/test_cluster_thread_recovery_fabric_execute.c +++ b/src/test/cluster_unit/test_cluster_thread_recovery_fabric_execute.c @@ -13,11 +13,9 @@ UT_DEFINE_GLOBALS(); void -ExceptionalCondition(const char *condition_name, const char *file_name, - int line_number) +ExceptionalCondition(const char *condition_name, const char *file_name, int line_number) { - printf("# unexpected Assert: %s at %s:%d\n", condition_name, file_name, - line_number); + printf("# unexpected Assert: %s at %s:%d\n", condition_name, file_name, line_number); abort(); } @@ -33,32 +31,28 @@ static int destroy_step; RfPageProofDetailV1 cluster_thread_recovery_fabric_scan_root_v1( uint16 dead_thread, XLogRecPtr scan_begin, XLogRecPtr scan_end, - const struct ClusterThreadRecoveryAuthorityV1 *authority, - bool space_active, ClusterThreadRecoveryFabricPlanV1 **out_plan, - uint64 *out_record_count) + const struct ClusterThreadRecoveryAuthorityV1 *authority, bool space_active, + ClusterThreadRecoveryFabricPlanV1 **out_plan, uint64 *out_record_count) { - UT_ASSERT(dead_thread == 2 && scan_begin == 0x100 && scan_end == 0x200 && - authority == (const struct ClusterThreadRecoveryAuthorityV1 *) - &authority_object && !space_active && out_plan != NULL && - out_record_count != NULL); + UT_ASSERT(dead_thread == 2 && scan_begin == 0x100 && scan_end == 0x200 + && authority == (const struct ClusterThreadRecoveryAuthorityV1 *)&authority_object + && !space_active && out_plan != NULL && out_record_count != NULL); scan_step = ++step; if (scan_detail != RF_PAGE_PROOF_DETAIL_OK) return scan_detail; - *out_plan = (ClusterThreadRecoveryFabricPlanV1 *) &fabric_object; + *out_plan = (ClusterThreadRecoveryFabricPlanV1 *)&fabric_object; *out_record_count = 4; return RF_PAGE_PROOF_DETAIL_OK; } RfPageProofDetailV1 -cluster_thread_recovery_fabric_apply_v1( - const ClusterThreadRecoveryFabricPlanV1 *plan, - const struct ClusterThreadRecoveryAuthorityV1 *authority, - ClusterThreadRecoveryFabricApplyResultV1 *result) +cluster_thread_recovery_fabric_apply_v1(const ClusterThreadRecoveryFabricPlanV1 *plan, + const struct ClusterThreadRecoveryAuthorityV1 *authority, + ClusterThreadRecoveryFabricApplyResultV1 *result) { - UT_ASSERT(plan == (const ClusterThreadRecoveryFabricPlanV1 *) - &fabric_object && authority == - (const struct ClusterThreadRecoveryAuthorityV1 *) &authority_object && - result != NULL); + UT_ASSERT(plan == (const ClusterThreadRecoveryFabricPlanV1 *)&fabric_object + && authority == (const struct ClusterThreadRecoveryAuthorityV1 *)&authority_object + && result != NULL); apply_step = ++step; if (apply_detail != RF_PAGE_PROOF_DETAIL_OK) return apply_detail; @@ -73,11 +67,9 @@ cluster_thread_recovery_fabric_apply_v1( } void -cluster_thread_recovery_fabric_plan_destroy_v1( - ClusterThreadRecoveryFabricPlanV1 **plan) +cluster_thread_recovery_fabric_plan_destroy_v1(ClusterThreadRecoveryFabricPlanV1 **plan) { - UT_ASSERT(plan != NULL && *plan == - (ClusterThreadRecoveryFabricPlanV1 *) &fabric_object); + UT_ASSERT(plan != NULL && *plan == (ClusterThreadRecoveryFabricPlanV1 *)&fabric_object); destroy_step = ++step; *plan = NULL; } @@ -96,17 +88,18 @@ UT_TEST(test_scan_then_apply_then_destroy_returns_only_complete_result) uint64 records = 0; init_case(); - UT_ASSERT_EQ(cluster_thread_recovery_fabric_execute_root_v1(2, 0x100, - 0x200, (const struct ClusterThreadRecoveryAuthorityV1 *) - &authority_object, false, &result, &records), - RF_PAGE_PROOF_DETAIL_OK); + UT_ASSERT_EQ(cluster_thread_recovery_fabric_execute_root_v1( + 2, 0x100, 0x200, + (const struct ClusterThreadRecoveryAuthorityV1 *)&authority_object, false, + &result, &records), + RF_PAGE_PROOF_DETAIL_OK); UT_ASSERT(scan_step < apply_step && apply_step < destroy_step); UT_ASSERT_EQ(records, 4); UT_ASSERT_EQ(result.page_target_count, 3); UT_ASSERT_EQ(result.page_write_count, 2); UT_ASSERT_EQ(result.page_result_skip_count, 1); - UT_ASSERT(result.page_durability_complete && result.page_postread_complete && - result.side_apply_complete); + UT_ASSERT(result.page_durability_complete && result.page_postread_complete + && result.side_apply_complete); } UT_TEST(test_scan_failure_never_calls_apply_and_leaves_zero_outputs) @@ -117,10 +110,11 @@ UT_TEST(test_scan_failure_never_calls_apply_and_leaves_zero_outputs) init_case(); scan_detail = RF_PAGE_PROOF_DETAIL_SOURCE_GAP; memset(&result, 0x7f, sizeof(result)); - UT_ASSERT_EQ(cluster_thread_recovery_fabric_execute_root_v1(2, 0x100, - 0x200, (const struct ClusterThreadRecoveryAuthorityV1 *) - &authority_object, false, &result, &records), - RF_PAGE_PROOF_DETAIL_SOURCE_GAP); + UT_ASSERT_EQ(cluster_thread_recovery_fabric_execute_root_v1( + 2, 0x100, 0x200, + (const struct ClusterThreadRecoveryAuthorityV1 *)&authority_object, false, + &result, &records), + RF_PAGE_PROOF_DETAIL_SOURCE_GAP); UT_ASSERT(scan_step != 0 && apply_step == 0 && destroy_step == 0); UT_ASSERT_EQ(records, 0); UT_ASSERT_EQ(result.page_target_count, 0); @@ -134,10 +128,11 @@ UT_TEST(test_apply_failure_destroys_plan_and_leaves_zero_outputs) init_case(); apply_detail = RF_PAGE_PROOF_DETAIL_SIDE_INCOMPLETE; memset(&result, 0x7f, sizeof(result)); - UT_ASSERT_EQ(cluster_thread_recovery_fabric_execute_root_v1(2, 0x100, - 0x200, (const struct ClusterThreadRecoveryAuthorityV1 *) - &authority_object, false, &result, &records), - RF_PAGE_PROOF_DETAIL_SIDE_INCOMPLETE); + UT_ASSERT_EQ(cluster_thread_recovery_fabric_execute_root_v1( + 2, 0x100, 0x200, + (const struct ClusterThreadRecoveryAuthorityV1 *)&authority_object, false, + &result, &records), + RF_PAGE_PROOF_DETAIL_SIDE_INCOMPLETE); UT_ASSERT(scan_step < apply_step && apply_step < destroy_step); UT_ASSERT_EQ(records, 0); UT_ASSERT_EQ(result.page_target_count, 0); diff --git a/src/test/cluster_unit/test_cluster_thread_recovery_fabric_plan.c b/src/test/cluster_unit/test_cluster_thread_recovery_fabric_plan.c index ad91d74c663..3e847a35311 100644 --- a/src/test/cluster_unit/test_cluster_thread_recovery_fabric_plan.c +++ b/src/test/cluster_unit/test_cluster_thread_recovery_fabric_plan.c @@ -13,11 +13,9 @@ UT_DEFINE_GLOBALS(); void -ExceptionalCondition(const char *condition_name, const char *file_name, - int line_number) +ExceptionalCondition(const char *condition_name, const char *file_name, int line_number) { - printf("# unexpected Assert: %s at %s:%d\n", condition_name, file_name, - line_number); + printf("# unexpected Assert: %s at %s:%d\n", condition_name, file_name, line_number); abort(); } @@ -35,45 +33,43 @@ static RfPageOnlineRecordIdentityV1 observed_identity; RfPageProofDetailV1 rf_page_online_plan_create_v1(const RfPageOnlinePlanRequestV1 *request, - RfPageOnlinePlanV1 **out_plan) + RfPageOnlinePlanV1 **out_plan) { - UT_ASSERT(request != NULL && request->system_identifier == 99 && - request->participant_count == 1 && - request->retention_binding_cookie == 41); - *out_plan = (RfPageOnlinePlanV1 *) &page_plan_object; + UT_ASSERT(request != NULL && request->system_identifier == 99 && request->participant_count == 1 + && request->retention_binding_cookie == 41); + *out_plan = (RfPageOnlinePlanV1 *)&page_plan_object; return RF_PAGE_PROOF_DETAIL_OK; } RfPageProofDetailV1 rf_side_online_plan_create_v1(const RfSideOnlinePlanRequestV1 *request, - RfSideOnlinePlanV1 **out_plan) + RfSideOnlinePlanV1 **out_plan) { - UT_ASSERT(request != NULL && request->system_identifier == 99 && - request->participant_count == 1); - *out_plan = (RfSideOnlinePlanV1 *) &side_plan_object; + UT_ASSERT(request != NULL && request->system_identifier == 99 + && request->participant_count == 1); + *out_plan = (RfSideOnlinePlanV1 *)&side_plan_object; return RF_PAGE_PROOF_DETAIL_OK; } RfPageProofDetailV1 rf_page_detached_preflight_v1(XLogReaderState *record, bool space_active, - const RfDetachedOwnerOpsV1 *owner_ops, RfDetachedRecordPlanV1 *plan) + const RfDetachedOwnerOpsV1 *owner_ops, RfDetachedRecordPlanV1 *plan) { RfOpcodeRouteV1 route; - UT_ASSERT(!space_active && owner_ops != NULL && - owner_ops->preflight_side_record != NULL && - owner_ops->preflight_side_component != NULL && - owner_ops->preflight_rebuildable_component != NULL); + UT_ASSERT(!space_active && owner_ops != NULL && owner_ops->preflight_side_record != NULL + && owner_ops->preflight_side_component != NULL + && owner_ops->preflight_rebuildable_component != NULL); memset(&route, 0, sizeof(route)); route.record_owner = RF_ROUTE_OWNER_LOGICAL_NOOP; - UT_ASSERT_EQ(owner_ops->preflight_side_record(owner_ops->arg, &route, - NULL, NULL), RF_PAGE_PROOF_DETAIL_OK); + UT_ASSERT_EQ(owner_ops->preflight_side_record(owner_ops->arg, &route, NULL, NULL), + RF_PAGE_PROOF_DETAIL_OK); route.record_owner = RF_ROUTE_OWNER_SIDE_TYPED; - UT_ASSERT_EQ(owner_ops->preflight_side_record(owner_ops->arg, &route, - NULL, NULL), RF_PAGE_PROOF_DETAIL_OK); + UT_ASSERT_EQ(owner_ops->preflight_side_record(owner_ops->arg, &route, NULL, NULL), + RF_PAGE_PROOF_DETAIL_OK); route.record_owner = RF_ROUTE_OWNER_INVALID; - UT_ASSERT_EQ(owner_ops->preflight_side_record(owner_ops->arg, &route, - NULL, NULL), RF_PAGE_PROOF_DETAIL_SIDE_INCOMPLETE); + UT_ASSERT_EQ(owner_ops->preflight_side_record(owner_ops->arg, &route, NULL, NULL), + RF_PAGE_PROOF_DETAIL_SIDE_INCOMPLETE); memset(plan, 0, sizeof(*plan)); plan->source_record = record; plan->route.record_owner = RF_ROUTE_OWNER_LOGICAL_NOOP; @@ -84,33 +80,31 @@ rf_page_detached_preflight_v1(XLogReaderState *record, bool space_active, RfPageProofDetailV1 rf_page_online_plan_feed_record_v1(RfPageOnlinePlanV1 *plan, - const RfDetachedRecordPlanV1 *record_plan, - const RfPageOnlineRecordIdentityV1 *identity) + const RfDetachedRecordPlanV1 *record_plan, + const RfPageOnlineRecordIdentityV1 *identity) { - UT_ASSERT(plan == (RfPageOnlinePlanV1 *) &page_plan_object && - record_plan != NULL && record_plan->preflight_complete); + UT_ASSERT(plan == (RfPageOnlinePlanV1 *)&page_plan_object && record_plan != NULL + && record_plan->preflight_complete); observed_identity = *identity; page_feed_step = ++step; - return fail_page_feed ? RF_PAGE_PROOF_DETAIL_EDGE_GAP : - RF_PAGE_PROOF_DETAIL_OK; + return fail_page_feed ? RF_PAGE_PROOF_DETAIL_EDGE_GAP : RF_PAGE_PROOF_DETAIL_OK; } RfPageProofDetailV1 rf_side_online_plan_feed_record_v1(RfSideOnlinePlanV1 *plan, - const RfDetachedRecordPlanV1 *record_plan, - const RfPageOnlineRecordIdentityV1 *identity) + const RfDetachedRecordPlanV1 *record_plan, + const RfPageOnlineRecordIdentityV1 *identity) { - UT_ASSERT(plan == (RfSideOnlinePlanV1 *) &side_plan_object && - record_plan != NULL && identity != NULL); + UT_ASSERT(plan == (RfSideOnlinePlanV1 *)&side_plan_object && record_plan != NULL + && identity != NULL); side_feed_step = ++step; - return fail_side_feed ? RF_PAGE_PROOF_DETAIL_SIDE_INCOMPLETE : - RF_PAGE_PROOF_DETAIL_OK; + return fail_side_feed ? RF_PAGE_PROOF_DETAIL_SIDE_INCOMPLETE : RF_PAGE_PROOF_DETAIL_OK; } RfPageProofDetailV1 rf_page_online_plan_seal_v1(RfPageOnlinePlanV1 *plan) { - UT_ASSERT(plan == (RfPageOnlinePlanV1 *) &page_plan_object); + UT_ASSERT(plan == (RfPageOnlinePlanV1 *)&page_plan_object); page_seal_step = ++step; return RF_PAGE_PROOF_DETAIL_OK; } @@ -118,7 +112,7 @@ rf_page_online_plan_seal_v1(RfPageOnlinePlanV1 *plan) RfPageProofDetailV1 rf_side_online_plan_seal_v1(RfSideOnlinePlanV1 *plan) { - UT_ASSERT(plan == (RfSideOnlinePlanV1 *) &side_plan_object); + UT_ASSERT(plan == (RfSideOnlinePlanV1 *)&side_plan_object); side_seal_step = ++step; return RF_PAGE_PROOF_DETAIL_OK; } @@ -163,8 +157,8 @@ create_plan(void) request.physical_cuts = &cut; request.participant_count = 1; request.retention_binding_cookie = 41; - UT_ASSERT_EQ(cluster_thread_recovery_fabric_plan_create_v1(&request, - &plan), RF_PAGE_PROOF_DETAIL_OK); + UT_ASSERT_EQ(cluster_thread_recovery_fabric_plan_create_v1(&request, &plan), + RF_PAGE_PROOF_DETAIL_OK); return plan; } @@ -179,7 +173,7 @@ init_reader(XLogReaderState *reader, DecodedXLogRecord *decoded) reader->EndRecPtr = 0x200; decoded->lsn = reader->ReadRecPtr; decoded->next_lsn = reader->EndRecPtr; - decoded->header.xl_crc = (pg_crc32c) 0x12345678; + decoded->header.xl_crc = (pg_crc32c)0x12345678; decoded->header.xl_rmid = RM_XLOG_ID; decoded->header.xl_info = 0x50; } @@ -192,8 +186,8 @@ UT_TEST(test_record_is_preflighted_then_fed_to_page_and_side) reset_steps(); init_reader(&reader, &decoded); - UT_ASSERT_EQ(cluster_thread_recovery_fabric_plan_feed_record_v1(plan, - &reader, 0), RF_PAGE_PROOF_DETAIL_OK); + UT_ASSERT_EQ(cluster_thread_recovery_fabric_plan_feed_record_v1(plan, &reader, 0), + RF_PAGE_PROOF_DETAIL_OK); UT_ASSERT(detached_step < page_feed_step && page_feed_step < side_feed_step); UT_ASSERT_EQ(observed_identity.record.system_identifier, 99); UT_ASSERT_EQ(observed_identity.record.origin_thread, 2); @@ -216,11 +210,11 @@ UT_TEST(test_page_failure_prevents_side_and_poisons_plan) reset_steps(); init_reader(&reader, &decoded); fail_page_feed = true; - UT_ASSERT_EQ(cluster_thread_recovery_fabric_plan_feed_record_v1(plan, - &reader, 0), RF_PAGE_PROOF_DETAIL_EDGE_GAP); + UT_ASSERT_EQ(cluster_thread_recovery_fabric_plan_feed_record_v1(plan, &reader, 0), + RF_PAGE_PROOF_DETAIL_EDGE_GAP); UT_ASSERT_EQ(side_feed_step, 0); UT_ASSERT_EQ(cluster_thread_recovery_fabric_plan_seal_v1(plan), - RF_PAGE_PROOF_DETAIL_COMPONENT_INCOMPLETE); + RF_PAGE_PROOF_DETAIL_COMPONENT_INCOMPLETE); cluster_thread_recovery_fabric_plan_destroy_v1(&plan); } @@ -233,11 +227,11 @@ UT_TEST(test_side_failure_poisons_whole_plan) reset_steps(); init_reader(&reader, &decoded); fail_side_feed = true; - UT_ASSERT_EQ(cluster_thread_recovery_fabric_plan_feed_record_v1(plan, - &reader, 0), RF_PAGE_PROOF_DETAIL_SIDE_INCOMPLETE); + UT_ASSERT_EQ(cluster_thread_recovery_fabric_plan_feed_record_v1(plan, &reader, 0), + RF_PAGE_PROOF_DETAIL_SIDE_INCOMPLETE); UT_ASSERT(page_feed_step != 0 && side_feed_step != 0); UT_ASSERT_EQ(cluster_thread_recovery_fabric_plan_seal_v1(plan), - RF_PAGE_PROOF_DETAIL_COMPONENT_INCOMPLETE); + RF_PAGE_PROOF_DETAIL_COMPONENT_INCOMPLETE); cluster_thread_recovery_fabric_plan_destroy_v1(&plan); } @@ -249,19 +243,17 @@ UT_TEST(test_seal_closes_page_before_side_and_exposes_both) reset_steps(); init_reader(&reader, &decoded); - UT_ASSERT_EQ(cluster_thread_recovery_fabric_plan_feed_record_v1(plan, - &reader, 0), RF_PAGE_PROOF_DETAIL_OK); - UT_ASSERT_EQ(cluster_thread_recovery_fabric_plan_seal_v1(plan), - RF_PAGE_PROOF_DETAIL_OK); + UT_ASSERT_EQ(cluster_thread_recovery_fabric_plan_feed_record_v1(plan, &reader, 0), + RF_PAGE_PROOF_DETAIL_OK); + UT_ASSERT_EQ(cluster_thread_recovery_fabric_plan_seal_v1(plan), RF_PAGE_PROOF_DETAIL_OK); UT_ASSERT(page_seal_step < side_seal_step); - UT_ASSERT(cluster_thread_recovery_fabric_page_plan_v1(plan) == - (RfPageOnlinePlanV1 *) &page_plan_object); - UT_ASSERT(cluster_thread_recovery_fabric_side_plan_v1(plan) == - (RfSideOnlinePlanV1 *) &side_plan_object); + UT_ASSERT(cluster_thread_recovery_fabric_page_plan_v1(plan) + == (RfPageOnlinePlanV1 *)&page_plan_object); + UT_ASSERT(cluster_thread_recovery_fabric_side_plan_v1(plan) + == (RfSideOnlinePlanV1 *)&side_plan_object); UT_ASSERT_EQ(cluster_thread_recovery_fabric_participant_count_v1(plan), 1); - UT_ASSERT(cluster_thread_recovery_fabric_identity_matches_v1(plan, 99, - (const uint8[16]) {3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3})); + UT_ASSERT(cluster_thread_recovery_fabric_identity_matches_v1( + plan, 99, (const uint8[16]){ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 })); { RfContributorStreamCutV1 cut; diff --git a/src/test/cluster_unit/test_cluster_thread_recovery_fabric_scan.c b/src/test/cluster_unit/test_cluster_thread_recovery_fabric_scan.c index 14b3ba597c8..74561cf22ff 100644 --- a/src/test/cluster_unit/test_cluster_thread_recovery_fabric_scan.c +++ b/src/test/cluster_unit/test_cluster_thread_recovery_fabric_scan.c @@ -15,11 +15,9 @@ UT_DEFINE_GLOBALS(); void -ExceptionalCondition(const char *condition_name, const char *file_name, - int line_number) +ExceptionalCondition(const char *condition_name, const char *file_name, int line_number) { - printf("# unexpected Assert: %s at %s:%d\n", condition_name, file_name, - line_number); + printf("# unexpected Assert: %s at %s:%d\n", condition_name, file_name, line_number); abort(); } @@ -49,17 +47,16 @@ cluster_thread_recovery_authority_revalidate_nowait_v1( const ClusterThreadRecoveryAuthorityV1 *authority) { authority_revalidations++; - return authority != NULL && authority_current ? - CLUSTER_THREAD_AUTHORITY_OK : CLUSTER_THREAD_AUTHORITY_ROOT_STALE; + return authority != NULL && authority_current ? CLUSTER_THREAD_AUTHORITY_OK + : CLUSTER_THREAD_AUTHORITY_ROOT_STALE; } bool cluster_thread_recovery_authority_covers_window_v1( - const ClusterThreadRecoveryAuthorityV1 *authority, uint16 dead_thread, - XLogRecPtr scan_begin, XLogRecPtr scan_end) + const ClusterThreadRecoveryAuthorityV1 *authority, uint16 dead_thread, XLogRecPtr scan_begin, + XLogRecPtr scan_end) { - return authority != NULL && dead_thread == 2 && scan_begin == 0x100 && - scan_end == 0x200; + return authority != NULL && dead_thread == 2 && scan_begin == 0x100 && scan_end == 0x200; } XLogReaderState * @@ -114,45 +111,40 @@ cluster_thread_recovery_fabric_plan_create_v1( UT_ASSERT(request != NULL && out_plan != NULL); UT_ASSERT_EQ(request->system_identifier, 99); - UT_ASSERT(request->storage_uuid[0] == 3 && request->participant_count == 1 && - request->retention_binding_cookie != 0 && !request->space_active); + UT_ASSERT(request->storage_uuid[0] == 3 && request->participant_count == 1 + && request->retention_binding_cookie != 0 && !request->space_active); cut = request->physical_cuts; - UT_ASSERT(cut != NULL && cut->failed_thread == 2 && - cut->flags == RF_CONTRIBUTOR_CUT_COMPLETE && cut->timeline_id == 7 && - cut->scan_begin_inclusive == 0x100 && - cut->scan_end_exclusive == 0x200); + UT_ASSERT(cut != NULL && cut->failed_thread == 2 && cut->flags == RF_CONTRIBUTOR_CUT_COMPLETE + && cut->timeline_id == 7 && cut->scan_begin_inclusive == 0x100 + && cut->scan_end_exclusive == 0x200); plan_create_count++; - *out_plan = (ClusterThreadRecoveryFabricPlanV1 *) &fabric_object; + *out_plan = (ClusterThreadRecoveryFabricPlanV1 *)&fabric_object; return RF_PAGE_PROOF_DETAIL_OK; } RfPageProofDetailV1 -cluster_thread_recovery_fabric_plan_feed_record_v1( - ClusterThreadRecoveryFabricPlanV1 *plan, XLogReaderState *state, - uint16 participant_index) +cluster_thread_recovery_fabric_plan_feed_record_v1(ClusterThreadRecoveryFabricPlanV1 *plan, + XLogReaderState *state, uint16 participant_index) { - UT_ASSERT(plan == (ClusterThreadRecoveryFabricPlanV1 *) &fabric_object && - state == &reader && state->seg.ws_tli == 7 && participant_index == 0); + UT_ASSERT(plan == (ClusterThreadRecoveryFabricPlanV1 *)&fabric_object && state == &reader + && state->seg.ws_tli == 7 && participant_index == 0); plan_feed_count++; - return plan_feed_count == feed_fail_at ? - RF_PAGE_PROOF_DETAIL_OPCODE_UNSUPPORTED : RF_PAGE_PROOF_DETAIL_OK; + return plan_feed_count == feed_fail_at ? RF_PAGE_PROOF_DETAIL_OPCODE_UNSUPPORTED + : RF_PAGE_PROOF_DETAIL_OK; } RfPageProofDetailV1 -cluster_thread_recovery_fabric_plan_seal_v1( - ClusterThreadRecoveryFabricPlanV1 *plan) +cluster_thread_recovery_fabric_plan_seal_v1(ClusterThreadRecoveryFabricPlanV1 *plan) { - UT_ASSERT(plan == (ClusterThreadRecoveryFabricPlanV1 *) &fabric_object); + UT_ASSERT(plan == (ClusterThreadRecoveryFabricPlanV1 *)&fabric_object); plan_seal_count++; return RF_PAGE_PROOF_DETAIL_OK; } void -cluster_thread_recovery_fabric_plan_destroy_v1( - ClusterThreadRecoveryFabricPlanV1 **plan) +cluster_thread_recovery_fabric_plan_destroy_v1(ClusterThreadRecoveryFabricPlanV1 **plan) { - UT_ASSERT(plan != NULL && - *plan == (ClusterThreadRecoveryFabricPlanV1 *) &fabric_object); + UT_ASSERT(plan != NULL && *plan == (ClusterThreadRecoveryFabricPlanV1 *)&fabric_object); plan_destroy_count++; *plan = NULL; } @@ -176,8 +168,7 @@ init_case(ClusterThreadRecoveryAuthorityV1 *authority) root.validated_tail_lsn_exclusive = 0x200; authority->duty = &duty; authority->root_snapshot = &root; - authority->retention_pin = - (ClusterWalRetentionPin *) &retention_pin_object; + authority->retention_pin = (ClusterWalRetentionPin *)&retention_pin_object; record_begin[0] = 0x100; record_end[0] = 0x140; record_begin[1] = 0x140; @@ -199,10 +190,10 @@ UT_TEST(test_scans_exact_root_cut_and_seals_only_at_upper_boundary) uint64 records = 0; init_case(&authority); - UT_ASSERT_EQ(cluster_thread_recovery_fabric_scan_root_v1(2, 0x100, - 0x200, &authority, false, &plan, &records), - RF_PAGE_PROOF_DETAIL_OK); - UT_ASSERT(plan == (ClusterThreadRecoveryFabricPlanV1 *) &fabric_object); + UT_ASSERT_EQ(cluster_thread_recovery_fabric_scan_root_v1(2, 0x100, 0x200, &authority, false, + &plan, &records), + RF_PAGE_PROOF_DETAIL_OK); + UT_ASSERT(plan == (ClusterThreadRecoveryFabricPlanV1 *)&fabric_object); UT_ASSERT_EQ(records, 2); UT_ASSERT_EQ(begin_read_lsn, 0x100); UT_ASSERT(authority_revalidations >= 2); @@ -222,9 +213,9 @@ UT_TEST(test_early_end_destroys_unsealed_plan) init_case(&authority); record_count = 1; - UT_ASSERT_EQ(cluster_thread_recovery_fabric_scan_root_v1(2, 0x100, - 0x200, &authority, false, &plan, &records), - RF_PAGE_PROOF_DETAIL_SOURCE_GAP); + UT_ASSERT_EQ(cluster_thread_recovery_fabric_scan_root_v1(2, 0x100, 0x200, &authority, false, + &plan, &records), + RF_PAGE_PROOF_DETAIL_SOURCE_GAP); UT_ASSERT(plan == NULL && records == 0); UT_ASSERT_EQ(plan_seal_count, 0); UT_ASSERT_EQ(plan_destroy_count, 1); @@ -239,9 +230,9 @@ UT_TEST(test_feed_failure_poisons_and_destroys_whole_plan) init_case(&authority); feed_fail_at = 2; - UT_ASSERT_EQ(cluster_thread_recovery_fabric_scan_root_v1(2, 0x100, - 0x200, &authority, false, &plan, &records), - RF_PAGE_PROOF_DETAIL_OPCODE_UNSUPPORTED); + UT_ASSERT_EQ(cluster_thread_recovery_fabric_scan_root_v1(2, 0x100, 0x200, &authority, false, + &plan, &records), + RF_PAGE_PROOF_DETAIL_OPCODE_UNSUPPORTED); UT_ASSERT(plan == NULL && records == 0); UT_ASSERT_EQ(plan_feed_count, 2); UT_ASSERT_EQ(plan_seal_count, 0); @@ -255,9 +246,9 @@ UT_TEST(test_non_root_window_is_rejected_before_reader_or_plan) uint64 records = 9; init_case(&authority); - UT_ASSERT_EQ(cluster_thread_recovery_fabric_scan_root_v1(2, 0x120, - 0x200, &authority, false, &plan, &records), - RF_PAGE_PROOF_DETAIL_ROOT_STALE); + UT_ASSERT_EQ(cluster_thread_recovery_fabric_scan_root_v1(2, 0x120, 0x200, &authority, false, + &plan, &records), + RF_PAGE_PROOF_DETAIL_ROOT_STALE); UT_ASSERT(plan == NULL && records == 0); UT_ASSERT_EQ(reader_make_count, 0); UT_ASSERT_EQ(plan_create_count, 0); diff --git a/src/test/cluster_unit/test_cluster_tt_2pc.c b/src/test/cluster_unit/test_cluster_tt_2pc.c index 4c9ecd973f4..5f9e2abcb15 100644 --- a/src/test/cluster_unit/test_cluster_tt_2pc.c +++ b/src/test/cluster_unit/test_cluster_tt_2pc.c @@ -368,17 +368,16 @@ UT_TEST(test_s14_prefinish_is_modifier_gated_and_error_safe) = loop == NULL ? NULL : strstr(loop, "cluster_tt_twophase_modifier_recheck_or_error("); durable_commit = start == NULL ? NULL : strstr(start, "cluster_tt_slot_durable_commit("); abort_recheck = durable_commit == NULL - ? NULL - : strstr(durable_commit, "cluster_tt_twophase_modifier_recheck_or_error("); + ? NULL + : strstr(durable_commit, "cluster_tt_twophase_modifier_recheck_or_error("); durable_abort = start == NULL ? NULL : strstr(start, "cluster_tt_slot_durable_abort("); head_recheck = durable_abort == NULL - ? NULL - : strstr(durable_abort, "cluster_tt_twophase_modifier_recheck_or_error("); + ? NULL + : strstr(durable_abort, "cluster_tt_twophase_modifier_recheck_or_error("); durable_set_head = start == NULL ? NULL : strstr(start, "cluster_tt_slot_durable_set_head("); finally_block = start == NULL ? NULL : strstr(start, "PG_FINALLY();"); - leave = finally_block == NULL - ? NULL - : strstr(finally_block, "cluster_semantic_activation_leave("); + leave = finally_block == NULL ? NULL + : strstr(finally_block, "cluster_semantic_activation_leave("); UT_ASSERT_NOT_NULL(start); UT_ASSERT_NOT_NULL(end); @@ -395,9 +394,9 @@ UT_TEST(test_s14_prefinish_is_modifier_gated_and_error_safe) UT_ASSERT_NOT_NULL(finally_block); UT_ASSERT_NOT_NULL(leave); if (start != NULL && end != NULL && enter != NULL && try_block != NULL && parse != NULL - && loop != NULL && commit_recheck != NULL && durable_commit != NULL - && abort_recheck != NULL && durable_abort != NULL && head_recheck != NULL - && durable_set_head != NULL && finally_block != NULL && leave != NULL) + && loop != NULL && commit_recheck != NULL && durable_commit != NULL && abort_recheck != NULL + && durable_abort != NULL && head_recheck != NULL && durable_set_head != NULL + && finally_block != NULL && leave != NULL) UT_ASSERT(start < enter && enter < try_block && try_block < parse && parse < loop && loop < commit_recheck && commit_recheck < durable_commit && durable_commit < abort_recheck && abort_recheck < durable_abort @@ -420,22 +419,19 @@ UT_TEST(test_s15_prefinish_preserves_binding_origin) if (source == NULL) return; start = strstr(source, "\ncluster_tt_twophase_prefinish("); - end = start == NULL ? NULL : strstr(start, - "\n}\n\n#endif /* USE_PGRAC_CLUSTER */"); - derive = start == NULL ? NULL : strstr(start, - "cluster_tt_2pc_binding_origin_node(b, &origin_node_id)"); - assign = start == NULL ? NULL : strstr(start, - "key.origin_node_id = origin_node_id;"); - wrong = start == NULL ? NULL : strstr(start, - "key.origin_node_id = (uint16)cluster_node_id;"); + end = start == NULL ? NULL : strstr(start, "\n}\n\n#endif /* USE_PGRAC_CLUSTER */"); + derive = start == NULL + ? NULL + : strstr(start, "cluster_tt_2pc_binding_origin_node(b, &origin_node_id)"); + assign = start == NULL ? NULL : strstr(start, "key.origin_node_id = origin_node_id;"); + wrong = start == NULL ? NULL : strstr(start, "key.origin_node_id = (uint16)cluster_node_id;"); UT_ASSERT_NOT_NULL(start); UT_ASSERT_NOT_NULL(end); UT_ASSERT_NOT_NULL(derive); UT_ASSERT_NOT_NULL(assign); UT_ASSERT(wrong == NULL || (end != NULL && wrong > end)); - if (start != NULL && end != NULL && derive != NULL && assign != NULL) - { + if (start != NULL && end != NULL && derive != NULL && assign != NULL) { UT_ASSERT(derive < assign); UT_ASSERT(assign < end); } @@ -470,29 +466,33 @@ UT_TEST(test_s16_recovery_pending_activates_native_owner_before_success) if (source == NULL) return; install = strstr(source, "\nTwoPhaseRecoveryPendingInstall("); - install_end = install == NULL ? NULL : strstr(install, - "\n}\n\n/* Caller holds TwoPhaseStateLock"); + install_end + = install == NULL ? NULL : strstr(install, "\n}\n\n/* Caller holds TwoPhaseStateLock"); mark_guts = install == NULL ? NULL : strstr(install, "MarkAsPreparingGuts("); - mark_pending = install == NULL ? NULL : strstr(install, - "gxact->recovery_activation_pending = true;"); + mark_pending + = install == NULL ? NULL : strstr(install, "gxact->recovery_activation_pending = true;"); load_subxids = install == NULL ? NULL : strstr(install, "GXactLoadSubxactData("); mark_prepared = install == NULL ? NULL : strstr(install, "MarkAsPrepared(gxact, true);"); - recover_records = install == NULL ? NULL : strstr(install, - "ProcessRecords(bufptr, xid, twophase_recover_callbacks);"); + recover_records + = install == NULL + ? NULL + : strstr(install, "ProcessRecords(bufptr, xid, twophase_recover_callbacks);"); catch_block = recover_records == NULL ? NULL : strstr(recover_records, "PG_CATCH();"); panic_transition = catch_block == NULL ? NULL : strstr(catch_block, "ereport(PANIC"); - clear_pending = install == NULL ? NULL : strstr(install, - "gxact->recovery_activation_pending = false;"); + clear_pending + = install == NULL ? NULL : strstr(install, "gxact->recovery_activation_pending = false;"); post_prepare = install == NULL ? NULL : strstr(install, "PostPrepare_Twophase();"); - postread = post_prepare == NULL ? NULL : strstr(post_prepare, - "postread = ReadTwoPhaseFile(xid, false);"); + postread = post_prepare == NULL + ? NULL + : strstr(post_prepare, "postread = ReadTwoPhaseFile(xid, false);"); lock_gxact = strstr(source, "\nLockGXact("); lock_end = lock_gxact == NULL ? NULL : strstr(lock_gxact, "\n}\n\n/*\n * RemoveGXact"); view = strstr(source, "\npg_prepared_xact(PG_FUNCTION_ARGS)"); view_end = view == NULL ? NULL : strstr(view, "\n}\n\n/*\n * TwoPhaseGetGXact"); prepared_predicate = strstr(source, "\nTwoPhaseTransactionIdIsPrepared("); - prepared_predicate_end = prepared_predicate == NULL ? NULL : - strstr(prepared_predicate, "\n}\n\n\n/* Working status"); + prepared_predicate_end = prepared_predicate == NULL + ? NULL + : strstr(prepared_predicate, "\n}\n\n\n/* Working status"); UT_ASSERT_NOT_NULL(install); UT_ASSERT_NOT_NULL(install_end); @@ -512,24 +512,21 @@ UT_TEST(test_s16_recovery_pending_activates_native_owner_before_success) UT_ASSERT_NOT_NULL(view_end); UT_ASSERT_NOT_NULL(prepared_predicate); UT_ASSERT_NOT_NULL(prepared_predicate_end); - if (install != NULL && install_end != NULL && mark_guts != NULL && - mark_pending != NULL && load_subxids != NULL && mark_prepared != NULL && - recover_records != NULL && catch_block != NULL && panic_transition != NULL && - clear_pending != NULL && post_prepare != NULL && - postread != NULL) - UT_ASSERT(install < mark_guts && mark_guts < mark_pending && - mark_pending < load_subxids && load_subxids < mark_prepared && - mark_prepared < recover_records && recover_records < catch_block && - catch_block < panic_transition && panic_transition < clear_pending && - clear_pending < post_prepare && post_prepare < postread && - postread < install_end); + if (install != NULL && install_end != NULL && mark_guts != NULL && mark_pending != NULL + && load_subxids != NULL && mark_prepared != NULL && recover_records != NULL + && catch_block != NULL && panic_transition != NULL && clear_pending != NULL + && post_prepare != NULL && postread != NULL) + UT_ASSERT(install < mark_guts && mark_guts < mark_pending && mark_pending < load_subxids + && load_subxids < mark_prepared && mark_prepared < recover_records + && recover_records < catch_block && catch_block < panic_transition + && panic_transition < clear_pending && clear_pending < post_prepare + && post_prepare < postread && postread < install_end); if (lock_gxact != NULL && lock_end != NULL) UT_ASSERT_NOT_NULL(strstr(lock_gxact, "gxact->recovery_activation_pending")); if (view != NULL && view_end != NULL) UT_ASSERT_NOT_NULL(strstr(view, "gxact->recovery_activation_pending")); if (prepared_predicate != NULL && prepared_predicate_end != NULL) - UT_ASSERT_NOT_NULL(strstr(prepared_predicate, - "!gxact->recovery_activation_pending")); + UT_ASSERT_NOT_NULL(strstr(prepared_predicate, "!gxact->recovery_activation_pending")); free(source); } @@ -553,20 +550,18 @@ UT_TEST(test_s17_recovery_pending_remains_reco_owned_after_activation) if (source == NULL) return; definition = strstr(source, "typedef struct GlobalTransactionData {"); - definition_end = definition == NULL ? NULL : strstr(definition, - "} GlobalTransactionData;"); + definition_end = definition == NULL ? NULL : strstr(definition, "} GlobalTransactionData;"); install = strstr(source, "\nTwoPhaseRecoveryPendingInstall("); - install_end = install == NULL ? NULL : strstr(install, - "\n}\n\n/* Caller holds TwoPhaseStateLock"); - mark_owned = install == NULL ? NULL : strstr(install, - "gxact->recovery_managed = true;"); - clear_activation = install == NULL ? NULL : strstr(install, - "gxact->recovery_activation_pending = false;"); - remark_owned = clear_activation == NULL ? NULL : strstr(clear_activation, - "gxact->recovery_managed = true;"); + install_end + = install == NULL ? NULL : strstr(install, "\n}\n\n/* Caller holds TwoPhaseStateLock"); + mark_owned = install == NULL ? NULL : strstr(install, "gxact->recovery_managed = true;"); + clear_activation + = install == NULL ? NULL : strstr(install, "gxact->recovery_activation_pending = false;"); + remark_owned = clear_activation == NULL + ? NULL + : strstr(clear_activation, "gxact->recovery_managed = true;"); lock_gxact = strstr(source, "\nLockGXact("); - lock_end = lock_gxact == NULL ? NULL : strstr(lock_gxact, - "\n}\n\n/*\n * RemoveGXact"); + lock_end = lock_gxact == NULL ? NULL : strstr(lock_gxact, "\n}\n\n/*\n * RemoveGXact"); UT_ASSERT_NOT_NULL(definition); UT_ASSERT_NOT_NULL(definition_end); @@ -579,10 +574,10 @@ UT_TEST(test_s17_recovery_pending_remains_reco_owned_after_activation) UT_ASSERT_NOT_NULL(lock_end); if (definition != NULL && definition_end != NULL) UT_ASSERT_NOT_NULL(strstr(definition, "bool recovery_managed;")); - if (install != NULL && install_end != NULL && mark_owned != NULL && - clear_activation != NULL && remark_owned != NULL) - UT_ASSERT(install < mark_owned && mark_owned < clear_activation && - clear_activation < remark_owned && remark_owned < install_end); + if (install != NULL && install_end != NULL && mark_owned != NULL && clear_activation != NULL + && remark_owned != NULL) + UT_ASSERT(install < mark_owned && mark_owned < clear_activation + && clear_activation < remark_owned && remark_owned < install_end); if (lock_gxact != NULL && lock_end != NULL) UT_ASSERT_NOT_NULL(strstr(lock_gxact, "gxact->recovery_managed")); free(source); @@ -600,16 +595,16 @@ UT_TEST(test_s20_prepared_count_excludes_only_terminal_cleanup_receipts) if (source == NULL) return; counter = strstr(source, "\nGetNumberOfPreparedTransactions(void)"); - counter_end = counter == NULL ? NULL : strstr(counter, - "\n}\n#endif\t\t\t\t\t\t\t/* USE_PGRAC_CLUSTER */"); + counter_end = counter == NULL + ? NULL + : strstr(counter, "\n}\n#endif\t\t\t\t\t\t\t/* USE_PGRAC_CLUSTER */"); UT_ASSERT_NOT_NULL(counter); UT_ASSERT_NOT_NULL(counter_end); - if (counter != NULL && counter_end != NULL) - { - UT_ASSERT_NOT_NULL(strstr(counter, - "!TwoPhaseState->prepXacts[i]->recovery_terminal_cleanup_pending")); - UT_ASSERT(strstr(counter, "prepXacts[i]->valid") == NULL || - strstr(counter, "prepXacts[i]->valid") > counter_end); + if (counter != NULL && counter_end != NULL) { + UT_ASSERT_NOT_NULL( + strstr(counter, "!TwoPhaseState->prepXacts[i]->recovery_terminal_cleanup_pending")); + UT_ASSERT(strstr(counter, "prepXacts[i]->valid") == NULL + || strstr(counter, "prepXacts[i]->valid") > counter_end); } free(source); } @@ -636,25 +631,19 @@ UT_TEST(test_s18_restart_finish_fence_reuses_root_and_projection) if (source == NULL) return; helper = strstr(source, "\nTwoPhaseRecoveryFinishIsFenced("); - helper_end = helper == NULL ? NULL : strstr(helper, - "\n#endif\n\n/*\n * LockGXact"); - event_read = helper == NULL ? NULL : strstr(helper, - "cluster_reconfig_get_last_event("); - dead_test = helper == NULL ? NULL : strstr(helper, - "RECONFIG_KIND_FAIL_STOP"); - digest = helper == NULL ? NULL : strstr(helper, - "cluster_remote_xact_prepare_digest_v2("); - projection = helper == NULL ? NULL : strstr(helper, - "cluster_remote_xact_pending_matches_v2("); + helper_end = helper == NULL ? NULL : strstr(helper, "\n#endif\n\n/*\n * LockGXact"); + event_read = helper == NULL ? NULL : strstr(helper, "cluster_reconfig_get_last_event("); + dead_test = helper == NULL ? NULL : strstr(helper, "RECONFIG_KIND_FAIL_STOP"); + digest = helper == NULL ? NULL : strstr(helper, "cluster_remote_xact_prepare_digest_v2("); + projection = helper == NULL ? NULL : strstr(helper, "cluster_remote_xact_pending_matches_v2("); lock_gxact = strstr(source, "\nLockGXact("); - lock_end = lock_gxact == NULL ? NULL : strstr(lock_gxact, - "\n}\n\n/*\n * RemoveGXact"); - claim_owner = lock_gxact == NULL ? NULL : strstr(lock_gxact, - "gxact->locking_backend = MyBackendId;"); - release_owner_lock = claim_owner == NULL ? NULL : strstr(claim_owner, - "LWLockRelease(TwoPhaseStateLock);"); - finish_fence = lock_gxact == NULL ? NULL : strstr(lock_gxact, - "TwoPhaseRecoveryFinishIsFenced("); + lock_end = lock_gxact == NULL ? NULL : strstr(lock_gxact, "\n}\n\n/*\n * RemoveGXact"); + claim_owner + = lock_gxact == NULL ? NULL : strstr(lock_gxact, "gxact->locking_backend = MyBackendId;"); + release_owner_lock + = claim_owner == NULL ? NULL : strstr(claim_owner, "LWLockRelease(TwoPhaseStateLock);"); + finish_fence + = lock_gxact == NULL ? NULL : strstr(lock_gxact, "TwoPhaseRecoveryFinishIsFenced("); UT_ASSERT_NOT_NULL(helper); UT_ASSERT_NOT_NULL(helper_end); @@ -667,14 +656,14 @@ UT_TEST(test_s18_restart_finish_fence_reuses_root_and_projection) UT_ASSERT_NOT_NULL(claim_owner); UT_ASSERT_NOT_NULL(release_owner_lock); UT_ASSERT_NOT_NULL(finish_fence); - if (helper != NULL && helper_end != NULL && event_read != NULL && - dead_test != NULL && digest != NULL && projection != NULL) - UT_ASSERT(helper < event_read && event_read < dead_test && - dead_test < digest && digest < projection && projection < helper_end); - if (lock_gxact != NULL && lock_end != NULL && claim_owner != NULL && - release_owner_lock != NULL && finish_fence != NULL) - UT_ASSERT(lock_gxact < claim_owner && claim_owner < release_owner_lock && - release_owner_lock < finish_fence && finish_fence < lock_end); + if (helper != NULL && helper_end != NULL && event_read != NULL && dead_test != NULL + && digest != NULL && projection != NULL) + UT_ASSERT(helper < event_read && event_read < dead_test && dead_test < digest + && digest < projection && projection < helper_end); + if (lock_gxact != NULL && lock_end != NULL && claim_owner != NULL && release_owner_lock != NULL + && finish_fence != NULL) + UT_ASSERT(lock_gxact < claim_owner && claim_owner < release_owner_lock + && release_owner_lock < finish_fence && finish_fence < lock_end); UT_ASSERT(strstr(source, ".rfside") == NULL); free(source); } @@ -708,28 +697,33 @@ UT_TEST(test_s19_recovery_terminal_resolves_native_owner_without_new_wal) if (source == NULL) return; read_exact = strstr(source, "\nTwoPhaseRecoveryPendingReadExact("); - read_end = read_exact == NULL ? NULL : strstr(read_exact, - "\n}\n\nTwoPhaseRecoveryPendingResult\nTwoPhaseRecoveryPendingResolveExact("); - managed_read = read_exact == NULL ? NULL : strstr(read_exact, - "gxact->recovery_managed"); - read_file = read_exact == NULL ? NULL : strstr(read_exact, - "ReadTwoPhaseFile("); + read_end + = read_exact == NULL + ? NULL + : strstr( + read_exact, + "\n}\n\nTwoPhaseRecoveryPendingResult\nTwoPhaseRecoveryPendingResolveExact("); + managed_read = read_exact == NULL ? NULL : strstr(read_exact, "gxact->recovery_managed"); + read_file = read_exact == NULL ? NULL : strstr(read_exact, "ReadTwoPhaseFile("); resolve = strstr(source, "\nTwoPhaseRecoveryPendingResolveExact("); - resolve_end = resolve == NULL ? NULL : strstr(resolve, - "\n}\n\nTwoPhaseRecoveryPendingResult\nTwoPhaseRecoveryPendingCleanupExact("); + resolve_end + = resolve == NULL + ? NULL + : strstr( + resolve, + "\n}\n\nTwoPhaseRecoveryPendingResult\nTwoPhaseRecoveryPendingCleanupExact("); hold = resolve == NULL ? NULL : strstr(resolve, "HOLD_INTERRUPTS();"); proc_remove = resolve == NULL ? NULL : strstr(resolve, "ProcArrayRemove("); callbacks = resolve == NULL ? NULL : strstr(resolve, "ProcessRecords("); catch_block = callbacks == NULL ? NULL : strstr(callbacks, "PG_CATCH();"); - panic_transition = catch_block == NULL ? NULL : strstr(catch_block, - "ereport(PANIC"); - predicate_finish = resolve == NULL ? NULL : strstr(resolve, - "PredicateLockTwoPhaseFinish("); - cleanup_mark = resolve == NULL ? NULL : strstr(resolve, - "recovery_terminal_cleanup_pending = true;"); + panic_transition = catch_block == NULL ? NULL : strstr(catch_block, "ereport(PANIC"); + predicate_finish = resolve == NULL ? NULL : strstr(resolve, "PredicateLockTwoPhaseFinish("); + cleanup_mark + = resolve == NULL ? NULL : strstr(resolve, "recovery_terminal_cleanup_pending = true;"); cleanup = strstr(source, "\nTwoPhaseRecoveryPendingCleanupExact("); - cleanup_end = cleanup == NULL ? NULL : strstr(cleanup, - "\n}\n#endif\t\t\t\t\t\t\t/* USE_PGRAC_CLUSTER */"); + cleanup_end = cleanup == NULL + ? NULL + : strstr(cleanup, "\n}\n#endif\t\t\t\t\t\t\t/* USE_PGRAC_CLUSTER */"); remove_gxact = cleanup == NULL ? NULL : strstr(cleanup, "RemoveGXact("); remove_file = cleanup == NULL ? NULL : strstr(cleanup, "durable_unlink("); @@ -750,28 +744,21 @@ UT_TEST(test_s19_recovery_terminal_resolves_native_owner_without_new_wal) UT_ASSERT_NOT_NULL(cleanup_end); UT_ASSERT_NOT_NULL(remove_gxact); UT_ASSERT_NOT_NULL(remove_file); - if (read_exact != NULL && read_end != NULL && managed_read != NULL && - read_file != NULL) - UT_ASSERT(read_exact < managed_read && managed_read < read_file && - read_file < read_end); - if (resolve != NULL && resolve_end != NULL && hold != NULL && - proc_remove != NULL && callbacks != NULL && catch_block != NULL && - panic_transition != NULL && predicate_finish != NULL && - cleanup_mark != NULL) - UT_ASSERT(resolve < hold && hold < proc_remove && - proc_remove < callbacks && callbacks < catch_block && - catch_block < panic_transition && panic_transition < predicate_finish && - predicate_finish < cleanup_mark && cleanup_mark < resolve_end); - if (cleanup != NULL && cleanup_end != NULL && remove_gxact != NULL && - remove_file != NULL) - UT_ASSERT(cleanup < remove_file && remove_file < remove_gxact && - remove_gxact < cleanup_end); - if (resolve != NULL && resolve_end != NULL) - { - const char *duplicate_commit = strstr(resolve, - "RecordTransactionCommitPrepared("); - const char *duplicate_abort = strstr(resolve, - "RecordTransactionAbortPrepared("); + if (read_exact != NULL && read_end != NULL && managed_read != NULL && read_file != NULL) + UT_ASSERT(read_exact < managed_read && managed_read < read_file && read_file < read_end); + if (resolve != NULL && resolve_end != NULL && hold != NULL && proc_remove != NULL + && callbacks != NULL && catch_block != NULL && panic_transition != NULL + && predicate_finish != NULL && cleanup_mark != NULL) + UT_ASSERT(resolve < hold && hold < proc_remove && proc_remove < callbacks + && callbacks < catch_block && catch_block < panic_transition + && panic_transition < predicate_finish && predicate_finish < cleanup_mark + && cleanup_mark < resolve_end); + if (cleanup != NULL && cleanup_end != NULL && remove_gxact != NULL && remove_file != NULL) + UT_ASSERT(cleanup < remove_file && remove_file < remove_gxact + && remove_gxact < cleanup_end); + if (resolve != NULL && resolve_end != NULL) { + const char *duplicate_commit = strstr(resolve, "RecordTransactionCommitPrepared("); + const char *duplicate_abort = strstr(resolve, "RecordTransactionAbortPrepared("); UT_ASSERT(duplicate_commit == NULL || duplicate_commit > resolve_end); UT_ASSERT(duplicate_abort == NULL || duplicate_abort > resolve_end); diff --git a/src/test/cluster_unit/test_cluster_tt_durable.c b/src/test/cluster_unit/test_cluster_tt_durable.c index ff6d62ab316..e1b874e3113 100644 --- a/src/test/cluster_unit/test_cluster_tt_durable.c +++ b/src/test/cluster_unit/test_cluster_tt_durable.c @@ -120,8 +120,8 @@ cluster_ges_timeout_src_text(ClusterGesTimeoutSrc src pg_attribute_unused()) } bool -cluster_semantic_activation_modifier_recheck( - const ClusterSemanticAdmissionToken *token, bool writable_admission) +cluster_semantic_activation_modifier_recheck(const ClusterSemanticAdmissionToken *token, + bool writable_admission) { return token != NULL && token->entered && writable_admission; } @@ -132,12 +132,12 @@ cluster_semantic_activation_modifier_recheck( * frozen. */ extern bool cluster_tt_slot_durable_read_exact_stable(uint32 segment_id, uint16 slot_offset, - TransactionId xid, uint16 expected_wrap, - TTSlot *slot_out); -extern XLogRecPtr cluster_tt_slot_durable_publish_active( - const ClusterTTSlotCurrentOwner *expected_owner, - const ClusterSemanticAdmissionToken *admission, - uint32 *segment_generation_out, TTSlot *successor_out); + TransactionId xid, uint16 expected_wrap, + TTSlot *slot_out); +extern XLogRecPtr +cluster_tt_slot_durable_publish_active(const ClusterTTSlotCurrentOwner *expected_owner, + const ClusterSemanticAdmissionToken *admission, + uint32 *segment_generation_out, TTSlot *successor_out); /* ============================================================ @@ -258,8 +258,8 @@ pg_re_throw(void) bool cluster_semantic_activation_resolve_shared_undo_root_live_owner_source( - const ClusterSemanticAdmissionToken *token, ClusterUndoPathIntent intent, - uint32 owner_instance, uint32 segment_id, ClusterUndoBlock0ResolvedRoot *out) + const ClusterSemanticAdmissionToken *token, ClusterUndoPathIntent intent, uint32 owner_instance, + uint32 segment_id, ClusterUndoBlock0ResolvedRoot *out) { g_current_root_calls++; if (!g_current_root_ok || token == NULL || !token->entered @@ -274,9 +274,10 @@ cluster_semantic_activation_resolve_shared_undo_root_live_owner_source( } bool -cluster_semantic_activation_resolve_shared_undo_root( - const ClusterSemanticAdmissionToken *token, ClusterUndoPathIntent intent, - uint32 owner_instance, uint32 segment_id, ClusterUndoBlock0ResolvedRoot *out) +cluster_semantic_activation_resolve_shared_undo_root(const ClusterSemanticAdmissionToken *token, + ClusterUndoPathIntent intent, + uint32 owner_instance, uint32 segment_id, + ClusterUndoBlock0ResolvedRoot *out) { g_current_root_calls++; g_current_target_root_calls++; @@ -295,17 +296,15 @@ bool cluster_undo_block0_root_matches(const ClusterUndoBlock0ResolvedRoot *observed, const ClusterUndoBlock0ResolvedRoot *expected) { - return observed != NULL && expected != NULL - && observed->intent == expected->intent - && observed->root_id == expected->root_id - && observed->root_generation == expected->root_generation; + return observed != NULL && expected != NULL && observed->intent == expected->intent + && observed->root_id == expected->root_id + && observed->root_generation == expected->root_generation; } ClusterUndoBlock0CurrentStep cluster_undo_block0_current_acquire_begin_live_owner_source( const ClusterUndoBlock0LogicalKey *key, int timeout_ms pg_attribute_unused(), - const ClusterSemanticAdmissionToken *admission, - ClusterUndoBlock0CurrentGuard *guard, + const ClusterSemanticAdmissionToken *admission, ClusterUndoBlock0CurrentGuard *guard, ClusterUndoBlock0Result *failure) { g_current_acquire_calls++; @@ -317,8 +316,8 @@ cluster_undo_block0_current_acquire_begin_live_owner_source( || guard->opaque[0] != 0) { if (failure != NULL) *failure = guard != NULL && guard->opaque[0] != 0 - ? CLUSTER_UNDO_BLOCK0_IDENTITY_MISMATCH - : CLUSTER_UNDO_BLOCK0_AUTHORITY_DENIED; + ? CLUSTER_UNDO_BLOCK0_IDENTITY_MISMATCH + : CLUSTER_UNDO_BLOCK0_AUTHORITY_DENIED; return CLUSTER_UNDO_BLOCK0_CURRENT_FAILED; } guard->opaque[0] = 1; @@ -329,8 +328,7 @@ cluster_undo_block0_current_acquire_begin_live_owner_source( ClusterUndoBlock0CurrentStep cluster_undo_block0_current_acquire_begin_live_owner_target( const ClusterUndoBlock0LogicalKey *key, int timeout_ms pg_attribute_unused(), - const ClusterSemanticAdmissionToken *admission, - ClusterUndoBlock0CurrentGuard *guard, + const ClusterSemanticAdmissionToken *admission, ClusterUndoBlock0CurrentGuard *guard, ClusterUndoBlock0Result *failure) { g_current_acquire_calls++; @@ -343,8 +341,8 @@ cluster_undo_block0_current_acquire_begin_live_owner_target( || guard->opaque[0] != 0) { if (failure != NULL) *failure = guard != NULL && guard->opaque[0] != 0 - ? CLUSTER_UNDO_BLOCK0_IDENTITY_MISMATCH - : CLUSTER_UNDO_BLOCK0_AUTHORITY_DENIED; + ? CLUSTER_UNDO_BLOCK0_IDENTITY_MISMATCH + : CLUSTER_UNDO_BLOCK0_AUTHORITY_DENIED; return CLUSTER_UNDO_BLOCK0_CURRENT_FAILED; } guard->opaque[0] = 1; @@ -353,12 +351,10 @@ cluster_undo_block0_current_acquire_begin_live_owner_target( } ClusterUndoBlock0CurrentStep -cluster_undo_block0_current_acquire_poll( - ClusterUndoBlock0CurrentGuard *guard pg_attribute_unused(), - ClusterUndoBlock0Result *failure pg_attribute_unused()) +cluster_undo_block0_current_acquire_poll(ClusterUndoBlock0CurrentGuard *guard pg_attribute_unused(), + ClusterUndoBlock0Result *failure pg_attribute_unused()) { - return g_current_active ? CLUSTER_UNDO_BLOCK0_CURRENT_HELD - : CLUSTER_UNDO_BLOCK0_CURRENT_FAILED; + return g_current_active ? CLUSTER_UNDO_BLOCK0_CURRENT_HELD : CLUSTER_UNDO_BLOCK0_CURRENT_FAILED; } bool @@ -373,8 +369,7 @@ cluster_undo_block0_current_wait_reply(ClusterUndoBlock0CurrentGuard *guard pg_a ClusterUndoBlock0Result cluster_undo_block0_current_sample_generation_exclusive( ClusterUndoBlock0CurrentGuard *guard pg_attribute_unused(), - const ClusterUndoBlock0ResolvedRoot *root, - ClusterUndoBlock0Generation *observed) + const ClusterUndoBlock0ResolvedRoot *root, ClusterUndoBlock0Generation *observed) { g_current_sample_calls++; if (!g_current_active || !g_current_sample_ok @@ -387,15 +382,13 @@ cluster_undo_block0_current_sample_generation_exclusive( ClusterUndoBlock0Result cluster_undo_block0_current_pin_exclusive( ClusterUndoBlock0CurrentGuard *guard pg_attribute_unused(), - const ClusterUndoBlock0ResolvedRoot *root, - const ClusterUndoBlock0Generation *expected, ClusterUndoBlock0Pin *pin, - char **page) + const ClusterUndoBlock0ResolvedRoot *root, const ClusterUndoBlock0Generation *expected, + ClusterUndoBlock0Pin *pin, char **page) { g_current_pin_calls++; if (!g_current_active || !g_current_pin_ok - || !cluster_undo_block0_root_matches(root, &g_current_root) - || expected == NULL || !expected->known - || expected->value != g_current_generation.value) + || !cluster_undo_block0_root_matches(root, &g_current_root) || expected == NULL + || !expected->known || expected->value != g_current_generation.value) return CLUSTER_UNDO_BLOCK0_AUTHORITY_DENIED; memset(pin, 0, sizeof(*pin)); pin->slot = 7; @@ -410,9 +403,8 @@ cluster_undo_block0_current_recheck_exclusive( ClusterUndoBlock0CurrentGuard *guard pg_attribute_unused()) { g_current_recheck_calls++; - return g_current_active && g_current_recheck_ok - ? CLUSTER_UNDO_BLOCK0_OK - : CLUSTER_UNDO_BLOCK0_AUTHORITY_DENIED; + return g_current_active && g_current_recheck_ok ? CLUSTER_UNDO_BLOCK0_OK + : CLUSTER_UNDO_BLOCK0_AUTHORITY_DENIED; } ClusterUndoBlock0Result @@ -435,9 +427,9 @@ cluster_undo_block0_unpin(ClusterUndoBlock0Pin *pin) } ClusterUndoBlock0CurrentStep -cluster_undo_block0_current_release_begin( - ClusterUndoBlock0CurrentGuard *guard pg_attribute_unused(), - ClusterUndoBlock0Result *failure pg_attribute_unused()) +cluster_undo_block0_current_release_begin(ClusterUndoBlock0CurrentGuard *guard + pg_attribute_unused(), + ClusterUndoBlock0Result *failure pg_attribute_unused()) { g_current_release_calls++; if (!g_current_release_ok) @@ -447,9 +439,8 @@ cluster_undo_block0_current_release_begin( } ClusterUndoBlock0CurrentStep -cluster_undo_block0_current_release_poll( - ClusterUndoBlock0CurrentGuard *guard pg_attribute_unused(), - ClusterUndoBlock0Result *failure pg_attribute_unused()) +cluster_undo_block0_current_release_poll(ClusterUndoBlock0CurrentGuard *guard pg_attribute_unused(), + ClusterUndoBlock0Result *failure pg_attribute_unused()) { return CLUSTER_UNDO_BLOCK0_CURRENT_RELEASED; } @@ -491,8 +482,7 @@ static int g_ctrc_bind_order = 0; static int g_ctrc_write_order = 0; static int g_ctrc_open_calls = 0; static int g_ctrc_open_order = 0; -static ClusterCtrcOriginReserveResult g_ctrc_reserve_result - = CLUSTER_CTRC_ORIGIN_RESERVED_PENDING; +static ClusterCtrcOriginReserveResult g_ctrc_reserve_result = CLUSTER_CTRC_ORIGIN_RESERVED_PENDING; static int g_ctrc_reserve_retry_countdown = 0; static int g_ctrc_release_overlap_pending_countdown = 0; static int g_ctrc_release_overlap_pending_polls = 0; @@ -514,33 +504,29 @@ cluster_ctrc_origin_reserve_active(const ClusterCtrcTxnKeyV1 *key, if (key == NULL || reservation == NULL) return CLUSTER_CTRC_ORIGIN_RESERVE_REFUSED; memset(reservation, 0, sizeof(*reservation)); - if (g_ctrc_reserve_retry_countdown > 0) - { + if (g_ctrc_reserve_retry_countdown > 0) { g_ctrc_reserve_retry_countdown--; return CLUSTER_CTRC_ORIGIN_RESERVE_RETRY_RELEASED; } reservation->key = *key; reservation->origin_index = 7; reservation->reservation_generation = 41; - reservation->kind = g_ctrc_reserve_result - == CLUSTER_CTRC_ORIGIN_RESERVED_PENDING - ? CTRC_ORIGIN_RESERVATION_PENDING_OWNED - : CTRC_ORIGIN_RESERVATION_EXISTING_OPEN; + reservation->kind = g_ctrc_reserve_result == CLUSTER_CTRC_ORIGIN_RESERVED_PENDING + ? CTRC_ORIGIN_RESERVATION_PENDING_OWNED + : CTRC_ORIGIN_RESERVATION_EXISTING_OPEN; reservation->valid = true; return g_ctrc_reserve_result; } bool -cluster_ctrc_origin_release_overlap_pending( - const ClusterCtrcTxnKeyV1 *key) +cluster_ctrc_origin_release_overlap_pending(const ClusterCtrcTxnKeyV1 *key) { g_ctrc_release_overlap_pending_polls++; if (g_ctrc_overlap_hook != NULL) g_ctrc_overlap_hook(); if (key == NULL) return false; - if (g_ctrc_release_overlap_pending_countdown > 0) - { + if (g_ctrc_release_overlap_pending_countdown > 0) { g_ctrc_release_overlap_pending_countdown--; return true; } @@ -554,9 +540,8 @@ cluster_undo_cleaner_wakeup(void) } bool -cluster_ctrc_origin_open_reserved( - const ClusterCtrcOriginReservation *reservation, - uint32 *grant_generation) +cluster_ctrc_origin_open_reserved(const ClusterCtrcOriginReservation *reservation, + uint32 *grant_generation) { g_ctrc_open_calls++; g_ctrc_open_order = ++g_ctrc_event_sequence; @@ -567,31 +552,25 @@ cluster_ctrc_origin_open_reserved( } bool -cluster_ctrc_origin_cancel_pre_bind( - const ClusterCtrcOriginReservation *reservation) +cluster_ctrc_origin_cancel_pre_bind(const ClusterCtrcOriginReservation *reservation) { g_ctrc_cancel_pre_bind_calls++; - return reservation != NULL - && reservation->kind == CTRC_ORIGIN_RESERVATION_PENDING_OWNED; + return reservation != NULL && reservation->kind == CTRC_ORIGIN_RESERVATION_PENDING_OWNED; } bool -cluster_ctrc_origin_block_post_bind( - const ClusterCtrcOriginReservation *reservation) +cluster_ctrc_origin_block_post_bind(const ClusterCtrcOriginReservation *reservation) { g_ctrc_block_post_bind_calls++; - return reservation != NULL - && reservation->kind == CTRC_ORIGIN_RESERVATION_PENDING_OWNED; + return reservation != NULL && reservation->kind == CTRC_ORIGIN_RESERVATION_PENDING_OWNED; } #ifndef TT_DURABLE_REAL_ALLOCATOR_FIXTURE bool -cluster_tt_slot_current_owner_by_xid(int node_id, TransactionId xid, - ClusterTTSlotCurrentOwner *out) +cluster_tt_slot_current_owner_by_xid(int node_id, TransactionId xid, ClusterTTSlotCurrentOwner *out) { g_allocator_owner_calls++; - if (g_allocator_rollover_after_first_owner - && g_allocator_owner_calls > 1) { + if (g_allocator_rollover_after_first_owner && g_allocator_owner_calls > 1) { if (out != NULL) memset(out, 0, sizeof(*out)); return false; @@ -611,24 +590,21 @@ cluster_tt_slot_current_segment(int node_id) { if (node_id != cluster_node_id) return 0; - if (g_allocator_rollover_after_first_owner - && g_allocator_owner_calls >= 1) + if (g_allocator_rollover_after_first_owner && g_allocator_owner_calls >= 1) return 2; return g_allocator_current_segment; } #endif XLogRecPtr -cluster_undo_emit_tt_slot_bind(uint8 instance, uint32 segment_id, - uint32 segment_generation, uint16 slot_offset, - uint16 wrap, TransactionId xid) +cluster_undo_emit_tt_slot_bind(uint8 instance, uint32 segment_id, uint32 segment_generation, + uint16 slot_offset, uint16 wrap, TransactionId xid) { g_bind_emit_calls++; g_ctrc_bind_order = ++g_ctrc_event_sequence; if (g_bind_emit_error) ereport(ERROR, - (errcode(ERRCODE_DATA_CORRUPTED), - errmsg("injected pre-return BIND failure"))); + (errcode(ERRCODE_DATA_CORRUPTED), errmsg("injected pre-return BIND failure"))); memset(&g_last_bind, 0, sizeof(g_last_bind)); g_last_bind.instance = instance; g_last_bind.segment_id = segment_id; @@ -655,11 +631,11 @@ cluster_undo_emit_tt_slot_abort(uint8 instance pg_attribute_unused(), XLogRecPtr cluster_undo_emit_tt_slot_abort_exact(uint8 instance pg_attribute_unused(), - uint32 segment_id pg_attribute_unused(), - uint32 segment_generation pg_attribute_unused(), - uint16 slot_offset pg_attribute_unused(), - uint16 wrap pg_attribute_unused(), - TransactionId xid pg_attribute_unused()) + uint32 segment_id pg_attribute_unused(), + uint32 segment_generation pg_attribute_unused(), + uint16 slot_offset pg_attribute_unused(), + uint16 wrap pg_attribute_unused(), + TransactionId xid pg_attribute_unused()) { g_abort_exact_emit_calls++; return g_abort_exact_lsn; @@ -740,8 +716,8 @@ cluster_undo_smgr_read_header_bytes(ClusterUndoPathIntent intent pg_attribute_un char *buf, uint32 len) { g_read_hdr_calls++; - if (!g_read_hdr_ok || (g_read_hdr_fail_on_call > 0 - && g_read_hdr_calls == g_read_hdr_fail_on_call) + if (!g_read_hdr_ok + || (g_read_hdr_fail_on_call > 0 && g_read_hdr_calls == g_read_hdr_fail_on_call) || buf == NULL || len != sizeof(TTSlot)) return false; (void)offset; @@ -775,7 +751,7 @@ cluster_undo_smgr_write_header_bytes(ClusterUndoPathIntent intent pg_attribute_u bool cluster_undo_smgr_fsync_segment_file(uint32 segment_id pg_attribute_unused(), - uint8 owner_instance pg_attribute_unused()) + uint8 owner_instance pg_attribute_unused()) { g_fsync_segment_calls++; return true; @@ -792,8 +768,7 @@ cluster_undo_smgr_read_block(ClusterUndoPathIntent intent pg_attribute_unused(), g_read_block_absent_once_segment = 0; return false; } - if (!g_read_block_ok || buf == NULL || block_no != 0 - || segment_id != g_canned_block_segment) + if (!g_read_block_ok || buf == NULL || block_no != 0 || segment_id != g_canned_block_segment) return false; /* other segments "don't exist" -> by-xid skips them */ memcpy(buf, g_canned_block, BLCKSZ); return true; @@ -875,7 +850,7 @@ reset_current_write_mock(void) .root_id = 71, .root_generation = 9, }; - g_current_generation = (ClusterUndoBlock0Generation){true, 4}; + g_current_generation = (ClusterUndoBlock0Generation){ true, 4 }; memset(g_current_resident, 0, sizeof(g_current_resident)); memset(g_canned_block, 0, sizeof(g_canned_block)); g_read_block_ok = true; @@ -1186,8 +1161,8 @@ UT_TEST(test_lookup_committed_stable_uncommitted_failclosed) * ============================================================ */ UT_TEST(test_read_exact_stable_accepts_known_status_and_preserves_32_bytes) { - static const uint8 known_statuses[] = {TT_SLOT_UNUSED, TT_SLOT_ACTIVE, TT_SLOT_COMMITTED, - TT_SLOT_ABORTED, TT_SLOT_RECYCLABLE}; + static const uint8 known_statuses[] = { TT_SLOT_UNUSED, TT_SLOT_ACTIVE, TT_SLOT_COMMITTED, + TT_SLOT_ABORTED, TT_SLOT_RECYCLABLE }; TTSlot got; int i; @@ -1207,7 +1182,7 @@ UT_TEST(test_read_exact_stable_accepts_known_status_and_preserves_32_bytes) UT_TEST(test_read_exact_stable_rejects_wrong_xid) { TTSlot got; - TTSlot zero = {0}; + TTSlot zero = { 0 }; reset_header_read_mock(); g_canned_slot.status = TT_SLOT_COMMITTED; @@ -1221,7 +1196,7 @@ UT_TEST(test_read_exact_stable_rejects_wrong_xid) UT_TEST(test_read_exact_stable_rejects_wrong_wrap) { TTSlot got; - TTSlot zero = {0}; + TTSlot zero = { 0 }; reset_header_read_mock(); g_canned_slot.status = TT_SLOT_COMMITTED; @@ -1235,7 +1210,7 @@ UT_TEST(test_read_exact_stable_rejects_wrong_wrap) UT_TEST(test_read_exact_stable_rejects_unknown_status) { TTSlot got; - TTSlot zero = {0}; + TTSlot zero = { 0 }; reset_header_read_mock(); g_canned_slot.status = 99; @@ -1249,7 +1224,7 @@ UT_TEST(test_read_exact_stable_rejects_unknown_status) UT_TEST(test_read_exact_stable_rejects_torn_slot) { TTSlot got; - TTSlot zero = {0}; + TTSlot zero = { 0 }; reset_header_read_mock(); g_canned_slot.status = TT_SLOT_ABORTED; @@ -1267,7 +1242,7 @@ UT_TEST(test_read_exact_stable_rejects_torn_slot) UT_TEST(test_read_exact_stable_rejects_either_io_failure) { TTSlot got; - TTSlot zero = {0}; + TTSlot zero = { 0 }; reset_header_read_mock(); g_canned_slot.status = TT_SLOT_ABORTED; @@ -1295,48 +1270,48 @@ UT_TEST(test_active_bind_predecessor_table_is_exact) TTSlot slot; memset(&slot, 0, sizeof(slot)); - UT_ASSERT_EQ(cluster_tt_active_transition_decide( - &slot, 7, 7, 100, 5, true), CLUSTER_TT_ACTIVE_APPLY); - UT_ASSERT_EQ(cluster_tt_active_transition_decide( - &slot, 7, 7, 100, 5, false), CLUSTER_TT_ACTIVE_CONFLICT); + UT_ASSERT_EQ(cluster_tt_active_transition_decide(&slot, 7, 7, 100, 5, true), + CLUSTER_TT_ACTIVE_APPLY); + UT_ASSERT_EQ(cluster_tt_active_transition_decide(&slot, 7, 7, 100, 5, false), + CLUSTER_TT_ACTIVE_CONFLICT); slot.xid = 100; slot.wrap = 5; slot.status = TT_SLOT_ACTIVE; - UT_ASSERT_EQ(cluster_tt_active_transition_decide( - &slot, 7, 7, 100, 5, true), CLUSTER_TT_ACTIVE_IDEMPOTENT); + UT_ASSERT_EQ(cluster_tt_active_transition_decide(&slot, 7, 7, 100, 5, true), + CLUSTER_TT_ACTIVE_IDEMPOTENT); slot.status = TT_SLOT_COMMITTED; slot.commit_scn = scn_encode(1, 42); - UT_ASSERT_EQ(cluster_tt_active_transition_decide( - &slot, 7, 7, 200, 6, true), CLUSTER_TT_ACTIVE_APPLY); + UT_ASSERT_EQ(cluster_tt_active_transition_decide(&slot, 7, 7, 200, 6, true), + CLUSTER_TT_ACTIVE_APPLY); slot.flags = TT_SLOT_FLAG_CTRC_RELEASE_PROVEN; - UT_ASSERT_EQ(cluster_tt_active_transition_decide( - &slot, 7, 7, 200, 6, true), CLUSTER_TT_ACTIVE_APPLY); + UT_ASSERT_EQ(cluster_tt_active_transition_decide(&slot, 7, 7, 200, 6, true), + CLUSTER_TT_ACTIVE_APPLY); slot.flags = UINT8_C(0x80); - UT_ASSERT_EQ(cluster_tt_active_transition_decide( - &slot, 7, 7, 200, 6, true), CLUSTER_TT_ACTIVE_CORRUPT); + UT_ASSERT_EQ(cluster_tt_active_transition_decide(&slot, 7, 7, 200, 6, true), + CLUSTER_TT_ACTIVE_CORRUPT); slot.flags = TT_FLAGS_RESERVED; - UT_ASSERT_EQ(cluster_tt_active_transition_decide( - &slot, 7, 7, 200, 5, true), CLUSTER_TT_ACTIVE_CONFLICT); + UT_ASSERT_EQ(cluster_tt_active_transition_decide(&slot, 7, 7, 200, 5, true), + CLUSTER_TT_ACTIVE_CONFLICT); slot.status = TT_SLOT_ACTIVE; slot.xid = 200; slot.wrap = 6; slot.commit_scn = InvalidScn; - UT_ASSERT_EQ(cluster_tt_active_transition_decide( - &slot, 7, 7, 100, 5, true), CLUSTER_TT_ACTIVE_STALE); - UT_ASSERT_EQ(cluster_tt_active_transition_decide( - &slot, 7, 7, 300, 6, true), CLUSTER_TT_ACTIVE_CONFLICT); + UT_ASSERT_EQ(cluster_tt_active_transition_decide(&slot, 7, 7, 100, 5, true), + CLUSTER_TT_ACTIVE_STALE); + UT_ASSERT_EQ(cluster_tt_active_transition_decide(&slot, 7, 7, 300, 6, true), + CLUSTER_TT_ACTIVE_CONFLICT); - UT_ASSERT_EQ(cluster_tt_active_transition_decide( - &slot, 8, 7, 200, 6, true), CLUSTER_TT_ACTIVE_STALE); - UT_ASSERT_EQ(cluster_tt_active_transition_decide( - &slot, 6, 7, 200, 6, true), CLUSTER_TT_ACTIVE_CORRUPT); + UT_ASSERT_EQ(cluster_tt_active_transition_decide(&slot, 8, 7, 200, 6, true), + CLUSTER_TT_ACTIVE_STALE); + UT_ASSERT_EQ(cluster_tt_active_transition_decide(&slot, 6, 7, 200, 6, true), + CLUSTER_TT_ACTIVE_CORRUPT); slot.status = TT_SLOT_INVALID; - UT_ASSERT_EQ(cluster_tt_active_transition_decide( - &slot, 7, 7, 200, 6, true), CLUSTER_TT_ACTIVE_CORRUPT); + UT_ASSERT_EQ(cluster_tt_active_transition_decide(&slot, 7, 7, 200, 6, true), + CLUSTER_TT_ACTIVE_CORRUPT); } UT_TEST(test_terminal_transition_requires_same_exact_active_entity) @@ -1348,57 +1323,57 @@ UT_TEST(test_terminal_transition_requires_same_exact_active_entity) slot.xid = 100; slot.wrap = 5; slot.status = TT_SLOT_ACTIVE; - UT_ASSERT_EQ(cluster_tt_terminal_transition_decide( - &slot, 7, 7, 100, 5, TT_SLOT_COMMITTED, commit_scn), + UT_ASSERT_EQ( + cluster_tt_terminal_transition_decide(&slot, 7, 7, 100, 5, TT_SLOT_COMMITTED, commit_scn), CLUSTER_TT_TERMINAL_APPLY); - UT_ASSERT_EQ(cluster_tt_terminal_transition_decide( - &slot, 7, 7, 100, 5, TT_SLOT_ABORTED, InvalidScn), + UT_ASSERT_EQ( + cluster_tt_terminal_transition_decide(&slot, 7, 7, 100, 5, TT_SLOT_ABORTED, InvalidScn), CLUSTER_TT_TERMINAL_APPLY); slot.status = TT_SLOT_COMMITTED; slot.commit_scn = commit_scn; - UT_ASSERT_EQ(cluster_tt_terminal_transition_decide( - &slot, 7, 7, 100, 5, TT_SLOT_COMMITTED, commit_scn), + UT_ASSERT_EQ( + cluster_tt_terminal_transition_decide(&slot, 7, 7, 100, 5, TT_SLOT_COMMITTED, commit_scn), CLUSTER_TT_TERMINAL_IDEMPOTENT); slot.flags = TT_SLOT_FLAG_CTRC_RELEASE_PROVEN; - UT_ASSERT_EQ(cluster_tt_terminal_transition_decide( - &slot, 7, 7, 100, 5, TT_SLOT_COMMITTED, commit_scn), + UT_ASSERT_EQ( + cluster_tt_terminal_transition_decide(&slot, 7, 7, 100, 5, TT_SLOT_COMMITTED, commit_scn), CLUSTER_TT_TERMINAL_APPLY); slot.flags = UINT8_C(0x80); - UT_ASSERT_EQ(cluster_tt_terminal_transition_decide( - &slot, 7, 7, 100, 5, TT_SLOT_COMMITTED, commit_scn), + UT_ASSERT_EQ( + cluster_tt_terminal_transition_decide(&slot, 7, 7, 100, 5, TT_SLOT_COMMITTED, commit_scn), CLUSTER_TT_TERMINAL_CORRUPT); slot.flags = TT_FLAGS_RESERVED; - UT_ASSERT_EQ(cluster_tt_terminal_transition_decide( - &slot, 7, 7, 100, 5, TT_SLOT_ABORTED, InvalidScn), + UT_ASSERT_EQ( + cluster_tt_terminal_transition_decide(&slot, 7, 7, 100, 5, TT_SLOT_ABORTED, InvalidScn), CLUSTER_TT_TERMINAL_CONFLICT); slot.xid = 101; - UT_ASSERT_EQ(cluster_tt_terminal_transition_decide( - &slot, 7, 7, 100, 5, TT_SLOT_COMMITTED, commit_scn), + UT_ASSERT_EQ( + cluster_tt_terminal_transition_decide(&slot, 7, 7, 100, 5, TT_SLOT_COMMITTED, commit_scn), CLUSTER_TT_TERMINAL_CONFLICT); slot.xid = 100; slot.wrap = 6; - UT_ASSERT_EQ(cluster_tt_terminal_transition_decide( - &slot, 7, 7, 100, 5, TT_SLOT_COMMITTED, commit_scn), + UT_ASSERT_EQ( + cluster_tt_terminal_transition_decide(&slot, 7, 7, 100, 5, TT_SLOT_COMMITTED, commit_scn), CLUSTER_TT_TERMINAL_STALE); - UT_ASSERT_EQ(cluster_tt_terminal_transition_decide( - &slot, 8, 7, 100, 6, TT_SLOT_COMMITTED, commit_scn), + UT_ASSERT_EQ( + cluster_tt_terminal_transition_decide(&slot, 8, 7, 100, 6, TT_SLOT_COMMITTED, commit_scn), CLUSTER_TT_TERMINAL_STALE); - UT_ASSERT_EQ(cluster_tt_terminal_transition_decide( - &slot, 6, 7, 100, 6, TT_SLOT_COMMITTED, commit_scn), + UT_ASSERT_EQ( + cluster_tt_terminal_transition_decide(&slot, 6, 7, 100, 6, TT_SLOT_COMMITTED, commit_scn), CLUSTER_TT_TERMINAL_CORRUPT); memset(&slot, 0, sizeof(slot)); - UT_ASSERT_EQ(cluster_tt_terminal_transition_decide( - &slot, 7, 7, 100, 5, TT_SLOT_ABORTED, InvalidScn), + UT_ASSERT_EQ( + cluster_tt_terminal_transition_decide(&slot, 7, 7, 100, 5, TT_SLOT_ABORTED, InvalidScn), CLUSTER_TT_TERMINAL_CONFLICT); slot.status = TT_SLOT_ACTIVE; slot.xid = 100; slot.wrap = 5; slot.flags = 1; - UT_ASSERT_EQ(cluster_tt_terminal_transition_decide( - &slot, 7, 7, 100, 5, TT_SLOT_ABORTED, InvalidScn), + UT_ASSERT_EQ( + cluster_tt_terminal_transition_decide(&slot, 7, 7, 100, 5, TT_SLOT_ABORTED, InvalidScn), CLUSTER_TT_TERMINAL_CORRUPT); } @@ -1418,8 +1393,8 @@ UT_TEST(test_active_publish_wal_precedes_identical_disk_and_resident_successor) disk->wrap_count = 4; memcpy(resident, disk, BLCKSZ); - lsn = cluster_tt_slot_durable_publish_active( - &g_allocator_owner, &admission, &generation, &successor); + lsn = cluster_tt_slot_durable_publish_active(&g_allocator_owner, &admission, &generation, + &successor); UT_ASSERT_EQ(lsn, (XLogRecPtr)0xabcdef); UT_ASSERT_EQ(generation, 4); @@ -1464,8 +1439,8 @@ UT_TEST(test_active_publish_waits_for_released_origin_notification_before_bind) g_ctrc_reserve_retry_countdown = 1; g_ctrc_release_overlap_pending_countdown = 5; - lsn = cluster_tt_slot_durable_publish_active( - &g_allocator_owner, &admission, &generation, &successor); + lsn = cluster_tt_slot_durable_publish_active(&g_allocator_owner, &admission, &generation, + &successor); UT_ASSERT_EQ(lsn, (XLogRecPtr)0xabcdef); UT_ASSERT_EQ(g_ctrc_reserve_calls, 2); @@ -1501,8 +1476,8 @@ UT_TEST(test_active_publish_final_xcur_drift_stays_unpublished) PG_TRY(); { - (void)cluster_tt_slot_durable_publish_active( - &g_allocator_owner, &admission, &generation, &successor); + (void)cluster_tt_slot_durable_publish_active(&g_allocator_owner, &admission, &generation, + &successor); } PG_CATCH(); { @@ -1539,8 +1514,8 @@ UT_TEST(test_active_publish_prebind_failures_cancel_only_owned_pending_reservati memcpy(resident, disk, BLCKSZ); PG_TRY(); { - (void)cluster_tt_slot_durable_publish_active( - &g_allocator_owner, &admission, &generation, &successor); + (void)cluster_tt_slot_durable_publish_active(&g_allocator_owner, &admission, &generation, + &successor); } PG_CATCH(); { @@ -1562,8 +1537,8 @@ UT_TEST(test_active_publish_prebind_failures_cancel_only_owned_pending_reservati caught = false; PG_TRY(); { - (void)cluster_tt_slot_durable_publish_active( - &g_allocator_owner, &admission, &generation, &successor); + (void)cluster_tt_slot_durable_publish_active(&g_allocator_owner, &admission, &generation, + &successor); } PG_CATCH(); { @@ -1585,8 +1560,8 @@ UT_TEST(test_active_publish_prebind_failures_cancel_only_owned_pending_reservati caught = false; PG_TRY(); { - (void)cluster_tt_slot_durable_publish_active( - &g_allocator_owner, &admission, &generation, &successor); + (void)cluster_tt_slot_durable_publish_active(&g_allocator_owner, &admission, &generation, + &successor); } PG_CATCH(); { @@ -1616,8 +1591,8 @@ UT_TEST(test_active_publish_postbind_failures_block_owned_pending_reservation) g_write_hdr_ok = false; PG_TRY(); { - (void)cluster_tt_slot_durable_publish_active( - &g_allocator_owner, &admission, &generation, &successor); + (void)cluster_tt_slot_durable_publish_active(&g_allocator_owner, &admission, &generation, + &successor); } PG_CATCH(); { @@ -1638,8 +1613,8 @@ UT_TEST(test_active_publish_postbind_failures_block_owned_pending_reservation) caught = false; PG_TRY(); { - (void)cluster_tt_slot_durable_publish_active( - &g_allocator_owner, &admission, &generation, &successor); + (void)cluster_tt_slot_durable_publish_active(&g_allocator_owner, &admission, &generation, + &successor); } PG_CATCH(); { @@ -1670,8 +1645,8 @@ UT_TEST(test_active_publish_existing_open_error_never_cancels_or_blocks_entry) g_write_hdr_ok = false; PG_TRY(); { - (void)cluster_tt_slot_durable_publish_active( - &g_allocator_owner, &admission, &generation, &successor); + (void)cluster_tt_slot_durable_publish_active(&g_allocator_owner, &admission, &generation, + &successor); } PG_CATCH(); { @@ -1703,8 +1678,8 @@ UT_TEST(test_active_publish_requires_exact_root_and_resident_disk_generation) PG_TRY(); { - (void)cluster_tt_slot_durable_publish_active( - &g_allocator_owner, &admission, &generation, &successor); + (void)cluster_tt_slot_durable_publish_active(&g_allocator_owner, &admission, &generation, + &successor); } PG_CATCH(); { @@ -1737,8 +1712,8 @@ UT_TEST(test_active_publish_rejects_allocator_identity_drift_before_wal) PG_TRY(); { - (void)cluster_tt_slot_durable_publish_active( - &g_allocator_owner, &admission, &generation, &successor); + (void)cluster_tt_slot_durable_publish_active(&g_allocator_owner, &admission, &generation, + &successor); } PG_CATCH(); { @@ -1850,8 +1825,8 @@ UT_TEST(test_active_publish_retries_rollover_before_xcur_allocator_linearization PG_TRY(); { - lsn = cluster_tt_slot_durable_publish_active( - &g_allocator_owner, &admission, &generation, &successor); + lsn = cluster_tt_slot_durable_publish_active(&g_allocator_owner, &admission, &generation, + &successor); } PG_CATCH(); { @@ -1896,8 +1871,8 @@ UT_TEST(test_active_publish_rejects_same_wrap_different_xid_before_wal) PG_TRY(); { - (void)cluster_tt_slot_durable_publish_active( - &g_allocator_owner, &admission, &generation, &successor); + (void)cluster_tt_slot_durable_publish_active(&g_allocator_owner, &admission, &generation, + &successor); } PG_CATCH(); { @@ -1924,17 +1899,16 @@ UT_TEST(test_precommit_writeonly_publishes_identical_durable_and_resident_succes seed_current_exact_active(7, 100, 5); memset(&successor, 0xa5, sizeof(successor)); - owner = cluster_tt_slot_durable_commit_writeonly( - 1, 4, 7, 100, 5, scn_encode(1, 42), &admission, &successor); + owner = cluster_tt_slot_durable_commit_writeonly(1, 4, 7, 100, 5, scn_encode(1, 42), &admission, + &successor); UT_ASSERT_EQ(owner, 1); UT_ASSERT(admission.entered); UT_ASSERT_EQ(g_write_hdr_calls, 1); UT_ASSERT_EQ(memcmp(&successor, &g_last_written_slot, sizeof(successor)), 0); UT_ASSERT_EQ(memcmp(&resident->tt_slots[7], &successor, sizeof(successor)), 0); - UT_ASSERT(cluster_tt_durable_slot_match( - successor.status, successor.xid, successor.wrap, successor.commit_scn, - 100, 5)); + UT_ASSERT(cluster_tt_durable_slot_match(successor.status, successor.xid, successor.wrap, + successor.commit_scn, 100, 5)); UT_ASSERT_EQ(g_current_root_calls, 3); UT_ASSERT_EQ(g_current_acquire_calls, 1); UT_ASSERT_EQ(g_current_sample_calls, 1); @@ -1958,8 +1932,8 @@ UT_TEST(test_precommit_writeonly_target_open_reuses_same_block0_authority) PG_TRY(); { - owner = cluster_tt_slot_durable_commit_writeonly( - 1, 4, 7, 100, 5, scn_encode(1, 42), &admission, &successor); + owner = cluster_tt_slot_durable_commit_writeonly(1, 4, 7, 100, 5, scn_encode(1, 42), + &admission, &successor); } PG_CATCH(); { @@ -1994,8 +1968,8 @@ UT_TEST(test_precommit_writeonly_accepts_exact_active_on_rolled_away_segment) PG_TRY(); { - owner = cluster_tt_slot_durable_commit_writeonly( - 1, 4, 7, 100, 5, scn_encode(1, 42), &admission, &successor); + owner = cluster_tt_slot_durable_commit_writeonly(1, 4, 7, 100, 5, scn_encode(1, 42), + &admission, &successor); } PG_CATCH(); { @@ -2010,8 +1984,7 @@ UT_TEST(test_precommit_writeonly_accepts_exact_active_on_rolled_away_segment) UT_ASSERT_EQ(successor.status, TT_SLOT_COMMITTED); UT_ASSERT_EQ(successor.xid, 100); UT_ASSERT_EQ(successor.wrap, 5); - UT_ASSERT_EQ(memcmp(&resident->tt_slots[7], &successor, - sizeof(successor)), 0); + UT_ASSERT_EQ(memcmp(&resident->tt_slots[7], &successor, sizeof(successor)), 0); } UT_TEST(test_precommit_writeonly_root_drift_never_writes_or_publishes) @@ -2032,8 +2005,8 @@ UT_TEST(test_precommit_writeonly_root_drift_never_writes_or_publishes) PG_TRY(); { - (void)cluster_tt_slot_durable_commit_writeonly( - 1, 4, 7, 100, 5, scn_encode(1, 42), &admission, &successor); + (void)cluster_tt_slot_durable_commit_writeonly(1, 4, 7, 100, 5, scn_encode(1, 42), + &admission, &successor); } PG_CATCH(); { @@ -2070,8 +2043,8 @@ UT_TEST(test_precommit_writeonly_missing_current_authority_never_writes_or_publi PG_TRY(); { - (void)cluster_tt_slot_durable_commit_writeonly( - 1, 4, 7, 100, 5, scn_encode(1, 42), &admission, &successor); + (void)cluster_tt_slot_durable_commit_writeonly(1, 4, 7, 100, 5, scn_encode(1, 42), + &admission, &successor); } PG_CATCH(); { @@ -2107,8 +2080,8 @@ UT_TEST(test_precommit_writeonly_durable_failure_never_publishes_resident) PG_TRY(); { - (void)cluster_tt_slot_durable_commit_writeonly( - 1, 4, 7, 100, 5, scn_encode(1, 42), &admission, &successor); + (void)cluster_tt_slot_durable_commit_writeonly(1, 4, 7, 100, 5, scn_encode(1, 42), + &admission, &successor); } PG_CATCH(); { @@ -2142,8 +2115,8 @@ UT_TEST(test_precommit_writeonly_postwrite_release_failure_is_nothrow_cleanup) PG_TRY(); { - owner = cluster_tt_slot_durable_commit_writeonly( - 1, 4, 7, 100, 5, scn_encode(1, 42), &admission, &successor); + owner = cluster_tt_slot_durable_commit_writeonly(1, 4, 7, 100, 5, scn_encode(1, 42), + &admission, &successor); } PG_CATCH(); { @@ -2174,8 +2147,7 @@ UT_TEST(test_ordinary_abort_flushes_exact_carrier_before_terminal_write) g_require_abort_flush_before_write = true; memset(&successor, 0xa5, sizeof(successor)); - lsn = cluster_tt_slot_durable_abort_exact( - 1, 4, 7, 100, 5, &admission, &successor); + lsn = cluster_tt_slot_durable_abort_exact(1, 4, 7, 100, 5, &admission, &successor); UT_ASSERT_EQ(lsn, g_abort_exact_lsn); UT_ASSERT_EQ(g_abort_exact_emit_calls, 1); @@ -2186,8 +2158,7 @@ UT_TEST(test_ordinary_abort_flushes_exact_carrier_before_terminal_write) UT_ASSERT_EQ(successor.xid, 100); UT_ASSERT_EQ(successor.wrap, 5); UT_ASSERT(!SCN_VALID(successor.commit_scn)); - UT_ASSERT_EQ(memcmp(&resident->tt_slots[7], &successor, - sizeof(successor)), 0); + UT_ASSERT_EQ(memcmp(&resident->tt_slots[7], &successor, sizeof(successor)), 0); UT_ASSERT_EQ(g_current_acquire_calls, 2); UT_ASSERT_EQ(g_current_cancel_calls, 2); } @@ -2206,8 +2177,7 @@ UT_TEST(test_precommit_writeonly_missing_canonical_active_refuses_without_write) g_canned_slot.xid = 100; g_canned_slot.wrap = 5; memset(g_current_resident, 0x6d, sizeof(g_current_resident)); - memcpy(&resident_before, - &((UndoSegmentHeaderData *)g_current_resident)->tt_slots[7], + memcpy(&resident_before, &((UndoSegmentHeaderData *)g_current_resident)->tt_slots[7], sizeof(resident_before)); memset(&successor, 0xa5, sizeof(successor)); g_allocator_owner.wrap = 5; @@ -2216,8 +2186,8 @@ UT_TEST(test_precommit_writeonly_missing_canonical_active_refuses_without_write) PG_TRY(); { - owner = cluster_tt_slot_durable_commit_writeonly( - 1, 4, 7, 100, 5, scn_encode(1, 42), &admission, &successor); + owner = cluster_tt_slot_durable_commit_writeonly(1, 4, 7, 100, 5, scn_encode(1, 42), + &admission, &successor); } PG_CATCH(); { @@ -2234,9 +2204,9 @@ UT_TEST(test_precommit_writeonly_missing_canonical_active_refuses_without_write) UT_ASSERT_EQ(g_current_sample_calls, 0); UT_ASSERT_EQ(g_current_pin_calls, 0); UT_ASSERT_EQ(g_write_hdr_calls, 0); - UT_ASSERT_EQ(memcmp( - &((UndoSegmentHeaderData *)g_current_resident)->tt_slots[7], - &resident_before, sizeof(resident_before)), 0); + UT_ASSERT_EQ(memcmp(&((UndoSegmentHeaderData *)g_current_resident)->tt_slots[7], + &resident_before, sizeof(resident_before)), + 0); UT_ASSERT_EQ(g_current_cancel_calls, 1); } @@ -2256,8 +2226,8 @@ UT_TEST(test_precommit_writeonly_missing_pgrd_nonempty_refuses_without_write) PG_TRY(); { - (void)cluster_tt_slot_durable_commit_writeonly( - 1, 4, 7, 100, 5, scn_encode(1, 42), &admission, &successor); + (void)cluster_tt_slot_durable_commit_writeonly(1, 4, 7, 100, 5, scn_encode(1, 42), + &admission, &successor); } PG_CATCH(); { @@ -2493,16 +2463,16 @@ UT_TEST(test_locate_any_state_reports_active_exact_identity) uint16 slot = 0xffff; uint16 wrap = 0xffff; uint8 status = TT_SLOT_INVALID; - UndoSegmentHeaderData *header = (UndoSegmentHeaderData *) g_canned_block; + UndoSegmentHeaderData *header = (UndoSegmentHeaderData *)g_canned_block; cluster_node_id = 0; g_unreadable_existing_segment = 0; memset(g_canned_block, 0, sizeof(g_canned_block)); seed_block_slot(6, TT_SLOT_ACTIVE, 12345, InvalidScn); header->tt_slots[6].wrap = 9; - UT_ASSERT_EQ((int) cluster_tt_slot_durable_locate_any_by_xid_origin( - 0, 12345, &seg, &slot, &wrap, &status), - (int) CLUSTER_TT_DURABLE_LOCATE_FOUND); + UT_ASSERT_EQ((int)cluster_tt_slot_durable_locate_any_by_xid_origin(0, 12345, &seg, &slot, &wrap, + &status), + (int)CLUSTER_TT_DURABLE_LOCATE_FOUND); UT_ASSERT_EQ(seg, 1); UT_ASSERT_EQ(slot, 6); UT_ASSERT_EQ(wrap, 9); @@ -2516,24 +2486,24 @@ UT_TEST(test_locate_any_state_distinguishes_missing_and_ambiguous) cluster_node_id = 0; g_unreadable_existing_segment = 0; memset(g_canned_block, 0, sizeof(g_canned_block)); - UT_ASSERT_EQ((int) cluster_tt_slot_durable_locate_any_by_xid_origin( - 0, 12345, &seg, NULL, NULL, NULL), - (int) CLUSTER_TT_DURABLE_LOCATE_MISSING); + UT_ASSERT_EQ( + (int)cluster_tt_slot_durable_locate_any_by_xid_origin(0, 12345, &seg, NULL, NULL, NULL), + (int)CLUSTER_TT_DURABLE_LOCATE_MISSING); UT_ASSERT_EQ(seg, 0xffff); seed_block_slot(3, TT_SLOT_ACTIVE, 12345, InvalidScn); seed_block_slot(9, TT_SLOT_ABORTED, 12345, InvalidScn); - UT_ASSERT_EQ((int) cluster_tt_slot_durable_locate_any_by_xid_origin( - 0, 12345, NULL, NULL, NULL, NULL), - (int) CLUSTER_TT_DURABLE_LOCATE_AMBIGUOUS); + UT_ASSERT_EQ( + (int)cluster_tt_slot_durable_locate_any_by_xid_origin(0, 12345, NULL, NULL, NULL, NULL), + (int)CLUSTER_TT_DURABLE_LOCATE_AMBIGUOUS); } UT_TEST(test_locate_any_state_incomplete_scan_fails_closed) { memset(g_canned_block, 0, sizeof(g_canned_block)); g_unreadable_existing_segment = 2; - UT_ASSERT_EQ((int) cluster_tt_slot_durable_locate_any_by_xid_origin( - 0, 12345, NULL, NULL, NULL, NULL), - (int) CLUSTER_TT_DURABLE_LOCATE_SCAN_UNAVAILABLE); + UT_ASSERT_EQ( + (int)cluster_tt_slot_durable_locate_any_by_xid_origin(0, 12345, NULL, NULL, NULL, NULL), + (int)CLUSTER_TT_DURABLE_LOCATE_SCAN_UNAVAILABLE); g_unreadable_existing_segment = 0; } @@ -2684,7 +2654,7 @@ UT_TEST(test_typed_redo_abort_is_durable_and_idempotent) cluster_tt_durable_redo_abort_slot(1, 1, 7, 5, 778); UT_ASSERT_EQ(g_write_hdr_calls, 1); UT_ASSERT_EQ(g_fsync_segment_calls, 1); - UT_ASSERT_EQ((int) g_last_written_slot.status, (int) TT_SLOT_ABORTED); + UT_ASSERT_EQ((int)g_last_written_slot.status, (int)TT_SLOT_ABORTED); UT_ASSERT_EQ(g_last_written_slot.xid, 778); UT_ASSERT_EQ(g_last_written_slot.wrap, 5); UT_ASSERT(UBA_is_invalid(g_last_written_slot.first_undo_block)); @@ -2707,8 +2677,7 @@ UT_TEST(test_typed_redo_set_head_requires_aborted_identity) cluster_tt_durable_redo_set_head_slot(1, 1, 7, 5, 778, head); UT_ASSERT_EQ(g_write_hdr_calls, 1); UT_ASSERT_EQ(g_fsync_segment_calls, 1); - UT_ASSERT_EQ(memcmp(&g_last_written_slot.first_undo_block, &head, - sizeof(head)), 0); + UT_ASSERT_EQ(memcmp(&g_last_written_slot.first_undo_block, &head, sizeof(head)), 0); g_canned_slot.status = TT_SLOT_COMMITTED; g_write_hdr_calls = 0; diff --git a/src/test/cluster_unit/test_cluster_tt_slot_allocator.c b/src/test/cluster_unit/test_cluster_tt_slot_allocator.c index 3b93ad63a09..f6062080344 100644 --- a/src/test/cluster_unit/test_cluster_tt_slot_allocator.c +++ b/src/test/cluster_unit/test_cluster_tt_slot_allocator.c @@ -87,9 +87,10 @@ UT_DEFINE_GLOBALS(); /* spec-5.22e D5-3 stub: the gc pass consults the F-D2 epoch fence * (cluster_undo_horizon_ic.c not linked here); never tripped in unit. */ bool cluster_undo_horizon_epoch_fence_tripped(uint64 expected_epoch); -bool cluster_ctrc_terminal_release_sample_exact(uint32 segment_id, - uint16 slot_offset, TransactionId xid, uint16 slot_wrap, - uint8 terminal_status, SCN terminal_scn, uint64 expected_epoch); +bool cluster_ctrc_terminal_release_sample_exact(uint32 segment_id, uint16 slot_offset, + TransactionId xid, uint16 slot_wrap, + uint8 terminal_status, SCN terminal_scn, + uint64 expected_epoch); void cluster_undo_cleaner_wakeup(void); bool @@ -167,13 +168,9 @@ LWLockRelease(LWLock *lock pg_attribute_unused()) * away-and-back rebind while the sample is in flight, exercising the final * allocator-candidate ABA recheck. */ bool -cluster_ctrc_terminal_release_sample_exact(uint32 segment_id, - uint16 slot_offset, - TransactionId xid, - uint16 slot_wrap, - uint8 terminal_status, - SCN terminal_scn, - uint64 expected_epoch) +cluster_ctrc_terminal_release_sample_exact(uint32 segment_id, uint16 slot_offset, TransactionId xid, + uint16 slot_wrap, uint8 terminal_status, + SCN terminal_scn, uint64 expected_epoch) { mock_ctrc_sample_calls++; mock_ctrc_sample_lock_depth = mock_lwlock_depth; @@ -181,16 +178,14 @@ cluster_ctrc_terminal_release_sample_exact(uint32 segment_id, UT_ASSERT_EQ(slot_offset, 0); UT_ASSERT_EQ(xid, (TransactionId)100); UT_ASSERT_EQ(slot_wrap, 0); - UT_ASSERT(terminal_status == TT_SLOT_COMMITTED - || terminal_status == TT_SLOT_ABORTED); + UT_ASSERT(terminal_status == TT_SLOT_COMMITTED || terminal_status == TT_SLOT_ABORTED); UT_ASSERT_EQ(expected_epoch, UINT64_C(7)); if (terminal_status == TT_SLOT_COMMITTED) UT_ASSERT(SCN_VALID(terminal_scn)); else UT_ASSERT_EQ(terminal_scn, InvalidScn); - if (mock_ctrc_rebind_during_sample) - { + if (mock_ctrc_rebind_during_sample) { uint16 rebound; mock_ctrc_rebind_during_sample = false; @@ -199,11 +194,9 @@ cluster_ctrc_terminal_release_sample_exact(uint32 segment_id, rebound = cluster_tt_slot_alloc(UINT32_C(1), (TransactionId)100); UT_ASSERT_EQ(rebound, 0); if (terminal_status == TT_SLOT_COMMITTED) - cluster_tt_slot_mark_committed(UINT32_C(1), rebound, - (TransactionId)100, terminal_scn); + cluster_tt_slot_mark_committed(UINT32_C(1), rebound, (TransactionId)100, terminal_scn); else - cluster_tt_slot_mark_aborted(UINT32_C(1), rebound, - (TransactionId)100); + cluster_tt_slot_mark_aborted(UINT32_C(1), rebound, (TransactionId)100); } return mock_ctrc_release_proven; } @@ -1196,7 +1189,7 @@ UT_TEST(test_t49_peer_mode_aborted_retains_canonical_slot) uint16 off; uint16 result; bool retained = false; - ClusterUndoCleanerPassStats stats = {0}; + ClusterUndoCleanerPassStats stats = { 0 }; int i; reset_allocator(); @@ -1232,7 +1225,7 @@ UT_TEST(test_t49_peer_mode_aborted_retains_canonical_slot) UT_TEST(test_t54_peer_gc_rejects_exact_candidate_aba_after_release_sample) { - ClusterUndoCleanerPassStats stats = {0}; + ClusterUndoCleanerPassStats stats = { 0 }; ClusterTTSlotCurrentOwner owner; uint16 off; @@ -1240,8 +1233,7 @@ UT_TEST(test_t54_peer_gc_rejects_exact_candidate_aba_after_release_sample) mock_cluster_conf.node_count = 2; off = cluster_tt_slot_alloc(NODE0_SEG, (TransactionId)100); UT_ASSERT_EQ(off, 0); - cluster_tt_slot_mark_committed(NODE0_SEG, off, - (TransactionId)100, (SCN)10); + cluster_tt_slot_mark_committed(NODE0_SEG, off, (TransactionId)100, (SCN)10); mock_ctrc_release_proven = true; mock_ctrc_rebind_during_sample = true; @@ -1249,8 +1241,7 @@ UT_TEST(test_t54_peer_gc_rejects_exact_candidate_aba_after_release_sample) UT_ASSERT_EQ(mock_ctrc_sample_calls, 1); UT_ASSERT_EQ(mock_ctrc_sample_lock_depth, 0); UT_ASSERT_EQ((int)stats.shmem_tt_slots_gcd, 0); - UT_ASSERT(cluster_tt_slot_current_owner_by_xid( - 0, (TransactionId)100, &owner)); + UT_ASSERT(cluster_tt_slot_current_owner_by_xid(0, (TransactionId)100, &owner)); UT_ASSERT_EQ(owner.status, CTS_COMMITTED); UT_ASSERT_EQ(owner.commit_scn, (SCN)10); } @@ -1288,8 +1279,7 @@ UT_TEST(test_t51_current_owner_snapshot_is_exact_and_rollover_bounded) cluster_tt_slot_rollover(0, NODE0_SEG, NULL); off = cluster_tt_slot_alloc(NODE0_SEG, (TransactionId)100); memset(&owner, 0xA5, sizeof(owner)); - UT_ASSERT(cluster_tt_slot_current_owner_by_xid( - 0, (TransactionId)100, &owner)); + UT_ASSERT(cluster_tt_slot_current_owner_by_xid(0, (TransactionId)100, &owner)); UT_ASSERT_EQ((int)owner.segment_id, (int)NODE0_SEG); UT_ASSERT_EQ((int)owner.xid, 100); UT_ASSERT_EQ((int)owner.slot_offset, (int)off); @@ -1300,18 +1290,15 @@ UT_TEST(test_t51_current_owner_snapshot_is_exact_and_rollover_bounded) UT_ASSERT_EQ((int)owner.reserved8[1], 0); UT_ASSERT_EQ((int)owner.reserved8[2], 0); - cluster_tt_slot_mark_committed( - NODE0_SEG, off, (TransactionId)100, (SCN)77); - UT_ASSERT(cluster_tt_slot_current_owner_by_xid( - 0, (TransactionId)100, &owner)); + cluster_tt_slot_mark_committed(NODE0_SEG, off, (TransactionId)100, (SCN)77); + UT_ASSERT(cluster_tt_slot_current_owner_by_xid(0, (TransactionId)100, &owner)); UT_ASSERT_EQ((int)owner.status, (int)CTS_COMMITTED); UT_ASSERT_EQ((int)owner.commit_scn, 77); cluster_tt_slot_rollover(0, 2, NULL); memset(&owner, 0xA5, sizeof(owner)); - UT_ASSERT(!cluster_tt_slot_current_owner_by_xid( - 0, (TransactionId)100, &owner)); - UT_ASSERT_EQ(memcmp(&owner, &(ClusterTTSlotCurrentOwner){0}, sizeof(owner)), 0); + UT_ASSERT(!cluster_tt_slot_current_owner_by_xid(0, (TransactionId)100, &owner)); + UT_ASSERT_EQ(memcmp(&owner, &(ClusterTTSlotCurrentOwner){ 0 }, sizeof(owner)), 0); } UT_TEST(test_t52_current_exact_alloc_reports_rollover_drift_without_mutation) @@ -1325,16 +1312,16 @@ UT_TEST(test_t52_current_exact_alloc_reports_rollover_drift_without_mutation) cluster_tt_slot_rollover(0, NODE0_SEG, NULL); cluster_tt_slot_rollover(0, 2, NULL); - result = cluster_tt_slot_alloc_current_exact( - 0, NODE0_SEG, (TransactionId)100, &retained, ¤t_drift, &wrap); + result = cluster_tt_slot_alloc_current_exact(0, NODE0_SEG, (TransactionId)100, &retained, + ¤t_drift, &wrap); UT_ASSERT_EQ((int)result, (int)INVALID_TT_SLOT_OFFSET); UT_ASSERT_EQ((int)retained, 0); UT_ASSERT_EQ((int)current_drift, 1); UT_ASSERT_EQ((int)wrap, (int)TT_WRAP_INVALID); UT_ASSERT_EQ((int)cluster_tt_slot_current_segment(0), 2); - result = cluster_tt_slot_alloc_current_exact( - 0, 2, (TransactionId)100, &retained, ¤t_drift, &wrap); + result = cluster_tt_slot_alloc_current_exact(0, 2, (TransactionId)100, &retained, + ¤t_drift, &wrap); UT_ASSERT_EQ((int)result, 0); UT_ASSERT_EQ((int)retained, 0); UT_ASSERT_EQ((int)current_drift, 0); @@ -1348,8 +1335,8 @@ UT_TEST(test_unbound_current_exact_cannot_invent_free_slots) uint16 wrap = 0; reset_allocator(); - UT_ASSERT_EQ(cluster_tt_slot_alloc_current_exact(0, NODE0_SEG, 100, - &retained, &drift, &wrap), INVALID_TT_SLOT_OFFSET); + UT_ASSERT_EQ(cluster_tt_slot_alloc_current_exact(0, NODE0_SEG, 100, &retained, &drift, &wrap), + INVALID_TT_SLOT_OFFSET); UT_ASSERT(drift); UT_ASSERT(!retained); UT_ASSERT_EQ(wrap, TT_WRAP_INVALID); @@ -1371,9 +1358,8 @@ UT_TEST(test_t53_current_exact_alloc_captures_recycle_wrap_atomically) for (i = 1; i < TT_SLOTS_PER_SEGMENT; i++) (void)cluster_tt_slot_alloc(NODE0_SEG, (TransactionId)(1000 + i)); - recycled = cluster_tt_slot_alloc_current_exact( - 0, NODE0_SEG, (TransactionId)99999, - &retained, ¤t_drift, &wrap); + recycled = cluster_tt_slot_alloc_current_exact(0, NODE0_SEG, (TransactionId)99999, &retained, + ¤t_drift, &wrap); UT_ASSERT_EQ((int)recycled, (int)first); UT_ASSERT_EQ((int)retained, 0); UT_ASSERT_EQ((int)current_drift, 0); diff --git a/src/test/cluster_unit/test_cluster_tt_status.c b/src/test/cluster_unit/test_cluster_tt_status.c index d8d297b07d1..9e986f091fb 100644 --- a/src/test/cluster_unit/test_cluster_tt_status.c +++ b/src/test/cluster_unit/test_cluster_tt_status.c @@ -103,8 +103,8 @@ int cluster_tt_status_overlay_ttl_ms = 30000; ClusterSemanticAdmissionResult cluster_tt_status_source_dispatch(ClusterTTStatusSourceOp op pg_attribute_unused(), - const ClusterTTStatusSourceRequest *request pg_attribute_unused(), - ClusterTTStatusSourceResult *result pg_attribute_unused()) + const ClusterTTStatusSourceRequest *request pg_attribute_unused(), + ClusterTTStatusSourceResult *result pg_attribute_unused()) { return CLUSTER_SEMANTIC_ADMISSION_CLOSED; } diff --git a/src/test/cluster_unit/test_cluster_tt_status_hint.c b/src/test/cluster_unit/test_cluster_tt_status_hint.c index 19c79b1d5e2..7f935133e50 100644 --- a/src/test/cluster_unit/test_cluster_tt_status_hint.c +++ b/src/test/cluster_unit/test_cluster_tt_status_hint.c @@ -79,9 +79,9 @@ int cluster_tt_status_hint_outbound_capacity = 256; int cluster_tt_status_hint_emit_mode = CLUSTER_TT_STATUS_HINT_EMIT_ALL_STATUS; ClusterSemanticAdmissionResult -cluster_tt_status_hint_source_dispatch( - ClusterTTStatusHintSourceOp op pg_attribute_unused(), - const ClusterTTStatusHintSourceRequest *request pg_attribute_unused()) +cluster_tt_status_hint_source_dispatch(ClusterTTStatusHintSourceOp op pg_attribute_unused(), + const ClusterTTStatusHintSourceRequest *request + pg_attribute_unused()) { return CLUSTER_SEMANTIC_ADMISSION_CLOSED; } diff --git a/src/test/cluster_unit/test_cluster_uba.c b/src/test/cluster_unit/test_cluster_uba.c index 0f1243b4087..418a8b4355d 100644 --- a/src/test/cluster_unit/test_cluster_uba.c +++ b/src/test/cluster_unit/test_cluster_uba.c @@ -313,8 +313,7 @@ UT_TEST(test_t25_record_decode_rejects_header_boundary_and_segment_alias) uint16 off = UINT16_MAX; uint16 row = UINT16_MAX; - UT_ASSERT(uba_decode_record(uba_encode(32768, 8191, 47, 65535), - &seg, &blk, &off, &row)); + UT_ASSERT(uba_decode_record(uba_encode(32768, 8191, 47, 65535), &seg, &blk, &off, &row)); UT_ASSERT_EQ(seg, 32768); UT_ASSERT_EQ(blk, 8191); UT_ASSERT_EQ(off, 47); @@ -322,8 +321,7 @@ UT_TEST(test_t25_record_decode_rejects_header_boundary_and_segment_alias) UT_ASSERT(!uba_decode_record(uba_encode(1, 0, 0, 0), &seg, &blk, &off, &row)); UT_ASSERT(!uba_decode_record(uba_encode(1, 8192, 0, 0), &seg, &blk, &off, &row)); - UT_ASSERT(!uba_decode_record(uba_encode(32769, 1, 0, 0), - &seg, &blk, &off, &row)); + UT_ASSERT(!uba_decode_record(uba_encode(32769, 1, 0, 0), &seg, &blk, &off, &row)); } diff --git a/src/test/cluster_unit/test_cluster_undo_block0.c b/src/test/cluster_unit/test_cluster_undo_block0.c index 3780ef037d8..481f7ae6aaa 100644 --- a/src/test/cluster_unit/test_cluster_undo_block0.c +++ b/src/test/cluster_unit/test_cluster_undo_block0.c @@ -58,25 +58,18 @@ pg_re_throw(void) /* Spec 8.4A P1 closed diagnostic/private-recovery read seam. */ extern ClusterUndoBlock0Result cluster_undo_block0_copy_readonly( - const ClusterUndoBlock0LogicalKey *logical, - const ClusterUndoBlock0ResolvedRoot *read_root, - const ClusterUndoBlock0Generation *expected, - const ClusterUndoBlock0AuthorityProof *proof, + const ClusterUndoBlock0LogicalKey *logical, const ClusterUndoBlock0ResolvedRoot *read_root, + const ClusterUndoBlock0Generation *expected, const ClusterUndoBlock0AuthorityProof *proof, char private_page[BLCKSZ]); extern ClusterUndoBlock0Result cluster_undo_block0_provision_begin( - const ClusterUndoBlock0LogicalKey *logical, - const ClusterUndoBlock0ResolvedRoot *target_root, - const ClusterUndoBlock0AuthorityProof *proof, - ClusterUndoBlock0FrameToken *token, - ClusterUndoBlock0Pin *pin, - char **unpublished_page, - bool *creator); -extern void cluster_undo_block0_provision_publish(ClusterUndoBlock0Pin *pin, - XLogRecPtr init_lsn); + const ClusterUndoBlock0LogicalKey *logical, const ClusterUndoBlock0ResolvedRoot *target_root, + const ClusterUndoBlock0AuthorityProof *proof, ClusterUndoBlock0FrameToken *token, + ClusterUndoBlock0Pin *pin, char **unpublished_page, bool *creator); +extern void cluster_undo_block0_provision_publish(ClusterUndoBlock0Pin *pin, XLogRecPtr init_lsn); extern void cluster_undo_block0_provision_abort(ClusterUndoBlock0Pin *pin); -extern ClusterUndoBlock0Result cluster_undo_block0_prove_strict_empty( - const ClusterUndoBlock0LogicalKey *logical, - const ClusterUndoBlock0AuthorityProof *proof); +extern ClusterUndoBlock0Result +cluster_undo_block0_prove_strict_empty(const ClusterUndoBlock0LogicalKey *logical, + const ClusterUndoBlock0AuthorityProof *proof); /* storage/shmem.h exports checked arithmetic from the backend executable. */ Size @@ -113,8 +106,7 @@ static bool copy_during_fill = false; static bool empty_probe_during_fill = false; static bool abort_during_fill = false; static ClusterUndoBlock0Result copy_during_fill_result = CLUSTER_UNDO_BLOCK0_OK; -static ClusterUndoBlock0Result empty_probe_during_fill_result - = CLUSTER_UNDO_BLOCK0_OK; +static ClusterUndoBlock0Result empty_probe_during_fill_result = CLUSTER_UNDO_BLOCK0_OK; static ClusterUndoBlock0LogicalKey fill_logical; static ClusterUndoBlock0ResolvedRoot fill_root; static ClusterUndoBlock0AuthorityProof fill_proof; @@ -124,8 +116,7 @@ static int lwlock_acquire_calls = 0; static int lwlock_throw_on_call = 0; static int lwlock_release_without_holdoff_count = 0; static ClusterUndoSmgrFinalState smgr_probe_state = CLUSTER_UNDO_SMGR_FINAL_EXACT; -static ClusterUndoSmgrPublishResult smgr_publish_result - = CLUSTER_UNDO_SMGR_PUBLISH_PUBLISHED; +static ClusterUndoSmgrPublishResult smgr_publish_result = CLUSTER_UNDO_SMGR_PUBLISH_PUBLISHED; static char smgr_probe_image[BLCKSZ]; static int smgr_probe_calls = 0; static int smgr_temp_create_calls = 0; @@ -135,7 +126,7 @@ static bool smgr_temp_active = false; static ClusterR4PrerequisiteSnapshot r4_owner_snapshot = { .status = CLUSTER_R4_PREREQUISITE_RF_DEFERRED, .ready = false, - .reserved0 = {0, 0, 0}, + .reserved0 = { 0, 0, 0 }, .target_node_id = -1, }; static bool r4_owner_publish_enabled = false; @@ -277,9 +268,9 @@ cluster_undo_smgr_read_block(ClusterUndoPathIntent intent pg_attribute_unused(), bool cluster_undo_smgr_write_block(ClusterUndoPathIntent intent pg_attribute_unused(), - uint32 segment_id pg_attribute_unused(), - uint8 owner_instance pg_attribute_unused(), uint32 block_no, - const char *buf, bool do_fsync) + uint32 segment_id pg_attribute_unused(), + uint8 owner_instance pg_attribute_unused(), uint32 block_no, + const char *buf, bool do_fsync) { smgr_write_calls++; smgr_last_write_block = block_no; @@ -739,8 +730,7 @@ UT_TEST(test_block0_attach_rejects_impossible_free_count) ctl->free_count = ctl->frame_count + 1; token.frame_index = 0; token.owned = true; - UT_ASSERT(!cluster_undo_block0_shmem_init_region( - block0_region, block0_region_size, 1, true)); + UT_ASSERT(!cluster_undo_block0_shmem_init_region(block0_region, block0_region_size, 1, true)); UT_ASSERT_EQ(cluster_undo_block0_frame_reserve_batch(1, &token), CLUSTER_UNDO_BLOCK0_CAPACITY_UNAVAILABLE); UT_ASSERT(!token.owned); @@ -795,11 +785,11 @@ UT_TEST(test_block0_runtime_admission_preserves_generation_zero_and_exact_identi make_valid_block0(1, 1, 0, 0x4d); memset(&token, 0, sizeof(token)); memset(&pin, 0, sizeof(pin)); - UT_ASSERT_EQ(cluster_undo_block0_frame_reserve_batch(1, &token), - CLUSTER_UNDO_BLOCK0_OK); + UT_ASSERT_EQ(cluster_undo_block0_frame_reserve_batch(1, &token), CLUSTER_UNDO_BLOCK0_OK); admitted_frame = token.frame_index; - UT_ASSERT_EQ(cluster_undo_block0_admit_runtime(&logical, &read_only_root, &proof, &token, &pin, - &page), CLUSTER_UNDO_BLOCK0_AUTHORITY_DENIED); + UT_ASSERT_EQ( + cluster_undo_block0_admit_runtime(&logical, &read_only_root, &proof, &token, &pin, &page), + CLUSTER_UNDO_BLOCK0_AUTHORITY_DENIED); UT_ASSERT(token.owned); UT_ASSERT_EQ(smgr_read_calls, 0); UT_ASSERT_EQ(cluster_undo_block0_admit_runtime(&logical, &root, &proof, &token, &pin, &page), @@ -820,7 +810,8 @@ UT_TEST(test_block0_runtime_admission_preserves_generation_zero_and_exact_identi UT_ASSERT_EQ(smgr_read_calls, 0); memset(copied, 0xa5, sizeof(copied)); UT_ASSERT_EQ(cluster_undo_block0_copy_resident(&logical, &root, &expected_zero, &proof, copied, - &observed), CLUSTER_UNDO_BLOCK0_OK); + &observed), + CLUSTER_UNDO_BLOCK0_OK); UT_ASSERT(observed.known); UT_ASSERT_EQ(observed.value, 0); UT_ASSERT_EQ((int)(unsigned char)copied[BLCKSZ - 1], 0x4d); @@ -848,10 +839,8 @@ UT_TEST(test_block0_unpin_after_error_interrupt_reset_is_balanced) memset(&pin, 0, sizeof(pin)); lwlock_release_without_holdoff_count = 0; UT_ASSERT_EQ(InterruptHoldoffCount, 0); - UT_ASSERT_EQ(cluster_undo_block0_frame_reserve_batch(1, &token), - CLUSTER_UNDO_BLOCK0_OK); - UT_ASSERT_EQ(cluster_undo_block0_admit_runtime( - &logical, &root, &proof, &token, &pin, &page), + UT_ASSERT_EQ(cluster_undo_block0_frame_reserve_batch(1, &token), CLUSTER_UNDO_BLOCK0_OK); + UT_ASSERT_EQ(cluster_undo_block0_admit_runtime(&logical, &root, &proof, &token, &pin, &page), CLUSTER_UNDO_BLOCK0_OK); UT_ASSERT_EQ(InterruptHoldoffCount, 1); @@ -876,10 +865,8 @@ UT_TEST(test_block0_runtime_admission_rejects_exhausted_generation) make_valid_block0(1, 1, UINT32_MAX, 0x5e); memset(&token, 0, sizeof(token)); memset(&pin, 0, sizeof(pin)); - UT_ASSERT_EQ(cluster_undo_block0_frame_reserve_batch(1, &token), - CLUSTER_UNDO_BLOCK0_OK); - UT_ASSERT_EQ(cluster_undo_block0_admit_runtime( - &logical, &root, &proof, &token, &pin, &page), + UT_ASSERT_EQ(cluster_undo_block0_frame_reserve_batch(1, &token), CLUSTER_UNDO_BLOCK0_OK); + UT_ASSERT_EQ(cluster_undo_block0_admit_runtime(&logical, &root, &proof, &token, &pin, &page), CLUSTER_UNDO_BLOCK0_GENERATION_MISMATCH); UT_ASSERT(token.owned); UT_ASSERT_NULL(page); @@ -900,27 +887,23 @@ UT_TEST(test_block0_strict_empty_proof_excludes_filling_and_resident_states) char *page = NULL; fresh_block0_region(1); - UT_ASSERT_EQ(cluster_undo_block0_prove_strict_empty(&logical, &proof), - CLUSTER_UNDO_BLOCK0_OK); + UT_ASSERT_EQ(cluster_undo_block0_prove_strict_empty(&logical, &proof), CLUSTER_UNDO_BLOCK0_OK); UT_ASSERT_EQ(cluster_undo_block0_prove_strict_empty(&logical, &wrong), - CLUSTER_UNDO_BLOCK0_AUTHORITY_DENIED); + CLUSTER_UNDO_BLOCK0_AUTHORITY_DENIED); make_valid_block0(1, 1, 0, 0x5f); memset(&token, 0, sizeof(token)); - UT_ASSERT_EQ(cluster_undo_block0_frame_reserve_batch(1, &token), - CLUSTER_UNDO_BLOCK0_OK); + UT_ASSERT_EQ(cluster_undo_block0_frame_reserve_batch(1, &token), CLUSTER_UNDO_BLOCK0_OK); fill_logical = logical; fill_root = root; fill_proof = proof; empty_probe_during_fill = true; - UT_ASSERT_EQ(cluster_undo_block0_admit_runtime( - &logical, &root, &proof, &token, &pin, &page), - CLUSTER_UNDO_BLOCK0_OK); - UT_ASSERT_EQ(empty_probe_during_fill_result, - CLUSTER_UNDO_BLOCK0_AUTHORITY_DENIED); + UT_ASSERT_EQ(cluster_undo_block0_admit_runtime(&logical, &root, &proof, &token, &pin, &page), + CLUSTER_UNDO_BLOCK0_OK); + UT_ASSERT_EQ(empty_probe_during_fill_result, CLUSTER_UNDO_BLOCK0_AUTHORITY_DENIED); cluster_undo_block0_unpin(&pin); UT_ASSERT_EQ(cluster_undo_block0_prove_strict_empty(&logical, &proof), - CLUSTER_UNDO_BLOCK0_AUTHORITY_DENIED); + CLUSTER_UNDO_BLOCK0_AUTHORITY_DENIED); } UT_TEST(test_block0_copy_readonly_is_recovery_only_and_generation_exact) @@ -937,23 +920,20 @@ UT_TEST(test_block0_copy_readonly_is_recovery_only_and_generation_exact) fresh_block0_region(1); make_valid_block0(1, 1, 0, 0x60); memset(copied, 0xa5, sizeof(copied)); - UT_ASSERT_EQ(cluster_undo_block0_copy_readonly( - &logical, &root, &zero, &recovery, copied), + UT_ASSERT_EQ(cluster_undo_block0_copy_readonly(&logical, &root, &zero, &recovery, copied), CLUSTER_UNDO_BLOCK0_OK); UT_ASSERT_EQ(smgr_read_calls, 1); UT_ASSERT_EQ((int)(unsigned char)copied[BLCKSZ - 1], 0x60); smgr_read_calls = 0; memset(copied, 0xa5, sizeof(copied)); - UT_ASSERT_EQ(cluster_undo_block0_copy_readonly( - &logical, &root, &zero, &live, copied), + UT_ASSERT_EQ(cluster_undo_block0_copy_readonly(&logical, &root, &zero, &live, copied), CLUSTER_UNDO_BLOCK0_AUTHORITY_DENIED); UT_ASSERT_EQ(smgr_read_calls, 0); UT_ASSERT_EQ((int)(unsigned char)copied[0], 0xa5); memset(copied, 0xa5, sizeof(copied)); - UT_ASSERT_EQ(cluster_undo_block0_copy_readonly( - &logical, &root, &wrong, &recovery, copied), + UT_ASSERT_EQ(cluster_undo_block0_copy_readonly(&logical, &root, &wrong, &recovery, copied), CLUSTER_UNDO_BLOCK0_GENERATION_MISMATCH); UT_ASSERT_EQ(smgr_read_calls, 1); UT_ASSERT_EQ((int)(unsigned char)copied[0], 0xa5); @@ -987,25 +967,27 @@ UT_TEST(test_block0_resident_copy_rejects_empty_generation_and_root_drift_withou UT_ASSERT_EQ(cluster_undo_block0_reserve(&logical, &root, &proof, &reserved_pin), CLUSTER_UNDO_BLOCK0_OK); UT_ASSERT_EQ(cluster_undo_block0_lock_content(&reserved_pin, &wrong_generation, - CLUSTER_UNDO_BLOCK0_SHARED, &page), + CLUSTER_UNDO_BLOCK0_SHARED, &page), CLUSTER_UNDO_BLOCK0_GENERATION_MISMATCH); UT_ASSERT_EQ(reserved_pin.slot, -1); UT_ASSERT_NULL(page); memset(copied, 0xa5, sizeof(copied)); - UT_ASSERT_EQ(cluster_undo_block0_copy_resident(&logical, &root, &wrong_generation, &proof, - copied, NULL), - CLUSTER_UNDO_BLOCK0_GENERATION_MISMATCH); + UT_ASSERT_EQ( + cluster_undo_block0_copy_resident(&logical, &root, &wrong_generation, &proof, copied, NULL), + CLUSTER_UNDO_BLOCK0_GENERATION_MISMATCH); UT_ASSERT_EQ((int)(unsigned char)copied[0], 0xa5); drifted_root.root_generation++; - UT_ASSERT_EQ(cluster_undo_block0_copy_resident(&logical, &drifted_root, NULL, &proof, copied, - NULL), CLUSTER_UNDO_BLOCK0_IDENTITY_MISMATCH); + UT_ASSERT_EQ( + cluster_undo_block0_copy_resident(&logical, &drifted_root, NULL, &proof, copied, NULL), + CLUSTER_UNDO_BLOCK0_IDENTITY_MISMATCH); UT_ASSERT_EQ((int)(unsigned char)copied[0], 0xa5); drifted_proof.cluster_epoch++; - UT_ASSERT_EQ(cluster_undo_block0_copy_resident(&logical, &root, NULL, &drifted_proof, copied, - NULL), CLUSTER_UNDO_BLOCK0_AUTHORITY_DENIED); + UT_ASSERT_EQ( + cluster_undo_block0_copy_resident(&logical, &root, NULL, &drifted_proof, copied, NULL), + CLUSTER_UNDO_BLOCK0_AUTHORITY_DENIED); UT_ASSERT_EQ((int)(unsigned char)copied[0], 0xa5); UT_ASSERT_EQ(cluster_undo_block0_copy_resident(&absent, &root, NULL, &proof, copied, NULL), @@ -1030,10 +1012,8 @@ UT_TEST(test_block0_pin_error_drops_reservation_before_rethrow) fresh_block0_region(1); make_valid_block0(1, 1, 0, 0x62); memset(&token, 0, sizeof(token)); - UT_ASSERT_EQ(cluster_undo_block0_frame_reserve_batch(1, &token), - CLUSTER_UNDO_BLOCK0_OK); - UT_ASSERT_EQ(cluster_undo_block0_admit_runtime( - &logical, &root, &proof, &token, &pin, &page), + UT_ASSERT_EQ(cluster_undo_block0_frame_reserve_batch(1, &token), CLUSTER_UNDO_BLOCK0_OK); + UT_ASSERT_EQ(cluster_undo_block0_admit_runtime(&logical, &root, &proof, &token, &pin, &page), CLUSTER_UNDO_BLOCK0_OK); memset(&item, 0, sizeof(item)); item.logical = logical; @@ -1046,8 +1026,8 @@ UT_TEST(test_block0_pin_error_drops_reservation_before_rethrow) lwlock_throw_on_call = 2; /* reserve succeeds; content-X acquire throws */ PG_TRY(); { - (void)cluster_undo_block0_pin(&logical, &root, &expected, - CLUSTER_UNDO_BLOCK0_EXCLUSIVE, &proof, &pin, &page); + (void)cluster_undo_block0_pin(&logical, &root, &expected, CLUSTER_UNDO_BLOCK0_EXCLUSIVE, + &proof, &pin, &page); } PG_CATCH(); { @@ -1075,7 +1055,8 @@ UT_TEST(test_block0_filling_is_not_a_positive_resident_copy) UT_ASSERT_EQ(cluster_undo_block0_frame_reserve_batch(1, &token), CLUSTER_UNDO_BLOCK0_OK); copy_during_fill = true; UT_ASSERT_EQ(cluster_undo_block0_admit_runtime(&fill_logical, &fill_root, &fill_proof, &token, - &pin, &page), CLUSTER_UNDO_BLOCK0_OK); + &pin, &page), + CLUSTER_UNDO_BLOCK0_OK); UT_ASSERT_EQ(copy_during_fill_result, CLUSTER_UNDO_BLOCK0_NOT_PUBLISHED); cluster_undo_block0_unpin(&pin); } @@ -1098,17 +1079,14 @@ UT_TEST(test_block0_runtime_fill_abort_releases_slot_and_frame_via_resource_owne memset(&token, 0, sizeof(token)); memset(&retry, 0, sizeof(retry)); memset(&extra, 0, sizeof(extra)); - UT_ASSERT_EQ(cluster_undo_block0_frame_reserve_batch(1, &token), - CLUSTER_UNDO_BLOCK0_OK); + UT_ASSERT_EQ(cluster_undo_block0_frame_reserve_batch(1, &token), CLUSTER_UNDO_BLOCK0_OK); abort_during_fill = true; if (sigsetjmp(wal_error_jump, 1) == 0) - (void)cluster_undo_block0_admit_runtime( - &logical, &root, &proof, &token, &pin, &page); + (void)cluster_undo_block0_admit_runtime(&logical, &root, &proof, &token, &pin, &page); else caught = true; UT_ASSERT(caught); - UT_ASSERT_EQ(cluster_undo_block0_frame_reserve_batch(1, &retry), - CLUSTER_UNDO_BLOCK0_OK); + UT_ASSERT_EQ(cluster_undo_block0_frame_reserve_batch(1, &retry), CLUSTER_UNDO_BLOCK0_OK); UT_ASSERT(retry.owned); cluster_undo_block0_frame_release(&token); UT_ASSERT(!token.owned); @@ -1136,18 +1114,15 @@ UT_TEST(test_block0_resource_owner_cleanup_is_balanced_with_normal_release) memset(&token, 0, sizeof(token)); memset(&retry, 0, sizeof(retry)); memset(&extra, 0, sizeof(extra)); - UT_ASSERT_EQ(cluster_undo_block0_frame_reserve_batch(1, &token), - CLUSTER_UNDO_BLOCK0_OK); - UT_ASSERT_EQ(cluster_undo_block0_admit_runtime( - &logical, &root, &proof, &token, &pin, &page), + UT_ASSERT_EQ(cluster_undo_block0_frame_reserve_batch(1, &token), CLUSTER_UNDO_BLOCK0_OK); + UT_ASSERT_EQ(cluster_undo_block0_admit_runtime(&logical, &root, &proof, &token, &pin, &page), CLUSTER_UNDO_BLOCK0_OK); memset(&item, 0, sizeof(item)); item.logical = logical; item.resolved_root = root; item.generation = pin.observed_generation; item.proof = proof; - resource_release_callback(RESOURCE_RELEASE_BEFORE_LOCKS, false, false, - resource_release_arg); + resource_release_callback(RESOURCE_RELEASE_BEFORE_LOCKS, false, false, resource_release_arg); UT_ASSERT(cluster_undo_block0_verify_clean_census(&item, 1)); /* The admitted frame stays bound. No stale tracker may return it. */ @@ -1157,13 +1132,10 @@ UT_TEST(test_block0_resource_owner_cleanup_is_balanced_with_normal_release) /* Normal release removes its tracker, so a later owner callback cannot * duplicate the free-stack entry. */ fresh_block0_region(1); - UT_ASSERT_EQ(cluster_undo_block0_frame_reserve_batch(1, &retry), - CLUSTER_UNDO_BLOCK0_OK); + UT_ASSERT_EQ(cluster_undo_block0_frame_reserve_batch(1, &retry), CLUSTER_UNDO_BLOCK0_OK); cluster_undo_block0_frame_release(&retry); - resource_release_callback(RESOURCE_RELEASE_BEFORE_LOCKS, false, false, - resource_release_arg); - UT_ASSERT_EQ(cluster_undo_block0_frame_reserve_batch(1, &retry), - CLUSTER_UNDO_BLOCK0_OK); + resource_release_callback(RESOURCE_RELEASE_BEFORE_LOCKS, false, false, resource_release_arg); + UT_ASSERT_EQ(cluster_undo_block0_frame_reserve_batch(1, &retry), CLUSTER_UNDO_BLOCK0_OK); UT_ASSERT_EQ(cluster_undo_block0_frame_reserve_batch(1, &extra), CLUSTER_UNDO_BLOCK0_CAPACITY_UNAVAILABLE); cluster_undo_block0_frame_release(&retry); @@ -1184,17 +1156,15 @@ UT_TEST(test_block0_provision_existing_exact_loads_without_temp_or_write) make_valid_block0(1, 1, 4, 0x75); memcpy(smgr_probe_image, smgr_image, BLCKSZ); memset(&token, 0, sizeof(token)); - UT_ASSERT_EQ(cluster_undo_block0_frame_reserve_batch(1, &token), - CLUSTER_UNDO_BLOCK0_OK); - UT_ASSERT_EQ(cluster_undo_block0_provision_begin( - &logical, &root, &proof, &token, &pin, &page, &creator), - CLUSTER_UNDO_BLOCK0_OK); + UT_ASSERT_EQ(cluster_undo_block0_frame_reserve_batch(1, &token), CLUSTER_UNDO_BLOCK0_OK); + UT_ASSERT_EQ( + cluster_undo_block0_provision_begin(&logical, &root, &proof, &token, &pin, &page, &creator), + CLUSTER_UNDO_BLOCK0_OK); UT_ASSERT(!creator); UT_ASSERT_EQ(smgr_probe_calls, 1); UT_ASSERT_EQ(smgr_temp_create_calls, 0); UT_ASSERT_EQ(smgr_write_calls, 0); - UT_ASSERT_EQ((unsigned char)page[BLCKSZ - 1], - (unsigned char)smgr_image[BLCKSZ - 1]); + UT_ASSERT_EQ((unsigned char)page[BLCKSZ - 1], (unsigned char)smgr_image[BLCKSZ - 1]); UT_ASSERT(pin.observed_generation.known); UT_ASSERT_EQ(pin.observed_generation.value, 4); cluster_undo_block0_unpin(&pin); @@ -1216,10 +1186,9 @@ UT_TEST(test_block0_provision_rejects_non_live_authority_before_io) make_valid_block0(1, 1, 4, 0x75); memcpy(smgr_probe_image, smgr_image, BLCKSZ); memset(&token, 0, sizeof(token)); - UT_ASSERT_EQ(cluster_undo_block0_frame_reserve_batch(1, &token), - CLUSTER_UNDO_BLOCK0_OK); - result = cluster_undo_block0_provision_begin( - &logical, &root, &proof, &token, &pin, &page, &creator); + UT_ASSERT_EQ(cluster_undo_block0_frame_reserve_batch(1, &token), CLUSTER_UNDO_BLOCK0_OK); + result = cluster_undo_block0_provision_begin(&logical, &root, &proof, &token, &pin, &page, + &creator); UT_ASSERT_EQ(result, CLUSTER_UNDO_BLOCK0_AUTHORITY_DENIED); UT_ASSERT_EQ(smgr_probe_calls, 0); UT_ASSERT_EQ(smgr_temp_create_calls, 0); @@ -1245,11 +1214,10 @@ UT_TEST(test_block0_provision_rejects_unknown_probe_state_without_consuming_fram fresh_block0_region(1); smgr_probe_state = (ClusterUndoSmgrFinalState)99; memset(&token, 0, sizeof(token)); - UT_ASSERT_EQ(cluster_undo_block0_frame_reserve_batch(1, &token), - CLUSTER_UNDO_BLOCK0_OK); - UT_ASSERT_EQ(cluster_undo_block0_provision_begin( - &logical, &root, &proof, &token, &pin, &page, &creator), - CLUSTER_UNDO_BLOCK0_IO_ERROR); + UT_ASSERT_EQ(cluster_undo_block0_frame_reserve_batch(1, &token), CLUSTER_UNDO_BLOCK0_OK); + UT_ASSERT_EQ( + cluster_undo_block0_provision_begin(&logical, &root, &proof, &token, &pin, &page, &creator), + CLUSTER_UNDO_BLOCK0_IO_ERROR); UT_ASSERT_EQ(smgr_probe_calls, 1); UT_ASSERT_EQ(smgr_temp_create_calls, 0); UT_ASSERT(token.owned); @@ -1273,11 +1241,10 @@ UT_TEST(test_block0_provision_absent_creator_publishes_after_wal_flush) make_valid_block0(1, 1, 5, 0x76); smgr_probe_state = CLUSTER_UNDO_SMGR_FINAL_ABSENT; memset(&token, 0, sizeof(token)); - UT_ASSERT_EQ(cluster_undo_block0_frame_reserve_batch(1, &token), - CLUSTER_UNDO_BLOCK0_OK); - UT_ASSERT_EQ(cluster_undo_block0_provision_begin( - &logical, &root, &proof, &token, &pin, &page, &creator), - CLUSTER_UNDO_BLOCK0_OK); + UT_ASSERT_EQ(cluster_undo_block0_frame_reserve_batch(1, &token), CLUSTER_UNDO_BLOCK0_OK); + UT_ASSERT_EQ( + cluster_undo_block0_provision_begin(&logical, &root, &proof, &token, &pin, &page, &creator), + CLUSTER_UNDO_BLOCK0_OK); UT_ASSERT(creator); UT_ASSERT(smgr_temp_active); UT_ASSERT_EQ(smgr_temp_create_calls, 1); @@ -1312,11 +1279,10 @@ UT_TEST(test_block0_provision_eexist_loser_installs_exact_winner_image) smgr_probe_state = CLUSTER_UNDO_SMGR_FINAL_ABSENT; smgr_publish_result = CLUSTER_UNDO_SMGR_PUBLISH_EXISTS; memset(&token, 0, sizeof(token)); - UT_ASSERT_EQ(cluster_undo_block0_frame_reserve_batch(1, &token), - CLUSTER_UNDO_BLOCK0_OK); - UT_ASSERT_EQ(cluster_undo_block0_provision_begin( - &logical, &root, &proof, &token, &pin, &page, &creator), - CLUSTER_UNDO_BLOCK0_OK); + UT_ASSERT_EQ(cluster_undo_block0_frame_reserve_batch(1, &token), CLUSTER_UNDO_BLOCK0_OK); + UT_ASSERT_EQ( + cluster_undo_block0_provision_begin(&logical, &root, &proof, &token, &pin, &page, &creator), + CLUSTER_UNDO_BLOCK0_OK); UT_ASSERT(creator); memcpy(page, smgr_image, BLCKSZ); page[BLCKSZ - 1] = (char)0xd7; @@ -1342,18 +1308,16 @@ UT_TEST(test_block0_provision_abort_cleans_temp_and_returns_frame) smgr_probe_state = CLUSTER_UNDO_SMGR_FINAL_ABSENT; memset(&token, 0, sizeof(token)); memset(&retry, 0, sizeof(retry)); - UT_ASSERT_EQ(cluster_undo_block0_frame_reserve_batch(1, &token), - CLUSTER_UNDO_BLOCK0_OK); - UT_ASSERT_EQ(cluster_undo_block0_provision_begin( - &logical, &root, &proof, &token, &pin, &page, &creator), - CLUSTER_UNDO_BLOCK0_OK); + UT_ASSERT_EQ(cluster_undo_block0_frame_reserve_batch(1, &token), CLUSTER_UNDO_BLOCK0_OK); + UT_ASSERT_EQ( + cluster_undo_block0_provision_begin(&logical, &root, &proof, &token, &pin, &page, &creator), + CLUSTER_UNDO_BLOCK0_OK); UT_ASSERT(creator); cluster_undo_block0_provision_abort(&pin); UT_ASSERT_EQ(pin.slot, -1); UT_ASSERT_EQ(smgr_temp_cleanup_calls, 1); UT_ASSERT(!smgr_temp_active); - UT_ASSERT_EQ(cluster_undo_block0_frame_reserve_batch(1, &retry), - CLUSTER_UNDO_BLOCK0_OK); + UT_ASSERT_EQ(cluster_undo_block0_frame_reserve_batch(1, &retry), CLUSTER_UNDO_BLOCK0_OK); cluster_undo_block0_frame_release(&retry); } @@ -1376,30 +1340,26 @@ UT_TEST(test_block0_provision_publish_error_resource_owner_cleans_exact_temp) smgr_publish_result = CLUSTER_UNDO_SMGR_PUBLISH_IO_ERROR; memset(&token, 0, sizeof(token)); memset(&retry, 0, sizeof(retry)); - UT_ASSERT_EQ(cluster_undo_block0_frame_reserve_batch(1, &token), - CLUSTER_UNDO_BLOCK0_OK); - UT_ASSERT_EQ(cluster_undo_block0_provision_begin( - &logical, &root, &proof, &token, &pin, &page, &creator), - CLUSTER_UNDO_BLOCK0_OK); + UT_ASSERT_EQ(cluster_undo_block0_frame_reserve_batch(1, &token), CLUSTER_UNDO_BLOCK0_OK); + UT_ASSERT_EQ( + cluster_undo_block0_provision_begin(&logical, &root, &proof, &token, &pin, &page, &creator), + CLUSTER_UNDO_BLOCK0_OK); UT_ASSERT(creator); memcpy(page, smgr_image, BLCKSZ); wal_error_armed = true; if (sigsetjmp(wal_error_jump, 1) == 0) - cluster_undo_block0_provision_publish(&pin, - (XLogRecPtr)UINT64CONST(0x140)); + cluster_undo_block0_provision_publish(&pin, (XLogRecPtr)UINT64CONST(0x140)); else caught = true; wal_error_armed = false; UT_ASSERT(caught); UT_ASSERT(smgr_temp_active); UT_ASSERT_NOT_NULL(resource_release_callback); - resource_release_callback(RESOURCE_RELEASE_BEFORE_LOCKS, false, false, - resource_release_arg); + resource_release_callback(RESOURCE_RELEASE_BEFORE_LOCKS, false, false, resource_release_arg); UT_ASSERT_EQ(smgr_temp_cleanup_calls, 1); UT_ASSERT(!smgr_temp_active); - UT_ASSERT_EQ(cluster_undo_block0_frame_reserve_batch(1, &retry), - CLUSTER_UNDO_BLOCK0_OK); + UT_ASSERT_EQ(cluster_undo_block0_frame_reserve_batch(1, &retry), CLUSTER_UNDO_BLOCK0_OK); cluster_undo_block0_frame_release(&retry); } @@ -1419,10 +1379,9 @@ UT_TEST(test_block0_recovery_private_begin_reads_without_allocating_a_frame) memset(&only_frame, 0, sizeof(only_frame)); memset(&guard, 0xa5, sizeof(guard)); memset(private_page, 0, sizeof(private_page)); - UT_ASSERT_EQ(cluster_undo_block0_frame_reserve_batch(1, &only_frame), - CLUSTER_UNDO_BLOCK0_OK); - UT_ASSERT_EQ(cluster_undo_block0_recovery_private_begin( - &logical, &root, &proof, false, &guard, private_page, &exists), + UT_ASSERT_EQ(cluster_undo_block0_frame_reserve_batch(1, &only_frame), CLUSTER_UNDO_BLOCK0_OK); + UT_ASSERT_EQ(cluster_undo_block0_recovery_private_begin(&logical, &root, &proof, false, &guard, + private_page, &exists), CLUSTER_UNDO_BLOCK0_OK); UT_ASSERT(exists); UT_ASSERT(guard.content_x_held); @@ -1452,8 +1411,8 @@ UT_TEST(test_block0_recovery_private_begin_rejects_live_authority_before_io) make_valid_block0(1, 1, 0, 0x45); memset(&guard, 0xa5, sizeof(guard)); memset(private_page, 0x5a, sizeof(private_page)); - UT_ASSERT_EQ(cluster_undo_block0_recovery_private_begin( - &logical, &root, &proof, false, &guard, private_page, &exists), + UT_ASSERT_EQ(cluster_undo_block0_recovery_private_begin(&logical, &root, &proof, false, &guard, + private_page, &exists), CLUSTER_UNDO_BLOCK0_AUTHORITY_DENIED); UT_ASSERT(!exists); UT_ASSERT(!guard.content_x_held); @@ -1476,8 +1435,8 @@ UT_TEST(test_block0_recovery_private_bad_identity_does_not_publish_disk_bytes) make_valid_block0(2, 1, 0, 0x58); memset(&guard, 0xa5, sizeof(guard)); memset(private_page, 0x6c, sizeof(private_page)); - UT_ASSERT_EQ(cluster_undo_block0_recovery_private_begin( - &logical, &root, &proof, false, &guard, private_page, &exists), + UT_ASSERT_EQ(cluster_undo_block0_recovery_private_begin(&logical, &root, &proof, false, &guard, + private_page, &exists), CLUSTER_UNDO_BLOCK0_IDENTITY_MISMATCH); UT_ASSERT(!exists); UT_ASSERT(!guard.content_x_held); @@ -1501,8 +1460,8 @@ UT_TEST(test_block0_recovery_private_absence_stays_fail_closed_without_typed_smg smgr_read_ok = false; memset(&guard, 0xa5, sizeof(guard)); memset(private_page, 0x6b, sizeof(private_page)); - UT_ASSERT_EQ(cluster_undo_block0_recovery_private_begin( - &logical, &root, &proof, true, &guard, private_page, &exists), + UT_ASSERT_EQ(cluster_undo_block0_recovery_private_begin(&logical, &root, &proof, true, &guard, + private_page, &exists), CLUSTER_UNDO_BLOCK0_IO_ERROR); UT_ASSERT(!exists); UT_ASSERT(!guard.content_x_held); @@ -1524,12 +1483,12 @@ UT_TEST(test_block0_recovery_private_finish_writes_fsyncs_and_releases_without_r fresh_block0_region(1); make_valid_block0(1, 1, 6, 0x68); - UT_ASSERT_EQ(cluster_undo_block0_recovery_private_begin( - &logical, &root, &proof, false, &guard, private_page, &exists), + UT_ASSERT_EQ(cluster_undo_block0_recovery_private_begin(&logical, &root, &proof, false, &guard, + private_page, &exists), CLUSTER_UNDO_BLOCK0_OK); private_page[BLCKSZ - 1] = (char)0xa8; - cluster_undo_block0_recovery_private_finish( - &guard, private_page, (XLogRecPtr)UINT64CONST(0xb0), true, false); + cluster_undo_block0_recovery_private_finish(&guard, private_page, (XLogRecPtr)UINT64CONST(0xb0), + true, false); UT_ASSERT_EQ(smgr_write_calls, 1); UT_ASSERT_EQ(smgr_last_write_block, 0); @@ -1539,8 +1498,7 @@ UT_TEST(test_block0_recovery_private_finish_writes_fsyncs_and_releases_without_r UT_ASSERT(!guard.content_x_held); UT_ASSERT_EQ(guard.slot, -1); memset(&frame, 0, sizeof(frame)); - UT_ASSERT_EQ(cluster_undo_block0_frame_reserve_batch(1, &frame), - CLUSTER_UNDO_BLOCK0_OK); + UT_ASSERT_EQ(cluster_undo_block0_frame_reserve_batch(1, &frame), CLUSTER_UNDO_BLOCK0_OK); cluster_undo_block0_frame_release(&frame); } @@ -1556,11 +1514,11 @@ UT_TEST(test_block0_recovery_private_finish_validated_noop_has_zero_io) fresh_block0_region(1); make_valid_block0(1, 1, 7, 0x69); - UT_ASSERT_EQ(cluster_undo_block0_recovery_private_begin( - &logical, &root, &proof, false, &guard, private_page, &exists), + UT_ASSERT_EQ(cluster_undo_block0_recovery_private_begin(&logical, &root, &proof, false, &guard, + private_page, &exists), CLUSTER_UNDO_BLOCK0_OK); - cluster_undo_block0_recovery_private_finish( - &guard, NULL, (XLogRecPtr)UINT64CONST(0xc0), false, true); + cluster_undo_block0_recovery_private_finish(&guard, NULL, (XLogRecPtr)UINT64CONST(0xc0), false, + true); UT_ASSERT_EQ(smgr_write_calls, 0); UT_ASSERT_EQ(xlog_flush_calls, 0); UT_ASSERT(!guard.content_x_held); @@ -1580,15 +1538,15 @@ UT_TEST(test_block0_recovery_private_finish_write_failure_panics_with_guard_unpu fresh_block0_region(1); make_valid_block0(1, 1, 8, 0x6a); - UT_ASSERT_EQ(cluster_undo_block0_recovery_private_begin( - &logical, &root, &proof, false, &guard, private_page, &exists), + UT_ASSERT_EQ(cluster_undo_block0_recovery_private_begin(&logical, &root, &proof, false, &guard, + private_page, &exists), CLUSTER_UNDO_BLOCK0_OK); private_page[BLCKSZ - 1] = (char)0xaa; smgr_write_ok = false; wal_error_armed = true; if (sigsetjmp(wal_error_jump, 1) == 0) - cluster_undo_block0_recovery_private_finish( - &guard, private_page, (XLogRecPtr)UINT64CONST(0xd0), true, false); + cluster_undo_block0_recovery_private_finish(&guard, private_page, + (XLogRecPtr)UINT64CONST(0xd0), true, false); else caught = true; wal_error_armed = false; @@ -1613,13 +1571,13 @@ UT_TEST(test_block0_recovery_private_parent_fsync_gap_panics_before_write) fresh_block0_region(1); make_valid_block0(1, 1, 9, 0x6b); - UT_ASSERT_EQ(cluster_undo_block0_recovery_private_begin( - &logical, &root, &proof, false, &guard, private_page, &exists), + UT_ASSERT_EQ(cluster_undo_block0_recovery_private_begin(&logical, &root, &proof, false, &guard, + private_page, &exists), CLUSTER_UNDO_BLOCK0_OK); wal_error_armed = true; if (sigsetjmp(wal_error_jump, 1) == 0) - cluster_undo_block0_recovery_private_finish( - &guard, private_page, (XLogRecPtr)UINT64CONST(0xe0), true, true); + cluster_undo_block0_recovery_private_finish(&guard, private_page, + (XLogRecPtr)UINT64CONST(0xe0), true, true); else caught = true; wal_error_armed = false; @@ -1644,18 +1602,15 @@ UT_TEST(test_block0_wal_dirty_uses_monotone_lsn_and_flushes_before_durable_data) fresh_block0_region(1); make_valid_block0(1, 1, 2, 0x47); memset(&token, 0, sizeof(token)); - UT_ASSERT_EQ(cluster_undo_block0_frame_reserve_batch(1, &token), - CLUSTER_UNDO_BLOCK0_OK); - UT_ASSERT_EQ(cluster_undo_block0_admit_runtime( - &logical, &root, &proof, &token, &pin, &page), + UT_ASSERT_EQ(cluster_undo_block0_frame_reserve_batch(1, &token), CLUSTER_UNDO_BLOCK0_OK); + UT_ASSERT_EQ(cluster_undo_block0_admit_runtime(&logical, &root, &proof, &token, &pin, &page), CLUSTER_UNDO_BLOCK0_OK); memcpy(successor, page, sizeof(successor)); successor[BLCKSZ - 1] = (char)0x94; cluster_undo_block0_mark_wal_dirty(&pin, (XLogRecPtr)UINT64CONST(0x80)); cluster_undo_block0_mark_wal_dirty(&pin, (XLogRecPtr)UINT64CONST(0x70)); - cluster_undo_block0_flush_sync(&pin, successor, - (XLogRecPtr)UINT64CONST(0x75), false); + cluster_undo_block0_flush_sync(&pin, successor, (XLogRecPtr)UINT64CONST(0x75), false); UT_ASSERT_EQ(xlog_flush_calls, 1); UT_ASSERT_EQ(xlog_last_flush_lsn, (XLogRecPtr)UINT64CONST(0x80)); @@ -1688,29 +1643,26 @@ UT_TEST(test_block0_flush_publishes_successor_generation) fresh_block0_region(1); make_valid_block0(1, 1, 2, 0x47); memset(&token, 0, sizeof(token)); - UT_ASSERT_EQ(cluster_undo_block0_frame_reserve_batch(1, &token), - CLUSTER_UNDO_BLOCK0_OK); - UT_ASSERT_EQ(cluster_undo_block0_admit_runtime( - &logical, &root, &proof, &token, &pin, &page), + UT_ASSERT_EQ(cluster_undo_block0_frame_reserve_batch(1, &token), CLUSTER_UNDO_BLOCK0_OK); + UT_ASSERT_EQ(cluster_undo_block0_admit_runtime(&logical, &root, &proof, &token, &pin, &page), CLUSTER_UNDO_BLOCK0_OK); memcpy(successor, page, sizeof(successor)); ((UndoSegmentHeaderData *)successor)->wrap_count = 3; - cluster_undo_block0_flush_sync(&pin, successor, - InvalidXLogRecPtr, false); + cluster_undo_block0_flush_sync(&pin, successor, InvalidXLogRecPtr, false); UT_ASSERT(pin.observed_generation.known); UT_ASSERT_EQ(pin.observed_generation.value, 3); cluster_undo_block0_unpin(&pin); - UT_ASSERT_EQ(cluster_undo_block0_sample_resident_generation( - &logical, &root, &proof, &sampled), CLUSTER_UNDO_BLOCK0_OK); + UT_ASSERT_EQ(cluster_undo_block0_sample_resident_generation(&logical, &root, &proof, &sampled), + CLUSTER_UNDO_BLOCK0_OK); UT_ASSERT(sampled.known); UT_ASSERT_EQ(sampled.value, 3); - UT_ASSERT_EQ(cluster_undo_block0_copy_resident( - &logical, &root, &old_generation, &proof, copied, NULL), - CLUSTER_UNDO_BLOCK0_GENERATION_MISMATCH); - UT_ASSERT_EQ(cluster_undo_block0_copy_resident( - &logical, &root, &new_generation, &proof, copied, NULL), - CLUSTER_UNDO_BLOCK0_OK); + UT_ASSERT_EQ( + cluster_undo_block0_copy_resident(&logical, &root, &old_generation, &proof, copied, NULL), + CLUSTER_UNDO_BLOCK0_GENERATION_MISMATCH); + UT_ASSERT_EQ( + cluster_undo_block0_copy_resident(&logical, &root, &new_generation, &proof, copied, NULL), + CLUSTER_UNDO_BLOCK0_OK); } UT_TEST(test_block0_flush_failure_preserves_resident_predecessor_and_dirty_lsn) @@ -1728,10 +1680,8 @@ UT_TEST(test_block0_flush_failure_preserves_resident_predecessor_and_dirty_lsn) fresh_block0_region(1); make_valid_block0(1, 1, 4, 0x48); memset(&token, 0, sizeof(token)); - UT_ASSERT_EQ(cluster_undo_block0_frame_reserve_batch(1, &token), - CLUSTER_UNDO_BLOCK0_OK); - UT_ASSERT_EQ(cluster_undo_block0_admit_runtime( - &logical, &root, &proof, &token, &pin, &page), + UT_ASSERT_EQ(cluster_undo_block0_frame_reserve_batch(1, &token), CLUSTER_UNDO_BLOCK0_OK); + UT_ASSERT_EQ(cluster_undo_block0_admit_runtime(&logical, &root, &proof, &token, &pin, &page), CLUSTER_UNDO_BLOCK0_OK); memcpy(successor, page, sizeof(successor)); successor[BLCKSZ - 1] = (char)0x98; @@ -1740,8 +1690,7 @@ UT_TEST(test_block0_flush_failure_preserves_resident_predecessor_and_dirty_lsn) wal_error_armed = true; if (sigsetjmp(wal_error_jump, 1) == 0) - cluster_undo_block0_flush_sync(&pin, successor, - (XLogRecPtr)UINT64CONST(0x85), false); + cluster_undo_block0_flush_sync(&pin, successor, (XLogRecPtr)UINT64CONST(0x85), false); else caught = true; wal_error_armed = false; @@ -1756,8 +1705,7 @@ UT_TEST(test_block0_flush_failure_preserves_resident_predecessor_and_dirty_lsn) xlog_flush_calls = 0; xlog_last_flush_lsn = InvalidXLogRecPtr; smgr_write_calls = 0; - cluster_undo_block0_flush_sync(&pin, successor, - (XLogRecPtr)UINT64CONST(0x85), false); + cluster_undo_block0_flush_sync(&pin, successor, (XLogRecPtr)UINT64CONST(0x85), false); UT_ASSERT_EQ(xlog_flush_calls, 1); UT_ASSERT_EQ(xlog_last_flush_lsn, (XLogRecPtr)UINT64CONST(0x90)); UT_ASSERT_EQ(smgr_write_calls, 1); @@ -1780,10 +1728,8 @@ UT_TEST(test_block0_flush_parent_fsync_request_fails_before_wal_or_data_publicat fresh_block0_region(1); make_valid_block0(1, 1, 5, 0x49); memset(&token, 0, sizeof(token)); - UT_ASSERT_EQ(cluster_undo_block0_frame_reserve_batch(1, &token), - CLUSTER_UNDO_BLOCK0_OK); - UT_ASSERT_EQ(cluster_undo_block0_admit_runtime( - &logical, &root, &proof, &token, &pin, &page), + UT_ASSERT_EQ(cluster_undo_block0_frame_reserve_batch(1, &token), CLUSTER_UNDO_BLOCK0_OK); + UT_ASSERT_EQ(cluster_undo_block0_admit_runtime(&logical, &root, &proof, &token, &pin, &page), CLUSTER_UNDO_BLOCK0_OK); memcpy(successor, page, sizeof(successor)); successor[BLCKSZ - 1] = (char)0x99; @@ -1791,8 +1737,7 @@ UT_TEST(test_block0_flush_parent_fsync_request_fails_before_wal_or_data_publicat wal_error_armed = true; if (sigsetjmp(wal_error_jump, 1) == 0) - cluster_undo_block0_flush_sync(&pin, successor, - (XLogRecPtr)UINT64CONST(0xa0), true); + cluster_undo_block0_flush_sync(&pin, successor, (XLogRecPtr)UINT64CONST(0xa0), true); else caught = true; wal_error_armed = false; @@ -1819,26 +1764,23 @@ UT_TEST(test_block0_flush_rejects_wrong_logical_successor_before_wal_or_data) fresh_block0_region(1); make_valid_block0(1, 1, 6, 0x4a); memset(&token, 0, sizeof(token)); - UT_ASSERT_EQ(cluster_undo_block0_frame_reserve_batch(1, &token), - CLUSTER_UNDO_BLOCK0_OK); - UT_ASSERT_EQ(cluster_undo_block0_admit_runtime( - &logical, &root, &proof, &token, &pin, &page), + UT_ASSERT_EQ(cluster_undo_block0_frame_reserve_batch(1, &token), CLUSTER_UNDO_BLOCK0_OK); + UT_ASSERT_EQ(cluster_undo_block0_admit_runtime(&logical, &root, &proof, &token, &pin, &page), CLUSTER_UNDO_BLOCK0_OK); memcpy(successor, page, sizeof(successor)); - ((UndoSegmentHeaderData *) successor)->segment_id = 2; - cluster_undo_block0_mark_wal_dirty(&pin, (XLogRecPtr) UINT64CONST(0xb0)); + ((UndoSegmentHeaderData *)successor)->segment_id = 2; + cluster_undo_block0_mark_wal_dirty(&pin, (XLogRecPtr)UINT64CONST(0xb0)); wal_error_armed = true; if (sigsetjmp(wal_error_jump, 1) == 0) - cluster_undo_block0_flush_sync(&pin, successor, - (XLogRecPtr) UINT64CONST(0xb0), false); + cluster_undo_block0_flush_sync(&pin, successor, (XLogRecPtr)UINT64CONST(0xb0), false); else caught = true; wal_error_armed = false; UT_ASSERT(caught); UT_ASSERT_EQ(xlog_flush_calls, 0); UT_ASSERT_EQ(smgr_write_calls, 0); - UT_ASSERT_EQ(((UndoSegmentHeaderData *) page)->segment_id, 1); + UT_ASSERT_EQ(((UndoSegmentHeaderData *)page)->segment_id, 1); UT_ASSERT_EQ(pin.slot, 0); cluster_undo_block0_unpin(&pin); } @@ -1863,13 +1805,12 @@ UT_TEST(test_block0_clean_census_requires_exact_complete_unpinned_residency) fresh_block0_region(2); memset(tokens, 0, sizeof(tokens)); - UT_ASSERT_EQ(cluster_undo_block0_frame_reserve_batch(2, tokens), - CLUSTER_UNDO_BLOCK0_OK); + UT_ASSERT_EQ(cluster_undo_block0_frame_reserve_batch(2, tokens), CLUSTER_UNDO_BLOCK0_OK); for (i = 0; i < 2; i++) { - make_valid_block0(logical[i].segment_id, logical[i].owner_instance, - 11 + i, (uint8)(0x51 + i)); - UT_ASSERT_EQ(cluster_undo_block0_admit_runtime( - &logical[i], &root[i], &proof, &tokens[i], &pin, &page), + make_valid_block0(logical[i].segment_id, logical[i].owner_instance, 11 + i, + (uint8)(0x51 + i)); + UT_ASSERT_EQ(cluster_undo_block0_admit_runtime(&logical[i], &root[i], &proof, &tokens[i], + &pin, &page), CLUSTER_UNDO_BLOCK0_OK); memset(&items[i], 0, sizeof(items[i])); items[i].logical = logical[i]; @@ -1899,9 +1840,9 @@ UT_TEST(test_block0_clean_census_requires_exact_complete_unpinned_residency) CLUSTER_UNDO_BLOCK0_OK); UT_ASSERT(!cluster_undo_block0_verify_clean_census(items, 2)); expected = items[0].generation; - UT_ASSERT_EQ(cluster_undo_block0_lock_content( - &pin, &expected, CLUSTER_UNDO_BLOCK0_EXCLUSIVE, &page), - CLUSTER_UNDO_BLOCK0_OK); + UT_ASSERT_EQ( + cluster_undo_block0_lock_content(&pin, &expected, CLUSTER_UNDO_BLOCK0_EXCLUSIVE, &page), + CLUSTER_UNDO_BLOCK0_OK); cluster_undo_block0_mark_wal_dirty(&pin, (XLogRecPtr)UINT64CONST(0xb0)); cluster_undo_block0_unpin(&pin); UT_ASSERT(!cluster_undo_block0_verify_clean_census(items, 2)); @@ -2105,8 +2046,7 @@ UT_TEST(test_r4_prerequisite_snapshot_is_fixed_for_concurrent_callers) calls += results[i].calls; mismatches += results[i].mismatches; } - UT_ASSERT_EQ(calls, - R4_PREREQUISITE_THREAD_COUNT * R4_PREREQUISITE_CALLS_PER_THREAD); + UT_ASSERT_EQ(calls, R4_PREREQUISITE_THREAD_COUNT * R4_PREREQUISITE_CALLS_PER_THREAD); UT_ASSERT_EQ(mismatches, 0); } diff --git a/src/test/cluster_unit/test_cluster_undo_block0_current.c b/src/test/cluster_unit/test_cluster_undo_block0_current.c index 2b432a56542..4edf6c5629d 100644 --- a/src/test/cluster_unit/test_cluster_undo_block0_current.c +++ b/src/test/cluster_unit/test_cluster_undo_block0_current.c @@ -2763,7 +2763,7 @@ UT_TEST(test_exclusive_pin_refuses_scur_and_nonheld_without_publishing_outputs) reset_fixture(); memset(&pin, 0xa5, sizeof(pin)); - sentinel = pin; + memcpy(&sentinel, &pin, sizeof(sentinel)); UT_ASSERT_EQ(cluster_undo_block0_current_pin_exclusive(&guard, &root, &expected, &pin, &page), CLUSTER_UNDO_BLOCK0_AUTHORITY_DENIED); UT_ASSERT_EQ(memcmp(&pin, &sentinel, sizeof(pin)), 0); @@ -2792,7 +2792,7 @@ UT_TEST(test_exclusive_pin_post_pin_drift_unpins_before_refusal_and_keeps_output acquire_remote_xcur_held(&guard); fake_pin_invalidates_authority = true; memset(&pin, 0xa5, sizeof(pin)); - sentinel = pin; + memcpy(&sentinel, &pin, sizeof(sentinel)); UT_ASSERT_EQ(cluster_undo_block0_current_pin_exclusive(&guard, &root, &expected, &pin, &page), CLUSTER_UNDO_BLOCK0_AUTHORITY_DENIED); UT_ASSERT_EQ(pin_calls, 1); diff --git a/src/test/cluster_unit/test_cluster_undo_buf.c b/src/test/cluster_unit/test_cluster_undo_buf.c index 0b5ea7e003e..605c159b64d 100644 --- a/src/test/cluster_unit/test_cluster_undo_buf.c +++ b/src/test/cluster_unit/test_cluster_undo_buf.c @@ -78,6 +78,21 @@ int cluster_node_id = 0; /* Linked block-zero observer is not called by this DATA-pool fixture. */ bool IsUnderPostmaster = false; BackendType MyBackendType = B_INVALID; +AuxProcType MyAuxProcType = NotAnAuxProcess; + +bool +cluster_semantic_normal_start_closed(void) +{ + /* This DATA-pool fixture cannot assert a normal-start barrier. */ + return false; +} + +uint64 +GetSystemIdentifier(void) +{ + /* Resolving a startup root is outside this DATA-pool test. */ + abort(); +} ClusterR4PrerequisiteSnapshot cluster_reconfig_r4_prerequisite_snapshot(void) @@ -104,42 +119,38 @@ cluster_undo_block0_current_startup_fenced_owned(void) } ClusterUndoSmgrFinalState -cluster_undo_smgr_probe_segment( - ClusterUndoPathIntent intent pg_attribute_unused(), - uint32 segment_id pg_attribute_unused(), - uint8 owner_instance pg_attribute_unused(), - char block0[BLCKSZ] pg_attribute_unused()) +cluster_undo_smgr_probe_segment(ClusterUndoPathIntent intent pg_attribute_unused(), + uint32 segment_id pg_attribute_unused(), + uint8 owner_instance pg_attribute_unused(), + char block0[BLCKSZ] pg_attribute_unused()) { return CLUSTER_UNDO_SMGR_FINAL_ABSENT; } bool -cluster_undo_smgr_provision_temp_create( - ClusterUndoPathIntent intent pg_attribute_unused(), - uint32 segment_id pg_attribute_unused(), - uint8 owner_instance pg_attribute_unused(), - char temp_path[MAXPGPATH] pg_attribute_unused()) +cluster_undo_smgr_provision_temp_create(ClusterUndoPathIntent intent pg_attribute_unused(), + uint32 segment_id pg_attribute_unused(), + uint8 owner_instance pg_attribute_unused(), + char temp_path[MAXPGPATH] pg_attribute_unused()) { return false; } ClusterUndoSmgrPublishResult -cluster_undo_smgr_provision_temp_publish( - ClusterUndoPathIntent intent pg_attribute_unused(), - uint32 segment_id pg_attribute_unused(), - uint8 owner_instance pg_attribute_unused(), - const char *temp_path pg_attribute_unused(), - const char block0[BLCKSZ] pg_attribute_unused()) +cluster_undo_smgr_provision_temp_publish(ClusterUndoPathIntent intent pg_attribute_unused(), + uint32 segment_id pg_attribute_unused(), + uint8 owner_instance pg_attribute_unused(), + const char *temp_path pg_attribute_unused(), + const char block0[BLCKSZ] pg_attribute_unused()) { return CLUSTER_UNDO_SMGR_PUBLISH_IO_ERROR; } bool -cluster_undo_smgr_provision_temp_cleanup( - ClusterUndoPathIntent intent pg_attribute_unused(), - uint32 segment_id pg_attribute_unused(), - uint8 owner_instance pg_attribute_unused(), - const char *temp_path pg_attribute_unused()) +cluster_undo_smgr_provision_temp_cleanup(ClusterUndoPathIntent intent pg_attribute_unused(), + uint32 segment_id pg_attribute_unused(), + uint8 owner_instance pg_attribute_unused(), + const char *temp_path pg_attribute_unused()) { return false; } @@ -240,8 +251,7 @@ LWLockRelease(LWLock *lock) bool LWLockConditionalAcquire(LWLock *lock, LWLockMode mode pg_attribute_unused()) { - if (!undo_test_conditional_acquire_allowed - || undo_test_conditionally_held_lock != NULL) + if (!undo_test_conditional_acquire_allowed || undo_test_conditionally_held_lock != NULL) return false; undo_test_conditionally_held_lock = lock; return true; @@ -584,14 +594,12 @@ UT_TEST(test_undo_buf_region_keeps_data_and_block0_frame_capacity_separate) /* Fill and retain every ordinary DATA slot. */ for (uint32 block = 1; block <= 4; block++) { - img = cluster_undo_buf_pin(1, 0, block, CLUSTER_UNDO_BUF_SHARED, - &data_pins[block - 1]); + img = cluster_undo_buf_pin(1, 0, block, CLUSTER_UNDO_BUF_SHARED, &data_pins[block - 1]); UT_ASSERT_NOT_NULL(img); } /* The separate block0 bank still owns all B=D frames. */ - UT_ASSERT_EQ(cluster_undo_block0_frame_reserve_batch(4, block0_tokens), - CLUSTER_UNDO_BLOCK0_OK); + UT_ASSERT_EQ(cluster_undo_block0_frame_reserve_batch(4, block0_tokens), CLUSTER_UNDO_BLOCK0_OK); UT_ASSERT_EQ(cluster_undo_block0_frame_reserve_batch(1, &extra), CLUSTER_UNDO_BLOCK0_CAPACITY_UNAVAILABLE); for (int i = 0; i < 4; i++) { diff --git a/src/test/cluster_unit/test_cluster_undo_format.c b/src/test/cluster_unit/test_cluster_undo_format.c index 7b665ba715d..0d971e33a81 100644 --- a/src/test/cluster_unit/test_cluster_undo_format.c +++ b/src/test/cluster_unit/test_cluster_undo_format.c @@ -180,18 +180,13 @@ UT_TEST(test_block_has_space) UT_TEST(test_record_slot_range_stays_inside_data_region) { - UT_ASSERT(cluster_undo_record_slot_range_valid(1, 0, - sizeof(UndoBlockHeader), 64)); - UT_ASSERT(!cluster_undo_record_slot_range_valid(0, 0, - sizeof(UndoBlockHeader), 64)); - UT_ASSERT(!cluster_undo_record_slot_range_valid(1, 1, - sizeof(UndoBlockHeader), 64)); - UT_ASSERT(!cluster_undo_record_slot_range_valid(UINT16_MAX, 0, - sizeof(UndoBlockHeader), 64)); + UT_ASSERT(cluster_undo_record_slot_range_valid(1, 0, sizeof(UndoBlockHeader), 64)); + UT_ASSERT(!cluster_undo_record_slot_range_valid(0, 0, sizeof(UndoBlockHeader), 64)); + UT_ASSERT(!cluster_undo_record_slot_range_valid(1, 1, sizeof(UndoBlockHeader), 64)); + UT_ASSERT(!cluster_undo_record_slot_range_valid(UINT16_MAX, 0, sizeof(UndoBlockHeader), 64)); UT_ASSERT(!cluster_undo_record_slot_range_valid(1, 0, BLCKSZ - 32, 64)); UT_ASSERT(!cluster_undo_record_slot_range_valid(1, 0, BLCKSZ - 8, 8)); - UT_ASSERT(!cluster_undo_record_slot_range_valid(1, 0, - sizeof(UndoBlockHeader) - 1, 64)); + UT_ASSERT(!cluster_undo_record_slot_range_valid(1, 0, sizeof(UndoBlockHeader) - 1, 64)); } diff --git a/src/test/cluster_unit/test_cluster_undo_record.c b/src/test/cluster_unit/test_cluster_undo_record.c index 8fe578ba2bf..36989636111 100644 --- a/src/test/cluster_unit/test_cluster_undo_record.c +++ b/src/test/cluster_unit/test_cluster_undo_record.c @@ -1309,7 +1309,7 @@ UT_TEST(test_full_undo_pool_selects_exact_recyclable_supply_without_rewrite) UT_TEST(test_allocated_nonempty_tt_is_not_fresh_supply) { ClusterUndoSegmentExtendPlan plan; - TTSlot old_slot = {0}; + TTSlot old_slot = { 0 }; TTSlot observed; char path[MAXPGPATH]; int fd; @@ -1325,13 +1325,15 @@ UT_TEST(test_allocated_nonempty_tt_is_not_fresh_supply) fd = open(path, O_RDWR); UT_ASSERT(fd >= 0); if (fd >= 0) { - UT_ASSERT_EQ(pwrite(fd, &old_slot, sizeof(old_slot), - offsetof(UndoSegmentHeaderData, tt_slots)), sizeof(old_slot)); + UT_ASSERT_EQ( + pwrite(fd, &old_slot, sizeof(old_slot), offsetof(UndoSegmentHeaderData, tt_slots)), + sizeof(old_slot)); UT_ASSERT(cluster_undo_segment_extend_or_create(1, &plan)); UT_ASSERT_EQ(plan.segment_id, 2); UT_ASSERT(!plan.needs_reuse); - UT_ASSERT_EQ(pread(fd, &observed, sizeof(observed), - offsetof(UndoSegmentHeaderData, tt_slots)), sizeof(observed)); + UT_ASSERT_EQ( + pread(fd, &observed, sizeof(observed), offsetof(UndoSegmentHeaderData, tt_slots)), + sizeof(observed)); UT_ASSERT_EQ(memcmp(&observed, &old_slot, sizeof(old_slot)), 0); close(fd); } @@ -2950,10 +2952,11 @@ UT_TEST(test_update_toast_releases_outer_receipt_before_nested_producers) UT_TEST(test_update_itl_wait_returns_through_receipt_and_page_requalification) { char *source = read_heapam_source(); - char *compact = malloc(strlen(source) + 1); + char *compact = source != NULL ? malloc(strlen(source) + 1) : NULL; char *write = compact; const char *read; - char *update = strstr(source, "\nheap_update(Relation "); + char *update = source != NULL ? strstr(source, "\nheap_update(Relation ") : NULL; + char *update_end = update != NULL ? strstr(update, "\n}\n") : NULL; char *deadline = update ? strstr(update, "itl_capacity_absolute_deadline_us = 0;") : NULL; char *wait = update ? strstr(update, "\nl_pgrac_itl_capacity_wait:") : NULL; char *old_full = update ? strstr(update, "itl_capacity_wait_buffer = buffer;") : NULL; @@ -2964,7 +2967,14 @@ UT_TEST(test_update_itl_wait_returns_through_receipt_and_page_requalification) char *same_page = receipt ? strstr(receipt, "goto l2;") : NULL; /* This is an adjacency contract, not a clang-format indentation contract. */ + UT_ASSERT_NOT_NULL(source); UT_ASSERT_NOT_NULL(compact); + UT_ASSERT_NOT_NULL(update_end); + if (compact == NULL || update_end == NULL) { + free(compact); + free(source); + return; + } for (read = source; *read; read++) if (!isspace((unsigned char)*read)) *write++ = *read; @@ -2980,8 +2990,11 @@ UT_TEST(test_update_itl_wait_returns_through_receipt_and_page_requalification) UT_ASSERT_NOT_NULL(receipt); UT_ASSERT_NOT_NULL(reacquire); UT_ASSERT_NOT_NULL(same_page); - if (deadline && wait) - UT_ASSERT(strstr(deadline + 1, "itl_capacity_absolute_deadline_us = 0;") == NULL); + if (deadline && wait) { + const char *next_deadline = strstr(deadline + 1, "itl_capacity_absolute_deadline_us = 0;"); + UT_ASSERT(deadline < update_end && wait < update_end); + UT_ASSERT(next_deadline == NULL || next_deadline > update_end); + } free(compact); free(source); } diff --git a/src/test/cluster_unit/test_cluster_undo_root_descriptor.c b/src/test/cluster_unit/test_cluster_undo_root_descriptor.c index 6ce478b2f9b..c0d109dabab 100644 --- a/src/test/cluster_unit/test_cluster_undo_root_descriptor.c +++ b/src/test/cluster_unit/test_cluster_undo_root_descriptor.c @@ -75,16 +75,12 @@ UT_TEST(test_pgrd_v1_exact_layout_and_roundtrip) ClusterUndoRootDescriptorV1 descriptor = valid_shared_descriptor(); ClusterUndoRootDescriptorV1 decoded; uint8 image[CLUSTER_UNDO_ROOT_DESCRIPTOR_BYTES]; - static const uint8 expected_prefix[64] = { - 0x44, 0x52, 0x47, 0x50, 0x01, 0x00, 0x40, 0x00, - 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, - 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, - 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x88, 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11 - }; + static const uint8 expected_prefix[64] + = { 0x44, 0x52, 0x47, 0x50, 0x01, 0x00, 0x40, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, + 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x88, 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11 }; int i; memset(image, 0xa5, sizeof(image)); @@ -98,16 +94,13 @@ UT_TEST(test_pgrd_v1_exact_layout_and_roundtrip) UT_ASSERT_EQ(image[511], 0x88); memset(&decoded, 0, sizeof(decoded)); - UT_ASSERT_EQ(cluster_undo_root_descriptor_decode( - image, descriptor.system_identifier, &decoded), - CLUSTER_UNDO_ROOT_DESCRIPTOR_VALID); - UT_ASSERT_EQ(decoded.descriptor_incarnation, - descriptor.descriptor_incarnation); + UT_ASSERT_EQ(cluster_undo_root_descriptor_decode(image, descriptor.system_identifier, &decoded), + CLUSTER_UNDO_ROOT_DESCRIPTOR_VALID); + UT_ASSERT_EQ(decoded.descriptor_incarnation, descriptor.descriptor_incarnation); UT_ASSERT_EQ(decoded.root_kind, descriptor.root_kind); UT_ASSERT_EQ(decoded.owner_node, descriptor.owner_node); UT_ASSERT_EQ(decoded.root_ordinal, descriptor.root_ordinal); - UT_ASSERT_EQ(memcmp(decoded.root_uuid, descriptor.root_uuid, - CLUSTER_UNDO_ROOT_UUID_BYTES), 0); + UT_ASSERT_EQ(memcmp(decoded.root_uuid, descriptor.root_uuid, CLUSTER_UNDO_ROOT_UUID_BYTES), 0); UT_ASSERT_EQ(decoded.namespace_id, descriptor.namespace_id); UT_ASSERT_EQ(decoded.system_identifier, descriptor.system_identifier); } @@ -124,26 +117,23 @@ UT_TEST(test_pgrd_v1_zero_and_corruption_fail_closed_without_output) memset(&sentinel, 0x5a, sizeof(sentinel)); memset(zero, 0, sizeof(zero)); decoded = sentinel; - UT_ASSERT_EQ(cluster_undo_root_descriptor_decode( - zero, descriptor.system_identifier, &decoded), - CLUSTER_UNDO_ROOT_DESCRIPTOR_UNPROVISIONED); + UT_ASSERT_EQ(cluster_undo_root_descriptor_decode(zero, descriptor.system_identifier, &decoded), + CLUSTER_UNDO_ROOT_DESCRIPTOR_UNPROVISIONED); UT_ASSERT_EQ(memcmp(&decoded, &sentinel, sizeof(decoded)), 0); UT_ASSERT(cluster_undo_root_descriptor_encode(&descriptor, image)); image[32] ^= UINT8_C(1); decoded = sentinel; - UT_ASSERT_EQ(cluster_undo_root_descriptor_decode( - image, descriptor.system_identifier, &decoded), - CLUSTER_UNDO_ROOT_DESCRIPTOR_HOLD); + UT_ASSERT_EQ(cluster_undo_root_descriptor_decode(image, descriptor.system_identifier, &decoded), + CLUSTER_UNDO_ROOT_DESCRIPTOR_HOLD); UT_ASSERT_EQ(memcmp(&decoded, &sentinel, sizeof(decoded)), 0); UT_ASSERT(cluster_undo_root_descriptor_encode(&descriptor, image)); image[64] = UINT8_C(1); set_image_crc(image); decoded = sentinel; - UT_ASSERT_EQ(cluster_undo_root_descriptor_decode( - image, descriptor.system_identifier, &decoded), - CLUSTER_UNDO_ROOT_DESCRIPTOR_HOLD); + UT_ASSERT_EQ(cluster_undo_root_descriptor_decode(image, descriptor.system_identifier, &decoded), + CLUSTER_UNDO_ROOT_DESCRIPTOR_HOLD); UT_ASSERT_EQ(memcmp(&decoded, &sentinel, sizeof(decoded)), 0); } @@ -160,33 +150,30 @@ UT_TEST(test_pgrd_v1_identity_relations_fail_closed) memset(image + 32, 0, CLUSTER_UNDO_ROOT_UUID_BYTES); set_image_crc(image); decoded = sentinel; - UT_ASSERT_EQ(cluster_undo_root_descriptor_decode( - image, descriptor.system_identifier, &decoded), - CLUSTER_UNDO_ROOT_DESCRIPTOR_HOLD); + UT_ASSERT_EQ(cluster_undo_root_descriptor_decode(image, descriptor.system_identifier, &decoded), + CLUSTER_UNDO_ROOT_DESCRIPTOR_HOLD); UT_ASSERT_EQ(memcmp(&decoded, &sentinel, sizeof(decoded)), 0); UT_ASSERT(cluster_undo_root_descriptor_encode(&descriptor, image)); image[16] = CLUSTER_UNDO_ROOT_KIND_LOCAL; set_image_crc(image); decoded = sentinel; - UT_ASSERT_EQ(cluster_undo_root_descriptor_decode( - image, descriptor.system_identifier, &decoded), - CLUSTER_UNDO_ROOT_DESCRIPTOR_HOLD); + UT_ASSERT_EQ(cluster_undo_root_descriptor_decode(image, descriptor.system_identifier, &decoded), + CLUSTER_UNDO_ROOT_DESCRIPTOR_HOLD); UT_ASSERT_EQ(memcmp(&decoded, &sentinel, sizeof(decoded)), 0); UT_ASSERT(cluster_undo_root_descriptor_encode(&descriptor, image)); image[48] = UINT8_C(2); set_image_crc(image); decoded = sentinel; - UT_ASSERT_EQ(cluster_undo_root_descriptor_decode( - image, descriptor.system_identifier, &decoded), - CLUSTER_UNDO_ROOT_DESCRIPTOR_HOLD); + UT_ASSERT_EQ(cluster_undo_root_descriptor_decode(image, descriptor.system_identifier, &decoded), + CLUSTER_UNDO_ROOT_DESCRIPTOR_HOLD); UT_ASSERT_EQ(memcmp(&decoded, &sentinel, sizeof(decoded)), 0); UT_ASSERT(cluster_undo_root_descriptor_encode(&descriptor, image)); decoded = sentinel; - UT_ASSERT_EQ(cluster_undo_root_descriptor_decode( - image, descriptor.system_identifier + 1, &decoded), + UT_ASSERT_EQ( + cluster_undo_root_descriptor_decode(image, descriptor.system_identifier + 1, &decoded), CLUSTER_UNDO_ROOT_DESCRIPTOR_HOLD); UT_ASSERT_EQ(memcmp(&decoded, &sentinel, sizeof(decoded)), 0); } @@ -233,12 +220,10 @@ UT_TEST(test_pgrd_formula_rejects_invalid_and_exhausted_inputs) UT_ASSERT_EQ(namespace_id, UINT64_C(0x5a5a5a5a5a5a5a5a)); UT_ASSERT(!cluster_undo_root_namespace_id(1, 129, &namespace_id)); UT_ASSERT_EQ(namespace_id, UINT64_C(0x5a5a5a5a5a5a5a5a)); - UT_ASSERT(cluster_undo_root_namespace_id( - UINT64_C(4363953127297), 0, &namespace_id)); + UT_ASSERT(cluster_undo_root_namespace_id(UINT64_C(4363953127297), 0, &namespace_id)); UT_ASSERT_EQ(namespace_id, UINT64_C(562949953421185)); namespace_id = UINT64_C(0x5a5a5a5a5a5a5a5a); - UT_ASSERT(!cluster_undo_root_namespace_id( - UINT64_C(4363953127298), 0, &namespace_id)); + UT_ASSERT(!cluster_undo_root_namespace_id(UINT64_C(4363953127298), 0, &namespace_id)); UT_ASSERT_EQ(namespace_id, UINT64_C(0x5a5a5a5a5a5a5a5a)); UT_ASSERT(!cluster_undo_root_file_slot(0, 0, &file_slot)); @@ -250,8 +235,7 @@ UT_TEST(test_pgrd_formula_rejects_invalid_and_exhausted_inputs) UT_ASSERT(!cluster_undo_root_id(0, 0, &root_id)); UT_ASSERT_EQ(root_id, UINT64_C(0x6b6b6b6b6b6b6b6b)); - UT_ASSERT(!cluster_undo_root_id( - UINT64_C(562949953421312), 0, &root_id)); + UT_ASSERT(!cluster_undo_root_id(UINT64_C(562949953421312), 0, &root_id)); UT_ASSERT_EQ(root_id, UINT64_C(0x6b6b6b6b6b6b6b6b)); UT_ASSERT(!cluster_undo_root_id(1, UINT32_C(32768), &root_id)); UT_ASSERT_EQ(root_id, UINT64_C(0x6b6b6b6b6b6b6b6b)); @@ -266,17 +250,15 @@ UT_TEST(test_pgrd_descriptor_resolves_exact_block0_root) ClusterUndoBlock0ResolvedRoot local; ClusterUndoBlock0ResolvedRoot sentinel; - UT_ASSERT(cluster_undo_root_descriptor_resolve( - &descriptor, CLUSTER_UNDO_PATH_RUNTIME_SHARED, 1, 1, &shared)); + UT_ASSERT(cluster_undo_root_descriptor_resolve(&descriptor, CLUSTER_UNDO_PATH_RUNTIME_SHARED, 1, + 1, &shared)); UT_ASSERT_EQ(shared.intent, CLUSTER_UNDO_PATH_RUNTIME_SHARED); UT_ASSERT_EQ(shared.root_id, UINT64_C(32768)); UT_ASSERT_EQ(shared.root_generation, UINT64_C(1)); UT_ASSERT(cluster_undo_root_descriptor_resolve( - &descriptor, CLUSTER_UNDO_PATH_RUNTIME_SHARED_AUTHORITY_BLOCK0, - 1, 1, &authority)); - UT_ASSERT_EQ(authority.intent, - CLUSTER_UNDO_PATH_RUNTIME_SHARED_AUTHORITY_BLOCK0); + &descriptor, CLUSTER_UNDO_PATH_RUNTIME_SHARED_AUTHORITY_BLOCK0, 1, 1, &authority)); + UT_ASSERT_EQ(authority.intent, CLUSTER_UNDO_PATH_RUNTIME_SHARED_AUTHORITY_BLOCK0); UT_ASSERT_EQ(authority.root_id, shared.root_id); UT_ASSERT_EQ(authority.root_generation, shared.root_generation); @@ -292,8 +274,8 @@ UT_TEST(test_pgrd_descriptor_resolves_exact_block0_root) memset(&sentinel, 0x5a, sizeof(sentinel)); local = sentinel; - UT_ASSERT(!cluster_undo_root_descriptor_resolve( - &descriptor, CLUSTER_UNDO_PATH_RUNTIME_SHARED, 2, 264, &local)); + UT_ASSERT(!cluster_undo_root_descriptor_resolve(&descriptor, CLUSTER_UNDO_PATH_RUNTIME_SHARED, + 2, 264, &local)); UT_ASSERT_EQ(memcmp(&local, &sentinel, sizeof(local)), 0); } diff --git a/src/test/cluster_unit/test_cluster_undo_segment_half_page_oversized.c b/src/test/cluster_unit/test_cluster_undo_segment_half_page_oversized.c index 205e1d116f1..ea09969f49b 100644 --- a/src/test/cluster_unit/test_cluster_undo_segment_half_page_oversized.c +++ b/src/test/cluster_unit/test_cluster_undo_segment_half_page_oversized.c @@ -17,6 +17,8 @@ #include "cluster/cluster_tt_slot.h" typedef struct ClusterUndoOversizedHalfPageFixture { + /* Layout-only prefix is required by the negative offsetof assertion. */ + /* cppcheck-suppress unusedStructMember */ char prefix[112]; TTSlot tt_slots[125]; } ClusterUndoOversizedHalfPageFixture; diff --git a/src/test/cluster_unit/test_cluster_undo_smgr_publication.c b/src/test/cluster_unit/test_cluster_undo_smgr_publication.c index 59540b7ded0..23a14304a75 100644 --- a/src/test/cluster_unit/test_cluster_undo_smgr_publication.c +++ b/src/test/cluster_unit/test_cluster_undo_smgr_publication.c @@ -75,106 +75,110 @@ errfinish(const char *file, int line, const char *function) abort(); } -void cluster_undo_record_note_smgr_open(void) {} -void cluster_undo_record_note_smgr_close(void) {} -void cluster_undo_record_note_smgr_pread(void) {} -void cluster_undo_record_note_smgr_pwrite(void) {} +void +cluster_undo_record_note_smgr_open(void) +{} +void +cluster_undo_record_note_smgr_close(void) +{} +void +cluster_undo_record_note_smgr_pread(void) +{} +void +cluster_undo_record_note_smgr_pwrite(void) +{} void -ExceptionalCondition(const char *conditionName, const char *fileName, - int lineNumber) +ExceptionalCondition(const char *conditionName, const char *fileName, int lineNumber) { - fprintf(stderr, "assertion failed: %s at %s:%d\n", conditionName, - fileName, lineNumber); - abort(); + fprintf(stderr, "assertion failed: %s at %s:%d\n", conditionName, fileName, lineNumber); + abort(); } int BasicOpenFile(const char *fileName, int fileFlags) { - if (basic_open_forced_error) { - errno = EACCES; - return -1; - } - if (basic_open_swap_to_symlink) { - basic_open_swap_to_symlink = false; - UT_ASSERT_EQ(unlink(fileName), 0); - UT_ASSERT_EQ(symlink(basic_open_swap_target, fileName), 0); - } - return open(fileName, fileFlags, pg_file_create_mode); + if (basic_open_forced_error) { + errno = EACCES; + return -1; + } + if (basic_open_swap_to_symlink) { + basic_open_swap_to_symlink = false; + UT_ASSERT_EQ(unlink(fileName), 0); + UT_ASSERT_EQ(symlink(basic_open_swap_target, fileName), 0); + } + return open(fileName, fileFlags, pg_file_create_mode); } DIR * AllocateDir(const char *dirname) { - return opendir(dirname); + return opendir(dirname); } int FreeDir(DIR *dir) { - int result = closedir(dir); + int result = closedir(dir); - if (result == 0 && free_dir_forced_error) { - errno = EIO; - return -1; - } - return result; + if (result == 0 && free_dir_forced_error) { + errno = EIO; + return -1; + } + return result; } int pg_fsync(int fd) { - fsync_calls++; - if (fsync_fail_on_call > 0 && fsync_calls == fsync_fail_on_call) { - errno = EIO; - return -1; - } - return fsync(fd); + fsync_calls++; + if (fsync_fail_on_call > 0 && fsync_calls == fsync_fail_on_call) { + errno = EIO; + return -1; + } + return fsync(fd); } static ssize_t test_product_pwrite(int fd, const void *buf, size_t nbytes, off_t offset) { - if (pwrite_forced_error) { - errno = EIO; - return -1; - } - return pwrite(fd, buf, nbytes, offset); + if (pwrite_forced_error) { + errno = EIO; + return -1; + } + return pwrite(fd, buf, nbytes, offset); } static int test_product_close(int fd) { - int result; + int result; - product_close_calls++; - result = close(fd); - if (result == 0 && product_close_fail_on_call > 0 - && product_close_calls == product_close_fail_on_call) { - errno = EIO; - return -1; - } - return result; + product_close_calls++; + result = close(fd); + if (result == 0 && product_close_fail_on_call > 0 + && product_close_calls == product_close_fail_on_call) { + errno = EIO; + return -1; + } + return result; } int -cluster_undo_path_resolve(ClusterUndoPathIntent intent pg_attribute_unused(), - uint8 owner_instance, uint32 segment_id, char *buf, - size_t buf_size) +cluster_undo_path_resolve(ClusterUndoPathIntent intent pg_attribute_unused(), uint8 owner_instance, + uint32 segment_id, char *buf, size_t buf_size) { - int ret = snprintf(buf, buf_size, "%s/seg_%u.dat", publication_dir, - (unsigned) segment_id); + int ret = snprintf(buf, buf_size, "%s/seg_%u.dat", publication_dir, (unsigned)segment_id); - return ret < 0 || (size_t) ret >= buf_size ? -1 : 0; + return ret < 0 || (size_t)ret >= buf_size ? -1 : 0; } bool cluster_undo_segment_header_identity_ok(const char *blockbuf, - uint32 segment_id pg_attribute_unused(), - uint8 owner_instance pg_attribute_unused()) + uint32 segment_id pg_attribute_unused(), + uint8 owner_instance pg_attribute_unused()) { - return blockbuf != NULL && (unsigned char) blockbuf[0] == 0xa5; + return blockbuf != NULL && (unsigned char)blockbuf[0] == 0xa5; } #undef pg_pwrite @@ -187,563 +191,528 @@ cluster_undo_segment_header_identity_ok(const char *blockbuf, static void resolve_final(char path[MAXPGPATH]) { - UT_ASSERT_EQ(cluster_undo_path_resolve(CLUSTER_UNDO_PATH_RUNTIME_SHARED, - 1, 1, path, MAXPGPATH), 0); + UT_ASSERT_EQ(cluster_undo_path_resolve(CLUSTER_UNDO_PATH_RUNTIME_SHARED, 1, 1, path, MAXPGPATH), + 0); } static void remove_if_present(const char *path) { - if (path != NULL && path[0] != '\0') - (void) unlink(path); + if (path != NULL && path[0] != '\0') + (void)unlink(path); } static void write_segment_file(const char *path, const char *block0, off_t size) { - int fd = open(path, O_RDWR | O_CREAT | O_EXCL | PG_BINARY, - pg_file_create_mode); + int fd = open(path, O_RDWR | O_CREAT | O_EXCL | PG_BINARY, pg_file_create_mode); - UT_ASSERT(fd >= 0); - UT_ASSERT_EQ(ftruncate(fd, size), 0); - if (size >= BLCKSZ) - UT_ASSERT_EQ(pwrite(fd, block0, BLCKSZ, 0), BLCKSZ); - UT_ASSERT_EQ(close(fd), 0); + UT_ASSERT(fd >= 0); + UT_ASSERT_EQ(ftruncate(fd, size), 0); + if (size >= BLCKSZ) + UT_ASSERT_EQ(pwrite(fd, block0, BLCKSZ, 0), BLCKSZ); + UT_ASSERT_EQ(close(fd), 0); } static void write_empty_file(const char *path) { - int fd = open(path, O_WRONLY | O_CREAT | O_EXCL | PG_BINARY, - pg_file_create_mode); + int fd = open(path, O_WRONLY | O_CREAT | O_EXCL | PG_BINARY, pg_file_create_mode); - UT_ASSERT(fd >= 0); - UT_ASSERT_EQ(close(fd), 0); + UT_ASSERT(fd >= 0); + UT_ASSERT_EQ(close(fd), 0); } static void make_page(char page[BLCKSZ], unsigned char marker) { - memset(page, 0, BLCKSZ); - page[0] = (char) marker; - page[BLCKSZ - 1] = (char) (marker ^ 0xff); + memset(page, 0, BLCKSZ); + page[0] = (char)marker; + page[BLCKSZ - 1] = (char)(marker ^ 0xff); } static void resolve_root_descriptor(char path[MAXPGPATH]) { - UT_ASSERT(snprintf(path, MAXPGPATH, "%s/pgrac_undo_root.control", - publication_dir) < MAXPGPATH); + UT_ASSERT(snprintf(path, MAXPGPATH, "%s/pgrac_undo_root.control", publication_dir) < MAXPGPATH); } static int count_root_descriptor_temps(void) { - DIR *dir = opendir(publication_dir); - struct dirent *entry; - int count = 0; + DIR *dir = opendir(publication_dir); + struct dirent *entry; + int count = 0; - UT_ASSERT_NOT_NULL(dir); - if (dir == NULL) - return -1; - while ((entry = readdir(dir)) != NULL) { - if (strstr(entry->d_name, "pgrac_undo_root.control.pgrac-rdtmp.") - == entry->d_name) - count++; - } - UT_ASSERT_EQ(closedir(dir), 0); - return count; + UT_ASSERT_NOT_NULL(dir); + if (dir == NULL) + return -1; + while ((entry = readdir(dir)) != NULL) { + if (strstr(entry->d_name, "pgrac_undo_root.control.pgrac-rdtmp.") == entry->d_name) + count++; + } + UT_ASSERT_EQ(closedir(dir), 0); + return count; } UT_TEST(test_probe_distinguishes_absent_and_preserves_output) { - char final[MAXPGPATH]; - char page[BLCKSZ]; + char final[MAXPGPATH]; + char page[BLCKSZ]; - resolve_final(final); - remove_if_present(final); - memset(page, 0x6d, sizeof(page)); - UT_ASSERT_EQ(cluster_undo_smgr_probe_segment( - CLUSTER_UNDO_PATH_RUNTIME_SHARED, 1, 1, page), - CLUSTER_UNDO_SMGR_FINAL_ABSENT); - UT_ASSERT_EQ((unsigned char) page[0], 0x6d); - UT_ASSERT_EQ((unsigned char) page[BLCKSZ - 1], 0x6d); + resolve_final(final); + remove_if_present(final); + memset(page, 0x6d, sizeof(page)); + UT_ASSERT_EQ(cluster_undo_smgr_probe_segment(CLUSTER_UNDO_PATH_RUNTIME_SHARED, 1, 1, page), + CLUSTER_UNDO_SMGR_FINAL_ABSENT); + UT_ASSERT_EQ((unsigned char)page[0], 0x6d); + UT_ASSERT_EQ((unsigned char)page[BLCKSZ - 1], 0x6d); } UT_TEST(test_probe_accepts_only_exact_full_identity) { - char final[MAXPGPATH]; - char expected[BLCKSZ]; - char observed[BLCKSZ]; + char final[MAXPGPATH]; + char expected[BLCKSZ]; + char observed[BLCKSZ]; - resolve_final(final); - remove_if_present(final); - make_page(expected, 0xa5); - write_segment_file(final, expected, UNDO_SEGMENT_SIZE_BYTES); - memset(observed, 0, sizeof(observed)); - fsync_calls = 0; - UT_ASSERT_EQ(cluster_undo_smgr_probe_segment( - CLUSTER_UNDO_PATH_RUNTIME_SHARED, 1, 1, observed), - CLUSTER_UNDO_SMGR_FINAL_EXACT); - UT_ASSERT_EQ(fsync_calls, 1); - UT_ASSERT_EQ(memcmp(observed, expected, BLCKSZ), 0); - remove_if_present(final); + resolve_final(final); + remove_if_present(final); + make_page(expected, 0xa5); + write_segment_file(final, expected, UNDO_SEGMENT_SIZE_BYTES); + memset(observed, 0, sizeof(observed)); + fsync_calls = 0; + UT_ASSERT_EQ(cluster_undo_smgr_probe_segment(CLUSTER_UNDO_PATH_RUNTIME_SHARED, 1, 1, observed), + CLUSTER_UNDO_SMGR_FINAL_EXACT); + UT_ASSERT_EQ(fsync_calls, 1); + UT_ASSERT_EQ(memcmp(observed, expected, BLCKSZ), 0); + remove_if_present(final); } UT_TEST(test_probe_classifies_short_or_wrong_identity_as_invalid) { - char final[MAXPGPATH]; - char page[BLCKSZ]; - char observed[BLCKSZ]; + char final[MAXPGPATH]; + char page[BLCKSZ]; + char observed[BLCKSZ]; - resolve_final(final); - remove_if_present(final); - make_page(page, 0xa5); - write_segment_file(final, page, BLCKSZ); - UT_ASSERT_EQ(cluster_undo_smgr_probe_segment( - CLUSTER_UNDO_PATH_RUNTIME_SHARED, 1, 1, observed), - CLUSTER_UNDO_SMGR_FINAL_INVALID); - remove_if_present(final); + resolve_final(final); + remove_if_present(final); + make_page(page, 0xa5); + write_segment_file(final, page, BLCKSZ); + UT_ASSERT_EQ(cluster_undo_smgr_probe_segment(CLUSTER_UNDO_PATH_RUNTIME_SHARED, 1, 1, observed), + CLUSTER_UNDO_SMGR_FINAL_INVALID); + remove_if_present(final); - make_page(page, 0x5a); - write_segment_file(final, page, UNDO_SEGMENT_SIZE_BYTES); - UT_ASSERT_EQ(cluster_undo_smgr_probe_segment( - CLUSTER_UNDO_PATH_RUNTIME_SHARED, 1, 1, observed), - CLUSTER_UNDO_SMGR_FINAL_INVALID); - remove_if_present(final); + make_page(page, 0x5a); + write_segment_file(final, page, UNDO_SEGMENT_SIZE_BYTES); + UT_ASSERT_EQ(cluster_undo_smgr_probe_segment(CLUSTER_UNDO_PATH_RUNTIME_SHARED, 1, 1, observed), + CLUSTER_UNDO_SMGR_FINAL_INVALID); + remove_if_present(final); } UT_TEST(test_probe_reports_non_absent_open_failure_as_io_error) { - char final[MAXPGPATH]; - char page[BLCKSZ]; + char final[MAXPGPATH]; + char page[BLCKSZ]; - resolve_final(final); - remove_if_present(final); - make_page(page, 0xa5); - write_segment_file(final, page, UNDO_SEGMENT_SIZE_BYTES); - basic_open_forced_error = true; - UT_ASSERT_EQ(cluster_undo_smgr_probe_segment( - CLUSTER_UNDO_PATH_RUNTIME_SHARED, 1, 1, page), - CLUSTER_UNDO_SMGR_FINAL_IO_ERROR); - basic_open_forced_error = false; - remove_if_present(final); + resolve_final(final); + remove_if_present(final); + make_page(page, 0xa5); + write_segment_file(final, page, UNDO_SEGMENT_SIZE_BYTES); + basic_open_forced_error = true; + UT_ASSERT_EQ(cluster_undo_smgr_probe_segment(CLUSTER_UNDO_PATH_RUNTIME_SHARED, 1, 1, page), + CLUSTER_UNDO_SMGR_FINAL_IO_ERROR); + basic_open_forced_error = false; + remove_if_present(final); } UT_TEST(test_probe_close_failure_overrides_invalid_size) { - char final[MAXPGPATH]; - char page[BLCKSZ]; + char final[MAXPGPATH]; + char page[BLCKSZ]; - resolve_final(final); - remove_if_present(final); - make_page(page, 0xa5); - write_segment_file(final, page, BLCKSZ); - product_close_calls = 0; - product_close_fail_on_call = 1; - UT_ASSERT_EQ(cluster_undo_smgr_probe_segment( - CLUSTER_UNDO_PATH_RUNTIME_SHARED, 1, 1, page), - CLUSTER_UNDO_SMGR_FINAL_IO_ERROR); - product_close_fail_on_call = 0; - remove_if_present(final); + resolve_final(final); + remove_if_present(final); + make_page(page, 0xa5); + write_segment_file(final, page, BLCKSZ); + product_close_calls = 0; + product_close_fail_on_call = 1; + UT_ASSERT_EQ(cluster_undo_smgr_probe_segment(CLUSTER_UNDO_PATH_RUNTIME_SHARED, 1, 1, page), + CLUSTER_UNDO_SMGR_FINAL_IO_ERROR); + product_close_fail_on_call = 0; + remove_if_present(final); } UT_TEST(test_temp_is_same_directory_boot_unique_and_exactly_cleaned) { - char final[MAXPGPATH]; - char temp[MAXPGPATH]; - char sibling[MAXPGPATH]; - int fd; - - resolve_final(final); - remove_if_present(final); - temp[0] = '\0'; - UT_ASSERT(cluster_undo_smgr_provision_temp_create( - CLUSTER_UNDO_PATH_RUNTIME_SHARED, 1, 1, temp)); - UT_ASSERT(strncmp(temp, publication_dir, strlen(publication_dir)) == 0); - UT_ASSERT(strstr(temp, ".pgrac-b0tmp.") != NULL); - UT_ASSERT(access(temp, F_OK) == 0); - - UT_ASSERT(snprintf(sibling, sizeof(sibling), "%s.sibling", temp) - < (int) sizeof(sibling)); - fd = open(sibling, O_WRONLY | O_CREAT | O_EXCL | PG_BINARY, - pg_file_create_mode); - UT_ASSERT(fd >= 0); - UT_ASSERT_EQ(close(fd), 0); - UT_ASSERT(cluster_undo_smgr_provision_temp_cleanup( - CLUSTER_UNDO_PATH_RUNTIME_SHARED, 1, 1, temp)); - UT_ASSERT(access(temp, F_OK) != 0 && errno == ENOENT); - UT_ASSERT(access(sibling, F_OK) == 0); - remove_if_present(sibling); + char final[MAXPGPATH]; + char temp[MAXPGPATH]; + char sibling[MAXPGPATH]; + int fd; + + resolve_final(final); + remove_if_present(final); + temp[0] = '\0'; + UT_ASSERT( + cluster_undo_smgr_provision_temp_create(CLUSTER_UNDO_PATH_RUNTIME_SHARED, 1, 1, temp)); + UT_ASSERT(strncmp(temp, publication_dir, strlen(publication_dir)) == 0); + UT_ASSERT(strstr(temp, ".pgrac-b0tmp.") != NULL); + UT_ASSERT(access(temp, F_OK) == 0); + + UT_ASSERT(snprintf(sibling, sizeof(sibling), "%s.sibling", temp) < (int)sizeof(sibling)); + fd = open(sibling, O_WRONLY | O_CREAT | O_EXCL | PG_BINARY, pg_file_create_mode); + UT_ASSERT(fd >= 0); + UT_ASSERT_EQ(close(fd), 0); + UT_ASSERT( + cluster_undo_smgr_provision_temp_cleanup(CLUSTER_UNDO_PATH_RUNTIME_SHARED, 1, 1, temp)); + UT_ASSERT(access(temp, F_OK) != 0 && errno == ENOENT); + UT_ASSERT(access(sibling, F_OK) == 0); + remove_if_present(sibling); } UT_TEST(test_cleanup_rejects_final_path) { - char final[MAXPGPATH]; - char page[BLCKSZ]; + char final[MAXPGPATH]; + char page[BLCKSZ]; - resolve_final(final); - remove_if_present(final); - make_page(page, 0xa5); - write_segment_file(final, page, UNDO_SEGMENT_SIZE_BYTES); - UT_ASSERT(!cluster_undo_smgr_provision_temp_cleanup( - CLUSTER_UNDO_PATH_RUNTIME_SHARED, 1, 1, final)); - UT_ASSERT(access(final, F_OK) == 0); - remove_if_present(final); + resolve_final(final); + remove_if_present(final); + make_page(page, 0xa5); + write_segment_file(final, page, UNDO_SEGMENT_SIZE_BYTES); + UT_ASSERT( + !cluster_undo_smgr_provision_temp_cleanup(CLUSTER_UNDO_PATH_RUNTIME_SHARED, 1, 1, final)); + UT_ASSERT(access(final, F_OK) == 0); + remove_if_present(final); } UT_TEST(test_startup_cleanup_removes_boot_foreign_temp_and_fsyncs_directory) { - char final[MAXPGPATH]; - char foreign[MAXPGPATH]; + char final[MAXPGPATH]; + char foreign[MAXPGPATH]; - resolve_final(final); - UT_ASSERT(snprintf(foreign, sizeof(foreign), - "%s.pgrac-b0tmp.777.888.1", final) - < (int) sizeof(foreign)); - remove_if_present(foreign); - write_empty_file(foreign); + resolve_final(final); + UT_ASSERT(snprintf(foreign, sizeof(foreign), "%s.pgrac-b0tmp.777.888.1", final) + < (int)sizeof(foreign)); + remove_if_present(foreign); + write_empty_file(foreign); - fsync_calls = 0; - UT_ASSERT(cluster_undo_smgr_cleanup_boot_foreign_temps( - CLUSTER_UNDO_PATH_RUNTIME_SHARED, 1)); - UT_ASSERT(access(foreign, F_OK) != 0 && errno == ENOENT); - UT_ASSERT_EQ(fsync_calls, 1); + fsync_calls = 0; + UT_ASSERT(cluster_undo_smgr_cleanup_boot_foreign_temps(CLUSTER_UNDO_PATH_RUNTIME_SHARED, 1)); + UT_ASSERT(access(foreign, F_OK) != 0 && errno == ENOENT); + UT_ASSERT_EQ(fsync_calls, 1); } UT_TEST(test_startup_cleanup_refuses_current_boot_temp) { - char current[MAXPGPATH]; + char current[MAXPGPATH]; - UT_ASSERT(cluster_undo_smgr_provision_temp_create( - CLUSTER_UNDO_PATH_RUNTIME_SHARED, 1, 1, current)); - UT_ASSERT(!cluster_undo_smgr_cleanup_boot_foreign_temps( - CLUSTER_UNDO_PATH_RUNTIME_SHARED, 1)); - UT_ASSERT(access(current, F_OK) == 0); - UT_ASSERT(cluster_undo_smgr_provision_temp_cleanup( - CLUSTER_UNDO_PATH_RUNTIME_SHARED, 1, 1, current)); + UT_ASSERT( + cluster_undo_smgr_provision_temp_create(CLUSTER_UNDO_PATH_RUNTIME_SHARED, 1, 1, current)); + UT_ASSERT(!cluster_undo_smgr_cleanup_boot_foreign_temps(CLUSTER_UNDO_PATH_RUNTIME_SHARED, 1)); + UT_ASSERT(access(current, F_OK) == 0); + UT_ASSERT( + cluster_undo_smgr_provision_temp_cleanup(CLUSTER_UNDO_PATH_RUNTIME_SHARED, 1, 1, current)); } UT_TEST(test_startup_cleanup_refuses_symlink_with_valid_foreign_name) { - char final[MAXPGPATH]; - char foreign[MAXPGPATH]; + char final[MAXPGPATH]; + char foreign[MAXPGPATH]; - resolve_final(final); - UT_ASSERT(snprintf(foreign, sizeof(foreign), - "%s.pgrac-b0tmp.777.888.2", final) - < (int) sizeof(foreign)); - remove_if_present(foreign); - UT_ASSERT_EQ(symlink("does-not-exist", foreign), 0); + resolve_final(final); + UT_ASSERT(snprintf(foreign, sizeof(foreign), "%s.pgrac-b0tmp.777.888.2", final) + < (int)sizeof(foreign)); + remove_if_present(foreign); + UT_ASSERT_EQ(symlink("does-not-exist", foreign), 0); - UT_ASSERT(!cluster_undo_smgr_cleanup_boot_foreign_temps( - CLUSTER_UNDO_PATH_RUNTIME_SHARED, 1)); - UT_ASSERT_EQ(access(foreign, F_OK), -1); - UT_ASSERT_EQ(errno, ENOENT); - { - struct stat st; + UT_ASSERT(!cluster_undo_smgr_cleanup_boot_foreign_temps(CLUSTER_UNDO_PATH_RUNTIME_SHARED, 1)); + UT_ASSERT_EQ(access(foreign, F_OK), -1); + UT_ASSERT_EQ(errno, ENOENT); + { + struct stat st; - UT_ASSERT_EQ(lstat(foreign, &st), 0); - UT_ASSERT(S_ISLNK(st.st_mode)); - } - remove_if_present(foreign); + UT_ASSERT_EQ(lstat(foreign, &st), 0); + UT_ASSERT(S_ISLNK(st.st_mode)); + } + remove_if_present(foreign); } UT_TEST(test_startup_cleanup_refuses_malformed_temp_and_preserves_final) { - char final[MAXPGPATH]; - char malformed[MAXPGPATH]; - char page[BLCKSZ]; - - resolve_final(final); - remove_if_present(final); - make_page(page, 0xa5); - write_segment_file(final, page, UNDO_SEGMENT_SIZE_BYTES); - UT_ASSERT(snprintf(malformed, sizeof(malformed), - "%s.pgrac-b0tmp.bad.888.3", final) - < (int) sizeof(malformed)); - remove_if_present(malformed); - write_empty_file(malformed); + char final[MAXPGPATH]; + char malformed[MAXPGPATH]; + char page[BLCKSZ]; - UT_ASSERT(!cluster_undo_smgr_cleanup_boot_foreign_temps( - CLUSTER_UNDO_PATH_RUNTIME_SHARED, 1)); - UT_ASSERT(access(malformed, F_OK) == 0); - UT_ASSERT(access(final, F_OK) == 0); - remove_if_present(malformed); - remove_if_present(final); + resolve_final(final); + remove_if_present(final); + make_page(page, 0xa5); + write_segment_file(final, page, UNDO_SEGMENT_SIZE_BYTES); + UT_ASSERT(snprintf(malformed, sizeof(malformed), "%s.pgrac-b0tmp.bad.888.3", final) + < (int)sizeof(malformed)); + remove_if_present(malformed); + write_empty_file(malformed); + + UT_ASSERT(!cluster_undo_smgr_cleanup_boot_foreign_temps(CLUSTER_UNDO_PATH_RUNTIME_SHARED, 1)); + UT_ASSERT(access(malformed, F_OK) == 0); + UT_ASSERT(access(final, F_OK) == 0); + remove_if_present(malformed); + remove_if_present(final); } UT_TEST(test_startup_cleanup_refuses_truncated_temp_marker) { - char final[MAXPGPATH]; - char malformed[MAXPGPATH]; + char final[MAXPGPATH]; + char malformed[MAXPGPATH]; - resolve_final(final); - UT_ASSERT(snprintf(malformed, sizeof(malformed), - "%s.pgrac-b0tmp", final) - < (int) sizeof(malformed)); - remove_if_present(malformed); - write_empty_file(malformed); + resolve_final(final); + UT_ASSERT(snprintf(malformed, sizeof(malformed), "%s.pgrac-b0tmp", final) + < (int)sizeof(malformed)); + remove_if_present(malformed); + write_empty_file(malformed); - UT_ASSERT(!cluster_undo_smgr_cleanup_boot_foreign_temps( - CLUSTER_UNDO_PATH_RUNTIME_SHARED, 1)); - UT_ASSERT(access(malformed, F_OK) == 0); - remove_if_present(malformed); + UT_ASSERT(!cluster_undo_smgr_cleanup_boot_foreign_temps(CLUSTER_UNDO_PATH_RUNTIME_SHARED, 1)); + UT_ASSERT(access(malformed, F_OK) == 0); + remove_if_present(malformed); } UT_TEST(test_startup_cleanup_empty_namespace_preserves_ordinary_final) { - char final[MAXPGPATH]; - char page[BLCKSZ]; + char final[MAXPGPATH]; + char page[BLCKSZ]; - resolve_final(final); - remove_if_present(final); - make_page(page, 0xa5); - write_segment_file(final, page, UNDO_SEGMENT_SIZE_BYTES); - fsync_calls = 0; - UT_ASSERT(cluster_undo_smgr_cleanup_boot_foreign_temps( - CLUSTER_UNDO_PATH_RUNTIME_SHARED, 1)); - UT_ASSERT(access(final, F_OK) == 0); - UT_ASSERT_EQ(fsync_calls, 0); - remove_if_present(final); + resolve_final(final); + remove_if_present(final); + make_page(page, 0xa5); + write_segment_file(final, page, UNDO_SEGMENT_SIZE_BYTES); + fsync_calls = 0; + UT_ASSERT(cluster_undo_smgr_cleanup_boot_foreign_temps(CLUSTER_UNDO_PATH_RUNTIME_SHARED, 1)); + UT_ASSERT(access(final, F_OK) == 0); + UT_ASSERT_EQ(fsync_calls, 0); + remove_if_present(final); } UT_TEST(test_startup_cleanup_propagates_directory_close_failure) { - free_dir_forced_error = true; - UT_ASSERT(!cluster_undo_smgr_cleanup_boot_foreign_temps( - CLUSTER_UNDO_PATH_RUNTIME_SHARED, 1)); - free_dir_forced_error = false; + free_dir_forced_error = true; + UT_ASSERT(!cluster_undo_smgr_cleanup_boot_foreign_temps(CLUSTER_UNDO_PATH_RUNTIME_SHARED, 1)); + free_dir_forced_error = false; } UT_TEST(test_startup_cleanup_propagates_directory_fsync_failure) { - char final[MAXPGPATH]; - char foreign[MAXPGPATH]; + char final[MAXPGPATH]; + char foreign[MAXPGPATH]; - resolve_final(final); - UT_ASSERT(snprintf(foreign, sizeof(foreign), - "%s.pgrac-b0tmp.777.888.4", final) - < (int) sizeof(foreign)); - remove_if_present(foreign); - write_empty_file(foreign); + resolve_final(final); + UT_ASSERT(snprintf(foreign, sizeof(foreign), "%s.pgrac-b0tmp.777.888.4", final) + < (int)sizeof(foreign)); + remove_if_present(foreign); + write_empty_file(foreign); - fsync_calls = 0; - fsync_fail_on_call = 1; - UT_ASSERT(!cluster_undo_smgr_cleanup_boot_foreign_temps( - CLUSTER_UNDO_PATH_RUNTIME_SHARED, 1)); - fsync_fail_on_call = 0; - UT_ASSERT(access(foreign, F_OK) != 0 && errno == ENOENT); + fsync_calls = 0; + fsync_fail_on_call = 1; + UT_ASSERT(!cluster_undo_smgr_cleanup_boot_foreign_temps(CLUSTER_UNDO_PATH_RUNTIME_SHARED, 1)); + fsync_fail_on_call = 0; + UT_ASSERT(access(foreign, F_OK) != 0 && errno == ENOENT); } UT_TEST(test_publish_is_no_replace_and_fsyncs_file_and_parent) { - char final[MAXPGPATH]; - char temp[MAXPGPATH]; - char page[BLCKSZ]; - char observed[BLCKSZ]; - - resolve_final(final); - remove_if_present(final); - make_page(page, 0xa5); - UT_ASSERT(cluster_undo_smgr_provision_temp_create( - CLUSTER_UNDO_PATH_RUNTIME_SHARED, 1, 1, temp)); - fsync_calls = 0; - UT_ASSERT_EQ(cluster_undo_smgr_provision_temp_publish( - CLUSTER_UNDO_PATH_RUNTIME_SHARED, 1, 1, temp, page), - CLUSTER_UNDO_SMGR_PUBLISH_PUBLISHED); - UT_ASSERT_EQ(fsync_calls, 2); - UT_ASSERT(access(temp, F_OK) != 0 && errno == ENOENT); - UT_ASSERT_EQ(cluster_undo_smgr_probe_segment( - CLUSTER_UNDO_PATH_RUNTIME_SHARED, 1, 1, observed), - CLUSTER_UNDO_SMGR_FINAL_EXACT); - UT_ASSERT_EQ(memcmp(observed, page, BLCKSZ), 0); - remove_if_present(final); + char final[MAXPGPATH]; + char temp[MAXPGPATH]; + char page[BLCKSZ]; + char observed[BLCKSZ]; + + resolve_final(final); + remove_if_present(final); + make_page(page, 0xa5); + UT_ASSERT( + cluster_undo_smgr_provision_temp_create(CLUSTER_UNDO_PATH_RUNTIME_SHARED, 1, 1, temp)); + fsync_calls = 0; + UT_ASSERT_EQ(cluster_undo_smgr_provision_temp_publish(CLUSTER_UNDO_PATH_RUNTIME_SHARED, 1, 1, + temp, page), + CLUSTER_UNDO_SMGR_PUBLISH_PUBLISHED); + UT_ASSERT_EQ(fsync_calls, 2); + UT_ASSERT(access(temp, F_OK) != 0 && errno == ENOENT); + UT_ASSERT_EQ(cluster_undo_smgr_probe_segment(CLUSTER_UNDO_PATH_RUNTIME_SHARED, 1, 1, observed), + CLUSTER_UNDO_SMGR_FINAL_EXACT); + UT_ASSERT_EQ(memcmp(observed, page, BLCKSZ), 0); + remove_if_present(final); } UT_TEST(test_eexist_loser_never_overwrites_final_and_drops_own_temp) { - char final[MAXPGPATH]; - char temp[MAXPGPATH]; - char winner[BLCKSZ]; - char loser[BLCKSZ]; - char observed[BLCKSZ]; - - resolve_final(final); - remove_if_present(final); - make_page(winner, 0xa5); - winner[1] = 0x11; - write_segment_file(final, winner, UNDO_SEGMENT_SIZE_BYTES); - make_page(loser, 0xa5); - loser[1] = 0x22; - UT_ASSERT(cluster_undo_smgr_provision_temp_create( - CLUSTER_UNDO_PATH_RUNTIME_SHARED, 1, 1, temp)); - UT_ASSERT_EQ(cluster_undo_smgr_provision_temp_publish( - CLUSTER_UNDO_PATH_RUNTIME_SHARED, 1, 1, temp, loser), - CLUSTER_UNDO_SMGR_PUBLISH_EXISTS); - UT_ASSERT(access(temp, F_OK) != 0 && errno == ENOENT); - UT_ASSERT_EQ(cluster_undo_smgr_probe_segment( - CLUSTER_UNDO_PATH_RUNTIME_SHARED, 1, 1, observed), - CLUSTER_UNDO_SMGR_FINAL_EXACT); - UT_ASSERT_EQ(memcmp(observed, winner, BLCKSZ), 0); - remove_if_present(final); + char final[MAXPGPATH]; + char temp[MAXPGPATH]; + char winner[BLCKSZ]; + char loser[BLCKSZ]; + char observed[BLCKSZ]; + + resolve_final(final); + remove_if_present(final); + make_page(winner, 0xa5); + winner[1] = 0x11; + write_segment_file(final, winner, UNDO_SEGMENT_SIZE_BYTES); + make_page(loser, 0xa5); + loser[1] = 0x22; + UT_ASSERT( + cluster_undo_smgr_provision_temp_create(CLUSTER_UNDO_PATH_RUNTIME_SHARED, 1, 1, temp)); + UT_ASSERT_EQ(cluster_undo_smgr_provision_temp_publish(CLUSTER_UNDO_PATH_RUNTIME_SHARED, 1, 1, + temp, loser), + CLUSTER_UNDO_SMGR_PUBLISH_EXISTS); + UT_ASSERT(access(temp, F_OK) != 0 && errno == ENOENT); + UT_ASSERT_EQ(cluster_undo_smgr_probe_segment(CLUSTER_UNDO_PATH_RUNTIME_SHARED, 1, 1, observed), + CLUSTER_UNDO_SMGR_FINAL_EXACT); + UT_ASSERT_EQ(memcmp(observed, winner, BLCKSZ), 0); + remove_if_present(final); } UT_TEST(test_eexist_invalid_final_is_never_repaired_or_overwritten) { - char final[MAXPGPATH]; - char temp[MAXPGPATH]; - char invalid[BLCKSZ]; - char candidate[BLCKSZ]; - char observed[BLCKSZ]; - int fd; - - resolve_final(final); - remove_if_present(final); - make_page(invalid, 0x5a); - invalid[1] = 0x33; - write_segment_file(final, invalid, UNDO_SEGMENT_SIZE_BYTES); - make_page(candidate, 0xa5); - candidate[1] = 0x44; - UT_ASSERT(cluster_undo_smgr_provision_temp_create( - CLUSTER_UNDO_PATH_RUNTIME_SHARED, 1, 1, temp)); - UT_ASSERT_EQ(cluster_undo_smgr_provision_temp_publish( - CLUSTER_UNDO_PATH_RUNTIME_SHARED, 1, 1, temp, candidate), - CLUSTER_UNDO_SMGR_PUBLISH_INVALID); - UT_ASSERT(access(temp, F_OK) != 0 && errno == ENOENT); - fd = open(final, O_RDONLY | PG_BINARY); - UT_ASSERT(fd >= 0); - UT_ASSERT_EQ(pread(fd, observed, BLCKSZ, 0), BLCKSZ); - UT_ASSERT_EQ(close(fd), 0); - UT_ASSERT_EQ(memcmp(observed, invalid, BLCKSZ), 0); - remove_if_present(final); + char final[MAXPGPATH]; + char temp[MAXPGPATH]; + char invalid[BLCKSZ]; + char candidate[BLCKSZ]; + char observed[BLCKSZ]; + int fd; + + resolve_final(final); + remove_if_present(final); + make_page(invalid, 0x5a); + invalid[1] = 0x33; + write_segment_file(final, invalid, UNDO_SEGMENT_SIZE_BYTES); + make_page(candidate, 0xa5); + candidate[1] = 0x44; + UT_ASSERT( + cluster_undo_smgr_provision_temp_create(CLUSTER_UNDO_PATH_RUNTIME_SHARED, 1, 1, temp)); + UT_ASSERT_EQ(cluster_undo_smgr_provision_temp_publish(CLUSTER_UNDO_PATH_RUNTIME_SHARED, 1, 1, + temp, candidate), + CLUSTER_UNDO_SMGR_PUBLISH_INVALID); + UT_ASSERT(access(temp, F_OK) != 0 && errno == ENOENT); + fd = open(final, O_RDONLY | PG_BINARY); + UT_ASSERT(fd >= 0); + UT_ASSERT_EQ(pread(fd, observed, BLCKSZ, 0), BLCKSZ); + UT_ASSERT_EQ(close(fd), 0); + UT_ASSERT_EQ(memcmp(observed, invalid, BLCKSZ), 0); + remove_if_present(final); } UT_TEST(test_eexist_retry_fsyncs_parent_after_prior_parent_fsync_failure) { - char final[MAXPGPATH]; - char failed_temp[MAXPGPATH]; - char retry_temp[MAXPGPATH]; - char page[BLCKSZ]; - - resolve_final(final); - remove_if_present(final); - make_page(page, 0xa5); - UT_ASSERT(cluster_undo_smgr_provision_temp_create( - CLUSTER_UNDO_PATH_RUNTIME_SHARED, 1, 1, failed_temp)); - fsync_calls = 0; - fsync_fail_on_call = 2; - UT_ASSERT_EQ(cluster_undo_smgr_provision_temp_publish( - CLUSTER_UNDO_PATH_RUNTIME_SHARED, 1, 1, failed_temp, page), - CLUSTER_UNDO_SMGR_PUBLISH_IO_ERROR); - UT_ASSERT(access(final, F_OK) == 0); - UT_ASSERT(access(failed_temp, F_OK) != 0 && errno == ENOENT); - - UT_ASSERT(cluster_undo_smgr_provision_temp_create( - CLUSTER_UNDO_PATH_RUNTIME_SHARED, 1, 1, retry_temp)); - fsync_calls = 0; - fsync_fail_on_call = 0; - UT_ASSERT_EQ(cluster_undo_smgr_provision_temp_publish( - CLUSTER_UNDO_PATH_RUNTIME_SHARED, 1, 1, retry_temp, page), - CLUSTER_UNDO_SMGR_PUBLISH_EXISTS); - UT_ASSERT_EQ(fsync_calls, 2); - UT_ASSERT(access(retry_temp, F_OK) != 0 && errno == ENOENT); - remove_if_present(final); + char final[MAXPGPATH]; + char failed_temp[MAXPGPATH]; + char retry_temp[MAXPGPATH]; + char page[BLCKSZ]; + + resolve_final(final); + remove_if_present(final); + make_page(page, 0xa5); + UT_ASSERT(cluster_undo_smgr_provision_temp_create(CLUSTER_UNDO_PATH_RUNTIME_SHARED, 1, 1, + failed_temp)); + fsync_calls = 0; + fsync_fail_on_call = 2; + UT_ASSERT_EQ(cluster_undo_smgr_provision_temp_publish(CLUSTER_UNDO_PATH_RUNTIME_SHARED, 1, 1, + failed_temp, page), + CLUSTER_UNDO_SMGR_PUBLISH_IO_ERROR); + UT_ASSERT(access(final, F_OK) == 0); + UT_ASSERT(access(failed_temp, F_OK) != 0 && errno == ENOENT); + + UT_ASSERT(cluster_undo_smgr_provision_temp_create(CLUSTER_UNDO_PATH_RUNTIME_SHARED, 1, 1, + retry_temp)); + fsync_calls = 0; + fsync_fail_on_call = 0; + UT_ASSERT_EQ(cluster_undo_smgr_provision_temp_publish(CLUSTER_UNDO_PATH_RUNTIME_SHARED, 1, 1, + retry_temp, page), + CLUSTER_UNDO_SMGR_PUBLISH_EXISTS); + UT_ASSERT_EQ(fsync_calls, 2); + UT_ASSERT(access(retry_temp, F_OK) != 0 && errno == ENOENT); + remove_if_present(final); } UT_TEST(test_temp_write_failure_closes_fd_and_removes_only_owned_temp) { - char final[MAXPGPATH]; - char temp[MAXPGPATH]; - char sibling[MAXPGPATH]; - char page[BLCKSZ]; - int fd; - - resolve_final(final); - remove_if_present(final); - make_page(page, 0xa5); - UT_ASSERT(cluster_undo_smgr_provision_temp_create( - CLUSTER_UNDO_PATH_RUNTIME_SHARED, 1, 1, temp)); - UT_ASSERT(snprintf(sibling, sizeof(sibling), "%s.sibling", temp) - < (int) sizeof(sibling)); - fd = open(sibling, O_WRONLY | O_CREAT | O_EXCL | PG_BINARY, - pg_file_create_mode); - UT_ASSERT(fd >= 0); - UT_ASSERT_EQ(close(fd), 0); - - product_close_calls = 0; - pwrite_forced_error = true; - UT_ASSERT_EQ(cluster_undo_smgr_provision_temp_publish( - CLUSTER_UNDO_PATH_RUNTIME_SHARED, 1, 1, temp, page), - CLUSTER_UNDO_SMGR_PUBLISH_IO_ERROR); - pwrite_forced_error = false; - UT_ASSERT_EQ(product_close_calls, 1); - UT_ASSERT(access(temp, F_OK) != 0 && errno == ENOENT); - UT_ASSERT(access(sibling, F_OK) == 0); - UT_ASSERT(access(final, F_OK) != 0 && errno == ENOENT); - remove_if_present(sibling); + char final[MAXPGPATH]; + char temp[MAXPGPATH]; + char sibling[MAXPGPATH]; + char page[BLCKSZ]; + int fd; + + resolve_final(final); + remove_if_present(final); + make_page(page, 0xa5); + UT_ASSERT( + cluster_undo_smgr_provision_temp_create(CLUSTER_UNDO_PATH_RUNTIME_SHARED, 1, 1, temp)); + UT_ASSERT(snprintf(sibling, sizeof(sibling), "%s.sibling", temp) < (int)sizeof(sibling)); + fd = open(sibling, O_WRONLY | O_CREAT | O_EXCL | PG_BINARY, pg_file_create_mode); + UT_ASSERT(fd >= 0); + UT_ASSERT_EQ(close(fd), 0); + + product_close_calls = 0; + pwrite_forced_error = true; + UT_ASSERT_EQ(cluster_undo_smgr_provision_temp_publish(CLUSTER_UNDO_PATH_RUNTIME_SHARED, 1, 1, + temp, page), + CLUSTER_UNDO_SMGR_PUBLISH_IO_ERROR); + pwrite_forced_error = false; + UT_ASSERT_EQ(product_close_calls, 1); + UT_ASSERT(access(temp, F_OK) != 0 && errno == ENOENT); + UT_ASSERT(access(sibling, F_OK) == 0); + UT_ASSERT(access(final, F_OK) != 0 && errno == ENOENT); + remove_if_present(sibling); } UT_TEST(test_root_descriptor_mirror_publish_is_exact_and_durable) { - char final[MAXPGPATH]; - uint8 image[512]; - uint8 observed[512]; - struct stat st; - int i; - - resolve_root_descriptor(final); - remove_if_present(final); - for (i = 0; i < 512; i++) - image[i] = (uint8)(i ^ 0x39); - memset(observed, 0xa5, sizeof(observed)); - fsync_calls = 0; - UT_ASSERT_EQ(cluster_undo_smgr_root_descriptor_publish( - publication_dir, image), - CLUSTER_UNDO_SMGR_ROOT_MIRROR_PUBLISHED); - UT_ASSERT_EQ(fsync_calls, 2); - UT_ASSERT_EQ(count_root_descriptor_temps(), 0); - UT_ASSERT_EQ(lstat(final, &st), 0); - UT_ASSERT(S_ISREG(st.st_mode)); - UT_ASSERT_EQ(st.st_size, 512); - UT_ASSERT_EQ(cluster_undo_smgr_root_descriptor_probe( - publication_dir, image, observed), - CLUSTER_UNDO_SMGR_ROOT_MIRROR_EXACT); - UT_ASSERT_EQ(memcmp(observed, image, sizeof(image)), 0); - remove_if_present(final); + char final[MAXPGPATH]; + uint8 image[512]; + uint8 observed[512]; + struct stat st; + int i; + + resolve_root_descriptor(final); + remove_if_present(final); + for (i = 0; i < 512; i++) + image[i] = (uint8)(i ^ 0x39); + memset(observed, 0xa5, sizeof(observed)); + fsync_calls = 0; + UT_ASSERT_EQ(cluster_undo_smgr_root_descriptor_publish(publication_dir, image), + CLUSTER_UNDO_SMGR_ROOT_MIRROR_PUBLISHED); + UT_ASSERT_EQ(fsync_calls, 2); + UT_ASSERT_EQ(count_root_descriptor_temps(), 0); + UT_ASSERT_EQ(lstat(final, &st), 0); + UT_ASSERT(S_ISREG(st.st_mode)); + UT_ASSERT_EQ(st.st_size, 512); + UT_ASSERT_EQ(cluster_undo_smgr_root_descriptor_probe(publication_dir, image, observed), + CLUSTER_UNDO_SMGR_ROOT_MIRROR_EXACT); + UT_ASSERT_EQ(memcmp(observed, image, sizeof(image)), 0); + remove_if_present(final); } UT_TEST(test_root_descriptor_mirror_eexist_is_validate_only) { - char final[MAXPGPATH]; - uint8 winner[512]; - uint8 loser[512]; - uint8 observed[512]; - int i; - - resolve_root_descriptor(final); - remove_if_present(final); - for (i = 0; i < 512; i++) { - winner[i] = (uint8)(i ^ 0x6d); - loser[i] = (uint8)(i ^ 0xc3); - } - UT_ASSERT_EQ(cluster_undo_smgr_root_descriptor_publish( - publication_dir, winner), - CLUSTER_UNDO_SMGR_ROOT_MIRROR_PUBLISHED); - UT_ASSERT_EQ(cluster_undo_smgr_root_descriptor_publish( - publication_dir, winner), - CLUSTER_UNDO_SMGR_ROOT_MIRROR_EXACT); - UT_ASSERT_EQ(count_root_descriptor_temps(), 0); - UT_ASSERT_EQ(cluster_undo_smgr_root_descriptor_publish( - publication_dir, loser), - CLUSTER_UNDO_SMGR_ROOT_MIRROR_HOLD); - UT_ASSERT_EQ(count_root_descriptor_temps(), 0); - memset(observed, 0, sizeof(observed)); - UT_ASSERT_EQ(cluster_undo_smgr_root_descriptor_probe( - publication_dir, winner, observed), - CLUSTER_UNDO_SMGR_ROOT_MIRROR_EXACT); - UT_ASSERT_EQ(memcmp(observed, winner, sizeof(winner)), 0); - remove_if_present(final); + char final[MAXPGPATH]; + uint8 winner[512]; + uint8 loser[512]; + uint8 observed[512]; + int i; + + resolve_root_descriptor(final); + remove_if_present(final); + for (i = 0; i < 512; i++) { + winner[i] = (uint8)(i ^ 0x6d); + loser[i] = (uint8)(i ^ 0xc3); + } + UT_ASSERT_EQ(cluster_undo_smgr_root_descriptor_publish(publication_dir, winner), + CLUSTER_UNDO_SMGR_ROOT_MIRROR_PUBLISHED); + UT_ASSERT_EQ(cluster_undo_smgr_root_descriptor_publish(publication_dir, winner), + CLUSTER_UNDO_SMGR_ROOT_MIRROR_EXACT); + UT_ASSERT_EQ(count_root_descriptor_temps(), 0); + UT_ASSERT_EQ(cluster_undo_smgr_root_descriptor_publish(publication_dir, loser), + CLUSTER_UNDO_SMGR_ROOT_MIRROR_HOLD); + UT_ASSERT_EQ(count_root_descriptor_temps(), 0); + memset(observed, 0, sizeof(observed)); + UT_ASSERT_EQ(cluster_undo_smgr_root_descriptor_probe(publication_dir, winner, observed), + CLUSTER_UNDO_SMGR_ROOT_MIRROR_EXACT); + UT_ASSERT_EQ(memcmp(observed, winner, sizeof(winner)), 0); + remove_if_present(final); } UT_TEST(test_root_descriptor_mirror_reads_exact_retry_candidate) @@ -757,12 +726,10 @@ UT_TEST(test_root_descriptor_mirror_reads_exact_retry_candidate) remove_if_present(final); for (i = 0; i < 512; i++) image[i] = (uint8)(i ^ 0x91); - UT_ASSERT_EQ(cluster_undo_smgr_root_descriptor_publish( - publication_dir, image), + UT_ASSERT_EQ(cluster_undo_smgr_root_descriptor_publish(publication_dir, image), CLUSTER_UNDO_SMGR_ROOT_MIRROR_PUBLISHED); memset(observed, 0, sizeof(observed)); - UT_ASSERT_EQ(cluster_undo_smgr_root_descriptor_read_candidate( - publication_dir, observed), + UT_ASSERT_EQ(cluster_undo_smgr_root_descriptor_read_candidate(publication_dir, observed), CLUSTER_UNDO_SMGR_ROOT_MIRROR_EXACT); UT_ASSERT_EQ(memcmp(observed, image, sizeof(image)), 0); remove_if_present(final); @@ -770,147 +737,138 @@ UT_TEST(test_root_descriptor_mirror_reads_exact_retry_candidate) UT_TEST(test_root_descriptor_mirror_probe_rejects_short_and_symlink) { - char final[MAXPGPATH]; - char target[MAXPGPATH]; - uint8 expected[512]; - uint8 sentinel[512]; - uint8 observed[512]; - int fd; - - resolve_root_descriptor(final); - remove_if_present(final); - memset(expected, 0x5a, sizeof(expected)); - memset(sentinel, 0x7c, sizeof(sentinel)); - observed[0] = 0; - memcpy(observed, sentinel, sizeof(observed)); - UT_ASSERT_EQ(cluster_undo_smgr_root_descriptor_probe( - publication_dir, expected, observed), - CLUSTER_UNDO_SMGR_ROOT_MIRROR_ABSENT); - UT_ASSERT_EQ(memcmp(observed, sentinel, sizeof(observed)), 0); - - fd = open(final, O_WRONLY | O_CREAT | O_EXCL | PG_BINARY, - pg_file_create_mode); - UT_ASSERT(fd >= 0); - UT_ASSERT_EQ(write(fd, expected, 511), 511); - UT_ASSERT_EQ(close(fd), 0); - memcpy(observed, sentinel, sizeof(observed)); - UT_ASSERT_EQ(cluster_undo_smgr_root_descriptor_probe( - publication_dir, expected, observed), - CLUSTER_UNDO_SMGR_ROOT_MIRROR_HOLD); - UT_ASSERT_EQ(memcmp(observed, sentinel, sizeof(observed)), 0); - remove_if_present(final); - - UT_ASSERT(snprintf(target, sizeof(target), "%s/root-target", - publication_dir) < (int) sizeof(target)); - remove_if_present(target); - fd = open(target, O_WRONLY | O_CREAT | O_EXCL | PG_BINARY, - pg_file_create_mode); - UT_ASSERT(fd >= 0); - UT_ASSERT_EQ(write(fd, expected, sizeof(expected)), sizeof(expected)); - UT_ASSERT_EQ(close(fd), 0); - UT_ASSERT_EQ(symlink(target, final), 0); - memcpy(observed, sentinel, sizeof(observed)); - UT_ASSERT_EQ(cluster_undo_smgr_root_descriptor_probe( - publication_dir, expected, observed), - CLUSTER_UNDO_SMGR_ROOT_MIRROR_HOLD); - UT_ASSERT_EQ(memcmp(observed, sentinel, sizeof(observed)), 0); - remove_if_present(final); - remove_if_present(target); + char final[MAXPGPATH]; + char target[MAXPGPATH]; + uint8 expected[512]; + uint8 sentinel[512]; + uint8 observed[512]; + int fd; + + resolve_root_descriptor(final); + remove_if_present(final); + memset(expected, 0x5a, sizeof(expected)); + memset(sentinel, 0x7c, sizeof(sentinel)); + observed[0] = 0; + memcpy(observed, sentinel, sizeof(observed)); + UT_ASSERT_EQ(cluster_undo_smgr_root_descriptor_probe(publication_dir, expected, observed), + CLUSTER_UNDO_SMGR_ROOT_MIRROR_ABSENT); + UT_ASSERT_EQ(memcmp(observed, sentinel, sizeof(observed)), 0); + + fd = open(final, O_WRONLY | O_CREAT | O_EXCL | PG_BINARY, pg_file_create_mode); + UT_ASSERT(fd >= 0); + UT_ASSERT_EQ(write(fd, expected, 511), 511); + UT_ASSERT_EQ(close(fd), 0); + memcpy(observed, sentinel, sizeof(observed)); + UT_ASSERT_EQ(cluster_undo_smgr_root_descriptor_probe(publication_dir, expected, observed), + CLUSTER_UNDO_SMGR_ROOT_MIRROR_HOLD); + UT_ASSERT_EQ(memcmp(observed, sentinel, sizeof(observed)), 0); + remove_if_present(final); + + UT_ASSERT(snprintf(target, sizeof(target), "%s/root-target", publication_dir) + < (int)sizeof(target)); + remove_if_present(target); + fd = open(target, O_WRONLY | O_CREAT | O_EXCL | PG_BINARY, pg_file_create_mode); + UT_ASSERT(fd >= 0); + UT_ASSERT_EQ(write(fd, expected, sizeof(expected)), sizeof(expected)); + UT_ASSERT_EQ(close(fd), 0); + UT_ASSERT_EQ(symlink(target, final), 0); + memcpy(observed, sentinel, sizeof(observed)); + UT_ASSERT_EQ(cluster_undo_smgr_root_descriptor_probe(publication_dir, expected, observed), + CLUSTER_UNDO_SMGR_ROOT_MIRROR_HOLD); + UT_ASSERT_EQ(memcmp(observed, sentinel, sizeof(observed)), 0); + remove_if_present(final); + remove_if_present(target); } UT_TEST(test_root_descriptor_mirror_probe_rejects_lstat_open_symlink_swap) { - char final[MAXPGPATH]; - char target[MAXPGPATH]; - uint8 expected[512]; - uint8 sentinel[512]; - uint8 observed[512]; - int fd; - - resolve_root_descriptor(final); - remove_if_present(final); - UT_ASSERT(snprintf(target, sizeof(target), "%s/root-race-target", - publication_dir) < (int) sizeof(target)); - remove_if_present(target); - memset(expected, 0x2d, sizeof(expected)); - memset(sentinel, 0xb6, sizeof(sentinel)); - - fd = open(final, O_WRONLY | O_CREAT | O_EXCL | PG_BINARY, - pg_file_create_mode); - UT_ASSERT(fd >= 0); - UT_ASSERT_EQ(write(fd, sentinel, sizeof(sentinel)), sizeof(sentinel)); - UT_ASSERT_EQ(close(fd), 0); - fd = open(target, O_WRONLY | O_CREAT | O_EXCL | PG_BINARY, - pg_file_create_mode); - UT_ASSERT(fd >= 0); - UT_ASSERT_EQ(write(fd, expected, sizeof(expected)), sizeof(expected)); - UT_ASSERT_EQ(close(fd), 0); - - strlcpy(basic_open_swap_target, target, sizeof(basic_open_swap_target)); - basic_open_swap_to_symlink = true; - memcpy(observed, sentinel, sizeof(observed)); - UT_ASSERT_EQ(cluster_undo_smgr_root_descriptor_probe( - publication_dir, expected, observed), - CLUSTER_UNDO_SMGR_ROOT_MIRROR_HOLD); - UT_ASSERT(!basic_open_swap_to_symlink); - UT_ASSERT_EQ(memcmp(observed, sentinel, sizeof(observed)), 0); - - remove_if_present(final); - remove_if_present(target); + char final[MAXPGPATH]; + char target[MAXPGPATH]; + uint8 expected[512]; + uint8 sentinel[512]; + uint8 observed[512]; + int fd; + + resolve_root_descriptor(final); + remove_if_present(final); + UT_ASSERT(snprintf(target, sizeof(target), "%s/root-race-target", publication_dir) + < (int)sizeof(target)); + remove_if_present(target); + memset(expected, 0x2d, sizeof(expected)); + memset(sentinel, 0xb6, sizeof(sentinel)); + + fd = open(final, O_WRONLY | O_CREAT | O_EXCL | PG_BINARY, pg_file_create_mode); + UT_ASSERT(fd >= 0); + UT_ASSERT_EQ(write(fd, sentinel, sizeof(sentinel)), sizeof(sentinel)); + UT_ASSERT_EQ(close(fd), 0); + fd = open(target, O_WRONLY | O_CREAT | O_EXCL | PG_BINARY, pg_file_create_mode); + UT_ASSERT(fd >= 0); + UT_ASSERT_EQ(write(fd, expected, sizeof(expected)), sizeof(expected)); + UT_ASSERT_EQ(close(fd), 0); + + strlcpy(basic_open_swap_target, target, sizeof(basic_open_swap_target)); + basic_open_swap_to_symlink = true; + memcpy(observed, sentinel, sizeof(observed)); + UT_ASSERT_EQ(cluster_undo_smgr_root_descriptor_probe(publication_dir, expected, observed), + CLUSTER_UNDO_SMGR_ROOT_MIRROR_HOLD); + UT_ASSERT(!basic_open_swap_to_symlink); + UT_ASSERT_EQ(memcmp(observed, sentinel, sizeof(observed)), 0); + + remove_if_present(final); + remove_if_present(target); } UT_TEST(test_root_descriptor_mirror_write_failure_cleans_owned_temp) { - char final[MAXPGPATH]; - uint8 image[512]; + char final[MAXPGPATH]; + uint8 image[512]; - resolve_root_descriptor(final); - remove_if_present(final); - memset(image, 0x4b, sizeof(image)); - pwrite_forced_error = true; - UT_ASSERT_EQ(cluster_undo_smgr_root_descriptor_publish( - publication_dir, image), - CLUSTER_UNDO_SMGR_ROOT_MIRROR_IO_ERROR); - pwrite_forced_error = false; - UT_ASSERT(access(final, F_OK) != 0 && errno == ENOENT); - UT_ASSERT_EQ(count_root_descriptor_temps(), 0); + resolve_root_descriptor(final); + remove_if_present(final); + memset(image, 0x4b, sizeof(image)); + pwrite_forced_error = true; + UT_ASSERT_EQ(cluster_undo_smgr_root_descriptor_publish(publication_dir, image), + CLUSTER_UNDO_SMGR_ROOT_MIRROR_IO_ERROR); + pwrite_forced_error = false; + UT_ASSERT(access(final, F_OK) != 0 && errno == ENOENT); + UT_ASSERT_EQ(count_root_descriptor_temps(), 0); } int main(void) { - char template[] = "/tmp/pgrac-b0pub-XXXXXX"; + char template[] = "/tmp/pgrac-b0pub-XXXXXX"; - UT_ASSERT_NOT_NULL(mkdtemp(template)); - strlcpy(publication_dir, template, sizeof(publication_dir)); + UT_ASSERT_NOT_NULL(mkdtemp(template)); + strlcpy(publication_dir, template, sizeof(publication_dir)); UT_PLAN(26); - UT_RUN(test_probe_distinguishes_absent_and_preserves_output); - UT_RUN(test_probe_accepts_only_exact_full_identity); - UT_RUN(test_probe_classifies_short_or_wrong_identity_as_invalid); - UT_RUN(test_probe_reports_non_absent_open_failure_as_io_error); - UT_RUN(test_probe_close_failure_overrides_invalid_size); - UT_RUN(test_temp_is_same_directory_boot_unique_and_exactly_cleaned); - UT_RUN(test_cleanup_rejects_final_path); - UT_RUN(test_startup_cleanup_removes_boot_foreign_temp_and_fsyncs_directory); - UT_RUN(test_startup_cleanup_refuses_current_boot_temp); - UT_RUN(test_startup_cleanup_refuses_symlink_with_valid_foreign_name); - UT_RUN(test_startup_cleanup_refuses_malformed_temp_and_preserves_final); - UT_RUN(test_startup_cleanup_refuses_truncated_temp_marker); - UT_RUN(test_startup_cleanup_empty_namespace_preserves_ordinary_final); - UT_RUN(test_startup_cleanup_propagates_directory_close_failure); - UT_RUN(test_startup_cleanup_propagates_directory_fsync_failure); - UT_RUN(test_publish_is_no_replace_and_fsyncs_file_and_parent); - UT_RUN(test_eexist_loser_never_overwrites_final_and_drops_own_temp); - UT_RUN(test_eexist_invalid_final_is_never_repaired_or_overwritten); - UT_RUN(test_eexist_retry_fsyncs_parent_after_prior_parent_fsync_failure); - UT_RUN(test_temp_write_failure_closes_fd_and_removes_only_owned_temp); - UT_RUN(test_root_descriptor_mirror_publish_is_exact_and_durable); - UT_RUN(test_root_descriptor_mirror_eexist_is_validate_only); + UT_RUN(test_probe_distinguishes_absent_and_preserves_output); + UT_RUN(test_probe_accepts_only_exact_full_identity); + UT_RUN(test_probe_classifies_short_or_wrong_identity_as_invalid); + UT_RUN(test_probe_reports_non_absent_open_failure_as_io_error); + UT_RUN(test_probe_close_failure_overrides_invalid_size); + UT_RUN(test_temp_is_same_directory_boot_unique_and_exactly_cleaned); + UT_RUN(test_cleanup_rejects_final_path); + UT_RUN(test_startup_cleanup_removes_boot_foreign_temp_and_fsyncs_directory); + UT_RUN(test_startup_cleanup_refuses_current_boot_temp); + UT_RUN(test_startup_cleanup_refuses_symlink_with_valid_foreign_name); + UT_RUN(test_startup_cleanup_refuses_malformed_temp_and_preserves_final); + UT_RUN(test_startup_cleanup_refuses_truncated_temp_marker); + UT_RUN(test_startup_cleanup_empty_namespace_preserves_ordinary_final); + UT_RUN(test_startup_cleanup_propagates_directory_close_failure); + UT_RUN(test_startup_cleanup_propagates_directory_fsync_failure); + UT_RUN(test_publish_is_no_replace_and_fsyncs_file_and_parent); + UT_RUN(test_eexist_loser_never_overwrites_final_and_drops_own_temp); + UT_RUN(test_eexist_invalid_final_is_never_repaired_or_overwritten); + UT_RUN(test_eexist_retry_fsyncs_parent_after_prior_parent_fsync_failure); + UT_RUN(test_temp_write_failure_closes_fd_and_removes_only_owned_temp); + UT_RUN(test_root_descriptor_mirror_publish_is_exact_and_durable); + UT_RUN(test_root_descriptor_mirror_eexist_is_validate_only); UT_RUN(test_root_descriptor_mirror_reads_exact_retry_candidate); - UT_RUN(test_root_descriptor_mirror_probe_rejects_short_and_symlink); - UT_RUN(test_root_descriptor_mirror_probe_rejects_lstat_open_symlink_swap); - UT_RUN(test_root_descriptor_mirror_write_failure_cleans_owned_temp); - UT_ASSERT_EQ(rmdir(publication_dir), 0); - UT_DONE(); - return ut_failed_count == 0 ? 0 : 1; + UT_RUN(test_root_descriptor_mirror_probe_rejects_short_and_symlink); + UT_RUN(test_root_descriptor_mirror_probe_rejects_lstat_open_symlink_swap); + UT_RUN(test_root_descriptor_mirror_write_failure_cleans_owned_temp); + UT_ASSERT_EQ(rmdir(publication_dir), 0); + UT_DONE(); + return ut_failed_count == 0 ? 0 : 1; } diff --git a/src/test/cluster_unit/test_cluster_visibility_fork.c b/src/test/cluster_unit/test_cluster_visibility_fork.c index 2dd505062a9..bc77803fe90 100644 --- a/src/test/cluster_unit/test_cluster_visibility_fork.c +++ b/src/test/cluster_unit/test_cluster_visibility_fork.c @@ -162,8 +162,7 @@ assert_data_active_publish(const char *source, const char *start_marker, const c const char *crit_end = start != NULL ? strstr(start, "END_CRIT_SECTION();") : NULL; snprintf(publish_call, sizeof(publish_call), - "cluster_tt_local_record_data_active(canonical_xid, %s);", - uba_name); + "cluster_tt_local_record_data_active(canonical_xid, %s);", uba_name); publish = start != NULL ? strstr(start, publish_call) : NULL; if (publish != NULL && end != NULL && publish >= end) @@ -192,28 +191,22 @@ static void assert_multi_insert_uses_receipt_safe_per_tuple_route(const char *source) { const char *start = strstr(source, "\nheap_multi_insert(Relation"); - const char *end = start == NULL - ? NULL - : strstr(start, "\n/*\n *\tsimple_heap_insert - insert a tuple"); - const char *route = start == NULL - ? NULL - : strstr(start, "cluster_heap_multi_insert_route("); - const char *per_tuple = route == NULL - ? NULL - : strstr(route, "heap_insert(relation, tuple, cid, options, bistate);"); - const char *route_return = per_tuple == NULL - ? NULL - : strstr(per_tuple, "\n\t\treturn;"); + const char *end + = start == NULL ? NULL : strstr(start, "\n/*\n *\tsimple_heap_insert - insert a tuple"); + const char *route = start == NULL ? NULL : strstr(start, "cluster_heap_multi_insert_route("); + const char *per_tuple + = route == NULL ? NULL + : strstr(route, "heap_insert(relation, tuple, cid, options, bistate);"); + const char *route_return = per_tuple == NULL ? NULL : strstr(per_tuple, "\n\t\treturn;"); UT_ASSERT_NOT_NULL(start); UT_ASSERT_NOT_NULL(end); UT_ASSERT_NOT_NULL(route); UT_ASSERT_NOT_NULL(per_tuple); UT_ASSERT_NOT_NULL(route_return); - if (start != NULL && end != NULL && route != NULL && per_tuple != NULL - && route_return != NULL) - UT_ASSERT(start < route && route < per_tuple - && per_tuple < route_return && route_return < end); + if (start != NULL && end != NULL && route != NULL && per_tuple != NULL && route_return != NULL) + UT_ASSERT(start < route && route < per_tuple && per_tuple < route_return + && route_return < end); } @@ -430,9 +423,7 @@ UT_TEST(test_update_fork_preserves_native_self_three_state) return; start = strstr(source, "\ncluster_satisfies_update_fork(HeapTuple htup, CommandId curcid,"); end = start == NULL ? NULL : strstr(start, "\n}\n#endif /* USE_PGRAC_CLUSTER */"); - helper = start == NULL - ? NULL - : strstr(start, "cluster_vis_update_native_self_verdict("); + helper = start == NULL ? NULL : strstr(start, "cluster_vis_update_native_self_verdict("); entry = strstr( source, "cluster_satisfies_update_fork(htup, curcid, buffer, &cluster_res, writer_bridge)"); @@ -462,23 +453,21 @@ UT_TEST(test_update_fork_preserves_terminal_local_lock_only) if (source == NULL) return; start = strstr(source, - "if (xmin_remote_visible) {\n\t\tif (TransactionIdIsInProgress(raw_xmax))"); + "if (xmin_remote_visible) {\n\t\tif (TransactionIdIsInProgress(raw_xmax))"); end = start == NULL ? NULL : strstr(start, "\n\t}\n\n\treturn false;"); lock_only = start == NULL ? NULL : strstr(start, "else if (lock_only)"); lock_released = lock_only == NULL ? NULL : strstr(lock_only, "*res = TM_Ok;"); - committed_writer = start == NULL - ? NULL - : strstr(start, "else if (TransactionIdDidCommit(raw_xmax))"); + committed_writer + = start == NULL ? NULL : strstr(start, "else if (TransactionIdDidCommit(raw_xmax))"); UT_ASSERT_NOT_NULL(start); UT_ASSERT_NOT_NULL(end); UT_ASSERT_NOT_NULL(lock_only); UT_ASSERT_NOT_NULL(lock_released); UT_ASSERT_NOT_NULL(committed_writer); - if (start != NULL && end != NULL && lock_only != NULL - && lock_released != NULL && committed_writer != NULL) - UT_ASSERT(start < lock_only && lock_only < lock_released - && lock_released < committed_writer + if (start != NULL && end != NULL && lock_only != NULL && lock_released != NULL + && committed_writer != NULL) + UT_ASSERT(start < lock_only && lock_only < lock_released && lock_released < committed_writer && committed_writer < end); free(source); } @@ -500,20 +489,16 @@ UT_TEST(test_dirty_remote_xmax_wait_uses_exact_unlocked_route) const char *exact_wait; const char *research; - if (visibility_source == NULL || heap_source == NULL - || handler_source == NULL || nbtree_source == NULL) + if (visibility_source == NULL || heap_source == NULL || handler_source == NULL + || nbtree_source == NULL) goto done; - capture = strstr(visibility_source, - "cluster_vis_dirty_remote_xmax_waitable("); + capture = strstr(visibility_source, "cluster_vis_dirty_remote_xmax_waitable("); propagate = strstr(handler_source, "remote_xmax_wait"); wait_branch = strstr(nbtree_source, "if (remote_xmax_wait)"); - release_leaf = wait_branch == NULL - ? NULL - : strstr(wait_branch, "_bt_relbuf(rel, insertstate.buf);"); - exact_wait = wait_branch == NULL - ? NULL - : strstr(wait_branch, "cluster_tx_enqueue_wait_exact("); + release_leaf + = wait_branch == NULL ? NULL : strstr(wait_branch, "_bt_relbuf(rel, insertstate.buf);"); + exact_wait = wait_branch == NULL ? NULL : strstr(wait_branch, "cluster_tx_enqueue_wait_exact("); research = exact_wait == NULL ? NULL : strstr(exact_wait, "goto search;"); UT_ASSERT_NOT_NULL(capture); @@ -523,12 +508,9 @@ UT_TEST(test_dirty_remote_xmax_wait_uses_exact_unlocked_route) UT_ASSERT_NOT_NULL(release_leaf); UT_ASSERT_NOT_NULL(exact_wait); UT_ASSERT_NOT_NULL(research); - if (wait_branch != NULL && release_leaf != NULL && exact_wait != NULL - && research != NULL) - UT_ASSERT(wait_branch < release_leaf && release_leaf < exact_wait - && exact_wait < research); - UT_ASSERT(strstr(nbtree_source, - "XactLockTableWait(remote_wait_locator.xid") == NULL); + if (wait_branch != NULL && release_leaf != NULL && exact_wait != NULL && research != NULL) + UT_ASSERT(wait_branch < release_leaf && release_leaf < exact_wait && exact_wait < research); + UT_ASSERT(strstr(nbtree_source, "XactLockTableWait(remote_wait_locator.xid") == NULL); done: free(visibility_source); @@ -551,23 +533,23 @@ UT_TEST(test_mvcc_frozen_xmin_bypasses_remote_resolve_but_keeps_xmax_gate) if (source == NULL) return; - mvcc = strstr(source, - "if (cluster_enabled && BufferIsValid(buffer)"); - frozen = mvcc == NULL ? NULL : strstr(mvcc, - "if (!cluster_vis_xmin_needs_resolution(tuple->t_infomask))"); - xmax_gate = frozen == NULL ? NULL : strstr(frozen, - "cluster_remote_live_xmax_keeps_visible(buffer, tuple, snapshot)"); - xmin_resolve = mvcc == NULL ? NULL : strstr(mvcc, - "cluster_visibility_resolve_from_ref_scn(raw_xmin"); + mvcc = strstr(source, "if (cluster_enabled && BufferIsValid(buffer)"); + frozen = mvcc == NULL + ? NULL + : strstr(mvcc, "if (!cluster_vis_xmin_needs_resolution(tuple->t_infomask))"); + xmax_gate + = frozen == NULL + ? NULL + : strstr(frozen, "cluster_remote_live_xmax_keeps_visible(buffer, tuple, snapshot)"); + xmin_resolve + = mvcc == NULL ? NULL : strstr(mvcc, "cluster_visibility_resolve_from_ref_scn(raw_xmin"); UT_ASSERT_NOT_NULL(mvcc); UT_ASSERT_NOT_NULL(frozen); UT_ASSERT_NOT_NULL(xmax_gate); UT_ASSERT_NOT_NULL(xmin_resolve); - if (mvcc != NULL && frozen != NULL && xmax_gate != NULL - && xmin_resolve != NULL) - UT_ASSERT(mvcc < frozen && frozen < xmax_gate - && xmax_gate < xmin_resolve); + if (mvcc != NULL && frozen != NULL && xmax_gate != NULL && xmin_resolve != NULL) + UT_ASSERT(mvcc < frozen && frozen < xmax_gate && xmax_gate < xmin_resolve); free(source); } @@ -589,20 +571,16 @@ UT_TEST(test_normal_commit_stamp_is_modifier_gated_and_error_safe) return; start = strstr(source, "\ncluster_tt_local_precommit_durable_finish("); end = start == NULL ? NULL : strstr(start, "\n}\n\nvoid\ncluster_tt_local_record_commit("); - published = start == NULL ? NULL - : strstr(start, "cluster_tt_local_get_published_binding(xid, &binding)"); + published = start == NULL + ? NULL + : strstr(start, "cluster_tt_local_get_published_binding(xid, &binding)"); enter = start == NULL ? NULL : strstr(start, "cluster_semantic_activation_modifier_enter("); try_block = start == NULL ? NULL : strstr(start, "PG_TRY();"); - recheck = start == NULL - ? NULL - : strstr(start, "cluster_tt_local_modifier_recheck_or_error("); - durable = recheck == NULL - ? NULL - : strstr(recheck, "cluster_tt_slot_durable_commit_writeonly("); + recheck = start == NULL ? NULL : strstr(start, "cluster_tt_local_modifier_recheck_or_error("); + durable = recheck == NULL ? NULL : strstr(recheck, "cluster_tt_slot_durable_commit_writeonly("); finally_block = start == NULL ? NULL : strstr(start, "PG_FINALLY();"); - leave = finally_block == NULL - ? NULL - : strstr(finally_block, "cluster_semantic_activation_leave("); + leave = finally_block == NULL ? NULL + : strstr(finally_block, "cluster_semantic_activation_leave("); UT_ASSERT_NOT_NULL(start); UT_ASSERT_NOT_NULL(end); @@ -641,24 +619,23 @@ UT_TEST(test_ordinary_abort_durable_receipt_precedes_allocator_reuse) free(tt_source); return; } - abort_start = strstr(xact_source, - "\nRecordTransactionAbort(bool isSubXact)\n{"); - preabort = abort_start == NULL ? NULL : strstr(abort_start, - "cluster_tt_local_preabort_durable_finish(xid)"); + abort_start = strstr(xact_source, "\nRecordTransactionAbort(bool isSubXact)\n{"); + preabort = abort_start == NULL + ? NULL + : strstr(abort_start, "cluster_tt_local_preabort_durable_finish(xid)"); crit = abort_start == NULL ? NULL : strstr(abort_start, "START_CRIT_SECTION();"); - record_abort = crit == NULL ? NULL : strstr(crit, - "cluster_tt_local_record_abort(xid)"); - local_preabort = strstr(tt_source, - "cluster_tt_local_preabort_durable_finish(TransactionId xid)"); - exact_abort = local_preabort == NULL ? NULL : strstr(local_preabort, - "cluster_tt_slot_durable_abort_exact("); - receipt = exact_abort == NULL ? NULL : strstr(exact_abort, - "CLUSTER_TT_LOCAL_TERMINAL_ABORT_DURABLE"); + record_abort = crit == NULL ? NULL : strstr(crit, "cluster_tt_local_record_abort(xid)"); + local_preabort + = strstr(tt_source, "cluster_tt_local_preabort_durable_finish(TransactionId xid)"); + exact_abort = local_preabort == NULL + ? NULL + : strstr(local_preabort, "cluster_tt_slot_durable_abort_exact("); + receipt = exact_abort == NULL ? NULL + : strstr(exact_abort, "CLUSTER_TT_LOCAL_TERMINAL_ABORT_DURABLE"); finish = strstr(tt_source, "cluster_tt_local_finish_bindings(bool committed"); - terminal_gate = finish == NULL ? NULL : strstr(finish, - "CLUSTER_TT_LOCAL_TERMINAL_ABORT_DURABLE"); - mark_aborted = finish == NULL ? NULL : strstr(finish, - "cluster_tt_slot_mark_aborted("); + terminal_gate + = finish == NULL ? NULL : strstr(finish, "CLUSTER_TT_LOCAL_TERMINAL_ABORT_DURABLE"); + mark_aborted = finish == NULL ? NULL : strstr(finish, "cluster_tt_slot_mark_aborted("); UT_ASSERT_NOT_NULL(abort_start); UT_ASSERT_NOT_NULL(preabort); @@ -670,10 +647,8 @@ UT_TEST(test_ordinary_abort_durable_receipt_precedes_allocator_reuse) UT_ASSERT_NOT_NULL(finish); UT_ASSERT_NOT_NULL(terminal_gate); UT_ASSERT_NOT_NULL(mark_aborted); - if (abort_start != NULL && preabort != NULL && crit != NULL - && record_abort != NULL) - UT_ASSERT(abort_start < preabort && preabort < crit - && crit < record_abort); + if (abort_start != NULL && preabort != NULL && crit != NULL && record_abort != NULL) + UT_ASSERT(abort_start < preabort && preabort < crit && crit < record_abort); if (local_preabort != NULL && exact_abort != NULL && receipt != NULL) UT_ASSERT(local_preabort < exact_abort && exact_abort < receipt); if (finish != NULL && terminal_gate != NULL && mark_aborted != NULL) @@ -697,14 +672,12 @@ UT_TEST(test_deleting_xmax_error_names_actual_xmax) if (source == NULL) return; - message = strstr(source, - "errmsg(\"cluster TT status unknown for deleting xmax of xid %u\""); + message = strstr(source, "errmsg(\"cluster TT status unknown for deleting xmax of xid %u\""); hint = message != NULL ? strstr(message, "errhint(") : NULL; - actual_xmax = message != NULL - ? strstr(message, "HeapTupleHeaderGetRawXmax(tuple)") : NULL; + actual_xmax = message != NULL ? strstr(message, "HeapTupleHeaderGetRawXmax(tuple)") : NULL; wrong_xmin = message != NULL ? strstr(message, "raw_xmin),") : NULL; - wrong_hint = message != NULL - ? strstr(message, "Remote deleter commit state not yet propagated") : NULL; + wrong_hint = message != NULL ? strstr(message, "Remote deleter commit state not yet propagated") + : NULL; UT_ASSERT_NOT_NULL(message); UT_ASSERT_NOT_NULL(hint); @@ -737,29 +710,16 @@ UT_TEST(test_tt_retention_rollover_follower_reclassifies_current_segment) if (source == NULL) return; start = strstr(source, "\ncluster_tt_local_reserve_binding("); - end = start == NULL - ? NULL - : strstr(start, "\n}\n\n/*\n * cluster_tt_local_peek_binding"); + end = start == NULL ? NULL : strstr(start, "\n}\n\n/*\n * cluster_tt_local_peek_binding"); retry_loop = start == NULL ? NULL : strstr(start, "for (;;)"); - classify = retry_loop == NULL - ? NULL - : strstr(retry_loop, - "cluster_tt_slot_alloc_current_exact("); - drift_retry = classify == NULL - ? NULL - : strstr(classify, "if (current_drift)"); - rollover = classify == NULL - ? NULL - : strstr(classify, "cluster_undo_tt_rollover_locked("); - one_shot = rollover == NULL - ? NULL - : strstr(rollover, "cluster_tt_slot_alloc(seg, top_xid)"); - fresh_error = rollover == NULL - ? NULL - : strstr(rollover, "fresh rollover segment"); - late_wrap_read = classify == NULL - ? NULL - : strstr(classify, "cluster_tt_slot_get_wrap(seg, off)"); + classify + = retry_loop == NULL ? NULL : strstr(retry_loop, "cluster_tt_slot_alloc_current_exact("); + drift_retry = classify == NULL ? NULL : strstr(classify, "if (current_drift)"); + rollover = classify == NULL ? NULL : strstr(classify, "cluster_undo_tt_rollover_locked("); + one_shot = rollover == NULL ? NULL : strstr(rollover, "cluster_tt_slot_alloc(seg, top_xid)"); + fresh_error = rollover == NULL ? NULL : strstr(rollover, "fresh rollover segment"); + late_wrap_read + = classify == NULL ? NULL : strstr(classify, "cluster_tt_slot_get_wrap(seg, off)"); UT_ASSERT_NOT_NULL(start); UT_ASSERT_NOT_NULL(end); @@ -793,24 +753,29 @@ UT_TEST(test_canonical_active_is_prepared_before_heap_content_lock) free(tt_source); return; } - prepare = strstr(tt_source, - "cluster_tt_local_prepare_canonical_active(TransactionId top_xid"); - publish = prepare == NULL ? NULL : strstr(prepare, - "cluster_tt_slot_durable_publish_active("); - published_accessor = strstr(tt_source, - "cluster_tt_local_get_published_binding(TransactionId top_xid"); + prepare = strstr(tt_source, "cluster_tt_local_prepare_canonical_active(TransactionId top_xid"); + publish = prepare == NULL ? NULL : strstr(prepare, "cluster_tt_slot_durable_publish_active("); + published_accessor + = strstr(tt_source, "cluster_tt_local_get_published_binding(TransactionId top_xid"); UT_ASSERT_NOT_NULL(prepare); UT_ASSERT_NOT_NULL(publish); UT_ASSERT_NOT_NULL(published_accessor); UT_ASSERT(strstr(heap_source, "cluster_tt_local_get_or_create_binding(") == NULL); UT_ASSERT(strstr(heap_source, "canonical_xid = GetTopTransactionId();") != NULL); - UT_ASSERT(strstr(heap_source, - "cluster_tt_local_prepare_canonical_active(\n\t\t\tcanonical_xid, &canonical_binding)") != NULL); - UT_ASSERT(strstr(heap_source, - "cluster_tt_local_get_published_binding(\n\t\t\t\tcanonical_xid, &canonical_binding)") != NULL); - UT_ASSERT(strstr(heap_source, - "cluster_tt_local_prepare_canonical_active(xid, &canonical_binding)") == NULL); + UT_ASSERT( + strstr( + heap_source, + "cluster_tt_local_prepare_canonical_active(\n\t\t\tcanonical_xid, &canonical_binding)") + != NULL); + UT_ASSERT( + strstr( + heap_source, + "cluster_tt_local_get_published_binding(\n\t\t\t\tcanonical_xid, &canonical_binding)") + != NULL); + UT_ASSERT( + strstr(heap_source, "cluster_tt_local_prepare_canonical_active(xid, &canonical_binding)") + == NULL); UT_ASSERT(strstr(tt_source, "CLUSTER_CANONICAL_TXN_PUBLISHED") != NULL); free(heap_source); @@ -832,10 +797,10 @@ UT_TEST(test_writer_proof_entry_excludes_native_inplace_and_keyshare_shortcuts) cursor++; } UT_ASSERT_EQ(count, 3); - UT_ASSERT( - strstr(source, "if (wait)\n\t\tresult = HeapTupleSatisfiesUpdateForWriter(&tp, cid, " - "buffer);\n\telse\n\t\tresult = HeapTupleSatisfiesUpdate(&tp, cid, buffer);") - != NULL); + UT_ASSERT(strstr(source, + "if (wait)\n\t\tresult = HeapTupleSatisfiesUpdateForWriter(&tp, cid, " + "buffer);\n\telse\n\t\tresult = HeapTupleSatisfiesUpdate(&tp, cid, buffer);") + != NULL); UT_ASSERT( strstr(source, "if (wait)\n\t\tresult = HeapTupleSatisfiesUpdateForWriter(&oldtup, cid, " diff --git a/src/test/cluster_unit/test_cluster_visibility_inject.c b/src/test/cluster_unit/test_cluster_visibility_inject.c index c7226e56d19..73cfa4fec88 100644 --- a/src/test/cluster_unit/test_cluster_visibility_inject.c +++ b/src/test/cluster_unit/test_cluster_visibility_inject.c @@ -99,8 +99,8 @@ cluster_visibility_inject_shmem_register(void) ClusterSemanticAdmissionResult cluster_tt_status_source_dispatch(ClusterTTStatusSourceOp op pg_attribute_unused(), - const ClusterTTStatusSourceRequest *request pg_attribute_unused(), - ClusterTTStatusSourceResult *result pg_attribute_unused()) + const ClusterTTStatusSourceRequest *request pg_attribute_unused(), + ClusterTTStatusSourceResult *result pg_attribute_unused()) { return CLUSTER_SEMANTIC_ADMISSION_CLOSED; } diff --git a/src/test/cluster_unit/test_cluster_visibility_variants.c b/src/test/cluster_unit/test_cluster_visibility_variants.c index 1a5b503addc..b8f42ee2268 100644 --- a/src/test/cluster_unit/test_cluster_visibility_variants.c +++ b/src/test/cluster_unit/test_cluster_visibility_variants.c @@ -196,18 +196,12 @@ UT_TEST(test_obs3_dirty_full_table) * terminal outcome or unexpected SUBCOMMITTED value never opens the route. */ UT_TEST(test_obs3_dirty_exact_remote_xmax_wait_gate) { - UT_ASSERT(cluster_vis_dirty_remote_xmax_waitable( - CLUSTER_TT_STATUS_IN_PROGRESS, true, true)); - UT_ASSERT(!cluster_vis_dirty_remote_xmax_waitable( - CLUSTER_TT_STATUS_IN_PROGRESS, true, false)); - UT_ASSERT(!cluster_vis_dirty_remote_xmax_waitable( - CLUSTER_TT_STATUS_IN_PROGRESS, false, true)); - UT_ASSERT(!cluster_vis_dirty_remote_xmax_waitable( - CLUSTER_TT_STATUS_SUBCOMMITTED, true, true)); - UT_ASSERT(!cluster_vis_dirty_remote_xmax_waitable( - CLUSTER_TT_STATUS_COMMITTED, true, true)); - UT_ASSERT(!cluster_vis_dirty_remote_xmax_waitable( - CLUSTER_TT_STATUS_ABORTED, true, true)); + UT_ASSERT(cluster_vis_dirty_remote_xmax_waitable(CLUSTER_TT_STATUS_IN_PROGRESS, true, true)); + UT_ASSERT(!cluster_vis_dirty_remote_xmax_waitable(CLUSTER_TT_STATUS_IN_PROGRESS, true, false)); + UT_ASSERT(!cluster_vis_dirty_remote_xmax_waitable(CLUSTER_TT_STATUS_IN_PROGRESS, false, true)); + UT_ASSERT(!cluster_vis_dirty_remote_xmax_waitable(CLUSTER_TT_STATUS_SUBCOMMITTED, true, true)); + UT_ASSERT(!cluster_vis_dirty_remote_xmax_waitable(CLUSTER_TT_STATUS_COMMITTED, true, true)); + UT_ASSERT(!cluster_vis_dirty_remote_xmax_waitable(CLUSTER_TT_STATUS_ABORTED, true, true)); } /* ---- meta: no status maps to an out-of-range verdict (exhaustive sweep) ---- */ diff --git a/src/test/cluster_unit/test_cluster_voting_disk_io.c b/src/test/cluster_unit/test_cluster_voting_disk_io.c index 5283bbd244a..6d52e909025 100644 --- a/src/test/cluster_unit/test_cluster_voting_disk_io.c +++ b/src/test/cluster_unit/test_cluster_voting_disk_io.c @@ -385,15 +385,14 @@ UT_TEST(test_io_9_marker_regions_are_disjoint) UT_ASSERT(CLUSTER_VOTING_STRIPE_SLOT_OFFSET(0) == (off_t)4 * CLUSTER_MAX_NODES * CLUSTER_VOTING_SLOT_BYTES); UT_ASSERT(CLUSTER_VOTING_STRIPE_ACTIVATION_OFFSET - == (off_t)5 * CLUSTER_MAX_NODES * CLUSTER_VOTING_SLOT_BYTES); + == (off_t)5 * CLUSTER_MAX_NODES * CLUSTER_VOTING_SLOT_BYTES); UT_ASSERT_EQ(CLUSTER_VOTING_PGSA_SLOT_OFFSET, (off_t)328192); UT_ASSERT_EQ(CLUSTER_EPOCH_BALLOT_SLOT(0), 642); UT_ASSERT_EQ(CLUSTER_EPOCH_BALLOT_SLOT(CLUSTER_MAX_NODES - 1), 769); UT_ASSERT_EQ(CLUSTER_VOTING_EPOCH_BALLOT_SLOT_OFFSET(0), (off_t)328704); - UT_ASSERT_EQ(CLUSTER_VOTING_EPOCH_BALLOT_SLOT_OFFSET(CLUSTER_MAX_NODES - 1), - (off_t)393728); + UT_ASSERT_EQ(CLUSTER_VOTING_EPOCH_BALLOT_SLOT_OFFSET(CLUSTER_MAX_NODES - 1), (off_t)393728); UT_ASSERT(CLUSTER_VOTING_FILE_BYTES_MIN - == (off_t)(6 * CLUSTER_MAX_NODES + 2) * CLUSTER_VOTING_SLOT_BYTES); + == (off_t)(6 * CLUSTER_MAX_NODES + 2) * CLUSTER_VOTING_SLOT_BYTES); UT_ASSERT_EQ(CLUSTER_VOTING_FILE_BYTES_MIN, (off_t)394240); UT_ASSERT_EQ(CLUSTER_VOTING_PGSA_SLOT_OFFSET + CLUSTER_VOTING_SLOT_BYTES, CLUSTER_VOTING_EPOCH_BALLOT_SLOT_OFFSET(0)); @@ -488,8 +487,7 @@ UT_TEST(test_io_12_raw_tail_write_lazily_extends_old_file) UT_ASSERT_EQ(cluster_voting_disk_write_raw_tail_slot(fd, in), CLUSTER_VOTING_DISK_IO_OK); UT_ASSERT_EQ(fstat(fd, &st), 0); - UT_ASSERT_EQ(st.st_size, - CLUSTER_VOTING_PGSA_SLOT_OFFSET + (off_t)CLUSTER_VOTING_SLOT_BYTES); + UT_ASSERT_EQ(st.st_size, CLUSTER_VOTING_PGSA_SLOT_OFFSET + (off_t)CLUSTER_VOTING_SLOT_BYTES); memset(out, 0, sizeof(out)); UT_ASSERT_EQ(cluster_voting_disk_read_raw_tail_slot(fd, out), @@ -584,12 +582,10 @@ UT_TEST(test_io_15_epoch_ballot_slots_round_trip_without_aliasing) CLUSTER_VOTING_DISK_IO_OK); memset(out, 0, sizeof(out)); - UT_ASSERT_EQ(cluster_voting_disk_read_epoch_ballot_slot(fd, 0, out), - CLUSTER_VOTING_DISK_IO_OK); + UT_ASSERT_EQ(cluster_voting_disk_read_epoch_ballot_slot(fd, 0, out), CLUSTER_VOTING_DISK_IO_OK); UT_ASSERT_EQ(memcmp(out, lane0, sizeof(out)), 0); memset(out, 0, sizeof(out)); - UT_ASSERT_EQ(cluster_voting_disk_read_epoch_ballot_slot(fd, 1, out), - CLUSTER_VOTING_DISK_IO_OK); + UT_ASSERT_EQ(cluster_voting_disk_read_epoch_ballot_slot(fd, 1, out), CLUSTER_VOTING_DISK_IO_OK); UT_ASSERT_EQ(memcmp(out, lane1, sizeof(out)), 0); memset(out, 0, sizeof(out)); UT_ASSERT_EQ(cluster_voting_disk_read_epoch_ballot_slot(fd, CLUSTER_MAX_NODES - 1, out), diff --git a/src/test/cluster_unit/test_cluster_wal_retention.c b/src/test/cluster_unit/test_cluster_wal_retention.c index 33f53a3d3da..e8ab2df6b6e 100644 --- a/src/test/cluster_unit/test_cluster_wal_retention.c +++ b/src/test/cluster_unit/test_cluster_wal_retention.c @@ -48,12 +48,10 @@ static ClusterLockAcquireResult fake_acquire_results[4]; static int fake_acquire_result_count; static int fake_acquire_call_count; static ClusterLockAcquireRequest fake_acquire_requests[4]; -static ClusterLockAcquireResult fake_release_result = - CLUSTER_LOCK_ACQUIRE_OK_GRANTED; +static ClusterLockAcquireResult fake_release_result = CLUSTER_LOCK_ACQUIRE_OK_GRANTED; static int fake_release_call_count; static uint16 fake_release_threads[4]; -static ClusterLockAcquireResult fake_s5_result = - CLUSTER_LOCK_ACQUIRE_OK_GRANTED; +static ClusterLockAcquireResult fake_s5_result = CLUSTER_LOCK_ACQUIRE_OK_GRANTED; static int fake_s5_call_count; static int fake_s7_call_count; static LockAcquireResult fake_native_acquire_result = LOCKACQUIRE_OK; @@ -72,10 +70,8 @@ static ClusterControlRootSnapshot fake_preflight_root; static ClusterControlRootReadToken fake_preflight_token; static bool fake_preflight_root_ready; static bool fake_extra_configured_thread; -static PgracExternalFenceNeedSetResult fake_need_build_result = - PGRAC_EXTERNAL_FENCE_NEED_SET_OK; -static ClusterRecoverySerialRevalidateResult fake_serial_result = - CLUSTER_RECOVERY_SERIAL_CURRENT; +static PgracExternalFenceNeedSetResult fake_need_build_result = PGRAC_EXTERNAL_FENCE_NEED_SET_OK; +static ClusterRecoverySerialRevalidateResult fake_serial_result = CLUSTER_RECOVERY_SERIAL_CURRENT; void RegisterResourceReleaseCallback(ResourceReleaseCallback callback, void *arg) @@ -97,8 +93,7 @@ errstart_cold(int elevel, const char *domain) } void -errfinish(const char *filename pg_attribute_unused(), - int lineno pg_attribute_unused(), +errfinish(const char *filename pg_attribute_unused(), int lineno pg_attribute_unused(), const char *funcname pg_attribute_unused()) {} @@ -129,10 +124,8 @@ GetCurrentTimestamp(void) ClusterLockAcquireResult cluster_lock_acquire_seven_step(const ClusterLockAcquireRequest *request) { - ClusterLockAcquireRequest *mutable_request = - (ClusterLockAcquireRequest *)request; - ClusterLockAcquireResult result = - CLUSTER_LOCK_ACQUIRE_NEED_PG_NATIVE_LOCK; + ClusterLockAcquireRequest *mutable_request = (ClusterLockAcquireRequest *)request; + ClusterLockAcquireResult result = CLUSTER_LOCK_ACQUIRE_NEED_PG_NATIVE_LOCK; if (fake_acquire_call_count < lengthof(fake_acquire_requests)) fake_acquire_requests[fake_acquire_call_count] = *request; @@ -153,8 +146,7 @@ cluster_lock_acquire_seven_step(const ClusterLockAcquireRequest *request) ClusterLockAcquireResult cluster_lock_acquire_s5_promote(const ClusterLockAcquireRequest *request) { - ClusterLockAcquireRequest *mutable_request = - (ClusterLockAcquireRequest *)request; + ClusterLockAcquireRequest *mutable_request = (ClusterLockAcquireRequest *)request; fake_s5_call_count++; if (fake_s5_result == CLUSTER_LOCK_ACQUIRE_OK_GRANTED @@ -197,8 +189,7 @@ ClusterLockAcquireResult cluster_lock_acquire_s6_release(const ClusterLockAcquireRequest *request) { if (fake_release_call_count < lengthof(fake_release_threads)) - fake_release_threads[fake_release_call_count] = - (uint16)request->resid.field1; + fake_release_threads[fake_release_call_count] = (uint16)request->resid.field1; fake_release_call_count++; return fake_release_result; } @@ -218,22 +209,21 @@ cluster_control_root_revalidate(const ClusterControlRootReadToken *token, } ClusterControlRootResult -cluster_control_root_read_canonical( - uint16 origin_thread_id, const ClusterControlRootIdentity *expected_identity, - ClusterControlRootReadMode mode, - ClusterControlRootSnapshot *out_snapshot, - ClusterControlRootReadToken *out_token) +cluster_control_root_read_canonical(uint16 origin_thread_id, + const ClusterControlRootIdentity *expected_identity, + ClusterControlRootReadMode mode, + ClusterControlRootSnapshot *out_snapshot, + ClusterControlRootReadToken *out_token) { if (!fake_preflight_root_ready || origin_thread_id != 1) return CLUSTER_CONTROL_ROOT_ABSENT; - if (mode == CLUSTER_CONTROL_ROOT_READ_BOOTSTRAP_VALIDATE - && expected_identity == NULL) { + if (mode == CLUSTER_CONTROL_ROOT_READ_BOOTSTRAP_VALIDATE && expected_identity == NULL) { *out_snapshot = fake_preflight_root; return CLUSTER_CONTROL_ROOT_OK_PRIMARY; } if (expected_identity == NULL - || memcmp(expected_identity, &fake_preflight_root.identity, - sizeof(*expected_identity)) != 0) + || memcmp(expected_identity, &fake_preflight_root.identity, sizeof(*expected_identity)) + != 0) return CLUSTER_CONTROL_ROOT_ABSENT; *out_snapshot = fake_preflight_root; if (out_token != NULL) @@ -242,12 +232,11 @@ cluster_control_root_read_canonical( } ClusterFormationWitnessResult -cluster_formation_witness_build_live_wait( - uint16 origin_thread, int timeout_ms, - ClusterFormationWitnessV1 **out) +cluster_formation_witness_build_live_wait(uint16 origin_thread, int timeout_ms, + ClusterFormationWitnessV1 **out) { - if (!fake_formation_current || origin_thread != 1 || timeout_ms < 1 - || out == NULL || *out != NULL) + if (!fake_formation_current || origin_thread != 1 || timeout_ms < 1 || out == NULL + || *out != NULL) return CLUSTER_FORMATION_WITNESS_UNSTABLE; *out = (ClusterFormationWitnessV1 *)(uintptr_t)0x1000; return CLUSTER_FORMATION_WITNESS_READY; @@ -269,9 +258,8 @@ cluster_formation_witness_revalidate_nowait( bool cluster_formation_witness_copy_classification_v1( - const ClusterFormationWitnessV1 *witness pg_attribute_unused(), - uint16 *origin_thread, ClusterFenceAuthorityProof *authority, - ClusterFormationSnapshotV1 *snapshot) + const ClusterFormationWitnessV1 *witness pg_attribute_unused(), uint16 *origin_thread, + ClusterFenceAuthorityProof *authority, ClusterFormationSnapshotV1 *snapshot) { memset(authority, 0, sizeof(*authority)); memset(snapshot, 0, sizeof(*snapshot)); @@ -289,7 +277,7 @@ cluster_external_fence_need_set_revalidate_nowait( PgracExternalFenceDenyReason *reason) { *reason = fake_need_current ? PGRAC_EXTERNAL_FENCE_DENY_NONE - : PGRAC_EXTERNAL_FENCE_DENY_MAPPING_CHANGED; + : PGRAC_EXTERNAL_FENCE_DENY_MAPPING_CHANGED; return fake_need_current; } @@ -301,15 +289,15 @@ cluster_external_fence_revalidate_set_nowait( PgracExternalFenceDenyReason *reason) { *reason = fake_admission_current ? PGRAC_EXTERNAL_FENCE_DENY_NONE - : PGRAC_EXTERNAL_FENCE_DENY_EXPIRED; + : PGRAC_EXTERNAL_FENCE_DENY_EXPIRED; return fake_admission_current; } PgracExternalFenceNeedSetResult -cluster_external_fence_need_set_build( - const ClusterRecoveryDutyKey *duty pg_attribute_unused(), - const ClusterFormationWitnessV1 *formation pg_attribute_unused(), - PgracExternalFenceNeedSetV1 **out) +cluster_external_fence_need_set_build(const ClusterRecoveryDutyKey *duty pg_attribute_unused(), + const ClusterFormationWitnessV1 *formation + pg_attribute_unused(), + PgracExternalFenceNeedSetV1 **out) { if (fake_need_build_result == PGRAC_EXTERNAL_FENCE_NEED_SET_OK) *out = (PgracExternalFenceNeedSetV1 *)(uintptr_t)0x4000; @@ -323,15 +311,13 @@ cluster_external_fence_need_set_release(PgracExternalFenceNeedSetV1 **set) } uint32 -cluster_external_fence_need_set_count( - const PgracExternalFenceNeedSetV1 *set pg_attribute_unused()) +cluster_external_fence_need_set_count(const PgracExternalFenceNeedSetV1 *set pg_attribute_unused()) { return fake_need_count; } const PgracExternalFenceWriterSetDigest * -cluster_external_fence_need_set_digest( - const PgracExternalFenceNeedSetV1 *set pg_attribute_unused()) +cluster_external_fence_need_set_digest(const PgracExternalFenceNeedSetV1 *set pg_attribute_unused()) { return &fake_need_digest; } @@ -354,16 +340,14 @@ PgracExternalFenceVerdict cluster_external_fence_admit_set_wait( const PgracExternalFenceNeedSetV1 *needs pg_attribute_unused(), const ClusterFormationWitnessV1 *formation pg_attribute_unused(), - int timeout_ms pg_attribute_unused(), - PgracExternalFenceAdmissionSetV1 **out) + int timeout_ms pg_attribute_unused(), PgracExternalFenceAdmissionSetV1 **out) { *out = (PgracExternalFenceAdmissionSetV1 *)(uintptr_t)0x5000; return PGRAC_EXTERNAL_FENCE_WRITE_EXCLUDED; } void -cluster_external_fence_admission_set_release( - PgracExternalFenceAdmissionSetV1 **set) +cluster_external_fence_admission_set_release(PgracExternalFenceAdmissionSetV1 **set) { *set = NULL; } @@ -430,7 +414,7 @@ make_duty(uint16 thread_id) duty.origin_node_id = thread_id - 1; duty.thread_claim_created_at = 1000 + thread_id; cluster_wal_thread_claim_fill(&claim, thread_id, duty.origin_node_id, - duty.thread_claim_created_at); + duty.thread_claim_created_at); duty.thread_claim_crc32c = claim.crc; duty.origin_owner_incarnation = 10 + thread_id; duty.root_lineage_seq = 20 + thread_id; @@ -451,16 +435,14 @@ make_root_token(const ClusterRecoveryDutyKey *duty) token.file_txn_seq = 1; token.root_publish_seq = 1; token.record_crc32c = 1; - token.root_flags = CLUSTER_CONTROL_ROOT_FLAG_CLAIM_VALID - | CLUSTER_CONTROL_ROOT_FLAG_CHECKPOINT_VALID - | CLUSTER_CONTROL_ROOT_FLAG_TAIL_VALID - | CLUSTER_CONTROL_ROOT_FLAG_RECOVERED_VALID; + token.root_flags + = CLUSTER_CONTROL_ROOT_FLAG_CLAIM_VALID | CLUSTER_CONTROL_ROOT_FLAG_CHECKPOINT_VALID + | CLUSTER_CONTROL_ROOT_FLAG_TAIL_VALID | CLUSTER_CONTROL_ROOT_FLAG_RECOVERED_VALID; return token; } static ClusterWalRetentionPinThreadRequest -make_pin_request(uint16 thread_id, const ClusterWalRetentionInterval *intervals, - uint32 nintervals) +make_pin_request(uint16 thread_id, const ClusterWalRetentionInterval *intervals, uint32 nintervals) { ClusterWalRetentionPinThreadRequest request; @@ -471,8 +453,7 @@ make_pin_request(uint16 thread_id, const ClusterWalRetentionInterval *intervals, request.root_read = make_root_token(&request.duty); request.formation = (const ClusterFormationWitnessV1 *)(uintptr_t)0x1000; request.needs = (const PgracExternalFenceNeedSetV1 *)(uintptr_t)0x2000; - request.admissions = - (const PgracExternalFenceAdmissionSetV1 *)(uintptr_t)0x3000; + request.admissions = (const PgracExternalFenceAdmissionSetV1 *)(uintptr_t)0x3000; return request; } @@ -493,8 +474,8 @@ make_serial_guard(const ClusterWalRetentionPinThreadRequest *request) } static void -write_test_wal_segment(const char *directory, TimeLineID tli, - XLogSegNo segno, char *out_path, Size out_path_size) +write_test_wal_segment(const char *directory, TimeLineID tli, XLogSegNo segno, char *out_path, + Size out_path_size) { char wal_name[MAXFNAMELEN]; XLogLongPageHeaderData header; @@ -549,22 +530,15 @@ write_fixture_wal_segment(int argc, char **argv) bool created = false; bool ok = false; - if (argc != 8 - || !parse_fixture_u64(argv[3], &system_identifier) - || !parse_fixture_u64(argv[4], &thread_value) - || !parse_fixture_u64(argv[5], &tli_value) - || !parse_fixture_u64(argv[6], &segno_value) - || !parse_fixture_u64(argv[7], &segsize_value) - || system_identifier == 0 - || thread_value == 0 - || thread_value > CLUSTER_WAL_RETENTION_MAX_THREADS - || tli_value == 0 || tli_value > UINT32_MAX - || segsize_value > INT_MAX - || !IsValidWalSegSize((int)segsize_value) - || segno_value > UINT64_MAX / segsize_value) + if (argc != 8 || !parse_fixture_u64(argv[3], &system_identifier) + || !parse_fixture_u64(argv[4], &thread_value) || !parse_fixture_u64(argv[5], &tli_value) + || !parse_fixture_u64(argv[6], &segno_value) || !parse_fixture_u64(argv[7], &segsize_value) + || system_identifier == 0 || thread_value == 0 + || thread_value > CLUSTER_WAL_RETENTION_MAX_THREADS || tli_value == 0 + || tli_value > UINT32_MAX || segsize_value > INT_MAX + || !IsValidWalSegSize((int)segsize_value) || segno_value > UINT64_MAX / segsize_value) return 2; - XLogFileName(expected_name, (TimeLineID)tli_value, - (XLogSegNo)segno_value, (int)segsize_value); + XLogFileName(expected_name, (TimeLineID)tli_value, (XLogSegNo)segno_value, (int)segsize_value); basename = strrchr(argv[2], '/'); basename = basename == NULL ? argv[2] : basename + 1; if (strcmp(basename, expected_name) != 0) @@ -584,8 +558,7 @@ write_fixture_wal_segment(int argc, char **argv) header.xlp_sysid = system_identifier; header.xlp_seg_size = (uint32)segsize_value; header.xlp_xlog_blcksz = XLOG_BLCKSZ; - if (pwrite(fd, &header, sizeof(header), 0) != sizeof(header) - || fsync(fd) != 0) + if (pwrite(fd, &header, sizeof(header), 0) != sizeof(header) || fsync(fd) != 0) goto done; ok = true; @@ -598,15 +571,13 @@ write_fixture_wal_segment(int argc, char **argv) } static void -prepare_bound_recovery_guard( - ClusterWalReuseActionGuard *guard, - const ClusterWalRetentionPinThreadRequest *request) +prepare_bound_recovery_guard(ClusterWalReuseActionGuard *guard, + const ClusterWalRetentionPinThreadRequest *request) { ClusterWalReuseDenyReason reason; memset(guard, 0, sizeof(*guard)); - UT_ASSERT_EQ(cluster_wal_reuse_guard_init(guard, &reason), - CLUSTER_WAL_GUARD_OK); + UT_ASSERT_EQ(cluster_wal_reuse_guard_init(guard, &reason), CLUSTER_WAL_GUARD_OK); guard->state = CLUSTER_WAL_GUARD_FENCE_ADMITTED_OR_NA; guard->entry = CLUSTER_WAL_REUSE_E1_CHECKPOINT_RESTARTPOINT; guard->action = CLUSTER_WAL_ACTION_RETIRE_RECYCLE_OR_REMOVE; @@ -622,8 +593,8 @@ prepare_bound_recovery_guard( } static ClusterControlRootSnapshot -make_root(uint16 thread_id, ClusterControlRootLifecycle lifecycle, - TimeLineID tli, XLogRecPtr lower, XLogRecPtr tail) +make_root(uint16 thread_id, ClusterControlRootLifecycle lifecycle, TimeLineID tli, XLogRecPtr lower, + XLogRecPtr tail) { ClusterControlRootSnapshot root; @@ -637,8 +608,8 @@ make_root(uint16 thread_id, ClusterControlRootLifecycle lifecycle, root.identity.root_lineage_seq = 1; root.lifecycle = lifecycle; root.root_publish_seq = 1; - root.root_flags = CLUSTER_CONTROL_ROOT_FLAG_CLAIM_VALID - | CLUSTER_CONTROL_ROOT_FLAG_CHECKPOINT_VALID; + root.root_flags + = CLUSTER_CONTROL_ROOT_FLAG_CLAIM_VALID | CLUSTER_CONTROL_ROOT_FLAG_CHECKPOINT_VALID; root.checkpoint_tli = tli; root.checkpoint_source_kind = CLUSTER_CONTROL_ROOT_CHECKPOINT_NATIVE_V1; root.checkpoint_lower_lsn = lower; @@ -659,7 +630,7 @@ make_root(uint16 thread_id, ClusterControlRootLifecycle lifecycle, static ClusterWalRootFoldInput make_fold_input(bool configured, ClusterControlRootResult read_result, - ClusterControlRootSnapshot root) + ClusterControlRootSnapshot root) { ClusterWalRootFoldInput input; @@ -707,8 +678,8 @@ UT_TEST(test_wal_basename_exact_parse) ClusterWalFileIdentity file; memset(&file, 0x5a, sizeof(file)); - UT_ASSERT_TRUE(cluster_wal_file_identity_parse( - "000000020000000100000003", 7, TEST_WAL_SEG_SIZE, &file)); + UT_ASSERT_TRUE( + cluster_wal_file_identity_parse("000000020000000100000003", 7, TEST_WAL_SEG_SIZE, &file)); UT_ASSERT_EQ(file.thread_id, 7); UT_ASSERT_EQ(file.kind, CLUSTER_WAL_FILE_NORMAL); UT_ASSERT_EQ(file.reserved_zero, 0); @@ -716,8 +687,8 @@ UT_TEST(test_wal_basename_exact_parse) UT_ASSERT_EQ(file.segno, 259); UT_ASSERT_TRUE(cluster_wal_file_identity_valid(&file, TEST_WAL_SEG_SIZE)); - UT_ASSERT_TRUE(cluster_wal_file_identity_parse( - "000000020000000100000003.partial", 7, TEST_WAL_SEG_SIZE, &file)); + UT_ASSERT_TRUE(cluster_wal_file_identity_parse("000000020000000100000003.partial", 7, + TEST_WAL_SEG_SIZE, &file)); UT_ASSERT_EQ(file.kind, CLUSTER_WAL_FILE_PARTIAL); UT_ASSERT_EQ(file.segno, 259); } @@ -727,23 +698,23 @@ UT_TEST(test_wal_basename_refuses_aliases) ClusterWalFileIdentity file; memset(&file, 0x5a, sizeof(file)); - UT_ASSERT_FALSE(cluster_wal_file_identity_parse( - "000000020000000100000003.done", 7, TEST_WAL_SEG_SIZE, &file)); + UT_ASSERT_FALSE(cluster_wal_file_identity_parse("000000020000000100000003.done", 7, + TEST_WAL_SEG_SIZE, &file)); UT_ASSERT_EQ(file.thread_id, 0); - UT_ASSERT_FALSE(cluster_wal_file_identity_parse( - "000000020000000100000003.partial.extra", 7, TEST_WAL_SEG_SIZE, &file)); - UT_ASSERT_FALSE(cluster_wal_file_identity_parse( - "00000002000000010000000a", 7, TEST_WAL_SEG_SIZE, &file)); - UT_ASSERT_FALSE(cluster_wal_file_identity_parse( - "000000000000000100000003", 7, TEST_WAL_SEG_SIZE, &file)); - UT_ASSERT_FALSE(cluster_wal_file_identity_parse( - "000000020000000100000100", 7, TEST_WAL_SEG_SIZE, &file)); - UT_ASSERT_FALSE(cluster_wal_file_identity_parse( - "000000020000000100000003", 0, TEST_WAL_SEG_SIZE, &file)); - UT_ASSERT_FALSE(cluster_wal_file_identity_parse( - "000000020000000100000003", 129, TEST_WAL_SEG_SIZE, &file)); - UT_ASSERT_FALSE(cluster_wal_file_identity_parse( - "000000020000000100000003", 7, 3 * 1024 * 1024, &file)); + UT_ASSERT_FALSE(cluster_wal_file_identity_parse("000000020000000100000003.partial.extra", 7, + TEST_WAL_SEG_SIZE, &file)); + UT_ASSERT_FALSE( + cluster_wal_file_identity_parse("00000002000000010000000a", 7, TEST_WAL_SEG_SIZE, &file)); + UT_ASSERT_FALSE( + cluster_wal_file_identity_parse("000000000000000100000003", 7, TEST_WAL_SEG_SIZE, &file)); + UT_ASSERT_FALSE( + cluster_wal_file_identity_parse("000000020000000100000100", 7, TEST_WAL_SEG_SIZE, &file)); + UT_ASSERT_FALSE( + cluster_wal_file_identity_parse("000000020000000100000003", 0, TEST_WAL_SEG_SIZE, &file)); + UT_ASSERT_FALSE( + cluster_wal_file_identity_parse("000000020000000100000003", 129, TEST_WAL_SEG_SIZE, &file)); + UT_ASSERT_FALSE( + cluster_wal_file_identity_parse("000000020000000100000003", 7, 3 * 1024 * 1024, &file)); } UT_TEST(test_long_header_exact_identity) @@ -752,8 +723,8 @@ UT_TEST(test_long_header_exact_identity) XLogLongPageHeaderData header; uint64 system_identifier = UINT64_C(0x1122334455667788); - UT_ASSERT_TRUE(cluster_wal_file_identity_parse( - "000000020000000100000003", 7, TEST_WAL_SEG_SIZE, &file)); + UT_ASSERT_TRUE( + cluster_wal_file_identity_parse("000000020000000100000003", 7, TEST_WAL_SEG_SIZE, &file)); memset(&header, 0, sizeof(header)); header.std.xlp_magic = XLOG_PAGE_MAGIC; header.std.xlp_info = XLP_LONG_HEADER; @@ -763,80 +734,72 @@ UT_TEST(test_long_header_exact_identity) header.xlp_sysid = system_identifier; header.xlp_seg_size = TEST_WAL_SEG_SIZE; header.xlp_xlog_blcksz = XLOG_BLCKSZ; - UT_ASSERT_TRUE(cluster_wal_file_long_header_matches( - &file, &header, system_identifier, TEST_WAL_SEG_SIZE)); + UT_ASSERT_TRUE( + cluster_wal_file_long_header_matches(&file, &header, system_identifier, TEST_WAL_SEG_SIZE)); header.std.xlp_thread_id++; - UT_ASSERT_FALSE(cluster_wal_file_long_header_matches( - &file, &header, system_identifier, TEST_WAL_SEG_SIZE)); + UT_ASSERT_FALSE( + cluster_wal_file_long_header_matches(&file, &header, system_identifier, TEST_WAL_SEG_SIZE)); header.std.xlp_thread_id--; header.std.xlp_tli++; - UT_ASSERT_FALSE(cluster_wal_file_long_header_matches( - &file, &header, system_identifier, TEST_WAL_SEG_SIZE)); + UT_ASSERT_FALSE( + cluster_wal_file_long_header_matches(&file, &header, system_identifier, TEST_WAL_SEG_SIZE)); header.std.xlp_tli--; header.std.xlp_pageaddr += XLOG_BLCKSZ; - UT_ASSERT_FALSE(cluster_wal_file_long_header_matches( - &file, &header, system_identifier, TEST_WAL_SEG_SIZE)); + UT_ASSERT_FALSE( + cluster_wal_file_long_header_matches(&file, &header, system_identifier, TEST_WAL_SEG_SIZE)); header.std.xlp_pageaddr -= XLOG_BLCKSZ; header.xlp_sysid++; - UT_ASSERT_FALSE(cluster_wal_file_long_header_matches( - &file, &header, system_identifier, TEST_WAL_SEG_SIZE)); + UT_ASSERT_FALSE( + cluster_wal_file_long_header_matches(&file, &header, system_identifier, TEST_WAL_SEG_SIZE)); } UT_TEST(test_interval_half_open_segment_bounds) { - ClusterWalRetentionInterval interval = { - .thread_id = 7, - .tli = 2, - .start_lsn = (XLogRecPtr)TEST_WAL_SEG_SIZE + 1, - .end_lsn = (XLogRecPtr)TEST_WAL_SEG_SIZE * 3 - }; + ClusterWalRetentionInterval interval = { .thread_id = 7, + .tli = 2, + .start_lsn = (XLogRecPtr)TEST_WAL_SEG_SIZE + 1, + .end_lsn = (XLogRecPtr)TEST_WAL_SEG_SIZE * 3 }; XLogSegNo first = 999; XLogSegNo last = 999; - UT_ASSERT_TRUE(cluster_wal_retention_interval_segment_bounds( - &interval, TEST_WAL_SEG_SIZE, &first, &last)); + UT_ASSERT_TRUE( + cluster_wal_retention_interval_segment_bounds(&interval, TEST_WAL_SEG_SIZE, &first, &last)); UT_ASSERT_EQ(first, 1); UT_ASSERT_EQ(last, 2); interval.end_lsn = interval.start_lsn; - UT_ASSERT_FALSE(cluster_wal_retention_interval_segment_bounds( - &interval, TEST_WAL_SEG_SIZE, &first, &last)); + UT_ASSERT_FALSE( + cluster_wal_retention_interval_segment_bounds(&interval, TEST_WAL_SEG_SIZE, &first, &last)); UT_ASSERT_EQ(first, 0); UT_ASSERT_EQ(last, 0); interval.start_lsn = 0; interval.end_lsn = 1; - UT_ASSERT_FALSE(cluster_wal_retention_interval_segment_bounds( - &interval, TEST_WAL_SEG_SIZE, &first, &last)); + UT_ASSERT_FALSE( + cluster_wal_retention_interval_segment_bounds(&interval, TEST_WAL_SEG_SIZE, &first, &last)); } UT_TEST(test_interval_intersection_requires_thread_and_tli) { - ClusterWalRetentionInterval interval = { - .thread_id = 7, - .tli = 2, - .start_lsn = (XLogRecPtr)TEST_WAL_SEG_SIZE, - .end_lsn = (XLogRecPtr)TEST_WAL_SEG_SIZE * 3 - }; - ClusterWalFileIdentity file = { - .thread_id = 7, - .kind = CLUSTER_WAL_FILE_NORMAL, - .tli = 2, - .segno = 2 - }; - - UT_ASSERT_TRUE(cluster_wal_retention_interval_intersects_file( - &interval, &file, TEST_WAL_SEG_SIZE)); + ClusterWalRetentionInterval interval = { .thread_id = 7, + .tli = 2, + .start_lsn = (XLogRecPtr)TEST_WAL_SEG_SIZE, + .end_lsn = (XLogRecPtr)TEST_WAL_SEG_SIZE * 3 }; + ClusterWalFileIdentity file + = { .thread_id = 7, .kind = CLUSTER_WAL_FILE_NORMAL, .tli = 2, .segno = 2 }; + + UT_ASSERT_TRUE( + cluster_wal_retention_interval_intersects_file(&interval, &file, TEST_WAL_SEG_SIZE)); file.segno = 3; - UT_ASSERT_FALSE(cluster_wal_retention_interval_intersects_file( - &interval, &file, TEST_WAL_SEG_SIZE)); + UT_ASSERT_FALSE( + cluster_wal_retention_interval_intersects_file(&interval, &file, TEST_WAL_SEG_SIZE)); file.segno = 2; file.tli = 3; - UT_ASSERT_FALSE(cluster_wal_retention_interval_intersects_file( - &interval, &file, TEST_WAL_SEG_SIZE)); + UT_ASSERT_FALSE( + cluster_wal_retention_interval_intersects_file(&interval, &file, TEST_WAL_SEG_SIZE)); file.tli = 2; file.thread_id = 8; - UT_ASSERT_FALSE(cluster_wal_retention_interval_intersects_file( - &interval, &file, TEST_WAL_SEG_SIZE)); + UT_ASSERT_FALSE( + cluster_wal_retention_interval_intersects_file(&interval, &file, TEST_WAL_SEG_SIZE)); } UT_TEST(test_walr_resource_encoding_exact) @@ -872,28 +835,23 @@ UT_TEST(test_walr_resource_encoding_refuses_invalid_thread) UT_TEST(test_pin_one_thread_acquire_and_confirmed_release) { - ClusterWalRetentionInterval interval = { - .thread_id = 1, - .tli = 1, - .start_lsn = TEST_WAL_SEG_SIZE, - .end_lsn = TEST_WAL_SEG_SIZE * 2 - }; - ClusterWalRetentionPinThreadRequest request = - make_pin_request(1, &interval, 1); + ClusterWalRetentionInterval interval = { .thread_id = 1, + .tli = 1, + .start_lsn = TEST_WAL_SEG_SIZE, + .end_lsn = TEST_WAL_SEG_SIZE * 2 }; + ClusterWalRetentionPinThreadRequest request = make_pin_request(1, &interval, 1); ClusterWalRetentionPin *pin = NULL; ClusterWalRootPublishGuard *publisher = NULL; reset_pin_fakes(); fake_native_acquire_result = LOCKACQUIRE_NOT_AVAIL; - UT_ASSERT_EQ(cluster_wal_retention_pin_acquire(&request, 1, &pin), - CLUSTER_WAL_PIN_UNAVAILABLE); + UT_ASSERT_EQ(cluster_wal_retention_pin_acquire(&request, 1, &pin), CLUSTER_WAL_PIN_UNAVAILABLE); UT_ASSERT_NULL(pin); UT_ASSERT_EQ(fake_native_acquire_call_count, 1); UT_ASSERT_EQ(fake_s7_call_count, 1); reset_pin_fakes(); - UT_ASSERT_EQ(cluster_wal_retention_pin_acquire(&request, 1, &pin), - CLUSTER_WAL_PIN_OK); + UT_ASSERT_EQ(cluster_wal_retention_pin_acquire(&request, 1, &pin), CLUSTER_WAL_PIN_OK); UT_ASSERT_NOT_NULL(pin); UT_ASSERT_EQ(fake_acquire_call_count, 1); UT_ASSERT_EQ(fake_acquire_requests[0].resid.field1, 1); @@ -902,11 +860,10 @@ UT_TEST(test_pin_one_thread_acquire_and_confirmed_release) UT_ASSERT(fake_acquire_requests[0].dontwait); UT_ASSERT_EQ(fake_native_acquire_call_count, 1); UT_ASSERT_EQ(fake_s5_call_count, 1); - UT_ASSERT_EQ(cluster_wal_retention_pin_acquire(&request, 1, - &(ClusterWalRetentionPin *){ NULL }), - CLUSTER_WAL_PIN_CAPACITY); - UT_ASSERT_EQ(cluster_wal_retention_pin_release(&pin), - CLUSTER_WALR_RELEASE_CONFIRMED); + UT_ASSERT_EQ( + cluster_wal_retention_pin_acquire(&request, 1, &(ClusterWalRetentionPin *){ NULL }), + CLUSTER_WAL_PIN_CAPACITY); + UT_ASSERT_EQ(cluster_wal_retention_pin_release(&pin), CLUSTER_WALR_RELEASE_CONFIRMED); UT_ASSERT_NULL(pin); UT_ASSERT_EQ(fake_release_call_count, 1); UT_ASSERT_EQ(fake_release_threads[0], 1); @@ -914,16 +871,17 @@ UT_TEST(test_pin_one_thread_acquire_and_confirmed_release) reset_pin_fakes(); fake_native_acquire_result = LOCKACQUIRE_NOT_AVAIL; - UT_ASSERT_EQ(cluster_wal_retention_root_publish_begin_exact( - &request.root_read, false, &publisher), - CLUSTER_WAL_PIN_UNAVAILABLE); + UT_ASSERT_EQ( + cluster_wal_retention_root_publish_begin_exact(&request.root_read, false, &publisher), + CLUSTER_WAL_PIN_UNAVAILABLE); UT_ASSERT_NULL(publisher); UT_ASSERT_EQ(fake_native_acquire_call_count, 1); UT_ASSERT_EQ(fake_s7_call_count, 1); reset_pin_fakes(); - UT_ASSERT_EQ(cluster_wal_retention_root_publish_begin_exact( - &request.root_read, false, &publisher), CLUSTER_WAL_PIN_OK); + UT_ASSERT_EQ( + cluster_wal_retention_root_publish_begin_exact(&request.root_read, false, &publisher), + CLUSTER_WAL_PIN_OK); UT_ASSERT_NOT_NULL(publisher); UT_ASSERT_EQ(fake_native_acquire_call_count, 1); UT_ASSERT_EQ(cluster_wal_retention_root_publish_end(&publisher), @@ -934,24 +892,23 @@ UT_TEST(test_pin_one_thread_acquire_and_confirmed_release) UT_TEST(test_pin_acquire_is_sorted_all_or_none) { - ClusterWalRetentionInterval intervals[2] = { - { .thread_id = 1, .tli = 1, .start_lsn = TEST_WAL_SEG_SIZE, - .end_lsn = TEST_WAL_SEG_SIZE * 2 }, - { .thread_id = 2, .tli = 1, .start_lsn = TEST_WAL_SEG_SIZE * 2, - .end_lsn = TEST_WAL_SEG_SIZE * 3 } - }; - ClusterWalRetentionPinThreadRequest requests[2] = { - make_pin_request(1, &intervals[0], 1), - make_pin_request(2, &intervals[1], 1) - }; + ClusterWalRetentionInterval intervals[2] = { { .thread_id = 1, + .tli = 1, + .start_lsn = TEST_WAL_SEG_SIZE, + .end_lsn = TEST_WAL_SEG_SIZE * 2 }, + { .thread_id = 2, + .tli = 1, + .start_lsn = TEST_WAL_SEG_SIZE * 2, + .end_lsn = TEST_WAL_SEG_SIZE * 3 } }; + ClusterWalRetentionPinThreadRequest requests[2] + = { make_pin_request(1, &intervals[0], 1), make_pin_request(2, &intervals[1], 1) }; ClusterWalRetentionPin *pin = NULL; reset_pin_fakes(); fake_acquire_result_count = 2; fake_acquire_results[0] = CLUSTER_LOCK_ACQUIRE_OK_GRANTED; fake_acquire_results[1] = CLUSTER_LOCK_ACQUIRE_NOT_AVAIL; - UT_ASSERT_EQ(cluster_wal_retention_pin_acquire(requests, 2, &pin), - CLUSTER_WAL_PIN_UNAVAILABLE); + UT_ASSERT_EQ(cluster_wal_retention_pin_acquire(requests, 2, &pin), CLUSTER_WAL_PIN_UNAVAILABLE); UT_ASSERT_NULL(pin); UT_ASSERT_EQ(fake_acquire_call_count, 2); UT_ASSERT_EQ(fake_release_call_count, 1); @@ -960,23 +917,22 @@ UT_TEST(test_pin_acquire_is_sorted_all_or_none) requests[0] = make_pin_request(2, &intervals[1], 1); requests[1] = make_pin_request(1, &intervals[0], 1); reset_pin_fakes(); - UT_ASSERT_EQ(cluster_wal_retention_pin_acquire(requests, 2, &pin), - CLUSTER_WAL_PIN_INVALID); + UT_ASSERT_EQ(cluster_wal_retention_pin_acquire(requests, 2, &pin), CLUSTER_WAL_PIN_INVALID); UT_ASSERT_EQ(fake_acquire_call_count, 0); } UT_TEST(test_pin_uncertain_rollback_remains_cleanup_only) { - ClusterWalRetentionInterval intervals[2] = { - { .thread_id = 1, .tli = 1, .start_lsn = TEST_WAL_SEG_SIZE, - .end_lsn = TEST_WAL_SEG_SIZE * 2 }, - { .thread_id = 2, .tli = 1, .start_lsn = TEST_WAL_SEG_SIZE * 2, - .end_lsn = TEST_WAL_SEG_SIZE * 3 } - }; - ClusterWalRetentionPinThreadRequest requests[2] = { - make_pin_request(1, &intervals[0], 1), - make_pin_request(2, &intervals[1], 1) - }; + ClusterWalRetentionInterval intervals[2] = { { .thread_id = 1, + .tli = 1, + .start_lsn = TEST_WAL_SEG_SIZE, + .end_lsn = TEST_WAL_SEG_SIZE * 2 }, + { .thread_id = 2, + .tli = 1, + .start_lsn = TEST_WAL_SEG_SIZE * 2, + .end_lsn = TEST_WAL_SEG_SIZE * 3 } }; + ClusterWalRetentionPinThreadRequest requests[2] + = { make_pin_request(1, &intervals[0], 1), make_pin_request(2, &intervals[1], 1) }; ClusterWalRetentionPin *pin = NULL; ClusterWalRetentionPin *other = NULL; @@ -988,152 +944,112 @@ UT_TEST(test_pin_uncertain_rollback_remains_cleanup_only) UT_ASSERT_EQ(cluster_wal_retention_pin_acquire(requests, 2, &pin), CLUSTER_WAL_PIN_RELEASE_UNCERTAIN); UT_ASSERT_NOT_NULL(pin); - UT_ASSERT_EQ(cluster_wal_retention_pin_bind_one(pin, - &(ClusterRecoverySerialGuard){ 0 }), + UT_ASSERT_EQ(cluster_wal_retention_pin_bind_one(pin, &(ClusterRecoverySerialGuard){ 0 }), CLUSTER_WAL_PIN_RELEASE_UNCERTAIN); - UT_ASSERT_EQ(cluster_wal_retention_pin_acquire(requests, 2, &other), - CLUSTER_WAL_PIN_CAPACITY); + UT_ASSERT_EQ(cluster_wal_retention_pin_acquire(requests, 2, &other), CLUSTER_WAL_PIN_CAPACITY); UT_ASSERT_NULL(other); fake_release_result = CLUSTER_LOCK_ACQUIRE_OK_GRANTED; - UT_ASSERT_EQ(cluster_wal_retention_pin_release(&pin), - CLUSTER_WALR_RELEASE_CONFIRMED); + UT_ASSERT_EQ(cluster_wal_retention_pin_release(&pin), CLUSTER_WALR_RELEASE_CONFIRMED); UT_ASSERT_NULL(pin); } UT_TEST(test_pin_bind_revalidate_and_seal_closed_fsm) { - ClusterWalRetentionInterval interval = { - .thread_id = 1, - .tli = 1, - .start_lsn = TEST_WAL_SEG_SIZE, - .end_lsn = TEST_WAL_SEG_SIZE * 2 - }; - ClusterWalRetentionPinThreadRequest request = - make_pin_request(1, &interval, 1); + ClusterWalRetentionInterval interval = { .thread_id = 1, + .tli = 1, + .start_lsn = TEST_WAL_SEG_SIZE, + .end_lsn = TEST_WAL_SEG_SIZE * 2 }; + ClusterWalRetentionPinThreadRequest request = make_pin_request(1, &interval, 1); ClusterRecoverySerialGuard serial = make_serial_guard(&request); ClusterWalRetentionPin *pin = NULL; reset_pin_fakes(); - UT_ASSERT_EQ(cluster_wal_retention_pin_acquire(&request, 1, &pin), - CLUSTER_WAL_PIN_OK); - UT_ASSERT_EQ(cluster_wal_retention_pin_bind_one(pin, &serial), - CLUSTER_WAL_PIN_OK); - UT_ASSERT_EQ(cluster_wal_retention_pin_bind_one(pin, &serial), - CLUSTER_WAL_PIN_INVALID); - UT_ASSERT_EQ(cluster_wal_retention_pin_revalidate(pin), - CLUSTER_WAL_PIN_OK); - UT_ASSERT_EQ(cluster_wal_retention_pin_seal_for_root_publish(pin), - CLUSTER_WAL_PIN_OK); - UT_ASSERT_EQ(cluster_wal_retention_pin_revalidate(pin), - CLUSTER_WAL_PIN_INVALID); - UT_ASSERT_EQ(cluster_wal_retention_pin_bind_one(pin, &serial), - CLUSTER_WAL_PIN_INVALID); - UT_ASSERT_EQ(cluster_wal_retention_pin_release(&pin), - CLUSTER_WALR_RELEASE_CONFIRMED); + UT_ASSERT_EQ(cluster_wal_retention_pin_acquire(&request, 1, &pin), CLUSTER_WAL_PIN_OK); + UT_ASSERT_EQ(cluster_wal_retention_pin_bind_one(pin, &serial), CLUSTER_WAL_PIN_OK); + UT_ASSERT_EQ(cluster_wal_retention_pin_bind_one(pin, &serial), CLUSTER_WAL_PIN_INVALID); + UT_ASSERT_EQ(cluster_wal_retention_pin_revalidate(pin), CLUSTER_WAL_PIN_OK); + UT_ASSERT_EQ(cluster_wal_retention_pin_seal_for_root_publish(pin), CLUSTER_WAL_PIN_OK); + UT_ASSERT_EQ(cluster_wal_retention_pin_revalidate(pin), CLUSTER_WAL_PIN_INVALID); + UT_ASSERT_EQ(cluster_wal_retention_pin_bind_one(pin, &serial), CLUSTER_WAL_PIN_INVALID); + UT_ASSERT_EQ(cluster_wal_retention_pin_release(&pin), CLUSTER_WALR_RELEASE_CONFIRMED); } UT_TEST(test_unbound_pin_has_pre_ir_slow_revalidation_only) { - ClusterWalRetentionInterval interval = { - .thread_id = 1, - .tli = 1, - .start_lsn = TEST_WAL_SEG_SIZE, - .end_lsn = TEST_WAL_SEG_SIZE * 2 - }; - ClusterWalRetentionPinThreadRequest request = - make_pin_request(1, &interval, 1); + ClusterWalRetentionInterval interval = { .thread_id = 1, + .tli = 1, + .start_lsn = TEST_WAL_SEG_SIZE, + .end_lsn = TEST_WAL_SEG_SIZE * 2 }; + ClusterWalRetentionPinThreadRequest request = make_pin_request(1, &interval, 1); ClusterRecoverySerialGuard serial = make_serial_guard(&request); ClusterWalRetentionPin *pin = NULL; reset_pin_fakes(); - UT_ASSERT_EQ(cluster_wal_retention_pin_acquire(&request, 1, &pin), - CLUSTER_WAL_PIN_OK); - UT_ASSERT_EQ(cluster_wal_retention_pin_preflight_revalidate_wait_v1(pin), - CLUSTER_WAL_PIN_OK); - UT_ASSERT_EQ(cluster_wal_retention_pin_revalidate(pin), - CLUSTER_WAL_PIN_INVALID); - UT_ASSERT_EQ(cluster_wal_retention_pin_bind_one(pin, &serial), - CLUSTER_WAL_PIN_OK); + UT_ASSERT_EQ(cluster_wal_retention_pin_acquire(&request, 1, &pin), CLUSTER_WAL_PIN_OK); + UT_ASSERT_EQ(cluster_wal_retention_pin_preflight_revalidate_wait_v1(pin), CLUSTER_WAL_PIN_OK); + UT_ASSERT_EQ(cluster_wal_retention_pin_revalidate(pin), CLUSTER_WAL_PIN_INVALID); + UT_ASSERT_EQ(cluster_wal_retention_pin_bind_one(pin, &serial), CLUSTER_WAL_PIN_OK); UT_ASSERT_EQ(cluster_wal_retention_pin_preflight_revalidate_wait_v1(pin), CLUSTER_WAL_PIN_INVALID); - UT_ASSERT_EQ(cluster_wal_retention_pin_release(&pin), - CLUSTER_WALR_RELEASE_CONFIRMED); - UT_ASSERT_EQ(cluster_wal_retention_pin_acquire(&request, 1, &pin), - CLUSTER_WAL_PIN_OK); + UT_ASSERT_EQ(cluster_wal_retention_pin_release(&pin), CLUSTER_WALR_RELEASE_CONFIRMED); + UT_ASSERT_EQ(cluster_wal_retention_pin_acquire(&request, 1, &pin), CLUSTER_WAL_PIN_OK); fake_root_current = false; UT_ASSERT_EQ(cluster_wal_retention_pin_preflight_revalidate_wait_v1(pin), CLUSTER_WAL_PIN_STALE); - UT_ASSERT(cluster_wal_retention_pin_bind_one(pin, &serial) != - CLUSTER_WAL_PIN_OK); - UT_ASSERT_EQ(cluster_wal_retention_pin_release(&pin), - CLUSTER_WALR_RELEASE_CONFIRMED); + UT_ASSERT(cluster_wal_retention_pin_bind_one(pin, &serial) != CLUSTER_WAL_PIN_OK); + UT_ASSERT_EQ(cluster_wal_retention_pin_release(&pin), CLUSTER_WALR_RELEASE_CONFIRMED); } UT_TEST(test_pin_revalidation_drift_poisoned_until_release) { - ClusterWalRetentionInterval interval = { - .thread_id = 1, - .tli = 1, - .start_lsn = TEST_WAL_SEG_SIZE, - .end_lsn = TEST_WAL_SEG_SIZE * 2 - }; - ClusterWalRetentionPinThreadRequest request = - make_pin_request(1, &interval, 1); + ClusterWalRetentionInterval interval = { .thread_id = 1, + .tli = 1, + .start_lsn = TEST_WAL_SEG_SIZE, + .end_lsn = TEST_WAL_SEG_SIZE * 2 }; + ClusterWalRetentionPinThreadRequest request = make_pin_request(1, &interval, 1); ClusterRecoverySerialGuard serial = make_serial_guard(&request); ClusterWalRetentionPin *pin = NULL; reset_pin_fakes(); - UT_ASSERT_EQ(cluster_wal_retention_pin_acquire(&request, 1, &pin), - CLUSTER_WAL_PIN_OK); - UT_ASSERT_EQ(cluster_wal_retention_pin_bind_one(pin, &serial), - CLUSTER_WAL_PIN_OK); + UT_ASSERT_EQ(cluster_wal_retention_pin_acquire(&request, 1, &pin), CLUSTER_WAL_PIN_OK); + UT_ASSERT_EQ(cluster_wal_retention_pin_bind_one(pin, &serial), CLUSTER_WAL_PIN_OK); fake_serial_result = CLUSTER_RECOVERY_SERIAL_FENCE_STALE; - UT_ASSERT_EQ(cluster_wal_retention_pin_revalidate(pin), - CLUSTER_WAL_PIN_STALE); + UT_ASSERT_EQ(cluster_wal_retention_pin_revalidate(pin), CLUSTER_WAL_PIN_STALE); UT_ASSERT_TRUE(cluster_wal_retention_active_pin_present()); fake_serial_result = CLUSTER_RECOVERY_SERIAL_CURRENT; - UT_ASSERT_EQ(cluster_wal_retention_pin_revalidate(pin), - CLUSTER_WAL_PIN_STALE); - UT_ASSERT_EQ(cluster_wal_retention_pin_seal_for_root_publish(pin), - CLUSTER_WAL_PIN_STALE); - UT_ASSERT_EQ(cluster_wal_retention_pin_release(&pin), - CLUSTER_WALR_RELEASE_CONFIRMED); + UT_ASSERT_EQ(cluster_wal_retention_pin_revalidate(pin), CLUSTER_WAL_PIN_STALE); + UT_ASSERT_EQ(cluster_wal_retention_pin_seal_for_root_publish(pin), CLUSTER_WAL_PIN_STALE); + UT_ASSERT_EQ(cluster_wal_retention_pin_release(&pin), CLUSTER_WALR_RELEASE_CONFIRMED); UT_ASSERT_FALSE(cluster_wal_retention_active_pin_present()); } UT_TEST(test_sealed_pin_root_publish_requires_whole_root_token) { - ClusterWalRetentionInterval interval = { - .thread_id = 1, - .tli = 1, - .start_lsn = TEST_WAL_SEG_SIZE, - .end_lsn = TEST_WAL_SEG_SIZE * 2 - }; - ClusterWalRetentionPinThreadRequest request = - make_pin_request(1, &interval, 1); + ClusterWalRetentionInterval interval = { .thread_id = 1, + .tli = 1, + .start_lsn = TEST_WAL_SEG_SIZE, + .end_lsn = TEST_WAL_SEG_SIZE * 2 }; + ClusterWalRetentionPinThreadRequest request = make_pin_request(1, &interval, 1); ClusterRecoverySerialGuard serial = make_serial_guard(&request); ClusterControlRootReadToken drifted_root = request.root_read; ClusterWalRetentionPin *pin = NULL; ClusterWalRootPublishGuard *publisher = NULL; reset_pin_fakes(); - UT_ASSERT_EQ(cluster_wal_retention_pin_acquire(&request, 1, &pin), - CLUSTER_WAL_PIN_OK); - UT_ASSERT_EQ(cluster_wal_retention_pin_bind_one(pin, &serial), - CLUSTER_WAL_PIN_OK); - UT_ASSERT_EQ(cluster_wal_retention_pin_seal_for_root_publish(pin), - CLUSTER_WAL_PIN_OK); + UT_ASSERT_EQ(cluster_wal_retention_pin_acquire(&request, 1, &pin), CLUSTER_WAL_PIN_OK); + UT_ASSERT_EQ(cluster_wal_retention_pin_bind_one(pin, &serial), CLUSTER_WAL_PIN_OK); + UT_ASSERT_EQ(cluster_wal_retention_pin_seal_for_root_publish(pin), CLUSTER_WAL_PIN_OK); drifted_root.root_publish_seq++; - UT_ASSERT_EQ(cluster_wal_retention_root_publish_begin_exact( - &drifted_root, true, &publisher), CLUSTER_WAL_PIN_STALE); + UT_ASSERT_EQ(cluster_wal_retention_root_publish_begin_exact(&drifted_root, true, &publisher), + CLUSTER_WAL_PIN_STALE); UT_ASSERT_NULL(publisher); - UT_ASSERT_EQ(cluster_wal_retention_root_publish_begin_exact( - &request.root_read, true, &publisher), CLUSTER_WAL_PIN_OK); + UT_ASSERT_EQ( + cluster_wal_retention_root_publish_begin_exact(&request.root_read, true, &publisher), + CLUSTER_WAL_PIN_OK); UT_ASSERT_NOT_NULL(publisher); UT_ASSERT_EQ(cluster_wal_retention_root_publish_end(&publisher), CLUSTER_WALR_RELEASE_CONFIRMED); - UT_ASSERT_EQ(cluster_wal_retention_pin_release(&pin), - CLUSTER_WALR_RELEASE_CONFIRMED); + UT_ASSERT_EQ(cluster_wal_retention_pin_release(&pin), CLUSTER_WALR_RELEASE_CONFIRMED); } static ClusterControlRootSnapshot @@ -1160,29 +1076,22 @@ make_pin_root_snapshot(const ClusterWalRetentionPinThreadRequest *request, UT_TEST(test_sealed_pin_adopts_same_immutable_root_readback) { - ClusterWalRetentionInterval interval = { - .thread_id = 1, - .tli = 1, - .start_lsn = TEST_WAL_SEG_SIZE, - .end_lsn = TEST_WAL_SEG_SIZE * 2 - }; - ClusterWalRetentionPinThreadRequest request = - make_pin_request(1, &interval, 1); + ClusterWalRetentionInterval interval = { .thread_id = 1, + .tli = 1, + .start_lsn = TEST_WAL_SEG_SIZE, + .end_lsn = TEST_WAL_SEG_SIZE * 2 }; + ClusterWalRetentionPinThreadRequest request = make_pin_request(1, &interval, 1); ClusterRecoverySerialGuard serial = make_serial_guard(&request); - ClusterControlRootSnapshot expected = - make_pin_root_snapshot(&request, &interval); + ClusterControlRootSnapshot expected = make_pin_root_snapshot(&request, &interval); ClusterControlRootSnapshot observed = expected; ClusterControlRootReadToken observed_token = request.root_read; ClusterWalRetentionPin *pin = NULL; ClusterWalRootPublishGuard *publisher = NULL; reset_pin_fakes(); - UT_ASSERT_EQ(cluster_wal_retention_pin_acquire(&request, 1, &pin), - CLUSTER_WAL_PIN_OK); - UT_ASSERT_EQ(cluster_wal_retention_pin_bind_one(pin, &serial), - CLUSTER_WAL_PIN_OK); - UT_ASSERT_EQ(cluster_wal_retention_pin_seal_for_root_publish(pin), - CLUSTER_WAL_PIN_OK); + UT_ASSERT_EQ(cluster_wal_retention_pin_acquire(&request, 1, &pin), CLUSTER_WAL_PIN_OK); + UT_ASSERT_EQ(cluster_wal_retention_pin_bind_one(pin, &serial), CLUSTER_WAL_PIN_OK); + UT_ASSERT_EQ(cluster_wal_retention_pin_seal_for_root_publish(pin), CLUSTER_WAL_PIN_OK); serial.held = false; observed.root_publish_seq++; observed.recovered_through_lsn_exclusive = interval.end_lsn; @@ -1190,122 +1099,101 @@ UT_TEST(test_sealed_pin_adopts_same_immutable_root_readback) observed_token.root_publish_seq++; observed_token.record_crc32c++; UT_ASSERT_EQ(cluster_wal_retention_pin_adopt_root_readback_v1( - pin, &expected, &request.root_read, &observed, &observed_token), - CLUSTER_WAL_PIN_OK); - UT_ASSERT_EQ(cluster_wal_retention_root_publish_begin_exact( - &request.root_read, true, &publisher), CLUSTER_WAL_PIN_STALE); + pin, &expected, &request.root_read, &observed, &observed_token), + CLUSTER_WAL_PIN_OK); + UT_ASSERT_EQ( + cluster_wal_retention_root_publish_begin_exact(&request.root_read, true, &publisher), + CLUSTER_WAL_PIN_STALE); UT_ASSERT_NULL(publisher); - UT_ASSERT_EQ(cluster_wal_retention_root_publish_begin_exact( - &observed_token, true, &publisher), CLUSTER_WAL_PIN_OK); + UT_ASSERT_EQ(cluster_wal_retention_root_publish_begin_exact(&observed_token, true, &publisher), + CLUSTER_WAL_PIN_OK); UT_ASSERT_EQ(cluster_wal_retention_root_publish_end(&publisher), CLUSTER_WALR_RELEASE_CONFIRMED); - UT_ASSERT_EQ(cluster_wal_retention_pin_release(&pin), - CLUSTER_WALR_RELEASE_CONFIRMED); + UT_ASSERT_EQ(cluster_wal_retention_pin_release(&pin), CLUSTER_WALR_RELEASE_CONFIRMED); } UT_TEST(test_sealed_pin_rejects_immutable_root_drift) { - ClusterWalRetentionInterval interval = { - .thread_id = 1, - .tli = 1, - .start_lsn = TEST_WAL_SEG_SIZE, - .end_lsn = TEST_WAL_SEG_SIZE * 2 - }; - ClusterWalRetentionPinThreadRequest request = - make_pin_request(1, &interval, 1); + ClusterWalRetentionInterval interval = { .thread_id = 1, + .tli = 1, + .start_lsn = TEST_WAL_SEG_SIZE, + .end_lsn = TEST_WAL_SEG_SIZE * 2 }; + ClusterWalRetentionPinThreadRequest request = make_pin_request(1, &interval, 1); ClusterRecoverySerialGuard serial = make_serial_guard(&request); - ClusterControlRootSnapshot expected = - make_pin_root_snapshot(&request, &interval); + ClusterControlRootSnapshot expected = make_pin_root_snapshot(&request, &interval); ClusterControlRootSnapshot observed = expected; ClusterControlRootReadToken observed_token = request.root_read; ClusterWalRetentionPin *pin = NULL; ClusterWalRootPublishGuard *publisher = NULL; reset_pin_fakes(); - UT_ASSERT_EQ(cluster_wal_retention_pin_acquire(&request, 1, &pin), - CLUSTER_WAL_PIN_OK); - UT_ASSERT_EQ(cluster_wal_retention_pin_bind_one(pin, &serial), - CLUSTER_WAL_PIN_OK); - UT_ASSERT_EQ(cluster_wal_retention_pin_seal_for_root_publish(pin), - CLUSTER_WAL_PIN_OK); + UT_ASSERT_EQ(cluster_wal_retention_pin_acquire(&request, 1, &pin), CLUSTER_WAL_PIN_OK); + UT_ASSERT_EQ(cluster_wal_retention_pin_bind_one(pin, &serial), CLUSTER_WAL_PIN_OK); + UT_ASSERT_EQ(cluster_wal_retention_pin_seal_for_root_publish(pin), CLUSTER_WAL_PIN_OK); serial.held = false; observed.checkpoint_lower_lsn++; observed_token.file_txn_seq++; observed_token.root_publish_seq++; observed_token.record_crc32c++; UT_ASSERT_EQ(cluster_wal_retention_pin_adopt_root_readback_v1( - pin, &expected, &request.root_read, &observed, &observed_token), - CLUSTER_WAL_PIN_STALE); - UT_ASSERT_EQ(cluster_wal_retention_root_publish_begin_exact( - &request.root_read, true, &publisher), CLUSTER_WAL_PIN_OK); + pin, &expected, &request.root_read, &observed, &observed_token), + CLUSTER_WAL_PIN_STALE); + UT_ASSERT_EQ( + cluster_wal_retention_root_publish_begin_exact(&request.root_read, true, &publisher), + CLUSTER_WAL_PIN_OK); UT_ASSERT_EQ(cluster_wal_retention_root_publish_end(&publisher), CLUSTER_WALR_RELEASE_CONFIRMED); - UT_ASSERT_EQ(cluster_wal_retention_pin_release(&pin), - CLUSTER_WALR_RELEASE_CONFIRMED); + UT_ASSERT_EQ(cluster_wal_retention_pin_release(&pin), CLUSTER_WALR_RELEASE_CONFIRMED); } UT_TEST(test_pin_resource_owner_abort_releases_live_grant) { - ClusterWalRetentionInterval interval = { - .thread_id = 1, - .tli = 1, - .start_lsn = TEST_WAL_SEG_SIZE, - .end_lsn = TEST_WAL_SEG_SIZE * 2 - }; - ClusterWalRetentionPinThreadRequest request = - make_pin_request(1, &interval, 1); + ClusterWalRetentionInterval interval = { .thread_id = 1, + .tli = 1, + .start_lsn = TEST_WAL_SEG_SIZE, + .end_lsn = TEST_WAL_SEG_SIZE * 2 }; + ClusterWalRetentionPinThreadRequest request = make_pin_request(1, &interval, 1); ClusterWalRetentionPin *pin = NULL; ClusterWalRetentionPin *next = NULL; reset_pin_fakes(); - UT_ASSERT_EQ(cluster_wal_retention_pin_acquire(&request, 1, &pin), - CLUSTER_WAL_PIN_OK); + UT_ASSERT_EQ(cluster_wal_retention_pin_acquire(&request, 1, &pin), CLUSTER_WAL_PIN_OK); UT_ASSERT_NOT_NULL(fake_resource_release_callback); if (fake_resource_release_callback != NULL) - fake_resource_release_callback(RESOURCE_RELEASE_BEFORE_LOCKS, false, - false, fake_resource_release_arg); + fake_resource_release_callback(RESOURCE_RELEASE_BEFORE_LOCKS, false, false, + fake_resource_release_arg); UT_ASSERT_EQ(fake_release_call_count, 1); - UT_ASSERT_EQ(cluster_wal_retention_pin_acquire(&request, 1, &next), - CLUSTER_WAL_PIN_OK); - UT_ASSERT_EQ(cluster_wal_retention_pin_release(&next), - CLUSTER_WALR_RELEASE_CONFIRMED); + UT_ASSERT_EQ(cluster_wal_retention_pin_acquire(&request, 1, &next), CLUSTER_WAL_PIN_OK); + UT_ASSERT_EQ(cluster_wal_retention_pin_release(&next), CLUSTER_WALR_RELEASE_CONFIRMED); } UT_TEST(test_pin_explicit_release_prevents_owner_double_release) { - ClusterWalRetentionInterval interval = { - .thread_id = 1, - .tli = 1, - .start_lsn = TEST_WAL_SEG_SIZE, - .end_lsn = TEST_WAL_SEG_SIZE * 2 - }; - ClusterWalRetentionPinThreadRequest request = - make_pin_request(1, &interval, 1); + ClusterWalRetentionInterval interval = { .thread_id = 1, + .tli = 1, + .start_lsn = TEST_WAL_SEG_SIZE, + .end_lsn = TEST_WAL_SEG_SIZE * 2 }; + ClusterWalRetentionPinThreadRequest request = make_pin_request(1, &interval, 1); ClusterWalRetentionPin *pin = NULL; reset_pin_fakes(); - UT_ASSERT_EQ(cluster_wal_retention_pin_acquire(&request, 1, &pin), - CLUSTER_WAL_PIN_OK); - UT_ASSERT_EQ(cluster_wal_retention_pin_release(&pin), - CLUSTER_WALR_RELEASE_CONFIRMED); + UT_ASSERT_EQ(cluster_wal_retention_pin_acquire(&request, 1, &pin), CLUSTER_WAL_PIN_OK); + UT_ASSERT_EQ(cluster_wal_retention_pin_release(&pin), CLUSTER_WALR_RELEASE_CONFIRMED); UT_ASSERT_EQ(fake_release_call_count, 1); UT_ASSERT_NOT_NULL(fake_resource_release_callback); if (fake_resource_release_callback != NULL) - fake_resource_release_callback(RESOURCE_RELEASE_BEFORE_LOCKS, true, - false, fake_resource_release_arg); + fake_resource_release_callback(RESOURCE_RELEASE_BEFORE_LOCKS, true, false, + fake_resource_release_arg); UT_ASSERT_EQ(fake_release_call_count, 1); } UT_TEST(test_recovery_guard_converts_same_pin_holder_and_poison_is_cleanup_only) { - ClusterWalRetentionInterval interval = { - .thread_id = 1, - .tli = 1, - .start_lsn = TEST_WAL_SEG_SIZE, - .end_lsn = TEST_WAL_SEG_SIZE * 2 - }; - ClusterWalRetentionPinThreadRequest request = - make_pin_request(1, &interval, 1); + ClusterWalRetentionInterval interval = { .thread_id = 1, + .tli = 1, + .start_lsn = TEST_WAL_SEG_SIZE, + .end_lsn = TEST_WAL_SEG_SIZE * 2 }; + ClusterWalRetentionPinThreadRequest request = make_pin_request(1, &interval, 1); ClusterRecoverySerialGuard serial = make_serial_guard(&request); ClusterWalRetentionPin *pin = NULL; ClusterWalReuseActionGuard guard; @@ -1314,14 +1202,11 @@ UT_TEST(test_recovery_guard_converts_same_pin_holder_and_poison_is_cleanup_only) /* Positive: one S holder converts in place to X and back to S. */ reset_pin_fakes(); - UT_ASSERT_EQ(cluster_wal_retention_pin_acquire(&request, 1, &pin), - CLUSTER_WAL_PIN_OK); - UT_ASSERT_EQ(cluster_wal_retention_pin_bind_one(pin, &serial), - CLUSTER_WAL_PIN_OK); + UT_ASSERT_EQ(cluster_wal_retention_pin_acquire(&request, 1, &pin), CLUSTER_WAL_PIN_OK); + UT_ASSERT_EQ(cluster_wal_retention_pin_bind_one(pin, &serial), CLUSTER_WAL_PIN_OK); prepare_bound_recovery_guard(&guard, &request); fake_s5_result = CLUSTER_LOCK_ACQUIRE_OK_CONVERTED; - UT_ASSERT_EQ(cluster_wal_reuse_guard_arm(&guard, &serial, pin, &reason), - CLUSTER_WAL_GUARD_OK); + UT_ASSERT_EQ(cluster_wal_reuse_guard_arm(&guard, &serial, pin, &reason), CLUSTER_WAL_GUARD_OK); UT_ASSERT_EQ(guard.state, CLUSTER_WAL_GUARD_ARMED); UT_ASSERT(guard.walr.held); UT_ASSERT(guard.walr.coordinated); @@ -1341,19 +1226,15 @@ UT_TEST(test_recovery_guard_converts_same_pin_holder_and_poison_is_cleanup_only) UT_ASSERT_EQ(fake_acquire_requests[2].current_mode, ExclusiveLock); UT_ASSERT_EQ(fake_acquire_requests[2].lockmode, ShareLock); UT_ASSERT(fake_acquire_requests[2].dontwait); - UT_ASSERT_EQ(cluster_wal_retention_pin_revalidate(pin), - CLUSTER_WAL_PIN_OK); - UT_ASSERT_EQ(cluster_wal_retention_pin_release(&pin), - CLUSTER_WALR_RELEASE_CONFIRMED); + UT_ASSERT_EQ(cluster_wal_retention_pin_revalidate(pin), CLUSTER_WAL_PIN_OK); + UT_ASSERT_EQ(cluster_wal_retention_pin_release(&pin), CLUSTER_WALR_RELEASE_CONFIRMED); UT_ASSERT_EQ(fake_release_call_count, 1); UT_ASSERT_EQ(fake_native_release_call_count, 3); /* A conflicting conversion keeps the original pin S usable. */ reset_pin_fakes(); - UT_ASSERT_EQ(cluster_wal_retention_pin_acquire(&request, 1, &pin), - CLUSTER_WAL_PIN_OK); - UT_ASSERT_EQ(cluster_wal_retention_pin_bind_one(pin, &serial), - CLUSTER_WAL_PIN_OK); + UT_ASSERT_EQ(cluster_wal_retention_pin_acquire(&request, 1, &pin), CLUSTER_WAL_PIN_OK); + UT_ASSERT_EQ(cluster_wal_retention_pin_bind_one(pin, &serial), CLUSTER_WAL_PIN_OK); prepare_bound_recovery_guard(&guard, &request); fake_s5_result = CLUSTER_LOCK_ACQUIRE_NOT_AVAIL; UT_ASSERT_EQ(cluster_wal_reuse_guard_arm(&guard, &serial, pin, &reason), @@ -1361,35 +1242,29 @@ UT_TEST(test_recovery_guard_converts_same_pin_holder_and_poison_is_cleanup_only) UT_ASSERT_EQ(reason, CLUSTER_WAL_DENY_GES_UNAVAILABLE); UT_ASSERT_EQ(guard.state, CLUSTER_WAL_GUARD_FENCE_ADMITTED_OR_NA); UT_ASSERT_FALSE(guard.walr.held); - UT_ASSERT_EQ(cluster_wal_retention_pin_revalidate(pin), - CLUSTER_WAL_PIN_OK); + UT_ASSERT_EQ(cluster_wal_retention_pin_revalidate(pin), CLUSTER_WAL_PIN_OK); UT_ASSERT_EQ(cluster_wal_reuse_guard_finish(&guard, &outcome, &reason), CLUSTER_WALR_RELEASE_NOT_HELD); - UT_ASSERT_EQ(cluster_wal_retention_pin_release(&pin), - CLUSTER_WALR_RELEASE_CONFIRMED); + UT_ASSERT_EQ(cluster_wal_retention_pin_release(&pin), CLUSTER_WALR_RELEASE_CONFIRMED); /* An uncertain X->S result poisons the pin; owner cleanup releases X once. */ reset_pin_fakes(); - UT_ASSERT_EQ(cluster_wal_retention_pin_acquire(&request, 1, &pin), - CLUSTER_WAL_PIN_OK); - UT_ASSERT_EQ(cluster_wal_retention_pin_bind_one(pin, &serial), - CLUSTER_WAL_PIN_OK); + UT_ASSERT_EQ(cluster_wal_retention_pin_acquire(&request, 1, &pin), CLUSTER_WAL_PIN_OK); + UT_ASSERT_EQ(cluster_wal_retention_pin_bind_one(pin, &serial), CLUSTER_WAL_PIN_OK); prepare_bound_recovery_guard(&guard, &request); fake_s5_result = CLUSTER_LOCK_ACQUIRE_OK_CONVERTED; - UT_ASSERT_EQ(cluster_wal_reuse_guard_arm(&guard, &serial, pin, &reason), - CLUSTER_WAL_GUARD_OK); + UT_ASSERT_EQ(cluster_wal_reuse_guard_arm(&guard, &serial, pin, &reason), CLUSTER_WAL_GUARD_OK); fake_s5_result = CLUSTER_LOCK_ACQUIRE_FAIL_TIMEOUT; UT_ASSERT_EQ(cluster_wal_reuse_guard_finish(&guard, &outcome, &reason), CLUSTER_WALR_RELEASE_UNCONFIRMED); UT_ASSERT_EQ(outcome, CLUSTER_WAL_TERMINAL_UNCHANGED); UT_ASSERT_EQ(reason, CLUSTER_WAL_DENY_RELEASE_UNCERTAIN); UT_ASSERT(guard.walr.release_uncertain); - UT_ASSERT_EQ(cluster_wal_retention_pin_revalidate(pin), - CLUSTER_WAL_PIN_STALE); + UT_ASSERT_EQ(cluster_wal_retention_pin_revalidate(pin), CLUSTER_WAL_PIN_STALE); UT_ASSERT_NOT_NULL(fake_resource_release_callback); if (fake_resource_release_callback != NULL) - fake_resource_release_callback(RESOURCE_RELEASE_BEFORE_LOCKS, false, - false, fake_resource_release_arg); + fake_resource_release_callback(RESOURCE_RELEASE_BEFORE_LOCKS, false, false, + fake_resource_release_arg); UT_ASSERT_EQ(fake_release_call_count, 1); UT_ASSERT_EQ(fake_native_release_call_count, 3); @@ -1397,10 +1272,8 @@ UT_TEST(test_recovery_guard_converts_same_pin_holder_and_poison_is_cleanup_only) * poisons both the guard/pin relationship until ResourceOwner cleanup. */ reset_pin_fakes(); pin = NULL; - UT_ASSERT_EQ(cluster_wal_retention_pin_acquire(&request, 1, &pin), - CLUSTER_WAL_PIN_OK); - UT_ASSERT_EQ(cluster_wal_retention_pin_bind_one(pin, &serial), - CLUSTER_WAL_PIN_OK); + UT_ASSERT_EQ(cluster_wal_retention_pin_acquire(&request, 1, &pin), CLUSTER_WAL_PIN_OK); + UT_ASSERT_EQ(cluster_wal_retention_pin_bind_one(pin, &serial), CLUSTER_WAL_PIN_OK); prepare_bound_recovery_guard(&guard, &request); fake_s5_result = CLUSTER_LOCK_ACQUIRE_FAIL_TIMEOUT; UT_ASSERT_EQ(cluster_wal_reuse_guard_arm(&guard, &serial, pin, &reason), @@ -1412,54 +1285,45 @@ UT_TEST(test_recovery_guard_converts_same_pin_holder_and_poison_is_cleanup_only) UT_ASSERT(guard.walr.release_uncertain); UT_ASSERT_EQ(guard.serial_or_null, &serial); UT_ASSERT_EQ(guard.pin_or_null, pin); - UT_ASSERT_EQ(cluster_wal_retention_pin_revalidate(pin), - CLUSTER_WAL_PIN_STALE); + UT_ASSERT_EQ(cluster_wal_retention_pin_revalidate(pin), CLUSTER_WAL_PIN_STALE); UT_ASSERT_NOT_NULL(fake_resource_release_callback); if (fake_resource_release_callback != NULL) - fake_resource_release_callback(RESOURCE_RELEASE_BEFORE_LOCKS, false, - false, fake_resource_release_arg); + fake_resource_release_callback(RESOURCE_RELEASE_BEFORE_LOCKS, false, false, + fake_resource_release_arg); UT_ASSERT_EQ(fake_release_call_count, 1); UT_ASSERT_EQ(fake_native_release_call_count, 2); } UT_TEST(test_recovery_guard_l3_revalidates_bound_pin_and_serial) { - ClusterWalRetentionInterval interval = { - .thread_id = 1, - .tli = 1, - .start_lsn = TEST_WAL_SEG_SIZE, - .end_lsn = TEST_WAL_SEG_SIZE * 2 - }; - ClusterWalRetentionPinThreadRequest request = - make_pin_request(1, &interval, 1); + ClusterWalRetentionInterval interval = { .thread_id = 1, + .tli = 1, + .start_lsn = TEST_WAL_SEG_SIZE, + .end_lsn = TEST_WAL_SEG_SIZE * 2 }; + ClusterWalRetentionPinThreadRequest request = make_pin_request(1, &interval, 1); ClusterRecoverySerialGuard serial = make_serial_guard(&request); ClusterWalRetentionPin *pin = NULL; ClusterWalReuseActionGuard guard; ClusterWalReuseDenyReason reason; reset_pin_fakes(); - UT_ASSERT_EQ(cluster_wal_retention_pin_acquire(&request, 1, &pin), - CLUSTER_WAL_PIN_OK); - UT_ASSERT_EQ(cluster_wal_retention_pin_bind_one(pin, &serial), - CLUSTER_WAL_PIN_OK); + UT_ASSERT_EQ(cluster_wal_retention_pin_acquire(&request, 1, &pin), CLUSTER_WAL_PIN_OK); + UT_ASSERT_EQ(cluster_wal_retention_pin_bind_one(pin, &serial), CLUSTER_WAL_PIN_OK); prepare_bound_recovery_guard(&guard, &request); fake_s5_result = CLUSTER_LOCK_ACQUIRE_OK_CONVERTED; - UT_ASSERT_EQ(cluster_wal_reuse_guard_arm(&guard, &serial, pin, &reason), - CLUSTER_WAL_GUARD_OK); + UT_ASSERT_EQ(cluster_wal_reuse_guard_arm(&guard, &serial, pin, &reason), CLUSTER_WAL_GUARD_OK); /* ARMED is not durable authority: serial/pin drift must be observed before * the final object stamp and any destructive syscall. */ fake_serial_result = CLUSTER_RECOVERY_SERIAL_FENCE_STALE; - UT_ASSERT_EQ(cluster_wal_reuse_guard_l3_begin( - &guard, CLUSTER_WAL_PHYSICAL_REMOVE, &reason), + UT_ASSERT_EQ(cluster_wal_reuse_guard_l3_begin(&guard, CLUSTER_WAL_PHYSICAL_REMOVE, &reason), CLUSTER_WAL_GUARD_BLOCKED); UT_ASSERT_EQ(reason, CLUSTER_WAL_DENY_SERIAL_STALE); - UT_ASSERT_EQ(cluster_wal_retention_pin_revalidate(pin), - CLUSTER_WAL_PIN_STALE); + UT_ASSERT_EQ(cluster_wal_retention_pin_revalidate(pin), CLUSTER_WAL_PIN_STALE); UT_ASSERT_NOT_NULL(fake_resource_release_callback); if (fake_resource_release_callback != NULL) - fake_resource_release_callback(RESOURCE_RELEASE_BEFORE_LOCKS, false, - false, fake_resource_release_arg); + fake_resource_release_callback(RESOURCE_RELEASE_BEFORE_LOCKS, false, false, + fake_resource_release_arg); } UT_TEST(test_active_recovery_preflight_borrows_exact_pin_and_blocks_retained_file) @@ -1469,25 +1333,18 @@ UT_TEST(test_active_recovery_preflight_borrows_exact_pin_and_blocks_retained_fil char thread_dir[MAXPGPATH]; char retained_path[MAXPGPATH]; char disjoint_path[MAXPGPATH]; - ClusterWalRetentionInterval interval = { - .thread_id = 1, - .tli = 1, - .start_lsn = TEST_WAL_SEG_SIZE, - .end_lsn = TEST_WAL_SEG_SIZE * 2 - }; - ClusterWalRetentionPinThreadRequest request = - make_pin_request(1, &interval, 1); + ClusterWalRetentionInterval interval = { .thread_id = 1, + .tli = 1, + .start_lsn = TEST_WAL_SEG_SIZE, + .end_lsn = TEST_WAL_SEG_SIZE * 2 }; + ClusterWalRetentionPinThreadRequest request = make_pin_request(1, &interval, 1); ClusterRecoverySerialGuard serial = make_serial_guard(&request); ClusterWalRetentionPin *pin = NULL; ClusterWalRetentionPin *borrowed_pin = NULL; ClusterRecoverySerialGuard *borrowed_serial = NULL; - ClusterWalReuseActionGuard guard = {0}; - ClusterWalFileIdentity file = { - .thread_id = 1, - .kind = CLUSTER_WAL_FILE_NORMAL, - .tli = 1, - .segno = 3 - }; + ClusterWalReuseActionGuard guard = { 0 }; + ClusterWalFileIdentity file + = { .thread_id = 1, .kind = CLUSTER_WAL_FILE_NORMAL, .tli = 1, .segno = 3 }; ClusterWalReuseDenyReason reason; ClusterWalTerminalOutcome outcome; @@ -1497,22 +1354,16 @@ UT_TEST(test_active_recovery_preflight_borrows_exact_pin_and_blocks_retained_fil UT_ASSERT_NOT_NULL(root_dir); snprintf(thread_dir, sizeof(thread_dir), "%s/thread_1", root_dir); UT_ASSERT_EQ(mkdir(thread_dir, 0700), 0); - write_test_wal_segment( - thread_dir, 1, 1, retained_path, sizeof(retained_path)); - write_test_wal_segment( - thread_dir, 1, 3, disjoint_path, sizeof(disjoint_path)); + write_test_wal_segment(thread_dir, 1, 1, retained_path, sizeof(retained_path)); + write_test_wal_segment(thread_dir, 1, 3, disjoint_path, sizeof(disjoint_path)); cluster_wal_threads_dir = root_dir; - UT_ASSERT_EQ(cluster_wal_retention_pin_acquire(&request, 1, &pin), - CLUSTER_WAL_PIN_OK); + UT_ASSERT_EQ(cluster_wal_retention_pin_acquire(&request, 1, &pin), CLUSTER_WAL_PIN_OK); UT_ASSERT_TRUE(cluster_wal_retention_active_pin_present()); - UT_ASSERT_EQ(cluster_wal_retention_pin_bind_one(pin, &serial), - CLUSTER_WAL_PIN_OK); - UT_ASSERT_EQ(cluster_wal_reuse_guard_init(&guard, &reason), - CLUSTER_WAL_GUARD_OK); + UT_ASSERT_EQ(cluster_wal_retention_pin_bind_one(pin, &serial), CLUSTER_WAL_PIN_OK); + UT_ASSERT_EQ(cluster_wal_reuse_guard_init(&guard, &reason), CLUSTER_WAL_GUARD_OK); UT_ASSERT_EQ(cluster_wal_reuse_guard_preflight_active_recovery( - &guard, &file, - CLUSTER_WAL_REUSE_E2_APPLY_TIMELINE_SWITCH, - &borrowed_serial, &borrowed_pin, &reason), + &guard, &file, CLUSTER_WAL_REUSE_E2_APPLY_TIMELINE_SWITCH, &borrowed_serial, + &borrowed_pin, &reason), CLUSTER_WAL_GUARD_OK); UT_ASSERT_EQ(borrowed_serial, &serial); UT_ASSERT_EQ(borrowed_pin, pin); @@ -1521,40 +1372,33 @@ UT_TEST(test_active_recovery_preflight_borrows_exact_pin_and_blocks_retained_fil UT_ASSERT_EQ(guard.needs_or_null, request.needs); UT_ASSERT_EQ(guard.admissions_or_null, request.admissions); fake_s5_result = CLUSTER_LOCK_ACQUIRE_OK_CONVERTED; - UT_ASSERT_EQ(cluster_wal_reuse_guard_arm( - &guard, borrowed_serial, borrowed_pin, &reason), + UT_ASSERT_EQ(cluster_wal_reuse_guard_arm(&guard, borrowed_serial, borrowed_pin, &reason), CLUSTER_WAL_GUARD_OK); UT_ASSERT_EQ(cluster_wal_reuse_guard_finish(&guard, &outcome, &reason), CLUSTER_WALR_RELEASE_CONFIRMED); - UT_ASSERT_EQ(cluster_wal_retention_pin_release(&pin), - CLUSTER_WALR_RELEASE_CONFIRMED); + UT_ASSERT_EQ(cluster_wal_retention_pin_release(&pin), CLUSTER_WALR_RELEASE_CONFIRMED); UT_ASSERT_FALSE(cluster_wal_retention_active_pin_present()); reset_pin_fakes(); request = make_pin_request(1, &interval, 1); serial = make_serial_guard(&request); - UT_ASSERT_EQ(cluster_wal_retention_pin_acquire(&request, 1, &pin), - CLUSTER_WAL_PIN_OK); - UT_ASSERT_EQ(cluster_wal_retention_pin_bind_one(pin, &serial), - CLUSTER_WAL_PIN_OK); + UT_ASSERT_EQ(cluster_wal_retention_pin_acquire(&request, 1, &pin), CLUSTER_WAL_PIN_OK); + UT_ASSERT_EQ(cluster_wal_retention_pin_bind_one(pin, &serial), CLUSTER_WAL_PIN_OK); memset(&guard, 0, sizeof(guard)); file.segno = 1; borrowed_serial = NULL; borrowed_pin = NULL; - UT_ASSERT_EQ(cluster_wal_reuse_guard_init(&guard, &reason), - CLUSTER_WAL_GUARD_OK); + UT_ASSERT_EQ(cluster_wal_reuse_guard_init(&guard, &reason), CLUSTER_WAL_GUARD_OK); UT_ASSERT_EQ(cluster_wal_reuse_guard_preflight_active_recovery( - &guard, &file, - CLUSTER_WAL_REUSE_E2_APPLY_TIMELINE_SWITCH, - &borrowed_serial, &borrowed_pin, &reason), + &guard, &file, CLUSTER_WAL_REUSE_E2_APPLY_TIMELINE_SWITCH, &borrowed_serial, + &borrowed_pin, &reason), CLUSTER_WAL_GUARD_BLOCKED); UT_ASSERT_EQ(reason, CLUSTER_WAL_DENY_ROOT_REQUIRED); UT_ASSERT_NULL(borrowed_serial); UT_ASSERT_NULL(borrowed_pin); UT_ASSERT_EQ(cluster_wal_reuse_guard_finish(&guard, &outcome, &reason), CLUSTER_WALR_RELEASE_NOT_HELD); - UT_ASSERT_EQ(cluster_wal_retention_pin_release(&pin), - CLUSTER_WALR_RELEASE_CONFIRMED); + UT_ASSERT_EQ(cluster_wal_retention_pin_release(&pin), CLUSTER_WALR_RELEASE_CONFIRMED); cluster_wal_threads_dir = NULL; UT_ASSERT_EQ(unlink(retained_path), 0); @@ -1570,19 +1414,15 @@ UT_TEST(test_correctness_action_context_preflights_e2_without_pin) char thread_dir[MAXPGPATH]; char wal_path[MAXPGPATH]; char retained_path[MAXPGPATH]; - ClusterWalRetentionE1Context context = {0}; - ClusterWalReuseActionGuard guard = {0}; - ClusterWalFileIdentity file = { - .thread_id = 1, - .kind = CLUSTER_WAL_FILE_NORMAL, - .tli = 1, - .segno = 1 - }; + ClusterWalRetentionE1Context context = { 0 }; + ClusterWalReuseActionGuard guard = { 0 }; + ClusterWalFileIdentity file + = { .thread_id = 1, .kind = CLUSTER_WAL_FILE_NORMAL, .tli = 1, .segno = 1 }; ClusterWalReuseDenyReason reason; ClusterWalTerminalOutcome outcome; PgracExternalFenceNeedSetV1 *needs = NULL; - const PgracExternalFenceAdmissionSetV1 *admissions = - (const PgracExternalFenceAdmissionSetV1 *)(uintptr_t)0x3000; + const PgracExternalFenceAdmissionSetV1 *admissions + = (const PgracExternalFenceAdmissionSetV1 *)(uintptr_t)0x3000; reset_pin_fakes(); root_dir = mkdtemp(root_template); @@ -1591,53 +1431,44 @@ UT_TEST(test_correctness_action_context_preflights_e2_without_pin) UT_ASSERT_EQ(mkdir(thread_dir, 0700), 0); write_test_wal_segment(thread_dir, 1, 1, wal_path, sizeof(wal_path)); cluster_wal_threads_dir = root_dir; - fake_preflight_root = make_root( - 1, CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_REQUIRED, 1, - TEST_WAL_SEG_SIZE * 4, TEST_WAL_SEG_SIZE * 5); + fake_preflight_root = make_root(1, CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_REQUIRED, 1, + TEST_WAL_SEG_SIZE * 4, TEST_WAL_SEG_SIZE * 5); fake_preflight_root.identity = make_duty(1); fake_preflight_token = make_root_token(&fake_preflight_root.identity); fake_preflight_root.root_flags = fake_preflight_token.root_flags; fake_preflight_root_ready = true; - UT_ASSERT_EQ(cluster_wal_retention_action_begin( - &context, 1, &reason), CLUSTER_WAL_GUARD_OK); + UT_ASSERT_EQ(cluster_wal_retention_action_begin(&context, 1, &reason), CLUSTER_WAL_GUARD_OK); UT_ASSERT_EQ(fake_acquire_call_count, 0); - UT_ASSERT_EQ(cluster_wal_reuse_guard_init(&guard, &reason), + UT_ASSERT_EQ(cluster_wal_reuse_guard_init(&guard, &reason), CLUSTER_WAL_GUARD_OK); + UT_ASSERT_EQ(cluster_wal_retention_action_preflight(&context, &file, + CLUSTER_WAL_REUSE_E2_APPLY_TIMELINE_SWITCH, + &guard, &needs, &reason), CLUSTER_WAL_GUARD_OK); - UT_ASSERT_EQ(cluster_wal_retention_action_preflight( - &context, &file, - CLUSTER_WAL_REUSE_E2_APPLY_TIMELINE_SWITCH, - &guard, &needs, &reason), CLUSTER_WAL_GUARD_OK); UT_ASSERT_NOT_NULL(needs); UT_ASSERT_EQ(guard.entry, CLUSTER_WAL_REUSE_E2_APPLY_TIMELINE_SWITCH); - UT_ASSERT_EQ(cluster_wal_reuse_guard_fence_admitted_nowait( - &guard, admissions, &reason), CLUSTER_WAL_GUARD_OK); + UT_ASSERT_EQ(cluster_wal_reuse_guard_fence_admitted_nowait(&guard, admissions, &reason), + CLUSTER_WAL_GUARD_OK); fake_acquire_result_count = 1; fake_acquire_results[0] = CLUSTER_LOCK_ACQUIRE_NEED_PG_NATIVE_LOCK; - UT_ASSERT_EQ(cluster_wal_reuse_guard_arm( - &guard, NULL, NULL, &reason), CLUSTER_WAL_GUARD_OK); - UT_ASSERT_EQ(cluster_wal_reuse_guard_l3_begin( - &guard, CLUSTER_WAL_PHYSICAL_REMOVE, &reason), - CLUSTER_WAL_GUARD_OK); - UT_ASSERT_EQ(cluster_wal_reuse_guard_remove(&guard, &reason), - CLUSTER_WAL_GUARD_OK); - UT_ASSERT_EQ(cluster_wal_reuse_guard_bookkeep(&guard, &reason), + UT_ASSERT_EQ(cluster_wal_reuse_guard_arm(&guard, NULL, NULL, &reason), CLUSTER_WAL_GUARD_OK); + UT_ASSERT_EQ(cluster_wal_reuse_guard_l3_begin(&guard, CLUSTER_WAL_PHYSICAL_REMOVE, &reason), CLUSTER_WAL_GUARD_OK); + UT_ASSERT_EQ(cluster_wal_reuse_guard_remove(&guard, &reason), CLUSTER_WAL_GUARD_OK); + UT_ASSERT_EQ(cluster_wal_reuse_guard_bookkeep(&guard, &reason), CLUSTER_WAL_GUARD_OK); UT_ASSERT_EQ(cluster_wal_reuse_guard_finish(&guard, &outcome, &reason), CLUSTER_WALR_RELEASE_CONFIRMED); UT_ASSERT_EQ(outcome, CLUSTER_WAL_TERMINAL_REMOVED); UT_ASSERT_EQ(access(wal_path, F_OK), -1); cluster_external_fence_need_set_release(&needs); - write_test_wal_segment( - thread_dir, 1, 4, retained_path, sizeof(retained_path)); + write_test_wal_segment(thread_dir, 1, 4, retained_path, sizeof(retained_path)); file.segno = 4; - UT_ASSERT_EQ(cluster_wal_reuse_guard_init(&guard, &reason), - CLUSTER_WAL_GUARD_OK); - UT_ASSERT_EQ(cluster_wal_retention_action_preflight( - &context, &file, - CLUSTER_WAL_REUSE_E2_APPLY_TIMELINE_SWITCH, - &guard, &needs, &reason), CLUSTER_WAL_GUARD_BLOCKED); + UT_ASSERT_EQ(cluster_wal_reuse_guard_init(&guard, &reason), CLUSTER_WAL_GUARD_OK); + UT_ASSERT_EQ(cluster_wal_retention_action_preflight(&context, &file, + CLUSTER_WAL_REUSE_E2_APPLY_TIMELINE_SWITCH, + &guard, &needs, &reason), + CLUSTER_WAL_GUARD_BLOCKED); UT_ASSERT_EQ(reason, CLUSTER_WAL_DENY_ROOT_REQUIRED); UT_ASSERT_NULL(needs); UT_ASSERT_EQ(access(retained_path, F_OK), 0); @@ -1654,12 +1485,11 @@ UT_TEST(test_correctness_action_context_preflights_e2_without_pin) UT_TEST(test_reuse_guard_init_and_empty_finish_exact) { - ClusterWalReuseActionGuard guard = {0}; + ClusterWalReuseActionGuard guard = { 0 }; ClusterWalReuseDenyReason reason = CLUSTER_WAL_DENY_GUARD_STATE; ClusterWalTerminalOutcome outcome = CLUSTER_WAL_TERMINAL_CREATED; - UT_ASSERT_EQ(cluster_wal_reuse_guard_init(&guard, &reason), - CLUSTER_WAL_GUARD_OK); + UT_ASSERT_EQ(cluster_wal_reuse_guard_init(&guard, &reason), CLUSTER_WAL_GUARD_OK); UT_ASSERT_EQ(reason, CLUSTER_WAL_DENY_NONE); UT_ASSERT_EQ(guard.magic, CLUSTER_WAL_REUSE_GUARD_MAGIC); UT_ASSERT_EQ(guard.version, CLUSTER_WAL_REUSE_GUARD_VERSION); @@ -1680,25 +1510,22 @@ UT_TEST(test_reuse_guard_init_and_empty_finish_exact) UT_TEST(test_e1_coarse_holds_x_across_strong_floor_then_releases) { - ClusterWalRetentionE1Context context = {0}; + ClusterWalRetentionE1Context context = { 0 }; ClusterWalRootFoldResult fold_result = CLUSTER_WAL_FOLD_UNKNOWN; XLogSegNo floor = 0; ClusterWalReuseDenyReason reason; reset_pin_fakes(); - fake_preflight_root = make_root( - 1, CLUSTER_CONTROL_ROOT_LIFECYCLE_OPEN, 1, - TEST_WAL_SEG_SIZE * 4, TEST_WAL_SEG_SIZE * 5); + fake_preflight_root = make_root(1, CLUSTER_CONTROL_ROOT_LIFECYCLE_OPEN, 1, + TEST_WAL_SEG_SIZE * 4, TEST_WAL_SEG_SIZE * 5); fake_preflight_root.identity = make_duty(1); fake_preflight_token = make_root_token(&fake_preflight_root.identity); fake_preflight_token.lifecycle = CLUSTER_CONTROL_ROOT_LIFECYCLE_OPEN; - fake_preflight_token.root_flags &= - ~CLUSTER_CONTROL_ROOT_FLAG_RECOVERED_VALID; + fake_preflight_token.root_flags &= ~CLUSTER_CONTROL_ROOT_FLAG_RECOVERED_VALID; fake_preflight_root.root_flags = fake_preflight_token.root_flags; fake_preflight_root_ready = true; - UT_ASSERT_EQ(cluster_wal_retention_e1_coarse_begin( - &context, 1, &fold_result, &floor, &reason), + UT_ASSERT_EQ(cluster_wal_retention_e1_coarse_begin(&context, 1, &fold_result, &floor, &reason), CLUSTER_WAL_GUARD_OK); UT_ASSERT_EQ(fold_result, CLUSTER_WAL_FOLD_BOUNDED); UT_ASSERT_EQ(floor, 4); @@ -1716,23 +1543,21 @@ UT_TEST(test_e1_coarse_holds_x_across_strong_floor_then_releases) UT_TEST(test_e1_coarse_unknown_configured_root_releases_and_retains) { - ClusterWalRetentionE1Context context = {0}; + ClusterWalRetentionE1Context context = { 0 }; ClusterWalRootFoldResult fold_result = CLUSTER_WAL_FOLD_UNCONSTRAINED; XLogSegNo floor = 99; ClusterWalReuseDenyReason reason; reset_pin_fakes(); - fake_preflight_root = make_root( - 1, CLUSTER_CONTROL_ROOT_LIFECYCLE_OPEN, 1, - TEST_WAL_SEG_SIZE * 4, TEST_WAL_SEG_SIZE * 5); + fake_preflight_root = make_root(1, CLUSTER_CONTROL_ROOT_LIFECYCLE_OPEN, 1, + TEST_WAL_SEG_SIZE * 4, TEST_WAL_SEG_SIZE * 5); fake_preflight_root.identity = make_duty(1); fake_preflight_token = make_root_token(&fake_preflight_root.identity); fake_preflight_root.root_flags = fake_preflight_token.root_flags; fake_preflight_root_ready = true; fake_extra_configured_thread = true; - UT_ASSERT_EQ(cluster_wal_retention_e1_coarse_begin( - &context, 1, &fold_result, &floor, &reason), + UT_ASSERT_EQ(cluster_wal_retention_e1_coarse_begin(&context, 1, &fold_result, &floor, &reason), CLUSTER_WAL_GUARD_BLOCKED); UT_ASSERT_EQ(reason, CLUSTER_WAL_DENY_ROOT_REQUIRED); UT_ASSERT_EQ(fold_result, CLUSTER_WAL_FOLD_UNKNOWN); @@ -1743,18 +1568,16 @@ UT_TEST(test_e1_coarse_unknown_configured_root_releases_and_retains) UT_TEST(test_reuse_guard_rejects_dirty_init_and_stack_copy) { - ClusterWalReuseActionGuard guard = {0}; + ClusterWalReuseActionGuard guard = { 0 }; ClusterWalReuseActionGuard copy; ClusterWalReuseDenyReason reason = CLUSTER_WAL_DENY_NONE; ClusterWalTerminalOutcome outcome = CLUSTER_WAL_TERMINAL_CREATED; guard.flags = 1; - UT_ASSERT_EQ(cluster_wal_reuse_guard_init(&guard, &reason), - CLUSTER_WAL_GUARD_INVALID); + UT_ASSERT_EQ(cluster_wal_reuse_guard_init(&guard, &reason), CLUSTER_WAL_GUARD_INVALID); UT_ASSERT_EQ(reason, CLUSTER_WAL_DENY_GUARD_STATE); memset(&guard, 0, sizeof(guard)); - UT_ASSERT_EQ(cluster_wal_reuse_guard_init(&guard, &reason), - CLUSTER_WAL_GUARD_OK); + UT_ASSERT_EQ(cluster_wal_reuse_guard_init(&guard, &reason), CLUSTER_WAL_GUARD_OK); copy = guard; UT_ASSERT_EQ(cluster_wal_reuse_guard_finish(©, &outcome, &reason), CLUSTER_WALR_RELEASE_INVALID); @@ -1766,28 +1589,26 @@ UT_TEST(test_reuse_guard_rejects_dirty_init_and_stack_copy) UT_TEST(test_reuse_guard_zero_attempts_finish_unchanged) { - ClusterWalReuseActionGuard guard = {0}; + ClusterWalReuseActionGuard guard = { 0 }; ClusterWalReuseDenyReason reason; ClusterWalTerminalOutcome outcome; - UT_ASSERT_EQ(cluster_wal_reuse_guard_init(&guard, &reason), - CLUSTER_WAL_GUARD_OK); + UT_ASSERT_EQ(cluster_wal_reuse_guard_init(&guard, &reason), CLUSTER_WAL_GUARD_OK); guard.entry = CLUSTER_WAL_REUSE_E1_CHECKPOINT_RESTARTPOINT; guard.action = CLUSTER_WAL_ACTION_RETIRE_RECYCLE_OR_REMOVE; guard.state = CLUSTER_WAL_GUARD_ARMED; - guard.flags = CLUSTER_WAL_GUARD_F_PRIMARY_L3 - | CLUSTER_WAL_GUARD_F_PRIMARY_RECYCLE; - UT_ASSERT_EQ(cluster_wal_reuse_guard_note_zero_mutation( - &guard, CLUSTER_WAL_PHYSICAL_RECYCLE, &reason), - CLUSTER_WAL_GUARD_OK); - UT_ASSERT_EQ(cluster_wal_reuse_guard_terminal_durable( - &guard, CLUSTER_WAL_TERMINAL_RECYCLED, &reason), - CLUSTER_WAL_GUARD_INVALID); + guard.flags = CLUSTER_WAL_GUARD_F_PRIMARY_L3 | CLUSTER_WAL_GUARD_F_PRIMARY_RECYCLE; + UT_ASSERT_EQ( + cluster_wal_reuse_guard_note_zero_mutation(&guard, CLUSTER_WAL_PHYSICAL_RECYCLE, &reason), + CLUSTER_WAL_GUARD_OK); + UT_ASSERT_EQ( + cluster_wal_reuse_guard_terminal_durable(&guard, CLUSTER_WAL_TERMINAL_RECYCLED, &reason), + CLUSTER_WAL_GUARD_INVALID); UT_ASSERT_EQ(reason, CLUSTER_WAL_DENY_GUARD_STATE); guard.flags |= CLUSTER_WAL_GUARD_F_FALLBACK_L3; - UT_ASSERT_EQ(cluster_wal_reuse_guard_note_zero_mutation( - &guard, CLUSTER_WAL_PHYSICAL_REMOVE, &reason), - CLUSTER_WAL_GUARD_OK); + UT_ASSERT_EQ( + cluster_wal_reuse_guard_note_zero_mutation(&guard, CLUSTER_WAL_PHYSICAL_REMOVE, &reason), + CLUSTER_WAL_GUARD_OK); UT_ASSERT_EQ(cluster_wal_reuse_guard_finish(&guard, &outcome, &reason), CLUSTER_WALR_RELEASE_NOT_HELD); UT_ASSERT_EQ(outcome, CLUSTER_WAL_TERMINAL_UNCHANGED); @@ -1796,30 +1617,27 @@ UT_TEST(test_reuse_guard_zero_attempts_finish_unchanged) UT_TEST(test_reuse_guard_terminal_mapping_bookkeep_and_finish) { - ClusterWalReuseActionGuard guard = {0}; + ClusterWalReuseActionGuard guard = { 0 }; ClusterWalReuseDenyReason reason; ClusterWalTerminalOutcome outcome; - UT_ASSERT_EQ(cluster_wal_reuse_guard_init(&guard, &reason), - CLUSTER_WAL_GUARD_OK); + UT_ASSERT_EQ(cluster_wal_reuse_guard_init(&guard, &reason), CLUSTER_WAL_GUARD_OK); guard.entry = CLUSTER_WAL_REUSE_E4_PARTIAL_RENAME; guard.action = CLUSTER_WAL_ACTION_RENAME_PARTIAL; guard.state = CLUSTER_WAL_GUARD_ARMED; guard.flags = CLUSTER_WAL_GUARD_F_PRIMARY_L3; - UT_ASSERT_EQ(cluster_wal_reuse_guard_terminal_durable( - &guard, CLUSTER_WAL_TERMINAL_REMOVED, &reason), - CLUSTER_WAL_GUARD_INVALID); + UT_ASSERT_EQ( + cluster_wal_reuse_guard_terminal_durable(&guard, CLUSTER_WAL_TERMINAL_REMOVED, &reason), + CLUSTER_WAL_GUARD_INVALID); UT_ASSERT_EQ(reason, CLUSTER_WAL_DENY_GUARD_STATE); UT_ASSERT_EQ(guard.state, CLUSTER_WAL_GUARD_ARMED); UT_ASSERT_EQ(cluster_wal_reuse_guard_terminal_durable( - &guard, CLUSTER_WAL_TERMINAL_RENAMED_PARTIAL, &reason), + &guard, CLUSTER_WAL_TERMINAL_RENAMED_PARTIAL, &reason), CLUSTER_WAL_GUARD_OK); UT_ASSERT_EQ(guard.state, CLUSTER_WAL_GUARD_TERMINAL_DURABLE); - UT_ASSERT_EQ(cluster_wal_reuse_guard_bookkeep(&guard, &reason), - CLUSTER_WAL_GUARD_OK); + UT_ASSERT_EQ(cluster_wal_reuse_guard_bookkeep(&guard, &reason), CLUSTER_WAL_GUARD_OK); UT_ASSERT_EQ(guard.state, CLUSTER_WAL_GUARD_BOOKKEPT); - UT_ASSERT_EQ(cluster_wal_reuse_guard_bookkeep(&guard, &reason), - CLUSTER_WAL_GUARD_INVALID); + UT_ASSERT_EQ(cluster_wal_reuse_guard_bookkeep(&guard, &reason), CLUSTER_WAL_GUARD_INVALID); UT_ASSERT_EQ(cluster_wal_reuse_guard_finish(&guard, &outcome, &reason), CLUSTER_WALR_RELEASE_NOT_HELD); UT_ASSERT_EQ(outcome, CLUSTER_WAL_TERMINAL_RENAMED_PARTIAL); @@ -1828,7 +1646,7 @@ UT_TEST(test_reuse_guard_terminal_mapping_bookkeep_and_finish) UT_TEST(test_reuse_guard_preflight_rejects_closed_matrix_before_authority) { - ClusterWalReuseActionGuard guard = {0}; + ClusterWalReuseActionGuard guard = { 0 }; ClusterWalReuseGuardRequest request; ClusterWalReuseDenyReason reason; PgracExternalFenceNeedSetV1 *needs = NULL; @@ -1841,85 +1659,78 @@ UT_TEST(test_reuse_guard_preflight_rejects_closed_matrix_before_authority) request.duty = make_duty(1); request.root_read = make_root_token(&request.duty); request.formation = (const ClusterFormationWitnessV1 *)(uintptr_t)0x1000; - UT_ASSERT_EQ(cluster_wal_reuse_guard_init(&guard, &reason), - CLUSTER_WAL_GUARD_OK); + UT_ASSERT_EQ(cluster_wal_reuse_guard_init(&guard, &reason), CLUSTER_WAL_GUARD_OK); request.entry = CLUSTER_WAL_REUSE_E5_RESTORE_STAGING; request.action = CLUSTER_WAL_ACTION_RETIRE_RECYCLE_OR_REMOVE; - UT_ASSERT_EQ(cluster_wal_reuse_guard_preflight( - &guard, &request, &needs, &reason), + UT_ASSERT_EQ(cluster_wal_reuse_guard_preflight(&guard, &request, &needs, &reason), CLUSTER_WAL_GUARD_INVALID); UT_ASSERT_EQ(reason, CLUSTER_WAL_DENY_INVALID_IDENTITY); UT_ASSERT_NULL(needs); UT_ASSERT_EQ(guard.state, CLUSTER_WAL_GUARD_EMPTY); request.entry = CLUSTER_WAL_REUSE_E7_EXTERNAL_CLEANUP; - UT_ASSERT_EQ(cluster_wal_reuse_guard_preflight( - &guard, &request, &needs, &reason), + UT_ASSERT_EQ(cluster_wal_reuse_guard_preflight(&guard, &request, &needs, &reason), CLUSTER_WAL_GUARD_INVALID); UT_ASSERT_EQ(reason, CLUSTER_WAL_DENY_INVALID_IDENTITY); request.entry = CLUSTER_WAL_REUSE_E4_PARTIAL_RENAME; request.action = CLUSTER_WAL_ACTION_RENAME_PARTIAL; request.source_kind = CLUSTER_WAL_INSTALL_SOURCE_ARCHIVE_STAGE; - UT_ASSERT_EQ(cluster_wal_reuse_guard_preflight( - &guard, &request, &needs, &reason), + UT_ASSERT_EQ(cluster_wal_reuse_guard_preflight(&guard, &request, &needs, &reason), CLUSTER_WAL_GUARD_INVALID); UT_ASSERT_EQ(reason, CLUSTER_WAL_DENY_INVALID_IDENTITY); request.entry = CLUSTER_WAL_REUSE_E3_ARCHIVE_END; request.action = CLUSTER_WAL_ACTION_CREATE_ABSENT; request.source_kind = CLUSTER_WAL_INSTALL_SOURCE_NONE; - UT_ASSERT_EQ(cluster_wal_reuse_guard_preflight( - &guard, &request, &needs, &reason), + UT_ASSERT_EQ(cluster_wal_reuse_guard_preflight(&guard, &request, &needs, &reason), CLUSTER_WAL_GUARD_INVALID); UT_ASSERT_EQ(reason, CLUSTER_WAL_DENY_INVALID_IDENTITY); - UT_ASSERT_EQ(cluster_wal_reuse_guard_finish(&guard, - &(ClusterWalTerminalOutcome){ CLUSTER_WAL_TERMINAL_CREATED }, - &reason), CLUSTER_WALR_RELEASE_NOT_HELD); + UT_ASSERT_EQ(cluster_wal_reuse_guard_finish( + &guard, &(ClusterWalTerminalOutcome){ CLUSTER_WAL_TERMINAL_CREATED }, &reason), + CLUSTER_WALR_RELEASE_NOT_HELD); } UT_TEST(test_reuse_guard_fence_admission_is_na_or_full_set_and) { - ClusterWalReuseActionGuard guard = {0}; + ClusterWalReuseActionGuard guard = { 0 }; ClusterWalReuseDenyReason reason; ClusterWalTerminalOutcome outcome; - const ClusterFormationWitnessV1 *formation = - (const ClusterFormationWitnessV1 *)(uintptr_t)0x1000; - const PgracExternalFenceNeedSetV1 *needs = - (const PgracExternalFenceNeedSetV1 *)(uintptr_t)0x2000; - const PgracExternalFenceAdmissionSetV1 *admissions = - (const PgracExternalFenceAdmissionSetV1 *)(uintptr_t)0x3000; + const ClusterFormationWitnessV1 *formation + = (const ClusterFormationWitnessV1 *)(uintptr_t)0x1000; + const PgracExternalFenceNeedSetV1 *needs + = (const PgracExternalFenceNeedSetV1 *)(uintptr_t)0x2000; + const PgracExternalFenceAdmissionSetV1 *admissions + = (const PgracExternalFenceAdmissionSetV1 *)(uintptr_t)0x3000; reset_pin_fakes(); - UT_ASSERT_EQ(cluster_wal_reuse_guard_init(&guard, &reason), - CLUSTER_WAL_GUARD_OK); + UT_ASSERT_EQ(cluster_wal_reuse_guard_init(&guard, &reason), CLUSTER_WAL_GUARD_OK); guard.state = CLUSTER_WAL_GUARD_PREFLIGHTED; guard.formation = formation; - UT_ASSERT_EQ(cluster_wal_reuse_guard_fence_admitted_nowait( - &guard, NULL, &reason), CLUSTER_WAL_GUARD_OK); + UT_ASSERT_EQ(cluster_wal_reuse_guard_fence_admitted_nowait(&guard, NULL, &reason), + CLUSTER_WAL_GUARD_OK); UT_ASSERT_EQ(guard.state, CLUSTER_WAL_GUARD_FENCE_ADMITTED_OR_NA); UT_ASSERT_EQ(cluster_wal_reuse_guard_finish(&guard, &outcome, &reason), CLUSTER_WALR_RELEASE_NOT_HELD); - UT_ASSERT_EQ(cluster_wal_reuse_guard_init(&guard, &reason), - CLUSTER_WAL_GUARD_OK); + UT_ASSERT_EQ(cluster_wal_reuse_guard_init(&guard, &reason), CLUSTER_WAL_GUARD_OK); guard.state = CLUSTER_WAL_GUARD_PREFLIGHTED; guard.formation = formation; guard.needs_or_null = needs; fake_need_count = 2; fake_admission_count = 1; - UT_ASSERT_EQ(cluster_wal_reuse_guard_fence_admitted_nowait( - &guard, admissions, &reason), CLUSTER_WAL_GUARD_BLOCKED); + UT_ASSERT_EQ(cluster_wal_reuse_guard_fence_admitted_nowait(&guard, admissions, &reason), + CLUSTER_WAL_GUARD_BLOCKED); UT_ASSERT_EQ(reason, CLUSTER_WAL_DENY_FENCE_UNAVAILABLE); UT_ASSERT_EQ(guard.state, CLUSTER_WAL_GUARD_PREFLIGHTED); fake_admission_count = 2; fake_admission_digest.bytes[0] = 1; - UT_ASSERT_EQ(cluster_wal_reuse_guard_fence_admitted_nowait( - &guard, admissions, &reason), CLUSTER_WAL_GUARD_BLOCKED); + UT_ASSERT_EQ(cluster_wal_reuse_guard_fence_admitted_nowait(&guard, admissions, &reason), + CLUSTER_WAL_GUARD_BLOCKED); fake_need_digest.bytes[0] = 1; - UT_ASSERT_EQ(cluster_wal_reuse_guard_fence_admitted_nowait( - &guard, admissions, &reason), CLUSTER_WAL_GUARD_OK); + UT_ASSERT_EQ(cluster_wal_reuse_guard_fence_admitted_nowait(&guard, admissions, &reason), + CLUSTER_WAL_GUARD_OK); UT_ASSERT_EQ(guard.admissions_or_null, admissions); UT_ASSERT_EQ(guard.state, CLUSTER_WAL_GUARD_FENCE_ADMITTED_OR_NA); UT_ASSERT_EQ(cluster_wal_reuse_guard_finish(&guard, &outcome, &reason), @@ -1940,14 +1751,14 @@ UT_TEST(test_reuse_guard_preflight_stamps_folds_and_builds_needset) char recycle_path[MAXPGPATH]; char held_recycle_path[MAXPGPATH]; XLogLongPageHeaderData header; - ClusterWalReuseActionGuard guard = {0}; + ClusterWalReuseActionGuard guard = { 0 }; ClusterWalReuseGuardRequest request; ClusterWalFileIdentity destination; ClusterWalReuseDenyReason reason; ClusterWalTerminalOutcome outcome; PgracExternalFenceNeedSetV1 *needs = NULL; - const PgracExternalFenceAdmissionSetV1 *admissions = - (const PgracExternalFenceAdmissionSetV1 *)(uintptr_t)0x5000; + const PgracExternalFenceAdmissionSetV1 *admissions + = (const PgracExternalFenceAdmissionSetV1 *)(uintptr_t)0x5000; int fd; reset_pin_fakes(); @@ -1985,8 +1796,7 @@ UT_TEST(test_reuse_guard_preflight_stamps_folds_and_builds_needset) request.root_read = make_root_token(&request.duty); request.formation = (const ClusterFormationWitnessV1 *)(uintptr_t)0x1000; fake_preflight_root.identity = request.duty; - fake_preflight_root.lifecycle = - CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_REQUIRED; + fake_preflight_root.lifecycle = CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_REQUIRED; fake_preflight_root.root_flags = request.root_read.root_flags; fake_preflight_root.root_publish_seq = 1; fake_preflight_root.checkpoint_tli = 1; @@ -1996,22 +1806,20 @@ UT_TEST(test_reuse_guard_preflight_stamps_folds_and_builds_needset) fake_preflight_token = request.root_read; fake_preflight_root_ready = true; - UT_ASSERT_EQ(cluster_wal_reuse_guard_init(&guard, &reason), + UT_ASSERT_EQ(cluster_wal_reuse_guard_init(&guard, &reason), CLUSTER_WAL_GUARD_OK); + UT_ASSERT_EQ(cluster_wal_reuse_guard_preflight(&guard, &request, &needs, &reason), CLUSTER_WAL_GUARD_OK); - UT_ASSERT_EQ(cluster_wal_reuse_guard_preflight( - &guard, &request, &needs, &reason), CLUSTER_WAL_GUARD_OK); UT_ASSERT_EQ(reason, CLUSTER_WAL_DENY_NONE); UT_ASSERT_NOT_NULL(needs); UT_ASSERT_EQ(guard.state, CLUSTER_WAL_GUARD_PREFLIGHTED); UT_ASSERT_EQ(guard.pre_action_stamp.platform, CLUSTER_WAL_OBJECT_POSIX); UT_ASSERT_EQ(guard.pre_action_stamp.parsed_identity.segno, 1); UT_ASSERT_EQ(guard.needs_or_null, needs); - UT_ASSERT_EQ(cluster_wal_reuse_guard_fence_admitted_nowait( - &guard, admissions, &reason), CLUSTER_WAL_GUARD_OK); + UT_ASSERT_EQ(cluster_wal_reuse_guard_fence_admitted_nowait(&guard, admissions, &reason), + CLUSTER_WAL_GUARD_OK); fake_acquire_result_count = 1; fake_acquire_results[0] = CLUSTER_LOCK_ACQUIRE_NEED_PG_NATIVE_LOCK; - UT_ASSERT_EQ(cluster_wal_reuse_guard_arm( - &guard, NULL, NULL, &reason), CLUSTER_WAL_GUARD_OK); + UT_ASSERT_EQ(cluster_wal_reuse_guard_arm(&guard, NULL, NULL, &reason), CLUSTER_WAL_GUARD_OK); UT_ASSERT_EQ(guard.state, CLUSTER_WAL_GUARD_ARMED); UT_ASSERT(guard.walr.held); UT_ASSERT(guard.walr.coordinated); @@ -2027,26 +1835,21 @@ UT_TEST(test_reuse_guard_preflight_stamps_folds_and_builds_needset) * the terminal identity authority if the configured pathname is swapped. */ snprintf(held_thread_dir, sizeof(held_thread_dir), "%s.held", thread_dir); UT_ASSERT_EQ(rename(thread_dir, held_thread_dir), 0); - snprintf(held_wal_path, sizeof(held_wal_path), "%s/%s", - held_thread_dir, wal_name); + snprintf(held_wal_path, sizeof(held_wal_path), "%s/%s", held_thread_dir, wal_name); UT_ASSERT_EQ(mkdir(thread_dir, 0700), 0); - snprintf(replacement_wal_path, sizeof(replacement_wal_path), "%s/%s", - thread_dir, wal_name); + snprintf(replacement_wal_path, sizeof(replacement_wal_path), "%s/%s", thread_dir, wal_name); fd = open(replacement_wal_path, O_RDWR | O_CREAT | O_EXCL, 0600); UT_ASSERT(fd >= 0); UT_ASSERT_EQ(ftruncate(fd, TEST_WAL_SEG_SIZE), 0); UT_ASSERT_EQ(pwrite(fd, &header, sizeof(header), 0), sizeof(header)); close(fd); - UT_ASSERT_EQ(cluster_wal_reuse_guard_l3_begin( - &guard, CLUSTER_WAL_PHYSICAL_REMOVE, &reason), - CLUSTER_WAL_GUARD_OK); - UT_ASSERT_EQ(cluster_wal_reuse_guard_remove(&guard, &reason), + UT_ASSERT_EQ(cluster_wal_reuse_guard_l3_begin(&guard, CLUSTER_WAL_PHYSICAL_REMOVE, &reason), CLUSTER_WAL_GUARD_OK); + UT_ASSERT_EQ(cluster_wal_reuse_guard_remove(&guard, &reason), CLUSTER_WAL_GUARD_OK); UT_ASSERT_EQ(access(held_wal_path, F_OK), -1); UT_ASSERT_EQ(errno, ENOENT); UT_ASSERT_EQ(access(replacement_wal_path, F_OK), 0); - UT_ASSERT_EQ(cluster_wal_reuse_guard_bookkeep(&guard, &reason), - CLUSTER_WAL_GUARD_OK); + UT_ASSERT_EQ(cluster_wal_reuse_guard_bookkeep(&guard, &reason), CLUSTER_WAL_GUARD_OK); UT_ASSERT_EQ(cluster_wal_reuse_guard_finish(&guard, &outcome, &reason), CLUSTER_WALR_RELEASE_CONFIRMED); UT_ASSERT_EQ(outcome, CLUSTER_WAL_TERMINAL_REMOVED); @@ -2062,8 +1865,8 @@ UT_TEST(test_reuse_guard_preflight_stamps_folds_and_builds_needset) close(fd); cluster_external_fence_need_set_release(&needs); if (fake_resource_release_callback != NULL) - fake_resource_release_callback(RESOURCE_RELEASE_BEFORE_LOCKS, true, - false, fake_resource_release_arg); + fake_resource_release_callback(RESOURCE_RELEASE_BEFORE_LOCKS, true, false, + fake_resource_release_arg); UT_ASSERT_EQ(fake_release_call_count, 1); /* Recycle must rename within the preflight dirfd and must not follow a @@ -2071,43 +1874,35 @@ UT_TEST(test_reuse_guard_preflight_stamps_folds_and_builds_needset) memset(&guard, 0, sizeof(guard)); fake_acquire_result_count = 2; fake_acquire_results[1] = CLUSTER_LOCK_ACQUIRE_NEED_PG_NATIVE_LOCK; - UT_ASSERT_EQ(cluster_wal_reuse_guard_init(&guard, &reason), + UT_ASSERT_EQ(cluster_wal_reuse_guard_init(&guard, &reason), CLUSTER_WAL_GUARD_OK); + UT_ASSERT_EQ(cluster_wal_reuse_guard_preflight(&guard, &request, &needs, &reason), + CLUSTER_WAL_GUARD_OK); + UT_ASSERT_EQ(cluster_wal_reuse_guard_fence_admitted_nowait(&guard, admissions, &reason), CLUSTER_WAL_GUARD_OK); - UT_ASSERT_EQ(cluster_wal_reuse_guard_preflight( - &guard, &request, &needs, &reason), CLUSTER_WAL_GUARD_OK); - UT_ASSERT_EQ(cluster_wal_reuse_guard_fence_admitted_nowait( - &guard, admissions, &reason), CLUSTER_WAL_GUARD_OK); - UT_ASSERT_EQ(cluster_wal_reuse_guard_arm( - &guard, NULL, NULL, &reason), CLUSTER_WAL_GUARD_OK); + UT_ASSERT_EQ(cluster_wal_reuse_guard_arm(&guard, NULL, NULL, &reason), CLUSTER_WAL_GUARD_OK); destination = request.file; destination.tli = 2; destination.segno = 2; - XLogFileName(recycle_name, destination.tli, destination.segno, - wal_segment_size); - snprintf(recycle_path, sizeof(recycle_path), "%s/%s", - thread_dir, recycle_name); + XLogFileName(recycle_name, destination.tli, destination.segno, wal_segment_size); + snprintf(recycle_path, sizeof(recycle_path), "%s/%s", thread_dir, recycle_name); UT_ASSERT_EQ(rename(thread_dir, held_thread_dir), 0); - snprintf(held_wal_path, sizeof(held_wal_path), "%s/%s", - held_thread_dir, wal_name); - snprintf(held_recycle_path, sizeof(held_recycle_path), "%s/%s", - held_thread_dir, recycle_name); + snprintf(held_wal_path, sizeof(held_wal_path), "%s/%s", held_thread_dir, wal_name); + snprintf(held_recycle_path, sizeof(held_recycle_path), "%s/%s", held_thread_dir, recycle_name); UT_ASSERT_EQ(mkdir(thread_dir, 0700), 0); fd = open(replacement_wal_path, O_RDWR | O_CREAT | O_EXCL, 0600); UT_ASSERT(fd >= 0); UT_ASSERT_EQ(ftruncate(fd, TEST_WAL_SEG_SIZE), 0); UT_ASSERT_EQ(pwrite(fd, &header, sizeof(header), 0), sizeof(header)); close(fd); - UT_ASSERT_EQ(cluster_wal_reuse_guard_l3_begin( - &guard, CLUSTER_WAL_PHYSICAL_RECYCLE, &reason), + UT_ASSERT_EQ(cluster_wal_reuse_guard_l3_begin(&guard, CLUSTER_WAL_PHYSICAL_RECYCLE, &reason), + CLUSTER_WAL_GUARD_OK); + UT_ASSERT_EQ(cluster_wal_reuse_guard_recycle(&guard, &destination, &reason), CLUSTER_WAL_GUARD_OK); - UT_ASSERT_EQ(cluster_wal_reuse_guard_recycle( - &guard, &destination, &reason), CLUSTER_WAL_GUARD_OK); UT_ASSERT_EQ(access(held_wal_path, F_OK), -1); UT_ASSERT_EQ(errno, ENOENT); UT_ASSERT_EQ(access(held_recycle_path, F_OK), 0); UT_ASSERT_EQ(access(replacement_wal_path, F_OK), 0); - UT_ASSERT_EQ(cluster_wal_reuse_guard_bookkeep(&guard, &reason), - CLUSTER_WAL_GUARD_OK); + UT_ASSERT_EQ(cluster_wal_reuse_guard_bookkeep(&guard, &reason), CLUSTER_WAL_GUARD_OK); UT_ASSERT_EQ(cluster_wal_reuse_guard_finish(&guard, &outcome, &reason), CLUSTER_WALR_RELEASE_CONFIRMED); UT_ASSERT_EQ(outcome, CLUSTER_WAL_TERMINAL_RECYCLED); @@ -2128,18 +1923,16 @@ UT_TEST(test_reuse_guard_preflight_stamps_folds_and_builds_needset) memset(&guard, 0, sizeof(guard)); fake_acquire_result_count = 3; fake_acquire_results[2] = CLUSTER_LOCK_ACQUIRE_NEED_PG_NATIVE_LOCK; - UT_ASSERT_EQ(cluster_wal_reuse_guard_init(&guard, &reason), + UT_ASSERT_EQ(cluster_wal_reuse_guard_init(&guard, &reason), CLUSTER_WAL_GUARD_OK); + UT_ASSERT_EQ(cluster_wal_reuse_guard_preflight(&guard, &request, &needs, &reason), CLUSTER_WAL_GUARD_OK); - UT_ASSERT_EQ(cluster_wal_reuse_guard_preflight( - &guard, &request, &needs, &reason), CLUSTER_WAL_GUARD_OK); - UT_ASSERT_EQ(cluster_wal_reuse_guard_fence_admitted_nowait( - &guard, admissions, &reason), CLUSTER_WAL_GUARD_OK); - UT_ASSERT_EQ(cluster_wal_reuse_guard_arm( - &guard, NULL, NULL, &reason), CLUSTER_WAL_GUARD_OK); + UT_ASSERT_EQ(cluster_wal_reuse_guard_fence_admitted_nowait(&guard, admissions, &reason), + CLUSTER_WAL_GUARD_OK); + UT_ASSERT_EQ(cluster_wal_reuse_guard_arm(&guard, NULL, NULL, &reason), CLUSTER_WAL_GUARD_OK); UT_ASSERT_EQ(fake_native_acquire_call_count, 3); if (fake_resource_release_callback != NULL) - fake_resource_release_callback(RESOURCE_RELEASE_BEFORE_LOCKS, false, - false, fake_resource_release_arg); + fake_resource_release_callback(RESOURCE_RELEASE_BEFORE_LOCKS, false, false, + fake_resource_release_arg); UT_ASSERT_EQ(fake_release_call_count, 3); UT_ASSERT_EQ(fake_native_release_call_count, 3); UT_ASSERT_FALSE(guard.walr.held); @@ -2150,14 +1943,13 @@ UT_TEST(test_reuse_guard_preflight_stamps_folds_and_builds_needset) fake_acquire_result_count = 4; fake_acquire_results[3] = CLUSTER_LOCK_ACQUIRE_NEED_PG_NATIVE_LOCK; fake_native_acquire_result = LOCKACQUIRE_NOT_AVAIL; - UT_ASSERT_EQ(cluster_wal_reuse_guard_init(&guard, &reason), + UT_ASSERT_EQ(cluster_wal_reuse_guard_init(&guard, &reason), CLUSTER_WAL_GUARD_OK); + UT_ASSERT_EQ(cluster_wal_reuse_guard_preflight(&guard, &request, &needs, &reason), + CLUSTER_WAL_GUARD_OK); + UT_ASSERT_EQ(cluster_wal_reuse_guard_fence_admitted_nowait(&guard, admissions, &reason), CLUSTER_WAL_GUARD_OK); - UT_ASSERT_EQ(cluster_wal_reuse_guard_preflight( - &guard, &request, &needs, &reason), CLUSTER_WAL_GUARD_OK); - UT_ASSERT_EQ(cluster_wal_reuse_guard_fence_admitted_nowait( - &guard, admissions, &reason), CLUSTER_WAL_GUARD_OK); - UT_ASSERT_EQ(cluster_wal_reuse_guard_arm( - &guard, NULL, NULL, &reason), CLUSTER_WAL_GUARD_BLOCKED); + UT_ASSERT_EQ(cluster_wal_reuse_guard_arm(&guard, NULL, NULL, &reason), + CLUSTER_WAL_GUARD_BLOCKED); UT_ASSERT_EQ(reason, CLUSTER_WAL_DENY_GES_UNAVAILABLE); UT_ASSERT_EQ(guard.state, CLUSTER_WAL_GUARD_FENCE_ADMITTED_OR_NA); UT_ASSERT_FALSE(guard.walr.held); @@ -2171,10 +1963,9 @@ UT_TEST(test_reuse_guard_preflight_stamps_folds_and_builds_needset) memset(&guard, 0, sizeof(guard)); fake_preflight_root.checkpoint_lower_lsn = TEST_WAL_SEG_SIZE; fake_preflight_root.validated_tail_lsn_exclusive = TEST_WAL_SEG_SIZE * 2; - UT_ASSERT_EQ(cluster_wal_reuse_guard_init(&guard, &reason), - CLUSTER_WAL_GUARD_OK); - UT_ASSERT_EQ(cluster_wal_reuse_guard_preflight( - &guard, &request, &needs, &reason), CLUSTER_WAL_GUARD_BLOCKED); + UT_ASSERT_EQ(cluster_wal_reuse_guard_init(&guard, &reason), CLUSTER_WAL_GUARD_OK); + UT_ASSERT_EQ(cluster_wal_reuse_guard_preflight(&guard, &request, &needs, &reason), + CLUSTER_WAL_GUARD_BLOCKED); UT_ASSERT_EQ(reason, CLUSTER_WAL_DENY_ROOT_REQUIRED); UT_ASSERT_NULL(needs); UT_ASSERT_EQ(guard.state, CLUSTER_WAL_GUARD_EMPTY); @@ -2193,8 +1984,8 @@ UT_TEST(test_fold_unconfigured_is_unconstrained) ClusterWalRootFold fold; memset(inputs, 0, sizeof(inputs)); - UT_ASSERT_TRUE(cluster_wal_retention_fold_validated_roots( - inputs, lengthof(inputs), TEST_WAL_SEG_SIZE, &fold)); + UT_ASSERT_TRUE(cluster_wal_retention_fold_validated_roots(inputs, lengthof(inputs), + TEST_WAL_SEG_SIZE, &fold)); UT_ASSERT_EQ(fold.result, CLUSTER_WAL_FOLD_UNCONSTRAINED); UT_ASSERT_EQ(fold.nintervals, 0); } @@ -2205,10 +1996,10 @@ UT_TEST(test_fold_configured_missing_is_unknown) ClusterWalRootFold fold; inputs[0] = make_fold_input(true, CLUSTER_CONTROL_ROOT_ABSENT, - make_root(1, CLUSTER_CONTROL_ROOT_LIFECYCLE_OPEN, - 1, TEST_WAL_SEG_SIZE, TEST_WAL_SEG_SIZE * 2)); - UT_ASSERT_TRUE(cluster_wal_retention_fold_validated_roots( - inputs, lengthof(inputs), TEST_WAL_SEG_SIZE, &fold)); + make_root(1, CLUSTER_CONTROL_ROOT_LIFECYCLE_OPEN, 1, + TEST_WAL_SEG_SIZE, TEST_WAL_SEG_SIZE * 2)); + UT_ASSERT_TRUE(cluster_wal_retention_fold_validated_roots(inputs, lengthof(inputs), + TEST_WAL_SEG_SIZE, &fold)); UT_ASSERT_EQ(fold.result, CLUSTER_WAL_FOLD_UNKNOWN); UT_ASSERT_EQ(fold.nintervals, 0); } @@ -2219,15 +2010,13 @@ UT_TEST(test_fold_open_and_recovery_required_are_bounded) ClusterWalRootFold fold; inputs[0] = make_fold_input(true, CLUSTER_CONTROL_ROOT_OK_PRIMARY, - make_root(1, CLUSTER_CONTROL_ROOT_LIFECYCLE_OPEN, - 1, TEST_WAL_SEG_SIZE + 7, - TEST_WAL_SEG_SIZE * 3)); + make_root(1, CLUSTER_CONTROL_ROOT_LIFECYCLE_OPEN, 1, + TEST_WAL_SEG_SIZE + 7, TEST_WAL_SEG_SIZE * 3)); inputs[1] = make_fold_input(true, CLUSTER_CONTROL_ROOT_OK_PRIMARY_DEGRADED, - make_root(2, CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_REQUIRED, - 2, TEST_WAL_SEG_SIZE * 4, - TEST_WAL_SEG_SIZE * 6)); - UT_ASSERT_TRUE(cluster_wal_retention_fold_validated_roots( - inputs, lengthof(inputs), TEST_WAL_SEG_SIZE, &fold)); + make_root(2, CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_REQUIRED, 2, + TEST_WAL_SEG_SIZE * 4, TEST_WAL_SEG_SIZE * 6)); + UT_ASSERT_TRUE(cluster_wal_retention_fold_validated_roots(inputs, lengthof(inputs), + TEST_WAL_SEG_SIZE, &fold)); UT_ASSERT_EQ(fold.result, CLUSTER_WAL_FOLD_BOUNDED); UT_ASSERT_EQ(fold.nintervals, 2); UT_ASSERT_EQ(fold.intervals[0].thread_id, 1); @@ -2243,16 +2032,16 @@ UT_TEST(test_fold_terminal_lifecycles_contribute_nothing) ClusterWalRootFold fold; inputs[0] = make_fold_input(true, CLUSTER_CONTROL_ROOT_OK_PRIMARY, - make_root(1, CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_COMPLETE, - 1, TEST_WAL_SEG_SIZE, TEST_WAL_SEG_SIZE * 2)); + make_root(1, CLUSTER_CONTROL_ROOT_LIFECYCLE_RECOVERY_COMPLETE, 1, + TEST_WAL_SEG_SIZE, TEST_WAL_SEG_SIZE * 2)); inputs[1] = make_fold_input(true, CLUSTER_CONTROL_ROOT_OK_PRIMARY, - make_root(2, CLUSTER_CONTROL_ROOT_LIFECYCLE_CLOSED, - 1, TEST_WAL_SEG_SIZE, TEST_WAL_SEG_SIZE * 2)); + make_root(2, CLUSTER_CONTROL_ROOT_LIFECYCLE_CLOSED, 1, + TEST_WAL_SEG_SIZE, TEST_WAL_SEG_SIZE * 2)); inputs[2] = make_fold_input(true, CLUSTER_CONTROL_ROOT_OK_PRIMARY, - make_root(3, CLUSTER_CONTROL_ROOT_LIFECYCLE_RETIRED, - 1, TEST_WAL_SEG_SIZE, TEST_WAL_SEG_SIZE * 2)); - UT_ASSERT_TRUE(cluster_wal_retention_fold_validated_roots( - inputs, lengthof(inputs), TEST_WAL_SEG_SIZE, &fold)); + make_root(3, CLUSTER_CONTROL_ROOT_LIFECYCLE_RETIRED, 1, + TEST_WAL_SEG_SIZE, TEST_WAL_SEG_SIZE * 2)); + UT_ASSERT_TRUE(cluster_wal_retention_fold_validated_roots(inputs, lengthof(inputs), + TEST_WAL_SEG_SIZE, &fold)); UT_ASSERT_EQ(fold.result, CLUSTER_WAL_FOLD_UNCONSTRAINED); UT_ASSERT_EQ(fold.nintervals, 0); } @@ -2261,28 +2050,24 @@ UT_TEST(test_fold_refuses_invalid_root_shape) { ClusterWalRootFoldInput input; ClusterWalRootFold fold; - ClusterControlRootSnapshot root = make_root( - 1, CLUSTER_CONTROL_ROOT_LIFECYCLE_OPEN, 1, - TEST_WAL_SEG_SIZE, TEST_WAL_SEG_SIZE * 2); + ClusterControlRootSnapshot root = make_root(1, CLUSTER_CONTROL_ROOT_LIFECYCLE_OPEN, 1, + TEST_WAL_SEG_SIZE, TEST_WAL_SEG_SIZE * 2); root.tail_tli = 2; input = make_fold_input(true, CLUSTER_CONTROL_ROOT_OK_PRIMARY, root); - UT_ASSERT_TRUE(cluster_wal_retention_fold_validated_roots( - &input, 1, TEST_WAL_SEG_SIZE, &fold)); + UT_ASSERT_TRUE(cluster_wal_retention_fold_validated_roots(&input, 1, TEST_WAL_SEG_SIZE, &fold)); UT_ASSERT_EQ(fold.result, CLUSTER_WAL_FOLD_UNKNOWN); - root = make_root(1, CLUSTER_CONTROL_ROOT_LIFECYCLE_OPEN, 1, - TEST_WAL_SEG_SIZE * 2, TEST_WAL_SEG_SIZE); + root = make_root(1, CLUSTER_CONTROL_ROOT_LIFECYCLE_OPEN, 1, TEST_WAL_SEG_SIZE * 2, + TEST_WAL_SEG_SIZE); input = make_fold_input(true, CLUSTER_CONTROL_ROOT_OK_PRIMARY, root); - UT_ASSERT_TRUE(cluster_wal_retention_fold_validated_roots( - &input, 1, TEST_WAL_SEG_SIZE, &fold)); + UT_ASSERT_TRUE(cluster_wal_retention_fold_validated_roots(&input, 1, TEST_WAL_SEG_SIZE, &fold)); UT_ASSERT_EQ(fold.result, CLUSTER_WAL_FOLD_UNKNOWN); - root = make_root(1, CLUSTER_CONTROL_ROOT_LIFECYCLE_UNUSED, 1, - TEST_WAL_SEG_SIZE, TEST_WAL_SEG_SIZE * 2); + root = make_root(1, CLUSTER_CONTROL_ROOT_LIFECYCLE_UNUSED, 1, TEST_WAL_SEG_SIZE, + TEST_WAL_SEG_SIZE * 2); input = make_fold_input(true, CLUSTER_CONTROL_ROOT_OK_PRIMARY, root); - UT_ASSERT_TRUE(cluster_wal_retention_fold_validated_roots( - &input, 1, TEST_WAL_SEG_SIZE, &fold)); + UT_ASSERT_TRUE(cluster_wal_retention_fold_validated_roots(&input, 1, TEST_WAL_SEG_SIZE, &fold)); UT_ASSERT_EQ(fold.result, CLUSTER_WAL_FOLD_UNKNOWN); } @@ -2291,11 +2076,10 @@ UT_TEST(test_fold_empty_open_interval_is_not_bounded) ClusterWalRootFoldInput input; ClusterWalRootFold fold; - input = make_fold_input(true, CLUSTER_CONTROL_ROOT_OK_PRIMARY, - make_root(1, CLUSTER_CONTROL_ROOT_LIFECYCLE_OPEN, - 1, TEST_WAL_SEG_SIZE, TEST_WAL_SEG_SIZE)); - UT_ASSERT_TRUE(cluster_wal_retention_fold_validated_roots( - &input, 1, TEST_WAL_SEG_SIZE, &fold)); + input = make_fold_input( + true, CLUSTER_CONTROL_ROOT_OK_PRIMARY, + make_root(1, CLUSTER_CONTROL_ROOT_LIFECYCLE_OPEN, 1, TEST_WAL_SEG_SIZE, TEST_WAL_SEG_SIZE)); + UT_ASSERT_TRUE(cluster_wal_retention_fold_validated_roots(&input, 1, TEST_WAL_SEG_SIZE, &fold)); UT_ASSERT_EQ(fold.result, CLUSTER_WAL_FOLD_UNCONSTRAINED); UT_ASSERT_EQ(fold.nintervals, 0); } diff --git a/src/test/cluster_unit/test_cluster_wal_state.c b/src/test/cluster_unit/test_cluster_wal_state.c index 9480f19ee8d..57f4f2006f6 100644 --- a/src/test/cluster_unit/test_cluster_wal_state.c +++ b/src/test/cluster_unit/test_cluster_wal_state.c @@ -297,8 +297,7 @@ UT_TEST(test_crc_covers_watermark_fields) static void fill_a1_active_slot(ClusterWalStateSlot *slot) { - cluster_wal_state_slot_fill(slot, 4, 3, CLUSTER_WAL_SLOT_STATE_ACTIVE, 7, 100, 200, 300, - 400); + cluster_wal_state_slot_fill(slot, 4, 3, CLUSTER_WAL_SLOT_STATE_ACTIVE, 7, 100, 200, 300, 400); slot->checkpoint_redo_lsn = 500; slot->refresh_interval_ms = 600; slot->fpw_was_off = 1; @@ -510,8 +509,7 @@ cluster_r4_bit22_source_writer_enter(void) void cluster_r4_bit22_source_writer_leave(void) -{ -} +{} bool cluster_r4_bit22_source_close_begin(uint64 transition_epoch pg_attribute_unused(), @@ -534,9 +532,7 @@ main(int argc, char **argv) UT_PLAN(21); - - -UT_RUN(test_header_layout_locks); + UT_RUN(test_header_layout_locks); UT_RUN(test_slot_layout_locks); UT_RUN(test_slot_offset_macro_locks); UT_RUN(test_header_roundtrip); diff --git a/src/test/cluster_unit/test_cluster_wal_state_rmw.c b/src/test/cluster_unit/test_cluster_wal_state_rmw.c index 08fae3b8e6c..fa134cdfe10 100644 --- a/src/test/cluster_unit/test_cluster_wal_state_rmw.c +++ b/src/test/cluster_unit/test_cluster_wal_state_rmw.c @@ -417,8 +417,7 @@ fixture_reset(void) memset(virtual_file, 0, sizeof(virtual_file)); cluster_wal_state_header_fill(header, 123); - cluster_wal_state_slot_fill(slot, 4, 3, CLUSTER_WAL_SLOT_STATE_ACTIVE, 7, 100, 200, 300, - 400); + cluster_wal_state_slot_fill(slot, 4, 3, CLUSTER_WAL_SLOT_STATE_ACTIVE, 7, 100, 200, 300, 400); slot->checkpoint_redo_lsn = 500; slot->refresh_interval_ms = 600; slot->fpw_was_off = 1; @@ -483,8 +482,7 @@ UT_TEST(test_a1_verified_cf_gate_rejects_before_io) fixture_reset(); cluster_controlfile_shared_authority = false; - UT_ASSERT_EQ((int)cluster_wal_state_update_own( - &update, CLUSTER_WAL_STATE_CF_ACQUIRE_X, NULL), + UT_ASSERT_EQ((int)cluster_wal_state_update_own(&update, CLUSTER_WAL_STATE_CF_ACQUIRE_X, NULL), (int)CLUSTER_WAL_STATE_UPDATE_CF_UNAVAILABLE); assert_no_registry_io(); UT_ASSERT_EQ(stub_cf_lock_count, 0); @@ -492,32 +490,28 @@ UT_TEST(test_a1_verified_cf_gate_rejects_before_io) fixture_reset(); cluster_lms_enabled = false; stub_lms_ready = true; - UT_ASSERT_EQ((int)cluster_wal_state_update_own( - &update, CLUSTER_WAL_STATE_CF_ACQUIRE_X, NULL), + UT_ASSERT_EQ((int)cluster_wal_state_update_own(&update, CLUSTER_WAL_STATE_CF_ACQUIRE_X, NULL), (int)CLUSTER_WAL_STATE_UPDATE_CF_UNAVAILABLE); assert_no_registry_io(); UT_ASSERT_EQ(stub_cf_lock_count, 0); fixture_reset(); stub_lms_ready = false; - UT_ASSERT_EQ((int)cluster_wal_state_update_own( - &update, CLUSTER_WAL_STATE_CF_ACQUIRE_X, NULL), + UT_ASSERT_EQ((int)cluster_wal_state_update_own(&update, CLUSTER_WAL_STATE_CF_ACQUIRE_X, NULL), (int)CLUSTER_WAL_STATE_UPDATE_CF_UNAVAILABLE); assert_no_registry_io(); UT_ASSERT_EQ(stub_cf_lock_count, 0); fixture_reset(); stub_cf_master = -1; - UT_ASSERT_EQ((int)cluster_wal_state_update_own( - &update, CLUSTER_WAL_STATE_CF_ACQUIRE_X, NULL), + UT_ASSERT_EQ((int)cluster_wal_state_update_own(&update, CLUSTER_WAL_STATE_CF_ACQUIRE_X, NULL), (int)CLUSTER_WAL_STATE_UPDATE_CF_UNAVAILABLE); assert_no_registry_io(); UT_ASSERT_EQ(stub_cf_lock_count, 0); fixture_reset(); stub_cf_lock_ok = false; - UT_ASSERT_EQ((int)cluster_wal_state_update_own( - &update, CLUSTER_WAL_STATE_CF_ACQUIRE_X, NULL), + UT_ASSERT_EQ((int)cluster_wal_state_update_own(&update, CLUSTER_WAL_STATE_CF_ACQUIRE_X, NULL), (int)CLUSTER_WAL_STATE_UPDATE_CF_UNAVAILABLE); assert_no_registry_io(); UT_ASSERT_EQ(stub_cf_lock_count, 1); @@ -530,16 +524,17 @@ UT_TEST(test_a1_acquire_fresh_rmw_exact_order_and_distinct_postread) ClusterWalStateSlot before; ClusterWalStateSlot published; ClusterWalStateSlot *ondisk; - RmwEvent expected_events[] = {RMW_EVENT_CF_LOCK, RMW_EVENT_OPEN, RMW_EVENT_FSTAT, - RMW_EVENT_PREAD_HEADER, RMW_EVENT_PREAD_SLOT, RMW_EVENT_PWRITE_SLOT, RMW_EVENT_FSYNC, - RMW_EVENT_PREAD_SLOT, RMW_EVENT_CLOSE, RMW_EVENT_CF_UNLOCK}; + RmwEvent expected_events[] + = { RMW_EVENT_CF_LOCK, RMW_EVENT_OPEN, RMW_EVENT_FSTAT, RMW_EVENT_PREAD_HEADER, + RMW_EVENT_PREAD_SLOT, RMW_EVENT_PWRITE_SLOT, RMW_EVENT_FSYNC, RMW_EVENT_PREAD_SLOT, + RMW_EVENT_CLOSE, RMW_EVENT_CF_UNLOCK }; size_t i; fixture_reset(); memcpy(&before, virtual_file + CLUSTER_WAL_STATE_SLOT_OFFSET(4), sizeof(before)); - UT_ASSERT_EQ((int)cluster_wal_state_update_own( - &update, CLUSTER_WAL_STATE_CF_ACQUIRE_X, &published), - (int)CLUSTER_WAL_STATE_UPDATE_OK); + UT_ASSERT_EQ( + (int)cluster_wal_state_update_own(&update, CLUSTER_WAL_STATE_CF_ACQUIRE_X, &published), + (int)CLUSTER_WAL_STATE_UPDATE_OK); UT_ASSERT_EQ(event_count, (int)lengthof(expected_events)); for (i = 0; i < lengthof(expected_events); i++) UT_ASSERT_EQ((int)event_log[i], (int)expected_events[i]); @@ -579,8 +574,7 @@ UT_TEST(test_a1_release_uncertain_fails_closed) * succeeded and was post-read-verified. */ fixture_reset(); stub_cf_release_confirmed = false; - UT_ASSERT_EQ((int)cluster_wal_state_update_own( - &update, CLUSTER_WAL_STATE_CF_ACQUIRE_X, NULL), + UT_ASSERT_EQ((int)cluster_wal_state_update_own(&update, CLUSTER_WAL_STATE_CF_ACQUIRE_X, NULL), (int)CLUSTER_WAL_STATE_UPDATE_RELEASE_UNCERTAIN); UT_ASSERT_EQ(stub_cf_unlock_count, 1); /* The slot deliberately stays held (never a double grant). */ @@ -588,8 +582,7 @@ UT_TEST(test_a1_release_uncertain_fails_closed) fixture_reset(); /* Confirmed release keeps the exact existing success semantics. */ - UT_ASSERT_EQ((int)cluster_wal_state_update_own( - &update, CLUSTER_WAL_STATE_CF_ACQUIRE_X, NULL), + UT_ASSERT_EQ((int)cluster_wal_state_update_own(&update, CLUSTER_WAL_STATE_CF_ACQUIRE_X, NULL), (int)CLUSTER_WAL_STATE_UPDATE_OK); UT_ASSERT(!stub_cf_held); } @@ -600,8 +593,7 @@ UT_TEST(test_a1_short_write_and_fsync_fail_without_compensation) fixture_reset(); forced_pwrite_result = 511; - UT_ASSERT_EQ((int)cluster_wal_state_update_own( - &update, CLUSTER_WAL_STATE_CF_ACQUIRE_X, NULL), + UT_ASSERT_EQ((int)cluster_wal_state_update_own(&update, CLUSTER_WAL_STATE_CF_ACQUIRE_X, NULL), (int)CLUSTER_WAL_STATE_UPDATE_IO_ERROR); UT_ASSERT_EQ(pwrite_count, 1); UT_ASSERT_EQ(fsync_count, 0); @@ -610,8 +602,7 @@ UT_TEST(test_a1_short_write_and_fsync_fail_without_compensation) fixture_reset(); forced_fsync_result = -1; - UT_ASSERT_EQ((int)cluster_wal_state_update_own( - &update, CLUSTER_WAL_STATE_CF_ACQUIRE_X, NULL), + UT_ASSERT_EQ((int)cluster_wal_state_update_own(&update, CLUSTER_WAL_STATE_CF_ACQUIRE_X, NULL), (int)CLUSTER_WAL_STATE_UPDATE_IO_ERROR); UT_ASSERT_EQ(pwrite_count, 1); UT_ASSERT_EQ(fsync_count, 1); @@ -629,9 +620,9 @@ UT_TEST(test_a1_postread_mismatch_fails_without_compensation) memset(&sentinel, 0xa5, sizeof(sentinel)); memcpy(&published, &sentinel, sizeof(published)); force_postread_mismatch = true; - UT_ASSERT_EQ((int)cluster_wal_state_update_own( - &update, CLUSTER_WAL_STATE_CF_ACQUIRE_X, &published), - (int)CLUSTER_WAL_STATE_UPDATE_POSTREAD_MISMATCH); + UT_ASSERT_EQ( + (int)cluster_wal_state_update_own(&update, CLUSTER_WAL_STATE_CF_ACQUIRE_X, &published), + (int)CLUSTER_WAL_STATE_UPDATE_POSTREAD_MISMATCH); UT_ASSERT_EQ(pwrite_count, 1); UT_ASSERT_EQ(fsync_count, 1); UT_ASSERT_EQ(slot_pread_count, 2); @@ -645,8 +636,7 @@ UT_TEST(test_a1_borrow_verified_cf_does_not_reenter_or_unlock) fixture_reset(); stub_cf_held = true; - UT_ASSERT_EQ((int)cluster_wal_state_update_own( - &update, CLUSTER_WAL_STATE_CF_BORROW_X, NULL), + UT_ASSERT_EQ((int)cluster_wal_state_update_own(&update, CLUSTER_WAL_STATE_CF_BORROW_X, NULL), (int)CLUSTER_WAL_STATE_UPDATE_OK); UT_ASSERT_EQ(stub_cf_lock_count, 0); UT_ASSERT_EQ(stub_cf_unlock_count, 0); @@ -655,8 +645,7 @@ UT_TEST(test_a1_borrow_verified_cf_does_not_reenter_or_unlock) fixture_reset(); stub_cf_held = false; - UT_ASSERT_EQ((int)cluster_wal_state_update_own( - &update, CLUSTER_WAL_STATE_CF_BORROW_X, NULL), + UT_ASSERT_EQ((int)cluster_wal_state_update_own(&update, CLUSTER_WAL_STATE_CF_BORROW_X, NULL), (int)CLUSTER_WAL_STATE_UPDATE_CF_UNAVAILABLE); assert_no_registry_io(); UT_ASSERT_EQ(stub_cf_lock_count, 0); @@ -671,8 +660,7 @@ UT_TEST(test_a1_fresh_header_slot_typed_rejections) fixture_reset(); virtual_file_size--; - UT_ASSERT_EQ((int)cluster_wal_state_update_own( - &update, CLUSTER_WAL_STATE_CF_ACQUIRE_X, NULL), + UT_ASSERT_EQ((int)cluster_wal_state_update_own(&update, CLUSTER_WAL_STATE_CF_ACQUIRE_X, NULL), (int)CLUSTER_WAL_STATE_UPDATE_CORRUPT); UT_ASSERT_EQ(pwrite_count, 0); UT_ASSERT_EQ(fsync_count, 0); @@ -681,8 +669,7 @@ UT_TEST(test_a1_fresh_header_slot_typed_rejections) fixture_reset(); header = (ClusterWalStateHeader *)virtual_file; header->crc ^= 1; - UT_ASSERT_EQ((int)cluster_wal_state_update_own( - &update, CLUSTER_WAL_STATE_CF_ACQUIRE_X, NULL), + UT_ASSERT_EQ((int)cluster_wal_state_update_own(&update, CLUSTER_WAL_STATE_CF_ACQUIRE_X, NULL), (int)CLUSTER_WAL_STATE_UPDATE_CORRUPT); UT_ASSERT_EQ(pwrite_count, 0); UT_ASSERT_EQ(fsync_count, 0); @@ -691,8 +678,7 @@ UT_TEST(test_a1_fresh_header_slot_typed_rejections) fixture_reset(); slot = (ClusterWalStateSlot *)(virtual_file + CLUSTER_WAL_STATE_SLOT_OFFSET(4)); memset(slot, 0, sizeof(*slot)); - UT_ASSERT_EQ((int)cluster_wal_state_update_own( - &update, CLUSTER_WAL_STATE_CF_ACQUIRE_X, NULL), + UT_ASSERT_EQ((int)cluster_wal_state_update_own(&update, CLUSTER_WAL_STATE_CF_ACQUIRE_X, NULL), (int)CLUSTER_WAL_STATE_UPDATE_EMPTY); UT_ASSERT_EQ(pwrite_count, 0); UT_ASSERT_EQ(fsync_count, 0); @@ -701,8 +687,7 @@ UT_TEST(test_a1_fresh_header_slot_typed_rejections) fixture_reset(); slot = (ClusterWalStateSlot *)(virtual_file + CLUSTER_WAL_STATE_SLOT_OFFSET(4)); slot->crc ^= 1; - UT_ASSERT_EQ((int)cluster_wal_state_update_own( - &update, CLUSTER_WAL_STATE_CF_ACQUIRE_X, NULL), + UT_ASSERT_EQ((int)cluster_wal_state_update_own(&update, CLUSTER_WAL_STATE_CF_ACQUIRE_X, NULL), (int)CLUSTER_WAL_STATE_UPDATE_CORRUPT); UT_ASSERT_EQ(pwrite_count, 0); UT_ASSERT_EQ(fsync_count, 0); @@ -712,8 +697,7 @@ UT_TEST(test_a1_fresh_header_slot_typed_rejections) slot = (ClusterWalStateSlot *)(virtual_file + CLUSTER_WAL_STATE_SLOT_OFFSET(4)); slot->node_id = 9; slot->crc = cluster_wal_state_block_crc(slot); - UT_ASSERT_EQ((int)cluster_wal_state_update_own( - &update, CLUSTER_WAL_STATE_CF_ACQUIRE_X, NULL), + UT_ASSERT_EQ((int)cluster_wal_state_update_own(&update, CLUSTER_WAL_STATE_CF_ACQUIRE_X, NULL), (int)CLUSTER_WAL_STATE_UPDATE_FOREIGN); UT_ASSERT_EQ(pwrite_count, 0); UT_ASSERT_EQ(fsync_count, 0); @@ -723,8 +707,7 @@ UT_TEST(test_a1_fresh_header_slot_typed_rejections) slot = (ClusterWalStateSlot *)(virtual_file + CLUSTER_WAL_STATE_SLOT_OFFSET(4)); slot->state = CLUSTER_WAL_SLOT_STATE_STOPPED; slot->crc = cluster_wal_state_block_crc(slot); - UT_ASSERT_EQ((int)cluster_wal_state_update_own( - &update, CLUSTER_WAL_STATE_CF_ACQUIRE_X, NULL), + UT_ASSERT_EQ((int)cluster_wal_state_update_own(&update, CLUSTER_WAL_STATE_CF_ACQUIRE_X, NULL), (int)CLUSTER_WAL_STATE_UPDATE_WRONG_STATE); UT_ASSERT_EQ(pwrite_count, 0); UT_ASSERT_EQ(fsync_count, 0); @@ -795,9 +778,10 @@ UT_TEST(test_a1_w3_publish_stopped_uses_verified_cf_rmw) { ClusterWalStateSlot before; ClusterWalStateSlot *ondisk; - RmwEvent expected_events[] = {RMW_EVENT_CF_LOCK, RMW_EVENT_OPEN, RMW_EVENT_FSTAT, - RMW_EVENT_PREAD_HEADER, RMW_EVENT_PREAD_SLOT, RMW_EVENT_PWRITE_SLOT, RMW_EVENT_FSYNC, - RMW_EVENT_PREAD_SLOT, RMW_EVENT_CLOSE, RMW_EVENT_CF_UNLOCK}; + RmwEvent expected_events[] + = { RMW_EVENT_CF_LOCK, RMW_EVENT_OPEN, RMW_EVENT_FSTAT, RMW_EVENT_PREAD_HEADER, + RMW_EVENT_PREAD_SLOT, RMW_EVENT_PWRITE_SLOT, RMW_EVENT_FSYNC, RMW_EVENT_PREAD_SLOT, + RMW_EVENT_CLOSE, RMW_EVENT_CF_UNLOCK }; size_t i; fixture_reset(); @@ -879,8 +863,7 @@ cluster_r4_bit22_source_writer_enter(void) void cluster_r4_bit22_source_writer_leave(void) -{ -} +{} bool cluster_r4_bit22_source_close_begin(uint64 transition_epoch pg_attribute_unused(), @@ -902,9 +885,7 @@ main(int argc pg_attribute_unused(), char **argv pg_attribute_unused()) UT_PLAN(13); - - -UT_RUN(test_a1_verified_cf_gate_rejects_before_io); + UT_RUN(test_a1_verified_cf_gate_rejects_before_io); UT_RUN(test_a1_acquire_fresh_rmw_exact_order_and_distinct_postread); UT_RUN(test_a1_release_uncertain_fails_closed); UT_RUN(test_a1_short_write_and_fsync_fail_without_compensation); diff --git a/src/test/cluster_unit/test_cluster_write_fence.c b/src/test/cluster_unit/test_cluster_write_fence.c index 0d928322241..2c3939233e6 100644 --- a/src/test/cluster_unit/test_cluster_write_fence.c +++ b/src/test/cluster_unit/test_cluster_write_fence.c @@ -489,35 +489,29 @@ UT_TEST(test_baseline_author_rejects_same_order_durable_conflict) memset(dead, 0, sizeof(dead)); durable = mk_marker(4, 0, 0x44, 1, 0x01); cluster_fence_marker_build_baseline(&baseline, 4, dead, 0, 0, - CLUSTER_FENCE_BASELINE_INITIAL_ISSUER); + CLUSTER_FENCE_BASELINE_INITIAL_ISSUER); /* A restarting lowest-live node has not applied the survivor's current * membership yet. It must not overwrite its self slot with a same-order, * different tuple: the direct durable reader correctly treats those two * identities as corruption. */ - UT_ASSERT(!cluster_fence_baseline_author_permitted_v1( - &baseline, true, &durable)); + UT_ASSERT(!cluster_fence_baseline_author_permitted_v1(&baseline, true, &durable)); baseline = durable; baseline.marker_kind = CLUSTER_FENCE_MARKER_KIND_BASELINE; - UT_ASSERT(cluster_fence_baseline_author_permitted_v1( - &baseline, true, &durable)); + UT_ASSERT(cluster_fence_baseline_author_permitted_v1(&baseline, true, &durable)); baseline.fence_epoch = 3; - UT_ASSERT(!cluster_fence_baseline_author_permitted_v1( - &baseline, true, &durable)); + UT_ASSERT(!cluster_fence_baseline_author_permitted_v1(&baseline, true, &durable)); baseline = durable; baseline.fence_epoch = 5; - UT_ASSERT(cluster_fence_baseline_author_permitted_v1( - &baseline, true, &durable)); + UT_ASSERT(cluster_fence_baseline_author_permitted_v1(&baseline, true, &durable)); cluster_fence_marker_build_baseline(&baseline, 5, dead, 0, 0, - CLUSTER_FENCE_BASELINE_INITIAL_ISSUER); - UT_ASSERT(!cluster_fence_baseline_author_permitted_v1( - &baseline, true, &durable)); - UT_ASSERT(cluster_fence_baseline_author_permitted_v1( - &baseline, false, NULL)); + CLUSTER_FENCE_BASELINE_INITIAL_ISSUER); + UT_ASSERT(!cluster_fence_baseline_author_permitted_v1(&baseline, true, &durable)); + UT_ASSERT(cluster_fence_baseline_author_permitted_v1(&baseline, false, NULL)); } UT_TEST(test_baseline_pristine_issuer_is_sentinel_and_uniform) @@ -719,18 +713,18 @@ UT_TEST(test_stop02_cache_exact_match_stale_and_expired) uint64 published = UINT64_C(10000000); uint64 expiry = published + CLUSTER_FENCE_AUTHORITY_CACHE_MAX_AGE_US; - UT_ASSERT_EQ(cluster_fence_authority_cache_decide_v1( - &expected, 2, 2, true, &observed, published, expiry, published), + UT_ASSERT_EQ(cluster_fence_authority_cache_decide_v1(&expected, 2, 2, true, &observed, + published, expiry, published), CLUSTER_FENCE_CACHE_MATCH); - UT_ASSERT_EQ(cluster_fence_authority_cache_decide_v1( - &expected, 2, 2, true, &observed, published, expiry, published - 1), + UT_ASSERT_EQ(cluster_fence_authority_cache_decide_v1(&expected, 2, 2, true, &observed, + published, expiry, published - 1), CLUSTER_FENCE_CACHE_STALE); - UT_ASSERT_EQ(cluster_fence_authority_cache_decide_v1( - &expected, 2, 2, true, &observed, published, expiry, expiry), + UT_ASSERT_EQ(cluster_fence_authority_cache_decide_v1(&expected, 2, 2, true, &observed, + published, expiry, expiry), CLUSTER_FENCE_CACHE_EXPIRED); observed.fence_event_id++; - UT_ASSERT_EQ(cluster_fence_authority_cache_decide_v1( - &expected, 2, 2, true, &observed, published, expiry, published), + UT_ASSERT_EQ(cluster_fence_authority_cache_decide_v1(&expected, 2, 2, true, &observed, + published, expiry, published), CLUSTER_FENCE_CACHE_STALE); } @@ -740,17 +734,17 @@ UT_TEST(test_stop02_cache_invalid_and_torn_are_distinct) uint64 published = UINT64_C(10000000); uint64 expiry = published + CLUSTER_FENCE_AUTHORITY_CACHE_MAX_AGE_US; - UT_ASSERT_EQ(cluster_fence_authority_cache_decide_v1( - &expected, 0, 0, false, &expected, 0, 0, published), - CLUSTER_FENCE_CACHE_INVALID); - UT_ASSERT_EQ(cluster_fence_authority_cache_decide_v1( - &expected, 3, 4, true, &expected, published, expiry, published), + UT_ASSERT_EQ( + cluster_fence_authority_cache_decide_v1(&expected, 0, 0, false, &expected, 0, 0, published), + CLUSTER_FENCE_CACHE_INVALID); + UT_ASSERT_EQ(cluster_fence_authority_cache_decide_v1(&expected, 3, 4, true, &expected, + published, expiry, published), CLUSTER_FENCE_CACHE_UNAVAILABLE); - UT_ASSERT_EQ(cluster_fence_authority_cache_decide_v1( - &expected, 4, 6, true, &expected, published, expiry, published), + UT_ASSERT_EQ(cluster_fence_authority_cache_decide_v1(&expected, 4, 6, true, &expected, + published, expiry, published), CLUSTER_FENCE_CACHE_UNAVAILABLE); - UT_ASSERT_EQ(cluster_fence_authority_cache_decide_v1( - &expected, 4, 4, false, &expected, published, expiry, published), + UT_ASSERT_EQ(cluster_fence_authority_cache_decide_v1(&expected, 4, 4, false, &expected, + published, expiry, published), CLUSTER_FENCE_CACHE_INVALID); } @@ -760,14 +754,14 @@ UT_TEST(test_stop02_cache_rejects_bad_expiry_and_semantic_kind_mismatch) ClusterFenceMarker observed = expected; uint64 published = UINT64_MAX - 10; - UT_ASSERT_EQ(cluster_fence_authority_cache_decide_v1( - &expected, 2, 2, true, &observed, published, UINT64_MAX, published), + UT_ASSERT_EQ(cluster_fence_authority_cache_decide_v1(&expected, 2, 2, true, &observed, + published, UINT64_MAX, published), CLUSTER_FENCE_CACHE_INVALID); published = UINT64_C(10000000); observed.marker_kind = CLUSTER_FENCE_MARKER_KIND_BASELINE; UT_ASSERT_EQ(cluster_fence_authority_cache_decide_v1( - &expected, 2, 2, true, &observed, published, - published + CLUSTER_FENCE_AUTHORITY_CACHE_MAX_AGE_US, published), + &expected, 2, 2, true, &observed, published, + published + CLUSTER_FENCE_AUTHORITY_CACHE_MAX_AGE_US, published), CLUSTER_FENCE_CACHE_STALE); } diff --git a/src/test/cluster_unit/test_cluster_write_fence_cache.c b/src/test/cluster_unit/test_cluster_write_fence_cache.c index b8dd1eaf2e3..6f57380d475 100644 --- a/src/test/cluster_unit/test_cluster_write_fence_cache.c +++ b/src/test/cluster_unit/test_cluster_write_fence_cache.c @@ -193,7 +193,12 @@ errcode(int sqlerrcode) captured_code = sqlerrcode; return 0; } -int errmsg(const char *fmt, ...) { (void)fmt; return 0; } +int +errmsg(const char *fmt, ...) +{ + (void)fmt; + return 0; +} int errmsg_internal(const char *fmt, ...) { @@ -209,7 +214,12 @@ errdetail(const char *fmt, ...) va_end(args); return 0; } -int errhint(const char *fmt, ...) { (void)fmt; return 0; } +int +errhint(const char *fmt, ...) +{ + (void)fmt; + return 0; +} static ClusterFenceMarker cache_marker(uint64 event_id) @@ -278,8 +288,8 @@ publisher_main(void *arg) ClusterFenceMarker *marker = (ClusterFenceMarker *)arg; uint64 expected_sequence = cluster_write_fence_authority_cache_sequence(); - (void)cluster_write_fence_authority_cache_publish_if_unchanged( - marker, UINT64_C(1000000), expected_sequence); + (void)cluster_write_fence_authority_cache_publish_if_unchanged(marker, UINT64_C(1000000), + expected_sequence); return NULL; } @@ -304,8 +314,8 @@ UT_TEST(test_cache_publish_revalidate_and_invalidate) attach_cache(); expected_sequence = cluster_write_fence_authority_cache_sequence(); - UT_ASSERT(cluster_write_fence_authority_cache_publish_if_unchanged( - &marker, UINT64_C(1000000), expected_sequence)); + UT_ASSERT(cluster_write_fence_authority_cache_publish_if_unchanged(&marker, UINT64_C(1000000), + expected_sequence)); UT_ASSERT_EQ(cluster_write_fence_revalidate_cached_nowait(&marker, UINT64_C(1000000)), CLUSTER_FENCE_CACHE_MATCH); cluster_write_fence_authority_cache_invalidate(); @@ -321,8 +331,8 @@ UT_TEST(test_invalidation_rejects_late_prechange_proof) attach_cache(); prechange_sequence = cluster_write_fence_authority_cache_sequence(); cluster_write_fence_authority_cache_invalidate(); - UT_ASSERT(!cluster_write_fence_authority_cache_publish_if_unchanged( - &marker, UINT64_C(1000000), prechange_sequence)); + UT_ASSERT(!cluster_write_fence_authority_cache_publish_if_unchanged(&marker, UINT64_C(1000000), + prechange_sequence)); UT_ASSERT_EQ(cluster_write_fence_revalidate_cached_nowait(&marker, UINT64_C(1000000)), CLUSTER_FENCE_CACHE_INVALID); } @@ -335,8 +345,8 @@ UT_TEST(test_mutation_guard_keeps_cache_unavailable_until_change_finishes) attach_cache(); expected_sequence = cluster_write_fence_authority_cache_sequence(); - UT_ASSERT(cluster_write_fence_authority_cache_publish_if_unchanged( - &marker, UINT64_C(1000000), expected_sequence)); + UT_ASSERT(cluster_write_fence_authority_cache_publish_if_unchanged(&marker, UINT64_C(1000000), + expected_sequence)); odd_sequence = cluster_write_fence_authority_cache_mutation_begin(); UT_ASSERT(odd_sequence != 0); UT_ASSERT_EQ(cluster_write_fence_revalidate_cached_nowait(&marker, UINT64_C(1000000)), @@ -392,8 +402,8 @@ UT_TEST(test_membership_mutation_invalidates_cache_before_change) attach_cache(); cluster_membership_attach(NULL); expected_sequence = cluster_write_fence_authority_cache_sequence(); - UT_ASSERT(cluster_write_fence_authority_cache_publish_if_unchanged( - &marker, UINT64_C(1000000), expected_sequence)); + UT_ASSERT(cluster_write_fence_authority_cache_publish_if_unchanged(&marker, UINT64_C(1000000), + expected_sequence)); UT_ASSERT_EQ(cluster_write_fence_revalidate_cached_nowait(&marker, UINT64_C(1000000)), CLUSTER_FENCE_CACHE_MATCH); cluster_membership_set_state(3, CLUSTER_MEMBER_DEAD); @@ -411,8 +421,8 @@ UT_TEST(test_epoch_mutation_invalidates_cache_before_change) attach_cache(); attach_epoch(); expected_sequence = cluster_write_fence_authority_cache_sequence(); - UT_ASSERT(cluster_write_fence_authority_cache_publish_if_unchanged( - &marker, UINT64_C(1000000), expected_sequence)); + UT_ASSERT(cluster_write_fence_authority_cache_publish_if_unchanged(&marker, UINT64_C(1000000), + expected_sequence)); cluster_epoch_advance_for_reconfig(&old_epoch, &new_epoch); UT_ASSERT_EQ(old_epoch, CLUSTER_EPOCH_INITIAL); UT_ASSERT_EQ(new_epoch, CLUSTER_EPOCH_INITIAL + 1); @@ -443,8 +453,7 @@ UT_TEST(test_external_fence_counters_are_exact_and_restart_empty) cluster_write_fence_note_external_mutation_gate_blocked(); cluster_write_fence_note_external_publish_gate_blocked(); UT_ASSERT_EQ(clock_gettime(CLOCK_MONOTONIC, &now), 0); - sample = (uint64) now.tv_sec * UINT64_C(1000000000) + - (uint64) now.tv_nsec; + sample = (uint64)now.tv_sec * UINT64_C(1000000000) + (uint64)now.tv_nsec; cluster_write_fence_note_external_write_excluded(41, sample); cluster_write_fence_note_external_write_excluded(40, sample - 1); diff --git a/src/test/cluster_unit/test_cluster_write_fence_durable.c b/src/test/cluster_unit/test_cluster_write_fence_durable.c index 65d7a67c324..c00b37c4811 100644 --- a/src/test/cluster_unit/test_cluster_write_fence_durable.c +++ b/src/test/cluster_unit/test_cluster_write_fence_durable.c @@ -46,8 +46,7 @@ static int mock_open_fd_count; static int cache_invalidation_count; static int owner_selector_total; -static void three_disk_config(char config[MAXPGPATH * 3 + 3], - char paths[3][MAXPGPATH]); +static void three_disk_config(char config[MAXPGPATH * 3 + 3], char paths[3][MAXPGPATH]); static void remove_three_disks(char paths[3][MAXPGPATH]); void @@ -94,8 +93,7 @@ cluster_voting_disk_read_slot(int fd, int expected_disk_index, uint32 node_id, out->node_id = node_id; out->incarnation = mock_owner_incarnations[expected_disk_index]; if (mock_slot_present[expected_disk_index][node_id]) - cluster_fence_marker_pack(out->_reserved1, - &mock_slots[expected_disk_index][node_id]); + cluster_fence_marker_pack(out->_reserved1, &mock_slots[expected_disk_index][node_id]); return CLUSTER_VOTING_DISK_IO_OK; } @@ -120,11 +118,11 @@ cluster_voting_disk_read_join_slot(int fd, uint32 node_id, void *out_slot512) } ClusterRecoveryOwnerImportResult -cluster_recovery_owner_import_select_v1( - int32 node_id, const ClusterWalThreadClaim *immutable_claim, - uint64 frozen_admitted_bitmap_low, uint64 frozen_admitted_bitmap_high, - const ClusterRecoveryOwnerDiskSampleV1 *samples, int total_disk_count, - uint64 *out_incarnation) +cluster_recovery_owner_import_select_v1(int32 node_id, const ClusterWalThreadClaim *immutable_claim, + uint64 frozen_admitted_bitmap_low, + uint64 frozen_admitted_bitmap_high, + const ClusterRecoveryOwnerDiskSampleV1 *samples, + int total_disk_count, uint64 *out_incarnation) { UT_ASSERT_EQ(node_id, 0); UT_ASSERT(immutable_claim != NULL); @@ -181,8 +179,8 @@ UT_TEST(test_owner_import_runtime_reads_every_distinct_disk) cluster_wal_thread_claim_fill(&claim, 1, 0, INT64_C(12345)); mock_join_slots[0].admitted_incarnation = 77; mock_owner_incarnations[1] = 70; - UT_ASSERT_EQ(cluster_recovery_owner_import_read_v1( - 0, &claim, 1, 0, &incarnation), CLUSTER_RECOVERY_OWNER_IMPORT_JCMK); + UT_ASSERT_EQ(cluster_recovery_owner_import_read_v1(0, &claim, 1, 0, &incarnation), + CLUSTER_RECOVERY_OWNER_IMPORT_JCMK); UT_ASSERT_EQ(owner_selector_total, 3); UT_ASSERT_EQ(incarnation, 77); remove_three_disks(paths); @@ -282,8 +280,7 @@ UT_TEST(test_durable_majority_and_total_counts) mock_slot_present[0][0] = true; mock_slot_present[1][0] = true; mock_slot_present[2][0] = true; - UT_ASSERT_EQ(cluster_write_fence_read_durable_authority(&proof), - CLUSTER_FENCE_AUTHORITY_OK); + UT_ASSERT_EQ(cluster_write_fence_read_durable_authority(&proof), CLUSTER_FENCE_AUTHORITY_OK); UT_ASSERT_EQ(proof.marker.fence_epoch, 8); UT_ASSERT_EQ(proof.agree_disk_count, 2); UT_ASSERT_EQ(proof.total_disk_count, 3); @@ -317,14 +314,12 @@ UT_TEST(test_join_baseline_majority_replaces_prior_failstop_tuple) mock_slot_present[0][0] = true; mock_slot_present[1][0] = true; mock_slot_present[2][0] = true; - UT_ASSERT_EQ(cluster_write_fence_read_durable_authority(&proof), - CLUSTER_FENCE_AUTHORITY_OK); + UT_ASSERT_EQ(cluster_write_fence_read_durable_authority(&proof), CLUSTER_FENCE_AUTHORITY_OK); UT_ASSERT_EQ(proof.marker.fence_epoch, UINT64_C(9)); UT_ASSERT_EQ(proof.marker.fence_generation, UINT64_C(9)); UT_ASSERT_EQ(proof.marker.fence_event_id, UINT64_C(0xBB)); UT_ASSERT_EQ(proof.marker.fenced_dead_bitmap[0], UINT8_C(0x04)); - UT_ASSERT_EQ((int)proof.marker.marker_kind, - (int)CLUSTER_FENCE_MARKER_KIND_BASELINE); + UT_ASSERT_EQ((int)proof.marker.marker_kind, (int)CLUSTER_FENCE_MARKER_KIND_BASELINE); UT_ASSERT_EQ(proof.agree_disk_count, 2); UT_ASSERT_EQ(proof.total_disk_count, 3); remove_three_disks(paths); @@ -343,8 +338,7 @@ UT_TEST(test_unreadable_disk_stays_in_denominator) mock_slot_present[0][0] = true; mock_slot_present[1][0] = true; (void)unlink(paths[2]); - UT_ASSERT_EQ(cluster_write_fence_read_durable_authority(&proof), - CLUSTER_FENCE_AUTHORITY_OK); + UT_ASSERT_EQ(cluster_write_fence_read_durable_authority(&proof), CLUSTER_FENCE_AUTHORITY_OK); UT_ASSERT_EQ(proof.total_disk_count, 3); mock_disk_read_failed[1] = true; diff --git a/src/test/cluster_unit/test_cluster_xid_stripe.c b/src/test/cluster_unit/test_cluster_xid_stripe.c index 04792ac4e79..26488ec459e 100644 --- a/src/test/cluster_unit/test_cluster_xid_stripe.c +++ b/src/test/cluster_unit/test_cluster_xid_stripe.c @@ -106,8 +106,7 @@ errmsg_internal(const char *fmt pg_attribute_unused(), ...) } void -errfinish(const char *filename pg_attribute_unused(), - int lineno pg_attribute_unused(), +errfinish(const char *filename pg_attribute_unused(), int lineno pg_attribute_unused(), const char *funcname pg_attribute_unused()) {} diff --git a/src/test/cluster_unit/test_cluster_xlog_insert_end.c b/src/test/cluster_unit/test_cluster_xlog_insert_end.c index c48ebaf7ced..999b0e113d3 100644 --- a/src/test/cluster_unit/test_cluster_xlog_insert_end.c +++ b/src/test/cluster_unit/test_cluster_xlog_insert_end.c @@ -52,16 +52,14 @@ extern void cluster_xlog_unit_set_insert_bytepos(uint64 bytepos); static uint64 usable_bytes_in_segment(void) { - return ((uint64)wal_segment_size / XLOG_BLCKSZ) * - (XLOG_BLCKSZ - SizeOfXLogShortPHD) - - (SizeOfXLogLongPHD - SizeOfXLogShortPHD); + return ((uint64)wal_segment_size / XLOG_BLCKSZ) * (XLOG_BLCKSZ - SizeOfXLogShortPHD) + - (SizeOfXLogLongPHD - SizeOfXLogShortPHD); } static uint64 second_internal_page_end_bytepos(void) { - return (XLOG_BLCKSZ - SizeOfXLogLongPHD) + - (XLOG_BLCKSZ - SizeOfXLogShortPHD); + return (XLOG_BLCKSZ - SizeOfXLogLongPHD) + (XLOG_BLCKSZ - SizeOfXLogShortPHD); } UT_TEST(test_internal_page_boundary_returns_record_end_not_next_start) @@ -83,8 +81,7 @@ UT_TEST(test_segment_boundary_returns_boundary_not_long_header_start) UT_ASSERT_NE(GetXLogInsertEndRecPtr(), boundary + SizeOfXLogLongPHD); } -typedef struct InsertEndRace -{ +typedef struct InsertEndRace { uint64 bytepos_a; uint64 bytepos_b; XLogRecPtr expected_a; @@ -139,8 +136,7 @@ UT_TEST(test_concurrent_reservation_sample_is_one_record_end) pg_atomic_write_u32(&race.start, 1); while (pg_atomic_read_u32(&race.published) == 0) ; - while (pg_atomic_read_u32(&race.stop) == 0) - { + while (pg_atomic_read_u32(&race.stop) == 0) { XLogRecPtr sample = GetXLogInsertEndRecPtr(); samples++; @@ -171,8 +167,7 @@ read_bufmgr_source(void) UT_ASSERT_EQ(fseek(file, 0, SEEK_SET), 0); source = malloc((size_t)length + 1); UT_ASSERT_NOT_NULL(source); - if (source == NULL) - { + if (source == NULL) { fclose(file); return NULL; } @@ -194,8 +189,7 @@ UT_TEST(test_ship_flush_ceiling_uses_record_end_accessor) UT_ASSERT_NOT_NULL(begin); end = begin != NULL ? strstr(begin, "\n}\n") : NULL; UT_ASSERT_NOT_NULL(end); - if (begin != NULL && end != NULL) - { + if (begin != NULL && end != NULL) { const char *record_end = strstr(begin, "GetXLogInsertEndRecPtr()"); const char *next_start = strstr(begin, "GetXLogInsertRecPtr()"); diff --git a/src/test/cluster_unit/test_pgrac_external_fence_protocol.c b/src/test/cluster_unit/test_pgrac_external_fence_protocol.c index bfccdda9146..dd7daca0823 100644 --- a/src/test/cluster_unit/test_pgrac_external_fence_protocol.c +++ b/src/test/cluster_unit/test_pgrac_external_fence_protocol.c @@ -32,134 +32,82 @@ pfree(void *pointer) } void -ExceptionalCondition(const char *condition_name, const char *file_name, - int line_number) +ExceptionalCondition(const char *condition_name, const char *file_name, int line_number) { - printf("# Assert failed: %s at %s:%d\n", condition_name, file_name, - line_number); + printf("# Assert failed: %s at %s:%d\n", condition_name, file_name, line_number); abort(); } -static const uint8 pfrq_golden[PGRAC_EXTERNAL_FENCE_REQUEST_V1_BYTES] = { - 0x50, 0x46, 0x52, 0x51, 0x01, 0x00, 0x01, 0x00, - 0xa0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, - 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, - 0xef, 0xcd, 0xab, 0x89, 0x67, 0x45, 0x23, 0x01, - 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, - 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, - 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, - 0xd6, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, - 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe, - 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, - 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, - 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, - 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, - 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, - 0xc0, 0x27, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0xb0, 0x4f, 0x1d, 0xa4 -}; +static const uint8 pfrq_golden[PGRAC_EXTERNAL_FENCE_REQUEST_V1_BYTES] + = { 0x50, 0x46, 0x52, 0x51, 0x01, 0x00, 0x01, 0x00, 0xa0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, + 0x0f, 0x10, 0xef, 0xcd, 0xab, 0x89, 0x67, 0x45, 0x23, 0x01, 0x20, 0x21, 0x22, 0x23, 0x24, + 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, + 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0xd6, 0xff, 0xff, + 0xff, 0x00, 0x00, 0x00, 0x00, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe, 0x80, 0x81, + 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, 0x90, + 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, + 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0xc0, 0x27, 0x09, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb0, 0x4f, 0x1d, 0xa4 }; static const uint8 pfrs_golden[PGRAC_EXTERNAL_FENCE_RESPONSE_V1_BYTES] = { - 0x50, 0x46, 0x52, 0x53, 0x01, 0x00, 0x02, 0x00, - 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, - 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, - 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, - 0xef, 0xcd, 0xab, 0x89, 0x67, 0x45, 0x23, 0x01, - 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, - 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, - 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, - 0xd6, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, - 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe, - 0x88, 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11, - 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, - 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, - 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, - 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, - 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, - 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, - 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, - 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, - 0x18, 0x17, 0x16, 0x15, 0x14, 0x13, 0x12, 0x11, - 0x18, 0x13, 0x0b, 0x3f, 0x15, 0x13, 0x12, 0x11, - 0x28, 0x27, 0x26, 0x25, 0x24, 0x23, 0x22, 0x21, - 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, - 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, - 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, - 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, - 0xf9, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x50, 0x46, 0x52, 0x45, 0x98, 0xa8, 0xdd, 0xc3 + 0x50, 0x46, 0x52, 0x53, 0x01, 0x00, 0x02, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, + 0xef, 0xcd, 0xab, 0x89, 0x67, 0x45, 0x23, 0x01, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, + 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, + 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0xd6, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, + 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe, 0x88, 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11, + 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, + 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, + 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, + 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, + 0x18, 0x17, 0x16, 0x15, 0x14, 0x13, 0x12, 0x11, 0x18, 0x13, 0x0b, 0x3f, 0x15, 0x13, 0x12, 0x11, + 0x28, 0x27, 0x26, 0x25, 0x24, 0x23, 0x22, 0x21, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, + 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, + 0xf9, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x50, 0x46, 0x52, 0x45, 0x98, 0xa8, 0xdd, 0xc3 }; static const uint8 pfrj_prepare_golden[PGRAC_EXTERNAL_FENCE_REJOIN_V1_BYTES] = { - 0x50, 0x46, 0x52, 0x4a, 0x01, 0x00, 0x01, 0x00, - 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, - 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xd6, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, - 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe, - 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, - 0xc0, 0x27, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x50, 0x46, 0x52, 0x5a, 0xf4, 0x5c, 0x94, 0x79 + 0x50, 0x46, 0x52, 0x4a, 0x01, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd6, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, + 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe, 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, + 0xc0, 0x27, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x50, 0x46, 0x52, 0x5a, 0xf4, 0x5c, 0x94, 0x79 }; -static const uint8 protected_set_digest_golden[32] = { - 0x2f, 0x1f, 0xff, 0xca, 0xee, 0x84, 0x6e, 0x21, - 0xb6, 0x81, 0x2a, 0xab, 0xb0, 0x8d, 0x20, 0xc8, - 0x95, 0xf3, 0xff, 0xbe, 0x1f, 0x2f, 0x7b, 0x1a, - 0xb9, 0x60, 0xd0, 0x65, 0xfe, 0x99, 0x9f, 0xc0 -}; +static const uint8 protected_set_digest_golden[32] + = { 0x2f, 0x1f, 0xff, 0xca, 0xee, 0x84, 0x6e, 0x21, 0xb6, 0x81, 0x2a, + 0xab, 0xb0, 0x8d, 0x20, 0xc8, 0x95, 0xf3, 0xff, 0xbe, 0x1f, 0x2f, + 0x7b, 0x1a, 0xb9, 0x60, 0xd0, 0x65, 0xfe, 0x99, 0x9f, 0xc0 }; -static const uint8 target_state_digest_golden[32] = { - 0x93, 0x15, 0xb3, 0x24, 0x80, 0x0b, 0xec, 0xa8, - 0x58, 0xb9, 0x12, 0x45, 0x4d, 0x0d, 0x60, 0x7a, - 0x34, 0xdb, 0x67, 0x0f, 0xcb, 0xa3, 0x21, 0xff, - 0x71, 0x92, 0xaa, 0xde, 0x71, 0xdd, 0xba, 0x54 -}; +static const uint8 target_state_digest_golden[32] + = { 0x93, 0x15, 0xb3, 0x24, 0x80, 0x0b, 0xec, 0xa8, 0x58, 0xb9, 0x12, + 0x45, 0x4d, 0x0d, 0x60, 0x7a, 0x34, 0xdb, 0x67, 0x0f, 0xcb, 0xa3, + 0x21, 0xff, 0x71, 0x92, 0xaa, 0xde, 0x71, 0xdd, 0xba, 0x54 }; -static const uint8 binding_digest_golden[32] = { - 0xef, 0x4e, 0xc3, 0x41, 0x1c, 0xee, 0x9a, 0x3c, - 0x73, 0x1d, 0x8f, 0x2e, 0x53, 0x4d, 0x4f, 0x58, - 0x89, 0x04, 0x46, 0x20, 0x4a, 0xea, 0xfe, 0x49, - 0x66, 0x19, 0x44, 0x0a, 0x67, 0x6e, 0x53, 0x65 -}; +static const uint8 binding_digest_golden[32] + = { 0xef, 0x4e, 0xc3, 0x41, 0x1c, 0xee, 0x9a, 0x3c, 0x73, 0x1d, 0x8f, + 0x2e, 0x53, 0x4d, 0x4f, 0x58, 0x89, 0x04, 0x46, 0x20, 0x4a, 0xea, + 0xfe, 0x49, 0x66, 0x19, 0x44, 0x0a, 0x67, 0x6e, 0x53, 0x65 }; -static const uint8 rejoin_binding_digest_golden[32] = { - 0xe0, 0x26, 0xaa, 0x2f, 0xb0, 0x55, 0x4e, 0xc0, - 0x6a, 0x05, 0xd6, 0xc3, 0x17, 0x55, 0x07, 0x8c, - 0xa5, 0x88, 0xe1, 0x51, 0x50, 0xc7, 0x33, 0xe6, - 0x11, 0x6d, 0x2d, 0x81, 0xfc, 0xfe, 0x9c, 0xef -}; +static const uint8 rejoin_binding_digest_golden[32] + = { 0xe0, 0x26, 0xaa, 0x2f, 0xb0, 0x55, 0x4e, 0xc0, 0x6a, 0x05, 0xd6, + 0xc3, 0x17, 0x55, 0x07, 0x8c, 0xa5, 0x88, 0xe1, 0x51, 0x50, 0xc7, + 0x33, 0xe6, 0x11, 0x6d, 0x2d, 0x81, 0xfc, 0xfe, 0x9c, 0xef }; static void fill_request(PgracExternalFenceProtocolRequestV1 *request) @@ -168,12 +116,11 @@ fill_request(PgracExternalFenceProtocolRequestV1 *request) memset(request, 0, sizeof(*request)); for (i = 0; i < 16; i++) - request->request_nonce[i] = (uint8) (i + 1); + request->request_nonce[i] = (uint8)(i + 1); request->need.system_identifier = UINT64_C(0x0123456789abcdef); - for (i = 0; i < 32; i++) - { - request->need.canonical_duty_digest[i] = (uint8) (0x20 + i); - request->need.protected_set_digest[i] = (uint8) (0x80 + i); + for (i = 0; i < 32; i++) { + request->need.canonical_duty_digest[i] = (uint8)(0x20 + i); + request->need.protected_set_digest[i] = (uint8)(0x80 + i); } request->need.victim_node_id = -42; request->need.victim_incarnation = UINT64_C(0xfedcba9876543210); @@ -189,17 +136,15 @@ fill_response(PgracExternalFenceProtocolResponseV1 *response) memset(response, 0, sizeof(*response)); response->verdict = 1; - for (i = 0; i < 16; i++) - { - response->request_nonce[i] = (uint8) (i + 1); - response->daemon_boot_id[i] = (uint8) (0xa0 + i); + for (i = 0; i < 16; i++) { + response->request_nonce[i] = (uint8)(i + 1); + response->daemon_boot_id[i] = (uint8)(0xa0 + i); } response->binding.system_identifier = UINT64_C(0x0123456789abcdef); - for (i = 0; i < 32; i++) - { - response->binding.canonical_duty_digest[i] = (uint8) (0x20 + i); - response->binding.protected_set_digest[i] = (uint8) (0x80 + i); - response->target_state_digest[i] = (uint8) (0xc0 + i); + for (i = 0; i < 32; i++) { + response->binding.canonical_duty_digest[i] = (uint8)(0x20 + i); + response->binding.protected_set_digest[i] = (uint8)(0x80 + i); + response->target_state_digest[i] = (uint8)(0xc0 + i); } response->binding.victim_node_id = -42; response->binding.victim_incarnation = UINT64_C(0xfedcba9876543210); @@ -225,7 +170,7 @@ fill_rejoin_prepare(PgracExternalFenceProtocolRejoinFrameV1 *frame) memset(frame, 0, sizeof(*frame)); frame->opcode = PGRAC_EXTERNAL_FENCE_REJOIN_ADMIN_PREPARE; for (i = 0; i < 16; i++) - frame->transport_nonce[i] = (uint8) (i + 1); + frame->transport_nonce[i] = (uint8)(i + 1); frame->old_node_id = -42; frame->old_incarnation = UINT64_C(0xfedcba9876543210); frame->candidate_incarnation = UINT64_C(0x0102030405060708); @@ -241,8 +186,7 @@ UT_TEST(test_pfrq_exact_golden_and_round_trip) fill_request(&input); UT_ASSERT(pgrac_external_fence_request_v1_encode(&input, frame)); UT_ASSERT(memcmp(frame, pfrq_golden, sizeof(frame)) == 0); - UT_ASSERT(pgrac_external_fence_request_v1_decode(frame, sizeof(frame), - &decoded)); + UT_ASSERT(pgrac_external_fence_request_v1_decode(frame, sizeof(frame), &decoded)); UT_ASSERT(memcmp(&decoded, &input, sizeof(input)) == 0); } @@ -253,18 +197,15 @@ UT_TEST(test_pfrq_rejects_bad_crc_reserved_and_nonce) memcpy(frame, pfrq_golden, sizeof(frame)); frame[40] ^= 0x01; - UT_ASSERT(!pgrac_external_fence_request_v1_decode(frame, sizeof(frame), - &decoded)); + UT_ASSERT(!pgrac_external_fence_request_v1_decode(frame, sizeof(frame), &decoded)); memcpy(frame, pfrq_golden, sizeof(frame)); frame[132] = 1; - UT_ASSERT(!pgrac_external_fence_request_v1_decode(frame, sizeof(frame), - &decoded)); + UT_ASSERT(!pgrac_external_fence_request_v1_decode(frame, sizeof(frame), &decoded)); memcpy(frame, pfrq_golden, sizeof(frame)); memset(frame + 16, 0, 16); - UT_ASSERT(!pgrac_external_fence_request_v1_decode(frame, sizeof(frame), - &decoded)); + UT_ASSERT(!pgrac_external_fence_request_v1_decode(frame, sizeof(frame), &decoded)); } UT_TEST(test_pfrq_rejects_wrong_length_version_and_type) @@ -272,23 +213,20 @@ UT_TEST(test_pfrq_rejects_wrong_length_version_and_type) PgracExternalFenceProtocolRequestV1 decoded; uint8 frame[PGRAC_EXTERNAL_FENCE_REQUEST_V1_BYTES]; - UT_ASSERT(!pgrac_external_fence_request_v1_decode(pfrq_golden, - sizeof(pfrq_golden) - 1, &decoded)); + UT_ASSERT( + !pgrac_external_fence_request_v1_decode(pfrq_golden, sizeof(pfrq_golden) - 1, &decoded)); memcpy(frame, pfrq_golden, sizeof(frame)); frame[4] = 2; - UT_ASSERT(!pgrac_external_fence_request_v1_decode(frame, sizeof(frame), - &decoded)); + UT_ASSERT(!pgrac_external_fence_request_v1_decode(frame, sizeof(frame), &decoded)); memcpy(frame, pfrq_golden, sizeof(frame)); frame[6] = 2; - UT_ASSERT(!pgrac_external_fence_request_v1_decode(frame, sizeof(frame), - &decoded)); + UT_ASSERT(!pgrac_external_fence_request_v1_decode(frame, sizeof(frame), &decoded)); memcpy(frame, pfrq_golden, sizeof(frame)); frame[8] = 0x9f; - UT_ASSERT(!pgrac_external_fence_request_v1_decode(frame, sizeof(frame), - &decoded)); + UT_ASSERT(!pgrac_external_fence_request_v1_decode(frame, sizeof(frame), &decoded)); } UT_TEST(test_pfrq_encoder_rejects_noncanonical_input) @@ -318,8 +256,7 @@ UT_TEST(test_pfrs_exact_golden_and_round_trip) fill_response(&input); UT_ASSERT(pgrac_external_fence_response_v1_encode(&input, frame)); UT_ASSERT(memcmp(frame, pfrs_golden, sizeof(frame)) == 0); - UT_ASSERT(pgrac_external_fence_response_v1_decode(frame, sizeof(frame), - &decoded)); + UT_ASSERT(pgrac_external_fence_response_v1_decode(frame, sizeof(frame), &decoded)); UT_ASSERT(memcmp(&decoded, &input, sizeof(input)) == 0); } @@ -330,18 +267,15 @@ UT_TEST(test_pfrs_rejects_crc_reserved_and_trailer_corruption) memcpy(frame, pfrs_golden, sizeof(frame)); frame[100] ^= 0x01; - UT_ASSERT(!pgrac_external_fence_response_v1_decode(frame, sizeof(frame), - &decoded)); + UT_ASSERT(!pgrac_external_fence_response_v1_decode(frame, sizeof(frame), &decoded)); memcpy(frame, pfrs_golden, sizeof(frame)); frame[232] = 1; - UT_ASSERT(!pgrac_external_fence_response_v1_decode(frame, sizeof(frame), - &decoded)); + UT_ASSERT(!pgrac_external_fence_response_v1_decode(frame, sizeof(frame), &decoded)); memcpy(frame, pfrs_golden, sizeof(frame)); frame[248] = 'X'; - UT_ASSERT(!pgrac_external_fence_response_v1_decode(frame, sizeof(frame), - &decoded)); + UT_ASSERT(!pgrac_external_fence_response_v1_decode(frame, sizeof(frame), &decoded)); } UT_TEST(test_pfrs_negative_preserves_diagnostic_boot_and_journal) @@ -353,10 +287,9 @@ UT_TEST(test_pfrs_negative_preserves_diagnostic_boot_and_journal) memset(&input, 0, sizeof(input)); input.verdict = 4; - for (i = 0; i < 16; i++) - { - input.request_nonce[i] = (uint8) (i + 1); - input.daemon_boot_id[i] = (uint8) (0xe0 + i); + for (i = 0; i < 16; i++) { + input.request_nonce[i] = (uint8)(i + 1); + input.daemon_boot_id[i] = (uint8)(0xe0 + i); } input.journal_seq = 9; input.provider_abi_version = 1; @@ -364,8 +297,7 @@ UT_TEST(test_pfrs_negative_preserves_diagnostic_boot_and_journal) input.provider_native_status = -9; input.deny_reason = 10; UT_ASSERT(pgrac_external_fence_response_v1_encode(&input, frame)); - UT_ASSERT(pgrac_external_fence_response_v1_decode(frame, sizeof(frame), - &decoded)); + UT_ASSERT(pgrac_external_fence_response_v1_decode(frame, sizeof(frame), &decoded)); UT_ASSERT(memcmp(&decoded, &input, sizeof(input)) == 0); } @@ -378,8 +310,7 @@ UT_TEST(test_pfrj_prepare_exact_golden_and_round_trip) fill_rejoin_prepare(&input); UT_ASSERT(pgrac_external_fence_rejoin_v1_encode(&input, frame)); UT_ASSERT(memcmp(frame, pfrj_prepare_golden, sizeof(frame)) == 0); - UT_ASSERT(pgrac_external_fence_rejoin_v1_decode(frame, sizeof(frame), - &decoded)); + UT_ASSERT(pgrac_external_fence_rejoin_v1_decode(frame, sizeof(frame), &decoded)); UT_ASSERT(memcmp(&decoded, &input, sizeof(input)) == 0); } @@ -390,18 +321,15 @@ UT_TEST(test_pfrj_rejects_reserved_crc_and_unknown_opcode) memcpy(frame, pfrj_prepare_golden, sizeof(frame)); frame[124] = 1; - UT_ASSERT(!pgrac_external_fence_rejoin_v1_decode(frame, sizeof(frame), - &decoded)); + UT_ASSERT(!pgrac_external_fence_rejoin_v1_decode(frame, sizeof(frame), &decoded)); memcpy(frame, pfrj_prepare_golden, sizeof(frame)); frame[140] ^= 1; - UT_ASSERT(!pgrac_external_fence_rejoin_v1_decode(frame, sizeof(frame), - &decoded)); + UT_ASSERT(!pgrac_external_fence_rejoin_v1_decode(frame, sizeof(frame), &decoded)); memcpy(frame, pfrj_prepare_golden, sizeof(frame)); frame[6] = 10; - UT_ASSERT(!pgrac_external_fence_rejoin_v1_decode(frame, sizeof(frame), - &decoded)); + UT_ASSERT(!pgrac_external_fence_rejoin_v1_decode(frame, sizeof(frame), &decoded)); } UT_TEST(test_pfrj_enforces_opcode_specific_zero_and_proof_rules) @@ -433,8 +361,7 @@ UT_TEST(test_pfrj_enforces_opcode_specific_zero_and_proof_rules) memset(rejoin.transport_nonce, 0x74, sizeof(rejoin.transport_nonce)); memset(rejoin.operation_id, 0x75, sizeof(rejoin.operation_id)); rejoin.system_identifier = 9001; - memset(rejoin.protected_set_digest, 0x76, - sizeof(rejoin.protected_set_digest)); + memset(rejoin.protected_set_digest, 0x76, sizeof(rejoin.protected_set_digest)); rejoin.old_node_id = 3; rejoin.old_incarnation = 70; rejoin.candidate_incarnation = 77; @@ -446,8 +373,7 @@ UT_TEST(test_pfrj_enforces_opcode_specific_zero_and_proof_rules) rejoin.verified_mono_ns = 10; rejoin.fresh_until_mono_ns = 20; rejoin.proof_generation = 5; - memset(rejoin.target_state_digest, 0x78, - sizeof(rejoin.target_state_digest)); + memset(rejoin.target_state_digest, 0x78, sizeof(rejoin.target_state_digest)); rejoin.status = 1; UT_ASSERT(pgrac_external_fence_rejoin_v1_encode(&rejoin, frame)); rejoin.rejoin_gate_digest[0] = 1; @@ -461,11 +387,9 @@ UT_TEST(test_protected_set_digest_exact_domain) int i; for (i = 0; i < 16; i++) - storage_uuid[i] = (uint8) i; - UT_ASSERT(pgrac_external_fence_protected_set_digest_v1( - UINT32_C(3), storage_uuid, digest)); - UT_ASSERT(memcmp(digest, protected_set_digest_golden, - sizeof(digest)) == 0); + storage_uuid[i] = (uint8)i; + UT_ASSERT(pgrac_external_fence_protected_set_digest_v1(UINT32_C(3), storage_uuid, digest)); + UT_ASSERT(memcmp(digest, protected_set_digest_golden, sizeof(digest)) == 0); } UT_TEST(test_target_state_digest_exact_domain_and_closed_values) @@ -475,18 +399,13 @@ UT_TEST(test_target_state_digest_exact_domain_and_closed_values) int i; for (i = 0; i < 16; i++) - target_uuid[i] = (uint8) i; + target_uuid[i] = (uint8)i; UT_ASSERT(pgrac_external_fence_target_state_digest_v1( - target_uuid, 1, 1, UINT64_C(0x1122334455667788), - UINT64_C(0x2122232425262728), digest)); - UT_ASSERT(memcmp(digest, target_state_digest_golden, - sizeof(digest)) == 0); - UT_ASSERT(!pgrac_external_fence_target_state_digest_v1( - target_uuid, 3, 1, 1, 1, digest)); - UT_ASSERT(!pgrac_external_fence_target_state_digest_v1( - target_uuid, 1, 0, 1, 1, digest)); - UT_ASSERT(!pgrac_external_fence_target_state_digest_v1( - target_uuid, 1, 1, 0, 1, digest)); + target_uuid, 1, 1, UINT64_C(0x1122334455667788), UINT64_C(0x2122232425262728), digest)); + UT_ASSERT(memcmp(digest, target_state_digest_golden, sizeof(digest)) == 0); + UT_ASSERT(!pgrac_external_fence_target_state_digest_v1(target_uuid, 3, 1, 1, 1, digest)); + UT_ASSERT(!pgrac_external_fence_target_state_digest_v1(target_uuid, 1, 0, 1, 1, digest)); + UT_ASSERT(!pgrac_external_fence_target_state_digest_v1(target_uuid, 1, 1, 0, 1, digest)); } UT_TEST(test_binding_digest_exact_manual_encoding) @@ -495,8 +414,7 @@ UT_TEST(test_binding_digest_exact_manual_encoding) uint8 digest[32]; fill_response(&response); - UT_ASSERT(pgrac_external_fence_binding_digest_v1(&response.binding, - digest)); + UT_ASSERT(pgrac_external_fence_binding_digest_v1(&response.binding, digest)); UT_ASSERT(memcmp(digest, binding_digest_golden, sizeof(digest)) == 0); } @@ -508,10 +426,9 @@ UT_TEST(test_rejoin_binding_digest_exact_manual_encoding) memset(&binding, 0, sizeof(binding)); binding.system_identifier = UINT64_C(0x0123456789abcdef); - for (i = 0; i < 32; i++) - { - binding.rejoin_gate_digest[i] = (uint8) (0x40 + i); - binding.protected_set_digest[i] = (uint8) (0x80 + i); + for (i = 0; i < 32; i++) { + binding.rejoin_gate_digest[i] = (uint8)(0x40 + i); + binding.protected_set_digest[i] = (uint8)(0x80 + i); } binding.old_node_id = -42; binding.old_incarnation = UINT64_C(0xfedcba9876543210); @@ -519,10 +436,8 @@ UT_TEST(test_rejoin_binding_digest_exact_manual_encoding) binding.target_mapping_generation = UINT64_C(0x1122334455667788); binding.predicate_id = 2; binding.predicate_version = 1; - UT_ASSERT(pgrac_external_fence_rejoin_binding_digest_v1(&binding, - digest)); - UT_ASSERT(memcmp(digest, rejoin_binding_digest_golden, - sizeof(digest)) == 0); + UT_ASSERT(pgrac_external_fence_rejoin_binding_digest_v1(&binding, digest)); + UT_ASSERT(memcmp(digest, rejoin_binding_digest_golden, sizeof(digest)) == 0); } UT_TEST(test_acquire_echo_binding_rejects_every_identity_mutation) @@ -540,50 +455,39 @@ UT_TEST(test_acquire_echo_binding_rejects_every_identity_mutation) UT_ASSERT(pgrac_external_fence_binding_from_request_v1( &request.need, response.binding.target_mapping_generation, &binding)); response.binding = binding; - UT_ASSERT(pgrac_external_fence_affirmative_response_matches_request_v1( - &request, &response)); + UT_ASSERT(pgrac_external_fence_affirmative_response_matches_request_v1(&request, &response)); changed = response; changed.request_nonce[0] ^= 1; - UT_ASSERT(!pgrac_external_fence_affirmative_response_matches_request_v1( - &request, &changed)); + UT_ASSERT(!pgrac_external_fence_affirmative_response_matches_request_v1(&request, &changed)); changed = response; changed.binding.system_identifier++; - UT_ASSERT(!pgrac_external_fence_affirmative_response_matches_request_v1( - &request, &changed)); + UT_ASSERT(!pgrac_external_fence_affirmative_response_matches_request_v1(&request, &changed)); changed = response; changed.binding.canonical_duty_digest[0] ^= 1; - UT_ASSERT(!pgrac_external_fence_affirmative_response_matches_request_v1( - &request, &changed)); + UT_ASSERT(!pgrac_external_fence_affirmative_response_matches_request_v1(&request, &changed)); changed = response; changed.binding.victim_node_id++; - UT_ASSERT(!pgrac_external_fence_affirmative_response_matches_request_v1( - &request, &changed)); + UT_ASSERT(!pgrac_external_fence_affirmative_response_matches_request_v1(&request, &changed)); changed = response; changed.binding.victim_incarnation++; - UT_ASSERT(!pgrac_external_fence_affirmative_response_matches_request_v1( - &request, &changed)); + UT_ASSERT(!pgrac_external_fence_affirmative_response_matches_request_v1(&request, &changed)); changed = response; changed.binding.target_mapping_generation = 0; - UT_ASSERT(!pgrac_external_fence_affirmative_response_matches_request_v1( - &request, &changed)); + UT_ASSERT(!pgrac_external_fence_affirmative_response_matches_request_v1(&request, &changed)); changed = response; changed.binding.protected_set_digest[0] ^= 1; - UT_ASSERT(!pgrac_external_fence_affirmative_response_matches_request_v1( - &request, &changed)); + UT_ASSERT(!pgrac_external_fence_affirmative_response_matches_request_v1(&request, &changed)); changed = response; changed.binding.predicate_id++; - UT_ASSERT(!pgrac_external_fence_affirmative_response_matches_request_v1( - &request, &changed)); + UT_ASSERT(!pgrac_external_fence_affirmative_response_matches_request_v1(&request, &changed)); changed = response; changed.binding.predicate_version++; - UT_ASSERT(!pgrac_external_fence_affirmative_response_matches_request_v1( - &request, &changed)); + UT_ASSERT(!pgrac_external_fence_affirmative_response_matches_request_v1(&request, &changed)); request.need.victim_node_id = -1; UT_ASSERT(!pgrac_external_fence_need_v1_valid(&request.need)); - UT_ASSERT(!pgrac_external_fence_binding_from_request_v1( - &request.need, 1, &binding)); + UT_ASSERT(!pgrac_external_fence_binding_from_request_v1(&request.need, 1, &binding)); } int diff --git a/src/test/cluster_unit/test_pgrac_fenced_async.c b/src/test/cluster_unit/test_pgrac_fenced_async.c index c1db93c6601..18f9c2f644f 100644 --- a/src/test/cluster_unit/test_pgrac_fenced_async.c +++ b/src/test/cluster_unit/test_pgrac_fenced_async.c @@ -28,8 +28,8 @@ UT_DEFINE_GLOBALS(); static volatile uint32 *actuation_entries; static PgracFencedProviderResult -test_resolve(const PgracFencedTargetV1 *configured, - PgracFencedTargetV1 *resolved, int32 *native_status) +test_resolve(const PgracFencedTargetV1 *configured, PgracFencedTargetV1 *resolved, + int32 *native_status) { *resolved = *configured; *native_status = 0; @@ -37,39 +37,36 @@ test_resolve(const PgracFencedTargetV1 *configured, } static PgracFencedProviderResult -concurrent_actuate(const PgracFencedTargetV1 *target, - uint64_t deadline_mono_ns, int32 *native_status) +concurrent_actuate(const PgracFencedTargetV1 *target, uint64_t deadline_mono_ns, + int32 *native_status) { - struct timespec pause = {0, 1000000}; + struct timespec pause = { 0, 1000000 }; uint32 loops = 0; - (void) target; - (void) deadline_mono_ns; + (void)target; + (void)deadline_mono_ns; *native_status = 0; - (void) __sync_add_and_fetch(actuation_entries, 1); + (void)__sync_add_and_fetch(actuation_entries, 1); while (*actuation_entries < 2 && loops++ < 500) - (void) nanosleep(&pause, NULL); - return *actuation_entries >= 2 ? PGRAC_FENCED_PROVIDER_OK : - PGRAC_FENCED_PROVIDER_UNKNOWN; + (void)nanosleep(&pause, NULL); + return *actuation_entries >= 2 ? PGRAC_FENCED_PROVIDER_OK : PGRAC_FENCED_PROVIDER_UNKNOWN; } static PgracFencedProviderResult -test_readback(const PgracFencedTargetV1 *target, - uint64_t deadline_mono_ns, PgracFencedReadbackV1 *out) +test_readback(const PgracFencedTargetV1 *target, uint64_t deadline_mono_ns, + PgracFencedReadbackV1 *out) { - (void) deadline_mono_ns; + (void)deadline_mono_ns; memset(out, 0, sizeof(*out)); out->state = PGRAC_FENCED_TARGET_OFF; out->io_drain_state = PGRAC_FENCED_IO_DRAIN_DRAINED; - memcpy(out->observed_target_uuid, target->target_uuid, - sizeof(out->observed_target_uuid)); + memcpy(out->observed_target_uuid, target->target_uuid, sizeof(out->observed_target_uuid)); return PGRAC_FENCED_PROVIDER_OK; } static void test_shutdown(void) -{ -} +{} static uint64_t deadline_after_ms(uint64_t milliseconds) @@ -77,15 +74,13 @@ deadline_after_ms(uint64_t milliseconds) struct timespec now; UT_ASSERT_EQ(clock_gettime(CLOCK_MONOTONIC, &now), 0); - return (uint64_t) now.tv_sec * UINT64_C(1000000000) + - (uint64_t) now.tv_nsec + milliseconds * UINT64_C(1000000); + return (uint64_t)now.tv_sec * UINT64_C(1000000000) + (uint64_t)now.tv_nsec + + milliseconds * UINT64_C(1000000); } static int -open_context(PgracFencedOperationContextV1 *context, - PgracFencedJournalScanState *journal_state, - PgracFencedConfigV1 *config, PgracFencedProviderOpsV1 *ops, - char path[64]) +open_context(PgracFencedOperationContextV1 *context, PgracFencedJournalScanState *journal_state, + PgracFencedConfigV1 *config, PgracFencedProviderOpsV1 *ops, char path[64]) { uint8 config_digest[32]; uint8 daemon_boot_id[16]; @@ -97,17 +92,15 @@ open_context(PgracFencedOperationContextV1 *context, config->system_identifier = 9001; config->storage_backend_id = 2; memset(config->storage_uuid, 0x31, sizeof(config->storage_uuid)); - config->allowed_db_uid = (uint64) geteuid(); - config->allowed_db_gid = (uint64) getegid(); + config->allowed_db_uid = (uint64)geteuid(); + config->allowed_db_gid = (uint64)getegid(); config->provider_id = PGRAC_FENCED_PROVIDER_ID_TEST_ONLY; config->provider_abi = PGRAC_FENCED_PROVIDER_ABI_V1; config->node_count = 2; config->nodes[3].present = true; - memset(config->nodes[3].target_uuid, 0x41, - sizeof(config->nodes[3].target_uuid)); + memset(config->nodes[3].target_uuid, 0x41, sizeof(config->nodes[3].target_uuid)); config->nodes[4].present = true; - memset(config->nodes[4].target_uuid, 0x42, - sizeof(config->nodes[4].target_uuid)); + memset(config->nodes[4].target_uuid, 0x42, sizeof(config->nodes[4].target_uuid)); memset(ops, 0, sizeof(*ops)); ops->abi_version = PGRAC_FENCED_PROVIDER_ABI_V1; ops->struct_size = sizeof(*ops); @@ -127,8 +120,8 @@ open_context(PgracFencedOperationContextV1 *context, return -1; UT_ASSERT_EQ(fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_APPEND), 0); pgrac_fenced_journal_scan_state_init(journal_state); - UT_ASSERT(pgrac_fenced_operation_context_init(context, config, ops, true, - config_digest, daemon_boot_id, fd, journal_state)); + UT_ASSERT(pgrac_fenced_operation_context_init(context, config, ops, true, config_digest, + daemon_boot_id, fd, journal_state)); return fd; } @@ -139,13 +132,12 @@ make_request(const PgracFencedConfigV1 *config, int32 node_id, uint8 nonce, memset(request, 0, sizeof(*request)); memset(request->request_nonce, nonce, sizeof(request->request_nonce)); request->need.system_identifier = config->system_identifier; - memset(request->need.canonical_duty_digest, (uint8) (nonce + 1), - sizeof(request->need.canonical_duty_digest)); + memset(request->need.canonical_duty_digest, (uint8)(nonce + 1), + sizeof(request->need.canonical_duty_digest)); request->need.victim_node_id = node_id; - request->need.victim_incarnation = (uint64) node_id + 20; + request->need.victim_incarnation = (uint64)node_id + 20; UT_ASSERT(pgrac_external_fence_protected_set_digest_v1( - config->storage_backend_id, config->storage_uuid, - request->need.protected_set_digest)); + config->storage_backend_id, config->storage_uuid, request->need.protected_set_digest)); request->need.predicate_id = 1; request->need.predicate_version = 1; request->timeout_ms = 2000; @@ -157,7 +149,7 @@ journal_record_count(int fd) struct stat st; UT_ASSERT_EQ(fstat(fd, &st), 0); - return (size_t) st.st_size / PGRAC_FENCED_JOURNAL_RECORD_BYTES; + return (size_t)st.st_size / PGRAC_FENCED_JOURNAL_RECORD_BYTES; } UT_TEST(test_two_targets_execute_concurrently_with_parent_serial_journal) @@ -184,28 +176,27 @@ UT_TEST(test_two_targets_execute_concurrently_with_parent_serial_journal) journal_fd = open_context(&context, &journal_state, &config, &ops, path); if (journal_fd < 0) return; - actuation_entries = mmap(NULL, sizeof(*actuation_entries), - PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0); + actuation_entries = mmap(NULL, sizeof(*actuation_entries), PROT_READ | PROT_WRITE, + MAP_SHARED | MAP_ANON, -1, 0); UT_ASSERT(actuation_entries != MAP_FAILED); if (actuation_entries == MAP_FAILED) return; *actuation_entries = 0; make_request(&config, 3, 0x51, &first_request); make_request(&config, 4, 0x61, &second_request); - UT_ASSERT_EQ(pgrac_fenced_operation_accept(&context, &first_request, - deadline_after_ms(2000), &first_prepared, &first_response), - PGRAC_FENCED_OPERATION_READY); - UT_ASSERT_EQ(pgrac_fenced_operation_accept(&context, &second_request, - deadline_after_ms(2000), &second_prepared, &second_response), - PGRAC_FENCED_OPERATION_READY); - UT_ASSERT(pgrac_fenced_async_start_preaccepted(&context, &first_request, - &first_prepared, deadline_after_ms(2000), &first)); - UT_ASSERT(pgrac_fenced_async_start_preaccepted(&context, &second_request, - &second_prepared, deadline_after_ms(2000), &second)); + UT_ASSERT_EQ(pgrac_fenced_operation_accept(&context, &first_request, deadline_after_ms(2000), + &first_prepared, &first_response), + PGRAC_FENCED_OPERATION_READY); + UT_ASSERT_EQ(pgrac_fenced_operation_accept(&context, &second_request, deadline_after_ms(2000), + &second_prepared, &second_response), + PGRAC_FENCED_OPERATION_READY); + UT_ASSERT(pgrac_fenced_async_start_preaccepted(&context, &first_request, &first_prepared, + deadline_after_ms(2000), &first)); + UT_ASSERT(pgrac_fenced_async_start_preaccepted(&context, &second_request, &second_prepared, + deadline_after_ms(2000), &second)); memset(&first_response, 0, sizeof(first_response)); memset(&second_response, 0, sizeof(second_response)); - while (completed < 2 && attempts++ < 100) - { + while (completed < 2 && attempts++ < 100) { descriptors[0].fd = pgrac_fenced_async_fd(&first); descriptors[0].events = descriptors[0].fd >= 0 ? POLLIN : 0; descriptors[0].revents = 0; @@ -213,10 +204,8 @@ UT_TEST(test_two_targets_execute_concurrently_with_parent_serial_journal) descriptors[1].events = descriptors[1].fd >= 0 ? POLLIN : 0; descriptors[1].revents = 0; UT_ASSERT(poll(descriptors, 2, 100) > 0); - if (descriptors[0].revents != 0) - { - bool ok = pgrac_fenced_async_service(&context, &first, &event, - &first_response); + if (descriptors[0].revents != 0) { + bool ok = pgrac_fenced_async_service(&context, &first, &event, &first_response); UT_ASSERT(ok); if (!ok) @@ -224,10 +213,8 @@ UT_TEST(test_two_targets_execute_concurrently_with_parent_serial_journal) if (event == PGRAC_FENCED_ASYNC_COMPLETE) completed++; } - if (descriptors[1].revents != 0) - { - bool ok = pgrac_fenced_async_service(&context, &second, &event, - &second_response); + if (descriptors[1].revents != 0) { + bool ok = pgrac_fenced_async_service(&context, &second, &event, &second_response); UT_ASSERT(ok); if (!ok) @@ -244,15 +231,13 @@ UT_TEST(test_two_targets_execute_concurrently_with_parent_serial_journal) UT_ASSERT_EQ(*actuation_entries, 2); UT_ASSERT_EQ(first_response.verdict, 1); UT_ASSERT_EQ(second_response.verdict, 1); - UT_ASSERT_NE(first_response.proof_generation, - second_response.proof_generation); + UT_ASSERT_NE(first_response.proof_generation, second_response.proof_generation); UT_ASSERT_EQ(journal_record_count(journal_fd), 11); UT_ASSERT_EQ(pgrac_fenced_async_fd(&first), -1); UT_ASSERT_EQ(pgrac_fenced_async_fd(&second), -1); - UT_ASSERT_EQ(munmap((void *) actuation_entries, - sizeof(*actuation_entries)), 0); - (void) close(journal_fd); - (void) unlink(path); + UT_ASSERT_EQ(munmap((void *)actuation_entries, sizeof(*actuation_entries)), 0); + (void)close(journal_fd); + (void)unlink(path); } int diff --git a/src/test/cluster_unit/test_pgrac_fenced_config.c b/src/test/cluster_unit/test_pgrac_fenced_config.c index 8f22628d7d4..860f4f78d06 100644 --- a/src/test/cluster_unit/test_pgrac_fenced_config.c +++ b/src/test/cluster_unit/test_pgrac_fenced_config.c @@ -19,26 +19,25 @@ UT_DEFINE_GLOBALS(); -static const char valid_config[] = - "format_version=1\n" - "mapping_generation=7\n" - "system_identifier=81985529216486895\n" - "storage_backend_id=3\n" - "storage_uuid=00112233445566778899aabbccddeeff\n" - "allowed_db_uid=501\n" - "allowed_db_gid=20\n" - "provider_id=0\n" - "provider_abi=1\n" - "node.0.target_uuid=ffeeddccbbaa99887766554433221100\n" - "node.0.adapter_data=\n"; +static const char valid_config[] = "format_version=1\n" + "mapping_generation=7\n" + "system_identifier=81985529216486895\n" + "storage_backend_id=3\n" + "storage_uuid=00112233445566778899aabbccddeeff\n" + "allowed_db_uid=501\n" + "allowed_db_gid=20\n" + "provider_id=0\n" + "provider_abi=1\n" + "node.0.target_uuid=ffeeddccbbaa99887766554433221100\n" + "node.0.adapter_data=\n"; UT_TEST(test_config_accepts_exact_canonical_provider_zero) { PgracFencedConfigV1 config; - UT_ASSERT_EQ(pgrac_fenced_config_parse_v1( - (const uint8 *) valid_config, sizeof(valid_config) - 1, &config), - PGRAC_FENCED_CONFIG_OK); + UT_ASSERT_EQ(pgrac_fenced_config_parse_v1((const uint8 *)valid_config, sizeof(valid_config) - 1, + &config), + PGRAC_FENCED_CONFIG_OK); UT_ASSERT_EQ(config.format_version, 1); UT_ASSERT_EQ(config.mapping_generation, 7); UT_ASSERT_EQ(config.system_identifier, UINT64_C(81985529216486895)); @@ -61,45 +60,42 @@ UT_TEST(test_config_rejects_noncanonical_numeric_and_hex) memcpy(changed, valid_config, sizeof(valid_config)); at = strstr(changed, "mapping_generation=7"); UT_ASSERT_NOT_NULL(at); - memmove(at + strlen("mapping_generation=") + 2, - at + strlen("mapping_generation=") + 1, - sizeof(valid_config) - - (at - changed + strlen("mapping_generation=") + 1)); + if (at == NULL) + return; + memmove(at + strlen("mapping_generation=") + 2, at + strlen("mapping_generation=") + 1, + sizeof(valid_config) - (at - changed + strlen("mapping_generation=") + 1)); at[strlen("mapping_generation=")] = '0'; - UT_ASSERT_NE(pgrac_fenced_config_parse_v1( - (const uint8 *) changed, sizeof(valid_config), &config), + UT_ASSERT_NE( + pgrac_fenced_config_parse_v1((const uint8 *)changed, sizeof(valid_config), &config), PGRAC_FENCED_CONFIG_OK); memcpy(changed, valid_config, sizeof(valid_config)); at = strstr(changed, "storage_uuid="); UT_ASSERT_NOT_NULL(at); + if (at == NULL) + return; at[strlen("storage_uuid=") + 20] = 'A'; - UT_ASSERT_NE(pgrac_fenced_config_parse_v1( - (const uint8 *) changed, sizeof(changed) - 1, &config), - PGRAC_FENCED_CONFIG_OK); + UT_ASSERT_NE(pgrac_fenced_config_parse_v1((const uint8 *)changed, sizeof(changed) - 1, &config), + PGRAC_FENCED_CONFIG_OK); } UT_TEST(test_config_rejects_reorder_unknown_blank_and_missing_lf) { PgracFencedConfigV1 config; - static const char reordered[] = - "mapping_generation=7\nformat_version=1\n"; - static const char unknown[] = - "format_version=1\nunknown=1\n"; + static const char reordered[] = "mapping_generation=7\nformat_version=1\n"; + static const char unknown[] = "format_version=1\nunknown=1\n"; static const char blank[] = "format_version=1\n\n"; - UT_ASSERT_NE(pgrac_fenced_config_parse_v1( - (const uint8 *) reordered, sizeof(reordered) - 1, &config), - PGRAC_FENCED_CONFIG_OK); - UT_ASSERT_NE(pgrac_fenced_config_parse_v1( - (const uint8 *) unknown, sizeof(unknown) - 1, &config), - PGRAC_FENCED_CONFIG_OK); - UT_ASSERT_NE(pgrac_fenced_config_parse_v1( - (const uint8 *) blank, sizeof(blank) - 1, &config), - PGRAC_FENCED_CONFIG_OK); - UT_ASSERT_NE(pgrac_fenced_config_parse_v1( - (const uint8 *) valid_config, sizeof(valid_config) - 2, &config), + UT_ASSERT_NE( + pgrac_fenced_config_parse_v1((const uint8 *)reordered, sizeof(reordered) - 1, &config), PGRAC_FENCED_CONFIG_OK); + UT_ASSERT_NE(pgrac_fenced_config_parse_v1((const uint8 *)unknown, sizeof(unknown) - 1, &config), + PGRAC_FENCED_CONFIG_OK); + UT_ASSERT_NE(pgrac_fenced_config_parse_v1((const uint8 *)blank, sizeof(blank) - 1, &config), + PGRAC_FENCED_CONFIG_OK); + UT_ASSERT_NE(pgrac_fenced_config_parse_v1((const uint8 *)valid_config, sizeof(valid_config) - 2, + &config), + PGRAC_FENCED_CONFIG_OK); } UT_TEST(test_config_rejects_mismatched_node_and_oversize) @@ -112,38 +108,37 @@ UT_TEST(test_config_rejects_mismatched_node_and_oversize) memcpy(changed, valid_config, sizeof(valid_config)); at = strstr(changed, "node.0.target_uuid"); UT_ASSERT_NOT_NULL(at); + if (at == NULL) + return; at[5] = '1'; - UT_ASSERT_NE(pgrac_fenced_config_parse_v1( - (const uint8 *) changed, sizeof(changed) - 1, &config), - PGRAC_FENCED_CONFIG_OK); + UT_ASSERT_NE(pgrac_fenced_config_parse_v1((const uint8 *)changed, sizeof(changed) - 1, &config), + PGRAC_FENCED_CONFIG_OK); memset(oversized, 'x', sizeof(oversized)); - UT_ASSERT_EQ(pgrac_fenced_config_parse_v1( - oversized, sizeof(oversized), &config), - PGRAC_FENCED_CONFIG_TOO_LARGE); + UT_ASSERT_EQ(pgrac_fenced_config_parse_v1(oversized, sizeof(oversized), &config), + PGRAC_FENCED_CONFIG_TOO_LARGE); } UT_TEST(test_config_rejects_duplicate_target_uuid) { PgracFencedConfigV1 config; - static const char duplicate_target[] = - "format_version=1\n" - "mapping_generation=7\n" - "system_identifier=81985529216486895\n" - "storage_backend_id=3\n" - "storage_uuid=00112233445566778899aabbccddeeff\n" - "allowed_db_uid=501\n" - "allowed_db_gid=20\n" - "provider_id=0\n" - "provider_abi=1\n" - "node.0.target_uuid=ffeeddccbbaa99887766554433221100\n" - "node.0.adapter_data=\n" - "node.1.target_uuid=ffeeddccbbaa99887766554433221100\n" - "node.1.adapter_data=\n"; - - UT_ASSERT_NE(pgrac_fenced_config_parse_v1( - (const uint8 *) duplicate_target, sizeof(duplicate_target) - 1, - &config), PGRAC_FENCED_CONFIG_OK); + static const char duplicate_target[] = "format_version=1\n" + "mapping_generation=7\n" + "system_identifier=81985529216486895\n" + "storage_backend_id=3\n" + "storage_uuid=00112233445566778899aabbccddeeff\n" + "allowed_db_uid=501\n" + "allowed_db_gid=20\n" + "provider_id=0\n" + "provider_abi=1\n" + "node.0.target_uuid=ffeeddccbbaa99887766554433221100\n" + "node.0.adapter_data=\n" + "node.1.target_uuid=ffeeddccbbaa99887766554433221100\n" + "node.1.adapter_data=\n"; + + UT_ASSERT_NE(pgrac_fenced_config_parse_v1((const uint8 *)duplicate_target, + sizeof(duplicate_target) - 1, &config), + PGRAC_FENCED_CONFIG_OK); } UT_TEST(test_config_file_metadata_is_exact_root_regular_0600) @@ -179,51 +174,54 @@ UT_TEST(test_mapping_reload_generation_rules) char changed[sizeof(valid_config)]; char *at; - UT_ASSERT_EQ(pgrac_fenced_config_parse_v1( - (const uint8 *) valid_config, sizeof(valid_config) - 1, ¤t), - PGRAC_FENCED_CONFIG_OK); - UT_ASSERT(pgrac_fenced_config_digest_v1( - (const uint8 *) valid_config, sizeof(valid_config) - 1, - current_digest)); - UT_ASSERT_EQ(pgrac_fenced_config_reload_decide_v1( - ¤t, current_digest, ¤t, current_digest), + UT_ASSERT_EQ(pgrac_fenced_config_parse_v1((const uint8 *)valid_config, sizeof(valid_config) - 1, + ¤t), + PGRAC_FENCED_CONFIG_OK); + UT_ASSERT(pgrac_fenced_config_digest_v1((const uint8 *)valid_config, sizeof(valid_config) - 1, + current_digest)); + UT_ASSERT_EQ( + pgrac_fenced_config_reload_decide_v1(¤t, current_digest, ¤t, current_digest), PGRAC_FENCED_CONFIG_RELOAD_UNCHANGED); memcpy(changed, valid_config, sizeof(changed)); at = strstr(changed, "node.0.target_uuid="); UT_ASSERT_NOT_NULL(at); + if (at == NULL) + return; at[strlen("node.0.target_uuid=")] = 'e'; - UT_ASSERT_EQ(pgrac_fenced_config_parse_v1( - (const uint8 *) changed, sizeof(changed) - 1, &candidate), + UT_ASSERT_EQ( + pgrac_fenced_config_parse_v1((const uint8 *)changed, sizeof(changed) - 1, &candidate), PGRAC_FENCED_CONFIG_OK); - UT_ASSERT(pgrac_fenced_config_digest_v1( - (const uint8 *) changed, sizeof(changed) - 1, candidate_digest)); - UT_ASSERT_EQ(pgrac_fenced_config_reload_decide_v1( - ¤t, current_digest, &candidate, candidate_digest), - PGRAC_FENCED_CONFIG_RELOAD_REJECT_SAME_GENERATION_CHANGE); + UT_ASSERT(pgrac_fenced_config_digest_v1((const uint8 *)changed, sizeof(changed) - 1, + candidate_digest)); + UT_ASSERT_EQ(pgrac_fenced_config_reload_decide_v1(¤t, current_digest, &candidate, + candidate_digest), + PGRAC_FENCED_CONFIG_RELOAD_REJECT_SAME_GENERATION_CHANGE); memcpy(changed, valid_config, sizeof(changed)); at = strstr(changed, "mapping_generation=7"); UT_ASSERT_NOT_NULL(at); + if (at == NULL) + return; at[strlen("mapping_generation=")] = '8'; - UT_ASSERT_EQ(pgrac_fenced_config_parse_v1( - (const uint8 *) changed, sizeof(changed) - 1, &candidate), + UT_ASSERT_EQ( + pgrac_fenced_config_parse_v1((const uint8 *)changed, sizeof(changed) - 1, &candidate), PGRAC_FENCED_CONFIG_OK); - UT_ASSERT(pgrac_fenced_config_digest_v1( - (const uint8 *) changed, sizeof(changed) - 1, candidate_digest)); - UT_ASSERT_EQ(pgrac_fenced_config_reload_decide_v1( - ¤t, current_digest, &candidate, candidate_digest), - PGRAC_FENCED_CONFIG_RELOAD_ADVANCE); + UT_ASSERT(pgrac_fenced_config_digest_v1((const uint8 *)changed, sizeof(changed) - 1, + candidate_digest)); + UT_ASSERT_EQ(pgrac_fenced_config_reload_decide_v1(¤t, current_digest, &candidate, + candidate_digest), + PGRAC_FENCED_CONFIG_RELOAD_ADVANCE); at[strlen("mapping_generation=")] = '6'; - UT_ASSERT_EQ(pgrac_fenced_config_parse_v1( - (const uint8 *) changed, sizeof(changed) - 1, &candidate), + UT_ASSERT_EQ( + pgrac_fenced_config_parse_v1((const uint8 *)changed, sizeof(changed) - 1, &candidate), PGRAC_FENCED_CONFIG_OK); - UT_ASSERT(pgrac_fenced_config_digest_v1( - (const uint8 *) changed, sizeof(changed) - 1, candidate_digest)); - UT_ASSERT_EQ(pgrac_fenced_config_reload_decide_v1( - ¤t, current_digest, &candidate, candidate_digest), - PGRAC_FENCED_CONFIG_RELOAD_REJECT_REGRESSION); + UT_ASSERT(pgrac_fenced_config_digest_v1((const uint8 *)changed, sizeof(changed) - 1, + candidate_digest)); + UT_ASSERT_EQ(pgrac_fenced_config_reload_decide_v1(¤t, current_digest, &candidate, + candidate_digest), + PGRAC_FENCED_CONFIG_RELOAD_REJECT_REGRESSION); } int diff --git a/src/test/cluster_unit/test_pgrac_fenced_coordinator.c b/src/test/cluster_unit/test_pgrac_fenced_coordinator.c index 1331bbf6da5..782cf0182b3 100644 --- a/src/test/cluster_unit/test_pgrac_fenced_coordinator.c +++ b/src/test/cluster_unit/test_pgrac_fenced_coordinator.c @@ -25,17 +25,18 @@ UT_DEFINE_GLOBALS(); -typedef struct SharedProviderState -{ +typedef struct SharedProviderState { volatile uint32 total_actions; volatile uint32 node_actions[PGRAC_FENCED_MAX_NODES]; + volatile uint32 hold_action; + volatile uint32 release_action; } SharedProviderState; static SharedProviderState *provider_state; static PgracFencedProviderResult -test_resolve(const PgracFencedTargetV1 *configured, - PgracFencedTargetV1 *resolved, int32 *native_status) +test_resolve(const PgracFencedTargetV1 *configured, PgracFencedTargetV1 *resolved, + int32 *native_status) { *resolved = *configured; *native_status = 0; @@ -43,42 +44,49 @@ test_resolve(const PgracFencedTargetV1 *configured, } static PgracFencedProviderResult -test_actuate(const PgracFencedTargetV1 *target, - uint64_t deadline_mono_ns, int32 *native_status) +test_actuate(const PgracFencedTargetV1 *target, uint64_t deadline_mono_ns, int32 *native_status) { - struct timespec pause = {0, 1000000}; + struct timespec pause = { 0, 1000000 }; uint32 action_number; uint32 loops = 0; - (void) deadline_mono_ns; *native_status = 0; action_number = __sync_add_and_fetch(&provider_state->total_actions, 1); - (void) __sync_add_and_fetch( - &provider_state->node_actions[target->victim_node_id], 1); - while (action_number <= 2 && provider_state->total_actions < 2 && - loops++ < 500) - (void) nanosleep(&pause, NULL); - return provider_state->total_actions >= 2 ? PGRAC_FENCED_PROVIDER_OK : - PGRAC_FENCED_PROVIDER_UNKNOWN; + (void)__sync_add_and_fetch(&provider_state->node_actions[target->victim_node_id], 1); + if (provider_state->hold_action) { + /* The reload test releases this exact action only after quiescing. */ + while (!provider_state->release_action) { + struct timespec now; + + if (clock_gettime(CLOCK_MONOTONIC, &now) != 0 + || (uint64_t)now.tv_sec * UINT64_C(1000000000) + (uint64_t)now.tv_nsec + >= deadline_mono_ns) + return PGRAC_FENCED_PROVIDER_UNKNOWN; + (void)nanosleep(&pause, NULL); + } + return PGRAC_FENCED_PROVIDER_OK; + } + while (action_number <= 2 && provider_state->total_actions < 2 && loops++ < 500) + (void)nanosleep(&pause, NULL); + return provider_state->total_actions >= 2 ? PGRAC_FENCED_PROVIDER_OK + : PGRAC_FENCED_PROVIDER_UNKNOWN; } static PgracFencedProviderResult -test_readback(const PgracFencedTargetV1 *target, - uint64_t deadline_mono_ns, PgracFencedReadbackV1 *out) +test_readback(const PgracFencedTargetV1 *target, uint64_t deadline_mono_ns, + PgracFencedReadbackV1 *out) { - (void) deadline_mono_ns; + (void)deadline_mono_ns; memset(out, 0, sizeof(*out)); out->state = PGRAC_FENCED_TARGET_OFF; out->io_drain_state = PGRAC_FENCED_IO_DRAIN_DRAINED; - memcpy(out->observed_target_uuid, target->target_uuid, - sizeof(out->observed_target_uuid)); + memcpy(out->observed_target_uuid, target->target_uuid, sizeof(out->observed_target_uuid)); return PGRAC_FENCED_PROVIDER_OK; } static void test_shutdown(void) -{ -} +{} static uint64_t deadline_after_ms(uint64_t milliseconds) @@ -86,15 +94,13 @@ deadline_after_ms(uint64_t milliseconds) struct timespec now; UT_ASSERT_EQ(clock_gettime(CLOCK_MONOTONIC, &now), 0); - return (uint64_t) now.tv_sec * UINT64_C(1000000000) + - (uint64_t) now.tv_nsec + milliseconds * UINT64_C(1000000); + return (uint64_t)now.tv_sec * UINT64_C(1000000000) + (uint64_t)now.tv_nsec + + milliseconds * UINT64_C(1000000); } static int -open_context(PgracFencedOperationContextV1 *context, - PgracFencedJournalScanState *journal_state, - PgracFencedConfigV1 *config, PgracFencedProviderOpsV1 *ops, - char path[64]) +open_context(PgracFencedOperationContextV1 *context, PgracFencedJournalScanState *journal_state, + PgracFencedConfigV1 *config, PgracFencedProviderOpsV1 *ops, char path[64]) { uint8 config_digest[32]; uint8 daemon_boot_id[16]; @@ -106,17 +112,15 @@ open_context(PgracFencedOperationContextV1 *context, config->system_identifier = 9001; config->storage_backend_id = 2; memset(config->storage_uuid, 0x31, sizeof(config->storage_uuid)); - config->allowed_db_uid = (uint64) geteuid(); - config->allowed_db_gid = (uint64) getegid(); + config->allowed_db_uid = (uint64)geteuid(); + config->allowed_db_gid = (uint64)getegid(); config->provider_id = PGRAC_FENCED_PROVIDER_ID_TEST_ONLY; config->provider_abi = PGRAC_FENCED_PROVIDER_ABI_V1; config->node_count = 2; config->nodes[3].present = true; - memset(config->nodes[3].target_uuid, 0x41, - sizeof(config->nodes[3].target_uuid)); + memset(config->nodes[3].target_uuid, 0x41, sizeof(config->nodes[3].target_uuid)); config->nodes[4].present = true; - memset(config->nodes[4].target_uuid, 0x42, - sizeof(config->nodes[4].target_uuid)); + memset(config->nodes[4].target_uuid, 0x42, sizeof(config->nodes[4].target_uuid)); memset(ops, 0, sizeof(*ops)); ops->abi_version = PGRAC_FENCED_PROVIDER_ABI_V1; ops->struct_size = sizeof(*ops); @@ -136,26 +140,23 @@ open_context(PgracFencedOperationContextV1 *context, return -1; UT_ASSERT_EQ(fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_APPEND), 0); pgrac_fenced_journal_scan_state_init(journal_state); - UT_ASSERT(pgrac_fenced_operation_context_init(context, config, ops, true, - config_digest, daemon_boot_id, fd, journal_state)); + UT_ASSERT(pgrac_fenced_operation_context_init(context, config, ops, true, config_digest, + daemon_boot_id, fd, journal_state)); return fd; } static void -make_request(const PgracFencedConfigV1 *config, int32 node_id, - uint8 nonce, uint8 duty, +make_request(const PgracFencedConfigV1 *config, int32 node_id, uint8 nonce, uint8 duty, PgracExternalFenceProtocolRequestV1 *request) { memset(request, 0, sizeof(*request)); memset(request->request_nonce, nonce, sizeof(request->request_nonce)); request->need.system_identifier = config->system_identifier; - memset(request->need.canonical_duty_digest, duty, - sizeof(request->need.canonical_duty_digest)); + memset(request->need.canonical_duty_digest, duty, sizeof(request->need.canonical_duty_digest)); request->need.victim_node_id = node_id; - request->need.victim_incarnation = (uint64) duty + 20; + request->need.victim_incarnation = (uint64)duty + 20; UT_ASSERT(pgrac_external_fence_protected_set_digest_v1( - config->storage_backend_id, config->storage_uuid, - request->need.protected_set_digest)); + config->storage_backend_id, config->storage_uuid, request->need.protected_set_digest)); request->need.predicate_id = 1; request->need.predicate_version = 1; request->timeout_ms = 2000; @@ -166,8 +167,8 @@ write_request(int fd, const PgracExternalFenceProtocolRequestV1 *request) { uint8 frame[PGRAC_EXTERNAL_FENCE_REQUEST_V1_BYTES]; - return pgrac_external_fence_request_v1_encode(request, frame) && - write(fd, frame, sizeof(frame)) == sizeof(frame); + return pgrac_external_fence_request_v1_encode(request, frame) + && write(fd, frame, sizeof(frame)) == sizeof(frame); } static bool @@ -176,15 +177,14 @@ try_response(int fd, PgracExternalFenceProtocolResponseV1 *response) uint8 frame[PGRAC_EXTERNAL_FENCE_RESPONSE_V1_BYTES]; ssize_t got; - do - { + do { got = recv(fd, frame, sizeof(frame), MSG_DONTWAIT); } while (got < 0 && errno == EINTR); if (got < 0 && (errno == EAGAIN || errno == EWOULDBLOCK)) return false; UT_ASSERT_EQ(got, sizeof(frame)); - return got == sizeof(frame) && - pgrac_external_fence_response_v1_decode(frame, sizeof(frame), response); + return got == sizeof(frame) + && pgrac_external_fence_response_v1_decode(frame, sizeof(frame), response); } static size_t @@ -193,7 +193,7 @@ journal_record_count(int fd) struct stat st; UT_ASSERT_EQ(fstat(fd, &st), 0); - return (size_t) st.st_size / PGRAC_FENCED_JOURNAL_RECORD_BYTES; + return (size_t)st.st_size / PGRAC_FENCED_JOURNAL_RECORD_BYTES; } UT_TEST(test_socket_join_fifo_and_different_target_concurrency) @@ -204,9 +204,9 @@ UT_TEST(test_socket_join_fifo_and_different_target_concurrency) PgracFencedConfigV1 config; PgracFencedCoordinatorV1 coordinator; PgracExternalFenceProtocolRequestV1 requests[4]; - PgracExternalFenceProtocolResponseV1 responses[4]; - bool received[4] = {false, false, false, false}; - struct timespec pause = {0, 1000000}; + PgracExternalFenceProtocolResponseV1 responses[4] = { 0 }; + bool received[4] = { false, false, false, false }; + struct timespec pause = { 0, 1000000 }; int sockets[4][2]; char path[64]; int journal_fd; @@ -216,8 +216,8 @@ UT_TEST(test_socket_join_fifo_and_different_target_concurrency) journal_fd = open_context(&context, &journal_state, &config, &ops, path); if (journal_fd < 0) return; - provider_state = mmap(NULL, sizeof(*provider_state), - PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0); + provider_state + = mmap(NULL, sizeof(*provider_state), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0); UT_ASSERT(provider_state != MAP_FAILED); if (provider_state == MAP_FAILED) return; @@ -225,29 +225,23 @@ UT_TEST(test_socket_join_fifo_and_different_target_concurrency) UT_ASSERT(pgrac_fenced_coordinator_init(&coordinator, &context)); make_request(&config, 3, 0x51, 0x61, &requests[0]); requests[1] = requests[0]; - memset(requests[1].request_nonce, 0x52, - sizeof(requests[1].request_nonce)); + memset(requests[1].request_nonce, 0x52, sizeof(requests[1].request_nonce)); make_request(&config, 3, 0x53, 0x62, &requests[2]); make_request(&config, 4, 0x54, 0x63, &requests[3]); - for (i = 0; i < 4; i++) - { + for (i = 0; i < 4; i++) { UT_ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, sockets[i]), 0); UT_ASSERT(write_request(sockets[i][0], &requests[i])); - UT_ASSERT(pgrac_fenced_coordinator_accept_fd(&coordinator, - sockets[i][1], deadline_after_ms(2000))); + UT_ASSERT(pgrac_fenced_coordinator_accept_fd(&coordinator, sockets[i][1], + deadline_after_ms(2000))); } UT_ASSERT(!pgrac_fenced_coordinator_shutdown(&coordinator, 16)); - for (loops = 0; loops < 2000 && - (!received[0] || !received[1] || !received[3]); loops++) - { - UT_ASSERT(pgrac_fenced_coordinator_service(&coordinator, - deadline_after_ms(0))); - for (i = 0; i < 4; i++) - { + for (loops = 0; loops < 2000 && (!received[0] || !received[1] || !received[3]); loops++) { + UT_ASSERT(pgrac_fenced_coordinator_service(&coordinator, deadline_after_ms(0))); + for (i = 0; i < 4; i++) { if (!received[i]) received[i] = try_response(sockets[i][0], &responses[i]); } - (void) nanosleep(&pause, NULL); + (void)nanosleep(&pause, NULL); } UT_ASSERT(received[0]); UT_ASSERT(received[1]); @@ -256,21 +250,17 @@ UT_TEST(test_socket_join_fifo_and_different_target_concurrency) UT_ASSERT_EQ(responses[0].verdict, 1); UT_ASSERT_EQ(responses[1].verdict, 1); UT_ASSERT_EQ(responses[3].verdict, 1); - UT_ASSERT_EQ(responses[0].proof_generation, - responses[1].proof_generation); - UT_ASSERT(memcmp(responses[0].target_state_digest, - responses[1].target_state_digest, - sizeof(responses[0].target_state_digest)) == 0); - UT_ASSERT_EQ(responses[0].verified_mono_ns, - responses[1].verified_mono_ns); + UT_ASSERT_EQ(responses[0].proof_generation, responses[1].proof_generation); + UT_ASSERT(memcmp(responses[0].target_state_digest, responses[1].target_state_digest, + sizeof(responses[0].target_state_digest)) + == 0); + UT_ASSERT_EQ(responses[0].verified_mono_ns, responses[1].verified_mono_ns); UT_ASSERT_EQ(close(sockets[0][0]), 0); UT_ASSERT_EQ(close(sockets[1][0]), 0); - for (loops = 0; loops < 2000 && !received[2]; loops++) - { - UT_ASSERT(pgrac_fenced_coordinator_service(&coordinator, - deadline_after_ms(0))); + for (loops = 0; loops < 2000 && !received[2]; loops++) { + UT_ASSERT(pgrac_fenced_coordinator_service(&coordinator, deadline_after_ms(0))); received[2] = try_response(sockets[2][0], &responses[2]); - (void) nanosleep(&pause, NULL); + (void)nanosleep(&pause, NULL); } UT_ASSERT(received[2]); UT_ASSERT_EQ(responses[2].verdict, 1); @@ -278,11 +268,11 @@ UT_TEST(test_socket_join_fifo_and_different_target_concurrency) UT_ASSERT_EQ(provider_state->node_actions[4], 1); UT_ASSERT_EQ(journal_record_count(journal_fd), 20); UT_ASSERT(pgrac_fenced_coordinator_shutdown(&coordinator, 16)); - (void) close(sockets[2][0]); - (void) close(sockets[3][0]); + (void)close(sockets[2][0]); + (void)close(sockets[3][0]); UT_ASSERT_EQ(munmap(provider_state, sizeof(*provider_state)), 0); - (void) close(journal_fd); - (void) unlink(path); + (void)close(journal_fd); + (void)unlink(path); } UT_TEST(test_queued_deadline_is_durably_invalidated_without_action) @@ -294,10 +284,10 @@ UT_TEST(test_queued_deadline_is_durably_invalidated_without_action) PgracFencedCoordinatorV1 coordinator; PgracExternalFenceProtocolRequestV1 owner_request; PgracExternalFenceProtocolRequestV1 queued_request; - PgracExternalFenceProtocolResponseV1 owner_response; - PgracExternalFenceProtocolResponseV1 queued_response; - struct timespec pause = {0, 1000000}; - struct timespec expire = {0, 30000000}; + PgracExternalFenceProtocolResponseV1 owner_response = { 0 }; + PgracExternalFenceProtocolResponseV1 queued_response = { 0 }; + struct timespec pause = { 0, 1000000 }; + struct timespec expire = { 0, 30000000 }; int owner_sockets[2]; int queued_sockets[2]; char path[64]; @@ -308,8 +298,8 @@ UT_TEST(test_queued_deadline_is_durably_invalidated_without_action) journal_fd = open_context(&context, &journal_state, &config, &ops, path); if (journal_fd < 0) return; - provider_state = mmap(NULL, sizeof(*provider_state), - PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0); + provider_state + = mmap(NULL, sizeof(*provider_state), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0); UT_ASSERT(provider_state != MAP_FAILED); if (provider_state == MAP_FAILED) return; @@ -321,35 +311,32 @@ UT_TEST(test_queued_deadline_is_durably_invalidated_without_action) queued_request.timeout_ms = 20; UT_ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, owner_sockets), 0); UT_ASSERT(write_request(owner_sockets[0], &owner_request)); - UT_ASSERT(pgrac_fenced_coordinator_accept_fd(&coordinator, - owner_sockets[1], deadline_after_ms(2000))); - for (loops = 0; loops < 1000 && !received; loops++) - { - UT_ASSERT(pgrac_fenced_coordinator_service(&coordinator, - deadline_after_ms(0))); + UT_ASSERT(pgrac_fenced_coordinator_accept_fd(&coordinator, owner_sockets[1], + deadline_after_ms(2000))); + for (loops = 0; loops < 1000 && !received; loops++) { + UT_ASSERT(pgrac_fenced_coordinator_service(&coordinator, deadline_after_ms(0))); received = try_response(owner_sockets[0], &owner_response); - (void) nanosleep(&pause, NULL); + (void)nanosleep(&pause, NULL); } UT_ASSERT(received); UT_ASSERT_EQ(owner_response.verdict, 1); UT_ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, queued_sockets), 0); UT_ASSERT(write_request(queued_sockets[0], &queued_request)); - UT_ASSERT(pgrac_fenced_coordinator_accept_fd(&coordinator, - queued_sockets[1], deadline_after_ms(2000))); - (void) nanosleep(&expire, NULL); - UT_ASSERT(pgrac_fenced_coordinator_service(&coordinator, - deadline_after_ms(0))); + UT_ASSERT(pgrac_fenced_coordinator_accept_fd(&coordinator, queued_sockets[1], + deadline_after_ms(2000))); + (void)nanosleep(&expire, NULL); + UT_ASSERT(pgrac_fenced_coordinator_service(&coordinator, deadline_after_ms(0))); UT_ASSERT(try_response(queued_sockets[0], &queued_response)); UT_ASSERT_EQ(queued_response.verdict, 4); UT_ASSERT_EQ(queued_response.deny_reason, 11); UT_ASSERT_EQ(provider_state->node_actions[3], 1); UT_ASSERT_EQ(journal_record_count(journal_fd), 8); UT_ASSERT(pgrac_fenced_coordinator_shutdown(&coordinator, 16)); - (void) close(owner_sockets[0]); - (void) close(queued_sockets[0]); + (void)close(owner_sockets[0]); + (void)close(queued_sockets[0]); UT_ASSERT_EQ(munmap(provider_state, sizeof(*provider_state)), 0); - (void) close(journal_fd); - (void) unlink(path); + (void)close(journal_fd); + (void)unlink(path); } UT_TEST(test_partial_ingress_never_blocks_other_clients_or_workers) @@ -360,10 +347,10 @@ UT_TEST(test_partial_ingress_never_blocks_other_clients_or_workers) PgracFencedConfigV1 config; PgracFencedCoordinatorV1 coordinator; PgracExternalFenceProtocolRequestV1 request; - PgracExternalFenceProtocolResponseV1 response; + PgracExternalFenceProtocolResponseV1 response = { 0 }; uint8 frame[PGRAC_EXTERNAL_FENCE_REQUEST_V1_BYTES]; - struct timespec pause = {0, 1000000}; - struct timespec expire = {0, 120000000}; + struct timespec pause = { 0, 1000000 }; + struct timespec expire = { 0, 120000000 }; int partial_sockets[2]; int full_sockets[2]; char path[64]; @@ -377,8 +364,8 @@ UT_TEST(test_partial_ingress_never_blocks_other_clients_or_workers) journal_fd = open_context(&context, &journal_state, &config, &ops, path); if (journal_fd < 0) return; - provider_state = mmap(NULL, sizeof(*provider_state), - PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0); + provider_state + = mmap(NULL, sizeof(*provider_state), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0); UT_ASSERT(provider_state != MAP_FAILED); if (provider_state == MAP_FAILED) return; @@ -390,37 +377,33 @@ UT_TEST(test_partial_ingress_never_blocks_other_clients_or_workers) UT_ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, partial_sockets), 0); UT_ASSERT_EQ(write(partial_sockets[0], frame, 1), 1); before = deadline_after_ms(0); - UT_ASSERT(pgrac_fenced_coordinator_accept_fd(&coordinator, - partial_sockets[1], deadline_after_ms(100))); + UT_ASSERT(pgrac_fenced_coordinator_accept_fd(&coordinator, partial_sockets[1], + deadline_after_ms(100))); after = deadline_after_ms(0); UT_ASSERT(after >= before && after - before < UINT64_C(50000000)); UT_ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, full_sockets), 0); UT_ASSERT(write_request(full_sockets[0], &request)); - UT_ASSERT(pgrac_fenced_coordinator_accept_fd(&coordinator, - full_sockets[1], deadline_after_ms(2000))); - for (loops = 0; loops < 2000 && !received; loops++) - { - UT_ASSERT(pgrac_fenced_coordinator_service(&coordinator, - deadline_after_ms(0))); + UT_ASSERT( + pgrac_fenced_coordinator_accept_fd(&coordinator, full_sockets[1], deadline_after_ms(2000))); + for (loops = 0; loops < 2000 && !received; loops++) { + UT_ASSERT(pgrac_fenced_coordinator_service(&coordinator, deadline_after_ms(0))); received = try_response(full_sockets[0], &response); - (void) nanosleep(&pause, NULL); + (void)nanosleep(&pause, NULL); } UT_ASSERT(received); UT_ASSERT_EQ(response.verdict, 1); UT_ASSERT_EQ(journal_record_count(journal_fd), 6); - (void) nanosleep(&expire, NULL); - UT_ASSERT(pgrac_fenced_coordinator_service(&coordinator, - deadline_after_ms(0))); + (void)nanosleep(&expire, NULL); + UT_ASSERT(pgrac_fenced_coordinator_service(&coordinator, deadline_after_ms(0))); UT_ASSERT_EQ(recv(partial_sockets[0], &byte, 1, MSG_DONTWAIT), 0); - (void) close(full_sockets[0]); - UT_ASSERT(pgrac_fenced_coordinator_service(&coordinator, - deadline_after_ms(0))); + (void)close(full_sockets[0]); + UT_ASSERT(pgrac_fenced_coordinator_service(&coordinator, deadline_after_ms(0))); UT_ASSERT(pgrac_fenced_coordinator_shutdown(&coordinator, 16)); - (void) close(partial_sockets[0]); + (void)close(partial_sockets[0]); UT_ASSERT_EQ(munmap(provider_state, sizeof(*provider_state)), 0); - (void) close(journal_fd); - (void) unlink(path); + (void)close(journal_fd); + (void)unlink(path); } UT_TEST(test_clean_shutdown_durably_invalidates_accepted_queue) @@ -432,9 +415,9 @@ UT_TEST(test_clean_shutdown_durably_invalidates_accepted_queue) PgracFencedCoordinatorV1 coordinator; PgracExternalFenceProtocolRequestV1 owner_request; PgracExternalFenceProtocolRequestV1 queued_request; - PgracExternalFenceProtocolResponseV1 owner_response; - PgracExternalFenceProtocolResponseV1 queued_response; - struct timespec pause = {0, 1000000}; + PgracExternalFenceProtocolResponseV1 owner_response = { 0 }; + PgracExternalFenceProtocolResponseV1 queued_response = { 0 }; + struct timespec pause = { 0, 1000000 }; int owner_sockets[2]; int queued_sockets[2]; char path[64]; @@ -445,8 +428,8 @@ UT_TEST(test_clean_shutdown_durably_invalidates_accepted_queue) journal_fd = open_context(&context, &journal_state, &config, &ops, path); if (journal_fd < 0) return; - provider_state = mmap(NULL, sizeof(*provider_state), - PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0); + provider_state + = mmap(NULL, sizeof(*provider_state), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0); UT_ASSERT(provider_state != MAP_FAILED); if (provider_state == MAP_FAILED) return; @@ -457,36 +440,33 @@ UT_TEST(test_clean_shutdown_durably_invalidates_accepted_queue) make_request(&config, 3, 0x93, 0x94, &queued_request); UT_ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, owner_sockets), 0); UT_ASSERT(write_request(owner_sockets[0], &owner_request)); - UT_ASSERT(pgrac_fenced_coordinator_accept_fd(&coordinator, - owner_sockets[1], deadline_after_ms(2000))); - for (loops = 0; loops < 2000 && !received; loops++) - { - UT_ASSERT(pgrac_fenced_coordinator_service(&coordinator, - deadline_after_ms(0))); + UT_ASSERT(pgrac_fenced_coordinator_accept_fd(&coordinator, owner_sockets[1], + deadline_after_ms(2000))); + for (loops = 0; loops < 2000 && !received; loops++) { + UT_ASSERT(pgrac_fenced_coordinator_service(&coordinator, deadline_after_ms(0))); received = try_response(owner_sockets[0], &owner_response); - (void) nanosleep(&pause, NULL); + (void)nanosleep(&pause, NULL); } UT_ASSERT(received); UT_ASSERT_EQ(owner_response.verdict, 1); UT_ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, queued_sockets), 0); UT_ASSERT(write_request(queued_sockets[0], &queued_request)); - UT_ASSERT(pgrac_fenced_coordinator_accept_fd(&coordinator, - queued_sockets[1], deadline_after_ms(2000))); + UT_ASSERT(pgrac_fenced_coordinator_accept_fd(&coordinator, queued_sockets[1], + deadline_after_ms(2000))); UT_ASSERT_EQ(provider_state->node_actions[3], 1); UT_ASSERT_EQ(journal_record_count(journal_fd), 7); UT_ASSERT(pgrac_fenced_coordinator_shutdown(&coordinator, 16)); UT_ASSERT(try_response(queued_sockets[0], &queued_response)); UT_ASSERT_EQ(queued_response.verdict, 4); UT_ASSERT_EQ(queued_response.deny_reason, 16); - UT_ASSERT_EQ(queued_response.provider_result, - PGRAC_FENCED_PROVIDER_UNAVAILABLE); + UT_ASSERT_EQ(queued_response.provider_result, PGRAC_FENCED_PROVIDER_UNAVAILABLE); UT_ASSERT_EQ(provider_state->node_actions[3], 1); UT_ASSERT_EQ(journal_record_count(journal_fd), 9); - (void) close(owner_sockets[0]); - (void) close(queued_sockets[0]); + (void)close(owner_sockets[0]); + (void)close(queued_sockets[0]); UT_ASSERT_EQ(munmap(provider_state, sizeof(*provider_state)), 0); - (void) close(journal_fd); - (void) unlink(path); + (void)close(journal_fd); + (void)unlink(path); } UT_TEST(test_mapping_reload_closes_old_admissions_before_new_mapping) @@ -500,9 +480,9 @@ UT_TEST(test_mapping_reload_closes_old_admissions_before_new_mapping) PgracExternalFenceProtocolRequestV1 owner_request; PgracExternalFenceProtocolRequestV1 queued_request; PgracExternalFenceProtocolRequestV1 fresh_request; - PgracExternalFenceProtocolResponseV1 response; + PgracExternalFenceProtocolResponseV1 response = { 0 }; uint8 candidate_digest[32]; - struct timespec pause = {0, 1000000}; + struct timespec pause = { 0, 1000000 }; int owner_sockets[2]; int queued_sockets[2]; int fresh_sockets[2]; @@ -514,8 +494,8 @@ UT_TEST(test_mapping_reload_closes_old_admissions_before_new_mapping) journal_fd = open_context(&context, &journal_state, &config, &ops, path); if (journal_fd < 0) return; - provider_state = mmap(NULL, sizeof(*provider_state), - PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0); + provider_state + = mmap(NULL, sizeof(*provider_state), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0); UT_ASSERT(provider_state != MAP_FAILED); if (provider_state == MAP_FAILED) return; @@ -526,27 +506,25 @@ UT_TEST(test_mapping_reload_closes_old_admissions_before_new_mapping) make_request(&config, 3, 0xa3, 0xa4, &queued_request); UT_ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, owner_sockets), 0); UT_ASSERT(write_request(owner_sockets[0], &owner_request)); - UT_ASSERT(pgrac_fenced_coordinator_accept_fd(&coordinator, - owner_sockets[1], deadline_after_ms(2000))); - for (loops = 0; loops < 2000 && !received; loops++) - { - UT_ASSERT(pgrac_fenced_coordinator_service(&coordinator, - deadline_after_ms(0))); + UT_ASSERT(pgrac_fenced_coordinator_accept_fd(&coordinator, owner_sockets[1], + deadline_after_ms(2000))); + for (loops = 0; loops < 2000 && !received; loops++) { + UT_ASSERT(pgrac_fenced_coordinator_service(&coordinator, deadline_after_ms(0))); received = try_response(owner_sockets[0], &response); - (void) nanosleep(&pause, NULL); + (void)nanosleep(&pause, NULL); } UT_ASSERT(received); UT_ASSERT_EQ(response.verdict, 1); UT_ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, queued_sockets), 0); UT_ASSERT(write_request(queued_sockets[0], &queued_request)); - UT_ASSERT(pgrac_fenced_coordinator_accept_fd(&coordinator, - queued_sockets[1], deadline_after_ms(2000))); + UT_ASSERT(pgrac_fenced_coordinator_accept_fd(&coordinator, queued_sockets[1], + deadline_after_ms(2000))); candidate = config; candidate.mapping_generation++; candidate.nodes[3].target_uuid[0] ^= 1; memset(candidate_digest, 0x72, sizeof(candidate_digest)); - UT_ASSERT(pgrac_fenced_operation_prepare_mapping_reload(&context, - &candidate, &ops, candidate_digest)); + UT_ASSERT(pgrac_fenced_operation_prepare_mapping_reload(&context, &candidate, &ops, + candidate_digest)); UT_ASSERT_EQ(context.config->mapping_generation, 17); UT_ASSERT(pgrac_fenced_coordinator_shutdown(&coordinator, 17)); UT_ASSERT(try_response(queued_sockets[0], &response)); @@ -558,15 +536,13 @@ UT_TEST(test_mapping_reload_closes_old_admissions_before_new_mapping) make_request(&candidate, 3, 0xa5, 0xa6, &fresh_request); UT_ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, fresh_sockets), 0); UT_ASSERT(write_request(fresh_sockets[0], &fresh_request)); - UT_ASSERT(pgrac_fenced_coordinator_accept_fd(&coordinator, - fresh_sockets[1], deadline_after_ms(2000))); + UT_ASSERT(pgrac_fenced_coordinator_accept_fd(&coordinator, fresh_sockets[1], + deadline_after_ms(2000))); received = false; - for (loops = 0; loops < 2000 && !received; loops++) - { - UT_ASSERT(pgrac_fenced_coordinator_service(&coordinator, - deadline_after_ms(0))); + for (loops = 0; loops < 2000 && !received; loops++) { + UT_ASSERT(pgrac_fenced_coordinator_service(&coordinator, deadline_after_ms(0))); received = try_response(fresh_sockets[0], &response); - (void) nanosleep(&pause, NULL); + (void)nanosleep(&pause, NULL); } UT_ASSERT(received); UT_ASSERT_EQ(response.verdict, 1); @@ -574,12 +550,12 @@ UT_TEST(test_mapping_reload_closes_old_admissions_before_new_mapping) UT_ASSERT_EQ(provider_state->node_actions[3], 2); UT_ASSERT_EQ(journal_record_count(journal_fd), 15); UT_ASSERT(pgrac_fenced_coordinator_shutdown(&coordinator, 16)); - (void) close(owner_sockets[0]); - (void) close(queued_sockets[0]); - (void) close(fresh_sockets[0]); + (void)close(owner_sockets[0]); + (void)close(queued_sockets[0]); + (void)close(fresh_sockets[0]); UT_ASSERT_EQ(munmap(provider_state, sizeof(*provider_state)), 0); - (void) close(journal_fd); - (void) unlink(path); + (void)close(journal_fd); + (void)unlink(path); } UT_TEST(test_reload_during_active_operation_invalidates_queue_without_abort) @@ -591,9 +567,9 @@ UT_TEST(test_reload_during_active_operation_invalidates_queue_without_abort) PgracFencedCoordinatorV1 coordinator; PgracExternalFenceProtocolRequestV1 owner_request; PgracExternalFenceProtocolRequestV1 queued_request; - PgracExternalFenceProtocolResponseV1 owner_response; - PgracExternalFenceProtocolResponseV1 queued_response; - struct timespec pause = {0, 1000000}; + PgracExternalFenceProtocolResponseV1 owner_response = { 0 }; + PgracExternalFenceProtocolResponseV1 queued_response = { 0 }; + struct timespec pause = { 0, 1000000 }; int owner_sockets[2]; int queued_sockets[2]; char path[64]; @@ -604,8 +580,8 @@ UT_TEST(test_reload_during_active_operation_invalidates_queue_without_abort) journal_fd = open_context(&context, &journal_state, &config, &ops, path); if (journal_fd < 0) return; - provider_state = mmap(NULL, sizeof(*provider_state), - PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0); + provider_state + = mmap(NULL, sizeof(*provider_state), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0); UT_ASSERT(provider_state != MAP_FAILED); if (provider_state == MAP_FAILED) return; @@ -613,28 +589,38 @@ UT_TEST(test_reload_during_active_operation_invalidates_queue_without_abort) UT_ASSERT(pgrac_fenced_coordinator_init(&coordinator, &context)); make_request(&config, 3, 0xb1, 0xb2, &owner_request); make_request(&config, 3, 0xb3, 0xb4, &queued_request); + provider_state->hold_action = 1; UT_ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, owner_sockets), 0); UT_ASSERT(write_request(owner_sockets[0], &owner_request)); - UT_ASSERT(pgrac_fenced_coordinator_accept_fd(&coordinator, - owner_sockets[1], deadline_after_ms(2000))); + UT_ASSERT(pgrac_fenced_coordinator_accept_fd(&coordinator, owner_sockets[1], + deadline_after_ms(2000))); UT_ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, queued_sockets), 0); UT_ASSERT(write_request(queued_sockets[0], &queued_request)); - UT_ASSERT(pgrac_fenced_coordinator_accept_fd(&coordinator, - queued_sockets[1], deadline_after_ms(2000))); + UT_ASSERT(pgrac_fenced_coordinator_accept_fd(&coordinator, queued_sockets[1], + deadline_after_ms(2000))); + /* + * Prove the provider is in flight before reload, then release it explicitly. + * Counting 500 sleeps made this test depend on OS timer coalescing and could + * exhaust the unchanged two-second operation deadline on macOS. + */ + for (loops = 0; loops < 2000 && provider_state->node_actions[3] == 0; loops++) { + UT_ASSERT(pgrac_fenced_coordinator_service(&coordinator, deadline_after_ms(0))); + (void)nanosleep(&pause, NULL); + } + UT_ASSERT_EQ(provider_state->node_actions[3], 1); + UT_ASSERT(!try_response(owner_sockets[0], &owner_response)); UT_ASSERT_EQ(pgrac_fenced_coordinator_active_worker_count(&coordinator), 1); UT_ASSERT(pgrac_fenced_coordinator_quiesce(&coordinator, 17)); UT_ASSERT(try_response(queued_sockets[0], &queued_response)); UT_ASSERT_EQ(queued_response.verdict, 4); UT_ASSERT_EQ(queued_response.deny_reason, 17); - for (loops = 0; loops < 2000 && - pgrac_fenced_coordinator_active_worker_count(&coordinator) > 0; - loops++) - { - UT_ASSERT(pgrac_fenced_coordinator_service(&coordinator, - deadline_after_ms(0))); + provider_state->release_action = 1; + for (loops = 0; loops < 2000 && pgrac_fenced_coordinator_active_worker_count(&coordinator) > 0; + loops++) { + UT_ASSERT(pgrac_fenced_coordinator_service(&coordinator, deadline_after_ms(0))); if (!owner_received) owner_received = try_response(owner_sockets[0], &owner_response); - (void) nanosleep(&pause, NULL); + (void)nanosleep(&pause, NULL); } UT_ASSERT_EQ(pgrac_fenced_coordinator_active_worker_count(&coordinator), 0); UT_ASSERT(owner_received); @@ -642,11 +628,11 @@ UT_TEST(test_reload_during_active_operation_invalidates_queue_without_abort) UT_ASSERT_EQ(provider_state->node_actions[3], 1); UT_ASSERT(pgrac_fenced_coordinator_shutdown(&coordinator, 17)); UT_ASSERT_EQ(journal_record_count(journal_fd), 9); - (void) close(owner_sockets[0]); - (void) close(queued_sockets[0]); + (void)close(owner_sockets[0]); + (void)close(queued_sockets[0]); UT_ASSERT_EQ(munmap(provider_state, sizeof(*provider_state)), 0); - (void) close(journal_fd); - (void) unlink(path); + (void)close(journal_fd); + (void)unlink(path); } UT_TEST(test_rejoin_reservation_invalidates_only_exact_target) @@ -658,7 +644,7 @@ UT_TEST(test_rejoin_reservation_invalidates_only_exact_target) PgracFencedCoordinatorV1 coordinator; PgracExternalFenceProtocolRequestV1 request; PgracExternalFenceProtocolResponseV1 response; - struct timespec pause = {0, 1000000}; + struct timespec pause = { 0, 1000000 }; int first[2]; int blocked[2]; int other[2]; @@ -672,8 +658,8 @@ UT_TEST(test_rejoin_reservation_invalidates_only_exact_target) journal_fd = open_context(&context, &journal_state, &config, &ops, path); if (journal_fd < 0) return; - provider_state = mmap(NULL, sizeof(*provider_state), - PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0); + provider_state + = mmap(NULL, sizeof(*provider_state), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0); UT_ASSERT(provider_state != MAP_FAILED); if (provider_state == MAP_FAILED) return; @@ -683,32 +669,30 @@ UT_TEST(test_rejoin_reservation_invalidates_only_exact_target) make_request(&config, 3, 0xc1, 0xc2, &request); UT_ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, first), 0); UT_ASSERT(write_request(first[0], &request)); - UT_ASSERT(pgrac_fenced_coordinator_accept_fd(&coordinator, first[1], - deadline_after_ms(2000))); + UT_ASSERT(pgrac_fenced_coordinator_accept_fd(&coordinator, first[1], deadline_after_ms(2000))); received = false; - for (loops = 0; loops < 2000 && !received; loops++) - { - UT_ASSERT(pgrac_fenced_coordinator_service(&coordinator, - deadline_after_ms(0))); + for (loops = 0; loops < 2000 && !received; loops++) { + UT_ASSERT(pgrac_fenced_coordinator_service(&coordinator, deadline_after_ms(0))); received = try_response(first[0], &response); - (void) nanosleep(&pause, NULL); + (void)nanosleep(&pause, NULL); } UT_ASSERT(received); UT_ASSERT_EQ(response.verdict, 1); - UT_ASSERT_EQ(pgrac_fenced_coordinator_rejoin_acquire_target(&coordinator, - config.nodes[3].target_uuid), PGRAC_FENCED_REJOIN_TARGET_READY); + UT_ASSERT_EQ( + pgrac_fenced_coordinator_rejoin_acquire_target(&coordinator, config.nodes[3].target_uuid), + PGRAC_FENCED_REJOIN_TARGET_READY); UT_ASSERT_EQ(recv(first[0], &byte, 1, MSG_DONTWAIT), -1); UT_ASSERT(errno == EAGAIN || errno == EWOULDBLOCK); - UT_ASSERT_EQ(pgrac_fenced_coordinator_rejoin_invalidate_target( - &coordinator, config.nodes[3].target_uuid, 19), - PGRAC_FENCED_REJOIN_TARGET_READY); + UT_ASSERT_EQ(pgrac_fenced_coordinator_rejoin_invalidate_target(&coordinator, + config.nodes[3].target_uuid, 19), + PGRAC_FENCED_REJOIN_TARGET_READY); UT_ASSERT_EQ(recv(first[0], &byte, 1, MSG_DONTWAIT), 0); make_request(&config, 3, 0xc3, 0xc4, &request); UT_ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, blocked), 0); UT_ASSERT(write_request(blocked[0], &request)); - UT_ASSERT(pgrac_fenced_coordinator_accept_fd(&coordinator, blocked[1], - deadline_after_ms(2000))); + UT_ASSERT( + pgrac_fenced_coordinator_accept_fd(&coordinator, blocked[1], deadline_after_ms(2000))); UT_ASSERT(try_response(blocked[0], &response)); UT_ASSERT_EQ(response.verdict, 4); UT_ASSERT_EQ(response.deny_reason, 19); @@ -717,46 +701,40 @@ UT_TEST(test_rejoin_reservation_invalidates_only_exact_target) make_request(&config, 4, 0xc5, 0xc6, &request); UT_ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, other), 0); UT_ASSERT(write_request(other[0], &request)); - UT_ASSERT(pgrac_fenced_coordinator_accept_fd(&coordinator, other[1], - deadline_after_ms(2000))); + UT_ASSERT(pgrac_fenced_coordinator_accept_fd(&coordinator, other[1], deadline_after_ms(2000))); received = false; - for (loops = 0; loops < 2000 && !received; loops++) - { - UT_ASSERT(pgrac_fenced_coordinator_service(&coordinator, - deadline_after_ms(0))); + for (loops = 0; loops < 2000 && !received; loops++) { + UT_ASSERT(pgrac_fenced_coordinator_service(&coordinator, deadline_after_ms(0))); received = try_response(other[0], &response); - (void) nanosleep(&pause, NULL); + (void)nanosleep(&pause, NULL); } UT_ASSERT(received); UT_ASSERT_EQ(response.verdict, 1); UT_ASSERT_EQ(provider_state->node_actions[4], 1); - UT_ASSERT(pgrac_fenced_coordinator_rejoin_release_target(&coordinator, - config.nodes[3].target_uuid)); + UT_ASSERT( + pgrac_fenced_coordinator_rejoin_release_target(&coordinator, config.nodes[3].target_uuid)); make_request(&config, 3, 0xc7, 0xc8, &request); UT_ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, fresh), 0); UT_ASSERT(write_request(fresh[0], &request)); - UT_ASSERT(pgrac_fenced_coordinator_accept_fd(&coordinator, fresh[1], - deadline_after_ms(2000))); + UT_ASSERT(pgrac_fenced_coordinator_accept_fd(&coordinator, fresh[1], deadline_after_ms(2000))); received = false; - for (loops = 0; loops < 2000 && !received; loops++) - { - UT_ASSERT(pgrac_fenced_coordinator_service(&coordinator, - deadline_after_ms(0))); + for (loops = 0; loops < 2000 && !received; loops++) { + UT_ASSERT(pgrac_fenced_coordinator_service(&coordinator, deadline_after_ms(0))); received = try_response(fresh[0], &response); - (void) nanosleep(&pause, NULL); + (void)nanosleep(&pause, NULL); } UT_ASSERT(received); UT_ASSERT_EQ(response.verdict, 1); UT_ASSERT_EQ(provider_state->node_actions[3], 2); UT_ASSERT(pgrac_fenced_coordinator_shutdown(&coordinator, 16)); - (void) close(first[0]); - (void) close(blocked[0]); - (void) close(other[0]); - (void) close(fresh[0]); + (void)close(first[0]); + (void)close(blocked[0]); + (void)close(other[0]); + (void)close(fresh[0]); UT_ASSERT_EQ(munmap(provider_state, sizeof(*provider_state)), 0); - (void) close(journal_fd); - (void) unlink(path); + (void)close(journal_fd); + (void)unlink(path); } int diff --git a/src/test/cluster_unit/test_pgrac_fenced_core.c b/src/test/cluster_unit/test_pgrac_fenced_core.c index deb440d464f..c1705b24db5 100644 --- a/src/test/cluster_unit/test_pgrac_fenced_core.c +++ b/src/test/cluster_unit/test_pgrac_fenced_core.c @@ -55,28 +55,27 @@ UT_TEST(test_recovery_operation_exact_happy_path) { PgracFencedTransition transition; - UT_ASSERT(pgrac_fenced_fsm_step(PGRAC_FENCED_STATE_IDLE, - PGRAC_FENCED_EVENT_REQUEST_TARGET_FREE, &transition)); + UT_ASSERT(pgrac_fenced_fsm_step(PGRAC_FENCED_STATE_IDLE, PGRAC_FENCED_EVENT_REQUEST_TARGET_FREE, + &transition)); UT_ASSERT_EQ(transition.next_state, PGRAC_FENCED_STATE_RESOLVING); UT_ASSERT_EQ(transition.journal_mask, PGRAC_FENCED_JOURNAL_REQUEST_ACCEPTED); UT_ASSERT_EQ(transition.outcome, PGRAC_FENCED_OUTCOME_PENDING); - UT_ASSERT(pgrac_fenced_fsm_step(transition.next_state, - PGRAC_FENCED_EVENT_RESOLVE_EXACT, &transition)); + UT_ASSERT(pgrac_fenced_fsm_step(transition.next_state, PGRAC_FENCED_EVENT_RESOLVE_EXACT, + &transition)); UT_ASSERT_EQ(transition.next_state, PGRAC_FENCED_STATE_ACTUATING); UT_ASSERT_EQ(transition.journal_mask, PGRAC_FENCED_JOURNAL_ACTUATION_ISSUED); - UT_ASSERT(pgrac_fenced_fsm_step(transition.next_state, - PGRAC_FENCED_EVENT_ACTUATION_FINISHED, &transition)); + UT_ASSERT(pgrac_fenced_fsm_step(transition.next_state, PGRAC_FENCED_EVENT_ACTUATION_FINISHED, + &transition)); UT_ASSERT_EQ(transition.next_state, PGRAC_FENCED_STATE_VERIFYING); UT_ASSERT_EQ(transition.journal_mask, PGRAC_FENCED_JOURNAL_ACTUATION_RESULT); - UT_ASSERT(pgrac_fenced_fsm_step(transition.next_state, - PGRAC_FENCED_EVENT_READBACK_OFF_DRAINED, &transition)); + UT_ASSERT(pgrac_fenced_fsm_step(transition.next_state, PGRAC_FENCED_EVENT_READBACK_OFF_DRAINED, + &transition)); UT_ASSERT_EQ(transition.next_state, PGRAC_FENCED_STATE_PROVEN_DURABLE); UT_ASSERT_EQ(transition.journal_mask, - PGRAC_FENCED_JOURNAL_READBACK_RESULT | - PGRAC_FENCED_JOURNAL_PROOF_SERVED); + PGRAC_FENCED_JOURNAL_READBACK_RESULT | PGRAC_FENCED_JOURNAL_PROOF_SERVED); UT_ASSERT_EQ(transition.outcome, PGRAC_FENCED_OUTCOME_WRITE_EXCLUDED); UT_ASSERT_EQ(transition.deny_reason, PGRAC_FENCED_DENY_NONE); } @@ -86,19 +85,19 @@ UT_TEST(test_queue_and_negative_readback_are_closed) PgracFencedTransition transition; UT_ASSERT(pgrac_fenced_fsm_step(PGRAC_FENCED_STATE_ACTUATING, - PGRAC_FENCED_EVENT_REQUEST_NONJOINABLE, &transition)); + PGRAC_FENCED_EVENT_REQUEST_NONJOINABLE, &transition)); UT_ASSERT_EQ(transition.next_state, PGRAC_FENCED_STATE_QUEUED); UT_ASSERT_EQ(transition.journal_mask, PGRAC_FENCED_JOURNAL_REQUEST_ACCEPTED); UT_ASSERT_EQ(transition.outcome, PGRAC_FENCED_OUTCOME_PENDING); - UT_ASSERT(pgrac_fenced_fsm_step(PGRAC_FENCED_STATE_QUEUED, - PGRAC_FENCED_EVENT_QUEUE_TIMEOUT, &transition)); + UT_ASSERT(pgrac_fenced_fsm_step(PGRAC_FENCED_STATE_QUEUED, PGRAC_FENCED_EVENT_QUEUE_TIMEOUT, + &transition)); UT_ASSERT_EQ(transition.next_state, PGRAC_FENCED_STATE_INVALIDATED); UT_ASSERT_EQ(transition.outcome, PGRAC_FENCED_OUTCOME_UNKNOWN); UT_ASSERT_EQ(transition.deny_reason, PGRAC_FENCED_DENY_TIMEOUT); UT_ASSERT(pgrac_fenced_fsm_step(PGRAC_FENCED_STATE_VERIFYING, - PGRAC_FENCED_EVENT_READBACK_OFF_NOT_DRAINED, &transition)); + PGRAC_FENCED_EVENT_READBACK_OFF_NOT_DRAINED, &transition)); UT_ASSERT_EQ(transition.next_state, PGRAC_FENCED_STATE_REJECTED); UT_ASSERT_EQ(transition.outcome, PGRAC_FENCED_OUTCOME_REJECTED); UT_ASSERT_EQ(transition.deny_reason, PGRAC_FENCED_DENY_IO_NOT_DRAINED); @@ -109,29 +108,29 @@ UT_TEST(test_rejoin_needs_authorize_then_fresh_refresh) { PgracFencedTransition transition; - UT_ASSERT(pgrac_fenced_fsm_step(PGRAC_FENCED_STATE_IDLE, - PGRAC_FENCED_EVENT_ADMIN_PREPARE, &transition)); + UT_ASSERT(pgrac_fenced_fsm_step(PGRAC_FENCED_STATE_IDLE, PGRAC_FENCED_EVENT_ADMIN_PREPARE, + &transition)); UT_ASSERT_EQ(transition.next_state, PGRAC_FENCED_STATE_REENABLING); UT_ASSERT_EQ(transition.outcome, PGRAC_FENCED_OUTCOME_ADMIN_OFFERED); UT_ASSERT_EQ(transition.journal_mask, PGRAC_FENCED_JOURNAL_REENABLE_REQUESTED); UT_ASSERT(pgrac_fenced_fsm_step(transition.next_state, - PGRAC_FENCED_EVENT_LMON_CLAIM_OFF_DRAINED, &transition)); + PGRAC_FENCED_EVENT_LMON_CLAIM_OFF_DRAINED, &transition)); UT_ASSERT_EQ(transition.outcome, PGRAC_FENCED_OUTCOME_LMON_OFFERED); UT_ASSERT_EQ(transition.journal_mask, PGRAC_FENCED_JOURNAL_READBACK_RESULT); - UT_ASSERT(pgrac_fenced_fsm_step(transition.next_state, - PGRAC_FENCED_EVENT_AUTHORIZE_ON, &transition)); + UT_ASSERT( + pgrac_fenced_fsm_step(transition.next_state, PGRAC_FENCED_EVENT_AUTHORIZE_ON, &transition)); UT_ASSERT_EQ(transition.outcome, PGRAC_FENCED_OUTCOME_PENDING); UT_ASSERT_EQ(transition.journal_mask, PGRAC_FENCED_JOURNAL_INVALIDATED); - UT_ASSERT(pgrac_fenced_fsm_step(transition.next_state, - PGRAC_FENCED_EVENT_READBACK_ON_DRAINED, &transition)); + UT_ASSERT(pgrac_fenced_fsm_step(transition.next_state, PGRAC_FENCED_EVENT_READBACK_ON_DRAINED, + &transition)); UT_ASSERT_EQ(transition.outcome, PGRAC_FENCED_OUTCOME_WAITING_JOINER); UT_ASSERT_EQ(transition.journal_mask, PGRAC_FENCED_JOURNAL_REENABLE_RESULT); - UT_ASSERT(pgrac_fenced_fsm_step(transition.next_state, - PGRAC_FENCED_EVENT_REFRESH_ON_DRAINED, &transition)); + UT_ASSERT(pgrac_fenced_fsm_step(transition.next_state, PGRAC_FENCED_EVENT_REFRESH_ON_DRAINED, + &transition)); UT_ASSERT_EQ(transition.outcome, PGRAC_FENCED_OUTCOME_READY); UT_ASSERT_EQ(transition.journal_mask, PGRAC_FENCED_JOURNAL_REENABLE_RESULT); } @@ -141,19 +140,19 @@ UT_TEST(test_illegal_state_event_is_fail_closed) PgracFencedTransition transition; UT_ASSERT(!pgrac_fenced_fsm_step(PGRAC_FENCED_STATE_IDLE, - PGRAC_FENCED_EVENT_READBACK_OFF_DRAINED, &transition)); + PGRAC_FENCED_EVENT_READBACK_OFF_DRAINED, &transition)); UT_ASSERT_EQ(transition.next_state, PGRAC_FENCED_STATE_UNAVAILABLE); UT_ASSERT_EQ(transition.outcome, PGRAC_FENCED_OUTCOME_UNAVAILABLE); UT_ASSERT_EQ(transition.deny_reason, PGRAC_FENCED_DENY_PROTOCOL); UT_ASSERT(pgrac_fenced_fsm_step(PGRAC_FENCED_STATE_PROVEN_DURABLE, - PGRAC_FENCED_EVENT_PROOF_INVALIDATED, &transition)); + PGRAC_FENCED_EVENT_PROOF_INVALIDATED, &transition)); UT_ASSERT_EQ(transition.next_state, PGRAC_FENCED_STATE_INVALIDATED); UT_ASSERT_EQ(transition.outcome, PGRAC_FENCED_OUTCOME_NONE); UT_ASSERT_EQ(transition.journal_mask, PGRAC_FENCED_JOURNAL_INVALIDATED); UT_ASSERT(pgrac_fenced_fsm_step(PGRAC_FENCED_STATE_VERIFYING, - PGRAC_FENCED_EVENT_INTEGRITY_FAILURE, &transition)); + PGRAC_FENCED_EVENT_INTEGRITY_FAILURE, &transition)); UT_ASSERT_EQ(transition.next_state, PGRAC_FENCED_STATE_UNAVAILABLE); UT_ASSERT_EQ(transition.outcome, PGRAC_FENCED_OUTCOME_UNAVAILABLE); UT_ASSERT_EQ(transition.deny_reason, PGRAC_FENCED_DENY_JOURNAL); diff --git a/src/test/cluster_unit/test_pgrac_fenced_ctl.c b/src/test/cluster_unit/test_pgrac_fenced_ctl.c index 0f97bde87df..f1a888fc313 100644 --- a/src/test/cluster_unit/test_pgrac_fenced_ctl.c +++ b/src/test/cluster_unit/test_pgrac_fenced_ctl.c @@ -25,11 +25,9 @@ pfree(void *pointer) } void -ExceptionalCondition(const char *condition_name, const char *file_name, - int line_number) +ExceptionalCondition(const char *condition_name, const char *file_name, int line_number) { - printf("# Assert failed: %s at %s:%d\n", condition_name, file_name, - line_number); + printf("# Assert failed: %s at %s:%d\n", condition_name, file_name, line_number); abort(); } @@ -40,28 +38,24 @@ fill_nonzero(uint8 *bytes, size_t len, uint8 value) } static void -make_journal_record(PgracFencedJournalRecordV1 *record, uint64 seq, - uint8 marker) +make_journal_record(PgracFencedJournalRecordV1 *record, uint64 seq, uint8 marker) { memset(record, 0, sizeof(*record)); record->record_kind = PGRAC_FENCED_JOURNAL_KIND_CONFIG_LOADED; record->seq = seq; - fill_nonzero(record->daemon_boot_id, sizeof(record->daemon_boot_id), - marker); + fill_nonzero(record->daemon_boot_id, sizeof(record->daemon_boot_id), marker); record->provider_result = PGRAC_FENCED_JOURNAL_PROVIDER_UNAVAILABLE; record->event_mono_ns = seq + 100; - fill_nonzero(record->semantic_config_digest, - sizeof(record->semantic_config_digest), marker + 1); + fill_nonzero(record->semantic_config_digest, sizeof(record->semantic_config_digest), + marker + 1); } UT_TEST(test_prepare_rejoin_request_is_exact_admin_frame) { - PgracFencedCtlPrepareRejoinV1 request = { - .node_id = 7, - .old_incarnation = UINT64_C(0x100000001), - .candidate_incarnation = UINT64_C(0x100000002), - .timeout_ms = UINT32_C(120000) - }; + PgracFencedCtlPrepareRejoinV1 request = { .node_id = 7, + .old_incarnation = UINT64_C(0x100000001), + .candidate_incarnation = UINT64_C(0x100000002), + .timeout_ms = UINT32_C(120000) }; PgracExternalFenceProtocolRejoinFrameV1 decoded; uint8 nonce[PGRAC_EXTERNAL_FENCE_NONCE_V1_BYTES]; uint8 frame[PGRAC_EXTERNAL_FENCE_REJOIN_V1_BYTES]; @@ -69,34 +63,27 @@ UT_TEST(test_prepare_rejoin_request_is_exact_admin_frame) fill_nonzero(nonce, sizeof(nonce), 0x31); UT_ASSERT(pgrac_fenced_ctl_prepare_rejoin_frame(&request, nonce, frame)); - UT_ASSERT(pgrac_external_fence_rejoin_v1_decode(frame, sizeof(frame), - &decoded)); - UT_ASSERT_EQ(decoded.opcode, - PGRAC_EXTERNAL_FENCE_REJOIN_ADMIN_PREPARE); + UT_ASSERT(pgrac_external_fence_rejoin_v1_decode(frame, sizeof(frame), &decoded)); + UT_ASSERT_EQ(decoded.opcode, PGRAC_EXTERNAL_FENCE_REJOIN_ADMIN_PREPARE); UT_ASSERT(memcmp(decoded.transport_nonce, nonce, sizeof(nonce)) == 0); UT_ASSERT_EQ(decoded.old_node_id, request.node_id); UT_ASSERT_EQ(decoded.old_incarnation, request.old_incarnation); - UT_ASSERT_EQ(decoded.candidate_incarnation, - request.candidate_incarnation); + UT_ASSERT_EQ(decoded.candidate_incarnation, request.candidate_incarnation); UT_ASSERT_EQ(decoded.timeout_ms, request.timeout_ms); UT_ASSERT_EQ(decoded.status, 0); UT_ASSERT_EQ(decoded.deny_reason, 0); - UT_ASSERT(memcmp(decoded.rejoin_gate_digest, zero_digest, - sizeof(zero_digest)) == 0); - UT_ASSERT(memcmp(decoded.protected_set_digest, zero_digest, - sizeof(zero_digest)) == 0); + UT_ASSERT(memcmp(decoded.rejoin_gate_digest, zero_digest, sizeof(zero_digest)) == 0); + UT_ASSERT(memcmp(decoded.protected_set_digest, zero_digest, sizeof(zero_digest)) == 0); UT_ASSERT_EQ(decoded.provider_id, 0); UT_ASSERT_EQ(decoded.target_mapping_generation, 0); } UT_TEST(test_prepare_rejoin_rejects_invalid_tuple_timeout_and_nonce) { - PgracFencedCtlPrepareRejoinV1 request = { - .node_id = 1, - .old_incarnation = UINT64_C(70), - .candidate_incarnation = UINT64_C(71), - .timeout_ms = UINT32_C(120000) - }; + PgracFencedCtlPrepareRejoinV1 request = { .node_id = 1, + .old_incarnation = UINT64_C(70), + .candidate_incarnation = UINT64_C(71), + .timeout_ms = UINT32_C(120000) }; uint8 nonce[PGRAC_EXTERNAL_FENCE_NONCE_V1_BYTES]; uint8 frame[PGRAC_EXTERNAL_FENCE_REJOIN_V1_BYTES]; @@ -121,12 +108,10 @@ UT_TEST(test_prepare_rejoin_rejects_invalid_tuple_timeout_and_nonce) UT_TEST(test_prepare_rejoin_response_requires_exact_nonce_and_tuple) { - PgracFencedCtlPrepareRejoinV1 request = { - .node_id = 1, - .old_incarnation = UINT64_C(70), - .candidate_incarnation = UINT64_C(77), - .timeout_ms = UINT32_C(120000) - }; + PgracFencedCtlPrepareRejoinV1 request = { .node_id = 1, + .old_incarnation = UINT64_C(70), + .candidate_incarnation = UINT64_C(77), + .timeout_ms = UINT32_C(120000) }; PgracExternalFenceProtocolRejoinFrameV1 wire; PgracExternalFenceProtocolRejoinFrameV1 decoded; uint8 nonce[PGRAC_EXTERNAL_FENCE_NONCE_V1_BYTES]; @@ -142,28 +127,23 @@ UT_TEST(test_prepare_rejoin_response_requires_exact_nonce_and_tuple) wire.candidate_incarnation = request.candidate_incarnation; wire.status = 1; UT_ASSERT(pgrac_external_fence_rejoin_v1_encode(&wire, frame)); - UT_ASSERT(pgrac_fenced_ctl_prepare_rejoin_response(&request, nonce, - frame, &decoded)); + UT_ASSERT(pgrac_fenced_ctl_prepare_rejoin_response(&request, nonce, frame, &decoded)); UT_ASSERT_EQ(decoded.status, 1); frame[16] ^= UINT8_C(0x01); - UT_ASSERT(!pgrac_fenced_ctl_prepare_rejoin_response(&request, nonce, - frame, &decoded)); + UT_ASSERT(!pgrac_fenced_ctl_prepare_rejoin_response(&request, nonce, frame, &decoded)); frame[16] ^= UINT8_C(0x01); wire.candidate_incarnation++; UT_ASSERT(pgrac_external_fence_rejoin_v1_encode(&wire, frame)); - UT_ASSERT(!pgrac_fenced_ctl_prepare_rejoin_response(&request, nonce, - frame, &decoded)); + UT_ASSERT(!pgrac_fenced_ctl_prepare_rejoin_response(&request, nonce, frame, &decoded)); } UT_TEST(test_prepare_rejoin_closed_negative_is_protocol_valid) { - PgracFencedCtlPrepareRejoinV1 request = { - .node_id = 1, - .old_incarnation = UINT64_C(70), - .candidate_incarnation = UINT64_C(77), - .timeout_ms = UINT32_C(120000) - }; + PgracFencedCtlPrepareRejoinV1 request = { .node_id = 1, + .old_incarnation = UINT64_C(70), + .candidate_incarnation = UINT64_C(77), + .timeout_ms = UINT32_C(120000) }; PgracExternalFenceProtocolRejoinFrameV1 wire; PgracExternalFenceProtocolRejoinFrameV1 decoded; uint8 nonce[PGRAC_EXTERNAL_FENCE_NONCE_V1_BYTES]; @@ -180,8 +160,7 @@ UT_TEST(test_prepare_rejoin_closed_negative_is_protocol_valid) wire.status = 7; wire.deny_reason = 10; UT_ASSERT(pgrac_external_fence_rejoin_v1_encode(&wire, frame)); - UT_ASSERT(pgrac_fenced_ctl_prepare_rejoin_response(&request, nonce, - frame, &decoded)); + UT_ASSERT(pgrac_fenced_ctl_prepare_rejoin_response(&request, nonce, frame, &decoded)); UT_ASSERT_EQ(decoded.status, 7); UT_ASSERT_EQ(decoded.deny_reason, 10); } @@ -217,31 +196,25 @@ UT_TEST(test_verify_journal_accepts_non_genesis_segment_and_checks_chain) uint8 expected_tail[PGRAC_FENCED_JOURNAL_DIGEST_BYTES]; make_journal_record(&first, 41, 0x71); - fill_nonzero(first.previous_record_digest, - sizeof(first.previous_record_digest), 0x70); + fill_nonzero(first.previous_record_digest, sizeof(first.previous_record_digest), 0x70); UT_ASSERT(pgrac_fenced_journal_record_encode(&first, frames)); make_journal_record(&second, 42, 0x72); - UT_ASSERT(pgrac_fenced_journal_record_digest(frames, - second.previous_record_digest)); - UT_ASSERT(pgrac_fenced_journal_record_encode(&second, - frames + PGRAC_FENCED_JOURNAL_RECORD_BYTES)); - UT_ASSERT(pgrac_fenced_journal_record_digest( - frames + PGRAC_FENCED_JOURNAL_RECORD_BYTES, expected_tail)); + UT_ASSERT(pgrac_fenced_journal_record_digest(frames, second.previous_record_digest)); + UT_ASSERT( + pgrac_fenced_journal_record_encode(&second, frames + PGRAC_FENCED_JOURNAL_RECORD_BYTES)); + UT_ASSERT(pgrac_fenced_journal_record_digest(frames + PGRAC_FENCED_JOURNAL_RECORD_BYTES, + expected_tail)); - UT_ASSERT(pgrac_fenced_ctl_journal_scan(frames, sizeof(frames), - &summary)); + UT_ASSERT(pgrac_fenced_ctl_journal_scan(frames, sizeof(frames), &summary)); UT_ASSERT_EQ(summary.first_seq, 41); UT_ASSERT_EQ(summary.last_seq, 42); UT_ASSERT_EQ(summary.record_count, 2); - UT_ASSERT(memcmp(summary.tail_digest, expected_tail, - sizeof(expected_tail)) == 0); + UT_ASSERT(memcmp(summary.tail_digest, expected_tail, sizeof(expected_tail)) == 0); - memset(second.previous_record_digest, 0, - sizeof(second.previous_record_digest)); - UT_ASSERT(pgrac_fenced_journal_record_encode(&second, - frames + PGRAC_FENCED_JOURNAL_RECORD_BYTES)); - UT_ASSERT(!pgrac_fenced_ctl_journal_scan(frames, sizeof(frames), - &summary)); + memset(second.previous_record_digest, 0, sizeof(second.previous_record_digest)); + UT_ASSERT( + pgrac_fenced_journal_record_encode(&second, frames + PGRAC_FENCED_JOURNAL_RECORD_BYTES)); + UT_ASSERT(!pgrac_fenced_ctl_journal_scan(frames, sizeof(frames), &summary)); } int diff --git a/src/test/cluster_unit/test_pgrac_fenced_ipmi.c b/src/test/cluster_unit/test_pgrac_fenced_ipmi.c index 98598bab5a0..332307bf5f8 100644 --- a/src/test/cluster_unit/test_pgrac_fenced_ipmi.c +++ b/src/test/cluster_unit/test_pgrac_fenced_ipmi.c @@ -33,27 +33,24 @@ make_adapter(uint8 *bytes, uint16 address_family, const char *path) memset(bytes, 0, PGRAC_FENCED_IPMI_ADAPTER_MAX_BYTES); memcpy(bytes, PGRAC_FENCED_IPMI_ADAPTER_MAGIC, 4); bytes[4] = PGRAC_FENCED_IPMI_ADAPTER_VERSION; - bytes[6] = (uint8) total_len; - bytes[7] = (uint8) (total_len >> 8); - bytes[8] = (uint8) address_family; + bytes[6] = (uint8)total_len; + bytes[7] = (uint8)(total_len >> 8); + bytes[8] = (uint8)address_family; bytes[10] = UINT8_C(0x6f); bytes[11] = UINT8_C(0x02); - if (address_family == 4) - { + if (address_family == 4) { bytes[12] = 192; bytes[13] = 0; bytes[14] = 2; bytes[15] = 10; - } - else - { + } else { bytes[12] = 0x20; bytes[13] = 0x01; bytes[27] = 0x01; } bytes[28] = 17; - bytes[30] = (uint8) path_len; - bytes[31] = (uint8) (path_len >> 8); + bytes[30] = (uint8)path_len; + bytes[31] = (uint8)(path_len >> 8); memset(bytes + 32, 0x5a, 32); memcpy(bytes + PGRAC_FENCED_IPMI_ADAPTER_FIXED_BYTES, path, path_len); return total_len; @@ -102,8 +99,8 @@ UT_TEST(test_adapter_rejects_header_and_length_errors) bytes[30]--; UT_ASSERT(!pgrac_fenced_ipmi_adapter_parse(bytes, len, &adapter)); UT_ASSERT(!pgrac_fenced_ipmi_adapter_parse(bytes, 63, &adapter)); - UT_ASSERT(!pgrac_fenced_ipmi_adapter_parse(bytes, - PGRAC_FENCED_IPMI_ADAPTER_MAX_BYTES + 1, &adapter)); + UT_ASSERT( + !pgrac_fenced_ipmi_adapter_parse(bytes, PGRAC_FENCED_IPMI_ADAPTER_MAX_BYTES + 1, &adapter)); UT_ASSERT(!pgrac_fenced_ipmi_adapter_parse(NULL, len, &adapter)); UT_ASSERT(!pgrac_fenced_ipmi_adapter_parse(bytes, len, NULL)); } @@ -173,8 +170,7 @@ UT_TEST(test_adapter_accepts_maximum_canonical_path) path[PGRAC_FENCED_IPMI_ADAPTER_PATH_MAX] = '\0'; len = make_adapter(bytes, 6, path); UT_ASSERT(pgrac_fenced_ipmi_adapter_parse(bytes, len, &adapter)); - UT_ASSERT_EQ(adapter.executable_path_len, - PGRAC_FENCED_IPMI_ADAPTER_PATH_MAX); + UT_ASSERT_EQ(adapter.executable_path_len, PGRAC_FENCED_IPMI_ADAPTER_PATH_MAX); UT_ASSERT_STR_EQ(adapter.executable_path, path); } @@ -213,26 +209,17 @@ UT_TEST(test_credential_grammars_are_exact) static const uint8 user_ok[] = "admin-1\n"; static const uint8 password_ok[] = "s ecret!\n"; - UT_ASSERT(pgrac_fenced_ipmi_username_parse(user_ok, - sizeof(user_ok) - 1, username)); + UT_ASSERT(pgrac_fenced_ipmi_username_parse(user_ok, sizeof(user_ok) - 1, username)); UT_ASSERT_STR_EQ(username, "admin-1"); - UT_ASSERT(!pgrac_fenced_ipmi_username_parse((const uint8 *) " admin\n", - 7, username)); - UT_ASSERT(!pgrac_fenced_ipmi_username_parse((const uint8 *) "admin \n", - 7, username)); - UT_ASSERT(!pgrac_fenced_ipmi_username_parse((const uint8 *) "admin\r\n", - 7, username)); - UT_ASSERT(!pgrac_fenced_ipmi_username_parse((const uint8 *) "admin\nroot\n", - 11, username)); - UT_ASSERT(!pgrac_fenced_ipmi_username_parse((const uint8 *) "admin", 5, - username)); - UT_ASSERT(pgrac_fenced_ipmi_password_validate(password_ok, - sizeof(password_ok) - 1)); - UT_ASSERT(!pgrac_fenced_ipmi_password_validate((const uint8 *) "secret", 6)); - UT_ASSERT(!pgrac_fenced_ipmi_password_validate( - (const uint8 *) "secret\r\n", 8)); - UT_ASSERT(!pgrac_fenced_ipmi_password_validate( - (const uint8 *) "secret\nmore\n", 12)); + UT_ASSERT(!pgrac_fenced_ipmi_username_parse((const uint8 *)" admin\n", 7, username)); + UT_ASSERT(!pgrac_fenced_ipmi_username_parse((const uint8 *)"admin \n", 7, username)); + UT_ASSERT(!pgrac_fenced_ipmi_username_parse((const uint8 *)"admin\r\n", 7, username)); + UT_ASSERT(!pgrac_fenced_ipmi_username_parse((const uint8 *)"admin\nroot\n", 11, username)); + UT_ASSERT(!pgrac_fenced_ipmi_username_parse((const uint8 *)"admin", 5, username)); + UT_ASSERT(pgrac_fenced_ipmi_password_validate(password_ok, sizeof(password_ok) - 1)); + UT_ASSERT(!pgrac_fenced_ipmi_password_validate((const uint8 *)"secret", 6)); + UT_ASSERT(!pgrac_fenced_ipmi_password_validate((const uint8 *)"secret\r\n", 8)); + UT_ASSERT(!pgrac_fenced_ipmi_password_validate((const uint8 *)"secret\nmore\n", 12)); } UT_TEST(test_credential_paths_use_raw_uuid_lowercase_hex) @@ -243,16 +230,16 @@ UT_TEST(test_credential_paths_use_raw_uuid_lowercase_hex) size_t i; for (i = 0; i < sizeof(uuid); i++) - uuid[i] = (uint8) i; - UT_ASSERT(pgrac_fenced_ipmi_credential_paths(uuid, user_path, - sizeof(user_path), password_path, sizeof(password_path))); + uuid[i] = (uint8)i; + UT_ASSERT(pgrac_fenced_ipmi_credential_paths(uuid, user_path, sizeof(user_path), password_path, + sizeof(password_path))); UT_ASSERT_STR_EQ(user_path, - "/etc/pgrac/credentials/ipmi-000102030405060708090a0b0c0d0e0f.user"); + "/etc/pgrac/credentials/ipmi-000102030405060708090a0b0c0d0e0f.user"); UT_ASSERT_STR_EQ(password_path, - "/etc/pgrac/credentials/ipmi-000102030405060708090a0b0c0d0e0f.password"); + "/etc/pgrac/credentials/ipmi-000102030405060708090a0b0c0d0e0f.password"); memset(uuid, 0, sizeof(uuid)); - UT_ASSERT(!pgrac_fenced_ipmi_credential_paths(uuid, user_path, - sizeof(user_path), password_path, sizeof(password_path))); + UT_ASSERT(!pgrac_fenced_ipmi_credential_paths(uuid, user_path, sizeof(user_path), password_path, + sizeof(password_path))); } UT_TEST(test_executable_open_requires_fresh_matching_hash) @@ -268,13 +255,12 @@ UT_TEST(test_executable_open_requires_fresh_matching_hash) UT_ASSERT(source_fd >= 0); if (source_fd < 0) return; - UT_ASSERT(pgrac_fenced_ipmi_sha256_fd(source_fd, - adapter.executable_sha256)); - (void) close(source_fd); + UT_ASSERT(pgrac_fenced_ipmi_sha256_fd(source_fd, adapter.executable_sha256)); + (void)close(source_fd); validated_fd = pgrac_fenced_ipmi_executable_open(&adapter); UT_ASSERT(validated_fd >= 0); if (validated_fd >= 0) - (void) close(validated_fd); + (void)close(validated_fd); adapter.executable_sha256[0] ^= 1; UT_ASSERT_EQ(pgrac_fenced_ipmi_executable_open(&adapter), -1); } @@ -294,11 +280,9 @@ UT_TEST(test_executable_open_rejects_final_symlink) adapter.executable_path_len = strlen(path); source_fd = open("/usr/bin/true", O_RDONLY); UT_ASSERT(source_fd >= 0); - if (source_fd >= 0) - { - UT_ASSERT(pgrac_fenced_ipmi_sha256_fd(source_fd, - adapter.executable_sha256)); - (void) close(source_fd); + if (source_fd >= 0) { + UT_ASSERT(pgrac_fenced_ipmi_sha256_fd(source_fd, adapter.executable_sha256)); + (void)close(source_fd); } UT_ASSERT_EQ(pgrac_fenced_ipmi_executable_open(&adapter), -1); UT_ASSERT_EQ(unlink(path), 0); @@ -327,8 +311,8 @@ UT_TEST(test_invocation_uses_only_fixed_numeric_argv) len = make_adapter(bytes, 4, VALID_PATH); UT_ASSERT(pgrac_fenced_ipmi_adapter_parse(bytes, len, &adapter)); - UT_ASSERT(pgrac_fenced_ipmi_invocation_build(&adapter, "admin", - "/etc/pgrac/credentials/ipmi-00112233445566778899aabbccddeeff.password", + UT_ASSERT(pgrac_fenced_ipmi_invocation_build( + &adapter, "admin", "/etc/pgrac/credentials/ipmi-00112233445566778899aabbccddeeff.password", PGRAC_FENCED_IPMI_COMMAND_GUID, &invocation)); UT_ASSERT_EQ(invocation.argc, 16); UT_ASSERT_STR_EQ(invocation.argv[0], "ipmitool"); @@ -344,58 +328,53 @@ UT_TEST(test_invocation_uses_only_fixed_numeric_argv) UT_ASSERT_STR_EQ(invocation.argv[10], "admin"); UT_ASSERT_STR_EQ(invocation.argv[11], "-f"); UT_ASSERT_STR_EQ(invocation.argv[12], - "/etc/pgrac/credentials/ipmi-00112233445566778899aabbccddeeff.password"); + "/etc/pgrac/credentials/ipmi-00112233445566778899aabbccddeeff.password"); UT_ASSERT_STR_EQ(invocation.argv[13], "raw"); UT_ASSERT_STR_EQ(invocation.argv[14], "0x06"); UT_ASSERT_STR_EQ(invocation.argv[15], "0x37"); UT_ASSERT_NULL(invocation.argv[16]); - UT_ASSERT(pgrac_fenced_ipmi_invocation_build(&adapter, "admin", - "/etc/pgrac/credentials/ipmi-00112233445566778899aabbccddeeff.password", + UT_ASSERT(pgrac_fenced_ipmi_invocation_build( + &adapter, "admin", "/etc/pgrac/credentials/ipmi-00112233445566778899aabbccddeeff.password", PGRAC_FENCED_IPMI_COMMAND_OFF, &invocation)); UT_ASSERT_STR_EQ(invocation.argv[13], "chassis"); UT_ASSERT_STR_EQ(invocation.argv[14], "power"); UT_ASSERT_STR_EQ(invocation.argv[15], "off"); - UT_ASSERT(pgrac_fenced_ipmi_invocation_build(&adapter, "admin", - "/etc/pgrac/credentials/ipmi-00112233445566778899aabbccddeeff.password", + UT_ASSERT(pgrac_fenced_ipmi_invocation_build( + &adapter, "admin", "/etc/pgrac/credentials/ipmi-00112233445566778899aabbccddeeff.password", PGRAC_FENCED_IPMI_COMMAND_STATUS, &invocation)); UT_ASSERT_STR_EQ(invocation.argv[15], "status"); - UT_ASSERT(pgrac_fenced_ipmi_invocation_build(&adapter, "admin", - "/etc/pgrac/credentials/ipmi-00112233445566778899aabbccddeeff.password", + UT_ASSERT(pgrac_fenced_ipmi_invocation_build( + &adapter, "admin", "/etc/pgrac/credentials/ipmi-00112233445566778899aabbccddeeff.password", PGRAC_FENCED_IPMI_COMMAND_ON, &invocation)); UT_ASSERT_STR_EQ(invocation.argv[15], "on"); len = make_adapter(bytes, 6, VALID_PATH); UT_ASSERT(pgrac_fenced_ipmi_adapter_parse(bytes, len, &adapter)); - UT_ASSERT(pgrac_fenced_ipmi_invocation_build(&adapter, "admin", - "/etc/pgrac/credentials/ipmi-00112233445566778899aabbccddeeff.password", + UT_ASSERT(pgrac_fenced_ipmi_invocation_build( + &adapter, "admin", "/etc/pgrac/credentials/ipmi-00112233445566778899aabbccddeeff.password", PGRAC_FENCED_IPMI_COMMAND_STATUS, &invocation)); UT_ASSERT_STR_EQ(invocation.argv[4], "2001::1"); } UT_TEST(test_guid_result_parser_is_byte_exact) { - static const uint8 valid[] = - " 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f\n"; + static const uint8 valid[] = " 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f\n"; uint8 output[sizeof(valid)]; uint8 uuid[16]; size_t i; UT_ASSERT_EQ(sizeof(valid) - 1, 49); - UT_ASSERT(pgrac_fenced_ipmi_guid_result_parse(0, valid, - sizeof(valid) - 1, NULL, 0, uuid)); + UT_ASSERT(pgrac_fenced_ipmi_guid_result_parse(0, valid, sizeof(valid) - 1, NULL, 0, uuid)); for (i = 0; i < sizeof(uuid); i++) UT_ASSERT_EQ(uuid[i], i); memcpy(output, valid, sizeof(valid)); output[31] = 'A'; - UT_ASSERT(!pgrac_fenced_ipmi_guid_result_parse(0, output, - sizeof(valid) - 1, NULL, 0, uuid)); - UT_ASSERT(!pgrac_fenced_ipmi_guid_result_parse(1, valid, - sizeof(valid) - 1, NULL, 0, uuid)); - UT_ASSERT(!pgrac_fenced_ipmi_guid_result_parse(0, valid, - sizeof(valid) - 2, NULL, 0, uuid)); - UT_ASSERT(!pgrac_fenced_ipmi_guid_result_parse(0, valid, - sizeof(valid) - 1, (const uint8 *) "x", 1, uuid)); + UT_ASSERT(!pgrac_fenced_ipmi_guid_result_parse(0, output, sizeof(valid) - 1, NULL, 0, uuid)); + UT_ASSERT(!pgrac_fenced_ipmi_guid_result_parse(1, valid, sizeof(valid) - 1, NULL, 0, uuid)); + UT_ASSERT(!pgrac_fenced_ipmi_guid_result_parse(0, valid, sizeof(valid) - 2, NULL, 0, uuid)); + UT_ASSERT(!pgrac_fenced_ipmi_guid_result_parse(0, valid, sizeof(valid) - 1, (const uint8 *)"x", + 1, uuid)); } UT_TEST(test_power_and_action_results_are_byte_exact) @@ -406,25 +385,21 @@ UT_TEST(test_power_and_action_results_are_byte_exact) PgracFencedTargetState state = PGRAC_FENCED_TARGET_UNKNOWN; memset(action_output, 'x', sizeof(action_output)); - UT_ASSERT(pgrac_fenced_ipmi_power_result_parse(0, on, sizeof(on) - 1, - NULL, 0, &state)); + UT_ASSERT(pgrac_fenced_ipmi_power_result_parse(0, on, sizeof(on) - 1, NULL, 0, &state)); UT_ASSERT_EQ(state, PGRAC_FENCED_TARGET_ON); - UT_ASSERT(pgrac_fenced_ipmi_power_result_parse(0, off, sizeof(off) - 1, - NULL, 0, &state)); + UT_ASSERT(pgrac_fenced_ipmi_power_result_parse(0, off, sizeof(off) - 1, NULL, 0, &state)); UT_ASSERT_EQ(state, PGRAC_FENCED_TARGET_OFF); - UT_ASSERT(!pgrac_fenced_ipmi_power_result_parse(0, on, sizeof(on), - NULL, 0, &state)); - UT_ASSERT(!pgrac_fenced_ipmi_power_result_parse(0, - (const uint8 *) "Chassis Power is unknown\n", 25, NULL, 0, &state)); + UT_ASSERT(!pgrac_fenced_ipmi_power_result_parse(0, on, sizeof(on), NULL, 0, &state)); + UT_ASSERT(!pgrac_fenced_ipmi_power_result_parse(0, (const uint8 *)"Chassis Power is unknown\n", + 25, NULL, 0, &state)); UT_ASSERT(!pgrac_fenced_ipmi_power_result_parse(0, off, sizeof(off) - 1, - (const uint8 *) "warning\n", 8, &state)); - UT_ASSERT(pgrac_fenced_ipmi_action_result_validate(0, action_output, - PGRAC_FENCED_IPMI_ACTION_OUTPUT_MAX, NULL, 0)); - UT_ASSERT(!pgrac_fenced_ipmi_action_result_validate(0, action_output, - PGRAC_FENCED_IPMI_ACTION_OUTPUT_MAX + 1, NULL, 0)); + (const uint8 *)"warning\n", 8, &state)); + UT_ASSERT(pgrac_fenced_ipmi_action_result_validate( + 0, action_output, PGRAC_FENCED_IPMI_ACTION_OUTPUT_MAX, NULL, 0)); + UT_ASSERT(!pgrac_fenced_ipmi_action_result_validate( + 0, action_output, PGRAC_FENCED_IPMI_ACTION_OUTPUT_MAX + 1, NULL, 0)); UT_ASSERT(!pgrac_fenced_ipmi_action_result_validate(1, NULL, 0, NULL, 0)); - UT_ASSERT(!pgrac_fenced_ipmi_action_result_validate(0, NULL, 0, - (const uint8 *) "warning\n", 8)); + UT_ASSERT(!pgrac_fenced_ipmi_action_result_validate(0, NULL, 0, (const uint8 *)"warning\n", 8)); } UT_TEST(test_uncertified_readback_never_claims_io_drained) @@ -433,17 +408,15 @@ UT_TEST(test_uncertified_readback_never_claims_io_drained) uint8 uuid[16]; memset(uuid, 0x42, sizeof(uuid)); - UT_ASSERT(pgrac_fenced_ipmi_uncertified_readback(uuid, - PGRAC_FENCED_TARGET_OFF, &readback)); + UT_ASSERT(pgrac_fenced_ipmi_uncertified_readback(uuid, PGRAC_FENCED_TARGET_OFF, &readback)); UT_ASSERT_EQ(readback.state, PGRAC_FENCED_TARGET_OFF); UT_ASSERT_EQ(readback.io_drain_state, PGRAC_FENCED_IO_DRAIN_UNKNOWN); UT_ASSERT(memcmp(readback.observed_target_uuid, uuid, sizeof(uuid)) == 0); - UT_ASSERT(pgrac_fenced_ipmi_uncertified_readback(uuid, - PGRAC_FENCED_TARGET_ON, &readback)); + UT_ASSERT(pgrac_fenced_ipmi_uncertified_readback(uuid, PGRAC_FENCED_TARGET_ON, &readback)); UT_ASSERT_EQ(readback.state, PGRAC_FENCED_TARGET_ON); UT_ASSERT_EQ(readback.io_drain_state, PGRAC_FENCED_IO_DRAIN_UNKNOWN); - UT_ASSERT(!pgrac_fenced_ipmi_uncertified_readback(uuid, - PGRAC_FENCED_TARGET_UNKNOWN, &readback)); + UT_ASSERT( + !pgrac_fenced_ipmi_uncertified_readback(uuid, PGRAC_FENCED_TARGET_UNKNOWN, &readback)); } int diff --git a/src/test/cluster_unit/test_pgrac_fenced_ipmi_exec.c b/src/test/cluster_unit/test_pgrac_fenced_ipmi_exec.c index 2e106dd6442..094f11aef66 100644 --- a/src/test/cluster_unit/test_pgrac_fenced_ipmi_exec.c +++ b/src/test/cluster_unit/test_pgrac_fenced_ipmi_exec.c @@ -25,12 +25,11 @@ UT_DEFINE_GLOBALS(); int fexecve(int fd, char *const argv[], char *const envp[]); -static const char password_path[] = - "/etc/pgrac/credentials/ipmi-00112233445566778899aabbccddeeff.password"; +static const char password_path[] + = "/etc/pgrac/credentials/ipmi-00112233445566778899aabbccddeeff.password"; static int descendant_pid_fd = -1; -typedef struct ProcessTreePids -{ +typedef struct ProcessTreePids { pid_t worker; pid_t command; pid_t descendant; @@ -38,44 +37,42 @@ typedef struct ProcessTreePids } ProcessTreePids; static bool +/* The array has the exact execve environment ABI, not a const-pointee API. */ +/* cppcheck-suppress constParameter */ exec_environment_exact(char *const envp[]) { - return envp != NULL && envp[0] != NULL && envp[1] != NULL && - envp[2] == NULL && strcmp(envp[0], "LC_ALL=C") == 0 && - strcmp(envp[1], "LANG=C") == 0; + return envp != NULL && envp[0] != NULL && envp[1] != NULL && envp[2] == NULL + && strcmp(envp[0], "LC_ALL=C") == 0 && strcmp(envp[1], "LANG=C") == 0; } int +/* This fixture interposes libc fexecve and must keep its exact prototype. */ +/* cppcheck-suppress constParameter */ fexecve(int fd, char *const argv[], char *const envp[]) { - static const char guid[] = - " 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f\n"; + static const char guid[] = " 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f\n"; static const char status[] = "Chassis Power is off\n"; - char overflow[PGRAC_FENCED_IPMI_ACTION_OUTPUT_MAX + 1]; - if (fd < 0 || argv == NULL || - !exec_environment_exact(envp) || - strcmp(argv[0], "ipmitool") != 0 || argv[16] != NULL) + if (fd < 0 || argv == NULL || !exec_environment_exact(envp) || strcmp(argv[0], "ipmitool") != 0 + || argv[16] != NULL) _exit(90); - if (strcmp(argv[10], "worker-tree") == 0) - { + if (strcmp(argv[10], "worker-tree") == 0) { pid_t command = getpid(); pid_t worker = getppid(); pid_t child = fork(); if (child < 0) _exit(91); - if (child == 0) - { + if (child == 0) { ProcessTreePids pids; - (void) signal(SIGTERM, SIG_IGN); + (void)signal(SIGTERM, SIG_IGN); pids.worker = worker; pids.command = command; pids.descendant = getpid(); pids.process_group = getpgrp(); - if (descendant_pid_fd < 0 || - write(descendant_pid_fd, &pids, sizeof(pids)) != sizeof(pids)) + if (descendant_pid_fd < 0 + || write(descendant_pid_fd, &pids, sizeof(pids)) != sizeof(pids)) _exit(92); for (;;) pause(); @@ -85,24 +82,21 @@ fexecve(int fd, char *const argv[], char *const envp[]) } if (getpgrp() != getpid()) _exit(90); - if (strcmp(argv[10], "slow") == 0) - { + if (strcmp(argv[10], "slow") == 0) { for (;;) pause(); } - if (strcmp(argv[10], "tree") == 0) - { + if (strcmp(argv[10], "tree") == 0) { pid_t child = fork(); if (child < 0) _exit(91); - if (child == 0) - { + if (child == 0) { pid_t self = getpid(); - (void) signal(SIGTERM, SIG_IGN); - if (descendant_pid_fd < 0 || - write(descendant_pid_fd, &self, sizeof(self)) != sizeof(self)) + (void)signal(SIGTERM, SIG_IGN); + if (descendant_pid_fd < 0 + || write(descendant_pid_fd, &self, sizeof(self)) != sizeof(self)) _exit(92); for (;;) pause(); @@ -112,23 +106,23 @@ fexecve(int fd, char *const argv[], char *const envp[]) } if (strcmp(argv[10], "fail") == 0) _exit(7); - if (strcmp(argv[10], "stderr") == 0) - { - (void) write(STDERR_FILENO, "warning\n", 8); + if (strcmp(argv[10], "stderr") == 0) { + (void)write(STDERR_FILENO, "warning\n", 8); _exit(0); } - if (strcmp(argv[10], "overflow") == 0) - { + if (strcmp(argv[10], "overflow") == 0) { + char overflow[PGRAC_FENCED_IPMI_ACTION_OUTPUT_MAX + 1]; + memset(overflow, 'x', sizeof(overflow)); - (void) write(STDOUT_FILENO, overflow, sizeof(overflow)); + (void)write(STDOUT_FILENO, overflow, sizeof(overflow)); _exit(0); } if (strcmp(argv[15], "0x37") == 0) - (void) write(STDOUT_FILENO, guid, sizeof(guid) - 1); + (void)write(STDOUT_FILENO, guid, sizeof(guid) - 1); else if (strcmp(argv[15], "status") == 0) - (void) write(STDOUT_FILENO, status, sizeof(status) - 1); + (void)write(STDOUT_FILENO, status, sizeof(status) - 1); else - (void) write(STDOUT_FILENO, "action\n", 7); + (void)write(STDOUT_FILENO, "action\n", 7); _exit(0); } @@ -138,8 +132,8 @@ deadline_after_ms(uint64 milliseconds) struct timespec now; UT_ASSERT_EQ(clock_gettime(CLOCK_MONOTONIC, &now), 0); - return (uint64) now.tv_sec * UINT64_C(1000000000) + - (uint64) now.tv_nsec + milliseconds * UINT64_C(1000000); + return (uint64)now.tv_sec * UINT64_C(1000000000) + (uint64)now.tv_nsec + + milliseconds * UINT64_C(1000000); } static void @@ -155,8 +149,8 @@ make_adapter(PgracFencedIpmiAdapterV1 *adapter) } static PgracFencedProviderResult -nested_test_resolve(const PgracFencedTargetV1 *configured, - PgracFencedTargetV1 *resolved, int32 *native_status) +nested_test_resolve(const PgracFencedTargetV1 *configured, PgracFencedTargetV1 *resolved, + int32 *native_status) { *resolved = *configured; *native_status = 0; @@ -164,8 +158,8 @@ nested_test_resolve(const PgracFencedTargetV1 *configured, } static PgracFencedProviderResult -nested_test_actuate(const PgracFencedTargetV1 *target, - uint64_t deadline_mono_ns, int32 *native_status) +nested_test_actuate(const PgracFencedTargetV1 *target, uint64_t deadline_mono_ns, + int32 *native_status) { PgracFencedIpmiAdapterV1 adapter; PgracFencedIpmiCommandOutputV1 output; @@ -173,35 +167,33 @@ nested_test_actuate(const PgracFencedTargetV1 *target, int fd; bool ok; - (void) target; + (void)target; *native_status = 0; make_adapter(&adapter); - if (!pgrac_fenced_ipmi_invocation_build(&adapter, "worker-tree", - password_path, PGRAC_FENCED_IPMI_COMMAND_OFF, &invocation)) + if (!pgrac_fenced_ipmi_invocation_build(&adapter, "worker-tree", password_path, + PGRAC_FENCED_IPMI_COMMAND_OFF, &invocation)) return PGRAC_FENCED_PROVIDER_CONFIG_ERROR; fd = open("/usr/bin/true", O_RDONLY); if (fd < 0) return PGRAC_FENCED_PROVIDER_CONFIG_ERROR; - ok = pgrac_fenced_ipmi_command_run_fd(fd, &invocation, - deadline_mono_ns, &output); - (void) close(fd); + ok = pgrac_fenced_ipmi_command_run_fd(fd, &invocation, deadline_mono_ns, &output); + (void)close(fd); return ok ? PGRAC_FENCED_PROVIDER_OK : PGRAC_FENCED_PROVIDER_UNKNOWN; } static PgracFencedProviderResult -nested_test_readback(const PgracFencedTargetV1 *target, - uint64_t deadline_mono_ns, PgracFencedReadbackV1 *out) +nested_test_readback(const PgracFencedTargetV1 *target, uint64_t deadline_mono_ns, + PgracFencedReadbackV1 *out) { - (void) target; - (void) deadline_mono_ns; + (void)target; + (void)deadline_mono_ns; memset(out, 0, sizeof(*out)); return PGRAC_FENCED_PROVIDER_UNKNOWN; } static void nested_test_shutdown(void) -{ -} +{} static void make_nested_test_ops(PgracFencedProviderOpsV1 *ops) @@ -219,8 +211,8 @@ make_nested_test_ops(PgracFencedProviderOpsV1 *ops) } static bool -run_command(const char *username, PgracFencedIpmiCommand command, - uint64 timeout_ms, PgracFencedIpmiCommandOutputV1 *output) +run_command(const char *username, PgracFencedIpmiCommand command, uint64 timeout_ms, + PgracFencedIpmiCommandOutputV1 *output) { PgracFencedIpmiAdapterV1 adapter; PgracFencedIpmiInvocationV1 invocation; @@ -228,15 +220,14 @@ run_command(const char *username, PgracFencedIpmiCommand command, bool ok; make_adapter(&adapter); - UT_ASSERT(pgrac_fenced_ipmi_invocation_build(&adapter, username, - password_path, command, &invocation)); + UT_ASSERT(pgrac_fenced_ipmi_invocation_build(&adapter, username, password_path, command, + &invocation)); fd = open("/usr/bin/true", O_RDONLY); UT_ASSERT(fd >= 0); if (fd < 0) return false; - ok = pgrac_fenced_ipmi_command_run_fd(fd, &invocation, - deadline_after_ms(timeout_ms), output); - (void) close(fd); + ok = pgrac_fenced_ipmi_command_run_fd(fd, &invocation, deadline_after_ms(timeout_ms), output); + (void)close(fd); return ok; } @@ -245,11 +236,10 @@ process_gone(pid_t pid) { int attempts; - for (attempts = 0; attempts < 100; attempts++) - { + for (attempts = 0; attempts < 100; attempts++) { if (kill(pid, 0) != 0 && errno == ESRCH) return true; - (void) usleep(10000); + (void)usleep(10000); } return false; } @@ -264,8 +254,8 @@ make_target_adapter(uint8 *bytes) memset(bytes, 0, PGRAC_FENCED_IPMI_ADAPTER_MAX_BYTES); memcpy(bytes, PGRAC_FENCED_IPMI_ADAPTER_MAGIC, 4); bytes[4] = PGRAC_FENCED_IPMI_ADAPTER_VERSION; - bytes[6] = (uint8) total_len; - bytes[7] = (uint8) (total_len >> 8); + bytes[6] = (uint8)total_len; + bytes[7] = (uint8)(total_len >> 8); bytes[8] = 4; bytes[10] = 0x6f; bytes[11] = 0x02; @@ -273,7 +263,7 @@ make_target_adapter(uint8 *bytes) bytes[14] = 2; bytes[15] = 10; bytes[28] = 17; - bytes[30] = (uint8) path_len; + bytes[30] = (uint8)path_len; memset(bytes + 32, 0x5a, 32); memcpy(bytes + PGRAC_FENCED_IPMI_ADAPTER_FIXED_BYTES, path, path_len); return total_len; @@ -286,10 +276,9 @@ make_exact_target_adapter(uint8 *bytes) int fd = open("/usr/bin/true", O_RDONLY); UT_ASSERT(fd >= 0); - if (fd >= 0) - { + if (fd >= 0) { UT_ASSERT(pgrac_fenced_ipmi_sha256_fd(fd, bytes + 32)); - (void) close(fd); + (void)close(fd); } return len; } @@ -299,13 +288,12 @@ UT_TEST(test_runner_uses_fexecve_and_sanitized_environment) PgracFencedIpmiCommandOutputV1 output; uint8 uuid[16]; - UT_ASSERT(run_command("admin", PGRAC_FENCED_IPMI_COMMAND_GUID, 1000, - &output)); + UT_ASSERT(run_command("admin", PGRAC_FENCED_IPMI_COMMAND_GUID, 1000, &output)); UT_ASSERT_EQ(output.exit_code, 0); UT_ASSERT_EQ(output.stderr_len, 0); - UT_ASSERT(pgrac_fenced_ipmi_guid_result_parse(output.exit_code, - output.stdout_bytes, output.stdout_len, output.stderr_bytes, - output.stderr_len, uuid)); + UT_ASSERT(pgrac_fenced_ipmi_guid_result_parse(output.exit_code, output.stdout_bytes, + output.stdout_len, output.stderr_bytes, + output.stderr_len, uuid)); UT_ASSERT_EQ(uuid[15], 15); } @@ -313,29 +301,25 @@ UT_TEST(test_runner_preserves_nonzero_and_stderr_for_strict_parser) { PgracFencedIpmiCommandOutputV1 output; - UT_ASSERT(run_command("fail", PGRAC_FENCED_IPMI_COMMAND_OFF, 1000, - &output)); + UT_ASSERT(run_command("fail", PGRAC_FENCED_IPMI_COMMAND_OFF, 1000, &output)); UT_ASSERT_EQ(output.exit_code, 7); - UT_ASSERT(!pgrac_fenced_ipmi_action_result_validate(output.exit_code, - output.stdout_bytes, output.stdout_len, output.stderr_bytes, - output.stderr_len)); - UT_ASSERT(run_command("stderr", PGRAC_FENCED_IPMI_COMMAND_OFF, 1000, - &output)); + UT_ASSERT(!pgrac_fenced_ipmi_action_result_validate(output.exit_code, output.stdout_bytes, + output.stdout_len, output.stderr_bytes, + output.stderr_len)); + UT_ASSERT(run_command("stderr", PGRAC_FENCED_IPMI_COMMAND_OFF, 1000, &output)); UT_ASSERT_EQ(output.exit_code, 0); UT_ASSERT_EQ(output.stderr_len, 8); - UT_ASSERT(!pgrac_fenced_ipmi_action_result_validate(output.exit_code, - output.stdout_bytes, output.stdout_len, output.stderr_bytes, - output.stderr_len)); + UT_ASSERT(!pgrac_fenced_ipmi_action_result_validate(output.exit_code, output.stdout_bytes, + output.stdout_len, output.stderr_bytes, + output.stderr_len)); } UT_TEST(test_runner_rejects_overflow_and_deadline) { PgracFencedIpmiCommandOutputV1 output; - UT_ASSERT(!run_command("overflow", PGRAC_FENCED_IPMI_COMMAND_OFF, 1000, - &output)); - UT_ASSERT(!run_command("slow", PGRAC_FENCED_IPMI_COMMAND_OFF, 20, - &output)); + UT_ASSERT(!run_command("overflow", PGRAC_FENCED_IPMI_COMMAND_OFF, 1000, &output)); + UT_ASSERT(!run_command("slow", PGRAC_FENCED_IPMI_COMMAND_OFF, 20, &output)); } UT_TEST(test_runner_deadline_drains_descendant_process_group) @@ -352,21 +336,19 @@ UT_TEST(test_runner_deadline_drains_descendant_process_group) if (pipe_rc != 0) return; descendant_pid_fd = pid_pipe[1]; - UT_ASSERT(!run_command("tree", PGRAC_FENCED_IPMI_COMMAND_OFF, 20, - &output)); - (void) close(pid_pipe[1]); + UT_ASSERT(!run_command("tree", PGRAC_FENCED_IPMI_COMMAND_OFF, 20, &output)); + (void)close(pid_pipe[1]); descendant_pid_fd = -1; - do - { + do { got = read(pid_pipe[0], &descendant, sizeof(descendant)); } while (got < 0 && errno == EINTR); - (void) close(pid_pipe[0]); + (void)close(pid_pipe[0]); UT_ASSERT_EQ(got, sizeof(descendant)); if (got != sizeof(descendant)) return; gone = process_gone(descendant); if (!gone) - (void) kill(descendant, SIGKILL); + (void)kill(descendant, SIGKILL); UT_ASSERT(gone); } @@ -394,22 +376,21 @@ UT_TEST(test_provider_deadline_owns_nested_command_descendants) return; descendant_pid_fd = pid_pipe[1]; UT_ASSERT_EQ(pgrac_fenced_provider_worker_actuate( - &ops, true, false, &target, deadline_after_ms(20), &result, - &native_status), PGRAC_FENCED_PROVIDER_WORKER_TIMEOUT); - (void) close(pid_pipe[1]); + &ops, true, false, &target, deadline_after_ms(20), &result, &native_status), + PGRAC_FENCED_PROVIDER_WORKER_TIMEOUT); + (void)close(pid_pipe[1]); descendant_pid_fd = -1; - do - { + do { got = read(pid_pipe[0], &pids, sizeof(pids)); } while (got < 0 && errno == EINTR); - (void) close(pid_pipe[0]); + (void)close(pid_pipe[0]); UT_ASSERT_EQ(got, sizeof(pids)); if (got != sizeof(pids)) return; command_gone = process_gone(pids.command); descendant_gone = process_gone(pids.descendant); if (!command_gone || !descendant_gone) - (void) kill(-pids.process_group, SIGKILL); + (void)kill(-pids.process_group, SIGKILL); UT_ASSERT_EQ(pids.process_group, pids.worker); UT_ASSERT(command_gone); UT_ASSERT(descendant_gone); @@ -430,7 +411,7 @@ UT_TEST(test_provider_callbacks_fail_closed_before_any_command) return; memset(&configured, 0, sizeof(configured)); for (i = 0; i < sizeof(configured.target_uuid); i++) - configured.target_uuid[i] = (uint8) i; + configured.target_uuid[i] = (uint8)i; configured.target_uuid[0] = 1; configured.victim_node_id = 2; configured.mapping_generation = 9; @@ -438,13 +419,13 @@ UT_TEST(test_provider_callbacks_fail_closed_before_any_command) configured.adapter_config_len = make_target_adapter(adapter); memset(&resolved, 0x7f, sizeof(resolved)); UT_ASSERT_EQ(ops->resolve(&configured, &resolved, &native_status), - PGRAC_FENCED_PROVIDER_CONFIG_ERROR); + PGRAC_FENCED_PROVIDER_CONFIG_ERROR); UT_ASSERT_EQ(resolved.mapping_generation, 0); - UT_ASSERT_EQ(ops->actuate_off(&configured, deadline_after_ms(1000), - &native_status), PGRAC_FENCED_PROVIDER_CONFIG_ERROR); + UT_ASSERT_EQ(ops->actuate_off(&configured, deadline_after_ms(1000), &native_status), + PGRAC_FENCED_PROVIDER_CONFIG_ERROR); memset(&readback, 0x7f, sizeof(readback)); - UT_ASSERT_EQ(ops->readback(&configured, deadline_after_ms(1000), - &readback), PGRAC_FENCED_PROVIDER_CONFIG_ERROR); + UT_ASSERT_EQ(ops->readback(&configured, deadline_after_ms(1000), &readback), + PGRAC_FENCED_PROVIDER_CONFIG_ERROR); UT_ASSERT_EQ(readback.state, 0); } @@ -461,30 +442,30 @@ UT_TEST(test_result_folding_requires_fresh_guid_before_status) memset(&configured, 0, sizeof(configured)); for (i = 0; i < sizeof(configured.target_uuid); i++) - configured.target_uuid[i] = (uint8) i; + configured.target_uuid[i] = (uint8)i; configured.victim_node_id = 3; configured.mapping_generation = 11; - UT_ASSERT(run_command("admin", PGRAC_FENCED_IPMI_COMMAND_GUID, 1000, - &guid_output)); - UT_ASSERT_EQ(pgrac_fenced_ipmi_resolve_result(&configured, &guid_output, - &resolved, &native_status), PGRAC_FENCED_PROVIDER_OK); + UT_ASSERT(run_command("admin", PGRAC_FENCED_IPMI_COMMAND_GUID, 1000, &guid_output)); + UT_ASSERT_EQ( + pgrac_fenced_ipmi_resolve_result(&configured, &guid_output, &resolved, &native_status), + PGRAC_FENCED_PROVIDER_OK); UT_ASSERT_EQ(resolved.victim_node_id, configured.victim_node_id); UT_ASSERT_EQ(resolved.mapping_generation, configured.mapping_generation); UT_ASSERT(memcmp(resolved.target_uuid, configured.target_uuid, 16) == 0); - UT_ASSERT(run_command("admin", PGRAC_FENCED_IPMI_COMMAND_STATUS, 1000, - &status_output)); - UT_ASSERT_EQ(pgrac_fenced_ipmi_readback_results(&configured, &guid_output, - &status_output, &readback), PGRAC_FENCED_PROVIDER_OK); + UT_ASSERT(run_command("admin", PGRAC_FENCED_IPMI_COMMAND_STATUS, 1000, &status_output)); + UT_ASSERT_EQ( + pgrac_fenced_ipmi_readback_results(&configured, &guid_output, &status_output, &readback), + PGRAC_FENCED_PROVIDER_OK); UT_ASSERT_EQ(readback.state, PGRAC_FENCED_TARGET_OFF); UT_ASSERT_EQ(readback.io_drain_state, PGRAC_FENCED_IO_DRAIN_UNKNOWN); guid_output.stdout_bytes[2] = '1'; - UT_ASSERT_EQ(pgrac_fenced_ipmi_readback_results(&configured, &guid_output, - &status_output, &readback), PGRAC_FENCED_PROVIDER_UNKNOWN); + UT_ASSERT_EQ( + pgrac_fenced_ipmi_readback_results(&configured, &guid_output, &status_output, &readback), + PGRAC_FENCED_PROVIDER_UNKNOWN); UT_ASSERT_EQ(readback.state, 0); - UT_ASSERT(run_command("admin", PGRAC_FENCED_IPMI_COMMAND_OFF, 1000, - &action_output)); - UT_ASSERT_EQ(pgrac_fenced_ipmi_action_result(&action_output, - &native_status), PGRAC_FENCED_PROVIDER_OK); + UT_ASSERT(run_command("admin", PGRAC_FENCED_IPMI_COMMAND_OFF, 1000, &action_output)); + UT_ASSERT_EQ(pgrac_fenced_ipmi_action_result(&action_output, &native_status), + PGRAC_FENCED_PROVIDER_OK); UT_ASSERT_EQ(native_status, 0); } @@ -497,24 +478,28 @@ UT_TEST(test_prevalidated_execution_rehashes_each_command) memset(&target, 0, sizeof(target)); for (i = 0; i < sizeof(target.target_uuid); i++) - target.target_uuid[i] = (uint8) i; + target.target_uuid[i] = (uint8)i; target.victim_node_id = 4; target.mapping_generation = 12; target.adapter_config = adapter; target.adapter_config_len = make_exact_target_adapter(adapter); - UT_ASSERT_EQ(pgrac_fenced_ipmi_execute_prevalidated(&target, "admin", - password_path, PGRAC_FENCED_IPMI_COMMAND_GUID, - deadline_after_ms(1000), &output), PGRAC_FENCED_PROVIDER_OK); + UT_ASSERT_EQ(pgrac_fenced_ipmi_execute_prevalidated(&target, "admin", password_path, + PGRAC_FENCED_IPMI_COMMAND_GUID, + deadline_after_ms(1000), &output), + PGRAC_FENCED_PROVIDER_OK); UT_ASSERT_EQ(output.stdout_len, 49); - UT_ASSERT_EQ(pgrac_fenced_ipmi_execute_prevalidated(&target, "admin", - password_path, PGRAC_FENCED_IPMI_COMMAND_STATUS, - deadline_after_ms(1000), &output), PGRAC_FENCED_PROVIDER_OK); + UT_ASSERT_EQ(pgrac_fenced_ipmi_execute_prevalidated(&target, "admin", password_path, + PGRAC_FENCED_IPMI_COMMAND_STATUS, + deadline_after_ms(1000), &output), + PGRAC_FENCED_PROVIDER_OK); UT_ASSERT_EQ(output.stdout_len, sizeof("Chassis Power is off\n") - 1); + /* Consumed through target.adapter_config by the external runner below. */ + /* cppcheck-suppress unreadVariable */ adapter[32] ^= 1; - UT_ASSERT_EQ(pgrac_fenced_ipmi_execute_prevalidated(&target, "admin", - password_path, PGRAC_FENCED_IPMI_COMMAND_OFF, - deadline_after_ms(1000), &output), - PGRAC_FENCED_PROVIDER_CONFIG_ERROR); + UT_ASSERT_EQ(pgrac_fenced_ipmi_execute_prevalidated(&target, "admin", password_path, + PGRAC_FENCED_IPMI_COMMAND_OFF, + deadline_after_ms(1000), &output), + PGRAC_FENCED_PROVIDER_CONFIG_ERROR); } int diff --git a/src/test/cluster_unit/test_pgrac_fenced_journal.c b/src/test/cluster_unit/test_pgrac_fenced_journal.c index f5f32147c4c..e877639a1d9 100644 --- a/src/test/cluster_unit/test_pgrac_fenced_journal.c +++ b/src/test/cluster_unit/test_pgrac_fenced_journal.c @@ -36,11 +36,9 @@ pfree(void *pointer) } void -ExceptionalCondition(const char *condition_name, const char *file_name, - int line_number) +ExceptionalCondition(const char *condition_name, const char *file_name, int line_number) { - printf("# Assert failed: %s at %s:%d\n", condition_name, file_name, - line_number); + printf("# Assert failed: %s at %s:%d\n", condition_name, file_name, line_number); abort(); } @@ -59,8 +57,7 @@ make_config_record(PgracFencedJournalRecordV1 *record, uint64 seq) fill_nonzero(record->daemon_boot_id, sizeof(record->daemon_boot_id), 0x11); record->event_mono_ns = 100; record->provider_result = PGRAC_FENCED_JOURNAL_PROVIDER_UNAVAILABLE; - fill_nonzero(record->semantic_config_digest, - sizeof(record->semantic_config_digest), 0x22); + fill_nonzero(record->semantic_config_digest, sizeof(record->semantic_config_digest), 0x22); } UT_TEST(test_journal_exact_codec_roundtrip) @@ -79,15 +76,14 @@ UT_TEST(test_journal_exact_codec_roundtrip) UT_ASSERT_EQ(frame[249], 'F'); UT_ASSERT_EQ(frame[250], 'G'); UT_ASSERT_EQ(frame[251], 'Z'); - UT_ASSERT(pgrac_fenced_journal_record_decode(frame, sizeof(frame), - &decoded)); + UT_ASSERT(pgrac_fenced_journal_record_decode(frame, sizeof(frame), &decoded)); UT_ASSERT_EQ(decoded.record_kind, record.record_kind); UT_ASSERT_EQ(decoded.seq, record.seq); - UT_ASSERT(memcmp(decoded.daemon_boot_id, record.daemon_boot_id, - sizeof(record.daemon_boot_id)) == 0); - UT_ASSERT(memcmp(decoded.semantic_config_digest, - record.semantic_config_digest, - sizeof(record.semantic_config_digest)) == 0); + UT_ASSERT(memcmp(decoded.daemon_boot_id, record.daemon_boot_id, sizeof(record.daemon_boot_id)) + == 0); + UT_ASSERT(memcmp(decoded.semantic_config_digest, record.semantic_config_digest, + sizeof(record.semantic_config_digest)) + == 0); } UT_TEST(test_journal_rejects_crc_reserved_unknown_and_bad_proof) @@ -98,8 +94,7 @@ UT_TEST(test_journal_rejects_crc_reserved_unknown_and_bad_proof) make_config_record(&record, 1); UT_ASSERT(pgrac_fenced_journal_record_encode(&record, frame)); frame[240] = 1; - UT_ASSERT(!pgrac_fenced_journal_record_decode(frame, sizeof(frame), - &record)); + UT_ASSERT(!pgrac_fenced_journal_record_decode(frame, sizeof(frame), &record)); make_config_record(&record, 1); record.record_kind = 11; @@ -123,22 +118,21 @@ UT_TEST(test_journal_scan_verifies_seq_and_full_record_hash_chain) make_config_record(&second, 2); second.record_kind = PGRAC_FENCED_JOURNAL_KIND_REQUEST_ACCEPTED; fill_nonzero(second.operation_id, sizeof(second.operation_id), 0x44); - UT_ASSERT(pgrac_fenced_journal_record_digest(frames, - second.previous_record_digest)); - UT_ASSERT(pgrac_fenced_journal_record_encode(&second, - frames + PGRAC_FENCED_JOURNAL_RECORD_BYTES)); + UT_ASSERT(pgrac_fenced_journal_record_digest(frames, second.previous_record_digest)); + UT_ASSERT( + pgrac_fenced_journal_record_encode(&second, frames + PGRAC_FENCED_JOURNAL_RECORD_BYTES)); pgrac_fenced_journal_scan_state_init(&state); - UT_ASSERT_EQ(pgrac_fenced_journal_scan_bytes(frames, sizeof(frames), - false, &state), PGRAC_FENCED_JOURNAL_SCAN_OK); + UT_ASSERT_EQ(pgrac_fenced_journal_scan_bytes(frames, sizeof(frames), false, &state), + PGRAC_FENCED_JOURNAL_SCAN_OK); UT_ASSERT_EQ(state.next_seq, 3); UT_ASSERT_EQ(state.segment_record_count, 2); UT_ASSERT_EQ(state.valid_bytes, sizeof(frames)); frames[PGRAC_FENCED_JOURNAL_RECORD_BYTES + 56] ^= 1; pgrac_fenced_journal_scan_state_init(&state); - UT_ASSERT_EQ(pgrac_fenced_journal_scan_bytes(frames, sizeof(frames), - false, &state), PGRAC_FENCED_JOURNAL_SCAN_CORRUPT); + UT_ASSERT_EQ(pgrac_fenced_journal_scan_bytes(frames, sizeof(frames), false, &state), + PGRAC_FENCED_JOURNAL_SCAN_CORRUPT); UT_ASSERT(!state.available); } @@ -153,15 +147,15 @@ UT_TEST(test_only_active_final_partial_record_is_truncatable) memset(bytes + PGRAC_FENCED_JOURNAL_RECORD_BYTES, 0x55, 13); pgrac_fenced_journal_scan_state_init(&state); - UT_ASSERT_EQ(pgrac_fenced_journal_scan_bytes(bytes, sizeof(bytes), true, - &state), PGRAC_FENCED_JOURNAL_SCAN_PARTIAL_TAIL); + UT_ASSERT_EQ(pgrac_fenced_journal_scan_bytes(bytes, sizeof(bytes), true, &state), + PGRAC_FENCED_JOURNAL_SCAN_PARTIAL_TAIL); UT_ASSERT(state.available); UT_ASSERT_EQ(state.valid_bytes, PGRAC_FENCED_JOURNAL_RECORD_BYTES); UT_ASSERT_EQ(state.next_seq, 2); pgrac_fenced_journal_scan_state_init(&state); - UT_ASSERT_EQ(pgrac_fenced_journal_scan_bytes(bytes, sizeof(bytes), false, - &state), PGRAC_FENCED_JOURNAL_SCAN_CORRUPT); + UT_ASSERT_EQ(pgrac_fenced_journal_scan_bytes(bytes, sizeof(bytes), false, &state), + PGRAC_FENCED_JOURNAL_SCAN_CORRUPT); UT_ASSERT(!state.available); } @@ -182,26 +176,26 @@ UT_TEST(test_append_advances_only_after_full_write_and_fsync) make_config_record(&record, 0); UT_ASSERT_EQ(pgrac_fenced_journal_append_fd(fd, &state, &record), - PGRAC_FENCED_JOURNAL_APPEND_OK); + PGRAC_FENCED_JOURNAL_APPEND_OK); UT_ASSERT_EQ(record.seq, 1); make_config_record(&record, 0); record.record_kind = PGRAC_FENCED_JOURNAL_KIND_REQUEST_ACCEPTED; fill_nonzero(record.operation_id, sizeof(record.operation_id), 0x66); UT_ASSERT_EQ(pgrac_fenced_journal_append_fd(fd, &state, &record), - PGRAC_FENCED_JOURNAL_APPEND_OK); + PGRAC_FENCED_JOURNAL_APPEND_OK); UT_ASSERT_EQ(record.seq, 2); UT_ASSERT_EQ(state.next_seq, 3); UT_ASSERT_EQ(lseek(fd, 0, SEEK_SET), 0); UT_ASSERT_EQ(read(fd, frames, sizeof(frames)), sizeof(frames)); pgrac_fenced_journal_scan_state_init(&scanned); - UT_ASSERT_EQ(pgrac_fenced_journal_scan_bytes(frames, sizeof(frames), - true, &scanned), PGRAC_FENCED_JOURNAL_SCAN_OK); + UT_ASSERT_EQ(pgrac_fenced_journal_scan_bytes(frames, sizeof(frames), true, &scanned), + PGRAC_FENCED_JOURNAL_SCAN_OK); UT_ASSERT_EQ(scanned.next_seq, 3); - (void) close(fd); - (void) unlink(path); + (void)close(fd); + (void)unlink(path); } UT_TEST(test_append_requests_rotation_at_exact_segment_limit) @@ -213,7 +207,7 @@ UT_TEST(test_append_requests_rotation_at_exact_segment_limit) state.segment_record_count = PGRAC_FENCED_JOURNAL_SEGMENT_RECORDS; make_config_record(&record, 0); UT_ASSERT_EQ(pgrac_fenced_journal_append_fd(-1, &state, &record), - PGRAC_FENCED_JOURNAL_APPEND_ROTATION_REQUIRED); + PGRAC_FENCED_JOURNAL_APPEND_ROTATION_REQUIRED); UT_ASSERT(state.available); UT_ASSERT_EQ(state.next_seq, 1); } @@ -225,13 +219,11 @@ UT_TEST(test_reconcile_actions_cover_all_durable_record_kinds) uint16 kind; for (kind = PGRAC_FENCED_JOURNAL_KIND_CONFIG_LOADED; - kind <= PGRAC_FENCED_JOURNAL_KIND_RECONCILED; kind++) - { + kind <= PGRAC_FENCED_JOURNAL_KIND_RECONCILED; kind++) { make_config_record(&record, 1); record.record_kind = kind; if (kind != PGRAC_FENCED_JOURNAL_KIND_CONFIG_LOADED) - fill_nonzero(record.operation_id, sizeof(record.operation_id), - 0x77); + fill_nonzero(record.operation_id, sizeof(record.operation_id), 0x77); if (kind == PGRAC_FENCED_JOURNAL_KIND_REENABLE_RESULT) record.target_state = PGRAC_FENCED_JOURNAL_TARGET_ON; if (kind == PGRAC_FENCED_JOURNAL_KIND_RECONCILED) @@ -314,11 +306,11 @@ UT_TEST(test_rotation_seals_exact_name_and_creates_new_active) UT_ASSERT_NOT_NULL(mkdtemp(dir_path)); UT_ASSERT(snprintf(active_path, sizeof(active_path), "%s/%s", dir_path, - PGRAC_FENCED_JOURNAL_ACTIVE_NAME) > 0); + PGRAC_FENCED_JOURNAL_ACTIVE_NAME) + > 0); active_fd = open(active_path, O_RDWR | O_CREAT | O_EXCL | O_APPEND, 0600); UT_ASSERT(active_fd >= 0); - UT_ASSERT_EQ(ftruncate(active_fd, - (off_t) PGRAC_FENCED_JOURNAL_SEGMENT_BYTES), 0); + UT_ASSERT_EQ(ftruncate(active_fd, (off_t)PGRAC_FENCED_JOURNAL_SEGMENT_BYTES), 0); dir_fd = open(dir_path, O_RDONLY | O_DIRECTORY); UT_ASSERT(dir_fd >= 0); @@ -327,14 +319,13 @@ UT_TEST(test_rotation_seals_exact_name_and_creates_new_active) state.next_seq = UINT64_C(262145); state.segment_record_count = PGRAC_FENCED_JOURNAL_SEGMENT_RECORDS; state.valid_bytes = PGRAC_FENCED_JOURNAL_SEGMENT_BYTES; - fill_nonzero(state.previous_record_digest, - sizeof(state.previous_record_digest), 0xab); - UT_ASSERT(pgrac_fenced_journal_rotate_at(dir_fd, &active_fd, 7, &state, - sealed_name, sizeof(sealed_name))); - UT_ASSERT_EQ(strcmp(sealed_name, - "journal.1-262144." - "abababababababababababababababab" - "abababababababababababababababab.sealed"), 0); + fill_nonzero(state.previous_record_digest, sizeof(state.previous_record_digest), 0xab); + UT_ASSERT(pgrac_fenced_journal_rotate_at(dir_fd, &active_fd, 7, &state, sealed_name, + sizeof(sealed_name))); + UT_ASSERT_EQ(strcmp(sealed_name, "journal.1-262144." + "abababababababababababababababab" + "abababababababababababababababab.sealed"), + 0); UT_ASSERT_EQ(state.segment_record_count, 0); UT_ASSERT_EQ(state.segment_first_seq, UINT64_C(262145)); UT_ASSERT_EQ(state.next_seq, UINT64_C(262145)); @@ -343,16 +334,15 @@ UT_TEST(test_rotation_seals_exact_name_and_creates_new_active) UT_ASSERT_EQ(fstat(active_fd, &st), 0); UT_ASSERT_EQ(st.st_size, 0); - UT_ASSERT(snprintf(sealed_path, sizeof(sealed_path), "%s/%s", dir_path, - sealed_name) > 0); + UT_ASSERT(snprintf(sealed_path, sizeof(sealed_path), "%s/%s", dir_path, sealed_name) > 0); UT_ASSERT_EQ(stat(sealed_path, &st), 0); - UT_ASSERT_EQ(st.st_size, (off_t) PGRAC_FENCED_JOURNAL_SEGMENT_BYTES); + UT_ASSERT_EQ(st.st_size, (off_t)PGRAC_FENCED_JOURNAL_SEGMENT_BYTES); - (void) close(active_fd); - (void) close(dir_fd); - (void) unlink(active_path); - (void) unlink(sealed_path); - (void) rmdir(dir_path); + (void)close(active_fd); + (void)close(dir_fd); + (void)unlink(active_path); + (void)unlink(sealed_path); + (void)rmdir(dir_path); } UT_TEST(test_ninth_rotation_fails_closed_without_rename) @@ -363,25 +353,21 @@ UT_TEST(test_ninth_rotation_fails_closed_without_rename) pgrac_fenced_journal_scan_state_init(&state); state.segment_record_count = PGRAC_FENCED_JOURNAL_SEGMENT_RECORDS; - UT_ASSERT(!pgrac_fenced_journal_rotate_at(-1, &active_fd, - PGRAC_FENCED_JOURNAL_MAX_SEALED, &state, sealed_name, - sizeof(sealed_name))); + UT_ASSERT(!pgrac_fenced_journal_rotate_at(-1, &active_fd, PGRAC_FENCED_JOURNAL_MAX_SEALED, + &state, sealed_name, sizeof(sealed_name))); UT_ASSERT(!state.available); } UT_TEST(test_semantic_config_digest_has_exact_domain_and_length) { - static const uint8 expected[PGRAC_FENCED_JOURNAL_DIGEST_BYTES] = { - 0xd4, 0x40, 0x05, 0x32, 0x5d, 0x7a, 0x43, 0xf4, - 0xb1, 0x81, 0xda, 0x56, 0x53, 0x8f, 0xf2, 0xe3, - 0xcc, 0x0a, 0x32, 0xa3, 0xf8, 0x50, 0xfc, 0x66, - 0xbe, 0x0f, 0x80, 0xcd, 0x4d, 0x0f, 0x3c, 0x63 - }; + static const uint8 expected[PGRAC_FENCED_JOURNAL_DIGEST_BYTES] + = { 0xd4, 0x40, 0x05, 0x32, 0x5d, 0x7a, 0x43, 0xf4, 0xb1, 0x81, 0xda, + 0x56, 0x53, 0x8f, 0xf2, 0xe3, 0xcc, 0x0a, 0x32, 0xa3, 0xf8, 0x50, + 0xfc, 0x66, 0xbe, 0x0f, 0x80, 0xcd, 0x4d, 0x0f, 0x3c, 0x63 }; static const uint8 config[] = "x\n"; uint8 digest[PGRAC_FENCED_JOURNAL_DIGEST_BYTES]; - UT_ASSERT(pgrac_fenced_journal_config_digest_v1(config, - sizeof(config) - 1, digest)); + UT_ASSERT(pgrac_fenced_journal_config_digest_v1(config, sizeof(config) - 1, digest)); UT_ASSERT(memcmp(digest, expected, sizeof(expected)) == 0); UT_ASSERT(!pgrac_fenced_journal_config_digest_v1(NULL, 0, digest)); } @@ -403,14 +389,14 @@ UT_TEST(test_partial_tail_repair_truncates_and_fsyncs_active) UT_ASSERT_EQ(fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_APPEND), 0); UT_ASSERT_EQ(write(fd, bytes, sizeof(bytes)), sizeof(bytes)); pgrac_fenced_journal_scan_state_init(&state); - UT_ASSERT_EQ(pgrac_fenced_journal_scan_bytes(bytes, sizeof(bytes), true, - &state), PGRAC_FENCED_JOURNAL_SCAN_PARTIAL_TAIL); + UT_ASSERT_EQ(pgrac_fenced_journal_scan_bytes(bytes, sizeof(bytes), true, &state), + PGRAC_FENCED_JOURNAL_SCAN_PARTIAL_TAIL); UT_ASSERT(pgrac_fenced_journal_repair_partial_tail_fd(fd, &state)); UT_ASSERT_EQ(fstat(fd, &st), 0); UT_ASSERT_EQ(st.st_size, PGRAC_FENCED_JOURNAL_RECORD_BYTES); UT_ASSERT(state.available); - (void) close(fd); - (void) unlink(path); + (void)close(fd); + (void)unlink(path); } UT_TEST(test_runtime_and_journal_stat_gates_are_exact) @@ -445,7 +431,7 @@ UT_TEST(test_runtime_and_journal_stat_gates_are_exact) st.st_mode = S_IFREG | 0640; UT_ASSERT(!pgrac_fenced_journal_file_stat_secure(&st)); st.st_mode = S_IFREG | 0600; - st.st_size = (off_t) PGRAC_FENCED_JOURNAL_SEGMENT_BYTES + 1; + st.st_size = (off_t)PGRAC_FENCED_JOURNAL_SEGMENT_BYTES + 1; UT_ASSERT(!pgrac_fenced_journal_file_stat_secure(&st)); } @@ -467,26 +453,23 @@ UT_TEST(test_runtime_loads_and_repairs_only_active_partial_tail) pgrac_fenced_journal_scan_state_init(&append_state); make_config_record(&record, 0); UT_ASSERT_EQ(pgrac_fenced_journal_append_fd(fd, &append_state, &record), - PGRAC_FENCED_JOURNAL_APPEND_OK); + PGRAC_FENCED_JOURNAL_APPEND_OK); memset(tail, 0x5a, sizeof(tail)); UT_ASSERT_EQ(write(fd, tail, sizeof(tail)), sizeof(tail)); pgrac_fenced_journal_scan_state_init(&loaded_state); - UT_ASSERT(pgrac_fenced_journal_load_active_fd(fd, &loaded_state, &last, - &have_last)); + UT_ASSERT(pgrac_fenced_journal_load_active_fd(fd, &loaded_state, &last, &have_last)); UT_ASSERT(have_last); - UT_ASSERT_EQ(last.record_kind, - PGRAC_FENCED_JOURNAL_KIND_CONFIG_LOADED); + UT_ASSERT_EQ(last.record_kind, PGRAC_FENCED_JOURNAL_KIND_CONFIG_LOADED); UT_ASSERT_EQ(loaded_state.next_seq, 2); UT_ASSERT_EQ(fstat(fd, &st), 0); UT_ASSERT_EQ(st.st_size, PGRAC_FENCED_JOURNAL_RECORD_BYTES); UT_ASSERT_EQ(pwrite(fd, "x", 1, 0), 1); UT_ASSERT_EQ(fsync(fd), 0); - UT_ASSERT(!pgrac_fenced_journal_load_active_fd(fd, &loaded_state, &last, - &have_last)); + UT_ASSERT(!pgrac_fenced_journal_load_active_fd(fd, &loaded_state, &last, &have_last)); UT_ASSERT(!loaded_state.available); - (void) close(fd); - (void) unlink(path); + (void)close(fd); + (void)unlink(path); } UT_TEST(test_runtime_loads_sealed_then_active_as_one_hash_chain) @@ -505,43 +488,38 @@ UT_TEST(test_runtime_loads_sealed_then_active_as_one_hash_chain) active_fd = mkstemp(active_path); UT_ASSERT(sealed_fd >= 0); UT_ASSERT(active_fd >= 0); - UT_ASSERT_EQ(fcntl(sealed_fd, F_SETFL, - fcntl(sealed_fd, F_GETFL) | O_APPEND), 0); - UT_ASSERT_EQ(fcntl(active_fd, F_SETFL, - fcntl(active_fd, F_GETFL) | O_APPEND), 0); + UT_ASSERT_EQ(fcntl(sealed_fd, F_SETFL, fcntl(sealed_fd, F_GETFL) | O_APPEND), 0); + UT_ASSERT_EQ(fcntl(active_fd, F_SETFL, fcntl(active_fd, F_GETFL) | O_APPEND), 0); pgrac_fenced_journal_scan_state_init(&append_state); make_config_record(&record, 0); - UT_ASSERT_EQ(pgrac_fenced_journal_append_fd(sealed_fd, &append_state, - &record), PGRAC_FENCED_JOURNAL_APPEND_OK); + UT_ASSERT_EQ(pgrac_fenced_journal_append_fd(sealed_fd, &append_state, &record), + PGRAC_FENCED_JOURNAL_APPEND_OK); append_state.segment_first_seq = append_state.next_seq; append_state.segment_record_count = 0; append_state.valid_bytes = 0; make_config_record(&record, 0); record.record_kind = PGRAC_FENCED_JOURNAL_KIND_REQUEST_ACCEPTED; fill_nonzero(record.operation_id, sizeof(record.operation_id), 0x33); - UT_ASSERT_EQ(pgrac_fenced_journal_append_fd(active_fd, &append_state, - &record), PGRAC_FENCED_JOURNAL_APPEND_OK); + UT_ASSERT_EQ(pgrac_fenced_journal_append_fd(active_fd, &append_state, &record), + PGRAC_FENCED_JOURNAL_APPEND_OK); pgrac_fenced_journal_scan_state_init(&loaded_state); - UT_ASSERT(pgrac_fenced_journal_load_sealed_fd(sealed_fd, &loaded_state, - &last, &have_last)); + UT_ASSERT(pgrac_fenced_journal_load_sealed_fd(sealed_fd, &loaded_state, &last, &have_last)); UT_ASSERT(have_last); UT_ASSERT_EQ(last.seq, 1); - UT_ASSERT(pgrac_fenced_journal_load_active_fd(active_fd, &loaded_state, - &last, &have_last)); + UT_ASSERT(pgrac_fenced_journal_load_active_fd(active_fd, &loaded_state, &last, &have_last)); UT_ASSERT(have_last); UT_ASSERT_EQ(last.seq, 2); UT_ASSERT_EQ(loaded_state.next_seq, 3); UT_ASSERT_EQ(write(sealed_fd, "x", 1), 1); pgrac_fenced_journal_scan_state_init(&loaded_state); - UT_ASSERT(!pgrac_fenced_journal_load_sealed_fd(sealed_fd, &loaded_state, - &last, &have_last)); + UT_ASSERT(!pgrac_fenced_journal_load_sealed_fd(sealed_fd, &loaded_state, &last, &have_last)); UT_ASSERT(!loaded_state.available); - (void) close(active_fd); - (void) close(sealed_fd); - (void) unlink(active_path); - (void) unlink(sealed_path); + (void)close(active_fd); + (void)close(sealed_fd); + (void)unlink(active_path); + (void)unlink(sealed_path); } UT_TEST(test_runtime_replays_verified_records_into_restart_reconcile) @@ -557,65 +535,57 @@ UT_TEST(test_runtime_replays_verified_records_into_restart_reconcile) fd = mkstemp(path); UT_ASSERT(fd >= 0); - UT_ASSERT_EQ(fcntl(fd, F_SETFL, - fcntl(fd, F_GETFL) | O_APPEND), 0); + UT_ASSERT_EQ(fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_APPEND), 0); pgrac_fenced_journal_scan_state_init(&append_state); make_config_record(&record, 0); UT_ASSERT_EQ(pgrac_fenced_journal_append_fd(fd, &append_state, &record), - PGRAC_FENCED_JOURNAL_APPEND_OK); + PGRAC_FENCED_JOURNAL_APPEND_OK); make_config_record(&record, 0); record.record_kind = PGRAC_FENCED_JOURNAL_KIND_ACTUATION_ISSUED; fill_nonzero(record.operation_id, sizeof(record.operation_id), 0x45); record.provider_result = PGRAC_FENCED_JOURNAL_PROVIDER_PENDING; UT_ASSERT_EQ(pgrac_fenced_journal_append_fd(fd, &append_state, &record), - PGRAC_FENCED_JOURNAL_APPEND_OK); + PGRAC_FENCED_JOURNAL_APPEND_OK); pgrac_fenced_journal_scan_state_init(&loaded_state); pgrac_fenced_journal_reconcile_state_init(&reconcile); - UT_ASSERT(pgrac_fenced_journal_load_active_reconcile_fd(fd, - &loaded_state, &last, &have_last, &reconcile)); + UT_ASSERT(pgrac_fenced_journal_load_active_reconcile_fd(fd, &loaded_state, &last, &have_last, + &reconcile)); UT_ASSERT(have_last); - UT_ASSERT_EQ(last.record_kind, - PGRAC_FENCED_JOURNAL_KIND_ACTUATION_ISSUED); + UT_ASSERT_EQ(last.record_kind, PGRAC_FENCED_JOURNAL_KIND_ACTUATION_ISSUED); UT_ASSERT(pgrac_fenced_journal_reconcile_finish(&reconcile)); UT_ASSERT_EQ(reconcile.pending_count, 1); UT_ASSERT(reconcile.fresh_readback_required); - (void) close(fd); - (void) unlink(path); + (void)close(fd); + (void)unlink(path); } UT_TEST(test_sealed_name_parser_is_canonical_and_full_segment_only) { - static const char valid[] = - "journal.1-262144." - "abababababababababababababababab" - "abababababababababababababababab.sealed"; + static const char valid[] = "journal.1-262144." + "abababababababababababababababab" + "abababababababababababababababab.sealed"; char invalid[sizeof(valid)]; uint8 digest[32]; uint64 first; uint64 last; - UT_ASSERT(pgrac_fenced_journal_sealed_name_parse(valid, &first, &last, - digest)); + UT_ASSERT(pgrac_fenced_journal_sealed_name_parse(valid, &first, &last, digest)); UT_ASSERT_EQ(first, 1); UT_ASSERT_EQ(last, UINT64_C(262144)); UT_ASSERT_EQ(digest[0], 0xab); UT_ASSERT_EQ(digest[31], 0xab); strcpy(invalid, valid); invalid[8] = '0'; - UT_ASSERT(!pgrac_fenced_journal_sealed_name_parse(invalid, &first, &last, - digest)); + UT_ASSERT(!pgrac_fenced_journal_sealed_name_parse(invalid, &first, &last, digest)); strcpy(invalid, valid); invalid[25] = 'A'; - UT_ASSERT(!pgrac_fenced_journal_sealed_name_parse(invalid, &first, &last, - digest)); - UT_ASSERT(!pgrac_fenced_journal_sealed_name_parse( - "journal.1-2." - "abababababababababababababababab" - "abababababababababababababababab.sealed", - &first, &last, digest)); - UT_ASSERT(!pgrac_fenced_journal_sealed_name_parse(NULL, &first, &last, - digest)); + UT_ASSERT(!pgrac_fenced_journal_sealed_name_parse(invalid, &first, &last, digest)); + UT_ASSERT(!pgrac_fenced_journal_sealed_name_parse("journal.1-2." + "abababababababababababababababab" + "abababababababababababababababab.sealed", + &first, &last, digest)); + UT_ASSERT(!pgrac_fenced_journal_sealed_name_parse(NULL, &first, &last, digest)); } int diff --git a/src/test/cluster_unit/test_pgrac_fenced_operation.c b/src/test/cluster_unit/test_pgrac_fenced_operation.c index 0647a0331b6..28c682d834f 100644 --- a/src/test/cluster_unit/test_pgrac_fenced_operation.c +++ b/src/test/cluster_unit/test_pgrac_fenced_operation.c @@ -26,8 +26,7 @@ UT_DEFINE_GLOBALS(); -typedef enum TestProviderMode -{ +typedef enum TestProviderMode { TEST_PROVIDER_EXACT = 0, TEST_PROVIDER_ACTION_UNKNOWN = 1, TEST_PROVIDER_READBACK_UNKNOWN = 2, @@ -45,14 +44,19 @@ typedef enum TestProviderMode static TestProviderMode provider_mode; static unsigned int resolve_calls; static volatile uint32 *shared_provider_counts; +static volatile uint32 *timeout_stage_entered; +static bool delay_before_timeout_stage; static PgracFencedProviderResult -test_resolve(const PgracFencedTargetV1 *configured, - PgracFencedTargetV1 *resolved, int32 *native_status) +test_resolve(const PgracFencedTargetV1 *configured, PgracFencedTargetV1 *resolved, + int32 *native_status) { resolve_calls++; + /* Model setup/journal latency before the action/readback fault is reached. */ + if (delay_before_timeout_stage) + (void)usleep(50000); if (provider_mode == TEST_PROVIDER_RESOLVE_SLOW) - (void) usleep(200000); + (void)usleep(200000); if (provider_mode == TEST_PROVIDER_RESOLVE_UNAVAILABLE) return PGRAC_FENCED_PROVIDER_UNAVAILABLE; if (provider_mode == TEST_PROVIDER_RESOLVE_CONFIG_ERROR) @@ -65,17 +69,18 @@ test_resolve(const PgracFencedTargetV1 *configured, } static PgracFencedProviderResult -test_actuate(const PgracFencedTargetV1 *target, - uint64_t deadline_mono_ns, int32 *native_status) +test_actuate(const PgracFencedTargetV1 *target, uint64_t deadline_mono_ns, int32 *native_status) { - (void) target; - (void) deadline_mono_ns; + (void)target; + (void)deadline_mono_ns; if (shared_provider_counts != NULL) shared_provider_counts[0]++; - if (provider_mode == TEST_PROVIDER_ACTION_SLOW) - (void) usleep(200000); - if (provider_mode == TEST_PROVIDER_ACTION_UNKNOWN) - { + if (provider_mode == TEST_PROVIDER_ACTION_SLOW) { + if (timeout_stage_entered != NULL) + *timeout_stage_entered = TEST_PROVIDER_ACTION_SLOW; + (void)usleep(2000000); + } + if (provider_mode == TEST_PROVIDER_ACTION_UNKNOWN) { *native_status = 71; return PGRAC_FENCED_PROVIDER_UNKNOWN; } @@ -84,44 +89,40 @@ test_actuate(const PgracFencedTargetV1 *target, } static PgracFencedProviderResult -test_readback(const PgracFencedTargetV1 *target, - uint64_t deadline_mono_ns, PgracFencedReadbackV1 *out) +test_readback(const PgracFencedTargetV1 *target, uint64_t deadline_mono_ns, + PgracFencedReadbackV1 *out) { uint32 readback_call = 0; - (void) deadline_mono_ns; + (void)deadline_mono_ns; memset(out, 0, sizeof(*out)); if (shared_provider_counts != NULL) readback_call = ++shared_provider_counts[1]; - if (provider_mode == TEST_PROVIDER_READBACK_SLOW) - (void) usleep(200000); + if (provider_mode == TEST_PROVIDER_READBACK_SLOW) { + if (timeout_stage_entered != NULL) + *timeout_stage_entered = TEST_PROVIDER_READBACK_SLOW; + (void)usleep(2000000); + } if (provider_mode == TEST_PROVIDER_READBACK_UNAVAILABLE) return PGRAC_FENCED_PROVIDER_UNAVAILABLE; if (provider_mode == TEST_PROVIDER_READBACK_UNKNOWN) return PGRAC_FENCED_PROVIDER_UNKNOWN; - if (provider_mode == TEST_PROVIDER_READBACK_TRANSIENT_TWICE && - readback_call <= 2) + if (provider_mode == TEST_PROVIDER_READBACK_TRANSIENT_TWICE && readback_call <= 2) return PGRAC_FENCED_PROVIDER_UNKNOWN; - if (provider_mode == TEST_PROVIDER_PREFLIGHT_ON_THEN_OFF && - readback_call == 1) - { + if (provider_mode == TEST_PROVIDER_PREFLIGHT_ON_THEN_OFF && readback_call == 1) { out->state = PGRAC_FENCED_TARGET_ON; out->io_drain_state = PGRAC_FENCED_IO_DRAIN_UNKNOWN; - } - else - { + } else { out->state = PGRAC_FENCED_TARGET_OFF; out->io_drain_state = PGRAC_FENCED_IO_DRAIN_DRAINED; } - memcpy(out->observed_target_uuid, target->target_uuid, - sizeof(out->observed_target_uuid)); + memcpy(out->observed_target_uuid, target->target_uuid, sizeof(out->observed_target_uuid)); return PGRAC_FENCED_PROVIDER_OK; } static void test_shutdown(void) -{ -} +{} static void make_ops(PgracFencedProviderOpsV1 *ops) @@ -151,24 +152,20 @@ make_config(PgracFencedConfigV1 *config) config->provider_abi = PGRAC_FENCED_PROVIDER_ABI_V1; config->node_count = 1; config->nodes[3].present = true; - memset(config->nodes[3].target_uuid, 0x41, - sizeof(config->nodes[3].target_uuid)); + memset(config->nodes[3].target_uuid, 0x41, sizeof(config->nodes[3].target_uuid)); } static void -make_request(const PgracFencedConfigV1 *config, - PgracExternalFenceProtocolRequestV1 *request) +make_request(const PgracFencedConfigV1 *config, PgracExternalFenceProtocolRequestV1 *request) { memset(request, 0, sizeof(*request)); memset(request->request_nonce, 0x51, sizeof(request->request_nonce)); request->need.system_identifier = config->system_identifier; - memset(request->need.canonical_duty_digest, 0x61, - sizeof(request->need.canonical_duty_digest)); + memset(request->need.canonical_duty_digest, 0x61, sizeof(request->need.canonical_duty_digest)); request->need.victim_node_id = 3; request->need.victim_incarnation = 23; UT_ASSERT(pgrac_external_fence_protected_set_digest_v1( - config->storage_backend_id, config->storage_uuid, - request->need.protected_set_digest)); + config->storage_backend_id, config->storage_uuid, request->need.protected_set_digest)); request->need.predicate_id = 1; request->need.predicate_version = 1; request->timeout_ms = 1000; @@ -180,15 +177,13 @@ deadline_after_ms(uint64_t milliseconds) struct timespec now; UT_ASSERT_EQ(clock_gettime(CLOCK_MONOTONIC, &now), 0); - return (uint64_t) now.tv_sec * UINT64_C(1000000000) + - (uint64_t) now.tv_nsec + milliseconds * UINT64_C(1000000); + return (uint64_t)now.tv_sec * UINT64_C(1000000000) + (uint64_t)now.tv_nsec + + milliseconds * UINT64_C(1000000); } static int -open_context(PgracFencedOperationContextV1 *context, - PgracFencedJournalScanState *journal_state, - PgracFencedConfigV1 *config, PgracFencedProviderOpsV1 *ops, - char path[64]) +open_context(PgracFencedOperationContextV1 *context, PgracFencedJournalScanState *journal_state, + PgracFencedConfigV1 *config, PgracFencedProviderOpsV1 *ops, char path[64]) { uint8 config_digest[32]; uint8 daemon_boot_id[16]; @@ -203,24 +198,21 @@ open_context(PgracFencedOperationContextV1 *context, return -1; UT_ASSERT_EQ(fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_APPEND), 0); pgrac_fenced_journal_scan_state_init(journal_state); - UT_ASSERT(pgrac_fenced_operation_context_init(context, config, ops, true, - config_digest, daemon_boot_id, fd, journal_state)); + UT_ASSERT(pgrac_fenced_operation_context_init(context, config, ops, true, config_digest, + daemon_boot_id, fd, journal_state)); return fd; } static size_t -read_journal_records(int fd, PgracFencedJournalRecordV1 *records, - size_t maximum) +read_journal_records(int fd, PgracFencedJournalRecordV1 *records, size_t maximum) { uint8 frame[PGRAC_FENCED_JOURNAL_RECORD_BYTES]; size_t count = 0; ssize_t got; UT_ASSERT_EQ(lseek(fd, 0, SEEK_SET), 0); - while (count < maximum) - { - do - { + while (count < maximum) { + do { got = read(fd, frame, sizeof(frame)); } while (got < 0 && errno == EINTR); if (got == 0) @@ -228,8 +220,7 @@ read_journal_records(int fd, PgracFencedJournalRecordV1 *records, UT_ASSERT_EQ(got, sizeof(frame)); if (got != sizeof(frame)) break; - UT_ASSERT(pgrac_fenced_journal_record_decode(frame, sizeof(frame), - &records[count])); + UT_ASSERT(pgrac_fenced_journal_record_decode(frame, sizeof(frame), &records[count])); count++; } return count; @@ -255,31 +246,24 @@ UT_TEST(test_scalar_acquire_fsyncs_exact_positive_sequence) fd = open_context(&context, &journal_state, &config, &ops, path); if (fd < 0) return; - UT_ASSERT(pgrac_fenced_operation_acquire(&context, &request, - deadline_after_ms(1000), &response)); + UT_ASSERT( + pgrac_fenced_operation_acquire(&context, &request, deadline_after_ms(1000), &response)); UT_ASSERT_EQ(response.verdict, 1); UT_ASSERT_EQ(response.deny_reason, 0); UT_ASSERT_EQ(response.proof_generation, 1); UT_ASSERT_EQ(response.binding.target_mapping_generation, 17); - UT_ASSERT(pgrac_external_fence_affirmative_response_matches_request_v1( - &request, &response)); + UT_ASSERT(pgrac_external_fence_affirmative_response_matches_request_v1(&request, &response)); count = read_journal_records(fd, records, lengthof(records)); UT_ASSERT_EQ(count, 6); - UT_ASSERT_EQ(records[0].record_kind, - PGRAC_FENCED_JOURNAL_KIND_CONFIG_LOADED); - UT_ASSERT_EQ(records[1].record_kind, - PGRAC_FENCED_JOURNAL_KIND_REQUEST_ACCEPTED); - UT_ASSERT_EQ(records[2].record_kind, - PGRAC_FENCED_JOURNAL_KIND_ACTUATION_ISSUED); - UT_ASSERT_EQ(records[3].record_kind, - PGRAC_FENCED_JOURNAL_KIND_ACTUATION_RESULT); - UT_ASSERT_EQ(records[4].record_kind, - PGRAC_FENCED_JOURNAL_KIND_READBACK_RESULT); - UT_ASSERT_EQ(records[5].record_kind, - PGRAC_FENCED_JOURNAL_KIND_PROOF_SERVED); + UT_ASSERT_EQ(records[0].record_kind, PGRAC_FENCED_JOURNAL_KIND_CONFIG_LOADED); + UT_ASSERT_EQ(records[1].record_kind, PGRAC_FENCED_JOURNAL_KIND_REQUEST_ACCEPTED); + UT_ASSERT_EQ(records[2].record_kind, PGRAC_FENCED_JOURNAL_KIND_ACTUATION_ISSUED); + UT_ASSERT_EQ(records[3].record_kind, PGRAC_FENCED_JOURNAL_KIND_ACTUATION_RESULT); + UT_ASSERT_EQ(records[4].record_kind, PGRAC_FENCED_JOURNAL_KIND_READBACK_RESULT); + UT_ASSERT_EQ(records[5].record_kind, PGRAC_FENCED_JOURNAL_KIND_PROOF_SERVED); UT_ASSERT_EQ(response.journal_seq, records[5].seq); - (void) close(fd); - (void) unlink(path); + (void)close(fd); + (void)unlink(path); } UT_TEST(test_action_failure_still_accepts_independent_positive_readback) @@ -300,12 +284,12 @@ UT_TEST(test_action_failure_still_accepts_independent_positive_readback) fd = open_context(&context, &journal_state, &config, &ops, path); if (fd < 0) return; - UT_ASSERT(pgrac_fenced_operation_acquire(&context, &request, - deadline_after_ms(1000), &response)); + UT_ASSERT( + pgrac_fenced_operation_acquire(&context, &request, deadline_after_ms(1000), &response)); UT_ASSERT_EQ(response.verdict, 1); UT_ASSERT_EQ(response.provider_result, PGRAC_FENCED_PROVIDER_OK); - (void) close(fd); - (void) unlink(path); + (void)close(fd); + (void)unlink(path); } UT_TEST(test_scalar_readback_retries_transient_results_before_proof) @@ -320,30 +304,28 @@ UT_TEST(test_scalar_readback_retries_transient_results_before_proof) int fd; provider_mode = TEST_PROVIDER_READBACK_TRANSIENT_TWICE; - shared_provider_counts = mmap(NULL, sizeof(uint32) * 2, - PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0); + shared_provider_counts + = mmap(NULL, sizeof(uint32) * 2, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0); UT_ASSERT(shared_provider_counts != MAP_FAILED); - if (shared_provider_counts == MAP_FAILED) - { + if (shared_provider_counts == MAP_FAILED) { shared_provider_counts = NULL; return; } - memset((void *) shared_provider_counts, 0, sizeof(uint32) * 2); + memset((void *)shared_provider_counts, 0, sizeof(uint32) * 2); make_config(&config); make_ops(&ops); make_request(&config, &request); fd = open_context(&context, &journal_state, &config, &ops, path); if (fd < 0) return; - UT_ASSERT(pgrac_fenced_operation_acquire(&context, &request, - deadline_after_ms(2000), &response)); + UT_ASSERT( + pgrac_fenced_operation_acquire(&context, &request, deadline_after_ms(2000), &response)); UT_ASSERT_EQ(response.verdict, 1); UT_ASSERT_EQ(shared_provider_counts[1], 3); UT_ASSERT_EQ(response.proof_generation, 1); - (void) close(fd); - (void) unlink(path); - UT_ASSERT_EQ(munmap((void *) shared_provider_counts, - sizeof(uint32) * 2), 0); + (void)close(fd); + (void)unlink(path); + UT_ASSERT_EQ(munmap((void *)shared_provider_counts, sizeof(uint32) * 2), 0); shared_provider_counts = NULL; } @@ -365,26 +347,26 @@ UT_TEST(test_resolve_mismatch_and_persistent_unknown_never_prove) fd = open_context(&context, &journal_state, &config, &ops, path); if (fd < 0) return; - UT_ASSERT(pgrac_fenced_operation_acquire(&context, &request, - deadline_after_ms(1000), &response)); + UT_ASSERT( + pgrac_fenced_operation_acquire(&context, &request, deadline_after_ms(1000), &response)); UT_ASSERT_EQ(response.verdict, 2); UT_ASSERT_EQ(response.deny_reason, 8); UT_ASSERT_EQ(context.next_proof_generation, 1); - (void) close(fd); - (void) unlink(path); + (void)close(fd); + (void)unlink(path); provider_mode = TEST_PROVIDER_READBACK_UNKNOWN; fd = open_context(&context, &journal_state, &config, &ops, path); if (fd < 0) return; - UT_ASSERT(pgrac_fenced_operation_acquire(&context, &request, - deadline_after_ms(1000), &response)); + UT_ASSERT( + pgrac_fenced_operation_acquire(&context, &request, deadline_after_ms(1000), &response)); UT_ASSERT_EQ(response.verdict, 4); UT_ASSERT_EQ(response.deny_reason, 11); UT_ASSERT_EQ(response.proof_generation, 0); UT_ASSERT_EQ(context.next_proof_generation, 1); - (void) close(fd); - (void) unlink(path); + (void)close(fd); + (void)unlink(path); } UT_TEST(test_protected_set_mismatch_has_zero_request_journal_and_action) @@ -407,14 +389,14 @@ UT_TEST(test_protected_set_mismatch_has_zero_request_journal_and_action) fd = open_context(&context, &journal_state, &config, &ops, path); if (fd < 0) return; - UT_ASSERT(pgrac_fenced_operation_acquire(&context, &request, - deadline_after_ms(1000), &response)); + UT_ASSERT( + pgrac_fenced_operation_acquire(&context, &request, deadline_after_ms(1000), &response)); UT_ASSERT_EQ(response.verdict, 4); UT_ASSERT_EQ(response.deny_reason, 4); UT_ASSERT_EQ(read_journal_records(fd, records, lengthof(records)), 1); UT_ASSERT_EQ(context.next_proof_generation, 1); - (void) close(fd); - (void) unlink(path); + (void)close(fd); + (void)unlink(path); } UT_TEST(test_deadline_owner_maps_slow_resolve_to_timeout) @@ -435,13 +417,12 @@ UT_TEST(test_deadline_owner_maps_slow_resolve_to_timeout) fd = open_context(&context, &journal_state, &config, &ops, path); if (fd < 0) return; - UT_ASSERT(pgrac_fenced_operation_acquire(&context, &request, - deadline_after_ms(20), &response)); + UT_ASSERT(pgrac_fenced_operation_acquire(&context, &request, deadline_after_ms(20), &response)); UT_ASSERT_EQ(response.verdict, 4); UT_ASSERT_EQ(response.deny_reason, 11); UT_ASSERT_EQ(response.proof_generation, 0); - (void) close(fd); - (void) unlink(path); + (void)close(fd); + (void)unlink(path); } UT_TEST(test_deadline_owner_maps_slow_action_and_readback_to_timeout) @@ -453,40 +434,54 @@ UT_TEST(test_deadline_owner_maps_slow_action_and_readback_to_timeout) PgracExternalFenceProtocolResponseV1 response; PgracFencedProviderOpsV1 ops; PgracFencedConfigV1 config; - TestProviderMode modes[] = { - TEST_PROVIDER_ACTION_SLOW, - TEST_PROVIDER_READBACK_SLOW - }; + TestProviderMode modes[] = { TEST_PROVIDER_ACTION_SLOW, TEST_PROVIDER_READBACK_SLOW }; char path[64]; - int fd; - size_t count; size_t i; make_config(&config); make_ops(&ops); make_request(&config, &request); - for (i = 0; i < lengthof(modes); i++) - { + timeout_stage_entered = mmap(NULL, sizeof(*timeout_stage_entered), PROT_READ | PROT_WRITE, + MAP_SHARED | MAP_ANON, -1, 0); + UT_ASSERT(timeout_stage_entered != MAP_FAILED); + if (timeout_stage_entered == MAP_FAILED) { + timeout_stage_entered = NULL; + return; + } + delay_before_timeout_stage = true; + for (i = 0; i < lengthof(modes); i++) { + int fd; + size_t count; + provider_mode = modes[i]; + *timeout_stage_entered = 0; fd = open_context(&context, &journal_state, &config, &ops, path); if (fd < 0) - return; + break; + /* + * Use the fixture's one-second request budget to reach the target stage; + * its two-second injected stall must then hit the real deadline. A + * 20ms whole-operation deadline could expire during setup, testing a + * different branch without ever executing the intended provider fault. + */ UT_ASSERT(pgrac_fenced_operation_acquire(&context, &request, - deadline_after_ms(20), &response)); + deadline_after_ms(request.timeout_ms), &response)); UT_ASSERT_EQ(response.verdict, 4); UT_ASSERT_EQ(response.deny_reason, 11); UT_ASSERT_EQ(response.proof_generation, 0); + UT_ASSERT_EQ(*timeout_stage_entered, modes[i]); count = read_journal_records(fd, records, lengthof(records)); UT_ASSERT(count > 0); - if (count > 0) - { - UT_ASSERT_EQ(records[count - 1].record_kind, - PGRAC_FENCED_JOURNAL_KIND_READBACK_RESULT); + if (count > 0) { + UT_ASSERT_EQ(records[count - 1].record_kind, PGRAC_FENCED_JOURNAL_KIND_READBACK_RESULT); UT_ASSERT_EQ(records[count - 1].deny_reason, 11); } - (void) close(fd); - (void) unlink(path); + (void)close(fd); + (void)unlink(path); } + delay_before_timeout_stage = false; + UT_ASSERT_EQ(munmap((void *)timeout_stage_entered, sizeof(*timeout_stage_entered)), 0); + timeout_stage_entered = NULL; } UT_TEST(test_journal_failure_is_sticky_and_prevents_provider_calls) @@ -509,18 +504,18 @@ UT_TEST(test_journal_failure_is_sticky_and_prevents_provider_calls) if (fd < 0) return; UT_ASSERT_EQ(close(fd), 0); - UT_ASSERT(pgrac_fenced_operation_acquire(&context, &request, - deadline_after_ms(1000), &response)); + UT_ASSERT( + pgrac_fenced_operation_acquire(&context, &request, deadline_after_ms(1000), &response)); UT_ASSERT_EQ(response.verdict, 4); UT_ASSERT_EQ(response.deny_reason, 12); UT_ASSERT(!context.available); UT_ASSERT_EQ(resolve_calls, 0); - UT_ASSERT(pgrac_fenced_operation_acquire(&context, &request, - deadline_after_ms(1000), &response)); + UT_ASSERT( + pgrac_fenced_operation_acquire(&context, &request, deadline_after_ms(1000), &response)); UT_ASSERT_EQ(response.verdict, 4); UT_ASSERT_EQ(response.deny_reason, 12); UT_ASSERT_EQ(resolve_calls, 0); - (void) unlink(path); + (void)unlink(path); } UT_TEST(test_malformed_request_is_bad_argument_without_side_effects) @@ -544,20 +539,20 @@ UT_TEST(test_malformed_request_is_bad_argument_without_side_effects) if (fd < 0) return; request.need.predicate_version = 0; - UT_ASSERT(pgrac_fenced_operation_acquire(&context, &request, - deadline_after_ms(1000), &response)); + UT_ASSERT( + pgrac_fenced_operation_acquire(&context, &request, deadline_after_ms(1000), &response)); UT_ASSERT_EQ(response.verdict, 4); UT_ASSERT_EQ(response.deny_reason, 1); make_request(&config, &request); request.timeout_ms = 0; - UT_ASSERT(pgrac_fenced_operation_acquire(&context, &request, - deadline_after_ms(1000), &response)); + UT_ASSERT( + pgrac_fenced_operation_acquire(&context, &request, deadline_after_ms(1000), &response)); UT_ASSERT_EQ(response.verdict, 4); UT_ASSERT_EQ(response.deny_reason, 1); UT_ASSERT_EQ(resolve_calls, 0); UT_ASSERT_EQ(read_journal_records(fd, records, lengthof(records)), 1); - (void) close(fd); - (void) unlink(path); + (void)close(fd); + (void)unlink(path); } UT_TEST(test_provider_unavailable_mapping_is_exact_in_journal_and_response) @@ -569,43 +564,38 @@ UT_TEST(test_provider_unavailable_mapping_is_exact_in_journal_and_response) PgracExternalFenceProtocolResponseV1 response; PgracFencedProviderOpsV1 ops; PgracFencedConfigV1 config; - TestProviderMode modes[] = { - TEST_PROVIDER_RESOLVE_UNAVAILABLE, - TEST_PROVIDER_RESOLVE_CONFIG_ERROR, - TEST_PROVIDER_READBACK_UNAVAILABLE - }; - uint16 expected_kinds[] = { - PGRAC_FENCED_JOURNAL_KIND_ACTUATION_RESULT, - PGRAC_FENCED_JOURNAL_KIND_ACTUATION_RESULT, - PGRAC_FENCED_JOURNAL_KIND_READBACK_RESULT - }; + TestProviderMode modes[] + = { TEST_PROVIDER_RESOLVE_UNAVAILABLE, TEST_PROVIDER_RESOLVE_CONFIG_ERROR, + TEST_PROVIDER_READBACK_UNAVAILABLE }; + uint16 expected_kinds[] + = { PGRAC_FENCED_JOURNAL_KIND_ACTUATION_RESULT, PGRAC_FENCED_JOURNAL_KIND_ACTUATION_RESULT, + PGRAC_FENCED_JOURNAL_KIND_READBACK_RESULT }; char path[64]; - int fd; - size_t count; size_t i; make_config(&config); make_ops(&ops); make_request(&config, &request); - for (i = 0; i < lengthof(modes); i++) - { + for (i = 0; i < lengthof(modes); i++) { + int fd; + size_t count; + provider_mode = modes[i]; fd = open_context(&context, &journal_state, &config, &ops, path); if (fd < 0) return; - UT_ASSERT(pgrac_fenced_operation_acquire(&context, &request, - deadline_after_ms(1000), &response)); + UT_ASSERT( + pgrac_fenced_operation_acquire(&context, &request, deadline_after_ms(1000), &response)); UT_ASSERT_EQ(response.verdict, 4); UT_ASSERT_EQ(response.deny_reason, 10); count = read_journal_records(fd, records, lengthof(records)); UT_ASSERT(count > 0); - if (count > 0) - { + if (count > 0) { UT_ASSERT_EQ(records[count - 1].record_kind, expected_kinds[i]); UT_ASSERT_EQ(records[count - 1].deny_reason, 10); } - (void) close(fd); - (void) unlink(path); + (void)close(fd); + (void)unlink(path); } } @@ -621,8 +611,6 @@ UT_TEST(test_operation_rotates_full_active_before_next_durable_record) uint8 daemon_boot_id[16]; char directory_path[] = "/tmp/pgrac-fenced-operation-rotate.XXXXXX"; char active_path[MAXPGPATH]; - char entry_path[MAXPGPATH]; - struct dirent *entry; DIR *directory; int directory_fd; int active_fd; @@ -634,44 +622,45 @@ UT_TEST(test_operation_rotates_full_active_before_next_durable_record) memset(config_digest, 0x71, sizeof(config_digest)); memset(daemon_boot_id, 0x81, sizeof(daemon_boot_id)); UT_ASSERT_NOT_NULL(mkdtemp(directory_path)); - UT_ASSERT(snprintf(active_path, sizeof(active_path), "%s/%s", - directory_path, PGRAC_FENCED_JOURNAL_ACTIVE_NAME) > 0); + UT_ASSERT(snprintf(active_path, sizeof(active_path), "%s/%s", directory_path, + PGRAC_FENCED_JOURNAL_ACTIVE_NAME) + > 0); active_fd = open(active_path, O_RDWR | O_CREAT | O_EXCL | O_APPEND, 0600); UT_ASSERT(active_fd >= 0); directory_fd = open(directory_path, O_RDONLY | O_DIRECTORY); UT_ASSERT(directory_fd >= 0); pgrac_fenced_journal_scan_state_init(&journal_state); - UT_ASSERT(pgrac_fenced_operation_context_init(&context, &config, &ops, - true, config_digest, daemon_boot_id, active_fd, &journal_state)); + UT_ASSERT(pgrac_fenced_operation_context_init(&context, &config, &ops, true, config_digest, + daemon_boot_id, active_fd, &journal_state)); UT_ASSERT(pgrac_fenced_operation_enable_rotation(&context, directory_fd, 0)); - UT_ASSERT_EQ(ftruncate(active_fd, - (off_t) PGRAC_FENCED_JOURNAL_SEGMENT_BYTES), 0); + UT_ASSERT_EQ(ftruncate(active_fd, (off_t)PGRAC_FENCED_JOURNAL_SEGMENT_BYTES), 0); journal_state.segment_first_seq = 1; journal_state.next_seq = UINT64_C(262145); journal_state.segment_record_count = PGRAC_FENCED_JOURNAL_SEGMENT_RECORDS; journal_state.valid_bytes = PGRAC_FENCED_JOURNAL_SEGMENT_BYTES; - UT_ASSERT(pgrac_fenced_operation_acquire(&context, &request, - deadline_after_ms(1000), &response)); + UT_ASSERT( + pgrac_fenced_operation_acquire(&context, &request, deadline_after_ms(1000), &response)); UT_ASSERT_EQ(response.verdict, 1); UT_ASSERT_EQ(context.sealed_count, 1); UT_ASSERT_EQ(journal_state.next_seq, UINT64_C(262150)); UT_ASSERT(context.journal_fd >= 0); - (void) close(context.journal_fd); - (void) close(directory_fd); + (void)close(context.journal_fd); + (void)close(directory_fd); directory = opendir(directory_path); UT_ASSERT_NOT_NULL(directory); - if (directory != NULL) - { - while ((entry = readdir(directory)) != NULL) - { - if (strcmp(entry->d_name, ".") == 0 || - strcmp(entry->d_name, "..") == 0) + if (directory != NULL) { + char entry_path[MAXPGPATH]; + const struct dirent *entry; + + while ((entry = readdir(directory)) != NULL) { + if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) continue; - UT_ASSERT(snprintf(entry_path, sizeof(entry_path), "%s/%s", - directory_path, entry->d_name) > 0); + UT_ASSERT( + snprintf(entry_path, sizeof(entry_path), "%s/%s", directory_path, entry->d_name) + > 0); UT_ASSERT_EQ(unlink(entry_path), 0); } - (void) closedir(directory); + (void)closedir(directory); } UT_ASSERT_EQ(rmdir(directory_path), 0); } @@ -696,18 +685,16 @@ UT_TEST(test_preaccepted_execution_has_one_request_record) if (journal_fd < 0) return; make_request(&config, &request); - UT_ASSERT_EQ(pgrac_fenced_operation_accept(&context, &request, - deadline_after_ms(1000), &prepared, &response), - PGRAC_FENCED_OPERATION_READY); - UT_ASSERT_EQ(read_journal_records(journal_fd, records, - lengthof(records)), 2); - UT_ASSERT(pgrac_fenced_operation_execute_preaccepted(&context, &request, - &prepared, deadline_after_ms(1000), &response)); + UT_ASSERT_EQ(pgrac_fenced_operation_accept(&context, &request, deadline_after_ms(1000), + &prepared, &response), + PGRAC_FENCED_OPERATION_READY); + UT_ASSERT_EQ(read_journal_records(journal_fd, records, lengthof(records)), 2); + UT_ASSERT(pgrac_fenced_operation_execute_preaccepted(&context, &request, &prepared, + deadline_after_ms(1000), &response)); UT_ASSERT_EQ(response.verdict, 1); - UT_ASSERT_EQ(read_journal_records(journal_fd, records, - lengthof(records)), 6); - (void) close(journal_fd); - (void) unlink(path); + UT_ASSERT_EQ(read_journal_records(journal_fd, records, lengthof(records)), 6); + (void)close(journal_fd); + (void)unlink(path); } UT_TEST(test_joiner_gets_shared_durable_proof_from_owner_readback) @@ -735,38 +722,34 @@ UT_TEST(test_joiner_gets_shared_durable_proof_from_owner_readback) return; make_request(&config, &owner_request); joiner_request = owner_request; - memset(joiner_request.request_nonce, 0x52, - sizeof(joiner_request.request_nonce)); + memset(joiner_request.request_nonce, 0x52, sizeof(joiner_request.request_nonce)); deadline = deadline_after_ms(1000); - UT_ASSERT_EQ(pgrac_fenced_operation_accept(&context, &owner_request, - deadline, &owner_prepared, &owner_response), - PGRAC_FENCED_OPERATION_READY); - UT_ASSERT_EQ(pgrac_fenced_operation_accept(&context, &joiner_request, - deadline, &joiner_prepared, &joiner_response), - PGRAC_FENCED_OPERATION_READY); - UT_ASSERT(memcmp(owner_prepared.binding_digest, - joiner_prepared.binding_digest, - sizeof(owner_prepared.binding_digest)) == 0); - UT_ASSERT(pgrac_fenced_operation_execute_preaccepted(&context, - &owner_request, &owner_prepared, deadline, &owner_response)); + UT_ASSERT_EQ(pgrac_fenced_operation_accept(&context, &owner_request, deadline, &owner_prepared, + &owner_response), + PGRAC_FENCED_OPERATION_READY); + UT_ASSERT_EQ(pgrac_fenced_operation_accept(&context, &joiner_request, deadline, + &joiner_prepared, &joiner_response), + PGRAC_FENCED_OPERATION_READY); + UT_ASSERT(memcmp(owner_prepared.binding_digest, joiner_prepared.binding_digest, + sizeof(owner_prepared.binding_digest)) + == 0); + UT_ASSERT(pgrac_fenced_operation_execute_preaccepted(&context, &owner_request, &owner_prepared, + deadline, &owner_response)); UT_ASSERT_EQ(owner_response.verdict, 1); - UT_ASSERT(pgrac_fenced_operation_serve_joiner(&context, &joiner_request, - &joiner_prepared, &owner_response, deadline, &joiner_response)); + UT_ASSERT(pgrac_fenced_operation_serve_joiner(&context, &joiner_request, &joiner_prepared, + &owner_response, deadline, &joiner_response)); UT_ASSERT_EQ(joiner_response.verdict, 1); - UT_ASSERT_EQ(owner_response.proof_generation, - joiner_response.proof_generation); - UT_ASSERT(memcmp(owner_response.target_state_digest, - joiner_response.target_state_digest, - sizeof(owner_response.target_state_digest)) == 0); - UT_ASSERT_EQ(owner_response.verified_mono_ns, - joiner_response.verified_mono_ns); - UT_ASSERT(memcmp(joiner_response.request_nonce, - joiner_request.request_nonce, - sizeof(joiner_response.request_nonce)) == 0); - UT_ASSERT_EQ(read_journal_records(journal_fd, records, - lengthof(records)), 8); - (void) close(journal_fd); - (void) unlink(path); + UT_ASSERT_EQ(owner_response.proof_generation, joiner_response.proof_generation); + UT_ASSERT(memcmp(owner_response.target_state_digest, joiner_response.target_state_digest, + sizeof(owner_response.target_state_digest)) + == 0); + UT_ASSERT_EQ(owner_response.verified_mono_ns, joiner_response.verified_mono_ns); + UT_ASSERT(memcmp(joiner_response.request_nonce, joiner_request.request_nonce, + sizeof(joiner_response.request_nonce)) + == 0); + UT_ASSERT_EQ(read_journal_records(journal_fd, records, lengthof(records)), 8); + (void)close(journal_fd); + (void)unlink(path); } UT_TEST(test_restart_uncertainty_forces_readback_before_new_off_action) @@ -782,15 +765,14 @@ UT_TEST(test_restart_uncertainty_forces_readback_before_new_off_action) int fd; provider_mode = TEST_PROVIDER_PREFLIGHT_ON_THEN_OFF; - shared_provider_counts = mmap(NULL, sizeof(uint32) * 2, - PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0); + shared_provider_counts + = mmap(NULL, sizeof(uint32) * 2, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0); UT_ASSERT(shared_provider_counts != MAP_FAILED); - if (shared_provider_counts == MAP_FAILED) - { + if (shared_provider_counts == MAP_FAILED) { shared_provider_counts = NULL; return; } - memset((void *) shared_provider_counts, 0, sizeof(uint32) * 2); + memset((void *)shared_provider_counts, 0, sizeof(uint32) * 2); make_config(&config); make_ops(&ops); make_request(&config, &request); @@ -798,24 +780,19 @@ UT_TEST(test_restart_uncertainty_forces_readback_before_new_off_action) if (fd < 0) return; context.restart_fresh_readback_required = true; - UT_ASSERT(pgrac_fenced_operation_acquire(&context, &request, - deadline_after_ms(1000), &response)); + UT_ASSERT( + pgrac_fenced_operation_acquire(&context, &request, deadline_after_ms(1000), &response)); UT_ASSERT_EQ(response.verdict, 1); UT_ASSERT_EQ(shared_provider_counts[0], 1); UT_ASSERT_EQ(shared_provider_counts[1], 2); UT_ASSERT_EQ(read_journal_records(fd, records, lengthof(records)), 7); - UT_ASSERT_EQ(records[2].record_kind, - PGRAC_FENCED_JOURNAL_KIND_READBACK_RESULT); - UT_ASSERT_EQ(records[3].record_kind, - PGRAC_FENCED_JOURNAL_KIND_ACTUATION_ISSUED); - UT_ASSERT_EQ(records[5].record_kind, - PGRAC_FENCED_JOURNAL_KIND_READBACK_RESULT); - UT_ASSERT_EQ(records[6].record_kind, - PGRAC_FENCED_JOURNAL_KIND_PROOF_SERVED); - (void) close(fd); - (void) unlink(path); - UT_ASSERT_EQ(munmap((void *) shared_provider_counts, - sizeof(uint32) * 2), 0); + UT_ASSERT_EQ(records[2].record_kind, PGRAC_FENCED_JOURNAL_KIND_READBACK_RESULT); + UT_ASSERT_EQ(records[3].record_kind, PGRAC_FENCED_JOURNAL_KIND_ACTUATION_ISSUED); + UT_ASSERT_EQ(records[5].record_kind, PGRAC_FENCED_JOURNAL_KIND_READBACK_RESULT); + UT_ASSERT_EQ(records[6].record_kind, PGRAC_FENCED_JOURNAL_KIND_PROOF_SERVED); + (void)close(fd); + (void)unlink(path); + UT_ASSERT_EQ(munmap((void *)shared_provider_counts, sizeof(uint32) * 2), 0); shared_provider_counts = NULL; } @@ -848,19 +825,16 @@ UT_TEST(test_startup_reconcile_fsyncs_diagnostic_without_provider_action) record.target_state = PGRAC_FENCED_JOURNAL_TARGET_TRANSITIONING; UT_ASSERT(pgrac_fenced_journal_reconcile_observe(&reconcile, &record)); UT_ASSERT(pgrac_fenced_journal_reconcile_finish(&reconcile)); - UT_ASSERT(pgrac_fenced_operation_reconcile_startup(&context, - &reconcile)); + UT_ASSERT(pgrac_fenced_operation_reconcile_startup(&context, &reconcile)); UT_ASSERT(context.restart_fresh_readback_required); UT_ASSERT_EQ(reconcile.pending_count, 0); UT_ASSERT_EQ(read_journal_records(fd, records, lengthof(records)), 2); - UT_ASSERT_EQ(records[1].record_kind, - PGRAC_FENCED_JOURNAL_KIND_RECONCILED); - UT_ASSERT_EQ(records[1].target_state, - PGRAC_FENCED_JOURNAL_TARGET_UNKNOWN); - UT_ASSERT(memcmp(records[1].operation_id, record.operation_id, - sizeof(record.operation_id)) == 0); - (void) close(fd); - (void) unlink(path); + UT_ASSERT_EQ(records[1].record_kind, PGRAC_FENCED_JOURNAL_KIND_RECONCILED); + UT_ASSERT_EQ(records[1].target_state, PGRAC_FENCED_JOURNAL_TARGET_UNKNOWN); + UT_ASSERT(memcmp(records[1].operation_id, record.operation_id, sizeof(record.operation_id)) + == 0); + (void)close(fd); + (void)unlink(path); } UT_TEST(test_mapping_reload_is_durable_before_activation) @@ -885,24 +859,23 @@ UT_TEST(test_mapping_reload_is_durable_before_activation) candidate.mapping_generation++; candidate.nodes[3].target_uuid[0] ^= 1; memset(candidate_digest, 0x72, sizeof(candidate_digest)); - UT_ASSERT(pgrac_fenced_operation_prepare_mapping_reload(&context, - &candidate, &ops, candidate_digest)); + UT_ASSERT(pgrac_fenced_operation_prepare_mapping_reload(&context, &candidate, &ops, + candidate_digest)); UT_ASSERT_EQ(context.config->mapping_generation, 17); UT_ASSERT_EQ(read_journal_records(fd, records, lengthof(records)), 2); - UT_ASSERT_EQ(records[1].record_kind, - PGRAC_FENCED_JOURNAL_KIND_CONFIG_LOADED); + UT_ASSERT_EQ(records[1].record_kind, PGRAC_FENCED_JOURNAL_KIND_CONFIG_LOADED); UT_ASSERT_EQ(records[1].mapping_generation, 18); - UT_ASSERT(memcmp(records[1].semantic_config_digest, candidate_digest, - sizeof(candidate_digest)) == 0); - UT_ASSERT(!pgrac_fenced_operation_prepare_mapping_reload(&context, - &candidate, &ops, candidate_digest)); + UT_ASSERT(memcmp(records[1].semantic_config_digest, candidate_digest, sizeof(candidate_digest)) + == 0); + UT_ASSERT(!pgrac_fenced_operation_prepare_mapping_reload(&context, &candidate, &ops, + candidate_digest)); UT_ASSERT(pgrac_fenced_operation_activate_mapping_reload(&context)); UT_ASSERT_EQ(context.config->mapping_generation, 18); - UT_ASSERT(memcmp(context.semantic_config_digest, candidate_digest, - sizeof(candidate_digest)) == 0); + UT_ASSERT(memcmp(context.semantic_config_digest, candidate_digest, sizeof(candidate_digest)) + == 0); UT_ASSERT(!pgrac_fenced_operation_activate_mapping_reload(&context)); - (void) close(fd); - (void) unlink(path); + (void)close(fd); + (void)unlink(path); } int diff --git a/src/test/cluster_unit/test_pgrac_fenced_provider.c b/src/test/cluster_unit/test_pgrac_fenced_provider.c index 37c558483aa..939677ca2ba 100644 --- a/src/test/cluster_unit/test_pgrac_fenced_provider.c +++ b/src/test/cluster_unit/test_pgrac_fenced_provider.c @@ -29,11 +29,10 @@ static uint64_t expected_resolve_deadline; static volatile uint32 *retry_state; static PgracFencedProviderResult -test_resolve(const PgracFencedTargetV1 *configured, - PgracFencedTargetV1 *resolved, int32 *native_status) +test_resolve(const PgracFencedTargetV1 *configured, PgracFencedTargetV1 *resolved, + int32 *native_status) { - if (pgrac_fenced_provider_callback_deadline_mono_ns() != - expected_resolve_deadline) + if (pgrac_fenced_provider_callback_deadline_mono_ns() != expected_resolve_deadline) return PGRAC_FENCED_PROVIDER_CONFIG_ERROR; *resolved = *configured; *native_status = 0; @@ -41,8 +40,8 @@ test_resolve(const PgracFencedTargetV1 *configured, } static PgracFencedProviderResult -mismatch_resolve(const PgracFencedTargetV1 *configured, - PgracFencedTargetV1 *resolved, int32 *native_status) +mismatch_resolve(const PgracFencedTargetV1 *configured, PgracFencedTargetV1 *resolved, + int32 *native_status) { *resolved = *configured; resolved->target_uuid[0] ^= 1; @@ -51,42 +50,40 @@ mismatch_resolve(const PgracFencedTargetV1 *configured, } static PgracFencedProviderResult -slow_resolve(const PgracFencedTargetV1 *configured, - PgracFencedTargetV1 *resolved, int32 *native_status) +slow_resolve(const PgracFencedTargetV1 *configured, PgracFencedTargetV1 *resolved, + int32 *native_status) { - (void) configured; - (void) resolved; - (void) native_status; - (void) usleep(200000); + (void)configured; + (void)resolved; + (void)native_status; + (void)usleep(200000); return PGRAC_FENCED_PROVIDER_OK; } static PgracFencedProviderResult -test_actuate(const PgracFencedTargetV1 *target, - uint64_t deadline_mono_ns, int32 *native_status) +test_actuate(const PgracFencedTargetV1 *target, uint64_t deadline_mono_ns, int32 *native_status) { - (void) target; - (void) deadline_mono_ns; + (void)target; + (void)deadline_mono_ns; *native_status = 0; return PGRAC_FENCED_PROVIDER_OK; } static PgracFencedProviderResult -test_readback(const PgracFencedTargetV1 *target, - uint64_t deadline_mono_ns, PgracFencedReadbackV1 *out) +test_readback(const PgracFencedTargetV1 *target, uint64_t deadline_mono_ns, + PgracFencedReadbackV1 *out) { - (void) deadline_mono_ns; + (void)deadline_mono_ns; memset(out, 0, sizeof(*out)); out->state = PGRAC_FENCED_TARGET_OFF; out->io_drain_state = PGRAC_FENCED_IO_DRAIN_DRAINED; - memcpy(out->observed_target_uuid, target->target_uuid, - sizeof(out->observed_target_uuid)); + memcpy(out->observed_target_uuid, target->target_uuid, sizeof(out->observed_target_uuid)); return PGRAC_FENCED_PROVIDER_OK; } static PgracFencedProviderResult -retry_readback(const PgracFencedTargetV1 *target, - uint64_t deadline_mono_ns, PgracFencedReadbackV1 *out) +retry_readback(const PgracFencedTargetV1 *target, uint64_t deadline_mono_ns, + PgracFencedReadbackV1 *out) { retry_state[0]++; if (retry_state[0] <= retry_state[1]) @@ -96,49 +93,43 @@ retry_readback(const PgracFencedTargetV1 *target, static void test_shutdown(void) -{ -} +{} static PgracFencedProviderResult -crash_actuate(const PgracFencedTargetV1 *target, - uint64_t deadline_mono_ns, int32 *native_status) +crash_actuate(const PgracFencedTargetV1 *target, uint64_t deadline_mono_ns, int32 *native_status) { - (void) target; - (void) deadline_mono_ns; - (void) native_status; + (void)target; + (void)deadline_mono_ns; + (void)native_status; _exit(9); } static PgracFencedProviderResult -slow_actuate(const PgracFencedTargetV1 *target, - uint64_t deadline_mono_ns, int32 *native_status) +slow_actuate(const PgracFencedTargetV1 *target, uint64_t deadline_mono_ns, int32 *native_status) { - (void) target; - (void) deadline_mono_ns; - (void) native_status; - (void) usleep(200000); + (void)target; + (void)deadline_mono_ns; + (void)native_status; + (void)usleep(200000); return PGRAC_FENCED_PROVIDER_OK; } static PgracFencedProviderResult -tree_actuate(const PgracFencedTargetV1 *target, - uint64_t deadline_mono_ns, int32 *native_status) +tree_actuate(const PgracFencedTargetV1 *target, uint64_t deadline_mono_ns, int32 *native_status) { pid_t child; - (void) target; - (void) deadline_mono_ns; - (void) native_status; + (void)target; + (void)deadline_mono_ns; + (void)native_status; child = fork(); if (child < 0) _exit(91); - if (child == 0) - { + if (child == 0) { pid_t self = getpid(); - (void) signal(SIGTERM, SIG_IGN); - if (descendant_pid_fd < 0 || - write(descendant_pid_fd, &self, sizeof(self)) != sizeof(self)) + (void)signal(SIGTERM, SIG_IGN); + if (descendant_pid_fd < 0 || write(descendant_pid_fd, &self, sizeof(self)) != sizeof(self)) _exit(92); for (;;) pause(); @@ -148,46 +139,41 @@ tree_actuate(const PgracFencedTargetV1 *target, } static PgracFencedProviderResult -success_with_lingering_descendant_actuate( - const PgracFencedTargetV1 *target, uint64_t deadline_mono_ns, - int32 *native_status) +success_with_lingering_descendant_actuate(const PgracFencedTargetV1 *target, + uint64_t deadline_mono_ns, int32 *native_status) { char ready; int ready_pipe[2]; pid_t child; ssize_t got; - (void) target; - (void) deadline_mono_ns; + (void)target; + (void)deadline_mono_ns; if (pipe(ready_pipe) != 0) return PGRAC_FENCED_PROVIDER_UNKNOWN; child = fork(); - if (child < 0) - { - (void) close(ready_pipe[0]); - (void) close(ready_pipe[1]); + if (child < 0) { + (void)close(ready_pipe[0]); + (void)close(ready_pipe[1]); return PGRAC_FENCED_PROVIDER_UNKNOWN; } - if (child == 0) - { + if (child == 0) { pid_t self = getpid(); - (void) close(ready_pipe[0]); - (void) signal(SIGTERM, SIG_IGN); - if (descendant_pid_fd < 0 || - write(descendant_pid_fd, &self, sizeof(self)) != sizeof(self) || - write(ready_pipe[1], "R", 1) != 1) + (void)close(ready_pipe[0]); + (void)signal(SIGTERM, SIG_IGN); + if (descendant_pid_fd < 0 || write(descendant_pid_fd, &self, sizeof(self)) != sizeof(self) + || write(ready_pipe[1], "R", 1) != 1) _exit(92); - (void) close(ready_pipe[1]); + (void)close(ready_pipe[1]); for (;;) pause(); } - (void) close(ready_pipe[1]); - do - { + (void)close(ready_pipe[1]); + do { got = read(ready_pipe[0], &ready, 1); } while (got < 0 && errno == EINTR); - (void) close(ready_pipe[0]); + (void)close(ready_pipe[0]); if (got != 1) return PGRAC_FENCED_PROVIDER_UNKNOWN; *native_status = 0; @@ -200,8 +186,8 @@ deadline_after_ms(uint64_t milliseconds) struct timespec now; UT_ASSERT_EQ(clock_gettime(CLOCK_MONOTONIC, &now), 0); - return (uint64_t) now.tv_sec * UINT64_C(1000000000) + - (uint64_t) now.tv_nsec + milliseconds * UINT64_C(1000000); + return (uint64_t)now.tv_sec * UINT64_C(1000000000) + (uint64_t)now.tv_nsec + + milliseconds * UINT64_C(1000000); } static bool @@ -209,11 +195,10 @@ process_gone(pid_t pid) { int attempts; - for (attempts = 0; attempts < 100; attempts++) - { + for (attempts = 0; attempts < 100; attempts++) { if (kill(pid, 0) != 0 && errno == ESRCH) return true; - (void) usleep(10000); + (void)usleep(10000); } return false; } @@ -247,10 +232,8 @@ UT_TEST(test_production_registry_honors_fexecve_gate) { const PgracFencedProviderOpsV1 *ops; - UT_ASSERT_NULL(pgrac_fenced_provider_lookup( - PGRAC_FENCED_PROVIDER_ID_UNAVAILABLE)); - UT_ASSERT_NULL(pgrac_fenced_provider_lookup( - PGRAC_FENCED_PROVIDER_ID_TEST_ONLY)); + UT_ASSERT_NULL(pgrac_fenced_provider_lookup(PGRAC_FENCED_PROVIDER_ID_UNAVAILABLE)); + UT_ASSERT_NULL(pgrac_fenced_provider_lookup(PGRAC_FENCED_PROVIDER_ID_TEST_ONLY)); ops = pgrac_fenced_provider_lookup(UINT16_C(0x0100)); #ifdef HAVE_FEXECVE UT_ASSERT_NOT_NULL(ops); @@ -292,39 +275,38 @@ UT_TEST(test_recovery_terminal_matrix_is_exact) memset(expected_uuid, 0x42, sizeof(expected_uuid)); memset(&readback, 0, sizeof(readback)); - memcpy(readback.observed_target_uuid, expected_uuid, - sizeof(expected_uuid)); + memcpy(readback.observed_target_uuid, expected_uuid, sizeof(expected_uuid)); readback.state = PGRAC_FENCED_TARGET_OFF; readback.io_drain_state = PGRAC_FENCED_IO_DRAIN_DRAINED; - UT_ASSERT_EQ(pgrac_fenced_provider_classify_recovery( - PGRAC_FENCED_PROVIDER_OK, expected_uuid, &readback), + UT_ASSERT_EQ( + pgrac_fenced_provider_classify_recovery(PGRAC_FENCED_PROVIDER_OK, expected_uuid, &readback), PGRAC_FENCED_PROVIDER_TERMINAL_PROVEN); readback.io_drain_state = PGRAC_FENCED_IO_DRAIN_NOT_DRAINED; - UT_ASSERT_EQ(pgrac_fenced_provider_classify_recovery( - PGRAC_FENCED_PROVIDER_OK, expected_uuid, &readback), + UT_ASSERT_EQ( + pgrac_fenced_provider_classify_recovery(PGRAC_FENCED_PROVIDER_OK, expected_uuid, &readback), PGRAC_FENCED_PROVIDER_TERMINAL_REJECTED); readback.state = PGRAC_FENCED_TARGET_ON; readback.io_drain_state = PGRAC_FENCED_IO_DRAIN_DRAINED; - UT_ASSERT_EQ(pgrac_fenced_provider_classify_recovery( - PGRAC_FENCED_PROVIDER_OK, expected_uuid, &readback), + UT_ASSERT_EQ( + pgrac_fenced_provider_classify_recovery(PGRAC_FENCED_PROVIDER_OK, expected_uuid, &readback), PGRAC_FENCED_PROVIDER_TERMINAL_REJECTED); readback.state = PGRAC_FENCED_TARGET_UNKNOWN; - UT_ASSERT_EQ(pgrac_fenced_provider_classify_recovery( - PGRAC_FENCED_PROVIDER_OK, expected_uuid, &readback), + UT_ASSERT_EQ( + pgrac_fenced_provider_classify_recovery(PGRAC_FENCED_PROVIDER_OK, expected_uuid, &readback), PGRAC_FENCED_PROVIDER_TERMINAL_UNKNOWN); readback.state = PGRAC_FENCED_TARGET_OFF; readback.io_drain_state = PGRAC_FENCED_IO_DRAIN_DRAINED; readback.observed_target_uuid[0] ^= 1; - UT_ASSERT_EQ(pgrac_fenced_provider_classify_recovery( - PGRAC_FENCED_PROVIDER_OK, expected_uuid, &readback), + UT_ASSERT_EQ( + pgrac_fenced_provider_classify_recovery(PGRAC_FENCED_PROVIDER_OK, expected_uuid, &readback), PGRAC_FENCED_PROVIDER_TERMINAL_REJECTED); - UT_ASSERT_EQ(pgrac_fenced_provider_classify_recovery( - PGRAC_FENCED_PROVIDER_IO_ERROR, expected_uuid, &readback), - PGRAC_FENCED_PROVIDER_TERMINAL_UNKNOWN); - UT_ASSERT_EQ(pgrac_fenced_provider_classify_recovery( - PGRAC_FENCED_PROVIDER_UNAVAILABLE, expected_uuid, &readback), - PGRAC_FENCED_PROVIDER_TERMINAL_UNAVAILABLE); + UT_ASSERT_EQ(pgrac_fenced_provider_classify_recovery(PGRAC_FENCED_PROVIDER_IO_ERROR, + expected_uuid, &readback), + PGRAC_FENCED_PROVIDER_TERMINAL_UNKNOWN); + UT_ASSERT_EQ(pgrac_fenced_provider_classify_recovery(PGRAC_FENCED_PROVIDER_UNAVAILABLE, + expected_uuid, &readback), + PGRAC_FENCED_PROVIDER_TERMINAL_UNAVAILABLE); } UT_TEST(test_rejoin_on_requires_exact_on_drained) @@ -334,22 +316,21 @@ UT_TEST(test_rejoin_on_requires_exact_on_drained) memset(expected_uuid, 0x24, sizeof(expected_uuid)); memset(&readback, 0, sizeof(readback)); - memcpy(readback.observed_target_uuid, expected_uuid, - sizeof(expected_uuid)); + memcpy(readback.observed_target_uuid, expected_uuid, sizeof(expected_uuid)); readback.state = PGRAC_FENCED_TARGET_ON; readback.io_drain_state = PGRAC_FENCED_IO_DRAIN_DRAINED; - UT_ASSERT_EQ(pgrac_fenced_provider_classify_rejoin_on( - PGRAC_FENCED_PROVIDER_OK, expected_uuid, &readback), - PGRAC_FENCED_PROVIDER_TERMINAL_PROVEN); + UT_ASSERT_EQ(pgrac_fenced_provider_classify_rejoin_on(PGRAC_FENCED_PROVIDER_OK, expected_uuid, + &readback), + PGRAC_FENCED_PROVIDER_TERMINAL_PROVEN); readback.io_drain_state = PGRAC_FENCED_IO_DRAIN_UNKNOWN; - UT_ASSERT_EQ(pgrac_fenced_provider_classify_rejoin_on( - PGRAC_FENCED_PROVIDER_OK, expected_uuid, &readback), - PGRAC_FENCED_PROVIDER_TERMINAL_UNKNOWN); + UT_ASSERT_EQ(pgrac_fenced_provider_classify_rejoin_on(PGRAC_FENCED_PROVIDER_OK, expected_uuid, + &readback), + PGRAC_FENCED_PROVIDER_TERMINAL_UNKNOWN); readback.state = PGRAC_FENCED_TARGET_OFF; readback.io_drain_state = PGRAC_FENCED_IO_DRAIN_DRAINED; - UT_ASSERT_EQ(pgrac_fenced_provider_classify_rejoin_on( - PGRAC_FENCED_PROVIDER_OK, expected_uuid, &readback), - PGRAC_FENCED_PROVIDER_TERMINAL_REJECTED); + UT_ASSERT_EQ(pgrac_fenced_provider_classify_rejoin_on(PGRAC_FENCED_PROVIDER_OK, expected_uuid, + &readback), + PGRAC_FENCED_PROVIDER_TERMINAL_REJECTED); } UT_TEST(test_worker_actuation_and_readback_return_exact_results) @@ -366,20 +347,19 @@ UT_TEST(test_worker_actuation_and_readback_return_exact_results) target.victim_node_id = 2; target.mapping_generation = 7; UT_ASSERT_EQ(pgrac_fenced_provider_worker_actuate( - &ops, true, false, &target, deadline_after_ms(1000), - &result, &native_status), PGRAC_FENCED_PROVIDER_WORKER_OK); + &ops, true, false, &target, deadline_after_ms(1000), &result, &native_status), + PGRAC_FENCED_PROVIDER_WORKER_OK); UT_ASSERT_EQ(result, PGRAC_FENCED_PROVIDER_OK); UT_ASSERT_EQ(native_status, 0); - UT_ASSERT_EQ(pgrac_fenced_provider_worker_readback( - &ops, true, &target, deadline_after_ms(1000), &result, &readback), - PGRAC_FENCED_PROVIDER_WORKER_OK); + UT_ASSERT_EQ(pgrac_fenced_provider_worker_readback(&ops, true, &target, deadline_after_ms(1000), + &result, &readback), + PGRAC_FENCED_PROVIDER_WORKER_OK); UT_ASSERT_EQ(result, PGRAC_FENCED_PROVIDER_OK); UT_ASSERT_EQ(readback.state, PGRAC_FENCED_TARGET_OFF); - UT_ASSERT_EQ(readback.io_drain_state, - PGRAC_FENCED_IO_DRAIN_DRAINED); - UT_ASSERT(memcmp(readback.observed_target_uuid, target.target_uuid, - sizeof(target.target_uuid)) == 0); + UT_ASSERT_EQ(readback.io_drain_state, PGRAC_FENCED_IO_DRAIN_DRAINED); + UT_ASSERT(memcmp(readback.observed_target_uuid, target.target_uuid, sizeof(target.target_uuid)) + == 0); } UT_TEST(test_worker_readback_retries_on_exact_backoff_schedule) @@ -409,8 +389,7 @@ UT_TEST(test_worker_readback_retries_on_exact_backoff_schedule) UT_ASSERT_EQ(retry_state[0], 3); UT_ASSERT(finished >= started + UINT64_C(250000000)); UT_ASSERT_EQ(readback.state, PGRAC_FENCED_TARGET_OFF); - UT_ASSERT_EQ(readback.io_drain_state, - PGRAC_FENCED_IO_DRAIN_DRAINED); + UT_ASSERT_EQ(readback.io_drain_state, PGRAC_FENCED_IO_DRAIN_DRAINED); } UT_TEST(test_worker_resolve_inherits_deadline_and_rebuilds_local_target) @@ -419,7 +398,7 @@ UT_TEST(test_worker_resolve_inherits_deadline_and_rebuilds_local_target) PgracFencedTargetV1 configured; PgracFencedTargetV1 resolved; PgracFencedProviderResult result; - uint8 adapter_config[4] = {1, 2, 3, 4}; + uint8 adapter_config[4] = { 1, 2, 3, 4 }; uint64_t deadline = deadline_after_ms(1000); int32 native_status = -1; @@ -432,13 +411,13 @@ UT_TEST(test_worker_resolve_inherits_deadline_and_rebuilds_local_target) configured.adapter_config_len = sizeof(adapter_config); expected_resolve_deadline = deadline; memset(&resolved, 0x7f, sizeof(resolved)); - UT_ASSERT_EQ(pgrac_fenced_provider_worker_resolve( - &ops, true, &configured, deadline, &result, &resolved, - &native_status), PGRAC_FENCED_PROVIDER_WORKER_OK); + UT_ASSERT_EQ(pgrac_fenced_provider_worker_resolve(&ops, true, &configured, deadline, &result, + &resolved, &native_status), + PGRAC_FENCED_PROVIDER_WORKER_OK); UT_ASSERT_EQ(result, PGRAC_FENCED_PROVIDER_OK); UT_ASSERT_EQ(native_status, 0); - UT_ASSERT(memcmp(resolved.target_uuid, configured.target_uuid, - sizeof(configured.target_uuid)) == 0); + UT_ASSERT(memcmp(resolved.target_uuid, configured.target_uuid, sizeof(configured.target_uuid)) + == 0); UT_ASSERT_EQ(resolved.victim_node_id, configured.victim_node_id); UT_ASSERT_EQ(resolved.mapping_generation, configured.mapping_generation); UT_ASSERT(resolved.adapter_config == configured.adapter_config); @@ -459,17 +438,19 @@ UT_TEST(test_worker_resolve_rejects_mismatch_and_times_out) configured.victim_node_id = 8; configured.mapping_generation = 20; ops.resolve = mismatch_resolve; - UT_ASSERT_EQ(pgrac_fenced_provider_worker_resolve( - &ops, true, &configured, deadline_after_ms(1000), &result, - &resolved, &native_status), PGRAC_FENCED_PROVIDER_WORKER_OK); + UT_ASSERT_EQ(pgrac_fenced_provider_worker_resolve(&ops, true, &configured, + deadline_after_ms(1000), &result, &resolved, + &native_status), + PGRAC_FENCED_PROVIDER_WORKER_OK); UT_ASSERT_EQ(result, PGRAC_FENCED_PROVIDER_REJECTED); UT_ASSERT_EQ(resolved.mapping_generation, 0); ops.resolve = slow_resolve; result = PGRAC_FENCED_PROVIDER_OK; - UT_ASSERT_EQ(pgrac_fenced_provider_worker_resolve( - &ops, true, &configured, deadline_after_ms(20), &result, - &resolved, &native_status), PGRAC_FENCED_PROVIDER_WORKER_TIMEOUT); + UT_ASSERT_EQ(pgrac_fenced_provider_worker_resolve(&ops, true, &configured, + deadline_after_ms(20), &result, &resolved, + &native_status), + PGRAC_FENCED_PROVIDER_WORKER_TIMEOUT); UT_ASSERT_NE(result, PGRAC_FENCED_PROVIDER_OK); UT_ASSERT_EQ(resolved.mapping_generation, 0); } @@ -487,16 +468,16 @@ UT_TEST(test_worker_crash_and_timeout_never_return_provider_success) target.mapping_generation = 8; ops.actuate_off = crash_actuate; UT_ASSERT_EQ(pgrac_fenced_provider_worker_actuate( - &ops, true, false, &target, deadline_after_ms(1000), - &result, &native_status), PGRAC_FENCED_PROVIDER_WORKER_CRASHED); + &ops, true, false, &target, deadline_after_ms(1000), &result, &native_status), + PGRAC_FENCED_PROVIDER_WORKER_CRASHED); UT_ASSERT_NE(result, PGRAC_FENCED_PROVIDER_OK); make_test_ops(&ops); ops.actuate_off = slow_actuate; result = PGRAC_FENCED_PROVIDER_OK; UT_ASSERT_EQ(pgrac_fenced_provider_worker_actuate( - &ops, true, false, &target, deadline_after_ms(20), - &result, &native_status), PGRAC_FENCED_PROVIDER_WORKER_TIMEOUT); + &ops, true, false, &target, deadline_after_ms(20), &result, &native_status), + PGRAC_FENCED_PROVIDER_WORKER_TIMEOUT); UT_ASSERT_NE(result, PGRAC_FENCED_PROVIDER_OK); } @@ -523,21 +504,20 @@ UT_TEST(test_worker_timeout_drains_descendant_process_group) return; descendant_pid_fd = pid_pipe[1]; UT_ASSERT_EQ(pgrac_fenced_provider_worker_actuate( - &ops, true, false, &target, deadline_after_ms(20), - &result, &native_status), PGRAC_FENCED_PROVIDER_WORKER_TIMEOUT); - (void) close(pid_pipe[1]); + &ops, true, false, &target, deadline_after_ms(20), &result, &native_status), + PGRAC_FENCED_PROVIDER_WORKER_TIMEOUT); + (void)close(pid_pipe[1]); descendant_pid_fd = -1; - do - { + do { got = read(pid_pipe[0], &descendant, sizeof(descendant)); } while (got < 0 && errno == EINTR); - (void) close(pid_pipe[0]); + (void)close(pid_pipe[0]); UT_ASSERT_EQ(got, sizeof(descendant)); if (got != sizeof(descendant)) return; gone = process_gone(descendant); if (!gone) - (void) kill(descendant, SIGKILL); + (void)kill(descendant, SIGKILL); UT_ASSERT(gone); } @@ -563,44 +543,40 @@ UT_TEST(test_worker_success_drains_descendants_after_leader_reap) descendant_pid_fd = pid_pipe[1]; runner = fork(); UT_ASSERT(runner >= 0); - if (runner == 0) - { + if (runner == 0) { PgracFencedProviderResult result = PGRAC_FENCED_PROVIDER_UNKNOWN; int32 native_status = -1; PgracFencedProviderWorkerResult worker_result; - (void) close(pid_pipe[0]); + (void)close(pid_pipe[0]); worker_result = pgrac_fenced_provider_worker_actuate( - &ops, true, false, &target, deadline_after_ms(3000), - &result, &native_status); - (void) close(pid_pipe[1]); - _exit(worker_result == PGRAC_FENCED_PROVIDER_WORKER_OK && - result == PGRAC_FENCED_PROVIDER_OK && native_status == 0 ? 0 : 1); + &ops, true, false, &target, deadline_after_ms(3000), &result, &native_status); + (void)close(pid_pipe[1]); + _exit(worker_result == PGRAC_FENCED_PROVIDER_WORKER_OK && result == PGRAC_FENCED_PROVIDER_OK + && native_status == 0 + ? 0 + : 1); } - (void) close(pid_pipe[1]); + (void)close(pid_pipe[1]); descendant_pid_fd = -1; - for (attempts = 0; attempts < 400; attempts++) - { + for (attempts = 0; attempts < 400; attempts++) { waited = waitpid(runner, &status, WNOHANG); if (waited != 0) break; - (void) usleep(10000); + (void)usleep(10000); } - if (waited == 0) - { - (void) kill(runner, SIGKILL); - do - { + if (waited == 0) { + (void)kill(runner, SIGKILL); + do { waited = waitpid(runner, &status, 0); } while (waited < 0 && errno == EINTR); } - do - { + do { got = read(pid_pipe[0], &descendant, sizeof(descendant)); } while (got < 0 && errno == EINTR); - (void) close(pid_pipe[0]); + (void)close(pid_pipe[0]); if (got == sizeof(descendant) && !process_gone(descendant)) - (void) kill(descendant, SIGKILL); + (void)kill(descendant, SIGKILL); gone = got == sizeof(descendant) && process_gone(descendant); UT_ASSERT_EQ(waited, runner); UT_ASSERT(attempts < 400); @@ -620,16 +596,16 @@ UT_TEST(test_worker_rejects_test_provider_without_test_gate) make_test_ops(&ops); memset(&target, 0, sizeof(target)); UT_ASSERT_EQ(pgrac_fenced_provider_worker_actuate( - &ops, false, false, &target, deadline_after_ms(1000), - &result, &native_status), PGRAC_FENCED_PROVIDER_WORKER_UNAVAILABLE); + &ops, false, false, &target, deadline_after_ms(1000), &result, &native_status), + PGRAC_FENCED_PROVIDER_WORKER_UNAVAILABLE); UT_ASSERT_EQ(result, PGRAC_FENCED_PROVIDER_UNAVAILABLE); } int main(void) { - retry_state = mmap(NULL, sizeof(uint32) * 2, - PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0); + retry_state + = mmap(NULL, sizeof(uint32) * 2, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0); if (retry_state == MAP_FAILED) return 1; UT_PLAN(13); @@ -647,6 +623,6 @@ main(void) UT_RUN(test_worker_success_drains_descendants_after_leader_reap); UT_RUN(test_worker_rejects_test_provider_without_test_gate); UT_DONE(); - (void) munmap((void *) retry_state, sizeof(uint32) * 2); + (void)munmap((void *)retry_state, sizeof(uint32) * 2); return ut_failed_count == 0 ? 0 : 1; } diff --git a/src/test/cluster_unit/test_pgrac_fenced_rejoin.c b/src/test/cluster_unit/test_pgrac_fenced_rejoin.c index 5753a518a19..061f1cd397d 100644 --- a/src/test/cluster_unit/test_pgrac_fenced_rejoin.c +++ b/src/test/cluster_unit/test_pgrac_fenced_rejoin.c @@ -26,12 +26,11 @@ UT_DEFINE_GLOBALS(); static volatile uint32 *provider_state; static PgracFencedProviderResult -test_resolve(const PgracFencedTargetV1 *configured, - PgracFencedTargetV1 *resolved, int32 *native_status) +test_resolve(const PgracFencedTargetV1 *configured, PgracFencedTargetV1 *resolved, + int32 *native_status) { provider_state[0]++; - if (provider_state[7] != 0) - { + if (provider_state[7] != 0) { *native_status = 71; return PGRAC_FENCED_PROVIDER_CONFIG_ERROR; } @@ -41,24 +40,22 @@ test_resolve(const PgracFencedTargetV1 *configured, } static PgracFencedProviderResult -test_actuate_off(const PgracFencedTargetV1 *target, - uint64_t deadline_mono_ns, int32 *native_status) +test_actuate_off(const PgracFencedTargetV1 *target, uint64_t deadline_mono_ns, int32 *native_status) { - (void) target; - (void) deadline_mono_ns; + (void)target; + (void)deadline_mono_ns; provider_state[1]++; *native_status = 0; return PGRAC_FENCED_PROVIDER_OK; } static PgracFencedProviderResult -test_readback(const PgracFencedTargetV1 *target, - uint64_t deadline_mono_ns, PgracFencedReadbackV1 *readback) +test_readback(const PgracFencedTargetV1 *target, uint64_t deadline_mono_ns, + PgracFencedReadbackV1 *readback) { - (void) deadline_mono_ns; + (void)deadline_mono_ns; provider_state[2]++; - if (provider_state[6] > 0) - { + if (provider_state[6] > 0) { provider_state[6]--; return PGRAC_FENCED_PROVIDER_UNKNOWN; } @@ -71,11 +68,10 @@ test_readback(const PgracFencedTargetV1 *target, } static PgracFencedProviderResult -test_actuate_on(const PgracFencedTargetV1 *target, - uint64_t deadline_mono_ns, int32 *native_status) +test_actuate_on(const PgracFencedTargetV1 *target, uint64_t deadline_mono_ns, int32 *native_status) { - (void) target; - (void) deadline_mono_ns; + (void)target; + (void)deadline_mono_ns; provider_state[3]++; provider_state[4] = PGRAC_FENCED_TARGET_ON; *native_status = 0; @@ -84,8 +80,7 @@ test_actuate_on(const PgracFencedTargetV1 *target, static void test_shutdown(void) -{ -} +{} static uint64 deadline_after_ms(uint64 milliseconds) @@ -93,8 +88,8 @@ deadline_after_ms(uint64 milliseconds) struct timespec now; UT_ASSERT_EQ(clock_gettime(CLOCK_MONOTONIC, &now), 0); - return (uint64) now.tv_sec * UINT64_C(1000000000) + - (uint64) now.tv_nsec + milliseconds * UINT64_C(1000000); + return (uint64)now.tv_sec * UINT64_C(1000000000) + (uint64)now.tv_nsec + + milliseconds * UINT64_C(1000000); } static void @@ -110,11 +105,9 @@ make_config(PgracFencedConfigV1 *config) config->provider_abi = PGRAC_FENCED_PROVIDER_ABI_V1; config->node_count = 2; config->nodes[3].present = true; - memset(config->nodes[3].target_uuid, 0x41, - sizeof(config->nodes[3].target_uuid)); + memset(config->nodes[3].target_uuid, 0x41, sizeof(config->nodes[3].target_uuid)); config->nodes[5].present = true; - memset(config->nodes[5].target_uuid, 0x51, - sizeof(config->nodes[5].target_uuid)); + memset(config->nodes[5].target_uuid, 0x51, sizeof(config->nodes[5].target_uuid)); } static void @@ -134,10 +127,8 @@ make_ops(PgracFencedProviderOpsV1 *ops) static int open_context(PgracFencedOperationContextV1 *operation_context, - PgracFencedRejoinContextV1 *rejoin_context, - PgracFencedJournalScanState *journal_state, - PgracFencedConfigV1 *config, PgracFencedProviderOpsV1 *ops, - char path[64]) + PgracFencedRejoinContextV1 *rejoin_context, PgracFencedJournalScanState *journal_state, + PgracFencedConfigV1 *config, PgracFencedProviderOpsV1 *ops, char path[64]) { uint8 config_digest[32]; uint8 daemon_boot_id[16]; @@ -152,21 +143,19 @@ open_context(PgracFencedOperationContextV1 *operation_context, return -1; UT_ASSERT_EQ(fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_APPEND), 0); pgrac_fenced_journal_scan_state_init(journal_state); - UT_ASSERT(pgrac_fenced_operation_context_init(operation_context, config, - ops, true, config_digest, daemon_boot_id, fd, journal_state)); + UT_ASSERT(pgrac_fenced_operation_context_init( + operation_context, config, ops, true, config_digest, daemon_boot_id, fd, journal_state)); UT_ASSERT(pgrac_fenced_rejoin_init(rejoin_context, operation_context)); return fd; } static void -make_prepare(int node_id, uint64 old_incarnation, - uint64 candidate_incarnation, uint8 nonce, +make_prepare(int node_id, uint64 old_incarnation, uint64 candidate_incarnation, uint8 nonce, PgracExternalFenceProtocolRejoinFrameV1 *request) { memset(request, 0, sizeof(*request)); request->opcode = PGRAC_EXTERNAL_FENCE_REJOIN_ADMIN_PREPARE; - memset(request->transport_nonce, nonce, - sizeof(request->transport_nonce)); + memset(request->transport_nonce, nonce, sizeof(request->transport_nonce)); request->old_node_id = node_id; request->old_incarnation = old_incarnation; request->candidate_incarnation = candidate_incarnation; @@ -174,30 +163,23 @@ make_prepare(int node_id, uint64 old_incarnation, } static void -make_claim(uint8 nonce, - PgracExternalFenceProtocolRejoinFrameV1 *request) +make_claim(uint8 nonce, PgracExternalFenceProtocolRejoinFrameV1 *request) { memset(request, 0, sizeof(*request)); request->opcode = PGRAC_EXTERNAL_FENCE_REJOIN_LMON_CLAIM_NEXT; - memset(request->transport_nonce, nonce, - sizeof(request->transport_nonce)); + memset(request->transport_nonce, nonce, sizeof(request->transport_nonce)); } static void -make_bound_request(uint16 opcode, - const PgracExternalFenceProtocolRejoinFrameV1 *source, - uint8 nonce, - PgracExternalFenceProtocolRejoinFrameV1 *request) +make_bound_request(uint16 opcode, const PgracExternalFenceProtocolRejoinFrameV1 *source, + uint8 nonce, PgracExternalFenceProtocolRejoinFrameV1 *request) { memset(request, 0, sizeof(*request)); request->opcode = opcode; - memset(request->transport_nonce, nonce, - sizeof(request->transport_nonce)); - memcpy(request->operation_id, source->operation_id, - sizeof(request->operation_id)); + memset(request->transport_nonce, nonce, sizeof(request->transport_nonce)); + memcpy(request->operation_id, source->operation_id, sizeof(request->operation_id)); request->system_identifier = source->system_identifier; - memset(request->rejoin_gate_digest, 0x91, - sizeof(request->rejoin_gate_digest)); + memset(request->rejoin_gate_digest, 0x91, sizeof(request->rejoin_gate_digest)); memcpy(request->protected_set_digest, source->protected_set_digest, sizeof(request->protected_set_digest)); request->old_node_id = source->old_node_id; @@ -214,10 +196,8 @@ read_records(int fd, PgracFencedJournalRecordV1 *records, size_t maximum) ssize_t got; UT_ASSERT_EQ(lseek(fd, 0, SEEK_SET), 0); - while (count < maximum) - { - do - { + while (count < maximum) { + do { got = read(fd, frame, sizeof(frame)); } while (got < 0 && errno == EINTR); if (got == 0) @@ -225,8 +205,7 @@ read_records(int fd, PgracFencedJournalRecordV1 *records, size_t maximum) UT_ASSERT_EQ(got, sizeof(frame)); if (got != sizeof(frame)) break; - UT_ASSERT(pgrac_fenced_journal_record_decode(frame, sizeof(frame), - &records[count])); + UT_ASSERT(pgrac_fenced_journal_record_decode(frame, sizeof(frame), &records[count])); count++; } return count; @@ -250,47 +229,43 @@ UT_TEST(test_admin_prepare_is_inert_durable_and_duplicate_stable) make_config(&config); make_ops(&ops); - memset((void *) provider_state, 0, sizeof(uint32) * 8); + memset((void *)provider_state, 0, sizeof(uint32) * 8); provider_state[4] = PGRAC_FENCED_TARGET_OFF; provider_state[5] = PGRAC_FENCED_IO_DRAIN_DRAINED; - fd = open_context(&operation_context, &context, &journal_state, - &config, &ops, path); + fd = open_context(&operation_context, &context, &journal_state, &config, &ops, path); if (fd < 0) return; make_prepare(3, 70, 77, 0x61, &request); memset(operation_id, 0xa1, sizeof(operation_id)); - UT_ASSERT(pgrac_fenced_rejoin_admin_prepare(&context, &request, - operation_id, deadline_after_ms(1000), &response)); + UT_ASSERT(pgrac_fenced_rejoin_admin_prepare(&context, &request, operation_id, + deadline_after_ms(1000), &response)); UT_ASSERT_EQ(response.status, PGRAC_FENCED_REJOIN_STATUS_OFFERED); - UT_ASSERT(memcmp(response.operation_id, operation_id, - sizeof(operation_id)) == 0); + UT_ASSERT(memcmp(response.operation_id, operation_id, sizeof(operation_id)) == 0); UT_ASSERT(pgrac_external_fence_rejoin_v1_encode(&response, frame)); UT_ASSERT_EQ(context.operation_count, 1); UT_ASSERT_EQ(provider_state[0], 1); UT_ASSERT_EQ(provider_state[1], 0); UT_ASSERT_EQ(provider_state[3], 0); UT_ASSERT_EQ(read_records(fd, records, lengthof(records)), 2); - UT_ASSERT_EQ(records[1].record_kind, - PGRAC_FENCED_JOURNAL_KIND_REENABLE_REQUESTED); + UT_ASSERT_EQ(records[1].record_kind, PGRAC_FENCED_JOURNAL_KIND_REENABLE_REQUESTED); memset(duplicate_id, 0xb1, sizeof(duplicate_id)); - UT_ASSERT(pgrac_fenced_rejoin_admin_prepare(&context, &request, - duplicate_id, deadline_after_ms(1000), &response)); - UT_ASSERT(memcmp(response.operation_id, operation_id, - sizeof(operation_id)) == 0); + UT_ASSERT(pgrac_fenced_rejoin_admin_prepare(&context, &request, duplicate_id, + deadline_after_ms(1000), &response)); + UT_ASSERT(memcmp(response.operation_id, operation_id, sizeof(operation_id)) == 0); UT_ASSERT_EQ(provider_state[0], 1); UT_ASSERT_EQ(read_records(fd, records, lengthof(records)), 2); make_prepare(3, 70, 78, 0x62, &request); - UT_ASSERT(pgrac_fenced_rejoin_admin_prepare(&context, &request, - duplicate_id, deadline_after_ms(1000), &response)); + UT_ASSERT(pgrac_fenced_rejoin_admin_prepare(&context, &request, duplicate_id, + deadline_after_ms(1000), &response)); UT_ASSERT_EQ(response.status, PGRAC_FENCED_REJOIN_STATUS_REJECTED); UT_ASSERT_EQ(response.deny_reason, 23); UT_ASSERT(pgrac_external_fence_rejoin_v1_encode(&response, frame)); UT_ASSERT_EQ(provider_state[0], 1); UT_ASSERT_EQ(context.operation_count, 1); - (void) close(fd); - (void) unlink(path); + (void)close(fd); + (void)unlink(path); } UT_TEST(test_claim_authorize_refresh_is_exact_and_on_happens_once) @@ -313,46 +288,39 @@ UT_TEST(test_claim_authorize_refresh_is_exact_and_on_happens_once) make_config(&config); make_ops(&ops); - memset((void *) provider_state, 0, sizeof(uint32) * 8); + memset((void *)provider_state, 0, sizeof(uint32) * 8); provider_state[4] = PGRAC_FENCED_TARGET_OFF; provider_state[5] = PGRAC_FENCED_IO_DRAIN_DRAINED; - fd = open_context(&operation_context, &context, &journal_state, - &config, &ops, path); + fd = open_context(&operation_context, &context, &journal_state, &config, &ops, path); if (fd < 0) return; make_prepare(3, 70, 77, 0x63, &request); memset(operation_id, 0xa2, sizeof(operation_id)); - UT_ASSERT(pgrac_fenced_rejoin_admin_prepare(&context, &request, - operation_id, deadline_after_ms(1000), &offer)); + UT_ASSERT(pgrac_fenced_rejoin_admin_prepare(&context, &request, operation_id, + deadline_after_ms(1000), &offer)); make_claim(0x64, &request); - UT_ASSERT(pgrac_fenced_rejoin_claim(&context, &request, - deadline_after_ms(1000), &offer)); + UT_ASSERT(pgrac_fenced_rejoin_claim(&context, &request, deadline_after_ms(1000), &offer)); UT_ASSERT_EQ(offer.status, PGRAC_FENCED_REJOIN_STATUS_OFFERED); UT_ASSERT_EQ(offer.proof_generation, 1); - UT_ASSERT_EQ(offer.fresh_until_mono_ns - offer.verified_mono_ns, - UINT64_C(5000000000)); + UT_ASSERT_EQ(offer.fresh_until_mono_ns - offer.verified_mono_ns, UINT64_C(5000000000)); UT_ASSERT(pgrac_external_fence_rejoin_v1_encode(&offer, frame)); UT_ASSERT_EQ(provider_state[1], 0); UT_ASSERT_EQ(provider_state[2], 1); - make_bound_request(PGRAC_EXTERNAL_FENCE_REJOIN_LMON_AUTHORIZE_ON, - &offer, 0x65, &request); - UT_ASSERT(!pgrac_fenced_rejoin_authorize_on(&context, &request, false, - deadline_after_ms(1000), &on_result)); + make_bound_request(PGRAC_EXTERNAL_FENCE_REJOIN_LMON_AUTHORIZE_ON, &offer, 0x65, &request); + UT_ASSERT(!pgrac_fenced_rejoin_authorize_on(&context, &request, false, deadline_after_ms(1000), + &on_result)); UT_ASSERT_EQ(provider_state[3], 0); - UT_ASSERT(pgrac_fenced_rejoin_authorize_on(&context, &request, true, - deadline_after_ms(1000), &on_result)); - UT_ASSERT_EQ(on_result.status, - PGRAC_FENCED_REJOIN_STATUS_WAITING_JOINER); + UT_ASSERT(pgrac_fenced_rejoin_authorize_on(&context, &request, true, deadline_after_ms(1000), + &on_result)); + UT_ASSERT_EQ(on_result.status, PGRAC_FENCED_REJOIN_STATUS_WAITING_JOINER); UT_ASSERT_EQ(on_result.proof_generation, 2); UT_ASSERT(pgrac_external_fence_rejoin_v1_encode(&on_result, frame)); UT_ASSERT_EQ(provider_state[3], 1); UT_ASSERT_EQ(provider_state[2], 2); - make_bound_request(PGRAC_EXTERNAL_FENCE_REJOIN_LMON_REFRESH_ON, - &on_result, 0x66, &request); - UT_ASSERT(pgrac_fenced_rejoin_refresh_on(&context, &request, - deadline_after_ms(1000), &ready)); + make_bound_request(PGRAC_EXTERNAL_FENCE_REJOIN_LMON_REFRESH_ON, &on_result, 0x66, &request); + UT_ASSERT(pgrac_fenced_rejoin_refresh_on(&context, &request, deadline_after_ms(1000), &ready)); UT_ASSERT_EQ(ready.status, PGRAC_FENCED_REJOIN_STATUS_READY); UT_ASSERT_EQ(ready.proof_generation, 3); UT_ASSERT(pgrac_external_fence_rejoin_v1_encode(&ready, frame)); @@ -360,23 +328,17 @@ UT_TEST(test_claim_authorize_refresh_is_exact_and_on_happens_once) UT_ASSERT_EQ(provider_state[2], 3); count = read_records(fd, records, lengthof(records)); UT_ASSERT_EQ(count, 7); - UT_ASSERT_EQ(records[1].record_kind, - PGRAC_FENCED_JOURNAL_KIND_REENABLE_REQUESTED); - UT_ASSERT_EQ(records[2].record_kind, - PGRAC_FENCED_JOURNAL_KIND_READBACK_RESULT); - UT_ASSERT_EQ(records[3].record_kind, - PGRAC_FENCED_JOURNAL_KIND_ACTUATION_ISSUED); - UT_ASSERT_EQ(records[4].record_kind, - PGRAC_FENCED_JOURNAL_KIND_ACTUATION_RESULT); - UT_ASSERT_EQ(records[5].record_kind, - PGRAC_FENCED_JOURNAL_KIND_REENABLE_RESULT); - UT_ASSERT_EQ(records[6].record_kind, - PGRAC_FENCED_JOURNAL_KIND_REENABLE_RESULT); + UT_ASSERT_EQ(records[1].record_kind, PGRAC_FENCED_JOURNAL_KIND_REENABLE_REQUESTED); + UT_ASSERT_EQ(records[2].record_kind, PGRAC_FENCED_JOURNAL_KIND_READBACK_RESULT); + UT_ASSERT_EQ(records[3].record_kind, PGRAC_FENCED_JOURNAL_KIND_ACTUATION_ISSUED); + UT_ASSERT_EQ(records[4].record_kind, PGRAC_FENCED_JOURNAL_KIND_ACTUATION_RESULT); + UT_ASSERT_EQ(records[5].record_kind, PGRAC_FENCED_JOURNAL_KIND_REENABLE_RESULT); + UT_ASSERT_EQ(records[6].record_kind, PGRAC_FENCED_JOURNAL_KIND_REENABLE_RESULT); UT_ASSERT_EQ(offer.journal_seq, records[2].seq); UT_ASSERT_EQ(on_result.journal_seq, records[5].seq); UT_ASSERT_EQ(ready.journal_seq, records[6].seq); - (void) close(fd); - (void) unlink(path); + (void)close(fd); + (void)unlink(path); } UT_TEST(test_nonterminal_claim_releases_offer_and_cancel_discards_it) @@ -395,40 +357,35 @@ UT_TEST(test_nonterminal_claim_releases_offer_and_cancel_discards_it) make_config(&config); make_ops(&ops); - memset((void *) provider_state, 0, sizeof(uint32) * 8); + memset((void *)provider_state, 0, sizeof(uint32) * 8); provider_state[4] = PGRAC_FENCED_TARGET_OFF; provider_state[5] = PGRAC_FENCED_IO_DRAIN_UNKNOWN; - fd = open_context(&operation_context, &context, &journal_state, - &config, &ops, path); + fd = open_context(&operation_context, &context, &journal_state, &config, &ops, path); if (fd < 0) return; make_prepare(3, 70, 77, 0x67, &request); memset(operation_id, 0xa3, sizeof(operation_id)); - UT_ASSERT(pgrac_fenced_rejoin_admin_prepare(&context, &request, - operation_id, deadline_after_ms(1000), &response)); + UT_ASSERT(pgrac_fenced_rejoin_admin_prepare(&context, &request, operation_id, + deadline_after_ms(1000), &response)); make_claim(0x68, &request); - UT_ASSERT(pgrac_fenced_rejoin_claim(&context, &request, - deadline_after_ms(1000), &response)); + UT_ASSERT(pgrac_fenced_rejoin_claim(&context, &request, deadline_after_ms(1000), &response)); UT_ASSERT_EQ(response.status, PGRAC_FENCED_REJOIN_STATUS_UNKNOWN); UT_ASSERT_EQ(response.deny_reason, 9); UT_ASSERT_EQ(response.proof_generation, 0); UT_ASSERT(pgrac_external_fence_rejoin_v1_encode(&response, frame)); provider_state[5] = PGRAC_FENCED_IO_DRAIN_DRAINED; make_claim(0x69, &request); - UT_ASSERT(pgrac_fenced_rejoin_claim(&context, &request, - deadline_after_ms(1000), &response)); + UT_ASSERT(pgrac_fenced_rejoin_claim(&context, &request, deadline_after_ms(1000), &response)); UT_ASSERT_EQ(response.status, PGRAC_FENCED_REJOIN_STATUS_OFFERED); memset(&request, 0, sizeof(request)); request.opcode = PGRAC_EXTERNAL_FENCE_REJOIN_LMON_CANCEL; - memset(request.transport_nonce, 0x6a, - sizeof(request.transport_nonce)); - memcpy(request.operation_id, operation_id, - sizeof(request.operation_id)); + memset(request.transport_nonce, 0x6a, sizeof(request.transport_nonce)); + memcpy(request.operation_id, operation_id, sizeof(request.operation_id)); UT_ASSERT(pgrac_fenced_rejoin_cancel(&context, &request)); UT_ASSERT_EQ(context.operation_count, 0); UT_ASSERT(pgrac_fenced_rejoin_target(&context, operation_id) == NULL); - (void) close(fd); - (void) unlink(path); + (void)close(fd); + (void)unlink(path); } UT_TEST(test_claim_retries_transient_readback_before_off_proof) @@ -446,26 +403,24 @@ UT_TEST(test_claim_retries_transient_readback_before_off_proof) make_config(&config); make_ops(&ops); - memset((void *) provider_state, 0, sizeof(uint32) * 8); + memset((void *)provider_state, 0, sizeof(uint32) * 8); provider_state[4] = PGRAC_FENCED_TARGET_OFF; provider_state[5] = PGRAC_FENCED_IO_DRAIN_DRAINED; provider_state[6] = 2; - fd = open_context(&operation_context, &context, &journal_state, - &config, &ops, path); + fd = open_context(&operation_context, &context, &journal_state, &config, &ops, path); if (fd < 0) return; make_prepare(3, 80, 81, 0x6b, &request); memset(operation_id, 0xa4, sizeof(operation_id)); - UT_ASSERT(pgrac_fenced_rejoin_admin_prepare(&context, &request, - operation_id, deadline_after_ms(1000), &response)); + UT_ASSERT(pgrac_fenced_rejoin_admin_prepare(&context, &request, operation_id, + deadline_after_ms(1000), &response)); make_claim(0x6c, &request); - UT_ASSERT(pgrac_fenced_rejoin_claim(&context, &request, - deadline_after_ms(2000), &response)); + UT_ASSERT(pgrac_fenced_rejoin_claim(&context, &request, deadline_after_ms(2000), &response)); UT_ASSERT_EQ(response.status, PGRAC_FENCED_REJOIN_STATUS_OFFERED); UT_ASSERT_EQ(provider_state[2], 3); UT_ASSERT_EQ(provider_state[6], 0); - (void) close(fd); - (void) unlink(path); + (void)close(fd); + (void)unlink(path); } UT_TEST(test_refresh_resolve_failure_returns_negative_and_discards_operation) @@ -485,45 +440,39 @@ UT_TEST(test_refresh_resolve_failure_returns_negative_and_discards_operation) make_config(&config); make_ops(&ops); - memset((void *) provider_state, 0, sizeof(uint32) * 8); + memset((void *)provider_state, 0, sizeof(uint32) * 8); provider_state[4] = PGRAC_FENCED_TARGET_OFF; provider_state[5] = PGRAC_FENCED_IO_DRAIN_DRAINED; - fd = open_context(&operation_context, &context, &journal_state, - &config, &ops, path); + fd = open_context(&operation_context, &context, &journal_state, &config, &ops, path); if (fd < 0) return; make_prepare(3, 90, 91, 0x6d, &request); memset(operation_id, 0xa5, sizeof(operation_id)); - UT_ASSERT(pgrac_fenced_rejoin_admin_prepare(&context, &request, - operation_id, deadline_after_ms(1000), &response)); + UT_ASSERT(pgrac_fenced_rejoin_admin_prepare(&context, &request, operation_id, + deadline_after_ms(1000), &response)); make_claim(0x6e, &request); - UT_ASSERT(pgrac_fenced_rejoin_claim(&context, &request, - deadline_after_ms(1000), &offer)); - make_bound_request(PGRAC_EXTERNAL_FENCE_REJOIN_LMON_AUTHORIZE_ON, - &offer, 0x6f, &request); - UT_ASSERT(pgrac_fenced_rejoin_authorize_on(&context, &request, true, - deadline_after_ms(1000), &on_result)); - UT_ASSERT_EQ(on_result.status, - PGRAC_FENCED_REJOIN_STATUS_WAITING_JOINER); - make_bound_request(PGRAC_EXTERNAL_FENCE_REJOIN_LMON_REFRESH_ON, - &on_result, 0x70, &request); + UT_ASSERT(pgrac_fenced_rejoin_claim(&context, &request, deadline_after_ms(1000), &offer)); + make_bound_request(PGRAC_EXTERNAL_FENCE_REJOIN_LMON_AUTHORIZE_ON, &offer, 0x6f, &request); + UT_ASSERT(pgrac_fenced_rejoin_authorize_on(&context, &request, true, deadline_after_ms(1000), + &on_result)); + UT_ASSERT_EQ(on_result.status, PGRAC_FENCED_REJOIN_STATUS_WAITING_JOINER); + make_bound_request(PGRAC_EXTERNAL_FENCE_REJOIN_LMON_REFRESH_ON, &on_result, 0x70, &request); provider_state[7] = 1; - UT_ASSERT(pgrac_fenced_rejoin_refresh_on(&context, &request, - deadline_after_ms(1000), &response)); - UT_ASSERT_EQ(response.opcode, - PGRAC_EXTERNAL_FENCE_REJOIN_LMON_REFRESH_RESULT); + UT_ASSERT( + pgrac_fenced_rejoin_refresh_on(&context, &request, deadline_after_ms(1000), &response)); + UT_ASSERT_EQ(response.opcode, PGRAC_EXTERNAL_FENCE_REJOIN_LMON_REFRESH_RESULT); UT_ASSERT_EQ(response.status, PGRAC_FENCED_REJOIN_STATUS_UNAVAILABLE); UT_ASSERT_EQ(response.deny_reason, 10); UT_ASSERT_EQ(context.operation_count, 0); - (void) close(fd); - (void) unlink(path); + (void)close(fd); + (void)unlink(path); } int main(void) { - provider_state = mmap(NULL, sizeof(uint32) * 8, - PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0); + provider_state + = mmap(NULL, sizeof(uint32) * 8, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0); if (provider_state == MAP_FAILED) return 1; UT_PLAN(5); @@ -533,6 +482,6 @@ main(void) UT_RUN(test_claim_retries_transient_readback_before_off_proof); UT_RUN(test_refresh_resolve_failure_returns_negative_and_discards_operation); UT_DONE(); - (void) munmap((void *) provider_state, sizeof(uint32) * 8); + (void)munmap((void *)provider_state, sizeof(uint32) * 8); return ut_failed_count == 0 ? 0 : 1; } diff --git a/src/test/cluster_unit/test_pgrac_fenced_rejoin_async.c b/src/test/cluster_unit/test_pgrac_fenced_rejoin_async.c index 7d6754f1842..50e525ef383 100644 --- a/src/test/cluster_unit/test_pgrac_fenced_rejoin_async.c +++ b/src/test/cluster_unit/test_pgrac_fenced_rejoin_async.c @@ -26,8 +26,8 @@ UT_DEFINE_GLOBALS(); static volatile uint32 *provider_state; static PgracFencedProviderResult -test_resolve(const PgracFencedTargetV1 *configured, - PgracFencedTargetV1 *resolved, int32 *native_status) +test_resolve(const PgracFencedTargetV1 *configured, PgracFencedTargetV1 *resolved, + int32 *native_status) { *resolved = *configured; *native_status = 0; @@ -36,11 +36,10 @@ test_resolve(const PgracFencedTargetV1 *configured, } static PgracFencedProviderResult -test_actuate(const PgracFencedTargetV1 *target, - uint64_t deadline_mono_ns, int32 *native_status) +test_actuate(const PgracFencedTargetV1 *target, uint64_t deadline_mono_ns, int32 *native_status) { - (void) target; - (void) deadline_mono_ns; + (void)target; + (void)deadline_mono_ns; *native_status = 0; provider_state[1]++; provider_state[2] = PGRAC_FENCED_TARGET_ON; @@ -48,10 +47,10 @@ test_actuate(const PgracFencedTargetV1 *target, } static PgracFencedProviderResult -test_readback(const PgracFencedTargetV1 *target, - uint64_t deadline_mono_ns, PgracFencedReadbackV1 *readback) +test_readback(const PgracFencedTargetV1 *target, uint64_t deadline_mono_ns, + PgracFencedReadbackV1 *readback) { - (void) deadline_mono_ns; + (void)deadline_mono_ns; memset(readback, 0, sizeof(*readback)); readback->state = provider_state[2]; readback->io_drain_state = PGRAC_FENCED_IO_DRAIN_DRAINED; @@ -63,8 +62,7 @@ test_readback(const PgracFencedTargetV1 *target, static void test_shutdown(void) -{ -} +{} static uint64 deadline_after_ms(uint64 milliseconds) @@ -72,16 +70,14 @@ deadline_after_ms(uint64 milliseconds) struct timespec now; UT_ASSERT_EQ(clock_gettime(CLOCK_MONOTONIC, &now), 0); - return (uint64) now.tv_sec * UINT64_C(1000000000) + - (uint64) now.tv_nsec + milliseconds * UINT64_C(1000000); + return (uint64)now.tv_sec * UINT64_C(1000000000) + (uint64)now.tv_nsec + + milliseconds * UINT64_C(1000000); } static int open_context(PgracFencedOperationContextV1 *operation_context, - PgracFencedRejoinContextV1 *rejoin_context, - PgracFencedJournalScanState *journal_state, - PgracFencedConfigV1 *config, PgracFencedProviderOpsV1 *ops, - char path[64]) + PgracFencedRejoinContextV1 *rejoin_context, PgracFencedJournalScanState *journal_state, + PgracFencedConfigV1 *config, PgracFencedProviderOpsV1 *ops, char path[64]) { uint8 config_digest[32]; uint8 daemon_boot_id[16]; @@ -97,8 +93,7 @@ open_context(PgracFencedOperationContextV1 *operation_context, config->provider_abi = PGRAC_FENCED_PROVIDER_ABI_V1; config->node_count = 1; config->nodes[3].present = true; - memset(config->nodes[3].target_uuid, 0x41, - sizeof(config->nodes[3].target_uuid)); + memset(config->nodes[3].target_uuid, 0x41, sizeof(config->nodes[3].target_uuid)); memset(ops, 0, sizeof(*ops)); ops->abi_version = PGRAC_FENCED_PROVIDER_ABI_V1; ops->struct_size = sizeof(*ops); @@ -118,31 +113,29 @@ open_context(PgracFencedOperationContextV1 *operation_context, return -1; UT_ASSERT_EQ(fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_APPEND), 0); pgrac_fenced_journal_scan_state_init(journal_state); - UT_ASSERT(pgrac_fenced_operation_context_init(operation_context, config, - ops, true, config_digest, daemon_boot_id, fd, journal_state)); + UT_ASSERT(pgrac_fenced_operation_context_init( + operation_context, config, ops, true, config_digest, daemon_boot_id, fd, journal_state)); UT_ASSERT(pgrac_fenced_rejoin_init(rejoin_context, operation_context)); return fd; } static bool finish_worker(PgracFencedOperationContextV1 *operation_context, - PgracFencedRejoinContextV1 *rejoin_context, - PgracFencedRejoinAsyncWorkerV1 *worker, - PgracExternalFenceProtocolRejoinFrameV1 *response) + PgracFencedRejoinContextV1 *rejoin_context, PgracFencedRejoinAsyncWorkerV1 *worker, + PgracExternalFenceProtocolRejoinFrameV1 *response) { PgracFencedRejoinAsyncEvent event; struct pollfd descriptor; int attempts = 0; - while (attempts++ < 100) - { + while (attempts++ < 100) { descriptor.fd = pgrac_fenced_rejoin_async_fd(worker); descriptor.events = POLLIN | POLLHUP | POLLERR; descriptor.revents = 0; if (poll(&descriptor, 1, 100) <= 0) continue; - if (!pgrac_fenced_rejoin_async_service(operation_context, - rejoin_context, worker, &event, response)) + if (!pgrac_fenced_rejoin_async_service(operation_context, rejoin_context, worker, &event, + response)) return false; if (event == PGRAC_FENCED_REJOIN_ASYNC_COMPLETE) return true; @@ -151,20 +144,15 @@ finish_worker(PgracFencedOperationContextV1 *operation_context, } static void -make_bound_request(uint16 opcode, - const PgracExternalFenceProtocolRejoinFrameV1 *source, - uint8 nonce, - PgracExternalFenceProtocolRejoinFrameV1 *request) +make_bound_request(uint16 opcode, const PgracExternalFenceProtocolRejoinFrameV1 *source, + uint8 nonce, PgracExternalFenceProtocolRejoinFrameV1 *request) { memset(request, 0, sizeof(*request)); request->opcode = opcode; - memset(request->transport_nonce, nonce, - sizeof(request->transport_nonce)); - memcpy(request->operation_id, source->operation_id, - sizeof(request->operation_id)); + memset(request->transport_nonce, nonce, sizeof(request->transport_nonce)); + memcpy(request->operation_id, source->operation_id, sizeof(request->operation_id)); request->system_identifier = source->system_identifier; - memset(request->rejoin_gate_digest, 0x91, - sizeof(request->rejoin_gate_digest)); + memset(request->rejoin_gate_digest, 0x91, sizeof(request->rejoin_gate_digest)); memcpy(request->protected_set_digest, source->protected_set_digest, sizeof(request->protected_set_digest)); request->old_node_id = source->old_node_id; @@ -189,81 +177,72 @@ UT_TEST(test_parent_serializes_full_async_rejoin_lifecycle) char path[64]; int journal_fd; - memset((void *) provider_state, 0, sizeof(uint32) * 4); + memset((void *)provider_state, 0, sizeof(uint32) * 4); provider_state[2] = PGRAC_FENCED_TARGET_OFF; - journal_fd = open_context(&operation_context, &rejoin_context, - &journal_state, &config, &ops, path); + journal_fd + = open_context(&operation_context, &rejoin_context, &journal_state, &config, &ops, path); if (journal_fd < 0) return; memset(&request, 0, sizeof(request)); request.opcode = PGRAC_EXTERNAL_FENCE_REJOIN_ADMIN_PREPARE; - memset(request.transport_nonce, 0x61, - sizeof(request.transport_nonce)); + memset(request.transport_nonce, 0x61, sizeof(request.transport_nonce)); request.old_node_id = 3; request.old_incarnation = 70; request.candidate_incarnation = 77; request.timeout_ms = 1000; memset(operation_id, 0xa1, sizeof(operation_id)); - UT_ASSERT(pgrac_fenced_rejoin_async_start(&operation_context, - &rejoin_context, PGRAC_FENCED_REJOIN_ASYNC_ADMIN_PREPARE, &request, + UT_ASSERT(pgrac_fenced_rejoin_async_start( + &operation_context, &rejoin_context, PGRAC_FENCED_REJOIN_ASYNC_ADMIN_PREPARE, &request, operation_id, false, deadline_after_ms(2000), &worker)); - UT_ASSERT(finish_worker(&operation_context, &rejoin_context, &worker, - &offer)); + UT_ASSERT(finish_worker(&operation_context, &rejoin_context, &worker, &offer)); UT_ASSERT_EQ(rejoin_context.operation_count, 1); UT_ASSERT_EQ(operation_context.next_proof_generation, 1); memset(&request, 0, sizeof(request)); request.opcode = PGRAC_EXTERNAL_FENCE_REJOIN_LMON_CLAIM_NEXT; - memset(request.transport_nonce, 0x62, - sizeof(request.transport_nonce)); - UT_ASSERT(pgrac_fenced_rejoin_async_start(&operation_context, - &rejoin_context, PGRAC_FENCED_REJOIN_ASYNC_CLAIM_NEXT, &request, - NULL, false, deadline_after_ms(2000), &worker)); - UT_ASSERT(finish_worker(&operation_context, &rejoin_context, &worker, - &offer)); + memset(request.transport_nonce, 0x62, sizeof(request.transport_nonce)); + UT_ASSERT(pgrac_fenced_rejoin_async_start(&operation_context, &rejoin_context, + PGRAC_FENCED_REJOIN_ASYNC_CLAIM_NEXT, &request, NULL, + false, deadline_after_ms(2000), &worker)); + UT_ASSERT(finish_worker(&operation_context, &rejoin_context, &worker, &offer)); UT_ASSERT_EQ(offer.status, PGRAC_FENCED_REJOIN_STATUS_OFFERED); UT_ASSERT_EQ(offer.proof_generation, 1); UT_ASSERT_EQ(operation_context.next_proof_generation, 2); - make_bound_request(PGRAC_EXTERNAL_FENCE_REJOIN_LMON_AUTHORIZE_ON, - &offer, 0x63, &request); - UT_ASSERT(pgrac_fenced_rejoin_async_start(&operation_context, - &rejoin_context, PGRAC_FENCED_REJOIN_ASYNC_AUTHORIZE_ON, &request, - NULL, true, deadline_after_ms(2000), &worker)); - UT_ASSERT(finish_worker(&operation_context, &rejoin_context, &worker, - &on_result)); - UT_ASSERT_EQ(on_result.status, - PGRAC_FENCED_REJOIN_STATUS_WAITING_JOINER); + make_bound_request(PGRAC_EXTERNAL_FENCE_REJOIN_LMON_AUTHORIZE_ON, &offer, 0x63, &request); + UT_ASSERT(pgrac_fenced_rejoin_async_start(&operation_context, &rejoin_context, + PGRAC_FENCED_REJOIN_ASYNC_AUTHORIZE_ON, &request, + NULL, true, deadline_after_ms(2000), &worker)); + UT_ASSERT(finish_worker(&operation_context, &rejoin_context, &worker, &on_result)); + UT_ASSERT_EQ(on_result.status, PGRAC_FENCED_REJOIN_STATUS_WAITING_JOINER); UT_ASSERT_EQ(on_result.proof_generation, 2); UT_ASSERT_EQ(provider_state[1], 1); - make_bound_request(PGRAC_EXTERNAL_FENCE_REJOIN_LMON_REFRESH_ON, - &on_result, 0x64, &request); - UT_ASSERT(pgrac_fenced_rejoin_async_start(&operation_context, - &rejoin_context, PGRAC_FENCED_REJOIN_ASYNC_REFRESH_ON, &request, - NULL, false, deadline_after_ms(2000), &worker)); - UT_ASSERT(finish_worker(&operation_context, &rejoin_context, &worker, - &ready)); + make_bound_request(PGRAC_EXTERNAL_FENCE_REJOIN_LMON_REFRESH_ON, &on_result, 0x64, &request); + UT_ASSERT(pgrac_fenced_rejoin_async_start(&operation_context, &rejoin_context, + PGRAC_FENCED_REJOIN_ASYNC_REFRESH_ON, &request, NULL, + false, deadline_after_ms(2000), &worker)); + UT_ASSERT(finish_worker(&operation_context, &rejoin_context, &worker, &ready)); UT_ASSERT_EQ(ready.status, PGRAC_FENCED_REJOIN_STATUS_READY); UT_ASSERT_EQ(ready.proof_generation, 3); UT_ASSERT_EQ(operation_context.next_proof_generation, 4); UT_ASSERT_EQ(provider_state[1], 1); UT_ASSERT_EQ(provider_state[3], 3); UT_ASSERT_EQ(pgrac_fenced_rejoin_async_fd(&worker), -1); - (void) close(journal_fd); - (void) unlink(path); + (void)close(journal_fd); + (void)unlink(path); } int main(void) { - provider_state = mmap(NULL, sizeof(uint32) * 4, - PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0); + provider_state + = mmap(NULL, sizeof(uint32) * 4, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0); if (provider_state == MAP_FAILED) return 1; UT_PLAN(1); UT_RUN(test_parent_serializes_full_async_rejoin_lifecycle); UT_DONE(); - (void) munmap((void *) provider_state, sizeof(uint32) * 4); + (void)munmap((void *)provider_state, sizeof(uint32) * 4); return ut_failed_count == 0 ? 0 : 1; } diff --git a/src/test/cluster_unit/test_pgrac_fenced_rejoin_coordinator.c b/src/test/cluster_unit/test_pgrac_fenced_rejoin_coordinator.c index 5867ff5063d..d87609789f8 100644 --- a/src/test/cluster_unit/test_pgrac_fenced_rejoin_coordinator.c +++ b/src/test/cluster_unit/test_pgrac_fenced_rejoin_coordinator.c @@ -26,8 +26,8 @@ UT_DEFINE_GLOBALS(); static volatile uint32 *provider_state; static PgracFencedProviderResult -test_resolve(const PgracFencedTargetV1 *configured, - PgracFencedTargetV1 *resolved, int32 *native_status) +test_resolve(const PgracFencedTargetV1 *configured, PgracFencedTargetV1 *resolved, + int32 *native_status) { *resolved = *configured; *native_status = 0; @@ -35,11 +35,10 @@ test_resolve(const PgracFencedTargetV1 *configured, } static PgracFencedProviderResult -test_actuate_off(const PgracFencedTargetV1 *target, - uint64_t deadline_mono_ns, int32 *native_status) +test_actuate_off(const PgracFencedTargetV1 *target, uint64_t deadline_mono_ns, int32 *native_status) { - (void) target; - (void) deadline_mono_ns; + (void)target; + (void)deadline_mono_ns; *native_status = 0; provider_state[0]++; provider_state[2] = PGRAC_FENCED_TARGET_OFF; @@ -47,11 +46,10 @@ test_actuate_off(const PgracFencedTargetV1 *target, } static PgracFencedProviderResult -test_actuate_on(const PgracFencedTargetV1 *target, - uint64_t deadline_mono_ns, int32 *native_status) +test_actuate_on(const PgracFencedTargetV1 *target, uint64_t deadline_mono_ns, int32 *native_status) { - (void) target; - (void) deadline_mono_ns; + (void)target; + (void)deadline_mono_ns; *native_status = 0; provider_state[1]++; provider_state[2] = PGRAC_FENCED_TARGET_ON; @@ -59,10 +57,10 @@ test_actuate_on(const PgracFencedTargetV1 *target, } static PgracFencedProviderResult -test_readback(const PgracFencedTargetV1 *target, - uint64_t deadline_mono_ns, PgracFencedReadbackV1 *readback) +test_readback(const PgracFencedTargetV1 *target, uint64_t deadline_mono_ns, + PgracFencedReadbackV1 *readback) { - (void) deadline_mono_ns; + (void)deadline_mono_ns; memset(readback, 0, sizeof(*readback)); readback->state = provider_state[2]; readback->io_drain_state = PGRAC_FENCED_IO_DRAIN_DRAINED; @@ -74,8 +72,7 @@ test_readback(const PgracFencedTargetV1 *target, static void test_shutdown(void) -{ -} +{} static uint64 now_ns(void) @@ -83,8 +80,7 @@ now_ns(void) struct timespec now; UT_ASSERT_EQ(clock_gettime(CLOCK_MONOTONIC, &now), 0); - return (uint64) now.tv_sec * UINT64_C(1000000000) + - (uint64) now.tv_nsec; + return (uint64)now.tv_sec * UINT64_C(1000000000) + (uint64)now.tv_nsec; } static uint64 @@ -94,10 +90,8 @@ deadline_after_ms(uint64 milliseconds) } static int -open_context(PgracFencedOperationContextV1 *context, - PgracFencedJournalScanState *journal_state, - PgracFencedConfigV1 *config, PgracFencedProviderOpsV1 *ops, - char path[64]) +open_context(PgracFencedOperationContextV1 *context, PgracFencedJournalScanState *journal_state, + PgracFencedConfigV1 *config, PgracFencedProviderOpsV1 *ops, char path[64]) { uint8 config_digest[32]; uint8 daemon_boot_id[16]; @@ -109,14 +103,13 @@ open_context(PgracFencedOperationContextV1 *context, config->system_identifier = 9001; config->storage_backend_id = 2; memset(config->storage_uuid, 0x31, sizeof(config->storage_uuid)); - config->allowed_db_uid = (uint64) geteuid(); - config->allowed_db_gid = (uint64) getegid(); + config->allowed_db_uid = (uint64)geteuid(); + config->allowed_db_gid = (uint64)getegid(); config->provider_id = PGRAC_FENCED_PROVIDER_ID_TEST_ONLY; config->provider_abi = PGRAC_FENCED_PROVIDER_ABI_V1; config->node_count = 1; config->nodes[3].present = true; - memset(config->nodes[3].target_uuid, 0x41, - sizeof(config->nodes[3].target_uuid)); + memset(config->nodes[3].target_uuid, 0x41, sizeof(config->nodes[3].target_uuid)); memset(ops, 0, sizeof(*ops)); ops->abi_version = PGRAC_FENCED_PROVIDER_ABI_V1; ops->struct_size = sizeof(*ops); @@ -136,31 +129,29 @@ open_context(PgracFencedOperationContextV1 *context, return -1; UT_ASSERT_EQ(fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_APPEND), 0); pgrac_fenced_journal_scan_state_init(journal_state); - UT_ASSERT(pgrac_fenced_operation_context_init(context, config, ops, true, - config_digest, daemon_boot_id, fd, journal_state)); + UT_ASSERT(pgrac_fenced_operation_context_init(context, config, ops, true, config_digest, + daemon_boot_id, fd, journal_state)); return fd; } static bool -write_rejoin(int fd, - const PgracExternalFenceProtocolRejoinFrameV1 *request) +write_rejoin(int fd, const PgracExternalFenceProtocolRejoinFrameV1 *request) { uint8 frame[PGRAC_EXTERNAL_FENCE_REJOIN_V1_BYTES]; - return pgrac_external_fence_rejoin_v1_encode(request, frame) && - write(fd, frame, sizeof(frame)) == sizeof(frame); + return pgrac_external_fence_rejoin_v1_encode(request, frame) + && write(fd, frame, sizeof(frame)) == sizeof(frame); } static bool -try_rejoin(int fd, uint8 frame[PGRAC_EXTERNAL_FENCE_REJOIN_V1_BYTES], - size_t *used, PgracExternalFenceProtocolRejoinFrameV1 *response) +try_rejoin(int fd, uint8 frame[PGRAC_EXTERNAL_FENCE_REJOIN_V1_BYTES], size_t *used, + PgracExternalFenceProtocolRejoinFrameV1 *response) { ssize_t got; - got = recv(fd, frame + *used, - PGRAC_EXTERNAL_FENCE_REJOIN_V1_BYTES - *used, MSG_DONTWAIT); + got = recv(fd, frame + *used, PGRAC_EXTERNAL_FENCE_REJOIN_V1_BYTES - *used, MSG_DONTWAIT); if (got > 0) - *used += (size_t) got; + *used += (size_t)got; else if (got < 0 && (errno == EAGAIN || errno == EWOULDBLOCK)) return false; else @@ -168,35 +159,33 @@ try_rejoin(int fd, uint8 frame[PGRAC_EXTERNAL_FENCE_REJOIN_V1_BYTES], if (*used != PGRAC_EXTERNAL_FENCE_REJOIN_V1_BYTES) return false; *used = 0; - return pgrac_external_fence_rejoin_v1_decode(frame, - PGRAC_EXTERNAL_FENCE_REJOIN_V1_BYTES, response); + return pgrac_external_fence_rejoin_v1_decode(frame, PGRAC_EXTERNAL_FENCE_REJOIN_V1_BYTES, + response); } static bool -await_rejoin(PgracFencedCoordinatorV1 *scalar, - PgracFencedRejoinCoordinatorV1 *rejoin, int peer_fd, - PgracExternalFenceProtocolRejoinFrameV1 *response) +await_rejoin(PgracFencedCoordinatorV1 *scalar, PgracFencedRejoinCoordinatorV1 *rejoin, int peer_fd, + PgracExternalFenceProtocolRejoinFrameV1 *response) { uint8 frame[PGRAC_EXTERNAL_FENCE_REJOIN_V1_BYTES]; - struct timespec pause = {0, 1000000}; + struct timespec pause = { 0, 1000000 }; size_t used = 0; int loops; - for (loops = 0; loops < 3000; loops++) - { - if (!pgrac_fenced_coordinator_service(scalar, now_ns()) || - !pgrac_fenced_rejoin_coordinator_service(rejoin, now_ns())) + for (loops = 0; loops < 3000; loops++) { + if (!pgrac_fenced_coordinator_service(scalar, now_ns()) + || !pgrac_fenced_rejoin_coordinator_service(rejoin, now_ns())) return false; if (try_rejoin(peer_fd, frame, &used, response)) return true; - (void) nanosleep(&pause, NULL); + (void)nanosleep(&pause, NULL); } return false; } static void make_scalar_request(const PgracFencedConfigV1 *config, uint8 nonce, - PgracExternalFenceProtocolRequestV1 *request) + PgracExternalFenceProtocolRequestV1 *request) { memset(request, 0, sizeof(*request)); memset(request->request_nonce, nonce, sizeof(request->request_nonce)); @@ -206,8 +195,7 @@ make_scalar_request(const PgracFencedConfigV1 *config, uint8 nonce, request->need.victim_node_id = 3; request->need.victim_incarnation = 70; UT_ASSERT(pgrac_external_fence_protected_set_digest_v1( - config->storage_backend_id, config->storage_uuid, - request->need.protected_set_digest)); + config->storage_backend_id, config->storage_uuid, request->need.protected_set_digest)); request->need.predicate_id = 1; request->need.predicate_version = 1; request->timeout_ms = 2000; @@ -218,8 +206,8 @@ write_scalar(int fd, const PgracExternalFenceProtocolRequestV1 *request) { uint8 frame[PGRAC_EXTERNAL_FENCE_REQUEST_V1_BYTES]; - return pgrac_external_fence_request_v1_encode(request, frame) && - write(fd, frame, sizeof(frame)) == sizeof(frame); + return pgrac_external_fence_request_v1_encode(request, frame) + && write(fd, frame, sizeof(frame)) == sizeof(frame); } static bool @@ -228,43 +216,37 @@ try_scalar(int fd, PgracExternalFenceProtocolResponseV1 *response) uint8 frame[PGRAC_EXTERNAL_FENCE_RESPONSE_V1_BYTES]; ssize_t got = recv(fd, frame, sizeof(frame), MSG_DONTWAIT); - return got == sizeof(frame) && - pgrac_external_fence_response_v1_decode(frame, sizeof(frame), response); + return got == sizeof(frame) + && pgrac_external_fence_response_v1_decode(frame, sizeof(frame), response); } static bool await_scalar(PgracFencedCoordinatorV1 *scalar, int peer_fd, - PgracExternalFenceProtocolResponseV1 *response) + PgracExternalFenceProtocolResponseV1 *response) { - struct timespec pause = {0, 1000000}; + struct timespec pause = { 0, 1000000 }; int loops; - for (loops = 0; loops < 3000; loops++) - { + for (loops = 0; loops < 3000; loops++) { if (!pgrac_fenced_coordinator_service(scalar, now_ns())) return false; if (try_scalar(peer_fd, response)) return true; - (void) nanosleep(&pause, NULL); + (void)nanosleep(&pause, NULL); } return false; } static void -make_bound_request(uint16 opcode, - const PgracExternalFenceProtocolRejoinFrameV1 *source, - uint8 nonce, - PgracExternalFenceProtocolRejoinFrameV1 *request) +make_bound_request(uint16 opcode, const PgracExternalFenceProtocolRejoinFrameV1 *source, + uint8 nonce, PgracExternalFenceProtocolRejoinFrameV1 *request) { memset(request, 0, sizeof(*request)); request->opcode = opcode; - memset(request->transport_nonce, nonce, - sizeof(request->transport_nonce)); - memcpy(request->operation_id, source->operation_id, - sizeof(request->operation_id)); + memset(request->transport_nonce, nonce, sizeof(request->transport_nonce)); + memcpy(request->operation_id, source->operation_id, sizeof(request->operation_id)); request->system_identifier = source->system_identifier; - memset(request->rejoin_gate_digest, 0x91, - sizeof(request->rejoin_gate_digest)); + memset(request->rejoin_gate_digest, 0x91, sizeof(request->rejoin_gate_digest)); memcpy(request->protected_set_digest, source->protected_set_digest, sizeof(request->protected_set_digest)); request->old_node_id = source->old_node_id; @@ -294,77 +276,68 @@ UT_TEST(test_socket_rejoin_invalidates_exact_scalar_and_releases_after_close) int old_scalar[2]; int fresh_scalar[2]; - memset((void *) provider_state, 0, sizeof(uint32) * 4); + memset((void *)provider_state, 0, sizeof(uint32) * 4); provider_state[2] = PGRAC_FENCED_TARGET_OFF; - journal_fd = open_context(&operation_context, &journal_state, &config, - &ops, path); + journal_fd = open_context(&operation_context, &journal_state, &config, &ops, path); if (journal_fd < 0) return; UT_ASSERT(pgrac_fenced_coordinator_init(&scalar, &operation_context)); - UT_ASSERT(pgrac_fenced_rejoin_coordinator_init(&rejoin, - &operation_context, &scalar)); + UT_ASSERT(pgrac_fenced_rejoin_coordinator_init(&rejoin, &operation_context, &scalar)); memset(&request, 0, sizeof(request)); request.opcode = PGRAC_EXTERNAL_FENCE_REJOIN_ADMIN_PREPARE; - memset(request.transport_nonce, 0x61, - sizeof(request.transport_nonce)); + memset(request.transport_nonce, 0x61, sizeof(request.transport_nonce)); request.old_node_id = 3; request.old_incarnation = 70; request.candidate_incarnation = 77; request.timeout_ms = 2000; UT_ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, admin), 0); UT_ASSERT(write_rejoin(admin[0], &request)); - UT_ASSERT(pgrac_fenced_rejoin_coordinator_accept_fd(&rejoin, admin[1], - true, deadline_after_ms(3000))); + UT_ASSERT(pgrac_fenced_rejoin_coordinator_accept_fd(&rejoin, admin[1], true, + deadline_after_ms(3000))); UT_ASSERT(await_rejoin(&scalar, &rejoin, admin[0], &response)); - UT_ASSERT_EQ(response.opcode, - PGRAC_EXTERNAL_FENCE_REJOIN_ADMIN_PREPARE_RESULT); + UT_ASSERT_EQ(response.opcode, PGRAC_EXTERNAL_FENCE_REJOIN_ADMIN_PREPARE_RESULT); UT_ASSERT_EQ(response.status, PGRAC_FENCED_REJOIN_STATUS_OFFERED); make_scalar_request(&config, 0x71, &scalar_request); UT_ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, old_scalar), 0); UT_ASSERT(write_scalar(old_scalar[0], &scalar_request)); - UT_ASSERT(pgrac_fenced_coordinator_accept_fd(&scalar, old_scalar[1], - deadline_after_ms(3000))); + UT_ASSERT(pgrac_fenced_coordinator_accept_fd(&scalar, old_scalar[1], deadline_after_ms(3000))); UT_ASSERT(await_scalar(&scalar, old_scalar[0], &scalar_response)); UT_ASSERT_EQ(scalar_response.verdict, 1); UT_ASSERT_EQ(provider_state[0], 1); memset(&request, 0, sizeof(request)); request.opcode = PGRAC_EXTERNAL_FENCE_REJOIN_LMON_CLAIM_NEXT; - memset(request.transport_nonce, 0x62, - sizeof(request.transport_nonce)); + memset(request.transport_nonce, 0x62, sizeof(request.transport_nonce)); UT_ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, db), 0); UT_ASSERT(write_rejoin(db[0], &request)); - UT_ASSERT(pgrac_fenced_rejoin_coordinator_accept_fd(&rejoin, db[1], - false, deadline_after_ms(3000))); + UT_ASSERT( + pgrac_fenced_rejoin_coordinator_accept_fd(&rejoin, db[1], false, deadline_after_ms(3000))); UT_ASSERT(await_rejoin(&scalar, &rejoin, db[0], &offer)); UT_ASSERT_EQ(offer.status, PGRAC_FENCED_REJOIN_STATUS_OFFERED); UT_ASSERT_EQ(recv(old_scalar[0], &byte, 1, MSG_DONTWAIT), -1); UT_ASSERT(errno == EAGAIN || errno == EWOULDBLOCK); - make_bound_request(PGRAC_EXTERNAL_FENCE_REJOIN_LMON_AUTHORIZE_ON, - &offer, 0x63, &request); + make_bound_request(PGRAC_EXTERNAL_FENCE_REJOIN_LMON_AUTHORIZE_ON, &offer, 0x63, &request); UT_ASSERT(write_rejoin(db[0], &request)); UT_ASSERT(await_rejoin(&scalar, &rejoin, db[0], &response)); - UT_ASSERT_EQ(response.status, - PGRAC_FENCED_REJOIN_STATUS_WAITING_JOINER); + UT_ASSERT_EQ(response.status, PGRAC_FENCED_REJOIN_STATUS_WAITING_JOINER); UT_ASSERT_EQ(recv(old_scalar[0], &byte, 1, MSG_DONTWAIT), 0); UT_ASSERT_EQ(provider_state[1], 1); - make_bound_request(PGRAC_EXTERNAL_FENCE_REJOIN_LMON_REFRESH_ON, - &response, 0x64, &request); + make_bound_request(PGRAC_EXTERNAL_FENCE_REJOIN_LMON_REFRESH_ON, &response, 0x64, &request); UT_ASSERT(write_rejoin(db[0], &request)); UT_ASSERT(await_rejoin(&scalar, &rejoin, db[0], &response)); UT_ASSERT_EQ(response.status, PGRAC_FENCED_REJOIN_STATUS_READY); - (void) close(db[0]); + (void)close(db[0]); UT_ASSERT(pgrac_fenced_rejoin_coordinator_service(&rejoin, now_ns())); make_scalar_request(&config, 0x72, &scalar_request); UT_ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, fresh_scalar), 0); UT_ASSERT(write_scalar(fresh_scalar[0], &scalar_request)); - UT_ASSERT(pgrac_fenced_coordinator_accept_fd(&scalar, fresh_scalar[1], - deadline_after_ms(3000))); + UT_ASSERT( + pgrac_fenced_coordinator_accept_fd(&scalar, fresh_scalar[1], deadline_after_ms(3000))); UT_ASSERT(await_scalar(&scalar, fresh_scalar[0], &scalar_response)); UT_ASSERT_EQ(scalar_response.verdict, 1); UT_ASSERT_EQ(provider_state[0], 2); @@ -372,23 +345,23 @@ UT_TEST(test_socket_rejoin_invalidates_exact_scalar_and_releases_after_close) UT_ASSERT_EQ(pgrac_fenced_rejoin_coordinator_operation_count(&rejoin), 0); UT_ASSERT(pgrac_fenced_rejoin_coordinator_shutdown(&rejoin)); UT_ASSERT(pgrac_fenced_coordinator_shutdown(&scalar, 16)); - (void) close(admin[0]); - (void) close(old_scalar[0]); - (void) close(fresh_scalar[0]); - (void) close(journal_fd); - (void) unlink(path); + (void)close(admin[0]); + (void)close(old_scalar[0]); + (void)close(fresh_scalar[0]); + (void)close(journal_fd); + (void)unlink(path); } int main(void) { - provider_state = mmap(NULL, sizeof(uint32) * 4, - PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0); + provider_state + = mmap(NULL, sizeof(uint32) * 4, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0); if (provider_state == MAP_FAILED) return 1; UT_PLAN(1); UT_RUN(test_socket_rejoin_invalidates_exact_scalar_and_releases_after_close); UT_DONE(); - (void) munmap((void *) provider_state, sizeof(uint32) * 4); + (void)munmap((void *)provider_state, sizeof(uint32) * 4); return ut_failed_count == 0 ? 0 : 1; } diff --git a/src/test/cluster_unit/test_pgrac_fenced_schedule.c b/src/test/cluster_unit/test_pgrac_fenced_schedule.c index 086c08548bf..afcc488cc53 100644 --- a/src/test/cluster_unit/test_pgrac_fenced_schedule.c +++ b/src/test/cluster_unit/test_pgrac_fenced_schedule.c @@ -21,7 +21,7 @@ static void identity(uint8 target[16], uint8 binding[32], uint8 seed) { memset(target, seed, 16); - memset(binding, (uint8) (seed + 64), 32); + memset(binding, (uint8)(seed + 64), 32); } UT_TEST(test_same_binding_joins_only_live_joinable_operation) @@ -36,12 +36,11 @@ UT_TEST(test_same_binding_joins_only_live_joinable_operation) identity(target, binding, 1); UT_ASSERT(pgrac_fenced_schedule_init(&schedule)); - UT_ASSERT_EQ(pgrac_fenced_schedule_submit(&schedule, 10, target, binding, - 1000, &owner), PGRAC_FENCED_SCHEDULE_START); - UT_ASSERT(pgrac_fenced_schedule_set_state(&schedule, &owner, - PGRAC_FENCED_STATE_ACTUATING)); - UT_ASSERT_EQ(pgrac_fenced_schedule_submit(&schedule, 11, target, binding, - 900, &joiner), PGRAC_FENCED_SCHEDULE_JOIN); + UT_ASSERT_EQ(pgrac_fenced_schedule_submit(&schedule, 10, target, binding, 1000, &owner), + PGRAC_FENCED_SCHEDULE_START); + UT_ASSERT(pgrac_fenced_schedule_set_state(&schedule, &owner, PGRAC_FENCED_STATE_ACTUATING)); + UT_ASSERT_EQ(pgrac_fenced_schedule_submit(&schedule, 11, target, binding, 900, &joiner), + PGRAC_FENCED_SCHEDULE_JOIN); UT_ASSERT_EQ(owner.slot, joiner.slot); UT_ASSERT_EQ(owner.serial, joiner.serial); UT_ASSERT(pgrac_fenced_schedule_snapshot(&schedule, &owner, &snapshot)); @@ -49,10 +48,10 @@ UT_TEST(test_same_binding_joins_only_live_joinable_operation) /* A joiner's shorter deadline never steals the operation owner's deadline. */ UT_ASSERT_EQ(snapshot.deadline_mono_ns, 1000); - UT_ASSERT(pgrac_fenced_schedule_set_state(&schedule, &owner, - PGRAC_FENCED_STATE_PROVEN_DURABLE)); - UT_ASSERT_EQ(pgrac_fenced_schedule_submit(&schedule, 12, target, binding, - 1200, &queued), PGRAC_FENCED_SCHEDULE_QUEUE); + UT_ASSERT( + pgrac_fenced_schedule_set_state(&schedule, &owner, PGRAC_FENCED_STATE_PROVEN_DURABLE)); + UT_ASSERT_EQ(pgrac_fenced_schedule_submit(&schedule, 12, target, binding, 1200, &queued), + PGRAC_FENCED_SCHEDULE_QUEUE); UT_ASSERT_NE(owner.serial, queued.serial); UT_ASSERT_EQ(pgrac_fenced_schedule_operation_count(&schedule), 2); } @@ -78,14 +77,15 @@ UT_TEST(test_same_target_is_strict_fifo_and_different_target_starts) memset(second_binding, 0x91, sizeof(second_binding)); memset(third_binding, 0x92, sizeof(third_binding)); UT_ASSERT(pgrac_fenced_schedule_init(&schedule)); - UT_ASSERT_EQ(pgrac_fenced_schedule_submit(&schedule, 20, target, binding, - 1000, &first), PGRAC_FENCED_SCHEDULE_START); - UT_ASSERT_EQ(pgrac_fenced_schedule_submit(&schedule, 21, target, - second_binding, 1100, &second), PGRAC_FENCED_SCHEDULE_QUEUE); - UT_ASSERT_EQ(pgrac_fenced_schedule_submit(&schedule, 22, target, - third_binding, 1200, &third), PGRAC_FENCED_SCHEDULE_QUEUE); - UT_ASSERT_EQ(pgrac_fenced_schedule_submit(&schedule, 23, other_target, - other_binding, 1300, &other), PGRAC_FENCED_SCHEDULE_START); + UT_ASSERT_EQ(pgrac_fenced_schedule_submit(&schedule, 20, target, binding, 1000, &first), + PGRAC_FENCED_SCHEDULE_START); + UT_ASSERT_EQ(pgrac_fenced_schedule_submit(&schedule, 21, target, second_binding, 1100, &second), + PGRAC_FENCED_SCHEDULE_QUEUE); + UT_ASSERT_EQ(pgrac_fenced_schedule_submit(&schedule, 22, target, third_binding, 1200, &third), + PGRAC_FENCED_SCHEDULE_QUEUE); + UT_ASSERT_EQ( + pgrac_fenced_schedule_submit(&schedule, 23, other_target, other_binding, 1300, &other), + PGRAC_FENCED_SCHEDULE_START); UT_ASSERT_EQ(pgrac_fenced_schedule_active_count(&schedule), 2); UT_ASSERT(pgrac_fenced_schedule_release(&schedule, &first, &started)); @@ -117,12 +117,12 @@ UT_TEST(test_cancel_queued_preserves_fifo_and_stale_ticket_is_rejected) memset(second_binding, 0xa1, sizeof(second_binding)); memset(third_binding, 0xa2, sizeof(third_binding)); UT_ASSERT(pgrac_fenced_schedule_init(&schedule)); - UT_ASSERT_EQ(pgrac_fenced_schedule_submit(&schedule, 30, target, binding, - 1000, &first), PGRAC_FENCED_SCHEDULE_START); - UT_ASSERT_EQ(pgrac_fenced_schedule_submit(&schedule, 31, target, - second_binding, 1100, &second), PGRAC_FENCED_SCHEDULE_QUEUE); - UT_ASSERT_EQ(pgrac_fenced_schedule_submit(&schedule, 32, target, - third_binding, 1200, &third), PGRAC_FENCED_SCHEDULE_QUEUE); + UT_ASSERT_EQ(pgrac_fenced_schedule_submit(&schedule, 30, target, binding, 1000, &first), + PGRAC_FENCED_SCHEDULE_START); + UT_ASSERT_EQ(pgrac_fenced_schedule_submit(&schedule, 31, target, second_binding, 1100, &second), + PGRAC_FENCED_SCHEDULE_QUEUE); + UT_ASSERT_EQ(pgrac_fenced_schedule_submit(&schedule, 32, target, third_binding, 1200, &third), + PGRAC_FENCED_SCHEDULE_QUEUE); UT_ASSERT(pgrac_fenced_schedule_cancel_client(&schedule, 31, &started)); UT_ASSERT_EQ(started.serial, 0); UT_ASSERT_EQ(pgrac_fenced_schedule_operation_count(&schedule), 2); @@ -140,28 +140,23 @@ UT_TEST(test_capacity_129_denies_without_mutating_existing_operations) uint32 i; UT_ASSERT(pgrac_fenced_schedule_init(&schedule)); - for (i = 0; i < PGRAC_FENCED_MAX_OPERATIONS; i++) - { + for (i = 0; i < PGRAC_FENCED_MAX_OPERATIONS; i++) { memset(target, 0, sizeof(target)); memset(binding, 0, sizeof(binding)); - target[0] = (uint8) (i + 1); - binding[0] = (uint8) (i + 1); - UT_ASSERT_EQ(pgrac_fenced_schedule_submit(&schedule, (int) i, - target, binding, UINT64_C(1000) + i, &ticket), - PGRAC_FENCED_SCHEDULE_START); + target[0] = (uint8)(i + 1); + binding[0] = (uint8)(i + 1); + UT_ASSERT_EQ(pgrac_fenced_schedule_submit(&schedule, (int)i, target, binding, + UINT64_C(1000) + i, &ticket), + PGRAC_FENCED_SCHEDULE_START); } - UT_ASSERT_EQ(pgrac_fenced_schedule_operation_count(&schedule), - PGRAC_FENCED_MAX_OPERATIONS); - UT_ASSERT_EQ(pgrac_fenced_schedule_active_count(&schedule), - PGRAC_FENCED_MAX_OPERATIONS); + UT_ASSERT_EQ(pgrac_fenced_schedule_operation_count(&schedule), PGRAC_FENCED_MAX_OPERATIONS); + UT_ASSERT_EQ(pgrac_fenced_schedule_active_count(&schedule), PGRAC_FENCED_MAX_OPERATIONS); memset(target, 0xee, sizeof(target)); memset(binding, 0xef, sizeof(binding)); - UT_ASSERT_EQ(pgrac_fenced_schedule_submit(&schedule, 200, target, binding, - 2000, &ticket), PGRAC_FENCED_SCHEDULE_DENY); - UT_ASSERT_EQ(pgrac_fenced_schedule_operation_count(&schedule), - PGRAC_FENCED_MAX_OPERATIONS); - UT_ASSERT_EQ(pgrac_fenced_schedule_active_count(&schedule), - PGRAC_FENCED_MAX_OPERATIONS); + UT_ASSERT_EQ(pgrac_fenced_schedule_submit(&schedule, 200, target, binding, 2000, &ticket), + PGRAC_FENCED_SCHEDULE_DENY); + UT_ASSERT_EQ(pgrac_fenced_schedule_operation_count(&schedule), PGRAC_FENCED_MAX_OPERATIONS); + UT_ASSERT_EQ(pgrac_fenced_schedule_active_count(&schedule), PGRAC_FENCED_MAX_OPERATIONS); } int diff --git a/src/test/cluster_unit/test_pgrac_fenced_session.c b/src/test/cluster_unit/test_pgrac_fenced_session.c index a741f51e518..8ff288292c7 100644 --- a/src/test/cluster_unit/test_pgrac_fenced_session.c +++ b/src/test/cluster_unit/test_pgrac_fenced_session.c @@ -26,8 +26,8 @@ UT_DEFINE_GLOBALS(); static PgracFencedProviderResult -test_resolve(const PgracFencedTargetV1 *configured, - PgracFencedTargetV1 *resolved, int32 *native_status) +test_resolve(const PgracFencedTargetV1 *configured, PgracFencedTargetV1 *resolved, + int32 *native_status) { *resolved = *configured; *native_status = 0; @@ -35,32 +35,29 @@ test_resolve(const PgracFencedTargetV1 *configured, } static PgracFencedProviderResult -test_actuate(const PgracFencedTargetV1 *target, - uint64_t deadline_mono_ns, int32 *native_status) +test_actuate(const PgracFencedTargetV1 *target, uint64_t deadline_mono_ns, int32 *native_status) { - (void) target; - (void) deadline_mono_ns; + (void)target; + (void)deadline_mono_ns; *native_status = 0; return PGRAC_FENCED_PROVIDER_OK; } static PgracFencedProviderResult -test_readback(const PgracFencedTargetV1 *target, - uint64_t deadline_mono_ns, PgracFencedReadbackV1 *out) +test_readback(const PgracFencedTargetV1 *target, uint64_t deadline_mono_ns, + PgracFencedReadbackV1 *out) { - (void) deadline_mono_ns; + (void)deadline_mono_ns; memset(out, 0, sizeof(*out)); out->state = PGRAC_FENCED_TARGET_OFF; out->io_drain_state = PGRAC_FENCED_IO_DRAIN_DRAINED; - memcpy(out->observed_target_uuid, target->target_uuid, - sizeof(out->observed_target_uuid)); + memcpy(out->observed_target_uuid, target->target_uuid, sizeof(out->observed_target_uuid)); return PGRAC_FENCED_PROVIDER_OK; } static void test_shutdown(void) -{ -} +{} static uint64_t deadline_after_ms(uint64_t milliseconds) @@ -68,15 +65,13 @@ deadline_after_ms(uint64_t milliseconds) struct timespec now; UT_ASSERT_EQ(clock_gettime(CLOCK_MONOTONIC, &now), 0); - return (uint64_t) now.tv_sec * UINT64_C(1000000000) + - (uint64_t) now.tv_nsec + milliseconds * UINT64_C(1000000); + return (uint64_t)now.tv_sec * UINT64_C(1000000000) + (uint64_t)now.tv_nsec + + milliseconds * UINT64_C(1000000); } static int -open_context(PgracFencedOperationContextV1 *context, - PgracFencedJournalScanState *journal_state, - PgracFencedConfigV1 *config, PgracFencedProviderOpsV1 *ops, - char path[64]) +open_context(PgracFencedOperationContextV1 *context, PgracFencedJournalScanState *journal_state, + PgracFencedConfigV1 *config, PgracFencedProviderOpsV1 *ops, char path[64]) { uint8 config_digest[32]; uint8 daemon_boot_id[16]; @@ -88,14 +83,13 @@ open_context(PgracFencedOperationContextV1 *context, config->system_identifier = 9001; config->storage_backend_id = 2; memset(config->storage_uuid, 0x31, sizeof(config->storage_uuid)); - config->allowed_db_uid = (uint64) geteuid(); - config->allowed_db_gid = (uint64) getegid(); + config->allowed_db_uid = (uint64)geteuid(); + config->allowed_db_gid = (uint64)getegid(); config->provider_id = PGRAC_FENCED_PROVIDER_ID_TEST_ONLY; config->provider_abi = PGRAC_FENCED_PROVIDER_ABI_V1; config->node_count = 1; config->nodes[3].present = true; - memset(config->nodes[3].target_uuid, 0x41, - sizeof(config->nodes[3].target_uuid)); + memset(config->nodes[3].target_uuid, 0x41, sizeof(config->nodes[3].target_uuid)); memset(ops, 0, sizeof(*ops)); ops->abi_version = PGRAC_FENCED_PROVIDER_ABI_V1; ops->struct_size = sizeof(*ops); @@ -115,25 +109,22 @@ open_context(PgracFencedOperationContextV1 *context, return -1; UT_ASSERT_EQ(fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_APPEND), 0); pgrac_fenced_journal_scan_state_init(journal_state); - UT_ASSERT(pgrac_fenced_operation_context_init(context, config, ops, true, - config_digest, daemon_boot_id, fd, journal_state)); + UT_ASSERT(pgrac_fenced_operation_context_init(context, config, ops, true, config_digest, + daemon_boot_id, fd, journal_state)); return fd; } static void -make_request(const PgracFencedConfigV1 *config, - PgracExternalFenceProtocolRequestV1 *request) +make_request(const PgracFencedConfigV1 *config, PgracExternalFenceProtocolRequestV1 *request) { memset(request, 0, sizeof(*request)); memset(request->request_nonce, 0x51, sizeof(request->request_nonce)); request->need.system_identifier = config->system_identifier; - memset(request->need.canonical_duty_digest, 0x61, - sizeof(request->need.canonical_duty_digest)); + memset(request->need.canonical_duty_digest, 0x61, sizeof(request->need.canonical_duty_digest)); request->need.victim_node_id = 3; request->need.victim_incarnation = 23; UT_ASSERT(pgrac_external_fence_protected_set_digest_v1( - config->storage_backend_id, config->storage_uuid, - request->need.protected_set_digest)); + config->storage_backend_id, config->storage_uuid, request->need.protected_set_digest)); request->need.predicate_id = 1; request->need.predicate_version = 1; request->timeout_ms = 1000; @@ -144,15 +135,14 @@ write_all(int fd, const uint8 *bytes, size_t len) { size_t used = 0; - while (used < len) - { + while (used < len) { ssize_t written = write(fd, bytes + used, len - used); if (written < 0 && errno == EINTR) continue; if (written <= 0) return false; - used += (size_t) written; + used += (size_t)written; } return true; } @@ -162,15 +152,14 @@ read_all(int fd, uint8 *bytes, size_t len) { size_t used = 0; - while (used < len) - { + while (used < len) { ssize_t got = read(fd, bytes + used, len - used); if (got < 0 && errno == EINTR) continue; if (got <= 0) return false; - used += (size_t) got; + used += (size_t)got; } return true; } @@ -183,10 +172,8 @@ journal_record_count(int fd) ssize_t got; UT_ASSERT_EQ(lseek(fd, 0, SEEK_SET), 0); - for (;;) - { - do - { + for (;;) { + do { got = read(fd, frame, sizeof(frame)); } while (got < 0 && errno == EINTR); if (got == 0) @@ -205,13 +192,10 @@ journal_record_at(int fd, size_t index, PgracFencedJournalRecordV1 *record) uint8 frame[PGRAC_FENCED_JOURNAL_RECORD_BYTES]; ssize_t got; - do - { - got = pread(fd, frame, sizeof(frame), - (off_t) (index * sizeof(frame))); + do { + got = pread(fd, frame, sizeof(frame), (off_t)(index * sizeof(frame))); } while (got < 0 && errno == EINTR); - return got == sizeof(frame) && - pgrac_fenced_journal_record_decode(frame, sizeof(frame), record); + return got == sizeof(frame) && pgrac_fenced_journal_record_decode(frame, sizeof(frame), record); } UT_TEST(test_exact_exchange_returns_wire_response_and_retains_positive_fd) @@ -236,20 +220,19 @@ UT_TEST(test_exact_exchange_returns_wire_response_and_retains_positive_fd) UT_ASSERT(pgrac_external_fence_request_v1_encode(&request, request_frame)); UT_ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, sockets), 0); UT_ASSERT(write_all(sockets[0], request_frame, sizeof(request_frame))); - UT_ASSERT_EQ(pgrac_fenced_session_exchange(&context, sockets[1], - true, deadline_after_ms(1000), &response), - PGRAC_FENCED_SESSION_RETAINED); + UT_ASSERT_EQ(pgrac_fenced_session_exchange(&context, sockets[1], true, deadline_after_ms(1000), + &response), + PGRAC_FENCED_SESSION_RETAINED); UT_ASSERT(read_all(sockets[0], response_frame, sizeof(response_frame))); - UT_ASSERT(pgrac_external_fence_response_v1_decode(response_frame, - sizeof(response_frame), &decoded)); + UT_ASSERT( + pgrac_external_fence_response_v1_decode(response_frame, sizeof(response_frame), &decoded)); UT_ASSERT_EQ(decoded.verdict, 1); - UT_ASSERT(pgrac_external_fence_affirmative_response_matches_request_v1( - &request, &decoded)); + UT_ASSERT(pgrac_external_fence_affirmative_response_matches_request_v1(&request, &decoded)); UT_ASSERT_EQ(journal_record_count(journal_fd), 6); - (void) close(sockets[0]); - (void) close(sockets[1]); - (void) close(journal_fd); - (void) unlink(path); + (void)close(sockets[0]); + (void)close(sockets[1]); + (void)close(journal_fd); + (void)unlink(path); } UT_TEST(test_nonaffirmative_response_closes_session_without_retention) @@ -275,19 +258,19 @@ UT_TEST(test_nonaffirmative_response_closes_session_without_retention) UT_ASSERT(pgrac_external_fence_request_v1_encode(&request, request_frame)); UT_ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, sockets), 0); UT_ASSERT(write_all(sockets[0], request_frame, sizeof(request_frame))); - UT_ASSERT_EQ(pgrac_fenced_session_exchange(&context, sockets[1], - true, deadline_after_ms(1000), &response), - PGRAC_FENCED_SESSION_CLOSED); + UT_ASSERT_EQ(pgrac_fenced_session_exchange(&context, sockets[1], true, deadline_after_ms(1000), + &response), + PGRAC_FENCED_SESSION_CLOSED); UT_ASSERT(read_all(sockets[0], response_frame, sizeof(response_frame))); - UT_ASSERT(pgrac_external_fence_response_v1_decode(response_frame, - sizeof(response_frame), &decoded)); + UT_ASSERT( + pgrac_external_fence_response_v1_decode(response_frame, sizeof(response_frame), &decoded)); UT_ASSERT_EQ(decoded.verdict, 4); UT_ASSERT_EQ(decoded.deny_reason, 4); UT_ASSERT_EQ(journal_record_count(journal_fd), 1); - (void) close(sockets[0]); - (void) close(sockets[1]); - (void) close(journal_fd); - (void) unlink(path); + (void)close(sockets[0]); + (void)close(sockets[1]); + (void)close(journal_fd); + (void)unlink(path); } UT_TEST(test_peer_and_protocol_failures_do_not_reach_provider) @@ -311,24 +294,24 @@ UT_TEST(test_peer_and_protocol_failures_do_not_reach_provider) UT_ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, sockets), 0); UT_ASSERT(write_all(sockets[0], request_frame, sizeof(request_frame))); config.allowed_db_uid++; - UT_ASSERT_EQ(pgrac_fenced_session_exchange(&context, sockets[1], - true, deadline_after_ms(1000), &response), - PGRAC_FENCED_SESSION_ERROR); + UT_ASSERT_EQ(pgrac_fenced_session_exchange(&context, sockets[1], true, deadline_after_ms(1000), + &response), + PGRAC_FENCED_SESSION_ERROR); config.allowed_db_uid--; - (void) close(sockets[0]); - (void) close(sockets[1]); + (void)close(sockets[0]); + (void)close(sockets[1]); memset(request_frame, 0, sizeof(request_frame)); UT_ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, sockets), 0); UT_ASSERT(write_all(sockets[0], request_frame, sizeof(request_frame))); - UT_ASSERT_EQ(pgrac_fenced_session_exchange(&context, sockets[1], - true, deadline_after_ms(1000), &response), - PGRAC_FENCED_SESSION_ERROR); + UT_ASSERT_EQ(pgrac_fenced_session_exchange(&context, sockets[1], true, deadline_after_ms(1000), + &response), + PGRAC_FENCED_SESSION_ERROR); UT_ASSERT_EQ(journal_record_count(journal_fd), 1); - (void) close(sockets[0]); - (void) close(sockets[1]); - (void) close(journal_fd); - (void) unlink(path); + (void)close(sockets[0]); + (void)close(sockets[1]); + (void)close(journal_fd); + (void)unlink(path); } static void @@ -355,37 +338,32 @@ run_retention_invalidation(bool expire) UT_ASSERT(pgrac_external_fence_request_v1_encode(&request, request_frame)); UT_ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, sockets), 0); UT_ASSERT(write_all(sockets[0], request_frame, sizeof(request_frame))); - UT_ASSERT_EQ(pgrac_fenced_session_exchange(&context, sockets[1], - true, deadline_after_ms(1000), &response), - PGRAC_FENCED_SESSION_RETAINED); + UT_ASSERT_EQ(pgrac_fenced_session_exchange(&context, sockets[1], true, deadline_after_ms(1000), + &response), + PGRAC_FENCED_SESSION_RETAINED); UT_ASSERT(read_all(sockets[0], response_frame, sizeof(response_frame))); UT_ASSERT(!pgrac_fenced_session_retention_event(sockets[1], &response, - response.verified_mono_ns, &reason)); - if (expire) - { + response.verified_mono_ns, &reason)); + if (expire) { UT_ASSERT(pgrac_fenced_session_retention_event(sockets[1], &response, - response.fresh_until_mono_ns, &reason)); + response.fresh_until_mono_ns, &reason)); UT_ASSERT_EQ(reason, 14); - } - else - { + } else { UT_ASSERT(write_all(sockets[0], request_frame, 1)); UT_ASSERT(pgrac_fenced_session_retention_event(sockets[1], &response, - response.verified_mono_ns, &reason)); + response.verified_mono_ns, &reason)); UT_ASSERT_EQ(reason, 16); } UT_ASSERT(pgrac_fenced_operation_invalidate(&context, &response, reason)); UT_ASSERT_EQ(journal_record_count(journal_fd), 7); UT_ASSERT(journal_record_at(journal_fd, 6, &record)); - UT_ASSERT_EQ(record.record_kind, - PGRAC_FENCED_JOURNAL_KIND_INVALIDATED); + UT_ASSERT_EQ(record.record_kind, PGRAC_FENCED_JOURNAL_KIND_INVALIDATED); UT_ASSERT_EQ(record.deny_reason, reason); - UT_ASSERT(memcmp(record.operation_id, request.request_nonce, - sizeof(record.operation_id)) == 0); - (void) close(sockets[0]); - (void) close(sockets[1]); - (void) close(journal_fd); - (void) unlink(path); + UT_ASSERT(memcmp(record.operation_id, request.request_nonce, sizeof(record.operation_id)) == 0); + (void)close(sockets[0]); + (void)close(sockets[1]); + (void)close(journal_fd); + (void)unlink(path); } UT_TEST(test_retained_extra_bytes_invalidate_live_proof) @@ -420,18 +398,17 @@ UT_TEST(test_dispatch_retains_then_reaps_client_event) UT_ASSERT(pgrac_external_fence_request_v1_encode(&request, request_frame)); UT_ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, sockets), 0); UT_ASSERT(write_all(sockets[0], request_frame, sizeof(request_frame))); - UT_ASSERT(pgrac_fenced_dispatch_accept_fd(&dispatcher, sockets[1], - deadline_after_ms(1000))); + UT_ASSERT(pgrac_fenced_dispatch_accept_fd(&dispatcher, sockets[1], deadline_after_ms(1000))); UT_ASSERT_EQ(dispatcher.client_count, 1); UT_ASSERT(read_all(sockets[0], response_frame, sizeof(response_frame))); UT_ASSERT(write_all(sockets[0], request_frame, 1)); - UT_ASSERT(pgrac_fenced_dispatch_reap(&dispatcher, - dispatcher.clients[0].response.verified_mono_ns)); + UT_ASSERT( + pgrac_fenced_dispatch_reap(&dispatcher, dispatcher.clients[0].response.verified_mono_ns)); UT_ASSERT_EQ(dispatcher.client_count, 0); UT_ASSERT_EQ(journal_record_count(journal_fd), 7); - (void) close(sockets[0]); - (void) close(journal_fd); - (void) unlink(path); + (void)close(sockets[0]); + (void)close(journal_fd); + (void)unlink(path); } UT_TEST(test_dispatch_capacity_denial_has_zero_operation_effect) @@ -458,17 +435,16 @@ UT_TEST(test_dispatch_capacity_denial_has_zero_operation_effect) UT_ASSERT(pgrac_external_fence_request_v1_encode(&request, request_frame)); UT_ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, sockets), 0); UT_ASSERT(write_all(sockets[0], request_frame, sizeof(request_frame))); - UT_ASSERT(pgrac_fenced_dispatch_accept_fd(&dispatcher, sockets[1], - deadline_after_ms(1000))); + UT_ASSERT(pgrac_fenced_dispatch_accept_fd(&dispatcher, sockets[1], deadline_after_ms(1000))); UT_ASSERT(read_all(sockets[0], response_frame, sizeof(response_frame))); - UT_ASSERT(pgrac_external_fence_response_v1_decode(response_frame, - sizeof(response_frame), &response)); + UT_ASSERT( + pgrac_external_fence_response_v1_decode(response_frame, sizeof(response_frame), &response)); UT_ASSERT_EQ(response.verdict, 4); UT_ASSERT_EQ(response.deny_reason, 10); UT_ASSERT_EQ(journal_record_count(journal_fd), 1); - (void) close(sockets[0]); - (void) close(journal_fd); - (void) unlink(path); + (void)close(sockets[0]); + (void)close(journal_fd); + (void)unlink(path); } UT_TEST(test_dispatch_journal_failure_closes_all_live_clients) @@ -493,17 +469,16 @@ UT_TEST(test_dispatch_journal_failure_closes_all_live_clients) UT_ASSERT(pgrac_external_fence_request_v1_encode(&request, request_frame)); UT_ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, sockets), 0); UT_ASSERT(write_all(sockets[0], request_frame, sizeof(request_frame))); - UT_ASSERT(pgrac_fenced_dispatch_accept_fd(&dispatcher, sockets[1], - deadline_after_ms(1000))); + UT_ASSERT(pgrac_fenced_dispatch_accept_fd(&dispatcher, sockets[1], deadline_after_ms(1000))); UT_ASSERT(read_all(sockets[0], response_frame, sizeof(response_frame))); UT_ASSERT_EQ(close(journal_fd), 0); UT_ASSERT(write_all(sockets[0], request_frame, 1)); - UT_ASSERT(!pgrac_fenced_dispatch_reap(&dispatcher, - dispatcher.clients[0].response.verified_mono_ns)); + UT_ASSERT( + !pgrac_fenced_dispatch_reap(&dispatcher, dispatcher.clients[0].response.verified_mono_ns)); UT_ASSERT_EQ(dispatcher.client_count, 0); UT_ASSERT(!context.available); - (void) close(sockets[0]); - (void) unlink(path); + (void)close(sockets[0]); + (void)unlink(path); } int diff --git a/src/test/cluster_unit/test_resource_x_send_c1.py b/src/test/cluster_unit/test_resource_x_send_c1.py index 6cd8aa4999a..6e7fed069d2 100644 --- a/src/test/cluster_unit/test_resource_x_send_c1.py +++ b/src/test/cluster_unit/test_resource_x_send_c1.py @@ -5,6 +5,9 @@ import importlib.util import pathlib +import os +import shlex +import subprocess import tempfile import unittest @@ -227,6 +230,62 @@ def test_edge_mutation_must_fail_its_bound_witness(self) -> None: }, ) + def test_mutation_compiles_with_separate_source_and_build_roots(self) -> None: + compiler = os.environ.get("CC", "cc") + recipes = { + "pcm_lock": ("version", "resource_x_identity", "resource_x_node_wire"), + "lms_outbound": ("version",), + "gcs_block": ("version", "pcm_x_convert", "resource_x_identity", + "resource_x_retry"), + } + for separate in (True, False): + with self.subTest(separate_build=separate): + build_root = self.root / "build" if separate else self.root + unit_build = build_root / "src/test/cluster_unit" + backend_build = build_root / "src/backend/cluster" + unit_build.mkdir(parents=True, exist_ok=True) + backend_build.mkdir(parents=True, exist_ok=True) + empty_source = self.root / "empty.c" + empty_source.write_text("/* link-only dependency fixture */\n") + empty_object = unit_build / "cluster_unit_port_stubs.o" + subprocess.run(shlex.split(compiler) + ["-c", str(empty_source), + "-o", str(empty_object)], check=True, capture_output=True) + for library in ("common/libpgcommon_srv.a", "port/libpgport_srv.a"): + archive = build_root / "src" / library + archive.parent.mkdir(parents=True, exist_ok=True) + subprocess.run(["ar", "rcs", str(archive), str(empty_object)], + check=True, capture_output=True) + (self.tests / "unit_test.h").write_text("int producer(void);\n") + (unit_build / "generated_fixture.h").write_text("#define EXPECTED 0\n") + for module, dependencies in recipes.items(): + with self.subTest(module=module): + source_relative = f"src/backend/cluster/cluster_{module}.c" + (self.root / source_relative).write_text( + "static int consumer(void) { return 1; }\n" + "int producer(void) { return consumer(); }\n") + binary_name = f"test_cluster_{module}" + unit_text = '#include "unit_test.h"\n#include "generated_fixture.h"\n' + if module == "gcs_block": + unit_text += '#include GCS_BLOCK_SOURCE_PATH\n' + unit_text += "int main(void) { return producer() != EXPECTED; }\n" + (self.tests / f"{binary_name}.c").write_text(unit_text) + for dependency in dependencies: + (backend_build / f"cluster_{dependency}.o").write_bytes( + empty_object.read_bytes()) + row = { + "id": "C1-1", "mutation_edge": ["producer", "consumer"], + "production_sources": {"producer": source_relative}, + "mutation_witness": "positive", "mutation_result": "0", + "positive_binary": binary_name, + } + with tempfile.TemporaryDirectory() as temporary: + executable, actual_name, _ = CHECKER._compile_mutation_binary( + row, self.root, unit_build, pathlib.Path(temporary), + compiler, "", "", "", "") + self.assertEqual(actual_name, binary_name) + self.assertEqual(subprocess.run([str(executable)], + capture_output=True).returncode, 0) + if __name__ == "__main__": unittest.main() diff --git a/src/tools/check_r11_source_removal_census.py b/src/tools/check_r11_source_removal_census.py index bc36e825c41..16fa259b995 100644 --- a/src/tools/check_r11_source_removal_census.py +++ b/src/tools/check_r11_source_removal_census.py @@ -23,8 +23,8 @@ L3_TREE = "be71cb8fa6bba4164f8f9b57e54adcc6ef2a34b5" CURRENT_PRODUCT_SNAPSHOT = { "algorithm": "sha256-canonical-path-blob-v1", - "path_count": 2224, - "sha256": "b257e233d68a37edfbd238891077e28248d64fa8f1743cba1cdaf18a3c2680c2", + "path_count": 2225, + "sha256": "526de2a0572d0c41dccfe05c6c01f1779646383a15a54db61f91e7cb3dde4d4a", } LAYERS = { @@ -64,7 +64,7 @@ }, { "path": "src/backend/cluster/cluster_lms_outbound.c", - "symbol": "cluster_pcm_lock_resource_x_outbound_intent_probe_exact", + "symbol": "cluster_pcm_lock_resource_x_outbound_work_probe_exact", }, ], }, @@ -361,7 +361,7 @@ def validate(source_root: pathlib.Path, manifest_path: pathlib.Path) -> str: stale_body = (source_root / "src/backend/cluster/cluster_gcs_block.c").read_text( encoding="utf-8" ) - if len(re.findall(r"(?m)^gcs_block_legacy_pcm_x_stale_ingress\($", stale_body)) != 1: + if len(re.findall(r"(?m)^gcs_block_legacy_pcm_x_stale_ingress\s*\(", stale_body)) != 1: raise CensusError("bounded stale-family ingress cardinality is not one") build_body = (source_root / BUILD_LINK["manifest_path"]).read_text(encoding="utf-8") for name in BUILD_LINK["forbidden_objects"]: diff --git a/src/tools/check_resource_x_send_c1.py b/src/tools/check_resource_x_send_c1.py index 3d69d7e2cf2..90269f2d558 100644 --- a/src/tools/check_resource_x_send_c1.py +++ b/src/tools/check_resource_x_send_c1.py @@ -1,4 +1,5 @@ #!/usr/bin/env python3 +# PGRAC: validate real cluster send-edge evidence in source and build trees. """Validate and freshness-check the Resource-X SEND-C1 9+2 gate.""" from __future__ import annotations @@ -519,15 +520,26 @@ def _compile_mutation_binary( output_binary = temporary / f"{row['id'].lower()}-{binary_name}" compiler = shlex.split(cc) common_flags = shlex.split(cflags) + shlex.split(cppflags) - include_flags = ["-I", str(unit_directory), "-I", str(source_root / "src" / "include")] + build_root = unit_directory.parents[2] + unit_source = source_root / "src" / "test" / "cluster_unit" + include_flags = ["-I", str(unit_directory), "-I", str(unit_source), + "-I", str(build_root / "src" / "include"), + "-I", str(source_root / "src" / "include")] backend = source_root / "src" / "backend" / "cluster" - common = source_root / "src" / "common" / "libpgcommon_srv.a" - port = source_root / "src" / "port" / "libpgport_srv.a" + backend_build = build_root / "src" / "backend" / "cluster" + common = build_root / "src" / "common" / "libpgcommon_srv.a" + port = build_root / "src" / "port" / "libpgport_srv.a" + port_boundary = unit_directory / "cluster_unit_port_stubs.o" if binary_name in {"test_cluster_pcm_lock", "test_cluster_lms_outbound"}: mutated_object = temporary / f"{row['id'].lower()}-{pathlib.Path(source_relative).stem}.o" + fixture_flags = ( + ["-Dclock_gettime=cluster_test_pcm_clock_gettime"] + if binary_name == "test_cluster_pcm_lock" + else ["-DCLUSTER_LMS_OUTBOUND_UNIT_TEST"] + ) _run_compile( - compiler + common_flags + include_flags + compiler + common_flags + include_flags + fixture_flags + ["-c", str(mutated_path), "-o", str(mutated_object)], unit_directory, f"{row['id']} mutation object compile", @@ -537,19 +549,19 @@ def _compile_mutation_binary( link += [ f'-DGCS_BLOCK_SOURCE_PATH="{backend / "cluster_gcs_block.c"}"', f'-DPCM_LOCK_SOURCE_PATH="{mutated_path}"', - str(unit_directory / "test_cluster_pcm_lock.c"), - str(backend / "cluster_version.o"), + str(unit_source / "test_cluster_pcm_lock.c"), + str(backend_build / "cluster_version.o"), str(mutated_object), - str(backend / "cluster_resource_x_identity.o"), - str(backend / "cluster_resource_x_node_wire.o"), + str(backend_build / "cluster_resource_x_identity.o"), + str(backend_build / "cluster_resource_x_node_wire.o"), ] else: link += [ - str(unit_directory / "test_cluster_lms_outbound.c"), - str(backend / "cluster_version.o"), + str(unit_source / "test_cluster_lms_outbound.c"), + str(backend_build / "cluster_version.o"), str(mutated_object), ] - link += [str(common), str(port), "-o", str(output_binary)] + link += [str(common), str(port), str(port_boundary), "-o", str(output_binary)] else: link = compiler + common_flags + shlex.split(pthread_cflags) + include_flags + [ f'-DGCS_BLOCK_SOURCE_PATH="{mutated_path}"', @@ -557,12 +569,15 @@ def _compile_mutation_binary( f'-DLMS_SOURCE_PATH="{backend / "cluster_lms.c"}"', f'-DLMS_OUTBOUND_SOURCE_PATH="{backend / "cluster_lms_outbound.c"}"', f'-DT400_SOURCE_PATH="{source_root / "src/test/cluster_tap/t/400_pcm_x_queue_4node_liveness.pl"}"', - str(unit_directory / "test_cluster_gcs_block.c"), - str(backend / "cluster_version.o"), - str(backend / "cluster_pcm_x_convert.o"), - str(backend / "cluster_resource_x_identity.o"), - str(backend / "cluster_resource_x_retry.o"), - str(common), str(port), + f'-DPCM_LOCK_SOURCE_PATH="{backend / "cluster_pcm_lock.c"}"', + f'-DRUNTIME_VISIBILITY_SOURCE_PATH="{backend / "cluster_runtime_visibility.c"}"', + f'-DLMON_SOURCE_PATH="{backend / "cluster_lmon.c"}"', + f'-DT406_SOURCE_PATH="{source_root / "src/test/cluster_tap/t/406_resource_x_finish_flush_failclosed_4node.pl"}"', + str(unit_source / "test_cluster_gcs_block.c"), + str(backend_build / "cluster_version.o"), + str(backend_build / "cluster_resource_x_identity.o"), + str(backend_build / "cluster_resource_x_retry.o"), + str(common), str(port), str(port_boundary), ] + shlex.split(pthread_libs) + ["-o", str(output_binary)] _run_compile(link, unit_directory, f"{row['id']} mutation witness link") return output_binary, binary_name, mutation_sha256